@juicesharp/rpiv-ask-user-question 1.5.0 → 1.5.2
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/ask-user-question.ts +12 -7
- package/config.ts +43 -0
- package/package.json +2 -1
package/ask-user-question.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { loadConfig, validateGuidanceFields } from "./config.js";
|
|
2
3
|
import { displayLabel } from "./state/i18n-bridge.js";
|
|
3
4
|
import { QuestionnaireSession } from "./state/questionnaire-session.js";
|
|
4
5
|
import { sentinelsToAppend } from "./state/row-intent.js";
|
|
@@ -30,7 +31,16 @@ export function buildItemsForQuestion(question: QuestionData): WrappingSelectIte
|
|
|
30
31
|
return items;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
export const DEFAULT_PROMPT_SNIPPET = `Ask the user up to ${MAX_QUESTIONS} structured questions (${MIN_OPTIONS}-${MAX_OPTIONS} options each) when requirements are ambiguous`;
|
|
35
|
+
export const DEFAULT_PROMPT_GUIDELINES: string[] = [
|
|
36
|
+
`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.`,
|
|
37
|
+
`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 single-select questions) or pick "Chat about this" to abandon the questionnaire.`,
|
|
38
|
+
`Set multiSelect: true when multiple answers are valid; this suppresses the "Type something." row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the "Type something." row (no room in the side-by-side layout); "Chat about this" remains the escape hatch. If you recommend a specific option, make it the first option and append "(Recommended)" to its label.`,
|
|
39
|
+
"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.",
|
|
40
|
+
];
|
|
41
|
+
|
|
33
42
|
export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
|
|
43
|
+
const guidance = validateGuidanceFields(loadConfig().guidance);
|
|
34
44
|
pi.registerTool({
|
|
35
45
|
name: "ask_user_question",
|
|
36
46
|
label: "Ask User Question",
|
|
@@ -53,13 +63,8 @@ Use the optional \`preview\` field on options when presenting concrete artifacts
|
|
|
53
63
|
- Configuration examples
|
|
54
64
|
|
|
55
65
|
Preview content is rendered as markdown in a monospace box. Multi-line text with newlines is supported. When any option has a preview, the UI switches to a side-by-side layout with a vertical option list on the left and preview on the right. Do not use previews for simple preference questions where labels and descriptions suffice. Note: previews are only supported for single-select questions (not multiSelect).`,
|
|
56
|
-
promptSnippet:
|
|
57
|
-
promptGuidelines:
|
|
58
|
-
`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.`,
|
|
59
|
-
`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 single-select questions) or pick "Chat about this" to abandon the questionnaire.`,
|
|
60
|
-
`Set multiSelect: true when multiple answers are valid; this suppresses the "Type something." row. Provide an options[].preview markdown string when an option benefits from richer side-by-side context (mockups, code snippets, diagrams, configs) — single-select only. NOTE: any non-empty preview on a single-select question ALSO suppresses the "Type something." row (no room in the side-by-side layout); "Chat about this" remains the escape hatch. If you recommend a specific option, make it the first option and append "(Recommended)" to its label.`,
|
|
61
|
-
"Do not stack multiple ask_user_question calls back-to-back — group all clarifying questions into one invocation.",
|
|
62
|
-
],
|
|
66
|
+
promptSnippet: guidance.promptSnippet ?? DEFAULT_PROMPT_SNIPPET,
|
|
67
|
+
promptGuidelines: guidance.promptGuidelines ?? DEFAULT_PROMPT_GUIDELINES,
|
|
63
68
|
parameters: QuestionParamsSchema,
|
|
64
69
|
|
|
65
70
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
package/config.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
const CONFIG_DIR = join(homedir(), ".config", "rpiv-ask-user-question");
|
|
6
|
+
const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
7
|
+
|
|
8
|
+
interface GuidanceFields {
|
|
9
|
+
promptSnippet?: string;
|
|
10
|
+
promptGuidelines?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface AskUserQuestionConfig {
|
|
14
|
+
guidance?: GuidanceFields;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function loadConfig(): AskUserQuestionConfig {
|
|
18
|
+
if (!existsSync(CONFIG_PATH)) return {};
|
|
19
|
+
try {
|
|
20
|
+
const parsed = JSON.parse(readFileSync(CONFIG_PATH, "utf-8")) as unknown;
|
|
21
|
+
if (parsed === null || typeof parsed !== "object") return {};
|
|
22
|
+
return parsed as AskUserQuestionConfig;
|
|
23
|
+
} catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function validateGuidanceFields(fields: unknown): GuidanceFields {
|
|
29
|
+
if (!fields || typeof fields !== "object") return {};
|
|
30
|
+
const g = fields as Record<string, unknown>;
|
|
31
|
+
const result: GuidanceFields = {};
|
|
32
|
+
if (typeof g.promptSnippet === "string" && g.promptSnippet.length > 0) {
|
|
33
|
+
result.promptSnippet = g.promptSnippet;
|
|
34
|
+
}
|
|
35
|
+
if (
|
|
36
|
+
Array.isArray(g.promptGuidelines) &&
|
|
37
|
+
g.promptGuidelines.length > 0 &&
|
|
38
|
+
g.promptGuidelines.every((s) => typeof s === "string" && s.length > 0)
|
|
39
|
+
) {
|
|
40
|
+
result.promptGuidelines = g.promptGuidelines;
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
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",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
29
|
"ask-user-question.ts",
|
|
30
|
+
"config.ts",
|
|
30
31
|
"index.ts",
|
|
31
32
|
"LICENSE",
|
|
32
33
|
"locales/",
|