@dikolab/kbdb 0.2.2 → 0.3.1
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 +47 -31
- package/dist/bench/constants/corpus-defaults.constant.d.ts +3 -0
- package/dist/bench/functions/format-report.function.d.ts +11 -0
- package/dist/bench/functions/generate-corpus.function.d.ts +12 -0
- package/dist/bench/functions/measure-operation.function.d.ts +14 -0
- package/dist/bench/functions/seeded-rng.function.d.ts +11 -0
- package/dist/bench/functions/zipf-word.function.d.ts +13 -0
- package/dist/bench/index.d.ts +10 -0
- package/dist/bench/typings/bench-result.interface.d.ts +11 -0
- package/dist/bench/typings/bench-suite-result.interface.d.ts +10 -0
- package/dist/bench/typings/corpus-config.interface.d.ts +11 -0
- package/dist/bench/typings/corpus-section.interface.d.ts +9 -0
- package/dist/cli.cjs +523 -80
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.mjs +515 -72
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +395 -60
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +17 -0
- package/dist/mod.cjs.map +2 -2
- package/dist/mod.mjs +17 -0
- package/dist/mod.mjs.map +2 -2
- package/dist/src/shared/auto-capture/classes/auto-capture-controller.class.d.ts +33 -0
- package/dist/src/shared/auto-capture/constants/auto-capture-defaults.constant.d.ts +8 -0
- package/dist/src/shared/auto-capture/functions/build-capture-prompt.function.d.ts +11 -0
- package/dist/src/shared/auto-capture/functions/evaluate-trigger.function.d.ts +12 -0
- package/dist/src/shared/auto-capture/index.d.ts +7 -0
- package/dist/src/shared/auto-capture/typings/auto-capture-config.interface.d.ts +13 -0
- package/dist/src/shared/auto-capture/typings/auto-capture-state.interface.d.ts +13 -0
- package/dist/src/shared/auto-capture/typings/auto-capture-trigger.interface.d.ts +7 -0
- package/dist/src/shared/cli/constants/global-help.constant.d.ts +8 -0
- package/dist/src/shared/cli/constants/leaf-help.constant.d.ts +7 -0
- package/dist/src/shared/cli/constants/memory-protocol-body.constant.d.ts +7 -0
- package/dist/src/shared/cli/constants/query-guidance-body.constant.d.ts +7 -0
- package/dist/src/shared/cli/constants/subcommand-help.constant.d.ts +8 -0
- package/dist/src/shared/cli/functions/collect-files.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/compute-section-kbid.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +3 -1
- package/dist/src/shared/cli/functions/format-mcp-output.function.d.ts +9 -0
- package/dist/src/shared/cli/functions/format-text-output.function.d.ts +9 -0
- package/dist/src/shared/cli/functions/generate-group-help.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/handle-data-command.function.d.ts +16 -0
- package/dist/src/shared/cli/functions/handle-mcp.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/handle-migrate.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/hydrate-search-previews.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/install-default-skills.function.d.ts +12 -0
- package/dist/src/shared/cli/functions/resolve-skill-names.function.d.ts +16 -0
- package/dist/src/shared/cli/functions/run-check.function.d.ts +47 -5
- package/dist/src/shared/cli/functions/run-export.function.d.ts +34 -0
- package/dist/src/shared/cli/functions/run-gc.function.d.ts +6 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +35 -6
- package/dist/src/shared/cli/functions/run-recall.function.d.ts +45 -0
- package/dist/src/shared/cli/functions/run-search.function.d.ts +53 -15
- package/dist/src/shared/cli/functions/version-gate.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/wrap-command.function.d.ts +15 -0
- package/dist/src/shared/cli/index.d.ts +4 -0
- package/dist/src/shared/cli/typings/agent-create-client.interface.d.ts +42 -0
- package/dist/src/shared/cli/typings/agent-get-client.interface.d.ts +36 -0
- package/dist/src/shared/cli/typings/check-client.interface.d.ts +58 -0
- package/dist/src/shared/cli/typings/cli-deps.interface.d.ts +48 -0
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +15 -0
- package/dist/src/shared/cli/typings/disconnectable-client.interface.d.ts +26 -0
- package/dist/src/shared/cli/typings/dispatch-client.type.d.ts +27 -0
- package/dist/src/shared/cli/typings/learn-client.interface.d.ts +52 -0
- package/dist/src/shared/cli/typings/learn-io.interface.d.ts +5 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +19 -0
- package/dist/src/shared/cli/typings/search-client.interface.d.ts +71 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +18 -0
- package/dist/src/shared/embedding/classes/null-embedding-provider.class.d.ts +20 -0
- package/dist/src/shared/embedding/constants/near-duplicate-thresholds.constant.d.ts +15 -0
- package/dist/src/shared/embedding/functions/build-vector-index.function.d.ts +14 -0
- package/dist/src/shared/embedding/functions/cosine-similarity.function.d.ts +10 -0
- package/dist/src/shared/embedding/functions/detect-near-duplicates.function.d.ts +18 -0
- package/dist/src/shared/embedding/functions/jaccard-coefficient.function.d.ts +9 -0
- package/dist/src/shared/embedding/functions/read-vector-index-meta.function.d.ts +10 -0
- package/dist/src/shared/embedding/functions/rrf-fuse.function.d.ts +14 -0
- package/dist/src/shared/embedding/functions/search-vectors.function.d.ts +14 -0
- package/dist/src/shared/embedding/index.d.ts +16 -0
- package/dist/src/shared/embedding/typings/embedding-config.interface.d.ts +20 -0
- package/dist/src/shared/embedding/typings/embedding-provider.interface.d.ts +23 -0
- package/dist/src/shared/embedding/typings/near-duplicate-candidate.model.d.ts +23 -0
- package/dist/src/shared/embedding/typings/near-duplicate-result.model.d.ts +24 -0
- package/dist/src/shared/embedding/typings/vector-index-entry.model.d.ts +12 -0
- package/dist/src/shared/embedding/typings/vector-index-meta.model.d.ts +11 -0
- package/dist/src/shared/embedding/typings/vector-search-result.model.d.ts +7 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +8 -0
- package/dist/src/shared/mcp/constants/tool-agent-create.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-agent-delete.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-agent-get.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-agent-list.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-auto-capture-review.constant.d.ts +8 -0
- package/dist/src/shared/mcp/constants/tool-check.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-content.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-export.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-gc.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-learn.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-rebuild.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-recall.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-retrieve.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-search.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-delete.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-get.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-learn.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-list.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-status.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-unlearn.constant.d.ts +3 -0
- package/dist/src/shared/mcp/functions/as-boolean-or-undefined.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/as-string-array-or-undefined.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/as-string-array.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/as-string.function.d.ts +8 -0
- package/dist/src/shared/mcp/functions/build-skills-text.function.d.ts +18 -0
- package/dist/src/shared/mcp/functions/handle-agent-prompt.function.d.ts +14 -0
- package/dist/src/shared/mcp/functions/handle-mcp-request.function.d.ts +14 -0
- package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +4 -3
- package/dist/src/shared/mcp/functions/handle-skill-prompt.function.d.ts +16 -0
- package/dist/src/shared/mcp/functions/handle-tool-auto-capture-review.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-check.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-content.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-export.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-gc.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-learn.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-rebuild.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-retrieve.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-search.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-delete.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-get.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-learn.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-list.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-status.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-unlearn.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/parse-agent-meta.function.d.ts +14 -0
- package/dist/src/shared/mcp/functions/parse-skill-arguments.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/read-agent-meta.function.d.ts +17 -0
- package/dist/src/shared/mcp/functions/resolve-skill-refs.function.d.ts +23 -0
- package/dist/src/shared/mcp/functions/run-startup-health-check.function.d.ts +14 -0
- package/dist/src/shared/mcp/typings/mcp-capabilities.interface.d.ts +16 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +45 -0
- package/dist/src/shared/mcp/typings/mcp-completion.interface.d.ts +43 -0
- package/dist/src/shared/mcp/typings/mcp-content-result.model.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-export-result.model.d.ts +11 -0
- package/dist/src/shared/mcp/typings/mcp-gc-result.model.d.ts +15 -0
- package/dist/src/shared/mcp/typings/mcp-integrity-check-result.model.d.ts +16 -0
- package/dist/src/shared/mcp/typings/mcp-integrity-error.model.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-notification.interface.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-rebuild-result.model.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-request.interface.d.ts +11 -0
- package/dist/src/shared/mcp/typings/mcp-resource-result.interface.d.ts +12 -0
- package/dist/src/shared/mcp/typings/mcp-resource-template.interface.d.ts +11 -0
- package/dist/src/shared/mcp/typings/mcp-response.interface.d.ts +18 -0
- package/dist/src/shared/mcp/typings/mcp-server-info.interface.d.ts +7 -0
- package/dist/src/shared/mcp/typings/mcp-server-state.interface.d.ts +16 -0
- package/dist/src/shared/mcp/typings/mcp-tool-annotations.interface.d.ts +32 -0
- package/dist/src/shared/mcp/typings/mcp-tool-definition.interface.d.ts +15 -0
- package/dist/src/shared/mcp/typings/mcp-tool-result.interface.d.ts +19 -0
- package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +220 -0
- package/dist/src/shared/mcp/typings/tool-call-result.model.d.ts +17 -0
- package/dist/src/shared/sync/functions/build-import-report.function.d.ts +18 -0
- package/dist/src/shared/sync/functions/parse-export-entry.function.d.ts +11 -0
- package/dist/src/shared/sync/functions/resolve-conflict.function.d.ts +13 -0
- package/dist/src/shared/sync/functions/serialize-export-entry.function.d.ts +8 -0
- package/dist/src/shared/sync/index.d.ts +9 -0
- package/dist/src/shared/sync/typings/conflict-resolution.type.d.ts +8 -0
- package/dist/src/shared/sync/typings/export-entry.interface.d.ts +13 -0
- package/dist/src/shared/sync/typings/export-options.interface.d.ts +9 -0
- package/dist/src/shared/sync/typings/import-options.interface.d.ts +7 -0
- package/dist/src/shared/sync/typings/import-report.interface.d.ts +15 -0
- package/dist/src/shared/wasm-codec/functions/decode-add-section-result.function.d.ts +48 -0
- package/dist/src/shared/wasm-codec/functions/decode-one-recall-result.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-option-string.function.d.ts +12 -0
- package/dist/src/shared/wasm-codec/functions/decode-recall-document.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-recall-reference.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-recall-sibling.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +58 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-match.function.d.ts +15 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record-trailing.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +33 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-type.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-wasm-list.function.d.ts +17 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +52 -0
- package/dist/src/shared/wasm-codec/index.d.ts +2 -0
- package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +45 -0
- package/dist/src/shared/wasm-codec/typings/add-section-result.model.d.ts +27 -0
- package/dist/src/shared/wasm-codec/typings/document-manifest.model.d.ts +19 -0
- package/dist/src/shared/wasm-codec/typings/document-section.model.d.ts +12 -0
- package/dist/src/shared/wasm-codec/typings/item-decoder.type.d.ts +6 -0
- package/dist/src/shared/wasm-codec/typings/near-duplicate.model.d.ts +16 -0
- package/dist/src/shared/wasm-codec/typings/paged-search-result.model.d.ts +21 -0
- package/dist/src/shared/wasm-codec/typings/section-match.model.d.ts +31 -0
- package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +38 -0
- package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +66 -0
- package/dist/src/shared/wasm-codec/typings/section-type-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +16 -0
- package/dist/src/shared/worker-client/functions/handle-ipc-data.function.d.ts +16 -0
- package/dist/src/shared/worker-client/functions/send-ipc-request.function.d.ts +19 -0
- package/dist/src/shared/worker-client/index.d.ts +1 -1
- package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +31 -15
- package/dist/src/shared/worker-client/typings/export-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +6 -0
- package/dist/src/shared/worker-client/typings/json-rpc-response.interface.d.ts +16 -0
- package/dist/src/shared/worker-client/typings/pending-call.interface.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/recall-document.model.d.ts +16 -0
- package/dist/src/shared/worker-client/typings/recall-params.model.d.ts +15 -0
- package/dist/src/shared/worker-client/typings/recall-reference.model.d.ts +32 -0
- package/dist/src/shared/worker-client/typings/recall-sibling.model.d.ts +11 -0
- package/dist/src/shared/worker-client/typings/recall-single-result.model.d.ts +40 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +16 -0
- package/dist/src/shared/worker-daemon/classes/ipc-error.class.d.ts +17 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +35 -0
- package/dist/src/shared/worker-daemon/constants/wasm-method-map.constant.d.ts +16 -0
- package/dist/src/shared/worker-daemon/functions/build-ipc-error-response.function.d.ts +9 -0
- package/dist/src/shared/worker-daemon/functions/check-catalog-version.function.d.ts +9 -0
- package/dist/src/shared/worker-daemon/functions/check-preconditions.function.d.ts +10 -0
- package/dist/src/shared/worker-daemon/functions/detect-stale-pid.function.d.ts +15 -0
- package/dist/src/shared/worker-daemon/functions/dispatch-request.function.d.ts +35 -0
- package/dist/src/shared/worker-daemon/functions/handle-check-version.function.d.ts +23 -0
- package/dist/src/shared/worker-daemon/functions/handle-config-method.function.d.ts +11 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +52 -0
- package/dist/src/shared/worker-daemon/functions/handle-write-ops.function.d.ts +44 -0
- package/dist/src/shared/worker-daemon/functions/parse-auto-capture-section.function.d.ts +14 -0
- package/dist/src/shared/worker-daemon/functions/parse-catalog-version.function.d.ts +10 -0
- package/dist/src/shared/worker-daemon/functions/parse-embedding-section.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/functions/parse-worker-toml.function.d.ts +11 -0
- package/dist/src/shared/worker-daemon/functions/run-startup-integrity-check.function.d.ts +18 -0
- package/dist/src/shared/worker-daemon/functions/scan-near-duplicates.function.d.ts +21 -0
- package/dist/src/shared/worker-daemon/functions/wasm-bridge.function.d.ts +51 -0
- package/dist/src/shared/worker-daemon/functions/wasm-memory-helpers.function.d.ts +22 -0
- package/dist/src/shared/worker-daemon/functions/write-lock.function.d.ts +32 -0
- package/dist/src/shared/worker-daemon/typings/allocator-ref.interface.d.ts +16 -0
- package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +6 -0
- package/dist/src/shared/worker-daemon/typings/fs-adapter.interface.d.ts +22 -0
- package/dist/src/shared/worker-daemon/typings/handler-context.interface.d.ts +18 -0
- package/dist/src/shared/worker-daemon/typings/memory-ref.interface.d.ts +13 -0
- package/dist/src/shared/worker-daemon/typings/wasm-fn.type.d.ts +2 -0
- package/dist/src/shared/worker-daemon/typings/write-lock.interface.d.ts +15 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
- package/dist/wasm/fs-database/kbdb_fs_database.js +28 -1
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +48 -1
- package/dist/wasm/kb-worker/kbdb_worker.js +60 -1
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.mjs +396 -60
- package/dist/worker.mjs.map +4 -4
- package/docs/details/cli.md +102 -15
- package/docs/details/library-api.md +55 -6
- package/docs/details/mcp-server.md +10 -4
- package/docs/details/search-and-ranking.md +63 -5
- package/docs/details/storage.md +2 -0
- package/docs/goals/auto-capture.md +378 -0
- package/docs/goals/benchmarking.md +296 -0
- package/docs/goals/cli.md +255 -14
- package/docs/goals/concurrency.md +259 -0
- package/docs/goals/database.md +244 -17
- package/docs/goals/document.md +1 -1
- package/docs/goals/hybrid-search.md +436 -0
- package/docs/goals/mcp.md +83 -14
- package/docs/goals/query-parser.md +98 -4
- package/docs/goals/query-result.md +177 -10
- package/docs/goals/semantic-dedup.md +229 -0
- package/docs/goals/skills.md +72 -0
- package/docs/goals/sync.md +217 -0
- package/docs/goals/worker-daemon.md +54 -7
- package/docs/modules/rust/fs-database/functions/integrity.md +11 -0
- package/docs/modules/rust/fs-database/functions/section.md +23 -6
- package/docs/modules/rust/fs-database/indexes/vectors.md +110 -0
- package/docs/modules/rust/fs-database/module.md +1 -0
- package/docs/modules/rust/fs-database/types/section.md +27 -1
- package/docs/modules/rust/overview.md +2 -1
- package/docs/modules/rust/query-parser/functions/module.md +2 -2
- package/docs/modules/rust/query-parser/functions/pipeline.md +44 -6
- package/docs/modules/rust/query-parser/module.md +5 -4
- package/docs/modules/rust/query-parser/types/keyphrase.md +11 -0
- package/docs/modules/rust/query-parser/types/module.md +3 -3
- package/docs/modules/typescript/shared/auto-capture/module.md +73 -0
- package/docs/modules/typescript/shared/cli/functions.md +68 -3
- package/docs/modules/typescript/shared/embedding/functions.md +94 -0
- package/docs/modules/typescript/shared/embedding/module.md +71 -0
- package/docs/modules/typescript/shared/embedding/typings.md +122 -0
- package/docs/overview.md +148 -166
- package/docs/release-notes/0.2.0.md +3 -3
- package/docs/release-notes/0.3.0.md +89 -0
- package/docs/release-notes/0.3.1.md +111 -0
- package/docs/release-notes/README.md +2 -0
- package/package.json +1 -1
- package/src/shared/auto-capture/classes/auto-capture-controller.class.ts +62 -0
- package/src/shared/auto-capture/constants/auto-capture-defaults.constant.ts +15 -0
- package/src/shared/auto-capture/functions/build-capture-prompt.function.ts +27 -0
- package/src/shared/auto-capture/functions/evaluate-trigger.function.ts +50 -0
- package/src/shared/auto-capture/index.ts +7 -0
- package/src/shared/auto-capture/typings/auto-capture-config.interface.ts +13 -0
- package/src/shared/auto-capture/typings/auto-capture-state.interface.ts +13 -0
- package/src/shared/auto-capture/typings/auto-capture-trigger.interface.ts +7 -0
- package/src/shared/cli/constants/global-help.constant.ts +73 -0
- package/src/shared/cli/constants/leaf-help.constant.ts +219 -0
- package/src/shared/cli/constants/memory-protocol-body.constant.ts +39 -0
- package/src/shared/cli/constants/query-guidance-body.constant.ts +37 -0
- package/src/shared/cli/constants/subcommand-help.constant.ts +195 -0
- package/src/shared/cli/functions/collect-files.function.ts +55 -0
- package/src/shared/cli/functions/compute-section-kbid.function.ts +49 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +53 -1
- package/src/shared/cli/functions/format-mcp-output.function.ts +41 -0
- package/src/shared/cli/functions/format-output.function.ts +36 -12
- package/src/shared/cli/functions/format-text-output.function.ts +42 -0
- package/src/shared/cli/functions/generate-group-help.function.ts +41 -0
- package/src/shared/cli/functions/generate-help.function.ts +56 -1
- package/src/shared/cli/functions/handle-data-command.function.ts +67 -0
- package/src/shared/cli/functions/handle-mcp.function.ts +56 -0
- package/src/shared/cli/functions/handle-migrate.function.ts +64 -0
- package/src/shared/cli/functions/hydrate-search-previews.function.ts +29 -0
- package/src/shared/cli/functions/install-default-skills.function.ts +296 -0
- package/src/shared/cli/functions/parse-args.function.ts +16 -0
- package/src/shared/cli/functions/resolve-skill-names.function.ts +43 -0
- package/src/shared/cli/functions/run-check.function.ts +87 -6
- package/src/shared/cli/functions/run-export.function.ts +40 -0
- package/src/shared/cli/functions/run-gc.function.ts +6 -0
- package/src/shared/cli/functions/run-init.function.ts +2 -0
- package/src/shared/cli/functions/run-learn.function.ts +68 -16
- package/src/shared/cli/functions/run-recall.function.ts +66 -0
- package/src/shared/cli/functions/run-search.function.ts +60 -15
- package/src/shared/cli/functions/version-gate.function.ts +44 -0
- package/src/shared/cli/functions/wrap-command.function.ts +34 -0
- package/src/shared/cli/index.ts +4 -0
- package/src/shared/cli/typings/agent-create-client.interface.ts +47 -0
- package/src/shared/cli/typings/agent-get-client.interface.ts +39 -0
- package/src/shared/cli/typings/check-client.interface.ts +66 -0
- package/src/shared/cli/typings/cli-deps.interface.ts +54 -0
- package/src/shared/cli/typings/cli-options.interface.ts +15 -0
- package/src/shared/cli/typings/disconnectable-client.interface.ts +29 -0
- package/src/shared/cli/typings/dispatch-client.type.ts +46 -0
- package/src/shared/cli/typings/learn-client.interface.ts +53 -0
- package/src/shared/cli/typings/learn-io.interface.ts +5 -0
- package/src/shared/cli/typings/learn-result.model.ts +16 -0
- package/src/shared/cli/typings/search-client.interface.ts +73 -0
- package/src/shared/cli/typings/search-display.model.ts +18 -0
- package/src/shared/embedding/classes/null-embedding-provider.class.ts +29 -0
- package/src/shared/embedding/constants/near-duplicate-thresholds.constant.ts +17 -0
- package/src/shared/embedding/functions/build-vector-index.function.ts +79 -0
- package/src/shared/embedding/functions/cosine-similarity.function.ts +31 -0
- package/src/shared/embedding/functions/detect-near-duplicates.function.ts +69 -0
- package/src/shared/embedding/functions/jaccard-coefficient.function.ts +26 -0
- package/src/shared/embedding/functions/read-vector-index-meta.function.ts +44 -0
- package/src/shared/embedding/functions/rrf-fuse.function.ts +33 -0
- package/src/shared/embedding/functions/search-vectors.function.ts +59 -0
- package/src/shared/embedding/index.ts +20 -0
- package/src/shared/embedding/typings/embedding-config.interface.ts +23 -0
- package/src/shared/embedding/typings/embedding-provider.interface.ts +25 -0
- package/src/shared/embedding/typings/near-duplicate-candidate.model.ts +25 -0
- package/src/shared/embedding/typings/near-duplicate-result.model.ts +26 -0
- package/src/shared/embedding/typings/vector-index-entry.model.ts +13 -0
- package/src/shared/embedding/typings/vector-index-meta.model.ts +14 -0
- package/src/shared/embedding/typings/vector-search-result.model.ts +8 -0
- package/src/shared/mcp/classes/mcp-server.class.ts +36 -4
- package/src/shared/mcp/constants/tool-agent-create.constant.ts +39 -0
- package/src/shared/mcp/constants/tool-agent-delete.constant.ts +26 -0
- package/src/shared/mcp/constants/tool-agent-get.constant.ts +24 -0
- package/src/shared/mcp/constants/tool-agent-list.constant.ts +18 -0
- package/src/shared/mcp/constants/tool-auto-capture-review.constant.ts +32 -0
- package/src/shared/mcp/constants/tool-check.constant.ts +21 -0
- package/src/shared/mcp/constants/tool-content.constant.ts +29 -0
- package/src/shared/mcp/constants/tool-export.constant.ts +27 -0
- package/src/shared/mcp/constants/tool-gc.constant.ts +21 -0
- package/src/shared/mcp/constants/tool-learn.constant.ts +58 -0
- package/src/shared/mcp/constants/tool-rebuild.constant.ts +21 -0
- package/src/shared/mcp/constants/tool-recall.constant.ts +36 -0
- package/src/shared/mcp/constants/tool-retrieve.constant.ts +31 -0
- package/src/shared/mcp/constants/tool-search.constant.ts +51 -0
- package/src/shared/mcp/constants/tool-skill-delete.constant.ts +24 -0
- package/src/shared/mcp/constants/tool-skill-get.constant.ts +27 -0
- package/src/shared/mcp/constants/tool-skill-learn.constant.ts +37 -0
- package/src/shared/mcp/constants/tool-skill-list.constant.ts +18 -0
- package/src/shared/mcp/constants/tool-status.constant.ts +20 -0
- package/src/shared/mcp/constants/tool-unlearn.constant.ts +25 -0
- package/src/shared/mcp/functions/as-boolean-or-undefined.function.ts +11 -0
- package/src/shared/mcp/functions/as-string-array-or-undefined.function.ts +17 -0
- package/src/shared/mcp/functions/as-string-array.function.ts +15 -0
- package/src/shared/mcp/functions/as-string.function.ts +10 -0
- package/src/shared/mcp/functions/build-skills-text.function.ts +43 -0
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +74 -5
- package/src/shared/mcp/functions/handle-agent-create.function.ts +1 -1
- package/src/shared/mcp/functions/handle-agent-prompt.function.ts +68 -0
- package/src/shared/mcp/functions/handle-mcp-request.function.ts +202 -0
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +18 -12
- package/src/shared/mcp/functions/handle-skill-prompt.function.ts +44 -0
- package/src/shared/mcp/functions/handle-tool-auto-capture-review.function.ts +24 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +88 -2
- package/src/shared/mcp/functions/handle-tool-check.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-content.function.ts +23 -0
- package/src/shared/mcp/functions/handle-tool-export.function.ts +25 -0
- package/src/shared/mcp/functions/handle-tool-gc.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-learn.function.ts +69 -0
- package/src/shared/mcp/functions/handle-tool-rebuild.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-retrieve.function.ts +40 -0
- package/src/shared/mcp/functions/handle-tool-search.function.ts +47 -0
- package/src/shared/mcp/functions/handle-tool-skill-delete.function.ts +34 -0
- package/src/shared/mcp/functions/handle-tool-skill-get.function.ts +59 -0
- package/src/shared/mcp/functions/handle-tool-skill-learn.function.ts +61 -0
- package/src/shared/mcp/functions/handle-tool-skill-list.function.ts +39 -0
- package/src/shared/mcp/functions/handle-tool-status.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-unlearn.function.ts +24 -0
- package/src/shared/mcp/functions/parse-agent-meta.function.ts +27 -0
- package/src/shared/mcp/functions/parse-skill-arguments.function.ts +36 -0
- package/src/shared/mcp/functions/read-agent-meta.function.ts +41 -0
- package/src/shared/mcp/functions/resolve-skill-refs.function.ts +50 -0
- package/src/shared/mcp/functions/run-startup-health-check.function.ts +34 -0
- package/src/shared/mcp/typings/mcp-capabilities.interface.ts +16 -0
- package/src/shared/mcp/typings/mcp-client.interface.ts +47 -0
- package/src/shared/mcp/typings/mcp-completion.interface.ts +45 -0
- package/src/shared/mcp/typings/mcp-content-result.model.ts +9 -0
- package/src/shared/mcp/typings/mcp-export-result.model.ts +11 -0
- package/src/shared/mcp/typings/mcp-gc-result.model.ts +15 -0
- package/src/shared/mcp/typings/mcp-integrity-check-result.model.ts +17 -0
- package/src/shared/mcp/typings/mcp-integrity-error.model.ts +15 -0
- package/src/shared/mcp/typings/mcp-notification.interface.ts +9 -0
- package/src/shared/mcp/typings/mcp-rebuild-result.model.ts +9 -0
- package/src/shared/mcp/typings/mcp-request.interface.ts +11 -0
- package/src/shared/mcp/typings/mcp-resource-result.interface.ts +12 -0
- package/src/shared/mcp/typings/mcp-resource-template.interface.ts +11 -0
- package/src/shared/mcp/typings/mcp-response.interface.ts +18 -0
- package/src/shared/mcp/typings/mcp-server-info.interface.ts +7 -0
- package/src/shared/mcp/typings/mcp-server-state.interface.ts +17 -0
- package/src/shared/mcp/typings/mcp-tool-annotations.interface.ts +32 -0
- package/src/shared/mcp/typings/mcp-tool-definition.interface.ts +16 -0
- package/src/shared/mcp/typings/mcp-tool-result.interface.ts +19 -0
- package/src/shared/mcp/typings/mcp-worker-client.interface.ts +243 -0
- package/src/shared/mcp/typings/tool-call-result.model.ts +18 -0
- package/src/shared/sync/functions/build-import-report.function.ts +40 -0
- package/src/shared/sync/functions/parse-export-entry.function.ts +45 -0
- package/src/shared/sync/functions/resolve-conflict.function.ts +31 -0
- package/src/shared/sync/functions/serialize-export-entry.function.ts +18 -0
- package/src/shared/sync/index.ts +9 -0
- package/src/shared/sync/typings/conflict-resolution.type.ts +8 -0
- package/src/shared/sync/typings/export-entry.interface.ts +13 -0
- package/src/shared/sync/typings/export-options.interface.ts +9 -0
- package/src/shared/sync/typings/import-options.interface.ts +7 -0
- package/src/shared/sync/typings/import-report.interface.ts +15 -0
- package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +112 -0
- package/src/shared/wasm-codec/functions/decode-one-recall-result.function.ts +86 -0
- package/src/shared/wasm-codec/functions/decode-option-string.function.ts +24 -0
- package/src/shared/wasm-codec/functions/decode-recall-document.function.ts +59 -0
- package/src/shared/wasm-codec/functions/decode-recall-reference.function.ts +52 -0
- package/src/shared/wasm-codec/functions/decode-recall-sibling.function.ts +43 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +86 -0
- package/src/shared/wasm-codec/functions/decode-section-match.function.ts +80 -0
- package/src/shared/wasm-codec/functions/decode-section-record-trailing.function.ts +75 -0
- package/src/shared/wasm-codec/functions/decode-section-record.function.ts +85 -0
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +87 -0
- package/src/shared/wasm-codec/functions/decode-section-type.function.ts +30 -0
- package/src/shared/wasm-codec/functions/decode-wasm-list.function.ts +31 -0
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +68 -0
- package/src/shared/wasm-codec/index.ts +5 -0
- package/src/shared/wasm-codec/typings/add-section-input.model.ts +45 -0
- package/src/shared/wasm-codec/typings/add-section-result.model.ts +28 -0
- package/src/shared/wasm-codec/typings/document-manifest.model.ts +20 -0
- package/src/shared/wasm-codec/typings/document-section.model.ts +12 -0
- package/src/shared/wasm-codec/typings/item-decoder.type.ts +10 -0
- package/src/shared/wasm-codec/typings/near-duplicate.model.ts +16 -0
- package/src/shared/wasm-codec/typings/paged-search-result.model.ts +22 -0
- package/src/shared/wasm-codec/typings/section-match.model.ts +31 -0
- package/src/shared/wasm-codec/typings/section-record-trailing.model.ts +38 -0
- package/src/shared/wasm-codec/typings/section-record.model.ts +66 -0
- package/src/shared/wasm-codec/typings/section-type-result.model.ts +12 -0
- package/src/shared/worker-client/classes/worker-client.class.ts +19 -0
- package/src/shared/worker-client/functions/handle-ipc-data.function.ts +49 -0
- package/src/shared/worker-client/functions/send-ipc-request.function.ts +39 -0
- package/src/shared/worker-client/index.ts +4 -1
- package/src/shared/worker-client/typings/add-section-result.model.ts +32 -15
- package/src/shared/worker-client/typings/export-result.model.ts +14 -0
- package/src/shared/worker-client/typings/gc-result.model.ts +6 -0
- package/src/shared/worker-client/typings/json-rpc-response.interface.ts +17 -0
- package/src/shared/worker-client/typings/pending-call.interface.ts +7 -0
- package/src/shared/worker-client/typings/recall-document.model.ts +16 -0
- package/src/shared/worker-client/typings/recall-params.model.ts +15 -0
- package/src/shared/worker-client/typings/recall-reference.model.ts +32 -0
- package/src/shared/worker-client/typings/recall-sibling.model.ts +11 -0
- package/src/shared/worker-client/typings/recall-single-result.model.ts +41 -0
- package/src/shared/worker-client/typings/search-result.model.ts +12 -0
- package/src/shared/worker-client/typings/section.model.ts +16 -0
- package/src/shared/worker-daemon/classes/ipc-error.class.ts +22 -0
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +315 -46
- package/src/shared/worker-daemon/constants/wasm-method-map.constant.ts +69 -0
- package/src/shared/worker-daemon/functions/build-ipc-error-response.function.ts +16 -0
- package/src/shared/worker-daemon/functions/check-catalog-version.function.ts +54 -0
- package/src/shared/worker-daemon/functions/check-preconditions.function.ts +28 -0
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +19 -4
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +5 -1
- package/src/shared/worker-daemon/functions/detect-stale-pid.function.ts +33 -0
- package/src/shared/worker-daemon/functions/dispatch-request.function.ts +190 -0
- package/src/shared/worker-daemon/functions/handle-check-version.function.ts +74 -0
- package/src/shared/worker-daemon/functions/handle-config-method.function.ts +27 -0
- package/src/shared/worker-daemon/functions/handle-read-ops.function.ts +236 -0
- package/src/shared/worker-daemon/functions/handle-write-ops.function.ts +257 -0
- package/src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts +51 -0
- package/src/shared/worker-daemon/functions/parse-catalog-version.function.ts +20 -0
- package/src/shared/worker-daemon/functions/parse-embedding-section.function.ts +38 -0
- package/src/shared/worker-daemon/functions/parse-worker-toml.function.ts +104 -0
- package/src/shared/worker-daemon/functions/run-startup-integrity-check.function.ts +55 -0
- package/src/shared/worker-daemon/functions/scan-near-duplicates.function.ts +92 -0
- package/src/shared/worker-daemon/functions/wasm-bridge.function.ts +144 -0
- package/src/shared/worker-daemon/functions/wasm-memory-helpers.function.ts +41 -0
- package/src/shared/worker-daemon/functions/write-lock.function.ts +49 -0
- package/src/shared/worker-daemon/typings/allocator-ref.interface.ts +16 -0
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +7 -0
- package/src/shared/worker-daemon/typings/fs-adapter.interface.ts +22 -0
- package/src/shared/worker-daemon/typings/handler-context.interface.ts +19 -0
- package/src/shared/worker-daemon/typings/memory-ref.interface.ts +13 -0
- package/src/shared/worker-daemon/typings/wasm-fn.type.ts +2 -0
- package/src/shared/worker-daemon/typings/write-lock.interface.ts +13 -0
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
- package/src/wasm/fs-database/kbdb_fs_database.js +28 -1
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +48 -1
- package/src/wasm/kb-worker/kbdb_worker.js +60 -1
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { McpLogLevel } from './log-types.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mutable runtime state shared by `McpServer` and its request
|
|
5
|
+
* handler. Extracted as an interface so the handler can be
|
|
6
|
+
* tested independently of the full server class.
|
|
7
|
+
*/
|
|
8
|
+
export interface McpServerState {
|
|
9
|
+
/** Advertised capabilities received from the MCP host. */
|
|
10
|
+
hostCapabilities: Record<string, unknown> | null;
|
|
11
|
+
/** Currently configured log level, or `null` when unset. */
|
|
12
|
+
logLevel: McpLogLevel | null;
|
|
13
|
+
/** Set of URI strings that the host has subscribed to. */
|
|
14
|
+
readonly subscriptions: Set<string>;
|
|
15
|
+
/** Filesystem path used as the KB context root. */
|
|
16
|
+
readonly contextPath: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional behavioral hints for an MCP tool, used by clients to
|
|
3
|
+
* decide how to present or invoke the tool safely.
|
|
4
|
+
*/
|
|
5
|
+
export interface McpToolAnnotations {
|
|
6
|
+
/**
|
|
7
|
+
* Human-readable title for the tool, suitable for display
|
|
8
|
+
* in client UIs.
|
|
9
|
+
*/
|
|
10
|
+
readonly title?: string;
|
|
11
|
+
/**
|
|
12
|
+
* When `true`, the tool only reads data and does not modify
|
|
13
|
+
* any server-side state.
|
|
14
|
+
*/
|
|
15
|
+
readonly readOnlyHint?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* When `true`, the tool may cause data loss or irreversible
|
|
18
|
+
* changes.
|
|
19
|
+
*/
|
|
20
|
+
readonly destructiveHint?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* When `true`, calling the tool multiple times with the same
|
|
23
|
+
* arguments produces the same result with no additional side
|
|
24
|
+
* effects.
|
|
25
|
+
*/
|
|
26
|
+
readonly idempotentHint?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* When `true`, the tool may interact with systems or data
|
|
29
|
+
* outside the immediate knowledge base context.
|
|
30
|
+
*/
|
|
31
|
+
readonly openWorldHint?: boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { McpToolAnnotations } from './mcp-tool-annotations.interface.ts';
|
|
2
|
+
|
|
3
|
+
/** Definition of a single MCP tool exposed by the server. */
|
|
4
|
+
export interface McpToolDefinition {
|
|
5
|
+
/** Unique tool name used to invoke it. */
|
|
6
|
+
readonly name: string;
|
|
7
|
+
/** Human-readable description of what the tool does. */
|
|
8
|
+
readonly description: string;
|
|
9
|
+
/** JSON Schema object describing the tool's input parameters. */
|
|
10
|
+
readonly inputSchema: Record<string, unknown>;
|
|
11
|
+
/**
|
|
12
|
+
* Optional behavioral hints that describe how the tool
|
|
13
|
+
* interacts with state.
|
|
14
|
+
*/
|
|
15
|
+
readonly annotations?: McpToolAnnotations;
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result returned by `handleToolCall`. Successful tool responses
|
|
3
|
+
* carry `isError: true` for application-level failures rather than
|
|
4
|
+
* using JSON-RPC error responses.
|
|
5
|
+
*/
|
|
6
|
+
export interface McpToolResult {
|
|
7
|
+
/** One or more text content items describing the result. */
|
|
8
|
+
readonly content: readonly {
|
|
9
|
+
/** Content type identifier, always 'text'. */
|
|
10
|
+
readonly type: string;
|
|
11
|
+
/** Text payload of the content item. */
|
|
12
|
+
readonly text: string;
|
|
13
|
+
}[];
|
|
14
|
+
/**
|
|
15
|
+
* Set to `true` when the tool encountered an application-level
|
|
16
|
+
* error. Absent or `false` on success.
|
|
17
|
+
*/
|
|
18
|
+
readonly isError?: boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import type { AddSectionResult } from '../../worker-client/typings/add-section-result.model.ts';
|
|
2
|
+
import type { RemoveSectionResult } from './remove-section-result.model.ts';
|
|
3
|
+
import type { SectionRecord } from '../../wasm-codec/functions/decode-section-records.function.ts';
|
|
4
|
+
import type { DocumentManifest } from '../../wasm-codec/functions/decode-document-manifest.function.ts';
|
|
5
|
+
import type { McpContentResult } from './mcp-content-result.model.ts';
|
|
6
|
+
import type { McpIntegrityCheckResult } from './mcp-integrity-check-result.model.ts';
|
|
7
|
+
import type { McpGcResult } from './mcp-gc-result.model.ts';
|
|
8
|
+
import type { McpRebuildResult } from './mcp-rebuild-result.model.ts';
|
|
9
|
+
import type { McpExportResult } from './mcp-export-result.model.ts';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Interface for the worker client dependency consumed by the MCP
|
|
13
|
+
* server. Defines the knowledge-base operations the server exposes
|
|
14
|
+
* as MCP tools and resources without coupling to the concrete
|
|
15
|
+
* `WorkerClient` class.
|
|
16
|
+
*/
|
|
17
|
+
export interface McpWorkerClient {
|
|
18
|
+
/**
|
|
19
|
+
* Searches the knowledge base using the given parameters.
|
|
20
|
+
*
|
|
21
|
+
* @param params - query string and optional search options
|
|
22
|
+
* @returns ranked list of matching section summaries
|
|
23
|
+
*/
|
|
24
|
+
search(params: {
|
|
25
|
+
/** Natural language query text. */
|
|
26
|
+
readonly query: string;
|
|
27
|
+
/** Search mode: 'sections', 'documents', or 'stats'. */
|
|
28
|
+
readonly mode?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Search algorithm: `'lexical'`, `'vector'`, or `'hybrid'`.
|
|
31
|
+
* Defaults to `'lexical'` when omitted.
|
|
32
|
+
*/
|
|
33
|
+
readonly algo?: string;
|
|
34
|
+
/** Maximum number of results to return. */
|
|
35
|
+
readonly limit?: number;
|
|
36
|
+
/** Number of results to skip for pagination. */
|
|
37
|
+
readonly offset?: number;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
readonly items: readonly {
|
|
40
|
+
readonly kbid: string;
|
|
41
|
+
readonly heading: string | null;
|
|
42
|
+
readonly type: string;
|
|
43
|
+
readonly docids: readonly string[];
|
|
44
|
+
readonly score: number;
|
|
45
|
+
readonly snippet: string;
|
|
46
|
+
readonly matched_terms: readonly string[];
|
|
47
|
+
/** Fields that contained matches (heading, body, code). */
|
|
48
|
+
readonly matched_fields?: readonly string[];
|
|
49
|
+
/** ISO 8601 creation timestamp of the section. */
|
|
50
|
+
readonly created_at?: string;
|
|
51
|
+
}[];
|
|
52
|
+
readonly total: number;
|
|
53
|
+
readonly offset: number;
|
|
54
|
+
readonly limit: number;
|
|
55
|
+
readonly has_more: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* `true` when results came from an automatic AND-to-OR
|
|
58
|
+
* fallback query relaxation.
|
|
59
|
+
*/
|
|
60
|
+
readonly relaxed?: boolean;
|
|
61
|
+
}>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Adds a new section to the knowledge base.
|
|
65
|
+
*
|
|
66
|
+
* @param params - content type, raw content, and optional metadata
|
|
67
|
+
* @returns the assigned knowledge-base identifier
|
|
68
|
+
*/
|
|
69
|
+
addSection(params: {
|
|
70
|
+
/** Semantic type label for the section content. */
|
|
71
|
+
readonly sectionType: string;
|
|
72
|
+
/** Raw text or base64-encoded content for the section. */
|
|
73
|
+
readonly content: string;
|
|
74
|
+
/** Optional section title. Required for image/* types. */
|
|
75
|
+
readonly title?: string;
|
|
76
|
+
/** Optional section description. */
|
|
77
|
+
readonly description?: string;
|
|
78
|
+
/** Optional document ID to group this section under. */
|
|
79
|
+
readonly docid?: string;
|
|
80
|
+
/** Optional tags for scoping and filtering. */
|
|
81
|
+
readonly tags?: string[];
|
|
82
|
+
/**
|
|
83
|
+
* When `true`, replaces an existing section that has the same
|
|
84
|
+
* source key (supersession).
|
|
85
|
+
*/
|
|
86
|
+
readonly replace?: boolean;
|
|
87
|
+
}): Promise<AddSectionResult>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Removes a section from the knowledge base.
|
|
91
|
+
*
|
|
92
|
+
* @param kbid - knowledge-base identifier of the section to remove
|
|
93
|
+
* @returns removal result with `removed` flag and elapsed time
|
|
94
|
+
*/
|
|
95
|
+
removeSection(kbid: string): Promise<RemoveSectionResult>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves one or more sections by their identifiers.
|
|
99
|
+
*
|
|
100
|
+
* @param kbids - list of knowledge-base identifiers to fetch
|
|
101
|
+
* @returns sections in the order their IDs were requested
|
|
102
|
+
*/
|
|
103
|
+
readSections(kbids: string[]): Promise<
|
|
104
|
+
{
|
|
105
|
+
/** Knowledge-base identifier for this section. */
|
|
106
|
+
kbid: string;
|
|
107
|
+
/** Semantic type label assigned to the section. */
|
|
108
|
+
sectionType: string;
|
|
109
|
+
/** Raw text content of the section. */
|
|
110
|
+
content: string;
|
|
111
|
+
/** Byte size of the stored content. */
|
|
112
|
+
size: number;
|
|
113
|
+
}[]
|
|
114
|
+
>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Retrieves a full document record including its ordered sections.
|
|
118
|
+
*
|
|
119
|
+
* @param docid - identifier of the document to retrieve
|
|
120
|
+
* @returns the document record as returned by the daemon
|
|
121
|
+
*/
|
|
122
|
+
retrieveDocument(docid: string): Promise<unknown>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Composes a rendered Markdown document from one or more kbid
|
|
126
|
+
* or docid identifiers.
|
|
127
|
+
*
|
|
128
|
+
* @param ids - list of kbid or docid identifiers (may be mixed)
|
|
129
|
+
* @returns composed Markdown result with character count
|
|
130
|
+
*/
|
|
131
|
+
content(ids: string[]): Promise<McpContentResult>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Returns database metadata and status from the daemon.
|
|
135
|
+
*
|
|
136
|
+
* @returns document count, section count, and timing statistics
|
|
137
|
+
*/
|
|
138
|
+
dbStatus(): Promise<{
|
|
139
|
+
/** Whether the daemon has finished loading its WASM modules. */
|
|
140
|
+
initialized: boolean;
|
|
141
|
+
/** Absolute path to the context directory the daemon serves. */
|
|
142
|
+
contextPath: string;
|
|
143
|
+
/** In-memory cache statistics. */
|
|
144
|
+
cacheStats: {
|
|
145
|
+
/** Number of content entries currently cached. */
|
|
146
|
+
contentCount: number;
|
|
147
|
+
/** Number of index entries currently cached. */
|
|
148
|
+
indexCount: number;
|
|
149
|
+
};
|
|
150
|
+
}>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Runs an integrity check on the knowledge-base database.
|
|
154
|
+
*
|
|
155
|
+
* @returns a report of all issues found; `ok` is `true` when
|
|
156
|
+
* no errors were detected
|
|
157
|
+
*/
|
|
158
|
+
integrityCheck(): Promise<McpIntegrityCheckResult>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Removes unreferenced sections from the database.
|
|
162
|
+
*
|
|
163
|
+
* @returns a report of sections removed and bytes freed
|
|
164
|
+
*/
|
|
165
|
+
gc(): Promise<McpGcResult>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Reconstructs all index files from section files and document
|
|
169
|
+
* manifests on disk.
|
|
170
|
+
*
|
|
171
|
+
* @returns a report of sections and terms re-indexed
|
|
172
|
+
*/
|
|
173
|
+
rebuildIndexes(): Promise<McpRebuildResult>;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Retrieves all sections whose type name matches the given string.
|
|
177
|
+
*
|
|
178
|
+
* @param sectionType - the application-level type name to filter by
|
|
179
|
+
* @returns all section records with a matching type name
|
|
180
|
+
*/
|
|
181
|
+
listByType(sectionType: string): Promise<SectionRecord[]>;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Retrieves all documents whose type name matches the given string.
|
|
185
|
+
*
|
|
186
|
+
* @param docType - the application-level document type to filter by
|
|
187
|
+
* @returns all document manifests with a matching type name
|
|
188
|
+
*/
|
|
189
|
+
listDocumentsByType(docType: string): Promise<DocumentManifest[]>;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Groups a set of sections under a named document.
|
|
193
|
+
*
|
|
194
|
+
* @param title - human-readable document title
|
|
195
|
+
* @param kbids - identifiers of the sections to group
|
|
196
|
+
* @returns the assigned document identifier
|
|
197
|
+
*/
|
|
198
|
+
groupSections(
|
|
199
|
+
title: string,
|
|
200
|
+
kbids: string[],
|
|
201
|
+
docType?: string,
|
|
202
|
+
): Promise<string>;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Removes the document grouping for the given document.
|
|
206
|
+
*
|
|
207
|
+
* The sections themselves are not deleted; only the grouping
|
|
208
|
+
* record is removed.
|
|
209
|
+
*
|
|
210
|
+
* @param docid - identifier of the document grouping to remove
|
|
211
|
+
*/
|
|
212
|
+
removeGrouping(docid: string): Promise<void>;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Retrieves full content and context for one or more sections by
|
|
216
|
+
* their knowledge-base identifiers.
|
|
217
|
+
*
|
|
218
|
+
* @param params - section identifier(s) and optional expansion depth
|
|
219
|
+
* @returns a single result or array of results depending on input
|
|
220
|
+
*/
|
|
221
|
+
recall(params: {
|
|
222
|
+
/** Single section identifier. */
|
|
223
|
+
readonly kbid?: string;
|
|
224
|
+
/** Batch section identifiers. */
|
|
225
|
+
readonly kbids?: readonly string[];
|
|
226
|
+
/** Expansion depth (0-3, default: 0). */
|
|
227
|
+
readonly depth?: number;
|
|
228
|
+
}): Promise<unknown>;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Exports the database to a target directory as a self-contained
|
|
232
|
+
* snapshot (sections, documents, catalog -- no indexes).
|
|
233
|
+
*
|
|
234
|
+
* @param params - optional export parameters
|
|
235
|
+
* @returns export report with the resolved path and file counts
|
|
236
|
+
*/
|
|
237
|
+
export(params?: {
|
|
238
|
+
readonly path?: string;
|
|
239
|
+
}): Promise<McpExportResult>;
|
|
240
|
+
|
|
241
|
+
/** Destroys the IPC socket and clears the connection state. */
|
|
242
|
+
disconnect(): void;
|
|
243
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Shape of a content item in an MCP tool call response. */
|
|
2
|
+
export interface ToolContent {
|
|
3
|
+
/** Content type identifier, typically `'text'`. */
|
|
4
|
+
readonly type: string;
|
|
5
|
+
/** The text payload. */
|
|
6
|
+
readonly text: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Result returned by any MCP tool call handler, containing one or
|
|
11
|
+
* more content items and an optional error flag.
|
|
12
|
+
*/
|
|
13
|
+
export interface ToolCallResult {
|
|
14
|
+
/** One or more content items describing the result. */
|
|
15
|
+
readonly content: ToolContent[];
|
|
16
|
+
/** Set to `true` when the tool encountered an error. */
|
|
17
|
+
readonly isError?: boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ConflictResolution } from '../typings/conflict-resolution.type.ts';
|
|
2
|
+
import type { ExportEntry } from '../typings/export-entry.interface.ts';
|
|
3
|
+
import type { ImportReport } from '../typings/import-report.interface.ts';
|
|
4
|
+
|
|
5
|
+
/** A resolution record pairing an entry with its resolution. */
|
|
6
|
+
interface ResolutionRecord {
|
|
7
|
+
/** The export entry being resolved. */
|
|
8
|
+
readonly entry: ExportEntry;
|
|
9
|
+
/** The resolution applied to the entry. */
|
|
10
|
+
readonly resolution: ConflictResolution;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Builds an import report from resolution results.
|
|
15
|
+
*
|
|
16
|
+
* Counts each resolution type and determines whether
|
|
17
|
+
* a database rebuild is required after the import.
|
|
18
|
+
*/
|
|
19
|
+
export function buildImportReport(
|
|
20
|
+
resolutions: readonly ResolutionRecord[],
|
|
21
|
+
): ImportReport {
|
|
22
|
+
let sectionsAdded = 0;
|
|
23
|
+
let sectionsSkipped = 0;
|
|
24
|
+
let sectionsSuperseded = 0;
|
|
25
|
+
|
|
26
|
+
for (const { resolution } of resolutions) {
|
|
27
|
+
if (resolution === 'add') sectionsAdded++;
|
|
28
|
+
else if (resolution === 'skip') sectionsSkipped++;
|
|
29
|
+
else sectionsSuperseded++;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
sectionsAdded,
|
|
34
|
+
sectionsSkipped,
|
|
35
|
+
sectionsSuperseded,
|
|
36
|
+
documentsAdded: sectionsAdded,
|
|
37
|
+
documentsSkipped: sectionsSkipped,
|
|
38
|
+
rebuildRequired: sectionsAdded > 0 || sectionsSuperseded > 0,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ExportEntry } from '../typings/export-entry.interface.ts';
|
|
2
|
+
|
|
3
|
+
/** Extracts a quoted string value for a TOML key. */
|
|
4
|
+
function extractField(lines: string[], key: string): string {
|
|
5
|
+
for (const line of lines) {
|
|
6
|
+
const prefix = `${key} = "`;
|
|
7
|
+
if (line.startsWith(prefix) && line.endsWith('"')) {
|
|
8
|
+
return line.slice(prefix.length, -1);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
throw new Error(`Missing required field: ${key}`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parses a serialized export entry.
|
|
16
|
+
*
|
|
17
|
+
* Expects TOML frontmatter delimited by `+++` lines,
|
|
18
|
+
* followed by the body content.
|
|
19
|
+
*
|
|
20
|
+
* @throws {Error} if the frontmatter delimiters are absent
|
|
21
|
+
* or required fields are missing.
|
|
22
|
+
*/
|
|
23
|
+
export function parseExportEntry(content: string): ExportEntry {
|
|
24
|
+
const firstDelim = content.indexOf('+++');
|
|
25
|
+
if (firstDelim === -1) {
|
|
26
|
+
throw new Error('Missing opening +++ delimiter');
|
|
27
|
+
}
|
|
28
|
+
const afterFirst = firstDelim + 3;
|
|
29
|
+
const secondDelim = content.indexOf('+++', afterFirst);
|
|
30
|
+
if (secondDelim === -1) {
|
|
31
|
+
throw new Error('Missing closing +++ delimiter');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const frontmatter = content.slice(afterFirst, secondDelim).trim();
|
|
35
|
+
const body = content.slice(secondDelim + 3).replace(/^\n/, '');
|
|
36
|
+
const lines = frontmatter.split('\n');
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
kbid: extractField(lines, 'kbid'),
|
|
40
|
+
sourceKey: extractField(lines, 'sourceKey'),
|
|
41
|
+
heading: extractField(lines, 'heading'),
|
|
42
|
+
createdAt: extractField(lines, 'createdAt'),
|
|
43
|
+
body,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ConflictResolution } from '../typings/conflict-resolution.type.ts';
|
|
2
|
+
import type { ExportEntry } from '../typings/export-entry.interface.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determines the conflict resolution action for
|
|
6
|
+
* an incoming section.
|
|
7
|
+
*
|
|
8
|
+
* Rules applied in order:
|
|
9
|
+
* 1. Same kbid exists -> skip
|
|
10
|
+
* 2. Same source_key, incoming is newer -> supersede
|
|
11
|
+
* 3. Same source_key, incoming is not newer -> skip
|
|
12
|
+
* 4. No match -> add
|
|
13
|
+
*/
|
|
14
|
+
export function resolveConflict(
|
|
15
|
+
incoming: ExportEntry,
|
|
16
|
+
existingKbids: ReadonlySet<string>,
|
|
17
|
+
existingBySourceKey: ReadonlyMap<string, ExportEntry>,
|
|
18
|
+
): ConflictResolution {
|
|
19
|
+
if (existingKbids.has(incoming.kbid)) {
|
|
20
|
+
return 'skip';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const existing = existingBySourceKey.get(incoming.sourceKey);
|
|
24
|
+
if (existing !== undefined) {
|
|
25
|
+
const incomingTime = new Date(incoming.createdAt).getTime();
|
|
26
|
+
const existingTime = new Date(existing.createdAt).getTime();
|
|
27
|
+
return incomingTime > existingTime ? 'supersede' : 'skip';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return 'add';
|
|
31
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ExportEntry } from '../typings/export-entry.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Serializes an export entry to a flat file format.
|
|
5
|
+
*
|
|
6
|
+
* Format: TOML frontmatter delimited by `+++` lines,
|
|
7
|
+
* followed by the body content.
|
|
8
|
+
*/
|
|
9
|
+
export function serializeExportEntry(entry: ExportEntry): string {
|
|
10
|
+
const frontmatter = [
|
|
11
|
+
`kbid = "${entry.kbid}"`,
|
|
12
|
+
`sourceKey = "${entry.sourceKey}"`,
|
|
13
|
+
`heading = "${entry.heading}"`,
|
|
14
|
+
`createdAt = "${entry.createdAt}"`,
|
|
15
|
+
].join('\n');
|
|
16
|
+
|
|
17
|
+
return `+++\n${frontmatter}\n+++\n${entry.body}`;
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { resolveConflict } from './functions/resolve-conflict.function.ts';
|
|
2
|
+
export { buildImportReport } from './functions/build-import-report.function.ts';
|
|
3
|
+
export { serializeExportEntry } from './functions/serialize-export-entry.function.ts';
|
|
4
|
+
export { parseExportEntry } from './functions/parse-export-entry.function.ts';
|
|
5
|
+
export type { ExportEntry } from './typings/export-entry.interface.ts';
|
|
6
|
+
export type { ExportOptions } from './typings/export-options.interface.ts';
|
|
7
|
+
export type { ImportOptions } from './typings/import-options.interface.ts';
|
|
8
|
+
export type { ImportReport } from './typings/import-report.interface.ts';
|
|
9
|
+
export type { ConflictResolution } from './typings/conflict-resolution.type.ts';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A single entry in an export manifest. */
|
|
2
|
+
export interface ExportEntry {
|
|
3
|
+
/** Section kbid. */
|
|
4
|
+
readonly kbid: string;
|
|
5
|
+
/** Source key. */
|
|
6
|
+
readonly sourceKey: string;
|
|
7
|
+
/** Section heading. */
|
|
8
|
+
readonly heading: string;
|
|
9
|
+
/** Content body. */
|
|
10
|
+
readonly body: string;
|
|
11
|
+
/** Created timestamp (ISO). */
|
|
12
|
+
readonly createdAt: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Options for export operation. */
|
|
2
|
+
export interface ExportOptions {
|
|
3
|
+
/** Export format. */
|
|
4
|
+
readonly format: 'git' | 'archive';
|
|
5
|
+
/** Output directory or file path. */
|
|
6
|
+
readonly outputPath: string;
|
|
7
|
+
/** Exclude vector indexes. */
|
|
8
|
+
readonly excludeVectors: boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Report of an import operation. */
|
|
2
|
+
export interface ImportReport {
|
|
3
|
+
/** Sections added. */
|
|
4
|
+
readonly sectionsAdded: number;
|
|
5
|
+
/** Sections skipped (same kbid). */
|
|
6
|
+
readonly sectionsSkipped: number;
|
|
7
|
+
/** Sections superseded (same source_key, newer). */
|
|
8
|
+
readonly sectionsSuperseded: number;
|
|
9
|
+
/** Documents added. */
|
|
10
|
+
readonly documentsAdded: number;
|
|
11
|
+
/** Documents skipped. */
|
|
12
|
+
readonly documentsSkipped: number;
|
|
13
|
+
/** Whether rebuild is required. */
|
|
14
|
+
readonly rebuildRequired: boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { decodeString } from './decode-string.function.ts';
|
|
2
|
+
import { decodeU32 } from './decode-u32.function.ts';
|
|
3
|
+
import { decodeU64 } from './decode-u64.function.ts';
|
|
4
|
+
import { decodeF32 } from './decode-f32.function.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A near-duplicate section identified during add-section indexing.
|
|
8
|
+
*/
|
|
9
|
+
export interface NearDuplicate {
|
|
10
|
+
/** Knowledge-base identifier of the near-duplicate section. */
|
|
11
|
+
readonly kbid: string;
|
|
12
|
+
/** Jaccard similarity score (0.0–1.0). */
|
|
13
|
+
readonly similarity: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Decoded result of a `worker_add_section` WASM call.
|
|
18
|
+
*
|
|
19
|
+
* Mirrors the Rust `AddSectionResult` struct encoded via the
|
|
20
|
+
* `Encode` trait wire format.
|
|
21
|
+
*/
|
|
22
|
+
export interface AddSectionResult {
|
|
23
|
+
/** Knowledge-base identifier assigned to the new section. */
|
|
24
|
+
readonly kbid: string;
|
|
25
|
+
/** Number of unique terms indexed for the section. */
|
|
26
|
+
readonly indexedTermsCount: number;
|
|
27
|
+
/** Wall-clock time the add operation took, in milliseconds. */
|
|
28
|
+
readonly elapsedMs: number;
|
|
29
|
+
/**
|
|
30
|
+
* Knowledge-base identifier of the section that was superseded,
|
|
31
|
+
* or `null` if no supersession occurred.
|
|
32
|
+
*/
|
|
33
|
+
readonly superseded: string | null;
|
|
34
|
+
/** Advisory warnings emitted during indexing. */
|
|
35
|
+
readonly warnings: string[];
|
|
36
|
+
/**
|
|
37
|
+
* Near-duplicate sections detected above the similarity threshold
|
|
38
|
+
* (Jaccard ≥ 0.85).
|
|
39
|
+
*/
|
|
40
|
+
readonly nearDuplicates: NearDuplicate[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Decodes the binary `AddSectionResult` returned by the
|
|
45
|
+
* `worker_add_section` WASM export.
|
|
46
|
+
*
|
|
47
|
+
* Wire format (little-endian):
|
|
48
|
+
* - `kbid`: `u32` length + UTF-8 bytes
|
|
49
|
+
* - `indexed_terms_count`: `u32`
|
|
50
|
+
* - `elapsed_ms`: `u64`
|
|
51
|
+
* - `superseded`: `u8` flag (0=None, 1=Some) + optional `String`
|
|
52
|
+
* - `warnings`: `u32` count + each `String`
|
|
53
|
+
* - `near_duplicates`: `u32` count + each (`String` + `f32`)
|
|
54
|
+
*/
|
|
55
|
+
export function decodeAddSectionResult(
|
|
56
|
+
bytes: Uint8Array,
|
|
57
|
+
): AddSectionResult {
|
|
58
|
+
let offset = 0;
|
|
59
|
+
|
|
60
|
+
const kbid = decodeString(bytes, offset);
|
|
61
|
+
offset += kbid.bytesRead;
|
|
62
|
+
|
|
63
|
+
const indexedTermsCount = decodeU32(bytes, offset);
|
|
64
|
+
offset += indexedTermsCount.bytesRead;
|
|
65
|
+
|
|
66
|
+
const elapsedMsBig = decodeU64(bytes, offset);
|
|
67
|
+
offset += elapsedMsBig.bytesRead;
|
|
68
|
+
|
|
69
|
+
// Decode Option<String> for superseded
|
|
70
|
+
const supersededTag = bytes[offset];
|
|
71
|
+
offset += 1;
|
|
72
|
+
let superseded: string | null = null;
|
|
73
|
+
if (supersededTag === 0x01) {
|
|
74
|
+
const supersededStr = decodeString(bytes, offset);
|
|
75
|
+
offset += supersededStr.bytesRead;
|
|
76
|
+
superseded = supersededStr.value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Decode Vec<String> for warnings
|
|
80
|
+
const warningCount = decodeU32(bytes, offset);
|
|
81
|
+
offset += warningCount.bytesRead;
|
|
82
|
+
const warnings: string[] = [];
|
|
83
|
+
for (let i = 0; i < warningCount.value; i++) {
|
|
84
|
+
const warning = decodeString(bytes, offset);
|
|
85
|
+
offset += warning.bytesRead;
|
|
86
|
+
warnings.push(warning.value);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Decode Vec<(String, f32)> for near_duplicates
|
|
90
|
+
const dupCount = decodeU32(bytes, offset);
|
|
91
|
+
offset += dupCount.bytesRead;
|
|
92
|
+
const nearDuplicates: NearDuplicate[] = [];
|
|
93
|
+
for (let i = 0; i < dupCount.value; i++) {
|
|
94
|
+
const dupKbid = decodeString(bytes, offset);
|
|
95
|
+
offset += dupKbid.bytesRead;
|
|
96
|
+
const similarity = decodeF32(bytes, offset);
|
|
97
|
+
offset += similarity.bytesRead;
|
|
98
|
+
nearDuplicates.push({
|
|
99
|
+
kbid: dupKbid.value,
|
|
100
|
+
similarity: similarity.value,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
kbid: kbid.value,
|
|
106
|
+
indexedTermsCount: indexedTermsCount.value,
|
|
107
|
+
elapsedMs: Number(elapsedMsBig.value),
|
|
108
|
+
superseded,
|
|
109
|
+
warnings,
|
|
110
|
+
nearDuplicates,
|
|
111
|
+
};
|
|
112
|
+
}
|