@zhuxixi/pi-agent-board 0.12.0 → 0.13.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 (52) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +7 -7
  3. package/docs/superpowers/plans/2026-10-19-issue-213-reply-guard-csi-key.md +257 -0
  4. package/docs/superpowers/plans/2026-10-19-issue-214-attach-forward-alt-modifier.md +202 -0
  5. package/docs/superpowers/plans/2026-10-21-issue-221-ask-user-question.md +198 -0
  6. package/docs/superpowers/plans/2026-10-23-issue-225-monotonic-foreground-state.md +450 -0
  7. package/docs/superpowers/plans/2026-10-23-issue-229-vim-jkl.md +449 -0
  8. package/docs/superpowers/plans/2026-10-23-issue-232-attach-bg-only-cells.md +153 -0
  9. package/docs/superpowers/plans/2026-10-23-lease-heartbeat-staleness.md +537 -0
  10. package/docs/superpowers/plans/2026-10-23-selected-row-highlight.md +405 -0
  11. package/docs/superpowers/plans/2026-10-24-issue-217-windows-pid-reuse-stopping.md +367 -0
  12. package/docs/superpowers/plans/2026-10-24-issue-230-warm-host-background-runs.md +806 -0
  13. package/docs/superpowers/plans/2026-10-24-issue-238-windows-process-identity-token.md +490 -0
  14. package/docs/superpowers/plans/2026-10-24-issue-241-coordinator-root-exit.md +461 -0
  15. package/docs/superpowers/plans/2026-10-25-issue-239-coordinator-replacement-identity.md +504 -0
  16. package/docs/superpowers/specs/2026-10-14-issue-170-attach-reply-guard-design.md +5 -0
  17. package/docs/superpowers/specs/2026-10-19-issue-213-reply-guard-csi-key-design.md +165 -0
  18. package/docs/superpowers/specs/2026-10-19-issue-214-attach-forward-alt-modifier-design.md +131 -0
  19. package/docs/superpowers/specs/2026-10-20-issue-221-ask-user-question-design.md +270 -0
  20. package/docs/superpowers/specs/2026-10-22-issue-225-monotonic-foreground-state-design.md +225 -0
  21. package/docs/superpowers/specs/2026-10-23-issue-229-vim-jkl-design.md +90 -0
  22. package/docs/superpowers/specs/2026-10-23-issue-232-attach-bg-only-cells-design.md +146 -0
  23. package/docs/superpowers/specs/2026-10-23-lease-heartbeat-staleness-design.md +271 -0
  24. package/docs/superpowers/specs/2026-10-23-selected-row-highlight-design.md +191 -0
  25. package/docs/superpowers/specs/2026-10-24-issue-217-windows-pid-reuse-stopping-design.md +334 -0
  26. package/docs/superpowers/specs/2026-10-24-issue-230-warm-host-background-runs-design.md +283 -0
  27. package/docs/superpowers/specs/2026-10-24-issue-238-windows-process-identity-token-design.md +286 -0
  28. package/docs/superpowers/specs/2026-10-24-issue-241-coordinator-root-exit-design.md +381 -0
  29. package/docs/superpowers/specs/2026-10-25-issue-239-coordinator-replacement-identity-design.md +331 -0
  30. package/package.json +3 -3
  31. package/runner/pty-runner.mjs +18 -22
  32. package/runner/state-coordinator.mjs +213 -26
  33. package/scripts/release_helper.mjs +39 -7
  34. package/scripts/run-tests.mjs +375 -0
  35. package/src/core/background-runs.mjs +273 -0
  36. package/src/core/coordinator-client.mjs +346 -26
  37. package/src/core/diagnostics.mjs +24 -0
  38. package/src/core/events.mjs +16 -3
  39. package/src/core/foreground-projection-cache.mjs +99 -0
  40. package/src/core/host-coordination.mjs +69 -1
  41. package/src/core/launch.mjs +21 -1
  42. package/src/core/locks.mjs +176 -31
  43. package/src/core/pid.mjs +4 -2
  44. package/src/core/process-identity-probe.mjs +228 -0
  45. package/src/core/pty-scroll.mjs +21 -14
  46. package/src/core/state-commands.mjs +5 -1
  47. package/src/core/terminal-reply-guard.mjs +26 -4
  48. package/src/core/types.mjs +1 -0
  49. package/src/core/warm-host-sweeper.mjs +7 -2
  50. package/src/runtime/service.mjs +385 -73
  51. package/src/ui/dashboard.ts +48 -25
  52. package/src/ui/pty-attach.ts +18 -7
