@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,133 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_FORMAT,
|
|
4
|
+
DEFAULT_LIMIT,
|
|
5
|
+
DEFAULT_MODE,
|
|
6
|
+
} from '../constants/defaults.constant.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parses a raw argument vector into a structured `CliOptions` object.
|
|
10
|
+
*
|
|
11
|
+
* Recognises `--help` / `-h` and `--version` / `-v` as early-exit
|
|
12
|
+
* flags that set the command and return immediately. All other flags
|
|
13
|
+
* consume the next token as their value. The first non-flag token
|
|
14
|
+
* becomes the command; subsequent non-flag tokens become `args`.
|
|
15
|
+
*
|
|
16
|
+
* Compound commands are supported: when the first positional token is
|
|
17
|
+
* a group name (`db`, `skill`, or `agent`), the next positional token
|
|
18
|
+
* is joined with a hyphen to form the compound command
|
|
19
|
+
* (e.g. `db init` → `'db-init'`).
|
|
20
|
+
*
|
|
21
|
+
* Context-aware `--help`: when `--help` or `-h` appears after a
|
|
22
|
+
* command has been set, the existing command is moved to `args[0]`
|
|
23
|
+
* and the command is set to `'help'`, enabling per-command help.
|
|
24
|
+
*
|
|
25
|
+
* Deprecated flags `--init` and `--migrate` emit a warning to stderr
|
|
26
|
+
* before setting the corresponding command.
|
|
27
|
+
*
|
|
28
|
+
* @param argv - argument strings (typically `process.argv.slice(2)`)
|
|
29
|
+
* @returns fully populated `CliOptions` with defaults applied
|
|
30
|
+
*/
|
|
31
|
+
export function parseArgs(argv: string[]): CliOptions {
|
|
32
|
+
const options: CliOptions = {
|
|
33
|
+
command: '',
|
|
34
|
+
format: DEFAULT_FORMAT,
|
|
35
|
+
mode: DEFAULT_MODE,
|
|
36
|
+
limit: DEFAULT_LIMIT,
|
|
37
|
+
args: [],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let i = 0;
|
|
41
|
+
while (i < argv.length) {
|
|
42
|
+
const arg = argv[i];
|
|
43
|
+
switch (arg) {
|
|
44
|
+
case '--help':
|
|
45
|
+
case '-h':
|
|
46
|
+
if (options.command) {
|
|
47
|
+
options.args.unshift(options.command);
|
|
48
|
+
options.command = 'help';
|
|
49
|
+
} else {
|
|
50
|
+
options.command = 'help';
|
|
51
|
+
}
|
|
52
|
+
return options;
|
|
53
|
+
case '--version':
|
|
54
|
+
case '-v':
|
|
55
|
+
options.command = 'version';
|
|
56
|
+
return options;
|
|
57
|
+
case '--init':
|
|
58
|
+
// eslint-disable-next-line no-console
|
|
59
|
+
console.error(
|
|
60
|
+
'warning: --init is deprecated,' + ' use "kbdb db init"',
|
|
61
|
+
);
|
|
62
|
+
options.command = 'init';
|
|
63
|
+
break;
|
|
64
|
+
case '--migrate':
|
|
65
|
+
// eslint-disable-next-line no-console
|
|
66
|
+
console.error(
|
|
67
|
+
'warning: --migrate is deprecated,' +
|
|
68
|
+
' use "kbdb db migrate"',
|
|
69
|
+
);
|
|
70
|
+
options.command = 'migrate';
|
|
71
|
+
break;
|
|
72
|
+
case '--db':
|
|
73
|
+
options.dbPath = argv[++i];
|
|
74
|
+
break;
|
|
75
|
+
case '--format':
|
|
76
|
+
case '-f':
|
|
77
|
+
options.format = (argv[++i] ??
|
|
78
|
+
DEFAULT_FORMAT) as CliOptions['format'];
|
|
79
|
+
break;
|
|
80
|
+
case '--mode':
|
|
81
|
+
case '-m':
|
|
82
|
+
options.mode = (argv[++i] ??
|
|
83
|
+
DEFAULT_MODE) as CliOptions['mode'];
|
|
84
|
+
break;
|
|
85
|
+
case '--limit':
|
|
86
|
+
case '-l':
|
|
87
|
+
options.limit =
|
|
88
|
+
parseInt(argv[++i] ?? '', 10) || DEFAULT_LIMIT;
|
|
89
|
+
break;
|
|
90
|
+
case '--title':
|
|
91
|
+
options.title = argv[++i];
|
|
92
|
+
break;
|
|
93
|
+
case '--description':
|
|
94
|
+
options.description = argv[++i];
|
|
95
|
+
break;
|
|
96
|
+
case '--docid':
|
|
97
|
+
options.docid = argv[++i];
|
|
98
|
+
break;
|
|
99
|
+
case '--name':
|
|
100
|
+
options.name = argv[++i];
|
|
101
|
+
break;
|
|
102
|
+
case '--persona':
|
|
103
|
+
options.persona = argv[++i];
|
|
104
|
+
break;
|
|
105
|
+
case '--body':
|
|
106
|
+
options.body = argv[++i];
|
|
107
|
+
break;
|
|
108
|
+
case '--skills':
|
|
109
|
+
options.skills = (argv[++i] ?? '').split(',');
|
|
110
|
+
break;
|
|
111
|
+
case '--content':
|
|
112
|
+
case '-c':
|
|
113
|
+
options.content = true;
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
if (!options.command) {
|
|
117
|
+
options.command = arg;
|
|
118
|
+
} else if (
|
|
119
|
+
!options.args.length &&
|
|
120
|
+
(options.command === 'db' ||
|
|
121
|
+
options.command === 'skill' ||
|
|
122
|
+
options.command === 'agent')
|
|
123
|
+
) {
|
|
124
|
+
options.command = `${options.command}-${arg}`;
|
|
125
|
+
} else {
|
|
126
|
+
options.args.push(arg);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
i++;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return options;
|
|
133
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
|
|
3
|
+
/** Injectable I/O for testing without real stdin. */
|
|
4
|
+
export interface PromptIO {
|
|
5
|
+
ask: (question: string) => Promise<string>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Prompts the user on stdin (TTY only) and returns the
|
|
10
|
+
* trimmed reply.
|
|
11
|
+
*
|
|
12
|
+
* @param question - the prompt text to display
|
|
13
|
+
* @param io - injectable I/O (defaults to readline on
|
|
14
|
+
* process.stdin/stdout)
|
|
15
|
+
*/
|
|
16
|
+
export async function promptUser(
|
|
17
|
+
question: string,
|
|
18
|
+
io?: PromptIO,
|
|
19
|
+
): Promise<string> {
|
|
20
|
+
const ask = io?.ask ?? askReadline;
|
|
21
|
+
const answer = await ask(question);
|
|
22
|
+
return answer.trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function askReadline(question: string): Promise<string> {
|
|
26
|
+
return new Promise<string>((resolve) => {
|
|
27
|
+
const rl = createInterface({
|
|
28
|
+
input: process.stdin,
|
|
29
|
+
output: process.stdout,
|
|
30
|
+
});
|
|
31
|
+
rl.question(question, (answer) => {
|
|
32
|
+
rl.close();
|
|
33
|
+
resolve(answer);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { CommandResult } from '../typings/command-result.model.ts';
|
|
3
|
+
import type { AddSectionResult } from '../../worker-client/typings/add-section-result.model.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Minimal client interface required by `runAgentCreate`.
|
|
7
|
+
*
|
|
8
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
9
|
+
* implementation, making it straightforward to test with mocks.
|
|
10
|
+
*/
|
|
11
|
+
export interface AgentCreateClient {
|
|
12
|
+
/**
|
|
13
|
+
* Ingests a content section into the knowledge base.
|
|
14
|
+
*
|
|
15
|
+
* @param params - section type label, raw content, and optional
|
|
16
|
+
* metadata
|
|
17
|
+
* @returns result object containing the assigned knowledge-base
|
|
18
|
+
* identifier
|
|
19
|
+
*/
|
|
20
|
+
addSection(params: {
|
|
21
|
+
readonly sectionType: string;
|
|
22
|
+
readonly content: string;
|
|
23
|
+
readonly title?: string;
|
|
24
|
+
readonly description?: string;
|
|
25
|
+
}): Promise<AddSectionResult>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Groups a set of sections under a named document.
|
|
29
|
+
*
|
|
30
|
+
* @param title - human-readable document title
|
|
31
|
+
* @param kbids - identifiers of the sections to group
|
|
32
|
+
* @param docType - application-level document type tag; omit or
|
|
33
|
+
* pass an empty string for untagged documents
|
|
34
|
+
* @returns the assigned document identifier
|
|
35
|
+
*/
|
|
36
|
+
groupSections(
|
|
37
|
+
title: string,
|
|
38
|
+
kbids: string[],
|
|
39
|
+
docType?: string,
|
|
40
|
+
): Promise<string>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves one or more sections by their identifiers.
|
|
44
|
+
*
|
|
45
|
+
* @param kbids - list of knowledge-base identifiers to fetch
|
|
46
|
+
* @returns sections found; missing kbids are omitted from the result
|
|
47
|
+
*/
|
|
48
|
+
readSections(kbids: string[]): Promise<{ kbid: string }[]>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new agent in the knowledge base.
|
|
53
|
+
*
|
|
54
|
+
* Validates `--name` and `--persona` options, verifies that all
|
|
55
|
+
* referenced skill kbids exist, stores agent metadata as a JSON
|
|
56
|
+
* section, and groups all sections under a single document.
|
|
57
|
+
*
|
|
58
|
+
* @param client - agent create client to delegate operations to
|
|
59
|
+
* @param options - parsed CLI options providing `name`, `persona`,
|
|
60
|
+
* optional `description`, and optional `skills` kbid list
|
|
61
|
+
* @returns a `CommandResult` with serialised creation info or an
|
|
62
|
+
* error message and a non-zero exit code
|
|
63
|
+
*/
|
|
64
|
+
export async function runAgentCreate(
|
|
65
|
+
client: AgentCreateClient,
|
|
66
|
+
options: CliOptions,
|
|
67
|
+
): Promise<CommandResult> {
|
|
68
|
+
const name = options.name;
|
|
69
|
+
if (!name) {
|
|
70
|
+
return { error: '--name is required', exitCode: 1 };
|
|
71
|
+
}
|
|
72
|
+
const persona = options.persona;
|
|
73
|
+
if (!persona) {
|
|
74
|
+
return { error: '--persona is required', exitCode: 1 };
|
|
75
|
+
}
|
|
76
|
+
const skills = options.skills ?? [];
|
|
77
|
+
|
|
78
|
+
if (skills.length > 0) {
|
|
79
|
+
const sections = await client.readSections(skills);
|
|
80
|
+
const found = new Set(sections.map((s) => s.kbid));
|
|
81
|
+
const missing = skills.filter((k) => !found.has(k));
|
|
82
|
+
if (missing.length > 0) {
|
|
83
|
+
return {
|
|
84
|
+
error: `skill not found: ${missing.join(', ')}`,
|
|
85
|
+
exitCode: 1,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const metadata = JSON.stringify({
|
|
91
|
+
name,
|
|
92
|
+
description: options.description ?? '',
|
|
93
|
+
persona,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const metaResult = await client.addSection({
|
|
97
|
+
sectionType: 'text',
|
|
98
|
+
content: metadata,
|
|
99
|
+
title: name,
|
|
100
|
+
description: options.description,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const allKbids = [metaResult.kbid, ...skills];
|
|
104
|
+
const docid = await client.groupSections(name, allKbids, 'agent');
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
output: JSON.stringify(
|
|
108
|
+
{ docid, name, skillCount: skills.length },
|
|
109
|
+
null,
|
|
110
|
+
2,
|
|
111
|
+
),
|
|
112
|
+
exitCode: 0,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -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 `runAgentDelete`.
|
|
6
|
+
*
|
|
7
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
8
|
+
* implementation, making it straightforward to test with mocks.
|
|
9
|
+
*/
|
|
10
|
+
export interface AgentDeleteClient {
|
|
11
|
+
/**
|
|
12
|
+
* Removes the document grouping for the given document.
|
|
13
|
+
*
|
|
14
|
+
* The sections themselves are not deleted; only the grouping
|
|
15
|
+
* record is removed.
|
|
16
|
+
*
|
|
17
|
+
* @param docid - identifier of the document grouping to remove
|
|
18
|
+
*/
|
|
19
|
+
removeGrouping(docid: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Deletes an agent from the knowledge base.
|
|
24
|
+
*
|
|
25
|
+
* Removes the document grouping identified by `options.args[0]`.
|
|
26
|
+
* Skill sections referenced by the agent are not deleted; only
|
|
27
|
+
* the grouping record is removed.
|
|
28
|
+
*
|
|
29
|
+
* @param client - agent delete client to delegate removal to
|
|
30
|
+
* @param options - parsed CLI options; `args[0]` must be the docid
|
|
31
|
+
* @returns a `CommandResult` confirming removal or an error message
|
|
32
|
+
* with a non-zero exit code
|
|
33
|
+
*/
|
|
34
|
+
export async function runAgentDelete(
|
|
35
|
+
client: AgentDeleteClient,
|
|
36
|
+
options: CliOptions,
|
|
37
|
+
): Promise<CommandResult> {
|
|
38
|
+
const docid = options.args[0];
|
|
39
|
+
if (!docid) {
|
|
40
|
+
return { error: 'docid is required', exitCode: 1 };
|
|
41
|
+
}
|
|
42
|
+
await client.removeGrouping(docid);
|
|
43
|
+
return {
|
|
44
|
+
output: JSON.stringify({ docid, removed: true }, null, 2),
|
|
45
|
+
exitCode: 0,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { CommandResult } from '../typings/command-result.model.ts';
|
|
3
|
+
|
|
4
|
+
/** A document section reference as returned by `retrieveDocument`. */
|
|
5
|
+
interface DocumentSection {
|
|
6
|
+
/** Knowledge-base identifier of the section. */
|
|
7
|
+
readonly kbid: string;
|
|
8
|
+
/** Zero-based position of the section within the document. */
|
|
9
|
+
readonly position: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A document record as returned by `retrieveDocument`. */
|
|
13
|
+
interface AgentDocument {
|
|
14
|
+
/** Unique document identifier. */
|
|
15
|
+
readonly docid: string;
|
|
16
|
+
/** Human-readable document title used as agent name fallback. */
|
|
17
|
+
readonly title: string;
|
|
18
|
+
/** Ordered list of section references. */
|
|
19
|
+
readonly sections: DocumentSection[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A section record as returned by `readSections`. */
|
|
23
|
+
interface SectionRecord {
|
|
24
|
+
/** Knowledge-base identifier of the section. */
|
|
25
|
+
readonly kbid: string;
|
|
26
|
+
/** Raw text content stored in the section. */
|
|
27
|
+
readonly content: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Minimal client interface required by `runAgentGet`.
|
|
32
|
+
*
|
|
33
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
34
|
+
* implementation, making it straightforward to test with mocks.
|
|
35
|
+
*/
|
|
36
|
+
export interface AgentGetClient {
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves a full document record including its ordered sections.
|
|
39
|
+
*
|
|
40
|
+
* @param docid - identifier of the document to retrieve
|
|
41
|
+
* @returns the document record
|
|
42
|
+
*/
|
|
43
|
+
retrieveDocument(docid: string): Promise<unknown>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves one or more sections by their identifiers.
|
|
47
|
+
*
|
|
48
|
+
* @param kbids - list of knowledge-base identifiers to fetch
|
|
49
|
+
* @returns sections found; missing kbids are omitted from the result
|
|
50
|
+
*/
|
|
51
|
+
readSections(kbids: string[]): Promise<SectionRecord[]>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Reads agent metadata from the first section's JSON content.
|
|
56
|
+
* Falls back to `fallbackName` when the section is absent or the
|
|
57
|
+
* content cannot be parsed.
|
|
58
|
+
*/
|
|
59
|
+
async function readAgentMeta(
|
|
60
|
+
client: AgentGetClient,
|
|
61
|
+
metaKbid: string,
|
|
62
|
+
fallbackName: string,
|
|
63
|
+
): Promise<{ name: string; description: string; persona: string }> {
|
|
64
|
+
const sections = await client.readSections([metaKbid]);
|
|
65
|
+
const first = sections.at(0);
|
|
66
|
+
if (!first) {
|
|
67
|
+
return { name: fallbackName, description: '', persona: '' };
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const meta = JSON.parse(first.content) as Record<string, unknown>;
|
|
71
|
+
return {
|
|
72
|
+
name:
|
|
73
|
+
typeof meta['name'] === 'string'
|
|
74
|
+
? meta['name']
|
|
75
|
+
: fallbackName,
|
|
76
|
+
description:
|
|
77
|
+
typeof meta['description'] === 'string'
|
|
78
|
+
? meta['description']
|
|
79
|
+
: '',
|
|
80
|
+
persona:
|
|
81
|
+
typeof meta['persona'] === 'string' ? meta['persona'] : '',
|
|
82
|
+
};
|
|
83
|
+
} catch {
|
|
84
|
+
return { name: fallbackName, description: '', persona: '' };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Resolves skill names by reading each skill section's JSON content.
|
|
90
|
+
* Returns `null` for any reference whose section no longer exists
|
|
91
|
+
* (dangling reference).
|
|
92
|
+
*/
|
|
93
|
+
async function resolveSkills(
|
|
94
|
+
client: AgentGetClient,
|
|
95
|
+
skillRefs: DocumentSection[],
|
|
96
|
+
): Promise<{ kbid: string; name: string | null; position: number }[]> {
|
|
97
|
+
if (skillRefs.length === 0) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
const kbids = skillRefs.map((r) => r.kbid);
|
|
101
|
+
const sections = await client.readSections(kbids);
|
|
102
|
+
const sectionMap = new Map(sections.map((s) => [s.kbid, s]));
|
|
103
|
+
return skillRefs.map((ref) => {
|
|
104
|
+
const sec = sectionMap.get(ref.kbid);
|
|
105
|
+
if (!sec) {
|
|
106
|
+
return { kbid: ref.kbid, name: null, position: ref.position };
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const parsed = JSON.parse(sec.content) as Record<
|
|
110
|
+
string,
|
|
111
|
+
unknown
|
|
112
|
+
>;
|
|
113
|
+
const skillName =
|
|
114
|
+
typeof parsed['name'] === 'string' ? parsed['name'] : null;
|
|
115
|
+
return {
|
|
116
|
+
kbid: ref.kbid,
|
|
117
|
+
name: skillName,
|
|
118
|
+
position: ref.position,
|
|
119
|
+
};
|
|
120
|
+
} catch {
|
|
121
|
+
return { kbid: ref.kbid, name: null, position: ref.position };
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Retrieves a full agent definition from the knowledge base.
|
|
128
|
+
*
|
|
129
|
+
* Reads the agent document identified by `options.args[0]`, extracts
|
|
130
|
+
* metadata (name, description, persona) from the first section, and
|
|
131
|
+
* resolves skill names from the remaining sections. Dangling skill
|
|
132
|
+
* references appear with `name: null`.
|
|
133
|
+
*
|
|
134
|
+
* @param client - agent get client to delegate retrieval to
|
|
135
|
+
* @param options - parsed CLI options; `args[0]` must be the docid
|
|
136
|
+
* @returns a `CommandResult` with serialised agent definition or an
|
|
137
|
+
* error message and a non-zero exit code
|
|
138
|
+
*/
|
|
139
|
+
export async function runAgentGet(
|
|
140
|
+
client: AgentGetClient,
|
|
141
|
+
options: CliOptions,
|
|
142
|
+
): Promise<CommandResult> {
|
|
143
|
+
const docid = options.args[0];
|
|
144
|
+
if (!docid) {
|
|
145
|
+
return { error: 'docid is required', exitCode: 1 };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const doc = (await client.retrieveDocument(docid)) as AgentDocument;
|
|
149
|
+
const metaKbid = doc.sections[0]?.kbid;
|
|
150
|
+
const skillRefs = doc.sections.slice(1);
|
|
151
|
+
|
|
152
|
+
const { name, description, persona } = metaKbid
|
|
153
|
+
? await readAgentMeta(client, metaKbid, doc.title)
|
|
154
|
+
: { name: doc.title, description: '', persona: '' };
|
|
155
|
+
|
|
156
|
+
const skills = await resolveSkills(client, skillRefs);
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
output: JSON.stringify(
|
|
160
|
+
{ docid, name, description, persona, skills },
|
|
161
|
+
null,
|
|
162
|
+
2,
|
|
163
|
+
),
|
|
164
|
+
exitCode: 0,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
import type { CommandResult } from '../typings/command-result.model.ts';
|
|
3
|
+
|
|
4
|
+
/** A document summary as returned by `listDocumentsByType`. */
|
|
5
|
+
interface DocumentSummary {
|
|
6
|
+
/** Unique document identifier. */
|
|
7
|
+
readonly docid: string;
|
|
8
|
+
/** Human-readable document title used as the agent name. */
|
|
9
|
+
readonly title: string;
|
|
10
|
+
/** Ordered list of section references for this document. */
|
|
11
|
+
readonly sections: readonly { kbid: string; position: number }[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Minimal client interface required by `runAgentList`.
|
|
16
|
+
*
|
|
17
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
18
|
+
* implementation, making it straightforward to test with mocks.
|
|
19
|
+
*/
|
|
20
|
+
export interface AgentListClient {
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves all documents whose type name matches the given string.
|
|
23
|
+
*
|
|
24
|
+
* @param docType - the application-level document type to filter by
|
|
25
|
+
* @returns all document summaries with a matching type name
|
|
26
|
+
*/
|
|
27
|
+
listDocumentsByType(docType: string): Promise<DocumentSummary[]>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Lists all agents stored in the knowledge base.
|
|
32
|
+
*
|
|
33
|
+
* Retrieves all documents with `doc_type: 'agent'` and returns a
|
|
34
|
+
* summary list. The `skillCount` for each agent is
|
|
35
|
+
* `Math.max(0, sections.length - 1)` because the first section
|
|
36
|
+
* always holds the agent's metadata JSON rather than a skill
|
|
37
|
+
* reference.
|
|
38
|
+
*
|
|
39
|
+
* @param client - agent list client to delegate retrieval to
|
|
40
|
+
* @param _options - parsed CLI options (unused; reserved for future
|
|
41
|
+
* filtering flags)
|
|
42
|
+
* @returns a `CommandResult` with serialised agent summary list
|
|
43
|
+
*/
|
|
44
|
+
export async function runAgentList(
|
|
45
|
+
client: AgentListClient,
|
|
46
|
+
_options: CliOptions,
|
|
47
|
+
): Promise<CommandResult> {
|
|
48
|
+
const docs = await client.listDocumentsByType('agent');
|
|
49
|
+
const items = docs.map((d) => ({
|
|
50
|
+
docid: d.docid,
|
|
51
|
+
name: d.title,
|
|
52
|
+
skillCount: Math.max(0, d.sections.length - 1),
|
|
53
|
+
}));
|
|
54
|
+
return {
|
|
55
|
+
output: JSON.stringify(items, null, 2),
|
|
56
|
+
exitCode: 0,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
2
|
+
|
|
3
|
+
/** A single integrity error found during a database check. */
|
|
4
|
+
interface IntegrityError {
|
|
5
|
+
/**
|
|
6
|
+
* The category of integrity violation detected.
|
|
7
|
+
*
|
|
8
|
+
* - `'checksum_mismatch'` -- stored content does not match its hash
|
|
9
|
+
* - `'orphan_section'` -- section not referenced by any document
|
|
10
|
+
* - `'orphan_document'` -- document references no existing sections
|
|
11
|
+
* - `'broken_reference'` -- a marker references a non-existent entity
|
|
12
|
+
* - `'type_mismatch'` -- stored MIME type conflicts with content
|
|
13
|
+
* - `'circular_reference'` -- marker chain contains a cycle
|
|
14
|
+
*/
|
|
15
|
+
readonly type:
|
|
16
|
+
| 'checksum_mismatch'
|
|
17
|
+
| 'orphan_section'
|
|
18
|
+
| 'orphan_document'
|
|
19
|
+
| 'broken_reference'
|
|
20
|
+
| 'type_mismatch'
|
|
21
|
+
| 'circular_reference';
|
|
22
|
+
/** Identifier of the entity (kbid or docid) that has the issue. */
|
|
23
|
+
readonly entity: string;
|
|
24
|
+
/** Human-readable description of the specific problem. */
|
|
25
|
+
readonly detail: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Integrity check report returned by the daemon.
|
|
30
|
+
*/
|
|
31
|
+
interface IntegrityCheckResult {
|
|
32
|
+
/** `true` when all checks passed and no errors were found. */
|
|
33
|
+
readonly ok: boolean;
|
|
34
|
+
/** All integrity errors found; empty when `ok` is `true`. */
|
|
35
|
+
readonly errors: IntegrityError[];
|
|
36
|
+
/** Total number of sections examined. */
|
|
37
|
+
readonly sections_checked: number;
|
|
38
|
+
/** Total number of documents examined. */
|
|
39
|
+
readonly documents_checked: number;
|
|
40
|
+
/** Total number of marker references checked. */
|
|
41
|
+
readonly references_checked: number;
|
|
42
|
+
/** Time taken to complete the check, in milliseconds. */
|
|
43
|
+
readonly elapsed_ms: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Minimal client interface required by `runCheck`.
|
|
48
|
+
*
|
|
49
|
+
* Decouples the CLI function from the concrete `WorkerClient`
|
|
50
|
+
* implementation, making it straightforward to test with mocks.
|
|
51
|
+
*/
|
|
52
|
+
export interface CheckClient {
|
|
53
|
+
/**
|
|
54
|
+
* Runs an integrity check on the knowledge-base database.
|
|
55
|
+
*
|
|
56
|
+
* @returns a report of all issues found; `ok` is `true` when
|
|
57
|
+
* no errors were detected
|
|
58
|
+
*/
|
|
59
|
+
integrityCheck(): Promise<IntegrityCheckResult>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Runs an integrity check on the database and returns the report.
|
|
64
|
+
*
|
|
65
|
+
* Delegates to `client.integrityCheck()`. The caller is responsible
|
|
66
|
+
* for printing the result to stdout and setting the process exit code
|
|
67
|
+
* based on `result.ok`.
|
|
68
|
+
*
|
|
69
|
+
* @param client - check client to delegate to
|
|
70
|
+
* @param _options - parsed CLI options (unused; reserved for future flags)
|
|
71
|
+
* @returns the integrity check report from the daemon
|
|
72
|
+
*/
|
|
73
|
+
export async function runCheck(
|
|
74
|
+
client: CheckClient,
|
|
75
|
+
_options: CliOptions,
|
|
76
|
+
): Promise<IntegrityCheckResult> {
|
|
77
|
+
return client.integrityCheck();
|
|
78
|
+
}
|