@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.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;
@@ -146,6 +149,19 @@ function parseArgs(argv) {
146
149
  case "--skills":
147
150
  options.skills = (argv[++i] ?? "").split(",");
148
151
  break;
152
+ case "--tags":
153
+ options.tags = (argv[++i] ?? "").split(",");
154
+ break;
155
+ case "--replace":
156
+ options.replace = true;
157
+ break;
158
+ case "--depth":
159
+ case "-d":
160
+ options.depth = Math.min(
161
+ 3,
162
+ Math.max(0, parseInt(argv[++i] ?? "", 10) || 0)
163
+ );
164
+ break;
149
165
  case "--content":
150
166
  case "-c":
151
167
  options.content = true;
@@ -183,9 +199,11 @@ function formatText(paged) {
183
199
  const num = paged.offset + i + 1;
184
200
  const heading = r.heading ?? "(untitled)";
185
201
  const terms = r.matched_terms.join(", ");
186
- return `${String(num)}. [${r.kbid}] ${heading} (score: ${r.score.toFixed(4)})
202
+ const fields = r.matched_fields.join(", ");
203
+ const confidencePct = (r.confidence * 100).toFixed(0);
204
+ return `${String(num)}. [${r.kbid}] ${heading} (score: ${r.score.toFixed(4)}, confidence: ${confidencePct}%)
187
205
  ${r.snippet || r.preview || "(no snippet)"}
188
- type: ${r.type} terms: ${terms}`;
206
+ type: ${r.type} terms: ${terms}` + (fields ? ` fields: ${fields}` : "");
189
207
  }).join("\n\n");
190
208
  const footer = `
191
209
  Showing ${String(start)}-${String(end)} of ${String(paged.total)} results`;
