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
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { stripVTControlCharacters } from "node:util";
|
|
3
3
|
|
|
4
|
+
import { truncateLine } from "@earendil-works/pi-coding-agent";
|
|
4
5
|
import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
5
|
-
import { Text,
|
|
6
|
+
import { Text, type Component } from "@earendil-works/pi-tui";
|
|
6
7
|
|
|
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";
|
|
8
10
|
import type {
|
|
9
11
|
ShellProfile,
|
|
10
12
|
TerminalSessionSnapshot,
|
|
@@ -12,6 +14,7 @@ import type {
|
|
|
12
14
|
} from "#src/plugins/pi-agent-ide-terminal/src/types.js";
|
|
13
15
|
|
|
14
16
|
type TerminalTheme = Pick<Theme, "fg">;
|
|
17
|
+
const TERMINAL_MAX_LINE_LENGTH = 500;
|
|
15
18
|
|
|
16
19
|
/** Render a stable shell prompt for a run tool call. */
|
|
17
20
|
export function renderRunCall(
|
|
@@ -54,18 +57,14 @@ export function renderTerminalAction(
|
|
|
54
57
|
lines.push(...changedLines.map((line) => ` ${theme.fg("dim", line)}`));
|
|
55
58
|
return new Text(lines.join("\n"), 0, 0);
|
|
56
59
|
}
|
|
57
|
-
/** Render a terminal
|
|
60
|
+
/** Render a bounded pseudo-terminal card; complete output stays available through its log file. */
|
|
58
61
|
export function renderTerminalResult(
|
|
59
62
|
snapshot: Partial<TerminalSessionSnapshot>,
|
|
60
|
-
|
|
63
|
+
_expanded: boolean,
|
|
61
64
|
theme: TerminalTheme,
|
|
62
65
|
action?: string,
|
|
63
66
|
): Component {
|
|
64
|
-
const lines = terminalCardLines(
|
|
65
|
-
snapshot,
|
|
66
|
-
expanded ? Number.POSITIVE_INFINITY : COMPACT_READ_ROWS,
|
|
67
|
-
theme,
|
|
68
|
-
);
|
|
67
|
+
const lines = terminalCardLines(snapshot, COMPACT_READ_ROWS, theme);
|
|
69
68
|
if (action !== undefined) lines.splice(1, 1, theme.fg("accent", action));
|
|
70
69
|
return new Text(lines.join("\n"), 0, 0);
|
|
71
70
|
}
|
|
@@ -79,7 +78,7 @@ export function renderRunResult(
|
|
|
79
78
|
if (expanded) return renderTerminalResult(snapshot, true, theme);
|
|
80
79
|
const window = outputWindow(snapshot.output ?? "", COMPACT_READ_ROWS);
|
|
81
80
|
const lines = [
|
|
82
|
-
...(window.
|
|
81
|
+
...(window.omission === undefined ? [] : [` ${theme.fg("muted", window.omission)}`]),
|
|
83
82
|
...window.lines.map((line) => ` ${theme.fg("dim", line)}`),
|
|
84
83
|
];
|
|
85
84
|
lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
|
|
@@ -117,55 +116,13 @@ export function terminalCardLines(
|
|
|
117
116
|
`${theme.fg("accent", promptMarker(family))} ${snapshot.command ?? ""}`,
|
|
118
117
|
];
|
|
119
118
|
const window = outputWindow(snapshot.output ?? "", outputLines);
|
|
120
|
-
if (window.
|
|
119
|
+
if (window.omission !== undefined) lines.push(` ${theme.fg("muted", window.omission)}`);
|
|
121
120
|
if (window.lines.length > 0)
|
|
122
121
|
lines.push(...window.lines.map((line) => ` ${theme.fg("dim", line)}`));
|
|
123
122
|
lines.push(statusLine(snapshot, (name, text) => theme.fg(name, text)));
|
|
124
123
|
return lines;
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
/** Render bordered mini-cards modeled after the Herdr subagent activity widget. */
|
|
128
|
-
export function renderTerminalWidgetLines(
|
|
129
|
-
snapshots: readonly TerminalSessionSnapshot[],
|
|
130
|
-
width: number,
|
|
131
|
-
theme: TerminalTheme,
|
|
132
|
-
): string[] {
|
|
133
|
-
if (snapshots.length === 0) return [];
|
|
134
|
-
const accent = (text: string): string => theme.fg("accent", text);
|
|
135
|
-
const lines = [borderTop("Terminals", `${snapshots.length} active`, width, accent)];
|
|
136
|
-
for (const snapshot of snapshots) {
|
|
137
|
-
const card = renderActiveTerminal(snapshot, theme).split("\n");
|
|
138
|
-
for (const line of card) lines.push(borderLine(` ${line} `, width, accent));
|
|
139
|
-
if (snapshot !== snapshots.at(-1)) lines.push(borderLine("", width, accent));
|
|
140
|
-
}
|
|
141
|
-
lines.push(borderBottom(width, accent));
|
|
142
|
-
return lines;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function borderTop(
|
|
146
|
-
title: string,
|
|
147
|
-
info: string,
|
|
148
|
-
width: number,
|
|
149
|
-
accent: (text: string) => string,
|
|
150
|
-
): string {
|
|
151
|
-
if (width <= 1) return accent("╭");
|
|
152
|
-
const inner = width - 2;
|
|
153
|
-
const left = `─ ${title} `;
|
|
154
|
-
const right = ` ${info} ─`;
|
|
155
|
-
const fill = "─".repeat(Math.max(0, inner - visibleWidth(left) - visibleWidth(right)));
|
|
156
|
-
return accent(`╭${truncateToWidth(`${left}${fill}${right}`, inner).padEnd(inner, "─")}╮`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function borderLine(line: string, width: number, accent: (text: string) => string): string {
|
|
160
|
-
if (width <= 1) return accent("│");
|
|
161
|
-
const inner = width - 2;
|
|
162
|
-
const clipped = truncateToWidth(line, inner);
|
|
163
|
-
return `${accent("│")}${clipped}${" ".repeat(Math.max(0, inner - visibleWidth(clipped)))}${accent("│")}`;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function borderBottom(width: number, accent: (text: string) => string): string {
|
|
167
|
-
return accent(width <= 1 ? "╰" : `╰${"─".repeat(width - 2)}╯`);
|
|
168
|
-
}
|
|
169
126
|
export function outputTail(output: string, count: number): readonly string[] {
|
|
170
127
|
return outputWindow(output, count).lines;
|
|
171
128
|
}
|
|
@@ -173,15 +130,22 @@ export function outputTail(output: string, count: number): readonly string[] {
|
|
|
173
130
|
function outputWindow(
|
|
174
131
|
output: string,
|
|
175
132
|
count: number,
|
|
176
|
-
): { readonly lines: readonly string[]; readonly
|
|
177
|
-
const
|
|
178
|
-
|
|
133
|
+
): { readonly lines: readonly string[]; readonly omission?: string } {
|
|
134
|
+
const truncation = terminalOutputTail(stripVTControlCharacters(output).replaceAll("\r", ""));
|
|
135
|
+
const lines = truncation.content
|
|
179
136
|
.split("\n")
|
|
180
|
-
.map((line) => line.trimEnd());
|
|
137
|
+
.map((line) => truncateLine(line.trimEnd(), TERMINAL_MAX_LINE_LENGTH).text);
|
|
181
138
|
if (lines.at(-1) === "") lines.pop();
|
|
182
139
|
const limit = Number.isFinite(count) ? Math.max(0, count) : lines.length;
|
|
183
|
-
const
|
|
184
|
-
|
|
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
|
+
};
|
|
185
149
|
}
|
|
186
150
|
|
|
187
151
|
function statusLine(
|
|
@@ -193,6 +157,8 @@ function statusLine(
|
|
|
193
157
|
const tone: ThemeColor =
|
|
194
158
|
status === "completed" ? "success" : status === "running" ? "accent" : "error";
|
|
195
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}`);
|
|
196
162
|
if (snapshot.exitCode !== undefined) parts.push(`exit ${snapshot.exitCode}`);
|
|
197
163
|
else if (snapshot.signal !== undefined) parts.push(`signal ${snapshot.signal}`);
|
|
198
164
|
return color(tone, parts.join(" · "));
|
|
@@ -14,6 +14,7 @@ import type { AgentContent, ResourceResolver } from "pi-agent-resource";
|
|
|
14
14
|
|
|
15
15
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
16
16
|
|
|
17
|
+
import { formatAgentTerminalSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/output-limits.js";
|
|
17
18
|
import { renderTerminalScreen } from "#src/plugins/pi-agent-ide-terminal/src/screen-image.js";
|
|
18
19
|
import {
|
|
19
20
|
renderTerminalAction,
|
|
@@ -85,6 +86,7 @@ export async function registerTerminalResources(
|
|
|
85
86
|
};
|
|
86
87
|
}
|
|
87
88
|
try {
|
|
89
|
+
manager.markInspected(source);
|
|
88
90
|
const data = await renderTerminalScreen(manager, source);
|
|
89
91
|
return {
|
|
90
92
|
kind: "return",
|
|
@@ -102,7 +104,7 @@ export async function registerTerminalResources(
|
|
|
102
104
|
},
|
|
103
105
|
});
|
|
104
106
|
api.describe(
|
|
105
|
-
'shell:<session> — terminal session status and bounded output. Use views: ["image"] to read the current virtual terminal screen as a PNG.',
|
|
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.',
|
|
106
108
|
);
|
|
107
109
|
api.addPromptGuideline(
|
|
108
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.",
|
|
@@ -281,6 +283,7 @@ function createReadResolver(manager: TerminalSessionManager): ResourceResolver {
|
|
|
281
283
|
resource: {
|
|
282
284
|
source: session.source,
|
|
283
285
|
async read() {
|
|
286
|
+
manager.markInspected(session.source);
|
|
284
287
|
const snapshot = manager.snapshot(session);
|
|
285
288
|
return [{ type: "text", text: formatSnapshot(snapshot) }];
|
|
286
289
|
},
|
|
@@ -356,20 +359,8 @@ function transformInsertInput<State extends { readonly input: unknown }>(state:
|
|
|
356
359
|
}
|
|
357
360
|
|
|
358
361
|
function formatSnapshot(snapshot: ReturnType<TerminalSessionManager["snapshot"]>): string {
|
|
359
|
-
|
|
360
|
-
`session: ${snapshot.source}`,
|
|
361
|
-
`status: ${snapshot.status}`,
|
|
362
|
-
`shell: ${snapshot.shell}`,
|
|
363
|
-
`cwd: ${snapshot.cwd}`,
|
|
364
|
-
`elapsedMs: ${snapshot.elapsedMs}`,
|
|
365
|
-
snapshot.exitCode === undefined ? undefined : `exitCode: ${snapshot.exitCode}`,
|
|
366
|
-
snapshot.signal === undefined ? undefined : `signal: ${snapshot.signal}`,
|
|
367
|
-
`outputRange: ${snapshot.outputStart}-${snapshot.outputEnd}`,
|
|
368
|
-
`truncated: ${String(snapshot.truncated)}`,
|
|
369
|
-
].filter((line): line is string => line !== undefined);
|
|
370
|
-
return `${metadata.join("\n")}\n\n${snapshot.output}`;
|
|
362
|
+
return formatAgentTerminalSnapshot(snapshot);
|
|
371
363
|
}
|
|
372
|
-
|
|
373
364
|
function singleText(content: AgentContent): string {
|
|
374
365
|
if (content.length !== 1 || content[0].type !== "text") {
|
|
375
366
|
throw new Error("Terminal input must contain one text block");
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { spawn as spawnProcess } from "node:child_process";
|
|
2
|
+
import { closeSync, mkdirSync, openSync, rmSync, writeSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
2
5
|
import { createRequire } from "node:module";
|
|
3
6
|
import { randomUUID } from "node:crypto";
|
|
4
7
|
import { stripVTControlCharacters } from "node:util";
|
|
@@ -10,6 +13,7 @@ import type {
|
|
|
10
13
|
ShellProfile,
|
|
11
14
|
TerminalSession,
|
|
12
15
|
TerminalSessionSnapshot,
|
|
16
|
+
TerminalWaitReason,
|
|
13
17
|
} from "#src/plugins/pi-agent-ide-terminal/src/types.js";
|
|
14
18
|
|
|
15
19
|
const require = createRequire(import.meta.url);
|
|
@@ -26,6 +30,7 @@ export class TerminalSessionManager {
|
|
|
26
30
|
readonly #sessions = new Map<string, TerminalSession>();
|
|
27
31
|
readonly #changeListeners = new Set<SessionListener>();
|
|
28
32
|
readonly #completionListeners = new Set<SessionListener>();
|
|
33
|
+
readonly #outputLogs = new Map<string, number>();
|
|
29
34
|
#disposed = false;
|
|
30
35
|
|
|
31
36
|
public constructor(createId: () => string = defaultSessionId) {
|
|
@@ -62,6 +67,12 @@ export class TerminalSessionManager {
|
|
|
62
67
|
shellFamily: session.shell.family,
|
|
63
68
|
background: session.background,
|
|
64
69
|
status: session.status,
|
|
70
|
+
...(session.waitReason === undefined ? {} : { waitReason: session.waitReason }),
|
|
71
|
+
...(session.completionReason === undefined
|
|
72
|
+
? {}
|
|
73
|
+
: { completionReason: session.completionReason }),
|
|
74
|
+
lastActivityAt: session.lastActivityAt,
|
|
75
|
+
idleMs: Math.max(0, now - session.lastActivityAt),
|
|
65
76
|
startedAt: session.startedAt,
|
|
66
77
|
...(session.endedAt === undefined ? {} : { endedAt: session.endedAt }),
|
|
67
78
|
elapsedMs: (session.endedAt ?? now) - session.startedAt,
|
|
@@ -72,6 +83,7 @@ export class TerminalSessionManager {
|
|
|
72
83
|
outputStart: session.outputStart,
|
|
73
84
|
outputEnd: session.outputStart + session.output.length,
|
|
74
85
|
truncated: session.outputStart > 0,
|
|
86
|
+
fullOutputPath: session.fullOutputPath,
|
|
75
87
|
cols: session.cols,
|
|
76
88
|
rows: session.rows,
|
|
77
89
|
};
|
|
@@ -90,6 +102,8 @@ export class TerminalSessionManager {
|
|
|
90
102
|
if (!/^[a-f\d]{12}$/u.test(id) || this.#sessions.has(id)) {
|
|
91
103
|
throw new Error("Terminal session IDs must be unique 12-character hexadecimal values");
|
|
92
104
|
}
|
|
105
|
+
const fullOutputPath = createOutputLog(id);
|
|
106
|
+
this.#outputLogs.set(id, openSync(fullOutputPath, "a", 0o600));
|
|
93
107
|
const cols = options.cols ?? DEFAULT_COLS;
|
|
94
108
|
const rows = options.rows ?? DEFAULT_ROWS;
|
|
95
109
|
const screen = createScreen(cols, rows);
|
|
@@ -105,8 +119,10 @@ export class TerminalSessionManager {
|
|
|
105
119
|
cwd: options.cwd,
|
|
106
120
|
shell: options.shell,
|
|
107
121
|
startedAt: Date.now(),
|
|
122
|
+
lastActivityAt: Date.now(),
|
|
108
123
|
cols,
|
|
109
124
|
rows,
|
|
125
|
+
fullOutputPath,
|
|
110
126
|
screen,
|
|
111
127
|
status: "running" as const,
|
|
112
128
|
output: "",
|
|
@@ -146,6 +162,7 @@ export class TerminalSessionManager {
|
|
|
146
162
|
error: errorMessage(error),
|
|
147
163
|
};
|
|
148
164
|
this.#sessions.set(id, session);
|
|
165
|
+
this.#closeOutputLog(id);
|
|
149
166
|
resolveCompletion(session);
|
|
150
167
|
queueMicrotask(() => this.#emitCompleted(session));
|
|
151
168
|
return session;
|
|
@@ -161,6 +178,8 @@ export class TerminalSessionManager {
|
|
|
161
178
|
if (signal !== 0) session.signal = signal;
|
|
162
179
|
session.status =
|
|
163
180
|
session.status === "stopping" ? "stopped" : exitCode === 0 ? "completed" : "failed";
|
|
181
|
+
if (exitCode === 124 || exitCode === 137) session.completionReason = "timeout";
|
|
182
|
+
this.#closeOutputLog(session.id);
|
|
164
183
|
session.resolveCompletion(session);
|
|
165
184
|
this.#emitChanged(session);
|
|
166
185
|
this.#emitCompleted(session);
|
|
@@ -188,6 +207,55 @@ export class TerminalSessionManager {
|
|
|
188
207
|
});
|
|
189
208
|
}
|
|
190
209
|
|
|
210
|
+
/** Wait for foreground completion, preserving a live PTY when the wait must return early. */
|
|
211
|
+
public async waitForForeground(
|
|
212
|
+
sourceOrId: string,
|
|
213
|
+
options: {
|
|
214
|
+
readonly signal?: AbortSignal;
|
|
215
|
+
readonly timeoutMs: number;
|
|
216
|
+
readonly interactiveDelayMs?: number;
|
|
217
|
+
},
|
|
218
|
+
): Promise<{ readonly session: TerminalSession; readonly reason?: TerminalWaitReason }> {
|
|
219
|
+
const session = this.required(sourceOrId);
|
|
220
|
+
if (isTerminalStatus(session.status)) return { session };
|
|
221
|
+
const interactiveDelayMs = options.interactiveDelayMs ?? 3_000;
|
|
222
|
+
|
|
223
|
+
return await new Promise((resolve) => {
|
|
224
|
+
let settled = false;
|
|
225
|
+
let interactiveSince: number | undefined;
|
|
226
|
+
const finish = (reason?: TerminalWaitReason): void => {
|
|
227
|
+
if (settled) return;
|
|
228
|
+
if (reason !== undefined && isTerminalStatus(session.status)) reason = undefined;
|
|
229
|
+
settled = true;
|
|
230
|
+
clearTimeout(timeout);
|
|
231
|
+
clearInterval(interactive);
|
|
232
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
233
|
+
if (reason !== undefined) {
|
|
234
|
+
session.background = true;
|
|
235
|
+
session.waitReason = reason;
|
|
236
|
+
this.#emitChanged(session);
|
|
237
|
+
}
|
|
238
|
+
resolve({ session, ...(reason === undefined ? {} : { reason }) });
|
|
239
|
+
};
|
|
240
|
+
const onAbort = (): void => finish("aborted");
|
|
241
|
+
const timeout = setTimeout(() => finish("timeout"), options.timeoutMs);
|
|
242
|
+
const interactive = setInterval(
|
|
243
|
+
() => {
|
|
244
|
+
if (!looksInteractive(session)) {
|
|
245
|
+
interactiveSince = undefined;
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
interactiveSince ??= Date.now();
|
|
249
|
+
if (Date.now() - interactiveSince >= interactiveDelayMs) finish("interactive");
|
|
250
|
+
},
|
|
251
|
+
Math.min(100, Math.max(10, interactiveDelayMs / 2)),
|
|
252
|
+
);
|
|
253
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
254
|
+
if (options.signal?.aborted === true) onAbort();
|
|
255
|
+
void session.completion.then(() => finish());
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
191
259
|
/** Wait for PTY output triggered by input to settle before capturing the screen. */
|
|
192
260
|
public async waitForOutputAfter(session: TerminalSession, previousEnd: number): Promise<void> {
|
|
193
261
|
const deadline = Date.now() + 300;
|
|
@@ -269,6 +337,14 @@ export class TerminalSessionManager {
|
|
|
269
337
|
}
|
|
270
338
|
return lines.slice(-Math.max(0, count));
|
|
271
339
|
}
|
|
340
|
+
/** Record that the agent inspected a live terminal session. */
|
|
341
|
+
public markInspected(sourceOrId: string): void {
|
|
342
|
+
const session = this.required(sourceOrId);
|
|
343
|
+
if (session.status !== "running") return;
|
|
344
|
+
session.lastActivityAt = Date.now();
|
|
345
|
+
this.#emitChanged(session);
|
|
346
|
+
}
|
|
347
|
+
|
|
272
348
|
public write(sourceOrId: string, data: string): void {
|
|
273
349
|
const session = this.requiredRunning(sourceOrId);
|
|
274
350
|
session.process?.write(data);
|
|
@@ -299,6 +375,7 @@ export class TerminalSessionManager {
|
|
|
299
375
|
if (!isTerminalStatus(session.status)) {
|
|
300
376
|
session.status = finalStatus;
|
|
301
377
|
session.endedAt = Date.now();
|
|
378
|
+
this.#closeOutputLog(session.id);
|
|
302
379
|
session.resolveCompletion(session);
|
|
303
380
|
this.#emitCompleted(session);
|
|
304
381
|
}
|
|
@@ -313,6 +390,8 @@ export class TerminalSessionManager {
|
|
|
313
390
|
session.completionDelivered = true;
|
|
314
391
|
await this.stop(session.source);
|
|
315
392
|
session.screen.dispose();
|
|
393
|
+
this.#closeOutputLog(session.id);
|
|
394
|
+
rmSync(session.fullOutputPath, { force: true });
|
|
316
395
|
this.#sessions.delete(session.id);
|
|
317
396
|
this.#emitChanged(session);
|
|
318
397
|
}
|
|
@@ -341,7 +420,10 @@ export class TerminalSessionManager {
|
|
|
341
420
|
.filter((session) => !isTerminalStatus(session.status))
|
|
342
421
|
.map((session) => this.stop(session.source)),
|
|
343
422
|
);
|
|
344
|
-
for (const session of this.#sessions.values())
|
|
423
|
+
for (const session of this.#sessions.values()) {
|
|
424
|
+
session.screen.dispose();
|
|
425
|
+
this.#closeOutputLog(session.id);
|
|
426
|
+
}
|
|
345
427
|
this.#changeListeners.clear();
|
|
346
428
|
this.#completionListeners.clear();
|
|
347
429
|
}
|
|
@@ -363,7 +445,10 @@ export class TerminalSessionManager {
|
|
|
363
445
|
}
|
|
364
446
|
|
|
365
447
|
#appendOutput(session: TerminalSession, data: string): void {
|
|
448
|
+
session.lastActivityAt = Date.now();
|
|
366
449
|
const plain = stripVTControlCharacters(data);
|
|
450
|
+
const descriptor = this.#outputLogs.get(session.id);
|
|
451
|
+
if (descriptor !== undefined) writeSync(descriptor, plain);
|
|
367
452
|
session.output += plain;
|
|
368
453
|
if (session.output.length > MAX_OUTPUT_CHARS) {
|
|
369
454
|
const removed = session.output.length - MAX_OUTPUT_CHARS;
|
|
@@ -379,6 +464,13 @@ export class TerminalSessionManager {
|
|
|
379
464
|
this.#emitChanged(session);
|
|
380
465
|
}
|
|
381
466
|
|
|
467
|
+
#closeOutputLog(id: string): void {
|
|
468
|
+
const descriptor = this.#outputLogs.get(id);
|
|
469
|
+
if (descriptor === undefined) return;
|
|
470
|
+
closeSync(descriptor);
|
|
471
|
+
this.#outputLogs.delete(id);
|
|
472
|
+
}
|
|
473
|
+
|
|
382
474
|
#emitChanged(session: TerminalSession): void {
|
|
383
475
|
for (const listener of this.#changeListeners) listener(session);
|
|
384
476
|
}
|
|
@@ -388,6 +480,21 @@ export class TerminalSessionManager {
|
|
|
388
480
|
}
|
|
389
481
|
}
|
|
390
482
|
|
|
483
|
+
function looksInteractive(session: TerminalSession): boolean {
|
|
484
|
+
if (session.status !== "running") return false;
|
|
485
|
+
const buffer = session.screen.buffer.active;
|
|
486
|
+
const line =
|
|
487
|
+
buffer
|
|
488
|
+
.getLine(buffer.baseY + buffer.cursorY)
|
|
489
|
+
?.translateToString(true)
|
|
490
|
+
.trimEnd() ?? "";
|
|
491
|
+
return (
|
|
492
|
+
/\[[^\]\n]{1,20}(?:\/[^\]\n]{1,20})+\]\s*[:?>]?\s*$/iu.test(line) ||
|
|
493
|
+
/(?:choose|select|enter|password|confirm|continue|proceed)[^\n]{0,60}[:?]\s*$/iu.test(line) ||
|
|
494
|
+
/^(?:❯|›)\s+\S/u.test(line)
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
391
498
|
function createScreen(cols: number, rows: number): XtermTerminal {
|
|
392
499
|
const { Terminal } = require("@xterm/headless") as {
|
|
393
500
|
Terminal: new (options: {
|
|
@@ -527,3 +634,9 @@ function delay(milliseconds: number): Promise<void> {
|
|
|
527
634
|
function errorMessage(error: unknown): string {
|
|
528
635
|
return error instanceof Error ? error.message : String(error);
|
|
529
636
|
}
|
|
637
|
+
|
|
638
|
+
function createOutputLog(id: string): string {
|
|
639
|
+
const directory = path.join(os.tmpdir(), `pi-agent-ide-terminal-${process.pid}`);
|
|
640
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
641
|
+
return path.join(directory, `${id}.log`);
|
|
642
|
+
}
|
|
@@ -5,6 +5,7 @@ import { defineTool, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
5
5
|
import { Type } from "typebox";
|
|
6
6
|
|
|
7
7
|
import { COMPACT_READ_ROWS } from "#src/extensions/pi-agent-read/src/core/tools/read/read-renderer.js";
|
|
8
|
+
import { formatAgentTerminalSnapshot } from "#src/plugins/pi-agent-ide-terminal/src/output-limits.js";
|
|
8
9
|
import { renderRunCall, renderRunResult } from "#src/plugins/pi-agent-ide-terminal/src/renderer.js";
|
|
9
10
|
|
|
10
11
|
import { shellSyntaxGuidance } from "#src/plugins/pi-agent-ide-terminal/src/shell-profile.js";
|
|
@@ -26,6 +27,14 @@ const runParameters = Type.Object(
|
|
|
26
27
|
description: "Return immediately while the terminal session continues. Defaults to false.",
|
|
27
28
|
}),
|
|
28
29
|
),
|
|
30
|
+
timeoutSeconds: Type.Optional(
|
|
31
|
+
Type.Number({
|
|
32
|
+
minimum: 0.1,
|
|
33
|
+
maximum: 86_400,
|
|
34
|
+
description:
|
|
35
|
+
"Maximum foreground wait in seconds before returning the live session as background. Defaults to 60.",
|
|
36
|
+
}),
|
|
37
|
+
),
|
|
29
38
|
cwd: Type.Optional(
|
|
30
39
|
Type.String({
|
|
31
40
|
description: "Working directory. Relative paths resolve from the current workspace.",
|
|
@@ -46,18 +55,19 @@ export function registerTerminalTools(
|
|
|
46
55
|
pi: ExtensionAPI,
|
|
47
56
|
manager: TerminalSessionManager,
|
|
48
57
|
profile: ShellProfile,
|
|
49
|
-
ui: Pick<TerminalUi, "bind">,
|
|
58
|
+
ui: Pick<TerminalUi, "bind" | "notifyWaitTransition">,
|
|
50
59
|
): void {
|
|
60
|
+
const toolName = process.platform === "win32" ? "powershell" : "bash";
|
|
51
61
|
pi.registerTool(
|
|
52
62
|
defineTool<typeof runParameters, TerminalSessionSnapshot>({
|
|
53
|
-
name:
|
|
54
|
-
label:
|
|
55
|
-
promptSnippet: `
|
|
63
|
+
name: toolName,
|
|
64
|
+
label: profile.displayName,
|
|
65
|
+
promptSnippet: `Execute ${profile.displayName} commands in synchronous or background terminal sessions`,
|
|
56
66
|
promptGuidelines: [
|
|
57
67
|
`Write commands for ${profile.displayName}; commands are not translated between shell languages.`,
|
|
58
|
-
|
|
68
|
+
`Use ${toolName} with background for servers, watchers, and long builds. Foreground waits become background after timeoutSeconds (60 by default), on a stable interactive prompt, or when the turn is aborted. A background session with no output for two minutes wakes an idle agent so it can be inspected. Sessions survive extension reloads and keep the same shell: source. Large output returns a bounded tail and a fullOutput file path. Use the returned shell: source with read, write, insert, and delete.`,
|
|
59
69
|
],
|
|
60
|
-
description: `Use
|
|
70
|
+
description: `Use ${toolName} to execute a command in the user's configured ${profile.displayName} shell (${profile.executable}). Every call creates an addressable terminal session. Set background to true to continue without waiting. A foreground wait automatically returns the live session as background on timeout, a stable interactive prompt, or turn abort; completion is delivered automatically and wakes the agent. Sessions survive extension reloads and keep the same shell: source. Output uses the shared Read limits, keeps the tail, and links a complete log file when truncated. ${shellSyntaxGuidance(profile)}`,
|
|
61
71
|
parameters: runParameters,
|
|
62
72
|
async execute(_toolCallId, input, signal, onUpdate, context) {
|
|
63
73
|
ui.bind(context);
|
|
@@ -76,8 +86,12 @@ export function registerTerminalTools(
|
|
|
76
86
|
return terminalResult(manager.snapshot(session));
|
|
77
87
|
}
|
|
78
88
|
if (session.status === "failed") return terminalResult(manager.snapshot(session));
|
|
79
|
-
const
|
|
80
|
-
|
|
89
|
+
const outcome = await manager.waitForForeground(session.source, {
|
|
90
|
+
signal,
|
|
91
|
+
timeoutMs: (input.timeoutSeconds ?? 60) * 1_000,
|
|
92
|
+
});
|
|
93
|
+
if (outcome.reason === "aborted") ui.notifyWaitTransition(outcome.session);
|
|
94
|
+
return terminalResult(manager.snapshot(outcome.session));
|
|
81
95
|
},
|
|
82
96
|
renderCall(args, theme) {
|
|
83
97
|
const command = typeof args.command === "string" ? args.command : "";
|
|
@@ -97,32 +111,12 @@ export function registerTerminalTools(
|
|
|
97
111
|
}
|
|
98
112
|
|
|
99
113
|
function terminalResult(snapshot: TerminalSessionSnapshot) {
|
|
100
|
-
const excerpt = outputExcerpt(snapshot.output);
|
|
101
|
-
const lines = [
|
|
102
|
-
`session: ${snapshot.source}`,
|
|
103
|
-
`status: ${snapshot.status}`,
|
|
104
|
-
`shell: ${snapshot.shell}`,
|
|
105
|
-
`cwd: ${snapshot.cwd}`,
|
|
106
|
-
`elapsedMs: ${snapshot.elapsedMs}`,
|
|
107
|
-
snapshot.exitCode === undefined ? undefined : `exitCode: ${snapshot.exitCode}`,
|
|
108
|
-
snapshot.signal === undefined ? undefined : `signal: ${snapshot.signal}`,
|
|
109
|
-
snapshot.error === undefined ? undefined : `error: ${snapshot.error}`,
|
|
110
|
-
`outputRange: ${snapshot.outputStart}-${snapshot.outputEnd}`,
|
|
111
|
-
snapshot.truncated ? "output: truncated; use read for the retained log" : undefined,
|
|
112
|
-
excerpt.length === 0 ? "output: (empty)" : `output:\n${excerpt}`,
|
|
113
|
-
].filter((line): line is string => line !== undefined);
|
|
114
114
|
return {
|
|
115
|
-
content: [{ type: "text" as const, text:
|
|
115
|
+
content: [{ type: "text" as const, text: formatAgentTerminalSnapshot(snapshot) }],
|
|
116
116
|
details: snapshot,
|
|
117
117
|
isError: snapshot.status === "failed" || snapshot.status === "lost",
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
function outputExcerpt(output: string): string {
|
|
122
|
-
const plain = stripVTControlCharacters(output).trimEnd();
|
|
123
|
-
return plain.length <= 8_000 ? plain : `[earlier output omitted]\n${plain.slice(-8_000)}`;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
120
|
async function captureInitialBackgroundPreview(
|
|
127
121
|
manager: TerminalSessionManager,
|
|
128
122
|
session: ReturnType<TerminalSessionManager["start"]>,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { IPty } from "node-pty";
|
|
2
2
|
import type { Terminal } from "@xterm/headless";
|
|
3
3
|
|
|
4
|
+
export type TerminalWaitReason = "timeout" | "interactive" | "aborted";
|
|
5
|
+
export type TerminalCompletionReason = "timeout";
|
|
6
|
+
|
|
4
7
|
export type TerminalSessionStatus =
|
|
5
8
|
| "running"
|
|
6
9
|
| "completed"
|
|
@@ -21,12 +24,13 @@ export interface TerminalSession {
|
|
|
21
24
|
readonly id: string;
|
|
22
25
|
readonly source: string;
|
|
23
26
|
readonly command: string;
|
|
24
|
-
|
|
27
|
+
background: boolean;
|
|
25
28
|
readonly cwd: string;
|
|
26
29
|
readonly shell: ShellProfile;
|
|
27
30
|
readonly startedAt: number;
|
|
28
31
|
readonly cols: number;
|
|
29
32
|
readonly rows: number;
|
|
33
|
+
readonly fullOutputPath: string;
|
|
30
34
|
readonly process?: IPty;
|
|
31
35
|
readonly screen: Terminal;
|
|
32
36
|
status: TerminalSessionStatus;
|
|
@@ -40,6 +44,9 @@ export interface TerminalSession {
|
|
|
40
44
|
completion: Promise<TerminalSession>;
|
|
41
45
|
resolveCompletion: (session: TerminalSession) => void;
|
|
42
46
|
completionDelivered: boolean;
|
|
47
|
+
waitReason?: TerminalWaitReason;
|
|
48
|
+
completionReason?: TerminalCompletionReason;
|
|
49
|
+
lastActivityAt: number;
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
export interface TerminalSessionSnapshot {
|
|
@@ -51,6 +58,10 @@ export interface TerminalSessionSnapshot {
|
|
|
51
58
|
readonly shellFamily: ShellProfile["family"];
|
|
52
59
|
readonly background: boolean;
|
|
53
60
|
readonly status: TerminalSessionStatus;
|
|
61
|
+
readonly waitReason?: TerminalWaitReason;
|
|
62
|
+
readonly completionReason?: TerminalCompletionReason;
|
|
63
|
+
readonly lastActivityAt: number;
|
|
64
|
+
readonly idleMs: number;
|
|
54
65
|
readonly startedAt: number;
|
|
55
66
|
readonly endedAt?: number;
|
|
56
67
|
readonly elapsedMs: number;
|
|
@@ -61,6 +72,7 @@ export interface TerminalSessionSnapshot {
|
|
|
61
72
|
readonly outputStart: number;
|
|
62
73
|
readonly outputEnd: number;
|
|
63
74
|
readonly truncated: boolean;
|
|
75
|
+
readonly fullOutputPath: string;
|
|
64
76
|
readonly cols: number;
|
|
65
77
|
readonly rows: number;
|
|
66
78
|
}
|