@dikolab/kbdb 0.2.2 → 0.3.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 (520) hide show
  1. package/README.md +47 -31
  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 +523 -80
  14. package/dist/cli.cjs.map +4 -4
  15. package/dist/cli.mjs +515 -72
  16. package/dist/cli.mjs.map +4 -4
  17. package/dist/kbdb-worker.cjs +395 -60
  18. package/dist/kbdb-worker.cjs.map +4 -4
  19. package/dist/mod.cjs +17 -0
  20. package/dist/mod.cjs.map +2 -2
  21. package/dist/mod.mjs +17 -0
  22. package/dist/mod.mjs.map +2 -2
  23. package/dist/src/shared/auto-capture/classes/auto-capture-controller.class.d.ts +33 -0
  24. package/dist/src/shared/auto-capture/constants/auto-capture-defaults.constant.d.ts +8 -0
  25. package/dist/src/shared/auto-capture/functions/build-capture-prompt.function.d.ts +11 -0
  26. package/dist/src/shared/auto-capture/functions/evaluate-trigger.function.d.ts +12 -0
  27. package/dist/src/shared/auto-capture/index.d.ts +7 -0
  28. package/dist/src/shared/auto-capture/typings/auto-capture-config.interface.d.ts +13 -0
  29. package/dist/src/shared/auto-capture/typings/auto-capture-state.interface.d.ts +13 -0
  30. package/dist/src/shared/auto-capture/typings/auto-capture-trigger.interface.d.ts +7 -0
  31. package/dist/src/shared/cli/constants/global-help.constant.d.ts +8 -0
  32. package/dist/src/shared/cli/constants/leaf-help.constant.d.ts +7 -0
  33. package/dist/src/shared/cli/constants/memory-protocol-body.constant.d.ts +7 -0
  34. package/dist/src/shared/cli/constants/query-guidance-body.constant.d.ts +7 -0
  35. package/dist/src/shared/cli/constants/subcommand-help.constant.d.ts +8 -0
  36. package/dist/src/shared/cli/functions/collect-files.function.d.ts +13 -0
  37. package/dist/src/shared/cli/functions/compute-section-kbid.function.d.ts +15 -0
  38. package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +3 -1
  39. package/dist/src/shared/cli/functions/format-mcp-output.function.d.ts +9 -0
  40. package/dist/src/shared/cli/functions/format-text-output.function.d.ts +9 -0
  41. package/dist/src/shared/cli/functions/generate-group-help.function.d.ts +11 -0
  42. package/dist/src/shared/cli/functions/handle-data-command.function.d.ts +16 -0
  43. package/dist/src/shared/cli/functions/handle-mcp.function.d.ts +15 -0
  44. package/dist/src/shared/cli/functions/handle-migrate.function.d.ts +15 -0
  45. package/dist/src/shared/cli/functions/hydrate-search-previews.function.d.ts +14 -0
  46. package/dist/src/shared/cli/functions/install-default-skills.function.d.ts +12 -0
  47. package/dist/src/shared/cli/functions/resolve-skill-names.function.d.ts +16 -0
  48. package/dist/src/shared/cli/functions/run-check.function.d.ts +47 -5
  49. package/dist/src/shared/cli/functions/run-export.function.d.ts +34 -0
  50. package/dist/src/shared/cli/functions/run-gc.function.d.ts +6 -0
  51. package/dist/src/shared/cli/functions/run-learn.function.d.ts +35 -6
  52. package/dist/src/shared/cli/functions/run-recall.function.d.ts +45 -0
  53. package/dist/src/shared/cli/functions/run-search.function.d.ts +53 -15
  54. package/dist/src/shared/cli/functions/version-gate.function.d.ts +15 -0
  55. package/dist/src/shared/cli/functions/wrap-command.function.d.ts +15 -0
  56. package/dist/src/shared/cli/index.d.ts +4 -0
  57. package/dist/src/shared/cli/typings/agent-create-client.interface.d.ts +42 -0
  58. package/dist/src/shared/cli/typings/agent-get-client.interface.d.ts +36 -0
  59. package/dist/src/shared/cli/typings/check-client.interface.d.ts +58 -0
  60. package/dist/src/shared/cli/typings/cli-deps.interface.d.ts +48 -0
  61. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +15 -0
  62. package/dist/src/shared/cli/typings/disconnectable-client.interface.d.ts +26 -0
  63. package/dist/src/shared/cli/typings/dispatch-client.type.d.ts +27 -0
  64. package/dist/src/shared/cli/typings/learn-client.interface.d.ts +52 -0
  65. package/dist/src/shared/cli/typings/learn-io.interface.d.ts +5 -0
  66. package/dist/src/shared/cli/typings/learn-result.model.d.ts +19 -0
  67. package/dist/src/shared/cli/typings/search-client.interface.d.ts +71 -0
  68. package/dist/src/shared/cli/typings/search-display.model.d.ts +18 -0
  69. package/dist/src/shared/embedding/classes/null-embedding-provider.class.d.ts +20 -0
  70. package/dist/src/shared/embedding/constants/near-duplicate-thresholds.constant.d.ts +15 -0
  71. package/dist/src/shared/embedding/functions/build-vector-index.function.d.ts +14 -0
  72. package/dist/src/shared/embedding/functions/cosine-similarity.function.d.ts +10 -0
  73. package/dist/src/shared/embedding/functions/detect-near-duplicates.function.d.ts +18 -0
  74. package/dist/src/shared/embedding/functions/jaccard-coefficient.function.d.ts +9 -0
  75. package/dist/src/shared/embedding/functions/read-vector-index-meta.function.d.ts +10 -0
  76. package/dist/src/shared/embedding/functions/rrf-fuse.function.d.ts +14 -0
  77. package/dist/src/shared/embedding/functions/search-vectors.function.d.ts +14 -0
  78. package/dist/src/shared/embedding/index.d.ts +16 -0
  79. package/dist/src/shared/embedding/typings/embedding-config.interface.d.ts +20 -0
  80. package/dist/src/shared/embedding/typings/embedding-provider.interface.d.ts +23 -0
  81. package/dist/src/shared/embedding/typings/near-duplicate-candidate.model.d.ts +23 -0
  82. package/dist/src/shared/embedding/typings/near-duplicate-result.model.d.ts +24 -0
  83. package/dist/src/shared/embedding/typings/vector-index-entry.model.d.ts +12 -0
  84. package/dist/src/shared/embedding/typings/vector-index-meta.model.d.ts +11 -0
  85. package/dist/src/shared/embedding/typings/vector-search-result.model.d.ts +7 -0
  86. package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +8 -0
  87. package/dist/src/shared/mcp/constants/tool-agent-create.constant.d.ts +3 -0
  88. package/dist/src/shared/mcp/constants/tool-agent-delete.constant.d.ts +3 -0
  89. package/dist/src/shared/mcp/constants/tool-agent-get.constant.d.ts +3 -0
  90. package/dist/src/shared/mcp/constants/tool-agent-list.constant.d.ts +3 -0
  91. package/dist/src/shared/mcp/constants/tool-auto-capture-review.constant.d.ts +8 -0
  92. package/dist/src/shared/mcp/constants/tool-check.constant.d.ts +3 -0
  93. package/dist/src/shared/mcp/constants/tool-content.constant.d.ts +3 -0
  94. package/dist/src/shared/mcp/constants/tool-export.constant.d.ts +3 -0
  95. package/dist/src/shared/mcp/constants/tool-gc.constant.d.ts +3 -0
  96. package/dist/src/shared/mcp/constants/tool-learn.constant.d.ts +3 -0
  97. package/dist/src/shared/mcp/constants/tool-rebuild.constant.d.ts +3 -0
  98. package/dist/src/shared/mcp/constants/tool-recall.constant.d.ts +3 -0
  99. package/dist/src/shared/mcp/constants/tool-retrieve.constant.d.ts +3 -0
  100. package/dist/src/shared/mcp/constants/tool-search.constant.d.ts +3 -0
  101. package/dist/src/shared/mcp/constants/tool-skill-delete.constant.d.ts +3 -0
  102. package/dist/src/shared/mcp/constants/tool-skill-get.constant.d.ts +3 -0
  103. package/dist/src/shared/mcp/constants/tool-skill-learn.constant.d.ts +3 -0
  104. package/dist/src/shared/mcp/constants/tool-skill-list.constant.d.ts +3 -0
  105. package/dist/src/shared/mcp/constants/tool-status.constant.d.ts +3 -0
  106. package/dist/src/shared/mcp/constants/tool-unlearn.constant.d.ts +3 -0
  107. package/dist/src/shared/mcp/functions/as-boolean-or-undefined.function.d.ts +7 -0
  108. package/dist/src/shared/mcp/functions/as-string-array-or-undefined.function.d.ts +7 -0
  109. package/dist/src/shared/mcp/functions/as-string-array.function.d.ts +7 -0
  110. package/dist/src/shared/mcp/functions/as-string.function.d.ts +8 -0
  111. package/dist/src/shared/mcp/functions/build-skills-text.function.d.ts +18 -0
  112. package/dist/src/shared/mcp/functions/handle-agent-prompt.function.d.ts +14 -0
  113. package/dist/src/shared/mcp/functions/handle-mcp-request.function.d.ts +14 -0
  114. package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +4 -3
  115. package/dist/src/shared/mcp/functions/handle-skill-prompt.function.d.ts +16 -0
  116. package/dist/src/shared/mcp/functions/handle-tool-auto-capture-review.function.d.ts +12 -0
  117. package/dist/src/shared/mcp/functions/handle-tool-check.function.d.ts +11 -0
  118. package/dist/src/shared/mcp/functions/handle-tool-content.function.d.ts +12 -0
  119. package/dist/src/shared/mcp/functions/handle-tool-export.function.d.ts +12 -0
  120. package/dist/src/shared/mcp/functions/handle-tool-gc.function.d.ts +11 -0
  121. package/dist/src/shared/mcp/functions/handle-tool-learn.function.d.ts +12 -0
  122. package/dist/src/shared/mcp/functions/handle-tool-rebuild.function.d.ts +11 -0
  123. package/dist/src/shared/mcp/functions/handle-tool-retrieve.function.d.ts +12 -0
  124. package/dist/src/shared/mcp/functions/handle-tool-search.function.d.ts +13 -0
  125. package/dist/src/shared/mcp/functions/handle-tool-skill-delete.function.d.ts +12 -0
  126. package/dist/src/shared/mcp/functions/handle-tool-skill-get.function.d.ts +13 -0
  127. package/dist/src/shared/mcp/functions/handle-tool-skill-learn.function.d.ts +13 -0
  128. package/dist/src/shared/mcp/functions/handle-tool-skill-list.function.d.ts +11 -0
  129. package/dist/src/shared/mcp/functions/handle-tool-status.function.d.ts +11 -0
  130. package/dist/src/shared/mcp/functions/handle-tool-unlearn.function.d.ts +12 -0
  131. package/dist/src/shared/mcp/functions/parse-agent-meta.function.d.ts +14 -0
  132. package/dist/src/shared/mcp/functions/parse-skill-arguments.function.d.ts +11 -0
  133. package/dist/src/shared/mcp/functions/read-agent-meta.function.d.ts +17 -0
  134. package/dist/src/shared/mcp/functions/resolve-skill-refs.function.d.ts +23 -0
  135. package/dist/src/shared/mcp/functions/run-startup-health-check.function.d.ts +14 -0
  136. package/dist/src/shared/mcp/typings/mcp-capabilities.interface.d.ts +16 -0
  137. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +45 -0
  138. package/dist/src/shared/mcp/typings/mcp-completion.interface.d.ts +43 -0
  139. package/dist/src/shared/mcp/typings/mcp-content-result.model.d.ts +9 -0
  140. package/dist/src/shared/mcp/typings/mcp-export-result.model.d.ts +11 -0
  141. package/dist/src/shared/mcp/typings/mcp-gc-result.model.d.ts +15 -0
  142. package/dist/src/shared/mcp/typings/mcp-integrity-check-result.model.d.ts +16 -0
  143. package/dist/src/shared/mcp/typings/mcp-integrity-error.model.d.ts +9 -0
  144. package/dist/src/shared/mcp/typings/mcp-notification.interface.d.ts +9 -0
  145. package/dist/src/shared/mcp/typings/mcp-rebuild-result.model.d.ts +9 -0
  146. package/dist/src/shared/mcp/typings/mcp-request.interface.d.ts +11 -0
  147. package/dist/src/shared/mcp/typings/mcp-resource-result.interface.d.ts +12 -0
  148. package/dist/src/shared/mcp/typings/mcp-resource-template.interface.d.ts +11 -0
  149. package/dist/src/shared/mcp/typings/mcp-response.interface.d.ts +18 -0
  150. package/dist/src/shared/mcp/typings/mcp-server-info.interface.d.ts +7 -0
  151. package/dist/src/shared/mcp/typings/mcp-server-state.interface.d.ts +16 -0
  152. package/dist/src/shared/mcp/typings/mcp-tool-annotations.interface.d.ts +32 -0
  153. package/dist/src/shared/mcp/typings/mcp-tool-definition.interface.d.ts +15 -0
  154. package/dist/src/shared/mcp/typings/mcp-tool-result.interface.d.ts +19 -0
  155. package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +220 -0
  156. package/dist/src/shared/mcp/typings/tool-call-result.model.d.ts +17 -0
  157. package/dist/src/shared/sync/functions/build-import-report.function.d.ts +18 -0
  158. package/dist/src/shared/sync/functions/parse-export-entry.function.d.ts +11 -0
  159. package/dist/src/shared/sync/functions/resolve-conflict.function.d.ts +13 -0
  160. package/dist/src/shared/sync/functions/serialize-export-entry.function.d.ts +8 -0
  161. package/dist/src/shared/sync/index.d.ts +9 -0
  162. package/dist/src/shared/sync/typings/conflict-resolution.type.d.ts +8 -0
  163. package/dist/src/shared/sync/typings/export-entry.interface.d.ts +13 -0
  164. package/dist/src/shared/sync/typings/export-options.interface.d.ts +9 -0
  165. package/dist/src/shared/sync/typings/import-options.interface.d.ts +7 -0
  166. package/dist/src/shared/sync/typings/import-report.interface.d.ts +15 -0
  167. package/dist/src/shared/wasm-codec/functions/decode-add-section-result.function.d.ts +48 -0
  168. package/dist/src/shared/wasm-codec/functions/decode-one-recall-result.function.d.ts +14 -0
  169. package/dist/src/shared/wasm-codec/functions/decode-option-string.function.d.ts +12 -0
  170. package/dist/src/shared/wasm-codec/functions/decode-recall-document.function.d.ts +14 -0
  171. package/dist/src/shared/wasm-codec/functions/decode-recall-reference.function.d.ts +14 -0
  172. package/dist/src/shared/wasm-codec/functions/decode-recall-sibling.function.d.ts +13 -0
  173. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +58 -0
  174. package/dist/src/shared/wasm-codec/functions/decode-section-match.function.d.ts +15 -0
  175. package/dist/src/shared/wasm-codec/functions/decode-section-record-trailing.function.d.ts +14 -0
  176. package/dist/src/shared/wasm-codec/functions/decode-section-record.function.d.ts +14 -0
  177. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +33 -0
  178. package/dist/src/shared/wasm-codec/functions/decode-section-type.function.d.ts +13 -0
  179. package/dist/src/shared/wasm-codec/functions/decode-wasm-list.function.d.ts +17 -0
  180. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +52 -0
  181. package/dist/src/shared/wasm-codec/index.d.ts +2 -0
  182. package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +45 -0
  183. package/dist/src/shared/wasm-codec/typings/add-section-result.model.d.ts +27 -0
  184. package/dist/src/shared/wasm-codec/typings/document-manifest.model.d.ts +19 -0
  185. package/dist/src/shared/wasm-codec/typings/document-section.model.d.ts +12 -0
  186. package/dist/src/shared/wasm-codec/typings/item-decoder.type.d.ts +6 -0
  187. package/dist/src/shared/wasm-codec/typings/near-duplicate.model.d.ts +16 -0
  188. package/dist/src/shared/wasm-codec/typings/paged-search-result.model.d.ts +21 -0
  189. package/dist/src/shared/wasm-codec/typings/section-match.model.d.ts +31 -0
  190. package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +38 -0
  191. package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +66 -0
  192. package/dist/src/shared/wasm-codec/typings/section-type-result.model.d.ts +12 -0
  193. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +16 -0
  194. package/dist/src/shared/worker-client/functions/handle-ipc-data.function.d.ts +16 -0
  195. package/dist/src/shared/worker-client/functions/send-ipc-request.function.d.ts +19 -0
  196. package/dist/src/shared/worker-client/index.d.ts +1 -1
  197. package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +31 -15
  198. package/dist/src/shared/worker-client/typings/export-result.model.d.ts +14 -0
  199. package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +6 -0
  200. package/dist/src/shared/worker-client/typings/json-rpc-response.interface.d.ts +16 -0
  201. package/dist/src/shared/worker-client/typings/pending-call.interface.d.ts +7 -0
  202. package/dist/src/shared/worker-client/typings/recall-document.model.d.ts +16 -0
  203. package/dist/src/shared/worker-client/typings/recall-params.model.d.ts +15 -0
  204. package/dist/src/shared/worker-client/typings/recall-reference.model.d.ts +32 -0
  205. package/dist/src/shared/worker-client/typings/recall-sibling.model.d.ts +11 -0
  206. package/dist/src/shared/worker-client/typings/recall-single-result.model.d.ts +40 -0
  207. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +12 -0
  208. package/dist/src/shared/worker-client/typings/section.model.d.ts +16 -0
  209. package/dist/src/shared/worker-daemon/classes/ipc-error.class.d.ts +17 -0
  210. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +35 -0
  211. package/dist/src/shared/worker-daemon/constants/wasm-method-map.constant.d.ts +16 -0
  212. package/dist/src/shared/worker-daemon/functions/build-ipc-error-response.function.d.ts +9 -0
  213. package/dist/src/shared/worker-daemon/functions/check-catalog-version.function.d.ts +9 -0
  214. package/dist/src/shared/worker-daemon/functions/check-preconditions.function.d.ts +10 -0
  215. package/dist/src/shared/worker-daemon/functions/detect-stale-pid.function.d.ts +15 -0
  216. package/dist/src/shared/worker-daemon/functions/dispatch-request.function.d.ts +35 -0
  217. package/dist/src/shared/worker-daemon/functions/handle-check-version.function.d.ts +23 -0
  218. package/dist/src/shared/worker-daemon/functions/handle-config-method.function.d.ts +11 -0
  219. package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +52 -0
  220. package/dist/src/shared/worker-daemon/functions/handle-write-ops.function.d.ts +44 -0
  221. package/dist/src/shared/worker-daemon/functions/parse-auto-capture-section.function.d.ts +14 -0
  222. package/dist/src/shared/worker-daemon/functions/parse-catalog-version.function.d.ts +10 -0
  223. package/dist/src/shared/worker-daemon/functions/parse-embedding-section.function.d.ts +13 -0
  224. package/dist/src/shared/worker-daemon/functions/parse-worker-toml.function.d.ts +11 -0
  225. package/dist/src/shared/worker-daemon/functions/run-startup-integrity-check.function.d.ts +18 -0
  226. package/dist/src/shared/worker-daemon/functions/scan-near-duplicates.function.d.ts +21 -0
  227. package/dist/src/shared/worker-daemon/functions/wasm-bridge.function.d.ts +51 -0
  228. package/dist/src/shared/worker-daemon/functions/wasm-memory-helpers.function.d.ts +22 -0
  229. package/dist/src/shared/worker-daemon/functions/write-lock.function.d.ts +32 -0
  230. package/dist/src/shared/worker-daemon/typings/allocator-ref.interface.d.ts +16 -0
  231. package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +6 -0
  232. package/dist/src/shared/worker-daemon/typings/fs-adapter.interface.d.ts +22 -0
  233. package/dist/src/shared/worker-daemon/typings/handler-context.interface.d.ts +18 -0
  234. package/dist/src/shared/worker-daemon/typings/memory-ref.interface.d.ts +13 -0
  235. package/dist/src/shared/worker-daemon/typings/wasm-fn.type.d.ts +2 -0
  236. package/dist/src/shared/worker-daemon/typings/write-lock.interface.d.ts +15 -0
  237. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
  238. package/dist/wasm/fs-database/kbdb_fs_database.js +28 -1
  239. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  240. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
  241. package/dist/wasm/kb-worker/kbdb_worker.d.ts +48 -1
  242. package/dist/wasm/kb-worker/kbdb_worker.js +60 -1
  243. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  244. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
  245. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  246. package/dist/worker.mjs +396 -60
  247. package/dist/worker.mjs.map +4 -4
  248. package/docs/details/cli.md +102 -15
  249. package/docs/details/library-api.md +55 -6
  250. package/docs/details/mcp-server.md +10 -4
  251. package/docs/details/search-and-ranking.md +63 -5
  252. package/docs/details/storage.md +2 -0
  253. package/docs/goals/auto-capture.md +378 -0
  254. package/docs/goals/benchmarking.md +296 -0
  255. package/docs/goals/cli.md +255 -14
  256. package/docs/goals/concurrency.md +259 -0
  257. package/docs/goals/database.md +244 -17
  258. package/docs/goals/document.md +1 -1
  259. package/docs/goals/hybrid-search.md +436 -0
  260. package/docs/goals/mcp.md +83 -14
  261. package/docs/goals/query-parser.md +98 -4
  262. package/docs/goals/query-result.md +177 -10
  263. package/docs/goals/semantic-dedup.md +229 -0
  264. package/docs/goals/skills.md +72 -0
  265. package/docs/goals/sync.md +217 -0
  266. package/docs/goals/worker-daemon.md +54 -7
  267. package/docs/modules/rust/fs-database/functions/integrity.md +11 -0
  268. package/docs/modules/rust/fs-database/functions/section.md +23 -6
  269. package/docs/modules/rust/fs-database/indexes/vectors.md +110 -0
  270. package/docs/modules/rust/fs-database/module.md +1 -0
  271. package/docs/modules/rust/fs-database/types/section.md +27 -1
  272. package/docs/modules/rust/overview.md +2 -1
  273. package/docs/modules/rust/query-parser/functions/module.md +2 -2
  274. package/docs/modules/rust/query-parser/functions/pipeline.md +44 -6
  275. package/docs/modules/rust/query-parser/module.md +5 -4
  276. package/docs/modules/rust/query-parser/types/keyphrase.md +11 -0
  277. package/docs/modules/rust/query-parser/types/module.md +3 -3
  278. package/docs/modules/typescript/shared/auto-capture/module.md +73 -0
  279. package/docs/modules/typescript/shared/cli/functions.md +68 -3
  280. package/docs/modules/typescript/shared/embedding/functions.md +94 -0
  281. package/docs/modules/typescript/shared/embedding/module.md +71 -0
  282. package/docs/modules/typescript/shared/embedding/typings.md +122 -0
  283. package/docs/overview.md +148 -166
  284. package/docs/release-notes/0.2.0.md +3 -3
  285. package/docs/release-notes/0.3.0.md +89 -0
  286. package/docs/release-notes/0.3.1.md +111 -0
  287. package/docs/release-notes/README.md +2 -0
  288. package/package.json +1 -1
  289. package/src/shared/auto-capture/classes/auto-capture-controller.class.ts +62 -0
  290. package/src/shared/auto-capture/constants/auto-capture-defaults.constant.ts +15 -0
  291. package/src/shared/auto-capture/functions/build-capture-prompt.function.ts +27 -0
  292. package/src/shared/auto-capture/functions/evaluate-trigger.function.ts +50 -0
  293. package/src/shared/auto-capture/index.ts +7 -0
  294. package/src/shared/auto-capture/typings/auto-capture-config.interface.ts +13 -0
  295. package/src/shared/auto-capture/typings/auto-capture-state.interface.ts +13 -0
  296. package/src/shared/auto-capture/typings/auto-capture-trigger.interface.ts +7 -0
  297. package/src/shared/cli/constants/global-help.constant.ts +73 -0
  298. package/src/shared/cli/constants/leaf-help.constant.ts +219 -0
  299. package/src/shared/cli/constants/memory-protocol-body.constant.ts +39 -0
  300. package/src/shared/cli/constants/query-guidance-body.constant.ts +37 -0
  301. package/src/shared/cli/constants/subcommand-help.constant.ts +195 -0
  302. package/src/shared/cli/functions/collect-files.function.ts +55 -0
  303. package/src/shared/cli/functions/compute-section-kbid.function.ts +49 -0
  304. package/src/shared/cli/functions/dispatch-command.function.ts +53 -1
  305. package/src/shared/cli/functions/format-mcp-output.function.ts +41 -0
  306. package/src/shared/cli/functions/format-output.function.ts +36 -12
  307. package/src/shared/cli/functions/format-text-output.function.ts +42 -0
  308. package/src/shared/cli/functions/generate-group-help.function.ts +41 -0
  309. package/src/shared/cli/functions/generate-help.function.ts +56 -1
  310. package/src/shared/cli/functions/handle-data-command.function.ts +67 -0
  311. package/src/shared/cli/functions/handle-mcp.function.ts +56 -0
  312. package/src/shared/cli/functions/handle-migrate.function.ts +64 -0
  313. package/src/shared/cli/functions/hydrate-search-previews.function.ts +29 -0
  314. package/src/shared/cli/functions/install-default-skills.function.ts +296 -0
  315. package/src/shared/cli/functions/parse-args.function.ts +16 -0
  316. package/src/shared/cli/functions/resolve-skill-names.function.ts +43 -0
  317. package/src/shared/cli/functions/run-check.function.ts +87 -6
  318. package/src/shared/cli/functions/run-export.function.ts +40 -0
  319. package/src/shared/cli/functions/run-gc.function.ts +6 -0
  320. package/src/shared/cli/functions/run-init.function.ts +2 -0
  321. package/src/shared/cli/functions/run-learn.function.ts +68 -16
  322. package/src/shared/cli/functions/run-recall.function.ts +66 -0
  323. package/src/shared/cli/functions/run-search.function.ts +60 -15
  324. package/src/shared/cli/functions/version-gate.function.ts +44 -0
  325. package/src/shared/cli/functions/wrap-command.function.ts +34 -0
  326. package/src/shared/cli/index.ts +4 -0
  327. package/src/shared/cli/typings/agent-create-client.interface.ts +47 -0
  328. package/src/shared/cli/typings/agent-get-client.interface.ts +39 -0
  329. package/src/shared/cli/typings/check-client.interface.ts +66 -0
  330. package/src/shared/cli/typings/cli-deps.interface.ts +54 -0
  331. package/src/shared/cli/typings/cli-options.interface.ts +15 -0
  332. package/src/shared/cli/typings/disconnectable-client.interface.ts +29 -0
  333. package/src/shared/cli/typings/dispatch-client.type.ts +46 -0
  334. package/src/shared/cli/typings/learn-client.interface.ts +53 -0
  335. package/src/shared/cli/typings/learn-io.interface.ts +5 -0
  336. package/src/shared/cli/typings/learn-result.model.ts +16 -0
  337. package/src/shared/cli/typings/search-client.interface.ts +73 -0
  338. package/src/shared/cli/typings/search-display.model.ts +18 -0
  339. package/src/shared/embedding/classes/null-embedding-provider.class.ts +29 -0
  340. package/src/shared/embedding/constants/near-duplicate-thresholds.constant.ts +17 -0
  341. package/src/shared/embedding/functions/build-vector-index.function.ts +79 -0
  342. package/src/shared/embedding/functions/cosine-similarity.function.ts +31 -0
  343. package/src/shared/embedding/functions/detect-near-duplicates.function.ts +69 -0
  344. package/src/shared/embedding/functions/jaccard-coefficient.function.ts +26 -0
  345. package/src/shared/embedding/functions/read-vector-index-meta.function.ts +44 -0
  346. package/src/shared/embedding/functions/rrf-fuse.function.ts +33 -0
  347. package/src/shared/embedding/functions/search-vectors.function.ts +59 -0
  348. package/src/shared/embedding/index.ts +20 -0
  349. package/src/shared/embedding/typings/embedding-config.interface.ts +23 -0
  350. package/src/shared/embedding/typings/embedding-provider.interface.ts +25 -0
  351. package/src/shared/embedding/typings/near-duplicate-candidate.model.ts +25 -0
  352. package/src/shared/embedding/typings/near-duplicate-result.model.ts +26 -0
  353. package/src/shared/embedding/typings/vector-index-entry.model.ts +13 -0
  354. package/src/shared/embedding/typings/vector-index-meta.model.ts +14 -0
  355. package/src/shared/embedding/typings/vector-search-result.model.ts +8 -0
  356. package/src/shared/mcp/classes/mcp-server.class.ts +36 -4
  357. package/src/shared/mcp/constants/tool-agent-create.constant.ts +39 -0
  358. package/src/shared/mcp/constants/tool-agent-delete.constant.ts +26 -0
  359. package/src/shared/mcp/constants/tool-agent-get.constant.ts +24 -0
  360. package/src/shared/mcp/constants/tool-agent-list.constant.ts +18 -0
  361. package/src/shared/mcp/constants/tool-auto-capture-review.constant.ts +32 -0
  362. package/src/shared/mcp/constants/tool-check.constant.ts +21 -0
  363. package/src/shared/mcp/constants/tool-content.constant.ts +29 -0
  364. package/src/shared/mcp/constants/tool-export.constant.ts +27 -0
  365. package/src/shared/mcp/constants/tool-gc.constant.ts +21 -0
  366. package/src/shared/mcp/constants/tool-learn.constant.ts +58 -0
  367. package/src/shared/mcp/constants/tool-rebuild.constant.ts +21 -0
  368. package/src/shared/mcp/constants/tool-recall.constant.ts +36 -0
  369. package/src/shared/mcp/constants/tool-retrieve.constant.ts +31 -0
  370. package/src/shared/mcp/constants/tool-search.constant.ts +51 -0
  371. package/src/shared/mcp/constants/tool-skill-delete.constant.ts +24 -0
  372. package/src/shared/mcp/constants/tool-skill-get.constant.ts +27 -0
  373. package/src/shared/mcp/constants/tool-skill-learn.constant.ts +37 -0
  374. package/src/shared/mcp/constants/tool-skill-list.constant.ts +18 -0
  375. package/src/shared/mcp/constants/tool-status.constant.ts +20 -0
  376. package/src/shared/mcp/constants/tool-unlearn.constant.ts +25 -0
  377. package/src/shared/mcp/functions/as-boolean-or-undefined.function.ts +11 -0
  378. package/src/shared/mcp/functions/as-string-array-or-undefined.function.ts +17 -0
  379. package/src/shared/mcp/functions/as-string-array.function.ts +15 -0
  380. package/src/shared/mcp/functions/as-string.function.ts +10 -0
  381. package/src/shared/mcp/functions/build-skills-text.function.ts +43 -0
  382. package/src/shared/mcp/functions/create-tool-definitions.function.ts +74 -5
  383. package/src/shared/mcp/functions/handle-agent-create.function.ts +1 -1
  384. package/src/shared/mcp/functions/handle-agent-prompt.function.ts +68 -0
  385. package/src/shared/mcp/functions/handle-mcp-request.function.ts +202 -0
  386. package/src/shared/mcp/functions/handle-prompt-get.function.ts +18 -12
  387. package/src/shared/mcp/functions/handle-skill-prompt.function.ts +44 -0
  388. package/src/shared/mcp/functions/handle-tool-auto-capture-review.function.ts +24 -0
  389. package/src/shared/mcp/functions/handle-tool-call.function.ts +88 -2
  390. package/src/shared/mcp/functions/handle-tool-check.function.ts +21 -0
  391. package/src/shared/mcp/functions/handle-tool-content.function.ts +23 -0
  392. package/src/shared/mcp/functions/handle-tool-export.function.ts +25 -0
  393. package/src/shared/mcp/functions/handle-tool-gc.function.ts +21 -0
  394. package/src/shared/mcp/functions/handle-tool-learn.function.ts +69 -0
  395. package/src/shared/mcp/functions/handle-tool-rebuild.function.ts +21 -0
  396. package/src/shared/mcp/functions/handle-tool-retrieve.function.ts +40 -0
  397. package/src/shared/mcp/functions/handle-tool-search.function.ts +47 -0
  398. package/src/shared/mcp/functions/handle-tool-skill-delete.function.ts +34 -0
  399. package/src/shared/mcp/functions/handle-tool-skill-get.function.ts +59 -0
  400. package/src/shared/mcp/functions/handle-tool-skill-learn.function.ts +61 -0
  401. package/src/shared/mcp/functions/handle-tool-skill-list.function.ts +39 -0
  402. package/src/shared/mcp/functions/handle-tool-status.function.ts +21 -0
  403. package/src/shared/mcp/functions/handle-tool-unlearn.function.ts +24 -0
  404. package/src/shared/mcp/functions/parse-agent-meta.function.ts +27 -0
  405. package/src/shared/mcp/functions/parse-skill-arguments.function.ts +36 -0
  406. package/src/shared/mcp/functions/read-agent-meta.function.ts +41 -0
  407. package/src/shared/mcp/functions/resolve-skill-refs.function.ts +50 -0
  408. package/src/shared/mcp/functions/run-startup-health-check.function.ts +34 -0
  409. package/src/shared/mcp/typings/mcp-capabilities.interface.ts +16 -0
  410. package/src/shared/mcp/typings/mcp-client.interface.ts +47 -0
  411. package/src/shared/mcp/typings/mcp-completion.interface.ts +45 -0
  412. package/src/shared/mcp/typings/mcp-content-result.model.ts +9 -0
  413. package/src/shared/mcp/typings/mcp-export-result.model.ts +11 -0
  414. package/src/shared/mcp/typings/mcp-gc-result.model.ts +15 -0
  415. package/src/shared/mcp/typings/mcp-integrity-check-result.model.ts +17 -0
  416. package/src/shared/mcp/typings/mcp-integrity-error.model.ts +15 -0
  417. package/src/shared/mcp/typings/mcp-notification.interface.ts +9 -0
  418. package/src/shared/mcp/typings/mcp-rebuild-result.model.ts +9 -0
  419. package/src/shared/mcp/typings/mcp-request.interface.ts +11 -0
  420. package/src/shared/mcp/typings/mcp-resource-result.interface.ts +12 -0
  421. package/src/shared/mcp/typings/mcp-resource-template.interface.ts +11 -0
  422. package/src/shared/mcp/typings/mcp-response.interface.ts +18 -0
  423. package/src/shared/mcp/typings/mcp-server-info.interface.ts +7 -0
  424. package/src/shared/mcp/typings/mcp-server-state.interface.ts +17 -0
  425. package/src/shared/mcp/typings/mcp-tool-annotations.interface.ts +32 -0
  426. package/src/shared/mcp/typings/mcp-tool-definition.interface.ts +16 -0
  427. package/src/shared/mcp/typings/mcp-tool-result.interface.ts +19 -0
  428. package/src/shared/mcp/typings/mcp-worker-client.interface.ts +243 -0
  429. package/src/shared/mcp/typings/tool-call-result.model.ts +18 -0
  430. package/src/shared/sync/functions/build-import-report.function.ts +40 -0
  431. package/src/shared/sync/functions/parse-export-entry.function.ts +45 -0
  432. package/src/shared/sync/functions/resolve-conflict.function.ts +31 -0
  433. package/src/shared/sync/functions/serialize-export-entry.function.ts +18 -0
  434. package/src/shared/sync/index.ts +9 -0
  435. package/src/shared/sync/typings/conflict-resolution.type.ts +8 -0
  436. package/src/shared/sync/typings/export-entry.interface.ts +13 -0
  437. package/src/shared/sync/typings/export-options.interface.ts +9 -0
  438. package/src/shared/sync/typings/import-options.interface.ts +7 -0
  439. package/src/shared/sync/typings/import-report.interface.ts +15 -0
  440. package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +112 -0
  441. package/src/shared/wasm-codec/functions/decode-one-recall-result.function.ts +86 -0
  442. package/src/shared/wasm-codec/functions/decode-option-string.function.ts +24 -0
  443. package/src/shared/wasm-codec/functions/decode-recall-document.function.ts +59 -0
  444. package/src/shared/wasm-codec/functions/decode-recall-reference.function.ts +52 -0
  445. package/src/shared/wasm-codec/functions/decode-recall-sibling.function.ts +43 -0
  446. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +86 -0
  447. package/src/shared/wasm-codec/functions/decode-section-match.function.ts +80 -0
  448. package/src/shared/wasm-codec/functions/decode-section-record-trailing.function.ts +75 -0
  449. package/src/shared/wasm-codec/functions/decode-section-record.function.ts +85 -0
  450. package/src/shared/wasm-codec/functions/decode-section-records.function.ts +87 -0
  451. package/src/shared/wasm-codec/functions/decode-section-type.function.ts +30 -0
  452. package/src/shared/wasm-codec/functions/decode-wasm-list.function.ts +31 -0
  453. package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +68 -0
  454. package/src/shared/wasm-codec/index.ts +5 -0
  455. package/src/shared/wasm-codec/typings/add-section-input.model.ts +45 -0
  456. package/src/shared/wasm-codec/typings/add-section-result.model.ts +28 -0
  457. package/src/shared/wasm-codec/typings/document-manifest.model.ts +20 -0
  458. package/src/shared/wasm-codec/typings/document-section.model.ts +12 -0
  459. package/src/shared/wasm-codec/typings/item-decoder.type.ts +10 -0
  460. package/src/shared/wasm-codec/typings/near-duplicate.model.ts +16 -0
  461. package/src/shared/wasm-codec/typings/paged-search-result.model.ts +22 -0
  462. package/src/shared/wasm-codec/typings/section-match.model.ts +31 -0
  463. package/src/shared/wasm-codec/typings/section-record-trailing.model.ts +38 -0
  464. package/src/shared/wasm-codec/typings/section-record.model.ts +66 -0
  465. package/src/shared/wasm-codec/typings/section-type-result.model.ts +12 -0
  466. package/src/shared/worker-client/classes/worker-client.class.ts +19 -0
  467. package/src/shared/worker-client/functions/handle-ipc-data.function.ts +49 -0
  468. package/src/shared/worker-client/functions/send-ipc-request.function.ts +39 -0
  469. package/src/shared/worker-client/index.ts +4 -1
  470. package/src/shared/worker-client/typings/add-section-result.model.ts +32 -15
  471. package/src/shared/worker-client/typings/export-result.model.ts +14 -0
  472. package/src/shared/worker-client/typings/gc-result.model.ts +6 -0
  473. package/src/shared/worker-client/typings/json-rpc-response.interface.ts +17 -0
  474. package/src/shared/worker-client/typings/pending-call.interface.ts +7 -0
  475. package/src/shared/worker-client/typings/recall-document.model.ts +16 -0
  476. package/src/shared/worker-client/typings/recall-params.model.ts +15 -0
  477. package/src/shared/worker-client/typings/recall-reference.model.ts +32 -0
  478. package/src/shared/worker-client/typings/recall-sibling.model.ts +11 -0
  479. package/src/shared/worker-client/typings/recall-single-result.model.ts +41 -0
  480. package/src/shared/worker-client/typings/search-result.model.ts +12 -0
  481. package/src/shared/worker-client/typings/section.model.ts +16 -0
  482. package/src/shared/worker-daemon/classes/ipc-error.class.ts +22 -0
  483. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +315 -46
  484. package/src/shared/worker-daemon/constants/wasm-method-map.constant.ts +69 -0
  485. package/src/shared/worker-daemon/functions/build-ipc-error-response.function.ts +16 -0
  486. package/src/shared/worker-daemon/functions/check-catalog-version.function.ts +54 -0
  487. package/src/shared/worker-daemon/functions/check-preconditions.function.ts +28 -0
  488. package/src/shared/worker-daemon/functions/create-host-imports.function.ts +19 -4
  489. package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +5 -1
  490. package/src/shared/worker-daemon/functions/detect-stale-pid.function.ts +33 -0
  491. package/src/shared/worker-daemon/functions/dispatch-request.function.ts +190 -0
  492. package/src/shared/worker-daemon/functions/handle-check-version.function.ts +74 -0
  493. package/src/shared/worker-daemon/functions/handle-config-method.function.ts +27 -0
  494. package/src/shared/worker-daemon/functions/handle-read-ops.function.ts +236 -0
  495. package/src/shared/worker-daemon/functions/handle-write-ops.function.ts +257 -0
  496. package/src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts +51 -0
  497. package/src/shared/worker-daemon/functions/parse-catalog-version.function.ts +20 -0
  498. package/src/shared/worker-daemon/functions/parse-embedding-section.function.ts +38 -0
  499. package/src/shared/worker-daemon/functions/parse-worker-toml.function.ts +104 -0
  500. package/src/shared/worker-daemon/functions/run-startup-integrity-check.function.ts +55 -0
  501. package/src/shared/worker-daemon/functions/scan-near-duplicates.function.ts +92 -0
  502. package/src/shared/worker-daemon/functions/wasm-bridge.function.ts +144 -0
  503. package/src/shared/worker-daemon/functions/wasm-memory-helpers.function.ts +41 -0
  504. package/src/shared/worker-daemon/functions/write-lock.function.ts +49 -0
  505. package/src/shared/worker-daemon/typings/allocator-ref.interface.ts +16 -0
  506. package/src/shared/worker-daemon/typings/daemon-config.interface.ts +7 -0
  507. package/src/shared/worker-daemon/typings/fs-adapter.interface.ts +22 -0
  508. package/src/shared/worker-daemon/typings/handler-context.interface.ts +19 -0
  509. package/src/shared/worker-daemon/typings/memory-ref.interface.ts +13 -0
  510. package/src/shared/worker-daemon/typings/wasm-fn.type.ts +2 -0
  511. package/src/shared/worker-daemon/typings/write-lock.interface.ts +13 -0
  512. package/src/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
  513. package/src/wasm/fs-database/kbdb_fs_database.js +28 -1
  514. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  515. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
  516. package/src/wasm/kb-worker/kbdb_worker.d.ts +48 -1
  517. package/src/wasm/kb-worker/kbdb_worker.js +60 -1
  518. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  519. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
  520. package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
