Skip to content

TUI: multi-select for array-of-choices form fields (#2904) - #2919

Merged
cliffhall merged 3 commits into
v2/mainfrom
v2/feat/2904-tui-multiselect
Nov 5, 2026
Merged

cliffhall merged 3 commits into
v2/mainfrom
v2/feat/2904-tui-multiselect

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2904

What changed

ink-form has no multi-select, so schemaToForm rendered 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, with minItems/maxItems never checked.

  • New custom field manager (clients/tui/src/components/MultiSelectField.tsx, shape and pure helpers in src/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. ToolTestModal and the elicitation form in PendingRequestModal register it through ink-form's customManagers.
  • schemaToForm emits a multiselect field for an array of choices. It carries minItems/maxItems, and an array default becomes the initial selection.
  • decodeFormValues converts the chosen option strings back to the schema's own enum members, so enum: [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) checks minItems/maxItems against the decoded values. It respects the chosen root-union branch. The tool modal refuses the call with Invalid argument(s): …, and the elicitation answer is held with Invalid field(s): ….
  • The TUI README describes the new field.

Out of scope, as the issue asks: tool-argument items.anyOf const lists. Elicitation's titled items.anyOf was already normalized to items.enum by #2903, so it is covered.

Screenshots

These are TUI frames from the real ink-form Form with the new manager. They were captured with ink-testing-library (ANSI stripped) and rendered to PNG. Tool argument form, editing and saved:

tool editing
tool saved

Elicitation form (titled items.anyOf, minItems: 2), editing and saved:

elicitation editing
elicitation saved

Tests

npm run local:gate is 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 elicitation invalid outcome (pendingRequests.test.ts), and both modals refusing an out-of-bounds submission (ToolTestModal.test.tsx, PendingRequestModal.test.tsx).

🤖 Generated with Claude Code

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]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Nov 5, 2026
@cliffhall cliffhall linked an issue Nov 5, 2026 that may be closed by this pull request
@cliffhall
cliffhall requested a balanced review from Copilot November 5, 2026 14:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread clients/tui/src/utils/schemaToForm.ts Resolved
Comment thread clients/tui/src/utils/schemaToForm.ts Resolved
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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Choice restoration can overwrite constant-pinned array values, while reference-based enum matching drops valid object defaults from untouched optional fields.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread clients/tui/src/utils/schemaToForm.ts Resolved
Comment thread clients/tui/src/utils/schemaToForm.ts Resolved
#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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are identified for the multi-select form changes.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 3 was clean, with no inline comments, no headline findings and no suppressed comments.

  • Round 1 (2 findings, both fixed in 6c052bb): a chosen null enum member decoded as "null", and look-alike members such as 1 and "1" shared one option id. Multi-select options are now identified by their enum index and decoded back to the exact member.
  • Round 2 (2 findings, both fixed in f59ab2c): object defaults are now matched by JSON value (sameJsonValue), and a const-pinned array is no longer re-read as option ids.
  • Round 3: clean, so the loop stopped.

@cliffhall
cliffhall merged commit 6512c10 into v2/main Nov 5, 2026
12 checks passed
@cliffhall
cliffhall deleted the v2/feat/2904-tui-multiselect branch November 5, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI: support multi-select (array) fields in ink-form forms

2 participants