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.

feat(agents): restart with fresh shell

Darren Kattan30134b54e624
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index ad26a10e6..32f8d7d49 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -4672,14 +4672,21 @@ export function Canvas() {
const restartAgentNode = useCallback(async (
nodeId: string,
targetAgentId?: AgentId,
- targetModel?: string
+ targetModel?: string,
+ restartShell?: boolean
) => {
const fn = agentRestartFn(nodeId)
if (!fn) return // node unmounted between opening the menu and clicking
- const action = targetModel ? 'Model switch' : targetAgentId ? 'Reopen' : 'Restart'
+ const action = restartShell
+ ? 'Restart'
+ : targetModel
+ ? 'Model switch'
+ : targetAgentId
+ ? 'Reopen'
+ : 'Restart'
let outcome: RestartOutcome
try {
- outcome = await fn(targetAgentId, targetModel)
+ outcome = await fn(targetAgentId, targetModel, restartShell)
} catch {
// The transport under the restart threw (a relay socket still CONNECTING rejects the very
// first write). Unhandled, this rejection made the action a silent no-op — the user clicked
@@ -5403,6 +5410,20 @@ export function Canvas() {
hint: why ?? 'Quits the CLI and relaunches it with --resume (same conversation).',
onClick: () => void restartAgentNode(ids[0])
},
+ // Restart agent AND shell: same quit + relaunch, but RECYCLES the tmux session so a
+ // FRESH shell spawns — re-sourcing the user's profile/env (a change to .zshrc, or an
+ // env var set after this node was created), which typing the resume line into the
+ // existing shell never picks up. Same eligibility gate as Restart; the cold-restore
+ // auto-resume on the fresh spawn relaunches the agent with --resume <sid>.
+ {
+ label: 'Restart agent and shell',
+ icon: <IconPower />,
+ disabled: !!why,
+ hint:
+ why ??
+ 'Quits the CLI, respawns a fresh shell (picks up env/profile changes), then resumes.',
+ onClick: () => void restartAgentNode(ids[0], undefined, undefined, true)
+ },
...(variants.length
? ([
{
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 99e7c50e4..0c5acdf11 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -2855,7 +2855,7 @@ export function TerminalNode({
}
const unregisterRestart = registerAgentRestart(
id,
- guardConcurrentRestart(id, async (targetAgentId?: AgentId, targetModel?: string) => {
+ guardConcurrentRestart(id, async (targetAgentId?: AgentId, targetModel?: string, restartShell?: boolean) => {
const st = useAgentStatus.getState().byId[id]
const agentSessionId = st?.sessionId
// `data.agentId` can change after a successful same-base swap while this deliberately
@@ -2908,6 +2908,30 @@ export function TerminalNode({
}))
return 'restarted'
}
+ // "Restart agent and shell": same quit + recycle as a model switch, but the agent and model
+ // are UNCHANGED — the point is a FRESH shell that re-sources the user's profile/env (a
+ // change to .zshrc, or an env var set after this node was created), which typing the resume
+ // line into the existing shell never picks up. The respawn's cold-restore auto-resume
+ // relaunches the agent (`--resume <sid>`), so the conversation continues in the fresh shell.
+ // Relay sessions are excluded for the same reason a model switch is: their shell env belongs
+ // to another core/settings store, and recycling here would respawn against this Mac's env.
+ if (restartShell) {
+ if (session.source === 'relay') return 'not-eligible'
+ const exited = await performExitPhase({
+ agentId: target,
+ sessionId: agentSessionId,
+ io: restartIo,
+ paneCommand: () => api.pty.paneCommand(id),
+ isLive: restartTarget
+ })
+ if (exited !== 'exited') return exited
+ transport.recycle(id)
+ updateNodeData(id, (node) => ({
+ agentId: target,
+ respawnNonce: ((node.data.respawnNonce as number | undefined) ?? 0) + 1
+ }))
+ return 'restarted'
+ }
// Built HERE, not inside the choreography: the shared assembly builder is the single funnel
// for every CLI launch path (shared/agents/launch.ts) and the mode is a renderer-side, async
// read — exactly as the cold-restore relaunch above does it. Without it a canvas running
diff --git a/src/renderer/terminal/agent-restart.ts b/src/renderer/terminal/agent-restart.ts
index 4aa66aaad..7cc61ab35 100644
--- a/src/renderer/terminal/agent-restart.ts
+++ b/src/renderer/terminal/agent-restart.ts
@@ -409,9 +409,22 @@ export function guardConcurrentRestart<T extends string, Args extends unknown[]>
}
// ── Node registry (same park-surviving pattern as TerminalNode's restartSubs) ────────────
+// The closure's optional args select what kind of restart:
+// - no args → plain "Restart agent": quit + resume the SAME agent in the SAME shell.
+// - `targetAgentId` → "Reopen session as <variant>": quit + resume the SAME session id
+// under a same-base agent's binary (the id is harness-portable within
+// a base; see lib/reopenVariants.ts).
+// - `targetModel` → switch the gateway model: quit + RECYCLE the tmux session so a fresh
+// shell spawns with the new gateway env, then the agent auto-resumes.
+// - `restartShell: true` → "Restart agent and shell": quit + RECYCLE for a FRESH shell (picks up
+// profile/env changes the same-shell restart cannot) keeping the SAME
+// agent + model, then the agent auto-resumes. The recycle-after-exit
+// mechanism is the one a model switch already uses, exposed as its own
+// action for the "I changed my .zshrc" case.
export type AgentRestartFn = (
targetAgentId?: AgentId,
- targetModel?: string
+ targetModel?: string,
+ restartShell?: boolean
) => Promise<RestartOutcome>
const restartFns = new Map<string, AgentRestartFn>()