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(grok): allow the in-place restart-and-resume for grok nodes

enes07679e6bbbde
diff --git a/src/renderer/terminal/agent-restart.test.ts b/src/renderer/terminal/agent-restart.test.ts
index c0fe40336..67ae4b188 100644
--- a/src/renderer/terminal/agent-restart.test.ts
+++ b/src/renderer/terminal/agent-restart.test.ts
@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { resumeCommand, withPermissionMode } from '../../shared/agents/config'
import {
__resetAgentRestartForTests,
agentRestartFn,
@@ -17,9 +18,11 @@ import {
} from './agent-restart'
describe('exitSequence', () => {
- it('knows claude and codex, refuses others', () => {
+ it('knows claude, codex and grok, refuses others', () => {
expect(exitSequence('claude')).toBe('/exit')
expect(exitSequence('codex')).toBe('/quit')
+ // grok's documented primary is `/quit` (`/exit` is its alias).
+ expect(exitSequence('grok')).toBe('/quit')
expect(exitSequence('gemini')).toBeNull()
expect(exitSequence('my-custom')).toBeNull()
})
@@ -431,6 +434,82 @@ describe('performRestartResume', () => {
})
})
+describe('performRestartResume — grok', () => {
+ beforeEach(() => vi.useFakeTimers())
+ afterEach(() => vi.useRealTimers())
+
+ it("quits with grok's own exit line and resumes by session id", async () => {
+ const { written, io } = fakeIo()
+ let pane = 'grok'
+ const p = performRestartResume({
+ agentId: 'grok',
+ sessionId: 'abc-1',
+ io,
+ paneCommand: async () => pane,
+ timeoutMs: 6000,
+ pollMs: 100
+ })
+ await vi.advanceTimersByTimeAsync(250) // a few polls while the CLI is still up
+ pane = 'zsh'
+ await vi.advanceTimersByTimeAsync(5000)
+ expect(await p).toBe('restarted')
+ // `/quit`, not claude's `/exit` — the table is per CLI.
+ expect(written.slice(0, 2)).toEqual(['\x15', '/quit\r'])
+ expect(written.join('')).toContain('grok --resume abc-1')
+ })
+
+ it("delivers the caller's permission-mode resume line, composed as TerminalNode composes it", async () => {
+ const { written, io } = fakeIo()
+ // The one place the two grok rules meet: `resumeCommand` builds the resume line and
+ // `withPermissionMode` appends the flag (no `--` separator here — the resume line carries no
+ // positional prompt). Pinned on the COMPOSED string, because that is what reaches the pane.
+ const command = withPermissionMode(resumeCommand('grok', 'abc-1')!, 'grok', 'plan')
+ expect(command).toBe('grok --resume abc-1 --permission-mode plan')
+ const p = performRestartResume({
+ agentId: 'grok',
+ sessionId: 'abc-1',
+ io,
+ command,
+ paneCommand: async () => 'zsh',
+ timeoutMs: 1000,
+ pollMs: 100
+ })
+ await vi.advanceTimersByTimeAsync(5000)
+ expect(await p).toBe('restarted')
+ expect(written.join('')).toContain('grok --resume abc-1 --permission-mode plan')
+ })
+})
+
+describe('restartEligibility — grok', () => {
+ it('is a target once it has a session id and is not busy', () => {
+ expect(restartEligibility('grok', 'done', 'abc-1')).toEqual({ ok: true })
+ expect(restartEligibility('grok', 'waiting', 'abc-1')).toEqual({ ok: true })
+ expect(restartEligibility('grok', 'done', undefined)).toEqual({
+ ok: false,
+ reason: 'no-session'
+ })
+ })
+
+ it('refuses a working OR blocked session — `/quit` typed into a prompt ANSWERS it', () => {
+ // Agent-agnostic by construction (BUSY_STATES), so grok needs no branch of its own.
+ for (const state of ['working', 'blocked'] as const)
+ expect(restartEligibility('grok', state, 'abc-1'), state).toEqual({
+ ok: false,
+ reason: 'working'
+ })
+ })
+
+ it('keeps a busy grok node out of the bulk run', () => {
+ const plan = planBulkRestart([
+ { id: 'idle', agentId: 'grok', state: 'done', sessionId: 'sid-1', wired: true },
+ { id: 'busy', agentId: 'grok', state: 'working', sessionId: 'sid-2', wired: true },
+ { id: 'prompt', agentId: 'grok', state: 'blocked', sessionId: 'sid-3', wired: true }
+ ])
+ expect(plan.runnable).toEqual(['idle'])
+ expect(plan.skipped).toEqual({ working: 2, noSession: 0 })
+ })
+})
+
describe('performRestartResume — the delivery await is bounded', () => {
beforeEach(() => {
vi.resetModules()
diff --git a/src/renderer/terminal/agent-restart.ts b/src/renderer/terminal/agent-restart.ts
index b1a72e696..68d1e99c9 100644
--- a/src/renderer/terminal/agent-restart.ts
+++ b/src/renderer/terminal/agent-restart.ts
@@ -14,8 +14,12 @@ import {
} from './command-delivery'
/** 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' }
+ * an unknown CLI has no safe way to be asked to quit.
+ *
+ * grok: `/quit` (its `/exit` is an alias — the documented primary is the one we type), and its
+ * relaunch line comes from `resumeCommand` → `grok --resume <id>`, so one entry here turns on the
+ * header button, the node-menu row and the bulk "restart idle agents" action at once. */
+const EXIT_SEQUENCES: Record<string, string> = { claude: '/exit', codex: '/quit', grok: '/quit' }
export function exitSequence(agentId: string): string | null {
return EXIT_SEQUENCES[agentId] ?? null