@herbertgao/pi-extensions 2026.10.10 → 2026.10.11

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 (108) hide show
  1. package/README.md +10 -8
  2. package/THIRD_PARTY_NOTICES.md +2 -2
  3. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +3 -0
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.md +3 -0
  5. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +1 -1
  6. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +3 -3
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +126 -42
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +24 -6
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/scroll.ts +69 -16
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/sticky-prompt.ts +1 -1
  11. package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
  12. package/node_modules/@herbertgao/sol-pi/README.md +7 -1
  13. package/node_modules/@herbertgao/sol-pi/docs/compatibility.md +28 -4
  14. package/node_modules/@herbertgao/sol-pi/docs/configuration.md +17 -4
  15. package/node_modules/@herbertgao/sol-pi/package.json +1 -1
  16. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/action-fusion/index.ts +35 -25
  17. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/action-fusion/then-run.ts +95 -26
  18. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/evidence-preserving-reducer/candidate.ts +39 -2
  19. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/evidence-preserving-reducer/index.ts +24 -0
  20. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/observation-pack/index.ts +12 -7
  21. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/extension.ts +138 -130
  22. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/projection.ts +88 -14
  23. package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/tools.ts +9 -0
  24. package/node_modules/@herbertgao/sol-pi/src/sol-pi/index.ts +14 -5
  25. package/node_modules/@herbertgao/sol-pi/src/sol-pi/shell-options.ts +22 -0
  26. package/node_modules/@herbertgao/sol-pi/src/sol-pi/tui.ts +11 -0
  27. package/node_modules/@juicesharp/rpiv-ask-user-question/answer-channel.ts +109 -0
  28. package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +117 -71
  29. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/hosts.md +2 -0
  30. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/keyboard.md +3 -1
  31. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/startup-performance.md +83 -0
  32. package/node_modules/@juicesharp/rpiv-ask-user-question/docs/tool-schema.md +74 -5
  33. package/node_modules/@juicesharp/rpiv-ask-user-question/events.ts +84 -0
  34. package/node_modules/@juicesharp/rpiv-ask-user-question/index.ts +10 -4
  35. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +4 -2
  36. package/node_modules/@juicesharp/rpiv-ask-user-question/presentation.ts +1 -1
  37. package/node_modules/@juicesharp/rpiv-ask-user-question/reconcile.ts +1 -1
  38. package/node_modules/@juicesharp/rpiv-ask-user-question/rpc-fallback.ts +5 -4
  39. package/node_modules/@juicesharp/rpiv-ask-user-question/state/build-questionnaire.ts +19 -19
  40. package/node_modules/@juicesharp/rpiv-ask-user-question/state/i18n-bridge.ts +1 -1
  41. package/node_modules/@juicesharp/rpiv-ask-user-question/state/key-router.ts +7 -4
  42. package/node_modules/@juicesharp/rpiv-ask-user-question/state/questionnaire-session.ts +10 -10
  43. package/node_modules/@juicesharp/rpiv-ask-user-question/state/row-intent.ts +2 -2
  44. package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/contract.ts +6 -6
  45. package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/derivations.ts +2 -2
  46. package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/focus.ts +1 -1
  47. package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/projections.ts +9 -9
  48. package/node_modules/@juicesharp/rpiv-ask-user-question/state/state-reducer.ts +5 -5
  49. package/node_modules/@juicesharp/rpiv-ask-user-question/state/state.ts +2 -2
  50. package/node_modules/@juicesharp/rpiv-ask-user-question/tool/external-answer.ts +125 -0
  51. package/node_modules/@juicesharp/rpiv-ask-user-question/tool/format-answer.ts +1 -1
  52. package/node_modules/@juicesharp/rpiv-ask-user-question/tool/normalize-params.ts +1 -1
  53. package/node_modules/@juicesharp/rpiv-ask-user-question/tool/response-envelope.ts +2 -2
  54. package/node_modules/@juicesharp/rpiv-ask-user-question/tool/types.ts +1 -1
  55. package/node_modules/@juicesharp/rpiv-ask-user-question/tool/validate-questionnaire.ts +1 -1
  56. package/node_modules/@juicesharp/rpiv-ask-user-question/view/component-binding.ts +4 -4
  57. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/multi-select-view.ts +4 -4
  58. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/option-list-view.ts +2 -2
  59. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/markdown-content-cache.ts +3 -3
  60. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-block-renderer.ts +5 -5
  61. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-layout-decider.ts +3 -3
  62. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-pane.ts +10 -10
  63. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/submit-picker.ts +2 -2
  64. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/tab-bar.ts +1 -1
  65. package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/wrapping-select.ts +1 -1
  66. package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-builder.ts +9 -9
  67. package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-copy.ts +1 -1
  68. package/node_modules/@juicesharp/rpiv-ask-user-question/view/props-adapter.ts +8 -8
  69. package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-components.ts +4 -4
  70. package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-content-strategy.ts +10 -10
  71. package/node_modules/@narumitw/pi-btw/dist/index.ts +3 -0
  72. package/node_modules/@narumitw/pi-btw/dist/index.ts.map +2 -2
  73. package/node_modules/@narumitw/pi-btw/package.json +4 -4
  74. package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +6 -0
  75. package/node_modules/@narumitw/pi-btw/src/keybindings.ts +1 -1
  76. package/node_modules/@narumitw/pi-caffeinate/dist/index.ts +1 -0
  77. package/node_modules/@narumitw/pi-caffeinate/dist/index.ts.map +2 -2
  78. package/node_modules/@narumitw/pi-caffeinate/package.json +3 -3
  79. package/node_modules/@narumitw/pi-caffeinate/src/inhibitor-process.ts +1 -0
  80. package/node_modules/pi-antigravity/README.md +6 -2
  81. package/node_modules/pi-antigravity/package.json +2 -2
  82. package/node_modules/pi-antigravity/src/client/client.ts +44 -52
  83. package/node_modules/pi-antigravity/src/index.ts +13 -0
  84. package/node_modules/pi-antigravity/src/models/discovery.ts +25 -2
  85. package/node_modules/pi-antigravity/src/models/grouping.ts +107 -68
  86. package/node_modules/pi-antigravity/src/models/models.ts +10 -0
  87. package/node_modules/pi-antigravity/src/search/search.ts +581 -43
  88. package/node_modules/pi-antigravity/src/stream/stream.ts +53 -13
  89. package/node_modules/pi-antigravity/src/types/types.ts +13 -0
  90. package/node_modules/pi-antigravity/src/usage/usage.ts +11 -3
  91. package/node_modules/pi-web-access/CHANGELOG.md +21 -0
  92. package/node_modules/pi-web-access/README.md +22 -7
  93. package/node_modules/pi-web-access/credential-source.ts +54 -4
  94. package/node_modules/pi-web-access/curator-page.ts +3 -1
  95. package/node_modules/pi-web-access/curator-server.ts +1 -0
  96. package/node_modules/pi-web-access/deepseek.ts +204 -0
  97. package/node_modules/pi-web-access/dist/index.js +927 -642
  98. package/node_modules/pi-web-access/dist/mcp-cli.js +877 -615
  99. package/node_modules/pi-web-access/gemini-adc.ts +48 -1
  100. package/node_modules/pi-web-access/gemini-search.ts +8 -4
  101. package/node_modules/pi-web-access/index.ts +16 -1
  102. package/node_modules/pi-web-access/package.json +1 -1
  103. package/node_modules/pi-web-access/page-query.ts +12 -6
  104. package/node_modules/pi-web-access/query-rewrite.ts +16 -13
  105. package/node_modules/pi-web-access/summary-review.ts +16 -6
  106. package/node_modules/pi-web-access/utils.ts +3 -0
  107. package/node_modules/pi-web-access/web-tool-core.ts +2 -0
  108. package/package.json +9 -9
