adeb4dad33
- Stack Swarm 'dev': redis + taskboard + frontend HMR (Vite) + backend HMR (tsx) + 5 agents - TaskBoard standalone React com Redis pub/sub e BLPOP queue - Backend API Express: /tasks /agents /health com hot reload - Agentes: 2 FE (frontend), 2 BE (backend), 1 DevOps (parallel workers) - Vault Obsidian: /root/Obsidian-Pulse/ com estrutura Inbox/Projetos/Docker/Dev/Codex/Logs/Memorias/Templates - Skill obsidian-vault-linker instalada e documentada - Caddy labels: board.octal.tec.br + api.octal.tec.br + frontend.octal.tec.br - Protocolo task queue Redis documentado em MEMORY.md
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import Redis from 'ioredis'
|
|
import { execSync } from 'child_process'
|
|
const redis = new Redis({ host: 'redis', port: 6379, lazyConnect: true })
|
|
const QUEUE = 'dev-tasks'
|
|
const LOG = 'dev-logs'
|
|
|
|
function log(level, msg) {
|
|
const line = JSON.stringify({ ts: new Date().toISOString(), level, msg })
|
|
redis.publish(LOG, line).catch(() => {})
|
|
console.log(`[${level}] ${msg}`)
|
|
}
|
|
|
|
function exec(cmd) {
|
|
try { return execSync(cmd, { encoding: 'utf8', timeout: 30000 }).trim() }
|
|
catch(e) { return `ERROR: ${e.message}` }
|
|
}
|
|
|
|
async function processTask(task) {
|
|
task.status = 'in_progress'
|
|
task.assignee = 'agent-devops'
|
|
await redis.set(`task:${task.id}`, JSON.stringify(task))
|
|
log('AGENT', `▶️ Processando: ${task.title}`)
|
|
const result = exec(task.command || `echo "${task.title}"`)
|
|
task.result = result
|
|
task.status = 'done'
|
|
task.done_at = new Date().toISOString()
|
|
await redis.set(`task:${task.id}`, JSON.stringify(task))
|
|
log('AGENT', `✔️ Concluído: ${task.title}`)
|
|
return result
|
|
}
|
|
|
|
async function run() {
|
|
await redis.connect()
|
|
await redis.set('agent:agent-devops', JSON.stringify({
|
|
id: 'agent-devops', role: 'devops', status: 'online',
|
|
started_at: new Date().toISOString(), tasks_done: 0,
|
|
}))
|
|
log('AGENT', 'DevOps Agent online — aguardando tarefas')
|
|
while (true) {
|
|
const [_, tid] = await redis.blpop(QUEUE, 60)
|
|
if (!tid) { await new Promise(r => setTimeout(r, 1000)); continue }
|
|
const raw = await redis.get(`task:${tid}`)
|
|
if (!raw) continue
|
|
const task = JSON.parse(raw)
|
|
if (task.domain !== 'devops') {
|
|
await redis.rpush(QUEUE, tid); continue
|
|
}
|
|
await processTask(task)
|
|
await redis.hincrby('agent:agent-devops', 'tasks_done', 1)
|
|
}
|
|
}
|
|
run().catch(e => { console.error(e); process.exit(1) })
|