project-brain 0.42.0 → 0.43.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
@@ -486,6 +486,18 @@ Override the table in `~/.project-brain/model-routing.json`:
486
486
 
487
487
  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.
488
488
 
489
+ #### Coding rules guard
490
+
491
+ A `PreToolUse` hook on `Edit`, `Write` and `MultiEdit` that hands an agent the installed `brain-style` skill the first time it edits a code file, so the rules arrive when code is written rather than when a prompt is typed. It reaches sub-agents too: Claude Code fires `PreToolUse` inside them, and the hook keys its once-only memory by session and agent. It is selected by default in `setup` because it is local and warn-only: it exits 0 and adds the rules as `additionalContext`, and fails open on anything it cannot read.
492
+
493
+ ```bash
494
+ project-brain setup --with=hooks:style-guard # already on in a plain `setup`
495
+ ```
496
+
497
+ **Which skills apply.** A table maps file extensions to skills (code files to `brain-style`; prose, data and config files to nothing). Only a file the table cannot classify, and only when a TypeSafe token exists, goes to Jev, which sees the file path alone and answers per skill whether it applies; without a token the hook stays silent for those files. The rules text is read from `~/.claude/skills/<skill>/SKILL.md`, so editing the installed skill changes what is injected; if the skill is not installed the hook says nothing.
498
+
499
+ **Opt out.** Deselect `hooks:style-guard` in `setup`.
500
+
489
501
  #### Architecture guard
490
502
 
491
503
  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.
