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(agents): a duplicated target node id is refused — one project's grant can never speak for another's pane
Claude Code6b867a6d2b37
diff --git a/src/core/agents/agent-message-decide.ts b/src/core/agents/agent-message-decide.tsindex 417d8738b..159506ec0 100644--- a/src/core/agents/agent-message-decide.ts+++ b/src/core/agents/agent-message-decide.ts@@ -30,6 +30,11 @@ export type NotPermittedReason =| 'self-send'| 'unsupported-edition'| 'unaddressable-node-id'+ /** The target id names nodes in MORE THAN ONE project while panes are keyed by the bare id —+ * one global pane, several possible owners, and one of them may be ungranted. Refused because+ * the per-project grant cannot be attributed (PR #237 review I-1); its own word because the+ * human's fix is de-duplicating ids, not moving nodes. See `agent-message-scope.ts`. */+ | 'ambiguous-target-node-id'/** Which signal satisfied the delivery receipt (Task 3.4). */export type ReceiptSignal = 'newTurn' | 'working'diff --git a/src/core/agents/agent-message-scope.test.ts b/src/core/agents/agent-message-scope.test.tsindex 44bb5e54a..447a3a6d9 100644--- a/src/core/agents/agent-message-scope.test.ts+++ b/src/core/agents/agent-message-scope.test.ts@@ -91,22 +91,52 @@ describe('resolveDeliveryScope', () => {})})- it('resolves a DUPLICATE node id to the sender’s own project', () => {- // A cloned `project.json` gives two projects the same node id — this repo has shipped that bug- // once. The sender addresses the node it can see. This is a ROUTING answer only: sessions are- // keyed by the bare node id, so the two ids still name one pane, and no resolver can change- // that from here.+ it('REFUSES a DUPLICATE target id — the one global pane cannot be attributed to one project’s grant', () => {+ // A `project.json` that merely LISTS another project's node id (a clone, or a hostile file)+ // resolves "same-project" by node-set membership, but the session namespace is the BARE id:+ // both listings name ONE tmux pane, and only one of the projects may hold the messaging grant.+ // PR #237 review I-1 proved the escalation by execution (granted A delivered into ungranted+ // B's pane), so ambiguity is now a refusal in BOTH directions — the resolver cannot prove+ // which project's pane the caller means, and "pick the sender's" was exactly the hole.const cloned: ScopeProject[] = [{ id: 'p-alpha', nodes: [{ id: 'a-1' }, { id: 'dup' }] },{ id: 'p-clone', nodes: [{ id: 'c-1' }, { id: 'dup' }] }]expect(resolveDeliveryScope(cloned, 'a-1', 'dup')).toEqual({- kind: 'same-project',- projectId: 'p-alpha'+ kind: 'refused',+ reason: 'ambiguous-target-node-id',+ targetFound: true})expect(resolveDeliveryScope(cloned, 'c-1', 'dup')).toEqual({+ kind: 'refused',+ reason: 'ambiguous-target-node-id',+ targetFound: true+ })+ })++ it('the ambiguity refusal names its own reason, not cross-project — different fact, different action', () => {+ // cross-project = "you two do not share a project"; ambiguous = "the id names panes in more+ // than one, and one of them may be ungranted". The human fixes the second by de-duplicating+ // ids (re-adding the cloned folder mints fresh ones), not by moving nodes between projects.+ const cloned: ScopeProject[] = [+ { id: 'p-alpha', nodes: [{ id: 'a-1' }, { id: 'dup' }] },+ { id: 'p-clone', nodes: [{ id: 'dup' }] }+ ]+ const scope = resolveDeliveryScope(cloned, 'a-1', 'dup')+ const outcome = decideDelivery(facts({ notPermitted: scopeRefusal(scope) }))+ expect(outcome).toEqual({ kind: 'notPermitted', reason: 'ambiguous-target-node-id' })+ expect(RETRYABLE.notPermitted).toBe(false)+ })++ it('a UNIQUE target still resolves, whatever else the projects carry', () => {+ // The refusal must not cost the legitimate population: same store shape, no duplicate.+ const cloned: ScopeProject[] = [+ { id: 'p-alpha', nodes: [{ id: 'a-1' }, { id: 'mine' }] },+ { id: 'p-clone', nodes: [{ id: 'c-1' }] }+ ]+ expect(resolveDeliveryScope(cloned, 'a-1', 'mine')).toEqual({kind: 'same-project',- projectId: 'p-clone'+ projectId: 'p-alpha'})})diff --git a/src/core/agents/agent-message-scope.ts b/src/core/agents/agent-message-scope.tsindex 984ebe041..a50477237 100644--- a/src/core/agents/agent-message-scope.ts+++ b/src/core/agents/agent-message-scope.ts@@ -59,10 +59,13 @@ export interface ScopeProject {export type ScopeRefusal = Extract<NotPermittedReason,- 'self-send' | 'cross-project' | 'unaddressable-node-id'+ 'self-send' | 'cross-project' | 'unaddressable-node-id' | 'ambiguous-target-node-id'>export type DeliveryScope =+ /** `projectId` is the target pane's UNIQUE owning project (which the sender provably shares) —+ * the project whose `agentMessaging` grant authorizes the delivery. Uniqueness is part of the+ * contract: a target id claimed by two projects never produces this arm. */| { kind: 'same-project'; projectId: string }| {kind: 'refused'@@ -102,23 +105,26 @@ export type DeliveryScope =* backstop so that no future caller can forget this one. Both produce the identical* `notPermitted{reason:'self-send'}`, which the test asserts by running them.*- * ── A DUPLICATE NODE ID IS RESOLVED, NOT DISAMBIGUATED ──────────────────────────────────────────+ * ── A DUPLICATE TARGET ID IS REFUSED, NOT DISAMBIGUATED ─────────────────────────────────────────*- * A duplicate id across two projects (a cloned `project.json` — this repo has shipped that bug- * once) resolves to the SOURCE's project when the source's project is one of them: the sender- * addresses the node it can see.+ * A session's only key is the bare node id (`PtyManager.byPersistKey`, `paneOwner(persistKey)`,+ * tmux `nt-<nodeId>`); no project id appears anywhere in that namespace and nothing de-duplicates+ * ids when a second project carrying them is opened (a cloned `project.json` — this repo has+ * shipped that bug once). So a duplicate id across projects is ONE global pane with several+ * claimed owners, and the messaging grant is PER PROJECT: a hostile file for granted project A+ * that merely LISTS ungranted project B's node id would resolve "same-project" to A by node-set+ * membership, pass A's switch, and land in B's running pane — the confused deputy PR #237's+ * review proved by execution (I-1), live from the moment the user keeps A's clone notice.*- * That is a routing answer, NOT an isolation guarantee, and the earlier claim here that "the- * ambiguity never reaches the pane" was false. A session's only key is the bare node id- * (`PtyManager.byPersistKey`, `paneOwner(persistKey)`, tmux `nt-<nodeId>`); no project id appears- * anywhere in that namespace and nothing de-duplicates ids when a second project carrying them is- * opened. So a `project.json` that merely LISTS another project's node id resolves `same-project`- * here and lands in that node's one global pane — verified by execution, not reasoned about.+ * Therefore: the grant must gate the project that OWNS the target pane, and when the target id+ * appears in more than one persisted project no single owner can be proved, so the pair is+ * refused as `ambiguous-target-node-id` — never "pick the sender's". A unique target's owning+ * project is by construction the same project the sender shares, which is what `projectId` names.+ * The cost falls only on stores that already carry duplicate ids, which the id-repair path+ * (re-adding a folder mints fresh ids) exists to fix.*- * This resolver cannot close that: the ambiguity is in the session namespace, not in the scope- * question. What it can do is refuse the ids that make it worse, which is the check above.* **PR 5's delivery call must run `isSafeNodeId(targetNodeId)` before `paneOwner`** — a direct- * caller that skips this resolver gets neither guard.+ * caller that skips this resolver gets neither that guard nor this one.** `closed` and `unavailable` projects are deliberately NOT filtered out. A closed project's tmux* sessions keep running and are re-adopted on the next start — that is the whole premise of@@ -131,12 +137,23 @@ export function resolveDeliveryScope(targetNodeId: string): DeliveryScope {const has = (p: ScopeProject, id: string): boolean => p.nodes.some((n) => n.id === id)- const targetFound = projects.some((p) => has(p, targetNodeId))+ // Every project claiming the target id — the pane's POSSIBLE owners. The grant is evaluated+ // against the pane's owning project, so this set deciding the answer is the point, not a detail.+ const targetOwners = projects.filter((p) => has(p, targetNodeId))+ const targetFound = targetOwners.length > 0if (!isSafeNodeId(sourceNodeId) || !isSafeNodeId(targetNodeId))return { kind: 'refused', reason: 'unaddressable-node-id', targetFound }if (sourceNodeId === targetNodeId) return { kind: 'refused', reason: 'self-send', targetFound }const owner = projects.find((p) => has(p, sourceNodeId))- if (owner && has(owner, targetNodeId)) return { kind: 'same-project', projectId: owner.id }+ if (owner && has(owner, targetNodeId)) {+ // The id names panes in more than one project: ONE global tmux pane, several claimed owners,+ // and the sender's grant must not speak for the others (PR #237 review I-1). Refused with its+ // own word — "pick the sender's project" was exactly the confused-deputy hole.+ if (targetOwners.length > 1)+ return { kind: 'refused', reason: 'ambiguous-target-node-id', targetFound: true }+ // Unique: the target's owning project, which the sender provably shares.+ return { kind: 'same-project', projectId: targetOwners[0].id }+ }return { kind: 'refused', reason: 'cross-project', targetFound }}diff --git a/src/main/agent-messaging-switch.test.ts b/src/main/agent-messaging-switch.test.tsindex 906c0296d..83f093b42 100644--- a/src/main/agent-messaging-switch.test.ts+++ b/src/main/agent-messaging-switch.test.ts@@ -233,6 +233,44 @@ describe('end to end through a REAL WorkspaceStore — the desktop wiring, minusexpect(outcome).toEqual({ kind: 'notPermitted', reason: 'switch-off' })})+ it('CONFUSED DEPUTY (PR #237 review I-1): a granted project cannot reach an UNGRANTED project\'s pane through a duplicated node id', async () => {+ // The reviewer's proved escalation: hostile/cloned project A sets `agentMessaging: true` AND+ // lists a node id that legitimate, ungranted project B is actually running. Panes are keyed by+ // the BARE node id (`nt-<id>`), so pre-fix, once the user kept A's notice, A's grant bought a+ // write into B's one global pane — outcome `delivered`. Now the duplicated target id is+ // refused at scope time with its own name: the pane cannot be attributed to a single+ // project's grant, and A's consent must never speak for B.+ const store = new WorkspaceStore()+ const attacker = project({+ id: 'attacker',+ name: 'cloned-hostile',+ cwd: projRoot,+ agentMessaging: true,+ capabilityAck: { agentMessaging: 'kept' },+ nodes: [+ { id: 'atk-1', kind: 'terminal', position: { x: 0, y: 0 }, size: { width: 1, height: 1 }, title: 'Atk', color: '#fff', group: null, agentId: 'claude' },+ // The hostile listing: victim-1 is NOT this project's node — it is B's.+ { id: 'victim-1', kind: 'terminal', position: { x: 0, y: 0 }, size: { width: 1, height: 1 }, title: 'Stolen', color: '#fff', group: null, agentId: 'claude' }+ ] as Project['nodes']+ })+ const victimProject = project({+ id: 'victim-proj',+ name: 'legit-ungranted',+ nodes: [+ { id: 'victim-1', kind: 'terminal', position: { x: 0, y: 0 }, size: { width: 1, height: 1 }, title: 'Victim', color: '#fff', group: null, agentId: 'claude' }+ ] as Project['nodes']+ })+ await store.save({ version: 2, activeProjectId: 'attacker', projects: [attacker, victimProject] })+ const deps = storeDeps(store)+ const { outcome, reply } = await deliverFromControl(+ { verb: 'send', sourceNodeId: 'atk-1', targetNodeId: 'victim-1', body: 'sneak' } as never,+ deps+ )+ expect(outcome).toEqual({ kind: 'notPermitted', reason: 'ambiguous-target-node-id' })+ expect(reply.ok).toBe(false)+ expect(deps.sent).toEqual([]) // NOT delivered — nothing reached any pane+ })+it('an INLINE (cwd-less) project grants through its entry too', async () => {const store = new WorkspaceStore()await store.save(diff --git a/src/main/agent-messaging.ts b/src/main/agent-messaging.tsindex d959cb521..3310949b3 100644--- a/src/main/agent-messaging.ts+++ b/src/main/agent-messaging.ts@@ -163,7 +163,11 @@ const NOT_PERMITTED_TEXT: Record<NotPermittedReason, string> = {'cross-project': 'the target node is not in the sending node\'s project.','self-send': 'a node cannot message itself.','unsupported-edition': 'agent messaging does not exist on this edition.',- 'unaddressable-node-id': 'that node id cannot be addressed safely.'+ 'unaddressable-node-id': 'that node id cannot be addressed safely.',+ 'ambiguous-target-node-id':+ 'that node id exists in more than one project, so the target pane cannot be attributed to a ' ++ 'single project\'s messaging grant. De-duplicate the id (re-add the cloned folder to mint ' ++ 'fresh ids) before messaging it.'}/**