@juicesharp/rpiv-ask-user-question 1.20.0 → 2.1.0

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.
Files changed (44) hide show
  1. package/README.md +68 -86
  2. package/ask-user-question.ts +193 -32
  3. package/config.ts +65 -4
  4. package/docs/configuration.md +112 -0
  5. package/docs/hosts.md +87 -0
  6. package/docs/keyboard.md +87 -0
  7. package/docs/localization.md +83 -0
  8. package/docs/tool-schema.md +121 -0
  9. package/events.ts +12 -0
  10. package/index.ts +6 -1
  11. package/locales/de.json +3 -3
  12. package/locales/en.json +3 -3
  13. package/locales/es.json +3 -3
  14. package/locales/fr.json +3 -3
  15. package/locales/pt-BR.json +3 -3
  16. package/locales/pt.json +3 -3
  17. package/locales/ru.json +3 -3
  18. package/locales/uk.json +3 -3
  19. package/locales/zh.json +3 -3
  20. package/package.json +11 -5
  21. package/reconcile.ts +47 -0
  22. package/rpc-fallback.ts +166 -0
  23. package/state/build-questionnaire.ts +0 -10
  24. package/state/key-router.ts +45 -62
  25. package/state/questionnaire-session.ts +41 -11
  26. package/state/row-intent.ts +21 -37
  27. package/state/selectors/derivations.ts +3 -54
  28. package/state/selectors/focus.ts +3 -5
  29. package/state/selectors/projections.ts +28 -13
  30. package/state/state-reducer.ts +31 -36
  31. package/state/state.ts +6 -3
  32. package/tool/format-answer.ts +6 -24
  33. package/tool/types.ts +13 -16
  34. package/view/components/inline-input.ts +96 -0
  35. package/view/components/multi-select-view.ts +62 -6
  36. package/view/components/option-list-view.ts +1 -4
  37. package/view/components/preview/preview-layout-decider.ts +4 -3
  38. package/view/components/preview/preview-pane.ts +22 -1
  39. package/view/components/wrapping-select.ts +19 -58
  40. package/view/dialog-builder.ts +13 -11
  41. package/view/props-adapter.ts +2 -2
  42. package/view/stateful-view.ts +6 -7
  43. package/view/tab-content-strategy.ts +16 -18
  44. package/view/components/chat-row-view.ts +0 -56
