fix(native-chat): add direct Codex model selection (#12657)

* fix(native-chat): select Codex models directly

* fix(native-chat): confirm agent exits before switching views

* fix(runtime): handle unavailable foreground probes
This commit is contained in:
Brennan Benson
2026-08-05 11:27:12 -07:00
committed by GitHub
parent de64337c26
commit 5d2ad3597a
11 changed files with 261 additions and 25 deletions
@@ -203,6 +203,11 @@ export const CODEX_SESSION_OPTION_CATALOG: AgentSessionOptionCatalog = {
modelApply: {
launchArgs: (value) => ['-m', String(value)],
agentArgsOverride: (tokens) => hasFlag(tokens, ['-m', '--model']),
midSession: { kind: 'agent-picker', command: '/model' }
// Codex accepts a model argument in its live /model command.
midSession: {
kind: 'command',
build: (value) => `/model ${String(value)}`,
pickerCommand: '/model'
}
}
}
+14
View File
@@ -56,16 +56,21 @@ export function createAgentStatusTracker(
): {
handleTitle: (title: string) => void
seedTitle: (title: string) => void
restoreLastExit: () => void
reset: () => void
} {
// Why: trackers restored mid-session need a last-known status without firing
// callbacks, or a hidden working agent can miss its later idle transition.
let lastStatus: AgentStatus | null =
initialTitle !== undefined ? detectAgentStatusFromTitle(initialTitle) : null
let restorableExitStatus: AgentStatus | null = null
return {
handleTitle(title: string): void {
const newStatus = detectAgentStatusFromTitle(title)
if (newStatus !== null) {
restorableExitStatus = null
}
if (lastStatus === 'working' && newStatus !== null && newStatus !== 'working') {
onBecameIdle(title)
}
@@ -75,6 +80,7 @@ export function createAgentStatusTracker(
// Why: reverting to a plain shell prompt after idle/permission means the
// agent exited; while working it can just be a transient internal title.
if (lastStatus !== null && lastStatus !== 'working' && newStatus === null) {
restorableExitStatus = lastStatus
lastStatus = null
onAgentExited?.()
}
@@ -84,9 +90,17 @@ export function createAgentStatusTracker(
},
seedTitle(title: string): void {
lastStatus = detectAgentStatusFromTitle(title)
restorableExitStatus = null
},
restoreLastExit(): void {
if (lastStatus === null && restorableExitStatus !== null) {
lastStatus = restorableExitStatus
}
restorableExitStatus = null
},
reset(): void {
lastStatus = null
restorableExitStatus = null
}
}
}
@@ -67,7 +67,7 @@ describe('buildNativeChatSessionOptionCommand', () => {
).toBe('/fast')
})
it('has no absolute command for agent-picker applies (Codex model)', () => {
it('builds an absolute command for live Codex model changes', () => {
expect(
buildNativeChatSessionOptionCommand({
optionId: 'model',
@@ -78,7 +78,7 @@ describe('buildNativeChatSessionOptionCommand', () => {
models: CODEX_SESSION_OPTION_CATALOG.models,
record: createNativeChatSessionOptionRecord('codex')
})
).toBeNull()
).toBe('/model gpt-5.5')
})
})
@@ -172,7 +172,7 @@ describe('buildNativeChatSessionOptionSnapshot', () => {
})
})
it('exposes Codex model changes as an agent-picker action', () => {
it('exposes Codex model changes as native selectable values', () => {
const snapshot = buildNativeChatSessionOptionSnapshot({
catalog: CODEX_SESSION_OPTION_CATALOG,
models: CODEX_SESSION_OPTION_CATALOG.models,
@@ -180,7 +180,12 @@ describe('buildNativeChatSessionOptionSnapshot', () => {
mode: 'live',
modelLabel: 'Model'
})
expect(snapshot[0]).toMatchObject({ settable: true, action: { type: 'agent-picker' } })
expect(snapshot[0]).toMatchObject({ settable: true })
expect(snapshot[0]?.action).toBeUndefined()
expect(snapshot[0]?.kind).toMatchObject({
type: 'select',
choices: expect.arrayContaining([{ value: 'gpt-5.5', label: 'GPT-5.5' }])
})
})
it('marks flip-only toggles without a baseline as toggle actions', () => {
@@ -90,6 +90,8 @@ export type TerminalTitleTracker = {
* No-ops once any title has been observed or seeded (live state wins); fires no callbacks.
*/
seedInitialTitle: (rawTitle: string) => void
/** Restore the status consumed by the latest exit candidate when process evidence disproves it. */
restoreLastAgentExit: () => void
/** Last title surfaced through onTitle, after normalization. */
getLastNormalizedTitle: () => string | null
/**
@@ -262,6 +264,9 @@ export function createTerminalTitleTracker(
lastEmittedTitle = normalizeTerminalTitle(rawTitle)
agentTracker?.seedTitle(rawTitle)
},
restoreLastAgentExit(): void {
agentTracker?.restoreLastExit()
},
getLastNormalizedTitle: () => lastEmittedTitle,
setTransientFactScanningSuppressed(suppressed: boolean): void {
if (suppressed === transientFactScanningSuppressed) {