project-brain 0.35.0 → 0.37.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 +62 -2
- package/package.json +6 -6
- package/templates/model-routing.md +14 -9
package/README.md
CHANGED
|
@@ -272,8 +272,16 @@ To enable it:
|
|
|
272
272
|
- Pass `--reranker-token <token>` to `project-brain setup` for a non-interactive install, or
|
|
273
273
|
- Set the `TYPESAFE_API_KEY` environment variable (checked before the file either way).
|
|
274
274
|
|
|
275
|
+
With the reranker unit installed, a Claude Code `SessionStart` hook (`project-brain jev-env`) also exports the stored token as `TYPESAFE_API_KEY` into the session's shell, so the typesafe-ai skill, the TypeSafe SDK and ad-hoc scripts find it too. It appends to `CLAUDE_ENV_FILE`, leaves an already-set `TYPESAFE_API_KEY` alone, and never prints the token. Re-run `project-brain setup` once to add the hook to an existing install; the stored token is reused.
|
|
276
|
+
|
|
275
277
|
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.
|
|
276
278
|
|
|
279
|
+
### Skill suggestions
|
|
280
|
+
|
|
281
|
+
With a token configured, the same `UserPromptSubmit` hook also asks Jev which installed skill best fits your prompt, in parallel with retrieval, and appends one line to the injected context: `Suggested skill: <name> — <why>`. It only appears when Jev is at least 70% confident; otherwise nothing is added. Skills are read from `~/.claude/skills`, `<project>/.claude/skills`, `~/.agents/skills` and installed plugins (`plugin:skill`), cached on disk (rebuilt when any SKILL.md changes, or after ten minutes). The shortlist is chosen by embedding similarity using the project's embedding model, so prompts in any language the model supports match English skill descriptions; skill vectors are cached next to the skill list, and without embeddings it falls back to keyword overlap.
|
|
282
|
+
|
|
283
|
+
**The prompt text and the shortlisted skills' names and descriptions (at most 12) are sent to `api.typesafe.ai`** — the same disclosure as the reranker. Trivial prompts send nothing, and on the keyword fallback so do prompts with no overlap with any skill. The whole pick is capped at 1.5s and fails silently. Opt out with `BRAIN_SKILL_PICKER=0`.
|
|
284
|
+
|
|
277
285
|
## Recipes — get the most out of it
|
|
278
286
|
|
|
279
287
|
You talk to your **AI assistant** in natural language; it picks the right tool. These prompts steer it well:
|
|
@@ -405,6 +413,56 @@ Override the table in `~/.project-brain/model-routing.json`:
|
|
|
405
413
|
|
|
406
414
|
Add `--routing-hook-strict` for enforcement: a `PreToolUse` hook that blocks a spawn naming no model and tells the model to re-issue it with one. Off by default — inheriting the session model is sometimes the right call, and the guard fails open on any payload it cannot parse. `--no-routing-hook` skips both.
|
|
407
415
|
|
|
416
|
+
#### Architecture guard
|
|
417
|
+
|
|
418
|
+
A `PreToolUse` hook on `Edit`, `Write` and `MultiEdit` that checks an edit against your architecture boundaries. It is selected by default in `setup` because it is local and warn-only out of the box: the setup unit installs the hook and seeds a **global default** at `~/.project-brain/architecture.json` (hexagonal/clean preset, `"mode": "warn"`), so every project is covered with no per-project step.
|
|
419
|
+
|
|
420
|
+
```bash
|
|
421
|
+
project-brain setup --with=hooks:arch-guard # hook + global default (already on in a plain `setup`)
|
|
422
|
+
project-brain arch init # optional: pin a per-project config that overrides the global default
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
**Which config applies.** A project's own `.project-brain/architecture.json` replaces the global one whole, with no merging (even a broken project file means "no check", never a silent fall-through to the global rules). Without one, the global default applies, and a warning or block names it: `(global default: ~/.project-brain/architecture.json)`. The seed is written only when the hook is first installed and the file is absent, so an edited or deliberately deleted global file is never recreated, and removing the unit leaves it in place.
|
|
426
|
+
|
|
427
|
+
**Opt out.** Deselect `hooks:arch-guard` in `setup`, or set `"mode": "off"` in a config (global to silence every project, or per project to silence one; a project file wins either way).
|
|
428
|
+
|
|
429
|
+
**The preset.** Only unambiguous folder names: `domain` = `**/domain/**`; `application` = `**/application/**`, `**/use-cases/**`, `**/usecases/**`; `infrastructure` = `**/infrastructure/**`, `**/infra/**`. Names like `core`, `entities` and `adapters` are left out because they mean other things in many trees; add them to the layer globs in your own `.project-brain/architecture.json` if your project uses them that way. Domain may not depend on application or infrastructure; application may not depend on infrastructure. A path matching several layers (`src/infra/domain/x.ts`) belongs to the layer whose matched directory is closest to the file (here `domain`); a tie at the same depth goes to the layer declared first. A project whose paths match no layer is left unchecked.
|
|
430
|
+
|
|
431
|
+
**Layer rules (deterministic, offline).** `.project-brain/architecture.json` names the layers and what may not depend on what:
|
|
432
|
+
|
|
433
|
+
```json
|
|
434
|
+
{
|
|
435
|
+
"layers": { "domain": "src/domain/**", "application": "src/application/**", "infrastructure": ["src/infra/**", "pkg:pg"] },
|
|
436
|
+
"forbid": [{ "from": "domain", "to": ["application", "infrastructure"] }],
|
|
437
|
+
"mode": "block"
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
A layer is a glob or an array of globs; `pkg:<name>` claims a third-party package, which is otherwise in no layer. Only the imports the edit **adds** are judged, so a violation already in the file never blocks an unrelated change. TS/JS (`import`, `export … from`, `require`, literal `import()`), Go (through the `go.mod` module path) and Python are understood; relative specifiers resolve against the edited file, trying extensions and `/index`. `tsconfig` `paths` aliases are not resolved yet. Import syntax is matched in code only, so an import written inside a string, template or docstring is not a dependency. Only an explicit `"mode": "block"` blocks; a missing or unrecognised mode, and a file that is not valid JSON, mean `"warn"`; `"off"` disables the guard, Jev layer included. A warning is delivered to Claude as `additionalContext` next to the tool result, and a malformed file means no check, never a crash.
|
|
442
|
+
|
|
443
|
+
**Constraints (fuzzy, needs a TypeSafe token).** Any `type: Constraint` concept in `okf/` whose `resource:` anchor covers the edited file is put to Jev as a yes/no question; the edit is blocked when P(violates) is above 0.8. A directory anchor with a trailing slash (`resource: ../src/domain/`) covers every file under it. This layer sends the edit and the constraint text to `api.typesafe.ai`, and only runs when a token resolves (the same one the reranker uses). With no token it is skipped, and a timeout or error lets the edit through. It blocks only when the applying `architecture.json` (project or global) says `"mode": "block"` (the file may hold nothing else); with no file it only warns, so a token you keep for reranking never stops an edit. At most 10 constraints are asked per edit, the most specific anchors first.
|
|
444
|
+
|
|
445
|
+
The hook reads stdin and fails open on anything it cannot parse. A block exits `2` with the reason on stderr, which Claude Code hands to the model as the retry prompt.
|
|
446
|
+
|
|
447
|
+
#### Commit check (needs a TypeSafe token)
|
|
448
|
+
|
|
449
|
+
A `PreToolUse` hook on `Bash` that acts only on `git commit` (including `git -C x commit` and `a && git commit`). One Jev call over the staged diff does two jobs:
|
|
450
|
+
|
|
451
|
+
- **Review triage.** Yes/no questions: security or permission boundaries, data loss or destructive operations, concurrency or locking, public contract changes. If any has P(yes) above 0.8 (or Jev is down or unsure on a risky-looking diff), Claude is told to run an independent deep review on a stronger model, or ask you, before committing. Jev only escalates: a routine change prints nothing, and silence is never an approval.
|
|
452
|
+
- **Test warning.** For staged source files with no staged test, Jev says whether the change is a business rule, bug fix, security boundary or data contract, which is where tests earn their keep. A match is a warning naming the files; nothing is ever required first.
|
|
453
|
+
|
|
454
|
+
```bash
|
|
455
|
+
project-brain setup --with=hooks:commit-check
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
`setup` ticks it by default only when a token is already configured, since the diff (first 16,000 characters) is sent to `api.typesafe.ai`. Without a token, with an empty diff, or on any error or timeout, it does nothing. The default is a warning delivered as `additionalContext`; to make the review escalation block (exit `2`, reason on stderr), write `~/.project-brain/commit-check.json`:
|
|
459
|
+
|
|
460
|
+
```json
|
|
461
|
+
{ "mode": "block" }
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
The test warning never blocks.
|
|
465
|
+
|
|
408
466
|
### `init`
|
|
409
467
|
|
|
410
468
|
Initialize a project. Detects the stack, writes a `CLAUDE.md` with MCP instructions, installs a git hook, scaffolds module stubs in `docs/modules/`, and indexes the project.
|
|
@@ -497,7 +555,7 @@ project-brain okf audit --json # one JSON object instead of prose, f
|
|
|
497
555
|
project-brain okf audit --judge # ask Claude whether a stale finding's reasoning still holds
|
|
498
556
|
```
|
|
499
557
|
|
|
500
|
-
`--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.
|
|
558
|
+
`--judge` is opt-in and costs money: it sends `claude-opus-5-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.
|
|
501
559
|
|
|
502
560
|
`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.
|
|
503
561
|
|
|
@@ -563,7 +621,9 @@ BRAIN_HTTP_TOKEN=your-secret project-brain serve --http [--port 3000]
|
|
|
563
621
|
| `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) |
|
|
564
622
|
| `OLLAMA_HOST` | `http://127.0.0.1:11434` | Ollama server URL |
|
|
565
623
|
| `BRAIN_NO_UPDATE_CHECK` | — | Set to `1` to disable the update-available notice |
|
|
566
|
-
| `
|
|
624
|
+
| `BRAIN_CONCEPT_MODEL` | `claude-haiku-5-5` | Anthropic model id `conceptualize` uses to write module concepts. Read on each call. Same credentials as `--judge` (`ANTHROPIC_API_KEY` or `ant auth login`). |
|
|
625
|
+
| `BRAIN_SKILL_PICKER` | on | Set to `0` to turn off the Jev skill suggestion the prompt hook appends — see [Skill suggestions](#skill-suggestions). |
|
|
626
|
+
| `TYPESAFE_API_KEY` | — | Opt-in Jev reranker token — see [Reranking (optional)](#reranking-optional). Checked before `~/.project-brain/reranker.json`; a SessionStart hook exports the stored token under this name to Claude Code sessions. |
|
|
567
627
|
|
|
568
628
|
## Tuning (environment variables)
|
|
569
629
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "project-brain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.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.
|
|
53
|
-
"project-brain-linux-x64": "0.
|
|
54
|
-
"project-brain-linux-arm64": "0.
|
|
55
|
-
"project-brain-windows-x64": "0.
|
|
56
|
-
"project-brain-windows-arm64": "0.
|
|
52
|
+
"project-brain-darwin-arm64": "0.37.0",
|
|
53
|
+
"project-brain-linux-x64": "0.37.0",
|
|
54
|
+
"project-brain-linux-arm64": "0.37.0",
|
|
55
|
+
"project-brain-windows-x64": "0.37.0",
|
|
56
|
+
"project-brain-windows-arm64": "0.37.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@types/bun": "latest",
|
|
@@ -16,7 +16,7 @@ Shortcut: sub-agent output is yes/no or a list → fast. Output is code or
|
|
|
16
16
|
synthesis → balanced. Output is "which approach is better" → deep.
|
|
17
17
|
|
|
18
18
|
**On {{hostName}}:** {{howToApply}}
|
|
19
|
-
{{labelRule}}
|
|
19
|
+
{{labelRule}}{{advisorRule}}
|
|
20
20
|
### When NOT to delegate
|
|
21
21
|
|
|
22
22
|
Delegation is not free — it pays a full context bootstrap before the sub-agent
|
|
@@ -29,9 +29,9 @@ stay there.
|
|
|
29
29
|
|
|
30
30
|
Run the cheapest tier the task table allows. On a failed or empty result,
|
|
31
31
|
retry one tier up. The escalation pays because most delegations never need it,
|
|
32
|
-
|
|
33
|
-
table already puts at `deep` goes there first: a wrong answer from a
|
|
34
|
-
tier costs a retry plus the parent's turns spent acting on it.
|
|
32
|
+
and because the fast tier is far cheaper than the rest — see Relative cost.
|
|
33
|
+
A task the table already puts at `deep` goes there first: a wrong answer from a
|
|
34
|
+
cheaper tier costs a retry plus the parent's turns spent acting on it.
|
|
35
35
|
|
|
36
36
|
### Verification must be asymmetric
|
|
37
37
|
|
|
@@ -57,11 +57,16 @@ cost the same tokens as three in sequence, and a third of the wall-clock.
|
|
|
57
57
|
|
|
58
58
|
### Relative cost
|
|
59
59
|
|
|
60
|
-
Per token, at list price
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
Per token, at list price, the gaps are uneven. On the Claude lineup, fast to
|
|
61
|
+
balanced (Haiku 5.5 to Sonnet 5.5) is about 20×, balanced to deep (Sonnet 5.5
|
|
62
|
+
to Opus 5.5) is 2×, and Fable 5.1 is 2.5× Opus. So moving a lookup down to fast
|
|
63
|
+
saves far more than moving a judgment call down from deep, and a failed fast
|
|
64
|
+
attempt retried one tier up still costs a fraction of starting at balanced.
|
|
65
|
+
Between balanced and deep the price rarely settles the choice: what does is the
|
|
66
|
+
tokens spent. A deeper tier at high effort thinks longer, and a cheap tier that
|
|
67
|
+
gets it wrong costs a retry and the parent's turns acting on it. Judge by the
|
|
68
|
+
cost of the finished task, not of one call.
|
|
69
|
+
(https://platform.claude.com/docs/en/models/overview.md)
|
|
65
70
|
|
|
66
71
|
### project-brain's own routing
|
|
67
72
|
|