@dikolab/kbdb 0.1.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/LICENSE +15 -0
- package/README.md +270 -0
- package/dist/chunk-QCCN7OZH.mjs +82 -0
- package/dist/chunk-QCCN7OZH.mjs.map +7 -0
- package/dist/cli.cjs +3598 -0
- package/dist/cli.cjs.map +7 -0
- package/dist/cli.mjs +3537 -0
- package/dist/cli.mjs.map +7 -0
- package/dist/kbdb-worker.cjs +1659 -0
- package/dist/kbdb-worker.cjs.map +7 -0
- package/dist/mod.cjs +538 -0
- package/dist/mod.cjs.map +7 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.mjs +507 -0
- package/dist/mod.mjs.map +7 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +11 -0
- package/dist/src/shared/cli/constants/help-text.constant.d.ts +2 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +37 -0
- package/dist/src/shared/cli/functions/ensure-db.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/error-to-message.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/find-db.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/generate-help.function.d.ts +31 -0
- package/dist/src/shared/cli/functions/is-stdin-tty.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/parse-args.function.d.ts +25 -0
- package/dist/src/shared/cli/functions/prompt-user.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/run-agent-create.function.d.ts +58 -0
- package/dist/src/shared/cli/functions/run-agent-delete.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-agent-get.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +45 -0
- package/dist/src/shared/cli/functions/run-check.function.d.ts +64 -0
- package/dist/src/shared/cli/functions/run-cli.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-content.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-db-init.function.d.ts +23 -0
- package/dist/src/shared/cli/functions/run-db-migrate.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-gc.function.d.ts +38 -0
- package/dist/src/shared/cli/functions/run-init.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-migrate.function.d.ts +57 -0
- package/dist/src/shared/cli/functions/run-rebuild.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-search.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-skill-delete.function.d.ts +30 -0
- package/dist/src/shared/cli/functions/run-skill-get.function.d.ts +49 -0
- package/dist/src/shared/cli/functions/run-skill-learn.function.d.ts +36 -0
- package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +43 -0
- package/dist/src/shared/cli/functions/run-status.function.d.ts +22 -0
- package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +45 -0
- package/dist/src/shared/cli/index.d.ts +35 -0
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +53 -0
- package/dist/src/shared/cli/typings/command-result.model.d.ts +15 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +11 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +17 -0
- package/dist/src/shared/dir-resolver/functions/resolve-base-dir.function.d.ts +3 -0
- package/dist/src/shared/dir-resolver/functions/resolve-wasm-dir.function.d.ts +1 -0
- package/dist/src/shared/dir-resolver/functions/resolve-worker-script.function.d.ts +2 -0
- package/dist/src/shared/dir-resolver/index.d.ts +4 -0
- package/dist/src/shared/dir-resolver/typings/base-dir.interface.d.ts +4 -0
- package/dist/src/shared/hash/functions/compute-sha256.d.ts +10 -0
- package/dist/src/shared/hash/index.d.ts +1 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +55 -0
- package/dist/src/shared/mcp/constants/mcp-error-codes.constant.d.ts +26 -0
- package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/create-prompt-definitions.function.d.ts +41 -0
- package/dist/src/shared/mcp/functions/create-resource-templates.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/create-tool-definitions.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/extract-skill-arguments.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-agent-create.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-delete.function.d.ts +28 -0
- package/dist/src/shared/mcp/functions/handle-agent-get.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-list.function.d.ts +31 -0
- package/dist/src/shared/mcp/functions/handle-completion.function.d.ts +58 -0
- package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +23 -0
- package/dist/src/shared/mcp/functions/handle-resource-read.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/handle-roots-list.function.d.ts +21 -0
- package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/parse-skill-content.function.d.ts +15 -0
- package/dist/src/shared/mcp/functions/serialize-skill-content.function.d.ts +9 -0
- package/dist/src/shared/mcp/functions/should-emit-log.function.d.ts +20 -0
- package/dist/src/shared/mcp/index.d.ts +9 -0
- package/dist/src/shared/mcp/typings/agent-types.interface.d.ts +38 -0
- package/dist/src/shared/mcp/typings/log-types.interface.d.ts +17 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +217 -0
- package/dist/src/shared/mcp/typings/mcp-types.interface.d.ts +149 -0
- package/dist/src/shared/mcp/typings/prompt-types.interface.d.ts +37 -0
- package/dist/src/shared/mcp/typings/remove-section-result.model.d.ts +10 -0
- package/dist/src/shared/mcp/typings/sampling-types.interface.d.ts +46 -0
- package/dist/src/shared/mcp/typings/skill-types.interface.d.ts +28 -0
- package/dist/src/shared/mod.d.ts +1 -0
- package/dist/src/shared/platform/functions/get-ipc-path.function.d.ts +11 -0
- package/dist/src/shared/platform/functions/get-tmpdir.function.d.ts +4 -0
- package/dist/src/shared/platform/functions/is-process-alive.function.d.ts +10 -0
- package/dist/src/shared/platform/index.d.ts +3 -0
- package/dist/src/shared/runtime/functions/detect-runtime.d.ts +8 -0
- package/dist/src/shared/runtime/functions/get-args.d.ts +7 -0
- package/dist/src/shared/runtime/index.d.ts +3 -0
- package/dist/src/shared/runtime/typings/runtime.d.ts +2 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +2 -0
- package/dist/src/shared/version/index.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-compose-output.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest-list.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest.function.d.ts +40 -0
- package/dist/src/shared/wasm-codec/functions/decode-f32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-key-value-text.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-remove-flag.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record-list.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +50 -0
- package/dist/src/shared/wasm-codec/functions/decode-string.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-u32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-u64.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-group-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-identifier-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-kbid-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-option-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-section-type.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-type-filter-param.function.d.ts +11 -0
- package/dist/src/shared/wasm-codec/functions/encode-u32.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/index.d.ts +29 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +230 -0
- package/dist/src/shared/worker-client/functions/compute-context-id.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/create-worker-client.function.d.ts +18 -0
- package/dist/src/shared/worker-client/functions/discover-daemon.function.d.ts +14 -0
- package/dist/src/shared/worker-client/functions/resolve-db-path.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/wait-for-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-client/index.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/content-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/daemon-info.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +36 -0
- package/dist/src/shared/worker-client/typings/migrate-result.model.d.ts +11 -0
- package/dist/src/shared/worker-client/typings/rebuild-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/remove-section-result.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +26 -0
- package/dist/src/shared/worker-client/typings/status-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/version-status.model.d.ts +24 -0
- package/dist/src/shared/worker-client/typings/worker-client-error.interface.d.ts +8 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +30 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +147 -0
- package/dist/src/shared/worker-daemon/constants/daemon-defaults.constant.d.ts +24 -0
- package/dist/src/shared/worker-daemon/functions/create-host-imports.function.d.ts +68 -0
- package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +18 -0
- package/dist/src/shared/worker-daemon/functions/load-wasm-modules.function.d.ts +19 -0
- package/dist/src/shared/worker-daemon/functions/read-config.function.d.ts +12 -0
- package/dist/src/shared/worker-daemon/functions/run-worker.function.d.ts +26 -0
- package/dist/src/shared/worker-daemon/functions/start-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/index.d.ts +9 -0
- package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +13 -0
- package/dist/src/shared/worker-daemon/typings/ipc-handler.interface.d.ts +36 -0
- package/dist/src/shared/worker-daemon/typings/wasm-modules.interface.d.ts +7 -0
- package/dist/src/worker.d.ts +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/worker.mjs +1615 -0
- package/dist/worker.mjs.map +7 -0
- package/mod.ts +17 -0
- package/package.json +85 -0
- package/src/cli.ts +62 -0
- package/src/shared/cli/constants/defaults.constant.ts +19 -0
- package/src/shared/cli/constants/help-text.constant.ts +4 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +338 -0
- package/src/shared/cli/functions/ensure-db.function.ts +21 -0
- package/src/shared/cli/functions/error-to-message.function.ts +9 -0
- package/src/shared/cli/functions/find-db.function.ts +20 -0
- package/src/shared/cli/functions/format-output.function.ts +64 -0
- package/src/shared/cli/functions/generate-help.function.ts +599 -0
- package/src/shared/cli/functions/is-stdin-tty.function.ts +12 -0
- package/src/shared/cli/functions/parse-args.function.ts +133 -0
- package/src/shared/cli/functions/prompt-user.function.ts +36 -0
- package/src/shared/cli/functions/run-agent-create.function.ts +114 -0
- package/src/shared/cli/functions/run-agent-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-agent-get.function.ts +166 -0
- package/src/shared/cli/functions/run-agent-list.function.ts +58 -0
- package/src/shared/cli/functions/run-check.function.ts +78 -0
- package/src/shared/cli/functions/run-cli.function.ts +299 -0
- package/src/shared/cli/functions/run-content.function.ts +47 -0
- package/src/shared/cli/functions/run-db-init.function.ts +44 -0
- package/src/shared/cli/functions/run-db-migrate.function.ts +40 -0
- package/src/shared/cli/functions/run-gc.function.ts +45 -0
- package/src/shared/cli/functions/run-init.function.ts +91 -0
- package/src/shared/cli/functions/run-learn.function.ts +171 -0
- package/src/shared/cli/functions/run-migrate.function.ts +85 -0
- package/src/shared/cli/functions/run-rebuild.function.ts +47 -0
- package/src/shared/cli/functions/run-search.function.ts +62 -0
- package/src/shared/cli/functions/run-skill-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-skill-get.function.ts +90 -0
- package/src/shared/cli/functions/run-skill-learn.function.ts +70 -0
- package/src/shared/cli/functions/run-skill-list.function.ts +74 -0
- package/src/shared/cli/functions/run-status.function.ts +29 -0
- package/src/shared/cli/functions/run-unlearn.function.ts +58 -0
- package/src/shared/cli/index.ts +48 -0
- package/src/shared/cli/typings/cli-options.interface.ts +55 -0
- package/src/shared/cli/typings/command-result.model.ts +15 -0
- package/src/shared/cli/typings/learn-result.model.ts +11 -0
- package/src/shared/cli/typings/search-display.model.ts +17 -0
- package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +25 -0
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +5 -0
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +13 -0
- package/src/shared/dir-resolver/index.ts +7 -0
- package/src/shared/dir-resolver/typings/base-dir.interface.ts +4 -0
- package/src/shared/hash/functions/compute-sha256.ts +17 -0
- package/src/shared/hash/index.ts +1 -0
- package/src/shared/mcp/classes/mcp-server.class.ts +448 -0
- package/src/shared/mcp/constants/mcp-error-codes.constant.ts +30 -0
- package/src/shared/mcp/functions/create-mcp-server.function.ts +14 -0
- package/src/shared/mcp/functions/create-prompt-definitions.function.ts +102 -0
- package/src/shared/mcp/functions/create-resource-templates.function.ts +23 -0
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +401 -0
- package/src/shared/mcp/functions/extract-skill-arguments.function.ts +27 -0
- package/src/shared/mcp/functions/handle-agent-create.function.ts +116 -0
- package/src/shared/mcp/functions/handle-agent-delete.function.ts +50 -0
- package/src/shared/mcp/functions/handle-agent-get.function.ts +160 -0
- package/src/shared/mcp/functions/handle-agent-list.function.ts +50 -0
- package/src/shared/mcp/functions/handle-completion.function.ts +114 -0
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +214 -0
- package/src/shared/mcp/functions/handle-resource-read.function.ts +56 -0
- package/src/shared/mcp/functions/handle-roots-list.function.ts +29 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +464 -0
- package/src/shared/mcp/functions/parse-skill-content.function.ts +38 -0
- package/src/shared/mcp/functions/serialize-skill-content.function.ts +12 -0
- package/src/shared/mcp/functions/should-emit-log.function.ts +38 -0
- package/src/shared/mcp/index.ts +28 -0
- package/src/shared/mcp/typings/agent-types.interface.ts +39 -0
- package/src/shared/mcp/typings/log-types.interface.ts +26 -0
- package/src/shared/mcp/typings/mcp-client.interface.ts +252 -0
- package/src/shared/mcp/typings/mcp-types.interface.ts +158 -0
- package/src/shared/mcp/typings/prompt-types.interface.ts +39 -0
- package/src/shared/mcp/typings/remove-section-result.model.ts +10 -0
- package/src/shared/mcp/typings/sampling-types.interface.ts +48 -0
- package/src/shared/mcp/typings/skill-types.interface.ts +29 -0
- package/src/shared/mod.ts +1 -0
- package/src/shared/platform/functions/get-ipc-path.function.ts +19 -0
- package/src/shared/platform/functions/get-tmpdir.function.ts +8 -0
- package/src/shared/platform/functions/is-process-alive.function.ts +17 -0
- package/src/shared/platform/index.ts +3 -0
- package/src/shared/runtime/functions/detect-runtime.ts +14 -0
- package/src/shared/runtime/functions/get-args.ts +16 -0
- package/src/shared/runtime/index.ts +3 -0
- package/src/shared/runtime/typings/runtime.ts +2 -0
- package/src/shared/version/constants/version.constant.ts +2 -0
- package/src/shared/version/index.ts +1 -0
- package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +70 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +87 -0
- package/src/shared/wasm-codec/functions/decode-f32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +15 -0
- package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +3 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +54 -0
- package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +20 -0
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +162 -0
- package/src/shared/wasm-codec/functions/decode-string.function.ts +22 -0
- package/src/shared/wasm-codec/functions/decode-u32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-u64.function.ts +16 -0
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +34 -0
- package/src/shared/wasm-codec/functions/encode-group-params.function.ts +28 -0
- package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-option-string.function.ts +14 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-section-type.function.ts +18 -0
- package/src/shared/wasm-codec/functions/encode-string.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +13 -0
- package/src/shared/wasm-codec/functions/encode-u32.function.ts +5 -0
- package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +16 -0
- package/src/shared/wasm-codec/index.ts +36 -0
- package/src/shared/worker-client/classes/worker-client.class.ts +427 -0
- package/src/shared/worker-client/functions/compute-context-id.function.ts +18 -0
- package/src/shared/worker-client/functions/create-worker-client.function.ts +70 -0
- package/src/shared/worker-client/functions/discover-daemon.function.ts +47 -0
- package/src/shared/worker-client/functions/resolve-db-path.function.ts +21 -0
- package/src/shared/worker-client/functions/spawn-daemon.function.ts +35 -0
- package/src/shared/worker-client/functions/wait-for-daemon.function.ts +34 -0
- package/src/shared/worker-client/index.ts +31 -0
- package/src/shared/worker-client/typings/add-section-result.model.ts +22 -0
- package/src/shared/worker-client/typings/content-result.model.ts +12 -0
- package/src/shared/worker-client/typings/daemon-info.model.ts +7 -0
- package/src/shared/worker-client/typings/gc-result.model.ts +12 -0
- package/src/shared/worker-client/typings/integrity-check-result.model.ts +43 -0
- package/src/shared/worker-client/typings/migrate-result.model.ts +11 -0
- package/src/shared/worker-client/typings/rebuild-result.model.ts +12 -0
- package/src/shared/worker-client/typings/remove-section-result.model.ts +7 -0
- package/src/shared/worker-client/typings/search-params.model.ts +12 -0
- package/src/shared/worker-client/typings/search-result.model.ts +14 -0
- package/src/shared/worker-client/typings/section.model.ts +27 -0
- package/src/shared/worker-client/typings/status-result.model.ts +14 -0
- package/src/shared/worker-client/typings/version-status.model.ts +28 -0
- package/src/shared/worker-client/typings/worker-client-error.interface.ts +8 -0
- package/src/shared/worker-client/typings/worker-client-options.interface.ts +30 -0
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +1001 -0
- package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +29 -0
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +312 -0
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +83 -0
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +98 -0
- package/src/shared/worker-daemon/functions/read-config.function.ts +83 -0
- package/src/shared/worker-daemon/functions/run-worker.function.ts +57 -0
- package/src/shared/worker-daemon/functions/start-daemon.function.ts +74 -0
- package/src/shared/worker-daemon/index.ts +16 -0
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +13 -0
- package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +39 -0
- package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +7 -0
- package/src/worker.ts +34 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
|
|
5
|
+
/** Default maximum wait time for the daemon PID file to appear. */
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
7
|
+
|
|
8
|
+
/** Polling interval in milliseconds between existence checks. */
|
|
9
|
+
const POLL_INTERVAL_MS = 100;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Waits for the worker daemon's PID file to appear on disk.
|
|
13
|
+
*
|
|
14
|
+
* Polls every 100 ms until the PID file at
|
|
15
|
+
* `<tmpdir>/kbdb-<contextId>.pid` exists or the timeout elapses.
|
|
16
|
+
*
|
|
17
|
+
* @param contextId - the 16-character context identifier
|
|
18
|
+
* @param timeoutMs - maximum wait time in milliseconds; defaults
|
|
19
|
+
* to 10 000 ms
|
|
20
|
+
* @returns `true` if the PID file appeared before the timeout,
|
|
21
|
+
* `false` otherwise
|
|
22
|
+
*/
|
|
23
|
+
export async function waitForDaemon(
|
|
24
|
+
contextId: string,
|
|
25
|
+
timeoutMs: number = DEFAULT_TIMEOUT_MS,
|
|
26
|
+
): Promise<boolean> {
|
|
27
|
+
const pidPath = join(tmpdir(), `kbdb-${contextId}.pid`);
|
|
28
|
+
const start = Date.now();
|
|
29
|
+
while (Date.now() - start < timeoutMs) {
|
|
30
|
+
if (existsSync(pidPath)) return true;
|
|
31
|
+
await new Promise<void>((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export { WorkerClient } from './classes/worker-client.class.ts';
|
|
2
|
+
export { createWorkerClient } from './functions/create-worker-client.function.ts';
|
|
3
|
+
export { resolveDbPath } from './functions/resolve-db-path.function.ts';
|
|
4
|
+
export { computeContextId } from './functions/compute-context-id.function.ts';
|
|
5
|
+
export { discoverDaemon } from './functions/discover-daemon.function.ts';
|
|
6
|
+
export { spawnDaemon } from './functions/spawn-daemon.function.ts';
|
|
7
|
+
export { waitForDaemon } from './functions/wait-for-daemon.function.ts';
|
|
8
|
+
export type { WorkerClientOptions } from './typings/worker-client-options.interface.ts';
|
|
9
|
+
export type { SearchParams } from './typings/search-params.model.ts';
|
|
10
|
+
export type { SearchResult } from './typings/search-result.model.ts';
|
|
11
|
+
export type {
|
|
12
|
+
Section,
|
|
13
|
+
AddSectionParams,
|
|
14
|
+
} from './typings/section.model.ts';
|
|
15
|
+
export type { StatusResult } from './typings/status-result.model.ts';
|
|
16
|
+
export type { WorkerClientError } from './typings/worker-client-error.interface.ts';
|
|
17
|
+
export type { DaemonInfo } from './typings/daemon-info.model.ts';
|
|
18
|
+
export type { AddSectionResult } from './typings/add-section-result.model.ts';
|
|
19
|
+
export type { RemoveSectionResult } from './typings/remove-section-result.model.ts';
|
|
20
|
+
export type { ContentResult } from './typings/content-result.model.ts';
|
|
21
|
+
export type {
|
|
22
|
+
IntegrityCheckResult,
|
|
23
|
+
IntegrityError,
|
|
24
|
+
} from './typings/integrity-check-result.model.ts';
|
|
25
|
+
export type { GcResult } from './typings/gc-result.model.ts';
|
|
26
|
+
export type { RebuildResult } from './typings/rebuild-result.model.ts';
|
|
27
|
+
export type { MigrateResult } from './typings/migrate-result.model.ts';
|
|
28
|
+
export type {
|
|
29
|
+
VersionCompatibility,
|
|
30
|
+
VersionStatus,
|
|
31
|
+
} from './typings/version-status.model.ts';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Result returned by the daemon after adding a new section. */
|
|
2
|
+
export interface AddSectionResult {
|
|
3
|
+
/** Knowledge-base identifier assigned to the section. */
|
|
4
|
+
readonly kbid: string;
|
|
5
|
+
/** MIME type of the stored section. */
|
|
6
|
+
readonly type: string;
|
|
7
|
+
/** Section title, if provided. */
|
|
8
|
+
readonly title?: string;
|
|
9
|
+
/** Section description, if provided. */
|
|
10
|
+
readonly description?: string;
|
|
11
|
+
/** Total token count for the section. */
|
|
12
|
+
readonly token_count: number;
|
|
13
|
+
/** Number of unique terms indexed for this section. */
|
|
14
|
+
readonly indexed_terms_count: number;
|
|
15
|
+
/** Time taken to process and store the section, in milliseconds. */
|
|
16
|
+
readonly elapsed_ms: number;
|
|
17
|
+
/**
|
|
18
|
+
* `true` when the content already existed and the provided docid
|
|
19
|
+
* was added to the existing section's `docids` list.
|
|
20
|
+
*/
|
|
21
|
+
readonly attached: boolean;
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result returned by the daemon after composing a Markdown document
|
|
3
|
+
* from one or more kbid or docid identifiers.
|
|
4
|
+
*/
|
|
5
|
+
export interface ContentResult {
|
|
6
|
+
/** MIME type of the composed output, always `'text/markdown'`. */
|
|
7
|
+
readonly type: 'text/markdown';
|
|
8
|
+
/** The composed Markdown string. */
|
|
9
|
+
readonly data: string;
|
|
10
|
+
/** Character count of `data` (not byte count). */
|
|
11
|
+
readonly total: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report returned by the daemon after running garbage collection
|
|
3
|
+
* on the knowledge-base database.
|
|
4
|
+
*/
|
|
5
|
+
export interface GcResult {
|
|
6
|
+
/** Number of unreferenced sections removed. */
|
|
7
|
+
readonly removed_sections: number;
|
|
8
|
+
/** Total bytes freed by removing unreferenced sections. */
|
|
9
|
+
readonly removed_bytes: number;
|
|
10
|
+
/** Time taken to complete garbage collection, in milliseconds. */
|
|
11
|
+
readonly elapsed_ms: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** A single integrity error found during a database check. */
|
|
2
|
+
export interface IntegrityError {
|
|
3
|
+
/**
|
|
4
|
+
* The category of integrity violation detected.
|
|
5
|
+
*
|
|
6
|
+
* - `'checksum_mismatch'` -- stored content does not match its hash
|
|
7
|
+
* - `'orphan_section'` -- section not referenced by any document
|
|
8
|
+
* - `'orphan_document'` -- document references no existing sections
|
|
9
|
+
* - `'broken_reference'` -- a marker references a non-existent entity
|
|
10
|
+
* - `'type_mismatch'` -- stored MIME type conflicts with content
|
|
11
|
+
* - `'circular_reference'` -- marker chain contains a cycle
|
|
12
|
+
*/
|
|
13
|
+
readonly type:
|
|
14
|
+
| 'checksum_mismatch'
|
|
15
|
+
| 'orphan_section'
|
|
16
|
+
| 'orphan_document'
|
|
17
|
+
| 'broken_reference'
|
|
18
|
+
| 'type_mismatch'
|
|
19
|
+
| 'circular_reference';
|
|
20
|
+
/** Identifier of the entity (kbid or docid) that has the issue. */
|
|
21
|
+
readonly entity: string;
|
|
22
|
+
/** Human-readable description of the specific problem. */
|
|
23
|
+
readonly detail: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Report returned by the daemon after running an integrity check
|
|
28
|
+
* on the knowledge-base database.
|
|
29
|
+
*/
|
|
30
|
+
export interface IntegrityCheckResult {
|
|
31
|
+
/** `true` when all checks passed and no errors were found. */
|
|
32
|
+
readonly ok: boolean;
|
|
33
|
+
/** All integrity errors found; empty when `ok` is `true`. */
|
|
34
|
+
readonly errors: IntegrityError[];
|
|
35
|
+
/** Total number of sections examined. */
|
|
36
|
+
readonly sections_checked: number;
|
|
37
|
+
/** Total number of documents examined. */
|
|
38
|
+
readonly documents_checked: number;
|
|
39
|
+
/** Total number of marker references checked. */
|
|
40
|
+
readonly references_checked: number;
|
|
41
|
+
/** Time taken to complete the check, in milliseconds. */
|
|
42
|
+
readonly elapsed_ms: number;
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report returned by the daemon after running database migrations.
|
|
3
|
+
*/
|
|
4
|
+
export interface MigrateResult {
|
|
5
|
+
/** The database format version before migration. */
|
|
6
|
+
readonly oldVersion: number;
|
|
7
|
+
/** The database format version after migration. */
|
|
8
|
+
readonly newVersion: number;
|
|
9
|
+
/** Number of individual migration steps that were applied. */
|
|
10
|
+
readonly migrationsRun: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report returned by the daemon after rebuilding all database indexes
|
|
3
|
+
* from section files and document manifests.
|
|
4
|
+
*/
|
|
5
|
+
export interface RebuildResult {
|
|
6
|
+
/** Number of text and code sections that were re-indexed. */
|
|
7
|
+
readonly sections_reindexed: number;
|
|
8
|
+
/** Total number of unique terms written to the rebuilt indexes. */
|
|
9
|
+
readonly terms_indexed: number;
|
|
10
|
+
/** Time taken to complete the rebuild, in milliseconds. */
|
|
11
|
+
readonly elapsed_ms: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Result returned by the daemon after removing a section. */
|
|
2
|
+
export interface RemoveSectionResult {
|
|
3
|
+
/** `true` when the section was found and successfully removed. */
|
|
4
|
+
readonly removed: boolean;
|
|
5
|
+
/** Time taken to perform the removal, in milliseconds. */
|
|
6
|
+
readonly elapsed_ms: number;
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Parameters for a search query sent to the worker daemon. */
|
|
2
|
+
export interface SearchParams {
|
|
3
|
+
/** The search query string. */
|
|
4
|
+
readonly query: string;
|
|
5
|
+
/**
|
|
6
|
+
* Controls what entity type is returned.
|
|
7
|
+
* Defaults to `'sections'` when omitted.
|
|
8
|
+
*/
|
|
9
|
+
readonly mode?: 'sections' | 'documents' | 'stats';
|
|
10
|
+
/** Maximum number of results to return. */
|
|
11
|
+
readonly limit?: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** A single ranked result returned by a search query. */
|
|
2
|
+
export interface SearchResult {
|
|
3
|
+
/** Knowledge-base identifier for the matched section. */
|
|
4
|
+
readonly kbid: string;
|
|
5
|
+
/** Relevance score assigned by the ranking engine. */
|
|
6
|
+
readonly score: number;
|
|
7
|
+
/** Terms that matched within this section. */
|
|
8
|
+
readonly matches: readonly {
|
|
9
|
+
/** The matched term. */
|
|
10
|
+
readonly term: string;
|
|
11
|
+
/** Number of times the term appears in the section. */
|
|
12
|
+
readonly frequency: number;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A content section stored in the knowledge-base. */
|
|
2
|
+
export interface Section {
|
|
3
|
+
/** Knowledge-base identifier for this section. */
|
|
4
|
+
readonly kbid: string;
|
|
5
|
+
/** Parent document identifier, if the section belongs to one. */
|
|
6
|
+
readonly docid?: string;
|
|
7
|
+
/** Semantic type label assigned to the section. */
|
|
8
|
+
readonly sectionType: string;
|
|
9
|
+
/** Raw text content of the section. */
|
|
10
|
+
readonly content: string;
|
|
11
|
+
/** Byte size of the stored content. */
|
|
12
|
+
readonly size: number;
|
|
13
|
+
/** Unix epoch timestamp (ms) when the section was created. */
|
|
14
|
+
readonly createdAt: number;
|
|
15
|
+
/** SHA-256 checksum of the stored content. */
|
|
16
|
+
readonly checksum: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Parameters required to add or update a section. */
|
|
20
|
+
export interface AddSectionParams {
|
|
21
|
+
/** Semantic type label to assign to the section. */
|
|
22
|
+
readonly sectionType: string;
|
|
23
|
+
/** Raw text content for the section. */
|
|
24
|
+
readonly content: string;
|
|
25
|
+
/** Parent document identifier to associate the section with. */
|
|
26
|
+
readonly docid?: string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Diagnostic status returned by the worker daemon. */
|
|
2
|
+
export interface StatusResult {
|
|
3
|
+
/** Whether the daemon has finished loading its WASM modules. */
|
|
4
|
+
readonly initialized: boolean;
|
|
5
|
+
/** Absolute path to the context directory the daemon serves. */
|
|
6
|
+
readonly contextPath: string;
|
|
7
|
+
/** In-memory cache statistics. */
|
|
8
|
+
readonly cacheStats: {
|
|
9
|
+
/** Number of content entries currently cached. */
|
|
10
|
+
readonly contentCount: number;
|
|
11
|
+
/** Number of index entries currently cached. */
|
|
12
|
+
readonly indexCount: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility status categories returned by a database version check.
|
|
3
|
+
*
|
|
4
|
+
* - `'compatible'` -- database version matches the WASM engine version
|
|
5
|
+
* - `'needs_migration'` -- database is older and must be migrated with
|
|
6
|
+
* `kbdb --migrate`
|
|
7
|
+
* - `'too_new'` -- database was created by a newer version of kbdb;
|
|
8
|
+
* upgrade the kbdb binary
|
|
9
|
+
*/
|
|
10
|
+
export type VersionCompatibility =
|
|
11
|
+
| 'compatible'
|
|
12
|
+
| 'needs_migration'
|
|
13
|
+
| 'too_new';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Version compatibility status returned by a database version check.
|
|
17
|
+
*/
|
|
18
|
+
export interface VersionStatus {
|
|
19
|
+
/** The format version stored in the database's `catalog.toml`. */
|
|
20
|
+
readonly currentVersion: number;
|
|
21
|
+
/**
|
|
22
|
+
* The format version required by the current WASM engine.
|
|
23
|
+
* Equivalent to `DB_FORMAT_VERSION` from the Rust shared crate.
|
|
24
|
+
*/
|
|
25
|
+
readonly requiredVersion: number;
|
|
26
|
+
/** Compatibility result between the database and WASM engine. */
|
|
27
|
+
readonly status: VersionCompatibility;
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Options for configuring a WorkerClient connection. */
|
|
2
|
+
export interface WorkerClientOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Path to the directory containing the `.kbdb` database
|
|
5
|
+
* folder. Defaults to `process.cwd()` when omitted.
|
|
6
|
+
*/
|
|
7
|
+
readonly dbPath?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Absolute path to the context directory. When provided,
|
|
10
|
+
* skips the `.kbdb` discovery step performed by `dbPath`.
|
|
11
|
+
*/
|
|
12
|
+
readonly contextPath?: string;
|
|
13
|
+
/**
|
|
14
|
+
* When `true` (default), automatically spawns the worker
|
|
15
|
+
* daemon if it is not already running before connecting.
|
|
16
|
+
* Set to `false` to require a running daemon.
|
|
17
|
+
*/
|
|
18
|
+
readonly autoSpawn?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum milliseconds to wait for the daemon PID file to
|
|
21
|
+
* appear after spawning. Defaults to 10 000 ms.
|
|
22
|
+
*/
|
|
23
|
+
readonly connectTimeoutMs?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Absolute path to the worker daemon script. Resolved
|
|
26
|
+
* once at the entry point and injected here so that
|
|
27
|
+
* `spawnDaemon` needs no runtime-specific path logic.
|
|
28
|
+
*/
|
|
29
|
+
readonly workerScript?: string;
|
|
30
|
+
}
|