project-brain 0.15.0 → 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.
Files changed (39) hide show
  1. package/README.md +100 -6
  2. package/package.json +7 -6
  3. package/templates/project.claude.md +1 -1
  4. package/templates/skills/brain-audit/SKILL.md +134 -0
  5. package/templates/skills/brain-audit/references/abuse.md +59 -0
  6. package/templates/skills/brain-audit/references/accessibility.md +55 -0
  7. package/templates/skills/brain-audit/references/ai.md +51 -0
  8. package/templates/skills/brain-audit/references/api.md +47 -0
  9. package/templates/skills/brain-audit/references/backend.md +48 -0
  10. package/templates/skills/brain-audit/references/complexity.md +52 -0
  11. package/templates/skills/brain-audit/references/concurrency.md +60 -0
  12. package/templates/skills/brain-audit/references/consistency.md +59 -0
  13. package/templates/skills/brain-audit/references/contract-drift.md +58 -0
  14. package/templates/skills/brain-audit/references/cost.md +60 -0
  15. package/templates/skills/brain-audit/references/database.md +59 -0
  16. package/templates/skills/brain-audit/references/dependencies-licensing.md +59 -0
  17. package/templates/skills/brain-audit/references/devops.md +61 -0
  18. package/templates/skills/brain-audit/references/documentation.md +56 -0
  19. package/templates/skills/brain-audit/references/failure.md +58 -0
  20. package/templates/skills/brain-audit/references/flow-integrity.md +61 -0
  21. package/templates/skills/brain-audit/references/frontend.md +51 -0
  22. package/templates/skills/brain-audit/references/functional.md +39 -0
  23. package/templates/skills/brain-audit/references/future.md +31 -0
  24. package/templates/skills/brain-audit/references/goal.md +38 -0
  25. package/templates/skills/brain-audit/references/i18n.md +61 -0
  26. package/templates/skills/brain-audit/references/infrastructure.md +62 -0
  27. package/templates/skills/brain-audit/references/mobile.md +58 -0
  28. package/templates/skills/brain-audit/references/observability.md +55 -0
  29. package/templates/skills/brain-audit/references/packaging.md +52 -0
  30. package/templates/skills/brain-audit/references/performance.md +58 -0
  31. package/templates/skills/brain-audit/references/privacy.md +63 -0
  32. package/templates/skills/brain-audit/references/product.md +34 -0
  33. package/templates/skills/brain-audit/references/prompt-spec-gap.md +41 -0
  34. package/templates/skills/brain-audit/references/reachability.md +58 -0
  35. package/templates/skills/brain-audit/references/scalability.md +55 -0
  36. package/templates/skills/brain-audit/references/security.md +75 -0
  37. package/templates/skills/brain-audit/references/testing.md +58 -0
  38. package/templates/skills/brain-audit/references/versioning-compatibility.md +59 -0
  39. package/templates/skills/brain-okf/SKILL.md +157 -0
