@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
package/dist/cli.mjs
CHANGED
|
@@ -78,6 +78,9 @@ function parseArgs(argv) {
|
|
|
78
78
|
parseInt(argv[++i] ?? "", 10) || 0
|
|
79
79
|
);
|
|
80
80
|
break;
|
|
81
|
+
case "--algo":
|
|
82
|
+
options.algo = argv[++i];
|
|
83
|
+
break;
|
|
81
84
|
case "--title":
|
|
82
85
|
options.title = argv[++i];
|
|
83
86
|
break;
|
|
@@ -99,6 +102,19 @@ function parseArgs(argv) {
|
|
|
99
102
|
case "--skills":
|
|
100
103
|
options.skills = (argv[++i] ?? "").split(",");
|
|
101
104
|
break;
|
|
105
|
+
case "--tags":
|
|
106
|
+
options.tags = (argv[++i] ?? "").split(",");
|
|
107
|
+
break;
|
|
108
|
+
case "--replace":
|
|
109
|
+
options.replace = true;
|
|
110
|
+
break;
|
|
111
|
+
case "--depth":
|
|
112
|
+
case "-d":
|
|
113
|
+
options.depth = Math.min(
|
|
114
|
+
3,
|
|
115
|
+
Math.max(0, parseInt(argv[++i] ?? "", 10) || 0)
|
|
116
|
+
);
|
|
117
|
+
break;
|
|
102
118
|
case "--content":
|
|
103
119
|
case "-c":
|
|
104
120
|
options.content = true;
|
|
@@ -136,9 +152,11 @@ function formatText(paged) {
|
|
|
136
152
|
const num = paged.offset + i + 1;
|
|
137
153
|
const heading = r.heading ?? "(untitled)";
|
|
138
154
|
const terms = r.matched_terms.join(", ");
|
|
139
|
-
|
|
155
|
+
const fields = r.matched_fields.join(", ");
|
|
156
|
+
const confidencePct = (r.confidence * 100).toFixed(0);
|
|
157
|
+
return `${String(num)}. [${r.kbid}] ${heading} (score: ${r.score.toFixed(4)}, confidence: ${confidencePct}%)
|
|
140
158
|
${r.snippet || r.preview || "(no snippet)"}
|
|
141
|
-
type: ${r.type} terms: ${terms}
|
|
159
|
+
type: ${r.type} terms: ${terms}` + (fields ? ` fields: ${fields}` : "");
|
|
142
160
|
}).join("\n\n");
|
|
143
161
|
const footer = `
|
|
144
162
|
Showing ${String(start)}-${String(end)} of ${String(paged.total)} results`;
|
|
@@ -147,12 +165,32 @@ Use --offset ${String(end)} to see more` : "";
|
|
|
147
165
|
return lines + footer + hint;
|
|
148
166
|
}
|
|
149
167
|
function formatMcp(paged) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
const mcpItems = paged.items.map((r) => ({
|
|
169
|
+
kbid: r.kbid,
|
|
170
|
+
heading: r.heading,
|
|
171
|
+
type: r.type,
|
|
172
|
+
docids: r.docids,
|
|
173
|
+
snippet: r.snippet,
|
|
174
|
+
matched_terms: r.matched_terms,
|
|
175
|
+
matched_fields: r.matched_fields,
|
|
176
|
+
created_at: r.created_at
|
|
177
|
+
}));
|
|
178
|
+
return JSON.stringify(
|
|
179
|
+
{
|
|
180
|
+
type: "text",
|
|
181
|
+
text: paged.items.map(
|
|
182
|
+
(r) => `[${r.kbid}] ${r.heading ?? "(untitled)"} \u2014 ${r.snippet || r.preview}`
|
|
183
|
+
).join("\n"),
|
|
184
|
+
items: mcpItems,
|
|
185
|
+
total: paged.total,
|
|
186
|
+
offset: paged.offset,
|
|
187
|
+
limit: paged.limit,
|
|
188
|
+
has_more: paged.has_more,
|
|
189
|
+
relaxed: paged.relaxed
|
|
190
|
+
},
|
|
191
|
+
null,
|
|
192
|
+
2
|
|
193
|
+
);
|
|
156
194
|
}
|
|
157
195
|
|
|
158
196
|
// src/shared/cli/functions/run-search.function.ts
|
|
@@ -164,14 +202,16 @@ async function runSearch(client, options) {
|
|
|
164
202
|
total: 0,
|
|
165
203
|
offset: 0,
|
|
166
204
|
limit: options.limit,
|
|
167
|
-
has_more: false
|
|
205
|
+
has_more: false,
|
|
206
|
+
relaxed: false
|
|
168
207
|
};
|
|
169
208
|
}
|
|
170
209
|
const results = await client.search({
|
|
171
210
|
query,
|
|
172
211
|
mode: options.mode,
|
|
173
212
|
limit: options.limit,
|
|
174
|
-
offset: options.offset
|
|
213
|
+
offset: options.offset,
|
|
214
|
+
algo: options.algo
|
|
175
215
|
});
|
|
176
216
|
return {
|
|
177
217
|
items: results.items.map((r) => ({
|
|
@@ -180,17 +220,43 @@ async function runSearch(client, options) {
|
|
|
180
220
|
type: r.type,
|
|
181
221
|
docids: r.docids,
|
|
182
222
|
score: r.score,
|
|
223
|
+
confidence: r.confidence ?? 0,
|
|
183
224
|
snippet: r.snippet,
|
|
184
225
|
matched_terms: r.matched_terms,
|
|
226
|
+
matched_fields: r.matched_fields ?? [],
|
|
227
|
+
created_at: r.created_at ?? "",
|
|
185
228
|
preview: ""
|
|
186
229
|
})),
|
|
187
230
|
total: results.total,
|
|
188
231
|
offset: results.offset,
|
|
189
232
|
limit: results.limit,
|
|
190
|
-
has_more: results.has_more
|
|
233
|
+
has_more: results.has_more,
|
|
234
|
+
relaxed: results.relaxed ?? false
|
|
191
235
|
};
|
|
192
236
|
}
|
|
193
237
|
|
|
238
|
+
// src/shared/cli/functions/run-recall.function.ts
|
|
239
|
+
var MAX_RECALL_DEPTH = 3;
|
|
240
|
+
async function runRecall(client, options) {
|
|
241
|
+
if (options.args.length === 0) {
|
|
242
|
+
return { error: "no kbid provided" };
|
|
243
|
+
}
|
|
244
|
+
const depth = Math.min(
|
|
245
|
+
MAX_RECALL_DEPTH,
|
|
246
|
+
Math.max(0, options.depth ?? 0)
|
|
247
|
+
);
|
|
248
|
+
if (options.args.length === 1) {
|
|
249
|
+
return client.recall({ kbid: options.args[0], depth });
|
|
250
|
+
}
|
|
251
|
+
return client.recall({ kbids: options.args, depth });
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/shared/cli/functions/run-export.function.ts
|
|
255
|
+
async function runExport(client, options) {
|
|
256
|
+
const path = options.args[0];
|
|
257
|
+
return client.export({ path });
|
|
258
|
+
}
|
|
259
|
+
|
|
194
260
|
// src/shared/cli/functions/run-learn.function.ts
|
|
195
261
|
import { readFileSync, readdirSync, statSync } from "node:fs";
|
|
196
262
|
import { basename, extname, join } from "node:path";
|
|
@@ -208,14 +274,11 @@ async function runLearn(client, options, io) {
|
|
|
208
274
|
content,
|
|
209
275
|
title: options.title,
|
|
210
276
|
description: options.description,
|
|
211
|
-
docid: options.docid
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
kbid: result.kbid,
|
|
215
|
-
path: "-",
|
|
216
|
-
size: content.length,
|
|
217
|
-
skipped: false
|
|
277
|
+
docid: options.docid,
|
|
278
|
+
tags: options.tags,
|
|
279
|
+
replace: options.replace
|
|
218
280
|
});
|
|
281
|
+
results.push(mapAddSectionResult(result, "-", content.length));
|
|
219
282
|
continue;
|
|
220
283
|
}
|
|
221
284
|
const files = collectFiles(target);
|
|
@@ -225,18 +288,30 @@ async function runLearn(client, options, io) {
|
|
|
225
288
|
sectionType: "text",
|
|
226
289
|
content,
|
|
227
290
|
title: options.title,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
size: content.length,
|
|
234
|
-
skipped: false
|
|
291
|
+
description: options.description,
|
|
292
|
+
docid: options.docid,
|
|
293
|
+
tags: options.tags,
|
|
294
|
+
replace: options.replace,
|
|
295
|
+
sourcePath: file
|
|
235
296
|
});
|
|
297
|
+
results.push(
|
|
298
|
+
mapAddSectionResult(result, file, content.length)
|
|
299
|
+
);
|
|
236
300
|
}
|
|
237
301
|
}
|
|
238
302
|
return results;
|
|
239
303
|
}
|
|
304
|
+
function mapAddSectionResult(result, path, size) {
|
|
305
|
+
return {
|
|
306
|
+
kbid: result.kbid,
|
|
307
|
+
path,
|
|
308
|
+
size,
|
|
309
|
+
skipped: false,
|
|
310
|
+
superseded: result.superseded ?? null,
|
|
311
|
+
warnings: result.warnings ?? [],
|
|
312
|
+
near_duplicates: result.near_duplicates ?? []
|
|
313
|
+
};
|
|
314
|
+
}
|
|
240
315
|
function readProcessStdin() {
|
|
241
316
|
return new Promise((resolve4) => {
|
|
242
317
|
const chunks = [];
|
|
@@ -301,8 +376,26 @@ async function runContent(client, options) {
|
|
|
301
376
|
}
|
|
302
377
|
|
|
303
378
|
// src/shared/cli/functions/run-check.function.ts
|
|
379
|
+
function parseDivergentContent(encoded) {
|
|
380
|
+
if (!encoded) return [];
|
|
381
|
+
return encoded.split(";").filter((segment) => segment.includes(":")).map((segment) => {
|
|
382
|
+
const colonIdx = segment.indexOf(":");
|
|
383
|
+
const sourceKey = segment.slice(0, colonIdx);
|
|
384
|
+
const kbids = segment.slice(colonIdx + 1).split(",").filter((k) => k.length > 0);
|
|
385
|
+
return { sourceKey, kbids };
|
|
386
|
+
}).filter((entry) => entry.kbids.length > 0);
|
|
387
|
+
}
|
|
304
388
|
async function runCheck(client, _options) {
|
|
305
|
-
|
|
389
|
+
const raw = await client.integrityCheck();
|
|
390
|
+
return {
|
|
391
|
+
ok: raw.ok,
|
|
392
|
+
errors: raw.errors,
|
|
393
|
+
sections_checked: raw.sections_checked,
|
|
394
|
+
documents_checked: raw.documents_checked,
|
|
395
|
+
references_checked: raw.references_checked,
|
|
396
|
+
elapsed_ms: raw.elapsed_ms,
|
|
397
|
+
divergent_content: parseDivergentContent(raw.divergent_content)
|
|
398
|
+
};
|
|
306
399
|
}
|
|
307
400
|
|
|
308
401
|
// src/shared/cli/functions/run-gc.function.ts
|
|
@@ -325,8 +418,109 @@ function findDb(dbPath) {
|
|
|
325
418
|
}
|
|
326
419
|
|
|
327
420
|
// src/shared/cli/functions/run-init.function.ts
|
|
421
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
422
|
+
import { join as join4, resolve as resolve2 } from "node:path";
|
|
423
|
+
|
|
424
|
+
// src/shared/cli/functions/install-default-skills.function.ts
|
|
425
|
+
import { createHash } from "node:crypto";
|
|
328
426
|
import { existsSync as existsSync2, mkdirSync, writeFileSync } from "node:fs";
|
|
329
|
-
import { join as join3
|
|
427
|
+
import { join as join3 } from "node:path";
|
|
428
|
+
var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
429
|
+
function base32Encode(bytes) {
|
|
430
|
+
let result = "";
|
|
431
|
+
let bits = 0;
|
|
432
|
+
let value = 0;
|
|
433
|
+
for (const byte of bytes) {
|
|
434
|
+
value = value << 8 | byte;
|
|
435
|
+
bits += 8;
|
|
436
|
+
while (bits >= 5) {
|
|
437
|
+
result += BASE32_ALPHABET[value >>> bits - 5 & 31];
|
|
438
|
+
bits -= 5;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (bits > 0) {
|
|
442
|
+
result += BASE32_ALPHABET[value << 5 - bits & 31];
|
|
443
|
+
}
|
|
444
|
+
return result.toLowerCase();
|
|
445
|
+
}
|
|
446
|
+
function computeSectionKbid(mimeType, content) {
|
|
447
|
+
const contentBytes = Buffer.from(content, "utf-8");
|
|
448
|
+
const header = `section ${mimeType} ${contentBytes.length.toString()}\0`;
|
|
449
|
+
const headerBytes = Buffer.from(header, "utf-8");
|
|
450
|
+
const input = Buffer.concat([headerBytes, contentBytes]);
|
|
451
|
+
const hash = createHash("sha256").update(input).digest();
|
|
452
|
+
const truncated = new Uint8Array(hash.buffer, 0, 16);
|
|
453
|
+
return base32Encode(truncated);
|
|
454
|
+
}
|
|
455
|
+
function escapeToml(s) {
|
|
456
|
+
return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
457
|
+
}
|
|
458
|
+
function serializeSkillSection(kbid, title, description, content) {
|
|
459
|
+
const size = Buffer.byteLength(content, "utf-8");
|
|
460
|
+
const header = [
|
|
461
|
+
`kbid = "${escapeToml(kbid)}"`,
|
|
462
|
+
`section_type = "text/markdown"`,
|
|
463
|
+
`type_name = "skill"`,
|
|
464
|
+
`title = "${escapeToml(title)}"`,
|
|
465
|
+
`description = "${escapeToml(description)}"`,
|
|
466
|
+
`size = ${size.toString()}`,
|
|
467
|
+
`token_count = 0`,
|
|
468
|
+
`heading_token_count = 0`,
|
|
469
|
+
`body_token_count = 0`,
|
|
470
|
+
`code_token_count = 0`,
|
|
471
|
+
`created_at = 0`,
|
|
472
|
+
`checksum = "${escapeToml(kbid)}"`,
|
|
473
|
+
""
|
|
474
|
+
].join("\n");
|
|
475
|
+
return `${header}
|
|
476
|
+
---
|
|
477
|
+
${content}`;
|
|
478
|
+
}
|
|
479
|
+
function installSkill(sectionsDir, skill) {
|
|
480
|
+
const content = JSON.stringify({
|
|
481
|
+
name: skill.name,
|
|
482
|
+
description: skill.description,
|
|
483
|
+
arguments: [],
|
|
484
|
+
body: skill.body
|
|
485
|
+
});
|
|
486
|
+
const kbid = computeSectionKbid("text/markdown", content);
|
|
487
|
+
const prefix = kbid.slice(0, 2);
|
|
488
|
+
const shardDir = join3(sectionsDir, prefix);
|
|
489
|
+
const filePath = join3(shardDir, `${kbid}.section`);
|
|
490
|
+
if (existsSync2(filePath)) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
mkdirSync(shardDir, { recursive: true });
|
|
494
|
+
const fileContent = serializeSkillSection(
|
|
495
|
+
kbid,
|
|
496
|
+
skill.name,
|
|
497
|
+
skill.description,
|
|
498
|
+
content
|
|
499
|
+
);
|
|
500
|
+
writeFileSync(filePath, fileContent, "utf-8");
|
|
501
|
+
}
|
|
502
|
+
var QUERY_GUIDANCE_BODY = 'This knowledge base uses lexical search (stemmed BM25F), not semantic/vector search. Follow these guidelines for effective retrieval:\n\n1. Issue MULTIPLE short keyword queries rather than one long natural-language question. Each query should target 2-3 specific terms.\n\n2. EXPAND SYNONYMS yourself. "login" will not match "sign-in" unless both terms appear in the content. Try alternative phrasings: search for "login", then "sign-in", then "authentication".\n\n3. USE BOOLEAN AND PHRASE SYNTAX:\n - Exact phrases: "error handling"\n - Boolean AND: auth AND token\n - Boolean OR: cache OR redis\n - Exclusion: auth -oauth\n\n4. LEAN ON HEADINGS. Headings carry 2x weight in ranking. Search for terms that are likely in section titles.\n\n5. STEMMING IS AUTOMATIC. "connections" matches "connect", "running" matches "run". You do not need to try inflected forms.\n\n6. USE RECALL AFTER SEARCH. After finding relevant sections with search, use recall with increasing depth (0-3) to progressively expand context: depth 0 = full content, depth 1 = parent documents + back-references, depth 2 = siblings + forward references, depth 3 = referenced sections.\n\n7. CODE IDENTIFIERS ARE SPLIT. camelCase and snake_case names are decomposed: getUserById becomes searchable as "get", "user", "by", "id".\n\n8. PAGINATION. Default limit is 20 results. Use offset for additional pages if total > limit.';
|
|
503
|
+
var MEMORY_PROTOCOL_BODY = "Follow these guidelines to keep the knowledge base accurate and useful:\n\n1. STORE DURABLE FACTS: decisions, architecture choices, configuration values, corrections to prior knowledge, API contracts, and resolved incidents. These are the facts that matter weeks later.\n\n2. DO NOT STORE: transient conversation context, debugging output, ephemeral task state, raw log dumps, or information that changes every session. The brain should contain knowledge, not activity logs.\n\n3. SEARCH BEFORE STORING. Always search the knowledge base before adding new content. If a section already covers the topic, use learn with --replace to update it rather than creating a duplicate.\n\n4. USE --replace FOR CORRECTIONS. When a fact changes (e.g., rate limit updated from 100 to 200 req/min), re-learn the corrected content with --replace so the old version is superseded. Without --replace, both the old and new versions coexist with equal ranking.\n\n5. ATTACH TAGS for scoping. Use tags like project name, domain, or topic (e.g., --tags auth,api,v2) so queries can be filtered by scope later.\n\n6. PREFER RECENT RESULTS. When search returns multiple sections covering the same topic, prefer the one with the most recent created_at timestamp -- it is more likely to reflect the current state.\n\n7. USE RECALL AFTER SEARCH. After finding relevant sections, use recall with increasing depth (0-3) to expand context progressively before making decisions.\n\n8. INCLUDE HEADINGS. Always provide a descriptive title when storing content. Headings carry 2x ranking weight -- omitting them significantly reduces searchability.";
|
|
504
|
+
var DEFAULT_SKILLS = [
|
|
505
|
+
{
|
|
506
|
+
name: "query-guidance",
|
|
507
|
+
description: "How to effectively search this knowledge base. Read this before issuing search queries.",
|
|
508
|
+
body: QUERY_GUIDANCE_BODY
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
name: "memory-protocol",
|
|
512
|
+
description: "Guidelines for what to store in this knowledge base and when. Read this before using the learn tool.",
|
|
513
|
+
body: MEMORY_PROTOCOL_BODY
|
|
514
|
+
}
|
|
515
|
+
];
|
|
516
|
+
function installDefaultSkills(dbDir) {
|
|
517
|
+
const sectionsDir = join3(dbDir, "sections");
|
|
518
|
+
for (const skill of DEFAULT_SKILLS) {
|
|
519
|
+
installSkill(sectionsDir, skill);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// src/shared/cli/functions/run-init.function.ts
|
|
330
524
|
var DB_FORMAT_VERSION = 1;
|
|
331
525
|
var CATALOG_TOML = `version = ${DB_FORMAT_VERSION.toString()}
|
|
332
526
|
section_count = 0
|
|
@@ -344,21 +538,21 @@ var GITIGNORE = [
|
|
|
344
538
|
""
|
|
345
539
|
].join("\n");
|
|
346
540
|
function createScaffold(dbDir) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
541
|
+
mkdirSync2(dbDir, { recursive: true });
|
|
542
|
+
mkdirSync2(join4(dbDir, "sections"));
|
|
543
|
+
mkdirSync2(join4(dbDir, "documents"));
|
|
544
|
+
writeFileSync2(join4(dbDir, "catalog.toml"), CATALOG_TOML);
|
|
545
|
+
writeFileSync2(join4(dbDir, "corpus.bin"), "");
|
|
546
|
+
writeFileSync2(join4(dbDir, "inverted.idx"), "");
|
|
547
|
+
writeFileSync2(join4(dbDir, "positional.idx"), "");
|
|
548
|
+
writeFileSync2(join4(dbDir, "worker.toml"), WORKER_TOML);
|
|
549
|
+
writeFileSync2(join4(dbDir, ".gitignore"), GITIGNORE);
|
|
356
550
|
}
|
|
357
551
|
function runInit(options) {
|
|
358
552
|
const basePath = options.dbPath ? resolve2(options.dbPath) : process.cwd();
|
|
359
|
-
const dbDir =
|
|
553
|
+
const dbDir = join4(basePath, ".kbdb");
|
|
360
554
|
try {
|
|
361
|
-
if (
|
|
555
|
+
if (existsSync3(dbDir)) {
|
|
362
556
|
return {
|
|
363
557
|
ok: false,
|
|
364
558
|
targetPath: dbDir,
|
|
@@ -366,6 +560,7 @@ function runInit(options) {
|
|
|
366
560
|
};
|
|
367
561
|
}
|
|
368
562
|
createScaffold(dbDir);
|
|
563
|
+
installDefaultSkills(dbDir);
|
|
369
564
|
return { ok: true, targetPath: dbDir };
|
|
370
565
|
} catch (err) {
|
|
371
566
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
@@ -723,6 +918,8 @@ async function dispatchCommand(client, options, io) {
|
|
|
723
918
|
return handleUnlearn(client, options);
|
|
724
919
|
case "search":
|
|
725
920
|
return handleSearch(client, options);
|
|
921
|
+
case "recall":
|
|
922
|
+
return handleRecall(client, options);
|
|
726
923
|
case "content":
|
|
727
924
|
return handleContent(client, options);
|
|
728
925
|
case "check":
|
|
@@ -733,6 +930,8 @@ async function dispatchCommand(client, options, io) {
|
|
|
733
930
|
return handleRebuild(client, options);
|
|
734
931
|
case "status":
|
|
735
932
|
return handleStatus(client, options);
|
|
933
|
+
case "export":
|
|
934
|
+
return handleExport(client, options);
|
|
736
935
|
case "db-init":
|
|
737
936
|
return handleDbInit(options);
|
|
738
937
|
case "db-migrate":
|
|
@@ -821,6 +1020,40 @@ async function handleSearch(client, options) {
|
|
|
821
1020
|
};
|
|
822
1021
|
}
|
|
823
1022
|
}
|
|
1023
|
+
async function handleRecall(client, options) {
|
|
1024
|
+
try {
|
|
1025
|
+
const result = await runRecall(client, options);
|
|
1026
|
+
if ("error" in result) {
|
|
1027
|
+
return {
|
|
1028
|
+
error: `error: ${result.error}`,
|
|
1029
|
+
exitCode: 1
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
return {
|
|
1033
|
+
output: JSON.stringify(result, null, 2),
|
|
1034
|
+
exitCode: 0
|
|
1035
|
+
};
|
|
1036
|
+
} catch (err) {
|
|
1037
|
+
return {
|
|
1038
|
+
error: `recall failed: ${errorToMessage(err)}`,
|
|
1039
|
+
exitCode: 1
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
async function handleExport(client, options) {
|
|
1044
|
+
try {
|
|
1045
|
+
const result = await runExport(client, options);
|
|
1046
|
+
return {
|
|
1047
|
+
output: JSON.stringify(result, null, 2),
|
|
1048
|
+
exitCode: 0
|
|
1049
|
+
};
|
|
1050
|
+
} catch (err) {
|
|
1051
|
+
return {
|
|
1052
|
+
error: `export failed: ${errorToMessage(err)}`,
|
|
1053
|
+
exitCode: 1
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
824
1057
|
async function handleContent(client, options) {
|
|
825
1058
|
try {
|
|
826
1059
|
const result = await runContent(client, options);
|
|
@@ -928,11 +1161,13 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
928
1161
|
"learn",
|
|
929
1162
|
"unlearn",
|
|
930
1163
|
"search",
|
|
1164
|
+
"recall",
|
|
931
1165
|
"content",
|
|
932
1166
|
"check",
|
|
933
1167
|
"gc",
|
|
934
1168
|
"rebuild",
|
|
935
1169
|
"status",
|
|
1170
|
+
"export",
|
|
936
1171
|
"mcp",
|
|
937
1172
|
"db",
|
|
938
1173
|
"skill",
|
|
@@ -995,6 +1230,7 @@ Knowledge Base:
|
|
|
995
1230
|
learn Import content from files/stdin
|
|
996
1231
|
unlearn Remove sections by kbid
|
|
997
1232
|
search Query the knowledge base
|
|
1233
|
+
recall Retrieve section context by kbid
|
|
998
1234
|
content Compose rendered content from ids
|
|
999
1235
|
|
|
1000
1236
|
Database:
|
|
@@ -1007,6 +1243,7 @@ Maintenance:
|
|
|
1007
1243
|
sections
|
|
1008
1244
|
rebuild Reconstruct all index files
|
|
1009
1245
|
status Show database status
|
|
1246
|
+
export Snapshot database for backup
|
|
1010
1247
|
|
|
1011
1248
|
Skills:
|
|
1012
1249
|
skill learn Create a new skill definition
|
|
@@ -1079,14 +1316,18 @@ Options:
|
|
|
1079
1316
|
--title <title> Section title
|
|
1080
1317
|
--description <d> Section description
|
|
1081
1318
|
--docid <docid> Document ID to group under
|
|
1319
|
+
--tags <t,...> Comma-separated tags
|
|
1320
|
+
--replace Supersede existing section by source key
|
|
1082
1321
|
--db <path> Path to .kbdb directory
|
|
1083
1322
|
|
|
1084
1323
|
Output:
|
|
1085
|
-
JSON array of { kbid, path, size, skipped
|
|
1324
|
+
JSON array of { kbid, path, size, skipped,
|
|
1325
|
+
superseded, warnings, near_duplicates }
|
|
1086
1326
|
|
|
1087
1327
|
Examples:
|
|
1088
1328
|
kbdb learn README.md
|
|
1089
1329
|
kbdb learn ./docs/
|
|
1330
|
+
kbdb learn --tags auth,api --replace doc.md
|
|
1090
1331
|
cat notes.txt | kbdb learn -
|
|
1091
1332
|
`,
|
|
1092
1333
|
unlearn: `kbdb unlearn - Remove sections by kbid
|
|
@@ -1127,6 +1368,25 @@ Examples:
|
|
|
1127
1368
|
kbdb search "machine learning"
|
|
1128
1369
|
kbdb search --limit 5 --format text query
|
|
1129
1370
|
kbdb search --mode documents --content term
|
|
1371
|
+
`,
|
|
1372
|
+
recall: `kbdb recall - Retrieve section context by kbid
|
|
1373
|
+
|
|
1374
|
+
Usage: kbdb recall [options] <kbid>...
|
|
1375
|
+
|
|
1376
|
+
Arguments:
|
|
1377
|
+
<kbid> 26-character knowledge base identifier
|
|
1378
|
+
|
|
1379
|
+
Options:
|
|
1380
|
+
--depth <n>, -d Expansion depth (0-3, default: 0)
|
|
1381
|
+
--tags <t,...> Filter by tags
|
|
1382
|
+
--db <path> Path to .kbdb directory
|
|
1383
|
+
|
|
1384
|
+
Output:
|
|
1385
|
+
JSON RecallResult or RecallResult[]
|
|
1386
|
+
|
|
1387
|
+
Examples:
|
|
1388
|
+
kbdb recall abcdef1234567890abcdef1234
|
|
1389
|
+
kbdb recall kbid1 --depth 2
|
|
1130
1390
|
`,
|
|
1131
1391
|
content: `kbdb content - Compose rendered content from ids
|
|
1132
1392
|
|
|
@@ -1200,6 +1460,25 @@ Output:
|
|
|
1200
1460
|
Examples:
|
|
1201
1461
|
kbdb status
|
|
1202
1462
|
kbdb status --db /path/to/project
|
|
1463
|
+
`,
|
|
1464
|
+
export: `kbdb export - Snapshot database for backup
|
|
1465
|
+
|
|
1466
|
+
Usage: kbdb export [options] [<path>]
|
|
1467
|
+
|
|
1468
|
+
Arguments:
|
|
1469
|
+
<path> Output directory path
|
|
1470
|
+
(default: ./kbdb-export/)
|
|
1471
|
+
|
|
1472
|
+
Options:
|
|
1473
|
+
--db <path> Path to .kbdb directory
|
|
1474
|
+
|
|
1475
|
+
Output:
|
|
1476
|
+
JSON { path, sections_exported, documents_exported }
|
|
1477
|
+
|
|
1478
|
+
Examples:
|
|
1479
|
+
kbdb export
|
|
1480
|
+
kbdb export ./my-backup
|
|
1481
|
+
kbdb export --db /path/to/project
|
|
1203
1482
|
`,
|
|
1204
1483
|
mcp: `kbdb mcp - Start MCP server mode (stdio)
|
|
1205
1484
|
|
|
@@ -1870,6 +2149,23 @@ var WorkerClient = class {
|
|
|
1870
2149
|
docType
|
|
1871
2150
|
});
|
|
1872
2151
|
}
|
|
2152
|
+
/**
|
|
2153
|
+
* Exports the database to a target directory on disk.
|
|
2154
|
+
*
|
|
2155
|
+
* Copies section files, document manifests, and `catalog.toml`
|
|
2156
|
+
* to `params.path`. Index files are not exported because they
|
|
2157
|
+
* are derivable from the section and document data.
|
|
2158
|
+
*
|
|
2159
|
+
* @param params - optional export parameters
|
|
2160
|
+
* @param params.path - target directory path; defaults to
|
|
2161
|
+
* `./kbdb-export/` when not provided
|
|
2162
|
+
* @returns export report with the resolved path and file counts
|
|
2163
|
+
*/
|
|
2164
|
+
async export(params) {
|
|
2165
|
+
return this.call("export", {
|
|
2166
|
+
targetPath: params?.path || void 0
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
1873
2169
|
/**
|
|
1874
2170
|
* Sends a JSON-RPC 2.0 request and awaits the response.
|
|
1875
2171
|
*
|
|
@@ -1927,17 +2223,17 @@ var WorkerClient = class {
|
|
|
1927
2223
|
};
|
|
1928
2224
|
|
|
1929
2225
|
// src/shared/worker-client/functions/create-worker-client.function.ts
|
|
1930
|
-
import { existsSync as
|
|
1931
|
-
import { join as
|
|
2226
|
+
import { existsSync as existsSync7, readFileSync as readFileSync3, unlinkSync as unlinkSync2 } from "node:fs";
|
|
2227
|
+
import { join as join8 } from "node:path";
|
|
1932
2228
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
1933
2229
|
|
|
1934
2230
|
// src/shared/worker-client/functions/resolve-db-path.function.ts
|
|
1935
|
-
import { existsSync as
|
|
1936
|
-
import { join as
|
|
2231
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
2232
|
+
import { join as join5, resolve as resolve3 } from "node:path";
|
|
1937
2233
|
function resolveDbPath(targetDir) {
|
|
1938
2234
|
const base = targetDir ? resolve3(targetDir) : process.cwd();
|
|
1939
|
-
const dbPath =
|
|
1940
|
-
if (!
|
|
2235
|
+
const dbPath = join5(base, ".kbdb");
|
|
2236
|
+
if (!existsSync4(dbPath)) {
|
|
1941
2237
|
throw new Error(`database not found: ${dbPath}`);
|
|
1942
2238
|
}
|
|
1943
2239
|
return dbPath;
|
|
@@ -1950,8 +2246,8 @@ async function computeContextId(absolutePath) {
|
|
|
1950
2246
|
}
|
|
1951
2247
|
|
|
1952
2248
|
// src/shared/worker-client/functions/discover-daemon.function.ts
|
|
1953
|
-
import { existsSync as
|
|
1954
|
-
import { join as
|
|
2249
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2, unlinkSync } from "node:fs";
|
|
2250
|
+
import { join as join6 } from "node:path";
|
|
1955
2251
|
import { tmpdir } from "node:os";
|
|
1956
2252
|
|
|
1957
2253
|
// src/shared/platform/functions/is-process-alive.function.ts
|
|
@@ -1966,8 +2262,8 @@ function isProcessAlive(pid) {
|
|
|
1966
2262
|
|
|
1967
2263
|
// src/shared/worker-client/functions/discover-daemon.function.ts
|
|
1968
2264
|
function discoverDaemon(contextId) {
|
|
1969
|
-
const pidPath =
|
|
1970
|
-
if (!
|
|
2265
|
+
const pidPath = join6(tmpdir(), `kbdb-${contextId}.pid`);
|
|
2266
|
+
if (!existsSync5(pidPath)) return null;
|
|
1971
2267
|
const pidStr = readFileSync2(pidPath, "utf-8").trim();
|
|
1972
2268
|
const pid = parseInt(pidStr, 10);
|
|
1973
2269
|
if (isNaN(pid) || !isProcessAlive(pid)) {
|
|
@@ -1977,8 +2273,8 @@ function discoverDaemon(contextId) {
|
|
|
1977
2273
|
}
|
|
1978
2274
|
return null;
|
|
1979
2275
|
}
|
|
1980
|
-
const socketPath =
|
|
1981
|
-
const crashPath =
|
|
2276
|
+
const socketPath = join6(tmpdir(), `kbdb-${contextId}.sock`);
|
|
2277
|
+
const crashPath = join6(tmpdir(), `kbdb-${contextId}.crash`);
|
|
1982
2278
|
try {
|
|
1983
2279
|
unlinkSync(crashPath);
|
|
1984
2280
|
} catch {
|
|
@@ -2004,16 +2300,16 @@ function spawnDaemon(contextPath, runtime2, workerScript2) {
|
|
|
2004
2300
|
}
|
|
2005
2301
|
|
|
2006
2302
|
// src/shared/worker-client/functions/wait-for-daemon.function.ts
|
|
2007
|
-
import { existsSync as
|
|
2008
|
-
import { join as
|
|
2303
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
2304
|
+
import { join as join7 } from "node:path";
|
|
2009
2305
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
2010
2306
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
2011
2307
|
var POLL_INTERVAL_MS = 100;
|
|
2012
2308
|
async function waitForDaemon(contextId, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
2013
|
-
const pidPath =
|
|
2309
|
+
const pidPath = join7(tmpdir2(), `kbdb-${contextId}.pid`);
|
|
2014
2310
|
const start = Date.now();
|
|
2015
2311
|
while (Date.now() - start < timeoutMs) {
|
|
2016
|
-
if (
|
|
2312
|
+
if (existsSync6(pidPath)) return true;
|
|
2017
2313
|
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
2018
2314
|
}
|
|
2019
2315
|
return false;
|
|
@@ -2041,8 +2337,8 @@ async function createWorkerClient(options) {
|
|
|
2041
2337
|
return client;
|
|
2042
2338
|
}
|
|
2043
2339
|
function readCrashReason(contextId) {
|
|
2044
|
-
const crashPath =
|
|
2045
|
-
if (!
|
|
2340
|
+
const crashPath = join8(tmpdir3(), `kbdb-${contextId}.crash`);
|
|
2341
|
+
if (!existsSync7(crashPath)) {
|
|
2046
2342
|
return "daemon failed to start (no details available)";
|
|
2047
2343
|
}
|
|
2048
2344
|
try {
|
|
@@ -2063,7 +2359,7 @@ function createToolDefinitions() {
|
|
|
2063
2359
|
return [
|
|
2064
2360
|
{
|
|
2065
2361
|
name: "search",
|
|
2066
|
-
description: "
|
|
2362
|
+
description: "Query the knowledge base by keywords. Returns ranked results with heading, snippet, and matched terms. Use multiple short keyword queries for best coverage. Use recall to get full content.",
|
|
2067
2363
|
inputSchema: {
|
|
2068
2364
|
type: "object",
|
|
2069
2365
|
properties: {
|
|
@@ -2083,6 +2379,11 @@ function createToolDefinitions() {
|
|
|
2083
2379
|
offset: {
|
|
2084
2380
|
type: "number",
|
|
2085
2381
|
description: "Number of results to skip for pagination (default: 0)"
|
|
2382
|
+
},
|
|
2383
|
+
algo: {
|
|
2384
|
+
type: "string",
|
|
2385
|
+
enum: ["lexical", "vector", "hybrid"],
|
|
2386
|
+
description: "Search algorithm (default: lexical)"
|
|
2086
2387
|
}
|
|
2087
2388
|
},
|
|
2088
2389
|
required: ["query"]
|
|
@@ -2097,7 +2398,7 @@ function createToolDefinitions() {
|
|
|
2097
2398
|
},
|
|
2098
2399
|
{
|
|
2099
2400
|
name: "learn",
|
|
2100
|
-
description: "
|
|
2401
|
+
description: "Import content into the knowledge base. Use for durable facts, decisions, and corrections. Use replace when updating existing knowledge. Attach tags for scoping.",
|
|
2101
2402
|
inputSchema: {
|
|
2102
2403
|
type: "object",
|
|
2103
2404
|
properties: {
|
|
@@ -2120,6 +2421,15 @@ function createToolDefinitions() {
|
|
|
2120
2421
|
docid: {
|
|
2121
2422
|
type: "string",
|
|
2122
2423
|
description: "Document ID to group under"
|
|
2424
|
+
},
|
|
2425
|
+
tags: {
|
|
2426
|
+
type: "array",
|
|
2427
|
+
items: { type: "string" },
|
|
2428
|
+
description: "Tags for scoping and filtering"
|
|
2429
|
+
},
|
|
2430
|
+
replace: {
|
|
2431
|
+
type: "boolean",
|
|
2432
|
+
description: "Replace existing section with same source key (supersession)"
|
|
2123
2433
|
}
|
|
2124
2434
|
},
|
|
2125
2435
|
required: ["content"]
|
|
@@ -2288,6 +2598,26 @@ function createToolDefinitions() {
|
|
|
2288
2598
|
openWorldHint: false
|
|
2289
2599
|
}
|
|
2290
2600
|
},
|
|
2601
|
+
{
|
|
2602
|
+
name: "export",
|
|
2603
|
+
description: "Export the database as a self-contained directory snapshot (sections, documents, catalog -- no indexes).",
|
|
2604
|
+
inputSchema: {
|
|
2605
|
+
type: "object",
|
|
2606
|
+
properties: {
|
|
2607
|
+
path: {
|
|
2608
|
+
type: "string",
|
|
2609
|
+
description: "Export destination path (default: ./kbdb-export/)"
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
},
|
|
2613
|
+
annotations: {
|
|
2614
|
+
title: "Export Snapshot",
|
|
2615
|
+
readOnlyHint: false,
|
|
2616
|
+
destructiveHint: false,
|
|
2617
|
+
idempotentHint: true,
|
|
2618
|
+
openWorldHint: false
|
|
2619
|
+
}
|
|
2620
|
+
},
|
|
2291
2621
|
{
|
|
2292
2622
|
name: "skill-learn",
|
|
2293
2623
|
description: "Create or update a skill definition. Skills are reusable AI agent capabilities with template placeholders.",
|
|
@@ -2467,6 +2797,27 @@ function createToolDefinitions() {
|
|
|
2467
2797
|
idempotentHint: true,
|
|
2468
2798
|
openWorldHint: false
|
|
2469
2799
|
}
|
|
2800
|
+
},
|
|
2801
|
+
{
|
|
2802
|
+
name: "auto-capture-review",
|
|
2803
|
+
description: "Review and approve pending auto-captured knowledge before storage.",
|
|
2804
|
+
inputSchema: {
|
|
2805
|
+
type: "object",
|
|
2806
|
+
properties: {
|
|
2807
|
+
action: {
|
|
2808
|
+
type: "string",
|
|
2809
|
+
enum: ["list", "approve", "reject"],
|
|
2810
|
+
description: "Action to perform on pending captures"
|
|
2811
|
+
}
|
|
2812
|
+
}
|
|
2813
|
+
},
|
|
2814
|
+
annotations: {
|
|
2815
|
+
title: "Auto-Capture Review",
|
|
2816
|
+
readOnlyHint: false,
|
|
2817
|
+
destructiveHint: false,
|
|
2818
|
+
idempotentHint: true,
|
|
2819
|
+
openWorldHint: false
|
|
2820
|
+
}
|
|
2470
2821
|
}
|
|
2471
2822
|
];
|
|
2472
2823
|
}
|
|
@@ -2540,7 +2891,7 @@ async function handleAgentCreate(client, args) {
|
|
|
2540
2891
|
description
|
|
2541
2892
|
});
|
|
2542
2893
|
const allKbids = [metaResult.kbid, ...skills];
|
|
2543
|
-
const docid = await client.groupSections(name, allKbids);
|
|
2894
|
+
const docid = await client.groupSections(name, allKbids, "agent");
|
|
2544
2895
|
return {
|
|
2545
2896
|
content: [
|
|
2546
2897
|
{
|
|
@@ -2667,7 +3018,7 @@ async function handleAgentDelete(client, args) {
|
|
|
2667
3018
|
}
|
|
2668
3019
|
|
|
2669
3020
|
// src/shared/mcp/functions/handle-recall.function.ts
|
|
2670
|
-
async function
|
|
3021
|
+
async function handleRecall2(client, args) {
|
|
2671
3022
|
const kbid = typeof args["kbid"] === "string" ? args["kbid"] : void 0;
|
|
2672
3023
|
const kbids = Array.isArray(args["kbids"]) && args["kbids"].every((item) => typeof item === "string") ? args["kbids"] : void 0;
|
|
2673
3024
|
if (!kbid && !kbids) {
|
|
@@ -2697,6 +3048,15 @@ async function handleRecall(client, args) {
|
|
|
2697
3048
|
function asString2(value, fallback) {
|
|
2698
3049
|
return typeof value === "string" ? value : fallback;
|
|
2699
3050
|
}
|
|
3051
|
+
function asBooleanOrUndefined(value) {
|
|
3052
|
+
return typeof value === "boolean" ? value : void 0;
|
|
3053
|
+
}
|
|
3054
|
+
function asStringArrayOrUndefined(value) {
|
|
3055
|
+
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
3056
|
+
return value;
|
|
3057
|
+
}
|
|
3058
|
+
return void 0;
|
|
3059
|
+
}
|
|
2700
3060
|
function asStringArray2(value) {
|
|
2701
3061
|
if (Array.isArray(value) && value.every((item) => typeof item === "string")) {
|
|
2702
3062
|
return value;
|
|
@@ -2715,7 +3075,7 @@ async function handleToolCall(client, name, args) {
|
|
|
2715
3075
|
case "retrieve":
|
|
2716
3076
|
return await handleRetrieve(client, args);
|
|
2717
3077
|
case "recall":
|
|
2718
|
-
return await
|
|
3078
|
+
return await handleRecall2(client, args);
|
|
2719
3079
|
case "status":
|
|
2720
3080
|
return await handleStatus2(client);
|
|
2721
3081
|
case "content":
|
|
@@ -2726,6 +3086,8 @@ async function handleToolCall(client, name, args) {
|
|
|
2726
3086
|
return await handleGc2(client);
|
|
2727
3087
|
case "rebuild":
|
|
2728
3088
|
return await handleRebuild2(client);
|
|
3089
|
+
case "export":
|
|
3090
|
+
return await handleExport2(client, args);
|
|
2729
3091
|
case "skill-learn":
|
|
2730
3092
|
return await handleSkillLearn(client, args);
|
|
2731
3093
|
case "skill-list":
|
|
@@ -2742,6 +3104,8 @@ async function handleToolCall(client, name, args) {
|
|
|
2742
3104
|
return await handleAgentGet(client, args);
|
|
2743
3105
|
case "agent-delete":
|
|
2744
3106
|
return await handleAgentDelete(client, args);
|
|
3107
|
+
case "auto-capture-review":
|
|
3108
|
+
return handleAutoCaptureReview();
|
|
2745
3109
|
default:
|
|
2746
3110
|
return {
|
|
2747
3111
|
content: [
|
|
@@ -2770,11 +3134,18 @@ async function handleSearch2(client, args) {
|
|
|
2770
3134
|
query: asString2(args["query"], ""),
|
|
2771
3135
|
mode: args["mode"],
|
|
2772
3136
|
limit: args["limit"],
|
|
2773
|
-
offset: args["offset"]
|
|
3137
|
+
offset: args["offset"],
|
|
3138
|
+
algo: args["algo"]
|
|
2774
3139
|
});
|
|
2775
3140
|
const stripped = {
|
|
2776
3141
|
...results,
|
|
2777
|
-
items: results.items.map(
|
|
3142
|
+
items: results.items.map(
|
|
3143
|
+
({
|
|
3144
|
+
score: _score,
|
|
3145
|
+
confidence: _confidence,
|
|
3146
|
+
...rest
|
|
3147
|
+
}) => rest
|
|
3148
|
+
)
|
|
2778
3149
|
};
|
|
2779
3150
|
return {
|
|
2780
3151
|
content: [
|
|
@@ -2790,6 +3161,8 @@ async function handleLearn2(client, args) {
|
|
|
2790
3161
|
const title = typeof args["title"] === "string" ? args["title"] : void 0;
|
|
2791
3162
|
const description = typeof args["description"] === "string" ? args["description"] : void 0;
|
|
2792
3163
|
const docid = typeof args["docid"] === "string" ? args["docid"] : void 0;
|
|
3164
|
+
const tags = asStringArrayOrUndefined(args["tags"]);
|
|
3165
|
+
const replace = asBooleanOrUndefined(args["replace"]);
|
|
2793
3166
|
if (sectionType.startsWith("image/") && !title) {
|
|
2794
3167
|
return {
|
|
2795
3168
|
content: [
|
|
@@ -2806,13 +3179,27 @@ async function handleLearn2(client, args) {
|
|
|
2806
3179
|
content: asString2(args["content"], ""),
|
|
2807
3180
|
title,
|
|
2808
3181
|
description,
|
|
2809
|
-
docid
|
|
3182
|
+
docid,
|
|
3183
|
+
tags,
|
|
3184
|
+
replace
|
|
2810
3185
|
});
|
|
3186
|
+
const normalized = {
|
|
3187
|
+
kbid: result.kbid,
|
|
3188
|
+
indexed_terms_count: result.indexed_terms_count ?? 0,
|
|
3189
|
+
elapsed_ms: result.elapsed_ms ?? 0,
|
|
3190
|
+
superseded: result.superseded ?? null,
|
|
3191
|
+
warnings: result.warnings ?? [],
|
|
3192
|
+
near_duplicates: (result.near_duplicates ?? []).map((d) => ({
|
|
3193
|
+
kbid: d.kbid,
|
|
3194
|
+
similarity: d.similarity,
|
|
3195
|
+
...d.method !== void 0 ? { method: d.method } : {}
|
|
3196
|
+
}))
|
|
3197
|
+
};
|
|
2811
3198
|
return {
|
|
2812
3199
|
content: [
|
|
2813
3200
|
{
|
|
2814
3201
|
type: "text",
|
|
2815
|
-
text: JSON.stringify(
|
|
3202
|
+
text: JSON.stringify(normalized)
|
|
2816
3203
|
}
|
|
2817
3204
|
]
|
|
2818
3205
|
};
|
|
@@ -3053,6 +3440,33 @@ async function handleSkillDelete(client, args) {
|
|
|
3053
3440
|
]
|
|
3054
3441
|
};
|
|
3055
3442
|
}
|
|
3443
|
+
function handleAutoCaptureReview() {
|
|
3444
|
+
return {
|
|
3445
|
+
content: [
|
|
3446
|
+
{
|
|
3447
|
+
type: "text",
|
|
3448
|
+
text: JSON.stringify({
|
|
3449
|
+
pending: [],
|
|
3450
|
+
message: "No pending auto-captured knowledge entries."
|
|
3451
|
+
})
|
|
3452
|
+
}
|
|
3453
|
+
]
|
|
3454
|
+
};
|
|
3455
|
+
}
|
|
3456
|
+
async function handleExport2(client, args) {
|
|
3457
|
+
const path = typeof args["path"] === "string" ? args["path"] : void 0;
|
|
3458
|
+
const result = await client.export(
|
|
3459
|
+
path !== void 0 ? { path } : {}
|
|
3460
|
+
);
|
|
3461
|
+
return {
|
|
3462
|
+
content: [
|
|
3463
|
+
{
|
|
3464
|
+
type: "text",
|
|
3465
|
+
text: JSON.stringify(result)
|
|
3466
|
+
}
|
|
3467
|
+
]
|
|
3468
|
+
};
|
|
3469
|
+
}
|
|
3056
3470
|
|
|
3057
3471
|
// src/shared/mcp/functions/handle-resource-read.function.ts
|
|
3058
3472
|
async function handleResourceRead(client, uri) {
|
|
@@ -3149,8 +3563,12 @@ function buildSkillsText(skillSections) {
|
|
|
3149
3563
|
${lines.join("\n")}`;
|
|
3150
3564
|
}
|
|
3151
3565
|
async function handleAgentPrompt(name, client) {
|
|
3152
|
-
const
|
|
3153
|
-
const
|
|
3566
|
+
const agentName = name.slice(6);
|
|
3567
|
+
const agents = await client.listDocumentsByType("agent");
|
|
3568
|
+
const doc = agents.find((a) => a.title === agentName);
|
|
3569
|
+
if (!doc) {
|
|
3570
|
+
throw new Error("agent not found: " + agentName);
|
|
3571
|
+
}
|
|
3154
3572
|
const sections = doc.sections;
|
|
3155
3573
|
const metaSection = sections.at(0);
|
|
3156
3574
|
const skillRefs = sections.slice(1);
|
|
@@ -3308,13 +3726,16 @@ var McpServer = class {
|
|
|
3308
3726
|
input: process.stdin,
|
|
3309
3727
|
terminal: false
|
|
3310
3728
|
});
|
|
3729
|
+
let pending = Promise.resolve();
|
|
3311
3730
|
await new Promise((resolve4) => {
|
|
3312
3731
|
rl.on("line", (line) => {
|
|
3313
|
-
|
|
3732
|
+
pending = pending.then(() => this.dispatchLine(line));
|
|
3314
3733
|
});
|
|
3315
3734
|
rl.on("close", () => {
|
|
3316
|
-
|
|
3317
|
-
|
|
3735
|
+
void pending.then(() => {
|
|
3736
|
+
this.client.disconnect();
|
|
3737
|
+
resolve4();
|
|
3738
|
+
});
|
|
3318
3739
|
});
|
|
3319
3740
|
});
|
|
3320
3741
|
}
|
|
@@ -3424,8 +3845,9 @@ var McpServer = class {
|
|
|
3424
3845
|
const request = parsed;
|
|
3425
3846
|
if (request.id === void 0) {
|
|
3426
3847
|
if (request.method === "notifications/initialized" || request.method === "notifications/cancelled") {
|
|
3427
|
-
if (request.method === "notifications/initialized") {
|
|
3848
|
+
if (request.method === "notifications/initialized" && !this.initialized) {
|
|
3428
3849
|
this.initialized = true;
|
|
3850
|
+
void this.runStartupHealthCheck();
|
|
3429
3851
|
}
|
|
3430
3852
|
}
|
|
3431
3853
|
return null;
|
|
@@ -3618,6 +4040,27 @@ var McpServer = class {
|
|
|
3618
4040
|
const json = JSON.stringify(response);
|
|
3619
4041
|
process.stdout.write(json + "\n");
|
|
3620
4042
|
}
|
|
4043
|
+
/**
|
|
4044
|
+
* Runs an integrity check immediately after the MCP handshake
|
|
4045
|
+
* completes. Emits a `notifications/message` warning when the
|
|
4046
|
+
* check detects issues so the connected agent is aware before
|
|
4047
|
+
* making requests. The server continues operating regardless of
|
|
4048
|
+
* the result.
|
|
4049
|
+
*/
|
|
4050
|
+
async runStartupHealthCheck() {
|
|
4051
|
+
try {
|
|
4052
|
+
const report = await this.client.integrityCheck();
|
|
4053
|
+
if (!report.ok) {
|
|
4054
|
+
const summary = report.errors.map((e) => `${e.type}: ${e.entity} -- ${e.detail}`).join("; ");
|
|
4055
|
+
this.notify("notifications/message", {
|
|
4056
|
+
level: "warning",
|
|
4057
|
+
logger: "kbdb",
|
|
4058
|
+
data: `Database integrity issues detected: ${summary}`
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
} catch {
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
3621
4064
|
};
|
|
3622
4065
|
|
|
3623
4066
|
// src/shared/mcp/functions/create-mcp-server.function.ts
|