@juicesharp/rpiv-ask-user-question 2.5.1 → 2.6.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.
- package/README.md +2 -0
- package/ask-user-question.ts +20 -0
- package/docs/hosts.md +6 -0
- package/docs/keyboard.md +7 -0
- package/package.json +2 -2
- package/state/build-questionnaire.ts +7 -0
- package/state/key-router.ts +16 -5
package/README.md
CHANGED
|
@@ -27,6 +27,8 @@ Nothing to set up — the tool is live as soon as Pi restarts. Hand the model a
|
|
|
27
27
|
|
|
28
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, 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.
|
|
29
29
|
|
|
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
|
+
|
|
30
32
|

|
|
31
33
|
|
|
32
34
|
When the model asks several things at once, `Tab` moves between them and a Submit tab reviews everything before it goes back:
|
package/ask-user-question.ts
CHANGED
|
@@ -61,6 +61,24 @@ const ERROR_SESSION_LOAD_FAILED =
|
|
|
61
61
|
const ERROR_STALE_MODULE_CACHE =
|
|
62
62
|
"Error: the questionnaire UI cannot load — the host's module cache went stale after an earlier failed load (typically dependencies replaced on disk mid-session). This is unrecoverable within the current Pi process. The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead, and tell the user to restart Pi to restore this tool.";
|
|
63
63
|
|
|
64
|
+
/** Standard terminal bell — same byte rpiv-warp exports as OSC_TERMINATOR. */
|
|
65
|
+
export const BEL = "\x07";
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Emit one portable terminal attention signal without touching redirected output.
|
|
69
|
+
* Writes to stdout rather than rpiv-warp's `/dev/tty` transport: the `isTTY` gate
|
|
70
|
+
* both proves an interactive terminal owns the coming wait and keeps the byte out
|
|
71
|
+
* of piped RPC transports (VS Code pendant, Zed) — a `/dev/tty` write would ring
|
|
72
|
+
* even when the questionnaire renders in a remote host's own UI.
|
|
73
|
+
*/
|
|
74
|
+
function emitTerminalAttention(): void {
|
|
75
|
+
try {
|
|
76
|
+
if (process.stdout.isTTY) process.stdout.write(BEL);
|
|
77
|
+
} catch {
|
|
78
|
+
// Terminal attention is best effort; the questionnaire must still proceed.
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
64
82
|
/** Delay before the background session-graph pre-warm; mirrors rpiv-workflow's /wf prewarm. */
|
|
65
83
|
export const PREWARM_DELAY_MS = 2000;
|
|
66
84
|
|
|
@@ -173,6 +191,7 @@ Preview content is rendered as markdown in a monospace box. Multi-line text with
|
|
|
173
191
|
if ((ctx as { mode?: string }).mode === "rpc" && hasDialogUI(ctx.ui)) {
|
|
174
192
|
emitAskUserBlockedEvent(pi, true);
|
|
175
193
|
try {
|
|
194
|
+
emitTerminalAttention();
|
|
176
195
|
return buildQuestionnaireResponse(await runRpcQuestionnaire(ctx.ui, typed), typed);
|
|
177
196
|
} finally {
|
|
178
197
|
emitAskUserBlockedEvent(pi, false);
|
|
@@ -232,6 +251,7 @@ Preview content is rendered as markdown in a monospace box. Multi-line text with
|
|
|
232
251
|
|
|
233
252
|
emitAskUserBlockedEvent(pi, true);
|
|
234
253
|
try {
|
|
254
|
+
emitTerminalAttention();
|
|
235
255
|
const result = await ctx.ui.custom<QuestionnaireResult>(
|
|
236
256
|
(tui, theme, keybindings, done) => {
|
|
237
257
|
const session = new QuestionnaireSession({
|
package/docs/hosts.md
CHANGED
|
@@ -11,6 +11,12 @@ render at all.
|
|
|
11
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
12
|
| Non-interactive run (no UI) | Nothing — the tool is removed | Nothing |
|
|
13
13
|
|
|
14
|
+
### Terminal attention
|
|
15
|
+
|
|
16
|
+
After UI availability and questionnaire validation succeed, the package emits exactly one standard terminal BEL (`\x07`) immediately before the interactive wait begins. The signal is sent to `stdout` only when `process.stdout.isTTY` is true, so redirected output and non-TTY RPC streams stay untouched. A TTY-backed RPC dialog walker receives the same signal as the TUI path.
|
|
17
|
+
|
|
18
|
+
The BEL is best effort: if the synchronous terminal write fails, the questionnaire continues and its existing prompt/blocked lifecycle and result envelope are unchanged. The terminal configuration decides whether the BEL is audible, visual, or ignored. No BEL is emitted for missing UI, invalid questionnaires, or a failed TUI session load.
|
|
19
|
+
|
|
14
20
|
### Non-interactive runs
|
|
15
21
|
|
|
16
22
|
A `before_agent_start` hook reconciles the active tool set against `ctx.hasUI` before every
|
package/docs/keyboard.md
CHANGED
|
@@ -18,6 +18,13 @@ adapts to the size of your terminal.
|
|
|
18
18
|
| `Ctrl+U` | Clear the current custom-answer draft. | `Type something.` input |
|
|
19
19
|
| `Ctrl+]` | Collapse or expand the dialog. Configurable via `collapseKey`. | Everywhere, including while collapsed |
|
|
20
20
|
|
|
21
|
+
The table names the default keys; the dialog actually follows your Pi keybindings.
|
|
22
|
+
Confirm listens to both `tui.select.confirm` and `tui.input.submit`, and a key bound to
|
|
23
|
+
`tui.input.newLine` always inserts a newline even if it also matches confirm. So a
|
|
24
|
+
Slack-style configuration — `enter` folded into `tui.input.newLine`, submit moved to
|
|
25
|
+
`ctrl+enter` — keeps working: `enter` breaks lines, and your submit key confirms
|
|
26
|
+
everywhere `Enter` does.
|
|
27
|
+
|
|
21
28
|
In a multi-select question, `Enter` on a regular row toggles its checkbox exactly like
|
|
22
29
|
`Space` — it does not submit. Committing the question means focusing the `Next` row and
|
|
23
30
|
pressing `Enter`. That is deliberate: it makes `Enter` a zero-cost way to flip boxes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
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",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
}
|
|
94
94
|
},
|
|
95
95
|
"dependencies": {
|
|
96
|
-
"@juicesharp/rpiv-config": "^2.
|
|
96
|
+
"@juicesharp/rpiv-config": "^2.6.0",
|
|
97
97
|
"typebox": "^1.1.24"
|
|
98
98
|
}
|
|
99
99
|
}
|
|
@@ -130,6 +130,13 @@ class QuestionnaireBuilder {
|
|
|
130
130
|
const textEditorTheme = editorTheme(this.theme);
|
|
131
131
|
this.notesInput = new Editor(this.tui, textEditorTheme);
|
|
132
132
|
this.inlineInput = new Editor(this.tui, textEditorTheme);
|
|
133
|
+
// The key router owns confirm/submit semantics; keys reaching these headless
|
|
134
|
+
// editors are text-editing only. Without this, a `tui.input.submit` match inside
|
|
135
|
+
// Editor.handleInput would run submitValue(), which resets the buffer and
|
|
136
|
+
// silently destroys the draft — no onSubmit is wired here, so the text is
|
|
137
|
+
// unrecoverable (#156).
|
|
138
|
+
this.notesInput.disableSubmit = true;
|
|
139
|
+
this.inlineInput.disableSubmit = true;
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
build(): QuestionnaireBuilt {
|
package/state/key-router.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { QuestionnaireRuntime, QuestionnaireState } from "./state.js";
|
|
|
6
6
|
const KEYBIND_UP = "tui.select.up";
|
|
7
7
|
const KEYBIND_DOWN = "tui.select.down";
|
|
8
8
|
const KEYBIND_CONFIRM = "tui.select.confirm";
|
|
9
|
+
const KEYBIND_SUBMIT = "tui.input.submit";
|
|
9
10
|
const KEYBIND_CANCEL = "tui.select.cancel";
|
|
10
11
|
const KEYBIND_NEW_LINE = "tui.input.newLine";
|
|
11
12
|
const KEYBIND_EDITOR_UP = "tui.editor.cursorUp";
|
|
@@ -39,6 +40,16 @@ export interface QuestionnaireKeybindings {
|
|
|
39
40
|
matches(data: string, name: string): boolean;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
// Confirm has two semantic sources: `tui.select.confirm` (the select-list default)
|
|
44
|
+
// and `tui.input.submit` (the user's "send" key). A Slack-style configuration folds
|
|
45
|
+
// `enter` into `tui.input.newLine` and moves submit elsewhere (e.g. `ctrl+enter`);
|
|
46
|
+
// the newline checks below stay first, so without the submit source every confirm
|
|
47
|
+
// branch would be shadowed by the collision and no key could confirm (#156). With
|
|
48
|
+
// pi defaults both names resolve to `enter`, so matching either is equivalent.
|
|
49
|
+
function isConfirm(kb: QuestionnaireKeybindings, data: string): boolean {
|
|
50
|
+
return kb.matches(data, KEYBIND_CONFIRM) || kb.matches(data, KEYBIND_SUBMIT);
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
export function wrapTab(index: number, total: number): number {
|
|
43
54
|
if (total <= 0) return 0;
|
|
44
55
|
return ((index % total) + total) % total;
|
|
@@ -183,7 +194,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
183
194
|
if (state.notesVisible) {
|
|
184
195
|
if (kb.matches(data, KEYBIND_CANCEL)) return { kind: "notes_exit" };
|
|
185
196
|
if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "notes_forward", data };
|
|
186
|
-
if (kb
|
|
197
|
+
if (isConfirm(kb, data)) return { kind: "notes_exit" };
|
|
187
198
|
return { kind: "notes_forward", data };
|
|
188
199
|
}
|
|
189
200
|
|
|
@@ -191,7 +202,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
191
202
|
// Newline takes precedence over confirmation if a user configuration binds
|
|
192
203
|
// the same physical key to both semantic actions.
|
|
193
204
|
if (kb.matches(data, KEYBIND_NEW_LINE)) return { kind: "ignore" };
|
|
194
|
-
if (kb
|
|
205
|
+
if (isConfirm(kb, data)) {
|
|
195
206
|
const answer = buildSingleSelectAnswer(state, runtime);
|
|
196
207
|
if (!answer) return { kind: "ignore" };
|
|
197
208
|
return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
|
|
@@ -219,7 +230,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
219
230
|
const next = wrapTab(state.submitChoiceIndex + delta, 2);
|
|
220
231
|
return { kind: "submit_nav", nextIndex: (next === 1 ? 1 : 0) as 0 | 1 };
|
|
221
232
|
}
|
|
222
|
-
if (kb
|
|
233
|
+
if (isConfirm(kb, data)) {
|
|
223
234
|
// D1 (revised): Submit always submits; Cancel always cancels. The warning header
|
|
224
235
|
// is informational only — `allAnswered(state)` no longer gates submission. Partial
|
|
225
236
|
// answers flow through `orderedAnswers()` in the host.
|
|
@@ -265,7 +276,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
265
276
|
if (focusedMeta?.activatesInputMode) return { kind: "ignore" };
|
|
266
277
|
return { kind: "toggle", index: state.optionIndex };
|
|
267
278
|
}
|
|
268
|
-
if (kb
|
|
279
|
+
if (isConfirm(kb, data)) {
|
|
269
280
|
// Enter on the "Type something." row is handled by the inputMode block above
|
|
270
281
|
// (→ confirm kind:"custom"). Defensive: never enter the toggle/multi_confirm
|
|
271
282
|
// path for an inputMode-activating row.
|
|
@@ -289,7 +300,7 @@ export function routeKey(data: string, state: QuestionnaireState, runtime: Quest
|
|
|
289
300
|
return { kind: "ignore" };
|
|
290
301
|
}
|
|
291
302
|
|
|
292
|
-
if (kb
|
|
303
|
+
if (isConfirm(kb, data)) {
|
|
293
304
|
const answer = buildSingleSelectAnswer(state, runtime);
|
|
294
305
|
if (!answer) return { kind: "ignore" };
|
|
295
306
|
return { kind: "confirm", answer, autoAdvanceTab: computeAutoAdvanceTab(state, runtime) };
|