@@ -50,6 +50,8 @@ TUI produces. Trade-offs inherent to the native primitives:
50
50
  Add a semicolon and custom text to return both (`1,3; another color`). Plain text still
51
51
  returns a custom-only multi-select answer. An empty input commits an empty selection,
52
52
  matching `Next` with nothing selected.
53
+ - In a single-select question, picking `Type something.` opens a text input. Cancelling it
54
+ or leaving it blank returns to the options; it never records an empty answer.
53
55
  - Dismissing any dialog cancels the whole questionnaire, mirroring `Esc` in the TUI.
54
56
 
55
57
  If the host can render neither custom UI nor dialogs, the call returns
@@ -47,7 +47,9 @@ squeezed into the narrow options column. `Shift+Enter` inserts a line break. Ver
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
49
  per question. `Ctrl+G` sends it through Pi's configured external editor. `Ctrl+U` clears
50
- it, while `Esc` cancels the questionnaire.
50
+ it, while `Esc` cancels the questionnaire. In a single-select question, `Enter` on an empty
51
+ or blank draft does nothing: a blank custom answer is never recorded. To leave a question
52
+ unanswered, move on and submit; the model is told which questions were left blank.
51
53
 
52
54
  On a single-select question, confirming the input produces `kind: "custom"`. On a
53
55
  multi-select question, the result uses `kind: "multi"`: `selected` contains checked
