Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
"license": "MIT",
"mcpServers": {
"scholar": {
"command": "/bin/sh",
"args": ["${CLAUDE_PLUGIN_ROOT}/bin/launch.sh"],
Comment thread
zaynram marked this conversation as resolved.
Resolved
"command": "bun",
"args": ["${CLAUDE_PLUGIN_ROOT}/bin/launch.mjs"],
"env": {
"SCHOLAR_RUNTIME_ROOT": "${HOME}/mcp-data/scholar/runtime",
"SCHOLAR_OLLAMA_URL": "http://127.0.0.1:11434",
"SCHOLAR_OLLAMA_EMBED_MODEL": "nomic-embed-text:v1.5",
"SCHOLAR_OLLAMA_CHAT_MODEL": "qwen3:8b"
Expand All @@ -29,7 +28,7 @@
"hooks": [
{
"type": "command",
"command": "sh \"${CLAUDE_PLUGIN_ROOT}/bin/ensure-bun.sh\""
"command": "bun \"${CLAUDE_PLUGIN_ROOT}/bin/launch.mjs\" --provision-only"
}
]
}
Expand Down
16 changes: 10 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Windows batch launcher must materialize with CRLF on every checkout, or
# cmd.exe mis-parses the rem block (byte-offset misalignment → '<cmd>' is not
# recognized noise on every launch). Confirmed via Cowork field test 2026-06-05.
# Scoped to *.cmd ONLY — the POSIX launchers (launch.sh, ensure-bun.sh) must
# stay LF, so do NOT add a blanket `* text=auto eol=crlf` rule here.
*.cmd text eol=crlf
# Prebuilt native extensions committed for the source-sync marketplace install
# (build/vendor/sqlite-vec/vec0.{so,dll}; .dylib reserved for a future mac drop).
# These are the repo's FIRST committed binaries and the marketplace performs a
# real `git checkout` on Windows. Git's text=auto heuristic already detects ELF/PE
# by their leading NUL bytes and skips EOL conversion (even under
# core.autocrlf=true), so this is belt-and-suspenders: mark them binary explicitly
# so no misconfigured checkout can ever CRLF-mangle the byte stream koffi loads.
*.so binary
*.dll binary
*.dylib binary
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
node_modules/
build/
# Build outputs are ignored, EXCEPT the prebuilt vec0 sqlite-vec extensions that
# the source-sync marketplace install needs at runtime (resolveVec0Path's
# <root>/build/vendor/sqlite-vec/vec0.{so,dll} rung). Git cannot re-include a file
# under an ignored parent, so the path is un-ignored level-by-level. macOS
# (.dylib) is intentionally absent — source-sync on mac boots but fails at the
# first vector op (known partial; see HUMAN.md).
build/*
!build/vendor/
build/vendor/*
!build/vendor/sqlite-vec/
build/vendor/sqlite-vec/*
!build/vendor/sqlite-vec/vec0.so
!build/vendor/sqlite-vec/vec0.dll
dist/
out/
runtime/
Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This file orients future Claude Code instances working in this repository. It ca
- `.claude/context/plans.xml` — the spec-pipeline plan registry (one plan-group, seven children, all closed).
- `.claude/context/chores.xml` — the spec-pipeline chore registry (all closed; one governance-tooling item dropped — see `HUMAN.md`).
- `src/` — the implemented server, tool modules, db layer, ingest adapters, pdf lifecycle, Ollama client, and React UI sources.
- `bin/` + `dist/` — the slim-plugin launcher/provisioner scripts (`launch.{sh,cmd}`, `ensure-bun.{sh,ps1}`, `scholar.nu`) and the built `server.js` + `pdf-server/` bundles.
- `bin/` + `dist/` — the slim-plugin launcher/provisioner scripts (`launch.mjs`, `ensure-bun.{sh,ps1}`, `scholar.nu`) and the built `server.js` + `pdf-server/` bundles.
- `docs/audits/` — the production-readiness roadmap (S/H/M batches) and the `2026-06-02-maintenance-readiness.md` assessment.

The remaining gates before reliable day-to-day use are **operational**, not code: the Ollama models must be installed and a live end-to-end workflow must be exercised. Both are tracked in `HUMAN.md` (repo root) and `docs/runbooks/e2e-smoke-test.md`.
Expand All @@ -30,7 +30,7 @@ Chores are cross-cutting work that doesn't belong to any single §6 cycle (licen
> `docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md`. The bullets below
> reflect the post-pivot model.

- **scholar MCP server** — Bun + `bun:sqlite` + `drizzle-orm/bun-sqlite` + `sqlite-vec`, shipped as a `bun build --target=bun` bundle (`dist/server.js`, ~2.5 MB, **not** `--compile`). The `bun` runtime is **provisioned** into `${CLAUDE_PLUGIN_DATA}` by `bin/ensure-bun` at first launch (pinned to `scholar.bundledBunVersion` for the vec0 ABI), not shipped. A shell launcher (`bin/launch.{sh,cmd}`, manifest command `/bin/sh` | `cmd.exe`) provisions-then-runs the server (M2 — SessionStart does not block MCP spawn). Exposes corpus, ingestion, annotation, digest, prompts, search, and UI-resource tools. Spawns the pdf MCP as a child.
- **scholar MCP server** — Bun + `bun:sqlite` + `drizzle-orm/bun-sqlite` + `sqlite-vec`, shipped as a `bun build --target=bun` bundle (`dist/server.js`, ~2.5 MB, **not** `--compile`). The `bun` runtime is **provisioned** into `${CLAUDE_PLUGIN_DATA}` by `bin/ensure-bun` at first launch (pinned to `scholar.bundledBunVersion` for the vec0 ABI), not shipped. A cross-OS launcher (`bin/launch.mjs`, manifest command `bun`) provisions-then-runs the server (M2 — SessionStart does not block MCP spawn). Exposes corpus, ingestion, annotation, digest, prompts, search, and UI-resource tools. Spawns the pdf MCP as a child.
- **pdf MCP** — `@modelcontextprotocol/server-pdf@1.7.2`. The vendored `src/vendor/pdf-server/` tree stays in-repo **unmodified** as the §16 `.d.ts` truth source and dev fallback. For packaging it is mechanically **rebundled standalone** (`bun build --target=bun` inlines pdfjs-dist) to `dist/pdf-server/index.js` + `mcp-app.html` — no source patch. `resolveChildEntrypoint` (`src/server/pdf/lifecycle.ts`) prefers `SCHOLAR_PDF_ENTRYPOINT` → shipped `dist/pdf-server/` → vendored dev fallback. Root injection rides the standard MCP `roots/list` + `notifications/roots/list_changed` protocol; scholar implements the client-side responder in `lifecycle.ts`.
- **single-file UI bundle** — React, built by Bun's HTML bundler (`bun build src/ui/index.html --target=browser`, no vite). Five views: corpus dashboard, paper detail, digest panel, reading prompts, reader progress.
- **nu CLI module** — `bin/scholar.nu`, user-facing wrapper that calls scholar MCP tools and shapes responses into nu tables.
Expand Down
68 changes: 51 additions & 17 deletions HUMAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ root). So the provisioning + spawn + migrate + activate spine is no longer an
assumption — the **only** unproven leg is the PDF *viewer* (`displayPdf`/`getText`,
step 7), which can only be exercised by a human at the desktop.

> **Superseded 2026-06-06 — bun-launcher unification.** The 2026-06-03 proof above
> was of the now-retired `/bin/sh launch.sh` path (`exec`-replace into bun). Both
> targets now launch via `bun ${CLAUDE_PLUGIN_ROOT}/bin/launch.mjs`; `launch.sh` and
> `launch.cmd` are deleted. The new Linux entry paths are **not** an assumption —
> **both** were re-driven **end-to-end headless (2026-06-06)** under a *non-pinned*
> on-PATH bun (1.3.14), each cold-provisioning the pinned **1.3.11** into a fresh
> `CLAUDE_PLUGIN_DATA` and returning a clean single-line MCP `initialize` (pdf child
> `Ready`, graceful exit on stdin-EOF): (a) the **built-bundle** path (`dist/server.js`
> present), and (b) the **source-sync from-src** path — `CLAUDE_PLUGIN_ROOT` set to the
> git-tracked ship set (no `dist/`, no `node_modules`), where `launch.mjs` falls through
> to `src/server/index.ts` and the pinned bun **cold-auto-installs the whole import
> graph** into the `BUN_INSTALL` cache under `CLAUDE_PLUGIN_DATA` (~67 MB) **without
> writing a local `node_modules`** into the shipped tree. That second path is exactly
> what the Cowork Linux sandbox runs, so the launcher's auto-install assumption is now
> validated empirically, not on faith. `ensure-bun.sh` and the server spine are
> unchanged. The **only** leg this does NOT cover is Windows — a bare `bun` resolving on
> PATH at the Claude Desktop spawn (CreateProcess PATH semantics differ from POSIX
> `execvp`); that is now the dominant residual risk, tracked in **§5 leg 2**.

> **Note (2026-06-04, updated):** the PDF viewer is an **MCP App** the Claude Code
> terminal can't render — the actual home for that leg is **Claude Desktop** via the
> `.mcpb` extension. See **§5** for the build + install + the Windows verification
Expand Down Expand Up @@ -121,9 +140,9 @@ can't be simulated from Linux. See leg 6.
bun run build:mcpb # -> out/scholar.mcpb (win32, ~2.9 MB, 20 files)
```
The build runs `mcpb validate` then `mcpb pack`. The manifest is `manifest.json`
at the bundle root (mcpb schema **0.2**), `server.type:"binary"`, command
`cmd.exe /c ${__dirname}\bin\launch.cmd`. It does **not** modify the launcher: the
manifest `env` aliases the two vars `launch.cmd`/`ensure-bun.ps1` already read —
at the bundle root (mcpb schema **0.2**), `server.type:"binary"` (`bun` is a binary
on PATH), command `bun` with args `[${__dirname}\bin\launch.mjs]`. It does **not**
modify the launcher: the manifest `env` aliases the two vars `launch.mjs`/`ensure-bun.ps1` already read —
`CLAUDE_PLUGIN_ROOT := ${__dirname}` and `CLAUDE_PLUGIN_DATA := ${user_config.data_dir}`
— so the win32 launch chain runs byte-identical to the Claude Code plugin.

Expand All @@ -141,30 +160,42 @@ different host, set the Ollama URL field at install.

Proven from Linux: the manifest validates against the real `mcpb` schema (0.1–0.4
all pass — no version-specific field), packs + unpacks to the correct structure
(manifest at root; `bin/launch.cmd`, `dist/server.js`, `dist/pdf-server/{index.js,
mcp-app.html}`, `build/vendor/sqlite-vec/vec0.dll`, `ui/`, `nu/`, migrations all
present; no `.claude-plugin/` cruft), and the source path-resolution chain reads
(manifest at root; `bin/launch.mjs`, `bin/ensure-bun.ps1`, `dist/server.js`,
`dist/pdf-server/{index.js, mcp-app.html}`, `build/vendor/sqlite-vec/vec0.dll`,
`ui/`, `nu/`, migrations all present; no `.claude-plugin/` cruft), and the source
path-resolution chain reads
the two aliased vars (vec0 + pdf entry off `CLAUDE_PLUGIN_ROOT`, bun off
`process.execPath`). **None of that proves Desktop runs it.** These legs can only
be checked on Windows — each with the symptom to watch for:

1. **Desktop accepts manifest_version 0.2** — *symptom:* the Install dialog rejects
the extension up front. *Fix:* bump `MCPB_MANIFEST_VERSION` in
`scripts/build-plugin.ts` (0.2 → 0.3 → 0.4), `bun run build:mcpb`, reinstall.
2. **Desktop spawns `cmd.exe`/`type:"binary"`** — *symptom:* extension installs but
the MCP never connects ("server failed to start"). Means Desktop won't launch an
arbitrary command for this extension type.
2. **Desktop spawns `bun`/`type:"binary"` AND a bare `bun` resolves on PATH** — the
**dominant residual risk** of the bun-launcher unification. On POSIX the host's
`execvp` searches PATH; Windows `CreateProcess` does not search PATH the same way,
so a bare `bun` resolves only if Desktop passes a PATH-aware spawn env. *symptom:*
extension installs but the MCP never connects ("server failed to start") — either
Desktop won't launch this command for `type:"binary"`, or `bun` was not found on
PATH. *First check:* `bun --version` in a fresh Windows shell (bun must be
installed system-wide — it is a dependency of these servers). *Fallback if PATH is
the problem:* edit the manifest `command` to an absolute `bun.exe` path (e.g.
`%USERPROFILE%\.bun\bin\bun.exe`) and reinstall.
3. **Variable substitution** (`${__dirname}`, `${user_config.data_dir}`, `${HOME}`)
— *symptom:* `ensure-bun: CLAUDE_PLUGIN_DATA unset` on stderr, or launch.cmd
can't find `dist\server.js`. Means a `${…}` token wasn't expanded. (`${HOME}`
— *symptom:* `ensure-bun: CLAUDE_PLUGIN_DATA unset` on stderr, or `launch.mjs`
dies with `CLAUDE_PLUGIN_ROOT is unset` / can't find `dist\server.js`. Means a
`${…}` token wasn't expanded. (`${HOME}`
is confirmed a documented mcpb substitution var, usable in `user_config`
defaults — mcpb `MANIFEST.md` — and Desktop maps it to the Windows user
profile, so the `data_dir` default `${HOME}\scholar` is portable, not a bug.)
4. **bun provisioning** (ensure-bun.ps1 downloads bun-windows-x64 **1.3.11** into
`%CLAUDE_PLUGIN_DATA%\bun`) — *symptom:* long first-launch then `bun.exe` not
found; or PowerShell blocked by ExecutionPolicy (the hook passes
`-ExecutionPolicy Bypass`, but Desktop spawns via cmd.exe, not the hook). Check
`%data_dir%\bun\bun.exe --version` prints `1.3.11`.
found; or PowerShell blocked by ExecutionPolicy. (Improved by the bun
unification: `launch.mjs` now invokes the provisioner as `powershell -NoProfile
-ExecutionPolicy Bypass -File ensure-bun.ps1` on **both** the server-spawn path
*and* the `--provision-only` SessionStart pre-warm — the old cmd.exe launcher
only bypassed on the hook — so a machine ExecutionPolicy should not block it.)
Check `%data_dir%\bun\bun.exe --version` prints `1.3.11`.
**Field-confirmed 2026-06-05 (Cowork):** on a *brand-new* data dir the first
connect can time out *during* this download — the ~110 MB fetch overran the
host's 30 s MCP connect budget (`Connection timeout triggered after 30027ms`),
Expand Down Expand Up @@ -257,9 +288,12 @@ be checked on Windows — each with the symptom to watch for:
*Caveat (salient uncertainty):* the conformance reading is grounded in SEP-1865 +
the version-matched pdf-server reference + the ext-apps `.d.ts`, but the live
render path has not been exercised on a real Claude Desktop from this environment.
7. **Clean shutdown / no orphaned lock** — `launch.cmd` runs `bun.exe` as a *child*
of cmd.exe (no exec-replace on Windows). *symptom:* after quitting/restarting
Desktop, the next launch refuses with `SCHOLAR_LOCKED`. The pid-liveness reclaim
7. **Clean shutdown / no orphaned lock** — `bun launch.mjs` spawns `bun.exe` as a
*child* (the same parent+child shape on both OSes now — the prior Linux
`exec`-replace is gone; launch.mjs forwards SIGINT/SIGTERM/SIGHUP and exits when
the child does; see slim-plugin-pivot.md "Launch orphan"). *symptom:* after
quitting/restarting Desktop, the next launch refuses with `SCHOLAR_LOCKED`. The
pid-liveness reclaim
in `session-lock.ts` should clear a stale `runtime\scholar.lock` on the next
start (unless the OS reused the pid) — confirm a restart recovers cleanly.

Expand Down
2 changes: 1 addition & 1 deletion bin/ensure-bun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Mirror of ensure-bun.sh. Idempotently provisions the PINNED bun.exe into
# ${CLAUDE_PLUGIN_DATA}\bun (persists across plugin updates). Called
# synchronously by launch.cmd before it launches the server.
# synchronously by launch.mjs before it launches the server.
#
# ALL diagnostic output goes to stderr (Write-Error / $host.UI write to stderr;
# we use [Console]::Error) — stdout must stay clean for the MCP JSON-RPC stream.
Expand Down
8 changes: 4 additions & 4 deletions bin/ensure-bun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# ${CLAUDE_PLUGIN_DATA} persists across plugin updates (unlike CLAUDE_PLUGIN_ROOT,
# which is replaced each version), so bun is downloaded at most once per machine.
#
# Called synchronously by launch.sh BEFORE it execs the server — this is the
# Called synchronously by launch.mjs BEFORE it spawns the server — this is the
# correctness guarantee that bun exists before the MCP server needs it (Claude
# Code's SessionStart hooks do NOT block MCP spawn, so provisioning cannot live
# there alone). May also be pre-warmed by a SessionStart hook; the flock below
# serializes concurrent invocations.
# there alone). May also be pre-warmed by a SessionStart hook (launch.mjs
# --provision-only); the flock below serializes concurrent invocations.
#
# ALL diagnostic output goes to stderr — stdout is reserved for the MCP server's
# JSON-RPC stream once launch.sh execs into it.
# JSON-RPC stream once launch.mjs spawns it.
set -eu

PIN="1.3.11" # keep in sync with package.json scholar.bundledBunVersion (vec0 ABI)
Expand Down
20 changes: 0 additions & 20 deletions bin/launch.cmd

This file was deleted.

Loading
Loading