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(restart): relaunch through withPermissionMode, from one shared agent-id

enesd1ab3bf85990
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 19268938d..6a3cdaa6c 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -75,7 +75,7 @@ import { useWorktrees } from '../state/worktrees'
import { isRemoteSessionNode } from '@shared/worktree'
import { useSession, useActiveSessionPresence } from '../session/session'
import { accountChipLabel, COLLAPSED_HEIGHT, NODE_COLORS, type CanvasNode } from '../state/workspace'
-import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, resumeCommand, withPermissionMode, agentConfig, type AgentId } from '@shared/agents/config'
+import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, createdAgentId, resumeCommand, withPermissionMode, agentConfig } from '@shared/agents/config'
import { ensureActivePermissionMode } from '../state/permissionMode'
import { buildSshArgs, type SshConnection } from '@shared/ssh'
import { hintLabel } from '@shared/platform-utils'
@@ -404,9 +404,10 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
const mdMode = !!data.mdMode
const collapsed = !!data.collapsed
const tags = (data.tags as string[]) ?? []
- // Derive the node's agent once. The `tags` fallback keeps not-yet-migrated legacy
- // claude nodes working until they're re-serialized with `agentId`.
- const agentId = (data.agentId as AgentId | undefined) ?? (tags.includes('claude') ? 'claude' : undefined)
+ // Derive the node's agent once, through the shared helper — the canvas menu decides whether to
+ // offer this node's in-place restart from the SAME derivation, and a second copy drifting from
+ // this one yields a row whose closure refuses every click.
+ const agentId = createdAgentId(data)
// Gate each former `isClaude` site by the capability it actually represents.
const showStatus = !!agentId && hasHooks(agentId) // status badge + session-title capture
const showLoop = !!agentId && canRecur(agentId) // /loop · /schedule · /cron chrome
@@ -1214,10 +1215,23 @@ export function TerminalNode({ id, data, selected, parentId }: NodeProps<CanvasN
const agentSessionId = st?.sessionId
const gate = restartEligibility(agentId, st?.state, agentSessionId)
if (!gate.ok || !agentId || !agentSessionId || !restartTarget()) return 'not-eligible'
+ // Built HERE, not inside the choreography: `withPermissionMode` is the single funnel for
+ // every CLI launch path (shared/agents/config.ts) and the mode is a renderer-side, async
+ // read — exactly as the cold-restore relaunch above does it. Without it a canvas running
+ // in acceptEdits/plan would come back from a restart in the default mode, silently.
+ // Re-resolved at call time for the same reason as there: the mode is a property of how a
+ // session is launched, not of the node.
+ const base = resumeCommand(agentId, agentSessionId)
+ const command = base
+ ? withPermissionMode(base, agentId, await ensureActivePermissionMode())
+ : undefined
return performRestartResume({
agentId,
sessionId: agentSessionId,
io: restartIo,
+ // An unusable session id leaves this undefined and performRestartResume refuses the
+ // restart on its own `resumeCommand` gate — nothing is written either way.
+ command,
// Session-scoped (`api`, not the global preload), like readScrollback above: a relay
// tab's pane lives on the host, and only its own api can see it.
paneCommand: () => api.pty.paneCommand(id),
diff --git a/src/shared/agents/config.capabilities.test.ts b/src/shared/agents/config.capabilities.test.ts
index 9b4fac886..085830836 100644
--- a/src/shared/agents/config.capabilities.test.ts
+++ b/src/shared/agents/config.capabilities.test.ts
@@ -11,6 +11,7 @@ import {
canResume,
canSubagent,
canTransferFrom,
+ createdAgentId,
hasHooks,
hasPermissionMode,
hasUsage
@@ -48,3 +49,23 @@ describe('opencode capabilities', () => {
}
})
})
+
+describe('createdAgentId', () => {
+ it('reads data.agentId, with the legacy tags fallback', () => {
+ expect(createdAgentId({ agentId: 'codex' })).toBe('codex')
+ expect(createdAgentId({ tags: ['claude', 'x'] })).toBe('claude')
+ expect(createdAgentId({ agentId: 'gemini', tags: ['claude'] })).toBe('gemini')
+ })
+
+ it('is undefined for a plain terminal, a foreign tag, or nothing at all', () => {
+ expect(createdAgentId({})).toBeUndefined()
+ expect(createdAgentId({ tags: ['review'] })).toBeUndefined()
+ expect(createdAgentId(undefined)).toBeUndefined()
+ })
+
+ it('tolerates hand-edited project.json shapes', () => {
+ // node data is deserialized JSON: nothing guarantees these types at runtime.
+ expect(createdAgentId({ agentId: 42 })).toBeUndefined()
+ expect(createdAgentId({ tags: 'claude' })).toBeUndefined()
+ })
+})
diff --git a/src/shared/agents/config.ts b/src/shared/agents/config.ts
index 19d14cd75..3d4badbdf 100644
--- a/src/shared/agents/config.ts
+++ b/src/shared/agents/config.ts
@@ -96,6 +96,27 @@ export const hasPermissionMode = (id: AgentId): boolean => includes(PERMISSION_M
export const agentConfig = (id: AgentId): AgentConfig | undefined =>
(AGENT_CONFIG as Record<string, AgentConfig>)[id]
+/**
+ * The agent a terminal node was CREATED as: `data.agentId`, with the legacy `tags` fallback for
+ * nodes serialized before `agentId` existed. Node data is deserialized (hand-editable) JSON, so
+ * the shapes are checked at runtime rather than trusted from the type.
+ *
+ * Deliberately NOT a hook-status fallback (Canvas's wider `agentIdOf`), which also reports a plain
+ * terminal someone typed `claude` into by hand.
+ *
+ * ONE definition on purpose: the canvas menu decides from it whether to OFFER an in-place restart,
+ * and the node's restart closure captures it to decide whether to RUN one. Two copies that drift
+ * apart silently produce a menu row whose closure refuses every click.
+ */
+export function createdAgentId(
+ data: { agentId?: unknown; tags?: unknown } | undefined
+): AgentId | undefined {
+ if (!data) return undefined
+ if (typeof data.agentId === 'string' && data.agentId) return data.agentId as AgentId
+ const tags = Array.isArray(data.tags) ? data.tags : []
+ return tags.includes('claude') ? 'claude' : undefined
+}
+
// Session ids are interpolated into a shell command line (written into the live shell on a
// cold restart), so accept only the safe charset agents actually use (UUIDs etc.) — never a
// flag-like or metacharacter-bearing value.