@dikolab/kbdb 0.3.1 → 0.4.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/README.md +108 -126
- package/dist/chunk-BJPSPNGX.mjs +223 -0
- package/dist/chunk-BJPSPNGX.mjs.map +7 -0
- package/dist/cli.cjs +956 -319
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.d.ts +9 -0
- package/dist/cli.mjs +840 -321
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +714 -94
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +122 -16
- package/dist/mod.cjs.map +3 -3
- package/dist/mod.d.ts +23 -2
- package/dist/mod.mjs +121 -16
- package/dist/mod.mjs.map +3 -3
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -1
- package/dist/src/shared/cli/functions/find-db.function.d.ts +7 -8
- package/dist/src/shared/cli/functions/handle-mcp.function.d.ts +1 -1
- package/dist/src/shared/cli/functions/parse-args.function.d.ts +4 -3
- package/dist/src/shared/cli/functions/resolve-kbid-prefix.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +10 -0
- package/dist/src/shared/cli/functions/run-cli.function.d.ts +3 -1
- package/dist/src/shared/cli/functions/run-content.function.d.ts +8 -3
- package/dist/src/shared/cli/functions/run-import.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/run-recall.function.d.ts +10 -4
- package/dist/src/shared/cli/functions/run-search.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +9 -4
- package/dist/src/shared/cli/functions/run-worker-restart.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/run-worker-stop.function.d.ts +11 -0
- package/dist/src/shared/cli/index.d.ts +2 -0
- package/dist/src/shared/cli/typings/cli-deps.interface.d.ts +4 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +17 -0
- package/dist/src/shared/cli/typings/dispatch-client.type.d.ts +2 -1
- package/dist/src/shared/cli/typings/search-display.model.d.ts +6 -0
- package/dist/src/shared/embedding/classes/api-embedding-provider.class.d.ts +33 -0
- package/dist/src/shared/embedding/classes/onnx-embedding-provider.class.d.ts +33 -0
- package/dist/src/shared/embedding/functions/append-vector-entry.function.d.ts +14 -0
- package/dist/src/shared/embedding/functions/create-embedding-provider.function.d.ts +12 -0
- package/dist/src/shared/embedding/functions/detect-stale-vectors.function.d.ts +16 -0
- package/dist/src/shared/embedding/functions/parse-api-embedding-response.function.d.ts +11 -0
- package/dist/src/shared/embedding/functions/rebuild-vectors.function.d.ts +15 -0
- package/dist/src/shared/embedding/functions/scan-semantic-contradictions.function.d.ts +13 -0
- package/dist/src/shared/embedding/index.d.ts +7 -0
- package/dist/src/shared/embedding/typings/semantic-contradiction.model.d.ts +21 -0
- package/dist/src/shared/embedding/typings/stale-vectors-report.model.d.ts +16 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +22 -2
- package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +6 -1
- package/dist/src/shared/mcp/functions/has-sampling-capability.function.d.ts +8 -0
- package/dist/src/shared/mcp/functions/run-auto-capture.function.d.ts +26 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +2 -0
- package/dist/src/shared/mcp/typings/mcp-integrity-check-result.model.d.ts +24 -0
- package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +3 -1
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/typings/paged-search-result.model.d.ts +2 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +31 -1
- package/dist/src/shared/worker-client/constants/request-timeout.constant.d.ts +2 -0
- package/dist/src/shared/worker-client/constants/retry-defaults.constant.d.ts +2 -0
- package/dist/src/shared/worker-client/functions/get-or-create-client.function.d.ts +20 -0
- package/dist/src/shared/worker-client/functions/retry-on-timeout.function.d.ts +17 -0
- package/dist/src/shared/worker-client/index.d.ts +4 -1
- package/dist/src/shared/worker-client/typings/import-result.model.d.ts +16 -0
- package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +24 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +4 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +6 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +7 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +5 -0
- package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +11 -11
- package/dist/src/shared/worker-daemon/functions/embed-after-learn.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/functions/handle-hybrid-search.function.d.ts +44 -0
- package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +14 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +7 -1
- package/dist/src/shared/worker-daemon/functions/handle-write-ops.function.d.ts +9 -4
- package/dist/src/shared/worker-daemon/typings/handler-context.interface.d.ts +3 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +16 -85
- package/dist/wasm/fs-database/kbdb_fs_database.js +16 -85
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +20 -115
- package/dist/wasm/kb-worker/kbdb_worker.js +20 -115
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.mjs +606 -102
- package/dist/worker.mjs.map +4 -4
- package/docs/details/README.md +4 -0
- package/docs/details/agent-tooling.md +122 -0
- package/docs/details/cli.md +78 -12
- package/docs/details/knowledge-base.md +173 -0
- package/docs/details/library-api.md +42 -2
- package/docs/details/mcp-server.md +39 -8
- package/docs/details/search-and-ranking.md +56 -0
- package/docs/goals/cli.md +110 -34
- package/docs/goals/mcp.md +22 -19
- package/docs/goals/query-parser.md +8 -0
- package/docs/goals/worker-client.md +62 -1
- package/docs/goals/worker-daemon.md +52 -10
- package/docs/modules/typescript/cli.md +1 -1
- package/docs/modules/typescript/shared/cli/functions.md +116 -13
- package/docs/modules/typescript/shared/cli/module.md +33 -20
- package/docs/modules/typescript/shared/cli/typings.md +4 -0
- package/docs/modules/typescript/shared/embedding/functions.md +104 -25
- package/docs/modules/typescript/shared/mcp/module.md +1 -1
- package/docs/modules/typescript/shared/mcp/typings.md +8 -1
- package/docs/modules/typescript/shared/worker-client/module.md +9 -1
- package/docs/modules/typescript/shared/worker-client/typings.md +3 -0
- package/docs/modules/typescript/shared/worker-daemon/module.md +6 -3
- package/docs/overview.md +43 -22
- package/docs/release-notes/0.3.1.md +10 -0
- package/docs/release-notes/0.3.2.md +64 -0
- package/docs/release-notes/0.4.0.md +80 -0
- package/docs/release-notes/README.md +2 -0
- package/mod.ts +33 -15
- package/package.json +11 -10
- package/dist/chunk-JG2UCKLI.mjs +0 -95
- package/dist/chunk-JG2UCKLI.mjs.map +0 -7
- package/src/cli.ts +0 -71
- package/src/shared/auto-capture/classes/auto-capture-controller.class.ts +0 -62
- package/src/shared/auto-capture/constants/auto-capture-defaults.constant.ts +0 -15
- package/src/shared/auto-capture/functions/build-capture-prompt.function.ts +0 -27
- package/src/shared/auto-capture/functions/evaluate-trigger.function.ts +0 -50
- package/src/shared/auto-capture/index.ts +0 -7
- package/src/shared/auto-capture/typings/auto-capture-config.interface.ts +0 -13
- package/src/shared/auto-capture/typings/auto-capture-state.interface.ts +0 -13
- package/src/shared/auto-capture/typings/auto-capture-trigger.interface.ts +0 -7
- package/src/shared/cli/constants/defaults.constant.ts +0 -19
- package/src/shared/cli/constants/global-help.constant.ts +0 -73
- package/src/shared/cli/constants/help-text.constant.ts +0 -4
- package/src/shared/cli/constants/leaf-help.constant.ts +0 -219
- package/src/shared/cli/constants/memory-protocol-body.constant.ts +0 -39
- package/src/shared/cli/constants/query-guidance-body.constant.ts +0 -37
- package/src/shared/cli/constants/subcommand-help.constant.ts +0 -195
- package/src/shared/cli/functions/collect-files.function.ts +0 -55
- package/src/shared/cli/functions/compute-section-kbid.function.ts +0 -49
- package/src/shared/cli/functions/dispatch-command.function.ts +0 -390
- package/src/shared/cli/functions/ensure-db.function.ts +0 -21
- package/src/shared/cli/functions/error-to-message.function.ts +0 -9
- package/src/shared/cli/functions/find-db.function.ts +0 -20
- package/src/shared/cli/functions/format-mcp-output.function.ts +0 -41
- package/src/shared/cli/functions/format-output.function.ts +0 -95
- package/src/shared/cli/functions/format-text-output.function.ts +0 -42
- package/src/shared/cli/functions/generate-group-help.function.ts +0 -41
- package/src/shared/cli/functions/generate-help.function.ts +0 -654
- package/src/shared/cli/functions/handle-data-command.function.ts +0 -67
- package/src/shared/cli/functions/handle-mcp.function.ts +0 -56
- package/src/shared/cli/functions/handle-migrate.function.ts +0 -64
- package/src/shared/cli/functions/hydrate-search-previews.function.ts +0 -29
- package/src/shared/cli/functions/install-default-skills.function.ts +0 -296
- package/src/shared/cli/functions/is-stdin-tty.function.ts +0 -12
- package/src/shared/cli/functions/parse-args.function.ts +0 -156
- package/src/shared/cli/functions/prompt-user.function.ts +0 -36
- package/src/shared/cli/functions/resolve-skill-names.function.ts +0 -43
- package/src/shared/cli/functions/run-agent-create.function.ts +0 -114
- package/src/shared/cli/functions/run-agent-delete.function.ts +0 -47
- package/src/shared/cli/functions/run-agent-get.function.ts +0 -166
- package/src/shared/cli/functions/run-agent-list.function.ts +0 -58
- package/src/shared/cli/functions/run-check.function.ts +0 -159
- package/src/shared/cli/functions/run-cli.function.ts +0 -299
- package/src/shared/cli/functions/run-content.function.ts +0 -47
- package/src/shared/cli/functions/run-db-init.function.ts +0 -44
- package/src/shared/cli/functions/run-db-migrate.function.ts +0 -40
- package/src/shared/cli/functions/run-export.function.ts +0 -40
- package/src/shared/cli/functions/run-gc.function.ts +0 -51
- package/src/shared/cli/functions/run-init.function.ts +0 -93
- package/src/shared/cli/functions/run-learn.function.ts +0 -223
- package/src/shared/cli/functions/run-migrate.function.ts +0 -85
- package/src/shared/cli/functions/run-rebuild.function.ts +0 -47
- package/src/shared/cli/functions/run-recall.function.ts +0 -66
- package/src/shared/cli/functions/run-search.function.ts +0 -133
- package/src/shared/cli/functions/run-skill-delete.function.ts +0 -47
- package/src/shared/cli/functions/run-skill-get.function.ts +0 -90
- package/src/shared/cli/functions/run-skill-learn.function.ts +0 -70
- package/src/shared/cli/functions/run-skill-list.function.ts +0 -74
- package/src/shared/cli/functions/run-status.function.ts +0 -29
- package/src/shared/cli/functions/run-unlearn.function.ts +0 -58
- package/src/shared/cli/functions/version-gate.function.ts +0 -44
- package/src/shared/cli/functions/wrap-command.function.ts +0 -34
- package/src/shared/cli/index.ts +0 -55
- package/src/shared/cli/typings/agent-create-client.interface.ts +0 -47
- package/src/shared/cli/typings/agent-get-client.interface.ts +0 -39
- package/src/shared/cli/typings/check-client.interface.ts +0 -66
- package/src/shared/cli/typings/cli-deps.interface.ts +0 -54
- package/src/shared/cli/typings/cli-options.interface.ts +0 -72
- package/src/shared/cli/typings/command-result.model.ts +0 -15
- package/src/shared/cli/typings/disconnectable-client.interface.ts +0 -29
- package/src/shared/cli/typings/dispatch-client.type.ts +0 -46
- package/src/shared/cli/typings/learn-client.interface.ts +0 -53
- package/src/shared/cli/typings/learn-io.interface.ts +0 -5
- package/src/shared/cli/typings/learn-result.model.ts +0 -27
- package/src/shared/cli/typings/search-client.interface.ts +0 -73
- package/src/shared/cli/typings/search-display.model.ts +0 -54
- package/src/shared/dir-resolver/functions/join-path.function.ts +0 -13
- package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +0 -25
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +0 -5
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +0 -13
- package/src/shared/dir-resolver/index.ts +0 -11
- package/src/shared/dir-resolver/typings/base-dir.interface.ts +0 -4
- package/src/shared/embedding/classes/null-embedding-provider.class.ts +0 -29
- package/src/shared/embedding/constants/near-duplicate-thresholds.constant.ts +0 -17
- package/src/shared/embedding/functions/build-vector-index.function.ts +0 -79
- package/src/shared/embedding/functions/cosine-similarity.function.ts +0 -31
- package/src/shared/embedding/functions/detect-near-duplicates.function.ts +0 -69
- package/src/shared/embedding/functions/jaccard-coefficient.function.ts +0 -26
- package/src/shared/embedding/functions/read-vector-index-meta.function.ts +0 -44
- package/src/shared/embedding/functions/rrf-fuse.function.ts +0 -33
- package/src/shared/embedding/functions/search-vectors.function.ts +0 -59
- package/src/shared/embedding/index.ts +0 -20
- package/src/shared/embedding/typings/embedding-config.interface.ts +0 -23
- package/src/shared/embedding/typings/embedding-provider.interface.ts +0 -25
- package/src/shared/embedding/typings/near-duplicate-candidate.model.ts +0 -25
- package/src/shared/embedding/typings/near-duplicate-result.model.ts +0 -26
- package/src/shared/embedding/typings/vector-index-entry.model.ts +0 -13
- package/src/shared/embedding/typings/vector-index-meta.model.ts +0 -14
- package/src/shared/embedding/typings/vector-search-result.model.ts +0 -8
- package/src/shared/hash/functions/compute-sha256.ts +0 -17
- package/src/shared/hash/index.ts +0 -1
- package/src/shared/mcp/classes/mcp-server.class.ts +0 -480
- package/src/shared/mcp/constants/mcp-error-codes.constant.ts +0 -30
- package/src/shared/mcp/constants/tool-agent-create.constant.ts +0 -39
- package/src/shared/mcp/constants/tool-agent-delete.constant.ts +0 -26
- package/src/shared/mcp/constants/tool-agent-get.constant.ts +0 -24
- package/src/shared/mcp/constants/tool-agent-list.constant.ts +0 -18
- package/src/shared/mcp/constants/tool-auto-capture-review.constant.ts +0 -32
- package/src/shared/mcp/constants/tool-check.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-content.constant.ts +0 -29
- package/src/shared/mcp/constants/tool-export.constant.ts +0 -27
- package/src/shared/mcp/constants/tool-gc.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-learn.constant.ts +0 -58
- package/src/shared/mcp/constants/tool-rebuild.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-recall.constant.ts +0 -36
- package/src/shared/mcp/constants/tool-retrieve.constant.ts +0 -31
- package/src/shared/mcp/constants/tool-search.constant.ts +0 -51
- package/src/shared/mcp/constants/tool-skill-delete.constant.ts +0 -24
- package/src/shared/mcp/constants/tool-skill-get.constant.ts +0 -27
- package/src/shared/mcp/constants/tool-skill-learn.constant.ts +0 -37
- package/src/shared/mcp/constants/tool-skill-list.constant.ts +0 -18
- package/src/shared/mcp/constants/tool-status.constant.ts +0 -20
- package/src/shared/mcp/constants/tool-unlearn.constant.ts +0 -25
- package/src/shared/mcp/functions/as-boolean-or-undefined.function.ts +0 -11
- package/src/shared/mcp/functions/as-string-array-or-undefined.function.ts +0 -17
- package/src/shared/mcp/functions/as-string-array.function.ts +0 -15
- package/src/shared/mcp/functions/as-string.function.ts +0 -10
- package/src/shared/mcp/functions/build-skills-text.function.ts +0 -43
- package/src/shared/mcp/functions/create-mcp-server.function.ts +0 -14
- package/src/shared/mcp/functions/create-prompt-definitions.function.ts +0 -102
- package/src/shared/mcp/functions/create-resource-templates.function.ts +0 -23
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +0 -530
- package/src/shared/mcp/functions/extract-skill-arguments.function.ts +0 -27
- package/src/shared/mcp/functions/handle-agent-create.function.ts +0 -116
- package/src/shared/mcp/functions/handle-agent-delete.function.ts +0 -50
- package/src/shared/mcp/functions/handle-agent-get.function.ts +0 -160
- package/src/shared/mcp/functions/handle-agent-list.function.ts +0 -50
- package/src/shared/mcp/functions/handle-agent-prompt.function.ts +0 -68
- package/src/shared/mcp/functions/handle-completion.function.ts +0 -114
- package/src/shared/mcp/functions/handle-mcp-request.function.ts +0 -202
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +0 -220
- package/src/shared/mcp/functions/handle-recall.function.ts +0 -66
- package/src/shared/mcp/functions/handle-resource-read.function.ts +0 -56
- package/src/shared/mcp/functions/handle-roots-list.function.ts +0 -29
- package/src/shared/mcp/functions/handle-skill-prompt.function.ts +0 -44
- package/src/shared/mcp/functions/handle-tool-auto-capture-review.function.ts +0 -24
- package/src/shared/mcp/functions/handle-tool-call.function.ts +0 -560
- package/src/shared/mcp/functions/handle-tool-check.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-content.function.ts +0 -23
- package/src/shared/mcp/functions/handle-tool-export.function.ts +0 -25
- package/src/shared/mcp/functions/handle-tool-gc.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-learn.function.ts +0 -69
- package/src/shared/mcp/functions/handle-tool-rebuild.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-retrieve.function.ts +0 -40
- package/src/shared/mcp/functions/handle-tool-search.function.ts +0 -47
- package/src/shared/mcp/functions/handle-tool-skill-delete.function.ts +0 -34
- package/src/shared/mcp/functions/handle-tool-skill-get.function.ts +0 -59
- package/src/shared/mcp/functions/handle-tool-skill-learn.function.ts +0 -61
- package/src/shared/mcp/functions/handle-tool-skill-list.function.ts +0 -39
- package/src/shared/mcp/functions/handle-tool-status.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-unlearn.function.ts +0 -24
- package/src/shared/mcp/functions/parse-agent-meta.function.ts +0 -27
- package/src/shared/mcp/functions/parse-skill-arguments.function.ts +0 -36
- package/src/shared/mcp/functions/parse-skill-content.function.ts +0 -38
- package/src/shared/mcp/functions/read-agent-meta.function.ts +0 -41
- package/src/shared/mcp/functions/resolve-skill-refs.function.ts +0 -50
- package/src/shared/mcp/functions/run-startup-health-check.function.ts +0 -34
- package/src/shared/mcp/functions/serialize-skill-content.function.ts +0 -12
- package/src/shared/mcp/functions/should-emit-log.function.ts +0 -38
- package/src/shared/mcp/index.ts +0 -28
- package/src/shared/mcp/typings/agent-types.interface.ts +0 -39
- package/src/shared/mcp/typings/log-types.interface.ts +0 -26
- package/src/shared/mcp/typings/mcp-capabilities.interface.ts +0 -16
- package/src/shared/mcp/typings/mcp-client.interface.ts +0 -317
- package/src/shared/mcp/typings/mcp-completion.interface.ts +0 -45
- package/src/shared/mcp/typings/mcp-content-result.model.ts +0 -9
- package/src/shared/mcp/typings/mcp-export-result.model.ts +0 -11
- package/src/shared/mcp/typings/mcp-gc-result.model.ts +0 -15
- package/src/shared/mcp/typings/mcp-integrity-check-result.model.ts +0 -17
- package/src/shared/mcp/typings/mcp-integrity-error.model.ts +0 -15
- package/src/shared/mcp/typings/mcp-notification.interface.ts +0 -9
- package/src/shared/mcp/typings/mcp-rebuild-result.model.ts +0 -9
- package/src/shared/mcp/typings/mcp-request.interface.ts +0 -11
- package/src/shared/mcp/typings/mcp-resource-result.interface.ts +0 -12
- package/src/shared/mcp/typings/mcp-resource-template.interface.ts +0 -11
- package/src/shared/mcp/typings/mcp-response.interface.ts +0 -18
- package/src/shared/mcp/typings/mcp-server-info.interface.ts +0 -7
- package/src/shared/mcp/typings/mcp-server-state.interface.ts +0 -17
- package/src/shared/mcp/typings/mcp-tool-annotations.interface.ts +0 -32
- package/src/shared/mcp/typings/mcp-tool-definition.interface.ts +0 -16
- package/src/shared/mcp/typings/mcp-tool-result.interface.ts +0 -19
- package/src/shared/mcp/typings/mcp-types.interface.ts +0 -158
- package/src/shared/mcp/typings/mcp-worker-client.interface.ts +0 -243
- package/src/shared/mcp/typings/prompt-types.interface.ts +0 -39
- package/src/shared/mcp/typings/remove-section-result.model.ts +0 -10
- package/src/shared/mcp/typings/sampling-types.interface.ts +0 -48
- package/src/shared/mcp/typings/skill-types.interface.ts +0 -29
- package/src/shared/mcp/typings/tool-call-result.model.ts +0 -18
- package/src/shared/mod.ts +0 -1
- package/src/shared/platform/functions/get-ipc-path.function.ts +0 -19
- package/src/shared/platform/functions/get-tmpdir.function.ts +0 -8
- package/src/shared/platform/functions/is-process-alive.function.ts +0 -17
- package/src/shared/platform/index.ts +0 -3
- package/src/shared/runtime/functions/detect-runtime.ts +0 -14
- package/src/shared/runtime/functions/get-args.ts +0 -16
- package/src/shared/runtime/index.ts +0 -3
- package/src/shared/runtime/typings/runtime.ts +0 -2
- package/src/shared/sync/functions/build-import-report.function.ts +0 -40
- package/src/shared/sync/functions/parse-export-entry.function.ts +0 -45
- package/src/shared/sync/functions/resolve-conflict.function.ts +0 -31
- package/src/shared/sync/functions/serialize-export-entry.function.ts +0 -18
- package/src/shared/sync/index.ts +0 -9
- package/src/shared/sync/typings/conflict-resolution.type.ts +0 -8
- package/src/shared/sync/typings/export-entry.interface.ts +0 -13
- package/src/shared/sync/typings/export-options.interface.ts +0 -9
- package/src/shared/sync/typings/import-options.interface.ts +0 -7
- package/src/shared/sync/typings/import-report.interface.ts +0 -15
- package/src/shared/version/constants/version.constant.ts +0 -2
- package/src/shared/version/index.ts +0 -1
- package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +0 -112
- package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +0 -70
- package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +0 -87
- package/src/shared/wasm-codec/functions/decode-f32.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +0 -15
- package/src/shared/wasm-codec/functions/decode-one-recall-result.function.ts +0 -86
- package/src/shared/wasm-codec/functions/decode-option-string.function.ts +0 -24
- package/src/shared/wasm-codec/functions/decode-recall-document.function.ts +0 -59
- package/src/shared/wasm-codec/functions/decode-recall-reference.function.ts +0 -52
- package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +0 -267
- package/src/shared/wasm-codec/functions/decode-recall-sibling.function.ts +0 -43
- package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +0 -3
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +0 -194
- package/src/shared/wasm-codec/functions/decode-section-match.function.ts +0 -80
- package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +0 -20
- package/src/shared/wasm-codec/functions/decode-section-record-trailing.function.ts +0 -75
- package/src/shared/wasm-codec/functions/decode-section-record.function.ts +0 -85
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +0 -249
- package/src/shared/wasm-codec/functions/decode-section-type.function.ts +0 -30
- package/src/shared/wasm-codec/functions/decode-string.function.ts +0 -22
- package/src/shared/wasm-codec/functions/decode-u32.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-u64.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-wasm-list.function.ts +0 -31
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +0 -102
- package/src/shared/wasm-codec/functions/encode-group-params.function.ts +0 -28
- package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +0 -17
- package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +0 -17
- package/src/shared/wasm-codec/functions/encode-option-string.function.ts +0 -14
- package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +0 -68
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +0 -12
- package/src/shared/wasm-codec/functions/encode-section-type.function.ts +0 -18
- package/src/shared/wasm-codec/functions/encode-string.function.ts +0 -9
- package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +0 -13
- package/src/shared/wasm-codec/functions/encode-u32.function.ts +0 -5
- package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +0 -16
- package/src/shared/wasm-codec/index.ts +0 -49
- package/src/shared/wasm-codec/typings/add-section-input.model.ts +0 -45
- package/src/shared/wasm-codec/typings/add-section-result.model.ts +0 -28
- package/src/shared/wasm-codec/typings/document-manifest.model.ts +0 -20
- package/src/shared/wasm-codec/typings/document-section.model.ts +0 -12
- package/src/shared/wasm-codec/typings/item-decoder.type.ts +0 -10
- package/src/shared/wasm-codec/typings/near-duplicate.model.ts +0 -16
- package/src/shared/wasm-codec/typings/paged-search-result.model.ts +0 -22
- package/src/shared/wasm-codec/typings/section-match.model.ts +0 -31
- package/src/shared/wasm-codec/typings/section-record-trailing.model.ts +0 -38
- package/src/shared/wasm-codec/typings/section-record.model.ts +0 -66
- package/src/shared/wasm-codec/typings/section-type-result.model.ts +0 -12
- package/src/shared/worker-client/classes/worker-client.class.ts +0 -466
- package/src/shared/worker-client/functions/compute-context-id.function.ts +0 -18
- package/src/shared/worker-client/functions/create-worker-client.function.ts +0 -70
- package/src/shared/worker-client/functions/discover-daemon.function.ts +0 -47
- package/src/shared/worker-client/functions/handle-ipc-data.function.ts +0 -49
- package/src/shared/worker-client/functions/resolve-db-path.function.ts +0 -21
- package/src/shared/worker-client/functions/send-ipc-request.function.ts +0 -39
- package/src/shared/worker-client/functions/spawn-daemon.function.ts +0 -35
- package/src/shared/worker-client/functions/wait-for-daemon.function.ts +0 -34
- package/src/shared/worker-client/index.ts +0 -44
- package/src/shared/worker-client/typings/add-section-result.model.ts +0 -39
- package/src/shared/worker-client/typings/content-result.model.ts +0 -12
- package/src/shared/worker-client/typings/daemon-info.model.ts +0 -7
- package/src/shared/worker-client/typings/export-result.model.ts +0 -14
- package/src/shared/worker-client/typings/gc-result.model.ts +0 -18
- package/src/shared/worker-client/typings/integrity-check-result.model.ts +0 -43
- package/src/shared/worker-client/typings/json-rpc-response.interface.ts +0 -17
- package/src/shared/worker-client/typings/migrate-result.model.ts +0 -11
- package/src/shared/worker-client/typings/pending-call.interface.ts +0 -7
- package/src/shared/worker-client/typings/rebuild-result.model.ts +0 -12
- package/src/shared/worker-client/typings/recall-document.model.ts +0 -16
- package/src/shared/worker-client/typings/recall-params.model.ts +0 -15
- package/src/shared/worker-client/typings/recall-reference.model.ts +0 -32
- package/src/shared/worker-client/typings/recall-result.model.ts +0 -98
- package/src/shared/worker-client/typings/recall-sibling.model.ts +0 -11
- package/src/shared/worker-client/typings/recall-single-result.model.ts +0 -41
- package/src/shared/worker-client/typings/remove-section-result.model.ts +0 -7
- package/src/shared/worker-client/typings/search-params.model.ts +0 -14
- package/src/shared/worker-client/typings/search-result.model.ts +0 -43
- package/src/shared/worker-client/typings/section.model.ts +0 -43
- package/src/shared/worker-client/typings/status-result.model.ts +0 -14
- package/src/shared/worker-client/typings/version-status.model.ts +0 -28
- package/src/shared/worker-client/typings/worker-client-error.interface.ts +0 -8
- package/src/shared/worker-client/typings/worker-client-options.interface.ts +0 -30
- package/src/shared/worker-daemon/classes/ipc-error.class.ts +0 -22
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +0 -1291
- package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +0 -29
- package/src/shared/worker-daemon/constants/wasm-method-map.constant.ts +0 -69
- package/src/shared/worker-daemon/functions/build-ipc-error-response.function.ts +0 -16
- package/src/shared/worker-daemon/functions/check-catalog-version.function.ts +0 -54
- package/src/shared/worker-daemon/functions/check-preconditions.function.ts +0 -28
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +0 -328
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +0 -87
- package/src/shared/worker-daemon/functions/detect-stale-pid.function.ts +0 -33
- package/src/shared/worker-daemon/functions/dispatch-request.function.ts +0 -190
- package/src/shared/worker-daemon/functions/handle-check-version.function.ts +0 -74
- package/src/shared/worker-daemon/functions/handle-config-method.function.ts +0 -27
- package/src/shared/worker-daemon/functions/handle-read-ops.function.ts +0 -236
- package/src/shared/worker-daemon/functions/handle-write-ops.function.ts +0 -257
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +0 -95
- package/src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts +0 -51
- package/src/shared/worker-daemon/functions/parse-catalog-version.function.ts +0 -20
- package/src/shared/worker-daemon/functions/parse-embedding-section.function.ts +0 -38
- package/src/shared/worker-daemon/functions/parse-worker-toml.function.ts +0 -104
- package/src/shared/worker-daemon/functions/read-config.function.ts +0 -83
- package/src/shared/worker-daemon/functions/run-startup-integrity-check.function.ts +0 -55
- package/src/shared/worker-daemon/functions/run-worker.function.ts +0 -57
- package/src/shared/worker-daemon/functions/scan-near-duplicates.function.ts +0 -92
- package/src/shared/worker-daemon/functions/start-daemon.function.ts +0 -74
- package/src/shared/worker-daemon/functions/wasm-bridge.function.ts +0 -144
- package/src/shared/worker-daemon/functions/wasm-memory-helpers.function.ts +0 -41
- package/src/shared/worker-daemon/functions/write-lock.function.ts +0 -49
- package/src/shared/worker-daemon/index.ts +0 -16
- package/src/shared/worker-daemon/typings/allocator-ref.interface.ts +0 -16
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +0 -20
- package/src/shared/worker-daemon/typings/fs-adapter.interface.ts +0 -22
- package/src/shared/worker-daemon/typings/handler-context.interface.ts +0 -19
- package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +0 -39
- package/src/shared/worker-daemon/typings/memory-ref.interface.ts +0 -13
- package/src/shared/worker-daemon/typings/wasm-fn.type.ts +0 -2
- package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +0 -7
- package/src/shared/worker-daemon/typings/write-lock.interface.ts +0 -13
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +0 -259
- package/src/wasm/fs-database/kbdb_fs_database.js +0 -515
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +0 -35
- package/src/wasm/fs-database/package.json +0 -13
- package/src/wasm/kb-worker/kbdb_worker.d.ts +0 -650
- package/src/wasm/kb-worker/kbdb_worker.js +0 -1181
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +0 -77
- package/src/wasm/kb-worker/package.json +0 -13
- package/src/wasm/query-parser/kbdb_query_parser.d.ts +0 -195
- package/src/wasm/query-parser/kbdb_query_parser.js +0 -403
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm.d.ts +0 -25
- package/src/wasm/query-parser/package.json +0 -13
- package/src/worker.ts +0 -42
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AgentGetClient,
|
|
3
|
-
AgentDocumentSection,
|
|
4
|
-
AgentSectionRecord,
|
|
5
|
-
} from '../typings/agent-get-client.interface.ts';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Resolves skill names by reading each skill section's JSON content.
|
|
9
|
-
*
|
|
10
|
-
* Returns `null` for any reference whose section no longer exists
|
|
11
|
-
* (dangling reference) or whose content cannot be parsed.
|
|
12
|
-
*
|
|
13
|
-
* @param client - client used to fetch section records
|
|
14
|
-
* @param skillRefs - ordered section references to resolve
|
|
15
|
-
* @returns list of resolved skill entries with name and position
|
|
16
|
-
*/
|
|
17
|
-
export async function resolveSkillNames(
|
|
18
|
-
client: AgentGetClient,
|
|
19
|
-
skillRefs: AgentDocumentSection[],
|
|
20
|
-
): Promise<{ kbid: string; name: string | null; position: number }[]> {
|
|
21
|
-
if (skillRefs.length === 0) return [];
|
|
22
|
-
const kbids = skillRefs.map((r) => r.kbid);
|
|
23
|
-
const sections: AgentSectionRecord[] =
|
|
24
|
-
await client.readSections(kbids);
|
|
25
|
-
const sectionMap = new Map(sections.map((s) => [s.kbid, s]));
|
|
26
|
-
return skillRefs.map((ref) => {
|
|
27
|
-
const sec = sectionMap.get(ref.kbid);
|
|
28
|
-
if (!sec) {
|
|
29
|
-
return { kbid: ref.kbid, name: null, position: ref.position };
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
const parsed = JSON.parse(sec.content) as Record<
|
|
33
|
-
string,
|
|
34
|
-
unknown
|
|
35
|
-
>;
|
|
36
|
-
const name =
|
|
37
|
-
typeof parsed['name'] === 'string' ? parsed['name'] : null;
|
|
38
|
-
return { kbid: ref.kbid, name, position: ref.position };
|
|
39
|
-
} catch {
|
|
40
|
-
return { kbid: ref.kbid, name: null, position: ref.position };
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
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
|
-
* A single entry in the divergent-content map.
|
|
30
|
-
* Groups kbids under a common source key.
|
|
31
|
-
*/
|
|
32
|
-
interface DivergentContentEntry {
|
|
33
|
-
/** Source key that has multiple divergent content versions. */
|
|
34
|
-
readonly sourceKey: string;
|
|
35
|
-
/** Kbids of sections sharing this source key but with different content. */
|
|
36
|
-
readonly kbids: string[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Integrity check report returned by the daemon.
|
|
41
|
-
*/
|
|
42
|
-
interface IntegrityCheckResult {
|
|
43
|
-
/** `true` when all checks passed and no errors were found. */
|
|
44
|
-
readonly ok: boolean;
|
|
45
|
-
/** All integrity errors found; empty when `ok` is `true`. */
|
|
46
|
-
readonly errors: IntegrityError[];
|
|
47
|
-
/** Total number of sections examined. */
|
|
48
|
-
readonly sections_checked: number;
|
|
49
|
-
/** Total number of documents examined. */
|
|
50
|
-
readonly documents_checked: number;
|
|
51
|
-
/** Total number of marker references checked. */
|
|
52
|
-
readonly references_checked: number;
|
|
53
|
-
/** Time taken to complete the check, in milliseconds. */
|
|
54
|
-
readonly elapsed_ms: number;
|
|
55
|
-
/**
|
|
56
|
-
* Sections that share a source key but have divergent content.
|
|
57
|
-
* Each entry groups the kbids under a common source key.
|
|
58
|
-
* Empty when no divergent content is found.
|
|
59
|
-
*/
|
|
60
|
-
readonly divergent_content: DivergentContentEntry[];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Raw daemon response from `integrityCheck`. */
|
|
64
|
-
interface RawIntegrityCheckResult {
|
|
65
|
-
/** `true` when all checks passed and no errors were found. */
|
|
66
|
-
readonly ok: boolean;
|
|
67
|
-
/** All integrity errors found; empty when `ok` is `true`. */
|
|
68
|
-
readonly errors: IntegrityError[];
|
|
69
|
-
/** Total number of sections examined. */
|
|
70
|
-
readonly sections_checked: number;
|
|
71
|
-
/** Total number of documents examined. */
|
|
72
|
-
readonly documents_checked: number;
|
|
73
|
-
/** Total number of marker references checked. */
|
|
74
|
-
readonly references_checked: number;
|
|
75
|
-
/** Time taken to complete the check, in milliseconds. */
|
|
76
|
-
readonly elapsed_ms: number;
|
|
77
|
-
/**
|
|
78
|
-
* Encoded divergent-content map.
|
|
79
|
-
*
|
|
80
|
-
* Format: `sk1:kbid1,kbid2;sk2:kbid3,kbid4`
|
|
81
|
-
*
|
|
82
|
-
* Each semicolon-separated segment is a source key followed by
|
|
83
|
-
* a colon and a comma-separated list of kbids. Absent when no
|
|
84
|
-
* divergent content exists.
|
|
85
|
-
*/
|
|
86
|
-
readonly divergent_content?: string;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Minimal client interface required by `runCheck`.
|
|
91
|
-
*
|
|
92
|
-
* Decouples the CLI function from the concrete `WorkerClient`
|
|
93
|
-
* implementation, making it straightforward to test with mocks.
|
|
94
|
-
*/
|
|
95
|
-
export interface CheckClient {
|
|
96
|
-
/**
|
|
97
|
-
* Runs an integrity check on the knowledge-base database.
|
|
98
|
-
*
|
|
99
|
-
* @returns a report of all issues found; `ok` is `true` when
|
|
100
|
-
* no errors were detected
|
|
101
|
-
*/
|
|
102
|
-
integrityCheck(): Promise<RawIntegrityCheckResult>;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Parses the encoded `divergent_content` string from the daemon
|
|
107
|
-
* into a structured array.
|
|
108
|
-
*
|
|
109
|
-
* Input format: `sk1:kbid1,kbid2;sk2:kbid3,kbid4`
|
|
110
|
-
*
|
|
111
|
-
* @param encoded - raw encoded string, or empty / absent
|
|
112
|
-
* @returns structured entries grouped by source key
|
|
113
|
-
*/
|
|
114
|
-
function parseDivergentContent(
|
|
115
|
-
encoded: string | undefined,
|
|
116
|
-
): DivergentContentEntry[] {
|
|
117
|
-
if (!encoded) return [];
|
|
118
|
-
return encoded
|
|
119
|
-
.split(';')
|
|
120
|
-
.filter((segment) => segment.includes(':'))
|
|
121
|
-
.map((segment) => {
|
|
122
|
-
const colonIdx = segment.indexOf(':');
|
|
123
|
-
const sourceKey = segment.slice(0, colonIdx);
|
|
124
|
-
const kbids = segment
|
|
125
|
-
.slice(colonIdx + 1)
|
|
126
|
-
.split(',')
|
|
127
|
-
.filter((k) => k.length > 0);
|
|
128
|
-
return { sourceKey, kbids };
|
|
129
|
-
})
|
|
130
|
-
.filter((entry) => entry.kbids.length > 0);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Runs an integrity check on the database and returns the report.
|
|
135
|
-
*
|
|
136
|
-
* Delegates to `client.integrityCheck()`, then parses the encoded
|
|
137
|
-
* `divergent_content` field into structured form. The caller is
|
|
138
|
-
* responsible for printing the result to stdout and setting the
|
|
139
|
-
* process exit code based on `result.ok`.
|
|
140
|
-
*
|
|
141
|
-
* @param client - check client to delegate to
|
|
142
|
-
* @param _options - parsed CLI options (unused; reserved for future flags)
|
|
143
|
-
* @returns the integrity check report with parsed `divergent_content`
|
|
144
|
-
*/
|
|
145
|
-
export async function runCheck(
|
|
146
|
-
client: CheckClient,
|
|
147
|
-
_options: CliOptions,
|
|
148
|
-
): Promise<IntegrityCheckResult> {
|
|
149
|
-
const raw = await client.integrityCheck();
|
|
150
|
-
return {
|
|
151
|
-
ok: raw.ok,
|
|
152
|
-
errors: raw.errors,
|
|
153
|
-
sections_checked: raw.sections_checked,
|
|
154
|
-
documents_checked: raw.documents_checked,
|
|
155
|
-
references_checked: raw.references_checked,
|
|
156
|
-
elapsed_ms: raw.elapsed_ms,
|
|
157
|
-
divergent_content: parseDivergentContent(raw.divergent_content),
|
|
158
|
-
};
|
|
159
|
-
}
|