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(canvas-control): never re-send /rename when the title has not changed
enes44873a753a38
diff --git a/src/main/canvas-control-core.test.ts b/src/main/canvas-control-core.test.tsindex d3a36f9a8..a728929f7 100644--- a/src/main/canvas-control-core.test.ts+++ b/src/main/canvas-control-core.test.ts@@ -376,6 +376,17 @@ describe('parseControlRequest', () => {}})+ it('both agent-facing texts say an unchanged rename types nothing into the session', () => {+ for (const body of [buildCanvasSkillBody('/x/shim.sh'), buildCanvasControlInstructions('/tmp/nodeterm.sh')]) {+ // Issues #582 / #569 §2. An orchestrator that re-asserts its node's name on startup and+ // after every context reset was previously paying a `/rename` injection into the working+ // session each time — one reporter worked around it by reading the title first. The verb+ // now compares, so the text has to say so, or callers keep building that workaround.+ expect(body.toLowerCase()).toContain('already named')+ expect(body.toLowerCase()).toContain('no-op')+ }+ })+it('both agent-facing texts document the messaging verbs and the outermost-frame convention', () => {for (const body of [buildCanvasSkillBody('/x/shim.sh'), buildCanvasControlInstructions('/tmp/nodeterm.sh')]) {for (const frag of ['`send --node', '`reply --node', '`notify --node']) {diff --git a/src/main/canvas-control-core.ts b/src/main/canvas-control-core.tsindex 206066ae2..d7f11f127 100644--- a/src/main/canvas-control-core.ts+++ b/src/main/canvas-control-core.ts@@ -380,6 +380,8 @@ export function buildCanvasControlInstructions(shimPath: string): string {' the user to confirm deletion.','- `branch --node <id>` — branch a Claude node\'s conversation (Claude nodes only).','- `rename --node <id> --title "New Name"` — rename any node (terminals, groups, stickies…).',+ ' Renaming to the title the node ALREADY has is a no-op: nothing is typed into its agent',+ ' session, and the reply says `already named`. Re-assert your own name as often as you like.','- `write --node <id> --text "..."` / `close --node <id>` — type into / close a node.',' Both ask the user to confirm a dialog and may be denied. Read WHICH answer came back:',' `denied by user` is a decision and is FINAL — never re-ask — while `no answer within 120s`',@@ -805,6 +807,8 @@ Verbs:- \`branch --node <id>\` — branch a Claude node's conversation: the node stays on the newbranch and a new node opens resuming the original. Target must be a Claude agent node.- \`rename --node <id> --title "New Name"\` — rename any node (terminals, groups, stickies…).+ Renaming to the title the node ALREADY has is a no-op: nothing is typed into its agent+ session, and the reply says \`already named\`. Re-assert your own name as often as you like.- \`write --node <id> --text "..."\` — type text into a terminal node. (Asks the user to confirm.)- \`close --node <id>\` — close a node. (Asks the user to confirm.)- \`send --node <id> --text "..."\` — deliver a message INTO another agent node's session, in thisdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 93d83e322..2f0a9025c 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -390,7 +390,7 @@ import {import { buildBackgroundLinkMaps, buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink, hiddenLinkIds, linkIdsCoveredByRopes, pairKey, planBridges, type LinkEndpoint } from '../lib/noteLink'import { dependencyEdges, launchesToFire, unmetDeps, type ArmedNode } from '../lib/pendingLaunch'import { freeSpot } from '../lib/placement'-import { pushSessionRename } from '../lib/sessionRename'+import { pushSessionRename, sessionNameUnchanged } from '../lib/sessionRename'import { useReopenHistory } from '../state/reopenHistory'import { snapshotNode, recreateNodeFromSnapshot } from '../lib/reopenNode'import { planReopen } from '../lib/reopenPlan'@@ -9552,6 +9552,12 @@ export function Canvas() {reply({ ok: false, error: `rename: no node with id ${id}` })return}+ // The name the node carries BEFORE this call — read here, before the setNodes below,+ // because a re-rename to the SAME title must reach the pane with nothing (#582,+ // #569 §2). Orchestrators re-assert their node's name on startup and after every+ // context reset, and each identical `/rename` costs the session a transcript entry+ // plus a `<system-reminder>` claiming the USER just renamed it.+ const prevTitle = (target.data.title as string) ?? ''// Same semantics as renameSession: an explicit rename takes ownership of the// name (titleAuto off) and mirrors it into a rename-capable agent's session.setNodes((ns) =>@@ -9560,11 +9566,18 @@ export function Canvas() {markDirty()const agentId = target.data.agentId as AgentId | undefinedif (agentId && canRename(agentId) && title) {- // Gated: an agent that opens a node and renames it in the same breath would- // otherwise splice this line into the launch command still being typed.- void pushSessionRename(api.pty, id, title)+ // Gated twice: on the pane's owner (an agent that opens a node and renames it in the+ // same breath would otherwise splice this line into the launch command still being+ // typed) and, inside, on the name actually changing.+ void pushSessionRename(api.pty, id, title, prevTitle)}- reply({ ok: true, message: `renamed ${id} to "${title}"` })+ reply(+ // Say which of the two happened: the caller cannot see the pane, and "already named"+ // is the answer that lets an orchestrator stop re-asserting a name it already set.+ title && sessionNameUnchanged(title, prevTitle)+ ? { ok: true, message: `${id} is already named "${title}"` }+ : { ok: true, message: `renamed ${id} to "${title}"` }+ )return}case 'sticky': {@@ -9970,6 +9983,15 @@ export function Canvas() {const renameSession = useCallback((projectId: string, id: string, title: string) => {+ // Both facts about the node are read BEFORE the rename lands: `renameNode` mutates the+ // store synchronously, so reading the previous title afterwards would compare the new name+ // against itself and push a duplicate `/rename` on every no-op rename (#582).+ const liveNode = nodesRef.current.find((n) => n.id === id)+ const storedNode = useProjects+ .getState()+ .projects.find((p) => p.id === projectId)+ ?.nodes.find((n) => n.id === id)+ const prevTitle = (liveNode?.data.title as string | undefined) ?? storedNode?.title ?? ''if (projectId === activeProjectId) {// An explicit rename takes ownership of the name → stop auto-tracking the session.setNodes((ns) =>@@ -9982,15 +10004,14 @@ export function Canvas() {}// Mirror the new name into a rename-capable agent's live session (tmux send-keys works// whether or not the node is currently mounted). Same one-way push as the node header's ✦.- const liveAgent = nodesRef.current.find((n) => n.id === id)?.data.agentId as AgentId | undefined- const storedAgent = useProjects- .getState()- .projects.find((p) => p.id === projectId)- ?.nodes.find((n) => n.id === id)?.agentId- const agentId = liveAgent ?? storedAgent+ // The unchanged-name gate inside `pushSessionRename` is defence in depth for the callers+ // that already compare (the header's rename box): this funnel is also reached by the ✦+ // AI-name and by the kanban/sidebar rename boxes, which can hand back the name the node+ // already has.+ const agentId = (liveNode?.data.agentId as AgentId | undefined) ?? storedNode?.agentIdconst name = title.trim()if (agentId && canRename(agentId) && name) {- void pushSessionRename(api.pty, id, name)+ void pushSessionRename(api.pty, id, name, prevTitle)}},[activeProjectId, setNodes, markDirty, writeDisk]diff --git a/src/renderer/lib/sessionRename.test.ts b/src/renderer/lib/sessionRename.test.tsindex 93e18cfba..9bafd6615 100644--- a/src/renderer/lib/sessionRename.test.ts+++ b/src/renderer/lib/sessionRename.test.ts@@ -1,5 +1,10 @@import { describe, it, expect, vi } from 'vitest'-import { RENAME_PUSH_ATTEMPTS, pushSessionRename, renameCommand } from './sessionRename'+import {+ RENAME_PUSH_ATTEMPTS,+ pushSessionRename,+ renameCommand,+ sessionNameUnchanged+} from './sessionRename'const io = (panes: (string | null)[] | (() => Promise<string | null>)) => {const sent: string[] = []@@ -18,7 +23,7 @@ const io = (panes: (string | null)[] | (() => Promise<string | null>)) => {describe('pushSessionRename', () => {it('writes as soon as a non-shell owns the pane', async () => {const x = io(['claude'])- await expect(pushSessionRename(x, 'n1', 'My session')).resolves.toBe(true)+ await expect(pushSessionRename(x, 'n1', 'My session', 'Claude Code')).resolves.toBe(true)expect(x.sent).toEqual(['/rename My session'])})@@ -26,21 +31,21 @@ describe('pushSessionRename', () => {// The regression this exists for: `claude '<long prompt>'` mid-delivery, cut in half by an// interleaved rename, leaving the shell at `quote>` and the agent never started.const x = io(['zsh'])- await expect(pushSessionRename(x, 'n1', 'My session')).resolves.toBe(false)+ await expect(pushSessionRename(x, 'n1', 'My session', 'Claude Code')).resolves.toBe(false)expect(x.sent).toEqual([])})it('recognizes a login shell and a full path as shells', async () => {for (const pane of ['-zsh', '/bin/bash', 'fish']) {const x = io([pane])- await pushSessionRename(x, 'n1', 'x')+ await pushSessionRename(x, 'n1', 'x', 'was')expect(x.sent, pane).toEqual([])}})it('waits for the CLI to boot, then writes once', async () => {const x = io(['zsh', 'zsh', 'node'])- await expect(pushSessionRename(x, 'n1', 'Later')).resolves.toBe(true)+ await expect(pushSessionRename(x, 'n1', 'Later', 'Earlier')).resolves.toBe(true)expect(x.sent).toEqual(['/rename Later'])})@@ -48,23 +53,100 @@ describe('pushSessionRename', () => {const x = io(async () => {throw new Error('tmux gone')})- await expect(pushSessionRename(x, 'n1', 'x')).resolves.toBe(false)+ await expect(pushSessionRename(x, 'n1', 'x', 'was')).resolves.toBe(false)expect(x.sent).toEqual([])})it('treats an unknown (null) pane as "not demonstrated" and stays silent', async () => {const x = io([null])- await expect(pushSessionRename(x, 'n1', 'x')).resolves.toBe(false)+ await expect(pushSessionRename(x, 'n1', 'x', 'was')).resolves.toBe(false)expect(x.sent).toEqual([])})it('gives up after a bounded number of attempts rather than probing forever', async () => {const probe = vi.fn(async () => 'zsh')- await pushSessionRename({ paneCommand: probe, sendText: async () => true, sleep: async () => {} }, 'n1', 'x')+ await pushSessionRename(+ { paneCommand: probe, sendText: async () => true, sleep: async () => {} },+ 'n1',+ 'x',+ 'was'+ )expect(probe).toHaveBeenCalledTimes(RENAME_PUSH_ATTEMPTS)})})+/**+ * The unchanged-title gate — issue #582, and issue #569 §2 from the orchestrator's side.+ *+ * A rename to the name the node already carries must reach the pane with NOTHING. It is not a+ * harmless duplicate: claude records each `/rename` as a transcript entry, its `Session renamed+ * to: …` stdout, and a `<system-reminder>` asserting that *the user* named this session — so a+ * re-sent identical name burns the working session's context to report an intent nobody had.+ * #582 measured 32 such injections in six hours, every one carrying the same title.+ *+ * The gate lives HERE, below every call site, because that is the only layer the compiler can+ * make unavoidable: `current` is a required argument, so a new caller cannot forget it, and+ * neither `Canvas.tsx` nor `TerminalNode.tsx` is unit-rendered in this repo.+ */+describe('pushSessionRename: an unchanged name writes nothing', () => {+ it('does not even PROBE the pane when the name is unchanged', async () => {+ const probe = vi.fn(async () => 'claude')+ const sendText = vi.fn(async () => true)+ await expect(+ pushSessionRename({ paneCommand: probe, sendText, sleep: async () => {} }, 'n1', 'Trial 1.08', 'Trial 1.08')+ ).resolves.toBe(false)+ expect(sendText).not.toHaveBeenCalled()+ // Nothing is asked of tmux either: the cheapest possible no-op, on a path an orchestrator+ // re-runs after every context reset.+ expect(probe).not.toHaveBeenCalled()+ })++ it('still pushes when the name actually changes', async () => {+ const x = io(['claude'])+ await expect(pushSessionRename(x, 'n1', 'Trial 1.09', 'Trial 1.08')).resolves.toBe(true)+ expect(x.sent).toEqual(['/rename Trial 1.09'])+ })++ it('pushes the FIRST name a node gets (no previous title is not "unchanged")', async () => {+ const x = io(['claude'])+ await expect(pushSessionRename(x, 'n1', 'Trial 1.08', '')).resolves.toBe(true)+ expect(x.sent).toEqual(['/rename Trial 1.08'])+ })++ it('compares the line that would be SENT, not the raw title', async () => {+ // `renameCommand` collapses control runs, so these two titles compose the same submitted+ // line. A raw `!==` would call this a new name and deliver a byte-identical duplicate.+ const x = io(['claude'])+ await expect(pushSessionRename(x, 'n1', 'Trial\n1.08', 'Trial 1.08')).resolves.toBe(false)+ expect(x.sent).toEqual([])+ })+})++describe('sessionNameUnchanged', () => {+ it('is true only when the composed rename line would be identical', () => {+ expect(sessionNameUnchanged('Trial 1.08', 'Trial 1.08')).toBe(true)+ expect(sessionNameUnchanged('Trial 1.08', 'Trial 1.09')).toBe(false)+ expect(sessionNameUnchanged('Trial 1.08', '')).toBe(false)+ // Normalized exactly as `renameCommand` normalizes: trimmed, control runs collapsed.+ expect(sessionNameUnchanged(' Trial 1.08 ', 'Trial 1.08')).toBe(true)+ expect(sessionNameUnchanged('Trial\r\n1.08', 'Trial 1.08')).toBe(true)+ // …and no further than that: inner spacing and case are part of the name.+ expect(sessionNameUnchanged('Trial 1.08', 'Trial 1.08')).toBe(false)+ expect(sessionNameUnchanged('trial 1.08', 'Trial 1.08')).toBe(false)+ })++ it('agrees with renameCommand on every pair it calls unchanged', () => {+ for (const [a, b] of [+ ['Trial 1.08', ' Trial 1.08'],+ ['Deploy\nx', 'Deploy x'],+ ['a', 'a']+ ] as const) {+ expect(sessionNameUnchanged(a, b)).toBe(true)+ expect(renameCommand(a)).toBe(renameCommand(b))+ }+ })+})+/*** SECURITY — the line this composes is SUBMITTED (`sendText` appends Enter), and `name` is not* ours: the canvas-control `rename` verb's `--title` puts an AGENT's string here.@@ -128,7 +210,7 @@ describe('renameCommand: a title cannot splice a second command', () => {// The gate's own tests above pin the ordinary case; this one pins that a malicious title// cannot reach the pane un-stripped by going through pushSessionRename instead.const x = io(['claude'])- return pushSessionRename(x, 'n1', 'Deploy\nrm -rf ~').then(() => {+ return pushSessionRename(x, 'n1', 'Deploy\nrm -rf ~', 'Old name').then(() => {expect(x.sent).toEqual(['/rename Deploy rm -rf ~'])})})diff --git a/src/renderer/lib/sessionRename.ts b/src/renderer/lib/sessionRename.tsindex adb6cf10b..43babeab2 100644--- a/src/renderer/lib/sessionRename.ts+++ b/src/renderer/lib/sessionRename.ts@@ -26,6 +26,24 @@ export function renameCommand(name: string): string {return `/rename ${oneLine(name)}`}+/**+ * Would `/rename <next>` be the line this session was already given?+ *+ * Compared AFTER `oneLine`, i.e. after exactly the normalization `renameCommand` applies, because+ * that is what decides whether the pane would receive a byte-identical line. Two titles that+ * differ only by a control character compose the same command, so a raw `!==` would answer "this+ * is a new name" and push a duplicate.+ *+ * The unchanged case is not cosmetic. Every `/rename` claude receives lands in the transcript as a+ * `local_command`, its `Session renamed to: …` stdout, AND a `<system-reminder>` that tells the+ * model *the user* just named this session — so a re-sent identical name spends the session's+ * context to assert an intent nobody expressed. Issue #582 measured 32 of them in six hours, all+ * carrying the same title; issue #569 §2 is the same push from the orchestrator's side.+ */+export function sessionNameUnchanged(next: string, current: string): boolean {+ return oneLine(next) === oneLine(current)+}+export interface RenamePushIo {paneCommand(persistKey: string): Promise<string | null>sendText(persistKey: string, text: string): Promise<boolean>@@ -47,12 +65,24 @@ export interface RenamePushIo {* So: probe the pane, and when we cannot DEMONSTRATE that a non-shell owns it, write nothing. A* probe that errors counts as "not demonstrated" — the asymmetry is deliberate, because an* unsynced session name is cosmetic while a destroyed launch is not.+ *+ * `current` is the name the node carries BEFORE this rename, and it is REQUIRED rather than+ * optional on purpose: a rename that changes nothing must reach the pane with nothing (see+ * `sessionNameUnchanged`), and an optional argument is one a call site forgets. Every caller+ * already holds the node it is renaming, so the type is what enforces the gate — neither+ * `Canvas.tsx` nor `TerminalNode.tsx` is unit-rendered in this repo, so the compiler is the only+ * reviewer that sees every site.+ *+ * Returns false both for "nothing to push" and for "the agent never took the pane"; the callers+ * are one-way mirrors and act on neither.*/export async function pushSessionRename(io: RenamePushIo,nodeId: string,- name: string+ name: string,+ current: string): Promise<boolean> {+ if (sessionNameUnchanged(name, current)) return falseconst sleep = io.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)))for (let i = 0; i < RENAME_PUSH_ATTEMPTS; i++) {if (i > 0) await sleep(RENAME_PUSH_RETRY_MS)diff --git a/src/renderer/nodes/title-gate.test.ts b/src/renderer/nodes/title-gate.test.tsindex 568fe66a3..4e495d799 100644--- a/src/renderer/nodes/title-gate.test.ts+++ b/src/renderer/nodes/title-gate.test.ts@@ -80,6 +80,27 @@ describe('session-name title gates', () => {}})+ it('every canvas rename push is compared against the name the node already carries', () => {+ // Issues #582 and #569 §2: an orchestrator re-asserts its node's name on startup and after+ // every context reset, and the canvas-control `rename` verb pushed `/rename <same title>`+ // into the pane every single time — 32 identical injections over six hours in the report,+ // each costing the working session a transcript entry plus a `<system-reminder>` claiming the+ // USER had renamed it. `pushSessionRename` now REQUIRES the previous name, so the compiler+ // catches an omitted argument; what it cannot catch is a call site passing something that is+ // not the node's own title, which is what this asserts.+ const lines = canvas.split('\n')+ const calls = lines.map((l, i) => [l, i] as const).filter(([l]) => l.includes('pushSessionRename('))+ expect(calls.length).toBeGreaterThan(0)+ for (const [line, i] of calls) {+ expect(line.includes('prevTitle'), `${i + 1}: ${line.trim()}`).toBe(true)+ }+ // …and `prevTitle` is read off the NODE (before the rename lands), never restated from the+ // incoming title — comparing the new name against itself would answer "unchanged" always.+ const assigned = lines.filter((l) => l.includes('const prevTitle ='))+ expect(assigned.length).toBe(calls.length)+ for (const line of assigned) expect(line, line.trim()).toContain('data.title')+ })+it('every canvas rename push sits behind a canRename guard', () => {const lines = canvas.split('\n')const calls = lines.map((l, i) => [l, i] as const).filter(([l]) => l.includes('pushSessionRename('))