pi-agent-ide 0.2.1 → 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 +56 -0
- package/README.md +12 -8
- package/dist/{chunk-XNXQYPVT.js → chunk-4LUW26BX.js} +1 -1
- 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-SMSIT3CE.js → chunk-B5KB2I7J.js} +1 -1
- package/dist/chunk-BHSO2MDK.js +6 -0
- package/dist/chunk-BMOJTJJJ.js +3 -0
- package/dist/{chunk-EEH4WYI7.js → chunk-CEKXBS55.js} +1 -1
- package/dist/chunk-CW53ZTU3.js +2 -0
- package/dist/chunk-EWNWKDMP.js +4 -0
- package/dist/{chunk-VSP2QQPQ.js → chunk-GIRAEVUJ.js} +1 -1
- package/dist/{chunk-MTTKFJV6.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-266RH77Z.js → chunk-LRYE2WCN.js} +1 -1
- package/dist/chunk-M5L42DWE.js +7 -0
- package/dist/chunk-M5MJP7Z2.js +1 -0
- package/dist/chunk-NMFQGKPE.js +2 -0
- package/dist/chunk-NTYXZ3EL.js +3 -0
- package/dist/{chunk-PETQCA7G.js → chunk-QDST6VIU.js} +1 -1
- package/dist/chunk-QIJMV2P2.js +2 -0
- package/dist/chunk-RHV5STR3.js +3 -0
- package/dist/chunk-ROXXK6TW.js +0 -0
- package/dist/chunk-S3ZPXWX7.js +2 -0
- package/dist/chunk-SSHZEWWV.js +1 -0
- package/dist/chunk-TPIHQYK2.js +14 -0
- 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-SJYDLHEF.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-11.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 +2 -1
- package/dist/entry-22.js +1 -1
- package/dist/entry-23.js +1 -1
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +12 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +4 -1
- package/dist/entry-32.js +9 -1
- package/dist/entry-33.js +1 -1
- package/dist/entry-35.js +1 -1
- 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 +18 -1
- package/dist/entry-41.js +1 -1
- 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 +7 -1
- package/dist/entry-46.js +11 -1
- 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 -1
- package/dist/entry-70.js +123 -1
- package/dist/entry-71.js +30 -1
- package/dist/entry-72.js +2 -1
- package/dist/entry-73.js +1 -1
- 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 -1
- package/dist/entry-78.js +1 -1
- package/dist/entry-79.js +1 -1
- package/dist/pi-agent-ide.js +3 -13
- package/docs/configuration.md +57 -11
- package/docs/extensions.md +4 -2
- package/docs/tools.md +7 -1
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-filesystem/index.ts +2 -2
- 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/ast/outline.ts +89 -19
- package/node_modules/pi-agent-ide-ast/src/extension.ts +11 -15
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +83 -0
- package/node_modules/pi-agent-ide-ast/src/scope-handler.ts +8 -1
- package/node_modules/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +83 -5
- package/node_modules/pi-agent-ide-changes/index.ts +22 -10
- 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 +5 -9
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +1 -5
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-formatter/src/formatter.ts +36 -13
- 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 +49 -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 +127 -20
- 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 +25 -7
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +12 -1
- 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-image/src/image-converter.ts +1 -1
- 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-pdf/src/pdf-converter.ts +1 -1
- 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/rendering.ts +3 -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 +32 -28
- package/node_modules/pi-agent-read/src/core/tools/read/native-resource-renderer.ts +74 -0
- 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 +87 -19
- 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 +87 -53
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/content-conversion/content-description.ts +1 -8
- 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 +8 -27
- package/node_modules/pi-agent-search/src/core/search-core.ts +38 -3
- package/node_modules/pi-agent-search-text/index.ts +82 -33
- package/node_modules/pi-agent-search-text/package.json +6 -6
- package/node_modules/pi-agent-search-text/src/file-search.ts +9 -1
- package/node_modules/pi-agent-search-text/src/resolvers.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +2 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +112 -24
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text/src/text-converter.ts +1 -1
- 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/index.ts +2 -6
- 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/mutation-result.ts +3 -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 +74 -1
- 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/builtin-edit-filter.ts +4 -12
- 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 +13 -9
- 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 +28 -2
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +43 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +81 -0
- 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-anchor-registry.ts +5 -2
- 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 +40 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +178 -58
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +313 -21
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +45 -43
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +18 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +7 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +13 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +18 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -1
- package/node_modules/pi-agent-text-editor-renderer/index.ts +93 -2
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +7 -0
- package/node_modules/pi-agent-text-editor-renderer/src/diff-renderer.ts +1 -1
- package/node_modules/pi-agent-text-editor-renderer/src/diff-viewport.ts +11 -2
- package/node_modules/pi-agent-text-editor-renderer/src/frozen-viewport.ts +140 -52
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +69 -4
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-result.ts +53 -1
- package/node_modules/pi-agent-text-editor-renderer/src/persisted-result.ts +8 -2
- package/node_modules/pi-agent-text-editor-renderer/src/render-resource.ts +10 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +24 -13
- 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-call-interception/src/index.ts +3 -0
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-web/index.ts +1 -6
- 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-html/src/html-converter.ts +1 -1
- 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 +12 -2
- package/src/api/text-editor.ts +7 -0
- package/src/api/tool-config.ts +77 -2
- package/src/code-view/diagnostic-view.ts +22 -3
- package/src/composite/builtin-extensions.ts +138 -67
- package/src/composite/extensions-config.ts +59 -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 +142 -0
- package/src/core/diagnostic-store.ts +96 -23
- package/src/core/extension.ts +45 -22
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +2 -2
- 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/index.ts +1 -6
- 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-html/src/html-converter.ts +1 -1
- 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/rendering.ts +3 -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 +32 -28
- package/src/extensions/pi-agent-read/src/core/tools/read/native-resource-renderer.ts +74 -0
- 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 +87 -19
- 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 +87 -53
- package/src/extensions/pi-agent-search/package.json +3 -3
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +82 -33
- 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/file-search.ts +9 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +2 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +112 -24
- 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 +8 -27
- package/src/extensions/pi-agent-search/src/core/search-core.ts +38 -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/index.ts +2 -6
- 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 +93 -2
- 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/diff-model.ts +7 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-renderer.ts +1 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-viewport.ts +11 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/frozen-viewport.ts +140 -52
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +69 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-result.ts +53 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/persisted-result.ts +8 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/render-resource.ts +10 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +24 -13
- 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/mutation-result.ts +3 -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 +74 -1
- 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/builtin-edit-filter.ts +4 -12
- 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 +13 -9
- 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 +28 -2
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +43 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/final-state-fragment.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/grouped-replacements.ts +81 -0
- 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-anchor-registry.ts +5 -2
- 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 +40 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +178 -58
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +313 -21
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +45 -43
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +18 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +7 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +13 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +18 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +2 -1
- package/src/pi-agent-ide.ts +45 -0
- package/src/plugins/pi-agent-ide-ast/package.json +9 -9
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +89 -19
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +11 -15
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +83 -0
- package/src/plugins/pi-agent-ide-ast/src/scope-handler.ts +8 -1
- package/src/plugins/pi-agent-ide-ast/src/scope-resolver.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +83 -5
- package/src/plugins/pi-agent-ide-changes/index.ts +22 -10
- 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 +5 -9
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +1 -5
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +62 -26
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-formatter/src/formatter.ts +36 -13
- 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 +49 -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 +127 -20
- 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 +25 -7
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +12 -1
- 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 +57 -15
- package/src/toolchain/types.ts +2 -0
- package/dist/chunk-2SKAED2I.js +0 -2
- package/dist/chunk-2XYXV5HS.js +0 -4
- package/dist/chunk-2ZMYT6ZC.js +0 -1
- package/dist/chunk-34ZQTTU2.js +0 -2
- package/dist/chunk-4SQQKEVD.js +0 -16
- package/dist/chunk-5BWUVAR4.js +0 -1
- package/dist/chunk-6DN7NO7L.js +0 -1
- package/dist/chunk-6SMFVLTY.js +0 -1
- package/dist/chunk-6XQQBKPE.js +0 -58
- package/dist/chunk-BYWAG6X3.js +0 -6
- package/dist/chunk-EW2KVKCN.js +0 -2
- package/dist/chunk-F6SESI3P.js +0 -4
- package/dist/chunk-GTK5AREE.js +0 -2
- package/dist/chunk-HOBTFFQR.js +0 -1
- package/dist/chunk-IMVCVPMP.js +0 -3
- package/dist/chunk-IOCABSRL.js +0 -1
- package/dist/chunk-JASLOB2X.js +0 -1
- package/dist/chunk-KH5KPBCR.js +0 -10
- package/dist/chunk-KNMWCDDK.js +0 -7
- package/dist/chunk-KYVOMBO5.js +0 -1
- package/dist/chunk-L4FA6OD4.js +0 -1
- package/dist/chunk-LFV6G5Z3.js +0 -1
- package/dist/chunk-LGN7EJYR.js +0 -13
- package/dist/chunk-MB6VVVAF.js +0 -2
- package/dist/chunk-MTQSGWZJ.js +0 -1
- package/dist/chunk-NI2NK4JU.js +0 -1
- package/dist/chunk-NXHPO7ER.js +0 -6
- package/dist/chunk-OFHVDY4Q.js +0 -2
- package/dist/chunk-OIL6BB2S.js +0 -33
- package/dist/chunk-ONWUJXUR.js +0 -1
- package/dist/chunk-PODWLGNO.js +0 -6
- package/dist/chunk-QZANC2IG.js +0 -1
- package/dist/chunk-SSZB66C3.js +0 -3
- package/dist/chunk-TG6H6EOI.js +0 -1
- package/dist/chunk-UTTW55S2.js +0 -1
- package/dist/chunk-VEJGSURY.js +0 -8
- package/dist/chunk-W3XYKJ5H.js +0 -1
- package/dist/chunk-XGUAL3CA.js +0 -1
- package/dist/chunk-YPHXLAQF.js +0 -1
- package/dist/chunk-ZIHEF6K3.js +0 -3
- package/dist/entry-80.js +0 -1
- package/node_modules/pi-agent-read/src/core/tools/read/views.ts +0 -29
- 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-read/src/core/tools/read/views.ts +0 -29
- 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
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { requiredValue } from "pi-agent-invariant";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
+
import type { TextEditCompletion } from "#src/api/edit-completion.js";
|
|
5
|
+
import { Value } from "typebox/value";
|
|
3
6
|
import type {
|
|
4
7
|
TextAnchorRecoveryCandidateRange,
|
|
5
8
|
TextAnchorRecoveryRange,
|
|
@@ -19,6 +22,7 @@ import {
|
|
|
19
22
|
type FileMutationBatchResult,
|
|
20
23
|
FileMutationResult,
|
|
21
24
|
type MutationResultPresentation,
|
|
25
|
+
type MutationOperationReceipt,
|
|
22
26
|
} from "#src/api/mutation-result.js";
|
|
23
27
|
import {
|
|
24
28
|
isMutationAnchorValue,
|
|
@@ -28,7 +32,11 @@ import {
|
|
|
28
32
|
type TextMutationEdit,
|
|
29
33
|
type TextMutationToolRegistration,
|
|
30
34
|
} from "#src/api/mutation-tool.js";
|
|
31
|
-
import {
|
|
35
|
+
import {
|
|
36
|
+
isFormattingContribution,
|
|
37
|
+
isDiffStatusContribution,
|
|
38
|
+
isTextMutationResultContributionData,
|
|
39
|
+
} from "#src/api/post-edit.js";
|
|
32
40
|
import {
|
|
33
41
|
formatStaleAnchorMessage,
|
|
34
42
|
type StaleAnchorMessageDetails,
|
|
@@ -49,7 +57,6 @@ import {
|
|
|
49
57
|
type ToolCallInterceptionRenderStore,
|
|
50
58
|
withToolCallInterceptionRendering,
|
|
51
59
|
} from "#src/core/tool-call-interceptor/rendering.js";
|
|
52
|
-
import { appendSchemaFieldOrder } from "#src/core/tool-description.js";
|
|
53
60
|
|
|
54
61
|
import type { TextEditExecutionOutcome } from "#src/api/edit-pipeline.js";
|
|
55
62
|
import type {
|
|
@@ -67,6 +74,7 @@ import { renderTextAnchor, type TextAnchor } from "pi-agent-text";
|
|
|
67
74
|
import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
|
|
68
75
|
import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception";
|
|
69
76
|
import type { Static, TSchema } from "typebox";
|
|
77
|
+
import type { ScriptMutationOutcome } from "#src/core/apply/mutation-outcome.js";
|
|
70
78
|
|
|
71
79
|
export function createTextTool<TParameters extends TSchema>(
|
|
72
80
|
core: TextEditorCore,
|
|
@@ -83,7 +91,9 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
83
91
|
label: definition.name,
|
|
84
92
|
|
|
85
93
|
promptSnippet: definition.promptSnippet,
|
|
86
|
-
|
|
94
|
+
promptGuidelines:
|
|
95
|
+
definition.promptGuidelines === undefined ? undefined : [...definition.promptGuidelines],
|
|
96
|
+
description: definition.description,
|
|
87
97
|
parameters: definition.parameters,
|
|
88
98
|
prepareArguments: (arguments_) =>
|
|
89
99
|
// oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
|
|
@@ -116,15 +126,18 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
116
126
|
}),
|
|
117
127
|
annotations,
|
|
118
128
|
);
|
|
119
|
-
Object.defineProperty(tool, "
|
|
129
|
+
Object.defineProperty(tool, "description", {
|
|
120
130
|
enumerable: true,
|
|
121
|
-
get(): string
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
get(): string {
|
|
132
|
+
return [
|
|
133
|
+
definition.description,
|
|
134
|
+
definition.source.inherited
|
|
135
|
+
? `When ${definition.source.field} is omitted, the tool can reuse the file identified by the supplied anchor, the last read, or the preceding edit in the same batch.`
|
|
136
|
+
: "",
|
|
137
|
+
pluginPromptGuideline() ?? "",
|
|
138
|
+
]
|
|
139
|
+
.filter(Boolean)
|
|
140
|
+
.join("\n");
|
|
128
141
|
},
|
|
129
142
|
});
|
|
130
143
|
return tool;
|
|
@@ -195,6 +208,7 @@ async function resolveMutationSources(
|
|
|
195
208
|
const expandedByAnchor = new Map<string, readonly TextTarget[]>();
|
|
196
209
|
const expandedBySourceField = new Map<string, readonly TextTarget[]>();
|
|
197
210
|
const expandedFromExplicitSource = new Set<string>();
|
|
211
|
+
const sourceSelections = new Map<string, readonly TextTarget[]>();
|
|
198
212
|
const explicitlyScopedSourceFields = new Set<string>();
|
|
199
213
|
const allKinds = [
|
|
200
214
|
...new Set((definition.anchors ?? []).flatMap((descriptor) => descriptor.kinds)),
|
|
@@ -239,6 +253,7 @@ async function resolveMutationSources(
|
|
|
239
253
|
const expanded = await resolveTargets(explicit, descriptor.field, explicit);
|
|
240
254
|
if (expanded !== undefined) {
|
|
241
255
|
expandedFromExplicitSource.add(descriptor.field);
|
|
256
|
+
sourceSelections.set(descriptor.field, expanded);
|
|
242
257
|
expandedBySourceField.set(
|
|
243
258
|
descriptor.field,
|
|
244
259
|
mergeTargets(expandedBySourceField.get(descriptor.field) ?? [], expanded),
|
|
@@ -288,14 +303,20 @@ async function resolveMutationSources(
|
|
|
288
303
|
const anchors = new Map<string, readonly string[]>();
|
|
289
304
|
const implicitTargets = new Map<string, readonly TextTarget[]>();
|
|
290
305
|
for (const descriptor of definition.anchors ?? []) {
|
|
291
|
-
const targets =
|
|
306
|
+
const targets = sourceSelections.get(descriptor.sourceField);
|
|
307
|
+
const firstAnchor = definition.anchors?.find(
|
|
308
|
+
(anchor) => anchor.sourceField === descriptor.sourceField,
|
|
309
|
+
);
|
|
292
310
|
|
|
293
311
|
const hasExplicitAnchor = isMutationAnchorValue(descriptor, input[descriptor.field]);
|
|
294
312
|
const hasImplicitSourceSelection = expandedFromExplicitSource.has(descriptor.sourceField);
|
|
295
313
|
if (!hasExplicitAnchor && !hasImplicitSourceSelection) continue;
|
|
314
|
+
// A sibling endpoint can identify the file, but must not contribute its
|
|
315
|
+
// selected ranges to this endpoint. Only a typed source supplies a selection.
|
|
296
316
|
if (
|
|
297
317
|
targets !== undefined &&
|
|
298
|
-
|
|
318
|
+
hasImplicitSourceSelection &&
|
|
319
|
+
descriptor.field === firstAnchor?.field
|
|
299
320
|
) {
|
|
300
321
|
implicitTargets.set(descriptor.field, targets);
|
|
301
322
|
}
|
|
@@ -355,9 +376,16 @@ function mergeTargets(left: readonly TextTarget[], right: readonly TextTarget[])
|
|
|
355
376
|
merged.set(target.source, target);
|
|
356
377
|
continue;
|
|
357
378
|
}
|
|
379
|
+
if (
|
|
380
|
+
previous.expectedContent !== undefined &&
|
|
381
|
+
target.expectedContent !== undefined &&
|
|
382
|
+
previous.expectedContent !== target.expectedContent
|
|
383
|
+
)
|
|
384
|
+
throw new Error("Selections refer to different source revisions. Read the source again.");
|
|
358
385
|
const ranges = [...(previous.ranges ?? []), ...(target.ranges ?? [])];
|
|
359
386
|
merged.set(target.source, {
|
|
360
387
|
source: target.source,
|
|
388
|
+
expectedContent: target.expectedContent ?? previous.expectedContent,
|
|
361
389
|
...(ranges.length > 0 && { ranges: deduplicateRanges(ranges) }),
|
|
362
390
|
});
|
|
363
391
|
}
|
|
@@ -698,6 +726,37 @@ export async function executeTextMutation<TParameters extends TSchema>(
|
|
|
698
726
|
publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
|
|
699
727
|
lastResolvedSource?: string,
|
|
700
728
|
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
729
|
+
const execution = await executeTextMutationPipeline(
|
|
730
|
+
core,
|
|
731
|
+
definition,
|
|
732
|
+
parameters,
|
|
733
|
+
signal,
|
|
734
|
+
context,
|
|
735
|
+
publishAnchorRenderState,
|
|
736
|
+
lastResolvedSource,
|
|
737
|
+
);
|
|
738
|
+
const result = await buildToolResult(
|
|
739
|
+
core,
|
|
740
|
+
execution.pipeline,
|
|
741
|
+
execution.source,
|
|
742
|
+
context,
|
|
743
|
+
definition.name,
|
|
744
|
+
);
|
|
745
|
+
return execution.pipeline.kind === "completed" && execution.pipeline.state.metadata !== undefined
|
|
746
|
+
? { ...result, details: { ...result.details, metadata: execution.pipeline.state.metadata } }
|
|
747
|
+
: result;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/** Runs configured mutation semantics without creating model-facing presentation. */
|
|
751
|
+
export async function executeTextMutationPipeline<TParameters extends TSchema>(
|
|
752
|
+
core: TextEditorCore,
|
|
753
|
+
definition: TextMutationToolRegistration<TParameters>,
|
|
754
|
+
parameters: Static<TParameters>,
|
|
755
|
+
signal: AbortSignal | undefined,
|
|
756
|
+
context: ExtensionContext,
|
|
757
|
+
publishAnchorRenderState?: (field: string, state: ToolCallAnchorRenderState) => void,
|
|
758
|
+
lastResolvedSource?: string,
|
|
759
|
+
): Promise<{ readonly pipeline: TextEditExecutionOutcome; readonly source: string }> {
|
|
701
760
|
const source = mutationSource(definition, parameters);
|
|
702
761
|
const pipeline = await core.executeEdit(
|
|
703
762
|
definition.name,
|
|
@@ -708,6 +767,46 @@ export async function executeTextMutation<TParameters extends TSchema>(
|
|
|
708
767
|
},
|
|
709
768
|
async (state) => {
|
|
710
769
|
try {
|
|
770
|
+
if (state.editPlan !== undefined) {
|
|
771
|
+
const plan = state.editPlan;
|
|
772
|
+
if (
|
|
773
|
+
plan.files.length === 0 ||
|
|
774
|
+
new Set(plan.files.map((file) => file.source)).size !== plan.files.length
|
|
775
|
+
)
|
|
776
|
+
throw new Error("Semantic edit plan must contain distinct source files.");
|
|
777
|
+
const outcome = await core.editTexts(
|
|
778
|
+
plan.files.map((file) => ({ source: file.source, read: true })),
|
|
779
|
+
{
|
|
780
|
+
cwd: state.cwd,
|
|
781
|
+
intent: definition.intent ?? "edit",
|
|
782
|
+
...(state.signal !== undefined && { signal: state.signal }),
|
|
783
|
+
},
|
|
784
|
+
(texts) => {
|
|
785
|
+
for (const file of plan.files) {
|
|
786
|
+
if (texts.get(file.source) !== file.expectedContent)
|
|
787
|
+
throw new Error(
|
|
788
|
+
"A semantic edit source changed. Resolve the symbol again before retrying.",
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
const edits = new Map(
|
|
792
|
+
plan.files.map((file) => [
|
|
793
|
+
file.source,
|
|
794
|
+
{ changes: file.changes, action: "edited" as const },
|
|
795
|
+
]),
|
|
796
|
+
);
|
|
797
|
+
return Promise.resolve({
|
|
798
|
+
changes: new Map(plan.files.map((file) => [file.source, file.changes])),
|
|
799
|
+
result: {
|
|
800
|
+
edits,
|
|
801
|
+
resultPresentations: new Map(
|
|
802
|
+
plan.files.map((file) => [file.source, "plain" as const]),
|
|
803
|
+
),
|
|
804
|
+
},
|
|
805
|
+
});
|
|
806
|
+
},
|
|
807
|
+
);
|
|
808
|
+
return await completeTextMutation(outcome, requiredValue(plan.files[0]).source);
|
|
809
|
+
}
|
|
711
810
|
const sources = await resolveMutationSources(
|
|
712
811
|
core,
|
|
713
812
|
definition,
|
|
@@ -727,6 +826,15 @@ export async function executeTextMutation<TParameters extends TSchema>(
|
|
|
727
826
|
...(state.signal !== undefined && { signal: state.signal }),
|
|
728
827
|
},
|
|
729
828
|
async (texts, resolveAnchor) => {
|
|
829
|
+
for (const target of sources.targets) {
|
|
830
|
+
if (
|
|
831
|
+
target.expectedContent !== undefined &&
|
|
832
|
+
texts.get(target.source) !== target.expectedContent
|
|
833
|
+
)
|
|
834
|
+
throw new Error(
|
|
835
|
+
"The selected source changed before editing. Resolve the symbol again.",
|
|
836
|
+
);
|
|
837
|
+
}
|
|
730
838
|
const mutationContext = createMutationContext(
|
|
731
839
|
definition,
|
|
732
840
|
state.input,
|
|
@@ -759,9 +867,142 @@ export async function executeTextMutation<TParameters extends TSchema>(
|
|
|
759
867
|
},
|
|
760
868
|
);
|
|
761
869
|
|
|
762
|
-
return
|
|
870
|
+
return { pipeline, source };
|
|
763
871
|
}
|
|
764
872
|
|
|
873
|
+
const scriptMutationScope = new AsyncLocalStorage<TextEditCompletion[]>();
|
|
874
|
+
|
|
875
|
+
async function captureScriptMutation<T>(core: TextEditorCore, action: () => Promise<T>) {
|
|
876
|
+
const completions: TextEditCompletion[] = [];
|
|
877
|
+
const unsubscribe = core.onDidEdit((completion) => {
|
|
878
|
+
if (scriptMutationScope.getStore() === completions) completions.push(completion);
|
|
879
|
+
});
|
|
880
|
+
try {
|
|
881
|
+
const value = await scriptMutationScope.run(completions, action);
|
|
882
|
+
return { kind: "completed" as const, value, completions };
|
|
883
|
+
} catch (error) {
|
|
884
|
+
return { kind: "failed" as const, error, completions };
|
|
885
|
+
} finally {
|
|
886
|
+
unsubscribe();
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Runs the configured mutation pipeline and returns plain script data.
|
|
891
|
+
* onPresentation retains rich edit annotations on the host without sending classes to the guest.
|
|
892
|
+
*/
|
|
893
|
+
export async function executeScriptMutation<TParameters extends TSchema>(
|
|
894
|
+
core: TextEditorCore,
|
|
895
|
+
definition: TextMutationToolRegistration<TParameters>,
|
|
896
|
+
arguments_: unknown,
|
|
897
|
+
signal: AbortSignal | undefined,
|
|
898
|
+
context: ExtensionContext,
|
|
899
|
+
lastResolvedSource?: string,
|
|
900
|
+
onPresentation?: (source: string, result: FileMutationResult) => void,
|
|
901
|
+
): Promise<ScriptMutationOutcome> {
|
|
902
|
+
const parameters = prepareGuardedArguments(
|
|
903
|
+
definition.parameters,
|
|
904
|
+
arguments_,
|
|
905
|
+
definition.source.inherited ? definition.source.field : undefined,
|
|
906
|
+
lastResolvedSource,
|
|
907
|
+
definition.anchors ?? [],
|
|
908
|
+
);
|
|
909
|
+
if (!Value.Check(definition.parameters, parameters)) {
|
|
910
|
+
throw Object.assign(new Error(`Invalid arguments for ${definition.name}`), {
|
|
911
|
+
code: "INVALID_ARGUMENTS",
|
|
912
|
+
details: { operation: definition.name, effect: "not-applied" },
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
const captured = await captureScriptMutation(core, () =>
|
|
916
|
+
executeTextMutationPipeline(
|
|
917
|
+
core,
|
|
918
|
+
definition,
|
|
919
|
+
parameters,
|
|
920
|
+
signal,
|
|
921
|
+
context,
|
|
922
|
+
undefined,
|
|
923
|
+
lastResolvedSource,
|
|
924
|
+
),
|
|
925
|
+
);
|
|
926
|
+
const source =
|
|
927
|
+
captured.kind === "completed" ? captured.value.source : mutationSource(definition, parameters);
|
|
928
|
+
const observedFiles: ScriptMutationOutcome["files"] = captured.completions.map((completion) => ({
|
|
929
|
+
source: completion.resourceSource,
|
|
930
|
+
before: completion.existed ? completion.before.content : null,
|
|
931
|
+
after: completion.after.content,
|
|
932
|
+
action: definition.name === "write" ? "overwritten" : "edited",
|
|
933
|
+
changes: [],
|
|
934
|
+
formatting: { status: "not-reported" },
|
|
935
|
+
}));
|
|
936
|
+
const failed = (
|
|
937
|
+
code: string,
|
|
938
|
+
message: string,
|
|
939
|
+
effect: ScriptMutationOutcome["effect"],
|
|
940
|
+
completed: readonly string[] = [],
|
|
941
|
+
): ScriptMutationOutcome => ({
|
|
942
|
+
operation: definition.name,
|
|
943
|
+
ok: false,
|
|
944
|
+
effect: effect === "unknown" ? "unknown" : observedFiles.length > 0 ? "applied" : effect,
|
|
945
|
+
completed: [...new Set([...completed, ...observedFiles.map((file) => file.source)])],
|
|
946
|
+
files: observedFiles,
|
|
947
|
+
errors: [{ source, code, message }],
|
|
948
|
+
});
|
|
949
|
+
if (captured.kind === "failed")
|
|
950
|
+
return failed("EXECUTION_FAILED", errorMessage(captured.error), "unknown");
|
|
951
|
+
const { pipeline } = captured.value;
|
|
952
|
+
if (pipeline.kind === "failed")
|
|
953
|
+
return {
|
|
954
|
+
...failed(pipeline.failure.code, pipeline.failure.message, "not-applied"),
|
|
955
|
+
recoveries: await scriptAnchorRecoveries(pipeline.failure.cause),
|
|
956
|
+
};
|
|
957
|
+
const outcome = pipeline.state.result;
|
|
958
|
+
if (!isResourcesEditOutcome(outcome))
|
|
959
|
+
return failed("INVALID_RESULT", "Invalid mutation outcome", "unknown");
|
|
960
|
+
if (outcome.kind === "failed")
|
|
961
|
+
return {
|
|
962
|
+
...failed(
|
|
963
|
+
outcome.failure.code,
|
|
964
|
+
outcome.failure.message,
|
|
965
|
+
outcome.completed.length > 0 ? "unknown" : "not-applied",
|
|
966
|
+
outcome.completed,
|
|
967
|
+
),
|
|
968
|
+
recoveries: await scriptAnchorRecoveries(outcome.failure.cause),
|
|
969
|
+
};
|
|
970
|
+
const mutation = outcome.result as ExecutedTextMutation;
|
|
971
|
+
const files = outcome.resources.flatMap((resource) => {
|
|
972
|
+
const edit = mutation.edits.get(resource.source);
|
|
973
|
+
if (edit === undefined) return [];
|
|
974
|
+
const presentation = withPipelineStatuses(
|
|
975
|
+
buildSuccessfulTextMutationResult(resource, resource.source, edit),
|
|
976
|
+
pipeline.state.metadata,
|
|
977
|
+
);
|
|
978
|
+
onPresentation?.(resource.after.source, presentation);
|
|
979
|
+
const data = presentation.data;
|
|
980
|
+
return [
|
|
981
|
+
{
|
|
982
|
+
source: resource.after.source,
|
|
983
|
+
before:
|
|
984
|
+
captured.completions.find(
|
|
985
|
+
(completion) => completion.resourceSource === resource.after.source,
|
|
986
|
+
)?.existed === false
|
|
987
|
+
? null
|
|
988
|
+
: resource.before.content,
|
|
989
|
+
after: resource.after.content,
|
|
990
|
+
action: edit.action,
|
|
991
|
+
changes: data.rawChanges ?? [],
|
|
992
|
+
formatting: data.formatting ?? { status: "not-reported" as const },
|
|
993
|
+
},
|
|
994
|
+
];
|
|
995
|
+
});
|
|
996
|
+
return {
|
|
997
|
+
operation: definition.name,
|
|
998
|
+
ok: true,
|
|
999
|
+
effect: files.length > 0 ? "applied" : "not-applied",
|
|
1000
|
+
files,
|
|
1001
|
+
completed: files.map((file) => file.source),
|
|
1002
|
+
...(pipeline.state.metadata !== undefined && { metadata: pipeline.state.metadata }),
|
|
1003
|
+
errors: [],
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
765
1006
|
export function mutationSources(
|
|
766
1007
|
definition: TextMutationToolRegistration,
|
|
767
1008
|
parameters: Readonly<Record<string, unknown>>,
|
|
@@ -795,6 +1036,7 @@ type CompletedTextResource = Extract<
|
|
|
795
1036
|
{ readonly kind: "completed" }
|
|
796
1037
|
>;
|
|
797
1038
|
|
|
1039
|
+
/** Builds a mutation receipt; peer ranges are supplied only for per-call batch display results. */
|
|
798
1040
|
export function buildSuccessfulTextMutationResult(
|
|
799
1041
|
resource: CompletedTextResource,
|
|
800
1042
|
resultSource: string,
|
|
@@ -802,10 +1044,17 @@ export function buildSuccessfulTextMutationResult(
|
|
|
802
1044
|
diffAfterContent = resource.after.content,
|
|
803
1045
|
resultPresentation: MutationResultPresentation = "plain",
|
|
804
1046
|
editCount = 1,
|
|
1047
|
+
operations: readonly MutationOperationReceipt[] = [],
|
|
1048
|
+
|
|
1049
|
+
diffPeerRanges?: readonly {
|
|
1050
|
+
readonly from: number;
|
|
1051
|
+
readonly to: number;
|
|
1052
|
+
readonly insert: string;
|
|
1053
|
+
}[],
|
|
805
1054
|
): FileMutationResult {
|
|
806
1055
|
const before = resource.before.content;
|
|
807
1056
|
const finalAfter = resource.after.content;
|
|
808
|
-
const applied = applyTextChanges(before, edit.changes);
|
|
1057
|
+
const applied = applyTextChanges(before, edit.changes, before.length === 0);
|
|
809
1058
|
const unified = createUnifiedDiff(resultSource, before, diffAfterContent);
|
|
810
1059
|
const mutationResultData = resource.postEditContributions
|
|
811
1060
|
.map((contribution) => contribution.data)
|
|
@@ -822,6 +1071,17 @@ export function buildSuccessfulTextMutationResult(
|
|
|
822
1071
|
|
|
823
1072
|
return new FileMutationResult({
|
|
824
1073
|
...mutationResultData,
|
|
1074
|
+
|
|
1075
|
+
...(diffPeerRanges === undefined ? {} : { diffPeerRanges }),
|
|
1076
|
+
|
|
1077
|
+
operations,
|
|
1078
|
+
diffStatuses: resource.postEditContributions
|
|
1079
|
+
.map((item) => item.data)
|
|
1080
|
+
.filter(isDiffStatusContribution)
|
|
1081
|
+
.flatMap((item) => item.diffStatuses),
|
|
1082
|
+
formatting: resource.postEditContributions
|
|
1083
|
+
.map((item) => item.data)
|
|
1084
|
+
.findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
|
|
825
1085
|
ok: true,
|
|
826
1086
|
path: resultSource,
|
|
827
1087
|
diffs: [unified.diff],
|
|
@@ -868,6 +1128,7 @@ async function buildToolResult(
|
|
|
868
1128
|
pipeline: TextEditExecutionOutcome,
|
|
869
1129
|
source: string,
|
|
870
1130
|
context: ExtensionContext,
|
|
1131
|
+
operation: string,
|
|
871
1132
|
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
872
1133
|
if (pipeline.kind === "failed") {
|
|
873
1134
|
return failureToolResult(
|
|
@@ -916,16 +1177,50 @@ async function buildToolResult(
|
|
|
916
1177
|
edit,
|
|
917
1178
|
undefined,
|
|
918
1179
|
mutation.resultPresentations.get(resultSource) ?? "plain",
|
|
1180
|
+
|
|
1181
|
+
1,
|
|
1182
|
+
[{ operation, changes: edit.changes.length }],
|
|
919
1183
|
),
|
|
920
1184
|
];
|
|
921
1185
|
});
|
|
922
1186
|
|
|
1187
|
+
const presented = results.map((result) => withPipelineStatuses(result, pipeline.state.metadata));
|
|
923
1188
|
return {
|
|
924
|
-
content: [new FileMutationAgentResult(
|
|
925
|
-
details: { results },
|
|
1189
|
+
content: [new FileMutationAgentResult(presented).toTextContent()],
|
|
1190
|
+
details: { results: presented },
|
|
926
1191
|
};
|
|
927
1192
|
}
|
|
928
1193
|
|
|
1194
|
+
function withPipelineStatuses(result: FileMutationResult, metadata: unknown): FileMutationResult {
|
|
1195
|
+
if (!isDiffStatusContribution(metadata)) return result;
|
|
1196
|
+
return new FileMutationResult({
|
|
1197
|
+
...result.data,
|
|
1198
|
+
diffStatuses: [...(result.data.diffStatuses ?? []), ...metadata.diffStatuses],
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
async function resolveAnchorRecovery(error: TextMutationAnchorResolutionError) {
|
|
1202
|
+
if (error.resolution.recovery === undefined) await error.resolution.refreshRecovery();
|
|
1203
|
+
return error.resolution.recovery;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
async function scriptAnchorRecoveries(
|
|
1207
|
+
cause: unknown,
|
|
1208
|
+
): Promise<NonNullable<ScriptMutationOutcome["recoveries"]>> {
|
|
1209
|
+
if (cause instanceof TextMutationAnchorAggregateError)
|
|
1210
|
+
return (await Promise.all(cause.failures.map(scriptAnchorRecoveries))).flat();
|
|
1211
|
+
if (!(cause instanceof TextMutationAnchorResolutionError)) return [];
|
|
1212
|
+
const recovery = await resolveAnchorRecovery(cause);
|
|
1213
|
+
return [
|
|
1214
|
+
{
|
|
1215
|
+
path: cause.source,
|
|
1216
|
+
field: cause.field,
|
|
1217
|
+
anchor: cause.anchor,
|
|
1218
|
+
status: recovery?.kind ?? "unavailable",
|
|
1219
|
+
candidates: recovery?.kind === "candidates" ? recovery.candidates : [],
|
|
1220
|
+
total: recovery?.kind === "candidates" ? recovery.total : 0,
|
|
1221
|
+
},
|
|
1222
|
+
];
|
|
1223
|
+
}
|
|
929
1224
|
async function anchorFailureToolResult(
|
|
930
1225
|
core: TextEditorCore,
|
|
931
1226
|
failure: TextResourceEditFailure,
|
|
@@ -966,10 +1261,7 @@ async function anchorFailureToolResult(
|
|
|
966
1261
|
|
|
967
1262
|
const contextual = failure.cause;
|
|
968
1263
|
const resolution = contextual.resolution;
|
|
969
|
-
|
|
970
|
-
await resolution.refreshRecovery();
|
|
971
|
-
}
|
|
972
|
-
const recovery = resolution.recovery;
|
|
1264
|
+
const recovery = await resolveAnchorRecovery(contextual);
|
|
973
1265
|
if (recovery?.kind === "timed-out") {
|
|
974
1266
|
return failureToolResult(
|
|
975
1267
|
contextual.source,
|
|
@@ -50,6 +50,7 @@ export function singleAnchorSpan(
|
|
|
50
50
|
context: TextMutationContext,
|
|
51
51
|
anchors: ReadonlyMap<string, TextAnchor>,
|
|
52
52
|
field: string,
|
|
53
|
+
wholeLines = false,
|
|
53
54
|
): TextAnchorSpan {
|
|
54
55
|
if (anchors.size !== 1) {
|
|
55
56
|
throw new Error(`Anchor ${field} must resolve in one resource.`);
|
|
@@ -63,7 +64,9 @@ export function singleAnchorSpan(
|
|
|
63
64
|
const selectedRange = requiredValue(anchor.ranges[0]);
|
|
64
65
|
const document = context.documentFor(source);
|
|
65
66
|
const exactRange = selectionRange(context, source, selectedRange);
|
|
66
|
-
const endLine =
|
|
67
|
+
const endLine = wholeLines
|
|
68
|
+
? containingEndLine(selectedRange)
|
|
69
|
+
: linewiseSelectionEndLine(selectedRange);
|
|
67
70
|
if (endLine !== undefined) {
|
|
68
71
|
const range = document.lineRange(selectedRange.start.lineNumber, endLine);
|
|
69
72
|
return {
|
|
@@ -89,7 +92,7 @@ export function singleAnchorSpan(
|
|
|
89
92
|
};
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
/**
|
|
95
|
+
/** A single anchor keeps its own extent; two ordered anchors select inclusive whole lines. */
|
|
93
96
|
export function anchorSpanRange(
|
|
94
97
|
context: TextMutationContext,
|
|
95
98
|
starts: ReadonlyMap<string, TextAnchor>,
|
|
@@ -102,15 +105,18 @@ export function anchorSpanRange(
|
|
|
102
105
|
if (start.source !== end.source) {
|
|
103
106
|
throw new Error(`Anchors ${startField} and ${endField} must resolve in one resource.`);
|
|
104
107
|
}
|
|
105
|
-
if (start.from > end.
|
|
108
|
+
if (start.from > end.from) {
|
|
106
109
|
throw new Error(`Anchor ${startField} must not come after ${endField}.`);
|
|
107
110
|
}
|
|
111
|
+
if (ends === undefined) return start;
|
|
112
|
+
const first = singleAnchorSpan(context, starts, startField, true);
|
|
113
|
+
const last = singleAnchorSpan(context, ends, endField, true);
|
|
108
114
|
return {
|
|
109
|
-
source:
|
|
110
|
-
from:
|
|
111
|
-
to:
|
|
112
|
-
selection:
|
|
113
|
-
preservesTrailingLineBreak:
|
|
115
|
+
source: first.source,
|
|
116
|
+
from: first.from,
|
|
117
|
+
to: last.to,
|
|
118
|
+
selection: false,
|
|
119
|
+
preservesTrailingLineBreak: true,
|
|
114
120
|
};
|
|
115
121
|
}
|
|
116
122
|
|
|
@@ -120,12 +126,13 @@ export function targetText(context: TextMutationContext, source: string, text: s
|
|
|
120
126
|
return text.replace(/\r\n|\r|\n/gu, separator);
|
|
121
127
|
}
|
|
122
128
|
|
|
123
|
-
/**
|
|
129
|
+
/** Empty text deletes the selection; nonempty text preserves a line endpoint's separator. */
|
|
124
130
|
export function replaceAnchorSpan(
|
|
125
131
|
context: TextMutationContext,
|
|
126
132
|
span: TextAnchorSpan,
|
|
127
133
|
text: string,
|
|
128
134
|
): { readonly from: number; readonly to: number; readonly insert: string } {
|
|
135
|
+
if (text === "") return deleteAnchorSpan(context, span);
|
|
129
136
|
const document = context.documentFor(span.source);
|
|
130
137
|
let insert = targetText(context, span.source, text);
|
|
131
138
|
const selected = document.text(span);
|
|
@@ -159,18 +166,15 @@ export function deleteAnchorSpan(
|
|
|
159
166
|
return { from: span.from, to: span.to, insert: "" };
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
/**
|
|
169
|
+
/** Inserts after the last containing line of one resolved anchor. */
|
|
163
170
|
export function insertionAfterAnchor(
|
|
164
171
|
context: TextMutationContext,
|
|
165
172
|
anchors: ReadonlyMap<string, TextAnchor>,
|
|
166
173
|
field: string,
|
|
167
174
|
insert: string,
|
|
168
175
|
): readonly [string, { readonly from: number; readonly to: number; readonly insert: string }] {
|
|
169
|
-
const span = singleAnchorSpan(context, anchors, field);
|
|
176
|
+
const span = singleAnchorSpan(context, anchors, field, true);
|
|
170
177
|
const normalizedInsert = targetText(context, span.source, insert);
|
|
171
|
-
if (span.selection) {
|
|
172
|
-
return [span.source, { from: span.to, to: span.to, insert: normalizedInsert }];
|
|
173
|
-
}
|
|
174
178
|
|
|
175
179
|
const lineNumber = span.linewiseEndLine ?? lineAnchor(anchors, field).lineNumber;
|
|
176
180
|
return [
|
|
@@ -179,18 +183,15 @@ export function insertionAfterAnchor(
|
|
|
179
183
|
];
|
|
180
184
|
}
|
|
181
185
|
|
|
182
|
-
/**
|
|
186
|
+
/** Inserts before the first containing line of one resolved anchor. */
|
|
183
187
|
export function insertionBeforeAnchor(
|
|
184
188
|
context: TextMutationContext,
|
|
185
189
|
anchors: ReadonlyMap<string, TextAnchor>,
|
|
186
190
|
field: string,
|
|
187
191
|
insert: string,
|
|
188
192
|
): readonly [string, { readonly from: number; readonly to: number; readonly insert: string }] {
|
|
189
|
-
const span = singleAnchorSpan(context, anchors, field);
|
|
193
|
+
const span = singleAnchorSpan(context, anchors, field, true);
|
|
190
194
|
const normalizedInsert = targetText(context, span.source, insert);
|
|
191
|
-
if (span.selection) {
|
|
192
|
-
return [span.source, { from: span.from, to: span.from, insert: normalizedInsert }];
|
|
193
|
-
}
|
|
194
195
|
|
|
195
196
|
const lineNumber = span.linewiseStartLine ?? lineAnchor(anchors, field).lineNumber;
|
|
196
197
|
return [
|
|
@@ -233,15 +234,16 @@ export function selectionChanges(
|
|
|
233
234
|
(insert.length === 0 ? coalesceAdjacentLinewiseRanges(anchor.ranges) : anchor.ranges).map(
|
|
234
235
|
(range) => {
|
|
235
236
|
const span = selectionRange(context, source, range);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
237
|
+
return replaceAnchorSpan(
|
|
238
|
+
context,
|
|
239
|
+
{
|
|
240
|
+
source,
|
|
241
|
+
...span,
|
|
242
|
+
selection: range.linewise !== true,
|
|
243
|
+
preservesTrailingLineBreak: range.linewise === true,
|
|
244
|
+
},
|
|
245
|
+
insert,
|
|
246
|
+
);
|
|
245
247
|
},
|
|
246
248
|
),
|
|
247
249
|
]),
|
|
@@ -261,23 +263,19 @@ export function insertionChanges(
|
|
|
261
263
|
return new Map(
|
|
262
264
|
[...selections].map(([source, anchor]) => [
|
|
263
265
|
source,
|
|
264
|
-
|
|
266
|
+
[
|
|
267
|
+
...new Set(
|
|
268
|
+
anchor.ranges.map((range) => {
|
|
269
|
+
selectionRange(context, source, range);
|
|
270
|
+
return before ? range.start.lineNumber : containingEndLine(range);
|
|
271
|
+
}),
|
|
272
|
+
),
|
|
273
|
+
].map((line) => {
|
|
265
274
|
const document = context.documentFor(source);
|
|
266
275
|
const normalizedInsert = targetText(context, source, insert);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
? document.insertBeforeLine(range.start.lineNumber, normalizedInsert)
|
|
271
|
-
: document.insertAfterLine(linewiseEnd, normalizedInsert);
|
|
272
|
-
}
|
|
273
|
-
const position = before ? range.start : range.end;
|
|
274
|
-
const at = document.range(
|
|
275
|
-
position.lineNumber,
|
|
276
|
-
position.column,
|
|
277
|
-
position.lineNumber,
|
|
278
|
-
position.column,
|
|
279
|
-
);
|
|
280
|
-
return { ...at, insert: normalizedInsert };
|
|
276
|
+
return before
|
|
277
|
+
? document.insertBeforeLine(line, normalizedInsert)
|
|
278
|
+
: document.insertAfterLine(line, normalizedInsert);
|
|
281
279
|
}),
|
|
282
280
|
]),
|
|
283
281
|
);
|
|
@@ -314,6 +312,10 @@ function linewiseSelectionEndLine(range: TextSelectionRange): number | undefined
|
|
|
314
312
|
if (range.linewise !== true) {
|
|
315
313
|
return undefined;
|
|
316
314
|
}
|
|
315
|
+
return containingEndLine(range);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function containingEndLine(range: TextSelectionRange): number {
|
|
317
319
|
return range.end.column === 0 && range.end.lineNumber > range.start.lineNumber
|
|
318
320
|
? range.end.lineNumber - 1
|
|
319
321
|
: range.end.lineNumber;
|