package/dist/cli.mjs CHANGED
@@ -78,6 +78,9 @@ function parseArgs(argv) {
78
78
  parseInt(argv[++i] ?? "", 10) || 0
79
79
  );
80
80
  break;
81
+ case "--algo":
82
+ options.algo = argv[++i];
83
+ break;
81
84
  case "--title":
82
85
  options.title = argv[++i];
83
86
  break;
@@ -99,6 +102,19 @@ function parseArgs(argv) {
99
102
  case "--skills":
100
103
  options.skills = (argv[++i] ?? "").split(",");
101
104
  break;
105
+ case "--tags":
106
+ options.tags = (argv[++i] ?? "").split(",");
107
+ break;
108
+ case "--replace":
109
+ options.replace = true;
110
+ break;
111
+ case "--depth":
112
+ case "-d":
113
+ options.depth = Math.min(
114
+ 3,
115
+ Math.max(0, parseInt(argv[++i] ?? "", 10) || 0)
116
+ );
117
+ break;
102
118
  case "--content":
103
119
  case "-c":
104
120
  options.content = true;
@@ -136,9 +152,11 @@ function formatText(paged) {
136
152
  const num = paged.offset + i + 1;
137
153
  const heading = r.heading ?? "(untitled)";
138
154
  const terms = r.matched_terms.join(", ");
139
- return `${String(num)}. [${r.kbid}] ${heading} (score: ${r.score.toFixed(4)})
155
+ const fields = r.matched_fields.join(", ");
156
+ const confidencePct = (r.confidence * 100).toFixed(0);
157
+ return `${String(num)}. [${r.kbid}] ${heading} (score: ${r.score.toFixed(4)}, confidence: ${confidencePct}%)
140
158
  ${r.snippet || r.preview || "(no snippet)"}
141
- type: ${r.type} terms: ${terms}`;
159
+ type: ${r.type} terms: ${terms}` + (fields ? ` fields: ${fields}` : "");
142
160
  }).join("\n\n");
