@yandy0725/pi-ask-user 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.
- package/README.md +152 -0
- package/README.zh.md +135 -0
- package/index.ts +1810 -0
- package/package.json +50 -0
- package/skills/ask-user/SKILL.md +162 -0
- package/skills/ask-user/references/ask-user-skill-extension-spec.md +96 -0
- package/src/single-select-layout.ts +208 -0
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# pi-ask-user
|
|
2
|
+
|
|
3
|
+
A Pi package that adds an interactive `ask_user` tool for collecting user decisions during an agent run.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Searchable single-select option lists with wrapped titles and descriptions
|
|
8
|
+
- Responsive split-pane details preview on wide terminals with single-column fallback on narrow terminals
|
|
9
|
+
- Multi-select option lists
|
|
10
|
+
- Optional freeform responses
|
|
11
|
+
- User-toggleable extra context on structured selections
|
|
12
|
+
- Context display support
|
|
13
|
+
- Configurable display mode: `overlay` (modal, default) or `inline` (rendered directly in the flow)
|
|
14
|
+
- Runtime overlay toggle: press the configured overlay-toggle key (`alt+o` by default, configurable per call or via env var) while the prompt is open to temporarily hide/show the popup so you can read prior agent output, then press it again to bring it back
|
|
15
|
+
- Pi-TUI-aligned keybinding and editor behavior
|
|
16
|
+
- Custom TUI rendering for tool calls and results
|
|
17
|
+
- System prompt integration via `promptSnippet` and `promptGuidelines`
|
|
18
|
+
- Optional timeout for auto-dismiss in both overlay and fallback input modes
|
|
19
|
+
- Structured `details` on all results for session state reconstruction
|
|
20
|
+
- Graceful fallback when interactive UI is unavailable
|
|
21
|
+
- Bundled `ask-user` skill for mandatory decision-gating in high-stakes or ambiguous tasks
|
|
22
|
+
|
|
23
|
+
## Bundled skill: `ask-user`
|
|
24
|
+
|
|
25
|
+
This package ships a skill at `skills/ask-user/SKILL.md` that nudges/mandates the agent to use `ask_user` when:
|
|
26
|
+
|
|
27
|
+
- architectural trade-offs are high impact
|
|
28
|
+
- requirements are ambiguous or conflicting
|
|
29
|
+
- assumptions would materially change implementation
|
|
30
|
+
|
|
31
|
+
The skill follows a "decision handshake" flow:
|
|
32
|
+
|
|
33
|
+
1. Gather evidence and summarize context
|
|
34
|
+
2. Ask one focused question via `ask_user`
|
|
35
|
+
3. Wait for explicit user choice
|
|
36
|
+
4. Confirm the decision, then proceed
|
|
37
|
+
|
|
38
|
+
See: `skills/ask-user/references/ask-user-skill-extension-spec.md`.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pi install npm:@yandy0725/pi-ask-user
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Tool name
|
|
47
|
+
|
|
48
|
+
The registered tool name is:
|
|
49
|
+
|
|
50
|
+
- `ask_user`
|
|
51
|
+
|
|
52
|
+
## Parameters
|
|
53
|
+
|
|
54
|
+
| Parameter | Type | Default | Description |
|
|
55
|
+
|-----------|------|---------|-------------|
|
|
56
|
+
| `question` | `string` | *required* | The question to ask the user |
|
|
57
|
+
| `context` | `string?` | — | Relevant context summary shown before the question |
|
|
58
|
+
| `options` | `(string \| {title, description?})[]?` | `[]` | Multiple-choice options |
|
|
59
|
+
| `allowMultiple` | `boolean?` | `false` | Enable multi-select mode |
|
|
60
|
+
| `allowFreeform` | `boolean?` | `true` | Add a "Type something" freeform option |
|
|
61
|
+
| `allowComment` | `boolean?` | `false` | Expose a user-toggleable extra-context option in the custom UI (`ctrl+g` or the toggle row) and collect an optional comment in fallback dialogs |
|
|
62
|
+
| `displayMode` | `"overlay" \| "inline"?` | env var or `"overlay"` | Controls custom UI rendering: `overlay` shows the centered modal (current behavior), `inline` renders without overlay framing |
|
|
63
|
+
| `overlayToggleKey` | `string?` | env var or `"alt+o"` | Shortcut for hiding/showing the overlay popup (overlay mode only). Pi-TUI key spec, e.g. `"alt+o"`, `"ctrl+shift+h"`. Pass `"off"` to disable. |
|
|
64
|
+
| `commentToggleKey` | `string?` | env var or `"ctrl+g"` | Shortcut for toggling the optional comment/extra-context row when `allowComment: true`. Pass `"off"` to disable. |
|
|
65
|
+
| `timeout` | `number?` | — | Auto-dismiss after N ms and return `null` if the prompt times out |
|
|
66
|
+
|
|
67
|
+
## Example usage shape
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"question": "Which option should we use?",
|
|
72
|
+
"context": "We are choosing a deploy target.",
|
|
73
|
+
"options": [
|
|
74
|
+
"staging",
|
|
75
|
+
{ "title": "production", "description": "Customer-facing" }
|
|
76
|
+
],
|
|
77
|
+
"allowMultiple": false,
|
|
78
|
+
"allowFreeform": true,
|
|
79
|
+
"allowComment": true,
|
|
80
|
+
"displayMode": "inline"
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Personal preferences via environment variables
|
|
85
|
+
|
|
86
|
+
Configure your defaults globally by setting these in your shell profile (`~/.zshrc`, `~/.bash_profile`, etc.):
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
export PI_ASK_USER_DISPLAY_MODE=inline
|
|
90
|
+
export PI_ASK_USER_OVERLAY_TOGGLE_KEY=alt+h
|
|
91
|
+
export PI_ASK_USER_COMMENT_TOGGLE_KEY=alt+c
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Display mode
|
|
95
|
+
|
|
96
|
+
Effective order:
|
|
97
|
+
|
|
98
|
+
1. Per-call `displayMode` parameter (if provided)
|
|
99
|
+
2. `PI_ASK_USER_DISPLAY_MODE` (if set to `"overlay"` or `"inline"`)
|
|
100
|
+
3. Fallback default: `"overlay"`
|
|
101
|
+
|
|
102
|
+
Unrecognised values are silently ignored and fall back to `"overlay"`.
|
|
103
|
+
|
|
104
|
+
### Shortcuts
|
|
105
|
+
|
|
106
|
+
Effective order for both `overlayToggleKey` and `commentToggleKey`:
|
|
107
|
+
|
|
108
|
+
1. Per-call parameter (if provided)
|
|
109
|
+
2. Matching env var (`PI_ASK_USER_OVERLAY_TOGGLE_KEY` / `PI_ASK_USER_COMMENT_TOGGLE_KEY`)
|
|
110
|
+
3. Built-in defaults: `alt+o` and `ctrl+g`
|
|
111
|
+
|
|
112
|
+
Pass `"off"`, `"none"`, or `"disabled"` (at any level) to disable the shortcut entirely. Invalid specs are silently dropped and the next source is used. Specs follow the Pi-TUI [`KeyId`](https://github.com/earendil-works/pi-mono/blob/main/packages/tui/src/keys.ts) format: `[mod+]...key` where modifiers are `ctrl`, `shift`, `alt`, `super`, in any order, joined by `+` (e.g. `ctrl+g`, `alt+shift+x`, `escape`, `tab`).
|
|
113
|
+
|
|
114
|
+
## Controls
|
|
115
|
+
|
|
116
|
+
While an `ask_user` prompt is open:
|
|
117
|
+
|
|
118
|
+
| Key | Action |
|
|
119
|
+
|-----|--------|
|
|
120
|
+
| `alt+o` (configurable via `overlayToggleKey`) | Hide/show the overlay popup so you can read the agent's prior output. Available in `overlay` mode only. The first time you hide it, a notification reminds you which key brings it back. |
|
|
121
|
+
| `ctrl+g` (configurable via `commentToggleKey`) | Toggle the optional comment/extra-context row (when `allowComment: true`). |
|
|
122
|
+
| `enter` | Confirm the focused option, submit a freeform response, or submit/skip an optional comment. |
|
|
123
|
+
| `esc` | Clear the search filter, exit freeform/comment mode, or cancel the prompt. |
|
|
124
|
+
| `↑` / `↓`, `ctrl+k` / `ctrl+j` | Navigate options. `ctrl+k` / `ctrl+j` (vim-style) work while typing in searchable prompts without disturbing the filter. |
|
|
125
|
+
|
|
126
|
+
If you prefer never to see the overlay, set `displayMode: "inline"` per call or `PI_ASK_USER_DISPLAY_MODE=inline` globally.
|
|
127
|
+
|
|
128
|
+
## Result details
|
|
129
|
+
|
|
130
|
+
All tool results include a structured `details` object for rendering and session state reconstruction:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
type AskResponse =
|
|
134
|
+
| { kind: "selection"; selections: string[]; comment?: string }
|
|
135
|
+
| { kind: "freeform"; text: string };
|
|
136
|
+
|
|
137
|
+
interface AskToolDetails {
|
|
138
|
+
question: string;
|
|
139
|
+
context?: string;
|
|
140
|
+
options: QuestionOption[];
|
|
141
|
+
response: AskResponse | null;
|
|
142
|
+
cancelled: boolean;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Credits
|
|
147
|
+
|
|
148
|
+
This project is based on [pi-ask-user](https://github.com/edlsh/pi-ask-user) by [Enzo Lucchesi](https://github.com/edlsh). Thank you to the original author for the excellent work.
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
MIT
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# pi-ask-user
|
|
2
|
+
|
|
3
|
+
一个 Pi 扩展包,添加交互式 `ask_user` 工具,用于在 Agent 运行期间收集用户决策。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 可搜索的单选选项列表,支持标题和描述文本换行
|
|
8
|
+
- 宽终端下的响应式分栏详情预览,窄终端下回退为单列布局
|
|
9
|
+
- 多选选项列表
|
|
10
|
+
- 可选的自由文本输入
|
|
11
|
+
- 选择后可切换添加额外上下文(可选注释)
|
|
12
|
+
- 上下文展示支持
|
|
13
|
+
- 可配置的显示模式:`overlay`(模态,默认)或 `inline`(直接内联渲染)
|
|
14
|
+
- 运行时浮层切换:当提示窗口打开时,按下配置的叠加层切换键(默认 `alt+o`,可每次调用配置或通过环境变量设置)临时隐藏/显示弹窗,以便阅读之前的 Agent 输出
|
|
15
|
+
- Pi-TUI 对齐的按键绑定和编辑器行为
|
|
16
|
+
- 工具调用和结果的自定义 TUI 渲染
|
|
17
|
+
- 通过 `promptSnippet` 和 `promptGuidelines` 集成系统提示词
|
|
18
|
+
- 叠加层和回退输入模式下均支持可选的超时自动关闭
|
|
19
|
+
- 所有结果均包含结构化 `details` 用于会话状态重建
|
|
20
|
+
- 交互式 UI 不可用时的优雅回退
|
|
21
|
+
- 内置 `ask-user` 技能,用于高风险或模糊任务中的强制决策门控
|
|
22
|
+
|
|
23
|
+
## 内置技能: `ask-user`
|
|
24
|
+
|
|
25
|
+
本包在 `skills/ask-user/SKILL.md` 中内置一个技能,引导/强制 Agent 在以下场景使用 `ask_user`:
|
|
26
|
+
|
|
27
|
+
- 架构权衡影响较大时
|
|
28
|
+
- 需求模糊或冲突时
|
|
29
|
+
- 假设会实质性地改变实现时
|
|
30
|
+
|
|
31
|
+
该技能遵循"决策握手"流程:
|
|
32
|
+
|
|
33
|
+
1. 收集证据并总结上下文
|
|
34
|
+
2. 通过 `ask_user` 提出一个聚焦的问题
|
|
35
|
+
3. 等待用户明确选择
|
|
36
|
+
4. 确认决策,然后继续
|
|
37
|
+
|
|
38
|
+
参见:`skills/ask-user/references/ask-user-skill-extension-spec.md`。
|
|
39
|
+
|
|
40
|
+
## 安装
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pi install npm:@yandy0725/pi-ask-user
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 工具名称
|
|
47
|
+
|
|
48
|
+
注册的工具名称为:
|
|
49
|
+
|
|
50
|
+
- `ask_user`
|
|
51
|
+
|
|
52
|
+
## 参数
|
|
53
|
+
|
|
54
|
+
| 参数 | 类型 | 默认值 | 描述 |
|
|
55
|
+
|-----------|------|---------|-------------|
|
|
56
|
+
| `question` | `string` | *必填* | 向用户提出的问题 |
|
|
57
|
+
| `context` | `string?` | — | 问题前展示的相关上下文摘要 |
|
|
58
|
+
| `options` | `(string \| {title, description?})[]?` | `[]` | 多选选项 |
|
|
59
|
+
| `allowMultiple` | `boolean?` | `false` | 启用多选模式 |
|
|
60
|
+
| `allowFreeform` | `boolean?` | `true` | 添加"自定义输入"自由文本选项 |
|
|
61
|
+
| `allowComment` | `boolean?` | `false` | 在自定义 UI 中提供可切换的额外上下文选项(`ctrl+g` 或切换行),并在回退对话框中收集可选注释 |
|
|
62
|
+
| `displayMode` | `"overlay" \| "inline"?` | 环境变量或 `"overlay"` | 控制自定义 UI 渲染:`overlay` 显示居中模态框(当前行为),`inline` 不显示叠加框架渲染 |
|
|
63
|
+
| `overlayToggleKey` | `string?` | 环境变量或 `"alt+o"` | 隐藏/显示叠加弹窗的快捷键(仅 overlay 模式)。Pi-TUI 键位格式,例如 `"alt+o"`、`"ctrl+shift+h"`。传入 `"off"` 禁用。 |
|
|
64
|
+
| `commentToggleKey` | `string?` | 环境变量或 `"ctrl+g"` | 当 `allowComment: true` 时切换可选注释/额外上下文行的快捷键。传入 `"off"` 禁用。 |
|
|
65
|
+
| `timeout` | `number?` | — | N 毫秒后自动关闭,超时返回 `null` |
|
|
66
|
+
|
|
67
|
+
## 通过环境变量设置个人偏好
|
|
68
|
+
|
|
69
|
+
在你的 shell 配置(`~/.zshrc`、`~/.bash_profile` 等)中设置以下变量来全局配置默认值:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export PI_ASK_USER_DISPLAY_MODE=inline
|
|
73
|
+
export PI_ASK_USER_OVERLAY_TOGGLE_KEY=alt+h
|
|
74
|
+
export PI_ASK_USER_COMMENT_TOGGLE_KEY=alt+c
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 显示模式
|
|
78
|
+
|
|
79
|
+
生效优先级:
|
|
80
|
+
|
|
81
|
+
1. 每次调用时的 `displayMode` 参数(如提供)
|
|
82
|
+
2. `PI_ASK_USER_DISPLAY_MODE`(如设置为 `"overlay"` 或 `"inline"`)
|
|
83
|
+
3. 回退默认值:`"overlay"`
|
|
84
|
+
|
|
85
|
+
无法识别的值会被静默忽略并回退到 `"overlay"`。
|
|
86
|
+
|
|
87
|
+
### 快捷键
|
|
88
|
+
|
|
89
|
+
`overlayToggleKey` 和 `commentToggleKey` 的生效优先级:
|
|
90
|
+
|
|
91
|
+
1. 每次调用时的参数(如提供)
|
|
92
|
+
2. 对应的环境变量(`PI_ASK_USER_OVERLAY_TOGGLE_KEY` / `PI_ASK_USER_COMMENT_TOGGLE_KEY`)
|
|
93
|
+
3. 内置默认值:`alt+o` 和 `ctrl+g`
|
|
94
|
+
|
|
95
|
+
传入 `"off"`、`"none"` 或 `"disabled"`(任意级别)可以完全禁用快捷键。无效的键位格式会被静默丢弃,使用下一个来源。键位格式遵循 Pi-TUI 的 [`KeyId`](https://github.com/earendil-works/pi-mono/blob/main/packages/tui/src/keys.ts) 格式:`[mod+]...key`,修饰键为 `ctrl`、`shift`、`alt`、`super`,可任意顺序用 `+` 连接(如 `ctrl+g`、`alt+shift+x`、`escape`、`tab`)。
|
|
96
|
+
|
|
97
|
+
## 操作控制
|
|
98
|
+
|
|
99
|
+
`ask_user` 提示窗口打开时:
|
|
100
|
+
|
|
101
|
+
| 按键 | 操作 |
|
|
102
|
+
|-----|--------|
|
|
103
|
+
| `alt+o`(可通过 `overlayToggleKey` 配置) | 隐藏/显示叠加弹窗,以便阅读 Agent 之前的输出。仅在 `overlay` 模式下可用。首次隐藏时会提示恢复弹窗的按键。 |
|
|
104
|
+
| `ctrl+g`(可通过 `commentToggleKey` 配置) | 切换可选注释/额外上下文行(当 `allowComment: true` 时)。 |
|
|
105
|
+
| `enter` | 确认聚焦的选项、提交自由文本回复、或提交/跳过可选注释。 |
|
|
106
|
+
| `esc` | 清除搜索过滤、退出自由文本/注释模式、或取消提示。 |
|
|
107
|
+
| `↑` / `↓`、`ctrl+k` / `ctrl+j` | 导航选项。`ctrl+k` / `ctrl+j`(vim 风格)可在可搜索提示中打字时不干扰过滤输入。 |
|
|
108
|
+
|
|
109
|
+
如果你始终不希望看到叠加层,请每次调用时设置 `displayMode: "inline"`,或全局设置 `PI_ASK_USER_DISPLAY_MODE=inline`。
|
|
110
|
+
|
|
111
|
+
## 结果详情
|
|
112
|
+
|
|
113
|
+
所有工具结果均包含结构化的 `details` 对象,用于渲染和会话状态重建:
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
type AskResponse =
|
|
117
|
+
| { kind: "selection"; selections: string[]; comment?: string }
|
|
118
|
+
| { kind: "freeform"; text: string };
|
|
119
|
+
|
|
120
|
+
interface AskToolDetails {
|
|
121
|
+
question: string;
|
|
122
|
+
context?: string;
|
|
123
|
+
options: QuestionOption[];
|
|
124
|
+
response: AskResponse | null;
|
|
125
|
+
cancelled: boolean;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## 致谢
|
|
130
|
+
|
|
131
|
+
本项目基于 [pi-ask-user](https://github.com/edlsh/pi-ask-user)(作者 [Enzo Lucchesi](https://github.com/edlsh))。感谢原作者的出色工作。
|
|
132
|
+
|
|
133
|
+
## 许可证
|
|
134
|
+
|
|
135
|
+
MIT
|