Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2454b4c
fix(start-server): forward argv + propagate child exit on SIGINT
zaynram May 28, 2026
8e204ec
docs(roadmap): mark S2 landed; link to branch
zaynram May 28, 2026
04a39ed
spec(S1.v1.1): drop inbound annotation reconciliation; rewrite §13
zaynram May 28, 2026
5500004
fix(pdf): rewrite interact() to vendor's {viewUUID, action} wire enve…
zaynram May 28, 2026
d97f3cf
fix(annotations,pdf): push-only propagation + scholar.pdf.open regist…
zaynram May 28, 2026
d47298e
test(pdf): vendor wire-envelope contract test (S1 drift canary)
zaynram May 28, 2026
6dd56cf
spec(S1.v1.1): document displayPdf() on §7.6 PdfChild contract
zaynram May 28, 2026
0874f34
docs(roadmap): mark S1 landed; link to branch + commits
zaynram May 28, 2026
99355f9
docs(roadmap): retarget S1/S2 branch refs to worktree-pre-v1-roadmap
zaynram May 28, 2026
6dbd990
fix(ollama): wrap embed/chat fetches in AbortSignal.timeout (S3)
zaynram May 28, 2026
eba95b0
docs(roadmap): mark S3 landed; link to commit 6dbd990
zaynram May 28, 2026
7fc166c
fix(corpus): use argv-form tar to neutralize shell injection (H1)
zaynram May 29, 2026
6bbb85d
fix(tools): emit structuredContent for view-opener tool results (H2)
zaynram May 29, 2026
d6c5e23
test(papers): seed DB via applyMigrations to eliminate schema drift (H3)
zaynram May 29, 2026
c273a83
fix(sqlite-vec): anchor dev vec0 path to import.meta.dir, not cwd (H4)
zaynram May 29, 2026
d071bb3
fix(migrations): assert PRAGMA foreign_keys=ON before migrate (H5)
zaynram May 29, 2026
3348b23
docs(roadmap): mark H1-H5 landed; link to commits
zaynram May 29, 2026
d101adb
fix(primitives): wrap realpathSync(root) in PathEscapeError (M9)
zaynram May 29, 2026
b31c7a1
fix(runtime-config): fsync parent directory after rename (M1)
zaynram May 29, 2026
1d4c294
fix(migrations): narrow countBundledMigrations catch to absent-folder…
zaynram May 29, 2026
5973060
test(annotations): pin phase-2 throw → row persists → retry idempoten…
zaynram May 29, 2026
e351c11
fix(vec): wrap Float32Array bind sites in toTightFloat32 (M3)
zaynram May 29, 2026
536ab98
fix(raw-ddl): align embedDim reader with canonical JSON convention (M4)
zaynram May 29, 2026
00cc76c
fix(chunker): drop tail chunks with ≤1 word of new content (M6)
zaynram May 29, 2026
ed95d9c
fix(papers): raise hybrid-search vec scan LIMIT 200 → 1000 (M5)
zaynram May 29, 2026
691daa9
docs(pdf): annotate Win32 Job Object attach-after-spawn race acceptan…
zaynram May 29, 2026
42edde2
docs(roadmap): mark M1-M9 landed; link to commits
zaynram May 29, 2026
901a07c
fix(raw-ddl): throw RawDdlInvariantError on chunk_vec/embed.dim desyn…
zaynram May 29, 2026
8958c2c
fix(primitives): preserve realpath error via Error.cause on PathEscap…
zaynram May 29, 2026
ac6c225
test(papers): pin M5 LIMIT 1000 with diversity-starvation regression …
zaynram May 29, 2026
a69e13e
test(runtime-config): pin M1 fsync via FileHandle.sync spy
zaynram May 29, 2026
14016e0
test(papers): pin M3 toTightFloat32 invocation at the qvec bind site
zaynram May 29, 2026
a5b4301
test(annotations): pin M8 delete-path push-failure asymmetry vs upsert
zaynram May 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 52 additions & 42 deletions docs/audits/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,71 @@

## Showstopper batch (S1–S3) — must land first

### S1 — pdf-viewer interop rewrite + §13 spec amendment
### S1 — pdf-viewer interop rewrite + §13 spec amendment ✅ landed 2026-05-27

