Elffuss BraidHub

kikocis/clonagent public

main · 1.0 KiBRawPermalink
1// Manages the shared task queue for each agent.
2// Lives at ~/.claude/skills/<agentId>/agent-tasks.json so both scheduler
3// and executor Claude sessions can read/write it directly via Bash tools.
4const fs = require('fs');
5const path = require('path');
6const os = require('os');
7
8function filePath(agentId) {
9 return path.join(os.homedir(), '.claude', 'skills', agentId, 'agent-tasks.json');
10}
11
12function empty(agentId) {
13 return { agentId, plan: '', tasks: [], updatedAt: new Date().toISOString() };
14}
15
16function read(agentId) {
17 try { return JSON.parse(fs.readFileSync(filePath(agentId), 'utf8')); }
18 catch { return empty(agentId); }
19}
20
21function write(agentId, data) {
22 const f = filePath(agentId);
23 fs.mkdirSync(path.dirname(f), { recursive: true });
24 fs.writeFileSync(f, JSON.stringify({ ...data, updatedAt: new Date().toISOString() }, null, 2));
25}
26
27function hasPending(agentId) {
28 const { tasks } = read(agentId);
29 return Array.isArray(tasks) && tasks.some(t => t.status === 'pending');
30}
31
32module.exports = { filePath, read, write, hasPending };