@dikolab/kbdb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +270 -0
  3. package/dist/chunk-QCCN7OZH.mjs +82 -0
  4. package/dist/chunk-QCCN7OZH.mjs.map +7 -0
  5. package/dist/cli.cjs +3598 -0
  6. package/dist/cli.cjs.map +7 -0
  7. package/dist/cli.mjs +3537 -0
  8. package/dist/cli.mjs.map +7 -0
  9. package/dist/kbdb-worker.cjs +1659 -0
  10. package/dist/kbdb-worker.cjs.map +7 -0
  11. package/dist/mod.cjs +538 -0
  12. package/dist/mod.cjs.map +7 -0
  13. package/dist/mod.d.ts +3 -0
  14. package/dist/mod.mjs +507 -0
  15. package/dist/mod.mjs.map +7 -0
  16. package/dist/src/cli.d.ts +1 -0
  17. package/dist/src/shared/cli/constants/defaults.constant.d.ts +11 -0
  18. package/dist/src/shared/cli/constants/help-text.constant.d.ts +2 -0
  19. package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +37 -0
  20. package/dist/src/shared/cli/functions/ensure-db.function.d.ts +11 -0
  21. package/dist/src/shared/cli/functions/error-to-message.function.d.ts +7 -0
  22. package/dist/src/shared/cli/functions/find-db.function.d.ts +13 -0
  23. package/dist/src/shared/cli/functions/format-output.function.d.ts +15 -0
  24. package/dist/src/shared/cli/functions/generate-help.function.d.ts +31 -0
  25. package/dist/src/shared/cli/functions/is-stdin-tty.function.d.ts +7 -0
  26. package/dist/src/shared/cli/functions/parse-args.function.d.ts +25 -0
  27. package/dist/src/shared/cli/functions/prompt-user.function.d.ts +13 -0
  28. package/dist/src/shared/cli/functions/run-agent-create.function.d.ts +58 -0
  29. package/dist/src/shared/cli/functions/run-agent-delete.function.d.ts +32 -0
  30. package/dist/src/shared/cli/functions/run-agent-get.function.d.ts +46 -0
  31. package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +45 -0
  32. package/dist/src/shared/cli/functions/run-check.function.d.ts +64 -0
  33. package/dist/src/shared/cli/functions/run-cli.function.d.ts +39 -0
  34. package/dist/src/shared/cli/functions/run-content.function.d.ts +40 -0
  35. package/dist/src/shared/cli/functions/run-db-init.function.d.ts +23 -0
  36. package/dist/src/shared/cli/functions/run-db-migrate.function.d.ts +32 -0
  37. package/dist/src/shared/cli/functions/run-gc.function.d.ts +38 -0
  38. package/dist/src/shared/cli/functions/run-init.function.d.ts +27 -0
  39. package/dist/src/shared/cli/functions/run-learn.function.d.ts +46 -0
  40. package/dist/src/shared/cli/functions/run-migrate.function.d.ts +57 -0
  41. package/dist/src/shared/cli/functions/run-rebuild.function.d.ts +40 -0
  42. package/dist/src/shared/cli/functions/run-search.function.d.ts +39 -0
  43. package/dist/src/shared/cli/functions/run-skill-delete.function.d.ts +30 -0
  44. package/dist/src/shared/cli/functions/run-skill-get.function.d.ts +49 -0
  45. package/dist/src/shared/cli/functions/run-skill-learn.function.d.ts +36 -0
  46. package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +43 -0
  47. package/dist/src/shared/cli/functions/run-status.function.d.ts +22 -0
  48. package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +45 -0
  49. package/dist/src/shared/cli/index.d.ts +35 -0
  50. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +53 -0
  51. package/dist/src/shared/cli/typings/command-result.model.d.ts +15 -0
  52. package/dist/src/shared/cli/typings/learn-result.model.d.ts +11 -0
  53. package/dist/src/shared/cli/typings/search-display.model.d.ts +17 -0
  54. package/dist/src/shared/dir-resolver/functions/resolve-base-dir.function.d.ts +3 -0
  55. package/dist/src/shared/dir-resolver/functions/resolve-wasm-dir.function.d.ts +1 -0
  56. package/dist/src/shared/dir-resolver/functions/resolve-worker-script.function.d.ts +2 -0
  57. package/dist/src/shared/dir-resolver/index.d.ts +4 -0
  58. package/dist/src/shared/dir-resolver/typings/base-dir.interface.d.ts +4 -0
  59. package/dist/src/shared/hash/functions/compute-sha256.d.ts +10 -0
  60. package/dist/src/shared/hash/index.d.ts +1 -0
  61. package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +55 -0
  62. package/dist/src/shared/mcp/constants/mcp-error-codes.constant.d.ts +26 -0
  63. package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +11 -0
  64. package/dist/src/shared/mcp/functions/create-prompt-definitions.function.d.ts +41 -0
  65. package/dist/src/shared/mcp/functions/create-resource-templates.function.d.ts +7 -0
  66. package/dist/src/shared/mcp/functions/create-tool-definitions.function.d.ts +7 -0
  67. package/dist/src/shared/mcp/functions/extract-skill-arguments.function.d.ts +13 -0
  68. package/dist/src/shared/mcp/functions/handle-agent-create.function.d.ts +29 -0
  69. package/dist/src/shared/mcp/functions/handle-agent-delete.function.d.ts +28 -0
  70. package/dist/src/shared/mcp/functions/handle-agent-get.function.d.ts +29 -0
  71. package/dist/src/shared/mcp/functions/handle-agent-list.function.d.ts +31 -0
  72. package/dist/src/shared/mcp/functions/handle-completion.function.d.ts +58 -0
  73. package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +23 -0
  74. package/dist/src/shared/mcp/functions/handle-resource-read.function.d.ts +26 -0
  75. package/dist/src/shared/mcp/functions/handle-roots-list.function.d.ts +21 -0
  76. package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +26 -0
  77. package/dist/src/shared/mcp/functions/parse-skill-content.function.d.ts +15 -0
  78. package/dist/src/shared/mcp/functions/serialize-skill-content.function.d.ts +9 -0
  79. package/dist/src/shared/mcp/functions/should-emit-log.function.d.ts +20 -0
  80. package/dist/src/shared/mcp/index.d.ts +9 -0
  81. package/dist/src/shared/mcp/typings/agent-types.interface.d.ts +38 -0
  82. package/dist/src/shared/mcp/typings/log-types.interface.d.ts +17 -0
  83. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +217 -0
  84. package/dist/src/shared/mcp/typings/mcp-types.interface.d.ts +149 -0
  85. package/dist/src/shared/mcp/typings/prompt-types.interface.d.ts +37 -0
  86. package/dist/src/shared/mcp/typings/remove-section-result.model.d.ts +10 -0
  87. package/dist/src/shared/mcp/typings/sampling-types.interface.d.ts +46 -0
  88. package/dist/src/shared/mcp/typings/skill-types.interface.d.ts +28 -0
  89. package/dist/src/shared/mod.d.ts +1 -0
  90. package/dist/src/shared/platform/functions/get-ipc-path.function.d.ts +11 -0
  91. package/dist/src/shared/platform/functions/get-tmpdir.function.d.ts +4 -0
  92. package/dist/src/shared/platform/functions/is-process-alive.function.d.ts +10 -0
  93. package/dist/src/shared/platform/index.d.ts +3 -0
  94. package/dist/src/shared/runtime/functions/detect-runtime.d.ts +8 -0
  95. package/dist/src/shared/runtime/functions/get-args.d.ts +7 -0
  96. package/dist/src/shared/runtime/index.d.ts +3 -0
  97. package/dist/src/shared/runtime/typings/runtime.d.ts +2 -0
  98. package/dist/src/shared/version/constants/version.constant.d.ts +2 -0
  99. package/dist/src/shared/version/index.d.ts +1 -0
  100. package/dist/src/shared/wasm-codec/functions/decode-compose-output.function.d.ts +5 -0
  101. package/dist/src/shared/wasm-codec/functions/decode-document-manifest-list.function.d.ts +14 -0
  102. package/dist/src/shared/wasm-codec/functions/decode-document-manifest.function.d.ts +40 -0
  103. package/dist/src/shared/wasm-codec/functions/decode-f32.function.d.ts +2 -0
  104. package/dist/src/shared/wasm-codec/functions/decode-key-value-text.function.d.ts +1 -0
  105. package/dist/src/shared/wasm-codec/functions/decode-remove-flag.function.d.ts +1 -0
  106. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +10 -0
  107. package/dist/src/shared/wasm-codec/functions/decode-section-record-list.function.d.ts +13 -0
  108. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +50 -0
  109. package/dist/src/shared/wasm-codec/functions/decode-string.function.d.ts +5 -0
  110. package/dist/src/shared/wasm-codec/functions/decode-u32.function.d.ts +2 -0
  111. package/dist/src/shared/wasm-codec/functions/decode-u64.function.d.ts +2 -0
  112. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +10 -0
  113. package/dist/src/shared/wasm-codec/functions/encode-group-params.function.d.ts +10 -0
  114. package/dist/src/shared/wasm-codec/functions/encode-identifier-list.function.d.ts +1 -0
  115. package/dist/src/shared/wasm-codec/functions/encode-kbid-list.function.d.ts +1 -0
  116. package/dist/src/shared/wasm-codec/functions/encode-option-string.function.d.ts +1 -0
  117. package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -0
  118. package/dist/src/shared/wasm-codec/functions/encode-section-type.function.d.ts +1 -0
  119. package/dist/src/shared/wasm-codec/functions/encode-string.function.d.ts +1 -0
  120. package/dist/src/shared/wasm-codec/functions/encode-type-filter-param.function.d.ts +11 -0
  121. package/dist/src/shared/wasm-codec/functions/encode-u32.function.d.ts +1 -0
  122. package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +2 -0
  123. package/dist/src/shared/wasm-codec/index.d.ts +29 -0
  124. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +230 -0
  125. package/dist/src/shared/worker-client/functions/compute-context-id.function.d.ts +11 -0
  126. package/dist/src/shared/worker-client/functions/create-worker-client.function.d.ts +18 -0
  127. package/dist/src/shared/worker-client/functions/discover-daemon.function.d.ts +14 -0
  128. package/dist/src/shared/worker-client/functions/resolve-db-path.function.d.ts +11 -0
  129. package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +11 -0
  130. package/dist/src/shared/worker-client/functions/wait-for-daemon.function.d.ts +13 -0
  131. package/dist/src/shared/worker-client/index.d.ts +22 -0
  132. package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +22 -0
  133. package/dist/src/shared/worker-client/typings/content-result.model.d.ts +12 -0
  134. package/dist/src/shared/worker-client/typings/daemon-info.model.d.ts +7 -0
  135. package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +12 -0
  136. package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +36 -0
  137. package/dist/src/shared/worker-client/typings/migrate-result.model.d.ts +11 -0
  138. package/dist/src/shared/worker-client/typings/rebuild-result.model.d.ts +12 -0
  139. package/dist/src/shared/worker-client/typings/remove-section-result.model.d.ts +7 -0
  140. package/dist/src/shared/worker-client/typings/search-params.model.d.ts +12 -0
  141. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +14 -0
  142. package/dist/src/shared/worker-client/typings/section.model.d.ts +26 -0
  143. package/dist/src/shared/worker-client/typings/status-result.model.d.ts +14 -0
  144. package/dist/src/shared/worker-client/typings/version-status.model.d.ts +24 -0
  145. package/dist/src/shared/worker-client/typings/worker-client-error.interface.d.ts +8 -0
  146. package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +30 -0
  147. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +147 -0
  148. package/dist/src/shared/worker-daemon/constants/daemon-defaults.constant.d.ts +24 -0
  149. package/dist/src/shared/worker-daemon/functions/create-host-imports.function.d.ts +68 -0
  150. package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +18 -0
  151. package/dist/src/shared/worker-daemon/functions/load-wasm-modules.function.d.ts +19 -0
  152. package/dist/src/shared/worker-daemon/functions/read-config.function.d.ts +12 -0
  153. package/dist/src/shared/worker-daemon/functions/run-worker.function.d.ts +26 -0
  154. package/dist/src/shared/worker-daemon/functions/start-daemon.function.d.ts +13 -0
  155. package/dist/src/shared/worker-daemon/index.d.ts +9 -0
  156. package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +13 -0
  157. package/dist/src/shared/worker-daemon/typings/ipc-handler.interface.d.ts +36 -0
  158. package/dist/src/shared/worker-daemon/typings/wasm-modules.interface.d.ts +7 -0
  159. package/dist/src/worker.d.ts +1 -0
  160. package/dist/vitest.config.d.ts +2 -0
  161. package/dist/worker.mjs +1615 -0
  162. package/dist/worker.mjs.map +7 -0
  163. package/mod.ts +17 -0
  164. package/package.json +85 -0
  165. package/src/cli.ts +62 -0
  166. package/src/shared/cli/constants/defaults.constant.ts +19 -0
  167. package/src/shared/cli/constants/help-text.constant.ts +4 -0
  168. package/src/shared/cli/functions/dispatch-command.function.ts +338 -0
  169. package/src/shared/cli/functions/ensure-db.function.ts +21 -0
  170. package/src/shared/cli/functions/error-to-message.function.ts +9 -0
  171. package/src/shared/cli/functions/find-db.function.ts +20 -0
  172. package/src/shared/cli/functions/format-output.function.ts +64 -0
  173. package/src/shared/cli/functions/generate-help.function.ts +599 -0
  174. package/src/shared/cli/functions/is-stdin-tty.function.ts +12 -0
  175. package/src/shared/cli/functions/parse-args.function.ts +133 -0
  176. package/src/shared/cli/functions/prompt-user.function.ts +36 -0
  177. package/src/shared/cli/functions/run-agent-create.function.ts +114 -0
  178. package/src/shared/cli/functions/run-agent-delete.function.ts +47 -0
  179. package/src/shared/cli/functions/run-agent-get.function.ts +166 -0
  180. package/src/shared/cli/functions/run-agent-list.function.ts +58 -0
  181. package/src/shared/cli/functions/run-check.function.ts +78 -0
  182. package/src/shared/cli/functions/run-cli.function.ts +299 -0
  183. package/src/shared/cli/functions/run-content.function.ts +47 -0
  184. package/src/shared/cli/functions/run-db-init.function.ts +44 -0
  185. package/src/shared/cli/functions/run-db-migrate.function.ts +40 -0
  186. package/src/shared/cli/functions/run-gc.function.ts +45 -0
  187. package/src/shared/cli/functions/run-init.function.ts +91 -0
  188. package/src/shared/cli/functions/run-learn.function.ts +171 -0
  189. package/src/shared/cli/functions/run-migrate.function.ts +85 -0
  190. package/src/shared/cli/functions/run-rebuild.function.ts +47 -0
  191. package/src/shared/cli/functions/run-search.function.ts +62 -0
  192. package/src/shared/cli/functions/run-skill-delete.function.ts +47 -0
  193. package/src/shared/cli/functions/run-skill-get.function.ts +90 -0
  194. package/src/shared/cli/functions/run-skill-learn.function.ts +70 -0
  195. package/src/shared/cli/functions/run-skill-list.function.ts +74 -0
  196. package/src/shared/cli/functions/run-status.function.ts +29 -0
  197. package/src/shared/cli/functions/run-unlearn.function.ts +58 -0
  198. package/src/shared/cli/index.ts +48 -0
  199. package/src/shared/cli/typings/cli-options.interface.ts +55 -0
  200. package/src/shared/cli/typings/command-result.model.ts +15 -0
  201. package/src/shared/cli/typings/learn-result.model.ts +11 -0
  202. package/src/shared/cli/typings/search-display.model.ts +17 -0
  203. package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +25 -0
  204. package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +5 -0
  205. package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +13 -0
  206. package/src/shared/dir-resolver/index.ts +7 -0
  207. package/src/shared/dir-resolver/typings/base-dir.interface.ts +4 -0
  208. package/src/shared/hash/functions/compute-sha256.ts +17 -0
  209. package/src/shared/hash/index.ts +1 -0
  210. package/src/shared/mcp/classes/mcp-server.class.ts +448 -0
  211. package/src/shared/mcp/constants/mcp-error-codes.constant.ts +30 -0
  212. package/src/shared/mcp/functions/create-mcp-server.function.ts +14 -0
  213. package/src/shared/mcp/functions/create-prompt-definitions.function.ts +102 -0
  214. package/src/shared/mcp/functions/create-resource-templates.function.ts +23 -0
  215. package/src/shared/mcp/functions/create-tool-definitions.function.ts +401 -0
  216. package/src/shared/mcp/functions/extract-skill-arguments.function.ts +27 -0
  217. package/src/shared/mcp/functions/handle-agent-create.function.ts +116 -0
  218. package/src/shared/mcp/functions/handle-agent-delete.function.ts +50 -0
  219. package/src/shared/mcp/functions/handle-agent-get.function.ts +160 -0
  220. package/src/shared/mcp/functions/handle-agent-list.function.ts +50 -0
  221. package/src/shared/mcp/functions/handle-completion.function.ts +114 -0
  222. package/src/shared/mcp/functions/handle-prompt-get.function.ts +214 -0
  223. package/src/shared/mcp/functions/handle-resource-read.function.ts +56 -0
  224. package/src/shared/mcp/functions/handle-roots-list.function.ts +29 -0
  225. package/src/shared/mcp/functions/handle-tool-call.function.ts +464 -0
  226. package/src/shared/mcp/functions/parse-skill-content.function.ts +38 -0
  227. package/src/shared/mcp/functions/serialize-skill-content.function.ts +12 -0
  228. package/src/shared/mcp/functions/should-emit-log.function.ts +38 -0
  229. package/src/shared/mcp/index.ts +28 -0
  230. package/src/shared/mcp/typings/agent-types.interface.ts +39 -0
  231. package/src/shared/mcp/typings/log-types.interface.ts +26 -0
  232. package/src/shared/mcp/typings/mcp-client.interface.ts +252 -0
  233. package/src/shared/mcp/typings/mcp-types.interface.ts +158 -0
  234. package/src/shared/mcp/typings/prompt-types.interface.ts +39 -0
  235. package/src/shared/mcp/typings/remove-section-result.model.ts +10 -0
  236. package/src/shared/mcp/typings/sampling-types.interface.ts +48 -0
  237. package/src/shared/mcp/typings/skill-types.interface.ts +29 -0
  238. package/src/shared/mod.ts +1 -0
  239. package/src/shared/platform/functions/get-ipc-path.function.ts +19 -0
  240. package/src/shared/platform/functions/get-tmpdir.function.ts +8 -0
  241. package/src/shared/platform/functions/is-process-alive.function.ts +17 -0
  242. package/src/shared/platform/index.ts +3 -0
  243. package/src/shared/runtime/functions/detect-runtime.ts +14 -0
  244. package/src/shared/runtime/functions/get-args.ts +16 -0
  245. package/src/shared/runtime/index.ts +3 -0
  246. package/src/shared/runtime/typings/runtime.ts +2 -0
  247. package/src/shared/version/constants/version.constant.ts +2 -0
  248. package/src/shared/version/index.ts +1 -0
  249. package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +16 -0
  250. package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +70 -0
  251. package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +87 -0
  252. package/src/shared/wasm-codec/functions/decode-f32.function.ts +16 -0
  253. package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +15 -0
  254. package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +3 -0
  255. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +54 -0
  256. package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +20 -0
  257. package/src/shared/wasm-codec/functions/decode-section-records.function.ts +162 -0
  258. package/src/shared/wasm-codec/functions/decode-string.function.ts +22 -0
  259. package/src/shared/wasm-codec/functions/decode-u32.function.ts +16 -0
  260. package/src/shared/wasm-codec/functions/decode-u64.function.ts +16 -0
  261. package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +34 -0
  262. package/src/shared/wasm-codec/functions/encode-group-params.function.ts +28 -0
  263. package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +17 -0
  264. package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +17 -0
  265. package/src/shared/wasm-codec/functions/encode-option-string.function.ts +14 -0
  266. package/src/shared/wasm-codec/functions/encode-search-params.function.ts +9 -0
  267. package/src/shared/wasm-codec/functions/encode-section-type.function.ts +18 -0
  268. package/src/shared/wasm-codec/functions/encode-string.function.ts +9 -0
  269. package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +13 -0
  270. package/src/shared/wasm-codec/functions/encode-u32.function.ts +5 -0
  271. package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +16 -0
  272. package/src/shared/wasm-codec/index.ts +36 -0
  273. package/src/shared/worker-client/classes/worker-client.class.ts +427 -0
  274. package/src/shared/worker-client/functions/compute-context-id.function.ts +18 -0
  275. package/src/shared/worker-client/functions/create-worker-client.function.ts +70 -0
  276. package/src/shared/worker-client/functions/discover-daemon.function.ts +47 -0
  277. package/src/shared/worker-client/functions/resolve-db-path.function.ts +21 -0
  278. package/src/shared/worker-client/functions/spawn-daemon.function.ts +35 -0
  279. package/src/shared/worker-client/functions/wait-for-daemon.function.ts +34 -0
  280. package/src/shared/worker-client/index.ts +31 -0
  281. package/src/shared/worker-client/typings/add-section-result.model.ts +22 -0
  282. package/src/shared/worker-client/typings/content-result.model.ts +12 -0
  283. package/src/shared/worker-client/typings/daemon-info.model.ts +7 -0
  284. package/src/shared/worker-client/typings/gc-result.model.ts +12 -0
  285. package/src/shared/worker-client/typings/integrity-check-result.model.ts +43 -0
  286. package/src/shared/worker-client/typings/migrate-result.model.ts +11 -0
  287. package/src/shared/worker-client/typings/rebuild-result.model.ts +12 -0
  288. package/src/shared/worker-client/typings/remove-section-result.model.ts +7 -0
  289. package/src/shared/worker-client/typings/search-params.model.ts +12 -0
  290. package/src/shared/worker-client/typings/search-result.model.ts +14 -0
  291. package/src/shared/worker-client/typings/section.model.ts +27 -0
  292. package/src/shared/worker-client/typings/status-result.model.ts +14 -0
  293. package/src/shared/worker-client/typings/version-status.model.ts +28 -0
  294. package/src/shared/worker-client/typings/worker-client-error.interface.ts +8 -0
  295. package/src/shared/worker-client/typings/worker-client-options.interface.ts +30 -0
  296. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +1001 -0
  297. package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +29 -0
  298. package/src/shared/worker-daemon/functions/create-host-imports.function.ts +312 -0
  299. package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +83 -0
  300. package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +98 -0
  301. package/src/shared/worker-daemon/functions/read-config.function.ts +83 -0
  302. package/src/shared/worker-daemon/functions/run-worker.function.ts +57 -0
  303. package/src/shared/worker-daemon/functions/start-daemon.function.ts +74 -0
  304. package/src/shared/worker-daemon/index.ts +16 -0
  305. package/src/shared/worker-daemon/typings/daemon-config.interface.ts +13 -0
  306. package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +39 -0
  307. package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +7 -0
  308. package/src/worker.ts +34 -0
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Resolves the absolute path to the `.kbdb` database directory
3
+ * under the given base path (or the current working directory).
4
+ *
5
+ * Unlike `ensureDb`, this function is purely read-only: it never
6
+ * creates the directory. Returns `null` when the `.kbdb` directory
7
+ * does not exist.
8
+ *
9
+ * @param dbPath - optional path to the knowledge-base root directory
10
+ * @returns absolute path to the `.kbdb` directory, or `null` when
11
+ * it does not exist
12
+ */
13
+ export declare function findDb(dbPath?: string): string | null;
@@ -0,0 +1,15 @@
1
+ import type { OutputFormat } from '../typings/cli-options.interface.ts';
2
+ import type { SearchDisplay } from '../typings/search-display.model.ts';
3
+ /**
4
+ * Serialises an array of search results into the requested output
5
+ * format string.
6
+ *
7
+ * - `'json'` -- pretty-printed JSON array
8
+ * - `'text'` -- numbered human-readable list
9
+ * - `'mcp'` -- JSON envelope compatible with MCP protocol consumers
10
+ *
11
+ * @param results - ranked search results to format
12
+ * @param format - target output format
13
+ * @returns formatted string ready for stdout
14
+ */
15
+ export declare function formatOutput(results: SearchDisplay[], format: OutputFormat): string;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Returns `true` when `cmd` is a recognised command name.
3
+ *
4
+ * Accepts both simple top-level names (`'learn'`, `'db'`)
5
+ * and the hyphenated compound form produced by `parseArgs`
6
+ * when a group + subcommand precedes `--help`
7
+ * (e.g. `'db-init'`, `'skill-learn'`).
8
+ */
9
+ export declare function isKnownCommand(cmd: string): boolean;
10
+ /**
11
+ * Generates contextual help text for the `kbdb` CLI.
12
+ *
13
+ * Three levels of detail are produced depending on
14
+ * how many command tokens are supplied:
15
+ *
16
+ * - No arguments: global help listing all commands.
17
+ * - `command` only: command-level help. When `command`
18
+ * is a hyphenated compound (`'db-init'`), it is split
19
+ * into group + subcommand automatically. Group
20
+ * commands show a subcommand listing; leaf commands
21
+ * show detailed help; unknown commands show an error
22
+ * prefix followed by global help.
23
+ * - `command` + `subcommand`: detailed help for that
24
+ * specific subcommand (falls back to group help when
25
+ * the subcommand is not recognised).
26
+ *
27
+ * @param command - optional top-level command token,
28
+ * or a hyphenated compound such as `'db-init'`
29
+ * @param subcommand - optional subcommand token
30
+ */
31
+ export declare function generateHelp(command?: string, subcommand?: string): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns `true` when stdin is an interactive terminal.
3
+ *
4
+ * @param stdin - readable stream to check (defaults to
5
+ * `process.stdin`)
6
+ */
7
+ export declare function isStdinTty(stdin?: NodeJS.ReadStream): boolean;
@@ -0,0 +1,25 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /**
3
+ * Parses a raw argument vector into a structured `CliOptions` object.
4
+ *
5
+ * Recognises `--help` / `-h` and `--version` / `-v` as early-exit
6
+ * flags that set the command and return immediately. All other flags
7
+ * consume the next token as their value. The first non-flag token
8
+ * becomes the command; subsequent non-flag tokens become `args`.
9
+ *
10
+ * Compound commands are supported: when the first positional token is
11
+ * a group name (`db`, `skill`, or `agent`), the next positional token
12
+ * is joined with a hyphen to form the compound command
13
+ * (e.g. `db init` → `'db-init'`).
14
+ *
15
+ * Context-aware `--help`: when `--help` or `-h` appears after a
16
+ * command has been set, the existing command is moved to `args[0]`
17
+ * and the command is set to `'help'`, enabling per-command help.
18
+ *
19
+ * Deprecated flags `--init` and `--migrate` emit a warning to stderr
20
+ * before setting the corresponding command.
21
+ *
22
+ * @param argv - argument strings (typically `process.argv.slice(2)`)
23
+ * @returns fully populated `CliOptions` with defaults applied
24
+ */
25
+ export declare function parseArgs(argv: string[]): CliOptions;
@@ -0,0 +1,13 @@
1
+ /** Injectable I/O for testing without real stdin. */
2
+ export interface PromptIO {
3
+ ask: (question: string) => Promise<string>;
4
+ }
5
+ /**
6
+ * Prompts the user on stdin (TTY only) and returns the
7
+ * trimmed reply.
8
+ *
9
+ * @param question - the prompt text to display
10
+ * @param io - injectable I/O (defaults to readline on
11
+ * process.stdin/stdout)
12
+ */
13
+ export declare function promptUser(question: string, io?: PromptIO): Promise<string>;
@@ -0,0 +1,58 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { CommandResult } from '../typings/command-result.model.ts';
3
+ import type { AddSectionResult } from '../../worker-client/typings/add-section-result.model.ts';
4
+ /**
5
+ * Minimal client interface required by `runAgentCreate`.
6
+ *
7
+ * Decouples the CLI function from the concrete `WorkerClient`
8
+ * implementation, making it straightforward to test with mocks.
9
+ */
10
+ export interface AgentCreateClient {
11
+ /**
12
+ * Ingests a content section into the knowledge base.
13
+ *
14
+ * @param params - section type label, raw content, and optional
15
+ * metadata
16
+ * @returns result object containing the assigned knowledge-base
17
+ * identifier
18
+ */
19
+ addSection(params: {
20
+ readonly sectionType: string;
21
+ readonly content: string;
22
+ readonly title?: string;
23
+ readonly description?: string;
24
+ }): Promise<AddSectionResult>;
25
+ /**
26
+ * Groups a set of sections under a named document.
27
+ *
28
+ * @param title - human-readable document title
29
+ * @param kbids - identifiers of the sections to group
30
+ * @param docType - application-level document type tag; omit or
31
+ * pass an empty string for untagged documents
32
+ * @returns the assigned document identifier
33
+ */
34
+ groupSections(title: string, kbids: string[], docType?: string): Promise<string>;
35
+ /**
36
+ * Retrieves one or more sections by their identifiers.
37
+ *
38
+ * @param kbids - list of knowledge-base identifiers to fetch
39
+ * @returns sections found; missing kbids are omitted from the result
40
+ */
41
+ readSections(kbids: string[]): Promise<{
42
+ kbid: string;
43
+ }[]>;
44
+ }
45
+ /**
46
+ * Creates a new agent in the knowledge base.
47
+ *
48
+ * Validates `--name` and `--persona` options, verifies that all
49
+ * referenced skill kbids exist, stores agent metadata as a JSON
50
+ * section, and groups all sections under a single document.
51
+ *
52
+ * @param client - agent create client to delegate operations to
53
+ * @param options - parsed CLI options providing `name`, `persona`,
54
+ * optional `description`, and optional `skills` kbid list
55
+ * @returns a `CommandResult` with serialised creation info or an
56
+ * error message and a non-zero exit code
57
+ */
58
+ export declare function runAgentCreate(client: AgentCreateClient, options: CliOptions): Promise<CommandResult>;
@@ -0,0 +1,32 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { CommandResult } from '../typings/command-result.model.ts';
3
+ /**
4
+ * Minimal client interface required by `runAgentDelete`.
5
+ *
6
+ * Decouples the CLI function from the concrete `WorkerClient`
7
+ * implementation, making it straightforward to test with mocks.
8
+ */
9
+ export interface AgentDeleteClient {
10
+ /**
11
+ * Removes the document grouping for the given document.
12
+ *
13
+ * The sections themselves are not deleted; only the grouping
14
+ * record is removed.
15
+ *
16
+ * @param docid - identifier of the document grouping to remove
17
+ */
18
+ removeGrouping(docid: string): Promise<void>;
19
+ }
20
+ /**
21
+ * Deletes an agent from the knowledge base.
22
+ *
23
+ * Removes the document grouping identified by `options.args[0]`.
24
+ * Skill sections referenced by the agent are not deleted; only
25
+ * the grouping record is removed.
26
+ *
27
+ * @param client - agent delete client to delegate removal to
28
+ * @param options - parsed CLI options; `args[0]` must be the docid
29
+ * @returns a `CommandResult` confirming removal or an error message
30
+ * with a non-zero exit code
31
+ */
32
+ export declare function runAgentDelete(client: AgentDeleteClient, options: CliOptions): Promise<CommandResult>;
@@ -0,0 +1,46 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { CommandResult } from '../typings/command-result.model.ts';
3
+ /** A section record as returned by `readSections`. */
4
+ interface SectionRecord {
5
+ /** Knowledge-base identifier of the section. */
6
+ readonly kbid: string;
7
+ /** Raw text content stored in the section. */
8
+ readonly content: string;
9
+ }
10
+ /**
11
+ * Minimal client interface required by `runAgentGet`.
12
+ *
13
+ * Decouples the CLI function from the concrete `WorkerClient`
14
+ * implementation, making it straightforward to test with mocks.
15
+ */
16
+ export interface AgentGetClient {
17
+ /**
18
+ * Retrieves a full document record including its ordered sections.
19
+ *
20
+ * @param docid - identifier of the document to retrieve
21
+ * @returns the document record
22
+ */
23
+ retrieveDocument(docid: string): Promise<unknown>;
24
+ /**
25
+ * Retrieves one or more sections by their identifiers.
26
+ *
27
+ * @param kbids - list of knowledge-base identifiers to fetch
28
+ * @returns sections found; missing kbids are omitted from the result
29
+ */
30
+ readSections(kbids: string[]): Promise<SectionRecord[]>;
31
+ }
32
+ /**
33
+ * Retrieves a full agent definition from the knowledge base.
34
+ *
35
+ * Reads the agent document identified by `options.args[0]`, extracts
36
+ * metadata (name, description, persona) from the first section, and
37
+ * resolves skill names from the remaining sections. Dangling skill
38
+ * references appear with `name: null`.
39
+ *
40
+ * @param client - agent get client to delegate retrieval to
41
+ * @param options - parsed CLI options; `args[0]` must be the docid
42
+ * @returns a `CommandResult` with serialised agent definition or an
43
+ * error message and a non-zero exit code
44
+ */
45
+ export declare function runAgentGet(client: AgentGetClient, options: CliOptions): Promise<CommandResult>;
46
+ export {};
@@ -0,0 +1,45 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { CommandResult } from '../typings/command-result.model.ts';
3
+ /** A document summary as returned by `listDocumentsByType`. */
4
+ interface DocumentSummary {
5
+ /** Unique document identifier. */
6
+ readonly docid: string;
7
+ /** Human-readable document title used as the agent name. */
8
+ readonly title: string;
9
+ /** Ordered list of section references for this document. */
10
+ readonly sections: readonly {
11
+ kbid: string;
12
+ position: number;
13
+ }[];
14
+ }
15
+ /**
16
+ * Minimal client interface required by `runAgentList`.
17
+ *
18
+ * Decouples the CLI function from the concrete `WorkerClient`
19
+ * implementation, making it straightforward to test with mocks.
20
+ */
21
+ export interface AgentListClient {
22
+ /**
23
+ * Retrieves all documents whose type name matches the given string.
24
+ *
25
+ * @param docType - the application-level document type to filter by
26
+ * @returns all document summaries with a matching type name
27
+ */
28
+ listDocumentsByType(docType: string): Promise<DocumentSummary[]>;
29
+ }
30
+ /**
31
+ * Lists all agents stored in the knowledge base.
32
+ *
33
+ * Retrieves all documents with `doc_type: 'agent'` and returns a
34
+ * summary list. The `skillCount` for each agent is
35
+ * `Math.max(0, sections.length - 1)` because the first section
36
+ * always holds the agent's metadata JSON rather than a skill
37
+ * reference.
38
+ *
39
+ * @param client - agent list client to delegate retrieval to
40
+ * @param _options - parsed CLI options (unused; reserved for future
41
+ * filtering flags)
42
+ * @returns a `CommandResult` with serialised agent summary list
43
+ */
44
+ export declare function runAgentList(client: AgentListClient, _options: CliOptions): Promise<CommandResult>;
45
+ export {};
@@ -0,0 +1,64 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /** A single integrity error found during a database check. */
3
+ interface IntegrityError {
4
+ /**
5
+ * The category of integrity violation detected.
6
+ *
7
+ * - `'checksum_mismatch'` -- stored content does not match its hash
8
+ * - `'orphan_section'` -- section not referenced by any document
9
+ * - `'orphan_document'` -- document references no existing sections
10
+ * - `'broken_reference'` -- a marker references a non-existent entity
11
+ * - `'type_mismatch'` -- stored MIME type conflicts with content
12
+ * - `'circular_reference'` -- marker chain contains a cycle
13
+ */
14
+ readonly type: 'checksum_mismatch' | 'orphan_section' | 'orphan_document' | 'broken_reference' | 'type_mismatch' | 'circular_reference';
15
+ /** Identifier of the entity (kbid or docid) that has the issue. */
16
+ readonly entity: string;
17
+ /** Human-readable description of the specific problem. */
18
+ readonly detail: string;
19
+ }
20
+ /**
21
+ * Integrity check report returned by the daemon.
22
+ */
23
+ interface IntegrityCheckResult {
24
+ /** `true` when all checks passed and no errors were found. */
25
+ readonly ok: boolean;
26
+ /** All integrity errors found; empty when `ok` is `true`. */
27
+ readonly errors: IntegrityError[];
28
+ /** Total number of sections examined. */
29
+ readonly sections_checked: number;
30
+ /** Total number of documents examined. */
31
+ readonly documents_checked: number;
32
+ /** Total number of marker references checked. */
33
+ readonly references_checked: number;
34
+ /** Time taken to complete the check, in milliseconds. */
35
+ readonly elapsed_ms: number;
36
+ }
37
+ /**
38
+ * Minimal client interface required by `runCheck`.
39
+ *
40
+ * Decouples the CLI function from the concrete `WorkerClient`
41
+ * implementation, making it straightforward to test with mocks.
42
+ */
43
+ export interface CheckClient {
44
+ /**
45
+ * Runs an integrity check on the knowledge-base database.
46
+ *
47
+ * @returns a report of all issues found; `ok` is `true` when
48
+ * no errors were detected
49
+ */
50
+ integrityCheck(): Promise<IntegrityCheckResult>;
51
+ }
52
+ /**
53
+ * Runs an integrity check on the database and returns the report.
54
+ *
55
+ * Delegates to `client.integrityCheck()`. The caller is responsible
56
+ * for printing the result to stdout and setting the process exit code
57
+ * based on `result.ok`.
58
+ *
59
+ * @param client - check client to delegate to
60
+ * @param _options - parsed CLI options (unused; reserved for future flags)
61
+ * @returns the integrity check report from the daemon
62
+ */
63
+ export declare function runCheck(client: CheckClient, _options: CliOptions): Promise<IntegrityCheckResult>;
64
+ export {};
@@ -0,0 +1,39 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { CommandResult } from '../typings/command-result.model.ts';
3
+ import type { InitResult } from './run-init.function.ts';
4
+ import type { VersionStatus } from '../../worker-client/typings/version-status.model.ts';
5
+ import type { MigrateResult } from '../../worker-client/typings/migrate-result.model.ts';
6
+ import type { DispatchClient } from './dispatch-command.function.ts';
7
+ export interface DisconnectableClient extends DispatchClient {
8
+ checkVersion(targetPath: string): Promise<VersionStatus>;
9
+ migrateDatabase(targetPath: string): Promise<MigrateResult>;
10
+ disconnect(): void;
11
+ }
12
+ /**
13
+ * Injectable dependencies for the CLI orchestrator.
14
+ *
15
+ * Every external side-effect is injected so the function
16
+ * is fully testable without touching process globals,
17
+ * filesystem, or network.
18
+ */
19
+ export interface CliDeps {
20
+ isStdinTty: () => boolean;
21
+ promptUser: (question: string) => Promise<string>;
22
+ createWorkerClient: (opts: {
23
+ contextPath: string;
24
+ }) => Promise<DisconnectableClient>;
25
+ findDb: (basePath?: string) => string | null;
26
+ runInit: (options: CliOptions) => InitResult;
27
+ startMcpServer?: (contextPath: string) => Promise<void>;
28
+ }
29
+ /**
30
+ * Full CLI orchestrator extracted from `src/cli.ts`.
31
+ *
32
+ * Parses arguments, routes to the appropriate sub-flow
33
+ * (help, version, init, mcp, migrate, data commands), and
34
+ * returns a `CommandResult` without touching process globals.
35
+ *
36
+ * @param argv - raw CLI arguments (typically `process.argv.slice(2)`)
37
+ * @param deps - injectable dependencies
38
+ */
39
+ export declare function runCli(argv: string[], deps: CliDeps): Promise<CommandResult>;
@@ -0,0 +1,40 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /** Result returned by content composition. */
3
+ interface ContentResult {
4
+ /** MIME type of the composed output, always `'text/markdown'`. */
5
+ readonly type: 'text/markdown';
6
+ /** The composed Markdown string. */
7
+ readonly data: string;
8
+ /** Character count of `data` (not byte count). */
9
+ readonly total: number;
10
+ }
11
+ /**
12
+ * Minimal client interface required by `runContent`.
13
+ *
14
+ * Decouples the CLI function from the concrete `WorkerClient`
15
+ * implementation, making it straightforward to test with mocks.
16
+ */
17
+ export interface ContentClient {
18
+ /**
19
+ * Composes a rendered Markdown document from one or more kbid
20
+ * or docid identifiers.
21
+ *
22
+ * @param ids - list of kbid or docid identifiers (may be mixed)
23
+ * @returns composed Markdown result with character count
24
+ */
25
+ content(ids: string[]): Promise<ContentResult>;
26
+ }
27
+ /**
28
+ * Composes and returns a rendered Markdown document from the
29
+ * identifiers listed in `options.args`.
30
+ *
31
+ * Delegates to `client.content(ids)`. The caller is responsible for
32
+ * writing the result to stdout.
33
+ *
34
+ * @param client - content client to delegate composition to
35
+ * @param options - parsed CLI options whose `args` list the kbid or
36
+ * docid identifiers to compose
37
+ * @returns the composed content result from the daemon
38
+ */
39
+ export declare function runContent(client: ContentClient, options: CliOptions): Promise<ContentResult>;
40
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { CommandResult } from '../typings/command-result.model.ts';
3
+ import type { InitResult } from './run-init.function.ts';
4
+ /**
5
+ * Callable signature for the init operation injected into
6
+ * `runDbInit`.
7
+ */
8
+ export type RunInitFn = (options: CliOptions) => InitResult;
9
+ /**
10
+ * Executes the `db init` compound command by delegating to the
11
+ * provided `runInit` function and mapping the result to a
12
+ * `CommandResult`.
13
+ *
14
+ * Accepts `runInit` as an injectable parameter so the function
15
+ * can be tested without touching the filesystem.
16
+ *
17
+ * @param options - parsed CLI options (forwarded to `runInitFn`)
18
+ * @param runInitFn - function that performs the actual
19
+ * initialisation
20
+ * @returns a `CommandResult` with JSON output on success or an
21
+ * error message on failure
22
+ */
23
+ export declare function runDbInit(options: CliOptions, runInitFn: RunInitFn): CommandResult;
@@ -0,0 +1,32 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { MigrateResult } from '../../worker-client/typings/migrate-result.model.ts';
3
+ /**
4
+ * Minimal client interface required by `runDbMigrate`.
5
+ *
6
+ * Intentionally narrower than `MigrateClient` from
7
+ * `run-migrate.function.ts` — this variant skips the version
8
+ * check and unconditionally runs migrations. Callers that need
9
+ * version-aware migration should use `runMigrate` instead.
10
+ */
11
+ export interface DbMigrateClient {
12
+ /**
13
+ * Runs all pending database migrations.
14
+ *
15
+ * @param targetPath - absolute path to the `.kbdb` database root
16
+ */
17
+ migrateDatabase(targetPath: string): Promise<MigrateResult>;
18
+ }
19
+ /**
20
+ * Runs database migrations unconditionally via `client.migrateDatabase`.
21
+ *
22
+ * Resolves the target path from `options.dbPath` when provided,
23
+ * falling back to `process.cwd()`. Does not perform a version
24
+ * compatibility check before migrating — use `runMigrate` for
25
+ * version-aware migration flows.
26
+ *
27
+ * @param client - database migration client to delegate to
28
+ * @param options - parsed CLI options supplying the optional
29
+ * `dbPath`
30
+ * @returns the migration report returned by the daemon
31
+ */
32
+ export declare function runDbMigrate(client: DbMigrateClient, options: CliOptions): Promise<MigrateResult>;
@@ -0,0 +1,38 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /**
3
+ * Garbage collection report returned by the daemon.
4
+ */
5
+ interface GcResult {
6
+ /** Number of unreferenced sections removed. */
7
+ readonly removed_sections: number;
8
+ /** Total bytes freed by removing unreferenced sections. */
9
+ readonly removed_bytes: number;
10
+ /** Time taken to complete garbage collection, in milliseconds. */
11
+ readonly elapsed_ms: number;
12
+ }
13
+ /**
14
+ * Minimal client interface required by `runGc`.
15
+ *
16
+ * Decouples the CLI function from the concrete `WorkerClient`
17
+ * implementation, making it straightforward to test with mocks.
18
+ */
19
+ export interface GcClient {
20
+ /**
21
+ * Removes unreferenced sections from the database.
22
+ *
23
+ * @returns a report of sections removed and bytes freed
24
+ */
25
+ gc(): Promise<GcResult>;
26
+ }
27
+ /**
28
+ * Runs garbage collection on the database and returns the report.
29
+ *
30
+ * Delegates to `client.gc()`. The caller is responsible for printing
31
+ * the result to stdout.
32
+ *
33
+ * @param client - gc client to delegate to
34
+ * @param _options - parsed CLI options (unused; reserved for future flags)
35
+ * @returns the garbage collection report from the daemon
36
+ */
37
+ export declare function runGc(client: GcClient, _options: CliOptions): Promise<GcResult>;
38
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /**
3
+ * Result returned by `runInit` describing whether the directory was
4
+ * successfully initialised.
5
+ */
6
+ export interface InitResult {
7
+ /** `true` when the database directory was created successfully. */
8
+ readonly ok: boolean;
9
+ /** Absolute path to the directory that was (or should have been) initialised. */
10
+ readonly targetPath: string;
11
+ /**
12
+ * Human-readable error message when `ok` is `false`.
13
+ * `undefined` when `ok` is `true`.
14
+ */
15
+ readonly errorMessage?: string;
16
+ }
17
+ /**
18
+ * Initialises a new `.kbdb` database directory.
19
+ *
20
+ * Creates the full scaffold directly on disk without requiring a
21
+ * running worker daemon. Resolves the target path from
22
+ * `options.dbPath` or `process.cwd()`.
23
+ *
24
+ * @param options - parsed CLI options supplying the optional `dbPath`
25
+ * @returns init result indicating success or failure
26
+ */
27
+ export declare function runInit(options: CliOptions): InitResult;
@@ -0,0 +1,46 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { LearnResult } from '../typings/learn-result.model.ts';
3
+ /**
4
+ * Minimal client interface required by `runLearn`.
5
+ *
6
+ * Decouples the CLI function from the concrete `WorkerClient`
7
+ * implementation, making it straightforward to test with mocks.
8
+ */
9
+ export interface LearnClient {
10
+ /**
11
+ * Ingests a content section into the knowledge base.
12
+ *
13
+ * @param params - section type label and raw text content
14
+ * @returns result object containing the knowledge-base identifier
15
+ * assigned to the section
16
+ */
17
+ addSection(params: {
18
+ sectionType: string;
19
+ content: string;
20
+ title?: string;
21
+ description?: string;
22
+ docid?: string;
23
+ }): Promise<{
24
+ kbid: string;
25
+ }>;
26
+ }
27
+ /** Injectable I/O for testing without real stdin. */
28
+ export interface LearnIO {
29
+ readStdin: () => Promise<string>;
30
+ }
31
+ /**
32
+ * Ingests one or more files or directories listed in `options.args`
33
+ * into the knowledge base via the provided client.
34
+ *
35
+ * Each argument is resolved to a set of supported files. Unsupported
36
+ * extensions, dotfiles, dot-directories, and non-existent paths are
37
+ * silently skipped. The `-` argument reads content from stdin
38
+ * (consumed only once).
39
+ *
40
+ * @param client - learn client to delegate ingestion to
41
+ * @param options - parsed CLI options whose `args` list targets to
42
+ * ingest
43
+ * @param io - injectable I/O (defaults to reading process.stdin)
44
+ * @returns one `LearnResult` per file successfully ingested
45
+ */
46
+ export declare function runLearn(client: LearnClient, options: CliOptions, io?: LearnIO): Promise<LearnResult[]>;