143
161
  const footer = `
144
162
  Showing ${String(start)}-${String(end)} of ${String(paged.total)} results`;
@@ -147,12 +165,32 @@ Use --offset ${String(end)} to see more` : "";
147
165
  return lines + footer + hint;
148
166
  }
149
167
  function formatMcp(paged) {
150
- return JSON.stringify({
151
- type: "text",
152
- text: paged.items.map(
153
- (r) => `[${r.kbid}] ${r.heading ?? "(untitled)"} \u2014 ${r.snippet || r.preview}`
154
- ).join("\n")
155
- });
168
+ const mcpItems = paged.items.map((r) => ({
169
+ kbid: r.kbid,
170
+ heading: r.heading,
171
+ type: r.type,
172
+ docids: r.docids,
173
+ snippet: r.snippet,
174
+ matched_terms: r.matched_terms,
175
+ matched_fields: r.matched_fields,
176
+ created_at: r.created_at
177
+ }));
178
+ return JSON.stringify(
179
+ {
180
+ type: "text",
181
+ text: paged.items.map(
182
+ (r) => `[${r.kbid}] ${r.heading ?? "(untitled)"} \u2014 ${r.snippet || r.preview}`
183
+ ).join("\n"),
184
+ items: mcpItems,
185
+ total: paged.total,
186
+ offset: paged.offset,
187
+ limit: paged.limit,
188
+ has_more: paged.has_more,
189
+ relaxed: paged.relaxed
190
+ },
191
+ null,
192
+ 2
193
+ );
156
194
  }
157
195
 
158
196
  // src/shared/cli/functions/run-search.function.ts
@@ -164,14 +202,16 @@ async function runSearch(client, options) {
164
202
  total: 0,
165
203
  offset: 0,
166
204
  limit: options.limit,
167
- has_more: false
205
+ has_more: false,
206
+ relaxed: false
168
207
  };
169
208
  }
170
209
  const results = await client.search({
171
210
  query,
172
211
  mode: options.mode,
173
212
  limit: options.limit,
174
- offset: options.offset
213
+ offset: options.offset,
214
+ algo: options.algo
175
215
  });
176
216
  return {
177
217
  items: results.items.map((r) => ({
@@ -180,17 +220,43 @@ async function runSearch(client, options) {
180
220
  type: r.type,
181
221
  docids: r.docids,
182
222
  score: r.score,
223
+ confidence: r.confidence ?? 0,
183
224
  snippet: r.snippet,
184
225
  matched_terms: r.matched_terms,
226
+ matched_fields: r.matched_fields ?? [],
227
+ created_at: r.created_at ?? "",
185
228
  preview: ""
186
229
  })),
187
230
  total: results.total,
188
231
  offset: results.offset,
189
232
  limit: results.limit,
190
- has_more: results.has_more
233
+ has_more: results.has_more,
234
+ relaxed: results.relaxed ?? false
191
235
  };
192
236
  }
193
237
 
238
+ // src/shared/cli/functions/run-recall.function.ts
239
+ var MAX_RECALL_DEPTH = 3;
240
+ async function runRecall(client, options) {
241
+ if (options.args.length === 0) {
242
+ return { error: "no kbid provided" };
243
+ }
244
+ const depth = Math.min(
245
+ MAX_RECALL_DEPTH,
246
+ Math.max(0, options.depth ?? 0)
247
+ );
248
+ if (options.args.length === 1) {
249
+ return client.recall({ kbid: options.args[0], depth });
250
+ }
251
+ return client.recall({ kbids: options.args, depth });
252
+ }
253
+
254
+ // src/shared/cli/functions/run-export.function.ts
255
+ async function runExport(client, options) {
256
+ const path = options.args[0];
257
+ return client.export({ path });
258
+ }
259
+
194
260
  // src/shared/cli/functions/run-learn.function.ts
195
261
  import { readFileSync, readdirSync, statSync } from "node:fs";
196
262
  import { basename, extname, join } from "node:path";
@@ -208,14 +274,11 @@ async function runLearn(client, options, io) {
208
274
  content,
209
275
  title: options.title,
210
276
  description: options.description,
211
- docid: options.docid
212
- });
213
- results.push({
214
- kbid: result.kbid,
215
- path: "-",
216
- size: content.length,
217
- skipped: false
277
+ docid: options.docid,
278
+ tags: options.tags,
279
+ replace: options.replace
218
280
  });
281
+ results.push(mapAddSectionResult(result, "-", content.length));
219
282
  continue;
220
283
  }
221
284
  const files = collectFiles(target);
@@ -225,18 +288,30 @@ async function runLearn(client, options, io) {
225
288
  sectionType: "text",
226
289
  content,
227
290
  title: options.title,
228
- docid: options.docid
229
- });
230
- results.push({
231
- kbid: result.kbid,
232
- path: file,
233
- size: content.length,
234
- skipped: false
291
+ description: options.description,
292
+ docid: options.docid,
293
+ tags: options.tags,
294
+ replace: options.replace,
295
+ sourcePath: file
235
296
  });
297
+ results.push(
298
+ mapAddSectionResult(result, file, content.length)
299
+ );
236
300
  }
237
301
  }
238
302
  return results;
239
303
  }
304
+ function mapAddSectionResult(result, path, size) {
305
+ return {
306
+ kbid: result.kbid,
307
+ path,
308
+ size,
309
+ skipped: false,
310
+ superseded: result.superseded ?? null,
311
+ warnings: result.warnings ?? [],
312
+ near_duplicates: result.near_duplicates ?? []
313
+ };
314
+ }
240
315
  function readProcessStdin() {
241
316
  return new Promise((resolve4) => {
242
317
  const chunks = [];
@@ -301,8 +376,26 @@ async function runContent(client, options) {
301
376
  }
302
377
 
303
378
  // src/shared/cli/functions/run-check.function.ts
379
+ function parseDivergentContent(encoded) {
380
+ if (!encoded) return [];
381
+ return encoded.split(";").filter((segment) => segment.includes(":")).map((segment) => {
382
+ const colonIdx = segment.indexOf(":");
383
+ const sourceKey = segment.slice(0, colonIdx);
384
+ const kbids = segment.slice(colonIdx + 1).split(",").filter((k) => k.length > 0);
385
+ return { sourceKey, kbids };
386
+ }).filter((entry) => entry.kbids.length > 0);
387
+ }
304
388
  async function runCheck(client, _options) {
305
- return client.integrityCheck();
389
+ const raw = await client.integrityCheck();
390
+ return {
391
+ ok: raw.ok,
392
+ errors: raw.errors,
393
+ sections_checked: raw.sections_checked,
394
+ documents_checked: raw.documents_checked,
395
+ references_checked: raw.references_checked,
396
+ elapsed_ms: raw.elapsed_ms,
397
+ divergent_content: parseDivergentContent(raw.divergent_content)
398
+ };
306
399
  }
307
400
 
308
401
  // src/shared/cli/functions/run-gc.function.ts
@@ -325,8 +418,109 @@ function findDb(dbPath) {
325
418
  }
326
419
 
327
420
  // src/shared/cli/functions/run-init.function.ts
421
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "node:fs";
422
+ import { join as join4, resolve as resolve2 } from "node:path";
423
+
424
+ // src/shared/cli/functions/install-default-skills.function.ts
425
+ import { createHash } from "node:crypto";
328
426
  import { existsSync as existsSync2, mkdirSync, writeFileSync } from "node:fs";
329
- import { join as join3, resolve as resolve2 } from "node:path";
427
+ import { join as join3 } from "node:path";
428
+ var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
429
+ function base32Encode(bytes) {
430
+ let result = "";
431
+ let bits = 0;
432
+ let value = 0;
433
+ for (const byte of bytes) {
434
+ value = value << 8 | byte;
435
+ bits += 8;
436
+ while (bits >= 5) {
437
+ result += BASE32_ALPHABET[value >>> bits - 5 & 31];
438
+ bits -= 5;
439
+ }
440
+ }
441
+ if (bits > 0) {
442
+ result += BASE32_ALPHABET[value << 5 - bits & 31];
443
+ }
444
+ return result.toLowerCase();
445
+ }
446
+ function computeSectionKbid(mimeType, content) {
447
+ const contentBytes = Buffer.from(content, "utf-8");
448
+ const header = `section ${mimeType} ${contentBytes.length.toString()}\0`;
449
+ const headerBytes = Buffer.from(header, "utf-8");
450
+ const input = Buffer.concat([headerBytes, contentBytes]);
451
+ const hash = createHash("sha256").update(input).digest();
452
+ const truncated = new Uint8Array(hash.buffer, 0, 16);
453
+ return base32Encode(truncated);
454
+ }
455
+ function escapeToml(s) {
456
+ return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
457
+ }
458
+ function serializeSkillSection(kbid, title, description, content) {
459
+ const size = Buffer.byteLength(content, "utf-8");
460
+ const header = [
461
+ `kbid = "${escapeToml(kbid)}"`,
462
+ `section_type = "text/markdown"`,
463
+ `type_name = "skill"`,
464
+ `title = "${escapeToml(title)}"`,
465
+ `description = "${escapeToml(description)}"`,
466
+ `size = ${size.toString()}`,
467
+ `token_count = 0`,
468
+ `heading_token_count = 0`,
469
+ `body_token_count = 0`,
470
+ `code_token_count = 0`,
471
+ `created_at = 0`,
472
+ `checksum = "${escapeToml(kbid)}"`,
473
+ ""
474
+ ].join("\n");
475
+ return `${header}
476
+ ---
477
+ ${content}`;
478
+ }
479
+ function installSkill(sectionsDir, skill) {
480
+ const content = JSON.stringify({
481
+ name: skill.name,
482
+ description: skill.description,
483
+ arguments: [],
484
+ body: skill.body
485
+ });
486
+ const kbid = computeSectionKbid("text/markdown", content);
487
+ const prefix = kbid.slice(0, 2);
488
+ const shardDir = join3(sectionsDir, prefix);
489
+ const filePath = join3(shardDir, `${kbid}.section`);
490
+ if (existsSync2(filePath)) {
491
+ return;
492
+ }
493
+ mkdirSync(shardDir, { recursive: true });
494
+ const fileContent = serializeSkillSection(
495
+ kbid,
496
+ skill.name,
497
+ skill.description,
498
+ content
499
+ );
500
+ writeFileSync(filePath, fileContent, "utf-8");
501
+ }
502
+ var QUERY_GUIDANCE_BODY = 'This knowledge base uses lexical search (stemmed BM25F), not semantic/vector search. Follow these guidelines for effective retrieval:\n\n1. Issue MULTIPLE short keyword queries rather than one long natural-language question. Each query should target 2-3 specific terms.\n\n2. EXPAND SYNONYMS yourself. "login" will not match "sign-in" unless both terms appear in the content. Try alternative phrasings: search for "login", then "sign-in", then "authentication".\n\n3. USE BOOLEAN AND PHRASE SYNTAX:\n - Exact phrases: "error handling"\n - Boolean AND: auth AND token\n - Boolean OR: cache OR redis\n - Exclusion: auth -oauth\n\n4. LEAN ON HEADINGS. Headings carry 2x weight in ranking. Search for terms that are likely in section titles.\n\n5. STEMMING IS AUTOMATIC. "connections" matches "connect", "running" matches "run". You do not need to try inflected forms.\n\n6. USE RECALL AFTER SEARCH. After finding relevant sections with search, use recall with increasing depth (0-3) to progressively expand context: depth 0 = full content, depth 1 = parent documents + back-references, depth 2 = siblings + forward references, depth 3 = referenced sections.\n\n7. CODE IDENTIFIERS ARE SPLIT. camelCase and snake_case names are decomposed: getUserById becomes searchable as "get", "user", "by", "id".\n\n8. PAGINATION. Default limit is 20 results. Use offset for additional pages if total > limit.';
503
+ var MEMORY_PROTOCOL_BODY = "Follow these guidelines to keep the knowledge base accurate and useful:\n\n1. STORE DURABLE FACTS: decisions, architecture choices, configuration values, corrections to prior knowledge, API contracts, and resolved incidents. These are the facts that matter weeks later.\n\n2. DO NOT STORE: transient conversation context, debugging output, ephemeral task state, raw log dumps, or information that changes every session. The brain should contain knowledge, not activity logs.\n\n3. SEARCH BEFORE STORING. Always search the knowledge base before adding new content. If a section already covers the topic, use learn with --replace to update it rather than creating a duplicate.\n\n4. USE --replace FOR CORRECTIONS. When a fact changes (e.g., rate limit updated from 100 to 200 req/min), re-learn the corrected content with --replace so the old version is superseded. Without --replace, both the old and new versions coexist with equal ranking.\n\n5. ATTACH TAGS for scoping. Use tags like project name, domain, or topic (e.g., --tags auth,api,v2) so queries can be filtered by scope later.\n\n6. PREFER RECENT RESULTS. When search returns multiple sections covering the same topic, prefer the one with the most recent created_at timestamp -- it is more likely to reflect the current state.\n\n7. USE RECALL AFTER SEARCH. After finding relevant sections, use recall with increasing depth (0-3) to expand context progressively before making decisions.\n\n8. INCLUDE HEADINGS. Always provide a descriptive title when storing content. Headings carry 2x ranking weight -- omitting them significantly reduces searchability.";
504
+ var DEFAULT_SKILLS = [
505
+ {
506
+ name: "query-guidance",
507
+ description: "How to effectively search this knowledge base. Read this before issuing search queries.",
508
+ body: QUERY_GUIDANCE_BODY
509
+ },
510
+ {
511
+ name: "memory-protocol",
512
+ description: "Guidelines for what to store in this knowledge base and when. Read this before using the learn tool.",
513
+ body: MEMORY_PROTOCOL_BODY
514
+ }
515
+ ];
516
+ function installDefaultSkills(dbDir) {
517
+ const sectionsDir = join3(dbDir, "sections");
518
+ for (const skill of DEFAULT_SKILLS) {
519
+ installSkill(sectionsDir, skill);
520
+ }
521
+ }
522
+
523
+ // src/shared/cli/functions/run-init.function.ts
330
524
  var DB_FORMAT_VERSION = 1;
331
525
  var CATALOG_TOML = `version = ${DB_FORMAT_VERSION.toString()}
