Skip to content

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

feat(workers): god-hired workers get a floor card, and it archives on death

Gastón Péchieu4bcbc9e5c823
diff --git a/src/main/index.ts b/src/main/index.ts
index ac6f91ae..adf19b2f 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -423,6 +423,12 @@ const preservedWorktrees = new Map<string, PreservedWorktree>();
* handler or node-pty's onExit).
*/
function teardownPty(id: string): void {
+ // Ephemeral-worker flag, read BEFORE the cleanup below deletes the entry. All
+ // worker deaths (done-release, idle/token reap, manual stop, crash) funnel
+ // through here, so this is the one place their floor card gets archived
+ // (workers card via the hive:agentSpawned broadcast in processSpawnRequest).
+ // pty id == worker id == agent id for workers.
+ const wasWorker = liveWorkers.has(id);
// 0) Revoke this id's broker capability (if any). Idempotent + harmless for a
// non-worker PTY; ensures a dead worker's token can never reach an integration.
try { integrationBroker.revoke(id); } catch { /* best-effort */ }
@@ -462,6 +468,12 @@ function teardownPty(id: string): void {
// A worker whose isolation failed (non-repo cwd) has no worktree to gate above —
// still clear its tracking entry so the controller stops watching a dead PTY.
if (liveWorkers.has(id)) liveWorkers.delete(id);
+ // Archive the dead worker's floor card (mirrors killAgent's voice-kill path;
+ // the renderer's archiveAgent is a no-op if the card is already gone). NOT
+ // done for regular agents: their kill flows already manage their own card.
+ if (wasWorker) {
+ try { liveWebContents()?.send('hive:agentArchived', { id }); } catch { /* window torn down */ }
+ }
syncKeepAwake();
}
@@ -4441,16 +4453,34 @@ async function processSpawnRequest(filePath: string): Promise<void> {
hive: meta, isolate, provider: raw.provider, env: brokerEnv
};
- let res: { ok: boolean; error?: string };
+ let res: { ok: boolean; error?: string; worktreePath?: string };
try {
- // Output routes to the primary window (no renderer evt here). Workers are
- // headless-by-design — they reply to Slack + report to god, not a watching human.
res = await spawnAgentCore(spawnOpts, liveWebContents());
} catch (e) {
res = { ok: false, error: String(e) };
}
if (!res.ok) { integrationBroker.revoke(workerId); fail(`spawn failed — ${res.error ?? 'unknown error'}`); return; }
+ // A god-hired worker is a MAIN-initiated spawn, so the renderer would never
+ // card it on its own (same reason as the voice-spawn broadcast): without this
+ // the worker is invisible on the floor, never enters the roster, and after a
+ // restart nothing offers to restore it. The card rides the normal agent
+ // lifecycle from here — teardownPty broadcasts the matching archive. A card
+ // RESTORED after an app quit revives through the renderer's normal spawn path
+ // and never re-enters liveWorkers: ephemerality is a property of the hiring,
+ // not of the card, so a restored worker is a regular agent (no reaping).
+ try {
+ liveWebContents()?.send('hive:agentSpawned', {
+ id: workerId,
+ name: meta.name,
+ provider: raw.provider ?? 'claude',
+ cwd: res.worktreePath ?? cwd,
+ command: launch.command,
+ role: meta.role,
+ worktreePath: res.worktreePath
+ });
+ } catch { /* window torn down */ }
+
// Register for done-scan / idle-reap / token-cap / safe teardown (pty id == workerId).
// tokenCap is optional plumbing (default unlimited) — only a positive finite cap is kept.
const tokenCap = typeof raw.tokenCap === 'number' && Number.isFinite(raw.tokenCap) && raw.tokenCap > 0