@juicesharp/rpiv-ask-user-question 2.13.5 → 2.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,7 +25,7 @@ Nothing to set up — the tool is live as soon as Pi restarts. Hand the model a
25
25
 
26
26
  > Add caching to the API client.
27
27
 
28
- Rather than picking a strategy on your behalf, the model calls `ask_user_question` and a dialog takes over the bottom of your terminal. Move with `↑`/`↓`, choose with `Enter`, press `n` to attach a note to a question — or a global note to the whole questionnaire from the Submit tab — or land on the `Type something.` row to answer in your own words. While typing, `Shift+Enter` adds a line, `Ctrl+G` opens Pi's configured external editor, and `Ctrl+U` clears the draft; browsing another option and returning keeps what you wrote. `Esc` abandons the questionnaire entirely.
28
+ Rather than picking a strategy on your behalf, the model calls `ask_user_question` and a dialog takes over the bottom of your terminal. Move with `↑`/`↓`, choose with `Enter`, press `n` to attach a note to a question or a global note from the Submit tab, or land on `Type something.` to answer in your own words. In a multi-select question, typed custom text is selected automatically and submitted together with checked options. While typing, `Shift+Enter` adds a line, `Ctrl+G` opens Pi's configured external editor, and `Ctrl+U` clears the draft; browsing another option and returning keeps what you wrote. `Esc` abandons the questionnaire entirely.
29
29
 
30
30
  When the questionnaire begins waiting in an interactive TTY, it emits one standard terminal BEL (`\x07`). Your terminal configuration determines whether that appears as an audible alert, a visual alert, or nothing; redirected and non-TTY output is untouched.
31
31
 
@@ -38,7 +38,7 @@ When the model asks several things at once, `Tab` moves between them and a Submi
38
38
  ## What you get
39
39
 
40
40
  - **Typed options instead of a wall of prose** — each question carries 2-4 authored choices, and every choice comes with a description of what it means or what it costs you.
41
- - **You can always answer in your own words** — a `Type something.` row is appended to every question, single- or multi-select, widens to the full pane while you type, keeps its multiline draft visible in that row while you browse, and supports Pi's `Shift+Enter` newline and `Ctrl+G` external-editor flows.
41
+ - **You can always answer in your own words**. A `Type something.` row is appended to every question. On multi-select questions, it keeps checked options and custom text in the same answer. The row widens to the full pane while you type, keeps its multiline draft visible while you browse, and supports Pi's `Shift+Enter` newline and `Ctrl+G` external-editor flows.
42
42
  - **Compare real artifacts, not just labels** — an option can carry a markdown `preview` (ASCII mockup, code, diagram, config) that renders in a bordered box beside the option list.
43
43
  - **One interruption, not five** — up to four questions arrive in a single tabbed dialog, and the Submit tab lists your answers and names anything still blank before you commit.
44
44
  - **Notes on any answer — or on all of them** — `n` opens a multiline note editor on any question tab, and on the Submit tab it opens one global note for the whole questionnaire. Per-question notes reach the model as `user notes: <text>`, the global note as `global note: <text>`; neither marks a question answered.
package/docs/hosts.md CHANGED
@@ -46,10 +46,10 @@ TUI produces. Trade-offs inherent to the native primitives:
46
46
  - No notes. Both note kinds — per-question `n` on a question tab and global `n` on the
47
47
  Submit tab — are terminal-only; the host's native `select` and `input` primitives carry
48
48
  no note field.
49
- - Multi-select is a free-text input: type the option numbers, comma-separated
50
- (`1,3`). Any token that is not a valid option index is treated as a typed custom answer,
51
- which is how the `Type something.` escape survives. An empty input commits an empty
52
- selection, matching `Next` with nothing toggled.
49
+ - Multi-select is a free-text input. Type option numbers separated by commas (`1,3`).
50
+ Add a semicolon and custom text to return both (`1,3; another color`). Plain text still
51
+ returns a custom-only multi-select answer. An empty input commits an empty selection,
52
+ matching `Next` with nothing selected.
53
53
  - Dismissing any dialog cancels the whole questionnaire, mirroring `Esc` in the TUI.
54
54
 
55
55
  If the host can render neither custom UI nor dialogs, the call returns
