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,127 @@
|
|
|
1
|
+
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
export type BatchCallEffect = "not-applied" | "applied" | "unknown";
|
|
4
|
+
|
|
5
|
+
export type BatchCallExecutionState =
|
|
6
|
+
| "pending"
|
|
7
|
+
| "running"
|
|
8
|
+
| "completed"
|
|
9
|
+
| "failed-not-applied"
|
|
10
|
+
| "failed-applied"
|
|
11
|
+
| "failed-unknown"
|
|
12
|
+
| "blocked";
|
|
13
|
+
|
|
14
|
+
export interface BatchCallFailure
|
|
15
|
+
{
|
|
16
|
+
readonly error: unknown;
|
|
17
|
+
readonly effect: BatchCallEffect;
|
|
18
|
+
readonly result?: AgentToolResult<unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface BatchCallExecutionEntry
|
|
22
|
+
{
|
|
23
|
+
readonly callId: string;
|
|
24
|
+
readonly state: BatchCallExecutionState;
|
|
25
|
+
readonly result?: AgentToolResult<unknown>;
|
|
26
|
+
readonly failure?: BatchCallFailure;
|
|
27
|
+
readonly blockedDetails?: unknown;
|
|
28
|
+
readonly recovered: boolean;
|
|
29
|
+
readonly reason?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface BatchExecutionReporter<TDetails = unknown>
|
|
33
|
+
{
|
|
34
|
+
start(callId: string): void;
|
|
35
|
+
complete(callId: string, result: AgentToolResult<TDetails>): void;
|
|
36
|
+
fail(callId: string, failure: BatchCallFailure): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class BatchExecutionJournal
|
|
40
|
+
{
|
|
41
|
+
private readonly entries: Map<string, BatchCallExecutionEntry>;
|
|
42
|
+
|
|
43
|
+
constructor(callIds: readonly string[])
|
|
44
|
+
{
|
|
45
|
+
this.entries = new Map(callIds.map((callId) => [callId, { callId, state: "pending", recovered: false }]));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
reporter(recovered = false): BatchExecutionReporter
|
|
49
|
+
{
|
|
50
|
+
return {
|
|
51
|
+
start: (callId) =>
|
|
52
|
+
{
|
|
53
|
+
this.transition(callId, { state: "running", recovered });
|
|
54
|
+
},
|
|
55
|
+
complete: (callId, result) =>
|
|
56
|
+
{
|
|
57
|
+
this.transition(callId, { state: "completed", result, recovered });
|
|
58
|
+
},
|
|
59
|
+
fail: (callId, failure) =>
|
|
60
|
+
{
|
|
61
|
+
this.transition(callId, {
|
|
62
|
+
state: `failed-${failure.effect}`,
|
|
63
|
+
failure,
|
|
64
|
+
...(failure.result === undefined ? {} : { result: failure.result }),
|
|
65
|
+
recovered,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
block(callId: string, result: AgentToolResult<unknown>, details?: unknown): void
|
|
72
|
+
{
|
|
73
|
+
this.transition(callId, { state: "blocked", result, blockedDetails: details, recovered: false });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
skip(callId: string, reason: string): void
|
|
77
|
+
{
|
|
78
|
+
this.transition(callId, {
|
|
79
|
+
state: "failed-not-applied",
|
|
80
|
+
failure: { error: new Error(reason), effect: "not-applied" },
|
|
81
|
+
recovered: false,
|
|
82
|
+
reason,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
markRunningUnknown(error: unknown): void
|
|
87
|
+
{
|
|
88
|
+
for (const entry of this.entries.values())
|
|
89
|
+
{
|
|
90
|
+
if (entry.state === "running")
|
|
91
|
+
{
|
|
92
|
+
this.transition(entry.callId, {
|
|
93
|
+
state: "failed-unknown",
|
|
94
|
+
failure: { error, effect: "unknown" },
|
|
95
|
+
recovered: entry.recovered,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get(callId: string): BatchCallExecutionEntry
|
|
102
|
+
{
|
|
103
|
+
const entry = this.entries.get(callId);
|
|
104
|
+
|
|
105
|
+
if (!entry)
|
|
106
|
+
{
|
|
107
|
+
throw new Error(`Unknown batch call ${callId}.`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return entry;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
snapshot(): readonly BatchCallExecutionEntry[]
|
|
114
|
+
{
|
|
115
|
+
return [...this.entries.values()].map((entry) => ({ ...entry }));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private transition(callId: string, update: Omit<BatchCallExecutionEntry, "callId">): void
|
|
119
|
+
{
|
|
120
|
+
if (!this.entries.has(callId))
|
|
121
|
+
{
|
|
122
|
+
throw new Error(`Unknown batch call ${callId}.`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.entries.set(callId, { callId, ...update });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BatchCallCandidate, OriginalToolCall } from "./text-edit-batch-coordinator.js";
|
|
2
|
+
import type { BatchCallExecutionEntry, BatchExecutionReporter } from "./text-edit-batch-execution.js";
|
|
3
|
+
import type { AgentToolResult, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
export interface BlockedToolCall
|
|
6
|
+
{
|
|
7
|
+
readonly callId: string;
|
|
8
|
+
readonly toolName: string;
|
|
9
|
+
readonly arguments: Record<string, unknown>;
|
|
10
|
+
readonly contentIndex?: number;
|
|
11
|
+
readonly batchEntryIndex?: number;
|
|
12
|
+
readonly details?: unknown;
|
|
13
|
+
readonly result: AgentToolResult<unknown>;
|
|
14
|
+
readonly nativeExecutionBlocked: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface BatchRecoveryInput<TState = unknown>
|
|
18
|
+
{
|
|
19
|
+
readonly batchId: string;
|
|
20
|
+
readonly calls: readonly OriginalToolCall[];
|
|
21
|
+
readonly candidates: readonly BatchCallCandidate<TState>[];
|
|
22
|
+
readonly journal: readonly BatchCallExecutionEntry[];
|
|
23
|
+
readonly blockedCalls: readonly BlockedToolCall[];
|
|
24
|
+
readonly cwd: string;
|
|
25
|
+
readonly signal: AbortSignal | undefined;
|
|
26
|
+
readonly ctx: ExtensionContext;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BatchRecoveryExecutionInput<TState = unknown> extends BatchRecoveryInput<TState>
|
|
30
|
+
{
|
|
31
|
+
readonly selected: readonly BatchCallCandidate<TState>[];
|
|
32
|
+
readonly reporter: BatchExecutionReporter;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface BatchRecoveryOutcome
|
|
36
|
+
{
|
|
37
|
+
readonly results: ReadonlyMap<string, AgentToolResult<unknown>>;
|
|
38
|
+
readonly skipped?: ReadonlyMap<string, string>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ToolBatchRecoveryDefinition<TState = unknown>
|
|
42
|
+
{
|
|
43
|
+
select(input: BatchRecoveryInput<TState>): readonly string[];
|
|
44
|
+
execute(input: BatchRecoveryExecutionInput<TState>): Promise<BatchRecoveryOutcome>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import { FileMutationAgentResult } from "#src/core/mutation-result/file-mutation-agent-result.js";
|
|
2
|
+
import { applyTextChanges, type TextChange, TextChangeDocument } from "#src/core/text-change-engine.js";
|
|
3
|
+
import {
|
|
4
|
+
executeWithBatchCoordinator,
|
|
5
|
+
registerBlockedToolCall,
|
|
6
|
+
registerToolBatch,
|
|
7
|
+
type ToolBatchDefinition,
|
|
8
|
+
} from "#src/core/text-edit-batch-coordinator.js";
|
|
9
|
+
import {
|
|
10
|
+
splitTextBatchResult,
|
|
11
|
+
type TextBatchDetails,
|
|
12
|
+
type TextBatchEntry,
|
|
13
|
+
type TextBatchParams,
|
|
14
|
+
} from "#src/core/text-edit-batch.js";
|
|
15
|
+
import { contextualizeTextMutationAnchorError } from "#src/core/text-mutation-anchor-error.js";
|
|
16
|
+
import {
|
|
17
|
+
buildFailedTextMutationResult,
|
|
18
|
+
buildSuccessfulTextMutationResult,
|
|
19
|
+
mutationSources,
|
|
20
|
+
} from "#src/core/text-mutation.js";
|
|
21
|
+
import { registerBlockedToolCallSink } from "#src/core/tool-call-interceptor/coordinator.js";
|
|
22
|
+
|
|
23
|
+
import type { TextEditIntent } from "#src/api/edit-completion.js";
|
|
24
|
+
import type { FileMutationResult } from "#src/api/mutation-result.js";
|
|
25
|
+
import type { AnyTextMutationToolRegistration, TextMutation } from "#src/api/mutation-tool.js";
|
|
26
|
+
import type { BatchExecutionReporter } from "#src/core/text-edit-batch-execution.js";
|
|
27
|
+
import type { TextEditorCore, TextResourceEditFailure, TextResourcesEditOutcome } from "#src/core/text-editor-core.js";
|
|
28
|
+
import type {
|
|
29
|
+
AgentToolResult,
|
|
30
|
+
AgentToolUpdateCallback,
|
|
31
|
+
ExtensionAPI,
|
|
32
|
+
ExtensionContext,
|
|
33
|
+
} from "@earendil-works/pi-coding-agent";
|
|
34
|
+
|
|
35
|
+
interface TextBatchState
|
|
36
|
+
{
|
|
37
|
+
readonly source: string;
|
|
38
|
+
readonly registration: AnyTextMutationToolRegistration;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface PlannedTextBatch
|
|
42
|
+
{
|
|
43
|
+
readonly mutations: readonly { readonly callId: string; readonly mutation: TextMutation; }[];
|
|
44
|
+
readonly failures: readonly {
|
|
45
|
+
readonly callId: string;
|
|
46
|
+
readonly source: string;
|
|
47
|
+
readonly error: unknown;
|
|
48
|
+
readonly effect: "applied" | "not-applied";
|
|
49
|
+
}[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const renderArgumentSinks = new WeakMap<
|
|
53
|
+
TextEditorCore,
|
|
54
|
+
(toolCallId: string, patch: Readonly<Record<string, unknown>>) => void
|
|
55
|
+
>();
|
|
56
|
+
|
|
57
|
+
export function setTextEditBatchRenderArgumentSink(
|
|
58
|
+
core: TextEditorCore,
|
|
59
|
+
sink: (toolCallId: string, patch: Readonly<Record<string, unknown>>) => void,
|
|
60
|
+
): void
|
|
61
|
+
{
|
|
62
|
+
renderArgumentSinks.set(core, sink);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function registerTextEditBatching(pi: ExtensionAPI, core: TextEditorCore): void
|
|
66
|
+
{
|
|
67
|
+
const sourceTools: string[] = [];
|
|
68
|
+
const registrations = new Map<string, AnyTextMutationToolRegistration>();
|
|
69
|
+
const renderArguments = (toolCallId: string, patch: Readonly<Record<string, unknown>>): void =>
|
|
70
|
+
renderArgumentSinks.get(core)?.(toolCallId, patch);
|
|
71
|
+
const definition: ToolBatchDefinition<TextBatchState> = {
|
|
72
|
+
sourceTools,
|
|
73
|
+
syntheticTool: "__pi_agent_text_editor_batch",
|
|
74
|
+
resolveCall(call, inherited)
|
|
75
|
+
{
|
|
76
|
+
const registration = registrations.get(call.name);
|
|
77
|
+
|
|
78
|
+
if (registration === undefined)
|
|
79
|
+
{
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const explicit = call.arguments[registration.source.field];
|
|
84
|
+
const inheritedSource = !(typeof explicit === "string" && explicit.length > 0)
|
|
85
|
+
&& registration.source.inherited
|
|
86
|
+
? inherited?.source
|
|
87
|
+
: undefined;
|
|
88
|
+
const source = typeof explicit === "string" && explicit.length > 0 ? explicit : inheritedSource;
|
|
89
|
+
|
|
90
|
+
return source === undefined
|
|
91
|
+
? undefined
|
|
92
|
+
: {
|
|
93
|
+
call,
|
|
94
|
+
state: { source, registration },
|
|
95
|
+
...(inheritedSource === undefined
|
|
96
|
+
? {}
|
|
97
|
+
: { renderArgumentPatch: { [registration.source.field]: inheritedSource } }),
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
buildArguments(calls)
|
|
101
|
+
{
|
|
102
|
+
const edits: TextBatchEntry[] = calls.map(({ call, state }) => ({
|
|
103
|
+
...call.arguments,
|
|
104
|
+
[state.registration.source.field]: state.source,
|
|
105
|
+
callId: call.id,
|
|
106
|
+
op: state.registration.name,
|
|
107
|
+
path: state.source,
|
|
108
|
+
}));
|
|
109
|
+
return { edits } satisfies TextBatchParams;
|
|
110
|
+
},
|
|
111
|
+
execute: (_toolCallId, params, signal, onUpdate, context, reporter) =>
|
|
112
|
+
executeRegisteredTextBatch(
|
|
113
|
+
core,
|
|
114
|
+
registrations,
|
|
115
|
+
params as unknown as TextBatchParams,
|
|
116
|
+
signal,
|
|
117
|
+
onUpdate,
|
|
118
|
+
context,
|
|
119
|
+
reporter,
|
|
120
|
+
),
|
|
121
|
+
splitResult: splitTextBatchResult,
|
|
122
|
+
onRenderArguments: renderArguments,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
core.onMutationTool((registration) =>
|
|
126
|
+
{
|
|
127
|
+
registrations.set(registration.name, registration);
|
|
128
|
+
sourceTools.push(registration.name);
|
|
129
|
+
});
|
|
130
|
+
registerBlockedToolCallSink(pi, registerBlockedToolCall);
|
|
131
|
+
registerToolBatch(pi, definition);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function executeRegisteredTextBatch(
|
|
135
|
+
core: TextEditorCore,
|
|
136
|
+
registrations: ReadonlyMap<string, AnyTextMutationToolRegistration>,
|
|
137
|
+
params: TextBatchParams,
|
|
138
|
+
signal: AbortSignal | undefined,
|
|
139
|
+
onUpdate: AgentToolUpdateCallback<TextBatchDetails> | undefined,
|
|
140
|
+
context: ExtensionContext,
|
|
141
|
+
reporter: BatchExecutionReporter,
|
|
142
|
+
): Promise<AgentToolResult<TextBatchDetails>>
|
|
143
|
+
{
|
|
144
|
+
const prepared = params.edits.map((entry) =>
|
|
145
|
+
{
|
|
146
|
+
const registration = registrations.get(entry.op);
|
|
147
|
+
|
|
148
|
+
if (registration === undefined)
|
|
149
|
+
{
|
|
150
|
+
throw new Error(`Unknown text mutation tool: ${entry.op}.`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const { callId, op: _op, ...input } = entry;
|
|
154
|
+
return { callId, input, registration, sources: mutationSources(registration, input) };
|
|
155
|
+
});
|
|
156
|
+
const intents = new Set(prepared.map(({ registration }) => registration.intent ?? "edit"));
|
|
157
|
+
const intent: TextEditIntent = intents.size > 1 ? "mixed" : intents.values().next().value ?? "edit";
|
|
158
|
+
const requests = new Map<string, { source: string; read: true; allowReadFailure?: true; }>();
|
|
159
|
+
|
|
160
|
+
for (const item of prepared)
|
|
161
|
+
{
|
|
162
|
+
for (const source of item.sources.values())
|
|
163
|
+
{
|
|
164
|
+
const current = requests.get(source);
|
|
165
|
+
const allowReadFailure = item.registration.name === "write"
|
|
166
|
+
&& source === item.sources.get(item.registration.source.field);
|
|
167
|
+
requests.set(source, {
|
|
168
|
+
source,
|
|
169
|
+
read: true,
|
|
170
|
+
...(current?.allowReadFailure === true || allowReadFailure ? { allowReadFailure: true } : {}),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
reporter.start(item.callId);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let outcome: TextResourcesEditOutcome<PlannedTextBatch>;
|
|
178
|
+
|
|
179
|
+
try
|
|
180
|
+
{
|
|
181
|
+
outcome = await core.editTexts(
|
|
182
|
+
[...requests.values()],
|
|
183
|
+
{ cwd: context.cwd, intent, ...(signal === undefined ? {} : { signal }) },
|
|
184
|
+
async (texts, resolveAnchor) =>
|
|
185
|
+
{
|
|
186
|
+
const mutations: { readonly callId: string; readonly mutation: TextMutation; }[] = [];
|
|
187
|
+
const failures: PlannedTextBatch["failures"][number][] = [];
|
|
188
|
+
const changes = new Map<string, TextChange[]>();
|
|
189
|
+
|
|
190
|
+
for (const item of prepared)
|
|
191
|
+
{
|
|
192
|
+
const sourceFor = (field: string): string =>
|
|
193
|
+
{
|
|
194
|
+
const source = item.sources.get(field);
|
|
195
|
+
|
|
196
|
+
if (source === undefined)
|
|
197
|
+
{
|
|
198
|
+
throw new Error(`Unknown mutation source field ${field}`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return source;
|
|
202
|
+
};
|
|
203
|
+
const documentFor = (source: string): TextChangeDocument =>
|
|
204
|
+
{
|
|
205
|
+
const text = texts.get(source);
|
|
206
|
+
|
|
207
|
+
if (text === undefined)
|
|
208
|
+
{
|
|
209
|
+
throw new Error(`Unknown mutation resource ${source}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return new TextChangeDocument(text);
|
|
213
|
+
};
|
|
214
|
+
const resolveAnchors = async (field: string) =>
|
|
215
|
+
{
|
|
216
|
+
const descriptor = (item.registration.anchors ?? []).find((anchor) => anchor.field === field);
|
|
217
|
+
const value = item.input[field];
|
|
218
|
+
const source = descriptor === undefined ? undefined : item.sources.get(descriptor.sourceField);
|
|
219
|
+
|
|
220
|
+
if (descriptor === undefined || typeof value !== "string" || source === undefined)
|
|
221
|
+
{
|
|
222
|
+
throw new Error(`Unable to resolve mutation anchor ${field}`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
try
|
|
226
|
+
{
|
|
227
|
+
return new Map([[source, await resolveAnchor(source, value, descriptor.kinds)]]);
|
|
228
|
+
}
|
|
229
|
+
catch (error)
|
|
230
|
+
{
|
|
231
|
+
throw contextualizeTextMutationAnchorError(
|
|
232
|
+
error,
|
|
233
|
+
item.registration.name,
|
|
234
|
+
field,
|
|
235
|
+
source,
|
|
236
|
+
value,
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
try
|
|
242
|
+
{
|
|
243
|
+
const mutation = await item.registration.mutate({
|
|
244
|
+
cwd: context.cwd,
|
|
245
|
+
...(signal === undefined ? {} : { signal }),
|
|
246
|
+
sourceDocument: documentFor(sourceFor(item.registration.source.field)),
|
|
247
|
+
sourceFor,
|
|
248
|
+
documentFor,
|
|
249
|
+
targetDocument: (field) => documentFor(sourceFor(field)),
|
|
250
|
+
resolveAnchors,
|
|
251
|
+
async resolveAnchor(field)
|
|
252
|
+
{
|
|
253
|
+
const resolved = await resolveAnchors(field);
|
|
254
|
+
return resolved.values().next().value!;
|
|
255
|
+
},
|
|
256
|
+
}, item.input);
|
|
257
|
+
mutations.push({ callId: item.callId, mutation });
|
|
258
|
+
|
|
259
|
+
for (const [source, edit] of mutation.edits)
|
|
260
|
+
{
|
|
261
|
+
changes.set(source, [...(changes.get(source) ?? []), ...edit.changes]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (error)
|
|
265
|
+
{
|
|
266
|
+
failures.push({
|
|
267
|
+
callId: item.callId,
|
|
268
|
+
source: item.sources.get(item.registration.source.field) ?? "",
|
|
269
|
+
error,
|
|
270
|
+
effect: "not-applied",
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return { changes, result: { mutations, failures } };
|
|
276
|
+
},
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
catch (error)
|
|
280
|
+
{
|
|
281
|
+
return failTextBatch(core, prepared.map(({ callId }) => callId), error, context, reporter);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (outcome.kind === "failed")
|
|
285
|
+
{
|
|
286
|
+
return failTextBatch(
|
|
287
|
+
core,
|
|
288
|
+
prepared.map(({ callId }) => callId),
|
|
289
|
+
outcome.failure,
|
|
290
|
+
context,
|
|
291
|
+
reporter,
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const completedMutations: PlannedTextBatch["mutations"][number][] = [];
|
|
296
|
+
const failures = [...outcome.result.failures];
|
|
297
|
+
|
|
298
|
+
for (const entry of outcome.result.mutations)
|
|
299
|
+
{
|
|
300
|
+
try
|
|
301
|
+
{
|
|
302
|
+
await entry.mutation.afterWrite?.();
|
|
303
|
+
completedMutations.push(entry);
|
|
304
|
+
}
|
|
305
|
+
catch (error)
|
|
306
|
+
{
|
|
307
|
+
failures.push({
|
|
308
|
+
callId: entry.callId,
|
|
309
|
+
source: entry.mutation.edits.keys().next().value ?? "",
|
|
310
|
+
error,
|
|
311
|
+
effect: "applied",
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const results: FileMutationResult[] = [];
|
|
317
|
+
const callIdsByResult: string[] = [];
|
|
318
|
+
|
|
319
|
+
for (const { callId, mutation } of completedMutations)
|
|
320
|
+
{
|
|
321
|
+
const callResults = [...mutation.edits].flatMap(([source, edit]) =>
|
|
322
|
+
{
|
|
323
|
+
const resource = outcome.resources.find((candidate) => candidate.source === source);
|
|
324
|
+
|
|
325
|
+
if (resource === undefined)
|
|
326
|
+
{
|
|
327
|
+
return [];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const ownAfter = applyTextChanges(resource.before.content, edit.changes).content;
|
|
331
|
+
return [buildSuccessfulTextMutationResult(resource, source, edit, ownAfter)];
|
|
332
|
+
});
|
|
333
|
+
const callResult = textBatchResult(callResults, callResults.map(() => callId));
|
|
334
|
+
reporter.complete(callId, callResult);
|
|
335
|
+
results.push(...callResults);
|
|
336
|
+
callIdsByResult.push(...callResults.map(() => callId));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
for (const failure of failures)
|
|
340
|
+
{
|
|
341
|
+
const failedResult = await buildFailedTextMutationResult(
|
|
342
|
+
core,
|
|
343
|
+
{
|
|
344
|
+
code: failure.effect === "applied" ? "POST_WRITE_FAILED" : "INVALID_REQUEST",
|
|
345
|
+
source: failure.source,
|
|
346
|
+
message: errorMessage(failure.error),
|
|
347
|
+
cause: failure.error,
|
|
348
|
+
},
|
|
349
|
+
context,
|
|
350
|
+
failure.effect,
|
|
351
|
+
);
|
|
352
|
+
const failureResults = failedResult.details.results ?? [];
|
|
353
|
+
reporter.fail(failure.callId, { error: failure.error, effect: failure.effect, result: failedResult });
|
|
354
|
+
results.push(...failureResults);
|
|
355
|
+
callIdsByResult.push(...failureResults.map(() => failure.callId));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
onUpdate?.({
|
|
359
|
+
content: [{ type: "text", text: "post-edit progress" }],
|
|
360
|
+
details: { results: [...results], callIdsByResult: [...callIdsByResult] },
|
|
361
|
+
});
|
|
362
|
+
return textBatchResult(results, callIdsByResult);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async function failTextBatch(
|
|
366
|
+
core: TextEditorCore,
|
|
367
|
+
callIds: readonly string[],
|
|
368
|
+
error: unknown,
|
|
369
|
+
context: ExtensionContext,
|
|
370
|
+
reporter: BatchExecutionReporter,
|
|
371
|
+
): Promise<AgentToolResult<TextBatchDetails>>
|
|
372
|
+
{
|
|
373
|
+
const cause = error;
|
|
374
|
+
const failure = isTextResourceEditFailure(error)
|
|
375
|
+
? error
|
|
376
|
+
: {
|
|
377
|
+
code: "INVALID_REQUEST" as const,
|
|
378
|
+
source: "",
|
|
379
|
+
message: errorMessage(cause),
|
|
380
|
+
cause,
|
|
381
|
+
};
|
|
382
|
+
const failedCallId = callIds[0];
|
|
383
|
+
const failedResult = await buildFailedTextMutationResult(core, failure, context);
|
|
384
|
+
|
|
385
|
+
for (const callId of callIds)
|
|
386
|
+
{
|
|
387
|
+
reporter.fail(callId, {
|
|
388
|
+
error: cause,
|
|
389
|
+
effect: "not-applied",
|
|
390
|
+
...(callId === failedCallId ? { result: failedResult } : {}),
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const results = failedResult.details.results ?? [];
|
|
395
|
+
return textBatchResult(results, results.map(() => failedCallId ?? ""));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function isTextResourceEditFailure(value: unknown): value is TextResourceEditFailure
|
|
399
|
+
{
|
|
400
|
+
return typeof value === "object"
|
|
401
|
+
&& value !== null
|
|
402
|
+
&& typeof (value as Partial<TextResourceEditFailure>).code === "string"
|
|
403
|
+
&& typeof (value as Partial<TextResourceEditFailure>).source === "string"
|
|
404
|
+
&& typeof (value as Partial<TextResourceEditFailure>).message === "string";
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function errorMessage(error: unknown): string
|
|
408
|
+
{
|
|
409
|
+
return error instanceof Error ? error.message : String(error);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function textBatchResult(
|
|
413
|
+
results: FileMutationResult[],
|
|
414
|
+
callIdsByResult: string[],
|
|
415
|
+
): AgentToolResult<TextBatchDetails>
|
|
416
|
+
{
|
|
417
|
+
return {
|
|
418
|
+
content: [new FileMutationAgentResult(results).toTextContent()],
|
|
419
|
+
details: { results, callIdsByResult },
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export function executeTextToolWithBatch<Result>(
|
|
424
|
+
toolCallId: string,
|
|
425
|
+
execute: () => Promise<AgentToolResult<Result>>,
|
|
426
|
+
signal: AbortSignal | undefined,
|
|
427
|
+
onUpdate: AgentToolUpdateCallback<Result> | undefined,
|
|
428
|
+
context: ExtensionContext,
|
|
429
|
+
): Promise<AgentToolResult<Result>>
|
|
430
|
+
{
|
|
431
|
+
return executeWithBatchCoordinator(toolCallId, execute, signal, onUpdate, context);
|
|
432
|
+
}
|