From 7c56d162c2a8688b33a1731b31439278554e1a15 Mon Sep 17 00:00:00 2001 From: Tauri-EPO Date: Tue, 1 Sep 2026 18:31:01 -0300 Subject: [PATCH 1/2] fix(cli): infer launchAgent when terminal create runs an interactive agent command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `orca terminal create --command "codex …"` (or `claude …`) never set launchAgent on the pane; it was only inferred later, reactively, from the agent's OSC title. A worker-start chained right after create therefore hit dispatch_input before any agent identity existed, took the open-loop submit delay instead of the agent-aware render gate, and stalled at agent_prompt_stalled (#17291). The CLI now reuses recognizeAgentProcessFromCommandLine to set launchAgent at creation time. Headless one-shots stay unrecognized: the shared recognizer already drops `claude -p`, and the Codex classifier rules out `codex exec` and its other non-interactive subcommands. Closes #17291 Co-Authored-By: Claude Fable 5.1 --- src/cli/handlers/terminal.test.ts | 40 +++++++++++++++++++++++++++++++ src/cli/handlers/terminal.ts | 18 ++++++++++++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/cli/handlers/terminal.test.ts b/src/cli/handlers/terminal.test.ts index bc411e322bf9..7591efeb8cd2 100644 --- a/src/cli/handlers/terminal.test.ts +++ b/src/cli/handlers/terminal.test.ts @@ -245,3 +245,43 @@ describe('terminal send CLI', () => { }) }) }) + +describe('terminal create CLI', () => { + afterEach(() => { + vi.restoreAllMocks() + }) + + async function createWith(command: string | undefined): Promise> { + const call = vi.fn().mockResolvedValue({ + result: { terminal: { handle: 'term-1', tabId: 'tab-1', worktreeId: 'wt-1' } } + }) + vi.spyOn(console, 'log').mockImplementation(() => {}) + const flags = new Map([['worktree', 'path:/tmp/wt']]) + if (command !== undefined) { + flags.set('command', command) + } + await TERMINAL_HANDLERS['terminal create']({ + flags, + client: { call, isRemote: false } as unknown as RuntimeClient, + cwd: '/tmp/worktree', + json: true + }) + return call.mock.calls[0]![1] as Record + } + + // Why (#17291): a worker-start chained right after create must find the agent already recognized. + it.each([ + ['codex', 'codex'], + ['claude --model sonnet --effort high', 'claude'], + ['codex --yolo', 'codex'] + ])('infers launchAgent from the interactive agent command %s', async (command, agent) => { + expect(await createWith(command)).toMatchObject({ command, launchAgent: agent }) + }) + + it.each(['codex exec "summarize"', 'claude -p "hello"', 'npm run dev', undefined])( + 'leaves launchAgent unset for %s', + async (command) => { + expect(await createWith(command)).not.toHaveProperty('launchAgent') + } + ) +}) diff --git a/src/cli/handlers/terminal.ts b/src/cli/handlers/terminal.ts index a0a8dc773cce..b8255ffbf30a 100644 --- a/src/cli/handlers/terminal.ts +++ b/src/cli/handlers/terminal.ts @@ -11,7 +11,11 @@ import type { RuntimeTerminalWait } from '../../shared/runtime-types' import type { CommandHandler } from '../dispatch' -import { shouldUseRendererBackedInteractiveTerminal } from '../codex-command-classification' +import { + shouldUseRendererBackedCodexTerminal, + shouldUseRendererBackedInteractiveTerminal +} from '../codex-command-classification' +import { recognizeAgentProcessFromCommandLine } from '../../shared/agent-process-recognition' import { formatTerminalClose, formatTerminalCreate, @@ -182,6 +186,15 @@ export const TERMINAL_HANDLERS: Record = { const useRendererBackedInteractiveTerminal = !client.isRemote && shouldUseRendererBackedInteractiveTerminal(command) const focus = flags.get('focus') === true + // Why (#17291): without this the pane has no launchAgent until the runtime infers one from an + // OSC title, so a worker-start chained right after create takes the open-loop submit delay and + // the generic readiness path. The shared recognizer already drops `claude -p`; `codex exec` and + // its other one-shot subcommands are only known to the Codex classifier. + const recognizedAgent = recognizeAgentProcessFromCommandLine(command)?.agent + const inferredLaunchAgent = + recognizedAgent === 'codex' && !shouldUseRendererBackedCodexTerminal(command) + ? undefined + : recognizedAgent const result = await client.call<{ terminal: RuntimeTerminalCreate }>('terminal.create', { worktree: await getBrowserWorktreeSelector(flags, cwd, client), command, @@ -191,7 +204,8 @@ export const TERMINAL_HANDLERS: Record = { // unless the caller explicitly asks for focus. focus, ...(focus ? { presentation: 'focused' } : {}), - ...(useRendererBackedInteractiveTerminal ? { rendererBacked: true, activate: focus } : {}) + ...(useRendererBackedInteractiveTerminal ? { rendererBacked: true, activate: focus } : {}), + ...(inferredLaunchAgent ? { launchAgent: inferredLaunchAgent } : {}) }) printResult(result, json, formatTerminalCreate) }, From c42dc01a691af8e7c6506b7f151ece479ffcf579 Mon Sep 17 00:00:00 2001 From: Tauri-EPO Date: Tue, 1 Sep 2026 20:32:51 -0300 Subject: [PATCH 2/2] fix(cli): label only interactive claude and codex commands with launchAgent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review follow-up: the inference labeled every agent the shared recognizer returned, but only codex had its one-shot subcommands filtered, so `opencode run …`, `gemini -p …` or `aider --message …` would have been labeled and, through launchAgent, marked unattended. The gate is now the interactive claude/codex classification the renderer-backed path already uses; other agents stay unlabeled until the runtime infers them, exactly as before this change. Co-Authored-By: Claude Fable 5.1 --- src/cli/handlers/terminal.test.ts | 20 ++++++++++++++------ src/cli/handlers/terminal.ts | 18 +++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/cli/handlers/terminal.test.ts b/src/cli/handlers/terminal.test.ts index 7591efeb8cd2..727befe4fb74 100644 --- a/src/cli/handlers/terminal.test.ts +++ b/src/cli/handlers/terminal.test.ts @@ -278,10 +278,18 @@ describe('terminal create CLI', () => { expect(await createWith(command)).toMatchObject({ command, launchAgent: agent }) }) - it.each(['codex exec "summarize"', 'claude -p "hello"', 'npm run dev', undefined])( - 'leaves launchAgent unset for %s', - async (command) => { - expect(await createWith(command)).not.toHaveProperty('launchAgent') - } - ) + it.each([ + 'codex exec "summarize"', + 'claude -p "hello"', + 'claude --version', + 'npm run dev', + // Why: the interactivity of other agents' commands is not classified here, and a launchAgent + // also marks the pane unattended, so they stay unlabeled until the runtime infers them. + 'gemini', + 'opencode run "summarize"', + 'aider --message "fix"', + undefined + ])('leaves launchAgent unset for %s', async (command) => { + expect(await createWith(command)).not.toHaveProperty('launchAgent') + }) }) diff --git a/src/cli/handlers/terminal.ts b/src/cli/handlers/terminal.ts index b8255ffbf30a..a3a7a7955ce3 100644 --- a/src/cli/handlers/terminal.ts +++ b/src/cli/handlers/terminal.ts @@ -11,10 +11,7 @@ import type { RuntimeTerminalWait } from '../../shared/runtime-types' import type { CommandHandler } from '../dispatch' -import { - shouldUseRendererBackedCodexTerminal, - shouldUseRendererBackedInteractiveTerminal -} from '../codex-command-classification' +import { shouldUseRendererBackedInteractiveTerminal } from '../codex-command-classification' import { recognizeAgentProcessFromCommandLine } from '../../shared/agent-process-recognition' import { formatTerminalClose, @@ -188,13 +185,16 @@ export const TERMINAL_HANDLERS: Record = { const focus = flags.get('focus') === true // Why (#17291): without this the pane has no launchAgent until the runtime infers one from an // OSC title, so a worker-start chained right after create takes the open-loop submit delay and - // the generic readiness path. The shared recognizer already drops `claude -p`; `codex exec` and - // its other one-shot subcommands are only known to the Codex classifier. + // the generic readiness path. Only claude and codex are labeled: they are the agents with an + // echo gate to unlock, and the only ones whose one-shot forms (`claude -p`, `codex exec`, …) + // are all known here. A launchAgent also marks the pane unattended, so an unknown agent's + // one-shot must not be guessed interactive. const recognizedAgent = recognizeAgentProcessFromCommandLine(command)?.agent const inferredLaunchAgent = - recognizedAgent === 'codex' && !shouldUseRendererBackedCodexTerminal(command) - ? undefined - : recognizedAgent + (recognizedAgent === 'claude' || recognizedAgent === 'codex') && + shouldUseRendererBackedInteractiveTerminal(command) + ? recognizedAgent + : undefined const result = await client.call<{ terminal: RuntimeTerminalCreate }>('terminal.create', { worktree: await getBrowserWorktreeSelector(flags, cwd, client), command,