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(restore): make 'Restore team' resilient + surface outcomes (was a silent no-op)
Vyapak Goyald2872bf92a95
diff --git a/src/renderer/src/components/AgentStrip.tsx b/src/renderer/src/components/AgentStrip.tsxindex 94825b90..5fbf5b6a 100644--- a/src/renderer/src/components/AgentStrip.tsx+++ b/src/renderer/src/components/AgentStrip.tsx@@ -19,6 +19,7 @@ export function AgentStrip({ config }: AgentStripProps) {const setAddAgentOpen = useStore(s => s.setAddAgentOpen);const openTaskDetail = useStore(s => s.openTaskDetail);const [restoring, setRestoring] = useState(false);+ const [restoreNote, setRestoreNote] = useState<string | null>(null);// Each worker's actively-DOING ledger tasks, polled from hive/tasks.json —// rendered as a sticky note on the avatar card (click → task detail).const [doingByAgent, setDoingByAgent] = useState<Record<string, string[]>>({});@@ -48,73 +49,103 @@ export function AgentStrip({ config }: AgentStripProps) {const restoreTeam = async () => {if (restoring) return;setRestoring(true);+ setRestoreNote(null);const prevSel = useStore.getState().selectedId;+ // Tally every agent's outcome so the loop ALWAYS leaves a visible trace — the+ // original bug was that every failure path was console-only, so a click that+ // couldn't spawn anything looked like a dead button.+ let restored = 0;+ let alreadyLive = 0;+ const failures: string[] = [];try {for (const a of [...restorableAgents]) {- const provider = inferAgentProvider(a.command, a.provider);- const command = (a.command ?? '').trim() || (config ? buildSpawnCommand(config, a.model, provider) : '');- if (!command || !a.cwd) { useStore.getState().removeRestorableAgent(a.id); continue; }- const [exe, ...args] = tokenizeCommand(command);- const ptyId = a.ptyId ?? `pty-${a.id}`;- // An isolated agent's worktree SURVIVES an app restart on disk (it's only- // torn down on per-tab close / mid-session exit, not on quit). So re-enter- // that exact worktree as the cwd rather than re-isolating — `git worktree- // add` would conflict with the existing path/branch, and re-isolating would- // also lose the worktree's uncommitted work. cwd = the worktree means- // resume + seedSessionTranscript land in the CORRECT checkout.- // But the user may have manually pruned/deleted the worktree between runs —- // gitIsRepo (git rev-parse) returns false for a missing/invalid dir, so- // fall back to the base repo cwd rather than spawning into a dead path.- let cwd = a.cwd;- let worktreeGone = false;- if (a.worktreePath) {- if (await window.cth.gitIsRepo(a.worktreePath)) {- cwd = a.worktreePath;- } else {- worktreeGone = true;- console.warn(`[restore] worktree gone for ${a.id} (${a.worktreePath}); falling back to base repo ${a.cwd}`);+ // Per-agent guard: one agent's failure (or a rejected IPC call) must NEVER+ // abort the whole loop — an unhandled rejection here used to make the+ // entire restore a silent no-op after the first bad agent.+ try {+ const provider = inferAgentProvider(a.command, a.provider);+ const command = (a.command ?? '').trim() || (config ? buildSpawnCommand(config, a.model, provider) : '');+ if (!command || !a.cwd) {+ // No spawn recipe (an old entry persisted before `command`, with no+ // config to rebuild one). Keep it restorable and SAY why rather than+ // silently dropping it — silent removal read as "nothing happened".+ failures.push(`${a.name}: no saved command`);+ continue;}- }- const res = await window.cth.spawnPty({- id: ptyId,- cwd,- command: exe,- provider,- args,- cols: 100,- rows: 30,- // Worktree (if any) already exists on disk — cd into it, don't create a- // new one (re-isolating would conflict on the existing path/branch and- // lose its uncommitted work).- isolate: false,- // Continue the worker's prior CLI session if one was recorded — the- // main process picks the provider's resume flag (Claude --resume,- // agy --conversation) and for Claude reattaches the transcript. The- // agent id is preserved across restart, so its registry entry,- // memory.md and inbox reattach by id. No-op without a recorded session.- resume: true,- hive: { id: a.id, name: a.name, provider, cwd, role: a.description }- });- if (res.ok) {- useStore.getState().addAgent({- ...a,+ const [exe, ...args] = tokenizeCommand(command);+ const ptyId = a.ptyId ?? `pty-${a.id}`;+ // An isolated agent's worktree SURVIVES an app restart on disk (it's only+ // torn down on per-tab close / mid-session exit, not on quit). So re-enter+ // that exact worktree as the cwd rather than re-isolating — `git worktree+ // add` would conflict with the existing path/branch, and re-isolating would+ // also lose the worktree's uncommitted work. cwd = the worktree means+ // resume + seedSessionTranscript land in the CORRECT checkout.+ // But the user may have manually pruned/deleted the worktree between runs —+ // gitIsRepo (git rev-parse) returns false for a missing/invalid dir, so+ // fall back to the base repo cwd rather than spawning into a dead path.+ let cwd = a.cwd;+ let worktreeGone = false;+ if (a.worktreePath) {+ if (await window.cth.gitIsRepo(a.worktreePath)) {+ cwd = a.worktreePath;+ } else {+ worktreeGone = true;+ console.warn(`[restore] worktree gone for ${a.id} (${a.worktreePath}); falling back to base repo ${a.cwd}`);+ }+ }+ const res = await window.cth.spawnPty({+ id: ptyId,+ cwd,+ command: exe,provider,- ptyId,- archived: false,- status: 'idle',- // Surface the worktree fallback on the floor card; otherwise normal.- action: worktreeGone ? 'worktree gone — using base repo' : 'starting up',- // The worktree is no longer on disk — drop it so this agent is treated- // as a plain base-cwd agent going forward (a future restore won't keep- // re-probing a dead path).- worktreePath: worktreeGone ? undefined : a.worktreePath,- carrying: undefined,- currentStation: 'desk',- recentTextTs: Date.now()+ args,+ cols: 100,+ rows: 30,+ // Worktree (if any) already exists on disk — cd into it, don't create a+ // new one (re-isolating would conflict on the existing path/branch and+ // lose its uncommitted work).+ isolate: false,+ // Continue the worker's prior CLI session if one was recorded — the+ // main process picks the provider's resume flag (Claude --resume,+ // agy --conversation) and for Claude reattaches the transcript. The+ // agent id is preserved across restart, so its registry entry,+ // memory.md and inbox reattach by id. No-op without a recorded session.+ resume: true,+ hive: { id: a.id, name: a.name, provider, cwd, role: a.description }});- } else {- // Leave it restorable so the user can retry; don't block the rest.- console.error('[restore] spawn failed for', a.id, res.error);+ if (res.ok) {+ restored++;+ useStore.getState().addAgent({+ ...a,+ provider,+ ptyId,+ archived: false,+ status: 'idle',+ // Surface the worktree fallback on the floor card; otherwise normal.+ action: worktreeGone ? 'worktree gone — using base repo' : 'starting up',+ // The worktree is no longer on disk — drop it so this agent is treated+ // as a plain base-cwd agent going forward (a future restore won't keep+ // re-probing a dead path).+ worktreePath: worktreeGone ? undefined : a.worktreePath,+ carrying: undefined,+ currentStation: 'desk',+ recentTextTs: Date.now()+ });+ } else if ((res.error ?? '').includes('already exists')) {+ // A live PTY with this id is already running (e.g. respawned at boot or+ // by another path) — the agent isn't actually missing, so retire it from+ // the restorable list rather than reporting a phantom failure.+ alreadyLive++;+ useStore.getState().removeRestorableAgent(a.id);+ } else {+ // Leave it restorable so the user can retry — but record WHY so the+ // outcome is shown on the floor, not buried in the devtools console.+ failures.push(`${a.name}: ${res.error ?? 'spawn failed'}`);+ console.error('[restore] spawn failed for', a.id, res.error);+ }+ } catch (e) {+ failures.push(`${a.name}: ${e instanceof Error ? e.message : String(e)}`);+ console.error('[restore] error for', a.id, e);}}} finally {@@ -122,6 +153,12 @@ export function AgentStrip({ config }: AgentStripProps) {const sel = useStore.getState();if (prevSel && sel.agents.some((x) => x.id === prevSel)) sel.select(prevSel);setRestoring(false);+ // ALWAYS surface a result so the button can never look inert.+ const parts: string[] = [];+ if (restored) parts.push(`restored ${restored}`);+ if (alreadyLive) parts.push(`${alreadyLive} already live`);+ if (failures.length) parts.push(`${failures.length} failed — ${failures.join('; ')}`);+ setRestoreNote(parts.length ? parts.join(' · ') : 'nothing to restore');}};@@ -177,6 +214,19 @@ export function AgentStrip({ config }: AgentStripProps) {</PixelButton></span>)}+ {restoreNote && (+ <span+ style={{+ alignSelf: 'center', flexShrink: 0, maxWidth: 360,+ fontFamily: 'var(--cth-font-ui)', fontSize: 12,+ color: 'var(--cth-ink-500)',+ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis'+ }}+ title={restoreNote}+ >+ {restoreNote}+ </span>+ )}<PixelButtonvariant="secondary"size="lg"