@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.
- package/LICENSE +15 -0
- package/README.md +270 -0
- package/dist/chunk-QCCN7OZH.mjs +82 -0
- package/dist/chunk-QCCN7OZH.mjs.map +7 -0
- package/dist/cli.cjs +3598 -0
- package/dist/cli.cjs.map +7 -0
- package/dist/cli.mjs +3537 -0
- package/dist/cli.mjs.map +7 -0
- package/dist/kbdb-worker.cjs +1659 -0
- package/dist/kbdb-worker.cjs.map +7 -0
- package/dist/mod.cjs +538 -0
- package/dist/mod.cjs.map +7 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.mjs +507 -0
- package/dist/mod.mjs.map +7 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +11 -0
- package/dist/src/shared/cli/constants/help-text.constant.d.ts +2 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +37 -0
- package/dist/src/shared/cli/functions/ensure-db.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/error-to-message.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/find-db.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/generate-help.function.d.ts +31 -0
- package/dist/src/shared/cli/functions/is-stdin-tty.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/parse-args.function.d.ts +25 -0
- package/dist/src/shared/cli/functions/prompt-user.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/run-agent-create.function.d.ts +58 -0
- package/dist/src/shared/cli/functions/run-agent-delete.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-agent-get.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +45 -0
- package/dist/src/shared/cli/functions/run-check.function.d.ts +64 -0
- package/dist/src/shared/cli/functions/run-cli.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-content.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-db-init.function.d.ts +23 -0
- package/dist/src/shared/cli/functions/run-db-migrate.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-gc.function.d.ts +38 -0
- package/dist/src/shared/cli/functions/run-init.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-migrate.function.d.ts +57 -0
- package/dist/src/shared/cli/functions/run-rebuild.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-search.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-skill-delete.function.d.ts +30 -0
- package/dist/src/shared/cli/functions/run-skill-get.function.d.ts +49 -0
- package/dist/src/shared/cli/functions/run-skill-learn.function.d.ts +36 -0
- package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +43 -0
- package/dist/src/shared/cli/functions/run-status.function.d.ts +22 -0
- package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +45 -0
- package/dist/src/shared/cli/index.d.ts +35 -0
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +53 -0
- package/dist/src/shared/cli/typings/command-result.model.d.ts +15 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +11 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +17 -0
- package/dist/src/shared/dir-resolver/functions/resolve-base-dir.function.d.ts +3 -0
- package/dist/src/shared/dir-resolver/functions/resolve-wasm-dir.function.d.ts +1 -0
- package/dist/src/shared/dir-resolver/functions/resolve-worker-script.function.d.ts +2 -0
- package/dist/src/shared/dir-resolver/index.d.ts +4 -0
- package/dist/src/shared/dir-resolver/typings/base-dir.interface.d.ts +4 -0
- package/dist/src/shared/hash/functions/compute-sha256.d.ts +10 -0
- package/dist/src/shared/hash/index.d.ts +1 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +55 -0
- package/dist/src/shared/mcp/constants/mcp-error-codes.constant.d.ts +26 -0
- package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/create-prompt-definitions.function.d.ts +41 -0
- package/dist/src/shared/mcp/functions/create-resource-templates.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/create-tool-definitions.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/extract-skill-arguments.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-agent-create.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-delete.function.d.ts +28 -0
- package/dist/src/shared/mcp/functions/handle-agent-get.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-list.function.d.ts +31 -0
- package/dist/src/shared/mcp/functions/handle-completion.function.d.ts +58 -0
- package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +23 -0
- package/dist/src/shared/mcp/functions/handle-resource-read.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/handle-roots-list.function.d.ts +21 -0
- package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/parse-skill-content.function.d.ts +15 -0
- package/dist/src/shared/mcp/functions/serialize-skill-content.function.d.ts +9 -0
- package/dist/src/shared/mcp/functions/should-emit-log.function.d.ts +20 -0
- package/dist/src/shared/mcp/index.d.ts +9 -0
- package/dist/src/shared/mcp/typings/agent-types.interface.d.ts +38 -0
- package/dist/src/shared/mcp/typings/log-types.interface.d.ts +17 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +217 -0
- package/dist/src/shared/mcp/typings/mcp-types.interface.d.ts +149 -0
- package/dist/src/shared/mcp/typings/prompt-types.interface.d.ts +37 -0
- package/dist/src/shared/mcp/typings/remove-section-result.model.d.ts +10 -0
- package/dist/src/shared/mcp/typings/sampling-types.interface.d.ts +46 -0
- package/dist/src/shared/mcp/typings/skill-types.interface.d.ts +28 -0
- package/dist/src/shared/mod.d.ts +1 -0
- package/dist/src/shared/platform/functions/get-ipc-path.function.d.ts +11 -0
- package/dist/src/shared/platform/functions/get-tmpdir.function.d.ts +4 -0
- package/dist/src/shared/platform/functions/is-process-alive.function.d.ts +10 -0
- package/dist/src/shared/platform/index.d.ts +3 -0
- package/dist/src/shared/runtime/functions/detect-runtime.d.ts +8 -0
- package/dist/src/shared/runtime/functions/get-args.d.ts +7 -0
- package/dist/src/shared/runtime/index.d.ts +3 -0
- package/dist/src/shared/runtime/typings/runtime.d.ts +2 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +2 -0
- package/dist/src/shared/version/index.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-compose-output.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest-list.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest.function.d.ts +40 -0
- package/dist/src/shared/wasm-codec/functions/decode-f32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-key-value-text.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-remove-flag.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record-list.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +50 -0
- package/dist/src/shared/wasm-codec/functions/decode-string.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-u32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-u64.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-group-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-identifier-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-kbid-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-option-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-section-type.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-type-filter-param.function.d.ts +11 -0
- package/dist/src/shared/wasm-codec/functions/encode-u32.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/index.d.ts +29 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +230 -0
- package/dist/src/shared/worker-client/functions/compute-context-id.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/create-worker-client.function.d.ts +18 -0
- package/dist/src/shared/worker-client/functions/discover-daemon.function.d.ts +14 -0
- package/dist/src/shared/worker-client/functions/resolve-db-path.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/wait-for-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-client/index.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/content-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/daemon-info.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +36 -0
- package/dist/src/shared/worker-client/typings/migrate-result.model.d.ts +11 -0
- package/dist/src/shared/worker-client/typings/rebuild-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/remove-section-result.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +26 -0
- package/dist/src/shared/worker-client/typings/status-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/version-status.model.d.ts +24 -0
- package/dist/src/shared/worker-client/typings/worker-client-error.interface.d.ts +8 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +30 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +147 -0
- package/dist/src/shared/worker-daemon/constants/daemon-defaults.constant.d.ts +24 -0
- package/dist/src/shared/worker-daemon/functions/create-host-imports.function.d.ts +68 -0
- package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +18 -0
- package/dist/src/shared/worker-daemon/functions/load-wasm-modules.function.d.ts +19 -0
- package/dist/src/shared/worker-daemon/functions/read-config.function.d.ts +12 -0
- package/dist/src/shared/worker-daemon/functions/run-worker.function.d.ts +26 -0
- package/dist/src/shared/worker-daemon/functions/start-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/index.d.ts +9 -0
- package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +13 -0
- package/dist/src/shared/worker-daemon/typings/ipc-handler.interface.d.ts +36 -0
- package/dist/src/shared/worker-daemon/typings/wasm-modules.interface.d.ts +7 -0
- package/dist/src/worker.d.ts +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/worker.mjs +1615 -0
- package/dist/worker.mjs.map +7 -0
- package/mod.ts +17 -0
- package/package.json +85 -0
- package/src/cli.ts +62 -0
- package/src/shared/cli/constants/defaults.constant.ts +19 -0
- package/src/shared/cli/constants/help-text.constant.ts +4 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +338 -0
- package/src/shared/cli/functions/ensure-db.function.ts +21 -0
- package/src/shared/cli/functions/error-to-message.function.ts +9 -0
- package/src/shared/cli/functions/find-db.function.ts +20 -0
- package/src/shared/cli/functions/format-output.function.ts +64 -0
- package/src/shared/cli/functions/generate-help.function.ts +599 -0
- package/src/shared/cli/functions/is-stdin-tty.function.ts +12 -0
- package/src/shared/cli/functions/parse-args.function.ts +133 -0
- package/src/shared/cli/functions/prompt-user.function.ts +36 -0
- package/src/shared/cli/functions/run-agent-create.function.ts +114 -0
- package/src/shared/cli/functions/run-agent-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-agent-get.function.ts +166 -0
- package/src/shared/cli/functions/run-agent-list.function.ts +58 -0
- package/src/shared/cli/functions/run-check.function.ts +78 -0
- package/src/shared/cli/functions/run-cli.function.ts +299 -0
- package/src/shared/cli/functions/run-content.function.ts +47 -0
- package/src/shared/cli/functions/run-db-init.function.ts +44 -0
- package/src/shared/cli/functions/run-db-migrate.function.ts +40 -0
- package/src/shared/cli/functions/run-gc.function.ts +45 -0
- package/src/shared/cli/functions/run-init.function.ts +91 -0
- package/src/shared/cli/functions/run-learn.function.ts +171 -0
- package/src/shared/cli/functions/run-migrate.function.ts +85 -0
- package/src/shared/cli/functions/run-rebuild.function.ts +47 -0
- package/src/shared/cli/functions/run-search.function.ts +62 -0
- package/src/shared/cli/functions/run-skill-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-skill-get.function.ts +90 -0
- package/src/shared/cli/functions/run-skill-learn.function.ts +70 -0
- package/src/shared/cli/functions/run-skill-list.function.ts +74 -0
- package/src/shared/cli/functions/run-status.function.ts +29 -0
- package/src/shared/cli/functions/run-unlearn.function.ts +58 -0
- package/src/shared/cli/index.ts +48 -0
- package/src/shared/cli/typings/cli-options.interface.ts +55 -0
- package/src/shared/cli/typings/command-result.model.ts +15 -0
- package/src/shared/cli/typings/learn-result.model.ts +11 -0
- package/src/shared/cli/typings/search-display.model.ts +17 -0
- package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +25 -0
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +5 -0
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +13 -0
- package/src/shared/dir-resolver/index.ts +7 -0
- package/src/shared/dir-resolver/typings/base-dir.interface.ts +4 -0
- package/src/shared/hash/functions/compute-sha256.ts +17 -0
- package/src/shared/hash/index.ts +1 -0
- package/src/shared/mcp/classes/mcp-server.class.ts +448 -0
- package/src/shared/mcp/constants/mcp-error-codes.constant.ts +30 -0
- package/src/shared/mcp/functions/create-mcp-server.function.ts +14 -0
- package/src/shared/mcp/functions/create-prompt-definitions.function.ts +102 -0
- package/src/shared/mcp/functions/create-resource-templates.function.ts +23 -0
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +401 -0
- package/src/shared/mcp/functions/extract-skill-arguments.function.ts +27 -0
- package/src/shared/mcp/functions/handle-agent-create.function.ts +116 -0
- package/src/shared/mcp/functions/handle-agent-delete.function.ts +50 -0
- package/src/shared/mcp/functions/handle-agent-get.function.ts +160 -0
- package/src/shared/mcp/functions/handle-agent-list.function.ts +50 -0
- package/src/shared/mcp/functions/handle-completion.function.ts +114 -0
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +214 -0
- package/src/shared/mcp/functions/handle-resource-read.function.ts +56 -0
- package/src/shared/mcp/functions/handle-roots-list.function.ts +29 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +464 -0
- package/src/shared/mcp/functions/parse-skill-content.function.ts +38 -0
- package/src/shared/mcp/functions/serialize-skill-content.function.ts +12 -0
- package/src/shared/mcp/functions/should-emit-log.function.ts +38 -0
- package/src/shared/mcp/index.ts +28 -0
- package/src/shared/mcp/typings/agent-types.interface.ts +39 -0
- package/src/shared/mcp/typings/log-types.interface.ts +26 -0
- package/src/shared/mcp/typings/mcp-client.interface.ts +252 -0
- package/src/shared/mcp/typings/mcp-types.interface.ts +158 -0
- package/src/shared/mcp/typings/prompt-types.interface.ts +39 -0
- package/src/shared/mcp/typings/remove-section-result.model.ts +10 -0
- package/src/shared/mcp/typings/sampling-types.interface.ts +48 -0
- package/src/shared/mcp/typings/skill-types.interface.ts +29 -0
- package/src/shared/mod.ts +1 -0
- package/src/shared/platform/functions/get-ipc-path.function.ts +19 -0
- package/src/shared/platform/functions/get-tmpdir.function.ts +8 -0
- package/src/shared/platform/functions/is-process-alive.function.ts +17 -0
- package/src/shared/platform/index.ts +3 -0
- package/src/shared/runtime/functions/detect-runtime.ts +14 -0
- package/src/shared/runtime/functions/get-args.ts +16 -0
- package/src/shared/runtime/index.ts +3 -0
- package/src/shared/runtime/typings/runtime.ts +2 -0
- package/src/shared/version/constants/version.constant.ts +2 -0
- package/src/shared/version/index.ts +1 -0
- package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +70 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +87 -0
- package/src/shared/wasm-codec/functions/decode-f32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +15 -0
- package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +3 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +54 -0
- package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +20 -0
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +162 -0
- package/src/shared/wasm-codec/functions/decode-string.function.ts +22 -0
- package/src/shared/wasm-codec/functions/decode-u32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-u64.function.ts +16 -0
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +34 -0
- package/src/shared/wasm-codec/functions/encode-group-params.function.ts +28 -0
- package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-option-string.function.ts +14 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-section-type.function.ts +18 -0
- package/src/shared/wasm-codec/functions/encode-string.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +13 -0
- package/src/shared/wasm-codec/functions/encode-u32.function.ts +5 -0
- package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +16 -0
- package/src/shared/wasm-codec/index.ts +36 -0
- package/src/shared/worker-client/classes/worker-client.class.ts +427 -0
- package/src/shared/worker-client/functions/compute-context-id.function.ts +18 -0
- package/src/shared/worker-client/functions/create-worker-client.function.ts +70 -0
- package/src/shared/worker-client/functions/discover-daemon.function.ts +47 -0
- package/src/shared/worker-client/functions/resolve-db-path.function.ts +21 -0
- package/src/shared/worker-client/functions/spawn-daemon.function.ts +35 -0
- package/src/shared/worker-client/functions/wait-for-daemon.function.ts +34 -0
- package/src/shared/worker-client/index.ts +31 -0
- package/src/shared/worker-client/typings/add-section-result.model.ts +22 -0
- package/src/shared/worker-client/typings/content-result.model.ts +12 -0
- package/src/shared/worker-client/typings/daemon-info.model.ts +7 -0
- package/src/shared/worker-client/typings/gc-result.model.ts +12 -0
- package/src/shared/worker-client/typings/integrity-check-result.model.ts +43 -0
- package/src/shared/worker-client/typings/migrate-result.model.ts +11 -0
- package/src/shared/worker-client/typings/rebuild-result.model.ts +12 -0
- package/src/shared/worker-client/typings/remove-section-result.model.ts +7 -0
- package/src/shared/worker-client/typings/search-params.model.ts +12 -0
- package/src/shared/worker-client/typings/search-result.model.ts +14 -0
- package/src/shared/worker-client/typings/section.model.ts +27 -0
- package/src/shared/worker-client/typings/status-result.model.ts +14 -0
- package/src/shared/worker-client/typings/version-status.model.ts +28 -0
- package/src/shared/worker-client/typings/worker-client-error.interface.ts +8 -0
- package/src/shared/worker-client/typings/worker-client-options.interface.ts +30 -0
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +1001 -0
- package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +29 -0
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +312 -0
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +83 -0
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +98 -0
- package/src/shared/worker-daemon/functions/read-config.function.ts +83 -0
- package/src/shared/worker-daemon/functions/run-worker.function.ts +57 -0
- package/src/shared/worker-daemon/functions/start-daemon.function.ts +74 -0
- package/src/shared/worker-daemon/index.ts +16 -0
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +13 -0
- package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +39 -0
- package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +7 -0
- package/src/worker.ts +34 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { CommandResult } from '../typings/command-result.model.ts';
|
|
3
|
+
import type { SearchDisplay } from '../typings/search-display.model.ts';
|
|
4
|
+
import type { LearnIO } from './run-learn.function.ts';
|
|
5
|
+
import type { SearchClient } from './run-search.function.ts';
|
|
6
|
+
import type { LearnClient } from './run-learn.function.ts';
|
|
7
|
+
import type { UnlearnClient } from './run-unlearn.function.ts';
|
|
8
|
+
import type { ContentClient } from './run-content.function.ts';
|
|
9
|
+
import type { CheckClient } from './run-check.function.ts';
|
|
10
|
+
import type { GcClient } from './run-gc.function.ts';
|
|
11
|
+
import type { RebuildClient } from './run-rebuild.function.ts';
|
|
12
|
+
import type { StatusClient } from './run-status.function.ts';
|
|
13
|
+
import type { DbMigrateClient } from './run-db-migrate.function.ts';
|
|
14
|
+
import type { SkillLearnClient } from './run-skill-learn.function.ts';
|
|
15
|
+
import type { SkillListClient } from './run-skill-list.function.ts';
|
|
16
|
+
import type { SkillGetClient } from './run-skill-get.function.ts';
|
|
17
|
+
import type { SkillDeleteClient } from './run-skill-delete.function.ts';
|
|
18
|
+
import type { AgentCreateClient } from './run-agent-create.function.ts';
|
|
19
|
+
import type { AgentListClient } from './run-agent-list.function.ts';
|
|
20
|
+
import type { AgentGetClient } from './run-agent-get.function.ts';
|
|
21
|
+
import type { AgentDeleteClient } from './run-agent-delete.function.ts';
|
|
22
|
+
import { runSearch } from './run-search.function.ts';
|
|
23
|
+
import { runLearn } from './run-learn.function.ts';
|
|
24
|
+
import { runUnlearn } from './run-unlearn.function.ts';
|
|
25
|
+
import { runContent } from './run-content.function.ts';
|
|
26
|
+
import { runCheck } from './run-check.function.ts';
|
|
27
|
+
import { runGc } from './run-gc.function.ts';
|
|
28
|
+
import { runRebuild } from './run-rebuild.function.ts';
|
|
29
|
+
import { runStatus } from './run-status.function.ts';
|
|
30
|
+
import { runDbInit } from './run-db-init.function.ts';
|
|
31
|
+
import { runInit } from './run-init.function.ts';
|
|
32
|
+
import { runDbMigrate } from './run-db-migrate.function.ts';
|
|
33
|
+
import { runSkillLearn } from './run-skill-learn.function.ts';
|
|
34
|
+
import { runSkillList } from './run-skill-list.function.ts';
|
|
35
|
+
import { runSkillGet } from './run-skill-get.function.ts';
|
|
36
|
+
import { runSkillDelete } from './run-skill-delete.function.ts';
|
|
37
|
+
import { runAgentCreate } from './run-agent-create.function.ts';
|
|
38
|
+
import { runAgentList } from './run-agent-list.function.ts';
|
|
39
|
+
import { runAgentGet } from './run-agent-get.function.ts';
|
|
40
|
+
import { runAgentDelete } from './run-agent-delete.function.ts';
|
|
41
|
+
import { formatOutput } from './format-output.function.ts';
|
|
42
|
+
import { errorToMessage } from './error-to-message.function.ts';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Intersection of all data-command client interfaces.
|
|
46
|
+
*
|
|
47
|
+
* Each run* function defines its own minimal interface; this
|
|
48
|
+
* intersection combines them so `dispatchCommand` can route
|
|
49
|
+
* to any command handler with full type safety.
|
|
50
|
+
*/
|
|
51
|
+
export type DispatchClient = SearchClient &
|
|
52
|
+
LearnClient &
|
|
53
|
+
UnlearnClient &
|
|
54
|
+
ContentClient &
|
|
55
|
+
CheckClient &
|
|
56
|
+
GcClient &
|
|
57
|
+
RebuildClient &
|
|
58
|
+
StatusClient &
|
|
59
|
+
DbMigrateClient &
|
|
60
|
+
SkillLearnClient &
|
|
61
|
+
SkillListClient &
|
|
62
|
+
SkillGetClient &
|
|
63
|
+
SkillDeleteClient &
|
|
64
|
+
AgentCreateClient &
|
|
65
|
+
AgentListClient &
|
|
66
|
+
AgentGetClient &
|
|
67
|
+
AgentDeleteClient;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Routes a parsed CLI command to the appropriate handler and
|
|
71
|
+
* returns a `CommandResult` without touching process globals.
|
|
72
|
+
*
|
|
73
|
+
* @param client - worker client covering all data commands
|
|
74
|
+
* @param options - parsed CLI options with command and args
|
|
75
|
+
* @param io - optional injectable I/O for learn stdin
|
|
76
|
+
*/
|
|
77
|
+
export async function dispatchCommand(
|
|
78
|
+
client: DispatchClient,
|
|
79
|
+
options: CliOptions,
|
|
80
|
+
io?: LearnIO,
|
|
81
|
+
): Promise<CommandResult> {
|
|
82
|
+
switch (options.command) {
|
|
83
|
+
case 'learn':
|
|
84
|
+
return handleLearn(client, options, io);
|
|
85
|
+
case 'unlearn':
|
|
86
|
+
return handleUnlearn(client, options);
|
|
87
|
+
case 'search':
|
|
88
|
+
return handleSearch(client, options);
|
|
89
|
+
case 'content':
|
|
90
|
+
return handleContent(client, options);
|
|
91
|
+
case 'check':
|
|
92
|
+
return handleCheck(client, options);
|
|
93
|
+
case 'gc':
|
|
94
|
+
return handleGc(client, options);
|
|
95
|
+
case 'rebuild':
|
|
96
|
+
return handleRebuild(client, options);
|
|
97
|
+
case 'status':
|
|
98
|
+
return handleStatus(client, options);
|
|
99
|
+
case 'db-init':
|
|
100
|
+
return handleDbInit(options);
|
|
101
|
+
case 'db-migrate':
|
|
102
|
+
return handleDbMigrate(client, options);
|
|
103
|
+
case 'skill-learn': {
|
|
104
|
+
const result = await runSkillLearn(client, options);
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
case 'skill-list': {
|
|
108
|
+
const result = await runSkillList(client, options);
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
case 'skill-get': {
|
|
112
|
+
const result = await runSkillGet(client, options);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
case 'skill-delete': {
|
|
116
|
+
const result = await runSkillDelete(client, options);
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
case 'agent-create': {
|
|
120
|
+
const result = await runAgentCreate(client, options);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
case 'agent-list': {
|
|
124
|
+
const result = await runAgentList(client, options);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
case 'agent-get': {
|
|
128
|
+
const result = await runAgentGet(client, options);
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
case 'agent-delete': {
|
|
132
|
+
const result = await runAgentDelete(client, options);
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
default:
|
|
136
|
+
return {
|
|
137
|
+
error: `unknown command: ${options.command}`,
|
|
138
|
+
exitCode: 1,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function handleLearn(
|
|
144
|
+
client: DispatchClient,
|
|
145
|
+
options: CliOptions,
|
|
146
|
+
io?: LearnIO,
|
|
147
|
+
): Promise<CommandResult> {
|
|
148
|
+
try {
|
|
149
|
+
const results = await runLearn(client, options, io);
|
|
150
|
+
return {
|
|
151
|
+
output: JSON.stringify(results, null, 2),
|
|
152
|
+
exitCode: 0,
|
|
153
|
+
};
|
|
154
|
+
} catch (err) {
|
|
155
|
+
return {
|
|
156
|
+
error: `learn failed: ${errorToMessage(err)}`,
|
|
157
|
+
exitCode: 1,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function handleUnlearn(
|
|
163
|
+
client: DispatchClient,
|
|
164
|
+
options: CliOptions,
|
|
165
|
+
): Promise<CommandResult> {
|
|
166
|
+
try {
|
|
167
|
+
const results = await runUnlearn(client, options);
|
|
168
|
+
return {
|
|
169
|
+
output: JSON.stringify(results, null, 2),
|
|
170
|
+
exitCode: 0,
|
|
171
|
+
};
|
|
172
|
+
} catch (err) {
|
|
173
|
+
return {
|
|
174
|
+
error: `unlearn failed: ${errorToMessage(err)}`,
|
|
175
|
+
exitCode: 1,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function handleSearch(
|
|
181
|
+
client: DispatchClient,
|
|
182
|
+
options: CliOptions,
|
|
183
|
+
): Promise<CommandResult> {
|
|
184
|
+
try {
|
|
185
|
+
const results = await runSearch(client, options);
|
|
186
|
+
if (options.content) {
|
|
187
|
+
await hydrateSearchPreviews(client, results);
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
output: formatOutput(results, options.format),
|
|
191
|
+
exitCode: 0,
|
|
192
|
+
};
|
|
193
|
+
} catch (err) {
|
|
194
|
+
return {
|
|
195
|
+
error: `search failed: ${errorToMessage(err)}`,
|
|
196
|
+
exitCode: 1,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function handleContent(
|
|
202
|
+
client: DispatchClient,
|
|
203
|
+
options: CliOptions,
|
|
204
|
+
): Promise<CommandResult> {
|
|
205
|
+
try {
|
|
206
|
+
const result = await runContent(client, options);
|
|
207
|
+
return {
|
|
208
|
+
output: JSON.stringify(result, null, 2),
|
|
209
|
+
exitCode: 0,
|
|
210
|
+
};
|
|
211
|
+
} catch (err) {
|
|
212
|
+
return {
|
|
213
|
+
error: `content failed: ${errorToMessage(err)}`,
|
|
214
|
+
exitCode: 1,
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function handleCheck(
|
|
220
|
+
client: DispatchClient,
|
|
221
|
+
options: CliOptions,
|
|
222
|
+
): Promise<CommandResult> {
|
|
223
|
+
try {
|
|
224
|
+
const result = await runCheck(client, options);
|
|
225
|
+
return {
|
|
226
|
+
output: JSON.stringify(result, null, 2),
|
|
227
|
+
exitCode: result.ok ? 0 : 1,
|
|
228
|
+
};
|
|
229
|
+
} catch (err) {
|
|
230
|
+
return {
|
|
231
|
+
error: `check failed: ${errorToMessage(err)}`,
|
|
232
|
+
exitCode: 1,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function handleGc(
|
|
238
|
+
client: DispatchClient,
|
|
239
|
+
options: CliOptions,
|
|
240
|
+
): Promise<CommandResult> {
|
|
241
|
+
try {
|
|
242
|
+
const result = await runGc(client, options);
|
|
243
|
+
return {
|
|
244
|
+
output: JSON.stringify(result, null, 2),
|
|
245
|
+
exitCode: 0,
|
|
246
|
+
};
|
|
247
|
+
} catch (err) {
|
|
248
|
+
return {
|
|
249
|
+
error: `gc failed: ${errorToMessage(err)}`,
|
|
250
|
+
exitCode: 1,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function handleRebuild(
|
|
256
|
+
client: DispatchClient,
|
|
257
|
+
options: CliOptions,
|
|
258
|
+
): Promise<CommandResult> {
|
|
259
|
+
try {
|
|
260
|
+
const result = await runRebuild(client, options);
|
|
261
|
+
return {
|
|
262
|
+
output: JSON.stringify(result, null, 2),
|
|
263
|
+
exitCode: 0,
|
|
264
|
+
};
|
|
265
|
+
} catch (err) {
|
|
266
|
+
return {
|
|
267
|
+
error: `rebuild failed: ${errorToMessage(err)}`,
|
|
268
|
+
exitCode: 1,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async function handleStatus(
|
|
274
|
+
client: DispatchClient,
|
|
275
|
+
options: CliOptions,
|
|
276
|
+
): Promise<CommandResult> {
|
|
277
|
+
try {
|
|
278
|
+
const result = await runStatus(client, options);
|
|
279
|
+
return {
|
|
280
|
+
output: JSON.stringify(result, null, 2),
|
|
281
|
+
exitCode: 0,
|
|
282
|
+
};
|
|
283
|
+
} catch (err) {
|
|
284
|
+
return {
|
|
285
|
+
error: `status failed: ${errorToMessage(err)}`,
|
|
286
|
+
exitCode: 1,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function handleDbInit(options: CliOptions): CommandResult {
|
|
292
|
+
return runDbInit(options, runInit);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async function handleDbMigrate(
|
|
296
|
+
client: DispatchClient,
|
|
297
|
+
options: CliOptions,
|
|
298
|
+
): Promise<CommandResult> {
|
|
299
|
+
try {
|
|
300
|
+
const result = await runDbMigrate(client, options);
|
|
301
|
+
return {
|
|
302
|
+
output: JSON.stringify(result, null, 2),
|
|
303
|
+
exitCode: 0,
|
|
304
|
+
};
|
|
305
|
+
} catch (err) {
|
|
306
|
+
return {
|
|
307
|
+
error: `db-migrate failed: ${errorToMessage(err)}`,
|
|
308
|
+
exitCode: 1,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Hydrates each result's `preview` field with the actual section
|
|
315
|
+
* content fetched from the client.
|
|
316
|
+
*
|
|
317
|
+
* Failures for individual results are caught and suppressed so that
|
|
318
|
+
* one unavailable section does not prevent other previews from
|
|
319
|
+
* being returned.
|
|
320
|
+
*
|
|
321
|
+
* @param client - content client used to fetch section text
|
|
322
|
+
* @param results - mutable search display records to hydrate
|
|
323
|
+
*/
|
|
324
|
+
async function hydrateSearchPreviews(
|
|
325
|
+
client: ContentClient,
|
|
326
|
+
results: SearchDisplay[],
|
|
327
|
+
): Promise<void> {
|
|
328
|
+
await Promise.all(
|
|
329
|
+
results.map(async (result) => {
|
|
330
|
+
try {
|
|
331
|
+
const contentResult = await client.content([result.kbid]);
|
|
332
|
+
result.preview = contentResult.data;
|
|
333
|
+
} catch {
|
|
334
|
+
// Leave preview as empty string on failure.
|
|
335
|
+
}
|
|
336
|
+
}),
|
|
337
|
+
);
|
|
338
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { existsSync, mkdirSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ensures that the `.kbdb` database directory exists at the
|
|
6
|
+
* resolved base path, creating it recursively if necessary.
|
|
7
|
+
*
|
|
8
|
+
* When `dbPath` is provided it is resolved to an absolute path and
|
|
9
|
+
* used as the base; otherwise `process.cwd()` is used.
|
|
10
|
+
*
|
|
11
|
+
* @param dbPath - optional path to the knowledge-base root directory
|
|
12
|
+
* @returns absolute path to the `.kbdb` directory
|
|
13
|
+
*/
|
|
14
|
+
export function ensureDb(dbPath?: string): string {
|
|
15
|
+
const base = dbPath ? resolve(dbPath) : process.cwd();
|
|
16
|
+
const kbdbDir = join(base, '.kbdb');
|
|
17
|
+
if (!existsSync(kbdbDir)) {
|
|
18
|
+
mkdirSync(kbdbDir, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
return kbdbDir;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an unknown thrown value to a human-readable message.
|
|
3
|
+
*
|
|
4
|
+
* @param err - the caught value
|
|
5
|
+
* @returns the error message string
|
|
6
|
+
*/
|
|
7
|
+
export function errorToMessage(err: unknown): string {
|
|
8
|
+
return err instanceof Error ? err.message : String(err);
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the absolute path to the `.kbdb` database directory
|
|
6
|
+
* under the given base path (or the current working directory).
|
|
7
|
+
*
|
|
8
|
+
* Unlike `ensureDb`, this function is purely read-only: it never
|
|
9
|
+
* creates the directory. Returns `null` when the `.kbdb` directory
|
|
10
|
+
* does not exist.
|
|
11
|
+
*
|
|
12
|
+
* @param dbPath - optional path to the knowledge-base root directory
|
|
13
|
+
* @returns absolute path to the `.kbdb` directory, or `null` when
|
|
14
|
+
* it does not exist
|
|
15
|
+
*/
|
|
16
|
+
export function findDb(dbPath?: string): string | null {
|
|
17
|
+
const base = dbPath ? resolve(dbPath) : process.cwd();
|
|
18
|
+
const kbdbDir = join(base, '.kbdb');
|
|
19
|
+
return existsSync(kbdbDir) ? kbdbDir : null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { OutputFormat } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { SearchDisplay } from '../typings/search-display.model.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Serialises an array of search results into the requested output
|
|
6
|
+
* format string.
|
|
7
|
+
*
|
|
8
|
+
* - `'json'` -- pretty-printed JSON array
|
|
9
|
+
* - `'text'` -- numbered human-readable list
|
|
10
|
+
* - `'mcp'` -- JSON envelope compatible with MCP protocol consumers
|
|
11
|
+
*
|
|
12
|
+
* @param results - ranked search results to format
|
|
13
|
+
* @param format - target output format
|
|
14
|
+
* @returns formatted string ready for stdout
|
|
15
|
+
*/
|
|
16
|
+
export function formatOutput(
|
|
17
|
+
results: SearchDisplay[],
|
|
18
|
+
format: OutputFormat,
|
|
19
|
+
): string {
|
|
20
|
+
switch (format) {
|
|
21
|
+
case 'json':
|
|
22
|
+
return JSON.stringify(results, null, 2);
|
|
23
|
+
case 'text':
|
|
24
|
+
return formatText(results);
|
|
25
|
+
case 'mcp':
|
|
26
|
+
return formatMcp(results);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Renders results as a numbered human-readable list.
|
|
32
|
+
*
|
|
33
|
+
* @param results - search results to render
|
|
34
|
+
*/
|
|
35
|
+
function formatText(results: SearchDisplay[]): string {
|
|
36
|
+
if (results.length === 0) return 'No results found.';
|
|
37
|
+
return results
|
|
38
|
+
.map(
|
|
39
|
+
(r, i) =>
|
|
40
|
+
`${String(i + 1)}. [${r.kbid}] ` +
|
|
41
|
+
`(score: ${r.score.toFixed(4)})\n` +
|
|
42
|
+
` ${r.preview}\n` +
|
|
43
|
+
` matches: ${r.matches.map((m) => m.term).join(', ')}`,
|
|
44
|
+
)
|
|
45
|
+
.join('\n\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Renders results as a JSON envelope for MCP protocol consumers.
|
|
50
|
+
*
|
|
51
|
+
* @param results - search results to render
|
|
52
|
+
*/
|
|
53
|
+
function formatMcp(results: SearchDisplay[]): string {
|
|
54
|
+
return JSON.stringify({
|
|
55
|
+
type: 'text',
|
|
56
|
+
text: results
|
|
57
|
+
.map(
|
|
58
|
+
(r) =>
|
|
59
|
+
`[${r.kbid}] score=${r.score.toFixed(4)}` +
|
|
60
|
+
` — ${r.preview}`,
|
|
61
|
+
)
|
|
62
|
+
.join('\n'),
|
|
63
|
+
});
|
|
64
|
+
}
|