The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): typing a custom clarify answer keeps multi-select picks
chelsealong94939c06c48a
diff --git a/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx b/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsxindex c2c0a9a0911..c2317884a00 100644--- a/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx+++ b/apps/desktop/src/components/assistant-ui/clarify-tool.test.tsx@@ -217,6 +217,28 @@ describe('ClarifyTool choice selection', () => {})})+ it('keeps picked multi-select choices when typing a custom answer alongside them', async () => {+ const { respond } = renderLiveClarify({ multiSelect: true })+ const staging = screen.getByRole('button', { name: /staging/ })+ const production = screen.getByRole('button', { name: /production/ })+ const other = screen.getByPlaceholderText(/Other/)++ fireEvent.click(staging)+ fireEvent.click(production)+ fireEvent.focus(other)+ fireEvent.change(other, { target: { value: 'something else' } })++ // Typing in "Other" must not silently drop the picks already made.+ expect(staging.getAttribute('aria-pressed')).toBe('true')+ expect(production.getAttribute('aria-pressed')).toBe('true')++ fireEvent.click(screen.getByRole('button', { name: /Continue/ }))++ await waitFor(() => {+ expect(respond).toHaveBeenCalledWith({ answer: JSON.stringify(['staging', 'production', 'something else']) })+ })+ })+it('keeps single-select replacement and plain-string submission', async () => {const { respond } = renderLiveClarify()const staging = screen.getByRole('button', { name: /staging/ })@@ -775,6 +797,28 @@ describe('ClarifyTool batch card', () => {})})+ it('keeps a picked multi-select batch choice when typing a custom answer alongside it', async () => {+ const { request } = renderLiveBatch(undefined, true)++ fireEvent.click(screen.getByRole('button', { name: /red/ }))+ fireEvent.change(screen.getByPlaceholderText(/Other/), { target: { value: 'green' } })++ // Typing in "Other" must not silently drop the pick already made.+ expect(screen.getByRole('button', { name: /red/ }).getAttribute('aria-pressed')).toBe('true')++ fireEvent.change(screen.getByPlaceholderText('Type your answer…'), { target: { value: 'packet' } })+ fireEvent.submit(document.querySelector('form') as HTMLFormElement)++ await waitFor(() => {+ expect(request).toHaveBeenCalledTimes(2)+ })+ expect(request).toHaveBeenNthCalledWith(1, 'clarify.lock', {+ answer: JSON.stringify(['red', 'green']),+ question_id: 'q0',+ request_id: 'request-batch'+ })+ })+it('pre-stages replayed locked answers from a reconnect', () => {renderLiveBatch({ q0: 'red' })diff --git a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx b/apps/desktop/src/components/assistant-ui/clarify-tool.tsxindex 9857f0c4696..dc68242fd67 100644--- a/apps/desktop/src/components/assistant-ui/clarify-tool.tsx+++ b/apps/desktop/src/components/assistant-ui/clarify-tool.tsx@@ -499,11 +499,13 @@ function ClarifyToolSinglePending({const trimmedDraft = draft.trim()// The answer is whichever input is active: a picked choice, or typed text.// Picking a choice no longer fires immediately — it selects, then the user- // confirms with Continue (or Enter from the field).+ // confirms with Continue (or Enter from the field). Multi-select treats the+ // typed text as one more answer alongside whatever is already picked.+ const multiSelectAnswers = multiSelect && trimmedDraft ? [...selectedChoices, trimmedDraft] : selectedChoicesconst selectedAnswer = multiSelect- ? selectedChoices.length > 0- ? JSON.stringify(selectedChoices)+ ? multiSelectAnswers.length > 0+ ? JSON.stringify(multiSelectAnswers): null: (selectedChoices[0] ?? null)@@ -703,8 +705,9 @@ function ClarifyToolSinglePending({setDraft(value)// Typing is its own answer — drop any picked choice so the two inputs can't- // both look selected.- if (value.trim()) {+ // both look selected. Multi-select allows both: the typed text becomes an+ // additional answer instead of replacing the picked choices.+ if (value.trim() && !multiSelect) {setSelectedChoices([])}}@@ -769,7 +772,10 @@ function ClarifyToolSinglePending({onBlur={() => setOtherFocused(false)}onChange={event => onDraftChange(event.target.value)}onFocus={() => {- setSelectedChoices([])+ if (!multiSelect) {+ setSelectedChoices([])+ }+setActiveIndex(choices.length)setOtherFocused(true)}}@@ -1030,12 +1036,19 @@ function ClarifyToolBatchPending({const stagedAnswer = useCallback((question: ClarifyQuestion): string | null => {const stage = staged[question.qid] ?? emptyStage+ const draft = stage.draft.trim()- if (stage.choices.length > 0) {- return question.multiSelect ? JSON.stringify(stage.choices.map(bareChoice)) : bareChoice(stage.choices[0])+ if (question.multiSelect) {+ // The typed text is an additional answer, not a replacement for the+ // staged choices.+ const combined = [...stage.choices.map(bareChoice), ...(draft ? [draft] : [])]++ return combined.length > 0 ? JSON.stringify(combined) : null}- const draft = stage.draft.trim()+ if (stage.choices.length > 0) {+ return bareChoice(stage.choices[0])+ }return draft ? draft : null},@@ -1102,7 +1115,13 @@ function ClarifyToolBatchPending({}, [])const draftFor = useCallback((question: ClarifyQuestion, value: string) => {- setStaged(current => ({ ...current, [question.qid]: { choices: [], draft: value } }))+ setStaged(current => {+ const stage = current[question.qid] ?? emptyStage++ // Multi-select keeps the staged choices while the free-text field is+ // edited; single-select stays mutually exclusive.+ return { ...current, [question.qid]: { choices: question.multiSelect ? stage.choices : [], draft: value } }+ })}, [])const cancelAll = useCallback(async () => {