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): move the hook payload off curl's argv (temp file, not --data-urlencode "payload=$payload")
enesa179c140d809
diff --git a/src/core/agents/hooks/managed-script.test.ts b/src/core/agents/hooks/managed-script.test.tsindex bde586ced..cc9d7a378 100644--- a/src/core/agents/hooks/managed-script.test.ts+++ b/src/core/agents/hooks/managed-script.test.ts@@ -40,7 +40,9 @@ describe('buildManagedScript', () => {expect(s).not.toContain('-H "X-Nodeterm-Hook-Token')expect(s).not.toContain('-H "X-Nodeterm-Node-Token')expect((s.match(/\n *curl -sS/g) ?? []).length).toBe(4)- expect((s.match(/\n *nt_hook_headers \|/g) ?? []).length).toBe(4)+ // The two answered POSTs are wrapped in a `{ … ; rm … } &` group that self-deletes the payload+ // temp file, so `nt_hook_headers |` there is preceded by `{ ` — match either form.+ expect((s.match(/\n *(\{ )?nt_hook_headers \|/g) ?? []).length).toBe(4)expect((s.match(/--config -/g) ?? []).length).toBe(4)})@@ -84,7 +86,11 @@ describe('buildManagedScript', () => {expect(s).toContain('if [ "$nt_decision" = "allow" ] || [ "$nt_decision" = "deny" ]; then')const answered = s.match(/--data-urlencode "nodeterm_answered=\$\{nt_decision\}"/g) ?? []expect(answered.length).toBe(2)- const backgrounded = s.match(/--data-urlencode "payload=\$\{payload\}" >\/dev\/null 2>&1 &/g) ?? []+ // Each backgrounded answered POST reads the payload from the temp file and self-deletes it+ // after curl returns (the file must never outlive its reader).+ const backgrounded = s.match(+ /--data-urlencode "payload@\$\{nt_payload_file\}" >\/dev\/null 2>&1; rm -f "\$nt_payload_file" 2>\/dev\/null \|\| :; \} &/g+ ) ?? []expect(backgrounded.length).toBe(2)expect(s).toContain('--max-time 1')})@@ -121,6 +127,28 @@ describe('buildManagedScript', () => {})})+ describe('payload stays OFF curl argv (/proc leak + E2BIG fix)', () => {+ it('never puts the payload on the command line', () => {+ // `--data-urlencode "payload=$payload"` would publish the full hook body via+ // /proc/<pid>/cmdline and cap the event at the kernel argv limit (E2BIG on a big diff).+ expect(s).not.toContain('payload=${payload}')+ })+ it('writes the payload to a 0600 temp file after reading stdin', () => {+ expect(s).toContain('nt_payload_file="$HOME/.nodeterm/pending/payload-$$.tmp"')+ expect(s).toContain('(umask 077; printf %s "$payload" > "$nt_payload_file")')+ })+ it('every POST reads the payload from the temp file with payload@file', () => {+ // Four POSTs: request (unix-socket + TCP) and answered (unix-socket + TCP).+ const atFile = s.match(/--data-urlencode "payload@\$\{nt_payload_file\}"/g) ?? []+ expect(atFile.length).toBe(4)+ })+ it('deletes the temp file on every exit path (hot path, answered, no-transport, timeout)', () => {+ expect(s).toContain('{ nt_send_request; rm -f "$nt_payload_file" 2>/dev/null || :; } &')+ expect(s).toContain('if [ "$nt_payload_owned" != 1 ]; then rm -f "$nt_payload_file" 2>/dev/null || :; fi')+ expect(s).toContain('rm -f "$nt_pending_file" "$nt_payload_file" 2>/dev/null || :')+ })+ })+describe('the Codex thread-identity prelude', () => {// It is prepended for EVERY agent, not just codex — the generated scripts all change. That is// intended: the block is inert without CODEX_THREAD_ID, which no other agent's tool shell@@ -199,13 +227,16 @@ describe('buildManagedScript', () => {})it('returns curl exit status from nt_request_post (no `|| true` masking) and returns 1 with no transport', () => {// The POST lines end at `>/dev/null 2>&1` (status preserved), NOT `>/dev/null 2>&1 || true`.- expect(s).not.toContain('--data-urlencode "payload=${payload}" >/dev/null 2>&1 || true')+ expect(s).not.toContain('--data-urlencode "payload@${nt_payload_file}" >/dev/null 2>&1 || true')expect(s).toContain(' else\n return 1\n fi')})it('perm-wait branch advertises the ask in the FOREGROUND (before the poll), non-perm backgrounds it', () => {// Foreground in perm-wait (pendingId reaches primary-or-fallback before the answer poll begins),// backgrounded otherwise so a live session's hot path never blocks.- expect(s).toContain('if [ -n "$nt_pending" ]; then\n nt_send_request\nelse\n nt_send_request &\nfi')+ expect(s).toContain('if [ -n "$nt_pending" ]; then\n nt_send_request\nelse\n')+ // Non-perm-wait backgrounds the POST and self-deletes the payload temp file after it (and its+ // one fallback retry) return, so the file never outlives its reader.+ expect(s).toContain(' { nt_send_request; rm -f "$nt_payload_file" 2>/dev/null || :; } &\nfi')// The request POST carries nodeterm_pending_id, so the fallback learns the ask too.expect(s).toContain('--data-urlencode "nodeterm_pending_id=${nt_pending}"')})diff --git a/src/core/agents/hooks/managed-script.ts b/src/core/agents/hooks/managed-script.tsindex d028b1382..3fa6b55c1 100644--- a/src/core/agents/hooks/managed-script.ts+++ b/src/core/agents/hooks/managed-script.ts@@ -157,6 +157,16 @@ export function buildManagedScript('if [ -z "$payload" ]; then',' exit 0','fi',+ '# Keep the payload OFF curl\'s argv. `--data-urlencode "payload=$payload"` puts the full hook',+ '# body (Edit/Write tool_input, the submitted prompt, the last assistant message) into',+ '# /proc/<pid>/cmdline — world-readable by every co-tenant for the life of each curl, the exact',+ '# leak the headers already avoid via --config. It also caps the event at the kernel argv limit',+ '# (~128KB on Linux): a large PreToolUse/PostToolUse body makes curl\'s execve fail E2BIG and the',+ '# event is dropped SILENTLY (a lost Stop leaves the node stuck RUNNING). A 0600 temp file read',+ '# back with `payload@file` fixes both; it is deleted by whichever POST last reads it (below).',+ 'nt_payload_file="$HOME/.nodeterm/pending/payload-$$.tmp"',+ '(umask 077; mkdir -p "$HOME/.nodeterm/pending") 2>/dev/null || :',+ '(umask 077; printf %s "$payload" > "$nt_payload_file") 2>/dev/null || :','# Deterministic-approval request: only for a PermissionRequest hook while the wait is armed.','# `nt_pending` stays empty otherwise, so the POST tag and the poll loop below are both inert.','nt_pending=""',@@ -224,7 +234,7 @@ export function buildManagedScript(' --data-urlencode "nodeId=${NODETERM_NODE_ID}" \\',' --data-urlencode "version=${NODETERM_HOOK_VERSION}" \\',' --data-urlencode "nodeterm_pending_id=${nt_pending}" \\',- ' --data-urlencode "payload=${payload}" >/dev/null 2>&1',+ ' --data-urlencode "payload@${nt_payload_file}" >/dev/null 2>&1',' elif [ -n "$NODETERM_HOOK_PORT" ]; then',' nt_hook_headers |',` curl -sS -X POST "http://127.0.0.1:\${NODETERM_HOOK_PORT}/hook/${agentId}" \\`,@@ -233,7 +243,7 @@ export function buildManagedScript(' --data-urlencode "nodeId=${NODETERM_NODE_ID}" \\',' --data-urlencode "version=${NODETERM_HOOK_VERSION}" \\',' --data-urlencode "nodeterm_pending_id=${nt_pending}" \\',- ' --data-urlencode "payload=${payload}" >/dev/null 2>&1',+ ' --data-urlencode "payload@${nt_payload_file}" >/dev/null 2>&1',' else',' return 1',' fi',@@ -261,7 +271,10 @@ export function buildManagedScript('if [ -n "$nt_pending" ]; then',' nt_send_request','else',- ' nt_send_request &',+ ' # Background the POST (a live session\'s hot path never blocks) and delete the payload temp',+ ' # file only AFTER it — and its one fallback retry — have finished reading it, so the file',+ ' # never outlives its reader. The perm-wait branch keeps the file for its "answered" POST.',+ ' { nt_send_request; rm -f "$nt_payload_file" 2>/dev/null || :; } &','fi','# Hold the hook open for a phone/canvas answer file, polling every 0.5s up to the armed seconds.','if [ -n "$nt_pending" ]; then',@@ -277,9 +290,14 @@ export function buildManagedScript(' # for a text-only reply, is not until the turn\'s Stop). Backgrounded (&) + short --max-time so',' # the decision JSON below is NEVER delayed. Same POST mechanism as above, tagged',' # nodeterm_answered=<decision>; only for a valid allow/deny (no POST on a bad/timed-out answer).',+ ' # The payload temp file is still needed here (the foreground nt_send_request above read',+ ' # it, and this backgrounded "answered" POST reads it again). Whichever backgrounded POST',+ ' # is launched self-deletes it after curl returns; if none is (no transport, or a decision',+ ' # that is neither allow nor deny), it is deleted inline just below.',+ ' nt_payload_owned=0',' if [ "$nt_decision" = "allow" ] || [ "$nt_decision" = "deny" ]; then',' if [ -n "$NODETERM_HOOK_SOCK" ]; then',- ' nt_hook_headers |',+ ' { nt_hook_headers |',` curl -sS -X POST --unix-socket "$NODETERM_HOOK_SOCK" "http://localhost/hook/${agentId}" \\`,' --connect-timeout 0.5 --max-time 1 --config - \\',' -H "Content-Type: application/x-www-form-urlencoded" \\',@@ -287,9 +305,10 @@ export function buildManagedScript(' --data-urlencode "version=${NODETERM_HOOK_VERSION}" \\',' --data-urlencode "nodeterm_pending_id=${nt_pending}" \\',' --data-urlencode "nodeterm_answered=${nt_decision}" \\',- ' --data-urlencode "payload=${payload}" >/dev/null 2>&1 &',+ ' --data-urlencode "payload@${nt_payload_file}" >/dev/null 2>&1; rm -f "$nt_payload_file" 2>/dev/null || :; } &',+ ' nt_payload_owned=1',' elif [ -n "$NODETERM_HOOK_PORT" ]; then',- ' nt_hook_headers |',+ ' { nt_hook_headers |',` curl -sS -X POST "http://127.0.0.1:\${NODETERM_HOOK_PORT}/hook/${agentId}" \\`,' --connect-timeout 0.5 --max-time 1 --config - \\',' -H "Content-Type: application/x-www-form-urlencoded" \\',@@ -297,9 +316,11 @@ export function buildManagedScript(' --data-urlencode "version=${NODETERM_HOOK_VERSION}" \\',' --data-urlencode "nodeterm_pending_id=${nt_pending}" \\',' --data-urlencode "nodeterm_answered=${nt_decision}" \\',- ' --data-urlencode "payload=${payload}" >/dev/null 2>&1 &',+ ' --data-urlencode "payload@${nt_payload_file}" >/dev/null 2>&1; rm -f "$nt_payload_file" 2>/dev/null || :; } &',+ ' nt_payload_owned=1',' fi',' fi',+ ' if [ "$nt_payload_owned" != 1 ]; then rm -f "$nt_payload_file" 2>/dev/null || :; fi',' if [ "$nt_decision" = "allow" ]; then',' printf \'%s\\n\' \'{"hookSpecificOutput":{"hookEventName":"PermissionRequest","decision":{"behavior":"allow"}}}\'',' elif [ "$nt_decision" = "deny" ]; then',@@ -310,8 +331,8 @@ export function buildManagedScript(' sleep 0.5 2>/dev/null || sleep 1',' nt_i=$((nt_i + 1))',' done',- ' # Timed out: clean up the request file and print nothing → Claude shows its normal prompt.',- ' rm -f "$nt_pending_file" 2>/dev/null || :',+ ' # Timed out: clean up the request + payload files and print nothing → Claude shows its normal prompt.',+ ' rm -f "$nt_pending_file" "$nt_payload_file" 2>/dev/null || :','fi','exit 0',''