@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,171 @@
|
|
|
1
|
+
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, extname, join } from 'node:path';
|
|
3
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
4
|
+
import type { LearnResult } from '../typings/learn-result.model.ts';
|
|
5
|
+
import { SUPPORTED_EXTENSIONS } from '../constants/defaults.constant.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Minimal client interface required by `runLearn`.
|
|
9
|
+
*
|
|
10
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
11
|
+
* implementation, making it straightforward to test with mocks.
|
|
12
|
+
*/
|
|
13
|
+
export interface LearnClient {
|
|
14
|
+
/**
|
|
15
|
+
* Ingests a content section into the knowledge base.
|
|
16
|
+
*
|
|
17
|
+
* @param params - section type label and raw text content
|
|
18
|
+
* @returns result object containing the knowledge-base identifier
|
|
19
|
+
* assigned to the section
|
|
20
|
+
*/
|
|
21
|
+
addSection(params: {
|
|
22
|
+
sectionType: string;
|
|
23
|
+
content: string;
|
|
24
|
+
title?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
docid?: string;
|
|
27
|
+
}): Promise<{ kbid: string }>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Injectable I/O for testing without real stdin. */
|
|
31
|
+
export interface LearnIO {
|
|
32
|
+
readStdin: () => Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Ingests one or more files or directories listed in `options.args`
|
|
37
|
+
* into the knowledge base via the provided client.
|
|
38
|
+
*
|
|
39
|
+
* Each argument is resolved to a set of supported files. Unsupported
|
|
40
|
+
* extensions, dotfiles, dot-directories, and non-existent paths are
|
|
41
|
+
* silently skipped. The `-` argument reads content from stdin
|
|
42
|
+
* (consumed only once).
|
|
43
|
+
*
|
|
44
|
+
* @param client - learn client to delegate ingestion to
|
|
45
|
+
* @param options - parsed CLI options whose `args` list targets to
|
|
46
|
+
* ingest
|
|
47
|
+
* @param io - injectable I/O (defaults to reading process.stdin)
|
|
48
|
+
* @returns one `LearnResult` per file successfully ingested
|
|
49
|
+
*/
|
|
50
|
+
export async function runLearn(
|
|
51
|
+
client: LearnClient,
|
|
52
|
+
options: CliOptions,
|
|
53
|
+
io?: LearnIO,
|
|
54
|
+
): Promise<LearnResult[]> {
|
|
55
|
+
const results: LearnResult[] = [];
|
|
56
|
+
let stdinConsumed = false;
|
|
57
|
+
const readStdin = io?.readStdin ?? readProcessStdin;
|
|
58
|
+
|
|
59
|
+
for (const target of options.args) {
|
|
60
|
+
if (target === '-') {
|
|
61
|
+
if (stdinConsumed) continue;
|
|
62
|
+
stdinConsumed = true;
|
|
63
|
+
const content = await readStdin();
|
|
64
|
+
const result = await client.addSection({
|
|
65
|
+
sectionType: 'text',
|
|
66
|
+
content,
|
|
67
|
+
title: options.title,
|
|
68
|
+
description: options.description,
|
|
69
|
+
docid: options.docid,
|
|
70
|
+
});
|
|
71
|
+
results.push({
|
|
72
|
+
kbid: result.kbid,
|
|
73
|
+
path: '-',
|
|
74
|
+
size: content.length,
|
|
75
|
+
skipped: false,
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const files = collectFiles(target);
|
|
81
|
+
for (const file of files) {
|
|
82
|
+
const content = readFileSync(file, 'utf-8');
|
|
83
|
+
const result = await client.addSection({
|
|
84
|
+
sectionType: 'text',
|
|
85
|
+
content,
|
|
86
|
+
title: options.title,
|
|
87
|
+
docid: options.docid,
|
|
88
|
+
});
|
|
89
|
+
results.push({
|
|
90
|
+
kbid: result.kbid,
|
|
91
|
+
path: file,
|
|
92
|
+
size: content.length,
|
|
93
|
+
skipped: false,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return results;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function readProcessStdin(): Promise<string> {
|
|
102
|
+
return new Promise<string>((resolve) => {
|
|
103
|
+
const chunks: Buffer[] = [];
|
|
104
|
+
process.stdin.on('data', (chunk: Buffer) => {
|
|
105
|
+
chunks.push(chunk);
|
|
106
|
+
});
|
|
107
|
+
process.stdin.on('end', () => {
|
|
108
|
+
resolve(Buffer.concat(chunks).toString('utf-8'));
|
|
109
|
+
});
|
|
110
|
+
process.stdin.resume();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Resolves a single target path to a flat list of supported files.
|
|
116
|
+
*
|
|
117
|
+
* Returns an empty array for non-existent or inaccessible paths.
|
|
118
|
+
*
|
|
119
|
+
* @param target - file or directory path to resolve
|
|
120
|
+
*/
|
|
121
|
+
function collectFiles(target: string): string[] {
|
|
122
|
+
try {
|
|
123
|
+
const stat = statSync(target);
|
|
124
|
+
if (stat.isFile()) {
|
|
125
|
+
return isSupportedFile(target) ? [target] : [];
|
|
126
|
+
}
|
|
127
|
+
if (stat.isDirectory()) {
|
|
128
|
+
return scanDirectory(target);
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// Non-existent or inaccessible path -- skip
|
|
132
|
+
}
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Recursively scans a directory and returns all supported files,
|
|
138
|
+
* excluding dot-entries at every level.
|
|
139
|
+
*
|
|
140
|
+
* @param dir - absolute or relative directory path to scan
|
|
141
|
+
*/
|
|
142
|
+
function scanDirectory(dir: string): string[] {
|
|
143
|
+
const files: string[] = [];
|
|
144
|
+
for (const entry of readdirSync(dir)) {
|
|
145
|
+
if (entry.startsWith('.')) continue;
|
|
146
|
+
const full = join(dir, entry);
|
|
147
|
+
try {
|
|
148
|
+
const stat = statSync(full);
|
|
149
|
+
if (stat.isDirectory()) {
|
|
150
|
+
files.push(...scanDirectory(full));
|
|
151
|
+
} else if (isSupportedFile(full)) {
|
|
152
|
+
files.push(full);
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
// Skip inaccessible entries
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return files;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Returns `true` when the file's extension is in
|
|
163
|
+
* `SUPPORTED_EXTENSIONS`.
|
|
164
|
+
*
|
|
165
|
+
* @param path - file path to check
|
|
166
|
+
*/
|
|
167
|
+
function isSupportedFile(path: string): boolean {
|
|
168
|
+
if (basename(path).startsWith('.')) return false;
|
|
169
|
+
const ext = extname(path).toLowerCase();
|
|
170
|
+
return (SUPPORTED_EXTENSIONS as readonly string[]).includes(ext);
|
|
171
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
3
|
+
import type { MigrateResult } from '../../worker-client/typings/migrate-result.model.ts';
|
|
4
|
+
import type {
|
|
5
|
+
VersionCompatibility,
|
|
6
|
+
VersionStatus,
|
|
7
|
+
} from '../../worker-client/typings/version-status.model.ts';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Result returned by `runMigrate` describing the outcome of the
|
|
11
|
+
* migration attempt.
|
|
12
|
+
*/
|
|
13
|
+
export interface MigrateCommandResult {
|
|
14
|
+
/**
|
|
15
|
+
* The compatibility status returned by the version check.
|
|
16
|
+
* Mirrors `VersionStatus.status`.
|
|
17
|
+
*/
|
|
18
|
+
readonly status: VersionCompatibility;
|
|
19
|
+
/** Full version status from the pre-migration check. */
|
|
20
|
+
readonly versionStatus: VersionStatus;
|
|
21
|
+
/**
|
|
22
|
+
* Migration report when `status` is `'needs_migration'`.
|
|
23
|
+
* `undefined` for `'compatible'` and `'too_new'` outcomes.
|
|
24
|
+
*/
|
|
25
|
+
readonly migrateResult?: MigrateResult;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Minimal client interface required by `runMigrate`.
|
|
30
|
+
*
|
|
31
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
32
|
+
* implementation, making it straightforward to test with mocks.
|
|
33
|
+
*/
|
|
34
|
+
export interface MigrateClient {
|
|
35
|
+
/**
|
|
36
|
+
* Checks the database format version against the WASM engine.
|
|
37
|
+
*
|
|
38
|
+
* @param targetPath - absolute path to the `.kbdb` database root
|
|
39
|
+
*/
|
|
40
|
+
checkVersion(targetPath: string): Promise<VersionStatus>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Runs all pending database migrations.
|
|
44
|
+
*
|
|
45
|
+
* @param targetPath - absolute path to the `.kbdb` database root
|
|
46
|
+
*/
|
|
47
|
+
migrateDatabase(targetPath: string): Promise<MigrateResult>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Checks the database version and runs pending migrations when needed.
|
|
52
|
+
*
|
|
53
|
+
* Resolution order:
|
|
54
|
+
* - `'compatible'`: returns without running migrations
|
|
55
|
+
* - `'needs_migration'`: calls `client.migrateDatabase` and returns
|
|
56
|
+
* the migration report
|
|
57
|
+
* - `'too_new'`: returns without running migrations (caller should
|
|
58
|
+
* print an error and exit non-zero)
|
|
59
|
+
*
|
|
60
|
+
* @param client - migrate client to delegate to
|
|
61
|
+
* @param options - parsed CLI options supplying the optional `dbPath`
|
|
62
|
+
* @returns result containing the version status and optional migration
|
|
63
|
+
* report
|
|
64
|
+
*/
|
|
65
|
+
export async function runMigrate(
|
|
66
|
+
client: MigrateClient,
|
|
67
|
+
options: CliOptions,
|
|
68
|
+
): Promise<MigrateCommandResult> {
|
|
69
|
+
const targetPath = options.dbPath
|
|
70
|
+
? resolve(options.dbPath)
|
|
71
|
+
: process.cwd();
|
|
72
|
+
|
|
73
|
+
const versionStatus = await client.checkVersion(targetPath);
|
|
74
|
+
|
|
75
|
+
if (versionStatus.status === 'needs_migration') {
|
|
76
|
+
const migrateResult = await client.migrateDatabase(targetPath);
|
|
77
|
+
return {
|
|
78
|
+
status: 'needs_migration',
|
|
79
|
+
versionStatus,
|
|
80
|
+
migrateResult,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { status: versionStatus.status, versionStatus };
|
|
85
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Index rebuild report returned by the daemon.
|
|
5
|
+
*/
|
|
6
|
+
interface RebuildResult {
|
|
7
|
+
/** Number of text and code sections that were re-indexed. */
|
|
8
|
+
readonly sections_reindexed: number;
|
|
9
|
+
/** Total number of unique terms written to the rebuilt indexes. */
|
|
10
|
+
readonly terms_indexed: number;
|
|
11
|
+
/** Time taken to complete the rebuild, in milliseconds. */
|
|
12
|
+
readonly elapsed_ms: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Minimal client interface required by `runRebuild`.
|
|
17
|
+
*
|
|
18
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
19
|
+
* implementation, making it straightforward to test with mocks.
|
|
20
|
+
*/
|
|
21
|
+
export interface RebuildClient {
|
|
22
|
+
/**
|
|
23
|
+
* Reconstructs all index files from section files and document
|
|
24
|
+
* manifests on disk. Text and code sections are re-tokenized;
|
|
25
|
+
* image sections are skipped.
|
|
26
|
+
*
|
|
27
|
+
* @returns a report of sections and terms re-indexed
|
|
28
|
+
*/
|
|
29
|
+
rebuildIndexes(): Promise<RebuildResult>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Rebuilds all database indexes and returns the report.
|
|
34
|
+
*
|
|
35
|
+
* Delegates to `client.rebuildIndexes()`. The caller is responsible
|
|
36
|
+
* for printing the result to stdout.
|
|
37
|
+
*
|
|
38
|
+
* @param client - rebuild client to delegate to
|
|
39
|
+
* @param _options - parsed CLI options (unused; reserved for future flags)
|
|
40
|
+
* @returns the index rebuild report from the daemon
|
|
41
|
+
*/
|
|
42
|
+
export async function runRebuild(
|
|
43
|
+
client: RebuildClient,
|
|
44
|
+
_options: CliOptions,
|
|
45
|
+
): Promise<RebuildResult> {
|
|
46
|
+
return client.rebuildIndexes();
|
|
47
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { SearchDisplay } from '../typings/search-display.model.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal client interface required by `runSearch`.
|
|
6
|
+
*
|
|
7
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
8
|
+
* implementation, making it straightforward to test with mocks.
|
|
9
|
+
*/
|
|
10
|
+
export interface SearchClient {
|
|
11
|
+
/**
|
|
12
|
+
* Searches the knowledge base and returns ranked results.
|
|
13
|
+
*
|
|
14
|
+
* @param params - query, mode, and result limit
|
|
15
|
+
*/
|
|
16
|
+
search(params: {
|
|
17
|
+
query: string;
|
|
18
|
+
mode?: string;
|
|
19
|
+
limit?: number;
|
|
20
|
+
}): Promise<
|
|
21
|
+
{
|
|
22
|
+
kbid: string;
|
|
23
|
+
score: number;
|
|
24
|
+
readonly matches: readonly {
|
|
25
|
+
readonly term: string;
|
|
26
|
+
readonly frequency: number;
|
|
27
|
+
}[];
|
|
28
|
+
}[]
|
|
29
|
+
>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Executes a search query via the provided client and maps the raw
|
|
34
|
+
* daemon results to the `SearchDisplay` format used by the CLI.
|
|
35
|
+
*
|
|
36
|
+
* Returns an empty array without calling the client when `options.args`
|
|
37
|
+
* contains no query terms.
|
|
38
|
+
*
|
|
39
|
+
* @param client - search client to delegate to
|
|
40
|
+
* @param options - parsed CLI options supplying query args and search
|
|
41
|
+
* parameters
|
|
42
|
+
*/
|
|
43
|
+
export async function runSearch(
|
|
44
|
+
client: SearchClient,
|
|
45
|
+
options: CliOptions,
|
|
46
|
+
): Promise<SearchDisplay[]> {
|
|
47
|
+
const query = options.args.join(' ').trim();
|
|
48
|
+
if (!query) return [];
|
|
49
|
+
|
|
50
|
+
const results = await client.search({
|
|
51
|
+
query,
|
|
52
|
+
mode: options.mode,
|
|
53
|
+
limit: options.limit,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return results.map((r) => ({
|
|
57
|
+
kbid: r.kbid,
|
|
58
|
+
score: r.score,
|
|
59
|
+
preview: '',
|
|
60
|
+
matches: r.matches,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { CommandResult } from '../typings/command-result.model.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal client interface required by `runSkillDelete`.
|
|
6
|
+
*
|
|
7
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
8
|
+
* implementation, making it straightforward to test with mocks.
|
|
9
|
+
*/
|
|
10
|
+
export interface SkillDeleteClient {
|
|
11
|
+
/**
|
|
12
|
+
* Removes a section from the knowledge base.
|
|
13
|
+
*
|
|
14
|
+
* @param kbid - knowledge-base identifier of the section to remove
|
|
15
|
+
* @returns result indicating whether the section was found and removed
|
|
16
|
+
*/
|
|
17
|
+
removeSection(kbid: string): Promise<{ 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 async function runSkillDelete(
|
|
31
|
+
client: SkillDeleteClient,
|
|
32
|
+
options: CliOptions,
|
|
33
|
+
): Promise<CommandResult> {
|
|
34
|
+
const kbid = options.args[0];
|
|
35
|
+
if (!kbid) {
|
|
36
|
+
return { error: 'kbid is required', exitCode: 1 };
|
|
37
|
+
}
|
|
38
|
+
const result = await client.removeSection(kbid);
|
|
39
|
+
return {
|
|
40
|
+
output: JSON.stringify(
|
|
41
|
+
{ kbid, removed: result.removed },
|
|
42
|
+
null,
|
|
43
|
+
2,
|
|
44
|
+
),
|
|
45
|
+
exitCode: 0,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { CommandResult } from '../typings/command-result.model.ts';
|
|
3
|
+
import { parseSkillContent } from '../../mcp/functions/parse-skill-content.function.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Minimal client interface required by `runSkillGet`.
|
|
7
|
+
*
|
|
8
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
9
|
+
* implementation, making it straightforward to test with mocks.
|
|
10
|
+
*/
|
|
11
|
+
export interface SkillGetClient {
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves one or more sections by their knowledge-base IDs.
|
|
14
|
+
*
|
|
15
|
+
* @param kbids - list of knowledge-base identifiers to fetch
|
|
16
|
+
* @returns matching section rows
|
|
17
|
+
*/
|
|
18
|
+
readSections(
|
|
19
|
+
kbids: string[],
|
|
20
|
+
): Promise<{ kbid: string; content: string }[]>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves all sections stored with the given type name.
|
|
24
|
+
*
|
|
25
|
+
* @param sectionType - the type name to filter by
|
|
26
|
+
* @returns matching section rows
|
|
27
|
+
*/
|
|
28
|
+
listByType(
|
|
29
|
+
sectionType: string,
|
|
30
|
+
): Promise<
|
|
31
|
+
{ kbid: string; title: string | null; content: string }[]
|
|
32
|
+
>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Retrieves a skill definition by name or kbid.
|
|
37
|
+
*
|
|
38
|
+
* Accepts the identifier as the first positional argument or as
|
|
39
|
+
* `options.name`. When the identifier looks like a hex hash
|
|
40
|
+
* (16 or more hex characters) it is tried as a kbid first; if
|
|
41
|
+
* no section is found it falls back to a name lookup. When the
|
|
42
|
+
* identifier is not hex-like it goes directly to name lookup.
|
|
43
|
+
* For name lookups the most recently stored match (last in the
|
|
44
|
+
* array) is returned.
|
|
45
|
+
*
|
|
46
|
+
* @param client - client used to look up the skill section
|
|
47
|
+
* @param options - parsed CLI options; first positional arg or `name`
|
|
48
|
+
* is used as the identifier
|
|
49
|
+
* @returns a `CommandResult` containing the serialized
|
|
50
|
+
* `SkillDefinition` JSON or an error message
|
|
51
|
+
*/
|
|
52
|
+
export async function runSkillGet(
|
|
53
|
+
client: SkillGetClient,
|
|
54
|
+
options: CliOptions,
|
|
55
|
+
): Promise<CommandResult> {
|
|
56
|
+
const identifier = options.args[0] ?? options.name;
|
|
57
|
+
if (!identifier) {
|
|
58
|
+
return {
|
|
59
|
+
error: 'skill name or kbid required',
|
|
60
|
+
exitCode: 1,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
let content: string | undefined;
|
|
64
|
+
// Try as kbid first when it looks like a hex hash.
|
|
65
|
+
if (/^[0-9a-f]{16,}$/i.test(identifier)) {
|
|
66
|
+
const sections = await client.readSections([identifier]);
|
|
67
|
+
if (sections.length > 0) {
|
|
68
|
+
content = sections[0]?.content;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// If not found by kbid, try by name.
|
|
72
|
+
if (content === undefined) {
|
|
73
|
+
const records = await client.listByType('skill');
|
|
74
|
+
const match = records.filter((r) => r.title === identifier).pop();
|
|
75
|
+
if (match) {
|
|
76
|
+
content = match.content;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (content === undefined) {
|
|
80
|
+
return {
|
|
81
|
+
error: `skill not found: ${identifier}`,
|
|
82
|
+
exitCode: 1,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const skill = parseSkillContent(content);
|
|
86
|
+
return {
|
|
87
|
+
output: JSON.stringify(skill, null, 2),
|
|
88
|
+
exitCode: 0,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import { extractSkillArguments } from '../../mcp/functions/extract-skill-arguments.function.ts';
|
|
5
|
+
import { serializeSkillContent } from '../../mcp/functions/serialize-skill-content.function.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Minimal client interface required by `runSkillLearn`.
|
|
9
|
+
*
|
|
10
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
11
|
+
* implementation, making it straightforward to test with mocks.
|
|
12
|
+
*/
|
|
13
|
+
export interface SkillLearnClient {
|
|
14
|
+
/**
|
|
15
|
+
* Stores a skill section in the knowledge base.
|
|
16
|
+
*
|
|
17
|
+
* @param params - section type, serialized JSON content,
|
|
18
|
+
* and optional title and description
|
|
19
|
+
* @returns result containing the assigned kbid
|
|
20
|
+
*/
|
|
21
|
+
addSection(params: {
|
|
22
|
+
readonly sectionType: string;
|
|
23
|
+
readonly content: string;
|
|
24
|
+
readonly title?: string;
|
|
25
|
+
readonly description?: string;
|
|
26
|
+
}): Promise<AddSectionResult>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates or updates a skill definition in the knowledge base.
|
|
31
|
+
*
|
|
32
|
+
* Validates that `--name` and `--body` are provided, extracts
|
|
33
|
+
* `{{argName}}` placeholders from the body, serializes the skill
|
|
34
|
+
* to JSON, and stores it as a `'skill'` section.
|
|
35
|
+
*
|
|
36
|
+
* @param client - client used to store the skill section
|
|
37
|
+
* @param options - parsed CLI options with `name` and `body` fields
|
|
38
|
+
* @returns a `CommandResult` with the stored section info or an error
|
|
39
|
+
*/
|
|
40
|
+
export async function runSkillLearn(
|
|
41
|
+
client: SkillLearnClient,
|
|
42
|
+
options: CliOptions,
|
|
43
|
+
): Promise<CommandResult> {
|
|
44
|
+
const name = options.name;
|
|
45
|
+
if (!name) {
|
|
46
|
+
return { error: '--name is required', exitCode: 1 };
|
|
47
|
+
}
|
|
48
|
+
const body = options.body;
|
|
49
|
+
if (!body) {
|
|
50
|
+
return { error: '--body is required', exitCode: 1 };
|
|
51
|
+
}
|
|
52
|
+
const args = extractSkillArguments(body);
|
|
53
|
+
const skill = {
|
|
54
|
+
name,
|
|
55
|
+
description: options.description,
|
|
56
|
+
arguments: args.length > 0 ? args : undefined,
|
|
57
|
+
body,
|
|
58
|
+
};
|
|
59
|
+
const json = serializeSkillContent(skill);
|
|
60
|
+
const result = await client.addSection({
|
|
61
|
+
sectionType: 'skill',
|
|
62
|
+
content: json,
|
|
63
|
+
title: name,
|
|
64
|
+
description: options.description,
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
output: JSON.stringify(result, null, 2),
|
|
68
|
+
exitCode: 0,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { CommandResult } from '../typings/command-result.model.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A single row returned by `listByType` for the skill client.
|
|
6
|
+
*/
|
|
7
|
+
interface SkillRecord {
|
|
8
|
+
/** Knowledge-base identifier for the skill section. */
|
|
9
|
+
kbid: string;
|
|
10
|
+
/** Skill name stored as the section title. */
|
|
11
|
+
title: string | null;
|
|
12
|
+
/** Optional skill description stored on the section. */
|
|
13
|
+
description: string | null;
|
|
14
|
+
/** Serialized `SkillDefinition` JSON stored as section content. */
|
|
15
|
+
content: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Minimal client interface required by `runSkillList`.
|
|
20
|
+
*
|
|
21
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
22
|
+
* implementation, making it straightforward to test with mocks.
|
|
23
|
+
*/
|
|
24
|
+
export interface SkillListClient {
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves all sections stored with the given type name.
|
|
27
|
+
*
|
|
28
|
+
* @param sectionType - the type name to filter by
|
|
29
|
+
* @returns matching section rows
|
|
30
|
+
*/
|
|
31
|
+
listByType(sectionType: string): Promise<SkillRecord[]>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Lists all skill definitions stored in the knowledge base.
|
|
36
|
+
*
|
|
37
|
+
* Calls `client.listByType('skill')` and maps each record to a
|
|
38
|
+
* summary that includes the argument count parsed from the JSON
|
|
39
|
+
* content. Parse errors default the argument count to `0`.
|
|
40
|
+
*
|
|
41
|
+
* @param client - client used to list skill sections
|
|
42
|
+
* @param _options - parsed CLI options (unused; reserved for future flags)
|
|
43
|
+
* @returns a `CommandResult` containing a JSON array of skill summaries
|
|
44
|
+
*/
|
|
45
|
+
export async function runSkillList(
|
|
46
|
+
client: SkillListClient,
|
|
47
|
+
_options: CliOptions,
|
|
48
|
+
): Promise<CommandResult> {
|
|
49
|
+
const records = await client.listByType('skill');
|
|
50
|
+
const items = records.map((r) => {
|
|
51
|
+
let argumentCount = 0;
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(r.content) as Record<
|
|
54
|
+
string,
|
|
55
|
+
unknown
|
|
56
|
+
>;
|
|
57
|
+
if (Array.isArray(parsed['arguments'])) {
|
|
58
|
+
argumentCount = parsed['arguments'].length;
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
// ignore parse errors
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
kbid: r.kbid,
|
|
65
|
+
name: r.title,
|
|
66
|
+
description: r.description,
|
|
67
|
+
argumentCount,
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
output: JSON.stringify(items, null, 2),
|
|
72
|
+
exitCode: 0,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal client interface required by `runStatus`.
|
|
5
|
+
*
|
|
6
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
7
|
+
* implementation, making it straightforward to test with mocks.
|
|
8
|
+
*/
|
|
9
|
+
export interface StatusClient {
|
|
10
|
+
dbStatus(): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the database status and returns the summary report.
|
|
15
|
+
*
|
|
16
|
+
* Delegates to `client.dbStatus()`. The caller is responsible
|
|
17
|
+
* for serialising the result and setting the process exit code.
|
|
18
|
+
*
|
|
19
|
+
* @param client - status client to delegate to
|
|
20
|
+
* @param _options - parsed CLI options (unused; reserved for
|
|
21
|
+
* future flags)
|
|
22
|
+
* @returns the status report from the daemon
|
|
23
|
+
*/
|
|
24
|
+
export async function runStatus(
|
|
25
|
+
client: StatusClient,
|
|
26
|
+
_options: CliOptions,
|
|
27
|
+
): Promise<unknown> {
|
|
28
|
+
return client.dbStatus();
|
|
29
|
+
}
|