@@ -0,0 +1,225 @@
1
+ # Root-cause report / Spec: monotonic foreground state rebuild (stale "Needs answer")
2
+
3
+ Drafted: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-22T23:50:00+08:00
4
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-23T00:05:00+08:00 — folded in R1-G1..G3 and R1-D1..D4
5
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-23T00:20:00+08:00 — R2-D1..D3 (A4 clock pin, timestamp-bound wording, forget wiring acceptance)
6
+
7
+ - **Issue**: zhuxixi/pi-agent-board#225
8
+ - **Date**: 2026-10-22
9
+ - **Status**: draft — awaiting cross-review and user confirmation
10
+ - **Type**: bug fix (foreground state mirroring); no reducer, schema, or UI change
11
+
12
+ ## 1. Problem
13
+
14
+ A foreground row that transiently becomes `needs_input` can stay in **Needs answer** for
15
+ the rest of the turn after the question is answered. Live evidence (issue #225):
16
+
17
+ ```
18
+ 22:56:21 needs_input pending=[call_.../1]
19
+ 22:56:44 working pending=[] ← tool_execution_end cleared it
20
+ 22:56:44 needs_input pending=[call_.../1] ← stale projection re-applied
21
+ 22:57:04 idle pending=[] ← agent_end finally rewrote it
22
+ ```
23
+
24
+ The reducer is correct (#221); the resurrection happens in the foreground mirror.
25
+
26
+ ## 2. Root cause
27
+
28
+ 1. `syncRowEvent` (`src/runtime/service.mjs:1533`) rebuilds status from disk on every
29
+ event: `statusFromRow(row)` (`:1535`).
30
+ 2. `statusFromRow` (`:814-843`) copies `semanticState` / `summary` / `question` /
31
+ `pendingQuestions` but **not `updatedAt`**, so the rebuild has no freshness signal.
32
+ 3. `writeForegroundState` (`:854-880`) stamps a new `updatedAt` through
33
+ `projectViewState(status, Date.now(), …)`, and every caller fires it as
34
+ `void writeForegroundState(...)` (`:1571`, `:1629`). Two events can therefore have two
35
+ `sync_foreground` commands in flight, and the older projection can materialize last.
36
+ 4. The next event reduces onto that stale status (it cannot tell it is stale) and writes it
37
+ back; the pending entry survives until `agent_end` finalizes the row.
38
+ 5. `foregroundPreviewCache` (#113) restores only `latestAssistantPreview` and
39
+ `lastAgentActivityAt`, keyed on `lastAgentActivityAt` — tool events never stamp that
40
+ field, so question state is uncovered.
41
+
42
+ Additional constraint: `mark_completed` / `mark_holding` / `patch_fields`
43
+ (`src/core/state-commands.mjs`) do **not** stamp `state.updatedAt`, so a timestamp-only
44
+ guard could resurrect a pre-verdict projection over a manual verdict. The manual-verdict
45
+ fence (`isManualVerdict`) must gate the adoption.
46
+
47
+ ## 3. Design
48
+
49
+ ### 3.1 New pure module: `src/core/foreground-projection-cache.mjs`
50
+
51
+ Module-level shared instance, same rationale as `foreground-preview-cache` (service
52
+ instances are created per call, so a per-instance cache is discarded between events).
53
+
54
+ The cache stores a **status-shaped snapshot**, not the `ViewState` projection: the
55
+ projection calls the active tool `latestTool`, while `RunStatus` calls it `currentTool` with
56
+ a `summary` (`src/core/events.mjs:225`, `src/runtime/service.mjs:826`). Storing the status
57
+ keeps the whitelist aligned with `RunStatus` and avoids an implicit shape mapping.
58
+
59
+ ```js
60
+ createForegroundProjectionCache(): {
61
+ nextStamp(viewId): number // strictly increasing per view
62
+ remember(viewId, status, stamp): void // snapshot the whitelisted fields
63
+ adopt(viewId, status): boolean // copy the snapshot when strictly newer
64
+ forget(viewId): boolean
65
+ clear(): void
66
+ size(): number
67
+ }
68
+ ```
69
+
70
+ - `nextStamp(viewId)` returns `max(Date.now(), lastStamp(viewId) + 1)`. Using it for
71
+ `projectViewState`'s `now` argument makes every foreground `updatedAt` strictly increasing
72
+ per view, so two events in the same millisecond can never tie and an older projection can
73
+ never outrank a newer one inside this process.
74
+ - `remember` snapshots this whitelist from the status:
75
+ `semanticState`, `processState`, `summary`, `currentTool`, `question`,
76
+ `pendingQuestions`, `error`, `lastActivityAt`, `latestAssistantPreview`,
77
+ `lastAgentActivityAt`, plus the `stamp`. Nested values (`currentTool`,
78
+ `pendingQuestions`) are cloned **on remember**, so a later mutation of the caller's status
79
+ cannot leak into the cache.
80
+ - `adopt(viewId, status)` compares `entry.stamp` with `status.updatedAt ?? 0`. Only a
81
+ strictly newer entry is adopted; it copies the same whitelist (cloning nested values
82
+ again, so `adopt` → caller mutation → second `adopt` is stable) and sets
83
+ `status.updatedAt = entry.stamp`. Returns whether anything changed.
84
+ - Nothing else (evidence `review`, `diagnostics`, `autoState`, `lastVisitedAt`, `steering`,
85
+ `followUps`) is touched — those have their own writers and freshness rules.
86
+
87
+ ### 3.2 Wiring in `src/runtime/service.mjs`
88
+
89
+ | Point | Change |
90
+ |---|---|
91
+ | `statusFromRow` (`:814`) | add `updatedAt: typeof s.updatedAt === "number" ? s.updatedAt : 0` (in-memory freshness only; `RunStatus` gains an optional `updatedAt` typedef in `src/core/types.mjs`) |
92
+ | `writeForegroundState` (`:854`) | `const stamp = foregroundProjectionCache.nextStamp(row.meta.id)`; pass `stamp` instead of `Date.now()` to `projectViewState`; then `foregroundProjectionCache.remember(row.meta.id, status, stamp)` |
93
+ | `syncRowEvent` (`:1540`) | after the preview backfill: `foregroundProjectionCache.adopt(row.meta.id, status)` before `reduceEvent` |
94
+ | cache eviction (`:775`, `:2131`) | call `foregroundProjectionCache.forget(viewId)` next to the existing `foregroundPreviewCache.forget(viewId)` |
95
+
96
+ `row` is loaded from disk at the event entry (`rowForSession` → `loadRow`), before any
97
+ `await`, so `row.state` is as fresh as `readState(root, viewId)` at that point.
98
+
99
+ The preview cache stays as-is: its #113 semantics (gap-fill when the timestamp ties) are
100
+ still useful, and folding it into the new cache is a separate refactor (non-goal).
101
+
102
+ ### 3.3 Why not serialize the writes (issue option 2)
103
+
104
+ A module-level write queue would fix the ordering at the source, but it adds a new failure
105
+ mode (one stalled coordinator round trip blocks every later event) and needs its own
106
+ backoff/timeout policy. The monotonic rebuild fixes the *read* side, so it also covers
107
+ future writers (dashboard patches, reconcile) and any out-of-order arrival that is not a
108
+ `sync_foreground` command. Option 2 remains a possible follow-up, not this fix.
109
+
110
+ ### 3.4 Manual verdicts (boundary, no new fence)
111
+
112
+ Adoption is a pure comparison: adopt only when `entry.stamp > status.updatedAt`. Because
113
+ `nextStamp` can run ahead of the wall clock during a sub-millisecond burst, a writer that
114
+ stamps with a bare `Date.now()` *can* compare older than the cache — the timestamp does not
115
+ order against every writer.
116
+
117
+ Manual verdicts do not rely on that comparison. Under the coordinator, `mark_completed` /
118
+ `mark_holding` writes are materialized without stamping `updatedAt`
119
+ (`state-commands.mjs:288-334`), and any later `sync_foreground` from `service` is rejected
120
+ with `manual_fence` (`state-commands.mjs:282-285`). In coordinator-disabled mode the direct
121
+ writers (`completeViewDirect`, `holdViewDirect`, `archiveStateDirect`, reconcile) *do* stamp
122
+ `Date.now()`, but that path already lets a foreground event overwrite the semantic state
123
+ through `reduceEvent` today, independent of this cache, so adoption adds no new way to
124
+ resurrect a verdict. No extra fence is added; the existing `manual_fence` and the
125
+ `agent_end` branch fence remain the protections, and A5 pins the observable behavior.
126
+
127
+ ### 3.5 Data flow after the change
128
+
129
+ | Event | Behavior |
130
+ |---|---|
131
+ | start question | `reduceEvent` → `needs_input`; write uses stamp S1 and remembers it |
132
+ | end question | rebuild from disk (maybe stale) → adopt if cache is newer → `reduceEvent` clears pending → write uses S2 > S1 |
133
+ | subsequent tool event | rebuild carries S2 → adopt is a no-op (equal) → `reduceEvent` keeps `working`; never resurrects `needs_input` |
134
+ | dashboard write | disk `updatedAt` is newer than the cache → nothing adopted |
135
+ | agent_end | finalize as today |
136
+
137
+ ## 4. Acceptance matrix
138
+
139
+ | ID | Feature point | Verification | Concrete check | Pass criteria |
140
+ |----|---------------|--------------|----------------|---------------|
141
+ | A1 | `remember`/`adopt` respect strict freshness | automated (unit) | `test/foreground-projection-cache.test.mjs` | newer stamp adopted (`true`); equal and older stamps not adopted (`false`), status unchanged |
142
+ | A2 | Whitelist copy is exact and isolated | automated (unit) | same file | all whitelisted fields copied; non-whitelisted untouched; mutating `status.pendingQuestions[0]` after `adopt` does not change a second `adopt`; mutating the status after `remember` does not change the stored snapshot |
143
+ | A3 | `nextStamp` is strictly increasing per view | automated (unit) | same file | two calls in a row return `b > a`, even when `Date.now()` is stubbed to a constant; different view ids do not share the counter |
144
+ | A4 | Out-of-order materialization no longer resurrects `needs_input` | automated (integration) | `test/service.test.mjs`, coordinator disabled, `Date.now` pinned to a constant for the whole test so the pre-fix same-millisecond tie is deterministic: question start → capture `state.json` (its `updatedAt` is the start stamp) → question end → `writeState(captured snapshot)` (an older stamp) → `tool_execution_start` for `bash` | persisted state is `working`, `pendingQuestions` empty, `needsInput` false. Pre-fix this asserts `needs_input` (the disk rebuild wins the tie), post-fix the monotonic stamp adopts the newer cached status |
145
+ | A5 | A manual verdict survives a foreground event | automated (integration) | `test/service.test.mjs`: seed the projection cache with an accepted-but-unmaterialized beat, write `completed` + `autoState: null` with an older `updatedAt`, then a `tool_execution_start` that adopts the cached snapshot | persisted state stays `completed` (coordinator answers `manual_fence`). Pins the fence, not adoption isolation — adoption has no independent observable there |
146
+ | A6 | `forget` drops the entry and is wired into archive | automated (unit + integration) | cache test: `remember` → `forget` → `adopt` false; `test/service.test.mjs`: `archiveByState` on a remembered view | `adopt` returns `false` after `forget`; after archiving, `foregroundProjectionCache.size()` no longer counts that view |
147
+ | A7 | Existing foreground behavior unchanged | automated (unit/integration) | `npm test` (existing `syncForegroundEvent` and preview-cache tests) | all pass |
148
+ | A8 | Repo static gate | automated (static) | `npm run typecheck` | exit 0 (`checkJs:false`, so this is a repo regression gate, not proof of the `.mjs` change) |
149
+ | U1 | Live: answering a question returns the row to RUNNING before the turn ends | user test | see §5 | row leaves **Needs answer** within ~1s of the answer and stays RUNNING until the turn ends |
150
+
151
+ Full gate: `npm run verify` (typecheck + perf + tests + coverage thresholds + pack dry-run).
152
+
153
+ Failure branches: A1/A2 assert the negative side (equal/older stamps are not adopted, nested
154
+ values cannot leak), A5 asserts the manual-verdict boundary, A6 asserts cache eviction. No
155
+ new error path is introduced.
156
+
157
+ ## 5. User test (U1)
158
+
159
+ Executable after merge, on this machine (the board clone at
160
+ `~/.pi/agent/git/github.com/zhuxixi/pi-agent-board` is updated to the merged commit and Pi
161
+ restarted):
162
+
163
+ 1. In a session, trigger a question (`ask_user_question` or `question`).
164
+ 2. Watch the row enter **Needs answer**; answer it in the dashboard/attach.
165
+ 3. Keep watching for the rest of the turn.
166
+
167
+ Expected: the row returns to **RUNNING** within about a second of the answer — not at
168
+ `agent_end`. Repeat with a nested call (question asked from inside `codemode`) to exercise
169
+ the wider window.
170
+
171
+ If the environment cannot be updated at completion time, U1 is reported as `pending`.
172
+
173
+ ## 6. Non-goals
174
+
175
+ - No change to `reduceEvent`, `deriveSummary`, or the question-tool detection (#221 is done).
176
+ - No serialization of `sync_foreground` writes (issue option 2) and no coordinator changes.
177
+ - No removal or rewrite of `foreground-preview-cache.mjs` (#113 behavior preserved).
178
+ - No changes to manual verdicts, auto-state classification, or evidence/diagnostics writes.
179
+
180
+ ## 7. Risks and boundaries
181
+
182
+ - **Clock ties**: prevented inside this process by `nextStamp` (strictly increasing per
183
+ view). Ties are still possible with a *different* writer (another Pi process) whose
184
+ `Date.now()` equals ours; then neither side is "strictly newer" and the disk value wins,
185
+ which is the pre-existing behavior. Cross-process ordering is not guaranteed.
186
+ - **Cross-process writers**: another Pi process mirroring the same view writes its own
187
+ `updatedAt`; this cache only protects against out-of-order writes from *this* process.
188
+ Outside the supported single-host model; documented, not fixed.
189
+ - **In-process writers with a bare `Date.now()`**: the auto-state classifier
190
+ (`applyAutoStateToViewState`, `src/core/auto-state.mjs:254`) stamps a wall-clock
191
+ `updatedAt`, which can compare older than a cache stamp that ran ahead within the same
192
+ millisecond. A late foreground tool event would then adopt the pre-classification
193
+ snapshot — but such an event already clobbers the classification through `reduceEvent`
194
+ today (it sets `working` and `alive`), so this is not a new resurrection path.
195
+ - **Manual verdicts**: protected by the coordinator's `manual_fence` and the `agent_end`
196
+ branch fence, not by timestamps. Coordinator materialization does not stamp `updatedAt`
197
+ for verdict writes; coordinator-disabled direct writers do stamp `Date.now()`, which can
198
+ compare older than a cache stamp that ran ahead of the clock — that path is not ordered by
199
+ this cache (see §3.4, A5).
200
+ - **Memory**: one small object per view, evicted with the existing `forget` sites.
201
+
202
+ ## 8. Testability split
203
+
204
+ | Unit | Purity | Test seam |
205
+ |---|---|---|
206
+ | `createForegroundProjectionCache()` (`nextStamp` / `remember` / `adopt` / `forget`) | pure (Map in/out, tested with a stubbed clock) | direct unit tests (`test/foreground-projection-cache.test.mjs`) |
207
+ | `statusFromRow` `updatedAt` passthrough | pure | exercised through `syncForegroundEvent` (A4) |
208
+ | adoption in `syncRowEvent` | side-effect-free call + thin I/O shell | `syncForegroundEvent` with coordinator disabled (A4), deterministic `writeState` between events; A5 uses the tracked coordinator |
209
+ | stamp assignment in `writeForegroundState` | pure call inside the existing shell | A4 (the repro fails without monotonic stamps: the stale snapshot would tie) |
210
+ | write-side `remember` | pure call inside the existing shell | A4 (the repro fails without it) |
211
+
212
+ Test boundary: new pure module tests + additions to `test/service.test.mjs`; no new exports
213
+ from the service.
214
+
215
+ ## 9. Deliverables
216
+
217
+ - `src/core/foreground-projection-cache.mjs` — new pure module.
218
+ - `src/runtime/service.mjs` — `statusFromRow` `updatedAt`; `nextStamp` + `remember` in
219
+ `writeForegroundState`; `adopt` in `syncRowEvent`; `forget` at the eviction sites.
220
+ - `src/core/types.mjs` — optional `updatedAt` on the `RunStatus` typedef (in-memory
221
+ freshness field).
222
+ - `test/foreground-projection-cache.test.mjs` — new unit tests (A1–A3, A6).
223
+ - `test/service.test.mjs` — A4/A5 integration tests.
224
+ - `docs/superpowers/specs/2026-10-22-issue-225-monotonic-foreground-state-design.md` — this
225
+ design, committed with the fix.
@@ -0,0 +1,90 @@
1
+ # spec — issue #229:vim-style j/k/l in the board list
2
+
3
+ Drafted: kimi-coding/k3 (selected) · kimi-coding/k3 (physical) @ 2026-10-23T22:50:00+08:00
4
+ Revised: kimi-coding/k3 (selected) · kimi-coding/k3 (physical) @ 2026-10-23T23:00:30+08:00 — cross-review R1:R1-G1 接受(§4.1 In evidence 行补 l attach、A7 改逐行断言);R1-G2 接受(新增 A9 负向断言);R1-D1 接受(U1 部署前置改为按 `pi list` 原源同形移除/恢复);R1-D2 接受(§7 先例引用改 dashboard-prewarm-smoke.ts)
5
+ Revised: kimi-coding/k3 (selected) · kimi-coding/k3 (physical) @ 2026-10-23T23:05:30+08:00 — cross-review R2:R2-D1 接受(evidence 帮助行手势串改 `→/l attach` 与 peek 口径对称);R2-D2 接受(A7 枚举补齐 4 处 j/k 行断言 + 负向断言扩展到 In peek/session/evidence 旧措辞)
6
+
7
+ 基线:main @ 759d659。调研留档:`research/01-keybinding-audit-and-history.md`(issue 测量全部验证属实)。
8
+
9
+ ## 1. 背景与问题
10
+
11
+ board 的 `list` 模式是用户停留最久的视图,却是唯一不接受 `j`/`k` 的导航视图:`j`/`k` 落到 printable fallback 弹错误的 INSERT toast;`l` 全模式空闲,而它的箭头孪生 `→` 是主 attach 手势。两个只读视图(session/evidence)已绑 `j`/`k` 滚动。目标:让 list/select/peek 的导航与 attach 键位符合 vim 肌肉记忆,且不破坏任何文本输入模式与既定键位契约(`h` = Hold,PR #151)。
12
+
13
+ ## 2. 设计决策表
14
+
15
+ | # | 决策 | 依据 |
16
+ |---|---|---|
17
+ | D1 | 采纳 issue 的 Proposed direction 全部内容 | 测量经调研验证属实,与历史决策无冲突 |
18
+ | D2 | `j`/`k` **复用** `moveSelection()` / `peekStep()` —— 继承**环绕(wrap)**语义,与 `↑`/`↓` 逐字节一致;**不**实现 issue Verification 措辞里的 "clamp" | wrap 是 issue #52 的既定行为,`test/dashboard-navigation.test.mjs` 锁定;`j`/`k` 与 `↑`/`↓` 行为分裂(一个 wrap 一个 clamp)比不环绕更糟。这是与 issue 措辞的唯一偏差 |
19
+ | D3 | 顺带清理 `handleListKey` 的两处重复行(`data === "d"` ×2、`ctrl("x")` ×2,merge 残留死代码) | 零行为变化;改动同函数,顺手清理成本最低 |
20
+ | D4 | select 不绑 `l`(无对应动作,`space` 才是 toggle);session 不绑 `l`(无 `→` 可镜像,已有 `enter`/`a` 两条 attach 路径) | issue 已论证 |
21
+ | D5 | 补齐**已有** `j`/`k` 在 Transcript/Evidence 的文档欠账(help 面板与 README 四表均未写) | 调研发现:欠账不止新键,既有键也未写 |
22
+ | D6 | 不动 `h`(Hold)、不动 dispatch/filter/rename/reply(`j`/`k`/`l` 保持字面字符)、不动 attach 侧键位 | `h` = Hold 是 PR #151 契约;文本模式字母必须字面;attach 是裸 PTY 透传的另一套面(JFox `202610182229584028`) |
23
+
24
+ ## 3. 逐模式键位变更(src/ui/dashboard.ts,行号为 main @ 759d659 参考值)
25
+
26
+ | 模式 | handler | 新增绑定 | 行为(复用现有路径) |
27
+ |---|---|---|---|
28
+ | list | `handleListKey` :359 | `j` / `k` | `moveSelection(+1 / -1)`,环绕,与 `↑`/`↓` 同一路径 |
29
+ | list | `handleListKey` | `l` | `attachSelected()`,镜像 `→` / `>` |
30
+ | select | `handleSelectKey` :400 | `j` / `k` | `moveSelection(±1)` |
31
+ | peek | `handlePeekKey` :427 | `j` / `k` | `peekStep(±1)`,环绕 |
32
+ | peek | `handlePeekKey` | `l` | `attachPeek()`,镜像 `→` / `>` |
33
+ | evidence | `handleEvidenceKey` :484 | `l` | `attachSelected()`,镜像 `→`(`j`/`k` 已有) |
34
+ | session | — | 无变更 | `j`/`k` 已有;不绑 `l`(D4) |
35
+ | dispatch / filter / rename / reply | `handleTextMode` | 无变更 | `j`/`k`/`l` 保持字面字符(D6) |
36
+
37
+ 插入位置约定:各 handler 内紧贴对应箭头键分支之后,保持「先功能键后字母」的既有阅读顺序。list 模式的新分支须位于 printable fallback(:394)之前。
38
+
39
+ ## 4. 文案同步(五处,调研发现的三处纪律 + 两处欠账)
40
+
41
+ 1. `renderHelp` 帮助面板(:1699-1730):`↑/↓` 行 → `↑/↓ or j/k`;`→ or >` 行 → `→ / > / l`;"In select" 行补 `j/k`;"In peek" 行 `↑↓` → `↑↓/j/k`、`→ attach` → `→/l attach`;"In session"/"In evidence" 行补已有的 `j/k` 滚动(D5);**"In evidence" 行另补 attach 手势串 `→/l attach`**(§3 给 evidence 新增了 `l`,帮助面板必须同步,否则 README/帮助/行为三处不一致;手势串保留主手势 `→` 与 peek 行口径对称,不只写新增的 `l`)。
42
+ 2. `listHints()` NORMAL 行(:1362):`→ attach` → `→/l attach`。
43
+ 3. `listHints()` SELECT 行(:1350):补 `j/k move`。
44
+ 4. README Main list 表:`Up/Down` 行补 `j`/`k`;`Right / >` 行补 `l`。
45
+ 5. README Peek / Transcript / Evidence 三表:Peek 补 `j`/`k` 与 `l`;Transcript/Evidence 补已有的 `j`/`k`(D5),Evidence 补 `l`。
46
+
47
+ ## 5. 非目标
48
+
49
+ - 不绑 `h` 的任何新义(Hold 契约不动,不「补全 hjkl 四键」)。
50
+ - 不给 session 模式加 `l`;不给 select 模式加 `l`。
51
+ - 不动 attach 视图键位、不动文本输入模式。
52
+ - 不改变 wrap 语义本身(想改 clamp 需另开 issue 并影响 `↑`/`↓`)。
53
+
54
+ ## 6. 验收矩阵(必答)
55
+
56
+ | ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
57
+ |----|--------|----------|----------|----------|
58
+ | A1 | list 模式 `j`/`k` 移动选择 | 自动化(unit,探针) | `node --test test/dashboard-vim-keys.test.mjs`(新探针 `test-support/vim-keys-wrap.ts`,复用 navigation-wrap 模式) | 3 行 fixture 上 `j`/`k` 序列的 `selectedId` 轨迹与 `↑`/`↓` 同序列完全一致(含两端环绕) |
59
+ | A2 | select 模式 `j`/`k` | 自动化(unit,同探针) | 同上 | 进入 select 后 `j`/`k` 移动选中且环绕 |
60
+ | A3 | peek 模式 `j`/`k` → `peekStep` | 自动化(unit,同探针) | 同上 | `peekId`/`selectedId` 轨迹与 `↑`/`↓` 一致 |
61
+ | A4 | `l` 在 list/peek/evidence 触发 attach | 自动化(unit,同探针) | 构造器注入 fake `done` 回调捕获 `{action:"attach", viewId}` | 三模式各捕获一次 attach 且 viewId 正确;fixture 用非 busy row(时序约束见 §7) |
62
+ | A5 | dispatch/filter/rename/reply 的 `j`/`k`/`l` 仍为字面字符 | 自动化(unit,同探针) | 各文本模式下按 `j`/`k`/`l`,白盒读 `this.input` | input 含字面 `jkl`,无模式跳出 |
63
+ | A6 | session/evidence `j`/`k` 滚动回归保护 | 自动化(unit,同探针) | 断言 `sessionScrollTop`/`evidenceScrollTop` | `j`↓`k`↑ 与 `↓`↑ 行为一致(既有行为不回归) |
64
+ | A7 | help/hints 文案更新 | 自动化(unit,同探针渲染路径) | 探针调用渲染输出,**逐行断言**:① 主 `↑/↓ or j/k` 行存在;② `→ / > / l` 行存在;③ "In select" 行含 `j/k`;④ "In peek" 行含 `↑↓/j/k` 与 `→/l attach`;⑤ "In session" 行含 `j/k` 滚动;⑥ "In evidence" 行含 `j/k` 滚动与 `→/l attach`;⑦ NORMAL hint 含 `→/l attach`;⑧ SELECT hint 含 `j/k`;⑨ 负向:无 j/k 的旧 `↑↓` 措辞在主行与 In peek/In session/In evidence 行均不再出现 | 逐行断言全过(不用子串级 `含 l 字样`,防单行遗漏被其它行掩护;①-⑧ 覆盖 §4.1 全部变更点含 D5 欠账项) |
65
+ | A9 | 负向契约:select/session **不**绑 `l`(D4) | 自动化(unit,同探针) | select 模式 `handleInput("l")` 后断言 mode 仍为 select 且 fake `done` 零调用;session 模式同理 | 两模式按 `l` 均无副作用(不 attach、不切模式、input 不增长) |
66
+ | A8 | 全量门槛 | 自动化(build/test) | `npm run verify` | typecheck + perf gate + 全测试 + coverage 阈值(lines 85/funcs 80/branches 70)+ pack:dry 全过 |
67
+ | U1 | 真实面板手感 | 用户实测 | 部署前置:① `pi list` 记录当前安装源标识(本机维护者环境为 git 源 `git:github.com/zhuxixi/pi-agent-board`,其它环境可能是 npm 源)② `pi remove <该源标识>`(命令出处:pi docs cli.md `pi remove <source>`,源标识与安装时同形;避免原源与 worktree 双 identity 并存)③ `pi install <worktree 绝对路径>` → `pi /agent-board`;步骤:① list 按 `j`/`k` 走行含两端环绕 ② 按 `j` 不再弹 INSERT toast ③ `l` attach 选中会话 ④ detach 后 `?` 帮助显示新绑定(含 evidence 行的 `l`) ⑤ `i` 进 INSERT 后 `j`/`k`/`l` 仍是字面字符 | 五项全部符合预期;验完 `pi remove <worktree 路径>` 并按 ① 记录的原源 `pi install <原源标识>` 恢复 |
68
+ | U2 | README 四表与行为一致 | 用户实测 | 对照 README 四个表格逐行核对实际行为 | 表格无遗漏、无虚构 |
69
+
70
+ ## 7. 可测性拆分设计(必答)
71
+
72
+ **不新增函数、不改现有拆分**。各 handler 已是独立方法;本次每个 handler 只加 1–2 个早返分支,复用现有纯路径:`moveSelection`(:266)、`peekStep`(:1163)、`attachSelected`(:1174)、`attachPeek`(:1180)。副作用本就隔离在这四个方法 + `done` 回调 + `input` buffer 内,本次改动不引入新耦合。
73
+
74
+ **测试边界**:`DashboardComponent.handleInput()` 公开入口。观测点:
75
+
76
+ - `selectedId` / `peekId` / `sessionScrollTop` / `evidenceScrollTop` / `input` —— 白盒读(TS-private 运行时可访问,`navigation-wrap.ts` 已有先例);
77
+ - attach 意图 —— 构造器第 4 参 `done` 注入 fake 捕获(先例:`test-support/dashboard-prewarm-smoke.ts` 第 42 行 `(r) => doneCapture?.push(r)` 与第 82-92 行断言 `done[0].stopFirst === false`;`done` 为第 4 参见 dashboard.ts:164,`DashboardResult` 含 `{action:"attach"; viewId; stopFirst}` 见 :58)。
78
+
79
+ **探针形态**:新建 `test-support/vim-keys-wrap.ts`(`node --experimental-transform-types` 运行,tsconfig 排除 test-support,与既有探针一致),fixture 用 `createService` + `mkdtemp` 三行 view(navigation-wrap 模式),`handleInput` 直调。一个探针覆盖 A1–A7 的全部按键序列,输出 JSON 供 `test/dashboard-vim-keys.test.mjs` 断言。
80
+
81
+ **触发时序约束(A4)**:`requestAttach` 内 `planDashboardAttach` 对 busy row 走 confirm 分支(进 `pending` 而非 `done`)。探针 fixture 固定使用 `idle/exited` 非 busy row,测直接 attach 路径;confirm 分支的 `pending` 机制由既有测试(如 `dashboard-delete-key.test.mjs`)覆盖,不在本 issue 重复。
82
+
83
+ **D3 死代码清理**:零行为变化,不单设验收项,由 A1–A8 回归兜底。
84
+
85
+ ## 8. 保证边界
86
+
87
+ - 只保证 `j`/`k` 与 `↑`/`↓` 行为**完全一致**(含环绕);不承诺 vim 语义里的 clamp。
88
+ - 只保证 list/select/peek 三模式新增导航、`l` 在 list/peek/evidence 三模式 attach;其它模式零变更。
89
+ - 文案同步覆盖 §4 五处;不保证仓内其它文档(如 demo 视频、外部博客)同步。
90
+ - U1 的部署前置(先 remove git 源再 install 本地路径)若被跳过,可能加载到旧代码,验收结论无效。
@@ -0,0 +1,146 @@
1
+ # Issue #232 — attach drops trailing background-only cells (design)
2
+
3
+ Drafted: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-23T22:58:00+08:00
4
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-23T23:20:00+08:00 — R1-G1, R1-D1, R1-D2, R1-D3
5
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-23T23:35:00+08:00 — R2-G1, R2-D1, R2-D2
6
+ Revised: deepseek/deepseek-flash (selected) · deepseek/deepseek-flash (physical) @ 2026-10-23T23:45:00+08:00 — R3-D1, R3-D2, R3-D3
7
+
8
+ Repo: `zhuxixi/pi-agent-board` · base `main` @ `759d659` · issue #232 (bug)
9
+
10
+ ## 1. Problem
11
+
12
+ In attach mode a full-screen TUI whose theme background differs from the host
13
+ terminal's default renders with the host background showing through every
14
+ character-less region (nvim's empty buffer, tab-bar gaps). Colours survive into
15
+ the xterm buffer; they are destroyed when the buffer is serialized back to ANSI.
16
+
17
+ ## 2. Root cause (verified against `759d659`)
18
+
19
+ `lineToAnsi()` (`src/ui/pty-attach.ts:1962`) computes `last` = last cell whose
20
+ `getChars()` is non-empty, returns `""` when `last < 0`, and renders
21
+ `x <= last`. Background-only cells therefore never reach the output:
22
+
23
+ - blank line + painted bg → `""` (whole line's bg dropped);
24
+ - content line → everything right of the last character dropped.
25
+
26
+ ## 3. Design
27
+
28
+ Three surgical changes inside `lineToAnsi()`, no signature/module changes.
29
+
30
+ **C1 — track the painted extent.** During the existing per-line scan, also
31
+ record `lastBg` = last cell with `!cell.isBgDefault()`. Compute
32
+ `renderEnd = Math.max(last, lastBg)`. The scan keeps skipping
33
+ `getWidth() === 0` continuation cells and never reads `extended`, so the
34
+ reusable-cell contract from issue #158 stays satisfied.
35
+
36
+ **C2 — render through `renderEnd`.** Replace both bounds derived from `last`:
37
+ the main render loop (`x <= renderEnd`) and the empty-line guard
38
+ (`if (renderEnd < 0)`). Blank default-bg lines still return `""`, so ordinary
39
+ shell output stays byte-identical. Blank painted lines now enter the normal
40
+ loop, which emits their cells' SGR bg plus `" "` padding; content lines pad
41
+ through their last painted column.
42
+
43
+ **C3 — cursor bound.** The post-loop "cursor past content" check compares
44
+ `cursor.col > renderEnd` instead of `> last`, so a cursor inside the newly
45
+ painted region is drawn exactly once by the in-loop `isCursor` path.
46
+
47
+ ### Why this is sufficient
48
+
49
+ pi-tui renders a component line as-is; the SGR run in the line paints the row's
50
+ bg. Padding exists only to give the SGR run cells to apply to. For an nvim
51
+ screen the bg covers the full width, so each line serializes to full width.
52
+
53
+ ## 4. Decisions
54
+
55
+ | Decision | Rationale |
56
+ | --- | --- |
57
+ | Follow the reporter's patch shape (3 changes) | Matches the verified root cause; smallest diff; reported as visually fixed. |
58
+ | Selection over padded cells becomes inverse-video | Correction to the issue comment: `pointWithinSelection` is evaluated per column, not per char. Drawing a selection over blank area matches real terminal behaviour; copied text is built from the selection model, not from padding, so copy output is unchanged. |
59
+ | `isBgDefault()` only — `isInverse()` deliberately excluded | Keeps the fix inside the reported class (explicit bg). Reversed-video-only blank regions are a separate, unmeasured case; see follow-up. |
60
+ | No pure-helper extraction | The defect is the emission bound, not the arithmetic; extracted-helper unit tests would not observe it. See §6. |
61
+ | Byte cost accepted | Painted screens now emit full-width lines, but the attach renderer is differential and only rewrites changed lines. |
62
+
63
+ ## 5. Non-goals
64
+
65
+ - No separate legacy/replay acceptance item: legacy attach is the **same**
66
+ `PtyAttachComponent` and the same renderer (`replayScreenLog()` feeds the same
67
+ `this.term`, `project()` always calls `lineToAnsi`), so C1–C3 apply to it
68
+ automatically — that is an expected benefit, not a boundary. The byte-cost
69
+ trade-off applies there too; A1–A5 exercise the same serialization path.
70
+ - Inverse-video-only blank regions (`SGR 7` with default bg) — same bug class,
71
+ different trigger; file a follow-up if a real app hits it.
72
+ - Capping padding at a viewport edge instead of the last painted column.
73
+ - Dashboard peek (text view) and web dashboard (real xterm.js frontend).
74
+
75
+ ## 6. Testability split (design constraint)
76
+
77
+ **Test boundary:** `PtyAttachComponent.render(width)` — the public surface
78
+ already used by `test-support/hyperlink-cell-smoke.ts`. Height comes from the
79
+ stub TUI (`tui.terminal.rows`), not from the argument. The fixture
80
+ constructs terminal state by writing ANSI into the component's real
81
+ `@xterm/headless` terminal, isolates all side effects (socket path
82
+ `/no/such/socket`, stub TUI, `dispose()` in `finally`), and returns the raw
83
+ rendered lines as JSON. Assertions live in `node:test` and never touch the
84
+ terminal directly.
85
+
86
+ **Pieces:**
87
+
88
+ | Piece | Kind | Test |
89
+ | --- | --- | --- |
90
+ | `test-support/attach-bg-paint-smoke.ts` | fixture (side effects isolated here) | driven by the .mjs test via `--experimental-transform-types` |
91
+ | `test/pty-attach-bg-paint.test.mjs` | assertions | `npm test` |
92
+
93
+ **Why no pure function is split out:** `lineToAnsi` is already pure given
94
+ `(line, reusable, term, selection, cursor)`; the only thing that can regress is
95
+ *which cells reach the output*. A helper returning `renderEnd` would be unit
96
+ tested while the actual loop bound could still be reverted to `last`, i.e. the
97
+ test would pass with the bug present. The render-boundary test fails if any of
98
+ C1/C2/C3 is reverted. If a future change makes this loop hot enough to justify
99
+ extraction, the same smoke test remains valid.
100
+
101
+ **Red-green proof (A8):** the fixture must produce cells with
102
+ `getChars() === ""` **and** a non-default bg — only erase sequences (EL `\x1b[K`
103
+ / ED `\x1b[2J`) under an active bg create those. Writing literal spaces would
104
+ make `getChars()` non-empty and the unpatched code would pass. Before
105
+ committing, revert C2's bound to `last` temporarily and confirm A1/A2 fail, then
106
+ restore; record both runs in the PR description.
107
+
108
+ ## 7. Acceptance matrix
109
+
110
+ | ID | 功能点 | 验收方式 | 具体验证 | 通过标准 |
111
+ | --- | --- | --- | --- | --- |
112
+ | A1 | 空白行的非默认背景不再被丢弃 | 自动化验证(integration,组件 render 输出) | `node --test test/pty-attach-bg-paint.test.mjs`;fixture 先发 `\x1b[48;2;30;30;46m` 再对空行发 `\x1b[K`(EL擦除,生成 `getChars()===""` 的 bg-only 单元格) | 该行渲染结果非空且含 `48;2;30;30;46` |
113
+ | A2 | 内容行尾部背景渲染到最后被涂色的列 | 同上 | 写 `AB` → `\x1b[41G`(1-based 第 41 列 = 0-based col 40)→ `\x1b[K` | `AB` 后有 38 个默认背景空格(0-based col 2–39),其后 40 个空格带 `48;2;30;30;46`(col 40–79);尾部 `\x1b[0m` 不计 |
114
+ | A3 | 默认背景的空白行保持空串(零字节开销路径不回退) | 同上 | fixture 中纯文本屏幕的空白行 | 对应行 `=== ""` |
115
+ | A4 | 宽字符行的背景填充列数正确 | 同上 | 写 `中`(宽字符)→ 在 bg 激活下 `\x1b[K` 擦到行尾 | 渲染行显示宽度 === 40,且 `中` 之后紧跟 38 个涂色空格(续列 `getWidth()===0` 不计入输出) |
116
+ | A5 | 光标落在填充区内只绘制一次 | 同上 | 光标置于涂色空白行的中部,`cursorHidden=false`(fixture 形状照抄 `test-support/cursor-visibility-smoke.ts`) | 该行恰含一个 `CURSOR_MARKER` 与一个反显块 |
117
+ | A6 | 类型与模块契约不破 | 自动化验证(static) | `npm run typecheck`(注意:tsconfig 排除 `test`/`test-support`,fixture 类型由 A1 运行时暴露) | 退出码 0 |
118
+ | A7 | 全量门禁 | 自动化验证(build/test suite/coverage/pack) | `npm run verify` | 全部通过(覆盖率阈值 lines 85 / funcs 80 / branches 70) |
119
+ | A8 | 测试对修复有判别力(防「未修复也绿」) | 自动化验证(mutation,一次性,非 CI) | 临时把 C2 的边界改回 `x <= last` → 跑 A1/A2 → 还原 | 回退时 A1/A2 均失败,还原后均通过;两次输出记入 PR 描述 |
120
+ | A9 | 填充区参与选区时仍可反显 | 自动化验证(integration,组件 render 输出) | fixture 通过私有字段 `selection = { anchor: { line, col: 20 }, focus: { line, col: 60 } }` 选中涂色区(形状照抄 `MouseSelection`,`src/ui/pty-attach.ts:159`) | 该行在 col 20–60 的渲染片段含反显属性 `7`;复制文本(`selectionText()`)不受 padding 影响 |
121
+ | U1 | 真实 nvim/catppuccin attach 观感 | 用户实测 | 见下方「U1 执行前置」,时机:PR 分支可安装之后、合并之前 | 空区域为 `#1e1e2e`;光标行高亮横贯整行 |
122
+
123
+ **U1 执行前置**(否则 attach 的是 npm 旧包,看不到修复):
124
+
125
+ 0. 确认 payload 是 PR head:`git log -1` 与 PR 的 head commit 对齐(worktree 就是 PR 分支时天然满足)。
126
+ 1. 在 worktree 内 `npm install`。
127
+ 2. 让 Pi 加载该 checkout:`pi install "$(pwd)"`(README「Local checkout」)或临时软链
128
+ `ln -s "$PWD" ~/.pi/agent/extensions/agent-board`(README「Development auto-discovery」)。
129
+ 3. **重启 pi** —— 扩展只在启动时加载。
130
+ 4. `/agent-board` → attach 到 nvim/catppuccin 会话,观察空缓冲区与光标行。
131
+ 5. 收尾:`pi remove "$(pwd)"` 或 `rm ~/.pi/agent/extensions/agent-board`。
132
+
133
+ > 记录:报告者已在 issue 评论中对该补丁做过一次视觉验证;U1 在合并前按上述步骤
134
+ > 在 PR 构建上复确认一次即可,不必重复造场景。A5 的 `CURSOR_MARKER`
135
+ > (`\x1b_pi:c\x07`)路径已由 `test-support/cursor-visibility-smoke.ts` 证明稳定。
136
+
137
+ ## 8. Risks
138
+
139
+ | Risk | Mitigation |
140
+ | --- | --- |
141
+ | Full-width serialization increases bytes for painted screens | Differential renderer; A2/A3 pin the cheap path. |
142
+ | Selection highlight now covers padding | Intentional and documented; copy path unaffected. |
143
+ | Cursor double-block regression | C3 + A5. |
144
+ | Wide-char padding misalignment | A4. |
145
+ | Test fixture drifts from the component's private API | Same pattern as existing smoke fixtures (`hyperlink-cell-smoke.ts`); only `term`, `receivedOutput`, `finishAttachTransition` are touched. `test-support/` is outside `tsconfig` (`exclude: ["node_modules", "test", "test-support"]`), so fixture type errors surface at A1's test run, not at A6 — same as every existing smoke fixture. |
146
+ | Test passes on unpatched code | A1/A2 use EL/ED-erased bg-only cells (literal spaces would keep `getChars()` non-empty); A8 records the red-green proof. |