@po.dev/pi-ask-me 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.
Files changed (3) hide show
  1. package/README.md +45 -0
  2. package/index.ts +40 -0
  3. package/package.json +26 -0
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # pi-ask-me
2
+
3
+ Pi extension that lets the agent ask you a question and **block the turn** until you answer. Also reports that blocked state to [herdr](https://github.com/lukilev/herdr).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:@po.dev/pi-ask-me
9
+ ```
10
+
11
+ Or load locally:
12
+
13
+ ```bash
14
+ pi -e ./pi-ask-me/index.ts
15
+ ```
16
+
17
+ ## Features
18
+
19
+ - `ask_me` tool — the agent asks, the turn parks on an `await` until you answer
20
+ - Bridges Pi 0.84.4+ `ui_prompt_start` / `ui_prompt_end` → `herdr:blocked` event
21
+ - Tool call and result render blank; the overlay already shows both
22
+
23
+ ## ask_me
24
+
25
+ ```
26
+ question string the question to ask
27
+ options string[] optional choices (renders a select instead of an input)
28
+ ```
29
+
30
+ `executionMode: "sequential"` so the model can't batch `ask_me` with `bash`/`write` and have those side effects run before you see the prompt.
31
+
32
+ ## How blocking works
33
+
34
+ Only these calls fire `ui_prompt_start`:
35
+
36
+ ```
37
+ ctx.ui.select() ctx.ui.confirm() ctx.ui.input() ctx.ui.editor() ctx.ui.custom()
38
+ ```
39
+
40
+ A plain-text agent reply does **not** block — the turn has already ended, so Pi emits no signal. "Blocked" means the code is actually parked, not that a human hasn't replied yet.
41
+
42
+ ## Requirements
43
+
44
+ - Pi >= 0.84.4 (for the `ui_prompt_*` events)
45
+ - herdr, only if you want the blocked state displayed somewhere
package/index.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * pi-ask-me
3
+ *
4
+ * 1. Bridges Pi 0.84.4+ ui_prompt_start/end events → herdr:blocked.
5
+ * Fires when ctx.ui.select / confirm / input / editor / custom opens.
6
+ * 2. Registers ask_me, a tool the agent can call to block on purpose.
7
+ *
8
+ * Plain-text agent replies do NOT block — there is no Pi signal for that.
9
+ */
10
+ import { Type } from "typebox";
11
+ import { Text } from "@earendil-works/pi-tui";
12
+
13
+ const blank = () => new Text("", 0, 0);
14
+
15
+ export default function (pi: any) {
16
+ pi.on("ui_prompt_start", () => pi.events.emit("herdr:blocked", { active: true }));
17
+ pi.on("ui_prompt_end", () => pi.events.emit("herdr:blocked", { active: false }));
18
+
19
+ pi.registerTool({
20
+ name: "ask_me",
21
+ label: "Ask Me",
22
+ description: "Ask the user a question and wait for the answer. Blocks the turn until answered.",
23
+ promptSnippet: "Ask the user a question and block until they answer",
24
+ executionMode: "sequential",
25
+ parameters: Type.Object({
26
+ question: Type.String({ description: "The question to ask" }),
27
+ options: Type.Optional(Type.Array(Type.String(), { description: "Choices to pick from" })),
28
+ }),
29
+ async execute(_id: string, params: any, _signal: any, _onUpdate: any, ctx: any) {
30
+ if (!ctx.hasUI) return { content: [{ type: "text", text: "No UI available." }] };
31
+ const answer = params.options?.length
32
+ ? await ctx.ui.select(params.question, params.options)
33
+ : await ctx.ui.input(params.question, "");
34
+ return { content: [{ type: "text", text: answer ?? "(cancelled)" }] };
35
+ },
36
+ // The overlay already showed the question and answer — don't log it twice.
37
+ renderCall: blank,
38
+ renderResult: blank,
39
+ });
40
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@po.dev/pi-ask-me",
3
+ "version": "0.1.0",
4
+ "description": "Report blocked state to herdr, plus an ask_me tool that blocks the turn",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "herdr",
9
+ "blocked",
10
+ "ask"
11
+ ],
12
+ "license": "MIT",
13
+ "files": [
14
+ "index.ts",
15
+ "README.md"
16
+ ],
17
+ "peerDependencies": {
18
+ "@earendil-works/pi-coding-agent": "*",
19
+ "@earendil-works/pi-tui": "*"
20
+ },
21
+ "pi": {
22
+ "extensions": [
23
+ "./index.ts"
24
+ ]
25
+ }
26
+ }