@zhuxixi/pi-agent-board 0.13.1 → 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 +51 -0
- package/README.md +15 -8
- 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-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-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/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-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/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 +198 -44
- package/src/ui/pty-attach.ts +1462 -117
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# spec — issue #270:场景在 stdout 排空前 `process.exit`,把 JSON 结果截断在 64 KiB
|
|
2
|
+
|
|
3
|
+
Drafted: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-11-04T00:19:30+08:00
|
|
4
|
+
Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-11-04T00:31:14+08:00 — cross-review R1(真缺口 1 / 细化 5):R1-G1 接受(补 `fake-slow-start-pi.mjs` 的第三条替换配方:write 保持无条件,只把 `if` 内的 `exit` 换成 flush-guarded 退出);R1-D1 接受(9 → 10 个 scenario);R1-D2 接受(A6 去掉不存在的 PR #272);R1-D3 接受(A2 断言改 payload 长度 + 合法 JSON,不写裸字节数);R1-D4 接受(守卫谓词钉死 `process.stdout.write`,`console.log` 不计,自测加一条样本);R1-D5 接受(§4 声明范围超出 issue 字面验收,PR 描述同步声明)
|
|
5
|
+
Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-11-04T00:37:59+08:00 — cross-review R2(真缺口 0,收敛):R2-D1 接受(§3.3 机械替换清单里移除 3 处专用配方站点,使清单恰好 15 处、与标题计数不再矛盾)
|
|
6
|
+
|
|
7
|
+
基线:`origin/main @ 936f46e`。复现证据、AST 清点与既有正确写法见
|
|
8
|
+
`research/01-reproduction-and-inventory.md`。本 issue 走 bug 路由,第 1 节即根因报告。
|
|
9
|
+
|
|
10
|
+
## 1. 现象与根因
|
|
11
|
+
|
|
12
|
+
`Test (Node 22)` / `Test (Node 24)` 两个必需 job 在 `test/pty-attach-ready.test.mjs:1286` 报
|
|
13
|
+
`Unterminated string in JSON at position 142957`,且与 PR 内容无关 —— 主分支自己的 `936f46e`
|
|
14
|
+
也是红的,因此**任何 PR 都合不了**。
|
|
15
|
+
|
|
16
|
+
根因是一行退出时序,不是数据生成:
|
|
17
|
+
|
|
18
|
+
- `test-support/pty-attach-ready-scenario.ts:4452-4453` 写 `JSON.stringify(result)`(约 143 KB)
|
|
19
|
+
后立刻 `process.exit(0)`。
|
|
20
|
+
- 测试侧 `spawnSync` 通过管道读 stdout,管道容量 64 KiB。payload 超限时 `write()` 返回 false,
|
|
21
|
+
余量在异步队列里等待 drain,而下一行的 `exit` 直接把进程拆掉。
|
|
22
|
+
- 结果:读端只拿到管道缓冲里的前 64 KiB。**退出码仍是 0**,截断静默发生,只有 `JSON.parse` 撞破。
|
|
23
|
+
- 本地绿的原因:读端是同一台机器上的快进程,写队列在 `exit` 之前排空;CI runner 更忙,输掉这场竞争。
|
|
24
|
+
|
|
25
|
+
确定性复现(慢读端,`| (sleep 3; cat)`):输出**正好 65536 字节**,
|
|
26
|
+
`JSON.parse` 报 `Unterminated string at position 63702`。见 research §1。
|
|
27
|
+
|
|
28
|
+
同形写法在 `test-support/**` 有 **18 处 / 17 个文件**(research §3)。s15 只是 payload 最大的那个,
|
|
29
|
+
其余是「payload 长大或 runner 变慢就会复现」的同类定时炸弹。
|
|
30
|
+
|
|
31
|
+
## 2. 设计决策表
|
|
32
|
+
|
|
33
|
+
| # | 决策 | 依据 / 取舍 |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| D1 | 新增 `test-support/stdout-flush.mjs`,分两层:`writeThenExit(stream, text, code, exit)`(注入流与退出函数)+ `exitAfterStdout(text, code = 0)`(绑定 `process.stdout` / `process.exit` 的薄壳) | 排空行为只能在子进程里观察,但「何时该退出」的判定可以纯化:注入 `stream` 与 `exit` 后,三条分支(正常回调 / `error` 事件 / 同步抛错)都能在单进程里单测 |
|
|
36
|
+
| D2 | 退出条件 = `write` 的**完成回调**触发;同时挂 `stream.once("error")` 并在写调用外 `try/catch` | 只挂回调会在管道被对端关闭时永远不触发(EPIPE 变未捕获异常)。三条路径都收敛到「按调用方给的 code 退出一次」,用一次性标志位保证不重复退出 |
|
|
37
|
+
| D3 | 全量替换 `test-support/**` 的 18 处,而不是只修 s15 那一处 | 形态完全同构、改法完全同构;只修一处等于把 17 个同类隐患留在原地,下一个 payload 长大的场景还要重演一次 CI 红灯 |
|
|
38
|
+
| D4 | 不修 `fake-pty-pi.mjs` / `fake-pty-generation-pi.mjs` | 它们已经是正确写法(回调形式),且 sha256 被测试钉死:`S15_ACCEPTED_HASHES.fakePtyChild`、`ENTRY_ACCEPTED_HASHES.generationFixture`。改动会让 harness 契约测试红 |
|
|
39
|
+
| D5 | 新增静态守卫测试 `test/scenario-stdout-flush.test.mjs`:用 TypeScript 编译器 API 解析 `test-support/**`,禁止「写 stdout 的语句紧邻 `process.exit` 语句」 | 正则会把 `.then` 里的写与 `.catch` 里的 `exit(1)` 误判成相邻,也会漏掉 `if (x) write(...)` 这种包裹;AST 判定给出精确口径,守卫才敢当门禁 |
|
|
40
|
+
| D6 | 守卫的判定函数是纯函数,配**正负样本自测**(含 `.then`/`.catch` 反例) | 守卫若自身写错会「永远通过」,等于没写。自测保证它能同时识别真违例与放过合法写法 |
|
|
41
|
+
| D7 | 不用 `process.exitCode = n` 的自然排空替代 | 多个 fixture 持有 `setInterval`、子进程或 socket,事件循环不会自己空转结束;改成自然退出会换来挂死风险 |
|
|
42
|
+
| D8 | 不改 `process.stderr.write(...)` + `exit` 的报错分支 | 写的是 stderr 且量级是几百字节报错信息;纳入范围只会扩大 diff,不解决本 issue |
|
|
43
|
+
|
|
44
|
+
## 3. 代码落点
|
|
45
|
+
|
|
46
|
+
### 3.1 新文件 `test-support/stdout-flush.mjs`
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
/**
|
|
50
|
+
* Write `text` to `stream` and call `exit(code)` only after every byte has
|
|
51
|
+
* been accepted. A bare `stream.write(text); exit(code)` tears the process
|
|
52
|
+
* down while the kernel pipe still holds a partial payload: anything past the
|
|
53
|
+
* 64 KiB pipe buffer is lost with a silent exit 0 (issue #270).
|
|
54
|
+
*
|
|
55
|
+
* `stream` and `exit` are injected so the three paths — flushed, broken pipe,
|
|
56
|
+
* synchronous throw — are unit-testable without spawning a child.
|
|
57
|
+
*/
|
|
58
|
+
export function writeThenExit(stream, text, code, exit) {
|
|
59
|
+
let settled = false;
|
|
60
|
+
const finish = () => {
|
|
61
|
+
if (settled) return;
|
|
62
|
+
settled = true;
|
|
63
|
+
exit(code);
|
|
64
|
+
};
|
|
65
|
+
stream.once("error", finish);
|
|
66
|
+
try {
|
|
67
|
+
stream.write(text, finish);
|
|
68
|
+
} catch {
|
|
69
|
+
finish();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function exitAfterStdout(text, code = 0) {
|
|
74
|
+
writeThenExit(process.stdout, text, code, (status) => process.exit(status));
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3.2 新文件 `test-support/stdout-flush-probe.mjs`
|
|
79
|
+
|
|
80
|
+
集成验证用的可执行夹具:`--bytes N`(默认 262144)→ 写出 `{"payload":"x"*N}` 后经
|
|
81
|
+
`exitAfterStdout` 退出。payload 必须明显大于 64 KiB,才能覆盖「`write()` 返回 false」的分支。
|
|
82
|
+
|
|
83
|
+
### 3.3 替换点(18 处:15 处机械替换 + 3 处专用配方)
|
|
84
|
+
|
|
85
|
+
机械替换的每一处语义保持逐字不变(写什么、退出码表达式都不改),只把「写 → 退出」换成一次
|
|
86
|
+
`exitAfterStdout(<同 text>, <同 code>)`:
|
|
87
|
+
|
|
88
|
+
- 10 个 `*-scenario.ts`:`pty-attach-ready`(4452)、`attach-entry-22`(1382)、`attach-ready-catchup`(368)、
|
|
89
|
+
`attach-ready-entry`(1070)、`attach-ready-interactions`(656)、`pty-attach-20b`(4010)、
|
|
90
|
+
`pty-attach-21b`(1389)、`pty-attach-matrix`(1222)、`pty-attach-timing`(1653)、
|
|
91
|
+
`pty-attach-parser-replacement`(808)
|
|
92
|
+
- `ensure-host-helper.mjs`(44)、`pi23a-smoke-runner.mjs`(452)、`pi23a-production-smoke-runner.mjs`(317)、
|
|
93
|
+
`formal-measurement/formal-runner.mjs`(24)、`formal-measurement/preflight.mjs`(135)
|
|
94
|
+
|
|
95
|
+
两处**非平凡形态**需要专用配方,不能套用上面的「合并成一次调用」规则:
|
|
96
|
+
|
|
97
|
+
- `fake-pty-frame-wrapper.mjs:137/143` 原本是 `if (cond) write(carry); exit(code)`,替换为
|
|
98
|
+
`exitAfterStdout(cond ? carry : "", code)`(`cond` 为假时写空串,行为等价)。
|
|
99
|
+
- `fake-slow-start-pi.mjs:34-35` 原本是**无条件** write 后跟 `if (text.includes("exit")) exit(0)`,
|
|
100
|
+
且进程靠 `setInterval(() => {}, 1000)` 保活。**不能**把 write 挪进 `if`:`test/pty-runner.integration.test.mjs`
|
|
101
|
+
的 resize-before-ready 用例先等 `echo:still-alive` 再发 `exit\r`,合并会让夹具在收到任意 stdin 块后
|
|
102
|
+
就退出、丢掉非 exit 输入的 echo。配方是:write 原位保留,只把 `if` 内的 `process.exit(0)` 换成
|
|
103
|
+
`if (text.includes("exit")) exitAfterStdout("", 0)`(空串写入的回调等价于「等已有输出排空」)。
|
|
104
|
+
替换后该点的语句相邻关系不再命中守卫(`if` 里是 `exitAfterStdout` 而非 `process.exit`),这是预期结果。
|
|
105
|
+
|
|
106
|
+
### 3.4 新测试 `test/scenario-stdout-flush.test.mjs`
|
|
107
|
+
|
|
108
|
+
- 纯函数 `findUnguardedStdoutExits(text, fileName)` 定义在本文件内(唯一使用方是守卫测试,
|
|
109
|
+
不额外引入模块):AST 解析 → 遍历所有语句列表 → 相邻语句对里「前句写 stdout、后句 `exit`」
|
|
110
|
+
记为违例;`if` / block 递归展开。
|
|
111
|
+
- **兄弟条件分支不配对**:前後两句都是 `if` 时直接跳过 —— 两个并列条件分支是相互独立的路径,
|
|
112
|
+
不是同一条「先 drain 再退出」序列(否则 `formal-runner.mjs` 的 `if (dryRun) { write; exit }`
|
|
113
|
+
会与后面那个 `if (FORMAL_APPROVED…) { … exit(2) }` 误配);块内部的真实相邻由递归单独发现。
|
|
114
|
+
- **谓词钉死**:只匹配 `process.stdout.write(...)` 的表达式语句;`console.log` / `console.info` /
|
|
115
|
+
`console.error` **不**计入(§6 显式非目标,`test-support/**` 里有 11 处 `console.log(x); process.exit(n)`,
|
|
116
|
+
计进来会让守卫与自己的非目标打架)。
|
|
117
|
+
- 守卫:扫描 `test-support/**/*.{ts,mjs,js}`,断言违例数 0,失败时打印 `file:line` 清单。
|
|
118
|
+
- 自测:合成样本表(违例 3 条、合法 6 条)断言判定口径,防止守卫空转。违例样本为
|
|
119
|
+
「直接写后 `exit`」「`if (x) write(...)` 后跟 `exit`」「`if (x) { write }` 后跟 `exit`」;
|
|
120
|
+
合法样本为「`write` 带回调」「`exitAfterStdout`」**「`console.log` 紧邻 `exit`」**
|
|
121
|
+
「`.then` 里写 / `.catch` 里 exit」「写后接条件式 helper 退出」「兄弟条件分支」。
|
|
122
|
+
|
|
123
|
+
## 4. 验收矩阵
|
|
124
|
+
|
|
125
|
+
| ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
|
|
126
|
+
|----|--------|----------|----------|----------|
|
|
127
|
+
| A1 | `writeThenExit` 三条分支都只退出一次 | 自动化验证(unit) | `node --test test/scenario-stdout-flush.test.mjs` | 正常回调 / `error` 事件 / `write` 同步抛错各触发 `exit` 恰好一次,且携带调用方给的 code |
|
|
128
|
+
| A2 | 超大 payload 在慢读端下不再截断 | 自动化验证(integration) | 同上:spawn `stdout-flush-probe.mjs --bytes 262144`,stdout 接管道且**延迟 250 ms 才开始读** | stdout 为合法 JSON、`payload.length === 262144`、退出码 0(不断言裸字节总数:JSON 包装让它等于 262157) |
|
|
129
|
+
| A3 | `test-support/**` 不再有「写 stdout 紧邻 `exit`」形态 | 自动化验证(static) | 同上:守卫用例 + 检测器自测 | 违例 0;自测样本判定与预期逐条一致(含 `.then`/`.catch` 与 `console.log` 反例不误报) |
|
|
130
|
+
| A4 | s15 battery 场景输出可解析 | 自动化验证(integration) | `node --test test/pty-attach-ready.test.mjs` | 88/88 通过(含 `case S real-runner battery`),无 `Unterminated string` |
|
|
131
|
+
| A5 | 全仓套件、类型、性能门禁、覆盖率、打包均绿 | 自动化验证(build) | `npm run verify` | typecheck + perf gate + tests + coverage(lines 85 / funcs 80 / branches 70)+ `pack:dry` 全部通过 |
|
|
132
|
+
| A6 | 两个必需 CI job 转绿 | 自动化验证(automated E2E) | 承载本修复的 PR(编号以创建时为准)上的 GitHub Actions | `Test (Node 22)` 与 `Test (Node 24)` 均 success |
|
|
133
|
+
|
|
134
|
+
**无用户实测项(无 U 项)**:本 issue 只改测试夹具的退出时序,产品行为零变化,用户侧没有可观测差异;
|
|
135
|
+
A6 用 PR 上的真实 CI 运行代替人工验证。这是分类结论,不是「想不出怎么测」的兜底。
|
|
136
|
+
|
|
137
|
+
**范围声明**:issue #270 的字面验收是「`test-support/*-scenario.ts` 清理干净或加注释豁免」,
|
|
138
|
+
本 spec 扩到 `test-support/**` 的 18 处(含 `.mjs` runner 与 `formal-measurement/`)。这是 D3 明确给出的
|
|
139
|
+
有意扩张(同一形态、同一改法,只修一处等于留 17 个同类隐患),PR 描述里会同步声明,便于评审对照。
|
|
140
|
+
|
|
141
|
+
## 5. 可测性拆分设计(实现阶段硬约束)
|
|
142
|
+
|
|
143
|
+
| 关注点 | 拆分后单元 | 测试边界 |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| 「何时退出」判定 | `writeThenExit(stream, text, code, exit)` —— 不碰全局 | 单进程内用假 stream(`EventEmitter` + `write(text, cb)`)覆盖三条分支;不需要 spawn |
|
|
146
|
+
| 与真实进程的绑定 | `exitAfterStdout(text, code)` —— 只有两行,不承载逻辑 | 由 A2 的子进程集成测试覆盖,不与判定逻辑混测 |
|
|
147
|
+
| 形态守卫 | `findUnguardedStdoutExits(text, fileName)` —— 纯函数,输入源码文本 | 合成样本自测(A3)+ 目录扫描(A3);两者都不依赖任何真实进程 |
|
|
148
|
+
| 真实截断机制 | `stdout-flush-probe.mjs` —— 可执行夹具 | 由父测试 spawn 并控制读取时机(A2) |
|
|
149
|
+
|
|
150
|
+
实现时不得把上述拆分重新耦合(例如把 AST 扫描写进产品代码、或让 `writeThenExit` 直接读 `process`)。
|
|
151
|
+
|
|
152
|
+
## 6. 非目标与保证边界
|
|
153
|
+
|
|
154
|
+
- **不覆盖** `console.log(x); process.exit(n)`(`test-support/**` 共 11 处):这是本 issue 的范围取舍,
|
|
155
|
+
不是因为这些站点安全。其中至少 6 处 —— `pty-attach-frame-overflow-scenario.ts:378`、
|
|
156
|
+
`pty-attach-mouse-mode-scenario.ts:94`、`pty-attach-wheel-scenario.ts:187`、
|
|
157
|
+
`pty-attach-selection-mirror-scenario.ts:260`、`attach-idle-socket-driver.ts:49`、
|
|
158
|
+
`attach-idle-candidate-open-harness.mjs:75` —— 都是 `console.log(JSON.stringify(result)); process.exit(...)`,
|
|
159
|
+
测试侧用 `JSON.parse(...)` 消费,与本 issue 修的是同一种失效模式,只是 payload 还小才没有暴露。
|
|
160
|
+
把其中机器解析的站点改成 flush 后退出由后续 issue #273 跟踪;在那之前它们同属定时炸弹。
|
|
161
|
+
- **不覆盖** `process.stderr.write(...)` + `exit` 的报错分支(stderr,量级为几百字节)。
|
|
162
|
+
- **不覆盖** 产品代码(`src/`、`runner/`)里的 `process.exit`:那里是命令行的正常退出路径,不在测试夹具范畴。
|
|
163
|
+
- **不修** #211(场景未消费的 stdout 管道)与 #95(real-process 测试的普遍 flake):本 issue 是确定性截断,
|
|
164
|
+
与「负载相关的预算问题」不是同一回事。
|
|
165
|
+
- **不做 lint 插件 / 独立 CI 步骤**:守卫以 `node:test` 用例形式存在,随套件跑,不新增 CI 配置面。
|
|
166
|
+
- 保证边界:本改动能让「同一进程内 write 后立刻 exit」不再丢字节;**不能**修复「父进程在子进程写完前
|
|
167
|
+
就杀掉子进程」这类外部 kill 造成的丢失。
|
|
168
|
+
|
|
169
|
+
## 7. 风险
|
|
170
|
+
|
|
171
|
+
| 风险 | 处置 |
|
|
172
|
+
|---|---|
|
|
173
|
+
| 17 个文件机械改动引入行为差异 | 每处的文本与退出码表达式逐字保留;这些文件全部被现有测试引用(`test-support/formal-measurement/preflight.mjs` 与 `fake-pty-frame-wrapper.mjs` 无直接测试,但后者被 6 个 scenario 间接使用),由 A4/A5 兜底 |
|
|
174
|
+
| EPIPE 时行为变化(原本 `exit(0)` 抢先,现在可能先收到 `error`) | D2 的 `once("error")` 让退出码与调用方一致,不会变成未捕获异常 |
|
|
175
|
+
| A2 的 250 ms 延迟被误读成时序断言 | 延迟只用来「先让 64 KiB 缓冲写满」,payload 256 KiB 是确定超限;延迟越长越必然,不构成 flake 来源 |
|
|
176
|
+
| `formal-plan.mjs` 的 `measurementScripts` 记录里 10 个文件哈希会变 | 那是身份记录(写进 artifacts),不是钉死常量;`test/formal-runner-plan.test.mjs:59` 的 `mirrored` 断言比较的是本 checkout 与同级 baseline 目录,在本仓解析为同一目录,不会因本次改动变红(已核实) |
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Issue #278 — Ctrl+G external editor invisible in modern attach: root cause and design
|
|
2
|
+
|
|
3
|
+
Drafted: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T22:01:37+08:00
|
|
4
|
+
Revised: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T22:25:23+08:00
|
|
5
|
+
Revised: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T23:23:04+08:00
|
|
6
|
+
Revised: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T23:27:52+08:00
|
|
7
|
+
|
|
8
|
+
- Issue: https://github.com/zhuxixi/pi-agent-board/issues/278
|
|
9
|
+
- Target base: `origin/main` `4bb836e9c9bb25c653bb6160e0d45a26e9348078` (approved design reviewed at `c71add85130d760684135c07d9ad2178d548a924`; intervening attach change is a one-line Kitty projection optimization with no contract impact)
|
|
10
|
+
- Research: `research/01-projection-history.md`, `research/02-reproduction-transition.md`
|
|
11
|
+
|
|
12
|
+
## 1. Conclusion
|
|
13
|
+
|
|
14
|
+
The defect is a projection-ownership gap. Modern protocol attach always renders the last immutable `committedView`, but Nvim owns the child terminal without emitting Pi's synchronized-output frame boundaries. The xterm buffer and input path are healthy; the visible projection and all committed-view interaction consumers remain attached to the old Pi frame.
|
|
15
|
+
|
|
16
|
+
The fix is a scoped external/live projection interval backed by an explicit terminal-ownership transition, plus a runner-owned boolean snapshot fact so a client that attaches while Nvim is already running can enter the same interval. Normal Pi rendering remains committed and fail-closed.
|
|
17
|
+
|
|
18
|
+
## 2. Evidence and root cause
|
|
19
|
+
|
|
20
|
+
### 2.1 Code path
|
|
21
|
+
|
|
22
|
+
- `src/ui/pty-attach.ts` `installParserObservers()` observes `CSI ?2026h/l`; only a real close calls `commitCommittedView()`.
|
|
23
|
+
- `modernCommittedMode()` is true for protocol attach with frame witness.
|
|
24
|
+
- `project()` selects `projectCommitted()` whenever that mode is true. Ordinary output schedules another render after parsing, but the render reads the same old immutable view.
|
|
25
|
+
- `interactionLine()`, `interactionNullCell()`, `mousePointForEvent()`, and `tryScrollBy()` independently select the committed view using the same mode. Changing only `render()` would leave mouse hit-testing, selection/copy, and scrolling on stale Pi coordinates.
|
|
26
|
+
|
|
27
|
+
### 2.2 Reproduction
|
|
28
|
+
|
|
29
|
+
A component reproduction (`research/component-result.json`) and a real managed Pi 1.5.0 + real runner/PTY + real Nvim reproduction (`research/real-nvim-result.json`) both produce:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"modern": true,
|
|
34
|
+
"liveProbeVisible": true,
|
|
35
|
+
"renderedProbeVisible": false,
|
|
36
|
+
"parserSyncOpen": false
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The real driver sends Ctrl+G through `PtyAttachComponent.handleInput()`, types `NVIM_VISIBLE_PROBE_1` into Nvim, and exits with `:q!`. After exit, the actual attach render shows Pi again and omits the Nvim probe.
|
|
41
|
+
|
|
42
|
+
### 2.3 Historical constraint
|
|
43
|
+
|
|
44
|
+
PR #261 introduced committed views to prevent partial Pi frames; #263 rolled them back; #265 restored them with idle downgrade. The #222 design intentionally makes synchronized close boundaries the normal modern publish mechanism. This issue must not weaken that mechanism globally.
|
|
45
|
+
|
|
46
|
+
## 3. Observed ownership protocol
|
|
47
|
+
|
|
48
|
+
The retained real screen log (`research/real-nvim-screen.log`) shows:
|
|
49
|
+
|
|
50
|
+
| Phase | Relevant order |
|
|
51
|
+
|---|---|
|
|
52
|
+
| Pi initial startup | Unframed `?1049h` before any Pi committed frame |
|
|
53
|
+
| Pi stops for Ctrl+G | `?2026h … ?1049l … ?2026l` |
|
|
54
|
+
| Nvim owns terminal | Unframed `?1049h`, one `?2026$p`, ordinary non-synchronized drawing |
|
|
55
|
+
| Nvim exits | Unframed `?1049l` |
|
|
56
|
+
| Pi restarts | Unframed `?1049h`, then `?2026h … ?2026l` |
|
|
57
|
+
|
|
58
|
+
Therefore alternate-screen state alone is not an ownership signal. A synchronized Pi `?1049l` is the entry signal; the next synchronized-output open is the return boundary. Nvim's own unframed `?1049h/l` and `?2026$p` do not change ownership.
|
|
59
|
+
|
|
60
|
+
## 4. Design decisions
|
|
61
|
+
|
|
62
|
+
| ID | Decision | Rationale |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| D1 | Add a pure screen-owner reducer shared by runner terminal model and attach component. | One tested definition prevents runner/UI transition drift. |
|
|
65
|
+
| D2 | Enter external/live only on `?1049l` observed while synchronized output is open; leave on the next `?2026h`. | Matches real Pi/Nvim order and does not misclassify Pi's startup alternate screen. |
|
|
66
|
+
| D3 | Runner retains the boolean for its whole child lifetime and includes it as optional `externalOutputActive` in `snapshot_begin`; client forwards it to `snapshotBegin`. | Supports attach/resnapshot while the editor is already open without process-name heuristics. |
|
|
67
|
+
| D4 | Add one component predicate for visible committed projection: modern mode AND (NOT external/live OR hydrating). Use it at every visible/interaction fork. | Rendering and interaction must address the same surface; hydration must retain committed/blank protection rather than exposing a partial live snapshot. |
|
|
68
|
+
| D5 | Keep `commitCommittedView()`, readiness, proof, recovery, and identity mechanisms in modern mode; only visible projection ownership changes. | A synchronized Pi stop can still commit a complete view; Pi restore must not publish its open/partial frame. |
|
|
69
|
+
| D6 | On external/live entry and exit, clear selection, pending click, auto-scroll, and stale viewport coordinates; follow the live bottom. | Old Pi/Nvim buffer offsets are not valid across screen ownership changes. |
|
|
70
|
+
| D7 | Preserve external/live across same-generation resize and parser replacement, but suspend it while hydration is in progress. Adopt the runner boolean at each new snapshot; reset on new generation, epoch reset, close/dispose, or legacy fallback. | Resize must not make Nvim invisible again; reconnect must not show a partial or stale surface. |
|
|
71
|
+
| D8 | Keep all input forwarding unchanged. | The defect is not in the input path. |
|
|
72
|
+
| D9 | Cover but do not alter Kitty APC proof classification in this issue. | Real evidence shows committed render restores before a new F; the APC proof gap is independent. |
|
|
73
|
+
|
|
74
|
+
## 5. Component and protocol contracts
|
|
75
|
+
|
|
76
|
+
### 5.1 Pure reducer and thin xterm adapters
|
|
77
|
+
|
|
78
|
+
Add a core module (working name `src/core/attach-screen-owner.mjs`) with a pure transition function over:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
interface AttachScreenOwnerState {
|
|
82
|
+
syncOpen: boolean;
|
|
83
|
+
externalOutputActive: boolean;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Accepted events are `sync-open`, `sync-close`, `alternate-screen-exit`, `adopt-external`, and `reset`. The transition table is:
|
|
88
|
+
|
|
89
|
+
| Event | Guard | Next state |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `sync-open` (`?2026h`) | none | `syncOpen=true`, `externalOutputActive=false` |
|
|
92
|
+
| `sync-close` (`?2026l`) | none | `syncOpen=false`; preserve external flag |
|
|
93
|
+
| `alternate-screen-exit` (`?1049l`) | `syncOpen === true` | set `externalOutputActive=true` |
|
|
94
|
+
| `alternate-screen-exit` | `syncOpen === false` | preserve state |
|
|
95
|
+
| `adopt-external` | snapshot boolean is present | replace only external flag with that boolean |
|
|
96
|
+
| `reset` | new generation/epoch/close/legacy | initial false/false state |
|
|
97
|
+
|
|
98
|
+
Unrelated CSI, `?1049h`, and `?2026$p` produce no transition. Parameter handling must recognize combined xterm parameter forms exactly as the current `?2026` observer does. For a combined CSI, the adapter evaluates the `alternate-screen-exit` guard against `syncOpen` **at the start of that CSI**, then applies the synchronized close/open transition; thus both `CSI ?2026;1049l` and `CSI ?1049;2026l` entered from an open block finish with `syncOpen=false` and `externalOutputActive=true`. A1 must pin both parameter orders and the corresponding unsynchronized non-entry case. The pure module has no terminal, socket, filesystem, timer, or UI dependency.
|
|
99
|
+
|
|
100
|
+
A thin adapter registers `? h/l` xterm handlers, returns `false` to preserve default parsing, and reports transitions to its caller. UI adapters retain existing closed/term/epoch fences and observer disposal. The runner adapter owns no timers or I/O beyond updating terminal-model state.
|
|
101
|
+
|
|
102
|
+
### 5.2 Runner and wire compatibility
|
|
103
|
+
|
|
104
|
+
`createTerminalModel()` installs the adapter on its real xterm parser and exposes the current boolean as model state. Both legacy and owned runners already share this model, so no duplicated child-output state machine is added.
|
|
105
|
+
|
|
106
|
+
`createTerminalSubscription()` copies the model boolean into non-empty and empty `snapshot_begin` messages as `externalOutputActive`. The value is sampled with the snapshot metadata after parser idle. Catch-up output remains authoritative for any transition after that sample.
|
|
107
|
+
|
|
108
|
+
`terminal-attach-client` validates the field as an optional boolean and includes it in `snapshotBegin`. A present non-boolean value (for example `"yes"` or `1`) is a protocol error: emit `protocolError`, omit the field from `snapshotBegin`, and leave the existing recovery state machine unchanged; never silently treat the value as absent or true. A2 must pin this failure branch in `test/terminal-attach-client.test.mjs`. The client does not invent `true` when the field is absent. For an older runner with no field, a same-generation component preserves its locally observed state; a fresh component starts false. This is the compatibility boundary, not a claim that an old runner can identify an already-open editor retrospectively.
|
|
109
|
+
|
|
110
|
+
No token, process name, command line, editor content, or host credential enters this field.
|
|
111
|
+
|
|
112
|
+
### 5.3 Component projection and lifecycle
|
|
113
|
+
|
|
114
|
+
Add a single internal predicate (working name `usesCommittedProjection()`):
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
modernCommittedMode()
|
|
118
|
+
&& (!externalOutputActive || localHydrationState === "hydrating")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Use this predicate in:
|
|
122
|
+
|
|
123
|
+
- `project()`;
|
|
124
|
+
- `interactionLine()`;
|
|
125
|
+
- `interactionNullCell()`;
|
|
126
|
+
- `mousePointForEvent()`;
|
|
127
|
+
- `tryScrollBy()`.
|
|
128
|
+
|
|
129
|
+
`render()` retains its existing attaching/loading and empty-baseline guards. External/live output uses the existing live projection, including cursor, Kitty-image projection, viewport clamping, and the existing 40 ms output scheduler. No extra per-chunk committed snapshot is introduced.
|
|
130
|
+
|
|
131
|
+
On entry/exit, interaction-state cleanup is a side effect outside the pure reducer. It clears the selection and pending mouse gesture, stops selection auto-scroll, clears pending click/double-click state, and sets `viewportTop=null`. It does not send input or request an unscheduled parser read.
|
|
132
|
+
|
|
133
|
+
At Pi restore, `?2026h` immediately returns visible rendering to the last valid committed view (or the existing blank/loading guard if none); live Pi redraw bytes are not exposed. Only `?2026l` commits and displays the restored Pi grid. The existing identity and geometry checks remain in force.
|
|
134
|
+
|
|
135
|
+
## 6. Restore-phase Kitty APC boundary
|
|
136
|
+
|
|
137
|
+
The real run observed Kitty image-deletion APC in Pi's first restored full redraw. That redraw did not increment `frameWitness.proofs`; a subsequent ordinary input incremented it from 1 to 2 and produced a new F at the new renderer epoch.
|
|
138
|
+
|
|
139
|
+
This issue's tests must therefore prove:
|
|
140
|
+
|
|
141
|
+
1. A restore synchronized frame containing `ESC _G … ESC \` still commits the actual restored Pi render.
|
|
142
|
+
2. No Nvim probe survives in that render.
|
|
143
|
+
3. A subsequent ordinary Pi input can still produce a later F proof.
|
|
144
|
+
|
|
145
|
+
The APC scanner/classifier itself remains unchanged. A separate issue can address proof coverage if desired.
|
|
146
|
+
|
|
147
|
+
## 7. Non-goals and guarantee boundaries
|
|
148
|
+
|
|
149
|
+
- Do not project every unframed write globally and do not remove Pi's complete-frame gate.
|
|
150
|
+
- Do not change Ctrl+G, editor configuration, key forwarding, mouse forwarding, or runner input protocol.
|
|
151
|
+
- Do not change legacy attach rendering except for the additive, inert model observation shared with protocol attach.
|
|
152
|
+
- Do not classify external applications that emit their own `?2026` synchronized frames; this contract targets the observed non-synchronized external-editor interval.
|
|
153
|
+
- Do not fix the independent Kitty APC proof-classification gap.
|
|
154
|
+
- The oracle is the actual `PtyAttachComponent.render()` plus interaction buffer addressing, as requested by the issue; it is not a physical-pixel screenshot claim.
|
|
155
|
+
- An old runner lacking the snapshot boolean cannot provide retrospective ownership to a fresh new client. Matching new runner/new client and locally observed transitions are the supported paths.
|
|
156
|
+
|
|
157
|
+
## 8. Testability decomposition (implementation constraint)
|
|
158
|
+
|
|
159
|
+
1. **Pure reducer:** exhaustive table tests for entry, non-entry, exit, adoption, reset, combined parameters, and unrelated controls. No xterm needed for the decision table; one real-xterm adapter test proves callback ordering and `return false` behavior.
|
|
160
|
+
2. **Terminal-model adapter:** feed real xterm output through `feedOutput()` and await `whenIdle()`; assert the persisted boolean at Pi start, Pi stop, Nvim output, Nvim exit, and Pi sync open. This is independently testable without sockets.
|
|
161
|
+
3. **Snapshot protocol:** drive `createTerminalSubscription()` with a terminal model and injected `send`; assert the optional boolean on empty/non-empty begins and catch-up ordering. Client tests drive `snapshot_begin` and assert `snapshotBegin` forwarding plus absent-field behavior.
|
|
162
|
+
4. **Component adapter and projection:** a dedicated transform-types scenario constructs the real `PtyAttachComponent`, drives real parser output through its attach events, waits for parser callbacks, and inspects actual `render()`. Input is spied at the existing socket/send seam; no input rewrite is needed.
|
|
163
|
+
5. **Interaction boundary:** in the same scenario, set non-default viewport/selection before entry; assert they are cleared, live interaction lines contain the Nvim probe, and restored Pi no longer uses Nvim coordinates. Test the open restore frame before its close to prove no partial Pi content is projected.
|
|
164
|
+
6. **Real E2E:** an opt-in `.mjs` test spawns a transform-types driver, following `attach-frame-witness.real.test.mjs` cleanup/isolation patterns. The driver discovers Pi with the existing `command -v pi` mechanism and discovers Nvim with `command -v nvim`, then uses real managed Pi, real runner/PTY, real component, and real `nvim -u NONE -i NONE`; it makes no model request and uses isolated roots and `PI_CODING_AGENT_DIR`. If either executable is missing, the real case reports a skip and A5 remains `pending` in the final report. The driver derives the repository root from its own `test-support/` location (or an explicit worktree root supplied by the test), and must not hard-code the main checkout path used by the research script.
|
|
165
|
+
|
|
166
|
+
Implementation must preserve these boundaries; parser observation, transition decisions, UI side effects, and wire transport must not be recoupled into an untestable monolithic handler.
|
|
167
|
+
|
|
168
|
+
## 9. Acceptance matrix
|
|
169
|
+
|
|
170
|
+
| ID | Feature / contract | Method | Concrete verification | Pass standard |
|
|
171
|
+
|---|---|---|---|---|
|
|
172
|
+
| A1 | Ownership reducer and parser transitions | Automated (unit) | `node --test test/attach-screen-owner.test.mjs` | All table cases pass: Pi startup alt entry does not activate; synced Pi alt exit activates; Nvim controls do not exit; next sync open exits; split/combined CSI and adapter disposal behave correctly. |
|
|
173
|
+
| A2 | Runner persistence + snapshot/client compatibility | Automated (unit + integration) | `node --test test/terminal-model.test.mjs test/terminal-attach-protocol.test.mjs test/terminal-attach-client.test.mjs` | Model retains correct boolean; empty/non-empty snapshots carry it; catch-up order remains intact; client forwards booleans, rejects present non-boolean values through `protocolError`, and preserves absent-field compatibility; existing protocol assertions pass. |
|
|
174
|
+
| A3 | Actual Nvim live render, input, and shared interaction projection | Automated (component + integration) | `node --test test/pty-attach-external-editor.test.mjs` | Before fix this scenario is RED. After fix actual `render()` contains `NVIM_VISIBLE_PROBE_1`; forwarded input is unchanged; live interaction reads the probe; normal Pi before/after uses committed view; no stale selection/viewport remains. |
|
|
175
|
+
| A4 | Restore, hydration, resize, generation, legacy, and disposal fences | Automated (component + integration + static) | Same component test plus `node --test test/pty-attach-parser-replacement.test.mjs test/pty-attach-ready.test.mjs` and `npm run typecheck` | Open Pi restore is never shown as a live partial frame; close restores Pi; same-generation resize/replacement preserve live after hydration; new generation/reset/fallback/close cannot leak stale state; existing suites and typecheck pass. |
|
|
176
|
+
| A5 | Full real Ctrl+G/Nvim round trip, reattach, Kitty restore observation, later proof | Automated E2E (opt-in real toolchain) | `PI278_REAL_NVIM=1 node --test test/attach-external-editor.real.test.mjs` | Real Pi + PTY + Nvim discovered through `command -v`: Pi prefill marker renders before Ctrl+G; Nvim unique probe appears in actual attach render; a fresh attach during Nvim also renders subsequent edits; `:q!` restores the original Pi marker at correct 80x22 body geometry and removes the Nvim probe; restore APC is recorded/covered; a later ordinary input produces a later F; cleanup leaves no runner/child. Missing executables produce skip plus A5 `pending`, never a false pass. |
|
|
177
|
+
| A6 | Repository-wide non-regression and ship gates | Automated (static + perf + full tests + coverage + build/package) | `npm run verify` | Typecheck, perf gate, all tests, coverage thresholds, and dry-run package pass in the issue worktree. Real E2E evidence is reported separately and is not replaced by the default suite. |
|
|
178
|
+
|
|
179
|
+
No acceptance item is classified as manual-only: the requested observable is programmatically inspectable component output. The opt-in real E2E must actually be executed on the development machine before merge; if it cannot run, A5 remains `pending` and the final report must say so.
|
|
180
|
+
|
|
181
|
+
## 10. Implementation scope
|
|
182
|
+
|
|
183
|
+
Expected production surfaces are the new pure owner module, `src/core/terminal-model.mjs`, `src/core/terminal-attach-protocol.mjs`, `src/core/terminal-attach-client.mjs`, and `src/ui/pty-attach.ts`. Tests and transform-types drivers are added under `test/` and `test-support/`. No dashboard layout, release tooling, or unrelated plans are in scope.
|
|
184
|
+
|
|
185
|
+
The implementation plan must map every task to at least one of A1–A6 and preserve the test boundaries above. RED evidence for A3 and the real A5 round trip is collected before the production fix; then the single ownership/projection change is implemented and verified without bundling unrelated fixes.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Issue #284 Spec — attach UI 恢复预算与安全重评(路径 B)
|
|
2
|
+
|
|
3
|
+
Drafted: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T22:05:00+08:00
|
|
4
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T22:40:00+08:00(round-1 复核 R1-G1/G2/G3 接受修订,R1-D1 接受细化)
|
|
5
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T23:10:00+08:00(round-2 复核 R2-G1/G2/G3/G4 接受修订,R2-D1/D2 接受细化)
|
|
6
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T23:45:00+08:00(round-3 复核 R3-G1/G2 接受修订,R3-D1 接受措辞修正)
|
|
7
|
+
Base: main @ 6f7b2dc(#282/#283 已合并;#267 spec v4 SHA-256 9bc4d0f2… 为设计基线)
|
|
8
|
+
Status: v4-final(round-4 收敛:0 真缺口;收敛后吸收 R4-D1/D2 两处非阻塞细化:枚举补 unknown、live S/A 行号锚点 1319/1326)
|
|
9
|
+
|
|
10
|
+
## 0. 本 spec 与 #267 spec v4 的关系
|
|
11
|
+
|
|
12
|
+
本 spec 是 #267 路径 B 的独立实施设计,继承父 spec v4 的 D3/D4/D5 与验收矩阵 A06–A12+U1/U2,并按 #284 调研(`research/report.md`,main @ 6f7b2dc)把设计锚定到实际代码:**纯策略函数 `decideAttachPresentation`(`src/core/pty-attach-render.mjs:182`)、事实装配 `evaluateAttachReady()`(`src/ui/pty-attach.ts:1371`)、committed view 机制、以及 #265 的 cap 时 idle-downgrade 特判块都已存在**。本 spec 的改动是在这些既有结构上的增量,不是从零新建。父 spec §3(协议语义)、§6(U1/U2 步骤)、§8(风险反思)继续有效,本 spec 不重复,只做增量引用与锚定。
|
|
13
|
+
|
|
14
|
+
**降级语义的关键澄清(R1-G1)**:父 spec D3 条件 5 明确允许降级的 coverage 形态包括 candidate-open、candidate-aborted、缺少 witness 证据与已显式丢失 witness——即「runner 协议候选未结束」是**可降级**状态;必须继续等待的是「本地同步帧未闭合」(frameState/openSyncBlock)与「传输/解析/身份校验失败」(proofStatus=invalid)。两者在本 spec 中由不同谓词表达,不得混用。candidate-open/aborted 有**两种真实到达形状**(R2-G1):快照内 `coverageFor` 产生的 `unavailable+candidate-*`,与 live 记录 `noteViewProofRecord`→`invalidateViewProof` 产生的 `unknown+candidate-*`——归纳表两者都归 missing。
|
|
15
|
+
|
|
16
|
+
## 1. 要解决的问题
|
|
17
|
+
|
|
18
|
+
#265 恢复了 F 门禁(busy attach P95 2541.6→54.1ms)并在 2500ms cap 提供了 idle downgrade,但降级出口太晚:**普通(非 fullscreen)会话的同尺寸 attach——子进程有输出、committed view 已安全、但不存在也不会有覆盖 F——仍要等满 `ATTACH_HARD_TIMEOUT_MS=2500` 才揭示**(`handleAttachHardTimeout` :1120-1140 特判块)。这是 #267 跟踪的 ~2500ms 残留的主要形态。
|
|
19
|
+
|
|
20
|
+
次要问题:capability loss(`frameWitness.enabled:false`,#280 后成为真实撤销路径)当前触发 `restoreLegacyDeadlines()` 回退 legacy 等待策略(:2349-2354),与现代协议的安全呈现路径不一致;且 `finishAttachTransition()` 将 `notReadyReason` 置 null,publish 时不区分「F 证明就绪」与「预算降级」,诊断无法回答「这次 attach 为什么显示了」。
|
|
21
|
+
|
|
22
|
+
## 2. 不变量(继承 + 新增)
|
|
23
|
+
|
|
24
|
+
继承父 spec §3 全部协议不变量(S/F 同 write 可能、A 非证明、openFrameId 仅协议层、geometry 门禁需真实目标 F、S 必须在 write 的 OPEN 偏移内联等——#280 已实现协议侧)。新增 UI 侧不变量:
|
|
25
|
+
|
|
26
|
+
- **I1(降级不伪造证明)**:`committed-degraded` 发布永不把 `latestViewProof.status` 改成 covered,永不写入 proof/marker/seq;它只发布已存在的 committed view。
|
|
27
|
+
- **I2(单次副作用)**:attach 转换副作用(`finishAttachTransition` 中的 color bridge、first-attach hooks 等)至多执行一次,降级路径与 F 路径共用同一入口。
|
|
28
|
+
- **I3(身份防栏)**:任何发布(含降级)必须通过 `canPublishAttachView(viewIdentity, currentIdentity)`;过期 token/callback、换代 baseline、reset 后的旧 view 一律拒绝。
|
|
29
|
+
- **I4(输入门禁不受降级影响)**:`childInputReady`、child 生命周期、selection/copy 视图来源、首 attach 副作用的既有门禁不因 committed-degraded 提前放行。
|
|
30
|
+
- **I5(预算不重置、不降低门禁)**:恢复预算从 attach 开始一次性计时,普通输出与重连(`startAttachSettle` 重入)不重置不延长;预算到期只新增「可降级」这一条出路,**不放宽 F 路径的任何既有门禁**——boot/raw/启动占位等内容等级拒绝是两条路径共享的前置门禁(见 3.1 谓词 7)。
|
|
31
|
+
- **I6(锁存与视图失效分层,R1-G3 + R2-D1 修订)**:失效分三层。**锁存层**:`witnessLatched`(本 attach 曾观察到 witness 能力)属于组件实例,只在 detach/dispose/新建 UI 组件时消失——同组件内的 socket/connection 重连**保留锁存**(重连不重置锁存,但旧 view/proof 失效)。**视图层**:baseline 替换、reset、resnapshot、connection 换代失效旧 view/旧 proof(凭新身份的新快照或合法闭合帧重建),不影响锁存。**失败事实层**:当前 baseline 的 invalid 分类(连续性/身份/校验失败)是 sticky 事实,capability loss 置空 `latestViewProof` 不抹掉它(见 3.1.1)。
|
|
32
|
+
|
|
33
|
+
## 3. 修复设计
|
|
34
|
+
|
|
35
|
+
### D3(修订版):250ms 恢复预算 + 策略化的降级发布
|
|
36
|
+
|
|
37
|
+
**3.1 策略函数扩展(`decideAttachPresentation`,src/core/pty-attach-render.mjs)**
|
|
38
|
+
|
|
39
|
+
在既有谓词链(F 门禁 → `publish/"complete"`)之后、返回 wait 之前,新增降级谓词链。新增输入(全部为事实,策略保持纯函数):
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
witnessLatched?: boolean // 本次 attach 曾观察到 witness 能力(见 3.3)
|
|
43
|
+
committedViewValid?: boolean // committedView 非空且 canPublishAttachView 通过
|
|
44
|
+
committedViewSource?: "snapshot" | "sync-close" | "none"
|
|
45
|
+
committedViewCols/Rows?: number // committed view 的实际来源尺寸
|
|
46
|
+
committedContentKind?: "complete" | "boot" | "raw" | "partial" | "unknown" // R2-G4 新增、R4-D1 补 unknown,见谓词 7
|
|
47
|
+
proofStatus?: "none" | "missing" | "invalid" | "covered" // 见 3.1.1 归纳表
|
|
48
|
+
budgetElapsed?: boolean // 恢复预算已到(timer 事实,非策略计时)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
降级谓词链(全部满足才 `publish-degraded/"committed-degraded"`,任一不满足返回带具体原因的 wait):
|
|
52
|
+
|
|
53
|
+
1. `mode === "protocol" && witnessLatched === true`;
|
|
54
|
+
2. `baselineState === "valid-content"`(empty baseline 保持等待)且 `localParseComplete === true`;
|
|
55
|
+
3. `frameState === "complete" && openSyncBlock !== true && committedViewValid === true`——本地 parser 事实(在途 write、未闭合本地同步帧必须等待);**runner 协议候选状态不在此谓词**(candidate-open/aborted 经 proofStatus 走 3.1.1 的可降级分类,R1-G1 修订);
|
|
56
|
+
4. `committedViewCols === targetCols && committedViewRows === targetRows && resizeIntentRequired !== true`(实际来源尺寸匹配;不能凭 identity 写入了 target 就推定源快照是目标尺寸——父 spec §8.5 反例);
|
|
57
|
+
5. `proofStatus === "none" || proofStatus === "missing"`——仅「缺证据」可降级;`"invalid"`(传输/解析/身份校验失败,含 sticky invalid,见 3.1.1)必须继续等待(父 spec D3 条件 3 的区分);
|
|
58
|
+
6. `budgetElapsed === true`;
|
|
59
|
+
7. `committedContentKind === "complete"`(R2-G4 新增、R3-G2 修订语义)——**本谓词的 "complete" 指本地闭合完整性,不声称语义级 boot/raw 识别**(无 F 时不可判定,见 §4 非目标)。可判定的生产装配规则:`commitCommittedView` 在提交时记录来源 `source`("snapshot" | "sync-close",新事实字段);snapshot 来源(校验完整、非空、hydration 完成的快照)或 sync-close 来源(本地完整解析闭合的同步帧)→ "complete";无法建立本地闭合完整性 → "unknown" → wait(fail-closed);boot/raw/partial 保留为策略级防御值,当前生产装配不产出,未来出现可观测判定时再接入。与 F 路径的 boot-content/raw-content 拒绝构成两条路径共享的前置门禁(I5)。
|
|
60
|
+
|
|
61
|
+
优先级固定:F 路径谓词全过 → `publish/"complete"`(不等预算);否则降级链全过 → `publish-degraded/"committed-degraded"`;否则 wait(reason 保留首个失败谓词)。每个拒绝原因必须在 A06/A08 有反例(可测性拆分见 §5)。
|
|
62
|
+
|
|
63
|
+
**3.1.1 proofStatus 归纳表(R1-G2 新增、R2-G1/G3、R3-G1 修订;新纯函数,独立单测)**
|
|
64
|
+
|
|
65
|
+
输入 `(latestViewProof, stickyInvalid)`,输出四分类。`classifyProofStatus(viewProof, stickyInvalid)` 为纯函数,与策略同层待新增。
|
|
66
|
+
|
|
67
|
+
**sticky 优先规则(R3-G1)**:`stickyInvalid === true` 时,**除 `status=covered` 外的任何输入——包括 candidate-open/aborted(双形状)、no-proof、no-output、null、以及一切未识别值——一律归 `invalid`**。sticky 不可被同 baseline 的后续非 covered 状态清洗。**清除条件只有两个**:当前 baseline 身份上出现 covered(真实 F 恢复),或 baseline 身份更换(resnapshot 接受新快照后凭新身份重新评估)。任何 invalid 分类(含未识别值 fail-closed)置 sticky(绑当前 baseline/视图身份);capability loss 置空 latestViewProof 不清除(归纳表 null 行)。
|
|
68
|
+
|
|
69
|
+
非 sticky 时的基础分类表:
|
|
70
|
+
|
|
71
|
+
| 输入 | 归类 | 依据 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `null` 且 `stickyInvalid === false`(capability 撤销置空、初始未收到,且当前 baseline 无未恢复失败) | `none` | 父 spec:已显式丢失 witness / 缺少证据可降级 |
|
|
74
|
+
| `null` 且 `stickyInvalid === true` | `invalid` | R2-G3:loss 不能抹掉未恢复的失败事实,否则旧失败借降级绕过恢复(父 spec D3 条件 5 后半) |
|
|
75
|
+
| `status=covered`(exact-proof / safe-trailing) | `covered`(且清除 sticky) | F 健康路径;唯一恢复出口 |
|
|
76
|
+
| `unavailable + candidate-open`(快照内 coverageFor 形状) | `missing` | 父 spec 明确可降级 |
|
|
77
|
+
| `unavailable + candidate-aborted`(快照内 coverageFor 形状) | `missing` | 父 spec 明确可降级 |
|
|
78
|
+
| `unknown + candidate-open`(live 记录 `noteViewProofRecord(S)`→`invalidateViewProof` 形状,pty-attach.ts:1319) | `missing` | R2-G1:live S 的真实形状,同为「候选未结束」的可恢复状态 |
|
|
79
|
+
| `unknown + candidate-aborted`(live 记录 `noteViewProofRecord(A)` 形状,pty-attach.ts:1326) | `missing` | R2-G1:live A 的真实形状 |
|
|
80
|
+
| `unknown + no-proof` | `missing` | 有输出但从未有 proof 记录——缺证据 |
|
|
81
|
+
| `unknown + no-output` | `missing` | 无任何输出,无证据可判 |
|
|
82
|
+
| `unavailable + trailing-pending / trailing-unsafe` | `invalid`(置 sticky) | 需已有更早 proof(covered 后延伸),属「已覆盖又失效」——不绕过恢复 |
|
|
83
|
+
| `unknown + output-gap / journal-gap / journal-evicted / proof-evicted / snapshot-seq-future / snapshot-before-window / invalid-snapshot-seq` | `invalid`(置 sticky) | 连续性/窗口完整性存疑 |
|
|
84
|
+
| `unknown + invalid-view-proof / view-proof-future / records-dropped / proof-output-gap` | `invalid`(置 sticky) | 协议校验失败 |
|
|
85
|
+
| UI invalidateViewProof 的 `view-proof-replay-gap`、`view-proof-trailing-*` | `invalid`(置 sticky) | 传输/解析/身份校验失败 |
|
|
86
|
+
| **任何未识别的 status/reason** | `invalid`(置 sticky) | fail-closed,宁等不显 |
|
|
87
|
+
|
|
88
|
+
(表中各行在 `stickyInvalid === true` 时除 covered 行外均被 sticky 优先规则覆盖为 invalid。)
|
|
89
|
+
|
|
90
|
+
「covered 后又因身份/连续性失效」归类 invalid 且 sticky,与父 spec「不能借降级绕过恢复」一致。A06 对本表逐行断言(每行一个正例 + sticky 优先规则的清洗反例 + null×sticky 两态 + 未识别值默认 invalid 的 fail-closed 反例)。
|
|
91
|
+
|
|
92
|
+
**3.2 恢复预算 timer(组件层;R1-D1 + R2-G2 修订)**
|
|
93
|
+
|
|
94
|
+
- 新增独立常量 `ATTACH_RECOVERY_BUDGET_MS = 250`(策略数值待实施后按 U1 数据校准);从 `attachStartedAt` 起算,**在 attach 首次启动时 arm 一次**(按 remaining 计算),普通输出不 defer,重连/`startAttachSettle` 重入**不重新 arm、不延长 deadline**(I5);`finishAttachTransition`/detach/dispose 清理。
|
|
95
|
+
- **fence 生命周期(R2-G2)**:预算回调**不使用 `attachWaitToken` 防栏**(它在重连的 `startAttachSettle` 重入时递增,会与 armed-once 互相抵消——首次 arm 捕获的 token 过期、budgetElapsed 永不置位)。预算使用**独立的 attach 生命周期 fence**:回调仅校验 `attaching && !closed && budgetArmed`;预算事实(budgetElapsed)属 attach 生命周期,与连接换代无关;到期后旧连接的过期视图发布仍由 I3 的身份防栏(connectionToken)拦截。
|
|
96
|
+
- **待新增注入接缝**(现有 `attachStartedAt` 直取 `Date.now()`、timer 直用全局 `setTimeout`,`nowFn` 只服务 desync):组件构造器增加可注入的 `now()` 与 scheduler(或等价 fake-timer 接线),A07 的 249/250ms 边界与预算生命周期测试全部走注入时钟,不依赖 wall clock。
|
|
97
|
+
- timer 回调:fence 校验 → `budgetElapsed = true` → `evaluateAttachReady()`。
|
|
98
|
+
- `handleAttachHardTimeout` 的 idle-downgrade 特判块(:1126-1140)**删除**,cap 到期只置 `deadlineState="expired"` 诊断后调用 `evaluateAttachReady()`——降级判定完全由策略承担(预算 2500ms 前早已过期,行为等价于「预算早已到、仍不满足谓词则继续等」)。legacy 分支行为不变。
|
|
99
|
+
|
|
100
|
+
**3.3 committed 路径锁存(组件层;R1-G3 + R2-D1 修订)**
|
|
101
|
+
|
|
102
|
+
- 新增 `witnessLatched` 状态:本次 attach 内 `frameWitnessAvailable` 首次变 true 时置位一次;**capability loss(`enabled:false`)不清除锁存、不调用 `restoreLegacyDeadlines()`**(当且仅当已锁存)——runner 撤销能力后 UI 继续走 committed 呈现路径。
|
|
103
|
+
- **锁存生命周期按 I6 三层**:**同组件内的 socket/connection 重连保留锁存**(重连是 connectionToken 递增 + `startAttachSettle` 重入,不新建组件),但旧 view/proof 按 I3 失效、凭新连接的新快照重建;baseline 替换、reset、resnapshot 同样只失效旧 view/proof,锁存保持;detach/dispose/新建 UI 组件才重置锁存(新 attach 重新观察能力)。
|
|
104
|
+
- 未协商协议 / 无 witness 能力 / parser observer 不支持的旧会话:`attachMode !== "protocol"` 或从未锁存——保留原 legacy 分支与 settle/hard 超时,锁存不影响它们。
|
|
105
|
+
- capability loss 后无新闭合帧则旧画面保留(不假装刷新)——此限制记录进诊断并由 U2 验证。
|
|
106
|
+
|
|
107
|
+
**3.4 readyReason 诊断字段**
|
|
108
|
+
|
|
109
|
+
`finishAttachTransition` 增加来源参数,发布时记录 `readyReason: "complete" | "committed-degraded" | "legacy-settle" | "legacy-cap"`(策略 publish → complete;publish-degraded → committed-degraded;legacy 两分支 → legacy-*)。`notReadyReason` 语义不变(等待原因)。诊断记录新增 `budgetDeadline` 与 `readyReason`,只记数值与有限枚举。
|
|
110
|
+
|
|
111
|
+
### D4(修订版):统一汇合点重评
|
|
112
|
+
|
|
113
|
+
`evaluateAttachReady()` 已有 6 个调用点(capability 更新、baseline 状态、snapshot proof、proof payload、geometry satisfied、sync close)。本设计新增/调整:
|
|
114
|
+
|
|
115
|
+
- **新增**预算到期回调(3.2);
|
|
116
|
+
- **新增** `commitCommittedView` 成功后的重评钩子(预算已到而视图刚提交的 quiet→late-snapshot 场景,不再等下一个 cap——父 spec D4「预算到期时没有可用视图,以后安全快照到达时立即重评」);
|
|
117
|
+
- **保持**过期 callback 的 token/stream 身份防栏(既有 `attachWaitToken` 模式适用于连接相位回调;预算回调按 3.2 的独立 fence);
|
|
118
|
+
- **语义**:预算到期时无可用视图只记「已到期」;之后任一汇合点到达即重评。持续输出每帧闭合 → 预算后下一个 sync close 发布最近已提交帧;输出始终未闭合 → 继续等待(不保证有界首屏)。
|
|
119
|
+
|
|
120
|
+
### D5(修订版):诊断与性能范围
|
|
121
|
+
|
|
122
|
+
- 扩充既有 attach 诊断(非新增常驻服务):`readyReason`、`budgetDeadline`、`witnessLatched`、`committedView` 的身份/实际尺寸/来源与内容等级、`proofStatus` 与 sticky-invalid 事实、既有 `deadlineState/notReadyReason/publishabilityState/latestViewProof` 全量保留。只记数值与有限枚举,不记 token、屏幕文本、密钥、整条终端数据。
|
|
123
|
+
- 性能目标范围不变:现代协议、同尺寸、安全快照已提交、受控无 F 场景——真实 socket 自动化首屏 <1500ms(调度余量)且证明未等 2500ms cap;纯策略精确断言预算边界(A06 用注入的 `budgetElapsed` 布尔,249/250ms 边界在组件 harness 用注入 clock 断言);健康 F 路径证明在预算前完成。1500ms 不是产品目标,250ms 数值是待 U1 校准的策略选择。
|
|
124
|
+
|
|
125
|
+
## 4. 非目标
|
|
126
|
+
|
|
127
|
+
- 不改协议层(evaluator/reporter/hosted-frame-witness 的 #280 语义)。
|
|
128
|
+
- 不做通用 renderer、resize 协议、terminal parser 重写;不加后台服务或全局 watchdog。
|
|
129
|
+
- 不改 `childInputReady`/selection/copy/首 attach 副作用门禁(I4)。
|
|
130
|
+
- 不承诺 empty baseline、differing-size、未闭合输出的有界首屏;不承诺 legacy 会话 250ms。
|
|
131
|
+
- **不声称降级内容的语义级 boot/raw 识别**(R3-G2):无 F 时生产代码无法判定内容是启动占位还是业务终帧——本设计的 "complete" 只指本地闭合完整性(快照校验完整非空 / 同步帧完整解析闭合)。残余风险(本地闭合但 producer 未完成的半帧被降级显示)是降级语义的固有部分,由 `readyReason=committed-degraded` 显式标记、由 U1 内容正确性样本与 U2 验证兜底,不伪装成已证实。
|
|
132
|
+
- 不把 `attach-frame-witness.real.test.mjs` 的绿灯当 U1 完成。
|
|
133
|
+
|
|
134
|
+
## 5. 验收矩阵与可测性拆分(A06–A12 + U1/U2)
|
|
135
|
+
|
|
136
|
+
自动化分层:策略 unit(纯函数语义)→ 组件 harness(真实 xterm + 注入 clock/timer,UI 状态转移)→ runner integration(真实双 main + 真实 socket + 真实组件,端到端时序)。
|
|
137
|
+
|
|
138
|
+
| ID | 功能点 | 层级与命令 | 通过标准 |
|
|
139
|
+
|---|---|---|---|
|
|
140
|
+
| A06 | D3 策略边界(unit):budgetElapsed 注入布尔;F 先到立即 publish/"complete";proofStatus=invalid 不降级;七条谓词各设反例(witnessLatched=false / baseline 非 valid-content / frameState 非 complete / committedViewValid=false / 尺寸不匹配或 resizeIntentRequired / budgetElapsed=false / **committedContentKind 为 boot、raw、partial、unknown** 各自 wait 且 reason 具体);**candidate-open 与 candidate-aborted 双形状正向降级断言**(unavailable 与 unknown 两种到达形状,均经 proofStatus=missing);**A/unavailable 不变为 covered(covered 只能来自真实 F,沿用父 spec 措辞)**;**committed-degraded 发布不改写 latestViewProof/proof/marker/seq(I1 独立断言)**;已 covered 但有其他门禁时 wait 不降级;**3.1.1 归纳表逐行断言 + sticky 优先规则清洗反例:同 baseline invalid 后到达 live S/A、no-proof、null 均归 invalid 不被清洗,预算与 cap 均不发布(R3-G1)**;null×sticky 两态;未识别 status/reason 默认 invalid 的 fail-closed 反例 | unit,`node --test test/attach-recovery.test.mjs`(新文件,直接测扩展后的 `decideAttachPresentation` 与新纯函数 `classifyProofStatus`) | 全部反例 wait 且 reason 命名谓词;降级仅七条全过;归纳表逐行符合;sticky 不可被非 covered 状态清洗 |
|
|
141
|
+
| A07 | D3/D4 组件行为(注入 clock):quiet(预算到期回调发布)、每 25ms 完整帧持续输出(不重置预算、预算后下一 sync close 发布)、预算前/后才提交快照(late-snapshot 重评钩子)、249ms 不发布 250ms 发布、candidate-aborted 场景降级、**t<250ms 重连(`startAttachSettle` 重入)后预算仍在原 250ms deadline 到期(不延长);旧连接回调不能发布**(R2-G2 成对断言)、**至少一条用例经真实 `viewProofRecord` 的 S/A 驱动 candidate 状态**(不伪造合成 proof 对象,R2-G1) | 组件 harness,`node --test test/attach-recovery.test.mjs test/attach-recovery-component.test.mjs test/pty-attach-parser-replacement.test.mjs`;新 harness `test/attach-recovery-component.test.mjs` 驱动 `test-support/attach-recovery-scenario.ts`(真实 xterm、**注入 now/scheduler**,模式参照 parser-replacement scenario),纳入 `npm test` | 首屏只取 committed 内容;预算不被输出/重连重置;晚到快照立即重评;重连保 deadline |
|
|
142
|
+
| A08 | D3/D4 反例(组件):empty baseline、open sync、parser 在途、错代、reset/resnapshot、晚 callback(token 过期)、proofStatus=invalid、covered 又失效、**invalid→capability loss(proof 置 null)→ 预算与 cap 均不得发布(sticky-invalid 反例)**;**同 baseline invalid→live S/A 到达、invalid→no-proof 到达均不得发布(sticky 清洗反例,R3-G1);随后当前 baseline covered 或 baseline 身份更换才清除**;**内容等级守卫用可观测事实驱动**(empty/占位 baseline → wait;committed view 的 source 字段记录 snapshot/sync-close,不手工伪造枚举装配,R3-G2)、producer 未完但合成 snapshot 已闭合(只 committed-degraded 非 proof-ready,后续完成可更新)、锁存后 capability loss 仍 committed 路径、loss → resnapshot/baseline 更换 → 新身份快照/合法闭合帧到达后继续 committed 更新(成对断言)、loss 后无闭合帧保留旧提交(成对断言)、**同组件重连保留锁存、旧 view/proof 失效需新快照**(R2-D1)、副作用至多一次、childInputReady 不被降级提前放行 | 组件 harness,命令同 A07 | 每反例保持 loading 或仅保留有效旧提交;不显示本地解析中状态;loss 后锁存与新身份重建共存;sticky invalid 不被 loss/后续 S/A/no-proof 清洗 |
|
|
143
|
+
| A09 | D3 geometry:same-size 零 resize/新 intent;错尺寸/错 intent/revision 的 F、A、loss、全部 timer 不解除 gate;真实 target F 才解除;源快照旧尺寸而 identity 已标当前 target 的反例不发布(I3+3.1 谓词 4) | integration + 组件,`node --test test/attach-frame-witness.integration.test.mjs test/pty-attach-parser-replacement.test.mjs` 及 A07 组件入口 | geometry proof 不可伪造 |
|
|
144
|
+
| A10 | D4 生命周期:detach/dispose 清 timer(含预算 timer)、失效→新 capability 不复活旧 view、连接/stream 换代旧身份不发布、新身份需新快照、legacy 不受锁存影响、降级后 selection/copy 与显示来源一致、预算 armed 一次(重复启动不重 arm)、**同组件重连保留锁存(R2-D1)** | 组件 harness,命令同 A07 | token fence 与身份防栏全过;预算一次性;重连保锁存 |
|
|
145
|
+
| A11 | D5 端到端:真实双 main、受控 S 后 quiet 与持续完整帧无 F(真实 coverage 含 live unknown/unavailable 双形状)——首屏 <1500ms、内容正确、readyReason=committed-degraded、证明未等 2500ms;healthy F 在预算前完成且 readyReason=complete;**断言保持外部 wall-clock(settledMs<1500ms、未等 2500ms),不用注入时钟、不放宽容差**(R2-D2);flaky 治理靠确定性等待条件(poll 至 settle 条件)而非放宽门槛;**至少一条用例经真实 viewProofRecord S 驱动**(R2-G1) | integration,扩充 `test/attach-frame-witness.integration.test.mjs` 与 `test-support/attach-idle-socket-driver.ts`;**改写** :306「S-then-idle at the legacy cap」为预算断言 | <1500ms + readyReason 正确 + 无 2500ms 等待 |
|
|
146
|
+
| A12 | 回归总量:typecheck、perf gate、tests、coverage、pack:dry;legacy 反例、#227 Kitty 回归、#275 快速路径、leaked coordinators | `npm run verify`(实施 worktree 内) | 全过,不得只以 `npm test` 代替 |
|
|
147
|
+
| U1 | 全新 fullscreen 会话首次 attach 隔离试点(≥10 首次 + 10 reattach 样本,P50/P95、readyReason 分布、按父 spec §4.1 报告成功率) | 用户实测,步骤按父 spec §6(worktree 绝对路径 entry/runner、隔离 PI_CODING_AGENT_DIR/board root/socket) | 样本齐全如实报告;任何 >预算样本注明阻塞门禁 |
|
|
148
|
+
| U2 | 不同尺寸、旧新版本组合与故障恢复(target F 后正常、loss 不伪造 geometry、混合版本兼容、全旧组合 legacy 策略保留、锁存后 loss → resnapshot 恢复序列与无闭合帧旧画面限制确认) | 用户实测,步骤按父 spec §6 | 如实报告 |
|
|
149
|
+
|
|
150
|
+
**可测性拆分设计(硬约束)**:① 策略扩展保持纯函数——`budgetElapsed`/`witnessLatched`/`proofStatus`/`committedContentKind` 等全部由调用方装配为事实传入,策略内不读时钟不读 socket(A06 直接单测谓词矩阵);② **`classifyProofStatus(viewProof, stickyInvalid)` 是独立纯函数**(3.1.1 表的唯一实现源),sticky 事实的记录/清除是组件层职责,独立单测;③ 预算 timer/fence/锁存/readyReason 属组件薄 I/O 层,经注入 now/scheduler 的组件 harness 测(A07/A08/A10),不进策略;④ 集成层只测协议端到端时序与诊断(A09/A11),不重复策略语义。实施不得把①②的纯函数逻辑耦合回组件。
|
|
151
|
+
|
|
152
|
+
## 6. 实施边界
|
|
153
|
+
|
|
154
|
+
- 允许改动:`src/core/pty-attach-render.mjs`(策略扩展)、新纯函数 `classifyProofStatus`(落位同文件或新 `src/core/attach-recovery.mjs`,实施计划定)、`src/ui/pty-attach.ts`(预算 timer 与独立 fence、锁存、sticky-invalid 事实、committedContentKind 装配、汇合点、readyReason、cap 特判删除、注入 now/scheduler 接缝)、上述测试与 test-support、诊断记录。
|
|
155
|
+
- 既有安全测试重写预期:`attach-frame-witness.integration.test.mjs:306` 及相关 cap 断言改为预算断言;empty/错尺寸/错代/解析未完反例**保留**。`attach-entry-22.test.mjs:100`(忙场景测量窗口)与 B/Q 200ms 发布预算经调研确认不受影响,**不改**;实施时如受影响按同一原则改写并说明。
|
|
156
|
+
- 保留 #227 grid/图像前缀与 bridge 生命周期、#275 快速路径。
|
|
157
|
+
- 提交按 task 分层可回退(策略+归纳函数 → 组件 → 集成/诊断),各阶段定向测试先行(TDD);worktree 内实施,main 保持干净。
|
|
158
|
+
|
|
159
|
+
## 7. 风险与反例(增量引用父 spec §8)
|
|
160
|
+
|
|
161
|
+
父 spec §8.1–8.7 的风险与反例全部继续有效,本节只列锚定增量:
|
|
162
|
+
|
|
163
|
+
- **§8.1 提前呈现(最高风险)**:降级谓词链的每个「不满足即 wait」都是防提前呈现的反例;`proofStatus=invalid`(含 sticky invalid 的优先规则——同 baseline 后续 S/A/no-proof/loss 均不可清洗、trailing-pending/unsafe、连续性缺口、协议校验失败、未识别值 fail-closed)不可降级,防「传输坏但时间到了就显示」;内容等级守卫用可观测事实(本地闭合完整性 + source 字段),不虚构语义判定(R3-G2);A08 逐反例覆盖。
|
|
164
|
+
- **§8.4 呈现锁存的新形态**:锁存后 capability loss 不回 legacy——若 runner 反复撤销/重建能力,UI 必须稳定停留在 committed 路径;loss 后 resnapshot 凭新身份重建 view(I6 分层),无新闭合帧时旧画面保留是**已知限制**,U2 专项确认,不作为缺陷掩盖。sticky invalid 在 loss 后保持,防「失败→撤销→降级」绕过链(R2-G3)。
|
|
165
|
+
- **#263 教训的延续**:降级出口必须保留(本设计把出口提前而非移除);若 #284 后再出现「witness 停帧永久等待」,按序怀疑:proofStatus 归纳把可降级态误归 invalid(检查 3.1.1 表与真实 reason——含 unknown/unavailable 双形状——的对齐)→ sticky invalid 清除条件过严(清除只有 covered 与 baseline 更换两途)→ #280 协议修复未覆盖的新路径。
|
|
166
|
+
- **预算数值风险**:250ms 是策略选择非验证指标;U1 数据若显示 committed view 常晚于 250ms 才安全提交,调大预算或改「预算+最近闭合帧」语义,不在 U1 前硬编码调小。
|