@zhuxixi/pi-agent-board 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +37 -12
  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-26-issue-245-key-hints-doc-sync.md +244 -0
  6. package/docs/superpowers/plans/2026-10-27-issue-172-fullscreen-selection-clear.md +344 -0
  7. package/docs/superpowers/plans/2026-10-27-issue-252-select-key-hints.md +209 -0
  8. package/docs/superpowers/plans/2026-10-28-issue-255-coordinator-endpoint-zombie.md +442 -0
  9. package/docs/superpowers/plans/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup.md +256 -0
  10. package/docs/superpowers/plans/2026-11-03-cwd-favorites-full-pool.md +266 -0
  11. package/docs/superpowers/plans/2026-11-03-issue-266-alt-h-detach.md +467 -0
  12. package/docs/superpowers/plans/2026-11-04-issue-270-scenario-stdout-flush.md +584 -0
  13. package/docs/superpowers/plans/2026-11-05-issue-278-ctrl-g-external-editor.md +381 -0
  14. package/docs/superpowers/plans/2026-11-06-issue-280-frame-witness-delivery.md +430 -0
  15. package/docs/superpowers/plans/2026-11-07-issue-284-attach-recovery.md +115 -0
  16. package/docs/superpowers/plans/2026-11-07-issue-284-u1-u2-trial-guide.md +39 -0
  17. package/docs/superpowers/plans/2026-11-08-host-restart-model-override.md +894 -0
  18. package/docs/superpowers/plans/2026-11-08-issue-288-cap-floor.md +51 -0
  19. package/docs/superpowers/plans/2026-11-09-dashboard-fold-flake.md +166 -0
  20. package/docs/superpowers/plans/2026-11-09-issue-273-harness-console-log-exit.md +369 -0
  21. package/docs/superpowers/plans/2026-11-10-issue-258-board-selection-settle.md +760 -0
  22. package/docs/superpowers/plans/2026-11-13-issue-294-snapshot-resize-intent.md +590 -0
  23. package/docs/superpowers/plans/2026-11-16-greeting-title-poll.md +838 -0
  24. package/docs/superpowers/plans/2026-11-22-issue-297-compaction-mirror.md +797 -0
  25. package/docs/superpowers/plans/2026-11-23-issue-254-cursor-keep-position.md +663 -0
  26. package/docs/superpowers/plans/2026-11-23-issue-95-legacy-quarantine.md +320 -0
  27. package/docs/superpowers/specs/2026-10-23-issue-222-attach-ready-design.md +204 -0
  28. package/docs/superpowers/specs/2026-10-26-issue-245-key-hints-doc-sync-design.md +72 -0
  29. package/docs/superpowers/specs/2026-10-27-issue-172-fullscreen-selection-clear-design.md +248 -0
  30. package/docs/superpowers/specs/2026-10-27-issue-252-select-key-hints-design.md +95 -0
  31. package/docs/superpowers/specs/2026-10-28-issue-255-coordinator-endpoint-zombie-design.md +380 -0
  32. package/docs/superpowers/specs/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup-design.md +197 -0
  33. package/docs/superpowers/specs/2026-11-03-cwd-favorites-full-pool-design.md +106 -0
  34. package/docs/superpowers/specs/2026-11-03-issue-266-alt-h-detach-design.md +185 -0
  35. package/docs/superpowers/specs/2026-11-04-issue-270-scenario-stdout-flush-design.md +176 -0
  36. package/docs/superpowers/specs/2026-11-05-issue-278-ctrl-g-external-editor-design.md +185 -0
  37. package/docs/superpowers/specs/2026-11-07-issue-284-attach-recovery-design.md +166 -0
  38. package/docs/superpowers/specs/2026-11-08-host-restart-model-override-design.md +115 -0
  39. package/docs/superpowers/specs/2026-11-08-issue-288-cap-floor-design.md +86 -0
  40. package/docs/superpowers/specs/2026-11-09-dashboard-fold-flake-design.md +109 -0
  41. package/docs/superpowers/specs/2026-11-09-issue-273-harness-console-log-exit-design.md +182 -0
  42. package/docs/superpowers/specs/2026-11-10-issue-258-board-selection-settle-design.md +109 -0
  43. package/docs/superpowers/specs/2026-11-13-issue-294-snapshot-resize-intent-design.md +141 -0
  44. package/docs/superpowers/specs/2026-11-16-greeting-title-poll-design.md +174 -0
  45. package/docs/superpowers/specs/2026-11-22-issue-297-compaction-mirror-design.md +158 -0
  46. package/docs/superpowers/specs/2026-11-22-issue-95-legacy-quarantine-design.md +209 -0
  47. package/docs/superpowers/specs/2026-11-23-issue-254-cursor-keep-position-design.md +201 -0
  48. package/package.json +1 -1
  49. package/runner/pty-runner.mjs +526 -63
  50. package/runner/state-coordinator.mjs +62 -5
  51. package/runner/title-runner.mjs +33 -24
  52. package/src/commands/agent-board.ts +5 -1
  53. package/src/core/attach-detach.mjs +27 -0
  54. package/src/core/attach-frame-proof.mjs +897 -0
  55. package/src/core/attach-frame-reporter.mjs +738 -0
  56. package/src/core/attach-frame-stream.mjs +266 -0
  57. package/src/core/attach-pr-label.mjs +12 -0
  58. package/src/core/attach-recovery.mjs +239 -0
  59. package/src/core/attach-screen-owner.mjs +55 -0
  60. package/src/core/attach-view-proof.mjs +709 -0
  61. package/src/core/auto-state.mjs +6 -1
  62. package/src/core/cwd-stats.mjs +3 -1
  63. package/src/core/dashboard-prefs.mjs +31 -0
  64. package/src/core/derive.mjs +8 -1
  65. package/src/core/events.mjs +127 -1
  66. package/src/core/foreground-projection-cache.mjs +1 -0
  67. package/src/core/frame-witness-update.mjs +35 -0
  68. package/src/core/fullscreen-selection.mjs +60 -0
  69. package/src/core/host-coordination.mjs +48 -0
  70. package/src/core/host-protocol.mjs +13 -2
  71. package/src/core/hosted-frame-witness.mjs +60 -0
  72. package/src/core/paths.mjs +10 -3
  73. package/src/core/pty-attach-render.mjs +239 -0
  74. package/src/core/pty-kitty-images.mjs +237 -0
  75. package/src/core/pty-scroll.mjs +8 -8
  76. package/src/core/rows.mjs +43 -7
  77. package/src/core/session-entries.mjs +82 -0
  78. package/src/core/session-launch-prefs.mjs +45 -0
  79. package/src/core/session-view.mjs +3 -63
  80. package/src/core/store.mjs +1 -0
  81. package/src/core/terminal-attach-client.mjs +199 -20
  82. package/src/core/terminal-attach-protocol.mjs +221 -7
  83. package/src/core/terminal-model.mjs +24 -3
  84. package/src/core/terminal-snapshot.mjs +10 -0
  85. package/src/core/title-flow.mjs +66 -0
  86. package/src/core/title.mjs +101 -0
  87. package/src/core/types.mjs +17 -0
  88. package/src/index.ts +85 -0
  89. package/src/runtime/service.mjs +87 -18
  90. package/src/ui/dashboard.ts +206 -49
  91. package/src/ui/pty-attach.ts +1472 -99
