mcp server
k0maru-agent-memory
A Standalone, Single-Static-Binary, Zero-Daemon Long-Term Memory Hub for AI Coding Agents.
Set up
Runs on your computer. Pick your agent and operating system.
This project does not publish an install method we can turn into a config. Follow the README instead.
README
synced Oct 21, 2026K0maru-Agent-Memory
A Standalone, Single-Static-Binary, Zero-Daemon Long-Term Memory Hub for AI Coding Agents.
Topology-agnostic memory hub mounting any Markdown vault or LLM-Wiki (flat Karpathy wikis, engineering ADRs, PARA, Johnny.Decimal) with instant sub-millisecond context retrieval, symbolic log offloading, and living ADR architectural guardrails.
💡 Dual Binary Support: Available as both
k0maruandk0maru-memorystandalone binaries for seamless compatibility with multi-agent orchestration systems.
🌟 Core Advantages & Architectural Superiority (Why K0maru?)
Modern AI coding agents (Claude Code, Cursor, Windsurf, Gemini, etc.) frequently suffer from two critical pain points: Cross-Session Amnesia (loss of architectural decisions across sessions) and Terminal Log Bloat (compiler and test outputs flooding the context window).
Existing agent memory frameworks frequently deploy heavy multi-container Docker clusters (PostgreSQL, pgvector, Redis) or resident background daemons, incurring continuous RAM footprints (800MB–2GB), port conflicts, and complex deployment friction.
K0maru is engineered specifically for local developer workstations, delivering industrial-grade performance with minimal mechanical complexity:
- ⚡ Zero-Daemon & Sub-Millisecond Cold Start:
- Pure Rust, statically compiled into a single 3.66 MB standalone binary.
- Cold-starts in just 3.38 ms with a lean ~11 MB RAM footprint; occupies 0 persistent network ports.
- Runs on demand via standard Unix pipes and
stdiostreams, releasing all memory immediately upon process exit.
- 📝 Bring Your Own Markdown (Topology-Agnostic LLM-Wiki):
- Your existing local Markdown notes serve as the Single Source of Truth. Fully topology-agnostic: adapts seamlessly to any LLM-Wiki shape — flat Karpathy-style LLM-Wikis, engineering
docs/adr/ordecisions/wikis, PARA (projects/,cards/,logs/), and Johnny.Decimal (10_Projects/,20_Cards/). - Zero proprietary binary lock-in, zero migration friction, and zero changes to your existing folder structure.
- Your existing local Markdown notes serve as the Single Source of Truth. Fully topology-agnostic: adapts seamlessly to any LLM-Wiki shape — flat Karpathy-style LLM-Wikis, engineering
- 🪓 Disposable Transient Cache:
- Maintains only a single-file SQLite database (
cache.sqlite) integrating FTS5 BM25 full-text indices andsqlite-vecvirtual tables with pluggable embedding dimensions. - Strictly disposable: delete it anytime (
rm cache.sqlite) and the scanner self-heals and rebuilds the index from scratch in 74 ms.
- Maintains only a single-file SQLite database (
- 📉 Symbolic Context Offloading & Governance (99.4% TRR & Live A100 Validation):
- Filters verbose logs via standard Unix pipes (
| k0maru offload), transforming long traces into Mermaid state diagrams and stored slices. - Includes 4-tier Context GC (
k0maru gc) keeping agent sessions within the cognitive Smart-Zone (15%–60%).
- Filters verbose logs via standard Unix pipes (
- 🛡️ Living ADR Guard & Architectural Invariant Sentinel (<10ms Audit):
- Transforms passive Architecture Decision Records (ADRs) and vault notes into active, executable guardrails.
- Audits staged Git diffs and incoming code against architectural rules (forbidden anti-patterns, required boundaries, regex invariants) via
k0maru guard check --diffor theguard_checkFastMCP tool. - Installs pre-commit hooks (
k0maru guard install) to block non-compliant code from entering repositories with 0 runtime dependencies.
Architectural Comparison Matrix
| Evaluation Dimension | Vanilla Context (Copy-Paste) | Containerized Microservices (Letta / TencentDB) | Resident Background Daemons (agentmemory) | K0maru-Agent-Memory (This Project) |
|---|---|---|---|---|
| Storage Medium | Ephemeral chat history | External DBs (PostgreSQL, pgvector, Redis) | Proprietary DB in hidden directories | Local Markdown Vaults (Plain Text) |
| Deployment Model | Manual copy | Multi-container Docker Compose clusters | Background daemon process (iii-engine, etc.) | Single static binary, on-demand (Zero-Daemon) |
| Network Port Footprint | None | 1–4 open ports | 1–4 open ports | 0 ports (Unix pipes & stdio streams) |
| Cold Start Latency | Instant | 2,500 ms – 3,500 ms (container boot) | 1,000 ms – 2,000 ms | 3.38 ms (native Rust binary) |
| Resident Memory (RAM) | 0 MB | ~850 MB – 2,000 MB | ~150 MB – 300 MB | ~11.7 MB (released instantly on command exit) |
| Terminal Log Governance | Manual or LLM truncation | Network API transfer required | Internal bespoke truncation | Standard Unix pipe filter (| k0maru offload) |
| Living ADR Sentinel | Manual code review | External SonarQube / heavy CI | None | Living ADR Guard (<10ms git diff audit against vault rules) |
| Index Self-Healing | None | Snapshot & backup dependent | Local database integrity dependent | cache.sqlite disposable anytime, rebuilt in 74ms |
Empirical Open-Source Model Benchmark (NVIDIA A100-80GB GPU)
Evaluated on an NVIDIA A100-SXM4-80GB GPU in Google Colab Pro, measuring real local inference across leading open-source models on 5 representative industrial defects (Rust concurrency, Python asyncio leaks, TypeScript auth crashes, Go deadlocks, C memory safety):
| Evaluated Open Model | Architecture | Baseline (Raw Traces) | K0maru Managed | Breakthrough & Performance Impact |
|---|---|---|---|---|
| Qwen2.5-Coder-32B | 32B Dense Code Model | Pass@1: 60.0%Latency: 17.23s | Pass@1: 100.0% (+40%)Latency: 2.92s (5.90x faster) | 100% Full Pass Rate; Mermaid diagrams eliminated trace noise, solving async deadlocks and null checks |
| DeepSeek-R1-32B | 32B Full Reasoning Distill | Latency: 27.14sTokens: 817 | Latency: 14.07s (1.93x faster)Tokens: 652 (-20.2%) | Reasoning Latency Cut in Half (-48.2%); streamlined reflection chain, Rust turnaround dropped from 39.2s to 11.5s (3.4x) |
| DeepSeek-Coder-V2 | 16B MoE (2.4B active) | Pass@1: 60.0%Latency: 12.46s | Pass@1: 80.0% (+20%)Latency: 1.05s (11.86x faster) | Sub-Second Extreme Throughput; cured Python async leak with 1.05s turnaround |
| Qwen3.8-27B | 27B Dense (Dual-Stage Reasoning) | Tokens: 923Rust Latency: 21.2s | Tokens: 709 (-23.2%)Rust Latency: 11.1s (2x faster) | Flawless 100% Pass Baseline; 23.2% Prompt Token reduction, halved Rust turnaround |
Autonomous Agent Ecosystem Adaptation (Hermes Agent & OpenClaw on Real LLM-Wiki)
Simulated an enterprise-grade payment gateway LLM-Wiki on Colab A100 (containing P0 service architecture, L3 idempotency rules, and incident postmortems), driving Qwen3.8-27B through an autonomous Hermes / OpenClaw function calling loop. All 4 core invariants achieved 100% compliance:
| Invariant Verification Item | Expected Standard & Behavior | Empirical Outcome | Status |
|---|---|---|---|
| 1. Pre-flight Memory Inspection | Query loadout and rules before generating any code | Autonomously issued get_project_loadout + 2x targeted recall_memory calls | PASS ✓ |
| 2. Architectural Invariant Compliance | Generated code must enforce distributed mutex & state guard | Produced Go handler with Redis lock SET NX EX 30 & STATUS_PENDING check | PASS ✓ |
| 3. Self-Healing Session Flush | Persist ADR decision to wiki via flush_session with WikiLinks | Automatically created 20_Cards/adr-pay-012-...md with frontmatter | PASS ✓ |
| 4. Instant Recall Without Re-indexing | Note must be recallable immediately without manual re-index | Recalled in 0.88 ms with top score of 12.05 (Rank #1 hit) | PASS ✓ |
📖 Comprehensive Case Breakdown & Autonomous Agent Traces:
For the complete per-case logs, multi-turn Hermes/OpenClaw traces, and 500B+ model notes, see Part 4 & Part 5 of the Comparison Report.
🚀 Quick Start & Installation
For step-by-step instructions, see QUICKSTART.md.
1. Install K0maru Binary
Option A: One-Line Install Script (macOS & Linux - Recommended)
No Rust toolchain required. Automatically detects OS and chip architecture, verifies SHA-256 checksums, and installs the standalone binary:
curl -fsSL https://raw.githubusercontent.com/K0maru/k0maru-agent-memory/main/install.sh | bash
Option B: Homebrew (macOS & Linux)
brew install K0maru/tap/k0maru
Option C: Build from Source (Cargo)
cargo install --git https://github.com/K0maru/k0maru-agent-memory
(Builds both k0maru and k0maru-memory binary aliases).
2. Connect Your Coding Agents (k0maru install)
With a single command, inject K0maru's FastMCP service into all detected coding agent configuration files (Claude Code, Cursor, Gemini CLI, Windsurf, Cline / Roo Code, Hermes, OpenClaw, and Oh My Pi / omp):
# Auto-detect and configure all installed agents pointing to your Markdown vault
k0maru install --vault ~/Documents/MyVault
# Or configure a specific client (e.g. Oh My Pi / omp)
k0maru install --target omp --vault ~/Documents/MyVault
# Or preview configuration diffs safely without writing to disk
k0maru install --vault ~/Documents/MyVault --dry-run
For manual setup, add this snippet to your IDE's MCP config:
{
"mcpServers": {
"k0maru-memory": {
"command": "k0maru",
"args": ["mcp", "--vault", "/path/to/your/markdown-vault"]
}
}
}
2.1 Tern Native Plugin & omp/Claude Plugin Marketplace
K0maru integrates natively with modern terminal multiplexers and agent plugin marketplaces:
- Tern Multiplexer Plugin: Native Luau plugin featuring an interactive cockpit dashboard, CLI lens, and Carly palette integration:
tern plugin install github.com/K0maru/k0maru-agent-memory/tern-plugin - Oh My Pi (
omp) Plugin Marketplace:/marketplace add K0maru/k0maru-agent-memory /marketplace install k0maru-memory@k0maru-agent-memory - Claude Code Plugin Marketplace:
/plugin add K0maru/k0maru-agent-memory
3. Verify Health & Environment (k0maru doctor)
Run the automated doctor check to inspect your binary, vault conventions, SQLite indices, and agent bindings:
k0maru doctor
Outputs a clear, color-coded health report (✓ Binary In Path, ✓ FTS5 Index Ready, ✓ Vectors Indexed, ✓ Claude Code Configured, ✓ Cursor Configured) with actionable remediation steps for any warnings.
🛠️ Common Use Cases & Workflows (How-Tos)
Use Case 1: Kickstarting New Sessions —— Rapid Context Loadout (k0maru loadout & get_project_loadout)
Avoid dumping dozens of unrelated files into fresh agent chats. loadout extracts project mission, core architectural invariants (L3), and recent engineering logs (L2), strictly contained within < 300 Tokens:
- 4-Tier Scoped Project Resolver:
- Tier 1: Normalized exact match, alias, tag, and backlink-derived project aliases.
- Tier 2: Scoped FTS5 SQL push-down via
search_scoped_fts(never global Top 5 truncation). - Tier 3: Vector semantic fallback (if vector embeddings exist).
- Tier 4: Ambient workspace / CWD directory matching.
- Git Diff Change-Awareness (
--diff): Dynamically analyzes working tree modifications to activate module-relevant ADRs and invariants.
# Generate project loadout and copy directly to the system clipboard (macOS / Linux / Windows)
k0maru loadout my-project --vault ~/wiki --copy
# Diff-aware loadout: dynamically inspect git changes and activate relevant ADRs
k0maru loadout my-project --vault ~/wiki --diff --copy
FastMCP Autonomous Tool Equivalent: get_project_loadout
{
"project_name": "k0maru-agent-memory",
"diff": true,
"branch": "main"
}
Use Case 2: Build & Test Failures —— Symbolic Context Offloading (| k0maru offload)
When running test suites or compilers that generate thousands of lines, pipe the command output through k0maru:
# Intercept verbose dumps; outputs a clean Mermaid diagram with a node_id
cargo test 2>&1 | k0maru offload
# Retrieve targeted failure stack trace slice on demand
k0maru inspect node_54697ed3
- 99.44% Token Reduction: Truncates massive compiler dumps, storing full raw logs safely under
.scratch/refs/or<vault>/.k0maru/refs/. - Mermaid State Diagrams: Transforms raw stack traces into structural transitions (e.g.,
Iteration1 --> Failure: E0382 borrow after move), guiding LLMs directly to the root cause without attention drift. - FastMCP Autonomous Tools:
offload_context: Agents can offload terminal logs produced during tool execution.inspect_log_node: Retrieve specific stack slices bynode_id.gc_session_context: Compresses long 50+ turn trajectory sessions using a 4-tier compaction protocol (preserving hot windows and achieving TRR >= 85%).
Use Case 3: Querying the Vault —— Natural Language Intent-Driven Recall (recall_memory & k0maru search)
Once connected via MCP, frontier models automatically understand intent and invoke the right tools without memorizing explicit keywords:
# Hybrid search (BM25 + ONNX vectors + RRF k=60 + WikiLinks graph boost)
k0maru search "concurrency deadlock mitigation" --vault ~/wiki --mode hybrid --limit 5
# Pluggable embeddings: select specific model or dimension
k0maru search "vector similarity" --vault ~/wiki --embed-model bge-small-zh-v1.5
- Compact K-DSL Wire Default (
!μ:<tier>|<path>|...) for MCPrecall_memory: To prevent Master Agent context explosion, therecall_memoryMCP tool defaults to returning ultra-dense single-line K-DSL wire entries (!μ:<tier>|<path>|score:<score>|links:<in>/<out> § <snippet>, capped at ≤140 chars per snippet). Pass"full": truein tool arguments only when full multi-line markdown excerpts are explicitly needed. - Pluggable Vector Backends: Built-in support for
all-minilm-l6-v2(384d, default),bge-small-zh-v1.5(512d),bge-base-en-v1.5(768d),paraphrase-multilingual-minilm-l12-v2(384d), and mock embedders for offline testing. - Dynamic Dimension Migration: Seamlessly reconfigures
sqlite-vecvirtual tables upon model switching without manual database rebuilds.
Use Case 4: Preserving Decisions & Troubleshooting Skills —— Memory Crystallization (k0maru flush & distill)
Crystallize engineering takeaways, architectural decisions (ADRs), or debugging playbooks back into your vault:
# Crystallize an ADR into vault matching local conventions
k0maru flush \
--title "Mitigating Tokio Runtime Blocking in Worker Pools" \
--category decision \
--summary "Offloaded synchronous disk IO to spawn_blocking threadpool" \
--content "Detailed stack analysis and remediation..." \
--tags "tokio,rust,performance" \
--related "Architecture Standards,Async Concurrency" \
--vault ~/wiki
# Distill troubleshooting trace into a reusable skill note
k0maru distill \
--trace-file /tmp/error.log \
--title "Resolving SQLite Vec Apple Silicon Linking" \
--vault ~/wiki
- Convention Sniffing: Automatically adapts to your vault's naming style (e.g.,
YYYY-MM-DD-slug.md), directory structures, andAGENTS.mdrules. - Collision Defense: Detects duplicate titles and increments versions safely (
-v2.md) without overwriting existing notes. - Hermes Skill Export: Supports
--target hermesto output dynamic skills compatible with Nous Research Hermes Agent. - FastMCP Autonomous Tools:
flush_sessionanddistill_session_skill.
Use Case 5: Pre-Commit Sentinel —— Living ADR Guard (k0maru guard & guard_check)
ADRs and technical guidelines should not be dead text in forgotten folders. K0maru's Living ADR Guard turns your documentation into an automated architectural sentinel:
# Audit Git working tree / staged diff against active Living ADR invariants (<10ms)
k0maru guard check --diff
# Install pre-commit hook into repository to block non-compliant commits automatically
k0maru guard install
How Invariants are Declared
In your vault's ADR notes (20_Cards/ or 10_Projects/), add an invariants block to the frontmatter:
---
title: ADR-042 Distributed Lock Standard
category: decision
tags: [architecture, redis, idempotency]
invariants:
- id: "enforce-distributed-mutex"
condition: "must_contain"
pattern: "redis_lock\\.acquire|SET\\s+NX\\s+EX"
paths: ["src/payment/**/*.rs", "services/order/**/*.go"]
severity: "deny"
fix_hint: "Critical financial paths must acquire a distributed Redis lock before mutating state."
- id: "ban-raw-sql-in-handlers"
condition: "forbidden"
pattern: "SELECT .* FROM raw_|execute_unprepared"
paths: ["src/api/**/*.rs"]
severity: "deny"
fix_hint: "Use query builders or prepared statements in storage layer."
---
You can also place rules in repository root .k0maru/rules, guard.toml, or AGENTS.md.
- <10ms Lightning Fast: Runs in native Rust, evaluating hundreds of diff hunks instantly.
- Exit Codes: Returns
0on clean pass,1on blockingdenyviolation,2on execution error. - FastMCP Autonomous Tool:
guard_checkallows AI agents to audit diffs before presenting changes to the human developer.
Use Case 6: Vault Introspection —— Embedded Developer Console (k0maru ui)
Launch a local visual dashboard on demand:
k0maru ui --vault ~/wiki --open
- 🌐 Bilingual Switching: Instant one-click toggle between English and Chinese in the header.
- 🔍 Search Explainability Console: Inspect BM25 ranks, vector cosine distances, and Emerald
+0.05 Graph Boostbadges. - 🪵 Log & State Machine Inspector: Native SVG Mermaid renderer with syntax-highlighted error logs and one-click copying.
- 📊 Token Economics Scoreboard: Real-time telemetry tracking vector coverage, database size, and cumulative tokens saved.
- Zero Daemon: Pressing
Ctrl+Cimmediately frees all memory and network ports. See docs/UI_TUTORIAL.md.
Use Case 7: Vault Changes —— Sub-Millisecond Incremental Synchronization (k0maru sync)
# Incremental rescan of markdown files and FTS5 indices (takes just 11ms when clean)
k0maru sync --vault ~/wiki
# Batch incremental generation of ONNX vector embeddings (skips unchanged notes)
k0maru sync --vault ~/wiki --vector
# Sync with custom embedding model
k0maru sync --vault ~/wiki --vector --embed-model bge-small-zh-v1.5
🤖 Autonomous Agent Ecosystem & FastMCP Protocol
When connected via FastMCP, K0maru operates in two distinct server modes:
- Default Full Mode (8 Tools): For general open-source and IDE agents (Claude Code, Cursor, Windsurf, Hermes, OpenClaw), providing the complete suite of memory, context offloading, and GC tools.
- Orthogonal Sidecar Mode (
--sidecar, 5 Tools): Tailored foromp(Oh My Pi). Becauseompnatively manages terminal streams and session compaction, sidecar mode exposes the 5 orthogonal domain tools (get_project_loadout,recall_memory,flush_session,distill_session_skill,guard_check) while omittingoffload_context,inspect_log_node, andgc_session_contextto prevent pipeline redundancy.
| FastMCP Tool | Mode | Target Intent & Natural Prompt Triggers | Core Value & Mechanics |
|---|---|---|---|
get_project_loadout | Full / Sidecar | "Start new task", "What are our architectural invariants?" | Scoped 4-tier retrieval returning mission, rules, and recent logs strictly < 300 Tokens. Supports --diff dynamic activation. |
recall_memory | Full / Sidecar | "How do we configure X?", "Search notes for Y" | Hybrid BM25 + ONNX vector + RRF $k=60$ + 1-hop WikiLinks graph boost. Instant sub-millisecond retrieval. |
offload_context | Full Only | Large tool execution outputs, test logs (>30 lines) | Externalizes verbose terminal text into Mermaid state diagrams and stored disk slices. Prevents attention drift. |
inspect_log_node | Full Only | "Inspect failure stack for node_xxxx" | Retrieves exact raw stack trace slice on demand by node ID. |
flush_session | Full / Sidecar | "Document this decision", "Save milestone to vault" | Atomically writes structured ADRs or logs into vault matching local naming conventions and frontmatter schemas. |
distill_session_skill | Full / Sidecar | "Distill this bug fix into a reusable skill" | Extracts troubleshooting patterns into structured skill notes (Markdown or Hermes format). |
gc_session_context | Full Only | Long multi-turn agent dialogues approaching context limit | Compresses session trajectory with 4-tier pruning protocol, achieving TRR >= 85% while preserving hot window. |
guard_check | Full / Sidecar | Before Git commits, post-implementation code review | Audits diff against Living ADR rules (<10ms). Halts non-compliant code from entering repositories. |
💡 Pro-Tip: Autonomous Vault Inspection System Prompt
Add this single instruction to yourAGENTS.mdor global system prompt:
> Before designing architecture, debugging complex failures, or implementing core logic, inspect the local vault using k0maru-memory to align with historical ADRs and codebase conventions. Run guard_check before completing tasks.
Agents will proactively consult your security and architectural standards before writing code.
📊 Empirical Google Colab A100 Benchmark Matrix
Evaluated live on a dedicated NVIDIA A100-SXM4-80GB GPU across 5 frontier and coding models on 5 representative industrial defect scenarios (Rust E0382, Python InvalidStateError, TypeScript auth null reference, Go deadlock, C double free) and 4 architectural invariants:
1. Multi-Model Benchmark Matrix
| Evaluated Model | Architecture | Pass@1 (Baseline) | Pass@1 (K0maru) | Avg Latency (Base -> K0maru) | Speedup | Prompt Tokens (Base -> K0maru) | Token Reduction (%) |
|---|---|---|---|---|---|---|---|
| Qwen3.8-27B (Flagship Kanban) | 27B Dual-Stage Reasoning | 20.0% (1/5) | 40.0% (2/5) | 16.70s ➔ 6.14s | 2.72x | 5,745 ➔ 1,076 | 81.3% |
| DeepSeek-Coder-V2-16B | 16B MoE (2.4B active) | 80.0% (4/5) | 100.0% (5/5) | 9.43s ➔ 1.36s | 6.93x | 6,298 ➔ 1,142 | 81.9% |
| Qwen2.5-Coder-32B (Code Baseline) | 32B Dense Q4_K_M | 60.0% (3/5) | 100.0% (5/5) | 24.68s ➔ 7.13s | 3.46x | 5,472 ➔ 1,119 | 79.6% |
| DeepSeek-R1-32B | 32B Reasoning Distill | 20.0% (1/5) | 40.0% (2/5) | 12.01s ➔ 9.19s | 1.31x | 5,412 ➔ 989 | 81.7% |
| Google Gemma 4 31B | 31B Multimodal Foundation | 0.0% (0/5) | 0.0% (0/5) | 16.69s ➔ 6.94s | 2.40x | 6,356 ➔ 1,134 | 82.2% |
See docs/COMPARISON_REPORT.md for full breakdown, including 4/4 invariant compliance.
2. Multi-Agent Concurrency & Heterogeneous Harness Benchmark (A100)
| Benchmark Stress Dimension | Concurrency / Load | Measured Metric / Throughput | Status | Engineering Assurance |
|---|---|---|---|---|
| Simultaneous Read Bursts | 12 Concurrent Agents, 120 queries | 18.9 QPS, Avg: 614.29ms (P50: 781.9ms) | 100% PASS | Zero SQLite busy contention (SQLITE_BUSY = 0) |
| Simultaneous Write & Flush Race | 8 Concurrent Writers | 12.2 writes/sec, Avg: 584.93ms | 100% PASS | 8/8 files created, zero collision loss (-v2.md to -v8.md) |
| Instant Self-Healing Recall | Read-your-writes validation | 290.99 ms | PASS ✓ | Immediate sub-second recall without re-indexing |
| Context Garbage Collection (GC) | 50-turn trajectory compaction | 94.67% TRR (20,946 ➔ 1,110 tokens) | PASS ✓ | Preserves context within cognitive Smart-Zone (15%–60%) |
| Dynamic Loadout Git-Diff | Change-aware ADR activation | 245 tokens | PASS ✓ | Strictly bounded under <300 token budget |
| Heterogeneous Agent Loops | Hermes, OpenClaw, Pi | Turnaround: 1.04s – 8.49s | 100% PASS | Verified autonomous tool calling & ADR crystallization |
🏗️ Architecture & Mechanics
Four-Layer Decoupled Architecture
- Interface Layer: CLI Tools (
doctor,install,loadout,search,flush,distill,gc,guard, pipe filters) + Embedded Dashboard (Axum + rust-embed) + FastMCP Stdio Service. - Orchestration & Governance Layer: Living ADR Guard Engine + State Machine Log Parser (Mermaid abstraction and slice storage) + Packager (<300 token Smart-Zone control) + Adaptive Convention Sniffer.
- Hybrid Search & Graph Layer: SQLite FTS5 BM25 +
sqlite-vecONNX Embeddings (pluggable 384d/512d/768d) + Reciprocal Rank Fusion ($k=60$) + 1-Hop WikiLinks Graph Boost (+0.05). - Storage & Persistence Layer: Local Plaintext Markdown Vault (Single Source of Truth) + Disposable
cache.sqlite(Transient full-text, vector, and adjacency index).
Memory Lifecycle Loop
- Wake & Loadout ➔ Run & Offload ➔ Pre-Commit Guard ➔ Session Flush (ADR) ➔ Consolidation (Evergreen Cards)
📖 CLI Cheat Sheet
Both k0maru and k0maru-memory binary names are supported identically.
| Command | Common Flags | Description |
|---|---|---|
k0maru install | --vault <path> | Injects k0maru-memory into agent client config files |
--target <client> | Target client (all, claude, cursor, gemini, windsurf, cline, hermes, openclaw, omp) | |
--dry-run | Previews configuration changes without touching disk | |
k0maru doctor | --vault <path> | Full diagnostic check of binary, vault, cache, and client bindings |
--json | Outputs machine-readable JSON diagnostic report | |
k0maru ui | --vault <path> | Launches embedded visual developer console (127.0.0.1:3721) |
--port <port> | Binds custom local port | |
--open | Automatically opens default browser upon startup | |
k0maru loadout <query> | --vault <path> | Target markdown vault directory |
--diff | Dynamically activates module-relevant ADRs by inspecting git diff | |
--copy | Copies assembled <300 token loadout directly to clipboard | |
--json | Outputs structured JSON loadout data | |
-l, --list | Lists all active projects within vault | |
k0maru search <query> | --vault <path> | Target markdown vault directory |
--mode <mode> | Search mode (hybrid [default], bm25, vector) | |
--embed-model <name> | Pluggable embedding model (all-minilm-l6-v2, bge-small-zh-v1.5, etc.) | |
--limit <N> | Maximum search results to return (default: 5) | |
--json | Outputs structured JSON search results | |
k0maru sync | --vault <path> | Incrementally scans and updates SQLite indices |
--vector | Computes and stores ONNX vector embeddings incrementally | |
--embed-model <name> | Selects embedding model for vector generation | |
--force | Forces full re-index ignoring cache timestamps | |
k0maru offload | --threshold <N> | Line count threshold for triggering symbolic offload (default: 50) |
--task-id <id> | Binds a task ID for traceable offloaded logs | |
k0maru inspect <id> | <node_id> | Retrieves persisted stack trace slice for a specific node ID |
k0maru flush | --vault <path> | Crystallizes decisions into vault matching local conventions |
--title <title> | Note title | |
--category <cat> | Note category (decision, log, concept, etc.) | |
--summary <text> | Executive summary | |
--tags <t1,t2> | Comma-separated tags | |
--related <r1,r2> | Comma-separated related note titles (linked as [[WikiLinks]]) | |
--dry-run | Previews destination path and generated note without writing | |
k0maru distill | --trace-file <path> | Distills raw execution trace into reusable skill note |
--target <ecosystem> | Export target: default (Obsidian) or hermes (Hermes Agent) | |
k0maru gc | --input <path> | Compacts multi-turn session trajectory with 4-tier GC protocol |
--threshold <N> | Line threshold for folding tool outputs (default: 20) | |
k0maru guard check | --diff | Audits git staged/unstaged diff against Living ADR rules (<10ms) |
--strict | Treats all warnings as blocking errors | |
--json | Outputs structured JSON guard report | |
k0maru guard install | --path <repo_dir> | Installs .git/hooks/pre-commit hook to block non-compliant commits |
k0maru mcp | --vault <path> | Starts stdio FastMCP service exposing all 8 memory tools |
--sidecar | Orthogonal 5-tool mode for omp (omits log offload and GC tools) | |
k0maru pack export | --name <name> --tag <tag> -o <file.pack.json> | Exports portable Memory Pack (.pack.json) of notes & ADRs |
k0maru pack import | <file.pack.json> [--dry-run] | Imports Memory Pack into LLM-Wiki adapting to local topology |
k0maru pack inspect | <file.pack.json> | Inspects pack contents, metadata, and predicted destination paths |
📊 Empirical Benchmarks: Cognitive Memory & Living ADR Guard
Empirically measured across a Google Colab Linux VM (Intel Xeon @ 2.20GHz, 12.67 GB RAM) protected by Zero-Burn Guard (runtime.unassign()), alongside local Apple M5 Pro Mac and Linux Workstation (company-pc):
| Benchmark Dimension | Baseline (Full Markdown RAG / Manual CI) | Google Colab Linux VM | Apple M5 Pro Mac | Architectural Advantage & Impact |
|---|---|---|---|---|
| Recall Payload Size (Single Memory) | 611 bytes (112 Tokens) | 164 bytes (22 Tokens) | 164 bytes (22 Tokens) | 73.16% Token Reduction via compact !μ: K-DSL wire |
Vault Index Sync (k0maru sync) | 500ms ~ 2,000ms | 34.48 ms | 9.50 ms | High-performance incremental SQLite + ONNX sync |
| Full Hybrid Search (BM25 + Vec) | 1,500ms+ (Remote API RAG) | 495.04 ms | 180.20 ms | 100% local ONNX embedding + RRF reciprocal rerank |
Living ADR Guard (guard check --diff) | Minutes (Human Review / CI) | 17.40 ms | 4.20 ms | Pre-commit AST invariant verification (<20ms) |
| Living ADR Rule Enforcement | Ad-hoc / Drift-prone | Strict Blocking (deny) | Strict Blocking (deny) | Prevents architectural erosion before code review |
🔒 Privacy & Cleanroom Principles
- 100% Local & Zero Telemetry: K0maru never collects, stores, or uploads your notes, code snippets, or queries. All indexing, vector inference, and guard evaluations run entirely on your physical machine.
- Open-Domain Evaluation Compliance: Benchmark data and rules are derived exclusively from public, compliant, and reproducible sources (SWE-bench agent trajectories, GitHub Actions public CI logs, BEIR/CoIR benchmarks). Zero private user data was involved. See docs/TUNING_AND_DATA.md.
🛠️ Customization & Tuning
- Vault Convention Tuning: Declare custom directory mappings in
.k0maru/rules.mdorAGENTS.md(e.g.,decisions: docs/adr,logs: 01_AI_Logs). - Living ADR Invariants: Add YAML frontmatter
invariantsto any ADR card in20_Cards/to immediately activate guardrails across your repositories. - Low-Resource Workstations: On memory-constrained devices (<1GB RAM), run with
--mode bm25for sub-millisecond keyword retrieval with zero ONNX memory overhead. - Offload Sensitivity: Adjust
--threshold <N>to match your model's context window. See Developer Tuning Guide.
🙏 Acknowledgments & Technical Ancestry
K0maru-Agent-Memory builds on foundational ideas from the open-source community:
- Andrej Karpathy (LLM-Wiki): Knowledge compounding via flat Markdown files, bidirectional links, and "filesystem as single source of truth".
- Tencent Cloud (TencentDB-Agent-Memory): "Mermaid Symbolic Log Offloading" and "L0–L3 Semantic Hierarchy". Clean-room reimplemented in 100% Rust as a standalone CLI filter and disposable cache.
- Colby McHenry (CodeGraph): Local Rust pre-indexing and graph topology models.
- Nous Research (Hermes Agent): Autonomous crystallization of skills from execution trajectories.
- Anthropic (Model Context Protocol): Standardized stdio JSON-RPC 2.0 communication.
- Open-Source Rust Ecosystem:
pulldown-cmark,rusqlite,sqlite-vec,fastembed-rs,axum, andclap.
⚖️ License
Distributed under the MIT License.