pi-agent-ide 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/assets/banner.png +0 -0
- package/docs/architecture.md +100 -0
- package/docs/configuration.md +104 -0
- package/docs/development.md +102 -0
- package/docs/evaluation.md +14 -0
- package/docs/extensions.md +298 -0
- package/docs/tools.md +104 -0
- package/node_modules/pi-agent-filesystem/index.ts +60 -0
- package/node_modules/pi-agent-filesystem/package.json +23 -0
- package/node_modules/pi-agent-filesystem/src/resolver.ts +175 -0
- package/node_modules/pi-agent-filesystem-image/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-image/package.json +20 -0
- package/node_modules/pi-agent-filesystem-pdf/index.ts +14 -0
- package/node_modules/pi-agent-filesystem-pdf/package.json +17 -0
- package/node_modules/pi-agent-filesystem-text/index.ts +23 -0
- package/node_modules/pi-agent-filesystem-text/package.json +20 -0
- package/node_modules/pi-agent-ide-ast/index.ts +1 -0
- package/node_modules/pi-agent-ide-ast/package.json +39 -0
- package/node_modules/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/node_modules/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/node_modules/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +85 -0
- package/node_modules/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/node_modules/pi-agent-ide-changes/index.ts +68 -0
- package/node_modules/pi-agent-ide-changes/package.json +29 -0
- package/node_modules/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/node_modules/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/node_modules/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/node_modules/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/node_modules/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/node_modules/pi-agent-ide-formatter/index.ts +33 -0
- package/node_modules/pi-agent-ide-formatter/package.json +14 -0
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-formatter/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lint/index.ts +237 -0
- package/node_modules/pi-agent-ide-lint/package.json +19 -0
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/node_modules/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/node_modules/pi-agent-ide-lint/src/registry.ts +30 -0
- package/node_modules/pi-agent-ide-lint/src/types.ts +10 -0
- package/node_modules/pi-agent-ide-lsp/index.ts +250 -0
- package/node_modules/pi-agent-ide-lsp/package.json +23 -0
- package/node_modules/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/node_modules/pi-agent-image/package.json +18 -0
- package/node_modules/pi-agent-image/src/image-converter.ts +318 -0
- package/node_modules/pi-agent-image/src/index.ts +6 -0
- package/node_modules/pi-agent-pdf/package.json +16 -0
- package/node_modules/pi-agent-pdf/src/index.ts +5 -0
- package/node_modules/pi-agent-pdf/src/pdf-converter.ts +197 -0
- package/node_modules/pi-agent-read/index.ts +1 -0
- package/node_modules/pi-agent-read/package.json +41 -0
- package/node_modules/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/node_modules/pi-agent-read/src/api/rendering.ts +11 -0
- package/node_modules/pi-agent-read/src/api/tools/read.ts +208 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +40 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +390 -0
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/node_modules/pi-agent-resource/package.json +17 -0
- package/node_modules/pi-agent-resource/src/content-conversion/connect-plugin.ts +84 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-converter.ts +49 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +29 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-host.ts +73 -0
- package/node_modules/pi-agent-resource/src/content-conversion/content-runner.ts +152 -0
- package/node_modules/pi-agent-resource/src/content-conversion/plugin-protocol.ts +74 -0
- package/node_modules/pi-agent-resource/src/content-conversion/validation.ts +149 -0
- package/node_modules/pi-agent-resource/src/content.ts +17 -0
- package/node_modules/pi-agent-resource/src/index.ts +65 -0
- package/node_modules/pi-agent-resource/src/resolver.ts +23 -0
- package/node_modules/pi-agent-resource/src/resource.ts +41 -0
- package/node_modules/pi-agent-resource/src/validation.ts +139 -0
- package/node_modules/pi-agent-search/index.ts +1 -0
- package/node_modules/pi-agent-search/package.json +35 -0
- package/node_modules/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/node_modules/pi-agent-search/src/api/search.ts +91 -0
- package/node_modules/pi-agent-search/src/core/extension.ts +126 -0
- package/node_modules/pi-agent-search/src/core/search-core.ts +400 -0
- package/node_modules/pi-agent-search-semantic/index.ts +105 -0
- package/node_modules/pi-agent-search-semantic/package.json +17 -0
- package/node_modules/pi-agent-search-text/index.ts +54 -0
- package/node_modules/pi-agent-search-text/package.json +33 -0
- package/node_modules/pi-agent-search-text/src/file-search.ts +105 -0
- package/node_modules/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +192 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +295 -0
- package/node_modules/pi-agent-search-text/src/search-query.ts +139 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +193 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +338 -0
- package/node_modules/pi-agent-search-web/index.ts +74 -0
- package/node_modules/pi-agent-search-web/package.json +19 -0
- package/node_modules/pi-agent-search-web/src/config.ts +499 -0
- package/node_modules/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/node_modules/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/node_modules/pi-agent-search-web/src/providers/request.ts +430 -0
- package/node_modules/pi-agent-search-web/src/providers/response.ts +402 -0
- package/node_modules/pi-agent-search-web/src/search-format.ts +29 -0
- package/node_modules/pi-agent-search-web/src/search.ts +434 -0
- package/node_modules/pi-agent-search-web/src/types.ts +153 -0
- package/node_modules/pi-agent-text/package.json +18 -0
- package/node_modules/pi-agent-text/src/index.ts +31 -0
- package/node_modules/pi-agent-text/src/presented-text.ts +24 -0
- package/node_modules/pi-agent-text/src/source-line.ts +49 -0
- package/node_modules/pi-agent-text/src/text-anchor.ts +157 -0
- package/node_modules/pi-agent-text/src/text-converter.ts +109 -0
- package/node_modules/pi-agent-text/src/text-document.ts +149 -0
- package/node_modules/pi-agent-text-anchor-constant/index.ts +30 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +17 -0
- package/node_modules/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/node_modules/pi-agent-text-editor/index.ts +19 -0
- package/node_modules/pi-agent-text-editor/package.json +92 -0
- package/node_modules/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/node_modules/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/node_modules/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/node_modules/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/node_modules/pi-agent-text-editor-argument-order/package.json +16 -0
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/node_modules/pi-agent-text-editor-overwrite/package.json +16 -0
- package/node_modules/pi-agent-text-editor-renderer/index.ts +22 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +21 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/node_modules/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +17 -0
- package/node_modules/pi-agent-tool-call-interception/src/index.ts +418 -0
- package/node_modules/pi-agent-web/index.ts +37 -0
- package/node_modules/pi-agent-web/package.json +24 -0
- package/node_modules/pi-agent-web/src/resolver.ts +182 -0
- package/node_modules/pi-agent-web-html/index.ts +15 -0
- package/node_modules/pi-agent-web-html/package.json +18 -0
- package/node_modules/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/node_modules/pi-agent-web-html/src/html-converter.ts +91 -0
- package/node_modules/pi-agent-web-image/index.ts +14 -0
- package/node_modules/pi-agent-web-image/package.json +17 -0
- package/node_modules/pi-agent-web-pdf/index.ts +14 -0
- package/node_modules/pi-agent-web-pdf/package.json +17 -0
- package/node_modules/pi-agent-web-text/index.ts +14 -0
- package/node_modules/pi-agent-web-text/package.json +17 -0
- package/package.json +176 -0
- package/src/api/code-view.ts +25 -0
- package/src/api/connect-plugin.ts +64 -0
- package/src/api/plugin-protocol.ts +63 -0
- package/src/api/read.ts +5 -0
- package/src/api/resource.ts +2 -0
- package/src/api/search.ts +4 -0
- package/src/api/text-editor.ts +3 -0
- package/src/api/text.ts +2 -0
- package/src/api/toolchain.ts +24 -0
- package/src/code-view/diagnostic-view.ts +82 -0
- package/src/code-view/reference.ts +113 -0
- package/src/code-view/source-view.ts +229 -0
- package/src/composite/builtin-extensions.ts +68 -0
- package/src/composite/config.ts +94 -0
- package/src/composite/selection.ts +66 -0
- package/src/core/extension.ts +48 -0
- package/src/core/ide-core.ts +117 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +60 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/index.ts +23 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +20 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/src/resolver.ts +175 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/index.ts +37 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +24 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/index.ts +15 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +18 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/extract-readable-html.ts +101 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/src/html-converter.ts +91 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/index.ts +14 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +17 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +182 -0
- package/src/extensions/pi-agent-read/index.ts +1 -0
- package/src/extensions/pi-agent-read/package.json +41 -0
- package/src/extensions/pi-agent-read/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +67 -0
- package/src/extensions/pi-agent-read/src/api/rendering.ts +11 -0
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +208 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +40 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +390 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +193 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +400 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +187 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +218 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +828 -0
- package/src/extensions/pi-agent-search/index.ts +1 -0
- package/src/extensions/pi-agent-search/package.json +35 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/index.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-semantic/package.json +17 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +54 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +33 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.ts +105 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/lucene-query-parser.d.ts +22 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +192 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +295 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-query.ts +139 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +420 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +193 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +338 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/index.ts +74 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/package.json +19 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/config.ts +499 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/duckduckgo-html.ts +78 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/endpoints.ts +89 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/request.ts +430 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/providers/response.ts +402 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search-format.ts +29 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/search.ts +434 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-web/src/types.ts +153 -0
- package/src/extensions/pi-agent-search/src/api/connect-plugin.ts +61 -0
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +60 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +91 -0
- package/src/extensions/pi-agent-search/src/core/extension.ts +126 -0
- package/src/extensions/pi-agent-search/src/core/search-core.ts +400 -0
- package/src/extensions/pi-agent-text-editor/index.ts +19 -0
- package/src/extensions/pi-agent-text-editor/package.json +92 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/index.ts +30 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/src/resolver.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +48 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +24 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/anchor.ts +110 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +47 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +29 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +112 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +391 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +16 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +22 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +21 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +452 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +271 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-theme.ts +411 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +38 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +205 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +229 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-projection.ts +407 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +153 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +8 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +728 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/typing-interpolation.ts +219 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/index.ts +375 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/anchor-inspection.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/connect-plugin.ts +67 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +64 -0
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +46 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-preview.ts +30 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +23 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +180 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +217 -0
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +147 -0
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +17 -0
- package/src/extensions/pi-agent-text-editor/src/api/text-selection-anchor.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-call-interceptor.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +39 -0
- package/src/extensions/pi-agent-text-editor/src/core/builtin-edit-filter.ts +59 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +150 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/agent-diff.ts +386 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +129 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +359 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +648 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/inline-hints.ts +117 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-recovery.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-anchor-registry.ts +381 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +273 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-coordinator.ts +607 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-execution.ts +127 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-recovery.ts +45 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +432 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +115 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +2348 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation-anchor-error.ts +28 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +756 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1235 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-json-resolver.ts +43 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/partial-tool-recovery.ts +308 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/rendering.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/streaming-provider.ts +467 -0
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +16 -0
- package/src/extensions/pi-agent-text-editor/src/tools/extension.ts +19 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +106 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +121 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +79 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +56 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +142 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +72 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +28 -0
- package/src/index.ts +1 -0
- package/src/pi-agent-ide.ts +17 -0
- package/src/plugins/pi-agent-ide-ast/index.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/package.json +39 -0
- package/src/plugins/pi-agent-ide-ast/src/api/scope.ts +1 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/collect-files.ts +24 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +374 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +813 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/read-text.ts +30 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +85 -0
- package/src/plugins/pi-agent-ide-ast/src/outline-resolver.ts +69 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +221 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +45 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +141 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +68 -0
- package/src/plugins/pi-agent-ide-changes/package.json +29 -0
- package/src/plugins/pi-agent-ide-changes/src/change-anchor.ts +103 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-groups.ts +309 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-service.ts +223 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/change-types.ts +105 -0
- package/src/plugins/pi-agent-ide-changes/src/changes/git-changes-backend.ts +325 -0
- package/src/plugins/pi-agent-ide-changes/src/current-change-presenter.ts +232 -0
- package/src/plugins/pi-agent-ide-changes/src/index-mutation-queue.ts +11 -0
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +88 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +116 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +153 -0
- package/src/plugins/pi-agent-ide-formatter/index.ts +33 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +14 -0
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +50 -0
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-formatter/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lint/index.ts +237 -0
- package/src/plugins/pi-agent-ide-lint/package.json +19 -0
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +160 -0
- package/src/plugins/pi-agent-ide-lint/src/command-runner.ts +51 -0
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +30 -0
- package/src/plugins/pi-agent-ide-lint/src/types.ts +10 -0
- package/src/plugins/pi-agent-ide-lsp/index.ts +250 -0
- package/src/plugins/pi-agent-ide-lsp/package.json +23 -0
- package/src/plugins/pi-agent-ide-lsp/src/code-view-resolvers.ts +139 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +463 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +577 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/diagnostics.ts +179 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/index.ts +59 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/language-map.ts +57 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/lsp-compiler.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +485 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/navigation.ts +85 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +97 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +50 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +149 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbols.ts +151 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/types.ts +95 -0
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +42 -0
- package/src/post-edit/gate.ts +153 -0
- package/src/toolchain/diagnostic.ts +7 -0
- package/src/toolchain/gate.ts +322 -0
- package/src/toolchain/registry.ts +223 -0
- package/src/toolchain/types.ts +164 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { TextAnchor } from "pi-agent-text";
|
|
6
|
+
import * as WTS from "web-tree-sitter";
|
|
7
|
+
|
|
8
|
+
export interface ScopeEntry
|
|
9
|
+
{
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly kind: string;
|
|
12
|
+
readonly startLine: number;
|
|
13
|
+
readonly endLine: number;
|
|
14
|
+
readonly depth: number;
|
|
15
|
+
readonly hash: string;
|
|
16
|
+
readonly blockHash: string;
|
|
17
|
+
readonly occurrence?: number;
|
|
18
|
+
readonly beginAnchor: TextAnchor;
|
|
19
|
+
readonly endScopeAnchor: TextAnchor;
|
|
20
|
+
readonly scopeBeginAnchor: TextAnchor;
|
|
21
|
+
readonly scopeEndAnchor: TextAnchor;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const require = createRequire(import.meta.url);
|
|
25
|
+
|
|
26
|
+
interface ScopeCandidate
|
|
27
|
+
{
|
|
28
|
+
readonly startLine: number;
|
|
29
|
+
readonly endLine: number;
|
|
30
|
+
readonly kind: string;
|
|
31
|
+
/** True if this candidate came from a named body field (step 1). */
|
|
32
|
+
readonly fromBodyField: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ROOT_KINDS = new Set([
|
|
36
|
+
"program",
|
|
37
|
+
"module",
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
/** Named AST fields that represent block-level bodies. */
|
|
41
|
+
const BODY_FIELDS = new Set([
|
|
42
|
+
"body",
|
|
43
|
+
"consequence",
|
|
44
|
+
"alternative",
|
|
45
|
+
"handler",
|
|
46
|
+
"finalizer",
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
let initPromise: Promise<void> | undefined;
|
|
50
|
+
const loadedLanguages = new Map<string, Promise<WTS.Language>>();
|
|
51
|
+
|
|
52
|
+
function grammarWasmPath(ext: string): string | undefined
|
|
53
|
+
{
|
|
54
|
+
switch (ext)
|
|
55
|
+
{
|
|
56
|
+
case ".ts":
|
|
57
|
+
case ".tsx":
|
|
58
|
+
{
|
|
59
|
+
return "tree-sitter-typescript/tree-sitter-typescript.wasm";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
case ".js":
|
|
63
|
+
case ".jsx":
|
|
64
|
+
case ".mjs":
|
|
65
|
+
case ".cjs":
|
|
66
|
+
{
|
|
67
|
+
return "tree-sitter-javascript/tree-sitter-javascript.wasm";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case ".py":
|
|
71
|
+
{
|
|
72
|
+
return "tree-sitter-python/tree-sitter-python.wasm";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
case ".rs":
|
|
76
|
+
{
|
|
77
|
+
return "tree-sitter-rust/tree-sitter-rust.wasm";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
case ".c":
|
|
81
|
+
case ".cpp":
|
|
82
|
+
case ".cxx":
|
|
83
|
+
case ".h":
|
|
84
|
+
case ".hpp":
|
|
85
|
+
{
|
|
86
|
+
return "tree-sitter-cpp/tree-sitter-cpp.wasm";
|
|
87
|
+
}
|
|
88
|
+
case ".json":
|
|
89
|
+
case ".jsonc":
|
|
90
|
+
{
|
|
91
|
+
return "tree-sitter-json/tree-sitter-json.wasm";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
case ".yaml":
|
|
95
|
+
case ".yml":
|
|
96
|
+
{
|
|
97
|
+
return "@tree-sitter-grammars/tree-sitter-yaml/tree-sitter-yaml.wasm";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
case ".toml":
|
|
101
|
+
{
|
|
102
|
+
return "@tree-sitter-grammars/tree-sitter-toml/tree-sitter-toml.wasm";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
default:
|
|
106
|
+
{
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function ensureParser(ext: string): Promise<WTS.Parser | undefined>
|
|
113
|
+
{
|
|
114
|
+
const wasmRelPath = grammarWasmPath(ext);
|
|
115
|
+
|
|
116
|
+
if (!wasmRelPath)
|
|
117
|
+
{
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
initPromise ??= WTS.Parser.init();
|
|
122
|
+
|
|
123
|
+
await initPromise;
|
|
124
|
+
|
|
125
|
+
let languageLoad = loadedLanguages.get(wasmRelPath);
|
|
126
|
+
|
|
127
|
+
if (languageLoad === undefined)
|
|
128
|
+
{
|
|
129
|
+
const wasmAbsolute = require.resolve(wasmRelPath);
|
|
130
|
+
languageLoad = WTS.Language.load(wasmAbsolute);
|
|
131
|
+
loadedLanguages.set(wasmRelPath, languageLoad);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const language = await languageLoad;
|
|
135
|
+
const parser = new WTS.Parser();
|
|
136
|
+
parser.setLanguage(language);
|
|
137
|
+
return parser;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function parseDocument(
|
|
141
|
+
filePath: string,
|
|
142
|
+
cwd: string,
|
|
143
|
+
lines: readonly string[],
|
|
144
|
+
): Promise<WTS.Tree | undefined>
|
|
145
|
+
{
|
|
146
|
+
if (lines.length === 0)
|
|
147
|
+
{
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
|
|
152
|
+
const parser = await ensureParser(path.extname(absolutePath).toLowerCase());
|
|
153
|
+
|
|
154
|
+
if (!parser)
|
|
155
|
+
{
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return parser.parse(lines.join("\n")) ?? undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function hashScope(lines: readonly string[], startLine: number, endLine: number): string
|
|
163
|
+
{
|
|
164
|
+
const text = lines.slice(Math.max(0, startLine - 1), Math.max(0, endLine)).join("\n");
|
|
165
|
+
return createHash("sha1").update(text).digest("hex").slice(0, 4).toUpperCase();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
class AstScopeTextAnchor extends TextAnchor
|
|
169
|
+
{
|
|
170
|
+
public constructor(
|
|
171
|
+
boundary: "begin" | "end",
|
|
172
|
+
hash: string,
|
|
173
|
+
lineNumber: number,
|
|
174
|
+
occurrence?: number,
|
|
175
|
+
)
|
|
176
|
+
{
|
|
177
|
+
super(`scope-${boundary}-${hash}${occurrence === undefined ? "" : `-${occurrence}`}`, lineNumber);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function createScopeAnchor(
|
|
182
|
+
boundary: "begin" | "end",
|
|
183
|
+
hash: string,
|
|
184
|
+
lineNumber: number,
|
|
185
|
+
occurrence?: number,
|
|
186
|
+
): TextAnchor
|
|
187
|
+
{
|
|
188
|
+
return new AstScopeTextAnchor(boundary, hash, lineNumber, occurrence);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Scope discovery via web-tree-sitter full AST walk. */
|
|
192
|
+
export class AstScopeManager
|
|
193
|
+
{
|
|
194
|
+
public async getDocumentScopes(
|
|
195
|
+
filePath: string,
|
|
196
|
+
cwd: string,
|
|
197
|
+
lines: readonly string[],
|
|
198
|
+
): Promise<ScopeEntry[]>
|
|
199
|
+
{
|
|
200
|
+
if (lines.length === 0)
|
|
201
|
+
{
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const tree = await parseDocument(filePath, cwd, lines);
|
|
206
|
+
|
|
207
|
+
if (!tree)
|
|
208
|
+
{
|
|
209
|
+
return [];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const candidates: ScopeCandidate[] = [];
|
|
213
|
+
this.collectCandidates(tree.rootNode, candidates);
|
|
214
|
+
|
|
215
|
+
return this.buildEntries(candidates, lines);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private collectCandidates(node: WTS.Node, candidates: ScopeCandidate[], depth = 0, isBodyChild = false): void
|
|
219
|
+
{
|
|
220
|
+
if (depth > 100)
|
|
221
|
+
{
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!node.isNamed)
|
|
226
|
+
{
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const nodeType = node.type;
|
|
231
|
+
|
|
232
|
+
if (!nodeType || ROOT_KINDS.has(nodeType))
|
|
233
|
+
{
|
|
234
|
+
// Root nodes (program, module) — still recurse into children
|
|
235
|
+
for (const child of node.namedChildren)
|
|
236
|
+
{
|
|
237
|
+
this.collectCandidates(child, candidates, depth + 1);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// 1. Collect block bodies from named fields (body, consequence, alternative, etc.)
|
|
244
|
+
for (const fieldName of BODY_FIELDS)
|
|
245
|
+
{
|
|
246
|
+
const child = node.childForFieldName(fieldName);
|
|
247
|
+
|
|
248
|
+
if (!child?.isNamed)
|
|
249
|
+
{
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const startLine = child.startPosition.row + 1;
|
|
254
|
+
const endLine = child.endPosition.row + 1;
|
|
255
|
+
const isMultiLine = endLine - startLine >= 3;
|
|
256
|
+
|
|
257
|
+
// If the child itself has a body field (e.g. catch_clause → body),
|
|
258
|
+
// skip registering the intermediate node — recurse into it so its
|
|
259
|
+
// inner body gets registered instead.
|
|
260
|
+
const hasOwnBody = [...BODY_FIELDS].some((f) => child.childForFieldName(f) !== null);
|
|
261
|
+
|
|
262
|
+
if (isMultiLine && !hasOwnBody)
|
|
263
|
+
{
|
|
264
|
+
candidates.push({ startLine, endLine, kind: `${nodeType}.${fieldName}`, fromBodyField: true });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
this.collectCandidates(child, candidates, depth + 1, true);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 2. Generic fallback: any named multi-line node with children is a scope,
|
|
271
|
+
// unless it already has a body field (handled by step 1).
|
|
272
|
+
const hasAnyBodyField = [...BODY_FIELDS].some((f) => node.childForFieldName(f) !== null);
|
|
273
|
+
|
|
274
|
+
if (!hasAnyBodyField && !isBodyChild)
|
|
275
|
+
{
|
|
276
|
+
const nodeStartLine = node.startPosition.row + 1;
|
|
277
|
+
const nodeEndLine = node.endPosition.row + 1;
|
|
278
|
+
|
|
279
|
+
if (nodeEndLine - nodeStartLine >= 3 && node.namedChildren.length > 0)
|
|
280
|
+
{
|
|
281
|
+
candidates.push({
|
|
282
|
+
startLine: nodeStartLine,
|
|
283
|
+
endLine: nodeEndLine,
|
|
284
|
+
kind: nodeType,
|
|
285
|
+
fromBodyField: false,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 3. Recurse into all named children (to find nested constructs)
|
|
291
|
+
for (const child of node.namedChildren)
|
|
292
|
+
{
|
|
293
|
+
this.collectCandidates(child, candidates, depth + 1);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private buildEntries(candidates: readonly ScopeCandidate[], lines: readonly string[]): ScopeEntry[]
|
|
298
|
+
{
|
|
299
|
+
const byStart = new Map<number, ScopeCandidate>();
|
|
300
|
+
|
|
301
|
+
for (const candidate of candidates)
|
|
302
|
+
{
|
|
303
|
+
const current = byStart.get(candidate.startLine);
|
|
304
|
+
|
|
305
|
+
if (
|
|
306
|
+
!current
|
|
307
|
+
|| candidate.endLine > current.endLine
|
|
308
|
+
|| (candidate.endLine === current.endLine && candidate.fromBodyField && !current.fromBodyField)
|
|
309
|
+
)
|
|
310
|
+
{
|
|
311
|
+
byStart.set(candidate.startLine, candidate);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const ordered = [...byStart.values()].sort((a, b) => a.startLine - b.startLine || b.endLine - a.endLine);
|
|
316
|
+
|
|
317
|
+
// Filter: nested scopes sharing an endLine with their outer parent are redundant.
|
|
318
|
+
// The outermost scope with a given endLine wins.
|
|
319
|
+
const deduped: ScopeCandidate[] = [];
|
|
320
|
+
|
|
321
|
+
for (const candidate of ordered)
|
|
322
|
+
{
|
|
323
|
+
const hasOuterWithSameEnd = deduped.some(
|
|
324
|
+
(existing) =>
|
|
325
|
+
existing.startLine < candidate.startLine
|
|
326
|
+
&& existing.endLine === candidate.endLine,
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
if (!hasOuterWithSameEnd)
|
|
330
|
+
{
|
|
331
|
+
deduped.push(candidate);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const counts = new Map<string, number>();
|
|
336
|
+
|
|
337
|
+
for (const candidate of deduped)
|
|
338
|
+
{
|
|
339
|
+
const hash = hashScope(lines, candidate.startLine, candidate.endLine);
|
|
340
|
+
counts.set(hash, (counts.get(hash) ?? 0) + 1);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const seen = new Map<string, number>();
|
|
344
|
+
|
|
345
|
+
return deduped.map((candidate) =>
|
|
346
|
+
{
|
|
347
|
+
const hash = hashScope(lines, candidate.startLine, candidate.endLine);
|
|
348
|
+
const total = counts.get(hash) ?? 1;
|
|
349
|
+
const occurrence = (seen.get(hash) ?? 0) + 1;
|
|
350
|
+
seen.set(hash, occurrence);
|
|
351
|
+
const occurrenceSuffix = total > 1 ? occurrence : undefined;
|
|
352
|
+
|
|
353
|
+
return {
|
|
354
|
+
name: candidate.kind,
|
|
355
|
+
kind: candidate.kind,
|
|
356
|
+
startLine: candidate.startLine,
|
|
357
|
+
endLine: candidate.endLine,
|
|
358
|
+
depth: deduped.filter((parent) =>
|
|
359
|
+
parent !== candidate
|
|
360
|
+
&& parent.startLine <= candidate.startLine
|
|
361
|
+
&& parent.endLine >= candidate.endLine
|
|
362
|
+
&& (parent.startLine < candidate.startLine || parent.endLine > candidate.endLine)
|
|
363
|
+
).length,
|
|
364
|
+
hash,
|
|
365
|
+
blockHash: hash,
|
|
366
|
+
...(occurrenceSuffix === undefined ? {} : { occurrence: occurrenceSuffix }),
|
|
367
|
+
beginAnchor: createScopeAnchor("begin", hash, candidate.startLine, occurrenceSuffix),
|
|
368
|
+
endScopeAnchor: createScopeAnchor("end", hash, candidate.endLine, occurrenceSuffix),
|
|
369
|
+
scopeBeginAnchor: createScopeAnchor("begin", hash, candidate.startLine, occurrenceSuffix),
|
|
370
|
+
scopeEndAnchor: createScopeAnchor("end", hash, candidate.endLine, occurrenceSuffix),
|
|
371
|
+
} satisfies ScopeEntry;
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|