knit-mcp 0.9.0 → 0.10.0

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
@@ -1,73 +1,63 @@
1
1
  <p align="center">
2
2
  <a href="https://www.npmjs.com/package/knit-mcp"><img src="https://img.shields.io/npm/v/knit-mcp?style=for-the-badge&color=7c3aed&label=npm" alt="npm version" /></a>
3
- <img src="https://img.shields.io/badge/license-MIT-blue?style=for-the-badge" alt="license" />
4
- <a href="https://github.com/PDgit12/knit/actions/workflows/ci.yml"><img src="https://github.com/PDgit12/knit/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
5
- <img src="https://img.shields.io/badge/node-%3E%3D18-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="node" />
3
+ <a href="https://github.com/PDgit12/knit/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/PDgit12/knit/ci.yml?style=for-the-badge&label=CI&color=10b981" alt="CI" /></a>
4
+ <img src="https://img.shields.io/badge/license-MIT-3b82f6?style=for-the-badge" alt="license" />
5
+ <img src="https://img.shields.io/badge/node-%E2%89%A518-339933?style=for-the-badge&logo=node.js&logoColor=white" alt="node" />
6
+ <img src="https://img.shields.io/badge/tests-492%20passing-22c55e?style=for-the-badge" alt="tests" />
7
+ <img src="https://img.shields.io/badge/MCP%20tools-43-7c3aed?style=for-the-badge" alt="tools" />
6
8
  </p>
7
9
 
8
- <h1 align="center">knit</h1>
10
+ <h1 align="center">🧶 knit</h1>
9
11
 
10
12
  <p align="center">
11
- <strong>An intelligent command layer for Claude Code.</strong>
12
- <br/>
13
- Project-scoped memory, on-demand workflow protocol, parallel team worktrees,<br/>
14
- and honest token accounting — all in one MCP server.
13
+ <strong>An intelligent command layer for Claude Code.</strong><br/>
14
+ Project-scoped memory · on-demand workflow · parallel team worktrees · honest token accounting.<br/>
15
+ <em>All in one MCP server.</em>
15
16
  </p>
16
17
 
17
- <br/>
18
-
19
- ## What knit is
20
-
21
- Knit makes Claude Code do the right thing automatically because it can't predict how a user will phrase a request. It does three jobs at once:
22
-
23
- - **Memory** — every project keeps a brain at `~/.knit/projects/<hash>/`. Sessions compound: learnings, false positives, session summaries, and a static-analysis import graph are all queryable next session.
24
- - **Tokens** — `CLAUDE.md` is ~100 lines (project facts only). Workflow protocol is fetched on demand via `knit_get_workflow(phase)`. Knit is net-negative on context cost.
25
- - **Workflow** — a 4-tier classification (Inquiry / Trivial / Standard / Complex) with phase-triggered plan mode, quality-gated `LEARN`, and team-scoped git worktrees so parallel agents don't step on each other.
26
-
27
- It's a **single product**, not three. Every design choice has to win on memory + tokens + workflow together.
18
+ <p align="center">
19
+ <a href="#-quick-start">Quick start</a> ·
20
+ <a href="#-what-knit-is">What it is</a> ·
21
+ <a href="#-whats-new-in-v090">v0.9</a> ·
22
+ <a href="#-43-mcp-tools">Tools</a> ·
23
+ <a href="#-how-its-different">Comparison</a>
24
+ </p>
28
25
 
29
- ## What's new in v0.7.0
26
+ ---
30
27
 
31
- - **Universal protocol injection.** Knit sets the MCP server-level `instructions` field, so every MCP client (Claude Code, Cursor, Codex) sees Knit's flow at session start — *before* tool descriptions. Session 1 follows the protocol instead of stumbling onto it.
32
- - **Tier-gated tool surface.** 38 tools split into three tiers: Tier 1 (26 universal — memory, knowledge graph, workflow, classification, false-positive suppression, reflection, Protocol Guard config, diagnostics) is always exposed. Tier 2 (team worktrees, subagent installer) auto-activates when the project shape matches (≥3 detected domains, `.claude/agents/` exists) or via explicit opt-in. Tier 3 (admin/setup) is opt-in only. Solo-domain projects no longer see 9 team-worktree tools cluttering their decision space.
33
- - **`knit_list_features`** is the discoverability escape hatch — always available, always tells you what's hidden and exactly how to enable it (`knit_enable_feature({feature: "teams" | "subagents" | "admin"})`). Persisted to `~/.knit/projects/<hash>/features.json` so the choice survives sessions.
34
- - **Inquiry tier in the classifier.** Read-only "what / where / audit / explain" tasks now route to `tier: "inquiry"` with no plan mode and no phases — fixes a long-standing over-routing bug where audit-style questions hijacked Complex.
35
- - **CLAUDE.md cut ~88%** (16.7 KB → ~2 KB on typical projects). The per-turn context tax dropped sharply; all project-specific content (header, project map, domain architecture, build gates, false positives) stays intact.
36
- - **Lazy / minimal response modes.** `knit_load_session` returns the lean core by default; opt into more via `include=patterns,teams,metrics,recent_sessions,full_learnings,full_knowledge,all`. `knit_classify_task` returns the minimal shape by default; pass `verbose=true` for the diagnostic fields.
37
- - **Legacy CLAUDE.md migration.** Users upgrading from v0.5.x with `<!-- engram:start -->/<!-- engram:end -->` markers are auto-migrated — the legacy block is replaced cleanly with the new lean block instead of leaving an orphan.
28
+ ## 🧠 What knit is
38
29
 
39
- ### Per-session token-budget table
30
+ Knit makes Claude Code do the right thing automatically — because you can't predict how a user will phrase a request. It does three jobs at once:
40
31
 
