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(windows): guard node-pty ConPTY AttachConsole crash + main resilience (#65)
Julian2f48f82644ce
diff --git a/package.json b/package.jsonindex ebc079d8..2def6630 100644--- a/package.json+++ b/package.json@@ -15,7 +15,7 @@"build": "electron-vite build && npm run copy:main-assets","copy:main-assets": "node tools/copy-main-assets.cjs","preview": "electron-vite preview",- "postinstall": "electron-rebuild -f && node tools/ensure-pty-perms.cjs",+ "postinstall": "electron-rebuild -f && node tools/ensure-pty-perms.cjs && node tools/patch-node-pty-conpty.cjs","typecheck:node": "tsc --noEmit -p tsconfig.node.json","typecheck:web": "tsc --noEmit -p tsconfig.web.json","typecheck": "npm run typecheck:node && npm run typecheck:web",diff --git a/src/main/index.ts b/src/main/index.tsindex d868dcc5..a170708b 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -37,6 +37,19 @@ import {} from '../shared/agentProvider';const isDev = !!process.env.ELECTRON_RENDERER_URL;++// Keep the hive alive through transient faults. The floor is a long-running+// multi-agent supervisor — a single stray throw (e.g. node-pty's ConPTY console+// helper choking when a fast-exiting agent CLI's console is already gone) must+// NOT take the whole app and every running agent down with it. Log and continue+// rather than letting the default handler exit the process.+process.on('uncaughtException', (err) => {+ console.error('[main] uncaughtException (kept alive):', err);+});+process.on('unhandledRejection', (reason) => {+ console.error('[main] unhandledRejection (kept alive):', reason);+});+const ptyManager = new PtyManager();/** Live PTY id → its hive agent id, recorded at spawn. The pty:kill handler only* gets the PTY id, so this lets a closed tab archive the right registry agent. */diff --git a/tools/patch-node-pty-conpty.cjs b/tools/patch-node-pty-conpty.cjsnew file mode 100644index 00000000..43f6bfdd--- /dev/null+++ b/tools/patch-node-pty-conpty.cjs@@ -0,0 +1,41 @@+#!/usr/bin/env node+'use strict';+/**+ * Windows-only node-pty crash guard, re-applied on every install (postinstall,+ * after electron-rebuild). No-op on non-Windows and when already patched.+ *+ * node-pty forks `conpty_console_list_agent.js` to enumerate console processes+ * when a pty is killed/exits. For a child whose console is already gone — e.g.+ * an agent CLI that manages its own console and exits fast (Antigravity's `agy`)+ * — `getConsoleProcessList(shellPid)` throws "AttachConsole failed" UNCAUGHT in+ * that forked helper, which cascades into a whole-app crash (exit 255). Wrap it+ * so it degrades to an empty list instead.+ */+const { readFileSync, writeFileSync, existsSync } = require('node:fs');+const { join } = require('node:path');++if (process.platform !== 'win32') process.exit(0);++const agent = join(__dirname, '..', 'node_modules', 'node-pty', 'lib', 'conpty_console_list_agent.js');+if (!existsSync(agent)) process.exit(0);++const src = readFileSync(agent, 'utf8');+// Idempotent: only patch the original unguarded form.+if (!src.includes('var consoleProcessList = getConsoleProcessList(shellPid);')) process.exit(0);++const guarded =+ 'var consoleProcessList = [];\n' ++ '// PATCHED: AttachConsole can fail when the shell console is already gone (e.g.\n' ++ "// a fast-exiting agent CLI that owns its console). Don't let the uncaught throw\n" ++ '// crash this forked helper and cascade into a whole-app crash.\n' ++ 'try { consoleProcessList = getConsoleProcessList(shellPid); } catch (e) { consoleProcessList = []; }';++let out = src.replace('var consoleProcessList = getConsoleProcessList(shellPid);', guarded);+out = out.replace(+ 'process.send({ consoleProcessList: consoleProcessList });',+ 'try { process.send({ consoleProcessList: consoleProcessList }); } catch (e) { /* parent gone */ }'+);+if (out !== src) {+ writeFileSync(agent, out, 'utf8');+ console.log('[patch-node-pty-conpty] guarded conpty_console_list_agent against AttachConsole crash');+}