- [ ] **Spec edit** `docs/superpowers/specs/2026-05-22-scholar-plugin-design.md` §13: drop inbound reconciliation phase. Document the one-way push contract. Remove every `list_annotations` reference (6+ sites).
- [ ] **Spec edit** §7.6 `PdfChild` contract: change `interact(commands: PdfCommand[])` → `interact(cmd: PdfCommand)`. Wire envelope translates `{type, ...rest}` → `{action: type, ...rest}` at transport boundary. Cite `src/vendor/pdf-server/dist/src/commands.d.ts` as source of truth for the `PdfCommand` union.
- [ ] **Spec add** §16 vendor-tool truth invariant: every command name in the spec must be exported by `src/vendor/pdf-server/dist/server.js`. The spec MAY NOT invent vendor capabilities.
- [ ] **Code** `src/server/pdf/lifecycle.ts` `interact()`: rewrite to take a single `PdfCommand`, translate `type` → `action`, always call `callTool({ name: "interact", arguments: {...} })`. Drop the per-command tool-name routing at `lifecycle.ts:208`.
- [ ] **Code** `src/server/tools/pdf.ts:244` envelope: route through `lifecycle.interact()`. Delete the `{tool, args}` envelope.
- [ ] **Code** `src/server/tools/annotations.ts`: rewrite reconciler against the chosen §13 path. Drop the `list_annotations` enumeration phase. Treat DB as source of truth; push-only outbound.
- [ ] **Test** add a contract-level test that spawns the actual vendor process and exercises at least one real `interact` call. Pick `navigate` as the smoke target (simplest payload).
- [ ] **Test** rewrite `annotations.test.ts` injections to mock at the `lifecycle.interact()` boundary, not at the handler's `ctx.pdf.interact` injection point — that gap is what hid the bug.
Branch: `worktree-pre-v1-roadmap` (consolidated showstopper branch; S1 commits 04a39ed → 6dd56cf, cherry-picked from the now-deleted `worktree-s1-pdf-interop-and-13-amendment`).

### S2 — CLI mode argv + SIGINT
- [x] **Spec edit** §13 v1.1 — inbound reconciliation removed; one-way push contract documented; all 6+ `list_annotations` references purged (commit 04a39ed).
- [x] **Spec edit** §7.6 PdfChild contract — `interact(cmd, {viewUUID, ...})`; envelope `{type, ...rest}` → `{viewUUID, action: type, ...rest}` translation pinned. `displayPdf()` added as a sibling vendor tool (commits 04a39ed, 6dd56cf).
- [x] **Spec add** §16 vendor-tool truth invariant — vendor commands.d.ts pinned as source of truth (commit 04a39ed).
- [x] **Code** `src/server/pdf/lifecycle.ts` `interact()` rewrite + `getText()` routed through interact + `displayPdf()` added (commit 5500004).
- [x] **Code** `src/server/tools/pdf.ts` `refreshExtraction` viewUUID lookup via `ctx.pdfViews`; new `scholar.pdf.open` tool registers viewUUIDs; broken v1.0 proxies dropped (commit d97f3cf).
- [x] **Code** `src/server/tools/annotations.ts` push-only rewrite + serializeForViewer maps scholar rows → vendor's NoteAnnotation shape (commit d97f3cf).
- [x] **Test** real-vendor contract test `src/server/pdf/lifecycle.contract.test.ts` — navigate + add/remove_annotations envelopes, gated by `SCHOLAR_PDF_E2E=1` (commit d47298e; both fixtures pass against the real vendor process).
- [x] **Test** `annotations.test.ts` rewritten — 22 tests covering NO_OPEN_VIEWER, write-then-push, idempotency, vendor note shape; v1.0 reconciler tests (Red-4/5/7b/7c/8b/9) retired with the reconciler (commit d97f3cf).

- [ ] **Code** `scripts/start-server.ts:6-10`: forward `process.argv.slice(2)` into `Bun.spawn`.
- [ ] **Code** `scripts/start-server.ts:5`: SIGINT forwards to child; await child exit; propagate child's exit code instead of `process.exit(0)`.
- [ ] **Test** add a test that launches `scholar --help` and asserts non-empty stdout + exit 0.
- [ ] **Test** add a test that SIGINT-during-child-running propagates the child's exit code.
### S2 — CLI mode argv + SIGINT ✅ landed 2026-05-27

### S3 — Ollama client timeouts
Branch: `worktree-pre-v1-roadmap` (S2 commits 2454b4c → 8e204ec; precedes S1 on the branch since S2 was authored first off `main`, then S1 cherry-picked atop).

