kb

module
v0.4.1 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

Git-native documentation discipline for AI coding agents — without taking away file-system freedom.

CI Go Reference Release llms.txt

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



The Problem

Existing "agent memory" tools restrict how AI coding agents work. MCP memory servers, vector RAG, graph databases, Notion, Confluence, and Obsidian force an agent through narrow external search calls instead of letting it use its strongest capability: scanning plain files on disk in milliseconds. In day-to-day development, external memory layers get in the agent's way more than they help.

Keeping all documentation as plain Markdown in Git solves the access problem — every spec sits right next to the code. On an active codebase, however, plain Markdown breaks down in four ways:

  • Silent documentation drift: Code changes in Git while Markdown specs keep describing last month's behavior, and agents forget to track or update them.
  • Shallow verification: Asking an agent to "check docs against code" produces superficial passes — or rubber-stamps accidental code bugs into specs as official business rules.
  • Postmortem poisoning: Agents grep docs/, land on old incident reports or migration plans, and mistake historical notes for active contracts.
  • Multi-repo split-brain: Across dozens of frontend and backend repositories, local README.md and CLAUDE.md files rot independently and contradict how the system works today.

kb solves this directly inside Git. It is a single static Go binary (no databases, daemons, or API keys) that teaches coding agents how to navigate, verify, and maintain plain Markdown documentation inside your workspace. Initialized once at the root of a project or multi-repo checkout, kb gives every agent an up-to-date map of where each frontend and backend lives, how each service works right now, which specs fell behind recent commits, and where business logic needs reconciliation against code.


Install

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

Downloads the SHA-256 verified binary for your OS/arch and opens the interactive kb setup TUI to wire up your coding agents.

Alternative install methods (Homebrew, Go, CI / dotfiles, skills.sh)
# Homebrew (macOS & Linux)
brew install mdwitr0/tap/kb && kb setup

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

# Non-interactive setup (CI, Dockerfiles, dotfiles)
curl -fsSL https://raw.githubusercontent.com/mdwitr0/kb/main/install.sh | bash -s -- --yes --lang en

# Agent skill only (skills.sh)
npx skills add mdwitr0/kb

How kb Works

