@zhuxixi/pi-agent-board 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +7 -7
  3. package/docs/superpowers/plans/2026-10-19-issue-213-reply-guard-csi-key.md +257 -0
  4. package/docs/superpowers/plans/2026-10-19-issue-214-attach-forward-alt-modifier.md +202 -0
  5. package/docs/superpowers/plans/2026-10-21-issue-221-ask-user-question.md +198 -0
  6. package/docs/superpowers/plans/2026-10-23-issue-225-monotonic-foreground-state.md +450 -0
  7. package/docs/superpowers/plans/2026-10-23-issue-229-vim-jkl.md +449 -0
  8. package/docs/superpowers/plans/2026-10-23-issue-232-attach-bg-only-cells.md +153 -0
  9. package/docs/superpowers/plans/2026-10-23-lease-heartbeat-staleness.md +537 -0
  10. package/docs/superpowers/plans/2026-10-23-selected-row-highlight.md +405 -0
  11. package/docs/superpowers/plans/2026-10-24-issue-217-windows-pid-reuse-stopping.md +367 -0
  12. package/docs/superpowers/plans/2026-10-24-issue-230-warm-host-background-runs.md +806 -0
  13. package/docs/superpowers/plans/2026-10-24-issue-238-windows-process-identity-token.md +490 -0
  14. package/docs/superpowers/plans/2026-10-24-issue-241-coordinator-root-exit.md +461 -0
  15. package/docs/superpowers/plans/2026-10-25-issue-239-coordinator-replacement-identity.md +504 -0
  16. package/docs/superpowers/specs/2026-10-14-issue-170-attach-reply-guard-design.md +5 -0
  17. package/docs/superpowers/specs/2026-10-19-issue-213-reply-guard-csi-key-design.md +165 -0
  18. package/docs/superpowers/specs/2026-10-19-issue-214-attach-forward-alt-modifier-design.md +131 -0
  19. package/docs/superpowers/specs/2026-10-20-issue-221-ask-user-question-design.md +270 -0
  20. package/docs/superpowers/specs/2026-10-22-issue-225-monotonic-foreground-state-design.md +225 -0
  21. package/docs/superpowers/specs/2026-10-23-issue-229-vim-jkl-design.md +90 -0
  22. package/docs/superpowers/specs/2026-10-23-issue-232-attach-bg-only-cells-design.md +146 -0
  23. package/docs/superpowers/specs/2026-10-23-lease-heartbeat-staleness-design.md +271 -0
  24. package/docs/superpowers/specs/2026-10-23-selected-row-highlight-design.md +191 -0
  25. package/docs/superpowers/specs/2026-10-24-issue-217-windows-pid-reuse-stopping-design.md +334 -0
  26. package/docs/superpowers/specs/2026-10-24-issue-230-warm-host-background-runs-design.md +283 -0
  27. package/docs/superpowers/specs/2026-10-24-issue-238-windows-process-identity-token-design.md +286 -0
  28. package/docs/superpowers/specs/2026-10-24-issue-241-coordinator-root-exit-design.md +381 -0
  29. package/docs/superpowers/specs/2026-10-25-issue-239-coordinator-replacement-identity-design.md +331 -0
  30. package/package.json +3 -3
  31. package/runner/pty-runner.mjs +18 -22
  32. package/runner/state-coordinator.mjs +213 -26
  33. package/scripts/release_helper.mjs +39 -7
  34. package/scripts/run-tests.mjs +375 -0
  35. package/src/core/background-runs.mjs +273 -0
  36. package/src/core/coordinator-client.mjs +346 -26
  37. package/src/core/diagnostics.mjs +24 -0
  38. package/src/core/events.mjs +16 -3
  39. package/src/core/foreground-projection-cache.mjs +99 -0
  40. package/src/core/host-coordination.mjs +69 -1
  41. package/src/core/launch.mjs +21 -1
  42. package/src/core/locks.mjs +176 -31
  43. package/src/core/pid.mjs +4 -2
  44. package/src/core/process-identity-probe.mjs +228 -0
  45. package/src/core/pty-scroll.mjs +21 -14
  46. package/src/core/state-commands.mjs +5 -1
  47. package/src/core/terminal-reply-guard.mjs +26 -4
  48. package/src/core/types.mjs +1 -0
  49. package/src/core/warm-host-sweeper.mjs +7 -2
  50. package/src/runtime/service.mjs +385 -73
  51. package/src/ui/dashboard.ts +48 -25
  52. package/src/ui/pty-attach.ts +18 -7
