pi-asker 1.0.0 → 1.1.1
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 -1
- package/extensions/ask-user-question.ts +79 -4
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ An `ask_user_question` tool for [pi](https://pi.dev). When the model would other
|
|
|
26
26
|
- **Previews** – mockups, code or configs shown next to the options (below them in narrow terminals). Text is kept verbatim; fenced code blocks are syntax highlighted.
|
|
27
27
|
- **Review** – the Submit tab lists every answer, warns about unanswered questions, and takes an optional note for the model.
|
|
28
28
|
- **No hard limits** – the schema only requires one question and two options. The tool description steers the model towards a few short questions instead.
|
|
29
|
-
- **
|
|
29
|
+
- **RPC hosts** – in RPC mode (e.g. Paseo, or JetBrains through pi-acp) the questions are asked one native `select` dialog at a time, with checkboxes and a "Done" row for multi-select; Paseo shows them in its own question form. Hosts that refuse text input (pi-acp) get "Answer in the chat instead" in place of "Type something.". Discuss, the note and the side-by-side preview are terminal-only.
|
|
30
|
+
- **Interactive only** – in print and JSON mode (and in subagents) the tool is hidden from the model, since there is no one to answer.
|
|
30
31
|
|
|
31
32
|
## Install
|
|
32
33
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExtensionAPI, highlightCode, type Theme } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import { type ExtensionAPI, type ExtensionContext, highlightCode, type Theme } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import {
|
|
3
3
|
type Component,
|
|
4
4
|
type Focusable,
|
|
@@ -102,6 +102,7 @@ const DESCRIPTION = `Ask the user one or more structured questions during execut
|
|
|
102
102
|
Each question is a tab; the user can move freely between them and reviews all answers on a final Submit tab, where they can also add a note for you.
|
|
103
103
|
|
|
104
104
|
Usage notes:
|
|
105
|
+
- The dialog must stand on its own: the user may not see anything you wrote before the call. Put the context needed to answer into the question and the option descriptions, e.g. which file, finding or trade-off it is about.
|
|
105
106
|
- Every question gets two rows appended automatically: a free-text row ("Type something.") and a "Discuss this question" row. Do NOT author "Other", "Type something" or "Discuss" options yourself.
|
|
106
107
|
- A question the user flags for discussion is NOT answered. The result says so, with what they are unsure about; discuss it with them before acting on it.
|
|
107
108
|
- The user may submit with questions unanswered or press Esc to decline the whole questionnaire.
|
|
@@ -121,6 +122,7 @@ Previews are shown as preformatted monospace text next to the option list (below
|
|
|
121
122
|
const PROMPT_SNIPPET = "Ask the user structured multiple-choice questions when requirements are ambiguous";
|
|
122
123
|
|
|
123
124
|
const PROMPT_GUIDELINES = [
|
|
125
|
+
"Make every ask_user_question self-contained: the user may not see text written before the call, so state in the question and option descriptions what it is about and what each choice means.",
|
|
124
126
|
"Use ask_user_question whenever the user's request is underspecified and you cannot proceed without concrete decisions. Batch the related clarifying questions of one decision point into one call.",
|
|
125
127
|
"Give every question at least 2 distinct options, each with a short label and a description of what it means or its trade-offs. A free-text row and a discuss row are appended automatically; never author 'Other', 'Type something' or 'Discuss' options.",
|
|
126
128
|
"Set multiSelect: true when several answers can apply. Use options[].preview for concrete artifacts to compare (mockups, code, configs) on single-select questions. Put a recommended option first and append '(Recommended)' to its label.",
|
|
@@ -644,11 +646,80 @@ class Dialog implements Component, Focusable {
|
|
|
644
646
|
}
|
|
645
647
|
}
|
|
646
648
|
|
|
649
|
+
type DialogUI = Pick<ExtensionContext["ui"], "select" | "input">;
|
|
650
|
+
|
|
651
|
+
const DONE_ROW = "Done";
|
|
652
|
+
const CHAT_ROW = "Answer in the chat instead";
|
|
653
|
+
const CHAT_NOTE = "they will give their own answer in the chat";
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* RPC hosts cannot render `ui.custom()`, but render `select` and `input` natively. Walk the
|
|
657
|
+
* questions one `select` at a time; a multi-select question repeats its `select` with
|
|
658
|
+
* checkboxes until the user picks "Done". The option lines, the "Type something." row right
|
|
659
|
+
* after them and the follow-up input match what Paseo's built-in ask_user_question adapter
|
|
660
|
+
* answers, so Paseo shows its own question form instead. Some hosts (pi-acp) refuse every
|
|
661
|
+
* `input`: once one is refused, "Type something." becomes a row that defers the answer to the chat.
|
|
662
|
+
*/
|
|
663
|
+
async function askViaDialogs(ui: DialogUI, questions: Question[], signal?: AbortSignal): Promise<Details> {
|
|
664
|
+
const answers: Answer[] = [];
|
|
665
|
+
let canType = true;
|
|
666
|
+
for (const q of questions) {
|
|
667
|
+
const title = `[${q.header}] ${q.question}`;
|
|
668
|
+
const box = (checked: boolean) => (q.multiSelect ? (checked ? "[✔] " : "[ ] ") : "");
|
|
669
|
+
const chosen = new Set<number>();
|
|
670
|
+
let typed = "";
|
|
671
|
+
let result: Pick<Answer, "values" | "discuss"> | undefined;
|
|
672
|
+
while (!result) {
|
|
673
|
+
const lines = q.options.map((o, i) => `${box(chosen.has(i))}${i + 1}. ${o.label} — ${o.description}`);
|
|
674
|
+
const other = canType
|
|
675
|
+
? `${box(typed !== "")}${q.options.length + 1}. ${typed || "Type something."}`
|
|
676
|
+
: `${q.options.length + 1}. ${CHAT_ROW}`;
|
|
677
|
+
const reply = await ui.select(title, [...lines, other, ...(q.multiSelect ? [DONE_ROW] : [])], { signal });
|
|
678
|
+
if (reply === undefined) return { answers, cancelled: true };
|
|
679
|
+
const index = lines.indexOf(reply);
|
|
680
|
+
if (index >= 0) {
|
|
681
|
+
if (!q.multiSelect) result = { values: [q.options[index].label] };
|
|
682
|
+
else if (!chosen.delete(index)) chosen.add(index);
|
|
683
|
+
} else if (reply === other) {
|
|
684
|
+
if (!canType) {
|
|
685
|
+
result = { values: [], discuss: CHAT_NOTE };
|
|
686
|
+
} else if (typed) {
|
|
687
|
+
typed = "";
|
|
688
|
+
} else {
|
|
689
|
+
// Cancelling or leaving the input empty goes back to the options.
|
|
690
|
+
const text = await ui.input(`${title}\n\nType your answer:`, "", { signal });
|
|
691
|
+
if (text === undefined) canType = false;
|
|
692
|
+
else if (!q.multiSelect && text.trim()) result = { values: [text.trim()] };
|
|
693
|
+
else typed = text.trim();
|
|
694
|
+
}
|
|
695
|
+
} else if (reply === DONE_ROW) {
|
|
696
|
+
const values = q.options.filter((_, i) => chosen.has(i)).map((o) => o.label);
|
|
697
|
+
result = { values: typed ? [...values, typed] : values };
|
|
698
|
+
} else if (reply.trim()) {
|
|
699
|
+
// Some hosts answer with typed text instead of a row; Paseo answers a multi-select
|
|
700
|
+
// question with the option numbers, e.g. "1,3".
|
|
701
|
+
const text = reply.trim();
|
|
702
|
+
const numbers = q.multiSelect && /^\d+(\s*,\s*\d+)*$/.test(text) ? text.split(",").map((n) => Number(n) - 1) : [];
|
|
703
|
+
const values = q.options.filter((_, i) => numbers.includes(i)).map((o) => o.label);
|
|
704
|
+
result = { values: values.length ? values : [text] };
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
const option = q.multiSelect ? undefined : q.options.find((o) => o.label === result.values[0]);
|
|
708
|
+
answers.push({
|
|
709
|
+
header: q.header,
|
|
710
|
+
question: q.question,
|
|
711
|
+
...result,
|
|
712
|
+
...(option?.preview ? { preview: option.preview } : {}),
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
return { answers, cancelled: false };
|
|
716
|
+
}
|
|
717
|
+
|
|
647
718
|
export default function (pi: ExtensionAPI) {
|
|
648
|
-
// Without
|
|
649
|
-
//
|
|
719
|
+
// Without any UI (print, JSON, subagents) there is no one to answer, so the model should
|
|
720
|
+
// not see the tool at all. The mode is fixed for the process.
|
|
650
721
|
pi.on("before_agent_start", (_event, ctx) => {
|
|
651
|
-
if (ctx.mode === "tui") return;
|
|
722
|
+
if (ctx.mode === "tui" || ctx.mode === "rpc") return;
|
|
652
723
|
const active = pi.getActiveTools();
|
|
653
724
|
if (active.includes(TOOL_NAME)) pi.setActiveTools(active.filter((name) => name !== TOOL_NAME));
|
|
654
725
|
});
|
|
@@ -666,6 +737,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
666
737
|
prepareArguments: parseArgs,
|
|
667
738
|
|
|
668
739
|
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
740
|
+
if (ctx.mode === "rpc") {
|
|
741
|
+
const details = await askViaDialogs(ctx.ui, params.questions, signal);
|
|
742
|
+
return { content: [{ type: "text", text: envelope(details) }], details };
|
|
743
|
+
}
|
|
669
744
|
const details = await ctx.ui.custom<Details>((tui, theme, _keybindings, done) => {
|
|
670
745
|
const dialog = new Dialog(tui, theme, params.questions, done);
|
|
671
746
|
signal?.addEventListener("abort", () => dialog.cancel(), { once: true });
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-asker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "ask_user_question for pi: tabs, multi-select, previews, a review tab, and a way to flag a question for discussion",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package"
|
|
7
|
+
],
|
|
6
8
|
"license": "MIT",
|
|
7
9
|
"author": "msvart",
|
|
8
10
|
"repository": {
|
|
@@ -10,9 +12,15 @@
|
|
|
10
12
|
"url": "git+https://github.com/msvart/pi-asker.git"
|
|
11
13
|
},
|
|
12
14
|
"type": "module",
|
|
13
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"extensions",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
14
20
|
"pi": {
|
|
15
|
-
"extensions": [
|
|
21
|
+
"extensions": [
|
|
22
|
+
"./extensions/ask-user-question.ts"
|
|
23
|
+
]
|
|
16
24
|
},
|
|
17
25
|
"peerDependencies": {
|
|
18
26
|
"@earendil-works/pi-coding-agent": "*",
|