package/docs/keyboard.md CHANGED
@@ -12,7 +12,7 @@ adapts to the size of your terminal.
12
12
  | `Shift+Enter` | Insert a newline. | `Type something.` input, notes editor |
13
13
  | `Esc` | Cancel the whole questionnaire. | Everywhere except the notes editor, where it closes notes |
14
14
  | `Tab` / `Shift+Tab` | Next / previous tab, wrapping. `→` / `←` do the same. | Multi-question dialogs only |
15
- | `Space` | Toggle the focused checkbox. | Multi-select questions |
15
+ | `Space` | Toggle the focused authored option. In `Type something.`, Space inserts text. | Multi-select questions |
16
16
  | `n` | Open the notes editor for the focused question — or, on the Submit tab, the global note for the whole questionnaire. | Every question tab; the Submit tab in multi-question dialogs |
17
17
  | `Ctrl+G` | Open Pi's configured external editor with the current custom-answer draft. | `Type something.` input |
18
18
  | `Ctrl+U` | Clear the current custom-answer draft. | `Type something.` input |
@@ -26,13 +26,13 @@ Slack-style configuration — `enter` folded into `tui.input.newLine`, submit mo
26
26
  everywhere `Enter` does.
27
27
 
28
28
  In a multi-select question, `Enter` on a regular row toggles its checkbox exactly like
29
- `Space` — it does not submit. Committing the question means focusing the `Next` row and
30
- pressing `Enter`. That is deliberate: it makes `Enter` a zero-cost way to flip boxes
31
- without leaving the home row.
29
+ `Space`. It does not submit. Focus `Next` and press `Enter` to commit the question. That
30
+ is deliberate: it makes `Enter` a zero-cost way to flip boxes without leaving the home row.
31
+ `Space` does nothing on `Next` (it is a command, not a choice).
32
32
 
33
- `Space` is suppressed on two rows: `Next` (it is a command, not a choice) and
34
- `Type something.` (it is an inline text input, so the space character belongs to your
35
- answer).
33
+ `Type something.` is an inline input, so Space inserts a space. Its checkbox changes to
34
+ `[✔]` when the input contains text. Press `Enter` in the input or use `Next` to submit
35
+ both the checked options and the custom text.
36
36
 
37
37
  ## The rows the dialog adds
38
38
 
@@ -43,12 +43,15 @@ answer).
43
43
 
44
44
  Focusing `Type something.` switches the row into an inline multiline editor. In preview
45
45
  mode it expands to the full pane width while you type, so a long custom answer is not
46
- squeezed into the narrow options column. `Shift+Enter` inserts a line break; vertical
46
+ squeezed into the narrow options column. `Shift+Enter` inserts a line break. Vertical
47
47
  arrows move between lines and return to row navigation at the draft's top and bottom.
48
48
  The draft replaces the static row label while you browse other options and is isolated
49
- per question. `Ctrl+G` round-trips it through Pi's configured external editor; `Ctrl+U`
50
- clears it, while `Esc` remains the explicit way to cancel the questionnaire. Confirming
51
- it produces an answer of `kind: "custom"`.
49
+ per question. `Ctrl+G` sends it through Pi's configured external editor. `Ctrl+U` clears
50
+ it, while `Esc` cancels the questionnaire.
51
+
52
+ On a single-select question, confirming the input produces `kind: "custom"`. On a
53
+ multi-select question, the result uses `kind: "multi"`: `selected` contains checked
54
+ labels, and `answer` contains the custom text.
52
55
 
53
56
  Both labels are reserved — the model cannot author an option that collides with them.
54
57
  Both localize with the rest of the UI chrome; the reserved-label check always compares
@@ -77,8 +77,8 @@ code. The `content[0].text` string is written for the model, not for a log.
77
77
  questionIndex: number,
78
78
  question: string,
79
79
  kind: "option" | "custom" | "multi",
80
- answer: string | null, // option label, typed text, or null for multi
81
- selected?: string[], // chosen labels, multi-select only
80
+ answer: string | null, // option label, custom text, or null
81
+ selected?: string[], // chosen labels, multi-select only; can accompany answer
82
82
  notes?: string, // free-text note, when you wrote one
