@zhuxixi/pi-agent-board 0.13.0 → 0.14.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 +65 -0
- package/README.md +37 -12
- package/docs/SECTION_FOLDING.md +53 -0
- package/docs/superpowers/plans/2026-10-23-issue-222-attach-ready.md +290 -0
- package/docs/superpowers/plans/2026-10-26-issue-245-key-hints-doc-sync.md +244 -0
- package/docs/superpowers/plans/2026-10-27-issue-172-fullscreen-selection-clear.md +344 -0
- package/docs/superpowers/plans/2026-10-27-issue-252-select-key-hints.md +209 -0
- package/docs/superpowers/plans/2026-10-28-issue-255-coordinator-endpoint-zombie.md +442 -0
- package/docs/superpowers/plans/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup.md +256 -0
- package/docs/superpowers/plans/2026-11-03-cwd-favorites-full-pool.md +266 -0
- package/docs/superpowers/plans/2026-11-03-issue-266-alt-h-detach.md +467 -0
- package/docs/superpowers/plans/2026-11-04-issue-270-scenario-stdout-flush.md +584 -0
- package/docs/superpowers/plans/2026-11-05-issue-278-ctrl-g-external-editor.md +381 -0
- package/docs/superpowers/plans/2026-11-06-issue-280-frame-witness-delivery.md +430 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-attach-recovery.md +115 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-u1-u2-trial-guide.md +39 -0
- package/docs/superpowers/plans/2026-11-08-host-restart-model-override.md +894 -0
- package/docs/superpowers/plans/2026-11-08-issue-288-cap-floor.md +51 -0
- package/docs/superpowers/plans/2026-11-09-dashboard-fold-flake.md +166 -0
- package/docs/superpowers/plans/2026-11-09-issue-273-harness-console-log-exit.md +369 -0
- package/docs/superpowers/plans/2026-11-10-issue-258-board-selection-settle.md +760 -0
- package/docs/superpowers/plans/2026-11-13-issue-294-snapshot-resize-intent.md +590 -0
- package/docs/superpowers/plans/2026-11-16-greeting-title-poll.md +838 -0
- package/docs/superpowers/plans/2026-11-22-issue-297-compaction-mirror.md +797 -0
- package/docs/superpowers/plans/2026-11-23-issue-254-cursor-keep-position.md +663 -0
- package/docs/superpowers/plans/2026-11-23-issue-95-legacy-quarantine.md +320 -0
- package/docs/superpowers/specs/2026-10-23-issue-222-attach-ready-design.md +204 -0
- package/docs/superpowers/specs/2026-10-26-issue-245-key-hints-doc-sync-design.md +72 -0
- package/docs/superpowers/specs/2026-10-27-issue-172-fullscreen-selection-clear-design.md +248 -0
- package/docs/superpowers/specs/2026-10-27-issue-252-select-key-hints-design.md +95 -0
- package/docs/superpowers/specs/2026-10-28-issue-255-coordinator-endpoint-zombie-design.md +380 -0
- package/docs/superpowers/specs/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup-design.md +197 -0
- package/docs/superpowers/specs/2026-11-03-cwd-favorites-full-pool-design.md +106 -0
- package/docs/superpowers/specs/2026-11-03-issue-266-alt-h-detach-design.md +185 -0
- package/docs/superpowers/specs/2026-11-04-issue-270-scenario-stdout-flush-design.md +176 -0
- package/docs/superpowers/specs/2026-11-05-issue-278-ctrl-g-external-editor-design.md +185 -0
- package/docs/superpowers/specs/2026-11-07-issue-284-attach-recovery-design.md +166 -0
- package/docs/superpowers/specs/2026-11-08-host-restart-model-override-design.md +115 -0
- package/docs/superpowers/specs/2026-11-08-issue-288-cap-floor-design.md +86 -0
- package/docs/superpowers/specs/2026-11-09-dashboard-fold-flake-design.md +109 -0
- package/docs/superpowers/specs/2026-11-09-issue-273-harness-console-log-exit-design.md +182 -0
- package/docs/superpowers/specs/2026-11-10-issue-258-board-selection-settle-design.md +109 -0
- package/docs/superpowers/specs/2026-11-13-issue-294-snapshot-resize-intent-design.md +141 -0
- package/docs/superpowers/specs/2026-11-16-greeting-title-poll-design.md +174 -0
- package/docs/superpowers/specs/2026-11-22-issue-297-compaction-mirror-design.md +158 -0
- package/docs/superpowers/specs/2026-11-22-issue-95-legacy-quarantine-design.md +209 -0
- package/docs/superpowers/specs/2026-11-23-issue-254-cursor-keep-position-design.md +201 -0
- package/package.json +1 -1
- package/runner/pty-runner.mjs +526 -63
- package/runner/state-coordinator.mjs +62 -5
- package/runner/title-runner.mjs +33 -24
- package/src/commands/agent-board.ts +5 -1
- package/src/core/attach-detach.mjs +27 -0
- package/src/core/attach-frame-proof.mjs +897 -0
- package/src/core/attach-frame-reporter.mjs +738 -0
- package/src/core/attach-frame-stream.mjs +266 -0
- package/src/core/attach-pr-label.mjs +12 -0
- package/src/core/attach-recovery.mjs +239 -0
- package/src/core/attach-screen-owner.mjs +55 -0
- package/src/core/attach-view-proof.mjs +709 -0
- package/src/core/auto-state.mjs +6 -1
- package/src/core/cwd-stats.mjs +3 -1
- package/src/core/dashboard-prefs.mjs +31 -0
- package/src/core/derive.mjs +8 -1
- package/src/core/events.mjs +127 -1
- package/src/core/foreground-projection-cache.mjs +1 -0
- package/src/core/frame-witness-update.mjs +35 -0
- package/src/core/fullscreen-selection.mjs +60 -0
- package/src/core/host-coordination.mjs +48 -0
- package/src/core/host-protocol.mjs +13 -2
- package/src/core/hosted-frame-witness.mjs +60 -0
- package/src/core/paths.mjs +10 -3
- package/src/core/pty-attach-render.mjs +239 -0
- package/src/core/pty-kitty-images.mjs +237 -0
- package/src/core/pty-scroll.mjs +8 -8
- package/src/core/rows.mjs +43 -7
- package/src/core/session-entries.mjs +82 -0
- package/src/core/session-launch-prefs.mjs +45 -0
- package/src/core/session-view.mjs +3 -63
- package/src/core/store.mjs +1 -0
- package/src/core/terminal-attach-client.mjs +199 -20
- package/src/core/terminal-attach-protocol.mjs +221 -7
- package/src/core/terminal-model.mjs +24 -3
- package/src/core/terminal-snapshot.mjs +10 -0
- package/src/core/title-flow.mjs +66 -0
- package/src/core/title.mjs +101 -0
- package/src/core/types.mjs +17 -0
- package/src/index.ts +85 -0
- package/src/runtime/service.mjs +87 -18
- package/src/ui/dashboard.ts +206 -49
- package/src/ui/pty-attach.ts +1472 -99
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Issue #279 — Root-cause report & fix spec: dashboard-fold harness flake ('selected session/header must never be hidden by an indicator')
|
|
2
|
+
|
|
3
|
+
Drafted: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-09T08:55:00+08:00
|
|
4
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-09T09:02:00+08:00
|
|
5
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-09T09:20:00+08:00
|
|
6
|
+
|
|
7
|
+
Repo: zhuxixi/pi-agent-board · Baseline: origin/main @ 608a22a · Type: bug (test-only) · Refs: #95 (umbrella), #234 (introducing PR)
|
|
8
|
+
|
|
9
|
+
## 1. Root cause (established, deterministic reproduction)
|
|
10
|
+
|
|
11
|
+
`frame()` in `test-support/dashboard-fold.ts:52-57` compares **full strings** from two
|
|
12
|
+
independent render passes: `dash.render(width)` then `dash.renderRows(width)`, asserting
|
|
13
|
+
`lines.includes(body[selectedBodyLine])`. `renderRows()` reads a fresh `Date.now()`
|
|
14
|
+
(`src/ui/dashboard.ts:1486`) and every session row ends with the `age` column
|
|
15
|
+
(`relativeTime`, whole-second granularity — `src/core/heuristics.mjs:303` via `rowView`,
|
|
16
|
+
`src/core/rows.mjs:151`). When the two passes straddle the selected row's age boundary
|
|
17
|
+
(phase = `lastActivityAt mod 1000`, recurs once per second), the trailing `1s` becomes
|
|
18
|
+
`2s` and the full-string `includes` fails. Header lines carry no age — consistent with
|
|
19
|
+
failures landing inside `focusHeader` navigation.
|
|
20
|
+
|
|
21
|
+
The originally suspected poll/refresh between the two calls is ruled out: the probe is
|
|
22
|
+
fully synchronous; the only state advancing between the two calls is the clock.
|
|
23
|
+
|
|
24
|
+
Evidence (untouched probe, main @ 608a22a; scripts in
|
|
25
|
+
`~/.github-issue-driven/zhuxixi/pi-agent-board/issue-279/research/`):
|
|
26
|
+
|
|
27
|
+
- frozen clock (`--import` loader pinning `Date.now`) → `{"ok":true}`;
|
|
28
|
+
- clock advancing +1000ms per `Date.now()` call → red with the **exact CI assertion and
|
|
29
|
+
stack** (`frame` @ dashboard-fold.ts:56 via `focusHeader` @ :64);
|
|
30
|
+
- real clock straddling the age boundary → red, no fake clock;
|
|
31
|
+
- real clock on a fast local machine → 10/10 green (matches the issue report; c8
|
|
32
|
+
instrumentation + throttled CI runners stretch the render pair into straddle range).
|
|
33
|
+
|
|
34
|
+
Why CI and not local: c8 instrumentation + parallel load stretch one render pair to tens
|
|
35
|
+
of ms; the probe issues 100+ `frame()` calls; any straddle while a row is selected fails.
|
|
36
|
+
Blast radius: this full-string cross-pass compare exists **only** at
|
|
37
|
+
`dashboard-fold.ts:56`. Sibling probes from the same PR compare a 20-char visible prefix
|
|
38
|
+
(`dashboard-scroll.ts:67`, `dashboard-tui-modes.ts:76`), which excludes the trailing age
|
|
39
|
+
and therefore never flakes. No production-code defect.
|
|
40
|
+
|
|
41
|
+
## 2. Fix design (test-only)
|
|
42
|
+
|
|
43
|
+
Decision table:
|
|
44
|
+
|
|
45
|
+
| Option | Change | Verdict | Rationale |
|
|
46
|
+
|---|---|---|---|
|
|
47
|
+
| D1 prefix compare | `frame()` compares a 20-char visible prefix of the selected body line against prefixes of the frame lines (local helper, same shape as `dashboard-scroll.ts:67`) | **adopt** | Matches the sibling-probe convention; asserts exactly what the check means (the selected target is visible in the windowed frame, not replaced by a scroll indicator); immune to trailing-column jitter; minimal diff |
|
|
48
|
+
| D2 freeze probe clock | pin `Date.now` for the whole probe | reject (standalone) | Masks future trailing-column nondeterminism instead of making the assertion precise about its meaning; no probe-layer precedent (clock patching exists only at unit-test layer) |
|
|
49
|
+
| D3 single snapshot | production `render()` exposes the body it used | reject | Adds statefulness to a production component for a test-only concern |
|
|
50
|
+
| D4 deterministic regression leg | a permanent test case runs the probe with a clock that advances +1000ms per `Date.now()` call and must stay green | **adopt** (on top of D1) | Converts the flake into a deterministic guard; precedent: #184's load-independent repro leg. Validated: this exact loader is what turns the current probe red at the CI assertion |
|
|
51
|
+
|
|
52
|
+
Planned changes (all under `test-support/` + `test/`):
|
|
53
|
+
|
|
54
|
+
1. `test-support/dashboard-fold.ts` — in `frame()`, replace the full-string
|
|
55
|
+
`includes` with a prefix comparison:
|
|
56
|
+
`const prefix = (line) => line.trimEnd().slice(0, 20);`
|
|
57
|
+
assert `lines.some(line => prefix(line) === prefix(body[selectedBodyLine]))`.
|
|
58
|
+
Keep the existing height and `visibleWidth` assertions unchanged.
|
|
59
|
+
2. `test-support/tick-clock.mjs` (new; side-effect-only preload module, no exports) —
|
|
60
|
+
`Date.now` advances +1000ms per call.
|
|
61
|
+
3. `test/dashboard-fold.test.mjs` — new test case "folding stays deterministic when the
|
|
62
|
+
clock advances between render passes": spawn the probe with
|
|
63
|
+
`--import <tick-clock.mjs>`, assert `{"ok":true}` (same execFileSync pattern as the
|
|
64
|
+
existing cases).
|
|
65
|
+
|
|
66
|
+
Why the tick leg passes after D1 (and only then): with the prefix compare, the only
|
|
67
|
+
column that differs between the two passes (trailing age) is outside the compared
|
|
68
|
+
prefix; all other fixture content is time-invariant (no host → `staleHost` constant;
|
|
69
|
+
`unread` static; no age-string assertions in the probe).
|
|
70
|
+
|
|
71
|
+
## 3. Acceptance matrix
|
|
72
|
+
|
|
73
|
+
| ID | Function point | Acceptance | Concrete verification | Pass standard |
|
|
74
|
+
|----|---|---|---|---|
|
|
75
|
+
| A1 | `frame()` visibility assertion is immune to clock advancing between the two render passes | Automated (integration — probe subprocess) | From repo root: `for i in $(seq 1 20); do node --test test/dashboard-fold.test.mjs >/dev/null || { echo "fail run $i"; exit 1; }; done; echo 20/20` (fail-fast; every round exit 0) | 20/20 green |
|
|
76
|
+
| A2 | Deterministic regression leg for this flake | Automated (integration — new test case) | `node --test test/dashboard-fold.test.mjs` includes the tick-clock case; on the unfixed probe it must be able to fail (verified pre-fix in research), post-fix green | New case passes; `npm test` green |
|
|
77
|
+
| A3 | The D1 rewrite keeps the assertion's teeth (it still fails when the selected line is actually hidden) | Automated (one-off mutation check, evidence recorded) | In the worktree, temporarily remove `windowBody`'s selected-line guard (make it slice from line 0 unconditionally), run the probe, confirm the prefix assertion fails; then revert | Probe red under the mutation; green after revert |
|
|
78
|
+
| A4 | Suite regression + stress per issue acceptance | Automated (integration + coverage) | `npm test` once; `npm run test:coverage` once (the full-suite 85/80/70 threshold gate; repo c8 entry `c8 node scripts/run-tests.mjs`, config `.c8rc.json`); probe-under-c8 stress from repo root with the coverage check disabled (thresholds are the full-suite gate's job, and `.c8rc.json`'s `check-coverage: true` would otherwise fail every single-probe round): `for i in $(seq 1 20); do npx c8 --check-coverage=false node --experimental-transform-types test-support/dashboard-fold.ts >/dev/null || { echo "fail run $i"; exit 1; }; done; echo 20/20` (note: `--silent` is not a valid c8 flag and usage-errors the invocation; verified forms: with `--check-coverage=false` the probe runs and exits 0, without it the probe passes but c8 exits 1 on thresholds) | All green, thresholds met, stress 20/20 |
|
|
79
|
+
| A5 | Repo gates | Automated (build/verify) | `npm run verify` | Passes |
|
|
80
|
+
| U1 | The issue's acceptance holds on main's CI for the carrying merge commit | User observation (post-merge window) | After merge, locate the main **push** CI run whose head SHA equals this fix's merge commit; record the run URL; check `Test (Node 22)` and `Test (Node 24)` job conclusions and grep their logs for the target signature | Both Node jobs `success` AND zero occurrences of 'must never be hidden by an indicator' in that run. If that run goes red on a *different* #95-family signature, U1 stays **pending** (that signature is logged to the #95 ledger, not here) until a green run on a subsequent head; other-family reds never satisfy U1 |
|
|
81
|
+
|
|
82
|
+
## 4. Testability split (design constraint for implementation)
|
|
83
|
+
|
|
84
|
+
- `prefix(line)` is a pure function local to the probe (same shape as the sibling
|
|
85
|
+
helper); no I/O. Test boundary: the probe subprocess itself (public key input driving
|
|
86
|
+
+ white-box `frame()`).
|
|
87
|
+
- `tick-clock.mjs` is a side-effect-only preload module (patches `Date.now` at preload
|
|
88
|
+
time, exports nothing). Test boundary: full subprocess isolation; the clock dimension
|
|
89
|
+
is exercised independently of the real-clock legs, so a regression in either dimension
|
|
90
|
+
fails a distinct named case.
|
|
91
|
+
- The `.test.mjs` layer owns only process spawning and JSON assertion (thin I/O shell
|
|
92
|
+
over pure probe logic) — matching `scripts/release_helper.mjs`'s pure-core/thin-shell
|
|
93
|
+
convention.
|
|
94
|
+
|
|
95
|
+
## 5. Non-goals
|
|
96
|
+
|
|
97
|
+
- No production `src/` changes.
|
|
98
|
+
- No suite-wide clock freezing or CI workflow changes.
|
|
99
|
+
- No new #95 umbrella accounting beyond a pointer comment (root cause + fix live here).
|
|
100
|
+
- Not touching `dashboard-scroll.ts` / `dashboard-tui-modes.ts` (already immune).
|
|
101
|
+
|
|
102
|
+
## 6. Risks
|
|
103
|
+
|
|
104
|
+
- Prefix window (20 cols) will not detect corruption beyond column 20 — accepted; same
|
|
105
|
+
acceptance as both sibling probes, and the assertion's intent is visibility, not
|
|
106
|
+
content equality.
|
|
107
|
+
- The tick leg assumes no other time-sensitive assertion exists in the probe —
|
|
108
|
+
verified against the current probe (age strings are never asserted); if a future
|
|
109
|
+
assert becomes time-sensitive, the tick leg will catch it loudly, which is desired.
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# spec — issue #273:六个 harness 用 `console.log` 打 JSON 结果后立刻 `process.exit`
|
|
2
|
+
|
|
3
|
+
Drafted: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-11-09T08:51:35+08:00
|
|
4
|
+
Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-11-09T08:58:04+08:00 — cross-review R1(真缺口 1 / 细化 2):R1-G1 接受(A3 拆成「driver 成功/失败退出码」与「孤儿 harness smoke 两条退出码」,不再把无消费方夹具计入「消费方已验证」);R1-D1 接受(whitespace-only 也视为 unset,A5 样本补齐);R1-D2 接受(D5 改为只同步 helper 的注释,不改运行时代码)
|
|
5
|
+
Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-11-09T09:04:38+08:00 — cross-review R2(真缺口 0 / 细化 3,收敛):R2-D1 接受(A4 命令写死 `test/scenario-stdout-flush.test.mjs`,注明 `--experimental-transform-types` 启动与 5 秒 spawn 超时);R2-D2 接受(A3/A4/A5 补「原始 stdout 以换行结尾」断言,六类调用点各覆盖一次);R2-D3 接受(「纯函数」表述收窄为「不直接读 `process.env`/`process.cwd`,非空相对值沿用 `path.resolve` 的 cwd 语义」,A7 增加相对值样本)
|
|
6
|
+
Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-11-09T10:27:00+08:00 — Zima CR round-1 advisory accepted(advisory,低):settled 运行钉住 4 秒 harness 预算 `HARNESS_TIMEOUT_MS: "4000"`,使 harness 自身超时总是先于 5 秒 spawn kill 触发(kill 层级:4 秒 < 5 秒 < harness 默认 8 秒),避免高负载 CI 下正常收尾的默认运行被 spawn 超时拆掉进程、`status` 变 `null` 令断言读起来误导;§3.5 与 A4 同步
|
|
7
|
+
|
|
8
|
+
基线:`origin/main @ 608a22a`。调研:`research/01-reproduction-and-inventory.md`、
|
|
9
|
+
`research/02-predicate-boundary-and-scope.md`。本 issue 走 bug 路由,第 1 节即根因报告。
|
|
10
|
+
|
|
11
|
+
## 1. 现象与根因
|
|
12
|
+
|
|
13
|
+
六个 `test-support` 夹具把结果 JSON 打到 stdout 后,下一行立即 `process.exit`:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
console.log(JSON.stringify(result));
|
|
17
|
+
process.exit(result.settledMs !== null && result.showsContent ? 0 : 1);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`console.log` 与 `process.stdout.write` 是同一个 `process.stdout`:参数被拼成一个字符串、
|
|
21
|
+
追加 `\n`、再调用一次 `stream.write`。stdout 接管道时写入是异步的,超过内核管道缓冲
|
|
22
|
+
(Linux 64 KiB)的部分留在用户态队列,`process.exit` 在队列排空前拆掉进程,读端只能拿到
|
|
23
|
+
前 64 KiB,而退出码仍是 0。父进程随后 `JSON.parse` 抛 `Unterminated string`。
|
|
24
|
+
|
|
25
|
+
确定性复现与三组对照(research/01 §1):200 KB 的 `console.log` + `exit` 在慢读端下输出
|
|
26
|
+
65536 字节;1 KB 输出 1025 字节(完整);`exitAfterStdout` 输出 200001 字节(完整)。
|
|
27
|
+
|
|
28
|
+
当前六个 payload 都远小于 64 KiB,所以是**潜伏缺陷**而非现行故障;payload 长大或 runner
|
|
29
|
+
变慢即复现,与 #270 的 s15 battery 完全同构。
|
|
30
|
+
|
|
31
|
+
#270 的修复(`test-support/stdout-flush.mjs` 的 `exitAfterStdout`)已在 22 个文件落地,
|
|
32
|
+
本 issue 处理同形态的最后六个漏网点,并把守卫的检测谓词从「只认 `process.stdout.write`」
|
|
33
|
+
放宽到「也认 `console.log` / `console.info`」——#270 的 spec §3.4 与守卫自测至今把这六处
|
|
34
|
+
当作合法样本,是门禁缺口的一半。
|
|
35
|
+
|
|
36
|
+
## 2. 设计决策表
|
|
37
|
+
|
|
38
|
+
| # | 决策 | 依据 / 取舍 |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| D1 | 六处统一改为 `exitAfterStdout(<同 text>, <同 code>)`,text 为 `JSON.stringify(result) + "\n"` | `console.log` 自带换行,转换必须补 `\n`;写什么、退出码表达式逐字不变 |
|
|
41
|
+
| D2 | 守卫谓词扩展为 `process.stdout.write(...)` **或** `console.log/info(...)` 的表达式语句 | 两者写同一个 `process.stdout`,语义等价而非近似(research/02 §1) |
|
|
42
|
+
| D3 | 守卫的配对规则(相邻语句、`if`/block 递归、兄弟 `if` 跳过)一字不改 | 放宽的只是「什么算写 stdout」,不是「什么算排空后退出」;新增分支会引入新的误报面 |
|
|
43
|
+
| D4 | 守卫自测把 `console.log` 紧邻 `exit` 从 `accepted` 移到 `violations`,并补 `console.info`(违例)与 `console.error`(合法)两条样本 | 自测是谓词的唯一规格;不同步迁移会让放宽后的守卫「永远通过」,等于没写 |
|
|
44
|
+
| D5 | 不修改 `test-support/stdout-flush.mjs` 的运行时代码;只同步它第 10-15 行的守卫范围注释 | 注释现写「只有 `process.stdout.write` 被守卫」,D2 之后必然过时;运行语义不变由 A6 的 256 KiB probe 继续证明 |
|
|
45
|
+
| D6 | 纳入 `FORMAL_BASELINE_REPO` 空串/纯空白防御,做成 `resolveBaselineRepo(envValue, repo)`:不直接读 `process.env`/`process.cwd`,非空相对值沿用 `path.resolve` 的 cwd 语义 | 承接 #270 收尾评论,并覆盖 PR #274 round-1 review 原话「empty (or whitespace-only)」;`resolve("")` 静默指向 cwd 会把候选仓自身当 baseline 算哈希 |
|
|
46
|
+
| D7 | `console.debug`、stderr 的 `console.error`、别名写法(`const log = console.log`)不覆盖 | issue 指定范围只有 `log`/`info`;stderr 是 #270 D8 的同类取舍;别名与 `const out = process.stdout` 同族,属守卫固有盲区 |
|
|
47
|
+
| D8 | 不为 `attach-idle-candidate-open-harness.mjs` 新增语义消费方;只在守卫测试里加一条成功/超时两路的退出码 smoke | 它是手工 A/B 夹具,孤儿归属 #211;但「无消费方」不能成为「退出码语义不验收」的理由(R1-G1) |
|
|
48
|
+
| D9 | 测试落点复用现有 `test/scenario-stdout-flush.test.mjs` 与 `test/formal-runner-plan.test.mjs`,不新建测试文件 | 守卫与纯函数同族,新建文件只会多一份 import 与 CI 时间 |
|
|
49
|
+
|
|
50
|
+
## 3. 代码落点
|
|
51
|
+
|
|
52
|
+
### 3.1 六个调用点
|
|
53
|
+
|
|
54
|
+
每个文件在现有相对导入区加入 `import { exitAfterStdout } from "./stdout-flush.mjs";`
|
|
55
|
+
(`.mjs` 夹具用同一行;`moduleResolution: NodeNext` 下已有多处先例,如
|
|
56
|
+
`pty-attach-external-editor-scenario.ts:7`)。
|
|
57
|
+
|
|
58
|
+
| 文件 | 现状 | 替换后 |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| `pty-attach-frame-overflow-scenario.ts:378-379` | `console.log(...); process.exit(0);` | `exitAfterStdout(JSON.stringify(result) + "\n", 0);` |
|
|
61
|
+
| `pty-attach-mouse-mode-scenario.ts:94-95` | 同上 | 同上 |
|
|
62
|
+
| `pty-attach-wheel-scenario.ts:187-188` | 同上 | 同上 |
|
|
63
|
+
| `pty-attach-selection-mirror-scenario.ts:260-261` | 同上 | 同上 |
|
|
64
|
+
| `attach-idle-socket-driver.ts:221-222` | 退出码含判定表达式 | `exitAfterStdout(JSON.stringify(result) + "\n", result.settledMs !== null && result.showsContent ? 0 : 1);` |
|
|
65
|
+
| `attach-idle-candidate-open-harness.mjs:75-76` | 同上 | 同上 |
|
|
66
|
+
|
|
67
|
+
语义保持:写的内容(`JSON.stringify(result)` 加一个换行)、退出码表达式、进程退出时机
|
|
68
|
+
(排空后)都与原实现一致,唯一变化是 `exit` 等写回调。
|
|
69
|
+
|
|
70
|
+
两个带条件退出码的夹具(`attach-idle-socket-driver.ts`、`attach-idle-candidate-open-harness.mjs`)
|
|
71
|
+
额外补退出码验收,因为它们正是「换成常量 0 也能全绿」的盲区(R1-G1):前者在
|
|
72
|
+
`test/attach-frame-witness.integration.test.mjs` 的成功用例(`spawnSync` 的 `status`)与
|
|
73
|
+
hard-invalid 用例(`driver.exitCode`)各加一条断言;后者在守卫测试里加成功/超时两路 smoke。
|
|
74
|
+
|
|
75
|
+
### 3.2 守卫谓词(`test/scenario-stdout-flush.test.mjs`)
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const CONSOLE_STDOUT_METHODS = new Set(["log", "info"]);
|
|
79
|
+
const isConsoleIdentifier = (node) => ts.isIdentifier(node) && node.text === "console";
|
|
80
|
+
const writesConsole = (statement) =>
|
|
81
|
+
ts.isExpressionStatement(statement) &&
|
|
82
|
+
ts.isCallExpression(statement.expression) &&
|
|
83
|
+
ts.isPropertyAccessExpression(statement.expression.expression) &&
|
|
84
|
+
CONSOLE_STDOUT_METHODS.has(statement.expression.expression.name.text) &&
|
|
85
|
+
isConsoleIdentifier(statement.expression.expression.expression);
|
|
86
|
+
const writesStdout = (statement) =>
|
|
87
|
+
isCallStatement(statement, "write", isStdoutReceiver) || writesConsole(statement);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`containsStatement`、相邻配对、兄弟 `if` 跳过的实现不动。函数文档注释改为:谓词覆盖
|
|
91
|
+
`process.stdout.write` 与 `console.log`/`console.info`(同一 stdout 通道);`console.error`
|
|
92
|
+
(stderr)与别名写法仍不覆盖,并列出 §6 的其余盲区。
|
|
93
|
+
|
|
94
|
+
### 3.3 守卫自测
|
|
95
|
+
|
|
96
|
+
- `violations` 新增:`["console.log then exit", \`console.log("x");\nprocess.exit(0);\`]`(从
|
|
97
|
+
`accepted` 移入)、`["console.info then exit", \`console.info("x");\nprocess.exit(0);\`]`。
|
|
98
|
+
- `accepted` 保留 `["console.error then exit", \`console.error("x");\nprocess.exit(0);\`]`
|
|
99
|
+
作为 stderr 边界的钉死样本。
|
|
100
|
+
- 现有的 `if (ready) console.log(x)` 形态由 `containsStatement` 递归自然覆盖,补一条违例
|
|
101
|
+
样本 `["conditional console.log then exit", ...]` 以证明它与 `process.stdout.write`
|
|
102
|
+
同口径。
|
|
103
|
+
|
|
104
|
+
### 3.4 `FORMAL_BASELINE_REPO` 空串/纯空白防御
|
|
105
|
+
|
|
106
|
+
`test-support/formal-measurement/formal-plan.mjs` 新增导出(不直接读 `process.env` / `process.cwd`):
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
// An empty or whitespace-only FORMAL_BASELINE_REPO is an unset variable, not
|
|
110
|
+
// the process cwd: resolve("") would silently re-root baseline hashing at the
|
|
111
|
+
// candidate repo.
|
|
112
|
+
export function resolveBaselineRepo(envValue, repo) {
|
|
113
|
+
return typeof envValue === "string" && envValue.trim() !== ""
|
|
114
|
+
? resolve(envValue)
|
|
115
|
+
: resolve(repo, "../issue-222-attach-baseline");
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`formal-plan.mjs` 需从 `node:path` 补 `resolve` 导入。`formal-runner.mjs:20-22` 替换为:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
const baselineRepo = resolveBaselineRepo(process.env.FORMAL_BASELINE_REPO, repo);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`repo` 已是绝对路径(`resolve(dirname(...), "../..")`),默认分支结果与现状逐字相同。
|
|
126
|
+
函数本身不直接读取 `process.env` 或 `process.cwd`;非空值与现状一致:相对路径仍由
|
|
127
|
+
`path.resolve` 相对进程 cwd 解析(A7 用一条相对值样本钉住该语义)。
|
|
128
|
+
|
|
129
|
+
### 3.5 孤儿 harness 的两路 smoke(A4)
|
|
130
|
+
|
|
131
|
+
在 `test/scenario-stdout-flush.test.mjs` 末尾新增一条用例,以
|
|
132
|
+
`spawnSync(process.execPath, ["--experimental-transform-types", HARNESS], { env, encoding: "utf8", timeout: 5000 })`
|
|
133
|
+
启动夹具(`HARNESS` 用 `fileURLToPath(new URL("../test-support/attach-idle-candidate-open-harness.mjs", import.meta.url))`);
|
|
134
|
+
两路显式 env:① `{ ...process.env, HARNESS_TIMEOUT_MS: "4000" }`(settled 运行钉住 4 秒预算,不用
|
|
135
|
+
harness 默认 8 秒)→ 断言 `status === 0`、stdout 末行可 `JSON.parse`、
|
|
136
|
+
`settledMs !== null`、原始 stdout 以 `"\n"` 结尾;② `{ ...process.env, HARNESS_TIMEOUT_MS: "0" }` →
|
|
137
|
+
断言 `status === 1`、stdout 末行可 `JSON.parse`、`settledMs === null`、原始 stdout 以 `"\n"` 结尾。
|
|
138
|
+
kill 层级:harness 预算 4 秒 < spawn 杀 5 秒 < harness 默认 8 秒,harness 总是在 spawn 超时
|
|
139
|
+
拆掉进程(`status` 变 `null`、断言读起来误导)之前自己排空退出。
|
|
140
|
+
|
|
141
|
+
## 4. 验收矩阵
|
|
142
|
+
|
|
143
|
+
| ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
|
|
144
|
+
|----|--------|----------|----------|----------|
|
|
145
|
+
| A1 | 守卫谓词能识别 `console.log`/`console.info` 紧邻 `exit`,且不误报 `console.error` | 自动化验证(unit) | `node --test test/scenario-stdout-flush.test.mjs` | 四条新样本(log / info / 条件式 log / error)判定与预期逐条一致 |
|
|
146
|
+
| A2 | `test-support/**` 不再有六种形态的违例 | 自动化验证(static) | 同上:全目录扫描用例 | `offenders` 为空;扫描前先临时还原一处可复现红 |
|
|
147
|
+
| A3 | `attach-idle-socket-driver.ts` 的成功/失败退出码与 JSON 输出 | 自动化验证(integration) | `node --test test/attach-frame-witness.integration.test.mjs` | 既有成功用例新增 `driver.status === 0` 断言;hard-invalid 用例新增 `driver.exitCode === 1` 断言;两条路径的 stdout 末行都能 `JSON.parse`,且原始 stdout 以 `"\n"` 结尾 |
|
|
148
|
+
| A4 | 孤儿 `attach-idle-candidate-open-harness.mjs` 的退出码与 JSON 输出 | 自动化验证(integration) | `node --test test/scenario-stdout-flush.test.mjs`(含两路 smoke,以 `--experimental-transform-types` 启动,5 秒 spawn 超时) | settled 运行(显式 `HARNESS_TIMEOUT_MS: "4000"`)在 5 秒内退出 0,stdout 为合法 JSON、`settledMs !== null`、原始 stdout 以 `"\n"` 结尾;`HARNESS_TIMEOUT_MS=0` 时退出 1,stdout 为合法 JSON、`settledMs === null`、原始 stdout 以 `"\n"` 结尾;kill 层级:harness 预算 4 秒 < spawn 杀 5 秒 < harness 默认 8 秒 |
|
|
149
|
+
| A5 | 另外四个场景夹具的输出仍可被消费方解析 | 自动化验证(integration) | `node --test test/pty-attach-frame-overflow.test.mjs test/pty-attach-mouse-mode.test.mjs test/pty-attach-wheel.test.mjs test/pty-attach-selection-mirror.test.mjs` | 全部通过,无 `Unterminated string`;每个消费方新增一条断言:原始 stdout 以 `"\n"` 结尾(与 A3/A4 一起覆盖六个调用点) |
|
|
150
|
+
| A6 | 排空助手在大 payload + 慢读端下不截断(回归保护) | 自动化验证(integration) | `node --test test/scenario-stdout-flush.test.mjs` 的 256 KiB probe 用例 | 通过,payload 长度 262144 |
|
|
151
|
+
| A7 | `FORMAL_BASELINE_REPO` 为空串/纯空白时回落默认路径,相对值沿用 cwd 语义 | 自动化验证(unit) | `node --test test/formal-runner-plan.test.mjs` | `undefined`、`""`、`" "` 都返回 `<repo>/../issue-222-attach-baseline`;绝对非空值返回其 `resolve` 结果(两侧空白保留);相对值 `"sibling"` 返回 `resolve("sibling")`(与现状一致) |
|
|
152
|
+
| A8 | 全仓门禁 | 自动化验证(build) | `npm run verify` | typecheck + perf gate + tests + coverage + `pack:dry` 全绿 |
|
|
153
|
+
| A9 | 两个必需 CI job | 自动化验证(automated E2E) | 承载本修复的 PR 上的 GitHub Actions | `Test (Node 22)` 与 `Test (Node 24)` 均 success |
|
|
154
|
+
|
|
155
|
+
**无用户实测项(无 U 项)**:本 issue 只改测试夹具的退出时序与静态守卫,产品行为零变化,
|
|
156
|
+
用户侧没有可观测差异;A7 用 PR 上的真实 CI 运行代替人工验证。这是分类结论,不是兜底。
|
|
157
|
+
|
|
158
|
+
## 5. 可测性拆分设计(实现阶段硬约束)
|
|
159
|
+
|
|
160
|
+
| 关注点 | 拆分后单元 | 测试边界 |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| 「什么算写 stdout」判定 | `writesConsole(statement)` / `writesStdout(statement)` 谓词 | 合成源码样本单测(A1),不读磁盘、不 spawn |
|
|
163
|
+
| 形态门禁 | `findUnguardedStdoutExits(text, fileName)`(纯函数) | 样本单测(A1)+ 目录扫描(A2),输入是源码文本 |
|
|
164
|
+
| env → baseline 路径 | `resolveBaselineRepo(envValue, repo)`(不直接读 `process.env`/`process.cwd`;非空相对值经 `path.resolve` 使用 cwd) | 四输入单测(A7),不 spawn、不依赖兄弟 checkout |
|
|
165
|
+
| 六个真实调用点 | 不改结构,只换退出写法 | 四个场景由现有消费方覆盖(A5);driver 由 witness 的成功/失败用例加断言(A3);孤儿夹具由两路 smoke 覆盖(A4) |
|
|
166
|
+
| 排空语义 | `writeThenExit(stream, text, code, exit)`(既有) | 现有三分支单测 + 256 KiB probe(A6),本 issue 不改 |
|
|
167
|
+
|
|
168
|
+
实现不得把这些判定重新耦合:不得让 `resolveBaselineRepo` 直接读 `process.env` 或 `process.cwd`
|
|
169
|
+
(相对值的 cwd 语义只由 `path.resolve` 承担,与现状一致),不得把 `console.*` 识别写成对
|
|
170
|
+
全文件文本的正则扫描(AST 谓词是唯一入口)。
|
|
171
|
+
|
|
172
|
+
## 6. 边界与非目标
|
|
173
|
+
|
|
174
|
+
- **不覆盖 stderr**:`console.error` + `exit` 存在于 `ui-smoke.ts`、`attach-frame-failure-child.mjs`,
|
|
175
|
+
量级是几百字节报错信息,#270 D8 的同类取舍。
|
|
176
|
+
- **不覆盖 `console.debug`**:Node 里同样写 stdout,但 issue 指定范围只有 `log`/`info`,
|
|
177
|
+
且当前零处;在守卫注释中明示,避免被误当成「已验证」。若 CR 要求,可无成本纳入。
|
|
178
|
+
- **别名盲区**:`const log = console.log; log(x); process.exit(0)` 与
|
|
179
|
+
`const out = process.stdout; out.write(x); process.exit(0)` 同属守卫看不见的形态。
|
|
180
|
+
- **非相邻语句 / try-finally / `.then` 写 + `.catch` 退**:现有配对规则不覆盖,保持原状。
|
|
181
|
+
- **不清理孤儿夹具**:`attach-idle-candidate-open-harness.mjs` 仍无语义消费方(归属 #211),本 issue 只给它加一条退出码 smoke。
|
|
182
|
+
- **不改产品代码**:`src/**`、`runner/**` 零改动(`formal-plan.mjs` 属测试支撑)。
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Spec: #258 — board (dashboard) keeps the fullscreen selection highlight after copy-on-release
|
|
2
|
+
|
|
3
|
+
Status: DRAFT (awaiting spec-cross-review; gate=auto per authorization.md — after convergence, proceed straight to step 5 without pausing)
|
|
4
|
+
Issue: https://github.com/zhuxixi/pi-agent-board/issues/258
|
|
5
|
+
Repo baseline: `origin/main` @ `5d0c982` (local main `608a22a`; `608a22a..5d0c982` touches only dashboard-fold test files and docs — all src/ citations below were verified on `608a22a` and are unaffected). pi-tui / pi-coding-agent 1.5.1 installed runtime verified.
|
|
6
|
+
|
|
7
|
+
Drafted: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-10T08:52:00+08:00
|
|
8
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-10T09:02:00+08:00 — R1-G1 (shouldSettle lifecycle gate), R1-G2 (U1/U2 deployment preconditions), R1-G3 (A4 non-empty precondition + no-silent-downgrade), R1-D1 (production overlay:true), R1-D2 (A4 wrapper attribution), R1-D3 (D6 acceptance owner)
|
|
9
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-10T09:38:00+08:00 — R2-D1 (board `disposed` gate + A3 unmount-race case), R2-D2 (A4 explicit command + launch flags)
|
|
10
|
+
|
|
11
|
+
## Problem (root cause, verified against source)
|
|
12
|
+
|
|
13
|
+
In fullscreen (pi ≥1.0), drag-selecting text inside the board copies on release (pi-tui copy-on-select) but the inverse-video highlight stays lit until the next mouse press.
|
|
14
|
+
|
|
15
|
+
`TuiAltScreen` owns the gesture: each decoded mouse event is dispatched to overlays/layout components first (`component.handleMouse?.(event)`), and only when nothing consumed it does pi run its own selection logic — the release path does `copySelectionToClipboard()` + `requestRender()` and does **not** reset selection state. `DashboardComponent` (`src/ui/dashboard.ts:137`) implements `handleInput` only; there is no `handleMouse` anywhere in the file, so no code ever observes the gesture ending and nothing settles it. The attach view fixed the same symptom in #172 (PR #251, `3d72b68`) by observing in its own `handleMouse`; the board has no equivalent observation point yet.
|
|
16
|
+
|
|
17
|
+
Production mount: `ctx.ui.custom<DashboardResult>(..., { overlay: true, overlayOptions: { anchor: "top-left", width: "100%", maxHeight: "100%", margin: 0 } })` (`src/commands/agent-board.ts:94-131`) — with `overlay: true`, pi's interactive mode mounts the board via `showOverlay`, so mouse events reach `DashboardComponent.handleMouse` through `TuiAltScreen`'s overlay hit-test dispatch — the same dispatch path the #172 attach fix rides. (Corrected per review R1-D1; the editor-container mounting described in JFox KB applies to `ctx.ui.custom` **without** `overlay: true`, not to this component.)
|
|
18
|
+
|
|
19
|
+
## Goal / non-goals
|
|
20
|
+
|
|
21
|
+
**Goal**: in fullscreen, once pi's copy-on-select has completed for a selection gesture that ends inside the board, drop pi's selection so the highlight disappears immediately — without changing what reaches the clipboard, without consuming any mouse event, and without breaking pi's multi-click chain (double-click word / triple-click line).
|
|
22
|
+
|
|
23
|
+
**Shared-core requirement** (from the issue's fix direction): extract the settle logic so the attach and board paths cannot drift. The attach path is refactored onto the same core with behavior preserved (its existing tests stay green, unmodified).
|
|
24
|
+
|
|
25
|
+
**Non-goals**:
|
|
26
|
+
|
|
27
|
+
- X11 PRIMARY mirroring for the board (the mirror hook stays attach-only behind `AGENT_BOARD_ATTACH_NATIVE_PASTE`; the board has no middle-click paste consumer — can be added later without touching the shared core).
|
|
28
|
+
- #250 — the legacy/regular-mode attach `shouldCopy` gap; a different code path, untouched.
|
|
29
|
+
- Selections that end outside the board's overlay box (pi transcript, other pi UI): outside the component's event window — same limitation class as #172/#174; would need an upstream event.
|
|
30
|
+
- The board's row-cursor highlight (`theme.bg("selectedBg")`): unrelated, by design stays visible.
|
|
31
|
+
- Any upstream change to pi/pi-tui; private-method access stays feature-detected with graceful degradation.
|
|
32
|
+
|
|
33
|
+
## Decisions
|
|
34
|
+
|
|
35
|
+
**D1 — shared settle core in `src/core/fullscreen-selection.mjs`.**
|
|
36
|
+
New core module exporting a `FullscreenSelectionSettler` with injected seams (repo convention: pure/testable core, thin I/O shell):
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
constructor({
|
|
40
|
+
host: FullscreenSelectionHost, // { getActiveSelectionText?, getCopyOnSelect?, clearTextSelection? } — feature-detected
|
|
41
|
+
mirror?: (text: string) => void, // attach passes its xclip write (already self-gated on its env knob); board omits
|
|
42
|
+
repaint?: () => void, // attach: scheduleRender(); board: tui.requestRender()
|
|
43
|
+
schedule?: (cb: () => void) => void, // defaults to process.nextTick; injectable for unit tests
|
|
44
|
+
shouldSettle?: () => boolean, // runtime lifecycle gate — checked inside the deferred callback BEFORE any host read/mirror/clear (R1-G1); attach passes () => !this.closed, board omits
|
|
45
|
+
})
|
|
46
|
+
observeMouse(event): void
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`observeMouse` semantics (exactly the semantics attach ships today):
|
|
50
|
+
1. `press` + `left` → bump the internal gesture serial.
|
|
51
|
+
2. `isFullscreenSelectionEnd(event)` (existing pure predicate, `src/core/pty-scroll.mjs:279` — release/click of left) → capture serial, `schedule(() => { if (serial unchanged) settle(); })`.
|
|
52
|
+
3. `settle()` order: `shouldSettle && !shouldSettle()` → return (runtime lifecycle gate, R1-G1; attach keeps its existing `!this.closed` semantics) → read `host.getActiveSelectionText?.()` → empty/absent: return → `mirror?.(text)` → `host.getCopyOnSelect?.() === false`: return (user keeps the selection for Ctrl+X) → `typeof host.clearTextSelection !== "function"`: return (older/newer runtime degrades) → `clearTextSelection()` → `repaint?.()`.
|
|
53
|
+
|
|
54
|
+
Read-before-clear is load-bearing (the #172 harness fixture invalidates text on clear to pin the order). `pty-attach.ts` refactors: delete its inline serial/defer/settle code — including the `if (this.closed) return;` first line of `settleFullscreenSelection` (`src/ui/pty-attach.ts:2433`), which moves into the `shouldSettle` option — and instantiate one settler with its existing host cast, mirror, `scheduleRender`, and `() => !this.closed`. No behavior change (R1-G1). Its `FullscreenSelectionHost` interface moves to (or is re-exported from) the core module so both components share one definition.
|
|
55
|
+
|
|
56
|
+
**D2 — gesture serial lives inside the settler.**
|
|
57
|
+
pi-tui decodes a stdin batch and dispatches events synchronously, so a release and the next press can share one tick; a settle queued on the release must not consume the next gesture's selection (this exact bug was caught in #172's local review). Bumping on left press and comparing the captured serial at run time is preserved as-is — now in one place instead of two.
|
|
58
|
+
|
|
59
|
+
**D3 — clear via `clearTextSelection()`, never `resetTextSelection()`.**
|
|
60
|
+
`resetTextSelection()` also clears `lastClick`, which `getClickCount` needs within `DOUBLE_CLICK_INTERVAL_MS = 500` — clearing it per release would break double-click word / triple-click line selection. `clearTextSelection()` drops only the visual selection state. It is `private` in pi-tui typings but a plain prototype method at runtime (verified present in the installed 1.5.1 `tui-alt-screen.js`); access stays feature-detected.
|
|
61
|
+
|
|
62
|
+
**D4 — no PRIMARY mirror for the board.**
|
|
63
|
+
The board's scope is the stale highlight only. The settler's `mirror` hook keeps attach's #174 behavior intact; the board simply does not pass one.
|
|
64
|
+
|
|
65
|
+
**D5 — dashboard wiring.**
|
|
66
|
+
- `handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined` on `DashboardComponent`: calls `this.selectionSettler.observeMouse(event)`, then **always returns `undefined`** (observe only — pi keeps every gesture, its copy and its link handling). No mode gating: the settle is about pi-level selection state and applies in every board mode.
|
|
67
|
+
- The settler is constructed in the constructor body (after the `tui` parameter property is assigned), with `repaint: () => this.tui.requestRender()` and `shouldSettle: () => !this.disposed` — non-forced repaint; content is unchanged, only pi's selection overlay goes away. (`requestRender` is already the board's seam; `dashboard.ts:1287` uses the forced variant only for full-clear cases.)
|
|
68
|
+
- The board gates on its own lifecycle too (R2-D1): a private `disposed` flag set at the top of `dispose()` (`src/ui/dashboard.ts:1266`), checked via `shouldSettle`. `done()` synchronously hides and disposes the overlay, but a settle queued before that still holds the global `TuiAltScreen` host and — if the host already carries a newer non-empty selection — the stale callback would read and clear it; the gesture serial cannot guard this (it only grows on presses the dead board still observes).
|
|
69
|
+
|
|
70
|
+
**D6 — the board's embedded `CustomEditor` rows are covered by the same observer.**
|
|
71
|
+
Mouse dispatch is hit-test-based within the board's box regardless of which sub-element sits under the cursor; if pi's editor consumes an event, the gesture never starts and there is nothing to settle. No special-casing.
|
|
72
|
+
|
|
73
|
+
## Testability split design (design constraint for the plan)
|
|
74
|
+
|
|
75
|
+
| Unit | Shape | How tested | Test boundary |
|
|
76
|
+
| --- | --- | --- | --- |
|
|
77
|
+
| `FullscreenSelectionSettler` (new, `src/core/fullscreen-selection.mjs`) | all I/O injected (host object, mirror/repaint/schedule callbacks, `shouldSettle` gate); no timers, no filesystem, no spawn | unit — fake host + manual `schedule` queue flushed by the test; no wall-clock waits | everything up to and including the `clearTextSelection()` call and the repaint trigger; gesture-serial semantics; the `shouldSettle` lifecycle gate |
|
|
78
|
+
| `DashboardComponent.handleMouse` wiring | thin shell: forward to settler, return `undefined` | component harness — child process, fake fullscreen TUI (the #172 `pty-attach-selection-mirror-scenario.ts` pattern), real `DashboardComponent` from `../src/ui/dashboard.ts`, drives `handleMouse` directly | board-side wiring only: the right events reach the settler, the return value never consumes |
|
|
79
|
+
| Real dispatch chain (TuiAltScreen → overlay → `handleMouse` → pi finalize → deferred settle) | real renderers | real-renderer harness — the `dashboard-tui-modes.ts` pattern: real `TuiAltScreen` + headless xterm + captured input callback, inject SGR mouse sequences | end-to-end within the process: synthetic SGR in, selection state cleared out |
|
|
80
|
+
| Attach behavior preservation | refactor only | existing `pty-attach-selection-mirror` tests, unmodified | regression fence for the extraction |
|
|
81
|
+
|
|
82
|
+
## Acceptance matrix
|
|
83
|
+
|
|
84
|
+
| ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
|
|
85
|
+
|----|--------|----------|----------|----------|
|
|
86
|
+
| A1 | settler 核心语义 | 自动化验证(unit) | `node --test test/fullscreen-selection.test.mjs` | 全绿:空文本不清也不镜像;`copyOnSelect=false` 不清(mirror 照跑);`clearTextSelection` 缺席不抛、不清;正常路径 clear+repaint 各一次;read-before-clear 顺序(clear 后文本失效的 fixture);同 tick release→新 press 时收尾被手势序号丢弃;`click` 事件同样触发 settle;`shouldSettle` 返回 false 时 host 读取/mirror/clear/repaint 均为零 |
|
|
87
|
+
| A2 | attach 重构行为保持(含关闭门禁)| 自动化验证(unit/component) | `node --test test/pty-attach-selection-mirror.test.mjs`(既有断言零改动;**追加**用例:release 入队 → 组件 close → flush tick → mirror 写入与 clear 调用均为 0) | 原断言全绿 + 新增关闭门禁用例全绿 |
|
|
88
|
+
| A3 | board 组件接线 | 自动化验证(integration,子进程组件 harness) | `node --test test/dashboard-selection-settle.test.mjs` | 全绿:release→flush tick→`clearTextSelection` 被调、`requestRender` 被调;press/release 同 tick 抑制;wheel/右键不触发;返回值恒 `undefined`;带嵌入 CustomEditor 的模式(filter/launch)下同一手势同样 settle 且返回恒 `undefined`(D6 归属,R1-D3);release 入队 → `dispose()` → host 换上新选区 → flush 后 host 读取/mirror/clear/repaint 均为零(卸载竞态,R2-D1) |
|
|
89
|
+
| A4 | 真派发链路(overlay 路径,与生产一致)| 自动化验证(integration,real renderer + headless xterm) | `node --test test/dashboard-tui-modes.test.mjs`(**新增 wrapper**,内部沿用 `test/dashboard-fold.test.mjs:27` 的启动方式:`node --experimental-transform-types test-support/dashboard-tui-modes.ts`,R2-D2;原 fold wrapper 不改动,R1-D2) | 渲染已知文本 → SGR press/drag → **先断言非空选区存在**(`getActiveSelectionText()` 非空或反色单元,R1-G3)→ release → flush nextTick → 同一选区被清且 repaint 发生;降级规则:合成 SGR 驱动不了 headless 选区时,fallback 必须仍经真实 `TuiAltScreen` 派发缝断言 finalize→deferred settle→clear 顺序与终态,否则 A4 记**未满足**(不得降级通过,U1 门保留) |
|
|
90
|
+
| A5 | 全量回归门 | 自动化验证(build) | `npm run verify` | exit 0(typecheck、perf、tests、coverage、pack:dry) |
|
|
91
|
+
| U1 | board 拖选复制后高亮即清 | 用户实测 | 按「部署前置」更新真实加载 checkout 并重启 pi 后:fullscreen 打开 board,拖选会话名/日志行后松开 | 内容已复制(CLIPBOARD 粘贴验证:Ctrl/Cmd+V;不依赖 board 未实现的 PRIMARY 中键粘贴),反色高亮立即消失,无需下一次点击 |
|
|
92
|
+
| U2 | 双击/三击不受影响 | 用户实测 | 在 U1 的同一已更新实例上:500ms 内双击单词、三击某行 | 选词/选行照常发生并复制,高亮随后清除 |
|
|
93
|
+
|
|
94
|
+
**U1/U2 部署前置(可执行时机,R1-G2)**:pi 通过 `git:github.com/zhuxixi/pi-agent-board` 从独立 checkout `~/.pi/agent/git/github.com/zhuxixi/pi-agent-board` 加载本扩展(`~/.pi/agent/settings.json` extensions 块),当前工作副本不是加载路径。PR 合并后:`git -C ~/.pi/agent/git/github.com/zhuxixi/pi-agent-board restore package-lock.json`(或 stash——该 checkout 2026-11-10 存在 package-lock.json 本地脏改动,在案)→ `git -C … pull --ff-only` → 完全退出并以 fullscreen 模式重启 pi → `/agent-board`。
|
|
95
|
+
|
|
96
|
+
若某项无法自动化:A1–A5 均有既有同类先例(#172 的 mirror 场景、dashboard-tui-modes 的真渲染 harness),无预期障碍;A4 的降级边界已写入矩阵(fallback 仍须走真实派发缝断言时序与终态;只证明"handleMouse 被派发到"不够,A4 记未满足、U1 门保留),不允许静默降级为只跑 A3。
|
|
97
|
+
|
|
98
|
+
## Boundaries / risks
|
|
99
|
+
|
|
100
|
+
- Observation covers the overlay's hit-test box (≈ the screen). Selections released outside it keep pi's behaviour — no seam exists.
|
|
101
|
+
- Production and the A4 harness mount the board identically as a fullscreen overlay (`overlay: true`, `src/commands/agent-board.ts:127-131`; harness `test-support/dashboard-tui-modes.ts:61-63`) — A4 exercises the production dispatch path directly (R1-D1 correction; no separate "layout path" exists for this component).
|
|
102
|
+
- A settle queued before unmount is stopped by the `disposed` gate (R2-D1); without it the stale callback would still hold the global `TuiAltScreen` host and could clear a newer UI's selection.
|
|
103
|
+
- No wall-clock-sensitive waits are introduced (one nextTick deferral, same as attach) — nothing new for the #95 realtime-budget ledger.
|
|
104
|
+
|
|
105
|
+
## Supersedence / relations
|
|
106
|
+
|
|
107
|
+
- Mirrors #172 (attach, merged `3d72b68`) onto the board; shares its core going forward.
|
|
108
|
+
- #250 (legacy/regular attach) remains separate.
|
|
109
|
+
- #174's deferred-selection hook contract is preserved unchanged on the attach path.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Spec: #294 — snapshot-carried target F must satisfy the resize intent
|
|
2
|
+
|
|
3
|
+
Status: DRAFT (rev 4, post round-3 cross-review; no authorization.md → gate=stepwise: after convergence, PAUSE for user design confirmation before step 5)
|
|
4
|
+
Issue: https://github.com/zhuxixi/pi-agent-board/issues/294
|
|
5
|
+
Repo baseline: local main `3815dea` at drafting; `750b854` (post-#293 merge) at round-1 review — the delta touches only dashboard selection code, not the attach paths cited here. Implementation re-pins `origin/main` before the worktree and records the SHA. Pi 1.5.1 runtime.
|
|
6
|
+
Research artifacts: `~/.github-issue-driven/zhuxixi/pi-agent-board/issue-294/research/` (repro programs + outputs + research-summary.md).
|
|
7
|
+
|
|
8
|
+
Drafted: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-12T08:57:00+08:00
|
|
9
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-12T09:20:00+08:00 — R1-G1 (ordinary-F0-in-capture shape: intent evidence + gate bypass), R1-G2 (U1 diagnostics criterion rewritten to real event shapes), R1-D1 (repro seq fix + new repro variants), R1-D2 (dropped the false subset claim), R1-D3 (A4 scope + real-Pi skip semantics)
|
|
10
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-12T09:52:00+08:00 — R2-G1 (sticky intent evidence; `invalidateViewProof` stops clearing it; real S0→F0 frame sequences in A2c/repro), R2-G2 (bypass head restricted to ordinary 0/0 + wrong-nonzero negatives), R2-D1 (live aggregation wording = actual lifecycle), R2-D2 (stale-evidence negative moved to A1b unit level), R2-D3 (harness protocolError readout + observable assertions)
|
|
11
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-12T10:18:00+08:00 — R3-G1 (live match reuses the same pure predicate: full validation incl. target dims; live wrong-dims mixed negative added to A3), R3-D1 (harness coverageHead readout summary + protocolError via handleAttachEvent wrapper; A2c head assertions)
|
|
12
|
+
|
|
13
|
+
## Problem (root cause, verified against source)
|
|
14
|
+
|
|
15
|
+
A differing-size attach can stay on the loading surface past the 2500 ms cap even when the client already holds a complete committed view at the target geometry, `covered` proof, and a matching target-geometry F **inside `snapshotReady.viewProofRecords`**. Root cause chain, verified on `3815dea` (line numbers from that SHA):
|
|
16
|
+
|
|
17
|
+
1. A differing resize arms the intent: `noteGeometryIntent` (`src/ui/pty-attach.ts:2523-2553`) sets `resizeIntentRequired = true`, `resizeIntentId = geometryRevision`, `resizeIntentSatisfied = false`.
|
|
18
|
+
2. While the attach client is `collecting`, `view_proof` records are buffered into `partial.viewProofRecords` instead of emitted live (`src/core/terminal-attach-client.mjs:708-713`); the runner interleaves queued S/F/A records into the snapshot stream around catch-up chunks (`src/core/terminal-attach-protocol.mjs:163-208`, `flushCaptureViewProofRecords`) — so a target F **does** reach the client inside the snapshot.
|
|
19
|
+
3. `snapshotReady` stores those records but unconditionally resets `this.resizeIntentSatisfied = false` (`src/ui/pty-attach.ts:2918`) — it never derives satisfaction from the validated snapshot-carried records.
|
|
20
|
+
4. Only the later live-record path updates the flag (`src/ui/pty-attach.ts:2987-2990`) — and `invalidateViewProof` (`:1520-1525`) clears it again on every transient coverage invalidation: a live **S** record (the mandatory start of every real ordinary frame, `noteViewProofRecord(S)` → `invalidateViewProof("candidate-open")`, `:1553`), aborts, trailing-unsafe output, replay gaps. So even a live-delivered target F's satisfaction does not survive the next frame's S marker (R2-G1).
|
|
21
|
+
5. The reporter consumes the intent after writing its first matching F and later frames fall back to `intentId=0` (`src/core/attach-frame-reporter.mjs` `#emitF`, `consumeIntentOnce()` → `setIntent(null)`; ordinary post-intent metadata is `intentId: decision.intentId ?? 0, geometryRevision: decision.geometryRevision ?? 0` via `metadataFor`, `src/core/attach-frame-proof.mjs:643-656`).
|
|
22
|
+
6. The runner's snapshot coverage head is the *newest* completed proof at or before the snapshot seq (`findNewestProofAtOrBefore`, `src/core/attach-view-proof.mjs:470-476`; `coverageFor` `:599-648`) — a capture window containing the target F **and** a later ordinary frame yields `covered` coverage whose head is the ordinary F0 (`intentId=0, geometryRevision=0`). The full chain then waits `geometry-revision`/`resize-intent` on the head's metadata (`requiredGeometryRevision` mismatch fires first, `src/core/pty-attach-render.mjs:252-257`), and the degraded chain refuses any armed intent. After the cap only the reason prefix changes.
|
|
23
|
+
|
|
24
|
+
Deterministic component reproductions (virtual clock, real `PtyAttachComponent` + real client messages, no production changes; all three STUCK on main, outputs in `research/`):
|
|
25
|
+
|
|
26
|
+
- `repro-bug.json` — resnapshot carrying `records=[F(intentId=1, geometryRevision=1, 100x30)]` + `covered/exact-proof` head = that F + committed 100x30 view → waits `resize-intent` → cap expires; legal `output seq=3` + live F0 afterwards does not rescue (coverage becomes `covered/safe-trailing` head F0, still locked).
|
|
27
|
+
- `repro-f0-head.json` — records `[F1, F0]` at the same seq (protocol-legal double proof per chunk; the harness's single-frame snapshot model requires `nextSeq = beginSeq + 1` and no flush, per `finishCollecting`, `terminal-attach-client.mjs:556-596`), end coverage head = F0 → same lock (the capture-window shape, step 6).
|
|
28
|
+
- `repro-live-f0-after.json` — resnapshot with F1 in records, then the **real ordinary frame sequence** `output seq=3` → live `S0` → live `F0` → coverage `covered/safe-trailing` head F0, satisfaction cleared by the S0 (step 4) → same lock.
|
|
29
|
+
|
|
30
|
+
Control (live-delivered target F, no subsequent frame before evaluation) settles at once: `readyReason=complete, settledAt=0` (`repro-control.json`).
|
|
31
|
+
|
|
32
|
+
Archaeology: the unconditional reset was introduced by `936f46e` (PR #265), before the #284 recovery-budget redesign that added the live-only derivation; PR #285 discussion and issues #284/#288 contain no decision that snapshot-carried records must not satisfy the intent — an oversight, not a safeguard.
|
|
33
|
+
|
|
34
|
+
## Fix design
|
|
35
|
+
|
|
36
|
+
Three coordinated changes: (1) derive intent satisfaction — and a separately carried **intent-proof seq** — from validated snapshot records; (2) make that evidence **sticky** (immune to transient coverage invalidations, cleared only by a superseding intent or baseline recompute); (3) let the untouched full-view gate accept an *ordinary* later coverage head when the intent evidence is fresh enough. No runner or protocol changes; the reporter is untouched; the degraded chain is untouched.
|
|
37
|
+
|
|
38
|
+
### 1. Pure predicate (new): `resizeIntentEvidenceFromRecords(intent, records)`
|
|
39
|
+
|
|
40
|
+
Location: `src/core/pty-attach-render.mjs` (the attach presentation-policy module that already hosts `decideAttachPresentation` and imports `validateFrameMetadata`). Serves **both** evidence sources: the `snapshotReady` recompute (whole records array) and the live-record branch (single-record array) — one matcher, no divergent semantics.
|
|
41
|
+
|
|
42
|
+
Returns `{ satisfied: boolean, proofSeq: number | null }`:
|
|
43
|
+
|
|
44
|
+
- `intent.required !== true` → `{ satisfied: true, proofSeq: null }` (vacuous, mirroring the live path's `!this.resizeIntentRequired || …`; no evidence needed).
|
|
45
|
+
- Otherwise scan `records` (only when it is an array) and keep the **highest-seq** element satisfying ALL of:
|
|
46
|
+
- non-null object with `marker === "F"`;
|
|
47
|
+
- `Number.isInteger(seq) && seq >= 1`;
|
|
48
|
+
- `validateFrameMetadata(metadata).ok === true` (strict 10-field whitelist, `protocol === 1`);
|
|
49
|
+
- `metadata.value.geometryRevision === intent.geometryRevision`;
|
|
50
|
+
- `metadata.value.intentId === intent.intentId` (component `intentId ≥ 1` by construction, so intent-0 records can never match);
|
|
51
|
+
- `metadata.value.cols === intent.cols && metadata.value.rows === intent.rows` (target-dimension match).
|
|
52
|
+
- Any element failing any condition is simply not evidence; empty/absent/malformed records yield `{ satisfied: false, proofSeq: null }` (fail-closed). Highest-seq choice maximizes freshness against the coverage `throughSeq` used below.
|
|
53
|
+
|
|
54
|
+
The predicate re-validates metadata even though the client already sanitized the records: pure testability without the sanitizer, defense in depth, and no reliance on the caller's slice/cap behavior. Ring-cap drops (`viewProofRecordsDropped`) need no special case: a dropped target F is simply absent.
|
|
55
|
+
|
|
56
|
+
### 2. Component state: sticky `resizeIntentSatisfied` + `resizeIntentProofSeq`
|
|
57
|
+
|
|
58
|
+
The pair represents one validated fact — "the armed intent's target frame was proven at seq k" — and its lifecycle is explicit:
|
|
59
|
+
|
|
60
|
+
| Event | `resizeIntentSatisfied` / `resizeIntentProofSeq` |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `noteGeometryIntent` (differing resize; `:2523-2553`) | cleared to `false` / `null` (a superseding intent invalidates the old fact) |
|
|
63
|
+
| `snapshotReady` (`:2918`) | **recomputed** from the accepted baseline's `records` via the predicate (supersedes any prior value — an empty/record-less baseline yields `false`/`null`, fail-closed) |
|
|
64
|
+
| live `viewProofRecord` F (`:2987-2990`) | **re-evaluated through the same pure predicate** with the single record — matching means full validation (marker F, integer seq ≥ 1, `validateFrameMetadata`, `geometryRevision`, `intentId`, **and target cols/rows**; single-source matching semantics, no revision/intent-only shortcut). Match → set `true` / that record's `seq` (upgrade); no match → untouched |
|
|
65
|
+
| live non-matching F, live S, live A | **untouched** |
|
|
66
|
+
| `invalidateViewProof` (`:1520-1525`) | **no longer touches the pair** — its `this.resizeIntentSatisfied = false` line is removed (production behavior change; S/A/trailing-unsafe/replay-gap/`generation-change`/`new-empty-baseline` invalidations are transient coverage facts, not intent facts). Safety: none of those paths can publish anyway — publishing requires `covered` coverage re-established in the current baseline, whose `snapshotReady` recompute or live match re-derives the evidence; `frameState`/`sync-open`/identity gates are untouched |
|
|
67
|
+
| capability loss / reporter-replaced | untouched (coverage goes UNKNOWN; the full chain cannot publish without `covered` coverage) |
|
|
68
|
+
|
|
69
|
+
Snapshot-carried records never pass through `noteViewProofRecord` (they are stored, not processed), so an S inside `records` is inert by construction — the S0 hazard exists only on the live path, which the table above handles.
|
|
70
|
+
|
|
71
|
+
Wiring changes in `src/ui/pty-attach.ts`: the `snapshotReady` reset line becomes the predicate call (sited exactly at the old reset, **after** the `records-without-coverage` resync guard, whose semantics are unchanged); the live-record branch calls the predicate with `[record]` and sets both fields only on a match (no reassignment on a non-match — a wrong-size live F is not evidence, exactly like a wrong-size snapshot record); `noteGeometryIntent` clears both; `invalidateViewProof` drops its reset line; the publication-facts assembly (≈ `:1680-1684`) passes `resizeIntentProofSeq` alongside `resizeIntentSatisfied`.
|
|
72
|
+
|
|
73
|
+
### 3. Full-view gate bypass: intent evidence vs an **ordinary** coverage head (R2-G2)
|
|
74
|
+
|
|
75
|
+
In `fullViewDecision` (`src/core/pty-attach-render.mjs`), the checks that compare the **coverage head's metadata** against the armed intent —
|
|
76
|
+
|
|
77
|
+
- `metadata.value.geometryRevision !== state.requiredGeometryRevision → wait("geometry-revision")`, and
|
|
78
|
+
- (under `resizeIntentRequired`) `metadata.value.intentId !== state.intentId || intentId === 0 → wait("resize-intent")`
|
|
79
|
+
|
|
80
|
+
— gain one shared alternative, evaluated only when **all** of the following hold (anything else fails closed to the existing waits):
|
|
81
|
+
|
|
82
|
+
1. `state.resizeIntentRequired === true && state.resizeIntentSatisfied === true`;
|
|
83
|
+
2. `Number.isInteger(state.resizeIntentProofSeq)`;
|
|
84
|
+
3. `state.resizeIntentProofSeq <= coverage.throughSeq` (the intent proof is inside the covered window — freshness);
|
|
85
|
+
4. the coverage head is an **ordinary** frame: structurally valid F with `metadata.value.intentId === 0 && metadata.value.geometryRevision === 0` — the exact metadata shape every post-intent ordinary frame carries (`metadataFor` defaults). A head with **wrong non-zero** revision/intent (e.g. from another intent generation) is NOT ordinary and keeps waiting under the existing checks;
|
|
86
|
+
5. the head's frame geometry matches the target: `metadata.value.cols === state.targetCols && metadata.value.rows === state.targetRows` (redundant with the chain's earlier `proof-geometry-mismatch` check, restated so the bypass is self-contained).
|
|
87
|
+
|
|
88
|
+
Semantics: the armed intent was provably completed by the validated target F (evidence ≤ head); an ordinary later frame at the same target size can only depict the same-or-fresher target-geometry view, and its 0/0 metadata is exactly the post-consumption shape. The wrong-size, stale (`proofSeq > throughSeq`), wrong-non-zero-revision/intent, missing-evidence cases all keep waiting with the existing reasons (gate order: `proof-geometry-mismatch` → `geometry-revision` → `resize-intent`).
|
|
89
|
+
|
|
90
|
+
Untouched: `degradedViewDecision` (an armed intent still blocks the degraded chain — existing #284 semantics; the full path with evidence covers this issue's shapes), the resync guard, the reporter's intent consumption, the runner protocol, and `noteGeometryIntent`'s arming.
|
|
91
|
+
|
|
92
|
+
This design covers all three lock shapes above, including the live `S0 → F0` frame sequence after the snapshot (A2c) — the S0 no longer erases the snapshot-derived evidence, and the F0 head is ordinary at target dims.
|
|
93
|
+
|
|
94
|
+
## Testability split design
|
|
95
|
+
|
|
96
|
+
| Unit | Kind | Boundary |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| `resizeIntentEvidenceFromRecords` | pure function, `src/core/pty-attach-render.mjs` | Unit-tested directly (`test/pty-attach-render.test.mjs`) with literal intents/records — no component, no client, no clock. |
|
|
99
|
+
| `fullViewDecision` bypass | pure decision chain, same module | Unit-tested via decision states (`test/pty-attach-render-decision.test.mjs`) — no component. |
|
|
100
|
+
| Component lifecycle + wiring | small changes in `PtyAttachComponent` | Driven through the existing real-path harness `test-support/attach-recovery-scenario.ts` (real `onSocketData` protocol lines, real client state machine, virtual clock) in `test/attach-recovery-component.test.mjs`. The harness gains one observability field (see below). |
|
|
101
|
+
| Runner / protocol | untouched | Existing suites keep pinning them; `npm run verify` runs the full set (real-Pi suite enumerated but skipped unless `PI23B1_REAL_PI=1` — see A4). |
|
|
102
|
+
|
|
103
|
+
Harness changes (R2-D3 + R3-D1): `test-support/attach-recovery-scenario.ts` collects attach-client `protocolError` events (via a wrapper on the component's `handleAttachEvent` channel — the same channel the component itself uses, `installSpy`-style; the client exposes no public `on()` seam to rely on) and exposes `protocolErrorCount` + codes in the step readout; the readout additionally gains a bounded `coverageHead` summary (`latestViewProof.proof` → `{ seq, frameId, intentId, geometryRevision, cols, rows }` or `null`), so "the coverage head became that F0" is assertable directly. Both listed in the test impact inventory.
|
|
104
|
+
|
|
105
|
+
## Acceptance matrix
|
|
106
|
+
|
|
107
|
+
| ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
|
|
108
|
+
|----|--------|----------|----------|----------|
|
|
109
|
+
| A1a | 纯谓词判定语义 | 自动化验证(unit) | `node --test test/pty-attach-render.test.mjs` 新增用例:satisfied+proofSeq=最大匹配 seq(匹配 F / required=false / 混合记录含匹配 F);false+null(仅 S/A、revision 错、intentId 错(0 或异值)、cols/rows 错、metadata 非法(多余字段/protocol≠1/非整数)、seq 非法、空数组、非数组、null 元素) | 全部断言通过 |
|
|
110
|
+
| A1b | full 链 bypass 语义 | 自动化验证(unit) | `node --test test/pty-attach-render-decision.test.mjs` 新增 decision-state 用例:放行(satisfied+proofSeq≤throughSeq+头 0/0 目标尺寸);不放行(无 evidence/未 satisfied → 原 reason;proofSeq>throughSeq → 原头检查 reason;头尺寸错 → proof-geometry-mismatch;**头 wrong-non-zero revision → geometry-revision**;**头 wrong-non-zero intent → resize-intent**——后两条前置有效 F1 证据,钉 R2-G2);头即目标 F(intent metadata 匹配)走原路径 | 全部断言通过 |
|
|
111
|
+
| A2a | 快照携带目标 F、coverage 头即目标 F | 自动化验证(integration,component + 真实 client 消息 + 虚拟时钟) | `node --test test/attach-recovery-component.test.mjs`(= repro-bug 前半形状):resnapshot 携带匹配 F 记录 + covered/exact-proof(目标 F) + committed 100x30 complete | resnapshot 步后 `attaching=false`、`readyReason=complete`、`settledAt=0`;`advance 2500` 后仍 settled |
|
|
112
|
+
| A2b | 快照窗口含目标 F + 普通 F0,coverage 头=F0 | 同上 | records=[F1, F0](同 seq 双 proof,= repro-f0-head),end coverage=covered 头 F0 | 同 A2a 通过标准(settle complete) |
|
|
113
|
+
| A2c | 快照后真实普通帧序列 `output → live S0 → live F0` 覆盖 coverage | 同上 | = repro-live-f0-after:resnapshot(F1 in records) → `output seq=3` → live `S0(seq=3)` → live `F0(seq=3)`;readout 断言 `protocolErrorCount===0` 且 `viewProofRecordCount` 递增;S0 后 `latestViewProof=unknown/candidate-open`,F0 后 `coverageHead={seq:3, intentId:0, geometryRevision:0, cols:100, rows:30}`(R2-D3/R3-D1) | settle complete;protocolErrorCount=0 |
|
|
114
|
+
| A3 | 负面语义不放松(集成层) | 同上 | ①records 携带 wrong-dims F / wrong-revision F / wrong-intent F(其余同 A2a)→ 仍锁;②无 evidence 时 live S0→F0 序列 → 仍锁(现行为);③二次 differing resize 后旧 evidence 失效(noteGeometryIntent 清除)→ 等待新 target F;④**live 混合序列(R3-G1)**:空 records resnapshot → live wrong-dims F1(revision/intent 匹配、cols 错,T8 已证可经真实 client 形成 covered proof)→ output → S0 → 目标尺寸 ordinary F0 → 不发布;⑤随后 live 匹配 F 仍可救活(正对照) | 各自在 250ms 与 2500ms 处仍 `attaching=true`、`notReadyReason` 按门序(resize-intent / geometry-revision / proof-geometry-mismatch → `deadline-expired:*`);正对照 settle complete |
|
|
115
|
+
| A4 | 全量回归门 | 自动化验证(build) | `npm run verify` = typecheck + perf gate + tests + coverage + pack:dry(package.json `verify` 脚本) | exit 0。real-Pi 套件(`test/attach-frame-witness.real.test.mjs`)默认 `test.skip`,不计为证据;如需真实拓扑证据另跑 `PI23B1_REAL_PI=1 node --test test/attach-frame-witness.real.test.mjs` 并记录。已知例外:共享 runner 上 `attach-entry-22` 200ms 墙钟断言慢性 flaky(#95 在案)——本地 verify 必须过;CI 失败仅允许重跑对拍,不得削弱断言 |
|
|
116
|
+
| U1 | 真实 differing-size attach 不再卡死 | 用户实测 | 部署前置(合并后):`git -C ~/.pi/agent/git/github.com/zhuxixi/pi-agent-board restore package-lock.json`(该 checkout 有在案 package-lock 脏改动)→ `git -C … pull --ff-only` → 完全退出并重启 pi → 对一个有输出的后台会话,以与创建时不同的终端尺寸 attach,必要时制造 capture 窗口内连续输出(如让会话正在流式输出时 attach)。回填时记录所检查的 view、budgetDeadline 与部署 SHA(R2-P1) | 内容在 2500ms 内(通常即时)展示。诊断判据(读 `~/.pi/agent/agent-board/views/<view>/diagnostics.jsonl`,按同一 attach 的 budgetDeadline 关联事件):① 该 attach 存在 `attach_settle_ready` 且 `details.readyReason="complete"`;② 该 attach 无 `attach_wait_expired` `details.phase="cap"` 事件(注意:cap 事件的 `notReadyReason` 恒为 `deadline-expired:waiting-for-complete-frame`,在发送前固定(`pty-attach.ts` `handleAttachHardTimeout`),`resize-intent` 只出现在 `phase="budget"` 事件——**不得**用 cap+resize-intent 筛选,那匹配不到任何事件);③ `phase="budget"` 且 proof facts 为 covered 的等待必须有同 attach 的后续 settle,否则记失败;④ 同尺寸 re-attach 即时(既有 workaround 路径不回归) |
|
|
117
|
+
|
|
118
|
+
A1a/A1b/A2/A3 均有直接先例(`pty-attach-render.test.mjs` / `pty-attach-render-decision.test.mjs` 的既有纯用例、T8 geometry-gate 场景),无预期障碍;U1 依赖合并后的部署前置,PR 期间以 A1–A4 为门,U1 在合并后执行并回填结果。
|
|
119
|
+
|
|
120
|
+
## Non-goals / out of scope
|
|
121
|
+
|
|
122
|
+
- **No gate weakening for bad proofs**: wrong-size / wrong-revision / wrong-intent evidence, stale evidence (`proofSeq > throughSeq`), wrong-**non-zero**-revision/intent coverage heads even when valid evidence exists, empty baselines, unfinished frames keep waiting exactly as today (A1b/A3 pin these). The bypass admits exactly one new fact: validated intent evidence *inside the covered window* plus an **ordinary (0/0)** coverage head at target dims.
|
|
123
|
+
- No changes to the degraded chain (armed intent still blocks it), the reporter's intent consumption, the resync guard, the runner protocol, or `noteGeometryIntent`'s arming.
|
|
124
|
+
- The sticky-evidence lifecycle deliberately does NOT cover: evidence surviving across `epochReset` semantics beyond what the current baseline recompute provides (an epoch reset nulls the committed view and the next accepted snapshot recomputes the evidence — no extra handling).
|
|
125
|
+
- Main-branch CI flakiness (#95, `attach-entry-22` wall-clock budget on shared runners) is tracked separately and explicitly not addressed here.
|
|
126
|
+
|
|
127
|
+
## Risks / guarantees
|
|
128
|
+
|
|
129
|
+
- **Guarantee (single-source matcher)**: both evidence sources — snapshot records and live records — go through the **same pure predicate** with identical per-record validation (marker, seq, strict metadata whitelist, revision, intent, target dims); no revision/intent-only shortcut exists anywhere. **Aggregation semantics (actual, R2-D1)**: snapshot derivation is per-baseline existential (highest-seq match, recomputed at each accepted `snapshotReady`); live derivation is set-on-match / untouched-otherwise; both share the sticky lifecycle table above. No subset/equivalence relation between paths is claimed — publication safety rests on the untouched coverage/identity/seq/frameState gates plus the bypass's own conditions (evidence freshness `proofSeq ≤ throughSeq`, ordinary 0/0 head, target dims). No missing, stale, wrong-size, wrong-non-zero-revision or wrong-intent proof can publish (A3④ pins the live wrong-size mixed sequence).
|
|
130
|
+
- Behavior change surface: `invalidateViewProof` no longer clears `resizeIntentSatisfied` (sticky evidence). This is intentional and pinned by A2c (S0 must not erase snapshot-derived evidence) and A3② (without evidence, S0/F0 still waits as today). The existing suites that pin `invalidateViewProof`'s coverage effects are untouched.
|
|
131
|
+
- This area has a revert history (#263): the production diff stays minimal — one pure predicate, gate-bypass logic in the pure decision module, four small component touches (reset line, live-record branch, `invalidateViewProof` reset removal, facts assembly), one harness observability field, tests.
|
|
132
|
+
- Coverage thresholds (`npm run verify`) apply unchanged.
|
|
133
|
+
|
|
134
|
+
## Test impact inventory
|
|
135
|
+
|
|
136
|
+
- `src/core/pty-attach-render.mjs` — add `resizeIntentEvidenceFromRecords`; extend `fullViewDecision` with the shared intent-evidence alternative (ordinary-head restricted).
|
|
137
|
+
- `src/ui/pty-attach.ts` — replace the `snapshotReady` reset line with the predicate call; the live-record branch calls the predicate with `[record]`; clear both in `noteGeometryIntent`; remove the reset line from `invalidateViewProof`; pass the field in the facts assembly.
|
|
138
|
+
- `test-support/attach-recovery-scenario.ts` — collect attach-client `protocolError` events (handleAttachEvent wrapper) into the readout (`protocolErrorCount`); add the bounded `coverageHead` summary to the readout.
|
|
139
|
+
- `test/pty-attach-render.test.mjs` — A1a.
|
|
140
|
+
- `test/pty-attach-render-decision.test.mjs` — A1b (incl. wrong-non-zero head negatives).
|
|
141
|
+
- `test/attach-recovery-component.test.mjs` — A2a/A2b/A2c/A3.
|