pi-agent-ide 0.3.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 +62 -0
- package/README.md +7 -6
- 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-CW53ZTU3.js → chunk-DQXPQOF7.js} +1 -1
- package/dist/chunk-EJ5OACQM.js +1 -0
- 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-J34VKQGJ.js +1 -0
- package/dist/chunk-J4RTW44E.js +1 -0
- package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
- package/dist/{chunk-CEKXBS55.js → chunk-L7JMDDSD.js} +1 -1
- package/dist/{chunk-EWNWKDMP.js → chunk-LY6U5EAD.js} +1 -1
- package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
- package/dist/{chunk-LRYE2WCN.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-SSHZEWWV.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/tools.md +11 -0
- 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 +66 -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-resource/src/resource.ts +2 -0
- 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/api/tool-renderer.ts +3 -0
- 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 +182 -10
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +135 -6
- 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 +60 -2
- 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 +61 -38
- package/src/api/hooks.ts +168 -0
- package/src/api/text-editor.ts +2 -0
- package/src/composite/builtin-extensions.ts +13 -0
- package/src/composite/extensions-config.ts +18 -0
- package/src/composite/module-labels.ts +12 -0
- package/src/composite/module-settings-store.ts +17 -1
- package/src/composite/module-settings.ts +34 -4
- package/src/composite/preferences.ts +26 -0
- package/src/composite/settings-panel.ts +62 -30
- 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 +66 -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 +60 -2
- 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/api/tool-renderer.ts +3 -0
- 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 +182 -10
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +135 -6
- 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/pi-agent-ide.ts +2 -1
- 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 +40 -0
- 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 +204 -0
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +452 -0
- package/src/plugins/pi-agent-ide-terminal/src/screen-image.ts +127 -0
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +159 -0
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +642 -0
- package/src/plugins/pi-agent-ide-terminal/src/shell-profile.ts +56 -0
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +151 -0
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +78 -0
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +212 -0
- package/dist/chunk-5MSNYFDE.js +0 -1
- package/dist/chunk-B5KB2I7J.js +0 -3
- package/dist/chunk-NMFQGKPE.js +0 -2
- package/dist/chunk-OVUYPHDE.js +0 -1
- package/dist/chunk-RHV5STR3.js +0 -3
- package/dist/chunk-TPIHQYK2.js +0 -14
- package/dist/chunk-VCCMVQXU.js +0 -1
- package/dist/chunk-VZJIZXSH.js +0 -14
- 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,204 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { stripVTControlCharacters } from "node:util";
|
|
3
|
+
|
|
4
|
+
import { truncateLine } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { Text, type Component } from "@earendil-works/pi-tui";
|
|
7
|
+
|
|
8
|
+
import { COMPACT_READ_ROWS } from "#src/extensions/pi-agent-read/src/core/tools/read/read-renderer.js";
|
|
9
|
+
import { terminalOutputTail } from "#src/plugins/pi-agent-ide-terminal/src/output-limits.js";
|
|
10
|
+
import type {
|
|
11
|
+
ShellProfile,
|
|
12
|
+
TerminalSessionSnapshot,
|
|
13
|
+
TerminalSessionStatus,
|
|
14
|
+
} from "#src/plugins/pi-agent-ide-terminal/src/types.js";
|
|
15
|
+
|
|
16
|
+
type TerminalTheme = Pick<Theme, "fg">;
|
|
17
|
+
const TERMINAL_MAX_LINE_LENGTH = 500;
|
|
18
|
+
|
|
19
|
+
/** Render a stable shell prompt for a run tool call. */
|
|
20
|
+
export function renderRunCall(
|
|
21
|
+
command: string,
|
|
22
|
+
background: boolean,
|
|
23
|
+
cwd: string,
|
|
24
|
+
profile: ShellProfile,
|
|
25
|
+
theme: TerminalTheme,
|
|
26
|
+
): Component {
|
|
27
|
+
const mode = background ? "background" : "wait";
|
|
28
|
+
const heading = `${theme.fg("toolTitle", profile.displayName.toLocaleLowerCase())} ${theme.fg("muted", `· ${shortCwd(cwd)} · ${mode}`)}`;
|
|
29
|
+
return new Text(
|
|
30
|
+
`${heading}\n${theme.fg("accent", promptMarker(profile.family))} ${command}`,
|
|
31
|
+
0,
|
|
32
|
+
0,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Render only the outcome below an already-visible terminal action call. */
|
|
37
|
+
export function renderTerminalActionResult(
|
|
38
|
+
action: "write" | "insert" | "delete",
|
|
39
|
+
changedLines: readonly string[],
|
|
40
|
+
theme: TerminalTheme,
|
|
41
|
+
): Component {
|
|
42
|
+
const lines = changedLines.map((line) => ` ${theme.fg("dim", line)}`);
|
|
43
|
+
lines.push(theme.fg("success", action === "delete" ? "✓ stopped" : "✓ sent"));
|
|
44
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Render a terminal resource action without exposing its internal shell address. */
|
|
48
|
+
export function renderTerminalAction(
|
|
49
|
+
snapshot: Partial<TerminalSessionSnapshot>,
|
|
50
|
+
action: "read" | "write" | "insert" | "delete" | "search",
|
|
51
|
+
value: string,
|
|
52
|
+
changedLines: readonly string[],
|
|
53
|
+
theme: TerminalTheme,
|
|
54
|
+
): Component {
|
|
55
|
+
const lines = [terminalIdentity(snapshot, theme), theme.fg("accent", `${action} ${value}`)];
|
|
56
|
+
if (changedLines.length > 0)
|
|
57
|
+
lines.push(...changedLines.map((line) => ` ${theme.fg("dim", line)}`));
|
|
58
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
59
|
+
}
|
|
60
|
+
/** Render a bounded pseudo-terminal card; complete output stays available through its log file. */
|
|
61
|
+
export function renderTerminalResult(
|
|
62
|
+
snapshot: Partial<TerminalSessionSnapshot>,
|
|
63
|
+
_expanded: boolean,
|
|
64
|
+
theme: TerminalTheme,
|
|
65
|
+
action?: string,
|
|
66
|
+
): Component {
|
|
67
|
+
const lines = terminalCardLines(snapshot, COMPACT_READ_ROWS, theme);
|
|
68
|
+
if (action !== undefined) lines.splice(1, 1, theme.fg("accent", action));
|
|
69
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Render the result beneath the already-visible run prompt without repeating the command. */
|
|
73
|
+
export function renderRunResult(
|
|
74
|
+
snapshot: Partial<TerminalSessionSnapshot>,
|
|
75
|
+
expanded: boolean,
|
|
76
|
+
theme: TerminalTheme,
|
|
77
|
+
): Component {
|
|
78
|
+
if (expanded) return renderTerminalResult(snapshot, true, theme);
|
|
79
|
+
const window = outputWindow(snapshot.output ?? "", COMPACT_READ_ROWS);
|
|
80
|
+
const lines = [
|
|
81
|
+
...(window.omission === undefined ? [] : [` ${theme.fg("muted", window.omission)}`]),
|
|
82
|
+
...window.lines.map((line) => ` ${theme.fg("dim", line)}`),
|
|
83
|
+
];
|
|
84
|
+
lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
|
|
85
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
86
|
+
}
|
|
87
|
+
/** Render one live below-editor mini-card with changing state only at its tail. */
|
|
88
|
+
export function renderActiveTerminal(
|
|
89
|
+
snapshot: TerminalSessionSnapshot,
|
|
90
|
+
theme?: TerminalTheme,
|
|
91
|
+
): string {
|
|
92
|
+
const color = (name: ThemeColor, text: string): string => theme?.fg(name, text) ?? text;
|
|
93
|
+
const heading = `${color("accent", snapshot.shell.toLocaleLowerCase())} ${color("muted", `· ${shortCwd(snapshot.cwd)} · ${snapshot.background ? "background" : "wait"}`)}`;
|
|
94
|
+
const lines = [
|
|
95
|
+
heading,
|
|
96
|
+
`${color("accent", promptMarker(snapshot.shellFamily))} ${oneLine(snapshot.command, 84)}`,
|
|
97
|
+
];
|
|
98
|
+
const tail = outputTail(snapshot.output, 2);
|
|
99
|
+
if (tail.length > 0) lines.push(...tail.map((line) => ` ${color("dim", oneLine(line, 90))}`));
|
|
100
|
+
lines.push(statusLine(snapshot, color));
|
|
101
|
+
return lines.join("\n");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Build a concise completion or result card from immutable session data. */
|
|
105
|
+
export function terminalCardLines(
|
|
106
|
+
snapshot: Partial<TerminalSessionSnapshot>,
|
|
107
|
+
outputLines: number,
|
|
108
|
+
theme: TerminalTheme,
|
|
109
|
+
): string[] {
|
|
110
|
+
const shell = (snapshot.shell ?? "terminal").toLocaleLowerCase();
|
|
111
|
+
const mode = snapshot.background === true ? "background" : "wait";
|
|
112
|
+
const cwd = snapshot.cwd === undefined ? "workspace" : shortCwd(snapshot.cwd);
|
|
113
|
+
const family = snapshot.shellFamily ?? "posix";
|
|
114
|
+
const lines = [
|
|
115
|
+
`${theme.fg("accent", shell)} ${theme.fg("muted", `· ${cwd} · ${mode}`)}`,
|
|
116
|
+
`${theme.fg("accent", promptMarker(family))} ${snapshot.command ?? ""}`,
|
|
117
|
+
];
|
|
118
|
+
const window = outputWindow(snapshot.output ?? "", outputLines);
|
|
119
|
+
if (window.omission !== undefined) lines.push(` ${theme.fg("muted", window.omission)}`);
|
|
120
|
+
if (window.lines.length > 0)
|
|
121
|
+
lines.push(...window.lines.map((line) => ` ${theme.fg("dim", line)}`));
|
|
122
|
+
lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
|
|
123
|
+
return lines;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function outputTail(output: string, count: number): readonly string[] {
|
|
127
|
+
return outputWindow(output, count).lines;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function outputWindow(
|
|
131
|
+
output: string,
|
|
132
|
+
count: number,
|
|
133
|
+
): { readonly lines: readonly string[]; readonly omission?: string } {
|
|
134
|
+
const truncation = terminalOutputTail(stripVTControlCharacters(output).replaceAll("\r", ""));
|
|
135
|
+
const lines = truncation.content
|
|
136
|
+
.split("\n")
|
|
137
|
+
.map((line) => truncateLine(line.trimEnd(), TERMINAL_MAX_LINE_LENGTH).text);
|
|
138
|
+
if (lines.at(-1) === "") lines.pop();
|
|
139
|
+
const limit = Number.isFinite(count) ? Math.max(0, count) : lines.length;
|
|
140
|
+
const omittedLines = Math.max(0, lines.length - limit);
|
|
141
|
+
const budgetOmittedLines = Math.max(0, truncation.totalLines - truncation.outputLines);
|
|
142
|
+
const omitted = omittedLines + budgetOmittedLines;
|
|
143
|
+
return {
|
|
144
|
+
lines: lines.slice(omittedLines),
|
|
145
|
+
...(truncation.truncated || omitted > 0
|
|
146
|
+
? { omission: omitted > 0 ? `… ${omitted} earlier lines` : "… earlier output omitted" }
|
|
147
|
+
: {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function statusLine(
|
|
152
|
+
snapshot: Partial<TerminalSessionSnapshot>,
|
|
153
|
+
color: (name: ThemeColor, text: string) => string,
|
|
154
|
+
): string {
|
|
155
|
+
const status = snapshot.status ?? "running";
|
|
156
|
+
const icon = statusIcon(status);
|
|
157
|
+
const tone: ThemeColor =
|
|
158
|
+
status === "completed" ? "success" : status === "running" ? "accent" : "error";
|
|
159
|
+
const parts = [`${icon} ${status}`, formatElapsed(snapshot.elapsedMs ?? 0)];
|
|
160
|
+
if (snapshot.waitReason !== undefined) parts.push(`background · ${snapshot.waitReason}`);
|
|
161
|
+
if (snapshot.completionReason !== undefined) parts.push(`reason ${snapshot.completionReason}`);
|
|
162
|
+
if (snapshot.exitCode !== undefined) parts.push(`exit ${snapshot.exitCode}`);
|
|
163
|
+
else if (snapshot.signal !== undefined) parts.push(`signal ${snapshot.signal}`);
|
|
164
|
+
return color(tone, parts.join(" · "));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function statusIcon(status: TerminalSessionStatus): string {
|
|
168
|
+
if (status === "completed") return "✓";
|
|
169
|
+
if (status === "running") return "●";
|
|
170
|
+
if (status === "stopping") return "◌";
|
|
171
|
+
return "✗";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function promptMarker(family: ShellProfile["family"]): string {
|
|
175
|
+
return family === "powershell" ? "PS>" : family === "cmd" ? ">" : "$";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function terminalIdentity(
|
|
179
|
+
snapshot: Partial<TerminalSessionSnapshot>,
|
|
180
|
+
theme: TerminalTheme,
|
|
181
|
+
): string {
|
|
182
|
+
const shell = (snapshot.shell ?? "terminal").toLocaleLowerCase();
|
|
183
|
+
const cwd = snapshot.cwd === undefined ? "workspace" : shortCwd(snapshot.cwd);
|
|
184
|
+
const mode = snapshot.background === true ? "background" : "wait";
|
|
185
|
+
const command = oneLine(snapshot.command ?? "process", 48);
|
|
186
|
+
return `${theme.fg("toolTitle", shell)} ${theme.fg("muted", `· ${cwd} · ${mode} · ${command}`)}`;
|
|
187
|
+
}
|
|
188
|
+
function shortCwd(cwd: string): string {
|
|
189
|
+
const home = process.env.HOME;
|
|
190
|
+
if (home !== undefined && (cwd === home || cwd.startsWith(`${home}${path.sep}`))) {
|
|
191
|
+
return `~${cwd.slice(home.length)}`;
|
|
192
|
+
}
|
|
193
|
+
return cwd;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function oneLine(value: string, max: number): string {
|
|
197
|
+
const line = value.replaceAll(/\s+/gu, " ").trim();
|
|
198
|
+
return line.length <= max ? line : `${line.slice(0, max - 1)}…`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function formatElapsed(milliseconds: number): string {
|
|
202
|
+
if (milliseconds < 1_000) return `${milliseconds}ms`;
|
|
203
|
+
return `${(milliseconds / 1_000).toFixed(milliseconds < 10_000 ? 1 : 0)}s`;
|
|
204
|
+
}
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import {
|
|
2
|
+
READ_API_VERSION,
|
|
3
|
+
READ_PROTOCOL,
|
|
4
|
+
type ReadPlugin,
|
|
5
|
+
} from "pi-agent-read/api/plugin-protocol";
|
|
6
|
+
import { connectReadPlugin } from "pi-agent-read/api/connect-plugin";
|
|
7
|
+
import { connectTextEditorPlugin } from "pi-agent-text-editor/api/connect-plugin";
|
|
8
|
+
import {
|
|
9
|
+
TEXT_EDITOR_API_VERSION,
|
|
10
|
+
TEXT_EDITOR_PROTOCOL,
|
|
11
|
+
type TextEditorPlugin,
|
|
12
|
+
} from "pi-agent-text-editor/api/plugin-protocol";
|
|
13
|
+
import type { AgentContent, ResourceResolver } from "pi-agent-resource";
|
|
14
|
+
|
|
15
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
|
|
17
|
+
import { formatAgentTerminalSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/output-limits.js";
|
|
18
|
+
import { renderTerminalScreen } from "#src/plugins/pi-agent-ide-terminal/src/screen-image.js";
|
|
19
|
+
import {
|
|
20
|
+
renderTerminalAction,
|
|
21
|
+
renderTerminalActionResult,
|
|
22
|
+
renderTerminalResult,
|
|
23
|
+
} from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
|
|
24
|
+
import type { TerminalSessionManager } from "#src/plugins/pi-agent-ide-terminal/src/session-manager.js";
|
|
25
|
+
import type { TerminalSessionSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/types.js";
|
|
26
|
+
|
|
27
|
+
const WRITE_PREFIX = "\u0000pi-terminal-write\u0000";
|
|
28
|
+
const KEYS_PREFIX = "\u0000pi-terminal-keys\u0000";
|
|
29
|
+
|
|
30
|
+
type TerminalAction = "write" | "insert" | "delete";
|
|
31
|
+
interface TerminalActionDetails {
|
|
32
|
+
readonly source: string;
|
|
33
|
+
readonly action: TerminalAction;
|
|
34
|
+
readonly input: string;
|
|
35
|
+
readonly snapshot: Partial<TerminalSessionSnapshot>;
|
|
36
|
+
readonly changedLines: readonly string[];
|
|
37
|
+
readonly status?: string;
|
|
38
|
+
readonly deleted?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Connect shell sessions to the shared read, write, and insert resource interfaces. */
|
|
42
|
+
export async function registerTerminalResources(
|
|
43
|
+
pi: ExtensionAPI,
|
|
44
|
+
manager: TerminalSessionManager,
|
|
45
|
+
): Promise<void> {
|
|
46
|
+
const pendingOutputEnd = new Map<string, number>();
|
|
47
|
+
const pendingScreen = new Map<string, readonly string[]>();
|
|
48
|
+
const readPlugin = {
|
|
49
|
+
protocol: READ_PROTOCOL,
|
|
50
|
+
apiVersion: READ_API_VERSION,
|
|
51
|
+
id: "terminal",
|
|
52
|
+
setup(api) {
|
|
53
|
+
api.addResolver({
|
|
54
|
+
resolver: createReadResolver(manager),
|
|
55
|
+
preserveTruncatedOutput: true,
|
|
56
|
+
renderResult(result, options, theme) {
|
|
57
|
+
const details = result.details as { source?: string };
|
|
58
|
+
const session = details.source === undefined ? undefined : manager.get(details.source);
|
|
59
|
+
const snapshot = session === undefined ? {} : manager.snapshot(session);
|
|
60
|
+
return renderTerminalResult(
|
|
61
|
+
session === undefined
|
|
62
|
+
? snapshot
|
|
63
|
+
: { ...snapshot, output: manager.screenTail(session).join("\n") },
|
|
64
|
+
options.expanded,
|
|
65
|
+
theme,
|
|
66
|
+
"read terminal",
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
api.addHandler({
|
|
71
|
+
stage: "pre-read",
|
|
72
|
+
async handler(context) {
|
|
73
|
+
const source = context.request.path;
|
|
74
|
+
if (
|
|
75
|
+
source === undefined ||
|
|
76
|
+
!isShellSource(source) ||
|
|
77
|
+
context.request.views?.includes("image") !== true
|
|
78
|
+
) {
|
|
79
|
+
return { kind: "continue", context };
|
|
80
|
+
}
|
|
81
|
+
const session = manager.get(source);
|
|
82
|
+
if (session === undefined) {
|
|
83
|
+
return {
|
|
84
|
+
kind: "return",
|
|
85
|
+
result: failure(source, `Unknown terminal session ${source}`),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
manager.markInspected(source);
|
|
90
|
+
const data = await renderTerminalScreen(manager, source);
|
|
91
|
+
return {
|
|
92
|
+
kind: "return",
|
|
93
|
+
result: {
|
|
94
|
+
content: [{ type: "image", data, mimeType: "image/png" }],
|
|
95
|
+
details: { source: session.source, resolvedBy: "terminal" },
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
} catch (error) {
|
|
99
|
+
return {
|
|
100
|
+
kind: "return",
|
|
101
|
+
result: failure(source, error instanceof Error ? error.message : String(error)),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
api.describe(
|
|
107
|
+
'shell:<session> — terminal session status and a bounded output tail with a full-log path when truncated. Use views: ["image"] to read the current virtual terminal screen as a PNG.',
|
|
108
|
+
);
|
|
109
|
+
api.addPromptGuideline(
|
|
110
|
+
"Use read with a returned shell:<session> source to inspect terminal status and output. Add the image view when cursor movement, ANSI layout, or a full-screen terminal interface matters.",
|
|
111
|
+
);
|
|
112
|
+
},
|
|
113
|
+
} satisfies ReadPlugin;
|
|
114
|
+
|
|
115
|
+
const editorPlugin = {
|
|
116
|
+
protocol: TEXT_EDITOR_PROTOCOL,
|
|
117
|
+
apiVersion: TEXT_EDITOR_API_VERSION,
|
|
118
|
+
id: "terminal",
|
|
119
|
+
setup(api) {
|
|
120
|
+
api.addResolver({ resolver: createInputResolver(manager) });
|
|
121
|
+
api.tool("write").addHandler({
|
|
122
|
+
stage: "text-pre-edit",
|
|
123
|
+
handler: async (state) => {
|
|
124
|
+
rememberOutputEnd(state.input, manager, pendingOutputEnd);
|
|
125
|
+
await rememberScreen(state.input, manager, pendingScreen);
|
|
126
|
+
return transformWriteInput(state, WRITE_PREFIX);
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
api.tool("insert").addHandler({
|
|
130
|
+
stage: "text-pre-edit",
|
|
131
|
+
handler: async (state) => {
|
|
132
|
+
await rememberScreen(state.input, manager, pendingScreen);
|
|
133
|
+
rememberOutputEnd(state.input, manager, pendingOutputEnd);
|
|
134
|
+
return transformInsertInput(state);
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
for (const tool of ["write", "insert", "delete"] as const) {
|
|
138
|
+
api.addToolRenderer({
|
|
139
|
+
tool,
|
|
140
|
+
matches: (value, phase) => isTerminalRenderValue(value, phase),
|
|
141
|
+
renderCall(arguments_, theme, context) {
|
|
142
|
+
const input = arguments_ as Record<string, unknown>;
|
|
143
|
+
const session = typeof input.path === "string" ? manager.get(input.path) : undefined;
|
|
144
|
+
const state = context.state as { snapshot?: TerminalSessionSnapshot };
|
|
145
|
+
if (session !== undefined) state.snapshot = manager.snapshot(session);
|
|
146
|
+
return renderTerminalAction(
|
|
147
|
+
state.snapshot ?? {},
|
|
148
|
+
tool,
|
|
149
|
+
terminalInputLabel(tool, input),
|
|
150
|
+
[],
|
|
151
|
+
theme,
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
renderResult(result, _options, theme) {
|
|
155
|
+
const details = terminalActionDetails(result.details);
|
|
156
|
+
return renderTerminalActionResult(details.action, details.changedLines, theme);
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
api.describe(
|
|
161
|
+
"For shell:<session> resources, write sends exact terminal input, insert sends named keys at end, and delete terminates and removes the session. replace is unsupported.",
|
|
162
|
+
);
|
|
163
|
+
api
|
|
164
|
+
.tool("write")
|
|
165
|
+
.describe(
|
|
166
|
+
"When path is shell:<session>, send content exactly as terminal input without adding Enter.",
|
|
167
|
+
);
|
|
168
|
+
api
|
|
169
|
+
.tool("insert")
|
|
170
|
+
.describe(
|
|
171
|
+
"When path is shell:<session>, omit anchor or use end, keep before false, and put whitespace- or comma-separated named keys and chords such as Enter, Ctrl+C, Ctrl+Left, Ctrl+Shift+Left, Up, or Backspace in text. Use Unix caret forms such as ^C and ^U for control characters.",
|
|
172
|
+
);
|
|
173
|
+
},
|
|
174
|
+
} satisfies TextEditorPlugin;
|
|
175
|
+
|
|
176
|
+
await Promise.all([connectReadPlugin(pi, readPlugin), connectTextEditorPlugin(pi, editorPlugin)]);
|
|
177
|
+
|
|
178
|
+
pi.on("tool_result", async (event, context) => {
|
|
179
|
+
if (!isRecord(event.input)) return;
|
|
180
|
+
const requestedSource = event.input.path;
|
|
181
|
+
if (
|
|
182
|
+
event.toolName === "replace" &&
|
|
183
|
+
typeof requestedSource === "string" &&
|
|
184
|
+
isShellSource(requestedSource)
|
|
185
|
+
) {
|
|
186
|
+
return {
|
|
187
|
+
content: [
|
|
188
|
+
{
|
|
189
|
+
type: "text",
|
|
190
|
+
text: `replace is unsupported for ${requestedSource}; use write for text, insert for keys, or delete to terminate and remove the session.`,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
details: event.details,
|
|
194
|
+
isError: true,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (
|
|
198
|
+
event.toolName === "delete" &&
|
|
199
|
+
typeof requestedSource === "string" &&
|
|
200
|
+
isShellSource(requestedSource)
|
|
201
|
+
) {
|
|
202
|
+
const session = manager.get(requestedSource);
|
|
203
|
+
if (session === undefined) return;
|
|
204
|
+
const snapshot = manager.snapshot(session);
|
|
205
|
+
return manager.delete(requestedSource).then(
|
|
206
|
+
() => ({
|
|
207
|
+
content: [
|
|
208
|
+
{ type: "text" as const, text: `Deleted terminal session ${requestedSource}.` },
|
|
209
|
+
],
|
|
210
|
+
details: {
|
|
211
|
+
source: requestedSource,
|
|
212
|
+
deleted: true,
|
|
213
|
+
snapshot,
|
|
214
|
+
action: "delete" as const,
|
|
215
|
+
input: "session",
|
|
216
|
+
changedLines: [],
|
|
217
|
+
} satisfies TerminalActionDetails,
|
|
218
|
+
isError: false,
|
|
219
|
+
}),
|
|
220
|
+
(error: unknown) => ({
|
|
221
|
+
content: [
|
|
222
|
+
{ type: "text" as const, text: error instanceof Error ? error.message : String(error) },
|
|
223
|
+
],
|
|
224
|
+
details: { source: requestedSource, deleted: false },
|
|
225
|
+
isError: true,
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (event.toolName !== "write" && event.toolName !== "insert") return;
|
|
230
|
+
if (event.isError) return;
|
|
231
|
+
const source = event.input.path;
|
|
232
|
+
if (typeof source !== "string" || !isShellSource(source)) return;
|
|
233
|
+
const session = manager.get(source);
|
|
234
|
+
if (session === undefined) return;
|
|
235
|
+
const beforeScreen = pendingScreen.get(source) ?? manager.screenRows(session);
|
|
236
|
+
pendingScreen.delete(source);
|
|
237
|
+
const previousEnd = pendingOutputEnd.get(source) ?? session.outputStart + session.output.length;
|
|
238
|
+
pendingOutputEnd.delete(source);
|
|
239
|
+
await manager.waitForOutputAfter(session, previousEnd);
|
|
240
|
+
const snapshot = manager.snapshot(session);
|
|
241
|
+
const action = event.toolName;
|
|
242
|
+
const input = terminalInputLabel(action, event.input);
|
|
243
|
+
const region = manager.screenChangeRegion(session, beforeScreen, 6);
|
|
244
|
+
const content: Array<
|
|
245
|
+
| { readonly type: "text"; readonly text: string }
|
|
246
|
+
| { readonly type: "image"; readonly data: string; readonly mimeType: "image/png" }
|
|
247
|
+
> = [{ type: "text", text: `Sent ${input} to ${session.source}.` }];
|
|
248
|
+
if (context.model?.input.includes("image") === true) {
|
|
249
|
+
content.push({
|
|
250
|
+
type: "image",
|
|
251
|
+
data: await renderTerminalScreen(manager, source, {
|
|
252
|
+
start: region.startRow,
|
|
253
|
+
count: region.lines.length,
|
|
254
|
+
}),
|
|
255
|
+
mimeType: "image/png",
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
content,
|
|
260
|
+
details: {
|
|
261
|
+
source: session.source,
|
|
262
|
+
action,
|
|
263
|
+
status: session.status,
|
|
264
|
+
snapshot,
|
|
265
|
+
input,
|
|
266
|
+
changedLines: region.lines,
|
|
267
|
+
} satisfies TerminalActionDetails,
|
|
268
|
+
isError: event.isError,
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function createReadResolver(manager: TerminalSessionManager): ResourceResolver {
|
|
274
|
+
return {
|
|
275
|
+
id: "terminal",
|
|
276
|
+
async tryResolve(source) {
|
|
277
|
+
if (!isShellSource(source)) return { kind: "not-handled" };
|
|
278
|
+
const session = manager.get(source);
|
|
279
|
+
if (session === undefined)
|
|
280
|
+
return { kind: "failed", error: new Error(`Unknown terminal session ${source}`) };
|
|
281
|
+
return {
|
|
282
|
+
kind: "resolved",
|
|
283
|
+
resource: {
|
|
284
|
+
source: session.source,
|
|
285
|
+
async read() {
|
|
286
|
+
manager.markInspected(session.source);
|
|
287
|
+
const snapshot = manager.snapshot(session);
|
|
288
|
+
return [{ type: "text", text: formatSnapshot(snapshot) }];
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function createInputResolver(manager: TerminalSessionManager): ResourceResolver {
|
|
297
|
+
return {
|
|
298
|
+
id: "terminal-input",
|
|
299
|
+
async tryResolve(source) {
|
|
300
|
+
if (!isShellSource(source)) return { kind: "not-handled" };
|
|
301
|
+
const session = manager.get(source);
|
|
302
|
+
if (session === undefined)
|
|
303
|
+
return { kind: "failed", error: new Error(`Unknown terminal session ${source}`) };
|
|
304
|
+
return {
|
|
305
|
+
kind: "resolved",
|
|
306
|
+
resource: {
|
|
307
|
+
source: session.source,
|
|
308
|
+
skipPostEdit: true,
|
|
309
|
+
async read() {
|
|
310
|
+
return [{ type: "text", text: "terminal input" }];
|
|
311
|
+
},
|
|
312
|
+
async write(content) {
|
|
313
|
+
const text = singleText(content);
|
|
314
|
+
const writeIndex = text.indexOf(WRITE_PREFIX);
|
|
315
|
+
const keysIndex = text.indexOf(KEYS_PREFIX);
|
|
316
|
+
if (writeIndex >= 0) {
|
|
317
|
+
manager.write(session.source, text.slice(writeIndex + WRITE_PREFIX.length));
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (keysIndex >= 0) {
|
|
321
|
+
manager.sendKeys(session.source, text.slice(keysIndex + KEYS_PREFIX.length).trim());
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
throw new Error(`Unsupported text operation for ${session.source}`);
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function transformWriteInput<State extends { readonly input: unknown }>(
|
|
333
|
+
state: State,
|
|
334
|
+
prefix: string,
|
|
335
|
+
): State {
|
|
336
|
+
if (!isRecord(state.input) || !isShellSourceValue(state.input.path)) return state;
|
|
337
|
+
return {
|
|
338
|
+
...state,
|
|
339
|
+
input: {
|
|
340
|
+
...state.input,
|
|
341
|
+
content: `${prefix}${typeof state.input.content === "string" ? state.input.content : ""}`,
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function transformInsertInput<State extends { readonly input: unknown }>(state: State): State {
|
|
347
|
+
if (!isRecord(state.input) || !isShellSourceValue(state.input.path)) return state;
|
|
348
|
+
if (state.input.before === true)
|
|
349
|
+
throw new Error("Shell keys can only be inserted after the active input position");
|
|
350
|
+
return {
|
|
351
|
+
...state,
|
|
352
|
+
input: {
|
|
353
|
+
...state.input,
|
|
354
|
+
anchor: "end",
|
|
355
|
+
before: false,
|
|
356
|
+
text: `${KEYS_PREFIX}${typeof state.input.text === "string" ? state.input.text : ""}`,
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function formatSnapshot(snapshot: ReturnType<TerminalSessionManager["snapshot"]>): string {
|
|
362
|
+
return formatAgentTerminalSnapshot(snapshot);
|
|
363
|
+
}
|
|
364
|
+
function singleText(content: AgentContent): string {
|
|
365
|
+
if (content.length !== 1 || content[0].type !== "text") {
|
|
366
|
+
throw new Error("Terminal input must contain one text block");
|
|
367
|
+
}
|
|
368
|
+
return content[0].text;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function failure(source: string, message: string) {
|
|
372
|
+
return {
|
|
373
|
+
content: [{ type: "text" as const, text: message }],
|
|
374
|
+
details: {
|
|
375
|
+
source,
|
|
376
|
+
failure: { code: "READ_FAILED" as const, source, resolverId: "terminal", message },
|
|
377
|
+
},
|
|
378
|
+
isError: true,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function isShellSource(value: string): boolean {
|
|
383
|
+
return /^shell:[a-f\d]{12}$/u.test(value);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function isShellSourceValue(value: unknown): value is string {
|
|
387
|
+
return typeof value === "string" && isShellSource(value);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function terminalActionDetails(value: unknown): TerminalActionDetails {
|
|
391
|
+
if (!isRecord(value) || !isRecord(value.snapshot)) {
|
|
392
|
+
throw new TypeError("Invalid terminal action result");
|
|
393
|
+
}
|
|
394
|
+
const snapshot = value.snapshot;
|
|
395
|
+
const action = value.action;
|
|
396
|
+
if (action !== "write" && action !== "insert" && action !== "delete") {
|
|
397
|
+
throw new TypeError("Invalid terminal action");
|
|
398
|
+
}
|
|
399
|
+
return {
|
|
400
|
+
source: typeof value.source === "string" ? value.source : "shell:unknown",
|
|
401
|
+
action,
|
|
402
|
+
input: typeof value.input === "string" ? value.input : "",
|
|
403
|
+
changedLines: Array.isArray(value.changedLines)
|
|
404
|
+
? value.changedLines.filter((line): line is string => typeof line === "string")
|
|
405
|
+
: [],
|
|
406
|
+
snapshot: {
|
|
407
|
+
...(typeof snapshot.shell === "string" ? { shell: snapshot.shell } : {}),
|
|
408
|
+
...(typeof snapshot.cwd === "string" ? { cwd: snapshot.cwd } : {}),
|
|
409
|
+
...(typeof snapshot.command === "string" ? { command: snapshot.command } : {}),
|
|
410
|
+
...(typeof snapshot.background === "boolean" ? { background: snapshot.background } : {}),
|
|
411
|
+
...(typeof snapshot.status === "string"
|
|
412
|
+
? { status: snapshot.status as TerminalSessionSnapshot["status"] }
|
|
413
|
+
: {}),
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async function rememberScreen(
|
|
419
|
+
input: unknown,
|
|
420
|
+
manager: TerminalSessionManager,
|
|
421
|
+
pending: Map<string, readonly string[]>,
|
|
422
|
+
): Promise<void> {
|
|
423
|
+
if (!isRecord(input) || typeof input.path !== "string" || !isShellSource(input.path)) return;
|
|
424
|
+
const session = manager.get(input.path);
|
|
425
|
+
if (session !== undefined) await session.screenReady;
|
|
426
|
+
if (session !== undefined) pending.set(input.path, manager.screenRows(session));
|
|
427
|
+
}
|
|
428
|
+
function rememberOutputEnd(
|
|
429
|
+
input: unknown,
|
|
430
|
+
manager: TerminalSessionManager,
|
|
431
|
+
pending: Map<string, number>,
|
|
432
|
+
): void {
|
|
433
|
+
if (!isRecord(input) || typeof input.path !== "string" || !isShellSource(input.path)) return;
|
|
434
|
+
const session = manager.get(input.path);
|
|
435
|
+
if (session !== undefined) pending.set(input.path, session.outputStart + session.output.length);
|
|
436
|
+
}
|
|
437
|
+
function terminalInputLabel(tool: TerminalAction, input: Record<string, unknown>): string {
|
|
438
|
+
if (tool === "delete") return "session";
|
|
439
|
+
const value = tool === "write" ? input.content : input.text;
|
|
440
|
+
const label = typeof value === "string" ? value : "";
|
|
441
|
+
return tool === "write" ? `text ${JSON.stringify(label)}` : `keys ${label}`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function isTerminalRenderValue(value: unknown, phase: "call" | "result"): boolean {
|
|
445
|
+
if (!isRecord(value)) return false;
|
|
446
|
+
if (phase === "call") return typeof value.path === "string" && isShellSource(value.path);
|
|
447
|
+
const details = value.details;
|
|
448
|
+
return isRecord(details) && typeof details.source === "string" && isShellSource(details.source);
|
|
449
|
+
}
|
|
450
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
451
|
+
return typeof value === "object" && value !== null;
|
|
452
|
+
}
|