pi-agent-ide 0.2.2 → 0.4.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/CHANGELOG.md +46 -0
- package/README.md +13 -8
- package/dist/chunk-3SE372WC.js +3 -0
- package/dist/chunk-5MSNYFDE.js +1 -0
- package/dist/chunk-5VSE5X5R.js +2 -0
- package/dist/chunk-6DZA4CLO.js +4 -0
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
- package/dist/chunk-7JYQMAEL.js +14 -0
- package/dist/{chunk-T2RPMEM2.js → chunk-7UGNGK7Y.js} +1 -1
- package/dist/{chunk-STUZZM5B.js → chunk-AADJ2KIB.js} +1 -1
- package/dist/{chunk-XF5PVZOS.js → chunk-B5KB2I7J.js} +1 -1
- package/dist/chunk-DQF5QMJ2.js +1 -0
- package/dist/chunk-EJ5OACQM.js +1 -0
- package/dist/chunk-GFW5QPQV.js +2 -0
- package/dist/{chunk-LQYZG62K.js → chunk-GUTQ3PWL.js} +1 -1
- package/dist/chunk-HGPUI7F3.js +1 -0
- package/dist/{chunk-OBWZ5RYN.js → chunk-HKMBQLEK.js} +1 -1
- package/dist/chunk-ITSNK5YG.js +7 -0
- package/dist/chunk-J34VKQGJ.js +1 -0
- package/dist/chunk-KAB3AYA2.js +1 -0
- package/dist/{chunk-76WHES5H.js → chunk-M5L42DWE.js} +5 -5
- package/dist/chunk-M5MJP7Z2.js +1 -0
- package/dist/chunk-NMFQGKPE.js +2 -0
- package/dist/chunk-NTYXZ3EL.js +3 -0
- package/dist/{chunk-P6T3Q7LB.js → chunk-QDST6VIU.js} +1 -1
- package/dist/chunk-ROXXK6TW.js +0 -0
- package/dist/{chunk-WNMGUALD.js → chunk-TI5GMJ7Q.js} +1 -1
- package/dist/{chunk-4ZTEPMJO.js → chunk-TPIHQYK2.js} +1 -1
- package/dist/chunk-XSTHESNR.js +25 -0
- package/dist/{chunk-THSCUT2L.js → chunk-Y7ZMR4LT.js} +1 -1
- package/dist/chunk-YHADTHQM.js +1 -0
- package/dist/{chunk-KZBAJFCV.js → chunk-Z3VC3S2T.js} +1 -1
- package/dist/{chunk-ZXN3TWWW.js → chunk-ZM4L5AGN.js} +1 -1
- package/dist/{chunk-E2RESHYR.js → chunk-ZTYWHL2F.js} +1 -1
- package/dist/entry-0.js +1 -1
- package/dist/entry-1.js +1 -1
- package/dist/entry-10.js +1 -1
- package/dist/entry-12.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-2.js +1 -1
- package/dist/entry-21.js +1 -1
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +10 -5
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-31.js +3 -3
- package/dist/entry-32.js +6 -5
- package/dist/entry-36.js +1 -1
- package/dist/entry-37.js +1 -1
- package/dist/entry-38.js +1 -1
- package/dist/entry-39.js +1 -1
- package/dist/entry-4.js +1 -1
- package/dist/entry-40.js +12 -8
- package/dist/entry-42.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +4 -4
- package/dist/entry-46.js +10 -10
- package/dist/entry-47.js +1 -1
- package/dist/entry-48.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -0
- package/dist/entry-55.js +0 -1
- package/dist/entry-56.js +1 -0
- package/dist/entry-57.js +0 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-63.js +1 -0
- package/dist/entry-64.js +0 -1
- package/dist/entry-65.js +1 -0
- package/dist/entry-66.js +0 -1
- package/dist/entry-67.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -59
- package/dist/entry-70.js +123 -4
- package/dist/entry-71.js +30 -1
- package/dist/entry-72.js +2 -29
- package/dist/entry-73.js +1 -2
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +3 -1
- package/dist/entry-77.js +1 -3
- package/dist/entry-78.js +1 -1
- package/dist/entry-79.js +1 -1
- package/dist/pi-agent-ide.js +3 -2
- package/docs/configuration.md +32 -11
- package/docs/tools.md +17 -0
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-filesystem/package.json +6 -6
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/package.json +9 -9
- package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -3
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
- package/node_modules/pi-agent-ide-changes/index.ts +21 -5
- package/node_modules/pi-agent-ide-changes/package.json +6 -6
- package/node_modules/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +26 -8
- package/node_modules/pi-agent-ide-formatter/src/registry.ts +9 -1
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/index.ts +46 -17
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lint/src/registry.ts +9 -1
- package/node_modules/pi-agent-ide-lsp/index.ts +126 -8
- package/node_modules/pi-agent-ide-lsp/package.json +9 -8
- package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
- package/node_modules/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
- package/node_modules/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +6 -6
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +29 -0
- package/node_modules/pi-agent-read/src/api/tools/read.ts +73 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +26 -2
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
- package/node_modules/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +73 -44
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/resolver.ts +2 -0
- package/node_modules/pi-agent-resource/src/resource.ts +2 -0
- package/node_modules/pi-agent-search/package.json +3 -3
- package/node_modules/pi-agent-search/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +25 -0
- package/node_modules/pi-agent-search/src/api/search.ts +55 -1
- package/node_modules/pi-agent-search/src/core/extension.ts +2 -23
- package/node_modules/pi-agent-search/src/core/search-core.ts +28 -3
- package/node_modules/pi-agent-search-text/index.ts +44 -4
- package/node_modules/pi-agent-search-text/package.json +6 -6
- package/node_modules/pi-agent-search-text/src/search-session.ts +65 -25
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text/src/text-document.ts +5 -0
- package/node_modules/pi-agent-text/src/text-target.ts +4 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
- package/node_modules/pi-agent-text-editor/index.ts +1 -3
- package/node_modules/pi-agent-text-editor/package.json +34 -24
- package/node_modules/pi-agent-text-editor/runtime/entry-69.js +0 -1
- package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
- package/node_modules/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
- package/node_modules/pi-agent-text-editor/src/api/post-edit.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +216 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +133 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +6 -0
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +153 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
- package/node_modules/pi-agent-text-editor-renderer/index.ts +88 -1
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
- package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +1 -0
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web/runtime/entry-75.js +2 -0
- package/node_modules/pi-agent-web/src/browser-loader.ts +1 -0
- package/node_modules/pi-agent-web-html/package.json +3 -3
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/package.json +41 -38
- package/src/api/plugin-protocol.ts +10 -2
- package/src/api/tool-config.ts +73 -2
- package/src/code-view/diagnostic-view.ts +22 -3
- package/src/composite/builtin-extensions.ts +10 -15
- package/src/composite/extensions-config.ts +59 -0
- package/src/composite/feature-flags.ts +32 -0
- package/src/composite/module-labels.ts +59 -0
- package/src/composite/module-settings-store.ts +60 -0
- package/src/composite/module-settings.ts +162 -0
- package/src/composite/preferences.ts +26 -0
- package/src/composite/selection.ts +4 -4
- package/src/composite/settings-panel.ts +103 -0
- package/src/core/diagnostic-delivery.ts +29 -0
- package/src/core/diagnostic-entry.ts +51 -3
- package/src/core/diagnostic-store.ts +56 -5
- package/src/core/extension.ts +34 -33
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +6 -6
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/browser-loader.ts +1 -0
- package/src/extensions/pi-agent-read/package.json +6 -6
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +29 -0
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +73 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +26 -2
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +1 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +113 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +64 -14
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +15 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +35 -126
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +73 -44
- package/src/extensions/pi-agent-search/package.json +3 -3
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +44 -4
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +6 -6
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +65 -25
- package/src/extensions/pi-agent-search/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +25 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +55 -1
- package/src/extensions/pi-agent-search/src/core/extension.ts +2 -23
- package/src/extensions/pi-agent-search/src/core/search-core.ts +28 -3
- package/src/extensions/pi-agent-text-editor/index.ts +1 -3
- package/src/extensions/pi-agent-text-editor/package.json +34 -24
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/src/read-handler.ts +1 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +88 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +42 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +20 -12
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +33 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/runtime/entry-69.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +15 -0
- package/src/extensions/pi-agent-text-editor/src/api/last-resolved-resource.ts +5 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +15 -1
- package/src/extensions/pi-agent-text-editor/src/api/post-edit.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/api/tool-renderer.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +237 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +50 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +208 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +39 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +216 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +45 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +25 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +324 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +133 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +112 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +132 -0
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +205 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +6 -0
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +76 -0
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +153 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/diff.ts +5 -2
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +73 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +10 -2
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +17 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +212 -51
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +273 -11
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +1 -1
- package/src/pi-agent-ide.ts +43 -8
- package/src/plugins/pi-agent-ide-ast/package.json +9 -9
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -3
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +68 -45
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
- package/src/plugins/pi-agent-ide-changes/index.ts +21 -5
- package/src/plugins/pi-agent-ide-changes/package.json +6 -6
- package/src/plugins/pi-agent-ide-changes/src/last-text-transaction-store.ts +10 -0
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +4 -2
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -11
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +26 -8
- package/src/plugins/pi-agent-ide-formatter/src/registry.ts +9 -1
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/index.ts +46 -17
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lint/src/registry.ts +9 -1
- package/src/plugins/pi-agent-ide-lsp/index.ts +126 -8
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -8
- package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +61 -0
- package/src/plugins/pi-agent-ide-lsp/src/diagnostic-source.ts +18 -3
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +4 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/code-views.ts +40 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +21 -32
- package/src/plugins/pi-agent-ide-lsp/src/lsp/registry.ts +15 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/rename.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +32 -5
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +138 -0
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +9 -2
- package/src/plugins/pi-agent-ide-terminal/index.ts +34 -0
- package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +238 -0
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +461 -0
- package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +127 -0
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +159 -0
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +529 -0
- package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +56 -0
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +157 -0
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +66 -0
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +336 -0
- package/src/post-edit/gate.ts +15 -2
- package/dist/chunk-4U6KGABH.js +0 -1
- package/dist/chunk-6ACQQBUY.js +0 -7
- package/dist/chunk-GFWDXTOB.js +0 -4
- package/dist/chunk-JASLOB2X.js +0 -1
- package/dist/chunk-JJVXUL5U.js +0 -2
- package/dist/chunk-KCEOTU5Z.js +0 -3
- package/dist/chunk-KVGQG43U.js +0 -1
- package/dist/chunk-QJFRAMK7.js +0 -2
- package/dist/chunk-RAZOACDD.js +0 -2
- package/dist/chunk-RIGRP3FD.js +0 -1
- package/dist/chunk-VCCMVQXU.js +0 -1
- package/dist/chunk-X6MPU7UO.js +0 -3
- package/dist/chunk-YPHXLAQF.js +0 -1
- package/dist/entry-80.js +0 -1
- package/node_modules/pi-agent-text-editor/src/core/tool-description.ts +0 -14
- package/node_modules/pi-agent-text-editor-argument-order/index.ts +0 -26
- package/node_modules/pi-agent-text-editor-argument-order/package.json +0 -16
- package/node_modules/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
- package/node_modules/pi-agent-text-editor-overwrite/index.ts +0 -365
- package/node_modules/pi-agent-text-editor-overwrite/package.json +0 -17
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +0 -1
- package/node_modules/pi-agent-web-text/runtime/entry-80.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/index.ts +0 -26
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/package.json +0 -16
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/runtime/entry-70.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-argument-order/src/argument-order-guard.ts +0 -100
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/index.ts +0 -365
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-overwrite/package.json +0 -17
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +0 -2
- package/src/extensions/pi-agent-text-editor/src/core/tool-description.ts +0 -14
- /package/dist/{chunk-3H2EU7VQ.js → chunk-4U2GUKNJ.js} +0 -0
- /package/node_modules/{pi-agent-text-editor-argument-order → pi-agent-text-editor}/runtime/entry-70.js +0 -0
- /package/node_modules/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
- /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-74.js +0 -0
- /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-76.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-77.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-78.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-overwrite → pi-agent-text-editor-renderer}/runtime/entry-71.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-72.js +0 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { isDiffOutcome, diffPresentation } from "#src/core/diff-tool.js";
|
|
2
|
+
import { createApplySourceProjection, type ApplyCallPreview } from "./mixed-source.js";
|
|
3
|
+
import { isFileOperationResult, formatFileOperation } from "#src/core/file-operations.js";
|
|
4
|
+
import { createReadResultRenderer } from "pi-agent-read/api/rendering";
|
|
5
|
+
import type { ReadToolResult } from "pi-agent-read/api/tools/read";
|
|
6
|
+
import { Text, type Component } from "@earendil-works/pi-tui";
|
|
7
|
+
import type { FileMutationBatchResult } from "#src/api/mutation-result.js";
|
|
8
|
+
import { finalApplyMutations } from "./final-mutations.js";
|
|
9
|
+
import { highlightCode, type Theme, type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import { wrapTextWithAnsi, visibleWidth, truncateToWidth } from "@earendil-works/pi-tui";
|
|
11
|
+
import { preserveEnclosingBackground } from "pi-agent-tool-ui";
|
|
12
|
+
import type { ApplyResults } from "./results.js";
|
|
13
|
+
import type { ApplyOutput } from "./output.js";
|
|
14
|
+
|
|
15
|
+
/** Deliberate user presentation, separate from model-facing operation receipts. */
|
|
16
|
+
export interface ApplyDisplay {
|
|
17
|
+
readonly blocks: readonly { readonly text: string; readonly read?: ReadToolResult }[];
|
|
18
|
+
readonly mutations?: FileMutationBatchResult;
|
|
19
|
+
readonly comparisons?: readonly FileMutationBatchResult[];
|
|
20
|
+
readonly cwd?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Build readable result blocks without exposing internal mutation receipts. */
|
|
24
|
+
export function createApplyDisplay(
|
|
25
|
+
results: ApplyResults,
|
|
26
|
+
output: ApplyOutput,
|
|
27
|
+
error?: unknown,
|
|
28
|
+
cwd = process.cwd(),
|
|
29
|
+
): ApplyDisplay {
|
|
30
|
+
const selected = results.select();
|
|
31
|
+
const diffEntries = [
|
|
32
|
+
...selected.automatic,
|
|
33
|
+
...selected.explicit.filter((entry) => entry.kind === "operation"),
|
|
34
|
+
].filter((entry) => isDiffOutcome(entry.value) && !entry.value.equal);
|
|
35
|
+
const comparisons = diffEntries.flatMap((entry) =>
|
|
36
|
+
isDiffOutcome(entry.value) ? [diffPresentation(entry.value, cwd)] : [],
|
|
37
|
+
);
|
|
38
|
+
const diffBlocks = new Set(diffEntries.flatMap((entry) => entry.presentation?.content ?? []));
|
|
39
|
+
if (selected.files.length === 0) {
|
|
40
|
+
const reads = [
|
|
41
|
+
...selected.automatic.map((entry) => entry.presentation),
|
|
42
|
+
...selected.explicit.map((entry) =>
|
|
43
|
+
entry.kind === "operation" ? entry.presentation : undefined,
|
|
44
|
+
),
|
|
45
|
+
].filter((read): read is ReadToolResult => read !== undefined);
|
|
46
|
+
return {
|
|
47
|
+
comparisons,
|
|
48
|
+
cwd,
|
|
49
|
+
blocks: output.content
|
|
50
|
+
.filter((block) => !diffBlocks.has(block))
|
|
51
|
+
.flatMap((block) =>
|
|
52
|
+
block.type === "text"
|
|
53
|
+
? [
|
|
54
|
+
{
|
|
55
|
+
text: block.text,
|
|
56
|
+
read: reads.find((read) => read.content.includes(block)),
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
: [],
|
|
60
|
+
),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const mutations = finalApplyMutations(results);
|
|
64
|
+
return {
|
|
65
|
+
...(mutations.length > 0 ? { mutations: { results: mutations } } : {}),
|
|
66
|
+
comparisons,
|
|
67
|
+
cwd,
|
|
68
|
+
blocks: [
|
|
69
|
+
...selected.explicit.flatMap((entry) => {
|
|
70
|
+
if (entry.kind === "operation" && isDiffOutcome(entry.value) && !entry.value.equal)
|
|
71
|
+
return [];
|
|
72
|
+
if (isFileOperationResult(entry.value)) return [{ text: formatFileOperation(entry.value) }];
|
|
73
|
+
if (entry.kind === "operation")
|
|
74
|
+
return (
|
|
75
|
+
entry.presentation?.content.flatMap((block) =>
|
|
76
|
+
block.type === "text" ? [{ text: block.text, read: entry.presentation }] : [],
|
|
77
|
+
) ?? []
|
|
78
|
+
);
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
text:
|
|
82
|
+
typeof entry.value === "string"
|
|
83
|
+
? entry.value
|
|
84
|
+
: entry.value === undefined
|
|
85
|
+
? "undefined"
|
|
86
|
+
: JSON.stringify(entry.value, null, 2),
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
}),
|
|
90
|
+
...selected.automatic.flatMap(({ value, presentation }) => {
|
|
91
|
+
if (isFileOperationResult(value)) return [{ text: formatFileOperation(value) }];
|
|
92
|
+
if (
|
|
93
|
+
value !== null &&
|
|
94
|
+
typeof value === "object" &&
|
|
95
|
+
"kind" in value &&
|
|
96
|
+
value.kind === "index-operation"
|
|
97
|
+
)
|
|
98
|
+
return (
|
|
99
|
+
presentation?.content.flatMap((block) =>
|
|
100
|
+
block.type === "text" ? [{ text: block.text }] : [],
|
|
101
|
+
) ?? []
|
|
102
|
+
);
|
|
103
|
+
if (
|
|
104
|
+
value === null ||
|
|
105
|
+
typeof value !== "object" ||
|
|
106
|
+
!("errors" in value) ||
|
|
107
|
+
!Array.isArray(value.errors)
|
|
108
|
+
)
|
|
109
|
+
return [];
|
|
110
|
+
return value.errors.flatMap((error: unknown) =>
|
|
111
|
+
error !== null &&
|
|
112
|
+
typeof error === "object" &&
|
|
113
|
+
"message" in error &&
|
|
114
|
+
typeof error.message === "string"
|
|
115
|
+
? [{ text: error.message }]
|
|
116
|
+
: [],
|
|
117
|
+
);
|
|
118
|
+
}),
|
|
119
|
+
...(error === undefined
|
|
120
|
+
? []
|
|
121
|
+
: [{ text: error instanceof Error ? error.message : JSON.stringify(error) }]),
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type RenderState = {
|
|
127
|
+
applyResultReady?: boolean;
|
|
128
|
+
displaySource?: string;
|
|
129
|
+
codeView?: boolean;
|
|
130
|
+
projectSource?: (source: string) => string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** Width-safe rows sharing one frame across the call and its appended result. */
|
|
134
|
+
export function applyFrameRows(
|
|
135
|
+
source: string,
|
|
136
|
+
theme: Theme,
|
|
137
|
+
width: number,
|
|
138
|
+
part: "call" | "result",
|
|
139
|
+
finish: boolean,
|
|
140
|
+
language?: string,
|
|
141
|
+
failed = false,
|
|
142
|
+
): string[] {
|
|
143
|
+
const size = Math.max(1, width);
|
|
144
|
+
if (size < 5) return source.split("\n").flatMap((line) => wrapTextWithAnsi(line, size));
|
|
145
|
+
const inner = size - 4;
|
|
146
|
+
const border = (value: string) => theme.fg("borderMuted", value);
|
|
147
|
+
const heading = part === "call" ? "Apply · JavaScript" : "Result";
|
|
148
|
+
const title = truncateToWidth(` ${heading} `, size - 4, "");
|
|
149
|
+
const rows = [
|
|
150
|
+
border(`${part === "call" ? "╭" : "├"}─`) +
|
|
151
|
+
theme.fg(failed ? "error" : "accent", title) +
|
|
152
|
+
border(
|
|
153
|
+
`${"─".repeat(Math.max(0, size - visibleWidth(title) - 3))}${part === "call" ? "╮" : "┤"}`,
|
|
154
|
+
),
|
|
155
|
+
];
|
|
156
|
+
const blank = `${border("│")}${" ".repeat(size - 2)}${border("│")}`;
|
|
157
|
+
for (const line of source.split("\n")) {
|
|
158
|
+
const highlighted =
|
|
159
|
+
language === "diff"
|
|
160
|
+
? theme.fg(
|
|
161
|
+
line.startsWith("+")
|
|
162
|
+
? "toolDiffAdded"
|
|
163
|
+
: line.startsWith("-")
|
|
164
|
+
? "toolDiffRemoved"
|
|
165
|
+
: "toolDiffContext",
|
|
166
|
+
line,
|
|
167
|
+
)
|
|
168
|
+
: language
|
|
169
|
+
? highlightCode(line, language).join("\n")
|
|
170
|
+
: theme.fg("toolOutput", line);
|
|
171
|
+
for (const wrapped of wrapTextWithAnsi(highlighted, inner))
|
|
172
|
+
rows.push(
|
|
173
|
+
`${border("│")} ${wrapped}${" ".repeat(Math.max(0, inner - visibleWidth(wrapped)))} ${border("│")}`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (part === "call") rows.push(blank);
|
|
177
|
+
if (finish) rows.push(border(`╰${"─".repeat(size - 2)}╯`));
|
|
178
|
+
const background = theme.getBgAnsi("toolPendingBg");
|
|
179
|
+
return rows.map((row) => background + preserveEnclosingBackground(row, background) + "\u001b[0m");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Compose compact written calls with a pure configured tool header renderer. */
|
|
183
|
+
export function createApplyCallRenderer(
|
|
184
|
+
renderWritten?: (call: ApplyCallPreview, theme: Theme) => string,
|
|
185
|
+
): NonNullable<ToolDefinition["renderCall"]> {
|
|
186
|
+
return (args, theme, context) => {
|
|
187
|
+
const state = context.state as RenderState;
|
|
188
|
+
const projectSource = (state.projectSource ??= createApplySourceProjection(
|
|
189
|
+
renderWritten ? (call) => renderWritten(call, theme) : undefined,
|
|
190
|
+
renderWritten ? (code) => highlightCode(code, "javascript").join("\n") : undefined,
|
|
191
|
+
));
|
|
192
|
+
const source =
|
|
193
|
+
args !== null &&
|
|
194
|
+
typeof args === "object" &&
|
|
195
|
+
"source" in args &&
|
|
196
|
+
typeof args.source === "string"
|
|
197
|
+
? args.source
|
|
198
|
+
: "";
|
|
199
|
+
return {
|
|
200
|
+
invalidate() {},
|
|
201
|
+
render(width) {
|
|
202
|
+
return applyFrameRows(
|
|
203
|
+
state.codeView || context.expanded
|
|
204
|
+
? (state.displaySource ?? source)
|
|
205
|
+
: projectSource(state.displaySource ?? source),
|
|
206
|
+
theme,
|
|
207
|
+
width,
|
|
208
|
+
"call",
|
|
209
|
+
!state.applyResultReady,
|
|
210
|
+
state.codeView || context.expanded || !renderWritten ? "javascript" : undefined,
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export const renderApplyCall = createApplyCallRenderer();
|
|
218
|
+
|
|
219
|
+
/** Configured editor presentation for final mutations inside the Apply card. */
|
|
220
|
+
export type ApplyMutationPanel = (
|
|
221
|
+
details: FileMutationBatchResult,
|
|
222
|
+
theme: Theme,
|
|
223
|
+
expanded: boolean,
|
|
224
|
+
cwd: string,
|
|
225
|
+
) => Component;
|
|
226
|
+
|
|
227
|
+
/** Reuse the owning editor renderer without introducing a core-to-plugin dependency. */
|
|
228
|
+
export function createApplyResultRenderer(
|
|
229
|
+
panel?: ApplyMutationPanel,
|
|
230
|
+
): NonNullable<ToolDefinition["renderResult"]> {
|
|
231
|
+
return (result, options, theme, context) => {
|
|
232
|
+
(context.state as RenderState).applyResultReady = true;
|
|
233
|
+
const details = result.details as
|
|
234
|
+
| { display?: ApplyDisplay; displaySource?: string }
|
|
235
|
+
| undefined;
|
|
236
|
+
(context.state as RenderState).displaySource = details?.displaySource;
|
|
237
|
+
const display = details?.display;
|
|
238
|
+
const blocks: ApplyDisplay["blocks"] = display?.blocks ?? [
|
|
239
|
+
{ text: context.isError ? "Apply failed" : "Apply finished" },
|
|
240
|
+
];
|
|
241
|
+
const renderRead = createReadResultRenderer({ kind: "source" });
|
|
242
|
+
const readPanels = blocks.map((block) =>
|
|
243
|
+
renderRead(
|
|
244
|
+
block.read ?? {
|
|
245
|
+
content: [{ type: "text", text: block.text }],
|
|
246
|
+
details: jsonDetails(block.text),
|
|
247
|
+
},
|
|
248
|
+
options,
|
|
249
|
+
theme,
|
|
250
|
+
{ ...context, isError: false, lastComponent: undefined },
|
|
251
|
+
),
|
|
252
|
+
);
|
|
253
|
+
const mutations = display?.mutations;
|
|
254
|
+
const comparisonPanels = (display?.comparisons ?? []).flatMap((details) => {
|
|
255
|
+
const rendered = panel?.(details, theme, options.expanded, display?.cwd ?? process.cwd());
|
|
256
|
+
return [
|
|
257
|
+
rendered ??
|
|
258
|
+
new Text(
|
|
259
|
+
(details.results ?? []).flatMap((result) => result.data.diffs ?? []).join("\n"),
|
|
260
|
+
0,
|
|
261
|
+
0,
|
|
262
|
+
),
|
|
263
|
+
];
|
|
264
|
+
});
|
|
265
|
+
const mutationPanel =
|
|
266
|
+
mutations === undefined
|
|
267
|
+
? undefined
|
|
268
|
+
: panel?.(mutations, theme, options.expanded, display?.cwd ?? process.cwd());
|
|
269
|
+
return {
|
|
270
|
+
invalidate() {
|
|
271
|
+
mutationPanel?.invalidate();
|
|
272
|
+
for (const comparison of comparisonPanels) comparison.invalidate();
|
|
273
|
+
},
|
|
274
|
+
render(width) {
|
|
275
|
+
const body: string[] = [];
|
|
276
|
+
for (const panel of readPanels) {
|
|
277
|
+
const rows = panel.render(Math.max(1, width - 4));
|
|
278
|
+
if (rows.length === 0) continue;
|
|
279
|
+
if (body.length > 0) body.push("");
|
|
280
|
+
body.push(...rows);
|
|
281
|
+
}
|
|
282
|
+
for (const comparison of comparisonPanels) {
|
|
283
|
+
if (body.length > 0) body.push("");
|
|
284
|
+
body.push(...comparison.render(Math.max(1, width - 4)));
|
|
285
|
+
}
|
|
286
|
+
if (mutationPanel !== undefined) {
|
|
287
|
+
const rows = mutationPanel.render(Math.max(1, width - 4));
|
|
288
|
+
if (body.length > 0 && rows.length > 0) body.push("");
|
|
289
|
+
body.push(...rows);
|
|
290
|
+
} else if (mutations !== undefined)
|
|
291
|
+
body.push(...(mutations.results ?? []).map((file) => file.path ?? "Changed file"));
|
|
292
|
+
if (
|
|
293
|
+
body.length === 0 &&
|
|
294
|
+
blocks.length > 0 &&
|
|
295
|
+
blocks.every(
|
|
296
|
+
(block) =>
|
|
297
|
+
block.read?.details.diagnosticCheck?.complete &&
|
|
298
|
+
block.read.details.diagnosticCheck.count === 0,
|
|
299
|
+
)
|
|
300
|
+
)
|
|
301
|
+
return applyFrameRows("", theme, width, "result", true).slice(-1);
|
|
302
|
+
return applyFrameRows(
|
|
303
|
+
body.length === 0 ? "No output" : body.join("\n"),
|
|
304
|
+
theme,
|
|
305
|
+
width,
|
|
306
|
+
"result",
|
|
307
|
+
true,
|
|
308
|
+
undefined,
|
|
309
|
+
context.isError,
|
|
310
|
+
);
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function jsonDetails(text: string): { source?: string } {
|
|
317
|
+
try {
|
|
318
|
+
const value: unknown = JSON.parse(text);
|
|
319
|
+
return value !== null && typeof value === "object" ? { source: "result.json" } : {};
|
|
320
|
+
} catch {
|
|
321
|
+
return {};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
export const renderApplyResult = createApplyResultRenderer();
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { FileMutationResult } from "#src/api/mutation-result.js";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
import { requiredValue } from "pi-agent-invariant";
|
|
4
|
+
import type { ReadToolResult } from "pi-agent-read/api/tools/read";
|
|
5
|
+
|
|
6
|
+
/** Host-owned outcome; identity refers to one call, not equal result contents. */
|
|
7
|
+
interface OperationResult {
|
|
8
|
+
readonly presentation?: ReadToolResult;
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly kind: "read" | "mutation";
|
|
11
|
+
readonly value: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type ExplicitResult =
|
|
15
|
+
| {
|
|
16
|
+
readonly kind: "operation";
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly value: unknown;
|
|
19
|
+
readonly presentation?: ReadToolResult;
|
|
20
|
+
}
|
|
21
|
+
| { readonly kind: "value"; readonly value: unknown };
|
|
22
|
+
|
|
23
|
+
/** Final observed contents for one canonical resource; null means absent. */
|
|
24
|
+
interface FileState {
|
|
25
|
+
readonly source: string;
|
|
26
|
+
readonly before: string | null;
|
|
27
|
+
readonly after: string | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Collected data for the formatter; operation receipts are not intermediate file views. */
|
|
31
|
+
interface SelectedResults {
|
|
32
|
+
readonly explicit: readonly ExplicitResult[];
|
|
33
|
+
readonly automatic: readonly OperationResult[];
|
|
34
|
+
readonly files: readonly FileState[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Per-invocation output selection and file-state consolidation, independent of guest return. */
|
|
38
|
+
export class ApplyResults {
|
|
39
|
+
readonly #operations = new Map<string, OperationResult>();
|
|
40
|
+
readonly #explicit: ExplicitResult[] = [];
|
|
41
|
+
readonly #explicitOperations = new Set<string>();
|
|
42
|
+
readonly #files = new Map<string, FileState>();
|
|
43
|
+
#hasMutation = false;
|
|
44
|
+
readonly #mutationPresentations = new Map<string, FileMutationResult>();
|
|
45
|
+
|
|
46
|
+
/** Retain configured post-edit annotations on the host, outside guest serialization. */
|
|
47
|
+
rememberMutation(source: string, presentation: FileMutationResult): void {
|
|
48
|
+
this.#mutationPresentations.set(source, presentation);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Latest observed presentation for a canonical file. */
|
|
52
|
+
mutationPresentation(source: string): FileMutationResult | undefined {
|
|
53
|
+
return this.#mutationPresentations.get(source);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Mutation receipts in execution order, including explicitly selected operations. */
|
|
57
|
+
mutationValues(): readonly unknown[] {
|
|
58
|
+
return [...this.#operations.values()]
|
|
59
|
+
.filter(({ kind }) => kind === "mutation")
|
|
60
|
+
.map(({ value }) => value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Records even refused mutations so they take precedence over automatic reads. */
|
|
64
|
+
record(
|
|
65
|
+
id: string,
|
|
66
|
+
kind: OperationResult["kind"],
|
|
67
|
+
value: unknown,
|
|
68
|
+
presentation?: ReadToolResult,
|
|
69
|
+
): void {
|
|
70
|
+
if (this.#operations.has(id)) throw new Error(`Duplicate operation identity: ${id}`);
|
|
71
|
+
this.#operations.set(id, {
|
|
72
|
+
id,
|
|
73
|
+
kind,
|
|
74
|
+
value,
|
|
75
|
+
...(presentation === undefined ? {} : { presentation }),
|
|
76
|
+
});
|
|
77
|
+
this.#hasMutation ||= kind === "mutation";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Adds a known operation once, preserving explicit selection order. */
|
|
81
|
+
addOperation(id: string): void {
|
|
82
|
+
const operation = requiredValue(this.#operations.get(id));
|
|
83
|
+
if (this.#explicitOperations.has(id)) return;
|
|
84
|
+
this.#explicitOperations.add(id);
|
|
85
|
+
this.#explicit.push({
|
|
86
|
+
kind: "operation",
|
|
87
|
+
id,
|
|
88
|
+
value: operation.value,
|
|
89
|
+
...(operation.presentation === undefined ? {} : { presentation: operation.presentation }),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Checks guest provenance against host data; edited values remain explicit additions. */
|
|
94
|
+
add(value: unknown, operationId?: string): void {
|
|
95
|
+
const operation = operationId === undefined ? undefined : this.#operations.get(operationId);
|
|
96
|
+
if (operation !== undefined && isDeepStrictEqual(operation.value, value)) {
|
|
97
|
+
this.addOperation(operation.id);
|
|
98
|
+
} else {
|
|
99
|
+
this.addValue(value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Adds arbitrary script output; equal values are not assumed to be duplicate calls. */
|
|
103
|
+
addValue(value: unknown): void {
|
|
104
|
+
this.#explicit.push({ kind: "value", value });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Records final observed text after an operation, retaining the first pre-edit state. */
|
|
108
|
+
updateFile(source: string, before: string | null, after: string | null): void {
|
|
109
|
+
const previous = this.#files.get(source);
|
|
110
|
+
this.#files.set(source, {
|
|
111
|
+
source,
|
|
112
|
+
before: previous === undefined ? before : previous.before,
|
|
113
|
+
after,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** A whole-file operation supersedes any previously recorded text snapshot. */
|
|
118
|
+
forgetFile(source: string): void {
|
|
119
|
+
this.#files.delete(source);
|
|
120
|
+
this.#mutationPresentations.delete(source);
|
|
121
|
+
}
|
|
122
|
+
/** Selects output without deleting the underlying operation receipts. */
|
|
123
|
+
select(): SelectedResults {
|
|
124
|
+
return {
|
|
125
|
+
explicit: [...this.#explicit],
|
|
126
|
+
automatic: [...this.#operations.values()].filter(
|
|
127
|
+
({ id, kind }) =>
|
|
128
|
+
!this.#explicitOperations.has(id) && (!this.#hasMutation || kind === "mutation"),
|
|
129
|
+
),
|
|
130
|
+
files: [...this.#files.values()],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { RunLimits } from "run";
|
|
2
|
+
import { fileOperations } from "#src/core/file-operations.js";
|
|
3
|
+
import { ApplyQueue } from "#src/core/apply/queue.js";
|
|
4
|
+
|
|
5
|
+
/** Only IDE operations approved for the guest; remove maps to the standalone delete tool. */
|
|
6
|
+
export const applyOperations = [
|
|
7
|
+
"read",
|
|
8
|
+
"search",
|
|
9
|
+
"diff",
|
|
10
|
+
"write",
|
|
11
|
+
"replace",
|
|
12
|
+
"insert",
|
|
13
|
+
"remove",
|
|
14
|
+
"copy",
|
|
15
|
+
"move",
|
|
16
|
+
"undo",
|
|
17
|
+
"stage",
|
|
18
|
+
"unstage",
|
|
19
|
+
...fileOperations,
|
|
20
|
+
] as const;
|
|
21
|
+
export type ApplyOperation = (typeof applyOperations)[number];
|
|
22
|
+
|
|
23
|
+
/** The host records outcomes before returning them across the guest bridge. */
|
|
24
|
+
export interface ApplyRuntimeHost {
|
|
25
|
+
execute(
|
|
26
|
+
operation: ApplyOperation,
|
|
27
|
+
arguments_: unknown,
|
|
28
|
+
signal: AbortSignal,
|
|
29
|
+
id: string,
|
|
30
|
+
): Promise<unknown>;
|
|
31
|
+
result(value: unknown, operationId?: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Runs a fresh composition and drains host work on success, failure, or cancellation. */
|
|
35
|
+
export async function executeApplySource(
|
|
36
|
+
source: string,
|
|
37
|
+
host: ApplyRuntimeHost,
|
|
38
|
+
signal?: AbortSignal,
|
|
39
|
+
limits?: RunLimits,
|
|
40
|
+
): Promise<void> {
|
|
41
|
+
const { createRunner, getHostFunctionContext } = await import("run");
|
|
42
|
+
const queue = new ApplyQueue();
|
|
43
|
+
const operations = Object.fromEntries(
|
|
44
|
+
applyOperations.map((operation) => [
|
|
45
|
+
operation,
|
|
46
|
+
(arguments_: unknown) => {
|
|
47
|
+
const context = getHostFunctionContext();
|
|
48
|
+
return queue.submit(async () => {
|
|
49
|
+
context.abortSignal.throwIfAborted();
|
|
50
|
+
try {
|
|
51
|
+
return {
|
|
52
|
+
ok: true,
|
|
53
|
+
value: await host.execute(
|
|
54
|
+
operation,
|
|
55
|
+
arguments_,
|
|
56
|
+
context.abortSignal,
|
|
57
|
+
context.requestId,
|
|
58
|
+
),
|
|
59
|
+
id: context.requestId,
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return { ok: false, error: serializeApplyError(error) };
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
]),
|
|
67
|
+
);
|
|
68
|
+
try {
|
|
69
|
+
const runner = createRunner({
|
|
70
|
+
syncHostFunctions: {
|
|
71
|
+
__apply: {
|
|
72
|
+
...operations,
|
|
73
|
+
result: (value: unknown, operationId?: string) =>
|
|
74
|
+
queue.submit(() => host.result(value, operationId)),
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
await runner.run({ source: `${guestBindings()}\n${source}`, abortSignal: signal, limits });
|
|
79
|
+
} finally {
|
|
80
|
+
await queue.close();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Preserves operation error fields without sending host Error instances across the bridge. */
|
|
85
|
+
export function serializeApplyError(error: unknown): {
|
|
86
|
+
code: string;
|
|
87
|
+
message: string;
|
|
88
|
+
details?: unknown;
|
|
89
|
+
} {
|
|
90
|
+
if (!(error instanceof Error)) return { code: "OPERATION_FAILED", message: String(error) };
|
|
91
|
+
return {
|
|
92
|
+
code: "code" in error && typeof error.code === "string" ? error.code : "OPERATION_FAILED",
|
|
93
|
+
message: error.message,
|
|
94
|
+
...("details" in error ? { details: error.details } : {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function guestBindings(): string {
|
|
99
|
+
return `const { ${applyOperations.join(", ")}, result } = (() => {
|
|
100
|
+
const origins = new WeakMap();
|
|
101
|
+
const invoke = (name, args) => {
|
|
102
|
+
const response = __apply[name](args);
|
|
103
|
+
if (!response.ok) throw Object.assign(new Error(response.error.message), response.error);
|
|
104
|
+
if (response.value !== null && typeof response.value === "object") origins.set(response.value, response.id);
|
|
105
|
+
return response.value;
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
${applyOperations.map((name) => `${name}: (args) => invoke(${JSON.stringify(name)}, args)`).join(",\n")},
|
|
109
|
+
result: (value) => __apply.result(value, value !== null && typeof value === "object" ? origins.get(value) : undefined),
|
|
110
|
+
};
|
|
111
|
+
})();`;
|
|
112
|
+
}
|