From ea4ec7cfd964cca88bb874d17b03380e2fcbf7fe Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Fri, 6 Nov 2026 05:10:38 +0000 Subject: [PATCH] feat(mobile): Codex async question keys on the smart rail --- mobile/src/i18n/locales/en.json | 4 +- .../session/MobileSessionSmartKeys.tsx | 8 +++- .../terminal/input/agent-smart-keys.test.ts | 19 +++++++++ src/shared/terminal/input/agent-smart-keys.ts | 42 +++++++++++++------ 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/mobile/src/i18n/locales/en.json b/mobile/src/i18n/locales/en.json index 6c5f5054314..a17ea4122a0 100644 --- a/mobile/src/i18n/locales/en.json +++ b/mobile/src/i18n/locales/en.json @@ -2894,10 +2894,11 @@ }, "smartKeys": { "always": "Always", - "answerEdit": "Answer · Edit", + "answer": "Answer", "background": "Background", "cancel": "Cancel", "confirm": "Confirm", + "edit": "Edit", "history": "History", "keyLabel": "{{word}}, sends {{combo}}", "mode": "Mode", @@ -2906,6 +2907,7 @@ "reject": "Reject", "rewind": "Rewind", "sendNow": "Send now", + "skip": "Skip", "stop": "Stop", "yes": "Yes" } diff --git a/mobile/src/terminal/session/MobileSessionSmartKeys.tsx b/mobile/src/terminal/session/MobileSessionSmartKeys.tsx index d12b2f02d07..fdc0f612d85 100644 --- a/mobile/src/terminal/session/MobileSessionSmartKeys.tsx +++ b/mobile/src/terminal/session/MobileSessionSmartKeys.tsx @@ -34,8 +34,12 @@ function smartKeyWord(t: Translate, name: AgentSmartKeyName): string { return t('session.smartKeys.rewind', 'Rewind') case 'queue': return t('session.smartKeys.queue', 'Queue') - case 'answerEdit': - return t('session.smartKeys.answerEdit', 'Answer · Edit') + case 'edit': + return t('session.smartKeys.edit', 'Edit') + case 'answer': + return t('session.smartKeys.answer', 'Answer') + case 'skip': + return t('session.smartKeys.skip', 'Skip') case 'confirm': return t('session.smartKeys.confirm', 'Confirm') case 'reject': diff --git a/src/shared/terminal/input/agent-smart-keys.test.ts b/src/shared/terminal/input/agent-smart-keys.test.ts index f0c1c515020..1152d2b4493 100644 --- a/src/shared/terminal/input/agent-smart-keys.test.ts +++ b/src/shared/terminal/input/agent-smart-keys.test.ts @@ -28,6 +28,25 @@ describe('resolveAgentSmartKeys', () => { ]) }) + it("opens Codex's async question with ⇧← before its digits", () => { + const ask = resolveAgentSmartKeys('codex', { + state: 'waiting', + toolName: 'request_user_input_async', + interactivePrompt: JSON.stringify({ + questions: [{ title: 'Which db?', options: ['a', 'b', 'c'] }, { title: 'Table name?' }] + }) + }) + expect(ask?.state).toBe('question') + expect(ask?.keys.map((key) => key.writes.join(''))).toEqual([ + '\x1b[1;2D', + '1', + '2', + '3', + '\r', + '\x1d' + ]) + }) + it('declines one Codex approval with n and stops OpenCode with two separate Escapes', () => { const codexNo = resolveAgentSmartKeys('codex', { state: 'waiting', diff --git a/src/shared/terminal/input/agent-smart-keys.ts b/src/shared/terminal/input/agent-smart-keys.ts index 379449aaa8b..3a7d185ef28 100644 --- a/src/shared/terminal/input/agent-smart-keys.ts +++ b/src/shared/terminal/input/agent-smart-keys.ts @@ -30,7 +30,9 @@ export type AgentSmartKeyName = | 'history' | 'rewind' | 'queue' - | 'answerEdit' + | 'edit' + | 'answer' + | 'skip' | 'confirm' | 'reject' @@ -99,7 +101,8 @@ const STATE_KEYS: Record< working: [ word('stop', 'Esc', [ESC]), word('queue', 'Tab', ['\t']), - word('answerEdit', '⇧←', [SHIFT_LEFT]) + // Pulls the last queued message back into the composer. + word('edit', '⇧←', [SHIFT_LEFT]) ], // `n` turns down only this request; Esc would also drop every queued approval. permission: [word('yes', 'y', ['y'], true), word('always', 'a', ['a']), word('no', 'n', ['n'])] @@ -116,20 +119,35 @@ const STATE_KEYS: Record< } } -function questionKeys(row: AgentSmartKeyRow): readonly AgentSmartKey[] | null { +function questionKeys( + agent: AgentSmartKeyAgent, + row: AgentSmartKeyRow +): readonly AgentSmartKey[] | null { const ask = parseAskFromStatus(row.interactivePrompt, row.toolName) - // The phone can't see which question tab is open, so offer digits for the longest one. - const optionCount = Math.min( - 9, - Math.max(0, ...(ask?.questions ?? []).map((q) => q.options.length)) + if (!ask) { + return null + } + // The phone can't see which question is open, so offer digits for the longest one. + const optionCount = Math.min(9, Math.max(0, ...ask.questions.map((q) => q.options.length))) + const digits = Array.from({ length: optionCount }, (_, index) => + plain(`option${index + 1}`, String(index + 1), String(index + 1)) ) - if (optionCount === 0) { + if (agent === 'codex') { + // Codex keeps working while its async question waits collapsed under the composer; ⇧← opens it. + return ask.replyAsMessage + ? [ + word('answer', '⇧←', [SHIFT_LEFT], true), + ...digits, + plain('enter', 'Enter', '\r'), + word('skip', '⌃]', ['\x1d']) + ] + : null + } + if (agent !== 'claude' || optionCount === 0) { return null } return [ - ...Array.from({ length: optionCount }, (_, index) => - plain(`option${index + 1}`, String(index + 1), String(index + 1)) - ), + ...digits, plain('left', '←', ARROW_LEFT), plain('right', '→', ARROW_RIGHT), word('cancel', 'Esc', [ESC]) @@ -164,7 +182,7 @@ export function resolveAgentSmartKeys( if (parseNativeChatApprovalEnvelope(row.interactivePrompt, agent)) { return withKeys('permission', STATE_KEYS[agent].permission) } - return agent === 'claude' ? withKeys('question', questionKeys(row)) : null + return withKeys('question', questionKeys(agent, row)) } /** Whether two sets draw the same keys, so a fresh status object doesn't redraw the row. */