pi-asker 1.0.0 → 1.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 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
- - **Interactive only** – in print, JSON and RPC mode (and in subagents) the tool is hidden from the model, since there is no one to answer.
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.
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,
@@ -644,11 +644,68 @@ class Dialog implements Component, Focusable {
644
644
  }
645
645
  }
646
646
 
647
+ type DialogUI = Pick<ExtensionContext["ui"], "select" | "input">;
648
+
649
+ /**
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.
654
+ */
655
+ async function askViaDialogs(ui: DialogUI, questions: Question[], signal?: AbortSignal): Promise<Details> {
656
+ const answers: Answer[] = [];
657
+ for (const q of questions) {
658
+ const lines = q.options.map((o, i) => `${i + 1}. ${o.label} — ${o.description}`);
659
+ 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
+ );
667
+ 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()];
690
+ }
691
+ }
692
+ }
693
+ const option = q.multiSelect ? undefined : q.options.find((o) => o.label === values[0]);
694
+ answers.push({
695
+ header: q.header,
696
+ question: q.question,
697
+ values,
698
+ ...(option?.preview ? { preview: option.preview } : {}),
699
+ });
700
+ }
701
+ return { answers, cancelled: false };
702
+ }
703
+
647
704
  export default function (pi: ExtensionAPI) {
648
- // Without the terminal UI (print, JSON, RPC, subagents) the dialog cannot be shown, so the
649
- // model should not see the tool at all. The mode is fixed for the process.
705
+ // Without any UI (print, JSON, subagents) there is no one to answer, so the model should
706
+ // not see the tool at all. The mode is fixed for the process.
650
707
  pi.on("before_agent_start", (_event, ctx) => {
651
- if (ctx.mode === "tui") return;
708
+ if (ctx.mode === "tui" || ctx.mode === "rpc") return;
652
709
  const active = pi.getActiveTools();
653
710
  if (active.includes(TOOL_NAME)) pi.setActiveTools(active.filter((name) => name !== TOOL_NAME));
654
711
  });
@@ -666,6 +723,10 @@ export default function (pi: ExtensionAPI) {
666
723
  prepareArguments: parseArgs,
667
724
 
668
725
  async execute(_toolCallId, params, signal, _onUpdate, ctx) {
726
+ if (ctx.mode === "rpc") {
727
+ const details = await askViaDialogs(ctx.ui, params.questions, signal);
728
+ return { content: [{ type: "text", text: envelope(details) }], details };
729
+ }
669
730
  const details = await ctx.ui.custom<Details>((tui, theme, _keybindings, done) => {
670
731
  const dialog = new Dialog(tui, theme, params.questions, done);
671
732
  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.0.0",
3
+ "version": "1.1.0",
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": ["pi-package"],
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": ["extensions", "README.md", "LICENSE"],
15
+ "files": [
16
+ "extensions",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
14
20
  "pi": {
15
- "extensions": ["./extensions/ask-user-question.ts"]
21
+ "extensions": [
22
+ "./extensions/ask-user-question.ts"
23
+ ]
16
24
  },
17
25
  "peerDependencies": {
18
26
  "@earendil-works/pi-coding-agent": "*",