pi-agent-ide 0.4.0 → 0.5.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 +41 -0
- package/README.md +7 -7
- 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-AWXVJ5AC.js +1 -0
- package/dist/chunk-BGUSBUUD.js +26 -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-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-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
- package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
- package/dist/chunk-QH4ZUDOD.js +1 -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/chunk-ZG2MWXCR.js +2 -0
- package/dist/chunk-ZUMN6U77.js +27 -0
- 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 +1 -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/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 +47 -19
- 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 +6 -3
- 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-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 +58 -38
- 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/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 +47 -19
- 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 +6 -3
- 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 +81 -0
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +252 -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 +30 -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/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 +13 -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/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
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
export interface ApplyUndoBeforeState {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly existed: boolean;
|
|
8
|
+
readonly bytes?: Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ApplyUndoPathState extends ApplyUndoBeforeState {
|
|
12
|
+
after: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ApplyUndoReceipt {
|
|
16
|
+
readonly paths: readonly ApplyUndoPathState[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ApplyUndoResult {
|
|
20
|
+
readonly transaction: string;
|
|
21
|
+
readonly restored: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Session-local, single-use receipts for atomic Apply rollback. */
|
|
25
|
+
export class ApplyUndoStore {
|
|
26
|
+
readonly #receipts = new Map<string, ApplyUndoReceipt>();
|
|
27
|
+
readonly #restoreState: (state: ApplyUndoBeforeState) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
public constructor(restore = restoreState) {
|
|
30
|
+
this.#restoreState = restore;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async record(before: readonly ApplyUndoBeforeState[]): Promise<string> {
|
|
34
|
+
const touched = new Set(before.map((state) => path.normalize(state.path)));
|
|
35
|
+
this.invalidate(touched);
|
|
36
|
+
const paths = await Promise.all(
|
|
37
|
+
before.map(async (state) => ({ ...state, after: await fingerprint(state.path) })),
|
|
38
|
+
);
|
|
39
|
+
const transaction = `APPLY#${randomBytes(6).toString("hex").toUpperCase()}`;
|
|
40
|
+
this.#receipts.set(transaction, { paths });
|
|
41
|
+
return transaction;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public observeTextChange(
|
|
45
|
+
file: string,
|
|
46
|
+
before: string,
|
|
47
|
+
after: string,
|
|
48
|
+
postProcessing: "deferred" | "complete" | "final",
|
|
49
|
+
): void {
|
|
50
|
+
const normalized = path.normalize(file);
|
|
51
|
+
if (postProcessing === "final") {
|
|
52
|
+
const beforeFingerprint = textFingerprint(before);
|
|
53
|
+
for (const receipt of this.#receipts.values()) {
|
|
54
|
+
const state = receipt.paths.find(
|
|
55
|
+
(candidate) => path.normalize(candidate.path) === normalized,
|
|
56
|
+
);
|
|
57
|
+
if (state?.after === beforeFingerprint) state.after = textFingerprint(after);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.invalidate(new Set([normalized]));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public invalidate(paths: ReadonlySet<string>): void {
|
|
65
|
+
for (const [transaction, receipt] of this.#receipts) {
|
|
66
|
+
if (receipt.paths.some((state) => paths.has(path.normalize(state.path))))
|
|
67
|
+
this.#receipts.delete(transaction);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public has(transaction: string): boolean {
|
|
72
|
+
return this.#receipts.has(transaction);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public async restore(transaction: string): Promise<ApplyUndoResult> {
|
|
76
|
+
const receipt = this.#receipts.get(transaction);
|
|
77
|
+
if (receipt === undefined)
|
|
78
|
+
throw coded("APPLY_UNDO_UNAVAILABLE", `No undo receipt is available for ${transaction}.`);
|
|
79
|
+
|
|
80
|
+
for (const state of receipt.paths) {
|
|
81
|
+
if ((await fingerprint(state.path)) !== state.after) {
|
|
82
|
+
this.#receipts.delete(transaction);
|
|
83
|
+
throw coded(
|
|
84
|
+
"APPLY_UNDO_STALE",
|
|
85
|
+
`${state.path} changed after ${transaction}; refusing to overwrite newer content.`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const current = await Promise.all(receipt.paths.map((state) => save(state.path)));
|
|
91
|
+
try {
|
|
92
|
+
for (const state of receipt.paths) await this.#restoreState(state);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const rollbackErrors: string[] = [];
|
|
95
|
+
for (const state of current) {
|
|
96
|
+
try {
|
|
97
|
+
await this.#restoreState(state);
|
|
98
|
+
} catch (rollbackError) {
|
|
99
|
+
rollbackErrors.push(
|
|
100
|
+
`${state.path}: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw Object.assign(
|
|
105
|
+
coded("APPLY_UNDO_FAILED", error instanceof Error ? error.message : String(error)),
|
|
106
|
+
{ rollbackErrors },
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.#receipts.delete(transaction);
|
|
111
|
+
return { transaction, restored: receipt.paths.map((state) => state.path) };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function save(file: string): Promise<ApplyUndoBeforeState> {
|
|
116
|
+
try {
|
|
117
|
+
const stat = await lstat(file);
|
|
118
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
119
|
+
throw coded("INVALID_FILE_TYPE", `${file} is not a regular file.`);
|
|
120
|
+
return { path: file, existed: true, bytes: await readFile(file) };
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (hasCode(error, "ENOENT")) return { path: file, existed: false };
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function textFingerprint(content: string): string {
|
|
128
|
+
return `file:${createHash("sha256").update(content).digest("hex")}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function fingerprint(file: string): Promise<string> {
|
|
132
|
+
const state = await save(file);
|
|
133
|
+
return state.existed
|
|
134
|
+
? `file:${createHash("sha256")
|
|
135
|
+
.update(state.bytes ?? new Uint8Array())
|
|
136
|
+
.digest("hex")}`
|
|
137
|
+
: "absent";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function restoreState(state: ApplyUndoBeforeState): Promise<void> {
|
|
141
|
+
if (!state.existed) {
|
|
142
|
+
await rm(state.path, { force: true });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
await mkdir(path.dirname(state.path), { recursive: true });
|
|
146
|
+
await writeFile(state.path, state.bytes ?? new Uint8Array());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function coded(code: string, message: string): Error {
|
|
150
|
+
return Object.assign(new Error(message), { code });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function hasCode(error: unknown, code: string): boolean {
|
|
154
|
+
return error !== null && typeof error === "object" && "code" in error && error.code === code;
|
|
155
|
+
}
|
|
@@ -8,14 +8,9 @@ import { readParameters, type ReadToolResult } from "pi-agent-read/api/tools/rea
|
|
|
8
8
|
import { searchSchema, type SearchPluginApi, type SearchRequest } from "pi-agent-search/api/search";
|
|
9
9
|
import { Value } from "typebox/value";
|
|
10
10
|
import type { TextEditorCore } from "#src/core/text-editor-core.js";
|
|
11
|
-
import { executeScriptMutation } from "#src/core/text-mutation.js";
|
|
12
11
|
import { ApplyResults } from "#src/core/apply/results.js";
|
|
13
|
-
import {
|
|
14
|
-
executeFileOperation,
|
|
15
|
-
fileOperations,
|
|
16
|
-
type FileOperation,
|
|
17
|
-
} from "#src/core/file-operations.js";
|
|
18
12
|
import { serializeApplyError, type ApplyRuntimeHost } from "#src/core/apply/runtime.js";
|
|
13
|
+
import { executeEditorTransaction } from "#src/core/apply/transaction.js";
|
|
19
14
|
|
|
20
15
|
/** Configured IDE services and ordinary tool schemas, shared with the standalone tools. */
|
|
21
16
|
export interface ApplyServices {
|
|
@@ -40,87 +35,71 @@ export function createApplyExecution(
|
|
|
40
35
|
let lastSource = services.lastResolvedSource;
|
|
41
36
|
const host: ApplyRuntimeHost = {
|
|
42
37
|
async execute(operation, arguments_, signal, id) {
|
|
43
|
-
const tool = operation
|
|
44
|
-
const kind =
|
|
38
|
+
const tool = operation;
|
|
39
|
+
const kind =
|
|
40
|
+
tool === "read" || tool === "search" || tool === "diff" || tool === "editorOpen"
|
|
41
|
+
? "read"
|
|
42
|
+
: "mutation";
|
|
45
43
|
let recorded = false;
|
|
46
44
|
try {
|
|
47
|
-
if (tool === "
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const value = await executeDiff(services.read, arguments_, { cwd: context.cwd, signal });
|
|
67
|
-
results.record(id, "read", value, diffReadResult(value));
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
if ((fileOperations as readonly string[]).includes(operation)) {
|
|
71
|
-
const value = await services.editor.enqueueFileOperation(
|
|
72
|
-
() => executeFileOperation(operation as FileOperation, arguments_, context.cwd, signal),
|
|
73
|
-
signal,
|
|
74
|
-
);
|
|
45
|
+
if (tool === "editorApply") {
|
|
46
|
+
let value;
|
|
47
|
+
try {
|
|
48
|
+
value = await executeEditorTransaction(services.editor, arguments_, signal, context);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const details =
|
|
51
|
+
error !== null && typeof error === "object" && "details" in error
|
|
52
|
+
? error.details
|
|
53
|
+
: undefined;
|
|
54
|
+
if (
|
|
55
|
+
details !== null &&
|
|
56
|
+
typeof details === "object" &&
|
|
57
|
+
"files" in details &&
|
|
58
|
+
Array.isArray(details.files)
|
|
59
|
+
)
|
|
60
|
+
for (const source of details.files)
|
|
61
|
+
if (typeof source === "string") scope.forget(source);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
75
64
|
results.record(id, "mutation", value);
|
|
76
65
|
recorded = true;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
scope.forget(value.path);
|
|
81
|
-
}
|
|
82
|
-
if (value.target !== undefined) {
|
|
83
|
-
results.forgetFile(value.target);
|
|
84
|
-
scope.forget(value.target);
|
|
85
|
-
}
|
|
66
|
+
for (const file of value.files) {
|
|
67
|
+
results.updateFile(file.source, file.before, file.after);
|
|
68
|
+
lastSource = file.source;
|
|
86
69
|
}
|
|
87
|
-
if (value.ok && value.target !== undefined)
|
|
88
|
-
await services.editor.postProcessFile(value.target, { cwd: context.cwd, signal });
|
|
89
|
-
if (!value.ok)
|
|
90
|
-
throw failure(
|
|
91
|
-
value.error?.code ?? "FILE_OPERATION_FAILED",
|
|
92
|
-
value.error?.message ?? "File operation failed",
|
|
93
|
-
value,
|
|
94
|
-
);
|
|
95
70
|
return value;
|
|
96
71
|
}
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (definition === undefined)
|
|
102
|
-
throw failure("UNAVAILABLE_OPERATION", `IDE operation ${tool} is unavailable`);
|
|
103
|
-
const value = await executeScriptMutation(
|
|
104
|
-
services.editor,
|
|
105
|
-
definition,
|
|
72
|
+
if (tool === "editorOpen") {
|
|
73
|
+
if (!Value.Check(readParameters, arguments_))
|
|
74
|
+
throw failure("INVALID_ARGUMENTS", "Invalid arguments for open");
|
|
75
|
+
const outcome = await services.read.read(
|
|
106
76
|
arguments_,
|
|
107
|
-
signal,
|
|
108
|
-
|
|
109
|
-
lastSource,
|
|
110
|
-
(source, presentation) => results.rememberMutation(source, presentation),
|
|
77
|
+
{ cwd: context.cwd, signal },
|
|
78
|
+
"script",
|
|
111
79
|
);
|
|
112
|
-
|
|
80
|
+
const value = outcome.script;
|
|
81
|
+
if (
|
|
82
|
+
outcome.isError ||
|
|
83
|
+
outcome.details.resolvedBy !== "filesystem" ||
|
|
84
|
+
value?.kind !== "text" ||
|
|
85
|
+
typeof value.content !== "string"
|
|
86
|
+
)
|
|
87
|
+
throw failure("NOT_EDITABLE_TEXT", "open() requires one local text file");
|
|
88
|
+
const snapshot = {
|
|
89
|
+
id,
|
|
90
|
+
source: outcome.details.source ?? value.source,
|
|
91
|
+
content: value.content,
|
|
92
|
+
lines: value.lines,
|
|
93
|
+
};
|
|
94
|
+
results.record(id, "read", snapshot, outcome);
|
|
113
95
|
recorded = true;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
value.errors[0]?.message ?? "Mutation failed",
|
|
122
|
-
value,
|
|
123
|
-
);
|
|
96
|
+
lastSource = snapshot.source;
|
|
97
|
+
services.rememberRead?.(outcome);
|
|
98
|
+
return snapshot;
|
|
99
|
+
}
|
|
100
|
+
if (tool === "diff") {
|
|
101
|
+
const value = await executeDiff(services.read, arguments_, { cwd: context.cwd, signal });
|
|
102
|
+
results.record(id, "read", value, diffReadResult(value));
|
|
124
103
|
return value;
|
|
125
104
|
}
|
|
126
105
|
const schema = tool === "read" ? readParameters : searchSchema;
|
|
@@ -5,18 +5,13 @@ const helpers = new Set([
|
|
|
5
5
|
"read",
|
|
6
6
|
"search",
|
|
7
7
|
"diff",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"stage",
|
|
16
|
-
"unstage",
|
|
17
|
-
"delete_file",
|
|
18
|
-
"copy_file",
|
|
19
|
-
"move_file",
|
|
8
|
+
"open",
|
|
9
|
+
"createFile",
|
|
10
|
+
"deleteFile",
|
|
11
|
+
"copyFile",
|
|
12
|
+
"moveFile",
|
|
13
|
+
"apply",
|
|
14
|
+
"result",
|
|
20
15
|
]);
|
|
21
16
|
|
|
22
17
|
/** Bounded source expression; literal does not imply the operation has executed. */
|
|
@@ -28,6 +28,8 @@ export interface ScriptMutationOutcome {
|
|
|
28
28
|
readonly effect: "not-applied" | "applied" | "unknown";
|
|
29
29
|
readonly files: readonly ScriptMutationFile[];
|
|
30
30
|
readonly completed: readonly string[];
|
|
31
|
+
/** Session-scoped receipt accepted by undo. */
|
|
32
|
+
readonly transaction?: string;
|
|
31
33
|
readonly recoveries?: readonly ScriptAnchorRecovery[];
|
|
32
34
|
/** Structured contributions from configured IDE mutation handlers. */
|
|
33
35
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
@@ -145,7 +145,39 @@ function isFailure(value: unknown): boolean {
|
|
|
145
145
|
}
|
|
146
146
|
function formatError(error: unknown): string {
|
|
147
147
|
const failure = serializeApplyError(error);
|
|
148
|
-
return
|
|
148
|
+
return formatApplyFailure(failure.code, failure.message);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function formatApplyFailure(code: string, message: string): string {
|
|
152
|
+
const guidance: Readonly<Record<string, string>> = {
|
|
153
|
+
NOT_FOUND:
|
|
154
|
+
"The requested text or selection was not found. Read the current file and select existing text.",
|
|
155
|
+
AMBIGUOUS_MATCH:
|
|
156
|
+
"The selection matched more than once. Use a larger unique fragment or findAll().",
|
|
157
|
+
STALE_EDITOR:
|
|
158
|
+
"This editor handle was already committed. Open the file again before staging more changes.",
|
|
159
|
+
STALE_SELECTION:
|
|
160
|
+
"The search selection no longer matches the file. Search again and use the fresh match.",
|
|
161
|
+
INVALID_SELECTION:
|
|
162
|
+
"The selected line or range is invalid. Read the file and select a range inside its current bounds.",
|
|
163
|
+
STALE_SNAPSHOT:
|
|
164
|
+
"A touched file changed after it was opened. Open it again and rebuild the transaction.",
|
|
165
|
+
INVALID_TRANSACTION:
|
|
166
|
+
"The staged operations conflict or overlap. Build non-overlapping selections from the original snapshots.",
|
|
167
|
+
TRANSACTION_FAILED:
|
|
168
|
+
"The commit failed after it started. Check the reported rollback state before retrying.",
|
|
169
|
+
EEXIST: "The destination already exists. Choose another path or explicitly enable overwrite.",
|
|
170
|
+
ENOENT: "A source path does not exist. Check the path and retry.",
|
|
171
|
+
RUN_PARSE_ERROR:
|
|
172
|
+
"The Apply JavaScript could not be parsed. Fix the reported syntax and run it again.",
|
|
173
|
+
RUN_RUNTIME_ERROR:
|
|
174
|
+
"The Apply JavaScript failed. Fix the reported operation or API usage and run it again.",
|
|
175
|
+
};
|
|
176
|
+
const hint = guidance[code];
|
|
177
|
+
return hint === undefined
|
|
178
|
+
? `${code}: ${message}`
|
|
179
|
+
: `${code}: ${message}
|
|
180
|
+
${hint}`;
|
|
149
181
|
}
|
|
150
182
|
|
|
151
183
|
function renderValue(value: unknown): Content {
|
|
@@ -206,11 +238,8 @@ function asReadResult(value: unknown): ReadToolResult | undefined {
|
|
|
206
238
|
|
|
207
239
|
function formatReceiptError(value: unknown): string {
|
|
208
240
|
if (value === null || typeof value !== "object") return String(value);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
]
|
|
214
|
-
.filter(Boolean)
|
|
215
|
-
.join(": ");
|
|
241
|
+
const source = "source" in value ? String(value.source) : undefined;
|
|
242
|
+
const code = "code" in value ? String(value.code) : "OPERATION_FAILED";
|
|
243
|
+
const message = "message" in value ? String(value.message) : "The operation failed.";
|
|
244
|
+
return [source, formatApplyFailure(code, message)].filter(Boolean).join(": ");
|
|
216
245
|
}
|
|
@@ -1,45 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
diff({before: string | {path: string, offset?: number, limit?: number, views?: string[]}, after: string | {path: string, offset?: number, limit?: number, views?: string[]}})
|
|
7
|
-
write({path: string, content: string})
|
|
8
|
-
replace({path?: string, start?: string, end?: string, text: string})
|
|
9
|
-
insert({path?: string, anchor?: string, text: string, before?: boolean})
|
|
10
|
-
remove({path?: string, start?: string, end?: string})
|
|
11
|
-
copy({path?: string, start?: string, end?: string, target?: string, targetStart?: string, targetEnd?: string})
|
|
12
|
-
move({path?: string, start?: string, end?: string, target?: string, targetStart?: string, targetEnd?: string})
|
|
13
|
-
delete_file({path: string})
|
|
14
|
-
copy_file({path: string, target: string, overwrite?: boolean})
|
|
15
|
-
move_file({path: string, target: string, overwrite?: boolean})
|
|
16
|
-
undo({file?: string, change: string})
|
|
17
|
-
stage({file: string, change: string})
|
|
18
|
-
unstage({file: string, change: string})
|
|
1
|
+
const editorGuide = `
|
|
2
|
+
Read-only helpers (same arguments as standalone tools):
|
|
3
|
+
read({path, offset?, limit?, views?})
|
|
4
|
+
search({query, path?, include?, exclude?, caseSensitive?, wholeWord?, limit?})
|
|
5
|
+
diff({before, after})
|
|
19
6
|
result(value)
|
|
20
7
|
|
|
21
|
-
|
|
8
|
+
Transactional editor:
|
|
9
|
+
const file = open(path | {path, views?})
|
|
10
|
+
file.source; file.content; file.lines
|
|
11
|
+
file.find(text) // exactly one match or an error
|
|
12
|
+
file.findAll(text) // stable selections from the original snapshot
|
|
13
|
+
file.select(searchMatch) // text, regex, or AST search match
|
|
14
|
+
file.between(start, end, {inside?: boolean})
|
|
15
|
+
file.line(first, last?)
|
|
16
|
+
file.replace(selection, text)
|
|
17
|
+
file.remove(selection)
|
|
18
|
+
file.insertBefore(selection, text)
|
|
19
|
+
file.insertAfter(selection, text)
|
|
20
|
+
file.replaceAll(text, replacement)
|
|
21
|
+
createFile(path, content)
|
|
22
|
+
deleteFile(path)
|
|
23
|
+
copyFile(path, target, {overwrite?: boolean})
|
|
24
|
+
moveFile(path, target, {overwrite?: boolean})
|
|
25
|
+
apply()
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
open() returns an immutable snapshot. Selection methods produce snapshot-bound ranges. Mutation methods only stage changes; they do not modify files. All selections in one transaction refer to the original snapshots, so earlier staged edits never shift later selections. Missing or ambiguous exact matches and overlapping selections reject the transaction.
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
Use read({path: "raw:local-file", offset: 0, limit: 64}) to inspect original bytes without conversion. In raw: reads, offset is a zero-based byte position (negative from EOF) and limit is a non-negative byte count; omit limit for all remaining bytes in the script. Raw reads return {kind: "bytes", source, byteOffset, byteLength, totalBytes, bytes: number[], ok}. Use result(doc) to display hex + ASCII. No views, text anchors or byte editing are supported.
|
|
27
|
-
Search query accepts literal text, Boolean conditions, regex:, files:, ast: and symbols:. limit is 1–1000. Reuse returned SEARCH references; do not invent session IDs. Search returns {resolverId, data, details, ok}; details contains resolver-specific selection metadata.
|
|
28
|
-
Use ast:<pattern> search for structural edits. Pass its returned SEARCH#...:N:match as path to replace, copy, move or remove; the selection covers the exact node, including multiline boundaries. Single references become stale after file changes; all selections rerun the original AST query and require complete results. Use data.matches and their metaVariables to compute replacement text. These are text edits, not reference-aware refactors. Use path/include/exclude to scope symbols: searches before the result limit is applied.
|
|
29
|
-
Text read returns {kind: "text", source, content: string, lines, startLine, endLine, totalLines, ok}. Each line contains content, lineNumber, lineEnding, anchors and available metadata. Native reads return {kind: "native", source, blocks, ok}; multi-source reads return {kind: "resources", resources, ok}. Check kind before using text-only fields.
|
|
30
|
-
Use unique exact text or an anchor returned by read/search for start, end and anchor. A whole-line anchor selects its line; end includes its final line. Omit end for a single selected fragment. begin/end are file-boundary anchors. Omit path only when a previous read/edit or a SEARCH reference identifies the source. A SEARCH selection may also supply the range without start/end. Insert goes after the selected line unless before:true. Copy/move target defaults to source; targetStart selects the destination, and targetEnd replaces an inclusive target line range instead of inserting after targetStart. remove deletes selected text, not a file. write creates or replaces the entire file.
|
|
31
|
-
Use symbol:<file>#<selector> as a declaration selection for copy, move, remove or replace when the LSP plugin is available. For example, copy({path: "symbol:src/a.ts#Example", target: "src/b.ts", targetStart: "end"}). Select parent/child for ambiguous names. Supply an explicit target for copy/move. This declaration-text fallback does not update imports or references; metadata.semanticEdit reports that limitation. Semantic insert is unsupported. Do not treat declaration replacement as a semantic rename.
|
|
32
|
-
Use replace({path: "symbol:src/a.ts#Example#name", text: "NewName"}) for native LSP rename, including references. Omit start/end. The #name suffix selects semantic rename rather than declaration replacement. If the server cannot rename, handle the failure; no identifier-text fallback is applied.
|
|
33
|
-
Use result(doc) to explicitly keep a read result with its source and presentation. Do not use result(doc.content) merely to display a read: it adds a separate raw string and loses the source/view information. Read-only calls are shown automatically, so mass reads need no result calls. Use result(value) for additional computed data; explicit additions survive mutations. Mutations return {operation, ok, effect, files, completed, errors, recoveries?, metadata?}; files contain source, before, after, changes and formatting. They are reported automatically as final per-file changes.
|
|
29
|
+
Call apply() explicitly to validate and commit all staged text and file operations together. One transaction may affect several files. A successful commit returns a session-scoped APPLY# receipt; pass it to undo({ transaction: "APPLY#..." }) before any touched path changes to restore the whole transaction. After a successful apply(), old editor handles are stale; call open() again for another transaction. A script may commit several transactions, and later reads observe earlier commits. Staged operations left without apply() do not change files and are reported as uncommitted.
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
Use stage/unstage with a current CHANGE# anchor from read({path: file, views: ["changes"]}) to change only the Git index. These operations return {kind: "index-operation", operation, ok, effect: "index-only", file, change, state, unchanged} and keep worktree content. Use undo({file, change: "last"}) to restore that file before its latest text-editor transaction, not the entire Apply call. Use undo({file, change: "CHANGE#..."}) to restore a selected change to HEAD in both worktree and index. Git operations require the Git changes module. Re-read stale changes before retrying; completed operations survive later failures.
|
|
37
|
-
Examples:
|
|
38
|
-
const doc = read({path: "src/example.ts"});
|
|
39
|
-
const line = doc.lines.find(line => line.content.includes("oldValue"));
|
|
40
|
-
if (line) replace({path: doc.source, start: line.anchors[0], text: line.content.replace("oldValue", "newValue")});
|
|
31
|
+
Before each commit the host verifies snapshots, resource types, ranges, overlaps, source existence, and destination conflicts. A preflight failure changes nothing. If execution fails after writing begins, the host restores captured resources and reports whether rollback completed. Do not describe an incomplete rollback as atomic success.
|
|
41
32
|
|
|
42
|
-
for (
|
|
33
|
+
Use find() for one expected occurrence, findAll()/replaceAll() for intentional repeated edits, between() for a uniquely delimited block, and line() only when line identity is genuinely part of the task. Generate replacement text with ordinary JavaScript, but never rebuild and submit a complete existing file.
|
|
43
34
|
|
|
44
|
-
|
|
35
|
+
Example:
|
|
36
|
+
const config = open("src/config.ts");
|
|
37
|
+
const test = open("tests/config.test.ts");
|
|
38
|
+
config.replace(config.find("legacyMode"), "stableMode");
|
|
39
|
+
test.replaceAll("legacyMode", "stableMode");
|
|
40
|
+
apply();
|
|
41
|
+
|
|
42
|
+
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
|
+
|
|
44
|
+
Do not retry by guessing argument names. Inspect structured error codes such as NOT_FOUND, AMBIGUOUS_MATCH, STALE_SNAPSHOT, INVALID_TRANSACTION, and TRANSACTION_FAILED.
|
|
45
45
|
`;
|
|
46
|
+
|
|
47
|
+
/** Agent-facing guide for the guarded Apply editor. */
|
|
48
|
+
export function applyHelperGuide(): string {
|
|
49
|
+
return editorGuide;
|
|
50
|
+
}
|
|
@@ -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);
|