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
1 change: 1 addition & 0 deletions .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"hooks": {
"SessionStart": [
{
"matcher": "startup",
"hooks": [
{
"type": "command",
Expand Down
2 changes: 1 addition & 1 deletion docs/audits/2026-06-02-maintenance-readiness.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ been run** against a live server. Everything else is tidiness.
| Test suite (`bun test src tests`) | **324 pass / 4 skip / 1 todo / 0 fail** (329 across 43 files, ~13s) |
| Build artifacts | `dist/server.js` 2.45 MB · `dist/pdf-server/{index.js 3.98 MB, mcp-app.html 4.42 MB}` present |
| UI bundle (`measure-bundle`) | 1014 KB single-file, within budget |
| Launch chain | `plugin.json` → `/bin/sh bin/launch.sh` → `ensure-bun.sh` (pins bun 1.3.11) → `exec bun dist/server.js` — statically sound, vec0-ABI pin intact |
| Launch chain | `plugin.json` → `/bin/sh bin/launch.sh` → `ensure-bun.sh` (pins bun 1.3.11) → `exec bun dist/server.js` — statically sound, vec0-ABI pin intact. **(2026-06-02 snapshot — retired; see supersede note directly below.)** |

> **Superseded 2026-06-06 (bun-launcher unification, PR #4).** The launch chain is
> now `plugin.json` → `bun ${CLAUDE_PLUGIN_ROOT}/bin/launch.mjs` →
Expand Down
23 changes: 19 additions & 4 deletions docs/superpowers/specs/2026-06-01-slim-plugin-pivot.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ not the 6.7 MB vendored pdf — were the bloat.
> history.

`scripts/build-plugin.ts` rewritten to the slim model; `SCHOLAR_BUILD_WIN`
selects target. Both packages build on the Linux host:
selects target. Both packages build on the Linux host (the 2026-06-01 sizes and
`launch.{sh,cmd}` launchers named in the two bullets below are the **retired**
shell-pair record, kept per the supersede banner above; the launcher is now the
cross-OS `bun ${ROOT}/bin/launch.mjs`):

- **linux** `scholar.plugin` 2.8 MB / 14 files — unzipped and launched via the
generated manifest (`/bin/sh ${ROOT}/bin/launch.sh`) with a fresh
Expand All @@ -127,9 +130,21 @@ selects target. Both packages build on the Linux host:

Launch is **M2** (see `bin/`): on both OSes `bun` runs `bin/launch.mjs`, which
calls the idempotent `ensure-bun` provisioner then spawns the pinned bun on the
server entry. A `SessionStart` hook pre-warms `ensure-bun` via `bun launch.mjs
--provision-only` (latency only — the launcher is the correctness gate, because
SessionStart does not block MCP spawn). **Shape change (2026-06-05):** the old
server entry. A `SessionStart` hook (scoped to the `startup` matcher) pre-warms
`ensure-bun` via `bun launch.mjs --provision-only` (latency only — the launcher is
the correctness gate, because SessionStart does not block MCP spawn). **Hook scope
(2026-06-06):** the pre-warm is `startup`-only — provisioning the pinned bun into
`CLAUDE_PLUGIN_DATA` is a first-session concern, so it need not re-fire on
resume/clear/compact. The plugins reference prescribes the *mechanism* — a
SessionStart hook that installs a dependency into `CLAUDE_PLUGIN_DATA` once and
reuses it across sessions and updates — but its example is *unscoped*, leaning on an
in-hook `diff` guard for idempotency. The `startup` narrowing is scholar's own
decision, not a doc prescription: scholar's guard-equivalent already exists
(`ensure-bun` is idempotent + flock-guarded) and `launch.mjs` (no flag) is the real
correctness gate, so re-firing on resume/clear/compact buys nothing. `Setup` is
deliberately *not* used: it fires only on explicit `claude --init-only` /
`-p --init|--maintenance` ("one-time preparation in CI or scripts"), never on
install or normal startup, so it would skip the pre-warm for ordinary users. **Shape change (2026-06-05):** the old
Linux launcher `exec`ed into bun, so the PID Claude Code spawned *became* the
server (no wrapper); `bun launch.mjs` instead spawns the pinned bun as a **child**
on both OSes — always a parent+child pair cross-OS. Mitigated, not a regression:
Expand Down
13 changes: 13 additions & 0 deletions scripts/build-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,22 @@ export function buildManifest(
// spawn, so this is a latency optimization only — `bun launch.mjs` (no
// flag) is the correctness gate. --provision-only runs the same shim,
// which dispatches to the per-OS ensure-bun (idempotent + lock-guarded).
//
// Scoped to the `startup` matcher: provisioning the pinned bun into
// CLAUDE_PLUGIN_DATA is a first-session concern, so there's no point
// re-firing it on resume/clear/compact (the bun already exists by then).
// The `Setup` event is deliberately NOT used — it fires only on explicit
// `claude --init-only` / `-p --init|--maintenance` ("one-time preparation
// in CI or scripts"), never on install or normal startup, so it would skip
// the pre-warm for ordinary users. The plugins reference prescribes the
// SessionStart-into-CLAUDE_PLUGIN_DATA *mechanism* (install a dependency once,
// reuse across sessions and updates) but its example is UNSCOPED, guarding
// idempotency with an in-hook `diff`; the `startup` narrowing is scholar's own
// call, justified by ensure-bun's guard + launch.mjs being the correctness gate.
hooks: {
SessionStart: [
{
matcher: 'startup',
hooks: [
{
type: 'command',
Expand Down
4 changes: 4 additions & 0 deletions tests/build-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ test('buildManifest(linux): bun launch.mjs + HOME runtime root + bun pre-warm',
expect(s.env.SCHOLAR_RUNTIME_ROOT).toBe('${HOME}/mcp-data/scholar/runtime')
expect(s.env.SCHOLAR_OLLAMA_EMBED_MODEL).toBe('nomic-embed-text:v1.5')
expect(s.env.SCHOLAR_OLLAMA_CHAT_MODEL).toBe('qwen3:8b')
// Pre-warm scoped to `startup` — not Setup, not every SessionStart trigger.
expect(m.hooks.SessionStart[0].matcher).toBe('startup')
const hook = m.hooks.SessionStart[0].hooks[0].command
expect(hook).toContain('launch.mjs')
expect(hook).toContain('--provision-only')
Expand All @@ -47,6 +49,8 @@ test('buildManifest(win32): bun launch.mjs + USERPROFILE root + bun pre-warm', (
)
// Ollama defaults are platform-independent.
expect(s.env.SCHOLAR_OLLAMA_EMBED_MODEL).toBe('nomic-embed-text:v1.5')
// Pre-warm scoped to `startup` — not Setup, not every SessionStart trigger.
expect(m.hooks.SessionStart[0].matcher).toBe('startup')
const hook = m.hooks.SessionStart[0].hooks[0].command
expect(hook).toContain('launch.mjs')
expect(hook).toContain('--provision-only')
Expand Down
19 changes: 17 additions & 2 deletions tests/manifests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,26 @@ test('mcpServers.scholar uses the cross-OS bun launcher (source-sync supersedes
expect(scholar.env.SCHOLAR_OLLAMA_CHAT_MODEL).toBe('qwen3:8b')
})

test('SessionStart hook pre-warms the bun provisioner via the cross-OS shim', () => {
test('SessionStart pre-warm is scoped to the startup matcher (not Setup, not every trigger)', () => {
// The hook is a pre-warm only — launch.mjs (no flag) is the correctness gate,
// because SessionStart does not block MCP spawn. Here it runs --provision-only
// so the same shim resolves the sh-vs-powershell provisioner per-OS.
const cmd = pluginManifest.hooks?.SessionStart?.[0]?.hooks?.[0]?.command
//
// Scoped to `startup`: provisioning the pinned bun into CLAUDE_PLUGIN_DATA is a
// first-session concern, so it must NOT re-fire on resume/clear/compact (the
// bun already exists by then). The docs prescribe the SessionStart-into-
// CLAUDE_PLUGIN_DATA *mechanism* ("install a dependency once, reuse across
// sessions and updates") but their example is UNSCOPED, guarding idempotency
// with an in-hook `diff`. The `startup` narrowing is scholar's OWN call, not a
// doc prescription: ensure-bun is already idempotent + flock-guarded and
// launch.mjs (no flag) is the real correctness gate, so re-firing on
// resume/clear/compact buys nothing. The `Setup` event is deliberately NOT
// used: it fires only on explicit `claude --init-only` / `-p --init|--maintenance`
// ("for one-time preparation in CI or scripts"), never on install or normal
// startup — so it would skip the pre-warm for normal users entirely.
const group = pluginManifest.hooks?.SessionStart?.[0]
expect(group?.matcher).toBe('startup')
const cmd = group?.hooks?.[0]?.command
expect(cmd).toContain('launch.mjs')
expect(cmd).toContain('--provision-only')
})
Loading