@angri450/zvec-grep 0.2.2
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 +201 -0
- package/README.md +319 -0
- package/README_CN.md +297 -0
- package/dist/authorization/index.d.ts +7 -0
- package/dist/authorization/index.js +7 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/manager.d.ts +8 -0
- package/dist/authorization/manager.js +19 -0
- package/dist/authorization/manager.js.map +1 -0
- package/dist/authorization/operation.d.ts +7 -0
- package/dist/authorization/operation.js +50 -0
- package/dist/authorization/operation.js.map +1 -0
- package/dist/authorization/planner.d.ts +21 -0
- package/dist/authorization/planner.js +97 -0
- package/dist/authorization/planner.js.map +1 -0
- package/dist/authorization/prompt.d.ts +12 -0
- package/dist/authorization/prompt.js +63 -0
- package/dist/authorization/prompt.js.map +1 -0
- package/dist/authorization/store.d.ts +20 -0
- package/dist/authorization/store.js +251 -0
- package/dist/authorization/store.js.map +1 -0
- package/dist/authorization/target.d.ts +15 -0
- package/dist/authorization/target.js +49 -0
- package/dist/authorization/target.js.map +1 -0
- package/dist/authorization/types.d.ts +61 -0
- package/dist/authorization/types.js +2 -0
- package/dist/authorization/types.js.map +1 -0
- package/dist/cli/args.d.ts +6 -0
- package/dist/cli/args.js +1255 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/auth.d.ts +21 -0
- package/dist/cli/auth.js +209 -0
- package/dist/cli/auth.js.map +1 -0
- package/dist/cli/commands.d.ts +4 -0
- package/dist/cli/commands.js +801 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/errors.d.ts +9 -0
- package/dist/cli/errors.js +131 -0
- package/dist/cli/errors.js.map +1 -0
- package/dist/cli/format/context.d.ts +9 -0
- package/dist/cli/format/context.js +786 -0
- package/dist/cli/format/context.js.map +1 -0
- package/dist/cli/format/debug.d.ts +4 -0
- package/dist/cli/format/debug.js +60 -0
- package/dist/cli/format/debug.js.map +1 -0
- package/dist/cli/format/highlight.d.ts +3 -0
- package/dist/cli/format/highlight.js +106 -0
- package/dist/cli/format/highlight.js.map +1 -0
- package/dist/cli/format/progress.d.ts +13 -0
- package/dist/cli/format/progress.js +290 -0
- package/dist/cli/format/progress.js.map +1 -0
- package/dist/cli/format/range.d.ts +3 -0
- package/dist/cli/format/range.js +24 -0
- package/dist/cli/format/range.js.map +1 -0
- package/dist/cli/format/status.d.ts +83 -0
- package/dist/cli/format/status.js +530 -0
- package/dist/cli/format/status.js.map +1 -0
- package/dist/cli/help.d.ts +1 -0
- package/dist/cli/help.js +546 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +40 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/install.d.ts +4 -0
- package/dist/cli/install.js +1735 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/cli/managed-rg.d.ts +10 -0
- package/dist/cli/managed-rg.js +337 -0
- package/dist/cli/managed-rg.js.map +1 -0
- package/dist/cli/server-search.d.ts +3 -0
- package/dist/cli/server-search.js +12 -0
- package/dist/cli/server-search.js.map +1 -0
- package/dist/cli/types.d.ts +87 -0
- package/dist/cli/types.js +10 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/version.d.ts +1 -0
- package/dist/cli/version.js +13 -0
- package/dist/cli/version.js.map +1 -0
- package/dist/client/daemon-client.d.ts +31 -0
- package/dist/client/daemon-client.js +203 -0
- package/dist/client/daemon-client.js.map +1 -0
- package/dist/client/mode-router.d.ts +9 -0
- package/dist/client/mode-router.js +28 -0
- package/dist/client/mode-router.js.map +1 -0
- package/dist/client/search-policy.d.ts +11 -0
- package/dist/client/search-policy.js +15 -0
- package/dist/client/search-policy.js.map +1 -0
- package/dist/daemon/backend.d.ts +78 -0
- package/dist/daemon/backend.js +1118 -0
- package/dist/daemon/backend.js.map +1 -0
- package/dist/daemon/change-set.d.ts +30 -0
- package/dist/daemon/change-set.js +163 -0
- package/dist/daemon/change-set.js.map +1 -0
- package/dist/daemon/config.d.ts +27 -0
- package/dist/daemon/config.js +107 -0
- package/dist/daemon/config.js.map +1 -0
- package/dist/daemon/errors.d.ts +5 -0
- package/dist/daemon/errors.js +11 -0
- package/dist/daemon/errors.js.map +1 -0
- package/dist/daemon/http-server.d.ts +30 -0
- package/dist/daemon/http-server.js +307 -0
- package/dist/daemon/http-server.js.map +1 -0
- package/dist/daemon/index-coordinator.d.ts +22 -0
- package/dist/daemon/index-coordinator.js +55 -0
- package/dist/daemon/index-coordinator.js.map +1 -0
- package/dist/daemon/job-scheduler.d.ts +85 -0
- package/dist/daemon/job-scheduler.js +492 -0
- package/dist/daemon/job-scheduler.js.map +1 -0
- package/dist/daemon/logger.d.ts +10 -0
- package/dist/daemon/logger.js +101 -0
- package/dist/daemon/logger.js.map +1 -0
- package/dist/daemon/model-pool.d.ts +48 -0
- package/dist/daemon/model-pool.js +190 -0
- package/dist/daemon/model-pool.js.map +1 -0
- package/dist/daemon/root-lease.d.ts +14 -0
- package/dist/daemon/root-lease.js +197 -0
- package/dist/daemon/root-lease.js.map +1 -0
- package/dist/daemon/root-runtime.d.ts +80 -0
- package/dist/daemon/root-runtime.js +340 -0
- package/dist/daemon/root-runtime.js.map +1 -0
- package/dist/daemon/runtime-manager.d.ts +47 -0
- package/dist/daemon/runtime-manager.js +252 -0
- package/dist/daemon/runtime-manager.js.map +1 -0
- package/dist/daemon/runtime.d.ts +12 -0
- package/dist/daemon/runtime.js +105 -0
- package/dist/daemon/runtime.js.map +1 -0
- package/dist/daemon/server-controller.d.ts +38 -0
- package/dist/daemon/server-controller.js +327 -0
- package/dist/daemon/server-controller.js.map +1 -0
- package/dist/daemon/watch-manager.d.ts +62 -0
- package/dist/daemon/watch-manager.js +415 -0
- package/dist/daemon/watch-manager.js.map +1 -0
- package/dist/daemon/workspace-read-session-cache.d.ts +31 -0
- package/dist/daemon/workspace-read-session-cache.js +115 -0
- package/dist/daemon/workspace-read-session-cache.js.map +1 -0
- package/dist/engine/code-formats.d.ts +3 -0
- package/dist/engine/code-formats.js +14 -0
- package/dist/engine/code-formats.js.map +1 -0
- package/dist/engine/config.d.ts +57 -0
- package/dist/engine/config.js +351 -0
- package/dist/engine/config.js.map +1 -0
- package/dist/engine/errors.d.ts +20 -0
- package/dist/engine/errors.js +51 -0
- package/dist/engine/errors.js.map +1 -0
- package/dist/engine/extraction/code/adapter.d.ts +19 -0
- package/dist/engine/extraction/code/adapter.js +24 -0
- package/dist/engine/extraction/code/adapter.js.map +1 -0
- package/dist/engine/extraction/code/extractor.d.ts +13 -0
- package/dist/engine/extraction/code/extractor.js +696 -0
- package/dist/engine/extraction/code/extractor.js.map +1 -0
- package/dist/engine/extraction/code/families/c-family.d.ts +2 -0
- package/dist/engine/extraction/code/families/c-family.js +122 -0
- package/dist/engine/extraction/code/families/c-family.js.map +1 -0
- package/dist/engine/extraction/code/families/js-ts.d.ts +12 -0
- package/dist/engine/extraction/code/families/js-ts.js +118 -0
- package/dist/engine/extraction/code/families/js-ts.js.map +1 -0
- package/dist/engine/extraction/code/families/metadata.d.ts +8 -0
- package/dist/engine/extraction/code/families/metadata.js +86 -0
- package/dist/engine/extraction/code/families/metadata.js.map +1 -0
- package/dist/engine/extraction/code/families/name-field.d.ts +3 -0
- package/dist/engine/extraction/code/families/name-field.js +22 -0
- package/dist/engine/extraction/code/families/name-field.js.map +1 -0
- package/dist/engine/extraction/code/languages/c.d.ts +1 -0
- package/dist/engine/extraction/code/languages/c.js +12 -0
- package/dist/engine/extraction/code/languages/c.js.map +1 -0
- package/dist/engine/extraction/code/languages/cpp.d.ts +1 -0
- package/dist/engine/extraction/code/languages/cpp.js +18 -0
- package/dist/engine/extraction/code/languages/cpp.js.map +1 -0
- package/dist/engine/extraction/code/languages/go.d.ts +2 -0
- package/dist/engine/extraction/code/languages/go.js +70 -0
- package/dist/engine/extraction/code/languages/go.js.map +1 -0
- package/dist/engine/extraction/code/languages/java.d.ts +1 -0
- package/dist/engine/extraction/code/languages/java.js +17 -0
- package/dist/engine/extraction/code/languages/java.js.map +1 -0
- package/dist/engine/extraction/code/languages/javascript.d.ts +2 -0
- package/dist/engine/extraction/code/languages/javascript.js +23 -0
- package/dist/engine/extraction/code/languages/javascript.js.map +1 -0
- package/dist/engine/extraction/code/languages/python.d.ts +2 -0
- package/dist/engine/extraction/code/languages/python.js +52 -0
- package/dist/engine/extraction/code/languages/python.js.map +1 -0
- package/dist/engine/extraction/code/languages/rust.d.ts +2 -0
- package/dist/engine/extraction/code/languages/rust.js +25 -0
- package/dist/engine/extraction/code/languages/rust.js.map +1 -0
- package/dist/engine/extraction/code/languages/typescript.d.ts +2 -0
- package/dist/engine/extraction/code/languages/typescript.js +37 -0
- package/dist/engine/extraction/code/languages/typescript.js.map +1 -0
- package/dist/engine/extraction/code/tree-sitter/grammar.d.ts +4 -0
- package/dist/engine/extraction/code/tree-sitter/grammar.js +49 -0
- package/dist/engine/extraction/code/tree-sitter/grammar.js.map +1 -0
- package/dist/engine/extraction/code/tree-sitter/nodes.d.ts +3 -0
- package/dist/engine/extraction/code/tree-sitter/nodes.js +27 -0
- package/dist/engine/extraction/code/tree-sitter/nodes.js.map +1 -0
- package/dist/engine/extraction/code/tree-sitter/parser.d.ts +2 -0
- package/dist/engine/extraction/code/tree-sitter/parser.js +31 -0
- package/dist/engine/extraction/code/tree-sitter/parser.js.map +1 -0
- package/dist/engine/extraction/ids.d.ts +1 -0
- package/dist/engine/extraction/ids.js +5 -0
- package/dist/engine/extraction/ids.js.map +1 -0
- package/dist/engine/extraction/image/extractor.d.ts +5 -0
- package/dist/engine/extraction/image/extractor.js +35 -0
- package/dist/engine/extraction/image/extractor.js.map +1 -0
- package/dist/engine/extraction/index.d.ts +4 -0
- package/dist/engine/extraction/index.js +3 -0
- package/dist/engine/extraction/index.js.map +1 -0
- package/dist/engine/extraction/markdown/extractor.d.ts +7 -0
- package/dist/engine/extraction/markdown/extractor.js +362 -0
- package/dist/engine/extraction/markdown/extractor.js.map +1 -0
- package/dist/engine/extraction/runtime.d.ts +9 -0
- package/dist/engine/extraction/runtime.js +37 -0
- package/dist/engine/extraction/runtime.js.map +1 -0
- package/dist/engine/extraction/source.d.ts +18 -0
- package/dist/engine/extraction/source.js +22 -0
- package/dist/engine/extraction/source.js.map +1 -0
- package/dist/engine/extraction/text/extractor.d.ts +7 -0
- package/dist/engine/extraction/text/extractor.js +168 -0
- package/dist/engine/extraction/text/extractor.js.map +1 -0
- package/dist/engine/extraction/types.d.ts +4 -0
- package/dist/engine/extraction/types.js +2 -0
- package/dist/engine/extraction/types.js.map +1 -0
- package/dist/engine/extraction/vector-content.d.ts +5 -0
- package/dist/engine/extraction/vector-content.js +83 -0
- package/dist/engine/extraction/vector-content.js.map +1 -0
- package/dist/engine/file-size-policy.d.ts +6 -0
- package/dist/engine/file-size-policy.js +20 -0
- package/dist/engine/file-size-policy.js.map +1 -0
- package/dist/engine/file-type.d.ts +15 -0
- package/dist/engine/file-type.js +152 -0
- package/dist/engine/file-type.js.map +1 -0
- package/dist/engine/index-status.d.ts +9 -0
- package/dist/engine/index-status.js +38 -0
- package/dist/engine/index-status.js.map +1 -0
- package/dist/engine/manifest.d.ts +13 -0
- package/dist/engine/manifest.js +124 -0
- package/dist/engine/manifest.js.map +1 -0
- package/dist/engine/models/artifact-cache-lock.d.ts +16 -0
- package/dist/engine/models/artifact-cache-lock.js +228 -0
- package/dist/engine/models/artifact-cache-lock.js.map +1 -0
- package/dist/engine/models/artifact-downloader.d.ts +77 -0
- package/dist/engine/models/artifact-downloader.js +766 -0
- package/dist/engine/models/artifact-downloader.js.map +1 -0
- package/dist/engine/models/backends/llama-cpp.d.ts +100 -0
- package/dist/engine/models/backends/llama-cpp.js +567 -0
- package/dist/engine/models/backends/llama-cpp.js.map +1 -0
- package/dist/engine/models/backends/model2vec-runtime.d.ts +63 -0
- package/dist/engine/models/backends/model2vec-runtime.js +112 -0
- package/dist/engine/models/backends/model2vec-runtime.js.map +1 -0
- package/dist/engine/models/backends/model2vec-tokenizer.d.ts +2 -0
- package/dist/engine/models/backends/model2vec-tokenizer.js +42 -0
- package/dist/engine/models/backends/model2vec-tokenizer.js.map +1 -0
- package/dist/engine/models/backends/model2vec-worker-pool.d.ts +25 -0
- package/dist/engine/models/backends/model2vec-worker-pool.js +264 -0
- package/dist/engine/models/backends/model2vec-worker-pool.js.map +1 -0
- package/dist/engine/models/backends/model2vec-worker.d.ts +1 -0
- package/dist/engine/models/backends/model2vec-worker.js +41 -0
- package/dist/engine/models/backends/model2vec-worker.js.map +1 -0
- package/dist/engine/models/backends/model2vec.d.ts +38 -0
- package/dist/engine/models/backends/model2vec.js +344 -0
- package/dist/engine/models/backends/model2vec.js.map +1 -0
- package/dist/engine/models/backends/qwen.d.ts +44 -0
- package/dist/engine/models/backends/qwen.js +411 -0
- package/dist/engine/models/backends/qwen.js.map +1 -0
- package/dist/engine/models/backends/transformers-js.d.ts +90 -0
- package/dist/engine/models/backends/transformers-js.js +411 -0
- package/dist/engine/models/backends/transformers-js.js.map +1 -0
- package/dist/engine/models/catalog.d.ts +490 -0
- package/dist/engine/models/catalog.js +522 -0
- package/dist/engine/models/catalog.js.map +1 -0
- package/dist/engine/models/download-progress.d.ts +16 -0
- package/dist/engine/models/download-progress.js +47 -0
- package/dist/engine/models/download-progress.js.map +1 -0
- package/dist/engine/models/embeddings.d.ts +73 -0
- package/dist/engine/models/embeddings.js +125 -0
- package/dist/engine/models/embeddings.js.map +1 -0
- package/dist/engine/models/factory.d.ts +2 -0
- package/dist/engine/models/factory.js +51 -0
- package/dist/engine/models/factory.js.map +1 -0
- package/dist/engine/models/index.d.ts +5 -0
- package/dist/engine/models/index.js +6 -0
- package/dist/engine/models/index.js.map +1 -0
- package/dist/engine/models/local-embedding-parallelism.d.ts +15 -0
- package/dist/engine/models/local-embedding-parallelism.js +63 -0
- package/dist/engine/models/local-embedding-parallelism.js.map +1 -0
- package/dist/engine/models/local-embedding-queue.d.ts +12 -0
- package/dist/engine/models/local-embedding-queue.js +65 -0
- package/dist/engine/models/local-embedding-queue.js.map +1 -0
- package/dist/engine/models/ranking.d.ts +19 -0
- package/dist/engine/models/ranking.js +2 -0
- package/dist/engine/models/ranking.js.map +1 -0
- package/dist/engine/models/resolution.d.ts +8 -0
- package/dist/engine/models/resolution.js +22 -0
- package/dist/engine/models/resolution.js.map +1 -0
- package/dist/engine/pipeline/indexing/index.d.ts +14 -0
- package/dist/engine/pipeline/indexing/index.js +1219 -0
- package/dist/engine/pipeline/indexing/index.js.map +1 -0
- package/dist/engine/pipeline/indexing/input-budget.d.ts +2 -0
- package/dist/engine/pipeline/indexing/input-budget.js +51 -0
- package/dist/engine/pipeline/indexing/input-budget.js.map +1 -0
- package/dist/engine/pipeline/indexing/root-paths.d.ts +7 -0
- package/dist/engine/pipeline/indexing/root-paths.js +148 -0
- package/dist/engine/pipeline/indexing/root-paths.js.map +1 -0
- package/dist/engine/pipeline/indexing/scanner/index.d.ts +14 -0
- package/dist/engine/pipeline/indexing/scanner/index.js +776 -0
- package/dist/engine/pipeline/indexing/scanner/index.js.map +1 -0
- package/dist/engine/pipeline/search/index.d.ts +12 -0
- package/dist/engine/pipeline/search/index.js +811 -0
- package/dist/engine/pipeline/search/index.js.map +1 -0
- package/dist/engine/service/index.d.ts +3 -0
- package/dist/engine/service/index.js +2 -0
- package/dist/engine/service/index.js.map +1 -0
- package/dist/engine/service/lexical.d.ts +28 -0
- package/dist/engine/service/lexical.js +446 -0
- package/dist/engine/service/lexical.js.map +1 -0
- package/dist/engine/service/root.d.ts +15 -0
- package/dist/engine/service/root.js +57 -0
- package/dist/engine/service/root.js.map +1 -0
- package/dist/engine/service/structure-enrichment.d.ts +8 -0
- package/dist/engine/service/structure-enrichment.js +178 -0
- package/dist/engine/service/structure-enrichment.js.map +1 -0
- package/dist/engine/service/types.d.ts +212 -0
- package/dist/engine/service/types.js +2 -0
- package/dist/engine/service/types.js.map +1 -0
- package/dist/engine/service/workspace-index.d.ts +26 -0
- package/dist/engine/service/workspace-index.js +157 -0
- package/dist/engine/service/workspace-index.js.map +1 -0
- package/dist/engine/service/zvec-grep.d.ts +15 -0
- package/dist/engine/service/zvec-grep.js +1520 -0
- package/dist/engine/service/zvec-grep.js.map +1 -0
- package/dist/engine/storage/index.d.ts +53 -0
- package/dist/engine/storage/index.js +3 -0
- package/dist/engine/storage/index.js.map +1 -0
- package/dist/engine/storage/layout.d.ts +10 -0
- package/dist/engine/storage/layout.js +29 -0
- package/dist/engine/storage/layout.js.map +1 -0
- package/dist/engine/storage/zvec.d.ts +4 -0
- package/dist/engine/storage/zvec.js +976 -0
- package/dist/engine/storage/zvec.js.map +1 -0
- package/dist/engine/types.d.ts +303 -0
- package/dist/engine/types.js +14 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/engine/utils/atomic-file.d.ts +3 -0
- package/dist/engine/utils/atomic-file.js +39 -0
- package/dist/engine/utils/atomic-file.js.map +1 -0
- package/dist/engine/utils/daemon-lease.d.ts +17 -0
- package/dist/engine/utils/daemon-lease.js +175 -0
- package/dist/engine/utils/daemon-lease.js.map +1 -0
- package/dist/engine/utils/file-selection.d.ts +10 -0
- package/dist/engine/utils/file-selection.js +157 -0
- package/dist/engine/utils/file-selection.js.map +1 -0
- package/dist/engine/utils/glob.d.ts +9 -0
- package/dist/engine/utils/glob.js +208 -0
- package/dist/engine/utils/glob.js.map +1 -0
- package/dist/engine/utils/hash.d.ts +2 -0
- package/dist/engine/utils/hash.js +8 -0
- package/dist/engine/utils/hash.js.map +1 -0
- package/dist/engine/utils/json.d.ts +8 -0
- package/dist/engine/utils/json.js +83 -0
- package/dist/engine/utils/json.js.map +1 -0
- package/dist/engine/utils/lock.d.ts +19 -0
- package/dist/engine/utils/lock.js +254 -0
- package/dist/engine/utils/lock.js.map +1 -0
- package/dist/engine/utils/path.d.ts +4 -0
- package/dist/engine/utils/path.js +18 -0
- package/dist/engine/utils/path.js.map +1 -0
- package/dist/engine/utils/timing.d.ts +19 -0
- package/dist/engine/utils/timing.js +87 -0
- package/dist/engine/utils/timing.js.map +1 -0
- package/dist/index-progress.d.ts +10 -0
- package/dist/index-progress.js +159 -0
- package/dist/index-progress.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/http-transport.d.ts +27 -0
- package/dist/mcp/http-transport.js +182 -0
- package/dist/mcp/http-transport.js.map +1 -0
- package/dist/mcp/input-normalization.d.ts +38 -0
- package/dist/mcp/input-normalization.js +104 -0
- package/dist/mcp/input-normalization.js.map +1 -0
- package/dist/mcp/progress-heartbeat.d.ts +17 -0
- package/dist/mcp/progress-heartbeat.js +46 -0
- package/dist/mcp/progress-heartbeat.js.map +1 -0
- package/dist/mcp/request-metadata.d.ts +2 -0
- package/dist/mcp/request-metadata.js +11 -0
- package/dist/mcp/request-metadata.js.map +1 -0
- package/dist/mcp/request-state.d.ts +40 -0
- package/dist/mcp/request-state.js +210 -0
- package/dist/mcp/request-state.js.map +1 -0
- package/dist/mcp/result-format.d.ts +13 -0
- package/dist/mcp/result-format.js +75 -0
- package/dist/mcp/result-format.js.map +1 -0
- package/dist/mcp/schemas.d.ts +668 -0
- package/dist/mcp/schemas.js +512 -0
- package/dist/mcp/schemas.js.map +1 -0
- package/dist/mcp/stdio-bridge.d.ts +15 -0
- package/dist/mcp/stdio-bridge.js +190 -0
- package/dist/mcp/stdio-bridge.js.map +1 -0
- package/dist/mcp/tools.d.ts +153 -0
- package/dist/mcp/tools.js +488 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/toolset.d.ts +5 -0
- package/dist/mcp/toolset.js +12 -0
- package/dist/mcp/toolset.js.map +1 -0
- package/dist/observability/trace-context.d.ts +11 -0
- package/dist/observability/trace-context.js +138 -0
- package/dist/observability/trace-context.js.map +1 -0
- package/dist/prompts/zvec-grep-guidance.d.ts +2 -0
- package/dist/prompts/zvec-grep-guidance.js +9 -0
- package/dist/prompts/zvec-grep-guidance.js.map +1 -0
- package/docs/01-agents.md +217 -0
- package/docs/02-cli.md +259 -0
- package/docs/03-mcp.md +185 -0
- package/docs/04-pipeline.md +234 -0
- package/docs/05-architecture.md +86 -0
- package/docs/06-server.md +279 -0
- package/docs/07-embedding.md +227 -0
- package/docs/08-roadmap.md +85 -0
- package/docs/README.md +53 -0
- package/package.json +87 -0
package/dist/cli/args.js
ADDED
|
@@ -0,0 +1,1255 @@
|
|
|
1
|
+
import { VALID_SYMBOL_TYPES } from "./types.js";
|
|
2
|
+
import { parseMcpToolset } from "../mcp/toolset.js";
|
|
3
|
+
const RG_OPTIONS_WITH_VALUE = new Set([
|
|
4
|
+
"--dfa-size-limit",
|
|
5
|
+
"--encoding",
|
|
6
|
+
"--engine",
|
|
7
|
+
"--max-columns",
|
|
8
|
+
"--max-count",
|
|
9
|
+
"--regex-size-limit",
|
|
10
|
+
"--threads",
|
|
11
|
+
]);
|
|
12
|
+
const RG_OPTIONS_WITHOUT_VALUE = new Set([
|
|
13
|
+
"--auto-hybrid-regex",
|
|
14
|
+
"--case-sensitive",
|
|
15
|
+
"--binary",
|
|
16
|
+
"--crlf",
|
|
17
|
+
"--invert-match",
|
|
18
|
+
"--line-regexp",
|
|
19
|
+
"--mmap",
|
|
20
|
+
"--multiline",
|
|
21
|
+
"--multiline-dotall",
|
|
22
|
+
"--no-crlf",
|
|
23
|
+
"--no-fixed-strings",
|
|
24
|
+
"--no-ignore",
|
|
25
|
+
"--no-ignore-dot",
|
|
26
|
+
"--no-ignore-files",
|
|
27
|
+
"--no-ignore-global",
|
|
28
|
+
"--no-ignore-parent",
|
|
29
|
+
"--no-ignore-vcs",
|
|
30
|
+
"--no-config",
|
|
31
|
+
"--no-mmap",
|
|
32
|
+
"--no-multiline",
|
|
33
|
+
"--no-search-zip",
|
|
34
|
+
"--pcre2",
|
|
35
|
+
"--one-file-system",
|
|
36
|
+
"--search-zip",
|
|
37
|
+
"--smart-case",
|
|
38
|
+
"--stop-on-nonmatch",
|
|
39
|
+
"--text",
|
|
40
|
+
"--unicode",
|
|
41
|
+
"--no-unicode",
|
|
42
|
+
"--glob-case-insensitive",
|
|
43
|
+
]);
|
|
44
|
+
const MANAGED_RG_OUTPUT_OPTIONS = new Set([
|
|
45
|
+
"--count",
|
|
46
|
+
"--count-matches",
|
|
47
|
+
"--files",
|
|
48
|
+
"--files-with-matches",
|
|
49
|
+
"--files-without-match",
|
|
50
|
+
"--column",
|
|
51
|
+
"--byte-offset",
|
|
52
|
+
"--no-column",
|
|
53
|
+
"--colors",
|
|
54
|
+
"--context-separator",
|
|
55
|
+
"--field-context-separator",
|
|
56
|
+
"--field-match-separator",
|
|
57
|
+
"--json",
|
|
58
|
+
"--heading",
|
|
59
|
+
"--no-heading",
|
|
60
|
+
"--no-filename",
|
|
61
|
+
"--no-line-number",
|
|
62
|
+
"--only-matching",
|
|
63
|
+
"--passthru",
|
|
64
|
+
"--path-separator",
|
|
65
|
+
"--quiet",
|
|
66
|
+
"--pretty",
|
|
67
|
+
"--replace",
|
|
68
|
+
"--stats",
|
|
69
|
+
"--trim",
|
|
70
|
+
"--vimgrep",
|
|
71
|
+
"-c",
|
|
72
|
+
"-b",
|
|
73
|
+
"-I",
|
|
74
|
+
"-l",
|
|
75
|
+
"-N",
|
|
76
|
+
"-o",
|
|
77
|
+
"-p",
|
|
78
|
+
"-q",
|
|
79
|
+
"-r",
|
|
80
|
+
]);
|
|
81
|
+
const ACTION_FLAGS = new Map([
|
|
82
|
+
["--index", "index"],
|
|
83
|
+
["--status", "status"],
|
|
84
|
+
["--install", "install"],
|
|
85
|
+
["--uninstall", "uninstall"],
|
|
86
|
+
["--config", "config"],
|
|
87
|
+
["--auth", "auth"],
|
|
88
|
+
["--server", "server"],
|
|
89
|
+
]);
|
|
90
|
+
const COMMAND_SHAPED_QUERY_WORDS = new Set(["query", "search"]);
|
|
91
|
+
const COMMAND_SHAPED_ACTION_WORDS = new Map([
|
|
92
|
+
["index", "--index"],
|
|
93
|
+
["status", "--status"],
|
|
94
|
+
["install", "--install"],
|
|
95
|
+
["uninstall", "--uninstall"],
|
|
96
|
+
["config", "--config"],
|
|
97
|
+
["auth", "--auth"],
|
|
98
|
+
["server", "--server"],
|
|
99
|
+
["help", "--help"],
|
|
100
|
+
["version", "--version"],
|
|
101
|
+
]);
|
|
102
|
+
export function compatibilityWarningForArgs(args) {
|
|
103
|
+
const first = args[0];
|
|
104
|
+
if (!first)
|
|
105
|
+
return undefined;
|
|
106
|
+
if (COMMAND_SHAPED_QUERY_WORDS.has(first)) {
|
|
107
|
+
return `warning: "zg ${first} ..." is not a subcommand; search is already the default. Remove "${first}", or use 'zg -- "${first}" ...' to search for that literal word.`;
|
|
108
|
+
}
|
|
109
|
+
const action = COMMAND_SHAPED_ACTION_WORDS.get(first);
|
|
110
|
+
if (!action)
|
|
111
|
+
return undefined;
|
|
112
|
+
return `warning: "zg ${first} ..." no longer runs an action and is parsed as search input. Use "zg ${action} ...", or 'zg -- "${first}" ...' to search for that literal word.`;
|
|
113
|
+
}
|
|
114
|
+
export function parseArgs(args) {
|
|
115
|
+
const commandInput = parseCommand(args);
|
|
116
|
+
if (commandInput.command === "help" || commandInput.command === "version") {
|
|
117
|
+
return {
|
|
118
|
+
command: commandInput.command,
|
|
119
|
+
options: {},
|
|
120
|
+
positionals: [],
|
|
121
|
+
...(commandInput.helpTopic ? { helpTopic: commandInput.helpTopic } : {}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const commandArgs = commandInput.args;
|
|
125
|
+
const options = {};
|
|
126
|
+
const positionals = [];
|
|
127
|
+
let startIndex = 0;
|
|
128
|
+
if (commandInput.command === "config") {
|
|
129
|
+
if (commandArgs[0] === "model" && commandArgs[1] === "set") {
|
|
130
|
+
options.configAction = "model-set";
|
|
131
|
+
startIndex = 2;
|
|
132
|
+
}
|
|
133
|
+
else if (commandArgs[0] === "provider" && commandArgs[1] === "set") {
|
|
134
|
+
options.configAction = "provider-set";
|
|
135
|
+
startIndex = 2;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (commandInput.command === "auth") {
|
|
139
|
+
if (commandArgs[0] === "grant" ||
|
|
140
|
+
commandArgs[0] === "status" ||
|
|
141
|
+
commandArgs[0] === "revoke") {
|
|
142
|
+
options.authAction = commandArgs[0];
|
|
143
|
+
startIndex = 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (commandInput.command === "server") {
|
|
147
|
+
if (commandArgs[0] === "on" ||
|
|
148
|
+
commandArgs[0] === "off" ||
|
|
149
|
+
commandArgs[0] === "status" ||
|
|
150
|
+
commandArgs[0] === "run") {
|
|
151
|
+
options.serverAction = commandArgs[0];
|
|
152
|
+
startIndex = 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (let index = startIndex; index < commandArgs.length; index++) {
|
|
156
|
+
const arg = commandArgs[index];
|
|
157
|
+
if (arg === "--") {
|
|
158
|
+
positionals.push(...commandArgs.slice(index + 1));
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (!arg.startsWith("-") || arg === "-") {
|
|
162
|
+
positionals.push(arg);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (arg === "--help" || arg === "-h") {
|
|
166
|
+
return {
|
|
167
|
+
command: "help",
|
|
168
|
+
options: {},
|
|
169
|
+
positionals: [],
|
|
170
|
+
helpTopic: commandInput.command === "query" ? "search" : commandInput.command,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
else if (arg === "--version") {
|
|
174
|
+
throw new Error(`${arg} must be used without a command`);
|
|
175
|
+
}
|
|
176
|
+
else if (isLongOptionWithValue(arg, "--mode")) {
|
|
177
|
+
options.mode = parseClientMode(valueFromLongOption(arg));
|
|
178
|
+
}
|
|
179
|
+
else if (arg === "--mode") {
|
|
180
|
+
options.mode = parseClientMode(readOptionValue(commandArgs, ++index, arg));
|
|
181
|
+
}
|
|
182
|
+
else if (arg === "--force-direct") {
|
|
183
|
+
options.forceDirect = true;
|
|
184
|
+
}
|
|
185
|
+
else if (arg === "--stdio") {
|
|
186
|
+
options.serverStdio = true;
|
|
187
|
+
}
|
|
188
|
+
else if (isLongOptionWithValue(arg, "--mcp-toolset")) {
|
|
189
|
+
options.mcpToolset = parseMcpToolset(valueFromLongOption(arg));
|
|
190
|
+
}
|
|
191
|
+
else if (arg === "--mcp-toolset") {
|
|
192
|
+
options.mcpToolset = parseMcpToolset(readOptionValue(commandArgs, ++index, arg));
|
|
193
|
+
}
|
|
194
|
+
else if (isLongOptionWithValue(arg, "--listen")) {
|
|
195
|
+
options.listen = valueFromLongOption(arg);
|
|
196
|
+
}
|
|
197
|
+
else if (arg === "--listen") {
|
|
198
|
+
options.listen = readOptionValue(commandArgs, ++index, arg);
|
|
199
|
+
}
|
|
200
|
+
else if (isLongOptionWithValue(arg, "--token-file")) {
|
|
201
|
+
options.serverTokenFile = valueFromLongOption(arg);
|
|
202
|
+
}
|
|
203
|
+
else if (arg === "--token-file") {
|
|
204
|
+
options.serverTokenFile = readOptionValue(commandArgs, ++index, arg);
|
|
205
|
+
}
|
|
206
|
+
else if (isLongOptionWithValue(arg, "--target")) {
|
|
207
|
+
options.installTargets = appendInstallTargets(options.installTargets, valueFromLongOption(arg));
|
|
208
|
+
}
|
|
209
|
+
else if (arg === "--target") {
|
|
210
|
+
options.installTargets = appendInstallTargets(options.installTargets, readOptionValue(commandArgs, ++index, arg));
|
|
211
|
+
}
|
|
212
|
+
else if (isLongOptionWithValue(arg, "--mcp-tool-timeout")) {
|
|
213
|
+
options.installMcpToolTimeoutSeconds = parsePositiveInteger(valueFromLongOption(arg), "--mcp-tool-timeout");
|
|
214
|
+
}
|
|
215
|
+
else if (arg === "--mcp-tool-timeout") {
|
|
216
|
+
options.installMcpToolTimeoutSeconds = parsePositiveInteger(readOptionValue(commandArgs, ++index, arg), arg);
|
|
217
|
+
}
|
|
218
|
+
else if (isLongOptionWithValue(arg, "--mcp-token-env")) {
|
|
219
|
+
options.installMcpTokenEnv = parseEnvironmentVariable(valueFromLongOption(arg), "--mcp-token-env");
|
|
220
|
+
}
|
|
221
|
+
else if (arg === "--mcp-token-env") {
|
|
222
|
+
options.installMcpTokenEnv = parseEnvironmentVariable(readOptionValue(commandArgs, ++index, arg), arg);
|
|
223
|
+
}
|
|
224
|
+
else if (isLongOptionWithValue(arg, "--mcp-transport")) {
|
|
225
|
+
options.installMcpTransport = parseMcpInstallTransport(valueFromLongOption(arg));
|
|
226
|
+
}
|
|
227
|
+
else if (arg === "--mcp-transport") {
|
|
228
|
+
options.installMcpTransport = parseMcpInstallTransport(readOptionValue(commandArgs, ++index, arg));
|
|
229
|
+
}
|
|
230
|
+
else if (arg === "--yes") {
|
|
231
|
+
options.yes = true;
|
|
232
|
+
}
|
|
233
|
+
else if (isLongOptionWithValue(arg, "--allow-remote")) {
|
|
234
|
+
throw allowRemoteValueError();
|
|
235
|
+
}
|
|
236
|
+
else if (arg === "--allow-remote") {
|
|
237
|
+
const legacyScope = commandArgs[index + 1];
|
|
238
|
+
if (legacyScope === "once" || legacyScope === "workspace") {
|
|
239
|
+
throw allowRemoteValueError();
|
|
240
|
+
}
|
|
241
|
+
options.allowRemote = true;
|
|
242
|
+
}
|
|
243
|
+
else if (isLongOptionWithValue(arg, "--capability")) {
|
|
244
|
+
options.authorizationCapability = parseAuthorizationCapability(valueFromLongOption(arg));
|
|
245
|
+
}
|
|
246
|
+
else if (arg === "--capability") {
|
|
247
|
+
options.authorizationCapability = parseAuthorizationCapability(readOptionValue(commandArgs, ++index, arg));
|
|
248
|
+
}
|
|
249
|
+
else if (isLongOptionWithValue(arg, "--scope")) {
|
|
250
|
+
options.authorizationScope = parseAuthorizationScope(valueFromLongOption(arg));
|
|
251
|
+
}
|
|
252
|
+
else if (arg === "--scope") {
|
|
253
|
+
options.authorizationScope = parseAuthorizationScope(readOptionValue(commandArgs, ++index, arg));
|
|
254
|
+
}
|
|
255
|
+
else if (arg === "--rg") {
|
|
256
|
+
options.rg = true;
|
|
257
|
+
}
|
|
258
|
+
else if (arg === "--debug") {
|
|
259
|
+
options.debug = true;
|
|
260
|
+
}
|
|
261
|
+
else if (arg === "--trace") {
|
|
262
|
+
options.trace = true;
|
|
263
|
+
}
|
|
264
|
+
else if (arg === "--human") {
|
|
265
|
+
throw new Error("--human has been removed; terminal output is human-readable by default");
|
|
266
|
+
}
|
|
267
|
+
else if (arg === "--compact") {
|
|
268
|
+
options.human = false;
|
|
269
|
+
}
|
|
270
|
+
else if (arg === "--check-ready") {
|
|
271
|
+
options.checkReady = true;
|
|
272
|
+
}
|
|
273
|
+
else if (isLongOptionWithValue(arg, "--preview")) {
|
|
274
|
+
options.preview = parsePreviewMode(valueFromLongOption(arg));
|
|
275
|
+
}
|
|
276
|
+
else if (arg === "--preview") {
|
|
277
|
+
options.preview = parsePreviewMode(readOptionValue(commandArgs, ++index, arg));
|
|
278
|
+
}
|
|
279
|
+
else if (arg === "--json") {
|
|
280
|
+
throw new Error("--json is not supported; redirect output or use --compact for compact markdown");
|
|
281
|
+
}
|
|
282
|
+
else if (arg === "--no-color") {
|
|
283
|
+
options.color = "never";
|
|
284
|
+
}
|
|
285
|
+
else if (arg === "--rebuild") {
|
|
286
|
+
options.rebuild = true;
|
|
287
|
+
}
|
|
288
|
+
else if (arg === "--drop") {
|
|
289
|
+
options.drop = true;
|
|
290
|
+
}
|
|
291
|
+
else if (arg === "--force") {
|
|
292
|
+
options.force = true;
|
|
293
|
+
}
|
|
294
|
+
else if (arg === "--reset-paths") {
|
|
295
|
+
options.resetPaths = true;
|
|
296
|
+
}
|
|
297
|
+
else if (arg === "--default") {
|
|
298
|
+
options.defaultModel = true;
|
|
299
|
+
}
|
|
300
|
+
else if (isLongOptionWithValue(arg, "--refresh")) {
|
|
301
|
+
options.refresh = parseQueryRefreshMode(valueFromLongOption(arg));
|
|
302
|
+
}
|
|
303
|
+
else if (arg === "--refresh") {
|
|
304
|
+
options.refresh = parseQueryRefreshMode(readOptionValue(commandArgs, ++index, arg));
|
|
305
|
+
}
|
|
306
|
+
else if (arg === "--prefer-symbol") {
|
|
307
|
+
options.preferSymbol = true;
|
|
308
|
+
}
|
|
309
|
+
else if (arg === "--home") {
|
|
310
|
+
options.home = readOptionValue(commandArgs, ++index, arg);
|
|
311
|
+
}
|
|
312
|
+
else if (arg === "--embedding") {
|
|
313
|
+
options.embedding = readOptionValue(commandArgs, ++index, arg);
|
|
314
|
+
}
|
|
315
|
+
else if (arg === "--model-cache") {
|
|
316
|
+
options.modelCacheDir = readOptionValue(commandArgs, ++index, arg);
|
|
317
|
+
}
|
|
318
|
+
else if (arg === "--device") {
|
|
319
|
+
options.device = parseDevice(readOptionValue(commandArgs, ++index, arg));
|
|
320
|
+
}
|
|
321
|
+
else if (arg === "--api-key") {
|
|
322
|
+
options.apiKey = readOptionValue(commandArgs, ++index, arg);
|
|
323
|
+
}
|
|
324
|
+
else if (arg === "--endpoint") {
|
|
325
|
+
options.endpoint = readOptionValue(commandArgs, ++index, arg);
|
|
326
|
+
}
|
|
327
|
+
else if (arg === "--limit") {
|
|
328
|
+
options.limit = parsePositiveInteger(readOptionValue(commandArgs, ++index, arg), arg);
|
|
329
|
+
}
|
|
330
|
+
else if (arg === "--index-embedding-concurrency") {
|
|
331
|
+
options.embeddingConcurrency = parsePositiveInteger(readOptionValue(commandArgs, ++index, arg), arg);
|
|
332
|
+
}
|
|
333
|
+
else if (isLongOptionWithValue(arg, "--hybrid")) {
|
|
334
|
+
options.hybridQueries = appendQuery(options.hybridQueries, valueFromLongOption(arg), "--hybrid");
|
|
335
|
+
}
|
|
336
|
+
else if (arg === "--hybrid") {
|
|
337
|
+
options.hybridQueries = appendQuery(options.hybridQueries, readOptionValue(commandArgs, ++index, arg), arg);
|
|
338
|
+
}
|
|
339
|
+
else if (isLongOptionWithValue(arg, "--fts")) {
|
|
340
|
+
options.routes = appendRoute(options.routes, "fts", valueFromLongOption(arg), "--fts");
|
|
341
|
+
}
|
|
342
|
+
else if (arg === "--fts") {
|
|
343
|
+
options.routes = appendRoute(options.routes, "fts", readOptionValue(commandArgs, ++index, arg), arg);
|
|
344
|
+
}
|
|
345
|
+
else if (isLongOptionWithValue(arg, "--vector")) {
|
|
346
|
+
options.routes = appendRoute(options.routes, "vector", valueFromLongOption(arg), "--vector");
|
|
347
|
+
}
|
|
348
|
+
else if (arg === "--vector") {
|
|
349
|
+
options.routes = appendRoute(options.routes, "vector", readOptionValue(commandArgs, ++index, arg), arg);
|
|
350
|
+
}
|
|
351
|
+
else if (arg === "--fuse") {
|
|
352
|
+
options.fuse = true;
|
|
353
|
+
}
|
|
354
|
+
else if (arg === "--color") {
|
|
355
|
+
options.color = parseColorMode(readOptionValue(commandArgs, ++index, arg));
|
|
356
|
+
}
|
|
357
|
+
else if (isLongOptionWithValue(arg, "--glob")) {
|
|
358
|
+
options.globs = appendValue(options.globs, valueFromLongOption(arg), "--glob");
|
|
359
|
+
}
|
|
360
|
+
else if (arg === "--glob" || arg === "-g") {
|
|
361
|
+
options.globs = appendValue(options.globs, readOptionValue(commandArgs, ++index, arg), arg);
|
|
362
|
+
}
|
|
363
|
+
else if (isLongOptionWithValue(arg, "--iglob")) {
|
|
364
|
+
options.insensitiveGlobs = appendValue(options.insensitiveGlobs, valueFromLongOption(arg), "--iglob");
|
|
365
|
+
}
|
|
366
|
+
else if (arg === "--iglob") {
|
|
367
|
+
options.insensitiveGlobs = appendValue(options.insensitiveGlobs, readOptionValue(commandArgs, ++index, arg), arg);
|
|
368
|
+
}
|
|
369
|
+
else if (isLongOptionWithValue(arg, "--type")) {
|
|
370
|
+
options.fileTypes = appendValue(options.fileTypes, valueFromLongOption(arg), "--type");
|
|
371
|
+
}
|
|
372
|
+
else if (arg === "--type" || arg === "-t") {
|
|
373
|
+
options.fileTypes = appendValue(options.fileTypes, readOptionValue(commandArgs, ++index, arg), arg);
|
|
374
|
+
}
|
|
375
|
+
else if (isLongOptionWithValue(arg, "--type-not")) {
|
|
376
|
+
options.excludedFileTypes = appendValue(options.excludedFileTypes, valueFromLongOption(arg), "--type-not");
|
|
377
|
+
}
|
|
378
|
+
else if (arg === "--type-not" || arg === "-T") {
|
|
379
|
+
options.excludedFileTypes = appendValue(options.excludedFileTypes, readOptionValue(commandArgs, ++index, arg), arg);
|
|
380
|
+
}
|
|
381
|
+
else if (arg === "--hidden") {
|
|
382
|
+
options.hidden = true;
|
|
383
|
+
}
|
|
384
|
+
else if (arg === "--no-ignore") {
|
|
385
|
+
options.noIgnore = true;
|
|
386
|
+
}
|
|
387
|
+
else if (isLongOptionWithValue(arg, "--ignore-file")) {
|
|
388
|
+
options.ignoreFiles = appendValue(options.ignoreFiles, valueFromLongOption(arg), "--ignore-file");
|
|
389
|
+
}
|
|
390
|
+
else if (arg === "--ignore-file") {
|
|
391
|
+
options.ignoreFiles = appendValue(options.ignoreFiles, readOptionValue(commandArgs, ++index, arg), arg);
|
|
392
|
+
}
|
|
393
|
+
else if (isLongOptionWithValue(arg, "--max-depth")) {
|
|
394
|
+
options.maxDepth = parseNonNegativeInteger(valueFromLongOption(arg), "--max-depth");
|
|
395
|
+
}
|
|
396
|
+
else if (arg === "--max-depth") {
|
|
397
|
+
options.maxDepth = parseNonNegativeInteger(readOptionValue(commandArgs, ++index, arg), arg);
|
|
398
|
+
}
|
|
399
|
+
else if (isLongOptionWithValue(arg, "--max-filesize")) {
|
|
400
|
+
options.maxFileSizeBytes = parseByteSize(valueFromLongOption(arg), "--max-filesize");
|
|
401
|
+
}
|
|
402
|
+
else if (arg === "--max-filesize") {
|
|
403
|
+
options.maxFileSizeBytes = parseByteSize(readOptionValue(commandArgs, ++index, arg), arg);
|
|
404
|
+
}
|
|
405
|
+
else if (arg === "--follow" || arg === "-L") {
|
|
406
|
+
options.follow = true;
|
|
407
|
+
}
|
|
408
|
+
else if (arg === "--ignore-case") {
|
|
409
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [arg]);
|
|
410
|
+
markRgCompatibilityOption(options, arg);
|
|
411
|
+
}
|
|
412
|
+
else if (arg === "--word-regexp") {
|
|
413
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [arg]);
|
|
414
|
+
markRgCompatibilityOption(options, arg);
|
|
415
|
+
}
|
|
416
|
+
else if (arg === "--fixed-strings") {
|
|
417
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [arg]);
|
|
418
|
+
markRgCompatibilityOption(options, arg);
|
|
419
|
+
}
|
|
420
|
+
else if (isLongOptionWithValue(arg, "--file")) {
|
|
421
|
+
options.rgOptions = appendRgPatternFile(options.rgOptions, valueFromLongOption(arg), "--file");
|
|
422
|
+
markRgCompatibilityOption(options, "--file");
|
|
423
|
+
}
|
|
424
|
+
else if (arg === "--file") {
|
|
425
|
+
options.rgOptions = appendRgPatternFile(options.rgOptions, readOptionValue(commandArgs, ++index, arg), arg);
|
|
426
|
+
markRgCompatibilityOption(options, arg);
|
|
427
|
+
}
|
|
428
|
+
else if (isRgFlagWithValue(arg)) {
|
|
429
|
+
const option = optionNameFromLong(arg);
|
|
430
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [
|
|
431
|
+
option,
|
|
432
|
+
valueFromLongOption(arg),
|
|
433
|
+
]);
|
|
434
|
+
markRgCompatibilityOption(options, option);
|
|
435
|
+
}
|
|
436
|
+
else if (RG_OPTIONS_WITH_VALUE.has(arg)) {
|
|
437
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [
|
|
438
|
+
arg,
|
|
439
|
+
readOptionValue(commandArgs, ++index, arg),
|
|
440
|
+
]);
|
|
441
|
+
markRgCompatibilityOption(options, arg);
|
|
442
|
+
}
|
|
443
|
+
else if (RG_OPTIONS_WITHOUT_VALUE.has(arg)) {
|
|
444
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [arg]);
|
|
445
|
+
markRgCompatibilityOption(options, arg);
|
|
446
|
+
}
|
|
447
|
+
else if (arg === "--recursive" ||
|
|
448
|
+
arg === "--line-number" ||
|
|
449
|
+
arg === "--with-filename") {
|
|
450
|
+
markRgCompatibilityOption(options, arg);
|
|
451
|
+
}
|
|
452
|
+
else if (isLongOptionWithValue(arg, "--regexp")) {
|
|
453
|
+
options.rgOptions = appendRgPattern(options.rgOptions, valueFromLongOption(arg));
|
|
454
|
+
markRgCompatibilityOption(options, "--regexp");
|
|
455
|
+
}
|
|
456
|
+
else if (arg === "--regexp") {
|
|
457
|
+
options.rgOptions = appendRgPattern(options.rgOptions, readOptionValue(commandArgs, ++index, arg));
|
|
458
|
+
markRgCompatibilityOption(options, arg);
|
|
459
|
+
}
|
|
460
|
+
else if (isLongOptionWithValue(arg, "--context")) {
|
|
461
|
+
options.rgOptions = setRgContext(options.rgOptions, "both", valueFromLongOption(arg), "--context");
|
|
462
|
+
markRgCompatibilityOption(options, "--context");
|
|
463
|
+
}
|
|
464
|
+
else if (arg === "--context") {
|
|
465
|
+
options.rgOptions = setRgContext(options.rgOptions, "both", readOptionValue(commandArgs, ++index, arg), arg);
|
|
466
|
+
markRgCompatibilityOption(options, arg);
|
|
467
|
+
}
|
|
468
|
+
else if (isLongOptionWithValue(arg, "--before-context")) {
|
|
469
|
+
options.rgOptions = setRgContext(options.rgOptions, "before", valueFromLongOption(arg), "--before-context");
|
|
470
|
+
markRgCompatibilityOption(options, "--before-context");
|
|
471
|
+
}
|
|
472
|
+
else if (arg === "--before-context") {
|
|
473
|
+
options.rgOptions = setRgContext(options.rgOptions, "before", readOptionValue(commandArgs, ++index, arg), arg);
|
|
474
|
+
markRgCompatibilityOption(options, arg);
|
|
475
|
+
}
|
|
476
|
+
else if (isLongOptionWithValue(arg, "--after-context")) {
|
|
477
|
+
options.rgOptions = setRgContext(options.rgOptions, "after", valueFromLongOption(arg), "--after-context");
|
|
478
|
+
markRgCompatibilityOption(options, "--after-context");
|
|
479
|
+
}
|
|
480
|
+
else if (arg === "--after-context") {
|
|
481
|
+
options.rgOptions = setRgContext(options.rgOptions, "after", readOptionValue(commandArgs, ++index, arg), arg);
|
|
482
|
+
markRgCompatibilityOption(options, arg);
|
|
483
|
+
}
|
|
484
|
+
else if (isManagedRgOutputOption(arg)) {
|
|
485
|
+
throw new Error(`${arg} changes rg output and cannot be used with managed --rg`);
|
|
486
|
+
}
|
|
487
|
+
else if (isShortRgOptionGroup(arg)) {
|
|
488
|
+
index = parseShortRgOptionGroup(commandArgs, index, options);
|
|
489
|
+
}
|
|
490
|
+
else if (arg === "--modified-after") {
|
|
491
|
+
options.modifiedAfter = parseModifiedTime(readOptionValue(commandArgs, ++index, arg), arg);
|
|
492
|
+
}
|
|
493
|
+
else if (arg === "--modified-before") {
|
|
494
|
+
options.modifiedBefore = parseModifiedTime(readOptionValue(commandArgs, ++index, arg), arg);
|
|
495
|
+
}
|
|
496
|
+
else if (arg === "--symbol-type") {
|
|
497
|
+
options.symbolTypes = [
|
|
498
|
+
...(options.symbolTypes ?? []),
|
|
499
|
+
parseSymbolType(readOptionValue(commandArgs, ++index, arg)),
|
|
500
|
+
];
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
throw new Error(`Unknown option: ${arg}`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
validateCliShape(commandInput.command, options, positionals);
|
|
507
|
+
return { command: commandInput.command, options, positionals };
|
|
508
|
+
}
|
|
509
|
+
function parseCommand(args) {
|
|
510
|
+
const [first, ...rest] = args;
|
|
511
|
+
if (first === undefined) {
|
|
512
|
+
return { command: "help", args: [] };
|
|
513
|
+
}
|
|
514
|
+
if (first === "-h" || first === "--help") {
|
|
515
|
+
if (rest.length > 1) {
|
|
516
|
+
throw new Error(`${first} accepts at most one topic`);
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
command: "help",
|
|
520
|
+
...(rest[0] ? { helpTopic: rest[0] } : {}),
|
|
521
|
+
args: [],
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
if (first.startsWith("--help=")) {
|
|
525
|
+
if (rest.length > 0) {
|
|
526
|
+
throw new Error("--help=<topic> does not accept arguments");
|
|
527
|
+
}
|
|
528
|
+
const helpTopic = first.slice("--help=".length);
|
|
529
|
+
if (!helpTopic)
|
|
530
|
+
throw new Error("--help requires a topic after =");
|
|
531
|
+
return { command: "help", helpTopic, args: [] };
|
|
532
|
+
}
|
|
533
|
+
if (first === "-v" || first === "--version") {
|
|
534
|
+
if (rest.length > 0) {
|
|
535
|
+
throw new Error(`${first} does not accept arguments`);
|
|
536
|
+
}
|
|
537
|
+
return { command: "version", args: [] };
|
|
538
|
+
}
|
|
539
|
+
const delimiter = args.indexOf("--");
|
|
540
|
+
const optionEnd = delimiter === -1 ? args.length : delimiter;
|
|
541
|
+
const actions = args
|
|
542
|
+
.slice(0, optionEnd)
|
|
543
|
+
.map((arg, index) => ({ command: ACTION_FLAGS.get(arg), index }))
|
|
544
|
+
.filter((entry) => entry.command !== undefined);
|
|
545
|
+
if (actions.length > 1) {
|
|
546
|
+
throw new Error("Only one management action can be used at a time");
|
|
547
|
+
}
|
|
548
|
+
if (actions[0]) {
|
|
549
|
+
return {
|
|
550
|
+
command: actions[0].command,
|
|
551
|
+
args: args.filter((_, index) => index !== actions[0].index),
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
return { command: "query", args };
|
|
555
|
+
}
|
|
556
|
+
function validateCliShape(command, options, positionals) {
|
|
557
|
+
if (command === "auth") {
|
|
558
|
+
if (!options.authAction) {
|
|
559
|
+
throw new Error("zg --auth requires grant, status, or revoke");
|
|
560
|
+
}
|
|
561
|
+
if (positionals.length > 1) {
|
|
562
|
+
throw new Error(`zg --auth ${options.authAction} accepts at most one root`);
|
|
563
|
+
}
|
|
564
|
+
if (options.authAction !== "grant" &&
|
|
565
|
+
(options.authorizationCapability || options.authorizationScope)) {
|
|
566
|
+
throw new Error(`--capability and --scope can only be used with zg --auth grant`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
else if (options.authorizationCapability || options.authorizationScope) {
|
|
570
|
+
throw new Error("--capability and --scope can only be used with zg --auth");
|
|
571
|
+
}
|
|
572
|
+
if (options.allowRemote && command !== "query" && command !== "index") {
|
|
573
|
+
throw new Error("--allow-remote can only be used with search or --index");
|
|
574
|
+
}
|
|
575
|
+
const queryOnly = firstEnabledOption([
|
|
576
|
+
[options.rg, "--rg"],
|
|
577
|
+
[options.hybridQueries?.length, "--hybrid"],
|
|
578
|
+
[options.routes?.length, "--fts/--vector"],
|
|
579
|
+
[options.fuse, "--fuse"],
|
|
580
|
+
[options.trace, "--trace"],
|
|
581
|
+
[options.human, "--compact"],
|
|
582
|
+
[options.preview, "--preview"],
|
|
583
|
+
[options.limit, "--limit"],
|
|
584
|
+
[options.refresh, "--refresh"],
|
|
585
|
+
[options.preferSymbol, "--prefer-symbol"],
|
|
586
|
+
[options.symbolTypes?.length, "--symbol-type"],
|
|
587
|
+
[options.modifiedAfter, "--modified-after"],
|
|
588
|
+
[options.modifiedBefore, "--modified-before"],
|
|
589
|
+
[options.rgCompatibilityOptions?.length, "ripgrep options"],
|
|
590
|
+
]);
|
|
591
|
+
if (command !== "query" && queryOnly) {
|
|
592
|
+
throw new Error(`${queryOnly} can only be used for search`);
|
|
593
|
+
}
|
|
594
|
+
if (options.debug &&
|
|
595
|
+
command !== "query" &&
|
|
596
|
+
command !== "index" &&
|
|
597
|
+
command !== "status") {
|
|
598
|
+
throw new Error("--debug can only be used with zg, zg --index, or zg --status");
|
|
599
|
+
}
|
|
600
|
+
const sharedSelection = firstEnabledOption([
|
|
601
|
+
[options.globs?.length, "--glob"],
|
|
602
|
+
[options.insensitiveGlobs?.length, "--iglob"],
|
|
603
|
+
[options.fileTypes?.length, "--type"],
|
|
604
|
+
[options.excludedFileTypes?.length, "--type-not"],
|
|
605
|
+
]);
|
|
606
|
+
if (sharedSelection && command !== "query" && command !== "index") {
|
|
607
|
+
throw new Error(`${sharedSelection} can only be used with search or --index`);
|
|
608
|
+
}
|
|
609
|
+
const discoveryOption = firstEnabledOption([
|
|
610
|
+
[options.hidden, "--hidden"],
|
|
611
|
+
[options.noIgnore, "--no-ignore"],
|
|
612
|
+
[options.ignoreFiles?.length, "--ignore-file"],
|
|
613
|
+
[options.maxDepth, "--max-depth"],
|
|
614
|
+
[options.maxFileSizeBytes, "--max-filesize"],
|
|
615
|
+
[options.follow, "--follow"],
|
|
616
|
+
]);
|
|
617
|
+
if (discoveryOption &&
|
|
618
|
+
command !== "index" &&
|
|
619
|
+
!(command === "query" && options.rg)) {
|
|
620
|
+
throw new Error(`${discoveryOption} can only be used with --index or --rg`);
|
|
621
|
+
}
|
|
622
|
+
if (command === "config") {
|
|
623
|
+
if (!options.configAction) {
|
|
624
|
+
throw new Error("zg --config requires provider set or model set");
|
|
625
|
+
}
|
|
626
|
+
const unsupported = firstEnabledOption([
|
|
627
|
+
[options.installTargets?.length, "--target"],
|
|
628
|
+
[options.installMcpToolTimeoutSeconds, "--mcp-tool-timeout"],
|
|
629
|
+
[options.installMcpTokenEnv, "--mcp-token-env"],
|
|
630
|
+
[options.yes, "--yes"],
|
|
631
|
+
[options.rg, "--rg"],
|
|
632
|
+
[options.home, "--home"],
|
|
633
|
+
[options.embedding, "--embedding"],
|
|
634
|
+
[
|
|
635
|
+
options.configAction === "model-set" ? options.apiKey : undefined,
|
|
636
|
+
"--api-key",
|
|
637
|
+
],
|
|
638
|
+
[
|
|
639
|
+
options.configAction === "provider-set" ? options.endpoint : undefined,
|
|
640
|
+
"--endpoint",
|
|
641
|
+
],
|
|
642
|
+
[
|
|
643
|
+
options.configAction === "provider-set" ? options.device : undefined,
|
|
644
|
+
"--device",
|
|
645
|
+
],
|
|
646
|
+
[
|
|
647
|
+
options.configAction === "provider-set"
|
|
648
|
+
? options.defaultModel
|
|
649
|
+
: undefined,
|
|
650
|
+
"--default",
|
|
651
|
+
],
|
|
652
|
+
[options.mode, "--mode"],
|
|
653
|
+
[options.listen, "--listen"],
|
|
654
|
+
[options.serverTokenFile, "--token-file"],
|
|
655
|
+
]);
|
|
656
|
+
if (unsupported) {
|
|
657
|
+
throw new Error(`zg --config ${options.configAction === "model-set" ? "model" : "provider"} set does not accept ${unsupported}`);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
else if (options.defaultModel) {
|
|
661
|
+
throw new Error("--default can only be used with zg --config model set");
|
|
662
|
+
}
|
|
663
|
+
if (command === "server") {
|
|
664
|
+
if (!options.serverAction && !options.serverStdio) {
|
|
665
|
+
throw new Error("zg --server requires on, off, status, run, or --stdio");
|
|
666
|
+
}
|
|
667
|
+
if (options.serverAction && options.serverStdio) {
|
|
668
|
+
throw new Error("--stdio cannot be combined with a server action");
|
|
669
|
+
}
|
|
670
|
+
if (options.listen !== undefined &&
|
|
671
|
+
options.serverAction !== "run" &&
|
|
672
|
+
options.serverAction !== "on" &&
|
|
673
|
+
!options.serverStdio) {
|
|
674
|
+
throw new Error("--listen can only be used with zg --server on or run");
|
|
675
|
+
}
|
|
676
|
+
if (options.serverTokenFile !== undefined &&
|
|
677
|
+
options.serverAction === "status") {
|
|
678
|
+
throw new Error("--token-file cannot be used with zg --server status");
|
|
679
|
+
}
|
|
680
|
+
if (options.mcpToolset !== undefined &&
|
|
681
|
+
options.serverAction !== "on" &&
|
|
682
|
+
options.serverAction !== "run" &&
|
|
683
|
+
!options.serverStdio) {
|
|
684
|
+
throw new Error("--mcp-toolset can only be used with zg --server on or run");
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
else if (options.mcpToolset !== undefined && command !== "install") {
|
|
688
|
+
throw new Error("--mcp-toolset can only be used with zg --server on, run, --stdio, or zg --install");
|
|
689
|
+
}
|
|
690
|
+
else if (options.serverStdio !== undefined) {
|
|
691
|
+
throw new Error("--stdio can only be used with zg --server");
|
|
692
|
+
}
|
|
693
|
+
if (options.rg &&
|
|
694
|
+
(hasExplicitRoutes(options) || options.hybridQueries?.length)) {
|
|
695
|
+
throw new Error("--rg cannot be combined with --hybrid, --fts, or --vector");
|
|
696
|
+
}
|
|
697
|
+
if (options.rg && options.fuse) {
|
|
698
|
+
throw new Error("--rg cannot be combined with --fuse");
|
|
699
|
+
}
|
|
700
|
+
if (options.forceDirect && options.mode !== "direct") {
|
|
701
|
+
throw new Error("--force-direct requires --mode direct");
|
|
702
|
+
}
|
|
703
|
+
if (options.rg && options.preview) {
|
|
704
|
+
throw new Error("--preview is not supported with --rg; use -A/-B/-C for rg context");
|
|
705
|
+
}
|
|
706
|
+
if (options.rg && options.trace) {
|
|
707
|
+
throw new Error("--rg cannot be combined with --trace");
|
|
708
|
+
}
|
|
709
|
+
if (options.rg && (options.preferSymbol || options.symbolTypes?.length)) {
|
|
710
|
+
throw new Error("--rg cannot be combined with indexed symbol options");
|
|
711
|
+
}
|
|
712
|
+
if (options.rg && options.refresh) {
|
|
713
|
+
throw new Error("--rg cannot be combined with indexed refresh options");
|
|
714
|
+
}
|
|
715
|
+
if (options.embeddingConcurrency !== undefined && command !== "index") {
|
|
716
|
+
throw new Error("--index-embedding-concurrency can only be used with zg --index");
|
|
717
|
+
}
|
|
718
|
+
if (!options.rg && (options.rgCompatibilityOptions?.length ?? 0) > 0) {
|
|
719
|
+
const [option] = options.rgCompatibilityOptions;
|
|
720
|
+
throw new Error(`${option} can only be used with --rg`);
|
|
721
|
+
}
|
|
722
|
+
if (options.mode !== undefined &&
|
|
723
|
+
command !== "query" &&
|
|
724
|
+
command !== "index" &&
|
|
725
|
+
command !== "status") {
|
|
726
|
+
throw new Error("--mode can only be used with search, --index, or --status");
|
|
727
|
+
}
|
|
728
|
+
if (options.checkReady &&
|
|
729
|
+
command !== "status" &&
|
|
730
|
+
!(command === "server" && options.serverAction === "status")) {
|
|
731
|
+
throw new Error("--check-ready can only be used with zg --status or zg --server status");
|
|
732
|
+
}
|
|
733
|
+
if (options.listen !== undefined && command !== "server") {
|
|
734
|
+
throw new Error("--listen can only be used with zg --server on or run");
|
|
735
|
+
}
|
|
736
|
+
if (options.serverTokenFile !== undefined && command !== "server") {
|
|
737
|
+
throw new Error("--token-file can only be used with zg --server");
|
|
738
|
+
}
|
|
739
|
+
if (options.installTargets?.length &&
|
|
740
|
+
command !== "install" &&
|
|
741
|
+
command !== "uninstall") {
|
|
742
|
+
throw new Error("--target can only be used with --install or --uninstall");
|
|
743
|
+
}
|
|
744
|
+
if (options.installMcpToolTimeoutSeconds !== undefined &&
|
|
745
|
+
command !== "install") {
|
|
746
|
+
throw new Error("--mcp-tool-timeout can only be used with zg --install");
|
|
747
|
+
}
|
|
748
|
+
if (options.installMcpTokenEnv !== undefined && command !== "install") {
|
|
749
|
+
throw new Error("--mcp-token-env can only be used with zg --install");
|
|
750
|
+
}
|
|
751
|
+
if (options.installMcpTransport !== undefined && command !== "install") {
|
|
752
|
+
throw new Error("--mcp-transport can only be used with zg --install");
|
|
753
|
+
}
|
|
754
|
+
if (command === "install" &&
|
|
755
|
+
options.installMcpTransport !== "http" &&
|
|
756
|
+
options.installMcpTokenEnv !== undefined) {
|
|
757
|
+
throw new Error("--mcp-token-env requires --mcp-transport http");
|
|
758
|
+
}
|
|
759
|
+
if (options.force && command !== "install") {
|
|
760
|
+
throw new Error("--force can only be used with zg --install");
|
|
761
|
+
}
|
|
762
|
+
if (command === "install" || command === "uninstall") {
|
|
763
|
+
const unsupported = firstEnabledOption([
|
|
764
|
+
[options.color, "--color"],
|
|
765
|
+
[options.home, "--home"],
|
|
766
|
+
[options.embedding, "--embedding"],
|
|
767
|
+
[options.modelCacheDir, "--model-cache"],
|
|
768
|
+
[options.device, "--device"],
|
|
769
|
+
[options.apiKey, "--api-key"],
|
|
770
|
+
[options.endpoint, "--endpoint"],
|
|
771
|
+
[options.rebuild, "--rebuild"],
|
|
772
|
+
[options.drop, "--drop"],
|
|
773
|
+
[options.resetPaths, "--reset-paths"],
|
|
774
|
+
[options.globs?.length, "--glob"],
|
|
775
|
+
[options.insensitiveGlobs?.length, "--iglob"],
|
|
776
|
+
[options.fileTypes?.length, "--type"],
|
|
777
|
+
[options.excludedFileTypes?.length, "--type-not"],
|
|
778
|
+
[options.hidden, "--hidden"],
|
|
779
|
+
[options.noIgnore, "--no-ignore"],
|
|
780
|
+
[options.ignoreFiles?.length, "--ignore-file"],
|
|
781
|
+
[options.maxDepth, "--max-depth"],
|
|
782
|
+
[options.maxFileSizeBytes, "--max-filesize"],
|
|
783
|
+
[options.follow, "--follow"],
|
|
784
|
+
]);
|
|
785
|
+
if (unsupported) {
|
|
786
|
+
throw new Error(`${unsupported} is not supported with zg --${command}`);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (options.yes &&
|
|
790
|
+
command !== "install" &&
|
|
791
|
+
command !== "uninstall" &&
|
|
792
|
+
!(command === "index" && options.drop)) {
|
|
793
|
+
throw new Error("--yes is only valid for --install, --uninstall, or --index --drop");
|
|
794
|
+
}
|
|
795
|
+
if (options.drop && command !== "index") {
|
|
796
|
+
throw new Error("--drop can only be used with zg --index");
|
|
797
|
+
}
|
|
798
|
+
if (options.rebuild && command !== "index") {
|
|
799
|
+
throw new Error("--rebuild can only be used with zg --index");
|
|
800
|
+
}
|
|
801
|
+
if (options.resetPaths && command !== "index") {
|
|
802
|
+
throw new Error("--reset-paths can only be used with zg --index");
|
|
803
|
+
}
|
|
804
|
+
if (options.drop &&
|
|
805
|
+
(options.rebuild ||
|
|
806
|
+
options.resetPaths ||
|
|
807
|
+
options.home ||
|
|
808
|
+
options.embedding ||
|
|
809
|
+
options.modelCacheDir ||
|
|
810
|
+
options.device !== undefined ||
|
|
811
|
+
options.apiKey ||
|
|
812
|
+
options.endpoint ||
|
|
813
|
+
options.globs?.length ||
|
|
814
|
+
options.insensitiveGlobs?.length ||
|
|
815
|
+
options.fileTypes?.length ||
|
|
816
|
+
options.excludedFileTypes?.length ||
|
|
817
|
+
options.hidden ||
|
|
818
|
+
options.noIgnore ||
|
|
819
|
+
options.ignoreFiles?.length ||
|
|
820
|
+
options.maxDepth !== undefined ||
|
|
821
|
+
options.maxFileSizeBytes !== undefined ||
|
|
822
|
+
options.debug ||
|
|
823
|
+
options.follow ||
|
|
824
|
+
options.embeddingConcurrency)) {
|
|
825
|
+
throw new Error("zg --index --drop cannot be combined with indexing options");
|
|
826
|
+
}
|
|
827
|
+
if (command === "query") {
|
|
828
|
+
const unsupported = firstEnabledOption([
|
|
829
|
+
[options.embedding, "--embedding"],
|
|
830
|
+
[options.endpoint, "--endpoint"],
|
|
831
|
+
]);
|
|
832
|
+
if (unsupported) {
|
|
833
|
+
throw new Error(`${unsupported} is not supported while searching`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (command === "query" && !options.rg) {
|
|
837
|
+
const queryCount = positionals.length +
|
|
838
|
+
(options.hybridQueries?.length ?? 0) +
|
|
839
|
+
(options.routes?.length ?? 0);
|
|
840
|
+
if (queryCount === 0) {
|
|
841
|
+
throw new Error("zg requires a query or --hybrid/--fts/--vector route");
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
function firstEnabledOption(candidates) {
|
|
846
|
+
return candidates.find(([value]) => Array.isArray(value) ? value.length > 0 : value !== undefined)?.[1];
|
|
847
|
+
}
|
|
848
|
+
function parseClientMode(value) {
|
|
849
|
+
if (value === "direct" || value === "server" || value === "auto")
|
|
850
|
+
return value;
|
|
851
|
+
throw new Error("--mode must be direct, server, or auto");
|
|
852
|
+
}
|
|
853
|
+
function parseQueryRefreshMode(value) {
|
|
854
|
+
if (value === "background" || value === "wait" || value === "off") {
|
|
855
|
+
return value;
|
|
856
|
+
}
|
|
857
|
+
throw new Error("--refresh must be background, wait, or off");
|
|
858
|
+
}
|
|
859
|
+
function allowRemoteValueError() {
|
|
860
|
+
return new Error([
|
|
861
|
+
"--allow-remote does not accept a value.",
|
|
862
|
+
"It authorizes Remote Embedding for the current command only.",
|
|
863
|
+
"For persistent authorization, use:",
|
|
864
|
+
" zg --auth grant --capability embedding --scope workspace",
|
|
865
|
+
].join("\n"));
|
|
866
|
+
}
|
|
867
|
+
function parseAuthorizationCapability(value) {
|
|
868
|
+
if (value === "embedding")
|
|
869
|
+
return value;
|
|
870
|
+
throw new Error("--capability currently supports only embedding");
|
|
871
|
+
}
|
|
872
|
+
function parseAuthorizationScope(value) {
|
|
873
|
+
if (value === "workspace")
|
|
874
|
+
return value;
|
|
875
|
+
throw new Error("zg --auth supports only workspace scope");
|
|
876
|
+
}
|
|
877
|
+
function readOptionValue(args, index, option) {
|
|
878
|
+
const value = args[index];
|
|
879
|
+
if (value === undefined || value.length === 0) {
|
|
880
|
+
throw new Error(`${option} requires a value`);
|
|
881
|
+
}
|
|
882
|
+
return value;
|
|
883
|
+
}
|
|
884
|
+
function isLongOptionWithValue(arg, option) {
|
|
885
|
+
return arg.startsWith(`${option}=`);
|
|
886
|
+
}
|
|
887
|
+
function valueFromLongOption(arg) {
|
|
888
|
+
const separator = arg.indexOf("=");
|
|
889
|
+
return separator >= 0 ? arg.slice(separator + 1) : "";
|
|
890
|
+
}
|
|
891
|
+
function optionNameFromLong(arg) {
|
|
892
|
+
const separator = arg.indexOf("=");
|
|
893
|
+
return separator >= 0 ? arg.slice(0, separator) : arg;
|
|
894
|
+
}
|
|
895
|
+
function isRgFlagWithValue(arg) {
|
|
896
|
+
const option = optionNameFromLong(arg);
|
|
897
|
+
return arg.includes("=") && RG_OPTIONS_WITH_VALUE.has(option);
|
|
898
|
+
}
|
|
899
|
+
function isManagedRgOutputOption(arg) {
|
|
900
|
+
const option = optionNameFromLong(arg);
|
|
901
|
+
return MANAGED_RG_OUTPUT_OPTIONS.has(option);
|
|
902
|
+
}
|
|
903
|
+
function isShortRgOptionGroup(arg) {
|
|
904
|
+
return /^-[A-Za-z].*$/.test(arg) && arg !== "-h";
|
|
905
|
+
}
|
|
906
|
+
function parseShortRgOptionGroup(args, index, options) {
|
|
907
|
+
const arg = args[index];
|
|
908
|
+
for (let offset = 1; offset < arg.length; offset++) {
|
|
909
|
+
const option = arg[offset];
|
|
910
|
+
const flag = `-${option}`;
|
|
911
|
+
switch (option) {
|
|
912
|
+
case "n":
|
|
913
|
+
case "H":
|
|
914
|
+
markRgCompatibilityOption(options, flag);
|
|
915
|
+
break;
|
|
916
|
+
case "F":
|
|
917
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [flag]);
|
|
918
|
+
markRgCompatibilityOption(options, flag);
|
|
919
|
+
break;
|
|
920
|
+
case "i":
|
|
921
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [flag]);
|
|
922
|
+
markRgCompatibilityOption(options, flag);
|
|
923
|
+
break;
|
|
924
|
+
case "w":
|
|
925
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [flag]);
|
|
926
|
+
markRgCompatibilityOption(options, flag);
|
|
927
|
+
break;
|
|
928
|
+
case "P":
|
|
929
|
+
case "S":
|
|
930
|
+
case "s":
|
|
931
|
+
case "a":
|
|
932
|
+
case "u":
|
|
933
|
+
case "U":
|
|
934
|
+
case "v":
|
|
935
|
+
case "x":
|
|
936
|
+
case "z":
|
|
937
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [flag]);
|
|
938
|
+
markRgCompatibilityOption(options, flag);
|
|
939
|
+
break;
|
|
940
|
+
case "L":
|
|
941
|
+
options.follow = true;
|
|
942
|
+
break;
|
|
943
|
+
case "e": {
|
|
944
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
945
|
+
options.rgOptions = appendRgPattern(options.rgOptions, value.value);
|
|
946
|
+
markRgCompatibilityOption(options, flag);
|
|
947
|
+
return value.nextIndex;
|
|
948
|
+
}
|
|
949
|
+
case "g": {
|
|
950
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
951
|
+
options.globs = appendValue(options.globs, value.value, flag);
|
|
952
|
+
return value.nextIndex;
|
|
953
|
+
}
|
|
954
|
+
case "E": {
|
|
955
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
956
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [
|
|
957
|
+
flag,
|
|
958
|
+
value.value,
|
|
959
|
+
]);
|
|
960
|
+
markRgCompatibilityOption(options, flag);
|
|
961
|
+
return value.nextIndex;
|
|
962
|
+
}
|
|
963
|
+
case "t":
|
|
964
|
+
case "T": {
|
|
965
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
966
|
+
if (option === "t") {
|
|
967
|
+
options.fileTypes = appendValue(options.fileTypes, value.value, flag);
|
|
968
|
+
}
|
|
969
|
+
else {
|
|
970
|
+
options.excludedFileTypes = appendValue(options.excludedFileTypes, value.value, flag);
|
|
971
|
+
}
|
|
972
|
+
return value.nextIndex;
|
|
973
|
+
}
|
|
974
|
+
case "f": {
|
|
975
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
976
|
+
options.rgOptions = appendRgPatternFile(options.rgOptions, value.value, flag);
|
|
977
|
+
markRgCompatibilityOption(options, flag);
|
|
978
|
+
return value.nextIndex;
|
|
979
|
+
}
|
|
980
|
+
case "m": {
|
|
981
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
982
|
+
parseNonNegativeInteger(value.value, flag);
|
|
983
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [
|
|
984
|
+
flag,
|
|
985
|
+
value.value,
|
|
986
|
+
]);
|
|
987
|
+
markRgCompatibilityOption(options, flag);
|
|
988
|
+
return value.nextIndex;
|
|
989
|
+
}
|
|
990
|
+
case "j": {
|
|
991
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
992
|
+
parseNonNegativeInteger(value.value, flag);
|
|
993
|
+
options.rgOptions = appendRgExtraArgs(options.rgOptions, [
|
|
994
|
+
flag,
|
|
995
|
+
value.value,
|
|
996
|
+
]);
|
|
997
|
+
markRgCompatibilityOption(options, flag);
|
|
998
|
+
return value.nextIndex;
|
|
999
|
+
}
|
|
1000
|
+
case "A":
|
|
1001
|
+
case "B":
|
|
1002
|
+
case "C": {
|
|
1003
|
+
const value = readShortOptionValue(args, index, offset, arg, flag);
|
|
1004
|
+
const direction = option === "A" ? "after" : option === "B" ? "before" : "both";
|
|
1005
|
+
options.rgOptions = setRgContext(options.rgOptions, direction, value.value, flag);
|
|
1006
|
+
markRgCompatibilityOption(options, flag);
|
|
1007
|
+
return value.nextIndex;
|
|
1008
|
+
}
|
|
1009
|
+
default:
|
|
1010
|
+
if (isManagedRgOutputOption(flag)) {
|
|
1011
|
+
throw new Error(`${flag} changes rg output and cannot be used with managed --rg`);
|
|
1012
|
+
}
|
|
1013
|
+
throw new Error(`Unsupported --rg option: ${flag}`);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
return index;
|
|
1017
|
+
}
|
|
1018
|
+
function readShortOptionValue(args, index, offset, arg, option) {
|
|
1019
|
+
const inline = arg.slice(offset + 1);
|
|
1020
|
+
if (inline.length > 0) {
|
|
1021
|
+
return {
|
|
1022
|
+
value: inline,
|
|
1023
|
+
nextIndex: index,
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
return {
|
|
1027
|
+
value: readOptionValue(args, index + 1, option),
|
|
1028
|
+
nextIndex: index + 1,
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
function markRgCompatibilityOption(options, option) {
|
|
1032
|
+
options.rgCompatibilityOptions = [
|
|
1033
|
+
...(options.rgCompatibilityOptions ?? []),
|
|
1034
|
+
option,
|
|
1035
|
+
];
|
|
1036
|
+
}
|
|
1037
|
+
function appendRgPattern(existing, value) {
|
|
1038
|
+
return {
|
|
1039
|
+
...(existing ?? {}),
|
|
1040
|
+
patterns: [...(existing?.patterns ?? []), value],
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
function appendRgPatternFile(existing, value, option) {
|
|
1044
|
+
return {
|
|
1045
|
+
...(existing ?? {}),
|
|
1046
|
+
patternFiles: appendValue(existing?.patternFiles, value, option),
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function appendInstallTargets(existing, value) {
|
|
1050
|
+
const targets = value
|
|
1051
|
+
.split(/[,\s]+/)
|
|
1052
|
+
.map((target) => target.trim())
|
|
1053
|
+
.filter((target) => target.length > 0);
|
|
1054
|
+
if (targets.length === 0) {
|
|
1055
|
+
throw new Error("--target requires at least one agent name");
|
|
1056
|
+
}
|
|
1057
|
+
return [...(existing ?? []), ...targets];
|
|
1058
|
+
}
|
|
1059
|
+
function setRgContext(existing, direction, value, option) {
|
|
1060
|
+
const parsed = parseNonNegativeInteger(value, option);
|
|
1061
|
+
return {
|
|
1062
|
+
...(existing ?? {}),
|
|
1063
|
+
beforeContext: direction === "before" || direction === "both"
|
|
1064
|
+
? parsed
|
|
1065
|
+
: existing?.beforeContext,
|
|
1066
|
+
afterContext: direction === "after" || direction === "both"
|
|
1067
|
+
? parsed
|
|
1068
|
+
: existing?.afterContext,
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
function appendRgExtraArgs(existing, args) {
|
|
1072
|
+
return {
|
|
1073
|
+
...(existing ?? {}),
|
|
1074
|
+
extraArgs: [...(existing?.extraArgs ?? []), ...args],
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
function parsePositiveInteger(value, option) {
|
|
1078
|
+
if (!/^\d+$/.test(value)) {
|
|
1079
|
+
throw new Error(`${option} requires a positive integer`);
|
|
1080
|
+
}
|
|
1081
|
+
const parsed = Number(value);
|
|
1082
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1) {
|
|
1083
|
+
throw new Error(`${option} requires a positive integer`);
|
|
1084
|
+
}
|
|
1085
|
+
return parsed;
|
|
1086
|
+
}
|
|
1087
|
+
function parseEnvironmentVariable(value, option) {
|
|
1088
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(value)) {
|
|
1089
|
+
throw new Error(`${option} requires a valid environment variable name`);
|
|
1090
|
+
}
|
|
1091
|
+
return value;
|
|
1092
|
+
}
|
|
1093
|
+
function parseMcpInstallTransport(value) {
|
|
1094
|
+
if (value === "stdio" || value === "http")
|
|
1095
|
+
return value;
|
|
1096
|
+
throw new Error("--mcp-transport must be stdio or http");
|
|
1097
|
+
}
|
|
1098
|
+
function parseByteSize(value, option) {
|
|
1099
|
+
const match = value.trim().match(/^(\d+)([KMGT])?$/i);
|
|
1100
|
+
if (!match) {
|
|
1101
|
+
throw new Error(`${option} requires bytes or an integer K/M/G/T size`);
|
|
1102
|
+
}
|
|
1103
|
+
const amount = Number.parseInt(match[1], 10);
|
|
1104
|
+
const suffix = match[2]?.toUpperCase();
|
|
1105
|
+
const multiplier = suffix === "K"
|
|
1106
|
+
? 1024
|
|
1107
|
+
: suffix === "M"
|
|
1108
|
+
? 1024 ** 2
|
|
1109
|
+
: suffix === "G"
|
|
1110
|
+
? 1024 ** 3
|
|
1111
|
+
: suffix === "T"
|
|
1112
|
+
? 1024 ** 4
|
|
1113
|
+
: 1;
|
|
1114
|
+
const bytes = amount * multiplier;
|
|
1115
|
+
if (!Number.isSafeInteger(bytes)) {
|
|
1116
|
+
throw new Error(`${option} is too large`);
|
|
1117
|
+
}
|
|
1118
|
+
return bytes;
|
|
1119
|
+
}
|
|
1120
|
+
function parseNonNegativeInteger(value, option) {
|
|
1121
|
+
if (!/^\d+$/.test(value)) {
|
|
1122
|
+
throw new Error(`${option} requires a non-negative integer`);
|
|
1123
|
+
}
|
|
1124
|
+
const parsed = Number(value);
|
|
1125
|
+
if (!Number.isSafeInteger(parsed)) {
|
|
1126
|
+
throw new Error(`${option} requires a non-negative integer`);
|
|
1127
|
+
}
|
|
1128
|
+
return parsed;
|
|
1129
|
+
}
|
|
1130
|
+
function parseColorMode(value) {
|
|
1131
|
+
if (value === "auto" || value === "always" || value === "never") {
|
|
1132
|
+
return value;
|
|
1133
|
+
}
|
|
1134
|
+
throw new Error(`Unsupported color mode: ${value}`);
|
|
1135
|
+
}
|
|
1136
|
+
function parsePreviewMode(value) {
|
|
1137
|
+
if (value === "none" || value === "short" || value === "full") {
|
|
1138
|
+
return value;
|
|
1139
|
+
}
|
|
1140
|
+
throw new Error(`Unsupported preview mode: ${value}`);
|
|
1141
|
+
}
|
|
1142
|
+
export function parseDevice(value) {
|
|
1143
|
+
const normalized = value.trim().toLowerCase();
|
|
1144
|
+
if (normalized === "auto" ||
|
|
1145
|
+
normalized === "cpu" ||
|
|
1146
|
+
normalized === "metal" ||
|
|
1147
|
+
normalized === "vulkan" ||
|
|
1148
|
+
normalized === "cuda") {
|
|
1149
|
+
return normalized;
|
|
1150
|
+
}
|
|
1151
|
+
throw new Error(`Unsupported device: ${value}`);
|
|
1152
|
+
}
|
|
1153
|
+
function hasExplicitRoutes(options) {
|
|
1154
|
+
return (options.routes?.length ?? 0) > 0;
|
|
1155
|
+
}
|
|
1156
|
+
function appendRoute(existing, mode, query, option) {
|
|
1157
|
+
const normalized = query.trim();
|
|
1158
|
+
if (!normalized) {
|
|
1159
|
+
throw new Error(`${option} requires a non-empty query`);
|
|
1160
|
+
}
|
|
1161
|
+
return [...(existing ?? []), { mode, query: normalized }];
|
|
1162
|
+
}
|
|
1163
|
+
function appendQuery(existing, query, option) {
|
|
1164
|
+
const normalized = query.trim();
|
|
1165
|
+
if (!normalized) {
|
|
1166
|
+
throw new Error(`${option} requires a non-empty query`);
|
|
1167
|
+
}
|
|
1168
|
+
return [...(existing ?? []), normalized];
|
|
1169
|
+
}
|
|
1170
|
+
function parseSymbolType(value) {
|
|
1171
|
+
if (VALID_SYMBOL_TYPES.has(value)) {
|
|
1172
|
+
return value;
|
|
1173
|
+
}
|
|
1174
|
+
throw new Error(`Unsupported symbol type: ${value}`);
|
|
1175
|
+
}
|
|
1176
|
+
export function splitPathFilters(value) {
|
|
1177
|
+
const filters = [];
|
|
1178
|
+
let start = 0;
|
|
1179
|
+
let braceDepth = 0;
|
|
1180
|
+
let bracketDepth = 0;
|
|
1181
|
+
let escaped = false;
|
|
1182
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
1183
|
+
const character = value[index];
|
|
1184
|
+
if (escaped) {
|
|
1185
|
+
escaped = false;
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
if (character === "\\") {
|
|
1189
|
+
escaped = true;
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
if (character === "[") {
|
|
1193
|
+
bracketDepth += 1;
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
if (character === "]" && bracketDepth > 0) {
|
|
1197
|
+
bracketDepth -= 1;
|
|
1198
|
+
continue;
|
|
1199
|
+
}
|
|
1200
|
+
if (bracketDepth === 0 && character === "{") {
|
|
1201
|
+
braceDepth += 1;
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
if (bracketDepth === 0 && character === "}" && braceDepth > 0) {
|
|
1205
|
+
braceDepth -= 1;
|
|
1206
|
+
continue;
|
|
1207
|
+
}
|
|
1208
|
+
if (character !== "," || braceDepth > 0 || bracketDepth > 0) {
|
|
1209
|
+
continue;
|
|
1210
|
+
}
|
|
1211
|
+
const filter = value.slice(start, index).trim();
|
|
1212
|
+
if (filter.length > 0) {
|
|
1213
|
+
filters.push(filter);
|
|
1214
|
+
}
|
|
1215
|
+
start = index + 1;
|
|
1216
|
+
}
|
|
1217
|
+
const finalFilter = value.slice(start).trim();
|
|
1218
|
+
if (finalFilter.length > 0) {
|
|
1219
|
+
filters.push(finalFilter);
|
|
1220
|
+
}
|
|
1221
|
+
return filters;
|
|
1222
|
+
}
|
|
1223
|
+
function appendValue(existing, value, option) {
|
|
1224
|
+
const normalized = value.trim();
|
|
1225
|
+
if (!normalized) {
|
|
1226
|
+
throw new Error(`${option} requires a non-empty value`);
|
|
1227
|
+
}
|
|
1228
|
+
return [...(existing ?? []), normalized];
|
|
1229
|
+
}
|
|
1230
|
+
export function parseModifiedTime(value, option) {
|
|
1231
|
+
if (/^\d+$/.test(value)) {
|
|
1232
|
+
const parsed = Number.parseInt(value, 10);
|
|
1233
|
+
if (Number.isSafeInteger(parsed) && parsed >= 0) {
|
|
1234
|
+
return parsed;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
const dateOnly = value.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
1238
|
+
if (dateOnly) {
|
|
1239
|
+
const year = Number.parseInt(dateOnly[1], 10);
|
|
1240
|
+
const month = Number.parseInt(dateOnly[2], 10);
|
|
1241
|
+
const day = Number.parseInt(dateOnly[3], 10);
|
|
1242
|
+
const date = new Date(year, month - 1, day);
|
|
1243
|
+
if (date.getFullYear() === year &&
|
|
1244
|
+
date.getMonth() === month - 1 &&
|
|
1245
|
+
date.getDate() === day) {
|
|
1246
|
+
return date.getTime();
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
const parsed = Date.parse(value);
|
|
1250
|
+
if (Number.isFinite(parsed)) {
|
|
1251
|
+
return parsed;
|
|
1252
|
+
}
|
|
1253
|
+
throw new Error(`${option} requires an epoch millisecond value or a parseable date`);
|
|
1254
|
+
}
|
|
1255
|
+
//# sourceMappingURL=args.js.map
|