41
- | Surface | v0.6.5 | v0.7.0 | Cut |
42
- |---|---|---|---|
43
- | CLAUDE.md per-turn | ~16.7 KB | ~2 KB | 88% |
44
- | Tool registry (typical project) | ~6–8 KB | ~3–4 KB | ~50% |
45
- | `knit_classify_task` response | ~500 tok | ~150 tok | 70% |
46
- | `knit_load_session` response | ~3–5 KB | ~1.5 KB | ~60% |
32
+ | | |
33
+ |---|---|
34
+ | 🧠 **Memory** | Every project keeps a brain at `~/.knit/projects/<hash>/`. Sessions compound: learnings, false positives, session summaries, and a static-analysis import graph are all queryable next session. |
35
+ | 🪶 **Tokens** | `CLAUDE.md` is ~2 KB (project facts only). Protocol depth is fetched on demand via `knit_get_workflow(phase)`. Knit is **net-negative** on context cost. |
36
+ | 🛠️ **Workflow** | A 4-tier classification (Inquiry / Trivial / Standard / Complex) with phase-triggered plan mode, quality-gated `LEARN`, and team-scoped git worktrees so parallel agents don't step on each other. |
47
37
 
48
- ### Upgrade note
38
+ It's a **single product**, not three. Every design choice has to win on memory + tokens + workflow together.
49
39
 
50
- After running `npx knit-mcp@latest setup` (or just updating the version pin), **restart Claude Code**. The MCP server's `instructions` field and tier-gated `tools/list` only flow into the system prompt at handshake — the cached process from before the upgrade keeps the v0.6.5 behavior until restart.
40
+ ---
51
41
 
52
- ## Setup (one time)
42
+ ## 🚀 Quick start
53
43
 
54
44
  ```bash
55
45
  npx knit-mcp@latest setup
56
46
  ```
57
47
 
58
- Adds the Knit MCP server to your Claude Code config (`~/.claude.json`). No per-project setup. Open Claude Code in any project and the first MCP tool call auto-initializes everything.
59
-
60
- **Supported shells:** macOS, Linux, WSL, Git Bash, and Windows PowerShell. The generated hooks use POSIX-style single-quoted `node -e '…'` payloads. Windows `cmd.exe` does not treat single quotes as delimiters and is not supported as the hook-runner shell — on Windows, use PowerShell (default in modern Windows Terminal) or Git Bash. If you hit a hook error on Windows, file an issue with the shell you're using.
48
+ Adds the Knit MCP server to your Claude Code config (`~/.claude.json`). **No per-project setup.** Open Claude Code in any project the first MCP tool call auto-initializes the brain, hooks, and per-project CLAUDE.md block.
61
49
 
62
- ### Quiet mode (no hook enforcement)
50
+ > **Supported shells:** macOS, Linux, WSL, Git Bash, PowerShell. Windows `cmd.exe` is not supported as the hook-runner shell — use PowerShell (default in modern Windows Terminal) or Git Bash.
63
51
 
64
- Knit ships Protocol Guard in `warn` mode by default — hooks print reminders, they never block. If you want it fully silent (no PreToolUse classification gate, no reminder messages), run this once inside Claude Code:
52
+ ### Quiet mode
65
53
 
66
- > `knit_set_protocol_strictness({ level: "off" })`
54
+ Knit ships **Protocol Guard in `warn` mode by default** — hooks print reminders, they never block. Fully silent:
67
55
 
68
- The other hooks (LEARN compliance, KB metrics, final build verification) stay as observability nudges — they print, they don't gate. To remove them too, see Uninstall below.
56
+ ```js
57
+ knit_set_protocol_strictness({ level: "off" })
58
+ ```
69
59
 
70
- ### Uninstall
60
+ ### Uninstall in 30 seconds
71
61
 
