@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,160 @@
1
+ import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
+ import type { AgentDefinition } from '../typings/agent-types.interface.ts';
3
+
4
+ /** Shape of a content item in an MCP tool call response. */
5
+ interface ToolContent {
6
+ /** Content type identifier, typically `'text'`. */
7
+ readonly type: string;
8
+ /** The text payload. */
9
+ readonly text: string;
10
+ }
11
+
12
+ /** Result returned by the agent-get tool handler. */
13
+ interface ToolCallResult {
14
+ /** One or more content items describing the result. */
15
+ readonly content: ToolContent[];
16
+ /** Set to `true` when the tool encountered an error. */
17
+ readonly isError?: boolean;
18
+ }
19
+
20
+ /** Parsed shape of an agent document section list entry. */
21
+ interface DocumentSection {
22
+ /** Knowledge-base identifier of the section. */
23
+ readonly kbid: string;
24
+ /** Zero-based position of the section within the document. */
25
+ readonly position: number;
26
+ }
27
+
28
+ /** Parsed shape of a retrieved agent document. */
29
+ interface AgentDocument {
30
+ /** Document identifier. */
31
+ readonly docid: string;
32
+ /** Document title used as agent name fallback. */
33
+ readonly title: string;
34
+ /** Ordered list of sections in the document. */
35
+ readonly sections: DocumentSection[];
36
+ }
37
+
38
+ /**
39
+ * Reads the metadata JSON stored in the first section of an agent
40
+ * document and extracts `name`, `description`, and `persona`.
41
+ */
42
+ async function readAgentMeta(
43
+ client: McpWorkerClient,
44
+ metaKbid: string,
45
+ fallbackName: string,
46
+ ): Promise<{ name: string; description: string; persona: string }> {
47
+ const metaSections = await client.readSections([metaKbid]);
48
+ const first = metaSections.at(0);
49
+ if (!first) {
50
+ return { name: fallbackName, description: '', persona: '' };
51
+ }
52
+ try {
53
+ const meta = JSON.parse(first.content) as Record<string, unknown>;
54
+ return {
55
+ name:
56
+ typeof meta['name'] === 'string'
57
+ ? meta['name']
58
+ : fallbackName,
59
+ description:
60
+ typeof meta['description'] === 'string'
61
+ ? meta['description']
62
+ : '',
63
+ persona:
64
+ typeof meta['persona'] === 'string' ? meta['persona'] : '',
65
+ };
66
+ } catch {
67
+ return { name: fallbackName, description: '', persona: '' };
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Resolves skill names for a list of section references by reading
73
+ * each section's JSON content and extracting the `name` field.
74
+ * Returns `null` for skill references where the section no longer
75
+ * exists (dangling references).
76
+ */
77
+ async function resolveSkillRefs(
78
+ client: McpWorkerClient,
79
+ skillRefs: DocumentSection[],
80
+ ): Promise<{ kbid: string; name: string | null; position: number }[]> {
81
+ if (skillRefs.length === 0) {
82
+ return [];
83
+ }
84
+ const skillKbids = skillRefs.map((s) => s.kbid);
85
+ const skillSections = await client.readSections(skillKbids);
86
+ const sectionMap = new Map(skillSections.map((s) => [s.kbid, s]));
87
+ return skillRefs.map((ref) => {
88
+ const sec = sectionMap.get(ref.kbid);
89
+ if (!sec) {
90
+ return { kbid: ref.kbid, name: null, position: ref.position };
91
+ }
92
+ try {
93
+ const parsed = JSON.parse(sec.content) as Record<
94
+ string,
95
+ unknown
96
+ >;
97
+ const skillName =
98
+ typeof parsed['name'] === 'string' ? parsed['name'] : null;
99
+ return {
100
+ kbid: ref.kbid,
101
+ name: skillName,
102
+ position: ref.position,
103
+ };
104
+ } catch {
105
+ return { kbid: ref.kbid, name: null, position: ref.position };
106
+ }
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Handles the `agent:get` MCP tool call.
112
+ *
113
+ * Retrieves an agent document by its `docid`, reads the metadata
114
+ * section and skill references, and returns a full `AgentDefinition`.
115
+ * Dangling skill references (sections that no longer exist) appear
116
+ * with `name: null` in the skills list.
117
+ *
118
+ * @param client - the worker client used to execute operations
119
+ * @param args - tool arguments; must include a `docid` string
120
+ * @returns content items containing the serialised `AgentDefinition`
121
+ */
122
+ export async function handleAgentGet(
123
+ client: McpWorkerClient,
124
+ args: Record<string, unknown>,
125
+ ): Promise<ToolCallResult> {
126
+ const docid = typeof args['docid'] === 'string' ? args['docid'] : '';
127
+ if (!docid) {
128
+ return {
129
+ content: [{ type: 'text', text: 'docid is required' }],
130
+ isError: true,
131
+ };
132
+ }
133
+
134
+ const doc = (await client.retrieveDocument(docid)) as AgentDocument;
135
+ const metaKbid = doc.sections[0]?.kbid;
136
+ const skillRefs = doc.sections.slice(1);
137
+
138
+ const { name, description, persona } = metaKbid
139
+ ? await readAgentMeta(client, metaKbid, doc.title)
140
+ : { name: doc.title, description: '', persona: '' };
141
+
142
+ const skills = await resolveSkillRefs(client, skillRefs);
143
+
144
+ const agent: AgentDefinition = {
145
+ docid,
146
+ name,
147
+ description,
148
+ persona,
149
+ skills,
150
+ };
151
+
152
+ return {
153
+ content: [
154
+ {
155
+ type: 'text',
156
+ text: JSON.stringify(agent, null, 2),
157
+ },
158
+ ],
159
+ };
160
+ }
@@ -0,0 +1,50 @@
1
+ import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
+
3
+ /** Shape of a content item in an MCP tool call response. */
4
+ interface ToolContent {
5
+ /** Content type identifier, typically `'text'`. */
6
+ readonly type: string;
7
+ /** The text payload. */
8
+ readonly text: string;
9
+ }
10
+
11
+ /** Result returned by the agent-list tool handler. */
12
+ interface ToolCallResult {
13
+ /** One or more content items describing the result. */
14
+ readonly content: ToolContent[];
15
+ /** Set to `true` when the tool encountered an error. */
16
+ readonly isError?: boolean;
17
+ }
18
+
19
+ /**
20
+ * Handles the `agent:list` MCP tool call.
21
+ *
22
+ * Retrieves all documents with `doc_type: 'agent'` and returns a
23
+ * summary list containing each agent's document identifier, name,
24
+ * and skill count.
25
+ *
26
+ * The `skillCount` is `Math.max(0, sections.length - 1)` because
27
+ * the first section of an agent document always holds the metadata
28
+ * JSON and does not count as a skill reference.
29
+ *
30
+ * @param client - the worker client used to execute operations
31
+ * @returns content items with the serialised agent list
32
+ */
33
+ export async function handleAgentList(
34
+ client: McpWorkerClient,
35
+ ): Promise<ToolCallResult> {
36
+ const docs = await client.listDocumentsByType('agent');
37
+ const items = docs.map((d) => ({
38
+ docid: d.docid,
39
+ name: d.title,
40
+ skillCount: Math.max(0, d.sections.length - 1),
41
+ }));
42
+ return {
43
+ content: [
44
+ {
45
+ type: 'text',
46
+ text: JSON.stringify(items, null, 2),
47
+ },
48
+ ],
49
+ };
50
+ }
@@ -0,0 +1,114 @@
1
+ import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
+
3
+ /**
4
+ * Discriminated reference used in MCP completion requests.
5
+ * Identifies whether the completion target is a prompt or a resource.
6
+ */
7
+ export interface McpCompletionRef {
8
+ /**
9
+ * The reference type: `'ref/prompt'` for named prompts (skills
10
+ * and agents) or `'ref/resource'` for resource URIs.
11
+ */
12
+ readonly type: 'ref/prompt' | 'ref/resource';
13
+ /** Prompt name, present when `type` is `'ref/prompt'`. */
14
+ readonly name?: string;
15
+ /** Resource URI, present when `type` is `'ref/resource'`. */
16
+ readonly uri?: string;
17
+ }
18
+
19
+ /**
20
+ * Completion argument supplied by the client, describing which
21
+ * argument is being completed and the current partial value.
22
+ */
23
+ export interface McpCompletionArgument {
24
+ /** The argument name being completed. */
25
+ readonly name: string;
26
+ /** The partial value typed so far; used for prefix filtering. */
27
+ readonly value: string;
28
+ }
29
+
30
+ /**
31
+ * Result returned by `handleCompletion`, containing the list of
32
+ * matching completion values and pagination metadata.
33
+ */
34
+ export interface McpCompletionResult {
35
+ /** Completion payload. */
36
+ readonly completion: {
37
+ /** Matching completion strings for the given prefix. */
38
+ readonly values: string[];
39
+ /**
40
+ * Whether more results are available beyond what is returned.
41
+ * Always `false` in this implementation.
42
+ */
43
+ readonly hasMore: boolean;
44
+ /** Total number of values returned. */
45
+ readonly total: number;
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Handles an MCP `completion/complete` request.
51
+ *
52
+ * For `ref/prompt` references, builds a list of all skill titles and
53
+ * agent titles (prefixed with `agent:`) and filters by the supplied
54
+ * argument value prefix. For `ref/resource` references, returns an
55
+ * empty result — resource completion is not implemented.
56
+ *
57
+ * @param ref - discriminated reference identifying the completion target
58
+ * @param argument - current argument name and partial value
59
+ * @param client - worker client used to fetch skills and agents
60
+ * @returns matching completion values with pagination metadata
61
+ */
62
+ export async function handleCompletion(
63
+ ref: McpCompletionRef,
64
+ argument: McpCompletionArgument,
65
+ client: McpWorkerClient,
66
+ ): Promise<McpCompletionResult> {
67
+ if (ref.type !== 'ref/prompt') {
68
+ return { completion: { values: [], hasMore: false, total: 0 } };
69
+ }
70
+
71
+ const [skills, agents] = await Promise.all([
72
+ client.listByType('skill'),
73
+ client.listDocumentsByType('agent'),
74
+ ]);
75
+
76
+ const names: string[] = [];
77
+
78
+ for (const skill of skills) {
79
+ if (skill.title !== null) {
80
+ names.push(skill.title);
81
+ }
82
+ }
83
+
84
+ for (const agent of agents) {
85
+ names.push(`agent:${agent.title}`);
86
+ }
87
+
88
+ const prefix = argument.value;
89
+
90
+ function matchesPrefix(candidate: string): boolean {
91
+ if (prefix.length === 0) {
92
+ return true;
93
+ }
94
+ if (candidate.startsWith(prefix)) {
95
+ return true;
96
+ }
97
+ // For agent-prefixed names, also match against the title portion.
98
+ const AGENT_PREFIX = 'agent:';
99
+ if (candidate.startsWith(AGENT_PREFIX)) {
100
+ return candidate.slice(AGENT_PREFIX.length).startsWith(prefix);
101
+ }
102
+ return false;
103
+ }
104
+
105
+ const values = names.filter(matchesPrefix);
106
+
107
+ return {
108
+ completion: {
109
+ values,
110
+ hasMore: false,
111
+ total: values.length,
112
+ },
113
+ };
114
+ }
@@ -0,0 +1,214 @@
1
+ import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
+ import type { McpPromptMessage } from '../typings/prompt-types.interface.ts';
3
+
4
+ /** Parsed shape of an agent metadata section. */
5
+ interface AgentMeta {
6
+ /** Agent persona text. */
7
+ readonly persona: string;
8
+ }
9
+
10
+ /** Minimal section shape returned by readSections. */
11
+ interface ReadSection {
12
+ /** Knowledge-base identifier. */
13
+ readonly kbid: string;
14
+ /** Raw text content. */
15
+ readonly content: string;
16
+ }
17
+
18
+ /** Minimal agent document shape returned by retrieveDocument. */
19
+ interface AgentDocument {
20
+ /** Document identifier. */
21
+ readonly docid: string;
22
+ /** Document title. */
23
+ readonly title: string;
24
+ /** Ordered section references. */
25
+ readonly sections: readonly {
26
+ readonly kbid: string;
27
+ readonly position: number;
28
+ }[];
29
+ }
30
+
31
+ /**
32
+ * Parses agent metadata from a raw JSON content string.
33
+ *
34
+ * Returns default values when parsing fails or required fields are
35
+ * absent.
36
+ */
37
+ function parseAgentMeta(content: string): AgentMeta {
38
+ try {
39
+ const parsed = JSON.parse(content) as Record<string, unknown>;
40
+ return {
41
+ persona:
42
+ typeof parsed['persona'] === 'string'
43
+ ? parsed['persona']
44
+ : '',
45
+ };
46
+ } catch {
47
+ return { persona: '' };
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Builds the skills listing user message text from an array of
53
+ * skill section content strings. Sections whose JSON is not parseable
54
+ * or whose name cannot be determined are omitted silently.
55
+ *
56
+ * Returns `null` when no valid skills remain after filtering.
57
+ */
58
+ function buildSkillsText(skillSections: ReadSection[]): string | null {
59
+ const lines: string[] = [];
60
+ for (const sec of skillSections) {
61
+ try {
62
+ const parsed = JSON.parse(sec.content) as Record<
63
+ string,
64
+ unknown
65
+ >;
66
+ const name =
67
+ typeof parsed['name'] === 'string' ? parsed['name'] : null;
68
+ if (name === null) {
69
+ continue;
70
+ }
71
+ const description =
72
+ typeof parsed['description'] === 'string'
73
+ ? parsed['description']
74
+ : '';
75
+ lines.push(`- ${name}: ${description}`);
76
+ } catch {
77
+ // skip unparseable sections
78
+ }
79
+ }
80
+ if (lines.length === 0) {
81
+ return null;
82
+ }
83
+ return `Available skills:\n${lines.join('\n')}`;
84
+ }
85
+
86
+ /**
87
+ * Handles an MCP `prompts/get` request for an agent prompt.
88
+ *
89
+ * Reads the agent document, extracts its persona from the metadata
90
+ * section, then reads all skill sections and composes the response.
91
+ * Returns an assistant message with the persona and, when skills
92
+ * exist, a user message listing them.
93
+ */
94
+ async function handleAgentPrompt(
95
+ name: string,
96
+ client: McpWorkerClient,
97
+ ): Promise<McpPromptMessage[]> {
98
+ const docid = name.slice(6);
99
+ const doc = (await client.retrieveDocument(docid)) as AgentDocument;
100
+ const sections = doc.sections;
101
+
102
+ const metaSection = sections.at(0);
103
+ const skillRefs = sections.slice(1);
104
+
105
+ let persona = '';
106
+ if (metaSection !== undefined) {
107
+ const metaSections = await client.readSections([
108
+ metaSection.kbid,
109
+ ]);
110
+ const metaContent = metaSections.at(0);
111
+ if (metaContent !== undefined) {
112
+ persona = parseAgentMeta(metaContent.content).persona;
113
+ }
114
+ }
115
+
116
+ const messages: McpPromptMessage[] = [
117
+ {
118
+ role: 'assistant',
119
+ content: { type: 'text', text: persona },
120
+ },
121
+ ];
122
+
123
+ if (skillRefs.length === 0) {
124
+ return messages;
125
+ }
126
+
127
+ const skillKbids = skillRefs.map((s) => s.kbid);
128
+ const skillSections = await client.readSections(skillKbids);
129
+ const skillsText = buildSkillsText(skillSections);
130
+
131
+ if (skillsText !== null) {
132
+ messages.push({
133
+ role: 'user',
134
+ content: { type: 'text', text: skillsText },
135
+ });
136
+ }
137
+
138
+ return messages;
139
+ }
140
+
141
+ /**
142
+ * Handles an MCP `prompts/get` request for a skill prompt.
143
+ *
144
+ * Looks up the skill by name in the `listByType('skill')` results,
145
+ * picks the most recent match (last occurrence), parses its body,
146
+ * and substitutes `{{argName}}` placeholders from `promptArgs`.
147
+ * Unresolved placeholders are left as-is.
148
+ *
149
+ * @throws {Error} when no skill with the given name is found
150
+ */
151
+ async function handleSkillPrompt(
152
+ name: string,
153
+ promptArgs: Record<string, string>,
154
+ client: McpWorkerClient,
155
+ ): Promise<McpPromptMessage[]> {
156
+ const sections = await client.listByType('skill');
157
+ let matchContent: string | undefined;
158
+ for (const sec of sections) {
159
+ if (sec.title === name) {
160
+ matchContent = sec.content;
161
+ }
162
+ }
163
+ if (matchContent === undefined) {
164
+ throw new Error(`Prompt not found: ${name}`);
165
+ }
166
+
167
+ const parsed = JSON.parse(matchContent) as Record<string, unknown>;
168
+ const body =
169
+ typeof parsed['body'] === 'string' ? parsed['body'] : '';
170
+
171
+ const rendered = body.replace(
172
+ /\{\{(\w+)\}\}/g,
173
+ (_match, key: string) =>
174
+ key in promptArgs ? (promptArgs[key] ?? _match) : _match,
175
+ );
176
+
177
+ return [
178
+ {
179
+ role: 'user',
180
+ content: { type: 'text', text: rendered },
181
+ },
182
+ ];
183
+ }
184
+
185
+ /**
186
+ * Handles an MCP `prompts/get` request.
187
+ *
188
+ * Dispatches to the agent handler when `name` starts with `"agent:"`,
189
+ * otherwise treats the name as a skill prompt.
190
+ *
191
+ * For skill prompts: looks up by title using `listByType('skill')`,
192
+ * substitutes `{{argName}}` placeholders in the body, and returns a
193
+ * single user message.
194
+ *
195
+ * For agent prompts: reads the agent document via `retrieveDocument`,
196
+ * builds an assistant message from the persona section, and (when
197
+ * skills exist) a user message listing their names and descriptions.
198
+ *
199
+ * @param name - prompt name from the MCP request
200
+ * @param promptArgs - argument key-value map from the MCP request
201
+ * @param client - worker client used to access the knowledge base
202
+ * @returns ordered list of prompt messages to return to the caller
203
+ * @throws {Error} when a skill prompt name is not found in the store
204
+ */
205
+ export async function handlePromptGet(
206
+ name: string,
207
+ promptArgs: Record<string, string>,
208
+ client: McpWorkerClient,
209
+ ): Promise<McpPromptMessage[]> {
210
+ if (name.startsWith('agent:')) {
211
+ return handleAgentPrompt(name, client);
212
+ }
213
+ return handleSkillPrompt(name, promptArgs, client);
214
+ }
@@ -0,0 +1,56 @@
1
+ import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
+
3
+ /** A single content item in an MCP resource read response. */
4
+ interface ResourceContent {
5
+ /** The resource URI that was read. */
6
+ readonly uri: string;
7
+ /** MIME type of the content body. */
8
+ readonly mimeType: string;
9
+ /** Text body of the resource. */
10
+ readonly text: string;
11
+ }
12
+
13
+ /** Result returned by a resource read operation. */
14
+ interface ResourceReadResult {
15
+ /** One or more content items for the requested URI. */
16
+ readonly contents: ResourceContent[];
17
+ }
18
+
19
+ /**
20
+ * Handles an MCP `resources/read` request by dispatching to the
21
+ * appropriate knowledge-base operation based on the resource URI.
22
+ *
23
+ * @param client - the worker client used to fetch the resource
24
+ * @param uri - the resource URI from the MCP request
25
+ * @returns contents array for the MCP response
26
+ * @throws {Error} when the URI does not match any known pattern
27
+ */
28
+ export async function handleResourceRead(
29
+ client: McpWorkerClient,
30
+ uri: string,
31
+ ): Promise<ResourceReadResult> {
32
+ const sectionMatch = uri.match(/^kbdb:\/\/section\/(.+)$/);
33
+ if (sectionMatch) {
34
+ const sections = await client.readSections([sectionMatch[1]]);
35
+ const text = sections.length > 0 ? sections[0].content : '';
36
+ return {
37
+ contents: [{ uri, mimeType: 'text/plain', text }],
38
+ };
39
+ }
40
+
41
+ const docMatch = uri.match(/^kbdb:\/\/document\/(.+)$/);
42
+ if (docMatch) {
43
+ const doc = await client.retrieveDocument(docMatch[1]);
44
+ return {
45
+ contents: [
46
+ {
47
+ uri,
48
+ mimeType: 'application/json',
49
+ text: JSON.stringify(doc, null, 2),
50
+ },
51
+ ],
52
+ };
53
+ }
54
+
55
+ throw new Error(`Unknown resource URI: ${uri}`);
56
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Represents a single file-system root entry advertised to MCP
3
+ * clients via the `roots/list` response.
4
+ */
5
+ export interface McpRoot {
6
+ /** Absolute file URI for the root directory. */
7
+ readonly uri: string;
8
+ /** Human-readable label for the root. */
9
+ readonly name: string;
10
+ }
11
+
12
+ /**
13
+ * Returns the list of MCP roots for the given database context path.
14
+ *
15
+ * Produces a single root entry whose URI is `file://` concatenated
16
+ * with the supplied `contextPath`. This tells MCP clients which
17
+ * file-system directory the server is authoritative for.
18
+ *
19
+ * @param contextPath - absolute path to the kbdb database directory
20
+ * @returns array containing a single root for the context path
21
+ */
22
+ export function handleRootsList(contextPath: string): McpRoot[] {
23
+ return [
24
+ {
25
+ uri: `file://${contextPath}`,
26
+ name: 'kbdb database',
27
+ },
28
+ ];
29
+ }