kb

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT

README

kb

Zero-DB, git-anchored project memory for AI coding agents.

Stop CLAUDE.md and AGENTS.md from rotting. Keep living domain specs in plain Git-tracked Markdown, catch spec-to-code drift via Git, isolate old postmortems, and aggregate multi-repo workspaces — in a single static Go binary.

CI Go Reference Release llms.txt

English · Русская документация · llms.txt



Install in 10 Seconds

# macOS & Linux — interactive TUI installer (downloads verified release binary)
curl -fsSL https://raw.githubusercontent.com/mdwitr0/kb/main/install.sh | bash

# Homebrew (macOS & Linux)
brew install mdwitr0/tap/kb && kb setup

# Go toolchain
go install github.com/mdwitr0/kb/cmd/kb@latest && kb setup

# Agent Skills registry (skills.sh)
npx skills add mdwitr0/kb

Headless install for dotfiles, Dockerfiles, or CI:

curl -fsSL https://raw.githubusercontent.com/mdwitr0/kb/main/install.sh | bash -s -- --yes --lang en

Sound Familiar?

Every team using Claude Code, Codex, Cursor, OpenCode, Windsurf, or Pi hits the same four walls after a few weeks:

  1. The 2,000-line CLAUDE.md / AGENTS.md graveyard. Every bug adds another warning. Nobody deletes obsolete rules. Half your context budget disappears before the agent reads a single source file — and CLAUDE.md, AGENTS.md, and GEMINI.md drift apart.
  2. Postmortem poisoning. An agent runs rg "timeout" across docs/, lands on outage-2026-10.md, and treats last autumn's broken config as today's production contract.
  3. Silent spec-to-code drift. Someone refactors VerifyHMACSignature in pay.go and merges the PR. The Markdown spec still describes last month's signature format, so the next agent writes broken webhook code.
  4. Multi-repo / microservice split-brain. Your workspace has 35 service repos, each with a dusty README.md from 2024 that contradicts how the platform works today.

Vector RAG and MCP memory servers try to solve this by adding Docker containers, SQL/graph databases, background daemons, and embedding API keys — turning plain documentation into opaque state you cannot git diff in a pull request.


How kb Fixes It — With Plain Markdown & Git

