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: keep one-way link direction through CLI links, bad readers and ropes (#852)
Erik Zwepa500163b90e2
diff --git a/CLAUDE.md b/CLAUDE.mdindex f5815a2d5..fce44e5f0 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -4898,10 +4898,14 @@ command-bearing opens; this does not add a human-confirm dialog or change mobile`project.json` files load unchanged. The rule is `linkReadPairs` (`shared/canvas-link.ts`), and`buildLinkMap` is where it BITES: the non-reading side gets no map entry, so main serves it nodocument and the resolver refuses it — enforcement is at the read, not in the discovery note. A- `reader` naming neither endpoint authorizes nobody (fail closed). Set it from the context-link- edge's right-click menu (both / A reads B / B reads A; arrowheads point at the reader) or with+ `reader` naming neither endpoint, or any present non-string value, authorizes nobody (fail closed)+and is carried VERBATIM through every conversion — dropping it as "absent" would widen it to two-way+on the next save. Set it from the context-link+ edge's right-click menu (both / A reads B / B reads A; arrowheads point at the reader — a rope+drawn over a hidden link resolves it by endpoint pair via `contextLinkForEdge`) or with`link --one-way` (`--from` reads). On the canvas it rides `edge.data.reader`; every bridge↔edge- conversion goes through `bridgeToEdge`/`edgeToBridge` (renderer/lib/noteLink.ts) and the server+ conversion goes through `bridgeToEdge`/`edgeToBridge` (renderer/lib/noteLink.ts; CLI-planned+bridges enter live state only via `appendBridgeEdges`) and the servermerge keeps it (`serverChange.edgeRef`) — a field-by-field `{id, source, target}` copy silentlyturns a one-way link two-way again. A flip that GRANTS read access sends the same one-shotdiscovery note a new link sends; losing access sends nothing, like removing a link. Note: thediff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex dac4d88ae..073b26953 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -603,7 +603,7 @@ import { answerHostedRequest, type HostedAnswer } from '../lib/hostedOwner'import { headRequest, type QueuedRequest } from '../lib/hostedPendingQueue'import { useHostedPending } from '../state/hostedPending'import { hostedInfoFor, isHostedReadOnly, useHostedTeams } from '../state/hostedTeams'-import { bridgeToEdge, buildContextLinkNote, buildNotePushMessage, classifyLink, edgeToBridge, gainedReaders, hiddenLinkIds, linkIdsCoveredByRopes, linkReadPairs, pairKey, planBridges, withLinkReader, type LinkEndpoint } from '../lib/noteLink'+import { appendBridgeEdges, bridgeToEdge, buildContextLinkNote, contextLinkForEdge, buildNotePushMessage, classifyLink, edgeToBridge, gainedReaders, hiddenLinkIds, linkIdsCoveredByRopes, linkReadPairs, pairKey, planBridges, withLinkReader, type LinkEndpoint } from '../lib/noteLink'import {deliveriesToRetire,launchesToFire,@@ -2818,7 +2818,11 @@ export function Canvas() {// A context link is two-way unless it names a one-way reader (issue #852).const readers = isNote ? [e.target] : linkReadPairs(edgeToBridge(e)).map((p) => p.reader)const oneWay = !isNote && readers.length < 2- const baseLabel = isNote ? '🗒 note' : oneWay ? '→ context (one-way)' : '⇄ context'+ const baseLabel = isNote+ ? '🗒 note'+ : readers.length === 0+ ? '⊘ context (invalid direction)'+ : oneWay ? '→ context (one-way)' : '⇄ context'return {...e,type: 'floating',@@ -2835,8 +2839,17 @@ export function Canvas() {...(readers.includes(e.source) ? { markerStart: arrow } : {})}})- const ropeCoversLink = new Set(- linkEdges.filter((e) => hiddenLinks.has(e.id)).map((e) => pairKey(e.source, e.target))+ // The covered link's label, by pair, so a selected rope still says which way its hidden+ // context link reads (issue #852) — the rope's own arrow shows lineage, not reading.+ const ropeCoversLink = new Map(+ linkEdges.filter((e) => hiddenLinks.has(e.id)).map((e) => {+ const n = linkReadPairs(edgeToBridge(e)).length+ const label =+ n === 2+ ? '⇄ context · ⌫ to remove'+ : `${n === 1 ? '→ context (one-way)' : '⊘ context (invalid direction)'} · ⌫ to remove`+ return [pairKey(e.source, e.target), label] as const+ }))// Ropes: colour from the source's agent, dashed + ⏳ while the target still waits on the// source, white + a removal hint while selected, clay + flowing while the target is a driven@@ -2860,7 +2873,7 @@ export function Canvas() {const label = v.waiting? `${WAIT_LABEL} · ⌫ to stop waiting`: ropeCoversLink.has(pairKey(e.source, e.target))- ? '⇄ context · ⌫ to remove'+ ? `${ropeCoversLink.get(pairKey(e.source, e.target))} · right-click for direction`: '⌫ to remove'return {...base,@@ -4695,8 +4708,12 @@ export function Canvas() {// Note links (sticky → terminal) are one-way by nature and get no menu.const onEdgeContextMenu = useCallback((e: React.MouseEvent, edge: Edge) => {- const link = linkEdgesRef.current.find((b) => b.id === edge.id)+ // A rope drawn over a context link (open-agent / spawn-team / --after) hides that link and+ // keeps the pixels, so its right-click must reach the covered link by endpoint pair — the+ // same rule the removal paths use. A rope with nothing under it gets no menu.+ const link = contextLinkForEdge(edge.id, linkEdgesRef.current, controlEdgesRef.current)if (!link) return+ const viaRope = link.id !== edge.idconst nodeOf = (id: string) => nodesRef.current.find((n) => n.id === id)if (nodeOf(link.source)?.type === 'sticky' || nodeOf(link.target)?.type === 'sticky') returne.preventDefault()@@ -4732,7 +4749,7 @@ export function Canvas() {option(`${b} reads ${a} only`, link.target),{ type: 'separator' },{- label: 'Remove link',+ label: viaRope ? 'Remove context link (keeps the rope)' : 'Remove link',danger: true,onClick: () => {setLinkEdges((es) => es.filter((x) => x.id !== link.id))@@ -13862,7 +13879,7 @@ export function Canvas() {useProjects.getState().appendCanvasLinks(offCanvas.project.id, { bridges: plan.edges })void writeDisk()} else {- setLinkEdges((es) => [...es, ...plan.edges])+ setLinkEdges((es) => appendBridgeEdges(es, plan.edges))markDirty()}}diff --git a/src/renderer/canvas/context-link-direction.source.test.ts b/src/renderer/canvas/context-link-direction.source.test.tsindex b7df4ed96..e28b5f433 100644--- a/src/renderer/canvas/context-link-direction.source.test.ts+++ b/src/renderer/canvas/context-link-direction.source.test.ts@@ -45,4 +45,17 @@ describe('one-way context links — Canvas wiring (source pins)', () => {const body = src.slice(start, start + 2000)expect(body).toContain("'one-way' in args")})++ it('CLI-created bridges become live edges only through appendBridgeEdges (review P1)', () => {+ // Appending planBridges output raw puts `reader` top-level, where edgeToBridge never looks.+ expect(src).not.toMatch(/setLinkEdges\(\(es\) => \[\.\.\.es,/)+ expect(src).toContain('setLinkEdges((es) => appendBridgeEdges(es, plan.edges))')+ })++ it('right-clicking a rope resolves the context link it covers (review P2b)', () => {+ const start = src.indexOf('const onEdgeContextMenu = useCallback(')+ const body = src.slice(start, start + 1500)+ expect(body).toContain('contextLinkForEdge(')+ expect(body).toContain('controlEdgesRef.current')+ })})diff --git a/src/renderer/lib/noteLink.test.ts b/src/renderer/lib/noteLink.test.tsindex b8f31cbbc..4fbb5a90f 100644--- a/src/renderer/lib/noteLink.test.ts+++ b/src/renderer/lib/noteLink.test.ts@@ -9,8 +9,11 @@ import {linkIdsCoveredByRopes,pairKey,planBridges,+ appendBridgeEdges,bridgeToEdge,- edgeToBridge+ contextLinkForEdge,+ edgeToBridge,+ linkReadPairs} from './noteLink'import type { CanvasNodeState } from '@shared/types'@@ -428,9 +431,60 @@ describe('bridge ⇄ React Flow edge (issue #852)', () => {expect(edgeToBridge(e)).toEqual(b)})- it('drops display-only edge fields and a non-string reader', () => {+ it('drops display-only edge fields', () => {expect(- edgeToBridge({ id: 'x', source: 'a', target: 'b', selected: true, data: { reader: 7, anchor: 'h' } } as never)+ edgeToBridge({ id: 'x', source: 'a', target: 'b', selected: true, data: { anchor: 'h' } } as never)).toEqual({ id: 'x', source: 'a', target: 'b' })})++ // A present-but-invalid reader is a restriction nobody can satisfy, and it must STAY one: if a+ // conversion dropped it, the next save would write an unrestricted two-way link.+ it.each([null, 42, '', 'z', { x: 1 }])('keeps an invalid reader %j through load and save', (reader) => {+ const b = { id: 'bridge-a-b', source: 'a', target: 'b', reader } as never+ const back = edgeToBridge(bridgeToEdge(b))+ expect(back).toEqual(b)+ expect(linkReadPairs(back)).toEqual([])+ })+})++describe('appendBridgeEdges (issue #852 review P1)', () => {+ it('a one-way bridge from planBridges keeps its reader once it is a live edge', () => {+ const lookup = () => ({ kind: 'terminal', contextCapable: true })+ const plan = planBridges('n1', ['n2'], lookup, [], { oneWay: true })+ const live = appendBridgeEdges([], plan.edges)+ expect(live).toEqual([{ id: 'bridge-n1-n2', source: 'n1', target: 'n2', data: { reader: 'n1' } }])+ expect(live.map(edgeToBridge)).toEqual(plan.edges)+ })++ it('never mutates the existing edge array', () => {+ const es = [{ id: 'e', source: 'a', target: 'b' }]+ const out = appendBridgeEdges(es, [{ id: 'f', source: 'c', target: 'd' }])+ expect(es).toHaveLength(1)+ expect(out).toHaveLength(2)+ })})++describe('contextLinkForEdge (issue #852 review P2b)', () => {+ const links = [{ id: 'bridge-a-b', source: 'a', target: 'b' }]+ const ropes = [+ { id: 'ctrl-b-a', source: 'b', target: 'a' },+ { id: 'ctrl-a-c', source: 'a', target: 'c' }+ ]++ it('a context link resolves to itself', () => {+ expect(contextLinkForEdge('bridge-a-b', links, ropes)?.id).toBe('bridge-a-b')+ })++ it('a rope resolves to the context link it covers (by endpoint pair, either direction)', () => {+ expect(contextLinkForEdge('ctrl-b-a', links, ropes)?.id).toBe('bridge-a-b')+ })++ it('a rope with no underlying context link resolves to nothing', () => {+ expect(contextLinkForEdge('ctrl-a-c', links, ropes)).toBeNull()+ })++ it('an unknown (ephemeral) edge resolves to nothing', () => {+ expect(contextLinkForEdge('sub-x', links, ropes)).toBeNull()+ })+})+diff --git a/src/renderer/lib/noteLink.ts b/src/renderer/lib/noteLink.tsindex a02b86da8..0bb725e2a 100644--- a/src/renderer/lib/noteLink.ts+++ b/src/renderer/lib/noteLink.ts@@ -29,18 +29,52 @@ export {* Persisted bridge → React Flow edge. A one-way link's reader (issue #852) rides `edge.data`,* because React Flow owns the edge's top-level fields; a reader-less bridge gets no `data` at all,* so every pre-#852 link loads exactly as before.+ *+ * A PRESENT reader is carried whatever its value — `null`, a number, a string naming neither+ * endpoint. `linkReadPairs` reads such a reader as "nobody may read", and that restriction must+ * survive load and save: treating a malformed value as absent would turn it into an unrestricted+ * two-way link on the next autosave. The rule is: absent (`undefined`) = both read; anything else+ * is kept verbatim and judged only by `linkReadPairs`.*/export function bridgeToEdge(b: BridgeLink): Edge {const e: Edge = { id: b.id, source: b.source, target: b.target }- return typeof b.reader === 'string' ? { ...e, data: { reader: b.reader } } : e+ return hasReader(b) ? { ...e, data: { reader: b.reader } } : e}/** React Flow edge → persisted bridge: id, endpoints and the one-way reader only — selection and* display-only data never reach project.json. The single inverse of `bridgeToEdge`. */export function edgeToBridge(e: Pick<Edge, 'id' | 'source' | 'target' | 'data'>): BridgeLink {const b: BridgeLink = { id: e.id, source: e.source, target: e.target }- const reader = (e.data as { reader?: unknown } | undefined)?.reader- return typeof reader === 'string' ? { ...b, reader } : b+ const data = e.data as { reader?: unknown } | undefined+ return data && hasReader(data) ? { ...b, reader: data.reader as string } : b+}++function hasReader(o: { reader?: unknown }): boolean {+ return 'reader' in o && o.reader !== undefined+}++/** Append persisted-shape bridges (e.g. `planBridges` output) to the live edge array. The ONLY+ * way bridge objects may enter it: appended raw, a one-way `reader` sits top-level where+ * `edgeToBridge` never looks, and publication + autosave silently make the link two-way. */+export function appendBridgeEdges(es: readonly Edge[], bridges: readonly BridgeLink[]): Edge[] {+ return [...es, ...bridges.map(bridgeToEdge)]+}++/**+ * The context link an edge stands for: itself when it IS a link, the link it covers when it is a+ * control rope drawn over one (`hiddenLinkIds` hides that link and lets the rope keep the pixels —+ * the same endpoint-pair rule `linkIdsCoveredByRopes` applies on removal), else null (a rope with+ * no link under it, or an ephemeral card edge).+ */+export function contextLinkForEdge<T extends { id: string; source: string; target: string }>(+ edgeId: string,+ links: readonly T[],+ ropes: readonly { id: string; source: string; target: string }[]+): T | null {+ const direct = links.find((l) => l.id === edgeId)+ if (direct) return direct+ const [covered] = linkIdsCoveredByRopes([edgeId], ropes, links)+ return covered === undefined ? null : (links.find((l) => l.id === covered) ?? null)}/** Order-independent key for an edge's endpoints (a↔b and b↔a are the same connection). */diff --git a/src/renderer/lib/serverChange.test.ts b/src/renderer/lib/serverChange.test.tsindex 619db9bfb..716ec653d 100644--- a/src/renderer/lib/serverChange.test.ts+++ b/src/renderer/lib/serverChange.test.ts@@ -230,4 +230,15 @@ describe('planServerChange', () => {{ id: 'bridge-new', source: caller.id, target: spawned.id, reader: spawned.id }])})++ it('keeps a present-but-invalid reader so it keeps granting nobody', () => {+ const plan = planServerChange({+ base: project([caller, first]),+ incoming: project([caller, first]),+ liveNodeIds: [caller.id, first.id],+ liveRopes: [],+ liveBridges: [{ id: 'bridge-x', source: caller.id, target: first.id, reader: null as never }]+ })+ expect(plan.bridges).toEqual([{ id: 'bridge-x', source: caller.id, target: first.id, reader: null }])+ })})diff --git a/src/renderer/lib/serverChange.ts b/src/renderer/lib/serverChange.tsindex bea3d94de..f8c712a86 100644--- a/src/renderer/lib/serverChange.ts+++ b/src/renderer/lib/serverChange.ts@@ -60,8 +60,9 @@ export interface ServerChangePlan {// A bridge's one-way `reader` (issue #852) is part of the link, not display state: dropping it// here would turn a one-way link back into a two-way one on any server-side change.+// A present-but-malformed reader is kept too: it grants nobody, and dropping it would widen it.const edgeRef = (e: EdgeRef): EdgeRef =>- typeof e.reader === 'string'+ e.reader !== undefined? { id: e.id, source: e.source, target: e.target, reader: e.reader }: { id: e.id, source: e.source, target: e.target }diff --git a/src/shared/context-link-map.test.ts b/src/shared/context-link-map.test.tsindex a0098395e..7a4cd45c1 100644--- a/src/shared/context-link-map.test.ts+++ b/src/shared/context-link-map.test.ts@@ -28,6 +28,11 @@ describe('buildLinkMap direction', () => {expect(buildLinkMap([{ source: 'a', target: 'b', reader: 'x' }], info)).toEqual({})})+ it('a malformed (non-string) persisted reader authorizes nobody', () => {+ expect(buildLinkMap([{ source: 'a', target: 'b', reader: null as never }], info)).toEqual({})+ expect(buildLinkMap([{ source: 'a', target: 'b', reader: 42 as never }], info)).toEqual({})+ })+it('note links keep their fixed direction (terminal reads the sticky)', () => {const map = buildLinkMap([{ source: 's1', target: 'a' }], info)expect(Object.keys(map)).toEqual(['a'])