Skip to content

The agent that grows with you

fix(desktop): plain Enter sends a clarify set only once every question is answered

Teknium0b5290df059b
diff --git a/apps/desktop/src/components/assistant-ui/clarify/clarify-set-form.test.tsx b/apps/desktop/src/components/assistant-ui/clarify/clarify-set-form.test.tsx
index e798a4fcc76..d5d25819b8b 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/clarify-set-form.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/clarify/clarify-set-form.test.tsx
@@ -32,13 +32,13 @@ const QUESTIONS = [
{ choices: null, multiSelect: false, qid: 'q2', question: 'Anything else?' }
]
-function renderSet() {
+function renderSet(questions = QUESTIONS) {
const request = vi.fn().mockResolvedValue({ ok: true, remaining: [] })
rememberServerRequest({ fail: vi.fn(), id: 'request-set', method: 'clarify', params: {}, respond: vi.fn() })
$activeSessionId.set('session-1')
$gateway.set({ request } as never)
- setClarifyRequest({ questions: QUESTIONS, requestId: 'request-set', sessionId: 'session-1' })
- const args = { questions: QUESTIONS.map(({ choices, question }) => ({ choices, question })) }
+ setClarifyRequest({ questions, requestId: 'request-set', sessionId: 'session-1' })
+ const args = { questions: questions.map(({ choices, question }) => ({ choices, question })) }
const props: ToolCallMessagePartProps = {
addResult: vi.fn(), args, argsText: JSON.stringify(args), isError: false, respondToApproval: vi.fn(),
@@ -86,4 +86,18 @@ describe('a multi-question clarify set is one form', () => {
await waitFor(() => expect(locks(request)).toHaveLength(3))
expect(locks(request)).toEqual([['q0', 'staging'], ['q1', 'us'], ['q2', 'after 5pm']])
})
+
+ it('plain Enter on the last question does not send the set while earlier questions are open', async () => {
+ const request = renderSet([...QUESTIONS.slice(0, 2), { ...QUESTIONS[2], choices: ['now', 'later'] }])
+
+ // Only the last question is answered; the user goes back to it and presses Enter.
+ fireEvent.click(screen.getByRole('button', { name: /later/ }))
+ fireEvent.pointerDown(screen.getByText('Anything else?'))
+ fireEvent.keyDown(window, { key: 'Enter' })
+ // That Enter sent nothing and moved the cursor to the first open question: Enter picks its row.
+ fireEvent.keyDown(window, { key: 'Enter' })
+ fireEvent.keyDown(screen.getByRole('button', { name: /later/ }), { key: 'Enter', ctrlKey: true })
+ await waitFor(() => expect(locks(request)).toHaveLength(3))
+ expect(locks(request)).toEqual([['q0', 'staging'], ['q1', null], ['q2', 'later']])
+ })
})
diff --git a/apps/desktop/src/components/assistant-ui/clarify/core/use-clarify-keys.ts b/apps/desktop/src/components/assistant-ui/clarify/core/use-clarify-keys.ts
index f1d41de498e..ce001c2361b 100644
--- a/apps/desktop/src/components/assistant-ui/clarify/core/use-clarify-keys.ts
+++ b/apps/desktop/src/components/assistant-ui/clarify/core/use-clarify-keys.ts
@@ -137,12 +137,12 @@ export function useClarifyKeys({
}
if (isStaged(active, row)) {
- // Plain Enter submits the set only from the last question or once nothing is left open:
- // an earlier question moves on to the next unanswered one, so a set is never sent half
- // answered by accident (Cmd/Ctrl+Enter still submits from anywhere).
- const next = questionIndex < questions.length - 1 ? nextUnstaged(questionIndex) : null
+ // Plain Enter submits the set only once every question is answered, from any question
+ // (the last one included); otherwise it moves to the first open one, so a set is never
+ // sent half answered by accident (Cmd/Ctrl+Enter still submits from anywhere).
+ const next = questions.findIndex(question => !isStaged(question))
- if (next === null) {
+ if (next < 0) {
onConfirm()
} else if (questions[next]?.choices?.length) {
setCursor({ question: next, row: 0 })
@@ -160,7 +160,7 @@ export function useClarifyKeys({
}
focusOther(questionIndex)
- }, [active, focusOther, isStaged, nextUnstaged, onConfirm, pick, questionIndex, questions, row])
+ }, [active, focusOther, isStaged, onConfirm, pick, questionIndex, questions, row])
useEffect(() => {
if (!enabled || !active) {