project-brain 0.32.1 → 0.34.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.
package/README.md CHANGED
@@ -256,7 +256,21 @@ The CLI commands exit 0 for any executed query — including legitimate empty re
256
256
 
257
257
  Curated knowledge (the *why* behind the code) lives in an OKF bundle rather than in these tools — see [`okf`](#okf--knowledge-bundles-the-why-not-the-what).
258
258
 
259
- Routing: exact symbol → `find_symbol`; who-calls → `find_callers`; what-it-calls → `find_callees`; "what breaks if I change X" → `impact`; "how does A end up calling B" → `trace_path`; fuzzy/conceptual → `search_context` then `expand_context`; exact string/identifier you can type verbatim → `search_code`. The canonical tool list lives in `src/constants.ts` (`TOOL_CATALOG`) and is rendered into both the MCP server instructions and the per-project `CLAUDE.md`.
259
+ Routing: exact symbol → `find_symbol`; who-calls → `find_callers`; what-it-calls → `find_callees`; "what breaks if I change X" → `impact`; "how does A end up calling B" → `trace_path`; fuzzy/conceptual → `search_context` then `expand_context`; exact string/identifier you can type verbatim → `search_code`. The canonical tool list lives in `src/constants.ts` (`TOOL_CATALOG`) and is rendered into the MCP server instructions plus the global rules files for hosts not proven to surface those instructions to the model. Claude Code IS proven to surface them (they land in context on every MCP connection), so its global and per-project `CLAUDE.md` point at that live copy instead of re-embedding the catalog.
260
+
261
+ ## Reranking (optional)
262
+
263
+ `search_context` can rerank its retrieved pool with [TypeSafe](https://typesafe.ai)'s Jev model before the usual threshold/MMR/budget steps run, scoring every candidate's relevance to the query with a single call. Measured on a bench of 332 mined queries (30 candidates each): recall@1 goes from 66.0% to 84.3%, and MRR from 0.761 to 0.894, at p50 0.60s and $0.15 for the whole bench.
264
+
265
+ It is opt-in and sends data off-machine: **the query text and every candidate's code/doc snippet are sent to `api.typesafe.ai`.** Enable it only if that is acceptable for your codebase.
266
+
267
+ To enable it:
268
+
269
+ - Run `project-brain setup` and select the reranker unit when prompted (you'll be asked for a token), or
270
+ - Pass `--reranker-token <token>` to `project-brain setup` for a non-interactive install, or
271
+ - Set the `TYPESAFE_API_KEY` environment variable (checked before the file either way).
272
+
273
+ With no token configured, nothing changes — zero network calls, identical result order. Any failure (timeout, non-2xx, a malformed response) falls back silently to the normal, unreranked order rather than surfacing an error. `project-brain health` reports `reranker: configured` once a token resolves.
260
274
 
261
275
  ## Recipes — get the most out of it
262
276
 
@@ -429,6 +443,19 @@ Check system health: Ollama availability, LanceDB status, and staleness of the i
429
443
  project-brain health
430
444
  ```
431
445
 
446
+ ### `bench` — measure retrieval quality
447
+
448
+ Published embedding leaderboards score a different corpus and a different task. A percent-or-two delta on someone else's benchmark says nothing about whether YOUR queries still surface the right file after changing model, dimension or chunking — so `bench` measures against ground truth from *this* repository instead.
449
+
450
+ ```bash
451
+ project-brain bench mine [--out .project-brain/bench/queries.jsonl] [--limit N] # mine ground truth from git history
452
+ project-brain bench .project-brain/bench/queries.jsonl [--project <id>] [--pipeline full|hybrid]
453
+ ```
454
+
455
+ `bench mine` walks non-merge commits and turns each one into a query: the commit subject (plus a short first body paragraph) as the query, the files it changed as the expected source(s). It skips release/version-bump commits, mass edits (more than ~8 files), and commits that touched only non-indexed files (lockfiles, `package.json`, `CHANGELOG.md`). Deterministic — the same repo history mines the same file every time.
456
+
457
+ `bench` then runs every query and reports recall@1/5/10 and MRR. `--pipeline hybrid` (default) measures `hybridSearch` alone — the retrieval signal in isolation. `--pipeline full` runs the exact path `search_context` runs (threshold + MMR + token budget), scoring what an agent actually receives, at the cost of conflating retrieval quality with post-processing behavior.
458
+
432
459
  ### `search`
433
460
 
434
461
  Search the indexed context and print compact results. Primarily used internally: `init` installs a `UserPromptSubmit` hook (`project-brain search --stdin`) in `.claude/settings.json` that auto-injects relevant context on every prompt, so retrieval is deterministic rather than relying on the AI to call a tool.
@@ -462,8 +489,12 @@ project-brain okf validate [dir] # conformance (SPEC §11). Offline.
462
489
  project-brain okf sync [dir] # index the concepts so search returns them
463
490
  project-brain okf audit [dir] # cross-check the bundle against the code graph
464
491
  project-brain okf audit --symbol <name> # which concepts to re-read after <name> changes
492
+ project-brain okf audit --json # one JSON object instead of prose, for CI/tooling
493
+ project-brain okf audit --judge # ask Claude whether a stale finding's reasoning still holds
465
494
  ```
466
495
 
496
+ `--judge` is opt-in and costs money: it sends `claude-opus-5` the concept's prose plus the actual code diff, for every `stale` finding where the code moved but the reasoning might not have (never for `uncommitted`, `expired`, or a broken anchor). Needs Anthropic credentials (`ANTHROPIC_API_KEY` or `ant auth login`) — without them the run aborts judging and falls back to the plain, unjudged audit. A "still holds" verdict never auto-attests; it only moves the finding into a non-failing `judged` backlog for a human to confirm with a `verified` entry.
497
+
467
498
  `init` writes `index.md` and `log.md` and stops — **no seeded concepts**, because a bundle shipped with examples makes the first `audit` report coverage gaps across the whole repo. Type directories appear when the first concept needs them.
468
499
 
469
500
  It also re-renders `CLAUDE.md`. `project-brain init` runs before any bundle exists, so the knowledge-bundle section is omitted then; `okf init` adds it once there is something to point at. That section asks the assistant to **decide, at the end of a task, whether anything belongs in the bundle** — and says plainly that most tasks produce nothing. A checkpoint that feels obliged to produce a file is a concept mill, and noise in a knowledge bundle is worse than gaps. Projects with no bundle never see the instruction.
@@ -528,6 +559,7 @@ BRAIN_HTTP_TOKEN=your-secret project-brain serve --http [--port 3000]
528
559
  | `BRAIN_EMBED_MODEL` | `qwen3-embedding:0.6b` | Ollama embedding model (registry keys: `qwen3-embedding`, `nomic-text`; or any raw Ollama model name; `none` disables embeddings — lexical/keyword search only, no Ollama needed) |
529
560
  | `OLLAMA_HOST` | `http://127.0.0.1:11434` | Ollama server URL |
530
561
  | `BRAIN_NO_UPDATE_CHECK` | — | Set to `1` to disable the update-available notice |
562
+ | `TYPESAFE_API_KEY` | — | Opt-in Jev reranker token — see [Reranking (optional)](#reranking-optional). Checked before `~/.project-brain/reranker.json`. |
531
563
 
532
564
  ## Tuning (environment variables)
533
565
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-brain",
3
- "version": "0.32.1",
3
+ "version": "0.34.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",
@@ -49,11 +49,11 @@
49
49
  "zod": "^4.4.3"
50
50
  },
51
51
  "optionalDependencies": {
52
- "project-brain-darwin-arm64": "0.32.1",
53
- "project-brain-linux-x64": "0.32.1",
54
- "project-brain-linux-arm64": "0.32.1",
55
- "project-brain-windows-x64": "0.32.1",
56
- "project-brain-windows-arm64": "0.32.1"
52
+ "project-brain-darwin-arm64": "0.34.0",
53
+ "project-brain-linux-x64": "0.34.0",
54
+ "project-brain-linux-arm64": "0.34.0",
55
+ "project-brain-windows-x64": "0.34.0",
56
+ "project-brain-windows-arm64": "0.34.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/bun": "latest",
@@ -4,11 +4,7 @@ This project is indexed with [project-brain](https://github.com/jcsoftdev/projec
4
4
 
5
5
  ## project-brain MCP
6
6
 
7
- You have access to the `project-brain` MCP server for codebase knowledge retrieval.
8
-
9
- {{tools}}
10
-
11
- When answering questions about this codebase, run `search_context` first to find semantically relevant context before reading files directly — and reach for the structural tools when you know the exact symbol, caller, or want the impact of a change.
7
+ You have access to the `project-brain` MCP server for codebase knowledge retrieval. Once connected, the server's own instructions describe the full tool catalog, routing (`search_context` for fuzzy/conceptual questions vs. the structural tools for exact symbols, callers, and change impact), and workflow — that copy always matches the tools actually registered, so it is not repeated here.
12
8
 
13
9
  ### Project Context
14
10
 
@@ -1,7 +1,3 @@
1
1
  ## project-brain MCP
2
2
 
3
- You have access to the `project-brain` MCP server for codebase knowledge retrieval.
4
-
5
- {{tools}}
6
-
7
- When answering questions about the codebase, run `search_context` first for fuzzy/conceptual questions, and use the structural tools (`find_symbol`/`find_callers`/`find_callees`/`impact`) for exact symbols, callers, and change impact — before reading files directly.
3
+ You have access to the `project-brain` MCP server for codebase knowledge retrieval. Once connected, the server's own instructions describe the full tool catalog, routing (`search_context` for fuzzy/conceptual questions vs. the structural tools — `find_symbol`/`find_callers`/`find_callees`/`impact` — for exact symbols, callers, and change impact), and workflow. That copy is generated from the same source as this file and always matches the tools actually registered, so it is not repeated here. Not seeing it? Reconnect or run `project-brain setup` again.
@@ -287,15 +287,17 @@ The absence gates (`Observability`, `Testing`, `Design System`, `Type Safety`, `
287
287
 
288
288
  1. Discovery — stack, architecture, feature map, via the routing table.
289
289
  2. Apply gates → proposed module set with per-module rationale.
290
- 3. **Present the proposal and wait for confirmation.** Report the token implication of the chosen set.
290
+ 3. **Present the proposal and wait for confirmation.** Report the token implication of the chosen set as a range, and label it an estimate: sum the line counts of the confirmed modules' reference files, then add an order-of-magnitude probe cost per module on top. A number with no method behind it is a guess wearing a token count.
291
291
  4. **Offer `Runtime` separately, after the module set is settled, and wait.** State that enabling it executes the project's code on this machine, list the declared commands it would run, and name the ones it will not touch. Declining is normal and costs only the `executed` tier. Never fold this into step 3 — a user confirming twenty static modules has not consented to run anything.
292
292
  - **4b. Offer `Browser` separately, after `Runtime`, and wait.** Only when a UI or HTML entry point was detected and a browser tool is present. Name the target URL and where it came from, the tool filling the walker and measurer roles, whether any role runs in the user's real browser session, the candidate flows (up to five, ranked by product centrality), and the total pass count. Wait for the flow list to be confirmed before any browser opens. Declining costs only the `observed` tier.
293
- 5. For each confirmed module, read only its `references/<module>.md`, then verify against real code — project-brain first, `Read` only to confirm lines it points at. **Run the probe each check names.** A check whose probe was not run produces no finding, not an `inferred` one.
294
- 6. Collect findings using the schema above, each with its evidence tier and its ruled-out alternative. Leave `Refutation` empty; step 8 fills it.
295
- 7. **Present the Refutation Manifest and wait** — findings collected, how many are eligible at Medium or above, how many are left raw below threshold, how many refuters that means, and the resolved mode with model ids where they are known. Answers are `all`, `critical+high only`, or `none`. A user who replied `refute all` at step 3 has pre-authorised it; print the manifest as a notice and continue. `none` stamps every finding `declined by user` — it does not silently skip the stage.
296
- 8. Refute. One subagent per eligible finding, fresh context, the brief and nothing else. Escalate to a second refuter only on `undetermined` at Critical or High, telling it which probes were already inconclusive.
297
- 9. Apply the verdicts: drop `refuted` findings into the ledger, reduce `weakened` ones to the severity the refuter named, cap `undetermined` at Medium, and record the mode on every finding. Deduplicate here — the refuters could not, having each seen one finding.
298
- 10. Record every module's `Out of static reach` items that mattered — they become Coverage Gaps, not silent omissions.
293
+ 5. Dispatch each confirmed module — or a small batch of cheap, related modules — to its own subagent. Its brief: the module's `references/<module>.md` path, the discovery summary from step 1, the finding schema, and a hard cap on the reply — schema-shaped findings only, no tool transcripts, no reasoning trace. The subagent reads only its reference file, verifies against real code — project-brain first, `Read` only to confirm lines it points at — and **runs the probe each check names**; a check whose probe was not run produces no finding, not an `inferred` one. Route mechanical sweeps (literal counts, orphan-asset greps, token adoption) to a fast model tier and reasoning-heavy modules (security, reachability, architecture) to a stronger one — the same split the Refutation Mode table already tracks by model id, so record it there instead of a second place. The main thread keeps discovery and aggregation; it does not read module references or run probes itself. Where the host has no subagent mechanism, fall back to running modules sequentially in the main context and say so in the Executive Summary.
294
+ 6. Collect findings using the schema above, each with its evidence tier and its ruled-out alternative. Leave `Refutation` empty; refutation (step 9) fills it.
295
+ 7. **Deduplicate before refuting.** Two findings are the same finding when they share a file with overlapping line ranges, or share a symbol and the same root cause — even when two different modules reported it. Keep the copy with the higher severity, or the stronger evidence tier on a tie, and list every module that reported it. This runs before the Refutation Manifest so no refuter is ever paid to kill a duplicate.
296
+ 8. **Present the Refutation Manifest and wait** — deduplicated findings collected, how many are eligible at Medium or above, how many are left raw below threshold, how many refuters that means, and the resolved mode with model ids where they are known. Answers are `all`, `critical+high only`, or `none`. A user who replied `refute all` at step 3 has pre-authorised it; print the manifest as a notice and continue. `none` stamps every finding `declined by user` — it does not silently skip the stage.
297
+ 9. Refute. One subagent per eligible finding, fresh context, the brief and nothing else — on a different model than the one that produced the finding, when the host lets you choose; the Refutation Mode table already records the model ids this yields, so name it there and not twice. Escalate to a second refuter only on `undetermined` at Critical or High, telling it which probes were already inconclusive.
298
+ 10. Apply the verdicts: drop `refuted` findings into the ledger, reduce `weakened` ones to the severity the refuter named, cap `undetermined` at Medium, and record the mode on every finding. Run one more light dedup pass, restricted to findings whose severity changed under refutation — step 7 saw them at their pre-refutation severity and could not have grouped them correctly.
299
+ 11. Record every module's `Out of static reach` items that mattered — they become Coverage Gaps, not silent omissions.
300
+ 12. **Persist the report.** Once the Output Contract is filled, write the full report to `.project-brain/audits/<YYYY-MM-DD>-audit.md` in the audited repo — and the SARIF file next to it when SARIF emission is on — then print the path. A report this size does not survive the next context compaction, and a dated file gives the next audit something to diff against. When a previous report exists in that directory, the Executive Summary names new, resolved, and unchanged findings by fingerprint, reusing the SARIF fingerprint definition even when SARIF itself is off.
299
301
 
300
302
  ## Output Contract
301
303
 
@@ -313,6 +315,8 @@ The Executive Summary carries one line naming the refutation mode, both model id
313
315
 
314
316
  Never invent issues — every finding is backed by repo evidence. Visual quality has a hard static ceiling: the modules say what the code determines and list the rest under Coverage Gaps. An aesthetic verdict with no evidence behind it is the one failure mode this audit cannot recover from, because the user has no way to tell it apart from a real finding.
315
317
 
318
+ The finished report is written to disk, not left in the transcript — see Execution Steps step 12 for the path and the diff-against-previous-run contract. This section governs its shape; that step governs its survival.
319
+
316
320
  ## SARIF Emission (optional)
317
321
 
318
322
  Prose is the default and remains the default — most readers of this audit read the report themselves, and turning SARIF on does not change or replace a single line of the Output Contract above. SARIF is an additional, opt-in artefact for teams that want findings in code scanning: pass `--sarif <path>` (or the session equivalent) to also emit a SARIF 2.1.0 document alongside the prose report.