an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
Fix race-safe realtime task writes
RARzc43d0018d4b7
diff --git a/src/main/index.ts b/src/main/index.tsindex 5944af45..56ac010c 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -4268,7 +4268,9 @@ registerRealtimeActionIpc({hiveEnabled: () => hive.enabled(),hiveSend: (partial, from) => hive.send(partial, from),hiveTasks: () => hive.tasks(),- hiveWriteTasks: (tasks) => hive.writeTasks(tasks),+ hiveAddTask: (task) => hive.addTask(task as HiveTask),+ hivePatchTask: (id, patch) => hive.patchTask(id, patch as Partial<Omit<HiveTask, 'id'>>),+ hiveDeleteTask: (id) => hive.deleteTask(id),hiveRegistry: () => hive.registry(),hiveLog: (event) => hive.appendLog(event),controlPause: (id, on) => control.pause(id, on),diff --git a/src/main/realtimeActions.ts b/src/main/realtimeActions.tsindex f4354bc2..9c852eee 100644--- a/src/main/realtimeActions.ts+++ b/src/main/realtimeActions.ts@@ -30,7 +30,7 @@* god-PTY cross-notify; rt-5 just needs the attribution present.** Thin wrappers ONLY — no new orchestration logic. Each verb maps onto a main fn- * the god PTY already uses (hive.send / writeTasks / spawnAgentCore /+ * the god PTY already uses (hive.send / atomic task mutations / spawnAgentCore /* control.pause+steer+halt / pty kill / missions save), injected via deps so this* module stays decoupled from index.ts wiring.*/@@ -57,7 +57,9 @@ export interface RealtimeActionDeps {hiveEnabled(): boolean;hiveSend(partial: Partial<HiveMessage>, from: string): HiveMessage;hiveTasks(): unknown;- hiveWriteTasks(tasks: HiveTask[]): void;+ hiveAddTask(task: HiveTask): boolean;+ hivePatchTask(id: string, patch: Partial<Omit<HiveTask, 'id'>>): boolean;+ hiveDeleteTask(id: string): boolean;hiveRegistry(): Registry;hiveLog(event: Record<string, unknown>): void;controlPause(agentId: string, on: boolean): void;@@ -346,7 +348,6 @@ function execSteer(deps: RealtimeActionDeps, a: Record<string, unknown>): Actionfunction execCreateTask(deps: RealtimeActionDeps, a: Record<string, unknown>): ActionResult {const title = str(a.title) || str(a.task) || str(a.name);if (!title) return { ok: false, spoken: 'What should the task be titled?' };- const tasks = findTasks(deps);const id = `${slug(title)}-${shortId()}`;const card: HiveTask = {id,@@ -358,7 +359,9 @@ function execCreateTask(deps: RealtimeActionDeps, a: Record<string, unknown>): Apriority: typeof a.priority === 'number' ? a.priority : 5,createdAt: new Date().toISOString()};- deps.hiveWriteTasks([...tasks, card]);+ if (!deps.hiveAddTask(card)) {+ return { ok: false, spoken: 'I can’t create that task because it already exists.' };+ }attribute(deps, 'create_task', id, { title: title.slice(0, 120), assignee: card.assignee });return { ok: true, spoken: `Created task "${title}"${card.assignee ? `, assigned to ${card.assignee}` : ''}.` };}@@ -419,13 +422,14 @@ function execAssignTask(deps: RealtimeActionDeps, a: Record<string, unknown>): Aconst ref = str(a.taskId) || str(a.task) || str(a.title);const assignee = str(a.assignee) || str(a.to) || str(a.agentId);if (!ref || !assignee) return { ok: false, spoken: 'I need both a task and who to assign it to.' };- const { tasks, card, ambiguous } = findCard(deps, ref);+ const { card, ambiguous } = findCard(deps, ref);if (ambiguous) {return { ok: false, spoken: `Which one — ${ambiguous.map((c) => `"${c.title}"`).join(', or ')}?` };}if (!card) return { ok: false, spoken: `I couldn't find a task matching "${ref}".` };- card.assignee = assignee;- deps.hiveWriteTasks(tasks);+ if (!deps.hivePatchTask(card.id, { assignee })) {+ return { ok: false, spoken: `I couldn't update "${card.title}" right now.` };+ }attribute(deps, 'assign_task', card.id, { assignee });return { ok: true, spoken: `Assigned "${card.title}" to ${assignee}.` };}@@ -433,7 +437,7 @@ function execAssignTask(deps: RealtimeActionDeps, a: Record<string, unknown>): Afunction execUpdateTask(deps: RealtimeActionDeps, a: Record<string, unknown>): ActionResult {const ref = str(a.taskId) || str(a.task) || str(a.title);if (!ref) return { ok: false, spoken: 'Which task should I update?' };- const { tasks, card, ambiguous } = findCard(deps, ref);+ const { card, ambiguous } = findCard(deps, ref);if (ambiguous) {return { ok: false, spoken: `Which one — ${ambiguous.map((c) => `"${c.title}"`).join(', or ')}?` };}@@ -441,11 +445,14 @@ function execUpdateTask(deps: RealtimeActionDeps, a: Record<string, unknown>): Aconst status = str(a.status);const valid = ['todo', 'doing', 'blocked', 'done'];if (status && !valid.includes(status)) return { ok: false, spoken: `"${status}" isn't a valid status.` };- if (status) card.status = status as HiveTask['status'];- if (str(a.result)) card.result = str(a.result);- if (str(a.assignee)) card.assignee = str(a.assignee);- deps.hiveWriteTasks(tasks);- attribute(deps, 'update_task', card.id, { status: card.status });+ const patch: Partial<Omit<HiveTask, 'id'>> = {};+ if (status) patch.status = status as HiveTask['status'];+ if (str(a.result)) patch.result = str(a.result);+ if (str(a.assignee)) patch.assignee = str(a.assignee);+ if (!deps.hivePatchTask(card.id, patch)) {+ return { ok: false, spoken: `I couldn't update "${card.title}" right now.` };+ }+ attribute(deps, 'update_task', card.id, { status: patch.status ?? card.status });return { ok: true, spoken: `Updated "${card.title}"${status ? ` to ${status}` : ''}.` };}@@ -492,10 +499,12 @@ function execGateTool(deps: RealtimeActionDeps, a: Record<string, unknown>): Actfunction execDeleteTask(deps: RealtimeActionDeps, a: Record<string, unknown>): ActionResult {const ref = str(a.taskId) || str(a.task) || str(a.title);if (!ref) return { ok: false, spoken: 'Which task should I delete?' };- const { tasks, card, ambiguous } = findCard(deps, ref);+ const { card, ambiguous } = findCard(deps, ref);if (ambiguous) return { ok: false, spoken: `Which one — ${ambiguous.map((c) => `"${c.title}"`).join(', or ')}?` };if (!card) return { ok: false, spoken: `I couldn't find a task matching "${ref}".` };- deps.hiveWriteTasks(tasks.filter((t) => t.id !== card.id));+ if (!deps.hiveDeleteTask(card.id)) {+ return { ok: false, spoken: `I couldn't delete "${card.title}" right now.` };+ }attribute(deps, 'delete_task', card.id, { title: card.title.slice(0, 120) });return { ok: true, spoken: `Deleted the task "${card.title}". Recreate it any time if that was wrong.` };}diff --git a/test/hive-task-mutation.test.cjs b/test/hive-task-mutation.test.cjsindex d8568366..7631472a 100644--- a/test/hive-task-mutation.test.cjs+++ b/test/hive-task-mutation.test.cjs@@ -88,6 +88,7 @@ test('renderer task actions never send a whole stale ledger back to main', () =>const root = path.resolve(__dirname, '..');const preload = fs.readFileSync(path.join(root, 'src/preload/index.ts'), 'utf8');const main = fs.readFileSync(path.join(root, 'src/main/index.ts'), 'utf8');+ const realtimeActions = fs.readFileSync(path.join(root, 'src/main/realtimeActions.ts'), 'utf8');const sources = ['src/renderer/src/components/AskMeTab.tsx','src/renderer/src/components/TaskDetailOverlay.tsx',@@ -103,6 +104,11 @@ test('renderer task actions never send a whole stale ledger back to main', () =>'the renderer bridge must not expose the unsafe whole-ledger write primitive');assert.doesNotMatch(main, /ipcMain\.handle\('hive:writeTasks'/,'main must not accept whole-ledger writes from a stale renderer');+ assert.doesNotMatch(realtimeActions, /hiveWriteTasks\s*\(/,+ 'voice actions must use atomic task mutations rather than overwrite tasks.json');+ assert.match(realtimeActions, /hiveAddTask\s*\(/);+ assert.match(realtimeActions, /hivePatchTask\s*\(/);+ assert.match(realtimeActions, /hiveDeleteTask\s*\(/);assert.match(sources[0], /hivePatchTask\s*\(/);assert.match(sources[1], /hivePatchTask\s*\(/);assert.match(sources[2], /hiveDeleteTask\s*\(/);