pi-ask-question-lite 0.0.0-stage → 0.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/CHANGELOG.md +23 -0
- package/README.md +107 -2
- package/README.zh-CN.md +107 -0
- package/package.json +50 -4
- package/src/config.ts +409 -0
- package/src/index.ts +397 -0
- package/src/schema.ts +223 -0
- package/src/state.ts +389 -0
- package/src/view.ts +710 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
本文件记录已发布版本的用户可见变更。更细的过程见 git log。破坏性变更标 **BREAKING**。
|
|
4
|
+
|
|
5
|
+
## 0.1.1 — 2026-11-25
|
|
6
|
+
|
|
7
|
+
- 无运行时变更:README 加封面图,截的是 `ask` 问第 1 题(共 2 题)时的面板:左边题目与选项,右边预览,底部一行按键提示。
|
|
8
|
+
- 封面链接用 `raw.githubusercontent.com` 绝对地址:`assets/` 不在 `files` 里,相对路径在 npm 页面上是死链。
|
|
9
|
+
|
|
10
|
+
## 0.1.0 — 2026-11-24
|
|
11
|
+
|
|
12
|
+
- 首个版本。一个工具 `ask(questions)`:1–4 题,每题 2–6 个选项,单选或多选。
|
|
13
|
+
- 单选按数字或 `Enter` 就给结论,答完自动跳到下一道未答题,全答自动提交;多选按数字或 `Enter` 勾选,走到 `→ Confirm` 按 `Enter` 收题。
|
|
14
|
+
- 补充说明就地写:`e` 在该选项(及其 `detail`)正下方展开输入框。单选取中项那一条,多选每个选项各一条(`notes`),取消勾选连同草稿一起清掉。
|
|
15
|
+
- 每题底部有 `+ Custom…` 自由输入,`Shift+Enter` 换行。
|
|
16
|
+
- `Esc` 一次中止:本轮结束,不向模型发送任何答案,模型也不会再回一句。
|
|
17
|
+
- `Ctrl+Enter` 提前提交已答的题,未答的标 `skipped`。
|
|
18
|
+
- `Ctrl+]` 把面板折叠成一行进度,再按一次展开,焦点、答案与草稿都保留。
|
|
19
|
+
- 选项的 `preview` markdown 宽屏并排显示在右侧、窄屏堆叠在选项下方;并排时右栏从 Tab / 题干那一行就顶对齐,左栏宽度按整题内容定死,滚动选项不抖。
|
|
20
|
+
- 聊天记录只有一行调用与每题一行结果,补充说明写在对应选项名后;`Ctrl+O` 展开成完整题干与逐条选项。
|
|
21
|
+
- 面板占编辑器槽位,不盖对话区;高度上限由 `ui.maxHeightRatio` 决定(默认 0.45)。
|
|
22
|
+
- 仅 TUI:`rpc` / `json` / `print` 模式下调 `ask` 直接报错。
|
|
23
|
+
- 配置在 `~/.pi/agent/pi-ask/config.json`:题数上限、高度占比、键位、工具名与模型提示文案。
|
package/README.md
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-ask-question-lite
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[简体中文](README.zh-CN.md) | **English**
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
One tool: `ask(questions)`. The model asks 1–4 questions with 2–6 options each, and the user answers with one keystroke. Esc aborts the whole turn: no second model reply, no half-finished answers. The package has no runtime dependencies.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Single select: `Enter` or a digit picks the focused option and moves to the next unanswered question.
|
|
12
|
+
- Multi select: `Enter` or a digit toggles the focused option. Walk down to `→ Confirm` and press `Enter` to finish the question.
|
|
13
|
+
- Every question has a `+ Custom…` row for free text. `Shift+Enter` adds a newline, `Enter` confirms.
|
|
14
|
+
- Everything below the top divider starts at column 0, flush with Pi's own footer, with no blank lines between sections; the focused row is marked with `›`, and the hint line only lists keys the current mode can use (`ui.showHints: false` hides it).
|
|
15
|
+
- `e` opens a note on the focused option: single select carries one `note`, multi select keeps one `notes` entry per option, and unchecking that option drops it.
|
|
16
|
+
- `Ctrl+Enter` submits what is answered and marks the rest as skipped.
|
|
17
|
+
- `Esc` aborts. The turn ends immediately and the model gets no answers.
|
|
18
|
+
- The tab bar labels each question with its `title` (or `Q1`, `Q2`…) and highlights the active one. The full `question` always renders below, wrapped to width.
|
|
19
|
+
- `Ctrl+]` collapses the panel to one line with progress; press it again to expand. Focus, answers and drafts stay. Change it with `keys.collapse`, or set `off` to disable.
|
|
20
|
+
- In the chat, the call line is `Ask <title1 · title2>` and the result is one `✓ <title>: <answer>` line per question with notes written as `<label> (note: …)`; skipped questions are dim `skipped`. `Ctrl+O` expands a result into full questions with per-option lines.
|
|
21
|
+
- An option can carry a `preview` in Markdown. Wide terminals show it beside the options, narrow ones stack it below.
|
|
22
|
+
- The dialog takes the editor slot, never the chat. Height is capped by `ui.maxHeightRatio`.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
Not on npm yet. Run it from this repo:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pi -ne -e ./packages/pi-ask-question-lite/src/index.ts
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Keys
|
|
33
|
+
|
|
34
|
+
| Key | Action |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `↑` / `↓` | Move between options, `+ Custom…` and (multi select) `→ Confirm` |
|
|
37
|
+
| `Tab` / `Shift+Tab` / `←` / `→` | Switch question |
|
|
38
|
+
| `1`–`9` | Pick that option (toggle in multi select) |
|
|
39
|
+
| `Enter` | Single select: pick and advance. Multi select: toggle the option, or finish on `→ Confirm` |
|
|
40
|
+
| `e` | Note on the focused option (`keys.annotate`) |
|
|
41
|
+
| `Ctrl+Enter` | Submit early (`keys.submitEarly`) |
|
|
42
|
+
| `Ctrl+]` | Collapse / expand the panel (`keys.collapse`) |
|
|
43
|
+
| `Esc` | Abort the turn, or leave the current editor |
|
|
44
|
+
|
|
45
|
+
## Configuration
|
|
46
|
+
|
|
47
|
+
The config file is `<agent dir>/pi-ask/config.json`. `<agent dir>` is `$PI_CODING_AGENT_DIR`, or `~/.pi/agent` when unset. The directory is `pi-ask`, not the package name.
|
|
48
|
+
|
|
49
|
+
The extension only reads this file and never writes it. Without the file, all values are defaults.
|
|
50
|
+
|
|
51
|
+
An error names the absolute path and one `path: reason` line per fault. These cases throw: broken JSON, an unknown key, a wrong type. `ui.maxHeightRatio` outside 0.2–0.8 clamps to the bound.
|
|
52
|
+
|
|
53
|
+
**Minimal configuration**: zero config works. To make the dialog shorter, set `ui.maxHeightRatio`.
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"ui": { "maxHeightRatio": 0.3 }
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Full configuration**: all keys follow, with their default values. `//` starts a comment; remove the comments in a real file.
|
|
62
|
+
|
|
63
|
+
```jsonc
|
|
64
|
+
{
|
|
65
|
+
"tools": { "ask": { "name": "ask" } }, // tool name
|
|
66
|
+
"limits": {
|
|
67
|
+
"maxQuestions": 4, // max questions per call
|
|
68
|
+
"maxOptions": 6 // max options per question
|
|
69
|
+
},
|
|
70
|
+
"ui": {
|
|
71
|
+
"maxHeightRatio": 0.45, // dialog height share (0.2–0.8)
|
|
72
|
+
"bell": true, // ring once when the dialog appears
|
|
73
|
+
"showHints": true, // draw the bottom key hint line
|
|
74
|
+
"preview": { "minSideBySideWidth": 100 } // below this width the preview stacks
|
|
75
|
+
},
|
|
76
|
+
"keys": {
|
|
77
|
+
"annotate": "e", // note editor on the focused option
|
|
78
|
+
"submitEarly": "ctrl+enter", // submit answered, skip the rest
|
|
79
|
+
"collapse": "ctrl+]" // collapse to one line; "off" disables
|
|
80
|
+
},
|
|
81
|
+
"guidance": { // what the model sees; `tool-name` becomes the tool name
|
|
82
|
+
"description": "Ask structured questions when user intent or trade-offs are unclear.",
|
|
83
|
+
"promptSnippet": "", // tool-list line; empty = omitted
|
|
84
|
+
"promptGuidelines": [
|
|
85
|
+
"tool-name: Check code, docs, or tools first; only ask when user intent or trade-offs are unclear.",
|
|
86
|
+
"tool-name: Ask only independent questions together; defer follow-ups that depend on earlier answers.",
|
|
87
|
+
"tool-name: Put the recommended option first, keep `label` short, and explain trade-offs in `detail`.",
|
|
88
|
+
"tool-name: Put concrete examples, code, or layouts in `preview` when options differ in behavior.",
|
|
89
|
+
"tool-name: Set `multiple: true` only when choices are not mutually exclusive."
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
An empty `guidance.promptSnippet` registers no tool-list line. `tool-name` in the other two fields becomes the tool name.
|
|
96
|
+
|
|
97
|
+
`keys.submitEarly` defaults to `ctrl+enter`, which only Kitty-protocol terminals report. Older terminals send a plain `\r`, so the key behaves like `Enter`. Change it when that matters.
|
|
98
|
+
|
|
99
|
+
`keys.collapse` takes `off` or a strict key: modifiers in `ctrl+shift+alt+super` order, then one letter, digit, symbol or special key name. It cannot take a navigation key (including the legacy aliases `ctrl+m`, `ctrl+j`, `ctrl+i`, `ctrl+[`, `ctrl+h`) or repeat `keys.annotate` / `keys.submitEarly`.
|
|
100
|
+
|
|
101
|
+
## Docs
|
|
102
|
+
|
|
103
|
+
| | |
|
|
104
|
+
| --- | --- |
|
|
105
|
+
| [Architecture](docs/ARCHITECTURE.md) | Modules, dependency rules, test seams |
|
|
106
|
+
| [Spec](docs/specs/0001-pi-ask-question-lite.md) | Contract, acceptance criteria, non-goals |
|
|
107
|
+
| [Decisions](docs/decisions/README.md) | One file per decision |
|
|
108
|
+
| [Glossary](docs/GLOSSARY.md) | What each term means |
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# pi-ask-question-lite
|
|
2
|
+
|
|
3
|
+
**[简体中文](README.zh-CN.md)** | [English](README.md)
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
一个工具 `ask(questions)`:模型问 1–4 题,每题 2–6 个选项,用户一次按键就给结论。Esc 整次中止本轮,模型不会再来一句,也不会拿到半成品答案。本包没有运行时依赖。
|
|
8
|
+
|
|
9
|
+
## 功能
|
|
10
|
+
|
|
11
|
+
- 单选:`Enter` 或数字键选中当前项,自动跳到下一道未答题;多选:`Enter` 或数字键勾选/取消当前项,走到 `→ Confirm` 按 `Enter` 收题。
|
|
12
|
+
- 每题底部有 `+ Custom…` 自由输入行。`Shift+Enter` 换行,`Enter` 提交。
|
|
13
|
+
- 分割线以下全部贴第 0 列、与 Pi 自己的 footer 左对齐,分段之间不留空行,焦点行用 `›` 标,底部只列当前模式真能用的键(`ui.showHints: false` 关掉这一行)。
|
|
14
|
+
- `e` 在当前选项上就地写补充说明:单选随答案带走,多选每个选项各记一条(`notes`),取消勾选就一起清掉。
|
|
15
|
+
- `Ctrl+Enter` 提前提交已答的题,其余标成 skipped。
|
|
16
|
+
- `Esc` 中止。本轮立刻结束,模型拿不到任何答案。
|
|
17
|
+
- Tab 栏用 `title`(缺省 `Q1`、`Q2`…)当标签并高亮当前题;完整 `question` 始终在下方按宽折行显示。
|
|
18
|
+
- `Ctrl+]` 把面板折叠成一行进度,再按一次展开;焦点、答案与草稿都保留。改 `keys.collapse` 换键,设 `off` 关闭。
|
|
19
|
+
- 聊天记录里调用行是 `Ask <title1 · title2>`,结果每题一行 `✓ <title>: <answer>`(补充说明写在选项名后 `(note: …)`),没答的题 dim 标 `skipped`;按 `Ctrl+O` 展开成完整题干加逐条选项。
|
|
20
|
+
- 选项可以带 Markdown 的 `preview`。宽终端显示在选项右侧,窄终端堆叠在下方。
|
|
21
|
+
- 对话框占编辑器槽位,不盖对话区。高度上限由 `ui.maxHeightRatio` 决定。
|
|
22
|
+
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
还没发到 npm。在仓库里直接跑:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pi -ne -e ./packages/pi-ask-question-lite/src/index.ts
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 键位
|
|
32
|
+
|
|
33
|
+
| 键 | 作用 |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `↑` / `↓` | 在选项、`+ Custom…` 与(多选)`→ Confirm` 之间移动 |
|
|
36
|
+
| `Tab` / `Shift+Tab` / `←` / `→` | 切题 |
|
|
37
|
+
| `1`–`9` | 选第 N 个选项(多选时切换勾选) |
|
|
38
|
+
| `Enter` | 单选:选中并推进;多选:勾选/取消,或在 `→ Confirm` 上收题 |
|
|
39
|
+
| `e` | 给当前选项写补充说明(`keys.annotate`) |
|
|
40
|
+
| `Ctrl+Enter` | 提前提交(`keys.submitEarly`) |
|
|
41
|
+
| `Ctrl+]` | 折叠 / 展开面板(`keys.collapse`) |
|
|
42
|
+
| `Esc` | 中止本轮,或退出当前编辑 |
|
|
43
|
+
|
|
44
|
+
## 配置
|
|
45
|
+
|
|
46
|
+
配置文件是 `<agent dir>/pi-ask/config.json`。`<agent dir>` 取 `$PI_CODING_AGENT_DIR`,未设置时取 `~/.pi/agent`。目录名是 `pi-ask`,不是包名。
|
|
47
|
+
|
|
48
|
+
扩展只读这个文件,不写。文件不存在时全部取默认值。
|
|
49
|
+
|
|
50
|
+
下列情况抛出错误:JSON 损坏、键名未知、类型错。消息带绝对路径,每个错误一行 `字段路径: 原因`。`ui.maxHeightRatio` 超出 0.2–0.8 时夹到边界。
|
|
51
|
+
|
|
52
|
+
**最小配置**:零配置即可用。要压矮对话框,改 `ui.maxHeightRatio`。
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"ui": { "maxHeightRatio": 0.3 }
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**完整配置**:下面列出全部键,取值即默认值。`//` 只是注释,实际文件里删掉。
|
|
61
|
+
|
|
62
|
+
```jsonc
|
|
63
|
+
{
|
|
64
|
+
"tools": { "ask": { "name": "ask" } }, // 工具名
|
|
65
|
+
"limits": {
|
|
66
|
+
"maxQuestions": 4, // 每次最多几题
|
|
67
|
+
"maxOptions": 6 // 每题最多几个选项
|
|
68
|
+
},
|
|
69
|
+
"ui": {
|
|
70
|
+
"maxHeightRatio": 0.45, // 对话框高度占比(0.2–0.8)
|
|
71
|
+
"bell": true, // 弹窗挂载时响一次
|
|
72
|
+
"showHints": true, // 是否画底部快捷键行
|
|
73
|
+
"preview": { "minSideBySideWidth": 100 } // 窄于此宽度时预览改为堆叠
|
|
74
|
+
},
|
|
75
|
+
"keys": {
|
|
76
|
+
"annotate": "e", // 在当前选项上写补充说明
|
|
77
|
+
"submitEarly": "ctrl+enter", // 提交已答的题,其余跳过
|
|
78
|
+
"collapse": "ctrl+]" // 折叠成一行;"off" 关闭
|
|
79
|
+
},
|
|
80
|
+
"guidance": { // 模型看到的文案;`tool-name` 换成工具名
|
|
81
|
+
"description": "Ask structured questions when user intent or trade-offs are unclear.",
|
|
82
|
+
"promptSnippet": "", // 工具清单那一行;空串 = 不出现
|
|
83
|
+
"promptGuidelines": [
|
|
84
|
+
"tool-name: Check code, docs, or tools first; only ask when user intent or trade-offs are unclear.",
|
|
85
|
+
"tool-name: Ask only independent questions together; defer follow-ups that depend on earlier answers.",
|
|
86
|
+
"tool-name: Put the recommended option first, keep `label` short, and explain trade-offs in `detail`.",
|
|
87
|
+
"tool-name: Put concrete examples, code, or layouts in `preview` when options differ in behavior.",
|
|
88
|
+
"tool-name: Set `multiple: true` only when choices are not mutually exclusive."
|
|
89
|
+
]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`guidance.promptSnippet` 为空串时不注册工具清单那一行。另外两段里的 `tool-name` 换成工具名。
|
|
95
|
+
|
|
96
|
+
`keys.submitEarly` 默认 `ctrl+enter`,只有 Kitty 协议的终端能区分。老终端发裸 `\r`,这个键等同 `Enter`。介意就换一个。
|
|
97
|
+
|
|
98
|
+
`keys.collapse` 取 `off` 或严格按键:修饰键按 `ctrl+shift+alt+super` 顺序,后面接单个字母、数字、符号或特殊键名。不能占导航键(含老终端别名 `ctrl+m`、`ctrl+j`、`ctrl+i`、`ctrl+[`、`ctrl+h`),也不能和 `keys.annotate` / `keys.submitEarly` 重复。
|
|
99
|
+
|
|
100
|
+
## 文档
|
|
101
|
+
|
|
102
|
+
| | |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| [架构](docs/ARCHITECTURE.md) | 模块、依赖规则、测试边界 |
|
|
105
|
+
| [规格](docs/specs/0001-pi-ask-question-lite.md) | 契约、验收标准、不做的 |
|
|
106
|
+
| [决策](docs/decisions/README.md) | 一条决策一份文件 |
|
|
107
|
+
| [术语](docs/GLOSSARY.md) | 每个词指什么 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ask-question-lite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Pi ask extension: one structured question dialog, one Esc to abort.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"ask",
|
|
9
|
+
"question",
|
|
10
|
+
"prompt"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "setwhite",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/setwhite/pi-extensions.git",
|
|
18
|
+
"directory": "packages/pi-ask-question-lite"
|
|
19
|
+
},
|
|
20
|
+
"packageManager": "pnpm@12.3.4",
|
|
21
|
+
"pi": {
|
|
22
|
+
"extensions": [
|
|
23
|
+
"./src/index.ts"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"lint": "biome check --error-on-warnings .",
|
|
28
|
+
"lint:fix": "biome check --write .",
|
|
29
|
+
"check:imports": "node ../../scripts/check-imports.mjs",
|
|
30
|
+
"check": "pnpm lint && pnpm check:imports && pnpm typecheck && pnpm test",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"src",
|
|
36
|
+
"CHANGELOG.md"
|
|
37
|
+
],
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
40
|
+
"@earendil-works/pi-tui": "*",
|
|
41
|
+
"typebox": "*"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@biomejs/biome": "2.5.15",
|
|
45
|
+
"@earendil-works/pi-coding-agent": "^1.3.0",
|
|
46
|
+
"@earendil-works/pi-tui": "^1.3.0",
|
|
47
|
+
"@types/node": "^26.6.5",
|
|
48
|
+
"typebox": "^1.4.0",
|
|
49
|
+
"typescript": "^7.0.2",
|
|
50
|
+
"vitest": "^5.0.5"
|
|
51
|
+
}
|
|
52
|
+
}
|