-
Notifications
You must be signed in to change notification settings - Fork 899
feat(vscode): show all agent questions in one form with multi-select support #2466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kimi-code": patch | ||
| --- | ||
|
|
||
| Show all agent questions in a single form with multi-select support, and allow skipping questions or dismissing the prompt. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /** | ||
| * Scenario: the QuestionDialog form state is projected into the AskUserQuestion answers contract. | ||
| * Responsibilities: verify single/multi-select resolution, custom text precedence, join format, | ||
| * and unanswered-question omission one case at a time. | ||
| * Wiring: the pure builder and real protocol types are used directly; there are no stubs. | ||
| * Run: pnpm exec vitest run --config apps/vscode/vitest.config.ts apps/vscode/test/question-answers.test.ts | ||
| */ | ||
|
|
||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import type { QuestionItem } from '../shared/legacy-sdk'; | ||
| import { | ||
| buildQuestionAnswers, | ||
| type QuestionFormState, | ||
| } from '../webview-ui/src/lib/question-answers'; | ||
|
|
||
| function question(overrides: Partial<QuestionItem> = {}): QuestionItem { | ||
| return { | ||
| question: 'Pick a color?', | ||
| header: 'Style', | ||
| options: [ | ||
| { label: 'Red', description: '' }, | ||
| { label: 'Blue', description: '' }, | ||
| { label: 'Green', description: '' }, | ||
| ], | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function form(overrides: Partial<QuestionFormState> = {}): QuestionFormState { | ||
| return { single: {}, multi: {}, custom: {}, ...overrides }; | ||
| } | ||
|
|
||
| describe('buildQuestionAnswers (projects the form state into the answers contract)', () => { | ||
| it('maps a single-select choice to the option label keyed by question text', () => { | ||
| const answers = buildQuestionAnswers([question()], form({ single: { 0: 1 } })); | ||
|
|
||
| expect(answers).toEqual({ 'Pick a color?': 'Blue' }); | ||
| }); | ||
|
|
||
| it('lets custom text win over a single-select choice', () => { | ||
| const answers = buildQuestionAnswers( | ||
| [question()], | ||
| form({ single: { 0: 1 }, custom: { 0: ' Chartreuse ' } }), | ||
| ); | ||
|
|
||
| expect(answers).toEqual({ 'Pick a color?': 'Chartreuse' }); | ||
| }); | ||
|
|
||
| it("joins multi-select labels with ', ' following the TUI convention", () => { | ||
| const answers = buildQuestionAnswers( | ||
| [question({ multi_select: true })], | ||
| form({ multi: { 0: new Set([2, 0]) } }), | ||
| ); | ||
|
|
||
| expect(answers).toEqual({ 'Pick a color?': 'Red, Green' }); | ||
| }); | ||
|
|
||
| it('appends custom text as an extra label for multi-select questions', () => { | ||
| const answers = buildQuestionAnswers( | ||
| [question({ multi_select: true })], | ||
| form({ multi: { 0: new Set([1]) }, custom: { 0: 'Purple' } }), | ||
| ); | ||
|
|
||
| expect(answers).toEqual({ 'Pick a color?': 'Blue, Purple' }); | ||
| }); | ||
|
|
||
| it('omits questions without any answer', () => { | ||
| const answers = buildQuestionAnswers( | ||
| [question({ question: 'First?' }), question({ question: 'Second?' })], | ||
| form({ single: { 1: 0 } }), | ||
| ); | ||
|
|
||
| expect(answers).toEqual({ 'Second?': 'Red' }); | ||
| }); | ||
|
|
||
| it('returns an empty record when nothing is answered (dismiss semantics)', () => { | ||
| const answers = buildQuestionAnswers( | ||
| [question(), question({ question: 'Another?', multi_select: true })], | ||
| form({ multi: { 1: new Set() }, custom: { 0: ' ' } }), | ||
| ); | ||
|
|
||
| expect(answers).toEqual({}); | ||
| }); | ||
|
|
||
| it('ignores out-of-range selections and empty option lists', () => { | ||
| const answers = buildQuestionAnswers( | ||
| [question(), question({ question: 'Empty?', options: [] })], | ||
| form({ single: { 0: 7, 1: 0 } }), | ||
| ); | ||
|
|
||
| expect(answers).toEqual({}); | ||
| }); | ||
| }); |
226 changes: 132 additions & 94 deletions
226
apps/vscode/webview-ui/src/components/QuestionDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a request contains multiple questions and the user types a custom response for an earlier question, pressing Enter in this input immediately calls
handleSubmit(), which sends the current partial answers and skips any remaining unanswered questions. In the new all-at-once form, Enter should only commit/close the current custom field or be ignored so users can finish the rest of the form before resolving the agent question.Useful? React with 👍 / 👎.