- [ ] **Code** `src/server/ollama/client.ts:60-83`: wrap embed fetch in `AbortSignal.timeout(60_000)`; surface `OllamaUnavailableError` on timeout.
- [ ] **Code** `src/server/ollama/client.ts:85-96`: wrap chat fetch in `AbortSignal.timeout(120_000)`; same error shape.
- [ ] **Test** add timeout tests using a fixture server that hangs past the timeout.
- [x] **Code** `scripts/start-server.ts`: replace `Bun.$` with `Bun.spawn`; forward `process.argv.slice(2)` to the child.
- [x] **Code** `scripts/start-server.ts`: SIGINT handler forwards to the child; parent awaits `child.exited` and propagates its code instead of `process.exit(0)`.
- [x] **Test** `tests/start-server.test.ts` — fixture stub `build/scholar` binary asserts `--help` reaches the child (stdout marker + exit 0).
- [x] **Test** `tests/start-server.test.ts` — same fixture, `--block` mode installs a child SIGINT handler exiting 42; the test sends SIGINT to the parent and asserts exit 42 (not 0).

### S3 — Ollama client timeouts ✅ landed 2026-05-27

Branch: `worktree-pre-v1-roadmap` (S3 commit 6dbd990).

- [x] **Code** `src/server/ollama/client.ts` `postJson()` parameterized with `timeoutMs`; `AbortSignal.timeout` wired through; `TimeoutError` mapped to `OllamaUnavailableError`. Defaults: embed 60s, chat 120s. Env-overridable via `SCHOLAR_OLLAMA_{EMBED,CHAT}_TIMEOUT_MS` so tests can use short windows.
- [x] **Code** `embed()` passes `embedTimeoutMs()`; `chat()` passes `chatTimeoutMs()` — both methods (not stored constants) so env-var overrides take effect at call time, mirroring `baseUrl()`.
- [x] **Test** `src/server/ollama/client.test.ts` — two regression tests using a `Bun.serve` fixture whose fetch handler returns a never-resolving promise; env override sets a 250ms timeout; assertion: throws `OllamaUnavailableError` in well under 5s (would hang indefinitely without the fix). Pre-fix the tests deadlock the runner; post-fix they pass in ~0.5s.

---

## High-priority batch (H1–H5) — land before personal-use ship
## High-priority batch (H1–H5) — land before personal-use ship ✅ landed 2026-05-28

Branch: `worktree-pre-v1-roadmap`. All five items landed in separate TDD cycles, one commit per H-item.

| ID | Defect | File:line | Fix |
|---|---|---|---|
| H1 | `corpus.export` shells `sh -c` with interpolation | `corpus.ts:384-387` | Replace with `Bun.spawn([cp, src, dest])` direct argv |
| H2 | View-opener tools wrap structured response into `text` block | `registry.ts:168-173` | Detect `result.openView` and emit `structuredContent` |
| H3 | `papers.test.ts` divergent inline DDL hides schema drift | `papers.test.ts:43-49` | Use `applyMigrations` against in-memory DB; delete inline DDL |
| H4 | `resolveVec0Path` uses `process.cwd()` | `sqlite-vec.ts:24-35` | Use `import.meta.dir` with relative traversal |
| H5 | No PRAGMA assertion in `applyMigrations` | `migrations.ts:39-55` | Assert `PRAGMA foreign_keys` is on before migrate |
| ID | Defect | File:line | Fix | Commit |
|---|---|---|---|---|
| H1 | `corpus.export` shells `sh -c` with interpolation | `corpus.ts:384-387` | argv-form `Bun.spawn(["tar", "--zstd", ...])` neutralizes shell metachars in runtime root | `7fc166c` |
| H2 | View-opener tools wrap structured response into `text` block | `registry.ts:168-173` | Detect `result.openView`; emit both `content` (text) and `structuredContent` envelope | `6bbb85d` |
| H3 | `papers.test.ts` divergent inline DDL hides schema drift | `papers.test.ts:43-49` | `seededDb()` uses `applyMigrations` + post-`settings` `runRawDdl` re-run for chunk_vec | `d6c5e23` |
| H4 | `resolveVec0Path` uses `process.cwd()` | `sqlite-vec.ts:24-35` | Anchor dev fallback to `import.meta.dir` (CLAUDE_PLUGIN_ROOT still wins for packaged) | `c273a83` |
| H5 | No PRAGMA assertion in `applyMigrations` | `migrations.ts:39-55` | Throw at top of `applyMigrations` if `PRAGMA foreign_keys` ≠ 1; names `openWithPragmas` in error | `d071bb3` |

Each H-item: one TDD cycle, regression test mocks at the layer above the bug (not the layer containing the bug).
Each H-item shipped with a regression test that fails pre-fix and passes post-fix. H1's test pins against a hostile runtime root containing a `"` rather than asserting on argv[0] so the implementation can swap tar binaries later without retest. Suite: 274 pass / 8 skip / 8 unchanged pre-existing failures (UI bundles + pdf.test.ts pdfViews — out of H scope). Typecheck clean.

