@lune_99/pi-ask-question 0.1.0 → 0.2.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/CHANGELOG.md +38 -2
- package/README.md +31 -22
- package/package.json +6 -6
- package/src/commands/question.ts +17 -7
- package/src/core/question-delivery.ts +81 -29
- package/src/core/question-format.ts +36 -11
- package/src/core/questionManager.ts +302 -78
- package/src/index.ts +64 -35
- package/src/tools/ask-user-questions.ts +142 -56
- package/src/tools/withdraw-user-questions.ts +169 -0
- package/src/tui/dock-line.ts +42 -0
- package/src/tui/panel/clipboard-paste.ts +124 -0
- package/src/tui/panel/question-panel-controller.ts +13 -12
- package/src/tui/panel/question-panel-renderer.ts +180 -126
- package/src/tui/panel/question-panel.ts +259 -97
- package/src/tui/preview/preview-box.ts +22 -15
- package/src/tui/preview/preview-layout.ts +7 -4
- package/src/tui/preview/preview-renderer.ts +6 -1
- package/src/tui/question-answer-message.ts +6 -4
- package/src/tui/question-dock-contribution.ts +63 -23
- package/src/tui/question-dock.ts +58 -21
- package/docs/question-answer-row.png +0 -0
- package/docs/question-answer-row.svg +0 -16
- package/docs/question-dock.png +0 -0
- package/docs/question-dock.svg +0 -8
- package/docs/question-panel.svg +0 -58
- package/src/core/question-notification.ts +0 -34
package/CHANGELOG.md
CHANGED
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.2.0] - 2026-11-28
|
|
6
|
+
|
|
7
|
+
> The scoped `@lune_99/pi-ask-question@0.1.0` release on 2026-10-16 already shipped the Lune Dock integration, Dock protocol, Draft 3 snapshot and simplified Dock entries below. The `0.1.0` section after this one describes the earlier unscoped `pi-ask-question@0.1.0` release.
|
|
8
|
+
|
|
5
9
|
### Added
|
|
6
10
|
|
|
7
11
|
- **Optional Lune Dock integration.** Pending request counts join the unified status row when its host is active, and Enter opens the same panel as `/question`. The unified item shows the count, name and status dot without a leading module icon. Without the host, the existing question dock remains available.
|
|
8
12
|
|
|
13
|
+
- **Blocking questions.** `ask_user_questions` takes `mode: "block"` to wait for the answer, which then becomes the tool result instead of a follow-up message. The default `continue` mode does not change. The dock shows `agent waiting`, and `/question` opens that request first; when the run is aborted, the question stays pending and its answer arrives as a message.
|
|
14
|
+
|
|
15
|
+
- **Withdraw a pending question.** The new `withdraw_user_questions` tool lets the model take back its own pending request by id, for example when a file or a chat message answered it. An open panel closes and shows `The agent withdrew: <header> (<reason>)`. A request that the user already answered or skipped is not withdrawn, and its answer still reaches the model.
|
|
16
|
+
|
|
9
17
|
### Changed
|
|
10
18
|
|
|
11
|
-
- **Published Core dependency.** Require `@lune_99/pi-lune-core@^0.1
|
|
19
|
+
- **Published Core dependency.** Require `@lune_99/pi-lune-extensions-core@^0.2.1` from npm instead of a sibling checkout. Core remains a mandatory runtime dependency for shared infrastructure and settings. The scoped 0.1.0 release required `^0.1.0`, which excluded Core 0.2, so an installation kept Core 0.1.0 beside the newer Core that other Lune packages load.
|
|
12
20
|
|
|
13
21
|
- **Dock protocol from Core.** Use `createDockContribution` and its types from
|
|
14
|
-
`@lune_99/pi-lune-core/dock` to join the optional shared Dock. Core supplies the
|
|
22
|
+
`@lune_99/pi-lune-extensions-core/dock` to join the optional shared Dock. Core supplies the
|
|
15
23
|
scoped registry and contributor lifecycle.
|
|
16
24
|
|
|
17
25
|
- **BREAKING: Lune Protocol v1 Draft 3 snapshots.** Publish plugin-styled, single-line base/detail/full Components instead of business summary fields. Idle providers stay registered; Dock owns density, visibility and order, while Enter opens the existing plugin UI. Update the host and both plugins together.
|
|
@@ -20,6 +28,34 @@
|
|
|
20
28
|
session UI cleanup, and host-presence switching. The existing independent status bar is
|
|
21
29
|
restored immediately when Lune Dock is disabled through `/dock` or is absent.
|
|
22
30
|
|
|
31
|
+
- **Fewer and smaller state entries.** The question state is written only when it differs from what the branch already records, so quitting and `/tree` no longer add an entry to sessions that never asked a question. A settled request keeps only its headers, questions and option labels, and it leaves the outbox when the run settles instead of at the next session start.
|
|
32
|
+
|
|
33
|
+
- **Below-editor dock counts questions.** The `N pending questions` row counts the questions inside every pending request, so one request with three questions reads `3 pending questions`. The Lune Dock item still counts requests.
|
|
34
|
+
|
|
35
|
+
- **Shorter tool prompt.** Each `ask_user_questions` rule is stated once, either in the guidelines or in the field description, which cuts the prompt by about a quarter.
|
|
36
|
+
|
|
37
|
+
- **Smaller npm package.** Only the gallery image `docs/question-panel.png` is published; the README already loads its images from GitHub.
|
|
38
|
+
|
|
39
|
+
- **Short request ids in the tool result.** New requests get an eight-digit hex id, and the `ask_user_questions` result now shows it (`Request id: 3f2a9c1e`), so the model can pass it to `withdraw_user_questions`. Requests restored from older sessions keep their UUIDs.
|
|
40
|
+
|
|
41
|
+
- **Quieter idle Dock item.** All display levels show only `○ Ask` when no requests are pending, matching Agents without the `· idle` suffix. Pending-request counts and waiting indicators are unchanged.
|
|
42
|
+
|
|
43
|
+
- **Dock lines drop whole parts instead of cutting them.** A short Lune Dock cell leaves out the request title, then the count, then `Ask`, so `agent waiting` stays longest. The row below the editor no longer cuts the question at 40 columns: it shows the whole question, its header when the question does not fit, or neither. The `/question to answer` hint stays longer than both.
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- **Tool card while streaming.** The `ask_user_questions` card no longer falls back to pi's raw-argument card while the model is still writing the call.
|
|
48
|
+
|
|
49
|
+
- **Image paste in the answer editor.** pi's paste key (`Ctrl+V`, `Alt+V` on Windows and WSL) now works in the `Type something` editor as it does in pi's editor: an image is saved to a temporary file and pasted as its path, so the model can read it. A paste on the focused `Type something` row opens the editor first. The clipboard is read through pi-tui's native helper, so on Linux it needs an X11 display.
|
|
50
|
+
|
|
51
|
+
- **Tab and the arrow keys leave a free-form question.** A question without options opens its editor by itself, and the editor took `Tab`, `⇧Tab`, `←` and `→`, so the other questions could only be reached after `Esc`. While the editor is open, `Tab` and `⇧Tab` now switch questions and keep the draft; `←` and `→` switch while the editor is empty and move the cursor once it holds text.
|
|
52
|
+
|
|
53
|
+
- **Each session owns its questions.** A Lune Subagents run that selected `ask_user_questions` cleared the main session's pending questions, interrupted a blocking call and released the open panel, because Pi reuses the loaded module for sessions in the same working directory and that state lived in the module. Each extension load now has its own question manager and panel ownership.
|
|
54
|
+
|
|
55
|
+
### Refactored
|
|
56
|
+
|
|
57
|
+
- **Panel and delivery cleanup.** The renderer reads question state through the controller, answer notifications live in `question-delivery.ts`, and the row, label and text helpers are shared instead of repeated.
|
|
58
|
+
|
|
23
59
|
## [0.1.0] - 2026-10-03
|
|
24
60
|
|
|
25
61
|
### Added
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
**Structured questions for [Pi](https://pi.dev): the model asks, the panel opens, and your answer reaches it when you are ready.**
|
|
8
8
|
|
|
9
|
-
`ask_user_questions` is for the decisions the model should not make on its own.
|
|
9
|
+
`ask_user_questions` is for the decisions the model should not make on its own. By default, asking is asynchronous: the question waits in the session while the model keeps working on everything that does not depend on it, and your answer - or a skip - arrives back as a message that resumes it. When the next step depends on the answer, the model can ask in block mode and wait for you instead. Read the panel, take your time, and answer when you get to it.
|
|
10
10
|
|
|
11
11
|
## Quick start
|
|
12
12
|
|
|
@@ -16,7 +16,6 @@ Install from npm:
|
|
|
16
16
|
pi install npm:@lune_99/pi-ask-question
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
Then start Pi normally:
|
|
21
20
|
|
|
22
21
|
```bash
|
|
@@ -26,26 +25,36 @@ pi
|
|
|
26
25
|
## What it does
|
|
27
26
|
|
|
28
27
|
- **Asks without stopping the turn.** The panel opens over the session the moment a decision is needed, and the model carries on with the parts that do not depend on the answer instead of waiting for you.
|
|
28
|
+
- **Waits when the answer must come first.** With `mode: "block"` the model waits for your answer, for example before a delete, a push or a migration, or when the choice controls most of the later work. Your answer becomes the result of the tool call, not a separate message. `Esc` on the panel only closes it, and the model keeps waiting. To stop the model, press `Esc` in the editor as usual: the question then stays pending, and your answer arrives as a message.
|
|
29
|
+
- **Takes back a question that no longer matters.** `withdraw_user_questions` lets the model withdraw its own pending question when a file, a tool or your chat message answered it, or when the plan changed. An open panel closes and tells you what the agent withdrew and why. A question that you already answered or skipped cannot be withdrawn.
|
|
29
30
|
- **Brings the answer back into the session.** Answering or skipping adds a `Questions answered` or `Questions skipped` row to the transcript and resumes the model from there.
|
|
30
31
|
- **A question waits as long as you need.** `Esc` closes the panel without settling anything: a dock below the editor says a question is still pending, and `/question` reopens it with the focused row and your drafts intact.
|
|
31
32
|
- **Survives a restart.** A pending question and what you had written come back after `/reload`, `/resume` or `/tree`.
|
|
32
33
|
- **Compares options before answering.** An option can carry a Markdown preview - a diff, a config block, a mockup - in a pane beside the options, side by side on a wide terminal and stacked under them on a narrow one. A preview is only for you: it never becomes the answer.
|
|
33
34
|
- **Only as tall as its content.** A short question covers as little of the transcript as possible; a long one scrolls, with the tab strip pinned above the body. While you are writing an answer, the body scrolls with you to keep the whole input box - and its cursor - in view instead of clipping the newest lines.
|
|
34
35
|
|
|
36
|
+
## Tools
|
|
37
|
+
|
|
38
|
+
| Tool | |
|
|
39
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
40
|
+
| `ask_user_questions` | Ask one to four questions in one panel. `mode` is `continue` (the default) or `block`. The result gives a short request id, such as `Request id: 3f2a9c1e`. |
|
|
41
|
+
| `withdraw_user_questions` | Withdraw a pending request by its `requestId`, with a short `reason` that the panel shows to you. No message is sent; the tool result is the record. |
|
|
42
|
+
|
|
35
43
|
## Panel
|
|
36
44
|
|
|
37
|
-
| Key
|
|
38
|
-
|
|
|
39
|
-
| `↑` `↓`, `k` `j`
|
|
40
|
-
| `Enter`
|
|
41
|
-
| `Space`
|
|
42
|
-
| `1`–`9`
|
|
43
|
-
| `Tab`, `⇧Tab`, `←` `→`
|
|
44
|
-
| Any printable key except `⇧S
|
|
45
|
-
| `
|
|
46
|
-
| `
|
|
47
|
-
| `Esc`
|
|
48
|
-
|
|
|
45
|
+
| Key | |
|
|
46
|
+
| -------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
+
| `↑` `↓`, `k` `j` | Move between option rows |
|
|
48
|
+
| `Enter` | Confirm the focused row - on a submit row it submits |
|
|
49
|
+
| `Space` | Toggle the focused option in a multi-select question |
|
|
50
|
+
| `1`–`9` | Pick an option by number |
|
|
51
|
+
| `Tab`, `⇧Tab`, `←` `→` | Switch question tabs and the `✓ Submit` tab; in the editor `←` `→` switch only while it is empty |
|
|
52
|
+
| Any printable key except `⇧S`, or a paste, on `Type something` | Open the answer editor with that key or paste |
|
|
53
|
+
| `Ctrl+V` in the editor (`Alt+V` on Windows and WSL) | Paste from the clipboard as in pi's editor: an image becomes the path of a temporary file, copied files become their paths, and other content is pasted as text |
|
|
54
|
+
| `Enter` in the editor | Submit the written answer |
|
|
55
|
+
| `Esc` in the editor | Back to the options, keeping the draft |
|
|
56
|
+
| `Esc` | Close the panel and leave the request pending |
|
|
57
|
+
| `⇧S` | Skip the whole request; inside the editor `S` is text, so leave it with `Esc` first |
|
|
49
58
|
|
|
50
59
|
A single-question request submits on the option press. Several questions walk through their tabs and meet on the `✓ Submit` tab, and submitting with a gap jumps to the first unanswered question instead of doing nothing.
|
|
51
60
|
|
|
@@ -53,12 +62,12 @@ Skip is `Shift+S`, so a plain `s` stays available as the first letter of an answ
|
|
|
53
62
|
|
|
54
63
|
In pi's fullscreen mode the panel also takes the mouse:
|
|
55
64
|
|
|
56
|
-
| Mouse
|
|
57
|
-
|
|
|
58
|
-
| Click a tab
|
|
59
|
-
| Click in the editor
|
|
60
|
-
| Wheel over the preview | Scroll the preview
|
|
61
|
-
| Wheel elsewhere
|
|
65
|
+
| Mouse | |
|
|
66
|
+
| ---------------------- | ----------------------------------------------------------- |
|
|
67
|
+
| Click a tab | Switch question tabs |
|
|
68
|
+
| Click in the editor | Move the cursor |
|
|
69
|
+
| Wheel over the preview | Scroll the preview |
|
|
70
|
+
| Wheel elsewhere | Scroll the body, including a long question or `displayText` |
|
|
62
71
|
|
|
63
72
|
Option rows stay keyboard-only - a click neither focuses nor confirms one - and a press that hits no tab or editor is left to pi's text selection, so the panel's text can still be copied. Regular mode keeps the terminal's own mouse handling, and every action above also has a key.
|
|
64
73
|
|
|
@@ -68,7 +77,7 @@ Answers land in the transcript and resume the model:
|
|
|
68
77
|
|
|
69
78
|
## Pending questions
|
|
70
79
|
|
|
71
|
-
`Esc` is a defer, not a dismissal: the panel closes, the request stays pending, and the dock under the editor says which question `/question` would show next.
|
|
80
|
+
`Esc` is a defer, not a dismissal: the panel closes, the request stays pending, and the dock under the editor says which question `/question` would show next. A row too narrow for the whole question shows its header instead; nothing is cut. While a blocking call waits, the dock shows `agent waiting`, and `/question` opens that request first.
|
|
72
81
|
|
|
73
82
|
With the optional **Lune Dock** host active, this independent row is replaced by a shared one-line dock. Press Down in an empty main editor, select a module with Left/Right, and press Enter to open its panel directly. Closing the panel returns to dock focus. The plugin publishes its own single-line `base`, `detail`, and `full` Components through the Dock protocol in `@lune_99/pi-lune-extensions-core/dock`; `/dock` controls density, visibility and order. Idle state remains available in the shared Dock, and hiding the plugin keeps its snapshots current. Removing the host restores the independent row.
|
|
74
83
|
|
|
@@ -90,7 +99,7 @@ npm run docs:images # regenerate docs/*.svg + docs/*.png (needs rsvg
|
|
|
90
99
|
|
|
91
100
|
`@earendil-works/pi-coding-agent`, `@earendil-works/pi-tui`, and `typebox` are supplied by the Pi host at runtime, so the package declares them as `peerDependencies` with a `"*"` range and never bundles them. They are repeated in `devDependencies` so local typecheck and tests resolve the same modules Pi injects.
|
|
92
101
|
|
|
93
|
-
The Dock contribution comes from `@lune_99/pi-lune-extensions-core/dock`. Core is a required runtime dependency (`@lune_99/pi-lune-extensions-core@^0.1
|
|
102
|
+
The Dock contribution comes from `@lune_99/pi-lune-extensions-core/dock`. Core is a required runtime dependency (`@lune_99/pi-lune-extensions-core@^0.2.1` from npm); no sibling checkout or local build is needed. The optional Dock host is separate: without a compatible host, the plugin keeps its independent status bar.
|
|
94
103
|
|
|
95
104
|
## License
|
|
96
105
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lune_99/pi-ask-question",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Ask the user questions for pi via tool and command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
|
-
"docs",
|
|
8
|
+
"docs/question-panel.png",
|
|
9
9
|
"README.md",
|
|
10
10
|
"CHANGELOG.md",
|
|
11
11
|
"LICENSE"
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"typebox": "*"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@earendil-works/pi-ai": "1.
|
|
54
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
55
|
-
"@earendil-works/pi-tui": "1.
|
|
53
|
+
"@earendil-works/pi-ai": "1.6.0",
|
|
54
|
+
"@earendil-works/pi-coding-agent": "1.6.0",
|
|
55
|
+
"@earendil-works/pi-tui": "1.6.0",
|
|
56
56
|
"@types/node": "^22.20.2",
|
|
57
57
|
"typebox": "1.3.27",
|
|
58
58
|
"typescript": "5.9.3"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@lune_99/pi-lune-extensions-core": "^0.1
|
|
61
|
+
"@lune_99/pi-lune-extensions-core": "^0.2.1"
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/commands/question.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { QuestionManager } from "../core/questionManager.ts";
|
|
4
|
+
import type { QuestionPanels } from "../tui/panel/question-panel.ts";
|
|
5
5
|
|
|
6
6
|
/** Reopen the panel after Esc closed it, without having to ask the model again. */
|
|
7
|
-
export function registerQuestionCommand(
|
|
7
|
+
export function registerQuestionCommand(
|
|
8
|
+
pi: ExtensionAPI,
|
|
9
|
+
manager: QuestionManager,
|
|
10
|
+
panels: QuestionPanels,
|
|
11
|
+
persist: (ctx: ExtensionContext) => void,
|
|
12
|
+
): void {
|
|
8
13
|
pi.registerCommand("question", {
|
|
9
14
|
description: "Open the pending question panel",
|
|
10
|
-
handler: (_args, ctx) => openPendingQuestions(ctx, persist),
|
|
15
|
+
handler: (_args, ctx) => openPendingQuestions(ctx, manager, panels, persist),
|
|
11
16
|
});
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
/** The dock and slash command share panel selection, draft persistence and mode checks. */
|
|
15
|
-
export async function openPendingQuestions(
|
|
20
|
+
export async function openPendingQuestions(
|
|
21
|
+
ctx: ExtensionContext,
|
|
22
|
+
manager: QuestionManager,
|
|
23
|
+
panels: QuestionPanels,
|
|
24
|
+
persist: (ctx: ExtensionContext) => void,
|
|
25
|
+
): Promise<void> {
|
|
16
26
|
if (ctx.mode !== "tui") {
|
|
17
27
|
ctx.ui.notify("Question panel needs interactive mode", "warning");
|
|
18
28
|
return;
|
|
19
29
|
}
|
|
20
|
-
if (
|
|
30
|
+
if (manager.getPendingRequests().length === 0) {
|
|
21
31
|
ctx.ui.notify("No pending questions", "info");
|
|
22
32
|
return;
|
|
23
33
|
}
|
|
24
|
-
await
|
|
34
|
+
await panels.open(ctx, { onDeferred: () => persist(ctx) });
|
|
25
35
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
3
|
import { formatAnswerMessage } from "./question-format.ts";
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
4
|
+
import { toAnswerMessageQuestion, type QuestionManager } from "./questionManager.ts";
|
|
5
|
+
import type { AskQuestionRequest } from "./question-types.ts";
|
|
6
6
|
|
|
7
7
|
/** Custom message type carrying answers (or a skip) back to the model. */
|
|
8
8
|
export const ASK_QUESTION_ANSWER_MESSAGE = "pi-ask-question-answer";
|
|
@@ -17,6 +17,35 @@ export interface QuestionDeliveryOptions {
|
|
|
17
17
|
onError?: (error: unknown) => void;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Attempt delivery as soon as a request settles.
|
|
22
|
+
*
|
|
23
|
+
* This is the initial attempt only. The persistence listener runs first, so the settled
|
|
24
|
+
* request is already in the durable outbox when this send happens; if pi drops the message,
|
|
25
|
+
* reconciliation recovers it instead of the answer being lost with the call.
|
|
26
|
+
*/
|
|
27
|
+
export function registerQuestionAnswerNotifications(
|
|
28
|
+
pi: ExtensionAPI,
|
|
29
|
+
manager: QuestionManager,
|
|
30
|
+
options: QuestionDeliveryOptions = {},
|
|
31
|
+
): () => void {
|
|
32
|
+
return manager.subscribe((event) => {
|
|
33
|
+
if (event.type !== "request-answered" && event.type !== "request-skipped") {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const request = manager.get(event.id);
|
|
38
|
+
|
|
39
|
+
// A request answered into a waiting tool call has no outbox entry: the tool result
|
|
40
|
+
// already carries the answer.
|
|
41
|
+
if (!request) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
deliverQuestionResult(pi, request, options);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
20
49
|
/**
|
|
21
50
|
* Attempt delivery of one settled request.
|
|
22
51
|
*
|
|
@@ -62,50 +91,73 @@ export function deliverQuestionResult(
|
|
|
62
91
|
*/
|
|
63
92
|
export function reconcileQuestionDeliveries(
|
|
64
93
|
pi: ExtensionAPI,
|
|
94
|
+
manager: QuestionManager,
|
|
65
95
|
ctx: ExtensionContext,
|
|
66
96
|
options: QuestionDeliveryOptions = {},
|
|
67
97
|
): void {
|
|
68
|
-
for (const request of
|
|
69
|
-
if (hasCommittedAnswerMessage(ctx, request.id)) {
|
|
70
|
-
questionManager.acknowledgeDelivery(request.id);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
|
|
98
|
+
for (const request of releaseDeliveredQuestions(manager, ctx)) {
|
|
74
99
|
deliverQuestionResult(pi, request, options);
|
|
75
100
|
}
|
|
76
101
|
}
|
|
77
102
|
|
|
78
|
-
/**
|
|
79
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Release the settled requests whose answer message the active branch already holds, and
|
|
105
|
+
* return the ones still missing.
|
|
106
|
+
*
|
|
107
|
+
* On its own this never sends. It runs while the session is live, where a missing message may
|
|
108
|
+
* have been cleared from pi's queue by an abort: sending it again would start the turn the user
|
|
109
|
+
* just stopped. The next session start or tree move attempts those again.
|
|
110
|
+
*/
|
|
111
|
+
export function releaseDeliveredQuestions(
|
|
112
|
+
manager: QuestionManager,
|
|
113
|
+
ctx: ExtensionContext,
|
|
114
|
+
): Readonly<AskQuestionRequest>[] {
|
|
115
|
+
const undelivered = manager.getUndeliveredRequests();
|
|
116
|
+
|
|
117
|
+
if (undelivered.length === 0) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const committed = committedRequestIds(ctx);
|
|
122
|
+
const missing: Readonly<AskQuestionRequest>[] = [];
|
|
123
|
+
|
|
124
|
+
for (const request of undelivered) {
|
|
125
|
+
if (committed.has(request.id)) {
|
|
126
|
+
manager.acknowledgeDelivery(request.id);
|
|
127
|
+
} else {
|
|
128
|
+
missing.push(request);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return missing;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Request ids of the answer messages the active branch really holds. */
|
|
136
|
+
export function committedRequestIds(ctx: ExtensionContext): Set<string> {
|
|
137
|
+
const ids = new Set<string>();
|
|
138
|
+
|
|
80
139
|
for (const entry of ctx.sessionManager.getBranch()) {
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
)
|
|
86
|
-
|
|
140
|
+
if (entry.type !== "custom_message" || entry.customType !== ASK_QUESTION_ANSWER_MESSAGE) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const requestId = answerRequestId(entry.details);
|
|
145
|
+
|
|
146
|
+
if (requestId !== undefined) {
|
|
147
|
+
ids.add(requestId);
|
|
87
148
|
}
|
|
88
149
|
}
|
|
89
150
|
|
|
90
|
-
return
|
|
151
|
+
return ids;
|
|
91
152
|
}
|
|
92
153
|
|
|
93
154
|
/** The stable identity of an answer message; details without a string requestId never match. */
|
|
94
|
-
function
|
|
155
|
+
function answerRequestId(details: unknown): string | undefined {
|
|
95
156
|
if (details === null || typeof details !== "object") {
|
|
96
|
-
return
|
|
157
|
+
return undefined;
|
|
97
158
|
}
|
|
98
159
|
|
|
99
160
|
const candidate = details as { requestId?: unknown };
|
|
100
161
|
|
|
101
|
-
return typeof candidate.requestId === "string"
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** The answer row reads the label, the prompt and the option names; previews stay in the panel. */
|
|
105
|
-
function toAnswerMessageQuestion(question: AskQuestion): AnswerMessageQuestion {
|
|
106
|
-
return {
|
|
107
|
-
header: question.header,
|
|
108
|
-
question: question.question,
|
|
109
|
-
options: question.options?.map((option) => ({ label: option.label })),
|
|
110
|
-
};
|
|
162
|
+
return typeof candidate.requestId === "string" ? candidate.requestId : undefined;
|
|
111
163
|
}
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
AnswerMessageQuestion,
|
|
5
5
|
AskQuestionAnswer,
|
|
6
6
|
AskQuestionRequest,
|
|
7
|
-
} from "./
|
|
7
|
+
} from "./question-types.ts";
|
|
8
8
|
|
|
9
9
|
/** Widest a tab label gets before it is cut, so several tabs still fit one row. */
|
|
10
10
|
export const TAB_LABEL_MAX_WIDTH = 16;
|
|
@@ -32,21 +32,24 @@ export function questionHeaderPrefix(question: AnswerMessageQuestion): string {
|
|
|
32
32
|
return label.length === 0 ? "" : `${label}: `;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
export function
|
|
37
|
-
|
|
35
|
+
/** Model-written text as one plain row: no terminal sequences, line breaks or runs of spaces. */
|
|
36
|
+
export function singleLine(text: string): string {
|
|
37
|
+
return stripTerminalSequences(text)
|
|
38
38
|
.replace(/[\r\n\t]/g, " ")
|
|
39
39
|
.replace(/ +/g, " ")
|
|
40
40
|
.trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Collapse a question (or option text) onto one row for a dock or a header. */
|
|
44
|
+
export function summarizeText(text: string, maxWidth: number): string {
|
|
45
|
+
const line = singleLine(text);
|
|
41
46
|
|
|
42
47
|
if (maxWidth <= 0) {
|
|
43
48
|
return "";
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
// The budget is terminal columns: a CJK question is longer on screen than in code units.
|
|
47
|
-
return visibleWidth(
|
|
48
|
-
? singleLine
|
|
49
|
-
: truncateToWidth(singleLine, maxWidth, "…");
|
|
52
|
+
return visibleWidth(line) <= maxWidth ? line : truncateToWidth(line, maxWidth, "…");
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
/** Numbered label of one option as the panel shows it: `2. Name`. */
|
|
@@ -89,21 +92,43 @@ export function formatAnswerMessage(request: AskQuestionRequest): string {
|
|
|
89
92
|
const lines: string[] = ["The user answered these questions.", ""];
|
|
90
93
|
|
|
91
94
|
for (const [index, question] of request.questions.entries()) {
|
|
92
|
-
lines.push(
|
|
95
|
+
lines.push(
|
|
96
|
+
question.question,
|
|
97
|
+
`answer: ${formatAnswer(question, request.answers?.[index]) ?? "unanswered"}`,
|
|
98
|
+
"",
|
|
99
|
+
);
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
return lines.join("\n").trimEnd();
|
|
96
103
|
}
|
|
97
104
|
|
|
105
|
+
/** The headers of a request as one plain label, such as `Storage, Auth`. */
|
|
106
|
+
export function requestHeaders(request: { questions: readonly AnswerMessageQuestion[] }): string {
|
|
107
|
+
return request.questions
|
|
108
|
+
.map((question) => singleLine(question.header ?? ""))
|
|
109
|
+
.filter((header) => header.length > 0)
|
|
110
|
+
.join(", ");
|
|
111
|
+
}
|
|
112
|
+
|
|
98
113
|
/**
|
|
99
114
|
* Model-facing text of the tool result, which returns before any answer exists.
|
|
100
115
|
*
|
|
101
|
-
* The questions are left out on purpose: they are the tool call's own arguments
|
|
102
|
-
*
|
|
116
|
+
* The questions are left out on purpose: they are the tool call's own arguments and do not
|
|
117
|
+
* belong in the context twice. The request id is the handle for `withdraw_user_questions`.
|
|
103
118
|
*/
|
|
104
|
-
export function formatPendingMessage(): string {
|
|
119
|
+
export function formatPendingMessage(requestId: string): string {
|
|
105
120
|
return [
|
|
106
121
|
"Questions are pending. Continue any independent work.",
|
|
107
122
|
"The user's answers will arrive as a follow-up message.",
|
|
123
|
+
`Request id: ${requestId}`,
|
|
124
|
+
].join("\n");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Model-facing text of a blocking call whose wait was aborted before the user answered. */
|
|
128
|
+
export function formatInterruptedMessage(requestId: string): string {
|
|
129
|
+
return [
|
|
130
|
+
"Interrupted before the user answered. The questions stay pending.",
|
|
131
|
+
"The user's answers will arrive as a follow-up message.",
|
|
132
|
+
`Request id: ${requestId}`,
|
|
108
133
|
].join("\n");
|
|
109
134
|
}
|