pi-agent-ide 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +2 -2
- package/dist/{chunk-AWXVJ5AC.js → chunk-2RTCSZB3.js} +1 -1
- package/dist/{chunk-QEJGED4V.js → chunk-3HYXQ4YA.js} +1 -1
- package/dist/chunk-3JO7QFIL.js +1 -0
- package/dist/{chunk-5J43L2RL.js → chunk-4NIFBFFR.js} +1 -1
- package/dist/{chunk-BSICWXMH.js → chunk-64M3SQPG.js} +1 -1
- package/dist/{chunk-3BBJZSMS.js → chunk-7LD2OQH3.js} +1 -1
- package/dist/chunk-7LZKOHH2.js +1 -0
- package/dist/chunk-AJRIASPQ.js +2 -0
- package/dist/chunk-EAZGN5ND.js +7 -0
- package/dist/{chunk-GIRAEVUJ.js → chunk-F5YZG77W.js} +1 -1
- package/dist/chunk-FK42RSF4.js +1 -0
- package/dist/{chunk-WJTHY6AG.js → chunk-FXNKMNSJ.js} +1 -1
- package/dist/chunk-GBLKIB6O.js +2 -0
- package/dist/{chunk-KUPHNMUK.js → chunk-KBP3QUDT.js} +1 -1
- package/dist/{chunk-VBICI5YA.js → chunk-KR36BT5E.js} +1 -1
- package/dist/chunk-OE7QVAI2.js +5 -0
- package/dist/chunk-PNU3E7IO.js +3 -0
- package/dist/chunk-PS2B6THP.js +3 -0
- package/dist/{chunk-HPUAIWIH.js → chunk-PYPPV2F5.js} +1 -1
- package/dist/{chunk-FUG2TEKI.js → chunk-QFTBY67N.js} +2 -2
- package/dist/chunk-S5LXX32D.js +28 -0
- package/dist/chunk-SQKAXYIR.js +2 -0
- package/dist/chunk-VCGNVTXQ.js +1 -0
- package/dist/chunk-XYS4FSCC.js +12 -0
- package/dist/{chunk-FBOW7XOV.js → chunk-YRF7OATP.js} +1 -1
- package/dist/entry-11.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +13 -11
- package/dist/entry-33.js +1 -1
- package/dist/entry-37.js +6 -6
- package/dist/entry-42.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +13 -13
- package/dist/entry-46.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +3 -6
- package/dist/entry-51.js +11 -9
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +0 -1
- package/dist/entry-62.js +1 -0
- package/dist/entry-63.js +0 -1
- package/dist/entry-64.js +1 -0
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-67.js +1 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-71.js +0 -1
- package/dist/entry-72.js +1 -0
- package/dist/entry-73.js +0 -1
- package/dist/entry-74.js +1 -0
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +1 -1
- package/dist/entry-77.js +67 -1
- package/dist/entry-78.js +14 -325
- package/dist/entry-79.js +2 -18
- package/dist/entry-80.js +1 -2
- package/dist/entry-81.js +1 -1
- package/dist/entry-82.js +5 -1
- package/dist/entry-83.js +3 -5
- package/dist/entry-84.js +1 -3
- package/dist/entry-85.js +1 -1
- package/dist/entry-86.js +1 -1
- package/dist/pi-agent-ide.js +5 -5
- package/docs/agent-guides/editing.md +20 -4
- package/docs/agent-guides/git-changes.md +1 -1
- package/docs/agent-guides/read-resources.md +9 -1
- package/docs/agent-guides/search-code.md +38 -1
- package/docs/agent-guides/select-code.md +194 -0
- package/docs/configuration.md +12 -17
- package/docs/development.md +2 -1
- package/docs/releases.md +1 -1
- package/docs/research/apply-native-capability-matrix.md +174 -0
- package/docs/research/apply-read-latency.md +2 -0
- package/docs/research/lpt-393-fuzzy-results/file.json +152 -0
- package/docs/research/lpt-393-fuzzy-results/repo.json +122 -0
- package/docs/research/lpt-393-search-fuzzy-fallback.md +97 -0
- package/docs/research/native-codemode-batch-decision.md +2 -0
- package/docs/research/native-codemode-batching.md +1 -1
- package/docs/structured-results.md +32 -5
- package/docs/tools.md +6 -2
- package/docs/user-hooks.md +1 -1
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-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 +15 -10
- package/node_modules/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/node_modules/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/node_modules/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/node_modules/pi-agent-ide-ast/src/extension.ts +4 -2
- package/node_modules/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +107 -21
- package/node_modules/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/node_modules/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/node_modules/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/node_modules/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/node_modules/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/node_modules/pi-agent-ide-ast/src/tool-select.ts +251 -0
- package/node_modules/pi-agent-ide-changes/index.ts +2 -18
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- 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 +2 -2
- package/node_modules/pi-agent-ide-lsp/package.json +9 -9
- package/node_modules/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/node_modules/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/node_modules/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/node_modules/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/node_modules/pi-agent-ide-lsp/src/search-resolver.ts +88 -45
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +7 -7
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +2 -2
- package/node_modules/pi-agent-read/src/api/tools/read.ts +4 -0
- package/node_modules/pi-agent-read/src/core/extension.ts +11 -0
- package/node_modules/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/node_modules/pi-agent-read/src/core/tools/read/structured-result.ts +2 -0
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +8 -1
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-resource/src/index.ts +10 -0
- package/node_modules/pi-agent-resource/src/result-targets.ts +233 -0
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/node_modules/pi-agent-search/src/api/presentation.ts +68 -0
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +9 -3
- package/node_modules/pi-agent-search/src/api/search-scope.ts +22 -0
- package/node_modules/pi-agent-search/src/api/search.ts +28 -0
- package/node_modules/pi-agent-search/src/api/structured-result.ts +69 -14
- package/node_modules/pi-agent-search/src/core/extension.ts +56 -16
- package/node_modules/pi-agent-search/src/core/search-core.ts +9 -1
- package/node_modules/pi-agent-search-text/index.ts +3 -1
- package/node_modules/pi-agent-search-text/package.json +7 -6
- package/node_modules/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +161 -30
- package/node_modules/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/node_modules/pi-agent-search-text/src/search-backend.ts +104 -17
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +89 -292
- package/node_modules/pi-agent-search-text/src/search-result.ts +77 -0
- package/node_modules/pi-agent-search-text/src/search-session.ts +96 -11
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-editor/index.ts +0 -5
- package/node_modules/pi-agent-text-editor/package.json +26 -31
- package/node_modules/pi-agent-text-editor/runtime/entry-77.js +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/node_modules/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
- package/node_modules/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +12 -2
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/node_modules/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/node_modules/pi-agent-text-editor/src/core/native-text-edit-batch.ts +199 -19
- package/node_modules/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/node_modules/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/node_modules/pi-agent-text-editor/src/core/structured-result.ts +109 -11
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +211 -223
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/node_modules/pi-agent-text-editor-renderer/index.ts +1 -72
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-80.js +1 -0
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/src/index.ts +7 -0
- package/node_modules/pi-agent-tool-ui/src/result-panel.ts +298 -0
- package/node_modules/pi-agent-web/index.ts +3 -0
- package/node_modules/pi-agent-web/package.json +8 -8
- package/node_modules/pi-agent-web/runtime/entry-82.js +2 -0
- package/node_modules/pi-agent-web/src/search.ts +111 -2
- package/node_modules/pi-agent-web-html/package.json +3 -3
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/package.json +35 -36
- package/src/composite/module-labels.ts +1 -1
- package/src/composite/preferences.ts +0 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-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 +3 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-83.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-82.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/search.ts +111 -2
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +2 -2
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +4 -0
- package/src/extensions/pi-agent-read/src/core/extension.ts +11 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/result-target.ts +93 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/structured-result.ts +2 -0
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +8 -1
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +3 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +7 -6
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/fuzzy-search.ts +164 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +161 -30
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/scoped-search.ts +103 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +104 -17
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +89 -292
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +77 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +96 -11
- package/src/extensions/pi-agent-search/src/api/fuzzy.ts +208 -0
- package/src/extensions/pi-agent-search/src/api/presentation.ts +68 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +9 -3
- package/src/extensions/pi-agent-search/src/api/search-scope.ts +22 -0
- package/src/extensions/pi-agent-search/src/api/search.ts +28 -0
- package/src/extensions/pi-agent-search/src/api/structured-result.ts +69 -14
- package/src/extensions/pi-agent-search/src/core/extension.ts +56 -16
- package/src/extensions/pi-agent-search/src/core/search-core.ts +9 -1
- package/src/extensions/pi-agent-text-editor/index.ts +0 -5
- package/src/extensions/pi-agent-text-editor/package.json +26 -31
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +1 -72
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-78.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/diff-model.ts +19 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +19 -45
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/runtime/entry-77.js +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +3 -1
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +1 -20
- package/src/extensions/pi-agent-text-editor/src/core/diff-tool.ts +4 -23
- package/src/extensions/pi-agent-text-editor/src/core/editing-guidelines.ts +2 -2
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +12 -2
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +29 -4
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/file-result-targets.ts +76 -0
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result/file-mutation-result.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/mutation-result-targets.ts +168 -0
- package/src/extensions/pi-agent-text-editor/src/core/native-text-edit-batch.ts +199 -19
- package/src/extensions/pi-agent-text-editor/src/core/result-input.ts +22 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-target-anchors.ts +78 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +175 -0
- package/src/extensions/pi-agent-text-editor/src/core/structured-result.ts +109 -11
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +0 -75
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +211 -223
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +9 -6
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +5 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -7
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +8 -8
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-write.ts +8 -3
- package/src/pi-agent-ide.ts +0 -6
- package/src/plugins/pi-agent-ide-ast/package.json +15 -10
- package/src/plugins/pi-agent-ide-ast/src/ast/constructs.ts +193 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/element-extent.ts +59 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +5 -1
- package/src/plugins/pi-agent-ide-ast/src/ast/selection.ts +204 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +2 -0
- package/src/plugins/pi-agent-ide-ast/src/extension.ts +4 -2
- package/src/plugins/pi-agent-ide-ast/src/geometry-selection.ts +184 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +107 -21
- package/src/plugins/pi-agent-ide-ast/src/select-presentation.ts +104 -0
- package/src/plugins/pi-agent-ide-ast/src/select-schema.ts +384 -0
- package/src/plugins/pi-agent-ide-ast/src/selection-region.ts +41 -0
- package/src/plugins/pi-agent-ide-ast/src/source-text.ts +92 -0
- package/src/plugins/pi-agent-ide-ast/src/text-selection.ts +214 -0
- package/src/plugins/pi-agent-ide-ast/src/tool-select.ts +251 -0
- package/src/plugins/pi-agent-ide-changes/index.ts +2 -18
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/src/tool-index-change.ts +2 -2
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +11 -40
- 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 +2 -2
- package/src/plugins/pi-agent-ide-lsp/package.json +9 -9
- package/src/plugins/pi-agent-ide-lsp/src/lsp/client.ts +5 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/manager.ts +8 -2
- package/src/plugins/pi-agent-ide-lsp/src/lsp/project.ts +19 -0
- package/src/plugins/pi-agent-ide-lsp/src/lsp/symbol-search.ts +204 -118
- package/src/plugins/pi-agent-ide-lsp/src/rename-plan.ts +2 -17
- package/src/plugins/pi-agent-ide-lsp/src/search-resolver.ts +88 -45
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +10 -36
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +1 -1
- package/src/plugins/pi-agent-ide-vision/index.ts +19 -0
- package/dist/chunk-2P2OGO3G.js +0 -2
- package/dist/chunk-6EYWFBNG.js +0 -0
- package/dist/chunk-7AVXUV4A.js +0 -7
- package/dist/chunk-7WCZOO5I.js +0 -1
- package/dist/chunk-BAYETTZZ.js +0 -16
- package/dist/chunk-BVK5A7ED.js +0 -28
- package/dist/chunk-F7NVAC4Q.js +0 -0
- package/dist/chunk-FZBCKIJJ.js +0 -1
- package/dist/chunk-I5JLCFUX.js +0 -1
- package/dist/chunk-MIZAFRDR.js +0 -1
- package/dist/chunk-PJPA5EEE.js +0 -2
- package/dist/chunk-PXWDDBBC.js +0 -0
- package/dist/chunk-TQZBVOTT.js +0 -5
- package/dist/chunk-VWW3RLUX.js +0 -12
- package/dist/chunk-YHUTTZC6.js +0 -2
- package/dist/chunk-ZODCBFBL.js +0 -2
- package/dist/entry-87.js +0 -1
- package/docs/agent-guides/apply.md +0 -333
- package/node_modules/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
- package/node_modules/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/node_modules/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/node_modules/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/node_modules/pi-agent-text-editor/src/core/apply/results.ts +0 -137
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/node_modules/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-82.js +0 -1
- package/node_modules/pi-agent-web-text/runtime/entry-87.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-87.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-83.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-80.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-78.js +0 -2
- package/src/extensions/pi-agent-text-editor/src/api/apply-renderer.ts +0 -3
- package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +0 -159
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +0 -405
- package/src/extensions/pi-agent-text-editor/src/core/apply/final-mutations.ts +0 -50
- package/src/extensions/pi-agent-text-editor/src/core/apply/format-source.ts +0 -11
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +0 -203
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +0 -55
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +0 -276
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +0 -13
- package/src/extensions/pi-agent-text-editor/src/core/apply/queue.ts +0 -25
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +0 -405
- package/src/extensions/pi-agent-text-editor/src/core/apply/results.ts +0 -137
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +0 -369
- package/src/extensions/pi-agent-text-editor/src/core/apply/structured-result.ts +0 -251
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +0 -168
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +0 -942
- /package/node_modules/{pi-agent-text-editor → pi-agent-text-editor-renderer}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
- /package/node_modules/{pi-agent-tool-call-interception → pi-agent-tool-ui}/runtime/entry-81.js +0 -0
- /package/node_modules/{pi-agent-web → pi-agent-web-html}/runtime/entry-83.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-html → pi-agent-web-image}/runtime/entry-84.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-pdf}/runtime/entry-85.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-text}/runtime/entry-86.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-renderer → pi-agent-text-editor-stale-anchor}/runtime/entry-79.js +0 -0
|
@@ -11,6 +11,7 @@ import { getLastResolvedResource } from "#src/api/last-resolved-resource.js";
|
|
|
11
11
|
import { isMutationAnchorValue } from "#src/api/mutation-tool.js";
|
|
12
12
|
import type { FileMutationBatchResult, FileMutationResult } from "#src/api/mutation-result.js";
|
|
13
13
|
import type { TextBatchEntry } from "./text-edit-batch.js";
|
|
14
|
+
import type { TextEditCompletion } from "#src/api/edit-completion.js";
|
|
14
15
|
import type { TextEditorCore, TextResourceEditRequest } from "./text-editor-core.js";
|
|
15
16
|
import { BatchExecutionJournal } from "./text-edit-batch-execution.js";
|
|
16
17
|
import {
|
|
@@ -25,10 +26,16 @@ import { Type } from "typebox";
|
|
|
25
26
|
import {
|
|
26
27
|
ResourceScheduler,
|
|
27
28
|
resourceAccesses,
|
|
29
|
+
connectResultTargets,
|
|
28
30
|
resultError,
|
|
29
31
|
withStructuredResult,
|
|
32
|
+
type ResultTargetStore,
|
|
30
33
|
type StructuredResult,
|
|
31
34
|
} from "pi-agent-resource";
|
|
35
|
+
import { createPostEditScope } from "./post-edit-scope.js";
|
|
36
|
+
import { committedMutationTargets } from "./mutation-result-targets.js";
|
|
37
|
+
import { FileMutationResult as MutationPresentation } from "./mutation-result/file-mutation-result.js";
|
|
38
|
+
import { isFormattingContribution, isDiffStatusContribution } from "#src/api/post-edit.js";
|
|
32
39
|
import { captureScriptMutation } from "./text-mutation.js";
|
|
33
40
|
import {
|
|
34
41
|
NATIVE_EDIT_BATCH_EVENT,
|
|
@@ -61,8 +68,11 @@ interface ScriptBatch {
|
|
|
61
68
|
readonly context: ExtensionContext;
|
|
62
69
|
readonly summaries: BatchSummary[];
|
|
63
70
|
readonly results: FileMutationResult[];
|
|
71
|
+
readonly presentations: NativeEditBatchEvent[];
|
|
64
72
|
readonly errors: string[];
|
|
65
73
|
readonly cancellation: AbortController;
|
|
74
|
+
readonly targets: Map<string, string>;
|
|
75
|
+
readonly postEdits: ReturnType<typeof createPostEditScope>;
|
|
66
76
|
tail: Promise<void>;
|
|
67
77
|
readonly scheduler: ResourceScheduler;
|
|
68
78
|
readonly callOrder: Map<string, number>;
|
|
@@ -156,11 +166,14 @@ function isBatchable(
|
|
|
156
166
|
class NativeTextEditBatchCoordinator {
|
|
157
167
|
private readonly scripts = new Map<string, ScriptBatch>();
|
|
158
168
|
private readonly invocations = new Map<string, ScriptBatch>();
|
|
169
|
+
private readonly scopedInvocations = new Map<string, ScriptBatch>();
|
|
170
|
+
private readonly resultTargets: ResultTargetStore;
|
|
159
171
|
|
|
160
172
|
constructor(
|
|
161
173
|
private readonly core: TextEditorCore,
|
|
162
174
|
private readonly pi: ExtensionAPI,
|
|
163
175
|
) {
|
|
176
|
+
this.resultTargets = connectResultTargets(pi);
|
|
164
177
|
pi.registerTool({
|
|
165
178
|
name: "flush",
|
|
166
179
|
exposure: "codemode",
|
|
@@ -227,9 +240,12 @@ class NativeTextEditBatchCoordinator {
|
|
|
227
240
|
summaries: [],
|
|
228
241
|
reports: [],
|
|
229
242
|
reportCursor: 0,
|
|
243
|
+
presentations: [],
|
|
230
244
|
results: [],
|
|
231
245
|
errors: [],
|
|
232
246
|
cancellation: new AbortController(),
|
|
247
|
+
targets: new Map(),
|
|
248
|
+
postEdits: createPostEditScope(context.cwd),
|
|
233
249
|
tail: Promise.resolve(),
|
|
234
250
|
scheduler: new ResourceScheduler(),
|
|
235
251
|
callOrder: new Map(),
|
|
@@ -248,6 +264,7 @@ class NativeTextEditBatchCoordinator {
|
|
|
248
264
|
const registration = this.core
|
|
249
265
|
.getMutationTools()
|
|
250
266
|
.find((tool) => tool.name === event.toolName);
|
|
267
|
+
if (registration) this.scopedInvocations.set(event.toolCallId, script);
|
|
251
268
|
const input: Record<string, unknown> = event.input;
|
|
252
269
|
let ownsSource = false;
|
|
253
270
|
if (registration && !isWholeFileInvocation(registration.wholeFileOperation, input)) {
|
|
@@ -258,6 +275,14 @@ class NativeTextEditBatchCoordinator {
|
|
|
258
275
|
for (const descriptor of [registration.source, ...(registration.source.targets ?? [])]) {
|
|
259
276
|
const value = input[descriptor.field];
|
|
260
277
|
if (typeof value === "string" && value.length > 0) {
|
|
278
|
+
if (
|
|
279
|
+
["replace", "write", "copy", "move", "delete", "undo"].includes(registration.name) &&
|
|
280
|
+
value.startsWith("RESULT#")
|
|
281
|
+
) {
|
|
282
|
+
// The executor validates result handles and returns a structured rejection.
|
|
283
|
+
ownsSource = true;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
261
286
|
const result = await this.core.textTargetResolver().tryResolve(value, resolverContext);
|
|
262
287
|
if (result.kind !== "not-handled") ownsSource = true;
|
|
263
288
|
}
|
|
@@ -295,6 +320,7 @@ class NativeTextEditBatchCoordinator {
|
|
|
295
320
|
});
|
|
296
321
|
pi.on("tool_result", async (event) => {
|
|
297
322
|
this.invocations.delete(event.toolCallId);
|
|
323
|
+
this.scopedInvocations.delete(event.toolCallId);
|
|
298
324
|
const script = this.scripts.get(event.toolCallId);
|
|
299
325
|
if (!script) return;
|
|
300
326
|
script.closed = true;
|
|
@@ -334,11 +360,77 @@ class NativeTextEditBatchCoordinator {
|
|
|
334
360
|
},
|
|
335
361
|
});
|
|
336
362
|
script.errors.push(error.message);
|
|
363
|
+
for (const entry of script.pending.entries) {
|
|
364
|
+
const target = script.targets.get(entry.callId);
|
|
365
|
+
if (target) this.resultTargets.reject(target, error.message);
|
|
366
|
+
}
|
|
337
367
|
script.pending = pendingBatch();
|
|
338
368
|
}
|
|
339
369
|
} else await this.commit(script);
|
|
370
|
+
try {
|
|
371
|
+
await this.core.enqueueFileOperation(
|
|
372
|
+
() =>
|
|
373
|
+
script.postEdits.finish((outcome) => {
|
|
374
|
+
const index = script.results.findLastIndex(
|
|
375
|
+
(item) => item.data.path === outcome.after.source,
|
|
376
|
+
);
|
|
377
|
+
if (index < 0) return;
|
|
378
|
+
const previous = requiredValue(script.results[index]).data;
|
|
379
|
+
const updated = new MutationPresentation({
|
|
380
|
+
...previous,
|
|
381
|
+
afterContent: outcome.after.content,
|
|
382
|
+
afterDocument: outcome.after,
|
|
383
|
+
formatting: outcome.postEditContributions
|
|
384
|
+
.map((item) => item.data)
|
|
385
|
+
.findLast(isFormattingContribution)?.formatting ?? { status: "not-reported" },
|
|
386
|
+
diffStatuses: outcome.postEditContributions
|
|
387
|
+
.map((item) => item.data)
|
|
388
|
+
.filter(isDiffStatusContribution)
|
|
389
|
+
.flatMap((item) => item.diffStatuses),
|
|
390
|
+
});
|
|
391
|
+
const previousResult = requiredValue(script.results[index]);
|
|
392
|
+
script.results[index] = updated;
|
|
393
|
+
for (const [slot, presentation] of script.presentations.entries()) {
|
|
394
|
+
const results = presentation.result.details.results;
|
|
395
|
+
if (!results?.includes(previousResult)) continue;
|
|
396
|
+
script.presentations[slot] = {
|
|
397
|
+
...presentation,
|
|
398
|
+
result: {
|
|
399
|
+
...presentation.result,
|
|
400
|
+
details: {
|
|
401
|
+
...presentation.result.details,
|
|
402
|
+
results: results.map((result) =>
|
|
403
|
+
result === previousResult ? updated : result,
|
|
404
|
+
),
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
}),
|
|
410
|
+
undefined,
|
|
411
|
+
{ cwd: script.context.cwd, sources: script.postEdits.sources() },
|
|
412
|
+
);
|
|
413
|
+
} catch (error) {
|
|
414
|
+
script.errors.push(error instanceof Error ? error.message : String(error));
|
|
415
|
+
}
|
|
416
|
+
// Nested panels are frozen on message_end. Publish final snapshots before history is saved.
|
|
417
|
+
for (const presentation of script.presentations) {
|
|
418
|
+
const results = presentation.result.details.results ?? [];
|
|
419
|
+
this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, {
|
|
420
|
+
...presentation,
|
|
421
|
+
result: {
|
|
422
|
+
...presentation.result,
|
|
423
|
+
content: [new FileMutationAgentResult(results).toTextContent()],
|
|
424
|
+
},
|
|
425
|
+
} satisfies NativeEditBatchEvent);
|
|
426
|
+
}
|
|
340
427
|
this.scripts.delete(event.toolCallId);
|
|
341
|
-
if (
|
|
428
|
+
if (
|
|
429
|
+
script.results.length === 0 &&
|
|
430
|
+
script.summaries.length === 0 &&
|
|
431
|
+
script.errors.length === 0
|
|
432
|
+
)
|
|
433
|
+
return;
|
|
342
434
|
const failed = script.errors.length > 0;
|
|
343
435
|
const content = event.content.map((block) =>
|
|
344
436
|
failed && block.type === "text"
|
|
@@ -373,11 +465,25 @@ class NativeTextEditBatchCoordinator {
|
|
|
373
465
|
}
|
|
374
466
|
this.scripts.clear();
|
|
375
467
|
this.invocations.clear();
|
|
468
|
+
this.scopedInvocations.clear();
|
|
376
469
|
};
|
|
377
470
|
pi.on("agent_end", clear);
|
|
378
471
|
pi.on("session_shutdown", clear);
|
|
379
472
|
}
|
|
380
473
|
|
|
474
|
+
/** Keep every mutation in the script's shared post-edit scope, including non-batched calls. */
|
|
475
|
+
runPostEdits<T>(id: string, work: () => T): T {
|
|
476
|
+
const script = this.scopedInvocations.get(id);
|
|
477
|
+
return script ? script.postEdits.run(work) : work();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** Include non-batched mutations in the script's final post-edit presentation. */
|
|
481
|
+
recordMutation(id: string, result: AgentToolResult<FileMutationBatchResult>): void {
|
|
482
|
+
const script = this.scopedInvocations.get(id);
|
|
483
|
+
if (!script || !result.details.results?.some((item) => item.data.ok === true)) return;
|
|
484
|
+
script.results.push(...result.details.results);
|
|
485
|
+
script.presentations.push({ parentToolCallId: script.id, calls: [id], result });
|
|
486
|
+
}
|
|
381
487
|
execute(
|
|
382
488
|
id: string,
|
|
383
489
|
registration: AnyTextMutationToolRegistration,
|
|
@@ -498,11 +604,16 @@ class NativeTextEditBatchCoordinator {
|
|
|
498
604
|
mutations: [...batch.plan.mutations, ...planning.plan.mutations].sort(order),
|
|
499
605
|
failures: [...batch.plan.failures, ...planning.plan.failures],
|
|
500
606
|
};
|
|
607
|
+
const target = ["replace", "insert", "write", "copy", "move"].includes(registration.name)
|
|
608
|
+
? this.resultTargets.reserve(context.cwd)
|
|
609
|
+
: undefined;
|
|
610
|
+
if (target) script.targets.set(id, target);
|
|
501
611
|
const details = {
|
|
502
612
|
results: [],
|
|
503
613
|
source: entry.path,
|
|
504
614
|
resolvedBy: preview.resources.find((resource) => resource.path === entry.path)?.resolvedBy,
|
|
505
615
|
nativeEditBatch: { parentToolCallId: script.id, state: "accepted" },
|
|
616
|
+
...(target ? { metadata: { resultTarget: target } } : {}),
|
|
506
617
|
};
|
|
507
618
|
return {
|
|
508
619
|
content: [
|
|
@@ -515,6 +626,51 @@ class NativeTextEditBatchCoordinator {
|
|
|
515
626
|
};
|
|
516
627
|
}
|
|
517
628
|
|
|
629
|
+
private async settleTargets(
|
|
630
|
+
script: ScriptBatch,
|
|
631
|
+
batch: PendingBatch,
|
|
632
|
+
journal: BatchExecutionJournal,
|
|
633
|
+
completions: readonly TextEditCompletion[],
|
|
634
|
+
signal: AbortSignal,
|
|
635
|
+
): Promise<void> {
|
|
636
|
+
let mapped: ReturnType<typeof committedMutationTargets>;
|
|
637
|
+
try {
|
|
638
|
+
mapped = committedMutationTargets(
|
|
639
|
+
batch.plan.mutations.map(({ callId, mutation }) => ({ callId, edits: mutation.edits })),
|
|
640
|
+
completions,
|
|
641
|
+
);
|
|
642
|
+
} catch (error) {
|
|
643
|
+
for (const entry of batch.entries) {
|
|
644
|
+
const target = script.targets.get(entry.callId);
|
|
645
|
+
if (target)
|
|
646
|
+
this.resultTargets.reject(target, error instanceof Error ? error.message : String(error));
|
|
647
|
+
}
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const calls = journal.snapshot();
|
|
651
|
+
for (const entry of batch.entries) {
|
|
652
|
+
const reference = script.targets.get(entry.callId);
|
|
653
|
+
if (!reference) continue;
|
|
654
|
+
const targets = mapped.get(entry.callId);
|
|
655
|
+
if (calls.find((call) => call.callId === entry.callId)?.state !== "completed" || !targets) {
|
|
656
|
+
this.resultTargets.reject(
|
|
657
|
+
reference,
|
|
658
|
+
"This operation did not produce confirmed filesystem targets.",
|
|
659
|
+
);
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
try {
|
|
663
|
+
await this.resultTargets.verify({ targets, complete: true }, signal);
|
|
664
|
+
this.resultTargets.confirm(reference, targets, script.context.cwd);
|
|
665
|
+
} catch (error) {
|
|
666
|
+
this.resultTargets.reject(
|
|
667
|
+
reference,
|
|
668
|
+
error instanceof Error ? error.message : String(error),
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
518
674
|
private async commit(script: ScriptBatch): Promise<boolean> {
|
|
519
675
|
const batch = script.pending;
|
|
520
676
|
if (batch.entries.length === 0) return true;
|
|
@@ -543,9 +699,13 @@ class NativeTextEditBatchCoordinator {
|
|
|
543
699
|
...operations.flatMap((operation) => {
|
|
544
700
|
const entry = requiredValue(batch.entries.find((entry) => entry.callId === operation.id));
|
|
545
701
|
const registration = requiredValue(registrations.get(entry.op));
|
|
702
|
+
const mutation = batch.plan.mutations.find(
|
|
703
|
+
(item) => item.callId === operation.id,
|
|
704
|
+
)?.mutation;
|
|
546
705
|
return [...mutationSources(registration, entry).values()].map((source) => ({
|
|
547
706
|
source,
|
|
548
|
-
effect:
|
|
707
|
+
effect:
|
|
708
|
+
mutation?.edits.has(source) === false ? ("not-applied" as const) : operation.effect,
|
|
549
709
|
}));
|
|
550
710
|
}),
|
|
551
711
|
...observedSources.map((source) => ({ source, effect: "applied" as const })),
|
|
@@ -587,34 +747,40 @@ class NativeTextEditBatchCoordinator {
|
|
|
587
747
|
};
|
|
588
748
|
try {
|
|
589
749
|
signal.throwIfAborted();
|
|
590
|
-
const captured = await
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
750
|
+
const captured = await script.postEdits.run(() =>
|
|
751
|
+
captureScriptMutation(this.core, () =>
|
|
752
|
+
executeRegisteredTextBatch(
|
|
753
|
+
this.core,
|
|
754
|
+
registrations,
|
|
755
|
+
{
|
|
756
|
+
edits: batch.entries,
|
|
757
|
+
expectedContent: batch.snapshots,
|
|
758
|
+
expectedExistence: batch.existence,
|
|
759
|
+
},
|
|
760
|
+
signal,
|
|
761
|
+
undefined,
|
|
762
|
+
script.context,
|
|
763
|
+
journal.reporter(),
|
|
764
|
+
() => {},
|
|
765
|
+
batch.plan,
|
|
766
|
+
),
|
|
605
767
|
),
|
|
606
768
|
);
|
|
607
769
|
observedSources = captured.completions.map((completion) => completion.resourceSource);
|
|
608
770
|
if (captured.kind === "failed") throw captured.error;
|
|
609
771
|
script.results.push(...(captured.value.details.results ?? []));
|
|
610
|
-
this.
|
|
772
|
+
await this.settleTargets(script, batch, journal, captured.completions, signal);
|
|
773
|
+
const presentation = {
|
|
611
774
|
parentToolCallId: script.id,
|
|
612
775
|
calls: batch.entries.map((entry) => entry.callId),
|
|
613
776
|
result: captured.value,
|
|
614
|
-
} satisfies NativeEditBatchEvent
|
|
777
|
+
} satisfies NativeEditBatchEvent;
|
|
778
|
+
script.presentations.push(presentation);
|
|
779
|
+
this.pi.events.emit(NATIVE_EDIT_BATCH_EVENT, presentation);
|
|
615
780
|
return record(mutationOutcome(captured.value, "flush", captured.completions));
|
|
616
781
|
} catch (error) {
|
|
617
782
|
journal.markRunningUnknown(error);
|
|
783
|
+
await this.settleTargets(script, batch, journal, [], signal);
|
|
618
784
|
return record({ status: "error", errors: [resultError(error)] });
|
|
619
785
|
}
|
|
620
786
|
}
|
|
@@ -622,6 +788,20 @@ class NativeTextEditBatchCoordinator {
|
|
|
622
788
|
|
|
623
789
|
const coordinators = new WeakMap<TextEditorCore, NativeTextEditBatchCoordinator>();
|
|
624
790
|
|
|
791
|
+
/** Run immediate mutation paths under the same deferred post-edit boundary as native batches. */
|
|
792
|
+
export function runNativePostEditScope<T>(core: TextEditorCore, id: string, work: () => T): T {
|
|
793
|
+
const coordinator = coordinators.get(core);
|
|
794
|
+
return coordinator ? coordinator.runPostEdits(id, work) : work();
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/** Retain immediate child results so final formatting is visible on the parent script. */
|
|
798
|
+
export function recordNativeTextMutation(
|
|
799
|
+
core: TextEditorCore,
|
|
800
|
+
id: string,
|
|
801
|
+
result: AgentToolResult<FileMutationBatchResult>,
|
|
802
|
+
): void {
|
|
803
|
+
coordinators.get(core)?.recordMutation(id, result);
|
|
804
|
+
}
|
|
625
805
|
/** Attach accumulating editor batches to native Codemode's public parent/child lifecycle. */
|
|
626
806
|
export function registerNativeTextEditBatching(pi: ExtensionAPI, core: TextEditorCore): void {
|
|
627
807
|
coordinators.set(core, new NativeTextEditBatchCoordinator(core, pi));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ResolvedResultTargets } from "pi-agent-resource";
|
|
2
|
+
import { TextChangeDocument } from "./text-change-engine.js";
|
|
3
|
+
|
|
4
|
+
/** Require a verified selection of one complete file before a whole-file operation. */
|
|
5
|
+
export function wholeFileResultSource(result: ResolvedResultTargets): string {
|
|
6
|
+
const target = result.targets[0];
|
|
7
|
+
const range = target?.ranges[0];
|
|
8
|
+
if (result.targets.length !== 1 || target?.ranges.length !== 1 || range === undefined)
|
|
9
|
+
throw new Error("This operation requires one whole-file result target.");
|
|
10
|
+
const document = new TextChangeDocument(target.expectedContent);
|
|
11
|
+
const selected = document.range(
|
|
12
|
+
range.start.lineNumber,
|
|
13
|
+
range.start.column,
|
|
14
|
+
range.end.lineNumber,
|
|
15
|
+
range.end.column,
|
|
16
|
+
);
|
|
17
|
+
if (selected.from !== 0 || selected.to !== document.length)
|
|
18
|
+
throw new Error(
|
|
19
|
+
"This operation requires one whole-file result target; partial scopes are not widened.",
|
|
20
|
+
);
|
|
21
|
+
return target.source;
|
|
22
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ResultTargetStore } from "pi-agent-resource";
|
|
2
|
+
import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
|
|
3
|
+
import {
|
|
4
|
+
TEXT_SEARCH_ANCHOR_KIND,
|
|
5
|
+
type TextAnchorResolverRegistration,
|
|
6
|
+
} from "#src/api/plugin-protocol.js";
|
|
7
|
+
|
|
8
|
+
/** Resolve registered snapshot targets through the editor's normal source and anchor guards. */
|
|
9
|
+
export function createResultTargetAnchors(
|
|
10
|
+
store: ResultTargetStore,
|
|
11
|
+
): TextAnchorResolverRegistration {
|
|
12
|
+
return {
|
|
13
|
+
kind: TEXT_SEARCH_ANCHOR_KIND,
|
|
14
|
+
type: "auxiliary",
|
|
15
|
+
describeInPrompt: false,
|
|
16
|
+
resolver: {
|
|
17
|
+
id: "result-targets",
|
|
18
|
+
description: "Use returned RESULT# references to target exact source snapshots.",
|
|
19
|
+
renderFull: (value) => value,
|
|
20
|
+
renderCompact: () => "result targets",
|
|
21
|
+
async tryResolve(value, context) {
|
|
22
|
+
if (!value.startsWith("RESULT#")) return { kind: "not-handled" };
|
|
23
|
+
try {
|
|
24
|
+
const target = store
|
|
25
|
+
.resolve(value, context.cwd)
|
|
26
|
+
.targets.find((target) => target.source === context.source);
|
|
27
|
+
if (target === undefined)
|
|
28
|
+
return {
|
|
29
|
+
kind: "rejected",
|
|
30
|
+
rejection: { code: "missing", reason: "Result does not select this source." },
|
|
31
|
+
};
|
|
32
|
+
if (target.expectedContent !== context.content)
|
|
33
|
+
return {
|
|
34
|
+
kind: "rejected",
|
|
35
|
+
rejection: { code: "stale", reason: "Result target is stale; repeat Read/Search." },
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
kind: "resolved",
|
|
39
|
+
anchor: new TextSelectionAnchor(value, target.source, target.ranges),
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return {
|
|
43
|
+
kind: "rejected",
|
|
44
|
+
rejection: {
|
|
45
|
+
code: "invalid",
|
|
46
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
resources: {
|
|
53
|
+
id: "result-target-sources",
|
|
54
|
+
async tryResolve(value, context) {
|
|
55
|
+
if (!value.startsWith("RESULT#")) return { kind: "not-handled" };
|
|
56
|
+
try {
|
|
57
|
+
const selected = store.resolve(value, context.cwd);
|
|
58
|
+
await store.verify(selected, context.signal);
|
|
59
|
+
return selected.targets.length === 0
|
|
60
|
+
? {
|
|
61
|
+
kind: "rejected",
|
|
62
|
+
rejection: { code: "missing", reason: "Empty result target set." },
|
|
63
|
+
}
|
|
64
|
+
: { kind: "resolved", targets: selected.targets };
|
|
65
|
+
} catch (error) {
|
|
66
|
+
context.signal?.throwIfAborted();
|
|
67
|
+
return {
|
|
68
|
+
kind: "rejected",
|
|
69
|
+
rejection: {
|
|
70
|
+
code: "stale",
|
|
71
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { ResolvedResultTargets, ResultTargetStore } from "pi-agent-resource";
|
|
2
|
+
import type {
|
|
3
|
+
TextMutation,
|
|
4
|
+
TextMutationContext,
|
|
5
|
+
TextMutationEdit,
|
|
6
|
+
} from "#src/api/mutation-tool.js";
|
|
7
|
+
import type { TextChange } from "./text-change-engine.js";
|
|
8
|
+
import {
|
|
9
|
+
anchorSpanRange,
|
|
10
|
+
insertionAfterAnchor,
|
|
11
|
+
replaceAnchorSpan,
|
|
12
|
+
} from "#src/tools/text-selection.js";
|
|
13
|
+
import { wholeFileResultSource } from "./result-input.js";
|
|
14
|
+
|
|
15
|
+
/** Distinguish structured source authority from ordinary paths and legacy anchors. */
|
|
16
|
+
export function isResultInput(value: unknown): boolean {
|
|
17
|
+
return value !== undefined && (typeof value !== "string" || value.startsWith("RESULT#"));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface TransferSpan {
|
|
21
|
+
readonly source: string;
|
|
22
|
+
readonly from: number;
|
|
23
|
+
readonly to: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface PreparedTransfer {
|
|
27
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
28
|
+
readonly empty: boolean;
|
|
29
|
+
readonly verifyFileSource?: () => Promise<void>;
|
|
30
|
+
readonly mutate?: (context: TextMutationContext) => Promise<TextMutation>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Resolve ordered pairs once; execute them inside the editor's existing guarded snapshots. */
|
|
34
|
+
export async function prepareResultTransfer(
|
|
35
|
+
operation: "copy" | "move",
|
|
36
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
37
|
+
store: ResultTargetStore,
|
|
38
|
+
cwd: string,
|
|
39
|
+
signal?: AbortSignal,
|
|
40
|
+
): Promise<PreparedTransfer> {
|
|
41
|
+
const input = { ...parameters };
|
|
42
|
+
const resolve = async (field: "path" | "target", start: string, end: string) => {
|
|
43
|
+
if (!isResultInput(input[field])) return undefined;
|
|
44
|
+
if (input[start] !== undefined || input[end] !== undefined)
|
|
45
|
+
throw new Error(`Do not combine structured ${field} with ${start}/${end}.`);
|
|
46
|
+
const selected = store.resolveOrdered(input[field], cwd);
|
|
47
|
+
if (!selected.complete)
|
|
48
|
+
throw new Error(
|
|
49
|
+
"Incomplete result targets cannot establish a complete transfer; repeat Search.",
|
|
50
|
+
);
|
|
51
|
+
await store.verify(selected, signal);
|
|
52
|
+
input[field] = store.register(selected.targets, cwd);
|
|
53
|
+
return selected;
|
|
54
|
+
};
|
|
55
|
+
const source = await resolve("path", "start", "end");
|
|
56
|
+
const destination = await resolve("target", "targetStart", "targetEnd");
|
|
57
|
+
if (source === undefined && destination === undefined) return { input, empty: false };
|
|
58
|
+
if (
|
|
59
|
+
source !== undefined &&
|
|
60
|
+
destination === undefined &&
|
|
61
|
+
input.targetStart === undefined &&
|
|
62
|
+
input.targetEnd === undefined
|
|
63
|
+
) {
|
|
64
|
+
// A structured source may use the byte-preserving file operation only when it really selects a whole file.
|
|
65
|
+
input.path = wholeFileResultSource(store.resolve(parameters.path, cwd));
|
|
66
|
+
return { input, empty: false, verifyFileSource: () => store.verify(source, signal) };
|
|
67
|
+
}
|
|
68
|
+
if (
|
|
69
|
+
source !== undefined &&
|
|
70
|
+
destination !== undefined &&
|
|
71
|
+
source.targets.length !== destination.targets.length
|
|
72
|
+
)
|
|
73
|
+
throw new Error(
|
|
74
|
+
"Transfer source and destination selection counts must match; no broadcast or concatenation.",
|
|
75
|
+
);
|
|
76
|
+
const empty = source?.targets.length === 0 || destination?.targets.length === 0;
|
|
77
|
+
return {
|
|
78
|
+
input,
|
|
79
|
+
empty,
|
|
80
|
+
async mutate(context) {
|
|
81
|
+
const spans = (selected: ResolvedResultTargets): TransferSpan[] =>
|
|
82
|
+
selected.targets.map((target) => {
|
|
83
|
+
const document = context.documentFor(target.source);
|
|
84
|
+
if (document.content !== target.expectedContent)
|
|
85
|
+
throw new Error("Transfer result target is stale; repeat Read/Search.");
|
|
86
|
+
const range = target.ranges[0];
|
|
87
|
+
if (range === undefined) throw new Error("Transfer selection has no range.");
|
|
88
|
+
return {
|
|
89
|
+
source: target.source,
|
|
90
|
+
...document.range(
|
|
91
|
+
range.start.lineNumber,
|
|
92
|
+
range.start.column,
|
|
93
|
+
range.end.lineNumber,
|
|
94
|
+
range.end.column,
|
|
95
|
+
),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
const sources =
|
|
99
|
+
source === undefined
|
|
100
|
+
? [
|
|
101
|
+
input.start === undefined
|
|
102
|
+
? { source: context.sourceFor("path"), from: 0, to: context.sourceDocument.length }
|
|
103
|
+
: anchorSpanRange(
|
|
104
|
+
context,
|
|
105
|
+
await context.resolveAnchors("start"),
|
|
106
|
+
input.end === undefined ? undefined : await context.resolveAnchors("end"),
|
|
107
|
+
"start",
|
|
108
|
+
"end",
|
|
109
|
+
),
|
|
110
|
+
]
|
|
111
|
+
: spans(source);
|
|
112
|
+
const destinations = destination === undefined ? undefined : spans(destination);
|
|
113
|
+
if (sources.length !== (destinations?.length ?? 1))
|
|
114
|
+
throw new Error(
|
|
115
|
+
"Transfer source and destination selection counts must match; no broadcast or concatenation.",
|
|
116
|
+
);
|
|
117
|
+
const edits = new Map<string, TextMutationEdit>();
|
|
118
|
+
const append = (span: TransferSpan, change: TextChange, producesTarget: boolean) => {
|
|
119
|
+
const edit = edits.get(span.source);
|
|
120
|
+
const changes = [...(edit?.changes ?? []), change];
|
|
121
|
+
const resultChanges = [
|
|
122
|
+
...(edit?.resultChanges ?? []),
|
|
123
|
+
...(producesTarget ? [changes.length - 1] : []),
|
|
124
|
+
];
|
|
125
|
+
edits.set(span.source, { action: "edited", changes, resultChanges });
|
|
126
|
+
};
|
|
127
|
+
const planned: { target: TransferSpan; change: TextChange }[] = [];
|
|
128
|
+
for (const [index, span] of sources.entries()) {
|
|
129
|
+
const copied = context.documentFor(span.source).text(span);
|
|
130
|
+
const destinationSpan = destinations?.[index];
|
|
131
|
+
if (destinationSpan !== undefined) {
|
|
132
|
+
planned.push({
|
|
133
|
+
target: destinationSpan,
|
|
134
|
+
change: { from: destinationSpan.from, to: destinationSpan.to, insert: copied },
|
|
135
|
+
});
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const starts = await context.resolveAnchors("targetStart");
|
|
139
|
+
if (input.targetEnd === undefined) {
|
|
140
|
+
const [target, change] = insertionAfterAnchor(context, starts, "targetStart", copied);
|
|
141
|
+
planned.push({
|
|
142
|
+
target: { source: target, from: change.from, to: change.to },
|
|
143
|
+
change,
|
|
144
|
+
});
|
|
145
|
+
} else {
|
|
146
|
+
const target = anchorSpanRange(
|
|
147
|
+
context,
|
|
148
|
+
starts,
|
|
149
|
+
await context.resolveAnchors("targetEnd"),
|
|
150
|
+
"targetStart",
|
|
151
|
+
"targetEnd",
|
|
152
|
+
);
|
|
153
|
+
planned.push({
|
|
154
|
+
target,
|
|
155
|
+
change: replaceAnchorSpan(context, target, copied),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (operation === "move") {
|
|
160
|
+
for (const sourceSpan of sources)
|
|
161
|
+
for (const transfer of planned)
|
|
162
|
+
if (
|
|
163
|
+
sourceSpan.source === transfer.target.source &&
|
|
164
|
+
sourceSpan.from <= transfer.target.to &&
|
|
165
|
+
transfer.target.from <= sourceSpan.to
|
|
166
|
+
)
|
|
167
|
+
throw new Error("Move target must not overlap or touch any source range.");
|
|
168
|
+
for (const span of sources)
|
|
169
|
+
append(span, { from: span.from, to: span.to, insert: "" }, false);
|
|
170
|
+
}
|
|
171
|
+
for (const transfer of planned) append(transfer.target, transfer.change, true);
|
|
172
|
+
return { edits };
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|