project-brain 0.36.0 → 0.38.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 +43 -7
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -272,8 +272,18 @@ 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
+
285
+ **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 prompt 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`.
286
+
277
287
  ## Recipes — get the most out of it
278
288
 
279
289
  You talk to your **AI assistant** in natural language; it picks the right tool. These prompts steer it well:
@@ -405,15 +415,21 @@ Override the table in `~/.project-brain/model-routing.json`:
405
415
 
406
416
  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
417
 
408
- #### Architecture guard (opt-in)
418
+ #### Architecture guard
409
419
 
410
- A `PreToolUse` hook on `Edit`, `Write` and `MultiEdit` that blocks an edit which breaks your architecture boundaries. Not installed by default, because it stops a real tool call:
420
+ 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.
411
421
 
412
422
  ```bash
413
- project-brain setup --with=hooks:arch-guard
414
- project-brain arch init # writes .project-brain/architecture.json (hexagonal preset, mode "warn")
423
+ project-brain setup --with=hooks:arch-guard # hook + global default (already on in a plain `setup`)
424
+ project-brain arch init # optional: pin a per-project config that overrides the global default
415
425
  ```
416
426
 
427
+ **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.
428
+
429
+ **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).
430
+
431
+ **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.
432
+
417
433
  **Layer rules (deterministic, offline).** `.project-brain/architecture.json` names the layers and what may not depend on what:
418
434
 
419
435
  ```json
@@ -424,12 +440,31 @@ project-brain arch init # writes .project-brain/architecture.json (he
424
440
  }
425
441
  ```
426
442
 
427
- 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"`. A warning is delivered to Claude as `additionalContext` next to the tool result, and a malformed file means no check, never a crash.
443
+ 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.
428
444
 
429
- **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 `architecture.json` exists and 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.
445
+ **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.
430
446
 
431
447
  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.
432
448
 
449
+ #### Commit check (needs a TypeSafe token)
450
+
451
+ 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:
452
+
453
+ - **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.
454
+ - **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.
455
+
456
+ ```bash
457
+ project-brain setup --with=hooks:commit-check
458
+ ```
459
+
460
+ `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`:
461
+
462
+ ```json
463
+ { "mode": "block" }
464
+ ```
465
+
466
+ The test warning never blocks.
467
+
433
468
  ### `init`
434
469
 
435
470
  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.
@@ -589,7 +624,8 @@ BRAIN_HTTP_TOKEN=your-secret project-brain serve --http [--port 3000]
589
624
  | `OLLAMA_HOST` | `http://127.0.0.1:11434` | Ollama server URL |
590
625
  | `BRAIN_NO_UPDATE_CHECK` | — | Set to `1` to disable the update-available notice |
591
626
  | `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`). |
592
- | `TYPESAFE_API_KEY` | — | Opt-in Jev reranker token — see [Reranking (optional)](#reranking-optional). Checked before `~/.project-brain/reranker.json`. |
627
+ | `BRAIN_SKILL_PICKER` | on | Set to `0` to turn off the Jev skill suggestion the prompt hook appends — see [Skill suggestions](#skill-suggestions). |
628
+ | `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. |
593
629
 
594
630
  ## Tuning (environment variables)
595
631
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-brain",
3
- "version": "0.36.0",
3
+ "version": "0.38.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.36.0",
53
- "project-brain-linux-x64": "0.36.0",
54
- "project-brain-linux-arm64": "0.36.0",
55
- "project-brain-windows-x64": "0.36.0",
56
- "project-brain-windows-arm64": "0.36.0"
52
+ "project-brain-darwin-arm64": "0.38.0",
53
+ "project-brain-linux-x64": "0.38.0",
54
+ "project-brain-linux-arm64": "0.38.0",
55
+ "project-brain-windows-x64": "0.38.0",
56
+ "project-brain-windows-arm64": "0.38.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/bun": "latest",