@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,590 @@
1
+ # Issue #294 Snapshot Resize-Intent 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 a validated target-geometry F carried inside a snapshot (or a live ordinary frame following it) satisfy the resize intent, so differing-size attaches settle instead of sticking past the 2500 ms cap.
6
+
7
+ **Architecture:** One new pure predicate (`resizeIntentEvidenceFromRecords`) shared by both evidence sources (snapshot records array, live single record); a sticky evidence lifecycle in `PtyAttachComponent` (`resizeIntentSatisfied` + `resizeIntentProofSeq`, cleared only by a new intent / recomputed per accepted baseline); and an ordinary-head alternative inside the pure `fullViewDecision` gate. No runner, protocol, reporter, or degraded-chain changes.
8
+
9
+ **Tech Stack:** TypeScript + `.mjs` core modules, `node:test` + `assert/strict`, existing `test-support/attach-recovery-scenario.ts` virtual-clock harness.
10
+
11
+ **Spec:** `docs/superpowers/specs/2026-11-13-issue-294-snapshot-resize-intent-design.md` (cross-reviewed v4). Acceptance IDs referenced per task: A1a, A1b, A2a, A2b, A2c, A3, A4, U1.
12
+
13
+ ## Global Constraints
14
+
15
+ - Tabs for indentation; English comments and commit messages; conventional commit subjects (`fix`/`test`/`docs`/`chore`).
16
+ - Never weaken existing gates: wrong-size / wrong-revision / wrong-intent / stale evidence / wrong-non-zero revision-intent heads keep waiting (A1b/A3 pin this).
17
+ - Single-source matcher: live and snapshot evidence go through the same predicate; do NOT reintroduce a revision/intent-only branch.
18
+ - `invalidateViewProof` must no longer clear `resizeIntentSatisfied` (sticky evidence), and nothing else in it changes.
19
+ - Work from: `/home/elling/git-repo/github/pi-agent-board/.pi/worktrees/issue-294-snapshot-resize-intent` (all paths below are relative to it).
20
+ - Full gate: `npm run verify` (typecheck + perf gate + tests + coverage + pack:dry) must exit 0 before step 9.
21
+
22
+ ---
23
+
24
+ ### Task 1: Pure predicate `resizeIntentEvidenceFromRecords` (A1a)
25
+
26
+ **Files:**
27
+ - Modify: `src/core/pty-attach-render.mjs` (add export near `decideAttachPresentation`)
28
+ - Test: `test/pty-attach-render.test.mjs`
29
+
30
+ **Interfaces:**
31
+ - Consumes: `validateFrameMetadata` (already imported in `src/core/pty-attach-render.mjs` from `./attach-frame-proof.mjs`).
32
+ - Produces: `export function resizeIntentEvidenceFromRecords(intent, records)` where `intent = { required: boolean, geometryRevision: number, intentId: number, cols: number, rows: number }`, `records = unknown`; returns `{ satisfied: boolean, proofSeq: number | null }`.
33
+
34
+ - [ ] **Step 1: Write the failing tests** — append to `test/pty-attach-render.test.mjs` (extend the existing import from `"../src/core/pty-attach-render.mjs"` with `resizeIntentEvidenceFromRecords`):
35
+
36
+ ```js
37
+ // Issue #294 A1a: the single-source intent-evidence predicate.
38
+ const INTENT = { required: true, geometryRevision: 1, intentId: 1, cols: 100, rows: 30 };
39
+ const MATCH = (seq) => ({
40
+ marker: "F", seq, frameId: seq,
41
+ metadata: { protocol: 1, cols: 100, rows: 30, mode: "fullscreen", rendererEpoch: 1, sessionEpoch: 1, focusPresent: true, overlayPresent: false, intentId: 1, geometryRevision: 1 },
42
+ });
43
+
44
+ test("A1a: a fully matching F yields evidence with its seq (highest wins)", () => {
45
+ assert.deepEqual(resizeIntentEvidenceFromRecords(INTENT, [MATCH(2)]), { satisfied: true, proofSeq: 2 });
46
+ assert.deepEqual(resizeIntentEvidenceFromRecords(INTENT, [{ marker: "S", seq: 1, frameId: 1 }, MATCH(2), MATCH(5)]), { satisfied: true, proofSeq: 5 });
47
+ });
48
+
49
+ test("A1a: a non-required intent is vacuously satisfied without evidence", () => {
50
+ assert.deepEqual(resizeIntentEvidenceFromRecords({ ...INTENT, required: false }, []), { satisfied: true, proofSeq: null });
51
+ });
52
+
53
+ test("A1a: anything short of a full match fails closed", () => {
54
+ const notEvidence = [
55
+ [{ marker: "S", seq: 2, frameId: 2 }],
56
+ [{ marker: "A", seq: 2, frameId: 2, reason: "stop" }],
57
+ [{ ...MATCH(2), metadata: { ...MATCH(2).metadata, geometryRevision: 0 } }],
58
+ [{ ...MATCH(2), metadata: { ...MATCH(2).metadata, intentId: 0 } }],
59
+ [{ ...MATCH(2), metadata: { ...MATCH(2).metadata, intentId: 2 } }],
60
+ [{ ...MATCH(2), metadata: { ...MATCH(2).metadata, cols: 140 } }],
61
+ [{ ...MATCH(2), metadata: { ...MATCH(2).metadata, rows: 40 } }],
62
+ [{ ...MATCH(2), metadata: { ...MATCH(2).metadata, protocol: 2 } }],
63
+ [{ ...MATCH(2), metadata: { ...MATCH(2).metadata, extra: 1 } }],
64
+ [{ ...MATCH(2), seq: 0 }],
65
+ [{ ...MATCH(2), seq: 1.5 }],
66
+ [],
67
+ "not-an-array",
68
+ [null],
69
+ ];
70
+ for (const records of notEvidence) {
71
+ assert.deepEqual(resizeIntentEvidenceFromRecords(INTENT, records), { satisfied: false, proofSeq: null }, `records=${JSON.stringify(records)}`);
72
+ }
73
+ assert.deepEqual(resizeIntentEvidenceFromRecords(null, [MATCH(2)]), { satisfied: false, proofSeq: null });
74
+ });
75
+ ```
76
+
77
+ - [ ] **Step 2: Run to verify failure**
78
+
79
+ Run: `node --test test/pty-attach-render.test.mjs`
80
+ Expected: FAIL — `resizeIntentEvidenceFromRecords` is not exported.
81
+
82
+ - [ ] **Step 3: Implement** — add to `src/core/pty-attach-render.mjs`:
83
+
84
+ ```js
85
+ /**
86
+ * Issue #294: derive the resize-intent evidence from view-proof records.
87
+ * One matcher for every evidence source — snapshotReady's records array and
88
+ * the live single-record path both call this; no revision/intent-only
89
+ * shortcut may exist anywhere. Fail-closed: anything short of a fully
90
+ * matching target F yields no evidence.
91
+ * @param {{ required: boolean, geometryRevision: number, intentId: number, cols: number, rows: number } | null} intent
92
+ * @param {unknown} records
93
+ * @returns {{ satisfied: boolean, proofSeq: number | null }}
94
+ */
95
+ export function resizeIntentEvidenceFromRecords(intent, records) {
96
+ if (intent === null || typeof intent !== "object") return { satisfied: false, proofSeq: null };
97
+ if (intent.required !== true) return { satisfied: true, proofSeq: null };
98
+ if (!Array.isArray(records)) return { satisfied: false, proofSeq: null };
99
+ let best = null;
100
+ for (const record of records) {
101
+ if (record === null || typeof record !== "object") continue;
102
+ if (record.marker !== "F") continue;
103
+ if (!Number.isInteger(record.seq) || record.seq < 1) continue;
104
+ const validation = validateFrameMetadata(record.metadata);
105
+ if (!validation.ok) continue;
106
+ const metadata = validation.value;
107
+ if (metadata.geometryRevision !== intent.geometryRevision) continue;
108
+ if (metadata.intentId !== intent.intentId) continue;
109
+ if (metadata.cols !== intent.cols || metadata.rows !== intent.rows) continue;
110
+ if (best === null || record.seq > best) best = record.seq;
111
+ }
112
+ return best === null ? { satisfied: false, proofSeq: null } : { satisfied: true, proofSeq: best };
113
+ }
114
+ ```
115
+
116
+ - [ ] **Step 4: Run to verify pass**
117
+
118
+ Run: `node --test test/pty-attach-render.test.mjs`
119
+ Expected: PASS (all, including pre-existing).
120
+
121
+ - [ ] **Step 5: Commit**
122
+
123
+ ```bash
124
+ git add src/core/pty-attach-render.mjs test/pty-attach-render.test.mjs
125
+ git commit -m "feat(attach): single-source resize-intent evidence predicate (issue #294)"
126
+ ```
127
+
128
+ ---
129
+
130
+ ### Task 2: Ordinary-head bypass in `fullViewDecision` (A1b)
131
+
132
+ **Files:**
133
+ - Modify: `src/core/pty-attach-render.mjs` (`fullViewDecision`, the `requiredGeometryRevision` + intent blocks)
134
+ - Test: `test/pty-attach-render-decision.test.mjs`
135
+
136
+ **Interfaces:**
137
+ - Consumes: Task 1's predicate semantics (state field `resizeIntentProofSeq: number | null`, passed by the component in Task 4).
138
+ - Produces: `decideAttachPresentation` accepts `resizeIntentProofSeq`; publishes `complete` when the head is ordinary (0/0) at target dims with fresh evidence.
139
+
140
+ - [ ] **Step 1: Write the failing tests** — append to `test/pty-attach-render-decision.test.mjs` (reuse the file's existing `view(over)` helper; `META`/`COVERED` are the file's constants):
141
+
142
+ ```js
143
+ // Issue #294 A1b: the intent-evidence / ordinary-head alternative.
144
+ const ORD_HEAD = { ...META, intentId: 0, geometryRevision: 0 };
145
+ const ordCovered = () => ({
146
+ ...COVERED,
147
+ proof: { ...COVERED.proof, metadata: ORD_HEAD },
148
+ throughSeq: 10,
149
+ });
150
+ const armed = (over = {}) => view({
151
+ resizeIntentRequired: true,
152
+ resizeIntentSatisfied: true,
153
+ resizeIntentProofSeq: 9,
154
+ intentId: 7,
155
+ viewProof: ordCovered(),
156
+ ...over,
157
+ });
158
+
159
+ test("A1b: fresh evidence + ordinary 0/0 head at target dims publishes", () => {
160
+ assert.deepEqual(decide(armed()), { action: "publish", reason: "complete" });
161
+ });
162
+
163
+ test("A1b: no evidence / not satisfied keeps the original waits", () => {
164
+ assert.deepEqual(decide(armed({ viewProof: COVERED, resizeIntentProofSeq: undefined })), { action: "wait", reason: "resize-intent" });
165
+ assert.deepEqual(decide(armed({ viewProof: COVERED, resizeIntentSatisfied: false })), { action: "wait", reason: "resize-intent" });
166
+ assert.deepEqual(decide(view({ resizeIntentRequired: true, resizeIntentSatisfied: false, intentId: 7, viewProof: COVERED })), { action: "wait", reason: "resize-intent" });
167
+ // Gate order pin: an ordinary 0/0 head WITHOUT evidence stops at the earlier geometry-revision gate.
168
+ assert.deepEqual(decide(view({ resizeIntentRequired: true, resizeIntentSatisfied: false, intentId: 7, viewProof: ordCovered() })), { action: "wait", reason: "geometry-revision" });
169
+ });
170
+
171
+ test("A1b: stale evidence (proofSeq > throughSeq) keeps waiting on the head checks", () => {
172
+ assert.deepEqual(decide(armed({ viewProof: ordCovered() , resizeIntentProofSeq: 11 })), { action: "wait", reason: "geometry-revision" });
173
+ });
174
+
175
+ test("A1b: a wrong-non-zero head is NOT ordinary — gates stay even with valid evidence", () => {
176
+ assert.deepEqual(decide(armed({ viewProof: { ...ordCovered(), proof: { ...ordCovered().proof, metadata: { ...ORD_HEAD, geometryRevision: 5 } } } })), { action: "wait", reason: "geometry-revision" });
177
+ assert.deepEqual(decide(armed({ viewProof: { ...COVERED, proof: { ...COVERED.proof, metadata: { ...META, intentId: 3 } } } })), { action: "wait", reason: "resize-intent" });
178
+ });
179
+
180
+ test("A1b: a wrong-size ordinary head still waits on proof-geometry-mismatch", () => {
181
+ assert.deepEqual(decide(armed({ viewProof: { ...ordCovered(), proof: { ...ordCovered().proof, metadata: { ...ORD_HEAD, cols: 140 } } } })), { action: "wait", reason: "proof-geometry-mismatch" });
182
+ });
183
+
184
+ test("A1b: a head carrying the intent itself keeps the original publish path", () => {
185
+ const intentMeta = { ...META, intentId: 7, geometryRevision: 2 };
186
+ assert.deepEqual(decide(armed({ viewProof: { ...COVERED, proof: { ...COVERED.proof, metadata: intentMeta } } })), { action: "publish", reason: "complete" });
187
+ });
188
+ ```
189
+
190
+ Note: `view()`'s base has `targetCols: 80, targetRows: 24, geometryRevision: 2, requiredGeometryRevision: 2` and `META.geometryRevision: 2` — `armed()` overrides `intentId: 7` and uses the ordinary head (0/0), so `requiredGeometryRevision !== undefined && metadata.geometryRevision(0) !== 2` must be bypassed for the first test to pass. Adjust the helper names/overrides only if the file's actual base differs; do not weaken the asserts.
191
+
192
+ - [ ] **Step 2: Run to verify failure**
193
+
194
+ Run: `node --test test/pty-attach-render-decision.test.mjs`
195
+ Expected: the "fresh evidence + ordinary head publishes" test FAILs with `geometry-revision`; the wrong-non-zero ones may initially pass for the wrong reason.
196
+
197
+ - [ ] **Step 3: Implement** — in `src/core/pty-attach-render.mjs` `fullViewDecision`, replace the two checks:
198
+
199
+ ```js
200
+ if (state.requiredGeometryRevision !== undefined && metadata.value.geometryRevision !== state.requiredGeometryRevision) return wait("geometry-revision");
201
+ if (state.resizeIntentRequired === true) {
202
+ if (state.resizeIntentSatisfied !== true) return wait("resize-intent");
203
+ if (metadata.value.intentId !== state.intentId || metadata.value.intentId === 0) return wait("resize-intent");
204
+ }
205
+ ```
206
+
207
+ with:
208
+
209
+ ```js
210
+ // Issue #294: a validated intent proof (snapshot-carried or live) that is
211
+ // fresh against the covered window, plus an ordinary post-intent (0/0)
212
+ // coverage head at the target size, is an acceptable alternative to the
213
+ // head itself carrying the intent metadata. Everything else fails closed
214
+ // to the original waits.
215
+ const intentEvidenceHeadOk =
216
+ state.resizeIntentRequired === true &&
217
+ state.resizeIntentSatisfied === true &&
218
+ Number.isInteger(state.resizeIntentProofSeq) &&
219
+ state.resizeIntentProofSeq <= coverage.throughSeq &&
220
+ metadata.value.intentId === 0 &&
221
+ metadata.value.geometryRevision === 0 &&
222
+ metadata.value.cols === state.targetCols &&
223
+ metadata.value.rows === state.targetRows;
224
+ if (state.requiredGeometryRevision !== undefined && metadata.value.geometryRevision !== state.requiredGeometryRevision && !intentEvidenceHeadOk) return wait("geometry-revision");
225
+ if (state.resizeIntentRequired === true) {
226
+ if (state.resizeIntentSatisfied !== true) return wait("resize-intent");
227
+ const headCarriesIntent = metadata.value.intentId === state.intentId && metadata.value.intentId !== 0;
228
+ if (!headCarriesIntent && !intentEvidenceHeadOk) return wait("resize-intent");
229
+ }
230
+ ```
231
+
232
+ Also extend the JSDoc `@param` state comment above `decideAttachPresentation` with `resizeIntentProofSeq?: number,`.
233
+
234
+ - [ ] **Step 4: Run to verify pass**
235
+
236
+ Run: `node --test test/pty-attach-render-decision.test.mjs`
237
+ Expected: PASS (all, including the pre-existing intent tests — they pass `resizeIntentProofSeq` never, so `intentEvidenceHeadOk` is false for them).
238
+
239
+ - [ ] **Step 5: Commit**
240
+
241
+ ```bash
242
+ git add src/core/pty-attach-render.mjs test/pty-attach-render-decision.test.mjs
243
+ git commit -m "feat(attach): ordinary-head intent-evidence alternative in the publish gate (issue #294)"
244
+ ```
245
+
246
+ ---
247
+
248
+ ### Task 3: Harness observability — `protocolErrorCount` + `coverageHead` (enables A2c)
249
+
250
+ **Files:**
251
+ - Modify: `test-support/attach-recovery-scenario.ts`
252
+
253
+ **Interfaces:**
254
+ - Produces: two new step-readout fields: `protocolErrorCount` (number) and `coverageHead` (`{ seq, frameId, intentId, geometryRevision, cols, rows } | null`).
255
+
256
+ - [ ] **Step 1: Implement** — in `createHarness`, after the component is constructed, wrap `handleAttachEvent` (the channel every client event — including `protocolError` — flows through; `installSpy` in the same file is the precedent):
257
+
258
+ ```ts
259
+ const protocolErrors: unknown[] = [];
260
+ const originalHandleAttachEvent = (component as any).handleAttachEvent.bind(component);
261
+ (component as any).handleAttachEvent = (event: string, payload?: unknown) => {
262
+ if (event === "protocolError") protocolErrors.push(payload ?? null);
263
+ return originalHandleAttachEvent(event, payload);
264
+ };
265
+ ```
266
+
267
+ Return `protocolErrors` from `createHarness` (add to the returned object). In `readout(h, state)` add:
268
+
269
+ ```ts
270
+ const proof = (c.latestViewProof as { proof?: Record<string, unknown> | null } | null)?.proof;
271
+ const headMeta = (proof?.metadata ?? {}) as Record<string, unknown>;
272
+ // ...inside the returned object:
273
+ protocolErrorCount: h.protocolErrors.length,
274
+ coverageHead: proof === null || proof === undefined || typeof proof !== "object" ? null : {
275
+ seq: (proof as { seq?: unknown }).seq ?? null,
276
+ frameId: (proof as { frameId?: unknown }).frameId ?? null,
277
+ intentId: headMeta.intentId ?? null,
278
+ geometryRevision: headMeta.geometryRevision ?? null,
279
+ cols: headMeta.cols ?? null,
280
+ rows: headMeta.rows ?? null,
281
+ },
282
+ ```
283
+
284
+ (Adapt to the file's actual structure: `readout` already destructures `h`; `Harness` type picks up the new field automatically via `ReturnType`.)
285
+
286
+ - [ ] **Step 2: Verify with the existing research program**
287
+
288
+ Run: `node --experimental-transform-types test-support/attach-recovery-scenario.ts "$(cat /home/elling/.github-issue-driven/zhuxixi/pi-agent-board/issue-294/research/repro-live-f0-after.json)" 2>/dev/null | tail -1` then pipe through `node -e '...'` to print `protocolErrorCount` and `coverageHead` per step.
289
+ Expected: all steps `protocolErrorCount: 0`; after the F0 record step, `coverageHead` = `{ seq: 3, frameId: 3, intentId: 0, geometryRevision: 0, cols: 100, rows: 30 }`.
290
+
291
+ - [ ] **Step 3: Run the existing component suite to prove no regression**
292
+
293
+ Run: `node --test test/attach-recovery-component.test.mjs`
294
+ Expected: PASS.
295
+
296
+ - [ ] **Step 4: Commit**
297
+
298
+ ```bash
299
+ git add test-support/attach-recovery-scenario.ts
300
+ git commit -m "test(attach): protocolError and coverageHead readouts in the recovery harness (issue #294)"
301
+ ```
302
+
303
+ ---
304
+
305
+ ### Task 4: Component wiring + component tests (A2a, A2b, A2c, A3)
306
+
307
+ **Files:**
308
+ - Modify: `src/ui/pty-attach.ts` (field ~`:476`, `noteGeometryIntent` ~`:2541`, `snapshotReady` ~`:2918`, `viewProofRecord` branch ~`:2982-2992`, `invalidateViewProof` ~`:1520-1525`, decision-facts assembly ~`:1677-1680`, import line `:14`)
309
+ - Test: `test/attach-recovery-component.test.mjs`
310
+
311
+ **Interfaces:**
312
+ - Consumes: Task 1 `resizeIntentEvidenceFromRecords`; Task 2 state field `resizeIntentProofSeq`; Task 3 readout fields.
313
+ - Produces: sticky evidence lifecycle per spec §2.
314
+
315
+ - [ ] **Step 1: Write the failing component tests** — append to `test/attach-recovery-component.test.mjs`, following the file's `runScenario`/`readouts`/`assertScenarioOk` pattern (see T8 at `:1298` for the geometry-gate precedent). Reuse these step-program builders (metadata literals as in T8's `target`):
316
+
317
+ ```js
318
+ // Issue #294: the target after a differing resize to 100x30 — revision 1, intent 1.
319
+ const i294Target = { protocol: 1, cols: 100, rows: 30, mode: "fullscreen", rendererEpoch: 1, sessionEpoch: 1, focusPresent: true, overlayPresent: false, intentId: 1, geometryRevision: 1 };
320
+ const i294Ord = { ...i294Target, intentId: 0, geometryRevision: 0 };
321
+ const i294F = (metadata, seq) => ({ marker: "F", seq, frameId: seq, metadata });
322
+ const i294Covered = (proof, throughSeq) => ({ status: "covered", reason: "exact-proof", proof, throughSeq, cursorVisible: true });
323
+ ```
324
+
325
+ Test A2a (snapshot-carried target F, head = target F):
326
+
327
+ ```js
328
+ test("A2a (#294): a snapshot-carried target F settles like the live control", () => {
329
+ const run = runScenario({
330
+ steps: [
331
+ { op: "connect" },
332
+ { op: "hello", witness: true, generation: "gen-1" },
333
+ { op: "snapshot", proof: "unavailable-candidate-open", text: "I294 80" },
334
+ { op: "geometry", cols: 100, rows: 30 },
335
+ { op: "snapshot", resnapshot: true, generation: "gen-2", text: "I294 100", beginSeq: 2,
336
+ records: [i294F(i294Target, 2)],
337
+ proof: i294Covered(i294F(i294Target, 2), 2) },
338
+ { op: "advance", ms: 2500 },
339
+ ],
340
+ });
341
+ assertScenarioOk("i294-a2a", run);
342
+ const [afterResnapshot, afterAdvance] = readouts(run.parsed).slice(4);
343
+ assert.equal(afterResnapshot.attaching, false, "settles at the hydration commit");
344
+ assert.equal(afterResnapshot.readyReason, "complete");
345
+ assert.equal(afterResnapshot.settledAt, 0);
346
+ assert.equal(afterAdvance.attaching, false, "stays settled");
347
+ });
348
+ ```
349
+
350
+ Test A2b (capture window F1+F0, head = F0):
351
+
352
+ ```js
353
+ test("A2b (#294): target F + ordinary F0 in the capture window, coverage head F0, settles", () => {
354
+ const run = runScenario({
355
+ steps: [
356
+ { op: "connect" },
357
+ { op: "hello", witness: true, generation: "gen-1" },
358
+ { op: "snapshot", proof: "unavailable-candidate-open", text: "I294 80" },
359
+ { op: "geometry", cols: 100, rows: 30 },
360
+ { op: "snapshot", resnapshot: true, generation: "gen-2", text: "I294 100", beginSeq: 2,
361
+ records: [i294F(i294Target, 2), i294F(i294Ord, 2)],
362
+ proof: i294Covered(i294F(i294Ord, 2), 2) },
363
+ { op: "advance", ms: 2500 },
364
+ ],
365
+ });
366
+ assertScenarioOk("i294-a2b", run);
367
+ const [afterResnapshot] = readouts(run.parsed).slice(4);
368
+ assert.equal(afterResnapshot.attaching, false);
369
+ assert.equal(afterResnapshot.readyReason, "complete");
370
+ });
371
+ ```
372
+
373
+ Test A2c (real ordinary frame after the snapshot):
374
+
375
+ ```js
376
+ test("A2c (#294): real output -> S0 -> F0 after the snapshot settles via the evidence bypass", () => {
377
+ const run = runScenario({
378
+ steps: [
379
+ { op: "connect" },
380
+ { op: "hello", witness: true, generation: "gen-1" },
381
+ { op: "snapshot", proof: "unavailable-candidate-open", text: "I294 80" },
382
+ { op: "geometry", cols: 100, rows: 30 },
383
+ { op: "snapshot", resnapshot: true, generation: "gen-2", text: "I294 100", beginSeq: 2,
384
+ records: [i294F(i294Target, 2)],
385
+ proof: { status: "unknown", reason: "candidate-open", proof: null, throughSeq: null, cursorVisible: null } },
386
+ { op: "output", seq: 3, text: "POST-SNAPSHOT OUTPUT" },
387
+ { op: "record", marker: "S", seq: 3, frameId: 3 },
388
+ { op: "record", marker: "F", seq: 3, metadata: i294Ord },
389
+ ],
390
+ });
391
+ assertScenarioOk("i294-a2c", run);
392
+ const [afterOutput, afterS0, afterF0] = readouts(run.parsed).slice(5);
393
+ assert.equal(afterOutput.protocolErrorCount, 0);
394
+ assert.equal(afterS0.protocolErrorCount, 0);
395
+ assert.equal(afterS0.latestViewProof.reason, "candidate-open", "S0 opens a candidate");
396
+ assert.equal(afterF0.protocolErrorCount, 0);
397
+ assert.deepEqual(afterF0.coverageHead, { seq: 3, frameId: 3, intentId: 0, geometryRevision: 0, cols: 100, rows: 30 });
398
+ assert.equal(afterF0.attaching, false, "the ordinary head publishes via fresh evidence");
399
+ assert.equal(afterF0.readyReason, "complete");
400
+ });
401
+ ```
402
+
403
+ Test A3 (negatives; one test per group):
404
+
405
+ ```js
406
+ test("A3-1 (#294): snapshot-carried wrong-dims/revision/intent F records keep the gate", () => {
407
+ for (const bad of [
408
+ { ...i294Target, cols: 140 },
409
+ { ...i294Target, geometryRevision: 0 },
410
+ { ...i294Target, intentId: 0 },
411
+ ]) {
412
+ const run = runScenario({
413
+ steps: [
414
+ { op: "connect" },
415
+ { op: "hello", witness: true, generation: "gen-1" },
416
+ { op: "snapshot", proof: "unavailable-candidate-open", text: "I294 80" },
417
+ { op: "geometry", cols: 100, rows: 30 },
418
+ { op: "snapshot", resnapshot: true, generation: "gen-2", text: "I294 100", beginSeq: 2,
419
+ records: [i294F(bad, 2)],
420
+ proof: { status: "unknown", reason: "candidate-open", proof: null, throughSeq: null, cursorVisible: null } },
421
+ { op: "advance", ms: 250 },
422
+ { op: "advance", ms: 2250 },
423
+ { op: "record", marker: "F", seq: 3, metadata: i294Target },
424
+ ],
425
+ });
426
+ assertScenarioOk("i294-a3n", run);
427
+ const [atBudget, atCap, afterRescue] = readouts(run.parsed).slice(5);
428
+ assert.equal(atBudget.attaching, true, `bad=${JSON.stringify(bad)} waits at budget`);
429
+ assert.equal(atCap.attaching, true);
430
+ assert.equal(atCap.deadlineState, "expired");
431
+ assert.equal(afterRescue.attaching, false, "a real live target F still rescues");
432
+ assert.equal(afterRescue.readyReason, "complete");
433
+ }
434
+ });
435
+
436
+ test("A3-2 (#294): no evidence — live S0/F0 keeps waiting as today", () => {
437
+ const run = runScenario({
438
+ steps: [
439
+ { op: "connect" },
440
+ { op: "hello", witness: true, generation: "gen-1" },
441
+ { op: "snapshot", proof: "unavailable-candidate-open", text: "I294 80" },
442
+ { op: "geometry", cols: 100, rows: 30 },
443
+ { op: "snapshot", resnapshot: true, generation: "gen-2", text: "I294 100", beginSeq: 2,
444
+ proof: { status: "unknown", reason: "candidate-open", proof: null, throughSeq: null, cursorVisible: null } },
445
+ { op: "output", seq: 3, text: "POST-SNAPSHOT OUTPUT" },
446
+ { op: "record", marker: "S", seq: 3, frameId: 3 },
447
+ { op: "record", marker: "F", seq: 3, metadata: i294Ord },
448
+ { op: "advance", ms: 250 },
449
+ { op: "advance", ms: 2250 },
450
+ ],
451
+ });
452
+ assertScenarioOk("i294-a3-2", run);
453
+ const final = run.parsed.final;
454
+ assert.equal(final.attaching, true, "no evidence -> ordinary F0 head keeps waiting");
455
+ assert.equal(final.deadlineState, "expired");
456
+ });
457
+
458
+ test("A3-3 (#294): a second differing resize clears the old evidence", () => {
459
+ const run = runScenario({
460
+ steps: [
461
+ { op: "connect" },
462
+ { op: "hello", witness: true, generation: "gen-1" },
463
+ { op: "snapshot", proof: "unavailable-candidate-open", text: "I294 80" },
464
+ { op: "geometry", cols: 100, rows: 30 },
465
+ { op: "snapshot", resnapshot: true, generation: "gen-2", text: "I294 100", beginSeq: 2,
466
+ records: [i294F(i294Target, 2)],
467
+ proof: i294Covered(i294F(i294Target, 2), 2) },
468
+ { op: "geometry", cols: 120, rows: 40 },
469
+ { op: "snapshot", resnapshot: true, generation: "gen-3", cols: 120, rows: 40, text: "I294 120", beginSeq: 3,
470
+ proof: { status: "unknown", reason: "candidate-open", proof: null, throughSeq: null, cursorVisible: null } },
471
+ { op: "output", seq: 4, text: "MORE OUTPUT" },
472
+ { op: "record", marker: "F", seq: 4, metadata: { ...i294Ord, cols: 120, rows: 40 } },
473
+ { op: "advance", ms: 2500 },
474
+ ],
475
+ });
476
+ assertScenarioOk("i294-a3-3", run);
477
+ const final = run.parsed.final;
478
+ assert.equal(final.attaching, true, "superseded evidence must not publish the new intent");
479
+ });
480
+
481
+ test("A3-4 (#294): live wrong-dims F1 -> S0 -> target F0 does not publish", () => {
482
+ const run = runScenario({
483
+ steps: [
484
+ { op: "connect" },
485
+ { op: "hello", witness: true, generation: "gen-1" },
486
+ { op: "snapshot", proof: "unavailable-candidate-open", text: "I294 80" },
487
+ { op: "geometry", cols: 100, rows: 30 },
488
+ { op: "snapshot", resnapshot: true, generation: "gen-2", text: "I294 100", beginSeq: 2,
489
+ proof: { status: "unknown", reason: "candidate-open", proof: null, throughSeq: null, cursorVisible: null } },
490
+ { op: "record", marker: "F", seq: 2, metadata: { ...i294Target, cols: 140 } },
491
+ { op: "output", seq: 3, text: "POST OUTPUT" },
492
+ { op: "record", marker: "S", seq: 3, frameId: 3 },
493
+ { op: "record", marker: "F", seq: 3, metadata: i294Ord },
494
+ { op: "advance", ms: 250 },
495
+ { op: "advance", ms: 2250 },
496
+ ],
497
+ });
498
+ assertScenarioOk("i294-a3-4", run);
499
+ const final = run.parsed.final;
500
+ assert.equal(final.attaching, true, "wrong-dims live F1 is not evidence");
501
+ assert.equal(final.deadlineState, "expired");
502
+ });
503
+ ```
504
+
505
+ - [ ] **Step 2: Run to verify failures**
506
+
507
+ Run: `node --test test/attach-recovery-component.test.mjs`
508
+ Expected: A2a/A2b/A2c FAIL (stuck at `resize-intent`), A3-2/A3-3/A3-4 PASS on current main (they pin today's behavior; A3-1's rescue assertion FAILs because the rescue F arrives post-cap — if the rescue assertion is the only failure there, that is expected to flip once wired).
509
+
510
+ - [ ] **Step 3: Implement the wiring** — in `src/ui/pty-attach.ts`:
511
+
512
+ 1. Import: extend line 14's import list with `resizeIntentEvidenceFromRecords`.
513
+ 2. Field (next to `resizeIntentSatisfied` ~`:475`):
514
+
515
+ ```ts
516
+ private resizeIntentProofSeq: number | null = null;
517
+ ```
518
+
519
+ 3. `invalidateViewProof` (~`:1520-1525`): delete the line `this.resizeIntentSatisfied = false;` (leave the coverage resets; add the comment `// Issue #294: intent evidence is sticky — see noteGeometryIntent/snapshotReady/viewProofRecord.`).
520
+ 4. `noteGeometryIntent` (~`:2541`): after `this.resizeIntentSatisfied = false;` add `this.resizeIntentProofSeq = null;`.
521
+ 5. `snapshotReady` (~`:2918`): replace `this.resizeIntentSatisfied = false;` with:
522
+
523
+ ```ts
524
+ const evidence = resizeIntentEvidenceFromRecords(
525
+ { required: this.resizeIntentRequired, geometryRevision: this.geometryRevision, intentId: this.resizeIntentId, cols: this.cols, rows: this.rows },
526
+ records,
527
+ );
528
+ this.resizeIntentSatisfied = evidence.satisfied;
529
+ this.resizeIntentProofSeq = evidence.proofSeq;
530
+ ```
531
+
532
+ 6. `viewProofRecord` branch (~`:2982-2992`): replace the `if (record.marker === "F") { ... }` body with:
533
+
534
+ ```ts
535
+ if (record.marker === "F") {
536
+ // Issue #294: one matcher for every evidence source — a live F
537
+ // re-evaluates through the same pure predicate (full validation
538
+ // incl. target dims); a non-match leaves the evidence untouched.
539
+ const evidence = resizeIntentEvidenceFromRecords(
540
+ { required: this.resizeIntentRequired, geometryRevision: this.geometryRevision, intentId: this.resizeIntentId, cols: this.cols, rows: this.rows },
541
+ [record],
542
+ );
543
+ if (evidence.satisfied) {
544
+ this.resizeIntentSatisfied = true;
545
+ this.resizeIntentProofSeq = evidence.proofSeq;
546
+ }
547
+ }
548
+ ```
549
+
550
+ 7. Decision-facts assembly (~`:1677-1680`): add `resizeIntentProofSeq: this.resizeIntentProofSeq,` after `resizeIntentSatisfied`.
551
+
552
+ - [ ] **Step 4: Run to verify pass**
553
+
554
+ Run: `node --test test/attach-recovery-component.test.mjs`
555
+ Expected: PASS (all, including the pre-existing T8 geometry-gate test — its wrong-F sequence never creates evidence).
556
+
557
+ - [ ] **Step 5: Typecheck**
558
+
559
+ Run: `npm run typecheck`
560
+ Expected: exit 0.
561
+
562
+ - [ ] **Step 6: Commit**
563
+
564
+ ```bash
565
+ git add src/ui/pty-attach.ts test/attach-recovery-component.test.mjs
566
+ git commit -m "fix(attach): satisfy resize intent from snapshot-carried and live evidence (issue #294)"
567
+ ```
568
+
569
+ ---
570
+
571
+ ### Task 5: Full regression gate (A4)
572
+
573
+ **Files:** none (verification only; fixes if genuinely caused by this change).
574
+
575
+ - [ ] **Step 1: Run the full gate**
576
+
577
+ Run: `npm run verify`
578
+ Expected: exit 0 (typecheck + perf gate + tests + coverage + pack:dry). If the known-flaky `attach-entry-22` 200 ms wall-clock assertion fails (`#95`), rerun once to confirm flake vs regression; do NOT weaken assertions. Any other failure is a regression from this change: fix and re-run.
579
+
580
+ - [ ] **Step 2: Commit** (only if fixes were needed)
581
+
582
+ ```bash
583
+ git add -u && git commit -m "fix(attach): verify-gate fallout from issue #294 wiring"
584
+ ```
585
+
586
+ ---
587
+
588
+ ### Task 6: U1 handoff (post-merge manual verification — not implementable now)
589
+
590
+ U1 executes only after merge + deployment (see spec §U1): pull `~/.pi/agent/git/github.com/zhuxixi/pi-agent-board`, restart pi, differing-size attach, check `diagnostics.jsonl`. It is tracked on the issue, not in this plan's tasks; do not mark it done here.