Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/plans/2026-11-28-codex-terminal-root-prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Deliver to an empty native Codex pane at narrow widths

## Reproduction and source

The same installed 0.172.0 PTY at 40 columns refuses delivery before writing.
An empty 120-column pane accepts one transport write. Both refuse a typed draft.
The app uses the same provider delivery code for both display modes. Terminal
view fits the PTY to the tile. In the verified narrow footer the CLI retains
its agents shortcut and omits its shortcuts label.

## Changes and checks

1. Protect the observed empty and drafted footer shapes at the parser boundary.
2. Update the pinned parser with only the verified dedicated-footer rule.
3. Exercise normal provider delivery with a disposable native CLI and local-only
model endpoint. Check writes, readback and draft preservation.
4. Keep caller, transport, modal and settled-frame guards intact.

## Verified mechanism

On the same local fixture, 20–56 columns showed the agents-only hint and
64, 80 and 120 columns showed both hints. At 40 columns the baseline returned
occupied with zero writes, while the wide empty control accepted one write.
A typed draft, including the exact placeholder text, remained unsent.
The verified provider change is codex-headless commit db20263. It uses
the CLI's empty-only agents-navigation contract and does not match status-line paths.

Independent review identified a second layout at 20–32 columns: the model and
path occupy two physical rows. Both recorded shapes initially failed. The
parser now validates both status fragments together and checks only the final
footer row for the shortcut. All 26 classifier tests pass.
92 changes: 92 additions & 0 deletions testing/live/codex-root-prompt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { mkdir, mkdtemp, readFile, readdir, realpath, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { expect, it, vi } from 'vitest'

// Both views send Root Management prompts through the same SessionManager
// entry. The fitted Terminal view can give Codex 40 columns, whereas the
// headless Agent view usually gives it enough space for the full shortcut hint.
// Vitest runs in Node. SessionManager also resolves its bundled helpers at
// spawn, which requires Electron's app path even for a Codex-only fixture.
vi.mock('electron', () => ({ app: { getAppPath: () => process.cwd(), getPath: () => process.env.HOME } }))

const live = it.skipIf(process.env.CODEX_ROOT_PROMPT_LIVE !== '1')

live.each([24, 40, 120])('delivers into an empty %i-column native Codex pane and preserves a real draft', async cols => {
const home = await realpath(await mkdtemp(join(tmpdir(), 'codex-root-prompt-')))
const config = join(home, '.codex')
const cwd = join(home, 'workspace')
const prompt = 'Root prompt local fixture'
let manager: import('@main/sessionManager').SessionManager | undefined
try {
vi.stubEnv('HOME', home)
vi.stubEnv('CODEX_HOME', config)
vi.stubEnv('CODEX_ROOT_PROMPT_FIXTURE_KEY', 'local-fixture')
await Promise.all([mkdir(cwd), mkdir(config)])
await writeFile(join(config, 'config.toml'), [
'model = "gpt-6-sol"', 'model_provider = "local_fixture"',
'[model_providers.local_fixture]', 'name = "Local fixture"', 'base_url = "http://127.0.0.1:9/v1"',
'wire_api = "responses"', 'env_key = "CODEX_ROOT_PROMPT_FIXTURE_KEY"',
`[projects.${JSON.stringify(cwd)}]`, 'trust_level = "trusted"',
].join('\n'))
const { SessionManager } = await import('@main/sessionManager')
manager = new SessionManager()
const host = manager
function replyToTerminalQueries(sessionId: string, data: string) {
if (data.includes('\x1b[6n')) host.write(sessionId, '\x1b[1;1R')
if (data.includes('\x1b[c')) host.write(sessionId, '\x1b[?1;2c')
}
host.on('agent-pty-data', ({ sessionId, data }) => replyToTerminalQueries(sessionId, data))
for (const hasDraft of [true, false]) {
const { sessionId } = await host.spawn({ kind: 'codex', cwd, cols, rows: 44, useProxy: false })
replyToTerminalQueries(sessionId, host.attachAgentPty(sessionId) ?? '')
const screen = () => host.getScreenSnapshot(sessionId)?.plain ?? ''
await vi.waitFor(() => expect(screen()).toMatch(/^ ← for agents\b/m), { timeout: 15_000 })
const placeholder = /^› (.+)$/m.exec(screen())?.[1]?.trim()
if (!placeholder) throw new Error('Expected the native Codex placeholder at the editor cursor')
if (hasDraft) {
// The same words can be either a dim suggestion or human-entered text.
// Wait for Codex's hint to leave so the subsequent receipt is decisive.
host.write(sessionId, placeholder)
await vi.waitFor(() => {
expect(screen()).toContain(`› ${placeholder}`)
expect(screen()).not.toMatch(/^ ← for agents\b/m)
})
}

const result = await host.deliverPromptToAgent(sessionId, prompt)
if (hasDraft) {
expect(result).toMatchObject({
ok: false, stage: 'before-write', code: 'not-ready', disposition: 'retry-after-resolve',
promptWritten: false, enterWritten: false,
})
expect(screen()).toContain(`› ${placeholder}`)
expect(screen()).not.toContain(prompt)
} else {
expect(result, JSON.stringify({ result, footer: screen().split('\n').filter(Boolean).slice(-4) })).toMatchObject({ ok: true, acceptance: { kind: 'transport' } })
// A transport receipt alone cannot establish that Codex committed the
// text. Its local rollout does, independent of the fixture's closed
// endpoint and independent of Agent Code's transcript attachment.
const sessionsDir = join(config, 'sessions')
await vi.waitFor(async () => {
const names = await readdir(sessionsDir, { recursive: true })
const records = await Promise.all(names.filter(name => name.endsWith('.jsonl'))
.map(name => readFile(join(sessionsDir, name), 'utf8')))
expect(records.some(data => data.split('\n').some(line => {
if (!line.includes(prompt)) return false
try {
const row = JSON.parse(line)
return row.type === 'response_item' && row.payload?.role === 'user' &&
row.payload.content?.some((block: { text?: string }) => block.text === prompt)
} catch { return false }
}))).toBe(true)
}, { timeout: 8_000 })
}
await host.kill(sessionId)
}
} finally {
await manager?.killAll()
vi.unstubAllEnvs()
await rm(home, { recursive: true, force: true })
}
}, 55_000)
Loading