72
62
  ```bash
73
63
  rm -rf ~/.knit # all per-project + global memory
@@ -76,13 +66,173 @@ rm -rf ~/.knit # all per-project + global memory
76
66
  Then:
77
67
  1. Remove `"knit-brain"` from `mcpServers` in `~/.claude.json`
78
68
  2. Delete the `<!-- knit:start --> ... <!-- knit:end -->` block from each project's `CLAUDE.md`
79
- 3. Remove `_knitOwned` entries from each project's `.claude/settings.local.json` (or delete the file if Knit was the only thing in it)
69
+ 3. Remove `_knitOwned` entries from each project's `.claude/settings.local.json`
70
+
71
+ Knit writes nowhere else on your machine.
72
+
73
+ ---
74
+
75
+ ## ✨ What's new in v0.9.0
76
+
77
+ v0.9 closes the **enforcement story** — every honest limit from the v0.8 architecture got a structural fix.
80
78
 
81
- Total time: ~30 seconds per project. Knit doesn't write anywhere else on your machine.
79
+ ### Anti-hallucination
80
+
81
+ - 📎 **Citation rule in the MCP `instructions` field.** Every session's system prompt now tells the agent: *"when you state a fact about this codebase, cite the Knit tool result that verified it — e.g. (per `knit_query_imports`). If you can't cite, say 'unverified' explicitly."* Makes hallucinations visible at the **claim level**.
82
+ - 🔍 **`knit_verify_claim` tool.** Single-call fact-check against the knowledge graph. Parses *"A imports B"*, *"X exports Y"*, *"A is tested by B"*, *"X exists"* and returns `verified | contradicted | unparseable` with evidence.
83
+
84
+ ### Smarter retrieval
85
+
86
+ - ⚡ **Auto-search inside `knit_classify_task`.** For `standard` / `complex` tier, classify now runs BM25 over (description + affected domains) automatically and embeds top-3 hits as `pre_emptive_learnings`. Closes the *"agent skipped `knit_search_learnings` before re-investigating"* gap with **zero extra calls**.
87
+ - 📚 **`suggested_reads` from `knit_build_context`.** Curated list of files worth opening *before* editing — three signals: graph-importers (blast radius), graph-imports (likely needed), memory-mentions (files referenced by past learnings). Each entry carries `{ path, reason, via }`.
88
+ - 🪜 **`knit_get_learning` — hierarchical retrieval.** Search returns headlines (summary + tags); the agent expands a specific learning by id only when needed. **Pay-per-detail.**
89
+ - 🧮 **`knit_consolidate_learnings`.** Tag-Jaccard clustering of similar learnings → one pattern entry per cluster. Dry-run by default; `commit=true` persists with originals tagged `#consolidated` (preserved but deprioritized).
90
+
91
+ ### Hook-level enforcement (`HOOKS_VERSION` 6 → 7)
92
+
93
+ | Hook | What it does |
94
+ |---|---|
95
+ | **PreToolUse search-gate** | For `standard`/`complex` tasks, blocks Edit/Write (in `block` mode) or warns (default `warn`) when `knit_search_learnings` hasn't fired in the current turn. |
96
+ | **PreToolUse content inspection** | Reads proposed Edit/Write content, parses local imports, warns on relative paths that don't resolve on disk — **catches hallucinated imports before they land**. |
97
+ | **PostToolUse import validation** | After the file lands, re-parses imports and warns about unresolved relative paths — catches anything that slipped past the pre-check. |
98
+ | **Stop-hook budget watch** | Cheap CLAUDE.md size check at session end; warns if it crosses the 12.5 KB over-budget threshold. Drift becomes visible even when the agent doesn't call `knit_brain_status`. |
99
+
100
+ > **Upgrade note.** After `npx knit-mcp@latest setup`, **restart Claude Code**. The `instructions` field and tier-gated `tools/list` only flow into the system prompt at handshake. The `HOOKS_VERSION` bump auto-regenerates installed hooks on the next brain load — no manual `knit refresh` needed.
101
+
102
+ ---
103
+
104
+ ## 📉 Token budget — measured, not vibes
105
+
106
+ | Surface | v0.6.5 | v0.9.0 | Cut |
107
+ |---|---|---|---|
108
+ | CLAUDE.md per-turn | ~16.7 KB | **~2 KB** | **88%** |
109
+ | Tool registry (typical project) | ~6–8 KB | **~3–4 KB** | ~50% |
110
+ | `knit_classify_task` response | ~500 tok | **~150 tok** | 70% |
111
+ | `knit_load_session` response | ~3–5 KB | **~1.5 KB** | ~60% |
112
+
113
+ Each surface gets a `healthy | warn | over-budget` verdict from `knit_brain_status.token_budget`. **Drift is a regression test, not a vibes claim.**
114
+
115
+ ---
116
+
117
+ ## 🛠️ 43 MCP Tools
118
+
119
+ <details open>
120
+ <summary><strong>🕸️ Knowledge graph</strong> <em>(Tier 1, ~5ms)</em></summary>
121
+
122
+ | Tool | What it does |
123
+ |---|---|
124
+ | `knit_query_imports` | Reverse dependencies — who imports this file. |
125
+ | `knit_query_dependents` | Forward dependencies — what this file imports. |
126
+ | `knit_query_exports` | Functions / classes / interfaces / types this file exposes. |
127
+ | `knit_query_tests` | Test coverage for a file, or list all untested with `filter=untested`. |
128
+ | `knit_find_fanout` | High-fanout files — the contracts to change carefully. |
129
+ | `knit_verify_claim` | **v0.9.** Fact-check one claim against the graph — `verified \| contradicted \| unparseable` with evidence. |
82
130
 
83
- ## How data is stored
131
+ </details>
84
132
 
