@plumpslabs/kuma 2.2.1 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Kuma
6
6
 
7
- **Zero-setup safety toolkit for AI coding agents.**
7
+ **Zero-setup safety & context runtime for AI coding agents — v2.2.2**
8
8
 
9
9
  [![npm](https://img.shields.io/npm/v/@plumpslabs/kuma.svg?logo=npm&color=red)](https://www.npmjs.com/package/@plumpslabs/kuma)
10
10
  [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
@@ -50,27 +50,27 @@ Or add Kuma MCP server manually to any MCP client:
50
50
 
51
51
  > **Kuma consolidates 46+ individual operations into 10 grouped tools.** AI agents scan 10 groups instead of 46 tools — simpler, faster, less context.
52
52
 
53
- | Group | Actions | When to call |
53
+ | Group | Actions | What it does |
54
54
  |-------|---------|-------------|
55
- | 🔵 `kuma_init` | `init`, `conventions`, `structure` | **Call first** every session |
56
- | 🟢 `kuma_core` | `grep`, `read`, `edit`, `batch`, `lsp` | During active coding |
57
- | 🟡 `kuma_verify` | `test`, `review`, `lint` | After every edit |
58
- | 🔴 `kuma_safety` | `guard` (anti-patterns, loops, drift), `score` (0-100 health), `check` (pre-exec safety), `policy` (`.kuma/policy.yml`), `risk` (impact prediction), `dependency` (native JS alternatives), `audit` (safety audit trail), `stats` (audit statistics), `override` (bypass safety) | Before risky ops |
59
- | 🟣 `kuma_graph` | `query` (nodes/edges/stats/search), `navigate`, `diagram`, `investigate`, `arch` (capture/diff/diagram/fs/graph/profiles), `experience` (suggest/errors/prune), `intent` (suggest/patterns) | Codebase understanding — powered by **SQLite knowledge graph** |
60
- | 🧠 `kuma_memory` | `get`, `search`, `write`, `decision`, `context`, `heal` | Persist/retrieve context |
61
- | 📊 `kuma_analytics` | `reflect`, `analytics`, `health`, `replay`, `heatmap`, `learn`, `predict`, `confidence`, `dna` | Session review |
62
- | ⏳ `kuma_history` | `timeline`, `log`, `diff` | Git/time analysis |
63
- | 🔒 `kuma_lock` | `acquire`, `release`, `list`, `clean` | Multi-agent coordination |
64
- | ⚙️ `kuma_advanced` | `failure`, `compress`, `shadow`, `collective` (sync patterns to VPS), `marketplace` (install templates) | Maintenance |
55
+ | 🔵 `kuma_init` | `init`, `conventions`, `structure` | **Call first** every session — load context, detect stack, show tree |
56
+ | 🟢 `kuma_core` | `grep`, `read`, `edit`, `batch`, `lsp` | During active coding — search, read, safe edit, create files, LSP queries |
57
+ | 🟡 `kuma_verify` | `test`, `review`, `lint` | After every edit — run tests, code review, static analysis |
58
+ | 🔴 `kuma_safety` | `guard`, `score`, `check`, `policy`, `risk`, `dependency`, `context`, `audit`, `stats`, `override` | Safety & risk anti-patterns, health score, pre-exec check, policy enforcement, impact analysis, dependency guard, snapshots, audit trail |
59
+ | 🟣 `kuma_graph` | `query`, `navigate`, `diagram`, `investigate`, `arch`, `experience`, `intent` | Codebase understanding — query knowledge graph, navigate flows, Mermaid diagrams, auto-investigate, architecture guard, experience patterns, intent paths |
60
+ | 🧠 `kuma_memory` | `get`, `search`, `write`, `decision`, `context`, `heal` | Persist/retrieve context — session memory, keyword search, persist knowledge, decisions (ADR), auto-context engine, self-heal graph |
61
+ | 📊 `kuma_analytics` | `reflect`, `analytics`, `health`, `replay`, `heatmap`, `learn`, `predict`, `confidence`, `dna` | Session review — on-track detection, stats dashboard, code health, session replay, activity heat map, AI learning, predictive next, confidence score, project DNA |
62
+ | ⏳ `kuma_history` | `timeline`, `log`, `diff` | Code history — symbol evolution timeline, commit log, structured diffs |
63
+ | 🔒 `kuma_lock` | `acquire`, `release`, `list`, `clean` | Multi-agent coordination — file-level locks, lock listing, stale cleanup |
64
+ | ⚙️ `kuma_advanced` | `failure`, `compress`, `shadow`, `collective`, `marketplace` | Maintenance failure knowledge base, semantic compression, shadow execution simulation, collective VPS sync, marketplace templates |
65
65
 
66
66
  ```bash
67
- # Example workflow
68
- kuma_init({ action: "init" }) # Load project context
69
- kuma_core({ action: "grep", query: "handleAuth" }) # Find code
70
- kuma_core({ action: "edit", filePath: "auth.ts", ... }) # Edit safely
71
- kuma_verify({ action: "test" }) # Verify didn't break
72
- kuma_safety({ action: "guard", goal: "refactor auth" }) # Safety check
73
- kuma_analytics({ action: "reflect" }) # Reflect on progress
67
+ # Full workflow example
68
+ kuma_init({ action: "init" }) # Load project context
69
+ kuma_core({ action: "grep", query: "handleAuth" }) # Find code
70
+ kuma_core({ action: "edit", filePath: "auth.ts", edits: [...] }) # Edit safely
71
+ kuma_safety({ action: "guard", goal: "refactor auth" }) # Safety check
72
+ kuma_verify({ action: "test" }) # Verify didn't break
73
+ kuma_analytics({ action: "reflect" }) # Reflect on progress
74
74
  ```
75
75
 
76
76
  ---
@@ -87,16 +87,118 @@ kuma_analytics({ action: "reflect" }) # Reflect on progress
87
87
  | 4 | **GitHub Copilot Editor** | `AGENTS.md` + `.github/skills/kuma/SKILL.md` | AGENTS.md + Skill file |
88
88
  | 5 | **Cline** | `.clinerules/kuma.md` | Rule file with `paths` frontmatter |
89
89
  | 6 | **Aider** | `CONVENTIONS.md` + `.aider.conf.yml` | Convention file referenced via `read: CONVENTIONS.md` |
90
- | 7 | **Antigravity CLI** | `.agents/skills/kuma/SKILL.md` + `.agents/mcp_config.json` | Skill (loaded on demand) |
90
+ | 7 | **Antigravity CLI** | `.agents/skills/kuma/SKILL.md` + `.agents/mcp_config.json` | Skill + MCP config |
91
91
  | 8 | **OpenCode** | `opencode.json` | Plugin config JSON |
92
92
  | 9 | **Codex CLI (OpenAI)** | `AGENTS.md` + `.codex/config.toml` | AGENTS.md + MCP server in TOML |
93
93
  | 10 | **Qwen Code** | `AGENTS.md` + `settings.json` | AGENTS.md + MCP server in JSON |
94
- | 11 | **Kiro** | `.kiro/steering/kuma.md` | Steering file with YAML frontmatter (`inclusion: always`) |
94
+ | 11 | **Kiro** | `.kiro/steering/kuma.md` | Steering file with YAML frontmatter |
95
95
  | 12 | **OpenClaw** | `skills/kuma/SKILL.md` | Skill (loaded on demand) |
96
96
  | 13 | **CodeWhale** | `skills/kuma/SKILL.md` + `.codewhale/mcp.json` | Skill + MCP server config |
97
97
 
98
- > `AGENTS.md` includes sections for all selected agents that read it (Codex CLI, Qwen Code, GitHub Copilot Editor) — one file, no conflicts.
99
- > `skills/kuma/SKILL.md` is shared by agents that load skills from workspace root.
98
+ > `AGENTS.md` is a merged file shared by Codex CLI, Qwen Code, and GitHub Copilot Editor — one file, no conflicts.
99
+
100
+ ---
101
+
102
+ ## Features
103
+
104
+ ### 🔍 Context & Understanding
105
+
106
+ | Feature | Tool / Action | Description |
107
+ |---------|--------------|-------------|
108
+ | **Smart Grep** | `kuma_core({ action: "grep" })` | Regex code search with context lines, caching, and `.gitignore` respect |
109
+ | **Smart File Picker** | `kuma_core({ action: "read" })` | Read files with chunking strategies: `full`, `smart` (signatures + tail), `outline` (exports only) |
110
+ | **Project Structure** | `kuma_init({ action: "structure" })` | Tree view of project layout with depth control, folder-only mode, patterns |
111
+ | **Project Conventions** | `kuma_init({ action: "conventions" })` | Auto-detect framework, test runner, package manager, monorepo workspaces |
112
+ | **LSP Query** | `kuma_core({ action: "lsp" })` | Go-to-definition, find references, type info, rename symbols via TypeScript Language Server. **Falls back to regex when LSP unavailable.** |
113
+ | **Code Time Machine** | `kuma_history({ action: "timeline" })` | Track how a function evolved over time — git blame + commit analysis + design decisions |
114
+ | **Git Log** | `kuma_history({ action: "log" })` | Structured commit history with file filtering |
115
+ | **Git Diff** | `kuma_history({ action: "diff" })` | Structured diff with staged/unstaged, ref ranges, context control |
116
+
117
+ ### 🧠 Knowledge Graph (SQLite)
118
+
119
+ Everything in Kuma is backed by a **SQLite knowledge graph** — auto-built, auto-healed, queryable:
120
+
121
+ | Feature | Tool / Action | Description |
122
+ |---------|--------------|-------------|
123
+ | **Graph Query** | `kuma_graph({ action: "query" })` | Query nodes/edges/stats. FTS5 full-text search with graceful fallback |
124
+ | **AI Navigation** | `kuma_graph({ action: "navigate" })` | Answer "How does login work?" — returns the full call chain |
125
+ | **Autonomous Investigation** | `kuma_graph({ action: "investigate" })` | Given a problem, auto-discovers the relevant code path + bottleneck |
126
+ | **Mermaid Diagrams** | `kuma_graph({ action: "diagram" })` | Generate architecture, sequence, impact, ownership, heatmap diagrams |
127
+ | **Living Architecture** | `kuma_graph({ action: "arch" })` | Auto-detect architecture (clean/layered/hexagonal/MVC), detect violations |
128
+ | **Experience Graph** | `kuma_graph({ action: "experience" })` | Learn from past sessions — suggests next tools based on success patterns |
129
+ | **Intent Graph** | `kuma_graph({ action: "intent" })` | Organize by intent, not dependency — suggests optimal paths for a goal |
130
+ | **Self-Healing** | `kuma_memory({ action: "heal" })` | Auto-detect stale nodes, repair via git history or content hash. Cascading edge cleanup |
131
+
132
+ ### ✏️ Execution — Make Changes Safely
133
+
134
+ | Feature | Tool / Action | Description |
135
+ |---------|--------------|-------------|
136
+ | **Precise Diff Editor** | `kuma_core({ action: "edit" })` | Search-and-replace with exact → whitespace → fuzzy fallback. **Auto-backup before every edit.** Dry-run preview, versioned rollback, batch edits (up to 10) |
137
+ | **Batch File Writer** | `kuma_core({ action: "batch" })` | Create up to 15 files in one call. Path validation before writing |
138
+ | **Static Analysis** | `kuma_verify({ action: "lint" })` | Run ESLint / TypeScript / Prettier / Ruff — structured output |
139
+ | **Code Reviewer** | `kuma_verify({ action: "review" })` | Senior-level static analysis. Focus modes: correctness, conventions, security, performance, **over-engineering detection** |
140
+
141
+ ### 🧠 Memory
142
+
143
+ | Feature | Tool / Action | Description |
144
+ |---------|--------------|-------------|
145
+ | **Session Memory** | `kuma_memory({ action: "get" })` | Session state tracker — modified files, unresolved failures, tool history |
146
+ | **Memory Search** | `kuma_memory({ action: "search" })` | Keyword search across tool calls, memory files, errors, dependency graph |
147
+ | **Persist Knowledge** | `kuma_memory({ action: "write" })` | Save decisions, glossary, architecture notes to `.kuma/memories/` |
148
+ | **Decision Memory** | `kuma_memory({ action: "decision" })` | ADR-style decision recording: context → options → rationale → outcome |
149
+ | **Context Engine** | `kuma_memory({ action: "context" })` | Auto-inject relevant context — finds files related to a goal via graph distance + recency + failure history |
150
+
151
+ ### 🛡️ Safety — Stay on Track
152
+
153
+ | Feature | Tool / Action | Description |
154
+ |---------|--------------|-------------|
155
+ | **Safety Guard** | `kuma_safety({ action: "guard" })` | Anti-pattern detection (script patching, bash grep), tool loops, drift (edits without tests) |
156
+ | **Safety Score** | `kuma_safety({ action: "score" })` | Aggregate 0-100 health score across 9 dimensions: git status, backups, LSP, tests, loops, etc. |
157
+ | **Safety Policy** | `kuma_safety({ action: "policy" })` | Policy file (`.kuma/policy.yml`) — `never_touch`, `require_review`, `require_tests`, `block_commands` |
158
+ | **Risk Prediction** | `kuma_safety({ action: "risk" })` | Before editing — shows references, test files, API routes affected |
159
+ | **Dependency Guard** | `kuma_safety({ action: "dependency" })` | Before adding packages — checks existing deps, suggests native JS alternatives |
160
+ | **Context Snapshots** | `kuma_safety({ action: "context" })` | Save/restore project state before risky operations |
161
+ | **Safety Audit** | `kuma_safety({ action: "audit" })` | Every tool call recorded in SQLite. Queryable trail with override logging |
162
+ | **Safety Check** | `kuma_safety({ action: "check" })` | Pre-execution safety check — validates path, policy, dangerous commands |
163
+
164
+ ### 📊 Analytics & Reflection
165
+
166
+ | Feature | Tool / Action | Description |
167
+ |---------|--------------|-------------|
168
+ | **Reflection** | `kuma_analytics({ action: "reflect" })` | On-track/off-track detection, drift warnings, next action suggestion |
169
+ | **Behavior Analytics** | `kuma_analytics({ action: "analytics" })` | Session stats — tool calls, edits, test runs, rollbacks, loops prevented |
170
+ | **Code Health Dashboard** | `kuma_analytics({ action: "health" })` | Project-level health — bug density, test pass rate, rollback rate, fragility scoring |
171
+ | **Session Replay** | `kuma_analytics({ action: "replay" })` | Replay what AI did in a previous session as a human-readable narrative |
172
+ | **Activity Heat Map** | `kuma_analytics({ action: "heatmap" })` | Show which parts of the codebase AI works on most |
173
+ | **AI Learning** | `kuma_analytics({ action: "learn" })` | Auto-prioritize high-usage patterns in the knowledge graph |
174
+ | **Predictive AI** | `kuma_analytics({ action: "predict" })` | Predict what file/tool AI needs next based on current context |
175
+ | **Confidence Engine** | `kuma_analytics({ action: "confidence" })` | Estimate how confident AI should be — factors: files read, refs checked, graph completeness |
176
+ | **Project DNA** | `kuma_analytics({ action: "dna" })` | One-page project fingerprint — architecture, coding style, coupling, risk areas, trends |
177
+
178
+ ### ⏳ History & Time Machine
179
+
180
+ | Feature | Tool / Action | Description |
181
+ |---------|--------------|-------------|
182
+ | **Symbol Timeline** | `kuma_history({ action: "timeline" })` | "Why does login work this way?" — traces a function's evolution across commits with design decisions |
183
+ | **Commit Log** | `kuma_history({ action: "log" })` | Structured commit history with file filter |
184
+ | **Git Diff** | `kuma_history({ action: "diff" })` | Staged/unstaged/ref-range diffs with configurable context |
185
+
186
+ ### 🔒 Multi-Agent
187
+
188
+ | Feature | Tool / Action | Description |
189
+ |---------|--------------|-------------|
190
+ | **File Locking** | `kuma_lock({ action: "acquire" })` | Prevent multiple AI agents from editing the same file simultaneously |
191
+ | **Lock Management** | `kuma_lock({ action: "list" })` | See active locks, clean stale ones |
192
+
193
+ ### ⚙️ Advanced
194
+
195
+ | Feature | Tool / Action | Description |
196
+ |---------|--------------|-------------|
197
+ | **Failure Knowledge Base** | `kuma_advanced({ action: "failure" })` | Every failure saved — type, symbol, solution. Proactive warnings for repeat patterns |
198
+ | **Semantic Compression** | `kuma_advanced({ action: "compress" })` | Compress large codebases into a semantic graph (type signatures + deps — no boilerplate) |
199
+ | **Shadow Execution** | `kuma_advanced({ action: "shadow" })` | Simulate changes before applying — virtual typecheck, test prediction, risk assessment |
200
+ | **Collective Intelligence** | `kuma_advanced({ action: "collective" })` | Sync anonymized patterns to your own VPS — learn from multiple projects |
201
+ | **Knowledge Marketplace** | `kuma_advanced({ action: "marketplace" })` | Install pre-built graph templates for popular frameworks |
100
202
 
101
203
  ---
102
204
 
@@ -104,7 +206,7 @@ kuma_analytics({ action: "reflect" }) # Reflect on progress
104
206
 
105
207
  **Kuma is built for one thing: making sure AI agents don't break your project.**
106
208
 
107
- Every tool in Kuma has a safety net built-in — not as an afterthought, but as a core design principle. Here's what Kuma guarantees:
209
+ Every tool in Kuma has a safety net built-in — not as an afterthought, but as a core design principle:
108
210
 
109
211
  | # | When this happens... | Kuma does this... |
110
212
  |---|---|---|
@@ -116,60 +218,17 @@ Every tool in Kuma has a safety net built-in — not as an afterthought, but as
116
218
  | 6 | AI keeps repeating the same tool | **Tool-loop detection** — flags if same tool called 4+ times in last 10 calls |
117
219
  | 7 | You need to undo an edit | **Versioned rollback** — `action: "rollback"` with `version: N` or `version: "list"` |
118
220
  | 8 | A diff doesn't match | **Fuzzy fallback** — exact → whitespace-normalized → fuzzy match with configurable threshold |
221
+ | 9 | AI needs to understand complex code | **Knowledge graph** — SQLite-backed, auto-built, queryable, self-healing |
222
+ | 10 | AI is about to break architecture | **Architecture guard** — detects layer violations, suggests correct dependency direction |
223
+ | 11 | AI has no context for a goal | **Auto-context engine** — finds relevant files via graph distance + recency + failure history |
224
+ | 12 | AI needs to know confidence | **Confidence engine** — 0-100 score based on context completeness |
225
+ | 13 | AI wants to know a file's history | **Code time machine** — shows why code is the way it is via git blame + commit analysis |
226
+ | 14 | Multiple agents edit the same file | **File lock** — prevents conflicts, clean stale locks |
119
227
 
120
228
  Most tools make AI smarter. **Kuma makes AI not break things.**
121
229
 
122
230
  ---
123
231
 
124
- ## Tools (19)
125
-
126
- ### 🔍 Context — Understand the codebase
127
-
128
- | Tool | Description |
129
- |------|-------------|
130
- | `smart_grep` | Search code with regex. Returns filename, line, and context. Caches results. |
131
- | `smart_file_picker` | Read files with smart chunking: `full` (entire file), `smart` (signatures + tail), `outline` (exports only). |
132
- | `project_structure` | Tree view of project layout. Depth control, folder-only mode, include/exclude patterns. |
133
- | `git_log` | Structured commit history with optional file filter. |
134
- | `git_diff` | Structured diff output. Supports staged/unstaged, file filter, ref ranges, and context line control. |
135
- | `lsp_query` | Go-to-definition, find references, get type info, **or rename symbols** via TypeScript Language Server. **Falls back to regex when LSP unavailable.** |
136
- | `project_conventions` | Auto-detect framework, test runner, package manager, import aliases, **monorepo workspaces**. |
137
- | `kuma_init` | **Call FIRST** every session. Loads `.kuma/init.md` rules, `.kuma/memories/`, previous session state, and **knowledge graph** from SQLite DB. After this, you can work without re-detecting conventions. |
138
-
139
- ### ✏️ Execution — Make changes safely
140
-
141
- | Tool | Description |
142
- |------|-------------|
143
- | `precise_diff_editor` | Search-and-replace with exact → whitespace → fuzzy fallback. **Auto-backup before every edit.** Supports **dry-run preview**, **versioned rollback** (`version: N`, `version: "list"`), and **batch edits** (up to 10 at once). |
144
- | `batch_file_writer` | Create up to 15 files in one call. Validates paths before writing. |
145
- | `static_analysis` | Run ESLint / TypeScript / Prettier / Ruff and **parse output into structured results.** Auto-detects tools from project config. |
146
-
147
- ### 🧪 Validation — Verify before breaking
148
-
149
- | Tool | Description |
150
- |------|-------------|
151
- | `execute_safe_test` | Run `test`/`build`/`lint`/`typecheck`/`custom` with **timeout, circuit breaker, and process tree kill.** Supports **monorepo workspaces** via `workspace` param or relative `cwd`. |
152
- | `code_reviewer` | Senior-level static analysis. Focus modes: correctness, conventions, security, performance, and **over-engineering detection.** Supports JSON output. |
153
-
154
- ### 🧠 Memory — Know what happened
155
-
156
- | Tool | Description |
157
- |------|-------------|
158
- | `get_session_memory` | Session state tracker. Shows modified files, unresolved failures, tool history. Load specific memory topics with `{ topic }`. |
159
- | `search_session_memory` | **Keyword search** across tool calls, memory files, errors, modified files, and dependency graph. |
160
- | `write_memory` | Persist project knowledge (decisions, glossary) to `.kuma/memories/`. Append, prepend, or overwrite. |
161
- | `kuma_reflect` | **Reflection tool** — checks if you're on track, detects drift (edits without tests, loops, unresolved failures), and suggests the next action. |
162
- | `kuma_context` | **Snapshot manager** — save/restore project state (modified files, errors, git diff) before risky operations. |
163
-
164
- ### 🛡️ Safety — Stay on track
165
-
166
- | Tool | Description |
167
- |------|-------------|
168
- | `kuma_guard` | **Context safety net.** Detects anti-patterns (script patching, bash grep), tool loops, drift (edits without tests, unresolved failures). Run this after every few edits. Checks: `all`, `anti-pattern`, `loop`, `drift`, `context`. |
169
- | `kuma_safety` | **Safety AI Layer.** Actions: `audit` (query trail), `stats` (audit statistics), `override` (bypass safety, logged). `precise_diff_editor` auto-wrapped with safety proxy. |
170
-
171
- ---
172
-
173
232
  ## Safety
174
233
 
175
234
  | Feature | What it does |
@@ -183,52 +242,115 @@ Most tools make AI smarter. **Kuma makes AI not break things.**
183
242
  | **LSP graceful degradation** | When TypeScript Language Server is not installed, LSP tools **fall back to regex** instead of hard failing. |
184
243
  | **Multi-agent lock** | File-level locks prevent multiple AI agents from editing the same file simultaneously. |
185
244
  | **Safety score** | Aggregate 0-100 score across 9 dimensions: git status, backups, LSP, tests, modified files, loops, failures, conventions, goal. |
245
+ | **Safety policy** | `.kuma/policy.yml` — declare `never_touch` files, `require_review` paths, `block_commands`. |
246
+ | **Risk prediction** | Before editing a symbol — shows 42 references in 15 files, 7 test files, 3 API routes. |
247
+ | **Dependency guard** | When AI installs a new package — checks existing deps, suggests native alternatives. |
248
+ | **Safety audit** | Every tool call recorded in SQLite. Queryable trail with override logging. |
186
249
 
187
250
  ---
188
251
 
189
252
  ## What Makes Kuma Unique
190
253
 
191
254
  - **Router groups** — 46+ operations consolidated into 10 grouped tools. AI scans 10 groups instead of 46 tools.
192
- - **Workflow combo** — `kuma_init → kuma_core → kuma_verify → kuma_safety → kuma_analytics` as a seamless pipeline.
193
255
  - **Knowledge Graph (SQLite)** — Built-in SQLite database via `sql.js` (pure WASM, zero native build). Tracks nodes (functions, files, API routes, tests) + edges (calls, imports, defines, tests) + experience patterns + sessions. FTS5 full-text search with graceful fallback.
256
+ - **Self-healing graph** — Automatically detects stale nodes, repairs via git history or content hash fingerprinting.
194
257
  - **Safety is default, not optional** — Rollback, circuit breaker, sandbox, timeout, dangerous pattern blocking are built into every tool.
195
258
  - **Graceful degradation** — When dependencies are missing (LSP, linters, FTS5), Kuma falls back instead of crashing.
196
259
  - **Over-engineering detection** — `code_reviewer` with `focus: "over-engineering"` catches unnecessary abstractions.
197
260
  - **Drift detection** — `kuma_guard` catches edits without tests, tool-call loops, unresolved failures.
198
261
  - **Impact prediction** — `kuma_risk` tells you how many files reference a symbol before you change it.
262
+ - **Auto-context engine** — Given a goal, finds relevant files via graph distance + recency + failure history.
263
+ - **Code time machine** — Shows why code is the way it is: "Because commit e4f5g6h migrated from sessions to JWT for mobile support."
264
+ - **Mermaid diagrams** — Auto-generated architecture, sequence, impact, ownership, and heatmap diagrams from the knowledge graph.
265
+ - **Architecture guard** — Detects layer violations (Handler → Database when it should be Handler → Service → Repository).
266
+ - **Confidence engine** — 0-100 score estimating how confident AI should be about a change.
267
+ - **Shadow execution** — Simulate changes before applying: virtual typecheck, test prediction, risk assessment.
268
+ - **Failure knowledge base** — Every failure saved and becomes a learning. Proactive warnings.
199
269
  - **Dependency guard** — Before adding npm packages, checks for native JS alternatives and existing similar packages.
200
- - **Persistent memory** — Knowledge survives across sessions via `.kuma/memories/` + `.kuma/kuma.db`. Auto-generates architecture & conventions docs.
270
+ - **Persistent memory** — Knowledge survives across sessions via `.kuma/memories/` + `.kuma/kuma.db`.
201
271
  - **Monorepo awareness** — Detects workspaces, scans `apps/*`, `packages/*`, `services/*`, and pnpm/yarn/npm workspaces.
272
+ - **Collective intelligence** — Anonymized pattern sharing across projects via your own VPS. Zero source code leakage.
273
+ - **Knowledge marketplace** — Pre-built graph templates for Laravel, Spring Boot, Django, Gin, Axum, Next.js, Express.js, and more.
202
274
 
203
275
  ### Storage Layout
204
276
 
205
277
  ```
206
278
  .kuma/
207
- ├── kuma.db # SQLite database (knowledge graph, sessions, experiences)
208
- ├── init.md # Behavioral rules for AI agents (auto-generated)
209
- ├── config.json # Per-project config (collective endpoint, autoSync, etc.)
210
- ├── memory.json # Session state (modified files, failures, tool history)
211
- └── memories/ # Persistent knowledge files
279
+ ├── kuma.db # SQLite database (knowledge graph, sessions, experiences, safety audit)
280
+ ├── init.md # Behavioral rules for AI agents (auto-generated)
281
+ ├── config.json # Per-project config (collective endpoint, autoSync, etc.)
282
+ ├── memory.json # Session state (modified files, failures, tool history)
283
+ ├── policy.yml # Safety policy (never_touch, require_review, block_commands)
284
+ ├── .instance-id # Anonymous instance ID for collective sync
285
+ └── memories/ # Persistent knowledge files
212
286
  ├── architecture.md
213
287
  ├── conventions.md
214
288
  ├── decisions.md
215
289
  ├── glossary.md
216
290
  └── known-issues.md
217
291
 
218
- .kuma/backups/ # Versioned backups from precise_diff_editor
219
- └── <timestamp>/ # One backup snapshot per edit
292
+ .kuma/backups/ # Versioned backups from precise_diff_editor
293
+ └── <timestamp>/ # One backup snapshot per edit
220
294
  └── <relative-file-path>
221
295
  ```
222
296
 
223
297
  ---
224
298
 
225
- ## Kuma's DNA
299
+ ## 🔄 Self-Healing
300
+
301
+ Kuma automatically detects and repairs issues in the knowledge graph:
302
+
303
+ ```bash
304
+ # Check for stale entries
305
+ kuma_memory({ action: "heal", healAction: "check" })
226
306
 
227
- 1. **Zero setup, zero friction** Built-in tools that work without config. No DB, no API key.
228
- 2. **Safety first** — Every tool has a safety net: timeout, circuit breaker, rollback, sandbox.
229
- 3. **Graceful degradation, not crash** — Every tool has a fallback before it fails. LSP unavailable? Regex. File not found? Show resolved paths. Diff mismatch? Whitespace→fuzzy retry. Test fails? Circuit breaker stops the loop. FTS5 unavailable? Full-text search disabled gracefully.
230
- 4. **Opinionated workflow** — Tools designed to be used together: `kuma_init → kuma_core → kuma_verify → kuma_safety → kuma_analytics`.
231
- 5. **Minimal surface** 19 focused tools. Each tool has one job and does it well. No overlap, no confusion.
307
+ # Auto-healremove stale nodes/edges
308
+ kuma_memory({ action: "heal" })
309
+ ```
310
+
311
+ | Feature | Description |
312
+ |---------|-------------|
313
+ | **Content Hash** | Detects files that changed since last scan (MD5 of head + tail + size) |
314
+ | **All-Node Scan** | Scans all node types: `file`, `function`, `class`, `interface`, `module`, `test`, etc. |
315
+ | **Git-Aware Repair** | Uses `git log --follow --diff-filter=R` to trace file renames |
316
+ | **Cascading Edges** | Stale node edges get weight reduced to near-zero |
317
+ | **Incremental Heal** | Batch processing — repairs only the affected subgraph, not full scan |
318
+ | **Auto-Heal Hook** | Runs automatically during graph queries — no manual action needed |
319
+
320
+ ---
321
+
322
+ ## 🛡️ Safety AI Layer
323
+
324
+ The Safety layer sits between AI agents and the filesystem. Every tool call goes through: policy check, path validation, audit logging.
325
+
326
+ ### Features
327
+
328
+ | Feature | Description |
329
+ |---------|-------------|
330
+ | **Safety Audit** | Every tool call recorded in SQLite (`safety_audit`). Queryable. |
331
+ | **Safety Proxy** | `precise_diff_editor` is auto-wrapped — runs preCheck before execution. |
332
+ | **Risk Assessment** | Path validation, policy checks, dangerous command detection. |
333
+ | **Override Logging** | Safety bypasses are logged with reasons — audit trail stays clean. |
334
+ | **Safety Score** | 0-100 aggregate health score across 9 dimensions. |
335
+
336
+ ### Usage
337
+
338
+ ```bash
339
+ # Query audit trail (20 most recent entries)
340
+ kuma_safety({ action: "audit", limit: 20 })
341
+
342
+ # Audit statistics
343
+ kuma_safety({ action: "stats" })
344
+
345
+ # Full safety check before execution
346
+ kuma_safety({ action: "check", actionCheck: "edit", filePath: "config.ts" })
347
+
348
+ # Safety Score
349
+ kuma_safety({ action: "score" })
350
+
351
+ # Bypass safety (logged with reason)
352
+ kuma_safety({ action: "override", tool: "precise_diff_editor", reason: "trusted edit" })
353
+ ```
232
354
 
233
355
  ---
234
356
 
@@ -311,36 +433,29 @@ Or via `.kuma/config.json`:
311
433
  | `GET` | `/api/v1/patterns?lang=go` | Get global patterns by language |
312
434
  | `GET` | `/api/v1/stats` | Dashboard statistics |
313
435
 
314
- ### Usage from Kuma
436
+ ### Trigger Manual via AI
437
+
438
+ Sync is **manually triggered** by the AI agent calling the Kuma tool. There is no background scheduler — the AI decides when to sync based on context.
315
439
 
316
440
  ```bash
317
- # Sync patterns to your VPS
441
+ # Sync patterns to your VPS (sends + receives)
318
442
  kuma_advanced({ action: "collective", collectiveAction: "sync" })
319
443
 
320
- # Export anonymized preview
444
+ # Preview what data would be sent (safe preview)
321
445
  kuma_advanced({ action: "collective", collectiveAction: "export" })
322
446
 
323
- # Discover patterns from VPS
447
+ # Discover local patterns without sending
324
448
  kuma_advanced({ action: "collective" })
325
449
  ```
326
450
 
451
+ > 💡 The `autoSync` flag in config tells the AI to remember syncing periodically — but the actual call is always made by the AI agent, not by a timer.
452
+
327
453
  ---
328
454
 
329
455
  ## 📦 Knowledge Marketplace
330
456
 
331
457
  Marketplace provides **pre-built knowledge graph templates** for popular frameworks. Installing a template means Kuma instantly understands the framework's structure without having to learn from scratch.
332
458
 
333
- ### What happens when you install a template?
334
-
335
- Templates inject nodes (modules, files, functions) and edges (depends_on, imports) into Kuma's SQLite graph. Results:
336
-
337
- | Before Installing | After Installing `graph:laravel` |
338
- |-------------------|----------------------------------|
339
- | Kuma doesn't know if `User.php` is a Model or Controller | Kuma knows `User.php` extends `Authenticatable` → Model |
340
- | `kuma_graph({ action: "navigate", query: "find controllers" })` fails | Can answer: "AuthController, UserController in app/Http/Controllers/" |
341
- | Empty graph — Kuma starts from zero | Graph knows Laravel MVC architecture from the start |
342
- | Intent prediction is less accurate | Predictions improve — knows Controller → Service → Repository patterns |
343
-
344
459
  ### Usage
345
460
 
346
461
  ```bash
@@ -392,68 +507,7 @@ kuma_advanced({ action: "marketplace", marketplaceAction: "install", template: "
392
507
  | `graph:gin` | Gin (Go) | Handlers, Services, Repositories, Middleware, Models | 25 | 65 |
393
508
  | `graph:axum` | Axum (Rust) | Handlers, Extractors, Services, Repositories, State | 20 | 55 |
394
509
 
395
- ### Distribution via npm
396
-
397
- Templates can also be installed via npm to persist across projects:
398
- ```bash
399
- npm install @kuma-templates/laravel-graph
400
- ```
401
-
402
- ---
403
-
404
- ## 🔄 Self-Healing (3.4)
405
-
406
- Kuma automatically detects and repairs issues in the knowledge graph:
407
-
408
- ```bash
409
- # Check for stale entries
410
- kuma_memory({ action: "heal", healAction: "check" })
411
-
412
- # Auto-heal — remove stale nodes/edges
413
- kuma_memory({ action: "heal" })
414
- ```
415
-
416
- | Feature | Description |
417
- |---------|-------------|
418
- | **Content Hash** | Detects files that changed since last scan |
419
- | **All-Node Scan** | Scans all nodes, not just modified ones |
420
- | **Cascading Edges** | Removes edges when their source node is deleted (cascade) |
421
- | **Incremental Heal** | Batch processing — 50 nodes per cycle, non-blocking |
422
- | **Auto-Heal Hook** | Runs automatically after edits — no manual action needed |
423
-
424
- ---
425
-
426
- ## 🛡️ Safety AI Layer
427
-
428
- The Safety layer sits between AI agents and the filesystem. Every tool call goes through: policy check, path validation, audit logging.
429
-
430
- ### Features
431
-
432
- | Feature | Description |
433
- |---------|-------------|
434
- | **Safety Audit** | Every tool call is recorded in SQLite (`safety_audit`). Queryable. |
435
- | **Safety Proxy** | `precise_diff_editor` is auto-wrapped — runs preCheck before execution. |
436
- | **Risk Assessment** | Path validation, policy checks, dangerous command detection. |
437
- | **Override Logging** | Safety bypasses are logged with reasons — audit trail stays clean. |
438
-
439
- ### Usage
440
-
441
- ```bash
442
- # Query audit trail (20 most recent entries)
443
- kuma_safety({ action: "audit", limit: 20 })
444
-
445
- # Audit statistics
446
- kuma_safety({ action: "stats" })
447
-
448
- # Bypass safety (logged with reason)
449
- kuma_safety({ action: "override", tool: "precise_diff_editor", reason: "trusted edit" })
450
- ```
451
-
452
- ### Full Safety Check
453
- ```bash
454
- # Full safety check before execution
455
- kuma_safety({ action: "check", actionCheck: "edit", filePath: "config.ts" })
456
- ```
510
+ > ⚠️ `@kuma-templates/*` packages do not exist on npmjs yet. All built-in templates are generated from Kuma's source code directly — no npm install needed. The npm path exists for future community-published templates.
457
511
 
458
512
  ---
459
513
 
@@ -480,6 +534,8 @@ npx @plumpslabs/kuma init --all # Install kuma safety tools
480
534
  Both tools are designed to complement each other — Kuma handles the
481
535
  "can't break things" layer while Matcha handles the "think before you act" layer.
482
536
 
537
+ ---
538
+
483
539
  ## Contributing
484
540
 
485
541
  See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getProjectRoot
3
- } from "./chunk-7Q3YUJSM.js";
3
+ } from "./chunk-T55NCW63.js";
4
4
 
5
5
  // src/utils/agentDetector.ts
6
6
  import fs from "fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getProjectRoot
3
- } from "./chunk-7Q3YUJSM.js";
3
+ } from "./chunk-T55NCW63.js";
4
4
 
5
5
  // src/cli/init.ts
6
6
  import fs from "fs";
@@ -150,6 +150,9 @@ function getKumaDir() {
150
150
  const root = getProjectRoot();
151
151
  return path.join(root, ".kuma");
152
152
  }
153
+ function getKumaBackupsDir() {
154
+ return path.join(getKumaDir(), "backups");
155
+ }
153
156
 
154
157
  export {
155
158
  validateFilePath,
@@ -157,5 +160,6 @@ export {
157
160
  getProjectRoot,
158
161
  getBackupPath,
159
162
  ensureBackupDir,
160
- getKumaDir
163
+ getKumaDir,
164
+ getKumaBackupsDir
161
165
  };