@@ -0,0 +1,165 @@
1
+ Drafted: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-19T12:40:00+08:00
2
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-19T13:05:00+08:00 — 第 1 轮复核处置(R1-G1/G2/G3 + D1/D2/D3)
3
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-19T13:15:00+08:00 — 第 2 轮复核处置(R2-G1 + D1/D2/D3)
4
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-19T13:25:00+08:00 — 第 3 轮复核处置(收敛轮,R3-D1/D2/D3 细化)
5
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-19T14:20:00+08:00 — 代码评审批次修复(A8③ 空转 grep、REPLY_HEADS 注释未改、armed 路径未覆盖)
6
+
7
+ # issue #213 根因报告与修复设计:reply guard 的 cell-size 前缀吞掉 kitty 编码的 PageDown
8
+
9
+ 仓库:zhuxixi/pi-agent-board · 基线:`origin/main` @ `ef4317f`
10
+
11
+ ## 1. 症状
12
+
13
+ `v0.12.0` + WezTerm 20240203 + pi fullscreen 1.3.0 → `/agent-board` → attach:
14
+
15
+ | 键 | 结果 |
16
+ | --- | --- |
17
+ | `PageUp` | 正常(本地滚动 / 转发) |
18
+ | `PageDown` | **完全无反应** |
19
+ | 鼠标滚轮 | 正常 |
20
+
21
+ 不对称本身就是线索:两个键在 `handleKeyInput` 里走**完全相同**的
22
+ `tryScrollBy(±pageSize)` → `send()` 兜底,所以差异只能出在更上游的输入分类层。
23
+
24
+ ## 2. 根因
25
+
26
+ `src/core/terminal-reply-guard.mjs` 的 `REPLY_HEADS` 含:
27
+
28
+ ```js
29
+ { family: "cell-size", prefix: "\x1b[6;" }
30
+ ```
31
+
32
+ 本意是吸收被拆碎的 XTWINOPS cell-size 回复(`CSI 6;<rows>;<cols>t`)。
33
+ 但 **PageDown 的 legacy 功能键编号正是 6**:kitty 键盘协议下带修饰键的 PageDown 编码为
34
+ `CSI 6;<mod>u`(`\x1b[6;1u`),modifyOtherKeys 回退下为 `CSI 6;<mod>~`(`\x1b[6;5~`)。
35
+ 两者都以 `\x1b[6;` 开头 → `classifyReplyEvent` 判成 `reply-head` → guard 进入 armed
36
+ → 250ms/64 字节吸收窗口把按键吞掉。PageUp 的编号是 5(`\x1b[5;1u`),永不命中,所以不受影响。
37
+
38
+ 附带发现的**文档与代码矛盾**:`REPLY_HEADS` 上方的注释写着
39
+ 「Deliberately absent: … `\x1b[5`/`\x1b[6` (PageUp/PageDown heads)」,
40
+ 但列表里实际存在 `\x1b[6;` —— 注释想表达的是"不吸收 `\x1b[6` 开头的裸键位",
41
+ 实现却用了一个更宽的前缀,正是这条矛盾掩盖了本次冲突。
42
+
43
+ 引入点:`2148360 fix(attach): stop terminal reply fragments leaking into the attached child's input (#194)`。
44
+
45
+ ## 3. 证据(对仓库当前代码实测)
46
+
47
+ ```
48
+ "\x1b[6;1u" → { kind: "reply-head", family: "cell-size" } ❌ PageDown 被吞
49
+ "\x1b[6;5~" → { kind: "reply-head", family: "cell-size" } ❌ modifyOtherKeys PageDown 被吞
50
+ "\x1b[5;1u" → { kind: "other" } ✓ PageUp
51
+ "\x1b[6~" → { kind: "other" } ✓ 无修饰的 legacy PageDown
52
+ "\x1b[57422u" → { kind: "other" } ✓ kitty codepoint 形式
53
+ "\x1b[6;" → { kind: "reply-head", family: "cell-size" } ✓ 真 fragment 仍 arm
54
+ "\x1b[6;24" → { kind: "reply-head", family: "cell-size" } ✓
55
+ "\x1b[6;24;80t" → { kind: "reply-complete", action: "drop" } ✓
56
+ ```
57
+
58
+ 现有测试(15 个 `test()` / 63 条 assert,全绿)**没有覆盖** `\x1b[6;<mod>u` / `\x1b[6;<mod>~` 形态 —— 这是回归缺口。
59
+ `test/terminal-reply-guard.test.mjs:58` 只测了裸 `\x1b[5~` / `\x1b[6~`,
60
+ `:96` 测了 `\x1b[6;` 仍需 arm。
61
+
62
+ ## 4. 修复
63
+
64
+ **在 head 前缀之前**识别"完整的 CSI 键序列":真 cell-size fragment 没有 `u`/`~` 终结符,
65
+ 所以完整键序列可以安全地判成用户输入。
66
+
67
+ ```js
68
+ // Kitty / modifyOtherKeys keys: `CSI <num>[;<mod>…]{u,~}`. PageDown's legacy number
69
+ // is 6, which shares the `\x1b[6;` prefix with the cell-size reply head.
70
+ const CSI_KEY_SEQUENCE = /^\x1b\[\d+(?:[;:]\d+)*[u~]$/;
71
+
72
+ export function classifyReplyEvent(data) {
73
+ …DROP/FORWARD 判定不变…
74
+ // A COMPLETE CSI key is user input, never a reply fragment.
75
+ if (CSI_KEY_SEQUENCE.test(data)) return { kind: "other" };
76
+ for (const head of REPLY_HEADS) { … }
77
+ …
78
+ }
79
+ ```
80
+
81
+ **正则比 issue 原文更宽一点**:issue 给的 `/^\x1b\[\d+(?:;\d+)?(?::\d+)?[u~]$/` 覆盖不了
82
+ kitty 的"交替键"编码 `\x1b[6;1:2;65u`(`;65` 在主修饰符之后),会重新落回 reply-head。
83
+ `(?:[;:]\d+)*` 覆盖全部 `CSI <num>;[<mod>[:<event>][;<alternate>]]u` 形态。
84
+
85
+ 保持不变的行为:
86
+
87
+ - `\x1b[6;`、`\x1b[6;24`(无终结符)→ 仍然 `reply-head`(arm)
88
+ - `\x1b[6;24;80t` → 仍然 `reply-complete` drop(DROP_SHAPES 命中在前)
89
+ - 其余 `REPLY_HEADS`(`\x1b[?`、`\x1b[>`、`\x1bP`、`\x1b]1`、`\x1b]4`)无键位冲突,不动
90
+
91
+ 顺带修掉 `REPLY_HEADS` 上方与新语义矛盾的注释(说明 `\x1b[6;` 只能靠"完整键序列优先"来消解冲突)。
92
+
93
+ ### 4.1 推翻既有设计文档的 pinned 不变式(R1-G3)
94
+
95
+ `docs/superpowers/specs/2026-10-14-issue-170-attach-reply-guard-design.md:106` 钉死了:
96
+
97
+ > 窗口只由 `reply-head` 武装,只有「**永不可能是按键/鼠标编码前缀**」的形状才武装:
98
+ > `ESC[?`、`ESC[>`、**`ESC[6;`**、`ESC P`、`ESC]1`、`ESC]4`。
99
+
100
+ 本次根因正是这条论断的反例:kitty 功能键编号形态 `ESC[6;1u`(PageDown)打破「永不可能是按键前缀」。
101
+ 因此本修复**显式推翻**该不变式,替换为:
102
+
103
+ > 完整 CSI 键序列(`CSI <num>[;<mod>[:<event>][;<alt>]]{u,~}`)优先于 head 前缀判定;
104
+ > 只有**不带** `u`/`~` 终结符的片段才按 head 武装。
105
+
106
+ 同步要求(实现阶段必做):
107
+
108
+ - **改掉 `REPLY_HEADS` 上方那段与新语义矛盾的注释**(源码 :76-79,「can never be a key/mouse/paste
109
+ encoding」「Deliberately absent: … `[5`/`[6`(PageUp/PageDown heads)」):不得再出现
110
+ 绝对断言,改为说明「完整键序列优先,只有不带终结符的片段才武装」。
111
+ 模块 header 用**英文**写同一条规则(`complete CSI key sequence … beats the head prefixes`),
112
+ 中文仅在 #170 文档里作为跨引用出现。
113
+ - 在 #170 设计文档 §3.3 的「设计要点」清单里补上「完整 CSI 键序列优先于 head 前缀」这一新类别,
114
+ 并把 L106 的论断标注为已被 #213 修正(追加而非改写历史)
115
+ - #170 文档 L112 与 A4 清单里「`ESC[6;` 必须武装」仍然成立(本修复只对**完整**键序列例外)
116
+
117
+ ## 5. 边界与风险
118
+
119
+ | 风险 | 说明 / 缓解 |
120
+ | --- | --- |
121
+ | 真 cell-size 回复被误判成键 | 不可能:cell-size 以 `t` 结尾,不带 `u`/`~` |
122
+ | kitty 其他功能键(`\x1b[5;1u` 等) | 本就未被 head 命中,行为不变 |
123
+ | modifyOtherKeys 其他键(`\x1b[3;5~`) | 不命中 `\x1b[6;`,行为不变 |
124
+ | 极少数终端把 PageDown 编码成 `\x1b[6;`(截断) | 仍会 arm 并吞掉;这是 issue #170 的保护方向,保留 |
125
+ | 安全方向 | 修复只是让**用户按键**更早地判定为非回复;不会让回复碎片更容易漏进子会话 |
126
+
127
+ ## 6. 验收矩阵
128
+
129
+ | ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
130
+ | --- | --- | --- | --- | --- |
131
+ | A1 | kitty/modifyOtherKeys PageDown 判为键 | 自动化(unit) | `test/terminal-reply-guard.test.mjs`:`\x1b[6;1u`、`\x1b[6;5u`、`\x1b[6;1:2u`、`\x1b[6;1:2;65u`、`\x1b[6;5~` | 全部 `{ kind: "other" }` |
132
+ | A2 | PageUp 与其他键不受影响 | 自动化(unit) | 同文件:`\x1b[5;1u`、`\x1b[5;5~`、`\x1b[57422u`、`\x1b[57421u`、`\x1b[3;5~` | 全部 `{ kind: "other" }` |
133
+ | A3 | 真 cell-size fragment 仍 arm | 自动化(unit) | 同文件:`\x1b[6;`、`\x1b[6;24` | 均 `{ kind: "reply-head", family: "cell-size" }` |
134
+ | A4 | 完整 cell-size 回复仍 drop | 自动化(unit) | 同文件:`\x1b[6;24;80t` | `{ kind: "reply-complete", family: "cell-size", action: "drop" }` |
135
+ | A5 | guard 状态机不回归 | 自动化(unit) | 现有 `terminal-reply-guard` 全部用例 | 全绿 |
136
+ | A6 | attach 按键真的转发到子会话(不被 guard 吞) | 自动化(integration) | `test-support/attach-reply-guard-smoke.ts` 新增:`handleInput("")` / `handleInput("[6;5~")` 后 `sent` 含该字节;断言归 `test/pty-attach-reply-guard.test.mjs` | `sent` 收到完整键序列;且随后的普通文本仍正常转发 |
137
+ | A7 | 语法/静态检查 | 自动化(static) | `npm run typecheck`(`tsconfig` 对 `.mjs` 是 `allowJs` + `checkJs:false`,只做语法解析)+ `npm run pack:dry` | 均通过 |
138
+ | A8 | §4.1 的文档同步真的落地 | 自动化(static) | 三条独立 grep,全部锚定**英文** marker(源码是英文注释,中文只出现在 #170 文档):① `grep -c "complete CSI key" src/core/terminal-reply-guard.mjs`(≥1,且位于模块顶部注释区);② `grep -n "完整 CSI 键序列优先.*#213" docs/superpowers/specs/2026-10-14-issue-170-attach-reply-guard-design.md`(≥1);③ `grep -c "can never be a key" src/core/terminal-reply-guard.mjs`(**必须为 0** —— 旧的绝对断言已删除) | ①② ≥1、③ ==0 |
139
+ | U1 | 真实终端 PageDown | 用户实测 | 见 §6.1 三步前置 + WezTerm + pi fullscreen → attach → 按 PageDown | 面板按页向后滚动(或转发给子会话),与 PageUp 对称 |
140
+
141
+ ### 6.1 U1 执行时机与部署前置
142
+
143
+ 仓库加载补丁 checkout 的方式见 `README.md:54`(`pi install "$(pwd)"`)或 `README.md:68`(symlink 到
144
+ `~/.pi/agent/extensions/agent-board`)。U1 必须在以下三步之后执行,否则测的是旧代码:
145
+
146
+ 1. 用上述任一方式把**当前 worktree/checkout** 加载到 pi(不是 `~/.pi/agent/git/...` 的缓存克隆)
147
+ 2. 完整重启 pi(模块缓存不会热更新),并新开一个 attach 会话
148
+ 3. 时机:本地 `npm run typecheck` + 目标套件全绿之后、合并之前
149
+
150
+ > **验收 ID 作用域**:#213 的 `A1–A8` 仅指本 issue。新增测试名一律带 `#213-` 前缀
151
+ > (如 `test("#213-A1: kitty PageDown is a key, not a reply head")`),
152
+ > 因为 `test/terminal-reply-guard.test.mjs` 里已有 #170 遗留的 `A1:`/`A2:`/… 测试名,
153
+ > 直接用 `--test-name-pattern="A1"` 会同时命中两套语义不同的用例。
154
+
155
+ ## 7. 可测性拆分设计
156
+
157
+ - **判定逻辑已经是纯函数**(`classifyReplyEvent`),零改动地单测;本次只新增一个正则常量。
158
+ - 测试边界:`test/terminal-reply-guard.test.mjs` 覆盖 A1–A5(纯函数层);`test-support/attach-reply-guard-smoke.ts` + `test/pty-attach-reply-guard.test.mjs` 覆盖 A6(真实 `PtyAttachComponent.handleInput` → `sent` 转发,只替换 socket)。`test/pty-scroll.test.mjs` 与本次改动无关,不作为护栏。
159
+ - 正则常量导出与否:**不导出**(内部实现细节),测试通过 `classifyReplyEvent` 的公开行为验证,避免把实现形状钉进测试。
160
+
161
+ ## 8. 非目标
162
+
163
+ - 不改变 guard 的吸收窗口(250ms / 64 字节)与 kill switch 语义
164
+ - 不改动其他 `REPLY_HEADS` 条目
165
+ - 不处理 `PageUp`/`PageDown` 在 legacy 路径的行为差异(本就正常)
@@ -0,0 +1,131 @@
1
+ Drafted: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-19T13:58:00+08:00
2
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-19T14:10:00+08:00 — 第 1 轮复核处置(收敛轮,R1-D1..D4 细化)
3
+
4
+ # issue #214 根因报告与修复设计:attach 转发丢 Alt 修饰位,Alt+滚轮退化为 1 行
5
+
6
+ 仓库:zhuxixi/pi-agent-board · 基线:`origin/main` @ `64bca89`
7
+
8
+ ## 1. 症状
9
+
10
+ pi fullscreen 1.3.0 + WezTerm,在 attach 一个 fullscreen 子会话时:
11
+
12
+ | 手势 | 正常 fullscreen | attach 内 |
13
+ | --- | --- | --- |
14
+ | 滚轮 | 1 notch = 加速后的行数 | 相同(转发给子会话) |
15
+ | **Alt + 滚轮** | **5×**(`ALT_WHEEL_SCROLL_MULTIPLIER = 5`) | **1×** —— Alt 被静默丢弃 |
16
+
17
+ 其余滚轮行为(普通滚轮、PageUp/PageDown、本地 scrollback)都正常。
18
+
19
+ ## 2. 根因
20
+
21
+ fullscreen 子会话的滚轮走**转发**路径(alternate buffer 无 scrollback,见 #185/#198/#199/#205)。该路径**从零重建** SGR 报告,只保留方向:
22
+
23
+ `src/ui/pty-attach.ts:1477`:
24
+
25
+ ```ts
26
+ private forwardWheelToChild(linesUp: number, event: TuiMouseEvent): void {
27
+ this.send({
28
+ type: "input",
29
+ data: encodeWheelReport(linesUp > 0 ? "up" : "down", {
30
+ col: clampInt(event.x + 1, 1, this.cols),
31
+ row: clampInt(event.y, 1, Math.max(1, this.bodyHeight())),
32
+ // ← event.alt 没有传
33
+ }),
34
+ });
35
+ }
36
+ ```
37
+
38
+ `src/core/pty-scroll.mjs:370`:
39
+
40
+ ```js
41
+ export function encodeWheelReport(direction, { col, row } = {}) {
42
+ const button = direction === "up" ? 64 : 65; // 永远不置 SGR bit 3 (值 8 = Alt)
43
+ ...
44
+ }
45
+ ```
46
+
47
+ 真实终端用 SGR **bit 3(值 8)** 表示 Alt:Alt+wheel-up = `72 = 64 + 8`,Alt+wheel-down = `73 = 65 + 8`。
48
+ 子会话的 pi-tui 正是读这一位来决定 5× 加速
49
+ (`@earendil-works/pi-tui/dist/tui-alt-screen.js` `handleViewportInput`):
50
+
51
+ ```js
52
+ const wheelDelta = wheelEvent.direction * ((wheelEvent.button & 8) !== 0 ? lines * ALT_WHEEL_SCROLL_MULTIPLIER : lines);
53
+ ```
54
+
55
+ attach 覆盖层**本来就拿到了** Alt:pi-tui 的 `TuiMouseEvent` 带 `alt: boolean`(`createMouseEvent` 里 `alt: (button & 8) !== 0`)。它只是没被传下去。
56
+
57
+ ## 3. 证据(对仓库当前代码实测)
58
+
59
+ ```
60
+ encodeWheelReport("up", {col:5,row:3}) → "\x1b[<64;5;3M"
61
+ encodeWheelReport("up", {col:5,row:3,alt:true}) → "\x1b[<64;5;3M" ❌ alt 被忽略(应为 72)
62
+ encodeWheelReport("down", {col:5,row:3,alt:true}) → "\x1b[<65;5;3M" ❌(应为 73)
63
+ ```
64
+
65
+ 子会话侧对照:
66
+
67
+ | 子会话收到的报告 | 结果 |
68
+ | --- | --- |
69
+ | `\x1b[<64;5;3M`(plain) | 1× |
70
+ | `\x1b[<72;5;3M`(Alt+up,**当前永远收不到**) | 5× |
71
+ | `\x1b[<65;5;3M`(plain) | 1× |
72
+ | `\x1b[<73;5;3M`(Alt+down,**当前永远收不到**) | 5× |
73
+
74
+ ## 4. 修复
75
+
76
+ 把覆盖层的 `alt` 透传进编码器,置 SGR bit 3:
77
+
78
+ `src/core/pty-scroll.mjs`:
79
+
80
+ ```js
81
+ export function encodeWheelReport(direction, { col, row, alt = false } = {}) {
82
+ const base = direction === "up" ? 64 : 65;
83
+ const button = alt === true ? base + 8 : base;
84
+ const cell = (v) => (Number.isFinite(v) ? Math.max(1, Math.floor(v)) : 1);
85
+ return `\x1b[<${button};${cell(col)};${cell(row)}M`;
86
+ }
87
+ ```
88
+
89
+ `src/ui/pty-attach.ts` `forwardWheelToChild`:在参数对象里补 `alt: event.alt === true`。
90
+
91
+ ## 5. 边界与风险
92
+
93
+ | 风险 | 说明 / 缓解 |
94
+ | --- | --- |
95
+ | 影响本地滚动 | 不影响:本地路径用 `wheelDelta`(外层 pi 已加速的值),不经 `encodeWheelReport` |
96
+ | 影响 legacy regular-mode 路径 | 不影响:该路径(`handleMouseInputChunk`,`src/ui/pty-attach.ts:1110`)把原始 SGR `raw` **原样**转发,从不重建报告,因此天然保留 alt 位,本次不动它 |
97
+ | `event.alt` 缺失(老 pi-tui) | `alt = false` 默认值兜底;`=== true` 显式比较,`undefined` 不会误开位 |
98
+ | Alt 被终端吞掉 | 不在本次范围:终端若不发 Alt 位,覆盖层也拿不到;本次只保证"拿到就转发" |
99
+ | shift / ctrl 修饰位 | **非目标**:pi-tui 只消费 Alt 位做加速,转发其他位不会改变行为却扩大改动面;若将来需要,同一参数可扩展 |
100
+ | 与 #170 reply guard 的交互 | 无关:本次只改出站编码,入站分类不动 |
101
+ | 与 #213 的交互 | 无关:`\x1b[<` 开头是 SGR mouse,不命中 `CSI_KEY_SEQUENCE` 也不命中任何 reply head |
102
+
103
+ ## 6. 验收矩阵
104
+
105
+ | ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
106
+ | --- | --- | --- | --- | --- |
107
+ | A1 | Alt+wheel-up 编码为 72 | 自动化(unit) | `test/pty-scroll.test.mjs`:`encodeWheelReport("up", { col: 5, row: 3, alt: true })` | `"\x1b[<72;5;3M"` |
108
+ | A2 | Alt+wheel-down 编码为 73 | 自动化(unit) | 同上 | `"\x1b[<73;5;3M"` |
109
+ | A3 | 无 Alt 时行为不变,且严格比较(`=== true`) | 自动化(unit) | 同上:`alt: false` / 缺省 / `alt: undefined` / **`alt: 1`** / **`alt: "yes"`**(truthy 非布尔) | 全部为 64 / 65,无一置 bit 3 —— 锁死 `event.alt === true` 的严格比较契约 |
110
+ | A4 | 转发链路真的把 `event.alt` 传下去 | 自动化(integration) | `test-support/pty-attach-wheel-fallback-scenario.ts` 增加 `alt: true` 的 wheel 事件,断言 runner 收到 `\x1b[<72;…M` | 收到的报告含 `72`(up)/ `73`(down) |
111
+ | A5 | 本地滚动路径不受影响 | 自动化(integration) | 既有 `pty-attach-wheel` / `pty-attach-frame-overflow` / `pty-attach-alt-wheel` 套件 | 全绿 |
112
+ | A6 | 静态检查 | 自动化(static) | `npm run typecheck` + `npm run pack:dry` | 通过 |
113
+ | U1 | 真实终端 Alt+滚轮 | 用户实测 | 部署前置见 §6.1;attach 一个 fullscreen 子会话,按住 Alt 滚一格 | 子会话滚动 5 行(与 attach 外一致) |
114
+
115
+ ### 6.1 U1 执行时机与部署前置
116
+
117
+ 1. 用 `pi install "$(pwd)"`(`README.md:54`)或 symlink 到 `~/.pi/agent/extensions/agent-board` 加载**当前 checkout**,而不是 `~/.pi/agent/git/...` 缓存
118
+ 2. 完整重启 pi,新开一个 attach 会话
119
+ 3. 时机:目标套件全绿之后、合并之前
120
+
121
+ ## 7. 可测性拆分设计
122
+
123
+ - **编码逻辑是纯函数**(`encodeWheelReport`),签名扩展一个可选参数即可单测;无 I/O。
124
+ - **接线在 `forwardWheelToChild`**(薄壳),只多传一个字段;集成测试落在既有的 `pty-attach-wheel-fallback-scenario.ts`(真实 `Socket.prototype.write` 拦截),与 #198/#205 的断言模式一致。
125
+ - **测试边界**:A1–A3 在 `test/pty-scroll.test.mjs`(纯函数);A4 在 `test/pty-attach-wheel-fallback.test.mjs` + 对应 scenario;A5 复用既有套件;不新增测试文件。
126
+
127
+ ## 8. 非目标
128
+
129
+ - 不转发 shift / ctrl 修饰位(见 §5)
130
+ - 不改本地滚动路径的任何行为
131
+ - 不改 reply guard / 输入分类
@@ -0,0 +1,270 @@
1
+ # Root-cause report / Spec: recognize `ask_user_question` as a pending-question tool
2
+
3
+ Drafted: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-20T22:10:00+08:00
4
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-20T22:24:00+08:00 — folded in R1-D1..D5
5
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-21T22:10:00+08:00 — emitter identified and installed locally; U1 deployment path corrected from npm release to the git-install clone
6
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-21T22:22:00+08:00 — R2-D1 reference precision (blocked-event emit site)
7
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-21T22:15:00+08:00 — user chose the hybrid guard (name OR questionnaire arg shape); design, acceptance matrix, risks and testability split updated
8
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-21T22:35:00+08:00 — R3-D1..D3 (deliverables list, superseded decision row, no-id fallback boundary)
9
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-21T22:52:00+08:00 — local-CR: shape bound wording matches the implementation (empty question string still matches)
10
+
11
+ - **Issue**: zhuxixi/pi-agent-board#221
12
+ - **Date**: 2026-10-20
13
+ - **Status**: draft — awaiting cross-review and user confirmation
14
+ - **Type**: bug fix (event-reducer allow-list + regression test); no data-model, schema, or UI change
15
+
16
+ ## 1. Problem
17
+
18
+ A pi-style session blocked on a tool named `ask_user_question` stays in the **RUNNING**
19
+ group with the row summary `Ask_user_question`. It never reaches the **Needs answer**
20
+ group (`needs_input`, amber).
21
+
22
+ Reproduced at reducer level on `main` (9a197f4):
23
+
24
+ ```
25
+ actual ask_user_question → semanticState=working, summary="Ask_user_question",
26
+ pendingQuestions=[], question=null,
27
+ currentTool={name:"ask_user_question"}, needsInput=false
28
+ control question → semanticState=needs_input, summary="Which approach?", needsInput=true
29
+ ```
30
+
31
+ Evidence trail: `issue-221/research/root-cause.md`, issue comment 6292835562.
32
+
33
+ ## 2. Root cause
34
+
35
+ `src/core/events.mjs:21` defines an exact-membership allow-list:
36
+
37
+ ```js
38
+ const QUESTION_TOOL_NAMES = new Set(["ask_questions", "question", "questionnaire"]);
39
+ ```
40
+
41
+ Both gates are exact membership — `events.mjs:86` (`tool_execution_start`) and
42
+ `events.mjs:100` (`tool_execution_end`). `ask_user_question` misses both, so
43
+ `tool_execution_start` takes the generic branch (`currentTool` set, `semanticState =
44
+ "working"`), `preservePendingQuestion()` has nothing to promote, and `deriveSummary()`
45
+ falls back to `capitalize(name)`.
46
+
47
+ `questionFromArgs()` (`events.mjs:232`) already handles the arg shape
48
+ (`args.questions[].question`) — no extraction change is needed.
49
+
50
+ **Emitter (confirmed 2026-10-21)**: `ask_user_question` is registered by the pi extension
51
+ `@juicesharp/rpiv-ask-user-question` — `ask-user-question.ts:84`
52
+ (`ASK_USER_QUESTION_TOOL_NAME = "ask_user_question"`), registered at `:455-459`. It is not a
53
+ pi 1.3.0 built-in (pi ships no question tool; `question`/`questionnaire` come from
54
+ `pi-question-tool`). The extension is now installed on this machine: v2.13.9,
55
+ `~/.pi/agent/settings.json:90`, `~/.pi/agent/npm/node_modules/@juicesharp/rpiv-ask-user-question`,
56
+ and the tool is live in the session after `/reload` (session tool list contains
57
+ `question`, `questionnaire`, `ask_user_question`). Its arg schema
58
+ (`{ questions: [{ question, header, options, multiSelect }] }`) is exactly what
59
+ `questionFromArgs` already reads.
60
+
61
+ The defect stands regardless of the emitter: any unrecognized question-tool name silently
62
+ degrades grouping.
63
+
64
+ ## 3. Design
65
+
66
+ ### 3.1 Detection: name allow-list OR questionnaire arg shape
67
+
68
+ ```js
69
+ /** Tool names whose interactive execution blocks on a user answer. */
70
+ const QUESTION_TOOL_NAMES = new Set(["ask_questions", "question", "questionnaire", "ask_user_question"]);
71
+
72
+ /** Questionnaire args shared by pi/Claude-Code style question tools. */
73
+ function isQuestionArgShape(args) {
74
+ const questions = Array.isArray(args?.questions) ? args.questions : null;
75
+ return Boolean(questions && questions.length > 0 && typeof questions[0]?.question === "string");
76
+ }
77
+
78
+ function isQuestionToolCall(name, args) {
79
+ return QUESTION_TOOL_NAMES.has(name) || isQuestionArgShape(args);
80
+ }
81
+ ```
82
+
83
+ Why both: the name set keeps the known tools working even with empty args
84
+ (`ask_questions` is exercised with `args: {}` at `test/events.test.mjs:137`), while the shape
85
+ check survives a renamed or newly packaged question tool as long as it keeps the
86
+ `questions[0].question` schema. Neither replaces the other.
87
+
88
+ **End gate becomes name-agnostic**: `tool_execution_end` carries no `args`, so a
89
+ shape-matched start cannot be recognized at end time. Replace
90
+ `opts.interactive && QUESTION_TOOL_NAMES.has(event.toolName ?? "")` with
91
+ `opts.interactive` and let `removePendingQuestion(status, event.toolCallId)` filter by call
92
+ id (it is already a no-op when the id is not pending). Tool-call ids are unique per call, so
93
+ this cannot clear someone else's question.
94
+
95
+ The guarantee is exact for real worker events, which always carry `toolCallId`
96
+ (`pi` dist `agent-session` emits `{toolCallId,toolName,result,isError}`). The pre-existing
97
+ no-id fallback (`events.mjs:242/250` map a missing id to the literal `"ask_questions"`) is
98
+ unchanged; a malformed event without an id could therefore clear a pending entry that also
99
+ lacked one. That path is unreachable from the real event stream and is left as-is.
100
+
101
+ No other module reads question-tool names (`rg ask_questions src/` → only `events.mjs`).
102
+
103
+ ### 3.2 Regression guard
104
+
105
+ Two new reducer tests in `test/events.test.mjs`, next to the existing
106
+ `interactive pi question tool …` test:
107
+
108
+ **Test A — name path (`ask_user_question`), pinned to the literal name**
109
+
110
+ - interactive start → `needs_input`, summary/question = first question text,
111
+ `pendingQuestions` length 1, `currentTool === null`, `projectViewState().needsInput === true`;
112
+ - interactive end for the same `toolCallId` → `working`, `question === null`,
113
+ `pendingQuestions === []`;
114
+ - detached reduction (no `interactive`) → `working`, `currentTool.name === "ask_user_question"`,
115
+ `pendingQuestions === []`.
116
+
117
+ **Test B — shape path (unknown name), plus the negative guard**
118
+
119
+ - interactive start with `toolName: "mystery_questionnaire"` and
120
+ `args: { questions: [{ question: "Ship it?", header: "Release", options: [{ label: "Yes" }] }] }`
121
+ → `needs_input`, question `"Ship it?"`, one pending entry;
122
+ - interactive end with the **same unknown name** → `working`, cleared (proves the end gate is
123
+ call-id based, not name based);
124
+ - negative cases that must stay `working` with an empty `pendingQuestions`:
125
+ `{ questions: [] }`, `{ questions: "nope" }`, and a non-question tool (`bash`).
126
+
127
+ The literal name in Test A plus the unknown-name case in Test B are the guards: dropping the
128
+ name or the shape check fails `npm test` instead of silently regressing the dashboard.
129
+
130
+ ### 3.3 Alternatives considered
131
+
132
+ | Alternative | Verdict | Reason |
133
+ |---|---|---|
134
+ | Arg-shape detection instead of a name set | Rejected | `ask_questions` is exercised with `args: {}` (`test/events.test.mjs:135`) and must still be `needs_input`; shape alone cannot cover it. |
135
+ | Hybrid (`set OR questions[] shape`) at drafting | Rejected, then superseded | Drafting-time verdict was to keep the diff minimal; the user gate on 2026-10-21 chose the hybrid, so this row is history only — the authoritative decision is the Adopted row below. |
136
+ | Configurable allow-list | Rejected | No config surface exists for reducer behavior; over-engineering for a one-name gap. |
137
+ | Export the set for tests | Rejected | The reducer is the public surface; tests already drive it directly. Exporting a private constant adds API for no gain. |
138
+ | Upstream `rpiv:ask-user:blocked` event instead of name detection | Rejected | Constant defined at `events.ts:38`, emitted at `ask-user-question.ts:64` (`pi.events.emit`) — an in-process bus event on the extension host. The board consumes JSON-mode worker stdout, which never carries pi bus events, so the channel is unreachable. |
139
+ | Name set OR arg-shape fallback | **Adopted** (user decision, 2026-10-21) | Survives a rename or a newly packaged question tool as long as the schema stays `questions[0].question`. Cost: any interactive tool with that exact shape is treated as a pending question; bounded by requiring a non-empty `questions[0].question` string and by the `opts.interactive` gate. |
140
+
141
+ ### 3.4 Data flow (unchanged, verified)
142
+
143
+ | Step | Location | Result |
144
+ |---|---|---|
145
+ | interactive start, name in set OR questionnaire shape | `events.mjs:86` → `upsertPendingQuestion` → `preservePendingQuestion` | `needs_input`, `currentTool=null`, `question` = first question |
146
+ | summary | `derive.mjs:103` | question text wins over tool name |
147
+ | projection | `events.mjs:209` | `needsInput: true` |
148
+ | interactive end | `events.mjs:100` → `removePendingQuestion` (by call id) | back to `working`, `question=null` |
149
+ | inline reply while pending | `src/ui/dashboard.ts:2054 isAgentBusy` + `README.md:167/299` | reply rejected; answer via attach (pre-existing contract, now also applies to this name) |
150
+ | detached start/end | `opts.interactive` gate | unchanged `currentTool` behavior |
151
+
152
+ ## 4. Acceptance matrix
153
+
154
+ | ID | Feature point | Verification | Concrete check | Pass criteria |
155
+ |----|---------------|--------------|----------------|---------------|
156
+ | A1 | `ask_user_question` start is treated as a pending question | automated (unit) | `npm test` — new test in `test/events.test.mjs` | `semanticState==="needs_input"`, `summary`/`question` equal `"Which approach?"`, `pendingQuestions.length===1`, `currentTool===null`, `projectViewState(s).needsInput===true` |
157
+ | A2 | `ask_user_question` end clears the pending question | automated (unit) | same test | `semanticState==="working"`, `question===null`, `pendingQuestions` empty |
158
+ | A3 | Detached reduction keeps legacy behavior | automated (unit) | same test (no `interactive` opt) | `semanticState==="working"`, `currentTool.name==="ask_user_question"`, `pendingQuestions` empty |
159
+ | A4 | No regression for the existing three names | automated (unit) | `npm test` (existing tests at `test/events.test.mjs:109/135/163/206/220`) | all pass unchanged |
160
+ | A5 | Shape fallback: unknown tool name with questionnaire args becomes a pending question | automated (unit) | Test B in `test/events.test.mjs` | `semanticState==="needs_input"`, question `"Ship it?"`, `pendingQuestions.length===1`, `currentTool===null` |
161
+ | A6 | End gate clears shape-matched calls without a name match | automated (unit) | Test B — `tool_execution_end` with the same unknown `toolName`/`toolCallId` | `semanticState==="working"`, `question===null`, `pendingQuestions` empty |
162
+ | A7 | Misleading args do not trigger the shape fallback | automated (unit) | Test B negative cases: `{questions: []}`, `{questions: "nope"}`, and `bash` | `semanticState==="working"`, `pendingQuestions` empty in all three |
163
+ | A8 | Repo-level static gate stays green | automated (static) | `npm run typecheck` | exit 0. Note: `tsconfig.json:9` sets `checkJs:false`, so this gate covers the `.ts` surface and is a repo regression check, not proof of this `.mjs` change; A1–A7 are the real proof |
164
+ | U1 | A real board session blocked on `ask_user_question` renders under Needs answer | user test | see §5 | row under **Needs answer** with the question text as summary; end of call returns it to RUNNING |
165
+
166
+ Full gate: `npm run verify` (typecheck + perf gate + tests + coverage thresholds + pack dry-run).
167
+
168
+ Failure branches: A2/A6 assert clear-on-end, A3 asserts detached stays generic, A7 asserts the
169
+ false-positive guard. No error path is added by this change, so no error-path item is owed.
170
+
171
+ ## 5. User test (U1) — steps and timing
172
+
173
+ Now executable on this machine: the emitter is installed (`@juicesharp/rpiv-ask-user-question`
174
+ 2.13.9) and the tool is live after `/reload`. The remaining precondition is the **board code**
175
+ itself — the board process loads from the git-install clone, not from this working checkout and
176
+ not from npm:
177
+
178
+ - `pi list` → `git:github.com/zhuxixi/pi-agent-board` at
179
+ `~/.pi/agent/git/github.com/zhuxixi/pi-agent-board` (`~/.pi/agent/settings.json:85`), HEAD
180
+ `9a197f4` (= `main` at drafting time). That clone currently has a dirty `package-lock.json`
181
+ (4 deleted `"peer": true` lines), which must be discarded before pulling.
182
+
183
+ Timing: after the fix merges to `main`.
184
+
185
+ 1. Update the clone the board actually loads, then restart the board/Pi:
186
+ `cd ~/.pi/agent/git/github.com/zhuxixi/pi-agent-board && git checkout -- package-lock.json && git pull`
187
+ (or re-run `pi install git:github.com/zhuxixi/pi-agent-board`); confirm
188
+ `git log -1 --oneline` is the merged commit.
189
+ 2. Restart Pi / the board service (an already-running pi process keeps the old extension code).
190
+ 3. Dispatch a board session whose prompt forces a decision, so the model calls
191
+ `ask_user_question` with `questions[0].question` containing a short decision question
192
+ (e.g. "Which approach?"). The extension is user-level, so every session sees the tool.
193
+ 4. Open the dashboard, then answer via attach.
194
+
195
+ Expected observation: the row sits under **Needs answer** (amber) with the question text as
196
+ its summary, `pendingQuestions` holds one entry, inline reply is refused (pre-existing
197
+ contract); after answering, the row returns to **RUNNING**.
198
+
199
+ If the merge has not happened by completion time, U1 is reported as `pending` (not passed);
200
+ A1–A5 still prove the reducer contract.
201
+
202
+ ## 6. Non-goals
203
+
204
+ - No change to `detectNeedsInput()` text heuristics or `message_end` classification.
205
+ - The shape fallback does **not** apply to detached (non-interactive) runs: headless sessions
206
+ cannot answer, so they keep `currentTool` display.
207
+ - No rename of the `"ask_questions"` fallback ids in `upsertPendingQuestion` /
208
+ `removePendingQuestion` (`events.mjs:242/250`).
209
+ - No config surface or UI affordance for arbitrary question-tool names.
210
+ - No change to attach/reply/answer transport; only reducer classification changes.
211
+
212
+ ## 7. Risks and boundaries
213
+
214
+ - **False positive (accepted)**: any interactive tool whose args are
215
+ `{ questions: [{ question: <string> }] }` is treated as a pending question, even if it is
216
+ not asking the user. Bounded by the `opts.interactive` gate and by requiring the first
217
+ `question` to be a string; an empty or whitespace-only string still matches and falls back
218
+ to the generic "Answer the pending question" text, exactly like the name-set path. No
219
+ installed extension is known to declare that shape for a non-question purpose today
220
+ (research §4), but absence over third-party code is not provable, so the guard is the bound
221
+ itself, not a completeness claim.
222
+ - **End gate is now name-agnostic**: every interactive `tool_execution_end` calls
223
+ `removePendingQuestion(id)`. For real worker events (which always carry `toolCallId`) ids are
224
+ unique per call, so this clears the matching entry or does nothing; it cannot clear another
225
+ call's question (covered by A6 and by the existing multi-question test at
226
+ `test/events.test.mjs:135`). The legacy no-id fallback is unchanged and is documented in §3.1
227
+ as the only way a cross-clear could occur.
228
+ - **Shape fallback is a heuristic**: a tool that renames its `questions` payload field
229
+ (e.g. to `prompts`) still regresses. Accepted; a schema change is a protocol change, not a
230
+ rename, and cannot be absorbed by a reducer heuristic.
231
+ - **Detached runs** are unaffected — headless sessions cannot answer, so they must keep
232
+ `currentTool` display.
233
+ - **Only JSON-mode worker events reach the reducer.** The extension's own
234
+ `rpiv:ask-user:blocked` bus event is in-process and never appears in worker stdout, so the
235
+ board cannot rely on it.
236
+ - **Inline reply is rejected while the question is pending** (`README.md:167/299`,
237
+ `src/ui/dashboard.ts:2054 isAgentBusy`). This is pre-existing behavior for pending
238
+ questions and now applies to `ask_user_question` rows too; answer via attach. Expected,
239
+ not a regression.
240
+
241
+ ## 8. Testability split
242
+
243
+ The reducer is already a pure-function seam: `createRunStatus(config, pid, now)` builds
244
+ state, `reduceEvent(status, event, now, opts)` mutates it, `projectViewState(status, now)`
245
+ projects it. Two new module-private pure helpers carry the new logic —
246
+ `isQuestionArgShape(args)` and `isQuestionToolCall(name, args)` — and are driven through
247
+ `reduceEvent`, the public surface, exactly like the existing `questionFromArgs` (which is
248
+ also private and tested through the reducer).
249
+
250
+ Planned split:
251
+
252
+ | Unit | Purity | Test seam |
253
+ |---|---|---|
254
+ | `isQuestionArgShape(args)` | pure, no I/O | via `reduceEvent` start events (Test B positives/negatives) |
255
+ | `isQuestionToolCall(name, args)` | pure, no I/O | via `reduceEvent`; name path in Test A, shape path in Test B |
256
+ | start handler branch | side-effect-free over `RunStatus` | `reduceEvent` + `projectViewState` assertions |
257
+ | end handler (call-id removal) | side-effect-free over `RunStatus` | `reduceEvent` end events (Test A, Test B, existing multi-question test) |
258
+
259
+ Test boundary: `test/events.test.mjs` only. No export is added to `src/core/events.mjs`;
260
+ the helpers stay private and are covered through the reducer, matching the existing pattern.
261
+
262
+ ## 9. Deliverables
263
+
264
+ - `src/core/events.mjs` — add `ask_user_question` to `QUESTION_TOOL_NAMES`; add the private
265
+ `isQuestionArgShape(args)` / `isQuestionToolCall(name, args)` helpers; gate
266
+ `tool_execution_start` on `isQuestionToolCall`; make `tool_execution_end` clear by
267
+ `toolCallId` under `opts.interactive` only.
268
+ - `test/events.test.mjs` — Test A (name path) and Test B (shape path + negative guards).
269
+ - `docs/superpowers/specs/2026-10-20-issue-221-ask-user-question-design.md` — this design,
270
+ committed with the fix (repo precedent: #213/#214/#215 each ship their spec with the PR).