@juicesharp/rpiv-ask-user-question 1.20.0 → 2.0.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 -2
- package/ask-user-question.ts +171 -31
- package/config.ts +65 -4
- package/index.ts +2 -0
- package/locales/de.json +3 -3
- package/locales/en.json +3 -3
- package/locales/es.json +3 -3
- package/locales/fr.json +3 -3
- package/locales/pt-BR.json +3 -3
- package/locales/pt.json +3 -3
- package/locales/ru.json +3 -3
- package/locales/uk.json +3 -3
- package/locales/zh.json +3 -3
- package/package.json +7 -5
- package/reconcile.ts +47 -0
- package/rpc-fallback.ts +166 -0
- package/state/build-questionnaire.ts +0 -10
- package/state/key-router.ts +25 -61
- package/state/questionnaire-session.ts +41 -7
- package/state/row-intent.ts +21 -37
- package/state/selectors/derivations.ts +4 -39
- package/state/selectors/focus.ts +3 -5
- package/state/selectors/projections.ts +28 -13
- package/state/state-reducer.ts +18 -21
- package/state/state.ts +6 -1
- package/tool/format-answer.ts +6 -24
- package/tool/types.ts +11 -14
- package/view/components/inline-input.ts +96 -0
- package/view/components/multi-select-view.ts +62 -6
- package/view/components/option-list-view.ts +1 -4
- package/view/components/preview/preview-layout-decider.ts +4 -3
- package/view/components/preview/preview-pane.ts +22 -1
- package/view/components/wrapping-select.ts +19 -58
- package/view/dialog-builder.ts +0 -3
- package/view/props-adapter.ts +2 -2
- package/view/stateful-view.ts +6 -7
- package/view/tab-content-strategy.ts +7 -12
- package/view/components/chat-row-view.ts +0 -56
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ Let the model ask you structured clarifying questions instead of guessing. `rpiv
|
|
|
21
21
|
- **Submit tab** - review every answer before submitting; warns about unanswered questions and offers a Submit picker.
|
|
22
22
|
- **Chat row on every tab** - redirect the conversation without leaving the dialog.
|
|
23
23
|
- **Terminal-row-aware overflow scroll** - when the dialog is taller than the terminal, the body scrolls between a sticky heading and sticky hints/border; overflow indicators (↑ / ↓ / ↕) show what's clipped.
|
|
24
|
-
- **"Other" free-text fallback** - type a custom answer when no option fits.
|
|
24
|
+
- **"Other" free-text fallback** - type a custom answer when no option fits; available on every single-select question, even in preview mode (the input expands to the full pane width while typing).
|
|
25
25
|
- **Localized UI** - sentinel rows, hints, submit/cancel labels, review pane, and notes affordance display in the user's chosen language via `@juicesharp/rpiv-i18n`. Ships Deutsch / English / Español / Français / Português (PT) / Português (BR) / Русский / Українська; switch with `/languages` or `pi --locale <code>`. LLM-facing copy (tool description, schemas, errors) stays English by design.
|
|
26
26
|
|
|
27
27
|
## Screens
|
|
@@ -52,7 +52,7 @@ With the SDK present, locale resolves from `--locale <code>` → `~/.config/rpiv
|
|
|
52
52
|
|
|
53
53
|
## Tool
|
|
54
54
|
|
|
55
|
-
- **`ask_user_question`** - present one or more structured questions, each with 2+ options, optional `multiSelect`, optional per-option `preview`, and
|
|
55
|
+
- **`ask_user_question`** - present one or more structured questions, each with 2+ options, optional `multiSelect`, optional per-option `preview`, and a free-text "Other" fallback available on every single-select question (even with previews). Returns the user's selection(s) plus any notes. See the tool's `promptGuidelines` for usage policy.
|
|
56
56
|
|
|
57
57
|
### Schema
|
|
58
58
|
|
package/ask-user-question.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { matchesKey } from "@earendil-works/pi-tui";
|
|
3
|
+
import { loadConfig, resolveCollapseKey, validateGuidanceFields } from "./config.js";
|
|
3
4
|
import { ASK_USER_PROMPT_EVENT, type AskUserPromptEventPayload } from "./events.js";
|
|
5
|
+
// Static import is fine — rpc-fallback pulls only types + the i18n bridge,
|
|
6
|
+
// none of the ~560ms TUI render graph that QuestionnaireSession lazy-loads.
|
|
7
|
+
import { hasDialogUI, runRpcQuestionnaire } from "./rpc-fallback.js";
|
|
4
8
|
import { displayLabel } from "./state/i18n-bridge.js";
|
|
5
9
|
import { sentinelsToAppend } from "./state/row-intent.js";
|
|
6
10
|
import { buildQuestionnaireResponse, buildToolResult } from "./tool/response-envelope.js";
|
|
@@ -9,6 +13,7 @@ import {
|
|
|
9
13
|
MAX_QUESTIONS,
|
|
10
14
|
MIN_OPTIONS,
|
|
11
15
|
type QuestionData,
|
|
16
|
+
type QuestionnaireError,
|
|
12
17
|
type QuestionnaireResult,
|
|
13
18
|
type QuestionParams,
|
|
14
19
|
QuestionParamsSchema,
|
|
@@ -32,16 +37,66 @@ function emitAskUserPromptEvent(pi: ExtensionAPI, params: QuestionParams): void
|
|
|
32
37
|
pi.events.emit(ASK_USER_PROMPT_EVENT, payload);
|
|
33
38
|
}
|
|
34
39
|
|
|
40
|
+
/** Canonical tool name — single source of truth shared with the reconcile module. */
|
|
41
|
+
export const ASK_USER_QUESTION_TOOL_NAME = "ask_user_question";
|
|
42
|
+
|
|
35
43
|
const ERROR_NO_UI = "Error: UI not available (running in non-interactive mode)";
|
|
36
44
|
|
|
45
|
+
const ERROR_NO_CUSTOM_UI =
|
|
46
|
+
"Error: this client cannot render the questionnaire (custom UI is unavailable, e.g. RPC/ACP hosts such as Zed or Paseo). The user never saw the questions — do NOT treat this as a decline. Ask the questions as plain chat text instead, without using this tool.";
|
|
47
|
+
|
|
48
|
+
const ERROR_SESSION_LOAD_FAILED =
|
|
49
|
+
"Error: the questionnaire UI failed to load — the host's installed dependencies were likely replaced or removed on disk while Pi was running (e.g. a package-manager install touched the store). 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 that restoring this tool requires repairing the install if needed and restarting Pi.";
|
|
50
|
+
|
|
51
|
+
const ERROR_STALE_MODULE_CACHE =
|
|
52
|
+
"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.";
|
|
53
|
+
|
|
54
|
+
/** Delay before the background session-graph pre-warm; mirrors rpiv-workflow's /wf prewarm. */
|
|
55
|
+
export const PREWARM_DELAY_MS = 2000;
|
|
56
|
+
|
|
57
|
+
type SessionModule = typeof import("./state/questionnaire-session.js");
|
|
58
|
+
|
|
59
|
+
type SessionLoad =
|
|
60
|
+
| { ok: true; module: SessionModule }
|
|
61
|
+
| { ok: false; error: Extract<QuestionnaireError, "session_load_failed" | "stale_module_cache">; message: string };
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Lazy-load the ~560ms QuestionnaireSession view/TUI render graph, guarding
|
|
65
|
+
* the two failure shapes of issue #107. Pi's jiti loader registers a module in
|
|
66
|
+
* its graph cache BEFORE evaluating the body and does not evict it when
|
|
67
|
+
* evaluation throws (jiti 2.7.0), so one failed load — e.g. `pnpm install
|
|
68
|
+
* --force` replacing the store entry mid-session — leaves every later import
|
|
69
|
+
* of this specifier resolving to a namespace without the class. That state is
|
|
70
|
+
* unrecoverable in-process (cache-busting specifiers fail jiti resolution);
|
|
71
|
+
* both branches therefore return an LLM-facing envelope that names the restart
|
|
72
|
+
* requirement instead of leaking a bare "not a constructor" TypeError.
|
|
73
|
+
*/
|
|
74
|
+
export async function loadQuestionnaireSession(): Promise<SessionLoad> {
|
|
75
|
+
let mod: SessionModule;
|
|
76
|
+
try {
|
|
77
|
+
mod = await import("./state/questionnaire-session.js");
|
|
78
|
+
} catch (e) {
|
|
79
|
+
const cause = e instanceof Error ? e.message : String(e);
|
|
80
|
+
return { ok: false, error: "session_load_failed", message: `${ERROR_SESSION_LOAD_FAILED} (cause: ${cause})` };
|
|
81
|
+
}
|
|
82
|
+
if (typeof mod.QuestionnaireSession !== "function") {
|
|
83
|
+
const keys = JSON.stringify(Object.keys(mod));
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
error: "stale_module_cache",
|
|
87
|
+
message: `${ERROR_STALE_MODULE_CACHE} (resolved namespace keys: ${keys})`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return { ok: true, module: mod };
|
|
91
|
+
}
|
|
92
|
+
|
|
37
93
|
export function buildItemsForQuestion(question: QuestionData): WrappingSelectItem[] {
|
|
38
94
|
const items: WrappingSelectItem[] = question.options.map((o) => ({
|
|
39
95
|
kind: "option",
|
|
40
96
|
label: o.label,
|
|
41
97
|
description: o.description,
|
|
42
98
|
}));
|
|
43
|
-
const
|
|
44
|
-
for (const kind of sentinelsToAppend(question, hasAnyPreview)) {
|
|
99
|
+
for (const kind of sentinelsToAppend(question)) {
|
|
45
100
|
items.push({ kind, label: displayLabel(kind) });
|
|
46
101
|
}
|
|
47
102
|
return items;
|
|
@@ -50,15 +105,15 @@ export function buildItemsForQuestion(question: QuestionData): WrappingSelectIte
|
|
|
50
105
|
export const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;
|
|
51
106
|
export const DEFAULT_PROMPT_GUIDELINES: string[] = [
|
|
52
107
|
`Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions — you can ask up to ${MAX_QUESTIONS} questions per invocation.`,
|
|
53
|
-
`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer ("Type something." row is appended automatically to
|
|
54
|
-
`Set multiSelect: true when multiple answers are valid
|
|
108
|
+
`Each question MUST have ${MIN_OPTIONS}-${MAX_OPTIONS} options. Every option requires a concise label (1-5 words) and a description explaining what the choice means or its trade-offs. The user can additionally type a custom answer ("Type something." row is appended automatically to every question) or press Esc to abandon the questionnaire.`,
|
|
109
|
+
`Set multiSelect: true when multiple answers are valid. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. The "Type something." row is appended to every single-select question regardless of whether any option carries a preview; in preview mode it expands to the full pane width while typing so the custom answer is not cramped into the narrow options column. If you recommend a specific option, make it the first option and append "(Recommended)" to its label.`,
|
|
55
110
|
"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.",
|
|
56
111
|
];
|
|
57
112
|
|
|
58
113
|
export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
|
|
59
114
|
const guidance = validateGuidanceFields(loadConfig().guidance);
|
|
60
115
|
pi.registerTool({
|
|
61
|
-
name:
|
|
116
|
+
name: ASK_USER_QUESTION_TOOL_NAME,
|
|
62
117
|
label: "Ask User Question",
|
|
63
118
|
description: `Ask the user one or more structured questions during execution. Use when you need to:
|
|
64
119
|
1. Gather user preferences or requirements
|
|
@@ -67,8 +122,8 @@ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
|
|
|
67
122
|
4. Offer choices to the user about what direction to take
|
|
68
123
|
|
|
69
124
|
Usage notes:
|
|
70
|
-
- Users will always be able to type a custom answer ("Type something." row is appended automatically to every
|
|
71
|
-
- Use multiSelect: true to allow multiple answers to be selected for a question.
|
|
125
|
+
- Users will always be able to type a custom answer ("Type something." row is appended automatically to every question) or press Esc to abandon the questionnaire. Do NOT author "Other" / "Type something." labels yourself — duplicates are rejected at runtime.
|
|
126
|
+
- Use multiSelect: true to allow multiple answers to be selected for a question. It is always available on every question (even when options carry a \`preview\`), expanding to the full pane width while typing so the custom answer is not cramped into the narrow options column.
|
|
72
127
|
- If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label.
|
|
73
128
|
|
|
74
129
|
Preview feature:
|
|
@@ -99,37 +154,122 @@ Preview content is rendered as markdown in a monospace box. Multi-line text with
|
|
|
99
154
|
// Emit event for external listeners (e.g., notification plugins)
|
|
100
155
|
emitAskUserPromptEvent(pi, typed);
|
|
101
156
|
|
|
157
|
+
// RPC hosts (VSCode pendant, ACP clients like Zed/Paseo — issue #78):
|
|
158
|
+
// ui.custom() cannot render there, but the select/input dialog
|
|
159
|
+
// sub-protocol works. Hosts that advertise ctx.mode (pi ≥0.79) route to
|
|
160
|
+
// the sequential dialog walker up front, skipping the TUI render-graph
|
|
161
|
+
// import entirely; RPC builds that predate ctx.mode are caught by the
|
|
162
|
+
// custom()-resolved-undefined backstop below. See ./rpc-fallback.ts.
|
|
163
|
+
if ((ctx as { mode?: string }).mode === "rpc" && hasDialogUI(ctx.ui)) {
|
|
164
|
+
return buildQuestionnaireResponse(await runRpcQuestionnaire(ctx.ui, typed), typed);
|
|
165
|
+
}
|
|
166
|
+
|
|
102
167
|
const itemsByTab: WrappingSelectItem[][] = typed.questions.map((q) => buildItemsForQuestion(q));
|
|
103
168
|
|
|
104
169
|
// Lazy — QuestionnaireSession pulls the ~560ms view/TUI render graph;
|
|
105
170
|
// load it only when the tool runs, not at extension registration.
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
171
|
+
const sessionLoad = await loadQuestionnaireSession();
|
|
172
|
+
if (!sessionLoad.ok) {
|
|
173
|
+
return buildToolResult(sessionLoad.message, { answers: [], cancelled: true, error: sessionLoad.error });
|
|
174
|
+
}
|
|
175
|
+
const { QuestionnaireSession } = sessionLoad.module;
|
|
176
|
+
// Resolve the collapse/expand key spec from config. Default is `ctrl+]`; users
|
|
177
|
+
// with non-US layouts (e.g. Latin American, where `]` is shifted) can override
|
|
178
|
+
// via the `collapseKey` config field. `resolveCollapseKey` also accepts the
|
|
179
|
+
// sentinel value `"off"` to disable the shortcut entirely.
|
|
180
|
+
const collapseKey = resolveCollapseKey(loadConfig());
|
|
181
|
+
|
|
182
|
+
// Capture the overlay handle so the session can call `setHidden()` when the
|
|
183
|
+
// user toggles collapse, and register a raw terminal input listener for the
|
|
184
|
+
// same key so the toggle still works while the overlay is hidden (pi-tui does
|
|
185
|
+
// not route input to a hidden overlay's `component.handleInput`).
|
|
186
|
+
const sessionRef: {
|
|
187
|
+
current: import("./state/questionnaire-session.js").QuestionnaireSession | null;
|
|
188
|
+
} = { current: null };
|
|
189
|
+
const overlayHandleRef: { current: import("@earendil-works/pi-tui").OverlayHandle | undefined } = {
|
|
190
|
+
current: undefined,
|
|
191
|
+
};
|
|
192
|
+
let hasAnnouncedHide = false;
|
|
193
|
+
let removeOverlayInputListener: (() => void) | undefined;
|
|
194
|
+
|
|
195
|
+
if (collapseKey !== "off" && typeof ctx.ui.onTerminalInput === "function") {
|
|
196
|
+
removeOverlayInputListener = ctx.ui.onTerminalInput((data) => {
|
|
197
|
+
const handle = overlayHandleRef.current;
|
|
198
|
+
if (!handle) return undefined;
|
|
199
|
+
// Only act while the questionnaire is hidden (its handleInput is
|
|
200
|
+
// unreachable) or actually focused. When some other overlay is on
|
|
201
|
+
// top (e.g. `/btw`), leave the keystroke to that overlay instead of
|
|
202
|
+
// toggling the questionnaire from underneath it.
|
|
203
|
+
if (!handle.isHidden() && !handle.isFocused()) return undefined;
|
|
204
|
+
if (!matchesKey(data, collapseKey as Parameters<typeof matchesKey>[1])) return undefined;
|
|
205
|
+
sessionRef.current?.toggleCollapsedExternal();
|
|
206
|
+
if (handle.isHidden() && !hasAnnouncedHide) {
|
|
207
|
+
hasAnnouncedHide = true;
|
|
208
|
+
ctx.ui.notify?.(`ask_user_question hidden — press ${collapseKey} to reopen`, "info");
|
|
209
|
+
}
|
|
210
|
+
return { consume: true };
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const result = await ctx.ui.custom<QuestionnaireResult>(
|
|
216
|
+
(tui, theme, _kb, done) => {
|
|
217
|
+
const session = new QuestionnaireSession({
|
|
218
|
+
tui,
|
|
219
|
+
theme,
|
|
220
|
+
params: typed,
|
|
221
|
+
itemsByTab,
|
|
222
|
+
done,
|
|
223
|
+
collapseKey,
|
|
224
|
+
});
|
|
225
|
+
sessionRef.current = session;
|
|
226
|
+
return session.component;
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
overlay: true,
|
|
230
|
+
overlayOptions: {
|
|
231
|
+
anchor: "bottom-center",
|
|
232
|
+
width: "100%",
|
|
233
|
+
maxHeight: "100%",
|
|
234
|
+
margin: { left: 0, right: 0, bottom: 0 },
|
|
235
|
+
},
|
|
236
|
+
onHandle: (handle) => {
|
|
237
|
+
overlayHandleRef.current = handle;
|
|
238
|
+
sessionRef.current?.setOverlayHandle(handle);
|
|
239
|
+
},
|
|
126
240
|
},
|
|
127
|
-
|
|
128
|
-
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
// A TUI questionnaire ALWAYS resolves a QuestionnaireResult (cancel
|
|
244
|
+
// included — state-reducer emits `{ answers, cancelled }`), so
|
|
245
|
+
// `undefined` uniquely means "host cannot render", never "user
|
|
246
|
+
// declined". RPC builds that predate ctx.mode land here: run the
|
|
247
|
+
// dialog walker when the host has the primitives; otherwise tell the
|
|
248
|
+
// model the user never saw the questions.
|
|
249
|
+
if (result === undefined) {
|
|
250
|
+
if (hasDialogUI(ctx.ui)) {
|
|
251
|
+
return buildQuestionnaireResponse(await runRpcQuestionnaire(ctx.ui, typed), typed);
|
|
252
|
+
}
|
|
253
|
+
return buildToolResult(ERROR_NO_CUSTOM_UI, { answers: [], cancelled: true, error: "no_custom_ui" });
|
|
254
|
+
}
|
|
129
255
|
|
|
130
|
-
|
|
256
|
+
return buildQuestionnaireResponse(result, typed);
|
|
257
|
+
} finally {
|
|
258
|
+
removeOverlayInputListener?.();
|
|
259
|
+
}
|
|
131
260
|
},
|
|
132
261
|
});
|
|
262
|
+
|
|
263
|
+
// Pre-warm the lazy session graph once startup settles (#107). A graph
|
|
264
|
+
// evaluated while the paths Pi resolved at boot still exist stays in memory
|
|
265
|
+
// for the process lifetime, so later on-disk dependency churn (e.g. `pnpm
|
|
266
|
+
// install --force` replacing the store mid-session) can no longer poison
|
|
267
|
+
// jiti's graph cache. Swallowed failure is safe: the first real call
|
|
268
|
+
// re-imports and surfaces it through loadQuestionnaireSession's structured
|
|
269
|
+
// envelope. unref keeps the timer from holding a non-TUI embedder's process
|
|
270
|
+
// open.
|
|
271
|
+
const timer = setTimeout(() => void loadQuestionnaireSession().catch(() => undefined), PREWARM_DELAY_MS);
|
|
272
|
+
timer.unref?.();
|
|
133
273
|
}
|
|
134
274
|
|
|
135
275
|
export { buildQuestionnaireResponse, buildToolResult };
|
package/config.ts
CHANGED
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
import type { GuidanceFields } from "@juicesharp/rpiv-config";
|
|
2
|
-
import {
|
|
2
|
+
import { loadJsonConfigWithLegacyFallback, validateGuidanceFields } from "@juicesharp/rpiv-config";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** Key spec for the overlay collapse/expand shortcut, e.g. `"ctrl+]"` or `"alt+o"`. */
|
|
5
|
+
export type CollapseKeySpec = string;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
export const DEFAULT_COLLAPSE_KEY: CollapseKeySpec = "ctrl+]";
|
|
8
|
+
export const COLLAPSE_KEY_OFF: CollapseKeySpec = "off";
|
|
9
|
+
|
|
10
|
+
export interface AskUserQuestionConfig {
|
|
7
11
|
guidance?: GuidanceFields;
|
|
12
|
+
/**
|
|
13
|
+
* Key spec for the collapse/expand shortcut, in the same format as pi-coding-agent
|
|
14
|
+
* keybinding ids (`modifier+key`, e.g. `ctrl+]`, `alt+o`, `ctrl+shift+h`). Defaults
|
|
15
|
+
* to `"ctrl+]"`. Set this to a key that is reachable on your keyboard layout — Latin
|
|
16
|
+
* American layouts (where `]` is on the shifted layer) often want `"ctrl+}"` instead.
|
|
17
|
+
* Pass `"off"` to disable the collapse shortcut entirely.
|
|
18
|
+
*/
|
|
19
|
+
collapseKey?: CollapseKeySpec;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Named keys accepted by pi-tui's `matchesKey` (keys.js switch on the parsed base key).
|
|
23
|
+
// parseKeyId lowercases the id before matching, so lowercase spellings are canonical.
|
|
24
|
+
const SPECIAL_KEYS = new Set([
|
|
25
|
+
"escape",
|
|
26
|
+
"esc",
|
|
27
|
+
"enter",
|
|
28
|
+
"return",
|
|
29
|
+
"tab",
|
|
30
|
+
"space",
|
|
31
|
+
"backspace",
|
|
32
|
+
"delete",
|
|
33
|
+
"insert",
|
|
34
|
+
"clear",
|
|
35
|
+
"home",
|
|
36
|
+
"end",
|
|
37
|
+
"pageup",
|
|
38
|
+
"pagedown",
|
|
39
|
+
"up",
|
|
40
|
+
"down",
|
|
41
|
+
"left",
|
|
42
|
+
"right",
|
|
43
|
+
...Array.from({ length: 12 }, (_, i) => `f${i + 1}`),
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
const MODIFIERS = new Set(["ctrl", "shift", "alt", "super"]);
|
|
47
|
+
|
|
48
|
+
function isValidCollapseKeySpec(spec: string): boolean {
|
|
49
|
+
// Mirror pi-tui's KeyId grammar strictly: zero or more distinct modifiers, then a
|
|
50
|
+
// base key that is a single printable character or a named special key. A loose
|
|
51
|
+
// check is not enough — pi-tui's `parseKeyId` takes the LAST `+`-part as the key
|
|
52
|
+
// and ignores unknown parts, so a typo like `ctr+]` would silently match every
|
|
53
|
+
// bare `]` keypress (and the raw terminal listener would consume them globally).
|
|
54
|
+
if (!spec) return false;
|
|
55
|
+
if (spec.startsWith("+") || spec.endsWith("+") || spec.includes("++")) return false;
|
|
56
|
+
const parts = spec.split("+");
|
|
57
|
+
const base = parts[parts.length - 1] ?? "";
|
|
58
|
+
const modifiers = parts.slice(0, -1);
|
|
59
|
+
if (modifiers.length !== new Set(modifiers).size) return false;
|
|
60
|
+
if (!modifiers.every((m) => MODIFIERS.has(m))) return false;
|
|
61
|
+
return base.length === 1 ? /[a-z0-9_\-!@#$%^&*()|~`'":;,./<>?[\]{}=\\]/.test(base) : SPECIAL_KEYS.has(base);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function resolveCollapseKey(config: Pick<AskUserQuestionConfig, "collapseKey">): CollapseKeySpec {
|
|
65
|
+
const raw = config.collapseKey?.trim().toLowerCase();
|
|
66
|
+
if (raw === undefined || raw === "") return DEFAULT_COLLAPSE_KEY;
|
|
67
|
+
if (raw === COLLAPSE_KEY_OFF) return COLLAPSE_KEY_OFF;
|
|
68
|
+
return isValidCollapseKeySpec(raw) ? raw : DEFAULT_COLLAPSE_KEY;
|
|
8
69
|
}
|
|
9
70
|
|
|
10
71
|
export function loadConfig(): AskUserQuestionConfig {
|
|
11
|
-
return
|
|
72
|
+
return loadJsonConfigWithLegacyFallback<AskUserQuestionConfig>("rpiv-ask-user-question");
|
|
12
73
|
}
|
|
13
74
|
|
|
14
75
|
export { validateGuidanceFields };
|
package/index.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
19
19
|
import { registerAskUserQuestionTool } from "./ask-user-question.js";
|
|
20
|
+
import { registerAskUserQuestionReconciler } from "./reconcile.js";
|
|
20
21
|
import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
|
|
21
22
|
|
|
22
23
|
type I18nLoader = {
|
|
@@ -46,4 +47,5 @@ export {
|
|
|
46
47
|
|
|
47
48
|
export default function (pi: ExtensionAPI) {
|
|
48
49
|
registerAskUserQuestionTool(pi);
|
|
50
|
+
registerAskUserQuestionReconciler(pi);
|
|
49
51
|
}
|
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
|
-
"
|
|
26
|
-
"
|
|
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
|
-
"
|
|
26
|
-
"
|
|
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
|
-
"
|
|
26
|
-
"
|
|
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
|
-
"
|
|
26
|
-
"
|
|
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
|
}
|
package/locales/pt-BR.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": "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
|
-
"
|
|
26
|
-
"
|
|
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
|
-
"
|
|
26
|
-
"
|
|
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
|
}
|
package/locales/ru.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": "Введите что-нибудь.",
|
|
5
|
-
"sentinel.chat": "Обсудить это",
|
|
6
5
|
"sentinel.next": "Далее",
|
|
7
6
|
|
|
8
7
|
"submit.label": "Отправить ответы",
|
|
@@ -21,7 +20,8 @@
|
|
|
21
20
|
|
|
22
21
|
"preview.no_preview": "Предпросмотр недоступен",
|
|
23
22
|
"preview.notes_affordance": "Заметки: нажмите n, чтобы добавить заметки",
|
|
23
|
+
"notes.header": "Заметки:",
|
|
24
24
|
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"rpc.multi_instructions": "Введите номера всех подходящих вариантов через запятую (например, \"1,3\") или введите свой ответ текстом.",
|
|
26
|
+
"rpc.custom_answer_title": "Введите свой ответ:"
|
|
27
27
|
}
|
package/locales/uk.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": "Введіть щось.",
|
|
5
|
-
"sentinel.chat": "Обговорити це",
|
|
6
5
|
"sentinel.next": "Далі",
|
|
7
6
|
|
|
8
7
|
"submit.label": "Надіслати відповіді",
|
|
@@ -21,7 +20,8 @@
|
|
|
21
20
|
|
|
22
21
|
"preview.no_preview": "Попередній перегляд недоступний",
|
|
23
22
|
"preview.notes_affordance": "Нотатки: натисніть n, щоб додати нотатки",
|
|
23
|
+
"notes.header": "Нотатки:",
|
|
24
24
|
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"rpc.multi_instructions": "Введіть номери всіх відповідних варіантів через кому (наприклад, \"1,3\") або введіть власну відповідь текстом.",
|
|
26
|
+
"rpc.custom_answer_title": "Введіть свою відповідь:"
|
|
27
27
|
}
|
package/locales/zh.json
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
"_meta.notes": "中文翻译。欢迎中文母语者通过 PR 审校。TUI 符号(↑/↓、⚠)为通用 CLI 约定,保持原文不译。Enter、Space 采用中文惯用说法(回车、空格);Esc、Tab、Ctrl、n 等保留原文。",
|
|
3
3
|
|
|
4
4
|
"sentinel.other": "输入内容",
|
|
5
|
-
"sentinel.chat": "聊聊这个",
|
|
6
5
|
"sentinel.next": "下一个",
|
|
7
6
|
|
|
8
7
|
"submit.label": "提交答案",
|
|
@@ -23,7 +22,8 @@
|
|
|
23
22
|
|
|
24
23
|
"preview.no_preview": "暂无预览",
|
|
25
24
|
"preview.notes_affordance": "备注:按 n 添加",
|
|
25
|
+
"notes.header": "备注:",
|
|
26
26
|
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"rpc.multi_instructions": "输入所有适用选项的编号,用逗号分隔(例如 \"1,3\"),或直接输入自定义回答。",
|
|
28
|
+
"rpc.custom_answer_title": "输入你的回答:"
|
|
29
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -31,9 +31,11 @@
|
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"ask-user-question.ts",
|
|
34
|
+
"rpc-fallback.ts",
|
|
34
35
|
"config.ts",
|
|
35
36
|
"events.ts",
|
|
36
37
|
"index.ts",
|
|
38
|
+
"reconcile.ts",
|
|
37
39
|
"LICENSE",
|
|
38
40
|
"locales/",
|
|
39
41
|
"README.md",
|
|
@@ -53,7 +55,7 @@
|
|
|
53
55
|
"tool/types.ts",
|
|
54
56
|
"tool/validate-questionnaire.ts",
|
|
55
57
|
"view/component-binding.ts",
|
|
56
|
-
"view/components/
|
|
58
|
+
"view/components/inline-input.ts",
|
|
57
59
|
"view/components/multi-select-view.ts",
|
|
58
60
|
"view/components/option-list-view.ts",
|
|
59
61
|
"view/components/preview/markdown-content-cache.ts",
|
|
@@ -78,8 +80,7 @@
|
|
|
78
80
|
"peerDependencies": {
|
|
79
81
|
"@juicesharp/rpiv-i18n": "*",
|
|
80
82
|
"@earendil-works/pi-coding-agent": "*",
|
|
81
|
-
"@earendil-works/pi-tui": "*"
|
|
82
|
-
"typebox": "*"
|
|
83
|
+
"@earendil-works/pi-tui": "*"
|
|
83
84
|
},
|
|
84
85
|
"peerDependenciesMeta": {
|
|
85
86
|
"@juicesharp/rpiv-i18n": {
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
}
|
|
88
89
|
},
|
|
89
90
|
"dependencies": {
|
|
90
|
-
"@juicesharp/rpiv-config": "^
|
|
91
|
+
"@juicesharp/rpiv-config": "^2.0.0",
|
|
92
|
+
"typebox": "^1.1.24"
|
|
91
93
|
}
|
|
92
94
|
}
|