@@ -0,0 +1,83 @@
1
+ # Startup import resolution
2
+
3
+ Pi loads this package's published TypeScript sources directly through Jiti. On the
4
+ entry point's eager import graph, relative specifiers should name the actual `.ts`
5
+ files. A `.js` specifier whose target exists only as `.ts` still works, but makes
6
+ Jiti perform fallback resolution even when its transform cache is warm.
7
+
8
+ This change only updates those static import/export specifiers and permits `.ts`
9
+ imports in the repository's existing no-emit TypeScript check. It does not change
10
+ registration order, the optional i18n contract, or the questionnaire UI's lazy
11
+ loading/prewarm behavior. The import-graph test guards the eager graph without
12
+ placing a machine-dependent timing threshold in CI.
13
+
14
+ The same rule now applies repo-wide: every package names the real `.ts` file in
15
+ relative imports, enforced by `scripts/check-ts-import-specifiers.mjs`
16
+ (`npm run check:ts-specifiers`).
17
+
18
+ ## Reproduce
19
+
20
+ From the repository root, with npm, Git, tar, and a Pi CLI supporting `PI_TIMING=1`:
21
+
22
+ ```sh
23
+ node scripts/benchmark-ask-user-question-startup.mjs --baseline 1ffa165c --runs 15 > before-after.json
24
+ node scripts/benchmark-ask-user-question-startup.mjs --baseline 1ffa165c --runs 15 --with-i18n > before-after-i18n.json
25
+ ```
26
+
27
+ Use `--pi /path/to/pi` to select a different Pi installation. The default baseline
28
+ is `HEAD`, useful when comparing uncommitted edits; after committing the fix,
29
+ explicitly select its parent or the original upstream commit instead.
30
+
31
+ The script:
32
+
33
+ - Packs the baseline Git revision and current working tree with `npm pack
34
+ --ignore-scripts`, then extracts their published files into equal-depth paths.
35
+ - Gives both packages identical packed `rpiv-config` sources from the current
36
+ checkout, and optionally identical `rpiv-i18n` sources. Host-provided libraries
37
+ remain supplied by Pi. It installs nothing and does not run package scripts.
38
+ - Uses an isolated home, agent directory, and working directory, with discovery
39
+ and startup network operations disabled. It does not read the user's Pi
40
+ settings or credentials and does not make model calls.
41
+ - Starts a fresh process per sample; discards two warm-ups per variant and then
42
+ alternates execution order. Run on an otherwise idle machine.
43
+ - Fails on load errors or missing module/factory timings, emits raw samples and
44
+ summary statistics as JSON, and removes its temporary package trees.
45
+
46
+ `importMs` is Pi's extension-import timing, including shared loader setup because
47
+ this extension loads first. `wallMs` measures the complete empty print-mode
48
+ process, **not** time until an interactive editor is ready. Neither measures
49
+ first-ever/cold-cache installation or first-question rendering.
50
+
51
+ ## Example measurements
52
+
53
+ Pi 1.2.0, Node v26.0.0, macOS arm64; baseline
54
+ `1ffa165c224b5489fb5774a6652ef2e1c3bc6b2a`; 15 measured fresh processes per variant,
55
+ following two warm-ups each:
56
+
57
+ | Optional i18n | Metric | Baseline median | Patched median |
58
+ | --- | --- | ---: | ---: |
59
+ | Absent | Extension import | 97 ms | 23 ms |
60
+ | Absent | Whole process | 327.74 ms | 252.84 ms |
61
+ | Present | Extension import | 99 ms | 25 ms |
62
+ | Present | Whole process | 330.06 ms | 254.88 ms |
63
+
64
+ The improvement is approximately **74 ms of import time** and **75 ms of
65
+ whole-process time** in both configurations. Factory time stayed at 0–1 ms.
66
+ Import ranges were 96–104 vs 22–24 ms without i18n, and 98–110 vs 24–27 ms with it.
67
+ The same 15-sample benchmark also improves startup on the two Node majors used
68
+ by CI (same Pi version and machine):
69
+
70
+ | Node | Optional i18n | Import median, before → after | Whole-process median, before → after |
71
+ | --- | --- | ---: | ---: |
72
+ | 22.23.3 | Absent | 82 → 22 ms | 250.94 → 189.46 ms |
73
+ | 22.23.3 | Present | 84 → 22 ms | 253.30 → 190.52 ms |
74
+ | 24.21.0 | Absent | 85 → 20 ms | 262.31 → 190.02 ms |
75
+ | 24.21.0 | Present | 85 → 22 ms | 252.85 → 190.17 ms |
76
+
77
+ The package suite passes all 787 tests on both Node 22 and 24, including the new
78
+ startup-import regression test and the existing real-TUI factory, RPC, locale,
79
+ and lazy-load tests. The full monorepo suite passes 6,906 tests on Node 26 and
80
+ on Node 24 with coverage enabled; all repository coverage thresholds pass.
81
+
82
+ Results depend on the host, loader version, filesystem, and caches; they are not a
83
+ universal latency guarantee.
@@ -109,21 +109,90 @@ in `details.globalNote`.
109
109
 
110
110
  ## Event contract
111
111
 
112
- The package publishes one event on Pi's event bus, emitted after validation passes and
113
- before the dialog is shown. Import it from the `/events` subpath:
112
+ Everything here imports from the `/events` subpath.
113
+
114
+ ### Outbound
115
+
116
+ `rpiv:ask-user:prompt` carries the questionnaire, emitted after validation passes and
117
+ before the dialog is shown:
114
118
 
115
119
  ```ts
116
120
  import { ASK_USER_PROMPT_EVENT, type AskUserPromptEventPayload } from "@juicesharp/rpiv-ask-user-question/events";
117
121
 
118
122
  pi.events.on(ASK_USER_PROMPT_EVENT, (payload: AskUserPromptEventPayload) => {
123
+ // payload.toolCallId — names this questionnaire on the events below
119
124
  // payload.questions[].{ question, header, multiSelect, options[] }
120
125
  // payload.questions[].options[].{ label, description, hasPreview }
121
126
  });
122
127
  ```
123
128
 
