@tomasznowak-dev/sdd-brain
v1.0.0
Published
Deterministic CLI for a spec-driven-development knowledge base (.context): local index, checksum-based drift detection, search and integrity repair for agents and humans.
Maintainers
Readme
sdd-brain
Deterministic CLI for a spec-driven-development knowledge base kept in .context/:
research, plans, implementations, lessons and improvement suggestions that agents and developers
accumulate while working on a project.
- Cheap lookups.
searchandgetreturn a few hundred tokens instead of a whole markdown index. - No merge conflicts. The index (
.context/index.json) is local, git-ignored and rebuilt by git hooks. Only per-artifact files are committed. - Drift detection. Every artifact records checksums of the files (and optionally functions or methods) it
documents. The CLI tells you right away whether the code still matches:
fresh,stale,missingorunverified. - Integrity repair. A deterministic worklist plus a step-by-step loop for an agent.
- Works for agents and humans. Zero runtime dependencies, Node ≥ 20, Windows, Linux and macOS.
Install
npm i -D @tomasznowak-dev/sdd-brain
npx sdd-brain initinit is safe to run repeatedly. It:
- Creates
.context/{research,plans,implementations,lessons,improvement-suggestions}. - Brownfield: if
.contextalready exists, it backs it up to.context/.backups/context-<timestamp>.tar.gzand migrates legacyshort.md,INDEX.mdand single-file suggestions tometa.json. Baseline checksums come from git history, taken at the commit that last touched each artifact. - Adds
.context/index.json,.context/.config,.context/.cache/and.context/.backups/to.gitignore. - Installs git hooks (
post-checkout,post-merge,post-rewrite,pre-commit). It detects husky, lefthook andcore.hooksPath, and appends between# sdd-brain start/endmarkers without overwriting your scripts. - Adds
sdd-brain hooks installto the project'spreparescript, so teammates get the hooks onnpm install. - Writes the agent procedure: a block in
AGENTS.md(Codex, Cursor, Copilot, Devin…), an import inCLAUDE.mdand the Claude Code skill.claude/skills/sdd-brain/SKILL.md.
Options: --language <code>, --no-hooks, --no-agents, --no-prepare.
Knowledge-base language
Agents write in English by default unless told otherwise. init therefore sets the language of the knowledge
base, and the file structure stays the same. Only the instructions change:
npx sdd-brain init --language pl(codes such aspl,en,de, or names likepolski,German;auto= the language of each artifact / conversation).- Without the flag, brownfield projects get the language detected from the existing
.context, greenfield projects getauto. - The language is stored in
.context/.configand written into the committedAGENTS.mdblock, so every teammate's agent sees the same rule. It is also passed tohelp agent,help summariesand the summarizer subagent. - To change it later, run
init --language <code>again. It only rewrites the managed blocks.
Layout
.context/
<category>/<key>/full.md # content (markdown)
<category>/<key>/meta.json # metadata + checksums – written by the CLI only
index.json # local index (git-ignored)
.config # local settings (git-ignored)Artifact id = <category>/<key>, e.g. plans/custom-fields. The same key across categories forms a chain
(research → plan → implementation → lesson).
meta.json:
{
"schema": 1,
"id": "implementations/jwt-removal",
"title": "Remove JWT",
"status": "active",
"lifecycle": null,
"summary": "≤200 characters – shown in search results",
"description": "≤1000 characters – shown by get",
"full": "full.md",
"created": "2026-08-07",
"updated": "2026-08-07",
"branch": "feature/x",
"files": [
{ "path": "src/Api/Api.php", "hash": "a1b2c3d4e5f60718", "commit": "<HEAD when hashed>",
"symbols": [{ "name": "Api::init_jwt_stub", "hash": "…" }] }
],
"refs": ["plans/jwt-removal"]
}status:active|archived(code described is gone or superseded;statusNotesays why).lifecycle(suggestions only):new|in-progress|completed|descoped.- Checksums: SHA-256 of the content with the BOM stripped and CRLF/CR converted to LF, so Windows and Linux produce the same value. Shortened to 16 hex characters.
- Research and implementation artifacts must record checksums. Plans list files without checksums. Lessons and suggestions may record them.
Commands
| Command | Purpose |
|---|---|
| search <phrase> [-c category] [-s active\|archived\|all] [-n N] [--json] | Ranked results: id \| status \| freshness \| summary |
| get <id>… [--full] [--json] | Description, files with freshness (stale symbols), refs, chain |
| which <file>… | Artifacts that document a file |
| verify <id>… \| --all [--exit-code] | Per-file and per-symbol checksum comparison |
| new <category> <key> --summary … [--title] [--description] [--file] | Create an artifact from a template |
| meta add-file <id> <file> [--symbol S…] [--no-hash] | Track code; the CLI computes the checksums |
| meta remove-file <id> <file> | Untrack code |
| meta refresh <id> [--files …] [--drop-missing] | Re-checksum changed code, re-read refs from full.md, bump updated |
| meta set <id> [--summary] [--description] [--title] [--status] [--note] [--lifecycle] [--branch] [--reviewed <flag\|all>] | Validated metadata edits; setting summary/description clears its review flag. Only status/lifecycle changes bump updated |
| meta set-many [--file f] | Batch summary/description/title from JSON Lines on stdin (no shell quoting issues) |
| hash <file> [--symbol S] [--list] \| --stdin | Raw checksums; --list shows detectable symbols |
| index [--force] | Rebuild the local index (hooks do this automatically) |
| migrate [--dry-run] [--keep-short] [--no-backup] | Convert a legacy .context |
| repair [list] \| next \| done <id> [--force] \| skip <id> \| reset + [--only <kind>] [--batch N] | Integrity worklist and agent loop |
| check [--strict] [--json] | Validate all meta.json files (exit code 1 on errors – use in CI) |
| hooks install \| uninstall \| status | Manage git hooks |
| precommit | Non-blocking warning for staged code whose artifacts were not updated |
| stats [--export file] [--json] [--reset] | Estimated token savings |
| help agent | The agent procedure (same content as the skill) |
| help summaries | Self-contained instructions for a light model rewriting summaries |
Global option: --root <dir> (defaults to the git root of the current directory).
Symbols
Symbol names look like Class::method, Class.method, Outer::Inner::method, function or Class.
Extraction is heuristic and dependency-free: strings and comments are masked, container blocks
(class / interface / trait / enum / struct / namespace / impl / object literal) are located, and the
member's body is matched by braces. The preceding docblock, attributes and decorators are included.
Supported: PHP, JS/TS, Java, C#, Kotlin, Go (receiver methods), Rust (impl), C/C++, Swift, Dart, Scala and
Python (by indentation). Unknown names are reported as unresolved, duplicates as ambiguous.
Freshness
| State | Meaning |
|---|---|
| fresh | All recorded checksums match the current code |
| stale | At least one file changed since the artifact was written; get and verify show which symbols |
| missing | A recorded file no longer exists (repair fixes renames with identical content automatically) |
| unverified | No baseline checksum (e.g. migrated without git history) |
| n/a | Nothing to compare (plans, artifacts without files) |
Typical agent workflow
npx sdd-brain search "taxonomy" # 1. find candidates
npx sdd-brain get research/how-to-add-taxonomy
# read full.md only if active and relevant; stale → verify against the code
npx sdd-brain which src/Taxonomy.php # 2. before editing a file
npx sdd-brain new implementation add-taxonomy --summary "…" # 3. leave knowledge behind
npx sdd-brain meta add-file implementations/add-taxonomy src/Taxonomy.php --symbol Taxonomy::register
npx sdd-brain meta refresh implementations/add-taxonomyIntegrity pass:
npx sdd-brain repair # worklist
npx sdd-brain repair next # one item with exact steps
npx sdd-brain repair done <id>Summaries after a migration
Summaries produced by migrate are mechanical excerpts of the old short.md (first sentences), so every
migrated artifact is flagged review: summary. Writing a real summary needs understanding but no code, which makes it
a good job for a light model (Haiku-class):
- Claude Code:
initinstalls the subagent.claude/agents/sdd-brain-summarizer.md(model: haiku). - Any other tool: give a cheap model the output of
npx sdd-brain help summaries.
The light model loops over sdd-brain repair next --only summary --batch 10 (title, status, current summary and
description per item) and saves each batch in one call:
npx sdd-brain meta set-many <<'EOF'
{"id": "research/example", "summary": "…"}
{"id": "plans/example", "summary": "…"}
EOFExpect roughly 400 input + 60 output tokens per artifact.
Configuration (.context/.config, local)
{
"language": "pl",
"searchLimit": 15,
"searchAttempts": 3,
"summaryMax": 200,
"descriptionMax": 1000,
"titleMax": 120,
"telemetry": true,
"precommitWarnings": true,
"subagent": { "enabled": false, "model": "haiku" }
}language, searchAttempts and subagent are instructions for agents (printed by help agent). The CLI itself never calls a model.
Telemetry
search, get, which, verify and repair append {cmd, outBytes, baselineBytes} to
.context/.cache/telemetry.jsonl. The baseline estimates what an agent would have read without the tool
(a legacy markdown index, artifact files, code). sdd-brain stats shows the estimate (tokens ≈ bytes / 4).
Nothing ever leaves the machine.
License
MIT