332
526
  section_count = 0
@@ -344,21 +538,21 @@ var GITIGNORE = [
344
538
  ""
345
539
  ].join("\n");
346
540
  function createScaffold(dbDir) {
347
- mkdirSync(dbDir, { recursive: true });
348
- mkdirSync(join3(dbDir, "sections"));
349
- mkdirSync(join3(dbDir, "documents"));
350
- writeFileSync(join3(dbDir, "catalog.toml"), CATALOG_TOML);
351
- writeFileSync(join3(dbDir, "corpus.bin"), "");
352
- writeFileSync(join3(dbDir, "inverted.idx"), "");
353
- writeFileSync(join3(dbDir, "positional.idx"), "");
354
- writeFileSync(join3(dbDir, "worker.toml"), WORKER_TOML);
355
- writeFileSync(join3(dbDir, ".gitignore"), GITIGNORE);
541
+ mkdirSync2(dbDir, { recursive: true });
542
+ mkdirSync2(join4(dbDir, "sections"));
543
+ mkdirSync2(join4(dbDir, "documents"));
544
+ writeFileSync2(join4(dbDir, "catalog.toml"), CATALOG_TOML);
545
+ writeFileSync2(join4(dbDir, "corpus.bin"), "");
546
+ writeFileSync2(join4(dbDir, "inverted.idx"), "");
547
+ writeFileSync2(join4(dbDir, "positional.idx"), "");
548
+ writeFileSync2(join4(dbDir, "worker.toml"), WORKER_TOML);
549
+ writeFileSync2(join4(dbDir, ".gitignore"), GITIGNORE);
356
550
  }