@@ -194,12 +212,32 @@ Use --offset ${String(end)} to see more` : "";
194
212
  return lines + footer + hint;
195
213
  }
196
214
  function formatMcp(paged) {
197
- return JSON.stringify({
198
- type: "text",
199
- text: paged.items.map(
200
- (r) => `[${r.kbid}] ${r.heading ?? "(untitled)"} \u2014 ${r.snippet || r.preview}`
201
- ).join("\n")
202
- });
215
+ const mcpItems = paged.items.map((r) => ({
216
+ kbid: r.kbid,
217
+ heading: r.heading,
218
+ type: r.type,
219
+ docids: r.docids,
220
+ snippet: r.snippet,
221
+ matched_terms: r.matched_terms,
222
+ matched_fields: r.matched_fields,
223
+ created_at: r.created_at
224
+ }));
225
+ return JSON.stringify(
226
+ {
227
+ type: "text",
228
+ text: paged.items.map(
229
+ (r) => `[${r.kbid}] ${r.heading ?? "(untitled)"} \u2014 ${r.snippet || r.preview}`
230
+ ).join("\n"),
231
+ items: mcpItems,
232
+ total: paged.total,
233
+ offset: paged.offset,
234
+ limit: paged.limit,
235
+ has_more: paged.has_more,
236
+ relaxed: paged.relaxed
237
+ },
238
+ null,
239
+ 2
240
+ );
203
241
  }
204
242
 
205
243
  // src/shared/cli/functions/run-search.function.ts
@@ -211,14 +249,16 @@ async function runSearch(client, options) {
211
249
  total: 0,
212
250
  offset: 0,
213
251
  limit: options.limit,
214
- has_more: false
252
+ has_more: false,
253
+ relaxed: false
215
254
  };
216
255
  }
217
256
  const results = await client.search({
218
257
  query,
219
258
  mode: options.mode,
220
259
  limit: options.limit,
221
- offset: options.offset
260
+ offset: options.offset,
261
+ algo: options.algo
222
262
  });
223
263
  return {
224
264
  items: results.items.map((r) => ({
@@ -227,17 +267,43 @@ async function runSearch(client, options) {
227
267
  type: r.type,
228
268
  docids: r.docids,
229
269
  score: r.score,
270
+ confidence: r.confidence ?? 0,
230
271
  snippet: r.snippet,
231
272
  matched_terms: r.matched_terms,
273
+ matched_fields: r.matched_fields ?? [],
274
+ created_at: r.created_at ?? "",
232
275
  preview: ""
233
276
  })),
234
277
  total: results.total,
235
278
  offset: results.offset,
236
279
  limit: results.limit,
237
- has_more: results.has_more
280
+ has_more: results.has_more,
281
+ relaxed: results.relaxed ?? false
238
282
  };
239
283
  }
240
284
 
285
+ // src/shared/cli/functions/run-recall.function.ts
286
+ var MAX_RECALL_DEPTH = 3;
287
+ async function runRecall(client, options) {
288
+ if (options.args.length === 0) {
289
+ return { error: "no kbid provided" };
290
+ }
291
+ const depth = Math.min(
292
+ MAX_RECALL_DEPTH,
293
+ Math.max(0, options.depth ?? 0)
294
+ );
295
+ if (options.args.length === 1) {
296
+ return client.recall({ kbid: options.args[0], depth });
297
+ }
298
+ return client.recall({ kbids: options.args, depth });
299
+ }
300
+
301
+ // src/shared/cli/functions/run-export.function.ts
302
+ async function runExport(client, options) {
303
+ const path = options.args[0];
304
+ return client.export({ path });
305
+ }
306
+
241
307
  // src/shared/cli/functions/run-learn.function.ts
242
308
  var import_node_fs = require("node:fs");
243
309
  var import_node_path3 = require("node:path");
@@ -255,14 +321,11 @@ async function runLearn(client, options, io) {
255
321
  content,
256
322
  title: options.title,
257
323
  description: options.description,
258
- docid: options.docid
259
- });
260
- results.push({
261
- kbid: result.kbid,
262
- path: "-",
263
- size: content.length,
264
- skipped: false
324
+ docid: options.docid,
325
+ tags: options.tags,
326
+ replace: options.replace
265
327
  });
328
+ results.push(mapAddSectionResult(result, "-", content.length));
266
329
  continue;
267
330
  }
268
331
  const files = collectFiles(target);
@@ -272,18 +335,30 @@ async function runLearn(client, options, io) {
272
335
  sectionType: "text",
273
336
  content,
274
337
  title: options.title,
275
- docid: options.docid
276
- });
277
- results.push({
278
- kbid: result.kbid,
279
- path: file,
280
- size: content.length,
281
- skipped: false
338
+ description: options.description,
339
+ docid: options.docid,
340
+ tags: options.tags,
341
+ replace: options.replace,
342
+ sourcePath: file
282
343
  });
344
+ results.push(
345
+ mapAddSectionResult(result, file, content.length)
346
+ );
283
347
  }
284
348
  }
285
349
  return results;
286
350
  }
351
+ function mapAddSectionResult(result, path, size) {
352
+ return {
353
+ kbid: result.kbid,
354
+ path,
355
+ size,
356
+ skipped: false,
357
+ superseded: result.superseded ?? null,
358
+ warnings: result.warnings ?? [],
359
+ near_duplicates: result.near_duplicates ?? []
360
+ };
361
+ }
287
362
  function readProcessStdin() {
288
363
  return new Promise((resolve4) => {
289
364
  const chunks = [];
@@ -348,8 +423,26 @@ async function runContent(client, options) {
348
423
  }
349
424
 
350
425
  // src/shared/cli/functions/run-check.function.ts
426
+ function parseDivergentContent(encoded) {
427
+ if (!encoded) return [];
428
+ return encoded.split(";").filter((segment) => segment.includes(":")).map((segment) => {
429
+ const colonIdx = segment.indexOf(":");
430
+ const sourceKey = segment.slice(0, colonIdx);
431
+ const kbids = segment.slice(colonIdx + 1).split(",").filter((k) => k.length > 0);
432
+ return { sourceKey, kbids };
433
+ }).filter((entry) => entry.kbids.length > 0);
434
+ }
351
435
  async function runCheck(client, _options) {
352
- return client.integrityCheck();
436
+ const raw = await client.integrityCheck();
437
+ return {
438
+ ok: raw.ok,
439
+ errors: raw.errors,
440
+ sections_checked: raw.sections_checked,
441
+ documents_checked: raw.documents_checked,
442
+ references_checked: raw.references_checked,
443
+ elapsed_ms: raw.elapsed_ms,
444
+ divergent_content: parseDivergentContent(raw.divergent_content)
445
+ };
353
446
  }
354
447
 
355
448
  // src/shared/cli/functions/run-gc.function.ts
@@ -372,8 +465,109 @@ function findDb(dbPath) {
372
465
  }
373
466
 
374
467
  // src/shared/cli/functions/run-init.function.ts
468
+ var import_node_fs4 = require("node:fs");
469
+ var import_node_path6 = require("node:path");
470
+
471
+ // src/shared/cli/functions/install-default-skills.function.ts
472
+ var import_node_crypto = require("node:crypto");
375
473
  var import_node_fs3 = require("node:fs");
376
474
  var import_node_path5 = require("node:path");
475
+ var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
476
+ function base32Encode(bytes) {
477
+ let result = "";
478
+ let bits = 0;
479
+ let value = 0;
480
+ for (const byte of bytes) {
481
+ value = value << 8 | byte;
482
+ bits += 8;
483
+ while (bits >= 5) {
484
+ result += BASE32_ALPHABET[value >>> bits - 5 & 31];
485
+ bits -= 5;
486
+ }
487
+ }
488
+ if (bits > 0) {
489
+ result += BASE32_ALPHABET[value << 5 - bits & 31];
490
+ }
491
+ return result.toLowerCase();
492
+ }
493
+ function computeSectionKbid(mimeType, content) {
494
+ const contentBytes = Buffer.from(content, "utf-8");
495
+ const header = `section ${mimeType} ${contentBytes.length.toString()}\0`;
496
+ const headerBytes = Buffer.from(header, "utf-8");
497
+ const input = Buffer.concat([headerBytes, contentBytes]);
498
+ const hash = (0, import_node_crypto.createHash)("sha256").update(input).digest();
499
+ const truncated = new Uint8Array(hash.buffer, 0, 16);
500
+ return base32Encode(truncated);
501
+ }
502
+ function escapeToml(s) {
503
+ return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
504
+ }
505
+ function serializeSkillSection(kbid, title, description, content) {
506
+ const size = Buffer.byteLength(content, "utf-8");
507
+ const header = [
508
+ `kbid = "${escapeToml(kbid)}"`,
509
+ `section_type = "text/markdown"`,
510
+ `type_name = "skill"`,
511
+ `title = "${escapeToml(title)}"`,
512
+ `description = "${escapeToml(description)}"`,
513
+ `size = ${size.toString()}`,
514
+ `token_count = 0`,
515
+ `heading_token_count = 0`,
516
+ `body_token_count = 0`,
517
+ `code_token_count = 0`,
518
+ `created_at = 0`,
519
+ `checksum = "${escapeToml(kbid)}"`,
520
+ ""
521
+ ].join("\n");
522
+ return `${header}
523
+ ---
524
+ ${content}`;
525
+ }
526
+ function installSkill(sectionsDir, skill) {
527
+ const content = JSON.stringify({
528
+ name: skill.name,
529
+ description: skill.description,
530
+ arguments: [],
531
+ body: skill.body
532
+ });
533
+ const kbid = computeSectionKbid("text/markdown", content);
534
+ const prefix = kbid.slice(0, 2);
535
+ const shardDir = (0, import_node_path5.join)(sectionsDir, prefix);
536
+ const filePath = (0, import_node_path5.join)(shardDir, `${kbid}.section`);
537
+ if ((0, import_node_fs3.existsSync)(filePath)) {
538
+ return;
539
+ }
540
+ (0, import_node_fs3.mkdirSync)(shardDir, { recursive: true });
541
+ const fileContent = serializeSkillSection(
542
+ kbid,
543
+ skill.name,
544
+ skill.description,
545
+ content
546
+ );
547
+ (0, import_node_fs3.writeFileSync)(filePath, fileContent, "utf-8");
548
+ }
549
+ 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.';
550
+ 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.";
551
+ var DEFAULT_SKILLS = [
552
+ {
553
+ name: "query-guidance",
554
+ description: "How to effectively search this knowledge base. Read this before issuing search queries.",
555
+ body: QUERY_GUIDANCE_BODY
556
+ },
557
+ {
558
+ name: "memory-protocol",
559
+ description: "Guidelines for what to store in this knowledge base and when. Read this before using the learn tool.",
560
+ body: MEMORY_PROTOCOL_BODY
561
+ }
562
+ ];
563
+ function installDefaultSkills(dbDir) {
564
+ const sectionsDir = (0, import_node_path5.join)(dbDir, "sections");
565
+ for (const skill of DEFAULT_SKILLS) {
566
+ installSkill(sectionsDir, skill);
567
+ }
568
+ }
569
+
570
+ // src/shared/cli/functions/run-init.function.ts
377
571
  var DB_FORMAT_VERSION = 1;
378
572
  var CATALOG_TOML = `version = ${DB_FORMAT_VERSION.toString()}