85
- Knit data is centralized — not in every repo's working tree:
133
+ <details open>
134
+ <summary><strong>📚 Memory + retrieval</strong> <em>(Tier 1)</em></summary>
135
+
136
+ | Tool | What it does |
137
+ |---|---|
138
+ | `knit_load_session` | Call at session start — returns handoff, top learnings, false positives, project knowledge. Lazy by default; opt in via `include=patterns,teams,metrics,recent_sessions,full_learnings,full_knowledge,all`. |
139
+ | `knit_search_learnings` | **v0.8+.** BM25 + import-graph hybrid. `query=text` for BM25, `domains=#tag` for tag filter, `files=src/a.ts` for graph-neighborhood boost. Fused via RRF (k=60). |
140
+ | `knit_search_sessions` | BM25 over session summaries + branch + commits + tags. Branch-diversified (max 2 per branch) — one feature branch can't flood. |
141
+ | `knit_search_global_learnings` | BM25 across the cross-project pool at `~/.knit/global/learnings.jsonl`. |
142
+ | `knit_get_learning` | **v0.9.** Fetch one full learning by id. Pair with search (headlines) for hierarchical retrieval. |
143
+ | `knit_record_learning` | Save a non-obvious insight. Quality check first; secret patterns redacted before persistence. |
144
+ | `knit_record_global_learning` | Opt-in: cross-project pool when the insight generalizes beyond this project. |
145
+ | `knit_record_false_positive` | Mark a finding as confirmed non-issue so future reviewers don't re-flag it. |
146
+ | `knit_get_false_positives` | List confirmed non-issues to suppress in review prompts. |
147
+ | `knit_save_session_summary` | Opt-in narrative — record only when this session accomplished something a future session would search for. |
148
+ | `knit_save_handoff` | Save state when context degrades. `failed_attempts` is the load-bearing field. |
149
+ | `knit_consolidate_learnings` | **v0.9.** Cluster similar learnings via tag-Jaccard → one pattern entry per cluster. Dry-run by default. |
150
+
151
+ </details>
152
+
153
+ <details>
154
+ <summary><strong>🧭 Workflow + classification</strong> <em>(Tier 1)</em></summary>
155
+
156
+ | Tool | What it does |
157
+ |---|---|
158
+ | `knit_classify_task` | First call on every task. Returns tier (`inquiry \| trivial \| standard \| complex`), phases, `auto_plan_mode`. **v0.9.** For standard/complex, auto-runs BM25 and embeds top-3 hits as `pre_emptive_learnings`. |
159
+ | `knit_build_context` | Domain context for the current task. **v0.9.** Includes `suggested_reads` — files worth opening (graph-importers, graph-imports, memory-mentions). |
160
+ | `knit_get_workflow` | Fetch protocol depth for one phase on demand. Sections: `overview, tier, phases, research, ideate, plan, execute, optimize, review, tdd, learn, handoff, ship, tools`. |
161
+ | `knit_get_suggestions` | Adaptive warnings from past patterns in given domains. |
162
+ | `knit_reflect` | Detect patterns across recorded learnings (per-project + global pool). Useful with ≥3 entries. |
163
+ | `knit_setup_project` | Describe a non-code project (legal, marketing, research) to bootstrap domain teams. |
164
+ | `knit_prune_sessions` | Prune `sessions.jsonl` by age (default 90 days). Atomic rewrite. |
165
+
166
+ </details>
167
+
168
+ <details>
169
+ <summary><strong>🛡️ Protocol Guard</strong> <em>(Tier 1)</em></summary>
170
+
171
+ Runtime enforcement of the Knit protocol via PreToolUse and SessionStart hooks. Default strictness: `warn`.
172
+
173
+ | Tool | What it does |
174
+ |---|---|
175
+ | `knit_set_protocol_strictness` | Set strictness: `off` (no checks), `warn` (reminder, default), `block` (hard-fail Edit/Write without prior `knit_classify_task` AND `knit_search_learnings`). |
176
+ | `knit_get_protocol_strictness` | Read current strictness level. |
177
+
178
+ </details>
179
+
180
+ <details>
181
+ <summary><strong>📊 Discoverability + diagnostics</strong> <em>(Tier 1)</em></summary>
182
+
183
+ | Tool | What it does |
184
+ |---|---|
185
+ | `knit_brain_status` | Brain health + **token-budget** verdicts per surface + `update_available` notification + integrations summary. |
186
+ | `knit_list_features` | Surfaces hidden tools and tells you how to enable them. The escape hatch. |
187
+ | `knit_enable_feature` | Flip on a Tier-2/3 feature (`teams`, `subagents`, `admin`). Emits `notifications/tools/list_changed` — new tools appear without a Claude Code restart. |
188
+ | `knit_disable_feature` | Symmetric to enable. |
189
+ | `knit_scan_integrations` | Re-detect existing workflow frameworks (Ruflo, gstack, CodeTour, Conductor, other MCP servers, custom CLAUDE.md sections). |
190
+ | `knit_compounding_metrics` | Quantifies *"Knit gets cheaper over time"* — sessions, cache hits, reuse-ratio %, estimated tokens saved. Verdict: `cold \| warming \| compounding \| strong`. |
191
+
192
+ </details>
193
+
194
+ <details>
195
+ <summary><strong>👥 Parallel team worktrees</strong> <em>(Tier 2 — auto-active with ≥3 domains)</em></summary>
196
+
197
+ | Tool | What it does |
198
+ |---|---|
199
+ | `knit_spawn_team_worktree` | Create a git worktree for a team so they can write in parallel without colliding. |
200
+ | `knit_list_team_worktrees` | List active team worktrees. |
201
+ | `knit_finalize_team_worktree` | Merge or discard a team's worktree; surfaces conflicts without destroying it. |
202
+ | `knit_get_teams` | List auto-detected or custom teams. |
203
+ | `knit_define_team` | Create a custom team. |
204
+ | `knit_start_team_review` | Start a parallel review with a shared findings board. |
205
+ | `knit_get_team_prompt` | Per-team prompt including other teams' findings. |
206
+ | `knit_post_team_findings` | Post findings to the shared board. |
207
+ | `knit_get_board_summary` | Cross-team summary, severity-gated. |
208
+
209
+ </details>
210
+
211
+ <details>
212
+ <summary><strong>🤖 Subagents</strong> <em>(Tier 2 — auto-active when `.claude/agents/` exists)</em></summary>
213
+
214
+ | Tool | What it does |
215
+ |---|---|
216
+ | `knit_install_agent` | Install a VoltAgent subagent (e.g. `typescript-pro`) into `.claude/agents/knit-<name>.md`, personalized with project context. |
217
+
218
+ </details>
219
+
220
+ <details>
221
+ <summary><strong>⚙️ Admin</strong> <em>(Tier 3 — opt-in only)</em></summary>
222
+
223
+ | Tool | What it does |
224
+ |---|---|
225
+ | `knit_setup_project` | Bootstrap domain teams for a non-code project. One-time. |
226
+
227
+ </details>
228
+
229
+ > The **cross-project pool** (`knit_search_global_learnings` + `knit_record_global_learning`) holds the lessons that travel between projects — *"Stripe signature rules", "GitHub API pagination quirks", "Redis cluster failover behavior"* — the kind of thing future-you will be glad you wrote down once, somewhere.
230
+
231
+ ---
232
+
233
+ ## 💾 How data is stored
234
+
235
+ Knit data is **centralized** — not in every repo's working tree:
86
236
 
87
237
  ```
88
238
  ~/.knit/
@@ -104,15 +254,17 @@ your-project/
104
254
  └── settings.local.json ← per-machine hooks (knit-managed; gitignored by convention)
105
255
  ```
106
256
 
