pi-asker 1.1.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 CHANGED
@@ -26,7 +26,7 @@ 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
- - **RPC hosts** – in RPC mode (e.g. Paseo) the questions are asked one native `select`/`input` dialog at a time; Paseo shows them in its own question form. Discuss, the note and the side-by-side preview are terminal-only.
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
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.
31
31
 
32
32
  ## Install
@@ -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.",
@@ -646,55 +648,67 @@ class Dialog implements Component, Focusable {
646
648
 
647
649
  type DialogUI = Pick<ExtensionContext["ui"], "select" | "input">;
648
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
+
649
655
  /**
650
- * RPC hosts (such as Paseo) cannot render `ui.custom()`, but render `select` and `input`
651
- * natively. Walk the questions one dialog at a time. The option lines, the trailing
652
- * "Type something." row and the follow-up input match what Paseo's built-in
653
- * ask_user_question adapter answers, so Paseo shows its own question form instead.
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.
654
662
  */
655
663
  async function askViaDialogs(ui: DialogUI, questions: Question[], signal?: AbortSignal): Promise<Details> {
656
664
  const answers: Answer[] = [];
665
+ let canType = true;
657
666
  for (const q of questions) {
658
- const lines = q.options.map((o, i) => `${i + 1}. ${o.label} — ${o.description}`);
659
667
  const title = `[${q.header}] ${q.question}`;
660
- let values: string[] | undefined;
661
- if (q.multiSelect) {
662
- const reply = await ui.input(
663
- `${title}\n\n${lines.join("\n")}\n\nEnter the numbers of all that apply, comma-separated (e.g. "1,3"), or type your own answer.`,
664
- "1,3",
665
- { signal },
666
- );
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 });
667
678
  if (reply === undefined) return { answers, cancelled: true };
668
- const text = reply.trim();
669
- const indices = /^\d+(\s*,\s*\d+)*$/.test(text) ? text.split(",").map((n) => Number(n) - 1) : [];
670
- values = indices.length
671
- ? q.options.filter((_, i) => indices.includes(i)).map((o) => o.label)
672
- : text
673
- ? [text]
674
- : [];
675
- } else {
676
- const other = `${q.options.length + 1}. Type something.`;
677
- while (!values) {
678
- const chosen = await ui.select(title, [...lines, other], { signal });
679
- if (chosen === undefined) return { answers, cancelled: true };
680
- const index = lines.indexOf(chosen);
681
- if (index >= 0) {
682
- values = [q.options[index].label];
683
- } else if (chosen === other) {
684
- // Cancelling or leaving the free-text input empty goes back to the options.
685
- const typed = (await ui.input(`${title}\n\nType your answer:`, "", { signal }))?.trim();
686
- if (typed) values = [typed];
687
- } else if (chosen.trim()) {
688
- // Some hosts let the user type a reply instead of picking a line.
689
- values = [chosen.trim()];
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();
690
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] };
691
705
  }
692
706
  }
693
- const option = q.multiSelect ? undefined : q.options.find((o) => o.label === values[0]);
707
+ const option = q.multiSelect ? undefined : q.options.find((o) => o.label === result.values[0]);
694
708
  answers.push({
695
709
  header: q.header,
696
710
  question: q.question,
697
- values,
711
+ ...result,
698
712
  ...(option?.preview ? { preview: option.preview } : {}),
699
713
  });
700
714
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-asker",
3
- "version": "1.1.0",
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
5
  "keywords": [
6
6
  "pi-package"