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,577 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
formatCodeViewReference,
|
|
7
|
+
formatSourceViewResults,
|
|
8
|
+
formatSymbolSelector,
|
|
9
|
+
renderSourceViewLine,
|
|
10
|
+
type SourceMappedTextContent,
|
|
11
|
+
type SourceViewBlock,
|
|
12
|
+
} from "pi-agent-ide/api/code-view";
|
|
13
|
+
|
|
14
|
+
import { requestCallHierarchy, requestReferences } from "./navigation.js";
|
|
15
|
+
import { requestDocumentSymbols, symbolKindName } from "./symbols.js";
|
|
16
|
+
|
|
17
|
+
import type { LspClient } from "./client.js";
|
|
18
|
+
import type { LspManager } from "./manager.js";
|
|
19
|
+
import type { LspCallHierarchyResult, LspIncomingCall, LspLocation, LspOutgoingCall } from "./navigation.js";
|
|
20
|
+
import type { LspDocumentSymbol } from "./symbols.js";
|
|
21
|
+
import type { LspRange } from "./types.js";
|
|
22
|
+
|
|
23
|
+
const SOURCE_VIEW_FORMAT_OPTIONS = {
|
|
24
|
+
failureLabel: "SYMBOL_READ_FAILED",
|
|
25
|
+
emptyReason: "no symbol source was produced.",
|
|
26
|
+
} as const;
|
|
27
|
+
const MAX_GROUPS = 10;
|
|
28
|
+
const MAX_ITEMS_PER_GROUP = 5;
|
|
29
|
+
const MAX_CALLS = 10;
|
|
30
|
+
|
|
31
|
+
export interface LspCodeSymbol
|
|
32
|
+
{
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly kind: number;
|
|
35
|
+
readonly range: LspRange;
|
|
36
|
+
readonly selectionRange: LspRange;
|
|
37
|
+
readonly selector: readonly string[];
|
|
38
|
+
readonly children: readonly LspCodeSymbol[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface LspCodeDocument
|
|
42
|
+
{
|
|
43
|
+
readonly client: LspClient;
|
|
44
|
+
readonly uri: string;
|
|
45
|
+
readonly filePath: string;
|
|
46
|
+
readonly displayPath: string;
|
|
47
|
+
readonly symbols: readonly LspCodeSymbol[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface SymbolRelations
|
|
51
|
+
{
|
|
52
|
+
readonly references: readonly LspLocation[];
|
|
53
|
+
readonly calls: LspCallHierarchyResult;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function readLspSymbolBody(
|
|
57
|
+
manager: LspManager,
|
|
58
|
+
filePath: string,
|
|
59
|
+
selector: readonly string[],
|
|
60
|
+
cwd: string,
|
|
61
|
+
signal?: AbortSignal,
|
|
62
|
+
): Promise<SourceMappedTextContent>
|
|
63
|
+
{
|
|
64
|
+
throwIfAborted(signal);
|
|
65
|
+
const document = await openCodeDocument(manager, filePath, cwd);
|
|
66
|
+
const symbol = resolveLspCodeSymbol(document.symbols, selector, document.displayPath);
|
|
67
|
+
const snapshot = await readTextFile(document.filePath);
|
|
68
|
+
throwIfAborted(signal);
|
|
69
|
+
|
|
70
|
+
const startLine = symbol.range.start.line + 1;
|
|
71
|
+
const endLine = Math.min(symbol.range.end.line + 1, snapshot.lines.length);
|
|
72
|
+
const renderedLines = snapshot.lines
|
|
73
|
+
.slice(Math.max(0, startLine - 1), Math.max(0, endLine))
|
|
74
|
+
.map((content, index) =>
|
|
75
|
+
{
|
|
76
|
+
const lineNumber = startLine + index;
|
|
77
|
+
|
|
78
|
+
return renderSourceViewLine({
|
|
79
|
+
content,
|
|
80
|
+
sourceLine: {
|
|
81
|
+
source: document.filePath,
|
|
82
|
+
lineNumber,
|
|
83
|
+
content,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
const block: SourceViewBlock = {
|
|
88
|
+
path: document.displayPath,
|
|
89
|
+
heading: `symbol: ${formatSymbolSelector(symbol.selector)}`,
|
|
90
|
+
details: [
|
|
91
|
+
`defined in: ${document.displayPath}:${startLine}-${endLine} (${symbolKindName(symbol.kind)})`,
|
|
92
|
+
],
|
|
93
|
+
startLine,
|
|
94
|
+
endLine,
|
|
95
|
+
totalLines: snapshot.lines.length,
|
|
96
|
+
renderedLines,
|
|
97
|
+
};
|
|
98
|
+
return formatSourceViewResults([block], SOURCE_VIEW_FORMAT_OPTIONS);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export async function readLspSymbolGraph(
|
|
102
|
+
manager: LspManager,
|
|
103
|
+
filePath: string,
|
|
104
|
+
selector: readonly string[],
|
|
105
|
+
cwd: string,
|
|
106
|
+
signal?: AbortSignal,
|
|
107
|
+
): Promise<string>
|
|
108
|
+
{
|
|
109
|
+
throwIfAborted(signal);
|
|
110
|
+
const document = await openCodeDocument(manager, filePath, cwd);
|
|
111
|
+
const symbol = resolveLspCodeSymbol(document.symbols, selector, document.displayPath);
|
|
112
|
+
const relations = await queryRelations(document, symbol, signal);
|
|
113
|
+
const locations = new LocationPresenter(cwd);
|
|
114
|
+
return await formatSymbolGraph(document, symbol, relations, locations);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function readLspFileGraph(
|
|
118
|
+
manager: LspManager,
|
|
119
|
+
filePath: string,
|
|
120
|
+
cwd: string,
|
|
121
|
+
signal?: AbortSignal,
|
|
122
|
+
): Promise<string>
|
|
123
|
+
{
|
|
124
|
+
throwIfAborted(signal);
|
|
125
|
+
const document = await openCodeDocument(manager, filePath, cwd);
|
|
126
|
+
const locations = new LocationPresenter(cwd);
|
|
127
|
+
const lines = [
|
|
128
|
+
`## file graph: ${document.displayPath}`,
|
|
129
|
+
`Top-level declarations: ${document.symbols.length}`,
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
for (const symbol of document.symbols)
|
|
133
|
+
{
|
|
134
|
+
throwIfAborted(signal);
|
|
135
|
+
const relations = await queryRelations(document, symbol, signal);
|
|
136
|
+
lines.push("", ...await formatFileGraphSymbol(document, symbol, relations, locations));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return lines.join("\n");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function resolveLspCodeSymbol(
|
|
143
|
+
symbols: readonly LspCodeSymbol[],
|
|
144
|
+
selector: readonly string[],
|
|
145
|
+
displayPath: string,
|
|
146
|
+
): LspCodeSymbol
|
|
147
|
+
{
|
|
148
|
+
if (selector.length === 0)
|
|
149
|
+
{
|
|
150
|
+
throw new TypeError("A symbol selector must contain at least one segment.");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (selector.length === 1)
|
|
154
|
+
{
|
|
155
|
+
const matches = collectNamedSymbols(symbols, selector[0]!);
|
|
156
|
+
|
|
157
|
+
if (matches.length === 1)
|
|
158
|
+
{
|
|
159
|
+
return matches[0]!;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (matches.length > 1)
|
|
163
|
+
{
|
|
164
|
+
throw new Error(
|
|
165
|
+
`Symbol selector "${formatSymbolSelector(selector)}" is ambiguous in ${displayPath}; use parent/child.`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
throw symbolNotFound(selector, displayPath);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
let current = symbols;
|
|
173
|
+
let selected: LspCodeSymbol | undefined;
|
|
174
|
+
|
|
175
|
+
for (const segment of selector)
|
|
176
|
+
{
|
|
177
|
+
const matches = current.filter((symbol) => symbol.name === segment);
|
|
178
|
+
|
|
179
|
+
if (matches.length === 0)
|
|
180
|
+
{
|
|
181
|
+
throw symbolNotFound(selector, displayPath);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (matches.length > 1)
|
|
185
|
+
{
|
|
186
|
+
throw new Error(
|
|
187
|
+
`Symbol selector "${formatSymbolSelector(selector)}" is ambiguous at "${segment}" in ${displayPath}.`,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
selected = matches[0]!;
|
|
192
|
+
current = selected.children;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return selected!;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function openCodeDocument(manager: LspManager, filePath: string, cwd: string): Promise<LspCodeDocument>
|
|
199
|
+
{
|
|
200
|
+
const absolutePath = path.isAbsolute(filePath) ? path.normalize(filePath) : path.resolve(cwd, filePath);
|
|
201
|
+
const opened = await manager.openFile(absolutePath, cwd, "symbols");
|
|
202
|
+
|
|
203
|
+
if (!opened)
|
|
204
|
+
{
|
|
205
|
+
throw new Error(`No LSP server with symbol support is configured for ${displayFilePath(absolutePath, cwd)}.`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const rawSymbols = await requestDocumentSymbols(opened.client, opened.uri);
|
|
209
|
+
const symbols = normalizeDocumentSymbols(rawSymbols).sort(compareSymbols);
|
|
210
|
+
return {
|
|
211
|
+
client: opened.client,
|
|
212
|
+
uri: opened.uri,
|
|
213
|
+
filePath: absolutePath,
|
|
214
|
+
displayPath: displayFilePath(absolutePath, cwd),
|
|
215
|
+
symbols,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function normalizeDocumentSymbols(
|
|
220
|
+
symbols: readonly LspDocumentSymbol[],
|
|
221
|
+
parentSelector: readonly string[] = [],
|
|
222
|
+
): LspCodeSymbol[]
|
|
223
|
+
{
|
|
224
|
+
return symbols.flatMap((symbol) =>
|
|
225
|
+
{
|
|
226
|
+
const selectionRange = symbol.selectionRange ?? symbol.range;
|
|
227
|
+
|
|
228
|
+
if (!selectionRange)
|
|
229
|
+
{
|
|
230
|
+
return [];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const range = symbol.range ?? selectionRange;
|
|
234
|
+
const selector = [...parentSelector, symbol.name];
|
|
235
|
+
return [{
|
|
236
|
+
name: symbol.name,
|
|
237
|
+
kind: symbol.kind,
|
|
238
|
+
range,
|
|
239
|
+
selectionRange,
|
|
240
|
+
selector,
|
|
241
|
+
children: normalizeDocumentSymbols(symbol.children ?? [], selector).sort(compareSymbols),
|
|
242
|
+
}];
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function compareSymbols(left: LspCodeSymbol, right: LspCodeSymbol): number
|
|
247
|
+
{
|
|
248
|
+
return left.range.start.line - right.range.start.line
|
|
249
|
+
|| left.range.start.character - right.range.start.character
|
|
250
|
+
|| left.name.localeCompare(right.name);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function collectNamedSymbols(symbols: readonly LspCodeSymbol[], name: string): LspCodeSymbol[]
|
|
254
|
+
{
|
|
255
|
+
return symbols.flatMap((symbol) => [
|
|
256
|
+
...(symbol.name === name ? [symbol] : []),
|
|
257
|
+
...collectNamedSymbols(symbol.children, name),
|
|
258
|
+
]);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function symbolNotFound(selector: readonly string[], displayPath: string): Error
|
|
262
|
+
{
|
|
263
|
+
return new Error(`Symbol "${formatSymbolSelector(selector)}" was not found in ${displayPath}.`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
async function queryRelations(
|
|
267
|
+
document: LspCodeDocument,
|
|
268
|
+
symbol: LspCodeSymbol,
|
|
269
|
+
signal: AbortSignal | undefined,
|
|
270
|
+
): Promise<SymbolRelations>
|
|
271
|
+
{
|
|
272
|
+
const position = symbol.selectionRange.start;
|
|
273
|
+
const [references, calls] = await Promise.all([
|
|
274
|
+
optionalRequest(
|
|
275
|
+
requestReferences(document.client, document.uri, position),
|
|
276
|
+
[] as readonly LspLocation[],
|
|
277
|
+
signal,
|
|
278
|
+
),
|
|
279
|
+
optionalRequest(
|
|
280
|
+
requestCallHierarchy(document.client, document.uri, position),
|
|
281
|
+
{ items: [], incoming: [], outgoing: [] },
|
|
282
|
+
signal,
|
|
283
|
+
),
|
|
284
|
+
]);
|
|
285
|
+
throwIfAborted(signal);
|
|
286
|
+
return { references, calls };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function optionalRequest<T>(request: Promise<T>, fallback: T, signal: AbortSignal | undefined): Promise<T>
|
|
290
|
+
{
|
|
291
|
+
try
|
|
292
|
+
{
|
|
293
|
+
const result = await request;
|
|
294
|
+
throwIfAborted(signal);
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
catch (error)
|
|
298
|
+
{
|
|
299
|
+
if (signal?.aborted === true)
|
|
300
|
+
{
|
|
301
|
+
throw abortReason(signal, error);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return fallback;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function formatSymbolGraph(
|
|
309
|
+
document: LspCodeDocument,
|
|
310
|
+
symbol: LspCodeSymbol,
|
|
311
|
+
relations: SymbolRelations,
|
|
312
|
+
locations: LocationPresenter,
|
|
313
|
+
): Promise<string>
|
|
314
|
+
{
|
|
315
|
+
const selector = formatSymbolSelector(symbol.selector);
|
|
316
|
+
const definitionAnchor = await locations.line(document.uri, symbol.selectionRange.start.line + 1);
|
|
317
|
+
const lines = [
|
|
318
|
+
`## graph: ${selector}`,
|
|
319
|
+
`Definition: ${document.displayPath} ${definitionAnchor} (${symbolKindName(symbol.kind)})`,
|
|
320
|
+
`Source: ${formatCodeViewReference("graph", document.displayPath, symbol.selector)}`,
|
|
321
|
+
"",
|
|
322
|
+
...await formatReferences(relations.references, locations),
|
|
323
|
+
"",
|
|
324
|
+
...await formatIncomingCalls(relations.calls.incoming, locations),
|
|
325
|
+
"",
|
|
326
|
+
...await formatOutgoingCalls(relations.calls.outgoing, locations),
|
|
327
|
+
];
|
|
328
|
+
return lines.join("\n");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async function formatReferences(
|
|
332
|
+
references: readonly LspLocation[],
|
|
333
|
+
locations: LocationPresenter,
|
|
334
|
+
): Promise<string[]>
|
|
335
|
+
{
|
|
336
|
+
const groups = groupLocationsByUri(references);
|
|
337
|
+
const lines = [`References: ${references.length} in ${groups.length} file(s)`];
|
|
338
|
+
|
|
339
|
+
for (const [uri, items] of groups.slice(0, MAX_GROUPS))
|
|
340
|
+
{
|
|
341
|
+
lines.push(`- ${locations.display(uri)} (${items.length})`);
|
|
342
|
+
|
|
343
|
+
for (const item of items.slice(0, MAX_ITEMS_PER_GROUP))
|
|
344
|
+
{
|
|
345
|
+
lines.push(` - ${await locations.line(uri, item.range.start.line + 1)}`);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (items.length > MAX_ITEMS_PER_GROUP)
|
|
349
|
+
{
|
|
350
|
+
lines.push(` - ... ${items.length - MAX_ITEMS_PER_GROUP} more`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (groups.length > MAX_GROUPS)
|
|
355
|
+
{
|
|
356
|
+
lines.push(`- ... ${groups.length - MAX_GROUPS} more file(s)`);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return lines;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async function formatIncomingCalls(
|
|
363
|
+
calls: readonly LspIncomingCall[],
|
|
364
|
+
locations: LocationPresenter,
|
|
365
|
+
): Promise<string[]>
|
|
366
|
+
{
|
|
367
|
+
const lines = [`Incoming calls: ${calls.length}`];
|
|
368
|
+
|
|
369
|
+
for (const call of calls.slice(0, MAX_CALLS))
|
|
370
|
+
{
|
|
371
|
+
const line = call.fromRanges[0]?.start.line ?? call.from.selectionRange.start.line;
|
|
372
|
+
const anchor = await locations.line(call.from.uri, line + 1);
|
|
373
|
+
lines.push(
|
|
374
|
+
`- ${symbolKindName(call.from.kind)} ${call.from.name} — ${locations.display(call.from.uri)} ${anchor}`,
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (calls.length > MAX_CALLS)
|
|
379
|
+
{
|
|
380
|
+
lines.push(`- ... ${calls.length - MAX_CALLS} more`);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return lines;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async function formatOutgoingCalls(
|
|
387
|
+
calls: readonly LspOutgoingCall[],
|
|
388
|
+
locations: LocationPresenter,
|
|
389
|
+
): Promise<string[]>
|
|
390
|
+
{
|
|
391
|
+
const lines = [`Outgoing calls: ${calls.length}`];
|
|
392
|
+
|
|
393
|
+
for (const call of calls.slice(0, MAX_CALLS))
|
|
394
|
+
{
|
|
395
|
+
const anchor = await locations.line(call.to.uri, call.to.selectionRange.start.line + 1);
|
|
396
|
+
lines.push(`- ${symbolKindName(call.to.kind)} ${call.to.name} — ${locations.display(call.to.uri)} ${anchor}`);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (calls.length > MAX_CALLS)
|
|
400
|
+
{
|
|
401
|
+
lines.push(`- ... ${calls.length - MAX_CALLS} more`);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return lines;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function formatFileGraphSymbol(
|
|
408
|
+
document: LspCodeDocument,
|
|
409
|
+
symbol: LspCodeSymbol,
|
|
410
|
+
relations: SymbolRelations,
|
|
411
|
+
locations: LocationPresenter,
|
|
412
|
+
): Promise<string[]>
|
|
413
|
+
{
|
|
414
|
+
const kind = symbolKindName(symbol.kind);
|
|
415
|
+
const definitionAnchor = await locations.line(document.uri, symbol.selectionRange.start.line + 1);
|
|
416
|
+
const referenceFiles = groupLocationsByUri(relations.references)
|
|
417
|
+
.map(([uri, items]) => `${locations.display(uri)} (${items.length})`);
|
|
418
|
+
const incoming = relations.calls.incoming.map((call) => `${call.from.name} (${locations.display(call.from.uri)})`);
|
|
419
|
+
const outgoing = relations.calls.outgoing.map((call) => `${call.to.name} (${locations.display(call.to.uri)})`);
|
|
420
|
+
const lines = [
|
|
421
|
+
`### ${kind} ${symbol.name}`,
|
|
422
|
+
`Selector: ${formatSymbolSelector(symbol.selector)}`,
|
|
423
|
+
`Definition: ${definitionAnchor}`,
|
|
424
|
+
`Used by: ${summarize(referenceFiles)}`,
|
|
425
|
+
`Incoming calls: ${summarize(incoming)}`,
|
|
426
|
+
`Outgoing calls: ${summarize(outgoing)}`,
|
|
427
|
+
];
|
|
428
|
+
|
|
429
|
+
if (symbol.children.length > 0)
|
|
430
|
+
{
|
|
431
|
+
lines.push("Members:");
|
|
432
|
+
|
|
433
|
+
for (const child of symbol.children)
|
|
434
|
+
{
|
|
435
|
+
const source = formatCodeViewReference("graph", document.displayPath, child.selector);
|
|
436
|
+
lines.push(`- ${symbolKindName(child.kind)} ${child.name} — ${source}`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return lines;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function summarize(items: readonly string[], limit = 5): string
|
|
444
|
+
{
|
|
445
|
+
if (items.length === 0)
|
|
446
|
+
{
|
|
447
|
+
return "none";
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const shown = items.slice(0, limit).join(", ");
|
|
451
|
+
return items.length > limit ? `${shown}, ... ${items.length - limit} more` : shown;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function groupLocationsByUri(locations: readonly LspLocation[]): [string, LspLocation[]][]
|
|
455
|
+
{
|
|
456
|
+
const grouped = new Map<string, LspLocation[]>();
|
|
457
|
+
|
|
458
|
+
for (const location of locations)
|
|
459
|
+
{
|
|
460
|
+
const current = grouped.get(location.uri) ?? [];
|
|
461
|
+
current.push(location);
|
|
462
|
+
grouped.set(location.uri, current);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
return [...grouped.entries()]
|
|
466
|
+
.map(([uri, items]) =>
|
|
467
|
+
[
|
|
468
|
+
uri,
|
|
469
|
+
items.sort((left, right) =>
|
|
470
|
+
left.range.start.line - right.range.start.line
|
|
471
|
+
|| left.range.start.character - right.range.start.character
|
|
472
|
+
),
|
|
473
|
+
] as [string, LspLocation[]]
|
|
474
|
+
)
|
|
475
|
+
.sort(([left], [right]) => left.localeCompare(right));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
interface TextFileSnapshot
|
|
479
|
+
{
|
|
480
|
+
readonly lines: string[];
|
|
481
|
+
readonly content: string;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async function readTextFile(filePath: string): Promise<TextFileSnapshot>
|
|
485
|
+
{
|
|
486
|
+
const buffer = await readFile(filePath);
|
|
487
|
+
|
|
488
|
+
if (buffer.byteLength > 256 * 1024)
|
|
489
|
+
{
|
|
490
|
+
throw new Error(`File exceeds the 262144-byte code-view limit: ${filePath}`);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (buffer.includes(0))
|
|
494
|
+
{
|
|
495
|
+
throw new Error(`File appears to be binary and cannot be read as text: ${filePath}`);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const content = buffer.toString("utf8").replaceAll("\r\n", "\n");
|
|
499
|
+
const withoutFinalNewline = content.endsWith("\n") ? content.slice(0, -1) : content;
|
|
500
|
+
const lines = withoutFinalNewline.length === 0 ? [] : withoutFinalNewline.split("\n");
|
|
501
|
+
|
|
502
|
+
return { content, lines };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
class LocationPresenter
|
|
506
|
+
{
|
|
507
|
+
readonly #cwd: string;
|
|
508
|
+
|
|
509
|
+
public constructor(cwd: string)
|
|
510
|
+
{
|
|
511
|
+
this.#cwd = cwd;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
public display(uri: string): string
|
|
515
|
+
{
|
|
516
|
+
return displayFilePath(filePathFromUri(uri), this.#cwd);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
public line(_uri: string, lineNumber: number): Promise<string>
|
|
520
|
+
{
|
|
521
|
+
return Promise.resolve(String(lineNumber));
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function filePathFromUri(uri: string): string
|
|
526
|
+
{
|
|
527
|
+
if (!uri.startsWith("file://"))
|
|
528
|
+
{
|
|
529
|
+
return uri;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
try
|
|
533
|
+
{
|
|
534
|
+
return fileURLToPath(uri);
|
|
535
|
+
}
|
|
536
|
+
catch
|
|
537
|
+
{
|
|
538
|
+
return decodeURIComponent(uri.slice("file://".length));
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function displayFilePath(filePath: string, cwd: string): string
|
|
543
|
+
{
|
|
544
|
+
const relative = path.relative(cwd, filePath);
|
|
545
|
+
|
|
546
|
+
if (relative.length === 0 || relative.startsWith("..") || path.isAbsolute(relative))
|
|
547
|
+
{
|
|
548
|
+
return filePath;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
return relative.replaceAll(path.sep, "/");
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function throwIfAborted(signal: AbortSignal | undefined): void
|
|
555
|
+
{
|
|
556
|
+
if (signal?.aborted === true)
|
|
557
|
+
{
|
|
558
|
+
throw abortReason(signal);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function abortReason(signal: AbortSignal, fallback?: unknown): Error
|
|
563
|
+
{
|
|
564
|
+
if (signal.reason instanceof Error)
|
|
565
|
+
{
|
|
566
|
+
return signal.reason;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
if (fallback instanceof Error)
|
|
570
|
+
{
|
|
571
|
+
return fallback;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
const error = new Error("The operation was aborted");
|
|
575
|
+
error.name = "AbortError";
|
|
576
|
+
return error;
|
|
577
|
+
}
|