107
- The project's own `CLAUDE.md` is wrapped in `<!-- knit:start --> ... <!-- knit:end -->` markers. Knit regenerates only the block between markers — never clobbers anything else you write. If your project already has a `CLAUDE.md` without markers, knit writes a sidecar at `.claude/KNIT.md` instead.
257
+ The project's own `CLAUDE.md` is wrapped in `<!-- knit:start --> ... <!-- knit:end -->` markers. Knit regenerates **only** the block between markers — never clobbers anything else. If your project already has a `CLAUDE.md` without markers, knit writes a sidecar at `.claude/KNIT.md` instead.
108
258
 
109
259
  Override the data location with `KNIT_HOME=/custom/path` (useful for sandboxes and tests).
110
260
 
111
- ## Workflow on demand
261
+ ---
112
262
 
113
- The protocol is in MCP, not preloaded in every session. CLAUDE.md tells the agent to call `knit_get_workflow(phase)` when it needs the actual procedure. Sections:
263
+ ## 🧩 Workflow on demand
114
264
 
115
- ```
265
+ The protocol is in MCP, **not preloaded** in every session. CLAUDE.md tells the agent to call `knit_get_workflow(phase)` when it needs the actual procedure:
266
+
267
+ ```js
116
268
  knit_get_workflow({phase: "research"}) // RESEARCH phase details
117
269
  knit_get_workflow({phase: "plan"}) // PLAN + plan-mode rules
118
270
  knit_get_workflow({phase: "execute"}) // EXECUTE + TDD
@@ -127,111 +279,40 @@ knit_get_workflow({phase: "tools"}) // knit MCP tools reference
127
279
 
128
280
  Plus `overview`, `tier`, `phases`. Call with no `phase` to list all sections.
129
281
 
130
- **Effect:** v0.1's CLAUDE.md was ~700 lines / ~20 KB per session, every session. v0.2's is ~100 lines / ~2.7 KB. Protocol depth pulled only when needed.
282
+ > **Effect:** v0.1's CLAUDE.md was ~700 lines / ~20 KB per session. v0.9's is ~100 lines / ~2 KB. **Protocol depth pulled only when needed.**
131
283
 
132
- ## 35 MCP Tools
284
+ ---
133
285
 
134
- ### Query the brain (read-only, cached, ~5ms)
286
+ ## 🌳 Parallel team worktrees
135
287
 
136
- | Tool | What it does |
137
- |------|--------------|
138
- | `knit_query_imports` | Reverse dependencies for a file. Use before edits. |
139
- | `knit_query_dependents` | What a file imports. |
140
- | `knit_query_exports` | What a file exposes. |
141
- | `knit_query_tests` | Test coverage for a file, or list all untested. |
142
- | `knit_find_fanout` | High-fanout files — the contracts. |
143
- | `knit_search_learnings` | Past lessons by domain tag. |
144
- | `knit_get_false_positives` | Confirmed non-issues to suppress in review. |
145
- | `knit_brain_status` | Brain health + **token accounting**. |
146
- | `knit_search_sessions` | Search past sessions by free text over summary+tags+branch. |
147
- | `knit_load_session` | Call at session start — returns last sessions, handoff, learnings, false positives, teams, project knowledge in one round trip. |
148
-
149
- ### Update the brain (write — quality-gated)
150
-
151
- | Tool | What it does |
152
- |------|--------------|
153
- | `knit_classify_task` | First call on every task. Returns tier, phases, affected domains. |
154
- | `knit_build_context` | Domain context for the current task. |
155
- | `knit_record_learning` | Save a non-obvious insight. Quality check first. |
156
- | `knit_record_false_positive` | Mark a finding as a confirmed non-issue. |
157
- | `knit_save_session_summary` | Opt-in narrative summary of what this session did. |
158
- | `knit_save_handoff` | Save state when context degrades. |
159
- | `knit_setup_project` | Describe a non-code project (legal, marketing, research). |
160
- | `knit_prune_sessions` | Prune sessions.jsonl by age — keep recent N or drop entries older than N days. |
161
- | `knit_install_agent` | Install a single VoltAgent subagent (e.g. `typescript-pro`) into `.claude/agents/`. |
162
-
163
- ### Protocol Guard (v0.5.0+)
164
-
165
- Runtime enforcement of the knit protocol via PreToolUse and SessionStart hooks. Default strictness: `warn`.
288
+ A Complex task gets broken across multiple teams. Each team works in its own git worktree (sibling to the main repo, native `git worktree` convention). Multiple agents within one team share the team's worktree. The orchestrator collects each team's work, runs gates, and merges back.
166
289
 
167
- | Tool | What it does |
168
- |------|--------------|
169
- | `knit_set_protocol_strictness` | Set strictness: `off` (no checks), `warn` (reminder), `block` (hard-fail Edit/Write without prior `knit_classify_task`). |
170
- | `knit_get_protocol_strictness` | Read current strictness level for this project. |
290
+ ```
291
+ /Users/p/my-repo ← main
292
+ /Users/p/my-repo-knit-ui-<ts> ← UI team
293
+ /Users/p/my-repo-knit-api-security-<ts> ← API & Security team
294
+ ```
171
295
 
172
- ### Workflow on demand
296
+ ```js
297
+ const ui = await knit_spawn_team_worktree({ team_name: "UI", task_description: "..." })
298
+ // Spawn agents with ui.path; they cd there and work
299
+ await knit_finalize_team_worktree({ team_name: "UI", action: "merge" })
300
+ ```
173
301
 
174
- | Tool | What it does |
175
- |------|--------------|
176
- | `knit_get_workflow` | Fetch protocol depth for one phase. |
302
+ **Merge conflicts surface cleanly** `knit_finalize_team_worktree` with `action: "merge"` returns `{status: "conflict", conflict_files: [...]}` without destroying the worktree. Resolve manually, then call again.
177
303
 
178
- ### Parallel team worktrees
304
+ Compatible with Claude Code's `EnterWorktree({path})` — knit's worktrees register via native `git worktree add`, so any session can switch into one.
179
305
 
