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
feat(restart): eligibility + exit-sequence helpers for in-place agent restart
enes48889af14722
diff --git a/src/renderer/terminal/agent-restart.test.ts b/src/renderer/terminal/agent-restart.test.tsnew file mode 100644index 000000000..130619c00--- /dev/null+++ b/src/renderer/terminal/agent-restart.test.ts@@ -0,0 +1,44 @@+import { describe, expect, it } from 'vitest'+import { exitSequence, isShellCommand, restartEligibility } from './agent-restart'++describe('exitSequence', () => {+ it('knows claude and codex, refuses others', () => {+ expect(exitSequence('claude')).toBe('/exit')+ expect(exitSequence('codex')).toBe('/quit')+ expect(exitSequence('gemini')).toBeNull()+ expect(exitSequence('my-custom')).toBeNull()+ })+})++describe('isShellCommand', () => {+ it('matches plain, login-dash and path-prefixed shells', () => {+ for (const c of ['zsh', 'bash', 'sh', 'fish', '-zsh', '/bin/bash', '/usr/local/bin/fish'])+ expect(isShellCommand(c)).toBe(true)+ })+ it('rejects agents, editors and empty', () => {+ for (const c of ['claude', 'codex', 'node', 'vim', '', null, undefined])+ expect(isShellCommand(c as never)).toBe(false)+ })+})++describe('restartEligibility', () => {+ it('ok for a resumable agent with a session id in a non-working state', () => {+ expect(restartEligibility('claude', 'waiting', 'abc-123')).toEqual({ ok: true })+ expect(restartEligibility('codex', 'done', 'abc-123')).toEqual({ ok: true })+ })+ it('flags working / missing session / non-resumable, in that priority', () => {+ expect(restartEligibility('claude', 'working', 'abc')).toEqual({ ok: false, reason: 'working' })+ expect(restartEligibility('claude', 'waiting', undefined)).toEqual({+ ok: false,+ reason: 'no-session'+ })+ expect(restartEligibility('gemini', 'waiting', 'abc')).toEqual({+ ok: false,+ reason: 'not-resumable'+ })+ expect(restartEligibility(undefined, undefined, undefined)).toEqual({+ ok: false,+ reason: 'not-resumable'+ })+ })+})diff --git a/src/renderer/terminal/agent-restart.ts b/src/renderer/terminal/agent-restart.tsnew file mode 100644index 000000000..a1450eddb--- /dev/null+++ b/src/renderer/terminal/agent-restart.ts@@ -0,0 +1,44 @@+/**+ * Pure helpers for restarting an agent CLI IN PLACE inside its tmux pane — quit the CLI, then+ * relaunch it with the provider's own `--resume`, so a newly released model shows up in the CLI's+ * model list without losing the conversation. Kept free of DOM/IPC so the node menu, the bulk+ * filter and the restart choreography can all share exactly one set of rules.+ */+import { canResume } from '../../shared/agents/config'++/** In-band exit command per agent CLI. Only agents listed here can be restarted in place —+ * an unknown CLI has no safe way to be asked to quit. */+const EXIT_SEQUENCES: Record<string, string> = { claude: '/exit', codex: '/quit' }++export function exitSequence(agentId: string): string | null {+ return EXIT_SEQUENCES[agentId] ?? null+}++/** Foreground commands that mean "the CLI is gone, a shell owns the pane". Login shells+ * report as '-zsh'; tmux may report a full path. */+const SHELLS = new Set(['zsh', 'bash', 'sh', 'fish', 'dash', 'ksh', 'tcsh'])++export function isShellCommand(cmd: string | null | undefined): boolean {+ if (!cmd) return false+ const base = cmd.replace(/^-/, '').split('/').pop() ?? ''+ return SHELLS.has(base)+}++export type IneligibleReason = 'working' | 'no-session' | 'not-resumable'++/** Single gate shared by the node menu, the bulk filter and the choreography itself.+ * `not-resumable` wins over the other two: a CLI we cannot quit or resume can never be+ * restarted, so there is nothing for the user to fix by waiting or picking another node. */+export function restartEligibility(+ agentId: string | undefined,+ state: string | undefined,+ sessionId: string | undefined+): { ok: true } | { ok: false; reason: IneligibleReason } {+ if (!agentId || !canResume(agentId) || !exitSequence(agentId))+ return { ok: false, reason: 'not-resumable' }+ // Quitting mid-turn would abandon work the agent is in the middle of.+ if (state === 'working') return { ok: false, reason: 'working' }+ // Without a provider session id there is nothing to resume into.+ if (!sessionId) return { ok: false, reason: 'no-session' }+ return { ok: true }+}