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
docs: the env gate was never a security boundary, and two corrections
freshjuicezcca3503f929c
diff --git a/CLAUDE.md b/CLAUDE.mdindex f09972f10..61602262e 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1083,7 +1083,39 @@ else, and its context links must keep classifying across restarts).`NODETERM_NODE_ID`/`NODETERM_CANVAS_CONTROL`. Before this was shared, status hooks recovered thenode while both user-facing shims declared that same first-class Codex session outsidenodeterm. The SSH constants remain machine-neutral: the local record root is not valid on a- remote host and must never be baked into its copy.+ remote host and must never be baked into its copy — enforced by+ `main/remote-ssh/remote-shim-neutrality.guard.test.ts`, two legs (the exported neutral bodies+ carry no record root or prelude, and `remote-hooks.ts` cannot even NAME a parameterised+ builder), because the failure is silent and one-sided: a remote shim carrying the prelude keeps+ working, and the only symptom is this machine's userData layout sitting in a file on someone+ else's server.+ - **That prelude EXPORTS WHAT THE RECORD SAYS — it never decides.** `NODETERM_AGENT_ID` and+ `NODETERM_CANVAS_CONTROL` were once constants there (`codex`, granted); both are+ `buildPtyEnv`'s answers about the PANE, which labels a node with its OWN agent id+ (`custom:<uuid>` for a custom agent whose `baseAgent` is codex, not `codex`) and gates the grant+ on `canControlCanvas`. The constants therefore mislabelled every custom codex-based node and+ asserted a grant that agrees with the pane only because+ `SHARED_IDENTITY_CAPABLE ⊆ CANVAS_CONTROL_CAPABLE` — a coincidence that list's own comment+ invites the next shared-identity agent to break, and breaking it hands a tool shell a capability+ its pane was denied. So the record carries `agentId` + `canvasControl` INSIDE the 6-tuple HMAC,+ and the prelude reads them; the grant is exported only when the record grants it and is left+ UNSET otherwise (absent, never `0` — the shape both shims' `[ -z … ]` gates expect). The **pane+ echoes its own label** on `/codex-thread/{start,bind}` (a tmux session outlives the app, so+ after a restart nothing server-side still knows what agent a node runs), but the **grant is+ never echoed**: the route derives it with `canControlCanvas`, so there is ONE decider and a+ forged id cannot manufacture a grant the table refuses. The three preimage generations are+ **selected by the record's shape, never tried in turn** — a record naming an agent must not+ verify under a preimage that ignores one — and a pre-agent record's implied `codex` + grant is+ keyed on the LINE being absent, never on the value being empty, so nothing that names an agent+ falls back to the guess. The env vars were never a security boundary in any case (anyone who can+ run the shim can `export` them by hand); the per-node token is, and+ `docs/shared-codex-node-identity.md` states that argument in full.+ - **A shell that forwards this identity cannot be type-checked into correctness.** A handler that+ destructures the request without `agent`, and a record write that omits its optional trailing+ argument, are BOTH well-typed — so the whole dimension can be plumbed through core, the route,+ the launcher and the prelude, pass `npm run typecheck` and every unit test, and ship INERT.+ `main/codex-identity-record-wiring.test.ts` pins it at source level, the same remedy+ `hook-verified-parity.test.ts` uses for the same class of hole.- **Every generated sh client walks the SAME endpoint failover** (`nt_candidates`/`nt_adopt`,`core/agents/hook-endpoint-failover-sh.ts`) — issue #445, the endpoint-level twin of #384: asession is pinned for life to the endpoint PATH it got at tmux creation, so an app@@ -1395,8 +1427,9 @@ else, and its context links must keep classifying across restarts).injects `isRemoteNode`/`readRemoteFile`/`runRemoteCommand`, bounded tail reads), its hook-fedpath is jailed at ingest (`isSafeRemoteTranscriptPath`), and `resolveLinkTranscript` REFUSESthe local locators for remote nodes (they'd resolve a stranger's local transcript). Server- Edition passes no deps → local-only (context link is NOT wired there at all — `initContextLink`- is never called from `src/server`). Discovery is per-agent: claude installs a+ Edition IS wired (`src/server/context-link.ts` calls `initContextLink(ptyManager, {})`) but+ passes no remote deps → **local-only**, which is the complete answer there: that shell runs ON the+ host whose transcripts and tmux it reads, and SSH projects are a desktop-only concept. Discovery is per-agent: claude installs a`get-linked-context` skill; codex/gemini get an idempotent marker block(`<!-- nodeterm:get-linked-context:start/end -->`) merged into `~/.codex/AGENTS.md` /`~/.gemini/GEMINI.md`. On connect an idle-gated one-line note is injected into each endpointdiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 809a81164..4e3fb3986 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -186,7 +186,23 @@ shell is forked by the account-scoped app-server, so it has `CODEX_THREAD_ID` bu`NODETERM_*`. Managed hooks, local `nodeterm.sh`, and local `context.sh` must prepend`codexThreadIdentityResolverSh(codexThreadIdentityRoot())` before checking `NODETERM_NODE_ID` or`NODETERM_CANVAS_CONTROL`. Keep the SSH shim constants machine-neutral: baking the desktop/server-record path into a remote host is both wrong and a local-layout leak.+record path into a remote host is both wrong and a local-layout leak. A guard test enforces that+(`remote-shim-neutrality.guard.test.ts`), because the leak is silent — the remote shim keeps+working, and nothing goes red.++**That prelude may not decide anything a pane already decided.** It exports the agent id and the+canvas-control grant the ownership RECORD carries, never constants. They used to be hardcoded+(`codex`, granted) and both are `buildPtyEnv`'s answers: a custom agent inheriting the codex harness+is `custom:<uuid>`, and the grant comes from `canControlCanvas`. If you add a field the prelude+exports, put it inside the record's HMAC and have the desktop re-derive anything that grants a+capability — never accept the client's word for that. Withhold rather than assume: a tool shell+missing a verb its pane has is a bug report, a tool shell holding one its pane was denied is a+security question.++**A shell that forwards data into these records cannot be type-checked into correctness.** A+handler that destructures the request without the new field, and a call that omits an optional+trailing argument, are both well-typed — so the feature ships inert with a green suite. Pin the+wiring at source level (`codex-identity-record-wiring.test.ts`, `hook-verified-parity.test.ts`).**A stream error is not a throw you can catch.** When a write to `process.stdout`/`stderr` fails —`EPIPE` down a closed pipe, `EIO` after macOS revokes a closed terminal's tty — node reports it bydiff --git a/docs/gemini-agent.md b/docs/gemini-agent.mdindex c2daa7aba..0b5f723e3 100644--- a/docs/gemini-agent.md+++ b/docs/gemini-agent.md@@ -405,7 +405,7 @@ one stray keystroke.| In-place restart + cold-restore resume | yes | yes | N/A || ⌘M transcript view (`ChatPanel`) | **not implemented for gemini** — `CHAT_CAPABLE` is claude-only; the panel parses claude's JSONL | idem | idem || Find bar's transcript index | **claude only** (`readsClaudeTranscript`); the terminal-buffer search works normally | idem | N/A |-| Context links | yes (`CONTEXT_LINK_CAPABLE`), marker block in `~/.gemini/GEMINI.md` | **not wired at all** — `initContextLink` is never called from `src/server` | N/A |+| Context links | yes (`CONTEXT_LINK_CAPABLE`), marker block in `~/.gemini/GEMINI.md` | wired, **local-only** — `src/server/context-link.ts` calls `initContextLink(pty, {})` with no remote deps | N/A || Canvas control | yes, marker block + the sh+curl shim | **not wired** — `agent:control` has no server handler; pre-existing | N/A — no canvas || Managed accounts | **N/A** — accounts are a claude config-dir mechanism; `createAgentNode` never stamps an `accountId` on a non-claude node, and `CLAUDE_CONFIG_DIR` is irrelevant to `~/.gemini/settings.json` | idem | idem || Working indicator | the **brand mark, breathing** — `brandPulsePlan('gemini', …)` returns the `gemini-color.svg` asset and it pulses with a bloom, on the canvas badge and in the notch strip. Before this branch gemini fell through to the plain dot, which says "something is happening" but not *who* | **N/A** for the notch (there is none); the canvas badge works | the phone has its own SwiftUI renderer |diff --git a/docs/shared-codex-node-identity.md b/docs/shared-codex-node-identity.mdindex b84fd13d9..cc100b042 100644--- a/docs/shared-codex-node-identity.md+++ b/docs/shared-codex-node-identity.md@@ -87,22 +87,55 @@ Each record is a flat `key=value` text file, mode `0600`, **parsed as data, neveaccountId=<id or empty for system>nodeId=<owning canvas node>endpoint=<hook endpoint file path>+agentId=<the node's own agent id>+canvasControl=<1 or 0>signature=<base64url HMAC>```-### The signature binds the full 4-tuple+### Why the record names the agent++`agentId` and `canvasControl` were once **constants in the sh prelude** (`codex`, granted). Both are+facts about the PANE that only `hookServer.buildPtyEnv` knows: it labels a node with the node's own+agent id — which for a custom agent declaring `baseAgent: 'codex'` is `custom:<uuid>`, **not**+`codex` — and gates the grant on `canControlCanvas`. A constant is the prelude asserting what it+cannot know. It mislabelled every custom codex-based node, and it asserted a grant that agrees with+the pane today only because `SHARED_IDENTITY_CAPABLE ⊆ CANVAS_CONTROL_CAPABLE` — a coincidence that+list's own comment invites the next shared-identity agent to break, at which point the prelude would+be handing a tool shell a capability its pane was denied.++Who decides what: the **pane echoes its own label** on `/codex-thread/{start,bind}` (a tmux session+outlives the app, so after a restart nothing server-side still remembers what agent a node runs, and+the pane's environment is the only durable holder). The **grant is never echoed** — the route derives+it with `canControlCanvas`, the same predicate in the same process that gated the pane, so there is+exactly one decider and a forged agent id cannot manufacture a grant the capability table refuses.+Echoing the label is not a capability claim in any case: reaching that route requires a token this+instance minted for that node, so the caller *is* the node, and the record it shapes is re-exported+only into that node's own tool shells.++### The signature binds the full 6-tuple```-signature = base64url( HMAC-SHA256( key, threadId ␀ accountScope ␀ nodeId ␀ hookEndpoint ) )+signature = base64url( HMAC-SHA256(+ key, threadId ␀ accountScope ␀ nodeId ␀ hookEndpoint ␀ agentId ␀ canvasControl ) )````accountScope` is the account id, or the literal `system` for the system account (empty idnormalised). Because the scope is inside the preimage, a record signed for account **A** verifiesonly under scope **A** — copying it byte-for-byte into account **B**'s directory fails the MAC.-Verification is `timingSafeEqual`. Records written before this slice carry **no** `accountId=` line-and are verified with the original 3-tuple preimage **at the system scope only** — the one-back-compat door, and it is a system-scope door (a scope-less signature is never honoured under a-managed account).+`canvasControl` is inside it for the same class of reason: it names a capability the prelude exports+into an agent's shell, so an unsigned copy would be a grant anyone able to write the file could add.+Verification is `timingSafeEqual`.++**The three preimage generations are SELECTED by the record's shape, never tried in turn.** An+`agentId=` line ⇒ the 6-tuple and only that; no agent line but an `accountId=` line ⇒ the 4-tuple+(an S6-era record); neither, at the system scope ⇒ the original 3-tuple. Falling through would be+the door by which an agent id could be stripped or rewritten and the record still accepted. A+pre-agent record is read with the implied values **`codex` + granted** — exactly what it meant when+it was written, since it came from this same spine and codex is unconditionally canvas-control-capable+— and that fallback is keyed on the **line being absent**, never on the value being empty, so nothing+that names an agent can land back on the guess. `bindCodexThreadIdentity` likewise never downgrades a+record that already names its agent, and never promotes a pre-agent record's *implication* into a+signed claim.## Fail-closed ambiguity (the house rule, reused)@@ -140,6 +173,50 @@ The resolver:charset and the account-line/scope agreement before exporting. Its behaviour is proven under real`/bin/sh` against a real on-disk scope tree in `codex-thread-identity-sh.test.ts`.+**It exports what the record says; it does not decide.** `NODETERM_AGENT_ID` comes from the record's+`agentId`, and `NODETERM_CANVAS_CONTROL=1` is exported **only** when the record's `canvasControl` says+so — left UNSET otherwise, absent rather than `0`, the same shape `buildPtyEnv` produces and the shape+both shims' `[ -z … ]` gates expect. Withholding is the honest degrade: a tool shell loses a verb its+pane still has, whereas asserting a grant the pane was denied is the widening direction. A pre-agent+record (no `agentId=` line) means `codex` with the grant; a record whose agent id is outside the+accepted alphabet resolves **nothing at all** rather than falling back, because a record we did not+write is not one to trust field by field.++## The `NODETERM_*` env gate was never a security boundary++Worth stating plainly, because both the prelude and the two shims *look* like access control: they+open with `[ -z "$NODETERM_NODE_ID" ]` / `[ -z "$NODETERM_CANVAS_CONTROL" ]` and refuse to do+anything without them. Widening what SETS those variables — which is what recovering a shared-Codex+tool shell's identity does — therefore reads like widening what a local attacker can reach. It is+not, and this section is the argument.++Anyone who can run `nodeterm.sh` at all is already running as the user, in a shell, and can simply+`export NODETERM_NODE_ID=… NODETERM_CANVAS_CONTROL=1` by hand. The variables are a **routing and+no-op gate** — they tell a generated script which node it belongs to and keep it inert in the user's+ordinary terminals — not an authorization check. Nothing server-side consults them; they never+travel to the hook server at all.++What actually authorizes is on the other side of the socket:++- **Every route requires the app-wide bearer** (`X-NodeTerm-Hook-Token`, checked before any path+ dispatch in `hook-server.ts`), which lives in the 0600 endpoint file.+- **`/control/*` and `/context-link/*` additionally require the per-node capability**+ (`X-NodeTerm-Node-Token`) through the single `identityGate` → `verifyNodeToken` →+ `controlPolicy` path. The `nodeId` a caller names is a body field, and it is the token — not the+ environment — that decides whether that caller may speak for it. `forged` is a bare 403, and the+ strict verbs demand a `verified` verdict outright.+- **Context link narrows again by construction**: the link document is selected by the REQUESTER's+ node id (`linkDocs.get(req.nodeId)`), so a token-holding caller can only read the nodes in its own+ directional link map — an env var cannot widen that set.+- **`/codex-thread/{start,bind}`** — the routes that shape these very records — are strict: only a+ `verified` per-node token proceeds.++So the identity prelude changes *which sessions are correctly attributed to their node*, not *what+anyone is permitted to do*. This PR does not change the threat model. The one thing that genuinely+would is a value the prelude exports that nothing re-derives — which is exactly why+`canvasControl` is signed and why the route computes it with `canControlCanvas` rather than+accepting the pane's word for it.+## Supply-chain guardAccount ids arrive from hand-editable `settings.json` / `project.json`. Every id passesdiff --git a/docs/ssh-agent-skills.md b/docs/ssh-agent-skills.mdindex 576d890d2..52e52a871 100644--- a/docs/ssh-agent-skills.md+++ b/docs/ssh-agent-skills.md@@ -137,10 +137,12 @@ never linked to, and cannot read *through* an edge it does not itself hold (thedirectional). The token remains the outer boundary, exactly as for status hooks. The one valuethat reaches a remote command line — an opencode session id — is shell-quoted at that site.-`docs/`-worthy consequence: `src/server` never calls `initContextLink`, so context link is absent-on the Server Edition (it was before this change too). The route and the renderer are both in-`src/core`, so wiring it there is now just a call plus a decision about what "remote" means when-the server *is* the host.+`docs/`-worthy consequence: at the time of this change `src/server` did not call+`initContextLink`, so context link was absent on the Server Edition. **It is wired now** —+`src/server/context-link.ts` calls `initContextLink(ptyManager, {})` and keeps the link map in step+with the canvases on disk. It passes **no remote deps**, deliberately: that shell runs ON the host+whose transcripts and tmux it reads, so local-only is the complete answer there and SSH projects are+a desktop-only concept.## Testing