project-brain 0.39.0 → 0.41.1

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 +63 -0
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -286,6 +286,8 @@ With a token configured, the hook asks Jev which installed skill best fits your
286
286
 
287
287
  **Tool suggestions.** The same request can also carry a second question about your MCP tools, and the hook then adds `Suggested tool: mcp__<server>__<tool> — <why>` (again only at 70% confidence). Claude Code defers most MCP tools, so the assistant often never reaches for the right one; the hint names it. project-brain keeps its own catalog in `~/.project-brain/`: `tool-catalog.json` for user-scope servers (`~/.claude.json` top level, `~/.claude/mcp-servers.json`) and a per-project file for local-scope servers plus the project's `.mcp.json` ones, which are used only if you approved them in Claude Code (so a freshly cloned repo can never make project-brain start its servers): each stdio server, or unauthenticated HTTP server, is started briefly and asked for `tools/list` (10s per server, four at a time; a failure or a 401 skips that server, and project-brain itself is left out). Servers that cannot be listed this way, such as claude.ai connectors, are filled in by name only from the `deferred_tools_delta` entries in your recent Claude Code transcripts (claude.ai connectors and plugin servers only). The suggest hook never builds the catalog: it only reads it, and when it is missing, older than 24 hours or its servers changed, it spawns `project-brain tool-catalog refresh` in the background (at most once every ten minutes). Run that command yourself to rebuild on demand; it prints how many tools it found, and it also embeds the tools in the background so the hook only ever reads cached vectors. Both questions share the one Jev request, so tool suggestions add no round trip, and the same disclosure applies to the shortlisted tools' names and descriptions (at most 12). Opt out with `BRAIN_TOOL_PICKER=0`, independently of `BRAIN_SKILL_PICKER`.
288
288
 
289
+ **Task-switch notice.** Once the session's context is at least 30% full (read from the latest assistant `usage` in the transcript, against the auto-compact window or 200K), the same Jev request (only when the skill or tool picker is on; with both opted out nothing is sent at all) also asks whether the prompt starts a task unrelated to the recent work. What leaves the machine for that question, only above 30%: your last four prompts (300 characters each), the last assistant text block cut to 400 characters, and the names (never the inputs or outputs) of the last few tools used. Jev answers `new_task`, `related_task` or `same_task`. A confident `new_task` (0.8 by default) shows a one-line notice (hook `systemMessage`) suggesting `/clear` and resending; a `related_task` answer of 0.6 or more suggests `/compact focus on: <the first ~60 characters of your prompt>`; a continuation at 75% or more suggests `/compact`. `/clear` is never suggested while work is in flight, meaning a background agent, shell command or workflow that has not reported back, or a tool call without its result; past 75% it becomes `/compact`, otherwise nothing. The notice appears at most once per session for each of `/clear` and `/compact`. The prompt always goes through, and under 30% nothing extra is asked or sent. Opt out with `PROJECT_BRAIN_TASK_SWITCH=0`; tune with `PROJECT_BRAIN_TASK_SWITCH_PCT`, `PROJECT_BRAIN_COMPACT_PCT`, `PROJECT_BRAIN_TASK_SWITCH_CONFIDENCE` (0.5-1, default 0.8) and `PROJECT_BRAIN_CONTEXT_WINDOW`. `scripts/calibrate-task-switch.ts` replays your own transcripts read-only against Jev (at most 30 requests) to measure the `/clear` precision and recall at 0.7, 0.8 and 0.9.
290
+
289
291
  ## Recipes — get the most out of it
290
292
 
291
293
  You talk to your **AI assistant** in natural language; it picks the right tool. These prompts steer it well:
@@ -317,6 +319,18 @@ One-time global setup. Detects your environment and registers project-brain with
317
319
  project-brain setup