83
83
  preview?: string, // echoed back when the chosen option carried a preview
84
84
  }>,
package/locales/de.json CHANGED
@@ -26,6 +26,6 @@
26
26
 
27
27
  "editor.failed": "Externer Editor fehlgeschlagen",
28
28
 
29
- "rpc.multi_instructions": "Gib die Nummern aller zutreffenden Optionen durch Komma getrennt ein (z. B. \"1,3\") oder tippe eine eigene Antwort als Text.",
29
+ "rpc.multi_instructions": "Gib die Nummern aller zutreffenden Optionen durch Kommas getrennt ein (z. B. \"1,3\"). Füge \"; eigene Antwort\" hinzu, um eigenen Text einzuschließen, oder gib nur eigenen Text ein.",
30
30
  "rpc.custom_answer_title": "Gib deine Antwort ein:"
31
31
  }
package/locales/en.json CHANGED
@@ -29,6 +29,6 @@
29
29
 
30
30
  "editor.failed": "External editor failed",
31
31
 
32
- "rpc.multi_instructions": "Enter the numbers of all that apply, comma-separated (e.g. \"1,3\"), or type a custom answer as plain text.",
32
+ "rpc.multi_instructions": "Enter the numbers of all that apply, comma-separated (e.g. \"1,3\"). Add \"; custom answer\" to include your own text, or type only custom text.",
33
33
  "rpc.custom_answer_title": "Type your answer:"
34
34
  }
package/locales/es.json CHANGED
@@ -26,6 +26,6 @@
26
26
 
27
27
  "editor.failed": "Error del editor externo",
28
28
 
29
- "rpc.multi_instructions": "Introduce los números de todas las opciones que apliquen, separados por comas (p. ej. \"1,3\"), o escribe una respuesta propia como texto.",
29
+ "rpc.multi_instructions": "Introduce los números de todas las opciones que correspondan, separados por comas (p. ej. \"1,3\"). Añade \"; respuesta propia\" para incluir texto propio, o escribe solo texto propio.",
30
30
  "rpc.custom_answer_title": "Escribe tu respuesta:"
31
31
  }
package/locales/fr.json CHANGED
@@ -26,6 +26,6 @@
26
26
 
27
27
  "editor.failed": "Échec de l’éditeur externe",
28
28
 
29
- "rpc.multi_instructions": "Saisissez les numéros de toutes les options applicables, séparés par des virgules (p. ex. « 1,3 »), ou tapez une réponse libre en texte.",
29
+ "rpc.multi_instructions": "Saisissez les numéros de toutes les options applicables, séparés par des virgules (p. ex. « 1,3 »). Ajoutez « ; réponse libre » pour inclure votre propre texte, ou saisissez uniquement ce texte.",
30
30
  "rpc.custom_answer_title": "Tapez votre réponse :"
31
31
  }
@@ -26,6 +26,6 @@
26
26
 
27
27
  "editor.failed": "Falha no editor externo",
28
28
 
29
- "rpc.multi_instructions": "Digite os números de todas as opções aplicáveis, separados por vírgula (ex.: \"1,3\") ou digite uma resposta própria em texto.",
29
+ "rpc.multi_instructions": "Digite os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\"). Adicione \"; resposta própria\" para incluir texto próprio, ou digite apenas esse texto.",
30
30
  "rpc.custom_answer_title": "Digite sua resposta:"
31
31
  }
package/locales/pt.json CHANGED
@@ -26,6 +26,6 @@
26
26
 
27
27
  "editor.failed": "Falha no editor externo",
28
28
 
29
- "rpc.multi_instructions": "Introduza os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\") ou escreva uma resposta própria em texto.",
29
+ "rpc.multi_instructions": "Introduza os números de todas as opções aplicáveis, separados por vírgulas (ex.: \"1,3\"). Adicione \"; resposta própria\" para incluir texto próprio, ou escreva apenas esse texto.",
30
30
  "rpc.custom_answer_title": "Escreva a sua resposta:"
31
31
  }
package/locales/ru.json CHANGED
@@ -26,6 +26,6 @@
26
26
 
27
27
  "editor.failed": "Ошибка внешнего редактора",
28
28
 
