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,386 @@
|
|
|
1
|
+
import { diffLines } from "diff";
|
|
2
|
+
import { type PresentedTextRow, renderPresentedTextRows } from "pi-agent-text";
|
|
3
|
+
|
|
4
|
+
import { formatHint } from "./inline-hints.js";
|
|
5
|
+
|
|
6
|
+
import type { DiagnosticHint, FileMutationResult } from "./file-mutation-result.js";
|
|
7
|
+
|
|
8
|
+
const CONTEXT_LINES = 5;
|
|
9
|
+
const MAX_SYNTAX_ERRORS = 5;
|
|
10
|
+
|
|
11
|
+
const SEVERITY_RANK: Record<DiagnosticHint["severity"], number> = {
|
|
12
|
+
error: 0,
|
|
13
|
+
warning: 1,
|
|
14
|
+
info: 2,
|
|
15
|
+
hint: 3,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface AgentDiffLine
|
|
19
|
+
{
|
|
20
|
+
readonly kind: "context" | "added" | "removed";
|
|
21
|
+
readonly text: string;
|
|
22
|
+
readonly beforeLine?: number;
|
|
23
|
+
readonly afterLine?: number;
|
|
24
|
+
readonly positionLine: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface LineRange
|
|
28
|
+
{
|
|
29
|
+
start: number;
|
|
30
|
+
end: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function renderAgentDiff(fmr: FileMutationResult, diffPath: string): string[]
|
|
34
|
+
{
|
|
35
|
+
const presentedAfter = fmr.data.afterDocument;
|
|
36
|
+
const before = fmr.data.snapshot?.content ?? fmr.data.beforeContentMap?.[diffPath] ?? undefined;
|
|
37
|
+
const after = fmr.data.afterContent ?? presentedAfter?.content;
|
|
38
|
+
|
|
39
|
+
if (before === undefined || after === undefined)
|
|
40
|
+
{
|
|
41
|
+
return renderUnavailableSourceDiff(fmr, diffPath);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const afterLines = splitLines(after);
|
|
45
|
+
const displayLineCount = Math.max(1, afterLines.length);
|
|
46
|
+
const diffLines = buildDiffLines(before, after, displayLineCount);
|
|
47
|
+
const baseRanges = editRanges(fmr, after, displayLineCount, diffLines);
|
|
48
|
+
const visibleRanges = expandAndMerge(baseRanges, displayLineCount);
|
|
49
|
+
const syntaxHints = fmr.hints.filter((hint) => hint.source === "compiler" && hint.severity === "error");
|
|
50
|
+
const selectedSyntaxHints = selectSyntaxHints(syntaxHints, visibleRanges);
|
|
51
|
+
const allRanges = expandAndMerge(
|
|
52
|
+
[
|
|
53
|
+
...baseRanges,
|
|
54
|
+
...selectedSyntaxHints
|
|
55
|
+
.filter((hint) => !isLineVisible(hint.line, visibleRanges))
|
|
56
|
+
.map((hint) => ({ start: hint.line, end: hint.line })),
|
|
57
|
+
],
|
|
58
|
+
displayLineCount,
|
|
59
|
+
);
|
|
60
|
+
const added = diffLines.filter((line) => line.kind === "added").length;
|
|
61
|
+
const removed = diffLines.filter((line) => line.kind === "removed").length;
|
|
62
|
+
const entries: (string | PresentedTextRow)[] = [`${diffPath} +${added} -${removed}`];
|
|
63
|
+
const allowedSyntaxHints = new Set(selectedSyntaxHints);
|
|
64
|
+
const scopeMarkers = fmr.data.scopeMarkers ?? {};
|
|
65
|
+
|
|
66
|
+
for (let rangeIndex = 0; rangeIndex < allRanges.length; rangeIndex += 1)
|
|
67
|
+
{
|
|
68
|
+
if (rangeIndex > 0)
|
|
69
|
+
{
|
|
70
|
+
entries.push("...");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const range = allRanges[rangeIndex]!;
|
|
74
|
+
|
|
75
|
+
for (const line of diffLines)
|
|
76
|
+
{
|
|
77
|
+
if (!isDiffLineVisible(line, range))
|
|
78
|
+
{
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (line.kind === "removed")
|
|
83
|
+
{
|
|
84
|
+
entries.push({ marker: "-", prefix: "|", content: line.text });
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (presentedAfter !== undefined)
|
|
89
|
+
{
|
|
90
|
+
const presentedLine = presentedAfter.lines[line.afterLine! - 1];
|
|
91
|
+
const prefix = presentedLine?.presentation?.prefix ?? "";
|
|
92
|
+
const suffix = presentedLine?.presentation?.suffix ?? "";
|
|
93
|
+
const metadata = metadataForLine(
|
|
94
|
+
line.afterLine!,
|
|
95
|
+
fmr.hints,
|
|
96
|
+
visibleRanges,
|
|
97
|
+
allowedSyntaxHints,
|
|
98
|
+
);
|
|
99
|
+
const metadataSuffix = metadata.length > 0 ? ` ${metadata.join(" ")}` : "";
|
|
100
|
+
entries.push({
|
|
101
|
+
marker: line.kind === "added" ? "+" : " ",
|
|
102
|
+
prefix,
|
|
103
|
+
content: line.text,
|
|
104
|
+
suffix: `${suffix}${metadataSuffix}`,
|
|
105
|
+
});
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const lineNumber = line.afterLine!;
|
|
110
|
+
const metadata = metadataForLine(
|
|
111
|
+
lineNumber,
|
|
112
|
+
fmr.hints,
|
|
113
|
+
visibleRanges,
|
|
114
|
+
allowedSyntaxHints,
|
|
115
|
+
scopeMarkers[String(lineNumber)] ?? scopeMarkers[lineNumber],
|
|
116
|
+
);
|
|
117
|
+
const suffix = metadata.length > 0 ? ` ${metadata.join(" ")}` : "";
|
|
118
|
+
entries.push({
|
|
119
|
+
marker: line.kind === "added" ? "+" : " ",
|
|
120
|
+
prefix: "|",
|
|
121
|
+
content: line.text,
|
|
122
|
+
suffix,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return renderDiffEntries(entries);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function renderDiffEntries(entries: readonly (string | PresentedTextRow)[]): string[]
|
|
131
|
+
{
|
|
132
|
+
const renderedRows = renderPresentedTextRows(entries.filter(isPresentedTextRow));
|
|
133
|
+
let rowIndex = 0;
|
|
134
|
+
|
|
135
|
+
return entries.map((entry) =>
|
|
136
|
+
{
|
|
137
|
+
if (typeof entry === "string")
|
|
138
|
+
{
|
|
139
|
+
return entry;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return renderedRows[rowIndex++]!;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function isPresentedTextRow(entry: string | PresentedTextRow): entry is PresentedTextRow
|
|
147
|
+
{
|
|
148
|
+
return typeof entry !== "string";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function renderUnavailableSourceDiff(fmr: FileMutationResult, diffPath: string): string[]
|
|
152
|
+
{
|
|
153
|
+
const diff = fmr.diffs.find((value) => extractDiffPath(value) === diffPath) ?? fmr.diffs[0] ?? "";
|
|
154
|
+
const body = diff
|
|
155
|
+
.split("\n")
|
|
156
|
+
.filter((line) =>
|
|
157
|
+
!line.startsWith("--- ")
|
|
158
|
+
&& !line.startsWith("+++ ")
|
|
159
|
+
&& !line.startsWith("@@ ")
|
|
160
|
+
&& !line.startsWith("\\ No newline")
|
|
161
|
+
);
|
|
162
|
+
const added = body.filter((line) => line.startsWith("+")).length;
|
|
163
|
+
const removed = body.filter((line) => line.startsWith("-")).length;
|
|
164
|
+
const entries: (string | PresentedTextRow)[] = [`${diffPath} +${added} -${removed}`];
|
|
165
|
+
|
|
166
|
+
for (const line of body)
|
|
167
|
+
{
|
|
168
|
+
const marker = line[0];
|
|
169
|
+
|
|
170
|
+
if (marker !== "+" && marker !== "-" && marker !== " ")
|
|
171
|
+
{
|
|
172
|
+
entries.push(line);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
entries.push({ marker, prefix: "|", content: line.slice(1) });
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return renderDiffEntries(entries);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function buildDiffLines(before: string, after: string, afterLineCount: number): AgentDiffLine[]
|
|
183
|
+
{
|
|
184
|
+
const result: AgentDiffLine[] = [];
|
|
185
|
+
let beforeLine = 1;
|
|
186
|
+
let afterLine = 1;
|
|
187
|
+
|
|
188
|
+
for (const part of diffLines(before, after))
|
|
189
|
+
{
|
|
190
|
+
for (const text of splitPartLines(part.value))
|
|
191
|
+
{
|
|
192
|
+
if (part.added)
|
|
193
|
+
{
|
|
194
|
+
result.push({ kind: "added", text, afterLine, positionLine: afterLine });
|
|
195
|
+
afterLine += 1;
|
|
196
|
+
}
|
|
197
|
+
else if (part.removed)
|
|
198
|
+
{
|
|
199
|
+
const positionLine = Math.max(1, Math.min(afterLine, afterLineCount));
|
|
200
|
+
result.push({ kind: "removed", text, beforeLine, positionLine });
|
|
201
|
+
beforeLine += 1;
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
{
|
|
205
|
+
result.push({ kind: "context", text, beforeLine, afterLine, positionLine: afterLine });
|
|
206
|
+
beforeLine += 1;
|
|
207
|
+
afterLine += 1;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function editRanges(
|
|
216
|
+
fmr: FileMutationResult,
|
|
217
|
+
after: string,
|
|
218
|
+
afterLineCount: number,
|
|
219
|
+
diff: readonly AgentDiffLine[],
|
|
220
|
+
): LineRange[]
|
|
221
|
+
{
|
|
222
|
+
const rawChanges = fmr.data.rawChanges ?? [];
|
|
223
|
+
|
|
224
|
+
if (rawChanges.length > 0)
|
|
225
|
+
{
|
|
226
|
+
return rawChanges.map((change) => ({
|
|
227
|
+
start: lineAtOffset(after, change.fromB),
|
|
228
|
+
end: lineAtOffset(after, Math.max(change.fromB, change.toB - (change.toB > change.fromB ? 1 : 0))),
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const changedLines = diff
|
|
233
|
+
.filter((line) => line.kind !== "context")
|
|
234
|
+
.map((line) => line.positionLine);
|
|
235
|
+
|
|
236
|
+
if (changedLines.length === 0)
|
|
237
|
+
{
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return [{
|
|
242
|
+
start: Math.max(1, Math.min(...changedLines)),
|
|
243
|
+
end: Math.min(afterLineCount, Math.max(...changedLines)),
|
|
244
|
+
}];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function expandAndMerge(ranges: readonly LineRange[], lineCount: number): LineRange[]
|
|
248
|
+
{
|
|
249
|
+
if (lineCount === 0)
|
|
250
|
+
{
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const windows = ranges
|
|
255
|
+
.map((range) => ({
|
|
256
|
+
start: Math.max(1, Math.min(lineCount, range.start) - CONTEXT_LINES),
|
|
257
|
+
end: Math.min(lineCount, Math.max(range.start, range.end) + CONTEXT_LINES),
|
|
258
|
+
}))
|
|
259
|
+
.sort((left, right) => left.start - right.start);
|
|
260
|
+
|
|
261
|
+
if (windows.length === 0)
|
|
262
|
+
{
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const merged: LineRange[] = [windows[0]!];
|
|
267
|
+
|
|
268
|
+
for (const current of windows.slice(1))
|
|
269
|
+
{
|
|
270
|
+
const previous = merged.at(-1)!;
|
|
271
|
+
|
|
272
|
+
if (current.start <= previous.end + 1)
|
|
273
|
+
{
|
|
274
|
+
previous.end = Math.max(previous.end, current.end);
|
|
275
|
+
}
|
|
276
|
+
else
|
|
277
|
+
{
|
|
278
|
+
merged.push(current);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return merged;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function selectSyntaxHints(hints: readonly DiagnosticHint[], visibleRanges: readonly LineRange[]): DiagnosticHint[]
|
|
286
|
+
{
|
|
287
|
+
const visible = hints
|
|
288
|
+
.filter((hint) => isLineVisible(hint.line, visibleRanges))
|
|
289
|
+
.sort((left, right) => left.line - right.line);
|
|
290
|
+
const hidden = hints
|
|
291
|
+
.filter((hint) => !isLineVisible(hint.line, visibleRanges))
|
|
292
|
+
.sort(compareHints);
|
|
293
|
+
|
|
294
|
+
return [
|
|
295
|
+
...visible,
|
|
296
|
+
...hidden.slice(0, Math.max(0, MAX_SYNTAX_ERRORS - visible.length)),
|
|
297
|
+
];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function compareHints(left: DiagnosticHint, right: DiagnosticHint): number
|
|
301
|
+
{
|
|
302
|
+
return SEVERITY_RANK[left.severity] - SEVERITY_RANK[right.severity]
|
|
303
|
+
|| left.line - right.line
|
|
304
|
+
|| left.column - right.column
|
|
305
|
+
|| left.code.localeCompare(right.code);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function metadataForLine(
|
|
309
|
+
lineNumber: number,
|
|
310
|
+
hints: readonly DiagnosticHint[],
|
|
311
|
+
visibleRanges: readonly LineRange[],
|
|
312
|
+
allowedSyntaxHints: ReadonlySet<DiagnosticHint>,
|
|
313
|
+
scopeMarkers?: readonly string[],
|
|
314
|
+
): string[]
|
|
315
|
+
{
|
|
316
|
+
const metadata: string[] = [];
|
|
317
|
+
|
|
318
|
+
if (scopeMarkers !== undefined && scopeMarkers.length > 0)
|
|
319
|
+
{
|
|
320
|
+
metadata.push(`<!-- ${scopeMarkers.join(" ")} -->`);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const lineIsVisible = isLineVisible(lineNumber, visibleRanges);
|
|
324
|
+
const lineHints = hints.filter((hint) =>
|
|
325
|
+
hint.line === lineNumber && (lineIsVisible || allowedSyntaxHints.has(hint))
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
if (lineHints.length > 0)
|
|
329
|
+
{
|
|
330
|
+
metadata.push(
|
|
331
|
+
`<!-- lsp: ${lineHints.map((hint) => formatHint(hint, { includeAnchor: false })).join(" | ")} -->`,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return metadata;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function isDiffLineVisible(line: AgentDiffLine, range: LineRange): boolean
|
|
339
|
+
{
|
|
340
|
+
return line.positionLine >= range.start && line.positionLine <= range.end;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function isLineVisible(line: number, ranges: readonly LineRange[]): boolean
|
|
344
|
+
{
|
|
345
|
+
return ranges.some((range) => line >= range.start && line <= range.end);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function lineAtOffset(content: string, offset: number): number
|
|
349
|
+
{
|
|
350
|
+
const boundedOffset = Math.max(0, Math.min(content.length, offset));
|
|
351
|
+
return content.slice(0, boundedOffset).split("\n").length;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function splitLines(content: string): string[]
|
|
355
|
+
{
|
|
356
|
+
if (content.length === 0)
|
|
357
|
+
{
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const normalized = content.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
362
|
+
return normalized.endsWith("\n") ? normalized.slice(0, -1).split("\n") : normalized.split("\n");
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function splitPartLines(content: string): string[]
|
|
366
|
+
{
|
|
367
|
+
if (content.length === 0)
|
|
368
|
+
{
|
|
369
|
+
return [];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const normalized = content.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
373
|
+
const lines = normalized.split("\n");
|
|
374
|
+
|
|
375
|
+
if (lines.at(-1) === "")
|
|
376
|
+
{
|
|
377
|
+
lines.pop();
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return lines;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function extractDiffPath(diff: string): string | undefined
|
|
384
|
+
{
|
|
385
|
+
return /^--- (.+)$/m.exec(diff)?.[1];
|
|
386
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createTwoFilesPatch, diffLines } from "diff";
|
|
2
|
+
|
|
3
|
+
export interface DiffStats
|
|
4
|
+
{
|
|
5
|
+
removed: number;
|
|
6
|
+
added: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface UnifiedDiffResult
|
|
10
|
+
{
|
|
11
|
+
diff: string;
|
|
12
|
+
stats: DiffStats;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createUnifiedDiff(path: string, beforeContent: string, afterContent: string): UnifiedDiffResult
|
|
16
|
+
{
|
|
17
|
+
const diff = createTwoFilesPatch(path, path, beforeContent, afterContent, "", "", { context: 3 })
|
|
18
|
+
.replace(/^Index: .*\n={3,}\n?/m, "")
|
|
19
|
+
.trimEnd();
|
|
20
|
+
|
|
21
|
+
return { diff, stats: computeStats(beforeContent, afterContent) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function computeStats(beforeContent: string, afterContent: string): DiffStats
|
|
25
|
+
{
|
|
26
|
+
let removed = 0;
|
|
27
|
+
let added = 0;
|
|
28
|
+
|
|
29
|
+
for (const part of diffLines(beforeContent, afterContent))
|
|
30
|
+
{
|
|
31
|
+
const lineCount = countDiffLines(part.value);
|
|
32
|
+
|
|
33
|
+
if (part.removed)
|
|
34
|
+
{
|
|
35
|
+
removed += lineCount;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (part.added)
|
|
39
|
+
{
|
|
40
|
+
added += lineCount;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { removed, added };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function countDiffLines(value: string): number
|
|
48
|
+
{
|
|
49
|
+
if (value.length === 0)
|
|
50
|
+
{
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const normalized = value.replaceAll("\r\n", "\n");
|
|
55
|
+
return normalized.endsWith("\n") ? normalized.slice(0, -1).split("\n").length : normalized.split("\n").length;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ChangedRange
|
|
59
|
+
{
|
|
60
|
+
/** 1-based, inclusive — line number in the AFTER file */
|
|
61
|
+
start: number;
|
|
62
|
+
/** 1-based, inclusive — line number in the AFTER file */
|
|
63
|
+
end: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Compute the line ranges that changed in the AFTER file compared to the
|
|
68
|
+
* BEFORE file. Returns 1-based inclusive ranges in the AFTER file's line
|
|
69
|
+
* numbering. Adjacent ranges are merged into single islands.
|
|
70
|
+
*/
|
|
71
|
+
export function computeChangedRanges(beforeContent: string, afterContent: string): ChangedRange[]
|
|
72
|
+
{
|
|
73
|
+
const parts = diffLines(beforeContent, afterContent);
|
|
74
|
+
const ranges: ChangedRange[] = [];
|
|
75
|
+
let afterLine = 0;
|
|
76
|
+
|
|
77
|
+
for (const part of parts)
|
|
78
|
+
{
|
|
79
|
+
const lineCount = countDiffLines(part.value);
|
|
80
|
+
|
|
81
|
+
if (lineCount === 0)
|
|
82
|
+
{
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (part.removed)
|
|
87
|
+
{
|
|
88
|
+
// removed lines do not advance the AFTER cursor
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (part.added)
|
|
93
|
+
{
|
|
94
|
+
ranges.push({ start: afterLine + 1, end: afterLine + lineCount });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
afterLine += lineCount;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return mergeAdjacentRanges(ranges);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function mergeAdjacentRanges(ranges: ChangedRange[]): ChangedRange[]
|
|
104
|
+
{
|
|
105
|
+
if (ranges.length === 0)
|
|
106
|
+
{
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const sorted = [...ranges].sort((a, b) => a.start - b.start);
|
|
111
|
+
const merged: ChangedRange[] = [sorted[0]!];
|
|
112
|
+
|
|
113
|
+
for (let i = 1; i < sorted.length; i++)
|
|
114
|
+
{
|
|
115
|
+
const last = merged.at(-1)!;
|
|
116
|
+
const cur = sorted[i]!;
|
|
117
|
+
|
|
118
|
+
if (cur.start <= last.end + 1)
|
|
119
|
+
{
|
|
120
|
+
last.end = Math.max(last.end, cur.end);
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
{
|
|
124
|
+
merged.push(cur);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return merged;
|
|
129
|
+
}
|