From 489cfc51488fd64094642cc4a35b7896c9dacc0b Mon Sep 17 00:00:00 2001 From: devswha Date: Fri, 27 Nov 2026 03:49:51 +0900 Subject: [PATCH 1/3] fix(chat): recheck Codex question notes before submitting Fixes #4144 (the Codex typed-answer item). --- changelog.d/codex-question-typed-recheck.md | 3 +++ server/codex-question.test.ts | 30 ++++++++++++++++++--- server/dialogs/codex.ts | 27 ++++++++++++++++--- server/prompt.ts | 7 ++++- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 changelog.d/codex-question-typed-recheck.md diff --git a/changelog.d/codex-question-typed-recheck.md b/changelog.d/codex-question-typed-recheck.md new file mode 100644 index 0000000000..0bcb47c314 --- /dev/null +++ b/changelog.d/codex-question-typed-recheck.md @@ -0,0 +1,3 @@ +### Fixed +- Codex question cards no longer send Enter to the chat prompt if the question closes while + the answer is being pasted. diff --git a/server/codex-question.test.ts b/server/codex-question.test.ts index 7eb7b8e4b5..8402332226 100644 --- a/server/codex-question.test.ts +++ b/server/codex-question.test.ts @@ -29,9 +29,10 @@ function root(): string { } /** herdr with one Codex pane showing `SCREEN`: the keys sent to it are kept. */ -async function herdr(): Promise<{ sent: string[] }> { +async function herdr(onInput: (input: string, screen: string) => string = (_, screen) => screen): Promise<{ sent: string[] }> { const path = join(root(), "herdr.sock"); const pane = { sent: [] as string[] }; + let screen = SCREEN; const sockets = new Set(); const server = createServer((socket) => { sockets.add(socket); @@ -44,12 +45,15 @@ async function herdr(): Promise<{ sent: string[] }> { const request = JSON.parse(input.split("\n")[0]!) as { id: string; method: string; params: { keys?: string[]; text?: string } }; const answer = (result: unknown) => socket.end(`${JSON.stringify({ id: request.id, result })}\n`); if (request.method === "session.snapshot") return answer({ snapshot: { panes: [{ pane_id: "p_1", agent: "codex", agent_status: "blocked" }], layouts: [] } }); - if (request.method === "pane.read") return answer({ read: { text: SCREEN } }); + if (request.method === "pane.read") return answer({ read: { text: screen } }); if (request.method === "pane.process_info") return answer({ process_info: { foreground_processes: [] } }); if (request.method === "pane.get") return answer({ pane: { pane_id: "p_1" } }); if (request.method === "agent.get") return answer({ agent: {} }); if (request.method === "pane.send_keys" || request.method === "pane.send_text") { - pane.sent.push(...(request.params.keys ?? [`text:${request.params.text}`])); + for (const key of request.params.keys ?? [`text:${request.params.text}`]) { + pane.sent.push(key); + screen = onInput(key, screen); + } return answer({}); } socket.end(`${JSON.stringify({ id: request.id, error: { code: "not_found", message: request.method } })}\n`); @@ -184,3 +188,23 @@ test("leaves a note and several picks to the TUI", () => { expect(servedAnswers(ask, { pane_id: "p", prompt_id: "x", option_index: 1 })).toBeNull(); expect(servedAnswers(ask, { pane_id: "p", prompt_id: "x", option_indices: [0] })).toBeNull(); }); + +test.each([ + ["the notes editor stays open", (screen: string) => screen, 200], + ["the question closes during the paste", () => "› An unsent composer draft\n", 409], + ["another question takes its place", (screen: string) => screen.replace(" Which color do you choose?", " Which color should we avoid?"), 409], +] as const)("rechecks before sending Enter when %s", async (_, redraw, status) => { + const pane = await herdr((key, screen) => { + if (key === "down") return screen.replace(/^ › (\d\..*\n) (?=\d\.)/mu, " $1 › "); + if (key === "tab") return screen.replace( + " tab to add notes | enter to submit answer | esc to interrupt", + " › Add notes\n\n tab or esc to clear notes | enter to submit answer", + ); + if (key === "text:green") return redraw(screen.replace(" › Add notes", " › green")); + return screen; + }); + const prompt = await card(); + const result = await answer(prompt.id, { custom_text: "green" }); + const edit = ["down", "down", "tab", "text:green"]; + expect([result, pane.sent]).toEqual([status, status === 200 ? [...edit, "enter"] : edit]); +}); diff --git a/server/dialogs/codex.ts b/server/dialogs/codex.ts index 2ca7b81c0e..8627c8a43c 100644 --- a/server/dialogs/codex.ts +++ b/server/dialogs/codex.ts @@ -54,9 +54,9 @@ function parseCodexContinueMenu(screen: string): ParsedPrompt | null { }); } -function parseCodexQuestion(screen: string): ParsedPrompt | null { +function parseCodexQuestion(screen: string, notes = false): ParsedPrompt | null { const lines = screen.replace(ANSI_RE, "").split(/\r?\n/); - const hintIndex = findLastIndex(lines, (_, index) => CODEX_ASK_HINT_RE.test(wrapped(lines, index))); + const hintIndex = notes ? codexNotesStart(lines) : findLastIndex(lines, (_, index) => CODEX_ASK_HINT_RE.test(wrapped(lines, index))); if (hintIndex < 0) return null; const rows = menuRows(lines, Math.max(0, hintIndex - 48), hintIndex); if (!sequentialRows(rows) || rows.filter((row) => row.selected).length !== 1) return null; @@ -74,7 +74,7 @@ function parseCodexQuestion(screen: string): ParsedPrompt | null { // several questions, and the hint says ←/→ move between them without answering: the card's Back and Next const at = progress ? Number(progress[1]) - 1 : 0; const total = progress ? Number(progress[2]) : 1; - const navigates = total > 1 && at < total && CODEX_NAVIGATE_RE.test(wrapped(lines, hintIndex)); + const navigates = !notes && total > 1 && at < total && CODEX_NAVIGATE_RE.test(wrapped(lines, hintIndex)); return finishPrompt("codex", { kind: "question", title, question, body: null, options, multi_select: false, custom_option_index: options.length, @@ -87,6 +87,27 @@ function parseCodexQuestion(screen: string): ParsedPrompt | null { }, { can_step_back: undefined, can_step_next: undefined }); } +// Codex replaces the options footer when Tab opens notes. The menu above the notes +// composer still identifies the question, but the composer itself isn't an option row. +function codexNotesStart(lines: string[]): number { + const end = findLastIndex(lines, (line) => line.trim() !== ""); + for (let start = end; start >= Math.max(0, end - 2); start -= 1) { + const hint = lines.slice(start, end + 1).map(cleanLine).join(" "); + if (!/^tab or esc to clear notes\s*\|\s*enter to submit (?:answer|all)$/i.test(hint)) continue; + const beforeHint = lines.slice(0, start); + const notesRow = findLastIndex(beforeHint, (line) => /^\s*›(?: |$)/u.test(line)); + if (notesRow < 0) return -1; + const selected = findLastIndex(beforeHint.slice(0, notesRow), (line) => /^\s*›(?: |$)/u.test(line)); + return /^\s*› +\d+\. +None of the above\b/i.test(lines[selected] ?? "") ? notesRow : -1; + } + return -1; +} + +export function parseCodexNotes(screen: string): ParsedPrompt | null { + const parsed = parseCodexQuestion(screen, true); + return parsed !== null && parsed.selectedIndex === parsed.customMenuIndex ? parsed : null; +} + /** * A question from Codex's queue, open: under the queue header, an optional "1 of 2", the * question (wrapped over as many lines as the pane needs), then its options and a last diff --git a/server/prompt.ts b/server/prompt.ts index 9c3d945122..43137602a3 100644 --- a/server/prompt.ts +++ b/server/prompt.ts @@ -29,6 +29,7 @@ import { executeInteractionPlan } from "./dialogs/interaction-plan.ts"; import { liveScreen, parsePrompt, promptTailIsActive } from "./dialogs/live.ts"; import { LETTA_SEARCH_MAX, lettaPick, lettaSearchShown } from "./dialogs/letta.ts"; import { agyCustomEditorMatches, agySameQuestion, parseAgyQuestion } from "./dialogs/agy.ts"; +import { parseCodexNotes } from "./dialogs/codex.ts"; import { dshFreeTextRow, dshTypedText } from "./dialogs/dsh.ts"; import { sameText } from "./dialogs/omo.ts"; import { OMP_REVIEW_HINT_RE, OMP_TABS_HINT_RE, ompCustomEditorMatches } from "./dialogs/omp.ts"; @@ -2218,7 +2219,7 @@ export async function handlePromptRequest(request: Request, url: URL, options: P const interaction = body.custom_text === undefined ? reader?.interaction?.(parsed) : undefined; const checkBeforeText = responder === "fallback-gjc-menu" || responder === "pi-ask-question" || responder === "pi-questionnaire-question" || responder === "agy-question"; - const editorAnswer = body.custom_text !== undefined && (checkBeforeText || responder === "dsh-question" + const editorAnswer = body.custom_text !== undefined && (checkBeforeText || responder === "dsh-question" || responder === "codex-question" || responder === "claude-question" || responder === "omp-question" || responder === "omo-question" || responder === "omo-review" || responder === "hermes-question" || responder === "hermes-input" || responder === "opencode-v1-question") ? { prompt: parsed, text: body.custom_text.trim() } : undefined; @@ -2347,6 +2348,10 @@ export async function handlePromptRequest(request: Request, url: URL, options: P if (typedEditor) { if (!asks() || request.signal.aborted) return false; if (checkBeforeText) return inlineEditorMatches(shown, screen, typedEditor.text); + if (responder === "codex-question") { + const notes = parseCodexNotes(screen); + return notes !== null && withServedAsk(body.pane_id, notes).id === parsed.id; + } if (responder === "dsh-question") return dshFreeTextRow(screen, parsed, dshTypedText(typedEditor.text)) === "typed"; if (responder === "omp-question") return ompCustomEditorMatches(screen, typedEditor); if (responder === "opencode-v1-question") return openCodeV1CustomEditorMatches(screen, typedEditor); From 0576e3b6390985f417b430b8cc79b8fcec92df3e Mon Sep 17 00:00:00 2001 From: devswha Date: Fri, 27 Nov 2026 04:02:36 +0900 Subject: [PATCH 2/3] fix(chat): verify Codex typed answers before sending Refs #4144. --- changelog.d/codex-question-typed-recheck.md | 5 +- server/codex-question.test.ts | 44 +++++++++++-- server/dialogs/codex.ts | 71 +++++++++++++++------ server/prompt.ts | 20 +++--- 4 files changed, 106 insertions(+), 34 deletions(-) diff --git a/changelog.d/codex-question-typed-recheck.md b/changelog.d/codex-question-typed-recheck.md index 0bcb47c314..bbc37c4719 100644 --- a/changelog.d/codex-question-typed-recheck.md +++ b/changelog.d/codex-question-typed-recheck.md @@ -1,3 +1,4 @@ ### Fixed -- Codex question cards no longer send Enter to the chat prompt if the question closes while - the answer is being pasted. +- Codex question cards check that the question is still open before pasting into its notes + editor. They no longer press Enter if a regular or queued question closes or the visible + answer changes before submission. diff --git a/server/codex-question.test.ts b/server/codex-question.test.ts index 8402332226..2b0bb3272d 100644 --- a/server/codex-question.test.ts +++ b/server/codex-question.test.ts @@ -1,4 +1,4 @@ -import { afterEach, expect, test } from "bun:test"; +import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, readFileSync, realpathSync, rmSync } from "node:fs"; import { createServer, type Socket } from "node:net"; import { tmpdir } from "node:os"; @@ -29,10 +29,10 @@ function root(): string { } /** herdr with one Codex pane showing `SCREEN`: the keys sent to it are kept. */ -async function herdr(onInput: (input: string, screen: string) => string = (_, screen) => screen): Promise<{ sent: string[] }> { +async function herdr(onInput: (input: string, screen: string) => string = (_, screen) => screen, initial = SCREEN): Promise<{ sent: string[] }> { const path = join(root(), "herdr.sock"); const pane = { sent: [] as string[] }; - let screen = SCREEN; + let screen = initial; const sockets = new Set(); const server = createServer((socket) => { sockets.add(socket); @@ -189,9 +189,13 @@ test("leaves a note and several picks to the TUI", () => { expect(servedAnswers(ask, { pane_id: "p", prompt_id: "x", option_indices: [0] })).toBeNull(); }); +const COMPOSER = "› An unsent composer draft\n"; + test.each([ ["the notes editor stays open", (screen: string) => screen, 200], - ["the question closes during the paste", () => "› An unsent composer draft\n", 409], + ["the notes footer wraps to two rows", (screen: string) => screen.replace(" | enter to submit answer", "\n enter to submit answer"), 200], + ["the visible note changes before Enter", (screen: string) => screen.replace("› green", "› blue"), 409], + ["the question closes during the paste", () => COMPOSER, 409], ["another question takes its place", (screen: string) => screen.replace(" Which color do you choose?", " Which color should we avoid?"), 409], ] as const)("rechecks before sending Enter when %s", async (_, redraw, status) => { const pane = await herdr((key, screen) => { @@ -208,3 +212,35 @@ test.each([ const edit = ["down", "down", "tab", "text:green"]; expect([result, pane.sent]).toEqual([status, status === 200 ? [...edit, "enter"] : edit]); }); + +test("does not paste into Codex's composer when the question closes after Tab", async () => { + const pane = await herdr((key, screen) => { + if (key === "down") return screen.replace(/^ › (\d\..*\n) (?=\d\.)/mu, " $1 › "); + return key === "tab" ? COMPOSER : screen; + }); + const result = await answer((await card()).id, { custom_text: "green" }); + expect([result, pane.sent]).toEqual([409, ["down", "down", "tab"]]); +}); + +describe.each([ + ["free-form", " Type your answer", " green"], + ["choice with Other", " 1. red\n 2. blue\n › 3. Other", " 1. red\n 2. blue\n › 3. green"], +] as const)("%s queued question", (_, initial, typed) => { + test.each([ + ["still open", (row: string) => row, 200], + ["closed during paste", () => null, 409], + ["answer changed", (row: string) => row.replace("green", "blue"), 409], + ["leading space was added", (row: string) => row.replace("green", " green"), 409], + ] as const)("checks the input before Enter when %s", async (_, redraw, status) => { + const queue = (row: string) => `• Queued follow-up inputs\n Which color?\n${row}\n enter submit ctrl+] skip alt+↓ main prompt\n`; + const pane = await herdr((key, screen) => { + if (key === "text:green") { + const shown = redraw(typed); + return shown === null ? COMPOSER : queue(shown); + } + return key === "enter" ? COMPOSER : screen; + }, queue(initial)); + const result = await answer((await card()).id, { custom_text: "green" }); + expect([result, pane.sent]).toEqual([status, ["text:green", ...(status === 200 ? ["enter"] : [])]]); + }); +}); diff --git a/server/dialogs/codex.ts b/server/dialogs/codex.ts index 8627c8a43c..363cc45240 100644 --- a/server/dialogs/codex.ts +++ b/server/dialogs/codex.ts @@ -54,9 +54,13 @@ function parseCodexContinueMenu(screen: string): ParsedPrompt | null { }); } -function parseCodexQuestion(screen: string, notes = false): ParsedPrompt | null { +function parseCodexQuestion(screen: string): ParsedPrompt | null { const lines = screen.replace(ANSI_RE, "").split(/\r?\n/); - const hintIndex = notes ? codexNotesStart(lines) : findLastIndex(lines, (_, index) => CODEX_ASK_HINT_RE.test(wrapped(lines, index))); + const hintIndex = findLastIndex(lines, (_, index) => CODEX_ASK_HINT_RE.test(wrapped(lines, index))); + return readCodexQuestion(lines, hintIndex, CODEX_NAVIGATE_RE.test(wrapped(lines, hintIndex))); +} + +function readCodexQuestion(lines: string[], hintIndex: number, canNavigate: boolean): ParsedPrompt | null { if (hintIndex < 0) return null; const rows = menuRows(lines, Math.max(0, hintIndex - 48), hintIndex); if (!sequentialRows(rows) || rows.filter((row) => row.selected).length !== 1) return null; @@ -74,7 +78,7 @@ function parseCodexQuestion(screen: string, notes = false): ParsedPrompt | null // several questions, and the hint says ←/→ move between them without answering: the card's Back and Next const at = progress ? Number(progress[1]) - 1 : 0; const total = progress ? Number(progress[2]) : 1; - const navigates = !notes && total > 1 && at < total && CODEX_NAVIGATE_RE.test(wrapped(lines, hintIndex)); + const navigates = canNavigate && total > 1 && at < total; return finishPrompt("codex", { kind: "question", title, question, body: null, options, multi_select: false, custom_option_index: options.length, @@ -89,23 +93,32 @@ function parseCodexQuestion(screen: string, notes = false): ParsedPrompt | null // Codex replaces the options footer when Tab opens notes. The menu above the notes // composer still identifies the question, but the composer itself isn't an option row. -function codexNotesStart(lines: string[]): number { +export function parseCodexNotes(screen: string, answer?: string): ParsedPrompt | null { + const lines = screen.replace(ANSI_RE, "").split(/\r?\n/); const end = findLastIndex(lines, (line) => line.trim() !== ""); - for (let start = end; start >= Math.max(0, end - 2); start -= 1) { - const hint = lines.slice(start, end + 1).map(cleanLine).join(" "); - if (!/^tab or esc to clear notes\s*\|\s*enter to submit (?:answer|all)$/i.test(hint)) continue; - const beforeHint = lines.slice(0, start); - const notesRow = findLastIndex(beforeHint, (line) => /^\s*›(?: |$)/u.test(line)); - if (notesRow < 0) return -1; - const selected = findLastIndex(beforeHint.slice(0, notesRow), (line) => /^\s*›(?: |$)/u.test(line)); - return /^\s*› +\d+\. +None of the above\b/i.test(lines[selected] ?? "") ? notesRow : -1; + const last = cleanLine(lines[end] ?? ""); + const before = cleanLine(lines[end - 1] ?? ""); + const submit = /^enter to submit (?:answer|all)$/i; + const footer = /^tab or esc to clear notes\s*\|\s*enter to submit (?:answer|all)$/i.test(last) ? end + : before.toLowerCase() === "tab or esc to clear notes" && submit.test(last) ? end - 1 : -1; + if (footer < 0) return null; + const notesRow = findLastIndex(lines.slice(0, footer), (line) => /^\s*›(?: |$)/u.test(line)); + if (notesRow < 0) return null; + const parsed = readCodexQuestion(lines, notesRow, false); + if (parsed === null || parsed.selectedIndex !== parsed.customMenuIndex) return null; + if (answer !== undefined) { + const prefix = /^([ \t]*)› /u.exec(lines[notesRow] ?? ""); + if (!prefix) return null; + const indent = " ".repeat(prefix[0].length); + const rest = lines.slice(notesRow + 1, footer); + while (rest.length > 0 && rest.at(-1)?.trimEnd() === "") rest.pop(); + if (!rest.every((line) => line.trimEnd() === "" || line.startsWith(indent))) return null; + // Don't guess whether a line break is a soft wrap or was typed. + const visible = [lines[notesRow]?.slice(prefix[0].length) ?? "", ...rest.map((line) => line.slice(indent.length))] + .map((line) => line.trimEnd()).join("\n"); + if (visible === "Add notes" || visible !== answer) return null; } - return -1; -} - -export function parseCodexNotes(screen: string): ParsedPrompt | null { - const parsed = parseCodexQuestion(screen, true); - return parsed !== null && parsed.selectedIndex === parsed.customMenuIndex ? parsed : null; + return parsed; } /** @@ -114,10 +127,13 @@ export function parseCodexNotes(screen: string): ParsedPrompt | null { * row that takes a typed answer ("Other", or what was typed there). A free-form question * has no options, only that answer line ("Type your answer"). */ -function parseCodexAsyncQuestion(screen: string): ParsedPrompt | null { +function parseCodexAsyncQuestion(screen: string, answer?: string): ParsedPrompt | null { const lines = screen.replace(ANSI_RE, "").split(/\r?\n/); - const hintIndex = findLastIndex(lines, (_, index) => CODEX_ASYNC_ASK_HINT_RE.test(wrapped(lines, index))); + const hintIndex = findLastIndex(lines, (line, index) => CODEX_ASYNC_ASK_HINT_RE.test(wrapped(lines, index)) + && (answer === undefined || /^(?:enter|return)\s+submit\b/i.test(cleanLine(line)))); if (hintIndex < 0) return null; + if (answer !== undefined && lines.slice(hintIndex + 1).map(cleanLine).some((line) => line !== "" + && !/^(?:\S+ (?:skip|main prompt|prev question|next question|queued messages)|option \d+\/\d+)(?:\s|$)/i.test(line))) return null; const header = findLastIndex(lines.slice(Math.max(0, hintIndex - 48), hintIndex), (line) => CODEX_QUEUE_HEADER_RE.test(cleanLine(line))); const top = header < 0 ? Math.max(0, hintIndex - 48) : Math.max(0, hintIndex - 48) + header + 1; const rows = menuRows(lines, top, hintIndex); @@ -137,12 +153,23 @@ function parseCodexAsyncQuestion(screen: string): ParsedPrompt | null { if (header < 0) return null; const answerLine = findLastIndex(lines.slice(0, hintIndex), (line) => Boolean(cleanLine(line)) && !isDivider(line)); if (answerLine < top) return null; + if (answer !== undefined) { + // The free-form input and the question start in the same column. Remove + // that inset, not spaces a person may have typed into the field. + const firstQuestionRow = lines.slice(top, answerLine).find((line) => line.trim() !== ""); + const inset = firstQuestionRow?.match(/^[ \t]*/u)?.[0]; + if (inset === undefined || answer === "Type your answer" || lines[answerLine]?.trimEnd() !== inset + answer) return null; + } question = normalizeText(questionLines(answerLine).join(" ")) || null; options = []; menuLabels = []; selectedIndex = 0; } else { if (!sequentialRows(rows) || rows.length < 2 || rows.filter((row) => row.selected).length !== 1) return null; + const lastRow = rows.at(-1)!; + if (answer !== undefined && (!lastRow.selected || answer === "Other" || answer === "Other (write an answer)" + || lines[lastRow.lineIndex]?.trimEnd().replace(/^\s*› *\d+\. /u, "") !== answer + || text(lastRow.lineIndex + 1, hintIndex).length !== 0)) return null; // an old layout without the header must still end in its "Other" row if (header < 0 && !/^Other\b/i.test(rows.at(-1)!.label)) return null; // a wrapped option continues on the lines under it: these rows carry no descriptions @@ -164,6 +191,10 @@ function parseCodexAsyncQuestion(screen: string): ParsedPrompt | null { }); } +export function codexAsyncAnswerMatches(screen: string, expected: ParsedPrompt, answer: string): boolean { + return parseCodexAsyncQuestion(screen, answer)?.id === expected.id; +} + /** The dialogs of an approval Codex asks a client on its app server (server/approvals/codex.ts holds them), by kind. */ const CODEX_REQUEST_DIALOGS: readonly [RegExp, string][] = [ [/^Would you like to run the following command\b/, "command"], diff --git a/server/prompt.ts b/server/prompt.ts index 43137602a3..4ac7a84818 100644 --- a/server/prompt.ts +++ b/server/prompt.ts @@ -29,7 +29,7 @@ import { executeInteractionPlan } from "./dialogs/interaction-plan.ts"; import { liveScreen, parsePrompt, promptTailIsActive } from "./dialogs/live.ts"; import { LETTA_SEARCH_MAX, lettaPick, lettaSearchShown } from "./dialogs/letta.ts"; import { agyCustomEditorMatches, agySameQuestion, parseAgyQuestion } from "./dialogs/agy.ts"; -import { parseCodexNotes } from "./dialogs/codex.ts"; +import { codexAsyncAnswerMatches, parseCodexNotes } from "./dialogs/codex.ts"; import { dshFreeTextRow, dshTypedText } from "./dialogs/dsh.ts"; import { sameText } from "./dialogs/omo.ts"; import { OMP_REVIEW_HINT_RE, OMP_TABS_HINT_RE, ompCustomEditorMatches } from "./dialogs/omp.ts"; @@ -2219,7 +2219,8 @@ export async function handlePromptRequest(request: Request, url: URL, options: P const interaction = body.custom_text === undefined ? reader?.interaction?.(parsed) : undefined; const checkBeforeText = responder === "fallback-gjc-menu" || responder === "pi-ask-question" || responder === "pi-questionnaire-question" || responder === "agy-question"; - const editorAnswer = body.custom_text !== undefined && (checkBeforeText || responder === "dsh-question" || responder === "codex-question" + const codexTyped = responder === "codex-question" || responder === "codex-async-question"; + const editorAnswer = body.custom_text !== undefined && (checkBeforeText || responder === "dsh-question" || codexTyped || responder === "claude-question" || responder === "omp-question" || responder === "omo-question" || responder === "omo-review" || responder === "hermes-question" || responder === "hermes-input" || responder === "opencode-v1-question") ? { prompt: parsed, text: body.custom_text.trim() } : undefined; @@ -2336,11 +2337,17 @@ export async function handlePromptRequest(request: Request, url: URL, options: P const lettaTyping = committed && responder === "letta-model" && body.custom_text !== undefined; const claudeDown = responder === "claude-question" && parsed.multi_select && step.keys?.[0] === KEY.down; const gjcEditorPaste = committed && !customTyped && responder === "fallback-gjc-menu" && step.text !== undefined && parsed.gjcCall !== undefined; + const codexNotesPaste = committed && responder === "codex-question" && step.text !== undefined; const typedEditor = customTyped && step.keys?.length === 1 && (step.keys[0] === KEY.enter || claudeDown) ? editorAnswer : undefined; - if (!committed || togglesInPlace() || lettaTyping || typedEditor || gjcEditorPaste) { + if (!committed || togglesInPlace() || lettaTyping || typedEditor || gjcEditorPaste || codexNotesPaste) { const onCursor = !move && (step.keys?.every((key) => key === KEY.enter || key === KEY.space) ?? false); const { written } = await verifyThenSend(look, guardUntil, Date.now() + SETTLE_MS, (shown, screen, settled) => { + if (responder === "codex-question" && (codexNotesPaste || typedEditor)) { + if (!asks() || request.signal.aborted) return false; + const notes = parseCodexNotes(screen, typedEditor?.text); + return notes !== null && withServedAsk(body.pane_id, notes).id === parsed.id; + } if (gjcEditorPaste) { if (!asks() || request.signal.aborted) return false; return inlineEditorMatches(shown, screen, ""); @@ -2348,10 +2355,7 @@ export async function handlePromptRequest(request: Request, url: URL, options: P if (typedEditor) { if (!asks() || request.signal.aborted) return false; if (checkBeforeText) return inlineEditorMatches(shown, screen, typedEditor.text); - if (responder === "codex-question") { - const notes = parseCodexNotes(screen); - return notes !== null && withServedAsk(body.pane_id, notes).id === parsed.id; - } + if (responder === "codex-async-question") return codexAsyncAnswerMatches(screen, parsed, typedEditor.text); if (responder === "dsh-question") return dshFreeTextRow(screen, parsed, dshTypedText(typedEditor.text)) === "typed"; if (responder === "omp-question") return ompCustomEditorMatches(screen, typedEditor); if (responder === "opencode-v1-question") return openCodeV1CustomEditorMatches(screen, typedEditor); @@ -2359,7 +2363,7 @@ export async function handlePromptRequest(request: Request, url: URL, options: P } return lettaTyping ? lettaSearchShown(shown, parsed, lettaSearch) : sameQuestion(shown, screen, onCursor, settled); }, () => ({ written: write() }), - typedEditor || gjcEditorPaste ? "editor" : interaction !== undefined || responder === "pi-question" || responder === "pi-confirm" || responder.startsWith("fallback")); + typedEditor || gjcEditorPaste || codexNotesPaste ? "editor" : interaction !== undefined || responder === "pi-question" || responder === "pi-confirm" || responder.startsWith("fallback")); await written; } else { const guarding = guardKey(body.pane_id, agent, look); From 4d34b6197f9449865d173789b13bddc5821fdbd8 Mon Sep 17 00:00:00 2001 From: devswha Date: Fri, 27 Nov 2026 04:37:43 +0900 Subject: [PATCH 3/3] fix(prompt): accept a typed answer in Codex's headerless queued question --- server/codex-question.test.ts | 7 +++++++ server/dialogs/codex.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/codex-question.test.ts b/server/codex-question.test.ts index 2b0bb3272d..d2cd66dc04 100644 --- a/server/codex-question.test.ts +++ b/server/codex-question.test.ts @@ -222,6 +222,13 @@ test("does not paste into Codex's composer when the question closes after Tab", expect([result, pane.sent]).toEqual([409, ["down", "down", "tab"]]); }); +test("answers a queued question in the old layout without the queue header", async () => { + const queue = (row: string) => ` Which color?\n 1. red\n 2. blue\n${row}\n enter submit ctrl+] skip alt+↓ main prompt\n`; + const pane = await herdr((key, screen) => key === "text:green" ? queue(" › 3. green") : key === "enter" ? COMPOSER : screen, queue(" › 3. Other")); + const result = await answer((await card()).id, { custom_text: "green" }); + expect([result, pane.sent]).toEqual([200, ["text:green", "enter"]]); +}); + describe.each([ ["free-form", " Type your answer", " green"], ["choice with Other", " 1. red\n 2. blue\n › 3. Other", " 1. red\n 2. blue\n › 3. green"], diff --git a/server/dialogs/codex.ts b/server/dialogs/codex.ts index 363cc45240..f2c17b1344 100644 --- a/server/dialogs/codex.ts +++ b/server/dialogs/codex.ts @@ -170,8 +170,8 @@ function parseCodexAsyncQuestion(screen: string, answer?: string): ParsedPrompt if (answer !== undefined && (!lastRow.selected || answer === "Other" || answer === "Other (write an answer)" || lines[lastRow.lineIndex]?.trimEnd().replace(/^\s*› *\d+\. /u, "") !== answer || text(lastRow.lineIndex + 1, hintIndex).length !== 0)) return null; - // an old layout without the header must still end in its "Other" row - if (header < 0 && !/^Other\b/i.test(rows.at(-1)!.label)) return null; + // an old layout without the header must still end in its "Other" row, until an answer is typed there + if (header < 0 && answer === undefined && !/^Other\b/i.test(rows.at(-1)!.label)) return null; // a wrapped option continues on the lines under it: these rows carry no descriptions const labels = rows.map((row, index) => normalizeText([row.label, ...text(row.lineIndex + 1, rows[index + 1]?.lineIndex ?? hintIndex)].join(" "))); question = header < 0 ? nearestQuestion(lines, rows[0]!.lineIndex) : normalizeText(questionLines(rows[0]!.lineIndex).join(" ")) || null;