@@ -0,0 +1,381 @@
1
+ # Ctrl+G External Editor Live Projection 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 non-synchronized external-editor output visible and interactive in modern attach, including reattach during Nvim, while preserving Pi's committed-frame restore guarantees.
6
+
7
+ **Architecture:** A pure screen-owner reducer and thin xterm adapter define the Pi/external transition. The runner terminal model persists the boolean and snapshots it to late attaching clients; the component switches all visible and interaction consumers between committed and live projections through one predicate. Tests precede each production change, including a real Pi + PTY + Nvim RED run before the component fix.
8
+
9
+ **Tech Stack:** Node 22+, TypeScript, JavaScript ESM modules, `node:test`, `@xterm/headless`, `node-pty`, managed Pi 1.5.0, Nvim.
10
+
11
+ **Spec:** `docs/superpowers/specs/2026-11-05-issue-278-ctrl-g-external-editor-design.md`
12
+
13
+ ## Global Constraints
14
+
15
+ - Work only in the issue worktree; do not edit or stage the main checkout. Use tabs and English comments; stage files by name, never `git add -A`.
16
+ - The wire field is exactly `externalOutputActive: boolean`. A present non-boolean value emits `protocolError` with code `external_output_active_invalid`, is omitted from `snapshotBegin`, and does not add a new resync path.
17
+ - The component predicate is exactly `modernCommittedMode() && (!externalOutputActive || localHydrationState === "hydrating")`. Hydrating therefore retains committed/blank protection.
18
+ - Enter external output only when `?1049l` is observed with `syncOpen=true`; exit on `?2026h`. `?1049h`, unsynchronized `?1049l`, and `?2026$p` do not independently change ownership.
19
+ - For combined close CSI such as `?2026;1049l` and `?1049;2026l`, evaluate the entry guard using `syncOpen` at the start of the CSI, then close sync.
20
+ - Do not change input forwarding, frame-proof/APC classification, or legacy projection behavior. Do not hard-code the main checkout or executable paths in committed test drivers.
21
+ - Acceptance ownership: Task 1 → A1; Task 2 → A2; Task 3 → RED evidence for A3/A4/A5; Task 4 → GREEN A3/A4/A5 and full A6. Every implementation change must retain these test boundaries.
22
+
23
+ ## Review Focus
24
+
25
+ - Combined parameter order: both `?2026;1049l` and `?1049;2026l` must enter external output from an open block; Task 1 Step 1 pins both.
26
+ - Malformed wire input: `"yes"`, `1`, and `null` must not become ownership facts; Task 2 Step 1 pins `protocolError` and omission.
27
+ - Late attach while Nvim is active: a second real component must render a second unique edit; Task 3 Step 3 pins this before the UI fix.
28
+ - Partial hydration and Pi restore: no live partial snapshot or open Pi restore frame may leak; Task 3 Step 1 pins both states.
29
+ - Stale interaction geometry: pre-existing selection, pending click, auto-scroll, and viewport coordinates must clear on ownership change; same-generation resize must not disable live mode; Task 3 Step 1 pins both.
30
+
31
+ ---
32
+
33
+ ### Task 1: Pure screen-owner reducer and xterm adapter
34
+
35
+ **Files:**
36
+ - Create: `src/core/attach-screen-owner.mjs`
37
+ - Test: `test/attach-screen-owner.test.mjs`
38
+
39
+ **Interfaces:**
40
+ - Consumes: xterm `term.parser.registerCsiHandler({ prefix: "?", final }, handler)` and disposable observer handles.
41
+ - Produces: `createAttachScreenOwnerState(externalOutputActive?)`, `transitionAttachScreenOwner(state, event)`, and `installAttachScreenOwnerObservers(term, { initialState, onTransition })`. The adapter callback receives `{ previous, current, event, syncOpenMarker, syncCloseMarker }`; it returns an array of disposable observers. Task 2 and Task 4 use these exact names.
42
+
43
+ - [ ] **Step 1: Write the failing reducer and adapter tests**
44
+
45
+ Create tests that import the three functions and assert this table with `node:test` and `assert/strict`:
46
+
47
+ ```js
48
+ const initial = createAttachScreenOwnerState();
49
+ assert.deepEqual(initial, { syncOpen: false, externalOutputActive: false });
50
+ assert.equal(transitionAttachScreenOwner(initial, {
51
+ type: "csi", final: "h", params: [1049],
52
+ }), initial); // Pi startup alt entry is not external ownership.
53
+ const stopped = transitionAttachScreenOwner(
54
+ transitionAttachScreenOwner(initial, { type: "csi", final: "h", params: [2026] }),
55
+ { type: "csi", final: "l", params: [1049] },
56
+ );
57
+ assert.deepEqual(stopped, { syncOpen: true, externalOutputActive: true });
58
+ const closed = transitionAttachScreenOwner(stopped, { type: "csi", final: "l", params: [2026] });
59
+ assert.deepEqual(closed, { syncOpen: false, externalOutputActive: true });
60
+ assert.deepEqual(transitionAttachScreenOwner(closed, { type: "csi", final: "h", params: [2026] }), {
61
+ syncOpen: true, externalOutputActive: false,
62
+ });
63
+ ```
64
+
65
+ Add separate cases for unsynchronized `1049l` non-entry, `1049h`/`2026$p` no-op, adoption of explicit true/false, reset, and both combined forms:
66
+
67
+ ```js
68
+ for (const params of [[2026, 1049], [1049, 2026], [[2026, 1049]]]) {
69
+ const open = { syncOpen: true, externalOutputActive: false };
70
+ assert.deepEqual(transitionAttachScreenOwner(open, { type: "csi", final: "l", params }), {
71
+ syncOpen: false, externalOutputActive: true,
72
+ });
73
+ }
74
+ ```
75
+
76
+ Use a real `Terminal` to prove the adapter returns `false` through normal parsing, emits marker facts, and disposed observers receive no later transitions.
77
+
78
+ - [ ] **Step 2: Run the tests and verify RED**
79
+
80
+ Run: `node --test test/attach-screen-owner.test.mjs`
81
+ Expected: FAIL because `src/core/attach-screen-owner.mjs` does not exist. Do not implement before observing this failure.
82
+
83
+ - [ ] **Step 3: Implement the minimal pure reducer and thin adapter**
84
+
85
+ Implement the module with this behavior and no I/O beyond xterm handler registration:
86
+
87
+ ```js
88
+ function hasParam(params, wanted) {
89
+ return params.some((value) => value === wanted || (Array.isArray(value) && value.includes(wanted)));
90
+ }
91
+
92
+ export function createAttachScreenOwnerState(externalOutputActive = false) {
93
+ return { syncOpen: false, externalOutputActive };
94
+ }
95
+
96
+ export function transitionAttachScreenOwner(state, event) {
97
+ if (event.type === "reset") return createAttachScreenOwnerState();
98
+ if (event.type === "adopt") return { ...state, externalOutputActive: event.active };
99
+ if (event.type !== "csi") return state;
100
+ const has2026 = hasParam(event.params, 2026);
101
+ const has1049 = hasParam(event.params, 1049);
102
+ if (event.final === "h" && has2026) return { syncOpen: true, externalOutputActive: false };
103
+ if (event.final === "l") {
104
+ return {
105
+ syncOpen: has2026 ? false : state.syncOpen,
106
+ externalOutputActive: has1049 && state.syncOpen ? true : state.externalOutputActive,
107
+ };
108
+ }
109
+ return state;
110
+ }
111
+
112
+ export function installAttachScreenOwnerObservers(term, { initialState = createAttachScreenOwnerState(), onTransition = () => {} } = {}) {
113
+ if (!term?.parser || typeof term.parser.registerCsiHandler !== "function") return [];
114
+ let state = initialState;
115
+ const observers = [];
116
+ try {
117
+ for (const final of ["h", "l"]) {
118
+ observers.push(term.parser.registerCsiHandler({ prefix: "?", final }, (params) => {
119
+ const previous = state;
120
+ const event = { type: "csi", final, params };
121
+ const current = transitionAttachScreenOwner(state, event);
122
+ state = current;
123
+ onTransition({
124
+ previous, current, event,
125
+ syncOpenMarker: final === "h" && hasParam(params, 2026),
126
+ syncCloseMarker: final === "l" && hasParam(params, 2026),
127
+ });
128
+ return false;
129
+ }));
130
+ }
131
+ return observers;
132
+ } catch (error) {
133
+ for (const observer of observers) observer.dispose();
134
+ throw error;
135
+ }
136
+ }
137
+ ```
138
+
139
+ - [ ] **Step 4: Run the focused tests and verify GREEN**
140
+
141
+ Run: `node --test test/attach-screen-owner.test.mjs`
142
+ Expected: PASS, including combined order, invalid/no-op controls, real parser callback order, and disposal.
143
+
144
+ - [ ] **Step 5: Commit Task 1**
145
+
146
+ ```bash
147
+ git add src/core/attach-screen-owner.mjs test/attach-screen-owner.test.mjs
148
+ git commit -m "feat: add attach screen ownership transitions (#278)"
149
+ ```
150
+
151
+ ### Task 2: Persist and transport external ownership
152
+
153
+ **Files:**
154
+ - Modify: `src/core/terminal-model.mjs`
155
+ - Modify: `src/core/terminal-attach-protocol.mjs`
156
+ - Modify: `src/core/terminal-attach-client.mjs`
157
+ - Test: `test/terminal-model.test.mjs`
158
+ - Test: `test/terminal-attach-protocol.test.mjs`
159
+ - Test: `test/terminal-attach-client.test.mjs`
160
+
161
+ **Interfaces:**
162
+ - Consumes: Task 1 `installAttachScreenOwnerObservers()` and its `current.externalOutputActive` callback field.
163
+ - Produces: terminal model boolean `externalOutputActive`; optional snapshot-begin wire boolean; `snapshotBegin` payload boolean. Task 3's real reattach and Task 4's UI adoption depend on these names.
164
+
165
+ - [ ] **Step 1: Add failing model, wire, and client tests**
166
+
167
+ Add a real-xterm model test:
168
+
169
+ ```js
170
+ const model = createTerminalModel({ cols: 80, rows: 22 });
171
+ feedOutput(model, "\x1b[?1049h\x1b[?2026hPI\x1b[?2026l");
172
+ await whenIdle(model);
173
+ assert.equal(model.externalOutputActive, false);
174
+ feedOutput(model, "\x1b[?2026h\x1b[?1049l\x1b[?2026l\x1b[?1049hNVIM");
175
+ await whenIdle(model);
176
+ assert.equal(model.externalOutputActive, true);
177
+ feedOutput(model, "\x1b[?1049l\x1b[?1049h\x1b[?2026hPI_RESTORE");
178
+ await whenIdle(model);
179
+ assert.equal(model.externalOutputActive, false);
180
+ ```
181
+
182
+ Add empty and non-empty subscription cases that capture sent messages and assert `snapshot_begin.externalOutputActive` is the model boolean. Add client cases for true, false, absent, and invalid values:
183
+
184
+ ```js
185
+ assert.equal(events.find((event) => event.event === "snapshotBegin").payload.externalOutputActive, true);
186
+ // Present "yes", 1, or null:
187
+ assert.ok(events.some((event) => event.event === "protocolError" && event.payload.code === "external_output_active_invalid"));
188
+ assert.equal(Object.hasOwn(events.find((event) => event.event === "snapshotBegin").payload, "externalOutputActive"), false);
189
+ ```
190
+
191
+ Keep existing sequence, frame, view-proof, and recovery assertions unchanged.
192
+
193
+ - [ ] **Step 2: Run the three suites and verify RED**
194
+
195
+ Run: `node --test test/terminal-model.test.mjs test/terminal-attach-protocol.test.mjs test/terminal-attach-client.test.mjs`
196
+ Expected: FAIL on missing model state, missing wire field, or missing client forwarding/validation; record the exact first failure.
197
+
198
+ - [ ] **Step 3: Implement model observation and additive wire transport**
199
+
200
+ In `createTerminalModel()`, construct the model first with `externalOutputActive:false`, then install Task 1's adapter on the real parser and update the model in `onTransition`. Keep fake parsers without `registerCsiHandler` supported through the adapter's empty-array path.
201
+
202
+ In both empty and non-empty `startSnapshot()` paths, add:
203
+
204
+ ```js
205
+ begin.externalOutputActive = model.externalOutputActive === true;
206
+ ```
207
+
208
+ In `beginCollecting()`, validate before emitting:
209
+
210
+ ```js
211
+ const external = msg.externalOutputActive;
212
+ const externalValid = external === undefined || typeof external === "boolean";
213
+ if (!externalValid) emit("protocolError", {
214
+ code: "external_output_active_invalid",
215
+ message: "snapshot_begin.externalOutputActive",
216
+ });
217
+ ```
218
+
219
+ Include `externalOutputActive` in `snapshotBegin` only when `typeof external === "boolean"`; do not resync or coerce invalid values.
220
+
221
+ - [ ] **Step 4: Run focused and existing protocol tests**
222
+
223
+ Run: `node --test test/attach-screen-owner.test.mjs test/terminal-model.test.mjs test/terminal-attach-protocol.test.mjs test/terminal-attach-client.test.mjs test/terminal-snapshot.integration.test.mjs`
224
+ Expected: PASS with no duplicate/gap output and unchanged legacy recovery.
225
+
226
+ - [ ] **Step 5: Commit Task 2**
227
+
228
+ ```bash
229
+ git add src/core/terminal-model.mjs src/core/terminal-attach-protocol.mjs src/core/terminal-attach-client.mjs test/terminal-model.test.mjs test/terminal-attach-protocol.test.mjs test/terminal-attach-client.test.mjs
230
+ git commit -m "feat: carry external output ownership in attach snapshots (#278)"
231
+ ```
232
+
233
+ ### Task 3: Add component and real-Nvim regression tests before the UI fix
234
+
235
+ **Files:**
236
+ - Create: `test-support/pty-attach-external-editor-scenario.ts`
237
+ - Create: `test/pty-attach-external-editor.test.mjs`
238
+ - Create: `test-support/attach-external-editor-real.ts`
239
+ - Create: `test/attach-external-editor.real.test.mjs`
240
+
241
+ **Interfaces:**
242
+ - Consumes: Task 2 snapshot boolean; real `PtyAttachComponent.handleInput()`, `handleAttachEvent()`, `render()`, and the existing transform-types child-process test pattern.
243
+ - Produces: executable RED evidence for Task 4. No production file is changed in this task.
244
+
245
+ - [ ] **Step 1: Build the component scenario and failing wrapper**
246
+
247
+ Use an isolated `/no/such/socket` component harness like `pty-attach-parser-replacement-scenario.ts`. Hydrate an 80x22 synchronized Pi frame containing `PI_BEFORE_NVIM`, enter modern mode with `attaching=false`, then drive:
248
+
249
+ ```js
250
+ const PI_STOP = "\x1b[?2026h\x1b[?1049l\x1b[?2026l";
251
+ const NVIM_START = "\x1b[?1049h\x1b[?2026$p\x1b[2J\x1b[HNVIM_VISIBLE_PROBE_1";
252
+ const NVIM_QUIT = "\x1b[?1049l";
253
+ const PI_RESTORE_OPEN = "\x1b[?1049h\x1b[?2026hPI_PARTIAL_MUST_NOT_SHOW";
254
+ const PI_RESTORE_CLOSE = "\x1b_Ga=d,d=A,q=2\x1b\\PI_RESTORED\x1b[?2026l";
255
+ ```
256
+
257
+ Before Pi stop, seed non-null viewport/selection and pending-click state. After Nvim starts, assert all of these in the scenario (the current code must fail the render assertion):
258
+
259
+ ```js
260
+ assert.ok(bufferText().includes("NVIM_VISIBLE_PROBE_1"));
261
+ assert.ok(component.render(80).join("\n").includes("NVIM_VISIBLE_PROBE_1"));
262
+ assert.equal(internals.externalOutputActive, true);
263
+ assert.equal(internals.viewportTop, null);
264
+ assert.equal(internals.selection, null);
265
+ assert.ok(internals.interactionLine(probeLine).translateToString(true).includes("NVIM_VISIBLE_PROBE_1"));
266
+ ```
267
+
268
+ Spy the existing socket write seam around `handleInput("\x07")` and `handleInput("iNVIM_VISIBLE_PROBE_1")`; assert decoded input messages contain exactly those bytes. After restore-open but before close, assert render omits `PI_PARTIAL_MUST_NOT_SHOW`; after close, assert it contains `PI_RESTORED`, omits both Nvim/partial markers, and retains 80x22 geometry. Add same-generation parser replacement, hydration, resize, new-generation/epoch reset, legacy fallback, and disposal checks using the actual existing events and fields.
269
+
270
+ The `.mjs` wrapper runs the scenario with `node --experimental-transform-types`, parses its final JSON line, writes failure output to a fresh temp artifact, and exits nonzero when `ok=false`.
271
+
272
+ - [ ] **Step 2: Run the component regression and record expected RED**
273
+
274
+ Run: `node --test test/pty-attach-external-editor.test.mjs`
275
+ Expected: FAIL specifically because the actual render omits `NVIM_VISIBLE_PROBE_1` while the underlying buffer contains it. If it errors for a harness reason, fix only the harness and rerun until the assertion is the failure.
276
+
277
+ - [ ] **Step 3: Build the opt-in real Pi/Nvim round-trip driver and wrapper**
278
+
279
+ The `.mjs` wrapper registers a test only when `PI278_REAL_NVIM=1`; inside that lane it discovers executables with `command -v pi` and `command -v nvim`, skips with an explicit reason if either is unavailable, and spawns the driver using `--experimental-transform-types`. The driver derives `REPO_ROOT` from `fileURLToPath(new URL("../", import.meta.url))` and never names the main checkout.
280
+
281
+ The driver follows `attach-frame-witness.real.test.mjs`: isolated root and `PI_CODING_AGENT_DIR`, owned real runner, `node-pty`, no model request, `--offline`, production `index.ts`, bounded cleanup, and optional fresh `PI278_ARTIFACT_DIR`. Write isolated `settings.json` with `externalEditor` set to the discovered Nvim path plus `-u NONE -i NONE`; set `NVIM_NOTTYFAST=1` in the child environment.
282
+
283
+ Drive this sequence through real components:
284
+
285
+ ```text
286
+ attach and settle → type PI_RESTORE_PROBE → Ctrl+G → wait for Nvim ?2026$p
287
+ → ggiNVIM_VISIBLE_PROBE_1 → assert actual render contains the probe
288
+ → dispose and attach a fresh component → type NVIM_REATTACH_PROBE_2
289
+ → assert the second render contains both probes
290
+ → Escape, :q! → assert PI_RESTORE_PROBE restored and both Nvim probes absent
291
+ → assert 80x22 body/committed identity and record the restore Kitty APC
292
+ → type x → require a later F proof
293
+ → Ctrl+U, Ctrl+D → require natural child and runner exit with no forced kill
294
+ ```
295
+
296
+ Capture actual render, underlying buffer, host frameWitness, and cleanup evidence. Failure must still reap the owned child/runner and retain the error before exiting nonzero.
297
+
298
+ - [ ] **Step 4: Run the real regression and record expected RED**
299
+
300
+ Run: `PI278_REAL_NVIM=1 PI278_ARTIFACT_DIR=/tmp/pi278-real-red node --test test/attach-external-editor.real.test.mjs`
301
+ Expected: FAIL because the first actual Nvim render never contains `NVIM_VISIBLE_PROBE_1`; the artifact must show live buffer=true and render=false, with cleanup complete. Remove only a pre-existing artifact directory owned by this test before a deliberate rerun, or choose a fresh path.
302
+
303
+ - [ ] **Step 5: Commit the RED regression harnesses**
304
+
305
+ ```bash
306
+ git add test-support/pty-attach-external-editor-scenario.ts test/pty-attach-external-editor.test.mjs test-support/attach-external-editor-real.ts test/attach-external-editor.real.test.mjs
307
+ git commit -m "test: reproduce external editor attach invisibility (#278)"
308
+ ```
309
+
310
+ The intermediate branch is intentionally RED at A3/A5; Task 4 owns the fix. Do not weaken assertions to make this task green.
311
+
312
+ ### Task 4: Switch component projection and complete acceptance
313
+
314
+ **Files:**
315
+ - Modify: `src/ui/pty-attach.ts`
316
+ - Modify only if harness defects are demonstrated: Task 3 test drivers (without weakening behavior assertions)
317
+ - Test: all Task 1–3 tests plus the repository suite
318
+
319
+ **Interfaces:**
320
+ - Consumes: Task 1 reducer/adapter and Task 2 `snapshotBegin.externalOutputActive`.
321
+ - Produces: `externalOutputActive` component state, `usesCommittedProjection()` visible-surface predicate, and ownership-change interaction cleanup. No new public API or input protocol.
322
+
323
+ - [ ] **Step 1: Implement the minimal component ownership/projection change**
324
+
325
+ Add `private externalOutputActive = false` and:
326
+
327
+ ```ts
328
+ private usesCommittedProjection(): boolean {
329
+ return this.modernCommittedMode() &&
330
+ (!this.externalOutputActive || this.localHydrationState === "hydrating");
331
+ }
332
+ ```
333
+
334
+ Replace `modernCommittedMode()` with `usesCommittedProjection()` only at visible/interaction forks: `project()`, `interactionLine()`, `interactionNullCell()`, `mousePointForEvent()`, and `tryScrollBy()`. Keep readiness, commit, recovery, identity, and proof decisions on `modernCommittedMode()`.
335
+
336
+ Replace the existing `?2026` observer body with Task 1's adapter. Initialize it from the component state; preserve closed/term/epoch fences and `parserObserverEvents`; copy `current.syncOpen` to `parserSyncOpen`; call `commitCommittedView(term, epoch)` for every `syncCloseMarker` exactly as before. On an actual external-flag change, run this side-effect boundary without sending input or forcing a parser read:
337
+
338
+ ```ts
339
+ private resetExternalProjectionInteraction(): void {
340
+ this.clearSelectionAutoScroll();
341
+ this.clearPendingClick();
342
+ this.selection = null;
343
+ this.selectionDragging = false;
344
+ this.lastClickPoint = null;
345
+ this.lastClickAt = 0;
346
+ this.viewportTop = null;
347
+ }
348
+ ```
349
+
350
+ At `snapshotBegin`, new-generation state first resets to false; then a validated boolean adopts the runner value and runs interaction cleanup on change. An absent field preserves same-generation local state. Preserve external state across same-generation parser replacement and resize. Reset it on epoch reset, legacy fallback, and close/dispose. The existing output scheduler performs post-parse rendering; do not add a synchronous partial-hydration render.
351
+
352
+ - [ ] **Step 2: Run component and focused regression suites to GREEN**
353
+
354
+ Run: `node --test test/attach-screen-owner.test.mjs test/terminal-model.test.mjs test/terminal-attach-protocol.test.mjs test/terminal-attach-client.test.mjs test/pty-attach-external-editor.test.mjs test/pty-attach-parser-replacement.test.mjs test/pty-attach-ready.test.mjs`
355
+ Expected: PASS. In particular, Nvim is visible and interactive, Pi restore-open is not visible, restore-close commits the APC-containing frame, hydration/resize/reset cases pass, and existing 32 parser-replacement checks remain intact.
356
+
357
+ - [ ] **Step 3: Run the real Nvim round trip to GREEN**
358
+
359
+ Run: `PI278_REAL_NVIM=1 PI278_ARTIFACT_DIR=/tmp/pi278-real-green node --test test/attach-external-editor.real.test.mjs`
360
+ Expected: PASS; both initial and reattached renders show live Nvim edits, `:q!` restores `PI_RESTORE_PROBE` at 80x22 without Nvim residue, the restore Kitty APC is recorded, a later ordinary input produces a later F, and natural cleanup succeeds. If Pi/Nvim is missing, record A5 as pending rather than claiming success; on this development machine both are present, so execute the real run before merge.
361
+
362
+ - [ ] **Step 4: Run all repository acceptance gates**
363
+
364
+ Run: `npm run verify`
365
+ Expected: typecheck, perf, full tests, coverage thresholds, and pack dry-run all pass. Report test/pass/skip counts and any pre-existing flaky failure honestly; do not call a targeted green run full verification.
366
+
367
+ - [ ] **Step 5: Commit the fix and any harness-only corrections**
368
+
369
+ ```bash
370
+ git add src/ui/pty-attach.ts test-support/pty-attach-external-editor-scenario.ts test/pty-attach-external-editor.test.mjs test-support/attach-external-editor-real.ts test/attach-external-editor.real.test.mjs
371
+ git commit -m "fix: show external editor output in modern attach (#278)"
372
+ ```
373
+
374
+ If no Task 3 harness correction was needed, stage only `src/ui/pty-attach.ts`. Do not include unrelated files or the SDD workspace.
375
+
376
+ ## Plan Self-Review Record
377
+
378
+ - Spec coverage: D1/A1 → Task 1; D2/D3/A2 → Task 2; D4–D8/A3/A4 → Tasks 3–4; D9 and Kitty restore/A5 → Tasks 3–4; A6 → Task 4. No acceptance ID lacks a task.
379
+ - Type consistency: Task 1 callback `{ previous, current, event, syncOpenMarker, syncCloseMarker }` is consumed by Tasks 2 and 4; Task 2's `snapshotBegin.externalOutputActive` is consumed by Tasks 3–4; the component predicate matches the corrected spec verbatim.
380
+ - Placeholder scan: every task has named files, executable commands, explicit expected RED/GREEN evidence, concrete interfaces, and commit scope. No task relies on an undefined helper or an unnamed future test.
381
+ - Review focus: combined CSI, malformed fields, late reattach, partial frames, and stale interaction geometry each have an owning test step.