@zvec/zvec-grep 0.2.1 → 0.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -238
- package/bin/zg.exe +3 -0
- package/install.cjs +510 -0
- package/package.json +22 -72
- package/platforms.json +92 -0
- package/plugins.cjs +183 -0
- package/README_CN.md +0 -230
- package/dist/authorization/index.d.ts +0 -7
- package/dist/authorization/index.js +0 -7
- package/dist/authorization/index.js.map +0 -1
- package/dist/authorization/manager.d.ts +0 -8
- package/dist/authorization/manager.js +0 -19
- package/dist/authorization/manager.js.map +0 -1
- package/dist/authorization/operation.d.ts +0 -7
- package/dist/authorization/operation.js +0 -50
- package/dist/authorization/operation.js.map +0 -1
- package/dist/authorization/planner.d.ts +0 -21
- package/dist/authorization/planner.js +0 -97
- package/dist/authorization/planner.js.map +0 -1
- package/dist/authorization/prompt.d.ts +0 -12
- package/dist/authorization/prompt.js +0 -63
- package/dist/authorization/prompt.js.map +0 -1
- package/dist/authorization/store.d.ts +0 -20
- package/dist/authorization/store.js +0 -251
- package/dist/authorization/store.js.map +0 -1
- package/dist/authorization/target.d.ts +0 -15
- package/dist/authorization/target.js +0 -49
- package/dist/authorization/target.js.map +0 -1
- package/dist/authorization/types.d.ts +0 -61
- package/dist/authorization/types.js +0 -2
- package/dist/authorization/types.js.map +0 -1
- package/dist/cli/args.d.ts +0 -5
- package/dist/cli/args.js +0 -1207
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/auth.d.ts +0 -21
- package/dist/cli/auth.js +0 -209
- package/dist/cli/auth.js.map +0 -1
- package/dist/cli/commands.d.ts +0 -4
- package/dist/cli/commands.js +0 -697
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/errors.d.ts +0 -6
- package/dist/cli/errors.js +0 -98
- package/dist/cli/errors.js.map +0 -1
- package/dist/cli/format/context.d.ts +0 -9
- package/dist/cli/format/context.js +0 -786
- package/dist/cli/format/context.js.map +0 -1
- package/dist/cli/format/debug.d.ts +0 -4
- package/dist/cli/format/debug.js +0 -60
- package/dist/cli/format/debug.js.map +0 -1
- package/dist/cli/format/highlight.d.ts +0 -3
- package/dist/cli/format/highlight.js +0 -106
- package/dist/cli/format/highlight.js.map +0 -1
- package/dist/cli/format/progress.d.ts +0 -13
- package/dist/cli/format/progress.js +0 -290
- package/dist/cli/format/progress.js.map +0 -1
- package/dist/cli/format/range.d.ts +0 -3
- package/dist/cli/format/range.js +0 -24
- package/dist/cli/format/range.js.map +0 -1
- package/dist/cli/format/status.d.ts +0 -81
- package/dist/cli/format/status.js +0 -512
- package/dist/cli/format/status.js.map +0 -1
- package/dist/cli/help.d.ts +0 -1
- package/dist/cli/help.js +0 -524
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -32
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/install.d.ts +0 -4
- package/dist/cli/install.js +0 -1661
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/managed-rg.d.ts +0 -10
- package/dist/cli/managed-rg.js +0 -329
- package/dist/cli/managed-rg.js.map +0 -1
- package/dist/cli/server-search.d.ts +0 -3
- package/dist/cli/server-search.js +0 -12
- package/dist/cli/server-search.js.map +0 -1
- package/dist/cli/types.d.ts +0 -87
- package/dist/cli/types.js +0 -10
- package/dist/cli/types.js.map +0 -1
- package/dist/cli/version.d.ts +0 -1
- package/dist/cli/version.js +0 -13
- package/dist/cli/version.js.map +0 -1
- package/dist/client/daemon-client.d.ts +0 -31
- package/dist/client/daemon-client.js +0 -203
- package/dist/client/daemon-client.js.map +0 -1
- package/dist/client/mode-router.d.ts +0 -9
- package/dist/client/mode-router.js +0 -28
- package/dist/client/mode-router.js.map +0 -1
- package/dist/client/search-policy.d.ts +0 -11
- package/dist/client/search-policy.js +0 -15
- package/dist/client/search-policy.js.map +0 -1
- package/dist/daemon/backend.d.ts +0 -78
- package/dist/daemon/backend.js +0 -1085
- package/dist/daemon/backend.js.map +0 -1
- package/dist/daemon/change-set.d.ts +0 -30
- package/dist/daemon/change-set.js +0 -163
- package/dist/daemon/change-set.js.map +0 -1
- package/dist/daemon/config.d.ts +0 -24
- package/dist/daemon/config.js +0 -88
- package/dist/daemon/config.js.map +0 -1
- package/dist/daemon/errors.d.ts +0 -5
- package/dist/daemon/errors.js +0 -11
- package/dist/daemon/errors.js.map +0 -1
- package/dist/daemon/http-server.d.ts +0 -30
- package/dist/daemon/http-server.js +0 -288
- package/dist/daemon/http-server.js.map +0 -1
- package/dist/daemon/index-coordinator.d.ts +0 -22
- package/dist/daemon/index-coordinator.js +0 -55
- package/dist/daemon/index-coordinator.js.map +0 -1
- package/dist/daemon/job-scheduler.d.ts +0 -70
- package/dist/daemon/job-scheduler.js +0 -366
- package/dist/daemon/job-scheduler.js.map +0 -1
- package/dist/daemon/logger.d.ts +0 -9
- package/dist/daemon/logger.js +0 -53
- package/dist/daemon/logger.js.map +0 -1
- package/dist/daemon/model-pool.d.ts +0 -45
- package/dist/daemon/model-pool.js +0 -187
- package/dist/daemon/model-pool.js.map +0 -1
- package/dist/daemon/root-lease.d.ts +0 -14
- package/dist/daemon/root-lease.js +0 -188
- package/dist/daemon/root-lease.js.map +0 -1
- package/dist/daemon/root-runtime.d.ts +0 -79
- package/dist/daemon/root-runtime.js +0 -337
- package/dist/daemon/root-runtime.js.map +0 -1
- package/dist/daemon/runtime-manager.d.ts +0 -46
- package/dist/daemon/runtime-manager.js +0 -246
- package/dist/daemon/runtime-manager.js.map +0 -1
- package/dist/daemon/runtime.d.ts +0 -12
- package/dist/daemon/runtime.js +0 -102
- package/dist/daemon/runtime.js.map +0 -1
- package/dist/daemon/server-controller.d.ts +0 -39
- package/dist/daemon/server-controller.js +0 -327
- package/dist/daemon/server-controller.js.map +0 -1
- package/dist/daemon/watch-manager.d.ts +0 -55
- package/dist/daemon/watch-manager.js +0 -340
- package/dist/daemon/watch-manager.js.map +0 -1
- package/dist/daemon/workspace-read-session-cache.d.ts +0 -31
- package/dist/daemon/workspace-read-session-cache.js +0 -115
- package/dist/daemon/workspace-read-session-cache.js.map +0 -1
- package/dist/engine/code-formats.d.ts +0 -3
- package/dist/engine/code-formats.js +0 -14
- package/dist/engine/code-formats.js.map +0 -1
- package/dist/engine/config.d.ts +0 -50
- package/dist/engine/config.js +0 -321
- package/dist/engine/config.js.map +0 -1
- package/dist/engine/errors.d.ts +0 -19
- package/dist/engine/errors.js +0 -40
- package/dist/engine/errors.js.map +0 -1
- package/dist/engine/extraction/code/adapter.d.ts +0 -19
- package/dist/engine/extraction/code/adapter.js +0 -24
- package/dist/engine/extraction/code/adapter.js.map +0 -1
- package/dist/engine/extraction/code/extractor.d.ts +0 -13
- package/dist/engine/extraction/code/extractor.js +0 -696
- package/dist/engine/extraction/code/extractor.js.map +0 -1
- package/dist/engine/extraction/code/families/c-family.d.ts +0 -2
- package/dist/engine/extraction/code/families/c-family.js +0 -122
- package/dist/engine/extraction/code/families/c-family.js.map +0 -1
- package/dist/engine/extraction/code/families/js-ts.d.ts +0 -12
- package/dist/engine/extraction/code/families/js-ts.js +0 -118
- package/dist/engine/extraction/code/families/js-ts.js.map +0 -1
- package/dist/engine/extraction/code/families/metadata.d.ts +0 -8
- package/dist/engine/extraction/code/families/metadata.js +0 -86
- package/dist/engine/extraction/code/families/metadata.js.map +0 -1
- package/dist/engine/extraction/code/families/name-field.d.ts +0 -3
- package/dist/engine/extraction/code/families/name-field.js +0 -22
- package/dist/engine/extraction/code/families/name-field.js.map +0 -1
- package/dist/engine/extraction/code/languages/c.d.ts +0 -1
- package/dist/engine/extraction/code/languages/c.js +0 -12
- package/dist/engine/extraction/code/languages/c.js.map +0 -1
- package/dist/engine/extraction/code/languages/cpp.d.ts +0 -1
- package/dist/engine/extraction/code/languages/cpp.js +0 -18
- package/dist/engine/extraction/code/languages/cpp.js.map +0 -1
- package/dist/engine/extraction/code/languages/go.d.ts +0 -2
- package/dist/engine/extraction/code/languages/go.js +0 -70
- package/dist/engine/extraction/code/languages/go.js.map +0 -1
- package/dist/engine/extraction/code/languages/java.d.ts +0 -1
- package/dist/engine/extraction/code/languages/java.js +0 -17
- package/dist/engine/extraction/code/languages/java.js.map +0 -1
- package/dist/engine/extraction/code/languages/javascript.d.ts +0 -2
- package/dist/engine/extraction/code/languages/javascript.js +0 -23
- package/dist/engine/extraction/code/languages/javascript.js.map +0 -1
- package/dist/engine/extraction/code/languages/python.d.ts +0 -2
- package/dist/engine/extraction/code/languages/python.js +0 -52
- package/dist/engine/extraction/code/languages/python.js.map +0 -1
- package/dist/engine/extraction/code/languages/rust.d.ts +0 -2
- package/dist/engine/extraction/code/languages/rust.js +0 -25
- package/dist/engine/extraction/code/languages/rust.js.map +0 -1
- package/dist/engine/extraction/code/languages/typescript.d.ts +0 -2
- package/dist/engine/extraction/code/languages/typescript.js +0 -37
- package/dist/engine/extraction/code/languages/typescript.js.map +0 -1
- package/dist/engine/extraction/code/tree-sitter/grammar.d.ts +0 -4
- package/dist/engine/extraction/code/tree-sitter/grammar.js +0 -49
- package/dist/engine/extraction/code/tree-sitter/grammar.js.map +0 -1
- package/dist/engine/extraction/code/tree-sitter/nodes.d.ts +0 -3
- package/dist/engine/extraction/code/tree-sitter/nodes.js +0 -27
- package/dist/engine/extraction/code/tree-sitter/nodes.js.map +0 -1
- package/dist/engine/extraction/code/tree-sitter/parser.d.ts +0 -2
- package/dist/engine/extraction/code/tree-sitter/parser.js +0 -31
- package/dist/engine/extraction/code/tree-sitter/parser.js.map +0 -1
- package/dist/engine/extraction/ids.d.ts +0 -1
- package/dist/engine/extraction/ids.js +0 -5
- package/dist/engine/extraction/ids.js.map +0 -1
- package/dist/engine/extraction/image/extractor.d.ts +0 -5
- package/dist/engine/extraction/image/extractor.js +0 -35
- package/dist/engine/extraction/image/extractor.js.map +0 -1
- package/dist/engine/extraction/index.d.ts +0 -4
- package/dist/engine/extraction/index.js +0 -3
- package/dist/engine/extraction/index.js.map +0 -1
- package/dist/engine/extraction/markdown/extractor.d.ts +0 -7
- package/dist/engine/extraction/markdown/extractor.js +0 -362
- package/dist/engine/extraction/markdown/extractor.js.map +0 -1
- package/dist/engine/extraction/runtime.d.ts +0 -9
- package/dist/engine/extraction/runtime.js +0 -37
- package/dist/engine/extraction/runtime.js.map +0 -1
- package/dist/engine/extraction/source.d.ts +0 -18
- package/dist/engine/extraction/source.js +0 -22
- package/dist/engine/extraction/source.js.map +0 -1
- package/dist/engine/extraction/text/extractor.d.ts +0 -7
- package/dist/engine/extraction/text/extractor.js +0 -168
- package/dist/engine/extraction/text/extractor.js.map +0 -1
- package/dist/engine/extraction/types.d.ts +0 -4
- package/dist/engine/extraction/types.js +0 -2
- package/dist/engine/extraction/types.js.map +0 -1
- package/dist/engine/extraction/vector-content.d.ts +0 -5
- package/dist/engine/extraction/vector-content.js +0 -83
- package/dist/engine/extraction/vector-content.js.map +0 -1
- package/dist/engine/file-size-policy.d.ts +0 -6
- package/dist/engine/file-size-policy.js +0 -20
- package/dist/engine/file-size-policy.js.map +0 -1
- package/dist/engine/file-type.d.ts +0 -15
- package/dist/engine/file-type.js +0 -152
- package/dist/engine/file-type.js.map +0 -1
- package/dist/engine/index-status.d.ts +0 -9
- package/dist/engine/index-status.js +0 -38
- package/dist/engine/index-status.js.map +0 -1
- package/dist/engine/manifest.d.ts +0 -13
- package/dist/engine/manifest.js +0 -124
- package/dist/engine/manifest.js.map +0 -1
- package/dist/engine/models/backends/llama-cpp.d.ts +0 -99
- package/dist/engine/models/backends/llama-cpp.js +0 -511
- package/dist/engine/models/backends/llama-cpp.js.map +0 -1
- package/dist/engine/models/backends/model2vec-runtime.d.ts +0 -63
- package/dist/engine/models/backends/model2vec-runtime.js +0 -112
- package/dist/engine/models/backends/model2vec-runtime.js.map +0 -1
- package/dist/engine/models/backends/model2vec-tokenizer.d.ts +0 -2
- package/dist/engine/models/backends/model2vec-tokenizer.js +0 -42
- package/dist/engine/models/backends/model2vec-tokenizer.js.map +0 -1
- package/dist/engine/models/backends/model2vec-worker-pool.d.ts +0 -25
- package/dist/engine/models/backends/model2vec-worker-pool.js +0 -264
- package/dist/engine/models/backends/model2vec-worker-pool.js.map +0 -1
- package/dist/engine/models/backends/model2vec-worker.d.ts +0 -1
- package/dist/engine/models/backends/model2vec-worker.js +0 -41
- package/dist/engine/models/backends/model2vec-worker.js.map +0 -1
- package/dist/engine/models/backends/model2vec.d.ts +0 -40
- package/dist/engine/models/backends/model2vec.js +0 -311
- package/dist/engine/models/backends/model2vec.js.map +0 -1
- package/dist/engine/models/backends/qwen.d.ts +0 -44
- package/dist/engine/models/backends/qwen.js +0 -411
- package/dist/engine/models/backends/qwen.js.map +0 -1
- package/dist/engine/models/backends/transformers-js.d.ts +0 -87
- package/dist/engine/models/backends/transformers-js.js +0 -316
- package/dist/engine/models/backends/transformers-js.js.map +0 -1
- package/dist/engine/models/catalog.d.ts +0 -231
- package/dist/engine/models/catalog.js +0 -218
- package/dist/engine/models/catalog.js.map +0 -1
- package/dist/engine/models/download-progress.d.ts +0 -15
- package/dist/engine/models/download-progress.js +0 -48
- package/dist/engine/models/download-progress.js.map +0 -1
- package/dist/engine/models/embeddings.d.ts +0 -67
- package/dist/engine/models/embeddings.js +0 -125
- package/dist/engine/models/embeddings.js.map +0 -1
- package/dist/engine/models/factory.d.ts +0 -2
- package/dist/engine/models/factory.js +0 -51
- package/dist/engine/models/factory.js.map +0 -1
- package/dist/engine/models/index.d.ts +0 -4
- package/dist/engine/models/index.js +0 -5
- package/dist/engine/models/index.js.map +0 -1
- package/dist/engine/models/ranking.d.ts +0 -19
- package/dist/engine/models/ranking.js +0 -2
- package/dist/engine/models/ranking.js.map +0 -1
- package/dist/engine/models/resolution.d.ts +0 -8
- package/dist/engine/models/resolution.js +0 -22
- package/dist/engine/models/resolution.js.map +0 -1
- package/dist/engine/pipeline/indexing/index.d.ts +0 -14
- package/dist/engine/pipeline/indexing/index.js +0 -1061
- package/dist/engine/pipeline/indexing/index.js.map +0 -1
- package/dist/engine/pipeline/indexing/input-budget.d.ts +0 -2
- package/dist/engine/pipeline/indexing/input-budget.js +0 -51
- package/dist/engine/pipeline/indexing/input-budget.js.map +0 -1
- package/dist/engine/pipeline/indexing/root-paths.d.ts +0 -7
- package/dist/engine/pipeline/indexing/root-paths.js +0 -148
- package/dist/engine/pipeline/indexing/root-paths.js.map +0 -1
- package/dist/engine/pipeline/indexing/scanner/index.d.ts +0 -14
- package/dist/engine/pipeline/indexing/scanner/index.js +0 -776
- package/dist/engine/pipeline/indexing/scanner/index.js.map +0 -1
- package/dist/engine/pipeline/search/index.d.ts +0 -12
- package/dist/engine/pipeline/search/index.js +0 -811
- package/dist/engine/pipeline/search/index.js.map +0 -1
- package/dist/engine/service/index.d.ts +0 -3
- package/dist/engine/service/index.js +0 -2
- package/dist/engine/service/index.js.map +0 -1
- package/dist/engine/service/lexical.d.ts +0 -28
- package/dist/engine/service/lexical.js +0 -446
- package/dist/engine/service/lexical.js.map +0 -1
- package/dist/engine/service/root.d.ts +0 -15
- package/dist/engine/service/root.js +0 -57
- package/dist/engine/service/root.js.map +0 -1
- package/dist/engine/service/structure-enrichment.d.ts +0 -8
- package/dist/engine/service/structure-enrichment.js +0 -178
- package/dist/engine/service/structure-enrichment.js.map +0 -1
- package/dist/engine/service/types.d.ts +0 -210
- package/dist/engine/service/types.js +0 -2
- package/dist/engine/service/types.js.map +0 -1
- package/dist/engine/service/workspace-index.d.ts +0 -26
- package/dist/engine/service/workspace-index.js +0 -157
- package/dist/engine/service/workspace-index.js.map +0 -1
- package/dist/engine/service/zvec-grep.d.ts +0 -13
- package/dist/engine/service/zvec-grep.js +0 -1393
- package/dist/engine/service/zvec-grep.js.map +0 -1
- package/dist/engine/storage/index.d.ts +0 -53
- package/dist/engine/storage/index.js +0 -3
- package/dist/engine/storage/index.js.map +0 -1
- package/dist/engine/storage/layout.d.ts +0 -10
- package/dist/engine/storage/layout.js +0 -29
- package/dist/engine/storage/layout.js.map +0 -1
- package/dist/engine/storage/zvec.d.ts +0 -4
- package/dist/engine/storage/zvec.js +0 -976
- package/dist/engine/storage/zvec.js.map +0 -1
- package/dist/engine/types.d.ts +0 -303
- package/dist/engine/types.js +0 -14
- package/dist/engine/types.js.map +0 -1
- package/dist/engine/utils/daemon-lease.d.ts +0 -17
- package/dist/engine/utils/daemon-lease.js +0 -175
- package/dist/engine/utils/daemon-lease.js.map +0 -1
- package/dist/engine/utils/file-selection.d.ts +0 -10
- package/dist/engine/utils/file-selection.js +0 -157
- package/dist/engine/utils/file-selection.js.map +0 -1
- package/dist/engine/utils/glob.d.ts +0 -9
- package/dist/engine/utils/glob.js +0 -208
- package/dist/engine/utils/glob.js.map +0 -1
- package/dist/engine/utils/hash.d.ts +0 -2
- package/dist/engine/utils/hash.js +0 -8
- package/dist/engine/utils/hash.js.map +0 -1
- package/dist/engine/utils/json.d.ts +0 -8
- package/dist/engine/utils/json.js +0 -83
- package/dist/engine/utils/json.js.map +0 -1
- package/dist/engine/utils/lock.d.ts +0 -19
- package/dist/engine/utils/lock.js +0 -254
- package/dist/engine/utils/lock.js.map +0 -1
- package/dist/engine/utils/path.d.ts +0 -4
- package/dist/engine/utils/path.js +0 -18
- package/dist/engine/utils/path.js.map +0 -1
- package/dist/engine/utils/timing.d.ts +0 -19
- package/dist/engine/utils/timing.js +0 -87
- package/dist/engine/utils/timing.js.map +0 -1
- package/dist/index-progress.d.ts +0 -10
- package/dist/index-progress.js +0 -159
- package/dist/index-progress.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/mcp/http-transport.d.ts +0 -27
- package/dist/mcp/http-transport.js +0 -182
- package/dist/mcp/http-transport.js.map +0 -1
- package/dist/mcp/input-normalization.d.ts +0 -38
- package/dist/mcp/input-normalization.js +0 -104
- package/dist/mcp/input-normalization.js.map +0 -1
- package/dist/mcp/progress-heartbeat.d.ts +0 -17
- package/dist/mcp/progress-heartbeat.js +0 -46
- package/dist/mcp/progress-heartbeat.js.map +0 -1
- package/dist/mcp/request-metadata.d.ts +0 -2
- package/dist/mcp/request-metadata.js +0 -11
- package/dist/mcp/request-metadata.js.map +0 -1
- package/dist/mcp/request-state.d.ts +0 -40
- package/dist/mcp/request-state.js +0 -210
- package/dist/mcp/request-state.js.map +0 -1
- package/dist/mcp/result-format.d.ts +0 -13
- package/dist/mcp/result-format.js +0 -75
- package/dist/mcp/result-format.js.map +0 -1
- package/dist/mcp/schemas.d.ts +0 -664
- package/dist/mcp/schemas.js +0 -510
- package/dist/mcp/schemas.js.map +0 -1
- package/dist/mcp/stdio-bridge.d.ts +0 -14
- package/dist/mcp/stdio-bridge.js +0 -178
- package/dist/mcp/stdio-bridge.js.map +0 -1
- package/dist/mcp/tools.d.ts +0 -153
- package/dist/mcp/tools.js +0 -482
- package/dist/mcp/tools.js.map +0 -1
- package/dist/mcp/toolset.d.ts +0 -5
- package/dist/mcp/toolset.js +0 -12
- package/dist/mcp/toolset.js.map +0 -1
- package/dist/observability/trace-context.d.ts +0 -11
- package/dist/observability/trace-context.js +0 -138
- package/dist/observability/trace-context.js.map +0 -1
- package/dist/prompts/zvec-grep-guidance.d.ts +0 -2
- package/dist/prompts/zvec-grep-guidance.js +0 -9
- package/dist/prompts/zvec-grep-guidance.js.map +0 -1
- package/docs/01-agents.md +0 -209
- package/docs/02-cli.md +0 -246
- package/docs/03-mcp.md +0 -185
- package/docs/04-pipeline.md +0 -226
- package/docs/05-architecture.md +0 -86
- package/docs/06-server.md +0 -220
- package/docs/07-embedding.md +0 -203
- package/docs/08-roadmap.md +0 -85
- package/docs/README.md +0 -53
package/dist/daemon/backend.js
DELETED
|
@@ -1,1085 +0,0 @@
|
|
|
1
|
-
import { createZvecGrep } from "../engine/service/index.js";
|
|
2
|
-
import { isEngineError } from "../engine/errors.js";
|
|
3
|
-
import { readGlobalConfig, resolveEmbeddingRuntimeOptions, } from "../engine/config.js";
|
|
4
|
-
import { readWorkspaceManifest } from "../engine/manifest.js";
|
|
5
|
-
import { workspaceIndexLocation } from "../engine/service/root.js";
|
|
6
|
-
import { resolveEmbeddingReference } from "../engine/models/index.js";
|
|
7
|
-
import { indexCompletionForJob, indexCompletionFromStatus, } from "../engine/index-status.js";
|
|
8
|
-
import { contextOptionsFromRgInput, normalizePlainStringList, } from "../mcp/input-normalization.js";
|
|
9
|
-
import { DaemonError } from "./errors.js";
|
|
10
|
-
import { JobScheduler, } from "./job-scheduler.js";
|
|
11
|
-
import { EmbeddingModelPool, } from "./model-pool.js";
|
|
12
|
-
import { IndexCoordinator, } from "./index-coordinator.js";
|
|
13
|
-
import { inspectRoot, resolveRequestedRoot, RuntimeManager, } from "./runtime-manager.js";
|
|
14
|
-
import { WatchManager } from "./watch-manager.js";
|
|
15
|
-
import { rootIdentity } from "./logger.js";
|
|
16
|
-
import { RemoteEmbeddingAuthorizationManager, RemoteEmbeddingAuthorizationStore, planRemoteIndexAuthorization, planRemoteSearchAuthorization, withRemoteEmbeddingOperationPermit, } from "../authorization/index.js";
|
|
17
|
-
const DEFAULT_LOCAL_EMBEDDING = "local/potion-code-16m-v2";
|
|
18
|
-
export class DaemonBackend {
|
|
19
|
-
options;
|
|
20
|
-
modelPool;
|
|
21
|
-
runtimeManager;
|
|
22
|
-
scheduler;
|
|
23
|
-
startedAt = Date.now();
|
|
24
|
-
statusCache = new Map();
|
|
25
|
-
lastScanDiagnostics = new Map();
|
|
26
|
-
workspaceRuntimeCache = new Map();
|
|
27
|
-
watchers = new Map();
|
|
28
|
-
indexCoordinators = new Map();
|
|
29
|
-
droppingRoots = new Set();
|
|
30
|
-
authorizationManager;
|
|
31
|
-
shuttingDown = false;
|
|
32
|
-
closePromise;
|
|
33
|
-
constructor(options) {
|
|
34
|
-
this.options = options;
|
|
35
|
-
this.authorizationManager = new RemoteEmbeddingAuthorizationManager(options.authorizationStore ??
|
|
36
|
-
new RemoteEmbeddingAuthorizationStore({
|
|
37
|
-
signingKeyPath: options.serviceOptions?.authorizationSigningKeyPath,
|
|
38
|
-
}));
|
|
39
|
-
this.modelPool = new EmbeddingModelPool({
|
|
40
|
-
...options.modelPoolOptions,
|
|
41
|
-
serviceOptions: options.serviceOptions,
|
|
42
|
-
logger: options.logger,
|
|
43
|
-
});
|
|
44
|
-
this.runtimeManager = new RuntimeManager({
|
|
45
|
-
modelPool: this.modelPool,
|
|
46
|
-
serviceOptions: options.serviceOptions,
|
|
47
|
-
readSessionIdleTtlMs: options.readSessionIdleTtlMs,
|
|
48
|
-
runtimeIdleTtlMs: options.runtimeIdleTtlMs,
|
|
49
|
-
onRuntimeEvicted: async (root) => {
|
|
50
|
-
this.statusCache.delete(root);
|
|
51
|
-
this.lastScanDiagnostics.delete(root);
|
|
52
|
-
this.workspaceRuntimeCache.delete(root);
|
|
53
|
-
await this.closeWatcher(root);
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
this.scheduler = new JobScheduler({
|
|
57
|
-
...options.schedulerOptions,
|
|
58
|
-
logger: options.logger,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async planIndexAuthorization(input) {
|
|
62
|
-
if (input.drop === true) {
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
const requestedRoot = await resolveRequestedRoot(input.root, false);
|
|
66
|
-
if (input.rebuild !== true && this.scheduler.hasActiveRoot(requestedRoot)) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
const info = await inspectRoot(input.root, this.options.serviceOptions, input.rebuild !== true);
|
|
70
|
-
let modelLoadRequest;
|
|
71
|
-
try {
|
|
72
|
-
modelLoadRequest = this.indexModelLoadRequest(info, input);
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
if (error instanceof DaemonError && error.code === "MODEL_LOAD_FAILED") {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
let lease;
|
|
81
|
-
try {
|
|
82
|
-
lease = await this.modelPool.acquire(modelLoadRequest);
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
if (isEngineError(error)) {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
90
|
-
let schema;
|
|
91
|
-
let modelInfo;
|
|
92
|
-
try {
|
|
93
|
-
schema = embeddingSchema(lease.model);
|
|
94
|
-
modelInfo = lease.model.info;
|
|
95
|
-
}
|
|
96
|
-
finally {
|
|
97
|
-
lease.release();
|
|
98
|
-
}
|
|
99
|
-
const existing = info.workspaceIndex?.embedding;
|
|
100
|
-
if (existing &&
|
|
101
|
-
input.embedding &&
|
|
102
|
-
input.rebuild !== true &&
|
|
103
|
-
(existing.provider !== schema.provider || existing.model !== schema.model)) {
|
|
104
|
-
throw new DaemonError("EMBEDDING_MODEL_MISMATCH", `Existing model ${existing.provider}/${existing.model} does not match requested model ${schema.provider}/${schema.model}; use rebuild to change models.`);
|
|
105
|
-
}
|
|
106
|
-
return await planRemoteIndexAuthorization({
|
|
107
|
-
info,
|
|
108
|
-
model: modelInfo,
|
|
109
|
-
rebuild: input.rebuild,
|
|
110
|
-
store: this.authorizationManager.store,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
async planSearchAuthorization(input) {
|
|
114
|
-
const requestedRoot = await resolveRequestedRoot(input.root, false);
|
|
115
|
-
let activeRuntime = this.runtimeManager.getByRequestedRoot(requestedRoot);
|
|
116
|
-
if (activeRuntime?.embeddingProvider() &&
|
|
117
|
-
activeRuntime.embeddingProvider() !== "qwen") {
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
let canonicalRoot = activeRuntime?.canonicalRoot;
|
|
121
|
-
let discoveredInfo;
|
|
122
|
-
if (!canonicalRoot) {
|
|
123
|
-
discoveredInfo = await this.inspectRoot(input.root, false);
|
|
124
|
-
canonicalRoot = await resolveRequestedRoot(discoveredInfo.root, false);
|
|
125
|
-
activeRuntime = this.runtimeManager.getByCanonicalRoot(canonicalRoot);
|
|
126
|
-
const provider = activeRuntime?.embeddingProvider() ??
|
|
127
|
-
discoveredInfo.workspaceIndex?.embedding?.provider;
|
|
128
|
-
if (provider && provider !== "qwen") {
|
|
129
|
-
return undefined;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const cachedInfo = activeRuntime
|
|
133
|
-
? this.statusCache.get(canonicalRoot)
|
|
134
|
-
: undefined;
|
|
135
|
-
let info;
|
|
136
|
-
if (cachedInfo) {
|
|
137
|
-
info = cachedInfo;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
try {
|
|
141
|
-
info = await this.inspectRoot(canonicalRoot, true);
|
|
142
|
-
this.statusCache.set(canonicalRoot, info);
|
|
143
|
-
}
|
|
144
|
-
catch (error) {
|
|
145
|
-
const cached = this.statusCache.get(canonicalRoot);
|
|
146
|
-
if (!cached ||
|
|
147
|
-
!isEngineError(error) ||
|
|
148
|
-
error.code !== "ZVEC_GREP.ENGINE.LOCK.BUSY") {
|
|
149
|
-
throw error;
|
|
150
|
-
}
|
|
151
|
-
info = cached;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const schema = info.workspaceIndex?.embedding;
|
|
155
|
-
if (!info.indexed || !schema || schema.provider !== "qwen") {
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
const modelLoadRequest = this.searchModelLoadRequest(info, input);
|
|
159
|
-
const modelInfo = await this.loadEmbeddingModelInfo(modelLoadRequest);
|
|
160
|
-
return await planRemoteSearchAuthorization({
|
|
161
|
-
info,
|
|
162
|
-
model: modelInfo,
|
|
163
|
-
search: input,
|
|
164
|
-
runtimeNeedsReconciliation: this.runtimeManager
|
|
165
|
-
.getByCanonicalRoot(canonicalRoot)
|
|
166
|
-
?.needsReconciliation() ?? false,
|
|
167
|
-
store: this.authorizationManager.store,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async existingRemoteEmbeddingPermit(plan) {
|
|
171
|
-
return await this.authorizationManager.existingWorkspacePermit(plan);
|
|
172
|
-
}
|
|
173
|
-
async grantRemoteEmbedding(plan, scope) {
|
|
174
|
-
return await this.authorizationManager.grant(plan, scope);
|
|
175
|
-
}
|
|
176
|
-
async index(input, options = {}) {
|
|
177
|
-
if (input.drop === true) {
|
|
178
|
-
assertDropOnlyInput(input);
|
|
179
|
-
const result = await this.dropIndex(input);
|
|
180
|
-
return {
|
|
181
|
-
root: result.root,
|
|
182
|
-
jobId: "drop",
|
|
183
|
-
state: "succeeded",
|
|
184
|
-
reused: false,
|
|
185
|
-
action: "drop",
|
|
186
|
-
dropped: result.removed,
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
const requestedRoot = await resolveRequestedRoot(input.root, true);
|
|
190
|
-
this.assertRootNotDropping(requestedRoot);
|
|
191
|
-
const runtime = await this.runtimeManager.activateForIndex(requestedRoot);
|
|
192
|
-
this.ensureWatcher(runtime);
|
|
193
|
-
const activeJob = this.scheduler.getByRoot(runtime.canonicalRoot);
|
|
194
|
-
const followsNarrowJob = activeJob?.state === "queued" || activeJob?.state === "running"
|
|
195
|
-
? activeJob.reason === "watch"
|
|
196
|
-
: false;
|
|
197
|
-
const createsWork = !this.scheduler.hasActiveRoot(runtime.canonicalRoot) ||
|
|
198
|
-
input.rebuild === true ||
|
|
199
|
-
followsNarrowJob;
|
|
200
|
-
if (createsWork) {
|
|
201
|
-
this.lastScanDiagnostics.delete(runtime.canonicalRoot);
|
|
202
|
-
}
|
|
203
|
-
const targetRevision = createsWork
|
|
204
|
-
? runtime.markDirty()
|
|
205
|
-
: runtime.snapshot().dirtyRevision;
|
|
206
|
-
const submitted = this.scheduler.submit({
|
|
207
|
-
canonicalRoot: runtime.canonicalRoot,
|
|
208
|
-
reason: "manual",
|
|
209
|
-
followupIfRunning: input.rebuild === true || followsNarrowJob,
|
|
210
|
-
run: async (report, signal) => {
|
|
211
|
-
const proof = await this.runIndex(runtime, input, report, options.authorization, signal);
|
|
212
|
-
this.lastScanDiagnostics.set(runtime.canonicalRoot, proof.scanDiagnostics);
|
|
213
|
-
if (proof.reconciled) {
|
|
214
|
-
runtime.markReconciled(targetRevision, proof.reconciliationEpoch);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
runtime.markIndexed(targetRevision);
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
const job = input.wait
|
|
222
|
-
? await this.scheduler.wait(submitted.job.id, options.onProgress)
|
|
223
|
-
: submitted.job;
|
|
224
|
-
if (input.wait) {
|
|
225
|
-
await this.settleKnownChanges(runtime);
|
|
226
|
-
}
|
|
227
|
-
this.options.logger?.event("job.submitted", {
|
|
228
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
229
|
-
job_id: job.id,
|
|
230
|
-
reason: "manual",
|
|
231
|
-
state: job.state,
|
|
232
|
-
reused: submitted.reused,
|
|
233
|
-
});
|
|
234
|
-
return {
|
|
235
|
-
root: runtime.canonicalRoot,
|
|
236
|
-
jobId: job.id,
|
|
237
|
-
state: job.state,
|
|
238
|
-
reused: submitted.reused,
|
|
239
|
-
action: "index",
|
|
240
|
-
error: job.error,
|
|
241
|
-
...(input.debug === true && input.wait === true
|
|
242
|
-
? {
|
|
243
|
-
scanDiagnostics: this.lastScanDiagnostics.get(runtime.canonicalRoot),
|
|
244
|
-
}
|
|
245
|
-
: {}),
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
async dropIndex(input) {
|
|
249
|
-
const canonicalRoot = await resolveRequestedRoot(input.root, true);
|
|
250
|
-
if (this.droppingRoots.has(canonicalRoot)) {
|
|
251
|
-
throw new DaemonError("INDEX_DROP_IN_PROGRESS", "The Workspace index is already being dropped.");
|
|
252
|
-
}
|
|
253
|
-
this.droppingRoots.add(canonicalRoot);
|
|
254
|
-
try {
|
|
255
|
-
await this.closeWatcher(canonicalRoot);
|
|
256
|
-
this.scheduler.cancelRoot(canonicalRoot);
|
|
257
|
-
await this.scheduler.waitForRootIdle(canonicalRoot);
|
|
258
|
-
const runtime = this.runtimeManager.getByCanonicalRoot(canonicalRoot);
|
|
259
|
-
const drop = async () => {
|
|
260
|
-
const service = await (this.options.createService ?? createZvecGrep)({
|
|
261
|
-
...this.options.serviceOptions,
|
|
262
|
-
root: canonicalRoot,
|
|
263
|
-
daemonInstanceToken: this.runtimeManager.instanceToken,
|
|
264
|
-
});
|
|
265
|
-
try {
|
|
266
|
-
return await service.dropIndex({ root: canonicalRoot });
|
|
267
|
-
}
|
|
268
|
-
finally {
|
|
269
|
-
await service.close();
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
const removed = runtime ? await runtime.withWrite(drop) : await drop();
|
|
273
|
-
this.options.logger?.event("index.dropped", {
|
|
274
|
-
root_id: rootIdentity(canonicalRoot),
|
|
275
|
-
dropped: removed,
|
|
276
|
-
});
|
|
277
|
-
return { root: canonicalRoot, removed };
|
|
278
|
-
}
|
|
279
|
-
finally {
|
|
280
|
-
this.statusCache.delete(canonicalRoot);
|
|
281
|
-
this.lastScanDiagnostics.delete(canonicalRoot);
|
|
282
|
-
this.workspaceRuntimeCache.delete(canonicalRoot);
|
|
283
|
-
try {
|
|
284
|
-
await this.runtimeManager.evict(canonicalRoot);
|
|
285
|
-
}
|
|
286
|
-
finally {
|
|
287
|
-
this.droppingRoots.delete(canonicalRoot);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async search(input, options = {}) {
|
|
292
|
-
const startedAt = Date.now();
|
|
293
|
-
const requestedRoot = await resolveRequestedRoot(input.root, false);
|
|
294
|
-
this.assertRootNotDropping(requestedRoot);
|
|
295
|
-
const runtime = await this.runtimeManager.activate(requestedRoot);
|
|
296
|
-
const releaseRuntimeActivity = runtime.beginActivity();
|
|
297
|
-
try {
|
|
298
|
-
const searchInfo = await this.inspectRootWithCache(runtime.canonicalRoot);
|
|
299
|
-
const currentModelLoadRequest = runtime.currentModelLoadRequest();
|
|
300
|
-
const defaultModelLoadRequest = searchInfo.indexed
|
|
301
|
-
? this.searchModelLoadRequest(searchInfo, {})
|
|
302
|
-
: currentModelLoadRequest;
|
|
303
|
-
if (!defaultModelLoadRequest) {
|
|
304
|
-
throw new DaemonError("INDEX_MISSING", "Search requires an existing workspace index.");
|
|
305
|
-
}
|
|
306
|
-
const searchModelLoadRequest = searchInfo.indexed
|
|
307
|
-
? this.searchModelLoadRequest(searchInfo, input)
|
|
308
|
-
: this.overrideActiveModelLoadRequest(defaultModelLoadRequest, input);
|
|
309
|
-
runtime.updateModelLoadRequest(defaultModelLoadRequest);
|
|
310
|
-
this.ensureWatcher(runtime);
|
|
311
|
-
await runtime.probeInitialFreshness(async () => {
|
|
312
|
-
const info = await this.inspectRoot(runtime.canonicalRoot, true);
|
|
313
|
-
this.statusCache.set(runtime.canonicalRoot, info);
|
|
314
|
-
return indexStatusIsFresh(info);
|
|
315
|
-
}, (initialFreshness) => {
|
|
316
|
-
this.options.logger?.event(`runtime.initial_probe_${initialFreshness}`, {
|
|
317
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
let updateJob;
|
|
321
|
-
const executeSearch = () => withRemoteEmbeddingOperationPermit(options.authorization, () => runtime.search({
|
|
322
|
-
queries: input.queries,
|
|
323
|
-
routes: input.routes,
|
|
324
|
-
fuse: input.fuse,
|
|
325
|
-
limit: input.limit,
|
|
326
|
-
trace: input.trace,
|
|
327
|
-
preferSymbol: input.preferSymbol,
|
|
328
|
-
symbolTypes: input.symbolTypes,
|
|
329
|
-
globs: normalizePlainStringList(input.globs),
|
|
330
|
-
insensitiveGlobs: normalizePlainStringList(input.insensitiveGlobs),
|
|
331
|
-
fileTypes: normalizePlainStringList(input.fileTypes),
|
|
332
|
-
excludedFileTypes: normalizePlainStringList(input.excludedFileTypes),
|
|
333
|
-
hidden: input.hidden,
|
|
334
|
-
noIgnore: input.noIgnore,
|
|
335
|
-
ignoreFiles: input.ignoreFiles,
|
|
336
|
-
maxDepth: input.maxDepth,
|
|
337
|
-
maxFileSizeBytes: input.maxFileSizeBytes,
|
|
338
|
-
follow: input.follow,
|
|
339
|
-
embeddingConcurrency: input.embeddingConcurrency,
|
|
340
|
-
modifiedAfter: input.modifiedAfter,
|
|
341
|
-
modifiedBefore: input.modifiedBefore,
|
|
342
|
-
autoUpdate: false,
|
|
343
|
-
}, searchModelLoadRequest));
|
|
344
|
-
let result;
|
|
345
|
-
if (input.freshness === "wait_for_fresh") {
|
|
346
|
-
while (true) {
|
|
347
|
-
updateJob =
|
|
348
|
-
(await this.waitForFresh(runtime, options.authorization, input)) ??
|
|
349
|
-
updateJob;
|
|
350
|
-
const beforeSearch = runtime.snapshot();
|
|
351
|
-
result = await executeSearch();
|
|
352
|
-
const afterSearch = runtime.snapshot();
|
|
353
|
-
if (!afterSearch.watcherPending &&
|
|
354
|
-
afterSearch.watcherEpoch === beforeSearch.watcherEpoch &&
|
|
355
|
-
!runtime.needsReconciliation()) {
|
|
356
|
-
break;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
else {
|
|
361
|
-
result = await executeSearch();
|
|
362
|
-
}
|
|
363
|
-
if (runtime.needsReconciliation() &&
|
|
364
|
-
input.autoUpdate &&
|
|
365
|
-
(runtime.requiresFullReconciliation() ||
|
|
366
|
-
!this.scheduler.hasActiveRoot(runtime.canonicalRoot))) {
|
|
367
|
-
const currentJob = this.scheduler.getByRoot(runtime.canonicalRoot);
|
|
368
|
-
const terminalKnownPathJob = !runtime.requiresFullReconciliation() &&
|
|
369
|
-
(currentJob?.state === "failed" || currentJob?.state === "cancelled");
|
|
370
|
-
if (runtime.needsReconciliation() && !terminalKnownPathJob) {
|
|
371
|
-
updateJob = await this.submitIndex(runtime, {
|
|
372
|
-
root: runtime.canonicalRoot,
|
|
373
|
-
apiKey: input.apiKey,
|
|
374
|
-
device: input.device,
|
|
375
|
-
runtimeOverridesAreEphemeral: true,
|
|
376
|
-
}, "background_reconcile", false, options.authorization);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
const job = updateJob ?? this.scheduler.getByRoot(runtime.canonicalRoot);
|
|
380
|
-
const runtimeSnapshot = runtime.snapshot();
|
|
381
|
-
const activeKnownChangeJob = job?.reason !== "background_reconcile" &&
|
|
382
|
-
(job?.state === "queued" || job?.state === "running");
|
|
383
|
-
const freshness = runtime.hasKnownChanges() ||
|
|
384
|
-
runtimeSnapshot.watcherPending ||
|
|
385
|
-
activeKnownChangeJob
|
|
386
|
-
? "possibly_stale"
|
|
387
|
-
: "fresh";
|
|
388
|
-
const response = {
|
|
389
|
-
root: runtime.canonicalRoot,
|
|
390
|
-
freshness,
|
|
391
|
-
indexing: freshness === "possibly_stale"
|
|
392
|
-
? searchIndexingSnapshot(job, this.currentIndexCompletion(runtime.canonicalRoot, job, runtime))
|
|
393
|
-
: undefined,
|
|
394
|
-
result,
|
|
395
|
-
};
|
|
396
|
-
this.options.logger?.event("search.completed", {
|
|
397
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
398
|
-
duration_ms: Date.now() - startedAt,
|
|
399
|
-
freshness: response.freshness,
|
|
400
|
-
result_count: result.items.length,
|
|
401
|
-
});
|
|
402
|
-
return response;
|
|
403
|
-
}
|
|
404
|
-
finally {
|
|
405
|
-
releaseRuntimeActivity();
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
currentIndexCompletion(canonicalRoot, job, runtime) {
|
|
409
|
-
// Narrow watcher updates skip the status scan, so the cached completion
|
|
410
|
-
// still describes the previous fresh snapshot rather than the active job.
|
|
411
|
-
if (job?.reason === "watch" &&
|
|
412
|
-
runtime.needsReconciliation() &&
|
|
413
|
-
!runtime.requiresFullReconciliation()) {
|
|
414
|
-
return undefined;
|
|
415
|
-
}
|
|
416
|
-
return indexCompletionFromStatus(this.statusCache.get(canonicalRoot)?.status);
|
|
417
|
-
}
|
|
418
|
-
async indexStatus(input) {
|
|
419
|
-
const requestedCanonicalRoot = await resolveRequestedRoot(input.root, false);
|
|
420
|
-
let info;
|
|
421
|
-
try {
|
|
422
|
-
info = await inspectRoot(input.root, this.options.serviceOptions);
|
|
423
|
-
this.statusCache.set(requestedCanonicalRoot, info);
|
|
424
|
-
}
|
|
425
|
-
catch (error) {
|
|
426
|
-
const cached = this.statusCache.get(requestedCanonicalRoot);
|
|
427
|
-
if (!cached ||
|
|
428
|
-
!isEngineError(error) ||
|
|
429
|
-
error.code !== "ZVEC_GREP.ENGINE.LOCK.BUSY") {
|
|
430
|
-
throw error;
|
|
431
|
-
}
|
|
432
|
-
info = cached;
|
|
433
|
-
}
|
|
434
|
-
const canonicalRoot = await resolveRequestedRoot(info.root, false);
|
|
435
|
-
const runtime = this.runtimeManager.getByCanonicalRoot(canonicalRoot);
|
|
436
|
-
const runtimeSnapshot = runtime?.snapshot();
|
|
437
|
-
const job = this.scheduler.getByRoot(canonicalRoot);
|
|
438
|
-
return {
|
|
439
|
-
root: canonicalRoot,
|
|
440
|
-
indexed: info.indexed,
|
|
441
|
-
indexPolicy: info.indexPolicy,
|
|
442
|
-
source: info.source,
|
|
443
|
-
persistent: persistentStatus(info),
|
|
444
|
-
runtime: runtimeSnapshot
|
|
445
|
-
? {
|
|
446
|
-
watcherActive: runtimeSnapshot.watcherActive,
|
|
447
|
-
dirtyRevision: runtimeSnapshot.dirtyRevision,
|
|
448
|
-
indexedRevision: runtimeSnapshot.indexedRevision,
|
|
449
|
-
activeJobId: job?.id,
|
|
450
|
-
jobState: job?.state,
|
|
451
|
-
progress: job?.progress ? formatProgress(job) : undefined,
|
|
452
|
-
completion: indexCompletionForJob(indexCompletionFromStatus(info.status), job?.state, job?.progress),
|
|
453
|
-
error: job?.error,
|
|
454
|
-
}
|
|
455
|
-
: undefined,
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
async serverStatus() {
|
|
459
|
-
const runtime = this.runtimeManager.snapshot();
|
|
460
|
-
const models = this.modelPool.snapshot();
|
|
461
|
-
const jobs = this.scheduler.snapshot();
|
|
462
|
-
return {
|
|
463
|
-
version: this.options.version,
|
|
464
|
-
uptimeMs: Date.now() - this.startedAt,
|
|
465
|
-
shuttingDown: this.shuttingDown,
|
|
466
|
-
activeRuntimes: runtime.activeRuntimes,
|
|
467
|
-
queuedJobs: jobs.queued,
|
|
468
|
-
runningJobs: jobs.running,
|
|
469
|
-
models,
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
async rg(input) {
|
|
473
|
-
const startedAt = Date.now();
|
|
474
|
-
const canonicalRoot = await resolveRequestedRoot(input.root, false);
|
|
475
|
-
const service = await (this.options.createService ?? createZvecGrep)({
|
|
476
|
-
...this.options.serviceOptions,
|
|
477
|
-
root: canonicalRoot,
|
|
478
|
-
daemonInstanceToken: this.runtimeManager.instanceToken,
|
|
479
|
-
});
|
|
480
|
-
try {
|
|
481
|
-
const result = await service.context({
|
|
482
|
-
...contextOptionsFromRgInput({ ...input, root: canonicalRoot }),
|
|
483
|
-
root: canonicalRoot,
|
|
484
|
-
autoUpdate: false,
|
|
485
|
-
});
|
|
486
|
-
this.options.logger?.event("rg.completed", {
|
|
487
|
-
root_id: rootIdentity(canonicalRoot),
|
|
488
|
-
duration_ms: Date.now() - startedAt,
|
|
489
|
-
result_count: result.items.length,
|
|
490
|
-
});
|
|
491
|
-
return {
|
|
492
|
-
root: canonicalRoot,
|
|
493
|
-
result,
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
finally {
|
|
497
|
-
await service.close();
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
async close() {
|
|
501
|
-
if (this.closePromise) {
|
|
502
|
-
return this.closePromise;
|
|
503
|
-
}
|
|
504
|
-
this.shuttingDown = true;
|
|
505
|
-
this.closePromise = (async () => {
|
|
506
|
-
await Promise.all([...this.watchers.values()].map((watcher) => watcher.close()));
|
|
507
|
-
for (const root of this.watchers.keys()) {
|
|
508
|
-
this.runtimeManager.getByCanonicalRoot(root)?.setWatcherActive(false);
|
|
509
|
-
}
|
|
510
|
-
this.watchers.clear();
|
|
511
|
-
this.indexCoordinators.clear();
|
|
512
|
-
await this.scheduler.close();
|
|
513
|
-
await this.runtimeManager.close();
|
|
514
|
-
await this.modelPool.close();
|
|
515
|
-
this.lastScanDiagnostics.clear();
|
|
516
|
-
this.workspaceRuntimeCache.clear();
|
|
517
|
-
})();
|
|
518
|
-
return this.closePromise;
|
|
519
|
-
}
|
|
520
|
-
async runIndex(runtime, input, report, authorization, signal) {
|
|
521
|
-
const releaseRuntimeActivity = runtime.beginActivity();
|
|
522
|
-
try {
|
|
523
|
-
return await this.runIndexOperation(runtime, input, report, authorization, signal);
|
|
524
|
-
}
|
|
525
|
-
finally {
|
|
526
|
-
releaseRuntimeActivity();
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
async runIndexOperation(runtime, input, report, authorization, signal) {
|
|
530
|
-
const startedAt = Date.now();
|
|
531
|
-
// Watcher path updates already identify their indexing scope. Uncertain
|
|
532
|
-
// watcher reconciliations are verified by the final status scan, so neither
|
|
533
|
-
// path needs another workspace-wide status scan before indexing starts.
|
|
534
|
-
const includeInitialStatus = input.skipInitialStatus !== true &&
|
|
535
|
-
input.rebuild !== true &&
|
|
536
|
-
input.changedPaths === undefined;
|
|
537
|
-
const includeFinalStatus = input.changedPaths === undefined;
|
|
538
|
-
const before = await this.inspectRoot(runtime.canonicalRoot, includeInitialStatus);
|
|
539
|
-
if (includeInitialStatus) {
|
|
540
|
-
this.statusCache.set(runtime.canonicalRoot, before);
|
|
541
|
-
}
|
|
542
|
-
const modelLoadRequest = this.indexModelLoadRequest(before, input);
|
|
543
|
-
const model = modelLoadRequest.model;
|
|
544
|
-
runtime.updateModelLoadRequest(modelLoadRequest);
|
|
545
|
-
let lease;
|
|
546
|
-
try {
|
|
547
|
-
lease = await this.modelPool.acquire(modelLoadRequest);
|
|
548
|
-
}
|
|
549
|
-
catch (error) {
|
|
550
|
-
throw new DaemonError("MODEL_LOAD_FAILED", `Embedding model ${embeddingModelReference(model)} could not be created: ${error instanceof Error ? error.message : String(error)}`);
|
|
551
|
-
}
|
|
552
|
-
let service;
|
|
553
|
-
let scanDiagnostics;
|
|
554
|
-
try {
|
|
555
|
-
service = await (this.options.createService ?? createZvecGrep)({
|
|
556
|
-
...this.options.serviceOptions,
|
|
557
|
-
root: runtime.canonicalRoot,
|
|
558
|
-
embeddingModel: lease.model,
|
|
559
|
-
embeddingModelOwnership: "borrowed",
|
|
560
|
-
embedding: input.runtimeOverridesAreEphemeral
|
|
561
|
-
? undefined
|
|
562
|
-
: input.embedding,
|
|
563
|
-
apiKey: input.runtimeOverridesAreEphemeral ? undefined : input.apiKey,
|
|
564
|
-
endpoint: input.runtimeOverridesAreEphemeral
|
|
565
|
-
? undefined
|
|
566
|
-
: input.endpoint,
|
|
567
|
-
device: input.runtimeOverridesAreEphemeral ? undefined : input.device,
|
|
568
|
-
daemonInstanceToken: this.runtimeManager.instanceToken,
|
|
569
|
-
});
|
|
570
|
-
const result = await runtime.withWrite(() => withRemoteEmbeddingOperationPermit(authorization, () => service.index({
|
|
571
|
-
root: runtime.canonicalRoot,
|
|
572
|
-
rebuild: input.rebuild,
|
|
573
|
-
resetPaths: input.resetPaths,
|
|
574
|
-
globs: normalizePlainStringList(input.globs),
|
|
575
|
-
insensitiveGlobs: normalizePlainStringList(input.insensitiveGlobs),
|
|
576
|
-
fileTypes: normalizePlainStringList(input.fileTypes),
|
|
577
|
-
excludedFileTypes: normalizePlainStringList(input.excludedFileTypes),
|
|
578
|
-
hidden: input.hidden,
|
|
579
|
-
noIgnore: input.noIgnore,
|
|
580
|
-
ignoreFiles: normalizePlainStringList(input.ignoreFiles),
|
|
581
|
-
maxDepth: input.maxDepth,
|
|
582
|
-
maxFileSizeBytes: input.maxFileSizeBytes,
|
|
583
|
-
follow: input.follow,
|
|
584
|
-
embeddingConcurrency: input.embeddingConcurrency,
|
|
585
|
-
changedPaths: input.changedPaths,
|
|
586
|
-
signal,
|
|
587
|
-
onProgress: report,
|
|
588
|
-
onWriterContext: (context) => runtime.setWriterContext(context, lease.key),
|
|
589
|
-
})));
|
|
590
|
-
scanDiagnostics = result.scanDiagnostics;
|
|
591
|
-
}
|
|
592
|
-
finally {
|
|
593
|
-
try {
|
|
594
|
-
await service?.close();
|
|
595
|
-
}
|
|
596
|
-
finally {
|
|
597
|
-
lease.release();
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
if (includeFinalStatus) {
|
|
601
|
-
await this.watchers.get(runtime.canonicalRoot)?.flushPending();
|
|
602
|
-
}
|
|
603
|
-
const proofReconciliationEpoch = runtime.reconciliationEpoch();
|
|
604
|
-
const after = await this.inspectRoot(runtime.canonicalRoot, includeFinalStatus);
|
|
605
|
-
if (includeFinalStatus) {
|
|
606
|
-
this.statusCache.set(runtime.canonicalRoot, after);
|
|
607
|
-
await this.watchers.get(runtime.canonicalRoot)?.refreshPaths?.();
|
|
608
|
-
}
|
|
609
|
-
if (!after.workspaceIndex?.embedding) {
|
|
610
|
-
throw new DaemonError("INDEX_MISSING", "Index completed without an embedding schema.");
|
|
611
|
-
}
|
|
612
|
-
runtime.updateModelLoadRequest(this.searchModelLoadRequest(after, {}));
|
|
613
|
-
this.options.logger?.event("index.completed", {
|
|
614
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
615
|
-
duration_ms: Date.now() - startedAt,
|
|
616
|
-
scope: input.changedPaths ? "paths" : "reconcile",
|
|
617
|
-
changed_paths: input.changedPaths?.length,
|
|
618
|
-
});
|
|
619
|
-
const reconciled = includeFinalStatus && indexStatusIsFresh(after);
|
|
620
|
-
if (includeFinalStatus && !reconciled) {
|
|
621
|
-
runtime.requireFullReconciliation(true);
|
|
622
|
-
}
|
|
623
|
-
return {
|
|
624
|
-
reconciled,
|
|
625
|
-
reconciliationEpoch: proofReconciliationEpoch,
|
|
626
|
-
scanDiagnostics,
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
async submitIndex(runtime, input, reason, wait, authorization) {
|
|
630
|
-
const createsWork = !this.scheduler.hasActiveRoot(runtime.canonicalRoot) ||
|
|
631
|
-
input.rebuild === true;
|
|
632
|
-
const probeBeforeUpdate = reason === "background_reconcile" && runtime.canProbeFullReconciliation();
|
|
633
|
-
let targetRevision = createsWork && !probeBeforeUpdate
|
|
634
|
-
? runtime.markDirty()
|
|
635
|
-
: runtime.snapshot().dirtyRevision;
|
|
636
|
-
const followsNarrowWatch = this.scheduler.getByRoot(runtime.canonicalRoot)?.reason === "watch";
|
|
637
|
-
const submitted = this.scheduler.submit({
|
|
638
|
-
canonicalRoot: runtime.canonicalRoot,
|
|
639
|
-
reason,
|
|
640
|
-
followupIfRunning: followsNarrowWatch,
|
|
641
|
-
run: async (report, signal) => {
|
|
642
|
-
if (probeBeforeUpdate) {
|
|
643
|
-
if ((await this.probeCurrentFreshness(runtime)) === "fresh") {
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
if (createsWork) {
|
|
647
|
-
targetRevision = runtime.markDirty();
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
const proof = await this.runIndex(runtime, input, report, authorization, signal);
|
|
651
|
-
if (proof.reconciled) {
|
|
652
|
-
runtime.markReconciled(targetRevision, proof.reconciliationEpoch);
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
runtime.markIndexed(targetRevision);
|
|
656
|
-
}
|
|
657
|
-
},
|
|
658
|
-
});
|
|
659
|
-
if (!wait)
|
|
660
|
-
return submitted.job;
|
|
661
|
-
const job = await this.scheduler.wait(submitted.job.id);
|
|
662
|
-
await this.scheduler.waitForRootIdle(runtime.canonicalRoot);
|
|
663
|
-
return job;
|
|
664
|
-
}
|
|
665
|
-
ensureWatcher(runtime) {
|
|
666
|
-
if (this.watchers.has(runtime.canonicalRoot) || this.shuttingDown) {
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
const coordinator = new IndexCoordinator({
|
|
670
|
-
runtime,
|
|
671
|
-
scheduler: this.scheduler,
|
|
672
|
-
run: async (changes, report, signal) => {
|
|
673
|
-
const changedPaths = [
|
|
674
|
-
...changes.touchedFiles,
|
|
675
|
-
...changes.rescanDirectories,
|
|
676
|
-
...changes.deletedPrefixes,
|
|
677
|
-
];
|
|
678
|
-
if (!changes.forceFullReconcile && changedPaths.length === 0) {
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
const automaticAuthorization = await this.automaticIndexAuthorization(runtime);
|
|
682
|
-
if (!automaticAuthorization.allowed) {
|
|
683
|
-
throw new DaemonError("REMOTE_EMBEDDING_AUTH_REQUIRED", "A Workspace Remote Embedding grant is required for file-watcher index updates.");
|
|
684
|
-
}
|
|
685
|
-
return await this.runIndex(runtime, {
|
|
686
|
-
root: runtime.canonicalRoot,
|
|
687
|
-
changedPaths: changes.forceFullReconcile ? undefined : changedPaths,
|
|
688
|
-
skipInitialStatus: changes.forceFullReconcile,
|
|
689
|
-
}, report, automaticAuthorization.authorization, signal);
|
|
690
|
-
},
|
|
691
|
-
});
|
|
692
|
-
const watcher = (this.options.watchManagerFactory ??
|
|
693
|
-
((options) => new WatchManager(options)))({
|
|
694
|
-
root: runtime.canonicalRoot,
|
|
695
|
-
onChanges: async (changes, reason) => {
|
|
696
|
-
const pathCount = changes.touchedFiles.length +
|
|
697
|
-
changes.rescanDirectories.length +
|
|
698
|
-
changes.deletedPrefixes.length;
|
|
699
|
-
if (changes.forceFullReconcile && pathCount === 0) {
|
|
700
|
-
runtime.requireFullReconciliation(true);
|
|
701
|
-
this.options.logger?.event("watcher.reconciliation_probe_requested", {
|
|
702
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
703
|
-
reason,
|
|
704
|
-
active_job: this.scheduler.hasActiveRoot(runtime.canonicalRoot),
|
|
705
|
-
});
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
const automaticAuthorization = await this.automaticIndexAuthorization(runtime);
|
|
709
|
-
if (!automaticAuthorization.allowed) {
|
|
710
|
-
runtime.markDirty();
|
|
711
|
-
runtime.requireFullReconciliation();
|
|
712
|
-
this.options.logger?.event("watcher.authorization_required", {
|
|
713
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
714
|
-
reason,
|
|
715
|
-
});
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
this.options.logger?.event(changes.forceFullReconcile ? "watcher.overflow" : "watcher.changes", {
|
|
719
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
720
|
-
reason,
|
|
721
|
-
touched_files: changes.touchedFiles.length,
|
|
722
|
-
rescan_directories: changes.rescanDirectories.length,
|
|
723
|
-
deleted_prefixes: changes.deletedPrefixes.length,
|
|
724
|
-
});
|
|
725
|
-
coordinator.enqueue(changes, reason);
|
|
726
|
-
},
|
|
727
|
-
onPendingChange: (pending) => runtime.setWatcherPending(pending),
|
|
728
|
-
getRootPaths: () => this.statusCache.get(runtime.canonicalRoot)?.workspaceIndex?.rootPaths,
|
|
729
|
-
});
|
|
730
|
-
watcher.start();
|
|
731
|
-
this.indexCoordinators.set(runtime.canonicalRoot, coordinator);
|
|
732
|
-
this.watchers.set(runtime.canonicalRoot, watcher);
|
|
733
|
-
runtime.setWatcherActive(true);
|
|
734
|
-
}
|
|
735
|
-
async settleKnownChanges(runtime) {
|
|
736
|
-
const watcher = this.watchers.get(runtime.canonicalRoot);
|
|
737
|
-
while (true) {
|
|
738
|
-
await watcher?.flushPending();
|
|
739
|
-
await this.scheduler.waitForRootIdle(runtime.canonicalRoot);
|
|
740
|
-
const job = this.scheduler.getByRoot(runtime.canonicalRoot);
|
|
741
|
-
const snapshot = runtime.snapshot();
|
|
742
|
-
if (job?.state === "failed" ||
|
|
743
|
-
job?.state === "cancelled" ||
|
|
744
|
-
!snapshot.watcherPending) {
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
async automaticIndexAuthorization(runtime) {
|
|
750
|
-
const knownProvider = runtime.embeddingProvider();
|
|
751
|
-
if (knownProvider && knownProvider !== "qwen")
|
|
752
|
-
return { allowed: true };
|
|
753
|
-
const root = runtime.canonicalRoot;
|
|
754
|
-
const info = await this.inspectRoot(root, false);
|
|
755
|
-
const schema = info.workspaceIndex?.embedding;
|
|
756
|
-
if (!schema || schema.provider !== "qwen")
|
|
757
|
-
return { allowed: true };
|
|
758
|
-
const modelInfo = await this.loadEmbeddingModelInfo(this.searchModelLoadRequest(info, {}));
|
|
759
|
-
const plan = await planRemoteIndexAuthorization({
|
|
760
|
-
info,
|
|
761
|
-
model: modelInfo,
|
|
762
|
-
needsUpdate: true,
|
|
763
|
-
store: this.authorizationManager.store,
|
|
764
|
-
});
|
|
765
|
-
if (!plan)
|
|
766
|
-
return { allowed: true };
|
|
767
|
-
const authorization = await this.authorizationManager.existingWorkspacePermit(plan);
|
|
768
|
-
return authorization
|
|
769
|
-
? { allowed: true, authorization }
|
|
770
|
-
: { allowed: false };
|
|
771
|
-
}
|
|
772
|
-
async waitForFresh(runtime, authorization, runtimeOverrides = {}) {
|
|
773
|
-
let updateJob;
|
|
774
|
-
while (true) {
|
|
775
|
-
await this.settleKnownChanges(runtime);
|
|
776
|
-
if (!runtime.needsReconciliation()) {
|
|
777
|
-
return updateJob;
|
|
778
|
-
}
|
|
779
|
-
if (!runtime.requiresFullReconciliation() ||
|
|
780
|
-
runtime.canProbeFullReconciliation() ||
|
|
781
|
-
this.scheduler.getByRoot(runtime.canonicalRoot)?.state === "failed" ||
|
|
782
|
-
this.scheduler.getByRoot(runtime.canonicalRoot)?.state === "cancelled") {
|
|
783
|
-
const freshness = await this.probeCurrentFreshness(runtime);
|
|
784
|
-
if (freshness === "fresh") {
|
|
785
|
-
return updateJob;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
const currentJob = this.scheduler.getByRoot(runtime.canonicalRoot);
|
|
789
|
-
if (!runtime.requiresFullReconciliation() &&
|
|
790
|
-
(currentJob?.state === "failed" || currentJob?.state === "cancelled")) {
|
|
791
|
-
throw new DaemonError(currentJob.error?.code ?? "INDEX_FAILED", currentJob.error?.message ??
|
|
792
|
-
"Known index changes did not complete successfully.");
|
|
793
|
-
}
|
|
794
|
-
updateJob = await this.submitIndex(runtime, {
|
|
795
|
-
root: runtime.canonicalRoot,
|
|
796
|
-
apiKey: runtimeOverrides.apiKey,
|
|
797
|
-
device: runtimeOverrides.device,
|
|
798
|
-
runtimeOverridesAreEphemeral: true,
|
|
799
|
-
}, "fresh_query", true, authorization);
|
|
800
|
-
if (updateJob.state !== "succeeded") {
|
|
801
|
-
throw new DaemonError(updateJob.error?.code ?? "INDEX_FAILED", updateJob.error?.message ??
|
|
802
|
-
"Index reconciliation did not complete successfully.");
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
async loadEmbeddingModelInfo(request) {
|
|
807
|
-
const lease = await this.modelPool.acquire(request);
|
|
808
|
-
try {
|
|
809
|
-
return lease.model.info;
|
|
810
|
-
}
|
|
811
|
-
finally {
|
|
812
|
-
lease.release();
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
async probeCurrentFreshness(runtime) {
|
|
816
|
-
const releaseRuntimeActivity = runtime.beginActivity();
|
|
817
|
-
try {
|
|
818
|
-
const freshness = await runtime.probeFreshness(async () => {
|
|
819
|
-
const info = await this.inspectRoot(runtime.canonicalRoot, true);
|
|
820
|
-
this.statusCache.set(runtime.canonicalRoot, info);
|
|
821
|
-
return indexStatusIsFresh(info);
|
|
822
|
-
});
|
|
823
|
-
this.options.logger?.event(`runtime.recovery_probe_${freshness}`, {
|
|
824
|
-
root_id: rootIdentity(runtime.canonicalRoot),
|
|
825
|
-
});
|
|
826
|
-
return freshness;
|
|
827
|
-
}
|
|
828
|
-
finally {
|
|
829
|
-
releaseRuntimeActivity();
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
async closeWatcher(canonicalRoot) {
|
|
833
|
-
const watcher = this.watchers.get(canonicalRoot);
|
|
834
|
-
this.watchers.delete(canonicalRoot);
|
|
835
|
-
this.indexCoordinators.delete(canonicalRoot);
|
|
836
|
-
await watcher?.close();
|
|
837
|
-
}
|
|
838
|
-
assertRootNotDropping(canonicalRoot) {
|
|
839
|
-
if (this.droppingRoots.has(canonicalRoot)) {
|
|
840
|
-
throw new DaemonError("INDEX_DROP_IN_PROGRESS", "The Workspace index is being dropped.", true);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
indexModel(info, input) {
|
|
844
|
-
if (info.workspaceIndex?.embedding && !input.embedding) {
|
|
845
|
-
return {
|
|
846
|
-
provider: info.workspaceIndex.embedding.provider,
|
|
847
|
-
name: info.workspaceIndex.embedding.model,
|
|
848
|
-
};
|
|
849
|
-
}
|
|
850
|
-
const reference = resolveEmbeddingReference({
|
|
851
|
-
explicit: input.embedding ?? this.options.serviceOptions?.embedding,
|
|
852
|
-
environment: {
|
|
853
|
-
ZVEC_GREP_EMBEDDING: input.embeddingEnvironment ?? process.env.ZVEC_GREP_EMBEDDING,
|
|
854
|
-
},
|
|
855
|
-
globalDefault: readGlobalConfig().defaults?.embedding,
|
|
856
|
-
fallback: DEFAULT_LOCAL_EMBEDDING,
|
|
857
|
-
});
|
|
858
|
-
if (!reference) {
|
|
859
|
-
throw new DaemonError("MODEL_LOAD_FAILED", "A new index requires embedding or an explicit server default model.");
|
|
860
|
-
}
|
|
861
|
-
return parseEmbeddingModelReference(reference);
|
|
862
|
-
}
|
|
863
|
-
indexModelLoadRequest(info, input) {
|
|
864
|
-
const model = this.indexModel(info, input);
|
|
865
|
-
const workspaceRuntime = info.workspaceIndex?.embedding?.provider === model.provider
|
|
866
|
-
? this.readWorkspaceEmbeddingRuntime(info)
|
|
867
|
-
: {};
|
|
868
|
-
const runtime = this.resolveModelRuntime(model, workspaceRuntime, input);
|
|
869
|
-
if (input.rebuild !== true &&
|
|
870
|
-
info.workspaceIndex?.embedding &&
|
|
871
|
-
workspaceRuntime.endpoint !== runtime.endpoint) {
|
|
872
|
-
throw new DaemonError("EMBEDDING_ENDPOINT_MISMATCH", "The requested embedding endpoint differs from the workspace snapshot; use rebuild to change endpoints.");
|
|
873
|
-
}
|
|
874
|
-
return { model, runtime };
|
|
875
|
-
}
|
|
876
|
-
searchModelLoadRequest(info, overrides) {
|
|
877
|
-
const schema = info.workspaceIndex?.embedding;
|
|
878
|
-
if (!info.indexed || !schema) {
|
|
879
|
-
throw new DaemonError("INDEX_MISSING", "Search requires an existing workspace index.");
|
|
880
|
-
}
|
|
881
|
-
const model = {
|
|
882
|
-
provider: schema.provider,
|
|
883
|
-
name: schema.model,
|
|
884
|
-
};
|
|
885
|
-
const workspaceRuntime = this.readWorkspaceEmbeddingRuntime(info);
|
|
886
|
-
const runtime = this.resolveModelRuntime(model, workspaceRuntime, overrides);
|
|
887
|
-
return { model, runtime };
|
|
888
|
-
}
|
|
889
|
-
resolveModelRuntime(model, workspaceRuntime, overrides) {
|
|
890
|
-
const serviceOptions = this.options.serviceOptions;
|
|
891
|
-
return resolveEmbeddingRuntimeOptions(embeddingModelReference(model), {
|
|
892
|
-
apiKey: overrides.apiKey ?? serviceOptions?.apiKey,
|
|
893
|
-
endpoint: overrides.endpoint ?? serviceOptions?.endpoint,
|
|
894
|
-
device: overrides.device ?? serviceOptions?.device,
|
|
895
|
-
}, workspaceRuntime, readGlobalConfig());
|
|
896
|
-
}
|
|
897
|
-
overrideActiveModelLoadRequest(request, overrides) {
|
|
898
|
-
const runtime = resolveEmbeddingRuntimeOptions(embeddingModelReference(request.model), overrides, request.runtime ?? {}, readGlobalConfig());
|
|
899
|
-
return { model: request.model, runtime };
|
|
900
|
-
}
|
|
901
|
-
readWorkspaceEmbeddingRuntime(info) {
|
|
902
|
-
try {
|
|
903
|
-
const runtime = readWorkspaceEmbeddingRuntime(info);
|
|
904
|
-
this.workspaceRuntimeCache.set(info.root, runtime);
|
|
905
|
-
return runtime;
|
|
906
|
-
}
|
|
907
|
-
catch (error) {
|
|
908
|
-
const cached = this.workspaceRuntimeCache.get(info.root);
|
|
909
|
-
if (cached &&
|
|
910
|
-
isEngineError(error) &&
|
|
911
|
-
(error.code === "ZVEC_GREP.ENGINE.STORAGE.ZVEC_OPEN_FAILED" ||
|
|
912
|
-
error.code === "ZVEC_GREP.ENGINE.LOCK.BUSY")) {
|
|
913
|
-
return cached;
|
|
914
|
-
}
|
|
915
|
-
throw error;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
async inspectRootWithCache(root) {
|
|
919
|
-
const cached = this.statusCache.get(root);
|
|
920
|
-
if (cached) {
|
|
921
|
-
return cached;
|
|
922
|
-
}
|
|
923
|
-
try {
|
|
924
|
-
const info = await this.inspectRoot(root, false);
|
|
925
|
-
this.statusCache.set(root, info);
|
|
926
|
-
return info;
|
|
927
|
-
}
|
|
928
|
-
catch (error) {
|
|
929
|
-
const fallback = this.statusCache.get(root);
|
|
930
|
-
if (fallback &&
|
|
931
|
-
isEngineError(error) &&
|
|
932
|
-
error.code === "ZVEC_GREP.ENGINE.LOCK.BUSY") {
|
|
933
|
-
return fallback;
|
|
934
|
-
}
|
|
935
|
-
throw error;
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
async inspectRoot(root, includeStatus) {
|
|
939
|
-
return await (this.options.inspectRoot ?? inspectRoot)(root, this.options.serviceOptions, includeStatus);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
function readWorkspaceEmbeddingRuntime(info) {
|
|
943
|
-
if (!info.workspaceIndex)
|
|
944
|
-
return {};
|
|
945
|
-
const location = workspaceIndexLocation(info.root);
|
|
946
|
-
return readWorkspaceManifest(location.home)?.embeddingRuntime ?? {};
|
|
947
|
-
}
|
|
948
|
-
function indexStatusIsFresh(info) {
|
|
949
|
-
const status = info.status;
|
|
950
|
-
return (status !== null &&
|
|
951
|
-
status !== undefined &&
|
|
952
|
-
status.filesAdded === 0 &&
|
|
953
|
-
status.filesModified === 0 &&
|
|
954
|
-
status.filesDeleted === 0 &&
|
|
955
|
-
status.filesPending === 0 &&
|
|
956
|
-
status.filesFailed === 0);
|
|
957
|
-
}
|
|
958
|
-
function assertDropOnlyInput(input) {
|
|
959
|
-
const conflicts = [
|
|
960
|
-
[input.embedding !== undefined, "embedding"],
|
|
961
|
-
[input.apiKey !== undefined, "apiKey"],
|
|
962
|
-
[input.endpoint !== undefined, "endpoint"],
|
|
963
|
-
[input.device !== undefined, "device"],
|
|
964
|
-
[input.rebuild !== undefined, "rebuild"],
|
|
965
|
-
[input.resetPaths !== undefined, "resetPaths"],
|
|
966
|
-
[input.globs !== undefined, "globs"],
|
|
967
|
-
[input.insensitiveGlobs !== undefined, "insensitiveGlobs"],
|
|
968
|
-
[input.fileTypes !== undefined, "fileTypes"],
|
|
969
|
-
[input.excludedFileTypes !== undefined, "excludedFileTypes"],
|
|
970
|
-
[input.hidden !== undefined, "hidden"],
|
|
971
|
-
[input.noIgnore !== undefined, "noIgnore"],
|
|
972
|
-
[input.ignoreFiles !== undefined, "ignoreFiles"],
|
|
973
|
-
[input.maxDepth !== undefined, "maxDepth"],
|
|
974
|
-
[input.maxFileSizeBytes !== undefined, "maxFileSizeBytes"],
|
|
975
|
-
[input.follow !== undefined, "follow"],
|
|
976
|
-
[input.embeddingConcurrency !== undefined, "embeddingConcurrency"],
|
|
977
|
-
[input.wait !== undefined, "wait"],
|
|
978
|
-
];
|
|
979
|
-
const names = conflicts
|
|
980
|
-
.filter(([conflictsWithDrop]) => conflictsWithDrop)
|
|
981
|
-
.map(([, name]) => name);
|
|
982
|
-
if (names.length > 0) {
|
|
983
|
-
throw new DaemonError("INVALID_ARGUMENT", `zvec_grep_index drop cannot be combined with ${names.join(", ")}.`);
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
function embeddingSchema(model) {
|
|
987
|
-
return {
|
|
988
|
-
provider: model.info.provider,
|
|
989
|
-
model: model.info.name,
|
|
990
|
-
dimension: model.info.dimension,
|
|
991
|
-
metric: model.info.metric,
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
function parseEmbeddingModelReference(reference) {
|
|
995
|
-
const separator = reference.indexOf("/");
|
|
996
|
-
if (separator <= 0 || separator === reference.length - 1) {
|
|
997
|
-
throw new DaemonError("MODEL_LOAD_FAILED", `Embedding model reference ${reference} is invalid.`);
|
|
998
|
-
}
|
|
999
|
-
return {
|
|
1000
|
-
provider: reference.slice(0, separator),
|
|
1001
|
-
name: reference.slice(separator + 1),
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
function embeddingModelReference(model) {
|
|
1005
|
-
return `${model.provider}/${model.name}`;
|
|
1006
|
-
}
|
|
1007
|
-
function persistentStatus(info) {
|
|
1008
|
-
return {
|
|
1009
|
-
home: info.home,
|
|
1010
|
-
index_path: info.indexPath,
|
|
1011
|
-
workspace_index: info.workspaceIndex
|
|
1012
|
-
? {
|
|
1013
|
-
id: info.workspaceIndex.id,
|
|
1014
|
-
name: info.workspaceIndex.name,
|
|
1015
|
-
path: info.workspaceIndex.path,
|
|
1016
|
-
root_paths: info.workspaceIndex.rootPaths.map((rootPath) => ({
|
|
1017
|
-
absolute_path: rootPath.absolutePath,
|
|
1018
|
-
recursive: rootPath.recursive,
|
|
1019
|
-
include: rootPath.include ? [...rootPath.include] : undefined,
|
|
1020
|
-
exclude: rootPath.exclude ? [...rootPath.exclude] : undefined,
|
|
1021
|
-
globs: rootPath.globs ? [...rootPath.globs] : undefined,
|
|
1022
|
-
insensitive_globs: rootPath.insensitiveGlobs
|
|
1023
|
-
? [...rootPath.insensitiveGlobs]
|
|
1024
|
-
: undefined,
|
|
1025
|
-
file_types: rootPath.fileTypes
|
|
1026
|
-
? [...rootPath.fileTypes]
|
|
1027
|
-
: undefined,
|
|
1028
|
-
excluded_file_types: rootPath.excludedFileTypes
|
|
1029
|
-
? [...rootPath.excludedFileTypes]
|
|
1030
|
-
: undefined,
|
|
1031
|
-
hidden: rootPath.hidden,
|
|
1032
|
-
no_ignore: rootPath.noIgnore,
|
|
1033
|
-
ignore_files: rootPath.ignoreFiles
|
|
1034
|
-
? [...rootPath.ignoreFiles]
|
|
1035
|
-
: undefined,
|
|
1036
|
-
max_depth: rootPath.maxDepth,
|
|
1037
|
-
max_file_size_bytes: rootPath.maxFileSizeBytes,
|
|
1038
|
-
follow: rootPath.follow,
|
|
1039
|
-
})),
|
|
1040
|
-
embedding: info.workspaceIndex.embedding,
|
|
1041
|
-
index_version: info.workspaceIndex.indexVersion,
|
|
1042
|
-
created_time: info.workspaceIndex.createdTime,
|
|
1043
|
-
updated_time: info.workspaceIndex.updatedTime,
|
|
1044
|
-
}
|
|
1045
|
-
: undefined,
|
|
1046
|
-
files: info.status
|
|
1047
|
-
? {
|
|
1048
|
-
stored: info.status.filesStored,
|
|
1049
|
-
scanned: info.status.filesScanned,
|
|
1050
|
-
indexed: info.status.filesIndexed,
|
|
1051
|
-
pending: info.status.filesPending,
|
|
1052
|
-
failed: info.status.filesFailed,
|
|
1053
|
-
added: info.status.filesAdded,
|
|
1054
|
-
modified: info.status.filesModified,
|
|
1055
|
-
deleted: info.status.filesDeleted,
|
|
1056
|
-
unchanged: info.status.filesUnchanged,
|
|
1057
|
-
entities: info.status.entitiesIndexed,
|
|
1058
|
-
truncated_fragments: info.status.fragmentsTruncated,
|
|
1059
|
-
}
|
|
1060
|
-
: undefined,
|
|
1061
|
-
suggestion: info.suggestion,
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
function formatProgress(job) {
|
|
1065
|
-
const progress = job.progress;
|
|
1066
|
-
if (!progress) {
|
|
1067
|
-
return undefined;
|
|
1068
|
-
}
|
|
1069
|
-
return {
|
|
1070
|
-
phase: progress.phase,
|
|
1071
|
-
files_total: progress.filesTotal,
|
|
1072
|
-
files_indexed: progress.filesIndexed,
|
|
1073
|
-
files_failed: progress.filesFailed,
|
|
1074
|
-
detail: progress.detail,
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
function searchIndexingSnapshot(job, completion) {
|
|
1078
|
-
const state = !job || job.state === "succeeded" ? "idle" : job.state;
|
|
1079
|
-
const effectiveCompletion = indexCompletionForJob(completion, job?.state, job?.progress);
|
|
1080
|
-
return {
|
|
1081
|
-
state,
|
|
1082
|
-
...effectiveCompletion,
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
//# sourceMappingURL=backend.js.map
|