29
- "rpc.multi_instructions": "Введите номера всех подходящих вариантов через запятую (например, \"1,3\") или введите свой ответ текстом.",
29
+ "rpc.multi_instructions": "Введите номера всех подходящих вариантов через запятую (например, \"1,3\"). Добавьте \"; свой ответ\", чтобы включить собственный текст, или введите только этот текст.",
30
30
  "rpc.custom_answer_title": "Введите свой ответ:"
31
31
  }
package/locales/uk.json CHANGED
@@ -26,6 +26,6 @@
26
26
 
27
27
  "editor.failed": "Помилка зовнішнього редактора",
28
28
 
29
- "rpc.multi_instructions": "Введіть номери всіх відповідних варіантів через кому (наприклад, \"1,3\") або введіть власну відповідь текстом.",
29
+ "rpc.multi_instructions": "Введіть номери всіх відповідних варіантів через кому (наприклад, \"1,3\"). Додайте \"; власна відповідь\", щоб включити власний текст, або введіть лише цей текст.",
30
30
  "rpc.custom_answer_title": "Введіть свою відповідь:"
31
31
  }
package/locales/zh.json CHANGED
@@ -28,6 +28,6 @@
28
28
 
29
29
  "editor.failed": "外部编辑器启动失败",
30
30
 
31
- "rpc.multi_instructions": "输入所有适用选项的编号,用逗号分隔(例如 \"1,3\"),或直接输入自定义回答。",
31
+ "rpc.multi_instructions": "输入所有适用选项的编号,用逗号分隔(例如 \"1,3\")。添加 \"; 自定义回答\" 可同时包含自定义文本,也可以只输入自定义文本。",
32
32
  "rpc.custom_answer_title": "输入你的回答:"
33
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "2.13.5",
3
+ "version": "2.13.6",
4
4
  "description": "Pi extension. A structured questionnaire the model can put to you when it would otherwise guess, with typed options instead of free-form replies.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -99,6 +99,6 @@
99
99
  }
100
100
  },
101
101
  "dependencies": {
102
- "@juicesharp/rpiv-config": "^2.13.5"
102
+ "@juicesharp/rpiv-config": "^2.13.6"
103
103
  }
104
104
  }
package/rpc-fallback.ts CHANGED
@@ -14,10 +14,8 @@
14
14
  * Parity trade-offs vs the TUI, inherent to the select/input API surface: no
15
15
  * side-by-side preview pane (previews are folded into the prompt title), no
16
16
  * tabbed multi-question review (one dialog per question), and multi-select is
17
- * a free-text numbers input instead of checkbox rows. The "Type something."
18
- * escape is preserved on both variants — multi-select treats any non-index
19
- * input as a typed custom answer — matching
20
- * `ROW_INTENT_META.other.autoAppendOnMultiSelect`.
17
+ * a free-text numbers input instead of checkbox rows. The input accepts selected
18
+ * option numbers, custom text, or both separated by a semicolon.
21
19
  */
22
20
 
23
21
  import { displayLabel, t } from "./state/i18n-bridge.js";
