@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,57 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { MigrateResult } from '../../worker-client/typings/migrate-result.model.ts';
3
+ import type { VersionCompatibility, VersionStatus } from '../../worker-client/typings/version-status.model.ts';
4
+ /**
5
+ * Result returned by `runMigrate` describing the outcome of the
6
+ * migration attempt.
7
+ */
8
+ export interface MigrateCommandResult {
9
+ /**
10
+ * The compatibility status returned by the version check.
11
+ * Mirrors `VersionStatus.status`.
12
+ */
13
+ readonly status: VersionCompatibility;
14
+ /** Full version status from the pre-migration check. */
15
+ readonly versionStatus: VersionStatus;
16
+ /**
17
+ * Migration report when `status` is `'needs_migration'`.
18
+ * `undefined` for `'compatible'` and `'too_new'` outcomes.
19
+ */
20
+ readonly migrateResult?: MigrateResult;
21
+ }
22
+ /**
23
+ * Minimal client interface required by `runMigrate`.
24
+ *
25
+ * Decouples the CLI function from the concrete `WorkerClient`
26
+ * implementation, making it straightforward to test with mocks.
27
+ */
28
+ export interface MigrateClient {
29
+ /**
30
+ * Checks the database format version against the WASM engine.
31
+ *
32
+ * @param targetPath - absolute path to the `.kbdb` database root
33
+ */
34
+ checkVersion(targetPath: string): Promise<VersionStatus>;
35
+ /**
36
+ * Runs all pending database migrations.
37
+ *
38
+ * @param targetPath - absolute path to the `.kbdb` database root
39
+ */
40
+ migrateDatabase(targetPath: string): Promise<MigrateResult>;
41
+ }
42
+ /**
43
+ * Checks the database version and runs pending migrations when needed.
44
+ *
45
+ * Resolution order:
46
+ * - `'compatible'`: returns without running migrations
47
+ * - `'needs_migration'`: calls `client.migrateDatabase` and returns
48
+ * the migration report
49
+ * - `'too_new'`: returns without running migrations (caller should
50
+ * print an error and exit non-zero)
51
+ *
52
+ * @param client - migrate client to delegate to
53
+ * @param options - parsed CLI options supplying the optional `dbPath`
54
+ * @returns result containing the version status and optional migration
55
+ * report
56
+ */
57
+ export declare function runMigrate(client: MigrateClient, options: CliOptions): Promise<MigrateCommandResult>;
@@ -0,0 +1,40 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /**
3
+ * Index rebuild report returned by the daemon.
4
+ */
5
+ interface RebuildResult {
6
+ /** Number of text and code sections that were re-indexed. */
7
+ readonly sections_reindexed: number;
8
+ /** Total number of unique terms written to the rebuilt indexes. */
9
+ readonly terms_indexed: number;
10
+ /** Time taken to complete the rebuild, in milliseconds. */
11
+ readonly elapsed_ms: number;
12
+ }
13
+ /**
14
+ * Minimal client interface required by `runRebuild`.
15
+ *
16
+ * Decouples the CLI function from the concrete `WorkerClient`
17
+ * implementation, making it straightforward to test with mocks.
18
+ */
19
+ export interface RebuildClient {
20
+ /**
21
+ * Reconstructs all index files from section files and document
22
+ * manifests on disk. Text and code sections are re-tokenized;
23
+ * image sections are skipped.
24
+ *
25
+ * @returns a report of sections and terms re-indexed
26
+ */
27
+ rebuildIndexes(): Promise<RebuildResult>;
28
+ }
29
+ /**
30
+ * Rebuilds all database indexes and returns the report.
31
+ *
32
+ * Delegates to `client.rebuildIndexes()`. The caller is responsible
33
+ * for printing the result to stdout.
34
+ *
35
+ * @param client - rebuild client to delegate to
36
+ * @param _options - parsed CLI options (unused; reserved for future flags)
37
+ * @returns the index rebuild report from the daemon
38
+ */
39
+ export declare function runRebuild(client: RebuildClient, _options: CliOptions): Promise<RebuildResult>;
40
+ export {};
@@ -0,0 +1,39 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { SearchDisplay } from '../typings/search-display.model.ts';
3
+ /**
4
+ * Minimal client interface required by `runSearch`.
5
+ *
6
+ * Decouples the CLI function from the concrete `WorkerClient`
7
+ * implementation, making it straightforward to test with mocks.
8
+ */
9
+ export interface SearchClient {
10
+ /**
11
+ * Searches the knowledge base and returns ranked results.
12
+ *
13
+ * @param params - query, mode, and result limit
14
+ */
15
+ search(params: {
16
+ query: string;
17
+ mode?: string;
18
+ limit?: number;
19
+ }): Promise<{
20
+ kbid: string;
21
+ score: number;
22
+ readonly matches: readonly {
23
+ readonly term: string;
24
+ readonly frequency: number;
25
+ }[];
26
+ }[]>;
27
+ }
28
+ /**
29
+ * Executes a search query via the provided client and maps the raw
30
+ * daemon results to the `SearchDisplay` format used by the CLI.
31
+ *
32
+ * Returns an empty array without calling the client when `options.args`
33
+ * contains no query terms.
34
+ *
35
+ * @param client - search client to delegate to
36
+ * @param options - parsed CLI options supplying query args and search
37
+ * parameters
38
+ */
39
+ export declare function runSearch(client: SearchClient, options: CliOptions): Promise<SearchDisplay[]>;
@@ -0,0 +1,30 @@
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 `runSkillDelete`.
5
+ *
6
+ * Decouples the CLI function from the concrete `WorkerClient`
7
+ * implementation, making it straightforward to test with mocks.
8
+ */
9
+ export interface SkillDeleteClient {
10
+ /**
11
+ * Removes a section from the knowledge base.
12
+ *
13
+ * @param kbid - knowledge-base identifier of the section to remove
14
+ * @returns result indicating whether the section was found and removed
15
+ */
16
+ removeSection(kbid: string): Promise<{
17
+ removed: boolean;
18
+ }>;
19
+ }
20
+ /**
21
+ * Deletes a skill section from the knowledge base by its kbid.
22
+ *
23
+ * The kbid must be supplied as the first positional argument. Returns
24
+ * an error result if it is missing.
25
+ *
26
+ * @param client - client used to remove the skill section
27
+ * @param options - parsed CLI options; `args[0]` is the kbid
28
+ * @returns a `CommandResult` with the kbid and removal status
29
+ */
30
+ export declare function runSkillDelete(client: SkillDeleteClient, options: CliOptions): Promise<CommandResult>;
@@ -0,0 +1,49 @@
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 `runSkillGet`.
5
+ *
6
+ * Decouples the CLI function from the concrete `WorkerClient`
7
+ * implementation, making it straightforward to test with mocks.
8
+ */
9
+ export interface SkillGetClient {
10
+ /**
11
+ * Retrieves one or more sections by their knowledge-base IDs.
12
+ *
13
+ * @param kbids - list of knowledge-base identifiers to fetch
14
+ * @returns matching section rows
15
+ */
16
+ readSections(kbids: string[]): Promise<{
17
+ kbid: string;
18
+ content: string;
19
+ }[]>;
20
+ /**
21
+ * Retrieves all sections stored with the given type name.
22
+ *
23
+ * @param sectionType - the type name to filter by
24
+ * @returns matching section rows
25
+ */
26
+ listByType(sectionType: string): Promise<{
27
+ kbid: string;
28
+ title: string | null;
29
+ content: string;
30
+ }[]>;
31
+ }
32
+ /**
33
+ * Retrieves a skill definition by name or kbid.
34
+ *
35
+ * Accepts the identifier as the first positional argument or as
36
+ * `options.name`. When the identifier looks like a hex hash
37
+ * (16 or more hex characters) it is tried as a kbid first; if
38
+ * no section is found it falls back to a name lookup. When the
39
+ * identifier is not hex-like it goes directly to name lookup.
40
+ * For name lookups the most recently stored match (last in the
41
+ * array) is returned.
42
+ *
43
+ * @param client - client used to look up the skill section
44
+ * @param options - parsed CLI options; first positional arg or `name`
45
+ * is used as the identifier
46
+ * @returns a `CommandResult` containing the serialized
47
+ * `SkillDefinition` JSON or an error message
48
+ */
49
+ export declare function runSkillGet(client: SkillGetClient, options: CliOptions): Promise<CommandResult>;
@@ -0,0 +1,36 @@
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 `runSkillLearn`.
6
+ *
7
+ * Decouples the CLI function from the concrete `WorkerClient`
8
+ * implementation, making it straightforward to test with mocks.
9
+ */
10
+ export interface SkillLearnClient {
11
+ /**
12
+ * Stores a skill section in the knowledge base.
13
+ *
14
+ * @param params - section type, serialized JSON content,
15
+ * and optional title and description
16
+ * @returns result containing the assigned kbid
17
+ */
18
+ addSection(params: {
19
+ readonly sectionType: string;
20
+ readonly content: string;
21
+ readonly title?: string;
22
+ readonly description?: string;
23
+ }): Promise<AddSectionResult>;
24
+ }
25
+ /**
26
+ * Creates or updates a skill definition in the knowledge base.
27
+ *
28
+ * Validates that `--name` and `--body` are provided, extracts
29
+ * `{{argName}}` placeholders from the body, serializes the skill
30
+ * to JSON, and stores it as a `'skill'` section.
31
+ *
32
+ * @param client - client used to store the skill section
33
+ * @param options - parsed CLI options with `name` and `body` fields
34
+ * @returns a `CommandResult` with the stored section info or an error
35
+ */
36
+ export declare function runSkillLearn(client: SkillLearnClient, options: CliOptions): Promise<CommandResult>;
@@ -0,0 +1,43 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ import type { CommandResult } from '../typings/command-result.model.ts';
3
+ /**
4
+ * A single row returned by `listByType` for the skill client.
5
+ */
6
+ interface SkillRecord {
7
+ /** Knowledge-base identifier for the skill section. */
8
+ kbid: string;
9
+ /** Skill name stored as the section title. */
10
+ title: string | null;
11
+ /** Optional skill description stored on the section. */
12
+ description: string | null;
13
+ /** Serialized `SkillDefinition` JSON stored as section content. */
14
+ content: string;
15
+ }
16
+ /**
17
+ * Minimal client interface required by `runSkillList`.
18
+ *
19
+ * Decouples the CLI function from the concrete `WorkerClient`
20
+ * implementation, making it straightforward to test with mocks.
21
+ */
22
+ export interface SkillListClient {
23
+ /**
24
+ * Retrieves all sections stored with the given type name.
25
+ *
26
+ * @param sectionType - the type name to filter by
27
+ * @returns matching section rows
28
+ */
29
+ listByType(sectionType: string): Promise<SkillRecord[]>;
30
+ }
31
+ /**
32
+ * Lists all skill definitions stored in the knowledge base.
33
+ *
34
+ * Calls `client.listByType('skill')` and maps each record to a
35
+ * summary that includes the argument count parsed from the JSON
36
+ * content. Parse errors default the argument count to `0`.
37
+ *
38
+ * @param client - client used to list skill sections
39
+ * @param _options - parsed CLI options (unused; reserved for future flags)
40
+ * @returns a `CommandResult` containing a JSON array of skill summaries
41
+ */
42
+ export declare function runSkillList(client: SkillListClient, _options: CliOptions): Promise<CommandResult>;
43
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /**
3
+ * Minimal client interface required by `runStatus`.
4
+ *
5
+ * Decouples the CLI function from the concrete `WorkerClient`
6
+ * implementation, making it straightforward to test with mocks.
7
+ */
8
+ export interface StatusClient {
9
+ dbStatus(): Promise<unknown>;
10
+ }
11
+ /**
12
+ * Retrieves the database status and returns the summary report.
13
+ *
14
+ * Delegates to `client.dbStatus()`. The caller is responsible
15
+ * for serialising the result and setting the process exit code.
16
+ *
17
+ * @param client - status client to delegate to
18
+ * @param _options - parsed CLI options (unused; reserved for
19
+ * future flags)
20
+ * @returns the status report from the daemon
21
+ */
22
+ export declare function runStatus(client: StatusClient, _options: CliOptions): Promise<unknown>;
@@ -0,0 +1,45 @@
1
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
2
+ /** Removal result returned by `UnlearnClient.removeSection`. */
3
+ interface RemoveSectionResult {
4
+ /** `true` when the section was found and successfully removed. */
5
+ readonly removed: boolean;
6
+ /** Time taken to perform the removal, in milliseconds. */
7
+ readonly elapsed_ms: number;
8
+ }
9
+ /**
10
+ * Minimal client interface required by `runUnlearn`.
11
+ *
12
+ * Decouples the CLI function from the concrete `WorkerClient`
13
+ * implementation, making it straightforward to test with mocks.
14
+ */
15
+ export interface UnlearnClient {
16
+ /**
17
+ * Removes a section from the knowledge base.
18
+ *
19
+ * @param kbid - identifier of the section to remove
20
+ * @returns removal result with `removed` flag and elapsed time
21
+ */
22
+ removeSection(kbid: string): Promise<RemoveSectionResult>;
23
+ }
24
+ /** Result record produced for each kbid processed by the unlearn command. */
25
+ export interface UnlearnResult {
26
+ /** Knowledge-base identifier that was targeted for removal. */
27
+ kbid: string;
28
+ /** `true` when the section was found and successfully removed. */
29
+ removed: boolean;
30
+ }
31
+ /**
32
+ * Removes the knowledge-base sections identified by `options.args`
33
+ * via the provided client.
34
+ *
35
+ * Each kbid in `options.args` is processed independently. If a kbid
36
+ * does not exist in the knowledge base, `removed` is set to `false`
37
+ * rather than throwing.
38
+ *
39
+ * @param client - unlearn client to delegate removal to
40
+ * @param options - parsed CLI options whose `args` list the kbids to
41
+ * remove
42
+ * @returns one `UnlearnResult` per kbid processed
43
+ */
44
+ export declare function runUnlearn(client: UnlearnClient, options: CliOptions): Promise<UnlearnResult[]>;
45
+ export {};
@@ -0,0 +1,35 @@
1
+ export { parseArgs } from './functions/parse-args.function.ts';
2
+ export { formatOutput } from './functions/format-output.function.ts';
3
+ export { runSearch } from './functions/run-search.function.ts';
4
+ export { runLearn } from './functions/run-learn.function.ts';
5
+ export { runUnlearn } from './functions/run-unlearn.function.ts';
6
+ export { runContent } from './functions/run-content.function.ts';
7
+ export { runCheck } from './functions/run-check.function.ts';
8
+ export { runGc } from './functions/run-gc.function.ts';
9
+ export { runRebuild } from './functions/run-rebuild.function.ts';
10
+ export { ensureDb } from './functions/ensure-db.function.ts';
11
+ export { findDb } from './functions/find-db.function.ts';
12
+ export { runInit } from './functions/run-init.function.ts';
13
+ export { runMigrate } from './functions/run-migrate.function.ts';
14
+ export { errorToMessage } from './functions/error-to-message.function.ts';
15
+ export { isStdinTty } from './functions/is-stdin-tty.function.ts';
16
+ export { promptUser } from './functions/prompt-user.function.ts';
17
+ export { dispatchCommand } from './functions/dispatch-command.function.ts';
18
+ export { runCli } from './functions/run-cli.function.ts';
19
+ export { HELP_TEXT } from './constants/help-text.constant.ts';
20
+ export type { CliOptions, OutputFormat, SearchMode, } from './typings/cli-options.interface.ts';
21
+ export type { LearnResult } from './typings/learn-result.model.ts';
22
+ export type { SearchDisplay } from './typings/search-display.model.ts';
23
+ export type { SearchClient } from './functions/run-search.function.ts';
24
+ export type { LearnClient } from './functions/run-learn.function.ts';
25
+ export type { UnlearnClient, UnlearnResult, } from './functions/run-unlearn.function.ts';
26
+ export type { ContentClient } from './functions/run-content.function.ts';
27
+ export type { CheckClient } from './functions/run-check.function.ts';
28
+ export type { GcClient } from './functions/run-gc.function.ts';
29
+ export type { RebuildClient } from './functions/run-rebuild.function.ts';
30
+ export type { InitResult } from './functions/run-init.function.ts';
31
+ export type { MigrateClient, MigrateCommandResult, } from './functions/run-migrate.function.ts';
32
+ export type { CommandResult } from './typings/command-result.model.ts';
33
+ export type { PromptIO } from './functions/prompt-user.function.ts';
34
+ export type { DispatchClient } from './functions/dispatch-command.function.ts';
35
+ export type { CliDeps, DisconnectableClient, } from './functions/run-cli.function.ts';
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Supported output formats for CLI results.
3
+ *
4
+ * - `'json'` -- machine-readable JSON array
5
+ * - `'text'` -- human-readable numbered list
6
+ * - `'mcp'` -- JSON envelope for MCP protocol consumers
7
+ */
8
+ export type OutputFormat = 'json' | 'text' | 'mcp';
9
+ /**
10
+ * Controls which entity type is returned by a search query.
11
+ *
12
+ * - `'sections'` -- individual content sections (default)
13
+ * - `'documents'` -- document-level groupings
14
+ * - `'stats'` -- index statistics
15
+ */
16
+ export type SearchMode = 'sections' | 'documents' | 'stats';
17
+ /** Parsed representation of all CLI arguments for a single invocation. */
18
+ export interface CliOptions {
19
+ /** The sub-command to execute (e.g. `'search'`, `'learn'`). */
20
+ command: string;
21
+ /**
22
+ * Path to the knowledge-base root directory.
23
+ * Defaults to the current working directory when omitted.
24
+ */
25
+ dbPath?: string;
26
+ /** Output format for results. Defaults to `'json'`. */
27
+ format: OutputFormat;
28
+ /** Search mode passed to the worker daemon. Defaults to `'sections'`. */
29
+ mode: SearchMode;
30
+ /** Maximum number of results to return. Defaults to 20. */
31
+ limit: number;
32
+ /** Section title for learn command. */
33
+ title?: string;
34
+ /** Section description for learn command. */
35
+ description?: string;
36
+ /** Document ID for learn command. */
37
+ docid?: string;
38
+ /**
39
+ * When `true`, hydrates each search result's `preview` field
40
+ * with the section's actual content via `client.content()`.
41
+ */
42
+ content?: boolean;
43
+ /** Skill or agent name for skill/agent commands. */
44
+ name?: string;
45
+ /** Agent persona content or file path. */
46
+ persona?: string;
47
+ /** Skill body content or file path. */
48
+ body?: string;
49
+ /** Comma-separated skill kbids for agent create. */
50
+ skills?: string[];
51
+ /** Positional arguments following the sub-command. */
52
+ args: string[];
53
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Result of dispatching a CLI command.
3
+ *
4
+ * Encapsulates output, error text, and exit code so the
5
+ * caller can decide how to present them (console, MCP, etc.)
6
+ * without the dispatch function touching process globals.
7
+ */
8
+ export interface CommandResult {
9
+ /** Text to write to stdout (if any). */
10
+ output?: string;
11
+ /** Error message to write to stderr (if any). */
12
+ error?: string;
13
+ /** Process exit code. `0` means success. */
14
+ exitCode: number;
15
+ }
@@ -0,0 +1,11 @@
1
+ /** Result record produced for each file processed by the learn command. */
2
+ export interface LearnResult {
3
+ /** Knowledge-base identifier assigned to the ingested section. */
4
+ kbid: string;
5
+ /** Absolute path to the source file that was ingested. */
6
+ path: string;
7
+ /** Size of the file content in bytes (UTF-8 character count). */
8
+ size: number;
9
+ /** `true` when the file was skipped without being ingested. */
10
+ skipped: boolean;
11
+ }
@@ -0,0 +1,17 @@
1
+ /** A single search result formatted for display to the user. */
2
+ export interface SearchDisplay {
3
+ /** Knowledge-base identifier of the matched section. */
4
+ kbid: string;
5
+ /** Relevance score assigned by the ranking engine. */
6
+ score: number;
7
+ /**
8
+ * Short excerpt from the section content.
9
+ * Empty string when no preview text is available.
10
+ */
11
+ preview: string;
12
+ /** Terms that matched within this section and their frequencies. */
13
+ readonly matches: readonly {
14
+ readonly term: string;
15
+ readonly frequency: number;
16
+ }[];
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { BaseDir } from '../typings/base-dir.interface.ts';
2
+ export declare function resolveScriptDir(entryUrl: string, entryDirname?: string): string;
3
+ export declare function resolveBaseDir(entryUrl: string, entryDirname?: string): BaseDir;
@@ -0,0 +1 @@
1
+ export declare function resolveWasmDir(scriptDir: string): string;
@@ -0,0 +1,2 @@
1
+ import type { Runtime } from '../../runtime/typings/runtime.ts';
2
+ export declare function resolveWorkerScript(scriptDir: string, runtime: Runtime): string;
@@ -0,0 +1,4 @@
1
+ export { resolveBaseDir, resolveScriptDir, } from './functions/resolve-base-dir.function.ts';
2
+ export { resolveWorkerScript } from './functions/resolve-worker-script.function.ts';
3
+ export { resolveWasmDir } from './functions/resolve-wasm-dir.function.ts';
4
+ export type { BaseDir } from './typings/base-dir.interface.ts';
@@ -0,0 +1,4 @@
1
+ export interface BaseDir {
2
+ readonly scriptDir: string;
3
+ readonly cwd: string;
4
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Computes the SHA-256 hash of a UTF-8 string.
3
+ *
4
+ * Uses the Web Crypto API (`crypto.subtle`), which is available
5
+ * in both Deno and Node.js >= 20 without additional imports.
6
+ *
7
+ * @param input - the string to hash
8
+ * @returns lowercase hex-encoded SHA-256 digest (64 characters)
9
+ */
10
+ export declare function computeSha256(input: string): Promise<string>;
@@ -0,0 +1 @@
1
+ export { computeSha256 } from './functions/compute-sha256.ts';
@@ -0,0 +1,55 @@
1
+ import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
+ import type { McpResponse } from '../typings/mcp-types.interface.ts';
3
+ import type { McpLogLevel } from '../typings/log-types.interface.ts';
4
+ /**
5
+ * MCP server that speaks JSON-RPC 2.0 over stdio. Listens for
6
+ * newline-delimited requests on `process.stdin`, dispatches each
7
+ * to the appropriate knowledge-base operation via
8
+ * `McpWorkerClient`, and writes JSON-RPC responses to
9
+ * `process.stdout`.
10
+ */
11
+ export declare class McpServer {
12
+ private readonly client;
13
+ private readonly contextPath;
14
+ private initialized;
15
+ private hostCapabilities;
16
+ private logLevel;
17
+ private readonly subscriptions;
18
+ private nextRequestId;
19
+ private readonly pendingRequests;
20
+ constructor(client: McpWorkerClient, contextPath?: string);
21
+ listen(): Promise<void>;
22
+ handleLineForTest(line: string): Promise<McpResponse | null>;
23
+ /**
24
+ * Sends a JSON-RPC notification (no `id`, no response
25
+ * expected) to stdout.
26
+ */
27
+ notify(method: string, params?: Record<string, unknown>): void;
28
+ /**
29
+ * Emits a log notification if the message severity meets or
30
+ * exceeds the configured log level threshold.
31
+ */
32
+ log(level: McpLogLevel, message: unknown, logger?: string): void;
33
+ /**
34
+ * Sends a JSON-RPC request to the host (server-to-client)
35
+ * and returns a Promise that resolves with the response
36
+ * result. Times out after 30 seconds.
37
+ */
38
+ sendRequest(method: string, params: Record<string, unknown>): Promise<unknown>;
39
+ /**
40
+ * Requests the host to generate text via the sampling
41
+ * capability. Throws if the host did not advertise sampling
42
+ * support during initialization.
43
+ */
44
+ requestSampling(messages: {
45
+ role: string;
46
+ content: {
47
+ type: string;
48
+ text: string;
49
+ };
50
+ }[], maxTokens: number): Promise<unknown>;
51
+ private dispatchLine;
52
+ private processLine;
53
+ private handleRequest;
54
+ private send;
55
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * JSON-RPC 2.0 parse error code. Returned when the
3
+ * server receives malformed JSON.
4
+ */
5
+ export declare const PARSE_ERROR = -32700;
6
+ /**
7
+ * JSON-RPC 2.0 method not found error code. Returned
8
+ * when the requested method does not exist.
9
+ */
10
+ export declare const METHOD_NOT_FOUND = -32601;
11
+ /**
12
+ * JSON-RPC 2.0 invalid params error code. Returned
13
+ * when method parameters are invalid or missing.
14
+ */
15
+ export declare const INVALID_PARAMS = -32602;
16
+ /**
17
+ * JSON-RPC 2.0 internal error code. Returned when an
18
+ * unexpected server-side error occurs.
19
+ */
20
+ export declare const INTERNAL_ERROR = -32603;
21
+ /**
22
+ * MCP-specific resource not found error code. Returned
23
+ * when a well-formed URI does not match any resource
24
+ * in the knowledge base.
25
+ */
26
+ export declare const RESOURCE_NOT_FOUND = -32002;
@@ -0,0 +1,11 @@
1
+ import { McpServer } from '../classes/mcp-server.class.ts';
2
+ import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
3
+ /**
4
+ * Factory that constructs a new `McpServer` bound to the given
5
+ * worker client. Call `server.listen()` on the returned instance
6
+ * to start processing stdio input.
7
+ *
8
+ * @param client - worker client providing knowledge-base operations
9
+ * @returns a configured `McpServer` ready to listen
10
+ */
11
+ export declare function createMcpServer(client: McpWorkerClient): McpServer;