@juicesharp/rpiv-ask-user-question 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # rpiv-ask-user-question
2
+
3
+ Pi extension that registers the `ask_user_question` tool — a structured option
4
+ selector (with free-text "Other" fallback) for disambiguating underspecified
5
+ user requests. Replaces Claude Code's `AskUserQuestion`.
6
+
7
+ ## Installation
8
+
9
+ pi install npm:@juicesharp/rpiv-ask-user-question
10
+
11
+ Then restart your Pi session.
12
+
13
+ ## Tool
14
+
15
+ - **`ask_user_question`** — present a structured question with 2+ options and
16
+ (optionally) a multi-select toggle. Returns the user's selection or free-text
17
+ answer. See the tool's `promptGuidelines` for usage policy.
18
+
19
+ ## License
20
+
21
+ MIT
@@ -0,0 +1,116 @@
1
+ /**
2
+ * ask_user_question tool — replaces Claude Code's AskUserQuestion.
3
+ *
4
+ * Registration function: call registerAskUserQuestionTool(pi) from index.ts.
5
+ */
6
+
7
+ import { type ExtensionAPI, DynamicBorder } from "@mariozechner/pi-coding-agent";
8
+ import { Container, SelectList, Spacer, Text, type SelectItem } from "@mariozechner/pi-tui";
9
+ import { Type } from "@sinclair/typebox";
10
+
11
+ export function registerAskUserQuestionTool(pi: ExtensionAPI): void {
12
+ const OptionSchema = Type.Object({
13
+ label: Type.String({ description: "Display label for the option" }),
14
+ description: Type.Optional(Type.String({ description: "Optional description shown below label" })),
15
+ });
16
+
17
+ pi.registerTool({
18
+ name: "ask_user_question",
19
+ label: "Ask User Question",
20
+ description:
21
+ "Ask the user a structured question with selectable options. Use when you need user input to proceed — choosing between approaches, confirming scope, resolving ambiguities. The user can also type a custom answer.",
22
+ promptSnippet: "Ask the user a structured question when requirements are ambiguous",
23
+ promptGuidelines: [
24
+ "Use the ask_user_question tool whenever the user's request is underspecified and you cannot proceed without a concrete decision.",
25
+ "Prefer ask_user_question over prose 'please tell me X' — the structured selector gives the user concrete options and records their choice in session history.",
26
+ "This replaces the AskUserQuestion tool from Claude Code. The user can always pick 'Other (type your own answer)' for free-text input.",
27
+ ],
28
+ parameters: Type.Object({
29
+ question: Type.String({ description: "The question to ask the user" }),
30
+ header: Type.Optional(Type.String({ description: "Section header for the question" })),
31
+ options: Type.Array(OptionSchema, { description: "Options for the user to choose from" }),
32
+ multiSelect: Type.Optional(
33
+ Type.Boolean({ description: "Allow multiple selections. Default: false", default: false }),
34
+ ),
35
+ }),
36
+
37
+ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
38
+ if (!ctx.hasUI) {
39
+ return {
40
+ content: [{ type: "text", text: "Error: UI not available (running in non-interactive mode)" }],
41
+ details: { question: params.question, answer: null },
42
+ };
43
+ }
44
+
45
+ if (params.options.length === 0) {
46
+ return {
47
+ content: [{ type: "text", text: "Error: No options provided" }],
48
+ details: { question: params.question, answer: null },
49
+ };
50
+ }
51
+
52
+ const headerPrefix = params.header ? `[${params.header}] ` : "";
53
+ const items = params.options.map(
54
+ (o) => `${o.label}${o.description ? ` — ${o.description}` : ""}`,
55
+ );
56
+
57
+ // Add "Other (type something)" option
58
+ const allItems = [...items, "Other (type your own answer)"];
59
+
60
+ const choice = await ctx.ui.custom<string | null>((tui, theme, _kb, done) => {
61
+ const container = new Container();
62
+
63
+ container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
64
+ container.addChild(new Spacer(1));
65
+ container.addChild(new Text(theme.fg("accent", theme.bold(`${headerPrefix}${params.question}`)), 1, 0));
66
+ container.addChild(new Spacer(1));
67
+
68
+ const selectItems: SelectItem[] = allItems.map((item) => ({ value: item, label: item }));
69
+ const selectList = new SelectList(selectItems, Math.min(allItems.length, 10), {
70
+ selectedPrefix: (t) => theme.bg("selectedBg", theme.fg("accent", t)),
71
+ selectedText: (t) => theme.bg("selectedBg", theme.bold(t)),
72
+ description: (t) => theme.fg("muted", t),
73
+ scrollInfo: (t) => theme.fg("dim", t),
74
+ noMatch: (t) => theme.fg("warning", t),
75
+ });
76
+ selectList.onSelect = (item) => done(item.value);
77
+ selectList.onCancel = () => done(null);
78
+ container.addChild(selectList);
79
+
80
+ container.addChild(new Spacer(1));
81
+ container.addChild(new Text(theme.fg("dim", "↑↓ navigate • enter select • esc cancel"), 1, 0));
82
+ container.addChild(new Spacer(1));
83
+ container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
84
+
85
+ return {
86
+ render: (w) => container.render(w),
87
+ invalidate: () => container.invalidate(),
88
+ handleInput: (data) => { selectList.handleInput(data); tui.requestRender(); },
89
+ };
90
+ });
91
+
92
+ if (!choice) {
93
+ return {
94
+ content: [{ type: "text", text: "User cancelled the selection" }],
95
+ details: { question: params.question, answer: null },
96
+ };
97
+ }
98
+
99
+ // If user picked "Other", ask for free-text input
100
+ if (choice === "Other (type your own answer)") {
101
+ const customAnswer = await ctx.ui.input(`${params.question}`, "Type your answer...");
102
+ return {
103
+ content: [{ type: "text", text: `User answered: ${customAnswer ?? "(no input)"}` }],
104
+ details: { question: params.question, answer: customAnswer ?? null, wasCustom: true },
105
+ };
106
+ }
107
+
108
+ // Extract just the label (before the " — " description separator)
109
+ const selectedLabel = choice.split(" — ")[0];
110
+ return {
111
+ content: [{ type: "text", text: `User selected: ${selectedLabel}` }],
112
+ details: { question: params.question, answer: selectedLabel, wasCustom: false },
113
+ };
114
+ },
115
+ });
116
+ }
package/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * rpiv-ask-user-question — Pi extension
3
+ *
4
+ * Registers the `ask_user_question` tool, which surfaces a structured
5
+ * option selector (plus free-text "Other" fallback) to disambiguate
6
+ * underspecified user requests.
7
+ *
8
+ * Extracted from rpiv-pi@7525a5d. Tool name preserved verbatim.
9
+ */
10
+
11
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
12
+ import { registerAskUserQuestionTool } from "./ask-user-question.js";
13
+
14
+ export default function (pi: ExtensionAPI) {
15
+ registerAskUserQuestionTool(pi);
16
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@juicesharp/rpiv-ask-user-question",
3
+ "version": "0.1.0",
4
+ "description": "Pi extension: structured ask_user_question tool for disambiguation prompts",
5
+ "keywords": ["pi-package", "pi-extension", "rpiv"],
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "author": "juicesharp",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/juicesharp/rpiv-ask-user-question.git"
12
+ },
13
+ "homepage": "https://github.com/juicesharp/rpiv-ask-user-question#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/juicesharp/rpiv-ask-user-question/issues"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "pi": {
21
+ "extensions": ["./index.ts"]
22
+ },
23
+ "peerDependencies": {
24
+ "@mariozechner/pi-coding-agent": "*",
25
+ "@mariozechner/pi-tui": "*",
26
+ "@sinclair/typebox": "*"
27
+ }
28
+ }