pi-agent-ide 0.2.2 → 0.3.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 +25 -0
- package/README.md +12 -8
- package/dist/chunk-5MSNYFDE.js +1 -0
- package/dist/chunk-5VSE5X5R.js +2 -0
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/{chunk-ORAPGW7W.js → chunk-72EEL2DW.js} +1 -1
- 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-WNMGUALD.js → chunk-CEKXBS55.js} +1 -1
- package/dist/chunk-CW53ZTU3.js +2 -0
- package/dist/chunk-EWNWKDMP.js +4 -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-KAB3AYA2.js +1 -0
- package/dist/{chunk-THSCUT2L.js → chunk-LRYE2WCN.js} +1 -1
- 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-RHV5STR3.js +3 -0
- package/dist/chunk-ROXXK6TW.js +0 -0
- package/dist/chunk-SSHZEWWV.js +1 -0
- package/dist/{chunk-4ZTEPMJO.js → chunk-TPIHQYK2.js} +1 -1
- package/dist/chunk-VZJIZXSH.js +14 -0
- 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 +6 -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 +61 -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-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/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 +173 -49
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +261 -9
- 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 +19 -10
- 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 +38 -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 +4 -15
- package/src/composite/extensions-config.ts +41 -0
- package/src/composite/feature-flags.ts +32 -0
- package/src/composite/module-labels.ts +55 -0
- package/src/composite/module-settings-store.ts +44 -0
- package/src/composite/module-settings.ts +132 -0
- package/src/composite/selection.ts +4 -4
- package/src/composite/settings-panel.ts +71 -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 +61 -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 +19 -10
- 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/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 +173 -49
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +261 -9
- 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 +42 -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/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-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,237 @@
|
|
|
1
|
+
import { createPostEditScope } from "#src/core/post-edit-scope.js";
|
|
2
|
+
import { FileMutationResult } from "#src/core/mutation-result/file-mutation-result.js";
|
|
3
|
+
import { isFormattingContribution, isDiffStatusContribution } from "#src/api/post-edit.js";
|
|
4
|
+
import { executeDiff, diffReadResult } from "#src/core/diff-tool.js";
|
|
5
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import type { ReadPluginApi } from "pi-agent-read/api/plugin-protocol";
|
|
7
|
+
import { readParameters, type ReadToolResult } from "pi-agent-read/api/tools/read";
|
|
8
|
+
import { searchSchema, type SearchPluginApi, type SearchRequest } from "pi-agent-search/api/search";
|
|
9
|
+
import { Value } from "typebox/value";
|
|
10
|
+
import type { TextEditorCore } from "#src/core/text-editor-core.js";
|
|
11
|
+
import { executeScriptMutation } from "#src/core/text-mutation.js";
|
|
12
|
+
import { ApplyResults } from "#src/core/apply/results.js";
|
|
13
|
+
import {
|
|
14
|
+
executeFileOperation,
|
|
15
|
+
fileOperations,
|
|
16
|
+
type FileOperation,
|
|
17
|
+
} from "#src/core/file-operations.js";
|
|
18
|
+
import { serializeApplyError, type ApplyRuntimeHost } from "#src/core/apply/runtime.js";
|
|
19
|
+
|
|
20
|
+
/** Configured IDE services and ordinary tool schemas, shared with the standalone tools. */
|
|
21
|
+
export interface ApplyServices {
|
|
22
|
+
readonly editor: TextEditorCore;
|
|
23
|
+
readonly read: ReadPluginApi;
|
|
24
|
+
readonly search: SearchPluginApi;
|
|
25
|
+
readonly lastResolvedSource?: string;
|
|
26
|
+
readonly rememberRead?: (outcome: ReadToolResult) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** One invocation's host-owned receipts, with guest errors independent of output selection. */
|
|
30
|
+
export function createApplyExecution(
|
|
31
|
+
services: ApplyServices,
|
|
32
|
+
context: ExtensionContext,
|
|
33
|
+
): {
|
|
34
|
+
readonly host: ApplyRuntimeHost;
|
|
35
|
+
readonly results: ApplyResults;
|
|
36
|
+
finish(): Promise<void>;
|
|
37
|
+
} {
|
|
38
|
+
const results = new ApplyResults();
|
|
39
|
+
const scope = createPostEditScope();
|
|
40
|
+
let lastSource = services.lastResolvedSource;
|
|
41
|
+
const host: ApplyRuntimeHost = {
|
|
42
|
+
async execute(operation, arguments_, signal, id) {
|
|
43
|
+
const tool = operation === "remove" ? "delete" : operation;
|
|
44
|
+
const kind = tool === "read" || tool === "search" || tool === "diff" ? "read" : "mutation";
|
|
45
|
+
let recorded = false;
|
|
46
|
+
try {
|
|
47
|
+
if (tool === "stage" || tool === "unstage") {
|
|
48
|
+
const operation = services.editor.getScriptIndexOperation(tool);
|
|
49
|
+
if (!operation)
|
|
50
|
+
throw failure("OPERATION_UNAVAILABLE", `${tool} requires the Git changes module`);
|
|
51
|
+
if (!Value.Check(operation.parameters, arguments_))
|
|
52
|
+
throw failure("INVALID_ARGUMENTS", `Invalid ${tool} arguments`);
|
|
53
|
+
const outcome = await operation.execute(arguments_, signal, context);
|
|
54
|
+
const value = {
|
|
55
|
+
operation: tool,
|
|
56
|
+
ok: true,
|
|
57
|
+
effect: "index-only",
|
|
58
|
+
kind: "index-operation",
|
|
59
|
+
...(outcome.details as object),
|
|
60
|
+
};
|
|
61
|
+
results.record(id, "mutation", value, { content: outcome.content, details: {} });
|
|
62
|
+
recorded = true;
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (tool === "diff") {
|
|
66
|
+
const value = await executeDiff(services.read, arguments_, { cwd: context.cwd, signal });
|
|
67
|
+
results.record(id, "read", value, diffReadResult(value));
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
if ((fileOperations as readonly string[]).includes(operation)) {
|
|
71
|
+
const value = await services.editor.enqueueFileOperation(
|
|
72
|
+
() => executeFileOperation(operation as FileOperation, arguments_, context.cwd, signal),
|
|
73
|
+
signal,
|
|
74
|
+
);
|
|
75
|
+
results.record(id, "mutation", value);
|
|
76
|
+
recorded = true;
|
|
77
|
+
if (value.effect !== "not-applied") {
|
|
78
|
+
if (value.path !== undefined && operation !== "copy_file") {
|
|
79
|
+
results.forgetFile(value.path);
|
|
80
|
+
scope.forget(value.path);
|
|
81
|
+
}
|
|
82
|
+
if (value.target !== undefined) {
|
|
83
|
+
results.forgetFile(value.target);
|
|
84
|
+
scope.forget(value.target);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (value.ok && value.target !== undefined)
|
|
88
|
+
await services.editor.postProcessFile(value.target, { cwd: context.cwd, signal });
|
|
89
|
+
if (!value.ok)
|
|
90
|
+
throw failure(
|
|
91
|
+
value.error?.code ?? "FILE_OPERATION_FAILED",
|
|
92
|
+
value.error?.message ?? "File operation failed",
|
|
93
|
+
value,
|
|
94
|
+
);
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
if (kind === "mutation") {
|
|
98
|
+
const definition = services.editor
|
|
99
|
+
.getMutationTools()
|
|
100
|
+
.find((candidate) => candidate.name === tool);
|
|
101
|
+
if (definition === undefined)
|
|
102
|
+
throw failure("UNAVAILABLE_OPERATION", `IDE operation ${tool} is unavailable`);
|
|
103
|
+
const value = await executeScriptMutation(
|
|
104
|
+
services.editor,
|
|
105
|
+
definition,
|
|
106
|
+
arguments_,
|
|
107
|
+
signal,
|
|
108
|
+
context,
|
|
109
|
+
lastSource,
|
|
110
|
+
(source, presentation) => results.rememberMutation(source, presentation),
|
|
111
|
+
);
|
|
112
|
+
results.record(id, kind, value);
|
|
113
|
+
recorded = true;
|
|
114
|
+
for (const file of value.files) {
|
|
115
|
+
results.updateFile(file.source, file.before, file.after);
|
|
116
|
+
lastSource = file.source;
|
|
117
|
+
}
|
|
118
|
+
if (!value.ok)
|
|
119
|
+
throw failure(
|
|
120
|
+
value.errors[0]?.code ?? "OPERATION_FAILED",
|
|
121
|
+
value.errors[0]?.message ?? "Mutation failed",
|
|
122
|
+
value,
|
|
123
|
+
);
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
const schema = tool === "read" ? readParameters : searchSchema;
|
|
127
|
+
if (!Value.Check(schema, arguments_))
|
|
128
|
+
throw failure("INVALID_ARGUMENTS", `Invalid arguments for ${tool}`);
|
|
129
|
+
if (tool === "read") {
|
|
130
|
+
const outcome = await services.read.read(
|
|
131
|
+
arguments_,
|
|
132
|
+
{ cwd: context.cwd, signal },
|
|
133
|
+
"script",
|
|
134
|
+
);
|
|
135
|
+
const value = {
|
|
136
|
+
...(outcome.script ?? {
|
|
137
|
+
kind: "native",
|
|
138
|
+
source: outcome.details.source,
|
|
139
|
+
blocks: outcome.content,
|
|
140
|
+
}),
|
|
141
|
+
ok: !outcome.isError && outcome.details.failure === undefined,
|
|
142
|
+
};
|
|
143
|
+
results.record(id, kind, value, outcome);
|
|
144
|
+
recorded = true;
|
|
145
|
+
if (outcome.isError || outcome.details.failure)
|
|
146
|
+
throw failure(
|
|
147
|
+
readFailureCode(outcome.details.failure),
|
|
148
|
+
outcome.details.failure?.message ?? "Read failed",
|
|
149
|
+
value,
|
|
150
|
+
);
|
|
151
|
+
lastSource = outcome.details.source ?? lastSource;
|
|
152
|
+
services.rememberRead?.(outcome);
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
const outcome = await services.search.search(
|
|
156
|
+
arguments_ as SearchRequest,
|
|
157
|
+
{
|
|
158
|
+
cwd: context.cwd,
|
|
159
|
+
signal,
|
|
160
|
+
},
|
|
161
|
+
"script",
|
|
162
|
+
);
|
|
163
|
+
const searchFailure = outcome.details.failure;
|
|
164
|
+
const value = {
|
|
165
|
+
...outcome.script,
|
|
166
|
+
ok: searchFailure === undefined,
|
|
167
|
+
...(searchFailure && { error: searchFailure }),
|
|
168
|
+
};
|
|
169
|
+
results.record(id, kind, value, { content: outcome.content, details: {} });
|
|
170
|
+
recorded = true;
|
|
171
|
+
if (searchFailure !== undefined)
|
|
172
|
+
throw failure("SEARCH_FAILED", "Search failed", searchFailure);
|
|
173
|
+
return value;
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (!recorded)
|
|
176
|
+
results.record(id, kind, { operation, ok: false, error: serializeApplyError(error) });
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
async result(value, id) {
|
|
181
|
+
results.add(value, id);
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
host: { ...host, execute: (...args) => scope.run(() => host.execute(...args)) },
|
|
186
|
+
results,
|
|
187
|
+
async finish() {
|
|
188
|
+
await services.editor.enqueueFileOperation(() =>
|
|
189
|
+
scope.finish((outcome) => {
|
|
190
|
+
const source = outcome.after.source;
|
|
191
|
+
const previous = results.mutationPresentation(source)?.data;
|
|
192
|
+
const formatting = outcome.postEditContributions
|
|
193
|
+
.map((item) => item.data)
|
|
194
|
+
.findLast(isFormattingContribution)?.formatting;
|
|
195
|
+
if (
|
|
196
|
+
!previous &&
|
|
197
|
+
outcome.before.content === outcome.after.content &&
|
|
198
|
+
!formatting?.formatter
|
|
199
|
+
)
|
|
200
|
+
return;
|
|
201
|
+
results.updateFile(source, outcome.before.content, outcome.after.content);
|
|
202
|
+
results.rememberMutation(
|
|
203
|
+
source,
|
|
204
|
+
new FileMutationResult({
|
|
205
|
+
ok: true,
|
|
206
|
+
path: source,
|
|
207
|
+
...previous,
|
|
208
|
+
afterContent: outcome.after.content,
|
|
209
|
+
afterDocument: outcome.after,
|
|
210
|
+
diffStatuses: outcome.postEditContributions
|
|
211
|
+
.map((item) => item.data)
|
|
212
|
+
.filter(isDiffStatusContribution)
|
|
213
|
+
.flatMap((item) => item.diffStatuses),
|
|
214
|
+
formatting: formatting ?? { status: "not-reported" },
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function failure(code: string, message: string, details?: unknown): Error {
|
|
224
|
+
return Object.assign(new Error(message), { code, details });
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function readFailureCode(
|
|
228
|
+
failure: { readonly code: string; readonly cause?: unknown } | undefined,
|
|
229
|
+
): string {
|
|
230
|
+
const cause = failure?.cause;
|
|
231
|
+
return cause !== null &&
|
|
232
|
+
typeof cause === "object" &&
|
|
233
|
+
"code" in cause &&
|
|
234
|
+
typeof cause.code === "string"
|
|
235
|
+
? cause.code
|
|
236
|
+
: (failure?.code ?? "READ_FAILED");
|
|
237
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FileMutationResult } from "#src/core/mutation-result/file-mutation-result.js";
|
|
2
|
+
import { createUnifiedDiff } from "#src/core/mutation-result/diff.js";
|
|
3
|
+
import type { ApplyResults } from "./results.js";
|
|
4
|
+
import type { ScriptMutationOutcome } from "./mutation-outcome.js";
|
|
5
|
+
|
|
6
|
+
/** Project recorded net effects into the same presentation model as standalone edits. */
|
|
7
|
+
export function finalApplyMutations(results: ApplyResults): FileMutationResult[] {
|
|
8
|
+
const selected = results.select();
|
|
9
|
+
const mutations = results.mutationValues().filter(isMutation);
|
|
10
|
+
return selected.files.map((file) => {
|
|
11
|
+
const receipts = mutations.flatMap((outcome) =>
|
|
12
|
+
outcome.files
|
|
13
|
+
.filter((changed) => changed.source === file.source)
|
|
14
|
+
.map((changed) => ({ outcome, changed })),
|
|
15
|
+
);
|
|
16
|
+
const presentation = results.mutationPresentation(file.source)?.data;
|
|
17
|
+
const latest = presentation?.afterContent === file.after ? presentation : undefined;
|
|
18
|
+
return new FileMutationResult({
|
|
19
|
+
ok: true,
|
|
20
|
+
path: file.source,
|
|
21
|
+
files: [{ path: file.source, action: file.before === null ? "created" : "edited" }],
|
|
22
|
+
snapshot: { content: file.before ?? "" },
|
|
23
|
+
beforeContentMap: { [file.source]: file.before },
|
|
24
|
+
afterContent: file.after ?? "",
|
|
25
|
+
afterDocument: latest?.afterDocument,
|
|
26
|
+
resultPresentation: latest?.resultPresentation,
|
|
27
|
+
scopeMarkers: latest?.scopeMarkers,
|
|
28
|
+
hints: latest?.hints,
|
|
29
|
+
warnings: latest?.warnings,
|
|
30
|
+
diffStatuses: latest?.diffStatuses,
|
|
31
|
+
diffs: [createUnifiedDiff(file.source, file.before ?? "", file.after ?? "").diff],
|
|
32
|
+
operations: receipts.map(({ outcome, changed }) => ({
|
|
33
|
+
operation: outcome.operation === "remove" ? "delete" : outcome.operation,
|
|
34
|
+
changes: changed.changes.length,
|
|
35
|
+
})),
|
|
36
|
+
formatting: latest?.formatting ?? receipts.at(-1)?.changed.formatting,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isMutation(value: unknown): value is ScriptMutationOutcome {
|
|
42
|
+
return (
|
|
43
|
+
value !== null &&
|
|
44
|
+
typeof value === "object" &&
|
|
45
|
+
"operation" in value &&
|
|
46
|
+
"files" in value &&
|
|
47
|
+
Array.isArray(value.files) &&
|
|
48
|
+
"effect" in value
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { format } from "oxfmt";
|
|
2
|
+
|
|
3
|
+
/** Format only the completed display copy; execution always receives the original source. */
|
|
4
|
+
export async function formatApplySource(source: string): Promise<string> {
|
|
5
|
+
try {
|
|
6
|
+
const formatted = await format("apply.js", source, { printWidth: 90 });
|
|
7
|
+
return formatted.errors.length === 0 ? formatted.code.trimEnd() : source;
|
|
8
|
+
} catch {
|
|
9
|
+
return source;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { parser } from "@lezer/javascript";
|
|
2
|
+
import { TreeFragment, type Tree } from "@lezer/common";
|
|
3
|
+
|
|
4
|
+
const helpers = new Set([
|
|
5
|
+
"read",
|
|
6
|
+
"search",
|
|
7
|
+
"diff",
|
|
8
|
+
"write",
|
|
9
|
+
"replace",
|
|
10
|
+
"insert",
|
|
11
|
+
"remove",
|
|
12
|
+
"copy",
|
|
13
|
+
"move",
|
|
14
|
+
"undo",
|
|
15
|
+
"stage",
|
|
16
|
+
"unstage",
|
|
17
|
+
"delete_file",
|
|
18
|
+
"copy_file",
|
|
19
|
+
"move_file",
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
/** Bounded source expression; literal does not imply the operation has executed. */
|
|
23
|
+
export interface PreviewArgument {
|
|
24
|
+
readonly text: string;
|
|
25
|
+
readonly literal: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** A written call preview, never evidence that the call executed. */
|
|
28
|
+
export interface ApplyCallPreview {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
readonly from: number;
|
|
31
|
+
readonly to: number;
|
|
32
|
+
readonly path?: PreviewArgument;
|
|
33
|
+
readonly query?: PreviewArgument;
|
|
34
|
+
readonly target?: PreviewArgument;
|
|
35
|
+
readonly before?: PreviewArgument;
|
|
36
|
+
readonly after?: PreviewArgument;
|
|
37
|
+
readonly arguments: Readonly<Record<string, PreviewArgument>>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Recover helper calls from incomplete JavaScript without evaluating arguments. */
|
|
41
|
+
export function parseApplyCalls(
|
|
42
|
+
source: string,
|
|
43
|
+
tree: Tree = parser.parse(source),
|
|
44
|
+
): ApplyCallPreview[] {
|
|
45
|
+
const shadows: { name: string; from: number; to: number }[] = [];
|
|
46
|
+
tree.iterate({
|
|
47
|
+
enter(node) {
|
|
48
|
+
if (node.name === "AssignmentExpression") {
|
|
49
|
+
const target = node.node.firstChild;
|
|
50
|
+
if (target?.name === "VariableName")
|
|
51
|
+
shadows.push({ name: source.slice(target.from, target.to), from: 0, to: source.length });
|
|
52
|
+
}
|
|
53
|
+
if (node.name !== "VariableDefinition") return;
|
|
54
|
+
let declaration = node.node.parent;
|
|
55
|
+
while (
|
|
56
|
+
declaration?.parent &&
|
|
57
|
+
!["VariableDeclaration", "ParamList", "Block", "Script"].includes(declaration.name)
|
|
58
|
+
)
|
|
59
|
+
declaration = declaration.parent;
|
|
60
|
+
const hoisted =
|
|
61
|
+
declaration?.name === "VariableDeclaration" && declaration.firstChild?.name === "var";
|
|
62
|
+
const boundaries = new Set([
|
|
63
|
+
"Script",
|
|
64
|
+
"FunctionDeclaration",
|
|
65
|
+
"FunctionExpression",
|
|
66
|
+
"ArrowFunction",
|
|
67
|
+
...(hoisted ? [] : ["Block"]),
|
|
68
|
+
]);
|
|
69
|
+
let scope = node.node.parent;
|
|
70
|
+
if (scope?.name === "FunctionDeclaration") scope = scope.parent;
|
|
71
|
+
while (scope?.parent && !boundaries.has(scope.name)) scope = scope.parent;
|
|
72
|
+
shadows.push({
|
|
73
|
+
name: source.slice(node.from, node.to),
|
|
74
|
+
from: scope?.from ?? 0,
|
|
75
|
+
to: scope?.to ?? source.length,
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const calls: ApplyCallPreview[] = [];
|
|
80
|
+
tree.iterate({
|
|
81
|
+
enter(node) {
|
|
82
|
+
if (node.name !== "CallExpression") return;
|
|
83
|
+
const callee = node.node.firstChild;
|
|
84
|
+
if (callee?.name !== "VariableName") return;
|
|
85
|
+
const name = source.slice(callee.from, callee.to);
|
|
86
|
+
if (
|
|
87
|
+
!helpers.has(name) ||
|
|
88
|
+
shadows.some(
|
|
89
|
+
(binding) => binding.name === name && binding.from <= node.from && binding.to >= node.to,
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
return;
|
|
93
|
+
const object = node.node.getChild("ArgList")?.getChild("ObjectExpression");
|
|
94
|
+
const fields = Object.create(null) as Record<string, PreviewArgument>;
|
|
95
|
+
if (!object) {
|
|
96
|
+
const args = node.node.getChild("ArgList");
|
|
97
|
+
const raw = args ? source.slice(args.from + 1, args.to).replace(/\)$/, "") : "";
|
|
98
|
+
if (raw)
|
|
99
|
+
fields.arguments = {
|
|
100
|
+
text: raw.length > 160 ? raw.slice(0, 120) + "…" : raw,
|
|
101
|
+
literal: false,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
for (const property of object?.getChildren("Property") ?? []) {
|
|
105
|
+
const key = property.firstChild;
|
|
106
|
+
const rawKey = key ? source.slice(key.from, key.to) : "";
|
|
107
|
+
const field = rawKey.replace(/^["']|["']$/g, "");
|
|
108
|
+
if (!/^[a-zA-Z_$][\w$]*$/.test(field)) {
|
|
109
|
+
// Computed keys and spreads can replace any earlier identity argument.
|
|
110
|
+
for (const identity of ["path", "query", "target", "before", "after"])
|
|
111
|
+
delete fields[identity];
|
|
112
|
+
const raw = source.slice(property.from, property.to);
|
|
113
|
+
fields[`argument@${property.from}`] = {
|
|
114
|
+
text: raw.length > 160 ? raw.slice(0, 160) + "…" : raw,
|
|
115
|
+
literal: false,
|
|
116
|
+
};
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const value = property.lastChild;
|
|
120
|
+
if (!value || value.type.isError || value.name === ":") continue;
|
|
121
|
+
const raw = source.slice(value.from, value.to);
|
|
122
|
+
const singleLine = raw.replace(/\r/g, "\\r").replace(/\n/g, "\\n").replace(/\t/g, "\\t");
|
|
123
|
+
const anchor =
|
|
124
|
+
/^(?:["'])(?:\d+#[0-9A-F]+|CHANGE#[0-9A-F]+|begin|end|scope-(?:begin|end)-[^"']+)["']$/.test(
|
|
125
|
+
raw,
|
|
126
|
+
);
|
|
127
|
+
fields[field] = {
|
|
128
|
+
text:
|
|
129
|
+
singleLine.length > 160 && !anchor
|
|
130
|
+
? `${singleLine.slice(0, 100)}…${singleLine.slice(-40)} (${raw.length} source chars)`
|
|
131
|
+
: singleLine,
|
|
132
|
+
literal:
|
|
133
|
+
["String", "Number", "BooleanLiteral", "Null"].includes(value.name) &&
|
|
134
|
+
value.lastChild?.type.isError !== true,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
calls.push({
|
|
138
|
+
name,
|
|
139
|
+
from: node.from,
|
|
140
|
+
to: node.to,
|
|
141
|
+
path: fields.path,
|
|
142
|
+
query: fields.query,
|
|
143
|
+
target: fields.target,
|
|
144
|
+
before: fields.before,
|
|
145
|
+
after: fields.after,
|
|
146
|
+
arguments: fields,
|
|
147
|
+
});
|
|
148
|
+
return false;
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
return calls;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Compact written calls only; source and execution are never changed. */
|
|
155
|
+
export function compactApplySource(
|
|
156
|
+
source: string,
|
|
157
|
+
calls = parseApplyCalls(source),
|
|
158
|
+
renderCall?: (call: ApplyCallPreview) => string,
|
|
159
|
+
renderCode: (source: string) => string = (source) => source,
|
|
160
|
+
): string {
|
|
161
|
+
let cursor = 0;
|
|
162
|
+
const parts: string[] = [];
|
|
163
|
+
const codePreview = (text: string) =>
|
|
164
|
+
renderCode(
|
|
165
|
+
text
|
|
166
|
+
.split("\n")
|
|
167
|
+
.map((line) => (line.length > 200 ? line.slice(0, 200) + "…" : line))
|
|
168
|
+
.join("\n"),
|
|
169
|
+
);
|
|
170
|
+
for (const call of calls) {
|
|
171
|
+
parts.push(codePreview(source.slice(cursor, call.from)));
|
|
172
|
+
parts.push(
|
|
173
|
+
renderCall?.(call) ??
|
|
174
|
+
`${call.name}(${call.path ? (call.path.literal ? call.path.text : `‹${call.path.text}›`) : "…"})`,
|
|
175
|
+
);
|
|
176
|
+
cursor = call.to;
|
|
177
|
+
}
|
|
178
|
+
parts.push(codePreview(source.slice(cursor)));
|
|
179
|
+
return parts.join("");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Reuse syntax trees across streamed argument updates and repeated terminal paints. */
|
|
183
|
+
export function createApplySourceProjection(
|
|
184
|
+
renderCall?: (call: ApplyCallPreview) => string,
|
|
185
|
+
renderCode?: (source: string) => string,
|
|
186
|
+
): (source: string) => string {
|
|
187
|
+
let previous = "";
|
|
188
|
+
let output = "";
|
|
189
|
+
let fragments: readonly TreeFragment[] = [];
|
|
190
|
+
return (source) => {
|
|
191
|
+
if (source === previous) return output;
|
|
192
|
+
let shared = 0;
|
|
193
|
+
while (
|
|
194
|
+
shared < previous.length &&
|
|
195
|
+
shared < source.length &&
|
|
196
|
+
previous[shared] === source[shared]
|
|
197
|
+
)
|
|
198
|
+
shared++;
|
|
199
|
+
fragments = TreeFragment.applyChanges(fragments, [
|
|
200
|
+
{ fromA: shared, toA: previous.length, fromB: shared, toB: source.length },
|
|
201
|
+
]);
|
|
202
|
+
const tree = parser.parse(source, fragments);
|
|
203
|
+
fragments = TreeFragment.addTree(tree);
|
|
204
|
+
output = compactApplySource(source, parseApplyCalls(source, tree), renderCall, renderCode);
|
|
205
|
+
previous = source;
|
|
206
|
+
return output;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { TextAnchorRecoveryCandidate } from "pi-agent-text";
|
|
2
|
+
import type { MutationFormatting, AppliedTextChange } from "#src/api/mutation-result.js";
|
|
3
|
+
|
|
4
|
+
/** Plain recovery data from the same anchor resolver used by standalone mutations. */
|
|
5
|
+
export interface ScriptAnchorRecovery {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly field: string;
|
|
8
|
+
readonly anchor: string;
|
|
9
|
+
readonly status: "candidates" | "unavailable" | "timed-out" | "failed";
|
|
10
|
+
readonly candidates: readonly TextAnchorRecoveryCandidate[];
|
|
11
|
+
readonly total: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Plain resource data crossing the script bridge, independent of renderer objects. */
|
|
15
|
+
export interface ScriptMutationFile {
|
|
16
|
+
readonly source: string;
|
|
17
|
+
readonly before: string | null;
|
|
18
|
+
readonly after: string;
|
|
19
|
+
readonly action: string;
|
|
20
|
+
readonly changes: readonly AppliedTextChange[];
|
|
21
|
+
readonly formatting: MutationFormatting;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Shared mutation execution outcome before model-facing formatting. */
|
|
25
|
+
export interface ScriptMutationOutcome {
|
|
26
|
+
readonly operation: string;
|
|
27
|
+
readonly ok: boolean;
|
|
28
|
+
readonly effect: "not-applied" | "applied" | "unknown";
|
|
29
|
+
readonly files: readonly ScriptMutationFile[];
|
|
30
|
+
readonly completed: readonly string[];
|
|
31
|
+
readonly recoveries?: readonly ScriptAnchorRecovery[];
|
|
32
|
+
/** Structured contributions from configured IDE mutation handlers. */
|
|
33
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
34
|
+
readonly errors: readonly {
|
|
35
|
+
readonly source: string;
|
|
36
|
+
readonly code: string;
|
|
37
|
+
readonly message: string;
|
|
38
|
+
}[];
|
|
39
|
+
}
|