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,117 @@
|
|
|
1
|
+
import type { DiagnosticHint } from "./file-mutation-result.js";
|
|
2
|
+
|
|
3
|
+
export interface InsertHintsOptions
|
|
4
|
+
{
|
|
5
|
+
readonly suppressContextHunksFor?: (hint: DiagnosticHint) => boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function insertHintsIntoDiff(
|
|
9
|
+
diff: string,
|
|
10
|
+
hints: readonly DiagnosticHint[],
|
|
11
|
+
options: InsertHintsOptions = {},
|
|
12
|
+
): string
|
|
13
|
+
{
|
|
14
|
+
if (hints.length === 0)
|
|
15
|
+
{
|
|
16
|
+
return diff;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const result: string[] = [];
|
|
20
|
+
const shown = new Set<number>();
|
|
21
|
+
let afterLine = 0;
|
|
22
|
+
|
|
23
|
+
for (const line of diff.split("\n"))
|
|
24
|
+
{
|
|
25
|
+
const hunk = /^@@ -(?:\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
|
|
26
|
+
|
|
27
|
+
if (hunk)
|
|
28
|
+
{
|
|
29
|
+
afterLine = Number(hunk[1]) - 1;
|
|
30
|
+
result.push(line);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const isAfterLine = (line.startsWith("+") && !line.startsWith("+++")) || line.startsWith(" ");
|
|
35
|
+
|
|
36
|
+
if (!isAfterLine)
|
|
37
|
+
{
|
|
38
|
+
result.push(line);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
afterLine++;
|
|
43
|
+
const lineHints = hints.filter((hint) => hint.line === afterLine);
|
|
44
|
+
result.push(
|
|
45
|
+
lineHints.length === 0
|
|
46
|
+
? line
|
|
47
|
+
: `${line} <!-- lsp: ${lineHints.map((hint) => formatHint(hint)).join(" | ")} -->`,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
for (const hint of lineHints)
|
|
51
|
+
{
|
|
52
|
+
shown.add(hint.line);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return insertContextHunks(result, hints, shown, options).join("\n");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function insertContextHunks(
|
|
60
|
+
result: string[],
|
|
61
|
+
hints: readonly DiagnosticHint[],
|
|
62
|
+
shown: ReadonlySet<number>,
|
|
63
|
+
options: InsertHintsOptions,
|
|
64
|
+
): string[]
|
|
65
|
+
{
|
|
66
|
+
const contextual = hints
|
|
67
|
+
.filter((hint) => !shown.has(hint.line) && hint.lineText !== undefined)
|
|
68
|
+
.filter((hint) => !options.suppressContextHunksFor?.(hint))
|
|
69
|
+
.map((hint) => ({
|
|
70
|
+
line: hint.line,
|
|
71
|
+
lines: [
|
|
72
|
+
`@@ -${hint.line},1 +${hint.line},1 @@`,
|
|
73
|
+
` ${hint.lineText} <!-- lsp: ${formatHint(hint)} -->`,
|
|
74
|
+
],
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
if (contextual.length === 0)
|
|
78
|
+
{
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const prefix: string[] = [];
|
|
83
|
+
const hunks: { line: number; lines: string[]; }[] = [];
|
|
84
|
+
|
|
85
|
+
for (const line of result)
|
|
86
|
+
{
|
|
87
|
+
const hunk = /^@@ -(?:\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(line);
|
|
88
|
+
|
|
89
|
+
if (hunk)
|
|
90
|
+
{
|
|
91
|
+
hunks.push({ line: Number(hunk[1]), lines: [line] });
|
|
92
|
+
}
|
|
93
|
+
else if (hunks.length === 0)
|
|
94
|
+
{
|
|
95
|
+
prefix.push(line);
|
|
96
|
+
}
|
|
97
|
+
else
|
|
98
|
+
{
|
|
99
|
+
hunks.at(-1)!.lines.push(line);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const ordered = [...hunks, ...contextual].sort((left, right) => left.line - right.line);
|
|
104
|
+
return [...prefix, ...ordered.flatMap((hunk) => hunk.lines)];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function renderDiffForAgent(diff: string): string[]
|
|
108
|
+
{
|
|
109
|
+
return diff.split("\n").slice(2);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function formatHint(hint: DiagnosticHint, options: { includeAnchor?: boolean; } = {}): string
|
|
113
|
+
{
|
|
114
|
+
const source = hint.source ? `${hint.source}:` : "";
|
|
115
|
+
const anchor = options.includeAnchor === false || hint.anchor === undefined ? "" : `${hint.anchor} — `;
|
|
116
|
+
return `[${hint.severity.toUpperCase()}] ${anchor}${source}${hint.code}: ${hint.message}`;
|
|
117
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TextEditorCore } from "#src/core/text-editor-core.js";
|
|
2
|
+
import type { ReadRequest, ReadToolResult } from "pi-agent-read/api/tools/read";
|
|
3
|
+
import type { ResourceResolverContext } from "pi-agent-resource";
|
|
4
|
+
|
|
5
|
+
export type TextAnchorRecoveryReader = (
|
|
6
|
+
request: ReadRequest,
|
|
7
|
+
context: ResourceResolverContext,
|
|
8
|
+
) => Promise<ReadToolResult>;
|
|
9
|
+
|
|
10
|
+
const readers = new WeakMap<TextEditorCore, TextAnchorRecoveryReader>();
|
|
11
|
+
|
|
12
|
+
export function setTextAnchorRecoveryReader(core: TextEditorCore, reader: TextAnchorRecoveryReader): void
|
|
13
|
+
{
|
|
14
|
+
readers.set(core, reader);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function readTextAnchorRecovery(
|
|
18
|
+
core: TextEditorCore,
|
|
19
|
+
request: ReadRequest,
|
|
20
|
+
context: ResourceResolverContext,
|
|
21
|
+
): Promise<ReadToolResult> | undefined
|
|
22
|
+
{
|
|
23
|
+
return readers.get(core)?.(request, context);
|
|
24
|
+
}
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isTextAnchorResolutionAttempt,
|
|
3
|
+
type TextAnchor,
|
|
4
|
+
type TextAnchorRejection,
|
|
5
|
+
type TextAnchorResolver,
|
|
6
|
+
type TextAnchorResolverContext,
|
|
7
|
+
} from "pi-agent-text";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
isTextAnchorResourceResolutionAttempt,
|
|
11
|
+
type TextAnchorResolverRegistration,
|
|
12
|
+
type TextAnchorResourceResolver,
|
|
13
|
+
type TextAnchorResourceResolverContext,
|
|
14
|
+
type TextAnchorType,
|
|
15
|
+
} from "#src/api/plugin-protocol.js";
|
|
16
|
+
import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
|
|
17
|
+
|
|
18
|
+
import type { TextAnchorInspectionOutcome } from "#src/api/anchor-inspection.js";
|
|
19
|
+
|
|
20
|
+
interface RegisteredTextAnchorResolver
|
|
21
|
+
{
|
|
22
|
+
readonly resolver: TextAnchorResolver;
|
|
23
|
+
readonly resources?: TextAnchorResourceResolver;
|
|
24
|
+
readonly kind: string;
|
|
25
|
+
readonly type: TextAnchorType;
|
|
26
|
+
readonly priority: number;
|
|
27
|
+
readonly order: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class TextAnchorResolutionError extends Error
|
|
31
|
+
{
|
|
32
|
+
public constructor(
|
|
33
|
+
message: string,
|
|
34
|
+
readonly resolverId?: string,
|
|
35
|
+
options?: ErrorOptions,
|
|
36
|
+
readonly rejection?: TextAnchorRejection,
|
|
37
|
+
)
|
|
38
|
+
{
|
|
39
|
+
super(message, options);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class TextAnchorRegistry
|
|
44
|
+
{
|
|
45
|
+
readonly #resolvers: RegisteredTextAnchorResolver[] = [];
|
|
46
|
+
|
|
47
|
+
public add(registration: TextAnchorResolverRegistration): void
|
|
48
|
+
{
|
|
49
|
+
if (typeof registration.kind !== "string" || registration.kind.trim().length === 0)
|
|
50
|
+
{
|
|
51
|
+
throw new TypeError("Text anchor resolver kind must be a non-empty string");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const resolverId = registration.resolver.id;
|
|
55
|
+
|
|
56
|
+
if (this.#resolvers.some(({ resolver }) => resolver.id === resolverId))
|
|
57
|
+
{
|
|
58
|
+
throw new Error(`Text anchor resolver ${resolverId} is already registered`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (registration.type === "major" && this.#resolvers.some(({ type }) => type === "major"))
|
|
62
|
+
{
|
|
63
|
+
throw new Error("A major text anchor resolver is already registered");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.#resolvers.push({
|
|
67
|
+
resolver: registration.resolver,
|
|
68
|
+
...(registration.resources === undefined ? {} : { resources: registration.resources }),
|
|
69
|
+
kind: registration.kind,
|
|
70
|
+
type: registration.type,
|
|
71
|
+
priority: registration.priority ?? 0,
|
|
72
|
+
order: this.#resolvers.length,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public assertCanAdd(registrations: readonly TextAnchorResolverRegistration[]): void
|
|
77
|
+
{
|
|
78
|
+
const resolverIds = new Set(this.#resolvers.map(({ resolver }) => resolver.id));
|
|
79
|
+
let hasMajor = this.#resolvers.some(({ type }) => type === "major");
|
|
80
|
+
|
|
81
|
+
for (const registration of registrations)
|
|
82
|
+
{
|
|
83
|
+
if (typeof registration.kind !== "string" || registration.kind.trim().length === 0)
|
|
84
|
+
{
|
|
85
|
+
throw new TypeError("Text anchor resolver kind must be a non-empty string");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (resolverIds.has(registration.resolver.id))
|
|
89
|
+
{
|
|
90
|
+
throw new Error(`Text anchor resolver ${registration.resolver.id} is already registered`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
resolverIds.add(registration.resolver.id);
|
|
94
|
+
|
|
95
|
+
if (registration.type === "major")
|
|
96
|
+
{
|
|
97
|
+
if (hasMajor)
|
|
98
|
+
{
|
|
99
|
+
throw new Error("A major text anchor resolver is already registered");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
hasMajor = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public snapshot(): TextAnchorRegistrySnapshot
|
|
108
|
+
{
|
|
109
|
+
return new TextAnchorRegistrySnapshot(
|
|
110
|
+
[...this.#resolvers].sort((left, right) => left.priority - right.priority || left.order - right.order),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public renderPromptSection(): string | undefined
|
|
115
|
+
{
|
|
116
|
+
const entries = this.#resolvers
|
|
117
|
+
.map(({ resolver }) => renderResolverDescription(resolver))
|
|
118
|
+
.filter((entry): entry is string => entry !== undefined);
|
|
119
|
+
|
|
120
|
+
return entries.length === 0
|
|
121
|
+
? undefined
|
|
122
|
+
: ["Text editor anchors:", ...entries, "", "Pass anchors exactly as shown."].join("\n");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class TextAnchorRegistrySnapshot
|
|
127
|
+
{
|
|
128
|
+
public constructor(private readonly resolvers: readonly RegisteredTextAnchorResolver[])
|
|
129
|
+
{}
|
|
130
|
+
|
|
131
|
+
public async inspect(
|
|
132
|
+
anchors: readonly [string] | readonly [string, string],
|
|
133
|
+
kinds: readonly [readonly string[]] | readonly [readonly string[], readonly string[]],
|
|
134
|
+
context: TextAnchorResolverContext,
|
|
135
|
+
): Promise<TextAnchorInspectionOutcome>
|
|
136
|
+
{
|
|
137
|
+
for (let index = 0; index < anchors.length; index += 1)
|
|
138
|
+
{
|
|
139
|
+
try
|
|
140
|
+
{
|
|
141
|
+
await this.resolve(anchors[index]!, context, new Set(kinds[index]));
|
|
142
|
+
}
|
|
143
|
+
catch (error)
|
|
144
|
+
{
|
|
145
|
+
if (!(error instanceof TextAnchorResolutionError))
|
|
146
|
+
{
|
|
147
|
+
return { kind: "failed", reason: "Text anchor resolution failed", cause: error };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (error.rejection === undefined)
|
|
151
|
+
{
|
|
152
|
+
return { kind: "invalid", anchorIndex: index, reason: error.message };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return {
|
|
156
|
+
kind: "invalid",
|
|
157
|
+
anchorIndex: index,
|
|
158
|
+
reason: error.rejection.reason,
|
|
159
|
+
...(error.rejection.contextRange === undefined
|
|
160
|
+
? {}
|
|
161
|
+
: { contextRange: error.rejection.contextRange }),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return { kind: "valid" };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public async resolveResources(
|
|
170
|
+
value: string,
|
|
171
|
+
context: TextAnchorResourceResolverContext,
|
|
172
|
+
allowedKinds?: ReadonlySet<string>,
|
|
173
|
+
): Promise<readonly string[] | undefined>
|
|
174
|
+
{
|
|
175
|
+
for (const { kind, resolver, resources } of this.resolvers)
|
|
176
|
+
{
|
|
177
|
+
if (
|
|
178
|
+
resources === undefined
|
|
179
|
+
|| (allowedKinds !== undefined && !allowedKinds.has(kind))
|
|
180
|
+
)
|
|
181
|
+
{
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let attempt: unknown;
|
|
186
|
+
|
|
187
|
+
try
|
|
188
|
+
{
|
|
189
|
+
attempt = await resources.tryResolve(value, context);
|
|
190
|
+
}
|
|
191
|
+
catch (error)
|
|
192
|
+
{
|
|
193
|
+
throw new TextAnchorResolutionError(
|
|
194
|
+
`Text anchor resource resolver ${resolver.id} failed for "${value}"`,
|
|
195
|
+
resolver.id,
|
|
196
|
+
{ cause: error },
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!isTextAnchorResourceResolutionAttempt(attempt))
|
|
201
|
+
{
|
|
202
|
+
throw new TextAnchorResolutionError(
|
|
203
|
+
`Text anchor resource resolver ${resolver.id} returned an invalid result for "${value}"`,
|
|
204
|
+
resolver.id,
|
|
205
|
+
{ cause: attempt },
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (attempt.kind === "not-handled")
|
|
210
|
+
{
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (attempt.kind === "failed")
|
|
215
|
+
{
|
|
216
|
+
throw new TextAnchorResolutionError(
|
|
217
|
+
`Text anchor resource resolver ${resolver.id} failed for "${value}"`,
|
|
218
|
+
resolver.id,
|
|
219
|
+
{ cause: attempt.error },
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (attempt.kind === "rejected")
|
|
224
|
+
{
|
|
225
|
+
throw new TextAnchorResolutionError(
|
|
226
|
+
attempt.rejection.reason,
|
|
227
|
+
resolver.id,
|
|
228
|
+
undefined,
|
|
229
|
+
attempt.rejection,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return [...new Set(attempt.sources)];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
public async resolve(
|
|
239
|
+
value: string,
|
|
240
|
+
context: TextAnchorResolverContext,
|
|
241
|
+
allowedKinds?: ReadonlySet<string>,
|
|
242
|
+
): Promise<TextAnchor>
|
|
243
|
+
{
|
|
244
|
+
if (context.lines.length === 0)
|
|
245
|
+
{
|
|
246
|
+
throw new TextAnchorResolutionError(`Anchor "${value}" cannot resolve in an empty file`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for (const { kind, resolver } of this.resolvers)
|
|
250
|
+
{
|
|
251
|
+
if (allowedKinds !== undefined && !allowedKinds.has(kind))
|
|
252
|
+
{
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let attempt: unknown;
|
|
257
|
+
let normalizedValue: string;
|
|
258
|
+
|
|
259
|
+
try
|
|
260
|
+
{
|
|
261
|
+
normalizedValue = resolver.normalize?.(value) ?? value;
|
|
262
|
+
|
|
263
|
+
if (typeof normalizedValue !== "string" || normalizedValue.trim().length === 0)
|
|
264
|
+
{
|
|
265
|
+
throw new TypeError("Text anchor normalization must return non-empty text");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
attempt = await resolver.tryResolve(normalizedValue, context);
|
|
269
|
+
}
|
|
270
|
+
catch (error)
|
|
271
|
+
{
|
|
272
|
+
throw new TextAnchorResolutionError(
|
|
273
|
+
`Text anchor resolver ${resolver.id} failed for "${value}"`,
|
|
274
|
+
resolver.id,
|
|
275
|
+
{ cause: error },
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!isTextAnchorResolutionAttempt(attempt))
|
|
280
|
+
{
|
|
281
|
+
throw new TextAnchorResolutionError(
|
|
282
|
+
`Text anchor resolver ${resolver.id} returned an invalid result for "${value}"`,
|
|
283
|
+
resolver.id,
|
|
284
|
+
{ cause: attempt },
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (attempt.kind === "not-handled")
|
|
289
|
+
{
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (attempt.kind === "failed")
|
|
294
|
+
{
|
|
295
|
+
throw new TextAnchorResolutionError(
|
|
296
|
+
`Text anchor resolver ${resolver.id} failed for "${value}"`,
|
|
297
|
+
resolver.id,
|
|
298
|
+
{ cause: attempt.error },
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (attempt.kind === "rejected")
|
|
303
|
+
{
|
|
304
|
+
throw new TextAnchorResolutionError(
|
|
305
|
+
attempt.rejection.reason,
|
|
306
|
+
resolver.id,
|
|
307
|
+
undefined,
|
|
308
|
+
attempt.rejection,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (
|
|
313
|
+
attempt.anchor.value !== normalizedValue
|
|
314
|
+
|| attempt.anchor.lineNumber > context.lines.length
|
|
315
|
+
)
|
|
316
|
+
{
|
|
317
|
+
throw new TextAnchorResolutionError(
|
|
318
|
+
`Text anchor resolver ${resolver.id} resolved "${value}" outside the current text`,
|
|
319
|
+
resolver.id,
|
|
320
|
+
{ cause: attempt },
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (
|
|
325
|
+
TextSelectionAnchor.is(attempt.anchor)
|
|
326
|
+
&& !isSelectionWithinContext(attempt.anchor, context)
|
|
327
|
+
)
|
|
328
|
+
{
|
|
329
|
+
throw new TextAnchorResolutionError(
|
|
330
|
+
`Text anchor resolver ${resolver.id} resolved "${value}" outside the current text`,
|
|
331
|
+
resolver.id,
|
|
332
|
+
{ cause: attempt },
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return attempt.anchor;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
throw new TextAnchorResolutionError(`No text anchor resolver handled "${value}"`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function isSelectionWithinContext(
|
|
344
|
+
anchor: TextSelectionAnchor,
|
|
345
|
+
context: TextAnchorResolverContext,
|
|
346
|
+
): boolean
|
|
347
|
+
{
|
|
348
|
+
if (anchor.source !== context.source)
|
|
349
|
+
{
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return anchor.ranges.every((range) =>
|
|
354
|
+
{
|
|
355
|
+
const startLine = context.lines[range.start.lineNumber - 1];
|
|
356
|
+
const endLine = context.lines[range.end.lineNumber - 1];
|
|
357
|
+
return startLine !== undefined
|
|
358
|
+
&& endLine !== undefined
|
|
359
|
+
&& range.start.column <= startLine.length
|
|
360
|
+
&& range.end.column <= endLine.length;
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function renderResolverDescription(resolver: TextAnchorResolver): string | undefined
|
|
365
|
+
{
|
|
366
|
+
const value: unknown = typeof resolver.description === "string"
|
|
367
|
+
? resolver.description
|
|
368
|
+
: resolver.description();
|
|
369
|
+
|
|
370
|
+
if (value === undefined)
|
|
371
|
+
{
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (typeof value !== "string" || value.trim().length === 0)
|
|
376
|
+
{
|
|
377
|
+
throw new TypeError(`Text anchor resolver ${resolver.id} description must be non-empty text`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return `- ${value.trim().replaceAll("\n", " ")}`;
|
|
381
|
+
}
|