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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-agent-text-anchor-line-hash",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#src/*": "./src/*"
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"pi-agent-invariant": "0.7.
|
|
16
|
-
"pi-agent-read": "0.7.
|
|
17
|
-
"pi-agent-text": "0.7.
|
|
18
|
-
"pi-agent-text-editor": "0.7.
|
|
15
|
+
"pi-agent-invariant": "0.7.2",
|
|
16
|
+
"pi-agent-read": "0.7.2",
|
|
17
|
+
"pi-agent-text": "0.7.2",
|
|
18
|
+
"pi-agent-text-editor": "0.7.2"
|
|
19
19
|
},
|
|
20
20
|
"pi": {
|
|
21
21
|
"extensions": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-agent-text-editor",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"imports": {
|
|
6
6
|
"#src/*": "./src/*"
|
|
@@ -79,14 +79,14 @@
|
|
|
79
79
|
"fs-extra": "^11.4.0",
|
|
80
80
|
"oxfmt": "0.64.0",
|
|
81
81
|
"partial-json": "^0.1.7",
|
|
82
|
-
"pi-agent-documentation": "0.7.
|
|
83
|
-
"pi-agent-invariant": "0.7.
|
|
84
|
-
"pi-agent-read": "0.7.
|
|
85
|
-
"pi-agent-resource": "0.7.
|
|
86
|
-
"pi-agent-search": "0.7.
|
|
87
|
-
"pi-agent-text": "0.7.
|
|
88
|
-
"pi-agent-tool-call-interception": "0.7.
|
|
89
|
-
"pi-agent-tool-ui": "0.7.
|
|
82
|
+
"pi-agent-documentation": "0.7.2",
|
|
83
|
+
"pi-agent-invariant": "0.7.2",
|
|
84
|
+
"pi-agent-read": "0.7.2",
|
|
85
|
+
"pi-agent-resource": "0.7.2",
|
|
86
|
+
"pi-agent-search": "0.7.2",
|
|
87
|
+
"pi-agent-text": "0.7.2",
|
|
88
|
+
"pi-agent-tool-call-interception": "0.7.2",
|
|
89
|
+
"pi-agent-tool-ui": "0.7.2",
|
|
90
90
|
"typebox-guard": "npm:typebox@^1.1.38"
|
|
91
91
|
},
|
|
92
92
|
"pi": {
|
|
@@ -3,8 +3,8 @@ import type { TextDocument } from "pi-agent-text";
|
|
|
3
3
|
export type TextEditIntent = "edit" | "restore" | "mixed";
|
|
4
4
|
|
|
5
5
|
export interface TextEditCompletion {
|
|
6
|
-
/**
|
|
7
|
-
readonly postProcessing?: "deferred" | "final" | "complete";
|
|
6
|
+
/** Saved bytes remain observable even when post-edit work is deferred or interrupted. */
|
|
7
|
+
readonly postProcessing?: "deferred" | "final" | "complete" | "interrupted";
|
|
8
8
|
readonly source: string;
|
|
9
9
|
readonly resourceSource: string;
|
|
10
10
|
readonly resolvedBy: string;
|
|
@@ -27,7 +27,8 @@ export {
|
|
|
27
27
|
export { type ChangedRange, computeChangedRanges } from "#src/core/mutation-result/diff.js";
|
|
28
28
|
export {
|
|
29
29
|
mutationDataSchema,
|
|
30
|
-
|
|
30
|
+
mutationResultSchema,
|
|
31
|
+
type BatchMutationData,
|
|
31
32
|
structuredMutation,
|
|
32
33
|
type MutationData,
|
|
33
34
|
} from "#src/core/structured-result.js";
|
|
@@ -5,6 +5,10 @@ import type { FileMutationBatchResult } from "./mutation-result.js";
|
|
|
5
5
|
export interface NativeEditBatchEvent {
|
|
6
6
|
readonly parentToolCallId: string;
|
|
7
7
|
readonly calls: readonly string[];
|
|
8
|
+
/** Successful Copy calls that retained identical destination text without a write. */
|
|
9
|
+
readonly unchangedCopyCalls?: readonly string[];
|
|
10
|
+
/** Per-call Copy receipts keep destination authority and rollback evidence. */
|
|
11
|
+
readonly copyResults?: ReadonlyMap<string, AgentToolResult<FileMutationBatchResult>>;
|
|
8
12
|
readonly result: AgentToolResult<FileMutationBatchResult>;
|
|
9
13
|
}
|
|
10
14
|
|
|
@@ -14,7 +14,7 @@ export function formatStaleAnchorMessage(
|
|
|
14
14
|
): string {
|
|
15
15
|
const context = details.context === undefined ? "" : `\n\n${details.context}`;
|
|
16
16
|
return (
|
|
17
|
-
`[SYSTEM] ${details.toolName} blocked: ${details.field} anchor "${details.anchor}" is stale. ` +
|
|
17
|
+
`[SYSTEM] ${details.toolName} blocked: ${details.field === "anchor" ? "anchor" : `${details.field} anchor`} "${details.anchor}" is stale. ` +
|
|
18
18
|
`If the required line is represented by one of the context lines below, use that anchor. Otherwise, reread only the relevant section of "${details.path}" and regenerate the anchor. (${reason})${context}`
|
|
19
19
|
);
|
|
20
20
|
}
|
|
@@ -33,10 +33,42 @@ export const diffDataSchema = Type.Object(
|
|
|
33
33
|
);
|
|
34
34
|
export const diffOutputSchema = structuredResultSchema(diffDataSchema);
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const comparisonReadParameters = {
|
|
37
|
+
...readParameters,
|
|
38
|
+
properties: {
|
|
39
|
+
...readParameters.properties,
|
|
40
|
+
path: {
|
|
41
|
+
...readParameters.properties.path,
|
|
42
|
+
description:
|
|
43
|
+
"Text-readable source accepted by Read, such as a file path, URL, temp: reference, SEARCH# or RESULT# reference, or registered resource. Supply a path.",
|
|
44
|
+
},
|
|
45
|
+
offset: {
|
|
46
|
+
...readParameters.properties.offset,
|
|
47
|
+
description:
|
|
48
|
+
"First text line to compare, numbered from 1. Omit or use 0 to start at line 1; negative offsets count from the end. For path#anchor, SEARCH# or RESULT# selections, count from the containing line: omitted, 0 or 1 starts there, 2 starts one line later, -1 one line earlier.",
|
|
49
|
+
},
|
|
50
|
+
limit: {
|
|
51
|
+
...readParameters.properties.limit,
|
|
52
|
+
description:
|
|
53
|
+
"Maximum text lines to compare from the selected starting position. Omit to compare all resolved text in the selected range. Read's display limits do not shorten the comparison inputs.",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
const source = Type.Union([Type.String({ minLength: 1 }), comparisonReadParameters]);
|
|
37
58
|
/** Each side accepts a source string or the same request object as read. */
|
|
38
59
|
export const diffParameters = Type.Object(
|
|
39
|
-
{
|
|
60
|
+
{
|
|
61
|
+
before: {
|
|
62
|
+
...source,
|
|
63
|
+
description:
|
|
64
|
+
"Source for the removed (-) side. Supply a non-empty source reference string or a Read request object. Strings identify sources, not literal text.",
|
|
65
|
+
},
|
|
66
|
+
after: {
|
|
67
|
+
...source,
|
|
68
|
+
description:
|
|
69
|
+
"Source for the added (+) side. Supply a non-empty source reference string or a Read request object. Strings identify sources, not literal text.",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
40
72
|
{ additionalProperties: false },
|
|
41
73
|
);
|
|
42
74
|
export type DiffRequest = Static<typeof diffParameters>;
|
|
@@ -107,13 +139,21 @@ export function comparisonText(data: ReadScriptData, requested: string): Compari
|
|
|
107
139
|
};
|
|
108
140
|
}
|
|
109
141
|
if (data.kind === "bytes")
|
|
110
|
-
throw Object.assign(
|
|
111
|
-
|
|
112
|
-
|
|
142
|
+
throw Object.assign(
|
|
143
|
+
new Error(
|
|
144
|
+
`Byte sources are not text: ${data.source}\nIf this is a text file, use its path without raw:.`,
|
|
145
|
+
),
|
|
146
|
+
{
|
|
147
|
+
code: "UNSUPPORTED_CONTENT",
|
|
148
|
+
},
|
|
149
|
+
);
|
|
113
150
|
if (data.blocks.length === 0 || data.blocks.some((block) => block.type !== "text"))
|
|
114
|
-
throw Object.assign(
|
|
115
|
-
|
|
116
|
-
|
|
151
|
+
throw Object.assign(
|
|
152
|
+
new Error(`Source is not text: ${data.source}\nUse a source that Read resolves to text.`),
|
|
153
|
+
{
|
|
154
|
+
code: "UNSUPPORTED_CONTENT",
|
|
155
|
+
},
|
|
156
|
+
);
|
|
117
157
|
return {
|
|
118
158
|
source: data.source,
|
|
119
159
|
sources: [data.source],
|
|
@@ -166,8 +206,7 @@ export function registerDiff(
|
|
|
166
206
|
parameters: diffParameters,
|
|
167
207
|
outputSchema: diffOutputSchema,
|
|
168
208
|
promptSnippet: "Compare two text-readable sources",
|
|
169
|
-
description:
|
|
170
|
-
"Use diff to compare two sources. before and after accept a source string or a read request {path, offset?, limit?, views?}. Use any source that read can resolve as text. Omit limit to compare complete resolved text; read presentation limits do not clip comparison inputs. Multiple resolved resources are joined with one newline separator in resolver order. Diff line numbers are relative to each selected text, not the original file when a window is selected. Native non-text content is rejected. Output uses the existing text diff and a shared output budget; oversized output has a full temporary reference.",
|
|
209
|
+
description: "Use diff to compare two text-readable sources without changing them.",
|
|
171
210
|
renderCall(_args, theme) {
|
|
172
211
|
return new Text(theme.fg("toolTitle", theme.bold("Diff")), 0, 0);
|
|
173
212
|
},
|
|
@@ -195,7 +234,10 @@ export function registerDiff(
|
|
|
195
234
|
const full = diffText(comparison);
|
|
196
235
|
const bounded = truncateHead(full);
|
|
197
236
|
const temporarySource = bounded.truncated ? await read.saveTemporary(full) : undefined;
|
|
198
|
-
const footer =
|
|
237
|
+
const footer =
|
|
238
|
+
temporarySource === undefined
|
|
239
|
+
? ""
|
|
240
|
+
: `\nDiff output is truncated; the comparison used the complete resolved inputs.\nUse read with path "${temporarySource}" for the full diff.`;
|
|
199
241
|
return withStructuredResult(
|
|
200
242
|
{
|
|
201
243
|
content: [
|
|
@@ -205,7 +247,7 @@ export function registerDiff(
|
|
|
205
247
|
temporarySource === undefined
|
|
206
248
|
? full
|
|
207
249
|
: truncateHead(full, {
|
|
208
|
-
maxLines: DEFAULT_MAX_LINES -
|
|
250
|
+
maxLines: DEFAULT_MAX_LINES - footer.split("\n").length,
|
|
209
251
|
maxBytes: DEFAULT_MAX_BYTES - Buffer.byteLength(footer),
|
|
210
252
|
}).content + footer,
|
|
211
253
|
},
|
|
@@ -4,5 +4,5 @@ export const EDITING_GUIDELINES = [
|
|
|
4
4
|
"Use an available anchor when it selects exactly the intended text; otherwise use minimal unique exact text. Keep the edit limited to the intended content.",
|
|
5
5
|
"When search broadens to separate words, treat its results as location hints. Refine the query before using those matches for replacement.",
|
|
6
6
|
"Use standalone mutation tools in one assistant-response batch when each change is known in advance and does not depend on another change. This is the default for several independent edits in one file or across files. Every call is evaluated against the original file snapshots. Combine overlapping changes into one mutation. Use native Codemode for computed or dependent tool composition; it keeps the same tool contracts and does not add grouped rollback. Check each batch result and retry only unapplied changes.",
|
|
7
|
-
"Inside
|
|
7
|
+
"Inside Codemode, run independent edits on different resources concurrently; run edits on the same resource in order. Check the final Codemode result and retry only unapplied changes. Read docs:editing when you need a write report inside the script.",
|
|
8
8
|
] as const;
|
|
@@ -63,6 +63,9 @@ export default async function registerTextEditorCore(
|
|
|
63
63
|
);
|
|
64
64
|
});
|
|
65
65
|
setTextEditBatchRenderArgumentSink(core, interceptionRendering.resolveArguments);
|
|
66
|
+
core.onDidEdit((completion) => {
|
|
67
|
+
resultTargets.refresh(completion.resourceSource, completion.cwd);
|
|
68
|
+
});
|
|
66
69
|
await core.registerPlugin({
|
|
67
70
|
protocol: TEXT_EDITOR_PROTOCOL,
|
|
68
71
|
apiVersion: TEXT_EDITOR_API_VERSION,
|
|
@@ -90,9 +93,13 @@ export default async function registerTextEditorCore(
|
|
|
90
93
|
api.addTargetResolver({ resolver: core.textTargetResolver() });
|
|
91
94
|
api.addFragmentResolver(createReadFragmentResolver(core));
|
|
92
95
|
|
|
93
|
-
api.describe(
|
|
94
|
-
"path#anchor — source around a returned line or scope anchor, e.g. notes.txt#12#A4F0. SEARCH# references go directly in path, without a file prefix.
|
|
95
|
-
|
|
96
|
+
api.describe({
|
|
97
|
+
path: "path#anchor — source around a returned line or scope anchor, e.g. notes.txt#12#A4F0. SEARCH# and RESULT# references go directly in path, without a file prefix. Returned Read/Search/Select/mutation targets select their verified source ranges.",
|
|
98
|
+
offset:
|
|
99
|
+
"For path#anchor, SEARCH# or RESULT# selections, count from each containing line: omitted, 0 or 1 starts there; 2 starts one line later; -1 starts one line earlier. Output keeps original line numbers.",
|
|
100
|
+
limit:
|
|
101
|
+
"For source selections, limit caps each selected context window separately. Without limit, each selection supplies its natural line count, with at least one line.",
|
|
102
|
+
});
|
|
96
103
|
},
|
|
97
104
|
});
|
|
98
105
|
setTextAnchorRecoveryReader(core, (request, context) => {
|
|
@@ -19,11 +19,6 @@ export const transferFileParameters = Type.Object(
|
|
|
19
19
|
{
|
|
20
20
|
path: filePath,
|
|
21
21
|
target: filePath,
|
|
22
|
-
overwrite: Type.Optional(
|
|
23
|
-
Type.Boolean({
|
|
24
|
-
description: "Allow replacing an existing regular target file. Defaults to false.",
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
22
|
},
|
|
28
23
|
{ additionalProperties: false },
|
|
29
24
|
);
|
|
@@ -76,7 +71,7 @@ export async function executeFileOperation(
|
|
|
76
71
|
throw Object.assign(new Error("Invalid file operation arguments"), {
|
|
77
72
|
code: "INVALID_ARGUMENTS",
|
|
78
73
|
});
|
|
79
|
-
const args = input as { path: string; target?: string
|
|
74
|
+
const args = input as { path: string; target?: string };
|
|
80
75
|
source = path.resolve(cwd, args.path);
|
|
81
76
|
target = args.target === undefined ? undefined : path.resolve(cwd, args.target);
|
|
82
77
|
signal?.throwIfAborted();
|
|
@@ -95,19 +90,14 @@ export async function executeFileOperation(
|
|
|
95
90
|
throw Object.assign(new Error("Source and target are the same file"), {
|
|
96
91
|
code: "SAME_FILE",
|
|
97
92
|
});
|
|
98
|
-
if (args.overwrite !== true)
|
|
99
|
-
throw Object.assign(new Error("Target exists; use overwrite: true to replace it"), {
|
|
100
|
-
code: "EEXIST",
|
|
101
|
-
});
|
|
102
93
|
}
|
|
103
94
|
}
|
|
104
95
|
signal?.throwIfAborted();
|
|
105
96
|
started = true;
|
|
106
97
|
if (operation === "delete") await unlink(source);
|
|
107
98
|
else if (target !== undefined) {
|
|
108
|
-
if (operation === "copy")
|
|
109
|
-
|
|
110
|
-
else await fs.move(source, target, { overwrite: args.overwrite === true });
|
|
99
|
+
if (operation === "copy") await fs.copy(source, target, { overwrite: true });
|
|
100
|
+
else await fs.move(source, target, { overwrite: true });
|
|
111
101
|
}
|
|
112
102
|
return {
|
|
113
103
|
kind: "file-operation",
|
package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-agent-result.ts
CHANGED
|
@@ -287,6 +287,27 @@ export class FileMutationAgentResult {
|
|
|
287
287
|
|
|
288
288
|
// ── Success formatting ────────────────────────────────────────────────
|
|
289
289
|
|
|
290
|
+
private formatFormatting(formatting: FileMutationResult["data"]["formatting"]): string {
|
|
291
|
+
const by = formatting?.formatter === undefined ? "" : ` (${formatting.formatter})`;
|
|
292
|
+
switch (formatting?.status) {
|
|
293
|
+
case "changed": {
|
|
294
|
+
return `Formatted${by}.`;
|
|
295
|
+
}
|
|
296
|
+
case "unchanged": {
|
|
297
|
+
return `Already formatted${by}.`;
|
|
298
|
+
}
|
|
299
|
+
case "unavailable": {
|
|
300
|
+
return "No formatter is available for this file.";
|
|
301
|
+
}
|
|
302
|
+
case "failed": {
|
|
303
|
+
return `Formatting failed${by}. Read the saved file before retrying.`;
|
|
304
|
+
}
|
|
305
|
+
default: {
|
|
306
|
+
return `Formatting: ${formatting?.status ?? "not-reported"}${by}.`;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
290
311
|
private formatSuccess(fmr: FileMutationResult): string {
|
|
291
312
|
const operations = fmr.data.operations ?? [];
|
|
292
313
|
const verbs: Record<string, string> = {
|
|
@@ -295,7 +316,6 @@ export class FileMutationAgentResult {
|
|
|
295
316
|
delete: "Deleted selected text",
|
|
296
317
|
copy: "Copied selected text",
|
|
297
318
|
move: "Moved selected text",
|
|
298
|
-
write: "Wrote file content",
|
|
299
319
|
undo: "Restored file content",
|
|
300
320
|
stage: "Staged selected changes",
|
|
301
321
|
unstage: "Unstaged selected changes",
|
|
@@ -304,15 +324,24 @@ export class FileMutationAgentResult {
|
|
|
304
324
|
operations.length === 0
|
|
305
325
|
? "Changes applied."
|
|
306
326
|
: operations
|
|
307
|
-
.map(
|
|
308
|
-
|
|
309
|
-
|
|
327
|
+
.map(({ operation, changes }) =>
|
|
328
|
+
operation === "write"
|
|
329
|
+
? "Saved file."
|
|
330
|
+
: `${verbs[operation] ?? `Applied ${operation}`}: ${changes} text change(s) in this file.`,
|
|
310
331
|
)
|
|
311
332
|
.join("\n"),
|
|
312
|
-
|
|
333
|
+
this.formatFormatting(fmr.data.formatting),
|
|
313
334
|
];
|
|
314
335
|
|
|
315
|
-
for (const status of fmr.data.diffStatuses ?? [])
|
|
336
|
+
for (const status of fmr.data.diffStatuses ?? []) {
|
|
337
|
+
if (
|
|
338
|
+
status.formattingStatus !== undefined &&
|
|
339
|
+
status.formattingStatus === fmr.data.formatting?.status &&
|
|
340
|
+
status.formatter === fmr.data.formatting.formatter
|
|
341
|
+
)
|
|
342
|
+
continue;
|
|
343
|
+
blocks.push(status.text);
|
|
344
|
+
}
|
|
316
345
|
for (const diff of fmr.diffs) {
|
|
317
346
|
const path = /^--- (.+)$/m.exec(diff)?.[1] ?? fmr.path ?? "<unknown file>";
|
|
318
347
|
blocks.push(renderFinalStateFragment(fmr, path).join("\n"));
|
|
@@ -29,6 +29,8 @@ export interface MutationFormatting {
|
|
|
29
29
|
export interface MutationDiffStatus {
|
|
30
30
|
/** Formatter identity allows multi-file summaries without parsing display text. */
|
|
31
31
|
readonly formatter?: string;
|
|
32
|
+
/** Observed formatter state for this label, kept distinct from file edit counts. */
|
|
33
|
+
readonly formattingStatus?: MutationFormatting["status"];
|
|
32
34
|
readonly text: string;
|
|
33
35
|
readonly tone?: "muted" | "success" | "warning" | "error";
|
|
34
36
|
}
|
|
@@ -236,6 +238,8 @@ export interface FileMutationData {
|
|
|
236
238
|
|
|
237
239
|
staleDiagnostic?: StaleAnchorDiagnostic | undefined;
|
|
238
240
|
fileChangedStatement?: string | undefined;
|
|
241
|
+
/** Failed rollback resources; an empty list means all attempted writes were restored. */
|
|
242
|
+
rollback?: { readonly failedSources: readonly string[] } | undefined;
|
|
239
243
|
|
|
240
244
|
// ── Transient engine fields ──
|
|
241
245
|
snapshot?: MutationSnapshot | undefined;
|
|
@@ -325,7 +329,21 @@ export class FileMutationResult {
|
|
|
325
329
|
readonly data: FileMutationData;
|
|
326
330
|
|
|
327
331
|
public constructor(data?: FileMutationData) {
|
|
328
|
-
|
|
332
|
+
const formatting = data?.formatting;
|
|
333
|
+
this.data =
|
|
334
|
+
formatting === undefined || data?.diffStatuses === undefined
|
|
335
|
+
? (data ?? {})
|
|
336
|
+
: {
|
|
337
|
+
...data,
|
|
338
|
+
diffStatuses: data.diffStatuses.map((status) =>
|
|
339
|
+
status.formattingStatus !== undefined ||
|
|
340
|
+
formatting.formatter === undefined ||
|
|
341
|
+
status.formatter !== formatting.formatter ||
|
|
342
|
+
(status.tone !== "success" && status.tone !== "error")
|
|
343
|
+
? status
|
|
344
|
+
: { ...status, formattingStatus: formatting.status },
|
|
345
|
+
),
|
|
346
|
+
};
|
|
329
347
|
}
|
|
330
348
|
|
|
331
349
|
// ── Getters ──
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
1
3
|
import type { ResultRange, ResultSourceTarget } from "pi-agent-resource";
|
|
2
4
|
import type { ResultTargetStore } from "pi-agent-resource";
|
|
3
5
|
import type { AgentToolResult } from "@earendil-works/pi-coding-agent";
|
|
4
6
|
import type { FileMutationBatchResult } from "#src/api/mutation-result.js";
|
|
5
7
|
import { createTextDocument } from "pi-agent-text";
|
|
6
8
|
import type { TextEditCompletion } from "#src/api/edit-completion.js";
|
|
7
|
-
import type { TextMutationEdit } from "#src/api/mutation-tool.js";
|
|
9
|
+
import type { TextMutation, TextMutationEdit } from "#src/api/mutation-tool.js";
|
|
8
10
|
import { applyTextChanges } from "./text-change-engine.js";
|
|
9
11
|
import { attachFileMutationTargets } from "./file-result-targets.js";
|
|
10
12
|
|
|
@@ -14,10 +16,36 @@ export interface OwnedMutationChanges {
|
|
|
14
16
|
readonly edits: ReadonlyMap<string, TextMutationEdit>;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
/**
|
|
19
|
+
/** Find Copy destinations with identical text and no secondary resource action. */
|
|
20
|
+
export function unchangedCopySources(
|
|
21
|
+
mutation: TextMutation,
|
|
22
|
+
snapshots: ReadonlyMap<string, string>,
|
|
23
|
+
): ReadonlySet<string> {
|
|
24
|
+
if (mutation.afterWrite !== undefined || mutation.semanticAction !== undefined) return new Set();
|
|
25
|
+
return new Set(
|
|
26
|
+
[...mutation.edits]
|
|
27
|
+
.filter(([source, edit]) => {
|
|
28
|
+
const before = snapshots.get(source);
|
|
29
|
+
return (
|
|
30
|
+
before !== undefined &&
|
|
31
|
+
edit.changes.length > 0 &&
|
|
32
|
+
edit.changes.every(
|
|
33
|
+
(change) =>
|
|
34
|
+
change.allowUnchanged && before.slice(change.from, change.to) === change.insert,
|
|
35
|
+
)
|
|
36
|
+
);
|
|
37
|
+
})
|
|
38
|
+
.map(([source]) => source),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
/** Map final resource snapshots and unchanged Copy ranges; verify before publishing. */
|
|
18
42
|
export function committedMutationTargets(
|
|
19
43
|
mutations: readonly OwnedMutationChanges[],
|
|
20
|
-
completions: readonly
|
|
44
|
+
completions: readonly Pick<
|
|
45
|
+
TextEditCompletion,
|
|
46
|
+
"source" | "resourceSource" | "resolvedBy" | "before" | "after" | "existed"
|
|
47
|
+
>[],
|
|
48
|
+
unchangedSnapshots: ReadonlyMap<string, string> = new Map(),
|
|
21
49
|
): ReadonlyMap<string, readonly ResultSourceTarget[]> {
|
|
22
50
|
const targets = new Map<string, ResultSourceTarget[]>();
|
|
23
51
|
const sources = new Set(mutations.flatMap((mutation) => [...mutation.edits.keys()]));
|
|
@@ -25,7 +53,7 @@ export function committedMutationTargets(
|
|
|
25
53
|
const completion = completions.findLast(
|
|
26
54
|
(item) => item.source === source || item.resourceSource === source,
|
|
27
55
|
);
|
|
28
|
-
if (
|
|
56
|
+
if (completion && completion.resolvedBy !== "filesystem") continue;
|
|
29
57
|
const changes = mutations
|
|
30
58
|
.flatMap((mutation) =>
|
|
31
59
|
(mutation.edits.get(source)?.changes ?? []).map((change, index) => ({
|
|
@@ -35,12 +63,22 @@ export function committedMutationTargets(
|
|
|
35
63
|
})),
|
|
36
64
|
)
|
|
37
65
|
.sort((left, right) => left.from - right.from);
|
|
38
|
-
const before = completion
|
|
39
|
-
|
|
40
|
-
if (
|
|
66
|
+
const before = completion?.before.content ?? unchangedSnapshots.get(source);
|
|
67
|
+
if (before === undefined) continue;
|
|
68
|
+
if (
|
|
69
|
+
!completion &&
|
|
70
|
+
changes.some(
|
|
71
|
+
(change) =>
|
|
72
|
+
!change.allowUnchanged || before.slice(change.from, change.to) !== change.insert,
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
continue;
|
|
76
|
+
const after = completion?.after.content ?? before;
|
|
77
|
+
const resourceSource = completion?.resourceSource ?? source;
|
|
78
|
+
if (applyTextChanges(before, changes, completion?.existed === false).content !== after)
|
|
41
79
|
throw new Error("Mutation targets cannot be mapped to the actual written snapshot.");
|
|
42
80
|
const starts = [0];
|
|
43
|
-
for (const line of createTextDocument(
|
|
81
|
+
for (const line of createTextDocument(resourceSource, after).lines)
|
|
44
82
|
if (line.lineEnding.length > 0)
|
|
45
83
|
starts.push((starts.at(-1) ?? 0) + line.content.length + line.lineEnding.length);
|
|
46
84
|
const position = (offset: number): ResultRange["start"] => {
|
|
@@ -71,7 +109,7 @@ export function committedMutationTargets(
|
|
|
71
109
|
for (const [callId, selected] of ranges) {
|
|
72
110
|
const own = targets.get(callId) ?? [];
|
|
73
111
|
own.push({
|
|
74
|
-
source:
|
|
112
|
+
source: resourceSource,
|
|
75
113
|
expectedContent: after,
|
|
76
114
|
ranges: selected,
|
|
77
115
|
});
|
|
@@ -81,6 +119,81 @@ export function committedMutationTargets(
|
|
|
81
119
|
return targets;
|
|
82
120
|
}
|
|
83
121
|
|
|
122
|
+
/** Explain missing Copy authority without changing its write outcome. */
|
|
123
|
+
export function describeUnavailableCopyTarget(
|
|
124
|
+
result: AgentToolResult<FileMutationBatchResult>,
|
|
125
|
+
): AgentToolResult<FileMutationBatchResult> {
|
|
126
|
+
const notice = "No verified text selection. Read the destination before further edits.";
|
|
127
|
+
if (
|
|
128
|
+
result.isError ||
|
|
129
|
+
typeof result.details.metadata?.targetUnavailable !== "string" ||
|
|
130
|
+
result.content.some((block) => block.type === "text" && block.text === notice)
|
|
131
|
+
)
|
|
132
|
+
return result;
|
|
133
|
+
return {
|
|
134
|
+
...result,
|
|
135
|
+
content: [
|
|
136
|
+
...result.content,
|
|
137
|
+
{
|
|
138
|
+
type: "text",
|
|
139
|
+
text: notice,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Publish filesystem Write snapshots, never grant file authority to live resources. */
|
|
146
|
+
export async function attachWriteTarget(
|
|
147
|
+
result: AgentToolResult<FileMutationBatchResult>,
|
|
148
|
+
completions: readonly TextEditCompletion[],
|
|
149
|
+
store: ResultTargetStore,
|
|
150
|
+
cwd: string,
|
|
151
|
+
signal?: AbortSignal,
|
|
152
|
+
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
153
|
+
if (result.isError) return result;
|
|
154
|
+
const file = result.details.results?.[0]?.data;
|
|
155
|
+
if (file?.path === undefined || file.afterContent === undefined) return result;
|
|
156
|
+
if (completions.some((completion) => completion.resolvedBy !== "filesystem")) return result;
|
|
157
|
+
try {
|
|
158
|
+
const content = file.afterContent;
|
|
159
|
+
const lines = content.split(/\r\n|\r|\n/u);
|
|
160
|
+
const targets: ResultSourceTarget[] = [
|
|
161
|
+
{
|
|
162
|
+
source: path.resolve(
|
|
163
|
+
cwd,
|
|
164
|
+
file.path.startsWith("file://") ? fileURLToPath(file.path) : file.path,
|
|
165
|
+
),
|
|
166
|
+
expectedContent: content,
|
|
167
|
+
ranges: [
|
|
168
|
+
{
|
|
169
|
+
start: { lineNumber: 1, column: 0 },
|
|
170
|
+
end: { lineNumber: lines.length, column: lines.at(-1)?.length ?? 0 },
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
await store.verify({ targets, complete: true }, signal);
|
|
176
|
+
return {
|
|
177
|
+
...result,
|
|
178
|
+
details: {
|
|
179
|
+
...result.details,
|
|
180
|
+
metadata: { ...result.details.metadata, resultTarget: store.register(targets, cwd) },
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
} catch (error) {
|
|
184
|
+
signal?.throwIfAborted();
|
|
185
|
+
return {
|
|
186
|
+
...result,
|
|
187
|
+
details: {
|
|
188
|
+
...result.details,
|
|
189
|
+
metadata: {
|
|
190
|
+
...result.details.metadata,
|
|
191
|
+
targetUnavailable: error instanceof Error ? error.message : String(error),
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
84
197
|
/** Publish immediate results only when their committed range mapping is verified. */
|
|
85
198
|
export async function attachCommittedMutationTarget(
|
|
86
199
|
result: AgentToolResult<FileMutationBatchResult>,
|
|
@@ -92,8 +205,14 @@ export async function attachCommittedMutationTarget(
|
|
|
92
205
|
wholeFile = false,
|
|
93
206
|
plannedEdits?: ReadonlyMap<string, TextMutationEdit>,
|
|
94
207
|
destinationOnly = false,
|
|
208
|
+
unchangedSnapshots: ReadonlyMap<string, string> = new Map(),
|
|
95
209
|
): Promise<AgentToolResult<FileMutationBatchResult>> {
|
|
96
|
-
if (
|
|
210
|
+
if (
|
|
211
|
+
result.isError ||
|
|
212
|
+
typeof result.details.metadata?.resultTarget === "string" ||
|
|
213
|
+
completions.some((completion) => completion.resolvedBy !== "filesystem")
|
|
214
|
+
)
|
|
215
|
+
return result;
|
|
97
216
|
result = await attachFileMutationTargets(result, store, cwd, signal);
|
|
98
217
|
if (
|
|
99
218
|
typeof result.details.metadata?.resultTarget === "string" ||
|
|
@@ -135,9 +254,11 @@ export async function attachCommittedMutationTarget(
|
|
|
135
254
|
},
|
|
136
255
|
);
|
|
137
256
|
}
|
|
257
|
+
for (const [source, edit] of plannedEdits ?? [])
|
|
258
|
+
if (!edits.has(source) && unchangedSnapshots.has(source)) edits.set(source, edit);
|
|
138
259
|
if (edits.size === 0 && result.details.metadata?.emptyTargets !== true) return result;
|
|
139
260
|
try {
|
|
140
|
-
const mapped = committedMutationTargets([{ callId, edits }], completions);
|
|
261
|
+
const mapped = committedMutationTargets([{ callId, edits }], completions, unchangedSnapshots);
|
|
141
262
|
const targets = mapped.get(callId) ?? [];
|
|
142
263
|
const outputCount = [...edits.values()].filter(
|
|
143
264
|
(edit) => edit.resultChanges?.length !== 0,
|