@dikolab/kbdb 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -126
- package/dist/chunk-BJPSPNGX.mjs +223 -0
- package/dist/chunk-BJPSPNGX.mjs.map +7 -0
- package/dist/cli.cjs +956 -319
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.d.ts +9 -0
- package/dist/cli.mjs +840 -321
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +714 -94
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +122 -16
- package/dist/mod.cjs.map +3 -3
- package/dist/mod.d.ts +23 -2
- package/dist/mod.mjs +121 -16
- package/dist/mod.mjs.map +3 -3
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -1
- package/dist/src/shared/cli/functions/find-db.function.d.ts +7 -8
- package/dist/src/shared/cli/functions/handle-mcp.function.d.ts +1 -1
- package/dist/src/shared/cli/functions/parse-args.function.d.ts +4 -3
- package/dist/src/shared/cli/functions/resolve-kbid-prefix.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +10 -0
- package/dist/src/shared/cli/functions/run-cli.function.d.ts +3 -1
- package/dist/src/shared/cli/functions/run-content.function.d.ts +8 -3
- package/dist/src/shared/cli/functions/run-import.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/run-recall.function.d.ts +10 -4
- package/dist/src/shared/cli/functions/run-search.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +9 -4
- package/dist/src/shared/cli/functions/run-worker-restart.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/run-worker-stop.function.d.ts +11 -0
- package/dist/src/shared/cli/index.d.ts +2 -0
- package/dist/src/shared/cli/typings/cli-deps.interface.d.ts +4 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +17 -0
- package/dist/src/shared/cli/typings/dispatch-client.type.d.ts +2 -1
- package/dist/src/shared/cli/typings/search-display.model.d.ts +6 -0
- package/dist/src/shared/embedding/classes/api-embedding-provider.class.d.ts +33 -0
- package/dist/src/shared/embedding/classes/onnx-embedding-provider.class.d.ts +33 -0
- package/dist/src/shared/embedding/functions/append-vector-entry.function.d.ts +14 -0
- package/dist/src/shared/embedding/functions/create-embedding-provider.function.d.ts +12 -0
- package/dist/src/shared/embedding/functions/detect-stale-vectors.function.d.ts +16 -0
- package/dist/src/shared/embedding/functions/parse-api-embedding-response.function.d.ts +11 -0
- package/dist/src/shared/embedding/functions/rebuild-vectors.function.d.ts +15 -0
- package/dist/src/shared/embedding/functions/scan-semantic-contradictions.function.d.ts +13 -0
- package/dist/src/shared/embedding/index.d.ts +7 -0
- package/dist/src/shared/embedding/typings/semantic-contradiction.model.d.ts +21 -0
- package/dist/src/shared/embedding/typings/stale-vectors-report.model.d.ts +16 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +22 -2
- package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +6 -1
- package/dist/src/shared/mcp/functions/has-sampling-capability.function.d.ts +8 -0
- package/dist/src/shared/mcp/functions/run-auto-capture.function.d.ts +26 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +2 -0
- package/dist/src/shared/mcp/typings/mcp-integrity-check-result.model.d.ts +24 -0
- package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +3 -1
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/typings/paged-search-result.model.d.ts +2 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +31 -1
- package/dist/src/shared/worker-client/constants/request-timeout.constant.d.ts +2 -0
- package/dist/src/shared/worker-client/constants/retry-defaults.constant.d.ts +2 -0
- package/dist/src/shared/worker-client/functions/get-or-create-client.function.d.ts +20 -0
- package/dist/src/shared/worker-client/functions/retry-on-timeout.function.d.ts +17 -0
- package/dist/src/shared/worker-client/index.d.ts +4 -1
- package/dist/src/shared/worker-client/typings/import-result.model.d.ts +16 -0
- package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +24 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +4 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +6 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +7 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +5 -0
- package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +11 -11
- package/dist/src/shared/worker-daemon/functions/embed-after-learn.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/functions/handle-hybrid-search.function.d.ts +44 -0
- package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +14 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +7 -1
- package/dist/src/shared/worker-daemon/functions/handle-write-ops.function.d.ts +9 -4
- package/dist/src/shared/worker-daemon/typings/handler-context.interface.d.ts +3 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +16 -85
- package/dist/wasm/fs-database/kbdb_fs_database.js +16 -85
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +20 -115
- package/dist/wasm/kb-worker/kbdb_worker.js +20 -115
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.mjs +606 -102
- package/dist/worker.mjs.map +4 -4
- package/docs/details/README.md +4 -0
- package/docs/details/agent-tooling.md +122 -0
- package/docs/details/cli.md +78 -12
- package/docs/details/knowledge-base.md +173 -0
- package/docs/details/library-api.md +42 -2
- package/docs/details/mcp-server.md +39 -8
- package/docs/details/search-and-ranking.md +56 -0
- package/docs/goals/cli.md +110 -34
- package/docs/goals/mcp.md +22 -19
- package/docs/goals/query-parser.md +8 -0
- package/docs/goals/worker-client.md +62 -1
- package/docs/goals/worker-daemon.md +52 -10
- package/docs/modules/typescript/cli.md +1 -1
- package/docs/modules/typescript/shared/cli/functions.md +116 -13
- package/docs/modules/typescript/shared/cli/module.md +33 -20
- package/docs/modules/typescript/shared/cli/typings.md +4 -0
- package/docs/modules/typescript/shared/embedding/functions.md +104 -25
- package/docs/modules/typescript/shared/mcp/module.md +1 -1
- package/docs/modules/typescript/shared/mcp/typings.md +8 -1
- package/docs/modules/typescript/shared/worker-client/module.md +9 -1
- package/docs/modules/typescript/shared/worker-client/typings.md +3 -0
- package/docs/modules/typescript/shared/worker-daemon/module.md +6 -3
- package/docs/overview.md +43 -22
- package/docs/release-notes/0.3.1.md +10 -0
- package/docs/release-notes/0.3.2.md +64 -0
- package/docs/release-notes/0.4.0.md +80 -0
- package/docs/release-notes/README.md +2 -0
- package/mod.ts +33 -15
- package/package.json +11 -10
- package/dist/chunk-JG2UCKLI.mjs +0 -95
- package/dist/chunk-JG2UCKLI.mjs.map +0 -7
- package/src/cli.ts +0 -71
- package/src/shared/auto-capture/classes/auto-capture-controller.class.ts +0 -62
- package/src/shared/auto-capture/constants/auto-capture-defaults.constant.ts +0 -15
- package/src/shared/auto-capture/functions/build-capture-prompt.function.ts +0 -27
- package/src/shared/auto-capture/functions/evaluate-trigger.function.ts +0 -50
- package/src/shared/auto-capture/index.ts +0 -7
- package/src/shared/auto-capture/typings/auto-capture-config.interface.ts +0 -13
- package/src/shared/auto-capture/typings/auto-capture-state.interface.ts +0 -13
- package/src/shared/auto-capture/typings/auto-capture-trigger.interface.ts +0 -7
- package/src/shared/cli/constants/defaults.constant.ts +0 -19
- package/src/shared/cli/constants/global-help.constant.ts +0 -73
- package/src/shared/cli/constants/help-text.constant.ts +0 -4
- package/src/shared/cli/constants/leaf-help.constant.ts +0 -219
- package/src/shared/cli/constants/memory-protocol-body.constant.ts +0 -39
- package/src/shared/cli/constants/query-guidance-body.constant.ts +0 -37
- package/src/shared/cli/constants/subcommand-help.constant.ts +0 -195
- package/src/shared/cli/functions/collect-files.function.ts +0 -55
- package/src/shared/cli/functions/compute-section-kbid.function.ts +0 -49
- package/src/shared/cli/functions/dispatch-command.function.ts +0 -390
- package/src/shared/cli/functions/ensure-db.function.ts +0 -21
- package/src/shared/cli/functions/error-to-message.function.ts +0 -9
- package/src/shared/cli/functions/find-db.function.ts +0 -20
- package/src/shared/cli/functions/format-mcp-output.function.ts +0 -41
- package/src/shared/cli/functions/format-output.function.ts +0 -95
- package/src/shared/cli/functions/format-text-output.function.ts +0 -42
- package/src/shared/cli/functions/generate-group-help.function.ts +0 -41
- package/src/shared/cli/functions/generate-help.function.ts +0 -654
- package/src/shared/cli/functions/handle-data-command.function.ts +0 -67
- package/src/shared/cli/functions/handle-mcp.function.ts +0 -56
- package/src/shared/cli/functions/handle-migrate.function.ts +0 -64
- package/src/shared/cli/functions/hydrate-search-previews.function.ts +0 -29
- package/src/shared/cli/functions/install-default-skills.function.ts +0 -296
- package/src/shared/cli/functions/is-stdin-tty.function.ts +0 -12
- package/src/shared/cli/functions/parse-args.function.ts +0 -156
- package/src/shared/cli/functions/prompt-user.function.ts +0 -36
- package/src/shared/cli/functions/resolve-skill-names.function.ts +0 -43
- package/src/shared/cli/functions/run-agent-create.function.ts +0 -114
- package/src/shared/cli/functions/run-agent-delete.function.ts +0 -47
- package/src/shared/cli/functions/run-agent-get.function.ts +0 -166
- package/src/shared/cli/functions/run-agent-list.function.ts +0 -58
- package/src/shared/cli/functions/run-check.function.ts +0 -159
- package/src/shared/cli/functions/run-cli.function.ts +0 -299
- package/src/shared/cli/functions/run-content.function.ts +0 -47
- package/src/shared/cli/functions/run-db-init.function.ts +0 -44
- package/src/shared/cli/functions/run-db-migrate.function.ts +0 -40
- package/src/shared/cli/functions/run-export.function.ts +0 -40
- package/src/shared/cli/functions/run-gc.function.ts +0 -51
- package/src/shared/cli/functions/run-init.function.ts +0 -93
- package/src/shared/cli/functions/run-learn.function.ts +0 -223
- package/src/shared/cli/functions/run-migrate.function.ts +0 -85
- package/src/shared/cli/functions/run-rebuild.function.ts +0 -47
- package/src/shared/cli/functions/run-recall.function.ts +0 -66
- package/src/shared/cli/functions/run-search.function.ts +0 -133
- package/src/shared/cli/functions/run-skill-delete.function.ts +0 -47
- package/src/shared/cli/functions/run-skill-get.function.ts +0 -90
- package/src/shared/cli/functions/run-skill-learn.function.ts +0 -70
- package/src/shared/cli/functions/run-skill-list.function.ts +0 -74
- package/src/shared/cli/functions/run-status.function.ts +0 -29
- package/src/shared/cli/functions/run-unlearn.function.ts +0 -58
- package/src/shared/cli/functions/version-gate.function.ts +0 -44
- package/src/shared/cli/functions/wrap-command.function.ts +0 -34
- package/src/shared/cli/index.ts +0 -55
- package/src/shared/cli/typings/agent-create-client.interface.ts +0 -47
- package/src/shared/cli/typings/agent-get-client.interface.ts +0 -39
- package/src/shared/cli/typings/check-client.interface.ts +0 -66
- package/src/shared/cli/typings/cli-deps.interface.ts +0 -54
- package/src/shared/cli/typings/cli-options.interface.ts +0 -72
- package/src/shared/cli/typings/command-result.model.ts +0 -15
- package/src/shared/cli/typings/disconnectable-client.interface.ts +0 -29
- package/src/shared/cli/typings/dispatch-client.type.ts +0 -46
- package/src/shared/cli/typings/learn-client.interface.ts +0 -53
- package/src/shared/cli/typings/learn-io.interface.ts +0 -5
- package/src/shared/cli/typings/learn-result.model.ts +0 -27
- package/src/shared/cli/typings/search-client.interface.ts +0 -73
- package/src/shared/cli/typings/search-display.model.ts +0 -54
- package/src/shared/dir-resolver/functions/join-path.function.ts +0 -13
- package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +0 -25
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +0 -5
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +0 -13
- package/src/shared/dir-resolver/index.ts +0 -11
- package/src/shared/dir-resolver/typings/base-dir.interface.ts +0 -4
- package/src/shared/embedding/classes/null-embedding-provider.class.ts +0 -29
- package/src/shared/embedding/constants/near-duplicate-thresholds.constant.ts +0 -17
- package/src/shared/embedding/functions/build-vector-index.function.ts +0 -79
- package/src/shared/embedding/functions/cosine-similarity.function.ts +0 -31
- package/src/shared/embedding/functions/detect-near-duplicates.function.ts +0 -69
- package/src/shared/embedding/functions/jaccard-coefficient.function.ts +0 -26
- package/src/shared/embedding/functions/read-vector-index-meta.function.ts +0 -44
- package/src/shared/embedding/functions/rrf-fuse.function.ts +0 -33
- package/src/shared/embedding/functions/search-vectors.function.ts +0 -59
- package/src/shared/embedding/index.ts +0 -20
- package/src/shared/embedding/typings/embedding-config.interface.ts +0 -23
- package/src/shared/embedding/typings/embedding-provider.interface.ts +0 -25
- package/src/shared/embedding/typings/near-duplicate-candidate.model.ts +0 -25
- package/src/shared/embedding/typings/near-duplicate-result.model.ts +0 -26
- package/src/shared/embedding/typings/vector-index-entry.model.ts +0 -13
- package/src/shared/embedding/typings/vector-index-meta.model.ts +0 -14
- package/src/shared/embedding/typings/vector-search-result.model.ts +0 -8
- package/src/shared/hash/functions/compute-sha256.ts +0 -17
- package/src/shared/hash/index.ts +0 -1
- package/src/shared/mcp/classes/mcp-server.class.ts +0 -480
- package/src/shared/mcp/constants/mcp-error-codes.constant.ts +0 -30
- package/src/shared/mcp/constants/tool-agent-create.constant.ts +0 -39
- package/src/shared/mcp/constants/tool-agent-delete.constant.ts +0 -26
- package/src/shared/mcp/constants/tool-agent-get.constant.ts +0 -24
- package/src/shared/mcp/constants/tool-agent-list.constant.ts +0 -18
- package/src/shared/mcp/constants/tool-auto-capture-review.constant.ts +0 -32
- package/src/shared/mcp/constants/tool-check.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-content.constant.ts +0 -29
- package/src/shared/mcp/constants/tool-export.constant.ts +0 -27
- package/src/shared/mcp/constants/tool-gc.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-learn.constant.ts +0 -58
- package/src/shared/mcp/constants/tool-rebuild.constant.ts +0 -21
- package/src/shared/mcp/constants/tool-recall.constant.ts +0 -36
- package/src/shared/mcp/constants/tool-retrieve.constant.ts +0 -31
- package/src/shared/mcp/constants/tool-search.constant.ts +0 -51
- package/src/shared/mcp/constants/tool-skill-delete.constant.ts +0 -24
- package/src/shared/mcp/constants/tool-skill-get.constant.ts +0 -27
- package/src/shared/mcp/constants/tool-skill-learn.constant.ts +0 -37
- package/src/shared/mcp/constants/tool-skill-list.constant.ts +0 -18
- package/src/shared/mcp/constants/tool-status.constant.ts +0 -20
- package/src/shared/mcp/constants/tool-unlearn.constant.ts +0 -25
- package/src/shared/mcp/functions/as-boolean-or-undefined.function.ts +0 -11
- package/src/shared/mcp/functions/as-string-array-or-undefined.function.ts +0 -17
- package/src/shared/mcp/functions/as-string-array.function.ts +0 -15
- package/src/shared/mcp/functions/as-string.function.ts +0 -10
- package/src/shared/mcp/functions/build-skills-text.function.ts +0 -43
- package/src/shared/mcp/functions/create-mcp-server.function.ts +0 -14
- package/src/shared/mcp/functions/create-prompt-definitions.function.ts +0 -102
- package/src/shared/mcp/functions/create-resource-templates.function.ts +0 -23
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +0 -530
- package/src/shared/mcp/functions/extract-skill-arguments.function.ts +0 -27
- package/src/shared/mcp/functions/handle-agent-create.function.ts +0 -116
- package/src/shared/mcp/functions/handle-agent-delete.function.ts +0 -50
- package/src/shared/mcp/functions/handle-agent-get.function.ts +0 -160
- package/src/shared/mcp/functions/handle-agent-list.function.ts +0 -50
- package/src/shared/mcp/functions/handle-agent-prompt.function.ts +0 -68
- package/src/shared/mcp/functions/handle-completion.function.ts +0 -114
- package/src/shared/mcp/functions/handle-mcp-request.function.ts +0 -202
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +0 -220
- package/src/shared/mcp/functions/handle-recall.function.ts +0 -66
- package/src/shared/mcp/functions/handle-resource-read.function.ts +0 -56
- package/src/shared/mcp/functions/handle-roots-list.function.ts +0 -29
- package/src/shared/mcp/functions/handle-skill-prompt.function.ts +0 -44
- package/src/shared/mcp/functions/handle-tool-auto-capture-review.function.ts +0 -24
- package/src/shared/mcp/functions/handle-tool-call.function.ts +0 -560
- package/src/shared/mcp/functions/handle-tool-check.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-content.function.ts +0 -23
- package/src/shared/mcp/functions/handle-tool-export.function.ts +0 -25
- package/src/shared/mcp/functions/handle-tool-gc.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-learn.function.ts +0 -69
- package/src/shared/mcp/functions/handle-tool-rebuild.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-retrieve.function.ts +0 -40
- package/src/shared/mcp/functions/handle-tool-search.function.ts +0 -47
- package/src/shared/mcp/functions/handle-tool-skill-delete.function.ts +0 -34
- package/src/shared/mcp/functions/handle-tool-skill-get.function.ts +0 -59
- package/src/shared/mcp/functions/handle-tool-skill-learn.function.ts +0 -61
- package/src/shared/mcp/functions/handle-tool-skill-list.function.ts +0 -39
- package/src/shared/mcp/functions/handle-tool-status.function.ts +0 -21
- package/src/shared/mcp/functions/handle-tool-unlearn.function.ts +0 -24
- package/src/shared/mcp/functions/parse-agent-meta.function.ts +0 -27
- package/src/shared/mcp/functions/parse-skill-arguments.function.ts +0 -36
- package/src/shared/mcp/functions/parse-skill-content.function.ts +0 -38
- package/src/shared/mcp/functions/read-agent-meta.function.ts +0 -41
- package/src/shared/mcp/functions/resolve-skill-refs.function.ts +0 -50
- package/src/shared/mcp/functions/run-startup-health-check.function.ts +0 -34
- package/src/shared/mcp/functions/serialize-skill-content.function.ts +0 -12
- package/src/shared/mcp/functions/should-emit-log.function.ts +0 -38
- package/src/shared/mcp/index.ts +0 -28
- package/src/shared/mcp/typings/agent-types.interface.ts +0 -39
- package/src/shared/mcp/typings/log-types.interface.ts +0 -26
- package/src/shared/mcp/typings/mcp-capabilities.interface.ts +0 -16
- package/src/shared/mcp/typings/mcp-client.interface.ts +0 -317
- package/src/shared/mcp/typings/mcp-completion.interface.ts +0 -45
- package/src/shared/mcp/typings/mcp-content-result.model.ts +0 -9
- package/src/shared/mcp/typings/mcp-export-result.model.ts +0 -11
- package/src/shared/mcp/typings/mcp-gc-result.model.ts +0 -15
- package/src/shared/mcp/typings/mcp-integrity-check-result.model.ts +0 -17
- package/src/shared/mcp/typings/mcp-integrity-error.model.ts +0 -15
- package/src/shared/mcp/typings/mcp-notification.interface.ts +0 -9
- package/src/shared/mcp/typings/mcp-rebuild-result.model.ts +0 -9
- package/src/shared/mcp/typings/mcp-request.interface.ts +0 -11
- package/src/shared/mcp/typings/mcp-resource-result.interface.ts +0 -12
- package/src/shared/mcp/typings/mcp-resource-template.interface.ts +0 -11
- package/src/shared/mcp/typings/mcp-response.interface.ts +0 -18
- package/src/shared/mcp/typings/mcp-server-info.interface.ts +0 -7
- package/src/shared/mcp/typings/mcp-server-state.interface.ts +0 -17
- package/src/shared/mcp/typings/mcp-tool-annotations.interface.ts +0 -32
- package/src/shared/mcp/typings/mcp-tool-definition.interface.ts +0 -16
- package/src/shared/mcp/typings/mcp-tool-result.interface.ts +0 -19
- package/src/shared/mcp/typings/mcp-types.interface.ts +0 -158
- package/src/shared/mcp/typings/mcp-worker-client.interface.ts +0 -243
- package/src/shared/mcp/typings/prompt-types.interface.ts +0 -39
- package/src/shared/mcp/typings/remove-section-result.model.ts +0 -10
- package/src/shared/mcp/typings/sampling-types.interface.ts +0 -48
- package/src/shared/mcp/typings/skill-types.interface.ts +0 -29
- package/src/shared/mcp/typings/tool-call-result.model.ts +0 -18
- package/src/shared/mod.ts +0 -1
- package/src/shared/platform/functions/get-ipc-path.function.ts +0 -19
- package/src/shared/platform/functions/get-tmpdir.function.ts +0 -8
- package/src/shared/platform/functions/is-process-alive.function.ts +0 -17
- package/src/shared/platform/index.ts +0 -3
- package/src/shared/runtime/functions/detect-runtime.ts +0 -14
- package/src/shared/runtime/functions/get-args.ts +0 -16
- package/src/shared/runtime/index.ts +0 -3
- package/src/shared/runtime/typings/runtime.ts +0 -2
- package/src/shared/sync/functions/build-import-report.function.ts +0 -40
- package/src/shared/sync/functions/parse-export-entry.function.ts +0 -45
- package/src/shared/sync/functions/resolve-conflict.function.ts +0 -31
- package/src/shared/sync/functions/serialize-export-entry.function.ts +0 -18
- package/src/shared/sync/index.ts +0 -9
- package/src/shared/sync/typings/conflict-resolution.type.ts +0 -8
- package/src/shared/sync/typings/export-entry.interface.ts +0 -13
- package/src/shared/sync/typings/export-options.interface.ts +0 -9
- package/src/shared/sync/typings/import-options.interface.ts +0 -7
- package/src/shared/sync/typings/import-report.interface.ts +0 -15
- package/src/shared/version/constants/version.constant.ts +0 -2
- package/src/shared/version/index.ts +0 -1
- package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +0 -112
- package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +0 -70
- package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +0 -87
- package/src/shared/wasm-codec/functions/decode-f32.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +0 -15
- package/src/shared/wasm-codec/functions/decode-one-recall-result.function.ts +0 -86
- package/src/shared/wasm-codec/functions/decode-option-string.function.ts +0 -24
- package/src/shared/wasm-codec/functions/decode-recall-document.function.ts +0 -59
- package/src/shared/wasm-codec/functions/decode-recall-reference.function.ts +0 -52
- package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +0 -267
- package/src/shared/wasm-codec/functions/decode-recall-sibling.function.ts +0 -43
- package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +0 -3
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +0 -194
- package/src/shared/wasm-codec/functions/decode-section-match.function.ts +0 -80
- package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +0 -20
- package/src/shared/wasm-codec/functions/decode-section-record-trailing.function.ts +0 -75
- package/src/shared/wasm-codec/functions/decode-section-record.function.ts +0 -85
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +0 -249
- package/src/shared/wasm-codec/functions/decode-section-type.function.ts +0 -30
- package/src/shared/wasm-codec/functions/decode-string.function.ts +0 -22
- package/src/shared/wasm-codec/functions/decode-u32.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-u64.function.ts +0 -16
- package/src/shared/wasm-codec/functions/decode-wasm-list.function.ts +0 -31
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +0 -102
- package/src/shared/wasm-codec/functions/encode-group-params.function.ts +0 -28
- package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +0 -17
- package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +0 -17
- package/src/shared/wasm-codec/functions/encode-option-string.function.ts +0 -14
- package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +0 -68
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +0 -12
- package/src/shared/wasm-codec/functions/encode-section-type.function.ts +0 -18
- package/src/shared/wasm-codec/functions/encode-string.function.ts +0 -9
- package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +0 -13
- package/src/shared/wasm-codec/functions/encode-u32.function.ts +0 -5
- package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +0 -16
- package/src/shared/wasm-codec/index.ts +0 -49
- package/src/shared/wasm-codec/typings/add-section-input.model.ts +0 -45
- package/src/shared/wasm-codec/typings/add-section-result.model.ts +0 -28
- package/src/shared/wasm-codec/typings/document-manifest.model.ts +0 -20
- package/src/shared/wasm-codec/typings/document-section.model.ts +0 -12
- package/src/shared/wasm-codec/typings/item-decoder.type.ts +0 -10
- package/src/shared/wasm-codec/typings/near-duplicate.model.ts +0 -16
- package/src/shared/wasm-codec/typings/paged-search-result.model.ts +0 -22
- package/src/shared/wasm-codec/typings/section-match.model.ts +0 -31
- package/src/shared/wasm-codec/typings/section-record-trailing.model.ts +0 -38
- package/src/shared/wasm-codec/typings/section-record.model.ts +0 -66
- package/src/shared/wasm-codec/typings/section-type-result.model.ts +0 -12
- package/src/shared/worker-client/classes/worker-client.class.ts +0 -466
- package/src/shared/worker-client/functions/compute-context-id.function.ts +0 -18
- package/src/shared/worker-client/functions/create-worker-client.function.ts +0 -70
- package/src/shared/worker-client/functions/discover-daemon.function.ts +0 -47
- package/src/shared/worker-client/functions/handle-ipc-data.function.ts +0 -49
- package/src/shared/worker-client/functions/resolve-db-path.function.ts +0 -21
- package/src/shared/worker-client/functions/send-ipc-request.function.ts +0 -39
- package/src/shared/worker-client/functions/spawn-daemon.function.ts +0 -35
- package/src/shared/worker-client/functions/wait-for-daemon.function.ts +0 -34
- package/src/shared/worker-client/index.ts +0 -44
- package/src/shared/worker-client/typings/add-section-result.model.ts +0 -39
- package/src/shared/worker-client/typings/content-result.model.ts +0 -12
- package/src/shared/worker-client/typings/daemon-info.model.ts +0 -7
- package/src/shared/worker-client/typings/export-result.model.ts +0 -14
- package/src/shared/worker-client/typings/gc-result.model.ts +0 -18
- package/src/shared/worker-client/typings/integrity-check-result.model.ts +0 -43
- package/src/shared/worker-client/typings/json-rpc-response.interface.ts +0 -17
- package/src/shared/worker-client/typings/migrate-result.model.ts +0 -11
- package/src/shared/worker-client/typings/pending-call.interface.ts +0 -7
- package/src/shared/worker-client/typings/rebuild-result.model.ts +0 -12
- package/src/shared/worker-client/typings/recall-document.model.ts +0 -16
- package/src/shared/worker-client/typings/recall-params.model.ts +0 -15
- package/src/shared/worker-client/typings/recall-reference.model.ts +0 -32
- package/src/shared/worker-client/typings/recall-result.model.ts +0 -98
- package/src/shared/worker-client/typings/recall-sibling.model.ts +0 -11
- package/src/shared/worker-client/typings/recall-single-result.model.ts +0 -41
- package/src/shared/worker-client/typings/remove-section-result.model.ts +0 -7
- package/src/shared/worker-client/typings/search-params.model.ts +0 -14
- package/src/shared/worker-client/typings/search-result.model.ts +0 -43
- package/src/shared/worker-client/typings/section.model.ts +0 -43
- package/src/shared/worker-client/typings/status-result.model.ts +0 -14
- package/src/shared/worker-client/typings/version-status.model.ts +0 -28
- package/src/shared/worker-client/typings/worker-client-error.interface.ts +0 -8
- package/src/shared/worker-client/typings/worker-client-options.interface.ts +0 -30
- package/src/shared/worker-daemon/classes/ipc-error.class.ts +0 -22
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +0 -1291
- package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +0 -29
- package/src/shared/worker-daemon/constants/wasm-method-map.constant.ts +0 -69
- package/src/shared/worker-daemon/functions/build-ipc-error-response.function.ts +0 -16
- package/src/shared/worker-daemon/functions/check-catalog-version.function.ts +0 -54
- package/src/shared/worker-daemon/functions/check-preconditions.function.ts +0 -28
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +0 -328
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +0 -87
- package/src/shared/worker-daemon/functions/detect-stale-pid.function.ts +0 -33
- package/src/shared/worker-daemon/functions/dispatch-request.function.ts +0 -190
- package/src/shared/worker-daemon/functions/handle-check-version.function.ts +0 -74
- package/src/shared/worker-daemon/functions/handle-config-method.function.ts +0 -27
- package/src/shared/worker-daemon/functions/handle-read-ops.function.ts +0 -236
- package/src/shared/worker-daemon/functions/handle-write-ops.function.ts +0 -257
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +0 -95
- package/src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts +0 -51
- package/src/shared/worker-daemon/functions/parse-catalog-version.function.ts +0 -20
- package/src/shared/worker-daemon/functions/parse-embedding-section.function.ts +0 -38
- package/src/shared/worker-daemon/functions/parse-worker-toml.function.ts +0 -104
- package/src/shared/worker-daemon/functions/read-config.function.ts +0 -83
- package/src/shared/worker-daemon/functions/run-startup-integrity-check.function.ts +0 -55
- package/src/shared/worker-daemon/functions/run-worker.function.ts +0 -57
- package/src/shared/worker-daemon/functions/scan-near-duplicates.function.ts +0 -92
- package/src/shared/worker-daemon/functions/start-daemon.function.ts +0 -74
- package/src/shared/worker-daemon/functions/wasm-bridge.function.ts +0 -144
- package/src/shared/worker-daemon/functions/wasm-memory-helpers.function.ts +0 -41
- package/src/shared/worker-daemon/functions/write-lock.function.ts +0 -49
- package/src/shared/worker-daemon/index.ts +0 -16
- package/src/shared/worker-daemon/typings/allocator-ref.interface.ts +0 -16
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +0 -20
- package/src/shared/worker-daemon/typings/fs-adapter.interface.ts +0 -22
- package/src/shared/worker-daemon/typings/handler-context.interface.ts +0 -19
- package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +0 -39
- package/src/shared/worker-daemon/typings/memory-ref.interface.ts +0 -13
- package/src/shared/worker-daemon/typings/wasm-fn.type.ts +0 -2
- package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +0 -7
- package/src/shared/worker-daemon/typings/write-lock.interface.ts +0 -13
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +0 -259
- package/src/wasm/fs-database/kbdb_fs_database.js +0 -515
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +0 -35
- package/src/wasm/fs-database/package.json +0 -13
- package/src/wasm/kb-worker/kbdb_worker.d.ts +0 -650
- package/src/wasm/kb-worker/kbdb_worker.js +0 -1181
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +0 -77
- package/src/wasm/kb-worker/package.json +0 -13
- package/src/wasm/query-parser/kbdb_query_parser.d.ts +0 -195
- package/src/wasm/query-parser/kbdb_query_parser.js +0 -403
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm.d.ts +0 -25
- package/src/wasm/query-parser/package.json +0 -13
- package/src/worker.ts +0 -42
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
// src/cli.ts
|
|
5
|
+
var import_node_fs9 = require("node:fs");
|
|
6
|
+
var import_node_path12 = require("node:path");
|
|
7
|
+
|
|
4
8
|
// src/shared/runtime/functions/detect-runtime.ts
|
|
5
9
|
function detectRuntime() {
|
|
6
10
|
if (typeof globalThis !== "undefined" && "Deno" in globalThis) {
|
|
@@ -109,6 +113,7 @@ function parseArgs(argv) {
|
|
|
109
113
|
case "--format":
|
|
110
114
|
case "-f":
|
|
111
115
|
options.format = argv[++i] ?? DEFAULT_FORMAT;
|
|
116
|
+
options.formatExplicit = true;
|
|
112
117
|
break;
|
|
113
118
|
case "--mode":
|
|
114
119
|
case "-m":
|
|
@@ -166,10 +171,28 @@ function parseArgs(argv) {
|
|
|
166
171
|
case "-c":
|
|
167
172
|
options.content = true;
|
|
168
173
|
break;
|
|
174
|
+
case "--relaxed":
|
|
175
|
+
options.relaxed = true;
|
|
176
|
+
break;
|
|
177
|
+
case "--from":
|
|
178
|
+
options.from = argv[++i];
|
|
179
|
+
break;
|
|
180
|
+
case "--dry-run":
|
|
181
|
+
options.dryRun = true;
|
|
182
|
+
break;
|
|
183
|
+
case "--export-format":
|
|
184
|
+
options.exportFormat = argv[++i] ?? "git";
|
|
185
|
+
break;
|
|
186
|
+
case "--timeout-ms":
|
|
187
|
+
options.timeoutMs = parseInt(argv[++i] ?? "", 10) || void 0;
|
|
188
|
+
break;
|
|
189
|
+
case "--retry":
|
|
190
|
+
options.retry = parseInt(argv[++i] ?? "", 10) || void 0;
|
|
191
|
+
break;
|
|
169
192
|
default:
|
|
170
193
|
if (!options.command) {
|
|
171
194
|
options.command = arg;
|
|
172
|
-
} else if (!options.args.length && (options.command === "db" || options.command === "skill" || options.command === "agent")) {
|
|
195
|
+
} else if (!options.args.length && (options.command === "db" || options.command === "skill" || options.command === "agent" || options.command === "worker")) {
|
|
173
196
|
options.command = `${options.command}-${arg}`;
|
|
174
197
|
} else {
|
|
175
198
|
options.args.push(arg);
|
|
@@ -258,7 +281,8 @@ async function runSearch(client, options) {
|
|
|
258
281
|
mode: options.mode,
|
|
259
282
|
limit: options.limit,
|
|
260
283
|
offset: options.offset,
|
|
261
|
-
algo: options.algo
|
|
284
|
+
algo: options.algo,
|
|
285
|
+
relaxed: options.relaxed
|
|
262
286
|
});
|
|
263
287
|
return {
|
|
264
288
|
items: results.items.map((r) => ({
|
|
@@ -278,10 +302,35 @@ async function runSearch(client, options) {
|
|
|
278
302
|
offset: results.offset,
|
|
279
303
|
limit: results.limit,
|
|
280
304
|
has_more: results.has_more,
|
|
281
|
-
relaxed: results.relaxed ?? false
|
|
305
|
+
relaxed: results.relaxed ?? false,
|
|
306
|
+
elapsed_ms: results.elapsed_ms,
|
|
307
|
+
search_mode: results.search_mode,
|
|
308
|
+
retrieval_method: results.retrieval_method
|
|
282
309
|
};
|
|
283
310
|
}
|
|
284
311
|
|
|
312
|
+
// src/shared/cli/functions/resolve-kbid-prefix.function.ts
|
|
313
|
+
var SECTION_TYPES = ["text", "code", "image"];
|
|
314
|
+
async function resolveKbidPrefix(prefix, client) {
|
|
315
|
+
if (prefix.length >= 26) return prefix;
|
|
316
|
+
const seen = /* @__PURE__ */ new Set();
|
|
317
|
+
for (const type of SECTION_TYPES) {
|
|
318
|
+
const records = await client.listByType(type);
|
|
319
|
+
for (const r of records) {
|
|
320
|
+
if (r.kbid.startsWith(prefix)) seen.add(r.kbid);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (seen.size === 0) {
|
|
324
|
+
throw new Error(`no section matches prefix "${prefix}"`);
|
|
325
|
+
}
|
|
326
|
+
if (seen.size > 1) {
|
|
327
|
+
throw new Error(
|
|
328
|
+
`ambiguous prefix "${prefix}": ${seen.size.toString()} matches`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return [...seen][0];
|
|
332
|
+
}
|
|
333
|
+
|
|
285
334
|
// src/shared/cli/functions/run-recall.function.ts
|
|
286
335
|
var MAX_RECALL_DEPTH = 3;
|
|
287
336
|
async function runRecall(client, options) {
|
|
@@ -292,10 +341,13 @@ async function runRecall(client, options) {
|
|
|
292
341
|
MAX_RECALL_DEPTH,
|
|
293
342
|
Math.max(0, options.depth ?? 0)
|
|
294
343
|
);
|
|
295
|
-
|
|
296
|
-
|
|
344
|
+
const resolved = await Promise.all(
|
|
345
|
+
options.args.map((a) => resolveKbidPrefix(a, client))
|
|
346
|
+
);
|
|
347
|
+
if (resolved.length === 1) {
|
|
348
|
+
return client.recall({ kbid: resolved[0], depth });
|
|
297
349
|
}
|
|
298
|
-
return client.recall({ kbids:
|
|
350
|
+
return client.recall({ kbids: resolved, depth });
|
|
299
351
|
}
|
|
300
352
|
|
|
301
353
|
// src/shared/cli/functions/run-export.function.ts
|
|
@@ -410,7 +462,8 @@ function isSupportedFile(path) {
|
|
|
410
462
|
// src/shared/cli/functions/run-unlearn.function.ts
|
|
411
463
|
async function runUnlearn(client, options) {
|
|
412
464
|
const results = [];
|
|
413
|
-
for (const
|
|
465
|
+
for (const arg of options.args) {
|
|
466
|
+
const kbid = await resolveKbidPrefix(arg, client);
|
|
414
467
|
const result = await client.removeSection(kbid);
|
|
415
468
|
results.push({ kbid, removed: result.removed });
|
|
416
469
|
}
|
|
@@ -419,7 +472,10 @@ async function runUnlearn(client, options) {
|
|
|
419
472
|
|
|
420
473
|
// src/shared/cli/functions/run-content.function.ts
|
|
421
474
|
async function runContent(client, options) {
|
|
422
|
-
|
|
475
|
+
const resolved = await Promise.all(
|
|
476
|
+
options.args.map((a) => resolveKbidPrefix(a, client))
|
|
477
|
+
);
|
|
478
|
+
return client.content(resolved);
|
|
423
479
|
}
|
|
424
480
|
|
|
425
481
|
// src/shared/cli/functions/run-check.function.ts
|
|
@@ -459,9 +515,20 @@ async function runRebuild(client, _options) {
|
|
|
459
515
|
var import_node_fs2 = require("node:fs");
|
|
460
516
|
var import_node_path4 = require("node:path");
|
|
461
517
|
function findDb(dbPath) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
518
|
+
if (dbPath) {
|
|
519
|
+
const target = (0, import_node_path4.join)((0, import_node_path4.resolve)(dbPath), ".kbdb");
|
|
520
|
+
return (0, import_node_fs2.existsSync)(target) ? target : null;
|
|
521
|
+
}
|
|
522
|
+
let current = process.cwd();
|
|
523
|
+
let parent = (0, import_node_path4.dirname)(current);
|
|
524
|
+
while (parent !== current) {
|
|
525
|
+
const candidate2 = (0, import_node_path4.join)(current, ".kbdb");
|
|
526
|
+
if ((0, import_node_fs2.existsSync)(candidate2)) return candidate2;
|
|
527
|
+
current = parent;
|
|
528
|
+
parent = (0, import_node_path4.dirname)(current);
|
|
529
|
+
}
|
|
530
|
+
const candidate = (0, import_node_path4.join)(current, ".kbdb");
|
|
531
|
+
return (0, import_node_fs2.existsSync)(candidate) ? candidate : null;
|
|
465
532
|
}
|
|
466
533
|
|
|
467
534
|
// src/shared/cli/functions/run-init.function.ts
|
|
@@ -956,6 +1023,18 @@ async function runAgentDelete(client, options) {
|
|
|
956
1023
|
};
|
|
957
1024
|
}
|
|
958
1025
|
|
|
1026
|
+
// src/shared/cli/functions/run-import.function.ts
|
|
1027
|
+
async function runImport(client, options) {
|
|
1028
|
+
const from = options.from;
|
|
1029
|
+
if (!from) {
|
|
1030
|
+
throw new Error("import requires --from <path>");
|
|
1031
|
+
}
|
|
1032
|
+
return client.import({
|
|
1033
|
+
from,
|
|
1034
|
+
dryRun: options.dryRun === true
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
|
|
959
1038
|
// src/shared/cli/functions/dispatch-command.function.ts
|
|
960
1039
|
async function dispatchCommand(client, options, io) {
|
|
961
1040
|
switch (options.command) {
|
|
@@ -979,6 +1058,8 @@ async function dispatchCommand(client, options, io) {
|
|
|
979
1058
|
return handleStatus(client, options);
|
|
980
1059
|
case "export":
|
|
981
1060
|
return handleExport(client, options);
|
|
1061
|
+
case "import":
|
|
1062
|
+
return handleImport(client, options);
|
|
982
1063
|
case "db-init":
|
|
983
1064
|
return handleDbInit(options);
|
|
984
1065
|
case "db-migrate":
|
|
@@ -1101,6 +1182,20 @@ async function handleExport(client, options) {
|
|
|
1101
1182
|
};
|
|
1102
1183
|
}
|
|
1103
1184
|
}
|
|
1185
|
+
async function handleImport(client, options) {
|
|
1186
|
+
try {
|
|
1187
|
+
const result = await runImport(client, options);
|
|
1188
|
+
return {
|
|
1189
|
+
output: JSON.stringify(result, null, 2),
|
|
1190
|
+
exitCode: 0
|
|
1191
|
+
};
|
|
1192
|
+
} catch (err) {
|
|
1193
|
+
return {
|
|
1194
|
+
error: `import failed: ${errorToMessage(err)}`,
|
|
1195
|
+
exitCode: 1
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1104
1199
|
async function handleContent(client, options) {
|
|
1105
1200
|
try {
|
|
1106
1201
|
const result = await runContent(client, options);
|
|
@@ -1201,7 +1296,7 @@ async function hydrateSearchPreviews(client, paged) {
|
|
|
1201
1296
|
}
|
|
1202
1297
|
|
|
1203
1298
|
// src/shared/version/constants/version.constant.ts
|
|
1204
|
-
var VERSION = "0.
|
|
1299
|
+
var VERSION = "0.4.0";
|
|
1205
1300
|
|
|
1206
1301
|
// src/shared/cli/functions/generate-help.function.ts
|
|
1207
1302
|
var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
@@ -1218,7 +1313,8 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
1218
1313
|
"mcp",
|
|
1219
1314
|
"db",
|
|
1220
1315
|
"skill",
|
|
1221
|
-
"agent"
|
|
1316
|
+
"agent",
|
|
1317
|
+
"worker"
|
|
1222
1318
|
]);
|
|
1223
1319
|
var GROUP_SUBCOMMANDS = {
|
|
1224
1320
|
db: [
|
|
@@ -1236,6 +1332,10 @@ var GROUP_SUBCOMMANDS = {
|
|
|
1236
1332
|
["list", "List all agents"],
|
|
1237
1333
|
["get", "Retrieve an agent by docid"],
|
|
1238
1334
|
["delete", "Remove an agent"]
|
|
1335
|
+
],
|
|
1336
|
+
worker: [
|
|
1337
|
+
["stop", "Stop the worker daemon"],
|
|
1338
|
+
["restart", "Restart the worker daemon"]
|
|
1239
1339
|
]
|
|
1240
1340
|
};
|
|
1241
1341
|
function isKnownCommand(cmd) {
|
|
@@ -1304,6 +1404,10 @@ Agents:
|
|
|
1304
1404
|
agent get Retrieve an agent by docid
|
|
1305
1405
|
agent delete Remove an agent
|
|
1306
1406
|
|
|
1407
|
+
Worker:
|
|
1408
|
+
worker stop Stop the worker daemon
|
|
1409
|
+
worker restart Restart the worker daemon
|
|
1410
|
+
|
|
1307
1411
|
Server:
|
|
1308
1412
|
mcp Start MCP server mode (stdio)
|
|
1309
1413
|
|
|
@@ -1349,7 +1453,8 @@ Run "kbdb ${group} <subcommand> --help" for details.
|
|
|
1349
1453
|
var GROUP_DESCRIPTIONS = {
|
|
1350
1454
|
db: "Database management",
|
|
1351
1455
|
skill: "Skill management",
|
|
1352
|
-
agent: "Agent management"
|
|
1456
|
+
agent: "Agent management",
|
|
1457
|
+
worker: "Worker daemon management"
|
|
1353
1458
|
};
|
|
1354
1459
|
var LEAF_HELP = {
|
|
1355
1460
|
learn: `kbdb learn - Import content from files or stdin
|
|
@@ -1535,11 +1640,11 @@ Options:
|
|
|
1535
1640
|
--db <path> Path to .kbdb directory
|
|
1536
1641
|
|
|
1537
1642
|
Environment:
|
|
1538
|
-
|
|
1643
|
+
KBDB_DB_DIR Fallback database path
|
|
1539
1644
|
|
|
1540
1645
|
Examples:
|
|
1541
1646
|
kbdb mcp --db /path/to/project
|
|
1542
|
-
|
|
1647
|
+
KBDB_DB_DIR=/path/to/project kbdb mcp
|
|
1543
1648
|
`
|
|
1544
1649
|
};
|
|
1545
1650
|
var SUBCOMMAND_HELP = {
|
|
@@ -1702,6 +1807,28 @@ Output:
|
|
|
1702
1807
|
|
|
1703
1808
|
Examples:
|
|
1704
1809
|
kbdb agent delete agent-code-reviewer
|
|
1810
|
+
`,
|
|
1811
|
+
"worker-stop": `kbdb worker stop - Stop the worker daemon
|
|
1812
|
+
|
|
1813
|
+
Usage: kbdb worker stop [options]
|
|
1814
|
+
|
|
1815
|
+
Options:
|
|
1816
|
+
--db <path> Path to .kbdb directory
|
|
1817
|
+
|
|
1818
|
+
Examples:
|
|
1819
|
+
kbdb worker stop
|
|
1820
|
+
kbdb worker stop --db /path/to/project
|
|
1821
|
+
`,
|
|
1822
|
+
"worker-restart": `kbdb worker restart - Restart the worker daemon
|
|
1823
|
+
|
|
1824
|
+
Usage: kbdb worker restart [options]
|
|
1825
|
+
|
|
1826
|
+
Options:
|
|
1827
|
+
--db <path> Path to .kbdb directory
|
|
1828
|
+
|
|
1829
|
+
Examples:
|
|
1830
|
+
kbdb worker restart
|
|
1831
|
+
kbdb worker restart --db /path/to/project
|
|
1705
1832
|
`
|
|
1706
1833
|
};
|
|
1707
1834
|
function generateSubcommandHelp(command, subcommand) {
|
|
@@ -1713,199 +1840,6 @@ function generateSubcommandHelp(command, subcommand) {
|
|
|
1713
1840
|
return generateCommandHelp(command);
|
|
1714
1841
|
}
|
|
1715
1842
|
|
|
1716
|
-
// src/shared/cli/functions/run-cli.function.ts
|
|
1717
|
-
async function runCli(argv, deps2) {
|
|
1718
|
-
const options = parseArgs(argv);
|
|
1719
|
-
if (options.command === "help" || !options.command) {
|
|
1720
|
-
const helpCommand = options.args[0];
|
|
1721
|
-
const helpSubcommand = options.args[1];
|
|
1722
|
-
const helpText = generateHelp(helpCommand, helpSubcommand);
|
|
1723
|
-
if (helpCommand && !isKnownCommand(helpCommand)) {
|
|
1724
|
-
return { output: helpText, exitCode: 1 };
|
|
1725
|
-
}
|
|
1726
|
-
return { output: helpText, exitCode: 0 };
|
|
1727
|
-
}
|
|
1728
|
-
if (options.command === "version") {
|
|
1729
|
-
return { output: VERSION, exitCode: 0 };
|
|
1730
|
-
}
|
|
1731
|
-
if (options.command === "init" || options.command === "db-init") {
|
|
1732
|
-
return handleInit(options, deps2);
|
|
1733
|
-
}
|
|
1734
|
-
if (options.command === "mcp") {
|
|
1735
|
-
return handleMcp(options, deps2);
|
|
1736
|
-
}
|
|
1737
|
-
if (options.command === "migrate" || options.command === "db-migrate") {
|
|
1738
|
-
return handleMigrate(options, deps2);
|
|
1739
|
-
}
|
|
1740
|
-
return handleDataCommand(options, deps2);
|
|
1741
|
-
}
|
|
1742
|
-
function handleInit(options, deps2) {
|
|
1743
|
-
const result = deps2.runInit(options);
|
|
1744
|
-
if (result.ok) {
|
|
1745
|
-
return {
|
|
1746
|
-
output: result.targetPath,
|
|
1747
|
-
exitCode: 0
|
|
1748
|
-
};
|
|
1749
|
-
}
|
|
1750
|
-
return {
|
|
1751
|
-
error: `error: ${result.errorMessage ?? "init failed"}`,
|
|
1752
|
-
exitCode: 1
|
|
1753
|
-
};
|
|
1754
|
-
}
|
|
1755
|
-
async function handleMcp(options, deps2) {
|
|
1756
|
-
const rawDbPath = options.dbPath ?? process.env["KBDB_DIR"];
|
|
1757
|
-
if (!rawDbPath) {
|
|
1758
|
-
return {
|
|
1759
|
-
error: "error: --db or KBDB_DIR required in MCP mode",
|
|
1760
|
-
exitCode: 1
|
|
1761
|
-
};
|
|
1762
|
-
}
|
|
1763
|
-
const dbDir = deps2.findDb(rawDbPath);
|
|
1764
|
-
if (!dbDir) {
|
|
1765
|
-
return {
|
|
1766
|
-
error: `error: no .kbdb database found at ${rawDbPath}`,
|
|
1767
|
-
exitCode: 1
|
|
1768
|
-
};
|
|
1769
|
-
}
|
|
1770
|
-
let client;
|
|
1771
|
-
try {
|
|
1772
|
-
client = await deps2.createWorkerClient({
|
|
1773
|
-
contextPath: dbDir
|
|
1774
|
-
});
|
|
1775
|
-
} catch (err) {
|
|
1776
|
-
return {
|
|
1777
|
-
error: `error: ${errorToMessage(err)}`,
|
|
1778
|
-
exitCode: 1
|
|
1779
|
-
};
|
|
1780
|
-
}
|
|
1781
|
-
try {
|
|
1782
|
-
const gateResult = await versionGate(client, dbDir);
|
|
1783
|
-
if (gateResult) return gateResult;
|
|
1784
|
-
if (deps2.startMcpServer) {
|
|
1785
|
-
await deps2.startMcpServer(dbDir);
|
|
1786
|
-
}
|
|
1787
|
-
return { exitCode: 0 };
|
|
1788
|
-
} catch (err) {
|
|
1789
|
-
return {
|
|
1790
|
-
error: `error: mcp failed: ${errorToMessage(err)}`,
|
|
1791
|
-
exitCode: 1
|
|
1792
|
-
};
|
|
1793
|
-
} finally {
|
|
1794
|
-
client.disconnect();
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
async function handleMigrate(options, deps2) {
|
|
1798
|
-
const dbDir = deps2.findDb(options.dbPath);
|
|
1799
|
-
if (!dbDir) {
|
|
1800
|
-
const basePath = options.dbPath ?? process.cwd();
|
|
1801
|
-
return {
|
|
1802
|
-
error: `error: no .kbdb database found at ${basePath}`,
|
|
1803
|
-
exitCode: 1
|
|
1804
|
-
};
|
|
1805
|
-
}
|
|
1806
|
-
let client;
|
|
1807
|
-
try {
|
|
1808
|
-
client = await deps2.createWorkerClient({
|
|
1809
|
-
contextPath: dbDir
|
|
1810
|
-
});
|
|
1811
|
-
} catch (err) {
|
|
1812
|
-
return {
|
|
1813
|
-
error: `error: ${errorToMessage(err)}`,
|
|
1814
|
-
exitCode: 1
|
|
1815
|
-
};
|
|
1816
|
-
}
|
|
1817
|
-
try {
|
|
1818
|
-
const versionStatus = await client.checkVersion(dbDir);
|
|
1819
|
-
if (versionStatus.status === "too_new") {
|
|
1820
|
-
return {
|
|
1821
|
-
error: `error: database version ${versionStatus.currentVersion.toString()} is newer than kbdb version ${versionStatus.requiredVersion.toString()} -- upgrade kbdb`,
|
|
1822
|
-
exitCode: 1
|
|
1823
|
-
};
|
|
1824
|
-
}
|
|
1825
|
-
if (versionStatus.status === "needs_migration") {
|
|
1826
|
-
const migrateResult = await client.migrateDatabase(dbDir);
|
|
1827
|
-
return {
|
|
1828
|
-
output: JSON.stringify(migrateResult, null, 2),
|
|
1829
|
-
exitCode: 0
|
|
1830
|
-
};
|
|
1831
|
-
}
|
|
1832
|
-
return { output: "already up to date", exitCode: 0 };
|
|
1833
|
-
} catch (err) {
|
|
1834
|
-
return {
|
|
1835
|
-
error: `error: migrate failed: ${errorToMessage(err)}`,
|
|
1836
|
-
exitCode: 1
|
|
1837
|
-
};
|
|
1838
|
-
} finally {
|
|
1839
|
-
client.disconnect();
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
async function handleDataCommand(options, deps2) {
|
|
1843
|
-
let dbDir = deps2.findDb(options.dbPath);
|
|
1844
|
-
if (!dbDir) {
|
|
1845
|
-
const basePath = options.dbPath ?? process.cwd();
|
|
1846
|
-
if (!deps2.isStdinTty()) {
|
|
1847
|
-
return {
|
|
1848
|
-
error: `error: no .kbdb database found at ${basePath} -- run \`kbdb --init\` to create one`,
|
|
1849
|
-
exitCode: 1
|
|
1850
|
-
};
|
|
1851
|
-
}
|
|
1852
|
-
const answer = await deps2.promptUser(
|
|
1853
|
-
`No .kbdb database found. Create one in ${basePath}? [y/N] `
|
|
1854
|
-
);
|
|
1855
|
-
if (answer.toLowerCase() !== "y") {
|
|
1856
|
-
return {
|
|
1857
|
-
error: "aborted: no database created",
|
|
1858
|
-
exitCode: 1
|
|
1859
|
-
};
|
|
1860
|
-
}
|
|
1861
|
-
const initResult = deps2.runInit(options);
|
|
1862
|
-
if (!initResult.ok) {
|
|
1863
|
-
return {
|
|
1864
|
-
error: `error: ${initResult.errorMessage ?? "init failed"}`,
|
|
1865
|
-
exitCode: 1
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
dbDir = initResult.targetPath;
|
|
1869
|
-
}
|
|
1870
|
-
let client;
|
|
1871
|
-
try {
|
|
1872
|
-
client = await deps2.createWorkerClient({
|
|
1873
|
-
contextPath: dbDir
|
|
1874
|
-
});
|
|
1875
|
-
} catch (err) {
|
|
1876
|
-
return {
|
|
1877
|
-
error: `error: ${errorToMessage(err)}`,
|
|
1878
|
-
exitCode: 1
|
|
1879
|
-
};
|
|
1880
|
-
}
|
|
1881
|
-
try {
|
|
1882
|
-
const gateResult = await versionGate(client, dbDir);
|
|
1883
|
-
if (gateResult) return gateResult;
|
|
1884
|
-
return await dispatchCommand(client, options);
|
|
1885
|
-
} finally {
|
|
1886
|
-
client.disconnect();
|
|
1887
|
-
}
|
|
1888
|
-
}
|
|
1889
|
-
async function versionGate(client, dbDir) {
|
|
1890
|
-
const versionStatus = await client.checkVersion(dbDir);
|
|
1891
|
-
if (versionStatus.status === "needs_migration") {
|
|
1892
|
-
return {
|
|
1893
|
-
error: "error: database needs migration -- run `kbdb --migrate`",
|
|
1894
|
-
exitCode: 1
|
|
1895
|
-
};
|
|
1896
|
-
}
|
|
1897
|
-
if (versionStatus.status === "too_new") {
|
|
1898
|
-
return {
|
|
1899
|
-
error: `error: database version ${versionStatus.currentVersion.toString()} is newer than kbdb version ${versionStatus.requiredVersion.toString()} -- upgrade kbdb`,
|
|
1900
|
-
exitCode: 1
|
|
1901
|
-
};
|
|
1902
|
-
}
|
|
1903
|
-
return null;
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
// src/shared/cli/constants/help-text.constant.ts
|
|
1907
|
-
var HELP_TEXT = generateHelp();
|
|
1908
|
-
|
|
1909
1843
|
// src/shared/worker-client/classes/worker-client.class.ts
|
|
1910
1844
|
var import_node_net = require("node:net");
|
|
1911
1845
|
var WorkerClient = class {
|
|
@@ -1914,10 +1848,13 @@ var WorkerClient = class {
|
|
|
1914
1848
|
* (or Windows named pipe path)
|
|
1915
1849
|
* @param contextId - 16-character context identifier sent as
|
|
1916
1850
|
* `ctx` in every JSON-RPC request
|
|
1851
|
+
* @param requestTimeoutMs - per-request timeout in ms
|
|
1852
|
+
* (0 or undefined disables the timeout)
|
|
1917
1853
|
*/
|
|
1918
|
-
constructor(socketPath, contextId) {
|
|
1854
|
+
constructor(socketPath, contextId, requestTimeoutMs) {
|
|
1919
1855
|
this.socketPath = socketPath;
|
|
1920
1856
|
this.contextId = contextId;
|
|
1857
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
1921
1858
|
}
|
|
1922
1859
|
/** Underlying socket; `null` when not connected. */
|
|
1923
1860
|
socket = null;
|
|
@@ -1927,30 +1864,85 @@ var WorkerClient = class {
|
|
|
1927
1864
|
pending = /* @__PURE__ */ new Map();
|
|
1928
1865
|
/** Partial line buffer for split TCP/IPC frames. */
|
|
1929
1866
|
buffer = "";
|
|
1867
|
+
/** Whether the underlying socket is connected. */
|
|
1868
|
+
get isConnected() {
|
|
1869
|
+
return this.socket !== null;
|
|
1870
|
+
}
|
|
1930
1871
|
/**
|
|
1931
1872
|
* Establishes the IPC connection to the worker daemon.
|
|
1932
1873
|
*
|
|
1874
|
+
* Retries up to 5 times with exponential backoff on
|
|
1875
|
+
* transient errors (`ENOENT`, `ECONNREFUSED`).
|
|
1876
|
+
*
|
|
1933
1877
|
* @throws {Error} if the connection cannot be established
|
|
1934
1878
|
*/
|
|
1935
1879
|
async connect() {
|
|
1880
|
+
const maxRetries = 5;
|
|
1881
|
+
let delay = 50;
|
|
1882
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1883
|
+
try {
|
|
1884
|
+
await this.tryConnect();
|
|
1885
|
+
return;
|
|
1886
|
+
} catch (err) {
|
|
1887
|
+
const code = err.code;
|
|
1888
|
+
const retriable = code === "ENOENT" || code === "ECONNREFUSED";
|
|
1889
|
+
if (!retriable || attempt === maxRetries) {
|
|
1890
|
+
throw err;
|
|
1891
|
+
}
|
|
1892
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
1893
|
+
delay = Math.min(delay * 2, 1e3);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
/** Destroys the IPC socket and clears the connection state. */
|
|
1898
|
+
disconnect() {
|
|
1899
|
+
if (this.socket) {
|
|
1900
|
+
this.socket.destroy();
|
|
1901
|
+
this.socket = null;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Single connection attempt with keepalive and
|
|
1906
|
+
* post-connect failure handlers.
|
|
1907
|
+
*/
|
|
1908
|
+
async tryConnect() {
|
|
1936
1909
|
return new Promise((resolve4, reject) => {
|
|
1937
|
-
|
|
1910
|
+
const sock = (0, import_node_net.connect)(this.socketPath, () => {
|
|
1911
|
+
sock.removeListener("error", reject);
|
|
1912
|
+
sock.setKeepAlive(true, 3e4);
|
|
1913
|
+
sock.on("error", (err) => {
|
|
1914
|
+
this.handleSocketFailure(err);
|
|
1915
|
+
});
|
|
1916
|
+
sock.on("close", () => {
|
|
1917
|
+
if (this.pending.size > 0) {
|
|
1918
|
+
this.handleSocketFailure(
|
|
1919
|
+
new Error("connection closed")
|
|
1920
|
+
);
|
|
1921
|
+
}
|
|
1922
|
+
this.socket = null;
|
|
1923
|
+
});
|
|
1924
|
+
this.socket = sock;
|
|
1938
1925
|
resolve4();
|
|
1939
1926
|
});
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
});
|
|
1943
|
-
this.socket.on("data", (chunk) => {
|
|
1927
|
+
sock.on("error", reject);
|
|
1928
|
+
sock.on("data", (chunk) => {
|
|
1944
1929
|
this.handleData(chunk.toString());
|
|
1945
1930
|
});
|
|
1946
1931
|
});
|
|
1947
1932
|
}
|
|
1948
|
-
/**
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1933
|
+
/**
|
|
1934
|
+
* Rejects all pending calls and marks the client as
|
|
1935
|
+
* disconnected.
|
|
1936
|
+
*/
|
|
1937
|
+
handleSocketFailure(err) {
|
|
1938
|
+
const sock = this.socket;
|
|
1939
|
+
this.socket = null;
|
|
1940
|
+
for (const [id, call] of this.pending) {
|
|
1941
|
+
this.pending.delete(id);
|
|
1942
|
+
if (call.timer) clearTimeout(call.timer);
|
|
1943
|
+
call.reject(err);
|
|
1953
1944
|
}
|
|
1945
|
+
if (sock) sock.destroy();
|
|
1954
1946
|
}
|
|
1955
1947
|
/**
|
|
1956
1948
|
* Searches the knowledge base.
|
|
@@ -1959,7 +1951,10 @@ var WorkerClient = class {
|
|
|
1959
1951
|
* @returns paginated search results with metadata
|
|
1960
1952
|
*/
|
|
1961
1953
|
async search(params) {
|
|
1962
|
-
return this.call("search",
|
|
1954
|
+
return this.call("search", {
|
|
1955
|
+
...params,
|
|
1956
|
+
algo: params.algo
|
|
1957
|
+
});
|
|
1963
1958
|
}
|
|
1964
1959
|
/**
|
|
1965
1960
|
* Retrieves full content and context for one or more sections by
|
|
@@ -2210,7 +2205,20 @@ var WorkerClient = class {
|
|
|
2210
2205
|
*/
|
|
2211
2206
|
async export(params) {
|
|
2212
2207
|
return this.call("export", {
|
|
2213
|
-
targetPath: params?.path || void 0
|
|
2208
|
+
targetPath: params?.path || void 0,
|
|
2209
|
+
format: params?.format
|
|
2210
|
+
});
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Imports an exported database from the given path.
|
|
2214
|
+
*
|
|
2215
|
+
* @param params - source path and dry-run flag
|
|
2216
|
+
* @returns import report with counts and timing
|
|
2217
|
+
*/
|
|
2218
|
+
async import(params) {
|
|
2219
|
+
return this.call("importDb", {
|
|
2220
|
+
sourcePath: params.from,
|
|
2221
|
+
dryRun: params.dryRun
|
|
2214
2222
|
});
|
|
2215
2223
|
}
|
|
2216
2224
|
/**
|
|
@@ -2233,8 +2241,21 @@ var WorkerClient = class {
|
|
|
2233
2241
|
method,
|
|
2234
2242
|
params: { ctx: this.contextId, ...params }
|
|
2235
2243
|
};
|
|
2244
|
+
const timeoutMs = this.requestTimeoutMs;
|
|
2236
2245
|
return new Promise((resolve4, reject) => {
|
|
2237
|
-
|
|
2246
|
+
const call = { resolve: resolve4, reject };
|
|
2247
|
+
if (timeoutMs) {
|
|
2248
|
+
call.timer = setTimeout(() => {
|
|
2249
|
+
if (!this.pending.has(id)) return;
|
|
2250
|
+
this.pending.delete(id);
|
|
2251
|
+
const err = new Error(
|
|
2252
|
+
`request timeout after ${String(timeoutMs)}ms`
|
|
2253
|
+
);
|
|
2254
|
+
err.code = "REQUEST_TIMEOUT";
|
|
2255
|
+
reject(err);
|
|
2256
|
+
}, timeoutMs);
|
|
2257
|
+
}
|
|
2258
|
+
this.pending.set(id, call);
|
|
2238
2259
|
socket.write(JSON.stringify(request) + "\n");
|
|
2239
2260
|
});
|
|
2240
2261
|
}
|
|
@@ -2255,6 +2276,7 @@ var WorkerClient = class {
|
|
|
2255
2276
|
const pending = this.pending.get(response.id);
|
|
2256
2277
|
if (pending) {
|
|
2257
2278
|
this.pending.delete(response.id);
|
|
2279
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
2258
2280
|
if (response.error) {
|
|
2259
2281
|
const err = new Error(response.error.message);
|
|
2260
2282
|
err.code = response.error.code;
|
|
@@ -2328,101 +2350,397 @@ function discoverDaemon(contextId) {
|
|
|
2328
2350
|
}
|
|
2329
2351
|
return null;
|
|
2330
2352
|
}
|
|
2331
|
-
const socketPath = (0, import_node_path8.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.sock`);
|
|
2332
|
-
const crashPath = (0, import_node_path8.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.crash`);
|
|
2353
|
+
const socketPath = (0, import_node_path8.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.sock`);
|
|
2354
|
+
const crashPath = (0, import_node_path8.join)((0, import_node_os.tmpdir)(), `kbdb-${contextId}.crash`);
|
|
2355
|
+
try {
|
|
2356
|
+
(0, import_node_fs6.unlinkSync)(crashPath);
|
|
2357
|
+
} catch {
|
|
2358
|
+
}
|
|
2359
|
+
return { pid, socketPath };
|
|
2360
|
+
}
|
|
2361
|
+
|
|
2362
|
+
// src/shared/worker-client/functions/spawn-daemon.function.ts
|
|
2363
|
+
var import_node_child_process = require("node:child_process");
|
|
2364
|
+
function spawnDaemon(contextPath, runtime2, workerScript2) {
|
|
2365
|
+
if (!workerScript2) {
|
|
2366
|
+
throw new Error(
|
|
2367
|
+
"workerScript must be provided (resolve at entry point)"
|
|
2368
|
+
);
|
|
2369
|
+
}
|
|
2370
|
+
const execPath = runtime2 === "deno" ? "deno" : process.execPath;
|
|
2371
|
+
const args = runtime2 === "deno" ? ["run", "--allow-all", workerScript2, contextPath] : [workerScript2, contextPath];
|
|
2372
|
+
const child = (0, import_node_child_process.spawn)(execPath, args, {
|
|
2373
|
+
detached: true,
|
|
2374
|
+
stdio: "ignore"
|
|
2375
|
+
});
|
|
2376
|
+
child.unref();
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
// src/shared/worker-client/functions/wait-for-daemon.function.ts
|
|
2380
|
+
var import_node_fs7 = require("node:fs");
|
|
2381
|
+
var import_node_path9 = require("node:path");
|
|
2382
|
+
var import_node_os2 = require("node:os");
|
|
2383
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
2384
|
+
var POLL_INTERVAL_MS = 100;
|
|
2385
|
+
async function waitForDaemon(contextId, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
2386
|
+
const pidPath = (0, import_node_path9.join)((0, import_node_os2.tmpdir)(), `kbdb-${contextId}.pid`);
|
|
2387
|
+
const start = Date.now();
|
|
2388
|
+
while (Date.now() - start < timeoutMs) {
|
|
2389
|
+
if ((0, import_node_fs7.existsSync)(pidPath)) return true;
|
|
2390
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
2391
|
+
}
|
|
2392
|
+
return false;
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
// src/shared/platform/functions/get-ipc-path.function.ts
|
|
2396
|
+
var import_node_path10 = require("node:path");
|
|
2397
|
+
|
|
2398
|
+
// src/shared/platform/functions/get-tmpdir.function.ts
|
|
2399
|
+
var import_node_os3 = require("node:os");
|
|
2400
|
+
function getTmpdir() {
|
|
2401
|
+
return (0, import_node_os3.tmpdir)();
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
// src/shared/platform/functions/get-ipc-path.function.ts
|
|
2405
|
+
function getIpcPath(ctx) {
|
|
2406
|
+
if (process.platform === "win32") {
|
|
2407
|
+
return `\\\\.\\pipe\\kbdb-${ctx}`;
|
|
2408
|
+
}
|
|
2409
|
+
return (0, import_node_path10.join)(getTmpdir(), `kbdb-${ctx}.sock`);
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
// src/shared/worker-client/functions/create-worker-client.function.ts
|
|
2413
|
+
async function createWorkerClient(options) {
|
|
2414
|
+
const dbPath = options?.contextPath ?? resolveDbPath(options?.dbPath);
|
|
2415
|
+
const contextId = await computeContextId(dbPath);
|
|
2416
|
+
const socketPath = getIpcPath(contextId);
|
|
2417
|
+
let daemon = discoverDaemon(contextId);
|
|
2418
|
+
if (!daemon && options?.autoSpawn !== false) {
|
|
2419
|
+
const runtime2 = detectRuntime();
|
|
2420
|
+
spawnDaemon(dbPath, runtime2, options?.workerScript);
|
|
2421
|
+
await waitForDaemon(contextId, options?.connectTimeoutMs);
|
|
2422
|
+
daemon = discoverDaemon(contextId);
|
|
2423
|
+
}
|
|
2424
|
+
if (!daemon) {
|
|
2425
|
+
throw new Error(
|
|
2426
|
+
`kbdb worker daemon did not start: ${readCrashReason(contextId)}`
|
|
2427
|
+
);
|
|
2428
|
+
}
|
|
2429
|
+
const client = new WorkerClient(
|
|
2430
|
+
socketPath,
|
|
2431
|
+
contextId,
|
|
2432
|
+
options?.requestTimeoutMs
|
|
2433
|
+
);
|
|
2434
|
+
await client.connect();
|
|
2435
|
+
return client;
|
|
2436
|
+
}
|
|
2437
|
+
function readCrashReason(contextId) {
|
|
2438
|
+
const crashPath = (0, import_node_path11.join)((0, import_node_os4.tmpdir)(), `kbdb-${contextId}.crash`);
|
|
2439
|
+
if (!(0, import_node_fs8.existsSync)(crashPath)) {
|
|
2440
|
+
return "daemon failed to start (no details available)";
|
|
2441
|
+
}
|
|
2442
|
+
try {
|
|
2443
|
+
const raw = (0, import_node_fs8.readFileSync)(crashPath, "utf-8");
|
|
2444
|
+
const crash = JSON.parse(raw);
|
|
2445
|
+
(0, import_node_fs8.unlinkSync)(crashPath);
|
|
2446
|
+
return crash.error ?? "unknown error (crash log empty)";
|
|
2447
|
+
} catch {
|
|
2448
|
+
return "daemon failed to start (crash log unreadable)";
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
// src/shared/cli/functions/run-worker-stop.function.ts
|
|
2453
|
+
async function runWorkerStop(dbDir) {
|
|
2454
|
+
const contextId = await computeContextId(dbDir);
|
|
2455
|
+
const info = discoverDaemon(contextId);
|
|
2456
|
+
if (!info) {
|
|
2457
|
+
return { output: "no daemon running", exitCode: 0 };
|
|
2458
|
+
}
|
|
2459
|
+
try {
|
|
2460
|
+
process.kill(info.pid, "SIGTERM");
|
|
2461
|
+
return {
|
|
2462
|
+
output: `stopped daemon (pid ${info.pid.toString()})`,
|
|
2463
|
+
exitCode: 0
|
|
2464
|
+
};
|
|
2465
|
+
} catch {
|
|
2466
|
+
return {
|
|
2467
|
+
error: "error: failed to stop daemon",
|
|
2468
|
+
exitCode: 1
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
// src/shared/cli/functions/run-worker-restart.function.ts
|
|
2474
|
+
async function runWorkerRestart(dbDir) {
|
|
2475
|
+
const stopResult = await runWorkerStop(dbDir);
|
|
2476
|
+
if (stopResult.exitCode !== 0) return stopResult;
|
|
2477
|
+
return {
|
|
2478
|
+
output: "daemon will restart on next command",
|
|
2479
|
+
exitCode: 0
|
|
2480
|
+
};
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
// src/shared/cli/functions/resolve-raw-db-path.function.ts
|
|
2484
|
+
function resolveRawDbPath(options) {
|
|
2485
|
+
return options.dbPath ?? process.env["KBDB_DB_DIR"];
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
// src/shared/worker-client/functions/retry-on-timeout.function.ts
|
|
2489
|
+
async function retryOnTimeout(createClient, operation, maxRetries) {
|
|
2490
|
+
let lastError = new Error("retryOnTimeout exhausted");
|
|
2491
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
2492
|
+
const client = await createClient();
|
|
2493
|
+
try {
|
|
2494
|
+
const result = await operation(client);
|
|
2495
|
+
return { client, result };
|
|
2496
|
+
} catch (err) {
|
|
2497
|
+
const code = err.code;
|
|
2498
|
+
if (code !== "REQUEST_TIMEOUT" || attempt >= maxRetries) {
|
|
2499
|
+
client.disconnect();
|
|
2500
|
+
throw err;
|
|
2501
|
+
}
|
|
2502
|
+
lastError = err;
|
|
2503
|
+
client.disconnect();
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
throw lastError;
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
// src/shared/worker-client/constants/request-timeout.constant.ts
|
|
2510
|
+
var DEFAULT_REQUEST_TIMEOUT_MS = 3e4;
|
|
2511
|
+
|
|
2512
|
+
// src/shared/worker-client/constants/retry-defaults.constant.ts
|
|
2513
|
+
var DEFAULT_RETRY_COUNT = 5;
|
|
2514
|
+
|
|
2515
|
+
// src/shared/cli/functions/run-cli.function.ts
|
|
2516
|
+
async function runCli(argv, deps2) {
|
|
2517
|
+
const options = parseArgs(argv);
|
|
2518
|
+
if (!options.formatExplicit) {
|
|
2519
|
+
options.format = deps2.isStdoutTty() ? "text" : "json";
|
|
2520
|
+
}
|
|
2521
|
+
if (options.command === "help" || !options.command) {
|
|
2522
|
+
const helpCommand = options.args[0];
|
|
2523
|
+
const helpSubcommand = options.args[1];
|
|
2524
|
+
const helpText = generateHelp(helpCommand, helpSubcommand);
|
|
2525
|
+
if (helpCommand && !isKnownCommand(helpCommand)) {
|
|
2526
|
+
return { output: helpText, exitCode: 1 };
|
|
2527
|
+
}
|
|
2528
|
+
return { output: helpText, exitCode: 0 };
|
|
2529
|
+
}
|
|
2530
|
+
if (options.command === "version") {
|
|
2531
|
+
return { output: VERSION, exitCode: 0 };
|
|
2532
|
+
}
|
|
2533
|
+
if (options.command === "init" || options.command === "db-init") {
|
|
2534
|
+
return handleInit(options, deps2);
|
|
2535
|
+
}
|
|
2536
|
+
if (options.command === "mcp") {
|
|
2537
|
+
return handleMcp(options, deps2);
|
|
2538
|
+
}
|
|
2539
|
+
if (options.command === "migrate" || options.command === "db-migrate") {
|
|
2540
|
+
return handleMigrate(options, deps2);
|
|
2541
|
+
}
|
|
2542
|
+
if (options.command === "worker-stop") {
|
|
2543
|
+
return handleWorkerLifecycle(options, deps2, runWorkerStop);
|
|
2544
|
+
}
|
|
2545
|
+
if (options.command === "worker-restart") {
|
|
2546
|
+
return handleWorkerLifecycle(options, deps2, runWorkerRestart);
|
|
2547
|
+
}
|
|
2548
|
+
return handleDataCommand(options, deps2);
|
|
2549
|
+
}
|
|
2550
|
+
function handleInit(options, deps2) {
|
|
2551
|
+
const result = deps2.runInit(options);
|
|
2552
|
+
if (result.ok) {
|
|
2553
|
+
return {
|
|
2554
|
+
output: result.targetPath,
|
|
2555
|
+
exitCode: 0
|
|
2556
|
+
};
|
|
2557
|
+
}
|
|
2558
|
+
return {
|
|
2559
|
+
error: `error: ${result.errorMessage ?? "init failed"}`,
|
|
2560
|
+
exitCode: 1
|
|
2561
|
+
};
|
|
2562
|
+
}
|
|
2563
|
+
function resolveTimeoutMs(options) {
|
|
2564
|
+
return options.timeoutMs ?? (parseInt(process.env["KBDB_DAEMON_TIMEOUT"] ?? "", 10) || DEFAULT_REQUEST_TIMEOUT_MS);
|
|
2565
|
+
}
|
|
2566
|
+
function resolveRetryCount(options) {
|
|
2567
|
+
return options.retry ?? (parseInt(process.env["KBDB_RETRY"] ?? "", 10) || DEFAULT_RETRY_COUNT);
|
|
2568
|
+
}
|
|
2569
|
+
async function handleMcp(options, deps2) {
|
|
2570
|
+
const explicitPath = resolveRawDbPath(options);
|
|
2571
|
+
const dbDir = deps2.findDb(explicitPath);
|
|
2572
|
+
if (!dbDir) {
|
|
2573
|
+
return {
|
|
2574
|
+
error: "error: no .kbdb database found at " + (explicitPath ?? process.cwd()),
|
|
2575
|
+
exitCode: 1
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
const timeoutMs = resolveTimeoutMs(options);
|
|
2579
|
+
const maxRetries = resolveRetryCount(options);
|
|
2580
|
+
let client;
|
|
2581
|
+
try {
|
|
2582
|
+
client = await deps2.createWorkerClient({
|
|
2583
|
+
contextPath: dbDir,
|
|
2584
|
+
requestTimeoutMs: timeoutMs
|
|
2585
|
+
});
|
|
2586
|
+
} catch (err) {
|
|
2587
|
+
return {
|
|
2588
|
+
error: `error: ${errorToMessage(err)}`,
|
|
2589
|
+
exitCode: 1
|
|
2590
|
+
};
|
|
2591
|
+
}
|
|
2592
|
+
try {
|
|
2593
|
+
const gateResult = await versionGate(client, dbDir);
|
|
2594
|
+
if (gateResult) return gateResult;
|
|
2595
|
+
if (deps2.startMcpServer) {
|
|
2596
|
+
await deps2.startMcpServer(
|
|
2597
|
+
dbDir,
|
|
2598
|
+
() => deps2.createWorkerClient({
|
|
2599
|
+
contextPath: dbDir,
|
|
2600
|
+
requestTimeoutMs: timeoutMs
|
|
2601
|
+
}),
|
|
2602
|
+
maxRetries
|
|
2603
|
+
);
|
|
2604
|
+
}
|
|
2605
|
+
return { exitCode: 0 };
|
|
2606
|
+
} catch (err) {
|
|
2607
|
+
return {
|
|
2608
|
+
error: `error: mcp failed: ${errorToMessage(err)}`,
|
|
2609
|
+
exitCode: 1
|
|
2610
|
+
};
|
|
2611
|
+
} finally {
|
|
2612
|
+
client.disconnect();
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
async function handleMigrate(options, deps2) {
|
|
2616
|
+
const dbDir = deps2.findDb(options.dbPath);
|
|
2617
|
+
if (!dbDir) {
|
|
2618
|
+
const basePath = options.dbPath ?? process.cwd();
|
|
2619
|
+
return {
|
|
2620
|
+
error: `error: no .kbdb database found at ${basePath}`,
|
|
2621
|
+
exitCode: 1
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
let client;
|
|
2625
|
+
try {
|
|
2626
|
+
client = await deps2.createWorkerClient({
|
|
2627
|
+
contextPath: dbDir
|
|
2628
|
+
});
|
|
2629
|
+
} catch (err) {
|
|
2630
|
+
return {
|
|
2631
|
+
error: `error: ${errorToMessage(err)}`,
|
|
2632
|
+
exitCode: 1
|
|
2633
|
+
};
|
|
2634
|
+
}
|
|
2333
2635
|
try {
|
|
2334
|
-
|
|
2335
|
-
|
|
2636
|
+
const versionStatus = await client.checkVersion(dbDir);
|
|
2637
|
+
if (versionStatus.status === "too_new") {
|
|
2638
|
+
return {
|
|
2639
|
+
error: `error: database version ${versionStatus.currentVersion.toString()} is newer than kbdb version ${versionStatus.requiredVersion.toString()} -- upgrade kbdb`,
|
|
2640
|
+
exitCode: 1
|
|
2641
|
+
};
|
|
2642
|
+
}
|
|
2643
|
+
if (versionStatus.status === "needs_migration") {
|
|
2644
|
+
const migrateResult = await client.migrateDatabase(dbDir);
|
|
2645
|
+
return {
|
|
2646
|
+
output: JSON.stringify(migrateResult, null, 2),
|
|
2647
|
+
exitCode: 0
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
return { output: "already up to date", exitCode: 0 };
|
|
2651
|
+
} catch (err) {
|
|
2652
|
+
return {
|
|
2653
|
+
error: `error: migrate failed: ${errorToMessage(err)}`,
|
|
2654
|
+
exitCode: 1
|
|
2655
|
+
};
|
|
2656
|
+
} finally {
|
|
2657
|
+
client.disconnect();
|
|
2336
2658
|
}
|
|
2337
|
-
return { pid, socketPath };
|
|
2338
2659
|
}
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2660
|
+
async function handleDataCommand(options, deps2) {
|
|
2661
|
+
const explicitPath = resolveRawDbPath(options);
|
|
2662
|
+
let dbDir = deps2.findDb(explicitPath);
|
|
2663
|
+
if (!dbDir) {
|
|
2664
|
+
const basePath = explicitPath ?? process.cwd();
|
|
2665
|
+
if (!deps2.isStdinTty()) {
|
|
2666
|
+
return {
|
|
2667
|
+
error: `error: no .kbdb database found at ${basePath} -- run \`kbdb --init\` to create one`,
|
|
2668
|
+
exitCode: 1
|
|
2669
|
+
};
|
|
2670
|
+
}
|
|
2671
|
+
const answer = await deps2.promptUser(
|
|
2672
|
+
`No .kbdb database found. Create one in ${basePath}? [y/N] `
|
|
2346
2673
|
);
|
|
2674
|
+
if (answer.toLowerCase() !== "y") {
|
|
2675
|
+
return {
|
|
2676
|
+
error: "aborted: no database created",
|
|
2677
|
+
exitCode: 1
|
|
2678
|
+
};
|
|
2679
|
+
}
|
|
2680
|
+
const initResult = deps2.runInit(options);
|
|
2681
|
+
if (!initResult.ok) {
|
|
2682
|
+
return {
|
|
2683
|
+
error: `error: ${initResult.errorMessage ?? "init failed"}`,
|
|
2684
|
+
exitCode: 1
|
|
2685
|
+
};
|
|
2686
|
+
}
|
|
2687
|
+
dbDir = initResult.targetPath;
|
|
2347
2688
|
}
|
|
2348
|
-
const
|
|
2349
|
-
const
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
}
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
return false;
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
// src/shared/platform/functions/get-ipc-path.function.ts
|
|
2374
|
-
var import_node_path10 = require("node:path");
|
|
2375
|
-
|
|
2376
|
-
// src/shared/platform/functions/get-tmpdir.function.ts
|
|
2377
|
-
var import_node_os3 = require("node:os");
|
|
2378
|
-
function getTmpdir() {
|
|
2379
|
-
return (0, import_node_os3.tmpdir)();
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
// src/shared/platform/functions/get-ipc-path.function.ts
|
|
2383
|
-
function getIpcPath(ctx) {
|
|
2384
|
-
if (process.platform === "win32") {
|
|
2385
|
-
return `\\\\.\\pipe\\kbdb-${ctx}`;
|
|
2689
|
+
const timeoutMs = resolveTimeoutMs(options);
|
|
2690
|
+
const maxRetries = resolveRetryCount(options);
|
|
2691
|
+
try {
|
|
2692
|
+
const { client, result } = await retryOnTimeout(
|
|
2693
|
+
() => deps2.createWorkerClient({
|
|
2694
|
+
contextPath: dbDir,
|
|
2695
|
+
requestTimeoutMs: timeoutMs
|
|
2696
|
+
}),
|
|
2697
|
+
async (c) => {
|
|
2698
|
+
const gateResult = await versionGate(c, dbDir);
|
|
2699
|
+
if (gateResult) return gateResult;
|
|
2700
|
+
return dispatchCommand(c, options);
|
|
2701
|
+
},
|
|
2702
|
+
maxRetries
|
|
2703
|
+
);
|
|
2704
|
+
client.disconnect();
|
|
2705
|
+
return result;
|
|
2706
|
+
} catch (err) {
|
|
2707
|
+
return {
|
|
2708
|
+
error: `error: ${errorToMessage(err)}`,
|
|
2709
|
+
exitCode: 1
|
|
2710
|
+
};
|
|
2386
2711
|
}
|
|
2387
|
-
return (0, import_node_path10.join)(getTmpdir(), `kbdb-${ctx}.sock`);
|
|
2388
2712
|
}
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
const runtime2 = detectRuntime();
|
|
2398
|
-
spawnDaemon(dbPath, runtime2, options?.workerScript);
|
|
2399
|
-
await waitForDaemon(contextId, options?.connectTimeoutMs);
|
|
2400
|
-
daemon = discoverDaemon(contextId);
|
|
2401
|
-
}
|
|
2402
|
-
if (!daemon) {
|
|
2403
|
-
throw new Error(
|
|
2404
|
-
`kbdb worker daemon did not start: ${readCrashReason(contextId)}`
|
|
2405
|
-
);
|
|
2713
|
+
async function handleWorkerLifecycle(options, deps2, action) {
|
|
2714
|
+
const explicitPath = resolveRawDbPath(options);
|
|
2715
|
+
const dbDir = deps2.findDb(explicitPath);
|
|
2716
|
+
if (!dbDir) {
|
|
2717
|
+
return {
|
|
2718
|
+
error: "error: no .kbdb database found at " + (explicitPath ?? process.cwd()),
|
|
2719
|
+
exitCode: 1
|
|
2720
|
+
};
|
|
2406
2721
|
}
|
|
2407
|
-
|
|
2408
|
-
await client.connect();
|
|
2409
|
-
return client;
|
|
2722
|
+
return action(dbDir);
|
|
2410
2723
|
}
|
|
2411
|
-
function
|
|
2412
|
-
const
|
|
2413
|
-
if (
|
|
2414
|
-
return
|
|
2724
|
+
async function versionGate(client, dbDir) {
|
|
2725
|
+
const versionStatus = await client.checkVersion(dbDir);
|
|
2726
|
+
if (versionStatus.status === "needs_migration") {
|
|
2727
|
+
return {
|
|
2728
|
+
error: "error: database needs migration -- run `kbdb --migrate`",
|
|
2729
|
+
exitCode: 1
|
|
2730
|
+
};
|
|
2415
2731
|
}
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
} catch {
|
|
2422
|
-
return "daemon failed to start (crash log unreadable)";
|
|
2732
|
+
if (versionStatus.status === "too_new") {
|
|
2733
|
+
return {
|
|
2734
|
+
error: `error: database version ${versionStatus.currentVersion.toString()} is newer than kbdb version ${versionStatus.requiredVersion.toString()} -- upgrade kbdb`,
|
|
2735
|
+
exitCode: 1
|
|
2736
|
+
};
|
|
2423
2737
|
}
|
|
2738
|
+
return null;
|
|
2424
2739
|
}
|
|
2425
2740
|
|
|
2741
|
+
// src/shared/cli/constants/help-text.constant.ts
|
|
2742
|
+
var HELP_TEXT = generateHelp();
|
|
2743
|
+
|
|
2426
2744
|
// src/shared/mcp/classes/mcp-server.class.ts
|
|
2427
2745
|
var import_node_readline2 = require("node:readline");
|
|
2428
2746
|
|
|
@@ -2456,6 +2774,10 @@ function createToolDefinitions() {
|
|
|
2456
2774
|
type: "string",
|
|
2457
2775
|
enum: ["lexical", "vector", "hybrid"],
|
|
2458
2776
|
description: "Search algorithm (default: lexical)"
|
|
2777
|
+
},
|
|
2778
|
+
relaxed: {
|
|
2779
|
+
type: "boolean",
|
|
2780
|
+
description: "Use relaxed (OR) matching when the strict query returns no results"
|
|
2459
2781
|
}
|
|
2460
2782
|
},
|
|
2461
2783
|
required: ["query"]
|
|
@@ -3207,7 +3529,8 @@ async function handleSearch2(client, args) {
|
|
|
3207
3529
|
mode: args["mode"],
|
|
3208
3530
|
limit: args["limit"],
|
|
3209
3531
|
offset: args["offset"],
|
|
3210
|
-
algo: args["algo"]
|
|
3532
|
+
algo: args["algo"],
|
|
3533
|
+
relaxed: args["relaxed"]
|
|
3211
3534
|
});
|
|
3212
3535
|
const stripped = {
|
|
3213
3536
|
...results,
|
|
@@ -3774,6 +4097,125 @@ function shouldEmitLog(messageLevel, threshold) {
|
|
|
3774
4097
|
return messageIndex >= thresholdIndex;
|
|
3775
4098
|
}
|
|
3776
4099
|
|
|
4100
|
+
// src/shared/auto-capture/functions/build-capture-prompt.function.ts
|
|
4101
|
+
function buildCapturePrompt(recentContext) {
|
|
4102
|
+
return "Review the following conversation context and identify factual knowledge worth storing in the knowledge base.\n\nRules:\n- Include durable facts, decisions, preferences, and corrections that would be useful in future sessions.\n- Exclude ephemeral, task-specific, or temporary information that has no lasting value.\n- Format each piece of extracted knowledge as a concise statement suitable for direct storage.\n- If no durable knowledge is found, respond with an empty list.\n\nConversation context:\n" + recentContext;
|
|
4103
|
+
}
|
|
4104
|
+
|
|
4105
|
+
// src/shared/mcp/functions/has-sampling-capability.function.ts
|
|
4106
|
+
function hasSamplingCapability(hostCapabilities) {
|
|
4107
|
+
if (hostCapabilities === null) return false;
|
|
4108
|
+
return Boolean(hostCapabilities["sampling"]);
|
|
4109
|
+
}
|
|
4110
|
+
|
|
4111
|
+
// src/shared/mcp/functions/run-auto-capture.function.ts
|
|
4112
|
+
function isSamplingResponse(v) {
|
|
4113
|
+
if (typeof v !== "object" || v === null) return false;
|
|
4114
|
+
const obj = v;
|
|
4115
|
+
const content = obj["content"];
|
|
4116
|
+
if (typeof content !== "object" || content === null) return false;
|
|
4117
|
+
return typeof content["text"] === "string";
|
|
4118
|
+
}
|
|
4119
|
+
async function runAutoCapture(controller, config, client, hostCapabilities, requestSampling) {
|
|
4120
|
+
try {
|
|
4121
|
+
const trigger = controller.evaluate();
|
|
4122
|
+
if (!trigger.shouldCapture) return;
|
|
4123
|
+
if (!hasSamplingCapability(hostCapabilities)) return;
|
|
4124
|
+
const prompt = buildCapturePrompt("recent conversation context");
|
|
4125
|
+
const messages = [
|
|
4126
|
+
{ role: "user", content: { type: "text", text: prompt } }
|
|
4127
|
+
];
|
|
4128
|
+
const raw = await requestSampling(messages, 1024);
|
|
4129
|
+
if (!isSamplingResponse(raw)) return;
|
|
4130
|
+
const text = raw.content.text.trim();
|
|
4131
|
+
if (!text) return;
|
|
4132
|
+
if (config.dryRun) return;
|
|
4133
|
+
await client.addSection({
|
|
4134
|
+
sectionType: "text/markdown",
|
|
4135
|
+
content: text,
|
|
4136
|
+
title: "Auto-captured knowledge"
|
|
4137
|
+
});
|
|
4138
|
+
} catch {
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4142
|
+
// src/shared/auto-capture/functions/evaluate-trigger.function.ts
|
|
4143
|
+
function evaluateTrigger(config, state) {
|
|
4144
|
+
if (!config.enabled) {
|
|
4145
|
+
return {
|
|
4146
|
+
shouldCapture: false,
|
|
4147
|
+
reason: "auto-capture is disabled"
|
|
4148
|
+
};
|
|
4149
|
+
}
|
|
4150
|
+
if (state.totalCapturesThisSession >= config.maxCapturesPerSession) {
|
|
4151
|
+
return {
|
|
4152
|
+
shouldCapture: false,
|
|
4153
|
+
reason: "session capture limit reached"
|
|
4154
|
+
};
|
|
4155
|
+
}
|
|
4156
|
+
const elapsed = state.lastCaptureTimestamp ? Date.now() - state.lastCaptureTimestamp : Infinity;
|
|
4157
|
+
if (elapsed < config.minIntervalMs) {
|
|
4158
|
+
return {
|
|
4159
|
+
shouldCapture: false,
|
|
4160
|
+
reason: "within minimum interval"
|
|
4161
|
+
};
|
|
4162
|
+
}
|
|
4163
|
+
if (state.toolCallsSinceLastCapture < config.triggerAfterToolCalls) {
|
|
4164
|
+
return {
|
|
4165
|
+
shouldCapture: false,
|
|
4166
|
+
reason: "tool call threshold not yet reached"
|
|
4167
|
+
};
|
|
4168
|
+
}
|
|
4169
|
+
return { shouldCapture: true, reason: "trigger threshold met" };
|
|
4170
|
+
}
|
|
4171
|
+
|
|
4172
|
+
// src/shared/auto-capture/classes/auto-capture-controller.class.ts
|
|
4173
|
+
var AutoCaptureController = class {
|
|
4174
|
+
toolCallsSinceLastCapture = 0;
|
|
4175
|
+
lastCaptureTimestamp = 0;
|
|
4176
|
+
totalCapturesThisSession = 0;
|
|
4177
|
+
config;
|
|
4178
|
+
/** @param config - the auto-capture configuration to use */
|
|
4179
|
+
constructor(config) {
|
|
4180
|
+
this.config = config;
|
|
4181
|
+
}
|
|
4182
|
+
/** Record one tool call for trigger counting. */
|
|
4183
|
+
recordToolCall() {
|
|
4184
|
+
this.toolCallsSinceLastCapture += 1;
|
|
4185
|
+
}
|
|
4186
|
+
/**
|
|
4187
|
+
* Evaluates the current state against the trigger criteria.
|
|
4188
|
+
*
|
|
4189
|
+
* When the trigger fires, advances the session counters so the
|
|
4190
|
+
* next evaluation respects rate limiting and the session cap.
|
|
4191
|
+
*
|
|
4192
|
+
* @returns the trigger decision with a human-readable reason
|
|
4193
|
+
*/
|
|
4194
|
+
evaluate() {
|
|
4195
|
+
const trigger = evaluateTrigger(this.config, this.state());
|
|
4196
|
+
if (trigger.shouldCapture) {
|
|
4197
|
+
this.totalCapturesThisSession += 1;
|
|
4198
|
+
this.lastCaptureTimestamp = Date.now();
|
|
4199
|
+
this.toolCallsSinceLastCapture = 0;
|
|
4200
|
+
}
|
|
4201
|
+
return trigger;
|
|
4202
|
+
}
|
|
4203
|
+
/** Reset all counters, e.g. on client disconnect. */
|
|
4204
|
+
reset() {
|
|
4205
|
+
this.toolCallsSinceLastCapture = 0;
|
|
4206
|
+
this.lastCaptureTimestamp = 0;
|
|
4207
|
+
this.totalCapturesThisSession = 0;
|
|
4208
|
+
}
|
|
4209
|
+
/** Returns a snapshot of the current controller state. */
|
|
4210
|
+
state() {
|
|
4211
|
+
return {
|
|
4212
|
+
toolCallsSinceLastCapture: this.toolCallsSinceLastCapture,
|
|
4213
|
+
lastCaptureTimestamp: this.lastCaptureTimestamp,
|
|
4214
|
+
totalCapturesThisSession: this.totalCapturesThisSession
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
};
|
|
4218
|
+
|
|
3777
4219
|
// src/shared/mcp/constants/mcp-error-codes.constant.ts
|
|
3778
4220
|
var PARSE_ERROR = -32700;
|
|
3779
4221
|
var METHOD_NOT_FOUND = -32601;
|
|
@@ -3783,15 +4225,50 @@ var RESOURCE_NOT_FOUND = -32002;
|
|
|
3783
4225
|
var McpServer = class {
|
|
3784
4226
|
client;
|
|
3785
4227
|
contextPath;
|
|
4228
|
+
autoCaptureConfig;
|
|
4229
|
+
clientFactory;
|
|
4230
|
+
maxRetries;
|
|
4231
|
+
autoCaptureController = null;
|
|
3786
4232
|
initialized = false;
|
|
3787
4233
|
hostCapabilities = null;
|
|
3788
4234
|
logLevel = null;
|
|
3789
4235
|
subscriptions = /* @__PURE__ */ new Set();
|
|
3790
4236
|
nextRequestId = 1;
|
|
3791
4237
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
3792
|
-
|
|
4238
|
+
/**
|
|
4239
|
+
* @param client - worker client providing knowledge-base operations
|
|
4240
|
+
* @param contextPath - absolute path to the `.kbdb` directory
|
|
4241
|
+
* @param autoCaptureConfig - optional auto-capture configuration;
|
|
4242
|
+
* when provided the server activates auto-capture on connection
|
|
4243
|
+
* @param clientFactory - creates a fresh worker client (for retry)
|
|
4244
|
+
* @param maxRetries - max retries on REQUEST_TIMEOUT
|
|
4245
|
+
*/
|
|
4246
|
+
constructor(client, contextPath, autoCaptureConfig, clientFactory, maxRetries) {
|
|
3793
4247
|
this.client = client;
|
|
3794
4248
|
this.contextPath = contextPath ?? "";
|
|
4249
|
+
this.autoCaptureConfig = autoCaptureConfig ?? null;
|
|
4250
|
+
this.clientFactory = clientFactory ?? null;
|
|
4251
|
+
this.maxRetries = maxRetries ?? DEFAULT_RETRY_COUNT;
|
|
4252
|
+
}
|
|
4253
|
+
async reconnectClient() {
|
|
4254
|
+
if (!this.clientFactory) {
|
|
4255
|
+
throw new Error("no client factory for reconnect");
|
|
4256
|
+
}
|
|
4257
|
+
this.client.disconnect();
|
|
4258
|
+
this.client = await this.clientFactory();
|
|
4259
|
+
}
|
|
4260
|
+
async withRetry(fn) {
|
|
4261
|
+
for (let attempt = 0; ; attempt++) {
|
|
4262
|
+
try {
|
|
4263
|
+
return await fn();
|
|
4264
|
+
} catch (err) {
|
|
4265
|
+
const code = err.code;
|
|
4266
|
+
if (code !== "REQUEST_TIMEOUT" || attempt >= this.maxRetries || !this.clientFactory) {
|
|
4267
|
+
throw err;
|
|
4268
|
+
}
|
|
4269
|
+
await this.reconnectClient();
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
3795
4272
|
}
|
|
3796
4273
|
async listen() {
|
|
3797
4274
|
const rl = (0, import_node_readline2.createInterface)({
|
|
@@ -3805,6 +4282,8 @@ var McpServer = class {
|
|
|
3805
4282
|
});
|
|
3806
4283
|
rl.on("close", () => {
|
|
3807
4284
|
void pending.then(() => {
|
|
4285
|
+
this.autoCaptureController?.reset();
|
|
4286
|
+
this.autoCaptureController = null;
|
|
3808
4287
|
this.client.disconnect();
|
|
3809
4288
|
resolve4();
|
|
3810
4289
|
});
|
|
@@ -3919,6 +4398,9 @@ var McpServer = class {
|
|
|
3919
4398
|
if (request.method === "notifications/initialized" || request.method === "notifications/cancelled") {
|
|
3920
4399
|
if (request.method === "notifications/initialized" && !this.initialized) {
|
|
3921
4400
|
this.initialized = true;
|
|
4401
|
+
if (this.autoCaptureConfig !== null) {
|
|
4402
|
+
this.autoCaptureController = new AutoCaptureController(this.autoCaptureConfig);
|
|
4403
|
+
}
|
|
3922
4404
|
void this.runStartupHealthCheck();
|
|
3923
4405
|
}
|
|
3924
4406
|
}
|
|
@@ -3952,7 +4434,7 @@ var McpServer = class {
|
|
|
3952
4434
|
protocolVersion: "2025-11-25",
|
|
3953
4435
|
serverInfo: {
|
|
3954
4436
|
name: "kbdb",
|
|
3955
|
-
version:
|
|
4437
|
+
version: VERSION
|
|
3956
4438
|
},
|
|
3957
4439
|
capabilities: {
|
|
3958
4440
|
tools: {},
|
|
@@ -3993,11 +4475,10 @@ var McpServer = class {
|
|
|
3993
4475
|
const rawName = params["name"];
|
|
3994
4476
|
const name = typeof rawName === "string" ? rawName : "";
|
|
3995
4477
|
const args = params["arguments"] ?? {};
|
|
3996
|
-
const result = await
|
|
3997
|
-
this.client,
|
|
3998
|
-
name,
|
|
3999
|
-
args
|
|
4478
|
+
const result = await this.withRetry(
|
|
4479
|
+
() => handleToolCall(this.client, name, args)
|
|
4000
4480
|
);
|
|
4481
|
+
this.afterToolCall();
|
|
4001
4482
|
return { jsonrpc: "2.0", id, result };
|
|
4002
4483
|
}
|
|
4003
4484
|
case "resources/read": {
|
|
@@ -4005,9 +4486,8 @@ var McpServer = class {
|
|
|
4005
4486
|
const rawUri = params["uri"];
|
|
4006
4487
|
const uri = typeof rawUri === "string" ? rawUri : "";
|
|
4007
4488
|
try {
|
|
4008
|
-
const result = await
|
|
4009
|
-
this.client,
|
|
4010
|
-
uri
|
|
4489
|
+
const result = await this.withRetry(
|
|
4490
|
+
() => handleResourceRead(this.client, uri)
|
|
4011
4491
|
);
|
|
4012
4492
|
return { jsonrpc: "2.0", id, result };
|
|
4013
4493
|
} catch (err) {
|
|
@@ -4112,6 +4592,23 @@ var McpServer = class {
|
|
|
4112
4592
|
const json = JSON.stringify(response);
|
|
4113
4593
|
process.stdout.write(json + "\n");
|
|
4114
4594
|
}
|
|
4595
|
+
/**
|
|
4596
|
+
* Records a tool call in the auto-capture controller and fires
|
|
4597
|
+
* a capture when the trigger condition is met.
|
|
4598
|
+
*/
|
|
4599
|
+
afterToolCall() {
|
|
4600
|
+
const ctrl = this.autoCaptureController;
|
|
4601
|
+
const cfg = this.autoCaptureConfig;
|
|
4602
|
+
if (ctrl === null || cfg === null) return;
|
|
4603
|
+
ctrl.recordToolCall();
|
|
4604
|
+
void runAutoCapture(
|
|
4605
|
+
ctrl,
|
|
4606
|
+
cfg,
|
|
4607
|
+
this.client,
|
|
4608
|
+
this.hostCapabilities,
|
|
4609
|
+
(messages, maxTokens) => this.requestSampling(messages, maxTokens)
|
|
4610
|
+
);
|
|
4611
|
+
}
|
|
4115
4612
|
/**
|
|
4116
4613
|
* Runs an integrity check immediately after the MCP handshake
|
|
4117
4614
|
* completes. Emits a `notifications/message` warning when the
|
|
@@ -4136,8 +4633,133 @@ var McpServer = class {
|
|
|
4136
4633
|
};
|
|
4137
4634
|
|
|
4138
4635
|
// src/shared/mcp/functions/create-mcp-server.function.ts
|
|
4139
|
-
function createMcpServer(client) {
|
|
4140
|
-
return new McpServer(
|
|
4636
|
+
function createMcpServer(client, contextPath, autoCaptureConfig, clientFactory, maxRetries) {
|
|
4637
|
+
return new McpServer(
|
|
4638
|
+
client,
|
|
4639
|
+
contextPath,
|
|
4640
|
+
autoCaptureConfig,
|
|
4641
|
+
clientFactory,
|
|
4642
|
+
maxRetries
|
|
4643
|
+
);
|
|
4644
|
+
}
|
|
4645
|
+
|
|
4646
|
+
// src/shared/worker-daemon/constants/daemon-defaults.constant.ts
|
|
4647
|
+
var DEFAULT_ITEM_LIMIT = 1e3;
|
|
4648
|
+
var DEFAULT_INDEX_LIMIT = 100;
|
|
4649
|
+
var DEFAULT_TIMEOUT_MS2 = 3e5;
|
|
4650
|
+
var DEFAULT_ITEM_TTL_MS = 6e4;
|
|
4651
|
+
|
|
4652
|
+
// src/shared/worker-daemon/functions/parse-embedding-section.function.ts
|
|
4653
|
+
function parseEmbeddingSection(entries) {
|
|
4654
|
+
const provider = entries.get("provider");
|
|
4655
|
+
if (!provider) {
|
|
4656
|
+
return void 0;
|
|
4657
|
+
}
|
|
4658
|
+
const model = entries.get("model");
|
|
4659
|
+
const endpoint = entries.get("endpoint");
|
|
4660
|
+
const dimensionsRaw = entries.get("dimensions");
|
|
4661
|
+
const dimensions = dimensionsRaw ? parseInt(dimensionsRaw, 10) || void 0 : void 0;
|
|
4662
|
+
return {
|
|
4663
|
+
provider,
|
|
4664
|
+
...model !== void 0 ? { model } : {},
|
|
4665
|
+
...endpoint !== void 0 ? { endpoint } : {},
|
|
4666
|
+
...dimensions !== void 0 ? { dimensions } : {}
|
|
4667
|
+
};
|
|
4668
|
+
}
|
|
4669
|
+
|
|
4670
|
+
// src/shared/auto-capture/constants/auto-capture-defaults.constant.ts
|
|
4671
|
+
var AUTO_CAPTURE_DEFAULTS = {
|
|
4672
|
+
enabled: false,
|
|
4673
|
+
triggerAfterToolCalls: 5,
|
|
4674
|
+
minIntervalMs: 6e4,
|
|
4675
|
+
maxCapturesPerSession: 10,
|
|
4676
|
+
dryRun: false
|
|
4677
|
+
};
|
|
4678
|
+
|
|
4679
|
+
// src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts
|
|
4680
|
+
function parseAutoCaptureSection(entries) {
|
|
4681
|
+
const enabled = entries.has("enabled") ? entries.get("enabled") === "true" : AUTO_CAPTURE_DEFAULTS.enabled;
|
|
4682
|
+
const dryRun = entries.has("dry_run") ? entries.get("dry_run") === "true" : AUTO_CAPTURE_DEFAULTS.dryRun;
|
|
4683
|
+
const triggerRaw = entries.get("trigger_after_tool_calls");
|
|
4684
|
+
const triggerAfterToolCalls = triggerRaw ? parseInt(triggerRaw, 10) || AUTO_CAPTURE_DEFAULTS.triggerAfterToolCalls : AUTO_CAPTURE_DEFAULTS.triggerAfterToolCalls;
|
|
4685
|
+
const intervalRaw = entries.get("min_interval_ms");
|
|
4686
|
+
const minIntervalMs = intervalRaw ? parseInt(intervalRaw, 10) || AUTO_CAPTURE_DEFAULTS.minIntervalMs : AUTO_CAPTURE_DEFAULTS.minIntervalMs;
|
|
4687
|
+
const capRaw = entries.get("max_captures_per_session");
|
|
4688
|
+
const maxCapturesPerSession = capRaw ? parseInt(capRaw, 10) || AUTO_CAPTURE_DEFAULTS.maxCapturesPerSession : AUTO_CAPTURE_DEFAULTS.maxCapturesPerSession;
|
|
4689
|
+
return {
|
|
4690
|
+
enabled,
|
|
4691
|
+
triggerAfterToolCalls,
|
|
4692
|
+
minIntervalMs,
|
|
4693
|
+
maxCapturesPerSession,
|
|
4694
|
+
dryRun
|
|
4695
|
+
};
|
|
4696
|
+
}
|
|
4697
|
+
|
|
4698
|
+
// src/shared/worker-daemon/functions/parse-worker-toml.function.ts
|
|
4699
|
+
function applyRootKey(acc, key, value) {
|
|
4700
|
+
switch (key) {
|
|
4701
|
+
case "item_limit":
|
|
4702
|
+
acc.itemLimit = parseInt(value, 10) || DEFAULT_ITEM_LIMIT;
|
|
4703
|
+
break;
|
|
4704
|
+
case "index_limit":
|
|
4705
|
+
acc.indexLimit = parseInt(value, 10) || DEFAULT_INDEX_LIMIT;
|
|
4706
|
+
break;
|
|
4707
|
+
case "timeout_ms":
|
|
4708
|
+
acc.timeoutMs = parseInt(value, 10) || DEFAULT_TIMEOUT_MS2;
|
|
4709
|
+
break;
|
|
4710
|
+
case "item_ttl_ms":
|
|
4711
|
+
acc.itemTtlMs = parseInt(value, 10) || DEFAULT_ITEM_TTL_MS;
|
|
4712
|
+
break;
|
|
4713
|
+
default:
|
|
4714
|
+
break;
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4717
|
+
function parseWorkerToml(text, contextPath) {
|
|
4718
|
+
let section = "";
|
|
4719
|
+
const embeddingEntries = /* @__PURE__ */ new Map();
|
|
4720
|
+
const autoCaptureEntries = /* @__PURE__ */ new Map();
|
|
4721
|
+
const acc = {
|
|
4722
|
+
itemLimit: DEFAULT_ITEM_LIMIT,
|
|
4723
|
+
indexLimit: DEFAULT_INDEX_LIMIT,
|
|
4724
|
+
timeoutMs: DEFAULT_TIMEOUT_MS2,
|
|
4725
|
+
itemTtlMs: DEFAULT_ITEM_TTL_MS
|
|
4726
|
+
};
|
|
4727
|
+
for (const line of text.split("\n")) {
|
|
4728
|
+
const trimmed = line.trim();
|
|
4729
|
+
if (trimmed === "[embedding]") {
|
|
4730
|
+
section = "embedding";
|
|
4731
|
+
continue;
|
|
4732
|
+
}
|
|
4733
|
+
if (trimmed === "[auto_capture]") {
|
|
4734
|
+
section = "auto_capture";
|
|
4735
|
+
continue;
|
|
4736
|
+
}
|
|
4737
|
+
if (trimmed.startsWith("[")) {
|
|
4738
|
+
section = "";
|
|
4739
|
+
continue;
|
|
4740
|
+
}
|
|
4741
|
+
if (trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
4742
|
+
const eqIdx = trimmed.indexOf("=");
|
|
4743
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
4744
|
+
const value = trimmed.slice(eqIdx + 1).trim();
|
|
4745
|
+
if (section === "embedding") {
|
|
4746
|
+
embeddingEntries.set(key, value);
|
|
4747
|
+
continue;
|
|
4748
|
+
}
|
|
4749
|
+
if (section === "auto_capture") {
|
|
4750
|
+
autoCaptureEntries.set(key, value);
|
|
4751
|
+
continue;
|
|
4752
|
+
}
|
|
4753
|
+
applyRootKey(acc, key, value);
|
|
4754
|
+
}
|
|
4755
|
+
const embedding = parseEmbeddingSection(embeddingEntries);
|
|
4756
|
+
const autoCapture = autoCaptureEntries.size > 0 ? parseAutoCaptureSection(autoCaptureEntries) : void 0;
|
|
4757
|
+
return {
|
|
4758
|
+
contextPath,
|
|
4759
|
+
...acc,
|
|
4760
|
+
...embedding !== void 0 ? { embedding } : {},
|
|
4761
|
+
...autoCapture !== void 0 ? { autoCapture } : {}
|
|
4762
|
+
};
|
|
4141
4763
|
}
|
|
4142
4764
|
|
|
4143
4765
|
// src/cli.ts
|
|
@@ -4147,17 +4769,32 @@ var baseDir = resolveBaseDir(import_meta.url, import_meta.dirname);
|
|
|
4147
4769
|
var workerScript = resolveWorkerScript(baseDir.scriptDir, runtime);
|
|
4148
4770
|
var deps = {
|
|
4149
4771
|
isStdinTty,
|
|
4772
|
+
isStdoutTty: () => process.stdout.isTTY,
|
|
4150
4773
|
promptUser,
|
|
4151
4774
|
createWorkerClient: (opts) => createWorkerClient({ ...opts, workerScript }),
|
|
4152
4775
|
findDb,
|
|
4153
4776
|
runInit,
|
|
4154
|
-
startMcpServer: async (contextPath) => {
|
|
4777
|
+
startMcpServer: async (contextPath, clientFactory, maxRetries) => {
|
|
4155
4778
|
const client = await createWorkerClient({
|
|
4156
4779
|
contextPath,
|
|
4157
4780
|
workerScript
|
|
4158
4781
|
});
|
|
4159
4782
|
try {
|
|
4160
|
-
const
|
|
4783
|
+
const tomlPath = (0, import_node_path12.join)(contextPath, "worker.toml");
|
|
4784
|
+
let autoCaptureConfig;
|
|
4785
|
+
try {
|
|
4786
|
+
const tomlText = (0, import_node_fs9.readFileSync)(tomlPath, "utf-8");
|
|
4787
|
+
const daemonConfig = parseWorkerToml(tomlText, contextPath);
|
|
4788
|
+
autoCaptureConfig = daemonConfig.autoCapture;
|
|
4789
|
+
} catch {
|
|
4790
|
+
}
|
|
4791
|
+
const server = createMcpServer(
|
|
4792
|
+
client,
|
|
4793
|
+
contextPath,
|
|
4794
|
+
autoCaptureConfig,
|
|
4795
|
+
clientFactory,
|
|
4796
|
+
maxRetries
|
|
4797
|
+
);
|
|
4161
4798
|
await server.listen();
|
|
4162
4799
|
} finally {
|
|
4163
4800
|
client.disconnect();
|