124
- The channel name is `rpiv:ask-user:prompt`. Preview *content* is deliberately not shipped
125
- in the payload — only `hasPreview: boolean` — so listeners forwarding the event across a
126
- process or network boundary stay cheap.
129
+ Preview *content* is deliberately not shipped in the payload — only `hasPreview: boolean` —
130
+ so listeners forwarding the event across a process or network boundary stay cheap.
131
+
132
+ `rpiv:ask-user:blocked` brackets the wait for input: `{ active: true, toolCallId }` before the
133
+ dialog opens, `{ active: false, toolCallId }` in a `finally` when it closes for any reason, so
134
+ a listener can tell blocked-on-human apart from working. Several questionnaires can be open
135
+ at once (Pi runs tool calls in parallel), so match `active: false` to its prompt by
136
+ `toolCallId` — that is also how a remote mirror learns a question was answered elsewhere.
137
+
138
+ ### Inbound
139
+
140
+ `rpiv:ask-user:answer` answers or cancels one open questionnaire without synthesizing
141
+ keystrokes — for programs driving Pi from outside: a pane supervisor, a phone or web
142
+ bridge, a test harness. Name the questionnaire by the `toolCallId` from its prompt event:
143
+
144
+ ```ts
145
+ import {
146
+ ASK_USER_ANSWER_EVENT,
147
+ ASK_USER_ANSWER_RESULT_EVENT,
148
+ ASK_USER_PROMPT_EVENT,
149
+ type AskUserAnswerResultEventPayload,
150
+ type AskUserPromptEventPayload,
151
+ } from "@juicesharp/rpiv-ask-user-question/events";
152
+
153
+ pi.events.on(ASK_USER_PROMPT_EVENT, ({ toolCallId }: AskUserPromptEventPayload) => {
154
+ pi.events.emit(ASK_USER_ANSWER_EVENT, {
155
+ toolCallId,
156
+ requestId: "r1", // optional, echoed on the verdict
157
+ answers: [
158
+ { questionIndex: 0, optionIndexes: [1] }, // single-select: one index…
159
+ { questionIndex: 1, text: "something else" }, // …or custom text
160
+ { questionIndex: 2, optionIndexes: [0, 2], text: "and" }, // multi-select: either or both
161
+ ],
162
+ globalNote: "optional, like the Submit tab's note",
163
+ });
164
+ // or decline, as Esc does: { toolCallId, cancel: true }
165
+ });
166
+
167
+ pi.events.on(ASK_USER_ANSWER_RESULT_EVENT, (v: AskUserAnswerResultEventPayload) => {
168
+ // { ok, code?, reason?, requestId?, toolCallId? }
169
+ });
170
+ ```
171
+
172
+ Indexes are 0-based into the prompt's `questions` and each question's `options`. Per-question
173
+ `notes` are accepted too; notes are trimmed and dropped when blank, as in the dialog.
174
+
175
+ - **When:** from the moment the prompt event is emitted — answering straight from the
176
+ prompt listener works, and no dialog is shown — until the questionnaire closes.
177
+ - **First answer wins**, typed in the terminal or sent here. A later one is refused.
178
+ - **All or nothing.** Every question must be answered once, indexes in range and distinct,
179
+ custom text not blank. Otherwise nothing is applied and the dialog stays open — a partly
180
+ applied answer would reach the model indistinguishable from one the user gave. Unknown
181
+ fields are ignored.
182
+ - **One verdict per attempt** on `rpiv:ask-user:answer-result`. Branch on `code`; `reason`
183
+ is for logs and its wording may change:
184
+
185
+ | `code` | Meaning |
186
+ |---|---|
187
+ | `not_found` | No open questionnaire has that `toolCallId` — never opened, or already answered or closed. |
188
+ | `invalid_payload` | A field is missing or has the wrong type. |
189
+ | `invalid_answer` | Well-formed, but does not fit the questions: a question unanswered or answered twice, an index out of range or repeated, blank text, two options or option plus text on single-select. |
190
+ | `unsupported_host` | An RPC/ACP host shows the questions in its own dialogs ([Hosts and runtime behavior](./hosts.md)); those cannot be answered from here. |
191
+
192
+ The bus is per session: questions asked inside a `/lanes` workflow child run on that child's
193
+ own bus, so an emitter on the parent session's bus cannot see or answer them.
194
+
195
+ ### Stability
127
196
 
128
197
  Stability policy for the `rpiv:*` namespace: channel names are immutable, payload changes
129
198
  are append-only and always optional, payloads stay JSON-safe, and any breaking change ships
@@ -23,6 +23,11 @@ export const ASK_USER_PROMPT_EVENT = "rpiv:ask-user:prompt" as const;
23
23
 
24
24
  export interface AskUserPromptEventPayload {
25
25
  questions: ReadonlyArray<AskUserPromptQuestion>;
26
+ /**
27
+ * The tool call's id — always set. Names this questionnaire on
28
+ * `ASK_USER_BLOCKED_EVENT` and `ASK_USER_ANSWER_EVENT`.
29
+ */
30
+ toolCallId?: string;
26
31
  }
27
32
 
28
33
  /**
@@ -35,6 +40,11 @@ export const ASK_USER_BLOCKED_EVENT = "rpiv:ask-user:blocked" as const;
35
40
  export interface AskUserBlockedEventPayload {
36
41
  /** True while input is awaited; false when the wait ends (answer, cancel, or error). */
37
42
  active: boolean;
43
+ /**
44
+ * The tool call's id — always set. Several questionnaires can be open at once,
45
+ * so pair `active: false` with the prompt it closes by this id.
46
+ */
47
+ toolCallId?: string;
38
48
  }
39
49
 
