@vpxa/kb 0.1.1

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.
Files changed (275) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1140 -0
  3. package/bin/kb.mjs +10 -0
  4. package/package.json +67 -0
  5. package/packages/analyzers/dist/blast-radius-analyzer.d.ts +23 -0
  6. package/packages/analyzers/dist/blast-radius-analyzer.js +114 -0
  7. package/packages/analyzers/dist/dependency-analyzer.d.ts +29 -0
  8. package/packages/analyzers/dist/dependency-analyzer.js +425 -0
  9. package/packages/analyzers/dist/diagram-generator.d.ts +13 -0
  10. package/packages/analyzers/dist/diagram-generator.js +86 -0
  11. package/packages/analyzers/dist/entry-point-analyzer.d.ts +19 -0
  12. package/packages/analyzers/dist/entry-point-analyzer.js +239 -0
  13. package/packages/analyzers/dist/index.d.ts +14 -0
  14. package/packages/analyzers/dist/index.js +23 -0
  15. package/packages/analyzers/dist/knowledge-producer.d.ts +32 -0
  16. package/packages/analyzers/dist/knowledge-producer.js +113 -0
  17. package/packages/analyzers/dist/pattern-analyzer.d.ts +12 -0
  18. package/packages/analyzers/dist/pattern-analyzer.js +359 -0
  19. package/packages/analyzers/dist/regex-call-graph.d.ts +17 -0
  20. package/packages/analyzers/dist/regex-call-graph.js +428 -0
  21. package/packages/analyzers/dist/structure-analyzer.d.ts +11 -0
  22. package/packages/analyzers/dist/structure-analyzer.js +258 -0
  23. package/packages/analyzers/dist/symbol-analyzer.d.ts +10 -0
  24. package/packages/analyzers/dist/symbol-analyzer.js +442 -0
  25. package/packages/analyzers/dist/ts-call-graph.d.ts +27 -0
  26. package/packages/analyzers/dist/ts-call-graph.js +160 -0
  27. package/packages/analyzers/dist/types.d.ts +98 -0
  28. package/packages/analyzers/dist/types.js +1 -0
  29. package/packages/chunker/dist/call-graph-extractor.d.ts +22 -0
  30. package/packages/chunker/dist/call-graph-extractor.js +90 -0
  31. package/packages/chunker/dist/chunker-factory.d.ts +7 -0
  32. package/packages/chunker/dist/chunker-factory.js +36 -0
  33. package/packages/chunker/dist/chunker.interface.d.ts +10 -0
  34. package/packages/chunker/dist/chunker.interface.js +1 -0
  35. package/packages/chunker/dist/code-chunker.d.ts +14 -0
  36. package/packages/chunker/dist/code-chunker.js +134 -0
  37. package/packages/chunker/dist/generic-chunker.d.ts +12 -0
  38. package/packages/chunker/dist/generic-chunker.js +72 -0
  39. package/packages/chunker/dist/index.d.ts +8 -0
  40. package/packages/chunker/dist/index.js +21 -0
  41. package/packages/chunker/dist/markdown-chunker.d.ts +14 -0
  42. package/packages/chunker/dist/markdown-chunker.js +122 -0
  43. package/packages/chunker/dist/treesitter-chunker.d.ts +47 -0
  44. package/packages/chunker/dist/treesitter-chunker.js +234 -0
  45. package/packages/cli/dist/commands/analyze.d.ts +3 -0
  46. package/packages/cli/dist/commands/analyze.js +112 -0
  47. package/packages/cli/dist/commands/context-cmds.d.ts +3 -0
  48. package/packages/cli/dist/commands/context-cmds.js +155 -0
  49. package/packages/cli/dist/commands/environment.d.ts +3 -0
  50. package/packages/cli/dist/commands/environment.js +204 -0
  51. package/packages/cli/dist/commands/execution.d.ts +3 -0
  52. package/packages/cli/dist/commands/execution.js +137 -0
  53. package/packages/cli/dist/commands/graph.d.ts +3 -0
  54. package/packages/cli/dist/commands/graph.js +81 -0
  55. package/packages/cli/dist/commands/init.d.ts +8 -0
  56. package/packages/cli/dist/commands/init.js +87 -0
  57. package/packages/cli/dist/commands/knowledge.d.ts +3 -0
  58. package/packages/cli/dist/commands/knowledge.js +139 -0
  59. package/packages/cli/dist/commands/search.d.ts +3 -0
  60. package/packages/cli/dist/commands/search.js +267 -0
  61. package/packages/cli/dist/commands/system.d.ts +3 -0
  62. package/packages/cli/dist/commands/system.js +241 -0
  63. package/packages/cli/dist/commands/workspace.d.ts +3 -0
  64. package/packages/cli/dist/commands/workspace.js +388 -0
  65. package/packages/cli/dist/context.d.ts +5 -0
  66. package/packages/cli/dist/context.js +14 -0
  67. package/packages/cli/dist/helpers.d.ts +52 -0
  68. package/packages/cli/dist/helpers.js +458 -0
  69. package/packages/cli/dist/index.d.ts +8 -0
  70. package/packages/cli/dist/index.js +69 -0
  71. package/packages/cli/dist/kb-init.d.ts +57 -0
  72. package/packages/cli/dist/kb-init.js +82 -0
  73. package/packages/cli/dist/types.d.ts +7 -0
  74. package/packages/cli/dist/types.js +1 -0
  75. package/packages/core/dist/constants.d.ts +49 -0
  76. package/packages/core/dist/constants.js +43 -0
  77. package/packages/core/dist/content-detector.d.ts +9 -0
  78. package/packages/core/dist/content-detector.js +79 -0
  79. package/packages/core/dist/errors.d.ts +18 -0
  80. package/packages/core/dist/errors.js +40 -0
  81. package/packages/core/dist/index.d.ts +6 -0
  82. package/packages/core/dist/index.js +9 -0
  83. package/packages/core/dist/logger.d.ts +9 -0
  84. package/packages/core/dist/logger.js +34 -0
  85. package/packages/core/dist/types.d.ts +108 -0
  86. package/packages/core/dist/types.js +1 -0
  87. package/packages/embeddings/dist/embedder.interface.d.ts +24 -0
  88. package/packages/embeddings/dist/embedder.interface.js +1 -0
  89. package/packages/embeddings/dist/index.d.ts +3 -0
  90. package/packages/embeddings/dist/index.js +5 -0
  91. package/packages/embeddings/dist/onnx-embedder.d.ts +24 -0
  92. package/packages/embeddings/dist/onnx-embedder.js +82 -0
  93. package/packages/indexer/dist/file-hasher.d.ts +11 -0
  94. package/packages/indexer/dist/file-hasher.js +13 -0
  95. package/packages/indexer/dist/filesystem-crawler.d.ts +27 -0
  96. package/packages/indexer/dist/filesystem-crawler.js +125 -0
  97. package/packages/indexer/dist/graph-extractor.d.ts +22 -0
  98. package/packages/indexer/dist/graph-extractor.js +111 -0
  99. package/packages/indexer/dist/incremental-indexer.d.ts +47 -0
  100. package/packages/indexer/dist/incremental-indexer.js +278 -0
  101. package/packages/indexer/dist/index.d.ts +5 -0
  102. package/packages/indexer/dist/index.js +14 -0
  103. package/packages/server/dist/api.d.ts +8 -0
  104. package/packages/server/dist/api.js +9 -0
  105. package/packages/server/dist/config.d.ts +3 -0
  106. package/packages/server/dist/config.js +75 -0
  107. package/packages/server/dist/curated-manager.d.ts +86 -0
  108. package/packages/server/dist/curated-manager.js +357 -0
  109. package/packages/server/dist/index.d.ts +2 -0
  110. package/packages/server/dist/index.js +134 -0
  111. package/packages/server/dist/replay-interceptor.d.ts +11 -0
  112. package/packages/server/dist/replay-interceptor.js +38 -0
  113. package/packages/server/dist/resources/resources.d.ts +4 -0
  114. package/packages/server/dist/resources/resources.js +40 -0
  115. package/packages/server/dist/server.d.ts +21 -0
  116. package/packages/server/dist/server.js +247 -0
  117. package/packages/server/dist/tools/analyze.tools.d.ts +11 -0
  118. package/packages/server/dist/tools/analyze.tools.js +288 -0
  119. package/packages/server/dist/tools/forge.tools.d.ts +12 -0
  120. package/packages/server/dist/tools/forge.tools.js +501 -0
  121. package/packages/server/dist/tools/forget.tool.d.ts +4 -0
  122. package/packages/server/dist/tools/forget.tool.js +43 -0
  123. package/packages/server/dist/tools/graph.tool.d.ts +4 -0
  124. package/packages/server/dist/tools/graph.tool.js +110 -0
  125. package/packages/server/dist/tools/list.tool.d.ts +4 -0
  126. package/packages/server/dist/tools/list.tool.js +56 -0
  127. package/packages/server/dist/tools/lookup.tool.d.ts +4 -0
  128. package/packages/server/dist/tools/lookup.tool.js +53 -0
  129. package/packages/server/dist/tools/onboard.tool.d.ts +5 -0
  130. package/packages/server/dist/tools/onboard.tool.js +112 -0
  131. package/packages/server/dist/tools/produce.tool.d.ts +3 -0
  132. package/packages/server/dist/tools/produce.tool.js +74 -0
  133. package/packages/server/dist/tools/read.tool.d.ts +4 -0
  134. package/packages/server/dist/tools/read.tool.js +49 -0
  135. package/packages/server/dist/tools/reindex.tool.d.ts +7 -0
  136. package/packages/server/dist/tools/reindex.tool.js +70 -0
  137. package/packages/server/dist/tools/remember.tool.d.ts +4 -0
  138. package/packages/server/dist/tools/remember.tool.js +45 -0
  139. package/packages/server/dist/tools/replay.tool.d.ts +3 -0
  140. package/packages/server/dist/tools/replay.tool.js +89 -0
  141. package/packages/server/dist/tools/search.tool.d.ts +5 -0
  142. package/packages/server/dist/tools/search.tool.js +331 -0
  143. package/packages/server/dist/tools/status.tool.d.ts +4 -0
  144. package/packages/server/dist/tools/status.tool.js +68 -0
  145. package/packages/server/dist/tools/toolkit.tools.d.ts +35 -0
  146. package/packages/server/dist/tools/toolkit.tools.js +1674 -0
  147. package/packages/server/dist/tools/update.tool.d.ts +4 -0
  148. package/packages/server/dist/tools/update.tool.js +42 -0
  149. package/packages/server/dist/tools/utility.tools.d.ts +15 -0
  150. package/packages/server/dist/tools/utility.tools.js +461 -0
  151. package/packages/store/dist/graph-store.interface.d.ts +104 -0
  152. package/packages/store/dist/graph-store.interface.js +1 -0
  153. package/packages/store/dist/index.d.ts +6 -0
  154. package/packages/store/dist/index.js +9 -0
  155. package/packages/store/dist/lance-store.d.ts +32 -0
  156. package/packages/store/dist/lance-store.js +258 -0
  157. package/packages/store/dist/sqlite-graph-store.d.ts +43 -0
  158. package/packages/store/dist/sqlite-graph-store.js +374 -0
  159. package/packages/store/dist/store-factory.d.ts +9 -0
  160. package/packages/store/dist/store-factory.js +14 -0
  161. package/packages/store/dist/store.interface.d.ts +48 -0
  162. package/packages/store/dist/store.interface.js +1 -0
  163. package/packages/tools/dist/batch.d.ts +21 -0
  164. package/packages/tools/dist/batch.js +45 -0
  165. package/packages/tools/dist/changelog.d.ts +34 -0
  166. package/packages/tools/dist/changelog.js +112 -0
  167. package/packages/tools/dist/check.d.ts +26 -0
  168. package/packages/tools/dist/check.js +59 -0
  169. package/packages/tools/dist/checkpoint.d.ts +17 -0
  170. package/packages/tools/dist/checkpoint.js +43 -0
  171. package/packages/tools/dist/codemod.d.ts +37 -0
  172. package/packages/tools/dist/codemod.js +69 -0
  173. package/packages/tools/dist/compact.d.ts +41 -0
  174. package/packages/tools/dist/compact.js +60 -0
  175. package/packages/tools/dist/data-transform.d.ts +10 -0
  176. package/packages/tools/dist/data-transform.js +124 -0
  177. package/packages/tools/dist/dead-symbols.d.ts +21 -0
  178. package/packages/tools/dist/dead-symbols.js +71 -0
  179. package/packages/tools/dist/delegate.d.ts +34 -0
  180. package/packages/tools/dist/delegate.js +130 -0
  181. package/packages/tools/dist/diff-parse.d.ts +26 -0
  182. package/packages/tools/dist/diff-parse.js +153 -0
  183. package/packages/tools/dist/digest.d.ts +53 -0
  184. package/packages/tools/dist/digest.js +242 -0
  185. package/packages/tools/dist/encode.d.ts +14 -0
  186. package/packages/tools/dist/encode.js +46 -0
  187. package/packages/tools/dist/env-info.d.ts +28 -0
  188. package/packages/tools/dist/env-info.js +58 -0
  189. package/packages/tools/dist/eval.d.ts +13 -0
  190. package/packages/tools/dist/eval.js +79 -0
  191. package/packages/tools/dist/evidence-map.d.ts +79 -0
  192. package/packages/tools/dist/evidence-map.js +203 -0
  193. package/packages/tools/dist/file-summary.d.ts +32 -0
  194. package/packages/tools/dist/file-summary.js +106 -0
  195. package/packages/tools/dist/file-walk.d.ts +4 -0
  196. package/packages/tools/dist/file-walk.js +75 -0
  197. package/packages/tools/dist/find-examples.d.ts +25 -0
  198. package/packages/tools/dist/find-examples.js +48 -0
  199. package/packages/tools/dist/find.d.ts +47 -0
  200. package/packages/tools/dist/find.js +120 -0
  201. package/packages/tools/dist/forge-classify.d.ts +44 -0
  202. package/packages/tools/dist/forge-classify.js +319 -0
  203. package/packages/tools/dist/forge-ground.d.ts +64 -0
  204. package/packages/tools/dist/forge-ground.js +184 -0
  205. package/packages/tools/dist/git-context.d.ts +22 -0
  206. package/packages/tools/dist/git-context.js +46 -0
  207. package/packages/tools/dist/graph-query.d.ts +89 -0
  208. package/packages/tools/dist/graph-query.js +194 -0
  209. package/packages/tools/dist/health.d.ts +14 -0
  210. package/packages/tools/dist/health.js +118 -0
  211. package/packages/tools/dist/http-request.d.ts +23 -0
  212. package/packages/tools/dist/http-request.js +58 -0
  213. package/packages/tools/dist/index.d.ts +49 -0
  214. package/packages/tools/dist/index.js +273 -0
  215. package/packages/tools/dist/lane.d.ts +39 -0
  216. package/packages/tools/dist/lane.js +227 -0
  217. package/packages/tools/dist/measure.d.ts +38 -0
  218. package/packages/tools/dist/measure.js +119 -0
  219. package/packages/tools/dist/onboard.d.ts +41 -0
  220. package/packages/tools/dist/onboard.js +1139 -0
  221. package/packages/tools/dist/parse-output.d.ts +80 -0
  222. package/packages/tools/dist/parse-output.js +158 -0
  223. package/packages/tools/dist/process-manager.d.ts +18 -0
  224. package/packages/tools/dist/process-manager.js +69 -0
  225. package/packages/tools/dist/queue.d.ts +38 -0
  226. package/packages/tools/dist/queue.js +126 -0
  227. package/packages/tools/dist/regex-test.d.ts +31 -0
  228. package/packages/tools/dist/regex-test.js +39 -0
  229. package/packages/tools/dist/rename.d.ts +29 -0
  230. package/packages/tools/dist/rename.js +70 -0
  231. package/packages/tools/dist/replay.d.ts +56 -0
  232. package/packages/tools/dist/replay.js +108 -0
  233. package/packages/tools/dist/schema-validate.d.ts +23 -0
  234. package/packages/tools/dist/schema-validate.js +141 -0
  235. package/packages/tools/dist/scope-map.d.ts +52 -0
  236. package/packages/tools/dist/scope-map.js +72 -0
  237. package/packages/tools/dist/snippet.d.ts +34 -0
  238. package/packages/tools/dist/snippet.js +80 -0
  239. package/packages/tools/dist/stash.d.ts +12 -0
  240. package/packages/tools/dist/stash.js +60 -0
  241. package/packages/tools/dist/stratum-card.d.ts +31 -0
  242. package/packages/tools/dist/stratum-card.js +239 -0
  243. package/packages/tools/dist/symbol.d.ts +28 -0
  244. package/packages/tools/dist/symbol.js +87 -0
  245. package/packages/tools/dist/test-run.d.ts +23 -0
  246. package/packages/tools/dist/test-run.js +55 -0
  247. package/packages/tools/dist/text-utils.d.ts +16 -0
  248. package/packages/tools/dist/text-utils.js +31 -0
  249. package/packages/tools/dist/time-utils.d.ts +18 -0
  250. package/packages/tools/dist/time-utils.js +135 -0
  251. package/packages/tools/dist/trace.d.ts +24 -0
  252. package/packages/tools/dist/trace.js +114 -0
  253. package/packages/tools/dist/truncation.d.ts +22 -0
  254. package/packages/tools/dist/truncation.js +45 -0
  255. package/packages/tools/dist/watch.d.ts +30 -0
  256. package/packages/tools/dist/watch.js +61 -0
  257. package/packages/tools/dist/web-fetch.d.ts +45 -0
  258. package/packages/tools/dist/web-fetch.js +249 -0
  259. package/packages/tools/dist/web-search.d.ts +23 -0
  260. package/packages/tools/dist/web-search.js +46 -0
  261. package/packages/tools/dist/workset.d.ts +45 -0
  262. package/packages/tools/dist/workset.js +77 -0
  263. package/packages/tui/dist/App.d.ts +8 -0
  264. package/packages/tui/dist/App.js +52659 -0
  265. package/packages/tui/dist/index.d.ts +19 -0
  266. package/packages/tui/dist/index.js +54742 -0
  267. package/packages/tui/dist/panels/CuratedPanel.d.ts +8 -0
  268. package/packages/tui/dist/panels/CuratedPanel.js +34452 -0
  269. package/packages/tui/dist/panels/LogPanel.d.ts +3 -0
  270. package/packages/tui/dist/panels/LogPanel.js +51894 -0
  271. package/packages/tui/dist/panels/SearchPanel.d.ts +10 -0
  272. package/packages/tui/dist/panels/SearchPanel.js +34985 -0
  273. package/packages/tui/dist/panels/StatusPanel.d.ts +8 -0
  274. package/packages/tui/dist/panels/StatusPanel.js +34465 -0
  275. package/skills/knowledge-base/SKILL.md +316 -0
