@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.
Files changed (80) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +15 -8
  3. package/docs/SECTION_FOLDING.md +53 -0
  4. package/docs/superpowers/plans/2026-10-23-issue-222-attach-ready.md +290 -0
  5. package/docs/superpowers/plans/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup.md +256 -0
  6. package/docs/superpowers/plans/2026-11-03-cwd-favorites-full-pool.md +266 -0
  7. package/docs/superpowers/plans/2026-11-03-issue-266-alt-h-detach.md +467 -0
  8. package/docs/superpowers/plans/2026-11-04-issue-270-scenario-stdout-flush.md +584 -0
  9. package/docs/superpowers/plans/2026-11-05-issue-278-ctrl-g-external-editor.md +381 -0
  10. package/docs/superpowers/plans/2026-11-06-issue-280-frame-witness-delivery.md +430 -0
  11. package/docs/superpowers/plans/2026-11-07-issue-284-attach-recovery.md +115 -0
  12. package/docs/superpowers/plans/2026-11-07-issue-284-u1-u2-trial-guide.md +39 -0
  13. package/docs/superpowers/plans/2026-11-08-host-restart-model-override.md +894 -0
  14. package/docs/superpowers/plans/2026-11-08-issue-288-cap-floor.md +51 -0
  15. package/docs/superpowers/plans/2026-11-09-dashboard-fold-flake.md +166 -0
  16. package/docs/superpowers/plans/2026-11-09-issue-273-harness-console-log-exit.md +369 -0
  17. package/docs/superpowers/plans/2026-11-10-issue-258-board-selection-settle.md +760 -0
  18. package/docs/superpowers/plans/2026-11-13-issue-294-snapshot-resize-intent.md +590 -0
  19. package/docs/superpowers/plans/2026-11-16-greeting-title-poll.md +838 -0
  20. package/docs/superpowers/plans/2026-11-22-issue-297-compaction-mirror.md +797 -0
  21. package/docs/superpowers/plans/2026-11-23-issue-254-cursor-keep-position.md +663 -0
  22. package/docs/superpowers/plans/2026-11-23-issue-95-legacy-quarantine.md +320 -0
  23. package/docs/superpowers/specs/2026-10-23-issue-222-attach-ready-design.md +204 -0
  24. package/docs/superpowers/specs/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup-design.md +197 -0
  25. package/docs/superpowers/specs/2026-11-03-cwd-favorites-full-pool-design.md +106 -0
  26. package/docs/superpowers/specs/2026-11-03-issue-266-alt-h-detach-design.md +185 -0
  27. package/docs/superpowers/specs/2026-11-04-issue-270-scenario-stdout-flush-design.md +176 -0
  28. package/docs/superpowers/specs/2026-11-05-issue-278-ctrl-g-external-editor-design.md +185 -0
  29. package/docs/superpowers/specs/2026-11-07-issue-284-attach-recovery-design.md +166 -0
  30. package/docs/superpowers/specs/2026-11-08-host-restart-model-override-design.md +115 -0
  31. package/docs/superpowers/specs/2026-11-08-issue-288-cap-floor-design.md +86 -0
  32. package/docs/superpowers/specs/2026-11-09-dashboard-fold-flake-design.md +109 -0
  33. package/docs/superpowers/specs/2026-11-09-issue-273-harness-console-log-exit-design.md +182 -0
  34. package/docs/superpowers/specs/2026-11-10-issue-258-board-selection-settle-design.md +109 -0
  35. package/docs/superpowers/specs/2026-11-13-issue-294-snapshot-resize-intent-design.md +141 -0
  36. package/docs/superpowers/specs/2026-11-16-greeting-title-poll-design.md +174 -0
  37. package/docs/superpowers/specs/2026-11-22-issue-297-compaction-mirror-design.md +158 -0
  38. package/docs/superpowers/specs/2026-11-22-issue-95-legacy-quarantine-design.md +209 -0
  39. package/docs/superpowers/specs/2026-11-23-issue-254-cursor-keep-position-design.md +201 -0
  40. package/package.json +1 -1
  41. package/runner/pty-runner.mjs +526 -63
  42. package/runner/title-runner.mjs +33 -24
  43. package/src/commands/agent-board.ts +5 -1
  44. package/src/core/attach-detach.mjs +27 -0
  45. package/src/core/attach-frame-proof.mjs +897 -0
  46. package/src/core/attach-frame-reporter.mjs +738 -0
  47. package/src/core/attach-frame-stream.mjs +266 -0
  48. package/src/core/attach-pr-label.mjs +12 -0
  49. package/src/core/attach-recovery.mjs +239 -0
  50. package/src/core/attach-screen-owner.mjs +55 -0
  51. package/src/core/attach-view-proof.mjs +709 -0
  52. package/src/core/auto-state.mjs +6 -1
  53. package/src/core/cwd-stats.mjs +3 -1
  54. package/src/core/dashboard-prefs.mjs +31 -0
  55. package/src/core/derive.mjs +8 -1
  56. package/src/core/events.mjs +127 -1
  57. package/src/core/foreground-projection-cache.mjs +1 -0
  58. package/src/core/frame-witness-update.mjs +35 -0
  59. package/src/core/fullscreen-selection.mjs +60 -0
  60. package/src/core/host-protocol.mjs +13 -2
  61. package/src/core/hosted-frame-witness.mjs +60 -0
  62. package/src/core/paths.mjs +10 -3
  63. package/src/core/pty-attach-render.mjs +239 -0
  64. package/src/core/pty-kitty-images.mjs +237 -0
  65. package/src/core/rows.mjs +43 -7
  66. package/src/core/session-entries.mjs +82 -0
  67. package/src/core/session-launch-prefs.mjs +45 -0
  68. package/src/core/session-view.mjs +3 -63
  69. package/src/core/store.mjs +1 -0
  70. package/src/core/terminal-attach-client.mjs +199 -20
  71. package/src/core/terminal-attach-protocol.mjs +221 -7
  72. package/src/core/terminal-model.mjs +24 -3
  73. package/src/core/terminal-snapshot.mjs +10 -0
  74. package/src/core/title-flow.mjs +66 -0
  75. package/src/core/title.mjs +101 -0
  76. package/src/core/types.mjs +17 -0
  77. package/src/index.ts +85 -0
  78. package/src/runtime/service.mjs +87 -18
  79. package/src/ui/dashboard.ts +198 -44
  80. package/src/ui/pty-attach.ts +1462 -117
