@dikolab/kbdb 0.3.0 → 0.3.2

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 (428) hide show
  1. package/README.md +89 -120
  2. package/dist/bench/constants/corpus-defaults.constant.d.ts +3 -0
  3. package/dist/bench/functions/format-report.function.d.ts +11 -0
  4. package/dist/bench/functions/generate-corpus.function.d.ts +12 -0
  5. package/dist/bench/functions/measure-operation.function.d.ts +14 -0
  6. package/dist/bench/functions/seeded-rng.function.d.ts +11 -0
  7. package/dist/bench/functions/zipf-word.function.d.ts +13 -0
  8. package/dist/bench/index.d.ts +10 -0
  9. package/dist/bench/typings/bench-result.interface.d.ts +11 -0
  10. package/dist/bench/typings/bench-suite-result.interface.d.ts +10 -0
  11. package/dist/bench/typings/corpus-config.interface.d.ts +11 -0
  12. package/dist/bench/typings/corpus-section.interface.d.ts +9 -0
  13. package/dist/cli.cjs +63 -9
  14. package/dist/cli.cjs.map +2 -2
  15. package/dist/cli.mjs +63 -9
  16. package/dist/cli.mjs.map +2 -2
  17. package/dist/src/shared/auto-capture/classes/auto-capture-controller.class.d.ts +33 -0
  18. package/dist/src/shared/auto-capture/constants/auto-capture-defaults.constant.d.ts +8 -0
  19. package/dist/src/shared/auto-capture/functions/build-capture-prompt.function.d.ts +11 -0
  20. package/dist/src/shared/auto-capture/functions/evaluate-trigger.function.d.ts +12 -0
  21. package/dist/src/shared/auto-capture/index.d.ts +7 -0
  22. package/dist/src/shared/auto-capture/typings/auto-capture-config.interface.d.ts +13 -0
  23. package/dist/src/shared/auto-capture/typings/auto-capture-state.interface.d.ts +13 -0
  24. package/dist/src/shared/auto-capture/typings/auto-capture-trigger.interface.d.ts +7 -0
  25. package/dist/src/shared/cli/constants/global-help.constant.d.ts +8 -0
  26. package/dist/src/shared/cli/constants/leaf-help.constant.d.ts +7 -0
  27. package/dist/src/shared/cli/constants/memory-protocol-body.constant.d.ts +7 -0
  28. package/dist/src/shared/cli/constants/query-guidance-body.constant.d.ts +7 -0
  29. package/dist/src/shared/cli/constants/subcommand-help.constant.d.ts +8 -0
  30. package/dist/src/shared/cli/functions/collect-files.function.d.ts +13 -0
  31. package/dist/src/shared/cli/functions/compute-section-kbid.function.d.ts +15 -0
  32. package/dist/src/shared/cli/functions/format-mcp-output.function.d.ts +9 -0
  33. package/dist/src/shared/cli/functions/format-text-output.function.d.ts +9 -0
  34. package/dist/src/shared/cli/functions/generate-group-help.function.d.ts +11 -0
  35. package/dist/src/shared/cli/functions/handle-data-command.function.d.ts +16 -0
  36. package/dist/src/shared/cli/functions/handle-mcp.function.d.ts +15 -0
  37. package/dist/src/shared/cli/functions/handle-migrate.function.d.ts +15 -0
  38. package/dist/src/shared/cli/functions/hydrate-search-previews.function.d.ts +14 -0
  39. package/dist/src/shared/cli/functions/resolve-skill-names.function.d.ts +16 -0
  40. package/dist/src/shared/cli/functions/run-search.function.d.ts +1 -0
  41. package/dist/src/shared/cli/functions/version-gate.function.d.ts +15 -0
  42. package/dist/src/shared/cli/functions/wrap-command.function.d.ts +15 -0
  43. package/dist/src/shared/cli/typings/agent-create-client.interface.d.ts +42 -0
  44. package/dist/src/shared/cli/typings/agent-get-client.interface.d.ts +36 -0
  45. package/dist/src/shared/cli/typings/check-client.interface.d.ts +58 -0
  46. package/dist/src/shared/cli/typings/cli-deps.interface.d.ts +48 -0
  47. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
  48. package/dist/src/shared/cli/typings/disconnectable-client.interface.d.ts +26 -0
  49. package/dist/src/shared/cli/typings/dispatch-client.type.d.ts +27 -0
  50. package/dist/src/shared/cli/typings/learn-client.interface.d.ts +52 -0
  51. package/dist/src/shared/cli/typings/learn-io.interface.d.ts +5 -0
  52. package/dist/src/shared/cli/typings/search-client.interface.d.ts +71 -0
  53. package/dist/src/shared/embedding/classes/null-embedding-provider.class.d.ts +20 -0
  54. package/dist/src/shared/embedding/constants/near-duplicate-thresholds.constant.d.ts +15 -0
  55. package/dist/src/shared/embedding/functions/build-vector-index.function.d.ts +14 -0
  56. package/dist/src/shared/embedding/functions/cosine-similarity.function.d.ts +10 -0
  57. package/dist/src/shared/embedding/functions/detect-near-duplicates.function.d.ts +18 -0
  58. package/dist/src/shared/embedding/functions/jaccard-coefficient.function.d.ts +9 -0
  59. package/dist/src/shared/embedding/functions/read-vector-index-meta.function.d.ts +10 -0
  60. package/dist/src/shared/embedding/functions/rrf-fuse.function.d.ts +14 -0
  61. package/dist/src/shared/embedding/functions/search-vectors.function.d.ts +14 -0
  62. package/dist/src/shared/embedding/index.d.ts +16 -0
  63. package/dist/src/shared/embedding/typings/embedding-config.interface.d.ts +20 -0
  64. package/dist/src/shared/embedding/typings/embedding-provider.interface.d.ts +23 -0
  65. package/dist/src/shared/embedding/typings/near-duplicate-candidate.model.d.ts +23 -0
  66. package/dist/src/shared/embedding/typings/near-duplicate-result.model.d.ts +24 -0
  67. package/dist/src/shared/embedding/typings/vector-index-entry.model.d.ts +12 -0
  68. package/dist/src/shared/embedding/typings/vector-index-meta.model.d.ts +11 -0
  69. package/dist/src/shared/embedding/typings/vector-search-result.model.d.ts +7 -0
  70. package/dist/src/shared/mcp/constants/tool-agent-create.constant.d.ts +3 -0
  71. package/dist/src/shared/mcp/constants/tool-agent-delete.constant.d.ts +3 -0
  72. package/dist/src/shared/mcp/constants/tool-agent-get.constant.d.ts +3 -0
  73. package/dist/src/shared/mcp/constants/tool-agent-list.constant.d.ts +3 -0
  74. package/dist/src/shared/mcp/constants/tool-auto-capture-review.constant.d.ts +8 -0
  75. package/dist/src/shared/mcp/constants/tool-check.constant.d.ts +3 -0
  76. package/dist/src/shared/mcp/constants/tool-content.constant.d.ts +3 -0
  77. package/dist/src/shared/mcp/constants/tool-export.constant.d.ts +3 -0
  78. package/dist/src/shared/mcp/constants/tool-gc.constant.d.ts +3 -0
  79. package/dist/src/shared/mcp/constants/tool-learn.constant.d.ts +3 -0
  80. package/dist/src/shared/mcp/constants/tool-rebuild.constant.d.ts +3 -0
  81. package/dist/src/shared/mcp/constants/tool-recall.constant.d.ts +3 -0
  82. package/dist/src/shared/mcp/constants/tool-retrieve.constant.d.ts +3 -0
  83. package/dist/src/shared/mcp/constants/tool-search.constant.d.ts +3 -0
  84. package/dist/src/shared/mcp/constants/tool-skill-delete.constant.d.ts +3 -0
  85. package/dist/src/shared/mcp/constants/tool-skill-get.constant.d.ts +3 -0
  86. package/dist/src/shared/mcp/constants/tool-skill-learn.constant.d.ts +3 -0
  87. package/dist/src/shared/mcp/constants/tool-skill-list.constant.d.ts +3 -0
  88. package/dist/src/shared/mcp/constants/tool-status.constant.d.ts +3 -0
  89. package/dist/src/shared/mcp/constants/tool-unlearn.constant.d.ts +3 -0
  90. package/dist/src/shared/mcp/functions/as-boolean-or-undefined.function.d.ts +7 -0
  91. package/dist/src/shared/mcp/functions/as-string-array-or-undefined.function.d.ts +7 -0
  92. package/dist/src/shared/mcp/functions/as-string-array.function.d.ts +7 -0
  93. package/dist/src/shared/mcp/functions/as-string.function.d.ts +8 -0
  94. package/dist/src/shared/mcp/functions/build-skills-text.function.d.ts +18 -0
  95. package/dist/src/shared/mcp/functions/handle-agent-prompt.function.d.ts +14 -0
  96. package/dist/src/shared/mcp/functions/handle-mcp-request.function.d.ts +14 -0
  97. package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +4 -3
  98. package/dist/src/shared/mcp/functions/handle-skill-prompt.function.d.ts +16 -0
  99. package/dist/src/shared/mcp/functions/handle-tool-auto-capture-review.function.d.ts +12 -0
  100. package/dist/src/shared/mcp/functions/handle-tool-check.function.d.ts +11 -0
  101. package/dist/src/shared/mcp/functions/handle-tool-content.function.d.ts +12 -0
  102. package/dist/src/shared/mcp/functions/handle-tool-export.function.d.ts +12 -0
  103. package/dist/src/shared/mcp/functions/handle-tool-gc.function.d.ts +11 -0
  104. package/dist/src/shared/mcp/functions/handle-tool-learn.function.d.ts +12 -0
  105. package/dist/src/shared/mcp/functions/handle-tool-rebuild.function.d.ts +11 -0
  106. package/dist/src/shared/mcp/functions/handle-tool-retrieve.function.d.ts +12 -0
  107. package/dist/src/shared/mcp/functions/handle-tool-search.function.d.ts +13 -0
  108. package/dist/src/shared/mcp/functions/handle-tool-skill-delete.function.d.ts +12 -0
  109. package/dist/src/shared/mcp/functions/handle-tool-skill-get.function.d.ts +13 -0
  110. package/dist/src/shared/mcp/functions/handle-tool-skill-learn.function.d.ts +13 -0
  111. package/dist/src/shared/mcp/functions/handle-tool-skill-list.function.d.ts +11 -0
  112. package/dist/src/shared/mcp/functions/handle-tool-status.function.d.ts +11 -0
  113. package/dist/src/shared/mcp/functions/handle-tool-unlearn.function.d.ts +12 -0
  114. package/dist/src/shared/mcp/functions/parse-agent-meta.function.d.ts +14 -0
  115. package/dist/src/shared/mcp/functions/parse-skill-arguments.function.d.ts +11 -0
  116. package/dist/src/shared/mcp/functions/read-agent-meta.function.d.ts +17 -0
  117. package/dist/src/shared/mcp/functions/resolve-skill-refs.function.d.ts +23 -0
  118. package/dist/src/shared/mcp/functions/run-startup-health-check.function.d.ts +14 -0
  119. package/dist/src/shared/mcp/typings/mcp-capabilities.interface.d.ts +16 -0
  120. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +2 -0
  121. package/dist/src/shared/mcp/typings/mcp-completion.interface.d.ts +43 -0
  122. package/dist/src/shared/mcp/typings/mcp-content-result.model.d.ts +9 -0
  123. package/dist/src/shared/mcp/typings/mcp-export-result.model.d.ts +11 -0
  124. package/dist/src/shared/mcp/typings/mcp-gc-result.model.d.ts +15 -0
  125. package/dist/src/shared/mcp/typings/mcp-integrity-check-result.model.d.ts +16 -0
  126. package/dist/src/shared/mcp/typings/mcp-integrity-error.model.d.ts +9 -0
  127. package/dist/src/shared/mcp/typings/mcp-notification.interface.d.ts +9 -0
  128. package/dist/src/shared/mcp/typings/mcp-rebuild-result.model.d.ts +9 -0
  129. package/dist/src/shared/mcp/typings/mcp-request.interface.d.ts +11 -0
  130. package/dist/src/shared/mcp/typings/mcp-resource-result.interface.d.ts +12 -0
  131. package/dist/src/shared/mcp/typings/mcp-resource-template.interface.d.ts +11 -0
  132. package/dist/src/shared/mcp/typings/mcp-response.interface.d.ts +18 -0
  133. package/dist/src/shared/mcp/typings/mcp-server-info.interface.d.ts +7 -0
  134. package/dist/src/shared/mcp/typings/mcp-server-state.interface.d.ts +16 -0
  135. package/dist/src/shared/mcp/typings/mcp-tool-annotations.interface.d.ts +32 -0
  136. package/dist/src/shared/mcp/typings/mcp-tool-definition.interface.d.ts +15 -0
  137. package/dist/src/shared/mcp/typings/mcp-tool-result.interface.d.ts +19 -0
  138. package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +220 -0
  139. package/dist/src/shared/mcp/typings/tool-call-result.model.d.ts +17 -0
  140. package/dist/src/shared/sync/functions/build-import-report.function.d.ts +18 -0
  141. package/dist/src/shared/sync/functions/parse-export-entry.function.d.ts +11 -0
  142. package/dist/src/shared/sync/functions/resolve-conflict.function.d.ts +13 -0
  143. package/dist/src/shared/sync/functions/serialize-export-entry.function.d.ts +8 -0
  144. package/dist/src/shared/sync/index.d.ts +9 -0
  145. package/dist/src/shared/sync/typings/conflict-resolution.type.d.ts +8 -0
  146. package/dist/src/shared/sync/typings/export-entry.interface.d.ts +13 -0
  147. package/dist/src/shared/sync/typings/export-options.interface.d.ts +9 -0
  148. package/dist/src/shared/sync/typings/import-options.interface.d.ts +7 -0
  149. package/dist/src/shared/sync/typings/import-report.interface.d.ts +15 -0
  150. package/dist/src/shared/wasm-codec/functions/decode-one-recall-result.function.d.ts +14 -0
  151. package/dist/src/shared/wasm-codec/functions/decode-option-string.function.d.ts +12 -0
  152. package/dist/src/shared/wasm-codec/functions/decode-recall-document.function.d.ts +14 -0
  153. package/dist/src/shared/wasm-codec/functions/decode-recall-reference.function.d.ts +14 -0
  154. package/dist/src/shared/wasm-codec/functions/decode-recall-sibling.function.d.ts +13 -0
  155. package/dist/src/shared/wasm-codec/functions/decode-section-match.function.d.ts +15 -0
  156. package/dist/src/shared/wasm-codec/functions/decode-section-record-trailing.function.d.ts +14 -0
  157. package/dist/src/shared/wasm-codec/functions/decode-section-record.function.d.ts +14 -0
  158. package/dist/src/shared/wasm-codec/functions/decode-section-type.function.d.ts +13 -0
  159. package/dist/src/shared/wasm-codec/functions/decode-wasm-list.function.d.ts +17 -0
  160. package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +45 -0
  161. package/dist/src/shared/wasm-codec/typings/add-section-result.model.d.ts +27 -0
  162. package/dist/src/shared/wasm-codec/typings/document-manifest.model.d.ts +19 -0
  163. package/dist/src/shared/wasm-codec/typings/document-section.model.d.ts +12 -0
  164. package/dist/src/shared/wasm-codec/typings/item-decoder.type.d.ts +6 -0
  165. package/dist/src/shared/wasm-codec/typings/near-duplicate.model.d.ts +16 -0
  166. package/dist/src/shared/wasm-codec/typings/paged-search-result.model.d.ts +21 -0
  167. package/dist/src/shared/wasm-codec/typings/section-match.model.d.ts +31 -0
  168. package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +38 -0
  169. package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +66 -0
  170. package/dist/src/shared/wasm-codec/typings/section-type-result.model.d.ts +12 -0
  171. package/dist/src/shared/worker-client/functions/handle-ipc-data.function.d.ts +16 -0
  172. package/dist/src/shared/worker-client/functions/send-ipc-request.function.d.ts +19 -0
  173. package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +2 -0
  174. package/dist/src/shared/worker-client/typings/json-rpc-response.interface.d.ts +16 -0
  175. package/dist/src/shared/worker-client/typings/pending-call.interface.d.ts +7 -0
  176. package/dist/src/shared/worker-client/typings/recall-document.model.d.ts +16 -0
  177. package/dist/src/shared/worker-client/typings/recall-params.model.d.ts +15 -0
  178. package/dist/src/shared/worker-client/typings/recall-reference.model.d.ts +32 -0
  179. package/dist/src/shared/worker-client/typings/recall-sibling.model.d.ts +11 -0
  180. package/dist/src/shared/worker-client/typings/recall-single-result.model.d.ts +40 -0
  181. package/dist/src/shared/worker-daemon/classes/ipc-error.class.d.ts +17 -0
  182. package/dist/src/shared/worker-daemon/constants/wasm-method-map.constant.d.ts +16 -0
  183. package/dist/src/shared/worker-daemon/functions/build-ipc-error-response.function.d.ts +9 -0
  184. package/dist/src/shared/worker-daemon/functions/check-catalog-version.function.d.ts +9 -0
  185. package/dist/src/shared/worker-daemon/functions/check-preconditions.function.d.ts +10 -0
  186. package/dist/src/shared/worker-daemon/functions/detect-stale-pid.function.d.ts +15 -0
  187. package/dist/src/shared/worker-daemon/functions/dispatch-request.function.d.ts +35 -0
  188. package/dist/src/shared/worker-daemon/functions/handle-check-version.function.d.ts +23 -0
  189. package/dist/src/shared/worker-daemon/functions/handle-config-method.function.d.ts +11 -0
  190. package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +52 -0
  191. package/dist/src/shared/worker-daemon/functions/handle-write-ops.function.d.ts +44 -0
  192. package/dist/src/shared/worker-daemon/functions/parse-auto-capture-section.function.d.ts +14 -0
  193. package/dist/src/shared/worker-daemon/functions/parse-catalog-version.function.d.ts +10 -0
  194. package/dist/src/shared/worker-daemon/functions/parse-embedding-section.function.d.ts +13 -0
  195. package/dist/src/shared/worker-daemon/functions/parse-worker-toml.function.d.ts +11 -0
  196. package/dist/src/shared/worker-daemon/functions/run-startup-integrity-check.function.d.ts +18 -0
  197. package/dist/src/shared/worker-daemon/functions/scan-near-duplicates.function.d.ts +21 -0
  198. package/dist/src/shared/worker-daemon/functions/wasm-bridge.function.d.ts +51 -0
  199. package/dist/src/shared/worker-daemon/functions/wasm-memory-helpers.function.d.ts +22 -0
  200. package/dist/src/shared/worker-daemon/functions/write-lock.function.d.ts +32 -0
  201. package/dist/src/shared/worker-daemon/typings/allocator-ref.interface.d.ts +16 -0
  202. package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +6 -0
  203. package/dist/src/shared/worker-daemon/typings/fs-adapter.interface.d.ts +22 -0
  204. package/dist/src/shared/worker-daemon/typings/handler-context.interface.d.ts +18 -0
  205. package/dist/src/shared/worker-daemon/typings/memory-ref.interface.d.ts +13 -0
  206. package/dist/src/shared/worker-daemon/typings/wasm-fn.type.d.ts +2 -0
  207. package/dist/src/shared/worker-daemon/typings/write-lock.interface.d.ts +15 -0
  208. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  209. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  210. package/docs/details/cli.md +9 -0
  211. package/docs/details/mcp-server.md +5 -3
  212. package/docs/details/search-and-ranking.md +55 -0
  213. package/docs/goals/auto-capture.md +378 -0
  214. package/docs/goals/benchmarking.md +296 -0
  215. package/docs/goals/concurrency.md +259 -0
  216. package/docs/goals/hybrid-search.md +436 -0
  217. package/docs/goals/semantic-dedup.md +229 -0
  218. package/docs/goals/sync.md +217 -0
  219. package/docs/modules/rust/fs-database/indexes/vectors.md +110 -0
  220. package/docs/modules/typescript/shared/auto-capture/module.md +73 -0
  221. package/docs/modules/typescript/shared/embedding/functions.md +94 -0
  222. package/docs/modules/typescript/shared/embedding/module.md +71 -0
  223. package/docs/modules/typescript/shared/embedding/typings.md +122 -0
  224. package/docs/overview.md +171 -167
  225. package/docs/release-notes/0.2.0.md +3 -3
  226. package/docs/release-notes/0.3.0.md +89 -0
  227. package/docs/release-notes/0.3.1.md +121 -0
  228. package/docs/release-notes/0.3.2.md +64 -0
  229. package/docs/release-notes/README.md +3 -0
  230. package/package.json +1 -1
  231. package/src/shared/auto-capture/classes/auto-capture-controller.class.ts +62 -0
  232. package/src/shared/auto-capture/constants/auto-capture-defaults.constant.ts +15 -0
  233. package/src/shared/auto-capture/functions/build-capture-prompt.function.ts +27 -0
  234. package/src/shared/auto-capture/functions/evaluate-trigger.function.ts +50 -0
  235. package/src/shared/auto-capture/index.ts +7 -0
  236. package/src/shared/auto-capture/typings/auto-capture-config.interface.ts +13 -0
  237. package/src/shared/auto-capture/typings/auto-capture-state.interface.ts +13 -0
  238. package/src/shared/auto-capture/typings/auto-capture-trigger.interface.ts +7 -0
  239. package/src/shared/cli/constants/global-help.constant.ts +73 -0
  240. package/src/shared/cli/constants/leaf-help.constant.ts +219 -0
  241. package/src/shared/cli/constants/memory-protocol-body.constant.ts +39 -0
  242. package/src/shared/cli/constants/query-guidance-body.constant.ts +37 -0
  243. package/src/shared/cli/constants/subcommand-help.constant.ts +195 -0
  244. package/src/shared/cli/functions/collect-files.function.ts +55 -0
  245. package/src/shared/cli/functions/compute-section-kbid.function.ts +49 -0
  246. package/src/shared/cli/functions/format-mcp-output.function.ts +41 -0
  247. package/src/shared/cli/functions/format-text-output.function.ts +42 -0
  248. package/src/shared/cli/functions/generate-group-help.function.ts +41 -0
  249. package/src/shared/cli/functions/handle-data-command.function.ts +67 -0
  250. package/src/shared/cli/functions/handle-mcp.function.ts +56 -0
  251. package/src/shared/cli/functions/handle-migrate.function.ts +64 -0
  252. package/src/shared/cli/functions/hydrate-search-previews.function.ts +29 -0
  253. package/src/shared/cli/functions/parse-args.function.ts +3 -0
  254. package/src/shared/cli/functions/resolve-skill-names.function.ts +43 -0
  255. package/src/shared/cli/functions/run-search.function.ts +2 -0
  256. package/src/shared/cli/functions/version-gate.function.ts +44 -0
  257. package/src/shared/cli/functions/wrap-command.function.ts +34 -0
  258. package/src/shared/cli/typings/agent-create-client.interface.ts +47 -0
  259. package/src/shared/cli/typings/agent-get-client.interface.ts +39 -0
  260. package/src/shared/cli/typings/check-client.interface.ts +66 -0
  261. package/src/shared/cli/typings/cli-deps.interface.ts +54 -0
  262. package/src/shared/cli/typings/cli-options.interface.ts +2 -0
  263. package/src/shared/cli/typings/disconnectable-client.interface.ts +29 -0
  264. package/src/shared/cli/typings/dispatch-client.type.ts +46 -0
  265. package/src/shared/cli/typings/learn-client.interface.ts +53 -0
  266. package/src/shared/cli/typings/learn-io.interface.ts +5 -0
  267. package/src/shared/cli/typings/search-client.interface.ts +73 -0
  268. package/src/shared/embedding/classes/null-embedding-provider.class.ts +29 -0
  269. package/src/shared/embedding/constants/near-duplicate-thresholds.constant.ts +17 -0
  270. package/src/shared/embedding/functions/build-vector-index.function.ts +79 -0
  271. package/src/shared/embedding/functions/cosine-similarity.function.ts +31 -0
  272. package/src/shared/embedding/functions/detect-near-duplicates.function.ts +69 -0
  273. package/src/shared/embedding/functions/jaccard-coefficient.function.ts +26 -0
  274. package/src/shared/embedding/functions/read-vector-index-meta.function.ts +44 -0
  275. package/src/shared/embedding/functions/rrf-fuse.function.ts +33 -0
  276. package/src/shared/embedding/functions/search-vectors.function.ts +59 -0
  277. package/src/shared/embedding/index.ts +20 -0
  278. package/src/shared/embedding/typings/embedding-config.interface.ts +23 -0
  279. package/src/shared/embedding/typings/embedding-provider.interface.ts +25 -0
  280. package/src/shared/embedding/typings/near-duplicate-candidate.model.ts +25 -0
  281. package/src/shared/embedding/typings/near-duplicate-result.model.ts +26 -0
  282. package/src/shared/embedding/typings/vector-index-entry.model.ts +13 -0
  283. package/src/shared/embedding/typings/vector-index-meta.model.ts +14 -0
  284. package/src/shared/embedding/typings/vector-search-result.model.ts +8 -0
  285. package/src/shared/mcp/classes/mcp-server.class.ts +6 -3
  286. package/src/shared/mcp/constants/tool-agent-create.constant.ts +39 -0
  287. package/src/shared/mcp/constants/tool-agent-delete.constant.ts +26 -0
  288. package/src/shared/mcp/constants/tool-agent-get.constant.ts +24 -0
  289. package/src/shared/mcp/constants/tool-agent-list.constant.ts +18 -0
  290. package/src/shared/mcp/constants/tool-auto-capture-review.constant.ts +32 -0
  291. package/src/shared/mcp/constants/tool-check.constant.ts +21 -0
  292. package/src/shared/mcp/constants/tool-content.constant.ts +29 -0
  293. package/src/shared/mcp/constants/tool-export.constant.ts +27 -0
  294. package/src/shared/mcp/constants/tool-gc.constant.ts +21 -0
  295. package/src/shared/mcp/constants/tool-learn.constant.ts +58 -0
  296. package/src/shared/mcp/constants/tool-rebuild.constant.ts +21 -0
  297. package/src/shared/mcp/constants/tool-recall.constant.ts +36 -0
  298. package/src/shared/mcp/constants/tool-retrieve.constant.ts +31 -0
  299. package/src/shared/mcp/constants/tool-search.constant.ts +51 -0
  300. package/src/shared/mcp/constants/tool-skill-delete.constant.ts +24 -0
  301. package/src/shared/mcp/constants/tool-skill-get.constant.ts +27 -0
  302. package/src/shared/mcp/constants/tool-skill-learn.constant.ts +37 -0
  303. package/src/shared/mcp/constants/tool-skill-list.constant.ts +18 -0
  304. package/src/shared/mcp/constants/tool-status.constant.ts +20 -0
  305. package/src/shared/mcp/constants/tool-unlearn.constant.ts +25 -0
  306. package/src/shared/mcp/functions/as-boolean-or-undefined.function.ts +11 -0
  307. package/src/shared/mcp/functions/as-string-array-or-undefined.function.ts +17 -0
  308. package/src/shared/mcp/functions/as-string-array.function.ts +15 -0
  309. package/src/shared/mcp/functions/as-string.function.ts +10 -0
  310. package/src/shared/mcp/functions/build-skills-text.function.ts +43 -0
  311. package/src/shared/mcp/functions/create-tool-definitions.function.ts +28 -0
  312. package/src/shared/mcp/functions/handle-agent-create.function.ts +1 -1
  313. package/src/shared/mcp/functions/handle-agent-prompt.function.ts +68 -0
  314. package/src/shared/mcp/functions/handle-mcp-request.function.ts +202 -0
  315. package/src/shared/mcp/functions/handle-prompt-get.function.ts +18 -12
  316. package/src/shared/mcp/functions/handle-skill-prompt.function.ts +44 -0
  317. package/src/shared/mcp/functions/handle-tool-auto-capture-review.function.ts +24 -0
  318. package/src/shared/mcp/functions/handle-tool-call.function.ts +18 -0
  319. package/src/shared/mcp/functions/handle-tool-check.function.ts +21 -0
  320. package/src/shared/mcp/functions/handle-tool-content.function.ts +23 -0
  321. package/src/shared/mcp/functions/handle-tool-export.function.ts +25 -0
  322. package/src/shared/mcp/functions/handle-tool-gc.function.ts +21 -0
  323. package/src/shared/mcp/functions/handle-tool-learn.function.ts +69 -0
  324. package/src/shared/mcp/functions/handle-tool-rebuild.function.ts +21 -0
  325. package/src/shared/mcp/functions/handle-tool-retrieve.function.ts +40 -0
  326. package/src/shared/mcp/functions/handle-tool-search.function.ts +47 -0
  327. package/src/shared/mcp/functions/handle-tool-skill-delete.function.ts +34 -0
  328. package/src/shared/mcp/functions/handle-tool-skill-get.function.ts +59 -0
  329. package/src/shared/mcp/functions/handle-tool-skill-learn.function.ts +61 -0
  330. package/src/shared/mcp/functions/handle-tool-skill-list.function.ts +39 -0
  331. package/src/shared/mcp/functions/handle-tool-status.function.ts +21 -0
  332. package/src/shared/mcp/functions/handle-tool-unlearn.function.ts +24 -0
  333. package/src/shared/mcp/functions/parse-agent-meta.function.ts +27 -0
  334. package/src/shared/mcp/functions/parse-skill-arguments.function.ts +36 -0
  335. package/src/shared/mcp/functions/read-agent-meta.function.ts +41 -0
  336. package/src/shared/mcp/functions/resolve-skill-refs.function.ts +50 -0
  337. package/src/shared/mcp/functions/run-startup-health-check.function.ts +34 -0
  338. package/src/shared/mcp/typings/mcp-capabilities.interface.ts +16 -0
  339. package/src/shared/mcp/typings/mcp-client.interface.ts +2 -0
  340. package/src/shared/mcp/typings/mcp-completion.interface.ts +45 -0
  341. package/src/shared/mcp/typings/mcp-content-result.model.ts +9 -0
  342. package/src/shared/mcp/typings/mcp-export-result.model.ts +11 -0
  343. package/src/shared/mcp/typings/mcp-gc-result.model.ts +15 -0
  344. package/src/shared/mcp/typings/mcp-integrity-check-result.model.ts +17 -0
  345. package/src/shared/mcp/typings/mcp-integrity-error.model.ts +15 -0
  346. package/src/shared/mcp/typings/mcp-notification.interface.ts +9 -0
  347. package/src/shared/mcp/typings/mcp-rebuild-result.model.ts +9 -0
  348. package/src/shared/mcp/typings/mcp-request.interface.ts +11 -0
  349. package/src/shared/mcp/typings/mcp-resource-result.interface.ts +12 -0
  350. package/src/shared/mcp/typings/mcp-resource-template.interface.ts +11 -0
  351. package/src/shared/mcp/typings/mcp-response.interface.ts +18 -0
  352. package/src/shared/mcp/typings/mcp-server-info.interface.ts +7 -0
  353. package/src/shared/mcp/typings/mcp-server-state.interface.ts +17 -0
  354. package/src/shared/mcp/typings/mcp-tool-annotations.interface.ts +32 -0
  355. package/src/shared/mcp/typings/mcp-tool-definition.interface.ts +16 -0
  356. package/src/shared/mcp/typings/mcp-tool-result.interface.ts +19 -0
  357. package/src/shared/mcp/typings/mcp-worker-client.interface.ts +243 -0
  358. package/src/shared/mcp/typings/tool-call-result.model.ts +18 -0
  359. package/src/shared/sync/functions/build-import-report.function.ts +40 -0
  360. package/src/shared/sync/functions/parse-export-entry.function.ts +45 -0
  361. package/src/shared/sync/functions/resolve-conflict.function.ts +31 -0
  362. package/src/shared/sync/functions/serialize-export-entry.function.ts +18 -0
  363. package/src/shared/sync/index.ts +9 -0
  364. package/src/shared/sync/typings/conflict-resolution.type.ts +8 -0
  365. package/src/shared/sync/typings/export-entry.interface.ts +13 -0
  366. package/src/shared/sync/typings/export-options.interface.ts +9 -0
  367. package/src/shared/sync/typings/import-options.interface.ts +7 -0
  368. package/src/shared/sync/typings/import-report.interface.ts +15 -0
  369. package/src/shared/wasm-codec/functions/decode-one-recall-result.function.ts +86 -0
  370. package/src/shared/wasm-codec/functions/decode-option-string.function.ts +24 -0
  371. package/src/shared/wasm-codec/functions/decode-recall-document.function.ts +59 -0
  372. package/src/shared/wasm-codec/functions/decode-recall-reference.function.ts +52 -0
  373. package/src/shared/wasm-codec/functions/decode-recall-sibling.function.ts +43 -0
  374. package/src/shared/wasm-codec/functions/decode-section-match.function.ts +80 -0
  375. package/src/shared/wasm-codec/functions/decode-section-record-trailing.function.ts +75 -0
  376. package/src/shared/wasm-codec/functions/decode-section-record.function.ts +85 -0
  377. package/src/shared/wasm-codec/functions/decode-section-type.function.ts +30 -0
  378. package/src/shared/wasm-codec/functions/decode-wasm-list.function.ts +31 -0
  379. package/src/shared/wasm-codec/typings/add-section-input.model.ts +45 -0
  380. package/src/shared/wasm-codec/typings/add-section-result.model.ts +28 -0
  381. package/src/shared/wasm-codec/typings/document-manifest.model.ts +20 -0
  382. package/src/shared/wasm-codec/typings/document-section.model.ts +12 -0
  383. package/src/shared/wasm-codec/typings/item-decoder.type.ts +10 -0
  384. package/src/shared/wasm-codec/typings/near-duplicate.model.ts +16 -0
  385. package/src/shared/wasm-codec/typings/paged-search-result.model.ts +22 -0
  386. package/src/shared/wasm-codec/typings/section-match.model.ts +31 -0
  387. package/src/shared/wasm-codec/typings/section-record-trailing.model.ts +38 -0
  388. package/src/shared/wasm-codec/typings/section-record.model.ts +66 -0
  389. package/src/shared/wasm-codec/typings/section-type-result.model.ts +12 -0
  390. package/src/shared/worker-client/functions/handle-ipc-data.function.ts +49 -0
  391. package/src/shared/worker-client/functions/send-ipc-request.function.ts +39 -0
  392. package/src/shared/worker-client/typings/add-section-result.model.ts +2 -0
  393. package/src/shared/worker-client/typings/json-rpc-response.interface.ts +17 -0
  394. package/src/shared/worker-client/typings/pending-call.interface.ts +7 -0
  395. package/src/shared/worker-client/typings/recall-document.model.ts +16 -0
  396. package/src/shared/worker-client/typings/recall-params.model.ts +15 -0
  397. package/src/shared/worker-client/typings/recall-reference.model.ts +32 -0
  398. package/src/shared/worker-client/typings/recall-sibling.model.ts +11 -0
  399. package/src/shared/worker-client/typings/recall-single-result.model.ts +41 -0
  400. package/src/shared/worker-daemon/classes/ipc-error.class.ts +22 -0
  401. package/src/shared/worker-daemon/constants/wasm-method-map.constant.ts +69 -0
  402. package/src/shared/worker-daemon/functions/build-ipc-error-response.function.ts +16 -0
  403. package/src/shared/worker-daemon/functions/check-catalog-version.function.ts +54 -0
  404. package/src/shared/worker-daemon/functions/check-preconditions.function.ts +28 -0
  405. package/src/shared/worker-daemon/functions/detect-stale-pid.function.ts +33 -0
  406. package/src/shared/worker-daemon/functions/dispatch-request.function.ts +190 -0
  407. package/src/shared/worker-daemon/functions/handle-check-version.function.ts +74 -0
  408. package/src/shared/worker-daemon/functions/handle-config-method.function.ts +27 -0
  409. package/src/shared/worker-daemon/functions/handle-read-ops.function.ts +236 -0
  410. package/src/shared/worker-daemon/functions/handle-write-ops.function.ts +257 -0
  411. package/src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts +51 -0
  412. package/src/shared/worker-daemon/functions/parse-catalog-version.function.ts +20 -0
  413. package/src/shared/worker-daemon/functions/parse-embedding-section.function.ts +38 -0
  414. package/src/shared/worker-daemon/functions/parse-worker-toml.function.ts +104 -0
  415. package/src/shared/worker-daemon/functions/run-startup-integrity-check.function.ts +55 -0
  416. package/src/shared/worker-daemon/functions/scan-near-duplicates.function.ts +92 -0
  417. package/src/shared/worker-daemon/functions/wasm-bridge.function.ts +144 -0
  418. package/src/shared/worker-daemon/functions/wasm-memory-helpers.function.ts +41 -0
  419. package/src/shared/worker-daemon/functions/write-lock.function.ts +49 -0
  420. package/src/shared/worker-daemon/typings/allocator-ref.interface.ts +16 -0
  421. package/src/shared/worker-daemon/typings/daemon-config.interface.ts +7 -0
  422. package/src/shared/worker-daemon/typings/fs-adapter.interface.ts +22 -0
  423. package/src/shared/worker-daemon/typings/handler-context.interface.ts +19 -0
  424. package/src/shared/worker-daemon/typings/memory-ref.interface.ts +13 -0
  425. package/src/shared/worker-daemon/typings/wasm-fn.type.ts +2 -0
  426. package/src/shared/worker-daemon/typings/write-lock.interface.ts +13 -0
  427. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  428. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
