The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): an empty multi-select never holds plain Enter back in a clarify set
Teknium690da2b7bee5
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.tsxindex d5d25819b8b..f70174c021c 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@@ -100,4 +100,43 @@ describe('a multi-question clarify set is one form', () => {await waitFor(() => expect(locks(request)).toHaveLength(3))expect(locks(request)).toEqual([['q0', 'staging'], ['q1', null], ['q2', 'later']])})++ // An empty multi-select ("pick any") is a valid answer, so it never holds plain Enter back:+ // mashing Enter from any question the keyboard cursor rests on sends the set within a few+ // presses instead of landing on the multi-select, where Enter toggles a choice on and off+ // forever. (On a multi-select row Enter is that toggle by design; a free-text question+ // takes Enter in its own text field.)+ const MIXED = [+ { choices: ['staging', 'production'], multiSelect: false, qid: 'q0', question: 'Which target?' },+ { choices: ['lint', 'tests', 'docs'], multiSelect: true, qid: 'q1', question: 'Which checks?' },+ { choices: null, multiSelect: false, qid: 'q2', question: 'Anything else?' },+ { choices: ['now', 'later'], multiSelect: false, qid: 'q3', question: 'When?' }+ ]++ const ENTER_BUDGET = 3++ for (const answerFirst of [true, false]) {+ for (const start of ['Which target?', 'When?']) {+ it(`plain Enter from "${start}" sends the set within ${ENTER_BUDGET} presses (q0 ${answerFirst ? 'answered' : 'open'})`, async () => {+ const request = renderSet(MIXED)++ if (answerFirst) {+ fireEvent.click(screen.getByRole('button', { name: /staging/ }))+ }++ fireEvent.change(screen.getByPlaceholderText(/Type your answer/), { target: { value: 'after 5pm' } })+ fireEvent.click(screen.getByRole('button', { name: /later/ }))+ // Clicking a question heading takes focus out of the text field a pick moved it into.+ screen.getByPlaceholderText(/Type your answer/).blur()+ fireEvent.pointerDown(screen.getByText(start))++ for (let press = 0; press < ENTER_BUDGET; press += 1) {+ fireEvent.keyDown(window, { key: 'Enter' })+ }++ await waitFor(() => expect(locks(request)).toHaveLength(4))+ expect(locks(request)).toEqual([['q0', 'staging'], ['q1', null], ['q2', 'after 5pm'], ['q3', '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.tsindex ce001c2361b..4e8b9189aa1 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@@ -67,19 +67,27 @@ export function useClarifyKeys({[formRef, onOtherFocus])+ // A multi-select is never "open": zero picks is a valid answer ("pick any"). Counting it+ // open would let plain Enter jump onto its first row, where Enter only toggles a choice,+ // so mashing Enter would flip that choice on and off forever and never send the set.+ const isOpen = useCallback(+ (question: ClarifyQuestion | undefined) => Boolean(question && !question.multiSelect && !isStaged(question)),+ [isStaged]+ )+const nextUnstaged = useCallback((index: number): null | number => {for (let offset = 1; offset < questions.length; offset += 1) {const candidate = (index + offset) % questions.length- if (!isStaged(questions[candidate])) {+ if (isOpen(questions[candidate])) {return candidate}}return null},- [isStaged, questions]+ [isOpen, questions])const pick = useCallback(@@ -137,10 +145,10 @@ export function useClarifyKeys({}if (isStaged(active, row)) {- // 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))+ // Plain Enter submits the set only once no question is open, 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(isOpen)if (next < 0) {onConfirm()@@ -160,7 +168,7 @@ export function useClarifyKeys({}focusOther(questionIndex)- }, [active, focusOther, isStaged, onConfirm, pick, questionIndex, questions, row])+ }, [active, focusOther, isOpen, isStaged, onConfirm, pick, questionIndex, questions, row])useEffect(() => {if (!enabled || !active) {