@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
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
import { EngineError } from "../../errors.js";
|
|
2
|
+
import { COMPONENT_CODE_FORMATS } from "../../code-formats.js";
|
|
3
|
+
import { makeEntityId } from "../ids.js";
|
|
4
|
+
import { validateSourceFile } from "../source.js";
|
|
5
|
+
import { hasGrammar } from "./tree-sitter/grammar.js";
|
|
6
|
+
import { withParser } from "./tree-sitter/parser.js";
|
|
7
|
+
import { extractPlainTextFragments } from "../text/extractor.js";
|
|
8
|
+
import { chunkOptionsForMetadata } from "../vector-content.js";
|
|
9
|
+
import { resolveAdapter } from "./adapter.js";
|
|
10
|
+
import { hasJavascriptTypescriptFunctionValue } from "./families/js-ts.js";
|
|
11
|
+
const DEFAULT_CODE_CHUNK_CHARS = 3600;
|
|
12
|
+
const DEFAULT_CODE_CHUNK_OVERLAP_CHARS = 540;
|
|
13
|
+
const COMPONENT_CODE_FORMAT_SET = new Set(COMPONENT_CODE_FORMATS);
|
|
14
|
+
export class CodeExtractor {
|
|
15
|
+
async extract(source, options = {}) {
|
|
16
|
+
return (await this.extractForIndexing(source, options)).map((item) => item.fragment);
|
|
17
|
+
}
|
|
18
|
+
async extractForIndexing(source, options = {}) {
|
|
19
|
+
if (source.kind !== "text" || source.file.kind !== "code") {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
validateSourceFile(source);
|
|
23
|
+
const chunkOptions = resolveCodeChunkOptions(options);
|
|
24
|
+
if (isScriptBlockFormat(source.file.format)) {
|
|
25
|
+
const fragments = await this.extractScriptBlocks(source, chunkOptions);
|
|
26
|
+
return fragments.length > 0
|
|
27
|
+
? fragments
|
|
28
|
+
: this.fallback(source, chunkOptions);
|
|
29
|
+
}
|
|
30
|
+
const adapter = resolveAdapter(source.file.format);
|
|
31
|
+
if (!hasGrammar(source.file.format) || !adapter) {
|
|
32
|
+
return this.fallback(source, chunkOptions);
|
|
33
|
+
}
|
|
34
|
+
const extracted = await withParser(source.text, source.file.format, (tree) => {
|
|
35
|
+
const collected = [];
|
|
36
|
+
walkCodeNode(tree.rootNode, adapter, [], collected);
|
|
37
|
+
const output = [];
|
|
38
|
+
let entityIdIndex = 0;
|
|
39
|
+
const appendEntity = (entity) => {
|
|
40
|
+
const fragments = codeEntityToSearchFragments(source, adapter, entity, chunkOptions.maxChunkChars, chunkOptions.chunkOverlapChars);
|
|
41
|
+
const majorId = fragments[0]?.group === ""
|
|
42
|
+
? makeEntityId(source.file.id, entityIdIndex)
|
|
43
|
+
: null;
|
|
44
|
+
for (const item of fragments) {
|
|
45
|
+
const id = makeEntityId(source.file.id, entityIdIndex);
|
|
46
|
+
const { embeddingText, ...fragment } = item;
|
|
47
|
+
output.push({
|
|
48
|
+
fragment: {
|
|
49
|
+
id,
|
|
50
|
+
...fragment,
|
|
51
|
+
group: fragment.group === "" ? id : (majorId ?? fragment.group),
|
|
52
|
+
},
|
|
53
|
+
embeddingText,
|
|
54
|
+
});
|
|
55
|
+
entityIdIndex++;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
for (const entity of collected) {
|
|
59
|
+
appendEntity(entity);
|
|
60
|
+
}
|
|
61
|
+
return output;
|
|
62
|
+
});
|
|
63
|
+
if (!extracted || extracted.length === 0) {
|
|
64
|
+
return this.fallback(source, chunkOptions);
|
|
65
|
+
}
|
|
66
|
+
return extracted;
|
|
67
|
+
}
|
|
68
|
+
fallback(source, options) {
|
|
69
|
+
return extractPlainTextFragments(source, options.maxChunkChars, options.chunkOverlapChars).map((fragment) => ({ fragment }));
|
|
70
|
+
}
|
|
71
|
+
async extractScriptBlocks(source, options) {
|
|
72
|
+
const fragments = [];
|
|
73
|
+
for (const block of findScriptBlocks(source.text)) {
|
|
74
|
+
const blockFile = {
|
|
75
|
+
...source.file,
|
|
76
|
+
format: block.format,
|
|
77
|
+
};
|
|
78
|
+
const blockFragments = await this.extractForIndexing({
|
|
79
|
+
kind: "text",
|
|
80
|
+
file: blockFile,
|
|
81
|
+
text: block.text,
|
|
82
|
+
}, options);
|
|
83
|
+
fragments.push(...remapScriptBlockFragments(source.file.id, blockFragments, fragments.length, block.startLine, block.startOffset));
|
|
84
|
+
}
|
|
85
|
+
return fragments;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function resolveCodeChunkOptions(options) {
|
|
89
|
+
const maxChunkChars = options.maxChunkChars ?? DEFAULT_CODE_CHUNK_CHARS;
|
|
90
|
+
const chunkOverlapChars = options.chunkOverlapChars ?? DEFAULT_CODE_CHUNK_OVERLAP_CHARS;
|
|
91
|
+
if (!Number.isInteger(maxChunkChars) || maxChunkChars <= 0) {
|
|
92
|
+
throw new EngineError("Code extractor requires a positive integer chunk size", {
|
|
93
|
+
code: "ZVEC_GREP.ENGINE.EXTRACTORS.CODE_INVALID_CHUNK_SIZE",
|
|
94
|
+
context: `maxChunkChars=${maxChunkChars}`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (!Number.isInteger(chunkOverlapChars) ||
|
|
98
|
+
chunkOverlapChars < 0 ||
|
|
99
|
+
chunkOverlapChars >= maxChunkChars) {
|
|
100
|
+
throw new EngineError("Code extractor requires overlap to be smaller than chunk size", {
|
|
101
|
+
code: "ZVEC_GREP.ENGINE.EXTRACTORS.CODE_INVALID_CHUNK_OVERLAP",
|
|
102
|
+
context: `maxChunkChars=${maxChunkChars} chunkOverlapChars=${chunkOverlapChars}`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return { maxChunkChars, chunkOverlapChars };
|
|
106
|
+
}
|
|
107
|
+
function walkCodeNode(node, adapter, breadcrumb, out) {
|
|
108
|
+
for (const child of node.children) {
|
|
109
|
+
const isScope = adapter.scopeTypes.has(child.type) &&
|
|
110
|
+
adapter.shouldEnterScope?.(child) !== false;
|
|
111
|
+
const isEntity = adapter.entityTypes.has(child.type) &&
|
|
112
|
+
adapter.shouldIndexEntity?.(child) !== false;
|
|
113
|
+
if (isEntity) {
|
|
114
|
+
const entities = adapter.resolveEntities?.(child) ?? [
|
|
115
|
+
adapter.resolveEntity ? adapter.resolveEntity(child) : child,
|
|
116
|
+
];
|
|
117
|
+
for (const entity of entities) {
|
|
118
|
+
const name = adapter.extractName(entity);
|
|
119
|
+
const entityBreadcrumb = adapter.scopeBreadcrumb?.(entity, breadcrumb) ?? breadcrumb;
|
|
120
|
+
const symbolType = adapter.classifyNode?.(entity, entityBreadcrumb) ??
|
|
121
|
+
classifyCodeNode(entity, entityBreadcrumb);
|
|
122
|
+
out.push({
|
|
123
|
+
node: entity,
|
|
124
|
+
name,
|
|
125
|
+
symbolType,
|
|
126
|
+
breadcrumb: entityBreadcrumb,
|
|
127
|
+
signature: adapter.extractSignature?.(entity),
|
|
128
|
+
doc: adapter.extractDoc?.(entity),
|
|
129
|
+
modifiers: adapter.extractModifiers?.(entity) ?? [],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (isScope) {
|
|
134
|
+
const name = adapter.extractName(child);
|
|
135
|
+
const scopeNode = adapter.enterScopeNode?.(child) ?? child;
|
|
136
|
+
walkCodeNode(scopeNode, adapter, name ? [...breadcrumb, name] : breadcrumb, out);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (!isEntity) {
|
|
140
|
+
walkCodeNode(child, adapter, breadcrumb, out);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function codeEntityToSearchFragments(source, adapter, entity, maxChars, overlapChars) {
|
|
145
|
+
const metadata = codeEntityMetadata(entity);
|
|
146
|
+
const contentChunkOptions = chunkOptionsForMetadata({ maxChunkChars: maxChars, chunkOverlapChars: overlapChars }, metadata);
|
|
147
|
+
const contentMaxChars = contentChunkOptions.maxChunkChars;
|
|
148
|
+
if (entity.node.text.length <= contentMaxChars) {
|
|
149
|
+
return [
|
|
150
|
+
codeEntityWindowToFragment(source, entity, nodeToWindow(entity.node)),
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
const major = {
|
|
154
|
+
group: "",
|
|
155
|
+
fileId: source.file.id,
|
|
156
|
+
range: nodeToWindow(entity.node).range,
|
|
157
|
+
content: {
|
|
158
|
+
kind: "text",
|
|
159
|
+
text: codeEntityOutline(entity, adapter, contentMaxChars),
|
|
160
|
+
},
|
|
161
|
+
metadata,
|
|
162
|
+
};
|
|
163
|
+
return [
|
|
164
|
+
major,
|
|
165
|
+
...[
|
|
166
|
+
...splitLargeNode(entity.node, contentMaxChars, contentChunkOptions.chunkOverlapChars),
|
|
167
|
+
].map((window) => codeEntityWindowToFragment(source, entity, window)),
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
function codeEntityWindowToFragment(source, entity, window) {
|
|
171
|
+
return {
|
|
172
|
+
fileId: source.file.id,
|
|
173
|
+
range: window.range,
|
|
174
|
+
content: {
|
|
175
|
+
kind: "text",
|
|
176
|
+
text: window.text,
|
|
177
|
+
},
|
|
178
|
+
metadata: codeEntityMetadata(entity),
|
|
179
|
+
embeddingText: window.embeddingText,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function nodeToWindow(node) {
|
|
183
|
+
return {
|
|
184
|
+
text: node.text,
|
|
185
|
+
range: {
|
|
186
|
+
kind: "text",
|
|
187
|
+
startLine: node.startPosition.row + 1,
|
|
188
|
+
endLine: node.endPosition.row + 1,
|
|
189
|
+
startOffset: node.startIndex,
|
|
190
|
+
endOffset: node.endIndex,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function* splitLargeNode(node, maxChars, overlapChars) {
|
|
195
|
+
const body = node.childForFieldName("body") ?? node;
|
|
196
|
+
const statements = body.namedChildren;
|
|
197
|
+
if (statements.length <= 1) {
|
|
198
|
+
yield* splitTextByLines(node.text, maxChars, node.startPosition.row + 1, node.startIndex, overlapChars);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const baseStart = node.startIndex;
|
|
202
|
+
const source = node.text;
|
|
203
|
+
let groupStart = 0;
|
|
204
|
+
let groupChars = 0;
|
|
205
|
+
for (let index = 0; index < statements.length; index++) {
|
|
206
|
+
const statement = statements[index];
|
|
207
|
+
const statementChars = statement.text.length;
|
|
208
|
+
if (statementChars > maxChars) {
|
|
209
|
+
if (index > groupStart) {
|
|
210
|
+
yield sliceStatements(source, baseStart, statements, groupStart, index - 1);
|
|
211
|
+
}
|
|
212
|
+
yield* splitTextByLines(statement.text, maxChars, statement.startPosition.row + 1, statement.startIndex, overlapChars);
|
|
213
|
+
groupStart = index + 1;
|
|
214
|
+
groupChars = 0;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
const separatorChars = index > groupStart ? 1 : 0;
|
|
218
|
+
if (groupChars + separatorChars + statementChars > maxChars &&
|
|
219
|
+
index > groupStart) {
|
|
220
|
+
yield sliceStatements(source, baseStart, statements, groupStart, index - 1);
|
|
221
|
+
const overlapStart = computeOverlapStart(statements, groupStart, index - 1, overlapChars);
|
|
222
|
+
let candidateStart = overlapStart < index ? overlapStart : index;
|
|
223
|
+
let candidateChars = statementChars;
|
|
224
|
+
for (let previous = index - 1; previous >= candidateStart; previous--) {
|
|
225
|
+
const addedChars = statements[previous].text.length + 1;
|
|
226
|
+
if (candidateChars + addedChars > maxChars) {
|
|
227
|
+
candidateStart = previous + 1;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
candidateChars += addedChars;
|
|
231
|
+
}
|
|
232
|
+
groupStart = candidateStart;
|
|
233
|
+
groupChars = candidateChars;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
groupChars += separatorChars + statementChars;
|
|
237
|
+
}
|
|
238
|
+
if (groupStart < statements.length) {
|
|
239
|
+
yield sliceStatements(source, baseStart, statements, groupStart, statements.length - 1);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function sliceStatements(source, baseStart, statements, startIndex, endIndex) {
|
|
243
|
+
const start = statements[startIndex].startIndex;
|
|
244
|
+
const end = statements[endIndex].endIndex;
|
|
245
|
+
return {
|
|
246
|
+
text: source.slice(start - baseStart, end - baseStart),
|
|
247
|
+
embeddingText: statements
|
|
248
|
+
.slice(startIndex, endIndex + 1)
|
|
249
|
+
.map((statement) => statement.text)
|
|
250
|
+
.join("\n"),
|
|
251
|
+
range: {
|
|
252
|
+
kind: "text",
|
|
253
|
+
startLine: statements[startIndex].startPosition.row + 1,
|
|
254
|
+
endLine: statements[endIndex].endPosition.row + 1,
|
|
255
|
+
startOffset: start,
|
|
256
|
+
endOffset: end,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function* splitTextByLines(text, maxChars, startLine, startOffset, overlapChars) {
|
|
261
|
+
const lines = text.split("\n");
|
|
262
|
+
let lineIndex = 0;
|
|
263
|
+
let offset = startOffset;
|
|
264
|
+
while (lineIndex < lines.length) {
|
|
265
|
+
if (lines[lineIndex].length > maxChars) {
|
|
266
|
+
yield* splitLongLineByChars(lines[lineIndex], maxChars, startLine + lineIndex, offset, overlapChars);
|
|
267
|
+
offset += lines[lineIndex].length + 1;
|
|
268
|
+
lineIndex++;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
let endIndex = lineIndex;
|
|
272
|
+
let usedChars = 0;
|
|
273
|
+
while (endIndex < lines.length) {
|
|
274
|
+
const lineLength = lines[endIndex].length + 1;
|
|
275
|
+
if (usedChars + lineLength > maxChars && endIndex > lineIndex) {
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
usedChars += lineLength;
|
|
279
|
+
endIndex++;
|
|
280
|
+
}
|
|
281
|
+
const chunk = lines.slice(lineIndex, endIndex).join("\n");
|
|
282
|
+
yield {
|
|
283
|
+
text: chunk,
|
|
284
|
+
range: {
|
|
285
|
+
kind: "text",
|
|
286
|
+
startLine: startLine + lineIndex,
|
|
287
|
+
endLine: startLine + endIndex - 1,
|
|
288
|
+
startOffset: offset,
|
|
289
|
+
endOffset: offset + chunk.length,
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
if (endIndex >= lines.length) {
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
const overlapLines = computeLineOverlap(lines, lineIndex, endIndex, overlapChars);
|
|
296
|
+
const nextIndex = endIndex - overlapLines;
|
|
297
|
+
offset += lines.slice(lineIndex, nextIndex).join("\n").length;
|
|
298
|
+
if (nextIndex > lineIndex) {
|
|
299
|
+
offset += 1;
|
|
300
|
+
}
|
|
301
|
+
lineIndex = nextIndex;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function* splitLongLineByChars(text, maxChars, line, startOffset, overlapChars) {
|
|
305
|
+
let relativeStart = 0;
|
|
306
|
+
while (relativeStart < text.length) {
|
|
307
|
+
const rawEnd = Math.min(text.length, relativeStart + maxChars);
|
|
308
|
+
const relativeEnd = safeCharacterEnd(text, relativeStart, rawEnd);
|
|
309
|
+
yield {
|
|
310
|
+
text: text.slice(relativeStart, relativeEnd),
|
|
311
|
+
range: {
|
|
312
|
+
kind: "text",
|
|
313
|
+
startLine: line,
|
|
314
|
+
endLine: line,
|
|
315
|
+
startOffset: startOffset + relativeStart,
|
|
316
|
+
endOffset: startOffset + relativeEnd,
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
if (relativeEnd >= text.length) {
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
const rawStart = Math.max(relativeStart + 1, relativeEnd - overlapChars);
|
|
323
|
+
relativeStart = safeCharacterStart(text, rawStart);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function safeCharacterEnd(text, start, end) {
|
|
327
|
+
if (end > start &&
|
|
328
|
+
end < text.length &&
|
|
329
|
+
isHighSurrogate(text.charCodeAt(end - 1)) &&
|
|
330
|
+
isLowSurrogate(text.charCodeAt(end))) {
|
|
331
|
+
return end - 1 > start ? end - 1 : end + 1;
|
|
332
|
+
}
|
|
333
|
+
return end;
|
|
334
|
+
}
|
|
335
|
+
function safeCharacterStart(text, start) {
|
|
336
|
+
if (start > 0 &&
|
|
337
|
+
start < text.length &&
|
|
338
|
+
isHighSurrogate(text.charCodeAt(start - 1)) &&
|
|
339
|
+
isLowSurrogate(text.charCodeAt(start))) {
|
|
340
|
+
return start + 1;
|
|
341
|
+
}
|
|
342
|
+
return start;
|
|
343
|
+
}
|
|
344
|
+
function isHighSurrogate(value) {
|
|
345
|
+
return value >= 0xd800 && value <= 0xdbff;
|
|
346
|
+
}
|
|
347
|
+
function isLowSurrogate(value) {
|
|
348
|
+
return value >= 0xdc00 && value <= 0xdfff;
|
|
349
|
+
}
|
|
350
|
+
function computeOverlapStart(statements, groupStart, groupEnd, overlapChars) {
|
|
351
|
+
if (overlapChars <= 0) {
|
|
352
|
+
return groupEnd + 1;
|
|
353
|
+
}
|
|
354
|
+
let chars = 0;
|
|
355
|
+
let index = groupEnd;
|
|
356
|
+
while (index >= groupStart && chars < overlapChars) {
|
|
357
|
+
chars += statements[index].text.length;
|
|
358
|
+
if (index < groupEnd) {
|
|
359
|
+
chars++;
|
|
360
|
+
}
|
|
361
|
+
index--;
|
|
362
|
+
}
|
|
363
|
+
return index + 1;
|
|
364
|
+
}
|
|
365
|
+
function computeLineOverlap(lines, startIndex, endIndex, overlapChars) {
|
|
366
|
+
if (overlapChars <= 0) {
|
|
367
|
+
return 0;
|
|
368
|
+
}
|
|
369
|
+
let chars = 0;
|
|
370
|
+
let count = 0;
|
|
371
|
+
for (let index = endIndex - 1; index >= startIndex; index--) {
|
|
372
|
+
chars += lines[index].length + 1;
|
|
373
|
+
if (chars > overlapChars) {
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
count++;
|
|
377
|
+
}
|
|
378
|
+
return Math.min(count, Math.floor((endIndex - startIndex) / 2));
|
|
379
|
+
}
|
|
380
|
+
const STRUCTURAL_SYMBOL_TYPES = new Set([
|
|
381
|
+
"class",
|
|
382
|
+
"interface",
|
|
383
|
+
"module",
|
|
384
|
+
]);
|
|
385
|
+
const OUTLINE_MAX_MEMBERS = 32;
|
|
386
|
+
const OUTLINE_MAX_CALLS = 24;
|
|
387
|
+
const OUTLINE_MAX_LINE_CHARS = 180;
|
|
388
|
+
function codeEntityOutline(entity, adapter, maxChars) {
|
|
389
|
+
const header = extractCodeHeader(entity.node.text);
|
|
390
|
+
const lines = [
|
|
391
|
+
header.length > 0 ? header : (entity.name ?? entity.symbolType),
|
|
392
|
+
];
|
|
393
|
+
if (STRUCTURAL_SYMBOL_TYPES.has(entity.symbolType)) {
|
|
394
|
+
const members = collectStructureOutlineMembers(entity, adapter);
|
|
395
|
+
if (members.length > 0) {
|
|
396
|
+
lines.push("", "members:", ...members.map((member) => `- ${formatOutlineMember(member)}`));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else if (entity.symbolType === "function") {
|
|
400
|
+
const calls = collectFunctionCallNames(entity.node);
|
|
401
|
+
if (calls.length > 0) {
|
|
402
|
+
lines.push("", `calls: ${calls.join(", ")}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return truncateOutline(lines.join("\n").trim(), maxChars);
|
|
406
|
+
}
|
|
407
|
+
function truncateOutline(outline, maxChars) {
|
|
408
|
+
if (outline.length <= maxChars) {
|
|
409
|
+
return outline;
|
|
410
|
+
}
|
|
411
|
+
if (maxChars <= 3) {
|
|
412
|
+
return ".".repeat(maxChars);
|
|
413
|
+
}
|
|
414
|
+
return `${outline.slice(0, maxChars - 3).trimEnd()}...`;
|
|
415
|
+
}
|
|
416
|
+
function extractCodeHeader(text) {
|
|
417
|
+
const maxChars = 1200;
|
|
418
|
+
const maxLines = 24;
|
|
419
|
+
const lines = [];
|
|
420
|
+
for (const line of text.split(/\r?\n/)) {
|
|
421
|
+
lines.push(line);
|
|
422
|
+
if (line.includes("{") || lines.length >= maxLines) {
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const header = lines.join("\n").trim();
|
|
427
|
+
return header.length > maxChars
|
|
428
|
+
? `${header.slice(0, maxChars).trimEnd()}\n...`
|
|
429
|
+
: header;
|
|
430
|
+
}
|
|
431
|
+
function collectStructureOutlineMembers(entity, adapter) {
|
|
432
|
+
const members = [];
|
|
433
|
+
const seen = new Set();
|
|
434
|
+
const visit = (node, depth) => {
|
|
435
|
+
if (members.length >= OUTLINE_MAX_MEMBERS || depth > 12) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (!sameNode(node, entity.node) && adapter.entityTypes.has(node.type)) {
|
|
439
|
+
if (adapter.shouldIndexEntity?.(node) !== false) {
|
|
440
|
+
const resolved = adapter.resolveEntities?.(node) ?? [
|
|
441
|
+
adapter.resolveEntity ? adapter.resolveEntity(node) : node,
|
|
442
|
+
];
|
|
443
|
+
for (const resolvedNode of resolved) {
|
|
444
|
+
if (members.length >= OUTLINE_MAX_MEMBERS ||
|
|
445
|
+
sameNode(resolvedNode, entity.node)) {
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
const name = adapter.extractName(resolvedNode);
|
|
449
|
+
const symbolType = adapter.classifyNode?.(resolvedNode, entity.breadcrumb) ??
|
|
450
|
+
classifyCodeNode(resolvedNode, entity.breadcrumb);
|
|
451
|
+
const signature = adapter.extractSignature?.(resolvedNode);
|
|
452
|
+
const key = `${symbolType}:${name ?? ""}:${signature ?? ""}:${resolvedNode.startIndex}`;
|
|
453
|
+
if (!seen.has(key)) {
|
|
454
|
+
seen.add(key);
|
|
455
|
+
members.push({ symbolType, name, signature });
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
for (const child of node.namedChildren) {
|
|
462
|
+
visit(child, depth + 1);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
visit(entity.node, 0);
|
|
466
|
+
return members;
|
|
467
|
+
}
|
|
468
|
+
function formatOutlineMember(member) {
|
|
469
|
+
const name = member.name ?? "";
|
|
470
|
+
const signature = member.signature
|
|
471
|
+
? truncateOutlineLine(oneLine(member.signature))
|
|
472
|
+
: "";
|
|
473
|
+
if (signature.length > 0) {
|
|
474
|
+
return name.length > 0 && !signature.includes(name)
|
|
475
|
+
? `${member.symbolType} ${name}: ${signature}`
|
|
476
|
+
: `${member.symbolType} ${signature}`;
|
|
477
|
+
}
|
|
478
|
+
return name.length > 0 ? `${member.symbolType} ${name}` : member.symbolType;
|
|
479
|
+
}
|
|
480
|
+
function collectFunctionCallNames(node) {
|
|
481
|
+
const calls = [];
|
|
482
|
+
const seen = new Set();
|
|
483
|
+
const visit = (current) => {
|
|
484
|
+
if (calls.length >= OUTLINE_MAX_CALLS) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (isCallNode(current)) {
|
|
488
|
+
const name = extractCallName(current);
|
|
489
|
+
if (name && !seen.has(name)) {
|
|
490
|
+
seen.add(name);
|
|
491
|
+
calls.push(name);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
for (const child of current.namedChildren) {
|
|
495
|
+
visit(child);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
visit(node);
|
|
499
|
+
return calls;
|
|
500
|
+
}
|
|
501
|
+
function isCallNode(node) {
|
|
502
|
+
return (node.type === "call" ||
|
|
503
|
+
node.type === "call_expression" ||
|
|
504
|
+
node.type === "function_call_expression" ||
|
|
505
|
+
node.type === "method_invocation" ||
|
|
506
|
+
node.type === "object_creation_expression" ||
|
|
507
|
+
node.type === "new_expression");
|
|
508
|
+
}
|
|
509
|
+
function extractCallName(node) {
|
|
510
|
+
const target = node.childForFieldName("function") ??
|
|
511
|
+
node.childForFieldName("name") ??
|
|
512
|
+
node.childForFieldName("constructor") ??
|
|
513
|
+
node.childForFieldName("type") ??
|
|
514
|
+
node.namedChildren[0];
|
|
515
|
+
if (!target) {
|
|
516
|
+
return undefined;
|
|
517
|
+
}
|
|
518
|
+
return normalizeCallName(target.text);
|
|
519
|
+
}
|
|
520
|
+
function normalizeCallName(value) {
|
|
521
|
+
const cleaned = value
|
|
522
|
+
.replace(/\s+/g, " ")
|
|
523
|
+
.replace(/^new\s+/, "")
|
|
524
|
+
.trim();
|
|
525
|
+
if (cleaned.length === 0 ||
|
|
526
|
+
cleaned.length > OUTLINE_MAX_LINE_CHARS ||
|
|
527
|
+
/[\n\r]/.test(cleaned) ||
|
|
528
|
+
!/[A-Za-z_$][A-Za-z0-9_$]*/.test(cleaned)) {
|
|
529
|
+
return undefined;
|
|
530
|
+
}
|
|
531
|
+
return cleaned;
|
|
532
|
+
}
|
|
533
|
+
function sameNode(left, right) {
|
|
534
|
+
return (left.startIndex === right.startIndex &&
|
|
535
|
+
left.endIndex === right.endIndex &&
|
|
536
|
+
left.type === right.type);
|
|
537
|
+
}
|
|
538
|
+
function oneLine(value) {
|
|
539
|
+
return value.replace(/\s+/g, " ").trim();
|
|
540
|
+
}
|
|
541
|
+
function truncateOutlineLine(value) {
|
|
542
|
+
return value.length > OUTLINE_MAX_LINE_CHARS
|
|
543
|
+
? `${value.slice(0, OUTLINE_MAX_LINE_CHARS - 3).trimEnd()}...`
|
|
544
|
+
: value;
|
|
545
|
+
}
|
|
546
|
+
function codeEntityMetadata(entity) {
|
|
547
|
+
return {
|
|
548
|
+
kind: "code",
|
|
549
|
+
symbolType: entity.symbolType,
|
|
550
|
+
symbolName: entity.name ?? null,
|
|
551
|
+
scope: entity.breadcrumb.length > 0 ? entity.breadcrumb.join("::") : null,
|
|
552
|
+
nodeType: entity.node.type,
|
|
553
|
+
signature: entity.signature ?? null,
|
|
554
|
+
doc: entity.doc ?? null,
|
|
555
|
+
modifiers: entity.modifiers,
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
function classifyCodeNode(node, breadcrumb) {
|
|
559
|
+
const nodeType = node.type;
|
|
560
|
+
if (nodeType === "decorated_definition") {
|
|
561
|
+
const inner = node.namedChildren.find((child) => child.type === "function_definition" ||
|
|
562
|
+
child.type === "class_definition");
|
|
563
|
+
return inner ? classifyCodeNode(inner, breadcrumb) : "value";
|
|
564
|
+
}
|
|
565
|
+
if ((nodeType === "field_definition" ||
|
|
566
|
+
nodeType === "public_field_definition" ||
|
|
567
|
+
nodeType === "variable_declarator") &&
|
|
568
|
+
hasJavascriptTypescriptFunctionValue(node)) {
|
|
569
|
+
return "function";
|
|
570
|
+
}
|
|
571
|
+
if (nodeType.includes("method") || nodeType.includes("constructor")) {
|
|
572
|
+
return "function";
|
|
573
|
+
}
|
|
574
|
+
if (breadcrumb.length > 0 &&
|
|
575
|
+
(nodeType.includes("function") ||
|
|
576
|
+
nodeType === "declaration" ||
|
|
577
|
+
nodeType === "function_item")) {
|
|
578
|
+
return "function";
|
|
579
|
+
}
|
|
580
|
+
if (nodeType.includes("function")) {
|
|
581
|
+
return "function";
|
|
582
|
+
}
|
|
583
|
+
if (nodeType === "declaration" || nodeType === "macro_type_specifier") {
|
|
584
|
+
return "function";
|
|
585
|
+
}
|
|
586
|
+
if (nodeType.includes("class") ||
|
|
587
|
+
nodeType.includes("struct") ||
|
|
588
|
+
nodeType.includes("impl") ||
|
|
589
|
+
nodeType.includes("enum") ||
|
|
590
|
+
nodeType.includes("union") ||
|
|
591
|
+
nodeType.includes("record")) {
|
|
592
|
+
return "class";
|
|
593
|
+
}
|
|
594
|
+
if (nodeType.includes("interface") ||
|
|
595
|
+
nodeType.includes("protocol") ||
|
|
596
|
+
nodeType.includes("trait")) {
|
|
597
|
+
return "interface";
|
|
598
|
+
}
|
|
599
|
+
if (nodeType.includes("module") ||
|
|
600
|
+
nodeType.includes("namespace") ||
|
|
601
|
+
nodeType === "mod_item") {
|
|
602
|
+
return "module";
|
|
603
|
+
}
|
|
604
|
+
if (nodeType.includes("alias") ||
|
|
605
|
+
nodeType.includes("typedef") ||
|
|
606
|
+
nodeType === "type_definition" ||
|
|
607
|
+
nodeType === "type_item") {
|
|
608
|
+
return "alias";
|
|
609
|
+
}
|
|
610
|
+
return "value";
|
|
611
|
+
}
|
|
612
|
+
function truncateInline(value, maxChars) {
|
|
613
|
+
const compact = value.replace(/\s+/g, " ").trim();
|
|
614
|
+
return compact.length > maxChars
|
|
615
|
+
? `${compact.slice(0, maxChars).trimEnd()}...`
|
|
616
|
+
: compact;
|
|
617
|
+
}
|
|
618
|
+
function isScriptBlockFormat(format) {
|
|
619
|
+
return COMPONENT_CODE_FORMAT_SET.has(format);
|
|
620
|
+
}
|
|
621
|
+
function findScriptBlocks(text) {
|
|
622
|
+
const blocks = [];
|
|
623
|
+
const scriptPattern = /<script(\s[^>]*)?>([\s\S]*?)<\/script>/gi;
|
|
624
|
+
for (const match of text.matchAll(scriptPattern)) {
|
|
625
|
+
const fullMatch = match[0];
|
|
626
|
+
const attrs = match[1] ?? "";
|
|
627
|
+
const blockText = match[2] ?? "";
|
|
628
|
+
const tagEndOffset = fullMatch.indexOf(">");
|
|
629
|
+
if (tagEndOffset < 0) {
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
const startOffset = match.index + tagEndOffset + 1;
|
|
633
|
+
blocks.push({
|
|
634
|
+
text: blockText,
|
|
635
|
+
format: scriptBlockFormat(attrs),
|
|
636
|
+
startLine: lineAtOffset(text, startOffset),
|
|
637
|
+
startOffset,
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
return blocks;
|
|
641
|
+
}
|
|
642
|
+
function scriptBlockFormat(attrs) {
|
|
643
|
+
const lang = attrs
|
|
644
|
+
.match(/\blang\s*=\s*["']?([A-Za-z0-9_-]+)/i)?.[1]
|
|
645
|
+
?.toLowerCase();
|
|
646
|
+
if (lang === "ts" || lang === "typescript") {
|
|
647
|
+
return "typescript";
|
|
648
|
+
}
|
|
649
|
+
if (lang === "tsx") {
|
|
650
|
+
return "tsx";
|
|
651
|
+
}
|
|
652
|
+
if (lang === "jsx") {
|
|
653
|
+
return "jsx";
|
|
654
|
+
}
|
|
655
|
+
return "javascript";
|
|
656
|
+
}
|
|
657
|
+
function lineAtOffset(text, offset) {
|
|
658
|
+
let line = 1;
|
|
659
|
+
for (let index = 0; index < offset; index++) {
|
|
660
|
+
if (text.charCodeAt(index) === 10) {
|
|
661
|
+
line++;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return line;
|
|
665
|
+
}
|
|
666
|
+
function remapScriptBlockFragments(fileId, fragments, startIndex, startLine, startOffset) {
|
|
667
|
+
const idMap = new Map();
|
|
668
|
+
for (const [index, item] of fragments.entries()) {
|
|
669
|
+
idMap.set(item.fragment.id, makeEntityId(fileId, startIndex + index));
|
|
670
|
+
}
|
|
671
|
+
return fragments.map((item) => ({
|
|
672
|
+
...item,
|
|
673
|
+
fragment: {
|
|
674
|
+
...item.fragment,
|
|
675
|
+
id: idMap.get(item.fragment.id) ?? item.fragment.id,
|
|
676
|
+
group: item.fragment.group
|
|
677
|
+
? (idMap.get(item.fragment.group) ?? item.fragment.group)
|
|
678
|
+
: undefined,
|
|
679
|
+
fileId,
|
|
680
|
+
range: remapScriptBlockRange(item.fragment.range, startLine, startOffset),
|
|
681
|
+
},
|
|
682
|
+
}));
|
|
683
|
+
}
|
|
684
|
+
function remapScriptBlockRange(range, startLine, startOffset) {
|
|
685
|
+
if (range.kind !== "text") {
|
|
686
|
+
return range;
|
|
687
|
+
}
|
|
688
|
+
return {
|
|
689
|
+
...range,
|
|
690
|
+
startLine: startLine + range.startLine - 1,
|
|
691
|
+
endLine: startLine + range.endLine - 1,
|
|
692
|
+
startOffset: startOffset + range.startOffset,
|
|
693
|
+
endOffset: startOffset + range.endOffset,
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
//# sourceMappingURL=extractor.js.map
|