40
50
  export interface AskUserPromptQuestion {
@@ -57,3 +67,77 @@ export interface AskUserPromptOption {
57
67
  /** True iff the option carries rich preview content (content not shipped). */
58
68
  hasPreview: boolean;
59
69
  }
70
+
71
+ /**
72
+ * INBOUND — the only event in this contract the package listens for rather than
73
+ * emits. Answers (or cancels) one open questionnaire without the TUI keystroke
74
+ * path, so a program driving Pi from outside — a pane supervisor, a phone or web
75
+ * bridge, a test harness — need not synthesize keys against a rendered dialog.
76
+ *
77
+ * `toolCallId` names the questionnaire: the id carried by its
78
+ * `ASK_USER_PROMPT_EVENT`. It is accepted from the moment that prompt is emitted
79
+ * (before the dialog is on screen) until the questionnaire closes; the first
80
+ * answer wins, whether typed in the terminal or sent here.
81
+ *
82
+ * Validation is strict and all-or-nothing: every question answered, every index
83
+ * in range, nothing duplicated — or nothing is applied and the dialog stays open.
84
+ * A partially applied answer would reach the model indistinguishable from one
85
+ * the user gave. Unknown fields are ignored (policy rule 2).
86
+ *
87
+ * Every attempt gets one verdict on `ASK_USER_ANSWER_RESULT_EVENT`; this payload
88
+ * carries no callback because payloads must survive JSON serialization.
89
+ */
90
+ export const ASK_USER_ANSWER_EVENT = "rpiv:ask-user:answer" as const;
91
+
92
+ export interface AskUserAnswerEventPayload {
93
+ /** The questionnaire to answer — `toolCallId` from its prompt event. */
94
+ toolCallId: string;
95
+ /** Echoed back on the verdict so an emitter can pair it with this request. */
96
+ requestId?: string;
97
+ /** One entry per question. Omitted (or empty) only with `cancel`. */
98
+ answers?: ReadonlyArray<AskUserAnswerEntry>;
99
+ /** Note for the whole questionnaire — what `n` on the Submit tab attaches in the TUI. */
100
+ globalNote?: string;
101
+ /** Decline the questionnaire, as Esc does: the model is told the user declined. */
102
+ cancel?: boolean;
103
+ }
104
+
105
+ /**
106
+ * One question's answer. Single-select takes exactly one of `optionIndexes`
107
+ * (one index) or `text`; multi-select takes either or both, like the TUI's
108
+ * checked options plus its `Type something.` row.
109
+ */
110
+ export interface AskUserAnswerEntry {
111
+ /** 0-based index into the prompt's `questions`. */
112
+ questionIndex: number;
113
+ /** 0-based, distinct indices into the question's `options`. */
114
+ optionIndexes?: readonly number[];
115
+ /** Custom answer — what the `Type something.` row produces. Must not be blank. */
116
+ text?: string;
117
+ /** Note on this question — what the `n` key attaches in the TUI. */
118
+ notes?: string;
119
+ }
120
+
121
+ /** Verdict for an `ASK_USER_ANSWER_EVENT`. One per attempt, accepted or not. */
122
+ export const ASK_USER_ANSWER_RESULT_EVENT = "rpiv:ask-user:answer-result" as const;
123
+
124
+ /**
125
+ * Why an answer was refused — branch on this, not on `reason`:
126
+ * - `not_found`: no open questionnaire has that `toolCallId` (never opened, or already closed).
127
+ * - `invalid_payload`: a field is missing or has the wrong type.
128
+ * - `invalid_answer`: well-formed, but does not fit the questions (missing, duplicated, out of range).
129
+ * - `unsupported_host`: the questionnaire runs in an RPC host's own dialogs, which cannot be answered here.
130
+ */
131
+ export type AskUserAnswerRejectCode = "not_found" | "invalid_payload" | "invalid_answer" | "unsupported_host";
132
+
133
+ export interface AskUserAnswerResultEventPayload {
134
+ ok: boolean;
135
+ /** Set when `ok` is false. */
136
+ code?: AskUserAnswerRejectCode;
137
+ /** Human-readable detail for logs. Wording may change — do not parse it. */
138
+ reason?: string;
139
+ /** Echoed from the request when it was a string. */
140
+ requestId?: string;
141
+ /** Echoed from the request when it was a string. */
142
+ toolCallId?: string;
143
+ }
@@ -17,9 +17,9 @@
17
17
  */
18
18
 
19
19
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
20
- import { registerAskUserQuestionTool } from "./ask-user-question.js";
21
- import { registerAskUserQuestionReconciler } from "./reconcile.js";
22
- import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
20
+ import { registerAskUserQuestionTool } from "./ask-user-question.ts";
21
+ import { registerAskUserQuestionReconciler } from "./reconcile.ts";
22
+ import { I18N_NAMESPACE } from "./state/i18n-bridge.ts";
23
23
 
24
24
  type I18nLoader = {
25
25
  registerLocalesFromDir: (namespace: string, packageUrl: string, options?: { label?: string }) => void;
@@ -40,13 +40,19 @@ try {
40
40
  }
41
41
 
42
42
  export {
43
+ ASK_USER_ANSWER_EVENT,
44
+ ASK_USER_ANSWER_RESULT_EVENT,
43
45
  ASK_USER_BLOCKED_EVENT,
44
46
  ASK_USER_PROMPT_EVENT,
47
+ type AskUserAnswerEntry,
48
+ type AskUserAnswerEventPayload,
49
+ type AskUserAnswerRejectCode,
50
+ type AskUserAnswerResultEventPayload,
45
51
  type AskUserBlockedEventPayload,
46
52
  type AskUserPromptEventPayload,
47
53
  type AskUserPromptOption,
48
54
  type AskUserPromptQuestion,
49
- } from "./events.js";
55
+ } from "./events.ts";
50
56
 
51
57
  export default function (pi: ExtensionAPI) {
52
58
  registerAskUserQuestionTool(pi);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "2.13.8",
3
+ "version": "2.13.9",
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",
@@ -30,6 +30,7 @@
30
30
  "test": "vitest run"
31
31
  },
32
32
  "files": [
33
+ "answer-channel.ts",
33
34
  "ask-user-question.ts",
34
35
  "rpc-fallback.ts",
35
36
  "config.ts",
@@ -56,6 +57,7 @@
56
57
  "state/selectors/projections.ts",
57
58
  "state/state-reducer.ts",
58
59
  "state/state.ts",
60
+ "tool/external-answer.ts",
59
61
  "tool/format-answer.ts",
60
62
  "tool/normalize-params.ts",
61
63
  "tool/response-envelope.ts",
@@ -99,6 +101,6 @@
99
101
  }
100
102
  },