@@ -0,0 +1,112 @@
1
+ # Configuration
2
+
3
+ Every setting the package reads, where the file lives, and what happens when a value is
4
+ wrong.
5
+
6
+ ## The config file
7
+
8
+ ```
9
+ ~/.config/rpiv-ask-user-question/config.json
10
+ ```
11
+
12
+ The file is optional — with no config at all, every setting takes its default. This
13
+ package only ever *reads* the file; it never creates, writes or chmods it, so its
14
+ permissions are whatever you give it.
15
+
16
+ A complete example:
17
+
18
+ ```json
19
+ {
20
+ "collapseKey": "alt+o",
21
+ "guidance": {
22
+ "promptSnippet": "Ask me before guessing on anything ambiguous",
23
+ "promptGuidelines": [
24
+ "Batch every clarifying question into one ask_user_question call.",
25
+ "Put your recommended option first and suffix it with (Recommended)."
26
+ ]
27
+ }
28
+ }
29
+ ```
30
+
31
+ ### Where the file is looked up
32
+
33
+ 1. `$XDG_CONFIG_HOME/rpiv-ask-user-question/config.json`, if `XDG_CONFIG_HOME` is set,
34
+ non-empty and absolute. A leading `~` is expanded first; a relative value is ignored.
35
+ Unset or ignored, the directory falls back to `~/.config`.
36
+ 2. If that file does not exist, the legacy path `~/.config/rpiv-ask-user-question/config.json`
37
+ is read. This path deliberately ignores `XDG_CONFIG_HOME`, so an existing config keeps
38
+ working after you set the variable.
39
+ 3. Neither present: all defaults.
40
+
41
+ If the XDG-path file exists, its result wins even when it is malformed — there is no
42
+ second chance at the legacy path.
43
+
44
+ ### When the file is invalid
45
+
46
+ Malformed JSON is not fatal. The loader warns on stderr and continues with defaults:
47
+
48
+ ```
49
+ rpiv-config: invalid JSON at <path>, using default ({}) — <parser message>
50
+ ```
51
+
52
+ Valid JSON that is not an object (a string, number, `null`, or an array) is rejected too,
53
+ falling back to defaults — but silently, with no warning. Individual keys with the wrong
54
+ type are likewise dropped back to their default without a warning.
55
+
56
+ ## Settings
57
+
58
+ | Setting | What it does | Default |
59
+ | --- | --- | --- |
60
+ | `collapseKey` | Key that collapses and expands the dialog overlay. | `"ctrl+]"` |
61
+ | `guidance.promptSnippet` | One-line snippet describing the tool in the system prompt. | built-in snippet |
62
+ | `guidance.promptGuidelines` | List of usage guidelines given to the model. | 4 built-in guidelines |
63
+
64
+ ### `collapseKey`
65
+
66
+ The value uses Pi's keybinding id format: zero or more distinct modifiers from `ctrl`,
67
+ `shift`, `alt`, `super`, joined by `+`, followed by a base key. Values are trimmed and
68
+ lowercased before matching.
69
+
70
+ The base key is either a single printable character from
71
+ `a-z 0-9 _ - ! @ # $ % ^ & * ( ) | ~ \` ' " : ; , . / < > ? [ ] { } = \`, or one of the
72
+ named keys `escape`, `esc`, `enter`, `return`, `tab`, `space`, `backspace`, `delete`,
73
+ `insert`, `clear`, `home`, `end`, `pageup`, `pagedown`, `up`, `down`, `left`, `right`,
74
+ `f1`–`f12`.
75
+
76
+ Examples that work: `"ctrl+]"`, `"alt+o"`, `"ctrl+shift+h"`, `"f9"`, `"ctrl+}"`.
77
+
78
+ Set `"off"` (any casing) to disable the collapse shortcut entirely — no raw terminal
79
+ listener is registered in that case.
80
+
81
+ A spec that does not match the grammar is rejected and the default is used. This is
82
+ strict on purpose: Pi's parser takes the last `+`-separated part as the key and ignores
83
+ unknown parts, so a typo like `"ctr+]"` would otherwise silently capture every bare `]`
84
+ keypress at the terminal level.
85
+
86
+ One known rough edge: the footer hint line inside the dialog always reads `Ctrl+] to
87
+ collapse` and does not interpolate a custom `collapseKey`. The one-shot notification you
88
+ get when the dialog first collapses *does* name your configured key.
89
+
90
+ ### `guidance.promptSnippet` and `guidance.promptGuidelines`
91
+
92
+ These replace the text Pi puts in the system prompt about when to reach for
93
+ `ask_user_question`. Use them to make the model ask more or less often, or to enforce a
94
+ house style for options.
95
+
96
+ `promptSnippet` is used only when it is a non-empty string. `promptGuidelines` is used
97
+ only when it is a non-empty array whose entries are all non-empty strings. Anything else
98
+ falls back to the built-in defaults. Both are read once, when the extension registers the
99
+ tool, so changes take effect on the next Pi restart.
100
+
101
+ ## Environment variables
102
+
103
+ | Variable | Effect |
104
+ | --- | --- |
105
+ | `XDG_CONFIG_HOME` | Relocates the config directory, as described above. Must be absolute. |
106
+
107
+ `LANG` and `LC_ALL` influence the dialog language, but they are read by
108
+ [`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n) rather than
109
+ by this package — see [localization.md](./localization.md).
110
+
111
+ No other environment variables are read. The package makes no model calls, so it needs no
112
+ API keys or model settings of its own.
package/docs/hosts.md ADDED
@@ -0,0 +1,87 @@
1
+ # Hosts and runtime behavior
2
+
3
+ Where the questionnaire renders, what it degrades to, and what happens when it cannot
4
+ render at all.
5
+
6
+ ## Three environments
7
+
8
+ | Environment | What the model sees | What you see |
9
+ | --- | --- | --- |
10
+ | Interactive terminal | `ask_user_question` in its tool list | The full tabbed TUI overlay |
11
+ | RPC / ACP host (VS Code pendant, Zed, Paseo) | `ask_user_question` in its tool list | A sequence of the host's own native select and input dialogs |
12
+ | Non-interactive run (no UI) | Nothing — the tool is removed | Nothing |
13
+
14
+ ### Non-interactive runs
15
+
16
+ A `before_agent_start` hook reconciles the active tool set against `ctx.hasUI` before every
17
+ turn. When there is no UI, `ask_user_question` is stripped from the list so the model never
18
+ sees a tool it cannot use — better than offering it and auto-declining every call. When UI
19
+ comes back, the tool is restored. The reconciler is idempotent and leaves sibling tools
20
+ untouched.
21
+
22
+ A second guard lives inside the tool handler as a one-turn backstop: if a call somehow
23
+ arrives without UI, it returns `error: "no_ui"` and the text
24
+ `Error: UI not available (running in non-interactive mode)`.
25
+
26
+ ### RPC and ACP hosts
27
+
28
+ RPC hosts report `hasUI: true` because Pi's dialog sub-protocol works there, but custom
29
+ terminal UI does not render. The package detects this two ways: hosts that advertise
30
+ `ctx.mode === "rpc"` route straight to the dialog walker, skipping the TUI import
31
+ entirely, and older RPC builds are caught by a backstop when custom UI resolves without
32
+ rendering anything. Either path requires the host to expose both `select` and `input`.
33
+
34
+ The walker asks one question per dialog and returns exactly the same result envelope the
35
+ TUI produces. Trade-offs inherent to the native primitives:
36
+
37
+ - No side-by-side preview pane. Previews are folded into the dialog title instead,
38
+ truncated at 600 characters each.
39
+ - No tab bar and no Submit review tab — one dialog per question, in order.
40
+ - Multi-select is a free-text input: type the option numbers, comma-separated
41
+ (`1,3`). Any token that is not a valid option index is treated as a typed custom answer,
42
+ which is how the `Type something.` escape survives. An empty input commits an empty
43
+ selection, matching `Next` with nothing toggled.
44
+ - Dismissing any dialog cancels the whole questionnaire, mirroring `Esc` in the TUI.
45
+
46
+ If the host can render neither custom UI nor dialogs, the call returns
47
+ `error: "no_custom_ui"` with text telling the model the user never saw the questions and
48
+ that it should ask them as plain chat text instead — explicitly not a decline.
49
+
50
+ ## Conditional surfaces
51
+
52
+ Some parts of the dialog exist only under the right conditions:
53
+
54
+ | Surface | Appears when |
55
+ | --- | --- |
56
+ | Tab bar and Submit tab | The call carries more than one question |
57
+ | `Next` row | The question is multi-select |
58
+ | `Type something.` row | Always |
59
+ | Side-by-side preview | An option carries a `preview`, and terminal and pane are both ≥ 100 columns |
60
+ | Preview pane at all | Single-select questions only |
61
+ | Collapse shortcut | `collapseKey` is not `"off"` and the host exposes raw terminal input |
62
+ | Localized chrome | `@juicesharp/rpiv-i18n` is installed |
63
+
64
+ ## Loading and startup cost
65
+
66
+ The dialog's render graph costs roughly 560 ms to import, so it is loaded lazily — on the
67
+ first tool call, not when the extension registers. To keep that first call fast and safe,
68
+ the graph is also pre-warmed in the background two seconds after startup. The pre-warm
69
+ timer is unref'd, so it never holds a process open, and a failed pre-warm is swallowed:
70
+ the first real call re-imports and reports properly.
71
+
72
+ The pre-warm exists for a specific failure. Pi's module loader registers a module in its
73
+ graph cache *before* evaluating it and does not evict it if evaluation throws. If your
74
+ package manager replaces the dependency store while Pi is running, one failed import can
75
+ poison the cache for the rest of the process. Evaluating the graph early, while the paths
76
+ Pi resolved at boot still exist, keeps it in memory for the process lifetime and makes
77
+ that unreachable.
78
+
79
+ When it does happen, you get a structured envelope rather than a raw `TypeError`:
80
+
81
+ | `error` | Meaning | Fix |
82
+ | --- | --- | --- |
83
+ | `session_load_failed` | The dialog module could not be imported. | Repair the install if needed, then restart Pi. |
84
+ | `stale_module_cache` | The module cache went stale after an earlier failed import. | Restart Pi — this is unrecoverable in the running process. |
85
+
86
+ Both messages tell the model the questions were never shown and to ask them as plain chat
87
+ text instead of treating the failure as a decline.
@@ -0,0 +1,87 @@
1
+ # Keyboard and dialog layout
2
+
3
+ Every key the questionnaire dialog reacts to, the rows it appends for you, and how it
4
+ adapts to the size of your terminal.
5
+
6
+ ## Keys
7
+
8
+ | Key | What it does | Where it applies |
9
+ | --- | --- | --- |
10
+ | `↑` / `↓` | Move between rows. Wraps at both ends. | Option list, Submit picker |
11
+ | `Enter` | Confirm the focused option, commit typed text, or activate the focused Submit-picker row. | Everywhere |
12
+ | `Esc` | Cancel the whole questionnaire. | Everywhere except the notes editor, where it closes notes |
13
+ | `Tab` / `Shift+Tab` | Next / previous tab, wrapping. `→` / `←` do the same. | Multi-question dialogs only |
14
+ | `Space` | Toggle the focused checkbox. | Multi-select questions |
15
+ | `n` | Open the notes editor for the current question. | Every question tab |
16
+ | `Ctrl+]` | Collapse or expand the dialog. Configurable via `collapseKey`. | Everywhere, including while collapsed |
17
+
18
+ In a multi-select question, `Enter` on a regular row toggles its checkbox exactly like
19
+ `Space` — it does not submit. Committing the question means focusing the `Next` row and
20
+ pressing `Enter`. That is deliberate: it makes `Enter` a zero-cost way to flip boxes
21
+ without leaving the home row.
22
+
23
+ `Space` is suppressed on two rows: `Next` (it is a command, not a choice) and
24
+ `Type something.` (it is an inline text input, so the space character belongs to your
25
+ answer).
26
+
27
+ ## The rows the dialog adds
28
+
29
+ | Row | Label | Appended to |
30
+ | --- | --- | --- |
31
+ | Custom answer | `Type something.` | Every question — single-select and multi-select, with or without previews |
32
+ | Commit | `Next` | Multi-select questions only |
33
+
34
+ Focusing `Type something.` switches the row into an inline text input. In preview mode it
35
+ expands to the full pane width while you type, so a long custom answer is not squeezed
36
+ into the narrow options column. Confirming it produces an answer of `kind: "custom"`.
37
+
38
+ Both labels are reserved — the model cannot author an option that collides with them.
39
+ Both localize with the rest of the UI chrome; the reserved-label check always compares
40
+ against the canonical English strings.
41
+
42
+ ## Notes
43
+
44
+ `n` opens a notes editor on any question tab, whether the question is single- or
45
+ multi-select and whether or not its options carry previews. Notes are stored in a
46
+ side-band keyed by tab index, not inside the answer, so writing a note does not mark a
47
+ question as answered — the Submit tab still lists it as outstanding. The note merges into
48
+ the answer when you confirm it, and reaches the model as `user notes: <text>`.
49
+
50
+ Inside the editor, `Esc` and `Enter` both close it and every other keystroke goes to the
51
+ text buffer, so `n` types an `n`.
52
+
53
+ ## Collapse mode
54
+
55
+ `Ctrl+]` gets the dialog out of the way: the overlay is marked hidden in Pi's overlay
56
+ stack and shrinks to a single dim hint row, so the transcript it was covering becomes
57
+ readable and chat scrolling resumes. Press the same key to bring the questionnaire back
58
+ with your answers intact. The first time you collapse, Pi notifies you with the key to
59
+ press — that message names your configured key.
60
+
61
+ Because Pi routes no input to a hidden overlay, the collapse key is additionally captured
62
+ at the raw terminal level. It only acts when the questionnaire is hidden or focused, so a
63
+ different overlay on top of it (for example `/btw`) keeps its keystrokes.
64
+
65
+ While collapsed, every keystroke other than cancel is ignored, so you cannot mutate
66
+ answers you cannot see.
67
+
68
+ The default `ctrl+]` is free in Terminal.app, iTerm2, Warp, tmux, zellij and screen. On
69
+ keyboard layouts where `]` sits on the shifted layer — Latin American `es-AR` / `es-MX`,
70
+ among others — set a different `collapseKey`, or `"off"` to disable the shortcut.
71
+
72
+ ## Layout
73
+
74
+ Options render in a vertical list. When any option in a single-select question carries a
75
+ `preview`, the dialog splits into a side-by-side layout with the option list on the left
76
+ and a bordered monospace preview box on the right — but only when both the terminal and
77
+ the dialog pane are at least 100 columns wide. Below that, the preview stacks underneath
78
+ the options instead.
79
+
80
+ When the dialog is taller than the terminal, the body scrolls between a sticky heading and
81
+ a sticky footer, and an overflow indicator shows which direction is clipped: `↑` for
82
+ content above, `↓` for content below, `↕` for both.
83
+
84
+ The footer hint line adapts to context — it drops the notes hint while the notes editor or
85
+ the inline input has the keyboard, and adds the tab hint only in multi-question dialogs.
86
+ On narrow terminals the collapse hint at the end of the line clips with `…` so the core
87
+ hints survive.
@@ -0,0 +1,83 @@
1
+ # Localization
2
+
3
+ How the dialog picks its language, which languages ship, and how to add one.
4
+
5
+ ## Enabling it
6
+
7
+ The extension works standalone: install only this package and you get the full dialog in
8
+ English. Localization needs one more install:
9
+
10
+ ```sh
11
+ pi install npm:@juicesharp/rpiv-i18n
12
+ ```
13
+
14
+ Restart your Pi session. If you installed through
15
+ [`@juicesharp/rpiv-pi`](https://www.npmjs.com/package/@juicesharp/rpiv-pi) and ran
16
+ `/rpiv-setup`, you already have it.
17
+
18
+ The dependency is a genuinely optional peer. This package loads the SDK inside a
19
+ `try`/`catch` at startup; when it is absent, every string falls back to its inline English
20
+ literal at the call site. There is no warning and no crash — the dialog simply renders in
21
+ English.
22
+
23
+ ## Picking a language
24
+
25
+ With the SDK installed, the locale resolves in this order, first hit wins:
26
+
27
+ 1. `pi --locale <code>` on the command line
28
+ 2. `~/.config/rpiv-i18n/locale.json`
29
+ 3. `LANG` / `LC_ALL` from the environment
30
+ 4. English
31
+
32
+ `/languages` opens an interactive picker and flips the strings live — the dialog reads its
33
+ strings at render time, so an open questionnaire follows the change. Both `/languages` and
34
+ `--locale` are registered by `@juicesharp/rpiv-i18n`, not by this package.
35
+
36
+ ## Shipped languages
37
+
38
+ Nine locale files ship in `locales/`:
39
+
40
+ | Code | Language |
41
+ | --- | --- |
42
+ | `de` | Deutsch |
43
+ | `en` | English |
44
+ | `es` | Español |
45
+ | `fr` | Français |
46
+ | `pt` | Português |
47
+ | `pt-BR` | Português (Brasil) |
48
+ | `ru` | Русский |
49
+ | `uk` | Українська |
50
+ | `zh` | 中文 |
51
+
52
+ ## What is translated, and what is not
53
+
54
+ Translation covers the chrome you read: the `Type something.` and `Next` sentinel rows,
55
+ the footer hint segments (including the collapsed-state line), the Submit picker labels,
56
+ the review-tab heading with its submit-readiness prompt and incomplete-answers warning, the
57
+ preview pane's empty and notes-affordance lines, the notes header, and the two RPC dialog
58
+ prompts. Twenty keys in total, all under the namespace
59
+ `@juicesharp/rpiv-ask-user-question`.
60
+
61
+ Everything the *model* reads stays English by design: the tool description, the parameter
62
+ schema descriptions, error messages, and the reserved-label list. Those are prompt inputs,
63
+ not UI, and translating them would change model behavior rather than your reading
64
+ experience. It also means reserved-label validation compares against fixed English
65
+ strings, so `Type something.` is rejected as an authored option label in every locale.
66
+
67
+ ## Adding a language
68
+
69
+ No code change is required.
70
+
71
+ 1. Copy `locales/en.json` to `locales/<code>.json`, where `<code>` is a locale the SDK
72
+ supports.
73
+ 2. Translate the values. Keep every key, and keep the placeholders and leading symbols
74
+ (`↑/↓`, `⚠`) intact.
75
+ 3. Restart Pi and select the language with `/languages`.
76
+
77
+ The loader iterates the SDK's supported-locale list over this directory at startup, so a
78
+ new file is picked up automatically. See the
79
+ [`@juicesharp/rpiv-i18n`](https://www.npmjs.com/package/@juicesharp/rpiv-i18n) README,
80
+ section "Contributing translations", for the full convention.
81
+
82
+ Keys are looked up individually with an English fallback, so a partially translated file
83
+ is safe — untranslated keys render in English rather than blank.
@@ -0,0 +1,121 @@
1
+ # Tool schema
2
+
3
+ The complete programmatic surface of `ask_user_question`: what the model sends, what
4
+ validation rejects, what comes back, and the event other extensions can listen to.
5
+
6
+ ## Parameters
7
+
8
+ ```ts
9
+ ask_user_question({
10
+ questions: [
11
+ {
12
+ question: string, // full question text, ends with "?"
13
+ header: string, // chip label, max 16 chars
14
+ options: [
15
+ {
16
+ label: string, // 1-5 words, max 60 chars
17
+ description: string, // what the choice means / its trade-off
18
+ preview?: string, // markdown rendered next to the options
19
+ },
20
+ // … 2-4 options total
21
+ ],
22
+ multiSelect?: boolean, // default false
23
+ },
24
+ // … 1-4 questions total
25
+ ]
26
+ })
27
+ ```
28
+
29
+ ### Limits
30
+
31
+ | Field | Constraint | Enforced by |
32
+ | --- | --- | --- |
33
+ | `questions` | 1-4 entries | TypeBox schema + `validateQuestionnaire` |
34
+ | `questions[].header` | max 16 characters | TypeBox schema only |
35
+ | `questions[].options` | 2-4 entries | TypeBox schema (both bounds) + `validateQuestionnaire` (minimum only) |
36
+ | `options[].label` | max 60 characters | TypeBox schema only |
37
+ | `options[].preview` | single-select questions only | tool description (multi-select tabs render checkbox rows) |
38
+
39
+ The two `maxLength` limits are checked by the parameter schema before `execute` runs;
40
+ the runtime validator does not re-check them.
41
+
42
+ ### Reserved option labels
43
+
44
+ Authoring any of `"Other"`, `"Type something."`, or `"Next"` as an option label is
45
+ rejected with `reserved_label`. The last two are the runtime sentinel rows the dialog
46
+ appends itself; `"Other"` is reserved because models are conditioned to reach for it.
47
+ Reservation is unconditional — a single-select question rejects `"Next"` even though
48
+ that row is never appended there.
49
+
50
+ ## Validation errors
51
+
52
+ Every rejection returns `cancelled: true`, an empty `answers` array, and an `error`
53
+ code. The `content[0].text` string is written for the model, not for a log.
54
+
55
+ | `error` | Cause |
56
+ | --- | --- |
57
+ | `no_questions` | `questions` was empty |
58
+ | `too_many_questions` | more than 4 questions in one call |
59
+ | `duplicate_question` | two questions with identical text |
60
+ | `empty_options` | a question carried fewer than 2 options |
61
+ | `reserved_label` | an option used a reserved label |
62
+ | `duplicate_option_label` | two options in one question share a label |
63
+ | `no_ui` | the run has no UI (`ctx.hasUI === false`) |
64
+ | `no_custom_ui` | the host cannot render custom UI and exposes no `select`/`input` dialogs |
65
+ | `session_load_failed` | the dialog module failed to import (dependencies changed on disk mid-session) |
66
+ | `stale_module_cache` | the loader cached a broken module after an earlier failed import; needs a Pi restart |
67
+
68
+ `reserved_label` short-circuits before `duplicate_option_label`.
69
+
70
+ ## Result
71
+
72
+ ```ts
73
+ {
74
+ content: [{ type: "text", text: string }], // envelope prose, or the decline message
75
+ details: {
76
+ answers: Array<{
77
+ questionIndex: number,
78
+ question: string,
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
82
+ notes?: string, // free-text note, when you wrote one
83
+ preview?: string, // echoed back when the chosen option carried a preview
84
+ }>,
85
+ cancelled: boolean,
86
+ error?: QuestionnaireError, // one of the codes above
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### Envelope text
92
+
93
+ On success the text reads `User has answered your questions: "<question>"="<answer>". …
94
+ You can now continue with the user's answers in mind.` A chosen option's `preview` is
95
+ appended as `selected preview: <markdown>`, and a note as `user notes: <text>`.
96
+
97
+ Cancelling, and any result that produces no answer segments, both collapse to the single
98
+ string `User declined to answer questions` so the model sees one canonical signal.
99
+ Partial submission is allowed: unanswered questions simply contribute no segment.
100
+
101
+ ## Event contract
102
+
103
+ The package publishes one event on Pi's event bus, emitted after validation passes and
104
+ before the dialog is shown. Import it from the `/events` subpath:
105
+
106
+ ```ts
107
+ import { ASK_USER_PROMPT_EVENT, type AskUserPromptEventPayload } from "@juicesharp/rpiv-ask-user-question/events";
108
+
109
+ pi.events.on(ASK_USER_PROMPT_EVENT, (payload: AskUserPromptEventPayload) => {
110
+ // payload.questions[].{ question, header, multiSelect, options[] }
111
+ // payload.questions[].options[].{ label, description, hasPreview }
112
+ });
113
+ ```
114
+
115
+ The channel name is `rpiv:ask-user:prompt`. Preview *content* is deliberately not shipped
116
+ in the payload — only `hasPreview: boolean` — so listeners forwarding the event across a
117
+ process or network boundary stay cheap.
118
+
119
+ Stability policy for the `rpiv:*` namespace: channel names are immutable, payload changes
120
+ are append-only and always optional, payloads stay JSON-safe, and any breaking change ships
121
+ as a new channel (e.g. `rpiv:ask-user:prompt.v2`) rather than a version field.
package/events.ts CHANGED
@@ -25,6 +25,18 @@ export interface AskUserPromptEventPayload {
25
25
  questions: ReadonlyArray<AskUserPromptQuestion>;
26
26
  }
27
27
 
28
+ /**
29
+ * Emitted while the questionnaire is awaiting user input (TUI `ui.custom` and
30
+ * RPC dialog walker). Cleared with `{ active: false }` in `finally` so listeners
31
+ * can distinguish blocked-on-human from working.
32
+ */
33
+ export const ASK_USER_BLOCKED_EVENT = "rpiv:ask-user:blocked" as const;
34
+
35
+ export interface AskUserBlockedEventPayload {
36
+ /** True while input is awaited; false when the wait ends (answer, cancel, or error). */
37
+ active: boolean;
38
+ }
39
+
28
40
  export interface AskUserPromptQuestion {
29
41
  /** The full question text, exactly as the agent authored it. */
30
42
  question: string;
package/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * rpiv-ask-user-question — Pi extension. Registers the `ask_user_question`
3
- * tool: a structured option selector with a free-text "Other" fallback.
3
+ * tool: a structured option selector with an automatically appended
4
+ * `Type something.` custom-answer row.
4
5
  *
5
6
  * Sentinel labels and TUI chrome strings localize at render time via the i18n
6
7
  * bridge. Strings are registered with rpiv-i18n here, once, at module init —
@@ -17,6 +18,7 @@
17
18
 
18
19
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
19
20
  import { registerAskUserQuestionTool } from "./ask-user-question.js";
21
+ import { registerAskUserQuestionReconciler } from "./reconcile.js";
20
22
  import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
21
23
 
22
24
  type I18nLoader = {
@@ -38,7 +40,9 @@ try {
38
40
  }
39
41
 
40
42
  export {
43
+ ASK_USER_BLOCKED_EVENT,
41
44
  ASK_USER_PROMPT_EVENT,
45
+ type AskUserBlockedEventPayload,
42
46
  type AskUserPromptEventPayload,
43
47
  type AskUserPromptOption,
44
48
  type AskUserPromptQuestion,
@@ -46,4 +50,5 @@ export {
46
50
 
47
51
  export default function (pi: ExtensionAPI) {
48
52
  registerAskUserQuestionTool(pi);
53
+ registerAskUserQuestionReconciler(pi);
49
54
  }
package/locales/de.json CHANGED
@@ -2,7 +2,6 @@
2
2
  "_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
3
3
 
4
4
  "sentinel.other": "Schreibe etwas.",
5
- "sentinel.chat": "Darüber chatten",
6
5
  "sentinel.next": "Weiter",
7
6
 
8
7
  "submit.label": "Antworten senden",
@@ -21,7 +20,8 @@
21
20
 
22
21
  "preview.no_preview": "Keine Vorschau verfügbar",
23
22
  "preview.notes_affordance": "Notizen: drücke n, um Notizen hinzuzufügen",
23
+ "notes.header": "Notizen:",
24
24
 
25
- "chat.summary": "Benutzer möchte darüber chatten",
26
- "notes.header": "Notizen:"
25
+ "rpc.multi_instructions": "Gib die Nummern aller zutreffenden Optionen durch Komma getrennt ein (z. B. \"1,3\") oder tippe eine eigene Antwort als Text.",
26
+ "rpc.custom_answer_title": "Gib deine Antwort ein:"
27
27
  }
package/locales/en.json CHANGED
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "sentinel.other": "Type something.",
3
- "sentinel.chat": "Chat about this",
4
3
  "sentinel.next": "Next",
5
4
 
6
5
  "submit.label": "Submit answers",
@@ -21,7 +20,8 @@
21
20
 
22
21
  "preview.no_preview": "No preview available",
23
22
  "preview.notes_affordance": "Notes: press n to add notes",
23
+ "notes.header": "Notes:",
24
24
 
25
- "chat.summary": "User wants to chat about this",
26
- "notes.header": "Notes:"
25
+ "rpc.multi_instructions": "Enter the numbers of all that apply, comma-separated (e.g. \"1,3\"), or type a custom answer as plain text.",
26
+ "rpc.custom_answer_title": "Type your answer:"
27
27
  }
package/locales/es.json CHANGED
@@ -2,7 +2,6 @@
2
2
  "_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
3
3
 
4
4
  "sentinel.other": "Escribe algo.",
5
- "sentinel.chat": "Conversar sobre esto",
6
5
  "sentinel.next": "Siguiente",
7
6
 
8
7
  "submit.label": "Enviar respuestas",
@@ -21,7 +20,8 @@
21
20
 
22
21
  "preview.no_preview": "Vista previa no disponible",
23
22
  "preview.notes_affordance": "Notas: pulsa n para añadir notas",
23
+ "notes.header": "Notas:",
24
24
 
25
- "chat.summary": "El usuario quiere conversar sobre esto",
26
- "notes.header": "Notas:"
25
+ "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.",
26
+ "rpc.custom_answer_title": "Escribe tu respuesta:"
27
27
  }
package/locales/fr.json CHANGED
@@ -2,7 +2,6 @@
2
2
  "_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
3
3
 
4
4
  "sentinel.other": "Écrivez quelque chose.",
5
- "sentinel.chat": "Discuter de ceci",
6
5
  "sentinel.next": "Suivant",
7
6
 
8
7
  "submit.label": "Envoyer les réponses",
@@ -21,7 +20,8 @@
21
20
 
22
21
  "preview.no_preview": "Aucun aperçu disponible",
23
22
  "preview.notes_affordance": "Notes : appuyez sur n pour ajouter des notes",
23
+ "notes.header": "Notes :",
24
24
 
25
- "chat.summary": "L'utilisateur souhaite discuter de ceci",
26
- "notes.header": "Notes :"
25
+ "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.",
26
+ "rpc.custom_answer_title": "Tapez votre réponse :"
27
27
  }
@@ -2,7 +2,6 @@
2
2
  "_meta.notes": "Auto-translated draft. Native-speaker review welcome via PR. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
3
3
 
4
4
  "sentinel.other": "Digite algo.",
5
- "sentinel.chat": "Conversar sobre isso",
6
5
  "sentinel.next": "Próximo",
7
6
 
8
7
  "submit.label": "Enviar respostas",
@@ -21,7 +20,8 @@
21
20
 
22
21
  "preview.no_preview": "Pré-visualização indisponível",
23
22
  "preview.notes_affordance": "Notas: pressione n para adicionar notas",
23
+ "notes.header": "Notas:",
24
24
 
25
- "chat.summary": "O usuário quer conversar sobre isso",
26
- "notes.header": "Notas:"
25
+ "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.",
26
+ "rpc.custom_answer_title": "Digite sua resposta:"
27
27
  }
package/locales/pt.json CHANGED
@@ -2,7 +2,6 @@
2
2
  "_meta.notes": "European Portuguese (Portugal). Auto-translated draft. Native-speaker review welcome via PR. Distinct from pt-BR (Brasil): differs in lexicon (utilizador / você), conjugation, and some terms. TUI symbols (↑/↓, ⚠) and key names (Enter, Esc, Tab, Space, n) are universal CLI conventions and stay untranslated.",
3
3
 
4
4
  "sentinel.other": "Escreva algo.",
5
- "sentinel.chat": "Conversar sobre isto",
6
5
  "sentinel.next": "Seguinte",
7
6
 
8
7
  "submit.label": "Enviar respostas",
@@ -21,7 +20,8 @@
21
20
 
22
21
  "preview.no_preview": "Pré-visualização indisponível",
23
22
  "preview.notes_affordance": "Notas: prima n para adicionar notas",
23
+ "notes.header": "Notas:",
24
24
 
25
- "chat.summary": "O utilizador quer conversar sobre isto",
26
- "notes.header": "Notas:"
25
+ "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.",
26
+ "rpc.custom_answer_title": "Escreva a sua resposta:"
27
27
  }