@zhuxixi/pi-agent-board 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/README.md +15 -8
- 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-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-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/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-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/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 +198 -44
- package/src/ui/pty-attach.ts +1462 -117
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Issue #257 — Legacy pty-runner endpoint cleanup: Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use subagent-driven-development (recommended) or executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** A legacy PTY runner never deletes an endpoint it no longer owns, while still cleaning up its own on a normal shutdown.
|
|
6
|
+
|
|
7
|
+
**Architecture:** Inside `legacyMain` only: record `{dev,ino}` at listen, stop calling `server.close()` (libuv unlinks the bind path on handle close — `nodejs/node#19729`), and gate the explicit unlink on the existing pure `ownsEndpoint`. No new pure functions, no protocol change.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** Node ESM (`.mjs`), `node:test` + `assert/strict`, existing `pty-runner.integration.test.mjs` fixtures.
|
|
10
|
+
|
|
11
|
+
**Spec:** `docs/superpowers/specs/2026-10-28-issue-257-legacy-pty-runner-endpoint-cleanup-design.md` (converged after 2 cross-review rounds; findings trail in `~/.github-issue-driven/zhuxixi/pi-agent-board/issue-257/research/`)
|
|
12
|
+
|
|
13
|
+
## Global Constraints
|
|
14
|
+
|
|
15
|
+
- POSIX-only behaviour; all new assertions guarded by `process.platform === "win32"` → `t.skip("POSIX AF_UNIX only")`.
|
|
16
|
+
- New test titles MUST be exactly `#257 A<n>: <summary>`; A1's selector anchors on `#257 A1:` because `#257 A1` is a prefix of `#257 A1b`.
|
|
17
|
+
- Do not touch `ownedMain` (out of scope) or the legacy boot-time unlink at `:140-142`.
|
|
18
|
+
- Tabs for indentation; English comments; conventional commit subjects with `(issue #257)`.
|
|
19
|
+
- Local Windows has no WSL/Docker: A1/A1b/A2 show as `skip` locally and execute on Linux CI only. `node --test --test-name-pattern="zzz"` exits 0 — always read the summary line, never the exit code alone.
|
|
20
|
+
|
|
21
|
+
## Review Focus
|
|
22
|
+
|
|
23
|
+
- A legacy shutdown after the path was replaced must leave the replacement intact (the bug).
|
|
24
|
+
- A legacy normal shutdown must still remove its own socket (no stale-socket regression).
|
|
25
|
+
- The identity must be captured before `state: "alive"` is published, or `hostReady` is not a barrier.
|
|
26
|
+
- Removing `server.close()` must not change shutdown timing/child handling.
|
|
27
|
+
- win32: no identity is captured; the cleanup degrades to a no-op (named pipes never unlink).
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### Task 1: legacyMain identity + no-close + gated unlink, with the three integration cases
|
|
32
|
+
|
|
33
|
+
**Files:**
|
|
34
|
+
- Modify: `runner/pty-runner.mjs` (`legacyMain`: identity holder, listen callback at `:409`, `shutdown` at `:503-531`)
|
|
35
|
+
- Test: `test/pty-runner.integration.test.mjs` (append three tests; file already imports `statSync`, `createServer`, `spawn`, `P`, `createView`, `readHost`, `atomicWriteJson`, and has `freshRoot`/`waitFor`/`hostReady`)
|
|
36
|
+
|
|
37
|
+
**Interfaces:**
|
|
38
|
+
- Consumes: `ownsEndpoint(bound, current)` (already imported at `runner/pty-runner.mjs:20`), `P.controlSocketPath(root, viewId)`, `P.hostConfigPath(root, viewId)`.
|
|
39
|
+
- Produces: nothing exported; `boundSocketIdentity` becomes a `legacyMain`-local variable; diagnostic `coordinator_endpoint_lost` is NOT used here (that is the coordinator path).
|
|
40
|
+
|
|
41
|
+
- [ ] **Step 1: Write the three failing tests**
|
|
42
|
+
|
|
43
|
+
Append to `test/pty-runner.integration.test.mjs` (use the exact helper names already in the file):
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
/** Shared fixture: boot a legacy runner (host-config WITHOUT instanceId). */
|
|
47
|
+
async function bootLegacyRunner(t, viewId = "v1") {
|
|
48
|
+
const root = freshRoot();
|
|
49
|
+
const meta = createView(root, { id: viewId, name: "legacy-endpoint", cwd: process.cwd() });
|
|
50
|
+
const configPath = P.hostConfigPath(root, viewId);
|
|
51
|
+
atomicWriteJson(configPath, {
|
|
52
|
+
root,
|
|
53
|
+
viewId,
|
|
54
|
+
sessionFile: meta.sessionFile,
|
|
55
|
+
cwd: process.cwd(),
|
|
56
|
+
initialPrompt: null,
|
|
57
|
+
piCommand: process.execPath,
|
|
58
|
+
piArgsPrefix: [resolve("test-support/fake-pty-pi.mjs")],
|
|
59
|
+
model: null,
|
|
60
|
+
tools: null,
|
|
61
|
+
env: { AGENT_BOARD_ALLOW_PIPE_FALLBACK: "1" },
|
|
62
|
+
cols: 80,
|
|
63
|
+
rows: 24,
|
|
64
|
+
});
|
|
65
|
+
const runner = spawn(process.execPath, [resolve("runner/pty-runner.mjs"), configPath], {
|
|
66
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
67
|
+
});
|
|
68
|
+
runner.stdout.resume();
|
|
69
|
+
runner.stderr.resume();
|
|
70
|
+
await waitFor(() => hostReady(root, viewId));
|
|
71
|
+
return { root, runner, socketPath: P.controlSocketPath(root, viewId) };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function waitExit(child, timeoutMs = 5000) {
|
|
75
|
+
return new Promise((done) => {
|
|
76
|
+
if (child.exitCode !== null) return done(child.exitCode);
|
|
77
|
+
const timer = setTimeout(() => done(null), timeoutMs);
|
|
78
|
+
child.once("exit", (code) => { clearTimeout(timer); done(code); });
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
test("#257 A1: a legacy runner cleans up its own endpoint on SIGTERM", async (t) => {
|
|
83
|
+
if (process.platform === "win32") return t.skip("POSIX AF_UNIX only");
|
|
84
|
+
const { root, runner, socketPath } = await bootLegacyRunner(t);
|
|
85
|
+
try {
|
|
86
|
+
assert.ok(existsSync(socketPath), "precondition: endpoint exists before SIGTERM");
|
|
87
|
+
runner.kill("SIGTERM");
|
|
88
|
+
const code = await waitExit(runner);
|
|
89
|
+
assert.equal(code, 0, "clean SIGTERM exit");
|
|
90
|
+
assert.equal(existsSync(socketPath), false, "normal shutdown removes its own endpoint");
|
|
91
|
+
} finally {
|
|
92
|
+
if (runner.exitCode === null) runner.kill("SIGKILL");
|
|
93
|
+
rmSync(root, { recursive: true, force: true });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("#257 A1b: a legacy runner exits cleanly when the endpoint is already gone", async (t) => {
|
|
98
|
+
if (process.platform === "win32") return t.skip("POSIX AF_UNIX only");
|
|
99
|
+
const { root, runner, socketPath } = await bootLegacyRunner(t);
|
|
100
|
+
try {
|
|
101
|
+
assert.ok(existsSync(socketPath), "precondition: endpoint exists");
|
|
102
|
+
unlinkSync(socketPath);
|
|
103
|
+
runner.kill("SIGTERM");
|
|
104
|
+
const code = await waitExit(runner);
|
|
105
|
+
assert.equal(code, 0, "ENOENT at cleanup must not crash the shutdown");
|
|
106
|
+
} finally {
|
|
107
|
+
if (runner.exitCode === null) runner.kill("SIGKILL");
|
|
108
|
+
rmSync(root, { recursive: true, force: true });
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("#257 A2: a legacy runner does not unlink a replaced endpoint", async (t) => {
|
|
113
|
+
if (process.platform === "win32") return t.skip("POSIX AF_UNIX only");
|
|
114
|
+
const { root, runner, socketPath } = await bootLegacyRunner(t);
|
|
115
|
+
const standinPath = join(root, `.standin-${process.pid}.sock`);
|
|
116
|
+
let standin = null;
|
|
117
|
+
try {
|
|
118
|
+
assert.ok(existsSync(socketPath), "precondition: endpoint exists");
|
|
119
|
+
const before = statSync(socketPath).ino;
|
|
120
|
+
standin = createServer(() => {});
|
|
121
|
+
await new Promise((ok, fail) => {
|
|
122
|
+
standin.once("error", fail);
|
|
123
|
+
standin.listen(standinPath, ok);
|
|
124
|
+
});
|
|
125
|
+
renameSync(standinPath, socketPath); // atomic, same filesystem
|
|
126
|
+
assert.notEqual(statSync(socketPath).ino, before, "stand-in really replaced the inode");
|
|
127
|
+
runner.kill("SIGTERM");
|
|
128
|
+
const code = await waitExit(runner);
|
|
129
|
+
assert.equal(code, 0, "clean SIGTERM exit");
|
|
130
|
+
assert.ok(existsSync(socketPath), "a legacy runner must not unlink an endpoint it no longer owns");
|
|
131
|
+
} finally {
|
|
132
|
+
if (runner.exitCode === null) runner.kill("SIGKILL");
|
|
133
|
+
if (standin) await new Promise((done) => standin.close(done));
|
|
134
|
+
rmSync(root, { recursive: true, force: true });
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
New imports needed at the top of the file: `unlinkSync`, `renameSync` (add to the `node:fs` import at `:2`).
|
|
140
|
+
|
|
141
|
+
- [ ] **Step 2: Run them (local: expect skip; Linux CI: expect A2 red)**
|
|
142
|
+
|
|
143
|
+
Run: `node --test --test-name-pattern="#257 A" test/pty-runner.integration.test.mjs`
|
|
144
|
+
Local Windows: `tests 3 / skipped 3` (documented channel limit). Linux: A1/A1b pass, **A2 fails**
|
|
145
|
+
(`a legacy runner must not unlink an endpoint it no longer owns`) because the old shutdown's
|
|
146
|
+
`server.close()` and unconditional unlink both delete the stand-in. Record the observed
|
|
147
|
+
summary in the ledger either way.
|
|
148
|
+
|
|
149
|
+
- [ ] **Step 3: Implement the three changes in `legacyMain`**
|
|
150
|
+
|
|
151
|
+
In `runner/pty-runner.mjs`, inside `legacyMain` (after `let shutdownExitCode = null;`):
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
/** {dev,ino} recorded at bind time; cleanup unlinks only this exact inode. */
|
|
155
|
+
let boundSocketIdentity = null;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Replace the `server.listen(...)` call at `:409` with:
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
server.listen(socketPath, () => {
|
|
162
|
+
// Capture the identity BEFORE publishing readiness: "host ready" must imply
|
|
163
|
+
// "identity recorded", or a shutdown could run with a stale/null identity.
|
|
164
|
+
if (process.platform !== "win32") {
|
|
165
|
+
try {
|
|
166
|
+
const st = statSync(socketPath);
|
|
167
|
+
boundSocketIdentity = { dev: st.dev, ino: st.ino };
|
|
168
|
+
} catch { /* without the identity, cleanup degrades to a no-op */ }
|
|
169
|
+
}
|
|
170
|
+
update({ socketPath, state: "alive" });
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
In `shutdown()`, replace:
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
try { server?.close(); } catch {}
|
|
178
|
+
try { if (existsSync(socketPath)) unlinkSync(socketPath); } catch {}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
with:
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
// Do NOT call server.close() (issue #257, nodejs/node#19729): libuv unlinks the
|
|
185
|
+
// unix-socket bind path when the listening handle closes, so a shutdown after a
|
|
186
|
+
// successor bound would delete the successor's endpoint. There is no close here,
|
|
187
|
+
// so the implicit unlink never runs. Cleanup is explicit and identity-gated below
|
|
188
|
+
// (the legacy path has no lease, so dev+ino is its only ownership proof).
|
|
189
|
+
if (process.platform !== "win32" && boundSocketIdentity) {
|
|
190
|
+
try {
|
|
191
|
+
const st = statSync(socketPath);
|
|
192
|
+
if (ownsEndpoint(boundSocketIdentity, { dev: st.dev, ino: st.ino })) {
|
|
193
|
+
try { unlinkSync(socketPath); } catch { /* best effort */ }
|
|
194
|
+
}
|
|
195
|
+
} catch { /* path gone — nothing to clean */ }
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- [ ] **Step 4: Run the cases again**
|
|
200
|
+
|
|
201
|
+
Run: `node --test --test-name-pattern="#257 A" test/pty-runner.integration.test.mjs`
|
|
202
|
+
Local Windows: `tests 3 / skipped 3` and exit 0 — read the summary, confirm 3 skipped (not 0 tests).
|
|
203
|
+
Linux CI: `tests 3 / pass 3`.
|
|
204
|
+
|
|
205
|
+
- [ ] **Step 5: Run the existing pty-runner suite for regressions**
|
|
206
|
+
|
|
207
|
+
Run: `node --test test/pty-runner.integration.test.mjs`
|
|
208
|
+
Local expectation: everything that ran before still passes (the legacy/owned cases that are
|
|
209
|
+
platform-independent). Linux CI: full pass. Any new failure must be understood before commit.
|
|
210
|
+
|
|
211
|
+
- [ ] **Step 6: Commit**
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
git add runner/pty-runner.mjs test/pty-runner.integration.test.mjs
|
|
215
|
+
git commit -m "fix(runner): stop legacy pty-runner from unlinking a replaced endpoint (issue #257)"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
### Task 2: Full verification and local code review
|
|
221
|
+
|
|
222
|
+
**Files:** none (verification + review); modify only if a gate fails.
|
|
223
|
+
|
|
224
|
+
**Interfaces:** consumes Task 1.
|
|
225
|
+
|
|
226
|
+
- [ ] **Step 1: Typecheck**
|
|
227
|
+
|
|
228
|
+
Run: `npm run typecheck` — exit 0.
|
|
229
|
+
|
|
230
|
+
- [ ] **Step 2: Targeted suites**
|
|
231
|
+
|
|
232
|
+
Run: `node --test test/pty-runner.integration.test.mjs test/host-coordination.test.mjs test/locks.test.mjs`
|
|
233
|
+
Local Windows: pass (POSIX cases skip). Linux CI: full pass.
|
|
234
|
+
|
|
235
|
+
- [ ] **Step 3: Pre-PR gate**
|
|
236
|
+
|
|
237
|
+
Run: `npm run test:coverage` (Linux CI authoritative; local Windows baseline is not the gate for
|
|
238
|
+
POSIX cases), then `npm run test:perf && npm run pack:dry`, then `npm run verify`. Record actual
|
|
239
|
+
results; a local failure caused by the known Windows platform gap must be named explicitly.
|
|
240
|
+
|
|
241
|
+
- [ ] **Step 4: Fresh-context local code review**
|
|
242
|
+
|
|
243
|
+
Dispatch a reviewer over `git diff main...HEAD` with the spec + this plan + the Review Focus
|
|
244
|
+
list; disposition findings (Critical/Important → one fix pass with a failing test first; Minor →
|
|
245
|
+
ledger). Commit only if files change.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Task ↔ acceptance traceability
|
|
250
|
+
|
|
251
|
+
| Spec acceptance ID | Task |
|
|
252
|
+
|---|---|
|
|
253
|
+
| A1, A1b, A2 | Task 1 (Steps 1-6) |
|
|
254
|
+
| A3 | Task 1 Step 5 + Task 2 Step 2 |
|
|
255
|
+
| A4 | Task 2 Step 1 |
|
|
256
|
+
| A5, A6 | Task 2 Step 3 (Linux CI authoritative) |
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# cwd Picker Full-History Search — Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** Make the launch-dialog cwd picker search the full ranked history instead of the top 8 entries (issue #262).
|
|
6
|
+
|
|
7
|
+
**Architecture:** Remove the pre-filter truncation at the dashboard wiring layer and make `rankedCwdCandidates` uncapped by default; the picker's pure state machine and the 6-row render window stay unchanged. A TS probe drives the real `handleInput()` path so the truncation regression is pinned at the layer that owned the bug.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** Node ESM `.mjs` core + TypeScript TUI (`src/ui/dashboard.ts`), `node:test` + `assert/strict`, Node `--experimental-transform-types` probes.
|
|
10
|
+
|
|
11
|
+
## Global Constraints
|
|
12
|
+
|
|
13
|
+
- `rankedCwdCandidates(root, limit = Number.POSITIVE_INFINITY)`: default returns every ranked entry; an explicit numeric `limit` still caps and still appends the home fallback afterwards (existing tests pass `limit = 2`, keep them green).
|
|
14
|
+
- `src/ui/dashboard.ts` `openLaunchPicker` loads the pool with `existingCwdCandidates(rankedCwdCandidates(this.deps.root))` — no `, 8` and no other hard-coded cap.
|
|
15
|
+
- Do not change `filterCwdCandidates`, `nextCwdPickerState`, `listDirectorySuggestions`, `browseTabCompletion`, `existingCwdCandidates`, the 6-row render window, or the ranking rule (count desc → lastUsed desc).
|
|
16
|
+
- Non-goals: symlink directory enumeration in browse mode, fuzzy matching, manual favorites, `cwd-stats.json` format changes.
|
|
17
|
+
- Tabs for indentation; English comments and commit subjects; conventional commit types.
|
|
18
|
+
- Tests use `node:test` + `assert/strict`; acceptance commands are `node --test <file>` and `npm run verify` (typecheck + perf gate + tests + coverage + pack:dry).
|
|
19
|
+
- Work from: `/home/elling/git-repo/github/pi-agent-board/.pi/worktrees/issue-262-cwd-favorites-full-pool`
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
### Task 1: Uncapped ranked candidates (core)
|
|
24
|
+
|
|
25
|
+
**Files:**
|
|
26
|
+
- Modify: `src/core/cwd-stats.mjs:92-108`
|
|
27
|
+
- Test: `test/cwd-stats.test.mjs` (append after the existing `rankedCwdCandidates appends home with its real count when sliced out by limit` test)
|
|
28
|
+
|
|
29
|
+
**Interfaces:**
|
|
30
|
+
- Consumes: `readCwdStats(root)` (already returns all entries), `os.homedir()`.
|
|
31
|
+
- Produces: `rankedCwdCandidates(root, limit = Number.POSITIVE_INFINITY) -> Array<{path: string, count: number}>` — uncapped by default.
|
|
32
|
+
|
|
33
|
+
- [ ] **Step 1: Write the failing test**
|
|
34
|
+
|
|
35
|
+
Append to `test/cwd-stats.test.mjs`:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
test("rankedCwdCandidates defaults to the full history with no 8-entry cap (issue #262)", () => {
|
|
39
|
+
const root = freshRoot();
|
|
40
|
+
try {
|
|
41
|
+
const dirs = Array.from({ length: 10 }, (_, i) => `/dir-${String(i + 1).padStart(2, "0")}`);
|
|
42
|
+
writeViews(root, dirs.map((dir, i) => [`v${i}`, dir, 1000 - i]));
|
|
43
|
+
seedCwdStatsFromViews(root);
|
|
44
|
+
const ranked = rankedCwdCandidates(root);
|
|
45
|
+
assert.deepEqual(
|
|
46
|
+
ranked.slice(0, 10),
|
|
47
|
+
dirs.map((dir) => ({ path: dir, count: 1 })),
|
|
48
|
+
);
|
|
49
|
+
assert.equal(ranked.length, 11);
|
|
50
|
+
assert.deepEqual(ranked[10], { path: os.homedir(), count: 0 });
|
|
51
|
+
} finally {
|
|
52
|
+
rmSync(root, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- [ ] **Step 2: Run the test to verify it fails**
|
|
58
|
+
|
|
59
|
+
Run: `node --test test/cwd-stats.test.mjs`
|
|
60
|
+
Expected: the new test FAILS — `ranked.slice(0, 10)` has only 8 recorded dirs, then the home fallback at index 8 (`ranked.length` is 9, not 11).
|
|
61
|
+
|
|
62
|
+
- [ ] **Step 3: Change the default limit**
|
|
63
|
+
|
|
64
|
+
In `src/core/cwd-stats.mjs`, replace the function header and JSDoc:
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
/**
|
|
68
|
+
* Ranked candidates: count desc, then lastUsed desc; home appended at the
|
|
69
|
+
* end when absent so the user's home dir is always one keystroke away.
|
|
70
|
+
* `limit` is an optional cap for callers that explicitly want one; the
|
|
71
|
+
* default returns the whole history so the launch picker can search it.
|
|
72
|
+
* @param {string} root @param {number=} limit
|
|
73
|
+
* @returns {Array<{path: string, count: number}>}
|
|
74
|
+
*/
|
|
75
|
+
export function rankedCwdCandidates(root, limit = Number.POSITIVE_INFINITY) {
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Leave the body unchanged: `rows.slice(0, Math.max(1, limit))` already treats `Infinity` as "no cap".
|
|
79
|
+
|
|
80
|
+
- [ ] **Step 4: Run the test to verify it passes**
|
|
81
|
+
|
|
82
|
+
Run: `node --test test/cwd-stats.test.mjs`
|
|
83
|
+
Expected: PASS — all `cwd-stats` tests green, including the existing `limit = 2` cases.
|
|
84
|
+
|
|
85
|
+
- [ ] **Step 5: Commit**
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
git add src/core/cwd-stats.mjs test/cwd-stats.test.mjs
|
|
89
|
+
git commit -m "fix(cwd): stop capping ranked cwd candidates at 8 (issue #262)"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### Task 2: Dashboard loads the full pool + picker regression probe
|
|
95
|
+
|
|
96
|
+
**Files:**
|
|
97
|
+
- Modify: `src/ui/dashboard.ts:755`
|
|
98
|
+
- Create: `test-support/cwd-favorites-pool-probe.ts`
|
|
99
|
+
- Create: `test/dashboard-cwd-favorites-pool.test.mjs`
|
|
100
|
+
- Test: `test/launch-options.test.mjs` (append)
|
|
101
|
+
|
|
102
|
+
**Interfaces:**
|
|
103
|
+
- Consumes: `rankedCwdCandidates(root)` (uncapped, Task 1), `existingCwdCandidates`, `nextCwdPickerState`, `DashboardComponent.openLaunchPicker`.
|
|
104
|
+
- Produces: no new production API; the dashboard now stores the full existing ranked history in `launch.cwdRanked`.
|
|
105
|
+
|
|
106
|
+
- [ ] **Step 1: Write the failing integration probe**
|
|
107
|
+
|
|
108
|
+
Create `test-support/cwd-favorites-pool-probe.ts`:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// cwd favorites-pool probe (issue #262): seed more favorites than the legacy
|
|
112
|
+
// 8-entry cap, then type a fragment of the lowest-ranked entry through the
|
|
113
|
+
// public handleInput() path and report the picker state as JSON.
|
|
114
|
+
// Run via `node --experimental-transform-types` (dashboard.ts uses TS
|
|
115
|
+
// parameter properties). Not typechecked (tsconfig excludes test-support).
|
|
116
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
117
|
+
import { tmpdir } from "node:os";
|
|
118
|
+
import { join } from "node:path";
|
|
119
|
+
import { createService } from "../src/runtime/service.mjs";
|
|
120
|
+
import { DashboardComponent } from "../src/ui/dashboard.ts";
|
|
121
|
+
|
|
122
|
+
const root = mkdtempSync(join(tmpdir(), "agentview-cwd-pool-"));
|
|
123
|
+
const entries: Record<string, { count: number; lastUsed: number }> = {};
|
|
124
|
+
for (let i = 1; i <= 9; i++) {
|
|
125
|
+
const dir = join(root, `rank-${String(i).padStart(2, "0")}`);
|
|
126
|
+
mkdirSync(dir, { recursive: true });
|
|
127
|
+
entries[dir] = { count: 100 - i, lastUsed: 1000 - i };
|
|
128
|
+
}
|
|
129
|
+
const target = join(root, "work", "proj", "stability", "alert-automation");
|
|
130
|
+
mkdirSync(target, { recursive: true });
|
|
131
|
+
entries[target] = { count: 1, lastUsed: 1 };
|
|
132
|
+
writeFileSync(join(root, "cwd-stats.json"), JSON.stringify({ version: 1, entries }));
|
|
133
|
+
|
|
134
|
+
const service = createService({
|
|
135
|
+
root,
|
|
136
|
+
runnerScript: "/no/runner.mjs",
|
|
137
|
+
piCommand: "pi",
|
|
138
|
+
piArgsPrefix: [],
|
|
139
|
+
defaultCwd: root,
|
|
140
|
+
launch: () => ({ pid: null, configPath: "/no/config.json" }),
|
|
141
|
+
launchHost: () => ({ pid: null, configPath: "/no/host-config.json" }),
|
|
142
|
+
launchTitle: () => ({ pid: null, configPath: "/no/title-config.json" }),
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const tui = {
|
|
146
|
+
terminal: { rows: 24, cols: 80, columns: 80, write: () => {} },
|
|
147
|
+
requestRender: () => {},
|
|
148
|
+
};
|
|
149
|
+
const theme = { fg: (_c: string, t: string) => t, bold: (t: string) => t, bg: (_c: string, t: string) => t };
|
|
150
|
+
|
|
151
|
+
const dash = new DashboardComponent(tui, theme, {}, () => {}, {
|
|
152
|
+
service,
|
|
153
|
+
root,
|
|
154
|
+
defaultCwd: root,
|
|
155
|
+
availableModels: [],
|
|
156
|
+
currentModel: null,
|
|
157
|
+
currentThinkingLevel: "off",
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// TS-private is runtime-accessible; input must be non-empty or
|
|
161
|
+
// openLaunchDialog() bails back to list mode and launch stays null.
|
|
162
|
+
dash.input = "go";
|
|
163
|
+
dash.openLaunchDialog();
|
|
164
|
+
dash.openLaunchPicker("cwd", "");
|
|
165
|
+
for (const ch of "aler") dash.handleInput(ch);
|
|
166
|
+
|
|
167
|
+
const out = { target, mode: dash.launch?.cwdPickerMode, suggestions: dash.launch?.cwdSuggestions };
|
|
168
|
+
dash.dispose();
|
|
169
|
+
console.log(JSON.stringify(out));
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Create `test/dashboard-cwd-favorites-pool.test.mjs`:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import assert from "node:assert/strict";
|
|
176
|
+
import { execFileSync } from "node:child_process";
|
|
177
|
+
import { fileURLToPath } from "node:url";
|
|
178
|
+
import { join } from "node:path";
|
|
179
|
+
import test from "node:test";
|
|
180
|
+
|
|
181
|
+
const ROOT_DIR = fileURLToPath(new URL("../", import.meta.url));
|
|
182
|
+
const PROBE = join(ROOT_DIR, "test-support", "cwd-favorites-pool-probe.ts");
|
|
183
|
+
|
|
184
|
+
test("cwd picker: favorites search covers entries ranked below the old 8-entry cap (issue #262)", () => {
|
|
185
|
+
// dashboard.ts uses TS parameter properties, which strip-only mode rejects;
|
|
186
|
+
// --experimental-transform-types handles them (Node 22.7+ / 24).
|
|
187
|
+
const out = execFileSync(process.execPath, ["--experimental-transform-types", PROBE], {
|
|
188
|
+
encoding: "utf8",
|
|
189
|
+
timeout: 30_000,
|
|
190
|
+
});
|
|
191
|
+
const r = JSON.parse(out);
|
|
192
|
+
assert.equal(r.mode, "favorites");
|
|
193
|
+
assert.deepEqual(r.suggestions, [r.target]);
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
- [ ] **Step 2: Run the probe test to verify it fails**
|
|
198
|
+
|
|
199
|
+
Run: `node --test test/dashboard-cwd-favorites-pool.test.mjs`
|
|
200
|
+
Expected: FAIL — `mode` is `"browse"` and `suggestions` is `[]`, because `dashboard.ts:755` still passes `, 8` and the rank-10 target falls outside the pool.
|
|
201
|
+
|
|
202
|
+
- [ ] **Step 3: Load the full pool in the dashboard**
|
|
203
|
+
|
|
204
|
+
In `src/ui/dashboard.ts`, inside `openLaunchPicker`, replace:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
launch.cwdRanked = existingCwdCandidates(rankedCwdCandidates(this.deps.root, 8));
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
with:
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
launch.cwdRanked = existingCwdCandidates(rankedCwdCandidates(this.deps.root));
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
- [ ] **Step 4: Run the probe test to verify it passes**
|
|
217
|
+
|
|
218
|
+
Run: `node --test test/dashboard-cwd-favorites-pool.test.mjs`
|
|
219
|
+
Expected: PASS — `mode === "favorites"` and `suggestions === [target]`.
|
|
220
|
+
|
|
221
|
+
- [ ] **Step 5: Pin the state-machine semantics for long lists**
|
|
222
|
+
|
|
223
|
+
Append to `test/launch-options.test.mjs`:
|
|
224
|
+
|
|
225
|
+
```js
|
|
226
|
+
test("nextCwdPickerState searches matches below the 8th ranked entry (issue #262)", () => {
|
|
227
|
+
const bigRanked = Array.from({ length: 12 }, (_, i) => ({
|
|
228
|
+
path: `/ranked/dir-${String(i + 1).padStart(2, "0")}`,
|
|
229
|
+
count: 100 - i,
|
|
230
|
+
}));
|
|
231
|
+
const state = nextCwdPickerState("dir-10", bigRanked, "/tmp");
|
|
232
|
+
assert.equal(state.mode, "favorites");
|
|
233
|
+
assert.deepEqual(state.suggestions, [bigRanked[9].path]);
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- [ ] **Step 6: Run the focused suites**
|
|
238
|
+
|
|
239
|
+
Run: `node --test test/cwd-stats.test.mjs test/launch-options.test.mjs test/dashboard-cwd-favorites-pool.test.mjs test/dashboard-cwd-tab.test.mjs`
|
|
240
|
+
Expected: PASS — new coverage plus the existing browse/favorites Tab regression (A4).
|
|
241
|
+
|
|
242
|
+
- [ ] **Step 7: Run the full gate**
|
|
243
|
+
|
|
244
|
+
Run: `npm run verify`
|
|
245
|
+
Expected: PASS — typecheck, perf gate, full test suite, coverage thresholds, pack:dry.
|
|
246
|
+
|
|
247
|
+
- [ ] **Step 8: Commit**
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
git add src/ui/dashboard.ts test-support/cwd-favorites-pool-probe.ts test/dashboard-cwd-favorites-pool.test.mjs test/launch-options.test.mjs
|
|
251
|
+
git commit -m "fix(cwd): search the full ranked history in the launch picker (issue #262)"
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Acceptance Traceability
|
|
257
|
+
|
|
258
|
+
| Spec ID | Plan task | Verification in this plan |
|
|
259
|
+
| --- | --- | --- |
|
|
260
|
+
| A1 | Task 1 | Step 1–4 (`node --test test/cwd-stats.test.mjs`) |
|
|
261
|
+
| A2 | Task 2 | Step 1–4 (`node --test test/dashboard-cwd-favorites-pool.test.mjs`) |
|
|
262
|
+
| A3 | Task 2 | Step 5 (`node --test test/launch-options.test.mjs`) |
|
|
263
|
+
| A4 | Task 2 | Step 6 (focused suites incl. `test/dashboard-cwd-tab.test.mjs`) |
|
|
264
|
+
| A5 | Task 2 | Step 7 (`npm run verify`) |
|
|
265
|
+
| A6 | Task 1 / Task 2 | Existing corrupt-stats, stale-filter and empty-pool tests re-run in Steps 4 and 6 |
|
|
266
|
+
| U1 | post-merge | Manual TUI run per spec §8 U1 (requires updated install copy; recorded as `pending` until executed) |
|