357
551
  function runInit(options) {
358
552
  const basePath = options.dbPath ? resolve2(options.dbPath) : process.cwd();
359
- const dbDir = join3(basePath, ".kbdb");
553
+ const dbDir = join4(basePath, ".kbdb");
360
554
  try {
361
- if (existsSync2(dbDir)) {
555
+ if (existsSync3(dbDir)) {
362
556
  return {
363
557
  ok: false,
364
558
  targetPath: dbDir,
@@ -366,6 +560,7 @@ function runInit(options) {
366
560
  };
367
561
  }
368
562
  createScaffold(dbDir);
563
+ installDefaultSkills(dbDir);
369
564
  return { ok: true, targetPath: dbDir };
370
565
  } catch (err) {
371
566
  const errorMessage = err instanceof Error ? err.message : String(err);
@@ -723,6 +918,8 @@ async function dispatchCommand(client, options, io) {
723
918
  return handleUnlearn(client, options);
724
919
  case "search":
725
920
  return handleSearch(client, options);
921
+ case "recall":
922
+ return handleRecall(client, options);
726
923
  case "content":
727
924
  return handleContent(client, options);
728
925
  case "check":
@@ -733,6 +930,8 @@ async function dispatchCommand(client, options, io) {
733
930
  return handleRebuild(client, options);
734
931
  case "status":
735
932
  return handleStatus(client, options);
933
+ case "export":
934
+ return handleExport(client, options);
736
935
  case "db-init":
737
936
  return handleDbInit(options);
738
937
  case "db-migrate":
@@ -821,6 +1020,40 @@ async function handleSearch(client, options) {
821
1020
  };
822
1021
  }
823
1022
  }
1023
+ async function handleRecall(client, options) {
1024
+ try {
1025
+ const result = await runRecall(client, options);
1026
+ if ("error" in result) {
1027
+ return {
1028
+ error: `error: ${result.error}`,
1029
+ exitCode: 1
1030
+ };
1031
+ }
1032
+ return {
1033
+ output: JSON.stringify(result, null, 2),
1034
+ exitCode: 0
1035
+ };
1036
+ } catch (err) {
1037
+ return {
1038
+ error: `recall failed: ${errorToMessage(err)}`,
1039
+ exitCode: 1
1040
+ };
1041
+ }
1042
+ }
1043
+ async function handleExport(client, options) {
1044
+ try {
1045
+ const result = await runExport(client, options);
1046
+ return {
1047
+ output: JSON.stringify(result, null, 2),
1048
+ exitCode: 0
1049
+ };
1050
+ } catch (err) {
1051
+ return {
1052
+ error: `export failed: ${errorToMessage(err)}`,
1053
+ exitCode: 1
1054
+ };
1055
+ }
1056
+ }
824
1057
  async function handleContent(client, options) {
825
1058
  try {
826
1059
  const result = await runContent(client, options);
@@ -928,11 +1161,13 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
928
1161
  "learn",
929
1162
  "unlearn",
930
1163
  "search",
1164
+ "recall",
931
1165
  "content",
932
1166
  "check",
933
1167
  "gc",
934
1168
  "rebuild",
935
1169
  "status",
1170
+ "export",
936
1171
  "mcp",
937
1172
  "db",
938
1173
  "skill",
@@ -995,6 +1230,7 @@ Knowledge Base:
995
1230
  learn Import content from files/stdin
996
1231
  unlearn Remove sections by kbid
997
1232
  search Query the knowledge base
1233
+ recall Retrieve section context by kbid
998
1234
  content Compose rendered content from ids
999
1235
 
1000
1236
  Database:
@@ -1007,6 +1243,7 @@ Maintenance:
1007
1243
  sections
1008
1244
  rebuild Reconstruct all index files
1009
1245
  status Show database status
1246
+ export Snapshot database for backup
1010
1247
 
1011
1248
  Skills:
1012
1249
  skill learn Create a new skill definition
@@ -1079,14 +1316,18 @@ Options:
1079
1316
  --title <title> Section title
1080
1317
  --description <d> Section description
1081
1318
  --docid <docid> Document ID to group under
1319
+ --tags <t,...> Comma-separated tags
1320
+ --replace Supersede existing section by source key
1082
1321
  --db <path> Path to .kbdb directory
1083
1322
 
1084
1323
  Output:
1085
- JSON array of { kbid, path, size, skipped }
1324
+ JSON array of { kbid, path, size, skipped,
1325
+ superseded, warnings, near_duplicates }
1086
1326
 
1087
1327
  Examples:
1088
1328
  kbdb learn README.md
1089
1329
  kbdb learn ./docs/
1330
+ kbdb learn --tags auth,api --replace doc.md
1090
1331
  cat notes.txt | kbdb learn -
1091
1332
  `,
1092
1333
  unlearn: `kbdb unlearn - Remove sections by kbid
@@ -1127,6 +1368,25 @@ Examples:
1127
1368
  kbdb search "machine learning"
1128
1369
  kbdb search --limit 5 --format text query
1129
1370
  kbdb search --mode documents --content term
1371
+ `,
1372
+ recall: `kbdb recall - Retrieve section context by kbid
1373
+
1374
+ Usage: kbdb recall [options] <kbid>...
1375
+
1376
+ Arguments:
1377
+ <kbid> 26-character knowledge base identifier
1378
+
1379
+ Options:
1380
+ --depth <n>, -d Expansion depth (0-3, default: 0)
1381
+ --tags <t,...> Filter by tags
1382
+ --db <path> Path to .kbdb directory
1383
+
1384
+ Output:
1385
+ JSON RecallResult or RecallResult[]
1386
+
1387
+ Examples:
1388
+ kbdb recall abcdef1234567890abcdef1234
1389
+ kbdb recall kbid1 --depth 2
1130
1390
  `,
1131
1391
  content: `kbdb content - Compose rendered content from ids
1132
1392
 
@@ -1200,6 +1460,25 @@ Output:
1200
1460
  Examples:
1201
1461
  kbdb status
1202
1462
  kbdb status --db /path/to/project
1463
+ `,
1464
+ export: `kbdb export - Snapshot database for backup
1465
+
1466
+ Usage: kbdb export [options] [<path>]
1467
+
1468
+ Arguments:
1469
+ <path> Output directory path
1470
+ (default: ./kbdb-export/)
1471
+
1472
+ Options:
1473
+ --db <path> Path to .kbdb directory
1474
+
1475
+ Output:
1476
+ JSON { path, sections_exported, documents_exported }
1477
+
1478
+ Examples:
1479
+ kbdb export
1480
+ kbdb export ./my-backup
1481
+ kbdb export --db /path/to/project
1203
1482
  `,
1204
1483
  mcp: `kbdb mcp - Start MCP server mode (stdio)
1205
1484
 
@@ -1870,6 +2149,23 @@ var WorkerClient = class {
1870
2149
  docType
1871
2150
  });
1872
2151
  }
2152
+ /**
2153
+ * Exports the database to a target directory on disk.
2154
+ *
2155
+ * Copies section files, document manifests, and `catalog.toml`
2156
+ * to `params.path`. Index files are not exported because they
2157
+ * are derivable from the section and document data.
2158
+ *
2159
+ * @param params - optional export parameters
2160
+ * @param params.path - target directory path; defaults to
2161
+ * `./kbdb-export/` when not provided
2162
+ * @returns export report with the resolved path and file counts
2163
+ */
2164
+ async export(params) {
2165
+ return this.call("export", {
2166
+ targetPath: params?.path || void 0
2167
+ });
2168
+ }
1873
2169
  /**
1874
2170
  * Sends a JSON-RPC 2.0 request and awaits the response.
1875
2171
  *
@@ -1927,17 +2223,17 @@ var WorkerClient = class {
1927
2223
  };
1928
2224
 
1929
2225
  // src/shared/worker-client/functions/create-worker-client.function.ts
1930
- import { existsSync as existsSync6, readFileSync as readFileSync3, unlinkSync as unlinkSync2 } from "node:fs";
1931
- import { join as join7 } from "node:path";
2226
+ import { existsSync as existsSync7, readFileSync as readFileSync3, unlinkSync as unlinkSync2 } from "node:fs";
2227
+ import { join as join8 } from "node:path";
1932
2228
  import { tmpdir as tmpdir3 } from "node:os";
1933
2229
 
1934
2230
  // src/shared/worker-client/functions/resolve-db-path.function.ts
1935
- import { existsSync as existsSync3 } from "node:fs";
1936
- import { join as join4, resolve as resolve3 } from "node:path";
2231
+ import { existsSync as existsSync4 } from "node:fs";
2232
+ import { join as join5, resolve as resolve3 } from "node:path";
1937
2233
  function resolveDbPath(targetDir) {
1938
2234
  const base = targetDir ? resolve3(targetDir) : process.cwd();
1939
- const dbPath = join4(base, ".kbdb");
1940
- if (!existsSync3(dbPath)) {
2235
+ const dbPath = join5(base, ".kbdb");
2236
+ if (!existsSync4(dbPath)) {
1941
2237
  throw new Error(`database not found: ${dbPath}`);
1942
2238
  }
1943
2239
  return dbPath;
@@ -1950,8 +2246,8 @@ async function computeContextId(absolutePath) {
1950
2246
  }
1951
2247
 
1952
2248
  // src/shared/worker-client/functions/discover-daemon.function.ts
1953
- import { existsSync as existsSync4, readFileSync as readFileSync2, unlinkSync } from "node:fs";
1954
- import { join as join5 } from "node:path";
2249
+ import { existsSync as existsSync5, readFileSync as readFileSync2, unlinkSync } from "node:fs";
2250
+ import { join as join6 } from "node:path";
1955
2251
  import { tmpdir } from "node:os";
1956
2252
 
1957
2253
  // src/shared/platform/functions/is-process-alive.function.ts
@@ -1966,8 +2262,8 @@ function isProcessAlive(pid) {
1966
2262
 
1967
2263
  // src/shared/worker-client/functions/discover-daemon.function.ts
1968
2264
  function discoverDaemon(contextId) {
1969
- const pidPath = join5(tmpdir(), `kbdb-${contextId}.pid`);
1970
- if (!existsSync4(pidPath)) return null;
2265
+ const pidPath = join6(tmpdir(), `kbdb-${contextId}.pid`);
2266
+ if (!existsSync5(pidPath)) return null;
1971
2267
  const pidStr = readFileSync2(pidPath, "utf-8").trim();
1972
2268
  const pid = parseInt(pidStr, 10);
1973
2269
  if (isNaN(pid) || !isProcessAlive(pid)) {
@@ -1977,8 +2273,8 @@ function discoverDaemon(contextId) {
1977
2273
  }
1978
2274
  return null;
1979
2275
  }
1980
- const socketPath = join5(tmpdir(), `kbdb-${contextId}.sock`);
1981
- const crashPath = join5(tmpdir(), `kbdb-${contextId}.crash`);
2276
+ const socketPath = join6(tmpdir(), `kbdb-${contextId}.sock`);
2277
+ const crashPath = join6(tmpdir(), `kbdb-${contextId}.crash`);
1982
2278
  try {
1983
2279
  unlinkSync(crashPath);
1984
2280
  } catch {
@@ -2004,16 +2300,16 @@ function spawnDaemon(contextPath, runtime2, workerScript2) {
2004
2300
  }
2005
2301
 
2006
2302
  // src/shared/worker-client/functions/wait-for-daemon.function.ts
2007
- import { existsSync as existsSync5 } from "node:fs";
2008
- import { join as join6 } from "node:path";
2303
+ import { existsSync as existsSync6 } from "node:fs";
2304
+ import { join as join7 } from "node:path";
2009
2305
  import { tmpdir as tmpdir2 } from "node:os";
2010
2306
  var DEFAULT_TIMEOUT_MS = 1e4;
2011
2307
  var POLL_INTERVAL_MS = 100;
2012
2308
  async function waitForDaemon(contextId, timeoutMs = DEFAULT_TIMEOUT_MS) {
2013
- const pidPath = join6(tmpdir2(), `kbdb-${contextId}.pid`);
2309
+ const pidPath = join7(tmpdir2(), `kbdb-${contextId}.pid`);
2014
2310
  const start = Date.now();
2015
2311
  while (Date.now() - start < timeoutMs) {
2016
- if (existsSync5(pidPath)) return true;
2312
+ if (existsSync6(pidPath)) return true;
2017
2313
  await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
2018
2314
  }
2019
2315
  return false;
@@ -2041,8 +2337,8 @@ async function createWorkerClient(options) {
2041
2337
  return client;
2042
2338
  }
2043
2339
  function readCrashReason(contextId) {
2044
- const crashPath = join7(tmpdir3(), `kbdb-${contextId}.crash`);
2045
- if (!existsSync6(crashPath)) {
2340
+ const crashPath = join8(tmpdir3(), `kbdb-${contextId}.crash`);
2341
+ if (!existsSync7(crashPath)) {
2046
2342
  return "daemon failed to start (no details available)";
2047
2343
  }
2048
2344
  try {
@@ -2063,7 +2359,7 @@ function createToolDefinitions() {
2063
2359
  return [
2064
2360
  {
2065
2361
  name: "search",
2066
- description: "Search the knowledge base. Returns ranked results with headings and snippets for relevance evaluation. Use `recall` to get full content of specific results.",
2362
+ description: "Query the knowledge base by keywords. Returns ranked results with heading, snippet, and matched terms. Use multiple short keyword queries for best coverage. Use recall to get full content.",
2067
2363
  inputSchema: {
2068
2364
  type: "object",
2069
2365
  properties: {
@@ -2083,6 +2379,11 @@ function createToolDefinitions() {
2083
2379
  offset: {
2084
2380
  type: "number",
2085
2381
  description: "Number of results to skip for pagination (default: 0)"
2382
+ },
2383
+ algo: {
2384
+ type: "string",
2385
+ enum: ["lexical", "vector", "hybrid"],
2386
+ description: "Search algorithm (default: lexical)"
2086
2387
  }
2087
2388
  },
2088
2389
  required: ["query"]
@@ -2097,7 +2398,7 @@ function createToolDefinitions() {
2097
2398
  },
2098
2399
  {
2099
2400
  name: "learn",
2100
- description: "Add a text section to the knowledge base.",
2401
+ description: "Import content into the knowledge base. Use for durable facts, decisions, and corrections. Use replace when updating existing knowledge. Attach tags for scoping.",
2101
2402
  inputSchema: {
2102
2403
  type: "object",
2103
2404
  properties: {
@@ -2120,6 +2421,15 @@ function createToolDefinitions() {
2120
2421
  docid: {
2121
2422
  type: "string",
2122
2423
  description: "Document ID to group under"
2424
+ },
2425
+ tags: {
2426
+ type: "array",
2427
+ items: { type: "string" },
2428
+ description: "Tags for scoping and filtering"
2429
+ },
2430
+ replace: {
2431
+ type: "boolean",
2432
+ description: "Replace existing section with same source key (supersession)"
2123
2433
  }
2124
2434
  },
2125
2435
  required: ["content"]
@@ -2288,6 +2598,26 @@ function createToolDefinitions() {
2288
2598
  openWorldHint: false
2289
2599
  }
2290
2600
  },
2601
+ {
2602
+ name: "export",
2603
+ description: "Export the database as a self-contained directory snapshot (sections, documents, catalog -- no indexes).",
2604
+ inputSchema: {
2605
+ type: "object",
2606
+ properties: {
2607
+ path: {
2608
+ type: "string",
2609
+ description: "Export destination path (default: ./kbdb-export/)"
2610
+ }
2611
+ }
2612
+ },
2613
+ annotations: {
2614
+ title: "Export Snapshot",
2615
+ readOnlyHint: false,
2616
+ destructiveHint: false,
2617
+ idempotentHint: true,
2618
+ openWorldHint: false
2619
+ }
2620
+ },
2291
2621
  {
2292
2622
  name: "skill-learn",
2293
2623
  description: "Create or update a skill definition. Skills are reusable AI agent capabilities with template placeholders.",
@@ -2467,6 +2797,27 @@ function createToolDefinitions() {
2467
2797
  idempotentHint: true,
2468
2798
  openWorldHint: false
2469
2799
  }
2800
+ },
2801
+ {
2802
+ name: "auto-capture-review",
2803
+ description: "Review and approve pending auto-captured knowledge before storage.",
2804
+ inputSchema: {
2805
+ type: "object",
2806
+ properties: {
2807
+ action: {
2808
+ type: "string",
2809
+ enum: ["list", "approve", "reject"],
2810
+ description: "Action to perform on pending captures"
2811
+ }
2812
+ }
2813
+ },
2814
+ annotations: {
2815
+ title: "Auto-Capture Review",
2816
+ readOnlyHint: false,
2817
+ destructiveHint: false,
2818
+ idempotentHint: true,
2819
+ openWorldHint: false
2820
+ }
2470
2821
  }
2471
2822
  ];
2472
2823
  }
@@ -2540,7 +2891,7 @@ async function handleAgentCreate(client, args) {
2540
2891
  description
2541
2892
  });
2542
2893
  const allKbids = [metaResult.kbid, ...skills];
2543
- const docid = await client.groupSections(name, allKbids);
2894
+ const docid = await client.groupSections(name, allKbids, "agent");
2544
2895
  return {
2545
2896
  content: [
2546
2897
  {
@@ -2667,7 +3018,7 @@ async function handleAgentDelete(client, args) {
2667
3018
  }
2668
3019
 
2669
3020
  // src/shared/mcp/functions/handle-recall.function.ts
2670
- async function handleRecall(client, args) {
3021
+ async function handleRecall2(client, args) {
2671
3022
  const kbid = typeof args["kbid"] === "string" ? args["kbid"] : void 0;
2672
3023
  const kbids = Array.isArray(args["kbids"]) && args["kbids"].every((item) => typeof item === "string") ? args["kbids"] : void 0;
2673
3024
  if (!kbid && !kbids) {
@@ -2697,6 +3048,15 @@ async function handleRecall(client, args) {
2697
3048
  function asString2(value, fallback) {
2698
3049
  return typeof value === "string" ? value : fallback;
2699
3050
  }
3051
+ function asBooleanOrUndefined(value) {
3052
+ return typeof value === "boolean" ? value : void 0;
3053
+ }
3054
+ function asStringArrayOrUndefined(value) {
3055
+ if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
3056
+ return value;
3057
+ }
3058
+ return void 0;
3059
+ }
2700
3060
  function asStringArray2(value) {
2701
3061
  if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
2702
3062
  return value;
@@ -2715,7 +3075,7 @@ async function handleToolCall(client, name, args) {
2715
3075
  case "retrieve":
2716
3076
  return await handleRetrieve(client, args);
2717
3077
  case "recall":
2718
- return await handleRecall(client, args);
3078
+ return await handleRecall2(client, args);
2719
3079
  case "status":
2720
3080
  return await handleStatus2(client);
2721
3081
  case "content":
@@ -2726,6 +3086,8 @@ async function handleToolCall(client, name, args) {
2726
3086
  return await handleGc2(client);
2727
3087
  case "rebuild":
2728
3088
  return await handleRebuild2(client);
3089
+ case "export":
3090
+ return await handleExport2(client, args);
2729
3091
  case "skill-learn":
2730
3092
  return await handleSkillLearn(client, args);
2731
3093
  case "skill-list":
@@ -2742,6 +3104,8 @@ async function handleToolCall(client, name, args) {
2742
3104
  return await handleAgentGet(client, args);
2743
3105
  case "agent-delete":
2744
3106
  return await handleAgentDelete(client, args);
3107
+ case "auto-capture-review":
3108
+ return handleAutoCaptureReview();
2745
3109
  default:
2746
3110
  return {
2747
3111
  content: [
@@ -2770,11 +3134,18 @@ async function handleSearch2(client, args) {
2770
3134
  query: asString2(args["query"], ""),
2771
3135
  mode: args["mode"],
2772
3136
  limit: args["limit"],
2773
- offset: args["offset"]
3137
+ offset: args["offset"],
3138
+ algo: args["algo"]
2774
3139
  });
2775
3140
  const stripped = {
2776
3141
  ...results,
2777
- items: results.items.map(({ score: _score, ...rest }) => rest)
3142
+ items: results.items.map(
3143
+ ({
3144
+ score: _score,
3145
+ confidence: _confidence,
3146
+ ...rest
3147
+ }) => rest
3148
+ )
2778
3149
  };
2779
3150
  return {
2780
3151
  content: [
@@ -2790,6 +3161,8 @@ async function handleLearn2(client, args) {
2790
3161
  const title = typeof args["title"] === "string" ? args["title"] : void 0;
2791
3162
  const description = typeof args["description"] === "string" ? args["description"] : void 0;
2792
3163
  const docid = typeof args["docid"] === "string" ? args["docid"] : void 0;
3164
+ const tags = asStringArrayOrUndefined(args["tags"]);
3165
+ const replace = asBooleanOrUndefined(args["replace"]);
2793
3166
  if (sectionType.startsWith("image/") && !title) {
2794
3167
  return {
2795
3168
  content: [
@@ -2806,13 +3179,27 @@ async function handleLearn2(client, args) {
2806
3179
  content: asString2(args["content"], ""),
2807
3180
  title,
2808
3181
  description,
2809
- docid
3182
+ docid,
3183
+ tags,
3184
+ replace
2810
3185
  });
3186
+ const normalized = {
3187
+ kbid: result.kbid,
3188
+ indexed_terms_count: result.indexed_terms_count ?? 0,
3189
+ elapsed_ms: result.elapsed_ms ?? 0,
3190
+ superseded: result.superseded ?? null,
3191
+ warnings: result.warnings ?? [],
3192
+ near_duplicates: (result.near_duplicates ?? []).map((d) => ({
3193
+ kbid: d.kbid,
3194
+ similarity: d.similarity,
3195
+ ...d.method !== void 0 ? { method: d.method } : {}
3196
+ }))
3197
+ };
2811
3198
  return {
2812
3199
  content: [
2813
3200
  {
2814
3201
  type: "text",
2815
- text: JSON.stringify(result)
3202
+ text: JSON.stringify(normalized)
2816
3203
  }
2817
3204
  ]
2818
3205
  };
@@ -3053,6 +3440,33 @@ async function handleSkillDelete(client, args) {
3053
3440
  ]
3054
3441
  };
3055
3442
  }
3443
+ function handleAutoCaptureReview() {
3444
+ return {
3445
+ content: [
3446
+ {
3447
+ type: "text",
3448
+ text: JSON.stringify({
3449
+ pending: [],
3450
+ message: "No pending auto-captured knowledge entries."
3451
+ })
3452
+ }
3453
+ ]
3454
+ };
3455
+ }
3456
+ async function handleExport2(client, args) {
3457
+ const path = typeof args["path"] === "string" ? args["path"] : void 0;
3458
+ const result = await client.export(
3459
+ path !== void 0 ? { path } : {}
3460
+ );
3461
+ return {
3462
+ content: [
3463
+ {
3464
+ type: "text",
3465
+ text: JSON.stringify(result)
3466
+ }
3467
+ ]
3468
+ };
3469
+ }
3056
3470
 
3057
3471
  // src/shared/mcp/functions/handle-resource-read.function.ts
3058
3472
  async function handleResourceRead(client, uri) {
@@ -3149,8 +3563,12 @@ function buildSkillsText(skillSections) {
3149
3563
  ${lines.join("\n")}`;
3150
3564
  }
3151
3565
  async function handleAgentPrompt(name, client) {
3152
- const docid = name.slice(6);
3153
- const doc = await client.retrieveDocument(docid);
3566
+ const agentName = name.slice(6);
3567
+ const agents = await client.listDocumentsByType("agent");
3568
+ const doc = agents.find((a) => a.title === agentName);
3569
+ if (!doc) {
3570
+ throw new Error("agent not found: " + agentName);
3571
+ }
3154
3572
  const sections = doc.sections;
3155
3573
  const metaSection = sections.at(0);
3156
3574
  const skillRefs = sections.slice(1);
@@ -3308,13 +3726,16 @@ var McpServer = class {
3308
3726
  input: process.stdin,
3309
3727
  terminal: false
3310
3728
  });
3729
+ let pending = Promise.resolve();
3311
3730
  await new Promise((resolve4) => {
3312
3731
  rl.on("line", (line) => {
3313
- void this.dispatchLine(line);
3732
+ pending = pending.then(() => this.dispatchLine(line));
3314
3733
  });
3315
3734
  rl.on("close", () => {
3316
- this.client.disconnect();
3317
- resolve4();
3735
+ void pending.then(() => {
3736
+ this.client.disconnect();
3737
+ resolve4();
3738
+ });
3318
3739
  });
3319
3740
  });
3320
3741
  }
@@ -3424,8 +3845,9 @@ var McpServer = class {
3424
3845
  const request = parsed;
3425
3846
  if (request.id === void 0) {
3426
3847
  if (request.method === "notifications/initialized" || request.method === "notifications/cancelled") {
3427
- if (request.method === "notifications/initialized") {
3848
+ if (request.method === "notifications/initialized" && !this.initialized) {
3428
3849
  this.initialized = true;
3850
+ void this.runStartupHealthCheck();
3429
3851
  }
3430
3852
  }
3431
3853
  return null;
@@ -3618,6 +4040,27 @@ var McpServer = class {
3618
4040
  const json = JSON.stringify(response);
3619
4041
  process.stdout.write(json + "\n");
3620
4042
  }
4043
+ /**
4044
+ * Runs an integrity check immediately after the MCP handshake
4045
+ * completes. Emits a `notifications/message` warning when the
4046
+ * check detects issues so the connected agent is aware before
4047
+ * making requests. The server continues operating regardless of
4048
+ * the result.
4049
+ */
4050
+ async runStartupHealthCheck() {
4051
+ try {
4052
+ const report = await this.client.integrityCheck();
4053
+ if (!report.ok) {
4054
+ const summary = report.errors.map((e) => `${e.type}: ${e.entity} -- ${e.detail}`).join("; ");
4055
+ this.notify("notifications/message", {
4056
+ level: "warning",
4057
+ logger: "kbdb",
4058
+ data: `Database integrity issues detected: ${summary}`
4059
+ });
4060
+ }
4061
+ } catch {
4062
+ }
4063
+ }
3621
4064
  };
3622
4065
 
3623
4066
  // src/shared/mcp/functions/create-mcp-server.function.ts