project-brain 0.45.1 → 0.46.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 (2) hide show
  1. package/README.md +22 -6
  2. package/package.json +7 -7
package/README.md CHANGED
@@ -361,6 +361,8 @@ project-brain setup --none
361
361
 
362
362
  Run `project-brain setup --with=nope` to print the list of valid ids.
363
363
 
364
+ After an upgrade, a prompt in a Claude Code session lists the units that shipped since you last chose (in neither list of `setup-selection.json`) and are not on disk: up to five by name, then a count. The list is computed between sessions, by `update` and by the SessionEnd maintenance job, so a prompt never waits on it; it is shown by one session only, each unit is named at most once per machine, a unit you declined is never named, and `PROJECT_BRAIN_WHATS_NEW=0` turns it off. `project-brain setup --new` opens the checklist with only those units and leaves every other answer as it is. Without a prompt, `--new --with=<ids>` enables what it names and `--new --without=<ids>` declines what it names, leaving the rest undecided; `--new --yes` enables only the units that are on by default unconditionally, so neither an opt-in unit nor one that turns on when a TypeSafe token exists is enabled that way. `--all`, `--none` and the `--no-*` flags are refused with `--new`. `project-brain status` keeps listing every unit that is available but not enabled.
365
+
364
366
  #### Claude TUI
365
367
 
366
368
  The "Claude TUI" checklist sets up Claude Code's terminal. Every unit changes files under `~/.claude`, so an upgrade never installs them on its own: they show up marked `NEW` and unchecked. Untick a unit to undo exactly what it wrote.
@@ -668,7 +670,19 @@ Everything left pending across every registered project, in one read-only report
668
670
  project-brain status [--json] [--project <id>]
669
671
  ```
670
672
 
671
- For each project it lists commits not yet pushed (a branch ahead of its upstream, or a local branch with no upstream that has commits not on the default branch), uncommitted changes in the main checkout, and linked worktrees that `worktree finish` would accept (merged, clean, idle). Globally it lists setup units that are available but not enabled (ones you declined are left out), and compares the installed version with npm's `latest` and `next` dist-tags, flagging when `latest` lags `next`. Each pending item comes with the command that resolves it. A clean project prints nothing; when nothing at all is pending it prints one `All clear` line. Repositories with no remote are not checked for unpushed commits, and the npm lookup gives up after 3 s.
673
+ For each project it lists commits not yet pushed (a branch ahead of its upstream, or a local branch with no upstream that has commits not on the default branch), uncommitted changes in the main checkout, and linked worktrees that `worktree finish` would accept (merged, clean, idle). Globally it lists setup units that are available but not enabled (ones you declined are left out), and compares the installed version with npm's `latest` and `next` dist-tags, flagging when `latest` lags `next`, and lists your live MCP servers that run an older version than the installed one. Each pending item comes with the command that resolves it. A clean project prints nothing; when nothing at all is pending it prints one `All clear` line. Repositories with no remote are not checked for unpushed commits, and the npm lookup gives up after 3 s.
674
+
675
+ ### `stats`
676
+
677
+ What project-brain put into your Claude Code sessions, per session and per project, read only from local files: nothing is sent anywhere and nothing is written.
678
+
679
+ ```bash
680
+ project-brain stats [--days N] [--all] [--json]
681
+ ```
682
+
683
+ For each session in the window (default the last 7 days, `--days N` or `--days=N`; only injections and gate drops stamped inside it count) it reports the prompt-context hook's injected blocks (prompts, hits, tokens), the context the Jev context gate dropped (`~/.project-brain/context-gate-log.json`), the tool names and server instructions the session's MCP set holds in context at its largest between compactions (subagents counted apart), and the MCP servers `mcp prune` had disabled for that directory before the session began. The scope is the current project: the initialized project root, else the git repository root, else exactly the current directory, and the header says which; `--all` covers every project. Unknown flags exit with status 2. Every token figure is an estimate, characters divided by 4. `--json` carries counts, sources and scores only, never prompt text.
684
+
685
+ Per project it also prints a usage signal: of the distinct hits injected, how many the model later read, edited, named in a shell command, or got back from a project-brain tool in the same transcript, and that share at each floor. It is a report, not a calibration. Measured on real transcripts (5,345 injected hits), only 2% were later read, edited or returned by a project-brain tool; counting shell commands, the signal agreed with hand labels only moderately (17 of 36 relevant hits used, 8 of 127 irrelevant). And since only hits above the floor in force are ever injected, it cannot show what a lower floor would add.
672
686
 
673
687
  ### `bench` — measure retrieval quality
674
688
 
@@ -692,7 +706,7 @@ project-brain search "how does auth work"
692
706
  echo "how does auth work" | project-brain search --stdin
693
707
  ```