@@ -528,7 +540,7 @@ A `PreToolUse` hook on `Bash` that acts only on `git commit` (including `git -C
528
540
  project-brain setup --with=hooks:commit-check
529
541
  ```
530
542
 
531
- `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`:
543
+ `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, the Jev part does nothing. Independently of Jev, it names the source files whose staged diff adds comment lines (the `brain-style` rule is zero comments in new code); that check is local, needs no token, and only warns. 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`:
532
544
 
533
545
  ```json
534
546
  { "mode": "block" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-brain",
3
- "version": "0.42.0",
3
+ "version": "0.43.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.42.0",
53
- "project-brain-linux-x64": "0.42.0",
54
- "project-brain-linux-arm64": "0.42.0",
55
- "project-brain-windows-x64": "0.42.0",
56
- "project-brain-windows-arm64": "0.42.0"
52
+ "project-brain-darwin-arm64": "0.43.0",
53
+ "project-brain-linux-x64": "0.43.0",
54
+ "project-brain-linux-arm64": "0.43.0",
55
+ "project-brain-windows-x64": "0.43.0",
56
+ "project-brain-windows-arm64": "0.43.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/bun": "latest",
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  name: brain-style
3
- description: "Trigger: writing or editing code, adding a comment, docblock or header, reviewing a diff for readability, escribe el código, refactor this, clean this up. Keeps generated code declarative — the code carries the meaning, and a comment appears only where it says something the code cannot."
3
+ description: "Trigger: writing or editing code, adding a comment, docblock or header, reviewing a diff for readability or architecture, escribe el código, refactor this, clean this up, delegating code to a sub-agent. Keeps generated code architecture-first and declarative — the code carries the meaning, and the why lives in the commit message or the knowledge bundle, never in a comment."
4
4
  license: Apache-2.0
5
5
  metadata:
6
6
  author: jcsoftdev
7
- version: "1.0"
7
+ version: "1.1"
8
8
  generator: project-brain
9
9
  ---
10
10
 
@@ -17,7 +17,7 @@ metadata:
17
17
 
18
18
  ## Activation Contract
19
19
 
20
- Apply whenever code is written or edited: a new file, a patch, a refactor, a snippet in an answer.
20
+ Apply whenever code is written or edited: a new file, a patch, a refactor, a snippet in an answer. Apply it to a sub-agent's diff before accepting it.
21
21
 
22
22
  Do not apply when: the user dictated the comment or the code verbatim, the file is generated or vendored, or the comment is published API documentation that a doc generator turns into a reference page.
23
23
 
@@ -27,13 +27,40 @@ This rule outranks inherited style guidance — a house style read off surroundi
27
27
 
28
28
  One thing outranks it: the user asking, in the moment, for something else. Their instruction is the answer, not a conflict to resolve.
29
29
 
30
- Existing comments are not the target. Do not strip a file's docblocks as a side effect of editing three lines in it — that is a rewrite nobody asked for, and it buries the actual change in the diff.
30
+ Existing comments are not the target. Do not strip a file's docblocks as a side effect of editing three lines in it — that is a rewrite nobody asked for, and it buries the actual change in the diff. Pre-existing comments on untouched lines stay.
31
31
 
32
- ## The rule
32
+ ## Architecture first
33
33
 
34
- **Default: no comment.** A comment is a claim that the code failed to say something, and most of the time the honest fix is the code.
34
+ Never write code "as it comes out".
35
35
 
36
- Before writing one, try these, in order:
36
+ - Before writing, find how the repo already solves the same problem and follow it.
37
+ - Use the repo's own formatter, never another one.
38
+ - Second copy of anything: extract it. Reach for the existing helper or kit component before writing a new one.
39
+
40
+ ### Contracts, not magic strings
41
+
42
+ A code or state that crosses a boundary (API to client, service to service) is a typed enum or schema in the shared contract.
43
+
44
+ - The producer builds with the contract type; the consumer parses with the schema.
45
+ - Copy per code lives in an exhaustive map, so a new code without copy fails to compile.
46
+ - Parse external data with its schema. `as` only when the type system cannot express the fact.
47
+
48
+ ### Layers
49
+
50
+ | Layer | Owns | Never owns |
51
+ |---|---|---|
52
+ | Domain | Business rules, pure and tested | I/O, framework types |
53
+ | Adapter | Persistence | Business rules |
54
+ | Controller | Validate, orchestrate, translate | Business rules |
55
+ | UI component | Rendering | Rules, thresholds, conditional copy |
56
+
57
+ - Container–presentational: a component receives what to show; it does not decide.
58
+ - Mappers, thresholds and conditional copy are pure functions with tests, outside the component.
59
+ - Translate errors in one place per module. The same `catch` repeated per handler is the defect.
60
+
61
+ ## Zero comments
62
+
63
+ A comment is a claim that the code failed to say something, and the honest fix is the code. Add none. Try these, in order:
37
64
 
38
65
  | Instead of a comment | Do this |
39
66
  |---|---|
@@ -43,26 +70,30 @@ Before writing one, try these, in order:
43
70
  | `// this branch handles the empty case` | Make the branch read as the empty case: guard clause, early return |
44
71
  | `// args: name, retries, timeout` | Take a named object, or a type the reader can open |
45
72
  | `// returns null when not found` | Say it in the signature: `T \| null`, `Option<T>`, a typed result |
73
+ | `// must stay sorted, bisect depends on it` | A type or a named function that enforces it |
46
74
 
47
75
  If one of those works, the comment was a naming problem wearing a disguise.
48
76
 
49
- ## What earns a comment
77
+ ### Where the why goes
78
+
79
+ A reason the code cannot hold — a rejected alternative, an external constraint, a vendor quirk, a workaround pinned to a bug or version — does not go in the file.
80
+
81
+ - The commit message carries the why of this change.
82
+ - The knowledge bundle carries the lasting why: a constraint that must keep holding, a trap that already cost a debugging session. Use the `brain-okf` skill.
83
+
84
+ Banners, commented-out code (delete it), changelog lines, attribution, dates and ownerless `TODO`s never belong in the file either.
50
85
 
51
- Three things, all of them the *why* — never the *what*:
86
+ ### Check before every commit
52
87
 
53
- - **A reason the code cannot hold.** A rejected alternative and why it lost, an external constraint, a spec or vendor quirk that makes correct code look wrong.
54
- - **An invariant that breaks non-locally.** "This must stay sorted, `bisect` downstream depends on it." The reader cannot see the downstream from here.
55
- - **A workaround pinned to something external.** Name the bug, version, or ticket, so the next person can tell whether it is still needed.
88
+ ```sh
89
+ git diff --cached | rg '^\+\s*(//|/\*|\*\s|\{/\*)'
90
+ ```
56
91
 
57
- Write those in full sentences. They are for a reader a year out with no memory of this week.
92
+ The output must be empty.
58
93
 
59
- ## What never earns one
94
+ ## Delegating code
60
95
 
61
- - Restating the line below it.
62
- - Section banners (`// ---- helpers ----`) — that is a file asking to be split.
63
- - Commented-out code. Delete it; that is what version control is for.
64
- - Changelog, attribution, or a date. The log holds those, and it stays accurate.
65
- - A `TODO` with no owner and no condition. Either it blocks and belongs in an issue, or it does not and belongs nowhere.
96
+ Restate this whole rule in every sub-agent prompt that writes code, and review its diff against it before accepting. A sub-agent that was not told produces code as it comes out.
66
97
 
67
98
  ## Reporting back
68
99