@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/mod.cjs
CHANGED
|
@@ -23,13 +23,14 @@ __export(mod_exports, {
|
|
|
23
23
|
WorkerClient: () => WorkerClient,
|
|
24
24
|
computeContextId: () => computeContextId,
|
|
25
25
|
createWorkerClient: () => createWorkerClient,
|
|
26
|
+
getOrCreateClient: () => getOrCreateClient,
|
|
26
27
|
resolveDbPath: () => resolveDbPath,
|
|
27
28
|
version: () => VERSION
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(mod_exports);
|
|
30
31
|
|
|
31
32
|
// src/shared/version/constants/version.constant.ts
|
|
32
|
-
var VERSION = "0.
|
|
33
|
+
var VERSION = "0.4.0";
|
|
33
34
|
|
|
34
35
|
// src/shared/worker-client/classes/worker-client.class.ts
|
|
35
36
|
var import_node_net = require("node:net");
|
|
@@ -39,10 +40,13 @@ var WorkerClient = class {
|
|
|
39
40
|
* (or Windows named pipe path)
|
|
40
41
|
* @param contextId - 16-character context identifier sent as
|
|
41
42
|
* `ctx` in every JSON-RPC request
|
|
43
|
+
* @param requestTimeoutMs - per-request timeout in ms
|
|
44
|
+
* (0 or undefined disables the timeout)
|
|
42
45
|
*/
|
|
43
|
-
constructor(socketPath, contextId) {
|
|
46
|
+
constructor(socketPath, contextId, requestTimeoutMs) {
|
|
44
47
|
this.socketPath = socketPath;
|
|
45
48
|
this.contextId = contextId;
|
|
49
|
+
this.requestTimeoutMs = requestTimeoutMs;
|
|
46
50
|
}
|
|
47
51
|
/** Underlying socket; `null` when not connected. */
|
|
48
52
|
socket = null;
|
|
@@ -52,30 +56,85 @@ var WorkerClient = class {
|
|
|
52
56
|
pending = /* @__PURE__ */ new Map();
|
|
53
57
|
/** Partial line buffer for split TCP/IPC frames. */
|
|
54
58
|
buffer = "";
|
|
59
|
+
/** Whether the underlying socket is connected. */
|
|
60
|
+
get isConnected() {
|
|
61
|
+
return this.socket !== null;
|
|
62
|
+
}
|
|
55
63
|
/**
|
|
56
64
|
* Establishes the IPC connection to the worker daemon.
|
|
57
65
|
*
|
|
66
|
+
* Retries up to 5 times with exponential backoff on
|
|
67
|
+
* transient errors (`ENOENT`, `ECONNREFUSED`).
|
|
68
|
+
*
|
|
58
69
|
* @throws {Error} if the connection cannot be established
|
|
59
70
|
*/
|
|
60
71
|
async connect() {
|
|
72
|
+
const maxRetries = 5;
|
|
73
|
+
let delay = 50;
|
|
74
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
75
|
+
try {
|
|
76
|
+
await this.tryConnect();
|
|
77
|
+
return;
|
|
78
|
+
} catch (err) {
|
|
79
|
+
const code = err.code;
|
|
80
|
+
const retriable = code === "ENOENT" || code === "ECONNREFUSED";
|
|
81
|
+
if (!retriable || attempt === maxRetries) {
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
85
|
+
delay = Math.min(delay * 2, 1e3);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Destroys the IPC socket and clears the connection state. */
|
|
90
|
+
disconnect() {
|
|
91
|
+
if (this.socket) {
|
|
92
|
+
this.socket.destroy();
|
|
93
|
+
this.socket = null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Single connection attempt with keepalive and
|
|
98
|
+
* post-connect failure handlers.
|
|
99
|
+
*/
|
|
100
|
+
async tryConnect() {
|
|
61
101
|
return new Promise((resolve2, reject) => {
|
|
62
|
-
|
|
102
|
+
const sock = (0, import_node_net.connect)(this.socketPath, () => {
|
|
103
|
+
sock.removeListener("error", reject);
|
|
104
|
+
sock.setKeepAlive(true, 3e4);
|
|
105
|
+
sock.on("error", (err) => {
|
|
106
|
+
this.handleSocketFailure(err);
|
|
107
|
+
});
|
|
108
|
+
sock.on("close", () => {
|
|
109
|
+
if (this.pending.size > 0) {
|
|
110
|
+
this.handleSocketFailure(
|
|
111
|
+
new Error("connection closed")
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
this.socket = null;
|
|
115
|
+
});
|
|
116
|
+
this.socket = sock;
|
|
63
117
|
resolve2();
|
|
64
118
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
this.socket.on("data", (chunk) => {
|
|
119
|
+
sock.on("error", reject);
|
|
120
|
+
sock.on("data", (chunk) => {
|
|
69
121
|
this.handleData(chunk.toString());
|
|
70
122
|
});
|
|
71
123
|
});
|
|
72
124
|
}
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Rejects all pending calls and marks the client as
|
|
127
|
+
* disconnected.
|
|
128
|
+
*/
|
|
129
|
+
handleSocketFailure(err) {
|
|
130
|
+
const sock = this.socket;
|
|
131
|
+
this.socket = null;
|
|
132
|
+
for (const [id, call] of this.pending) {
|
|
133
|
+
this.pending.delete(id);
|
|
134
|
+
if (call.timer) clearTimeout(call.timer);
|
|
135
|
+
call.reject(err);
|
|
78
136
|
}
|
|
137
|
+
if (sock) sock.destroy();
|
|
79
138
|
}
|
|
80
139
|
/**
|
|
81
140
|
* Searches the knowledge base.
|
|
@@ -84,7 +143,10 @@ var WorkerClient = class {
|
|
|
84
143
|
* @returns paginated search results with metadata
|
|
85
144
|
*/
|
|
86
145
|
async search(params) {
|
|
87
|
-
return this.call("search",
|
|
146
|
+
return this.call("search", {
|
|
147
|
+
...params,
|
|
148
|
+
algo: params.algo
|
|
149
|
+
});
|
|
88
150
|
}
|
|
89
151
|
/**
|
|
90
152
|
* Retrieves full content and context for one or more sections by
|
|
@@ -335,7 +397,20 @@ var WorkerClient = class {
|
|
|
335
397
|
*/
|
|
336
398
|
async export(params) {
|
|
337
399
|
return this.call("export", {
|
|
338
|
-
targetPath: params?.path || void 0
|
|
400
|
+
targetPath: params?.path || void 0,
|
|
401
|
+
format: params?.format
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Imports an exported database from the given path.
|
|
406
|
+
*
|
|
407
|
+
* @param params - source path and dry-run flag
|
|
408
|
+
* @returns import report with counts and timing
|
|
409
|
+
*/
|
|
410
|
+
async import(params) {
|
|
411
|
+
return this.call("importDb", {
|
|
412
|
+
sourcePath: params.from,
|
|
413
|
+
dryRun: params.dryRun
|
|
339
414
|
});
|
|
340
415
|
}
|
|
341
416
|
/**
|
|
@@ -358,8 +433,21 @@ var WorkerClient = class {
|
|
|
358
433
|
method,
|
|
359
434
|
params: { ctx: this.contextId, ...params }
|
|
360
435
|
};
|
|
436
|
+
const timeoutMs = this.requestTimeoutMs;
|
|
361
437
|
return new Promise((resolve2, reject) => {
|
|
362
|
-
|
|
438
|
+
const call = { resolve: resolve2, reject };
|
|
439
|
+
if (timeoutMs) {
|
|
440
|
+
call.timer = setTimeout(() => {
|
|
441
|
+
if (!this.pending.has(id)) return;
|
|
442
|
+
this.pending.delete(id);
|
|
443
|
+
const err = new Error(
|
|
444
|
+
`request timeout after ${String(timeoutMs)}ms`
|
|
445
|
+
);
|
|
446
|
+
err.code = "REQUEST_TIMEOUT";
|
|
447
|
+
reject(err);
|
|
448
|
+
}, timeoutMs);
|
|
449
|
+
}
|
|
450
|
+
this.pending.set(id, call);
|
|
363
451
|
socket.write(JSON.stringify(request) + "\n");
|
|
364
452
|
});
|
|
365
453
|
}
|
|
@@ -380,6 +468,7 @@ var WorkerClient = class {
|
|
|
380
468
|
const pending = this.pending.get(response.id);
|
|
381
469
|
if (pending) {
|
|
382
470
|
this.pending.delete(response.id);
|
|
471
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
383
472
|
if (response.error) {
|
|
384
473
|
const err = new Error(response.error.message);
|
|
385
474
|
err.code = response.error.code;
|
|
@@ -537,7 +626,11 @@ async function createWorkerClient(options) {
|
|
|
537
626
|
`kbdb worker daemon did not start: ${readCrashReason(contextId)}`
|
|
538
627
|
);
|
|
539
628
|
}
|
|
540
|
-
const client = new WorkerClient(
|
|
629
|
+
const client = new WorkerClient(
|
|
630
|
+
socketPath,
|
|
631
|
+
contextId,
|
|
632
|
+
options?.requestTimeoutMs
|
|
633
|
+
);
|
|
541
634
|
await client.connect();
|
|
542
635
|
return client;
|
|
543
636
|
}
|
|
@@ -555,11 +648,24 @@ function readCrashReason(contextId) {
|
|
|
555
648
|
return "daemon failed to start (crash log unreadable)";
|
|
556
649
|
}
|
|
557
650
|
}
|
|
651
|
+
|
|
652
|
+
// src/shared/worker-client/functions/get-or-create-client.function.ts
|
|
653
|
+
var cache = /* @__PURE__ */ new Map();
|
|
654
|
+
async function getOrCreateClient(options) {
|
|
655
|
+
const dbPath = options?.contextPath ?? resolveDbPath(options?.dbPath);
|
|
656
|
+
const cached = cache.get(dbPath);
|
|
657
|
+
if (cached?.isConnected) return cached;
|
|
658
|
+
cache.delete(dbPath);
|
|
659
|
+
const client = await createWorkerClient(options);
|
|
660
|
+
cache.set(dbPath, client);
|
|
661
|
+
return client;
|
|
662
|
+
}
|
|
558
663
|
// Annotate the CommonJS export names for ESM import in node:
|
|
559
664
|
0 && (module.exports = {
|
|
560
665
|
WorkerClient,
|
|
561
666
|
computeContextId,
|
|
562
667
|
createWorkerClient,
|
|
668
|
+
getOrCreateClient,
|
|
563
669
|
resolveDbPath,
|
|
564
670
|
version
|
|
565
671
|
});
|
package/dist/mod.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../mod.ts", "../src/shared/version/constants/version.constant.ts", "../src/shared/worker-client/classes/worker-client.class.ts", "../src/shared/worker-client/functions/create-worker-client.function.ts", "../src/shared/worker-client/functions/resolve-db-path.function.ts", "../src/shared/hash/functions/compute-sha256.ts", "../src/shared/worker-client/functions/compute-context-id.function.ts", "../src/shared/worker-client/functions/discover-daemon.function.ts", "../src/shared/platform/functions/is-process-alive.function.ts", "../src/shared/worker-client/functions/spawn-daemon.function.ts", "../src/shared/worker-client/functions/wait-for-daemon.function.ts", "../src/shared/runtime/functions/detect-runtime.ts", "../src/shared/platform/functions/get-ipc-path.function.ts", "../src/shared/platform/functions/get-tmpdir.function.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @module\n *\n * File-based knowledge base database for AI agents.\n * Provides a programmatic API for indexing documents,\n * searching with ranked results, and recalling section\n * context at progressive depths.\n *\n * @example\n * ```ts\n * import { createWorkerClient } from '@dikolab/kbdb';\n *\n * const client = await createWorkerClient({\n * contextPath: '/path/to/.kbdb',\n * });\n *\n * const results = await client.search({\n * query: 'authentication',\n * limit: 10,\n * });\n *\n * console.log(results.items);\n * client.disconnect();\n * ```\n */\n\nexport { version } from './src/shared/mod.ts';\n\nexport {\n createWorkerClient,\n WorkerClient,\n resolveDbPath,\n computeContextId,\n} from './src/shared/worker-client/index.ts';\n\nexport type {\n WorkerClientOptions,\n SearchParams,\n SearchResult,\n Section,\n AddSectionParams,\n StatusResult,\n} from './src/shared/worker-client/index.ts';\n", "/** Current package version, kept in sync with package.json. */\nexport const VERSION = '0.2.2';\n", "import { connect } from 'node:net';\nimport type { Socket } from 'node:net';\nimport type { SearchParams } from '../typings/search-params.model.ts';\nimport type { PagedSearchResult } from '../typings/search-result.model.ts';\nimport type {\n AddSectionParams,\n Section,\n} from '../typings/section.model.ts';\nimport type { StatusResult } from '../typings/status-result.model.ts';\nimport type { AddSectionResult } from '../typings/add-section-result.model.ts';\nimport type { RemoveSectionResult } from '../typings/remove-section-result.model.ts';\nimport type { ContentResult } from '../typings/content-result.model.ts';\nimport type { IntegrityCheckResult } from '../typings/integrity-check-result.model.ts';\nimport type { GcResult } from '../typings/gc-result.model.ts';\nimport type { RebuildResult } from '../typings/rebuild-result.model.ts';\nimport type { MigrateResult } from '../typings/migrate-result.model.ts';\nimport type { VersionStatus } from '../typings/version-status.model.ts';\nimport type { SectionRecord } from '../../wasm-codec/functions/decode-section-records.function.ts';\nimport type { DocumentManifest } from '../../wasm-codec/functions/decode-document-manifest.function.ts';\nimport type {\n RecallParams,\n RecallResult,\n} from '../typings/recall-result.model.ts';\nimport type { ExportResult } from '../typings/export-result.model.ts';\n\n/** Pending JSON-RPC call awaiting a response from the daemon. */\ninterface PendingCall {\n resolve: (v: unknown) => void;\n reject: (e: Error) => void;\n}\n\n/** Shape of a JSON-RPC 2.0 error object from the daemon. */\ninterface JsonRpcError {\n readonly code: number;\n readonly message: string;\n}\n\n/** Shape of a JSON-RPC 2.0 response from the daemon. */\ninterface JsonRpcResponse {\n readonly id: number;\n readonly result?: unknown;\n readonly error?: JsonRpcError;\n}\n\n/**\n * IPC client that communicates with the worker daemon over a Unix\n * domain socket (or Windows named pipe) using JSON-RPC 2.0 with\n * newline-delimited message framing.\n *\n * Call `connect()` before any other method and `disconnect()` when\n * done to release the underlying socket.\n */\nexport class WorkerClient {\n /** Underlying socket; `null` when not connected. */\n private socket: Socket | null = null;\n\n /** Monotonically increasing request ID counter. */\n private nextId = 1;\n\n /** Map of outstanding request IDs to their resolve/reject pairs. */\n private readonly pending = new Map<number, PendingCall>();\n\n /** Partial line buffer for split TCP/IPC frames. */\n private buffer = '';\n\n /**\n * @param socketPath - absolute path to the daemon's IPC socket\n * (or Windows named pipe path)\n * @param contextId - 16-character context identifier sent as\n * `ctx` in every JSON-RPC request\n */\n constructor(\n private readonly socketPath: string,\n private readonly contextId: string,\n ) {}\n\n /**\n * Establishes the IPC connection to the worker daemon.\n *\n * @throws {Error} if the connection cannot be established\n */\n async connect(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n this.socket = connect(this.socketPath, () => {\n resolve();\n });\n this.socket.on('error', (err: Error) => {\n reject(err);\n });\n this.socket.on('data', (chunk: Buffer) => {\n this.handleData(chunk.toString());\n });\n });\n }\n\n /** Destroys the IPC socket and clears the connection state. */\n disconnect(): void {\n if (this.socket) {\n this.socket.destroy();\n this.socket = null;\n }\n }\n\n /**\n * Searches the knowledge base.\n *\n * @param params - query parameters including the search string\n * @returns paginated search results with metadata\n */\n async search(params: SearchParams): Promise<PagedSearchResult> {\n return this.call('search', params) as Promise<PagedSearchResult>;\n }\n\n /**\n * Retrieves full content and context for one or more sections by\n * their knowledge-base identifiers.\n *\n * @param params - section identifier(s) and optional expansion depth\n * @returns a single `RecallResult` when `kbid` is provided without\n * `kbids`, or a `RecallResult[]` when `kbids` is provided\n */\n async recall(\n params: RecallParams,\n ): Promise<RecallResult | RecallResult[]> {\n return this.call('recall', params) as Promise<\n RecallResult | RecallResult[]\n >;\n }\n\n /**\n * Adds a new section to the knowledge base.\n *\n * @param params - section content and metadata\n * @returns the result including the assigned knowledge-base\n * identifier and indexing statistics\n */\n async addSection(\n params: AddSectionParams,\n ): Promise<AddSectionResult> {\n return this.call(\n 'addSection',\n params,\n ) as Promise<AddSectionResult>;\n }\n\n /**\n * Replaces an existing section's content and metadata.\n *\n * @param kbid - identifier of the section to update\n * @param params - new content and metadata\n * @returns the knowledge-base identifier of the updated section\n */\n async updateSection(\n kbid: string,\n params: AddSectionParams,\n ): Promise<string> {\n return this.call('updateSection', {\n kbid,\n ...params,\n }) as Promise<string>;\n }\n\n /**\n * Removes a section from the knowledge base.\n *\n * @param kbid - identifier of the section to remove\n * @returns removal result with `removed` flag and elapsed time\n */\n async removeSection(kbid: string): Promise<RemoveSectionResult> {\n return this.call('removeSection', {\n kbid,\n }) as Promise<RemoveSectionResult>;\n }\n\n /**\n * Retrieves multiple sections by their identifiers.\n *\n * @param kbids - list of knowledge-base identifiers to fetch\n * @returns sections in the order their IDs were requested\n */\n async readSections(kbids: string[]): Promise<Section[]> {\n return this.call('readSections', {\n kbids,\n }) as Promise<Section[]>;\n }\n\n /**\n * Groups a set of sections under a named document.\n *\n * @param title - human-readable document title\n * @param kbids - identifiers of the sections to group\n * @param docType - application-level document type tag; omit or\n * pass an empty string for untagged documents\n * @returns the assigned document identifier\n */\n async groupSections(\n title: string,\n kbids: string[],\n docType?: string,\n ): Promise<string> {\n const result = (await this.call('groupSections', {\n title,\n kbids,\n docType: docType ?? '',\n })) as { docid: string } | string;\n return typeof result === 'string' ? result : result.docid;\n }\n\n /**\n * Removes the document grouping for the given document.\n *\n * The sections themselves are not deleted; only the grouping\n * record is removed.\n *\n * @param docid - identifier of the document grouping to remove\n */\n async removeGrouping(docid: string): Promise<void> {\n await this.call('removeGrouping', { docid });\n }\n\n /**\n * Retrieves a full document record including its sections.\n *\n * @param docid - identifier of the document to retrieve\n * @returns the document record as returned by the daemon\n */\n async retrieveDocument(docid: string): Promise<unknown> {\n return this.call('retrieveDocument', { docid });\n }\n\n /**\n * Composes a rendered Markdown document from one or more kbid\n * or docid identifiers.\n *\n * @param ids - list of kbid or docid identifiers (may be mixed)\n * @returns composed Markdown result with character count\n */\n async content(ids: string[]): Promise<ContentResult> {\n return this.call('content', { ids }) as Promise<ContentResult>;\n }\n\n /**\n * Runs an integrity check on the knowledge-base database.\n *\n * @returns a report of all issues found; `ok` is `true` when\n * no errors were detected\n */\n async integrityCheck(): Promise<IntegrityCheckResult> {\n return this.call(\n 'integrityCheck',\n {},\n ) as Promise<IntegrityCheckResult>;\n }\n\n /**\n * Removes unreferenced sections from the database.\n *\n * @returns a report of sections removed and bytes freed\n */\n async gc(): Promise<GcResult> {\n return this.call('gc', {}) as Promise<GcResult>;\n }\n\n /**\n * Reconstructs all index files from section files and document\n * manifests on disk. Text and code sections are re-tokenized;\n * image sections are skipped.\n *\n * @returns a report of sections and terms re-indexed\n */\n async rebuildIndexes(): Promise<RebuildResult> {\n return this.call('rebuildIndexes', {}) as Promise<RebuildResult>;\n }\n\n /**\n * Invalidates the in-memory cache entry for a single section.\n *\n * @param kbid - identifier of the section to evict from cache\n */\n async invalidate(kbid: string): Promise<void> {\n await this.call('invalidate', { kbid });\n }\n\n /** Clears all entries from the daemon's in-memory cache. */\n async invalidateAll(): Promise<void> {\n await this.call('invalidateAll', {});\n }\n\n /**\n * Retrieves diagnostic status information from the daemon.\n *\n * @returns current initialization state and cache statistics\n */\n async status(): Promise<StatusResult> {\n return this.call('status', {}) as Promise<StatusResult>;\n }\n\n /**\n * Returns database metadata and status from the daemon,\n * including document count, section count, index size, and\n * cache statistics.\n *\n * @returns database metadata from the daemon's cached state\n */\n async dbStatus(): Promise<StatusResult> {\n return this.call('dbStatus', {}) as Promise<StatusResult>;\n }\n\n /**\n * Initialises a new `.kbdb` database directory at the given path\n * by sending an init request to the worker daemon.\n *\n * The daemon creates all required subdirectories and seed files via\n * the `worker_init_directory` WASM export.\n *\n * @param targetPath - absolute path to the directory that will\n * contain the new `.kbdb` database\n * @throws {Error} if the `.kbdb` directory already exists or the\n * daemon cannot create the layout\n */\n async initDirectory(targetPath: string): Promise<void> {\n await this.call('initDirectory', { targetPath });\n }\n\n /**\n * Runs all pending database migrations for the `.kbdb` directory\n * at the given path.\n *\n * Delegates to the `worker_migrate` WASM export on the daemon.\n * Each migration step updates `catalog.toml` on success, so\n * retrying after a partial failure is safe.\n *\n * @param targetPath - absolute path to the `.kbdb` database root\n * @returns migration report with old version, new version, and\n * number of migration steps applied\n */\n async migrateDatabase(targetPath: string): Promise<MigrateResult> {\n return this.call('migrateDatabase', {\n targetPath,\n }) as Promise<MigrateResult>;\n }\n\n /**\n * Checks the format version of the `.kbdb` database at the given\n * path against the version required by the current WASM engine.\n *\n * This is a read-only operation: it reads `catalog.toml` and\n * returns the compatibility status without making any changes.\n *\n * @param targetPath - absolute path to the `.kbdb` database root\n * @returns version compatibility report\n */\n async checkVersion(targetPath: string): Promise<VersionStatus> {\n return this.call('checkVersion', {\n targetPath,\n }) as Promise<VersionStatus>;\n }\n\n /**\n * Retrieves all sections whose type name matches the given string.\n *\n * @param sectionType - the application-level type name to filter by\n * @returns all section records with a matching type name\n */\n async listByType(sectionType: string): Promise<SectionRecord[]> {\n return this.call('listByType', {\n sectionType,\n }) as Promise<SectionRecord[]>;\n }\n\n /**\n * Retrieves all documents whose type name matches the given string.\n *\n * @param docType - the application-level document type to filter by\n * @returns all document manifests with a matching type name\n */\n async listDocumentsByType(\n docType: string,\n ): Promise<DocumentManifest[]> {\n return this.call('listDocumentsByType', {\n docType,\n }) as Promise<DocumentManifest[]>;\n }\n\n /**\n * Exports the database to a target directory on disk.\n *\n * Copies section files, document manifests, and `catalog.toml`\n * to `params.path`. Index files are not exported because they\n * are derivable from the section and document data.\n *\n * @param params - optional export parameters\n * @param params.path - target directory path; defaults to\n * `./kbdb-export/` when not provided\n * @returns export report with the resolved path and file counts\n */\n async export(params?: { path?: string }): Promise<ExportResult> {\n return this.call('export', {\n targetPath: params?.path || undefined,\n }) as Promise<ExportResult>;\n }\n\n /**\n * Sends a JSON-RPC 2.0 request and awaits the response.\n *\n * @param method - the RPC method name\n * @param params - parameters to include in the request\n * @throws {Error} if not connected\n * @throws {Error} when the daemon returns an error response\n */\n private async call(\n method: string,\n params: unknown,\n ): Promise<unknown> {\n const socket = this.socket;\n if (!socket) {\n throw new Error('not connected');\n }\n\n const id = this.nextId++;\n const request = {\n jsonrpc: '2.0',\n id,\n method,\n params: { ctx: this.contextId, ...(params as object) },\n };\n\n return new Promise<unknown>((resolve, reject) => {\n this.pending.set(id, { resolve, reject });\n socket.write(JSON.stringify(request) + '\\n');\n });\n }\n\n /**\n * Processes incoming data from the socket, splitting on newlines\n * and dispatching complete JSON-RPC response objects.\n *\n * @param data - raw string chunk received from the socket\n */\n private handleData(data: string): void {\n this.buffer += data;\n const lines = this.buffer.split('\\n');\n this.buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (!line.trim()) continue;\n try {\n const response = JSON.parse(line) as JsonRpcResponse;\n const pending = this.pending.get(response.id);\n if (pending) {\n this.pending.delete(response.id);\n if (response.error) {\n const err = new Error(response.error.message);\n (err as unknown as Record<string, unknown>).code =\n response.error.code;\n pending.reject(err);\n } else {\n pending.resolve(response.result);\n }\n }\n } catch {\n // Ignore unparseable lines\n }\n }\n }\n}\n", "import { existsSync, readFileSync, unlinkSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport { WorkerClient } from '../classes/worker-client.class.ts';\nimport { resolveDbPath } from './resolve-db-path.function.ts';\nimport { computeContextId } from './compute-context-id.function.ts';\nimport { discoverDaemon } from './discover-daemon.function.ts';\nimport { spawnDaemon } from './spawn-daemon.function.ts';\nimport { waitForDaemon } from './wait-for-daemon.function.ts';\nimport { detectRuntime } from '../../runtime/functions/detect-runtime.ts';\nimport { getIpcPath } from '../../platform/functions/get-ipc-path.function.ts';\nimport type { WorkerClientOptions } from '../typings/worker-client-options.interface.ts';\n\n/**\n * Creates and connects a `WorkerClient` to the worker daemon.\n *\n * Resolves the context path, derives a stable context identifier,\n * and checks whether a daemon is already running. If no daemon is\n * found and `autoSpawn` is not `false`, a new daemon process is\n * spawned and the factory waits for its PID file to appear before\n * connecting.\n *\n * @param options - optional configuration for path resolution,\n * auto-spawn behaviour, and connection timeout\n * @returns a connected `WorkerClient` ready to send requests\n * @throws {Error} if the `.kbdb` directory cannot be found\n * @throws {Error} if the socket connection cannot be established\n */\nexport async function createWorkerClient(\n options?: WorkerClientOptions,\n): Promise<WorkerClient> {\n const dbPath =\n options?.contextPath ?? resolveDbPath(options?.dbPath);\n const contextId = await computeContextId(dbPath);\n const socketPath = getIpcPath(contextId);\n\n let daemon = discoverDaemon(contextId);\n\n if (!daemon && options?.autoSpawn !== false) {\n const runtime = detectRuntime();\n spawnDaemon(dbPath, runtime, options?.workerScript);\n await waitForDaemon(contextId, options?.connectTimeoutMs);\n daemon = discoverDaemon(contextId);\n }\n\n if (!daemon) {\n throw new Error(\n `kbdb worker daemon did not start: ${readCrashReason(contextId)}`,\n );\n }\n\n const client = new WorkerClient(socketPath, contextId);\n await client.connect();\n return client;\n}\n\nfunction readCrashReason(contextId: string): string {\n const crashPath = join(tmpdir(), `kbdb-${contextId}.crash`);\n if (!existsSync(crashPath)) {\n return 'daemon failed to start (no details available)';\n }\n try {\n const raw = readFileSync(crashPath, 'utf-8');\n const crash = JSON.parse(raw) as { error?: string };\n unlinkSync(crashPath);\n return crash.error ?? 'unknown error (crash log empty)';\n } catch {\n return 'daemon failed to start (crash log unreadable)';\n }\n}\n", "import { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\n/**\n * Resolves the absolute path to the `.kbdb` database directory.\n *\n * Searches for a `.kbdb` sub-directory inside `targetDir`. When\n * `targetDir` is omitted, `process.cwd()` is used as the base.\n *\n * @param targetDir - directory to search in; defaults to cwd\n * @throws {Error} if no `.kbdb` directory exists at the resolved\n * path\n */\nexport function resolveDbPath(targetDir?: string): string {\n const base = targetDir ? resolve(targetDir) : process.cwd();\n const dbPath = join(base, '.kbdb');\n if (!existsSync(dbPath)) {\n throw new Error(`database not found: ${dbPath}`);\n }\n return dbPath;\n}\n", "/**\n * Computes the SHA-256 hash of a UTF-8 string.\n *\n * Uses the Web Crypto API (`crypto.subtle`), which is available\n * in both Deno and Node.js >= 20 without additional imports.\n *\n * @param input - the string to hash\n * @returns lowercase hex-encoded SHA-256 digest (64 characters)\n */\nexport async function computeSha256(input: string): Promise<string> {\n const data = new TextEncoder().encode(input);\n const hash = await crypto.subtle.digest('SHA-256', data);\n const bytes = new Uint8Array(hash);\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n", "import { computeSha256 } from '../../hash/functions/compute-sha256.ts';\n\n/**\n * Computes a short context identifier for an absolute path.\n *\n * Hashes the path with SHA-256 and returns the first 16 hex\n * characters. The result is stable for the same input and unique\n * enough to avoid accidental collisions across typical path sets.\n *\n * @param absolutePath - the absolute filesystem path to identify\n * @returns a 16-character lowercase hex string\n */\nexport async function computeContextId(\n absolutePath: string,\n): Promise<string> {\n const hash = await computeSha256(absolutePath);\n return hash.slice(0, 16);\n}\n", "import { existsSync, readFileSync, unlinkSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport { isProcessAlive } from '../../platform/functions/is-process-alive.function.ts';\nimport type { DaemonInfo } from '../typings/daemon-info.model.ts';\n\nexport type { DaemonInfo };\n\n/**\n * Discovers a running worker daemon for the given context.\n *\n * Reads the PID file at `<tmpdir>/kbdb-<contextId>.pid`. If the\n * file exists and the process is alive, returns its PID and the\n * expected socket path. If the file is stale (process dead or PID\n * unparseable), removes the PID file and returns `null`.\n *\n * @param contextId - the 16-character context identifier\n * @returns daemon location info, or `null` if no live daemon found\n */\nexport function discoverDaemon(contextId: string): DaemonInfo | null {\n const pidPath = join(tmpdir(), `kbdb-${contextId}.pid`);\n\n if (!existsSync(pidPath)) return null;\n\n const pidStr = readFileSync(pidPath, 'utf-8').trim();\n const pid = parseInt(pidStr, 10);\n\n if (isNaN(pid) || !isProcessAlive(pid)) {\n try {\n unlinkSync(pidPath);\n } catch {\n // Stale PID file removal is best-effort\n }\n return null;\n }\n\n const socketPath = join(tmpdir(), `kbdb-${contextId}.sock`);\n\n const crashPath = join(tmpdir(), `kbdb-${contextId}.crash`);\n try {\n unlinkSync(crashPath);\n } catch {\n // stale crash file removal is best-effort\n }\n\n return { pid, socketPath };\n}\n", "/**\n * Checks whether a process with the given PID is alive.\n *\n * Sends signal `0` to the process, which performs a permission\n * check without sending an actual signal. Returns `true` if the\n * process exists and is reachable, `false` otherwise.\n *\n * @param pid - the process identifier to probe\n */\nexport function isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n}\n", "import { spawn } from 'node:child_process';\nimport type { Runtime } from '../../runtime/typings/runtime.ts';\n\n/**\n * Spawns a detached worker daemon process for the given context.\n *\n * @param contextPath - absolute path to the context directory the\n * daemon should serve\n * @param runtime - the current JavaScript runtime environment\n * @param workerScript - absolute path to the worker daemon script,\n * resolved at the entry point by `resolveWorkerScript`\n */\nexport function spawnDaemon(\n contextPath: string,\n runtime: Runtime,\n workerScript?: string,\n): void {\n if (!workerScript) {\n throw new Error(\n 'workerScript must be provided' + ' (resolve at entry point)',\n );\n }\n const execPath = runtime === 'deno' ? 'deno' : process.execPath;\n\n const args =\n runtime === 'deno'\n ? ['run', '--allow-all', workerScript, contextPath]\n : [workerScript, contextPath];\n\n const child = spawn(execPath, args, {\n detached: true,\n stdio: 'ignore',\n });\n child.unref();\n}\n", "import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { tmpdir } from 'node:os';\n\n/** Default maximum wait time for the daemon PID file to appear. */\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\n/** Polling interval in milliseconds between existence checks. */\nconst POLL_INTERVAL_MS = 100;\n\n/**\n * Waits for the worker daemon's PID file to appear on disk.\n *\n * Polls every 100 ms until the PID file at\n * `<tmpdir>/kbdb-<contextId>.pid` exists or the timeout elapses.\n *\n * @param contextId - the 16-character context identifier\n * @param timeoutMs - maximum wait time in milliseconds; defaults\n * to 10 000 ms\n * @returns `true` if the PID file appeared before the timeout,\n * `false` otherwise\n */\nexport async function waitForDaemon(\n contextId: string,\n timeoutMs: number = DEFAULT_TIMEOUT_MS,\n): Promise<boolean> {\n const pidPath = join(tmpdir(), `kbdb-${contextId}.pid`);\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n if (existsSync(pidPath)) return true;\n await new Promise<void>((r) => setTimeout(r, POLL_INTERVAL_MS));\n }\n return false;\n}\n", "import type { Runtime } from '../typings/runtime.ts';\n\n/**\n * Detects the current JavaScript runtime environment.\n *\n * Returns `'deno'` when the global `Deno` object is present,\n * otherwise returns `'node'`.\n */\nexport function detectRuntime(): Runtime {\n if (typeof globalThis !== 'undefined' && 'Deno' in globalThis) {\n return 'deno';\n }\n return 'node';\n}\n", "import { join } from 'node:path';\nimport { getTmpdir } from './get-tmpdir.function.ts';\n\n/**\n * Returns the platform-appropriate IPC socket path for a given\n * context identifier.\n *\n * On Windows, returns a named pipe path (`\\\\.\\pipe\\kbdb-<ctx>`).\n * On POSIX systems, returns a Unix domain socket path under the\n * system temp directory (`<tmpdir>/kbdb-<ctx>.sock`).\n *\n * @param ctx - unique context identifier embedded in the path\n */\nexport function getIpcPath(ctx: string): string {\n if (process.platform === 'win32') {\n return `\\\\\\\\.\\\\pipe\\\\kbdb-${ctx}`;\n }\n return join(getTmpdir(), `kbdb-${ctx}.sock`);\n}\n", "import { tmpdir } from 'node:os';\n\n/**\n * Returns the operating system's default temporary directory path.\n */\nexport function getTmpdir(): string {\n return tmpdir();\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,IAAM,UAAU;;;ACDvB,sBAAwB;
|
|
3
|
+
"sources": ["../mod.ts", "../src/shared/version/constants/version.constant.ts", "../src/shared/worker-client/classes/worker-client.class.ts", "../src/shared/worker-client/functions/create-worker-client.function.ts", "../src/shared/worker-client/functions/resolve-db-path.function.ts", "../src/shared/hash/functions/compute-sha256.ts", "../src/shared/worker-client/functions/compute-context-id.function.ts", "../src/shared/worker-client/functions/discover-daemon.function.ts", "../src/shared/platform/functions/is-process-alive.function.ts", "../src/shared/worker-client/functions/spawn-daemon.function.ts", "../src/shared/worker-client/functions/wait-for-daemon.function.ts", "../src/shared/runtime/functions/detect-runtime.ts", "../src/shared/platform/functions/get-ipc-path.function.ts", "../src/shared/platform/functions/get-tmpdir.function.ts", "../src/shared/worker-client/functions/get-or-create-client.function.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * @module\n *\n * File-based knowledge base database for AI agents.\n * Provides a programmatic API for indexing documents,\n * searching with ranked results, and recalling section\n * context at progressive depths.\n *\n * @example\n * ```ts\n * import { createWorkerClient } from '@dikolab/kbdb';\n *\n * const client = await createWorkerClient({\n * contextPath: '/path/to/.kbdb',\n * });\n *\n * const results = await client.search({\n * query: 'authentication',\n * limit: 10,\n * });\n *\n * console.log(results.items);\n * client.disconnect();\n * ```\n */\n\n/** Semantic version string matching `package.json`. */\nexport { version } from './src/shared/mod.ts';\n\n/** Creates a connected worker client for the given database. */\nexport { createWorkerClient } from './src/shared/worker-client/index.ts';\n\n/** Persistent client wrapping JSON-RPC calls to the daemon. */\nexport { WorkerClient } from './src/shared/worker-client/index.ts';\n\n/** Resolves a parent directory to the `.kbdb` path inside it. */\nexport { resolveDbPath } from './src/shared/worker-client/index.ts';\n\n/** Derives the 16-char hex context ID from an absolute path. */\nexport { computeContextId } from './src/shared/worker-client/index.ts';\n\n/** Returns a cached client or creates a new one for the given path. */\nexport { getOrCreateClient } from './src/shared/worker-client/index.ts';\n\n/** Options accepted by {@linkcode createWorkerClient}. */\nexport type { WorkerClientOptions } from './src/shared/worker-client/index.ts';\n\n/** Parameters for a search query. */\nexport type { SearchParams } from './src/shared/worker-client/index.ts';\n\n/** A single ranked result returned by search. */\nexport type { SearchResult } from './src/shared/worker-client/index.ts';\n\n/** Raw section record stored on disk. */\nexport type { Section } from './src/shared/worker-client/index.ts';\n\n/** Parameters for adding a new section. */\nexport type { AddSectionParams } from './src/shared/worker-client/index.ts';\n\n/** Database status snapshot returned by `client.status()`. */\nexport type { StatusResult } from './src/shared/worker-client/index.ts';\n", "/** Current package version, kept in sync with package.json. */\nexport const VERSION = '0.4.0';\n", "import { connect } from 'node:net';\nimport type { Socket } from 'node:net';\nimport type { SearchParams } from '../typings/search-params.model.ts';\nimport type { PagedSearchResult } from '../typings/search-result.model.ts';\nimport type {\n AddSectionParams,\n Section,\n} from '../typings/section.model.ts';\nimport type { StatusResult } from '../typings/status-result.model.ts';\nimport type { AddSectionResult } from '../typings/add-section-result.model.ts';\nimport type { RemoveSectionResult } from '../typings/remove-section-result.model.ts';\nimport type { ContentResult } from '../typings/content-result.model.ts';\nimport type { IntegrityCheckResult } from '../typings/integrity-check-result.model.ts';\nimport type { GcResult } from '../typings/gc-result.model.ts';\nimport type { RebuildResult } from '../typings/rebuild-result.model.ts';\nimport type { MigrateResult } from '../typings/migrate-result.model.ts';\nimport type { VersionStatus } from '../typings/version-status.model.ts';\nimport type { SectionRecord } from '../../wasm-codec/functions/decode-section-records.function.ts';\nimport type { DocumentManifest } from '../../wasm-codec/functions/decode-document-manifest.function.ts';\nimport type {\n RecallParams,\n RecallResult,\n} from '../typings/recall-result.model.ts';\nimport type { ExportResult } from '../typings/export-result.model.ts';\nimport type { ImportResult } from '../typings/import-result.model.ts';\n\n/** Pending JSON-RPC call awaiting a response from the daemon. */\ninterface PendingCall {\n resolve: (v: unknown) => void;\n reject: (e: Error) => void;\n timer?: ReturnType<typeof setTimeout>;\n}\n\n/** Shape of a JSON-RPC 2.0 error object from the daemon. */\ninterface JsonRpcError {\n readonly code: number;\n readonly message: string;\n}\n\n/** Shape of a JSON-RPC 2.0 response from the daemon. */\ninterface JsonRpcResponse {\n readonly id: number;\n readonly result?: unknown;\n readonly error?: JsonRpcError;\n}\n\n/**\n * IPC client that communicates with the worker daemon over a Unix\n * domain socket (or Windows named pipe) using JSON-RPC 2.0 with\n * newline-delimited message framing.\n *\n * Call `connect()` before any other method and `disconnect()` when\n * done to release the underlying socket.\n */\nexport class WorkerClient {\n /** Underlying socket; `null` when not connected. */\n private socket: Socket | null = null;\n\n /** Monotonically increasing request ID counter. */\n private nextId = 1;\n\n /** Map of outstanding request IDs to their resolve/reject pairs. */\n private readonly pending = new Map<number, PendingCall>();\n\n /** Partial line buffer for split TCP/IPC frames. */\n private buffer = '';\n\n /**\n * @param socketPath - absolute path to the daemon's IPC socket\n * (or Windows named pipe path)\n * @param contextId - 16-character context identifier sent as\n * `ctx` in every JSON-RPC request\n * @param requestTimeoutMs - per-request timeout in ms\n * (0 or undefined disables the timeout)\n */\n constructor(\n private readonly socketPath: string,\n private readonly contextId: string,\n private readonly requestTimeoutMs?: number,\n ) {}\n\n /** Whether the underlying socket is connected. */\n get isConnected(): boolean {\n return this.socket !== null;\n }\n\n /**\n * Establishes the IPC connection to the worker daemon.\n *\n * Retries up to 5 times with exponential backoff on\n * transient errors (`ENOENT`, `ECONNREFUSED`).\n *\n * @throws {Error} if the connection cannot be established\n */\n async connect(): Promise<void> {\n const maxRetries = 5;\n let delay = 50;\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n await this.tryConnect();\n return;\n } catch (err: unknown) {\n const code = (err as NodeJS.ErrnoException).code;\n const retriable =\n code === 'ENOENT' || code === 'ECONNREFUSED';\n if (!retriable || attempt === maxRetries) {\n throw err;\n }\n await new Promise<void>((r) => setTimeout(r, delay));\n delay = Math.min(delay * 2, 1000);\n }\n }\n }\n\n /** Destroys the IPC socket and clears the connection state. */\n disconnect(): void {\n if (this.socket) {\n this.socket.destroy();\n this.socket = null;\n }\n }\n\n /**\n * Single connection attempt with keepalive and\n * post-connect failure handlers.\n */\n private async tryConnect(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const sock = connect(this.socketPath, () => {\n sock.removeListener('error', reject);\n sock.setKeepAlive(true, 30_000);\n sock.on('error', (err: Error) => {\n this.handleSocketFailure(err);\n });\n sock.on('close', () => {\n if (this.pending.size > 0) {\n this.handleSocketFailure(\n new Error('connection closed'),\n );\n }\n this.socket = null;\n });\n this.socket = sock;\n resolve();\n });\n sock.on('error', reject);\n sock.on('data', (chunk: Buffer) => {\n this.handleData(chunk.toString());\n });\n });\n }\n\n /**\n * Rejects all pending calls and marks the client as\n * disconnected.\n */\n private handleSocketFailure(err: Error): void {\n const sock = this.socket;\n this.socket = null;\n for (const [id, call] of this.pending) {\n this.pending.delete(id);\n if (call.timer) clearTimeout(call.timer);\n call.reject(err);\n }\n if (sock) sock.destroy();\n }\n\n /**\n * Searches the knowledge base.\n *\n * @param params - query parameters including the search string\n * @returns paginated search results with metadata\n */\n async search(params: SearchParams): Promise<PagedSearchResult> {\n return this.call('search', {\n ...params,\n algo: params.algo,\n }) as Promise<PagedSearchResult>;\n }\n\n /**\n * Retrieves full content and context for one or more sections by\n * their knowledge-base identifiers.\n *\n * @param params - section identifier(s) and optional expansion depth\n * @returns a single `RecallResult` when `kbid` is provided without\n * `kbids`, or a `RecallResult[]` when `kbids` is provided\n */\n async recall(\n params: RecallParams,\n ): Promise<RecallResult | RecallResult[]> {\n return this.call('recall', params) as Promise<\n RecallResult | RecallResult[]\n >;\n }\n\n /**\n * Adds a new section to the knowledge base.\n *\n * @param params - section content and metadata\n * @returns the result including the assigned knowledge-base\n * identifier and indexing statistics\n */\n async addSection(\n params: AddSectionParams,\n ): Promise<AddSectionResult> {\n return this.call(\n 'addSection',\n params,\n ) as Promise<AddSectionResult>;\n }\n\n /**\n * Replaces an existing section's content and metadata.\n *\n * @param kbid - identifier of the section to update\n * @param params - new content and metadata\n * @returns the knowledge-base identifier of the updated section\n */\n async updateSection(\n kbid: string,\n params: AddSectionParams,\n ): Promise<string> {\n return this.call('updateSection', {\n kbid,\n ...params,\n }) as Promise<string>;\n }\n\n /**\n * Removes a section from the knowledge base.\n *\n * @param kbid - identifier of the section to remove\n * @returns removal result with `removed` flag and elapsed time\n */\n async removeSection(kbid: string): Promise<RemoveSectionResult> {\n return this.call('removeSection', {\n kbid,\n }) as Promise<RemoveSectionResult>;\n }\n\n /**\n * Retrieves multiple sections by their identifiers.\n *\n * @param kbids - list of knowledge-base identifiers to fetch\n * @returns sections in the order their IDs were requested\n */\n async readSections(kbids: string[]): Promise<Section[]> {\n return this.call('readSections', {\n kbids,\n }) as Promise<Section[]>;\n }\n\n /**\n * Groups a set of sections under a named document.\n *\n * @param title - human-readable document title\n * @param kbids - identifiers of the sections to group\n * @param docType - application-level document type tag; omit or\n * pass an empty string for untagged documents\n * @returns the assigned document identifier\n */\n async groupSections(\n title: string,\n kbids: string[],\n docType?: string,\n ): Promise<string> {\n const result = (await this.call('groupSections', {\n title,\n kbids,\n docType: docType ?? '',\n })) as { docid: string } | string;\n return typeof result === 'string' ? result : result.docid;\n }\n\n /**\n * Removes the document grouping for the given document.\n *\n * The sections themselves are not deleted; only the grouping\n * record is removed.\n *\n * @param docid - identifier of the document grouping to remove\n */\n async removeGrouping(docid: string): Promise<void> {\n await this.call('removeGrouping', { docid });\n }\n\n /**\n * Retrieves a full document record including its sections.\n *\n * @param docid - identifier of the document to retrieve\n * @returns the document record as returned by the daemon\n */\n async retrieveDocument(docid: string): Promise<unknown> {\n return this.call('retrieveDocument', { docid });\n }\n\n /**\n * Composes a rendered Markdown document from one or more kbid\n * or docid identifiers.\n *\n * @param ids - list of kbid or docid identifiers (may be mixed)\n * @returns composed Markdown result with character count\n */\n async content(ids: string[]): Promise<ContentResult> {\n return this.call('content', { ids }) as Promise<ContentResult>;\n }\n\n /**\n * Runs an integrity check on the knowledge-base database.\n *\n * @returns a report of all issues found; `ok` is `true` when\n * no errors were detected\n */\n async integrityCheck(): Promise<IntegrityCheckResult> {\n return this.call(\n 'integrityCheck',\n {},\n ) as Promise<IntegrityCheckResult>;\n }\n\n /**\n * Removes unreferenced sections from the database.\n *\n * @returns a report of sections removed and bytes freed\n */\n async gc(): Promise<GcResult> {\n return this.call('gc', {}) as Promise<GcResult>;\n }\n\n /**\n * Reconstructs all index files from section files and document\n * manifests on disk. Text and code sections are re-tokenized;\n * image sections are skipped.\n *\n * @returns a report of sections and terms re-indexed\n */\n async rebuildIndexes(): Promise<RebuildResult> {\n return this.call('rebuildIndexes', {}) as Promise<RebuildResult>;\n }\n\n /**\n * Invalidates the in-memory cache entry for a single section.\n *\n * @param kbid - identifier of the section to evict from cache\n */\n async invalidate(kbid: string): Promise<void> {\n await this.call('invalidate', { kbid });\n }\n\n /** Clears all entries from the daemon's in-memory cache. */\n async invalidateAll(): Promise<void> {\n await this.call('invalidateAll', {});\n }\n\n /**\n * Retrieves diagnostic status information from the daemon.\n *\n * @returns current initialization state and cache statistics\n */\n async status(): Promise<StatusResult> {\n return this.call('status', {}) as Promise<StatusResult>;\n }\n\n /**\n * Returns database metadata and status from the daemon,\n * including document count, section count, index size, and\n * cache statistics.\n *\n * @returns database metadata from the daemon's cached state\n */\n async dbStatus(): Promise<StatusResult> {\n return this.call('dbStatus', {}) as Promise<StatusResult>;\n }\n\n /**\n * Initialises a new `.kbdb` database directory at the given path\n * by sending an init request to the worker daemon.\n *\n * The daemon creates all required subdirectories and seed files via\n * the `worker_init_directory` WASM export.\n *\n * @param targetPath - absolute path to the directory that will\n * contain the new `.kbdb` database\n * @throws {Error} if the `.kbdb` directory already exists or the\n * daemon cannot create the layout\n */\n async initDirectory(targetPath: string): Promise<void> {\n await this.call('initDirectory', { targetPath });\n }\n\n /**\n * Runs all pending database migrations for the `.kbdb` directory\n * at the given path.\n *\n * Delegates to the `worker_migrate` WASM export on the daemon.\n * Each migration step updates `catalog.toml` on success, so\n * retrying after a partial failure is safe.\n *\n * @param targetPath - absolute path to the `.kbdb` database root\n * @returns migration report with old version, new version, and\n * number of migration steps applied\n */\n async migrateDatabase(targetPath: string): Promise<MigrateResult> {\n return this.call('migrateDatabase', {\n targetPath,\n }) as Promise<MigrateResult>;\n }\n\n /**\n * Checks the format version of the `.kbdb` database at the given\n * path against the version required by the current WASM engine.\n *\n * This is a read-only operation: it reads `catalog.toml` and\n * returns the compatibility status without making any changes.\n *\n * @param targetPath - absolute path to the `.kbdb` database root\n * @returns version compatibility report\n */\n async checkVersion(targetPath: string): Promise<VersionStatus> {\n return this.call('checkVersion', {\n targetPath,\n }) as Promise<VersionStatus>;\n }\n\n /**\n * Retrieves all sections whose type name matches the given string.\n *\n * @param sectionType - the application-level type name to filter by\n * @returns all section records with a matching type name\n */\n async listByType(sectionType: string): Promise<SectionRecord[]> {\n return this.call('listByType', {\n sectionType,\n }) as Promise<SectionRecord[]>;\n }\n\n /**\n * Retrieves all documents whose type name matches the given string.\n *\n * @param docType - the application-level document type to filter by\n * @returns all document manifests with a matching type name\n */\n async listDocumentsByType(\n docType: string,\n ): Promise<DocumentManifest[]> {\n return this.call('listDocumentsByType', {\n docType,\n }) as Promise<DocumentManifest[]>;\n }\n\n /**\n * Exports the database to a target directory on disk.\n *\n * Copies section files, document manifests, and `catalog.toml`\n * to `params.path`. Index files are not exported because they\n * are derivable from the section and document data.\n *\n * @param params - optional export parameters\n * @param params.path - target directory path; defaults to\n * `./kbdb-export/` when not provided\n * @returns export report with the resolved path and file counts\n */\n async export(params?: {\n path?: string;\n format?: string;\n }): Promise<ExportResult> {\n return this.call('export', {\n targetPath: params?.path || undefined,\n format: params?.format,\n }) as Promise<ExportResult>;\n }\n\n /**\n * Imports an exported database from the given path.\n *\n * @param params - source path and dry-run flag\n * @returns import report with counts and timing\n */\n async import(params: {\n from: string;\n dryRun: boolean;\n }): Promise<ImportResult> {\n return this.call('importDb', {\n sourcePath: params.from,\n dryRun: params.dryRun,\n }) as Promise<ImportResult>;\n }\n\n /**\n * Sends a JSON-RPC 2.0 request and awaits the response.\n *\n * @param method - the RPC method name\n * @param params - parameters to include in the request\n * @throws {Error} if not connected\n * @throws {Error} when the daemon returns an error response\n */\n private async call(\n method: string,\n params: unknown,\n ): Promise<unknown> {\n const socket = this.socket;\n if (!socket) {\n throw new Error('not connected');\n }\n\n const id = this.nextId++;\n const request = {\n jsonrpc: '2.0',\n id,\n method,\n params: { ctx: this.contextId, ...(params as object) },\n };\n\n const timeoutMs = this.requestTimeoutMs;\n return new Promise<unknown>((resolve, reject) => {\n const call: PendingCall = { resolve, reject };\n if (timeoutMs) {\n call.timer = setTimeout(() => {\n if (!this.pending.has(id)) return;\n this.pending.delete(id);\n const err = new Error(\n `request timeout after ${String(timeoutMs)}ms`,\n );\n (err as unknown as Record<string, unknown>).code =\n 'REQUEST_TIMEOUT';\n reject(err);\n }, timeoutMs);\n }\n this.pending.set(id, call);\n socket.write(JSON.stringify(request) + '\\n');\n });\n }\n\n /**\n * Processes incoming data from the socket, splitting on newlines\n * and dispatching complete JSON-RPC response objects.\n *\n * @param data - raw string chunk received from the socket\n */\n private handleData(data: string): void {\n this.buffer += data;\n const lines = this.buffer.split('\\n');\n this.buffer = lines.pop() ?? '';\n\n for (const line of lines) {\n if (!line.trim()) continue;\n try {\n const response = JSON.parse(line) as JsonRpcResponse;\n const pending = this.pending.get(response.id);\n if (pending) {\n this.pending.delete(response.id);\n if (pending.timer) clearTimeout(pending.timer);\n if (response.error) {\n const err = new Error(response.error.message);\n (err as unknown as Record<string, unknown>).code =\n response.error.code;\n pending.reject(err);\n } else {\n pending.resolve(response.result);\n }\n }\n } catch {\n // Ignore unparseable lines\n }\n }\n }\n}\n", "import { existsSync, readFileSync, unlinkSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport { WorkerClient } from '../classes/worker-client.class.ts';\nimport { resolveDbPath } from './resolve-db-path.function.ts';\nimport { computeContextId } from './compute-context-id.function.ts';\nimport { discoverDaemon } from './discover-daemon.function.ts';\nimport { spawnDaemon } from './spawn-daemon.function.ts';\nimport { waitForDaemon } from './wait-for-daemon.function.ts';\nimport { detectRuntime } from '../../runtime/functions/detect-runtime.ts';\nimport { getIpcPath } from '../../platform/functions/get-ipc-path.function.ts';\nimport type { WorkerClientOptions } from '../typings/worker-client-options.interface.ts';\n\n/**\n * Creates and connects a `WorkerClient` to the worker daemon.\n *\n * Resolves the context path, derives a stable context identifier,\n * and checks whether a daemon is already running. If no daemon is\n * found and `autoSpawn` is not `false`, a new daemon process is\n * spawned and the factory waits for its PID file to appear before\n * connecting.\n *\n * @param options - optional configuration for path resolution,\n * auto-spawn behaviour, and connection timeout\n * @returns a connected `WorkerClient` ready to send requests\n * @throws {Error} if the `.kbdb` directory cannot be found\n * @throws {Error} if the socket connection cannot be established\n */\nexport async function createWorkerClient(\n options?: WorkerClientOptions,\n): Promise<WorkerClient> {\n const dbPath =\n options?.contextPath ?? resolveDbPath(options?.dbPath);\n const contextId = await computeContextId(dbPath);\n const socketPath = getIpcPath(contextId);\n\n let daemon = discoverDaemon(contextId);\n\n if (!daemon && options?.autoSpawn !== false) {\n const runtime = detectRuntime();\n spawnDaemon(dbPath, runtime, options?.workerScript);\n await waitForDaemon(contextId, options?.connectTimeoutMs);\n daemon = discoverDaemon(contextId);\n }\n\n if (!daemon) {\n throw new Error(\n `kbdb worker daemon did not start: ${readCrashReason(contextId)}`,\n );\n }\n\n const client = new WorkerClient(\n socketPath,\n contextId,\n options?.requestTimeoutMs,\n );\n await client.connect();\n return client;\n}\n\nfunction readCrashReason(contextId: string): string {\n const crashPath = join(tmpdir(), `kbdb-${contextId}.crash`);\n if (!existsSync(crashPath)) {\n return 'daemon failed to start (no details available)';\n }\n try {\n const raw = readFileSync(crashPath, 'utf-8');\n const crash = JSON.parse(raw) as { error?: string };\n unlinkSync(crashPath);\n return crash.error ?? 'unknown error (crash log empty)';\n } catch {\n return 'daemon failed to start (crash log unreadable)';\n }\n}\n", "import { existsSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\n/**\n * Resolves the absolute path to the `.kbdb` database directory.\n *\n * Searches for a `.kbdb` sub-directory inside `targetDir`. When\n * `targetDir` is omitted, `process.cwd()` is used as the base.\n *\n * @param targetDir - directory to search in; defaults to cwd\n * @throws {Error} if no `.kbdb` directory exists at the resolved\n * path\n */\nexport function resolveDbPath(targetDir?: string): string {\n const base = targetDir ? resolve(targetDir) : process.cwd();\n const dbPath = join(base, '.kbdb');\n if (!existsSync(dbPath)) {\n throw new Error(`database not found: ${dbPath}`);\n }\n return dbPath;\n}\n", "/**\n * Computes the SHA-256 hash of a UTF-8 string.\n *\n * Uses the Web Crypto API (`crypto.subtle`), which is available\n * in both Deno and Node.js >= 20 without additional imports.\n *\n * @param input - the string to hash\n * @returns lowercase hex-encoded SHA-256 digest (64 characters)\n */\nexport async function computeSha256(input: string): Promise<string> {\n const data = new TextEncoder().encode(input);\n const hash = await crypto.subtle.digest('SHA-256', data);\n const bytes = new Uint8Array(hash);\n return Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, '0'))\n .join('');\n}\n", "import { computeSha256 } from '../../hash/functions/compute-sha256.ts';\n\n/**\n * Computes a short context identifier for an absolute path.\n *\n * Hashes the path with SHA-256 and returns the first 16 hex\n * characters. The result is stable for the same input and unique\n * enough to avoid accidental collisions across typical path sets.\n *\n * @param absolutePath - the absolute filesystem path to identify\n * @returns a 16-character lowercase hex string\n */\nexport async function computeContextId(\n absolutePath: string,\n): Promise<string> {\n const hash = await computeSha256(absolutePath);\n return hash.slice(0, 16);\n}\n", "import { existsSync, readFileSync, unlinkSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { tmpdir } from 'node:os';\nimport { isProcessAlive } from '../../platform/functions/is-process-alive.function.ts';\nimport type { DaemonInfo } from '../typings/daemon-info.model.ts';\n\nexport type { DaemonInfo };\n\n/**\n * Discovers a running worker daemon for the given context.\n *\n * Reads the PID file at `<tmpdir>/kbdb-<contextId>.pid`. If the\n * file exists and the process is alive, returns its PID and the\n * expected socket path. If the file is stale (process dead or PID\n * unparseable), removes the PID file and returns `null`.\n *\n * @param contextId - the 16-character context identifier\n * @returns daemon location info, or `null` if no live daemon found\n */\nexport function discoverDaemon(contextId: string): DaemonInfo | null {\n const pidPath = join(tmpdir(), `kbdb-${contextId}.pid`);\n\n if (!existsSync(pidPath)) return null;\n\n const pidStr = readFileSync(pidPath, 'utf-8').trim();\n const pid = parseInt(pidStr, 10);\n\n if (isNaN(pid) || !isProcessAlive(pid)) {\n try {\n unlinkSync(pidPath);\n } catch {\n // Stale PID file removal is best-effort\n }\n return null;\n }\n\n const socketPath = join(tmpdir(), `kbdb-${contextId}.sock`);\n\n const crashPath = join(tmpdir(), `kbdb-${contextId}.crash`);\n try {\n unlinkSync(crashPath);\n } catch {\n // stale crash file removal is best-effort\n }\n\n return { pid, socketPath };\n}\n", "/**\n * Checks whether a process with the given PID is alive.\n *\n * Sends signal `0` to the process, which performs a permission\n * check without sending an actual signal. Returns `true` if the\n * process exists and is reachable, `false` otherwise.\n *\n * @param pid - the process identifier to probe\n */\nexport function isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch {\n return false;\n }\n}\n", "import { spawn } from 'node:child_process';\nimport type { Runtime } from '../../runtime/typings/runtime.ts';\n\n/**\n * Spawns a detached worker daemon process for the given context.\n *\n * @param contextPath - absolute path to the context directory the\n * daemon should serve\n * @param runtime - the current JavaScript runtime environment\n * @param workerScript - absolute path to the worker daemon script,\n * resolved at the entry point by `resolveWorkerScript`\n */\nexport function spawnDaemon(\n contextPath: string,\n runtime: Runtime,\n workerScript?: string,\n): void {\n if (!workerScript) {\n throw new Error(\n 'workerScript must be provided' + ' (resolve at entry point)',\n );\n }\n const execPath = runtime === 'deno' ? 'deno' : process.execPath;\n\n const args =\n runtime === 'deno'\n ? ['run', '--allow-all', workerScript, contextPath]\n : [workerScript, contextPath];\n\n const child = spawn(execPath, args, {\n detached: true,\n stdio: 'ignore',\n });\n child.unref();\n}\n", "import { existsSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { tmpdir } from 'node:os';\n\n/** Default maximum wait time for the daemon PID file to appear. */\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\n/** Polling interval in milliseconds between existence checks. */\nconst POLL_INTERVAL_MS = 100;\n\n/**\n * Waits for the worker daemon's PID file to appear on disk.\n *\n * Polls every 100 ms until the PID file at\n * `<tmpdir>/kbdb-<contextId>.pid` exists or the timeout elapses.\n *\n * @param contextId - the 16-character context identifier\n * @param timeoutMs - maximum wait time in milliseconds; defaults\n * to 10 000 ms\n * @returns `true` if the PID file appeared before the timeout,\n * `false` otherwise\n */\nexport async function waitForDaemon(\n contextId: string,\n timeoutMs: number = DEFAULT_TIMEOUT_MS,\n): Promise<boolean> {\n const pidPath = join(tmpdir(), `kbdb-${contextId}.pid`);\n const start = Date.now();\n while (Date.now() - start < timeoutMs) {\n if (existsSync(pidPath)) return true;\n await new Promise<void>((r) => setTimeout(r, POLL_INTERVAL_MS));\n }\n return false;\n}\n", "import type { Runtime } from '../typings/runtime.ts';\n\n/**\n * Detects the current JavaScript runtime environment.\n *\n * Returns `'deno'` when the global `Deno` object is present,\n * otherwise returns `'node'`.\n */\nexport function detectRuntime(): Runtime {\n if (typeof globalThis !== 'undefined' && 'Deno' in globalThis) {\n return 'deno';\n }\n return 'node';\n}\n", "import { join } from 'node:path';\nimport { getTmpdir } from './get-tmpdir.function.ts';\n\n/**\n * Returns the platform-appropriate IPC socket path for a given\n * context identifier.\n *\n * On Windows, returns a named pipe path (`\\\\.\\pipe\\kbdb-<ctx>`).\n * On POSIX systems, returns a Unix domain socket path under the\n * system temp directory (`<tmpdir>/kbdb-<ctx>.sock`).\n *\n * @param ctx - unique context identifier embedded in the path\n */\nexport function getIpcPath(ctx: string): string {\n if (process.platform === 'win32') {\n return `\\\\\\\\.\\\\pipe\\\\kbdb-${ctx}`;\n }\n return join(getTmpdir(), `kbdb-${ctx}.sock`);\n}\n", "import { tmpdir } from 'node:os';\n\n/**\n * Returns the operating system's default temporary directory path.\n */\nexport function getTmpdir(): string {\n return tmpdir();\n}\n", "import { createWorkerClient } from './create-worker-client.function.ts';\nimport type { WorkerClient } from '../classes/worker-client.class.ts';\nimport type { WorkerClientOptions } from '../typings/worker-client-options.interface.ts';\nimport { resolveDbPath } from './resolve-db-path.function.ts';\n\n/** Cache of connected clients keyed by database path. */\nconst cache = new Map<string, WorkerClient>();\n\n/**\n * Returns a cached `WorkerClient` for the given context\n * path, or creates and caches a new one if the cached\n * client is disconnected or absent.\n *\n * Intended for library consumers and the MCP server. CLI\n * one-shots should use `createWorkerClient()` directly.\n *\n * @param options - optional configuration forwarded to\n * `createWorkerClient`\n * @returns a connected `WorkerClient`\n */\nexport async function getOrCreateClient(\n options?: WorkerClientOptions,\n): Promise<WorkerClient> {\n const dbPath =\n options?.contextPath ?? resolveDbPath(options?.dbPath);\n const cached = cache.get(dbPath);\n if (cached?.isConnected) return cached;\n cache.delete(dbPath);\n const client = await createWorkerClient(options);\n cache.set(dbPath, client);\n return client;\n}\n\n/**\n * Clears the internal client cache. Intended for tests\n * that need isolation between runs.\n */\nexport function clearClientCache(): void {\n for (const [key, client] of cache) {\n client.disconnect();\n cache.delete(key);\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCO,IAAM,UAAU;;;ACDvB,sBAAwB;AAsDjB,IAAM,eAAN,MAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBvB,YACoB,YACA,WACA,kBAClB;AAHkB;AACA;AACA;AAAA,EACjB;AAAA;AAAA,EAvBK,SAAwB;AAAA;AAAA,EAGxB,SAAS;AAAA;AAAA,EAGA,UAAU,oBAAI,IAAyB;AAAA;AAAA,EAGhD,SAAS;AAAA;AAAA,EAiBjB,IAAI,cAAuB;AACxB,WAAO,KAAK,WAAW;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,UAAy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,KAAC,4BAAW,SAAS,GAAG;AACzB,WAAO;AAAA,EACV;AACA,MAAI;AACD,UAAM,UAAM,8BAAa,WAAW,OAAO;AAC3C,UAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,oCAAW,SAAS;AACpB,WAAO,MAAM,SAAS;AAAA,EACzB,QAAQ;AACL,WAAO;AAAA,EACV;AACH;;;AWnEA,IAAM,QAAQ,oBAAI,IAA0B;AAc5C,eAAsB,kBACnB,SACsB;AACtB,QAAM,SACH,SAAS,eAAe,cAAc,SAAS,MAAM;AACxD,QAAM,SAAS,MAAM,IAAI,MAAM;AAC/B,MAAI,QAAQ,YAAa,QAAO;AAChC,QAAM,OAAO,MAAM;AACnB,QAAM,SAAS,MAAM,mBAAmB,OAAO;AAC/C,QAAM,IAAI,QAAQ,MAAM;AACxB,SAAO;AACV;",
|
|
6
6
|
"names": ["resolve", "import_node_fs", "import_node_path", "import_node_os", "import_node_fs", "import_node_path", "import_node_fs", "import_node_path", "import_node_os", "import_node_path", "import_node_os"]
|
|
7
7
|
}
|
package/dist/mod.d.ts
CHANGED
|
@@ -23,6 +23,27 @@
|
|
|
23
23
|
* client.disconnect();
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
+
/** Semantic version string matching `package.json`. */
|
|
26
27
|
export { version } from './src/shared/mod.ts';
|
|
27
|
-
|
|
28
|
-
export
|
|
28
|
+
/** Creates a connected worker client for the given database. */
|
|
29
|
+
export { createWorkerClient } from './src/shared/worker-client/index.ts';
|
|
30
|
+
/** Persistent client wrapping JSON-RPC calls to the daemon. */
|
|
31
|
+
export { WorkerClient } from './src/shared/worker-client/index.ts';
|
|
32
|
+
/** Resolves a parent directory to the `.kbdb` path inside it. */
|
|
33
|
+
export { resolveDbPath } from './src/shared/worker-client/index.ts';
|
|
34
|
+
/** Derives the 16-char hex context ID from an absolute path. */
|
|
35
|
+
export { computeContextId } from './src/shared/worker-client/index.ts';
|
|
36
|
+
/** Returns a cached client or creates a new one for the given path. */
|
|
37
|
+
export { getOrCreateClient } from './src/shared/worker-client/index.ts';
|
|
38
|
+
/** Options accepted by {@linkcode createWorkerClient}. */
|
|
39
|
+
export type { WorkerClientOptions } from './src/shared/worker-client/index.ts';
|
|
40
|
+
/** Parameters for a search query. */
|
|
41
|
+
export type { SearchParams } from './src/shared/worker-client/index.ts';
|
|
42
|
+
/** A single ranked result returned by search. */
|
|
43
|
+
export type { SearchResult } from './src/shared/worker-client/index.ts';
|
|
44
|
+
/** Raw section record stored on disk. */
|
|
45
|
+
export type { Section } from './src/shared/worker-client/index.ts';
|
|
46
|
+
/** Parameters for adding a new section. */
|
|
47
|
+
export type { AddSectionParams } from './src/shared/worker-client/index.ts';
|
|
48
|
+
/** Database status snapshot returned by `client.status()`. */
|
|
49
|
+
export type { StatusResult } from './src/shared/worker-client/index.ts';
|