@zhuxixi/pi-agent-board 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +37 -12
- package/docs/SECTION_FOLDING.md +53 -0
- package/docs/superpowers/plans/2026-10-23-issue-222-attach-ready.md +290 -0
- package/docs/superpowers/plans/2026-10-26-issue-245-key-hints-doc-sync.md +244 -0
- package/docs/superpowers/plans/2026-10-27-issue-172-fullscreen-selection-clear.md +344 -0
- package/docs/superpowers/plans/2026-10-27-issue-252-select-key-hints.md +209 -0
- package/docs/superpowers/plans/2026-10-28-issue-255-coordinator-endpoint-zombie.md +442 -0
- package/docs/superpowers/plans/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup.md +256 -0
- package/docs/superpowers/plans/2026-11-03-cwd-favorites-full-pool.md +266 -0
- package/docs/superpowers/plans/2026-11-03-issue-266-alt-h-detach.md +467 -0
- package/docs/superpowers/plans/2026-11-04-issue-270-scenario-stdout-flush.md +584 -0
- package/docs/superpowers/plans/2026-11-05-issue-278-ctrl-g-external-editor.md +381 -0
- package/docs/superpowers/plans/2026-11-06-issue-280-frame-witness-delivery.md +430 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-attach-recovery.md +115 -0
- package/docs/superpowers/plans/2026-11-07-issue-284-u1-u2-trial-guide.md +39 -0
- package/docs/superpowers/plans/2026-11-08-host-restart-model-override.md +894 -0
- package/docs/superpowers/plans/2026-11-08-issue-288-cap-floor.md +51 -0
- package/docs/superpowers/plans/2026-11-09-dashboard-fold-flake.md +166 -0
- package/docs/superpowers/plans/2026-11-09-issue-273-harness-console-log-exit.md +369 -0
- package/docs/superpowers/plans/2026-11-10-issue-258-board-selection-settle.md +760 -0
- package/docs/superpowers/plans/2026-11-13-issue-294-snapshot-resize-intent.md +590 -0
- package/docs/superpowers/plans/2026-11-16-greeting-title-poll.md +838 -0
- package/docs/superpowers/plans/2026-11-22-issue-297-compaction-mirror.md +797 -0
- package/docs/superpowers/plans/2026-11-23-issue-254-cursor-keep-position.md +663 -0
- package/docs/superpowers/plans/2026-11-23-issue-95-legacy-quarantine.md +320 -0
- package/docs/superpowers/specs/2026-10-23-issue-222-attach-ready-design.md +204 -0
- package/docs/superpowers/specs/2026-10-26-issue-245-key-hints-doc-sync-design.md +72 -0
- package/docs/superpowers/specs/2026-10-27-issue-172-fullscreen-selection-clear-design.md +248 -0
- package/docs/superpowers/specs/2026-10-27-issue-252-select-key-hints-design.md +95 -0
- package/docs/superpowers/specs/2026-10-28-issue-255-coordinator-endpoint-zombie-design.md +380 -0
- package/docs/superpowers/specs/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup-design.md +197 -0
- package/docs/superpowers/specs/2026-11-03-cwd-favorites-full-pool-design.md +106 -0
- package/docs/superpowers/specs/2026-11-03-issue-266-alt-h-detach-design.md +185 -0
- package/docs/superpowers/specs/2026-11-04-issue-270-scenario-stdout-flush-design.md +176 -0
- package/docs/superpowers/specs/2026-11-05-issue-278-ctrl-g-external-editor-design.md +185 -0
- package/docs/superpowers/specs/2026-11-07-issue-284-attach-recovery-design.md +166 -0
- package/docs/superpowers/specs/2026-11-08-host-restart-model-override-design.md +115 -0
- package/docs/superpowers/specs/2026-11-08-issue-288-cap-floor-design.md +86 -0
- package/docs/superpowers/specs/2026-11-09-dashboard-fold-flake-design.md +109 -0
- package/docs/superpowers/specs/2026-11-09-issue-273-harness-console-log-exit-design.md +182 -0
- package/docs/superpowers/specs/2026-11-10-issue-258-board-selection-settle-design.md +109 -0
- package/docs/superpowers/specs/2026-11-13-issue-294-snapshot-resize-intent-design.md +141 -0
- package/docs/superpowers/specs/2026-11-16-greeting-title-poll-design.md +174 -0
- package/docs/superpowers/specs/2026-11-22-issue-297-compaction-mirror-design.md +158 -0
- package/docs/superpowers/specs/2026-11-22-issue-95-legacy-quarantine-design.md +209 -0
- package/docs/superpowers/specs/2026-11-23-issue-254-cursor-keep-position-design.md +201 -0
- package/package.json +1 -1
- package/runner/pty-runner.mjs +526 -63
- package/runner/state-coordinator.mjs +62 -5
- package/runner/title-runner.mjs +33 -24
- package/src/commands/agent-board.ts +5 -1
- package/src/core/attach-detach.mjs +27 -0
- package/src/core/attach-frame-proof.mjs +897 -0
- package/src/core/attach-frame-reporter.mjs +738 -0
- package/src/core/attach-frame-stream.mjs +266 -0
- package/src/core/attach-pr-label.mjs +12 -0
- package/src/core/attach-recovery.mjs +239 -0
- package/src/core/attach-screen-owner.mjs +55 -0
- package/src/core/attach-view-proof.mjs +709 -0
- package/src/core/auto-state.mjs +6 -1
- package/src/core/cwd-stats.mjs +3 -1
- package/src/core/dashboard-prefs.mjs +31 -0
- package/src/core/derive.mjs +8 -1
- package/src/core/events.mjs +127 -1
- package/src/core/foreground-projection-cache.mjs +1 -0
- package/src/core/frame-witness-update.mjs +35 -0
- package/src/core/fullscreen-selection.mjs +60 -0
- package/src/core/host-coordination.mjs +48 -0
- package/src/core/host-protocol.mjs +13 -2
- package/src/core/hosted-frame-witness.mjs +60 -0
- package/src/core/paths.mjs +10 -3
- package/src/core/pty-attach-render.mjs +239 -0
- package/src/core/pty-kitty-images.mjs +237 -0
- package/src/core/pty-scroll.mjs +8 -8
- package/src/core/rows.mjs +43 -7
- package/src/core/session-entries.mjs +82 -0
- package/src/core/session-launch-prefs.mjs +45 -0
- package/src/core/session-view.mjs +3 -63
- package/src/core/store.mjs +1 -0
- package/src/core/terminal-attach-client.mjs +199 -20
- package/src/core/terminal-attach-protocol.mjs +221 -7
- package/src/core/terminal-model.mjs +24 -3
- package/src/core/terminal-snapshot.mjs +10 -0
- package/src/core/title-flow.mjs +66 -0
- package/src/core/title.mjs +101 -0
- package/src/core/types.mjs +17 -0
- package/src/index.ts +85 -0
- package/src/runtime/service.mjs +87 -18
- package/src/ui/dashboard.ts +206 -49
- package/src/ui/pty-attach.ts +1472 -99
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Issue #278 — Ctrl+G external editor invisible in modern attach: root cause and design
|
|
2
|
+
|
|
3
|
+
Drafted: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T22:01:37+08:00
|
|
4
|
+
Revised: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T22:25:23+08:00
|
|
5
|
+
Revised: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T23:23:04+08:00
|
|
6
|
+
Revised: kimi-coding/k3.1-pro (selected) · kimi-coding/k3.1-pro (physical) @ 2026-11-05T23:27:52+08:00
|
|
7
|
+
|
|
8
|
+
- Issue: https://github.com/zhuxixi/pi-agent-board/issues/278
|
|
9
|
+
- Target base: `origin/main` `4bb836e9c9bb25c653bb6160e0d45a26e9348078` (approved design reviewed at `c71add85130d760684135c07d9ad2178d548a924`; intervening attach change is a one-line Kitty projection optimization with no contract impact)
|
|
10
|
+
- Research: `research/01-projection-history.md`, `research/02-reproduction-transition.md`
|
|
11
|
+
|
|
12
|
+
## 1. Conclusion
|
|
13
|
+
|
|
14
|
+
The defect is a projection-ownership gap. Modern protocol attach always renders the last immutable `committedView`, but Nvim owns the child terminal without emitting Pi's synchronized-output frame boundaries. The xterm buffer and input path are healthy; the visible projection and all committed-view interaction consumers remain attached to the old Pi frame.
|
|
15
|
+
|
|
16
|
+
The fix is a scoped external/live projection interval backed by an explicit terminal-ownership transition, plus a runner-owned boolean snapshot fact so a client that attaches while Nvim is already running can enter the same interval. Normal Pi rendering remains committed and fail-closed.
|
|
17
|
+
|
|
18
|
+
## 2. Evidence and root cause
|
|
19
|
+
|
|
20
|
+
### 2.1 Code path
|
|
21
|
+
|
|
22
|
+
- `src/ui/pty-attach.ts` `installParserObservers()` observes `CSI ?2026h/l`; only a real close calls `commitCommittedView()`.
|
|
23
|
+
- `modernCommittedMode()` is true for protocol attach with frame witness.
|
|
24
|
+
- `project()` selects `projectCommitted()` whenever that mode is true. Ordinary output schedules another render after parsing, but the render reads the same old immutable view.
|
|
25
|
+
- `interactionLine()`, `interactionNullCell()`, `mousePointForEvent()`, and `tryScrollBy()` independently select the committed view using the same mode. Changing only `render()` would leave mouse hit-testing, selection/copy, and scrolling on stale Pi coordinates.
|
|
26
|
+
|
|
27
|
+
### 2.2 Reproduction
|
|
28
|
+
|
|
29
|
+
A component reproduction (`research/component-result.json`) and a real managed Pi 1.5.0 + real runner/PTY + real Nvim reproduction (`research/real-nvim-result.json`) both produce:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"modern": true,
|
|
34
|
+
"liveProbeVisible": true,
|
|
35
|
+
"renderedProbeVisible": false,
|
|
36
|
+
"parserSyncOpen": false
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The real driver sends Ctrl+G through `PtyAttachComponent.handleInput()`, types `NVIM_VISIBLE_PROBE_1` into Nvim, and exits with `:q!`. After exit, the actual attach render shows Pi again and omits the Nvim probe.
|
|
41
|
+
|
|
42
|
+
### 2.3 Historical constraint
|
|
43
|
+
|
|
44
|
+
PR #261 introduced committed views to prevent partial Pi frames; #263 rolled them back; #265 restored them with idle downgrade. The #222 design intentionally makes synchronized close boundaries the normal modern publish mechanism. This issue must not weaken that mechanism globally.
|
|
45
|
+
|
|
46
|
+
## 3. Observed ownership protocol
|
|
47
|
+
|
|
48
|
+
The retained real screen log (`research/real-nvim-screen.log`) shows:
|
|
49
|
+
|
|
50
|
+
| Phase | Relevant order |
|
|
51
|
+
|---|---|
|
|
52
|
+
| Pi initial startup | Unframed `?1049h` before any Pi committed frame |
|
|
53
|
+
| Pi stops for Ctrl+G | `?2026h … ?1049l … ?2026l` |
|
|
54
|
+
| Nvim owns terminal | Unframed `?1049h`, one `?2026$p`, ordinary non-synchronized drawing |
|
|
55
|
+
| Nvim exits | Unframed `?1049l` |
|
|
56
|
+
| Pi restarts | Unframed `?1049h`, then `?2026h … ?2026l` |
|
|
57
|
+
|
|
58
|
+
Therefore alternate-screen state alone is not an ownership signal. A synchronized Pi `?1049l` is the entry signal; the next synchronized-output open is the return boundary. Nvim's own unframed `?1049h/l` and `?2026$p` do not change ownership.
|
|
59
|
+
|
|
60
|
+
## 4. Design decisions
|
|
61
|
+
|
|
62
|
+
| ID | Decision | Rationale |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| D1 | Add a pure screen-owner reducer shared by runner terminal model and attach component. | One tested definition prevents runner/UI transition drift. |
|
|
65
|
+
| D2 | Enter external/live only on `?1049l` observed while synchronized output is open; leave on the next `?2026h`. | Matches real Pi/Nvim order and does not misclassify Pi's startup alternate screen. |
|
|
66
|
+
| D3 | Runner retains the boolean for its whole child lifetime and includes it as optional `externalOutputActive` in `snapshot_begin`; client forwards it to `snapshotBegin`. | Supports attach/resnapshot while the editor is already open without process-name heuristics. |
|
|
67
|
+
| D4 | Add one component predicate for visible committed projection: modern mode AND (NOT external/live OR hydrating). Use it at every visible/interaction fork. | Rendering and interaction must address the same surface; hydration must retain committed/blank protection rather than exposing a partial live snapshot. |
|
|
68
|
+
| D5 | Keep `commitCommittedView()`, readiness, proof, recovery, and identity mechanisms in modern mode; only visible projection ownership changes. | A synchronized Pi stop can still commit a complete view; Pi restore must not publish its open/partial frame. |
|
|
69
|
+
| D6 | On external/live entry and exit, clear selection, pending click, auto-scroll, and stale viewport coordinates; follow the live bottom. | Old Pi/Nvim buffer offsets are not valid across screen ownership changes. |
|
|
70
|
+
| D7 | Preserve external/live across same-generation resize and parser replacement, but suspend it while hydration is in progress. Adopt the runner boolean at each new snapshot; reset on new generation, epoch reset, close/dispose, or legacy fallback. | Resize must not make Nvim invisible again; reconnect must not show a partial or stale surface. |
|
|
71
|
+
| D8 | Keep all input forwarding unchanged. | The defect is not in the input path. |
|
|
72
|
+
| D9 | Cover but do not alter Kitty APC proof classification in this issue. | Real evidence shows committed render restores before a new F; the APC proof gap is independent. |
|
|
73
|
+
|
|
74
|
+
## 5. Component and protocol contracts
|
|
75
|
+
|
|
76
|
+
### 5.1 Pure reducer and thin xterm adapters
|
|
77
|
+
|
|
78
|
+
Add a core module (working name `src/core/attach-screen-owner.mjs`) with a pure transition function over:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
interface AttachScreenOwnerState {
|
|
82
|
+
syncOpen: boolean;
|
|
83
|
+
externalOutputActive: boolean;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Accepted events are `sync-open`, `sync-close`, `alternate-screen-exit`, `adopt-external`, and `reset`. The transition table is:
|
|
88
|
+
|
|
89
|
+
| Event | Guard | Next state |
|
|
90
|
+
|---|---|---|
|
|
91
|
+
| `sync-open` (`?2026h`) | none | `syncOpen=true`, `externalOutputActive=false` |
|
|
92
|
+
| `sync-close` (`?2026l`) | none | `syncOpen=false`; preserve external flag |
|
|
93
|
+
| `alternate-screen-exit` (`?1049l`) | `syncOpen === true` | set `externalOutputActive=true` |
|
|
94
|
+
| `alternate-screen-exit` | `syncOpen === false` | preserve state |
|
|
95
|
+
| `adopt-external` | snapshot boolean is present | replace only external flag with that boolean |
|
|
96
|
+
| `reset` | new generation/epoch/close/legacy | initial false/false state |
|
|
97
|
+
|
|
98
|
+
Unrelated CSI, `?1049h`, and `?2026$p` produce no transition. Parameter handling must recognize combined xterm parameter forms exactly as the current `?2026` observer does. For a combined CSI, the adapter evaluates the `alternate-screen-exit` guard against `syncOpen` **at the start of that CSI**, then applies the synchronized close/open transition; thus both `CSI ?2026;1049l` and `CSI ?1049;2026l` entered from an open block finish with `syncOpen=false` and `externalOutputActive=true`. A1 must pin both parameter orders and the corresponding unsynchronized non-entry case. The pure module has no terminal, socket, filesystem, timer, or UI dependency.
|
|
99
|
+
|
|
100
|
+
A thin adapter registers `? h/l` xterm handlers, returns `false` to preserve default parsing, and reports transitions to its caller. UI adapters retain existing closed/term/epoch fences and observer disposal. The runner adapter owns no timers or I/O beyond updating terminal-model state.
|
|
101
|
+
|
|
102
|
+
### 5.2 Runner and wire compatibility
|
|
103
|
+
|
|
104
|
+
`createTerminalModel()` installs the adapter on its real xterm parser and exposes the current boolean as model state. Both legacy and owned runners already share this model, so no duplicated child-output state machine is added.
|
|
105
|
+
|
|
106
|
+
`createTerminalSubscription()` copies the model boolean into non-empty and empty `snapshot_begin` messages as `externalOutputActive`. The value is sampled with the snapshot metadata after parser idle. Catch-up output remains authoritative for any transition after that sample.
|
|
107
|
+
|
|
108
|
+
`terminal-attach-client` validates the field as an optional boolean and includes it in `snapshotBegin`. A present non-boolean value (for example `"yes"` or `1`) is a protocol error: emit `protocolError`, omit the field from `snapshotBegin`, and leave the existing recovery state machine unchanged; never silently treat the value as absent or true. A2 must pin this failure branch in `test/terminal-attach-client.test.mjs`. The client does not invent `true` when the field is absent. For an older runner with no field, a same-generation component preserves its locally observed state; a fresh component starts false. This is the compatibility boundary, not a claim that an old runner can identify an already-open editor retrospectively.
|
|
109
|
+
|
|
110
|
+
No token, process name, command line, editor content, or host credential enters this field.
|
|
111
|
+
|
|
112
|
+
### 5.3 Component projection and lifecycle
|
|
113
|
+
|
|
114
|
+
Add a single internal predicate (working name `usesCommittedProjection()`):
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
modernCommittedMode()
|
|
118
|
+
&& (!externalOutputActive || localHydrationState === "hydrating")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Use this predicate in:
|
|
122
|
+
|
|
123
|
+
- `project()`;
|
|
124
|
+
- `interactionLine()`;
|
|
125
|
+
- `interactionNullCell()`;
|
|
126
|
+
- `mousePointForEvent()`;
|
|
127
|
+
- `tryScrollBy()`.
|
|
128
|
+
|
|
129
|
+
`render()` retains its existing attaching/loading and empty-baseline guards. External/live output uses the existing live projection, including cursor, Kitty-image projection, viewport clamping, and the existing 40 ms output scheduler. No extra per-chunk committed snapshot is introduced.
|
|
130
|
+
|
|
131
|
+
On entry/exit, interaction-state cleanup is a side effect outside the pure reducer. It clears the selection and pending mouse gesture, stops selection auto-scroll, clears pending click/double-click state, and sets `viewportTop=null`. It does not send input or request an unscheduled parser read.
|
|
132
|
+
|
|
133
|
+
At Pi restore, `?2026h` immediately returns visible rendering to the last valid committed view (or the existing blank/loading guard if none); live Pi redraw bytes are not exposed. Only `?2026l` commits and displays the restored Pi grid. The existing identity and geometry checks remain in force.
|
|
134
|
+
|
|
135
|
+
## 6. Restore-phase Kitty APC boundary
|
|
136
|
+
|
|
137
|
+
The real run observed Kitty image-deletion APC in Pi's first restored full redraw. That redraw did not increment `frameWitness.proofs`; a subsequent ordinary input incremented it from 1 to 2 and produced a new F at the new renderer epoch.
|
|
138
|
+
|
|
139
|
+
This issue's tests must therefore prove:
|
|
140
|
+
|
|
141
|
+
1. A restore synchronized frame containing `ESC _G … ESC \` still commits the actual restored Pi render.
|
|
142
|
+
2. No Nvim probe survives in that render.
|
|
143
|
+
3. A subsequent ordinary Pi input can still produce a later F proof.
|
|
144
|
+
|
|
145
|
+
The APC scanner/classifier itself remains unchanged. A separate issue can address proof coverage if desired.
|
|
146
|
+
|
|
147
|
+
## 7. Non-goals and guarantee boundaries
|
|
148
|
+
|
|
149
|
+
- Do not project every unframed write globally and do not remove Pi's complete-frame gate.
|
|
150
|
+
- Do not change Ctrl+G, editor configuration, key forwarding, mouse forwarding, or runner input protocol.
|
|
151
|
+
- Do not change legacy attach rendering except for the additive, inert model observation shared with protocol attach.
|
|
152
|
+
- Do not classify external applications that emit their own `?2026` synchronized frames; this contract targets the observed non-synchronized external-editor interval.
|
|
153
|
+
- Do not fix the independent Kitty APC proof-classification gap.
|
|
154
|
+
- The oracle is the actual `PtyAttachComponent.render()` plus interaction buffer addressing, as requested by the issue; it is not a physical-pixel screenshot claim.
|
|
155
|
+
- An old runner lacking the snapshot boolean cannot provide retrospective ownership to a fresh new client. Matching new runner/new client and locally observed transitions are the supported paths.
|
|
156
|
+
|
|
157
|
+
## 8. Testability decomposition (implementation constraint)
|
|
158
|
+
|
|
159
|
+
1. **Pure reducer:** exhaustive table tests for entry, non-entry, exit, adoption, reset, combined parameters, and unrelated controls. No xterm needed for the decision table; one real-xterm adapter test proves callback ordering and `return false` behavior.
|
|
160
|
+
2. **Terminal-model adapter:** feed real xterm output through `feedOutput()` and await `whenIdle()`; assert the persisted boolean at Pi start, Pi stop, Nvim output, Nvim exit, and Pi sync open. This is independently testable without sockets.
|
|
161
|
+
3. **Snapshot protocol:** drive `createTerminalSubscription()` with a terminal model and injected `send`; assert the optional boolean on empty/non-empty begins and catch-up ordering. Client tests drive `snapshot_begin` and assert `snapshotBegin` forwarding plus absent-field behavior.
|
|
162
|
+
4. **Component adapter and projection:** a dedicated transform-types scenario constructs the real `PtyAttachComponent`, drives real parser output through its attach events, waits for parser callbacks, and inspects actual `render()`. Input is spied at the existing socket/send seam; no input rewrite is needed.
|
|
163
|
+
5. **Interaction boundary:** in the same scenario, set non-default viewport/selection before entry; assert they are cleared, live interaction lines contain the Nvim probe, and restored Pi no longer uses Nvim coordinates. Test the open restore frame before its close to prove no partial Pi content is projected.
|
|
164
|
+
6. **Real E2E:** an opt-in `.mjs` test spawns a transform-types driver, following `attach-frame-witness.real.test.mjs` cleanup/isolation patterns. The driver discovers Pi with the existing `command -v pi` mechanism and discovers Nvim with `command -v nvim`, then uses real managed Pi, real runner/PTY, real component, and real `nvim -u NONE -i NONE`; it makes no model request and uses isolated roots and `PI_CODING_AGENT_DIR`. If either executable is missing, the real case reports a skip and A5 remains `pending` in the final report. The driver derives the repository root from its own `test-support/` location (or an explicit worktree root supplied by the test), and must not hard-code the main checkout path used by the research script.
|
|
165
|
+
|
|
166
|
+
Implementation must preserve these boundaries; parser observation, transition decisions, UI side effects, and wire transport must not be recoupled into an untestable monolithic handler.
|
|
167
|
+
|
|
168
|
+
## 9. Acceptance matrix
|
|
169
|
+
|
|
170
|
+
| ID | Feature / contract | Method | Concrete verification | Pass standard |
|
|
171
|
+
|---|---|---|---|---|
|
|
172
|
+
| A1 | Ownership reducer and parser transitions | Automated (unit) | `node --test test/attach-screen-owner.test.mjs` | All table cases pass: Pi startup alt entry does not activate; synced Pi alt exit activates; Nvim controls do not exit; next sync open exits; split/combined CSI and adapter disposal behave correctly. |
|
|
173
|
+
| A2 | Runner persistence + snapshot/client compatibility | Automated (unit + integration) | `node --test test/terminal-model.test.mjs test/terminal-attach-protocol.test.mjs test/terminal-attach-client.test.mjs` | Model retains correct boolean; empty/non-empty snapshots carry it; catch-up order remains intact; client forwards booleans, rejects present non-boolean values through `protocolError`, and preserves absent-field compatibility; existing protocol assertions pass. |
|
|
174
|
+
| A3 | Actual Nvim live render, input, and shared interaction projection | Automated (component + integration) | `node --test test/pty-attach-external-editor.test.mjs` | Before fix this scenario is RED. After fix actual `render()` contains `NVIM_VISIBLE_PROBE_1`; forwarded input is unchanged; live interaction reads the probe; normal Pi before/after uses committed view; no stale selection/viewport remains. |
|
|
175
|
+
| A4 | Restore, hydration, resize, generation, legacy, and disposal fences | Automated (component + integration + static) | Same component test plus `node --test test/pty-attach-parser-replacement.test.mjs test/pty-attach-ready.test.mjs` and `npm run typecheck` | Open Pi restore is never shown as a live partial frame; close restores Pi; same-generation resize/replacement preserve live after hydration; new generation/reset/fallback/close cannot leak stale state; existing suites and typecheck pass. |
|
|
176
|
+
| A5 | Full real Ctrl+G/Nvim round trip, reattach, Kitty restore observation, later proof | Automated E2E (opt-in real toolchain) | `PI278_REAL_NVIM=1 node --test test/attach-external-editor.real.test.mjs` | Real Pi + PTY + Nvim discovered through `command -v`: Pi prefill marker renders before Ctrl+G; Nvim unique probe appears in actual attach render; a fresh attach during Nvim also renders subsequent edits; `:q!` restores the original Pi marker at correct 80x22 body geometry and removes the Nvim probe; restore APC is recorded/covered; a later ordinary input produces a later F; cleanup leaves no runner/child. Missing executables produce skip plus A5 `pending`, never a false pass. |
|
|
177
|
+
| A6 | Repository-wide non-regression and ship gates | Automated (static + perf + full tests + coverage + build/package) | `npm run verify` | Typecheck, perf gate, all tests, coverage thresholds, and dry-run package pass in the issue worktree. Real E2E evidence is reported separately and is not replaced by the default suite. |
|
|
178
|
+
|
|
179
|
+
No acceptance item is classified as manual-only: the requested observable is programmatically inspectable component output. The opt-in real E2E must actually be executed on the development machine before merge; if it cannot run, A5 remains `pending` and the final report must say so.
|
|
180
|
+
|
|
181
|
+
## 10. Implementation scope
|
|
182
|
+
|
|
183
|
+
Expected production surfaces are the new pure owner module, `src/core/terminal-model.mjs`, `src/core/terminal-attach-protocol.mjs`, `src/core/terminal-attach-client.mjs`, and `src/ui/pty-attach.ts`. Tests and transform-types drivers are added under `test/` and `test-support/`. No dashboard layout, release tooling, or unrelated plans are in scope.
|
|
184
|
+
|
|
185
|
+
The implementation plan must map every task to at least one of A1–A6 and preserve the test boundaries above. RED evidence for A3 and the real A5 round trip is collected before the production fix; then the single ownership/projection change is implemented and verified without bundling unrelated fixes.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Issue #284 Spec — attach UI 恢复预算与安全重评(路径 B)
|
|
2
|
+
|
|
3
|
+
Drafted: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T22:05:00+08:00
|
|
4
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T22:40:00+08:00(round-1 复核 R1-G1/G2/G3 接受修订,R1-D1 接受细化)
|
|
5
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T23:10:00+08:00(round-2 复核 R2-G1/G2/G3/G4 接受修订,R2-D1/D2 接受细化)
|
|
6
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-07T23:45:00+08:00(round-3 复核 R3-G1/G2 接受修订,R3-D1 接受措辞修正)
|
|
7
|
+
Base: main @ 6f7b2dc(#282/#283 已合并;#267 spec v4 SHA-256 9bc4d0f2… 为设计基线)
|
|
8
|
+
Status: v4-final(round-4 收敛:0 真缺口;收敛后吸收 R4-D1/D2 两处非阻塞细化:枚举补 unknown、live S/A 行号锚点 1319/1326)
|
|
9
|
+
|
|
10
|
+
## 0. 本 spec 与 #267 spec v4 的关系
|
|
11
|
+
|
|
12
|
+
本 spec 是 #267 路径 B 的独立实施设计,继承父 spec v4 的 D3/D4/D5 与验收矩阵 A06–A12+U1/U2,并按 #284 调研(`research/report.md`,main @ 6f7b2dc)把设计锚定到实际代码:**纯策略函数 `decideAttachPresentation`(`src/core/pty-attach-render.mjs:182`)、事实装配 `evaluateAttachReady()`(`src/ui/pty-attach.ts:1371`)、committed view 机制、以及 #265 的 cap 时 idle-downgrade 特判块都已存在**。本 spec 的改动是在这些既有结构上的增量,不是从零新建。父 spec §3(协议语义)、§6(U1/U2 步骤)、§8(风险反思)继续有效,本 spec 不重复,只做增量引用与锚定。
|
|
13
|
+
|
|
14
|
+
**降级语义的关键澄清(R1-G1)**:父 spec D3 条件 5 明确允许降级的 coverage 形态包括 candidate-open、candidate-aborted、缺少 witness 证据与已显式丢失 witness——即「runner 协议候选未结束」是**可降级**状态;必须继续等待的是「本地同步帧未闭合」(frameState/openSyncBlock)与「传输/解析/身份校验失败」(proofStatus=invalid)。两者在本 spec 中由不同谓词表达,不得混用。candidate-open/aborted 有**两种真实到达形状**(R2-G1):快照内 `coverageFor` 产生的 `unavailable+candidate-*`,与 live 记录 `noteViewProofRecord`→`invalidateViewProof` 产生的 `unknown+candidate-*`——归纳表两者都归 missing。
|
|
15
|
+
|
|
16
|
+
## 1. 要解决的问题
|
|
17
|
+
|
|
18
|
+
#265 恢复了 F 门禁(busy attach P95 2541.6→54.1ms)并在 2500ms cap 提供了 idle downgrade,但降级出口太晚:**普通(非 fullscreen)会话的同尺寸 attach——子进程有输出、committed view 已安全、但不存在也不会有覆盖 F——仍要等满 `ATTACH_HARD_TIMEOUT_MS=2500` 才揭示**(`handleAttachHardTimeout` :1120-1140 特判块)。这是 #267 跟踪的 ~2500ms 残留的主要形态。
|
|
19
|
+
|
|
20
|
+
次要问题:capability loss(`frameWitness.enabled:false`,#280 后成为真实撤销路径)当前触发 `restoreLegacyDeadlines()` 回退 legacy 等待策略(:2349-2354),与现代协议的安全呈现路径不一致;且 `finishAttachTransition()` 将 `notReadyReason` 置 null,publish 时不区分「F 证明就绪」与「预算降级」,诊断无法回答「这次 attach 为什么显示了」。
|
|
21
|
+
|
|
22
|
+
## 2. 不变量(继承 + 新增)
|
|
23
|
+
|
|
24
|
+
继承父 spec §3 全部协议不变量(S/F 同 write 可能、A 非证明、openFrameId 仅协议层、geometry 门禁需真实目标 F、S 必须在 write 的 OPEN 偏移内联等——#280 已实现协议侧)。新增 UI 侧不变量:
|
|
25
|
+
|
|
26
|
+
- **I1(降级不伪造证明)**:`committed-degraded` 发布永不把 `latestViewProof.status` 改成 covered,永不写入 proof/marker/seq;它只发布已存在的 committed view。
|
|
27
|
+
- **I2(单次副作用)**:attach 转换副作用(`finishAttachTransition` 中的 color bridge、first-attach hooks 等)至多执行一次,降级路径与 F 路径共用同一入口。
|
|
28
|
+
- **I3(身份防栏)**:任何发布(含降级)必须通过 `canPublishAttachView(viewIdentity, currentIdentity)`;过期 token/callback、换代 baseline、reset 后的旧 view 一律拒绝。
|
|
29
|
+
- **I4(输入门禁不受降级影响)**:`childInputReady`、child 生命周期、selection/copy 视图来源、首 attach 副作用的既有门禁不因 committed-degraded 提前放行。
|
|
30
|
+
- **I5(预算不重置、不降低门禁)**:恢复预算从 attach 开始一次性计时,普通输出与重连(`startAttachSettle` 重入)不重置不延长;预算到期只新增「可降级」这一条出路,**不放宽 F 路径的任何既有门禁**——boot/raw/启动占位等内容等级拒绝是两条路径共享的前置门禁(见 3.1 谓词 7)。
|
|
31
|
+
- **I6(锁存与视图失效分层,R1-G3 + R2-D1 修订)**:失效分三层。**锁存层**:`witnessLatched`(本 attach 曾观察到 witness 能力)属于组件实例,只在 detach/dispose/新建 UI 组件时消失——同组件内的 socket/connection 重连**保留锁存**(重连不重置锁存,但旧 view/proof 失效)。**视图层**:baseline 替换、reset、resnapshot、connection 换代失效旧 view/旧 proof(凭新身份的新快照或合法闭合帧重建),不影响锁存。**失败事实层**:当前 baseline 的 invalid 分类(连续性/身份/校验失败)是 sticky 事实,capability loss 置空 `latestViewProof` 不抹掉它(见 3.1.1)。
|
|
32
|
+
|
|
33
|
+
## 3. 修复设计
|
|
34
|
+
|
|
35
|
+
### D3(修订版):250ms 恢复预算 + 策略化的降级发布
|
|
36
|
+
|
|
37
|
+
**3.1 策略函数扩展(`decideAttachPresentation`,src/core/pty-attach-render.mjs)**
|
|
38
|
+
|
|
39
|
+
在既有谓词链(F 门禁 → `publish/"complete"`)之后、返回 wait 之前,新增降级谓词链。新增输入(全部为事实,策略保持纯函数):
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
witnessLatched?: boolean // 本次 attach 曾观察到 witness 能力(见 3.3)
|
|
43
|
+
committedViewValid?: boolean // committedView 非空且 canPublishAttachView 通过
|
|
44
|
+
committedViewSource?: "snapshot" | "sync-close" | "none"
|
|
45
|
+
committedViewCols/Rows?: number // committed view 的实际来源尺寸
|
|
46
|
+
committedContentKind?: "complete" | "boot" | "raw" | "partial" | "unknown" // R2-G4 新增、R4-D1 补 unknown,见谓词 7
|
|
47
|
+
proofStatus?: "none" | "missing" | "invalid" | "covered" // 见 3.1.1 归纳表
|
|
48
|
+
budgetElapsed?: boolean // 恢复预算已到(timer 事实,非策略计时)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
降级谓词链(全部满足才 `publish-degraded/"committed-degraded"`,任一不满足返回带具体原因的 wait):
|
|
52
|
+
|
|
53
|
+
1. `mode === "protocol" && witnessLatched === true`;
|
|
54
|
+
2. `baselineState === "valid-content"`(empty baseline 保持等待)且 `localParseComplete === true`;
|
|
55
|
+
3. `frameState === "complete" && openSyncBlock !== true && committedViewValid === true`——本地 parser 事实(在途 write、未闭合本地同步帧必须等待);**runner 协议候选状态不在此谓词**(candidate-open/aborted 经 proofStatus 走 3.1.1 的可降级分类,R1-G1 修订);
|
|
56
|
+
4. `committedViewCols === targetCols && committedViewRows === targetRows && resizeIntentRequired !== true`(实际来源尺寸匹配;不能凭 identity 写入了 target 就推定源快照是目标尺寸——父 spec §8.5 反例);
|
|
57
|
+
5. `proofStatus === "none" || proofStatus === "missing"`——仅「缺证据」可降级;`"invalid"`(传输/解析/身份校验失败,含 sticky invalid,见 3.1.1)必须继续等待(父 spec D3 条件 3 的区分);
|
|
58
|
+
6. `budgetElapsed === true`;
|
|
59
|
+
7. `committedContentKind === "complete"`(R2-G4 新增、R3-G2 修订语义)——**本谓词的 "complete" 指本地闭合完整性,不声称语义级 boot/raw 识别**(无 F 时不可判定,见 §4 非目标)。可判定的生产装配规则:`commitCommittedView` 在提交时记录来源 `source`("snapshot" | "sync-close",新事实字段);snapshot 来源(校验完整、非空、hydration 完成的快照)或 sync-close 来源(本地完整解析闭合的同步帧)→ "complete";无法建立本地闭合完整性 → "unknown" → wait(fail-closed);boot/raw/partial 保留为策略级防御值,当前生产装配不产出,未来出现可观测判定时再接入。与 F 路径的 boot-content/raw-content 拒绝构成两条路径共享的前置门禁(I5)。
|
|
60
|
+
|
|
61
|
+
优先级固定:F 路径谓词全过 → `publish/"complete"`(不等预算);否则降级链全过 → `publish-degraded/"committed-degraded"`;否则 wait(reason 保留首个失败谓词)。每个拒绝原因必须在 A06/A08 有反例(可测性拆分见 §5)。
|
|
62
|
+
|
|
63
|
+
**3.1.1 proofStatus 归纳表(R1-G2 新增、R2-G1/G3、R3-G1 修订;新纯函数,独立单测)**
|
|
64
|
+
|
|
65
|
+
输入 `(latestViewProof, stickyInvalid)`,输出四分类。`classifyProofStatus(viewProof, stickyInvalid)` 为纯函数,与策略同层待新增。
|
|
66
|
+
|
|
67
|
+
**sticky 优先规则(R3-G1)**:`stickyInvalid === true` 时,**除 `status=covered` 外的任何输入——包括 candidate-open/aborted(双形状)、no-proof、no-output、null、以及一切未识别值——一律归 `invalid`**。sticky 不可被同 baseline 的后续非 covered 状态清洗。**清除条件只有两个**:当前 baseline 身份上出现 covered(真实 F 恢复),或 baseline 身份更换(resnapshot 接受新快照后凭新身份重新评估)。任何 invalid 分类(含未识别值 fail-closed)置 sticky(绑当前 baseline/视图身份);capability loss 置空 latestViewProof 不清除(归纳表 null 行)。
|
|
68
|
+
|
|
69
|
+
非 sticky 时的基础分类表:
|
|
70
|
+
|
|
71
|
+
| 输入 | 归类 | 依据 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `null` 且 `stickyInvalid === false`(capability 撤销置空、初始未收到,且当前 baseline 无未恢复失败) | `none` | 父 spec:已显式丢失 witness / 缺少证据可降级 |
|
|
74
|
+
| `null` 且 `stickyInvalid === true` | `invalid` | R2-G3:loss 不能抹掉未恢复的失败事实,否则旧失败借降级绕过恢复(父 spec D3 条件 5 后半) |
|
|
75
|
+
| `status=covered`(exact-proof / safe-trailing) | `covered`(且清除 sticky) | F 健康路径;唯一恢复出口 |
|
|
76
|
+
| `unavailable + candidate-open`(快照内 coverageFor 形状) | `missing` | 父 spec 明确可降级 |
|
|
77
|
+
| `unavailable + candidate-aborted`(快照内 coverageFor 形状) | `missing` | 父 spec 明确可降级 |
|
|
78
|
+
| `unknown + candidate-open`(live 记录 `noteViewProofRecord(S)`→`invalidateViewProof` 形状,pty-attach.ts:1319) | `missing` | R2-G1:live S 的真实形状,同为「候选未结束」的可恢复状态 |
|
|
79
|
+
| `unknown + candidate-aborted`(live 记录 `noteViewProofRecord(A)` 形状,pty-attach.ts:1326) | `missing` | R2-G1:live A 的真实形状 |
|
|
80
|
+
| `unknown + no-proof` | `missing` | 有输出但从未有 proof 记录——缺证据 |
|
|
81
|
+
| `unknown + no-output` | `missing` | 无任何输出,无证据可判 |
|
|
82
|
+
| `unavailable + trailing-pending / trailing-unsafe` | `invalid`(置 sticky) | 需已有更早 proof(covered 后延伸),属「已覆盖又失效」——不绕过恢复 |
|
|
83
|
+
| `unknown + output-gap / journal-gap / journal-evicted / proof-evicted / snapshot-seq-future / snapshot-before-window / invalid-snapshot-seq` | `invalid`(置 sticky) | 连续性/窗口完整性存疑 |
|
|
84
|
+
| `unknown + invalid-view-proof / view-proof-future / records-dropped / proof-output-gap` | `invalid`(置 sticky) | 协议校验失败 |
|
|
85
|
+
| UI invalidateViewProof 的 `view-proof-replay-gap`、`view-proof-trailing-*` | `invalid`(置 sticky) | 传输/解析/身份校验失败 |
|
|
86
|
+
| **任何未识别的 status/reason** | `invalid`(置 sticky) | fail-closed,宁等不显 |
|
|
87
|
+
|
|
88
|
+
(表中各行在 `stickyInvalid === true` 时除 covered 行外均被 sticky 优先规则覆盖为 invalid。)
|
|
89
|
+
|
|
90
|
+
「covered 后又因身份/连续性失效」归类 invalid 且 sticky,与父 spec「不能借降级绕过恢复」一致。A06 对本表逐行断言(每行一个正例 + sticky 优先规则的清洗反例 + null×sticky 两态 + 未识别值默认 invalid 的 fail-closed 反例)。
|
|
91
|
+
|
|
92
|
+
**3.2 恢复预算 timer(组件层;R1-D1 + R2-G2 修订)**
|
|
93
|
+
|
|
94
|
+
- 新增独立常量 `ATTACH_RECOVERY_BUDGET_MS = 250`(策略数值待实施后按 U1 数据校准);从 `attachStartedAt` 起算,**在 attach 首次启动时 arm 一次**(按 remaining 计算),普通输出不 defer,重连/`startAttachSettle` 重入**不重新 arm、不延长 deadline**(I5);`finishAttachTransition`/detach/dispose 清理。
|
|
95
|
+
- **fence 生命周期(R2-G2)**:预算回调**不使用 `attachWaitToken` 防栏**(它在重连的 `startAttachSettle` 重入时递增,会与 armed-once 互相抵消——首次 arm 捕获的 token 过期、budgetElapsed 永不置位)。预算使用**独立的 attach 生命周期 fence**:回调仅校验 `attaching && !closed && budgetArmed`;预算事实(budgetElapsed)属 attach 生命周期,与连接换代无关;到期后旧连接的过期视图发布仍由 I3 的身份防栏(connectionToken)拦截。
|
|
96
|
+
- **待新增注入接缝**(现有 `attachStartedAt` 直取 `Date.now()`、timer 直用全局 `setTimeout`,`nowFn` 只服务 desync):组件构造器增加可注入的 `now()` 与 scheduler(或等价 fake-timer 接线),A07 的 249/250ms 边界与预算生命周期测试全部走注入时钟,不依赖 wall clock。
|
|
97
|
+
- timer 回调:fence 校验 → `budgetElapsed = true` → `evaluateAttachReady()`。
|
|
98
|
+
- `handleAttachHardTimeout` 的 idle-downgrade 特判块(:1126-1140)**删除**,cap 到期只置 `deadlineState="expired"` 诊断后调用 `evaluateAttachReady()`——降级判定完全由策略承担(预算 2500ms 前早已过期,行为等价于「预算早已到、仍不满足谓词则继续等」)。legacy 分支行为不变。
|
|
99
|
+
|
|
100
|
+
**3.3 committed 路径锁存(组件层;R1-G3 + R2-D1 修订)**
|
|
101
|
+
|
|
102
|
+
- 新增 `witnessLatched` 状态:本次 attach 内 `frameWitnessAvailable` 首次变 true 时置位一次;**capability loss(`enabled:false`)不清除锁存、不调用 `restoreLegacyDeadlines()`**(当且仅当已锁存)——runner 撤销能力后 UI 继续走 committed 呈现路径。
|
|
103
|
+
- **锁存生命周期按 I6 三层**:**同组件内的 socket/connection 重连保留锁存**(重连是 connectionToken 递增 + `startAttachSettle` 重入,不新建组件),但旧 view/proof 按 I3 失效、凭新连接的新快照重建;baseline 替换、reset、resnapshot 同样只失效旧 view/proof,锁存保持;detach/dispose/新建 UI 组件才重置锁存(新 attach 重新观察能力)。
|
|
104
|
+
- 未协商协议 / 无 witness 能力 / parser observer 不支持的旧会话:`attachMode !== "protocol"` 或从未锁存——保留原 legacy 分支与 settle/hard 超时,锁存不影响它们。
|
|
105
|
+
- capability loss 后无新闭合帧则旧画面保留(不假装刷新)——此限制记录进诊断并由 U2 验证。
|
|
106
|
+
|
|
107
|
+
**3.4 readyReason 诊断字段**
|
|
108
|
+
|
|
109
|
+
`finishAttachTransition` 增加来源参数,发布时记录 `readyReason: "complete" | "committed-degraded" | "legacy-settle" | "legacy-cap"`(策略 publish → complete;publish-degraded → committed-degraded;legacy 两分支 → legacy-*)。`notReadyReason` 语义不变(等待原因)。诊断记录新增 `budgetDeadline` 与 `readyReason`,只记数值与有限枚举。
|
|
110
|
+
|
|
111
|
+
### D4(修订版):统一汇合点重评
|
|
112
|
+
|
|
113
|
+
`evaluateAttachReady()` 已有 6 个调用点(capability 更新、baseline 状态、snapshot proof、proof payload、geometry satisfied、sync close)。本设计新增/调整:
|
|
114
|
+
|
|
115
|
+
- **新增**预算到期回调(3.2);
|
|
116
|
+
- **新增** `commitCommittedView` 成功后的重评钩子(预算已到而视图刚提交的 quiet→late-snapshot 场景,不再等下一个 cap——父 spec D4「预算到期时没有可用视图,以后安全快照到达时立即重评」);
|
|
117
|
+
- **保持**过期 callback 的 token/stream 身份防栏(既有 `attachWaitToken` 模式适用于连接相位回调;预算回调按 3.2 的独立 fence);
|
|
118
|
+
- **语义**:预算到期时无可用视图只记「已到期」;之后任一汇合点到达即重评。持续输出每帧闭合 → 预算后下一个 sync close 发布最近已提交帧;输出始终未闭合 → 继续等待(不保证有界首屏)。
|
|
119
|
+
|
|
120
|
+
### D5(修订版):诊断与性能范围
|
|
121
|
+
|
|
122
|
+
- 扩充既有 attach 诊断(非新增常驻服务):`readyReason`、`budgetDeadline`、`witnessLatched`、`committedView` 的身份/实际尺寸/来源与内容等级、`proofStatus` 与 sticky-invalid 事实、既有 `deadlineState/notReadyReason/publishabilityState/latestViewProof` 全量保留。只记数值与有限枚举,不记 token、屏幕文本、密钥、整条终端数据。
|
|
123
|
+
- 性能目标范围不变:现代协议、同尺寸、安全快照已提交、受控无 F 场景——真实 socket 自动化首屏 <1500ms(调度余量)且证明未等 2500ms cap;纯策略精确断言预算边界(A06 用注入的 `budgetElapsed` 布尔,249/250ms 边界在组件 harness 用注入 clock 断言);健康 F 路径证明在预算前完成。1500ms 不是产品目标,250ms 数值是待 U1 校准的策略选择。
|
|
124
|
+
|
|
125
|
+
## 4. 非目标
|
|
126
|
+
|
|
127
|
+
- 不改协议层(evaluator/reporter/hosted-frame-witness 的 #280 语义)。
|
|
128
|
+
- 不做通用 renderer、resize 协议、terminal parser 重写;不加后台服务或全局 watchdog。
|
|
129
|
+
- 不改 `childInputReady`/selection/copy/首 attach 副作用门禁(I4)。
|
|
130
|
+
- 不承诺 empty baseline、differing-size、未闭合输出的有界首屏;不承诺 legacy 会话 250ms。
|
|
131
|
+
- **不声称降级内容的语义级 boot/raw 识别**(R3-G2):无 F 时生产代码无法判定内容是启动占位还是业务终帧——本设计的 "complete" 只指本地闭合完整性(快照校验完整非空 / 同步帧完整解析闭合)。残余风险(本地闭合但 producer 未完成的半帧被降级显示)是降级语义的固有部分,由 `readyReason=committed-degraded` 显式标记、由 U1 内容正确性样本与 U2 验证兜底,不伪装成已证实。
|
|
132
|
+
- 不把 `attach-frame-witness.real.test.mjs` 的绿灯当 U1 完成。
|
|
133
|
+
|
|
134
|
+
## 5. 验收矩阵与可测性拆分(A06–A12 + U1/U2)
|
|
135
|
+
|
|
136
|
+
自动化分层:策略 unit(纯函数语义)→ 组件 harness(真实 xterm + 注入 clock/timer,UI 状态转移)→ runner integration(真实双 main + 真实 socket + 真实组件,端到端时序)。
|
|
137
|
+
|
|
138
|
+
| ID | 功能点 | 层级与命令 | 通过标准 |
|
|
139
|
+
|---|---|---|---|
|
|
140
|
+
| A06 | D3 策略边界(unit):budgetElapsed 注入布尔;F 先到立即 publish/"complete";proofStatus=invalid 不降级;七条谓词各设反例(witnessLatched=false / baseline 非 valid-content / frameState 非 complete / committedViewValid=false / 尺寸不匹配或 resizeIntentRequired / budgetElapsed=false / **committedContentKind 为 boot、raw、partial、unknown** 各自 wait 且 reason 具体);**candidate-open 与 candidate-aborted 双形状正向降级断言**(unavailable 与 unknown 两种到达形状,均经 proofStatus=missing);**A/unavailable 不变为 covered(covered 只能来自真实 F,沿用父 spec 措辞)**;**committed-degraded 发布不改写 latestViewProof/proof/marker/seq(I1 独立断言)**;已 covered 但有其他门禁时 wait 不降级;**3.1.1 归纳表逐行断言 + sticky 优先规则清洗反例:同 baseline invalid 后到达 live S/A、no-proof、null 均归 invalid 不被清洗,预算与 cap 均不发布(R3-G1)**;null×sticky 两态;未识别 status/reason 默认 invalid 的 fail-closed 反例 | unit,`node --test test/attach-recovery.test.mjs`(新文件,直接测扩展后的 `decideAttachPresentation` 与新纯函数 `classifyProofStatus`) | 全部反例 wait 且 reason 命名谓词;降级仅七条全过;归纳表逐行符合;sticky 不可被非 covered 状态清洗 |
|
|
141
|
+
| A07 | D3/D4 组件行为(注入 clock):quiet(预算到期回调发布)、每 25ms 完整帧持续输出(不重置预算、预算后下一 sync close 发布)、预算前/后才提交快照(late-snapshot 重评钩子)、249ms 不发布 250ms 发布、candidate-aborted 场景降级、**t<250ms 重连(`startAttachSettle` 重入)后预算仍在原 250ms deadline 到期(不延长);旧连接回调不能发布**(R2-G2 成对断言)、**至少一条用例经真实 `viewProofRecord` 的 S/A 驱动 candidate 状态**(不伪造合成 proof 对象,R2-G1) | 组件 harness,`node --test test/attach-recovery.test.mjs test/attach-recovery-component.test.mjs test/pty-attach-parser-replacement.test.mjs`;新 harness `test/attach-recovery-component.test.mjs` 驱动 `test-support/attach-recovery-scenario.ts`(真实 xterm、**注入 now/scheduler**,模式参照 parser-replacement scenario),纳入 `npm test` | 首屏只取 committed 内容;预算不被输出/重连重置;晚到快照立即重评;重连保 deadline |
|
|
142
|
+
| A08 | D3/D4 反例(组件):empty baseline、open sync、parser 在途、错代、reset/resnapshot、晚 callback(token 过期)、proofStatus=invalid、covered 又失效、**invalid→capability loss(proof 置 null)→ 预算与 cap 均不得发布(sticky-invalid 反例)**;**同 baseline invalid→live S/A 到达、invalid→no-proof 到达均不得发布(sticky 清洗反例,R3-G1);随后当前 baseline covered 或 baseline 身份更换才清除**;**内容等级守卫用可观测事实驱动**(empty/占位 baseline → wait;committed view 的 source 字段记录 snapshot/sync-close,不手工伪造枚举装配,R3-G2)、producer 未完但合成 snapshot 已闭合(只 committed-degraded 非 proof-ready,后续完成可更新)、锁存后 capability loss 仍 committed 路径、loss → resnapshot/baseline 更换 → 新身份快照/合法闭合帧到达后继续 committed 更新(成对断言)、loss 后无闭合帧保留旧提交(成对断言)、**同组件重连保留锁存、旧 view/proof 失效需新快照**(R2-D1)、副作用至多一次、childInputReady 不被降级提前放行 | 组件 harness,命令同 A07 | 每反例保持 loading 或仅保留有效旧提交;不显示本地解析中状态;loss 后锁存与新身份重建共存;sticky invalid 不被 loss/后续 S/A/no-proof 清洗 |
|
|
143
|
+
| A09 | D3 geometry:same-size 零 resize/新 intent;错尺寸/错 intent/revision 的 F、A、loss、全部 timer 不解除 gate;真实 target F 才解除;源快照旧尺寸而 identity 已标当前 target 的反例不发布(I3+3.1 谓词 4) | integration + 组件,`node --test test/attach-frame-witness.integration.test.mjs test/pty-attach-parser-replacement.test.mjs` 及 A07 组件入口 | geometry proof 不可伪造 |
|
|
144
|
+
| A10 | D4 生命周期:detach/dispose 清 timer(含预算 timer)、失效→新 capability 不复活旧 view、连接/stream 换代旧身份不发布、新身份需新快照、legacy 不受锁存影响、降级后 selection/copy 与显示来源一致、预算 armed 一次(重复启动不重 arm)、**同组件重连保留锁存(R2-D1)** | 组件 harness,命令同 A07 | token fence 与身份防栏全过;预算一次性;重连保锁存 |
|
|
145
|
+
| A11 | D5 端到端:真实双 main、受控 S 后 quiet 与持续完整帧无 F(真实 coverage 含 live unknown/unavailable 双形状)——首屏 <1500ms、内容正确、readyReason=committed-degraded、证明未等 2500ms;healthy F 在预算前完成且 readyReason=complete;**断言保持外部 wall-clock(settledMs<1500ms、未等 2500ms),不用注入时钟、不放宽容差**(R2-D2);flaky 治理靠确定性等待条件(poll 至 settle 条件)而非放宽门槛;**至少一条用例经真实 viewProofRecord S 驱动**(R2-G1) | integration,扩充 `test/attach-frame-witness.integration.test.mjs` 与 `test-support/attach-idle-socket-driver.ts`;**改写** :306「S-then-idle at the legacy cap」为预算断言 | <1500ms + readyReason 正确 + 无 2500ms 等待 |
|
|
146
|
+
| A12 | 回归总量:typecheck、perf gate、tests、coverage、pack:dry;legacy 反例、#227 Kitty 回归、#275 快速路径、leaked coordinators | `npm run verify`(实施 worktree 内) | 全过,不得只以 `npm test` 代替 |
|
|
147
|
+
| U1 | 全新 fullscreen 会话首次 attach 隔离试点(≥10 首次 + 10 reattach 样本,P50/P95、readyReason 分布、按父 spec §4.1 报告成功率) | 用户实测,步骤按父 spec §6(worktree 绝对路径 entry/runner、隔离 PI_CODING_AGENT_DIR/board root/socket) | 样本齐全如实报告;任何 >预算样本注明阻塞门禁 |
|
|
148
|
+
| U2 | 不同尺寸、旧新版本组合与故障恢复(target F 后正常、loss 不伪造 geometry、混合版本兼容、全旧组合 legacy 策略保留、锁存后 loss → resnapshot 恢复序列与无闭合帧旧画面限制确认) | 用户实测,步骤按父 spec §6 | 如实报告 |
|
|
149
|
+
|
|
150
|
+
**可测性拆分设计(硬约束)**:① 策略扩展保持纯函数——`budgetElapsed`/`witnessLatched`/`proofStatus`/`committedContentKind` 等全部由调用方装配为事实传入,策略内不读时钟不读 socket(A06 直接单测谓词矩阵);② **`classifyProofStatus(viewProof, stickyInvalid)` 是独立纯函数**(3.1.1 表的唯一实现源),sticky 事实的记录/清除是组件层职责,独立单测;③ 预算 timer/fence/锁存/readyReason 属组件薄 I/O 层,经注入 now/scheduler 的组件 harness 测(A07/A08/A10),不进策略;④ 集成层只测协议端到端时序与诊断(A09/A11),不重复策略语义。实施不得把①②的纯函数逻辑耦合回组件。
|
|
151
|
+
|
|
152
|
+
## 6. 实施边界
|
|
153
|
+
|
|
154
|
+
- 允许改动:`src/core/pty-attach-render.mjs`(策略扩展)、新纯函数 `classifyProofStatus`(落位同文件或新 `src/core/attach-recovery.mjs`,实施计划定)、`src/ui/pty-attach.ts`(预算 timer 与独立 fence、锁存、sticky-invalid 事实、committedContentKind 装配、汇合点、readyReason、cap 特判删除、注入 now/scheduler 接缝)、上述测试与 test-support、诊断记录。
|
|
155
|
+
- 既有安全测试重写预期:`attach-frame-witness.integration.test.mjs:306` 及相关 cap 断言改为预算断言;empty/错尺寸/错代/解析未完反例**保留**。`attach-entry-22.test.mjs:100`(忙场景测量窗口)与 B/Q 200ms 发布预算经调研确认不受影响,**不改**;实施时如受影响按同一原则改写并说明。
|
|
156
|
+
- 保留 #227 grid/图像前缀与 bridge 生命周期、#275 快速路径。
|
|
157
|
+
- 提交按 task 分层可回退(策略+归纳函数 → 组件 → 集成/诊断),各阶段定向测试先行(TDD);worktree 内实施,main 保持干净。
|
|
158
|
+
|
|
159
|
+
## 7. 风险与反例(增量引用父 spec §8)
|
|
160
|
+
|
|
161
|
+
父 spec §8.1–8.7 的风险与反例全部继续有效,本节只列锚定增量:
|
|
162
|
+
|
|
163
|
+
- **§8.1 提前呈现(最高风险)**:降级谓词链的每个「不满足即 wait」都是防提前呈现的反例;`proofStatus=invalid`(含 sticky invalid 的优先规则——同 baseline 后续 S/A/no-proof/loss 均不可清洗、trailing-pending/unsafe、连续性缺口、协议校验失败、未识别值 fail-closed)不可降级,防「传输坏但时间到了就显示」;内容等级守卫用可观测事实(本地闭合完整性 + source 字段),不虚构语义判定(R3-G2);A08 逐反例覆盖。
|
|
164
|
+
- **§8.4 呈现锁存的新形态**:锁存后 capability loss 不回 legacy——若 runner 反复撤销/重建能力,UI 必须稳定停留在 committed 路径;loss 后 resnapshot 凭新身份重建 view(I6 分层),无新闭合帧时旧画面保留是**已知限制**,U2 专项确认,不作为缺陷掩盖。sticky invalid 在 loss 后保持,防「失败→撤销→降级」绕过链(R2-G3)。
|
|
165
|
+
- **#263 教训的延续**:降级出口必须保留(本设计把出口提前而非移除);若 #284 后再出现「witness 停帧永久等待」,按序怀疑:proofStatus 归纳把可降级态误归 invalid(检查 3.1.1 表与真实 reason——含 unknown/unavailable 双形状——的对齐)→ sticky invalid 清除条件过严(清除只有 covered 与 baseline 更换两途)→ #280 协议修复未覆盖的新路径。
|
|
166
|
+
- **预算数值风险**:250ms 是策略选择非验证指标;U1 数据若显示 committed view 常晚于 250ms 才安全提交,调大预算或改「预算+最近闭合帧」语义,不在 U1 前硬编码调小。
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Spec — host 重启不得覆盖会话内 /model 与 /thinking 选择(issue #286)
|
|
2
|
+
|
|
3
|
+
Drafted: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-08T09:30:11+08:00
|
|
4
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-08T09:38:00+08:00(R1-D1~D4 四条细化全接受)
|
|
5
|
+
|
|
6
|
+
调研依据:`research/root-cause-and-pi-restore-semantics.md`(本目录)。本文只写设计与验收,证据细节见调研文件。
|
|
7
|
+
|
|
8
|
+
## 0. 问题与根因(一句话版)
|
|
9
|
+
|
|
10
|
+
board 的三条 spawn 路径把 view 创建参数 `meta.defaultModel`/`meta.defaultThinking` 显式拼成 `--model`/`--thinking` 传给子 pi;而 pi 只在**没有**显式 flag 时才从会话恢复模型/thinking(恢复源:branch 上最新 `model_change`,否则最新非虚拟 assistant 消息的物理模型)。进程任何原因重建(warm-host TTL 回收、超额挤掉、崩溃、board 重启、attach 冷启动、后台 job-runner)都会把用户在会话内 `/model`、`/thinking` 的选择悄悄重置回 view 创建时的值。
|
|
11
|
+
|
|
12
|
+
## 1. 修复设计(方案 A 精化:按「会话可恢复性」决定是否传 flag)
|
|
13
|
+
|
|
14
|
+
### 1.1 决策表(唯一权威)
|
|
15
|
+
|
|
16
|
+
对每次 spawn,按会话 JSONL 的 **active branch**(root→leaf 路径,leaf 缺省为文件最后一条 entry)判定:
|
|
17
|
+
|
|
18
|
+
| active branch 状态 | `--model` | `--thinking` |
|
|
19
|
+
| --- | --- | --- |
|
|
20
|
+
| 无 message 条目(文件缺失/空/不可解析/仅有非 message 条目) | 传 `meta.defaultModel`(现行为) | 传 `meta.defaultThinking`(现行为) |
|
|
21
|
+
| 有 message,且(有 `model_change` 或有 assistant message 条目) | **不传**(pi 从会话恢复) | 见下行 |
|
|
22
|
+
| 有 message,但既无 `model_change` 也无 assistant message | 传(pi 恢复不出来,回落 settings 默认会丢 view 意图) | 见下行 |
|
|
23
|
+
| 有 message,且有 `thinking_level_change` 条目 | 见上行 | **不传**(pi 从会话恢复) |
|
|
24
|
+
| 有 message,但无 `thinking_level_change` 条目 | 见上行 | 传(pi 此时会恢复 settings 默认而非 view 值,传才能保住 view 意图) |
|
|
25
|
+
|
|
26
|
+
两个维度独立判定(会出现只丢一个 flag 的情况)。
|
|
27
|
+
|
|
28
|
+
判定依据(pi 1.5.0 `createAgentSession`,源码级核对):
|
|
29
|
+
- 模型恢复门槛 = `!显式model && messages.length>0 && getBranchSelection(branch)≠undefined`;`getBranchSelection` 倒扫 branch:最新 `model_change` 直接胜出,否则最新非虚拟 assistant 消息的物理模型胜出。
|
|
30
|
+
- thinking 恢复 = `显式thinking===undefined && messages>0`;但无 `thinking_level_change` 条目时恢复的是 **settings 默认**,不是 view 的 defaultThinking。
|
|
31
|
+
- pi 新建会话时无条件写 `model_change` + `thinking_level_change`(记录启动时解析的值);恢复已有会话时不写 model_change、只在缺 thinking 条目时补写。因此 board 创建的会话「出生即带两个条目」,上表第 2/4 行是常态,第 3/5 行只出现在历史遗留/外部构造的会话上。判定条件镜像 pi 恢复门槛的**正常路径语义**;病态会话(如 `context_edit` 全量擦除投影)不做逐条目精确镜像,差异与方向见 §5。
|
|
32
|
+
|
|
33
|
+
### 1.2 组件契约
|
|
34
|
+
|
|
35
|
+
**新增 `src/core/session-entries.mjs`(纯函数,无 I/O)**——从 `session-view.mjs` 抽取的会话结构原语,单一分支语义源:
|
|
36
|
+
- `parseSessionEntries(text) -> { header, entries, byId }`:逐行 JSON.parse,坏行/非对象/无 `id` 的行跳过;`type==="session"` 的行提取为 header(不进 entries)。行为与现 `session-view.mjs` 的 parse 循环一致(重构搬运,不改语义)。
|
|
37
|
+
- `activeBranchEntries(entries, byId) -> Entry[]`:leaf = `entries[entries.length-1]`,沿 `parentId` 走到根,`seen` 集合防环,返回 root→leaf 顺序。行为与现 `activeBranch` 一致。
|
|
38
|
+
- `session-view.mjs` 重构为调用这两个函数(`parseSessionText` 对外签名与返回值不变)。
|
|
39
|
+
|
|
40
|
+
**新增 `src/core/session-launch-prefs.mjs`(纯函数,无 I/O)**——策略层:
|
|
41
|
+
- `resolveLaunchModelPrefs(defaults, text) -> { model, thinkingLevel, droppedModel, droppedThinking }`
|
|
42
|
+
- `defaults = { model: string|null, thinkingLevel: string|null }`(来自 meta)
|
|
43
|
+
- `text`:会话 JSONL 全文;`null`/`""` 视为不可恢复
|
|
44
|
+
- 返回 effective 值:可恢复维度 → `null`(并置 dropped=true),不可恢复 → 原值透传
|
|
45
|
+
- 判定只依赖 1.1 决策表,不读文件、不看时钟
|
|
46
|
+
|
|
47
|
+
**`src/runtime/service.mjs`(薄 I/O 壳)**:
|
|
48
|
+
- 闭包内新增 `resolveViewLaunchPrefs(meta)`:读 `meta.sessionFile`(缺失/读失败 → text=null),调 `resolveLaunchModelPrefs`;若 droppedModel||droppedThinking,`appendDiagnostic(root, meta.id, { source:"service", code:"launch_prefs_from_session", message:"Launch model/thinking left to session restore", details:{ droppedModel, droppedThinking } })`。
|
|
49
|
+
- 三处 spawn 点接入(effective 值进 config):
|
|
50
|
+
1. `launchForView`(RunConfig 的 `model`/`thinkingLevel`,:253-254)
|
|
51
|
+
2. `startHostUnderLease`(HostConfig 的 `model`/`thinkingLevel`,:368-369)
|
|
52
|
+
3. `adoptClaimedHost`(HostConfig,:1445-1446)
|
|
53
|
+
- 守卫改造:`validateViewModelMeta(meta)` 改为接收 **effective model**(签名变为 `validateViewModelMeta(effectiveModel)`):effective 为 `null` → 直接放行(此时不传 flag,子进程不存在 exit-1 死循环风险,且顺带缓解 #90 的「dead defaultModel + 会话可恢复」场景);非 null → 与今天语义一致(`modelRefAvailable` 判定不变)。`startHostUnderLease` 在 claim 前、`adoptClaimedHost` 在组 config/spawn 前(它接管的是已存在的废弃 claim,没有「claim 前」时点;`service.mjs:1413-1446` 顺序:tryAcquireLock → readHost 复核 → validateViewModelMeta → 组 config → spawn),各自先算 effective 再过守卫;`launchForView` 路径今天无守卫,保持无守卫。
|
|
54
|
+
- **runner 零改动**:`pty-runner.mjs`(:525-526/:1366-1367)与 `job-runner.mjs`(:168-169)已是 `if (config.model) push("--model", ...)` 的 falsy 跳过语义,config 值为 null 时自然不拼 flag。
|
|
55
|
+
|
|
56
|
+
### 1.3 数据流(不变部分省略)
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
attach/reply/dispatch → service spawn 点
|
|
60
|
+
→ resolveViewLaunchPrefs(meta) [读 sessionFile,一次]
|
|
61
|
+
→ resolveLaunchModelPrefs(defaults,text)[纯函数,按决策表]
|
|
62
|
+
→ effective model 过 #90 守卫(startHost/adopt 路径)
|
|
63
|
+
→ config.model / config.thinkingLevel [null 或原值]
|
|
64
|
+
→ runner: config.model 为 falsy → argv 不含 --model
|
|
65
|
+
→ 子 pi: 无显式 flag → createAgentSession 走会话恢复分支
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 1.4 降级与边界
|
|
69
|
+
|
|
70
|
+
- 会话文件读取失败(IO 错误/权限):`text=null` → 两个 flag 照传(完全等于今天的行为,fail-safe 到现状)。
|
|
71
|
+
- 半写行(spawn 时理论上无并发写;极端时序下最后一行撕裂):坏行被 parse 跳过,判定基于完整行;最坏效果是多传一次 flag(=今天行为),不会错丢。
|
|
72
|
+
- 大会话文件(数 MB):冷启动路径上一次性 `readFileSync`+逐行 parse,`session-view` 预览已同样做法,量级可接受;不做流式优化(非目标)。
|
|
73
|
+
- pi 恢复失败(会话里的模型已不可用):pi 自身有 `modelFallbackMessage` + `findInitialModel` 兜底,子进程正常启动,不会 exit-1 循环——这正是丢 flag 比硬传 dead id 更安全的原因。
|
|
74
|
+
- 外部 adopt 的会话(`isExternalSession`):走同一 `startHostUnderLease`,判定同样生效——adopt 后会话自身的模型选择优先于 adopt 时快照,符合本 issue 的意图。
|
|
75
|
+
- `piArgsPrefix` 里若被人为配置了 `--model`,本修复不覆盖(该前缀语义是用户级注入,保持原样)——保证边界,见 §5。
|
|
76
|
+
|
|
77
|
+
## 2. 非目标
|
|
78
|
+
|
|
79
|
+
- 方案 B(子进程上报 `model_select`/thinking 变更回写 `meta.defaultModel/defaultThinking`,让 dashboard 与后续 launch 反映当前选择)——独立增强,不属本 issue。
|
|
80
|
+
- #90 的完整修复(dead defaultModel 且会话**不可**恢复时的 UX 引导)——本修复只让守卫输入变为 effective model,空会话行为不变。
|
|
81
|
+
- dashboard 行的 model 展示(`statusFromRow` :880 仍显示 defaultModel)——展示语义随方案 B 一并考虑。
|
|
82
|
+
- 大会话文件的流式/增量读取优化。
|
|
83
|
+
- `piArgsPrefix` 注入 flag 的清理。
|
|
84
|
+
|
|
85
|
+
## 3. 验收矩阵
|
|
86
|
+
|
|
87
|
+
| ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
|
|
88
|
+
|----|--------|----------|----------|----------|
|
|
89
|
+
| A0 | `session-entries` 底座(parse + branch 走查) | 自动化验证(unit) | `node --test test/session-entries.test.mjs`(新文件) | 解析:header(`type==="session"`)提取、无 `id` 行跳过、坏行跳过;走查:root→leaf 顺序、废弃分支条目被排除、`parentId` 断链时止于可达段、环防护生效 |
|
|
90
|
+
| A1 | `resolveLaunchModelPrefs` 全分支策略 | 自动化验证(unit) | `node --test test/session-launch-prefs.test.mjs`(新文件,构造 JSONL 文本直接喂纯函数,含分叉树用例) | 1.1 决策表每一行至少一个用例:缺文件代 null/空文本/纯垃圾行→透传;user-only→透传 model;assistant(无 model_change)→丢 model;model_change+message→丢 model;model_change 无 message→透传;thinking 条目+message→丢 thinking;thinking 条目无 message→透传 thinking;混合→两丢;defaults 本身为 null→返回 null 且 dropped 语义正确;分叉树(废弃分支上有 model_change、active 链上没有→透传;active 链上有→丢) |
|
|
91
|
+
| A2 | `session-view.mjs` 重构回归(对外行为不变) | 自动化验证(unit) | `node --test test/session-view.test.mjs`(现有用例)+ 新增 2 个用例:header 提取、无 `id` 行跳过(搬运中最易丢的两点语义) | 新旧用例全部通过 |
|
|
92
|
+
| A3 | 三条 spawn 路径 config 生效 | 自动化验证(integration) | 扩展 `test/service.test.mjs` / `test/host-resolver.test.mjs` 现有 harness(temp root + `createView` + 写 session fixture + 覆写注入的 `launch`/`launchHost` 捕获 config):可恢复会话 vs 空/不可恢复会话两组,覆盖 `ensureHost`(→ startHostUnderLease)、adopt 恢复路径、`launchForView`(dispatch 与 json-runner reply 路径) | 可恢复 → 捕获的 config.model/thinkingLevel 为 null 且 diagnostics 有 `launch_prefs_from_session`;不可恢复 → 原值透传且无该 diagnostic |
|
|
93
|
+
| A4 | #90 守卫按 effective model 判定 | 自动化验证(integration) | 现有守卫用例(`host-resolver.test.mjs` 两处,fixture 为空会话)必须原样通过;新增用例:dead defaultModel + 可恢复会话 fixture(model_change+assistant)→ `ensureHost` 放行且 config.model=null | 空会话守卫行为与 main 一致;可恢复会话不再被 dead defaultModel 拦截 |
|
|
94
|
+
| A5 | runner argv 映射 | 自动化验证(unit) | `test/runner.integration.test.mjs` 的 fake-worker 模式新增断言:config.model=null → 记录的子进程 argv 不含 `--model`/`--thinking`;config 有值 → 含(证明映射方向) | null → argv 无两个 flag;非 null → 有 |
|
|
95
|
+
| U1 | 真实冷启动恢复(模型) | 用户实测 | 合并后(部署前置:扩展从本仓 symlink 加载,需 `git pull` 主 checkout 后新起 board):取一个「最后 `/model`=B、defaultModel=A」的会话,stop host(或等 TTL 回收)→ attach 冷启动 | 子 pi footer 显示 B;会话 JSONL 不新增 model_change;该 view 的 diagnostics 出现 `launch_prefs_from_session` |
|
|
96
|
+
| U2 | 真实冷启动恢复(thinking)+ 长期不再回退 | 用户实测 | 同 U1 会话先 `/thinking` 调档再冷启动验证 thinking;之后日常使用数天(跨 warm-host 回收/board 重启)抽查 footer | thinking 保持会话内最后选择;模型数天内不再自动回退到 A(对照 issue 里的 5–24s 重置现象消失) |
|
|
97
|
+
|
|
98
|
+
自动化验证层级选择说明:A0–A2 是纯函数 → unit;A3/A4 跨 service/文件系统/守卫多组件 → integration(沿用现有 service 级 harness,不起真子进程);A5 需要真 runner 进程产 argv → 现有 runner 集成测试同层级;完整「真 pi 子进程恢复」依赖真实终端 UI 与真实模型目录,属外部系统 → U1/U2 用户实测(合并后、主 checkout 拉取后可执行,时机与前置已写明),不用假 E2E 冒充。所有自动化验收项(A0–A5)在实现完成时随全量 `npm test`(含 coverage 门,出处 AGENTS.md「Commands」)整体回归一遍,作为重构类改动的总闸。
|
|
99
|
+
|
|
100
|
+
## 4. 可测性拆分设计(实现阶段的硬约束)
|
|
101
|
+
|
|
102
|
+
- `parseSessionEntries(text)` / `activeBranchEntries(entries, byId)`:纯函数,`test/session-entries.test.mjs`(新,验收 A0)直测解析/走查/坏行容错/防环;`session-view` 重构的对外行为回归由验收 A2 承接(现有 `test/session-view.test.mjs` + 补 header/无-id 两用例);分叉树下的策略行为归 A1(经 `resolveLaunchModelPrefs` 端到端喂分叉文本)。
|
|
103
|
+
- `resolveLaunchModelPrefs(defaults, text)`:纯函数,A1/A2 的唯一被测对象;不碰 fs/时钟。
|
|
104
|
+
- service 闭包 `resolveViewLaunchPrefs(meta)`:唯一 I/O 点(readFileSync + diagnostic);不经单测直接 mock,而由 A3/A4 integration 用真实临时文件穿过(I/O 壳保持薄到不值得单测)。
|
|
105
|
+
- 测试边界:策略正确性全部压在纯函数层;integration 层只验证「config 真的带上了 effective 值」与「守卫真的按 effective 判定」,两层各自独立失败、互不重复。
|
|
106
|
+
- 实现不得把策略判定内联进三个 spawn 点(会三处漂移),也不得把 fs 读取塞进 `session-launch-prefs.mjs`(破坏纯函数边界)。
|
|
107
|
+
|
|
108
|
+
## 5. 保证边界(明说做不到/不保证的)
|
|
109
|
+
|
|
110
|
+
- 本修复让「重启后与会话内最后选择一致」依赖 **pi 自身的恢复正确性**;pi 恢复行为的正确性是 pi 的契约,本仓只保证「不再用创建参数覆盖它」。
|
|
111
|
+
- 虚拟模型的路由语义由 pi 的 `model_change`(含创建时写入的虚拟选择)承载,本仓不解析、不判断虚拟性(布尔判定无需感知虚拟模型,见调研 §2 推论③)。
|
|
112
|
+
- 历史 pi 版本创建、无 `model_change`/`thinking_level_change` 条目的会话:按决策表 3/5 行透传 view 默认值,不尝试补写会话。
|
|
113
|
+
- 病态会话(`context_edit` 置空 replacement 等全量擦除投影):pi 侧 `buildSessionContext().messages` 可能为 0(视作新会话),而 board 按原始条目判定可恢复而丢 flag——此时首轮模型取 pi 的回落值(settings 默认),不保证等于 view 默认;接受此角落差异(fail 方向是「一轮模型异常、用户可 `/model` 纠正」,仍优于硬传 dead id)。反向(branch 上只有 custom/summary 类投影条目、board 视为不可恢复而透传 flag)等于今天的行为,fail-safe。
|
|
114
|
+
- 若用户在**空会话**(从未有过消息)上重启,行为与今天完全一致(传创建参数)。
|
|
115
|
+
- diagnostics 的 `launch_prefs_from_session` 只在冷启动判定时写,不承诺实时反映会话内选择(那是方案 B)。
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Issue #288 Spec — cap 地板降级:trailing-unsafe 锁死的解锁出口
|
|
2
|
+
|
|
3
|
+
Drafted: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-08T17:40:00+08:00
|
|
4
|
+
Revised: zai-coding-cn/glm-5.3 (selected) · zai-coding-cn/glm-5.3 (physical) @ 2026-11-08T18:20:00+08:00(round-1 复核 R1-G1/G2/G3 接受修订,R1-D1/D2/D3 接受细化)
|
|
5
|
+
Base: main @ a439b36(#284/#285 已合并)
|
|
6
|
+
Status: v2-final(round-2 收敛:0 真缺口;收敛后吸收 R2-D1 细化:§0 总述限缩为 trailing-only 条件地板)
|
|
7
|
+
|
|
8
|
+
## 0. 关系与继承
|
|
9
|
+
|
|
10
|
+
本 spec 修复 #284 引入的回归(#288):idle fullscreen 会话 reattach 因 `trailing-unsafe` proof 被归为 sticky invalid 而永久锁死。**全部继承 #284 spec v4-final 的不变量 I1–I6、归纳表与谓词语义**;本 spec 只做两处增量:D1 cap 地板降级、D2 等待态诊断落盘。trailing-only 条件下的 cap 出口由此恢复:对「trailing 家族失败、且其余六条降级谓词均满足」的 committed view,最坏约 2500ms 必能进入;hard 族、identity/geometry 失败、未闭合帧等仍按既有门禁等待(见 §3 I8 与 §4 非目标)。
|
|
11
|
+
|
|
12
|
+
## 1. 要解决的问题
|
|
13
|
+
|
|
14
|
+
现场与根因见 issue #288(live 探针证据:`unavailable + trailing-unsafe / csi-unknown`,proof 停在 seq 142,nvim idle 无 F,用户被锁在 attach 门外)。锁死链:恢复需要 F → F 需要子进程动 → 子进程动需要用户输入 → 输入需要 attach 成功。#284 把 trailing-* 归为 sticky invalid 在「连续性存疑」意义上正确,但没给这个家族留任何时间性出口——#263 教训(降级出口必须保留)被违反。
|
|
15
|
+
|
|
16
|
+
**trailing 失效的两种真实到达形状(R1-G2)**:runner 快照内 `coverageFor` 产生的 `unavailable + trailing-pending/trailing-unsafe`,与 UI 本地路径产生的 `unknown + view-proof-trailing-pending` / `unknown + view-proof-trailing-<reason>`(`noteViewProofOutput` 的 live 输出与 F 后 replay 产生)。cap 地板必须同时覆盖两者,否则第二条生产路径仍会锁死。
|
|
17
|
+
|
|
18
|
+
## 2. 修复设计
|
|
19
|
+
|
|
20
|
+
### D1:cap 地板降级(策略层 + 组件装配)
|
|
21
|
+
|
|
22
|
+
**新纯函数** `classifyProofInvalidFamily(viewProof) -> "trailing" | "hard" | null`(null = 输入非 invalid 形状):
|
|
23
|
+
|
|
24
|
+
- trailing 家族(可被 cap 恢复):`unavailable + trailing-pending / trailing-unsafe`(runner 快照形状);`unknown + view-proof-trailing-pending`;`unknown + view-proof-trailing-<identifier>`(identifier 仅接受小写字母数字与连字符的严格形式——畸形值不进 trailing,防任意字节借前缀)。
|
|
25
|
+
- hard 家族(cap 不可恢复):其余一切 invalid 归类(output-gap/journal-*/proof-evicted/snapshot-*/invalid-view-proof/view-proof-future/records-dropped/proof-output-gap/view-proof-replay-gap/未识别值)。
|
|
26
|
+
- fail-closed:未识别值 → `"hard"`。
|
|
27
|
+
|
|
28
|
+
**hard 占优的 baseline 锁存(R1-G1)**:组件维护 `proofHardInvalidatedThisBaseline`(绑定当前 baselineToken):当前 baseline 上任何一次 `classifyProofInvalidFamily === "hard"` 的 invalid 分类即置位;**hard 占优——置位后即使后续形状变为 trailing/non-covered/loss 也不复位**;清除条件与 sticky 相同:仅 F 路径策略 publish 或 baseline 身份更换。策略新输入 `capRecoverable := !proofHardInvalidatedThisBaseline`(组件装配的布尔事实)。
|
|
29
|
+
|
|
30
|
+
**策略扩展**:`decideAttachPresentation` 新增可选输入 `capRecoverable`;谓词 5 修改为:
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
deadlineState !== "expired" 时(现状不变):
|
|
34
|
+
proofStatus ∈ {none, missing} 才通过;invalid → wait "proof-status-invalid"
|
|
35
|
+
deadlineState === "expired" 时(cap 地板):
|
|
36
|
+
proofStatus ∈ {none, missing} ∪ {invalid ∧ capRecoverable === true} 通过;
|
|
37
|
+
invalid ∧ capRecoverable !== true → wait "proof-status-invalid"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
(expired 语义下 wait reason 沿用既有 `wait` helper 的 `deadline-expired:` 前缀规则——expired 分支的 hard-invalid 拒绝 reason 为 `deadline-expired:proof-status-invalid`,pending 分支为 `proof-status-invalid`,与既有组件断言的前缀约定一致,R1-D3。)
|
|
41
|
+
|
|
42
|
+
其余六条谓词(witnessLatched / baseline / 本地帧闭合+committedView / 尺寸+intent / budgetElapsed / committedContentKind)与优先级完全不变;budgetElapsed 在 cap 时必然已 true。cap-floor 走 `publish-degraded/"committed-degraded"`——readyReason 枚举不扩,靠同一条 settle 诊断记录的 `deadlineState:"expired"` + `proofStatus:"invalid"` 区分于预算降级。
|
|
43
|
+
|
|
44
|
+
**sticky 与 hard 锁存都不因 cap-floor 清除**:cap-floor 的 publish-degraded 不清除 `proofInvalidatedBaselineToken`、不清除 `proofHardInvalidatedThisBaseline`(只有 F 路径 publish 清除)。同 attach 周期内两个失败事实语义完全不变——R2-G3 的清洗绕过不因 cap 放宽重开,hard 失败也不能借后续 trailing 形状洗白(R1-G1)。
|
|
45
|
+
|
|
46
|
+
**identity/geometry 防栏不变**:`committedViewValid`(I3 身份)、尺寸谓词(§8.5 反例)在 cap 地板同样生效。
|
|
47
|
+
|
|
48
|
+
### D2:等待态诊断落盘(组件层)
|
|
49
|
+
|
|
50
|
+
**共享快照构造器(R1-D2)**:抽取 `buildAttachRecoveryFacts()`(#284 settle 诊断的枚举白名单、token 排除逻辑原样复用),两个薄包装分别发出:
|
|
51
|
+
- `attach_settle_ready`(现状):facts + code/message + readyReason(非空);
|
|
52
|
+
- `attach_wait_expired`(新):facts + `details.phase: "budget" | "cap"`,**不含 readyReason**(等待态无该字段);`onDiagnostic` 联合类型相应扩展。
|
|
53
|
+
|
|
54
|
+
两个触发点:预算到期回调(置 budgetElapsed 后,phase="budget");cap 到期(`handleAttachHardTimeout` protocol 分支的 `deadlineState="expired"` 赋值处,phase="cap")。事件经现有 `onDiagnostic` 管道落 `views/<id>/diagnostics.jsonl`。等待中的 attach 从此有盘上证据。
|
|
55
|
+
|
|
56
|
+
## 3. 不变量(增量)
|
|
57
|
+
|
|
58
|
+
- **I7(cap 地板不洗任何失败事实)**:deadlineState=expired 只放宽谓词 5 的通过集;sticky 与 hard 锁存的置位/清除规则不变;cap-floor 发布后两者保持。
|
|
59
|
+
- **I8(hard 占优,R1-G1)**:当前 baseline 一旦出现 hard invalid,cap-floor 禁止直至 F publish 或 baseline 更换;纯 trailing-only 序列(含两种到达形状)才可被 cap 放行。hard 族 invalid 在 cap 后仍永久等待——那些形态下 committed view 的连续性疑点不能用时间消除;若它们也锁死用户,按 #288 的排查模式单独立案。
|
|
60
|
+
- **I9(trailing 家族的严格标识符)**:`view-proof-trailing-<identifier>` 只在接受小写字母数字与连字符时归 trailing;任何畸形/未识别值按 hard fail-closed。
|
|
61
|
+
- 继承 #284 I1–I6 全部。
|
|
62
|
+
|
|
63
|
+
## 4. 非目标
|
|
64
|
+
|
|
65
|
+
- 不改 250ms 预算路径的任何语义(missing 族照旧 250ms 降级)。
|
|
66
|
+
- 不识别 `csi-unknown` 的具体 CSI(trailing 扫描器 hygiene,后续单独处理)。
|
|
67
|
+
- 不为 hard 族 invalid 增加时间出口(I8)。
|
|
68
|
+
- 不改 legacy 分支、协议层、runner/reporter 语义(本修复纯 UI/策略层)。
|
|
69
|
+
|
|
70
|
+
## 5. 验收矩阵与可测性拆分
|
|
71
|
+
|
|
72
|
+
| ID | 功能点 | 层级与命令 | 通过标准 |
|
|
73
|
+
|---|---|---|---|
|
|
74
|
+
| A1 | D1 纯函数与策略:`classifyProofInvalidFamily` 逐形状断言(unavailable+trailing-pending/unsafe→trailing;unknown+view-proof-trailing-pending→trailing;unknown+view-proof-trailing-\<合法标识符\>→trailing;**畸形前缀值(大写/特殊字符/空)→hard**;全部 hard reason→hard;未识别值→hard;非 invalid 输入→null)。谓词 5 三态:pending 时 invalid 全 wait(reason=proof-status-invalid);expired 时 invalid∧capRecoverable=true 通过、invalid∧capRecoverable≠true → wait(reason=**deadline-expired:**proof-status-invalid);其余六谓词不因 cap 放宽 | unit,`node --test test/attach-recovery.test.mjs` | 反例全 wait 且 reason(含前缀)精确;cap 放宽仅 trailing-only |
|
|
75
|
+
| A2 | D1/D2 组件(注入 clock):**trailing-only 序列**(快照形状与 UI live 形状各一:covered→live unsafe 输出(真实 noteViewProofOutput 路径)→idle→250ms 预算不发布→2500ms cap→publish-degraded、readyReason=committed-degraded、sticky 仍置位、hard 锁存未置位);**hard 占优序列**:hard→trailing、trailing→hard、hard→loss/S/no-proof——cap 后均不发布;covered F publish 后两锁存清除、恢复正常降级 | 组件 harness,`node --test test/attach-recovery.test.mjs test/attach-recovery-component.test.mjs` | 预算拦、cap 放行 trailing-only、hard 占优全反例、sticky/hard 锁存语义 |
|
|
76
|
+
| A3 | D1 集成(真实双 main + 真实 socket):trailing-only 锁死形态(至少一种 UI 到达形状)→ **settle ≤4000ms(外部 wall-clock,=2500ms cap + 1500ms 调度余量)**、断言 `deadlineState=expired ∧ budgetElapsed=true`、readyReason=committed-degraded、proofStatus=invalid;对照场景(candidate-open)**<1500ms 且 deadlineState=pending** 不回归 | integration,`node --test test/attach-frame-witness.integration.test.mjs`(扩充 driver 注入 trailing 形状) | 锁死形态 cap 内必然 settle;预算快路径不回归 |
|
|
77
|
+
| A4 | D2 诊断:budget 与 cap 两个 `attach_wait_expired` 事件按相位落盘、字段枚举白名单、无 readyReason 字段、无 token/屏幕文本;**budget→cap→settle 顺序断言**;settle 事件照旧 | 组件 harness + 集成(命令同 A2/A3) | 两相位事件齐、顺序正确、字段合规 |
|
|
78
|
+
| A5 | 回归总量:`npm run verify` 全过;#284 全部既有断言(预算语义、sticky 序列、锁存、geometry、既有 deadline-expired 前缀断言)不回归 | `npm run verify`(实施 worktree) | 全过 |
|
|
79
|
+
| U1 | 用户实测(**可执行前提,R1-G3**):A5 全过后执行;**加载修复版 UI**——以实施 worktree 的绝对 `index.ts` 为 extensionEntry 启动隔离 pi(`--no-extensions --no-mcp --extension <绝对路径>`)或安装后 reload/重启,记录实际 SHA 与入口;本修复纯 UI/策略层不改 runner——复用原 a439b36 runner 现场(原 nvim 会话)或同 SHA 隔离 runner 均可,须记录选择了哪种;执行 #288 复现步骤(nvim idle→Alt+H→reattach);检查 `~/.pi/agent/agent-board/views/<id>/diagnostics.jsonl` 出现 budget/cap 两相位 `attach_wait_expired` 与随后的 `attach_settle_ready`。加载前提未满足时 U1 标记待执行 | 用户实测 | 最坏 ~2.5s 进入、画面为 detach 前 committed view、诊断链齐全 |
|
|
80
|
+
|
|
81
|
+
**可测性拆分(硬约束)**:① `classifyProofInvalidFamily` 独立纯函数、独立单测(A1);② hard 锁存/capRecoverable 装配为组件职责,经 harness 读数断言(A2),不进策略;③ `buildAttachRecoveryFacts` 共享构造器纯函数化,settle/wait 为薄包装(A4),不复制白名单逻辑;④ 组件/集成层只测时序与落盘。不得把①③耦合进组件。
|
|
82
|
+
|
|
83
|
+
## 6. 实施边界
|
|
84
|
+
|
|
85
|
+
- 允许改动:`src/core/attach-recovery.mjs`(新纯函数)、`src/core/pty-attach-render.mjs`(谓词 5 + `capRecoverable` 输入)、`src/ui/pty-attach.ts`(hard 锁存装配、共享 facts 构造器抽取、两处 wait 事件)、上述测试与 driver 扩充。
|
|
86
|
+
- 既有断言不改写(A5 守住 #284 语义与 deadline-expired 前缀约定);spec 与 plan 落 worktree;commit 按纯函数/策略/组件/测试分层。
|