Skip to content

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.

fix(canvas): `/rename` no longer splices into a launch command; one edge per pair

enesa19f9fddfcd7
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 8192f9c67..e2ae85755 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -188,8 +188,9 @@ import {
reconnectRelayTab,
type RelayTab,
} from '../session/relay-tab'
-import { buildBackgroundLinkMaps, buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink, planBridges, type LinkEndpoint } from '../lib/noteLink'
+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 { pushSessionRename } from '../lib/sessionRename'
import { parseLenses, verifyLensPrompt, verifySynthesisPrompt } from '../lib/verifyPanel'
import { useSettings } from '../state/settings'
import { activePermissionMode } from '../state/permissionMode'
@@ -1073,7 +1074,12 @@ export function Canvas() {
)
const displayEdges = useMemo(() => {
const stickyIds = new Set(stickySig ? stickySig.split('|') : [])
- const decorated = linkEdges.map((e) => {
+ // ONE edge per pair. A node an agent opens gets both a rope (lineage) and a context bridge
+ // (readable context), which drew two near-identical arrows between the same two nodes. The
+ // rope keeps the pixels; the bridge still exists in data (it is what authorizes reading) and
+ // rides the rope's delete, so it can never become an invisible link with nothing to click.
+ const hidden = hiddenLinkIds(linkEdges, controlEdges)
+ const decorated = linkEdges.filter((e) => !hidden.has(e.id)).map((e) => {
const sel = !!e.selected
const isNote = stickyIds.has(e.source)
const stroke = sel ? '#ffffff' : accent
@@ -1096,12 +1102,19 @@ export function Canvas() {
: { markerStart: { type: MarkerType.ArrowClosed, color: stroke, width: 14, height: 14 } })
}
})
- // Control ropes: white + a removal hint while selected (mirrors the context-link look).
+ // Control ropes: white + a removal hint while selected (mirrors the context-link look). A
+ // rope that is also standing in for a hidden context bridge says so, so the one visible edge
+ // never under-reports what removing it will take with it.
+ const ropeCoversLink = new Set(
+ linkEdges.filter((e) => hidden.has(e.id)).map((e) => pairKey(e.source, e.target))
+ )
const ropes = controlEdges.map((e) =>
e.selected
? {
...e,
- label: '⌫ to remove',
+ label: ropeCoversLink.has(pairKey(e.source, e.target))
+ ? '⇄ context · ⌫ to remove'
+ : '⌫ to remove',
labelStyle: { fill: '#ffffff', fontSize: 11, fontWeight: 600 },
labelBgStyle: { fill: '#1c1c1e', fillOpacity: 0.85 },
labelBgPadding: [6, 3] as [number, number],
@@ -1947,7 +1960,14 @@ export function Canvas() {
(_e: React.MouseEvent, edge: Edge) => {
// Control ropes are removable the same way as context links (ephemeral edges are not).
if (controlEdgesRef.current.some((b) => b.id === edge.id)) {
+ // A rope may be the only DRAWN edge for a pair that also has a context bridge (see
+ // displayEdges) — take that bridge with it, or the nodes stay linked with nothing left
+ // on screen to unlink them.
+ const covered = new Set(
+ linkIdsCoveredByRopes([edge.id], controlEdgesRef.current, linkEdgesRef.current)
+ )
setControlEdges((es) => es.filter((b) => b.id !== edge.id))
+ if (covered.size) setLinkEdges((es) => es.filter((b) => !covered.has(b.id)))
markDirty()
return
}
@@ -3110,13 +3130,18 @@ export function Canvas() {
const ropeIds = controlEdgesRef.current.filter((b) => b.selected).map((b) => b.id)
if (edgeIds.length || ropeIds.length) {
e.preventDefault()
- if (edgeIds.length) {
- const drop = new Set(edgeIds)
+ // A selected rope may be standing in for a hidden context bridge — drop both, or the
+ // pair stays linked with no edge left to click (see displayEdges).
+ const drop = new Set([
+ ...edgeIds,
+ ...linkIdsCoveredByRopes(ropeIds, controlEdgesRef.current, linkEdgesRef.current)
+ ])
+ if (drop.size) {
setLinkEdges((es) => es.filter((b) => !drop.has(b.id)))
}
if (ropeIds.length) {
- const drop = new Set(ropeIds)
- setControlEdges((es) => es.filter((b) => !drop.has(b.id)))
+ const dropRopes = new Set(ropeIds)
+ setControlEdges((es) => es.filter((b) => !dropRopes.has(b.id)))
}
markDirty()
}
@@ -5714,8 +5739,10 @@ export function Canvas() {
)
markDirty()
const agentId = target.data.agentId as AgentId | undefined
- if (agentId && canRename(agentId)) {
- void api.pty.sendText(id, `/rename ${title}`)
+ if (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)
}
reply({ ok: true, message: `renamed ${id} to "${title}"` })
return
@@ -5845,7 +5872,7 @@ export function Canvas() {
const agentId = liveAgent ?? storedAgent
const name = title.trim()
if (agentId && canRename(agentId) && name) {
- void api.pty.sendText(id, `/rename ${name}`)
+ void pushSessionRename(api.pty, id, name)
}
},
[activeProjectId, setNodes, markDirty, writeDisk]
diff --git a/src/renderer/lib/noteLink.test.ts b/src/renderer/lib/noteLink.test.ts
index 8e6e033cc..2fb7ab33b 100644
--- a/src/renderer/lib/noteLink.test.ts
+++ b/src/renderer/lib/noteLink.test.ts
@@ -5,6 +5,8 @@ import {
buildLinkMap,
buildNotePushMessage,
classifyLink,
+ hiddenLinkIds,
+ linkIdsCoveredByRopes,
planBridges
} from './noteLink'
import type { CanvasNodeState } from '@shared/types'
@@ -94,6 +96,33 @@ describe('planBridges', () => {
})
})
+describe('one edge per pair (hiddenLinkIds / linkIdsCoveredByRopes)', () => {
+ const link = { id: 'bridge-a-b', source: 'a', target: 'b' }
+ const rope = { id: 'ctrl-a-b', source: 'a', target: 'b' }
+
+ it('hides a link whose pair already has a rope — in either direction', () => {
+ expect(hiddenLinkIds([link], [rope])).toEqual(new Set(['bridge-a-b']))
+ expect(hiddenLinkIds([link], [{ id: 'ctrl-b-a', source: 'b', target: 'a' }])).toEqual(
+ new Set(['bridge-a-b'])
+ )
+ })
+
+ it('keeps a hand-drawn link that no rope covers', () => {
+ expect(hiddenLinkIds([link], [{ id: 'ctrl-a-c', source: 'a', target: 'c' }]).size).toBe(0)
+ expect(hiddenLinkIds([link], []).size).toBe(0)
+ })
+
+ it('deleting a rope also names the link it was standing in for', () => {
+ expect(linkIdsCoveredByRopes(['ctrl-a-b'], [rope], [link])).toEqual(['bridge-a-b'])
+ })
+
+ it('deleting an unrelated rope drops no link', () => {
+ const other = { id: 'ctrl-x-y', source: 'x', target: 'y' }
+ expect(linkIdsCoveredByRopes(['ctrl-x-y'], [rope, other], [link])).toEqual([])
+ expect(linkIdsCoveredByRopes([], [rope], [link])).toEqual([])
+ })
+})
+
describe('buildNotePushMessage', () => {
it('wraps the note text with the nodeterm prefix and title', () => {
expect(buildNotePushMessage('Deploy notes', 'use the staging key')).toBe(
diff --git a/src/renderer/lib/noteLink.ts b/src/renderer/lib/noteLink.ts
index 98e6170e6..f46b89565 100644
Binary files a/src/renderer/lib/noteLink.ts and b/src/renderer/lib/noteLink.ts differ
diff --git a/src/renderer/lib/sessionRename.test.ts b/src/renderer/lib/sessionRename.test.ts
new file mode 100644
index 000000000..a884a4c39
--- /dev/null
+++ b/src/renderer/lib/sessionRename.test.ts
@@ -0,0 +1,66 @@
+import { describe, it, expect, vi } from 'vitest'
+import { RENAME_PUSH_ATTEMPTS, pushSessionRename } from './sessionRename'
+
+const io = (panes: (string | null)[] | (() => Promise<string | null>)) => {
+ const sent: string[] = []
+ let i = 0
+ return {
+ sent,
+ paneCommand: typeof panes === 'function' ? panes : async () => panes[Math.min(i++, panes.length - 1)],
+ sendText: async (_k: string, t: string) => {
+ sent.push(t)
+ return true
+ },
+ sleep: async () => {}
+ }
+}
+
+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)
+ expect(x.sent).toEqual(['/rename My session'])
+ })
+
+ it('NEVER writes while a shell owns the pane — that is the launch command being typed', async () => {
+ // 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)
+ 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')
+ 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)
+ expect(x.sent).toEqual(['/rename Later'])
+ })
+
+ it('treats a failed probe as "not demonstrated" and stays silent', async () => {
+ const x = io(async () => {
+ throw new Error('tmux gone')
+ })
+ await expect(pushSessionRename(x, 'n1', 'x')).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)
+ 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')
+ expect(probe).toHaveBeenCalledTimes(RENAME_PUSH_ATTEMPTS)
+ })
+})
diff --git a/src/renderer/lib/sessionRename.ts b/src/renderer/lib/sessionRename.ts
new file mode 100644
index 000000000..d66e549f4
--- /dev/null
+++ b/src/renderer/lib/sessionRename.ts
@@ -0,0 +1,48 @@
+// Mirroring a node's title into its agent session as `/rename <name>`, safely.
+//
+// The io is injected so the gate below is unit-testable: it is the fix for a real data-loss bug,
+// not a nicety. Lives outside Canvas.tsx for that reason alone.
+import { isShellCommand } from '../terminal/agent-restart'
+
+/** How long to wait for an agent CLI to take its pane before giving up on the mirror. */
+export const RENAME_PUSH_ATTEMPTS = 12
+export const RENAME_PUSH_RETRY_MS = 500
+
+export interface RenamePushIo {
+ paneCommand(persistKey: string): Promise<string | null>
+ sendText(persistKey: string, text: string): Promise<boolean>
+ /** Injected so tests don't wait in real time. */
+ sleep?(ms: number): Promise<void>
+}
+
+/**
+ * Push `/rename <name>` into a node's agent session — but ONLY once the agent CLI actually owns
+ * the pane.
+ *
+ * `sendText` appends Enter, so writing while a SHELL owns the pane splices the line into whatever
+ * that shell is currently reading. For a freshly opened agent node that is its own launch command
+ * being typed, and the observed damage was exactly that: `claude '<long prompt>'` cut in half by
+ * an interleaved `/rename …`, leaving the shell sitting at `quote>` with the agent never started
+ * and the prompt lost. An agent that opens a node and renames it in the same breath — the entire
+ * orchestration flow — hits that window every single time.
+ *
+ * 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.
+ */
+export async function pushSessionRename(
+ io: RenamePushIo,
+ nodeId: string,
+ name: string
+): Promise<boolean> {
+ const 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)
+ const pane = await io.paneCommand(nodeId).catch(() => null)
+ if (pane && !isShellCommand(pane)) {
+ void io.sendText(nodeId, `/rename ${name}`)
+ return true
+ }
+ }
+ return false
+}