@@ -0,0 +1,34 @@
1
+ # Product
2
+
3
+ Who is this for, and does the shape of the code agree? This module audits the product surface, not the implementation — a codebase can be technically excellent and still ship the wrong thing.
4
+
5
+ Start with `get_architecture` and `repo_map`. The highest-PageRank symbols are the product's real center of gravity; if they do not match what the README says the product is about, that gap is the finding.
6
+
7
+ ## Users and jobs
8
+
9
+ - [ ] The repo states who the user is. If no doc says it, infer it from the entry points and say you inferred it — that ambiguity is itself worth reporting.
10
+ - [ ] Each primary user job maps to a real, reachable code path. Trace one with `trace_path` from entry point to effect.
11
+ - [ ] Nothing in the codebase serves a user the docs never mention. Unexplained surface is either an undocumented feature or abandoned work.
12
+
13
+ ## Surface coherence
14
+
15
+ - [ ] One way to do each thing, or a stated reason for more than one. Three overlapping commands that half-solve the same job is a product defect before it is a code defect.
16
+ - [ ] Naming is consistent with the user's vocabulary, not the implementation's. A CLI flag named after an internal class leaks the model.
17
+ - [ ] Defaults serve the common case. Count how many flags a user must pass to do the most obvious thing — if it is more than zero, ask why.
18
+ - [ ] Error messages tell the user what to do next, not what went wrong internally.
19
+
20
+ ## Onboarding path
21
+
22
+ - [ ] There is a shortest path from install to first value, and it is documented. Follow it literally against the repo and note every step that is missing, wrong, or assumed.
23
+ - [ ] Prerequisites are stated before they are needed, not discovered by failure.
24
+ - [ ] The first-run experience handles the empty state — no data, no config, no index.
25
+
26
+ ## Feature economics
27
+
28
+ - [ ] For each feature, is there evidence anyone uses it? Cross-check with the `Reachability` module: a feature with no in-repo caller and no doc is a maintenance cost with no return.
29
+ - [ ] Features that exist only for one caller — worth reporting as candidates for inlining or removal.
30
+ - [ ] Configuration options that no code branches on. Same category.
31
+
32
+ ## Reporting
33
+
34
+ Product findings are the easiest to state as opinion and the hardest to defend. Anchor each one: a `file:line`, a missing doc section, or a traced path that dead-ends. If the only evidence is your judgement, mark the confidence low and say what would settle it.
@@ -0,0 +1,41 @@
1
+ # Prompt/Spec Gap
2
+
3
+ What would a reasonable request for this work have failed to ask for? This is the meta module: it audits the *instructions*, not the code. It exists because the most expensive omissions are the ones nobody thought to specify.
4
+
5
+ Run it last. It needs the findings from the other modules as raw material.
6
+
7
+ ## Reconstruct the implied ask
8
+
9
+ - [ ] For each significant subsystem, write the one-sentence request that would plausibly have produced it ("add project scoping to the structural tools").
10
+ - [ ] List what that sentence does **not** say but the implementation needed anyway: error handling, empty states, concurrency, cleanup, migration, observability, docs.
11
+ - [ ] Each gap that the code also missed is a finding. Each gap the code handled anyway is worth naming as a strength — it tells you where the team's instincts are good.
12
+
13
+ ## Dimensions a prompt routinely omits
14
+
15
+ Walk this list against the subsystem under audit. These are the categories that almost never appear in a request and almost always matter:
16
+
17
+ - [ ] **Failure** — what happens when the dependency is down, the disk is full, the token expired mid-operation.
18
+ - [ ] **Empty and boundary** — zero items, one item, maximum items, first run, nothing configured.
19
+ - [ ] **Concurrency** — two of these at once, the same operation twice, a partial run resumed.
20
+ - [ ] **Cleanup** — what removes what this created. Most requests say "add", none say "and remove".
21
+ - [ ] **Idempotency** — running it twice.
22
+ - [ ] **Migration** — what happens to state written by the previous version.
23
+ - [ ] **Observability** — how anyone would know this broke in production.
24
+ - [ ] **Test isolation** — whether running the tests touches anything outside the temp directory.
25
+ - [ ] **Ownership** — whether this writes to a path someone else owns.
26
+ - [ ] **Docs** — whether the thing that ships is discoverable by the person who needs it.
27
+
28
+ ## Spec vs. implementation drift
29
+
30
+ - [ ] Where written specs, plans, or ADRs exist, compare them to the code. Report both directions: spec'd and not built, built and not spec'd.
31
+ - [ ] Assertions in specs that no test enforces. A requirement with no test is a hope.
32
+ - [ ] Deviations that were the right call but never recorded. The code is correct and the document is now lying — that is a real finding, and the cheapest one to fix.
33
+
34
+ ## Output
35
+
36
+ Report this module as two lists, not as severities:
37
+
38
+ 1. **Gaps the implementation also missed** — these become findings in their proper module, cross-referenced here.
39
+ 2. **Gaps the implementation covered anyway** — these are not defects. State them, because they tell the reader which dimensions this team does not need reminding about, and which they do.
40
+
41
+ Then name the single dimension most likely to be omitted from the *next* request on this codebase, with the evidence that led you there.
@@ -0,0 +1,58 @@
1
+ # Reachability
2
+
3
+ Is this code reachable at all? This module runs on the call graph, so it answers with certainty where a grep-based auditor can only guess.
4
+
5
+ **Before reporting anything here as dead, rule out** — and state which you ruled out: public API surface, dynamic dispatch, reflection, string-keyed registries, framework-convention entry points (route files, migrations, plugin folders), test-only usage, and cross-repo consumers. `find_callers` returning empty means *no in-repo caller*, nothing more.
6
+
7
+ ## Dead exports
8
+
9
+ - [ ] For each exported symbol, `find_callers`. Empty ⇒ candidate. Cross-check against the exclusion list above before reporting.
10
+ - [ ] `impact` on each candidate to confirm the blast radius is genuinely zero — a symbol with no direct callers but a live transitive path is not dead.
11
+ - [ ] Whole modules whose every export is unreferenced. These are the cheap, high-value deletions.
12
+ - [ ] Types, interfaces, and enums declared and never referenced.
13
+
14
+ ## Dead endpoints
15
+
16
+ - [ ] Every server route / handler: does any client in the repo call it? `search_code` the path literal, then `trace_path` from the client call site to the handler.
17
+ - [ ] Routes registered but never mounted, or mounted behind a router nobody attaches.
18
+ - [ ] The inverse: a client calling a path that no handler serves. This is `High` — it fails in production, not at build.
19
+
20
+ ## Unreachable branches
21
+
22
+ - [ ] Conditions that cannot be true: checks after an early return, mutually exclusive guards, `if (x)` where `x` is a constant.
23
+ - [ ] Feature flags permanently off — flag read in code, default `false`, never set anywhere. The gated code is dead until someone flips it, and nobody remembers it exists.
24
+ - [ ] Environment variables read by code but set by no `.env.example`, no CI config, no Dockerfile, no docs. The fallback path is the only path that ever runs.
25
+ - [ ] Catch blocks for exceptions the try block cannot raise.
26
+
27
+ ## Declared but unused
28
+
29
+ Sweep each category and report the orphans:
30
+
31
+ - [ ] Assets — images, fonts, icons, static files referenced by nothing.
32
+ - [ ] i18n keys present in locale files, referenced by no call site (defer depth to the `i18n` module if it is in the confirmed set).
33
+ - [ ] Environment variables declared in `.env.example` / config schema, read by nothing.
34
+ - [ ] Config options accepted by the parser, consumed by nothing.
35
+ - [ ] Dependencies in the manifest, imported by nothing (defer licensing depth to `dependencies-licensing.md`).
36
+ - [ ] Database columns, indexes, and tables that no query touches.
37
+
38
+ ## Used but never declared — the inverse gap
39
+
40
+ **This is the check almost nobody runs, and it is where the expensive bugs hide.** The declared-but-unused direction wastes bytes; this direction breaks at runtime.
41
+
42
+ - [ ] Environment variables read in code but declared in no `.env.example`, schema, or deployment manifest. Works on the author's machine, `undefined` in production.
43
+ - [ ] i18n keys referenced by call sites but missing from one or more locale files — the missing locale renders the raw key to a user.
44
+ - [ ] Asset paths built at runtime (string concatenation, template literals) pointing at files that do not exist.
45
+ - [ ] Code reading a database column that no migration creates.
46
+ - [ ] Imports of packages absent from the manifest — resolved today only by a transitive hoist that the next lockfile update will remove.
47
+ - [ ] Config keys consumed by code but rejected or ignored by the config parser.
48
+
49
+ ## Severity guidance
50
+
51
+ | Situation | Severity |
52
+ |---|---|
53
+ | Client calls an endpoint that does not exist | Critical / High |
54
+ | Code reads an env var or column nothing provides | High |
55
+ | Feature flag permanently off, gating shipped code | Medium |
56
+ | Exported symbol with zero callers, exclusions ruled out | Medium |
57
+ | Unused asset, dependency, or locale key | Low |
58
+ | Declared-and-unused type or config option | Info / Low |
@@ -0,0 +1,55 @@
1
+ # Scalability
2
+
3
+ What breaks when there is more of everything? Gate: a queue, worker, or background jobs were detected.
4
+
5
+ `Performance` asks how fast one operation is. This module asks what happens at ten times the load, ten times the data, and two instances instead of one.
6
+
7
+ ## Horizontal readiness
8
+
9
+ - [ ] No state lives only in one process's memory. In-memory caches, counters, session maps, and rate-limit buckets all diverge across instances.
10
+ - [ ] Nothing depends on being the only instance. `search_code` for in-process locks, singletons holding mutable state, and interval timers — each one runs N times with N instances.
11
+ - [ ] Scheduled work has a leader election or a distributed lock. Otherwise every instance runs the cron.
12
+ - [ ] Local filesystem writes are either ephemeral or explicitly shared storage. A file written on one instance and read on another silently fails behind a load balancer.
13
+
14
+ ## Queues and workers
15
+
16
+ - [ ] Every queue has a consumer, and every consumer has a producer. Cross-reference the half-wired pairs table in `flow-integrity.md` — an unconsumed queue grows forever.
17
+ - [ ] Jobs are idempotent. At-least-once delivery is the norm, so a job that runs twice must be safe.
18
+ - [ ] Failed jobs go somewhere — a dead-letter queue, a retry with backoff, or an alert. Silent drop is the default failure mode and it is `High`.
19
+ - [ ] Retries are bounded. An infinite retry on a poison message blocks the queue.
20
+ - [ ] Job payloads carry identifiers, not whole objects. Fat payloads make the queue the database.
21
+ - [ ] Concurrency per consumer is bounded and configurable.
22
+
23
+ ## Data growth
24
+
25
+ - [ ] Every table, collection, log, and index has an answer to "what bounds this?" Unbounded growth with no retention policy is a finding even when it is slow.
26
+ - [ ] Queries that work today at current row counts — state the count at which each becomes a problem.
27
+ - [ ] Batch jobs that process everything rather than only what changed. These get slower every day by construction.
28
+ - [ ] Pagination is cursor-based where the dataset is large; offset pagination degrades linearly.
29
+
30
+ ## Backpressure
31
+
32
+ - [ ] Producers slow down or shed load when consumers fall behind. Unbounded buffering between them just moves the failure.
33
+ - [ ] Bounded pools exist for connections, workers, and concurrent outbound calls.
34
+ - [ ] Rate limits protect downstream dependencies, not only inbound callers.
35
+ - [ ] Timeouts are shorter than the caller's timeout, so failures surface at the right layer.
36
+
37
+ ## Degradation
38
+
39
+ - [ ] Under load the system degrades rather than collapsing — sheds optional work, serves stale cache, returns a clear 503.
40
+ - [ ] Non-critical work is genuinely non-blocking. A failing analytics call must not fail the request.
41
+ - [ ] Health checks reflect real capacity, not just process liveness.
42
+
43
+ ## Severity guidance
44
+
45
+ | Situation | Severity |
46
+ |---|---|
47
+ | Failed jobs silently dropped | High |
48
+ | In-memory state that breaks with a second instance | High |
49
+ | Unbounded retry on a poison message | High |
50
+ | Scheduled job with no leader election | High |
51
+ | Non-idempotent job under at-least-once delivery | High |
52
+ | No backpressure between producer and consumer | Medium |
53
+ | Unbounded data growth with no retention policy | Medium |
54
+ | Batch job that reprocesses everything | Medium |
55
+ | Offset pagination over a large dataset | Low |
@@ -0,0 +1,75 @@
1
+ # Security
2
+
3
+ Gate: auth, external input, or a network boundary was detected.
4
+
5
+ **Scope discipline.** This module finds and reports defects in the audited codebase. It does not write exploits, and it does not produce working attack payloads. A finding names the vulnerable line, the class of attack, and the fix.
6
+
7
+ Trace every input from where it enters to where it is used. `find_callees` from the entry point, or `trace_path` from the handler to the sink. An input that reaches a sink without passing validation is the finding.
8
+
9
+ ## Injection sinks
10
+
11
+ Enumerate the sinks, then check what reaches each one:
12
+
13
+ - [ ] **Query** — any query built by concatenation or interpolation from external input. Parameterised or nothing. `Critical`.
14
+ - [ ] **Shell** — `exec`, `spawn` with a shell, or a command string built from input. Prefer argument arrays with no shell.
15
+ - [ ] **Filesystem** — a path built from input. Check for `..` traversal and absolute-path override; the fix is resolve-then-verify-inside-root, not string filtering.
16
+ - [ ] **Code** — `eval`, `new Function`, dynamic `require`/`import` of an input-derived name, deserialisation of untrusted data.
17
+ - [ ] **Template/markup** — unescaped interpolation into HTML, `innerHTML`, `dangerouslySetInnerHTML`.
18
+ - [ ] **Model prompt** — untrusted text concatenated into instructions; see `abuse.md` and `ai.md`.
19
+
20
+ ## AuthN
21
+
22
+ - [ ] Credential comparison is constant-time. `search_code` for `===` against a token or secret.
23
+ - [ ] Passwords are hashed with a slow, salted algorithm — never a plain digest, never encrypted, never stored raw.
24
+ - [ ] Sessions and tokens expire, and expiry is checked with the correct comparison. An off-by-one on `<` vs `<=` at an expiry boundary is a real defect.
25
+ - [ ] Tokens are validated for signature, issuer, audience, and expiry — not merely decoded.
26
+ - [ ] Logout invalidates server-side, not only client-side.
27
+
28
+ ## AuthZ
29
+
30
+ - [ ] Every protected operation checks authorisation, and the check is on the server. `find_callers` on the authorisation helper, then compare against the full list of protected handlers — the gap is the finding.
31
+ - [ ] Authorisation is checked against the *resource*, not only the *route*. Being logged in is not permission to read record 42.
32
+ - [ ] No object reference from the client is trusted as ownership proof.
33
+ - [ ] Privilege escalation paths: can a user set their own role, quota, or flags through a mass-assigned update?
34
+ - [ ] Default is deny. A new endpoint added tomorrow should be closed unless opened.
35
+
36
+ ## Secrets
37
+
38
+ - [ ] No secret in source, config committed to the repo, test fixture, or log line. `search_code` for `secret`, `password`, `token`, `api_key`, `private_key`, `Bearer`.
39
+ - [ ] No secret in an error message, stack trace, or debug output.
40
+ - [ ] Secrets come from the environment or a secret manager, and absence fails loudly at startup.
41
+ - [ ] Check git history if a secret is found in the working tree — removal from HEAD does not remove it from history. Report the need for rotation.
42
+
43
+ ## Transport and headers
44
+
45
+ - [ ] TLS enforced; no plaintext transport for credentials or user data. No disabled certificate verification — `search_code` for `rejectUnauthorized: false` and equivalents.
46
+ - [ ] CORS is not permissive-with-credentials. A wildcard origin plus credentials is `High`.
47
+ - [ ] Cookies are `HttpOnly`, `Secure`, and have an appropriate `SameSite`.
48
+ - [ ] State-changing requests are protected against cross-site forgery where cookie auth is used.
49
+
50
+ ## Information disclosure
51
+
52
+ - [ ] No stack trace, internal path, dependency version, or query text reaches a client. Cross-reference `failure.md`.
53
+ - [ ] Error messages do not distinguish "no such user" from "wrong password".
54
+ - [ ] Directory listing, source maps, and debug endpoints are disabled in production.
55
+ - [ ] Logs do not contain credentials, tokens, or personal data — cross-reference `privacy.md`.
56
+
57
+ ## Dependencies
58
+
59
+ - [ ] Known-vulnerable dependencies. Report the advisory, not a guess. Cross-reference `dependencies-licensing.md`.
60
+ - [ ] Lockfile present and committed, so builds are reproducible.
61
+
62
+ ## Severity guidance
63
+
64
+ | Situation | Severity |
65
+ |---|---|
66
+ | Injection sink reachable from unvalidated external input | Critical |
67
+ | Missing authorisation on a protected operation | Critical |
68
+ | Secret committed to the repository | Critical |
69
+ | Password stored unhashed or reversibly | Critical |
70
+ | Certificate verification disabled | High |
71
+ | Authorisation checked on route but not on resource | High |
72
+ | Wildcard CORS with credentials | High |
73
+ | Non-constant-time secret comparison | Medium |
74
+ | Missing cookie security attributes | Medium |
75
+ | Internal detail disclosed in an error | Medium |
@@ -0,0 +1,58 @@
1
+ # Testing
2
+
3
+ Gate: test files are present **or conspicuously absent**. The absence case is the point — "this project has no tests" is a finding, not a reason to skip the module.
4
+
5
+ Coverage percentage is not the question. The question is: **which defects would this suite have caught?** Take the findings from the other modules and ask, for each, why no test failed.
6
+
7
+ ## Does the suite prove anything
8
+
9
+ - [ ] For each confirmed finding elsewhere in this audit, identify the missing test. That list is the most valuable output of this module.
10
+ - [ ] Tests assert behaviour, not implementation. A test that breaks on every refactor and passes through every real bug is negative value.
11
+ - [ ] Tests would fail if the feature broke. Try it mentally on the most important test: mutate the logic and ask whether an assertion catches it.
12
+ - [ ] No test asserts only that a function was called. Call-count assertions on a mock prove the test's own wiring.
13
+ - [ ] Assertions are specific — `toEqual` on a shape rather than `toBeDefined`, expected values rather than `expect.anything()`.
14
+
15
+ ## What is not covered
16
+
17
+ - [ ] Error paths. Most suites test only the happy path; cross-reference `failure.md` and check each error branch has a test.
18
+ - [ ] Boundaries: empty, one, many, maximum, negative, zero, unicode, very long.
19
+ - [ ] Concurrency. Tests run operations one at a time, which is why the defects in `concurrency.md` survive green suites. Note explicitly which are untestable as written.
20
+ - [ ] Idempotency and re-run paths.
21
+ - [ ] Migration and upgrade paths — reading state written by the previous version.
22
+ - [ ] The packaged artefact, as a consumer would use it. Cross-reference `packaging.md`: the suite runs from the repository where every file exists, which is exactly why it misses packaging bugs.
23
+
24
+ ## Test isolation
25
+
26
+ - [ ] **No test writes outside its own temporary directory.** Check for writes derived from the home directory, a global config path, or a shared data directory. A test that pollutes the developer's real environment is `High` — and it is easy to introduce accidentally when production code resolves paths from `homedir()`.
27
+ - [ ] Injection seams exist for anything that resolves a real path, spawns a process, or reaches the network — and the tests actually use them.
28
+ - [ ] Tests do not depend on execution order or on each other's leftovers.
29
+ - [ ] Each test cleans up on both the pass and the fail path.
30
+ - [ ] Nothing hits a real paid or external endpoint. Cross-reference `cost.md`.
31
+
32
+ ## Determinism
33
+
34
+ - [ ] No dependence on wall-clock time, current date, timezone, or locale without control.
35
+ - [ ] No dependence on unseeded randomness.
36
+ - [ ] No fixed sleeps standing in for synchronisation — that is a flake with a timer.
37
+ - [ ] No dependence on a fixed port, or ports are allocated dynamically. Fixed ports collide under parallel runs and in CI.
38
+ - [ ] **Known flaky tests are tracked, not tolerated.** A test that fails one run in ten is a real signal being discarded. Report each one with its observed failure rate.
39
+
40
+ ## Guard tests
41
+
42
+ - [ ] Where the codebase depends on two things agreeing — a manifest and a directory, a schema and a model, a gate table and a file set — a test asserts the agreement. Hand-maintained lists are fine; unguarded hand-maintained lists are not.
43
+ - [ ] **A guard nobody has watched fail is not a guard.** Verify each one by mutation: break the invariant deliberately, confirm the test fails, revert. Report guards that pass unconditionally.
44
+
45
+ ## Severity guidance
46
+
47
+ | Situation | Severity |
48
+ |---|---|
49
+ | No tests at all for correctness-critical logic | High |
50
+ | Test writes outside its temp directory into a real user path | High |
51
+ | Tests hitting real paid or external endpoints | High |
52
+ | A confirmed defect that the suite could have caught but does not | High |
53
+ | Guard test that cannot fail | Medium |
54
+ | Flaky test tolerated and untracked | Medium |
55
+ | No test for any error path | Medium |
56
+ | Fixed sleep standing in for synchronisation | Medium |
57
+ | Fixed port causing collisions under parallel runs | Medium |
58
+ | Tests asserting implementation rather than behaviour | Low |
@@ -0,0 +1,59 @@
1
+ # Versioning & Compatibility
2
+
3
+ Gate: a published package manifest or a release workflow was detected.
4
+
5
+ Every published thing has consumers you cannot see. This module asks whether a consumer who upgrades will survive it.
6
+
7
+ ## Public surface
8
+
9
+ - [ ] What is public is stated. Without a declared boundary, everything exported is public by accident and every internal rename is a breaking change.
10
+ - [ ] Internal-only exports are marked internal, or not exported. `find_callers` on each export — one with only in-repo callers is a candidate to unexport.
11
+ - [ ] Types and schemas that appear in public signatures are part of the contract, including their optional fields.
12
+ - [ ] Configuration keys, CLI flags, environment variables, and on-disk formats are public surface too. These are the ones teams forget.
13
+
14
+ ## Breaking-change discipline
15
+
16
+ - [ ] Version numbers follow a stated scheme, and breaking changes actually bump the breaking component. A major-version-zero project should say what its stability promise is.
17
+ - [ ] For each recent change to public surface, classify it: added (minor), fixed (patch), removed or narrowed (major). Report any misclassification.
18
+ - [ ] These are breaking even when they look small: narrowing an accepted input, adding a required parameter, changing a default, changing an error type, changing a return shape, renaming a config key, tightening validation.
19
+ - [ ] Behavioural breaks count, not only signature breaks. Same types, different meaning is worse — it compiles and misbehaves.
20
+
21
+ ## Deprecation
22
+
23
+ - [ ] Removals are preceded by a deprecation with a runtime warning and a stated replacement.
24
+ - [ ] Deprecations have a removal version, not just a label. Cross-reference `future.md`: an undated deprecation is kept forever.
25
+ - [ ] Both paths work during the overlap, and the old one is genuinely equivalent.
26
+ - [ ] Deprecation warnings are emitted once per process, not once per call.
27
+
28
+ ## Data and state compatibility
29
+
30
+ - [ ] Persisted formats carry a version field. Without one, the next reader must guess.
31
+ - [ ] The new version reads state written by the previous version. Test it, do not assume it.
32
+ - [ ] Forward compatibility is decided deliberately: does an older version encountering newer state fail loudly or corrupt quietly? Loudly is the only acceptable answer.
33
+ - [ ] Migrations of on-disk or cached state are idempotent and recoverable if interrupted.
34
+
35
+ ## Runtime and platform
36
+
37
+ - [ ] Declared engine and platform support matches what the code and dependencies actually require.
38
+ - [ ] Minimum supported versions are tested, not just declared. A CI matrix of one version supports one version.
39
+ - [ ] Newly used runtime APIs do not silently raise the real minimum below the declared one.
40
+
41
+ ## Communication
42
+
43
+ - [ ] Changes are recorded somewhere a consumer will find — changelog, release notes, or migration guide.
44
+ - [ ] Breaking changes state the migration, not just the fact.
45
+ - [ ] Entries correspond to real commits; a changelog nobody maintains is worse than none because it is trusted.
46
+
47
+ ## Severity guidance
48
+
49
+ | Situation | Severity |
50
+ |---|---|
51
+ | Breaking change shipped without a breaking version bump | High |
52
+ | Behavioural break with an unchanged signature | High |
53
+ | New version cannot read the previous version's persisted state | High |
54
+ | Persisted format with no version field | High |
55
+ | Removal with no prior deprecation | Medium |
56
+ | Deprecation with no removal version | Medium |
57
+ | Declared engine support wider than what the code requires | Medium |
58
+ | No declared public-surface boundary | Medium |
59
+ | Breaking change documented without a migration path | Low |
@@ -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.