@@ -0,0 +1,51 @@
1
+ # Implementation Plan — Issue #288: cap 地板降级(trailing-unsafe 锁死修复)
2
+
3
+ Work from: /home/elling/work/git-repo/pi-agent-board/.pi/worktrees/issue-288-cap-floor-downgrade
4
+ Spec: docs/superpowers/specs/2026-11-08-issue-288-cap-floor-design.md(v2-final)
5
+ Base: main @ a439b36 · branch issue-288-cap-floor-downgrade
6
+ Conventions: tabs; node:test + assert/strict; conventional commits; TDD; never `git add -A`.
7
+
8
+ ## 验收 ID ↔ Task 追溯
9
+
10
+ | 验收 ID | Tasks |
11
+ |---|---|
12
+ | A1(unit:家族函数 + 谓词三态) | T1 |
13
+ | A2(组件:trailing-only 放行 + hard 占优 + 双锁存) | T2 |
14
+ | A3(集成:≤4000ms cap settle + 对照) | T3 |
15
+ | A4(诊断:两相位 + 顺序) | T2(构造器与事件)、T3(集成断言) |
16
+ | A5(verify 总量) | T3 |
17
+ | U1(用户实测) | T4(试点提示,post-implementation pending) |
18
+
19
+ ## T1 — `classifyProofInvalidFamily` 纯函数 + 谓词 5 cap 分支(A1)
20
+
21
+ **Files**: `src/core/attach-recovery.mjs`(新纯函数)、`src/core/pty-attach-render.mjs`(谓词 5 + `capRecoverable` 输入 + JSDoc)、`test/attach-recovery.test.mjs`
22
+ **Steps(TDD)**:
23
+ 1. RED:A1 全部断言——家族函数逐形状(unavailable+trailing-pending/unsafe→trailing;unknown+view-proof-trailing-pending→trailing;unknown+view-proof-trailing-\<小写字母数字连字符\>→trailing;**畸形前缀**(大写/特殊字符/空 identifier/纯前缀)→hard;全部 hard reason(output-gap/journal-gap/journal-evicted/proof-evicted/snapshot-seq-future/snapshot-before-window/invalid-snapshot-seq/invalid-view-proof/view-proof-future/records-dropped/proof-output-gap/view-proof-replay-gap)→hard;未识别值→hard;非 invalid 输入(covered/missing 形状、null)→null)。谓词三态:pending 时 invalid(trailing 与 hard 皆)→ wait `proof-status-invalid`;expired 时 `invalid ∧ capRecoverable===true` → 通过谓词 5(后续谓词照常,全过 → publish-degraded);`invalid ∧ capRecoverable!==true` → wait **`deadline-expired:proof-status-invalid`**;`capRecoverable` 缺省(undefined)时 expired invalid → 同 hard 拒绝(fail-closed);其余六谓词不因 cap 放宽(各一反例)。
24
+ 2. GREEN:实现家族函数(精确字符串表 + 严格 identifier 正则 `^[a-z0-9-]+$`);谓词 5 按 spec §D1 分支。
25
+ **Verify**: `node --test test/attach-recovery.test.mjs`
26
+
27
+ ## T2 — 组件 hard 锁存 + capRecoverable 装配 + 等待态诊断(A2、A4 构造器部分)
28
+
29
+ **Files**: `src/ui/pty-attach.ts`(`proofHardInvalidatedThisBaseline` 锁存、装配、`buildAttachRecoveryFacts` 抽取 + settle/wait 薄包装、budget/cap 两触发点、onDiagnostic 联合类型)、`test-support/attach-recovery-scenario.ts`(读数扩展:hardInvalidated、capRecoverable、wait 事件采集)、`test/attach-recovery-component.test.mjs`
30
+ **Steps(TDD)**:
31
+ 1. RED→GREEN:hard 锁存生命周期(分类 invalid∧family=hard → 置位绑定 baselineToken;trailing/loss/S/no-proof 到达不清除;F 路径 publish 清除;baseline 更换重置);`capRecoverable = !hardInvalidated` 装配进 `evaluateAttachReady` 的事实。
32
+ 2. RED→GREEN(A2 序列,注入 clock):**trailing-only**(快照形状 + UI live 形状各一:covered→真实 noteViewProofOutput unsafe 输出→idle→250ms 预算不发布→2500ms cap→publish-degraded、readyReason=committed-degraded、sticky 置位、hard 锁存未置位);**hard 占优**(hard→trailing、trailing→hard、hard→loss、hard→S、hard→no-proof——cap 后均不发布);covered F publish 后双锁存清除、恢复正常降级。
33
+ 3. RED→GREEN(A4 构造器):抽取 `buildAttachRecoveryFacts()`(现 settle 诊断的白名单/token 排除逻辑原样迁移);`attach_wait_expired` 薄包装(`details.phase: "budget"|"cap"`,无 readyReason 字段);budget 回调与 cap handler 两触发点发事件;组件测试断言 **budget→cap→settle 事件顺序**、字段枚举白名单、无 token。
34
+ **Verify**: `node --test test/attach-recovery.test.mjs test/attach-recovery-component.test.mjs`
35
+
36
+ ## T3 — 集成 + verify 总量(A3、A4 集成断言、A5)
37
+
38
+ **Files**: `test/attach-frame-witness.integration.test.mjs`、`test-support/attach-idle-socket-driver.ts`
39
+ **Steps**:
40
+ 1. RED→GREEN(A3):双 main、真实 socket、注入 trailing-only 形状(至少一种 UI 到达形状)→ settle **≤4000ms(外部 wall-clock)**、断言 settle 诊断 `deadlineState=expired ∧ budgetElapsed=true`、readyReason=committed-degraded、proofStatus=invalid;对照场景(candidate-open)**<1500ms 且 deadlineState=pending**。确定性 poll、不注入时钟、不放宽容差(A3 的 4000ms 是设计内余量)。
41
+ 2. A4 集成断言:diagnostics.jsonl(或 driver 采集)出现 budget/cap 两相位 `attach_wait_expired` + `attach_settle_ready` 顺序。
42
+ 3. A5:`npm run verify` 全过;#284 既有断言零改写零回归(含 deadline-expired 前缀断言)。
43
+ **Verify**: `node --test test/attach-frame-witness.integration.test.mjs` + `npm run verify`
44
+
45
+ ## T4 — U1 试点提示(pending)
46
+
47
+ PR body 注明 U1 步骤(spec §5 U1:A5 后、修复版 UI 加载方式与 SHA 记录、runner 复用策略、diagnostics 检查路径);合并后提醒用户执行,未执行不得宣称验收完成。
48
+
49
+ ## 提交粒度
50
+
51
+ T1 `feat: add proof invalid family classifier and cap-floor policy branch` → T2 `feat: latch hard proof invalidation and emit attach wait diagnostics` → T3 `test: assert cap-floor settle on real sockets across dual mains`。
@@ -0,0 +1,166 @@
1
+ # Dashboard-fold harness flake fix — Implementation Plan
2
+
3
+ > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+ **Goal:** Make `test/dashboard-fold.test.mjs` immune to the trailing-age second flip between `render()` and `renderRows()` (issue #279), and add a deterministic regression leg that fails on the unfixed probe.
6
+
7
+ **Architecture:** Test-only change. (1) A `--import` preload module advances a fake clock +1000ms per `Date.now()` call, turning the CI-only flake into a deterministic red. (2) `frame()` in `test-support/dashboard-fold.ts` switches from full-string `includes` to the 20-column visible-prefix comparison already used by `dashboard-scroll.ts` / `dashboard-tui-modes.ts`, which excludes the trailing age column while still proving the selected target is visible in the windowed frame.
8
+
9
+ **Tech Stack:** node:test, execFileSync probe subprocesses, `--experimental-transform-types`, c8.
10
+
11
+ **Spec:** `docs/superpowers/specs/2026-11-09-dashboard-fold-flake-design.md` (acceptance IDs A1–A5, U1 quoted below).
12
+
13
+ ## Global Constraints
14
+
15
+ - Test-only: the final diff must not touch `src/` (A3's temporary mutation is reverted before commit).
16
+ - Tabs for indentation; English comments and commit messages.
17
+ - New filenames kebab-case (`tick-clock.mjs`).
18
+ - Conventional commit subject for the final change: `test(dashboard): …issue #279`.
19
+ - The tick leg and the probe fix land in **one atomic commit** (a tick-leg-only commit would leave the suite red).
20
+ - Work from: `/home/elling/git-repo/github/pi-agent-board/.pi/worktrees/issue-279-dashboard-fold-flake` (branch `issue-279-dashboard-fold-flake`, base `608a22a`). `node_modules` is symlinked from the main checkout — do not run `npm install`.
21
+
22
+ ---
23
+
24
+ ### Task 1: Deterministic red leg (tick-clock loader + test case)
25
+
26
+ **Files:**
27
+ - Create: `test-support/tick-clock.mjs`
28
+ - Modify: `test/dashboard-fold.test.mjs`
29
+
30
+ **Interfaces:**
31
+ - Consumes: existing `PROBE` constant and execFileSync pattern in `test/dashboard-fold.test.mjs`.
32
+ - Produces: `test-support/tick-clock.mjs` (side-effect-only preload, no exports) referenced by name in Task 2's verification and by spec A2.
33
+
34
+ - [ ] **Step 1: Write the loader**
35
+
36
+ Create `test-support/tick-clock.mjs` with exactly:
37
+
38
+ ```js
39
+ // Issue #279: advance a fake clock by 1000ms on every Date.now() call, so any
40
+ // two render passes that read the clock independently land on different seconds
41
+ // (the CI flake condition, made deterministic). Side-effect-only preload module
42
+ // for `node --import`; exports nothing.
43
+ const base = Date.now();
44
+ let calls = 0;
45
+ Date.now = () => base + calls++ * 1000;
46
+ ```
47
+
48
+ - [ ] **Step 2: Add the test case**
49
+
50
+ In `test/dashboard-fold.test.mjs`, append after the existing first test:
51
+
52
+ ```js
53
+ test("folding stays deterministic when the clock advances between render passes", () => {
54
+ const loader = fileURLToPath(new URL("../test-support/tick-clock.mjs", import.meta.url));
55
+ const out = execFileSync(process.execPath, ["--experimental-transform-types", "--import", loader, PROBE], {
56
+ encoding: "utf8",
57
+ timeout: 30_000,
58
+ });
59
+ assert.equal(JSON.parse(out).ok, true);
60
+ });
61
+ ```
62
+
63
+ (`fileURLToPath`, `execFileSync`, `process`, `assert`, `test`, `PROBE` are already imported/defined at the top of the file — no new imports.)
64
+
65
+ - [ ] **Step 3: Run the new case, verify it fails at the exact CI assertion**
66
+
67
+ Run: `node --test --test-name-pattern "clock advances" test/dashboard-fold.test.mjs`
68
+ Expected: FAIL — child probe aborts with `AssertionError: selected session/header must never be hidden by an indicator` at `frame (test-support/dashboard-fold.ts:56)`. Record the failure output verbatim for the PR body (spec A2's "can fail" evidence).
69
+
70
+ - [ ] **Step 4: Do NOT commit yet**
71
+
72
+ Task 1 and Task 2 form one atomic change; the commit happens in Task 2 Step 3.
73
+
74
+ ### Task 2: Prefix-compare fix in the probe
75
+
76
+ **Files:**
77
+ - Modify: `test-support/dashboard-fold.ts:52-57` (the `frame` helper)
78
+
79
+ **Interfaces:**
80
+ - Consumes: nothing from Task 1 (independent edit; same atomic commit).
81
+ - Produces: a `frame()` whose visibility assertion compares 20-column visible prefixes (spec A1).
82
+
83
+ - [ ] **Step 1: Replace the full-string comparison**
84
+
85
+ In `test-support/dashboard-fold.ts`, replace the `frame` helper (currently at lines ~52-60) with:
86
+
87
+ ```ts
88
+ // Issue #279: a row's trailing age column flips whole seconds, so two render
89
+ // passes can differ even with no state change. Compare the 20-column visible
90
+ // prefix instead (same convention as dashboard-scroll.ts / dashboard-tui-modes.ts):
91
+ // it still proves the selected target is visible in the windowed frame — a
92
+ // scroll marker never shares a row's prefix.
93
+ const visiblePrefix = (line: string) => line.trimEnd().slice(0, 20);
94
+ const frame = (width = 120) => {
95
+ const lines: string[] = dash.render(width);
96
+ assert.equal(lines.length, tui.terminal.rows);
97
+ assert.ok(lines.every((line: string) => visibleWidth(line) <= width));
98
+ if (dash.listTargets.length > 0) {
99
+ const body: string[] = dash.renderRows(width).map(stripVTControlCharacters);
100
+ const prefix = visiblePrefix(body[dash.selectedBodyLine]);
101
+ assert.ok(lines.map(stripVTControlCharacters).some((line: string) => visiblePrefix(line) === prefix), "selected session/header must never be hidden by an indicator");
102
+ }
103
+ return lines.map(stripVTControlCharacters);
104
+ };
105
+ ```
106
+
107
+ (Tab indentation, matching the file. The `visiblePrefix` helper sits immediately above `frame`, at the same depth.)
108
+
109
+ - [ ] **Step 2: Run the whole file, verify green**
110
+
111
+ Run: `node --test test/dashboard-fold.test.mjs`
112
+ Expected: PASS, all cases including the new tick leg.
113
+
114
+ - [ ] **Step 3: Commit the atomic change**
115
+
116
+ ```bash
117
+ git add test-support/tick-clock.mjs test-support/dashboard-fold.ts test/dashboard-fold.test.mjs
118
+ git commit -m "test(dashboard): keep dashboard-fold deterministic across second boundaries (issue #279)"
119
+ ```
120
+
121
+ ### Task 3: A3 mutation check (assertion still has teeth) — no commit
122
+
123
+ **Files:**
124
+ - Temporarily modify then revert: `src/ui/dashboard.ts` (`windowBody`, ~line 1846)
125
+
126
+ - [ ] **Step 1: Break the windowing guard**
127
+
128
+ In `src/ui/dashboard.ts`, inside `windowBody`, comment out the two clamp lines:
129
+
130
+ ```ts
131
+ // MUTATION (issue #279 A3, revert immediately): if (selLine < this.scrollTop + margin) this.scrollTop = selLine - margin;
132
+ // MUTATION: if (selLine >= this.scrollTop + capacity - margin) this.scrollTop = selLine - capacity + margin + 1;
133
+ ```
134
+
135
+ - [ ] **Step 2: Run the probe, verify the prefix assertion fails**
136
+
137
+ Run: `node --experimental-transform-types test-support/dashboard-fold.ts`
138
+ Expected: FAIL with `selected session/header must never be hidden by an indicator` (the selected row scrolls out of the window and no frame line shares its prefix). Record the output verbatim.
139
+
140
+ - [ ] **Step 3: Revert the mutation**
141
+
142
+ Run: `git checkout -- src/ui/dashboard.ts && git status --short`
143
+ Expected: clean (no `src/` changes).
144
+
145
+ ### Task 4: Acceptance battery (A1 / A4 / A5) — no commit
146
+
147
+ - [ ] **Step 1: A1 stress — real-clock test file ×20**
148
+
149
+ Run: `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`
150
+ Expected: `20/20`.
151
+
152
+ - [ ] **Step 2: A4 suite + threshold gate + probe-under-c8 stress**
153
+
154
+ Run: `npm test` (full suite) — expect pass.
155
+ Run: `npm run test:coverage` — expect pass, thresholds met.
156
+ Run: `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`
157
+ Expected: `20/20`.
158
+
159
+ - [ ] **Step 3: A5 full gate**
160
+
161
+ Run: `npm run verify`
162
+ Expected: typecheck + perf gate + tests + coverage + pack:dry all pass.
163
+
164
+ - [ ] **Step 4: Record evidence**
165
+
166
+ Paste the recorded outputs (Task 1 Step 3 red leg, Task 3 mutation red + revert, Task 4 loops) into the PR body under per-acceptance-ID headings.
@@ -0,0 +1,369 @@
1
+ # Six console.log harness exits — Implementation Plan
2
+
3
+ > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
4
+
5
+ **Goal:** Convert the last six `console.log(JSON.stringify(result)); process.exit(code)` harnesses to `exitAfterStdout`, widen the static guard to cover `console.log`/`console.info`, and pin the exit-code/newline contracts the guard alone cannot prove.
6
+
7
+ **Architecture:** No product code changes. Three layers: (1) the AST predicate in the guard test learns that `console.log`/`console.info` write the same `process.stdout`; (2) six call sites switch to the existing `exitAfterStdout` helper, keeping the text and exit-code expressions verbatim; (3) integration/unit assertions pin the behaviors the guard cannot see — conditional exit codes, the trailing newline, and `FORMAL_BASELINE_REPO` blank handling.
8
+
9
+ **Tech Stack:** Node 22/24, `node:test` + `assert/strict`, TypeScript compiler API for the AST guard, `--experimental-transform-types` for scenario harnesses.
10
+
11
+ Spec: `docs/superpowers/specs/2026-11-09-issue-273-harness-console-log-exit-design.md`(验收 ID A1–A9 均引用自此)。
12
+
13
+ ## Global Constraints
14
+
15
+ - Tabs for indentation; English comments and commit subjects (`feat`/`fix`/`test`/`docs`/`chore`).
16
+ - Do not touch `src/**` or `runner/**`; this issue is test-support only.
17
+ - Preserve the written text and exit-code expression at every conversion point; only the exit timing changes.
18
+ - `npm run verify` is the only complete gate (typecheck + perf + tests + coverage + pack:dry).
19
+ - `git add <file>` per file; never `git add -A`.
20
+
21
+ ---
22
+
23
+ ### Task 1: Widen the guard predicate and migrate its self-test samples (A1)
24
+
25
+ **Files:**
26
+ - Modify: `test/scenario-stdout-flush.test.mjs`(样本表、`writesStdout` 谓词、函数注释)
27
+ - Modify: `test-support/stdout-flush.mjs:10-15`(只改注释,不改运行时代码)
28
+
29
+ **Interfaces:**
30
+ - Produces: `writesStdout(statement)` 现在覆盖 `process.stdout.write(...)` 与 `console.log(...)` / `console.info(...)`;`findUnguardedStdoutExits(sourceText, fileName)` 签名不变。
31
+ - Consumes: 无。
32
+
33
+ - [ ] **Step 1: Write the failing samples first**
34
+
35
+ 在 `test/scenario-stdout-flush.test.mjs` 的 `violations` 数组加入:
36
+
37
+ ```js
38
+ ["console.log then exit", `console.log("x");\nprocess.exit(0);`],
39
+ ["console.info then exit", `console.info("x");\nprocess.exit(0);`],
40
+ ["conditional console.log then exit", `if (ready) console.log(x);\nprocess.exit(1);`],
41
+ ```
42
+
43
+ 从 `accepted` 数组删除 `["console.log then exit", ...]`,并加入:
44
+
45
+ ```js
46
+ ["console.error then exit", `console.error("x");\nprocess.exit(0);`],
47
+ ```
48
+
49
+ - [ ] **Step 2: Run the self-test and watch it fail**
50
+
51
+ Run: `node --test test/scenario-stdout-flush.test.mjs`
52
+ Expected: FAIL —— 三条新违例样本返回 `[]`(`must flag: console.log then exit` 等)。
53
+
54
+ - [ ] **Step 3: Implement the predicate**
55
+
56
+ 在 `isStdoutReceiver` 之后加:
57
+
58
+ ```js
59
+ const CONSOLE_STDOUT_METHODS = new Set(["log", "info"]);
60
+ const isConsoleIdentifier = (node) => ts.isIdentifier(node) && node.text === "console";
61
+ const writesConsole = (statement) =>
62
+ ts.isExpressionStatement(statement) &&
63
+ ts.isCallExpression(statement.expression) &&
64
+ ts.isPropertyAccessExpression(statement.expression.expression) &&
65
+ CONSOLE_STDOUT_METHODS.has(statement.expression.expression.name.text) &&
66
+ isConsoleIdentifier(statement.expression.expression.expression);
67
+ ```
68
+
69
+ 把 `writesStdout` 改为:
70
+
71
+ ```js
72
+ const writesStdout = (statement) =>
73
+ isCallStatement(statement, "write", isStdoutReceiver) || writesConsole(statement);
74
+ ```
75
+
76
+ 同步函数注释:谓词覆盖 `process.stdout.write` 与 `console.log`/`console.info`(同一 stdout 通道);
77
+ `console.error`(stderr)、`console.debug`、别名写法仍不覆盖。
78
+
79
+ 同步 `test-support/stdout-flush.mjs:10-15` 的注释:守卫覆盖 `process.stdout.write(...)` 与
80
+ `console.log`/`console.info(...)`;其余边界保持不变。运行时代码零改动。
81
+
82
+ - [ ] **Step 4: Run the self-test — samples pass, directory scan now fails on six real offenders**
83
+
84
+ Run: `node --test test/scenario-stdout-flush.test.mjs`
85
+ Expected: 样本用例 PASS;全目录扫描用例 **FAIL**,并列出恰好 6 行
86
+ (`pty-attach-frame-overflow-scenario.ts:378`、`pty-attach-mouse-mode-scenario.ts:94`、
87
+ `pty-attach-wheel-scenario.ts:187`、`pty-attach-selection-mirror-scenario.ts:260`、
88
+ `attach-idle-socket-driver.ts:221`、`attach-idle-candidate-open-harness.mjs:75`)。
89
+
90
+ 这条红就是 A2 的「放宽后守卫确实会咬人」证据,记录在实现评论里。
91
+
92
+ - [ ] **Step 5: Commit**
93
+
94
+ ```bash
95
+ git add test/scenario-stdout-flush.test.mjs test-support/stdout-flush.mjs
96
+ git commit -m "test: guard console.log stdout writes before exit (issue #273)"
97
+ ```
98
+
99
+ ---
100
+
101
+ ### Task 2: Convert the six call sites (A2)
102
+
103
+ **Files:**
104
+ - Modify: `test-support/pty-attach-frame-overflow-scenario.ts:378-379`
105
+ - Modify: `test-support/pty-attach-mouse-mode-scenario.ts:94-95`
106
+ - Modify: `test-support/pty-attach-wheel-scenario.ts:187-188`
107
+ - Modify: `test-support/pty-attach-selection-mirror-scenario.ts:260-261`
108
+ - Modify: `test-support/attach-idle-socket-driver.ts:221-222`
109
+ - Modify: `test-support/attach-idle-candidate-open-harness.mjs:75-76`
110
+
111
+ **Interfaces:**
112
+ - Consumes: `exitAfterStdout(text, code = 0)`(`test-support/stdout-flush.mjs`,既有)。
113
+ - Produces: 六个夹具仍打印一行 JSON + `\n`,退出码表达式不变。
114
+
115
+ - [ ] **Step 1: Convert the four fixed-code scenarios**
116
+
117
+ 每个文件在现有相对导入区加入 `import { exitAfterStdout } from "./stdout-flush.mjs";`,
118
+ 把
119
+
120
+ ```ts
121
+ console.log(JSON.stringify(result));
122
+ process.exit(0);
123
+ ```
124
+
125
+ 换成
126
+
127
+ ```ts
128
+ exitAfterStdout(JSON.stringify(result) + "\n", 0);
129
+ ```
130
+
131
+ 四个文件:`pty-attach-frame-overflow-scenario.ts`、`pty-attach-mouse-mode-scenario.ts`、
132
+ `pty-attach-wheel-scenario.ts`、`pty-attach-selection-mirror-scenario.ts`。
133
+
134
+ - [ ] **Step 2: Convert the two conditional-code harnesses**
135
+
136
+ `attach-idle-socket-driver.ts` 与 `attach-idle-candidate-open-harness.mjs` 同样加导入,把
137
+
138
+ ```ts
139
+ console.log(JSON.stringify(result));
140
+ process.exit(result.settledMs !== null && result.showsContent ? 0 : 1);
141
+ ```
142
+
143
+ 换成
144
+
145
+ ```ts
146
+ exitAfterStdout(JSON.stringify(result) + "\n", result.settledMs !== null && result.showsContent ? 0 : 1);
147
+ ```
148
+
149
+ - [ ] **Step 3: Run the guard test — scan is green**
150
+
151
+ Run: `node --test test/scenario-stdout-flush.test.mjs`
152
+ Expected: PASS,`offenders` 为空。
153
+
154
+ - [ ] **Step 4: Run the four consumer suites**
155
+
156
+ Run: `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`
157
+ Expected: 全部 PASS,无 `Unterminated string`。
158
+
159
+ - [ ] **Step 5: Commit**
160
+
161
+ ```bash
162
+ git add test-support/pty-attach-frame-overflow-scenario.ts test-support/pty-attach-mouse-mode-scenario.ts test-support/pty-attach-wheel-scenario.ts test-support/pty-attach-selection-mirror-scenario.ts test-support/attach-idle-socket-driver.ts test-support/attach-idle-candidate-open-harness.mjs
163
+ git commit -m "fix(test): drain stdout for the six console.log harness exits (issue #273)"
164
+ ```
165
+
166
+ ---
167
+
168
+ ### Task 3: Pin exit codes and the trailing newline (A3, A4, A5)
169
+
170
+ **Files:**
171
+ - Modify: `test/attach-frame-witness.integration.test.mjs`(成功用例约 448 行、hard-invalid 用例约 815 行)
172
+ - Modify: `test/scenario-stdout-flush.test.mjs`(文件末尾新增两路 smoke)
173
+ - Modify: `test/pty-attach-frame-overflow.test.mjs:18-22`
174
+ - Modify: `test/pty-attach-mouse-mode.test.mjs:18-22`
175
+ - Modify: `test/pty-attach-wheel.test.mjs:19-23`
176
+ - Modify: `test/pty-attach-selection-mirror.test.mjs:18-22`
177
+
178
+ **Interfaces:**
179
+ - Consumes: 六个夹具的 stdout/退出码(Task 2 的产物)。
180
+ - Produces: 无新导出;只加断言。
181
+
182
+ - [ ] **Step 1: Add the driver success-path assertions**
183
+
184
+ 在 `test/attach-frame-witness.integration.test.mjs` 的「the proven frame settles the attach」用例,
185
+ `spawnSync` 之后、现有 `attaching` 断言之前加:
186
+
187
+ ```js
188
+ assert.equal(driver.status, 0, `the settled driver must exit 0; stderr:\n${(driver.stderr ?? "").slice(-300)}`);
189
+ assert.ok(driver.stdout.endsWith("\n"), "the result channel keeps console.log's trailing newline");
190
+ ```
191
+
192
+ - [ ] **Step 2: Add the driver failure-path assertions**
193
+
194
+ 在 hard-invalid 用例的 `assert.equal(exited, true, ...)` 之后加:
195
+
196
+ ```js
197
+ assert.equal(driver.exitCode, 1, "an unsettled driver must exit 1, not a constant 0");
198
+ assert.ok(driverOut.endsWith("\n"), "the failure path also keeps console.log's trailing newline");
199
+ ```
200
+
201
+ - [ ] **Step 3: Add the orphan-harness smoke**
202
+
203
+ 在 `test/scenario-stdout-flush.test.mjs` 末尾加:
204
+
205
+ ```js
206
+ const CANDIDATE_OPEN_HARNESS = fileURLToPath(new URL("../test-support/attach-idle-candidate-open-harness.mjs", import.meta.url));
207
+
208
+ const runCandidateOpenHarness = (env) => spawnSync(
209
+ process.execPath,
210
+ ["--experimental-transform-types", CANDIDATE_OPEN_HARNESS],
211
+ { encoding: "utf8", timeout: 5000, env: { ...process.env, ...env } },
212
+ );
213
+
214
+ test("stdout-flush: the orphan candidate-open harness prints one JSON line and keeps its own exit code", () => {
215
+ const settled = runCandidateOpenHarness({});
216
+ assert.equal(settled.status, 0, `default run must exit 0; stderr:\n${settled.stderr}`);
217
+ assert.ok(settled.stdout.endsWith("\n"), "the result channel keeps console.log's trailing newline");
218
+ const settledResult = JSON.parse(settled.stdout.trim());
219
+ assert.notEqual(settledResult.settledMs, null, "the default run settles");
220
+
221
+ const timedOut = runCandidateOpenHarness({ HARNESS_TIMEOUT_MS: "0" });
222
+ assert.equal(timedOut.status, 1, `a zero timeout must exit 1; stderr:\n${timedOut.stderr}`);
223
+ assert.ok(timedOut.stdout.endsWith("\n"), "the failure path also keeps the trailing newline");
224
+ const timedOutResult = JSON.parse(timedOut.stdout.trim());
225
+ assert.equal(timedOutResult.settledMs, null, "a zero timeout never settles");
226
+ });
227
+ ```
228
+
229
+ (`spawnSync`、`fileURLToPath` 已在该文件顶部导入,无需新增 import。)
230
+
231
+ - [ ] **Step 4: Add the four consumer newline assertions**
232
+
233
+ 四个文件都在 `const out = execFileSync(...)` 之后、`JSON.parse` 之前加同一行:
234
+
235
+ ```js
236
+ assert.ok(out.endsWith("\n"), "the result channel keeps console.log's trailing newline");
237
+ ```
238
+
239
+ - [ ] **Step 5: Run the touched suites**
240
+
241
+ Run: `node --test test/scenario-stdout-flush.test.mjs test/attach-frame-witness.integration.test.mjs 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`
242
+ Expected: 全部 PASS。
243
+
244
+ - [ ] **Step 6: Commit**
245
+
246
+ ```bash
247
+ git add test/attach-frame-witness.integration.test.mjs test/scenario-stdout-flush.test.mjs 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
248
+ git commit -m "test: pin harness exit codes and trailing newline (issue #273)"
249
+ ```
250
+
251
+ ---
252
+
253
+ ### Task 4: `resolveBaselineRepo` for blank `FORMAL_BASELINE_REPO` (A7)
254
+
255
+ **Files:**
256
+ - Modify: `test-support/formal-measurement/formal-plan.mjs`(新增导出,`node:path` 导入补 `resolve`)
257
+ - Modify: `test-support/formal-measurement/formal-runner.mjs:20-22`
258
+ - Test: `test/formal-runner-plan.test.mjs`
259
+
260
+ **Interfaces:**
261
+ - Produces: `resolveBaselineRepo(envValue, repo) => string` —— 不直接读 `process.env`/`process.cwd`;
262
+ `undefined` / 空串 / 纯空白回落 `<repo>/../issue-222-attach-baseline`;非空值走 `resolve(envValue)`。
263
+ - Consumes: 无。
264
+
265
+ - [ ] **Step 1: Write the failing test**
266
+
267
+ `test/formal-runner-plan.test.mjs` 顶部 import 改为:
268
+
269
+ ```js
270
+ import { resolve } from "node:path";
271
+ import { buildFormalPlan, classifyTrial, FORMAL_TOTAL, WARMUP_TOTAL, expectedPath, resolveBaselineRepo } from "../test-support/formal-measurement/formal-plan.mjs";
272
+ ```
273
+
274
+ 文件末尾加:
275
+
276
+ ```js
277
+ test("FORMAL_BASELINE_REPO: unset, empty and blank resolve to the default baseline", () => {
278
+ const repo = "/repo/candidate";
279
+ assert.equal(resolveBaselineRepo(undefined, repo), "/repo/issue-222-attach-baseline");
280
+ assert.equal(resolveBaselineRepo("", repo), "/repo/issue-222-attach-baseline");
281
+ assert.equal(resolveBaselineRepo(" ", repo), "/repo/issue-222-attach-baseline");
282
+ assert.equal(resolveBaselineRepo("/baseline/abs", repo), "/baseline/abs");
283
+ assert.equal(resolveBaselineRepo("sibling", repo), resolve("sibling"), "relative values keep the path.resolve cwd semantics");
284
+ });
285
+ ```
286
+
287
+ - [ ] **Step 2: Run it and watch it fail**
288
+
289
+ Run: `node --test test/formal-runner-plan.test.mjs`
290
+ Expected: FAIL —— `resolveBaselineRepo is not a function`(或 import 报 undefined)。
291
+
292
+ - [ ] **Step 3: Implement the helper and wire the runner**
293
+
294
+ `formal-plan.mjs` 的 `node:path` 导入改为 `import { basename, join, resolve } from "node:path";`,并加:
295
+
296
+ ```js
297
+ // An empty or whitespace-only FORMAL_BASELINE_REPO is an unset variable, not
298
+ // the process cwd: resolve("") would silently re-root baseline hashing at the
299
+ // candidate repo.
300
+ export function resolveBaselineRepo(envValue, repo) {
301
+ return typeof envValue === "string" && envValue.trim() !== ""
302
+ ? resolve(envValue)
303
+ : resolve(repo, "../issue-222-attach-baseline");
304
+ }
305
+ ```
306
+
307
+ `formal-runner.mjs:20-22` 整段替换为:
308
+
309
+ ```js
310
+ const baselineRepo = resolveBaselineRepo(process.env.FORMAL_BASELINE_REPO, repo);
311
+ ```
312
+
313
+ 并在其导入区加入 `resolveBaselineRepo`(与现有 `formal-plan.mjs` 导入合并):
314
+
315
+ ```js
316
+ import { buildFormalPlan, buildReplacementPlan, classifyTrial, resolveBaselineRepo } from "./formal-plan.mjs";
317
+ ```
318
+
319
+ - [ ] **Step 4: Run the test — green, and the existing dry-run integration stays green**
320
+
321
+ Run: `node --test test/formal-runner-plan.test.mjs test/scenario-stdout-flush.test.mjs`
322
+ Expected: 全部 PASS(后者含真实 dry-run,证明非空值分支未被改坏)。
323
+
324
+ - [ ] **Step 5: Commit**
325
+
326
+ ```bash
327
+ git add test-support/formal-measurement/formal-plan.mjs test-support/formal-measurement/formal-runner.mjs test/formal-runner-plan.test.mjs
328
+ git commit -m "fix(test): treat a blank FORMAL_BASELINE_REPO as unset (issue #273)"
329
+ ```
330
+
331
+ ---
332
+
333
+ ### Task 5: Full gate (A8) and acceptance reconciliation
334
+
335
+ **Files:**
336
+ - Modify: 无(只在失败时回到对应 task)
337
+
338
+ **Interfaces:**
339
+ - Consumes: Task 1–4 的全部产物。
340
+ - Produces: `npm run verify` 的完整结果,作为 A8 证据。
341
+
342
+ - [ ] **Step 1: Run the full gate**
343
+
344
+ Run: `npm run verify`
345
+ Expected: typecheck + perf gate + tests + coverage(lines 85 / funcs 80 / branches 70)+ `pack:dry` 全部通过,exit 0。
346
+
347
+ - [ ] **Step 2: Reconcile the acceptance matrix**
348
+
349
+ 逐条记录实际命令与结果:
350
+
351
+ | ID | 证据 |
352
+ |---|---|
353
+ | A1 | `node --test test/scenario-stdout-flush.test.mjs`(样本) |
354
+ | A2 | 同文件全目录扫描 `offenders === []`;Task 1 Step 4 的六处红 |
355
+ | A3 | `node --test test/attach-frame-witness.integration.test.mjs` |
356
+ | A4 | 同 A1 文件的两路 smoke |
357
+ | A5 | 四个场景测试 + 各自 `endsWith("\n")` 断言 |
358
+ | A6 | 同 A1 文件的 256 KiB probe |
359
+ | A7 | `node --test test/formal-runner-plan.test.mjs` |
360
+ | A8 | `npm run verify` 输出 |
361
+
362
+ - [ ] **Step 3: Commit any plan/spec corrections found during implementation**
363
+
364
+ ```bash
365
+ git add docs/superpowers/plans/2026-11-09-issue-273-harness-console-log-exit.md
366
+ git commit -m "docs: correct the issue #273 plan after implementation"
367
+ ```
368
+
369
+ A9(PR 上 `Test (Node 22)` / `Test (Node 24)`)在步 9 完成后记录,不在本 plan 的本地步骤内。