pi-agent-ide 0.7.1 → 0.7.3
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 +66 -0
- package/README.md +3 -1
- package/dist/{chunk-PKKDDIWW.js → chunk-2ZMMRINH.js} +1 -1
- package/dist/chunk-6U5OU77O.js +3 -0
- package/dist/chunk-BYZSBXUK.js +2 -0
- package/dist/{chunk-LEEQIQ7D.js → chunk-CEX73RI5.js} +6 -6
- package/dist/chunk-DZWTKF2K.js +1 -0
- package/dist/{chunk-WMO6RNE2.js → chunk-EOKEQ3YH.js} +6 -6
- package/dist/{chunk-HZEY4GT4.js → chunk-H445SHSJ.js} +2 -2
- package/dist/{chunk-4GCWGE2C.js → chunk-HZ5BNF3A.js} +1 -1
- package/dist/chunk-IG56UGSO.js +2 -0
- package/dist/chunk-IICJXZBU.js +6 -0
- package/dist/{chunk-XYS4FSCC.js → chunk-IM24DB3K.js} +1 -1
- package/dist/chunk-MXLSGMRZ.js +3 -0
- package/dist/{chunk-76ZK5ODR.js → chunk-NHKPP2AI.js} +13 -13
- package/dist/chunk-OB46OPMZ.js +1 -0
- package/dist/{chunk-PNU3E7IO.js → chunk-Q6CZ6GBR.js} +2 -2
- package/dist/chunk-QUYXINGZ.js +7 -0
- package/dist/{chunk-OMVRLWMX.js → chunk-SBP3ABH4.js} +1 -1
- package/dist/{chunk-YP46DVVP.js → chunk-STBJO3Z3.js} +1 -1
- package/dist/{chunk-2TRHFMCZ.js → chunk-TXOTNK6B.js} +1 -1
- package/dist/chunk-WLZIUMJL.js +1 -0
- package/dist/chunk-ZIWPKIBZ.js +1 -0
- package/dist/entry-11.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +1 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-31.js +12 -11
- package/dist/entry-33.js +3 -1
- package/dist/entry-37.js +6 -6
- package/dist/entry-42.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +20 -12
- package/dist/entry-46.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +7 -6
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-77.js +63 -49
- package/dist/entry-78.js +15 -14
- package/dist/entry-79.js +1 -1
- package/dist/entry-82.js +5 -5
- package/dist/entry-83.js +1 -1
- package/dist/entry-84.js +1 -1
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/pi-agent-ide.js +34 -11
- package/docs/agent-guides/editing.md +14 -7
- package/docs/agent-guides/git-changes.md +10 -0
- package/docs/agent-guides/read-resources.md +9 -46
- package/docs/agent-guides/search-code.md +7 -1
- package/docs/agent-guides/select-code.md +1 -0
- package/docs/agent-guides/terminal.md +9 -1
- package/docs/configuration.md +22 -1
- package/docs/development.md +4 -0
- package/docs/directory-operations.md +45 -0
- package/docs/releases.md +12 -0
- package/docs/research/codemode-write-context.md +56 -0
- package/docs/research/native-codemode-batch-decision.md +2 -0
- package/docs/structured-results.md +2 -2
- package/docs/tools.md +10 -2
- package/docs/user-hooks.md +26 -0
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-jq/src/jq.ts +4 -1
- 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 +13 -13
- package/node_modules/pi-agent-ide-ast/src/extension.ts +3 -3
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +0 -3
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +8 -6
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +13 -5
- package/node_modules/pi-agent-ide-changes/package.json +9 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lsp/index.ts +1 -1
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
- 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 +7 -7
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +3 -3
- package/node_modules/pi-agent-read/src/api/tools/read.ts +11 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +1 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +5 -1
- package/node_modules/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
- package/node_modules/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +99 -44
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +1 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +6 -3
- package/node_modules/{pi-agent-read/src/core/tools/read → pi-agent-resource/src}/temp-resource-store.ts +17 -7
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +5 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +2 -2
- package/node_modules/pi-agent-search/src/core/extension.ts +2 -1
- package/node_modules/pi-agent-search/src/core/search-core.ts +13 -4
- package/node_modules/pi-agent-search-text/package.json +7 -7
- package/node_modules/pi-agent-search-text/src/resolvers.ts +11 -1
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +42 -32
- package/node_modules/pi-agent-search-text/src/search-recipe.ts +1 -1
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +6 -0
- package/node_modules/pi-agent-search-text/src/search-result.ts +17 -3
- package/node_modules/pi-agent-text/package.json +2 -2
- 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-editor/package.json +9 -9
- package/node_modules/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
- package/node_modules/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
- package/node_modules/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +30 -40
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +24 -4
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +21 -14
- package/node_modules/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
- package/node_modules/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
- package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
- package/node_modules/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
- package/node_modules/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/package.json +1 -1
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web/src/resolver.ts +11 -13
- package/node_modules/pi-agent-web-html/package.json +2 -2
- package/node_modules/pi-agent-web-image/package.json +3 -3
- package/node_modules/pi-agent-web-pdf/package.json +3 -3
- package/node_modules/pi-agent-web-text/package.json +3 -3
- package/package.json +36 -35
- package/src/api/hooks.ts +24 -0
- package/src/composite/nested-tool-rendering.ts +184 -77
- package/src/composite/output-limits.ts +125 -0
- package/src/composite/responses-tools.ts +25 -0
- package/src/composite/text-results.ts +158 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- 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-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/src/jq.ts +4 -1
- 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 +2 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +11 -13
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +3 -3
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +11 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +1 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +5 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/output-truncation.ts +91 -18
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +8 -2
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +38 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/read-result.ts +57 -2
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +99 -44
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +11 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +42 -32
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-recipe.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +6 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +17 -3
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +5 -1
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +2 -2
- package/src/extensions/pi-agent-search/src/core/extension.ts +2 -1
- package/src/extensions/pi-agent-search/src/core/search-core.ts +13 -4
- package/src/extensions/pi-agent-text-editor/package.json +9 -9
- 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-editor-renderer/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/mutation-panel.ts +11 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +75 -11
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/status-summary.ts +18 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/src/api/delete-guard.ts +24 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +1 -2
- package/src/extensions/pi-agent-text-editor/src/api/native-edit-batch-event.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +4 -1
- package/src/extensions/pi-agent-text-editor/src/api/stale-anchor-message.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/delete-policy.ts +284 -0
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +54 -12
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +32 -3
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +30 -40
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-transfers.ts +164 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +36 -12
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +25 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +132 -11
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +286 -162
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +34 -10
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +24 -4
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +46 -11
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +21 -14
- package/src/extensions/pi-agent-text-editor/src/core/temporary-directories.ts +96 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +5 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +155 -22
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +126 -32
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +428 -189
- package/src/extensions/pi-agent-text-editor/src/core/write-agent-result.ts +66 -0
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +15 -6
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +9 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +6 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +2 -3
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
- package/src/pi-agent-ide.ts +11 -0
- package/src/plugins/pi-agent-ide-ast/package.json +13 -13
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +3 -3
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +9 -4
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +0 -3
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +8 -6
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +13 -5
- package/src/plugins/pi-agent-ide-changes/package.json +9 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +82 -4
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- package/src/plugins/pi-agent-ide-debugger/index.ts +20 -8
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +5 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +93 -38
- package/src/plugins/pi-agent-ide-diagnostics/src/extension.ts +3 -2
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lsp/index.ts +1 -1
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/declaration-targets.ts +2 -1
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +0 -1
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +3 -3
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +3 -3
- package/src/plugins/pi-agent-ide-vision/index.ts +1 -0
- package/src/post-edit/gate.ts +13 -2
- package/dist/chunk-4XMY4H4V.js +0 -1
- package/dist/chunk-64M3SQPG.js +0 -3
- package/dist/chunk-CWD4O5PM.js +0 -3
- package/dist/chunk-D3WTDA6V.js +0 -2
- package/dist/chunk-EAZGN5ND.js +0 -7
- package/dist/chunk-GXEGY7GV.js +0 -1
- package/dist/chunk-MBUXFKIW.js +0 -3
- package/dist/chunk-PGIVHICI.js +0 -1
- package/dist/chunk-VMTR74FF.js +0 -2
- package/dist/chunk-WU6ZK6YD.js +0 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +0 -105
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { connectResultTargets, type ResultTargetStore } from "pi-agent-resource";
|
|
2
|
+
import {
|
|
3
|
+
committedMutationTargets,
|
|
4
|
+
describeUnavailableCopyTarget,
|
|
5
|
+
unchangedCopySources,
|
|
6
|
+
} from "./mutation-result-targets.js";
|
|
1
7
|
import { requiredValue } from "pi-agent-invariant";
|
|
2
8
|
import { renderTextAnchor } from "pi-agent-text";
|
|
3
9
|
import {
|
|
@@ -29,15 +35,21 @@ import {
|
|
|
29
35
|
TextMutationAnchorResolutionError,
|
|
30
36
|
} from "#src/core/text-mutation-anchor-error.js";
|
|
31
37
|
import {
|
|
38
|
+
buildFailedCopyWriteResult,
|
|
32
39
|
buildFailedTextMutationResult,
|
|
33
40
|
buildSuccessfulTextMutationResult,
|
|
34
41
|
mutationSources,
|
|
35
42
|
preflightMutationAnchors,
|
|
43
|
+
textMutationOperationReceipts,
|
|
36
44
|
} from "#src/core/text-mutation.js";
|
|
37
45
|
import { registerBlockedToolCallSink } from "#src/core/tool-call-interceptor/coordinator.js";
|
|
38
46
|
|
|
39
47
|
import type { TextEditIntent } from "#src/api/edit-completion.js";
|
|
40
|
-
import type {
|
|
48
|
+
import type {
|
|
49
|
+
FileMutationBatchResult,
|
|
50
|
+
FileMutationResult,
|
|
51
|
+
MutationResultPresentation,
|
|
52
|
+
} from "#src/api/mutation-result.js";
|
|
41
53
|
import type { AnyTextMutationToolRegistration, TextMutation } from "#src/api/mutation-tool.js";
|
|
42
54
|
import type { BatchExecutionReporter } from "#src/core/text-edit-batch-execution.js";
|
|
43
55
|
import type {
|
|
@@ -90,6 +102,7 @@ export function setTextEditBatchRenderArgumentSink(
|
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
export function registerTextEditBatching(pi: ExtensionAPI, core: TextEditorCore): void {
|
|
105
|
+
const resultTargets = connectResultTargets(pi);
|
|
93
106
|
const sourceTools: string[] = [];
|
|
94
107
|
const registrations = new Map<string, AnyTextMutationToolRegistration>();
|
|
95
108
|
const renderArguments = (toolCallId: string, patch: Readonly<Record<string, unknown>>): void =>
|
|
@@ -159,6 +172,8 @@ export function registerTextEditBatching(pi: ExtensionAPI, core: TextEditorCore)
|
|
|
159
172
|
context,
|
|
160
173
|
reporter,
|
|
161
174
|
renderArguments,
|
|
175
|
+
undefined,
|
|
176
|
+
resultTargets,
|
|
162
177
|
),
|
|
163
178
|
splitResult: splitTextBatchResult,
|
|
164
179
|
onRenderArguments: renderArguments,
|
|
@@ -301,6 +316,7 @@ export async function executeRegisteredTextBatch(
|
|
|
301
316
|
reporter: BatchExecutionReporter,
|
|
302
317
|
renderArguments: (toolCallId: string, patch: Readonly<Record<string, unknown>>) => void,
|
|
303
318
|
planned?: PlannedTextBatch,
|
|
319
|
+
resultTargets?: ResultTargetStore,
|
|
304
320
|
): Promise<AgentToolResult<TextBatchDetails>> {
|
|
305
321
|
const prepared = parameters.edits.map((entry) => {
|
|
306
322
|
const registration = registrations.get(entry.op);
|
|
@@ -339,12 +355,15 @@ export async function executeRegisteredTextBatch(
|
|
|
339
355
|
}
|
|
340
356
|
|
|
341
357
|
let outcome: TextResourcesEditOutcome<PlannedTextBatch>;
|
|
358
|
+
let executionPlan = planned;
|
|
359
|
+
const guardedSnapshots = new Map<string, string>();
|
|
342
360
|
|
|
343
361
|
try {
|
|
344
362
|
outcome = await core.editTexts(
|
|
345
363
|
[...requests.values()],
|
|
346
364
|
{ cwd: context.cwd, intent, ...(signal !== undefined && { signal }) },
|
|
347
365
|
async (texts, resolveAnchor) => {
|
|
366
|
+
for (const [source, content] of texts) guardedSnapshots.set(source, content);
|
|
348
367
|
for (const [source, expected] of parameters.expectedContent ?? []) {
|
|
349
368
|
if (!texts.has(source) || texts.get(source) !== expected) {
|
|
350
369
|
throw new Error(`Snapshot source ${source} changed before the edit batch.`);
|
|
@@ -361,6 +380,7 @@ export async function executeRegisteredTextBatch(
|
|
|
361
380
|
signal,
|
|
362
381
|
renderArguments,
|
|
363
382
|
));
|
|
383
|
+
executionPlan = result;
|
|
364
384
|
return { changes: result.changes, result };
|
|
365
385
|
},
|
|
366
386
|
);
|
|
@@ -375,12 +395,46 @@ export async function executeRegisteredTextBatch(
|
|
|
375
395
|
}
|
|
376
396
|
|
|
377
397
|
if (outcome.kind === "failed") {
|
|
398
|
+
const copyResults = new Map<string, AgentToolResult<FileMutationBatchResult>>();
|
|
399
|
+
if (outcome.failure.code === "WRITE_FAILED") {
|
|
400
|
+
for (const { callId, mutation } of executionPlan?.mutations ?? []) {
|
|
401
|
+
if (mutation.operation !== "copy") continue;
|
|
402
|
+
const unrestored = (outcome.failure.rollback?.failed ?? outcome.completed).filter(
|
|
403
|
+
(source) => mutation.edits.has(source),
|
|
404
|
+
);
|
|
405
|
+
const destination = unrestored[0] ?? mutation.edits.keys().next().value;
|
|
406
|
+
copyResults.set(
|
|
407
|
+
callId,
|
|
408
|
+
buildFailedCopyWriteResult(
|
|
409
|
+
{
|
|
410
|
+
...outcome.failure,
|
|
411
|
+
source: destination ?? outcome.failure.source,
|
|
412
|
+
...(outcome.failure.rollback !== undefined && {
|
|
413
|
+
rollback: {
|
|
414
|
+
restored: outcome.failure.rollback.restored.filter((source) =>
|
|
415
|
+
mutation.edits.has(source),
|
|
416
|
+
),
|
|
417
|
+
failed: outcome.failure.rollback.failed.filter((source) =>
|
|
418
|
+
mutation.edits.has(source),
|
|
419
|
+
),
|
|
420
|
+
originallyMissing: outcome.failure.rollback.originallyMissing.filter((source) =>
|
|
421
|
+
mutation.edits.has(source),
|
|
422
|
+
),
|
|
423
|
+
},
|
|
424
|
+
}),
|
|
425
|
+
},
|
|
426
|
+
unrestored,
|
|
427
|
+
),
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
378
431
|
return failTextBatch(
|
|
379
432
|
core,
|
|
380
433
|
prepared.map(({ callId }) => callId),
|
|
381
434
|
outcome.failure,
|
|
382
435
|
context,
|
|
383
436
|
reporter,
|
|
437
|
+
copyResults,
|
|
384
438
|
);
|
|
385
439
|
}
|
|
386
440
|
|
|
@@ -433,7 +487,7 @@ export async function executeRegisteredTextBatch(
|
|
|
433
487
|
mutation.resultPresentations.get(source) ?? "plain",
|
|
434
488
|
|
|
435
489
|
1,
|
|
436
|
-
|
|
490
|
+
textMutationOperationReceipts(mutation.operation, edit, resource.before.content),
|
|
437
491
|
|
|
438
492
|
completedMutations.flatMap((peer) =>
|
|
439
493
|
peer.callId === callId
|
|
@@ -451,7 +505,12 @@ export async function executeRegisteredTextBatch(
|
|
|
451
505
|
displayResults.push(...callDisplayResults);
|
|
452
506
|
callIdsByDisplayResult.push(...callDisplayResults.map(() => callId));
|
|
453
507
|
|
|
508
|
+
const unchangedCopy =
|
|
509
|
+
mutation.operation === "copy" &&
|
|
510
|
+
mutation.edits.size > 0 &&
|
|
511
|
+
unchangedCopySources(mutation, guardedSnapshots).size === mutation.edits.size;
|
|
454
512
|
for (const source of mutation.edits.keys()) {
|
|
513
|
+
if (unchangedCopy && finalCallIdBySource.has(source)) continue;
|
|
455
514
|
finalCallIdBySource.set(source, callId);
|
|
456
515
|
finalPresentationBySource.set(source, mutation.resultPresentations.get(source) ?? "plain");
|
|
457
516
|
}
|
|
@@ -483,7 +542,7 @@ export async function executeRegisteredTextBatch(
|
|
|
483
542
|
const edit = mutation.edits.get(source);
|
|
484
543
|
return edit === undefined
|
|
485
544
|
? []
|
|
486
|
-
:
|
|
545
|
+
: textMutationOperationReceipts(mutation.operation, edit, resource.before.content);
|
|
487
546
|
}),
|
|
488
547
|
);
|
|
489
548
|
resultsByCallId.get(finalCallId)?.push(result);
|
|
@@ -491,17 +550,82 @@ export async function executeRegisteredTextBatch(
|
|
|
491
550
|
callIdsByResult.push(finalCallId);
|
|
492
551
|
}
|
|
493
552
|
|
|
553
|
+
const copyResults = new Map<string, AgentToolResult<FileMutationBatchResult>>();
|
|
554
|
+
if (resultTargets) {
|
|
555
|
+
const copies = completedMutations.filter(
|
|
556
|
+
({ mutation }) => mutation.operation === "copy" && mutation.edits.size > 0,
|
|
557
|
+
);
|
|
558
|
+
for (const { callId, mutation } of copies) {
|
|
559
|
+
const sources = new Set(mutation.edits.keys());
|
|
560
|
+
let metadata: FileMutationBatchResult["metadata"];
|
|
561
|
+
try {
|
|
562
|
+
const mapped = committedMutationTargets(
|
|
563
|
+
completedMutations.map(({ callId, mutation }) => ({
|
|
564
|
+
callId,
|
|
565
|
+
edits: new Map([...mutation.edits].filter(([source]) => sources.has(source))),
|
|
566
|
+
})),
|
|
567
|
+
// Copy read these destinations successfully, so they existed before the batch.
|
|
568
|
+
outcome.resources
|
|
569
|
+
.filter((resource) => sources.has(resource.source))
|
|
570
|
+
.map((resource) => ({
|
|
571
|
+
source: resource.source,
|
|
572
|
+
resourceSource: resource.after.source,
|
|
573
|
+
resolvedBy: resource.resolvedBy,
|
|
574
|
+
before: resource.before,
|
|
575
|
+
after: resource.after,
|
|
576
|
+
existed: true,
|
|
577
|
+
})),
|
|
578
|
+
guardedSnapshots,
|
|
579
|
+
);
|
|
580
|
+
const targets = mapped.get(callId);
|
|
581
|
+
const expectedTargets = [...mutation.edits.values()].filter(
|
|
582
|
+
(edit) => edit.resultChanges?.length !== 0,
|
|
583
|
+
).length;
|
|
584
|
+
if (!targets || targets.length !== expectedTargets)
|
|
585
|
+
throw new Error("This operation did not produce confirmed filesystem targets.");
|
|
586
|
+
const reference = resultTargets.register(targets, context.cwd);
|
|
587
|
+
await resultTargets.verify(resultTargets.resolve(reference, context.cwd), signal);
|
|
588
|
+
metadata = { resultTarget: reference };
|
|
589
|
+
} catch (error) {
|
|
590
|
+
signal?.throwIfAborted();
|
|
591
|
+
metadata = { targetUnavailable: errorMessage(error) };
|
|
592
|
+
}
|
|
593
|
+
const unchanged =
|
|
594
|
+
unchangedCopySources(mutation, guardedSnapshots).size === mutation.edits.size;
|
|
595
|
+
const ownResults = resultsByCallId.get(callId) ?? [];
|
|
596
|
+
const displayed = displayResultsByCallId.get(callId) ?? [];
|
|
597
|
+
const receipt = textBatchResult(
|
|
598
|
+
ownResults.length > 0 ? ownResults : displayed,
|
|
599
|
+
[],
|
|
600
|
+
displayed,
|
|
601
|
+
[],
|
|
602
|
+
);
|
|
603
|
+
copyResults.set(
|
|
604
|
+
callId,
|
|
605
|
+
describeUnavailableCopyTarget({
|
|
606
|
+
...receipt,
|
|
607
|
+
...(unchanged
|
|
608
|
+
? {
|
|
609
|
+
content: [{ type: "text", text: "No changes: destination already has this text." }],
|
|
610
|
+
}
|
|
611
|
+
: {}),
|
|
612
|
+
details: { ...receipt.details, effect: unchanged ? "not-applied" : "applied", metadata },
|
|
613
|
+
}),
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
494
617
|
for (const { callId } of completedMutations) {
|
|
495
618
|
const callResults = resultsByCallId.get(callId) ?? [];
|
|
496
619
|
const callDisplayResults = displayResultsByCallId.get(callId) ?? [];
|
|
497
620
|
reporter.complete(
|
|
498
621
|
callId,
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
622
|
+
copyResults.get(callId) ??
|
|
623
|
+
textBatchResult(
|
|
624
|
+
callResults,
|
|
625
|
+
callResults.map(() => callId),
|
|
626
|
+
callDisplayResults,
|
|
627
|
+
callDisplayResults.map(() => callId),
|
|
628
|
+
),
|
|
505
629
|
);
|
|
506
630
|
}
|
|
507
631
|
|
|
@@ -556,7 +680,10 @@ export async function executeRegisteredTextBatch(
|
|
|
556
680
|
callIdsByDisplayResult: [...callIdsByDisplayResult],
|
|
557
681
|
},
|
|
558
682
|
});
|
|
559
|
-
|
|
683
|
+
const result = textBatchResult(results, callIdsByResult, displayResults, callIdsByDisplayResult);
|
|
684
|
+
return copyResults.size === 0
|
|
685
|
+
? result
|
|
686
|
+
: { ...result, details: { ...result.details, copyResults } };
|
|
560
687
|
}
|
|
561
688
|
|
|
562
689
|
async function failTextBatch(
|
|
@@ -565,32 +692,38 @@ async function failTextBatch(
|
|
|
565
692
|
error: unknown,
|
|
566
693
|
context: ExtensionContext,
|
|
567
694
|
reporter: BatchExecutionReporter,
|
|
695
|
+
copyResults: ReadonlyMap<string, AgentToolResult<FileMutationBatchResult>> = new Map(),
|
|
568
696
|
): Promise<AgentToolResult<TextBatchDetails>> {
|
|
569
|
-
const cause = error;
|
|
570
697
|
const failure = isTextResourceEditFailure(error)
|
|
571
698
|
? error
|
|
572
699
|
: {
|
|
573
700
|
code: "INVALID_REQUEST" as const,
|
|
574
701
|
source: "",
|
|
575
|
-
message: errorMessage(
|
|
576
|
-
cause,
|
|
702
|
+
message: errorMessage(error),
|
|
703
|
+
cause: error,
|
|
577
704
|
};
|
|
705
|
+
const cause = Object.assign(new Error(failure.message), { code: failure.code });
|
|
578
706
|
const failedCallId = callIds[0];
|
|
579
707
|
const failedResult = await buildFailedTextMutationResult(core, failure, context);
|
|
580
|
-
|
|
708
|
+
const results: FileMutationResult[] = [];
|
|
709
|
+
const callIdsByResult: string[] = [];
|
|
581
710
|
for (const callId of callIds) {
|
|
711
|
+
const copyResult = copyResults.get(callId);
|
|
712
|
+
const result = copyResult ?? (callId === failedCallId ? failedResult : undefined);
|
|
582
713
|
reporter.fail(callId, {
|
|
583
714
|
error: cause,
|
|
584
|
-
effect: "not-applied",
|
|
585
|
-
...(
|
|
715
|
+
effect: copyResult?.details.effect ?? failedResult.details.effect ?? "not-applied",
|
|
716
|
+
...(result !== undefined && { result }),
|
|
586
717
|
});
|
|
718
|
+
for (const item of result?.details.results ?? []) {
|
|
719
|
+
results.push(item);
|
|
720
|
+
callIdsByResult.push(callId);
|
|
721
|
+
}
|
|
587
722
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
results.map(() => failedCallId ?? ""),
|
|
593
|
-
);
|
|
723
|
+
const result = textBatchResult(results, callIdsByResult);
|
|
724
|
+
return copyResults.size === 0
|
|
725
|
+
? result
|
|
726
|
+
: { ...result, details: { ...result.details, copyResults } };
|
|
594
727
|
}
|
|
595
728
|
|
|
596
729
|
function isTextResourceEditFailure(value: unknown): value is TextResourceEditFailure {
|
|
@@ -28,6 +28,8 @@ export interface TextBatchDetails extends FileMutationBatchResult {
|
|
|
28
28
|
readonly displayResults?: readonly FileMutationResult[];
|
|
29
29
|
/** Original call id for each user-facing result. */
|
|
30
30
|
readonly callIdsByDisplayResult?: readonly string[];
|
|
31
|
+
/** Per-call Copy receipts retain destination authority and their own failure evidence. */
|
|
32
|
+
readonly copyResults?: ReadonlyMap<string, AgentToolResult<FileMutationBatchResult>>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
function resultPath(result: FileMutationResult): string | undefined {
|
|
@@ -54,6 +56,8 @@ export function splitTextBatchResult(
|
|
|
54
56
|
|
|
55
57
|
return new Map(
|
|
56
58
|
calls.map((call) => {
|
|
59
|
+
const copyResult = details?.copyResults?.get(call.id);
|
|
60
|
+
if (copyResult) return [call.id, copyResult];
|
|
57
61
|
const agentResults = coalesceResults(agentResultsByCall.get(call.id) ?? []);
|
|
58
62
|
const displayResults = coalesceResults(displayResultsByCall.get(call.id) ?? []);
|
|
59
63
|
return [
|
|
@@ -97,6 +97,7 @@ import type {
|
|
|
97
97
|
TextMutationPreviewRequest,
|
|
98
98
|
} from "#src/api/mutation-preview.js";
|
|
99
99
|
|
|
100
|
+
import type { BeforeDeleteEvent, DeleteGuardRegistration } from "#src/api/delete-guard.js";
|
|
100
101
|
type PluginStatus = "active" | "pending";
|
|
101
102
|
|
|
102
103
|
interface PluginLifecycle {
|
|
@@ -215,6 +216,7 @@ interface PluginContributionDraft {
|
|
|
215
216
|
readonly mutationToolListeners?: TextMutationToolListener[];
|
|
216
217
|
readonly editCompletionListeners?: TextEditCompletionListener[];
|
|
217
218
|
readonly mutationGuards?: TextMutationGuardRegistration[];
|
|
219
|
+
readonly deleteGuards?: DeleteGuardRegistration[];
|
|
218
220
|
readonly toolRenderers?: TextEditorToolRendererRegistration[];
|
|
219
221
|
}
|
|
220
222
|
|
|
@@ -260,6 +262,13 @@ export interface TextResourceEditFailure {
|
|
|
260
262
|
readonly resolverId?: string;
|
|
261
263
|
readonly message: string;
|
|
262
264
|
readonly cause?: unknown;
|
|
265
|
+
/** Failed restoration and prior absence prevent a confirmed unchanged-resource claim. */
|
|
266
|
+
readonly rollback?: {
|
|
267
|
+
readonly failed: readonly string[];
|
|
268
|
+
readonly originallyMissing: readonly string[];
|
|
269
|
+
/** Existing resources whose restoration write succeeded. */
|
|
270
|
+
readonly restored: readonly string[];
|
|
271
|
+
};
|
|
263
272
|
}
|
|
264
273
|
|
|
265
274
|
export type TextResourceEditOutcome<Result> =
|
|
@@ -329,6 +338,8 @@ export interface TextResourcesEditContext
|
|
|
329
338
|
extends ResourceResolverContext, TextMutationGuardContext {}
|
|
330
339
|
|
|
331
340
|
export interface TextEditorCore {
|
|
341
|
+
/** Run whole-object deletion policies in registration order; denial and errors block removal. */
|
|
342
|
+
beforeDelete(event: BeforeDeleteEvent): Promise<void>;
|
|
332
343
|
/** Finalize a surviving local text file after a whole-file operation; binary files are untouched. */
|
|
333
344
|
postProcessFile(source: string, context: ResourceResolverContext): Promise<void>;
|
|
334
345
|
/** Reserve complete file sets. Only an explicit transaction owner may enqueue covered nested edits. */
|
|
@@ -421,6 +432,7 @@ export function createTextEditorCore(
|
|
|
421
432
|
const mutationListeners = new Set<TextMutationToolListener>();
|
|
422
433
|
const editCompletionListeners = new Set<TextEditCompletionListener>();
|
|
423
434
|
const mutationGuards: TextMutationGuardRegistration[] = [];
|
|
435
|
+
const deleteGuards: DeleteGuardRegistration[] = [];
|
|
424
436
|
const toolRenderers = new Map<TextEditorToolId, TextEditorToolRendererRegistration>();
|
|
425
437
|
let registrationQueue = Promise.resolve();
|
|
426
438
|
const scheduler = resourceScheduler;
|
|
@@ -494,6 +506,7 @@ export function createTextEditorCore(
|
|
|
494
506
|
handlers.push(...draft.handlers);
|
|
495
507
|
semanticHandlers.push(...(draft.semanticHandlers ?? []));
|
|
496
508
|
mutationGuards.push(...(draft.mutationGuards ?? []));
|
|
509
|
+
deleteGuards.push(...(draft.deleteGuards ?? []));
|
|
497
510
|
promptContributions.push(...draft.promptContributions);
|
|
498
511
|
writablePromptContributions.push(...draft.writablePromptContributions);
|
|
499
512
|
|
|
@@ -528,6 +541,22 @@ export function createTextEditorCore(
|
|
|
528
541
|
};
|
|
529
542
|
|
|
530
543
|
const core: TextEditorCore = {
|
|
544
|
+
async beforeDelete(event) {
|
|
545
|
+
for (const registration of [...deleteGuards]) {
|
|
546
|
+
event.signal?.throwIfAborted();
|
|
547
|
+
try {
|
|
548
|
+
const decision = await registration.guard(event);
|
|
549
|
+
if (decision.decision !== "allow") throw new Error(decision.reason);
|
|
550
|
+
} catch (error) {
|
|
551
|
+
throw Object.assign(
|
|
552
|
+
new Error(
|
|
553
|
+
`Delete blocked by hook ${registration.id}: ${error instanceof Error ? error.message : String(error)}`,
|
|
554
|
+
),
|
|
555
|
+
{ code: "DELETE_HOOK_REJECTED" },
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
},
|
|
531
560
|
async postProcessFile(source, context) {
|
|
532
561
|
await enqueueMutation(
|
|
533
562
|
async () => {
|
|
@@ -932,6 +961,10 @@ export function createTextEditorCore(
|
|
|
932
961
|
return core;
|
|
933
962
|
}
|
|
934
963
|
|
|
964
|
+
function readFailureMessage(source: string, error: unknown): string {
|
|
965
|
+
return `Unable to read ${source}: ${error instanceof Error ? error.message : String(error)}`;
|
|
966
|
+
}
|
|
967
|
+
|
|
935
968
|
async function inspectTextResource(
|
|
936
969
|
request: TextAnchorInspectionRequest,
|
|
937
970
|
resolvers: readonly RegisteredResolver[],
|
|
@@ -980,7 +1013,7 @@ async function inspectTextResource(
|
|
|
980
1013
|
try {
|
|
981
1014
|
content = await resource.read(request.signal === undefined ? {} : { signal: request.signal });
|
|
982
1015
|
} catch (error) {
|
|
983
|
-
return { kind: "failed", reason:
|
|
1016
|
+
return { kind: "failed", reason: readFailureMessage(resource.source, error), cause: error };
|
|
984
1017
|
}
|
|
985
1018
|
|
|
986
1019
|
if (!isAgentContent(content) || content.length !== 1 || content[0].type !== "text") {
|
|
@@ -1316,45 +1349,68 @@ async function editTextResources<Result>(
|
|
|
1316
1349
|
rollbackFailures.push(writtenSource);
|
|
1317
1350
|
}
|
|
1318
1351
|
}
|
|
1352
|
+
const cause: unknown = failure.status === "rejected" ? failure.reason : undefined;
|
|
1353
|
+
const originallyMissing = written.filter(
|
|
1354
|
+
(writtenSource) => !requiredValue(prepared.get(writtenSource)).existed,
|
|
1355
|
+
);
|
|
1319
1356
|
return {
|
|
1320
1357
|
kind: "failed",
|
|
1321
1358
|
failure: {
|
|
1322
1359
|
code: "WRITE_FAILED",
|
|
1323
1360
|
source,
|
|
1324
1361
|
resolverId: item.resolverId,
|
|
1325
|
-
message:
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1362
|
+
message: `Unable to write ${source}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1363
|
+
cause,
|
|
1364
|
+
rollback: {
|
|
1365
|
+
failed: rollbackFailures,
|
|
1366
|
+
originallyMissing,
|
|
1367
|
+
restored: written.filter(
|
|
1368
|
+
(source) => !rollbackFailures.includes(source) && !originallyMissing.includes(source),
|
|
1369
|
+
),
|
|
1370
|
+
},
|
|
1330
1371
|
},
|
|
1331
|
-
completed:
|
|
1372
|
+
completed: [],
|
|
1332
1373
|
};
|
|
1333
1374
|
}
|
|
1334
1375
|
const outcomes: Exclude<TextResourceEditOutcome<unknown>, { readonly kind: "failed" }>[] = [];
|
|
1335
1376
|
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1377
|
+
let finalizingSource = written[0] ?? sources[0] ?? "";
|
|
1378
|
+
try {
|
|
1379
|
+
await collectPostEditNotifications(async () => {
|
|
1380
|
+
for (const source of written) {
|
|
1381
|
+
finalizingSource = source;
|
|
1382
|
+
const text = requiredValue(applied.get(source)).content;
|
|
1383
|
+
const item = requiredValue(prepared.get(source));
|
|
1384
|
+
outcomes.push(
|
|
1385
|
+
await finalizeTextResource({
|
|
1386
|
+
requestedSource: item.requestedSource,
|
|
1387
|
+
outcomeSource: item.requestedSource,
|
|
1388
|
+
resource: item.resource,
|
|
1389
|
+
resolvedBy: item.resolverId,
|
|
1390
|
+
existed: item.existed,
|
|
1391
|
+
before: item.before,
|
|
1392
|
+
requestedText: text,
|
|
1393
|
+
context,
|
|
1394
|
+
presenters,
|
|
1395
|
+
postEditHandlers,
|
|
1396
|
+
editCompletionListeners,
|
|
1397
|
+
result: mutation.result,
|
|
1398
|
+
}),
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
});
|
|
1402
|
+
} catch (error) {
|
|
1403
|
+
return {
|
|
1404
|
+
kind: "failed",
|
|
1405
|
+
failure: {
|
|
1406
|
+
code: "POST_WRITE_FAILED",
|
|
1407
|
+
source: finalizingSource,
|
|
1408
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1409
|
+
cause: error,
|
|
1410
|
+
},
|
|
1411
|
+
completed: written,
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1358
1414
|
return { kind: "completed", resources: outcomes, result: mutation.result };
|
|
1359
1415
|
}
|
|
1360
1416
|
|
|
@@ -1442,7 +1498,7 @@ async function prepareTextResource(
|
|
|
1442
1498
|
code: "READ_FAILED",
|
|
1443
1499
|
source: attempt.resource.source,
|
|
1444
1500
|
resolverId: resolver.id,
|
|
1445
|
-
message:
|
|
1501
|
+
message: readFailureMessage(attempt.resource.source, error),
|
|
1446
1502
|
cause: error,
|
|
1447
1503
|
},
|
|
1448
1504
|
};
|
|
@@ -1561,6 +1617,18 @@ async function finalizeTextResource<Result>(
|
|
|
1561
1617
|
}
|
|
1562
1618
|
}
|
|
1563
1619
|
|
|
1620
|
+
if (!skipPostEdit && !deferred && request.context.signal?.aborted)
|
|
1621
|
+
postEditContributions.push({
|
|
1622
|
+
id: "post-edit-interruption",
|
|
1623
|
+
data: {
|
|
1624
|
+
diffStatuses: [
|
|
1625
|
+
{
|
|
1626
|
+
text: "Post-edit processing was interrupted. Read the saved file before retrying.",
|
|
1627
|
+
tone: "warning",
|
|
1628
|
+
},
|
|
1629
|
+
],
|
|
1630
|
+
},
|
|
1631
|
+
});
|
|
1564
1632
|
let finalText = request.requestedText;
|
|
1565
1633
|
|
|
1566
1634
|
if (!skipPostEdit && request.resource.read !== undefined) {
|
|
@@ -1587,7 +1655,13 @@ async function finalizeTextResource<Result>(
|
|
|
1587
1655
|
before: request.postProcessingFinal ? requestedAfter : request.before,
|
|
1588
1656
|
after: finalAfter,
|
|
1589
1657
|
intent: request.context.intent ?? "edit",
|
|
1590
|
-
postProcessing: deferred
|
|
1658
|
+
postProcessing: deferred
|
|
1659
|
+
? "deferred"
|
|
1660
|
+
: request.context.signal?.aborted
|
|
1661
|
+
? "interrupted"
|
|
1662
|
+
: request.postProcessingFinal
|
|
1663
|
+
? "final"
|
|
1664
|
+
: "complete",
|
|
1591
1665
|
};
|
|
1592
1666
|
|
|
1593
1667
|
for (const listener of request.editCompletionListeners) {
|
|
@@ -1734,7 +1808,7 @@ async function editTextResource<Result>(
|
|
|
1734
1808
|
code: "READ_FAILED",
|
|
1735
1809
|
source: resource.source,
|
|
1736
1810
|
resolverId: resolver.id,
|
|
1737
|
-
message:
|
|
1811
|
+
message: readFailureMessage(resource.source, error),
|
|
1738
1812
|
cause: error,
|
|
1739
1813
|
},
|
|
1740
1814
|
};
|
|
@@ -1951,6 +2025,7 @@ function createPluginContributionController(
|
|
|
1951
2025
|
mutationToolListeners: [],
|
|
1952
2026
|
editCompletionListeners: [],
|
|
1953
2027
|
mutationGuards: [],
|
|
2028
|
+
deleteGuards: [],
|
|
1954
2029
|
toolRenderers: [],
|
|
1955
2030
|
};
|
|
1956
2031
|
let state: "active" | "closed" | "setup" = "setup";
|
|
@@ -2074,6 +2149,25 @@ function createPluginContributionController(
|
|
|
2074
2149
|
toolRenderers: [registration],
|
|
2075
2150
|
});
|
|
2076
2151
|
},
|
|
2152
|
+
addDeleteGuard(registration): void {
|
|
2153
|
+
assertAvailable();
|
|
2154
|
+
if (registration.id.trim().length === 0 || typeof registration.guard !== "function") {
|
|
2155
|
+
throw new TypeError(`Plugin ${pluginId} provided an invalid delete guard`);
|
|
2156
|
+
}
|
|
2157
|
+
if (state === "setup") {
|
|
2158
|
+
requiredValue(setupDraft.deleteGuards).push(registration);
|
|
2159
|
+
return;
|
|
2160
|
+
}
|
|
2161
|
+
registerContributions({
|
|
2162
|
+
resolvers: [],
|
|
2163
|
+
anchorResolvers: [],
|
|
2164
|
+
handlers: [],
|
|
2165
|
+
promptContributions: [],
|
|
2166
|
+
writablePromptContributions: [],
|
|
2167
|
+
tools: [],
|
|
2168
|
+
deleteGuards: [registration],
|
|
2169
|
+
});
|
|
2170
|
+
},
|
|
2077
2171
|
addMutationGuard(registration): void {
|
|
2078
2172
|
assertAvailable();
|
|
2079
2173
|
|