pi-agent-ide 0.7.0 → 0.7.2
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 +44 -0
- package/dist/chunk-6U5OU77O.js +3 -0
- package/dist/{chunk-6CZO43OH.js → chunk-BU7IZLKB.js} +1 -1
- package/dist/chunk-EURHXLN3.js +2 -0
- package/dist/{chunk-PYPPV2F5.js → chunk-F6IWZKOG.js} +6 -6
- package/dist/{chunk-GBLKIB6O.js → chunk-H445SHSJ.js} +2 -2
- 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-YRF7OATP.js → chunk-KOVPDKSJ.js} +1 -1
- package/dist/chunk-MXLSGMRZ.js +3 -0
- package/dist/chunk-NRZO5KJT.js +9 -0
- package/dist/chunk-OB46OPMZ.js +1 -0
- package/dist/chunk-PKSQT6TC.js +1 -0
- package/dist/{chunk-PNU3E7IO.js → chunk-Q6CZ6GBR.js} +2 -2
- package/dist/{chunk-EDURPQAV.js → chunk-QRJLIV6P.js} +6 -6
- package/dist/chunk-QUYXINGZ.js +7 -0
- package/dist/{chunk-OBNING2A.js → chunk-S5PL5DFQ.js} +1 -1
- package/dist/chunk-SBP3ABH4.js +5 -0
- package/dist/{chunk-FXNKMNSJ.js → chunk-SJ4UZ4GU.js} +1 -1
- package/dist/chunk-SNF7PDDX.js +11 -0
- package/dist/{chunk-AJRIASPQ.js → chunk-STBJO3Z3.js} +1 -1
- package/dist/{chunk-3HYXQ4YA.js → chunk-TQGE7RH6.js} +13 -13
- package/dist/{chunk-S5LXX32D.js → chunk-XDG7EQRN.js} +3 -3
- package/dist/{chunk-F5YZG77W.js → chunk-XH5WN5XA.js} +1 -1
- package/dist/chunk-YWQS33DF.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 +2 -2
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +2 -2
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-31.js +15 -13
- package/dist/entry-33.js +2 -1
- package/dist/entry-37.js +6 -6
- 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 +20 -13
- 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 +8 -7
- 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-57.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 +51 -43
- package/dist/entry-78.js +14 -14
- package/dist/entry-79.js +1 -1
- package/dist/entry-80.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 +37 -9
- package/docs/agent-guides/editing.md +35 -46
- package/docs/agent-guides/git-changes.md +10 -0
- package/docs/agent-guides/read-resources.md +9 -50
- package/docs/agent-guides/search-code.md +18 -17
- package/docs/agent-guides/select-code.md +62 -140
- package/docs/agent-guides/terminal.md +9 -1
- package/docs/configuration.md +1 -1
- package/docs/releases.md +4 -0
- package/docs/research/native-codemode-batch-decision.md +2 -0
- package/docs/structured-results.md +27 -62
- package/docs/tools.md +15 -11
- 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/index.ts +7 -6
- 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/index.ts +4 -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 +5 -4
- package/node_modules/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +35 -9
- package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +1 -1
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +10 -8
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +28 -3
- package/node_modules/pi-agent-ide-changes/index.ts +4 -3
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +66 -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 +3 -3
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +5 -2
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +7 -7
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +38 -1
- package/node_modules/pi-agent-read/src/api/tools/read.ts +18 -1
- package/node_modules/pi-agent-read/src/core/extension.ts +8 -2
- package/node_modules/pi-agent-read/src/core/read-core.ts +54 -35
- 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/read/structured-result.ts +3 -3
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +108 -46
- 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 +186 -9
- 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-resource/src/tool-result.ts +13 -1
- 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 +3 -3
- 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/index.ts +1 -1
- 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/index.ts +65 -4
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/src/anchor.ts +12 -2
- package/node_modules/pi-agent-text-anchor-line-hash/index.ts +4 -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/edit-completion.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/api/mutation-result.ts +2 -1
- 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/stale-anchor-message.ts +1 -1
- 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/extension.ts +10 -3
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +3 -13
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +35 -6
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -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 +232 -144
- 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 +7 -2
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +49 -214
- 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 +152 -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 +76 -32
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +409 -209
- package/node_modules/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -9
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +10 -3
- 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 +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +3 -4
- 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 +54 -5
- 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-call-interception/src/index.ts +3 -0
- package/node_modules/pi-agent-tool-ui/package.json +1 -1
- package/node_modules/pi-agent-web/index.ts +4 -3
- 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 +35 -35
- package/src/composite/nested-tool-rendering.ts +64 -6
- package/src/composite/output-limits.ts +125 -0
- package/src/composite/responses-tools.ts +25 -0
- package/src/composite/text-results.ts +372 -0
- package/src/documentation/extension.ts +11 -9
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/index.ts +7 -6
- 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/index.ts +4 -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/index.ts +4 -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/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +38 -1
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +18 -1
- package/src/extensions/pi-agent-read/src/core/extension.ts +8 -2
- package/src/extensions/pi-agent-read/src/core/read-core.ts +54 -35
- 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/read/structured-result.ts +3 -3
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +108 -46
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
- 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 +3 -3
- 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/index.ts +65 -4
- 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-exact/src/anchor.ts +12 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/index.ts +4 -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 +54 -5
- 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/edit-completion.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/api/mutation-result.ts +2 -1
- 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/stale-anchor-message.ts +1 -1
- 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/extension.ts +10 -3
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +3 -13
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts +35 -6
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +19 -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 +232 -144
- 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 +7 -2
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +49 -214
- 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 +152 -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 +76 -32
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +409 -209
- package/src/extensions/pi-agent-text-editor/src/core/tool-call-interceptor/coordinator.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +6 -9
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +10 -3
- 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 +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +3 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +10 -4
- package/src/pi-agent-ide.ts +15 -1
- package/src/plugins/pi-agent-ide-ast/package.json +13 -13
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +5 -4
- package/src/plugins/pi-agent-ide-ast/src/overflow-handler.ts +2 -2
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +35 -9
- package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +1 -1
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +10 -8
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +28 -3
- package/src/plugins/pi-agent-ide-changes/index.ts +4 -3
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +66 -4
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +8 -11
- package/src/plugins/pi-agent-ide-debugger/index.ts +22 -10
- 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 +6 -3
- 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 +3 -3
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +5 -2
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +3 -3
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +8 -6
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +3 -3
- package/src/plugins/pi-agent-ide-vision/index.ts +13 -4
- package/src/post-edit/gate.ts +13 -2
- package/dist/chunk-3JO7QFIL.js +0 -1
- package/dist/chunk-4NIFBFFR.js +0 -11
- package/dist/chunk-64M3SQPG.js +0 -3
- package/dist/chunk-7LZKOHH2.js +0 -1
- package/dist/chunk-EAZGN5ND.js +0 -7
- package/dist/chunk-FK42RSF4.js +0 -1
- package/dist/chunk-KBP3QUDT.js +0 -2
- package/dist/chunk-KR36BT5E.js +0 -1
- package/dist/chunk-MBUXFKIW.js +0 -3
- package/dist/chunk-OE7QVAI2.js +0 -5
- package/dist/chunk-SILJ3OL4.js +0 -9
- package/dist/chunk-SQKAXYIR.js +0 -2
- package/dist/chunk-VCGNVTXQ.js +0 -1
- package/src/extensions/pi-agent-read/src/core/tools/read/temp-resource-store.ts +0 -105
|
@@ -51,7 +51,12 @@ import {
|
|
|
51
51
|
runNativePostEditScope,
|
|
52
52
|
recordNativeTextMutation,
|
|
53
53
|
} from "#src/core/native-text-edit-batch.js";
|
|
54
|
-
import {
|
|
54
|
+
import {
|
|
55
|
+
attachCommittedMutationTarget,
|
|
56
|
+
attachWriteTarget,
|
|
57
|
+
describeUnavailableCopyTarget,
|
|
58
|
+
unchangedCopySources,
|
|
59
|
+
} from "./mutation-result-targets.js";
|
|
55
60
|
import { wholeFileResultSource } from "./result-input.js";
|
|
56
61
|
import { TEXT_SEARCH_ANCHOR_KIND } from "#src/api/plugin-protocol.js";
|
|
57
62
|
import { isResultInput, prepareResultTransfer } from "./result-transfer.js";
|
|
@@ -84,7 +89,7 @@ import type { ToolCallAnchorRenderState } from "pi-agent-tool-call-interception"
|
|
|
84
89
|
import type { Static, TSchema } from "typebox";
|
|
85
90
|
import { executeWholeFileTool, isWholeFileInvocation } from "#src/core/file-operation-tools.js";
|
|
86
91
|
import { EDITING_GUIDELINES } from "#src/core/editing-guidelines.js";
|
|
87
|
-
import {
|
|
92
|
+
import { mutationResultSchema, structuredMutation } from "./structured-result.js";
|
|
88
93
|
import type { ResultTargetStore } from "pi-agent-resource";
|
|
89
94
|
|
|
90
95
|
export function createTextTool<TParameters extends TSchema>(
|
|
@@ -118,7 +123,7 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
118
123
|
promptGuidelines: [...EDITING_GUIDELINES, ...(definition.promptGuidelines ?? [])],
|
|
119
124
|
description: definition.description,
|
|
120
125
|
parameters: definition.parameters,
|
|
121
|
-
outputSchema:
|
|
126
|
+
outputSchema: mutationResultSchema(definition.name),
|
|
122
127
|
prepareArguments: (arguments_) =>
|
|
123
128
|
// oxlint-disable-next-line typescript/no-unsafe-return -- TypeBox resolves only concrete tool schemas.
|
|
124
129
|
prepareGuardedArguments(
|
|
@@ -142,170 +147,197 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
142
147
|
}),
|
|
143
148
|
async execute(toolCallId, parameters, signal, onUpdate, context) {
|
|
144
149
|
let plannedEdits: ReadonlyMap<string, TextMutationEdit> | undefined;
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
150
|
+
const copyPlan = { snapshots: new Map<string, string>(), unchanged: false };
|
|
151
|
+
const captured = await runNativePostEditScope(
|
|
152
|
+
core,
|
|
153
|
+
toolCallId,
|
|
154
|
+
() =>
|
|
155
|
+
captureScriptMutation(core, async () => {
|
|
156
|
+
const execute = async (): Promise<AgentToolResult<FileMutationBatchResult>> => {
|
|
157
|
+
let input = asMutationParameters<TParameters>(parameters);
|
|
158
|
+
if (
|
|
159
|
+
["replace", "write", "delete", "undo", "insert"].includes(definition.name) &&
|
|
160
|
+
isResultInput(input[definition.source.field])
|
|
161
|
+
) {
|
|
162
|
+
try {
|
|
163
|
+
if (resultTargets === undefined)
|
|
164
|
+
throw new Error("Result targets are unavailable.");
|
|
165
|
+
if (input.start !== undefined || input.end !== undefined)
|
|
166
|
+
throw new Error("Do not combine result targets with start/end.");
|
|
167
|
+
const selected = resultTargets.resolve(
|
|
168
|
+
input[definition.source.field],
|
|
169
|
+
context.cwd,
|
|
165
170
|
);
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
171
|
+
if (!selected.complete)
|
|
172
|
+
throw new Error(
|
|
173
|
+
"Incomplete result targets cannot establish a complete edit. Run Search again with a higher limit or a narrower query, then use the complete result.",
|
|
174
|
+
);
|
|
175
|
+
await resultTargets.verify(selected, signal);
|
|
176
|
+
if (definition.name === "write" || definition.name === "undo")
|
|
177
|
+
wholeFileResultSource(selected, definition.name);
|
|
178
|
+
if (selected.targets.length === 0)
|
|
179
|
+
return {
|
|
180
|
+
content: [{ type: "text", text: "Empty result target set; no changes." }],
|
|
181
|
+
details: {
|
|
182
|
+
results: [],
|
|
183
|
+
effect: "not-applied",
|
|
184
|
+
metadata: { emptyTargets: true },
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
input = {
|
|
188
|
+
...input,
|
|
189
|
+
[definition.source.field]: resultTargets.register(
|
|
190
|
+
selected.targets,
|
|
191
|
+
context.cwd,
|
|
192
|
+
selected.complete,
|
|
193
|
+
),
|
|
177
194
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
} catch (error) {
|
|
196
|
+
signal?.throwIfAborted();
|
|
197
|
+
return failureToolResult(
|
|
198
|
+
"",
|
|
199
|
+
"RESULT_INPUT_REJECTED",
|
|
200
|
+
errorMessage(error),
|
|
201
|
+
"not-applied",
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
let executionDefinition = definition;
|
|
206
|
+
let verifyFileSource: (() => Promise<void>) | undefined;
|
|
207
|
+
if (
|
|
208
|
+
(definition.name === "copy" || definition.name === "move") &&
|
|
209
|
+
(isResultInput(input.path) || isResultInput(input.target))
|
|
210
|
+
) {
|
|
211
|
+
try {
|
|
212
|
+
if (resultTargets === undefined)
|
|
213
|
+
throw new Error("Result targets are unavailable.");
|
|
214
|
+
const prepared = await prepareResultTransfer(
|
|
215
|
+
definition.name,
|
|
216
|
+
input,
|
|
217
|
+
resultTargets,
|
|
182
218
|
context.cwd,
|
|
183
|
-
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
219
|
+
signal,
|
|
220
|
+
);
|
|
221
|
+
input = asMutationParameters<TParameters>(prepared.input);
|
|
222
|
+
verifyFileSource = prepared.verifyFileSource;
|
|
223
|
+
if (prepared.empty)
|
|
224
|
+
return {
|
|
225
|
+
content: [
|
|
226
|
+
{
|
|
227
|
+
type: "text",
|
|
228
|
+
text:
|
|
229
|
+
definition.name === "copy"
|
|
230
|
+
? "No changes: empty selection."
|
|
231
|
+
: "Empty result target set; no changes.",
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
details: {
|
|
235
|
+
results: [],
|
|
236
|
+
effect: "not-applied",
|
|
237
|
+
metadata: { emptyTargets: true },
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
if (prepared.mutate !== undefined)
|
|
241
|
+
executionDefinition = { ...definition, mutate: prepared.mutate };
|
|
242
|
+
} catch (error) {
|
|
243
|
+
signal?.throwIfAborted();
|
|
244
|
+
return failureToolResult(
|
|
245
|
+
"",
|
|
246
|
+
"RESULT_INPUT_REJECTED",
|
|
247
|
+
errorMessage(error),
|
|
248
|
+
"not-applied",
|
|
249
|
+
);
|
|
250
|
+
}
|
|
194
251
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
252
|
+
const directDefinition = executionDefinition;
|
|
253
|
+
executionDefinition = {
|
|
254
|
+
...directDefinition,
|
|
255
|
+
mutate: async (mutationContext, arguments_) => {
|
|
256
|
+
const mutation = await directDefinition.mutate(mutationContext, arguments_);
|
|
257
|
+
plannedEdits = mutation.edits;
|
|
258
|
+
if (definition.name === "copy") {
|
|
259
|
+
for (const source of mutation.edits.keys())
|
|
260
|
+
copyPlan.snapshots.set(source, mutationContext.documentFor(source).content);
|
|
261
|
+
copyPlan.unchanged =
|
|
262
|
+
mutation.edits.size > 0 &&
|
|
263
|
+
unchangedCopySources(mutation, copyPlan.snapshots).size ===
|
|
264
|
+
mutation.edits.size;
|
|
265
|
+
}
|
|
266
|
+
return mutation;
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
const queued = executeNativeTextEditBatch(
|
|
270
|
+
core,
|
|
271
|
+
toolCallId,
|
|
272
|
+
definition,
|
|
273
|
+
input,
|
|
274
|
+
signal,
|
|
275
|
+
context,
|
|
276
|
+
);
|
|
277
|
+
if (queued !== undefined) return queued;
|
|
278
|
+
if (definition.direct?.matches(input) === true) {
|
|
279
|
+
try {
|
|
280
|
+
const action = await definition.direct.execute(
|
|
281
|
+
{ cwd: context.cwd, ...(signal !== undefined && { signal }) },
|
|
282
|
+
input,
|
|
283
|
+
);
|
|
215
284
|
return {
|
|
216
|
-
content: [{ type: "text", text:
|
|
285
|
+
content: [{ type: "text", text: action.summary }],
|
|
217
286
|
details: {
|
|
218
287
|
results: [],
|
|
219
|
-
|
|
220
|
-
metadata: { emptyTargets: true },
|
|
288
|
+
metadata: { semanticAction: { ...action.data, source: action.source } },
|
|
221
289
|
},
|
|
222
290
|
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
291
|
+
} catch (error) {
|
|
292
|
+
const code =
|
|
293
|
+
error !== null && typeof error === "object" && "code" in error
|
|
294
|
+
? String(error.code)
|
|
295
|
+
: "DIRECT_MUTATION_FAILED";
|
|
296
|
+
return failureToolResult(
|
|
297
|
+
"transaction" in input ? String(input.transaction) : "",
|
|
298
|
+
code,
|
|
299
|
+
error instanceof Error ? error.message : String(error),
|
|
300
|
+
"unknown",
|
|
301
|
+
);
|
|
302
|
+
}
|
|
233
303
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return mutation;
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
const queued = executeNativeTextEditBatch(
|
|
245
|
-
core,
|
|
246
|
-
toolCallId,
|
|
247
|
-
definition,
|
|
248
|
-
input,
|
|
249
|
-
signal,
|
|
250
|
-
context,
|
|
251
|
-
);
|
|
252
|
-
if (queued !== undefined) return queued;
|
|
253
|
-
if (definition.direct?.matches(input) === true) {
|
|
254
|
-
try {
|
|
255
|
-
const action = await definition.direct.execute(
|
|
256
|
-
{ cwd: context.cwd, ...(signal !== undefined && { signal }) },
|
|
304
|
+
if (
|
|
305
|
+
isWholeFileInvocation(definition.wholeFileOperation, input) &&
|
|
306
|
+
core.getSemanticMutationHandler(definition.name, input) === undefined
|
|
307
|
+
) {
|
|
308
|
+
return executeWholeFileTool(
|
|
309
|
+
core,
|
|
310
|
+
definition.wholeFileOperation,
|
|
257
311
|
input,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
details: {
|
|
262
|
-
results: [],
|
|
263
|
-
metadata: { semanticAction: { ...action.data, source: action.source } },
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
|
-
} catch (error) {
|
|
267
|
-
const code =
|
|
268
|
-
error !== null && typeof error === "object" && "code" in error
|
|
269
|
-
? String(error.code)
|
|
270
|
-
: "DIRECT_MUTATION_FAILED";
|
|
271
|
-
return failureToolResult(
|
|
272
|
-
"transaction" in input ? String(input.transaction) : "",
|
|
273
|
-
code,
|
|
274
|
-
error instanceof Error ? error.message : String(error),
|
|
275
|
-
"unknown",
|
|
312
|
+
signal,
|
|
313
|
+
context,
|
|
314
|
+
verifyFileSource,
|
|
276
315
|
);
|
|
277
316
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
core,
|
|
295
|
-
executionDefinition,
|
|
296
|
-
input,
|
|
317
|
+
const directExecute = () =>
|
|
318
|
+
executeTextMutation(
|
|
319
|
+
core,
|
|
320
|
+
executionDefinition,
|
|
321
|
+
input,
|
|
322
|
+
signal,
|
|
323
|
+
context,
|
|
324
|
+
(field, state) =>
|
|
325
|
+
annotations.resolveArguments(toolCallId, {
|
|
326
|
+
[TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
|
|
327
|
+
}),
|
|
328
|
+
getLastResolvedSource(),
|
|
329
|
+
);
|
|
330
|
+
return executeTextToolWithBatch(
|
|
331
|
+
toolCallId,
|
|
332
|
+
directExecute,
|
|
297
333
|
signal,
|
|
334
|
+
onUpdate,
|
|
298
335
|
context,
|
|
299
|
-
(field, state) =>
|
|
300
|
-
annotations.resolveArguments(toolCallId, {
|
|
301
|
-
[TOOL_CALL_INTERCEPTION_ANCHOR_RENDER_PATCH]: { [field]: state },
|
|
302
|
-
}),
|
|
303
|
-
getLastResolvedSource(),
|
|
304
336
|
);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
337
|
+
};
|
|
338
|
+
return execute();
|
|
339
|
+
}),
|
|
340
|
+
definition.name === "write",
|
|
309
341
|
);
|
|
310
342
|
if (captured.kind === "failed") {
|
|
311
343
|
const failed = failureToolResult(
|
|
@@ -313,26 +345,54 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
313
345
|
"EXECUTION_FAILED",
|
|
314
346
|
errorMessage(captured.error),
|
|
315
347
|
"unknown",
|
|
348
|
+
undefined,
|
|
349
|
+
definition.name === "copy",
|
|
316
350
|
);
|
|
317
351
|
return structuredMutation(failed, definition.name, captured.completions, toolCallId);
|
|
318
352
|
}
|
|
319
|
-
|
|
353
|
+
const completedValue =
|
|
354
|
+
copyPlan.unchanged && captured.completions.length === 0 && !captured.value.isError
|
|
355
|
+
? {
|
|
356
|
+
...captured.value,
|
|
357
|
+
content: [
|
|
358
|
+
{ type: "text" as const, text: "No changes: destination already has this text." },
|
|
359
|
+
],
|
|
360
|
+
details: { ...captured.value.details, effect: "not-applied" as const },
|
|
361
|
+
}
|
|
362
|
+
: captured.value;
|
|
363
|
+
// Live-resource actions have their own receipts, not filesystem editor batches.
|
|
364
|
+
if (captured.completions.every((completion) => completion.resolvedBy === "filesystem"))
|
|
365
|
+
recordNativeTextMutation(core, toolCallId, completedValue);
|
|
320
366
|
const value =
|
|
321
367
|
resultTargets &&
|
|
322
368
|
["replace", "insert", "write", "copy", "move", "undo"].includes(definition.name)
|
|
323
|
-
?
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
369
|
+
? definition.name === "write"
|
|
370
|
+
? await attachWriteTarget(
|
|
371
|
+
completedValue,
|
|
372
|
+
captured.completions,
|
|
373
|
+
resultTargets,
|
|
374
|
+
context.cwd,
|
|
375
|
+
signal,
|
|
376
|
+
)
|
|
377
|
+
: await attachCommittedMutationTarget(
|
|
378
|
+
completedValue,
|
|
379
|
+
captured.completions,
|
|
380
|
+
resultTargets,
|
|
381
|
+
toolCallId,
|
|
382
|
+
context.cwd,
|
|
383
|
+
signal,
|
|
384
|
+
definition.name === "undo",
|
|
385
|
+
plannedEdits,
|
|
386
|
+
definition.name === "copy" || definition.name === "move",
|
|
387
|
+
copyPlan.snapshots,
|
|
388
|
+
)
|
|
389
|
+
: completedValue;
|
|
390
|
+
return structuredMutation(
|
|
391
|
+
definition.name === "copy" ? describeUnavailableCopyTarget(value) : value,
|
|
392
|
+
definition.name,
|
|
393
|
+
captured.completions,
|
|
394
|
+
toolCallId,
|
|
395
|
+
);
|
|
336
396
|
},
|
|
337
397
|
}),
|
|
338
398
|
annotations,
|
|
@@ -342,27 +402,32 @@ export function createTextTool<TParameters extends TSchema>(
|
|
|
342
402
|
get(): string {
|
|
343
403
|
return [
|
|
344
404
|
definition.description,
|
|
345
|
-
definition.
|
|
346
|
-
? "In native Codemode, local text edits share original snapshots and return acceptance before writing. Another tool, whole-file operation, or resource-owned selector commits the batch first; script completion also commits it. Formatting and registered resource post-edit handlers run at script end, not at flush or dependency boundaries. Earlier targets become stale if final processing changes bytes. Ordinary script errors keep accepted edits; aborts and deadlines discard pending edits."
|
|
347
|
-
: "",
|
|
405
|
+
core.renderToolPromptGuideline(definition.name) ?? "",
|
|
348
406
|
(
|
|
349
407
|
{
|
|
350
408
|
replace:
|
|
351
|
-
"
|
|
409
|
+
"This result selects the resulting text; empty replacement selects the resulting position, not the removed text.",
|
|
352
410
|
insert:
|
|
353
|
-
"
|
|
354
|
-
write:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
undo: "
|
|
411
|
+
"For text edits, this result selects the inserted text, including supplied line separators. Specialized resources return their own action result.",
|
|
412
|
+
write:
|
|
413
|
+
"For file writes, this result selects the whole file, not only its changed span.",
|
|
414
|
+
copy: "This result selects only the copied destination text; a whole-file copy selects the whole destination. Copy edits only the destination.",
|
|
415
|
+
move: "Use the Move result to work with the inserted destination text, including any added line separators. Source removals are not selected. A whole-file move selects the whole destination when a reusable text result is available.",
|
|
416
|
+
delete: "Delete returns no reusable text selection.",
|
|
417
|
+
undo: "The result selects the whole restored text file, not only the reversed span.",
|
|
360
418
|
} as Record<string, string>
|
|
361
419
|
)[definition.name] ?? "",
|
|
362
|
-
|
|
363
|
-
? "
|
|
364
|
-
: ""
|
|
365
|
-
|
|
420
|
+
definition.name === "replace"
|
|
421
|
+
? "Pass the unchanged result to another source tool to use its selection. If it has no text selection, read the file again."
|
|
422
|
+
: definition.name === "write"
|
|
423
|
+
? "For file writes, pass this unchanged result to another source tool for dependent work. If the result reports no verified text selection, inspect the file instead."
|
|
424
|
+
: definition.name === "undo"
|
|
425
|
+
? "Pass the unchanged result to another source tool for dependent work. If no verified text selection is returned, read the file again."
|
|
426
|
+
: ["insert", "copy", "move"].includes(definition.name)
|
|
427
|
+
? "Pass this unchanged result to another source tool for dependent work." +
|
|
428
|
+
" If the result reports no verified text selection, inspect the file instead."
|
|
429
|
+
: "",
|
|
430
|
+
definition.source.inherited && !["delete", "undo"].includes(definition.name)
|
|
366
431
|
? definition.wholeFileOperation === undefined
|
|
367
432
|
? `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.`
|
|
368
433
|
: `When ${definition.source.field} is omitted, the tool can reuse the file identified by a supplied text anchor.`
|
|
@@ -705,6 +770,7 @@ interface MutationExecutionContext extends TextMutationContext {
|
|
|
705
770
|
|
|
706
771
|
interface ExecutedTextMutation extends TextMutation {
|
|
707
772
|
readonly resultPresentations: ReadonlyMap<string, MutationResultPresentation>;
|
|
773
|
+
readonly unchangedWrite?: { readonly source: string; readonly content: string };
|
|
708
774
|
}
|
|
709
775
|
|
|
710
776
|
function createMutationContext(
|
|
@@ -1137,7 +1203,15 @@ export async function executeTextMutationPipeline<TParameters extends TSchema>(
|
|
|
1137
1203
|
);
|
|
1138
1204
|
await preflightMutationAnchors(definition, state.input, mutationContext);
|
|
1139
1205
|
const mutation = await definition.mutate(mutationContext, state.input);
|
|
1140
|
-
const executedMutation =
|
|
1206
|
+
const executedMutation: ExecutedTextMutation = {
|
|
1207
|
+
...withResultPresentations(mutation, mutationContext),
|
|
1208
|
+
...(definition.name === "write" && {
|
|
1209
|
+
unchangedWrite: {
|
|
1210
|
+
source: mutationContext.sourceFor("path"),
|
|
1211
|
+
content: mutationContext.sourceDocument.content,
|
|
1212
|
+
},
|
|
1213
|
+
}),
|
|
1214
|
+
};
|
|
1141
1215
|
return {
|
|
1142
1216
|
changes: new Map(
|
|
1143
1217
|
[...mutation.edits].map(([editSource, edit]) => [editSource, edit.changes]),
|
|
@@ -1211,6 +1285,21 @@ type CompletedTextResource = Extract<
|
|
|
1211
1285
|
{ readonly kind: "completed" }
|
|
1212
1286
|
>;
|
|
1213
1287
|
|
|
1288
|
+
/** Count real Copy changes without counting retained identical destination ranges. */
|
|
1289
|
+
export function textMutationOperationReceipts(
|
|
1290
|
+
operation: string,
|
|
1291
|
+
edit: TextMutationEdit,
|
|
1292
|
+
before: string,
|
|
1293
|
+
): readonly MutationOperationReceipt[] {
|
|
1294
|
+
const changes =
|
|
1295
|
+
operation === "copy"
|
|
1296
|
+
? edit.changes.filter(
|
|
1297
|
+
(change) =>
|
|
1298
|
+
!change.allowUnchanged || before.slice(change.from, change.to) !== change.insert,
|
|
1299
|
+
).length
|
|
1300
|
+
: edit.changes.length;
|
|
1301
|
+
return operation === "copy" && changes === 0 ? [] : [{ operation, changes }];
|
|
1302
|
+
}
|
|
1214
1303
|
/** Builds a mutation receipt; peer ranges are supplied only for per-call batch display results. */
|
|
1215
1304
|
export function buildSuccessfulTextMutationResult(
|
|
1216
1305
|
resource: CompletedTextResource,
|
|
@@ -1310,7 +1399,7 @@ async function buildToolResult(
|
|
|
1310
1399
|
source,
|
|
1311
1400
|
pipeline.failure.code,
|
|
1312
1401
|
pipeline.failure.message,
|
|
1313
|
-
"not-applied",
|
|
1402
|
+
pipeline.failure.stage === "text-pre-edit" ? "not-applied" : "unknown",
|
|
1314
1403
|
);
|
|
1315
1404
|
}
|
|
1316
1405
|
|
|
@@ -1332,11 +1421,19 @@ async function buildToolResult(
|
|
|
1332
1421
|
return recovery;
|
|
1333
1422
|
}
|
|
1334
1423
|
|
|
1424
|
+
if (operation === "copy" && outcome.failure.code === "WRITE_FAILED") {
|
|
1425
|
+
return buildFailedCopyWriteResult(outcome.failure, outcome.completed);
|
|
1426
|
+
}
|
|
1335
1427
|
const completed =
|
|
1336
1428
|
outcome.completed.length === 0 ? "" : ` Completed writes: ${outcome.completed.join(", ")}.`;
|
|
1337
|
-
const effect =
|
|
1429
|
+
const effect =
|
|
1430
|
+
outcome.completed.length > 0
|
|
1431
|
+
? "applied"
|
|
1432
|
+
: outcome.failure.code === "POST_WRITE_FAILED"
|
|
1433
|
+
? "unknown"
|
|
1434
|
+
: "not-applied";
|
|
1338
1435
|
const message = `${outcome.failure.message.replace(/[.!?]+$/u, "")}.${completed}`;
|
|
1339
|
-
return
|
|
1436
|
+
return buildFailedTextMutationResult(core, { ...outcome.failure, message }, context, effect);
|
|
1340
1437
|
}
|
|
1341
1438
|
|
|
1342
1439
|
const mutation = outcome.result as ExecutedTextMutation;
|
|
@@ -1354,6 +1451,28 @@ async function buildToolResult(
|
|
|
1354
1451
|
},
|
|
1355
1452
|
};
|
|
1356
1453
|
}
|
|
1454
|
+
if (operation === "write" && outcome.resources.length === 0 && mutation.unchangedWrite) {
|
|
1455
|
+
const { source: unchangedSource, content } = mutation.unchangedWrite;
|
|
1456
|
+
return {
|
|
1457
|
+
content: [
|
|
1458
|
+
{
|
|
1459
|
+
type: "text",
|
|
1460
|
+
text: `File already matches the supplied content. Nothing was written.\nPost-edit processing was skipped.\n\n${unchangedSource}`,
|
|
1461
|
+
},
|
|
1462
|
+
],
|
|
1463
|
+
details: {
|
|
1464
|
+
effect: "not-applied",
|
|
1465
|
+
results: [
|
|
1466
|
+
new FileMutationResult({
|
|
1467
|
+
ok: true,
|
|
1468
|
+
path: unchangedSource,
|
|
1469
|
+
afterContent: content,
|
|
1470
|
+
rawChanges: [],
|
|
1471
|
+
}),
|
|
1472
|
+
],
|
|
1473
|
+
},
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1357
1476
|
const results = outcome.resources.flatMap((resource) => {
|
|
1358
1477
|
const resultSource = resource.source;
|
|
1359
1478
|
const edit = mutation.edits.get(resultSource);
|
|
@@ -1368,7 +1487,7 @@ async function buildToolResult(
|
|
|
1368
1487
|
mutation.resultPresentations.get(resultSource) ?? "plain",
|
|
1369
1488
|
|
|
1370
1489
|
1,
|
|
1371
|
-
|
|
1490
|
+
textMutationOperationReceipts(operation, edit, resource.before.content),
|
|
1372
1491
|
),
|
|
1373
1492
|
];
|
|
1374
1493
|
});
|
|
@@ -1406,12 +1525,18 @@ async function anchorFailureToolResult(
|
|
|
1406
1525
|
const results: FileMutationResult[] = [];
|
|
1407
1526
|
const anchorRecoveries: NonNullable<FileMutationBatchResult["anchorRecoveries"]>[number][] = [];
|
|
1408
1527
|
const messages: string[] = [];
|
|
1528
|
+
const exactTextFailures: string[] = [];
|
|
1409
1529
|
for (const item of recovered) {
|
|
1410
1530
|
if (item === undefined) {
|
|
1411
1531
|
continue;
|
|
1412
1532
|
}
|
|
1413
1533
|
results.push(...(item.details.results ?? []));
|
|
1414
1534
|
anchorRecoveries.push(...(item.details.anchorRecoveries ?? []));
|
|
1535
|
+
const failed = item.details.metadata?.exactTextFailures;
|
|
1536
|
+
if (Array.isArray(failed))
|
|
1537
|
+
exactTextFailures.push(
|
|
1538
|
+
...failed.filter((source): source is string => typeof source === "string"),
|
|
1539
|
+
);
|
|
1415
1540
|
for (const block of item.content) {
|
|
1416
1541
|
if (block.type === "text") {
|
|
1417
1542
|
messages.push(block.text);
|
|
@@ -1423,7 +1548,12 @@ async function anchorFailureToolResult(
|
|
|
1423
1548
|
}
|
|
1424
1549
|
return {
|
|
1425
1550
|
content: [{ type: "text", text: messages.join("\n\n") }],
|
|
1426
|
-
details: {
|
|
1551
|
+
details: {
|
|
1552
|
+
results,
|
|
1553
|
+
anchorRecoveries,
|
|
1554
|
+
effect: "not-applied",
|
|
1555
|
+
metadata: { exactTextFailures },
|
|
1556
|
+
},
|
|
1427
1557
|
};
|
|
1428
1558
|
}
|
|
1429
1559
|
if (!(failure.cause instanceof TextMutationAnchorResolutionError)) {
|
|
@@ -1432,15 +1562,10 @@ async function anchorFailureToolResult(
|
|
|
1432
1562
|
|
|
1433
1563
|
const contextual = failure.cause;
|
|
1434
1564
|
const resolution = contextual.resolution;
|
|
1435
|
-
const recovery = await resolveAnchorRecovery(contextual)
|
|
1436
|
-
|
|
1437
|
-
return
|
|
1438
|
-
|
|
1439
|
-
failure.code,
|
|
1440
|
-
`${failure.message}; recovery timed out`,
|
|
1441
|
-
"not-applied",
|
|
1442
|
-
);
|
|
1443
|
-
}
|
|
1565
|
+
const recovery = await resolveAnchorRecovery(contextual).catch(() => {
|
|
1566
|
+
context.signal?.throwIfAborted();
|
|
1567
|
+
return undefined;
|
|
1568
|
+
});
|
|
1444
1569
|
|
|
1445
1570
|
const windows =
|
|
1446
1571
|
recovery?.kind === "candidates"
|
|
@@ -1451,9 +1576,7 @@ async function anchorFailureToolResult(
|
|
|
1451
1576
|
: resolution.rejection?.contextRange === undefined
|
|
1452
1577
|
? []
|
|
1453
1578
|
: [resolution.rejection.contextRange];
|
|
1454
|
-
if (windows.length === 0) {
|
|
1455
|
-
return undefined;
|
|
1456
|
-
}
|
|
1579
|
+
if (windows.length === 0) windows.push({ offset: 1, limit: 40 });
|
|
1457
1580
|
|
|
1458
1581
|
const reads = await Promise.all(
|
|
1459
1582
|
windows.map((range) =>
|
|
@@ -1464,14 +1587,15 @@ async function anchorFailureToolResult(
|
|
|
1464
1587
|
cwd: context.cwd,
|
|
1465
1588
|
...(context.signal !== undefined && { signal: context.signal }),
|
|
1466
1589
|
},
|
|
1467
|
-
)
|
|
1590
|
+
)?.catch(() => {
|
|
1591
|
+
context.signal?.throwIfAborted();
|
|
1592
|
+
return undefined;
|
|
1593
|
+
}),
|
|
1468
1594
|
),
|
|
1469
1595
|
);
|
|
1470
1596
|
const recoveryTexts: string[] = [];
|
|
1471
1597
|
for (const read of reads) {
|
|
1472
|
-
if (read === undefined || read.isError === true)
|
|
1473
|
-
return undefined;
|
|
1474
|
-
}
|
|
1598
|
+
if (read === undefined || read.isError === true) continue;
|
|
1475
1599
|
recoveryTexts.push(
|
|
1476
1600
|
...read.content.filter((block) => block.type === "text").map((block) => block.text),
|
|
1477
1601
|
);
|
|
@@ -1512,6 +1636,9 @@ async function anchorFailureToolResult(
|
|
|
1512
1636
|
results: [result],
|
|
1513
1637
|
effect: "not-applied",
|
|
1514
1638
|
anchorRecovery: true,
|
|
1639
|
+
...(resolution.resolverId === "exact-text" && {
|
|
1640
|
+
metadata: { exactTextFailures: [contextual.source] },
|
|
1641
|
+
}),
|
|
1515
1642
|
...(recovery?.kind === "candidates" && {
|
|
1516
1643
|
anchorRecoveries: [
|
|
1517
1644
|
{
|
|
@@ -1539,14 +1666,16 @@ function formatRejectedAnchorMessage(
|
|
|
1539
1666
|
: code === "missing"
|
|
1540
1667
|
? "was not found"
|
|
1541
1668
|
: code === "invalid"
|
|
1542
|
-
? "
|
|
1669
|
+
? "was rejected"
|
|
1543
1670
|
: "could not be resolved";
|
|
1544
1671
|
const guidance =
|
|
1545
|
-
|
|
1546
|
-
?
|
|
1672
|
+
failure.resolution.resolverId === "exact-text"
|
|
1673
|
+
? failure.toolName === "copy"
|
|
1674
|
+
? "Use an anchor below, or get a fresh Read/Search selection and pass it to Copy."
|
|
1675
|
+
: "Exact-text edits are blocked for this file. Use a current anchor below for the intended edit, or get one with Read/Search. Exact text is available again after that edit succeeds."
|
|
1547
1676
|
: "If the intended text is represented below, use its candidate anchor. Otherwise, reread the relevant section and choose a current anchor.";
|
|
1548
1677
|
const context = recoveryContext.length === 0 ? "" : `\n\n${recoveryContext}`;
|
|
1549
|
-
return `[SYSTEM] ${failure.toolName} blocked: ${failure.field} anchor "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
|
|
1678
|
+
return `[SYSTEM] ${failure.toolName} blocked: ${failure.field === "anchor" ? "anchor" : `${failure.field} anchor`} "${failure.anchor}" ${state}. ${guidance} (${reason})${context}`;
|
|
1550
1679
|
}
|
|
1551
1680
|
|
|
1552
1681
|
function recoveryWindows(
|
|
@@ -1578,27 +1707,98 @@ export async function buildFailedTextMutationResult(
|
|
|
1578
1707
|
context: ExtensionContext,
|
|
1579
1708
|
effect: "applied" | "not-applied" | "unknown" = "not-applied",
|
|
1580
1709
|
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
1710
|
+
if (failure.rollback !== undefined) {
|
|
1711
|
+
return failureToolResult(
|
|
1712
|
+
failure.source,
|
|
1713
|
+
failure.code,
|
|
1714
|
+
failure.message,
|
|
1715
|
+
failure.rollback.failed.length === 0 && failure.rollback.originallyMissing.length === 0
|
|
1716
|
+
? "not-applied"
|
|
1717
|
+
: "unknown",
|
|
1718
|
+
failure.rollback,
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1581
1721
|
return effect === "not-applied"
|
|
1582
1722
|
? ((await anchorFailureToolResult(core, failure, context)) ??
|
|
1583
|
-
failureToolResult(failure.source, failure.code, failure.message, effect))
|
|
1584
|
-
: failureToolResult(failure.source, failure.code, failure.message, effect);
|
|
1723
|
+
failureToolResult(failure.source, failure.code, failure.message, effect, failure.rollback))
|
|
1724
|
+
: failureToolResult(failure.source, failure.code, failure.message, effect, failure.rollback);
|
|
1585
1725
|
}
|
|
1586
1726
|
|
|
1727
|
+
/** Report Copy rollback evidence without claiming that an unverified destination is unchanged. */
|
|
1728
|
+
export function buildFailedCopyWriteResult(
|
|
1729
|
+
failure: TextResourceEditFailure,
|
|
1730
|
+
unrestoredSources: readonly string[],
|
|
1731
|
+
): AgentToolResult<FileMutationBatchResult> {
|
|
1732
|
+
const rollbackFailed =
|
|
1733
|
+
failure.rollback === undefined
|
|
1734
|
+
? unrestoredSources.length > 0
|
|
1735
|
+
: failure.rollback.failed.length > 0 || failure.rollback.originallyMissing.length > 0;
|
|
1736
|
+
const effect = rollbackFailed ? "unknown" : "not-applied";
|
|
1737
|
+
const result = new FileMutationResult({
|
|
1738
|
+
ok: false,
|
|
1739
|
+
path: failure.source,
|
|
1740
|
+
errors: [{ path: failure.source, code: failure.code, reason: failure.message }],
|
|
1741
|
+
fileChangedStatement: rollbackFailed
|
|
1742
|
+
? "Rollback failed. Read the listed destinations before retrying."
|
|
1743
|
+
: "Copy failed. Destination changes were rolled back.",
|
|
1744
|
+
});
|
|
1745
|
+
return {
|
|
1746
|
+
content: [new FileMutationAgentResult(result).toTextContent()],
|
|
1747
|
+
details: {
|
|
1748
|
+
results: [result],
|
|
1749
|
+
effect,
|
|
1750
|
+
metadata: { copyRollback: rollbackFailed ? "failed" : "restored" },
|
|
1751
|
+
},
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1587
1754
|
function failureToolResult(
|
|
1588
1755
|
source: string,
|
|
1589
1756
|
code: string,
|
|
1590
1757
|
reason: string,
|
|
1591
1758
|
effect: "not-applied" | "applied" | "unknown",
|
|
1759
|
+
rollback?: TextResourceEditFailure["rollback"],
|
|
1760
|
+
copyExecutionFailure = false,
|
|
1592
1761
|
): { content: [{ type: "text"; text: string }]; details: FileMutationBatchResult } {
|
|
1762
|
+
const uncertain =
|
|
1763
|
+
rollback !== undefined && (rollback.failed.length > 0 || rollback.originallyMissing.length > 0);
|
|
1764
|
+
const fileChangedStatement =
|
|
1765
|
+
rollback === undefined
|
|
1766
|
+
? effect === "applied"
|
|
1767
|
+
? "The edit was saved, but a post-write step failed. Run Read/Search before editing this resource again."
|
|
1768
|
+
: effect === "unknown"
|
|
1769
|
+
? "The operation failed, and its effects are unknown. Read the affected resources before retrying."
|
|
1770
|
+
: undefined
|
|
1771
|
+
: rollback.originallyMissing.length > 0
|
|
1772
|
+
? "The file may now exist. Read the path before retrying."
|
|
1773
|
+
: uncertain
|
|
1774
|
+
? `Rollback failed for ${rollback.failed.join(", ")}. Current contents are unknown. Run Read/Search before editing these resources again.`
|
|
1775
|
+
: "Attempted writes were rolled back.";
|
|
1593
1776
|
const result = new FileMutationResult({
|
|
1594
1777
|
ok: false,
|
|
1595
1778
|
path: source,
|
|
1596
1779
|
errors: [{ path: source, code, reason }],
|
|
1780
|
+
...(fileChangedStatement === undefined ? {} : { fileChangedStatement }),
|
|
1781
|
+
...(rollback !== undefined && {
|
|
1782
|
+
rollback: {
|
|
1783
|
+
failedSources: [...new Set([...rollback.failed, ...rollback.originallyMissing])],
|
|
1784
|
+
},
|
|
1785
|
+
}),
|
|
1786
|
+
...(copyExecutionFailure && {
|
|
1787
|
+
fileChangedStatement:
|
|
1788
|
+
"Copy failed. Its effects are uncertain. Read the affected destinations before retrying.",
|
|
1789
|
+
}),
|
|
1597
1790
|
});
|
|
1598
1791
|
|
|
1599
1792
|
return {
|
|
1600
1793
|
content: [new FileMutationAgentResult(result).toTextContent()],
|
|
1601
|
-
details: {
|
|
1794
|
+
details: {
|
|
1795
|
+
results: [result],
|
|
1796
|
+
effect: rollback === undefined ? effect : uncertain ? "unknown" : "not-applied",
|
|
1797
|
+
...(rollback === undefined
|
|
1798
|
+
? {}
|
|
1799
|
+
: { metadata: { rollback: uncertain ? "uncertain" : "restored" } }),
|
|
1800
|
+
...(copyExecutionFailure && { metadata: { copyExecution: "uncertain" } }),
|
|
1801
|
+
},
|
|
1602
1802
|
};
|
|
1603
1803
|
}
|
|
1604
1804
|
|