@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,58 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
|
|
3
|
+
/** Removal result returned by `UnlearnClient.removeSection`. */
|
|
4
|
+
interface RemoveSectionResult {
|
|
5
|
+
/** `true` when the section was found and successfully removed. */
|
|
6
|
+
readonly removed: boolean;
|
|
7
|
+
/** Time taken to perform the removal, in milliseconds. */
|
|
8
|
+
readonly elapsed_ms: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Minimal client interface required by `runUnlearn`.
|
|
13
|
+
*
|
|
14
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
15
|
+
* implementation, making it straightforward to test with mocks.
|
|
16
|
+
*/
|
|
17
|
+
export interface UnlearnClient {
|
|
18
|
+
/**
|
|
19
|
+
* Removes a section from the knowledge base.
|
|
20
|
+
*
|
|
21
|
+
* @param kbid - identifier of the section to remove
|
|
22
|
+
* @returns removal result with `removed` flag and elapsed time
|
|
23
|
+
*/
|
|
24
|
+
removeSection(kbid: string): Promise<RemoveSectionResult>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Result record produced for each kbid processed by the unlearn command. */
|
|
28
|
+
export interface UnlearnResult {
|
|
29
|
+
/** Knowledge-base identifier that was targeted for removal. */
|
|
30
|
+
kbid: string;
|
|
31
|
+
/** `true` when the section was found and successfully removed. */
|
|
32
|
+
removed: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Removes the knowledge-base sections identified by `options.args`
|
|
37
|
+
* via the provided client.
|
|
38
|
+
*
|
|
39
|
+
* Each kbid in `options.args` is processed independently. If a kbid
|
|
40
|
+
* does not exist in the knowledge base, `removed` is set to `false`
|
|
41
|
+
* rather than throwing.
|
|
42
|
+
*
|
|
43
|
+
* @param client - unlearn client to delegate removal to
|
|
44
|
+
* @param options - parsed CLI options whose `args` list the kbids to
|
|
45
|
+
* remove
|
|
46
|
+
* @returns one `UnlearnResult` per kbid processed
|
|
47
|
+
*/
|
|
48
|
+
export async function runUnlearn(
|
|
49
|
+
client: UnlearnClient,
|
|
50
|
+
options: CliOptions,
|
|
51
|
+
): Promise<UnlearnResult[]> {
|
|
52
|
+
const results: UnlearnResult[] = [];
|
|
53
|
+
for (const kbid of options.args) {
|
|
54
|
+
const result = await client.removeSection(kbid);
|
|
55
|
+
results.push({ kbid, removed: result.removed });
|
|
56
|
+
}
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 {
|
|
21
|
+
CliOptions,
|
|
22
|
+
OutputFormat,
|
|
23
|
+
SearchMode,
|
|
24
|
+
} from './typings/cli-options.interface.ts';
|
|
25
|
+
export type { LearnResult } from './typings/learn-result.model.ts';
|
|
26
|
+
export type { SearchDisplay } from './typings/search-display.model.ts';
|
|
27
|
+
export type { SearchClient } from './functions/run-search.function.ts';
|
|
28
|
+
export type { LearnClient } from './functions/run-learn.function.ts';
|
|
29
|
+
export type {
|
|
30
|
+
UnlearnClient,
|
|
31
|
+
UnlearnResult,
|
|
32
|
+
} from './functions/run-unlearn.function.ts';
|
|
33
|
+
export type { ContentClient } from './functions/run-content.function.ts';
|
|
34
|
+
export type { CheckClient } from './functions/run-check.function.ts';
|
|
35
|
+
export type { GcClient } from './functions/run-gc.function.ts';
|
|
36
|
+
export type { RebuildClient } from './functions/run-rebuild.function.ts';
|
|
37
|
+
export type { InitResult } from './functions/run-init.function.ts';
|
|
38
|
+
export type {
|
|
39
|
+
MigrateClient,
|
|
40
|
+
MigrateCommandResult,
|
|
41
|
+
} from './functions/run-migrate.function.ts';
|
|
42
|
+
export type { CommandResult } from './typings/command-result.model.ts';
|
|
43
|
+
export type { PromptIO } from './functions/prompt-user.function.ts';
|
|
44
|
+
export type { DispatchClient } from './functions/dispatch-command.function.ts';
|
|
45
|
+
export type {
|
|
46
|
+
CliDeps,
|
|
47
|
+
DisconnectableClient,
|
|
48
|
+
} from './functions/run-cli.function.ts';
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
/**
|
|
11
|
+
* Controls which entity type is returned by a search query.
|
|
12
|
+
*
|
|
13
|
+
* - `'sections'` -- individual content sections (default)
|
|
14
|
+
* - `'documents'` -- document-level groupings
|
|
15
|
+
* - `'stats'` -- index statistics
|
|
16
|
+
*/
|
|
17
|
+
export type SearchMode = 'sections' | 'documents' | 'stats';
|
|
18
|
+
|
|
19
|
+
/** Parsed representation of all CLI arguments for a single invocation. */
|
|
20
|
+
export interface CliOptions {
|
|
21
|
+
/** The sub-command to execute (e.g. `'search'`, `'learn'`). */
|
|
22
|
+
command: string;
|
|
23
|
+
/**
|
|
24
|
+
* Path to the knowledge-base root directory.
|
|
25
|
+
* Defaults to the current working directory when omitted.
|
|
26
|
+
*/
|
|
27
|
+
dbPath?: string;
|
|
28
|
+
/** Output format for results. Defaults to `'json'`. */
|
|
29
|
+
format: OutputFormat;
|
|
30
|
+
/** Search mode passed to the worker daemon. Defaults to `'sections'`. */
|
|
31
|
+
mode: SearchMode;
|
|
32
|
+
/** Maximum number of results to return. Defaults to 20. */
|
|
33
|
+
limit: number;
|
|
34
|
+
/** Section title for learn command. */
|
|
35
|
+
title?: string;
|
|
36
|
+
/** Section description for learn command. */
|
|
37
|
+
description?: string;
|
|
38
|
+
/** Document ID for learn command. */
|
|
39
|
+
docid?: string;
|
|
40
|
+
/**
|
|
41
|
+
* When `true`, hydrates each search result's `preview` field
|
|
42
|
+
* with the section's actual content via `client.content()`.
|
|
43
|
+
*/
|
|
44
|
+
content?: boolean;
|
|
45
|
+
/** Skill or agent name for skill/agent commands. */
|
|
46
|
+
name?: string;
|
|
47
|
+
/** Agent persona content or file path. */
|
|
48
|
+
persona?: string;
|
|
49
|
+
/** Skill body content or file path. */
|
|
50
|
+
body?: string;
|
|
51
|
+
/** Comma-separated skill kbids for agent create. */
|
|
52
|
+
skills?: string[];
|
|
53
|
+
/** Positional arguments following the sub-command. */
|
|
54
|
+
args: string[];
|
|
55
|
+
}
|
|
@@ -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,25 @@
|
|
|
1
|
+
import { dirname } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
import type { BaseDir } from '../typings/base-dir.interface.ts';
|
|
5
|
+
|
|
6
|
+
export function resolveScriptDir(
|
|
7
|
+
entryUrl: string,
|
|
8
|
+
entryDirname?: string,
|
|
9
|
+
): string {
|
|
10
|
+
if (entryDirname) return entryDirname;
|
|
11
|
+
if (entryUrl.startsWith('file:'))
|
|
12
|
+
return dirname(fileURLToPath(entryUrl));
|
|
13
|
+
return dirname(entryUrl);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function resolveBaseDir(
|
|
17
|
+
entryUrl: string,
|
|
18
|
+
entryDirname?: string,
|
|
19
|
+
): BaseDir {
|
|
20
|
+
const scriptDir =
|
|
21
|
+
typeof __dirname !== 'undefined'
|
|
22
|
+
? __dirname
|
|
23
|
+
: resolveScriptDir(entryUrl, entryDirname);
|
|
24
|
+
return { scriptDir, cwd: process.cwd() };
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
|
|
3
|
+
import type { Runtime } from '../../runtime/typings/runtime.ts';
|
|
4
|
+
|
|
5
|
+
export function resolveWorkerScript(
|
|
6
|
+
scriptDir: string,
|
|
7
|
+
runtime: Runtime,
|
|
8
|
+
): string {
|
|
9
|
+
if (runtime === 'deno') {
|
|
10
|
+
return join(scriptDir, 'worker.ts');
|
|
11
|
+
}
|
|
12
|
+
return join(scriptDir, 'kbdb-worker.cjs');
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export {
|
|
2
|
+
resolveBaseDir,
|
|
3
|
+
resolveScriptDir,
|
|
4
|
+
} from './functions/resolve-base-dir.function.ts';
|
|
5
|
+
export { resolveWorkerScript } from './functions/resolve-worker-script.function.ts';
|
|
6
|
+
export { resolveWasmDir } from './functions/resolve-wasm-dir.function.ts';
|
|
7
|
+
export type { BaseDir } from './typings/base-dir.interface.ts';
|
|
@@ -0,0 +1,17 @@
|
|
|
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 async function computeSha256(input: string): Promise<string> {
|
|
11
|
+
const data = new TextEncoder().encode(input);
|
|
12
|
+
const hash = await crypto.subtle.digest('SHA-256', data);
|
|
13
|
+
const bytes = new Uint8Array(hash);
|
|
14
|
+
return Array.from(bytes)
|
|
15
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
16
|
+
.join('');
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { computeSha256 } from './functions/compute-sha256.ts';
|