pi-agent-ide 0.4.0 → 0.5.1
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 +41 -0
- package/README.md +74 -22
- package/assets/gallery/apply-editing.png +0 -0
- package/assets/gallery/debugging.png +0 -0
- package/assets/gallery/read-web.png +0 -0
- package/assets/gallery/search-replace.png +0 -0
- package/assets/gallery/terminal.png +0 -0
- package/assets/gallery/tool-editing.png +0 -0
- package/dist/chunk-25CZ5ZIU.js +3 -0
- package/dist/chunk-526E364R.js +3 -0
- package/dist/chunk-5PLV4HLG.js +1 -0
- package/dist/chunk-5QQABP47.js +14 -0
- package/dist/{chunk-72EEL2DW.js → chunk-6CZO43OH.js} +1 -1
- package/dist/chunk-7ALCBKCW.js +26 -0
- package/dist/chunk-AWXVJ5AC.js +1 -0
- package/dist/{chunk-GFW5QPQV.js → chunk-DQXPQOF7.js} +1 -1
- package/dist/chunk-ESPNEJHK.js +1 -0
- package/dist/chunk-G725MARR.js +16 -0
- package/dist/{chunk-M5L42DWE.js → chunk-HKXDP2FD.js} +2 -2
- package/dist/chunk-IQD6PON5.js +0 -0
- package/dist/chunk-IRECDTJG.js +27 -0
- package/dist/chunk-J4RTW44E.js +1 -0
- package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
- package/dist/{chunk-TI5GMJ7Q.js → chunk-L7JMDDSD.js} +1 -1
- package/dist/{chunk-6DZA4CLO.js → chunk-LY6U5EAD.js} +1 -1
- package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
- package/dist/chunk-NZYDMBM6.js +1 -0
- package/dist/{chunk-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
- package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
- package/dist/chunk-P7XO5CIP.js +2 -0
- package/dist/{chunk-VFBLX4TG.js → chunk-T6LX2RX5.js} +1 -1
- package/dist/{chunk-AADJ2KIB.js → chunk-U22JNO6N.js} +1 -1
- package/dist/chunk-U2JKHKLK.js +0 -0
- package/dist/{chunk-DQF5QMJ2.js → chunk-WGGIQ7IJ.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 -0
- package/dist/entry-17.js +1 -1
- 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 -2
- package/dist/entry-22.js +2 -1
- package/dist/entry-23.js +1 -1
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -12
- package/dist/entry-27.js +12 -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 +1 -4
- package/dist/entry-32.js +3 -8
- package/dist/entry-33.js +9 -1
- package/dist/entry-34.js +1 -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 -18
- package/dist/entry-41.js +18 -1
- package/dist/entry-42.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +1 -7
- package/dist/entry-46.js +7 -11
- package/dist/entry-47.js +11 -1
- package/dist/entry-48.js +1 -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 -0
- package/dist/entry-56.js +0 -1
- package/dist/entry-57.js +1 -0
- package/dist/entry-58.js +0 -1
- package/dist/entry-59.js +1 -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 -0
- package/dist/entry-65.js +0 -1
- package/dist/entry-66.js +1 -0
- package/dist/entry-67.js +0 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -123
- package/dist/entry-71.js +198 -25
- package/dist/entry-72.js +30 -2
- package/dist/entry-73.js +2 -1
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +3 -3
- package/dist/entry-77.js +3 -1
- package/dist/entry-78.js +1 -1
- package/dist/entry-79.js +1 -1
- package/dist/entry-8.js +1 -1
- package/dist/entry-80.js +1 -0
- package/dist/entry-9.js +1 -1
- package/dist/pi-agent-ide.js +3 -3
- package/docs/configuration.md +1 -1
- package/docs/development.md +0 -6
- package/docs/user-hooks.md +68 -0
- package/node_modules/pi-agent-doctor/package.json +6 -6
- package/node_modules/pi-agent-doctor/runtime/entry-21.js +1 -0
- package/node_modules/pi-agent-doctor/src/catalog.ts +9 -1
- package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +5 -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-25.js +2 -0
- package/node_modules/pi-agent-ide-ast/package.json +32 -11
- package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +2 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +16 -8
- package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +22 -17
- package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +4 -1
- package/node_modules/pi-agent-ide-changes/index.ts +3 -1
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
- package/node_modules/pi-agent-ide-formatter/package.json +9 -4
- package/node_modules/pi-agent-ide-languages/package.json +3 -3
- package/node_modules/pi-agent-ide-lint/package.json +13 -8
- package/node_modules/pi-agent-ide-lsp/index.ts +4 -1
- package/node_modules/pi-agent-ide-lsp/package.json +15 -10
- package/node_modules/pi-agent-ide-lsp/runtime/entry-33.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-40.js +0 -1
- package/node_modules/pi-agent-read/runtime/entry-41.js +2 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/rendering.ts +1 -1
- package/node_modules/pi-agent-read/src/api/tools/read.ts +32 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +8 -0
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +105 -5
- 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-45.js +0 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +5 -1
- package/node_modules/pi-agent-search-text/index.ts +1 -1
- package/node_modules/pi-agent-search-text/package.json +9 -9
- package/node_modules/pi-agent-search-text/runtime/entry-47.js +1 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +72 -39
- package/node_modules/pi-agent-search-text/src/search-backend.ts +6 -15
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +80 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +17 -1
- package/node_modules/pi-agent-search-text/src/search-result.ts +32 -12
- package/node_modules/pi-agent-search-text/src/search-session.ts +33 -4
- package/node_modules/pi-agent-text/package.json +3 -3
- package/node_modules/pi-agent-text/runtime/entry-49.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-50.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
- package/node_modules/pi-agent-text-editor/package.json +25 -25
- package/node_modules/pi-agent-text-editor/runtime/entry-70.js +0 -1
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +37 -8
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +3 -2
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
- package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.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-75.js +1 -0
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web/src/resolver.ts +128 -1
- 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-80.js +2 -0
- package/package.json +59 -39
- package/src/api/hooks.ts +168 -0
- package/src/api/text-editor.ts +2 -0
- package/src/composite/builtin-extensions.ts +7 -0
- package/src/composite/module-labels.ts +8 -0
- package/src/composite/preferences.ts +3 -3
- package/src/core/reload-resource-store.ts +34 -0
- package/src/doctor/tip-provider.ts +1 -0
- 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-25.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.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-80.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/src/resolver.ts +128 -1
- package/src/extensions/pi-agent-read/package.json +11 -11
- package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
- package/src/extensions/pi-agent-read/runtime/entry-41.js +2 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/rendering.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +32 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +8 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +105 -5
- package/src/extensions/pi-agent-search/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +1 -0
- 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/src/resolvers.ts +72 -39
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +6 -15
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +80 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +17 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +32 -12
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +33 -4
- package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
- package/src/extensions/pi-agent-search/runtime/entry-46.js +2 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +5 -1
- 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-50.js +2 -0
- 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-51.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
- 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-53.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -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-renderer/src/renderer.ts +59 -0
- 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-73.js +2 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +37 -8
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +3 -2
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
- package/src/plugins/pi-agent-ide-ast/package.json +32 -11
- package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +2 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +16 -8
- package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +22 -17
- package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +4 -1
- package/src/plugins/pi-agent-ide-changes/index.ts +3 -1
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
- package/src/plugins/pi-agent-ide-debugger/index.ts +573 -0
- package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +73 -0
- package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +306 -0
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +338 -0
- package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +349 -0
- package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +39 -0
- package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +152 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +1344 -0
- package/src/plugins/pi-agent-ide-debugger/src/ui.ts +14 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +9 -4
- package/src/plugins/pi-agent-ide-languages/package.json +3 -3
- package/src/plugins/pi-agent-ide-lint/package.json +13 -8
- package/src/plugins/pi-agent-ide-lsp/index.ts +4 -1
- package/src/plugins/pi-agent-ide-lsp/package.json +15 -10
- package/src/plugins/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
- package/src/plugins/pi-agent-ide-processes/index.ts +28 -0
- package/src/plugins/pi-agent-ide-processes/src/registry.ts +83 -0
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +260 -0
- package/src/plugins/pi-agent-ide-terminal/index.ts +19 -13
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +52 -0
- package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +31 -0
- package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +24 -58
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -14
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +32 -2
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +114 -1
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +23 -29
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +14 -1
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +116 -240
- package/dist/chunk-3SE372WC.js +0 -3
- package/dist/chunk-5MSNYFDE.js +0 -1
- package/dist/chunk-7JYQMAEL.js +0 -14
- package/dist/chunk-B5KB2I7J.js +0 -3
- package/dist/chunk-NMFQGKPE.js +0 -2
- package/dist/chunk-OVUYPHDE.js +0 -1
- package/dist/chunk-TPIHQYK2.js +0 -14
- package/dist/chunk-XSTHESNR.js +0 -25
- package/dist/entry-16.js +0 -1
- package/docs/evaluation.md +0 -14
- package/node_modules/pi-agent-doctor/runtime/entry-16.js +0 -1
- package/node_modules/pi-agent-filesystem/runtime/entry-21.js +0 -2
- package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +0 -1
- package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +0 -1
- package/node_modules/pi-agent-image/runtime/entry-33.js +0 -1
- package/node_modules/pi-agent-resource/runtime/entry-41.js +0 -1
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
- package/node_modules/pi-agent-text-editor/runtime/entry-54.js +0 -1
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +0 -1
- package/node_modules/pi-agent-web/runtime/entry-75.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-22.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-21.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +0 -2
- package/src/extensions/pi-agent-read/runtime/entry-36.js +0 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +0 -2
- package/src/extensions/pi-agent-search/runtime/entry-42.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +0 -1
- package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +0 -1
- /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-22.js +0 -0
- /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
- /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
- /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
- /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
- /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
- /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
- /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-34.js +0 -0
- /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-35.js +0 -0
- /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-36.js +0 -0
- /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-42.js +0 -0
- /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-46.js +0 -0
- /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-48.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-71.js +0 -0
- /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
- /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-74.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-76.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
- /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
- /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
- /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
- /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isDiffOutcome, diffPresentation } from "#src/core/diff-tool.js";
|
|
2
2
|
import { createApplySourceProjection, type ApplyCallPreview } from "./mixed-source.js";
|
|
3
3
|
import { isFileOperationResult, formatFileOperation } from "#src/core/file-operations.js";
|
|
4
|
-
import { createReadResultRenderer } from "pi-agent-read/api/rendering";
|
|
4
|
+
import { COMPACT_READ_ROWS, createReadResultRenderer } from "pi-agent-read/api/rendering";
|
|
5
5
|
import type { ReadToolResult } from "pi-agent-read/api/tools/read";
|
|
6
6
|
import { Text, type Component } from "@earendil-works/pi-tui";
|
|
7
7
|
import type { FileMutationBatchResult } from "#src/api/mutation-result.js";
|
|
@@ -46,18 +46,20 @@ export function createApplyDisplay(
|
|
|
46
46
|
return {
|
|
47
47
|
comparisons,
|
|
48
48
|
cwd,
|
|
49
|
-
blocks:
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
block
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
blocks: [
|
|
50
|
+
...output.content
|
|
51
|
+
.filter((block) => !diffBlocks.has(block))
|
|
52
|
+
.flatMap((block) =>
|
|
53
|
+
block.type === "text"
|
|
54
|
+
? [
|
|
55
|
+
{
|
|
56
|
+
text: redactApplyReceipts(block.text),
|
|
57
|
+
read: reads.find((read) => read.content.includes(block)),
|
|
58
|
+
},
|
|
59
|
+
]
|
|
60
|
+
: [],
|
|
61
|
+
),
|
|
62
|
+
],
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
65
|
const mutations = finalApplyMutations(results);
|
|
@@ -78,12 +80,13 @@ export function createApplyDisplay(
|
|
|
78
80
|
);
|
|
79
81
|
return [
|
|
80
82
|
{
|
|
81
|
-
text:
|
|
83
|
+
text: redactApplyReceipts(
|
|
82
84
|
typeof entry.value === "string"
|
|
83
85
|
? entry.value
|
|
84
86
|
: entry.value === undefined
|
|
85
87
|
? "undefined"
|
|
86
88
|
: JSON.stringify(entry.value, null, 2),
|
|
89
|
+
),
|
|
87
90
|
},
|
|
88
91
|
];
|
|
89
92
|
}),
|
|
@@ -202,7 +205,7 @@ export function createApplyCallRenderer(
|
|
|
202
205
|
return applyFrameRows(
|
|
203
206
|
state.codeView || context.expanded
|
|
204
207
|
? (state.displaySource ?? source)
|
|
205
|
-
: projectSource(state.displaySource ?? source),
|
|
208
|
+
: compactApplyPreview(projectSource(state.displaySource ?? source)),
|
|
206
209
|
theme,
|
|
207
210
|
width,
|
|
208
211
|
"call",
|
|
@@ -214,6 +217,19 @@ export function createApplyCallRenderer(
|
|
|
214
217
|
};
|
|
215
218
|
}
|
|
216
219
|
|
|
220
|
+
/** Keep a useful source head and tail within the compact read row budget. */
|
|
221
|
+
export function compactApplyPreview(source: string, limit = COMPACT_READ_ROWS): string {
|
|
222
|
+
const lines = source.split("\n");
|
|
223
|
+
if (lines.length <= limit) return source;
|
|
224
|
+
const visible = Math.max(2, limit - 1);
|
|
225
|
+
const head = Math.ceil(visible / 2);
|
|
226
|
+
const tail = Math.floor(visible / 2);
|
|
227
|
+
const omitted = lines.length - head - tail;
|
|
228
|
+
return [...lines.slice(0, head), `… ${omitted} lines omitted …`, ...lines.slice(-tail)].join(
|
|
229
|
+
"\n",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
217
233
|
export const renderApplyCall = createApplyCallRenderer();
|
|
218
234
|
|
|
219
235
|
/** Configured editor presentation for final mutations inside the Apply card. */
|
|
@@ -313,6 +329,26 @@ export function createApplyResultRenderer(
|
|
|
313
329
|
};
|
|
314
330
|
}
|
|
315
331
|
|
|
332
|
+
function redactApplyReceipts(text: string): string {
|
|
333
|
+
if (/^(?:Undo transaction:|Undo available)/u.test(text.trim())) return "";
|
|
334
|
+
try {
|
|
335
|
+
const value: unknown = JSON.parse(text);
|
|
336
|
+
return JSON.stringify(redactTransactionKeys(value), null, 2);
|
|
337
|
+
} catch {
|
|
338
|
+
return text.replace(/APPLY#[0-9A-F]{12}/gu, "Apply transaction");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function redactTransactionKeys(value: unknown): unknown {
|
|
343
|
+
if (Array.isArray(value)) return value.map(redactTransactionKeys);
|
|
344
|
+
if (value === null || typeof value !== "object") return value;
|
|
345
|
+
return Object.fromEntries(
|
|
346
|
+
Object.entries(value)
|
|
347
|
+
.filter(([key]) => key !== "transaction")
|
|
348
|
+
.map(([key, item]) => [key, redactTransactionKeys(item)]),
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
316
352
|
function jsonDetails(text: string): { source?: string } {
|
|
317
353
|
try {
|
|
318
354
|
const value: unknown = JSON.parse(text);
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import type { RunLimits } from "run";
|
|
2
|
-
import { fileOperations } from "#src/core/file-operations.js";
|
|
3
2
|
import { ApplyQueue } from "#src/core/apply/queue.js";
|
|
4
3
|
|
|
5
|
-
/**
|
|
6
|
-
export const
|
|
4
|
+
/** Read-only IDE operations plus the private transactional editor bridge. */
|
|
5
|
+
export const defaultApplyOperations = [
|
|
7
6
|
"read",
|
|
8
7
|
"search",
|
|
9
8
|
"diff",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"insert",
|
|
13
|
-
"remove",
|
|
14
|
-
"copy",
|
|
15
|
-
"move",
|
|
16
|
-
"undo",
|
|
17
|
-
"stage",
|
|
18
|
-
"unstage",
|
|
19
|
-
...fileOperations,
|
|
9
|
+
"editorOpen",
|
|
10
|
+
"editorApply",
|
|
20
11
|
] as const;
|
|
21
|
-
export type ApplyOperation = (typeof
|
|
12
|
+
export type ApplyOperation = (typeof defaultApplyOperations)[number];
|
|
13
|
+
|
|
14
|
+
// Node timers use signed 32-bit delays. This is effectively unbounded for an agent turn while
|
|
15
|
+
// preserving Run's finite sandbox deadline and explicit limits used by focused tests.
|
|
16
|
+
const APPLY_EXECUTION_TIMEOUT_MS = 2_147_483_647;
|
|
17
|
+
|
|
18
|
+
/** Return the fixed Apply capability set. Kept as a function for callers that build prompts. */
|
|
19
|
+
export function getApplyOperations(): readonly ApplyOperation[] {
|
|
20
|
+
return defaultApplyOperations;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
23
|
/** The host records outcomes before returning them across the guest bridge. */
|
|
24
24
|
export interface ApplyRuntimeHost {
|
|
@@ -37,11 +37,12 @@ export async function executeApplySource(
|
|
|
37
37
|
host: ApplyRuntimeHost,
|
|
38
38
|
signal?: AbortSignal,
|
|
39
39
|
limits?: RunLimits,
|
|
40
|
+
enabledOperations: readonly ApplyOperation[] = defaultApplyOperations,
|
|
40
41
|
): Promise<void> {
|
|
41
42
|
const { createRunner, getHostFunctionContext } = await import("run");
|
|
42
43
|
const queue = new ApplyQueue();
|
|
43
44
|
const operations = Object.fromEntries(
|
|
44
|
-
|
|
45
|
+
enabledOperations.map((operation) => [
|
|
45
46
|
operation,
|
|
46
47
|
(arguments_: unknown) => {
|
|
47
48
|
const context = getHostFunctionContext();
|
|
@@ -75,7 +76,11 @@ export async function executeApplySource(
|
|
|
75
76
|
},
|
|
76
77
|
},
|
|
77
78
|
});
|
|
78
|
-
await runner.run({
|
|
79
|
+
await runner.run({
|
|
80
|
+
source: `${guestBindings(enabledOperations)}\n${source}\n__finishApplyScript();`,
|
|
81
|
+
abortSignal: signal,
|
|
82
|
+
limits: { ...limits, timeoutMs: limits?.timeoutMs ?? APPLY_EXECUTION_TIMEOUT_MS },
|
|
83
|
+
});
|
|
79
84
|
} finally {
|
|
80
85
|
await queue.close();
|
|
81
86
|
}
|
|
@@ -88,15 +93,32 @@ export function serializeApplyError(error: unknown): {
|
|
|
88
93
|
details?: unknown;
|
|
89
94
|
} {
|
|
90
95
|
if (!(error instanceof Error)) return { code: "OPERATION_FAILED", message: String(error) };
|
|
96
|
+
const runtimeCode = "code" in error && typeof error.code === "string" ? error.code : undefined;
|
|
91
97
|
return {
|
|
92
|
-
code:
|
|
98
|
+
code:
|
|
99
|
+
runtimeCode === "RUN_USER_SOURCE_ERROR"
|
|
100
|
+
? applyGuestErrorCode(error.message)
|
|
101
|
+
: (runtimeCode ?? "OPERATION_FAILED"),
|
|
93
102
|
message: error.message,
|
|
94
103
|
...("details" in error ? { details: error.details } : {}),
|
|
95
104
|
};
|
|
96
105
|
}
|
|
97
106
|
|
|
98
|
-
function
|
|
99
|
-
|
|
107
|
+
function applyGuestErrorCode(message: string): string {
|
|
108
|
+
if (/Expected exactly one (?:match|end marker)/u.test(message))
|
|
109
|
+
return message.endsWith("found 0") ? "NOT_FOUND" : "AMBIGUOUS_MATCH";
|
|
110
|
+
if (message === "No matches") return "NOT_FOUND";
|
|
111
|
+
if (message === "Search match is stale") return "STALE_SELECTION";
|
|
112
|
+
if (message === "Editor handle belongs to a committed transaction") return "STALE_EDITOR";
|
|
113
|
+
if (/^(?:Invalid line range|Line range is outside document)$/u.test(message))
|
|
114
|
+
return "INVALID_SELECTION";
|
|
115
|
+
return "RUN_USER_SOURCE_ERROR";
|
|
116
|
+
}
|
|
117
|
+
function guestBindings(enabledOperations: readonly ApplyOperation[]): string {
|
|
118
|
+
const readOperations = enabledOperations.filter(
|
|
119
|
+
(name) => name === "read" || name === "search" || name === "diff",
|
|
120
|
+
);
|
|
121
|
+
return `const { ${readOperations.join(", ")}, open, createFile, deleteFile, copyFile, moveFile, apply, result, __finishApplyScript } = (() => {
|
|
100
122
|
const origins = new WeakMap();
|
|
101
123
|
const invoke = (name, args) => {
|
|
102
124
|
const response = __apply[name](args);
|
|
@@ -104,9 +126,86 @@ function guestBindings(): string {
|
|
|
104
126
|
if (response.value !== null && typeof response.value === "object") origins.set(response.value, response.id);
|
|
105
127
|
return response.value;
|
|
106
128
|
};
|
|
129
|
+
let generation = 0;
|
|
130
|
+
let snapshots = new Map();
|
|
131
|
+
let operations = [];
|
|
132
|
+
const assertCurrent = (document) => {
|
|
133
|
+
if (document.generation !== generation) throw Object.assign(new Error("Editor handle belongs to a committed transaction"), {code: "STALE_EDITOR"});
|
|
134
|
+
};
|
|
135
|
+
const selection = (document, from, to) => Object.freeze({document: document.id, from, to, text: document.content.slice(from, to)});
|
|
136
|
+
const occurrences = (content, needle) => {
|
|
137
|
+
if (typeof needle !== "string" || needle.length === 0) throw new Error("Find text must be non-empty");
|
|
138
|
+
const found = [];
|
|
139
|
+
for (let from = content.indexOf(needle); from >= 0; from = content.indexOf(needle, from + needle.length)) found.push(from);
|
|
140
|
+
return found;
|
|
141
|
+
};
|
|
142
|
+
const unique = (document, needle) => {
|
|
143
|
+
const found = occurrences(document.content, needle);
|
|
144
|
+
if (found.length !== 1) throw Object.assign(new Error("Expected exactly one match, found " + found.length), {code: found.length === 0 ? "NOT_FOUND" : "AMBIGUOUS_MATCH"});
|
|
145
|
+
return selection(document, found[0], found[0] + needle.length);
|
|
146
|
+
};
|
|
147
|
+
const makeDocument = (snapshot) => {
|
|
148
|
+
const document = {id: snapshot.id, source: snapshot.source, content: snapshot.content, lines: snapshot.lines, generation};
|
|
149
|
+
const api = {
|
|
150
|
+
source: document.source,
|
|
151
|
+
content: document.content,
|
|
152
|
+
lines: document.lines,
|
|
153
|
+
find: (text) => { assertCurrent(document); return unique(document, text); },
|
|
154
|
+
findAll: (text) => { assertCurrent(document); return occurrences(document.content, text).map((from) => selection(document, from, from + text.length)); },
|
|
155
|
+
between: (start, end, options = {}) => {
|
|
156
|
+
assertCurrent(document);
|
|
157
|
+
const first = unique(document, start);
|
|
158
|
+
const tail = document.content.slice(first.to);
|
|
159
|
+
const ends = occurrences(tail, end);
|
|
160
|
+
if (ends.length !== 1) throw Object.assign(new Error("Expected exactly one end marker after start, found " + ends.length), {code: ends.length === 0 ? "NOT_FOUND" : "AMBIGUOUS_MATCH"});
|
|
161
|
+
const endFrom = first.to + ends[0];
|
|
162
|
+
return selection(document, options.inside === true ? first.to : first.from, options.inside === true ? endFrom : endFrom + end.length);
|
|
163
|
+
},
|
|
164
|
+
select: (match) => {
|
|
165
|
+
assertCurrent(document);
|
|
166
|
+
const candidate = match?.selection ?? match;
|
|
167
|
+
if (!candidate || typeof candidate !== "object") throw new Error("select() requires a search match");
|
|
168
|
+
if (candidate.source && candidate.source !== document.source) throw new Error("Search match belongs to another file");
|
|
169
|
+
const starts = [0];
|
|
170
|
+
for (let index = 0; index < document.content.length; index += 1) if (document.content[index] === "\\n") starts.push(index + 1);
|
|
171
|
+
const startLine = candidate.lineNumber;
|
|
172
|
+
const endLine = candidate.endLineNumber ?? startLine;
|
|
173
|
+
if (!Number.isInteger(startLine) || !Number.isInteger(endLine)) throw new Error("Search match has no text range");
|
|
174
|
+
const from = starts[startLine - 1] + candidate.startColumn;
|
|
175
|
+
const to = starts[endLine - 1] + candidate.endColumn;
|
|
176
|
+
const selected = selection(document, from, to);
|
|
177
|
+
if (typeof candidate.matchedText === "string" && selected.text !== candidate.matchedText) throw Object.assign(new Error("Search match is stale"), {code: "STALE_SELECTION"});
|
|
178
|
+
return selected;
|
|
179
|
+
},
|
|
180
|
+
line: (first, last = first) => {
|
|
181
|
+
assertCurrent(document);
|
|
182
|
+
if (!Number.isInteger(first) || !Number.isInteger(last) || first < 1 || last < first) throw new RangeError("Invalid line range");
|
|
183
|
+
const starts = [0];
|
|
184
|
+
for (let index = 0; index < document.content.length; index += 1) if (document.content[index] === "\\n") starts.push(index + 1);
|
|
185
|
+
if (last > starts.length) throw new RangeError("Line range is outside document");
|
|
186
|
+
return selection(document, starts[first - 1], starts[last] === undefined ? document.content.length : starts[last]);
|
|
187
|
+
},
|
|
188
|
+
replace: (selected, text) => { assertCurrent(document); operations.push({kind: "replace", selection: selected, text: String(text)}); },
|
|
189
|
+
remove: (selected) => { assertCurrent(document); operations.push({kind: "replace", selection: selected, text: ""}); },
|
|
190
|
+
insertBefore: (selected, text) => { assertCurrent(document); operations.push({kind: "replace", selection: selection(document, selected.from, selected.from), text: String(text)}); },
|
|
191
|
+
insertAfter: (selected, text) => { assertCurrent(document); operations.push({kind: "replace", selection: selection(document, selected.to, selected.to), text: String(text)}); },
|
|
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; },
|
|
193
|
+
};
|
|
194
|
+
return Object.freeze(api);
|
|
195
|
+
};
|
|
107
196
|
return {
|
|
108
|
-
${
|
|
197
|
+
${readOperations.map((name) => `${name}: (args) => invoke(${JSON.stringify(name)}, args)`).join(",\n")},
|
|
198
|
+
open: (path) => { const snapshot = invoke("editorOpen", typeof path === "string" ? {path} : path); snapshots.set(snapshot.id, snapshot); return makeDocument(snapshot); },
|
|
199
|
+
createFile: (path, content) => operations.push({kind: "create", path, content: String(content)}),
|
|
200
|
+
deleteFile: (path) => operations.push({kind: "delete", path}),
|
|
201
|
+
copyFile: (path, target, options = {}) => operations.push({kind: "copy", path, target, overwrite: options.overwrite === true}),
|
|
202
|
+
moveFile: (path, target, options = {}) => operations.push({kind: "move", path, target, overwrite: options.overwrite === true}),
|
|
203
|
+
apply: () => {
|
|
204
|
+
const value = invoke("editorApply", {snapshots: [...snapshots.values()].map(({id, source, content}) => ({id, source, content})), operations});
|
|
205
|
+
generation += 1; snapshots = new Map(); operations = []; return value;
|
|
206
|
+
},
|
|
109
207
|
result: (value) => __apply.result(value, value !== null && typeof value === "object" ? origins.get(value) : undefined),
|
|
208
|
+
__finishApplyScript: () => { if (operations.length > 0) __apply.result({kind: "uncommitted-transaction", staged: operations.length, message: "Staged changes were not applied; call apply()."}); },
|
|
110
209
|
};
|
|
111
210
|
})();`;
|
|
112
211
|
}
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "#src/api/last-resolved-resource.js";
|
|
18
18
|
import type { TextEditorCore } from "#src/core/text-editor-core.js";
|
|
19
19
|
import { createApplyExecution } from "#src/core/apply/execution.js";
|
|
20
|
-
import { executeApplySource } from "#src/core/apply/runtime.js";
|
|
20
|
+
import { executeApplySource, getApplyOperations } from "#src/core/apply/runtime.js";
|
|
21
21
|
import { renderApplyOutput } from "#src/core/apply/output.js";
|
|
22
22
|
import {
|
|
23
23
|
createApplyDisplay,
|
|
@@ -45,6 +45,7 @@ export async function registerApply(pi: ExtensionAPI, editor: TextEditorCore): P
|
|
|
45
45
|
search = api;
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
|
+
const operations = getApplyOperations();
|
|
48
49
|
pi.registerTool({
|
|
49
50
|
name: "apply",
|
|
50
51
|
label: "Apply",
|
|
@@ -60,12 +61,13 @@ export async function registerApply(pi: ExtensionAPI, editor: TextEditorCore): P
|
|
|
60
61
|
renderApplyResult) as typeof renderApplyResult;
|
|
61
62
|
return render(...args);
|
|
62
63
|
},
|
|
63
|
-
promptSnippet: "Compose
|
|
64
|
+
promptSnippet: "Compose guarded multi-file editor transactions with JavaScript",
|
|
64
65
|
description:
|
|
65
|
-
|
|
66
|
-
applyHelperGuide,
|
|
66
|
+
`Use apply to compose read-only IDE operations and snapshot-guarded editor transactions in JavaScript. Read-only functions: read, search, diff, result. Editor functions: open, createFile, deleteFile, copyFile, moveFile, apply. Mutations are staged until apply() commits them. Calls execute sequentially. Output has one 2000-line/50KB budget. No shell, imports or resume.` +
|
|
67
|
+
applyHelperGuide(),
|
|
67
68
|
promptGuidelines: [
|
|
68
|
-
"Use
|
|
69
|
+
"Use Apply for complex, multi-file changes. Open immutable file snapshots, select exact text or lines, stage guarded operations, then call apply() explicitly. Use standalone editor tools for small precise edits.",
|
|
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
71
|
],
|
|
70
72
|
parameters: Type.Object({
|
|
71
73
|
source: Type.String({
|
|
@@ -90,7 +92,7 @@ export async function registerApply(pi: ExtensionAPI, editor: TextEditorCore): P
|
|
|
90
92
|
let failed = false;
|
|
91
93
|
let error: unknown;
|
|
92
94
|
try {
|
|
93
|
-
await executeApplySource(source, execution.host, signal);
|
|
95
|
+
await executeApplySource(source, execution.host, signal, undefined, operations);
|
|
94
96
|
} catch (cause) {
|
|
95
97
|
failed = true;
|
|
96
98
|
error = cause;
|
|
@@ -105,8 +107,26 @@ export async function registerApply(pi: ExtensionAPI, editor: TextEditorCore): P
|
|
|
105
107
|
cwd: context.cwd,
|
|
106
108
|
signal,
|
|
107
109
|
});
|
|
110
|
+
const transactions = execution.results
|
|
111
|
+
.mutationValues()
|
|
112
|
+
.flatMap((value) =>
|
|
113
|
+
value !== null &&
|
|
114
|
+
typeof value === "object" &&
|
|
115
|
+
"transaction" in value &&
|
|
116
|
+
typeof value.transaction === "string" &&
|
|
117
|
+
editor.hasApplyUndo(value.transaction)
|
|
118
|
+
? [value.transaction]
|
|
119
|
+
: [],
|
|
120
|
+
);
|
|
121
|
+
const content = [
|
|
122
|
+
...output.content,
|
|
123
|
+
...transactions.map((transaction) => ({
|
|
124
|
+
type: "text" as const,
|
|
125
|
+
text: `Undo transaction: ${transaction}`,
|
|
126
|
+
})),
|
|
127
|
+
];
|
|
108
128
|
return {
|
|
109
|
-
content
|
|
129
|
+
content,
|
|
110
130
|
details: {
|
|
111
131
|
failed,
|
|
112
132
|
displaySource: await displaySource,
|
|
@@ -114,6 +134,7 @@ export async function registerApply(pi: ExtensionAPI, editor: TextEditorCore): P
|
|
|
114
134
|
display: createApplyDisplay(execution.results, output, error, context.cwd),
|
|
115
135
|
temporarySource: output.temporarySource,
|
|
116
136
|
files: execution.results.select().files.map(({ source: file }) => file),
|
|
137
|
+
transactions,
|
|
117
138
|
},
|
|
118
139
|
};
|
|
119
140
|
},
|