@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,14 @@
1
+ /** A single ranked result returned by a search query. */
2
+ export interface SearchResult {
3
+ /** Knowledge-base identifier for the matched section. */
4
+ readonly kbid: string;
5
+ /** Relevance score assigned by the ranking engine. */
6
+ readonly score: number;
7
+ /** Terms that matched within this section. */
8
+ readonly matches: readonly {
9
+ /** The matched term. */
10
+ readonly term: string;
11
+ /** Number of times the term appears in the section. */
12
+ readonly frequency: number;
13
+ }[];
14
+ }
@@ -0,0 +1,26 @@
1
+ /** A content section stored in the knowledge-base. */
2
+ export interface Section {
3
+ /** Knowledge-base identifier for this section. */
4
+ readonly kbid: string;
5
+ /** Parent document identifier, if the section belongs to one. */
6
+ readonly docid?: string;
7
+ /** Semantic type label assigned to the section. */
8
+ readonly sectionType: string;
9
+ /** Raw text content of the section. */
10
+ readonly content: string;
11
+ /** Byte size of the stored content. */
12
+ readonly size: number;
13
+ /** Unix epoch timestamp (ms) when the section was created. */
14
+ readonly createdAt: number;
15
+ /** SHA-256 checksum of the stored content. */
16
+ readonly checksum: string;
17
+ }
18
+ /** Parameters required to add or update a section. */
19
+ export interface AddSectionParams {
20
+ /** Semantic type label to assign to the section. */
21
+ readonly sectionType: string;
22
+ /** Raw text content for the section. */
23
+ readonly content: string;
24
+ /** Parent document identifier to associate the section with. */
25
+ readonly docid?: string;
26
+ }
@@ -0,0 +1,14 @@
1
+ /** Diagnostic status returned by the worker daemon. */
2
+ export interface StatusResult {
3
+ /** Whether the daemon has finished loading its WASM modules. */
4
+ readonly initialized: boolean;
5
+ /** Absolute path to the context directory the daemon serves. */
6
+ readonly contextPath: string;
7
+ /** In-memory cache statistics. */
8
+ readonly cacheStats: {
9
+ /** Number of content entries currently cached. */
10
+ readonly contentCount: number;
11
+ /** Number of index entries currently cached. */
12
+ readonly indexCount: number;
13
+ };
14
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Compatibility status categories returned by a database version check.
3
+ *
4
+ * - `'compatible'` -- database version matches the WASM engine version
5
+ * - `'needs_migration'` -- database is older and must be migrated with
6
+ * `kbdb --migrate`
7
+ * - `'too_new'` -- database was created by a newer version of kbdb;
8
+ * upgrade the kbdb binary
9
+ */
10
+ export type VersionCompatibility = 'compatible' | 'needs_migration' | 'too_new';
11
+ /**
12
+ * Version compatibility status returned by a database version check.
13
+ */
14
+ export interface VersionStatus {
15
+ /** The format version stored in the database's `catalog.toml`. */
16
+ readonly currentVersion: number;
17
+ /**
18
+ * The format version required by the current WASM engine.
19
+ * Equivalent to `DB_FORMAT_VERSION` from the Rust shared crate.
20
+ */
21
+ readonly requiredVersion: number;
22
+ /** Compatibility result between the database and WASM engine. */
23
+ readonly status: VersionCompatibility;
24
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * An error returned by the worker daemon over JSON-RPC,
3
+ * carrying a numeric error code alongside the message.
4
+ */
5
+ export interface WorkerClientError extends Error {
6
+ /** JSON-RPC error code returned by the daemon. */
7
+ readonly code: number;
8
+ }
@@ -0,0 +1,30 @@
1
+ /** Options for configuring a WorkerClient connection. */
2
+ export interface WorkerClientOptions {
3
+ /**
4
+ * Path to the directory containing the `.kbdb` database
5
+ * folder. Defaults to `process.cwd()` when omitted.
6
+ */
7
+ readonly dbPath?: string;
8
+ /**
9
+ * Absolute path to the context directory. When provided,
10
+ * skips the `.kbdb` discovery step performed by `dbPath`.
11
+ */
12
+ readonly contextPath?: string;
13
+ /**
14
+ * When `true` (default), automatically spawns the worker
15
+ * daemon if it is not already running before connecting.
16
+ * Set to `false` to require a running daemon.
17
+ */
18
+ readonly autoSpawn?: boolean;
19
+ /**
20
+ * Maximum milliseconds to wait for the daemon PID file to
21
+ * appear after spawning. Defaults to 10 000 ms.
22
+ */
23
+ readonly connectTimeoutMs?: number;
24
+ /**
25
+ * Absolute path to the worker daemon script. Resolved
26
+ * once at the entry point and injected here so that
27
+ * `spawnDaemon` needs no runtime-specific path logic.
28
+ */
29
+ readonly workerScript?: string;
30
+ }
@@ -0,0 +1,147 @@
1
+ import type { DaemonConfig } from '../typings/daemon-config.interface.ts';
2
+ import type { WasmModules } from '../typings/wasm-modules.interface.ts';
3
+ import type { IpcRequest, IpcResponse } from '../typings/ipc-handler.interface.ts';
4
+ /**
5
+ * Core daemon class that manages the full worker daemon lifecycle.
6
+ *
7
+ * Orchestrates WASM module loading, IPC server creation, request
8
+ * routing to `kb-worker.wasm` exports, idle timeout tracking, and
9
+ * graceful shutdown. The daemon validates startup preconditions before
10
+ * loading WASM modules and rejects IPC requests whose `ctx` param does
11
+ * not match the daemon's context ID.
12
+ */
13
+ export declare class WorkerDaemon {
14
+ /** Context ID (16-character hex SHA-256 prefix). */
15
+ readonly ctx: string;
16
+ /** Absolute path to the `.kbdb` directory. */
17
+ readonly targetDir: string;
18
+ /** Parsed daemon configuration from `worker.toml`. */
19
+ readonly config: DaemonConfig;
20
+ /** Number of currently active IPC client connections. */
21
+ get connectionCount(): number;
22
+ private _connectionCount;
23
+ private _wasmModules;
24
+ private _idleAt;
25
+ private _idleTimer;
26
+ private _server;
27
+ private readonly _wasmDir;
28
+ /**
29
+ * @param ctx - context ID (16-hex characters), the first 16 of
30
+ * the SHA-256 hash of `targetDir`
31
+ * @param targetDir - absolute path to the `.kbdb` directory
32
+ * @param config - parsed daemon configuration
33
+ * @param wasmDir - path to the WASM build output directory
34
+ */
35
+ constructor(ctx: string, targetDir: string, config: DaemonConfig, wasmDir?: string);
36
+ /**
37
+ * Validates startup preconditions before WASM module loading.
38
+ *
39
+ * Checks that the database directory exists, is readable and
40
+ * writable, and that `catalog.toml` reports a compatible version.
41
+ *
42
+ * @throws {Error} if any precondition fails -- `startDaemon`
43
+ * catches this, prints to stderr, and exits with code 1
44
+ */
45
+ checkPreconditions(): void;
46
+ /**
47
+ * Starts the daemon: loads WASM modules, writes the PID file,
48
+ * creates the IPC socket, and begins listening for connections.
49
+ *
50
+ * Call `checkPreconditions()` before `start()` to validate the
51
+ * database directory. The daemon will not start if any precondition
52
+ * fails.
53
+ *
54
+ * @throws when WASM module loading fails or the IPC socket cannot
55
+ * be created
56
+ */
57
+ start(): Promise<void>;
58
+ /**
59
+ * Gracefully shuts down the daemon.
60
+ *
61
+ * Stops accepting new connections, clears the idle timer, purges
62
+ * WASM state, removes the PID file and IPC socket file, then exits
63
+ * the process.
64
+ */
65
+ stop(): void;
66
+ /**
67
+ * Handles a single JSON-RPC 2.0 request.
68
+ *
69
+ * Validates context, then routes to a daemon-state handler or a
70
+ * WASM export. Requests whose `ctx` param does not match the
71
+ * daemon's context ID are rejected with error code `-32001`.
72
+ *
73
+ * @param request - incoming JSON-RPC request
74
+ * @returns the JSON-RPC response
75
+ */
76
+ handleRequest(request: IpcRequest): Promise<IpcResponse>;
77
+ /**
78
+ * Increments the active connection count.
79
+ *
80
+ * Call when a new IPC client connects.
81
+ */
82
+ incrementConnections(): void;
83
+ /**
84
+ * Decrements the active connection count, clamped to zero.
85
+ *
86
+ * Call when an IPC client disconnects.
87
+ */
88
+ decrementConnections(): void;
89
+ /**
90
+ * Injects pre-built WASM modules for unit testing.
91
+ *
92
+ * This method exists solely to support unit tests that cannot
93
+ * load real WASM binaries. It must not be called in production
94
+ * code -- production code uses `start()` to load modules.
95
+ *
96
+ * @param modules - pre-built WASM module instances
97
+ * @internal
98
+ */
99
+ injectModulesForTesting(modules: WasmModules): void;
100
+ /** Resets the idle timer; triggers stop() when it fires. */
101
+ private resetIdleTimer;
102
+ /** Reads catalog.toml and validates the version field. */
103
+ private checkCatalogVersion;
104
+ /** Builds a JSON-RPC error response. */
105
+ private errorResponse;
106
+ /**
107
+ * Dispatches a request method to the appropriate handler.
108
+ *
109
+ * Handles daemon-state methods (`status`, `idle_at`,
110
+ * `config_{key}`) inline and routes WASM methods to the
111
+ * correct calling convention for each export.
112
+ */
113
+ private dispatch;
114
+ private dispatchWasm;
115
+ private handleSearch;
116
+ private handleResultStatus;
117
+ private handleGetResult;
118
+ private handleAddSection;
119
+ private handleUpdateSection;
120
+ private handleReadSections;
121
+ private handleGroupSections;
122
+ private handleCompose;
123
+ private handleRemoveSection;
124
+ private handleRetrieveDoc;
125
+ private handleRemoveGrouping;
126
+ private handleInitDirectory;
127
+ private handleInvalidate;
128
+ private handleListByType;
129
+ private handleListDocsByType;
130
+ private handleInvalidateAll;
131
+ private handleDbStatus;
132
+ private handleIntegrityCheck;
133
+ private handleGc;
134
+ private handleRebuild;
135
+ private initWorkerContext;
136
+ private getExport;
137
+ private wasmAlloc;
138
+ private wasmFree;
139
+ private wasmWrite;
140
+ private readReturnSlot;
141
+ private callWasmSync;
142
+ private callWasmZeroArg;
143
+ private invokeWasmRaw;
144
+ private handleCheckVersion;
145
+ /** Returns a daemon config value by config method name. */
146
+ private handleConfigMethod;
147
+ }
@@ -0,0 +1,24 @@
1
+ /** Default maximum number of items held in daemon memory. */
2
+ export declare const DEFAULT_ITEM_LIMIT = 1000;
3
+ /** Default maximum number of index entries held in daemon memory. */
4
+ export declare const DEFAULT_INDEX_LIMIT = 100;
5
+ /**
6
+ * Default idle timeout in milliseconds before the daemon shuts
7
+ * down automatically (5 minutes).
8
+ */
9
+ export declare const DEFAULT_TIMEOUT_MS = 300000;
10
+ /**
11
+ * Default time-to-live in milliseconds for each cached item
12
+ * (1 minute).
13
+ */
14
+ export declare const DEFAULT_ITEM_TTL_MS = 60000;
15
+ /** Filename of the daemon configuration file inside `.kbdb/`. */
16
+ export declare const WORKER_TOML_FILENAME = "worker.toml";
17
+ /**
18
+ * Database format version the daemon supports.
19
+ *
20
+ * Read from `catalog.toml` at startup. If the catalog version
21
+ * differs, the daemon prints a structured error to stderr and
22
+ * exits with code 1 before loading any WASM modules.
23
+ */
24
+ export declare const DB_FORMAT_VERSION = 1;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Minimal filesystem operations required by the host imports.
3
+ *
4
+ * The default implementation delegates to `node:fs` synchronous
5
+ * APIs. Tests inject a stub to avoid touching the real filesystem.
6
+ */
7
+ export interface FsAdapter {
8
+ /** Read entire file as a Buffer. */
9
+ readFileSync(path: string): Buffer;
10
+ /** Write data buffer to file. */
11
+ writeFileSync(path: string, data: Uint8Array): void;
12
+ /** Rename `oldPath` to `newPath`. */
13
+ renameSync(oldPath: string, newPath: string): void;
14
+ /** Delete a file. */
15
+ unlinkSync(path: string): void;
16
+ /** List directory entries as strings. */
17
+ readdirSync(path: string): string[];
18
+ /** Create a directory (and parents) recursively. */
19
+ mkdirSync(path: string): void;
20
+ /** Return true if the path exists. */
21
+ existsSync(path: string): boolean;
22
+ }
23
+ /**
24
+ * A mutable reference to the WASM linear memory.
25
+ *
26
+ * The `memory` field starts as `null` and is wired up after the
27
+ * `kb-worker` WASM module is instantiated (the module exports its
28
+ * own memory rather than importing one). Host import functions
29
+ * read `memory` at call time, not at creation time, so the ref
30
+ * can be populated after the import record is built.
31
+ */
32
+ export interface MemoryRef {
33
+ memory: WebAssembly.Memory | null;
34
+ }
35
+ /**
36
+ * A mutable reference to the WASM allocator function.
37
+ *
38
+ * The `alloc` field starts as `null` and is wired up after the
39
+ * `kb-worker` WASM module is instantiated. Host import functions
40
+ * that must allocate memory in WASM linear memory check this
41
+ * reference before proceeding and return -1 when it is null.
42
+ */
43
+ export interface AllocatorRef {
44
+ /**
45
+ * Allocates `size` bytes in WASM linear memory and returns the
46
+ * byte offset of the allocated region, or `null` when the
47
+ * allocator is not yet available.
48
+ */
49
+ alloc: ((size: number) => number) | null;
50
+ }
51
+ /**
52
+ * Creates the host I/O import functions required by `kb-worker.wasm`.
53
+ *
54
+ * All functions read the WASM linear memory through `memoryRef`,
55
+ * a deferred reference wired up after module instantiation (the
56
+ * module exports its own memory). Paths from WASM are resolved
57
+ * relative to `contextPath`.
58
+ *
59
+ * @param contextPath - absolute path to the `.kbdb` database directory
60
+ * @param memoryRef - deferred reference to the WASM module's
61
+ * exported memory; wired after instantiation
62
+ * @param fs - filesystem adapter; defaults to real `node:fs` operations
63
+ * @param allocator - reference to the WASM allocator; wired after
64
+ * `kb-worker` instantiation. Defaults to a null (uninitialized) ref.
65
+ * @returns a record of host import functions keyed by their WASM import
66
+ * names
67
+ */
68
+ export declare function createHostImports(contextPath: string, memoryRef?: MemoryRef, fs?: FsAdapter, allocator?: AllocatorRef): Record<string, WebAssembly.ImportValue>;
@@ -0,0 +1,18 @@
1
+ import type { Server } from 'node:net';
2
+ import type { IpcHandler } from '../typings/ipc-handler.interface.ts';
3
+ /**
4
+ * Creates a Unix socket (or named pipe on Windows) IPC server that
5
+ * reads newline-delimited JSON-RPC requests and writes responses.
6
+ *
7
+ * Each line received on a socket connection is parsed as an
8
+ * `IpcRequest`, dispatched to `handler`, and the resulting
9
+ * `IpcResponse` is written back as a newline-terminated JSON string.
10
+ * A malformed line that cannot be parsed results in a JSON-RPC
11
+ * parse-error response (`-32700`).
12
+ *
13
+ * @param socketPath - path to the Unix domain socket or Windows
14
+ * named pipe
15
+ * @param handler - async function invoked for each valid request
16
+ * @returns the listening `net.Server` instance
17
+ */
18
+ export declare function createIpcServer(socketPath: string, handler: IpcHandler): Server;
@@ -0,0 +1,19 @@
1
+ import type { DaemonConfig } from '../typings/daemon-config.interface.ts';
2
+ import type { WasmModules } from '../typings/wasm-modules.interface.ts';
3
+ /**
4
+ * Loads and instantiates the `kb-worker` WASM module.
5
+ *
6
+ * `kb-worker.wasm` statically links the `fs-database` and
7
+ * `query-parser` crates, so only one module needs to be
8
+ * instantiated. The module exports its own linear memory;
9
+ * host I/O imports read it through a deferred `MemoryRef`
10
+ * that is wired up immediately after instantiation.
11
+ *
12
+ * @param config - daemon configuration, used to supply the context
13
+ * path to the host I/O imports
14
+ * @param wasmDir - absolute path to the directory containing the
15
+ * compiled WASM subdirectories (`query-parser/`, `fs-database/`,
16
+ * `kb-worker/`)
17
+ * @throws when the WASM file cannot be read or instantiated
18
+ */
19
+ export declare function loadWasmModules(config: DaemonConfig, wasmDir: string): Promise<WasmModules>;
@@ -0,0 +1,12 @@
1
+ import type { DaemonConfig } from '../typings/daemon-config.interface.ts';
2
+ /**
3
+ * Reads the `worker.toml` configuration file from the given
4
+ * context directory and returns a `DaemonConfig`.
5
+ *
6
+ * Falls back to all-default values when the file is absent or
7
+ * unreadable.
8
+ *
9
+ * @param contextPath - absolute path to the `.kbdb` context
10
+ * directory
11
+ */
12
+ export declare function readConfig(contextPath: string): DaemonConfig;
@@ -0,0 +1,26 @@
1
+ /** Result of the worker entry point. */
2
+ export interface WorkerResult {
3
+ /** Error message (if any). */
4
+ error?: string;
5
+ /** Process exit code. `0` means success. */
6
+ exitCode: number;
7
+ }
8
+ /**
9
+ * Injectable dependencies for the worker entry point.
10
+ */
11
+ export interface WorkerDeps {
12
+ existsSync: (path: string) => boolean;
13
+ startDaemon: (contextPath: string, wasmDir?: string) => Promise<void>;
14
+ wasmDir?: string;
15
+ }
16
+ /**
17
+ * Worker daemon entry point extracted from `src/worker.ts`.
18
+ *
19
+ * Validates the context path argument, resolves it to an
20
+ * absolute path, checks existence, and delegates to
21
+ * `startDaemon`.
22
+ *
23
+ * @param argv - raw arguments (expects `[contextPath]`)
24
+ * @param deps - injectable dependencies
25
+ */
26
+ export declare function runWorker(argv: string[], deps: WorkerDeps): Promise<WorkerResult>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Starts the worker daemon for the given knowledge-base context.
3
+ *
4
+ * Reads configuration from `worker.toml` in the context directory,
5
+ * validates startup preconditions (directory exists, accessible, and
6
+ * database version compatible), and then starts the `WorkerDaemon`.
7
+ *
8
+ * Signal handlers for `SIGTERM` and `SIGINT` trigger a graceful stop.
9
+ * Precondition failures are printed to stderr and cause exit code 1.
10
+ *
11
+ * @param contextPath - absolute path to the `.kbdb` context directory
12
+ */
13
+ export declare function startDaemon(contextPath: string, wasmDir?: string): Promise<void>;
@@ -0,0 +1,9 @@
1
+ export { readConfig } from './functions/read-config.function.ts';
2
+ export { startDaemon } from './functions/start-daemon.function.ts';
3
+ export { createIpcServer } from './functions/create-ipc-server.function.ts';
4
+ export { loadWasmModules } from './functions/load-wasm-modules.function.ts';
5
+ export type { DaemonConfig } from './typings/daemon-config.interface.ts';
6
+ export type { WasmModules } from './typings/wasm-modules.interface.ts';
7
+ export type { IpcRequest, IpcResponse, IpcHandler, } from './typings/ipc-handler.interface.ts';
8
+ export { runWorker } from './functions/run-worker.function.ts';
9
+ export type { WorkerResult, WorkerDeps, } from './functions/run-worker.function.ts';
@@ -0,0 +1,13 @@
1
+ /** Configuration for the worker daemon process. */
2
+ export interface DaemonConfig {
3
+ /** Absolute path to the knowledge-base context directory. */
4
+ readonly contextPath: string;
5
+ /** Maximum number of items held in memory at once. */
6
+ readonly itemLimit: number;
7
+ /** Maximum number of index entries held in memory at once. */
8
+ readonly indexLimit: number;
9
+ /** Idle timeout in milliseconds before the daemon shuts down. */
10
+ readonly timeoutMs: number;
11
+ /** Time-to-live in milliseconds for each cached item. */
12
+ readonly itemTtlMs: number;
13
+ }
@@ -0,0 +1,36 @@
1
+ /** A JSON-RPC 2.0 request sent to the daemon over IPC. */
2
+ export interface IpcRequest {
3
+ /** JSON-RPC version string -- always `'2.0'`. */
4
+ readonly jsonrpc: '2.0';
5
+ /** Request identifier, echoed back in the response. */
6
+ readonly id: number | string;
7
+ /** Method name to invoke on the daemon. */
8
+ readonly method: string;
9
+ /** Optional method parameters. */
10
+ readonly params?: unknown;
11
+ }
12
+ /** Error detail included in a failed JSON-RPC response. */
13
+ export interface IpcErrorDetail {
14
+ /** JSON-RPC error code. */
15
+ readonly code: number;
16
+ /** Human-readable error message. */
17
+ readonly message: string;
18
+ /** Optional additional error data. */
19
+ readonly data?: unknown;
20
+ }
21
+ /** A JSON-RPC 2.0 response returned by the daemon over IPC. */
22
+ export interface IpcResponse {
23
+ /** JSON-RPC version string -- always `'2.0'`. */
24
+ readonly jsonrpc: '2.0';
25
+ /** Identifier matching the originating request. */
26
+ readonly id: number | string;
27
+ /** Successful result payload. Present on success. */
28
+ readonly result?: unknown;
29
+ /** Error detail. Present on failure. */
30
+ readonly error?: IpcErrorDetail;
31
+ }
32
+ /**
33
+ * Function that handles a single IPC request and returns a
34
+ * JSON-RPC response.
35
+ */
36
+ export type IpcHandler = (request: IpcRequest) => Promise<IpcResponse>;
@@ -0,0 +1,7 @@
1
+ /** Loaded and instantiated WASM module instances. */
2
+ export interface WasmModules {
3
+ /** Linear memory exported by the kb-worker WASM module. */
4
+ readonly memory: WebAssembly.Memory;
5
+ /** Instantiated kb-worker WASM module. */
6
+ readonly kbWorker: WebAssembly.Instance;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;