project-brain 0.16.1 → 0.17.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
@@ -7,17 +7,25 @@ project-brain indexes your project files into a local LanceDB vector store using
7
7
  ## Quick Start
8
8
 
9
9
  ```bash
10
- # 1. Install globally
11
- bun install -g project-brain
10
+ # 1. Install globally — pick one
11
+ curl -fsSL https://raw.githubusercontent.com/jcsoftdev/project-brain/main/scripts/install.sh | sh
12
+ bun install -g project-brain # or npm / pnpm / yarn
13
+ brew install jcsoftdev/tap/project-brain
12
14
 
13
15
  # 2. One-time: register in your AI tools (Claude, Codex, Cursor, Gemini, Windsurf, Zed, VS Code)
16
+ # Also installs the brain-audit and brain-okf host skills. --no-skills to opt out.
14
17
  project-brain setup
15
18
 
16
19
  # 3. Per-project: initialize, index, and install git hook
17
20
  cd my-project
18
21
  project-brain init
22
+
23
+ # 4. Optional, per-project: start a knowledge bundle for the *why*
24
+ project-brain okf init
19
25
  ```
20
26
 
27
+ The `curl` line needs no package manager at all — the binary ships self-contained. See [Install](#install) for every channel and the platforms each covers.
28
+
21
29
  After `init`, the following run **automatically** without any extra steps:
22
30
 
23
31
  | Trigger | What happens |
@@ -28,7 +36,7 @@ After `init`, the following run **automatically** without any extra steps:
28
36
 
29
37
  ## Prerequisites
30
38
 
31
- - **Nothing extra to run it.** The registry install ships a self-contained, prebuilt binary per platform (the runtime is bundled in) — you do **not** need Bun or Node installed to use project-brain.
39
+ - **Nothing extra to run it.** Every channel ships the same self-contained, prebuilt binary per platform, with the runtime, WASM grammars and templates bundled in — you do **not** need Bun or Node installed to use project-brain. The `curl` installer does not even need one to *install* it.
32
40
  - **Bun** ≥ 1.3.14 — only needed to build/run **from source** ([install](https://bun.sh)).
33
41
  - **Ollama** (optional, only for semantic search) — download from [ollama.com](https://ollama.com). `project-brain init` **auto-pulls** the default embedding model `qwen3-embedding:0.6b` (1024-dim, fast, code-capable). To pre-pull it: `ollama pull qwen3-embedding:0.6b`. If it can't be pulled, project-brain falls back to `nomic-embed-text`. The structural tools work with **no** Ollama at all.
34
42
 
@@ -42,15 +50,44 @@ bun install -g project-brain
42
50
  npm install -g project-brain
43
51
  ```
44
52
 
45
- ### Standalone binary (no runtime required)
53
+ ### No package manager
54
+
55
+ The published binary is a `bun build --compile` artifact with the runtime, WASM grammars and templates embedded, so it needs no Node, no Bun, and nothing else at runtime.
56
+
57
+ ```bash
58
+ curl -fsSL https://raw.githubusercontent.com/jcsoftdev/project-brain/main/scripts/install.sh | sh
59
+ ```
60
+
61
+ Installs to `~/.local/bin` (override with `BRAIN_INSTALL_DIR`). Pin a version with `BRAIN_VERSION=v0.16.0`. To update, re-run it.
62
+
63
+ Apple Silicon, Linux x64 and Linux arm64 have published binaries. **Intel macOS does not** — the script says so instead of handing you an arm64 binary; use a registry install there.
64
+
65
+ ### Homebrew / Scoop
66
+
67
+ Each release attaches a generated `project-brain.rb` and `project-brain.json`, checksummed against the real assets. Once a tap and bucket exist:
68
+
69
+ ```bash
70
+ brew install jcsoftdev/tap/project-brain # macOS (Apple Silicon), Linux
71
+ scoop install project-brain # Windows
72
+ ```
73
+
74
+ Whichever channel you use, `project-brain update` reads the binary's own path to work out how it was installed and prints the right command — `brew upgrade`, `scoop update`, or the package manager's. For a channel it cannot drive it says so rather than guessing, because a guessed `npm install -g` would leave a second copy shadowing the first.
75
+
76
+ ### Build it yourself
46
77
 
47
78
  ```bash
48
79
  git clone https://github.com/jcsoftdev/project-brain
49
80
  cd project-brain
50
- bun build ./src/cli.ts --compile --outfile project-brain
81
+ bun build ./src/cli.ts ./src/parser/worker.ts --compile --outfile project-brain
51
82
  ./project-brain --help
52
83
  ```
53
84
 
85
+ `worker.ts` is a required second entrypoint — without it the parser's worker pool cannot resolve its own imports inside the compiled binary and silently extracts zero symbols.
86
+
87
+ ### Keeping the host skills current
88
+
89
+ Skills live in your assistant's global skills directory, not in the package, so upgrading the binary does not move them. project-brain compares the installed skill content against what the running binary carries and refreshes any directory it originally created — whichever way you upgraded. It never creates one (that is `setup`'s job) and never touches a directory it cannot prove it wrote. Opt out with `BRAIN_NO_SKILL_REFRESH=1`.
90
+
54
91
  ## Usage modes
55
92
 
56
93
  project-brain runs in two modes — CLI and inside AI tools. Both call the same underlying commands.
@@ -73,19 +110,20 @@ Once `project-brain setup` has registered the MCP server in your AI tool, you ca
73
110
 
74
111
  These five are thin wrappers over the CLI. **project-brain does not install them** — write them yourself as skills in your assistant's global skills directory if you want the shortcuts, or just run the CLI.
75
112
 
76
- ### `/brain-audit` — the one skill setup does install
113
+ ### Host skills setup installs
77
114
 
78
115
  | Skill | Equivalent CLI | What it does |
79
116
  |---|---|---|
80
117
  | `/brain-audit` | *(none — host skill)* | Whole-project audit: dead code, orphan UI, broken flows, coverage gaps, plus findings by severity across security, performance and architecture |
118
+ | `/brain-okf` | *(none — host skill)* | Write an OKF concept: the reasoning behind code, anchored to a verified symbol and checkable by `okf audit` |
81
119
 
82
- Unlike the `/brain-*` commands above, `brain-audit` has no CLI equivalent. It is a host skill: its logic lives in `SKILL.md` and runs inside the assistant, which calls project-brain's MCP tools to do the work. That is what lets it answer "is this export dead?" with `find_callers` instead of guessing from a grep.
120
+ Unlike the `/brain-*` commands above, these have no CLI equivalent. They are **host skills**: the logic lives in `SKILL.md` and runs inside the assistant, which calls project-brain's MCP tools to do the work. That is what lets `brain-audit` answer "is this export dead?" with `find_callers` instead of guessing from a grep, and what lets `brain-okf` verify an anchor with `find_symbol` before writing it.
83
121
 
84
- `project-brain setup` installs it into each registered tool's global skills directory (`~/.claude/skills/`, `~/.codex/skills/`, or the shared `~/.agents/skills/`). Opt out with `project-brain setup --no-brain-audit`.
122
+ `project-brain setup` installs them into each registered tool's global skills directory (`~/.claude/skills/`, `~/.codex/skills/`, or the shared `~/.agents/skills/`). Opt out with `project-brain setup --no-skills` (`--no-brain-audit` still works as an alias).
85
123
 
86
- It runs discovery first, proposes an audit module set from what it found, and **waits for you to confirm** before loading anything — 34 modules exist, and loading all of them every time is what makes an audit expensive.
124
+ **Both are offered, not scheduled.** Nothing invokes them for you and nothing fires on commit — you decide when. `brain-audit` runs discovery, proposes an audit module set, and waits for you to confirm before loading anything: 34 modules exist, and loading all of them every time is what makes an audit expensive. `brain-okf` proposes the type, title, and anchor and waits before creating a file, because whether an insight deserves a permanent home is your call, not the assistant's.
87
125
 
88
- Setup never overwrites a `brain-audit/` directory it did not create. If you have your own skill by that name, setup leaves it untouched and tells you.
126
+ Setup never overwrites a skill directory it did not create. Ownership is proven per directory, so your own hand-written `brain-okf/` is left untouched — and reported — while `brain-audit/` upgrades beside it.
89
127
 
90
128
  ## MCP Tools
91
129
 
@@ -239,12 +277,17 @@ project-brain code "chargeCard" --limit 5
239
277
  The index answers "what does this code do". It cannot answer "why is it like this", because that never existed in the AST. An **[Open Knowledge Format](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md) v0.2 bundle** — a committed directory of Markdown files with YAML frontmatter — holds that half, and `okf` keeps the two halves honest about each other.
240
278
 
241
279
  ```bash
280
+ project-brain okf init [dir] # scaffold an empty bundle. Never overwrites.
242
281
  project-brain okf validate [dir] # conformance (SPEC §11). Offline.
243
282
  project-brain okf sync [dir] # index the concepts so search returns them
244
283
  project-brain okf audit [dir] # cross-check the bundle against the code graph
245
284
  project-brain okf audit --symbol <name> # which concepts to re-read after <name> changes
246
285
  ```
247
286
 
287
+ `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.
288
+
289
+ 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.
290
+
248
291
  `dir` defaults to `./okf`. Because the bundle is tracked in git, a plain `project-brain sync` also keeps it fresh — bundle files are routed through the curated projection instead of being chunked as raw markdown, so `search_context` returns the reasoning next to the code it explains.
249
292
 
250
293
  A concept anchors code through `resource` (and `sources[]`), resolved from the bundle root:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-brain",
3
- "version": "0.16.1",
3
+ "version": "0.17.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.16.1",
53
- "project-brain-linux-x64": "0.16.1",
54
- "project-brain-linux-arm64": "0.16.1",
55
- "project-brain-windows-x64": "0.16.1",
56
- "project-brain-windows-arm64": "0.16.1"
52
+ "project-brain-darwin-arm64": "0.17.0",
53
+ "project-brain-linux-x64": "0.17.0",
54
+ "project-brain-linux-arm64": "0.17.0",
55
+ "project-brain-windows-x64": "0.17.0",
56
+ "project-brain-windows-arm64": "0.17.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/bun": "latest",
@@ -14,4 +14,4 @@ When answering questions about this codebase, run `search_context` first to find
14
14
 
15
15
  - **Project ID**: {{projectId}}
16
16
  - **Stack**: {{stack}}
17
- {{modules}}
17
+ {{modules}}{{okf}}
@@ -0,0 +1,157 @@
1
+ ---
2
+ name: brain-okf
3
+ description: "Trigger: write this down, capture why, record this decision, document this gotcha, add an OKF concept, knowledge bundle, why is it like this, save this for next time. Writes an Open Knowledge Format v0.2 concept — the reasoning behind code that no AST can hold — anchored to real symbols and validated against the code graph."
4
+ license: Apache-2.0
5
+ metadata:
6
+ author: jcsoftdev
7
+ version: "1.0"
8
+ generator: project-brain
9
+ ---
10
+
11
+ <!--
12
+ `generator: project-brain` is an ownership marker, not decoration.
13
+ `project-brain setup` overwrites this directory only when it finds that line;
14
+ without it, setup treats the directory as hand-written and leaves it alone.
15
+ Strip it and you pin this copy forever — no upgrade will ever reach it.
16
+ -->
17
+
18
+ ## Activation Contract
19
+
20
+ Apply when a **specific piece of reasoning** is worth keeping: a fix that surprised someone, a decision with a real rejected alternative, a constraint that must not be violated, a gotcha that cost time. The knowledge already exists in the conversation — this skill turns it into an anchored, auditable file.
21
+
22
+ **You are never required to invoke this.** It is offered, not scheduled. There is no hook, no per-commit trigger, and there should not be — see "Why this is not automated" below.
23
+
24
+ Do not apply when: the ask is "document this module" or "explain what this code does" (that is `conceptualize`, below); the project has no `okf/` bundle and the user has not asked to start one; or the insight is a restatement of the diff.
25
+
26
+ ### End of a task is a checkpoint, not a quota
27
+
28
+ A project whose CLAUDE.md carries the knowledge-bundle section is asking for one thing at the end of a piece of work: **decide whether anything belongs in the bundle.** Deciding is the whole obligation. Three things qualify:
29
+
30
+ - A fix whose **cause was surprising** — the symptom pointed somewhere else.
31
+ - A decision where a **real alternative was rejected**, and the reason is not obvious from the result.
32
+ - A **constraint** that must keep holding, where violating it breaks something non-locally.
33
+
34
+ **Most tasks produce nothing, and that is the expected answer.** Say so in one line and move on. A checkpoint that feels obliged to produce a file is a concept mill, and noise in a knowledge bundle is worse than gaps — it destroys the signal that made the bundle worth reading.
35
+
36
+ If a project has no bundle, `project-brain okf init` scaffolds an empty one and re-renders the project rules so the host learns it exists. Propose that; do not create it unasked.
37
+
38
+ ## Two knowledge layers — do not conflate them
39
+
40
+ | | `conceptualize` (already automatic) | OKF concept (this skill) |
41
+ |---|---|---|
42
+ | Runs | every commit, via the post-commit git hook | only when a human decides |
43
+ | Scope | a whole module | one specific insight |
44
+ | Answers | what this module does and how | **why it is like this** |
45
+ | Written by | an LLM from the commit diff | a human, or you with the human's confirmation |
46
+ | Anchored | no | yes — to a file, symbol, or line range |
47
+ | Audited | no | yes — broken anchors and staleness are CI-gateable |
48
+
49
+ If the answer lives in the diff, it is not a concept. `conceptualize` already has it.
50
+
51
+ ## Hard Rules
52
+
53
+ - **Propose before writing.** State the `type`, `title`, and the `resource` anchor you intend, and wait. The user decides whether the insight is worth a permanent file. Never create concepts unprompted or in bulk.
54
+ - **One insight per file.** A concept that needs two titles is two concepts.
55
+ - **The anchor must be verified, not guessed.** Run `find_symbol` on the symbol you plan to cite before writing it. An anchor that does not resolve is a `Broken anchor` finding the moment anyone runs `audit`.
56
+ - **Never invent the "how it was found".** If you did not observe the debugging, say the concept needs that section filled in by whoever did.
57
+ - Write for the reader who hits this in eight months with no context. Assume they know the language and nothing about this incident.
58
+ - Prose carries the value. The frontmatter is plumbing — do not spend the user's attention on YAML.
59
+
60
+ ## Why this is not automated
61
+
62
+ Three reasons, each worth knowing before someone proposes a hook again:
63
+
64
+ 1. **The input is not in the diff.** A concept comes from "this surprised me", which no diff contains. `conceptualize` works as a hook precisely because a diff *determines* module docs; nothing determines a concept.
65
+ 2. **The frequency does not match.** Concepts are rare — a mature bundle holds tens, not thousands. A per-commit trigger fires a hundred times per concept actually written, and an alert nobody acts on trains everyone to ignore alerts.
66
+ 3. **`audit`'s coverage gaps are NOT a work queue.** They rank by PageRank, which measures structural centrality, not explanatory need. On a real run the top of that list was `get`, `set`, `key`, `close`, `jsonResult`, `normalize` — cache accessors and formatters, every one of which has zero interesting *why*. Treat coverage gaps as a hint about *areas*, never as a list of files to generate.
67
+
68
+ ## File shape
69
+
70
+ Path: `okf/<type-pluralised>/<kebab-slug>.md`. Existing convention: `decisions/`, `gotchas/`, `constraints/`.
71
+
72
+ ```markdown
73
+ ---
74
+ type: Gotcha
75
+ title: Language.load ignores Bun's /$bunfs virtual filesystem
76
+ description: One line — the cost of not knowing this.
77
+ tags: [parser, bun, wasm]
78
+ resource: ../src/parser/wasm.ts
79
+ sources:
80
+ - resource: ../src/okf/audit.ts#findStale
81
+ title: Why this other file also matters
82
+ status: stable
83
+ generated: { by: "human:<handle>", at: 2026-07-30T00:00:00Z }
84
+ ---
85
+ ```
86
+
87
+ `validate` enforces exactly two things: a parseable frontmatter block, and a non-empty `type` (SPEC §11.1–11.2). The spec **forbids** rejecting a document for missing optional fields, and the `type` value is not constrained — the vocabulary is the bundle's convention, not a schema.
88
+
89
+ That means everything else is optional, and every optional field still earns its place:
90
+
91
+ | Field | What it buys |
92
+ |---|---|
93
+ | `resource` | The anchor. **Without it the concept is invisible to `audit`** — no broken-anchor check, no staleness check. This is what separates knowledge from a note. |
94
+ | `sources[]` | Additional anchors. Each one is watched independently. |
95
+ | `generated.at` | The staleness baseline. Absent, `audit` falls back to the concept file's own commit date. |
96
+ | `title` / `description` | How it reads in a list and in search results. |
97
+ | `tags` | Retrieval. |
98
+ | `status` | `stable`, or say it is provisional. |
99
+
100
+ ## Anchors
101
+
102
+ Three forms, least to most precise. Resolved **from the bundle root**, which is why they start with `../`:
103
+
104
+ ```yaml
105
+ resource: ../src/parser/wasm.ts # whole file
106
+ resource: ../src/hooks/git.ts#installGitHook # symbol — prefer this
107
+ resource: ../src/commands/sync.ts#L478-L499 # line range
108
+ ```
109
+
110
+ Choosing:
111
+
112
+ - **Symbol** is the default. It survives the file moving within itself, and `find_symbol` proves it exists.
113
+ - **Whole file** when the reasoning is about the file's role, not one function.
114
+ - **Line range** only when the point is a specific few lines with no symbol boundary. It is the most fragile form: a range claims only what fits inside it, and if the file shrinks past that range the anchor breaks — which is correct behaviour, not a bug. `audit` surfaces it rather than silently downgrading to "unknown".
115
+
116
+ Verify before writing. `find_symbol <name>` gives the path and line range; if it returns nothing, the anchor is wrong.
117
+
118
+ ## Body conventions
119
+
120
+ Free markdown — but these shapes are what makes the bundle readable as a set:
121
+
122
+ **Gotcha** — `# Symptom` (what a person actually sees, including the exact error text) → `# Why` (the mechanism) → `# Fix` (the code) → `# How it was found` (the procedure that isolated it — often the most reusable part).
123
+
124
+ **Decision** — `# Why <chosen>` → **the rejected alternative and what it cost**. A decision with no stated alternative is a description, and it cannot be revisited later because nobody knows what it traded against.
125
+
126
+ **Constraint** — what must hold, and **what breaks if it does not**. State the failure, not the rule.
127
+
128
+ Cross-link with bundle-root paths: `[title](/constraints/guards-must-be-seen-failing.md)`.
129
+
130
+ ## Flow
131
+
132
+ ```bash
133
+ project-brain okf validate # conformance, offline, no embeddings
134
+ project-brain okf sync # index the concepts so search returns them
135
+ project-brain okf audit # cross-check against the code graph
136
+ project-brain okf audit --symbol <name> # which concepts to re-read after <name> changes
137
+ ```
138
+
139
+ Run `validate` before finishing. A plain `project-brain sync` also keeps the bundle fresh, since it is tracked in git.
140
+
141
+ `audit` exits 1 on **broken anchors** and **stale concepts**, so it works as a CI gate. Coverage gaps and link suggestions are backlog and never fail the run.
142
+
143
+ ## Clearing a stale finding
144
+
145
+ A concept is stale when the cited code changed after the knowledge was last confirmed. The fix is not to edit the date — it is to **re-read the concept and confirm it still holds**, then record that:
146
+
147
+ ```yaml
148
+ verified:
149
+ - by: "human:<handle>"
150
+ at: 2026-07-30T00:00:00Z
151
+ ```
152
+
153
+ `verified[]` is a list, and the staleness baseline is the newest `at` across `generated` and every `verified` entry. Appending an entry also changes the file, so its own commit date moves — the finding clears either way. If the concept no longer holds, rewrite the prose instead; a `verified` stamp on wrong knowledge is worse than a stale flag.
154
+
155
+ ## Output Contract
156
+
157
+ When you write a concept, report: the path created, the `type` and `title`, every anchor and the symbol it resolved to, and the `validate` result. If any section was left for the user to fill in, say which and why.