Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(hooks): sessions born on a bare host self-heal once a server appears
enes5be935df2deb
diff --git a/src/core/agents/hooks/managed-script.test.ts b/src/core/agents/hooks/managed-script.test.tsindex bcb0bcf17..1ea12f969 100644--- a/src/core/agents/hooks/managed-script.test.ts+++ b/src/core/agents/hooks/managed-script.test.ts@@ -18,6 +18,14 @@ describe('buildManagedScript', () => {it('still no-ops without node id / endpoint', () => {expect(s).toContain('NODETERM_NODE_ID')})+ it('gates the hook body on the NODE ID only (not the token) so an empty-endpoint session self-heals', () => {+ // A phone-spawned session created before any host process existed has a node id but no token+ // (its baked NODETERM_HOOK_ENDPOINT resolved empty). The gate must exit on a MISSING NODE ID,+ // NOT on a missing token — otherwise the failover in nt_send_request never runs and the session+ // stays dark until it is recreated. See buildManagedScript's "Empty-endpoint self-heal" note.+ expect(s).toContain('if [ -z "$NODETERM_NODE_ID" ]; then\n exit 0\nfi')+ expect(s).not.toContain('if [ -z "$NODETERM_HOOK_TOKEN" ] || [ -z "$NODETERM_NODE_ID" ]; then')+ })describe('deterministic hook-reply approvals (PermissionRequest wait branch)', () => {it('gates the wait branch on NODETERM_PERM_WAIT_SECS > 0', () => {diff --git a/src/core/agents/hooks/managed-script.ts b/src/core/agents/hooks/managed-script.tsindex 8fae7d291..33b6973a2 100644--- a/src/core/agents/hooks/managed-script.ts+++ b/src/core/agents/hooks/managed-script.ts@@ -14,6 +14,13 @@// unchanged — curl succeeds, no candidate scan, no re-POST. A host with no candidate files// behaves exactly as before (nothing posts).//+// Empty-endpoint self-heal: a session spawned when NO endpoint file existed yet (a phone injects+// NODETERM_NODE_ID + NODETERM_HOOK_ENDPOINT="$NT_EP" where $NT_EP resolved empty on a bare host)+// carries a node id but no token. The gate below keys on the NODE ID, not the token, so such a+// session still reaches nt_send_request — whose failover sources a live sibling endpoint (a Server+// Edition installed later, right next to it) and posts under it. Gating on the token instead would+// exit before that failover ran, leaving the session dark until it was recreated.+//// Deterministic hook-reply approvals (docs/hook-reply-approvals.md): when// NODETERM_PERM_WAIT_SECS is set (> 0) in the session env AND the incoming hook is a// PermissionRequest, the script generates a pendingId, drops the request JSON under@@ -31,7 +38,14 @@ export function buildManagedScript(agentId: string): string {'if [ -n "$NODETERM_HOOK_ENDPOINT" ] && [ -r "$NODETERM_HOOK_ENDPOINT" ]; then',' . "$NODETERM_HOOK_ENDPOINT" 2>/dev/null || :','fi',- 'if [ -z "$NODETERM_HOOK_TOKEN" ] || [ -z "$NODETERM_NODE_ID" ]; then',+ '# Gate on the NODE ID only — it is what marks a nodeterm-spawned session (a user\'s own',+ '# terminal has neither var and exits here, bit-for-bit legacy no-op). The token is NOT',+ '# required at this point: a phone-spawned session whose endpoint was empty/dead at spawn',+ '# (NODETERM_HOOK_ENDPOINT="" because no host process existed yet) carries a node id but no',+ '# token, and nt_send_request below sources a live sibling endpoint (e.g. a headless Server',+ '# Edition that came up AFTER the session) to heal it. Gating on the token here instead would',+ '# exit before that failover ever ran, leaving such a session dark until it was recreated.',+ 'if [ -z "$NODETERM_NODE_ID" ]; then',' exit 0','fi','payload=$(cat)',