@lune_99/pi-ask-question 0.0.0-stage → 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 ADDED
@@ -0,0 +1,102 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
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
+
9
+ ### Added
10
+
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.
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
+
17
+ ### Changed
18
+
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.
20
+
21
+ - **Dock protocol from Core.** Use `createDockContribution` and its types from
22
+ `@lune_99/pi-lune-extensions-core/dock` to join the optional shared Dock. Core supplies the
23
+ scoped registry and contributor lifecycle.
24
+
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.
26
+
27
+ - **Simplified Dock integration.** The shared contributor adapter owns registration,
28
+ session UI cleanup, and host-presence switching. The existing independent status bar is
29
+ restored immediately when Lune Dock is disabled through `/dock` or is absent.
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
+
59
+ ## [0.1.0] - 2026-10-03
60
+
61
+ ### Added
62
+
63
+ - **Interactive question panel.** `ask_user_questions` opens a centered overlay as soon as the tool call arrives: tabbed questions, numbered options with descriptions, multi-select checkboxes, and a `Type something` row for free-form answers. `displayText` renders as Markdown above the options, and a single-question request submits on the option press while several questions walk through a Submit tab.
64
+ - **Option preview pane.** An option's `preview` renders as Markdown in a bordered pane beside the options while it is focused, side by side on wide terminals and stacked under them on narrow ones. The pane is titled with the option label in its border, trimmed of the blank lines a preview may carry, and only as tall as what is left after trimming. The pane keeps its place with a `No preview available` placeholder for an option without a preview, and steps aside while the free-form editor is open so typing gets the full width. The block is sized to the room the panel actually has - rows that no longer fit are reported in its bottom border instead of being clipped, and on a terminal too short for even that the pane is left out rather than drawn half-height.
65
+ - **Deferred answering, skipping and handover.** Esc closes the panel without settling the request, keeping the focused row and written drafts in `questionManager`, and `⇧S` skips the whole request. The below-editor dock shows `N pending question · <question> · /question to answer`, and `/question` reopens the next pending request with its draft. A request that arrives while a panel is open no longer needs `/question`: answering (or skipping) the current one hands the panel over to the next pending request on its own. A defer is quiet on purpose - it ends the chain and leaves every request pending for `/question` or the next incoming request.
66
+ - **Async answers and restart persistence.** The tool returns while the panel stays open; answering or skipping sends a `lune-ask-question-answer` follow-up message (`triggerTurn`, `deliverAs: "steer"`) so the model resumes, rendered as a "Questions answered" or "Questions skipped" row. The message is sent exactly once per settle, and a delivery that fails outright is reported in the UI instead of dropping the answer silently. Pending questions and drafts are snapshotted with `pi.appendEntry` and restored from the active branch on `session_start` and `session_tree`, so a question survives Esc and a Pi restart.
67
+ - **Real-TUI observer.** `npm run tui:demo` starts Pi with a scripted faux model that asks one question, for watching the panel, Esc, `/question` and `⇧S` by hand; `LAQ_DEMO=two npm run tui:demo` queues a second request while the first panel is open to watch the handover.
68
+ - **README and generated reference images.** `npm run docs:images` renders the README screenshots (`docs/question-panel.png`, `question-dock.png`, `question-answer-row.png`) from the real panel, dock and answer-row renderers against Pi's dark theme palette, and the package declares its gallery image. The images are regenerated by one command instead of re-photographed, so they cannot drift from the UI. Needs `rsvg-convert`.
69
+ - **Mouse support for tabs and the editor.** In pi's fullscreen mode (the default since pi 1.0.0) a click on a tab switches questions and a click in the open editor moves its cursor. 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.
70
+ - **Wheel scrolling for the body and the preview.** The wheel scrolls the body, so a question or `displayText` taller than the panel can be read from the top instead of only around the focused row, and over the preview pane it scrolls the preview, whose border now reports rows hidden above and below. The next key or a tab switch returns the body to the focused row.
71
+
72
+ ### Changed
73
+
74
+ - **`displayText` and `options[].preview` have separate jobs.** `displayText` is the context every option shares - a diff, an excerpt, the values in play - while a preview belongs to one option and changes with focus, so the same block does not have to be written into both. The old wording described the two as equally suitable for code and snippets, which invited the model to duplicate them.
75
+ - **A new question outranks one that was only deferred.** The panel picks the least recently shown pending request, so a question that just arrived surfaces immediately instead of an older one the user dismissed with Esc; requests that were never shown keep their creation order. `/question` and the below-editor dock follow the same order.
76
+ - **BREAKING: every question now needs a short `header`.** `ask_user_questions` requires a subject label per question (`Storage`, `Auth`, `Timeouts`) and the panel shows it as the tab label, on the submit row and on the answer row; the generated `Q1`/`Q2` numbering is gone from the panel, the tool result and the follow-up message. The header is required rather than derived from the question text, because a truncated sentence reads worse in a tab than a label and a number says nothing about where the tab leads.
77
+ - **The panel is only as tall as its content.** The body no longer pads itself to a fixed height or stops at a fixed row cap: a request is rendered whole while the terminal has room for it, and only scrolls when it genuinely does not fit the screen. A short question therefore covers as little of the transcript as possible, and a long one is not clipped to an arbitrary number of rows.
78
+ - **The free-form row no longer mirrors typing.** `Type something` stays in place while the editor is open and the row shows an answer only once it is committed, so it no longer rewrites itself on every keystroke or follows edits to an answer that was already written. The draft is untouched: it still lives in the editor, survives Esc, and is restored with the request.
79
+ - **Typing on the free-form row opens the editor.** Focusing `Type something` and pressing a printable key starts the answer without `Enter` first, and on that row the single-key shortcuts are text while they keep working on the option rows and on the submit tab.
80
+ - **`options[].example` is now `options[].preview`.** The field holds Markdown and renders in a pane beside the options for the focused option instead of as one grey line under every option, which is what makes code, config blocks and mockups comparable before answering. A preview is display input only: it is never echoed into the answer the model receives.
81
+ - **Extension surface.** The scaffold's placeholder `ask-question` tool and `/ask` command are replaced by `ask_user_questions` (model-only, sequential) and `/question`; outside the interactive TUI the tool reports that plain text is required instead of waiting for an answer that can never arrive.
82
+ - **The model-facing tool result is a status line.** `ask_user_questions` no longer echoes the request id or repeats the questions, which are already in the tool call's own arguments; the id stays in the result `details` for the UI.
83
+ - **The answer message stores only what the transcript shows.** `details.questions` carries the header, the prompt and the option labels instead of the whole question, so a `displayText` or an option `preview` no longer stays in the session file forever.
84
+ - **Peer dependencies follow the Pi package contract.** The host-provided packages stay on the `"*"` range Pi requires, and the redundant `peerDependenciesMeta.optional` is gone: Pi already suppresses peer installation, and an extension cannot run without them. `devDependencies` names the versions this release is tested against, currently Pi 1.0.0.
85
+
86
+ ### Fixed
87
+
88
+ - **An answer survives until the session really carries it.** `pi.sendMessage()` only queues a steered message and can drop it, while the answered request left the durable snapshot the moment it settled - so an answer lost from pi's queue was gone for good. Settled answers and skips now stay in a durable outbox until the session branch holds their `lune-ask-question-answer` message (matched by `requestId`); a restore retries delivery while it is missing and releases the entry once it is there.
89
+ - **The tab strip no longer scrolls out of view.** When a request's content was taller than the panel's height cap, the body scrolled and took the tabs with it, leaving a multi-question panel with no way to see or reach the other questions. The strip is now pinned above the scrolling body, which itself only appears when the content does not fit the terminal.
90
+ - **A large paste survives Esc and a restart.** The draft was captured with `Editor.getText()`, which returns a `[paste #1 +12 lines]` marker for any paste over ten lines or a thousand characters; that marker was what got restored, and the pasted answer was gone. Capture now uses `getExpandedText()`, so a pasted answer comes back whole.
91
+ - **A session start does not render into the session that replaced it.** Listeners were replaced after the state reset, so clearing the old state woke the previous session's still-subscribed listener and drew a dock through its context. They are replaced before any change that would wake them.
92
+ - **A stale panel cannot take over the panel that replaced it.** Overlay ownership was a boolean that a session boundary cleared, so a panel that resolved after `/reload`, `/resume` or `/tree` released - and its loop kept using - the panel of the session that had replaced it. Opening is now guarded by a generation and an owner token, and `session_tree` resets them the way `session_start` does, so `/question` still opens after a tree jump.
93
+ - **Skipping works on a free-form question.** A free-form request opens its editor immediately and the editor turns printable keys into text, so a plain `s` could never reach the skip shortcut - while the footer advertised it. Skip is now `Shift+S`, and a plain `s` is always the letter it is; the one place that asks for `Enter` first is a `Type something` row whose answer starts with a capital `S`.
94
+ - **Shift+S skips on terminals using the Kitty keyboard protocol.** The shortcut only matched the literal `"S"` byte, but a kitty-protocol terminal reports a modified key as a CSI sequence such as `\x1b[115:83;2u` instead, so skip was unreachable there while the footer advertised it. The key is now matched through pi's own key parser, which accepts every spelling of `Shift+S`.
95
+ - **A failed snapshot no longer sticks the panel.** `Esc` wrote the snapshot before closing the overlay, so a throwing `appendEntry` left the panel up with no way out, and the same throw could cut short a shutdown or a tree switch. Persistence now reports the failure instead of raising it, and the overlay closes either way.
96
+ - **The dock follows the request `/question` would reopen.** `markShown` moved a request behind the ones it had already been shown after without emitting an event, so the dock could name one question while `/question` opened another. It now emits `request-shown`, which also writes the new order to the session immediately instead of at the next settle point.
97
+ - **A snapshot that could not be written is reported.** Listener failures were swallowed, which could hide a persistence error while the in-memory state moved on. The manager reports them, and the extension says that the question state could not be saved.
98
+ - **The open editor is no longer clipped while the answer grows.** The body window followed the focused option row, so an answer taller than the room left under the question pushed the editor's bottom border, the `Enter to submit` hint and the cursor past the panel's bottom edge - the newest lines looked like they had left the input box. While the editor owns the keys the window now scrolls to hold the whole editor block, falling back to the cursor line when the block itself cannot fit, and a wheel scroll still pins wherever the reader left it.
99
+
100
+ ### Refactored
101
+
102
+ - **The panel's interaction model and renderer are separate modules.** `QuestionPanelController` owns the draft transitions and the row model, `QuestionPanelRenderer` owns the frame, option rows and preview layout, and `QuestionPanel` is left with input routing, editor ownership and overlay lifecycle. The draft stays the single source of interaction state, so existing exports, behavior and persistence are unchanged.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nouvelle-Lune
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,111 @@
1
- # Temporary Holding Version
1
+ # Lune Ask Question
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm version](https://img.shields.io/npm/v/@lune_99/pi-ask-question.svg)](https://www.npmjs.com/package/@lune_99/pi-ask-question) [![npm downloads](https://img.shields.io/npm/dw/@lune_99/pi-ask-question.svg)](https://www.npmjs.com/package/@lune_99/pi-ask-question) [![license](https://img.shields.io/npm/l/@lune_99/pi-ask-question.svg)](https://github.com/Nouvelle-Lune/lune-pi/blob/main/packages/pi-ask-question/LICENSE)
4
+
5
+ ![Lune Ask Question preview](https://raw.githubusercontent.com/Nouvelle-Lune/lune-pi/main/packages/pi-ask-question/docs/question-panel.png)
6
+
7
+ **Structured questions for [Pi](https://pi.dev): the model asks, the panel opens, and your answer reaches it when you are ready.**
8
+
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
+
11
+ ## Quick start
12
+
13
+ Install from npm:
14
+
15
+ ```bash
16
+ pi install npm:@lune_99/pi-ask-question
17
+ ```
18
+
19
+ Then start Pi normally:
20
+
21
+ ```bash
22
+ pi
23
+ ```
24
+
25
+ ## What it does
26
+
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.
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.
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.
32
+ - **Survives a restart.** A pending question and what you had written come back after `/reload`, `/resume` or `/tree`.
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.
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.
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
+
43
+ ## Panel
44
+
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 |
58
+
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.
60
+
61
+ Skip is `Shift+S`, so a plain `s` stays available as the first letter of an answer; on a `Type something` row, an answer that starts with a capital `S` starts with `Enter` instead.
62
+
63
+ In pi's fullscreen mode the panel also takes the mouse:
64
+
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` |
71
+
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.
73
+
74
+ Answers land in the transcript and resume the model:
75
+
76
+ ![The Questions answered row: header, question and the selected option or written answer for each question](https://raw.githubusercontent.com/Nouvelle-Lune/lune-pi/main/packages/pi-ask-question/docs/question-answer-row.png)
77
+
78
+ ## Pending questions
79
+
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.
81
+
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.
83
+
84
+ ![The below-editor dock: 1 pending question, the next question and the /question hint](https://raw.githubusercontent.com/Nouvelle-Lune/lune-pi/main/packages/pi-ask-question/docs/question-dock.png)
85
+
86
+ A question that just arrived surfaces immediately, while one you only deferred waits its turn. A request that arrives while a panel is open does not need `/question`: answering the current one hands the panel over to the next.
87
+
88
+ ## Development
89
+
90
+ ```bash
91
+ npm install
92
+ npm test
93
+ npm run typecheck
94
+ npm run tui:demo # real pi TUI, scripted model, one question
95
+ LAQ_DEMO=two npm run tui:demo # queue a second request to watch the handover
96
+ LAQ_DEMO=multi npm run tui:demo # one request with three questions, to watch the tabs
97
+ npm run docs:images # regenerate docs/*.svg + docs/*.png (needs rsvg-convert)
98
+ ```
99
+
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.
101
+
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.
103
+
104
+ ## License
105
+
106
+ MIT
107
+
108
+ Lune Dock can be toggled with `/dock`. Turning it off immediately restores this plugin's
109
+ independent status bar. The choice belongs to Lune Dock and is saved in
110
+ `~/.pi/agent/lune-settings/pi-dock.json` (following `PI_CODING_AGENT_DIR`; a project can
111
+ override it in `<project>/.pi/lune-settings/pi-dock.json`).
Binary file
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
- "name": "@lune_99/pi-ask-question",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@lune_99/pi-ask-question",
3
+ "version": "0.2.0",
4
+ "description": "Ask the user questions for pi via tool and command",
5
+ "type": "module",
6
+ "files": [
7
+ "src",
8
+ "docs/question-panel.png",
9
+ "README.md",
10
+ "CHANGELOG.md",
11
+ "LICENSE"
12
+ ],
13
+ "pi": {
14
+ "extensions": [
15
+ "./src/index.ts"
16
+ ],
17
+ "image": "./docs/question-panel.png"
18
+ },
19
+ "scripts": {
20
+ "test": "node --experimental-strip-types --test 'test/**/*.test.ts'",
21
+ "typecheck": "tsc --noEmit",
22
+ "tui:demo": "node --experimental-strip-types test/tui/launch.ts",
23
+ "docs:images": "node --experimental-strip-types tools/make-doc-images.mjs",
24
+ "prepublishOnly": "npm run typecheck && npm test"
25
+ },
26
+ "keywords": [
27
+ "pi-package",
28
+ "pi",
29
+ "pi-coding-agent",
30
+ "ask",
31
+ "question"
32
+ ],
33
+ "author": "Nouvelle-Lune",
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/Nouvelle-Lune/lune-pi.git",
38
+ "directory": "packages/pi-ask-question"
39
+ },
40
+ "homepage": "https://github.com/Nouvelle-Lune/lune-pi/tree/main/packages/pi-ask-question#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/Nouvelle-Lune/lune-pi/issues"
43
+ },
44
+ "engines": {
45
+ "node": ">=22.19.0"
46
+ },
47
+ "peerDependencies": {
48
+ "@earendil-works/pi-coding-agent": "*",
49
+ "@earendil-works/pi-tui": "*",
50
+ "typebox": "*"
51
+ },
52
+ "devDependencies": {
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
+ "@types/node": "^22.20.2",
57
+ "typebox": "1.3.27",
58
+ "typescript": "5.9.3"
59
+ },
60
+ "dependencies": {
61
+ "@lune_99/pi-lune-extensions-core": "^0.2.1"
62
+ }
63
+ }
@@ -0,0 +1,35 @@
1
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+
3
+ import type { QuestionManager } from "../core/questionManager.ts";
4
+ import type { QuestionPanels } from "../tui/panel/question-panel.ts";
5
+
6
+ /** Reopen the panel after Esc closed it, without having to ask the model again. */
7
+ export function registerQuestionCommand(
8
+ pi: ExtensionAPI,
9
+ manager: QuestionManager,
10
+ panels: QuestionPanels,
11
+ persist: (ctx: ExtensionContext) => void,
12
+ ): void {
13
+ pi.registerCommand("question", {
14
+ description: "Open the pending question panel",
15
+ handler: (_args, ctx) => openPendingQuestions(ctx, manager, panels, persist),
16
+ });
17
+ }
18
+
19
+ /** The dock and slash command share panel selection, draft persistence and mode checks. */
20
+ export async function openPendingQuestions(
21
+ ctx: ExtensionContext,
22
+ manager: QuestionManager,
23
+ panels: QuestionPanels,
24
+ persist: (ctx: ExtensionContext) => void,
25
+ ): Promise<void> {
26
+ if (ctx.mode !== "tui") {
27
+ ctx.ui.notify("Question panel needs interactive mode", "warning");
28
+ return;
29
+ }
30
+ if (manager.getPendingRequests().length === 0) {
31
+ ctx.ui.notify("No pending questions", "info");
32
+ return;
33
+ }
34
+ await panels.open(ctx, { onDeferred: () => persist(ctx) });
35
+ }
@@ -0,0 +1,163 @@
1
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+
3
+ import { formatAnswerMessage } from "./question-format.ts";
4
+ import { toAnswerMessageQuestion, type QuestionManager } from "./questionManager.ts";
5
+ import type { AskQuestionRequest } from "./question-types.ts";
6
+
7
+ /** Custom message type carrying answers (or a skip) back to the model. */
8
+ export const ASK_QUESTION_ANSWER_MESSAGE = "pi-ask-question-answer";
9
+
10
+ export interface QuestionDeliveryOptions {
11
+ /**
12
+ * Called when the answer could not be handed to pi at all.
13
+ *
14
+ * The request stays in the durable outbox either way; without this notice the user would
15
+ * never learn that the model never received the answer.
16
+ */
17
+ onError?: (error: unknown) => void;
18
+ }
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
+
49
+ /**
50
+ * Attempt delivery of one settled request.
51
+ *
52
+ * A normal return is not an acknowledgement: pi can queue a steered message and drop it
53
+ * before it reaches the session. The caller keeps the request in the durable outbox until
54
+ * the branch really contains its message, so this function never mutates the outbox.
55
+ */
56
+ export function deliverQuestionResult(
57
+ pi: ExtensionAPI,
58
+ request: Readonly<AskQuestionRequest>,
59
+ options: QuestionDeliveryOptions = {},
60
+ ): void {
61
+ try {
62
+ pi.sendMessage(
63
+ {
64
+ customType: ASK_QUESTION_ANSWER_MESSAGE,
65
+ content: formatAnswerMessage(request),
66
+ display: true,
67
+ details: {
68
+ requestId: request.id,
69
+ status: request.status,
70
+ questions: request.questions.map(toAnswerMessageQuestion),
71
+ answers: request.answers,
72
+ },
73
+ },
74
+ {
75
+ triggerTurn: true,
76
+ deliverAs: "steer",
77
+ },
78
+ );
79
+ } catch (error) {
80
+ options.onError?.(error);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Reconcile the durable outbox against the session branch of `ctx`.
86
+ *
87
+ * The branch is the only acknowledgement: a settled request whose answer message is really
88
+ * there is released, and the release is persisted; one whose message is missing - never
89
+ * sent, or dropped by pi's queue - is attempted again. Matching is by requestId, so one
90
+ * request's message says nothing about another's.
91
+ */
92
+ export function reconcileQuestionDeliveries(
93
+ pi: ExtensionAPI,
94
+ manager: QuestionManager,
95
+ ctx: ExtensionContext,
96
+ options: QuestionDeliveryOptions = {},
97
+ ): void {
98
+ for (const request of releaseDeliveredQuestions(manager, ctx)) {
99
+ deliverQuestionResult(pi, request, options);
100
+ }
101
+ }
102
+
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
+
139
+ for (const entry of ctx.sessionManager.getBranch()) {
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);
148
+ }
149
+ }
150
+
151
+ return ids;
152
+ }
153
+
154
+ /** The stable identity of an answer message; details without a string requestId never match. */
155
+ function answerRequestId(details: unknown): string | undefined {
156
+ if (details === null || typeof details !== "object") {
157
+ return undefined;
158
+ }
159
+
160
+ const candidate = details as { requestId?: unknown };
161
+
162
+ return typeof candidate.requestId === "string" ? candidate.requestId : undefined;
163
+ }