Skip to content

Commit eef5aba

Browse files
committed
docs: reorganize per Diátaxis + add OSS root files
Three threads: 1. Drop `docs/spec-audit/` (internal scratch, no longer needed) + the in-source-code comment references to its fix-plan identifiers (the F-N markers stay; just the broken path pointers go). 2. Restructure `docs/` to follow the Diátaxis framework — the de-facto OSS doc standard (used by Django, Kubernetes, Numpy): docs/ ├── README.md # Navigation hub (new) ├── tutorials/ # Learning-oriented ├── guides/ # Task-oriented (install / configure / operate / upgrade / observability) ├── reference/ # Info-oriented (new; perf targets, error codes) ├── runbooks/ # Operator procedures (RB-1 … RB-11) └── development/ # Contributor-oriented (new bucket) ├── README.md ├── usage/ # Build + run + debug + test (was docs/usage/) ├── spec-deviations.md (was docs/spec-deviations.md) └── phases/ # Per-phase plans (was docs/phases/) Plus `monitoring/` at repo root (Grafana JSON dashboards + Alertmanager rules; was `docs/analytics/` — these are deployment assets, not docs). `docs/performance/README.md` collapsed into `docs/reference/performance.md`. 3. Add the OSS root files GitHub auto-surfaces: - `CONTRIBUTING.md` (new) — spec-first, plan-first workflow + invariants + anti-patterns. Points to `docs/development/` for the build / test / debug loop. - `SECURITY.md` (new) — disclosure policy + threat model. - `CODE_OF_CONDUCT.md` (new) — Contributor Covenant v2.1. Plus housekeeping: - `RELEASE-NOTES-v1.0.0.md` deleted (CHANGELOG.md has the same v1.0.0 entry; single source of truth). - All cross-references in non-historical files updated via `sed` to the new paths. `.claude/plans/` (historical record) left untouched. The 4 spec/*/0[78]_references.md files carry forward pointers to docs/phases/ — updated to docs/development/phases/ to keep them resolving. Verified: - `cargo zigbuild --target x86_64-unknown-linux-gnu --workspace` clean. - `cargo clippy --workspace --all-targets -- -D warnings` clean. - `bash scripts/spec-link-check.sh` shows only the 7 pre-existing spec-internal broken links (unchanged from before this commit; not introduced by the reorg).
1 parent e465573 commit eef5aba

93 files changed

Lines changed: 618 additions & 1592 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/commands/commit-task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Steps:
1010

1111
1. **Pre-commit verification.** Run `just verify` (or the equivalent `cargo` chain). If it fails, abort the commit and surface the failure — never commit red. Per `AUTONOMY.md` §2 rule 3.
1212

13-
2. **Identify the spec file(s) referenced** in the sub-task. From `docs/phases/phase-NN-*.md`, find the sub-task by ID. Extract the entries from its "Reads:" list.
13+
2. **Identify the spec file(s) referenced** in the sub-task. From `docs/development/phases/phase-NN-*.md`, find the sub-task by ID. Extract the entries from its "Reads:" list.
1414

1515
3. **Compose the commit message** in the format from `AUTONOMY.md` §5:
1616

.claude/commands/next-task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Algorithm:
1313
- If no `phase-*-complete` tag exists at all, active phase is **Phase 0** (verify scaffolding) or **Phase 1** (start wire protocol) depending on whether `just verify` passes.
1414

1515
2. **Open the relevant phase doc.**
16-
- `docs/phases/phase-NN-*.md` — the file matching the active phase.
16+
- `docs/development/phases/phase-NN-*.md` — the file matching the active phase.
1717
- For Phase 0, there is no detailed doc — the work is just `just verify` then tag.
1818

1919
3. **Find the lowest unfinished sub-task.**
@@ -29,7 +29,7 @@ Algorithm:
2929