kb keeps every piece of project memory as regular Markdown files inside your repository and enforces structure with fast CLI gates (< 40 ms, zero daemons, zero external APIs):

  • Git-anchored drift detection (anchors + verified_at): Every domain spec points to real files or Go/TS/Python/Rust symbols (services/billing/pay.go#VerifyHMACSignature) and stamps verified_at: YYYY-MM-DD. kb check flags deleted symbols (anchor-symbol-missing) and commits touching anchored code after verified_at (code-drift).
  • Hot canon vs. cold archive: Active truth lives in kb/specs/ and kb/decisions/. Historical postmortems and closed delta specs live in archive/ (automatically added to .rgignore), invisible to ripgrep and kb find unless --archive is requested explicitly.
  • Root aggregation across nested .git subrepos: In umbrella workspaces with dozens of service repos, kb find walks upward across .git boundaries to the root kb.yaml. kb subprojects and kb check verify every subrepo is covered in root kb/specs/ and install priority rules so agents trust root kb/ over stale local subproject README.mds — without modifying files inside subproject git trees.
  • Hard byte budgets & symlinked root mirrors: CLAUDE.md stays short (AGENTS.md and GEMINI.md symlink to it), kb/INDEX.md is auto-generated from frontmatter, and kb check fails pre-commit if files exceed configured budgets.
flowchart LR
  A["Agent starts in root or nested subrepo"] --> B["CLAUDE.md / AGENTS.md<br/>(short, symlinked, budgeted)"]
  B --> C["kb find 'webhook retry'<br/>(&lt; 40 ms, EN/RU stems + synonyms)"]
  C --> D["kb/specs/*.md + kb/decisions/*.md<br/>(active truth only)"]
  D -- "anchors + verified_at" --> E["kb check --strict<br/>(git log & symbol verification)"]
  F["archive/reports & archive/features<br/>(.rgignore — cold history)"] -. "only with --archive" .-> C

How kb Compares

Capability Raw CLAUDE.md / AGENTS.md Fission-AI/OpenSpec steveyegge/beads (bd) Vector / Graph MCP Memory kb
Primary job Static bootstrap prompt Change proposals & delta specs Task graph & issue queue Unstructured chat/doc recall Living domain specs & drift-checked project memory
Storage Single Markdown file Plain Markdown Dolt SQL / JSONL Vector / Graph DB + daemon Plain Markdown (git diff-able)
Detects code-to-doc drift No No N/A (tracks tasks) No Yes (git log vs verified_at + #Symbol check)
Isolates old postmortems No Archives change folders Closes issues Often retrieves stale chunks Yes (.rgignore + active-only kb find)
Multi-repo root override Manual copy-paste Per-repo Per-repo / Dolt External index Built-in (kb subprojects + upward root walk)
Token-safe brownfield onboarding Manual Manual / slash cmd N/A Full-repo embedding Built-in (kb onboard with token estimate)
Diff-driven spec/code/intent grill Manual Slash prompts N/A No Built-in (kb grill / /kb-grill + 3-bucket split)
Runtime dependencies None Node.js (npm) Go / Dolt Docker + DB + API keys Single static binary (0 runtime deps)

Using kb + Beads together: They solve orthogonal halves of agent memory. Use Beads (bd) for execution state (what tasks exist, what blocks what) and kb for system knowledge (how billing, auth, and deployment work today, verified against Git).


60-Second Quickstart

1. Configure your AI coding agents (kb setup)

kb setup opens a keyboard-friendly TUI (supports both QWERTY and ЙЦУКЕН layouts out of the box) that detects installed harnesses and wires up the kb skill, /kb-onboard slash command, and root-precedence rules:

  • Claude Code (~/.claude/skills/kb + ~/.claude/rules/kb.md + /kb-onboard + /kb-grill)
  • OpenAI Codex (~/.codex/skills/kb + ~/.codex/AGENTS.md)
  • OpenCode (~/.config/opencode/skills/kb + AGENTS.md + /kb-onboard + /kb-grill)
  • Pi (pi-coding-agent) (~/.pi/agent/skills/kb + APPEND_SYSTEM.md + /kb-onboard + /kb-grill)
  • Antigravity (agy) (~/.agents/skills/kb + ~/.gemini/config/rules/kb.md)
  • Cursor / Windsurf / Cline (~/.agents/skills/kb)
2. Initialize & onboard an existing codebase (kb init + kb onboard)

At your repository or multi-repo workspace root:

kb init --name my-platform --hook
kb onboard

kb onboard scans your workspace before invoking any LLM, prints the exact Markdown count and estimated input token cost, and lets you choose:

  • Mode: Docs-first (default — consolidates existing .md files and moves dated postmortems to archive/reports/ without reading source code wholesale, saving tokens) or Deep audit (cross-checks undocumented code too).
  • Model & effort: Pick a fast, cheap model (e.g. Haiku / Flash / Mini) instead of burning flagship quota.
  • Permissions: Scoped (kb/ + kb.yaml edits only, default), Yolo (--yolo), or Interactive prompt.

Already inside an agent chat? Just tell your agent:

Run kb onboard --prompt and populate kb
3. Reconcile business rules vs. actual code (kb grill)

When your mental model, old docs, and real service code (e.g., billing or auth) may have drifted apart, auto-documenting from code blindly risks enshrining accidental bugs as "official rules". Run a focused grill on one domain or folder:

kb grill billing
# or inside an open agent chat:  /kb-grill billing

kb grill silently cross-checks kb/specs/, local docs, code-drift git commits, and source files, skips everything unambiguous, and asks one evidence-backed path:line question at a time only where contradictions or edge cases exist — then splits outcomes cleanly into kb/specs/ (current code reality), kb/decisions/ (rationale), and changes/<slug>/delta.md (bugs/gaps where code violates your business rule).


Workspace Layout & Spec Format

my-platform/
├── CLAUDE.md                  # Short bootstrap (< 20 KB); AGENTS.md & GEMINI.md symlink here
├── kb.yaml                    # Domains, byte budgets, EN/RU synonyms, mirror config
├── kb/
│   ├── INDEX.md               # Auto-generated map of active specs & decisions (kb index)
│   ├── inbox.md               # Fast flock-safe scratchpad for facts discovered mid-task (kb note)
│   ├── specs/                 # Living domain truth ONLY (overwritten in place, never dated logs)
│   │   └── billing.md
│   └── decisions/             # Architectural "why" & bans (status: active | superseded)
├── changes/                   # Active feature deltas (ADDED / MODIFIED / REMOVED)
└── archive/                   # Cold postmortems & synced deltas (hidden via .rgignore)

Each file in kb/specs/ carries lightweight YAML frontmatter:

---
title: "Billing & Webhooks"
domain: billing
kind: spec
status: active
triggers: ["billing", "webhook", "retry", "hmac"]
anchors:
  - "services/billing/cmd"
  - "services/billing/pay.go#VerifyHMACSignature"
verified_at: 2026-12-04
---

For every path in anchors, kb check locates the nearest .git repository (supporting both monorepos and nested multi-repo checkouts), verifies #Symbol still exists in source files, and compares the latest Git commit touching that path against verified_at.


CLI Reference

Command Description
kb setup [--yes] [--lang en|ru] [--agents list] Interactive TUI installer (or headless setup with --yes)
kb init [--lang en|ru] [--name <proj>] [--hook] Initialize kb skeleton, symlinks, .rgignore, and optional pre-commit hook
kb onboard [--mode docs|deep] [--yolo] [--model <id>] [--prompt] Estimate token cost, pick model & permission tier, and migrate docs into kb/
kb grill [--domain <id>] [--path <dir>] [--prompt] [target] Diff-driven 1-by-1 interview to reconcile business intent, docs, and code
kb find [--domain <id>] [--archive] <query> Search active canon sections (< 40 ms, EN/RU stemming + project synonyms)
kb note [--domain <id>] <fact> Concurrency-safe (flock) one-line append to kb/inbox.md
kb index Rebuild kb/INDEX.md from canon frontmatter and extra_canon globs
kb check [--strict] [--quiet] Verify budgets, root symlinks, code anchors, git log drift, subproject coverage, and stray reports
kb change new <slug> --domain <id> Scaffold a delta spec changes/<slug>/delta.md (ADDED / MODIFIED / REMOVED)
kb change sync <slug> Verify verified_at update in kb/specs/<domain>.md, archive delta, and rebuild index
kb subprojects Audit nested .git subprojects and check root kb/ anchor coverage
kb status One-screen health summary (domains, docs, subproject coverage, errors, drift)
kb version Print kb CLI version

Tested on Small, Cheap Models (Not Just Frontier Opus)

Many agent conventions work only when an expensive frontier model follows 40 paragraphs of prose. kb includes a live end-to-end suite (make test-e2e) that spawns low-cost models (Claude Haiku, Gemini Flash-Lite) inside synthetic multi-repo sandboxes containing:

  • stale local CLAUDE.md files inside nested microservice repos that contradict root kb/specs/;
  • archived incident postmortems with decoy port numbers and deprecated retry limits;
  • concurrent kb note writes and code-drift commits.

Small models consistently resolve the active truth via kb find in a single tool call without reading archived decoys or trusting outdated local READMEs.

(And yes — kb dogfoods itself: browse kb.yaml, kb/INDEX.md, and kb/specs/ right in this repo.)


Development

make build      # Build ./bin/kb
make test       # Unit tests with -race
make lint       # go vet + golangci-lint
make test-e2e   # Live E2E agent suite in temporary sandboxes

License

MIT

Directories

Path Synopsis
cmd
kb command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL