A portable brain-first contract for AI coding agents. Gives the agent a persistent,
searchable brain/ of durable knowledge plus a mandatory retrieve-before step and a
capture-after workflow, so it keeps learning about projects, issues, debugging, and
patterns across sessions — in every project.
- Retrieve before any non-trivial task: search the brain for prior knowledge and apply it.
- Capture after learning a durable fact (fix, pattern, gotcha, project knowledge).
- Announce via
[brain]markers so a human can verify it's actually being used. - Guardrails: never store secrets; summarize, don't dump transcripts; keep retrievals fast.
- Brain = a folder of small Markdown files with YAML frontmatter, organized by namespace
(
concepts,patterns,references,toolbox,memory). - Indexing/search = QMD (
qmd searchBM25,qmd vsearchsemantic,qmd queryhybrid). QMD also exposes a stdio MCP server (qmd mcp) that agents register as a native search tool. - Enforcement = an
AGENTS.mdcontract loaded every session (a skill alone can't guarantee retrieval;AGENTS.mdis the always-on layer). A v2 plugin can add hard telemetry viatool.execute+brain/_access.log.
Prerequisites: Node.js with npm, and OpenCode. From PowerShell:
git clone https://github.com/programmerlapar/knowledge-evolution-protocol.git
Set-Location knowledge-evolution-protocol
powershell -ExecutionPolicy Bypass -File .\scripts\install.ps1The PowerShell installer installs qmd with npm when needed, creates the global
$HOME\.config\opencode brain, installs the skill and /remember command, and registers
the Windows qmd.cmd mcp command in opencode.json. It does not require Git Bash or Python.
If PowerShell blocks script execution, -ExecutionPolicy Bypass applies only to this process.
Set KEP_OPENCODE_DIR, KEP_BRAIN_DIR, KEP_QMD_CMD, or KEP_NO_INSTALL=1 in the PowerShell
environment before running the script when you need the same overrides as the Bash installer.
Then restart OpenCode.
Prerequisites: Git, Node.js 22 or newer with
npm, and OpenCode. From Terminal, run these commands from the directory where you keep
your tools:
git clone https://github.com/programmerlapar/knowledge-evolution-protocol.git
cd knowledge-evolution-protocol
bash scripts/install.shThe installer installs QMD globally with npm when needed. It creates the brain at
~/.config/opencode/brain, installs the KEP skill and /remember command, and registers
the QMD MCP server in your global OpenCode config. It is safe to run again.
If you already have ~/.config/opencode/opencode.jsonc with comments or trailing commas,
the installer may warn that it cannot parse the file as strict JSON. Add this entry manually
under the top-level mcp object, preserving any existing MCP entries:
"qmd": { "type": "local", "command": ["qmd", "mcp"], "enabled": true }Restart OpenCode after installation. Verify the setup with:
qmd collection list
grep -n '"qmd"' ~/.config/opencode/opencode.jsonc 2>/dev/null || \
grep -n '"qmd"' ~/.config/opencode/opencode.jsongit clone https://github.com/programmerlapar/knowledge-evolution-protocol.git
cd knowledge-evolution-protocol
bash scripts/install.shThe installer (idempotent, safe) will:
- Install
qmdif missing (npm i -g qmd). - Create
~/.config/opencode/brain/and register it as theopencodeQMD collection. - Auto-detect an existing OpenClaw brain (
~/.openclaw/workspace/brain) and register it as anopenclawsecondary collection (skipped silently if absent). - Write the global
~/.config/opencode/AGENTS.mdcontract (merged, never clobbers). - Install the
knowledge-evolution-protocolskill and the/remembercommand. - Register the
qmdMCP server inopencode.json(c)(with a backup).
Then restart opencode.
Machine-specific: if your qmd needs a wrapper (e.g. a specific Node version or CPU-forced embeddings), set
KEP_USE_WRAPPER=1to use~/.openclaw/workspace/scripts/qmd-safe.sh, or pointKEP_QMD_CMDat your own wrapper. The default is plainqmdfor portability.
- Automatic. The
AGENTS.mdcontract triggers retrieval and capture on non-trivial tasks. - Manual capture:
/remember <topic>: <what you learned>.
Verify it's working by grepping sessions for [brain] markers:
[brain] searched "<topic>" → 3 hits
[brain] applied references/opencode/foo.md
[brain] captured patterns/programming/bar.md (reindexed)
PROTOCOL.md # full contract spec
SKILL.md # portable agent skill (retrieval + capture + indexing)
AGENTS.md.template # always-on contract, installed to ~/.config/opencode/AGENTS.md
command/remember.md # /remember capture command
scripts/install.sh # one-shot idempotent installer
scripts/install.ps1 # native Windows PowerShell installer
tests/ # test suite (Tier 1-2 plumbing; Tier 3 e2e gated by RUN_E2E=1)
brain/ # empty namespace scaffold (your data lives in ~/.config/opencode/brain)
bash tests/run.sh # Tier 1 + 2 (plumbing + contract) — no LLM needed
RUN_E2E=1 bash tests/run.sh # + Tier 3 real opencode session (requires model API, costs tokens)- Tier 1 verifies install, qmd search/vsearch/query recall, capture→reindex, and the MCP handshake against a scratch brain.
- Tier 2 verifies the installed contract contains the mandatory sections (regression guard).
- Tier 3 runs a real headless opencode session on a fixture Node project, asserting
[brain] searched/[brain] appliedretrieval and that a resolved issue is captured and reused on recurrence. Tests useKEP_BRAIN_DIR+ a scratch brain so your real knowledge is never touched.
Set KEP_BRAIN_DIR to point the brain at another directory (tests, sandboxes, multiple KBs).
Keep the opencode QMD collection pointed at it too.
MIT