pi-agent-ide 0.5.1 → 0.6.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 +42 -0
- package/README.md +10 -4
- package/dist/chunk-22CLOM2D.js +1 -0
- package/dist/{chunk-LY6U5EAD.js → chunk-2527OQ4Y.js} +1 -1
- package/dist/chunk-3XJ3KDPZ.js +16 -0
- package/dist/chunk-5JELU6RV.js +7 -0
- package/dist/chunk-DDKHZZDO.js +5 -0
- package/dist/chunk-FEDVTZJG.js +1 -0
- package/dist/chunk-HSM6R7IB.js +27 -0
- package/dist/chunk-K5G4FDXD.js +1 -0
- package/dist/chunk-M5IVSCR2.js +1 -0
- package/dist/chunk-OYWIZII6.js +1 -0
- package/dist/{chunk-7ALCBKCW.js → chunk-PCZH7GOX.js} +11 -11
- package/dist/{chunk-DQXPQOF7.js → chunk-SQ7ZTGOP.js} +1 -1
- package/dist/entry-10.js +1 -1
- package/dist/entry-11.js +1 -1
- package/dist/entry-12.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-16.js +1 -0
- package/dist/entry-18.js +1 -1
- package/dist/entry-19.js +1 -1
- package/dist/entry-20.js +1 -1
- package/dist/entry-21.js +1 -1
- package/dist/entry-22.js +1 -2
- package/dist/entry-23.js +2 -1
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +1 -12
- package/dist/entry-28.js +12 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +1 -1
- package/dist/entry-32.js +1 -4
- package/dist/entry-33.js +3 -8
- package/dist/entry-34.js +9 -1
- package/dist/entry-35.js +1 -1
- package/dist/entry-36.js +1 -1
- package/dist/entry-37.js +1 -1
- package/dist/entry-38.js +1 -1
- package/dist/entry-39.js +1 -1
- package/dist/entry-40.js +1 -1
- package/dist/entry-41.js +1 -18
- package/dist/entry-42.js +18 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +1 -1
- package/dist/entry-46.js +1 -7
- package/dist/entry-47.js +7 -11
- package/dist/entry-48.js +11 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-55.js +1 -1
- package/dist/entry-56.js +1 -0
- package/dist/entry-57.js +0 -1
- package/dist/entry-58.js +1 -0
- package/dist/entry-59.js +0 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-63.js +1 -1
- package/dist/entry-64.js +1 -1
- package/dist/entry-65.js +1 -0
- package/dist/entry-66.js +0 -1
- package/dist/entry-67.js +1 -0
- package/dist/entry-68.js +0 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -1
- package/dist/entry-71.js +1 -203
- package/dist/entry-72.js +254 -25
- package/dist/entry-73.js +30 -2
- package/dist/entry-74.js +2 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +1 -3
- package/dist/entry-77.js +3 -3
- package/dist/entry-78.js +3 -1
- package/dist/entry-79.js +1 -1
- package/dist/entry-80.js +1 -1
- package/dist/entry-81.js +1 -0
- package/dist/pi-agent-ide.js +3 -3
- package/docs/configuration.md +3 -1
- package/docs/tools.md +12 -0
- package/node_modules/pi-agent-doctor/package.json +6 -6
- package/node_modules/pi-agent-doctor/runtime/entry-22.js +1 -0
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +4 -4
- package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
- package/node_modules/pi-agent-filesystem-text/package.json +4 -4
- package/node_modules/pi-agent-filesystem-text/runtime/entry-26.js +2 -0
- package/node_modules/pi-agent-ide-ast/package.json +12 -11
- package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +0 -1
- package/node_modules/pi-agent-ide-ast/runtime/entry-28.js +2 -0
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +8 -6
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/runtime/entry-29.js +0 -1
- package/node_modules/pi-agent-ide-formatter/package.json +4 -4
- package/node_modules/pi-agent-ide-languages/package.json +3 -3
- package/node_modules/pi-agent-ide-lint/package.json +8 -8
- package/node_modules/pi-agent-ide-lint/src/command-linter.ts +3 -1
- package/node_modules/pi-agent-ide-lsp/package.json +10 -10
- package/node_modules/pi-agent-ide-lsp/runtime/entry-34.js +2 -0
- package/node_modules/pi-agent-image/package.json +3 -3
- package/node_modules/pi-agent-invariant/package.json +2 -2
- package/node_modules/pi-agent-pdf/package.json +3 -3
- package/node_modules/pi-agent-read/package.json +11 -11
- package/node_modules/pi-agent-read/runtime/entry-41.js +0 -1
- package/node_modules/pi-agent-read/runtime/entry-42.js +2 -0
- package/node_modules/pi-agent-read/src/api/read-parameters.ts +2 -2
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +11 -6
- package/node_modules/pi-agent-resource/package.json +2 -2
- package/node_modules/pi-agent-search/package.json +7 -7
- package/node_modules/pi-agent-search/runtime/entry-46.js +0 -1
- package/node_modules/pi-agent-search-text/package.json +9 -9
- package/node_modules/pi-agent-search-text/runtime/entry-48.js +1 -0
- package/node_modules/pi-agent-text/package.json +3 -3
- package/node_modules/pi-agent-text/runtime/entry-50.js +1 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-51.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/index.ts +3 -3
- package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +0 -1
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-53.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/src/config.ts +2 -2
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-55.js +2 -0
- package/node_modules/pi-agent-text-editor/package.json +25 -25
- package/node_modules/pi-agent-text-editor/runtime/entry-71.js +0 -1
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +125 -3
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +14 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +32 -3
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +21 -19
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +37 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +85 -34
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +2 -3
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +589 -241
- package/node_modules/pi-agent-text-editor/src/core/post-edit-scope.ts +5 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-config.ts +3 -3
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +9 -1
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +53 -0
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +11 -41
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +8 -18
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +11 -41
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -19
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-74.js +2 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-76.js +1 -0
- package/node_modules/pi-agent-web/package.json +7 -7
- 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/node_modules/pi-agent-web-text/runtime/entry-81.js +2 -0
- package/package.json +43 -38
- package/src/api/path-identity.ts +15 -0
- package/src/composite/builtin-extensions.ts +7 -2
- package/src/composite/module-labels.ts +4 -0
- package/src/composite/module-settings.ts +34 -14
- package/src/composite/preferences.ts +46 -3
- package/src/composite/selection.ts +5 -1
- package/src/doctor/inventory.ts +7 -2
- 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 +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-26.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-23.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-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/plugins/pi-agent-web-text/runtime/entry-81.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-77.js +2 -0
- package/src/extensions/pi-agent-read/package.json +11 -11
- package/src/extensions/pi-agent-read/runtime/entry-41.js +0 -1
- package/src/extensions/pi-agent-read/runtime/entry-42.js +2 -0
- package/src/extensions/pi-agent-read/src/api/read-parameters.ts +2 -2
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +11 -6
- package/src/extensions/pi-agent-search/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-49.js +1 -0
- package/src/extensions/pi-agent-search/runtime/entry-46.js +0 -1
- package/src/extensions/pi-agent-search/runtime/entry-47.js +2 -0
- package/src/extensions/pi-agent-text-editor/package.json +25 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-51.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/index.ts +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-53.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/src/config.ts +2 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-55.js +2 -0
- 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-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-74.js +2 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-72.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +125 -3
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +14 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +32 -3
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +21 -19
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +37 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +85 -34
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +2 -3
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +589 -241
- package/src/extensions/pi-agent-text-editor/src/core/post-edit-scope.ts +5 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-config.ts +3 -3
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +9 -1
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +53 -0
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +11 -41
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +8 -18
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +11 -41
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-replace.ts +9 -19
- package/src/pi-agent-ide.ts +15 -2
- package/src/plugins/pi-agent-ide-ast/package.json +12 -11
- package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-28.js +2 -0
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +8 -6
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/runtime/entry-29.js +0 -1
- package/src/plugins/pi-agent-ide-debugger/index.ts +2 -8
- package/src/plugins/pi-agent-ide-debugger/src/adapter-executables.ts +31 -0
- package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +3 -1
- package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +24 -23
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +5 -2
- package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +55 -17
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +55 -22
- package/src/plugins/pi-agent-ide-formatter/package.json +4 -4
- package/src/plugins/pi-agent-ide-languages/package.json +3 -3
- package/src/plugins/pi-agent-ide-lint/package.json +8 -8
- package/src/plugins/pi-agent-ide-lint/src/command-linter.ts +3 -1
- package/src/plugins/pi-agent-ide-lsp/package.json +10 -10
- package/src/plugins/pi-agent-ide-lsp/runtime/entry-34.js +2 -0
- package/src/plugins/pi-agent-ide-processes/src/registry.ts +4 -0
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +18 -9
- package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +1 -0
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +1 -0
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +2 -2
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +1 -0
- package/src/plugins/pi-agent-ide-vision/index.ts +232 -0
- package/src/plugins/pi-agent-ide-vision/src/vision.ts +530 -0
- package/src/plugins/pi-agent-ide-vision/src/windows-display-capture.ps1 +30 -0
- package/src/plugins/pi-agent-ide-vision/src/windows-window-capture.ps1 +33 -0
- package/dist/chunk-5PLV4HLG.js +0 -1
- package/dist/chunk-G725MARR.js +0 -16
- package/dist/chunk-HKXDP2FD.js +0 -7
- package/dist/chunk-IRECDTJG.js +0 -27
- package/dist/chunk-J4RTW44E.js +0 -1
- package/dist/chunk-NZYDMBM6.js +0 -1
- package/dist/chunk-WGGIQ7IJ.js +0 -1
- package/dist/entry-17.js +0 -1
- package/node_modules/pi-agent-doctor/runtime/entry-17.js +0 -1
- package/node_modules/pi-agent-filesystem/runtime/entry-22.js +0 -2
- package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- package/node_modules/pi-agent-image/runtime/entry-34.js +0 -1
- package/node_modules/pi-agent-resource/runtime/entry-42.js +0 -1
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-50.js +0 -2
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
- package/node_modules/pi-agent-text-editor/runtime/entry-55.js +0 -1
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-74.js +0 -1
- package/node_modules/pi-agent-web/runtime/entry-76.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-23.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-77.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +0 -2
- package/src/extensions/pi-agent-read/runtime/entry-37.js +0 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +0 -2
- package/src/extensions/pi-agent-search/runtime/entry-43.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-50.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-72.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-55.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-23.js +0 -0
- /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-24.js +0 -0
- /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-25.js +0 -0
- /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-30.js +0 -0
- /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-31.js +0 -0
- /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-32.js +0 -0
- /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-33.js +0 -0
- /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-35.js +0 -0
- /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-36.js +0 -0
- /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-37.js +0 -0
- /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-43.js +0 -0
- /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-47.js +0 -0
- /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-49.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-72.js +0 -0
- /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-73.js +0 -0
- /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-75.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-77.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-79.js +0 -0
- /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-80.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-24.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-25.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-78.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-80.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-73.js +0 -0
- /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-30.js +0 -0
- /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-31.js +0 -0
- /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-32.js +0 -0
- /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-33.js +0 -0
|
@@ -10,7 +10,11 @@ import { Value } from "typebox/value";
|
|
|
10
10
|
import type { TextEditorCore } from "#src/core/text-editor-core.js";
|
|
11
11
|
import { ApplyResults } from "#src/core/apply/results.js";
|
|
12
12
|
import { serializeApplyError, type ApplyRuntimeHost } from "#src/core/apply/runtime.js";
|
|
13
|
-
import { executeEditorTransaction } from "#src/core/apply/transaction.js";
|
|
13
|
+
import { executeEditorTransaction, type EditorSnapshot } from "#src/core/apply/transaction.js";
|
|
14
|
+
import { TextSelectionAnchor } from "#src/api/text-selection-anchor.js";
|
|
15
|
+
import { TextAnchorResolutionError } from "#src/core/text-anchor-registry.js";
|
|
16
|
+
import { buildFailedTextMutationResult } from "#src/core/text-mutation.js";
|
|
17
|
+
import { TextMutationAnchorResolutionError } from "#src/core/text-mutation-anchor-error.js";
|
|
14
18
|
|
|
15
19
|
/** Configured IDE services and ordinary tool schemas, shared with the standalone tools. */
|
|
16
20
|
export interface ApplyServices {
|
|
@@ -41,6 +45,91 @@ export function createApplyExecution(
|
|
|
41
45
|
? "read"
|
|
42
46
|
: "mutation";
|
|
43
47
|
let recorded = false;
|
|
48
|
+
const resolveMutationTarget = async (): Promise<unknown> => {
|
|
49
|
+
const request = arguments_ as {
|
|
50
|
+
snapshot?: { id?: unknown; source?: unknown; content?: unknown };
|
|
51
|
+
query?: unknown;
|
|
52
|
+
};
|
|
53
|
+
const snapshot = request.snapshot;
|
|
54
|
+
const content = snapshot?.content;
|
|
55
|
+
if (
|
|
56
|
+
snapshot === undefined ||
|
|
57
|
+
typeof snapshot.id !== "string" ||
|
|
58
|
+
typeof snapshot.source !== "string" ||
|
|
59
|
+
typeof content !== "string" ||
|
|
60
|
+
typeof request.query !== "string"
|
|
61
|
+
)
|
|
62
|
+
throw failure("INVALID_ARGUMENTS", "Invalid mutation-target resolution request");
|
|
63
|
+
let anchor;
|
|
64
|
+
try {
|
|
65
|
+
anchor = await services.editor.resolveAnchorInText({
|
|
66
|
+
source: snapshot.source,
|
|
67
|
+
content,
|
|
68
|
+
value: request.query,
|
|
69
|
+
cwd: context.cwd,
|
|
70
|
+
signal,
|
|
71
|
+
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (!(error instanceof TextAnchorResolutionError)) throw error;
|
|
74
|
+
const cause = new TextMutationAnchorResolutionError(
|
|
75
|
+
"apply",
|
|
76
|
+
"target",
|
|
77
|
+
snapshot.source,
|
|
78
|
+
request.query,
|
|
79
|
+
error,
|
|
80
|
+
);
|
|
81
|
+
const presentation = await buildFailedTextMutationResult(
|
|
82
|
+
services.editor,
|
|
83
|
+
{ code: "RESOLVE_FAILED", source: snapshot.source, message: error.message, cause },
|
|
84
|
+
{ ...context, signal },
|
|
85
|
+
);
|
|
86
|
+
return {
|
|
87
|
+
selections: [],
|
|
88
|
+
warning: {
|
|
89
|
+
code: "EMPTY_SELECTION",
|
|
90
|
+
message: presentation.content
|
|
91
|
+
.filter((block) => block.type === "text")
|
|
92
|
+
.map((block) => block.text)
|
|
93
|
+
.join("\n"),
|
|
94
|
+
presentation: {
|
|
95
|
+
anchorRecoveries: presentation.details.anchorRecoveries,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const starts = lineStarts(content);
|
|
101
|
+
if (!TextSelectionAnchor.is(anchor)) {
|
|
102
|
+
const from = starts[anchor.lineNumber - 1];
|
|
103
|
+
if (from === undefined)
|
|
104
|
+
throw failure("INVALID_SELECTION", "Anchor line is outside the opened snapshot");
|
|
105
|
+
const to = starts[anchor.lineNumber] ?? content.length;
|
|
106
|
+
return {
|
|
107
|
+
selections: [
|
|
108
|
+
{
|
|
109
|
+
document: snapshot.id,
|
|
110
|
+
from,
|
|
111
|
+
to,
|
|
112
|
+
text: content.slice(from, to),
|
|
113
|
+
linewise: true,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
selections: anchor.ranges.map((range) => {
|
|
120
|
+
const from = positionOffset(starts, range.start.lineNumber, range.start.column);
|
|
121
|
+
const to = positionOffset(starts, range.end.lineNumber, range.end.column);
|
|
122
|
+
return {
|
|
123
|
+
document: snapshot.id,
|
|
124
|
+
from,
|
|
125
|
+
to,
|
|
126
|
+
text: content.slice(from, to),
|
|
127
|
+
...(range.linewise === true && { linewise: true }),
|
|
128
|
+
};
|
|
129
|
+
}),
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
if (tool === "editorResolve") return await resolveMutationTarget();
|
|
44
133
|
try {
|
|
45
134
|
if (tool === "editorApply") {
|
|
46
135
|
let value;
|
|
@@ -61,13 +150,36 @@ export function createApplyExecution(
|
|
|
61
150
|
if (typeof source === "string") scope.forget(source);
|
|
62
151
|
throw error;
|
|
63
152
|
}
|
|
64
|
-
|
|
153
|
+
const requestedSnapshots =
|
|
154
|
+
(arguments_ as { snapshots?: readonly EditorSnapshot[] }).snapshots ?? [];
|
|
155
|
+
const refreshed = await Promise.all(
|
|
156
|
+
requestedSnapshots.map(async (snapshot) => {
|
|
157
|
+
const outcome = await services.read.read(
|
|
158
|
+
{ path: snapshot.source },
|
|
159
|
+
{ cwd: context.cwd, signal },
|
|
160
|
+
"script",
|
|
161
|
+
);
|
|
162
|
+
const script = outcome.script;
|
|
163
|
+
return !outcome.isError &&
|
|
164
|
+
script?.kind === "text" &&
|
|
165
|
+
typeof script.content === "string"
|
|
166
|
+
? {
|
|
167
|
+
id: snapshot.id,
|
|
168
|
+
source: outcome.details.source ?? script.source,
|
|
169
|
+
content: script.content,
|
|
170
|
+
lines: script.lines,
|
|
171
|
+
}
|
|
172
|
+
: { id: snapshot.id, unavailable: true };
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
const response = { ...value, snapshots: refreshed };
|
|
176
|
+
results.record(id, "mutation", response);
|
|
65
177
|
recorded = true;
|
|
66
178
|
for (const file of value.files) {
|
|
67
179
|
results.updateFile(file.source, file.before, file.after);
|
|
68
180
|
lastSource = file.source;
|
|
69
181
|
}
|
|
70
|
-
return
|
|
182
|
+
return response;
|
|
71
183
|
}
|
|
72
184
|
if (tool === "editorOpen") {
|
|
73
185
|
if (!Value.Check(readParameters, arguments_))
|
|
@@ -199,6 +311,16 @@ export function createApplyExecution(
|
|
|
199
311
|
};
|
|
200
312
|
}
|
|
201
313
|
|
|
314
|
+
function lineStarts(content: string): number[] {
|
|
315
|
+
const starts = [0];
|
|
316
|
+
for (let index = 0; index < content.length; index += 1)
|
|
317
|
+
if (content[index] === "\n") starts.push(index + 1);
|
|
318
|
+
return starts;
|
|
319
|
+
}
|
|
320
|
+
function positionOffset(starts: readonly number[], line: number, column: number): number {
|
|
321
|
+
return (starts[line - 1] ?? 0) + column;
|
|
322
|
+
}
|
|
323
|
+
|
|
202
324
|
function failure(code: string, message: string, details?: unknown): Error {
|
|
203
325
|
return Object.assign(new Error(message), { code, details });
|
|
204
326
|
}
|
|
@@ -28,6 +28,20 @@ export interface ScriptMutationOutcome {
|
|
|
28
28
|
readonly effect: "not-applied" | "applied" | "unknown";
|
|
29
29
|
readonly files: readonly ScriptMutationFile[];
|
|
30
30
|
readonly completed: readonly string[];
|
|
31
|
+
/** Per-operation outcomes in staging order for Apply transactions. */
|
|
32
|
+
readonly operations?: readonly {
|
|
33
|
+
readonly index: number;
|
|
34
|
+
readonly kind: string;
|
|
35
|
+
readonly status: "applied" | "warning" | "failed" | "unknown" | "blocked";
|
|
36
|
+
readonly effect: "not-applied" | "applied" | "unknown";
|
|
37
|
+
readonly resources: readonly string[];
|
|
38
|
+
readonly error?: { readonly code: string; readonly message: string };
|
|
39
|
+
readonly warning?: {
|
|
40
|
+
readonly code: string;
|
|
41
|
+
readonly message: string;
|
|
42
|
+
readonly presentation?: unknown;
|
|
43
|
+
};
|
|
44
|
+
}[];
|
|
31
45
|
/** Session-scoped receipt accepted by undo. */
|
|
32
46
|
readonly transaction?: string;
|
|
33
47
|
readonly recoveries?: readonly ScriptAnchorRecovery[];
|
|
@@ -42,6 +42,7 @@ export async function renderApplyOutput(
|
|
|
42
42
|
for (const operation of selected.automatic) {
|
|
43
43
|
if (
|
|
44
44
|
operation.kind === "read" ||
|
|
45
|
+
hasOperationWarnings(operation.value) ||
|
|
45
46
|
isFailure(operation.value) ||
|
|
46
47
|
(operation.value !== null &&
|
|
47
48
|
typeof operation.value === "object" &&
|
|
@@ -140,6 +141,18 @@ function expandReadSection(section: {
|
|
|
140
141
|
? resources.flatMap((read) => expandReadSection({ content: read.content, read }))
|
|
141
142
|
: [section];
|
|
142
143
|
}
|
|
144
|
+
function hasOperationWarnings(value: unknown): boolean {
|
|
145
|
+
return (
|
|
146
|
+
value !== null &&
|
|
147
|
+
typeof value === "object" &&
|
|
148
|
+
"operations" in value &&
|
|
149
|
+
Array.isArray(value.operations) &&
|
|
150
|
+
(value.operations as unknown[]).some(
|
|
151
|
+
(item) =>
|
|
152
|
+
item !== null && typeof item === "object" && "status" in item && item.status === "warning",
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
143
156
|
function isFailure(value: unknown): boolean {
|
|
144
157
|
return value !== null && typeof value === "object" && "ok" in value && value.ok === false;
|
|
145
158
|
}
|
|
@@ -153,7 +166,7 @@ function formatApplyFailure(code: string, message: string): string {
|
|
|
153
166
|
NOT_FOUND:
|
|
154
167
|
"The requested text or selection was not found. Read the current file and select existing text.",
|
|
155
168
|
AMBIGUOUS_MATCH:
|
|
156
|
-
"The selection matched more than once. Use a larger unique fragment or
|
|
169
|
+
"The selection matched more than once. Use a larger unique fragment or a current candidate anchor.",
|
|
157
170
|
STALE_EDITOR:
|
|
158
171
|
"This editor handle was already committed. Open the file again before staging more changes.",
|
|
159
172
|
STALE_SELECTION:
|
|
@@ -190,12 +203,14 @@ function renderValue(value: unknown): Content {
|
|
|
190
203
|
typeof value.operation === "string"
|
|
191
204
|
) {
|
|
192
205
|
const lines = [
|
|
193
|
-
`${value.operation}: ${"effect" in value ? String(value.effect) : isFailure(value) ? "failed" : "completed"}`,
|
|
206
|
+
`${value.operation}: ${isFailure(value) && "effect" in value && value.effect === "applied" ? "partially applied" : "effect" in value ? String(value.effect) : isFailure(value) ? "failed" : "completed"}`,
|
|
194
207
|
];
|
|
195
208
|
if ("path" in value && typeof value.path === "string") lines.push(value.path);
|
|
196
209
|
if ("target" in value && typeof value.target === "string")
|
|
197
210
|
lines.push(`Target: ${value.target}`);
|
|
198
|
-
if ("
|
|
211
|
+
if ("operations" in value && Array.isArray(value.operations))
|
|
212
|
+
lines.push(...value.operations.map(formatOperationOutcome));
|
|
213
|
+
else if ("errors" in value && Array.isArray(value.errors))
|
|
199
214
|
lines.push(...value.errors.map(formatReceiptError));
|
|
200
215
|
if ("error" in value) lines.push(formatReceiptError(value.error));
|
|
201
216
|
if (
|
|
@@ -236,6 +251,20 @@ function asReadResult(value: unknown): ReadToolResult | undefined {
|
|
|
236
251
|
return { content: renderValue(value), details: value as ReadResultDetails };
|
|
237
252
|
}
|
|
238
253
|
|
|
254
|
+
function formatOperationOutcome(value: unknown): string {
|
|
255
|
+
if (value === null || typeof value !== "object") return String(value);
|
|
256
|
+
const index = "index" in value ? Number(value.index) + 1 : "?";
|
|
257
|
+
const kind = "kind" in value ? String(value.kind) : "operation";
|
|
258
|
+
const status = "status" in value ? String(value.status) : "unknown";
|
|
259
|
+
const detail =
|
|
260
|
+
"warning" in value
|
|
261
|
+
? ` — ${formatReceiptError(value.warning)}`
|
|
262
|
+
: "error" in value
|
|
263
|
+
? ` — ${formatReceiptError(value.error)}`
|
|
264
|
+
: "";
|
|
265
|
+
return `${index}. ${kind}: ${status}${detail}`;
|
|
266
|
+
}
|
|
267
|
+
|
|
239
268
|
function formatReceiptError(value: unknown): string {
|
|
240
269
|
if (value === null || typeof value !== "object") return String(value);
|
|
241
270
|
const source = "source" in value ? String(value.source) : undefined;
|
|
@@ -8,40 +8,42 @@ result(value)
|
|
|
8
8
|
Transactional editor:
|
|
9
9
|
const file = open(path | {path, views?})
|
|
10
10
|
file.source; file.content; file.lines
|
|
11
|
-
file.find(text) //
|
|
12
|
-
file.
|
|
13
|
-
file.
|
|
14
|
-
file.
|
|
15
|
-
file.
|
|
16
|
-
file.
|
|
17
|
-
file.
|
|
18
|
-
file.
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
file.find(text) // immutable SelectionSet with every exact match, including zero
|
|
12
|
+
file.select(searchMatch) // one-range SelectionSet
|
|
13
|
+
file.between(start, end, {inside?: boolean}) // every sequential non-overlapping pair
|
|
14
|
+
file.line(first, last?) // one-range SelectionSet
|
|
15
|
+
file.replace(textOrSet, replacement)
|
|
16
|
+
file.remove(textOrSet)
|
|
17
|
+
file.insertBefore(textOrSet, text)
|
|
18
|
+
file.insertAfter(textOrSet, text)
|
|
19
|
+
copy(sourceSet, destinationSet)
|
|
20
|
+
move(sourceSet, destinationSet)
|
|
21
21
|
createFile(path, content)
|
|
22
22
|
deleteFile(path)
|
|
23
23
|
copyFile(path, target, {overwrite?: boolean})
|
|
24
24
|
moveFile(path, target, {overwrite?: boolean})
|
|
25
|
-
|
|
25
|
+
flush()
|
|
26
26
|
|
|
27
|
-
open() returns an immutable snapshot. Selection
|
|
27
|
+
open() returns an immutable snapshot. Selection helpers return immutable snapshot-bound SelectionSets. find() returns zero or more ranges; an empty result is not an error. Mutation methods accept a direct string or SelectionSet and stage one operation for every selected range. A direct string uses every configured in-document resolver in standalone order: structured anchors first, then exact text fallback. Resolver rejection does not fall through to literal text. Position-only anchors select their natural whole line. An empty set stages a non-applying warning; exact-query provenance can include fuzzy recovery candidates and fresh line anchors. Recovery never applies a guessed edit.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
All selections in one transaction refer to the current opened snapshots, so earlier staged edits never shift later selections. After each checkpoint, opened file handles refresh to actual post-outcome contents and lines; SelectionSets created before that checkpoint become stale. copy() and move() concatenate source ranges in document order and replicate that payload at every destination range. move() stages destination effects before source removals. Whole-file copyFile() and moveFile() remain separate.
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Pending operations commit once when the JavaScript completes normally. If the script throws, pending operations do not commit. Use flush() as an optional mid-script checkpoint. Operations run in staging order: the first valid overlapping operation wins, and later conflicts fail without undoing independent work. Check every per-operation outcome and retry only failed or blocked work. When a checkpoint changes a file, it creates one session-scoped APPLY# receipt. Explicit flush() returns it; automatic finalization reports it in the tool result. Pass the receipt to undo({ transaction: "APPLY#..." }) before any successfully changed path changes to restore all successful effects. After flush(), reuse the same opened handles and create fresh SelectionSets. Every checkpoint clears all staged operations, including failed operations and warnings. With no pending mutations, completion creates no transaction or receipt.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
Before each operation the host verifies snapshots, resource types, ranges, overlaps, source existence, and destination conflicts. A failed operation changes nothing when rollback completes. If rollback is incomplete, its effect is unknown and later dependent operations are blocked. Do not describe an unknown effect as success.
|
|
34
|
+
|
|
35
|
+
Use find() for all exact occurrences, between() for sequential delimited ranges, select() for search results, and line() only when line identity is part of the task. Use direct strings when a configured anchor or unique exact-text fallback should select one target within the opened snapshot. Generate replacement text with ordinary JavaScript.
|
|
34
36
|
|
|
35
37
|
Example:
|
|
36
38
|
const config = open("src/config.ts");
|
|
37
39
|
const test = open("tests/config.test.ts");
|
|
38
|
-
config.replace(
|
|
39
|
-
test.
|
|
40
|
-
|
|
40
|
+
config.replace("legacyMode", "stableMode");
|
|
41
|
+
test.replace(test.find("legacyMode"), "stableMode");
|
|
42
|
+
// Normal completion commits both staged edits.
|
|
41
43
|
|
|
42
44
|
Read accepts file paths, URLs, temp/search/debug/shell/diagnostics/symbol/graph resources, and supported views. Search accepts literal, regex:, files:, ast:, and symbols: queries. File changes and read-only calls are shown automatically. Use result(value) only to expose additional calculated data; do not call it merely to display committed changes.
|
|
43
45
|
|
|
44
|
-
Do not retry by guessing argument names. Inspect structured error codes such as
|
|
46
|
+
Do not retry by guessing argument names. Inspect structured error codes such as EMPTY_SELECTION, STALE_SNAPSHOT, INVALID_TRANSACTION, and TRANSACTION_FAILED.
|
|
45
47
|
`;
|
|
46
48
|
|
|
47
49
|
/** Agent-facing guide for the guarded Apply editor. */
|
|
@@ -110,6 +110,31 @@ export function createApplyDisplay(
|
|
|
110
110
|
!Array.isArray(value.errors)
|
|
111
111
|
)
|
|
112
112
|
return [];
|
|
113
|
+
if ("operations" in value && Array.isArray(value.operations)) {
|
|
114
|
+
const completed = value.operations.filter(
|
|
115
|
+
(operation: unknown) =>
|
|
116
|
+
operation !== null &&
|
|
117
|
+
typeof operation === "object" &&
|
|
118
|
+
"status" in operation &&
|
|
119
|
+
operation.status === "applied",
|
|
120
|
+
).length;
|
|
121
|
+
if (completed === value.operations.length) return [];
|
|
122
|
+
const outcomes = value.operations
|
|
123
|
+
.filter(
|
|
124
|
+
(operation: unknown) =>
|
|
125
|
+
operation !== null &&
|
|
126
|
+
typeof operation === "object" &&
|
|
127
|
+
"status" in operation &&
|
|
128
|
+
operation.status !== "applied",
|
|
129
|
+
)
|
|
130
|
+
.map((operation: unknown) => ({ text: formatDisplayOutcome(operation) }));
|
|
131
|
+
return [
|
|
132
|
+
{
|
|
133
|
+
text: `Apply partially applied: ${completed} of ${value.operations.length} operations completed.`,
|
|
134
|
+
},
|
|
135
|
+
...outcomes,
|
|
136
|
+
];
|
|
137
|
+
}
|
|
113
138
|
return value.errors.flatMap((error: unknown) =>
|
|
114
139
|
error !== null &&
|
|
115
140
|
typeof error === "object" &&
|
|
@@ -329,6 +354,18 @@ export function createApplyResultRenderer(
|
|
|
329
354
|
};
|
|
330
355
|
}
|
|
331
356
|
|
|
357
|
+
function formatDisplayOutcome(value: unknown): string {
|
|
358
|
+
if (value === null || typeof value !== "object") return String(value);
|
|
359
|
+
const index = "index" in value ? Number(value.index) + 1 : "?";
|
|
360
|
+
const kind = "kind" in value ? String(value.kind) : "operation";
|
|
361
|
+
const status = "status" in value ? String(value.status) : "unknown";
|
|
362
|
+
const error =
|
|
363
|
+
"error" in value && value.error !== null && typeof value.error === "object"
|
|
364
|
+
? `: ${"code" in value.error ? String(value.error.code) : "ERROR"}: ${"message" in value.error ? String(value.error.message) : "Operation failed"}`
|
|
365
|
+
: "";
|
|
366
|
+
return `Operation ${index} (${kind}): ${status}${error}`;
|
|
367
|
+
}
|
|
368
|
+
|
|
332
369
|
function redactApplyReceipts(text: string): string {
|
|
333
370
|
if (/^(?:Undo transaction:|Undo available)/u.test(text.trim())) return "";
|
|
334
371
|
try {
|
|
@@ -7,6 +7,7 @@ export const defaultApplyOperations = [
|
|
|
7
7
|
"search",
|
|
8
8
|
"diff",
|
|
9
9
|
"editorOpen",
|
|
10
|
+
"editorResolve",
|
|
10
11
|
"editorApply",
|
|
11
12
|
] as const;
|
|
12
13
|
export type ApplyOperation = (typeof defaultApplyOperations)[number];
|
|
@@ -77,7 +78,7 @@ export async function executeApplySource(
|
|
|
77
78
|
},
|
|
78
79
|
});
|
|
79
80
|
await runner.run({
|
|
80
|
-
source: `${guestBindings(enabledOperations)}\n${source}\n__finishApplyScript();`,
|
|
81
|
+
source: `${guestBindings(enabledOperations)}\nawait (async () => {\n${source}\n})();\n__finishApplyScript();`,
|
|
81
82
|
abortSignal: signal,
|
|
82
83
|
limits: { ...limits, timeoutMs: limits?.timeoutMs ?? APPLY_EXECUTION_TIMEOUT_MS },
|
|
83
84
|
});
|
|
@@ -118,7 +119,7 @@ function guestBindings(enabledOperations: readonly ApplyOperation[]): string {
|
|
|
118
119
|
const readOperations = enabledOperations.filter(
|
|
119
120
|
(name) => name === "read" || name === "search" || name === "diff",
|
|
120
121
|
);
|
|
121
|
-
return `const { ${readOperations.join(", ")}, open, createFile, deleteFile, copyFile, moveFile,
|
|
122
|
+
return `const { ${readOperations.join(", ")}, open, createFile, deleteFile, copyFile, moveFile, copy, move, flush, result, __finishApplyScript } = (() => {
|
|
122
123
|
const origins = new WeakMap();
|
|
123
124
|
const invoke = (name, args) => {
|
|
124
125
|
const response = __apply[name](args);
|
|
@@ -126,40 +127,75 @@ function guestBindings(enabledOperations: readonly ApplyOperation[]): string {
|
|
|
126
127
|
if (response.value !== null && typeof response.value === "object") origins.set(response.value, response.id);
|
|
127
128
|
return response.value;
|
|
128
129
|
};
|
|
129
|
-
let generation = 0;
|
|
130
130
|
let snapshots = new Map();
|
|
131
131
|
let operations = [];
|
|
132
132
|
const assertCurrent = (document) => {
|
|
133
|
-
if (document.
|
|
133
|
+
if (!snapshots.has(document.id)) throw Object.assign(new Error("Editor handle belongs to an unavailable snapshot"), {code: "STALE_EDITOR"});
|
|
134
|
+
};
|
|
135
|
+
const selection = (document, from, to, linewise = false) => Object.freeze({document: document.id, from, to, text: document.content.slice(from, to), ...(linewise && {linewise: true})});
|
|
136
|
+
const selectionSet = (document, ranges, provenance) => {
|
|
137
|
+
const set = ranges.map(({from, to, linewise}) => selection(document, from, to, linewise === true));
|
|
138
|
+
Object.defineProperties(set, {document: {value: document.id}, generation: {value: document.generation}, provenance: {value: provenance}, text: {value: set.map((item) => item.text).join("")}});
|
|
139
|
+
return Object.freeze(set);
|
|
134
140
|
};
|
|
135
|
-
const selection = (document, from, to) => Object.freeze({document: document.id, from, to, text: document.content.slice(from, to)});
|
|
136
141
|
const occurrences = (content, needle) => {
|
|
137
142
|
if (typeof needle !== "string" || needle.length === 0) throw new Error("Find text must be non-empty");
|
|
138
143
|
const found = [];
|
|
139
144
|
for (let from = content.indexOf(needle); from >= 0; from = content.indexOf(needle, from + needle.length)) found.push(from);
|
|
140
145
|
return found;
|
|
141
146
|
};
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return
|
|
147
|
+
const targetSet = (document, target) => {
|
|
148
|
+
if (typeof target !== "string") return target;
|
|
149
|
+
const resolved = invoke("editorResolve", {snapshot: {id: document.id, source: document.source, content: document.content}, query: target});
|
|
150
|
+
return selectionSet(document, resolved.selections, {kind: "exact", query: target, warning: resolved.warning});
|
|
151
|
+
};
|
|
152
|
+
const stage = (document, target, text, edge) => {
|
|
153
|
+
const selected = targetSet(document, target);
|
|
154
|
+
if (!Array.isArray(selected) || selected.document !== document.id) throw new Error("SelectionSet belongs to another file");
|
|
155
|
+
if (selected.generation !== document.generation) throw Object.assign(new Error("SelectionSet belongs to a stale snapshot"), {code:"STALE_SELECTION"});
|
|
156
|
+
if (selected.length === 0) { operations.push({kind: "warning", document: document.id, query: selected.provenance?.query, warning: selected.provenance?.warning}); return; }
|
|
157
|
+
for (const range of selected) {
|
|
158
|
+
const point = edge === "before" ? range.from : edge === "after" ? range.to : undefined;
|
|
159
|
+
let insert = text;
|
|
160
|
+
if (point !== undefined && range.linewise === true) {
|
|
161
|
+
const ending = /(?:\\r\\n|\\r|\\n)$/u.exec(range.text)?.[0];
|
|
162
|
+
const separator = ending ?? (document.content.includes("\\r\\n") ? "\\r\\n" : "\\n");
|
|
163
|
+
if (edge === "after" && ending === undefined) insert = separator + insert;
|
|
164
|
+
else if (!/(?:\\r\\n|\\r|\\n)$/u.test(insert)) insert += separator;
|
|
165
|
+
}
|
|
166
|
+
operations.push({kind: "replace", selection: point === undefined ? range : selection(document, point, point), text: insert});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const stageTransfer = (kind, source, destination) => {
|
|
170
|
+
for (const set of [source, destination]) {
|
|
171
|
+
const document = snapshots.get(set?.document);
|
|
172
|
+
if (!Array.isArray(set) || document === undefined || set.generation !== document.generation) throw Object.assign(new Error("SelectionSet belongs to a stale or unopened snapshot"), {code:"STALE_SELECTION"});
|
|
173
|
+
}
|
|
174
|
+
const empty = source.length === 0 ? source : destination.length === 0 ? destination : undefined;
|
|
175
|
+
if (empty !== undefined) { operations.push({kind:"warning", document:empty.document, query:empty.provenance?.query, warning:empty.provenance?.warning}); return; }
|
|
176
|
+
operations.push({kind, sources:[...source], destinations:[...destination], text:source.map((item) => item.text).join("")});
|
|
146
177
|
};
|
|
147
178
|
const makeDocument = (snapshot) => {
|
|
148
|
-
const document = {id: snapshot.id, source: snapshot.source, content: snapshot.content, lines: snapshot.lines, generation};
|
|
179
|
+
const document = {id: snapshot.id, source: snapshot.source, content: snapshot.content, lines: snapshot.lines, generation: 0};
|
|
180
|
+
snapshots.set(document.id, document);
|
|
149
181
|
const api = {
|
|
150
|
-
source
|
|
151
|
-
content
|
|
152
|
-
lines
|
|
153
|
-
find: (text) => { assertCurrent(document); return
|
|
154
|
-
findAll: (text) => { assertCurrent(document); return occurrences(document.content, text).map((from) => selection(document, from, from + text.length)); },
|
|
182
|
+
get source() { return document.source; },
|
|
183
|
+
get content() { return document.content; },
|
|
184
|
+
get lines() { return document.lines; },
|
|
185
|
+
find: (text) => { assertCurrent(document); const ranges = occurrences(document.content, text).map((from) => ({from, to: from + text.length})); if (ranges.length > 0) return selectionSet(document, ranges, {kind: "exact", query: text}); const resolved = invoke("editorResolve", {snapshot: {id: document.id, source: document.source, content: document.content}, query: text}); return selectionSet(document, [], {kind: "exact", query: text, warning: resolved.warning}); },
|
|
155
186
|
between: (start, end, options = {}) => {
|
|
156
187
|
assertCurrent(document);
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
188
|
+
const ranges = [];
|
|
189
|
+
let cursor = 0;
|
|
190
|
+
while (cursor <= document.content.length) {
|
|
191
|
+
const from = document.content.indexOf(start, cursor);
|
|
192
|
+
if (from < 0) break;
|
|
193
|
+
const endFrom = document.content.indexOf(end, from + start.length);
|
|
194
|
+
if (endFrom < 0) break;
|
|
195
|
+
ranges.push({from: options.inside === true ? from + start.length : from, to: options.inside === true ? endFrom : endFrom + end.length});
|
|
196
|
+
cursor = endFrom + end.length;
|
|
197
|
+
}
|
|
198
|
+
return selectionSet(document, ranges, {kind: "between", start, end});
|
|
163
199
|
},
|
|
164
200
|
select: (match) => {
|
|
165
201
|
assertCurrent(document);
|
|
@@ -175,7 +211,7 @@ select: (match) => {
|
|
|
175
211
|
const to = starts[endLine - 1] + candidate.endColumn;
|
|
176
212
|
const selected = selection(document, from, to);
|
|
177
213
|
if (typeof candidate.matchedText === "string" && selected.text !== candidate.matchedText) throw Object.assign(new Error("Search match is stale"), {code: "STALE_SELECTION"});
|
|
178
|
-
return selected;
|
|
214
|
+
return selectionSet(document, [selected]);
|
|
179
215
|
},
|
|
180
216
|
line: (first, last = first) => {
|
|
181
217
|
assertCurrent(document);
|
|
@@ -183,29 +219,44 @@ select: (match) => {
|
|
|
183
219
|
const starts = [0];
|
|
184
220
|
for (let index = 0; index < document.content.length; index += 1) if (document.content[index] === "\\n") starts.push(index + 1);
|
|
185
221
|
if (last > starts.length) throw new RangeError("Line range is outside document");
|
|
186
|
-
return
|
|
222
|
+
return selectionSet(document, [{from: starts[first - 1], to: starts[last] === undefined ? document.content.length : starts[last]}]);
|
|
187
223
|
},
|
|
188
|
-
replace: (
|
|
189
|
-
remove: (
|
|
190
|
-
insertBefore: (
|
|
191
|
-
insertAfter: (
|
|
192
|
-
replaceAll: (text, replacement) => { assertCurrent(document); const found = api.findAll(text); if (found.length === 0) throw Object.assign(new Error("No matches"), {code: "NOT_FOUND"}); for (const selected of found) api.replace(selected, replacement); return found.length; },
|
|
224
|
+
replace: (target, text) => { assertCurrent(document); stage(document, target, String(text)); },
|
|
225
|
+
remove: (target) => { assertCurrent(document); stage(document, target, ""); },
|
|
226
|
+
insertBefore: (target, text) => { assertCurrent(document); stage(document, target, String(text), "before"); },
|
|
227
|
+
insertAfter: (target, text) => { assertCurrent(document); stage(document, target, String(text), "after"); },
|
|
193
228
|
};
|
|
194
229
|
return Object.freeze(api);
|
|
195
230
|
};
|
|
196
|
-
|
|
231
|
+
const api = {
|
|
197
232
|
${readOperations.map((name) => `${name}: (args) => invoke(${JSON.stringify(name)}, args)`).join(",\n")},
|
|
198
|
-
open: (path) =>
|
|
233
|
+
open: (path) => makeDocument(invoke("editorOpen", typeof path === "string" ? {path} : path)),
|
|
199
234
|
createFile: (path, content) => operations.push({kind: "create", path, content: String(content)}),
|
|
200
235
|
deleteFile: (path) => operations.push({kind: "delete", path}),
|
|
201
236
|
copyFile: (path, target, options = {}) => operations.push({kind: "copy", path, target, overwrite: options.overwrite === true}),
|
|
202
237
|
moveFile: (path, target, options = {}) => operations.push({kind: "move", path, target, overwrite: options.overwrite === true}),
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
238
|
+
copy: (source, destination) => stageTransfer("text-copy", source, destination),
|
|
239
|
+
move: (source, destination) => stageTransfer("text-move", source, destination),
|
|
240
|
+
flush: () => {
|
|
241
|
+
if (operations.length === 0) return undefined;
|
|
242
|
+
const pending = operations;
|
|
243
|
+
operations = [];
|
|
244
|
+
const value = invoke("editorApply", {snapshots: [...snapshots.values()].map(({id, source, content}) => ({id, source, content})), operations: pending});
|
|
245
|
+
for (const refreshed of value?.snapshots ?? []) {
|
|
246
|
+
const document = snapshots.get(refreshed.id);
|
|
247
|
+
if (document !== undefined && refreshed.unavailable === true) snapshots.delete(refreshed.id);
|
|
248
|
+
else if (document !== undefined) {
|
|
249
|
+
document.source = refreshed.source;
|
|
250
|
+
document.content = refreshed.content;
|
|
251
|
+
document.lines = refreshed.lines;
|
|
252
|
+
document.generation += 1;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return value;
|
|
206
256
|
},
|
|
207
257
|
result: (value) => __apply.result(value, value !== null && typeof value === "object" ? origins.get(value) : undefined),
|
|
208
|
-
__finishApplyScript: () => { if (operations.length > 0)
|
|
258
|
+
__finishApplyScript: () => { if (operations.length > 0) return api.flush(); },
|
|
209
259
|
};
|
|
260
|
+
return api;
|
|
210
261
|
})();`;
|
|
211
262
|
}
|
|
@@ -63,11 +63,10 @@ export async function registerApply(pi: ExtensionAPI, editor: TextEditorCore): P
|
|
|
63
63
|
},
|
|
64
64
|
promptSnippet: "Compose guarded multi-file editor transactions with JavaScript",
|
|
65
65
|
description:
|
|
66
|
-
`Use apply to
|
|
66
|
+
`Use apply to run read-only IDE operations and snapshot-guarded editor transactions in JavaScript. Output has one 2000-line/50KB budget. No shell, imports or resume.` +
|
|
67
67
|
applyHelperGuide(),
|
|
68
68
|
promptGuidelines: [
|
|
69
|
-
"Use Apply for complex, multi-file changes
|
|
70
|
-
"Do not call result() merely to display reads or committed file changes; Apply reports them automatically. Use result(value) only for additional calculated data.",
|
|
69
|
+
"Use Apply for complex, multi-file changes and standalone editor tools for small precise edits.",
|
|
71
70
|
],
|
|
72
71
|
parameters: Type.Object({
|
|
73
72
|
source: Type.String({
|