Loading files
1f7f19214This file is pinned to the selected release. Download the original to open it in your design tool.
import { describe, expect, it, vi } from 'vitest'
import type { RegisteredSession } from './registry.js'
import { encodeRuntimeProfile, parseRuntimeProfile, RuntimeProfileManager } from './runtimeProfile.js'
import {
inspectRuntimePane,
parseCodexAdvancedRows,
parseCodexEffortRows,
parseCodexModelMenuRows,
parseCodexModelRows,
parseCursorModelPicker,
parseCursorParameterRows,
RuntimeProfileController,
} from './runtimeProfileController.js'
// The id inside a `runtime-v1:` string is the AGENT id ('h1' here) — a client only ever echoes back an id
// the catalog minted, and the catalog is agent-scoped. `setProfile` is still addressed with either id.
function session(engine: 'claude' | 'codex' | 'cursor' | 'opencode'): RegisteredSession {
return {
schemaVersion: 2,
active: true,
sessionId: 's1', engine, launcherId: 'h1', agentId: 'h1', boundAt: 0, transcriptPath: '/tmp/s1.jsonl', projectDir: 'tmp', cwd: '/tmp',
tmuxPane: '%1', source: null, title: null, model: null,
runtimes: [{ backend: 'tmux', paneId: '%1' }], primaryRuntimeKey: 'tmux\u0000%1',
cliVersion: engine === 'codex' ? '0.144.5' : engine === 'cursor' ? '2026.07.20-8cc9c0b' : engine === 'opencode' ? '1.18.31' : '2.1.212', processIdentity: null,
registeredAt: 1, updatedAt: 1, lastHookAt: 1, lastTranscriptAt: 1,
}
}
describe('runtime pane parsing', () => {
it('distinguishes dim placeholders from real drafts', () => {
expect(inspectRuntimePane('codex', '\u001b[1m›\u001b[0m \u001b[2mWrite tests\u001b[0m')).toMatchObject({ idle: true, draft: false })
expect(inspectRuntimePane('codex', '\u001b[1m›\u001b[0m write tests')).toMatchObject({ idle: false, draft: true })
expect(inspectRuntimePane('claude', '\u001b[39m❯\u00a0\u001b[2mAsk about the codebase\u001b[0m')).toMatchObject({ idle: true, draft: false })
expect(inspectRuntimePane('claude', '\u001b[39m❯\u00a0Ask about the codebase')).toMatchObject({ idle: false, draft: true })
expect(inspectRuntimePane(
'cursor',
'\u001b[48;2;21;21;21m \u001b[2m→ \u001b[0;7mP\u001b[0;2mlan, search, build anything\u001b[0m',
)).toMatchObject({ idle: true, draft: false })
})
it('reads hermes, which italicises its placeholder instead of dimming it', () => {
// Copied byte-for-byte off a live pane. Hermes carries no SGR 2 at all: the placeholder is
// italic (3) over a 256-colour gold, so a dim-only rule read every hermes pane as holding a
// draft — `idle` false for the agent's whole life, and every retarget answered AGENT_BUSY over an
// engine sitting at an empty prompt.
const placeholder = '❯ \u001b[3m\u001b[38;5;136mAsk anything, or type / for commands…\u001b[0m'
expect(inspectRuntimePane('hermes', placeholder)).toMatchObject({ idle: true, draft: false })
expect(inspectRuntimePane('hermes', '❯ what changed in this repo')).toMatchObject({ idle: false, draft: true })
})
it('reads opencode past the status strip its own gutter runs through', () => {
// The box: three composer rows, then the strip that names the mode, model and account, then the
// rule that closes it. Every one of those rows carries the `┃` gutter, so the last-marker rule
// landed on the strip and read the BOX describing itself as something the user had typed —
// opencode was never idle, and every retarget came back AGENT_BUSY over an empty composer.
const box = (composer: readonly string[]) => [
' ▣ Build · DeepSeek-V4-Flash-0731 · 6.0s',
'',
...composer.map((line) => ` ┃${line}`),
' ┃ Build · DeepSeek-V4-Flash-0731 autonomous.ai',
' ╹▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
' /Users/example/Downloads/20260907',
].join('\n')
expect(inspectRuntimePane('opencode', box(['', '', '']))).toMatchObject({ idle: true, draft: false })
// Wrapped text counts wherever in the box it sits: reading only the row above the strip would
// call a full composer empty.
expect(inspectRuntimePane('opencode', box(['', ' what changed in', ' this repo'])))
.toMatchObject({ idle: false, draft: true })
// No closing rule is a layout we do not recognise, and then nothing is assumed to be a status
// strip — a line the user typed must never be swallowed by a guess about the frame.
expect(inspectRuntimePane('opencode', [' ┃', ' ┃ fix the parser'].join('\n')))
.toMatchObject({ idle: false, draft: true })
// An earlier box still in scrollback is a message already SENT, not a draft.
expect(inspectRuntimePane(
'opencode',
[box(['', ' LSP là gì thế', '']), 'answer text', box(['', '', ''])].join('\n'),
)).toMatchObject({ idle: true, draft: false })
})
it('reads opencode past a card floating over its composer', () => {
// Copied off a live pane (2026-09-15). OpenCode's `Getting started` card is drawn on the RIGHT,
// which puts its text on the composer's own rows — a TUI paints one terminal row at a time, so
// anything floating over the box lands inside the box's lines. Reading to end-of-line took
// `Connect provider /connect` as something the user had typed, so an EMPTY composer read as a
// draft, the pane was never idle, and every model switch came back AGENT_BUSY.
const PANE = '\u001b[48;2;10;10;10m'
const BOX = '\u001b[48;2;30;30;30m'
const SIDEBAR = '\u001b[48;2;20;20;20m'
const BLUE = '\u001b[38;2;92;156;245m'
const WHITE = '\u001b[38;2;255;255;255m'
const row = (composer: string, card: string) =>
`${PANE} ${BLUE}┃${WHITE}${BOX}${composer.padEnd(40)}`
+ `${PANE} ${SIDEBAR} ${BOX} \u001b[38;2;238;238;238m${card}`
const pane = (composer: readonly string[]) => [
...composer.map((line) => row(line, 'Connect provider /connect')),
row(' Build · Big Pickle OpenCode Zen', ''),
` ${BLUE}╹\u001b[38;2;30;30;30m▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀`,
].join('\n')
expect(inspectRuntimePane('opencode', pane(['', '', '']))).toMatchObject({ idle: true, draft: false })
// The card must not be able to hide a draft either: text INSIDE the box still counts, on the
// very row the card writes into. Reading a real draft as an empty prompt respawns the engine
// under text the user typed — the one direction this must never be wrong in.
expect(inspectRuntimePane('opencode', pane(['', ' what changed in this repo', ''])))
.toMatchObject({ idle: false, draft: true })
})
it('reads OpenCode\'s grey placeholder as a placeholder, not a draft', () => {
// Copied off a live pane (1.18.31). The third placeholder styling this module has had to learn:
// claude/codex/devin draw dim, hermes draws italic, and OpenCode draws a plain TRUECOLOR GREY
// with neither attribute — so nothing recognised it and a BRAND-NEW pane read as one holding a
// draft. It was never idle, and every model switch on an agent with no messages yet refused as
// AGENT_BUSY over an empty composer.
const BOX = '\u001b[48;2;30;30;30m'
const PANE = '\u001b[48;2;10;10;10m'
const WHITE = '\u001b[38;2;255;255;255m'
const GREY = '\u001b[38;2;128;128;128m'
const pane = (composer: string) => [
` \u001b[38;2;92;156;245m┃${WHITE}${BOX} ${composer}${WHITE} ${PANE}`,
` \u001b[38;2;92;156;245m┃${WHITE}${BOX} \u001b[38;2;92;156;245mBuild${WHITE} ${GREY}·${WHITE} Big Pickle${PANE}`,
' \u001b[38;2;92;156;245m╹\u001b[38;2;30;30;30m▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
].join('\n')
expect(inspectRuntimePane('opencode', pane(`${GREY}Ask anything… "What is the tech stack of this project?"`)))
.toMatchObject({ idle: true, draft: false })
// ⚠️ The direction that must never be wrong: text the user typed is drawn in the composer's own
// near-white, and reading it as a placeholder would respawn the engine under a real draft.
expect(inspectRuntimePane('opencode', pane(`${WHITE}switch me please`)))
.toMatchObject({ idle: false, draft: true })
// A grey hint sitting BESIDE typed text does not make the line a placeholder — every visible
// character has to be muted, not merely some of them.
expect(inspectRuntimePane('opencode', pane(`${WHITE}fix the parser${GREY} ⏎ send`)))
.toMatchObject({ idle: false, draft: true })
})
it('reads copilot, whose composer carries no marker while its sent messages do', () => {
// Copied off a live pane. Copilot echoes every message the user has ALREADY SENT into the
// transcript as `❯ <text>` in full brightness, and draws its composer as a `┃` box that carries
// no marker at all — so the generic reader walked back to the last echo and read `hi`, a message
// sent minutes ago, as a draft. Copilot was never idle for the life of the agent, and every
// model switch came back AGENT_BUSY over an empty prompt.
const pane = (composer: string) => [
' ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
' \u001b[38;2;240;246;252m❯ hi\u001b[39m',
' ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
' ● Hi! What would you like to work on?',
' \u001b[38;2;145;152;161m~/Downloads/20260907\u001b[39m',
'\u001b[38;2;129;139;152m╻\u001b[38;2;20;27;34m▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄',
`\u001b[38;2;129;139;152m┃\u001b[39m\u001b[48;2;20;27;34m${composer}`,
'\u001b[38;2;129;139;152m\u001b[49m╹\u001b[38;2;20;27;34m▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀',
'\u001b[39m ← open sidebar · / commands · ? help · tab next tab',
].join('\n')
expect(inspectRuntimePane('copilot', pane(''))).toMatchObject({ idle: true, draft: false })
// Copilot's box has no status strip, so its single gutter line IS the composer. Dropping it the
// way opencode's last row is dropped would read a real draft as an empty prompt and respawn the
// pane out from under it.
expect(inspectRuntimePane('copilot', pane(' fix the parser'))).toMatchObject({ idle: false, draft: true })
// A picker or a permission prompt REPLACES the box, so there is no gutter on screen and the pane
// reads not-idle without [DIALOG_UI] having to name copilot's dialogs.
expect(inspectRuntimePane('copilot', [
'│ Do you want to allow this access?',
'│ ❯ 1. Yes',
'│ 2. No, and tell Copilot what to do differently (Esc to stop)',
].join('\n'))).toMatchObject({ idle: false })
})
it('reads grok past the right-hand edge of its own composer box', () => {
// Measured on a live pane (`harness-grok-*`, grok 4.6, 2026-09-09) with NOTHING typed into it.
// The shared reader takes everything after `❯` and finds the box's closing `│`: one character,
// non-empty, so `draft` was true on an empty composer. Not a transient — that edge is drawn on
// every frame, so `idle` was false for the agent's whole life and every model switch came back
// AGENT_BUSY. Same family as the hermes and opencode cases above; here the culprit is the box.
const W = 60
const box = (composer: readonly string[]) => [
' ╭' + '─'.repeat(W) + '╮',
...composer.map((line) => ' │ ' + line.padEnd(W - 2) + '│'),
' ╰' + '─'.repeat(W - 20) + ' Grok 4.6 (xhigh) ─╯',
'',
// The footer separator is also `│`, and it sits below the box. A body line must carry BOTH
// edges, which this — one separator, no edges — never does.
' Shift+Tab:mode │ Ctrl+x:shortcuts',
].join('\n')
expect(inspectRuntimePane('grok', box(['❯']))).toMatchObject({ idle: true, draft: false })
expect(inspectRuntimePane('grok', box(['❯ fix the parser']))).toMatchObject({ idle: false, draft: true })
// Wrapped text counts wherever in the box it sits — the marker is only on the first row.
expect(inspectRuntimePane('grok', box(['❯ a very long message', ' that wrapped down'])))
.toMatchObject({ idle: false, draft: true })
// An earlier box still in scrollback is a message already SENT, not a draft.
expect(inspectRuntimePane('grok', [box(['❯ what is an LSP']), 'answer text', box(['❯'])].join('\n')))
.toMatchObject({ idle: true, draft: false })
// A picker over the pane is not something to respawn under, empty composer or not.
expect(inspectRuntimePane('grok', box(['❯']) + '\n Select Model and Effort'))
.toMatchObject({ idle: false, dialog: true })
// A layout with no recognisable box is "we cannot tell", which the caller reads as busy. Refusing
// a switch costs a retry; respawning a pane we misread would discard whatever was in it.
expect(inspectRuntimePane('grok', ' │ ❯ fix the parser')).toMatchObject({ idle: false })
})
it('does not read a truecolor foreground as a dim placeholder', () => {
// `38;2;<r>;<g>;<b>` carries a literal 2 that is a colour-space selector, not the dim attribute.
// Counting it would make a line the user had TYPED look like an empty composer — the one
// direction this must never be wrong in, since the pane would read idle and be respawned under
// the draft.
expect(inspectRuntimePane('claude', '\u001b[39m❯\u00a0\u001b[38;2;255;170;0mfix the parser\u001b[0m'))
.toMatchObject({ idle: false, draft: true })
})
it('reads devin and pi panes, whose composers look nothing like the others', () => {
// Devin's marker is ❭ (U+276D), not claude's ❯ (U+276F) — reading it as claude's found no prompt at
// all, and a pane with no prompt is never idle, so every switch would have been refused as BUSY.
const devinPane = (composer: string) => [
composer,
'────────────────────────────',
'SWE-1.6 Slow See all keyboard shortcuts: /shortcuts',
].join('\n')
// Devin dims its placeholder the way claude does, so the same SGR rule separates it from a draft.
expect(inspectRuntimePane('devin', devinPane('\u001b[39m❭ \u001b[2mAsk Devin to build features\u001b[0m')))
.toMatchObject({ idle: true, draft: false })
expect(inspectRuntimePane('devin', devinPane('\u001b[39m❭ fix the parser')))
.toMatchObject({ idle: false, draft: true })
// Pi draws no marker: its composer is the band between the last two rules, and the footer only
// exists in the normal view.
const piIdle = [
'────────────────────────────',
'',
'────────────────────────────',
'/private/tmp/rp-probe/pi',
'0.0%/500k (auto) minimax/minimax-m3 • high',
].join('\n')
expect(inspectRuntimePane('pi', piIdle)).toMatchObject({ idle: true, draft: false, dialog: false })
expect(inspectRuntimePane('pi', piIdle.replace('\n\n', '\n/model something\n')))
.toMatchObject({ idle: false, draft: true })
expect(inspectRuntimePane('pi', [
'Thinking Level',
'Select reasoning depth for thinking-capable models',
'→ medium Moderate reasoning (~8k tokens)',
' Enter to select · Esc to go back',
].join('\n'))).toMatchObject({ idle: false, dialog: true })
// A model with no thinking ladder draws no `• <level>`, so the footer ends at the model name.
// EVERY grid model is that shape (`gridLaunch.ts` declares `reasoning: false`), and reading
// idleness through the strict profile parser left every Pi agent on a grid permanently
// AGENT_BUSY. Captured live from pi 0.82 on grid-3378218621364f16.
const piGridIdle = [
'───────────────────────────────────────────',
'',
'───────────────────────────────────────────',
'~/KloveY/sandbox (main)',
'↑5.4k ↓292 1.5%/200k (auto) Auto',
].join('\n')
expect(inspectRuntimePane('pi', piGridIdle))
.toMatchObject({ idle: true, draft: false, dialog: false })
// The band still decides what a draft is — the looser footer check must not make Pi look idle
// while somebody is mid-sentence.
expect(inspectRuntimePane('pi', piGridIdle.replace('\n\n', '\n/model something\n')))
.toMatchObject({ idle: false, draft: true })
// And a picker over that same footer is still a dialog, not idleness.
expect(inspectRuntimePane('pi', `Type to search\n${piGridIdle}`))
.toMatchObject({ idle: false, dialog: true })
})
it('ignores picker and Plan mode text left above the latest prompt', () => {
const capture = 'Select Model and Effort\nPlan mode\n› old\ncompleted\n› \ngpt-5.6-sol high ·'
expect(inspectRuntimePane('codex', capture)).toMatchObject({ idle: true, dialog: false, plan: false })
})
it('parses the version-gated Codex picker rows', () => {
const menu = parseCodexModelMenuRows([
'Select Model',
'Pick a quick auto mode or browse all models.',
' 1. codex-auto-review Balanced agentic coding model for everyday work.',
'› 2. All models (current) Choose a specific model and reasoning level',
].join('\n'))
expect(menu?.quickModels.get('codex-auto-review')).toBe('1')
expect(menu?.allModelsRow).toBe('2')
const models = parseCodexModelRows('Select Model and Effort\n 1. gpt-5.6-sol (default) Latest frontier model.\n 2. gpt-5.6-terra\n› 3. gpt-5.6-luna (current) Fast model.')
expect(models?.get('gpt-5.6-sol')).toBe('1')
expect(models?.get('gpt-5.6-terra')).toBe('2')
expect(models?.get('gpt-5.6-luna')).toBe('3')
const efforts = parseCodexEffortRows('Select Reasoning Level for gpt-5.6-sol\n 1. Low\n 2. High (default)\n 3. Extra high\n 4. More reasoning options')
expect(efforts?.efforts.get('xhigh')).toBe('3')
expect(efforts?.defaultRow).toBe('2')
expect(efforts?.advancedRow).toBe('4')
const advanced = parseCodexAdvancedRows('Advanced Reasoning\n› 1. Max (current) Higher usage\n 2. Ultra Highest usage')
expect(advanced?.get('max')).toBe('1')
expect(advanced?.get('ultra')).toBe('2')
})
it('treats both Codex model picker generations as active dialogs', () => {
expect(inspectRuntimePane(
'codex',
'Select Model\nPick a quick auto mode or browse all models.\n› 2. All models (current)',
)).toMatchObject({ idle: false, dialog: true })
expect(inspectRuntimePane(
'codex',
'Select Model and Effort\n› 1. gpt-5.6-sol (current)',
)).toMatchObject({ idle: false, dialog: true })
})
it('does not reuse picker rows left before a newer composer prompt', () => {
const stale = 'Select Model and Effort\n 1. gpt-old\n› 1. gpt-old\n› \ngpt-current high ·'
expect(parseCodexModelRows(stale)).toBeNull()
})
it('parses the gated Cursor picker and parameter rows by meaning', () => {
const picker = [
' Available models Max mode: OFF',
' Filter:',
' Auto',
' → GPT-5.6 Sol 272K Medium (Tab to modify)',
' Type to filter • Enter to select • Tab to edit',
].join('\n')
expect(parseCursorModelPicker(picker)).toEqual({ selectedFamily: 'GPT-5.6 Sol' })
const parameters = [
' GPT-5.6 Sol — Edit Parameters',
' Context',
' → ● 272K ✓',
' ○ 1M',
' Reasoning',
' ○ None',
' ● Medium ✓',
' ○ Extra High',
' ◯ Fast',
].join('\n')
expect(parseCursorParameterRows(parameters)).toEqual([
{ kind: 'context', value: '272k', selected: true, cursor: true, index: 0 },
{ kind: 'context', value: '1m', selected: false, cursor: false, index: 1 },
{ kind: 'reasoning', value: 'none', selected: false, cursor: false, index: 2 },
{ kind: 'reasoning', value: 'medium', selected: true, cursor: false, index: 3 },
{ kind: 'reasoning', value: 'xhigh', selected: false, cursor: false, index: 4 },
{ kind: 'fast', value: 'true', selected: false, cursor: false, index: 5 },
])
})
})
describe('RuntimeProfileController', () => {
it('sets Claude model and effort only after transcript confirmations', async () => {
const value = session('claude')
const manager = new RuntimeProfileManager()
manager.hydrate(value, [])
manager.ingestPane(value, 'Sonnet 5 with low effort\n❯ ', true)
value.cliVersion = null // simulate an old persisted registry entry after manager hydration
const commands: string[] = []
const release = vi.fn()
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime: async () => true,
capture: async () => 'Opus 4.8 with high effort\n❯ ',
sendText: async (_pane, command) => {
commands.push(command)
if (command.startsWith('/model ')) {
manager.ingest(value, JSON.stringify({ type: 'assistant', message: { content: [{ type: 'text', text: 'Set model to Opus 4.8' }] } }))
} else {
manager.ingest(value, JSON.stringify({ type: 'assistant', message: { content: [{ type: 'text', text: 'Set effort level to high' }] } }))
}
return true
},
sendLiteral: async () => true,
sendKey: async () => true,
acquireInput: () => release,
})
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'claude', model: 'opus', effort: 'high' })
await controller.setProfile('s1', target)
expect(commands).toEqual(['/model opus', '/effort high'])
expect(manager.selectedModel(value)).toBe(target)
expect(release).toHaveBeenCalledOnce()
})
it('does not reset unchanged auto effort after switching from Haiku to Sonnet', async () => {
const value = session('claude')
const manager = new RuntimeProfileManager()
manager.hydrate(value, [JSON.stringify({
type: 'user', message: { content: '<local-command-stdout>Set model to Haiku 4.5</local-command-stdout>' },
})])
expect(manager.selectedModel(value)).toBe(encodeRuntimeProfile({
sessionId: 'h1', engine: 'claude', model: 'haiku', effort: 'auto',
}))
const commands: string[] = []
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime: async () => true,
capture: async () => '\u001b[39m\u276f\u00a0\u001b[2mAsk about the codebase\u001b[0m',
sendText: async (_pane, command) => {
commands.push(command)
const output = command.startsWith('/model ')
? 'Set model to \u001b[1mSonnet 5\u001b[22m and saved as your default for new sessions'
: 'Effort level set to auto'
manager.ingest(value, JSON.stringify({
type: 'user', message: { content: `<local-command-stdout>${output}</local-command-stdout>` },
}))
return true
},
sendLiteral: async () => true,
sendKey: async () => true,
acquireInput: () => () => undefined,
})
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'claude', model: 'sonnet', effort: 'auto' })
await controller.setProfile('s1', target)
expect(commands).toEqual(['/model sonnet'])
expect(manager.selectedModel(value)).toBe(target)
})
it('sets Claude ultracode effort through its native command value', async () => {
const value = session('claude')
const manager = new RuntimeProfileManager()
manager.hydrate(value, [])
manager.ingestPane(value, 'Sonnet 5 with high effort\n❯ ', true)
const commands: string[] = []
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime: async () => true,
capture: async () => '\u001b[39m\u276f\u00a0\u001b[2mAsk about the codebase\u001b[0m',
sendText: async (_pane, command) => {
commands.push(command)
const output = command.startsWith('/model ')
? 'Set model to Sonnet 5 and saved as your default for new sessions'
: 'Set effort level to ultracode (this session only): xhigh + dynamic workflow orchestration'
manager.ingest(value, JSON.stringify({
type: 'user', message: { content: `<local-command-stdout>${output}</local-command-stdout>` },
}))
return true
},
sendLiteral: async () => true,
sendKey: async () => true,
acquireInput: () => () => undefined,
})
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'claude', model: 'sonnet', effort: 'ultracode' })
await controller.setProfile('s1', target)
expect(commands).toEqual(['/effort ultracode'])
expect(manager.selectedModel(value)).toBe(target)
})
it('does not touch tmux when the requested profile is already current', async () => {
const value = session('claude')
const manager = new RuntimeProfileManager()
manager.hydrate(value, [])
manager.ingestPane(value, 'Sonnet 5 with high effort\n❯ ', true)
const validateRuntime = vi.fn(async () => true)
const sendText = vi.fn(async () => true)
const acquireInput = vi.fn(() => () => undefined)
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime,
capture: async () => '\u001b[39m\u276f\u00a0\u001b[2mAsk about the codebase\u001b[0m',
sendText,
sendLiteral: async () => true,
sendKey: async () => true,
acquireInput,
})
const current = encodeRuntimeProfile({ sessionId: 'h1', engine: 'claude', model: 'sonnet', effort: 'high' })
await controller.setProfile('s1', current)
expect(validateRuntime).not.toHaveBeenCalled()
expect(acquireInput).not.toHaveBeenCalled()
expect(sendText).not.toHaveBeenCalled()
})
it('rejects remote Codex changes while the native session is in Plan mode', async () => {
const value = session('codex')
const manager = new RuntimeProfileManager()
manager.hydrate(value, [JSON.stringify({
type: 'turn_context', payload: { model: 'gpt-5.6-sol', reasoning_effort: 'high', collaboration_mode: { mode: 'plan' } },
})])
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'codex', model: 'gpt-5.6-sol', effort: 'low' })
vi.spyOn(manager, 'modelsForSession').mockResolvedValue([{ id: target, displayName: 'GPT-5.6-Sol / Low' }])
const controller = new RuntimeProfileController({
manager, getSession: () => value, validateRuntime: async () => true,
capture: async () => '› \ngpt-5.6-sol high ·', sendText: vi.fn(), sendLiteral: vi.fn(), sendKey: vi.fn(), acquireInput: vi.fn(),
})
await expect(controller.setProfile('s1', target)).rejects.toMatchObject({ code: 'PLAN_SCOPE_AMBIGUOUS' })
})
it('selects Codex Ultra through the Advanced Reasoning submenu', async () => {
const value = session('codex')
const manager = new RuntimeProfileManager()
manager.hydrate(value, [JSON.stringify({
type: 'turn_context', payload: { model: 'gpt-5.6-sol', reasoning_effort: 'high' },
})])
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'codex', model: 'gpt-5.6-sol', effort: 'ultra' })
vi.spyOn(manager, 'modelsForSession').mockResolvedValue([{ id: target, displayName: 'GPT-5.6-Sol / Ultra' }])
let phase: 'idle' | 'models' | 'efforts' | 'advanced' = 'idle'
const keys: string[] = []
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime: async () => true,
capture: async () => {
if (phase === 'models') return 'Select Model and Effort\n 1. gpt-5.6-sol (current)'
if (phase === 'efforts') return 'Select Reasoning Level for gpt-5.6-sol\n 5. More reasoning options'
if (phase === 'advanced') return 'Advanced Reasoning\n 1. Max\n 2. Ultra'
return '› \ngpt-5.6-sol high ·'
},
sendText: async () => { phase = 'models'; return true },
sendLiteral: async () => true,
sendKey: async (_pane, key) => {
keys.push(key)
if (phase === 'models' && key === '1') phase = 'efforts'
else if (phase === 'efforts' && key === '5') phase = 'advanced'
else if (phase === 'advanced' && key === '2') {
phase = 'idle'
manager.ingest(value, JSON.stringify({
type: 'turn_context', payload: { model: 'gpt-5.6-sol', reasoning_effort: 'ultra' },
}))
}
return true
},
acquireInput: () => () => undefined,
})
await controller.setProfile('s1', target)
expect(keys).toEqual(['1', '5', '2'])
expect(manager.selectedModel(value)).toBe(target)
})
it('selects an explicit Codex model through the 0.145 All models pre-menu', async () => {
const value = session('codex')
value.cliVersion = '0.145.0'
const manager = new RuntimeProfileManager()
manager.hydrate(value, [JSON.stringify({
type: 'turn_context', payload: { model: 'gpt-5.6-sol', reasoning_effort: 'high' },
})])
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'codex', model: 'gpt-5.6-terra', effort: 'low' })
vi.spyOn(manager, 'modelsForSession').mockResolvedValue([{ id: target, displayName: 'GPT-5.6-Terra / Low' }])
let phase: 'idle' | 'menu' | 'models' | 'efforts' = 'idle'
const keys: string[] = []
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime: async () => true,
capture: async () => {
if (phase === 'menu') {
return 'Select Model\nPick a quick auto mode or browse all models.\n 1. codex-auto-review\n› 2. All models (current)'
}
if (phase === 'models') {
return 'Select Model and Effort\n 1. gpt-5.6-sol (current)\n 2. gpt-5.6-terra'
}
if (phase === 'efforts') return 'Select Reasoning Level for gpt-5.6-terra\n 1. Low\n 2. High (default)'
return '› \ngpt-5.6-sol high ·'
},
sendText: async () => { phase = 'menu'; return true },
sendLiteral: async () => true,
sendKey: async (_pane, key) => {
keys.push(key)
if (phase === 'menu' && key === '2') phase = 'models'
else if (phase === 'models' && key === '2') phase = 'efforts'
else if (phase === 'efforts' && key === '1') {
phase = 'idle'
manager.ingest(value, JSON.stringify({
type: 'turn_context', payload: { model: 'gpt-5.6-terra', reasoning_effort: 'low' },
}))
}
return true
},
acquireInput: () => () => undefined,
})
await controller.setProfile('s1', target)
expect(keys).toEqual(['2', '2', '1'])
expect(manager.selectedModel(value)).toBe(target)
})
it('selects a Codex quick profile directly from the 0.145 pre-menu', async () => {
const value = session('codex')
value.cliVersion = '0.145.0'
const manager = new RuntimeProfileManager()
manager.hydrate(value, [JSON.stringify({
type: 'turn_context', payload: { model: 'gpt-5.6-sol', reasoning_effort: 'high' },
})])
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'codex', model: 'codex-auto-review', effort: 'high' })
vi.spyOn(manager, 'modelsForSession').mockResolvedValue([{ id: target, displayName: 'GPT-5.6-Terra / High' }])
let phase: 'idle' | 'menu' | 'efforts' = 'idle'
const keys: string[] = []
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime: async () => true,
capture: async () => {
if (phase === 'menu') {
return 'Select Model\nPick a quick auto mode or browse all models.\n 1. codex-auto-review\n› 2. All models (current)'
}
if (phase === 'efforts') {
return 'Select Reasoning Level for codex-auto-review\n 1. Low\n 2. Medium (default)\n 3. High'
}
return '› \ngpt-5.6-sol high ·'
},
sendText: async () => { phase = 'menu'; return true },
sendLiteral: async () => true,
sendKey: async (_pane, key) => {
keys.push(key)
if (phase === 'menu' && key === '1') phase = 'efforts'
else if (phase === 'efforts' && key === '3') {
phase = 'idle'
manager.ingest(value, JSON.stringify({
type: 'turn_context', payload: { model: 'codex-auto-review', reasoning_effort: 'high' },
}))
}
return true
},
acquireInput: () => () => undefined,
})
await controller.setProfile('s1', target)
expect(keys).toEqual(['1', '3'])
expect(manager.selectedModel(value)).toBe(target)
})
it('refuses to drive an engine the owner made view-only', async () => {
// Switching is Claude and Codex only (owner, 2026-07-31). This replaces two tests that drove Cursor's
// picker end to end: setCursor and the other per-engine drivers are still in the code, deliberately —
// this policy has already flipped twice — but nothing can reach them while the gate is shut, so what
// is worth asserting now is the refusal, and that it costs the user's pane nothing.
const value = session('cursor')
const manager = new RuntimeProfileManager()
manager.hydrate(value, [])
const target = encodeRuntimeProfile({ sessionId: 'h1', engine: 'cursor', model: 'claude-4.5-sonnet', effort: 'auto' })
vi.spyOn(manager, 'modelsForSession').mockResolvedValue([{ id: target, displayName: 'Sonnet 4.5 / Auto' }])
const sendKey = vi.fn().mockResolvedValue(true)
const sendText = vi.fn().mockResolvedValue(true)
const controller = new RuntimeProfileController({
manager,
getSession: () => value,
validateRuntime: async () => true,
capture: async () => '→ Add a follow-up',
sendText,
sendKey,
sendLiteral: vi.fn().mockResolvedValue(true),
acquireInput: () => () => undefined,
})
await expect(controller.setProfile('s1', target)).rejects.toMatchObject({ code: 'UNSUPPORTED_CLI_VERSION' })
expect(sendKey).not.toHaveBeenCalled()
expect(sendText).not.toHaveBeenCalled()
})
})