318
320
  ```
319
321
 
322
+ #### Context-economy units
323
+
324
+ Every context-economy feature is its own unit in the `setup` checklist, ticked by default, and an upgrade that never saw them turns them on without a prompt. Untick one to switch it off; your choice is stored in `~/.project-brain/features.json`, which the hooks read at runtime (the existing `PROJECT_BRAIN_*=0` variables still override it).
325
+
326
+ | Unit | What it does | Leaves the machine |
327
+ |---|---|---|
328
+ | `feature:routing-skill` | model-routing table loads as the `brain-model-routing` skill; unticked, the full block goes back inline | nothing |
329
+ | `feature:task-switch` | one-line `/clear` or `/compact` notice at 30% context | your last few prompts, to api.typesafe.ai, with a TypeSafe token and a picker on |
330
+ | `feature:search-gate` | per-prompt search skips non-code prompts, caps hits, floors reranker scores | nothing extra |
331
+ | `config:mcp-prune` | disables MCP servers a project never uses | nothing |
332
+ | `config:context-slim` | moves large user sections of CLAUDE.md into skills | nothing |
333
+
320
334
  `setup` asks which parts to install — one checklist per group (Hosts, Guidance,
321
335
  Skills, Other), asked in order, so each question is about one kind of thing — and
322
336
  remembers the answer in `~/.project-brain/setup-selection.json`. Re-running it
@@ -347,6 +361,31 @@ On this repository that took a worktree's first index from 2m38s to 2.1s.
347
361
 
348
362
  It copies nothing, and indexes normally, when the main checkout has no index, when the worktree already has one, or when the two would disagree about the embedding model. Vectors from a different model are not comparable, and that is the one case sync could not correct on its own.
349
363
 
364
+ #### Memory slimming
365
+
366
+ Everything in `~/.claude/CLAUDE.md` loads on every turn of every session. `setup` already moves project-brain's own long block (the model-routing guidance) into the on-demand `brain-model-routing` skill, leaving a short pointer, and an existing install migrates the next time `setup` or `update` re-applies it. For the rest of the file, the `config:context-slim` unit (on by default) moves your own sections of 1500 tokens or more into skills each time `setup` or `update` runs, and unticking it restores them; managed blocks are never touched, so a file that is all managed blocks changes nothing. The manual command stays available:
367
+
368
+ ```bash
369
+ project-brain context slim # measure: estimated tokens per section (chars / 4)
370
+ project-brain context slim --apply user:my-notes # move your own section into a skill (backup first)
371
+ project-brain context slim --revert # restore the latest backup, remove the skills it made
372
+ ```
373
+
374
+ Sections are marked `project-brain`, `other tool` (inside another tool's `<!-- x:start -->`/`<!-- x:end -->` or `<!-- x -->`/`<!-- /x -->` markers) or `yours`. Only `yours` can be moved; content a tool regenerates (for example gentle-ai) is refused, and has to be changed through that tool's own override mechanism. Moved sections become skills named `memory-<heading>` with a description derived from the heading (`--description` overrides it). Backups live in `~/.claude/context-slim/<timestamp>/`; each `--revert` undoes the newest slim that still has a backup, and keeps the pre-revert CLAUDE.md under `~/.claude/context-slim/safety/`.
375
+
376
+ #### Unused MCP servers
377
+
378
+ Every enabled MCP server loads its tool list and instructions into every session of every project, used or not. `project-brain mcp prune` reads each project's transcripts (subagents included) and finds the servers that project has not called in 30 days:
379
+
380
+ ```bash
381
+ project-brain mcp prune # this project: what would be disabled, no changes
382
+ project-brain mcp prune --all # every project in ~/.claude.json
383
+ project-brain mcp prune --apply # add them to that project's disabledMcpServers (backup first)
384
+ project-brain mcp prune --revert # re-enable exactly what --apply disabled
385
+ ```
386
+
387
+ It is per project: usage in one project never disables a server in another, and nothing touches the user-wide list. Git worktrees of a repo pool their usage and history, so a fresh worktree inherits the repo's. A project needs 10 sessions, or 14 days of history with at least 3 sessions inside the window, and its directory must still exist; new projects are handled by a later setup or update once they have history. project-brain, servers you list in `PROJECT_BRAIN_MCP_PRUNE_KEEP` (comma separated) and servers you switched back on after we disabled them are never touched: re-enabling a pruned server through `/mcp` is respected for good, even if it goes unused afterwards. Only MCP tool calls count as usage, so a server you use through resources or prompts alone belongs on the keep list. Setup (`config:mcp-prune`, checked by default) and `update` run `--apply` for all projects; opt out with `PROJECT_BRAIN_MCP_PRUNE=0`, change the window with `PROJECT_BRAIN_MCP_PRUNE_DAYS`. `~/.claude.json` is backed up under `~/.project-brain/mcp-prune/`, written atomically, and only the disabled lists change. Changes apply from the next session.
388
+
350
389
  #### Auto-compact window
351
390
 
352
391
  Setup sets Claude Code's `autoCompactWindow` to 400K tokens (`config:auto-compact`, checked by default). Every request re-sends the whole conversation, and those cache reads count against your plan. A 1M-context model left on its default compacts near 967K, so a long session keeps re-reading a far larger context than the work needs. With the cap it compacts near 387K. 200K models aren't affected.
@@ -531,6 +570,14 @@ project-brain search "how does auth work"
531
570
  echo "how does auth work" | project-brain search --stdin
532
571
  ```