379
573
  section_count = 0
@@ -391,21 +585,21 @@ var GITIGNORE = [
391
585
  ""
392
586
  ].join("\n");
393
587
  function createScaffold(dbDir) {
394
- (0, import_node_fs3.mkdirSync)(dbDir, { recursive: true });
395
- (0, import_node_fs3.mkdirSync)((0, import_node_path5.join)(dbDir, "sections"));
396
- (0, import_node_fs3.mkdirSync)((0, import_node_path5.join)(dbDir, "documents"));
397
- (0, import_node_fs3.writeFileSync)((0, import_node_path5.join)(dbDir, "catalog.toml"), CATALOG_TOML);
398
- (0, import_node_fs3.writeFileSync)((0, import_node_path5.join)(dbDir, "corpus.bin"), "");
399
- (0, import_node_fs3.writeFileSync)((0, import_node_path5.join)(dbDir, "inverted.idx"), "");
400
- (0, import_node_fs3.writeFileSync)((0, import_node_path5.join)(dbDir, "positional.idx"), "");
401
- (0, import_node_fs3.writeFileSync)((0, import_node_path5.join)(dbDir, "worker.toml"), WORKER_TOML);
402
- (0, import_node_fs3.writeFileSync)((0, import_node_path5.join)(dbDir, ".gitignore"), GITIGNORE);
588
+ (0, import_node_fs4.mkdirSync)(dbDir, { recursive: true });
589
+ (0, import_node_fs4.mkdirSync)((0, import_node_path6.join)(dbDir, "sections"));
590
+ (0, import_node_fs4.mkdirSync)((0, import_node_path6.join)(dbDir, "documents"));
591
+ (0, import_node_fs4.writeFileSync)((0, import_node_path6.join)(dbDir, "catalog.toml"), CATALOG_TOML);
592
+ (0, import_node_fs4.writeFileSync)((0, import_node_path6.join)(dbDir, "corpus.bin"), "");
593
+ (0, import_node_fs4.writeFileSync)((0, import_node_path6.join)(dbDir, "inverted.idx"), "");
594
+ (0, import_node_fs4.writeFileSync)((0, import_node_path6.join)(dbDir, "positional.idx"), "");
595
+ (0, import_node_fs4.writeFileSync)((0, import_node_path6.join)(dbDir, "worker.toml"), WORKER_TOML);
596
+ (0, import_node_fs4.writeFileSync)((0, import_node_path6.join)(dbDir, ".gitignore"), GITIGNORE);
403
597
  }