101
103
  "dependencies": {
102
- "@juicesharp/rpiv-config": "^2.13.8"
104
+ "@juicesharp/rpiv-config": "^2.13.9"
103
105
  }
104
106
  }
@@ -1,4 +1,4 @@
1
- import type { QuestionnaireResult } from "./tool/types.js";
1
+ import type { QuestionnaireResult } from "./tool/types.ts";
2
2
 
3
3
  /**
4
4
  * Inline row budget. A component in Pi's editor slot only receives a width, and the
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
18
- import { ASK_USER_QUESTION_TOOL_NAME } from "./ask-user-question.js";
18
+ import { ASK_USER_QUESTION_TOOL_NAME } from "./ask-user-question.ts";
19
19
 
20
20
  /**
21
21
  * Strip-or-restore `ask_user_question` to match `ctx.hasUI`. Reads the active
@@ -18,8 +18,8 @@
18
18
  * option numbers, custom text, or both separated by a semicolon.
19
19
  */
20
20
 
21
- import { displayLabel, t } from "./state/i18n-bridge.js";
22
- import type { QuestionAnswer, QuestionData, QuestionnaireResult, QuestionParams } from "./tool/types.js";
21
+ import { displayLabel, t } from "./state/i18n-bridge.ts";
22
+ import type { QuestionAnswer, QuestionData, QuestionnaireResult, QuestionParams } from "./tool/types.ts";
23
23
 
24
24
  /**
25
25
  * Canonical-English fallbacks; resolved through `t()` at dialog time so the
@@ -136,12 +136,13 @@ async function askSingleSelect(
136
136
  preview: o.preview && o.preview.length > 0 ? o.preview : undefined,
137
137
  };
138
138
  }
139
- // "Type something." sentinel → free-text follow-up; cancelling it goes back to the options.
139
+ // "Type something." sentinel → free-text follow-up; cancelling it, or a blank reply (#301),
140
+ // goes back to the options.
140
141
  const typed = await ui.input(
141
142
  `${header}${q.question}\n\n${q.options.map(formatOptionLine).join("\n")}\n\n${t("rpc.custom_answer_title", CUSTOM_ANSWER_TITLE)}`,
142
143
  "",
143
144
  );
144
- if (typed == null) continue;
145
+ if (typed == null || typed.trim().length === 0) continue;
145
146
  return { questionIndex, question: q.question, kind: "custom", answer: typed };
146
147
  }
147
148
  }
@@ -1,27 +1,27 @@
1
1
  import { getMarkdownTheme, type Theme } from "@earendil-works/pi-coding-agent";
2
2
  import { Editor, type EditorTheme, type TUI } from "@earendil-works/pi-tui";
3
- import type { QuestionData } from "../tool/types.js";
3
+ import type { QuestionData } from "../tool/types.ts";
4
4
  import {
5
5
  type BoundGlobalBinding,
6
6
  type BoundPerTabBinding,
7
7
  globalBinding,
8
8
  perTabBinding,
9
- } from "../view/component-binding.js";
10
- import { MultiSelectView } from "../view/components/multi-select-view.js";
11
- import { OptionListView } from "../view/components/option-list-view.js";
12
- import { PreviewBlockRenderer } from "../view/components/preview/preview-block-renderer.js";
13
- import { crossTabLeftWidthWithDonation } from "../view/components/preview/preview-layout-decider.js";
14
- import type { PreviewPaneProps } from "../view/components/preview/preview-pane.js";
15
- import { PreviewPane } from "../view/components/preview/preview-pane.js";
16
- import { SubmitPicker } from "../view/components/submit-picker.js";
17
- import { TabBar } from "../view/components/tab-bar.js";
18
- import type { WrappingSelectItem, WrappingSelectTheme } from "../view/components/wrapping-select.js";
19
- import { DialogView } from "../view/dialog-builder.js";
20
- import { QuestionnairePropsAdapter } from "../view/props-adapter.js";
21
- import type { StatefulView } from "../view/stateful-view.js";
22
- import type { TabBodyHeights, TabComponents } from "../view/tab-components.js";
23
- import type { PerTabSelector } from "./selectors/contract.js";
24
- import { selectActivePreviewPaneIndex } from "./selectors/derivations.js";
9
+ } from "../view/component-binding.ts";
10
+ import { MultiSelectView } from "../view/components/multi-select-view.ts";
11
+ import { OptionListView } from "../view/components/option-list-view.ts";
12
+ import { PreviewBlockRenderer } from "../view/components/preview/preview-block-renderer.ts";
13
+ import { crossTabLeftWidthWithDonation } from "../view/components/preview/preview-layout-decider.ts";
14
+ import type { PreviewPaneProps } from "../view/components/preview/preview-pane.ts";
15
+ import { PreviewPane } from "../view/components/preview/preview-pane.ts";
16
+ import { SubmitPicker } from "../view/components/submit-picker.ts";
17
+ import { TabBar } from "../view/components/tab-bar.ts";
18
+ import type { WrappingSelectItem, WrappingSelectTheme } from "../view/components/wrapping-select.ts";
19
+ import { DialogView } from "../view/dialog-builder.ts";
20
+ import { QuestionnairePropsAdapter } from "../view/props-adapter.ts";
21
+ import type { StatefulView } from "../view/stateful-view.ts";
22
+ import type { TabBodyHeights, TabComponents } from "../view/tab-components.ts";
23
+ import type { PerTabSelector } from "./selectors/contract.ts";
24
+ import { selectActivePreviewPaneIndex } from "./selectors/derivations.ts";
25
25
  import {
26
26
  selectDialogProps,
27
27
  selectMultiSelectProps,
@@ -29,8 +29,8 @@ import {
29
29
  selectPreviewPaneProps,
30
30
  selectSubmitPickerProps,
31
31
  selectTabBarProps,
32
- } from "./selectors/projections.js";
33
- import type { QuestionnaireState } from "./state.js";
32
+ } from "./selectors/projections.ts";
33
+ import type { QuestionnaireState } from "./state.ts";
34
34
 
35
35
  export interface QuestionnaireBuildConfig {
36
36
  tui: TUI;
@@ -20,7 +20,7 @@
20
20
  * the canonical `ROW_INTENT_META[kind].label`, never `displayLabel(kind)`.
21
21
  */