package/README.md ADDED
@@ -0,0 +1,1140 @@
1
+ # @anvpx/kb
2
+
3
+ Local-first AI developer toolkit — knowledge base, code analysis, context management, and developer tools for LLM agents.
4
+
5
+ ## Features
6
+
7
+ - **64 MCP tools** for AI agents to search, analyze, and manipulate codebases
8
+ - **47 CLI commands** for shell-based interaction
9
+ - **Local-first** — ONNX embeddings, LanceDB vector store, no cloud dependencies
10
+ - **Three interfaces**: MCP (for agent IDEs), CLI (for terminal agents), and programmatic API
11
+
12
+ ## What This Is
13
+
14
+ This is an **MCP (Model Context Protocol) server** that gives AI agents:
15
+
16
+ 1. **Hybrid search** — combines semantic vector search with full-text keyword search (BM25) using Reciprocal Rank Fusion (RRF) for best results. Supports `hybrid` (default), `semantic`, and `keyword` modes.
17
+ 2. **Persistent curated memory** — agents can `remember`, `update`, `read`, `list`, and `forget` knowledge entries that survive across sessions
18
+ 3. **Codebase analysis** — structural analysis, dependency graphs with confidence scoring, symbol extraction, pattern detection, and Mermaid diagram generation. Analysis results are auto-persisted into the vector store for future search.
19
+ 4. **Knowledge production** — automated analysis pipelines that produce structured baselines for the agent to synthesize and store
20
+ 5. **Next-step workflow hints** — every tool response includes contextual `_Next:` suggestions guiding the agent to logical follow-up actions
21
+ 6. **Tree-sitter code chunking** — AST-based chunking for TS/JS/Python/Go/Rust/Java preserves function/class boundaries for higher-quality code search
22
+ 7. **Knowledge graph** — auto-populated SQLite graph of modules, symbols, and import relationships with traversal, neighbor queries, and change impact tracking
23
+ 8. **Graph auto-population** — during indexing, a lightweight regex extractor builds the knowledge graph automatically from TS/JS source files (functions, classes, interfaces, types, imports)
24
+ 9. **Optimized reindex** — full reindex skips redundant hash checks, batches graph writes (flush every 50 files), and skips per-file graph deletes when bulk-cleared
25
+
26
+ The KB auto-indexes configured source directories on startup, stores embeddings in a local LanceDB vector store, and exposes everything through 64 MCP tools, 47 CLI commands, and 2 resources.
27
+
28
+ ---
29
+
30
+ ## Quick Start
31
+
32
+ ```bash
33
+ # Install
34
+ pnpm add -D @anvpx/kb
35
+
36
+ # Initialize in your project
37
+ npx kb init
38
+
39
+ # Index your codebase
40
+ npx kb reindex
41
+
42
+ # Search
43
+ npx kb search "authentication middleware"
44
+
45
+ # Start MCP server for AI agents
46
+ npx kb serve
47
+ ```
48
+
49
+ ## Tools by Category
50
+
51
+ ### Search & Discovery
52
+ | Tool | CLI | Description |
53
+ |------|-----|-------------|
54
+ | `kb_search` | `kb search` | Hybrid vector + keyword search |
55
+ | `kb_find` | `kb find` | Federated search (vector, FTS, glob, regex) |
56
+ | `kb_symbol` | `kb symbol` | Resolve symbol definition, imports, references |
57
+ | `kb_lookup` | `kb lookup` | Look up indexed chunks by file path |
58
+ | `kb_trace` | `kb trace` | Forward/backward flow tracing |
59
+ | `kb_find_examples` | `kb examples` | Find usage examples of a symbol |
60
+ | `kb_scope_map` | `kb scope-map` | Generate task-scoped reading plan |
61
+ | `kb_dead_symbols` | `kb dead-symbols` | Find unused exported symbols |
62
+ | `kb_file_summary` | `kb summarize` | Structural file overview |
63
+
64
+ ### Code Analysis
65
+ | Tool | CLI | Description |
66
+ |------|-----|-------------|
67
+ | `kb_analyze_structure` | `kb analyze structure` | Project structure analysis |
68
+ | `kb_analyze_dependencies` | `kb analyze deps` | Dependency graph |
69
+ | `kb_analyze_symbols` | `kb analyze symbols` | Symbol extraction |
70
+ | `kb_analyze_patterns` | `kb analyze patterns` | Code pattern detection |
71
+ | `kb_analyze_entry_points` | `kb analyze entry-points` | Entry point discovery |
72
+ | `kb_analyze_diagram` | `kb analyze diagram` | Mermaid diagram generation |
73
+ | `kb_blast_radius` | `kb analyze blast-radius` | Change impact analysis |
74
+
75
+ ### Context Management
76
+ | Tool | CLI | Description |
77
+ |------|-----|-------------|
78
+ | `kb_compact` | `kb compact` | Compress text to relevant sections |
79
+ | `kb_workset` | `kb workset` | Named file set management |
80
+ | `kb_stash` | `kb stash` | Named key-value store |
81
+ | `kb_checkpoint` | `kb checkpoint` | Session checkpoint save/restore |
82
+ | `kb_parse_output` | `kb parse-output` | Parse build tool output (tsc, vitest, biome) |
83
+
84
+ ### FORGE & Context Compression
85
+ | Tool | CLI | Description |
86
+ |------|-----|-------------|
87
+ | `kb_forge_ground` | — | Complete FORGE Ground phase in one call (chains classify→scope→summarize→constraints→evidence) |
88
+ | `kb_forge_classify` | — | Classify FORGE tier (Floor/Standard/Critical) from files and task |
89
+ | `kb_evidence_map` | — | Track critical-path claims as V/A/U with receipts + deterministic Gate |
90
+ | `kb_digest` | — | Compress multiple text sources into token-budgeted digest |
91
+ | `kb_stratum_card` | — | Generate STRATUM T1/T2 context cards (10-100x token reduction) |
92
+
93
+ ### Code Manipulation
94
+ | Tool | CLI | Description |
95
+ |------|-----|-------------|
96
+ | `kb_rename` | `kb rename` | Smart symbol rename across files |
97
+ | `kb_codemod` | `kb codemod` | Regex-based code transformations |
98
+ | `kb_diff_parse` | `kb diff` | Parse unified diff into structured changes |
99
+ | `kb_data_transform` | `kb transform` | JQ-like JSON transformations |
100
+
101
+ ### Execution & Validation
102
+ | Tool | CLI | Description |
103
+ |------|-----|-------------|
104
+ | `kb_eval` | `kb eval` | Sandboxed JavaScript/TypeScript execution |
105
+ | `kb_check` | `kb check` | Incremental typecheck + lint |
106
+ | `kb_test_run` | `kb test` | Run tests with structured results |
107
+ | `kb_batch` | `kb batch` | Parallel operation execution |
108
+
109
+ ### Knowledge Management
110
+ | Tool | CLI | Description |
111
+ |------|-----|-------------|
112
+ | `kb_remember` | `kb remember` | Store curated knowledge |
113
+ | `kb_update` | `kb update` | Update existing entries |
114
+ | `kb_forget` | `kb forget` | Remove entries |
115
+ | `kb_read` | `kb read` | Read entry content |
116
+ | `kb_list` | `kb list` | List entries |
117
+ | `kb_produce_knowledge` | — | Auto-generate knowledge from analysis |
118
+
119
+ ### Git & Environment
120
+ | Tool | CLI | Description |
121
+ |------|-----|-------------|
122
+ | `kb_git_context` | `kb git` | Branch, status, recent commits |
123
+ | `kb_process` | `kb proc` | Process supervisor |
124
+ | `kb_watch` | `kb watch` | Filesystem watcher |
125
+ | `kb_delegate` | `kb delegate` | Delegate subtask to local Ollama model |
126
+
127
+ ### Web & Network
128
+ | Tool | CLI | Description |
129
+ |------|-----|-------------|
130
+ | `kb_web_fetch` | — | Fetch web page → markdown/raw/links/outline |
131
+ | `kb_web_search` | — | Search the web via DuckDuckGo (no API key) |
132
+ | `kb_http` | — | Make HTTP requests for API testing/debugging |
133
+
134
+ ### Developer Utilities
135
+ | Tool | CLI | Description |
136
+ |------|-----|-------------|
137
+ | `kb_regex_test` | — | Test regex patterns (match/replace/split modes) |
138
+ | `kb_encode` | — | Base64, URL, SHA-256, MD5, hex, JWT decode |
139
+ | `kb_measure` | — | Code complexity and line-count metrics |
140
+ | `kb_changelog` | — | Generate changelog from git history |
141
+ | `kb_schema_validate` | — | Validate JSON data against JSON Schema |
142
+ | `kb_snippet` | — | Persistent code snippet/template storage |
143
+ | `kb_env` | — | System and runtime environment info |
144
+ | `kb_time` | — | Date parsing, timezone conversion, duration math |
145
+
146
+ ### Verified Lanes
147
+ | Tool | CLI | Description |
148
+ |------|-----|-------------|
149
+ | `kb_lane` (create) | `kb lane create` | Create isolated file copy for parallel exploration |
150
+ | `kb_lane` (list) | `kb lane list` | List active lanes |
151
+ | `kb_lane` (status) | `kb lane status` | Show modified/added/deleted files in a lane |
152
+ | `kb_lane` (diff) | `kb lane diff` | Generate diff between lane and originals |
153
+ | `kb_lane` (merge) | `kb lane merge` | Merge lane files back to originals |
154
+ | `kb_lane` (discard) | `kb lane discard` | Discard a lane entirely |
155
+
156
+ ### System
157
+ | Tool | CLI | Description |
158
+ |------|-----|-------------|
159
+ | `kb_status` | `kb status` | Index statistics |
160
+ | `kb_reindex` | `kb reindex` | Rebuild index |
161
+ | `kb_health` | `kb health` | Project health checks (package.json, tsconfig, lockfile, etc.) |
162
+ | `kb_queue` | `kb queue` | Task queue for sequential agent operations |
163
+ | `kb_graph` | `kb graph` | Query and manage the knowledge graph (8 actions: find_nodes, find_edges, neighbors, traverse, stats, add, delete, clear) |
164
+ | `kb_onboard` | `kb onboard` | First-time codebase onboarding — runs all analysis tools in one command, auto-persists results |
165
+ | `kb_replay_list` | `kb replay` | View audit trail of tool invocations |
166
+ | `kb_replay_clear` | `kb replay-clear` | Clear the replay audit trail |
167
+
168
+ ### TUI Dashboard
169
+
170
+ ```bash
171
+ kb tui # Launch interactive Ink terminal dashboard
172
+ ```
173
+
174
+ The TUI is a human monitoring dashboard with 4 panels: Status, Search, Curated, and Activity Log. It shows real-time tool activity via the replay audit trail, letting you observe what an AI agent is doing with the KB.
175
+
176
+ ## MCP Integration
177
+
178
+ After `kb init`, your `.vscode/mcp.json` is configured automatically:
179
+
180
+ ```json
181
+ {
182
+ "servers": {
183
+ "knowledge-base": {
184
+ "command": "npx",
185
+ "args": ["kb", "serve"]
186
+ }
187
+ }
188
+ }
189
+ ```
190
+
191
+ ## CLI Usage
192
+
193
+ ```bash
194
+ kb <command> [options]
195
+
196
+ # Search & Discovery
197
+ kb search <query> [--limit N] [--mode hybrid|semantic|keyword]
198
+ kb find [query] [--glob pattern] [--pattern regex] [--limit N]
199
+ kb symbol <name>
200
+ kb scope-map <task> [--max-files N]
201
+ kb trace <symbol> [--direction forward|backward|both] [--depth N]
202
+ kb examples <query> [--limit N]
203
+ kb summarize <file>
204
+ kb dead-symbols [--limit N]
205
+
206
+ # Analysis
207
+ kb analyze <type> <path>
208
+ kb lookup <path>
209
+
210
+ # Context
211
+ kb compact <query> [--max-chars N]
212
+ kb workset <action> [name] [--files f1,f2]
213
+ kb stash <action> [key] [value]
214
+ kb checkpoint <action> [label]
215
+ kb parse-output [--tool tsc|vitest|biome|git-status]
216
+
217
+ # Code Manipulation
218
+ kb rename <old> <new> <path> [--dry-run]
219
+ kb codemod <path> --rules <file.json> [--dry-run]
220
+ kb diff
221
+ kb transform <expression>
222
+
223
+ # Execution
224
+ kb eval <code> [--lang js|ts] [--timeout N]
225
+ kb test [files...] [--grep pattern]
226
+ kb check [--skip-types] [--skip-lint]
227
+ kb batch
228
+
229
+ # Knowledge
230
+ kb remember <title> --category <cat> [--tags t1,t2]
231
+ kb forget <path> --reason <reason>
232
+ kb read <path>
233
+ kb list [--category cat] [--tag tag]
234
+ kb update <path> --reason <reason>
235
+
236
+ # Git & Environment
237
+ kb git [--commits N] [--diff]
238
+ kb proc <action> [id] [--command cmd]
239
+ kb watch <action> [--path dir]
240
+
241
+ # Verified Lanes
242
+ kb lane create <name> --files file1.ts,file2.ts
243
+ kb lane list
244
+ kb lane status <name>
245
+ kb lane diff <name>
246
+ kb lane merge <name>
247
+ kb lane discard <name>
248
+
249
+ # Graph
250
+ kb graph stats
251
+ kb graph find-nodes [--type module|function|class] [--query pattern]
252
+ kb graph find-edges [--type imports|defines] [--source path]
253
+ kb graph neighbors <nodeId> [--direction in|out|both]
254
+ kb graph traverse <startId> [--direction forward|backward] [--depth N]
255
+
256
+ # System
257
+ kb status
258
+ kb reindex [--full]
259
+ kb onboard <path> [--mode analyze|generate]
260
+ kb serve [--transport stdio|http] [--port N]
261
+ kb init [--force]
262
+ ```
263
+
264
+ ## Configuration
265
+
266
+ `kb.config.json`:
267
+
268
+ ```json
269
+ {
270
+ "sources": [{ "path": ".", "name": "project" }],
271
+ "embedding": {
272
+ "model": "Xenova/mxbai-embed-large-v1",
273
+ "dimensions": 1024
274
+ },
275
+ "store": {
276
+ "backend": "lancedb",
277
+ "path": ".kb-data/store"
278
+ },
279
+ "curated": {
280
+ "path": "curated"
281
+ }
282
+ }
283
+ ```
284
+
285
+ ## Architecture
286
+
287
+ ```text
288
+ @anvpx/kb
289
+ ├── packages/
290
+ │ ├── core/ — types, config, logger, constants
291
+ │ ├── store/ — LanceDB vector store
292
+ │ ├── embeddings/ — ONNX local embeddings
293
+ │ ├── chunker/ — tree-sitter + regex code chunking
294
+ │ ├── indexer/ — incremental file indexer
295
+ │ ├── analyzers/ — blast-radius, deps, symbols, patterns, diagrams
296
+ │ ├── tools/ — 49 tool modules (64 MCP tools)
297
+ │ ├── server/ — MCP protocol server
298
+ │ └── cli/ — command-line interface
299
+ ├── bin/kb.mjs — CLI entry point
300
+ └── skills/ — LLM skill files
301
+ ```
302
+
303
+ ## License
304
+
305
+ MIT
306
+
307
+ ### Development
308
+
309
+ ```bash
310
+ pnpm install # Install dependencies
311
+ pnpm build # Build all packages
312
+ pnpm test # Run tests (Vitest)
313
+ pnpm lint # Lint (Biome)
314
+ ```
315
+
316
+ ---
317
+
318
+ ## Detailed MCP Tools Reference
319
+
320
+ ### Search & Retrieval
321
+
322
+ #### `kb_search` — Hybrid search across the knowledge base
323
+
324
+ Find relevant code, docs, patterns, and curated knowledge using hybrid (vector + keyword), semantic, or keyword-only search.
325
+
326
+ | Parameter | Type | Required | Default | Description |
327
+ |-----------|------|----------|---------|-------------|
328
+ | `query` | string | **yes** | — | Natural language search query |
329
+ | `limit` | number (1–20) | no | 5 | Maximum results to return |
330
+ | `search_mode` | enum | no | `hybrid` | Search strategy: `hybrid` (vector + FTS + RRF fusion), `semantic` (vector only), `keyword` (FTS only) |
331
+ | `content_type` | enum | no | — | Filter: `markdown`, `code-typescript`, `code-javascript`, `code-python`, `config-json`, `config-yaml`, `config-toml`, `config-dotenv`, `infrastructure`, `documentation`, `test`, `script`, `curated-knowledge`, `produced-knowledge`, `other` |
332
+ | `origin` | enum | no | — | Filter: `indexed` (from files), `curated` (agent memory), `produced` (auto-generated) |
333
+ | `category` | string | no | — | Filter by curated category (e.g., `decisions`, `patterns`) |
334
+ | `tags` | string[] | no | — | Filter by tags (OR matching) |
335
+ | `min_score` | number (0–1) | no | 0.25 | Minimum similarity score threshold |
336
+
337
+ **Returns**: Ranked results with score, source path, content type, line range, heading path, origin, tags, and full content text. Each response includes a `_Next:` hint suggesting logical follow-up tools.
338
+
339
+ **Search modes**:
340
+ - **`hybrid`** (default) — Runs vector similarity and full-text keyword search in parallel, then merges rankings using Reciprocal Rank Fusion (k=60). Best for most queries.
341
+ - **`semantic`** — Pure vector cosine similarity. Best when searching by meaning/concept rather than exact terms.
342
+ - **`keyword`** — Full-text search using LanceDB's built-in FTS index. Best when searching for exact identifiers, function names, or specific strings.
343
+
344
+ **Best practices for query**:
345
+ - Use natural language describing what you're looking for: `"how does the notification dispatcher route messages"`
346
+ - Include domain terms that would appear in the code: `"DynamoDB single-table GSI pattern for notifications"`
347
+ - Use `search_mode: "keyword"` for exact function/class names: `"reciprocalRankFusion"`
348
+ - Use `search_mode: "semantic"` for conceptual queries: `"retry strategy with exponential backoff"`
349
+ - For curated knowledge, combine with `origin: "curated"`: `query: "architecture decision", origin: "curated"`
350
+
351
+ #### `kb_lookup` — Get all chunks for a specific file
352
+
353
+ | Parameter | Type | Required | Description |
354
+ |-----------|------|----------|-------------|
355
+ | `path` | string | **yes** | Relative file path (e.g., `src/index.ts`) |
356
+
357
+ **Returns**: All chunks for that file, sorted by position, with line ranges and content.
358
+
359
+ #### `kb_status` — View index statistics
360
+
361
+ No parameters. Returns total records, total files, content type breakdown, last indexed timestamp, and list of indexed files.
362
+
363
+ ### Curated Knowledge (Persistent Memory)
364
+
365
+ These tools give the agent **persistent, version-tracked memory** that survives across sessions. Knowledge is stored as markdown files with YAML frontmatter in the `curated/` directory and simultaneously indexed into the vector store for semantic search.
366
+
367
+ #### `kb_remember` — Store new knowledge
368
+
369
+ | Parameter | Type | Required | Description |
370
+ |-----------|------|----------|-------------|
371
+ | `title` | string (3–120 chars) | **yes** | Short descriptive title |
372
+ | `content` | string (≥10 chars) | **yes** | Markdown content to store |
373
+ | `category` | string (kebab-case) | **yes** | Category slug: `decisions`, `patterns`, `conventions`, `troubleshooting`, or any custom kebab-case name |
374
+ | `tags` | string[] | no | Tags for filtering |
375
+
376
+ **What to remember**: Architecture decisions, coding conventions, recurring patterns, API contracts, deployment procedures, debugging solutions, team agreements, review findings.
377
+
378
+ #### `kb_update` — Update existing knowledge
379
+
380
+ | Parameter | Type | Required | Description |
381
+ |-----------|------|----------|-------------|
382
+ | `path` | string | **yes** | Path from `kb_list` (e.g., `decisions/use-lancedb.md`) |
383
+ | `content` | string (≥10 chars) | **yes** | New markdown content (replaces existing) |
384
+ | `reason` | string (≥3 chars) | **yes** | Why this update is being made (recorded in changelog) |
385
+
386
+ Increments version number and appends to the entry's changelog.
387
+
388
+ #### `kb_read` — Read a curated entry
389
+
390
+ | Parameter | Type | Required | Description |
391
+ |-----------|------|----------|-------------|
392
+ | `path` | string | **yes** | Path from `kb_list` |
393
+
394
+ **Returns**: Full metadata (title, version, tags, created, updated) and content.
395
+
396
+ #### `kb_list` — List curated entries
397
+
398
+ | Parameter | Type | Required | Description |
399
+ |-----------|------|----------|-------------|
400
+ | `category` | string | no | Filter by category |
401
+ | `tag` | string | no | Filter by tag |
402
+
403
+ **Returns**: All entries with title, version, tags, path, and 80-char content preview.
404
+
405
+ #### `kb_forget` — Remove a curated entry
406
+
407
+ | Parameter | Type | Required | Description |
408
+ |-----------|------|----------|-------------|
409
+ | `path` | string | **yes** | Path from `kb_list` |
410
+ | `reason` | string (≥3 chars) | **yes** | Why this entry is being removed |
411
+
412
+ Deletes from disk and vector store.
413
+
414
+ ### Indexing
415
+
416
+ #### `kb_reindex` — Trigger re-indexing
417
+
418
+ | Parameter | Type | Required | Default | Description |
419
+ |-----------|------|----------|---------|-------------|
420
+ | `full` | boolean | no | false | If true, force full re-index ignoring file hashes |
421
+
422
+ Incremental mode (default) only re-indexes files whose content hash has changed. Full mode drops the table and rebuilds from scratch.
423
+
424
+ ### Codebase Analysis
425
+
426
+ #### `kb_produce_knowledge` — Automated analysis + synthesis instructions
427
+
428
+ | Parameter | Type | Required | Default | Description |
429
+ |-----------|------|----------|---------|-------------|
430
+ | `scope` | string | no | `.` (root) | Root path to analyze |
431
+ | `aspects` | enum[] | no | `["all"]` | `all`, `structure`, `dependencies`, `symbols`, `patterns`, `entry-points`, `diagrams` |
432
+
433
+ Runs deterministic analyzers, then returns structured instructions for the agent to synthesize and store findings using `kb_remember`.
434
+
435
+ #### `kb_analyze_structure` — File/directory tree with language stats
436
+
437
+ | Parameter | Type | Required | Default | Description |
438
+ |-----------|------|----------|---------|-------------|
439
+ | `path` | string | **yes** | — | Root path to analyze |
440
+ | `max_depth` | number (1–10) | no | 6 | Maximum directory depth |
441
+ | `format` | enum | no | `markdown` | `json` or `markdown` |
442
+
443
+ #### `kb_analyze_dependencies` — Import/require dependency graph (with confidence)
444
+
445
+ | Parameter | Type | Required | Default | Description |
446
+ |-----------|------|----------|---------|-------------|
447
+ | `path` | string | **yes** | — | Root path |
448
+ | `format` | enum | no | `markdown` | `json`, `markdown`, or `mermaid` |
449
+
450
+ Dependency results include a **confidence** level per import: `high` (ES static imports), `medium` (dynamic imports, require()), `low` (inferred). The markdown format shows a Confidence column in dependency tables.
451
+
452
+ #### `kb_analyze_symbols` — Exported & local symbols
453
+
454
+ | Parameter | Type | Required | Default | Description |
455
+ |-----------|------|----------|---------|-------------|
456
+ | `path` | string | **yes** | — | Root path |
457
+ | `filter` | string | no | — | Filter symbols by name substring |
458
+ | `format` | enum | no | `markdown` | `json` or `markdown` |
459
+
460
+ #### `kb_analyze_patterns` — Detect architectural patterns & frameworks
461
+
462
+ | Parameter | Type | Required | Description |
463
+ |-----------|------|----------|-------------|
464
+ | `path` | string | **yes** | Root path |
465
+
466
+ #### `kb_analyze_entry_points` — Find Lambda handlers, CLI bins, server starts
467
+
468
+ | Parameter | Type | Required | Description |
469
+ |-----------|------|----------|-------------|
470
+ | `path` | string | **yes** | Root path |
471
+
472
+ #### `kb_analyze_diagram` — Generate Mermaid architecture/dependency diagrams
473
+
474
+ | Parameter | Type | Required | Default | Description |
475
+ |-----------|------|----------|---------|-------------|
476
+ | `path` | string | **yes** | — | Root path |
477
+ | `diagram_type` | enum | no | `architecture` | `architecture` or `dependencies` |
478
+
479
+ ### Context Management
480
+
481
+ #### `kb_compact` — Compress text to query-relevant sections
482
+
483
+ | Parameter | Type | Required | Default | Description |
484
+ |-----------|------|----------|---------|-------------|
485
+ | `text` | string | **yes** | — | The text to compress |
486
+ | `query` | string | **yes** | — | Focus query — what are you trying to understand? |
487
+ | `max_chars` | number (100–50000) | no | `3000` | Target output size in characters |
488
+ | `segmentation` | enum | no | `paragraph` | How to split: `paragraph`, `sentence`, `line` |
489
+
490
+ Uses embedding similarity (no LLM needed) to keep only the segments most relevant to the query. Returns compression stats (original → compressed chars, ratio, segments kept/total) and the compressed text.
491
+
492
+ #### `kb_workset` — Manage named file sets
493
+
494
+ | Parameter | Type | Required | Default | Description |
495
+ |-----------|------|----------|---------|-------------|
496
+ | `action` | enum | **yes** | — | `save`, `get`, `list`, `delete`, `add`, `remove` |
497
+ | `name` | string | varies | — | Workset name (required for all except `list`) |
498
+ | `files` | string[] | varies | — | File paths (required for `save`, `add`, `remove`) |
499
+ | `description` | string | no | — | Description (for `save`) |
500
+
501
+ Worksets persist across sessions in `.kb-state/worksets.json`.
502
+
503
+ #### `kb_stash` — Persist named key-value pairs
504
+
505
+ | Parameter | Type | Required | Default | Description |
506
+ |-----------|------|----------|---------|-------------|
507
+ | `action` | enum | **yes** | — | `set`, `get`, `list`, `delete`, `clear` |
508
+ | `key` | string | varies | — | Entry key (for `set`, `get`, `delete`) |
509
+ | `value` | string | varies | — | String or JSON value (for `set`) |
510
+
511
+ Stores intermediate results between tool calls in `.kb-state/stash.json`.
512
+
513
+ #### `kb_checkpoint` — Save/restore session checkpoints
514
+
515
+ | Parameter | Type | Required | Default | Description |
516
+ |-----------|------|----------|---------|-------------|
517
+ | `action` | enum | **yes** | — | `save`, `load`, `list`, `latest` |
518
+ | `label` | string | varies | — | Checkpoint label (for `save`), or checkpoint ID (for `load`) |
519
+ | `data` | string | varies | — | JSON object string (for `save`) |
520
+ | `notes` | string | no | — | Optional notes (for `save`) |
521
+
522
+ Lightweight checkpoints stored in `.kb-state/checkpoints/` for cross-session continuity.
523
+
524
+ #### `kb_parse_output` — Parse build tool output
525
+
526
+ | Parameter | Type | Required | Default | Description |
527
+ |-----------|------|----------|---------|-------------|
528
+ | `output` | string | **yes** | — | Raw output text from a build tool |
529
+ | `tool` | enum | no | auto-detect | `tsc`, `vitest`, `biome`, `git-status` |
530
+
531
+ Returns JSON structured parse result with errors, warnings, and file references. Auto-detects the tool format when not specified.
532
+
533
+ ### FORGE & Context Compression
534
+
535
+ #### `kb_forge_ground` — Complete FORGE Ground phase
536
+
537
+ | Parameter | Type | Required | Default | Description |
538
+ |-----------|------|----------|---------|-------------|
539
+ | `task` | string | **yes** | — | Task description |
540
+ | `files` | string[] | **yes** | — | Target files being modified (absolute paths) |
541
+ | `root_path` | string | **yes** | — | Root path of the codebase |
542
+ | `max_constraints` | number (0–10) | no | `3` | Max constraint entries to load from KB |
543
+ | `force_tier` | enum | no | auto | Force tier: `floor`, `standard`, `critical` (skips auto-classification) |
544
+ | `task_id` | string | no | auto-generated | Custom task ID for evidence map |
545
+
546
+ Chains: tier classification → scope map → file summaries → constraint loading → typed unknown seeds → evidence map creation. Replaces 5-15 manual tool calls. Floor tasks get a minimal shortcut (no scope map / constraints / evidence map).
547
+
548
+ #### `kb_forge_classify` — Classify FORGE tier
549
+
550
+ | Parameter | Type | Required | Description |
551
+ |-----------|------|----------|-------------|
552
+ | `files` | string[] | **yes** | Files being modified (paths) |
553
+ | `task` | string | **yes** | Task description |
554
+ | `root_path` | string | **yes** | Root path of the codebase |
555
+
556
+ Checks blast radius, cross-package boundaries, schema/contract patterns, and security signals. Returns tier, triggers, typed unknown seeds, packages crossed, and ceremony guidance.
557
+
558
+ #### `kb_evidence_map` — FORGE Evidence Map CRUD + Gate
559
+
560
+ | Parameter | Type | Required | Default | Description |
561
+ |-----------|------|----------|---------|-------------|
562
+ | `action` | enum | **yes** | — | `create`, `add`, `update`, `get`, `gate`, `list`, `delete` |
563
+ | `task_id` | string | varies | — | Task identifier (all except `list`) |
564
+ | `tier` | enum | varies | — | FORGE tier (for `create`): `floor`, `standard`, `critical` |
565
+ | `claim` | string | varies | — | Critical-path claim text (for `add`) |
566
+ | `status` | enum | varies | — | `V` (Verified), `A` (Assumed), `U` (Unresolved) |
567
+ | `receipt` | string | no | — | Evidence: tool→ref for V, reasoning for A, attempts for U |
568
+ | `id` | number | varies | — | Entry ID (for `update`) |
569
+ | `critical_path` | boolean | no | `true` | Whether claim is on the critical path |
570
+ | `unknown_type` | enum | no | — | `contract`, `convention`, `freshness`, `runtime`, `data-flow`, `impact` |
571
+ | `retry_count` | number | no | `0` | Retry count for gate evaluation |
572
+
573
+ Gate decision logic: HARD_BLOCK (contract U on critical path) → HOLD (non-contract U, retry 0) → FORCED_DELIVERY (non-contract U, retry ≥ 1) → YIELD. Persists in `.kb-state/evidence-maps.json`.
574
+
575
+ #### `kb_digest` — Token-budgeted multi-source compression
576
+
577
+ | Parameter | Type | Required | Default | Description |
578
+ |-----------|------|----------|---------|-------------|
579
+ | `sources` | object[] | **yes** | — | Sources: `{ id, text, weight }` (weight = priority, higher = more budget) |
580
+ | `query` | string | **yes** | — | Focus query — what matters for the next step? |
581
+ | `max_chars` | number (100–50000) | no | `4000` | Target budget in characters |
582
+ | `pin_fields` | string[] | no | status, files, decisions, blockers, next | Key fields to always extract |
583
+ | `segmentation` | enum | no | `paragraph` | `paragraph`, `sentence`, `line` |
584
+
585
+ Jointly ranks across all sources using embedding similarity. Pins structured fields (key:value patterns) and allocates remaining budget proportionally by weight. Returns compressed text + extracted fields + per-source stats.
586
+
587
+ #### `kb_stratum_card` — STRATUM context cards
588
+
589
+ | Parameter | Type | Required | Default | Description |
590
+ |-----------|------|----------|---------|-------------|
591
+ | `files` | string[] | **yes** | — | Absolute file paths to generate cards for |
592
+ | `query` | string | **yes** | — | Current task query — guides relevance scoring |
593
+ | `tier` | enum | no | `T1` | `T1` = structural only (~100 tok/file), `T2` = T1 + compressed content (~300 tok/file) |
594
+ | `max_content_chars` | number (100–5000) | no | `800` | For T2: max chars for compressed content section |
595
+
596
+ T1 cards contain: ROLE, DEPS, EXPORTS, UNKNOWNS, RISK. T2 adds a CONTEXT section with query-compressed content. Uses `kb_file_summary` + embedder similarity. No generative LLM needed.
597
+
598
+ ### Search & Discovery
599
+
600
+ #### `kb_find` — Federated multi-strategy search
601
+
602
+ | Parameter | Type | Required | Default | Description |
603
+ |-----------|------|----------|---------|-------------|
604
+ | `query` | string | no | — | Semantic/keyword search query |
605
+ | `glob` | string | no | — | File glob pattern |
606
+ | `pattern` | string | no | — | Regex pattern to match in content |
607
+ | `limit` | number (1–50) | no | `10` | Max results |
608
+ | `content_type` | string | no | — | Filter by content type |
609
+
610
+ Combines vector similarity, keyword (FTS), file glob, and regex strategies. Deduplicates and returns unified results with source, path, line range, score %, and preview.
611
+
612
+ #### `kb_symbol` — Resolve a symbol across the codebase
613
+
614
+ | Parameter | Type | Required | Default | Description |
615
+ |-----------|------|----------|---------|-------------|
616
+ | `name` | string | **yes** | — | Symbol name (function, class, type, etc.) |
617
+ | `limit` | number (1–50) | no | `20` | Max results per category |
618
+
619
+ Finds where a symbol is defined, who imports it, and where it is referenced. Works on TypeScript and JavaScript.
620
+
621
+ #### `kb_scope_map` — Generate a task-scoped reading plan
622
+
623
+ | Parameter | Type | Required | Default | Description |
624
+ |-----------|------|----------|---------|-------------|
625
+ | `task` | string | **yes** | — | Description of the task to scope |
626
+ | `max_files` | number (1–50) | no | `15` | Maximum files to include |
627
+ | `content_type` | string | no | — | Filter by content type |
628
+
629
+ Returns a ranked file list with estimated token counts, relevance %, focus line ranges, and a suggested reading order.
630
+
631
+ #### `kb_trace` — Trace data flow through imports/references
632
+
633
+ | Parameter | Type | Required | Default | Description |
634
+ |-----------|------|----------|---------|-------------|
635
+ | `start` | string | **yes** | — | Starting point — symbol name or `file:line` reference |
636
+ | `direction` | enum | **yes** | — | `forward`, `backward`, `both` |
637
+ | `max_depth` | number (1–10) | no | `3` | Maximum trace depth |
638
+
639
+ Follows imports, call sites, and references to build a relationship graph from a starting symbol or file location.
640
+
641
+ #### `kb_find_examples` — Find real usage examples
642
+
643
+ | Parameter | Type | Required | Default | Description |
644
+ |-----------|------|----------|---------|-------------|
645
+ | `query` | string | **yes** | — | Symbol or pattern to find examples of |
646
+ | `limit` | number (1–20) | no | `5` | Maximum examples to return |
647
+ | `content_type` | string | no | — | Filter by content type |
648
+
649
+ Returns usage examples with file paths and code snippets from the indexed codebase.
650
+
651
+ #### `kb_dead_symbols` — Find unused exported symbols
652
+
653
+ | Parameter | Type | Required | Default | Description |
654
+ |-----------|------|----------|---------|-------------|
655
+ | `limit` | number (1–500) | no | `100` | Maximum exported symbols to scan |
656
+
657
+ Finds exported symbols that are never imported or re-exported anywhere in the project.
658
+
659
+ #### `kb_file_summary` — Structural summary of a source file
660
+
661
+ | Parameter | Type | Required | Description |
662
+ |-----------|------|----------|-------------|
663
+ | `path` | string | **yes** | Absolute path to the file |
664
+
665
+ Returns imports, exports, functions, classes, interfaces, and types found in the file.
666
+
667
+ ### Code Manipulation
668
+
669
+ #### `kb_rename` — Rename a symbol across files
670
+
671
+ | Parameter | Type | Required | Default | Description |
672
+ |-----------|------|----------|---------|-------------|
673
+ | `old_name` | string | **yes** | — | Existing symbol name |
674
+ | `new_name` | string | **yes** | — | New symbol name |
675
+ | `root_path` | string | **yes** | — | Root directory to search within |
676
+ | `extensions` | string[] | no | — | File extensions to include (e.g., `.ts`, `.tsx`) |
677
+ | `dry_run` | boolean | no | `true` | Preview changes without writing files |
678
+
679
+ Uses whole-word regex matching for exports, imports, and general usage references. Defaults to dry run.
680
+
681
+ #### `kb_codemod` — Apply regex-based codemod rules
682
+
683
+ | Parameter | Type | Required | Default | Description |
684
+ |-----------|------|----------|---------|-------------|
685
+ | `root_path` | string | **yes** | — | Root directory to transform within |
686
+ | `rules` | object[] (min 1) | **yes** | — | Codemod rules: `description`, `pattern` (regex), `replacement` (with capture groups) |
687
+ | `dry_run` | boolean | no | `true` | Preview changes without writing files |
688
+
689
+ Returns structured before/after changes for each affected line. Defaults to dry run.
690
+
691
+ #### `kb_diff_parse` — Parse unified diff text
692
+
693
+ | Parameter | Type | Required | Description |
694
+ |-----------|------|----------|-------------|
695
+ | `diff` | string | **yes** | Raw unified diff text |
696
+
697
+ Parses into file-level and hunk-level structural changes.
698
+
699
+ #### `kb_data_transform` — jq-like JSON transforms
700
+
701
+ | Parameter | Type | Required | Description |
702
+ |-----------|------|----------|-------------|
703
+ | `input` | string | **yes** | Input JSON string |
704
+ | `expression` | string | **yes** | Transform expression (filtering, projection, grouping, path extraction) |
705
+
706
+ ### Execution & Validation
707
+
708
+ #### `kb_eval` — Execute code in a sandboxed VM
709
+
710
+ | Parameter | Type | Required | Default | Description |
711
+ |-----------|------|----------|---------|-------------|
712
+ | `code` | string | **yes** | — | Code snippet to execute |
713
+ | `lang` | enum | no | `js` | `js` (direct) or `ts` (strips type syntax first) |
714
+ | `timeout` | number (1–60000) | no | `5000` | Execution timeout in milliseconds |
715
+
716
+ Captures console output and return values. Constrained VM with timeout.
717
+
718
+ #### `kb_check` — Run typecheck and lint
719
+
720
+ | Parameter | Type | Required | Default | Description |
721
+ |-----------|------|----------|---------|-------------|
722
+ | `files` | string[] | no | — | Specific files (omit to check all) |
723
+ | `cwd` | string | no | — | Working directory |
724
+ | `skip_types` | boolean | no | `false` | Skip TypeScript typecheck |
725
+ | `skip_lint` | boolean | no | `false` | Skip Biome lint |
726
+
727
+ Runs incremental `tsc` and `biome` and returns structured error/warning lists.
728
+
729
+ #### `kb_test_run` — Run Vitest tests
730
+
731
+ | Parameter | Type | Required | Default | Description |
732
+ |-----------|------|----------|---------|-------------|
733
+ | `files` | string[] | no | — | Specific test files or patterns |
734
+ | `grep` | string | no | — | Only run tests matching this pattern |
735
+ | `cwd` | string | no | — | Working directory |
736
+
737
+ Returns structured pass/fail summary. `isError` set if any tests failed.
738
+
739
+ #### `kb_batch` — Execute multiple operations in parallel
740
+
741
+ | Parameter | Type | Required | Default | Description |
742
+ |-----------|------|----------|---------|-------------|
743
+ | `operations` | object[] (min 1) | **yes** | — | Operations: `id` (string), `type` (`search`/`find`/`check`), `args` (record) |
744
+ | `concurrency` | number (1–20) | no | `4` | Max concurrent operations |
745
+
746
+ Returns per-operation outcomes (success/failure with results or errors).
747
+
748
+ ### Git & Environment
749
+
750
+ #### `kb_git_context` — Summarize Git repository state
751
+
752
+ | Parameter | Type | Required | Default | Description |
753
+ |-----------|------|----------|---------|-------------|
754
+ | `cwd` | string | no | — | Repository root |
755
+ | `commit_count` | number (1–50) | no | `5` | Recent commits to include |
756
+ | `include_diff` | boolean | no | `false` | Include diff stat for working tree |
757
+
758
+ Returns branch, working tree status, recent commits, and optionally diff stats.
759
+
760
+ #### `kb_process` — Manage child processes
761
+
762
+ | Parameter | Type | Required | Default | Description |
763
+ |-----------|------|----------|---------|-------------|
764
+ | `action` | enum | **yes** | — | `start`, `stop`, `status`, `list`, `logs` |
765
+ | `id` | string | varies | — | Managed process ID |
766
+ | `command` | string | varies | — | Executable (for `start`) |
767
+ | `args` | string[] | no | — | Arguments (for `start`) |
768
+ | `tail` | number (1–500) | no | — | Log lines (for `logs`) |
769
+
770
+ #### `kb_watch` — Filesystem watchers
771
+
772
+ | Parameter | Type | Required | Default | Description |
773
+ |-----------|------|----------|---------|-------------|
774
+ | `action` | enum | **yes** | — | `start`, `stop`, `list` |
775
+ | `path` | string | varies | — | Directory path (for `start`) |
776
+ | `id` | string | varies | — | Watcher ID (for `stop`) |
777
+
778
+ #### `kb_delegate` — Delegate subtask to local Ollama model
779
+
780
+ | Parameter | Type | Required | Default | Description |
781
+ |-----------|------|----------|---------|-------------|
782
+ | `prompt` | string | **yes** | — | Task or question to send |
783
+ | `model` | string | no | first available | Ollama model name |
784
+ | `system` | string | no | — | System prompt |
785
+ | `context` | string | no | — | Context text (e.g., file contents) |
786
+ | `temperature` | number (0–2) | no | `0.3` | Sampling temperature |
787
+ | `timeout` | number (1000–600000) | no | `120000` | Timeout in ms |
788
+ | `action` | enum | no | `generate` | `generate` or `list_models` |
789
+
790
+ Fails fast if Ollama is not running. Returns model name, response text, duration, and token count.
791
+
792
+ ### Web & Network
793
+
794
+ #### `kb_web_fetch` — Fetch web page for LLM consumption
795
+
796
+ | Parameter | Type | Required | Default | Description |
797
+ |-----------|------|----------|---------|-------------|
798
+ | `url` | string | **yes** | — | URL to fetch (http/https only) |
799
+ | `mode` | enum | no | `markdown` | `markdown`, `raw`, `links`, `outline` |
800
+ | `selector` | string | no | — | CSS selector to extract a specific element |
801
+ | `max_length` | number (500–100000) | no | `15000` | Max output characters |
802
+ | `include_metadata` | boolean | no | `true` | Include page title/description header |
803
+ | `include_links` | boolean | no | `false` | Append extracted links |
804
+ | `include_images` | boolean | no | `false` | Include image alt texts |
805
+ | `timeout` | number (1000–60000) | no | `15000` | Request timeout in ms |
806
+
807
+ Strips scripts, styles, and boilerplate. Smart truncation at paragraph boundaries.
808
+
809
+ #### `kb_web_search` — Search the web
810
+
811
+ | Parameter | Type | Required | Default | Description |
812
+ |-----------|------|----------|---------|-------------|
813
+ | `query` | string | **yes** | — | Search query |
814
+ | `limit` | number (1–20) | no | `5` | Max results |
815
+ | `site` | string | no | — | Restrict to domain (e.g., `docs.aws.amazon.com`) |
816
+
817
+ Uses DuckDuckGo HTML search — no API key required. Returns title, URL, and snippet for each result.
818
+
819
+ #### `kb_http` — Make HTTP requests
820
+
821
+ | Parameter | Type | Required | Default | Description |
822
+ |-----------|------|----------|---------|-------------|
823
+ | `url` | string | **yes** | — | Request URL (http/https only) |
824
+ | `method` | enum | no | `GET` | `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD` |
825
+ | `headers` | record | no | — | Request headers |
826
+ | `body` | string | no | — | Request body |
827
+ | `timeout` | number (1000–60000) | no | `15000` | Timeout in ms |
828
+
829
+ Returns status, headers, formatted body (auto-pretty-prints JSON), timing, and size. Truncates responses over 50K chars.
830
+
831
+ ### Developer Utilities
832
+
833
+ #### `kb_regex_test` — Test regex patterns
834
+
835
+ | Parameter | Type | Required | Default | Description |
836
+ |-----------|------|----------|---------|-------------|
837
+ | `pattern` | string | **yes** | — | Regex pattern (without delimiters) |
838
+ | `flags` | string | no | `""` | Regex flags (g, i, m, s, etc.) |
839
+ | `test_strings` | string[] | **yes** | — | Strings to test against |
840
+ | `mode` | enum | no | `match` | `match`, `replace`, `split` |
841
+ | `replacement` | string | no | — | Replacement string (for replace mode) |
842
+
843
+ Returns match details with groups and indices for each test string.
844
+
845
+ #### `kb_encode` — Encoding, decoding, and hashing
846
+
847
+ | Parameter | Type | Required | Description |
848
+ |-----------|------|----------|-------------|
849
+ | `operation` | enum | **yes** | `base64_encode`, `base64_decode`, `url_encode`, `url_decode`, `sha256`, `md5`, `jwt_decode`, `hex_encode`, `hex_decode` |
850
+ | `input` | string | **yes** | Input text |
851
+
852
+ JWT decode shows header and payload without signature verification.
853
+
854
+ #### `kb_measure` — Code complexity metrics
855
+
856
+ | Parameter | Type | Required | Default | Description |
857
+ |-----------|------|----------|---------|-------------|
858
+ | `path` | string | **yes** | — | File or directory to measure |
859
+ | `extensions` | string[] | no | `.ts,.tsx,.js,.jsx` | File extensions to include |
860
+
861
+ Returns per-file metrics (cyclomatic complexity, line counts, function counts, imports/exports) sorted by complexity, plus aggregate summary.
862
+
863
+ #### `kb_changelog` — Generate changelog from git history
864
+
865
+ | Parameter | Type | Required | Default | Description |
866
+ |-----------|------|----------|---------|-------------|
867
+ | `from` | string | **yes** | — | Start ref (tag, SHA, HEAD~N) |
868
+ | `to` | string | no | `HEAD` | End ref |
869
+ | `format` | enum | no | `grouped` | `grouped`, `chronological`, `per-scope` |
870
+ | `include_breaking` | boolean | no | `true` | Highlight breaking changes |
871
+
872
+ Parses conventional commit format (type(scope): subject). Groups by feat/fix/refactor/etc.
873
+
874
+ #### `kb_schema_validate` — JSON Schema validation
875
+
876
+ | Parameter | Type | Required | Description |
877
+ |-----------|------|----------|-------------|
878
+ | `data` | string | **yes** | JSON data to validate (as string) |
879
+ | `schema` | string | **yes** | JSON Schema to validate against (as string) |
880
+
881
+ Supports: type, required, properties, additionalProperties, items, enum, const, pattern, minimum/maximum, minLength/maxLength, minItems/maxItems.
882
+
883
+ #### `kb_snippet` — Persistent code snippet storage
884
+
885
+ | Parameter | Type | Required | Description |
886
+ |-----------|------|----------|-------------|
887
+ | `action` | enum | **yes** | `save`, `get`, `list`, `search`, `delete` |
888
+ | `name` | string | varies | Snippet name |
889
+ | `language` | string | no | Language tag |
890
+ | `code` | string | varies | Code content (for save) |
891
+ | `tags` | string[] | no | Categorization tags |
892
+ | `query` | string | varies | Search query (for search) |
893
+
894
+ Stored as JSON in `.kb-state/snippets/`. Searchable by name, tags, language, and content.
895
+
896
+ #### `kb_env` — System environment info
897
+
898
+ | Parameter | Type | Required | Default | Description |
899
+ |-----------|------|----------|---------|-------------|
900
+ | `include_env` | boolean | no | `false` | Include environment variables |
901
+ | `filter_env` | string | no | — | Filter env vars by name substring |
902
+ | `show_sensitive` | boolean | no | `false` | Show sensitive values (redacted by default) |
903
+
904
+ Returns platform, arch, OS, CPU count, memory, Node version, CWD. Sensitive env var values (keys matching key/secret/token/password) are redacted unless explicitly requested.
905
+
906
+ #### `kb_time` — Date/time utilities
907
+
908
+ | Parameter | Type | Required | Description |
909
+ |-----------|------|----------|-------------|
910
+ | `operation` | enum | **yes** | `now`, `parse`, `convert`, `diff`, `add` |
911
+ | `input` | string | varies | Date input (ISO, unix timestamp, parseable string). For diff: two comma-separated dates |
912
+ | `timezone` | string | no | Target timezone (e.g., `America/New_York`) |
913
+ | `duration` | string | no | Duration to add (e.g., `2h30m`, `1d`) — for add operation |
914
+
915
+ Auto-detects unix seconds vs milliseconds. Supports human-readable duration format (2h30m, 1d12h).
916
+
917
+ ### Verified Lanes
918
+
919
+ #### `kb_lane` — Manage verified lanes
920
+
921
+ | Parameter | Type | Required | Default | Description |
922
+ |-----------|------|----------|---------|-------------|
923
+ | `action` | enum | **yes** | — | `create`, `list`, `status`, `diff`, `merge`, `discard` |
924
+ | `name` | string | varies | — | Lane name |
925
+ | `files` | string[] | varies | — | File paths to copy into lane (for `create`) |
926
+
927
+ Isolated file copies for parallel exploration. Create a lane, make changes, diff against originals, merge back, or discard.
928
+
929
+ ### System
930
+
931
+ #### `kb_health` — Run project health checks
932
+
933
+ | Parameter | Type | Required | Default | Description |
934
+ |-----------|------|----------|---------|-------------|
935
+ | `path` | string | no | cwd | Root directory to check |
936
+
937
+ Verifies package.json, tsconfig, scripts, lockfile, README, LICENSE, .gitignore.
938
+
939
+ #### `kb_queue` — Manage task queues
940
+
941
+ | Parameter | Type | Required | Default | Description |
942
+ |-----------|------|----------|---------|-------------|
943
+ | `action` | enum | **yes** | — | `create`, `push`, `next`, `done`, `fail`, `get`, `list`, `clear`, `delete` |
944
+ | `name` | string | varies | — | Queue name |
945
+ | `title` | string | varies | — | Item title (for `push`) |
946
+ | `id` | string | varies | — | Item ID (for `done`/`fail`) |
947
+ | `data` | any | no | — | Arbitrary data to attach |
948
+ | `error` | string | varies | — | Error message (for `fail`) |
949
+
950
+ Sequential task queues for agent operations.
951
+
952
+ #### `kb_replay_list` — View audit trail
953
+
954
+ | Parameter | Type | Required | Default | Description |
955
+ |-----------|------|----------|---------|-------------|
956
+ | `last` | number | no | 20 | Number of entries to return |
957
+ | `tool` | string | no | — | Filter by tool name (e.g., `kb_search`) |
958
+ | `source` | enum | no | — | Filter by source: `mcp` or `cli` |
959
+ | `since` | string | no | — | ISO timestamp — only show entries after this time |
960
+
961
+ Shows the audit trail of recent tool invocations. Each entry includes tool name, duration, input/output summaries, and status. Useful for debugging agent behavior.
962
+
963
+ #### `kb_replay_clear` — Clear audit trail
964
+
965
+ No parameters. Clears the entire replay log.
966
+
967
+ ---
968
+
969
+ ## MCP Resources
970
+
971
+ | URI | Name | Description |
972
+ |-----|------|-------------|
973
+ | `kb://status` | `kb-status` | Quick status: record count, file count, last indexed time |
974
+ | `kb://file-tree` | `kb-file-tree` | Sorted list of all indexed source file paths |
975
+
976
+ ---
977
+
978
+ ## Curated Knowledge System
979
+
980
+ The curated system is the agent's **persistent memory layer**. Files are stored as markdown with YAML frontmatter in `curated/`:
981
+
982
+ ```
983
+ curated/
984
+ ├── conventions/ # 214 entries — coding conventions, style rules, naming patterns
985
+ ├── decisions/ # 295 entries — architecture decisions, ADRs, design rationale
986
+ ├── patterns/ # 165 entries — recurring patterns, templates, code idioms
987
+ └── troubleshooting/ # 62 entries — known issues, fixes, debugging guides
988
+ ```
989
+
990
+ ### Frontmatter Format
991
+
992
+ ```yaml
993
+ ---
994
+ title: "Use LanceDB for local vector storage"
995
+ category: decisions
996
+ tags: ["vector-store", "architecture", "lancedb"]
997
+ created: 2026-01-15T10:30:00.000Z
998
+ updated: 2026-02-20T14:22:00.000Z
999
+ version: 3
1000
+ origin: curated
1001
+ changelog:
1002
+ - version: 1
1003
+ date: 2026-01-15T10:30:00.000Z
1004
+ reason: "Initial creation"
1005
+ - version: 2
1006
+ date: 2026-02-01T09:00:00.000Z
1007
+ reason: "Added performance benchmarks"
1008
+ - version: 3
1009
+ date: 2026-02-20T14:22:00.000Z
1010
+ reason: "Updated with hybrid search findings"
1011
+ ---
1012
+
1013
+ Markdown content here...
1014
+ ```
1015
+
1016
+ ### Category Guidelines
1017
+
1018
+ | Category | Use For | Examples |
1019
+ |----------|---------|---------|
1020
+ | `conventions` | Rules the team follows | Naming patterns, import ordering, error handling style, test structure |
1021
+ | `decisions` | Why something was chosen | ADRs, technology choices, pattern selections with trade-offs |
1022
+ | `patterns` | How to do recurring things | CDK stack templates, API endpoint patterns, state machine shapes |
1023
+ | `troubleshooting` | Known problems and fixes | Build failures, deployment gotchas, dependency conflicts |
1024
+ | Custom (`api-contracts`, `runbooks`, etc.) | Any kebab-case slug | Domain-specific categories as needed |
1025
+
1026
+ ---
1027
+
1028
+ ## How to Write Agent Instructions for Using This KB
1029
+
1030
+ When writing instructions for an AI agent (e.g., in `.copilot-instructions.md`, `AGENTS.md`, `CLAUDE.md`, or system prompts), include the following guidance:
1031
+
1032
+ ### Recommended Agent Instruction Template
1033
+
1034
+ ```markdown
1035
+ ## Knowledge Base Usage
1036
+
1037
+ You have access to a persistent knowledge base via MCP tools. Use it proactively.
1038
+
1039
+ ### Before Starting Any Task
1040
+ 1. **Search first**: Use `kb_search` with a natural language query describing your task to find relevant context, prior decisions, conventions, and patterns before writing code.
1041
+ 2. **Check conventions**: `kb_search` with `origin: "curated"` and `category: "conventions"` for coding standards that apply to your work.
1042
+ 3. **Check decisions**: `kb_search` with `category: "decisions"` to understand why things were built a certain way.
1043
+
1044
+ ### Search Strategies
1045
+ - **Broad hybrid** (default, best for most queries): `kb_search({ query: "notification routing architecture" })`
1046
+ - **Exact identifier lookup**: `kb_search({ query: "handleNotification", search_mode: "keyword" })`
1047
+ - **Conceptual similarity**: `kb_search({ query: "event-driven message fanout design", search_mode: "semantic" })`
1048
+ - **Specific convention**: `kb_search({ query: "error handling", origin: "curated", category: "conventions" })`
1049
+ - **Code patterns**: `kb_search({ query: "DynamoDB batch write pattern", content_type: "code-typescript" })`
1050
+ - **Troubleshooting**: `kb_search({ query: "deployment failure CDK", category: "troubleshooting" })`
1051
+ - **View a full file**: `kb_lookup({ path: "src/services/dispatcher.ts" })`
1052
+
1053
+ ### Follow the Hints
1054
+ Every tool response includes a `_Next:` suggestion at the bottom. Follow these hints for efficient workflows — they guide you to logical next actions (e.g., after `kb_search`, the hint suggests `kb_lookup` or `kb_analyze_structure`).
1055
+
1056
+ ### After Completing a Task
1057
+ 1. **Remember decisions**: If you made an architecture or design decision, store it:
1058
+ ```
1059
+ kb_remember({
1060
+ title: "Use event-driven pattern for notification fanout",
1061
+ content: "## Decision\n\n...\n\n## Rationale\n\n...\n\n## Alternatives Considered\n\n...",
1062
+ category: "decisions",
1063
+ tags: ["notifications", "architecture", "event-driven"]
1064
+ })
1065
+ ```
1066
+ 2. **Remember patterns**: If you established a reusable code pattern:
1067
+ ```
1068
+ kb_remember({
1069
+ title: "CDK construct pattern for SQS-Lambda integration",
1070
+ content: "## Pattern\n\n```typescript\n...\n```\n\n## When to Use\n\n...",
1071
+ category: "patterns",
1072
+ tags: ["cdk", "sqs", "lambda"]
1073
+ })
1074
+ ```
1075
+ 3. **Remember troubleshooting**: If you solved a tricky bug:
1076
+ ```
1077
+ kb_remember({
1078
+ title: "LanceDB dimension mismatch after model change",
1079
+ content: "## Problem\n\n...\n\n## Solution\n\nRun `kb_reindex({ full: true })`...",
1080
+ category: "troubleshooting",
1081
+ tags: ["lancedb", "embeddings"]
1082
+ })
1083
+ ```
1084
+ 4. **Update existing knowledge**: If you're revising a prior decision:
1085
+ ```
1086
+ kb_update({
1087
+ path: "decisions/use-event-driven-fanout.md",
1088
+ content: "updated markdown...",
1089
+ reason: "Added retry strategy after production incident"
1090
+ })
1091
+ ```
1092
+
1093
+ ### Knowledge Quality Standards
1094
+ - **Decisions** should include: Context, Decision, Rationale, Alternatives Considered, Consequences
1095
+ - **Patterns** should include: Pattern description, Code example, When to Use, When Not to Use
1096
+ - **Conventions** should include: The Rule, Why, Examples (good vs bad)
1097
+ - **Troubleshooting** should include: Problem, Symptoms, Root Cause, Solution, Prevention
1098
+
1099
+ ### Codebase Analysis (for onboarding or deep understanding)
1100
+ - Run `kb_produce_knowledge({ aspects: ["all"] })` to get analysis baselines and follow the synthesis instructions to populate the KB
1101
+ - Use `kb_analyze_structure({ path: "." })` for project layout overview
1102
+ - Use `kb_analyze_dependencies({ path: ".", format: "mermaid" })` for dependency visualization
1103
+ - Use `kb_analyze_patterns({ path: "." })` to detect frameworks and conventions
1104
+
1105
+ ### Index Maintenance
1106
+ - Run `kb_reindex()` after significant code changes (incremental, fast)
1107
+ - Run `kb_reindex({ full: true })` after model changes or corruption
1108
+ - Check `kb_status()` to verify index health
1109
+ ```
1110
+
1111
+ ---
1112
+
1113
+ ## Environment Variables
1114
+
1115
+ | Variable | Default | Description |
1116
+ |----------|---------|-------------|
1117
+ | `KB_TRANSPORT` | `stdio` | Transport mode: `stdio` or `http` |
1118
+ | `KB_PORT` | `3210` | HTTP server port (when `--transport http`) |
1119
+ | `KB_AUTO_INDEX` | `true` | Set to `false` to skip initial auto-indexing |
1120
+ | `KB_CORS_ORIGIN` | `*` | CORS allowed origin for HTTP mode |
1121
+ | `KB_WORKSPACE_DIR` | — | Override workspace root path |
1122
+ | `KB_DATA_DIR` | — | Override LanceDB data directory |
1123
+ | `KB_MODEL_DIR` | — | Override ONNX model cache directory |
1124
+
1125
+ ---
1126
+
1127
+ ## Tech Stack
1128
+
1129
+ - **Embeddings**: `@huggingface/transformers` with `mixedbread-ai/mxbai-embed-large-v1` (1024 dimensions, ONNX, query-prefixed with `"Represent this sentence for searching relevant passages: "`)
1130
+ - **Vector Store**: LanceDB (local disk, L2 distance → similarity score, built-in FTS index for keyword search)
1131
+ - **Search**: Hybrid (vector + FTS + RRF fusion), semantic-only, or keyword-only modes
1132
+ - **Chunking**: Markdown-aware (heading hierarchy), **tree-sitter AST-based** (TS/JS/Python/Go/Rust/Java — preserves function/class boundaries), with overlap. Falls back to regex-based generic chunking when tree-sitter grammars are unavailable.
1133
+ - **Dependency Analysis**: Confidence-scored imports (high/medium/low per import pattern)
1134
+ - **Auto-Persist**: Analysis tool results are automatically indexed as `origin: 'produced'` entries for future search
1135
+ - **Workflow Hints**: Every tool response includes `_Next:` suggestions for logical follow-up actions
1136
+ - **MCP SDK**: `@modelcontextprotocol/sdk` (stdio + StreamableHTTP transports)
1137
+ - **Runtime**: Node.js ≥ 24, TypeScript, ESM, pnpm workspaces
1138
+ - **Build**: esbuild with tsc for declarations
1139
+ - **Lint**: Biome
1140
+ - **Test**: Vitest