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
Harden terminal handoff delivery
Piotr Durlej7e58148d6503
diff --git a/src/main/hive.ts b/src/main/hive.tsindex b2ef926d..321d664f 100644--- a/src/main/hive.ts+++ b/src/main/hive.ts@@ -141,7 +141,7 @@ export class HiveManager {*/constructor(private getHome: () => string | null,- private emit?: (channel: string, payload: unknown) => void+ private emit?: (channel: string, payload: unknown) => boolean | void) {}private routerTimer: NodeJS.Timeout | null = null;@@ -566,7 +566,13 @@ export class HiveManager {continue;}if (target && !isClaudeProvider(target.provider ?? 'claude')) {- this.emitTerminalHandoff(msg, t);+ if (!this.emitTerminalHandoff(msg, t)) {+ this.deliver({+ ...msg,+ to: godId,+ subject: `[terminal handoff failed — "${t}" uses ${target.provider ?? 'custom'}; renderer unavailable] ${msg.subject}`+ }, godId);+ }continue;}this.deliver(msg, t);@@ -593,16 +599,27 @@ export class HiveManager {/** Non-Claude providers cannot drain hive inbox; hand direct mail to the* renderer so it can queue a terminal work order for the target PTY. */- private emitTerminalHandoff(msg: HiveMessage, targetId: string): void {- this.emit?.('hive:terminalHandoff', {+ private emitTerminalHandoff(msg: HiveMessage, targetId: string): boolean {+ const delivered = this.emit?.('hive:terminalHandoff', {id: msg.id,from: msg.from,to: targetId,act: msg.act,subject: msg.subject,body: msg.body,+ requiresReply: msg.requires_reply,createdAt: msg.created_at+ }) === true;+ this.appendLog({+ kind: 'terminal-handoff',+ from: msg.from,+ to: targetId,+ act: msg.act,+ subject: msg.subject,+ id: msg.id,+ delivered});+ return delivered;}// — router: drain outboxes → inboxes —diff --git a/src/main/index.ts b/src/main/index.tsindex 0acef987..8416a8aa 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -34,7 +34,11 @@ const ptyManager = new PtyManager();const ptyToAgent = new Map<string, string>();const hive = new HiveManager(() => readConfig().harnessHome,- (channel, payload) => { try { liveWebContents()?.send(channel, payload); } catch { /* window tore down */ } }+ (channel, payload) => {+ const wc = liveWebContents();+ if (!wc) return false;+ try { wc.send(channel, payload); return true; } catch { return false; }+ });// #7C — operator control state (pause/gate/steer/halt), read by the HookServer// when deciding hook returns.diff --git a/src/preload/index.ts b/src/preload/index.tsindex a89a5e1b..2e7ba4b8 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -69,6 +69,7 @@ export interface HiveTerminalHandoffEvent {act: 'request' | 'inform' | 'propose' | 'query' | 'agree' | 'refuse' | 'done';subject: string;body: string;+ requiresReply: boolean;createdAt: string;}diff --git a/src/renderer/src/hooks/useHive.ts b/src/renderer/src/hooks/useHive.tsindex 26dfbdde..ebd6ba19 100644--- a/src/renderer/src/hooks/useHive.ts+++ b/src/renderer/src/hooks/useHive.ts@@ -92,14 +92,21 @@ function enrichTaskPrompt(text: string): string {}function terminalWorkOrderPrompt(msg: {+ id: string;from: string;+ act: string;subject: string;body: string;+ requiresReply: boolean;+ createdAt: string;}): string {return ['WORK ORDER FROM HIVE',+ `Message: ${msg.id}`,`From: ${msg.from}`,`Subject: ${msg.subject}`,+ `Act: ${msg.act}${msg.requiresReply ? ' (reply expected)' : ''}`,+ `Issued: ${msg.createdAt}`,'',msg.body,'',@@ -159,6 +166,7 @@ export function useHive(config: HarnessConfig | null): void {// must leave the agent alone — set while its boot sequence is typing so nothing// collides with /remote-control + the orientation prompt.const bootGraceUntil = useRef<Record<string, number>>({});+ const seenTerminalHandoffs = useRef<Set<string>>(new Set());// Reactive so the assistant bootstrap (effect #1b) re-runs once Michael is ready.const godStatus = useStore((s) => s.godStatus);// #5C/#7C.4 — latest circuit-breaker level per agent. When 'constrained'/@@ -426,12 +434,17 @@ export function useHive(config: HarnessConfig | null): void {useEffect(() => {if (!config?.onboardingComplete) return;return window.cth.onHiveTerminalHandoff((msg) => {- const { agents, enqueueMessage } = useStore.getState();+ if (seenTerminalHandoffs.current.has(msg.id)) return;+ const { agents, enqueueMessage, messageQueues } = useStore.getState();const target = agents.find((a) => a.id === msg.to);if (target?.ptyId) {+ const marker = `Message: ${msg.id}`;+ if ((messageQueues[target.id] ?? []).some((queued) => queued.text.includes(marker))) return;+ seenTerminalHandoffs.current.add(msg.id);enqueueMessage(target.id, terminalWorkOrderPrompt(msg));return;}+ seenTerminalHandoffs.current.add(msg.id);enqueueMessage(GOD_ID,[