Repository navigation
TUI: multi-select for array-of-choices form fields (#2904) - #2919
Merged
Merged
Conversation
ink-form has no multi-select, so an array-of-enums property rendered as a single select: a tool argument could carry one value at most, and a multi-select elicitation was answered with a one-element array. Add a custom ink-form field manager (Up/Down, Space to toggle) that every schemaToForm-built form registers, restore the schema's typed enum members on decode, and check minItems/maxItems before the tool call or the elicitation answer is sent. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Multi-select enum handling incorrectly converts null to a string and conflates distinct members such as 1 and "1", causing schema-invalid submissions and preventing valid single-item selections.
2 open issues
What changed in this PR
Adds multi-select fields to the TUI’s shared tool and elicitation forms, addressing #2904’s single-choice limitation for array-of-enum inputs.
Changes:
- Introduces a keyboard-driven multi-select manager with scrolling, selection labels, and bounds hints.
- Adds array defaults, enum-member decoding, and submission checks for
minItems/maxItems. - Documents the interaction and adds helper, component, and modal tests.
| File | Description |
|---|---|
clients/tui/src/utils/schemaToForm.ts |
Builds multi-select fields, decodes selections, and checks bounds. |
clients/tui/src/utils/pendingRequests.ts |
Checks selection bounds before accepting elicitation. |
clients/tui/src/utils/multiSelectField.ts |
Defines field types and pure selection helpers. |
clients/tui/src/components/ToolTestModal.tsx |
Registers the manager and rejects out-of-bounds arguments. |
clients/tui/src/components/PendingRequestModal.tsx |
Registers the manager and displays elicitation validation errors. |
clients/tui/src/components/MultiSelectField.tsx |
Implements keyboard interaction and selection rendering. |
clients/tui/README.md |
Documents multi-select controls and validation. |
clients/tui/__tests__/ToolTestModal.test.tsx |
Covers bounds rejection and typed argument submission. |
clients/tui/__tests__/schemaToForm.test.ts |
Covers field construction, defaults, decoding, and bounds. |
clients/tui/__tests__/pendingRequests.test.ts |
Covers multi-select elicitation results and validation. |
clients/tui/__tests__/PendingRequestModal.test.tsx |
Covers invalid-answer rejection followed by acceptance. |
clients/tui/__tests__/MultiSelectInput.test.tsx |
Covers navigation, toggling, scrolling, and real form submission. |
clients/tui/__tests__/multiSelectField.test.ts |
Tests selection, label, hint, and scrolling helpers. |
Review effort: Balanced
String(member) is not an identity for an arbitrary enum: [1, "1"] shared one option id and a chosen null decoded as "null". Options are now keyed by their member's index and decoded back to the exact member; defaults map to indices by Object.is. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
#2904) Object.is dropped an object enum member's default, and choice restoration re-read an already-restored const array as option ids. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
Member
Author
|
Copilot review loop closed: round 3 was clean, with no inline comments, no headline findings and no suppressed comments.
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Closes #2904
What changed
ink-form has no multi-select, so
schemaToFormrendered an array-of-choices property ({ type: "array", items: { enum: [...] } }) as a single select. A tool argument could carry one value at most, and since #2829 a multi-select elicitation was answered with a one-element array, withminItems/maxItemsnever checked.clients/tui/src/components/MultiSelectField.tsx, shape and pure helpers insrc/utils/multiSelectField.ts). Enter opens the field, Up/Down moves, Space toggles, Enter saves. The bounds are shown while editing, and a list longer than 8 rows scrolls with the cursor.ToolTestModaland the elicitation form inPendingRequestModalregister it through ink-form'scustomManagers.schemaToFormemits amultiselectfield for an array of choices. It carriesminItems/maxItems, and an arraydefaultbecomes the initial selection.decodeFormValuesconverts the chosen option strings back to the schema's own enum members, soenum: [1, 2]sends[2]and not["2"]. It also drops a selection the user emptied on an optional field, because ink-form has no way to unset a saved field.selectionCountErrors(new) checksminItems/maxItemsagainst the decoded values. It respects the chosen root-union branch. The tool modal refuses the call withInvalid argument(s): …, and the elicitation answer is held withInvalid field(s): ….Out of scope, as the issue asks: tool-argument
items.anyOfconst lists. Elicitation's titleditems.anyOfwas already normalized toitems.enumby #2903, so it is covered.Screenshots
These are TUI frames from the real ink-form
Formwith the new manager. They were captured with ink-testing-library (ANSI stripped) and rendered to PNG. Tool argument form, editing and saved:Elicitation form (titled
items.anyOf,minItems: 2), editing and saved:Tests
npm run local:gateis green. New suites cover the pure helpers (multiSelectField.test.ts) and the input plus a real end-to-end ink-form edit-and-submit (MultiSelectInput.test.tsx). Existing suites now also cover typed-member restoration and bounds, including inside a root-union branch and on a__proto__field (schemaToForm.test.ts), the elicitationinvalidoutcome (pendingRequests.test.ts), and both modals refusing an out-of-bounds submission (ToolTestModal.test.tsx,PendingRequestModal.test.tsx).🤖 Generated with Claude Code