3030
```
3131
Active phase: <N> — <Title>
32-
Phase doc: docs/phases/phase-NN-*.md
32+
Phase doc: docs/development/phases/phase-NN-*.md
3333
3434
Next sub-task: <task-id> — <title>
3535

.claude/commands/status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Steps:
1414

1515
2. **Active phase**
1616
- The lowest-numbered phase that does NOT have a `phase-N-complete` tag is the active phase.
17-
- Open `docs/phases/phase-NN-*.md` for that phase.
17+
- Open `docs/development/phases/phase-NN-*.md` for that phase.
1818
- Count `[x]` vs `[ ]` checkboxes in sub-task headers and the phase exit checklist.
1919

2020
3. **Next sub-task**

AUTONOMY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LOOP:
1515
1. Read current state:
1616
- git status, git log -5
1717
- last commit's tag (phase-N-task-M-complete or similar)
18-
- check ROADMAP.md and the active docs/phases/phase-NN-*.md
18+
- check ROADMAP.md and the active docs/development/phases/phase-NN-*.md
1919
2020
2. Decide the next sub-task:
2121
- The lowest-numbered sub-task in the current phase that isn't ✓ done
@@ -411,7 +411,7 @@ This is not a "legacy mode" or "compatibility mode" — it is a real v1.0 deploy
411411

412412
### Phase progression for knowledge layer
413413

414-
Phases 16–22 may partially overlap once 15 is done (see DAG in `docs/phases/README.md`). Phase 23 strictly requires 17, 21, 22. Phase 24 is final.
414+
Phases 16–22 may partially overlap once 15 is done (see DAG in `docs/development/phases/README.md`). Phase 23 strictly requires 17, 21, 22. Phase 24 is final.
415415

416416
After each knowledge-layer phase:
417417
- Run that phase's tests.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ operator runbook; full acceptance suite.
4040
**Known limitations** — see
4141
`spec/30_knowledge_open_questions/00_purpose.md` for OQ-23-A
4242
through OQ-23-E and the v2 deferrals. Phase-24 v1 scope cuts
43-
documented in `docs/phases/phase-24-acceptance.md`.
43+
documented in `docs/development/phases/phase-24-acceptance.md`.
4444

4545
Tags: `v0.9.0-substrate-rc` (substrate gate), `phase-24-complete`
4646
+ `v1.0.0` (this release).

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The full directory map is in [`spec/00_master_overview/02_doc_map.md`](spec/00_m
5656
The roadmap is in three layers:
5757

5858
1. **[`ROADMAP.md`](ROADMAP.md)** — high-level phase index. One-line per phase.
59-
2. **[`docs/phases/phase-NN-*.md`](docs/phases/)** — detailed sub-task breakdown for each phase. Reads, writes, "done when" criteria.
59+
2. **[`docs/development/phases/phase-NN-*.md`](docs/development/phases/)** — detailed sub-task breakdown for each phase. Reads, writes, "done when" criteria.
6060
3. **[`AUTONOMY.md`](AUTONOMY.md)** — operating rules (commit format, stop conditions, scope guards).
6161

6262
When asked "what's next?", the answer is always: the lowest-numbered unfinished sub-task in the active phase doc.
@@ -221,7 +221,7 @@ If running for the first time on a fresh checkout:
221221
2. `just verify` — confirm Phase 0 passes.
222222
3. If green: `git tag phase-0-complete` (if not already tagged).
223223
4. Read [`AUTONOMY.md`](AUTONOMY.md) end-to-end.
224-
5. Read the relevant phase doc (`docs/phases/phase-NN-*.md`) end-to-end.
224+
5. Read the relevant phase doc (`docs/development/phases/phase-NN-*.md`) end-to-end.
225225
6. Begin sub-task 1.1 (or current).
226226

227227
## 15. When in doubt

CODE_OF_CONDUCT.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Code of Conduct
2+
3+
Brain follows the
4+
[Contributor Covenant v2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/).
5+
6+
## Our pledge
7+
8+
We pledge to make participation in our project and community a
9+
harassment-free experience for everyone, regardless of age,
10+
body size, visible or invisible disability, ethnicity, sex
11+
characteristics, gender identity and expression, level of
12+
experience, education, socio-economic status, nationality,
13+
personal appearance, race, religion, or sexual identity and
14+
orientation.
15+
16+
## Our standards
17+
18+
Examples of behaviour that contributes to a positive
19+
environment:
20+
21+
- Demonstrating empathy and kindness toward other people.
22+
- Being respectful of differing opinions, viewpoints, and
23+
experiences.
24+
- Giving and gracefully accepting constructive feedback.
25+
- Accepting responsibility and apologising to those affected
26+
by our mistakes, and learning from the experience.
27+
- Focusing on what is best for the overall community.
28+
29+
Examples of unacceptable behaviour:
30+
31+
- Sexualised language or imagery, and sexual attention or
32+
advances of any kind.
33+
- Trolling, insulting or derogatory comments, and personal or
34+
political attacks.
35+
- Public or private harassment.
36+
- Publishing others' private information, such as a physical
37+
or email address, without their explicit permission.
38+
- Other conduct which could reasonably be considered
39+
inappropriate in a professional setting.
40+
41+
## Enforcement
42+
43+
Instances of abusive, harassing, or otherwise unacceptable
44+
behaviour may be reported to the maintainer at the contact
45+
listed on the GitHub profile, or via GitHub's
46+
[abuse-report flow](https://docs.github.com/en/communities/maintaining-your-safety-on-github/reporting-abuse-or-spam).
47+
48+
All complaints will be reviewed and investigated promptly and
49+
fairly. Maintainers are obligated to respect the privacy and
50+
security of the reporter of any incident.
51+
52+
## Scope
53+
54+
This Code of Conduct applies within all community spaces
55+
(GitHub issues, pull requests, discussions, and any
56+
project-affiliated channel), and also when an individual is
57+
officially representing the community in public spaces.
58+
59+
## Attribution
60+
61+
This Code of Conduct is adapted from the
62+
[Contributor Covenant](https://www.contributor-covenant.org/),
63+
version 2.1, available at
64+
<https://www.contributor-covenant.org/version/2/1/code_of_conduct.html>.

CONTRIBUTING.md

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Contributing to Brain
2+
3+
Thanks for considering a contribution. Brain has strong design
4+
constraints — read this end-to-end before you start.
5+
6+
## TL;DR
7+
8+
1. The [spec](spec/) is authoritative. Code disagreements get
9+
fixed in the code, not the spec. Spec changes go through
10+
the maintainer.
11+
2. Every sub-task: **read the spec → read the phase doc → write
12+
a plan in `.claude/plans/phase-NN-task-MM.md` → wait for
13+
approval → implement → verify → commit**.
14+
3. No `unwrap()` outside tests. Use `expect("invariant:
15+
<reason>")` for unreachable.
16+
4. Run `just verify` (or `cargo zigbuild --target
17+
x86_64-unknown-linux-gnu --workspace --tests` on macOS)
18+
before opening a PR.
19+
20+
See [`AUTONOMY.md`](AUTONOMY.md) for the full operating
21+
contract Brain's autonomous mode runs under — much of it
22+
applies to human contributors too.
23+
24+
## Architecture in one paragraph
25+
26+
Linux server. Connection layer (Tokio) accepts TCP; each
27+
request dispatches to one of N **shards**. Each shard runs a
28+
**Glommio** executor (thread-per-core, io_uring) and owns its
29+
data: a memory-mapped **arena** for vectors, a **WAL** with
30+
O_DIRECT + `pwritev2(RWF_DSYNC)` group commit, a **redb**
31+
B-tree for metadata, an **HNSW** index in RAM.
32+
Single-writer-per-shard, lock-free reads via
33+
**ArcSwap** + **crossbeam-epoch**. When a schema is declared,
34+
the same shard additionally owns entity / statement HNSWs,
35+
two **tantivy** indexes, an LLM extractor cache, and runs the
36+
three-tier extractor pipeline.
37+
38+
## Where to start reading
39+
40+
- [`README.md`](README.md) — what Brain is + capability tour.
41+
- [`spec/00_master_overview/`](spec/00_master_overview/) — design
42+
start.
43+
- [`ROADMAP.md`](ROADMAP.md) — phase index.
44+
- [`CLAUDE.md`](CLAUDE.md) — operating rules + invariants.
45+
- [`docs/development/`](docs/development/) — contributor
46+
workflow.
47+
48+
## Core invariants — DO NOT violate
49+
50+
Code that violates these is wrong regardless of test results:
51+
52+
1. **WAL-before-acknowledge.** No operation returns success
53+
until its WAL record is fsynced.
54+
2. **Single writer per shard.** No locks needed; the discipline
55+
enforces it.
56+
3. **CRC everywhere.** Every WAL record + arena slot.
57+
4. **Slot version on `MemoryId`.** Stale references →
58+
`NotFound`.
59+
5. **Idempotency by `RequestId`.** 24h TTL. Same params →
60+
cached response. Different params → `Conflict`.
61+
6. **Tombstone grace before reclamation.** Default 7 days. Hard
62+
FORGET zeroes immediately.
63+
7. **No silent corruption.** Fail-stop and alert.
64+
65+
## Anti-patterns
66+
67+
- Don't add Tokio inside a shard. Shards use Glommio.
68+
- Don't hold a lock across `.await`.
69+
- Don't allocate in the hot path (encode/recall serving).
70+
- Don't add `Send + Sync` to per-shard types.
71+
- Don't use `tokio::fs` in shard code.
72+
- Don't introduce a thread pool for parallel work. Sharding is
73+
the parallelism.
74+
- Don't trust user input. All wire input is untrusted.
75+
- Don't `panic!` on user-input errors.
76+
77+
## Workflow
78+
79+
### 1. Pick a sub-task
80+
81+
The lowest-numbered unfinished sub-task in the active phase
82+
doc. Use `/next-task` if you're in Claude Code.
83+
84+
### 2. Read the spec
85+
86+
The spec section that section governs the work. Don't infer
87+
from the code if the spec covers it — read the spec.
88+
89+
### 3. Plan
90+
91+
Write `.claude/plans/phase-NN-task-MM.md` with:
92+
- Scope.
93+
- Spec references.
94+
- Architecture sketch.
95+
- Trade-offs considered.
96+
- Risks / open questions.
97+
- Test plan.
98+
- Commit shape.
99+
- Confirmation questions.
100+
101+
Wait for approval before coding. This isn't ceremony — most
102+
mistakes are caught at the plan step.
103+
104+
### 4. Implement
105+
106+
Follow the plan. Deviations go back through plan → approval.
107+
108+
### 5. Verify
109+
110+
```bash
111+
just verify
112+
# or, on macOS:
113+
cargo zigbuild --target x86_64-unknown-linux-gnu --workspace --tests
114+
cargo clippy --workspace --all-targets -- -D warnings
115+
cargo fmt --check
116+
```
117+
118+
### 6. Commit
119+
120+
One commit per sub-task. Commit subject:
121+
122+
```
123+
<type>(<scope>): <NN.MM> — <summary>
124+
```
125+
126+
Types: `feat`, `fix`, `refactor`, `test`, `docs`, `chore`,
127+
`perf`.
128+
129+
**Never** add a `Co-Authored-By: Claude` trailer. The user is
130+
the sole author of these commits.
131+
132+
## Code conventions
133+
134+
- Edition: Rust 2021. MSRV: stable latest minus one.
135+
- Errors: `thiserror` for libs; `anyhow` for binaries. Stable
136+
error taxonomy per spec §03/10.
137+
- No `unwrap()` outside tests. Use `expect("invariant:
138+
<reason>")` for unreachable.
139+
- Public APIs: rustdoc + at least one example for non-trivial.
140+
- No `unsafe` outside `crates/brain-storage`. That crate needs
141+
it for mmap. Every `unsafe` block: `// SAFETY:` comment,
142+
smallest scope.
143+
- Formatting: rustfmt defaults.
144+
- Lints: clippy default warnings as errors in CI. Pedantic is
145+
aspirational; not enforced on stubs.
146+
- Naming: snake_case items, CamelCase types — Rust standard.
147+
148+
## Testing
149+
150+
- Unit tests colocated.
151+
- Integration tests in `tests/` per crate.
152+
- Property tests with `proptest` for parsers, allocators,
153+
recovery.
154+
- Fuzz with `cargo-fuzz` for the wire protocol.
155+
- Loom for concurrency-critical paths.
156+
- Miri for `crates/brain-storage`'s unsafe.
157+
- Chaos tests for recovery (kill-during-operation).
158+
- Benchmarks with `criterion` per phase.
159+
160+
New behaviour → new test. Spec change → corresponding test
161+
change.
162+
163+
## Reporting bugs / security issues
164+
165+
- Functional bugs: open a GitHub issue with a reproducer.
166+
- Security issues: see [`SECURITY.md`](SECURITY.md).
167+
168+
## License
169+
170+
By contributing, you agree your contribution is licensed under
171+
the project's [Apache 2.0 license](LICENSE).

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ When a schema is declared, the substrate exposes typed cognition. Three layers,
187187
| `0x60–0x6F` | Query | QUERY (hybrid), QUERY_EXPLAIN, QUERY_TRACE, RECALL_HYBRID |
188188
| `0x70–0x7F` | Admin | ADMIN_BACKFILL, ADMIN_LIST_PENDING_RESOLUTIONS, ADMIN_LIST_STALE_STATEMENTS |
189189

190-
**End-to-end** ([`docs/usage/practical-guide.md`](docs/usage/practical-guide.md) walks through this in full):
190+
**End-to-end** ([`docs/development/usage/practical-guide.md`](docs/development/usage/practical-guide.md) walks through this in full):
191191

192192
```
193193
ENCODE "Priya kicked off the billing rewrite today."
@@ -512,9 +512,9 @@ Activates when a schema is declared. Substrate-only deployments are unaffected.
512512
| 23 | Hybrid query engine (router, RRF fusion, filter chain, EXPLAIN/TRACE) | planned |
513513
| 24 | Sweepers, knowledge acceptance & `v1.0.0` | planned |
514514

515-
See [`ROADMAP.md`](ROADMAP.md) for the phase index and [`docs/phases/`](docs/phases/) for per-phase sub-task breakdowns. The dependency DAG for the knowledge-layer phases lives in [`docs/phases/README.md`](docs/phases/README.md).
515+
See [`ROADMAP.md`](ROADMAP.md) for the phase index and [`docs/development/phases/`](docs/development/phases/) for per-phase sub-task breakdowns. The dependency DAG for the knowledge-layer phases lives in [`docs/development/phases/README.md`](docs/development/phases/README.md).
516516

517-
For a hands-on walkthrough of every feature in context (substrate primitives, schema declaration, extractors, hybrid query, FORGET cascade), see [`docs/usage/practical-guide.md`](docs/usage/practical-guide.md).
517+
For a hands-on walkthrough of every feature in context (substrate primitives, schema declaration, extractors, hybrid query, FORGET cascade), see [`docs/development/usage/practical-guide.md`](docs/development/usage/practical-guide.md).
518518

519519
## Development environment
520520

@@ -597,7 +597,7 @@ cargo +nightly fuzz run protocol_frame -- -max_total_time=60 # nightly + Li
597597
just shell # enter the dev container (Docker required)
598598
```
599599

600-
A step-by-step setup, CLI tour, SDK tour, and troubleshooting walkthrough lives under [`docs/usage/`](docs/usage/).
600+
A step-by-step setup, CLI tour, SDK tour, and troubleshooting walkthrough lives under [`docs/development/usage/`](docs/development/usage/).
601601

602602
### When something doesn't work
603603

@@ -616,14 +616,17 @@ brain/
616616
│ ├── Dockerfile
617617
│ ├── devcontainer.json
618618
│ └── post-create.sh
619-
├── docs/
620-
│ ├── phases/ # Per-phase detailed sub-task plans (0–24)
621-
│ ├── usage/ # Setup + CLI + SDK + walkthrough + troubleshooting
622-
│ ├── guides/ # Operator guides (observability, …)
623-
│ ├── analytics/ # Reference Grafana dashboards + Alertmanager rules
624-
│ ├── runbooks/ # Operational runbooks
625-
│ ├── spec-audit/ # Per-section spec ↔ impl audit pages
626-
│ └── spec-deviations.md # Recorded conscious deviations from the spec
619+
├── docs/ # See docs/README.md for navigation
620+
│ ├── README.md # Navigation hub (Diátaxis-shaped)
621+
│ ├── tutorials/ # Learning-oriented (getting started)
622+
│ ├── guides/ # Task-oriented (install, configure, operate, upgrade, observability)
623+
│ ├── reference/ # Info-oriented (perf targets, error codes)
624+
│ ├── runbooks/ # Operator procedures (RB-1 … RB-11)
625+
│ └── development/ # Contributor-oriented
626+
│ ├── usage/ # Build + run + debug + test workflow
627+
│ ├── spec-deviations.md # Recorded conscious deviations from the spec
628+
│ └── phases/ # Per-phase plans (0–24); dev history
629+
├── monitoring/ # Deployment assets (Grafana dashboards + Alertmanager rules)
627630
├── spec/ # The 32-section specification (read-only)
628631
│ ├── 00_master_overview/ # Substrate (§00–§16)
629632
│ ├── 01_system_architecture/

0 commit comments

Comments
 (0)