533
572
 
573
+ 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 scoring below 0.5 are dropped and at most 5 are kept; if nothing survives, nothing is printed. The plain CLI `search "<q>"` is not gated.
574
+
575
+ | Variable | Default | Effect |
576
+ |---|---|---|
577
+ | `PROJECT_BRAIN_SEARCH_MIN_SCORE` | `0.5` | Minimum reranker score (0-1) a hit needs to be injected; ignored without a reranker token, where only `PROJECT_BRAIN_SEARCH_MAX_HITS` applies |
578
+ | `PROJECT_BRAIN_SEARCH_MAX_HITS` | `5` | Maximum snippets injected |
579
+ | `PROJECT_BRAIN_SEARCH_PROMPT_FILTER` | on | Set to `0` to search every prompt, including non-code ones |
580
+
534
581
  ### Structural & lexical commands (`find`, `callers`, `callees`, `impact`, `trace`, `map`, `code`)
535
582
 
536
583
  Native CLI equivalents of the structural/lexical MCP tools — see the [Structural](#structural-ast-graph--exact-no-embeddings-needed) and [Lexical](#lexical-keyword--no-embeddings-needed) tables above for the full CLI ↔ MCP tool mapping. All read the local index directly (no Ollama probe), so they work fully offline once `project-brain sync` has run.
@@ -599,6 +646,22 @@ project-brain update
599
646
 
600
647
  Every other command already prints an `update available` notice (current → latest, with the exact command to run) once a day when a newer version is published — `update` runs that command for you instead of requiring a copy-paste.
601
648
 
649
+ #### Live updates
650
+
651
+ After installing, `update` re-applies your saved `setup` selection with the new binary — no prompts, only the units you chose (a unit you declined is never added, and one never offered is refreshed only if it is already installed). If brew or npm upgraded the binary for you, run `project-brain update --apply-only` to do just that step.
652
+
653
+ What reaches Claude Code sessions that are already open:
654
+
655
+ - **Hooks and skills** are live at once: Claude Code reloads `settings.json` and skill directories, and hooks re-run the binary on every event.
656
+ - **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.
657
+ - **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.
658
+
659
+ #### Optional: automatic MCP hot swap
660
+
661
+ 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`.
662
+
663
+ 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.
664
+
602
665
  ### `serve`
603
666
 
604
667
  Start the MCP server. Default mode uses stdio (for local AI tool connections).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-brain",
3
- "version": "0.39.0",
3
+ "version": "0.41.1",
4
4
  "type": "module",
5
5
  "description": "Local-first MCP server that gives AI tools semantic memory of your codebase.",
6
6
  "author": "jcsoftdev",
@@ -49,11 +49,11 @@
49
49
  "zod": "^4.4.3"
50
50
  },
51
51
  "optionalDependencies": {
52
- "project-brain-darwin-arm64": "0.39.0",
53
- "project-brain-linux-x64": "0.39.0",
54
- "project-brain-linux-arm64": "0.39.0",
55
- "project-brain-windows-x64": "0.39.0",
56
- "project-brain-windows-arm64": "0.39.0"
52
+ "project-brain-darwin-arm64": "0.41.1",
53
+ "project-brain-linux-x64": "0.41.1",
54
+ "project-brain-linux-arm64": "0.41.1",
55
+ "project-brain-windows-x64": "0.41.1",
56
+ "project-brain-windows-arm64": "0.41.1"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/bun": "latest",