Files
orca/src/shared/tui-agent-launch-command.ts
T
Jinjing 5b75a87dd3 feat(native-chat): add per-model session option pickers with verified Claude switch (#9085)
* Add per-model session-option pickers (model/effort/fast-mode) to native

Introduces a shared agent session-option catalog (Claude/Codex/Gemini/Cursor)
with model-scoped options, launch-command composition, mid-session dispatch
via slash commands, and per-model persisted defaults. Wires the new
NativeChatSessionOptionPickers UI into the composer, threads sessionOptions
through every startup-plan builder (worktree creation, onboarding, source
control actions, folder workspace, direct work-item launches), and adds
localized strings and tests across the affected surfaces.

* Add per-model session-option pickers with a verified Claude model switch

Native chat's model/effort picker now dispatches option commands through a
body-then-verified-Enter write path and, for Claude, arms a PTY observer that
classifies the cached-history confirmation prompt as applied/rejected/needs
interaction before the picker returns — falling back to the terminal only
when Claude genuinely requires manual input, and clearing stale truth
otherwise. Also reorders the composer's model/effort pills, disambiguates
their tooltip labels, and switches disabled-reason strings to a closed enum
so producer and localized copy can't drift.

* Add live model/effort detection from Claude's TUI header

- Reads the mounted xterm's main-buffer snapshot (falling back to the
  rendered screen when the alternate screen owns the buffer) to parse
  Claude's header for the currently active model and effort, so the
  native chat picker reflects reality instead of only dispatched state
- Extracts command-apply recording and reported-value application into
  dedicated modules, and factors file-link click handling into a hook,
  to keep native-chat-pty-session-options.ts focused
2026-07-16 17:12:44 -07:00

63 lines
2.2 KiB
TypeScript

import { resolveAgentSessionOptionLaunch } from './agent-session-option-launch'
import type { SessionOptionValue } from './native-chat-session-options'
import { getTuiAgentLaunchCommand, TUI_AGENT_CONFIG } from './tui-agent-config'
import {
planAgentCliArgsSuffix,
quoteStartupArg,
tokenizeStartupCommand,
type AgentStartupShell
} from './tui-agent-startup-shell'
import type { TuiAgent } from './types'
export type ResolvedAgentLaunchCommand =
| {
ok: true
command: string
commandWithoutSessionOptions: string
appliedSessionOptions: Record<string, SessionOptionValue>
}
| { ok: false; error: string }
export function resolveAgentLaunchCommand(args: {
agent: TuiAgent
cmdOverrides: Partial<Record<TuiAgent, string>>
platform: NodeJS.Platform
shell: AgentStartupShell
agentArgs?: string | null
sessionOptions?: Record<string, SessionOptionValue>
isRemote?: boolean
}): ResolvedAgentLaunchCommand {
const override = args.cmdOverrides[args.agent]
const command =
override ||
getTuiAgentLaunchCommand(TUI_AGENT_CONFIG[args.agent], args.platform, {
isRemote: args.isRemote
})
const suffix = planAgentCliArgsSuffix(args.agentArgs, args.shell)
if (!suffix.ok) {
return suffix
}
const trailingTokens = args.agentArgs?.trim()
? tokenizeStartupCommand(args.agentArgs.trim(), args.shell)
: { ok: true as const, tokens: [] }
if (!trailingTokens.ok) {
return { ok: false, error: `CLI arguments are invalid: ${trailingTokens.error}` }
}
const resolvedOptions = resolveAgentSessionOptionLaunch(
args.agent,
args.sessionOptions,
trailingTokens.tokens
)
const optionSuffix = resolvedOptions.args.map((arg) => quoteStartupArg(arg, args.shell)).join(' ')
const commandWithOptions = optionSuffix ? `${command} ${optionSuffix}` : command
const commandWithoutSessionOptions = suffix.suffix ? `${command} ${suffix.suffix}` : command
// Why: session flags precede the free-form suffix so the user's explicit
// repeated flag remains the final, winning occurrence.
return {
ok: true,
command: suffix.suffix ? `${commandWithOptions} ${suffix.suffix}` : commandWithOptions,
commandWithoutSessionOptions,
appliedSessionOptions: resolvedOptions.appliedValues
}
}