180
- | Tool | What it does |
181
- |------|--------------|
182
- | `knit_spawn_team_worktree` | Create a git worktree for a team. |
183
- | `knit_list_team_worktrees` | List active team worktrees. |
184
- | `knit_finalize_team_worktree` | Merge or discard a team's worktree. |
306
+ ---
185
307
 
186
- ### Team review board
308
+ ## 🧬 Subagents — VoltAgent + project personalization
187
309
 
188
- | Tool | What it does |
189
- |------|--------------|
190
- | `knit_get_teams` | List auto-detected or custom teams. |
191
- | `knit_define_team` | Create a custom team. |
192
- | `knit_start_team_review` | Start a parallel review with shared findings. |
193
- | `knit_get_team_prompt` | Per-team prompt including other teams' findings. |
194
- | `knit_post_team_findings` | Post findings to the shared board. |
195
- | `knit_get_board_summary` | Cross-team summary, severity-gated. |
310
+ On first MCP call, knit installs **personalized subagents** into `<project>/.claude/agents/knit-<name>.md`. Each agent has:
196
311
 
197
- ### Cross-project learnings (Model C, opt-in)
312
+ 1. **The VoltAgent base** — the curated system prompt from [github.com/VoltAgent/awesome-claude-code-subagents](https://github.com/VoltAgent/awesome-claude-code-subagents) (MIT, 131+ agents). Knit bundles the 6 most common (`code-reviewer`, `security-engineer`, `qa-expert`, `typescript-pro`, `python-pro`, `golang-pro`) so they install with zero network. Specialized agents fetch at a pinned SHA the first time knit needs them.
313
+ 2. **A knit context block** appended at the end with project name, stack, high-fanout files, recent relevant learnings, false positives to suppress, and the knit MCP tools the agent can call.
198
314
 
199
- | Tool | What it does |
200
- |------|--------------|
201
- | `knit_record_global_learning` | Opt-in: save an insight to `~/.knit/global/learnings.jsonl` when it generalizes beyond this project. |
202
- | `knit_search_global_learnings` | Free-text search across **all** of your projects' shared learnings. |
203
- | `knit_reflect` | Detect patterns across recorded learnings. Useful with ≥3 entries (which Model C makes easy to reach). |
204
- | `knit_get_suggestions` | Adaptive suggestions for the current task based on past patterns in given domains. |
205
-
206
- Per-project `knit_record_learning` stays primary. The global pool is for the lessons that travel between projects — "Stripe signature rules", "GitHub API pagination quirks", "Redis cluster failover behavior" — the kind of thing future-you will be glad you wrote down once, somewhere.
207
-
208
- ## Subagents — VoltAgent + project personalization
209
-
210
- v0.4 closes the gap where knit's team configs referenced agent names
211
- (`typescript-pro`, `security-engineer`, etc.) without actually installing them.
212
- A fresh user opening Claude Code had none of those agents on disk, so teams
213
- fell back to generic prompts.
214
-
215
- Now: on first MCP call, knit **installs personalized subagents** into
216
- `<project>/.claude/agents/knit-<name>.md`. Each agent has:
217
-
218
- 1. **The VoltAgent base** — the curated system prompt from
219
- [github.com/VoltAgent/awesome-claude-code-subagents](https://github.com/VoltAgent/awesome-claude-code-subagents)
220
- (MIT-licensed, 131+ agents). Knit bundles the 6 most common
221
- (`code-reviewer`, `security-engineer`, `qa-expert`, `typescript-pro`,
222
- `python-pro`, `golang-pro`) so they install with zero network. Specialized
223
- agents fetch from VoltAgent at a pinned SHA the first time knit needs them.
224
- 2. **An knit context block** appended at the end with project name, stack,
225
- high-fanout files, recent relevant learnings, false positives to suppress,
226
- and the knit MCP tools the agent can call.
227
-
228
- Each agent now has both VoltAgent's role expertise AND knit's project-specific
229
- context. When a team dispatches via Claude Code's Agent tool, the agent inherits
230
- both layers.
231
-
232
- **Never clobbers user-curated agents.** If you have your own
233
- `<project>/.claude/agents/typescript-pro.md`, knit writes
234
- `knit-typescript-pro.md` alongside it. Different filename, no conflict.
315
+ **Never clobbers user-curated agents.** If you have your own `typescript-pro.md`, knit writes `knit-typescript-pro.md` alongside it. Different filename, no conflict.
235
316
 
236
317
  ```bash
237
318
  knit install-agents # install agents this project's teams need
@@ -239,116 +320,141 @@ knit install-agents --all # install every known agent
239
320
  knit install-agents --refresh # re-fetch from network even if cached
240
321
  ```
241
322
 
242
- `KNIT_OFFLINE=1` disables network fetches (bundled-core still works).
243
- `KNIT_AGENT_REGISTRY_REF=main` overrides the pinned VoltAgent SHA.
244
- (Legacy `ENGRAM_OFFLINE` / `ENGRAM_AGENT_REGISTRY_REF` are still honored.)
245
-
246
- ## Parallel team worktrees
247
-
248
- A Complex task gets broken across multiple teams. Each team works in its own git worktree (sibling to the main repo, native `git worktree` convention). Multiple agents within one team share the team's worktree. The orchestrator collects each team's work, runs gates, and merges back.
249
-
250
- ```
251
- /Users/p/my-repo <- main
252
- /Users/p/my-repo-knit-ui-<ts> <- UI team
253
- /Users/p/my-repo-knit-api-security-<ts> <- API & Security team
254
- ```
323
+ `KNIT_OFFLINE=1` disables network fetches (bundled-core still works). `KNIT_AGENT_REGISTRY_REF=main` overrides the pinned SHA.
255
324
 
256
- ```js
257
- // Orchestrator workflow
258
- const ui = await knit_spawn_team_worktree({ team_name: "UI", task_description: "..." })
259
- // Spawn agents with ui.path; they cd there and work
260
- // ...
261
- await knit_finalize_team_worktree({ team_name: "UI", action: "merge" })
262
- ```
325
+ ---
263
326
 
264
- **Merge conflicts surface cleanly** — `knit_finalize_team_worktree` with `action: "merge"` returns `{status: "conflict", conflict_files: [...]}` without destroying the worktree. Resolve manually, then call again.
327
+ ## 💰 Token accounting
265
328
 
266
- Compatible with Claude Code's `EnterWorktree({path})` knit's worktrees register via native `git worktree add`, so any session can switch into one.
267
-
268
- ## Token accounting
269
-
270
- `knit_brain_status` answers the only question that matters: is knit saving more than it costs?
329
+ `knit_brain_status` answers the only question that matters: **is knit saving more than it costs?**
271
330
 
272
331
  ```json
273
332
  {
274
- "token_accounting": {
275
- "claude_md_kb": 2.7,
276
- "session_count": 12,
277
- "learnings_hit_rate_pct": 67,
278
- "note": "Healthy."
333
+ "token_budget": {
334
+ "budgets": {
335
+ "claude_md": { "bytes": 2048, "target_bytes": 6500, "verdict": "healthy" },
336
+ "tool_registry": { "bytes": 8400, "target_bytes": 8500, "verdict": "healthy", "active_tool_count": 31, "total_tool_count": 43 },
337
+ "instructions": { "bytes": 2200, "target_bytes": 2500, "verdict": "healthy" },
338
+ "per_session_overhead": { "bytes": 12648, "target_bytes": 17500, "verdict": "healthy" }
339
+ },
340
+ "overall_verdict": "healthy",
341
+ "compounding": {
342
+ "session_count": 12,
343
+ "total_learnings": 18,
344
+ "learnings_hit_rate_pct": 67,
345
+ "note": "Strong compounding — learnings are getting reused across sessions."
346
+ }
347
+ },
348
+ "update_available": {
349
+ "current": "0.8.0",
350
+ "latest": "0.9.0",
351
+ "upgrade": "Restart Claude Code to spawn a fresh MCP — npx will auto-fetch the new version."
279
352
  }
280
353
  }
281
354
  ```
282
355
 
283
- Warnings surface when CLAUDE.md > 30 KB (knit is too heavy) or hit rate < 20 % on >10 learnings (most learnings unused — prune).
356
+ Pair with `knit_compounding_metrics` for the value side of the ledger (sessions, hit rate, estimated tokens saved by skipped re-investigations).
284
357
 
285
- ## CLI
358
+ ---
359
+
360
+ ## 💻 CLI
286
361
 
287
362
  ```bash
288
- knit setup # One time: add MCP to Claude settings
289
- knit status # Dashboard: sessions, learnings, hit rate, knowledge health
290
- knit refresh # Force rebuild knowledge brain
363
+ knit setup # one time: add MCP to Claude settings
364
+ knit status # dashboard: sessions, learnings, hit rate, knowledge health
365
+ knit refresh # force rebuild knowledge brain
291
366
  ```
292
367
 
293
- Example `knit status` output:
368
+ Example `knit status`:
294
369
 
295
370
  ```
296
371
  Knowledge Index
297
- Files: 47 indexed (12,340 lines)
298
- Imports: 23 edges mapped
299
- Untested: 8 files
372
+ Files: 54 indexed (11,495 lines)
373
+ Imports: 46 edges mapped
374
+ Untested: 5 files
300
375
 
301
376
  Knowledge Base
302
- Learnings: 12 total
303
- Accessed: 8 (67% hit rate)
377
+ Learnings: 18 total
378
+ Accessed: 12 (67% hit rate)
304
379
  False positives: 3
305
380
 
306
- Token accounting
307
- CLAUDE.md: 2.7 KB
308
- Sessions logged: 14
309
- Hit rate: 67%Healthy
381
+ Token budget (v0.9)
382
+ CLAUDE.md: 2.0 KB → healthy
383
+ Tool registry: 8.4 KB → healthy (31 active / 43 total)
384
+ Instructions: 2.2 KB healthy
385
+ Per-session total: 12.6 KB → healthy
386
+
387
+ Compounding
388
+ Sessions logged: 14
389
+ Reuse ratio: 67% → strong
390
+ Tokens saved (est.): 65,000
310
391
  ```
311
392
 
312
- ## How it's different
393
+ ---
394
+
395
+ ## 🆚 How it's different
396
+
397
+ | | gstack (skills) | ECC (agents) | Ruflo (orchestration) | **Knit** |
398
+ |--|---|---|---|---|
399
+ | **Bet** | Slash-command flows | Agent rules | 100+ agents in swarms | **One disciplined agent, compounding memory** |
400
+ | **Setup** | Install skills per-project | Manual `.claude/` setup | `npx ruflo init` (heavy) | **`npx knit-mcp setup` (light)** |
401
+ | **Memory** | jsonl files in-tree | Memory directory | Vector DB + 4-tier consolidation | **Local, searchable, vectorless BM25 + graph fusion** |
402
+ | **Token cost** | Skills loaded into context | Rules loaded into context | 314 tools advertised | **~2 KB CLAUDE.md, tier-gated registry, budget guardrail** |
403
+ | **Parallel work** | None | None | Multi-agent swarms + federation | **Team-scoped git worktrees** |
404
+ | **Cloud dependency** | None | None | Cognitum.One (cloud backbone) | **None — fully local** |
405
+ | **Self-measurement** | None | None | Cost-tracker plugin | **`knit_brain_status.token_budget` + `knit_compounding_metrics`** |
406
+ | **Anti-hallucination** | None | None | None advertised | **`knit_verify_claim` + citation rule + pre/post import validation** |
407
+ | **Non-code projects** | No | No | Limited | **Description-driven via `knit_setup_project`** |
408
+
409
+ **The bet:** Ruflo for agent quantity (swarms, federation, plugins). Knit for **agent quality** (memory, classification, token discipline, hallucination defense). Different markets. The integration scanner detects Ruflo when installed and tailors instructions to defer routing to it — Knit operates as the memory + classification substrate underneath.
410
+
411
+ ---
313
412
 
314
- | | gstack (skills) | ECC (agents) | Knit |
315
- |--|---|---|---|
316
- | Setup | Install skills per-project | Manual `.claude/` setup | One command. Done forever. |
317
- | Memory | jsonl files in-tree | Memory directory | `~/.knit/projects/<hash>/` — centralized, project-keyed, searchable sessions |
318
- | Token cost | Skills loaded into context | Rules loaded into context | Workflow fetched on-demand. CLAUDE.md is ~2.7 KB. |
319
- | Parallel work | None | None | Team-scoped git worktrees |
320
- | Self-measurement | None | None | `knit_brain_status.token_accounting` |
321
- | Non-code projects | No | No | Description-driven domains via `knit_setup_project` |
413
+ ## 📜 Release history
322
414
 
323
- ## Migration from v0.1
415
+ | Version | Headline |
416
+ |---|---|
417
+ | **v0.10.0** | Token-economics release · risk × scope × change_kind classifier split · `context_budget_remaining` graceful degradation · per-project diversity cap on cross-project search · 11 new compounding-metrics fields + weekly snapshot persistence + `knit_get_metrics_history`. Makes "Knit makes Claude cheaper" a chartable number from day 1. |
418
+ | **v0.9.0** | Hook-level enforcement · citation rule · `knit_verify_claim` · auto-search in classify · `suggested_reads` · `knit_get_learning` · `knit_consolidate_learnings`. |
419
+ | **v0.8.x** | Vectorless RAG (BM25 + RRF) · graph-traversal retriever · per-project instruction tailoring · `knit_compounding_metrics` · integration scanner. |
420
+ | **v0.7.x** | Universal protocol injection via MCP `instructions` · tier-gated tool surface · `knit_list_features` · Inquiry classification tier · CLAUDE.md cut 88% · lazy response modes · token-budget guardrail · legacy migration. |
421
+ | **v0.5.x** | Protocol Guard — runtime enforcement via hooks (off / warn / block). |
422
+ | **v0.4.x** | VoltAgent subagent integration · personalization layer · `engram install-agents` CLI · hybrid hook merging · `export obsidian`. |
423
+ | **v0.3.x** | Centralized data at `~/.knit/projects/<hash>/` · marker-wrapped CLAUDE.md · on-demand workflow · cross-project learnings pool. |
324
424
 
325
- If you have an existing project with knit v0.1 data at `<project>/.claude/`, knit v0.2 auto-migrates on the first MCP call:
425
+ ---
426
+
427
+ ## 🔄 Migration from v0.1
428
+
429
+ If you have an existing project with knit v0.1 data at `<project>/.claude/`, knit auto-migrates on the first MCP call:
326
430
 
327
431
  1. Detects `<project>/.claude/knowledge.json` (or `knowledgebase.json`)
328
432
  2. Copies all knit data forward to `~/.knit/projects/<hash>/`
329
433
  3. Writes `<project>/.claude/MIGRATED.txt` breadcrumb explaining where the data went
330
434
  4. Leaves the old `.claude/` directory intact (delete at your discretion)
331
435
 
332
- No data loss, no dual-writes. Single migration per project.
436
+ **No data loss, no dual-writes.** Single migration per project.
333
437
 
334
- ## Development
438
+ ---
439
+
440
+ ## 🛠️ Development
335
441
 
336
442
  ```bash
337
443
  git clone https://github.com/PDgit12/knit.git
338
444
  cd knit
339
445
  npm install
340
- npm run dev # Run CLI locally
341
- npm run test # 295 tests
342
- npm run typecheck # TypeScript strict mode
343
- npm run build # Compile CLI + MCP server
446
+ npm run dev # run CLI locally
447
+ npm run test # 492 tests
448
+ npm run typecheck # TypeScript strict mode
449
+ npm run build # compile CLI + MCP server
344
450
  ```
345
451
 
346
- ## Architecture
452
+ ### Architecture
347
453
 
348
454
  ```
349
455
  knit (npm package)
350
456
  ├── dist/cli.js # CLI: setup, status, refresh
351
- └── dist/mcp/server.js # MCP server: 27 tools, auto-init
457
+ └── dist/mcp/server.js # MCP server: 43 tools (tier-gated), auto-init
352
458
 
353
459
  per-project, in ~/.knit/projects/<hash>/
354
460
  ├── knowledge.json # import graph + exports + test map
@@ -360,11 +466,17 @@ per-project, in ~/.knit/projects/<hash>/
360
466
 
361
467
  per-project, in <project>/
362
468
  ├── CLAUDE.md # ≤150-line thin shape, marker-wrapped
363
- └── .claude/settings.local.json # per-machine hooks, knit-managed (gitignored by convention)
469
+ └── .claude/settings.local.json # per-machine hooks, knit-managed
364
470
  ```
365
471
 
366
- Zero external dependencies for the knowledge brain. 295 tests. Strict-mode TypeScript.
472
+ **Zero external dependencies for the knowledge brain.** 492 tests. Strict-mode TypeScript.
473
+
474
+ ---
367
475
 
368
- ## License
476
+ ## 📄 License
369
477
 
370
- MIT
478
+ [MIT](./LICENSE) © 2026
479
+
480
+ <p align="center">
481
+ <sub>If knit saved you tokens, <a href="https://github.com/PDgit12/knit">give it a ⭐</a>.</sub>
482
+ </p>