404
598
  function runInit(options) {
405
- const basePath = options.dbPath ? (0, import_node_path5.resolve)(options.dbPath) : process.cwd();
406
- const dbDir = (0, import_node_path5.join)(basePath, ".kbdb");
599
+ const basePath = options.dbPath ? (0, import_node_path6.resolve)(options.dbPath) : process.cwd();
600
+ const dbDir = (0, import_node_path6.join)(basePath, ".kbdb");
407
601
  try {
408
- if ((0, import_node_fs3.existsSync)(dbDir)) {
602
+ if ((0, import_node_fs4.existsSync)(dbDir)) {
409
603
  return {
410
604
  ok: false,
411
605
  targetPath: dbDir,
@@ -413,6 +607,7 @@ function runInit(options) {
413
607
  };
414
608
  }
415
609
  createScaffold(dbDir);
610
+ installDefaultSkills(dbDir);
416
611
  return { ok: true, targetPath: dbDir };
417
612
  } catch (err) {
418
613
  const errorMessage = err instanceof Error ? err.message : String(err);
@@ -770,6 +965,8 @@ async function dispatchCommand(client, options, io) {
770
965
  return handleUnlearn(client, options);
771
966
  case "search":
772
967
  return handleSearch(client, options);
968
+ case "recall":
969
+ return handleRecall(client, options);
773
970
  case "content":
774
971
  return handleContent(client, options);
775
972
  case "check":
@@ -780,6 +977,8 @@ async function dispatchCommand(client, options, io) {
780
977
  return handleRebuild(client, options);
781
978
  case "status":
782
979
  return handleStatus(client, options);
980
+ case "export":
981
+ return handleExport(client, options);
783
982
  case "db-init":
784
983
  return handleDbInit(options);
785
984
  case "db-migrate":
@@ -868,6 +1067,40 @@ async function handleSearch(client, options) {
868
1067
  };
869
1068
  }
870
1069
  }
1070
+ async function handleRecall(client, options) {
1071
+ try {
1072
+ const result = await runRecall(client, options);
1073
+ if ("error" in result) {
1074
+ return {
1075
+ error: `error: ${result.error}`,
1076
+ exitCode: 1
1077
+ };
1078
+ }
1079
+ return {
1080
+ output: JSON.stringify(result, null, 2),
1081
+ exitCode: 0
1082
+ };
1083
+ } catch (err) {
1084
+ return {
1085
+ error: `recall failed: ${errorToMessage(err)}`,
1086
+ exitCode: 1
1087
+ };
1088
+ }
1089
+ }
1090
+ async function handleExport(client, options) {
1091
+ try {
1092
+ const result = await runExport(client, options);
1093
+ return {
1094
+ output: JSON.stringify(result, null, 2),
1095
+ exitCode: 0
1096
+ };
1097
+ } catch (err) {
1098
+ return {
1099
+ error: `export failed: ${errorToMessage(err)}`,
1100
+ exitCode: 1
1101
+ };
1102
+ }
1103
+ }
871
1104
  async function handleContent(client, options) {
872
1105
  try {
873
1106
  const result = await runContent(client, options);
@@ -975,11 +1208,13 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
975
1208
  "learn",
976
1209
  "unlearn",
977
1210
  "search",
1211
+ "recall",
978
1212
  "content",
979
1213
  "check",
980
1214
  "gc",
981
1215
  "rebuild",
982
1216
  "status",
1217
+ "export",
983
1218
  "mcp",
984
1219
  "db",
985
1220
  "skill",
@@ -1042,6 +1277,7 @@ Knowledge Base:
1042
1277
  learn Import content from files/stdin
1043
1278
  unlearn Remove sections by kbid
1044
1279
  search Query the knowledge base
1280
+ recall Retrieve section context by kbid
1045
1281
  content Compose rendered content from ids
1046
1282
 
1047
1283
  Database:
@@ -1054,6 +1290,7 @@ Maintenance:
1054
1290
  sections
1055
1291
  rebuild Reconstruct all index files
1056
1292
  status Show database status
1293
+ export Snapshot database for backup
1057
1294
 
1058
1295
  Skills:
1059
1296
  skill learn Create a new skill definition
@@ -1126,14 +1363,18 @@ Options:
1126
1363
  --title <title> Section title
1127
1364
  --description <d> Section description
1128
1365
  --docid <docid> Document ID to group under
1366
+ --tags <t,...> Comma-separated tags
1367
+ --replace Supersede existing section by source key
1129
1368
  --db <path> Path to .kbdb directory
1130
1369
 
1131
1370
  Output:
1132
- JSON array of { kbid, path, size, skipped }
1371
+ JSON array of { kbid, path, size, skipped,
1372
+ superseded, warnings, near_duplicates }
1133
1373
 
1134
1374
  Examples:
1135
1375
  kbdb learn README.md
1136
1376
  kbdb learn ./docs/
1377
+ kbdb learn --tags auth,api --replace doc.md
1137
1378
  cat notes.txt | kbdb learn -
1138
1379
  `,
1139
1380
  unlearn: `kbdb unlearn - Remove sections by kbid
@@ -1174,6 +1415,25 @@ Examples:
1174
1415
  kbdb search "machine learning"
1175
1416
  kbdb search --limit 5 --format text query
1176
1417
  kbdb search --mode documents --content term
1418
+ `,
1419
+ recall: `kbdb recall - Retrieve section context by kbid
1420
+
1421
+ Usage: kbdb recall [options] <kbid>...
1422
+
1423
+ Arguments:
1424
+ <kbid> 26-character knowledge base identifier
1425
+
1426
+ Options:
1427
+ --depth <n>, -d Expansion depth (0-3, default: 0)
1428
+ --tags <t,...> Filter by tags
1429
+ --db <path> Path to .kbdb directory
1430
+
1431
+ Output:
1432
+ JSON RecallResult or RecallResult[]
1433
+
1434
+ Examples:
1435
+ kbdb recall abcdef1234567890abcdef1234
1436
+ kbdb recall kbid1 --depth 2
1177
1437
  `,
1178
1438
  content: `kbdb content - Compose rendered content from ids
1179
1439
 
@@ -1247,6 +1507,25 @@ Output:
1247
1507
  Examples:
1248
1508
  kbdb status
1249
1509
  kbdb status --db /path/to/project
1510
+ `,
1511
+ export: `kbdb export - Snapshot database for backup
1512
+
1513
+ Usage: kbdb export [options] [<path>]
1514
+
1515
+ Arguments:
1516
+ <path> Output directory path
1517
+ (default: ./kbdb-export/)
1518
+
1519
+ Options:
1520
+ --db <path> Path to .kbdb directory
1521
+
1522
+ Output:
1523
+ JSON { path, sections_exported, documents_exported }
1524
+
1525
+ Examples:
1526
+ kbdb export
1527
+ kbdb export ./my-backup
1528
+ kbdb export --db /path/to/project
1250
1529
  `,
1251
1530
  mcp: `kbdb mcp - Start MCP server mode (stdio)
1252
1531
 
@@ -1917,6 +2196,23 @@ var WorkerClient = class {
1917
2196
  docType
1918
2197
  });
1919
2198
  }
2199
+ /**
2200
+ * Exports the database to a target directory on disk.
2201
+ *
2202
+ * Copies section files, document manifests, and `catalog.toml`
2203
+ * to `params.path`. Index files are not exported because they
2204
+ * are derivable from the section and document data.
2205
+ *
2206
+ * @param params - optional export parameters
2207
+ * @param params.path - target directory path; defaults to
2208
+ * `./kbdb-export/` when not provided
2209
+ * @returns export report with the resolved path and file counts
2210
+ */
2211
+ async export(params) {
2212
+ return this.call("export", {
2213
+ targetPath: params?.path || void 0
2214
+ });
2215
+ }
1920
2216
  /**
1921
2217
  * Sends a JSON-RPC 2.0 request and awaits the response.
1922
2218
  *
@@ -1974,17 +2270,17 @@ var WorkerClient = class {
1974
2270
  };
1975
2271
 
1976
2272
  // src/shared/worker-client/functions/create-worker-client.function.ts
1977
- var import_node_fs7 = require("node:fs");
1978
- var import_node_path10 = require("node:path");
2273
+ var import_node_fs8 = require("node:fs");
2274
+ var import_node_path11 = require("node:path");
1979
2275
  var import_node_os4 = require("node:os");
1980
2276
 
1981
2277
  // src/shared/worker-client/functions/resolve-db-path.function.ts
1982
- var import_node_fs4 = require("node:fs");
1983
- var import_node_path6 = require("node:path");
2278
+ var import_node_fs5 = require("node:fs");
2279
+ var import_node_path7 = require("node:path");
1984
2280
  function resolveDbPath(targetDir) {
1985
- const base = targetDir ? (0, import_node_path6.resolve)(targetDir) : process.cwd();
1986
- const dbPath = (0, import_node_path6.join)(base, ".kbdb");
1987
- if (!(0, import_node_fs4.existsSync)(dbPath)) {
2281
+ const base = targetDir ? (0, import_node_path7.resolve)(targetDir) : process.cwd();
2282
+ const dbPath = (0, import_node_path7.join)(base, ".kbdb");
2283
+ if (!(0, import_node_fs5.existsSync)(dbPath)) {
1988
2284
  throw new Error(`database not found: ${dbPath}`);
1989
2285
  }
1990
2286
  return dbPath;
@@ -2005,8 +2301,8 @@ async function computeContextId(absolutePath) {
2005
2301
  }
2006
2302
 
2007
2303
  // src/shared/worker-client/functions/discover-daemon.function.ts
2008
- var import_node_fs5 = require("node:fs");
2009
- var import_node_path7 = require("node:path");
2304
+ var import_node_fs6 = require("node:fs");
2305
+ var import_node_path8 = require("node:path");
2010
2306
  var import_node_os = require("node:os");
2011
2307
 
2012
2308
  // src/shared/platform/functions/is-process-alive.function.ts
@@ -2021,21 +2317,21 @@ function isProcessAlive(pid) {
2021
2317
 
2022
2318
  // src/shared/worker-client/functions/discover-daemon.function.ts
2023
2319
  function discoverDaemon(contextId) {
2024
- const pidPath = (0, import_node_path7.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.pid`);
2025
- if (!(0, import_node_fs5.existsSync)(pidPath)) return null;
2026
- const pidStr = (0, import_node_fs5.readFileSync)(pidPath, "utf-8").trim();
2320
+ const pidPath = (0, import_node_path8.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.pid`);
2321
+ if (!(0, import_node_fs6.existsSync)(pidPath)) return null;
2322
+ const pidStr = (0, import_node_fs6.readFileSync)(pidPath, "utf-8").trim();
2027
2323
  const pid = parseInt(pidStr, 10);
2028
2324
  if (isNaN(pid) || !isProcessAlive(pid)) {
2029
2325
  try {
2030
- (0, import_node_fs5.unlinkSync)(pidPath);
2326
+ (0, import_node_fs6.unlinkSync)(pidPath);
2031
2327
  } catch {
2032
2328
  }
2033
2329
  return null;
2034
2330
  }
2035
- const socketPath = (0, import_node_path7.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.sock`);
2036
- const crashPath = (0, import_node_path7.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.crash`);
2331
+ const socketPath = (0, import_node_path8.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.sock`);
2332
+ const crashPath = (0, import_node_path8.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.crash`);
2037
2333
  try {
2038
- (0, import_node_fs5.unlinkSync)(crashPath);
2334
+ (0, import_node_fs6.unlinkSync)(crashPath);
2039
2335
  } catch {
2040
2336
  }
2041
2337
  return { pid, socketPath };
@@ -2059,23 +2355,23 @@ function spawnDaemon(contextPath, runtime2, workerScript2) {
2059
2355
  }
2060
2356
 
2061
2357
  // src/shared/worker-client/functions/wait-for-daemon.function.ts
2062
- var import_node_fs6 = require("node:fs");
2063
- var import_node_path8 = require("node:path");
2358
+ var import_node_fs7 = require("node:fs");
2359
+ var import_node_path9 = require("node:path");
2064
2360
  var import_node_os2 = require("node:os");
2065
2361
  var DEFAULT_TIMEOUT_MS = 1e4;
2066
2362
  var POLL_INTERVAL_MS = 100;
2067
2363
  async function waitForDaemon(contextId, timeoutMs = DEFAULT_TIMEOUT_MS) {
2068
- const pidPath = (0, import_node_path8.join)((0, import_node_os2.tmpdir)(), `kbdb-${contextId}.pid`);
2364
+ const pidPath = (0, import_node_path9.join)((0, import_node_os2.tmpdir)(), `kbdb-${contextId}.pid`);
2069
2365
  const start = Date.now();
2070
2366
  while (Date.now() - start < timeoutMs) {
2071
- if ((0, import_node_fs6.existsSync)(pidPath)) return true;
2367
+ if ((0, import_node_fs7.existsSync)(pidPath)) return true;
2072
2368
  await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
2073
2369
  }
2074
2370
  return false;
2075
2371
  }
2076
2372
 
2077
2373
  // src/shared/platform/functions/get-ipc-path.function.ts
2078
- var import_node_path9 = require("node:path");
2374
+ var import_node_path10 = require("node:path");
2079
2375
 
2080
2376
  // src/shared/platform/functions/get-tmpdir.function.ts
2081
2377
  var import_node_os3 = require("node:os");
@@ -2088,7 +2384,7 @@ function getIpcPath(ctx) {
2088
2384
  if (process.platform === "win32") {
2089
2385
  return `\\\\.\\pipe\\kbdb-${ctx}`;
2090
2386
  }
2091
- return (0, import_node_path9.join)(getTmpdir(), `kbdb-${ctx}.sock`);
2387
+ return (0, import_node_path10.join)(getTmpdir(), `kbdb-${ctx}.sock`);
2092
2388
  }
2093
2389
 
2094
2390
  // src/shared/worker-client/functions/create-worker-client.function.ts
@@ -2113,14 +2409,14 @@ async function createWorkerClient(options) {
2113
2409
  return client;
2114
2410
  }
2115
2411
  function readCrashReason(contextId) {
2116
- const crashPath = (0, import_node_path10.join)((0, import_node_os4.tmpdir)(), `kbdb-${contextId}.crash`);
2117
- if (!(0, import_node_fs7.existsSync)(crashPath)) {
2412
+ const crashPath = (0, import_node_path11.join)((0, import_node_os4.tmpdir)(), `kbdb-${contextId}.crash`);
2413
+ if (!(0, import_node_fs8.existsSync)(crashPath)) {
2118
2414
  return "daemon failed to start (no details available)";
2119
2415
  }
2120
2416
  try {
2121
- const raw = (0, import_node_fs7.readFileSync)(crashPath, "utf-8");
2417
+ const raw = (0, import_node_fs8.readFileSync)(crashPath, "utf-8");
2122
2418
  const crash = JSON.parse(raw);
2123
- (0, import_node_fs7.unlinkSync)(crashPath);
2419
+ (0, import_node_fs8.unlinkSync)(crashPath);
2124
2420
  return crash.error ?? "unknown error (crash log empty)";
2125
2421
  } catch {
2126
2422
  return "daemon failed to start (crash log unreadable)";
@@ -2135,7 +2431,7 @@ function createToolDefinitions() {
2135
2431
  return [
2136
2432
  {
2137
2433
  name: "search",
2138
- description: "Search the knowledge base. Returns ranked results with headings and snippets for relevance evaluation. Use `recall` to get full content of specific results.",
2434
+ 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.",
2139
2435
  inputSchema: {
2140
2436
  type: "object",
2141
2437
  properties: {
@@ -2155,6 +2451,11 @@ function createToolDefinitions() {
2155
2451
  offset: {
2156
2452
  type: "number",
2157
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)"
2158
2459
  }
2159
2460
  },
2160
2461
  required: ["query"]
@@ -2169,7 +2470,7 @@ function createToolDefinitions() {
2169
2470
  },
2170
2471
  {
2171
2472
  name: "learn",
2172
- description: "Add a text section to the knowledge base.",
2473
+ description: "Import content into the knowledge base. Use for durable facts, decisions, and corrections. Use replace when updating existing knowledge. Attach tags for scoping.",
2173
2474
  inputSchema: {
2174
2475
  type: "object",
2175
2476
  properties: {
@@ -2192,6 +2493,15 @@ function createToolDefinitions() {
2192
2493
  docid: {
2193
2494
  type: "string",
2194
2495
  description: "Document ID to group under"
2496
+ },
2497
+ tags: {
2498
+ type: "array",
2499
+ items: { type: "string" },
2500
+ description: "Tags for scoping and filtering"
2501
+ },
2502
+ replace: {
2503
+ type: "boolean",
2504
+ description: "Replace existing section with same source key (supersession)"
2195
2505
  }
2196
2506
  },
2197
2507
  required: ["content"]
@@ -2360,6 +2670,26 @@ function createToolDefinitions() {
2360
2670
  openWorldHint: false
2361
2671
  }
2362
2672
  },
2673
+ {
2674
+ name: "export",
2675
+ description: "Export the database as a self-contained directory snapshot (sections, documents, catalog -- no indexes).",
2676
+ inputSchema: {
2677
+ type: "object",
2678
+ properties: {
2679
+ path: {
2680
+ type: "string",
2681
+ description: "Export destination path (default: ./kbdb-export/)"
2682
+ }
2683
+ }
2684
+ },
2685
+ annotations: {
2686
+ title: "Export Snapshot",
2687
+ readOnlyHint: false,
2688
+ destructiveHint: false,
2689
+ idempotentHint: true,
2690
+ openWorldHint: false
2691
+ }
2692
+ },
2363
2693
  {
2364
2694
  name: "skill-learn",
2365
2695
  description: "Create or update a skill definition. Skills are reusable AI agent capabilities with template placeholders.",
@@ -2539,6 +2869,27 @@ function createToolDefinitions() {
2539
2869
  idempotentHint: true,
2540
2870
  openWorldHint: false
2541
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
+ }
2542
2893
  }
2543
2894
  ];
2544
2895
  }
@@ -2612,7 +2963,7 @@ async function handleAgentCreate(client, args) {
2612
2963
  description
2613
2964
  });
2614
2965
  const allKbids = [metaResult.kbid, ...skills];
2615
- const docid = await client.groupSections(name, allKbids);
2966
+ const docid = await client.groupSections(name, allKbids, "agent");
2616
2967
  return {
2617
2968
  content: [
2618
2969
  {
@@ -2739,7 +3090,7 @@ async function handleAgentDelete(client, args) {
2739
3090
  }
2740
3091
 
2741
3092
  // src/shared/mcp/functions/handle-recall.function.ts
2742
- async function handleRecall(client, args) {
3093
+ async function handleRecall2(client, args) {
2743
3094
  const kbid = typeof args["kbid"] === "string" ? args["kbid"] : void 0;
2744
3095
  const kbids = Array.isArray(args["kbids"]) && args["kbids"].every((item) => typeof item === "string") ? args["kbids"] : void 0;
2745
3096
  if (!kbid && !kbids) {
@@ -2769,6 +3120,15 @@ async function handleRecall(client, args) {
2769
3120
  function asString2(value, fallback) {
2770
3121
  return typeof value === "string" ? value : fallback;
2771
3122
  }
3123
+ function asBooleanOrUndefined(value) {
3124
+ return typeof value === "boolean" ? value : void 0;
3125
+ }
3126
+ function asStringArrayOrUndefined(value) {
3127
+ if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
3128
+ return value;
3129
+ }
3130
+ return void 0;
3131
+ }
2772
3132
  function asStringArray2(value) {
2773
3133
  if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
2774
3134
  return value;
@@ -2787,7 +3147,7 @@ async function handleToolCall(client, name, args) {
2787
3147
  case "retrieve":
2788
3148
  return await handleRetrieve(client, args);
2789
3149
  case "recall":
2790
- return await handleRecall(client, args);
3150
+ return await handleRecall2(client, args);
2791
3151
  case "status":
2792
3152
  return await handleStatus2(client);
2793
3153
  case "content":
@@ -2798,6 +3158,8 @@ async function handleToolCall(client, name, args) {
2798
3158
  return await handleGc2(client);
2799
3159
  case "rebuild":
2800
3160
  return await handleRebuild2(client);
3161
+ case "export":
3162
+ return await handleExport2(client, args);
2801
3163
  case "skill-learn":
2802
3164
  return await handleSkillLearn(client, args);
2803
3165
  case "skill-list":
@@ -2814,6 +3176,8 @@ async function handleToolCall(client, name, args) {
2814
3176
  return await handleAgentGet(client, args);
2815
3177
  case "agent-delete":
2816
3178
  return await handleAgentDelete(client, args);
3179
+ case "auto-capture-review":
3180
+ return handleAutoCaptureReview();
2817
3181
  default:
2818
3182
  return {
2819
3183
  content: [
@@ -2842,11 +3206,18 @@ async function handleSearch2(client, args) {
2842
3206
  query: asString2(args["query"], ""),
2843
3207
  mode: args["mode"],
2844
3208
  limit: args["limit"],
2845
- offset: args["offset"]
3209
+ offset: args["offset"],
3210
+ algo: args["algo"]
2846
3211
  });
2847
3212
  const stripped = {
2848
3213
  ...results,
2849
- items: results.items.map(({ score: _score, ...rest }) => rest)
3214
+ items: results.items.map(
3215
+ ({
3216
+ score: _score,
3217
+ confidence: _confidence,
3218
+ ...rest
3219
+ }) => rest
3220
+ )
2850
3221
  };
2851
3222
  return {
2852
3223
  content: [
@@ -2862,6 +3233,8 @@ async function handleLearn2(client, args) {
2862
3233
  const title = typeof args["title"] === "string" ? args["title"] : void 0;
2863
3234
  const description = typeof args["description"] === "string" ? args["description"] : void 0;
2864
3235
  const docid = typeof args["docid"] === "string" ? args["docid"] : void 0;
3236
+ const tags = asStringArrayOrUndefined(args["tags"]);
3237
+ const replace = asBooleanOrUndefined(args["replace"]);
2865
3238
  if (sectionType.startsWith("image/") && !title) {
2866
3239
  return {
2867
3240
  content: [
@@ -2878,13 +3251,27 @@ async function handleLearn2(client, args) {
2878
3251
  content: asString2(args["content"], ""),
2879
3252
  title,
2880
3253
  description,
2881
- docid
3254
+ docid,
3255
+ tags,
3256
+ replace
2882
3257
  });
3258
+ const normalized = {
3259
+ kbid: result.kbid,
3260
+ indexed_terms_count: result.indexed_terms_count ?? 0,
3261
+ elapsed_ms: result.elapsed_ms ?? 0,
3262
+ superseded: result.superseded ?? null,
3263
+ warnings: result.warnings ?? [],
3264
+ near_duplicates: (result.near_duplicates ?? []).map((d) => ({
3265
+ kbid: d.kbid,
3266
+ similarity: d.similarity,
3267
+ ...d.method !== void 0 ? { method: d.method } : {}
3268
+ }))
3269
+ };
2883
3270
  return {
2884
3271
  content: [
2885
3272
  {
2886
3273
  type: "text",
2887
- text: JSON.stringify(result)
3274
+ text: JSON.stringify(normalized)
2888
3275
  }
2889
3276
  ]
2890
3277
  };
@@ -3125,6 +3512,33 @@ async function handleSkillDelete(client, args) {
3125
3512
  ]
3126
3513
  };
3127
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
+ }
3528
+ async function handleExport2(client, args) {
3529
+ const path = typeof args["path"] === "string" ? args["path"] : void 0;
3530
+ const result = await client.export(
3531
+ path !== void 0 ? { path } : {}
3532
+ );
3533
+ return {
3534
+ content: [
3535
+ {
3536
+ type: "text",
3537
+ text: JSON.stringify(result)
3538
+ }
3539
+ ]
3540
+ };
3541
+ }
3128
3542
 
3129
3543
  // src/shared/mcp/functions/handle-resource-read.function.ts
3130
3544
  async function handleResourceRead(client, uri) {
@@ -3221,8 +3635,12 @@ function buildSkillsText(skillSections) {
3221
3635
  ${lines.join("\n")}`;
3222
3636
  }
3223
3637
  async function handleAgentPrompt(name, client) {
3224
- const docid = name.slice(6);
3225
- 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
+ }
3226
3644
  const sections = doc.sections;
3227
3645
  const metaSection = sections.at(0);
3228
3646
  const skillRefs = sections.slice(1);
@@ -3380,13 +3798,16 @@ var McpServer = class {
3380
3798
  input: process.stdin,
3381
3799
  terminal: false
3382
3800
  });
3801
+ let pending = Promise.resolve();
3383
3802
  await new Promise((resolve4) => {
3384
3803
  rl.on("line", (line) => {
3385
- void this.dispatchLine(line);
3804
+ pending = pending.then(() => this.dispatchLine(line));
3386
3805
  });
3387
3806
  rl.on("close", () => {
3388
- this.client.disconnect();
3389
- resolve4();
3807
+ void pending.then(() => {
3808
+ this.client.disconnect();
3809
+ resolve4();
3810
+ });
3390
3811
  });
3391
3812
  });
3392
3813
  }
@@ -3496,8 +3917,9 @@ var McpServer = class {
3496
3917
  const request = parsed;
3497
3918
  if (request.id === void 0) {
3498
3919
  if (request.method === "notifications/initialized" || request.method === "notifications/cancelled") {
3499
- if (request.method === "notifications/initialized") {
3920
+ if (request.method === "notifications/initialized" && !this.initialized) {
3500
3921
  this.initialized = true;
3922
+ void this.runStartupHealthCheck();
3501
3923
  }
3502
3924
  }
3503
3925
  return null;
@@ -3690,6 +4112,27 @@ var McpServer = class {
3690
4112
  const json = JSON.stringify(response);
3691
4113
  process.stdout.write(json + "\n");
3692
4114
  }
4115
+ /**
4116
+ * Runs an integrity check immediately after the MCP handshake
4117
+ * completes. Emits a `notifications/message` warning when the
4118
+ * check detects issues so the connected agent is aware before
4119
+ * making requests. The server continues operating regardless of
4120
+ * the result.
4121
+ */
4122
+ async runStartupHealthCheck() {
4123
+ try {
4124
+ const report = await this.client.integrityCheck();
4125
+ if (!report.ok) {
4126
+ const summary = report.errors.map((e) => `${e.type}: ${e.entity} -- ${e.detail}`).join("; ");
4127
+ this.notify("notifications/message", {
4128
+ level: "warning",
4129
+ logger: "kbdb",
4130
+ data: `Database integrity issues detected: ${summary}`
4131
+ });
4132
+ }
4133
+ } catch {
4134
+ }
4135
+ }
3693
4136
  };
3694
4137
 
3695
4138
  // src/shared/mcp/functions/create-mcp-server.function.ts