package/README.md CHANGED
@@ -6,56 +6,47 @@ required.
6
6
  [GitLab](https://gitlab.com/tech-slaves/knowledge-base-db)
7
7
  | [NPM](https://www.npmjs.com/package/@dikolab/kbdb)
8
8
  | [JSR](https://jsr.io/@dikolab/kbdb)
9
- | [License: ISC](https://gitlab.com/tech-slaves/knowledge-base-db/-/blob/main/LICENSE)
9
+ | [License: ISC](LICENSE)
10
10
 
11
11
  ---
12
12
 
13
13
  ## What is kbdb?
14
14
 
15
- Storing and searching documentation shouldn't
16
- require setting up a database server, tuning
17
- indexes, or managing infrastructure.
18
-
19
- **kbdb** is a knowledge base that stores your docs
20
- in a plain folder on disk. No server to install.
21
- No cloud account to create. It handles indexing
22
- and fast search out of the box -- just point it
23
- at your files and start searching.
24
-
25
- It runs anywhere Node.js or Deno runs. Import your
26
- Markdown files, and kbdb indexes them automatically.
15
+ **kbdb** stores your docs in a plain folder on
16
+ disk and makes them searchable. No server to
17
+ install. No cloud account. Import your Markdown
18
+ files, and kbdb indexes them automatically.
27
19
  Search returns ranked results instantly.
28
20
 
29
- kbdb uses **lexical search** (keyword matching with
30
- stemming and synonym expansion), not semantic
31
- embeddings. This is a deliberate tradeoff: fast,
32
- offline, deterministic, and zero embedding cost.
33
- When AI agents are the primary consumers, lexical
34
- search works well -- agents can issue multiple
35
- keyword queries, use boolean/phrase syntax, and
36
- expand vocabulary themselves. When an exact-match
37
- query returns nothing, kbdb automatically retries
38
- with relaxed OR matching so you always get the
39
- best available results. Write clear headings
40
- (they carry 2x ranking weight) and use specific
41
- terms for best recall.
42
-
43
- kbdb tracks **knowledge freshness** automatically.
44
- Re-learn a file and supersession replaces the old
45
- version instead of duplicating it. Near-duplicate
46
- detection warns you before content drifts.
47
- Integrity checks catch contradictions between
48
- versions of the same source. Confidence scores
49
- let agents tell strong matches from weak tail
50
- results.
51
-
52
- As a bonus, kbdb also works as an MCP server --
53
- giving AI agents like Claude a searchable second
54
- brain. Store skills, agent profiles, and
55
- documentation that your AI can query across
56
- sessions. Default skills (`query-guidance` and
57
- `memory-protocol`) teach agents how to search
58
- effectively and what to store.
21
+ It runs anywhere Node.js or Deno runs, and also
22
+ works as an [MCP](https://modelcontextprotocol.io/)
23
+ server -- giving AI agents like Claude a searchable
24
+ second brain that persists between sessions.
25
+
26
+ **How search works:** kbdb searches by keywords --
27
+ it matches your query against indexed terms, expands
28
+ synonyms, and ranks results by relevance. This is
29
+ the default **lexical** mode: fast, works offline,
30
+ and gives consistent results every time.
31
+
32
+ When an exact query finds nothing, kbdb automatically
33
+ loosens the match so you still get the best available
34
+ results. Headings count for more in ranking, so
35
+ writing clear headings helps.
36
+
37
+ Want smarter matching? kbdb supports **hybrid search**
38
+ (`--algo hybrid`) that blends keyword matching with
39
+ AI-powered similarity. This catches results that use
40
+ different words for the same concept. Hybrid mode
41
+ needs an embedding provider -- without one, kbdb
42
+ sticks to keyword search.
43
+
44
+ **Knowledge stays fresh:** Re-learn a file and kbdb
45
+ replaces the old version automatically.
46
+ Near-duplicate detection warns you before content
47
+ drifts. Integrity checks catch contradictions.
48
+ Confidence scores help agents tell strong matches
49
+ from weak ones.
59
50
 
60
51
  ---
61
52
 
@@ -106,7 +97,7 @@ kbdb learn ./docs --db ./my-kb
106
97
  Point it at a folder of Markdown files. kbdb reads
107
98
  them, breaks them into sections, and builds a
108
99
  search index. Add `--tags design,v2` to tag
109
- sections for scoping, or `--replace` to supersede
100
+ sections for scoping, or `--replace` to update
110
101
  existing sections from the same source.
111
102
 
112
103
  **3. Search**
@@ -115,11 +106,16 @@ existing sections from the same source.
115
106
  kbdb search "how does auth work" --db ./my-kb
116
107
  ```
117
108
 
118
- Results are ranked by relevance with confidence
119
- scores and snippets showing matched terms in
120
- context. Each result includes `matched_fields`
121
- (heading, body, code) and `created_at` timestamps.
122
- Use `--offset` to page through large result sets.
109
+ Results are ranked by relevance with snippets
110
+ showing where your terms matched. Use `--offset`
111
+ to page through large result sets.
112
+
113
+ To try hybrid search (keyword + AI similarity):
114
+
115
+ ```sh
116
+ kbdb search "how does auth work" --algo hybrid \
117
+ --db ./my-kb
118
+ ```
123
119
 
124
120
  **4. Recall context**
125
121
 
@@ -140,25 +136,28 @@ referenced sections.
140
136
 
141
137
  - **Import** Markdown files and other documents,
142
138
  with tags and source tracking
143
- - **Supersede** outdated sections automatically
144
- when re-learning from the same source
145
- - **Search** with ranked results, confidence
146
- scores, snippets, and paginated output
147
- - **Relaxed fallback** -- automatic OR retry when
148
- exact AND queries return nothing
139
+ - **Smart updates** -- re-learning a file replaces
140
+ the old version instead of duplicating it
141
+ - **Search** with three modes: keyword (default),
142
+ AI similarity, or hybrid (both combined)
143
+ - **Auto-fallback** -- if your exact query finds
144
+ nothing, kbdb loosens the match automatically
149
145
  - **Recall** sections with progressive context --
150
146
  from a quick summary to full related content
151
- - **Export** the database as a portable snapshot
147
+ - **Export and sync** -- snapshot your knowledge
148
+ base for backup or sharing across machines
152
149
  - **Skills** -- store reusable prompt templates
153
- with placeholder arguments
150
+ with fill-in-the-blank arguments
154
151
  - **Agents** -- create AI agent profiles that
155
152
  combine a persona with skills
156
- - **Manage** documents, sections, and metadata
157
- - **Verify** database integrity, detect
158
- contradictions, and clean up superseded data
153
+ - **Auto-capture** -- the MCP server can
154
+ proactively suggest knowledge to store from
155
+ your conversations
156
+ - **Verify** database integrity and clean up
157
+ stale data
159
158
  - **Rebuild** indexes if anything goes wrong
160
159
 
161
- See the [CLI Reference](https://gitlab.com/tech-slaves/knowledge-base-db/-/blob/main/docs/details/cli.md)
160
+ See the [CLI Reference](docs/details/cli.md)
162
161
  for the full command list and examples.
163
162
 
164
163
  ---
@@ -167,56 +166,22 @@ for the full command list and examples.
167
166
 
168
167
  kbdb runs as an
169
168
  [MCP](https://modelcontextprotocol.io/) server
170
- with 19 tools, so AI agents can search your docs,
169
+ with 20 tools, so AI agents can search your docs,
171
170
  recall context progressively, export snapshots,
172
171
  store reusable skills, and build agent profiles --
173
172
  a second brain that persists between sessions.
174
173
 
175
- ### Claude Code (CLI)
174
+ ### Setup
176
175
 
177
- Create `.mcp.json` in your project root:
176
+ Add kbdb to your AI tool's MCP config. The setup
177
+ is the same for Claude Code, VS Code, Cursor, and
178
+ Claude Desktop -- just put the config in the right
179
+ file for your tool.
178
180
 
179
- ```json
180
- {
181
- "mcpServers": {
182
- "kbdb": {
183
- "command": "npx",
184
- "args": [
185
- "-y",
186
- "@dikolab/kbdb",
187
- "mcp",
188
- "--db",
189
- "/path/to/.kbdb"
190
- ]
191
- }
192
- }
193
- }
194
- ```
195
-
196
- ### Claude for VS Code
197
-
198
- Create `.vscode/mcp.json` in your project:
199
-
200
- ```json
201
- {
202
- "servers": {
203
- "kbdb": {
204
- "command": "npx",
205
- "args": [
206
- "-y",
207
- "@dikolab/kbdb",
208
- "mcp",
209
- "--db",
210
- "${workspaceFolder}/.kbdb"
211
- ]
212
- }
213
- }
214
- }
215
- ```
216
-
217
- ### Claude Desktop
218
-
219
- Add to your `claude_desktop_config.json`:
181
+ **Claude Code** -- `.mcp.json` in your project root.
182
+ **VS Code / Cursor** -- `.vscode/mcp.json` in your
183
+ project. **Claude Desktop** --
184
+ `claude_desktop_config.json`.
220
185
 
221
186
  ```json
222
187
  {
@@ -235,13 +200,18 @@ Add to your `claude_desktop_config.json`:
235
200
  }
236
201
  ```
237
202
 
238
- ### Other AI Agents
203
+ For VS Code / Cursor, wrap in `{"servers": ...}`
204
+ instead of `{"mcpServers": ...}`. Use
205
+ `"${workspaceFolder}/.kbdb"` for the db path.
239
206
 
240
- Any MCP-compatible agent can connect. See the
241
- [MCP Server Guide](https://gitlab.com/tech-slaves/knowledge-base-db/-/blob/main/docs/details/mcp-server.md) for
242
- setup instructions, Deno variants, environment
243
- variable configuration, and the full list of
244
- available tools.
207
+ **Deno users:** replace `npx` / `-y` /
208
+ `@dikolab/kbdb` with `deno` / `run` / `-A` /
209
+ `jsr:@dikolab/kbdb/cli`.
210
+
211
+ See the
212
+ [MCP Server Guide](docs/details/mcp-server.md)
213
+ for Deno examples, environment variable config,
214
+ multiple knowledge bases, and the full tool list.
245
215
 
246
216
  ---
247
217
 
@@ -265,13 +235,12 @@ const results = await client.search({
265
235
  offset: 0,
266
236
  });
267
237
 
268
- // results = { items, total, offset, limit, has_more, relaxed }
269
238
  console.log(results.items);
270
239
  client.disconnect();
271
240
  ```
272
241
 
273
242
  See the
274
- [Library API Reference](https://gitlab.com/tech-slaves/knowledge-base-db/-/blob/main/docs/details/library-api.md)
243
+ [Library API Reference](docs/details/library-api.md)
275
244
  for the full API.
276
245
 
277
246
  ### Development Setup
@@ -292,7 +261,7 @@ A Docker setup is included with all build tools
292
261
  HOST_UMASK=$(umask) docker compose run --rm dev bash
293
262
  ```
294
263
 
295
- See the [Makefile](https://gitlab.com/tech-slaves/knowledge-base-db/-/blob/main/Makefile) for all available
264
+ See the [Makefile](Makefile) for all available
296
265
  build targets.
297
266
 
298
267
  ### Contributing
@@ -307,17 +276,17 @@ build targets.
307
276
 
308
277
  ## Documentation
309
278
 
310
- - [Detailed Guides](https://gitlab.com/tech-slaves/knowledge-base-db/-/tree/main/docs/details) -- CLI
311
- reference, MCP setup, search internals, storage
312
- format, library API
313
- - [Release Notes](https://gitlab.com/tech-slaves/knowledge-base-db/-/tree/main/docs/release-notes)
314
- - [Architecture Overview](https://gitlab.com/tech-slaves/knowledge-base-db/-/blob/main/docs/overview.md)
279
+ - [Detailed Guides](docs/details/) -- CLI reference,
280
+ MCP setup, search internals, storage format,
281
+ library API
282
+ - [Release Notes](docs/release-notes/)
283
+ - [Architecture Overview](docs/overview.md)
315
284
 
316
285
  ---
317
286
 
318
287
  ## License
319
288
 
320
- ISC License -- see [LICENSE](https://gitlab.com/tech-slaves/knowledge-base-db/-/blob/main/LICENSE) for details.
289
+ ISC License -- see [LICENSE](LICENSE) for details.
321
290
 
322
291
  ---
323
292
 
@@ -0,0 +1,3 @@
1
+ import type { CorpusConfig } from '../typings/corpus-config.interface.ts';
2
+ /** Default corpus generation settings. */
3
+ export declare const CORPUS_DEFAULTS: CorpusConfig;
@@ -0,0 +1,11 @@
1
+ import type { BenchSuiteResult } from '../typings/bench-suite-result.interface.ts';
2
+ /**
3
+ * Formats benchmark results as a Markdown table.
4
+ *
5
+ * Renders a header row, a separator, and one data row per
6
+ * result in the suite.
7
+ *
8
+ * @param suite - completed benchmark suite to render
9
+ * @returns multi-line Markdown table string
10
+ */
11
+ export declare function formatReport(suite: BenchSuiteResult): string;
@@ -0,0 +1,12 @@
1
+ import type { CorpusConfig } from '../typings/corpus-config.interface.ts';
2
+ import type { CorpusSection } from '../typings/corpus-section.interface.ts';
3
+ /**
4
+ * Generates a synthetic corpus of sections.
5
+ *
6
+ * Uses Zipfian word frequency distribution for realistic
7
+ * token patterns. Output is deterministic for the same seed.
8
+ *
9
+ * @param config - corpus generation parameters
10
+ * @returns array of generated corpus sections
11
+ */
12
+ export declare function generateCorpus(config: CorpusConfig): CorpusSection[];
@@ -0,0 +1,14 @@
1
+ import type { BenchResult } from '../typings/bench-result.interface.ts';
2
+ /**
3
+ * Measures the duration of an async operation.
4
+ *
5
+ * Runs one warmup call then measures N iterations, returning
6
+ * the median duration. Uses `performance.now()` for timing.
7
+ *
8
+ * @param name - label for the operation
9
+ * @param corpusSize - corpus size associated with this run
10
+ * @param operation - the function to benchmark
11
+ * @param iterations - number of measured iterations (default 3)
12
+ * @returns benchmark result with median timing
13
+ */
14
+ export declare function measureOperation(name: string, corpusSize: number, operation: () => Promise<void> | void, iterations?: number): Promise<BenchResult>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Creates a deterministic pseudo-random number generator
3
+ * using a linear congruential algorithm.
4
+ *
5
+ * Each call to the returned function advances the internal
6
+ * state and returns the next value in [0, 1).
7
+ *
8
+ * @param seed - initial state for the LCG sequence
9
+ * @returns a stateful RNG function producing values in [0, 1)
10
+ */
11
+ export declare function seededRng(seed: number): () => number;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Selects a word index using Zipfian distribution.
3
+ *
4
+ * Higher-ranked words (lower indices) appear more frequently,
5
+ * modeling natural language word frequencies. Uses inverse CDF
6
+ * approximation: `floor(vocabSize * (1 - rng()^(1/s)))` where
7
+ * s ≈ 1.07 maps uniform random values to rank-biased indices.
8
+ *
9
+ * @param rng - stateful random number generator in [0, 1)
10
+ * @param vocabSize - total vocabulary size (exclusive upper bound)
11
+ * @returns integer index in [0, vocabSize)
12
+ */
13
+ export declare function zipfWord(rng: () => number, vocabSize: number): number;
@@ -0,0 +1,10 @@
1
+ export type { CorpusConfig } from './typings/corpus-config.interface.ts';
2
+ export type { CorpusSection } from './typings/corpus-section.interface.ts';
3
+ export type { BenchResult } from './typings/bench-result.interface.ts';
4
+ export type { BenchSuiteResult } from './typings/bench-suite-result.interface.ts';
5
+ export { CORPUS_DEFAULTS } from './constants/corpus-defaults.constant.ts';
6
+ export { seededRng } from './functions/seeded-rng.function.ts';
7
+ export { zipfWord } from './functions/zipf-word.function.ts';
8
+ export { generateCorpus } from './functions/generate-corpus.function.ts';
9
+ export { measureOperation } from './functions/measure-operation.function.ts';
10
+ export { formatReport } from './functions/format-report.function.ts';
@@ -0,0 +1,11 @@
1
+ /** Result of a single benchmark run. */
2
+ export interface BenchResult {
3
+ /** Operation name. */
4
+ readonly operation: string;
5
+ /** Corpus size. */
6
+ readonly corpusSize: number;
7
+ /** Duration in milliseconds. */
8
+ readonly durationMs: number;
9
+ /** Operations per second. */
10
+ readonly opsPerSec: number;
11
+ }
@@ -0,0 +1,10 @@
1
+ import type { BenchResult } from './bench-result.interface.ts';
2
+ /** Results from a complete benchmark suite. */
3
+ export interface BenchSuiteResult {
4
+ /** Individual benchmark results. */
5
+ readonly results: BenchResult[];
6
+ /** Timestamp of the run. */
7
+ readonly timestamp: string;
8
+ /** System info. */
9
+ readonly system: string;
10
+ }
@@ -0,0 +1,11 @@
1
+ /** Configuration for synthetic corpus generation. */
2
+ export interface CorpusConfig {
3
+ /** Number of sections to generate. */
4
+ readonly count: number;
5
+ /** Seed for deterministic RNG. */
6
+ readonly seed: number;
7
+ /** Average tokens per section. */
8
+ readonly avgTokens: number;
9
+ /** Vocabulary size. */
10
+ readonly vocabSize: number;
11
+ }
@@ -0,0 +1,9 @@
1
+ /** A generated section for benchmarking. */
2
+ export interface CorpusSection {
3
+ /** Section heading. */
4
+ readonly heading: string;
5
+ /** Section body text. */
6
+ readonly body: string;
7
+ /** Source key for dedup. */
8
+ readonly sourceKey: string;
9
+ }
package/dist/cli.cjs CHANGED
@@ -125,6 +125,9 @@ function parseArgs(argv) {
125
125
  parseInt(argv[++i] ?? "", 10) || 0
126
126
  );
127
127
  break;
128
+ case "--algo":
129
+ options.algo = argv[++i];
130
+ break;
128
131
  case "--title":
129
132
  options.title = argv[++i];
130
133
  break;
@@ -254,7 +257,8 @@ async function runSearch(client, options) {
254
257
  query,
255
258
  mode: options.mode,
256
259
  limit: options.limit,
257
- offset: options.offset
260
+ offset: options.offset,
261
+ algo: options.algo
258
262
  });
259
263
  return {
260
264
  items: results.items.map((r) => ({
@@ -2447,6 +2451,11 @@ function createToolDefinitions() {
2447
2451
  offset: {
2448
2452
  type: "number",
2449
2453
  description: "Number of results to skip for pagination (default: 0)"
2454
+ },
2455
+ algo: {
2456
+ type: "string",
2457
+ enum: ["lexical", "vector", "hybrid"],
2458
+ description: "Search algorithm (default: lexical)"
2450
2459
  }
2451
2460
  },
2452
2461
  required: ["query"]
@@ -2860,6 +2869,27 @@ function createToolDefinitions() {
2860
2869
  idempotentHint: true,
2861
2870
  openWorldHint: false
2862
2871
  }
2872
+ },
2873
+ {
2874
+ name: "auto-capture-review",
2875
+ description: "Review and approve pending auto-captured knowledge before storage.",
2876
+ inputSchema: {
2877
+ type: "object",
2878
+ properties: {
2879
+ action: {
2880
+ type: "string",
2881
+ enum: ["list", "approve", "reject"],
2882
+ description: "Action to perform on pending captures"
2883
+ }
2884
+ }
2885
+ },
2886
+ annotations: {
2887
+ title: "Auto-Capture Review",
2888
+ readOnlyHint: false,
2889
+ destructiveHint: false,
2890
+ idempotentHint: true,
2891
+ openWorldHint: false
2892
+ }
2863
2893
  }
2864
2894
  ];
2865
2895
  }
@@ -2933,7 +2963,7 @@ async function handleAgentCreate(client, args) {
2933
2963
  description
2934
2964
  });
2935
2965
  const allKbids = [metaResult.kbid, ...skills];
2936
- const docid = await client.groupSections(name, allKbids);
2966
+ const docid = await client.groupSections(name, allKbids, "agent");
2937
2967
  return {
2938
2968
  content: [
2939
2969
  {
@@ -3146,6 +3176,8 @@ async function handleToolCall(client, name, args) {
3146
3176
  return await handleAgentGet(client, args);
3147
3177
  case "agent-delete":
3148
3178
  return await handleAgentDelete(client, args);
3179
+ case "auto-capture-review":
3180
+ return handleAutoCaptureReview();
3149
3181
  default:
3150
3182
  return {
3151
3183
  content: [
@@ -3174,7 +3206,8 @@ async function handleSearch2(client, args) {
3174
3206
  query: asString2(args["query"], ""),
3175
3207
  mode: args["mode"],
3176
3208
  limit: args["limit"],
3177
- offset: args["offset"]
3209
+ offset: args["offset"],
3210
+ algo: args["algo"]
3178
3211
  });
3179
3212
  const stripped = {
3180
3213
  ...results,
@@ -3230,7 +3263,8 @@ async function handleLearn2(client, args) {
3230
3263
  warnings: result.warnings ?? [],
3231
3264
  near_duplicates: (result.near_duplicates ?? []).map((d) => ({
3232
3265
  kbid: d.kbid,
3233
- similarity: d.similarity
3266
+ similarity: d.similarity,
3267
+ ...d.method !== void 0 ? { method: d.method } : {}
3234
3268
  }))
3235
3269
  };
3236
3270
  return {
@@ -3478,6 +3512,19 @@ async function handleSkillDelete(client, args) {
3478
3512
  ]
3479
3513
  };
3480
3514
  }
3515
+ function handleAutoCaptureReview() {
3516
+ return {
3517
+ content: [
3518
+ {
3519
+ type: "text",
3520
+ text: JSON.stringify({
3521
+ pending: [],
3522
+ message: "No pending auto-captured knowledge entries."
3523
+ })
3524
+ }
3525
+ ]
3526
+ };
3527
+ }
3481
3528
  async function handleExport2(client, args) {
3482
3529
  const path = typeof args["path"] === "string" ? args["path"] : void 0;
3483
3530
  const result = await client.export(
@@ -3588,8 +3635,12 @@ function buildSkillsText(skillSections) {
3588
3635
  ${lines.join("\n")}`;
3589
3636
  }
3590
3637
  async function handleAgentPrompt(name, client) {
3591
- const docid = name.slice(6);
3592
- const doc = await client.retrieveDocument(docid);
3638
+ const agentName = name.slice(6);
3639
+ const agents = await client.listDocumentsByType("agent");
3640
+ const doc = agents.find((a) => a.title === agentName);
3641
+ if (!doc) {
3642
+ throw new Error("agent not found: " + agentName);
3643
+ }
3593
3644
  const sections = doc.sections;
3594
3645
  const metaSection = sections.at(0);
3595
3646
  const skillRefs = sections.slice(1);
@@ -3747,13 +3798,16 @@ var McpServer = class {
3747
3798
  input: process.stdin,
3748
3799
  terminal: false
3749
3800
  });
3801
+ let pending = Promise.resolve();
3750
3802
  await new Promise((resolve4) => {
3751
3803
  rl.on("line", (line) => {
3752
- void this.dispatchLine(line);
3804
+ pending = pending.then(() => this.dispatchLine(line));
3753
3805
  });
3754
3806
  rl.on("close", () => {
3755
- this.client.disconnect();
3756
- resolve4();
3807
+ void pending.then(() => {
3808
+ this.client.disconnect();
3809
+ resolve4();
3810
+ });
3757
3811
  });
3758
3812
  });
3759
3813
  }