pi-agent-ide 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/{chunk-TVH2ND35.js → chunk-35LZOKEW.js} +1 -1
- package/dist/chunk-3LVBARLW.js +33 -0
- package/dist/chunk-4GBFIGH3.js +1 -1
- package/dist/{chunk-64JTD2DJ.js → chunk-5PC5INOL.js} +1 -1
- package/dist/{chunk-FKKAHI62.js → chunk-BT2CFM7D.js} +1 -1
- package/dist/{chunk-VN3XBH2Q.js → chunk-DVNL5NZE.js} +1 -1
- package/dist/{chunk-PLMHBXWI.js → chunk-FXPY3V4L.js} +1 -1
- package/dist/{chunk-AJZVKDYC.js → chunk-HGCJDIRR.js} +1 -1
- package/dist/{chunk-RVFMH77U.js → chunk-HISGZD3C.js} +43 -44
- package/dist/{chunk-KFBRL2V4.js → chunk-HKYVP2Q6.js} +1 -1
- package/dist/{chunk-TVXZE4KW.js → chunk-HRBUY2FF.js} +1 -1
- package/dist/{chunk-QM5WDEFI.js → chunk-IOGWZNWT.js} +1 -1
- package/dist/{chunk-HT7LZN5A.js → chunk-IUJUECXH.js} +1 -1
- package/dist/chunk-LXDF2NWX.js +1 -0
- package/dist/{chunk-TVSZYABY.js → chunk-MPNE25CY.js} +1 -1
- package/dist/{chunk-Y74EKJOY.js → chunk-O7V6G3OO.js} +1 -1
- package/dist/chunk-OUCVZBOR.js +28 -0
- package/dist/{chunk-WUO3UW4J.js → chunk-PCGBM2D6.js} +1 -1
- package/dist/{chunk-V4J3TLCV.js → chunk-RIZARTUM.js} +1 -1
- package/dist/{chunk-LTADNZKW.js → chunk-T3Z4KXOX.js} +1 -1
- package/dist/chunk-TSQ6FBTB.js +1 -0
- package/dist/{chunk-CVOYSEBE.js → chunk-VNWGT367.js} +1 -1
- package/dist/{chunk-FS3KCKFX.js → chunk-X2WFNMQR.js} +1 -1
- package/dist/{chunk-7SG756UO.js → chunk-XCPIIDFS.js} +1 -1
- package/dist/entry-0.js +1 -1
- package/dist/entry-1.js +1 -1
- package/dist/entry-10.js +1 -1
- package/dist/entry-11.js +1 -1
- package/dist/entry-12.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -1
- package/dist/entry-16.js +1 -1
- package/dist/entry-17.js +1 -1
- package/dist/entry-18.js +1 -1
- package/dist/entry-19.js +1 -1
- package/dist/entry-2.js +1 -1
- package/dist/entry-20.js +1 -1
- package/dist/entry-21.js +1 -1
- package/dist/entry-22.js +1 -0
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -1
- package/dist/entry-27.js +1 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-3.js +1 -1
- package/dist/entry-30.js +1 -2
- package/dist/entry-31.js +2 -1
- package/dist/entry-32.js +1 -1
- package/dist/entry-33.js +1 -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 -15
- package/dist/entry-38.js +15 -1
- package/dist/entry-39.js +1 -1
- package/dist/entry-4.js +1 -1
- package/dist/entry-40.js +1 -1
- package/dist/entry-41.js +1 -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 -1
- package/dist/entry-46.js +1 -1
- package/dist/entry-47.js +1 -1
- package/dist/entry-48.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-5.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-55.js +1 -1
- package/dist/entry-56.js +1 -1
- package/dist/entry-57.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-6.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 -1
- package/dist/entry-65.js +1 -1
- package/dist/entry-66.js +1 -1
- package/dist/entry-67.js +1 -0
- package/dist/entry-68.js +0 -1
- package/dist/entry-69.js +1 -0
- package/dist/entry-7.js +1 -1
- package/dist/entry-70.js +0 -1
- package/dist/entry-71.js +1 -1
- package/dist/entry-72.js +1 -1
- package/dist/entry-73.js +1 -1
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +1 -1
- package/dist/entry-77.js +1 -0
- package/dist/entry-78.js +0 -1
- package/dist/entry-79.js +1 -0
- package/dist/entry-8.js +1 -1
- package/dist/entry-80.js +0 -1
- package/dist/entry-81.js +1 -1
- package/dist/entry-82.js +1 -1
- package/dist/entry-83.js +1 -1
- package/dist/entry-84.js +1 -1
- package/dist/entry-85.js +1 -2
- package/dist/entry-86.js +2 -1
- package/dist/entry-87.js +1 -1
- package/dist/entry-88.js +1 -1
- package/dist/entry-89.js +1 -1
- package/dist/entry-9.js +1 -1
- package/dist/entry-90.js +1 -3
- package/dist/entry-91.js +3 -1
- package/dist/entry-92.js +1 -1
- package/dist/entry-93.js +1 -1
- package/dist/entry-94.js +1 -0
- package/dist/pi-agent-ide.js +13 -10
- package/docs/agent-guides/editing.md +3 -0
- package/docs/tools.md +2 -2
- package/node_modules/pi-agent-doctor/package.json +7 -7
- package/node_modules/pi-agent-documentation/package.json +2 -2
- package/node_modules/pi-agent-documentation/runtime/entry-30.js +1 -0
- package/node_modules/pi-agent-filesystem/package.json +8 -8
- package/node_modules/pi-agent-filesystem-image/package.json +4 -4
- package/node_modules/pi-agent-filesystem-image/runtime/entry-32.js +2 -0
- package/node_modules/pi-agent-filesystem-jq/package.json +7 -7
- package/node_modules/pi-agent-filesystem-jq/runtime/entry-33.js +0 -1
- 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-36.js +2 -0
- package/node_modules/pi-agent-ide-ast/package.json +15 -15
- package/node_modules/pi-agent-ide-ast/runtime/entry-37.js +0 -1
- package/node_modules/pi-agent-ide-ast/runtime/entry-38.js +2 -0
- package/node_modules/pi-agent-ide-changes/package.json +10 -10
- package/node_modules/pi-agent-ide-changes/runtime/entry-39.js +0 -1
- package/node_modules/pi-agent-ide-formatter/package.json +4 -4
- package/node_modules/pi-agent-ide-languages/package.json +3 -3
- package/node_modules/pi-agent-ide-lint/package.json +8 -8
- package/node_modules/pi-agent-ide-lsp/package.json +13 -13
- package/node_modules/pi-agent-ide-lsp/runtime/entry-44.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 +12 -12
- package/node_modules/pi-agent-read/runtime/entry-51.js +0 -1
- package/node_modules/pi-agent-read/runtime/entry-52.js +2 -0
- package/node_modules/pi-agent-resource/package.json +2 -2
- package/node_modules/pi-agent-search/package.json +9 -9
- package/node_modules/pi-agent-search/runtime/entry-56.js +0 -1
- package/node_modules/pi-agent-search-text/package.json +15 -15
- package/node_modules/pi-agent-search-text/runtime/entry-58.js +1 -0
- package/node_modules/pi-agent-text/package.json +3 -3
- package/node_modules/pi-agent-text/runtime/entry-62.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-63.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-64.js +0 -1
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-65.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-66.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-67.js +2 -0
- package/node_modules/pi-agent-text-editor/package.json +26 -26
- package/node_modules/pi-agent-text-editor/runtime/entry-83.js +0 -1
- package/node_modules/pi-agent-text-editor/src/core/result-transfer.ts +2 -6
- package/node_modules/pi-agent-text-editor/src/core/text-change-engine.ts +17 -36
- package/node_modules/pi-agent-text-editor/src/tools/text-selection.ts +40 -82
- package/node_modules/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +1 -1
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -9
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -3
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -5
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +2 -8
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +6 -6
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +2 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-ui/package.json +3 -3
- package/node_modules/pi-agent-tool-ui/runtime/entry-89.js +1 -0
- package/node_modules/pi-agent-web/package.json +8 -8
- 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-94.js +2 -0
- package/package.json +60 -56
- package/src/api/capabilities.ts +60 -0
- package/src/composite/capabilities.ts +252 -0
- package/src/composite/capability-schemas.ts +53 -0
- package/src/composite/responses-tools.ts +27 -9
- package/src/composite/tool-availability.ts +28 -13
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +8 -8
- 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-image/runtime/entry-32.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/runtime/entry-33.js +0 -1
- 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-36.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-31.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +8 -8
- 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-94.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-90.js +2 -0
- package/src/extensions/pi-agent-read/package.json +12 -12
- package/src/extensions/pi-agent-read/runtime/entry-51.js +0 -1
- package/src/extensions/pi-agent-read/runtime/entry-52.js +2 -0
- package/src/extensions/pi-agent-search/package.json +9 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +15 -15
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-58.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-61.js +1 -0
- package/src/extensions/pi-agent-search/runtime/entry-56.js +0 -1
- package/src/extensions/pi-agent-search/runtime/entry-57.js +2 -0
- package/src/extensions/pi-agent-text-editor/package.json +26 -26
- 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-63.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-64.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-65.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-66.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-67.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-86.js +2 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-83.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-84.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/result-transfer.ts +2 -6
- package/src/extensions/pi-agent-text-editor/src/core/text-change-engine.ts +17 -36
- package/src/extensions/pi-agent-text-editor/src/tools/text-selection.ts +40 -82
- package/src/extensions/pi-agent-text-editor/src/tools/text-tool-schema-properties.ts +1 -1
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +5 -9
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +1 -3
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-insert.ts +7 -5
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +2 -8
- package/src/pi-agent-ide.ts +4 -1
- package/src/plugins/pi-agent-ide-ast/package.json +15 -15
- package/src/plugins/pi-agent-ide-ast/runtime/entry-37.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-38.js +2 -0
- package/src/plugins/pi-agent-ide-changes/package.json +10 -10
- package/src/plugins/pi-agent-ide-changes/runtime/entry-39.js +0 -1
- package/src/plugins/pi-agent-ide-debugger/index.ts +31 -26
- package/src/plugins/pi-agent-ide-formatter/package.json +4 -4
- package/src/plugins/pi-agent-ide-languages/package.json +3 -3
- package/src/plugins/pi-agent-ide-lint/package.json +8 -8
- package/src/plugins/pi-agent-ide-lsp/package.json +13 -13
- package/src/plugins/pi-agent-ide-lsp/runtime/entry-44.js +2 -0
- package/src/plugins/pi-agent-ide-terminal/index.ts +42 -0
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +0 -21
- package/src/plugins/pi-agent-ide-terminal/src/search.ts +0 -3
- package/dist/chunk-7URANI6I.js +0 -28
- package/dist/chunk-K4UTEMDU.js +0 -1
- package/dist/chunk-TNAUCNUT.js +0 -33
- package/dist/entry-23.js +0 -1
- package/node_modules/pi-agent-doctor/runtime/entry-23.js +0 -1
- package/node_modules/pi-agent-filesystem/runtime/entry-30.js +0 -2
- package/node_modules/pi-agent-filesystem-jq/runtime/entry-32.js +0 -1
- package/node_modules/pi-agent-ide-ast/runtime/entry-36.js +0 -1
- package/node_modules/pi-agent-ide-changes/runtime/entry-38.js +0 -1
- package/node_modules/pi-agent-image/runtime/entry-44.js +0 -1
- package/node_modules/pi-agent-resource/runtime/entry-52.js +0 -1
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-62.js +0 -2
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-63.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-65.js +0 -1
- package/node_modules/pi-agent-text-editor/runtime/entry-67.js +0 -1
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-86.js +0 -1
- package/node_modules/pi-agent-web/runtime/entry-89.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-31.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/runtime/entry-32.js +0 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-30.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-90.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-89.js +0 -2
- package/src/extensions/pi-agent-read/runtime/entry-47.js +0 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-57.js +0 -2
- package/src/extensions/pi-agent-search/runtime/entry-53.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-62.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-63.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-65.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-84.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-67.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-36.js +0 -1
- package/src/plugins/pi-agent-ide-changes/runtime/entry-38.js +0 -1
- /package/node_modules/{pi-agent-documentation → pi-agent-doctor}/runtime/entry-29.js +0 -0
- /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-31.js +0 -0
- /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-jq}/runtime/entry-34.js +0 -0
- /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-35.js +0 -0
- /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-40.js +0 -0
- /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-41.js +0 -0
- /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-42.js +0 -0
- /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-43.js +0 -0
- /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-45.js +0 -0
- /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-46.js +0 -0
- /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-47.js +0 -0
- /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-53.js +0 -0
- /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-57.js +0 -0
- /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-61.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-84.js +0 -0
- /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-85.js +0 -0
- /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-87.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-90.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-91.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-92.js +0 -0
- /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-93.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-jq}/runtime/entry-34.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-35.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-91.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-92.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-93.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-85.js +0 -0
- /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-40.js +0 -0
- /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-41.js +0 -0
- /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-42.js +0 -0
- /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-43.js +0 -0
package/dist/chunk-7URANI6I.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import{a as we,b as Se,c as Te}from"./chunk-PBQDHYNX.js";import{a as ye}from"./chunk-L2B4DTVS.js";import{a as ge,b as he,c as O}from"./chunk-WQIMM4SU.js";import"./chunk-4IWEKRSP.js";import{c as fe}from"./chunk-W7CASEO3.js";import{a as ce}from"./chunk-47SPPIXK.js";import{a as le,b as ue}from"./chunk-VAXLSPPU.js";import{a as me}from"./chunk-FYOU4RBH.js";import{d as de}from"./chunk-7PVDTMEM.js";import"./chunk-5S74Z6Y4.js";import{a as _}from"./chunk-GS5ZRTUG.js";import{f as se,g as ae}from"./chunk-KN6VPARZ.js";import{b as C}from"./chunk-OMNKD7WW.js";import"./chunk-PS2B6THP.js";import{a as pe}from"./chunk-GXL4NMHR.js";import{c as ie,d as oe}from"./chunk-PQWANILR.js";import{a as re}from"./chunk-BU7IZLKB.js";import{a as te,b as ne}from"./chunk-S5PL5DFQ.js";import{m as q,n as M}from"./chunk-DDH3FP4G.js";import"./chunk-VDJSH3DQ.js";import"./chunk-ZC65Z3CK.js";import{a as l}from"./chunk-EI7MMDWY.js";import ut from"node:path";import{stripVTControlCharacters as dt}from"node:util";import{truncateLine as ct}from"@earendil-works/pi-coding-agent";import{Text as E}from"@earendil-works/pi-tui";import{DEFAULT_MAX_BYTES as be,DEFAULT_MAX_LINES as ve,formatSize as at,truncateTail as lt}from"@earendil-works/pi-coding-agent";function $(t){return lt(t,{maxBytes:be-4096,maxLines:ve-32})}l($,"terminalOutputTail");function D(t){let e=$(t.output),n=[`session: ${t.source}`,`status: ${t.status}`,`shell: ${t.shell}`,`cwd: ${t.cwd}`,`elapsedMs: ${t.elapsedMs}`,t.exitCode===void 0?void 0:`exitCode: ${t.exitCode}`,t.signal===void 0?void 0:`signal: ${t.signal}`,t.error===void 0?void 0:`error: ${t.error}`,t.waitReason===void 0?void 0:`reason: ${t.waitReason}`,t.completionReason===void 0?void 0:`completionReason: ${t.completionReason}`,t.status==="running"&&t.background?`next: Continue independent work or finish your turn; completion or a one-time idle inspection notice will wake the agent. Read ${t.source} to inspect output; use write or insert when input is needed.`:void 0,`outputRange: ${t.outputStart}-${t.outputEnd}`,t.truncated?"retainedOutput: earlier data omitted from memory":void 0,e.truncated?`fullOutput: ${t.fullOutputPath}`:void 0].filter(o=>o!==void 0),r=e.content.trimEnd();if(!e.truncated)return`${n.join(`
|
|
2
|
-
`)}
|
|
3
|
-
output:${r.length===0?" (empty)":`
|
|
4
|
-
${r}`}`;let i=e.truncatedBy==="lines"?`${ve} line output budget`:`${at(be)} output budget`,a=`[Earlier output omitted: showing the last ${e.outputLines} of ${e.totalLines} lines (${i}). Full output: ${t.fullOutputPath}]`;return`${n.join(`
|
|
5
|
-
`)}
|
|
6
|
-
output:
|
|
7
|
-
${a}${r.length===0?"":`
|
|
8
|
-
${r}`}`}l(D,"formatAgentTerminalSnapshot");var mt=500;function xe(t,e,n,r,i){let a=e?"background":"wait",o=`${i.fg("toolTitle",r.displayName.toLocaleLowerCase())} ${i.fg("muted",`\xB7 ${F(n)} \xB7 ${a}`)}`;return new E(`${o}
|
|
9
|
-
${i.fg("accent",X(r.family))} ${t}`,0,0)}l(xe,"renderRunCall");function Re(t,e,n){let r=e.map(i=>` ${n.fg("dim",i)}`);return r.push(n.fg("success",t==="delete"?"\u2713 stopped":"\u2713 sent")),new E(r.join(`
|
|
10
|
-
`),0,0)}l(Re,"renderTerminalActionResult");function Pe(t,e,n,r,i){let a=[gt(t,i),i.fg("accent",`${e} ${n}`)];return r.length>0&&a.push(...r.map(o=>` ${i.fg("dim",o)}`)),new E(a.join(`
|
|
11
|
-
`),0,0)}l(Pe,"renderTerminalAction");function k(t,e,n,r){let i=ke(t,C,n);return r!==void 0&&i.splice(1,1,n.fg("accent",r)),new E(i.join(`
|
|
12
|
-
`),0,0)}l(k,"renderTerminalResult");function Ee(t,e,n){if(e===!0?e="full":e===!1&&(e="compact"),e==="disabled"){if(!(t.status!==void 0&&!["running","completed"].includes(t.status)||t.exitCode!==void 0&&t.exitCode!==0||t.error!==void 0))return new E(I(t,(u,d)=>n.fg(u,d)),0,0);let o=N(t.output??"",C),s=[...o.omission===void 0?[]:[` ${n.fg("muted",o.omission)}`],...o.lines.map(u=>` ${n.fg("dim",u)}`),...t.error===void 0?[]:[` ${n.fg("error",t.error)}`],I(t,(u,d)=>n.fg(u,d))];return new E(s.join(`
|
|
13
|
-
`),0,0)}if(e==="full"){let a=ke(t,Number.POSITIVE_INFINITY,n).slice(2);return new E(a.join(`
|
|
14
|
-
`),0,0)}let r=N(t.output??"",C),i=[...r.omission===void 0?[]:[` ${n.fg("muted",r.omission)}`],...r.lines.map(a=>` ${n.fg("dim",a)}`)];return i.push(I(t,(a,o)=>n.fg(a,o))),new E(i.join(`
|
|
15
|
-
`),0,0)}l(Ee,"renderRunResult");function Ae(t,e){let n=l((o,s)=>e?.fg(o,s)??s,"color"),i=[`${n("accent",t.shell.toLocaleLowerCase())} ${n("muted",`\xB7 ${F(t.cwd)} \xB7 ${t.background?"background":"wait"}`)}`,`${n("accent",X(t.shellFamily))} ${V(t.command,84)}`],a=pt(t.output,2);return a.length>0&&i.push(...a.map(o=>` ${n("dim",V(o,90))}`)),i.push(I(t,n)),i.join(`
|
|
16
|
-
`)}l(Ae,"renderActiveTerminal");function ke(t,e,n){let r=(t.shell??"terminal").toLocaleLowerCase(),i=t.background===!0?"background":"wait",a=t.cwd===void 0?"workspace":F(t.cwd),o=t.shellFamily??"posix",s=[`${n.fg("accent",r)} ${n.fg("muted",`\xB7 ${a} \xB7 ${i}`)}`,`${n.fg("accent",X(o))} ${t.command??""}`],u=N(t.output??"",e);return u.omission!==void 0&&s.push(` ${n.fg("muted",u.omission)}`),u.lines.length>0&&s.push(...u.lines.map(d=>` ${n.fg("dim",d)}`)),s.push(I(t,(d,c)=>n.fg(d,c))),s}l(ke,"terminalCardLines");function pt(t,e){return N(t,e).lines}l(pt,"outputTail");function N(t,e){let n=$(dt(t).replaceAll("\r","")),r=n.content.split(`
|
|
17
|
-
`).map(u=>ct(u.trimEnd(),mt).text);r.at(-1)===""&&r.pop();let i=Number.isFinite(e)?Math.max(0,e):r.length,a=Math.max(0,r.length-i),o=Math.max(0,n.totalLines-n.outputLines),s=a+o;return{lines:r.slice(a),...n.truncated||s>0?{omission:s>0?`\u2026 ${s} earlier lines`:"\u2026 earlier output omitted"}:{}}}l(N,"outputWindow");function I(t,e){let n=t.status??"running",r=ft(n),i=n==="completed"?"success":n==="running"?"accent":"error",a=[`${r} ${n}`,ht(t.elapsedMs??0)];return t.waitReason!==void 0&&a.push(`background \xB7 ${t.waitReason}`),t.completionReason!==void 0&&a.push(`reason ${t.completionReason}`),t.exitCode!==void 0?a.push(`exit ${t.exitCode}`):t.signal!==void 0&&a.push(`signal ${t.signal}`),e(i,a.join(" \xB7 "))}l(I,"statusLine");function ft(t){return t==="completed"?"\u2713":t==="running"?"\u25CF":t==="stopping"?"\u25CC":"\u2717"}l(ft,"statusIcon");function X(t){return t==="powershell"?"PS>":t==="cmd"?">":"$"}l(X,"promptMarker");function gt(t,e){let n=(t.shell??"terminal").toLocaleLowerCase(),r=t.cwd===void 0?"workspace":F(t.cwd),i=t.background===!0?"background":"wait",a=V(t.command??"process",48);return`${e.fg("toolTitle",n)} ${e.fg("muted",`\xB7 ${r} \xB7 ${i} \xB7 ${a}`)}`}l(gt,"terminalIdentity");function F(t){let e=process.env.HOME;return e!==void 0&&(t===e||t.startsWith(`${e}${ut.sep}`))?`~${t.slice(e.length)}`:t}l(F,"shortCwd");function V(t,e){let n=t.replaceAll(/\s+/gu," ").trim();return n.length<=e?n:`${n.slice(0,e-1)}\u2026`}l(V,"oneLine");function ht(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(t<1e4?1:0)}s`}l(ht,"formatElapsed");function Ce(t){return{id:"terminal",onDidChange:l(e=>t.onDidChange(e),"onDidChange"),list:l(()=>t.list().filter(e=>e.status==="running"||e.status==="stopping").map(e=>({source:e.source,kind:"terminal",title:e.shell.toLocaleLowerCase(),description:e.command,status:e.status==="stopping"?"stopping":"running",...e.pid===void 0?{}:{pid:e.pid,owned:!0},...e.remote===void 0?{}:{remote:e.remote,owned:!0},renderSummary:l(n=>Ae(e,n).split(`
|
|
18
|
-
`),"renderSummary"),renderDetail:l(n=>k(e,!0,n),"renderDetail"),sendInput:l(n=>{Promise.resolve(t.write(e.source,n)).catch(()=>{})},"sendInput"),stop:l(()=>t.delete(e.source),"stop")})),"list")}}l(Ce,"terminalProcessProvider");import{setTimeout as bt}from"node:timers/promises";var yt="#d8dee9",Y="#111418",wt=["#000000","#cd0000","#00cd00","#cdcd00","#0000ee","#cd00cd","#00cdcd","#e5e5e5","#7f7f7f","#ff0000","#00ff00","#ffff00","#5c5cff","#ff00ff","#00ffff","#ffffff"];async function K(t,e,n,r=1){let i=t.get(e);if(i===void 0)throw new Error(`Unknown terminal session ${e}`);await i.screenReady;let{createCanvas:a}=await import("@napi-rs/canvas"),o=Math.max(0,Math.min(i.rows-1,n?.start??0)),s=Math.max(1,Math.min(i.rows-o,n?.count??i.rows)),u=i.cols*9+24,d=s*18+24,c=a(Math.max(1,Math.round(u*r)),Math.max(1,Math.round(d*r))),m=c.getContext("2d");m.scale(r,r),m.fillStyle=Y,m.fillRect(0,0,c.width,c.height),m.textBaseline="top";let p=i.screen.buffer.active,h=Math.max(0,p.baseY);for(let g=0;g<s;g+=1){let S=p.getLine(h+o+g);if(S!==void 0)for(let y=0;y<i.cols;y+=1){let x=S.getCell(y);x===void 0||x.getWidth()===0||St(m,x,y,g)}}return i.status==="running"&&p.cursorY>=o&&p.cursorY<o+s&&(m.fillStyle="rgba(216, 222, 233, 0.75)",m.fillRect(12+p.cursorX*9,12+(p.cursorY-o)*18+18-2,9,2)),c.toBuffer("image/png").toString("base64")}l(K,"renderTerminalScreen");function St(t,e,n,r){let i=$e(e,"foreground"),a=$e(e,"background");e.isInverse()&&([i,a]=[a,i]);let o=12+n*9,s=12+r*18;a!==Y&&(t.fillStyle=a,t.fillRect(o,s,9*Math.max(1,e.getWidth()),18));let u=e.getChars();u.length!==0&&(t.font=`${e.isBold()?"bold ":""}14px monospace`,t.fillStyle=i,t.fillText(u,o,s),e.isUnderline()&&t.fillRect(o,s+18-2,9*Math.max(1,e.getWidth()),1))}l(St,"drawCell");function $e(t,e){let n=e==="foreground";if(n?t.isFgDefault():t.isBgDefault())return n?yt:Y;let i=n?t.isFgRGB():t.isBgRGB(),a=n?t.getFgColor():t.getBgColor();return i?`#${a.toString(16).padStart(6,"0")}`:Tt(a)}l($e,"cellColor");function Tt(t){let e=wt[t];if(e!==void 0)return e;if(t>=232){let s=8+(t-232)*10;return Ie(s,s,s)}let n=Math.max(0,t-16),r=Math.floor(n/36),i=Math.floor(n%36/6),a=n%6,o=l(s=>s===0?0:55+s*40,"channel");return Ie(o(r),o(i),o(a))}l(Tt,"ansiColor");function Ie(t,e,n){return`#${[t,e,n].map(r=>r.toString(16).padStart(2,"0")).join("")}`}l(Ie,"rgb");var Z="\0pi-terminal-write\0",J="\0pi-terminal-keys\0";function vt(t){let e=t?.find(u=>u==="image"||u==="sequence"||u.startsWith("image:")||u.startsWith("sequence:"));if(e===void 0)return;let n=e.indexOf(":"),r=n<0?e:e.slice(0,n),i=new Map;if(n>=0)for(let u of e.slice(n+1).split(",")){let[d,c,m]=u.split("=");if(d===void 0||c===void 0||m!==void 0||c.length===0)throw new Error(`Invalid terminal ${r} view parameter: ${u}`);if(d!=="duration"&&d!=="interval"&&d!=="scale")throw new Error(`Unsupported terminal ${r} view parameter: ${d}`);let p=Number(c);if(!Number.isFinite(p))throw new Error(`Terminal ${d} must be a number`);i.set(d,p)}let a=i.get("duration")??2,o=i.get("interval")??.5,s=i.get("scale")??1;if(!(s>0&&s<=1))throw new Error("Terminal image scale must be greater than 0 and at most 1");if(r==="sequence"){if(!(a>0&&a<=10))throw new Error("Terminal sequence duration must be greater than 0 and at most 10 seconds");if(!(o>0))throw new Error("Terminal sequence interval must be greater than 0 seconds");if(Math.floor(a/o)+1>20)throw new Error("Terminal sequence capture is limited to 20 frames")}return{mode:r,duration:a,interval:o,scale:s}}l(vt,"parseTerminalVisualView");async function Oe(t,e){let n=new Map,r=new Map,i={protocol:te,apiVersion:ne,id:"terminal",setup(o){o.addResolver({resolver:xt(e),preserveTruncatedOutput:!0,renderResult(s,u,d){let c=s.details,m=c.source===void 0?void 0:e.get(c.source),p=m===void 0?{}:e.snapshot(m);return k(m===void 0?p:{...p,output:e.screenTail(m).join(`
|
|
19
|
-
`)},u.expanded,d,"read terminal")}}),o.addHandler({stage:"pre-read",async handler(s){let u=s.request.path;if(u===void 0||!v(u))return{kind:"continue",context:s};let d;try{d=vt(s.request.views)}catch(m){return{kind:"return",result:z(u,m instanceof Error?m.message:String(m))}}if(d===void 0)return{kind:"continue",context:s};let c=e.get(u);if(c===void 0)return{kind:"return",result:z(u,`Unknown terminal session ${u}`)};try{e.markInspected(u);let m=d.mode==="image"?1:Math.floor(d.duration/d.interval)+1,p=[];for(let h=0;h<m;h+=1){s.resolverContext.signal?.throwIfAborted(),h>0&&await bt(d.interval*1e3,void 0,{signal:s.resolverContext.signal});let g=await K(e,u,void 0,d.scale);p.push({type:"image",data:g,mimeType:"image/png"})}return{kind:"return",result:{content:p,script:{kind:"native",source:c.source,blocks:p},details:{source:c.source,resolvedBy:"terminal",frames:m,mode:d.mode}}}}catch(m){return{kind:"return",result:z(u,m instanceof Error?m.message:String(m))}}}}),o.describe({path:"shell:<session> \u2014 status and output tail.",views:"On shell:<session>: image[:scale=S] \u2014 screen image; sequence[:duration=D,interval=I,scale=S] \u2014 frames over time, up to 10 s and 20 frames."})}},a={protocol:ie,apiVersion:oe,id:"terminal",setup(o){o.addResolver({resolver:Rt(e)}),o.tool("write").addHandler({stage:"text-pre-edit",handler:l(async s=>(Me(s.input,e,n),await Le(s.input,e,r),Pt(s,Z)),"handler")}),o.tool("insert").addHandler({stage:"text-pre-edit",handler:l(async s=>(await Le(s.input,e,r),Me(s.input,e,n),Et(s)),"handler")});for(let s of["write","insert","delete"])o.addToolRenderer({tool:s,matches:l((u,d)=>$t(u,d),"matches"),renderCall(u,d,c){let m=u,p=typeof m.path=="string"?e.get(m.path):void 0,h=c.state;return p!==void 0&&(h.snapshot=e.snapshot(p)),Pe(h.snapshot??{},s,_e(s,m),[],d)},renderResult(u,d,c){let m=Ct(u.details);return Re(m.action,m.changedLines,c)}});o.describe("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."),o.tool("write").describeField("path","shell:<session> types into that terminal."),o.tool("delete").describeField("path","shell:<session> ends that session."),o.tool("write").describeField("content","For shell:<session>, exact input; Enter is not added."),o.tool("insert").describeField("path","shell:<session> sends keys to that terminal."),o.tool("insert").describeField("anchor","Omit for shell:<session>."),o.tool("insert").describeField("text","For shell:<session>: named keys and chords such as Enter, Ctrl+C, Up, or caret forms such as ^C, separated by spaces or commas.")}};await Promise.all([re(t,i),pe(t,a)]),t.on("tool_result",async(o,s)=>{if(!R(o.input))return;let u=o.input.path;if(o.toolName==="replace"&&typeof u=="string"&&v(u)){let w=`replace is unsupported for ${u}; use write for text, insert for keys, or delete to terminate and remove the session.`;return M({content:[{type:"text",text:w}],details:o.details},_(o.toolName),{status:"error",errors:[q(w,"UNSUPPORTED_OPERATION",u)],data:{operation:"replace",effect:"not-applied",files:[{source:u,effect:"not-applied"}]}})}if(o.toolName==="delete"&&typeof u=="string"&&v(u)){let w=e.get(u);if(w===void 0)return;let A=e.snapshot(w);return e.delete(u).then(()=>M({content:[{type:"text",text:`Deleted terminal session ${u}.`}],details:{source:u,deleted:!0,snapshot:A,action:"delete",input:"session",changedLines:[]}},_(o.toolName),{status:"success",errors:[],data:{operation:"delete",effect:"applied",files:[{source:u,effect:"applied"}]}}),T=>M({content:[{type:"text",text:T instanceof Error?T.message:String(T)}],details:{source:u,deleted:!1}},_(o.toolName),{status:"error",errors:[q(T,"TERMINAL_DELETE_FAILED",u)],data:{operation:"delete",effect:"unknown",files:[{source:u,effect:"unknown"}]}}))}if(o.toolName!=="write"&&o.toolName!=="insert"||o.isError)return;let d=o.input.path;if(typeof d!="string"||!v(d))return;let c=e.get(d);if(c===void 0)return;let m=r.get(d)??e.screenRows(c);r.delete(d);let p=n.get(d)??c.outputStart+c.output.length;n.delete(d),await e.waitForOutputAfter(c,p);let h=e.snapshot(c),g=o.toolName,S=_e(g,o.input),y=e.screenChangeRegion(c,m,6),x=[{type:"text",text:`Sent ${S} to ${c.source}.`}];return s.model?.input.includes("image")===!0&&x.push({type:"image",data:await K(e,d,{start:y.startRow,count:y.lines.length}),mimeType:"image/png"}),{content:x,details:{source:c.source,action:g,status:c.status,snapshot:h,input:S,changedLines:y.lines},isError:o.isError,...o.structuredContent===void 0?{}:{structuredContent:o.structuredContent}}})}l(Oe,"registerTerminalResources");function xt(t){return{id:"terminal",async tryResolve(e){if(!v(e))return{kind:"not-handled"};let n=t.get(e);return n===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${e}`)}:{kind:"resolved",resource:{source:n.source,async read(){t.markInspected(n.source);let r=t.snapshot(n);return[{type:"text",text:At(r)}]}}}}}}l(xt,"createReadResolver");function Rt(t){return{id:"terminal-input",async tryResolve(e){if(!v(e))return{kind:"not-handled"};let n=t.get(e);return n===void 0?{kind:"failed",error:new Error(`Unknown terminal session ${e}`)}:{kind:"resolved",resource:{source:n.source,skipPostEdit:!0,async read(){return[{type:"text",text:"terminal input"}]},async write(r){let i=kt(r),a=i.indexOf(Z),o=i.indexOf(J);if(a>=0){await t.write(n.source,i.slice(a+Z.length));return}if(o>=0){await t.sendKeys(n.source,i.slice(o+J.length).trim());return}throw new Error(`Unsupported text operation for ${n.source}`)}}}}}}l(Rt,"createInputResolver");function Pt(t,e){return!R(t.input)||!De(t.input.path)?t:{...t,input:{...t.input,content:`${e}${typeof t.input.content=="string"?t.input.content:""}`}}}l(Pt,"transformWriteInput");function Et(t){if(!R(t.input)||!De(t.input.path))return t;if(t.input.before===!0)throw new Error("Shell keys can only be inserted after the active input position");return{...t,input:{...t.input,anchor:"end",before:!1,text:`${J}${typeof t.input.text=="string"?t.input.text:""}`}}}l(Et,"transformInsertInput");function At(t){return D(t)}l(At,"formatSnapshot");function kt(t){if(t.length!==1||t[0].type!=="text")throw new Error("Terminal input must contain one text block");return t[0].text}l(kt,"singleText");function z(t,e){return{content:[{type:"text",text:e}],details:{source:t,failure:{code:"READ_FAILED",source:t,resolverId:"terminal",message:e}},isError:!0}}l(z,"failure");function v(t){return/^shell:[a-f\d]{12}$/u.test(t)}l(v,"isShellSource");function De(t){return typeof t=="string"&&v(t)}l(De,"isShellSourceValue");function Ct(t){if(!R(t)||!R(t.snapshot))throw new TypeError("Invalid terminal action result");let e=t.snapshot,n=t.action;if(n!=="write"&&n!=="insert"&&n!=="delete")throw new TypeError("Invalid terminal action");return{source:typeof t.source=="string"?t.source:"shell:unknown",action:n,input:typeof t.input=="string"?t.input:"",changedLines:Array.isArray(t.changedLines)?t.changedLines.filter(r=>typeof r=="string"):[],snapshot:{...typeof e.shell=="string"?{shell:e.shell}:{},...typeof e.cwd=="string"?{cwd:e.cwd}:{},...typeof e.command=="string"?{command:e.command}:{},...typeof e.background=="boolean"?{background:e.background}:{},...typeof e.status=="string"?{status:e.status}:{}}}}l(Ct,"terminalActionDetails");async function Le(t,e,n){if(!R(t)||typeof t.path!="string"||!v(t.path))return;let r=e.get(t.path);r!==void 0&&await r.screenReady,r!==void 0&&n.set(t.path,e.screenRows(r))}l(Le,"rememberScreen");function Me(t,e,n){if(!R(t)||typeof t.path!="string"||!v(t.path))return;let r=e.get(t.path);r!==void 0&&n.set(t.path,r.outputStart+r.output.length)}l(Me,"rememberOutputEnd");function _e(t,e){if(t==="delete")return"session";let n=t==="write"?e.content:e.text,r=typeof n=="string"?n:"";return t==="write"?`text ${JSON.stringify(r)}`:`keys ${r}`}l(_e,"terminalInputLabel");function $t(t,e){if(!R(t))return!1;if(e==="call")return typeof t.path=="string"&&v(t.path);let n=t.details;return R(n)&&typeof n.source=="string"&&v(n.source)}l($t,"isTerminalRenderValue");function R(t){return typeof t=="object"&&t!==null}l(R,"isRecord");async function Ne(t,e){await ce(t,{protocol:le,apiVersion:ue,id:"terminal",setup(r){r.addResolver({resolver:It(e),priority:100}),r.describe("path shell:<session> searches the retained text output of that terminal, including rows outside its current screen.")}})}l(Ne,"registerTerminalSearch");function It(t){return{readResources:l(e=>e.path?.startsWith("shell:")?[e.path]:[],"readResources"),id:"terminal",toScriptData(e){let n=B(e);return de(n.matches,!1)},async tryResolve(e){if(e.path===void 0||!e.path.startsWith("shell:"))return{kind:"not-handled"};let n=t.get(e.path);if(n===void 0)return{kind:"failed",error:new Error(`Unknown terminal session ${e.path}`)};let r=t.snapshot(n),i=Lt(r,e);return{kind:"resolved",payload:{snapshot:r,query:e.query,matches:i}}},format(e){let n=B(e),r=n.matches.map(i=>`${n.snapshot.source}:${i.lineNumber}: ${i.lineText}`);return{content:[{type:"text",text:r.length===0?`No matches in ${n.snapshot.source}`:`${r.join(`
|
|
20
|
-
`)}
|
|
21
|
-
|
|
22
|
-
${r.length} match${r.length===1?"":"es"} in ${n.snapshot.source}`}],details:{source:n.snapshot.source,payload:n}}},renderResult(e,n,r){let i=e.details,a=Q(i)?B(i.payload):B(void 0);return me(a.matches,!1,r,n.expanded===!0,void 0,[`Retained terminal output \xB7 ${a.snapshot.status} \xB7 read-only`])}}}l(It,"terminalSearchResolver");function Lt(t,e){let n=e.caseSensitive===!0?e.query:e.query.toLocaleLowerCase();if(n.length===0)return[];let r=[],i=e.limit??100;for(let[a,o]of t.output.replaceAll("\r","").split(`
|
|
23
|
-
`).entries()){let s=e.caseSensitive===!0?o:o.toLocaleLowerCase(),u=0;for(;r.length<i;){let d=s.indexOf(n,u);if(d<0)break;let c=d+n.length;(e.wholeWord!==!0||Mt(s,d,c))&&r.push({source:t.source,lineNumber:a+1,startColumn:d,endColumn:c,matchedText:o.slice(d,c),lineText:o}),u=Math.max(c,d+1)}if(r.length>=i)break}return r}l(Lt,"findTerminalMatches");function Mt(t,e,n){return!/[\p{L}\p{N}_]/u.test(t[e-1]??"")&&!/[\p{L}\p{N}_]/u.test(t[n]??"")}l(Mt,"isWordBoundary");function B(t){if(!_t(t))throw new TypeError("Invalid terminal search result");return t}l(B,"parsePayload");function _t(t){return Q(t)&&typeof t.query=="string"&&Array.isArray(t.matches)&&Q(t.snapshot)&&typeof t.snapshot.source=="string"}l(_t,"isTerminalSearchPayload");function Q(t){return typeof t=="object"&&t!==null}l(Q,"isRecord");import{spawn as Dt}from"node:child_process";import{closeSync as Nt,mkdirSync as Ft,openSync as Bt,rmSync as Wt,writeSync as jt}from"node:fs";import Ut from"node:os";import je from"node:path";import{createRequire as Ht}from"node:module";import{randomUUID as Gt}from"node:crypto";import{stripVTControlCharacters as qt}from"node:util";import{StringDecoder as Vt}from"node:string_decoder";import Ot from"node:os";import Fe from"node:path";var W={executable:"/bin/bash",displayName:"Bash over SSH",family:"posix",commandArgs:l(t=>["-lc",t],"commandArgs")};function Be(t=process.platform,e=process.env){if(t==="win32"){let i=e.SHELL?.trim()||"powershell.exe",a=Fe.win32.basename(i).toLowerCase();return a==="cmd"||a==="cmd.exe"?{executable:i,displayName:"Command Prompt",family:"cmd",commandArgs:l(o=>["/d","/s","/c",o],"commandArgs")}:{executable:i,displayName:a.startsWith("pwsh")?"PowerShell":"Windows PowerShell",family:"powershell",commandArgs:l(o=>["-NoLogo","-NoProfile","-Command",o],"commandArgs")}}let n=e.SHELL?.trim()||Ot.userInfo().shell||(t==="darwin"?"/bin/zsh":"/bin/bash"),r=Fe.basename(n);return{executable:n,displayName:r==="zsh"?"zsh":r==="bash"?"Bash":r,family:"posix",commandArgs:l(i=>["-c",i],"commandArgs")}}l(Be,"resolveShellProfile");function We(t){switch(t.family){case"powershell":return"Write PowerShell syntax. Use PowerShell cmdlets, `$env:NAME` for environment variables, and `;` or pipelines to compose commands.";case"cmd":return"Write Command Prompt syntax. Use `%NAME%` for environment variables and `&&` to chain successful commands.";case"posix":return`Write ${t.displayName} syntax. Use POSIX-style paths, \`$NAME\` for environment variables, and \`&&\` or pipelines to compose commands.`}}l(We,"shellSyntaxGuidance");var Ge=Ht(new URL("../src/plugins/pi-agent-ide-terminal/src/session-manager.ts",import.meta.url).href),Ue=1e6,Xt=100,Yt=30,Kt=2e3,zt=50,L=class{static{l(this,"TerminalSessionManager")}#l;#e=new Map;#r=new Set;#i=new Set;#o=new Map;#s=new Map;#u=!1;constructor(e=Qt){this.#l=e}onDidChange(e){return this.#r.add(e),()=>this.#r.delete(e)}onDidComplete(e){return this.#i.add(e),()=>this.#i.delete(e)}list(){return[...this.#e.values()].sort((e,n)=>n.startedAt-e.startedAt).map(e=>this.snapshot(e))}get(e){return this.#e.get(en(e))}snapshot(e,n=Date.now()){return{id:e.id,source:e.source,...e.origin===void 0?{}:{origin:e.origin},command:e.command,cwd:e.cwd,shell:e.shell.displayName,shellFamily:e.shell.family,...e.process===void 0?{}:{pid:e.process.pid},...e.remote===void 0?{}:{remote:{target:e.remote.target,pid:e.remote.process.pid,...e.remote.process.identity===void 0?{}:{identity:e.remote.process.identity}}},background:e.background,status:e.status,...e.waitReason===void 0?{}:{waitReason:e.waitReason},...e.completionReason===void 0?{}:{completionReason:e.completionReason},lastActivityAt:e.lastActivityAt,idleMs:Math.max(0,n-e.lastActivityAt),startedAt:e.startedAt,...e.endedAt===void 0?{}:{endedAt:e.endedAt},elapsedMs:(e.endedAt??n)-e.startedAt,...e.exitCode===void 0?{}:{exitCode:e.exitCode},...e.signal===void 0?{}:{signal:e.signal},...e.error===void 0?{}:{error:e.error},output:e.output,outputStart:e.outputStart,outputEnd:e.outputStart+e.output.length,truncated:e.outputStart>0,fullOutputPath:e.fullOutputPath,cols:e.cols,rows:e.rows}}start(e){let n=this.#d(e),{id:r,cols:i,rows:a}=n,o;try{let u=Ge("node-pty"),d={name:"xterm-256color",cols:i,rows:a,cwd:e.cwd,env:nn(tn()),...globalThis.process.platform==="win32"?{useConptyDll:!0}:{}};o=u.spawn(e.shell.executable,[...e.shell.commandArgs(e.command)],d)}catch(u){let d={...n,status:"failed",endedAt:Date.now(),error:j(u)};return this.#e.set(r,d),this.#n(r),n.resolveCompletion(d),queueMicrotask(()=>this.#a(d)),d}let s={...n,process:o};return this.#e.set(r,s),o.onData(u=>this.#c(s,u)),globalThis.process.platform==="win32"&&s.screen.onData(u=>{if(!P(s.status))try{o.write(u)}catch{}}),o.onExit(({exitCode:u,signal:d})=>{P(s.status)||(s.endedAt=Date.now(),s.exitCode=u,d!==0&&(s.signal=d),s.status=s.status==="stopping"?"stopped":u===0?"completed":"failed",(u===124||u===137)&&(s.completionReason="timeout"),this.#n(s.id),s.resolveCompletion(s),this.#t(s),this.#a(s))}),this.#t(s),s}#d(e){if(this.#u)throw new Error("Terminal session manager is closed");let n=this.#l();if(!/^[a-f0-9]{12}$/u.test(n)||this.#e.has(n)||this.#s.has(n))throw new Error("Terminal session IDs must be unique 12-character hexadecimal values");let r=sn(n);this.#o.set(n,Bt(r,"a",384));let i=e.cols??Xt,a=e.rows??Yt,o=Jt(i,a),s=l(d=>{},"resolveCompletion"),u=new Promise(d=>{s=d});return{id:n,source:`shell:${n}`,command:e.command,background:e.background,cwd:e.cwd,shell:e.shell,startedAt:Date.now(),lastActivityAt:Date.now(),cols:i,rows:a,fullOutputPath:r,screen:o,status:"running",output:"",outputStart:0,screenReady:Promise.resolve(),completion:u,resolveCompletion:s,completionDelivered:!1,staleReminderDelivered:!1}}async startRemote(e){let n=W,r=this.#d({...e,cwd:e.remote.location.source,shell:n}),i=new AbortController;this.#s.set(r.id,{abort:i,completion:r.completion});let a=l(()=>i.abort(),"abortStartup");e.signal?.addEventListener("abort",a,{once:!0}),e.signal?.aborted&&a();try{let o=await e.remote.backend.startProcess(n.executable,n.commandArgs(e.command),e.remote.location.path,{pty:{cols:r.cols,rows:r.rows},signal:i.signal}).finally(()=>e.signal?.removeEventListener("abort",a)),s={...r,remote:{target:e.remote.location.target,process:o}};this.#e.set(s.id,s);let u=new Vt("utf8");o.stdout.on("data",c=>this.#c(s,u.write(c))),o.stderr.resume();let d=l(()=>{this.#c(s,u.end()),s.endedAt=Date.now(),this.#n(s.id),s.resolveCompletion(s),this.#t(s),this.#a(s)},"finish");return o.completion.then(({exitCode:c})=>{s.exitCode=c,c<0&&(s.signal=-c),s.status=s.status==="stopping"?"stopped":c===0?"completed":"failed",(c===124||c===137)&&(s.completionReason="timeout"),d()},c=>{s.status="lost",s.error=j(c),d()}),this.#t(s),s}catch(o){let s={...r,status:"failed",endedAt:Date.now(),error:j(o)};return this.#e.set(s.id,s),this.#n(s.id),s.resolveCompletion(s),queueMicrotask(()=>this.#a(s)),s}finally{this.#s.delete(r.id)}}async wait(e,n){let r=this.required(e);return P(r.status)?r:n?.aborted===!0?(await this.stop(r.source,"cancelled"),r):await new Promise((i,a)=>{let o=l(()=>{this.stop(r.source,"cancelled").then(i,a)},"onAbort");n?.addEventListener("abort",o,{once:!0}),r.completion.then(s=>{n?.removeEventListener("abort",o),i(s)},a)})}async waitForForeground(e,n){let r=this.required(e);if(P(r.status))return{session:r};let i=n.interactiveDelayMs??3e3;return await new Promise(a=>{let o=!1,s,u=l(p=>{o||(p!==void 0&&P(r.status)&&(p=void 0),o=!0,clearTimeout(c),clearInterval(m),n.signal?.removeEventListener("abort",d),p!==void 0&&(r.background=!0,p!=="aborted"&&(r.waitReason=p),this.#t(r)),a({session:r,...p===void 0?{}:{reason:p}}))},"finish"),d=l(()=>u("aborted"),"onAbort"),c=setTimeout(()=>u("timeout"),n.timeoutMs),m=setInterval(()=>{if(!Zt(r)){s=void 0;return}s??=Date.now(),Date.now()-s>=i&&u("interactive")},Math.min(100,Math.max(10,i/2)));n.signal?.addEventListener("abort",d,{once:!0}),n.signal?.aborted===!0&&d(),r.completion.then(()=>u())})}async waitForOutputAfter(e,n){let r=Date.now()+300,i=n,a;for(;Date.now()<r;){let o=e.outputStart+e.output.length;if(o!==i)i=o,a=Date.now(),await e.screenReady;else if(a!==void 0&&Date.now()-a>=40)return;await ee(10)}await e.screenReady}screenRows(e){let n=e.screen.buffer.active;return Array.from({length:e.rows},(r,i)=>(n.getLine(n.baseY+i)?.translateToString(!0)??"").trimEnd())}screenChangeRegion(e,n,r=6){let i=this.screenRows(e),a=Math.max(1,Math.min(e.rows,r)),o=Math.max(0,e.screen.buffer.active.cursorY-Math.floor(a/2)),s=-1;for(let c=0;c<=e.rows-a;c+=1){let m=0;for(let p=c;p<c+a;p+=1){let h=n[p]??"",g=i[p]??"",S=g.length>0&&!n.includes(g),y=h.length>0&&g.length===0;h!==g&&(S||y)&&(m+=1)}m>s&&(s=m,o=c)}let u=e.screen.buffer.active;return{lines:i.slice(o,o+a).map((c,m)=>{if(o+m!==u.cursorY)return c;let h=c.padEnd(u.cursorX," ");return`${h.slice(0,u.cursorX)}\u258C${h.slice(u.cursorX)}`}),startRow:o}}screenChangeWindow(e,n,r=6){return this.screenChangeRegion(e,n,r).lines}screenTail(e,n=e.rows){let r=e.screen.buffer.active,i=Math.max(0,r.baseY),a=[];for(let o=0;o<e.rows;o+=1){let s=r.getLine(i+o)?.translateToString(!0).trimEnd();s!==void 0&&s.length>0&&a.push(s)}return a.slice(-Math.max(0,n))}markInspected(e){let n=this.required(e);n.status==="running"&&(n.lastActivityAt=Date.now(),this.#t(n))}write(e,n){let r=this.requiredRunning(e);if(r.remote)return r.remote.process.write(Buffer.from(n)).catch(i=>{throw r.error=j(i),this.#t(r),i});r.process?.write(n)}sendKeys(e,n){return this.write(e,rn(n))}async stop(e,n="stopped"){let r=this.required(e);return P(r.status)||(r.status="stopping",this.#t(r),await He(r,!1),await Promise.race([r.completion.then(()=>!0),ee(Kt).then(()=>!1)])||(await He(r,!0),await Promise.race([r.completion,ee(1e3)])),P(r.status)||(r.status=n,r.endedAt=Date.now(),this.#n(r.id),r.resolveCompletion(r),this.#a(r)),n==="cancelled"&&(r.status="cancelled"),this.#t(r)),r}async delete(e){let n=this.required(e);n.completionDelivered=!0,await this.stop(n.source),n.screen.dispose(),this.#n(n.id),Wt(n.fullOutputPath,{force:!0}),this.#e.delete(n.id),this.#t(n)}async screenLines(e){let n=this.required(e);await n.screenReady;let r=n.screen.buffer.active,i=[],a=Math.max(0,r.baseY);for(let o=a;o<a+n.rows;o+=1)i.push(r.getLine(o)?.translateToString(!0)??"");return i}cursor(e){let n=this.required(e);return{x:n.screen.buffer.active.cursorX,y:n.screen.buffer.active.cursorY}}async dispose(){if(this.#u)return;this.#u=!0;let e=[...this.#s.values()];for(let n of e)n.abort.abort();await Promise.all(e.map(n=>n.completion)),await Promise.all([...this.#e.values()].filter(n=>!P(n.status)).map(n=>this.stop(n.source)));for(let n of this.#e.values())n.screen.dispose(),this.#n(n.id);this.#r.clear(),this.#i.clear()}required(e){let n=this.get(e);if(n===void 0)throw new Error(`Unknown terminal session ${e}`);return n}requiredRunning(e){let n=this.required(e);if(n.status!=="running")throw new Error(`Terminal session ${n.source} is ${n.status}; input is unavailable`);return n}#c(e,n){e.lastActivityAt=Date.now();let r=qt(n),i=this.#o.get(e.id);if(i!==void 0&&jt(i,r),e.output+=r,e.output.length>Ue){let a=e.output.length-Ue;e.output=e.output.slice(a),e.outputStart+=a}e.screenReady=e.screenReady.then(()=>new Promise(a=>{e.screen.write(n,a)})),this.#t(e)}#n(e){let n=this.#o.get(e);n!==void 0&&(Nt(n),this.#o.delete(e))}#t(e){for(let n of this.#r)n(e)}#a(e){for(let n of this.#i)n(e);this.#m()}#m(){let e=[...this.#e.values()].filter(n=>P(n.status)).sort((n,r)=>(r.endedAt??0)-(n.endedAt??0));for(let n of e.slice(zt))n.background&&!n.completionDelivered||(n.screen.dispose(),this.#n(n.id),this.#e.delete(n.id))}};function Zt(t){if(t.status!=="running")return!1;let e=t.screen.buffer.active,n=e.getLine(e.baseY+e.cursorY)?.translateToString(!0).trimEnd()??"";return/\[[^\]\n]{1,20}(?:\/[^\]\n]{1,20})+\]\s*[:?>]?\s*$/iu.test(n)||/(?:choose|select|enter|password|confirm|continue|proceed)[^\n]{0,60}[:?]\s*$/iu.test(n)||/^(?:❯|›)\s+\S/u.test(n)}l(Zt,"looksInteractive");function Jt(t,e){let{Terminal:n}=Ge("@xterm/headless");return new n({cols:t,rows:e,scrollback:2e3,allowProposedApi:!0})}l(Jt,"createScreen");function Qt(){return Gt().replaceAll("-","").slice(0,12)}l(Qt,"defaultSessionId");function en(t){return t.startsWith("shell:")?t.slice(6):t}l(en,"normalizeSessionId");function P(t){return t!=="running"&&t!=="stopping"}l(P,"isTerminalStatus");function tn(){return process.env}l(tn,"processEnvironment");function nn(t){return{...Object.fromEntries(Object.entries(t).filter(e=>e[1]!==void 0)),PAGER:"cat",GIT_PAGER:"cat",SYSTEMD_PAGER:"cat",GH_PAGER:"cat"}}l(nn,"cleanEnvironment");function rn(t){return t.split(/[\s,]+/u).filter(Boolean).map(on).join("")}l(rn,"encodeTerminalKeys");function on(t){if(/^\^[?@A-Z[\\\]^_]$/iu.test(t)){let c=t.slice(1).toUpperCase();return c==="?"?"\x7F":String.fromCharCode(c.charCodeAt(0)&31)}let e=t.toLowerCase().split("+"),n=e.pop()??"",r=new Set(e);if([...r].some(c=>!["ctrl","control","alt","meta","shift"].includes(c)))throw new Error(`Unsupported terminal key ${t}`);let i=r.has("ctrl")||r.has("control"),a=r.has("alt")||r.has("meta"),o=r.has("shift");if(i&&n.length===1&&/[a-z@[\\\]^_?]/u.test(n)){let c=n.toUpperCase(),m=c==="?"?"\x7F":String.fromCharCode(c.charCodeAt(0)&31);return a?`\x1B${m}`:m}let s={enter:"\r",tab:" ",escape:"\x1B",esc:"\x1B",backspace:"\x7F",home:"\x1B[H",end:"\x1B[F",delete:"\x1B[3~"};if(!i&&!a&&!o&&s[n]!==void 0)return s[n];if(a&&!i&&!o&&s[n]!==void 0)return`\x1B${s[n]}`;let d={up:"A",down:"B",right:"C",left:"D",home:"H",end:"F"}[n];if(d!==void 0)return!i&&!a&&!o?`\x1B[${d}`:`\x1B[1;${1+(o?1:0)+(a?2:0)+(i?4:0)}${d}`;if(a&&!i&&n.length===1)return`\x1B${o?n.toUpperCase():n}`;throw new Error(`Unsupported terminal key ${t}`)}l(on,"encodeTerminalKey");async function He(t,e){if(t.remote){await t.remote.process.stop().catch(()=>{});return}let n=t.process;if(n!==void 0){if(globalThis.process.platform!=="win32")try{globalThis.process.kill(-n.pid,e?"SIGKILL":"SIGTERM");return}catch{try{n.kill(e?"SIGKILL":"SIGTERM")}catch{}return}await new Promise(r=>{let i=Dt("taskkill.exe",["/PID",String(n.pid),"/T",...e?["/F"]:[]],{windowsHide:!0,stdio:"ignore"});i.once("error",()=>r()),i.once("exit",()=>r())})}}l(He,"terminateProcessTree");function ee(t){return new Promise(e=>setTimeout(e,t))}l(ee,"delay");function j(t){return t instanceof Error?t.message:String(t)}l(j,"errorMessage");function sn(t){let e=je.join(Ut.tmpdir(),`pi-agent-ide-terminal-${process.pid}`);return Ft(e,{recursive:!0,mode:448}),je.join(e,`${t}.log`)}l(sn,"createOutputLog");import{AgentSession as an}from"@earendil-works/pi-coding-agent";var U=Symbol.for("pi-agent-ide.terminal-steering-observers");function qe(t){let e=an.prototype,n=e[U]??ln(e);return n.listeners.add(t),()=>{n.listeners.delete(t),n.listeners.size===0&&n.restore()}}l(qe,"observeQueuedSteering");function ln(t){let e=t.prompt,n=t.steer,r=new Set,i=l(u=>{for(let d of[...r])d(u)},"notify"),a=l(function(u,d){return d?.streamingBehavior!=="steer"?e.call(this,u,d):e.call(this,u,{...d,preflightResult:l(c=>{d.preflightResult?.(c),c==="queued"&&i(this)},"preflightResult")})},"prompt"),o=l(async function(...u){let d=await n.apply(this,u);return d==="queued"&&i(this),d},"steer");t.prompt=a,t.steer=o;let s={listeners:r,restore:l(()=>{t[U]===s&&(t.prompt===a&&(t.prompt=e),t.steer===o&&(t.steer=n),delete t[U])},"restore")};return t[U]=s,s}l(ln,"installObservers");import Ke from"node:path";import{stripVTControlCharacters as dn}from"node:util";import{defineTool as cn}from"@earendil-works/pi-coding-agent";import{Type as b}from"typebox";import{Text as mn}from"@earendil-works/pi-tui";import{open as un}from"node:fs/promises";import{Type as f}from"typebox";var Ve=1024*1024,Xe=f.Object({output:f.String({description:"ANSI-free PTY output, up to 1 MiB. Longer output joins the first and last 512 KiB without adding labels or an omission marker. See output_ranges for the gap."}),truncated:f.Boolean({description:"Whether output omits bytes from the retained log. This is independent of whether the process has finished."}),full_output_path:f.String({description:"UTF-8 log of all output received so far. Available until the shell session is deleted."}),output_ranges:f.Array(f.Object({start:f.Integer(),end:f.Integer()}),{description:"Zero-based, end-exclusive UTF-8 byte ranges in the log, concatenated into output."}),exit_code:f.Optional(f.Number({description:"Process exit code, only when known."})),wall_time_seconds:f.Number(),session:f.String({description:"Session ID."}),source:f.String({description:"Persistent shell: source for Read, input and termination."}),status:f.Union(["running","completed","failed","stopping","stopped","cancelled","lost"].map(t=>f.Literal(t))),background:f.Boolean(),cwd:f.String({description:"Actual working directory; SSH sessions retain their canonical ssh:// target URI."}),remote:f.Optional(f.Object({target:f.String(),pid:f.Integer({minimum:1})},{description:"Remote process identity, never a local native PID."})),wait_reason:f.Optional(f.Union([f.Literal("timeout"),f.Literal("interactive"),f.Literal("steering")])),completion_reason:f.Optional(f.Literal("timeout")),signal:f.Optional(f.Number()),error:f.Optional(f.String())});async function Ye(t){let e=await un(t.fullOutputPath,"r");try{let n=(await e.stat()).size,r=l(async(s,u)=>{let d=Buffer.alloc(u),c=0;for(;c<u;){let m=await e.read(d,c,u-c,s+c);if(m.bytesRead===0)throw new Error("Shell output log ended before its snapshot size");c+=m.bytesRead}return d},"readRange"),i,a,o=n>Ve;if(!o)i=(await r(0,n)).toString("utf8"),a=[{start:0,end:n}];else{let s=Ve/2,u=await r(0,s),d=await r(n-s,s),c=new TextDecoder().decode(u,{stream:!0}),m=0;for(;m<d.length&&(d.readUInt8(m)&192)===128;)m++;let p=d.subarray(m).toString("utf8");i=c+p,a=[{start:0,end:Buffer.byteLength(c)},{start:n-s+m,end:n}]}return{output:i,truncated:o,full_output_path:t.fullOutputPath,output_ranges:a,...t.exitCode===void 0?{}:{exit_code:t.exitCode},wall_time_seconds:t.elapsedMs/1e3,session:t.id,source:t.source,status:t.status,background:t.background,cwd:t.cwd,...t.remote===void 0?{}:{remote:t.remote},...t.waitReason===void 0?{}:{wait_reason:t.waitReason},...t.completionReason===void 0?{}:{completion_reason:t.completionReason},...t.signal===void 0?{}:{signal:t.signal},...t.error===void 0?{}:{error:t.error}}}finally{await e.close()}}l(Ye,"structuredShellResult");var pn=l(t=>b.Object({command:b.String({minLength:1,description:`Command for ${t.displayName} (${t.executable}). ${We(t)}`}),background:b.Optional(b.Boolean({description:"Set true to return after an initial output preview instead of waiting for completion. Defaults to false."})),timeoutSeconds:b.Optional(b.Number({minimum:.1,maximum:86400,description:"Set the foreground wait limit in seconds. On expiry, the live session returns in background without stopping the process. Ignored when background is true. Defaults to 60."})),cwd:b.Optional(b.String({description:"Working directory. Relative paths resolve from the current workspace."})),cols:b.Optional(b.Integer({minimum:20,maximum:300,description:"Virtual terminal width in cells"})),rows:b.Optional(b.Integer({minimum:5,maximum:120,description:"Virtual terminal height in cells"}))},{additionalProperties:!1}),"createRunParameters");function ze(t,e,n,r,i="compact",a=new O([]),o){let s=new Set,u=process.platform==="win32"?"powershell":"bash",d=pn(n);return t.registerTool(cn({name:u,exposure:"direct",namespace:{name:"ide_terminal",description:"Run shell commands in persistent terminal sessions."},annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!0},label:n.displayName,promptSnippet:`Execute ${n.displayName} commands in synchronous or background terminal sessions`,promptGuidelines:[`Edit files with the edit tools, not ${u}.`],description:`Use ${u} to execute a command in the user's configured shell. Each call creates a new terminal session and returns its shell: source for inspection and interaction.`,parameters:d,outputSchema:Xe,async execute(c,m,p,h,g){r.bind(g);let S=o?.(c,g),y=a.resolve(m.cwd??g.cwd,g.cwd),x={command:m.command,background:m.background??!1,...m.cols===void 0?{}:{cols:m.cols},...m.rows===void 0?{}:{rows:m.rows}},w=y?await e.startRemote({...x,remote:y,...p===void 0?{}:{signal:p}}):e.start({...x,cwd:m.cwd===void 0?g.cwd:Ke.resolve(g.cwd,m.cwd),shell:n});if(w.origin??=S,m.background===!0&&w.status!=="failed")return await fn(e,w,h),w.status!=="running"&&(w.completionDelivered=!0),H(e.snapshot(w));if(w.status==="failed")return H(e.snapshot(w));let A=new AbortController;s.add(A);let T;try{T=await e.waitForForeground(w.source,{signal:p===void 0?A.signal:AbortSignal.any([p,A.signal]),timeoutMs:(m.timeoutSeconds??60)*1e3})}finally{s.delete(A)}return T.reason==="aborted"&&A.signal.aborted&&p?.aborted!==!0?(T.session.waitReason="steering",H(e.snapshot(T.session))):(T.reason==="aborted"&&r.notifyWaitTransition(T.session),H(e.snapshot(T.session)))},renderCall(c,m,p){if((p.expanded?"full":i)==="disabled")return new mn(m.fg("toolTitle",u),0,0);let g=typeof c.command=="string"?c.command:"",S=typeof c.cwd=="string"&&c.cwd.startsWith("ssh:"),y=typeof c.cwd=="string"?S?c.cwd:Ke.resolve(process.cwd(),c.cwd):process.cwd();return xe(g,c.background===!0,y,S?W:n,m)},renderResult(c,m,p){return Ee(c.details,m.expanded?"full":i,p)}})),()=>{for(let c of s)c.abort()}}l(ze,"registerTerminalTools");function Ze(t){let e=$(t.output).content;return{content:[{type:"text",text:D(t)}],details:{...t,output:e,outputStart:t.outputEnd-e.length,truncated:t.truncated||e.length<t.output.length},isError:t.status==="failed"||t.status==="lost"}}l(Ze,"terminalPreview");async function H(t){return{...Ze(t),structuredContent:await Ye(t)}}l(H,"terminalResult");async function fn(t,e,n){await new Promise(r=>{let i=!1,a,o=l(()=>{},"unsubscribe"),s=l(()=>{i||(i=!0,clearTimeout(a),o(),r())},"finish"),u=l(()=>{let d=t.snapshot(e);n?.(Ze(d)),(dn(d.output).replaceAll("\r","").split(`
|
|
24
|
-
`).filter(m=>m.length>0).length>=C||d.status!=="running")&&s()},"publish");o=t.onDidChange(d=>{d.id===e.id&&u()}),a=setTimeout(s,2e3),u()})}l(fn,"captureInitialBackgroundPreview");import{Box as et,Container as tt}from"@earendil-works/pi-tui";var gn=120,hn=12e4,G=class{constructor(e,n,r=hn){this.pi=e;this.manager=n;this.staleIntervalMs=r;e.registerMessageRenderer("terminal-stale",(i,{expanded:a},o)=>Je(i.details,a,o)),e.registerMessageRenderer("terminal-completion",(i,{expanded:a},o)=>Qe(i.details,a,o)),e.registerEntryRenderer("terminal-stale-display",(i,{expanded:a},o)=>Je(i.data,a,o)),e.registerEntryRenderer("terminal-completion-display",(i,{expanded:a},o)=>Qe(i.data,a,o)),this.#u=[n.onDidChange(i=>this.#d(i)),n.onDidComplete(i=>{this.#a(i.id),i.background&&this.#m(i)})]}static{l(this,"TerminalUi")}#l=new Map;#e;#r=new Map;#i=new Set;#o;#s=!1;#u;bind(e){this.#o=e;for(let n of this.manager.list()){let r=this.manager.get(n.id);r===void 0||!r.background||(r.status==="running"?this.#d(r):r.status!=="stopping"&&this.#m(r))}}onAgentSettled(e){this.#o=e;for(let n of[...this.#i]){this.#i.delete(n);let r=this.manager.get(n);r!==void 0&&this.#d(r,!0)}}notifyWaitTransition(e){let n=this.#n(e);this.pi.sendMessage({customType:"terminal-wait-transition",display:!1,content:`Terminal wait ended; ${n.source} is still running in background. Read it to inspect output, then use write or insert to send input.`,details:n},{triggerTurn:!0,deliverAs:"steer"})}dispose(){this.#s=!0,this.#e!==void 0&&clearTimeout(this.#e),this.#e=void 0,this.#l.clear();for(let e of this.#r.values())clearTimeout(e);this.#r.clear(),this.#i.clear(),this.#o=void 0;for(let e of this.#u)e()}#d(e,n=!1){if(this.#a(e.id),this.#s||e.staleReminderDelivered||!e.background||e.status!=="running")return;let r=this.#n(e),i=Math.max(0,this.staleIntervalMs-r.idleMs);if(n&&i===0){this.#c(e);return}this.#r.set(e.id,setTimeout(()=>this.#c(e),i))}#c(e){if(this.#r.delete(e.id),this.#s||e.staleReminderDelivered||e.status!=="running"||!e.background)return;if(this.#o?.isIdle()!==!0){this.#i.add(e.id);return}e.staleReminderDelivered=!0;let n=this.#n(e);this.pi.sendMessage({customType:"terminal-stale",display:!1,content:Sn(n),details:n},{triggerTurn:!0,deliverAs:"followUp"}),this.pi.appendEntry("terminal-stale-display",{...n,...this.#t(n)})}#n(e){return{...this.manager.snapshot(e),...e.origin===void 0?{}:{origin:e.origin}}}#t(e){let n=e.origin;return n!==void 0&&n.sessionId===this.#o?.sessionManager.getSessionId()?{parentToolCallId:n.parentToolCallId}:{}}#a(e){let n=this.#r.get(e);n!==void 0&&clearTimeout(n),this.#r.delete(e),this.#i.delete(e)}#m(e){this.#s||e.completionDelivered||(this.#l.set(e.id,e),this.#e===void 0&&(this.#e=setTimeout(()=>{this.#e=void 0;let n=[...this.#l.values()].filter(a=>!a.completionDelivered);if(this.#l.clear(),this.#s||n.length===0)return;for(let a of n)a.completionDelivered=!0;let r=n.map(a=>this.#n(a));this.pi.sendMessage({customType:"terminal-completion",display:!1,content:wn(r),details:{sessions:r}},{triggerTurn:!0,deliverAs:"steer"});let i=new Map;for(let a of r){let o=this.#t(a).parentToolCallId,s=i.get(o)??[];s.push(a),i.set(o,s)}for(let[a,o]of i)this.pi.appendEntry("terminal-completion-display",{sessions:o,...a===void 0?{}:{parentToolCallId:a}})},gn)))}};function Je(t,e,n){let r=new tt;nt(t)&&r.addChild(k(t,e,n,"stale \xB7 inspect session"));let i=new et(1,1,a=>n.bg("toolPendingBg",a));return i.addChild(r),i}l(Je,"renderStale");function Qe(t,e,n){let r=new tt;for(let a of yn(t))r.addChild(k(a,e,n));let i=new et(1,1,a=>n.bg("toolSuccessBg",a));return i.addChild(r),i}l(Qe,"renderCompletion");function yn(t){return!it(t)||!Array.isArray(t.sessions)?[]:t.sessions.filter(nt)}l(yn,"completionSnapshots");function nt(t){return it(t)&&typeof t.id=="string"&&typeof t.source=="string"&&typeof t.command=="string"&&typeof t.cwd=="string"&&typeof t.shell=="string"&&typeof t.background=="boolean"&&typeof t.status=="string"&&typeof t.startedAt=="number"&&typeof t.elapsedMs=="number"&&typeof t.output=="string"}l(nt,"isTerminalSessionSnapshot");function wn(t){return`${t.length===1?"Background terminal completed:":"Background terminals completed:"}
|
|
25
|
-
${t.map(n=>{let r=n.exitCode===void 0?"":`, exit ${n.exitCode}`,i=n.completionReason===void 0?"":`, reason ${n.completionReason}`,a=n.output.trimEnd().slice(-2e3);return`- ${n.source}: ${n.status}${r}${i}, ${rt(n.elapsedMs)}
|
|
26
|
-
${a||"(no output)"}`}).join(`
|
|
27
|
-
`)}`}l(wn,"formatCompletionMessage");function Sn(t){let e=t.output.trimEnd().slice(-2e3);return`Background terminal ${t.source} has produced no output for ${rt(t.idleMs)}. Inspect it with read. If it is healthy, keep waiting; otherwise send input or stop it.
|
|
28
|
-
${e||"(no output)"}`}l(Sn,"formatStaleMessage");function rt(t){return t<1e3?`${t}ms`:`${(t/1e3).toFixed(t<1e4?1:0)}s`}l(rt,"formatElapsed");function it(t){return typeof t=="object"&&t!==null}l(it,"isRecord");function ot(t){let e=new Map;return t.on("tool_call",n=>{let r=n.parentToolCallId;e.set(n.toolCallId,r===void 0?n.toolCallId:e.get(r)??r)}),t.on("tool_result",n=>{e.delete(n.toolCallId)}),t.on("agent_end",()=>{e.clear()}),t.on("session_shutdown",()=>{e.clear()}),(n,r)=>({toolCallId:n,parentToolCallId:e.get(n)??n,sessionId:r.sessionManager.getSessionId()})}l(ot,"registerTerminalOrigins");function st(t){return t==="full"||t==="disabled"?t:"compact"}l(st,"toolPresentation");async function Tn(t,e){ae(t,[await se({id:"terminal",description:"Foreground and background commands, shell resources, and processes",triggers:[{tool:"bash"},{tool:"powershell"},...["read","write","insert","delete"].map(d=>({tool:d,resourcePrefixes:["shell:"]}))]})]);let n=Se("terminal",L)??new L,r=Be(),i=new O(await he(ge(fe()))),a=new G(t,n),o=ye(t).add(Ce(n));await Promise.all([Oe(t,n),Ne(t,n)]);let s=ze(t,n,r,a,st(e?.preferences["ui.terminal"]),i,ot(t)),u=l(()=>{},"removeSteeringObserver");t.on("session_start",(d,c)=>{a.bind(c),u(),u=qe(m=>{m.sessionManager===c.sessionManager&&s()})}),t.on("agent_settled",(d,c)=>a.onAgentSettled(c)),t.on("session_shutdown",async d=>{if(u(),a.dispose(),o(),d.reason!=="quit"){we("terminal",n);return}Te("terminal",n),await n.dispose()})}l(Tn,"registerTerminal");export{Tn as default};
|
package/dist/chunk-K4UTEMDU.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-PLMHBXWI.js";import"./chunk-47SPPIXK.js";import"./chunk-VAXLSPPU.js";import"./chunk-FYOU4RBH.js";import"./chunk-7PVDTMEM.js";import"./chunk-MPT3R4BL.js";import"./chunk-KN6VPARZ.js";import"./chunk-PS2B6THP.js";import"./chunk-BU7IZLKB.js";import"./chunk-S5PL5DFQ.js";import"./chunk-DDH3FP4G.js";import"./chunk-EI7MMDWY.js";export{a as default};
|
package/dist/chunk-TNAUCNUT.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import{a as Ge,b as We,c as ze}from"./chunk-PBQDHYNX.js";import{a as Je}from"./chunk-L2B4DTVS.js";import{a as Ve}from"./chunk-AMIIOWFL.js";import{a as qe}from"./chunk-LF325WYO.js";import{a as Ue,b as He,c as Me}from"./chunk-WQIMM4SU.js";import{a as K,g as v}from"./chunk-4IWEKRSP.js";import{c as Fe}from"./chunk-W7CASEO3.js";import{a as N}from"./chunk-K5G4FDXD.js";import{a as ue,b as P,c as T}from"./chunk-R2U5WXYR.js";import{f as Ce,g as je}from"./chunk-KN6VPARZ.js";import{a as Be}from"./chunk-MDD5ORB6.js";import{b as $e,c as Le}from"./chunk-MLFJU2US.js";import{e as xe}from"./chunk-PS2B6THP.js";import{a as Oe}from"./chunk-GXL4NMHR.js";import{c as Ie,d as Te}from"./chunk-PQWANILR.js";import{a as Re}from"./chunk-BU7IZLKB.js";import{a as _e,b as Ae}from"./chunk-S5PL5DFQ.js";import{j as ke,m as Ee,n as de}from"./chunk-DDH3FP4G.js";import"./chunk-VDJSH3DQ.js";import{d as Ne}from"./chunk-756K3LJY.js";import{a as d}from"./chunk-EI7MMDWY.js";import B from"node:path";import{access as Vr}from"node:fs/promises";import{StringEnum as Et}from"@earendil-works/pi-ai";import{defineTool as Mr}from"@earendil-works/pi-coding-agent";import{Type as y}from"typebox";async function X(r,e=process.env,t=process.platform,n=o=>Ne(o,r,e)){if(e.PI_PYTHON_PATH!==void 0)return{command:e.PI_PYTHON_PATH,args:[]};let o=t==="win32"?[{command:"python",args:[]},{command:"python3",args:[]},{command:"py",args:["-3"]}]:[{command:"python3",args:[]},{command:"python",args:[]}];for(let a of o)if(await n(a.command))return a;return o[0]}d(X,"resolvePythonDebuggerCommand");import qt from"cross-spawn";import{cp as Vt,mkdtemp as Mt,readdir as Jt,rm as Gt,stat as Y}from"node:fs/promises";import{tmpdir as Wt}from"node:os";import zt from"node:net";import A from"node:path";import{pathToFileURL as Kt}from"node:url";import{createMessageConnection as Xt,StreamMessageReader as Yt,StreamMessageWriter as Zt}from"vscode-jsonrpc/node";import Nt from"cross-spawn";import Ft from"node:net";var Ut=new Set(["initialized","stopped","continued","terminated","exited","loadedSource","breakpoint","custom"]),Ht=128,S=class r{static{d(this,"DapClient")}#o;#a;#r;#t;#i;#e=new Map;#u=[];#d=new Set;#m=new Set;#l=Buffer.alloc(0);#f=1;#p;#h;#b;constructor(e,t,n,o){this.#o=e,this.#a=t,this.#r=n,this.#t=o,o&&o.completion.then(()=>this.#s(new Error("Debug adapter transport completed")),a=>this.#s(a instanceof Error?a:new Error("Debug adapter transport failed"))),e.on("data",a=>this.#v(a)),e.once("error",a=>this.#s(a)),t.once("error",a=>this.#s(a)),e.once("close",()=>this.#s(new Error("Debug adapter connection closed"))),n!==void 0&&(n.stderr.on("data",a=>{process.env.PI_DEBUG_DAP_TRACE==="1"&&process.stderr.write(a)}),n.once("error",a=>this.#s(a)),n.once("exit",(a,i)=>{this.#s(new Error(`Debug adapter exited${a===null?"":` with code ${a}`}${i===null?"":` (${i})`}`))}))}static start(e,t,n){let a=Nt(e,[...t],{cwd:n,env:process.env,stdio:["pipe","pipe","pipe"]});return new r(a.stdout,a.stdin,a)}static fromTransport(e){return new r(e.readable,e.writable,void 0,e)}static fromSocket(e,t=1){let n=new r(e,e);return n.#f=t,n}static connect(e,t="127.0.0.1"){return new Promise((n,o)=>{let a=Ft.createConnection({port:e,host:t}),i=d(s=>o(s),"fail");a.once("error",i),a.once("connect",()=>{a.off("error",i),n(new r(a,a))})})}onReverseRequest(e){this.#h=e}onEvent(e){return this.#m.add(e),()=>this.#m.delete(e)}request(e,t,n={}){if(this.#p!==void 0)return Promise.reject(this.#p);if(n.signal?.aborted===!0)return Promise.reject(n.signal.reason instanceof Error?n.signal.reason:new Error("Debug operation aborted"));["continue","next","stepIn","stepOut"].includes(e)&&(this.#b=void 0);let o=this.#f++,a={seq:o,type:"request",command:e,...t===void 0?{}:{arguments:t}},i=new Promise((s,u)=>{let c,l=d(()=>{c!==void 0&&clearTimeout(c),n.signal?.removeEventListener("abort",p)},"cleanup"),p=d(()=>{this.#e.delete(o),l(),u(n.signal?.reason instanceof Error?n.signal.reason:new Error("Debug operation aborted"))},"abort");n.timeoutMs!==void 0&&(c=setTimeout(()=>{this.#e.delete(o),l(),u(new Error(`Timed out waiting for debug response ${e}`))},n.timeoutMs)),this.#e.set(o,{resolve:d(m=>s(m),"resolve"),reject:u,cleanup:l}),n.signal?.addEventListener("abort",p,{once:!0})});return this.#w(a),i}takeEvent(e){let t=this.#u.findIndex(n=>e.includes(n.event));return t<0?void 0:this.#u.splice(t,1)[0]}waitForEvent(e,t=3e4){return this.waitForAnyEvent([e],t)}waitForAnyEvent(e,t=3e4,n){let o=new Set(e),a=this.#u.findIndex(i=>o.has(i.event));return a>=0?Promise.resolve(this.#u.splice(a,1)[0]):this.#p!==void 0?Promise.reject(this.#p):new Promise((i,s)=>{let u={events:o,resolve:d(l=>{clearTimeout(u.timer),this.#d.delete(u),i(l)},"resolve"),reject:d(l=>{clearTimeout(u.timer),this.#d.delete(u),s(l)},"reject"),timer:setTimeout(()=>{this.#d.delete(u),s(new Error(`Timed out waiting for debug event ${e.join(" or ")}`))},t)};this.#d.add(u);let c=d(()=>u.reject(n?.reason instanceof Error?n.reason:new Error("Debug operation aborted")),"abort");n?.aborted===!0?c():n?.addEventListener("abort",c,{once:!0})})}close(){this.#o.destroy(),this.#a.destroy(),this.#r!==void 0&&!this.#r.killed&&this.#r.kill(),this.#s(new Error("Debug adapter closed")),this.#t&&!this.#i&&(this.#i=Promise.resolve().then(()=>this.#t?.stop()),this.#i.catch(()=>{}))}async dispose(){this.close(),await this.#i}#w(e){let t=Buffer.from(JSON.stringify(e),"utf8");this.#a.write(Buffer.concat([Buffer.from(`Content-Length: ${t.length}\r
|
|
2
|
-
\r
|
|
3
|
-
`),t]))}#v(e){for(this.#l=Buffer.concat([this.#l,e]);;){let t=this.#l.indexOf(`\r
|
|
4
|
-
\r
|
|
5
|
-
`);if(t<0)return;let n=this.#l.subarray(0,t).toString("ascii"),o=/^Content-Length:\s*(\d+)$/imu.exec(n);if(o===null){this.#s(new Error("Debug adapter sent a frame without Content-Length"));return}let a=Number(o[1]),i=t+4;if(this.#l.length<i+a)return;let s=this.#l.subarray(i,i+a).toString("utf8");this.#l=this.#l.subarray(i+a);try{this.#y(JSON.parse(s))}catch(u){this.#s(u instanceof Error?u:new Error(String(u)));return}}}#y(e){if(e.type==="event")if(e.event==="stopped"){let t=JSON.stringify(e.body??null);if(t===this.#b)return;this.#b=t}else e.event==="continued"&&(this.#b=void 0);if(e.type==="response"){let t=this.#e.get(e.request_seq);if(t===void 0)return;this.#e.delete(e.request_seq),t.cleanup(),e.success?t.resolve(e.body):t.reject(new Error(`${e.command}: ${e.message??"failed"}`));return}if(e.type==="event"){for(let n of this.#m)n(e);let t=[...this.#d].find(n=>n.events.has(e.event));t!==void 0?t.resolve(e):Ut.has(e.event)&&(this.#u.length===Ht&&this.#u.shift(),this.#u.push(e));return}this.#g(e)}async#g(e){try{if(this.#h===void 0)throw new Error(`Client does not support reverse request ${e.command}`);let t=await this.#h(e);this.#w({seq:this.#f++,type:"response",request_seq:e.seq,success:!0,command:e.command,...t===void 0?{}:{body:t}})}catch(t){this.#w({seq:this.#f++,type:"response",request_seq:e.seq,success:!1,command:e.command,message:t instanceof Error?t.message:String(t)})}}#s(e){if(this.#p===void 0){this.#p=e;for(let t of this.#e.values())t.cleanup(),t.reject(e);this.#e.clear();for(let t of this.#d)t.reject(e);this.#d.clear()}}};function Q(r=process.env){return r.PI_JAVA_PATH??(r.JAVA_HOME===void 0?"java":A.join(r.JAVA_HOME,"bin",process.platform==="win32"?"java.exe":"java"))}d(Q,"javaExecutable");async function ee(r=process.env,e=process.platform){let t=r.PI_JDTLS_HOME??"/opt/pi-debug-adapters/jdtls",n=r.PI_JAVA_DEBUG_PLUGIN_PATH??"/opt/pi-debug-adapters/java-debug/com.microsoft.java.debug.plugin-0.53.2.jar",o=A.join(t,e==="win32"?"config_win":"config_linux");try{let a=(await Jt(A.join(t,"plugins"))).filter(s=>/^org\.eclipse\.equinox\.launcher_[^/]+\.jar$/u.test(s));if(a.length!==1)throw new Error("Expected one Equinox launcher jar");let i=A.join(t,"plugins",a[0]);if(!(await Y(i)).isFile()||!(await Y(n)).isFile()||!(await Y(o)).isDirectory())throw new Error("Expected JDT LS configuration and Java debug plugin files");return{launcher:i,configuration:o,plugin:n}}catch(a){throw new Error(`Java debugger requires JDT LS (PI_JDTLS_HOME) and java-debug plugin (PI_JAVA_DEBUG_PLUGIN_PATH): ${a instanceof Error?a.message:String(a)}`,{cause:a})}}d(ee,"javaDebuggerFiles");var U=class{static{d(this,"JavaDebugRuntime")}#o;#a;#r;#t;#i;#e;get processIds(){return[this.#o?.pid,this.#a?.pid].filter(e=>e!==void 0)}async start(e,t){if(t.throwIfAborted(),e.mainClass===void 0)throw new Error("Java debug sessions require mainClass");let n=await er(e),o=await this.connect(e.cwd,t);t.throwIfAborted(),this.#a=this.#d(["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=127.0.0.1:0","-cp",n.join(A.delimiter),e.mainClass,...e.args],e.cwd,process.env);let a=await tr(this.#a,t),i=A.dirname(e.sourceFile);for(let s of e.mainClass.split(".").slice(1))i=A.dirname(i);return{client:o,attach:{hostName:"127.0.0.1",port:a,timeout:1e4,sourcePaths:[i]}}}async connect(e,t,n=process.env){t.throwIfAborted();let o=await ee(n);this.#i=await Mt(A.join(Wt(),"pi-java-debug-"));let a=A.join(this.#i,"configuration");await Vt(o.configuration,a,{recursive:!0});let i={...n};delete i.CLIENT_PORT,delete i.CLIENT_HOST,t.throwIfAborted(),this.#o=this.#d(["-Declipse.application=org.eclipse.jdt.ls.core.id1","-Dosgi.bundles.defaultStartLevel=4","-Declipse.product=org.eclipse.jdt.ls.core.product","-Xmx512m","--add-modules=ALL-SYSTEM","--add-opens","java.base/java.util=ALL-UNNAMED","--add-opens","java.base/java.lang=ALL-UNNAMED","-jar",o.launcher,"-configuration",a,"-data",A.join(this.#i,"workspace")],e,i);let s=this.#o;await Z(new Promise((g,f)=>{s.once("spawn",g),s.once("error",f)}),t);let u=new AbortController,c=new class extends Zt{async write(g){try{await super.write(g)}catch(f){u.abort(f)}}}(s.stdin),l=Xt(new Yt(s.stdout),c);this.#r=l;let p="";s.stderr.on("data",g=>{p=(p+g.toString()).slice(-4e3)}),s.once("error",g=>u.abort(g)),s.once("exit",g=>u.abort(new Error(`Java debugger language server exited (${String(g)}): ${p}`)));let m=AbortSignal.any([t,u.signal]);l.onRequest("workspace/configuration",g=>g.items.map(()=>null)),l.onRequest("client/registerCapability",()=>null),l.onRequest("window/workDoneProgress/create",()=>null),l.listen(),await Z(l.sendRequest("initialize",{processId:process.pid,rootUri:Kt(e).href,capabilities:{},initializationOptions:{bundles:[o.plugin],settings:{java:{import:{gradle:{enabled:!1},maven:{enabled:!1}}}}}}),m),await l.sendNotification("initialized",{});let b=await Z(l.sendRequest("workspace/executeCommand",{command:"vscode.java.startDebugSession",arguments:[]}),m);if(typeof b!="number"||!Number.isInteger(b)||b<1||b>65535)throw new Error("JDT LS did not return a Java DAP port; check PI_JAVA_DEBUG_PLUGIN_PATH");return this.#t=await Qt(b,m),this.#t}close(){return this.#e??=this.#u(),this.#e}async#u(){this.#t?.close(),this.#r?.dispose(),await Promise.all([Ke(this.#a),Ke(this.#o)]),this.#i!==void 0&&await Gt(this.#i,{recursive:!0,force:!0,maxRetries:10,retryDelay:100})}#d(e,t,n){let o=qt(Q(n),[...e],{cwd:t,env:n,stdio:"pipe",windowsHide:!0});return o.stdin.on("error",()=>{}),o}};function Qt(r,e){return e.throwIfAborted(),new Promise((t,n)=>{let o=zt.createConnection({port:r,host:"127.0.0.1"}),a=d(()=>{o.destroy(),n(e.reason)},"abort"),i=d(()=>{e.removeEventListener("abort",a)},"cleanup");e.addEventListener("abort",a,{once:!0}),o.once("error",s=>{i(),n(s)}),o.once("connect",()=>{i(),t(S.fromSocket(o))})})}d(Qt,"connectDap");async function er(r){let e=`${r.mainClass.replaceAll(".",A.sep)}.class`,t=["build/classes/java/main","target/classes","out/production","bin","."],n=[];for(let o of t){let a=A.resolve(r.cwd,o);try{(await Y(A.join(a,e))).isFile()&&n.push(a)}catch{}}if(n.length===0)throw new Error(`Java main class ${r.mainClass} is not compiled. Compile with javac -g into build/classes/java/main, target/classes, out/production, bin, or the project directory.`);return n}d(er,"javaClassPaths");async function Z(r,e){let t=d(()=>{},"abort"),n=new Promise((o,a)=>{t=d(()=>a(e.reason),"abort"),e.addEventListener("abort",t,{once:!0}),e.aborted&&t()});try{return await Promise.race([r,n])}finally{e.removeEventListener("abort",t)}}d(Z,"bounded");function tr(r,e){return Z(new Promise((t,n)=>{let o="",a=d(i=>{o=(o+i.toString()).slice(-4e3);let s=/Listening for transport dt_socket at address: (\d+)/u.exec(o);s!==null&&t(Number(s[1]))},"consume");r.stdout.on("data",a),r.stderr.on("data",a),r.once("error",n),r.once("exit",i=>n(new Error(`Java target exited before JDWP was ready (${String(i)}): ${o}`)))}),e)}d(tr,"targetReady");async function Ke(r){r===void 0||r.pid===void 0||r.exitCode!==null||r.signalCode!==null||await new Promise((e,t)=>{let n=d(()=>{clearTimeout(i),clearTimeout(s),r.removeListener("exit",o),r.removeListener("error",a)},"cleanup"),o=d(()=>{n(),e()},"exited"),a=d(u=>{n(),t(u)},"failed"),i=setTimeout(()=>{r.kill("SIGKILL")},500),s=setTimeout(()=>{n(),t(new Error(`Could not stop owned Java process ${String(r.pid)} within 2 seconds`))},2e3);r.once("exit",o),r.once("error",a),r.kill()})}d(Ke,"stopProcess");var Xe=[{language:"c",backend:"lldb-dap",status:"verified"},{language:"cpp",backend:"lldb-dap",status:"verified"},{language:"csharp",backend:"netcoredbg",status:"verified"},{language:"dart",backend:"dart debug_adapter",status:"verified"},{language:"elixir",backend:"elixir-ls",status:"verified"},{language:"go",backend:"dlv dap",status:"verified"},{language:"java",backend:"java-debug / JDT LS",status:"verified"},{language:"javascript",backend:"vscode-js-debug",status:"verified"},{language:"julia",backend:"DebugAdapter.jl",status:"verified"},{language:"kotlin",backend:"kotlin-debug-adapter",status:"verified"},{language:"lua",backend:"local-lua-debugger-vscode",status:"verified"},{language:"php",backend:"vscode-php-debug",status:"verified"},{language:"powershell",backend:"PowerShellEditorServices",status:"verified"},{language:"python",backend:"debugpy",status:"verified"},{language:"r",backend:"vscDebugger",status:"verified"},{language:"ruby",backend:"rdbg",status:"verified"},{language:"rust",backend:"lldb-dap",status:"verified"},{language:"shell",backend:"bash-debug-adapter",status:"verified"},{language:"swift",backend:"lldb-dap",status:"verified"},{language:"typescript",backend:"vscode-js-debug",status:"verified"},{language:"zig",backend:"lldb-dap",status:"verified"}],ce=[{id:"dart-debug-adapter",name:"Dart debug adapter",kind:"debugger",languages:["dart"],executables:["dart"],dependencies:["Dart SDK 3.13.3"],documentation:"https://github.com/dart-lang/sdk/tree/main/third_party/pkg/dap",debugger:{runtimeExecutables:["dart"],adapterExecutables:["dart"],platforms:["linux","win32"],install:"Install Dart SDK 3.13.3 from the official Dart archive."}},{id:"debugpy",name:"debugpy",kind:"debugger",languages:["python"],executables:["python3"],dependencies:["debugpy"],documentation:"https://github.com/microsoft/debugpy",debugger:{runtimeExecutables:["python3"],adapterExecutables:["python3"],platforms:["linux","win32"],install:"Install Python 3 and debugpy for that interpreter."}},{id:"delve",name:"Delve",kind:"debugger",languages:["go"],executables:["dlv"],dependencies:["github.com/go-delve/delve/cmd/dlv@v1.25.2"],documentation:"https://github.com/go-delve/delve/tree/master/Documentation/api/dap",debugger:{runtimeExecutables:["go"],adapterExecutables:["dlv"],platforms:["linux","win32"],install:"Install Go and Delve. Native Windows support requires amd64."}},{id:"elixir-ls-debug-adapter",name:"ElixirLS debug adapter",kind:"debugger",languages:["elixir"],executables:["elixir","mix"],dependencies:["Elixir","Erlang/OTP","ElixirLS 0.31.1"],documentation:"https://github.com/elixir-lsp/elixir-ls",debugger:{runtimeExecutables:["elixir","mix"],adapterExecutables:["debug_adapter.sh","debug_adapter.bat"],platforms:["linux","win32"],install:"Install compatible Erlang/OTP and Elixir releases plus ElixirLS 0.31.1. Use debug_adapter.bat on Windows."}},{id:"vsc-debugger",name:"vscDebugger",kind:"debugger",languages:["r"],executables:["R"],dependencies:["R 4.5.3","R6 2.6.1","jsonlite 2.0.0","vscDebugger 0.5.9"],documentation:"https://manuelhentschel.github.io/vscDebugger/",debugger:{runtimeExecutables:["R"],adapterExecutables:["R"],platforms:["linux","win32"],install:"Install R 4.5.3 and vscDebugger 0.5.9 for that R installation."}},{id:"julia-debug-adapter",name:"DebugAdapter.jl",kind:"debugger",languages:["julia"],executables:["julia"],dependencies:["Julia 1.13.0","DebugAdapter.jl 3.2.1"],documentation:"https://github.com/julia-vscode/DebugAdapter.jl",debugger:{runtimeExecutables:["julia"],adapterExecutables:["julia"],platforms:["linux"],install:"Install Julia 1.13.0 and add DebugAdapter.jl 3.2.1 to /opt/pi-debug-adapters/julia."}},{id:"java-debug",name:"Microsoft Java Debug Server",kind:"debugger",languages:["java"],executables:["java"],dependencies:["JDK 21+","Eclipse JDT LS 1.61.0","Microsoft java-debug 0.53.2"],documentation:"https://github.com/microsoft/java-debug",debugger:{runtimeExecutables:["java"],adapterExecutables:["java"],platforms:["linux","win32"],install:"Install JDK 21+, Eclipse JDT LS 1.61.0 and the java-debug 0.53.2 plugin jar (from vscode-java-debug 0.59.0). Set PI_JAVA_PATH (or JAVA_HOME), PI_JDTLS_HOME and PI_JAVA_DEBUG_PLUGIN_PATH. Compile with javac -g before debugging. Pi owns a suspended target JVM and attaches through JDT LS; Kotlin still uses its own adapter."}},{id:"kotlin-debug-adapter",name:"Kotlin Debug Adapter",kind:"debugger",languages:["kotlin"],executables:["kotlin-debug-adapter"],dependencies:["fwcd/kotlin-debug-adapter 0.4.4","Temurin JDK 21.0.8+9","Kotlin compiler 2.2.20 for Kotlin builds"],documentation:"https://github.com/fwcd/kotlin-debug-adapter",debugger:{runtimeExecutables:["java"],adapterExecutables:["kotlin-debug-adapter"],platforms:["linux"],install:"Install Temurin JDK 21.0.8+9 and fwcd/kotlin-debug-adapter 0.4.4. Compile the target with debug information before launching it."}},{id:"netcoredbg",name:"NetCoreDbg",kind:"debugger",languages:["csharp"],executables:["netcoredbg"],dependencies:["Samsung/netcoredbg 3.2.0-1092",".NET SDK 8"],documentation:"https://github.com/Samsung/netcoredbg",debugger:{runtimeExecutables:["dotnet"],adapterExecutables:["netcoredbg"],platforms:["linux","win32"],install:"Install .NET SDK 8 and NetCoreDbg 3.2.0-1092. On Windows, ensure the selected dotnet SDK is on PATH."}},{id:"lldb-dap",name:"lldb-dap",kind:"debugger",languages:["c","cpp","rust"],executables:["lldb-dap-18","lldb-dap"],dependencies:["lldb-18"],documentation:"https://lldb.llvm.org/use/lldbdap.html",debugger:{runtimeExecutables:[],adapterExecutables:["lldb-dap-18","lldb-dap"],platforms:["linux"],install:"Install LLDB 18 and compile the target with debug information."}},{id:"lldb-dap-swift",name:"lldb-dap for Swift",kind:"debugger",languages:["swift"],executables:["lldb-dap"],dependencies:["Swift 6.3.3 toolchain"],documentation:"https://lldb.llvm.org/use/lldbdap.html",debugger:{runtimeExecutables:["swiftc"],adapterExecutables:["lldb-dap"],platforms:["linux"],install:"Install the official Swift 6.3.3 Linux toolchain, which includes swiftc and lldb-dap."}},{id:"lldb-dap-zig",name:"lldb-dap for Zig",kind:"debugger",languages:["zig"],executables:["lldb-dap-18","lldb-dap"],dependencies:["Zig 0.15.2","lldb-18"],documentation:"https://lldb.llvm.org/use/lldbdap.html",debugger:{runtimeExecutables:["zig"],adapterExecutables:["lldb-dap-18","lldb-dap"],platforms:["linux","win32"],install:"Install Zig 0.15.2 and LLDB 18, then compile the target in Debug mode with the LLVM backend (-fllvm) so LLDB can inspect locals."}},{id:"local-lua-debugger",name:"Local Lua Debugger",kind:"debugger",languages:["lua"],executables:["lua","node"],dependencies:["local-lua-debugger-vscode 0.3.3"],documentation:"https://github.com/tomblind/local-lua-debugger-vscode",debugger:{runtimeExecutables:["lua","node"],adapterExecutables:["debugAdapter.js"],platforms:["linux","win32"],install:"Install Lua 5.3, Node 24, and local-lua-debugger-vscode 0.3.3."}},{id:"powershell-editor-services-debug",name:"PowerShell Editor Services",kind:"debugger",languages:["powershell"],executables:["pwsh"],dependencies:["PowerShellEditorServices 4.7.0"],documentation:"https://github.com/PowerShell/PowerShellEditorServices",debugger:{runtimeExecutables:["pwsh"],adapterExecutables:["Start-EditorServices.ps1"],platforms:["linux","win32"],install:"Install PowerShell 7.4.13 and PowerShellEditorServices 4.7.0."}},{id:"rdbg",name:"rdbg",kind:"debugger",languages:["ruby"],executables:["rdbg"],dependencies:["debug gem 1.11.0 or newer"],documentation:"https://github.com/ruby/debug",debugger:{runtimeExecutables:["ruby"],adapterExecutables:["rdbg","rdbg.bat"],platforms:["linux","win32"],install:"Install Ruby and debug gem 1.11.0 or newer."}},{id:"vscode-bash-debug",name:"Bash Debug",kind:"debugger",languages:["shell"],executables:["bash","node"],dependencies:["Bash Debug 0.3.9"],documentation:"https://github.com/rogalmic/vscode-bash-debug",debugger:{runtimeExecutables:["bash","node"],adapterExecutables:["bashDebug.js"],platforms:["linux"],install:"Install Bash, Node 24, and Bash Debug 0.3.9."}},{id:"vscode-php-debug",name:"PHP Debug",kind:"debugger",languages:["php"],executables:["php","node"],dependencies:["PHP Debug 1.40.1","Xdebug"],documentation:"https://github.com/xdebug/vscode-php-debug",debugger:{runtimeExecutables:["php","node"],adapterExecutables:["phpDebug.js"],platforms:["linux","win32"],install:"Install PHP with Xdebug, Node 24, and PHP Debug 1.40.1."}},{id:"vscode-js-debug",name:"vscode-js-debug",kind:"debugger",languages:["javascript","typescript"],executables:["node"],dependencies:["@vscode/js-debug"],documentation:"https://github.com/microsoft/vscode-js-debug",debugger:{runtimeExecutables:["node"],adapterExecutables:["dapDebugServer.js"],platforms:["linux","win32"],install:"Install Node 24 and js-debug-dap v1.117.0 from the official release archive."}}];function te(r){return ce.find(e=>e.languages.includes(r))}d(te,"debuggerRecipeForLanguage");import{readdir as Qe,readFile as nr}from"node:fs/promises";import{homedir as pe}from"node:os";import R from"node:path";var Ye="2025-06-18",V=class r{static{d(this,"DebugMcpClient")}#o;#a;#r=1;constructor(e){this.#o=e}static async connect(e,t){let n=new r(`http://127.0.0.1:${e}/mcp`);return await n.#t("initialize",{protocolVersion:Ye,capabilities:{},clientInfo:{name:"pi-agent-ide",version:"1"}},t),await n.#i({jsonrpc:"2.0",method:"notifications/initialized"},t),n}async call(e,t,n){let o=await this.#t("tools/call",{name:e,arguments:t},n),a=(o.content??[]).flatMap(i=>i.type==="text"&&i.text!==void 0?[i.text]:[]).join(`
|
|
6
|
-
`);if(o.isError===!0)throw new Error(a||`DebugMCP ${e} failed`);return a}async close(){this.#a!==void 0&&(await fetch(this.#o,{method:"DELETE",headers:this.#e(),signal:AbortSignal.timeout(1e3)}).catch(()=>{}),this.#a=void 0)}async#t(e,t,n){let o=this.#r++,a=await this.#i({jsonrpc:"2.0",id:o,method:e,params:t},n),i=await rr(a,o);if(i.error!==void 0)throw new Error(`DebugMCP ${e} failed: ${i.error.message??"unknown error"}`);return i.result}async#i(e,t){let n=await fetch(this.#o,{method:"POST",headers:{...this.#e(),"content-type":"application/json",accept:"application/json, text/event-stream"},body:JSON.stringify(e),...t===void 0?{}:{signal:t}});if(!n.ok)throw new Error(`DebugMCP returned HTTP ${n.status}: ${await n.text()}`);return this.#a=n.headers.get("mcp-session-id")??this.#a,n}#e(){return this.#a===void 0?{}:{"mcp-session-id":this.#a,"mcp-protocol-version":Ye}}};async function rr(r,e){let t=await r.text(),n=(r.headers.get("content-type")??"").includes("text/event-stream")?t.split(/\r?\n/u).filter(o=>o.startsWith("data:")).map(o=>o.slice(5).trim()):[t];for(let o of n){if(o.length===0)continue;let a=JSON.parse(o);if(a.id===e)return a}throw new Error("DebugMCP returned no response")}d(rr,"responseMessage");var ne="ozzafar.debugmcpextension";function ae(r=process.env){return Number(r.PI_DEBUGMCP_PORT??3001)}d(ae,"debugMcpPort");var ar=6e4,or=30,Ze=6e4,ir=new Set([".exe",".out",".bin",".elf",".so",".dll",".dylib"]);function le(r,e=process.platform){return e==="win32"?r.replace(/^[A-Z](?=:)/u,t=>t.toLowerCase()):r}d(le,"vscodePath");function sr(r){return ir.has(R.extname(r).toLowerCase())}d(sr,"isExecutable");var dr={continue:"continue_execution",next:"step_over",stepIn:"step_into",stepOut:"step_out"};async function ge(r){for(let e of ur()){let t=await Qe(e).catch(()=>[]);for(let n of t){if(!/^window-\d+\.json$/u.test(n))continue;let o=await cr(R.join(e,n));if(o!==void 0&&r.every(a=>o.workspaceFolders.some(i=>pr(a,i))))return o}}}d(ge,"findVscodeWindow");async function et(){for(let r of[R.join(pe(),".vscode-server","extensions"),R.join(pe(),".vscode","extensions")])if((await Qe(r).catch(()=>[])).some(t=>t.startsWith(`${ne}-`)))return!0;return!1}d(et,"debugMcpInstalled");async function tt(r){try{return await(await V.connect(ae(),r)).close(),!0}catch{return!1}}d(tt,"debugMcpResponds");var re=class r{static{d(this,"VscodeDebugSession")}window;#o;#a;#r=new Map;#t;constructor(e,t,n){this.window=e,this.#o=t,this.#a=n}static async open(e,t){let n=await ge([e.cwd,e.program,e.sourceFile]);if(n===void 0)throw new Error(`No running VS Code window with DebugMCP has ${e.cwd} open`);let o=ae(),a;try{a=await V.connect(o,t)}catch(s){throw t?.throwIfAborted(),new Error(`DebugMCP did not respond on port ${o}: ${wr(s)}`,{cause:s})}let i=new r(n,a,e.program);try{if(await i.#i(t),(await i.status(0,t)).status!=="no-session")throw new Error(`VS Code window "${n.name}" already has an active debug session`)}catch(s){throw await a.close(),s}return i}async addBreakpoint(e,t,n){let o=`${e}:${t}`,a=this.#r.get(o);if(a!==void 0){this.#r.set(o,a+1);return}let i=await this.#e("list_breakpoints",{},n);fr(i).has(`${R.basename(e)}:${t}`)||(await this.#e("add_breakpoint",{fileFullPath:le(e),line:t},n),this.#r.set(o,1))}async removeBreakpoint(e,t,n){let o=`${e}:${t}`,a=this.#r.get(o);if(a!==void 0){if(a>1){this.#r.set(o,a-1);return}this.#r.delete(o),await this.#e("remove_breakpoint",{fileFullPath:le(e),line:t},n)}}async start(e,t){if(e.configuration===void 0&&e.test===void 0&&sr(e.program))throw new Error(`VS Code cannot choose a debugger for the executable ${R.basename(e.program)}. Add a .vscode/launch.json configuration for it (for example "cppvsdbg" or "cppdbg") and pass its name as configuration.`);let n=AbortSignal.timeout(Ze);try{await this.#e("start_debugging",{fileFullPath:e.program,workingDirectory:e.cwd,...e.configuration===void 0?{}:{configurationName:e.configuration},...e.test===void 0?{}:{testName:e.test}},t===void 0?n:AbortSignal.any([t,n]))}catch(a){throw!n.aborted||t?.aborted===!0?a:(await this.#e("stop_debugging",{}).catch(()=>{}),new Error(`VS Code did not start the debug session within ${Ze/1e3} s. Check that the VS Code window has the debugger extension for this configuration and that no prompt is waiting in VS Code.`,{cause:a}))}let o=await this.status(0,t);return this.#t=o.configurationName,o}async command(e,t){return await this.#e(dr[e],{},t),this.status(or,t)}async status(e,t){let n=d(async a=>gr(JSON.parse(await this.#e("get_debug_status",a===0?{}:{waitForPauseSeconds:a},t))),"read"),o=await n(e);for(let a=0;o.status==="paused"&&o.frame===void 0&&a<20;a++)await new Promise(i=>setTimeout(i,100)),o=await n(0);return o}async locals(e){let t=br(await this.#e("list_variable_names",{scope:"local"},e)).slice(0,50);if(t.length===0)return[];let n=await this.#e("get_variables_values",{variableNames:t.map(({name:o})=>o),scope:"local"},e);return mr(n,t)}async evaluate(e,t){return hr(await this.#e("evaluate_expression",{expression:e},t))}async#i(e){await this.#o.call("remove_breakpoint",{fileFullPath:this.#a,line:0},e)}async#e(e,t,n){try{return await this.#o.call(e,t,n)}catch(o){throw await this.#i().catch(()=>{}),o}}async close(e){try{for(let n of this.#r.keys()){let o=n.lastIndexOf(":");await this.#e("remove_breakpoint",{fileFullPath:le(n.slice(0,o)),line:Number(n.slice(o+1))},e)}this.#r.clear();let t=await this.status(0,e);t.status!=="no-session"&&t.configurationName===this.#t&&await this.#e("stop_debugging",{},e)}finally{await this.#o.close()}}};function ur(){let r=pe();return[R.join(r,".vscode-server","data","User"),R.join(r,".config","Code","User"),R.join(r,"Library","Application Support","Code","User"),...process.env.APPDATA===void 0?[]:[R.join(process.env.APPDATA,"Code","User")]].map(e=>R.join(e,"globalStorage",ne,"window-registry"))}d(ur,"registryDirectories");async function cr(r){try{let e=JSON.parse(await nr(r,"utf8"));return typeof e.pid!="number"||typeof e.updatedAt!="number"||!Array.isArray(e.workspaceFolders)||Date.now()-e.updatedAt>ar||!lr(e.pid)?void 0:{pid:e.pid,name:typeof e.name=="string"?e.name:"",workspaceFolders:e.workspaceFolders.filter(t=>typeof t=="string")}}catch{return}}d(cr,"readRegistration");function lr(r){try{return process.kill(r,0),!0}catch(e){return e.code==="EPERM"}}d(lr,"processAlive");function pr(r,e,t=process.platform){let n=t==="win32"?R.win32:R.posix,o=d(s=>t==="win32"?n.resolve(s).toLowerCase():n.resolve(s),"fold"),a=o(e),i=o(r);return i===a||i.startsWith(a.endsWith(n.sep)?a:a+n.sep)}d(pr,"isInside");function gr(r){let e=r.status==="paused"||r.status==="running"?r.status:"no-session",t=typeof r.configurationName=="string"?r.configurationName:void 0,n=typeof r.state=="object"&&r.state!==null?r.state:{},o=Array.isArray(n.stackTrace)&&typeof n.stackTrace[0]=="string"?/^(.*):(\d+)$/u.exec(n.stackTrace[0]):null,a=typeof n.currentLine=="number"?n.currentLine:o===null?void 0:Number(o[2]),i=a===void 0?void 0:{id:typeof n.frameId=="number"?n.frameId:0,threadId:typeof n.threadId=="number"?n.threadId:0,name:typeof n.frameName=="string"?n.frameName:o?.[1]??"",...typeof n.fileFullPath=="string"?{file:n.fileFullPath}:{},line:a};return{status:e,...t===void 0?{}:{configurationName:t},...e==="paused"&&i!==void 0?{frame:i}:{}}}d(gr,"debugState");function fr(r){return new Set(r.split(/\r?\n/u).flatMap(e=>{let t=/^\d+\. (?:Breakpoint|Logpoint) (.+?):(\d+)(?: \(|$)/u.exec(e);return t===null?[]:[`${t[1]}:${t[2]}`]}))}d(fr,"listedBreakpoints");function br(r){return r.split(/\r?\n/u).flatMap(e=>{let t=/^ {2}(\S.*?)(?: \(([^()]*)\))?$/u.exec(e);if(t===null||/^(?:No variables in this scope|Error retrieving variables:)/u.test(e.trim()))return[];let n=t[1],o=t[2];return n===void 0?[]:[{name:n,...o===void 0?{}:{type:o}}]})}d(br,"variableNames");function mr(r,e){let t=r.split(/\r?\n/u);return e.flatMap(({name:n,type:o})=>{let a=` ${n}`,i=t.find(l=>l===a||l.startsWith(`${a}: `)||l.startsWith(`${a} (`));if(i===void 0)return[];let s=i.slice(a.length),u=o===void 0?void 0:` (${o})`,c=s.startsWith(": ")?s.slice(2):"<complex value>";return u!==void 0&&c.endsWith(u)&&(c=c.slice(0,-u.length)),[{name:n,value:c,...o===void 0?{}:{type:o}}]})}d(mr,"variableValues");function hr(r){let e=r.split(/\r?\n/u),t=e.findIndex(a=>a.startsWith("Result: ")),n=/^Result: (.*?)(?: \(([^()]*)\))?$/u.exec(e[t]??"");if(n===null)throw new Error(`DebugMCP returned no evaluation result: ${r}`);let o=e.slice(t+1).filter(a=>/^ {2}\S/u.test(a));return{result:[n[1],...o].join(`
|
|
7
|
-
`),...n[2]===void 0?{}:{type:n[2]}}}d(hr,"evaluation");function wr(r){return r instanceof Error?r.message:String(r)}d(wr,"message");var rt="/opt/pi-debug-adapters/js-debug/src/dapDebugServer.js",nt="/opt/pi-debug-adapters/elixir-ls/debug_adapter.sh",at={protocol:$e,apiVersion:Le,id:"debugger",setup(r){for(let e of ce)r.addToolRecipe(e);r.addSetupCheck({id:"effective-config",inspect:yr}),r.addCheck({id:"adapters",title:"Debug adapters",run:vr}),r.addCheck({id:"vscode",title:"VS Code debugger backend",run:Dr})}};async function yr(r,e=r.workspace?.platform??process.platform){let t=new Map([...r.detectedLanguageIds].map(te).filter(a=>a!==void 0).map(a=>[a.id,a])),n=[...r.detectedLanguageIds].flatMap(a=>{let i=te(a);return i===void 0?[]:[{kind:"debugger",languageId:a,toolId:i.id}]}),o=[];for(let a of Xe)a.status==="planned"&&r.detectedLanguageIds.has(a.language)&&o.push({id:`debugger-${a.language}-not-verified`,message:`${a.backend} is selected for ${a.language}, but its Linux debugger integration is not verified yet`});for(let a of t.values()){let i=a.debugger;if(i===void 0)continue;let s=e==="linux"||e==="darwin"||e==="win32"?e:void 0;if(s===void 0||!i.platforms.includes(s)){o.push({id:`debugger-${a.id}-platform`,category:"unsupported-platform",message:`${a.name} does not support the ${e} debugger recipe`});continue}let u=a.id==="debugpy"?await fe(r,e):void 0,c=await Pr(a.id==="java-debug"?[Q(r.env)]:u===void 0?i.runtimeExecutables:[u.command],r);if(c!==void 0){o.push({id:`debugger-${a.id}-runtime`,category:"missing-runtime",message:`Runtime ${c} is unavailable. ${i.install}`});continue}if(!await Sr(a.id,r,e)){o.push({id:`debugger-${a.id}-adapter`,category:"missing-adapter",message:`${a.name} is not installed. ${i.install}`});continue}await kr(a.id,r,e)||o.push({id:`debugger-${a.id}-startup`,category:"adapter-startup",message:`${a.name} is installed but cannot start. ${i.install}`})}return{selections:n,actions:o}}d(yr,"inspectDebuggerSetup");async function vr(r){let e=[...new Map([...r.detectedLanguageIds].map(te).filter(t=>t!==void 0).map(t=>[t.id,t])).values()];return e.length===0?[{status:"skip",message:"No supported executable language was detected"}]:Promise.all(e.map(async t=>{let n=await it(t.id,r);if(t.id==="java-debug"&&n.ok&&r.workspace===void 0){let o=new U;try{await o.connect(r.cwd,AbortSignal.timeout(2e4),r.env),n={ok:!0,detail:`${n.detail}
|
|
8
|
-
Java DAP bridge ready`}}catch(a){n={ok:!1,detail:a instanceof Error?a.message:String(a)}}finally{await o.close()}}return{status:n.ok?"pass":"fail",message:`${t.name}: ${n.ok?"available":"unavailable"}`,detail:n.detail}}))}d(vr,"checkDebuggerAdapters");async function Dr(r){if(r.workspace!==void 0)return[{status:"skip",message:"The VS Code backend debugs only local workspaces"}];let e=await ge([r.cwd]);return e!==void 0?await tt(r.signal)?[{status:"pass",message:`VS Code backend: available in "${e.name}"`}]:[{status:"fail",message:"VS Code backend: DebugMCP does not respond",detail:`"${e.name}" has this workspace open, but DebugMCP does not accept connections on port ${ae(r.env)}. Set PI_DEBUGMCP_PORT when debugmcp.serverPort differs.`}]:await et()?[{status:"skip",message:"VS Code backend: no VS Code window with DebugMCP has this workspace open",detail:"Open the workspace in VS Code to debug through it; debug uses native adapters meanwhile."}]:await T(r,"code")?[{status:"warn",message:"VS Code backend: DebugMCP is not installed",detail:`Install it with: code --install-extension ${ne}`}]:[{status:"skip",message:"VS Code backend: VS Code is not installed"}]}d(Dr,"checkVscodeBackend");async function ot(r,e){if(r.workspace!==void 0)return P(r,"python3",["-c","import glob,os,sys; home,plugin=sys.argv[1:]; launchers=glob.glob(os.path.join(home,'plugins','org.eclipse.equinox.launcher_*.jar')); ok=len(launchers)==1 and os.path.isfile(plugin) and os.path.isdir(os.path.join(home,'config_linux')); print('Java debugger files ready' if ok else 'Missing JDT LS or java-debug plugin'); sys.exit(0 if ok else 1)",r.env.PI_JDTLS_HOME??"/opt/pi-debug-adapters/jdtls",r.env.PI_JAVA_DEBUG_PLUGIN_PATH??"/opt/pi-debug-adapters/java-debug/com.microsoft.java.debug.plugin-0.53.2.jar"]);try{return await ee(r.env,e),{ok:!0,detail:"Java debugger files ready"}}catch(t){return r.signal?.throwIfAborted(),{ok:!1,detail:t instanceof Error?t.message:String(t)}}}d(ot,"probeJavaFiles");async function Pr(r,e){for(let t of r)if(!await T(e,t))return t}d(Pr,"firstMissingExecutable");async function Sr(r,e,t=e.workspace?.platform??process.platform){let{env:n}=e;if(r==="elixir-ls-debug-adapter")return H(e,n.PI_ELIXIR_LS_DEBUG_PATH??nt);if(r==="vsc-debugger")return(await P(e,n.PI_R_PATH??"R",["--vanilla","--quiet","-e","quit(status=if (requireNamespace('vscDebugger', quietly=TRUE)) 0 else 1)"])).ok;if(r==="vscode-js-debug")return H(e,n.PI_JS_DEBUG_PATH??rt);if(r.startsWith("lldb-dap"))return await T(e,n.PI_LLDB_DAP_PATH??(t==="win32"?"lldb-dap":"lldb-dap-18"))||await T(e,"lldb-dap");if(r==="delve")return T(e,n.PI_DELVE_PATH??"dlv");if(r==="java-debug")try{return e.workspace!==void 0?(await ot(e,t)).ok:(await ee(n,t),!0)}catch{return!1}if(r==="kotlin-debug-adapter")return T(e,n.PI_KOTLIN_DEBUG_ADAPTER_PATH??"kotlin-debug-adapter");if(r==="julia-debug-adapter")return H(e,`${n.PI_JULIA_DEBUG_PROJECT??"/opt/pi-debug-adapters/julia"}/Project.toml`);if(r==="dart-debug-adapter")return T(e,n.PI_DART_PATH??"dart");if(r==="netcoredbg")return T(e,n.PI_NETCOREDBG_PATH??"netcoredbg");if(r==="rdbg")return T(e,n.PI_RUBY_DEBUG_PATH??"rdbg");let a={"vscode-php-debug":n.PI_PHP_DEBUG_PATH??"/opt/pi-debug-adapters/php-debug/extension/out/phpDebug.js","local-lua-debugger":n.PI_LUA_DEBUG_PATH??"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js","vscode-bash-debug":n.PI_BASH_DEBUG_PATH??"/opt/pi-debug-adapters/bash-debug/extension/out/bashDebug.js","powershell-editor-services-debug":`${n.PI_POWERSHELL_EDITOR_SERVICES_PATH??"/opt/pi-debug-adapters/powershell-editor-services"}/PowerShellEditorServices/Start-EditorServices.ps1`}[r];if(a!==void 0)return H(e,a);if(r!=="debugpy")return!1;let i=await fe(e,t);return(await P(e,i.command,[...i.args,"-c","import importlib.util; raise SystemExit(importlib.util.find_spec('debugpy') is None)"])).ok}d(Sr,"adapterInstalled");async function kr(r,e,t=e.workspace?.platform??process.platform){return(await it(r,e,t)).ok}d(kr,"adapterAvailable");async function it(r,e,t=e.workspace?.platform??process.platform){let{env:n}=e;if(r==="elixir-ls-debug-adapter")return M(n.PI_ELIXIR_LS_DEBUG_PATH??nt,e);if(r==="vsc-debugger")return P(e,n.PI_R_PATH??"R",["--vanilla","--quiet","-e","library(vscDebugger); cat(as.character(packageVersion('vscDebugger')))"]);if(r==="dart-debug-adapter")return P(e,n.PI_DART_PATH??"dart",["--version"]);if(r==="debugpy"){let a=await fe(e,t);return P(e,a.command,[...a.args,"-c","import debugpy; print(debugpy.__version__)"])}if(r==="delve")return P(e,n.PI_DELVE_PATH??"dlv",["version"]);if(r==="julia-debug-adapter"){let a=n.PI_JULIA_DEBUG_PROJECT??"/opt/pi-debug-adapters/julia";return P(e,n.PI_JULIA_PATH??"julia",[`--project=${a}`,"--startup-file=no","-e","using DebugAdapter"])}if(r==="java-debug"){let a=await ot(e,t);if(!a.ok)return a;let i=await P(e,Q(n),["-version"]);if(!i.ok)return i;let s=/version "(\d+)/u.exec(i.detail)?.[1];return Number(s)>=21?i:{ok:!1,detail:"Java debugger requires JDK 21 or newer. Set PI_JAVA_PATH or JAVA_HOME."}}if(r==="kotlin-debug-adapter"){let a=await P(e,n.PI_KOTLIN_DEBUG_ADAPTER_PATH??"kotlin-debug-adapter",["--help"]);return a.ok?P(e,"java",["-version"]):a}if(r==="netcoredbg"){let a=await P(e,n.PI_NETCOREDBG_PATH??"netcoredbg",["--version"]);return a.ok?P(e,"dotnet",["--version"]):a}if(r.startsWith("lldb-dap")){let a=n.PI_LLDB_DAP_PATH??(t==="win32"?"lldb-dap":await T(e,"lldb-dap-18")?"lldb-dap-18":"lldb-dap");return P(e,a,["--version"])}if(r==="rdbg")return P(e,n.PI_RUBY_DEBUG_PATH??"rdbg",["--version"]);if(r==="vscode-php-debug"){let a=await P(e,n.PI_PHP_PATH??"php",["-r","exit(extension_loaded('xdebug') ? 0 : 1);"]);return a.ok?M(n.PI_PHP_DEBUG_PATH??"/opt/pi-debug-adapters/php-debug/extension/out/phpDebug.js",e):a}if(r==="local-lua-debugger"){let a=await P(e,n.PI_LUA_PATH??"lua",["-v"]);return a.ok?M(n.PI_LUA_DEBUG_PATH??"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js",e):a}if(r==="vscode-bash-debug"){let a=await P(e,n.PI_BASH_PATH??"bash",["--version"]);return a.ok?M(n.PI_BASH_DEBUG_PATH??"/opt/pi-debug-adapters/bash-debug/extension/out/bashDebug.js",e):a}if(r==="powershell-editor-services-debug"){let a=await P(e,n.PI_PWSH_PATH??"pwsh",["--version"]),i=n.PI_POWERSHELL_EDITOR_SERVICES_PATH??"/opt/pi-debug-adapters/powershell-editor-services";return a.ok?M(`${i}/PowerShellEditorServices/Start-EditorServices.ps1`,e):a}if(r!=="vscode-js-debug")return{ok:!1,detail:`Unknown debugger adapter: ${r}`};let o=n.PI_JS_DEBUG_PATH??rt;return await H(e,o)?P(e,e.workspace?"node":process.execPath,["-e","const fs=require('node:fs'); fs.accessSync(process.argv[1]); console.log(process.version)",o]):{ok:!1,detail:`${o} does not exist`}}d(it,"probeAdapter");async function M(r,e){return await H(e,r)?P(e,e.workspace?"node":process.execPath,["-e","const fs=require('node:fs'); fs.accessSync(process.argv[1])",r]):{ok:!1,detail:`${r} does not exist`}}d(M,"probeAdapterFile");async function fe(r,e){return X(r.cwd,r.env,e,t=>T(r,t))}d(fe,"pythonCommand");async function H(r,e){if(!r.workspace)return ue(r,e);let t=r.workspace.toNativeUri(r.cwd).replace(/\/?$/u,"/"),n=e.split("/").map(encodeURIComponent).join("/"),o=r.workspace.fromNativeUri(new URL(n,t).href);return ue(r,o)}d(H,"adapterFileExists");import Er from"node:path";import{fileURLToPath as _r}from"node:url";function dt(r){return{id:"debug-breakpoints",present(e,t){let n=r.get(t.source),o=r.sourceFile(t.source)??st(t.source,t.cwd)??st(e.source,t.cwd);if(o===void 0)return e;let a=r.breakpointsForFile(o,n?.source);if(a.length===0)return e;let i=Ar(a);return{...e,lines:e.lines.map(s=>{let u=i.get(s.lineNumber);return u===void 0?s:{...s,presentation:{...s.presentation,suffix:`${s.presentation?.suffix??""}${Rr(u)}`,compactSuffix:`${s.presentation?.compactSuffix??""}${Ir(u)}`}}})}}}}d(dt,"createBreakpointPresenter");function Ar(r){let e=new Map;for(let t of r){let n=e.get(t.line)??[];n.push(t),e.set(t.line,n)}return e}d(Ar,"groupByLine");function st(r,e){if(r.startsWith("file://"))return _r(r);if(!/^[a-z][a-z\d+.-]*:/iu.test(r))return Er.resolve(e,r)}d(st,"filesystemSource");function Rr(r){return r.map(e=>` ${e.verified?"\u25CF":"\u25CB"} breakpoint ${e.source} (${e.verified?"verified":"pending"})`).join("")}d(Rr,"renderAgentBreakpoints");function Ir(r){let t=r.filter(o=>o.verified).length===r.length?"\u25CF":"\u25CB",n=r.length===1?"breakpoint":`${r.length} breakpoints`;return` ${t} ${n}`}d(Ir,"renderUserBreakpoints");import oe from"node:path";import{Text as be}from"@earendil-works/pi-tui";function me(r,e,t,n){return new be(`${n.fg("toolTitle",r)} ${n.fg("muted",`\xB7 ${ft(e,t)}`)}
|
|
9
|
-
${n.fg("accent","\u25C6 configure debugger")}`,0,0)}d(me,"renderDebugCall");function ut(r,e,t){return new be(`${lt(r,t)}
|
|
10
|
-
${t.fg("accent",xr(e))}`,0,0)}d(ut,"renderDebugActionCall");function J(r,e,t,n,o){let a=Tr(r,e,t);return o!==void 0&&a.unshift(t.fg("error",`\u2717 ${o}`)),n!==void 0&&a.unshift(`${t.fg("accent",n.expression)} ${t.fg("muted","=")} ${t.fg("toolOutput",n.result)}${n.type===void 0?"":t.fg("dim",` ${n.type}`)}`),new be(a.join(`
|
|
11
|
-
`),0,0)}d(J,"renderDebugResult");function ct(r,e){let t=[lt(r,e),pt(r.status,e)];return r.stop?.frame!==void 0&&t.push(` ${e.fg("warning","\u25CF")} ${r.stop.frame.name} ${e.fg("muted",`\xB7 ${gt(r.stop)}`)}`),t}d(ct,"renderActiveDebugger");function Tr(r,e,t){let n=[];if(r.status==="stopped"&&r.stop!==void 0){n.push(t.fg("warning",`\u25CF stopped \xB7 ${r.stop.reason}`),t.fg("text",`${r.stop.frame?.name??"unknown frame"} ${t.fg("muted",`\xB7 ${gt(r.stop)}`)}`));for(let a of r.stop.sourceLines){let i=a.current?t.fg("warning",">"):t.fg("dim","\u2502"),s=a.current?"text":"dim";n.push(`${i} ${String(a.lineNumber).padStart(4)} ${t.fg(s,a.content)}`)}let o=e?r.stop.variables:r.stop.variables.slice(0,6);if(o.length>0){n.push(t.fg("muted","Locals"));for(let a of o)n.push(` ${t.fg("accent",a.name.padEnd(16))} ${t.fg("toolOutput",a.value)}${a.type===void 0?"":t.fg("dim",` ${a.type}`)}`);o.length<r.stop.variables.length&&n.push(t.fg("muted",` \u2026 ${r.stop.variables.length-o.length} more`))}return n}if(n.push(pt(r.status,t)),r.breakpoints.length>0){let o=r.breakpoints.filter(a=>a.verified).length;n.push(t.fg("muted",`${r.breakpoints.length} breakpoint${r.breakpoints.length===1?"":"s"} \xB7 ${o} verified`))}return n}d(Tr,"debugResultLines");function lt(r,e){return`${e.fg("toolTitle",r.options.adapter)} ${e.fg("muted",`\xB7 ${ft(r.options.program,r.options.cwd)}`)}`}d(lt,"debugIdentity");function xr(r){let e=r.trim().toLowerCase();return e==="start"?"\u25B6 start debugging":e==="continue"?"\u25B6 continue":e==="step over"?"\u21B7 step over":e==="step into"?"\u2193 step into":e==="step out"?"\u2191 step out":e.startsWith("evaluate ")?`\u25C6 ${r.trim().slice(9)}`:e.startsWith("breakpoint ")?`\u25CF add ${e}`:e.startsWith("delete-breakpoint ")?`\u25CB remove breakpoint \xB7 ${e.slice(18)}`:e==="breakpoint"?"\u25CF add breakpoint":e==="delete-breakpoint"?"\u25CB remove breakpoint":e==="delete-session"?"\u25A0 stop debugging":e}d(xr,"actionLabel");function pt(r,e){return r==="configured"?e.fg("muted","\u25C7 ready"):r==="running"?e.fg("accent","\u25CF running"):r==="stopped"?e.fg("warning","\u25CF stopped"):e.fg("success","\u25A0 stopped debugging")}d(pt,"statusLine");function gt(r){let e=r.frame?.source?.path??r.frame?.source?.name??"unknown";return`${oe.basename(e)}:${r.frame?.line??"?"}`}d(gt,"shortFrame");function ft(r,e){let t=oe.relative(e,r),n=".".repeat(2),o=t===n||t.startsWith(`${n}${oe.sep}`);return t.length>0&&!o?t:oe.basename(r)}d(ft,"shortPath");function he(r){let e=we(r);if(e===void 0)return;let t=e.snapshot;return typeof t=="object"&&t!==null?t:void 0}d(he,"debuggerSnapshotFromResult");function bt(r){let e=we(r);if(e===void 0)return;let t=e.evaluation;if(!(typeof t!="object"||t===null||!("expression"in t)||typeof t.expression!="string"||!("result"in t)||typeof t.result!="string"||!("variablesReference"in t)||typeof t.variablesReference!="number"))return{expression:t.expression,result:t.result,variablesReference:t.variablesReference,..."type"in t&&typeof t.type=="string"?{type:t.type}:{}}}d(bt,"debuggerEvaluationFromResult");function mt(r){let e=we(r),t=e?.ok===!1?e.error:void 0;return typeof t=="object"&&t!==null&&"message"in t&&typeof t.message=="string"?t.message:void 0}d(mt,"debuggerFailureFromResult");function we(r){if(typeof r!="object"||r===null)return;let e=r.metadata;if(typeof e!="object"||e===null)return;let t=e.semanticAction;return typeof t=="object"&&t!==null?t:void 0}d(we,"semanticActionFromResult");function ht(r){return{id:"debugger",onDidChange:d(e=>r.onDidChange(e),"onDidChange"),list:d(()=>r.list().map(e=>r.snapshot(e)).filter(e=>e.status==="configured"||e.status==="running"||e.status==="stopped").map(e=>({source:e.source,...e.remote===void 0?{}:{remote:e.remote},owned:!0,kind:"debugger",title:e.options.adapter,description:e.options.program,status:e.status==="configured"?"configured":e.status==="stopped"?"paused":"running",renderSummary:d(t=>ct(e,t),"renderSummary"),renderDetail:d(t=>J(e,!0,t),"renderDetail"),stop:d(()=>r.delete(e.source),"stop")})),"list")}}d(ht,"debuggerProcessProvider");import q from"cross-spawn";import{randomBytes as wt}from"node:crypto";import{mkdtemp as Cr,readFile as St,rm as jr}from"node:fs/promises";import kt from"node:net";import{tmpdir as $r}from"node:os";import k from"node:path";var G=class{static{d(this,"DebugSessionManager")}#o=new Map;#a=new Set;#r;constructor(e){this.#r=e}setOwnerResolver(e){this.#r=e}#t(e){let t=this.#r?.(e.options.cwd);if(t?.key!==e.ownerKey)throw new Error("Debugger resource owner changed");return t}create(e,t){let n=this.#r?.(e.cwd);if(!n&&[e.cwd,e.program,e.sourceFile].some(i=>i?.includes("://")))throw new Error("No debugger workspace owner");if(n)for(let i of[e.cwd,e.program,e.sourceFile??e.program])n.serverPath(i);let o=wt(6).toString("hex"),a={id:o,source:`debug:${o}`,options:{...e,sourceFile:e.sourceFile??e.program},...n===void 0?{}:{ownerKey:n.key},...t===void 0?{}:{vscode:t},breakpoints:new Map,status:"configured",stopGeneration:0};return this.#o.set(o,a),this.#n(a),a}get(e){let t=/^debug:([a-f\d]{12})(?:\/|$)/u.exec(e);return t===null?void 0:this.#o.get(t[1])}list(){return[...this.#o.values()]}snapshot(e){return{id:e.id,source:e.source,options:e.options,status:e.status,...e.remote===void 0?{}:{remote:e.remote},breakpoints:[...e.breakpoints.values()].map(t=>({...t})),...e.stop===void 0?{}:{stop:e.stop}}}onDidChange(e){return this.#a.add(e),()=>this.#a.delete(e)}breakpointsForFile(e,t){return this.list().filter(n=>t===void 0||n.source===t).flatMap(n=>[...n.breakpoints.values()]).filter(n=>N(n.file,e))}sourceFile(e){let t=this.get(e);return t!==void 0&&e===`${t.source}/source`?t.options.sourceFile:void 0}sourceResource(e){return`${e.source}/source`}async readSource(e){let t=this.get(e),n=this.sourceFile(e);if(t===void 0||n===void 0)throw new Error(`Unknown debug source ${e}`);let o=this.#t(t);return o===void 0?St(n,"utf8"):o.readText(n)}async addBreakpoint(e,t,n){let o=this.get(e),a=this.sourceFile(e);if(o===void 0||a===void 0)throw new Error(`Unknown debug source ${e}`);if(this.#t(o),o.status==="terminated")throw new Error("Cannot add a breakpoint to a terminated session");let i=wt(5).toString("hex"),s={id:i,source:`${o.source}/breakpoint/${i}`,file:a,requestedLine:t,line:t,verified:!1};return o.vscode!==void 0&&await o.vscode.addBreakpoint(a,t,n),o.breakpoints.set(i,s),o.client!==void 0&&await this.#s(o,o.client,a,n),this.#n(o),s}breakpoint(e){let t=this.get(e);return t===void 0?void 0:[...t.breakpoints.values()].find(n=>n.source===e)}async start(e,t){return e.vscode!==void 0?this.#i(e,e.vscode,t):e.options.adapter==="java"&&this.#t(e)===void 0?this.#u(e,t):this.#d(e,t,2)}async#i(e,t,n){if(e.status!=="configured")throw new Error(`Session is already ${e.status}`);e.status="running",this.#n(e);try{let{program:o,cwd:a,configuration:i,test:s}=e.options,u=await t.start({program:o,cwd:a,...i===void 0?{}:{configuration:i},...s===void 0?{}:{test:s}},n);await this.#e(e,t,u)}catch(o){throw e.status="configured",this.#n(e),o}return e}async#e(e,t,n,o){if(n.status!=="paused"){e.status=n.status==="running"?"running":"terminated",e.stop=void 0,this.#n(e);return}let a=n.frame===void 0?void 0:{id:n.frame.id,name:n.frame.name,line:n.frame.line,...Br(n.frame.file??Lr(e,n.frame,o))},i=!1;for(let s of e.breakpoints.values())a?.source?.path!==void 0&&N(s.file,a.source.path)&&s.line===a.line&&(s.verified=!0,i=!0);e.stopGeneration++,e.stop={generation:e.stopGeneration,reason:i?"breakpoint":"step",threadId:n.frame?.threadId??0,...a===void 0?{}:{frame:a},variables:a===void 0?[]:await yt(t),sourceLines:a===void 0?[]:await vt(a)},e.status="stopped",this.#n(e)}async#u(e,t){if(e.status!=="configured")throw new Error(`Session is already ${e.status}`);let n=new U;e.javaRuntime=n;let o=AbortSignal.any([...t===void 0?[]:[t],AbortSignal.timeout(3e4)]),a=d(()=>{n.close()},"abortStartup");e.status="running",this.#n(e);try{let{client:i,attach:s}=await n.start(e.options,o);return e.client=i,e.controlClient=i,o.addEventListener("abort",a,{once:!0}),e.clients=[i],await ye(i,"java",o),await Promise.all([i.waitForAnyEvent(["initialized"],3e4,o),i.request("attach",s,{signal:o})]),await this.#g(e,i,o),await i.request("configurationDone",void 0,{signal:o}),await this.#c(e,o),this.snapshot(e).status==="terminated"&&await n.close(),e}catch(i){throw await n.close(),e.javaRuntime=void 0,e.client=void 0,e.controlClient=void 0,e.clients=void 0,e.status="configured",this.#n(e),i}finally{o.removeEventListener("abort",a)}}async#d(e,t,n){if(e.status!=="configured")throw new Error(`Session is already ${e.status}`);t?.throwIfAborted();let o=this.#t(e);o===void 0&&e.options.adapter==="powershell"&&(e.adapterTemporaryDirectory=await Cr(k.join($r(),"pi-powershell-debug-")));let a=o===void 0?await this.#m(e):await o.prepare(e.options,t);a.remote&&(e.remote=a.remote);let i=a.client;e.client=i,e.controlClient=i,e.clients=[i],e.options.adapter==="node"&&(e.targetReady=new Promise(s=>{e.resolveTargetReady=s})),e.status="running",this.#n(e);try{if(o!==void 0&&e.options.adapter==="node"){if(!a.connectChild)throw new Error("Owned Node adapter has no child connection");i.onReverseRequest(this.#y(e,a.connectChild))}(o!==void 0||e.options.adapter!=="r")&&await ye(i,a.adapterID,t);let s=i.waitForAnyEvent(["initialized"],3e4,t),u=i.request(a.request,a.launch,{signal:t});await Promise.race([s,u.then(()=>s)]),await this.#g(e,i,t);let c=i.request("configurationDone",void 0,{signal:t});if(e.options.adapter==="kotlin"?c.catch(()=>{}):await c,await u,e.options.adapter==="r"&&(e.rStarted=!0),e.targetReady!==void 0&&await e.targetReady,await this.#c(e,t),this.snapshot(e).status==="terminated"&&n>0&&(e.options.adapter==="dart"||e.options.adapter==="kotlin")&&e.breakpoints.size>0){await Promise.all((e.clients??[i]).map(l=>l.dispose())),e.adapterProcess?.kill(),await De(e),e.client=void 0,e.controlClient=void 0,e.clients=void 0,e.adapterProcess=void 0,e.status="configured";for(let l of e.breakpoints.values())l.verified=!1;return this.#n(e),await this.#d(e,t,n-1)}return e}catch(s){throw await Promise.all((e.clients??[i]).map(u=>u.dispose())),e.adapterProcess?.kill(),await De(e),e.client=void 0,e.controlClient=void 0,e.clients=void 0,e.adapterProcess=void 0,e.targetReady=void 0,e.resolveTargetReady=void 0,e.status="configured",this.#n(e),s}}async refresh(e){if(e.vscode!==void 0){e.status==="running"&&await this.#e(e,e.vscode,await e.vscode.status(0));return}if(e.client!==void 0){for(let t=e.client.takeEvent(["breakpoint"]);t!==void 0;t=e.client.takeEvent(["breakpoint"]))this.#D(e,t);if(e.status!=="terminated")for(;;){let t=e.client.takeEvent([...e.status==="running"?["stopped"]:[],"terminated","exited"]);if(t===void 0)return;if(t.event==="stopped")await this.#P(e,t);else{e.status="terminated",e.stop=void 0,this.#n(e),await e.javaRuntime?.close();return}}}}async command(e,t,n){if(this.#t(e),await this.refresh(e),e.status!=="stopped"||e.stop===void 0)throw new Error(`Cannot ${t} while session is ${e.status}`);if(e.vscode!==void 0){let i=e.vscode,s=e.stop.frame;return e.stop=void 0,e.status="running",this.#n(e),await this.#e(e,i,await i.command(t,n),s),e}let o=C(e),a=e.stop.threadId;return await o.request(t,{threadId:a},{signal:n}),e.stop=void 0,e.status="running",this.#n(e),await this.#c(e,n),this.snapshot(e).status==="terminated"&&await e.javaRuntime?.close(),e}async evaluate(e,t,n){if(this.#t(e),await this.refresh(e),e.status!=="stopped"||e.stop?.frame===void 0)throw new Error(`Cannot evaluate while session is ${e.status}`);let o=t.trim(),a=e.stop,i=e.stop.frame.id;if(o.length===0)throw new Error("Debug evaluation requires an expression");if(e.vscode!==void 0){let u=await e.vscode.evaluate(o,n);return e.stop={...a,variables:await yt(e.vscode,n)},this.#n(e),{expression:o,...u,variablesReference:0}}let s=await C(e).request("evaluate",{expression:o,frameId:e.stop.frame.id,context:e.options.adapter==="powershell"?"watch":"repl"},{signal:n});if(typeof s.result!="string")throw new Error("Debug adapter returned no evaluation result");return e.stop={...a,variables:await this.#S(e,i)},this.#n(e),{expression:o,result:s.result,variablesReference:s.variablesReference??0,...s.type===void 0?{}:{type:s.type}}}async delete(e,t){let n=this.get(e);if(n===void 0)throw new Error(`Unknown debug session ${e}`);let o=/\/breakpoint\/([a-f\d]{10})$/u.exec(e);if(o!==null){let a=n.breakpoints.get(o[1]);if(a===void 0)throw new Error(`Unknown debug breakpoint ${e}`);n.breakpoints.delete(a.id),await n.vscode?.removeBreakpoint(a.file,a.requestedLine,t),n.client!==void 0&&n.status!=="terminated"&&await this.#s(n,n.client,a.file,t),this.#n(n);return}if(e!==n.source)throw new Error(`Cannot delete debug resource ${e}`);await n.vscode?.close(t).catch(()=>{}),n.client!==void 0&&(await(n.controlClient??n.client).request("disconnect",{terminateDebuggee:!0},{signal:t,timeoutMs:500}).catch(()=>{}),await Promise.all((n.clients??[n.client]).map(a=>a.dispose()))),await n.javaRuntime?.close(),await Hr(n.adapterProcess),await De(n),n.status="terminated",this.#n(n),this.#o.delete(n.id)}async dispose(){await Promise.all(this.list().map(e=>this.delete(e.source)))}async#m(e){let t=await qr(e.options,e.adapterTemporaryDirectory),n=e.options.adapter==="node"?await this.#v(e):e.options.adapter==="delve"?await this.#f(e):e.options.adapter==="ruby"?await this.#l(e):e.options.adapter==="julia"?await this.#p(e):e.options.adapter==="r"?await this.#h(e):S.start(t.command,t.args,e.options.cwd);return{...t,client:n}}async#l(e){let t=await ie(),n=process.env.PI_RUBY_DEBUG_PATH??"rdbg";return e.adapterProcess=q(n,["--open","--host","127.0.0.1","--port",String(t),"--no-rc","--",e.options.program,...e.options.args],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),ve(e.adapterProcess,`rdbg:${String(t)}`),await Dt(e.adapterProcess,"Debugger can attach via TCP/IP","rdbg"),S.connect(t)}async#f(e){let t=await ie(),n=process.env.PI_DELVE_PATH??"dlv";return e.adapterProcess=q(n,["dap",`--listen=127.0.0.1:${String(t)}`,"--log=false"],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),e.adapterProcess.stderr?.on("data",()=>{}),await Dt(e.adapterProcess,"DAP server listening","Delve"),S.connect(t)}async#p(e){let t=await ie(),n=process.env.PI_JULIA_PATH??"julia",o=process.env.PI_JULIA_DEBUG_PROJECT??"/opt/pi-debug-adapters/julia",a='using Sockets, DebugAdapter; server = listen(ip"127.0.0.1", parse(Int, ARGS[1])); conn = accept(server); run(DebugAdapter.DebugSession(conn)); close(server)';return e.adapterProcess=q(n,["--startup-file=no","--history-file=no",`--project=${o}`,"-e",a,String(t)],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),ve(e.adapterProcess,`DebugAdapter.jl:${String(t)}`),await new Promise(i=>setTimeout(i,25)),Pt(t,"DebugAdapter.jl")}async#h(e){let t=kt.createServer();await new Promise((s,u)=>{t.once("error",u),t.listen(0,"127.0.0.1",()=>s())});let n=t.address();if(n===null||typeof n=="string")throw t.close(),new Error("Could not start the vscDebugger DAP listener");let o=new Promise((s,u)=>{t.once("connection",c=>{t.close();let l=S.fromSocket(c,2);l.onEvent(p=>this.#b(e,p)),s(l)}),t.once("error",u)}),a=process.env.PI_R_PATH??"R";e.rPromptInputs=[],e.rAtBrowserPrompt=!1,e.rStarted=!1,e.adapterProcess=q(a,["--vanilla","--quiet"],{cwd:e.options.cwd,env:process.env,stdio:["pipe","pipe","pipe"]}),ve(e.adapterProcess,`vscDebugger:${String(n.port)}`),this.#w(e);let i=Nr({seq:1,type:"request",command:"initialize",arguments:{clientID:"pi-agent-ide",adapterID:"R-Debugger",pathFormat:"path",linesStartAt1:!0,columnsStartAt1:!0,supportsVariableType:!0,supportsVariablePaging:!0,supportsWriteToStdinEvent:!0,supportsStdoutReading:!0,rStrings:{packageName:"vscDebugger",prompt:"__PI_R_PROMPT__",continue:"__PI_R_CONTINUE__",attachName:"tools:vscDebugger"},useDapSocket:!0,dapHost:"127.0.0.1",dapPort:n.port}});return e.adapterProcess.stdin?.write(`library(vscDebugger); vscDebugger:::.vsc.handleDap(${JSON.stringify(i)})
|
|
12
|
-
`),Fr(o,e.adapterProcess,t)}#b(e,t){if(process.env.PI_DEBUG_DAP_TRACE==="1"&&process.stderr.write(`[vscDebugger:event] ${JSON.stringify(t)}
|
|
13
|
-
`),t.event!=="custom")return;let n=L(t.body),o=typeof n.reason=="string"?n.reason:"",a=typeof n.text=="string"?n.text:"";if(!(o!=="writeToStdin"||a.length===0)){if(n.when==="browserPrompt"&&e.rAtBrowserPrompt===!0){e.rAtBrowserPrompt=!1,e.adapterProcess?.stdin?.write(`${a}
|
|
14
|
-
`);return}e.rPromptInputs?.push(a)}}#w(e){let t="";e.adapterProcess?.stdout?.on("data",n=>{for(t+=n.toString("utf8");;){let o=/Browse\[\d+\]> /u.exec(t),a=/(?:^|\r?\n)__PI_R_PROMPT__(?:\r?\n|$)/u.exec(t),i=o?.index??Number.POSITIVE_INFINITY,s=a?.index??Number.POSITIVE_INFINITY;if(!Number.isFinite(i)&&!Number.isFinite(s)){t=t.slice(-128);return}if(i<s){t=t.slice(i+(o?.[0].length??0));let u=e.rPromptInputs?.shift();u===void 0?(e.rAtBrowserPrompt=!0,setTimeout(()=>{e.rAtBrowserPrompt===!0&&(e.rAtBrowserPrompt=!1,e.adapterProcess?.stdin?.write(`vscDebugger::.vsc.listenForDAP(timeout=-1)
|
|
15
|
-
`))},100)):e.adapterProcess?.stdin?.write(`${u}
|
|
16
|
-
`)}else t=t.slice(s+(a?.[0].length??0)),e.adapterProcess?.stdin?.write(`vscDebugger::.vsc.listenForDAP(timeout=-1)
|
|
17
|
-
`),e.rStarted===!0&&e.client?.request("custom",{reason:"showingPrompt",which:"topLevel"}).catch(()=>{})}})}async#v(e){let t=await ie(),n=process.env.PI_JS_DEBUG_PATH??"/opt/pi-debug-adapters/js-debug/src/dapDebugServer.js";e.adapterProcess=q(process.execPath,[n,String(t),"127.0.0.1"],{cwd:e.options.cwd,env:process.env,stdio:["ignore","pipe","pipe"]}),e.adapterProcess.stderr?.on("data",()=>{}),await Ur(e.adapterProcess);let o=await Pt(t);return o.onReverseRequest(this.#y(e,()=>S.connect(t))),o}#y(e,t){return async n=>{if(n.command!=="startDebugging")throw new Error(`Client does not support reverse request ${n.command}`);let o=L(n.arguments),a=L(o.configuration),i=this.#t(e),s=await t();e.clients?.push(s),s.onReverseRequest(this.#y(e,t)),await ye(s,"pwa-node");let u=s.waitForEvent("initialized"),c=s.request(typeof o.request=="string"?o.request:"launch",{...a,sourceMaps:!0,pauseForSourceMap:!0,outFiles:[k.join(k.dirname(i?.serverPath(e.options.program)??e.options.program),"**","*.js")]});return await Promise.race([u,c.then(()=>u)]),e.client=s,await this.#g(e,s),await s.request("configurationDone"),await c,e.resolveTargetReady?.(),{}}}async#g(e,t,n){let o=new Set([...e.breakpoints.values()].map(a=>a.file));for(let a of o)await this.#s(e,t,a,n)}async#s(e,t,n,o){let a=[...e.breakpoints.values()].filter(s=>s.file===n),i=await t.request("setBreakpoints",{source:{path:this.#t(e)?.serverPath(n)??n,name:k.basename(n)},breakpoints:a.map(({requestedLine:s})=>({line:s})),sourceModified:!1},{signal:o});for(let[s,u]of a.entries()){let c=i.breakpoints?.[s];u.verified=c?.verified===!0,u.line=c?.line??u.requestedLine,u.adapterId=c?.id}}async#c(e,t){let n=await C(e).waitForAnyEvent(["stopped","terminated","exited","loadedSource","breakpoint","custom"],3e4,t),o=L(n.body);if(n.event==="custom"&&e.options.adapter==="r"){await this.#c(e,t);return}if(n.event==="loadedSource"){let a=L(o.source),i=this.#t(e);if(i!==void 0&&e.options.adapter==="node"&&typeof a.path=="string"&&!k.posix.isAbsolute(a.path)){await this.#c(e,t);return}let s=typeof a.path=="string"?i?.resourcePath(a.path)??k.resolve(a.path):void 0,u=s===void 0?void 0:[...e.breakpoints.values()].find(c=>N(c.file,s))?.file;u!==void 0&&await this.#s(e,C(e),u,t),await this.#c(e,t);return}if(n.event==="breakpoint"){this.#D(e,n),await this.#c(e,t);return}if(o.reason==="exit"){e.status="terminated",e.stop=void 0,this.#n(e);return}if(e.options.adapter==="node"&&o.reason==="entry"){await this.#g(e,C(e),t);let a=typeof o.threadId=="number"?o.threadId:1;await C(e).request("continue",{threadId:a},{signal:t}),await this.#c(e,t);return}if((e.options.adapter==="dart"||e.options.adapter==="kotlin")&&o.reason==="entry"){let a=C(e);if(await this.#g(e,a,t),e.options.adapter==="kotlin"){let s=Date.now()+5e3;for(;[...e.breakpoints.values()].some(u=>!u.verified)&&Date.now()<s;)await new Promise(u=>setTimeout(u,50)),await this.#g(e,a,t)}let i=typeof o.threadId=="number"?o.threadId:1;await a.request("continue",{threadId:i},{signal:t}),await this.#c(e,t);return}if(n.event!=="stopped"){e.status="terminated",e.stop=void 0,this.#n(e);return}if(await this.#P(e,n,e.options.adapter!=="shell"),e.options.adapter==="r"&&e.stop?.frame?.source?.path===void 0){e.stopGeneration--,e.stop=void 0,e.status="running",await this.#c(e,t);return}if(e.options.adapter==="shell"&&e.stopGeneration===1&&e.stop?.frame!==void 0&&![...e.breakpoints.values()].some(a=>N(a.file,e.stop?.frame?.source?.path??"")&&a.line===e.stop?.frame?.line)){let a=e.stop.threadId;e.stopGeneration--,e.stop=void 0,e.status="running",await C(e).request("continue",{threadId:a},{signal:t}),await this.#c(e,t);return}e.options.adapter==="shell"&&this.#n(e)}#D(e,t){let n=L(L(t.body).breakpoint),o=L(n.source);for(let a of e.breakpoints.values())(typeof n.id=="number"&&a.adapterId!==void 0?n.id===a.adapterId:typeof o.path=="string"&&N(this.#t(e)?.resourcePath(o.path)??o.path,a.file)&&n.line===a.requestedLine)&&(typeof n.line=="number"&&(a.line=n.line),a.verified=n.verified===!0);this.#n(e)}async#P(e,t,n=!0){let o=C(e),a=L(t.body),i=(await o.request("threads")).threads?.[0]?.id,s=typeof a.threadId=="number"?a.threadId:i;if(s===void 0)throw new Error("Debugger stopped without a thread");let u=this.#t(e),c=(await Or(o,s,e.options.adapter==="dart")).stackFrames?.[0],l=c?.source?.path===void 0||u===void 0?c:{...c,source:{...c.source,path:u.resourcePath(c.source.path)}};if(l?.source?.path!==void 0)for(let m of e.breakpoints.values())N(m.file,l.source.path)&&m.line===l.line&&(m.verified=!0);let p=l===void 0?[]:await this.#S(e,l.id);e.stopGeneration++,e.stop={generation:e.stopGeneration,reason:typeof a.reason=="string"?a.reason:"stopped",threadId:s,...l===void 0?{}:{frame:l},variables:p,sourceLines:l===void 0?[]:await vt(l,u?.readText.bind(u))},e.status="stopped",n&&this.#n(e)}async#S(e,t){let n=C(e),o=(await n.request("scopes",{frameId:t})).scopes??[],a=e.options.adapter==="r"?o:o.filter(s=>[s.name.toLowerCase(),s.presentationHint?.toLowerCase()].some(u=>u?.includes("local")===!0||u==="variables")),i=[];for(let s of a){let u=await n.request("variables",{variablesReference:s.variablesReference,start:0,count:100});i.push(...u.variables??[])}return i}#n(e){let t=this.snapshot(e);for(let n of this.#a)n(t)}};function Lr(r,e,t){let n=new Set([...r.breakpoints.values()].filter(o=>o.line===e.line).map(o=>o.file));return n.size===1?[...n][0]:t?.name===e.name?t.source?.path:void 0}d(Lr,"inferVscodeFrameFile");function Br(r){return r===void 0?{}:{source:{path:r}}}d(Br,"withSourcePath");async function yt(r,e){return(await r.locals(e)).map(t=>({...t,variablesReference:0}))}d(yt,"vscodeVariables");async function vt(r,e){let t=r.source?.path;if(t===void 0)return[];try{let n=(await(e===void 0?St(t,"utf8"):e(t))).split(/\r?\n/u),o=Math.max(1,r.line-2),a=Math.min(n.length,r.line+2);return n.slice(o-1,a).map((i,s)=>({lineNumber:o+s,content:i,current:o+s===r.line}))}catch(n){if(e!==void 0)throw n;return[]}}d(vt,"sourceWindow");async function Or(r,e,t){let n=Date.now()+1e3,o;do{try{let a=await r.request("stackTrace",{threadId:e});if(!t||(a.stackFrames?.length??0)>0)return a;o=new Error("Debugger stack is not ready")}catch(a){if(o=a,!t)throw a}await new Promise(a=>setTimeout(a,25))}while(Date.now()<n);throw o instanceof Error?o:new Error("Could not read debugger stack")}d(Or,"requestStackTrace");function W(r){let e=[`Session: ${r.source}`,`Adapter: ${r.options.adapter}`,`Program: ${k.relative(r.options.cwd,r.options.program)||r.options.program}`,`Status: ${r.status}`];if(r.breakpoints.size>0){e.push("","Breakpoints:");for(let t of r.breakpoints.values())e.push(`- ${t.source} ${k.relative(r.options.cwd,t.file)}:${t.line} (${t.verified?"verified":"pending"})`)}if(r.stop!==void 0){let{stop:t}=r;if(e.push("",`Stop: ${t.generation} (${t.reason})`,`Thread: ${t.threadId}`),t.frame!==void 0&&e.push(`Frame: ${t.frame.name} at ${t.frame.source?.path??t.frame.source?.name??"unknown"}:${t.frame.line}`),t.variables.length>0){e.push("","Locals:");for(let n of t.variables)e.push(`- ${n.name}: ${n.value}${n.type===void 0?"":` (${n.type})`}`)}}return e.join(`
|
|
18
|
-
`)}d(W,"renderDebugSession");function C(r){if(r.client===void 0)throw new Error("Debug adapter is not running");return r.client}d(C,"requiredClient");function L(r){return typeof r=="object"&&r!==null?r:{}}d(L,"asRecord");function Nr(r){let e=JSON.stringify(r);return`Content-Length: ${Buffer.byteLength(e,"utf8")}\r
|
|
19
|
-
\r
|
|
20
|
-
${e}`}d(Nr,"dapFrame");function ye(r,e,t){return r.request("initialize",{clientID:"pi-agent-ide",adapterID:e,pathFormat:"path",linesStartAt1:!0,columnsStartAt1:!0,supportsVariableType:!0,supportsVariablePaging:!0,supportsRunInTerminalRequest:!1,supportsStartDebuggingRequest:!0},{signal:t})}d(ye,"initializeClient");function ie(){return new Promise((r,e)=>{let t=kt.createServer();t.once("error",e),t.listen(0,"127.0.0.1",()=>{let n=t.address();if(n===null||typeof n=="string"){t.close(),e(new Error("Could not allocate a debug adapter port"));return}t.close(o=>o===void 0?r(n.port):e(o))})})}d(ie,"availablePort");function ve(r,e){if(process.env.PI_DEBUG_DAP_TRACE==="1"){process.stderr.write(`[${e}] pid=${String(r.pid)}
|
|
21
|
-
`),r.once("exit",(t,n)=>process.stderr.write(`[${e}] exit code=${String(t)} signal=${String(n)}
|
|
22
|
-
`));for(let t of[r.stdout,r.stderr])t?.on("data",n=>process.stderr.write(`[${e}] ${n.toString("utf8")}`))}}d(ve,"traceAdapterProcess");function Fr(r,e,t){return new Promise((n,o)=>{let a=setTimeout(()=>s(new Error("Timed out starting vscDebugger")),5e3),i=d(()=>{clearTimeout(a),e.off("error",s),e.off("exit",u)},"cleanup"),s=d(c=>{i(),t.close(),e.killed||e.kill(),o(c)},"fail"),u=d(c=>s(new Error(`vscDebugger exited with code ${String(c)} before connecting`)),"onExit");e.once("error",s),e.once("exit",u),r.then(c=>{i(),n(c)},s)})}d(Fr,"waitForRAdapterConnection");function Dt(r,e,t){return new Promise((n,o)=>{let a=[r.stdout,r.stderr].filter(c=>c!==null),i=setTimeout(()=>o(new Error(`Timed out starting ${t} server`)),process.platform==="win32"?15e3:5e3),s=d(()=>{clearTimeout(i);for(let c of a)c.off("data",u)},"cleanup"),u=d(c=>{c.toString("utf8").includes(e)&&(s(),n())},"onData");for(let c of a)c.on("data",u);r.once("error",c=>{s(),o(c)}),r.once("exit",c=>{s(),o(new Error(`${t} server exited with code ${String(c)}`))})})}d(Dt,"waitForAdapterReady");function Ur(r){return new Promise((e,t)=>{let n=r.stdout;if(n===null){t(new Error("js-debug server stdout is unavailable"));return}let o=setTimeout(()=>t(new Error("Timed out starting js-debug server")),5e3),a=d(i=>{i.toString("utf8").includes("Debug server listening")&&(clearTimeout(o),n.off("data",a),e())},"onData");n.on("data",a),r.once("error",t),r.once("exit",i=>t(new Error(`js-debug server exited with code ${i}`)))})}d(Ur,"waitForJsDebugReady");async function Pt(r,e="js-debug"){let t;for(let n=0;n<100;n++)try{return await S.connect(r)}catch(o){t=o,await new Promise(a=>setTimeout(a,25))}throw t instanceof Error?t:new Error(`Could not connect to ${e}`)}d(Pt,"connectWithRetry");async function De(r){r.adapterTemporaryDirectory!==void 0&&(await jr(r.adapterTemporaryDirectory,{recursive:!0,force:!0,maxRetries:process.platform==="win32"?10:0,retryDelay:100}),r.adapterTemporaryDirectory=void 0)}d(De,"removeAdapterTemporaryDirectory");async function Hr(r){if(!(r===void 0||r.exitCode!==null||r.signalCode!==null)){if(process.platform!=="win32"||r.pid===void 0){r.kill();return}await new Promise(e=>{let t=q("taskkill.exe",["/pid",String(r.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0});t.once("error",()=>{r.kill(),e()}),t.once("exit",()=>e())})}}d(Hr,"terminateOwnedAdapterProcess");async function qr(r,e){let t={name:"Pi Agent IDE debug session",request:"launch",program:r.program,cwd:r.cwd,args:[...r.args]};if(r.adapter==="dart")return{command:process.env.PI_DART_PATH??"dart",args:["debug_adapter"],adapterID:"dart",request:"launch",launch:{...t,type:"dart",debugSdkLibraries:!1,debugExternalPackageLibraries:!1,stopOnEntry:!0,vmAdditionalArgs:["--pause-isolates-on-start"]}};if(r.adapter==="debugpy"){let n=await X(r.cwd);return{command:n.command,args:[...n.args,"-m","debugpy.adapter"],adapterID:"debugpy",request:"launch",launch:{...t,type:"python",console:"internalConsole",justMyCode:!1}}}if(r.adapter==="kotlin"){if(r.mainClass===void 0)throw new Error("Java and Kotlin debug sessions require mainClass");return{command:process.env.PI_KOTLIN_DEBUG_ADAPTER_PATH??"kotlin-debug-adapter",args:[],adapterID:r.adapter,request:"launch",launch:{...t,type:"kotlin",mainClass:r.mainClass,projectRoot:r.cwd,stopOnEntry:!0}}}if(r.adapter==="netcoredbg")return{command:process.env.PI_NETCOREDBG_PATH??"netcoredbg",args:["--interpreter=vscode"],adapterID:"coreclr",request:"launch",launch:{...t,type:"coreclr",console:"internalConsole"}};if(r.adapter==="elixir")return{command:process.env.PI_ELIXIR_LS_DEBUG_PATH??(process.platform==="win32"?"debug_adapter.bat":"/opt/pi-debug-adapters/elixir-ls/debug_adapter.sh"),args:[],adapterID:"mix_task",request:"launch",launch:{name:t.name,request:"launch",type:"mix_task",task:"run",taskArgs:[r.program,...r.args],projectDir:r.cwd,startApps:!0,exitAfterTaskReturns:!0}};if(r.adapter==="julia")return{command:process.env.PI_JULIA_PATH??"julia",args:[],adapterID:"julia",request:"launch",launch:{...t,type:"julia",stopOnEntry:!1}};if(r.adapter==="lldb-dap")return{command:k.extname(r.sourceFile).toLowerCase()===".swift"?process.env.PI_SWIFT_LLDB_DAP_PATH??process.env.PI_LLDB_DAP_PATH??"lldb-dap":process.env.PI_LLDB_DAP_PATH??(process.platform==="win32"?"lldb-dap":"lldb-dap-18"),args:[],adapterID:"lldb-dap",request:"launch",launch:{...t,type:"lldb-dap"}};if(r.adapter==="delve")return{command:process.env.PI_DELVE_PATH??"dlv",args:[],adapterID:"go",request:"launch",launch:{...t,type:"go",mode:"debug"}};if(r.adapter==="r")return{command:process.env.PI_R_PATH??"R",args:[],adapterID:"R-Debugger",request:"launch",launch:{name:t.name,request:"launch",type:"R-Debugger",debugMode:"file",file:r.program,workingDirectory:r.cwd,commandLineArgs:[...r.args],allowGlobalDebugging:!1,loadPackages:[],supportsStdoutReading:!0,supportsWriteToStdinEvent:!0,overwriteHelp:!1}};if(r.adapter==="ruby")return{command:process.env.PI_RUBY_DEBUG_PATH??"rdbg",args:[],adapterID:"rdbg",request:"launch",launch:{...t,type:"rdbg"}};if(r.adapter==="php")return{command:process.execPath,args:[process.env.PI_PHP_DEBUG_PATH??"/opt/pi-debug-adapters/php-debug/extension/out/phpDebug.js"],adapterID:"php",request:"launch",launch:{...t,type:"php",runtimeExecutable:process.env.PI_PHP_PATH??"php",runtimeArgs:["-dxdebug.start_with_request=yes"],console:"internalConsole",port:0,env:{XDEBUG_MODE:"debug,develop",XDEBUG_CONFIG:"client_port=${port}"}}};if(r.adapter==="lua")return{command:process.execPath,args:[process.env.PI_LUA_DEBUG_PATH??"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js"],adapterID:"lua-local",request:"launch",launch:{...t,type:"lua-local",program:{lua:process.env.PI_LUA_PATH??"lua",file:r.program},extensionPath:k.dirname(k.dirname(process.env.PI_LUA_DEBUG_PATH??"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js")),workspacePath:r.cwd}};if(r.adapter==="shell"){let n=process.env.PI_BASH_DEBUG_ROOT??"/opt/pi-debug-adapters/bash-debug/extension";return{command:process.execPath,args:[process.env.PI_BASH_DEBUG_PATH??k.join(n,"out/bashDebug.js")],adapterID:"bashdb",request:"launch",launch:{...t,type:"bashdb",pathBash:process.env.PI_BASH_PATH??"/usr/bin/bash",pathBashdb:k.join(n,"bashdb_dir/bashdb"),pathBashdbLib:k.join(n,"bashdb_dir"),pathCat:"/usr/bin/cat",pathMkfifo:"/usr/bin/mkfifo",pathPkill:"/usr/bin/pkill",terminalKind:"debugConsole",argsString:"",env:{},showDebugOutput:!1,trace:!1}}}if(r.adapter==="powershell"){let n=process.env.PI_POWERSHELL_EDITOR_SERVICES_PATH??"/opt/pi-debug-adapters/powershell-editor-services";if(e===void 0)throw new Error("PowerShell debugger temporary directory was not created");return{command:process.env.PI_PWSH_PATH??"pwsh",args:["-NoLogo","-NoProfile","-Command",`& '${k.join(n,"PowerShellEditorServices/Start-EditorServices.ps1").replaceAll("'","''")}' -LogPath '${k.join(e,"logs").replaceAll("'","''")}' -LogLevel Warning -SessionDetailsPath '${k.join(e,"session.json").replaceAll("'","''")}' -FeatureFlags @() -AdditionalModules @() -HostName 'Pi Agent IDE' -HostProfileId 'pi-agent-ide' -HostVersion '1.0.0' -BundledModulesPath '${n.replaceAll("'","''")}' -Stdio -DebugServiceOnly`],adapterID:"PowerShell",request:"launch",launch:{...t,script:r.program,createTemporaryIntegratedConsole:!1,executeMode:"Call"}}}return{command:process.execPath,args:[],adapterID:"pwa-node",request:"launch",launch:{...t,type:"pwa-node",console:"internalConsole",autoAttachChildProcesses:!1,stopOnEntry:!0,sourceMaps:!0,pauseForSourceMap:!0,outFiles:[k.join(k.dirname(r.program),"**","*.js")]}}}d(qr,"adapterRecipe");var Pe=y.Object({source:y.String(),sourceResource:y.String(),breakpointsResource:y.String(),adapter:y.String(),program:y.String(),cwd:y.String(),status:y.String(),breakpoints:y.Array(y.Object({source:y.String(),file:y.String(),line:y.Integer(),verified:y.Boolean()},{additionalProperties:!1}))},{additionalProperties:!1}),Jr=ke(Pe),Gr=y.Object({backend:y.Optional(Et(["auto","vscode","native"],{description:"Select the debugger backend. auto (default) debugs through VS Code when the local program is inside a workspace open in VS Code with the DebugMCP extension, that window has no active debug session, and args and mainClass are omitted; otherwise it uses the native adapter. vscode fails with the unmet condition instead of falling back. native always launches the selected adapter."})),adapter:y.Optional(Et(["dart","debugpy","delve","java","elixir","julia","kotlin","lldb-dap","lua","netcoredbg","node","php","powershell","r","ruby","shell"],{description:"Select an installed native DAP adapter for Dart, Python, Go, Java, Elixir, Julia, Kotlin, C, C++, Rust, Swift, Zig, Lua, C#, JavaScript, TypeScript, PHP, PowerShell, R, Ruby, or shell scripts. Required for the native backend; VS Code chooses its debugger from launch.json or the file type."})),program:y.String({minLength:1,description:"Source file or executable to launch. Relative paths resolve from cwd."}),source:y.Optional(y.String({description:"Source file used for anchored breakpoints. Defaults to program. Relative paths resolve from cwd."})),args:y.Optional(y.Array(y.String(),{description:"Arguments passed to the debugged program by the native backend. For VS Code, put them in a launch.json configuration."})),mainClass:y.Optional(y.String({minLength:1,description:"Fully qualified JVM main class. Required by Java and Kotlin adapters."})),configuration:y.Optional(y.String({minLength:1,description:"Name of a .vscode/launch.json configuration to launch in VS Code. Use it for program arguments or environment. VS Code backend only."})),test:y.Optional(y.String({minLength:1,description:"Name of one test to debug through the VS Code Testing API; set program to its test file. VS Code backend only."})),cwd:y.Optional(y.String({description:"Select a local working directory or ssh://target/absolute/path. Relative paths resolve from the workspace."}))},{additionalProperties:!1});async function It(r,e){je(r,[await Ce({id:"debugger",description:"Debugger sessions, breakpoints, stepping, and cleanup",triggers:[{tool:"debug"},...["read","insert","delete"].map(l=>({tool:l,resourcePrefixes:["debug:"]}))]})]);let t=We("debugger",G)??new G;t.setOwnerResolver(e?.workspace);let n=new Map,o=_t(t,"debugger-source"),a=_t(t,"debugger-input"),i=Je(r).add(ht(t)),s=dt(t),u={protocol:_e,apiVersion:Ae,id:"debugger",setup(l){l.addResolver({resolver:o,matchesCall:d(p=>t.sourceFile(p)!==void 0,"matchesCall"),renderCall(p,m,b){let g=F(p)?p:{},f=typeof g.path=="string"?g.path:"",h=t.get(f),w=t.sourceFile(f);if(h===void 0||w===void 0)throw new Error("Debugger source header lost its session");let D=B.relative(h.options.cwd,w),E=Array.isArray(g.views)?g.views.filter(z=>typeof z=="string"):[],_=typeof g.offset=="number"?g.offset:1,I=typeof g.limit=="number"?g.limit:void 0,$=I===void 0?String(_):`${_}-${_+I-1}`;return xe(b.lastComponent,{tool:"debug file",primary:{text:`${D}:${$}`,color:"accent",underline:!0},qualifiers:E.length===0?[]:[{text:`views ${E.join(",")}`}],details:[{label:"source",value:f},{label:"file",value:w},...E.length===0?[]:[{label:"views",value:E.join(",")}]],expanded:b.expanded},m)}}),l.addView({view:"breakpoints",presenter:s}),l.describe({path:"debug:<session> \u2014 debugger state.",views:"breakpoints \u2014 breakpoints beside the lines."})}},c={protocol:Ie,apiVersion:Te,id:"debugger",setup(l){l.addResolver({resolver:a}),l.tool("insert").describeField("path","debug:<session> controls the debugger; debug:<session>/source with a line anchor sets a breakpoint."),l.tool("insert").describeField("text","For debug:<session>: start, continue, step over, step into, step out or evaluate <expression> (needs a stopped frame). For debug:<session>/source: breakpoint."),l.tool("insert").describeField("anchor","Omit for debug:<session>."),l.tool("insert").addSemanticHandler({matches:d(p=>zr(p,t),"matches"),execute:d(async(p,m)=>{let b=m,g=Rt(t,b.path);if(t.sourceFile(b.path)!==void 0){if(b.text!=="breakpoint"||b.anchor===void 0)throw new Error('A debug source accepts text "breakpoint" with one anchor');let h=await p.resolveAnchor("anchor"),w=await t.addBreakpoint(b.path,h.lineNumber,p.signal);return{source:w.source,summary:`Breakpoint ${w.source} registered at ${B.relative(g.options.cwd,w.file)}:${w.line} (${w.verified?"verified":"pending"}).`,data:{kind:"debug-breakpoint",session:g.source,file:w.file,line:w.line,verified:w.verified,snapshot:t.snapshot(g)}}}if(b.path!==g.source||b.anchor!==void 0)throw new Error("Debug commands target the session resource without an anchor");let f;try{f=await Xr(t,g,b.text,p.signal)}catch(h){if(p.signal?.aborted===!0)throw h;let w=h instanceof Error?h.message:String(h);return{source:g.source,summary:`${b.text.trim()} failed: ${w}
|
|
23
|
-
|
|
24
|
-
${W(g)}`,data:{...At(t,g,b.text),ok:!1,effect:"not-applied",error:{code:"DEBUG_ACTION_FAILED",message:w}}}}return{source:g.source,summary:f===void 0?W(g):`${f.expression} = ${f.result}${f.type===void 0?"":` (${f.type})`}`,data:At(t,g,b.text,f)}},"execute")}),l.tool("delete").describeField("path","debug:<session> ends it; debug:<session>/breakpoint/<id> removes a breakpoint."),l.tool("delete").addSemanticHandler({matches:d(p=>Kr(p,t),"matches"),execute:d(async(p,m)=>{let b=m.path,g=Rt(t,b),f=t.snapshot(g);n.set(b,f);let h=b.includes("/breakpoint/");await t.delete(b,p.signal);let w=h?t.snapshot(g):{...f,status:"terminated"};return{source:b,summary:`Deleted ${b}.`,data:{kind:h?"debug-breakpoint":"debug-session",deleted:!0,snapshot:w}}},"execute")}),l.describe('For debug:<session> resources, insert performs debugger actions without changing source text. On a debug source, insert "breakpoint" at an anchor. On the session, insert start, continue, step over, step into, step out, or evaluate <expression>. Delete removes a breakpoint or terminates the session.');for(let p of["insert","delete"])l.addToolRenderer({tool:p,matches(m,b){return b==="call"?F(m)&&typeof m.path=="string"&&(t.get(m.path)!==void 0||n.has(m.path)):he(F(m)&&"details"in m?m.details:m)!==void 0},renderCall(m,b,g){let f=m,h=f.path===void 0?void 0:t.get(f.path),w=f.path===void 0?void 0:n.get(f.path),D=g.state;h!==void 0?D.snapshot=t.snapshot(h):w!==void 0&&(D.snapshot=w);let E=D.snapshot;if(E===void 0)throw new Error("Debugger renderer lost its session");let _=f.path===void 0?void 0:t.breakpoint(f.path)??(w??E).breakpoints.find(z=>z.source===f.path),I=f.path===void 0?void 0:t.sourceFile(f.path),$=p==="delete"?_===void 0?"delete-session":`delete-breakpoint ${B.basename(_.file)}:${_.line}`:f.text==="breakpoint"&&I!==void 0?`breakpoint ${B.basename(I)}:${Qr(f)}`:f.text??"debug action";return ut(E,$,b)},renderResult(m,b,g){let f=he(m.details);if(f===void 0)throw new Error("Debugger result is missing its session");let h=bt(m.details);return J(f,b.expanded,g,h,mt(m.details))}})}};await Promise.all([Be(r,at),Re(r,u)]),await Oe(r,c),r.registerTool(Mr({name:"debug",exposure:"deferred",namespace:{name:"ide_debug",description:"Create debugger sessions and inspect debug resources."},annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},label:"Debug session",promptSnippet:"Configure a local debugger session",description:"Use debug to create a configured debugger session on a local or supported SSH workspace, through VS Code or a native adapter. This does not launch the program yet. The returned debug: resource survives extension reloads.",parameters:Gr,outputSchema:Jr,async execute(l,p,m,b,g){let f=p.backend??"auto",h=p.cwd??g.cwd,w=p.program;try{if(m?.throwIfAborted(),f==="vscode"&&[p.cwd,p.program,p.source].some(se=>se?.includes("://")))throw new Error("The VS Code backend debugs only local workspaces");let D=await e?.resolveOptions(p,g.cwd,m);if(D===void 0&&[h,w,p.source].some(se=>se?.includes("://")))throw new Error(`No debugger workspace owner: ${w}`);h=D?.cwd??B.resolve(g.cwd,p.cwd??"."),w=D?.program??B.resolve(h,p.program),D===void 0&&await Vr(w),m?.throwIfAborted();let E=B.resolve(h,p.source??p.program),_=D===void 0&&f!=="native"?await Wr(f,p,{cwd:h,program:w,sourceFile:E},m):{unavailable:"native backend requested"},I;if("vscode"in _)I=t.create({adapter:"vscode",program:w,sourceFile:E,args:[],cwd:h,...p.configuration===void 0?{}:{configuration:p.configuration},...p.test===void 0?{}:{test:p.test}},_.vscode);else{if(p.configuration!==void 0||p.test!==void 0)throw new Error("configuration and test need the VS Code backend");if(D!==void 0)I=t.create(D);else{if(p.adapter===void 0)throw new Error(`Select an adapter for the native debugger backend. VS Code is not used: ${_.unavailable}`);I=t.create({adapter:p.adapter,program:w,sourceFile:E,args:p.args??[],cwd:h,...p.mainClass===void 0?{}:{mainClass:p.mainClass}})}}let $=Yr(t,I),{snapshot:z,stop:bn,...Ot}=$;return de({content:[{type:"text",text:`${W(I)}
|
|
25
|
-
Source: ${$.sourceResource}
|
|
26
|
-
Breakpoints: ${$.breakpointsResource}
|
|
27
|
-
|
|
28
|
-
Next: read ${I.source} to inspect the configured session. To set a breakpoint, read ${$.sourceResource} with views ["anchors"], then insert "breakpoint" at an anchor.`}],details:$},Pe,{status:"success",data:Ot,errors:[]})}catch(D){return de({content:[{type:"text",text:D instanceof Error?D.message:String(D)}],details:{adapter:p.adapter??f,program:w,cwd:h,status:"failed"},isError:!0},Pe,{status:"error",errors:[Ee(D,"DEBUG_SESSION_FAILED",w)]})}},renderCall(l,p){let m=typeof l.cwd=="string"?l.cwd:".",b=typeof l.program=="string"?l.program:"program",g=m.startsWith("ssh://")?m:B.resolve(process.cwd(),m),f=b.startsWith("ssh://")||g.startsWith("ssh://")?b:B.resolve(g,b);return me(typeof l.adapter=="string"?l.adapter:l.backend==="vscode"?"vscode":"debugger",f,g,p)},renderResult(l,p,m){let b=F(l.details)?l.details.snapshot:void 0;if(typeof b=="object"&&b!==null)return J(b,p.expanded,m);let g=l.details;return me(g.adapter,g.program,g.cwd,m)}})),r.on("session_shutdown",async l=>{if(i(),l.reason!=="quit"){Ge("debugger",t);return}ze("debugger",t),await t.dispose()})}d(It,"registerDebuggerWithOwner");async function Wr(r,e,t,n){try{let o=(e.args?.length??0)>0?"args":e.mainClass===void 0?void 0:"mainClass";if(o!==void 0)throw new Error(`it does not accept ${o}; use a launch.json configuration`);return{vscode:await re.open(t,n)}}catch(o){n?.throwIfAborted();let a=o instanceof Error?o.message:String(o);if(r==="vscode"||e.configuration!==void 0||e.test!==void 0)throw new Error(`VS Code backend unavailable: ${a}`,{cause:o});return{unavailable:a}}}d(Wr,"openVscodeBackend");function _t(r,e){return{id:e,tryResolve(t){let n=r.get(t);return n===void 0?Promise.resolve({kind:"not-handled"}):Promise.resolve({kind:"resolved",resource:{source:t,async read(){await r.refresh(n);let o=r.sourceFile(t);if(o!==void 0)return[en(o,await r.readSource(t))];if(t===`${n.source}/breakpoints`)return[{type:"text",text:Zr(n)}];let a=r.breakpoint(t);if(t!==n.source&&a===void 0)throw new Error(`Unknown debug resource ${t}`);return[{type:"text",text:a===void 0?W(n):`Breakpoint: ${a.source}
|
|
29
|
-
File: ${a.file}
|
|
30
|
-
Line: ${a.line}
|
|
31
|
-
Status: ${a.verified?"verified":"pending"}`}]}}})}}}d(_t,"createDebugResourceResolver");function zr(r,e){if(!F(r)||typeof r.path!="string"||typeof r.text!="string")return!1;let t=e.get(r.path);return t!==void 0&&(r.path===t.source||e.sourceFile(r.path)!==void 0)}d(zr,"matchesDebugInsert");function Kr(r,e){if(!F(r)||typeof r.path!="string")return!1;let t=e.get(r.path);return t!==void 0&&(r.path===t.source||r.path.startsWith(`${t.source}/breakpoint/`))}d(Kr,"matchesDebugDelete");async function Xr(r,e,t,n){let o=t.trim(),a=/^evaluate\s+(.+)$/isu.exec(o);if(a!==null)return await r.evaluate(e,a[1],n);switch(o.toLowerCase()){case"start":{await r.start(e,n);return}case"continue":{await r.command(e,"continue",n);return}case"step over":{await r.command(e,"next",n);return}case"step into":{await r.command(e,"stepIn",n);return}case"step out":{await r.command(e,"stepOut",n);return}default:throw new Error(`Unknown debug command ${JSON.stringify(t)}`)}}d(Xr,"executeSessionCommand");function Yr(r,e){return{source:e.source,sourceResource:r.sourceResource(e),breakpointsResource:`${e.source}/breakpoints`,adapter:e.options.adapter,program:e.options.program,cwd:e.options.cwd,status:e.status,breakpoints:[...e.breakpoints.values()].map(({source:t,file:n,line:o,verified:a})=>({source:t,file:n,line:o,verified:a})),...e.stop===void 0?{}:{stop:e.stop},snapshot:r.snapshot(e)}}d(Yr,"debugDetails");function At(r,e,t,n){return{kind:"debug-command",command:t,status:e.status,breakpoints:[...e.breakpoints.values()].map(({source:o,file:a,line:i,verified:s})=>({source:o,file:a,line:i,verified:s})),...e.stop===void 0?{}:{stop:e.stop},...n===void 0?{}:{evaluation:n},snapshot:r.snapshot(e)}}d(At,"debugActionData");function Zr(r){return r.breakpoints.size===0?`No breakpoints in ${r.source}.`:[...r.breakpoints.values()].map(e=>`${e.verified?"\u25CF":"\u25CB"} ${e.file}:${e.line} \xB7 ${e.source} (${e.verified?"verified":"pending"})`).join(`
|
|
32
|
-
`)}d(Zr,"renderBreakpointList");function Rt(r,e){let t=r.get(e);if(t===void 0)throw new Error(`Unknown debug session ${e}`);return t}d(Rt,"requiredSession");function Qr(r){let e=F(r)&&typeof r.anchor=="string"?r.anchor:void 0;return/^(\d+)#/u.exec(e??"")?.[1]??e??"selected line"}d(Qr,"breakpointLine");function F(r){return typeof r=="object"&&r!==null}d(F,"isRecord");function en(r,e){return{type:"text",text:e,sourceLines:Object.fromEntries(e.split(/\r?\n/u).map((t,n)=>[String(n+1),{source:r,lineNumber:n+1,content:t}]))}}d(en,"debugSourceContent");import O from"node:path";import{readFile as Lt}from"node:fs/promises";import{Type as j}from"typebox";import{Value as un}from"typebox/value";import{Writable as tn}from"node:stream";import{callbackify as Tt}from"node:util";async function x(r,e,t){t.signal?.throwIfAborted();let n=r.resolve(e);if(!n)throw new v("UNSUPPORTED_SOURCE",e,"not-applied");let o=Object.entries(await qe(n.backend,n.location.path,t.env,t.signal)).map(([c,l])=>`${c}=${l}`),a=await n.backend.startProcess("env",[...o,t.command,...t.args],n.location.path,{signal:t.signal});a.stderr.resume();let i=new tn({write:Tt(async(c,l)=>{await a.write(c)}),final:Tt(async()=>{await a.end()})}),s,u=a.completion.then(c=>{if(c.exitCode!==0)throw new v("ADAPTER_EXITED",e,"unknown")});return u.catch(()=>{}),{readable:a.stdout,writable:i,completion:u,remote:{target:n.location.target,pid:a.pid,...a.identity===void 0?{}:{identity:a.identity}},stop(){return s??=Ve(a,r,e).finally(()=>{i.destroy()}),s}}}d(x,"startSshDapTransport");import{readFile as rn}from"node:fs/promises";var xt;async function Ct(r,e,t){t.signal?.throwIfAborted();let n=Buffer.from(JSON.stringify({kind:t.kind,program:t.program,args:t.args})+`
|
|
33
|
-
`);if(n.byteLength>65536)throw new v("BYTE_LIMIT",e,"not-applied");xt??=rn(new URL("./dap-tcp-worker.py",new URL("../src/backend/dap-tcp-transport.ts",import.meta.url).href),"utf8");let o=await x(r,e,{command:"python3",args:["-c",await xt],signal:t.signal});try{return await new Promise((a,i)=>{o.writable.once("error",i),o.writable.write(n,s=>s?i(s):a())}),t.signal?.throwIfAborted(),o}catch(a){throw await o.stop(),a}}d(Ct,"startSshTcpDapTransport");import{readFile as nn}from"node:fs/promises";async function jt(r,e,t,n){n?.throwIfAborted();let o=r.resolve(e);if(!o)throw new v("UNSUPPORTED_SOURCE",e,"not-applied");let a=await o.backend.execute("python3",["-c","import tempfile; print(tempfile.mkdtemp(prefix='pi-agent-ide-node-',dir='/tmp'))"],o.location.path,{signal:n}),i=a.stdout.toString("utf8").trim();if(a.exitCode!==0||!/^\/tmp\/pi-agent-ide-node-[A-Za-z0-9_-]+$/u.test(i))throw new v("INVALID_RESPONSE",e,"unknown");let s,u=new Set,c=new Set,l,p=d(()=>l!==void 0,"isStopping"),m=d(async()=>{if((await o.backend.execute("python3",["-c","import shutil,sys; shutil.rmtree(sys.argv[1])",i],o.location.path)).exitCode!==0)throw new v("CLEANUP_FAILED",e,"unknown")},"cleanup"),b=d(()=>(l??=(async()=>{try{await Promise.allSettled([...c]);let f=(await Promise.allSettled([...u].map(h=>h.stop()))).find(h=>h.status==="rejected");if(f)throw f.reason}finally{try{await s?.stop()}finally{await m()}}})(),l),"stop");try{let g=await nn(new URL("./dap-unix-worker.py",new URL("../src/backend/dap-node-transport.ts",import.meta.url).href),"utf8");s=await x(r,e,{command:"python3",args:["-c","import os,sys; script=os.environ.get('PI_JS_DEBUG_PATH','/opt/pi-debug-adapters/js-debug/src/dapDebugServer.js'); os.execvpe('node',['node',script,sys.argv[1]],os.environ)",`${i}/dap.sock`],env:{TMPDIR:i},signal:n}),s.readable.resume();let f=s,h=f.remote.identity;if(!h)throw new v("CAPABILITY_UNAVAILABLE",e,"not-applied");let w=d(async()=>{if(p())throw new v("SESSION_CLOSED",e,"not-applied");let E=x(r,e,{command:"python3",args:["-c",g,`${i}/dap.sock`,String(f.remote.pid),h],signal:n});c.add(E);try{let _=await E;if(u.add(_),p())throw new v("SESSION_CLOSED",e,"not-applied");return _}finally{c.delete(E)}},"connect"),D=await w();return{client:S.fromTransport({readable:D.readable,writable:D.writable,completion:Promise.race([D.completion,f.completion]),stop:b}),connectChild:d(async()=>S.fromTransport(await w()),"connectChild"),adapterID:"pwa-node",request:"launch",remote:f.remote,launch:t}}catch(g){throw await b(),g}}d(jt,"prepareSshNodeDebugger");import{readFile as an}from"node:fs/promises";import{Type as Se}from"typebox";import{Value as on}from"typebox/value";var sn=Se.Object({port:Se.Integer({minimum:1,maximum:65535}),sourceRoot:Se.String()},{additionalProperties:!1});async function $t(r,e,t,n){if(t.mainClass===void 0)throw new v("INVALID_REQUEST",e,"not-applied");let o=await an(new URL("./dap-java-worker.py",new URL("../src/backend/dap-java-transport.ts",import.meta.url).href),"utf8"),a=AbortSignal.any([...n===void 0?[]:[n],AbortSignal.timeout(4e4)]),i=await x(r,e,{command:"python3",args:["-c",o,JSON.stringify({mainClass:t.mainClass,args:t.args,sourceFile:t.sourceFile})],signal:n});try{let s=await dn(i,e,a);a.throwIfAborted();let u=S.fromTransport(i);return i.readable.resume(),{client:u,adapterID:"java",request:"attach",launch:{hostName:"127.0.0.1",port:s.port,timeout:1e4,sourcePaths:[s.sourceRoot]},remote:i.remote}}catch(s){throw await i.stop(),s}}d($t,"prepareSshJavaDebugger");function dn(r,e,t){return new Promise((n,o)=>{let a=Buffer.alloc(0),i=d(()=>{t.removeEventListener("abort",c),r.readable.removeListener("data",l),r.readable.removeListener("end",u),r.readable.removeListener("error",s)},"cleanup"),s=d(p=>{i(),o(p)},"failed"),u=d(()=>s(new v("ADAPTER_EXITED",e,"not-applied")),"closed"),c=d(()=>s(t.reason),"aborted"),l=d(p=>{a=Buffer.concat([a,p]);let m=a.indexOf(10);if(m<0){a.length>4096&&s(new v("INVALID_RESPONSE",e,"not-applied"));return}r.readable.pause(),i();try{if(m>4096)throw new Error("Java startup header limit");let b=JSON.parse(a.subarray(0,m).toString("utf8"));if(!on.Check(sn,b))throw new Error("Invalid Java startup header");a.length>m+1&&r.readable.unshift(a.subarray(m+1)),n(b)}catch{o(new v("INVALID_RESPONSE",e,"not-applied"))}},"received");r.readable.on("data",l),r.readable.once("end",u),r.readable.once("error",s),t.addEventListener("abort",c,{once:!0}),r.completion.then(u,s),t.aborted&&c()})}d(dn,"readReady");var cn=j.Object({phpDebug:j.String(),php:j.String(),luaDebug:j.String(),lua:j.String(),bashRoot:j.String(),bashDebug:j.Union([j.String(),j.Null()]),bash:j.String()},{additionalProperties:!1});async function ln(r,e,t,n,o){let a={phpDebug:["PI_PHP_DEBUG_PATH","/opt/pi-debug-adapters/php-debug/extension/out/phpDebug.js"],php:["PI_PHP_PATH","php"],luaDebug:["PI_LUA_DEBUG_PATH","/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js"],lua:["PI_LUA_PATH","lua"],bashRoot:["PI_BASH_DEBUG_ROOT","/opt/pi-debug-adapters/bash-debug/extension"],bashDebug:["PI_BASH_DEBUG_PATH",null],bash:["PI_BASH_PATH","/usr/bin/bash"]},i=await r.execute("python3",["-c","import json,os,sys; fields=json.loads(sys.argv[1]); print(json.dumps({k:os.environ.get(v[0],v[1]) for k,v in fields.items()}))",JSON.stringify(a)],n,{signal:o});if(i.exitCode!==0)throw new v("DEPENDENCY_UNAVAILABLE",e.program,"not-applied");let s;try{s=JSON.parse(i.stdout.toString("utf8"))}catch{throw new v("INVALID_RESPONSE",e.program,"not-applied")}if(!un.Check(cn,s))throw new v("INVALID_RESPONSE",e.program,"not-applied");let u={name:"Pi Agent IDE debug session",request:"launch",program:t,cwd:n,args:[...e.args]};if(e.adapter==="php")return{command:"node",overrides:[],args:[s.phpDebug],adapterID:"php",launch:{...u,type:"php",runtimeExecutable:s.php,runtimeArgs:["-dxdebug.start_with_request=yes"],console:"internalConsole",hostname:"127.0.0.1",port:0,env:{XDEBUG_MODE:"debug,develop",XDEBUG_CONFIG:"client_port=${port}"}}};if(e.adapter==="lua")return{command:"node",overrides:[],args:[s.luaDebug],adapterID:"lua-local",launch:{...u,type:"lua-local",program:{lua:s.lua,file:t},extensionPath:O.posix.dirname(O.posix.dirname(s.luaDebug)),workspacePath:n}};if(e.adapter==="shell")return{command:"node",overrides:[],args:[s.bashDebug??O.posix.join(s.bashRoot,"out/bashDebug.js")],adapterID:"bashdb",launch:{...u,type:"bashdb",pathBash:s.bash,pathBashdb:O.posix.join(s.bashRoot,"bashdb_dir/bashdb"),pathBashdbLib:O.posix.join(s.bashRoot,"bashdb_dir"),pathCat:"/usr/bin/cat",pathMkfifo:"/usr/bin/mkfifo",pathPkill:"/usr/bin/pkill",terminalKind:"debugConsole",argsString:"",env:{},showDebugOutput:!1,trace:!1}};throw new v("CAPABILITY_UNAVAILABLE",e.program,"not-applied")}d(ln,"nodeStdioRecipe");function pn(r,e,t,n){let o={name:"Pi Agent IDE debug session",request:"launch",program:e,cwd:t,args:[...r.args]};switch(r.adapter){case"debugpy":return{command:"python3",overrides:["PI_PYTHON_PATH"],args:["-m","debugpy.adapter"],adapterID:"debugpy",launch:{...o,type:"python",console:"internalConsole",justMyCode:!1}};case"dart":return{command:"dart",overrides:["PI_DART_PATH"],args:["debug_adapter"],adapterID:"dart",launch:{...o,type:"dart",debugSdkLibraries:!1,debugExternalPackageLibraries:!1,stopOnEntry:!0,vmAdditionalArgs:["--pause-isolates-on-start"]}};case"kotlin":{if(r.mainClass===void 0)throw new Error("Java and Kotlin debug sessions require mainClass");return{command:"kotlin-debug-adapter",overrides:["PI_KOTLIN_DEBUG_ADAPTER_PATH"],args:[],adapterID:r.adapter,launch:{...o,type:"kotlin",mainClass:r.mainClass,projectRoot:t,stopOnEntry:!0}}}case"netcoredbg":return{command:"netcoredbg",overrides:["PI_NETCOREDBG_PATH"],args:["--interpreter=vscode"],adapterID:"coreclr",launch:{...o,type:"coreclr",console:"internalConsole"}};case"elixir":return{command:"/opt/pi-debug-adapters/elixir-ls/debug_adapter.sh",overrides:["PI_ELIXIR_LS_DEBUG_PATH"],args:[],adapterID:"mix_task",launch:{name:o.name,request:"launch",type:"mix_task",task:"run",taskArgs:[e,...r.args],projectDir:t,startApps:!0,exitAfterTaskReturns:!0}};case"lldb-dap":{let a=O.posix.extname(n).toLowerCase()===".swift";return{command:a?"lldb-dap":"lldb-dap-18",overrides:a?["PI_SWIFT_LLDB_DAP_PATH","PI_LLDB_DAP_PATH"]:["PI_LLDB_DAP_PATH"],args:[],adapterID:"lldb-dap",launch:{...o,type:"lldb-dap"}}}default:throw new v("CAPABILITY_UNAVAILABLE",r.program,"not-applied")}}d(pn,"stdioRecipe");function Bt(r){return e=>{let t=r.resolve(e);if(!t){if(e.includes("://"))throw new v("UNSUPPORTED_SOURCE",e,"not-applied");return}let n=d(u=>{let c=r.resolve(u,t.location.source);if(!c||c.location.target!==t.location.target)throw new v("UNSUPPORTED_SOURCE",u,"not-applied");return c},"resolve"),{id:o,host:a,workspace:i,configFile:s}=t.backend.target;return{key:JSON.stringify([o,a,i,s??null]),serverPath:d(u=>n(u).location.path,"serverPath"),resourcePath(u){if(!O.posix.isAbsolute(u)||u.includes("\0"))throw new v("INVALID_RESPONSE",t.location.source,"not-applied");return K(t.location.target,u).source},async readText(u){let c=n(u);return new TextDecoder("utf-8",{fatal:!0}).decode((await c.backend.read(c.location.path)).bytes)},async prepare(u,c){c?.throwIfAborted();let l=n(u.program).location.path,p=n(u.cwd).location.path,m=n(u.sourceFile).location.path;if(u.adapter==="java")return await $t(r,t.location.source,{...u,cwd:p,program:l,sourceFile:m},c);if(u.adapter==="delve"||u.adapter==="ruby"||u.adapter==="julia"){let f=await Ct(r,t.location.source,{kind:u.adapter,program:l,args:u.args,signal:c}),h=u.adapter==="delve"?"go":u.adapter==="ruby"?"rdbg":"julia";return{client:S.fromTransport(f),adapterID:h,request:"launch",remote:f.remote,launch:{name:"Pi Agent IDE debug session",request:"launch",type:h,program:l,cwd:p,args:[...u.args],...u.adapter==="delve"?{mode:"debug"}:{},...u.adapter==="julia"?{stopOnEntry:!1}:{}}}}if(u.adapter==="node")return jt(r,t.location.source,{name:"Pi Agent IDE debug session",request:"launch",type:"pwa-node",program:l,cwd:p,args:[...u.args],console:"internalConsole",autoAttachChildProcesses:!1,stopOnEntry:!0,sourceMaps:!0,pauseForSourceMap:!0,outFiles:[O.posix.join(O.posix.dirname(l),"**","*.js")]},c);if(u.adapter==="r"){let f=await Lt(new URL("./dap-r-worker.py",new URL("../src/backend/debugger-workspace-owner.ts",import.meta.url).href),"utf8"),h=await x(r,t.location.source,{command:"python3",args:["-c",f],signal:c});return{client:S.fromTransport(h),adapterID:"R-Debugger",request:"launch",remote:h.remote,launch:{name:"Pi Agent IDE debug session",request:"launch",type:"R-Debugger",debugMode:"file",file:l,workingDirectory:p,commandLineArgs:[...u.args],allowGlobalDebugging:!1,loadPackages:[],supportsStdoutReading:!0,supportsWriteToStdinEvent:!0,overwriteHelp:!1}}}if(u.adapter==="powershell"){let f=await Lt(new URL("./dap-powershell-worker.py",new URL("../src/backend/debugger-workspace-owner.ts",import.meta.url).href),"utf8"),h=await x(r,t.location.source,{command:"python3",args:["-c",f],signal:c});return{client:S.fromTransport(h),adapterID:"PowerShell",request:"launch",remote:h.remote,launch:{name:"Pi Agent IDE debug session",request:"launch",program:l,script:l,cwd:p,args:[...u.args],createTemporaryIntegratedConsole:!1,executeMode:"Call"}}}let b=u.adapter==="php"||u.adapter==="lua"||u.adapter==="shell"?await ln(t.backend,u,l,p,c):pn(u,l,p,m),g=await x(r,t.location.source,{command:"python3",args:["-c","import json,os,sys; names=json.loads(sys.argv[1]); p=next((os.environ[n] for n in names if os.environ.get(n)),sys.argv[2]); args=json.loads(sys.argv[3]); os.execvpe(p,[p,*args],os.environ)",JSON.stringify(b.overrides),b.command,JSON.stringify(b.args)],signal:c});return{client:S.fromTransport(g),adapterID:b.adapterID,request:"launch",remote:g.remote,launch:b.launch}}}}}d(Bt,"createSshDebuggerWorkspaceOwner");function gn(r){return{workspace:Bt(r),async resolveOptions(e,t,n){n?.throwIfAborted();let o=r.resolve(e.program),a=e.cwd??(o?K(o.location.target,o.backend.target.workspace).source:t),i=r.resolve(a,t);if(!i){if([a,e.program,e.source].some(l=>l?.includes("://")))throw new v("UNSUPPORTED_SOURCE",e.program,"not-applied");return}let s=e.adapter;if(s===void 0)throw new Error("Select an adapter: SSH workspaces use the native debugger backend");let u=r.resolve(e.program,i.location.source),c=r.resolve(e.source??e.program,i.location.source);if(!u||!c||u.location.target!==i.location.target||c.location.target!==i.location.target)throw new v("UNSUPPORTED_SOURCE",e.program,"not-applied");return await u.backend.stat(u.location.path,{signal:n}),c.location.source!==u.location.source&&await c.backend.stat(c.location.path,{signal:n}),{adapter:s,program:u.location.source,sourceFile:c.location.source,cwd:i.location.source,args:e.args??[],...e.mainClass===void 0?{}:{mainClass:e.mainClass}}}}}d(gn,"createSshDebuggerAccess");async function fn(r){let e=new Me(await He(Ue(Fe())));await It(r,gn(e))}d(fn,"registerOwnedDebugger");export{gn as createSshDebuggerAccess,fn as default};
|
package/dist/entry-23.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./chunk-K4ZMRDEI.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-23.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-32.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-36.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-38.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-44.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-52.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-63.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-65.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-67.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../dist/entry-86.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../../../../../dist/entry-32.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../dist/entry-47.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../dist/entry-53.js";
|
package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-63.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../../../dist/entry-63.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../../../dist/entry-65.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../dist/entry-67.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../dist/entry-36.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../../../../dist/entry-38.js";
|
|
File without changes
|
|
File without changes
|