22
22
 
23
- import { ROW_INTENT_META, type SentinelKind } from "./row-intent.js";
23
+ import { ROW_INTENT_META, type SentinelKind } from "./row-intent.ts";
24
24
 
25
25
  export const I18N_NAMESPACE = "@juicesharp/rpiv-ask-user-question";
26
26
 
@@ -1,7 +1,7 @@
1
1
  import { Key, matchesKey } from "@earendil-works/pi-tui";
2
- import type { QuestionAnswer } from "../tool/types.js";
3
- import { ROW_INTENT_META } from "./row-intent.js";
4
- import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
2
+ import type { QuestionAnswer } from "../tool/types.ts";
3
+ import { ROW_INTENT_META } from "./row-intent.ts";
4
+ import type { QuestionnaireRuntime, QuestionnaireState } from "./state.ts";
5
5
 
6
6
  const KEYBIND_UP = "tui.select.up";
7
7
  const KEYBIND_DOWN = "tui.select.down";
@@ -80,12 +80,15 @@ function buildSingleSelectAnswer(state: QuestionnaireState, runtime: Questionnai
80
80
  const item = runtime.currentItem;
81
81
 
82
82
  if (state.inputMode) {
83
+ // A blank draft is not an answer (#301): Enter stays on the row instead of recording
84
+ // an empty custom answer. Skipping a question is the Submit tab's `unanswered:` path.
83
85
  const label = runtime.inputBuffer;
86
+ if (label.trim().length === 0) return null;
84
87
  return {
85
88
  questionIndex: state.currentTab,
86
89
  question: q.question,
87
90
  kind: "custom",
88
- answer: label.length > 0 ? label : null,
91
+ answer: label,
89
92
  };
90
93
  }
91
94
  if (!item) return null;
@@ -1,15 +1,15 @@
1
1
  import type { Theme } from "@earendil-works/pi-coding-agent";
2
2
  import type { Editor, OverlayHandle, TUI } from "@earendil-works/pi-tui";
3
- import { COLLAPSE_KEY_OFF, formatKeySpecForDisplay } from "../config.js";
4
- import type { QuestionData, QuestionnaireResult, QuestionParams } from "../tool/types.js";
5
- import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
6
- import { COLLAPSED_HINT_TEMPLATE, HINT_PART_CANCEL, KEY_PLACEHOLDER } from "../view/dialog-builder.js";
7
- import type { QuestionnairePropsAdapter } from "../view/props-adapter.js";
8
- import { buildQuestionnaire, type QuestionnaireBuilt } from "./build-questionnaire.js";
9
- import { t } from "./i18n-bridge.js";
10
- import { type QuestionnaireAction, routeKey } from "./key-router.js";
11
- import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
12
- import { type ApplyContext, type Effect, reduce } from "./state-reducer.js";
3
+ import { COLLAPSE_KEY_OFF, formatKeySpecForDisplay } from "../config.ts";
4
+ import type { QuestionData, QuestionnaireResult, QuestionParams } from "../tool/types.ts";
5
+ import type { WrappingSelectItem } from "../view/components/wrapping-select.ts";
6
+ import { COLLAPSED_HINT_TEMPLATE, HINT_PART_CANCEL, KEY_PLACEHOLDER } from "../view/dialog-builder.ts";
7
+ import type { QuestionnairePropsAdapter } from "../view/props-adapter.ts";
8
+ import { buildQuestionnaire, type QuestionnaireBuilt } from "./build-questionnaire.ts";
9
+ import { t } from "./i18n-bridge.ts";
10
+ import { type QuestionnaireAction, routeKey } from "./key-router.ts";
11
+ import type { QuestionnaireRuntime, QuestionnaireState } from "./state.ts";
12
+ import { type ApplyContext, type Effect, reduce } from "./state-reducer.ts";
13
13
 
14
14
  export interface QuestionnaireSessionConfig {
15
15
  tui: TUI;
@@ -1,5 +1,5 @@
1
- import type { QuestionData } from "../tool/types.js";
2
- import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
1
+ import type { QuestionData } from "../tool/types.ts";
2
+ import type { WrappingSelectItem } from "../view/components/wrapping-select.ts";
3
3
 
4
4
  /**
5
5
  * Row kind discriminator. Single source of truth — derived from the runtime
@@ -1,9 +1,9 @@
1
- import type { QuestionData } from "../../tool/types.js";
2
- import type { PreviewPaneProps } from "../../view/components/preview/preview-pane.js";
3
- import type { WrappingSelectItem } from "../../view/components/wrapping-select.js";
4
- import type { ActiveView, StatefulView } from "../../view/stateful-view.js";
5
- import type { TabComponents } from "../../view/tab-components.js";
6
- import type { QuestionnaireState } from "../state.js";
1
+ import type { QuestionData } from "../../tool/types.ts";
2
+ import type { PreviewPaneProps } from "../../view/components/preview/preview-pane.ts";
3
+ import type { WrappingSelectItem } from "../../view/components/wrapping-select.ts";
4
+ import type { ActiveView, StatefulView } from "../../view/stateful-view.ts";
5
+ import type { TabComponents } from "../../view/tab-components.ts";
6
+ import type { QuestionnaireState } from "../state.ts";
7
7
 
8
8
  export interface BindingContext {
9
9
  readonly questions: readonly QuestionData[];
@@ -1,5 +1,5 @@
1
- import type { QuestionAnswer, QuestionData } from "../../tool/types.js";
2
- import type { WrappingSelectItem } from "../../view/components/wrapping-select.js";
1
+ import type { QuestionAnswer, QuestionData } from "../../tool/types.ts";
2
+ import type { WrappingSelectItem } from "../../view/components/wrapping-select.ts";
3
3
 
4
4
  /**
5
5
  * Which row in the active tab should be marked as "previously confirmed"? Drives the
@@ -1,4 +1,4 @@
1
- import type { ActiveView } from "../../view/stateful-view.js";
1
+ import type { ActiveView } from "../../view/stateful-view.ts";
2
2
 
3
3
  /**
4
4
  * Discriminated focus selector — single source of truth for "which view owns
@@ -1,12 +1,12 @@
1
- import { MULTI_SUBMIT_LABEL, type MultiSelectViewProps } from "../../view/components/multi-select-view.js";
2
- import type { OptionListViewProps } from "../../view/components/option-list-view.js";
3
- import type { PreviewPaneProps } from "../../view/components/preview/preview-pane.js";
4
- import type { SubmitPickerProps } from "../../view/components/submit-picker.js";
5
- import type { TabBarProps } from "../../view/components/tab-bar.js";
6
- import type { DialogProps } from "../../view/dialog-builder.js";
7
- import { displayLabel } from "../i18n-bridge.js";
8
- import type { GlobalSelector, PerTabBindingContext, PerTabSelector } from "./contract.js";
9
- import { selectConfirmedIndicator, selectSavedNote } from "./derivations.js";
1
+ import { MULTI_SUBMIT_LABEL, type MultiSelectViewProps } from "../../view/components/multi-select-view.ts";
2
+ import type { OptionListViewProps } from "../../view/components/option-list-view.ts";
3
+ import type { PreviewPaneProps } from "../../view/components/preview/preview-pane.ts";
4
+ import type { SubmitPickerProps } from "../../view/components/submit-picker.ts";
5
+ import type { TabBarProps } from "../../view/components/tab-bar.ts";
6
+ import type { DialogProps } from "../../view/dialog-builder.ts";
7
+ import { displayLabel } from "../i18n-bridge.ts";
8
+ import type { GlobalSelector, PerTabBindingContext, PerTabSelector } from "./contract.ts";
9
+ import { selectConfirmedIndicator, selectSavedNote } from "./derivations.ts";
10
10
 
11
11
  function emptyMultiSelectProps(ctx: PerTabBindingContext): MultiSelectViewProps {
12
12
  return {
@@ -1,8 +1,8 @@
1
- import type { QuestionAnswer, QuestionData, QuestionnaireResult } from "../tool/types.js";
2
- import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
3
- import type { QuestionnaireAction } from "./key-router.js";
4
- import { ROW_INTENT_META } from "./row-intent.js";
5
- import type { QuestionnaireState } from "./state.js";
1
+ import type { QuestionAnswer, QuestionData, QuestionnaireResult } from "../tool/types.ts";
2
+ import type { WrappingSelectItem } from "../view/components/wrapping-select.ts";
3
+ import type { QuestionnaireAction } from "./key-router.ts";
4
+ import { ROW_INTENT_META } from "./row-intent.ts";
5
+ import type { QuestionnaireState } from "./state.ts";
6
6
 
7
7
  /** Session-lifetime constants. No live-component reads — peripheral values live on canonical state. */
8
8
  export interface ApplyContext {
@@ -1,5 +1,5 @@
1
- import type { QuestionAnswer, QuestionData } from "../tool/types.js";
2
- import type { WrappingSelectItem } from "../view/components/wrapping-select.js";
1
+ import type { QuestionAnswer, QuestionData } from "../tool/types.ts";
2
+ import type { WrappingSelectItem } from "../view/components/wrapping-select.ts";
3
3
 
4
4
  /**
5
5
  * Canonical state for the questionnaire dialog. Single source of truth — both the