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,607 @@
|
|
|
1
|
+
import { BatchExecutionJournal, type BatchExecutionReporter } from "./text-edit-batch-execution.js";
|
|
2
|
+
|
|
3
|
+
import type { BlockedToolCall, ToolBatchRecoveryDefinition } from "./text-edit-batch-recovery.js";
|
|
4
|
+
import type {
|
|
5
|
+
AgentToolResult,
|
|
6
|
+
AgentToolUpdateCallback,
|
|
7
|
+
ExtensionAPI,
|
|
8
|
+
ExtensionContext,
|
|
9
|
+
} from "@earendil-works/pi-coding-agent";
|
|
10
|
+
|
|
11
|
+
function isObjectNotArray(value: unknown): value is Record<string, unknown>
|
|
12
|
+
{
|
|
13
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface OriginalToolCall
|
|
17
|
+
{
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly arguments: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface BatchCallCandidate<TState = unknown>
|
|
24
|
+
{
|
|
25
|
+
readonly call: OriginalToolCall;
|
|
26
|
+
readonly state: TState;
|
|
27
|
+
readonly renderArgumentPatch?: Readonly<Record<string, unknown>>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ToolBatchDefinition<TState = unknown>
|
|
31
|
+
{
|
|
32
|
+
readonly sourceTools: readonly string[];
|
|
33
|
+
readonly syntheticTool: string;
|
|
34
|
+
readonly resolveCall: (
|
|
35
|
+
call: OriginalToolCall,
|
|
36
|
+
inheritedState: TState | undefined,
|
|
37
|
+
) => BatchCallCandidate<TState> | undefined;
|
|
38
|
+
readonly buildArguments: (calls: readonly BatchCallCandidate<TState>[]) => Record<string, unknown>;
|
|
39
|
+
readonly execute: (
|
|
40
|
+
toolCallId: string,
|
|
41
|
+
params: Record<string, unknown>,
|
|
42
|
+
signal: AbortSignal | undefined,
|
|
43
|
+
onUpdate: AgentToolUpdateCallback<unknown> | undefined,
|
|
44
|
+
ctx: ExtensionContext,
|
|
45
|
+
reporter: BatchExecutionReporter,
|
|
46
|
+
) => Promise<AgentToolResult<unknown>>;
|
|
47
|
+
readonly splitResult?: (
|
|
48
|
+
aggregate: AgentToolResult<unknown>,
|
|
49
|
+
calls: readonly OriginalToolCall[],
|
|
50
|
+
candidates: readonly BatchCallCandidate<TState>[],
|
|
51
|
+
) => ReadonlyMap<string, AgentToolResult<unknown>>;
|
|
52
|
+
readonly onRenderArguments?: (
|
|
53
|
+
toolCallId: string,
|
|
54
|
+
patch: Readonly<Record<string, unknown>>,
|
|
55
|
+
) => void;
|
|
56
|
+
readonly recovery?: ToolBatchRecoveryDefinition<TState>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface RawToolCall
|
|
60
|
+
{
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly arguments: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface CoordinatorState
|
|
67
|
+
{
|
|
68
|
+
readonly definitions: ToolBatchDefinition[];
|
|
69
|
+
registered: boolean;
|
|
70
|
+
nextBatchId: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface BatchExecution
|
|
74
|
+
{
|
|
75
|
+
readonly aggregate?: AgentToolResult<unknown>;
|
|
76
|
+
readonly perCallResults?: ReadonlyMap<string, AgentToolResult<unknown>>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface BatchPlan
|
|
80
|
+
{
|
|
81
|
+
readonly definition: ToolBatchDefinition;
|
|
82
|
+
readonly candidates: readonly BatchCallCandidate[];
|
|
83
|
+
readonly calls: readonly OriginalToolCall[];
|
|
84
|
+
readonly carrierId: string;
|
|
85
|
+
readonly batchId: string;
|
|
86
|
+
readonly remainingCallIds: Set<string>;
|
|
87
|
+
readonly journal: BatchExecutionJournal;
|
|
88
|
+
readonly blockedCalls: BlockedToolCall[];
|
|
89
|
+
execution?: Promise<BatchExecution>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const batchPlans = new Map<string, BatchPlan>();
|
|
93
|
+
const coordinators = new WeakMap<object, CoordinatorState>();
|
|
94
|
+
const blockedToolCalls = new Map<string, BlockedToolCall>();
|
|
95
|
+
|
|
96
|
+
export function registerBlockedToolCall(blocked: BlockedToolCall): void
|
|
97
|
+
{
|
|
98
|
+
blockedToolCalls.set(blocked.callId, blocked);
|
|
99
|
+
const plan = batchPlans.get(blocked.callId);
|
|
100
|
+
|
|
101
|
+
if (plan && !plan.blockedCalls.some((item) => item.callId === blocked.callId))
|
|
102
|
+
{
|
|
103
|
+
plan.blockedCalls.push(blocked);
|
|
104
|
+
plan.journal.block(blocked.callId, blocked.result, blocked.details);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function clearCoordinatorCalls(): void
|
|
109
|
+
{
|
|
110
|
+
batchPlans.clear();
|
|
111
|
+
blockedToolCalls.clear();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function asRawToolCall(value: unknown): RawToolCall | undefined
|
|
115
|
+
{
|
|
116
|
+
if (
|
|
117
|
+
!isObjectNotArray(value) || value.type !== "toolCall" || typeof value.id !== "string"
|
|
118
|
+
|| typeof value.name !== "string"
|
|
119
|
+
)
|
|
120
|
+
{
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!isObjectNotArray(value.arguments))
|
|
125
|
+
{
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return { id: value.id, name: value.name, arguments: value.arguments };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function definitionFor(state: CoordinatorState, name: string): ToolBatchDefinition | undefined
|
|
133
|
+
{
|
|
134
|
+
return state.definitions.find((definition) => definition.sourceTools.includes(name));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function publishRenderArguments(definition: ToolBatchDefinition, candidate: BatchCallCandidate): void
|
|
138
|
+
{
|
|
139
|
+
if (candidate.renderArgumentPatch !== undefined)
|
|
140
|
+
{
|
|
141
|
+
definition.onRenderArguments?.(candidate.call.id, candidate.renderArgumentPatch);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function rewriteMessage(state: CoordinatorState, message: unknown, createPlans: boolean): unknown
|
|
146
|
+
{
|
|
147
|
+
if (!isObjectNotArray(message) || message.role !== "assistant" || !Array.isArray(message.content))
|
|
148
|
+
{
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const content = message.content;
|
|
153
|
+
let inheritedDefinition: ToolBatchDefinition | undefined;
|
|
154
|
+
let inheritedState: unknown;
|
|
155
|
+
|
|
156
|
+
for (let index = 0; index < content.length;)
|
|
157
|
+
{
|
|
158
|
+
const first = asRawToolCall(content[index]);
|
|
159
|
+
const definition = first ? definitionFor(state, first.name) : undefined;
|
|
160
|
+
const firstCandidate = first && definition
|
|
161
|
+
? definition.resolveCall(
|
|
162
|
+
first,
|
|
163
|
+
inheritedDefinition === definition ? inheritedState : undefined,
|
|
164
|
+
)
|
|
165
|
+
: undefined;
|
|
166
|
+
|
|
167
|
+
if (!definition || !firstCandidate)
|
|
168
|
+
{
|
|
169
|
+
inheritedDefinition = undefined;
|
|
170
|
+
inheritedState = undefined;
|
|
171
|
+
index += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
publishRenderArguments(definition, firstCandidate);
|
|
176
|
+
|
|
177
|
+
const run: BatchCallCandidate[] = [firstCandidate];
|
|
178
|
+
let nextIndex = index + 1;
|
|
179
|
+
|
|
180
|
+
while (nextIndex < content.length)
|
|
181
|
+
{
|
|
182
|
+
const next = asRawToolCall(content[nextIndex]);
|
|
183
|
+
|
|
184
|
+
if (!next || definitionFor(state, next.name) !== definition)
|
|
185
|
+
{
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const candidate = definition.resolveCall(next, run.at(-1)!.state);
|
|
190
|
+
|
|
191
|
+
if (!candidate)
|
|
192
|
+
{
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
publishRenderArguments(definition, candidate);
|
|
197
|
+
run.push(candidate);
|
|
198
|
+
nextIndex += 1;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const last = run.at(-1)!;
|
|
202
|
+
|
|
203
|
+
if (createPlans && run.length >= 2)
|
|
204
|
+
{
|
|
205
|
+
const calls = run.map(({ call }) => call);
|
|
206
|
+
const journal = new BatchExecutionJournal(calls.map((call) => call.id));
|
|
207
|
+
const blockedCalls = calls.flatMap((call) =>
|
|
208
|
+
{
|
|
209
|
+
const blocked = blockedToolCalls.get(call.id);
|
|
210
|
+
return blocked === undefined ? [] : [blocked];
|
|
211
|
+
});
|
|
212
|
+
const plan: BatchPlan = {
|
|
213
|
+
definition,
|
|
214
|
+
candidates: run,
|
|
215
|
+
calls,
|
|
216
|
+
carrierId: last.call.id,
|
|
217
|
+
batchId: `${String(Date.now())}-${String(state.nextBatchId++)}`,
|
|
218
|
+
remainingCallIds: new Set(calls.map((call) => call.id)),
|
|
219
|
+
journal,
|
|
220
|
+
blockedCalls,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
for (const blocked of blockedCalls)
|
|
224
|
+
{
|
|
225
|
+
journal.block(blocked.callId, blocked.result, blocked.details);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
for (const call of calls)
|
|
229
|
+
{
|
|
230
|
+
batchPlans.set(call.id, plan);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
inheritedDefinition = definition;
|
|
235
|
+
inheritedState = last.state;
|
|
236
|
+
index = nextIndex;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Keep the assistant message exactly as produced by the model. The batch
|
|
240
|
+
// exists only in the execution plan, never as a persisted synthetic call.
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function filterProviderTools(state: CoordinatorState, event: { payload?: unknown; }): unknown
|
|
245
|
+
{
|
|
246
|
+
const payload = event.payload;
|
|
247
|
+
|
|
248
|
+
if (!isObjectNotArray(payload) || !Array.isArray(payload.tools))
|
|
249
|
+
{
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const syntheticTools = new Set(state.definitions.map((definition) => definition.syntheticTool));
|
|
254
|
+
return {
|
|
255
|
+
...payload,
|
|
256
|
+
tools: payload.tools.filter((tool) =>
|
|
257
|
+
{
|
|
258
|
+
if (!isObjectNotArray(tool))
|
|
259
|
+
{
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const toolName = typeof tool.name === "string" ? tool.name : undefined;
|
|
264
|
+
const functionName = isObjectNotArray(tool.function) && typeof tool.function.name === "string"
|
|
265
|
+
? tool.function.name
|
|
266
|
+
: undefined;
|
|
267
|
+
|
|
268
|
+
if (toolName === undefined && functionName === undefined)
|
|
269
|
+
{
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return (toolName === undefined || !syntheticTools.has(toolName))
|
|
274
|
+
&& (functionName === undefined || !syntheticTools.has(functionName));
|
|
275
|
+
}),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
interface BatchDisplayCall
|
|
280
|
+
{
|
|
281
|
+
readonly id: string;
|
|
282
|
+
readonly name: string;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function markBatchResult<TDetails>(
|
|
286
|
+
result: AgentToolResult<TDetails>,
|
|
287
|
+
batchId: string,
|
|
288
|
+
calls: readonly BatchDisplayCall[],
|
|
289
|
+
): AgentToolResult<TDetails>
|
|
290
|
+
{
|
|
291
|
+
const details = isObjectNotArray(result.details) ? result.details : {};
|
|
292
|
+
return { ...result, details: { ...details, agenticIdeBatch: { batchId, calls } } as TDetails };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function batchDisplayCalls(plan: BatchPlan): BatchDisplayCall[]
|
|
296
|
+
{
|
|
297
|
+
return plan.calls.map((call) => ({ id: call.id, name: call.name }));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function ensureBatchExecution(
|
|
301
|
+
plan: BatchPlan,
|
|
302
|
+
signal: AbortSignal | undefined,
|
|
303
|
+
onUpdate: AgentToolUpdateCallback<unknown> | undefined,
|
|
304
|
+
ctx: ExtensionContext,
|
|
305
|
+
): Promise<BatchExecution>
|
|
306
|
+
{
|
|
307
|
+
plan.execution ??= (async () =>
|
|
308
|
+
{
|
|
309
|
+
let aggregate: AgentToolResult<unknown> | undefined;
|
|
310
|
+
let executionError: unknown;
|
|
311
|
+
|
|
312
|
+
try
|
|
313
|
+
{
|
|
314
|
+
const executable = plan.candidates.filter(({ call }) => plan.journal.get(call.id).state !== "blocked");
|
|
315
|
+
const params = plan.definition.buildArguments(executable);
|
|
316
|
+
aggregate = await plan.definition.execute(
|
|
317
|
+
plan.carrierId,
|
|
318
|
+
params,
|
|
319
|
+
signal,
|
|
320
|
+
onUpdate,
|
|
321
|
+
ctx,
|
|
322
|
+
plan.journal.reporter(),
|
|
323
|
+
);
|
|
324
|
+
const split = plan.definition.splitResult?.(aggregate, plan.calls, plan.candidates);
|
|
325
|
+
|
|
326
|
+
for (const [callId, result] of split ?? [])
|
|
327
|
+
{
|
|
328
|
+
if (plan.journal.get(callId).state === "completed")
|
|
329
|
+
{
|
|
330
|
+
plan.journal.reporter().complete(callId, result);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch (error)
|
|
335
|
+
{
|
|
336
|
+
executionError = error;
|
|
337
|
+
plan.journal.markRunningUnknown(error);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
await recoverBatch(plan, signal, ctx);
|
|
341
|
+
const perCallResults = finalBatchResults(plan, executionError);
|
|
342
|
+
return aggregate === undefined ? { perCallResults } : { aggregate, perCallResults };
|
|
343
|
+
})();
|
|
344
|
+
|
|
345
|
+
return plan.execution;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async function recoverBatch(plan: BatchPlan, signal: AbortSignal | undefined, ctx: ExtensionContext): Promise<void>
|
|
349
|
+
{
|
|
350
|
+
const recovery = plan.definition.recovery;
|
|
351
|
+
|
|
352
|
+
if (!recovery)
|
|
353
|
+
{
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const input = {
|
|
358
|
+
batchId: plan.batchId,
|
|
359
|
+
calls: plan.calls,
|
|
360
|
+
candidates: plan.candidates,
|
|
361
|
+
journal: plan.journal.snapshot(),
|
|
362
|
+
blockedCalls: plan.blockedCalls,
|
|
363
|
+
cwd: ctx.cwd,
|
|
364
|
+
signal,
|
|
365
|
+
ctx,
|
|
366
|
+
};
|
|
367
|
+
const requested = new Set(recovery.select(input));
|
|
368
|
+
const selected = plan.candidates.filter(({ call }) =>
|
|
369
|
+
{
|
|
370
|
+
const state = plan.journal.get(call.id).state;
|
|
371
|
+
return requested.has(call.id) && (state === "pending" || state === "failed-not-applied");
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
if (selected.length === 0)
|
|
375
|
+
{
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
try
|
|
380
|
+
{
|
|
381
|
+
const outcome = await recovery.execute({
|
|
382
|
+
...input,
|
|
383
|
+
selected,
|
|
384
|
+
reporter: plan.journal.reporter(true),
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
for (const [callId, result] of outcome.results)
|
|
388
|
+
{
|
|
389
|
+
if (selected.some(({ call }) => call.id === callId))
|
|
390
|
+
{
|
|
391
|
+
plan.journal.reporter(true).complete(callId, result);
|
|
392
|
+
}
|
|
393
|
+
else if (plan.journal.get(callId).state === "completed")
|
|
394
|
+
{
|
|
395
|
+
plan.journal.reporter().complete(callId, result);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
for (const [callId, reason] of outcome.skipped ?? [])
|
|
400
|
+
{
|
|
401
|
+
plan.journal.skip(callId, reason);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
catch (error)
|
|
405
|
+
{
|
|
406
|
+
for (const { call } of selected)
|
|
407
|
+
{
|
|
408
|
+
const state = plan.journal.get(call.id).state;
|
|
409
|
+
|
|
410
|
+
if (state === "pending" || state === "running" || state === "failed-not-applied")
|
|
411
|
+
{
|
|
412
|
+
plan.journal.reporter(true).fail(call.id, {
|
|
413
|
+
error,
|
|
414
|
+
effect: state === "running" ? "unknown" : "not-applied",
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function finalBatchResults(plan: BatchPlan, executionError: unknown): ReadonlyMap<string, AgentToolResult<unknown>>
|
|
422
|
+
{
|
|
423
|
+
return new Map(plan.calls.map((call) =>
|
|
424
|
+
{
|
|
425
|
+
const entry = plan.journal.get(call.id);
|
|
426
|
+
|
|
427
|
+
if (entry.result)
|
|
428
|
+
{
|
|
429
|
+
const details = isObjectNotArray(entry.result.details) ? entry.result.details : {};
|
|
430
|
+
return [call.id, {
|
|
431
|
+
...entry.result,
|
|
432
|
+
details: {
|
|
433
|
+
...details,
|
|
434
|
+
batchRecovery: {
|
|
435
|
+
batchId: plan.batchId,
|
|
436
|
+
state: entry.state,
|
|
437
|
+
recovered: entry.recovered,
|
|
438
|
+
...(entry.reason === undefined ? {} : { reason: entry.reason }),
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
}];
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const cause = entry.failure?.error ?? executionError ?? entry.reason;
|
|
445
|
+
const message = cause instanceof Error
|
|
446
|
+
? cause.message
|
|
447
|
+
: typeof cause === "string"
|
|
448
|
+
? cause
|
|
449
|
+
: "call did not execute";
|
|
450
|
+
return [call.id, {
|
|
451
|
+
content: [{ type: "text" as const, text: `${call.name} failed: ${message}` }],
|
|
452
|
+
details: {
|
|
453
|
+
batchRecovery: {
|
|
454
|
+
batchId: plan.batchId,
|
|
455
|
+
state: entry.state,
|
|
456
|
+
recovered: entry.recovered,
|
|
457
|
+
...(entry.reason === undefined ? {} : { reason: entry.reason }),
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
isError: true,
|
|
461
|
+
}];
|
|
462
|
+
}));
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function releaseBatchCall(plan: BatchPlan, toolCallId: string): void
|
|
466
|
+
{
|
|
467
|
+
plan.remainingCallIds.delete(toolCallId);
|
|
468
|
+
|
|
469
|
+
if (plan.remainingCallIds.size > 0)
|
|
470
|
+
{
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
for (const call of plan.calls)
|
|
475
|
+
{
|
|
476
|
+
batchPlans.delete(call.id);
|
|
477
|
+
blockedToolCalls.delete(call.id);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** Execute a planned batch once and return the result belonging to this call. */
|
|
482
|
+
export async function executeWithBatchCoordinator<TDetails>(
|
|
483
|
+
toolCallId: string,
|
|
484
|
+
directExecute: () => Promise<AgentToolResult<TDetails>>,
|
|
485
|
+
signal: AbortSignal | undefined,
|
|
486
|
+
onUpdate: AgentToolUpdateCallback<TDetails> | undefined,
|
|
487
|
+
ctx: ExtensionContext,
|
|
488
|
+
): Promise<AgentToolResult<TDetails>>
|
|
489
|
+
{
|
|
490
|
+
const plan = batchPlans.get(toolCallId);
|
|
491
|
+
|
|
492
|
+
if (!plan)
|
|
493
|
+
{
|
|
494
|
+
return directExecute();
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
try
|
|
498
|
+
{
|
|
499
|
+
if (
|
|
500
|
+
plan.definition.splitResult === undefined
|
|
501
|
+
&& plan.carrierId !== toolCallId
|
|
502
|
+
)
|
|
503
|
+
{
|
|
504
|
+
return {
|
|
505
|
+
content: [{ type: "text", text: "" }],
|
|
506
|
+
details: { agenticIdeBatchSuppressed: true },
|
|
507
|
+
} as AgentToolResult<TDetails>;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const execution = await ensureBatchExecution(
|
|
511
|
+
plan,
|
|
512
|
+
signal,
|
|
513
|
+
onUpdate as AgentToolUpdateCallback<unknown> | undefined,
|
|
514
|
+
ctx,
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
if (plan.definition.splitResult !== undefined)
|
|
518
|
+
{
|
|
519
|
+
const result = execution.perCallResults?.get(toolCallId);
|
|
520
|
+
|
|
521
|
+
if (!result)
|
|
522
|
+
{
|
|
523
|
+
throw new Error(`Missing split batch result for tool call ${toolCallId}.`);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return markBatchResult(result as AgentToolResult<TDetails>, plan.batchId, batchDisplayCalls(plan));
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (!execution.aggregate)
|
|
530
|
+
{
|
|
531
|
+
return await directExecute();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return execution.aggregate as AgentToolResult<TDetails>;
|
|
535
|
+
}
|
|
536
|
+
finally
|
|
537
|
+
{
|
|
538
|
+
releaseBatchCall(plan, toolCallId);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** Get or create the coordinator state for one extension instance. */
|
|
543
|
+
function coordinatorFor(pi: ExtensionAPI): CoordinatorState
|
|
544
|
+
{
|
|
545
|
+
let state = coordinators.get(pi);
|
|
546
|
+
|
|
547
|
+
if (!state)
|
|
548
|
+
{
|
|
549
|
+
const created: CoordinatorState = {
|
|
550
|
+
definitions: [],
|
|
551
|
+
registered: false,
|
|
552
|
+
nextBatchId: 1,
|
|
553
|
+
};
|
|
554
|
+
coordinators.set(pi, created);
|
|
555
|
+
state = created;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (!state.registered)
|
|
559
|
+
{
|
|
560
|
+
state.registered = true;
|
|
561
|
+
pi.on("message_update", (event) =>
|
|
562
|
+
{
|
|
563
|
+
rewriteMessage(state, event.message, false);
|
|
564
|
+
return;
|
|
565
|
+
});
|
|
566
|
+
pi.on("message_end", (event) =>
|
|
567
|
+
{
|
|
568
|
+
rewriteMessage(state, event.message, true);
|
|
569
|
+
return;
|
|
570
|
+
});
|
|
571
|
+
pi.on("before_provider_request", (event) => filterProviderTools(state, event));
|
|
572
|
+
pi.on("agent_end", () =>
|
|
573
|
+
{
|
|
574
|
+
clearCoordinatorCalls();
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return state;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** Register one batch family with the coordinator. */
|
|
582
|
+
export function registerToolBatch<TState>(pi: ExtensionAPI, definition: ToolBatchDefinition<TState>): void
|
|
583
|
+
{
|
|
584
|
+
const state = coordinatorFor(pi);
|
|
585
|
+
const definitionForCoordinator: ToolBatchDefinition = {
|
|
586
|
+
sourceTools: definition.sourceTools,
|
|
587
|
+
syntheticTool: definition.syntheticTool,
|
|
588
|
+
resolveCall: (call, inheritedState) => definition.resolveCall(call, inheritedState as TState | undefined),
|
|
589
|
+
buildArguments: (calls) => definition.buildArguments(calls as readonly BatchCallCandidate<TState>[]),
|
|
590
|
+
execute: definition.execute,
|
|
591
|
+
...(definition.onRenderArguments === undefined
|
|
592
|
+
? {}
|
|
593
|
+
: { onRenderArguments: definition.onRenderArguments }),
|
|
594
|
+
...(definition.recovery === undefined ? {} : { recovery: definition.recovery }),
|
|
595
|
+
...(definition.splitResult === undefined
|
|
596
|
+
? {}
|
|
597
|
+
: {
|
|
598
|
+
splitResult: (aggregate, calls, candidates) =>
|
|
599
|
+
definition.splitResult!(
|
|
600
|
+
aggregate,
|
|
601
|
+
calls,
|
|
602
|
+
candidates as readonly BatchCallCandidate<TState>[],
|
|
603
|
+
),
|
|
604
|
+
}),
|
|
605
|
+
};
|
|
606
|
+
state.definitions.push(definitionForCoordinator);
|
|
607
|
+
}
|