---

## Medium-priority batch (M1–M9) — optional defensive hardening

Land as a single follow-up plan or skip until first real-world bug bites.

| ID | Defect | File:line | Why deferrable |
|---|---|---|---|
| M1 | `runtime-config.ts` no parent-dir fsync after rename | `runtime-config.ts:24-49` | App-crash bar met; OS-crash gap rare |
| M2 | Win32 Job Object attach-after-spawn race | `lifecycle.ts:148-155` | Microsecond race window |
| M3 | Float32Array view binding risk | `papers.ts:115-122` | Bun handles correctly; defensive |
| M4 | Settings serialization mismatch (`pdf.ts` writer vs `raw-ddl.ts` reader) | `pdf.ts:105-112` / `raw-ddl.ts:42-47` | Single field |
| M5 | RRF LIMIT 200 truncation bias | `papers.ts:115-122` | Acceptable at v1 corpus scale |
| M6 | Chunker tail-chunk insufficient new content | `chunker.ts:31-39` | Low-impact edge |
| M7 | `countBundledMigrations` swallows errors | `migrations.ts:68-77` | Defensive logging only |
| M8 | Phase-2 throw timing in `annotations.ts` | `annotations.ts:254-256` | Self-healing per §13; add test only |
| M9 | `resolveUnderRoot` doesn't wrap `realpathSync(root)` ENOENT | `primitives.ts:75-91` | Fires only on backup-dest path |
## Medium-priority batch (M1–M9) — defensive hardening ✅ landed 2026-05-29

Branch: `worktree-pre-v1-roadmap`. Eight items landed as Red→Green TDD cycles (M3, M8 as defense-in-depth pins). M2 is **documented acceptance**, not a code fix — closing the race needs a Win32 test rig.

| ID | Defect | File:line | Disposition | Commit |
|---|---|---|---|---|
| M1 | `runtime-config.ts` no parent-dir fsync after rename | `runtime-config.ts:24-49` | Linux/POSIX: post-rename `open(O_DIRECTORY).sync()`. Win32 unchanged (no equivalent) | `b31c7a1` |
| M2 | Win32 Job Object attach-after-spawn race | `lifecycle.ts:148-155` | **Documented acceptance** — race window is µs-wide; closure needs `CREATE_SUSPENDED` + spawn-path rewrite, deferred until Win32 test rig | `691daa9` (docs-only) |
| M3 | Float32Array view binding risk | `papers.ts:115-122`, `pdf.ts:210` | `toTightFloat32` helper wraps both vec0 bind sites. Bun currently honors `byteOffset`/`byteLength` so this is defense-in-depth | `e351c11` |
| M4 | Settings serialization mismatch | `raw-ddl.ts:42-47` | `embedDim` reader switched `Number(raw)` → `JSON.parse + typeof guard` to align with the canonical convention; rejects non-JSON forms like `"0x300"` | `536ab98` |
| M5 | RRF vec scan LIMIT 200 truncation bias | `papers.ts:121` | Raised to `LIMIT 1000` (covers personal-use 5k-chunk budget). KNN-per-paper subquery rewrite deferred — needs benchmark | `ed95d9c` |
| M6 | Chunker tail-chunk insufficient new content | `chunker.ts:31-39` | Drop tail when `slice.length ≤ OVERLAP_WORDS + 1`. Boundary tests pin 385-word (drop) and 386-word (keep) | `00cc76c` |
| M7 | `countBundledMigrations` swallows errors silently | `migrations.ts:79-88` | Narrowed catch to `existsSync(folder) ? scan() : 0`; let scan errors (permission, ENOTDIR) propagate. Function exported for direct testability | `1d4c294` |
| M8 | Phase-2 throw timing in `annotations.ts` | `annotations.ts` (test-only) | Added regression pinning §13 v1.1 "write-then-push": push throw leaves a re-pushable dirty row; retry with same id is idempotent | `5973060` |
| M9 | `resolveUnderRoot` doesn't wrap `realpathSync(root)` ENOENT | `primitives.ts:75-91` | Wrap root realpath in `try/catch` → `PathEscapeError`. Regression test uses real-leaf + missing-root to bypass the existing leaf-stat catch | `d101adb` |

Full-suite verification: 285 pass / 8 skip / 8 unchanged pre-existing failures (the same UI bundle + pdf.test.ts pdfViews tests that pre-date the M-batch). +11 new tests vs. H-batch baseline. Typecheck clean. The M2 race remains technically open — track Win32 test-rig work separately before claiming it closed.

---

Expand Down
Loading
Loading