@@ -30,9 +28,9 @@ import type { QuestionAnswer, QuestionData, QuestionnaireResult, QuestionParams
30
28
  * `displayLabel("other")` — same source as the TUI row.
31
29
  */
32
30
  const MULTI_SELECT_INSTRUCTIONS =
33
- 'Enter the numbers of all that apply, comma-separated (e.g. "1,3"), or type a custom answer as plain text.';
31
+ 'Enter the numbers of all that apply, comma-separated (e.g. "1,3"). Add "; custom answer" to include your own text, or type only custom text.';
34
32
  const CUSTOM_ANSWER_TITLE = "Type your answer:";
35
- const MULTI_SELECT_PLACEHOLDER = "1,3";
33
+ const MULTI_SELECT_PLACEHOLDER = "1,3; custom answer";
36
34
 
37
35
  /** Longest preview slice folded into a select title before truncation. */
38
36
  const MAX_PREVIEW_CHARS = 600;
@@ -180,19 +178,26 @@ async function askMultiSelect(
180
178
  // Deliberate empty commit — same as pressing "Next" with nothing toggled.
181
179
  return { questionIndex, question: q.question, kind: "multi", answer: null, selected: [] };
182
180
  }
183
- const tokens = trimmed.split(/[,\s]+/).filter((tok) => tok.length > 0);
181
+ const [selectionPart = "", ...customParts] = trimmed.split(";");
182
+ const selection = selectionPart.trim();
183
+ const custom = customParts.join(";").trim();
184
+ const tokens = selection.split(/[,\s]+/).filter((tok) => tok.length > 0);
184
185
  const indices = tokens.map((tok) => (/^\d+\.?$/.test(tok) ? parseIndex(tok, q.options.length) : null));
185
- if (indices.every((i): i is number => i != null)) {
186
+ if (selection.length === 0 || indices.every((i): i is number => i != null)) {
186
187
  const selected: string[] = [];
187
188
  for (const i of indices) {
189
+ if (i == null) continue;
188
190
  const label = q.options[i].label;
189
191
  if (!selected.includes(label)) selected.push(label);
190
192
  }
191
- return { questionIndex, question: q.question, kind: "multi", answer: null, selected };
193
+ return {
194
+ questionIndex,
195
+ question: q.question,
196
+ kind: "multi",
197
+ answer: custom.length > 0 ? custom : null,
198
+ selected,
199
+ };
192
200
  }
193
- // Any non-index token (words, or an out-of-range number like "13" for three
194
- // options) means the user typed an answer, not a selection. Preserve it
195
- // verbatim as a custom answer instead of silently dropping their input —
196
- // this is also the multi-select "Type something." escape.
197
- return { questionIndex, question: q.question, kind: "custom", answer: trimmed };
201
+ // Preserve unparseable input verbatim as custom text rather than dropping it.
202
+ return { questionIndex, question: q.question, kind: "multi", answer: trimmed, selected: [] };
198
203
  }
@@ -25,7 +25,7 @@ export type QuestionnaireAction =
25
25
  | { kind: "tab_switch"; nextTab: number }
26
26
  | { kind: "confirm"; answer: QuestionAnswer; autoAdvanceTab?: number }
27
27
  | { kind: "toggle"; index: number }
28
- | { kind: "multi_confirm"; selected: string[]; autoAdvanceTab?: number }
28
+ | { kind: "multi_confirm"; selected: string[]; answer: string | null; autoAdvanceTab?: number }
29
29
  | { kind: "cancel" }
30
30
  | { kind: "notes_enter" }
31
31
  | { kind: "notes_exit" }
@@ -116,6 +116,15 @@ function buildMultiSelected(state: QuestionnaireState, runtime: QuestionnaireRun
116
116
  return out;
117
117
  }
118
118
 
119
+ function buildMultiConfirmAction(state: QuestionnaireState, runtime: QuestionnaireRuntime): QuestionnaireAction {
120
+ return {
121
+ kind: "multi_confirm",
122
+ selected: buildMultiSelected(state, runtime),
123
+ answer: runtime.inputBuffer.trim().length > 0 ? runtime.inputBuffer : null,
124
+ autoAdvanceTab: computeAutoAdvanceTab(state, runtime),
125
+ };
126
+ }
127
+
119
128
  function tabSwitchAction(
120
129
  data: string,
121
130
  state: QuestionnaireState,
@@ -175,6 +184,8 @@ function routeInputMode(
175
184
  // the same physical key to both semantic actions.
176
185
  if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "ignore" };
177
186
  if (isConfirm(kb, data)) {
187
+ const q = runtime.questions[state.currentTab];
188
+ if (q?.multiSelect) return buildMultiConfirmAction(state, runtime);
178
189
  const answer = buildSingleSelectAnswer(state, runtime);
179
190
  if (!answer) return { kind: "ignore" };
180
191
  return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
@@ -241,24 +252,15 @@ function routeMultiSelectTab(
241
252
  return { kind: "toggle", index: state.optionIndex };
242
253
  }
243
254
  if (isConfirm(kb, data)) {
244
- // Enter on the "Type something." row is handled by the inputMode block above
245
- // (→ confirm kind:"custom"). Defensive: never enter the toggle/multi_confirm
246
- // path for an inputMode-activating row.
255
+ // Enter on the "Type something." row is handled by the inputMode block above.
256
+ // Defensive: never enter the toggle/multi_confirm path for an input-mode row.
247
257
  if (focusedMeta?.activatesInputMode) return { kind: "ignore" };
248
258
  // Enter on a regular row toggles (matching Space) — committing the question is now
249
259
  // gated behind explicit focus on a row whose META declares `autoSubmitsInMulti`
250
260
  // (the Next sentinel), so Enter on options is a no-cost way to flip checkboxes
251
261
  // without leaving the keyboard home row.
252
262
  if (!focusedMeta?.autoSubmitsInMulti) return { kind: "toggle", index: state.optionIndex };
253
- // Enter on Next: carry autoAdvanceTab so the host can advance to the next tab in
254
- // multi-question mode, OR submit the dialog in single-question mode
255
- // (autoAdvanceTab === undefined when !isMulti). Without this, a single multi-select
256
- // question would have no way to commit at all.
257
- return {
258
- kind: "multi_confirm",
259
- selected: buildMultiSelected(state, runtime),
260
- autoAdvanceTab: computeAutoAdvanceTab(state, runtime),
261
- };
263
+ return buildMultiConfirmAction(state, runtime);
262
264
  }
263
265
  if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "cancel" };
264
266
  return { kind: "ignore" };
@@ -13,6 +13,7 @@ function emptyMultiSelectProps(ctx: PerTabBindingContext): MultiSelectViewProps
13
13
  rows: [],
14
14
  other: {
15
15
  active: false,
16
+ checked: false,
16
17
  inputMode: false,
17
18
  inputBuffer: ctx.inputBuffer,
18
19
  inputCursorOffset: ctx.inputCursorOffset,
@@ -46,6 +47,7 @@ export const selectMultiSelectProps: PerTabSelector<MultiSelectViewProps> = (sta
46
47
  rows,
47
48
  other: {
48
49
  active: otherActive,
50
+ checked: ctx.inputBuffer.trim().length > 0,
49
51
  inputMode: state.inputMode,
50
52
  inputBuffer: ctx.inputBuffer,
51
53
  inputCursorOffset: ctx.inputCursorOffset,
@@ -63,15 +63,22 @@ function syncMultiSelectFromAnswers(
63
63
  return indices;
64
64
  }
65
65
 
66
+ function selectedLabels(state: QuestionnaireState, question: QuestionData): string[] {
67
+ const selected: string[] = [];
68
+ for (let i = 0; i < question.options.length; i++) {
69
+ if (state.multiSelectChecked.has(i)) selected.push(question.options[i]!.label);
70
+ }
71
+ return selected;
72
+ }
73
+
66
74
  function persistMultiSelectAnswer(state: QuestionnaireState, ctx: ApplyContext): ReadonlyMap<number, QuestionAnswer> {
67
75
  const q = ctx.questions[state.currentTab];
68
76
  if (!q?.multiSelect) return state.answers;
69
- const selected: string[] = [];
70
- for (let i = 0; i < q.options.length; i++) {
71
- if (state.multiSelectChecked.has(i)) selected.push(q.options[i]!.label);
72
- }
77
+ const selected = selectedLabels(state, q);
78
+ const custom = customDraftValueFor(state, state.currentTab);
79
+ const hasCustom = custom.trim().length > 0;
73
80
  const out = new Map(state.answers);
74
- if (selected.length === 0) {
81
+ if (selected.length === 0 && !hasCustom) {
75
82
  out.delete(state.currentTab);
76
83
  return out;
77
84
  }
@@ -80,7 +87,7 @@ function persistMultiSelectAnswer(state: QuestionnaireState, ctx: ApplyContext):
80
87
  questionIndex: state.currentTab,
81
88
  question: q.question,
82
89
  kind: "multi",
83
- answer: null,
90
+ answer: hasCustom ? custom : null,
84
91
  selected,
85
92
  ...(pendingNotes && pendingNotes.length > 0 ? { notes: pendingNotes } : {}),
86
93
  });
@@ -100,7 +107,8 @@ function customDraftValueFor(state: QuestionnaireState, tab: number): string {
100
107
  const draft = state.customDraftsByTab.get(tab);
101
108
  if (draft !== undefined) return draft;
102
109
  const answer = state.answers.get(tab);
103
- return answer?.kind === "custom" && typeof answer.answer === "string" ? answer.answer : "";
110
+ if (answer?.kind !== "custom" && answer?.kind !== "multi") return "";
111
+ return typeof answer.answer === "string" ? answer.answer : "";
104
112
  }
105
113
 
106
114
  function setCustomDraft(state: QuestionnaireState, tab: number, value: string): ReadonlyMap<number, string> {
@@ -170,7 +178,10 @@ const navHandler: Handler<"nav"> = (state, action, ctx) => {
170
178
  const customDraftsByTab = state.inputMode
171
179
  ? setCustomDraft(state, state.currentTab, action.inputValue)
172
180
  : state.customDraftsByTab;
173
- const next: QuestionnaireState = { ...state, optionIndex: action.nextIndex, inputMode, customDraftsByTab };
181
+ let next: QuestionnaireState = { ...state, optionIndex: action.nextIndex, inputMode, customDraftsByTab };
182
+ if (state.inputMode && !inputMode && ctx.questions[state.currentTab]?.multiSelect) {
183
+ next = { ...next, answers: persistMultiSelectAnswer(next, ctx) };
184
+ }
174
185
  if (!inputMode) return { state: next, effects: [] };
175
186
  return {
176
187
  state: next,
@@ -195,8 +206,10 @@ const tabSwitchHandler: Handler<"tab_switch"> = (state, action, ctx) => switchTa
195
206
 
196
207
  const confirmHandler: Handler<"confirm"> = (state, action, ctx) => {
197
208
  let answer = action.answer;
198
- if (answer.kind === "option" && answer.answer) {
199
- const q = ctx.questions[answer.questionIndex];
209
+ const q = ctx.questions[answer.questionIndex];
210
+ if (answer.kind === "custom" && q?.multiSelect) {
211
+ answer = { ...answer, kind: "multi", selected: selectedLabels(state, q) };
212
+ } else if (answer.kind === "option" && answer.answer) {
200
213
  const matched = q?.options.find((o) => o.label === answer.answer);
201
214
  if (matched?.preview && matched.preview.length > 0) {
202
215
  answer = { ...answer, preview: matched.preview };
@@ -208,17 +221,14 @@ const confirmHandler: Handler<"confirm"> = (state, action, ctx) => {
208
221
  }
209
222
  const answers = new Map(state.answers);
210
223
  answers.set(answer.questionIndex, answer);
211
- // Custom free-text on a multi-select tab is mutually exclusive with checkbox selections:
212
- // clear the checked set immediately so [✔] glyphs vanish on Enter. (A custom answer
213
- // carries no `selected` array, so syncMultiSelectFromAnswers keeps it empty on tab-back.)
214
- const isCustomMulti = answer.kind === "custom" && ctx.questions[answer.questionIndex]?.multiSelect === true;
215
- const customDraftsByTab =
216
- answer.kind === "custom" ? withoutCustomDraft(state, answer.questionIndex) : state.customDraftsByTab;
224
+ const hasCustomAnswer = answer.kind === "custom" || (answer.kind === "multi" && answer.answer !== null);
225
+ const customDraftsByTab = hasCustomAnswer
226
+ ? withoutCustomDraft(state, answer.questionIndex)
227
+ : state.customDraftsByTab;
217
228
  const next: QuestionnaireState = {
218
229
  ...state,
219
230
  answers,
220
231
  customDraftsByTab,
221
- ...(isCustomMulti ? { multiSelectChecked: new Set<number>() } : {}),
222
232
  };
223
233
  if (action.autoAdvanceTab !== undefined) return switchTabResult(next, action.autoAdvanceTab, ctx);
224
234
  return doneFor(next, ctx, false);
@@ -242,13 +252,14 @@ const multiConfirmHandler: Handler<"multi_confirm"> = (state, action, ctx) => {
242
252
  questionIndex: state.currentTab,
243
253
  question: q.question,
244
254
  kind: "multi",
245
- answer: null,
255
+ answer: action.answer,
246
256
  selected: action.selected,
247
257
  ...(pendingNotes && pendingNotes.length > 0 ? { notes: pendingNotes } : {}),
248
258
  });
249
259
  const synced: QuestionnaireState = {
250
260
  ...state,
251
261
  answers,
262
+ customDraftsByTab: withoutCustomDraft(state, state.currentTab),
252
263
  multiSelectChecked: syncMultiSelectFromAnswers(answers, ctx.questions, state.currentTab),
253
264
  };
254
265
  if (action.autoAdvanceTab !== undefined) return switchTabResult(synced, action.autoAdvanceTab, ctx);
@@ -19,8 +19,11 @@ export type FormatAnswerVariant = "summary" | "envelope";
19
19
  */
20
20
  export function formatAnswerScalar(a: QuestionAnswer, _variant: FormatAnswerVariant): string {
21
21
  switch (a.kind) {
22
- case "multi":
23
- return a.selected && a.selected.length > 0 ? a.selected.join(", ") : NO_INPUT_PLACEHOLDER;
22
+ case "multi": {
23
+ const values = [...(a.selected ?? [])];
24
+ if (a.answer && a.answer.length > 0) values.push(a.answer);
25
+ return values.length > 0 ? values.join(", ") : NO_INPUT_PLACEHOLDER;
26
+ }
24
27
  case "custom":
25
28
  return a.answer && a.answer.length > 0 ? a.answer : NO_INPUT_PLACEHOLDER;
26
29
  case "option":
package/tool/types.ts CHANGED
@@ -100,8 +100,9 @@ export type QuestionParams = Static<typeof QuestionParamsSchema>;
100
100
  *
101
101
  * Variant semantics:
102
102
  * - `option`: user picked one of the author-defined options. `answer` is the option's label.
103
- * - `custom`: user typed free-text via the "Type something." row. `answer` is the typed text or null.
104
- * - `multi`: user committed multi-select choices. `selected` carries chosen labels; `answer` is null.
103
+ * - `custom`: user typed free-text on a single-select question. `answer` is the typed text or null.
104
+ * - `multi`: user committed a multi-select question. `selected` carries chosen labels and `answer`
105
+ * carries optional custom text.
105
106
  */
106
107
  export interface QuestionAnswer {
107
108
  questionIndex: number;
@@ -20,6 +20,8 @@ export const MULTI_SUBMIT_LABEL = "Submit";
20
20
  export interface MultiSelectOtherRowProps {
21
21
  /** The "Type something." row is the focused row (optionIndex === options.length). */
22
22
  active: boolean;
23
+ /** Non-empty custom text counts as a selected multi-value. */
24
+ checked: boolean;
23
25
  /** `state.inputMode` — true once the row has focus and keystrokes append to the buffer. */
24
26
  inputMode: boolean;
25
27
  /** Live inline-input buffer (read from `runtime.inputBuffer` / `ctx.inputBuffer`). */
@@ -66,7 +68,7 @@ export class MultiSelectView implements StatefulView<MultiSelectViewProps> {
66
68
  ) {
67
69
  this.props = {
68
70
  rows: [],
69
- other: { active: false, inputMode: false, inputBuffer: "", inputCursorOffset: undefined },
71
+ other: { active: false, checked: false, inputMode: false, inputBuffer: "", inputCursorOffset: undefined },
70
72
  nextActive: false,
71
73
  nextLabel: displayLabel("next"),
72
74
  };
@@ -152,7 +154,7 @@ export class MultiSelectView implements StatefulView<MultiSelectViewProps> {
152
154
  private renderOtherRow(contentWidth: number, numberWidth: number): string[] {
153
155
  const other = this.props.other;
154
156
  const pointer = other.active ? this.theme.fg("accent", ACTIVE_POINTER) : INACTIVE_POINTER;
155
- const box = this.theme.fg("muted", UNCHECKED);
157
+ const box = other.checked ? this.theme.fg("accent", CHECKED) : this.theme.fg("muted", UNCHECKED);
156
158
  const number = String(this.question.options.length + 1).padStart(numberWidth, " ");
157
159
  const rowPrefix = `${pointer}${number}${NUMBER_SEPARATOR}${box}${BOX_LABEL_GAP}`;
158
160
  const continuationPrefix = " ".repeat(visibleWidth(rowPrefix));