All project knowledge stays in regular Git-tracked Markdown files, with < 40 ms in-memory search and per-repository batched Git drift checks:

  • Root map across frontends & backends (kb/INDEX.md + kb subprojects): In workspaces with dozens of nested .git repositories, all living specs live in one root kb/ without modifying subproject git trees. Agents walking inside any nested service resolve the root kb.yaml automatically and prioritize root kb/ over stale local README.mds.
  • Exact per-service context & SHA-anchored Git drift (kb context <path> + kb check + kb stamp): Specs declare anchors (services/billing/pay.go#VerifyHMACSignature), verified_at, and verified_commit SHA cursors. Before editing a service, the agent runs kb context <service-path> and immediately sees the governing spec, any deleted #Symbol declarations (ignoring leftover comments and test mocks), and exact <verified_commit>..HEAD commits — catching merged PR branches with older commit dates and same-day edits alike.
  • Diff-driven spec & code reconciliation (kb grill): Instead of blindly turning buggy code into specs, kb grill cross-checks docs against source code for a target service, asks one path:line question at a time on genuine contradictions and edge cases, and separates current code behavior (kb/specs/), architectural rationale (kb/decisions/), and code bugs (changes/*/delta.md).
  • Active canon vs. cold archive (kb find): Living specs live in kb/specs/ and kb/decisions/. Dated postmortems and synced feature deltas live in archive/ (added to .rgignore), hidden from ripgrep and kb find unless --archive is passed explicitly.
  • Byte budgets & unified entrypoints: AGENTS.md and GEMINI.md symlink to a concise CLAUDE.md, and kb check enforces size limits in pre-commit.
flowchart LR
  A["User task in natural language"] --> B["Agent reads root map<br/>(kb/INDEX.md + kb find)"]
  B --> C["kb context &lt;service-path&gt;<br/>(governing specs + git drift commits)"]
  C --> D["kb/specs/*.md + kb/decisions/*.md<br/>(active plain Markdown in Git)"]
  D -- "anchors + verified_at" --> E["kb check --strict / kb grill<br/>(drift gate & 1-by-1 reconciliation)"]
  F["archive/reports & archive/features<br/>(.rgignore — cold history)"] -. "only with --archive" .-> B

Comparison

Capability Raw CLAUDE.md / AGENTS.md Fission-AI/OpenSpec steveyegge/beads (bd) MCP / Vector / Wiki (Notion, Confluence) kb
Primary role Static bootstrap prompt Change proposals & delta specs Task graph & issue queue External search over docs/chats Living domain specs & Git-verified project memory
Agent file freedom Full (single file) Full (Markdown) CLI / Dolt SQL Restricted behind API calls Full (plain Markdown in Git)
Detects code-to-doc drift No No N/A (tracks tasks) No Yes (SHA cursor <commit>..HEAD + #Symbol decls)
Isolates old postmortems No Archives change folders Closes issues Often retrieves stale pages Yes (.rgignore + active-only kb find)
Multi-repo root map Manual copy-paste Per-repo Per-repo / Dolt External workspace Built-in (kb subprojects + upward root walk)
Token-safe onboarding Manual Manual / slash cmd N/A Full indexing Built-in (kb onboard with token estimate)
Code vs. intent reconciliation Manual Slash prompts N/A No Built-in (kb grill / /kb-grill)
Runtime dependencies None Node.js (npm) Go / Dolt Cloud SaaS / Docker / DB Single static binary (0 runtime deps)

Using kb + Beads together: Use Beads (bd) for execution state (task queue and dependencies) and kb for system knowledge (how each frontend, backend, and contract works today, verified against Git).


Quickstart

1. Connect your coding agents (kb setup)

kb setup opens a terminal TUI (supporting both QWERTY and ЙЦУКЕН keyboard layouts) that installs the kb skill, slash commands (/kb-onboard, /kb-grill), and root-precedence rules into your selected tools:

  • 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 project (kb init + kb onboard)

At your repository or multi-repo workspace root:

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

Before launching an agent, kb onboard counts discovered Markdown files, prints the estimated input token footprint, and lets you choose:

  • Analysis depth: docs (default — consolidates existing .md files and moves dated reports to archive/reports/ without reading all source code) or deep (cross-checks undocumented code too).
  • Model & effort: Choose a fast, low-cost model instead of spending flagship quota.
  • Permissions: scoped (kb/ + kb.yaml edits auto-approved, default), yolo (--yolo), or prompt.

Inside an already open agent session:

Run kb onboard --prompt and populate kb
3. Reconcile business logic against code (kb grill)

To verify a specific service or domain where documentation, code, and business expectations may disagree:

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

The agent maps your request to the target service via the project map, runs kb context <service-path> to pull its governing spec and code-drift commits, inspects the service code silently, and interviews you one path:line question at a time. Confirmed answers are split into three places: verified current code behavior (kb/specs/), architectural rationale and bans (kb/decisions/), and implementation gaps or bugs (changes/<slug>/delta.md).


Workspace Layout & Spec Frontmatter

my-platform/
├── CLAUDE.md                  # Concise entrypoint (< 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               # Lock-safe scratchpad for facts captured mid-task (kb note)
│   ├── specs/                 # Current domain behavior ONLY (overwritten in place)
│   │   └── billing.md
│   └── decisions/             # Architectural rationale & bans (status: active | superseded)
├── changes/                   # Active feature deltas (ADDED / MODIFIED / REMOVED)
└── archive/                   # Cold postmortems & synced deltas (hidden via .rgignore)

Frontmatter on kb/specs/*.md:

---
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
verified_commit: "7f83d10c2a19"
---

For each entry in anchors, kb check resolves the nearest .git root (both root monorepos and nested service repos, where verified_commit becomes a per-repo SHA map), verifies #Symbol declarations after stripping comments and string literals, and checks <verified_commit>..HEAD via a single batched git log per repository. Run kb stamp <domain> (or kb stamp --all) after verifying specs against code to lock the current HEAD cursor.


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 & permissions, and migrate docs into kb/
kb grill [--domain <id>] [--path <dir>] [--prompt] [request] Diff-driven 1-by-1 interview to reconcile business intent, docs, and code
kb context <path...> Exact slice for path(s): governing kb/ specs, SHA-anchored code-drift commits, inbox notes, and open deltas
kb stamp [--all] [domain-or-spec...] Update verified_at and lock verified_commit HEAD SHA cursors on specs
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

End-to-End Verification on Small Models

make test-e2e runs live low-cost models (Claude Haiku, Gemini Flash-Lite) inside temporary multi-repo sandboxes containing conflicting local subproject CLAUDE.md files, archived incident decoys, concurrent kb note writes, and code-drift commits — verifying that even small models resolve active rules via kb in a single lookup without reading archived postmortems.

This repository also manages its own documentation with kb: see kb.yaml, kb/INDEX.md, and kb/specs/.


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