694
708
 
695
- The hook only injects when it is likely to help. Before any embedding work it skips prompts that carry no code question: very short prompts (under 3 words or 15 characters, unless they name a code identifier), acknowledgements and continuations in English and Spanish ("ok", "sí", "continúa", "commit y push"), slash-command echoes, and pasted harness or agent reports. Hits Jev scores below 0.65 are dropped and at most 5 are kept; if nothing survives, nothing is printed. The floor comes from `scripts/calibrate-hook-floor.ts`, which replays your own prompts read-only through the hook's retrieval and Jev (at most 30 requests), writes every hit to a file outside the repository for labelling, and prints precision and recall per floor. The plain CLI `search "<q>"` is not gated.
709
+ The hook only injects when it is likely to help. Before any embedding work it skips prompts that carry no code question: very short prompts (under 3 words or 15 characters, unless they name a code identifier), acknowledgements and continuations in English and Spanish ("ok", "sí", "continúa", "commit y push"), slash-command echoes, and pasted harness or agent reports. Hits Jev scores below 0.65 are dropped and at most 5 are kept; if nothing survives, nothing is printed. The floor comes from `scripts/calibrate-hook-floor.ts`, which replays your own prompts read-only through the hook's retrieval and Jev (at most 30 requests), writes every hit to a file outside the repository for labelling, and prints precision and recall per floor. The floor is one value for every project and is not adjusted automatically; `project-brain stats` shows it next to how often injected hits were used. The plain CLI `search "<q>"` is not gated.
696
710
 
697
711
  Hook output stays in the conversation, so a snippet is injected only while it is not already there: the hook reads the newest 8 MB of the session transcript (`transcript_path`), follows the live message chain back from the newest entry, and skips any snippet whose printed text, score aside, an earlier UserPromptSubmit hook output on that chain already holds. When every relevant hit is already there, nothing is printed. The skill/tool suggestion hook does the same per suggested name. Because it reads the live chain, a compaction, `/clear`, `/rewind` or an edited earlier message brings the dropped snippets back on the next prompt, and an unreadable transcript dedups nothing. No state is stored.
698
712
 
@@ -779,13 +793,15 @@ What reaches Claude Code sessions that are already open:
779
793
 
780
794
  - **Hooks and skills** are live at once: Claude Code reloads `settings.json` and skill directories, and hooks re-run the binary on every event.
781
795
  - **CLAUDE.md** is only read at launch, so the first prompt after an update shows a one-time notice (`project-brain updated X → Y`) with the current model-routing guidance.
782
- - **The MCP server** is not reloaded by Claude Code. By default the same notice tells you to run `/mcp reconnect all` (or `/mcp`) to load the new tools.
796
+ - **The MCP server** is not reloaded by Claude Code, so stdio `serve` moves itself to the new binary (the hot swap below). With the hot swap turned off, the same notice tells you to run `/mcp reconnect all` (or `/mcp`) to load the new tools.
797
+
798
+ Whenever a server is still on old code, the `check_health` tool says so in its `versionDrift` field (`MCP server runs 0.42.0, installed 0.45.1: run /mcp reconnect ...`, or, when a hot swap to that version failed, the reason it failed), and `project-brain status` lists every live MCP server of yours that runs an older version than the installed one, by pid, with the same fix. Each server records its version under `~/.project-brain/servers/` while it runs, and a record counts only while its pid is still that server; a server too old to have recorded itself is found in the process table and reported when it started before the installed binary was put in place. Without `ps` (Windows) status leaves servers out.
783
799
 
784
- #### Optional: automatic MCP hot swap
800
+ #### Automatic MCP hot swap
785
801
 
786
- Set `BRAIN_MCP_HOT_SWAP=1` in the MCP server's environment and stdio `serve` runs a small supervisor that relays to a worker process. When the binary on disk is newer, it starts a new worker, waits until no request is in flight, switches over, sends `tools/list_changed`, then lets the old worker drain and exit. A failure at any point leaves the old worker serving, and the notice then says to run `/mcp reconnect all`; after two failed attempts at a version the supervisor stops trying for that session. It is off by default because the supervisor is a second process per session, about 76 MB of memory each. Servers started before the first release with this feature have no supervisor, so that first update still needs one `/mcp reconnect all`.
802
+ Stdio `serve` runs a small supervisor that relays to a worker process. When the binary on disk is newer, it starts a new worker, waits until no request is in flight, switches over, sends `tools/list_changed`, then lets the old worker drain and exit. A failure at any point leaves the old worker serving and is reported by `check_health`: when the new binary does not start, it says so and tells you to reinstall or upgrade again rather than reconnect, since a reconnect would start the same binary. After two failed attempts at a version the supervisor stops trying for that session. A new worker that speaks another MCP protocol version than the session negotiated is refused. If the old worker dies while the new one is ready, the new one takes over instead of the session ending. A retiring worker that is finishing a sync is never killed for it: it marks itself as draining and gets up to 10 minutes; the new worker cannot start indexing meanwhile, because the old one holds the project's `watch.lock` until its sync has finished. Only `serve` gets a supervisor: never `serve --http`, one-shot commands or hooks. The supervisor costs about 16 MB of physical memory per session (measured on macOS, against about 50 MB for the worker), because the release binary is compiled with `--splitting` and the supervisor loads only its own code. Set `BRAIN_MCP_HOT_SWAP=0` in the MCP server's environment to run the server in-process instead; `BRAIN_MCP_HOT_SWAP=1` from before this was the default keeps working. Servers started before the release that made this the default have no supervisor, so that first update still needs one `/mcp reconnect all`.
787
803
 
788
- Limits to know about: a new worker is launched through the same command your tool used (for a brew or npm link, the link, so a retargeted link is picked up), never through the old versioned directory; and when running from source with `bun run`, only the entry script is watched, so a change that touches `package.json` alone is not noticed.
804
+ Limits to know about: a new worker is launched through the same command your tool used (for a brew or npm link, the link, so a retargeted link is picked up), never through the old versioned directory; when running from source with `bun run`, only the entry script is watched, so a change that touches `package.json` alone is not noticed; and a pnpm global install runs project-brain from a versioned `.pnpm/project-brain@<version>` directory that an upgrade leaves in place, so pnpm users still need one `/mcp reconnect` per upgrade.
789
805
 
790
806
  ### `serve`
791
807
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-brain",
3
- "version": "0.45.1",
3
+ "version": "0.46.0",
4
4
  "type": "module",
5
5
  "description": "Local-first MCP server that gives AI tools semantic memory of your codebase.",
6
6
  "author": "jcsoftdev",
@@ -33,7 +33,7 @@
33
33
  "typecheck": "tsc --noEmit",
34
34
  "setup": "bun run src/cli.ts setup",
35
35
  "init": "bun run src/cli.ts init",
36
- "build": "bun build ./src/cli.ts ./src/parser/worker.ts --compile --outfile dist/project-brain"
36
+ "build": "bun build ./src/cli.ts ./src/parser/worker.ts --compile --splitting --outfile dist/project-brain"
37
37
  },
38
38
  "dependencies": {
39
39
  "@anthropic-ai/sdk": "^0.111.0",
@@ -49,11 +49,11 @@
49
49
  "zod": "^4.4.3"
50
50
  },
51
51
  "optionalDependencies": {
52
- "project-brain-darwin-arm64": "0.45.1",
53
- "project-brain-linux-x64": "0.45.1",
54
- "project-brain-linux-arm64": "0.45.1",
55
- "project-brain-windows-x64": "0.45.1",
56
- "project-brain-windows-arm64": "0.45.1"
52
+ "project-brain-darwin-arm64": "0.46.0",
53
+ "project-brain-linux-x64": "0.46.0",
54
+ "project-brain-linux-arm64": "0.46.0",
55
+ "project-brain-windows-x64": "0.46.0",
56
+ "project-brain-windows-arm64": "0.46.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/bun": "latest",