feat(mobile): Codex async question keys on the smart rail

This commit is contained in:
Kelvin Amoaba
2026-11-09 21:08:53 +00:00
parent 7358b9d334
commit ea4ec7cfd9
4 changed files with 58 additions and 15 deletions
+3 -1
View File
@@ -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"
}
@@ -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':
@@ -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',
+30 -12
View File
@@ -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. */