pi-agent-ide 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +7 -7
- package/dist/chunk-25CZ5ZIU.js +3 -0
- package/dist/chunk-526E364R.js +3 -0
- package/dist/chunk-5PLV4HLG.js +1 -0
- package/dist/chunk-5QQABP47.js +14 -0
- package/dist/{chunk-72EEL2DW.js → chunk-6CZO43OH.js} +1 -1
- package/dist/chunk-AWXVJ5AC.js +1 -0
- package/dist/chunk-BGUSBUUD.js +26 -0
- package/dist/{chunk-GFW5QPQV.js → chunk-DQXPQOF7.js} +1 -1
- package/dist/chunk-ESPNEJHK.js +1 -0
- package/dist/chunk-G725MARR.js +16 -0
- package/dist/{chunk-M5L42DWE.js → chunk-HKXDP2FD.js} +2 -2
- package/dist/chunk-IQD6PON5.js +0 -0
- package/dist/chunk-J4RTW44E.js +1 -0
- package/dist/{chunk-HGPUI7F3.js → chunk-KII2JQC5.js} +1 -1
- package/dist/{chunk-TI5GMJ7Q.js → chunk-L7JMDDSD.js} +1 -1
- package/dist/{chunk-6DZA4CLO.js → chunk-LY6U5EAD.js} +1 -1
- package/dist/{chunk-ERVMDQGX.js → chunk-MGCHOGQD.js} +1 -1
- package/dist/{chunk-Y7ZMR4LT.js → chunk-O6LE42GK.js} +1 -1
- package/dist/{chunk-KAB3AYA2.js → chunk-OBNING2A.js} +1 -1
- package/dist/chunk-QH4ZUDOD.js +1 -0
- package/dist/{chunk-VFBLX4TG.js → chunk-T6LX2RX5.js} +1 -1
- package/dist/{chunk-AADJ2KIB.js → chunk-U22JNO6N.js} +1 -1
- package/dist/chunk-U2JKHKLK.js +0 -0
- package/dist/{chunk-DQF5QMJ2.js → chunk-WGGIQ7IJ.js} +1 -1
- package/dist/chunk-ZG2MWXCR.js +2 -0
- package/dist/chunk-ZUMN6U77.js +27 -0
- package/dist/entry-10.js +1 -1
- package/dist/entry-11.js +1 -1
- package/dist/entry-12.js +1 -1
- package/dist/entry-13.js +1 -1
- package/dist/entry-14.js +1 -1
- package/dist/entry-15.js +1 -0
- package/dist/entry-17.js +1 -1
- package/dist/entry-18.js +1 -1
- package/dist/entry-19.js +1 -1
- package/dist/entry-20.js +1 -1
- package/dist/entry-21.js +1 -2
- package/dist/entry-22.js +2 -1
- package/dist/entry-23.js +1 -1
- package/dist/entry-24.js +1 -1
- package/dist/entry-25.js +1 -1
- package/dist/entry-26.js +1 -12
- package/dist/entry-27.js +12 -1
- package/dist/entry-28.js +1 -1
- package/dist/entry-29.js +1 -1
- package/dist/entry-30.js +1 -1
- package/dist/entry-31.js +1 -4
- package/dist/entry-32.js +3 -8
- package/dist/entry-33.js +9 -1
- package/dist/entry-34.js +1 -1
- package/dist/entry-35.js +1 -1
- package/dist/entry-36.js +1 -1
- package/dist/entry-37.js +1 -1
- package/dist/entry-38.js +1 -1
- package/dist/entry-39.js +1 -1
- package/dist/entry-40.js +1 -18
- package/dist/entry-41.js +18 -1
- package/dist/entry-42.js +1 -1
- package/dist/entry-43.js +1 -1
- package/dist/entry-44.js +1 -1
- package/dist/entry-45.js +1 -7
- package/dist/entry-46.js +7 -11
- package/dist/entry-47.js +11 -1
- package/dist/entry-48.js +1 -1
- package/dist/entry-49.js +1 -1
- package/dist/entry-50.js +1 -1
- package/dist/entry-51.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-53.js +1 -1
- package/dist/entry-54.js +1 -1
- package/dist/entry-55.js +1 -0
- package/dist/entry-56.js +0 -1
- package/dist/entry-57.js +1 -0
- package/dist/entry-58.js +0 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-60.js +1 -1
- package/dist/entry-61.js +1 -1
- package/dist/entry-62.js +1 -1
- package/dist/entry-63.js +1 -1
- package/dist/entry-64.js +1 -0
- package/dist/entry-65.js +0 -1
- package/dist/entry-66.js +1 -0
- package/dist/entry-67.js +0 -1
- package/dist/entry-68.js +1 -1
- package/dist/entry-69.js +1 -1
- package/dist/entry-70.js +1 -123
- package/dist/entry-71.js +198 -25
- package/dist/entry-72.js +30 -2
- package/dist/entry-73.js +2 -1
- package/dist/entry-74.js +1 -1
- package/dist/entry-75.js +1 -1
- package/dist/entry-76.js +1 -3
- package/dist/entry-77.js +3 -1
- package/dist/entry-78.js +1 -1
- package/dist/entry-79.js +1 -1
- package/dist/entry-8.js +1 -1
- package/dist/entry-80.js +1 -0
- package/dist/entry-9.js +1 -1
- package/dist/pi-agent-ide.js +3 -3
- package/docs/configuration.md +1 -1
- package/docs/user-hooks.md +68 -0
- package/node_modules/pi-agent-doctor/package.json +6 -6
- package/node_modules/pi-agent-doctor/runtime/entry-21.js +1 -0
- package/node_modules/pi-agent-doctor/src/catalog.ts +9 -1
- package/node_modules/pi-agent-doctor/src/plugin-protocol.ts +5 -0
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +4 -4
- package/node_modules/pi-agent-filesystem-pdf/package.json +4 -4
- package/node_modules/pi-agent-filesystem-text/package.json +4 -4
- package/node_modules/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
- package/node_modules/pi-agent-ide-ast/package.json +32 -11
- package/node_modules/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/node_modules/pi-agent-ide-ast/runtime/entry-27.js +2 -0
- package/node_modules/pi-agent-ide-ast/src/ast/manager.ts +16 -8
- package/node_modules/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
- package/node_modules/pi-agent-ide-ast/src/ast/outline.ts +22 -17
- package/node_modules/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
- package/node_modules/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
- package/node_modules/pi-agent-ide-ast/src/search-resolver.ts +4 -1
- package/node_modules/pi-agent-ide-changes/index.ts +3 -1
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- package/node_modules/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
- package/node_modules/pi-agent-ide-formatter/package.json +9 -4
- package/node_modules/pi-agent-ide-languages/package.json +3 -3
- package/node_modules/pi-agent-ide-lint/package.json +13 -8
- package/node_modules/pi-agent-ide-lsp/index.ts +4 -1
- package/node_modules/pi-agent-ide-lsp/package.json +15 -10
- package/node_modules/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
- package/node_modules/pi-agent-image/package.json +3 -3
- package/node_modules/pi-agent-invariant/package.json +2 -2
- package/node_modules/pi-agent-pdf/package.json +3 -3
- package/node_modules/pi-agent-read/package.json +11 -11
- package/node_modules/pi-agent-read/runtime/entry-40.js +0 -1
- package/node_modules/pi-agent-read/runtime/entry-41.js +2 -0
- package/node_modules/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/node_modules/pi-agent-read/src/api/rendering.ts +1 -1
- package/node_modules/pi-agent-read/src/api/tools/read.ts +32 -0
- package/node_modules/pi-agent-read/src/core/read-core.ts +8 -0
- package/node_modules/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
- package/node_modules/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +105 -5
- package/node_modules/pi-agent-resource/package.json +2 -2
- package/node_modules/pi-agent-search/package.json +7 -7
- package/node_modules/pi-agent-search/runtime/entry-45.js +0 -1
- package/node_modules/pi-agent-search/src/api/search-parameters.ts +5 -1
- package/node_modules/pi-agent-search-text/index.ts +1 -1
- package/node_modules/pi-agent-search-text/package.json +9 -9
- package/node_modules/pi-agent-search-text/runtime/entry-47.js +1 -0
- package/node_modules/pi-agent-search-text/src/resolvers.ts +47 -19
- package/node_modules/pi-agent-search-text/src/search-backend.ts +6 -15
- package/node_modules/pi-agent-search-text/src/search-presentation.ts +80 -0
- package/node_modules/pi-agent-search-text/src/search-renderer.ts +17 -1
- package/node_modules/pi-agent-search-text/src/search-result.ts +32 -12
- package/node_modules/pi-agent-search-text/src/search-session.ts +6 -3
- package/node_modules/pi-agent-text/package.json +3 -3
- package/node_modules/pi-agent-text/runtime/entry-49.js +1 -0
- package/node_modules/pi-agent-text-anchor-constant/package.json +4 -4
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
- package/node_modules/pi-agent-text-anchor-exact/package.json +5 -5
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
- package/node_modules/pi-agent-text-editor/package.json +25 -25
- package/node_modules/pi-agent-text-editor/runtime/entry-70.js +0 -1
- package/node_modules/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
- package/node_modules/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/node_modules/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
- package/node_modules/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
- package/node_modules/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
- package/node_modules/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
- package/node_modules/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
- package/node_modules/pi-agent-text-editor/src/core/apply/output.ts +37 -8
- package/node_modules/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
- package/node_modules/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
- package/node_modules/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
- package/node_modules/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
- package/node_modules/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
- package/node_modules/pi-agent-text-editor/src/core/extension.ts +3 -2
- package/node_modules/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
- package/node_modules/pi-agent-text-editor/src/core/file-operations.ts +4 -4
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
- package/node_modules/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/node_modules/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
- package/node_modules/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
- package/node_modules/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
- package/node_modules/pi-agent-text-editor-renderer/index.ts +5 -0
- package/node_modules/pi-agent-text-editor-renderer/package.json +6 -6
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
- package/node_modules/pi-agent-tool-call-interception/package.json +3 -3
- package/node_modules/pi-agent-tool-ui/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/runtime/entry-75.js +1 -0
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web-html/package.json +3 -3
- package/node_modules/pi-agent-web-image/package.json +4 -4
- package/node_modules/pi-agent-web-pdf/package.json +4 -4
- package/node_modules/pi-agent-web-text/package.json +4 -4
- package/node_modules/pi-agent-web-text/runtime/entry-80.js +2 -0
- package/package.json +58 -38
- package/src/api/hooks.ts +168 -0
- package/src/api/text-editor.ts +2 -0
- package/src/composite/builtin-extensions.ts +7 -0
- package/src/composite/module-labels.ts +8 -0
- package/src/composite/preferences.ts +3 -3
- package/src/core/reload-resource-store.ts +34 -0
- package/src/doctor/tip-provider.ts +1 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/runtime/entry-25.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-22.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +4 -4
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/runtime/entry-80.js +2 -0
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-76.js +2 -0
- package/src/extensions/pi-agent-read/package.json +11 -11
- package/src/extensions/pi-agent-read/runtime/entry-40.js +0 -1
- package/src/extensions/pi-agent-read/runtime/entry-41.js +2 -0
- package/src/extensions/pi-agent-read/src/api/plugin-protocol.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/rendering.ts +1 -1
- package/src/extensions/pi-agent-read/src/api/tools/read.ts +32 -0
- package/src/extensions/pi-agent-read/src/core/read-core.ts +8 -0
- package/src/extensions/pi-agent-read/src/core/tools/read/raw-read.ts +38 -4
- package/src/extensions/pi-agent-read/src/core/tools/read/read-renderer.ts +63 -4
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +105 -5
- package/src/extensions/pi-agent-search/package.json +7 -7
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/index.ts +1 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +9 -9
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-47.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-48.js +1 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/resolvers.ts +47 -19
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-backend.ts +6 -15
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-presentation.ts +80 -0
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-renderer.ts +17 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-result.ts +32 -12
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/search-session.ts +6 -3
- package/src/extensions/pi-agent-search/runtime/entry-45.js +0 -1
- package/src/extensions/pi-agent-search/runtime/entry-46.js +2 -0
- package/src/extensions/pi-agent-search/src/api/search-parameters.ts +5 -1
- package/src/extensions/pi-agent-text-editor/package.json +25 -25
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +4 -4
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-50.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-51.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-52.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +7 -7
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-53.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-54.js +2 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +5 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +6 -6
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +59 -0
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/runtime/entry-73.js +2 -0
- package/src/extensions/pi-agent-text-editor/runtime/entry-70.js +0 -1
- package/src/extensions/pi-agent-text-editor/runtime/entry-71.js +2 -0
- package/src/extensions/pi-agent-text-editor/src/api/edit-completion.ts +7 -1
- package/src/extensions/pi-agent-text-editor/src/api/edit-pipeline.ts +3 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-guard.ts +1 -0
- package/src/extensions/pi-agent-text-editor/src/api/mutation-tool.ts +47 -0
- package/src/extensions/pi-agent-text-editor/src/api/plugin-protocol.ts +6 -1
- package/src/extensions/pi-agent-text-editor/src/core/apply/apply-undo-store.ts +155 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/execution.ts +56 -77
- package/src/extensions/pi-agent-text-editor/src/core/apply/mixed-source.ts +7 -12
- package/src/extensions/pi-agent-text-editor/src/core/apply/mutation-outcome.ts +2 -0
- package/src/extensions/pi-agent-text-editor/src/core/apply/output.ts +37 -8
- package/src/extensions/pi-agent-text-editor/src/core/apply/prompt.ts +42 -37
- package/src/extensions/pi-agent-text-editor/src/core/apply/renderer.ts +51 -15
- package/src/extensions/pi-agent-text-editor/src/core/apply/runtime.ts +119 -20
- package/src/extensions/pi-agent-text-editor/src/core/apply/tool.ts +28 -7
- package/src/extensions/pi-agent-text-editor/src/core/apply/transaction.ts +387 -0
- package/src/extensions/pi-agent-text-editor/src/core/extension.ts +3 -2
- package/src/extensions/pi-agent-text-editor/src/core/file-operation-tools.ts +68 -71
- package/src/extensions/pi-agent-text-editor/src/core/file-operations.ts +4 -4
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch-registrar.ts +11 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-edit-batch.ts +4 -0
- package/src/extensions/pi-agent-text-editor/src/core/text-editor-core.ts +141 -6
- package/src/extensions/pi-agent-text-editor/src/core/text-mutation.ts +123 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-copy.ts +9 -4
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-delete.ts +3 -2
- package/src/extensions/pi-agent-text-editor/src/tools/tool-text-move.ts +9 -4
- package/src/plugins/pi-agent-ide-ast/package.json +32 -11
- package/src/plugins/pi-agent-ide-ast/runtime/entry-26.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-27.js +2 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/manager.ts +16 -8
- package/src/plugins/pi-agent-ide-ast/src/ast/native-parser.ts +151 -0
- package/src/plugins/pi-agent-ide-ast/src/ast/outline.ts +22 -17
- package/src/plugins/pi-agent-ide-ast/src/ast/syntax-tree.ts +25 -0
- package/src/plugins/pi-agent-ide-ast/src/doctor-plugin.ts +52 -1
- package/src/plugins/pi-agent-ide-ast/src/search-resolver.ts +4 -1
- package/src/plugins/pi-agent-ide-changes/index.ts +3 -1
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-changes/runtime/entry-28.js +0 -1
- package/src/plugins/pi-agent-ide-changes/src/tool-text-undo.ts +42 -9
- package/src/plugins/pi-agent-ide-debugger/index.ts +573 -0
- package/src/plugins/pi-agent-ide-debugger/src/breakpoint-view.ts +73 -0
- package/src/plugins/pi-agent-ide-debugger/src/catalog.ts +306 -0
- package/src/plugins/pi-agent-ide-debugger/src/dap-client.ts +338 -0
- package/src/plugins/pi-agent-ide-debugger/src/doctor-plugin.ts +349 -0
- package/src/plugins/pi-agent-ide-debugger/src/process-provider.ts +39 -0
- package/src/plugins/pi-agent-ide-debugger/src/renderer.ts +152 -0
- package/src/plugins/pi-agent-ide-debugger/src/session-manager.ts +1344 -0
- package/src/plugins/pi-agent-ide-debugger/src/ui.ts +14 -0
- package/src/plugins/pi-agent-ide-formatter/package.json +9 -4
- package/src/plugins/pi-agent-ide-languages/package.json +3 -3
- package/src/plugins/pi-agent-ide-lint/package.json +13 -8
- package/src/plugins/pi-agent-ide-lsp/index.ts +4 -1
- package/src/plugins/pi-agent-ide-lsp/package.json +15 -10
- package/src/plugins/pi-agent-ide-lsp/runtime/entry-33.js +2 -0
- package/src/plugins/pi-agent-ide-processes/index.ts +28 -0
- package/src/plugins/pi-agent-ide-processes/src/registry.ts +81 -0
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +252 -0
- package/src/plugins/pi-agent-ide-terminal/index.ts +19 -13
- package/src/plugins/pi-agent-ide-terminal/src/output-limits.ts +52 -0
- package/src/plugins/pi-agent-ide-terminal/src/process-provider.ts +30 -0
- package/src/plugins/pi-agent-ide-terminal/src/renderer.ts +24 -58
- package/src/plugins/pi-agent-ide-terminal/src/resources.ts +5 -14
- package/src/plugins/pi-agent-ide-terminal/src/session-manager.ts +114 -1
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +23 -29
- package/src/plugins/pi-agent-ide-terminal/src/types.ts +13 -1
- package/src/plugins/pi-agent-ide-terminal/src/ui.ts +116 -240
- package/dist/chunk-3SE372WC.js +0 -3
- package/dist/chunk-5MSNYFDE.js +0 -1
- package/dist/chunk-7JYQMAEL.js +0 -14
- package/dist/chunk-B5KB2I7J.js +0 -3
- package/dist/chunk-NMFQGKPE.js +0 -2
- package/dist/chunk-OVUYPHDE.js +0 -1
- package/dist/chunk-TPIHQYK2.js +0 -14
- package/dist/chunk-XSTHESNR.js +0 -25
- package/dist/entry-16.js +0 -1
- package/node_modules/pi-agent-doctor/runtime/entry-16.js +0 -1
- package/node_modules/pi-agent-filesystem/runtime/entry-21.js +0 -2
- package/node_modules/pi-agent-ide-ast/runtime/entry-25.js +0 -1
- package/node_modules/pi-agent-ide-changes/runtime/entry-27.js +0 -1
- package/node_modules/pi-agent-image/runtime/entry-33.js +0 -1
- package/node_modules/pi-agent-resource/runtime/entry-41.js +0 -1
- package/node_modules/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
- package/node_modules/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
- package/node_modules/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
- package/node_modules/pi-agent-text-editor/runtime/entry-54.js +0 -1
- package/node_modules/pi-agent-tool-call-interception/runtime/entry-73.js +0 -1
- package/node_modules/pi-agent-web/runtime/entry-75.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/runtime/entry-22.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/runtime/entry-21.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/runtime/entry-76.js +0 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/runtime/entry-75.js +0 -2
- package/src/extensions/pi-agent-read/runtime/entry-36.js +0 -1
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/runtime/entry-46.js +0 -2
- package/src/extensions/pi-agent-search/runtime/entry-42.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/runtime/entry-49.js +0 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/runtime/entry-50.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/runtime/entry-52.js +0 -1
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/runtime/entry-71.js +0 -2
- package/src/extensions/pi-agent-text-editor/runtime/entry-54.js +0 -1
- package/src/plugins/pi-agent-ide-ast/runtime/entry-25.js +0 -1
- package/src/plugins/pi-agent-ide-changes/runtime/entry-27.js +0 -1
- /package/node_modules/{pi-agent-filesystem-image → pi-agent-filesystem}/runtime/entry-22.js +0 -0
- /package/node_modules/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
- /package/node_modules/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
- /package/node_modules/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
- /package/node_modules/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
- /package/node_modules/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
- /package/node_modules/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
- /package/node_modules/{pi-agent-invariant → pi-agent-image}/runtime/entry-34.js +0 -0
- /package/node_modules/{pi-agent-pdf → pi-agent-invariant}/runtime/entry-35.js +0 -0
- /package/node_modules/{pi-agent-read → pi-agent-pdf}/runtime/entry-36.js +0 -0
- /package/node_modules/{pi-agent-search → pi-agent-resource}/runtime/entry-42.js +0 -0
- /package/node_modules/{pi-agent-search-text → pi-agent-search}/runtime/entry-46.js +0 -0
- /package/node_modules/{pi-agent-text → pi-agent-search-text}/runtime/entry-48.js +0 -0
- /package/node_modules/{pi-agent-text-editor-renderer → pi-agent-text-editor}/runtime/entry-71.js +0 -0
- /package/node_modules/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
- /package/node_modules/{pi-agent-tool-ui → pi-agent-tool-call-interception}/runtime/entry-74.js +0 -0
- /package/node_modules/{pi-agent-web-html → pi-agent-web}/runtime/entry-76.js +0 -0
- /package/node_modules/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
- /package/node_modules/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
- /package/node_modules/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-pdf → pi-agent-filesystem-image}/runtime/entry-23.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/{pi-agent-filesystem-text → pi-agent-filesystem-pdf}/runtime/entry-24.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-image → pi-agent-web-html}/runtime/entry-77.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-pdf → pi-agent-web-image}/runtime/entry-78.js +0 -0
- /package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/{pi-agent-web-text → pi-agent-web-pdf}/runtime/entry-79.js +0 -0
- /package/src/extensions/pi-agent-text-editor/plugins/{pi-agent-text-editor-stale-anchor → pi-agent-text-editor-renderer}/runtime/entry-72.js +0 -0
- /package/src/plugins/{pi-agent-ide-formatter → pi-agent-ide-changes}/runtime/entry-29.js +0 -0
- /package/src/plugins/{pi-agent-ide-languages → pi-agent-ide-formatter}/runtime/entry-30.js +0 -0
- /package/src/plugins/{pi-agent-ide-lint → pi-agent-ide-languages}/runtime/entry-31.js +0 -0
- /package/src/plugins/{pi-agent-ide-lsp → pi-agent-ide-lint}/runtime/entry-32.js +0 -0
|
@@ -0,0 +1,1344 @@
|
|
|
1
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { rmSync } from "node:fs";
|
|
4
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
5
|
+
import net from "node:net";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
DapClient,
|
|
11
|
+
type DapEvent,
|
|
12
|
+
type DapReverseRequest,
|
|
13
|
+
} from "#src/plugins/pi-agent-ide-debugger/src/dap-client.js";
|
|
14
|
+
|
|
15
|
+
export type DebugSessionStatus = "configured" | "running" | "stopped" | "terminated";
|
|
16
|
+
|
|
17
|
+
/** Adapter identifiers accepted by agent-native debug sessions. */
|
|
18
|
+
export type DebugAdapter =
|
|
19
|
+
| "dart"
|
|
20
|
+
| "debugpy"
|
|
21
|
+
| "delve"
|
|
22
|
+
| "java"
|
|
23
|
+
| "elixir"
|
|
24
|
+
| "julia"
|
|
25
|
+
| "kotlin"
|
|
26
|
+
| "lldb-dap"
|
|
27
|
+
| "lua"
|
|
28
|
+
| "netcoredbg"
|
|
29
|
+
| "node"
|
|
30
|
+
| "php"
|
|
31
|
+
| "powershell"
|
|
32
|
+
| "r"
|
|
33
|
+
| "ruby"
|
|
34
|
+
| "shell";
|
|
35
|
+
|
|
36
|
+
export interface DebugSessionOptions {
|
|
37
|
+
readonly adapter: DebugAdapter;
|
|
38
|
+
readonly program: string;
|
|
39
|
+
readonly sourceFile: string;
|
|
40
|
+
readonly args: readonly string[];
|
|
41
|
+
readonly cwd: string;
|
|
42
|
+
readonly mainClass?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface DebugBreakpoint {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly source: string;
|
|
48
|
+
readonly file: string;
|
|
49
|
+
readonly line: number;
|
|
50
|
+
verified: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface DebugVariable {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly value: string;
|
|
56
|
+
readonly type?: string;
|
|
57
|
+
readonly variablesReference: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface DebugFrame {
|
|
61
|
+
readonly id: number;
|
|
62
|
+
readonly name: string;
|
|
63
|
+
readonly line: number;
|
|
64
|
+
readonly source?: { readonly path?: string; readonly name?: string };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface DebugSourceLine {
|
|
68
|
+
readonly lineNumber: number;
|
|
69
|
+
readonly content: string;
|
|
70
|
+
readonly current: boolean;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface DebugStop {
|
|
74
|
+
readonly generation: number;
|
|
75
|
+
readonly reason: string;
|
|
76
|
+
readonly threadId: number;
|
|
77
|
+
readonly frame?: DebugFrame;
|
|
78
|
+
readonly variables: readonly DebugVariable[];
|
|
79
|
+
readonly sourceLines: readonly DebugSourceLine[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface DebugSession {
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly source: string;
|
|
85
|
+
readonly options: DebugSessionOptions;
|
|
86
|
+
readonly breakpoints: Map<string, DebugBreakpoint>;
|
|
87
|
+
status: DebugSessionStatus;
|
|
88
|
+
client?: DapClient;
|
|
89
|
+
controlClient?: DapClient;
|
|
90
|
+
clients?: DapClient[];
|
|
91
|
+
adapterProcess?: ChildProcess;
|
|
92
|
+
adapterTemporaryDirectory?: string;
|
|
93
|
+
targetReady?: Promise<void>;
|
|
94
|
+
resolveTargetReady?: () => void;
|
|
95
|
+
rPromptInputs?: string[];
|
|
96
|
+
rAtBrowserPrompt?: boolean;
|
|
97
|
+
rStarted?: boolean;
|
|
98
|
+
stop?: DebugStop;
|
|
99
|
+
stopGeneration: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface DebugSessionSnapshot {
|
|
103
|
+
readonly id: string;
|
|
104
|
+
readonly source: string;
|
|
105
|
+
readonly options: DebugSessionOptions;
|
|
106
|
+
readonly status: DebugSessionStatus;
|
|
107
|
+
readonly breakpoints: readonly DebugBreakpoint[];
|
|
108
|
+
readonly stop?: DebugStop;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type DebugSessionChangeListener = (snapshot: DebugSessionSnapshot) => void;
|
|
112
|
+
|
|
113
|
+
interface ThreadsBody {
|
|
114
|
+
readonly threads?: readonly { readonly id: number; readonly name: string }[];
|
|
115
|
+
}
|
|
116
|
+
interface StackTraceBody {
|
|
117
|
+
readonly stackFrames?: readonly DebugFrame[];
|
|
118
|
+
}
|
|
119
|
+
interface ScopesBody {
|
|
120
|
+
readonly scopes?: readonly {
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly presentationHint?: string;
|
|
123
|
+
readonly variablesReference: number;
|
|
124
|
+
}[];
|
|
125
|
+
}
|
|
126
|
+
interface VariablesBody {
|
|
127
|
+
readonly variables?: readonly DebugVariable[];
|
|
128
|
+
}
|
|
129
|
+
interface SetBreakpointsBody {
|
|
130
|
+
readonly breakpoints?: readonly { readonly verified?: boolean; readonly line?: number }[];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Owns debug sessions and keeps DAP references scoped to their current stop. */
|
|
134
|
+
export class DebugSessionManager {
|
|
135
|
+
readonly #sessions = new Map<string, DebugSession>();
|
|
136
|
+
readonly #changeListeners = new Set<DebugSessionChangeListener>();
|
|
137
|
+
|
|
138
|
+
/** Create a configured session without launching the debuggee. */
|
|
139
|
+
create(
|
|
140
|
+
options: Omit<DebugSessionOptions, "sourceFile"> & { readonly sourceFile?: string },
|
|
141
|
+
): DebugSession {
|
|
142
|
+
const id = randomBytes(6).toString("hex");
|
|
143
|
+
const session: DebugSession = {
|
|
144
|
+
id,
|
|
145
|
+
source: `debug:${id}`,
|
|
146
|
+
options: { ...options, sourceFile: options.sourceFile ?? options.program },
|
|
147
|
+
breakpoints: new Map(),
|
|
148
|
+
status: "configured",
|
|
149
|
+
stopGeneration: 0,
|
|
150
|
+
};
|
|
151
|
+
this.#sessions.set(id, session);
|
|
152
|
+
this.#notify(session);
|
|
153
|
+
return session;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Resolve a session URI or one of its child resources. */
|
|
157
|
+
get(source: string): DebugSession | undefined {
|
|
158
|
+
const match = /^debug:([a-f\d]{12})(?:\/|$)/u.exec(source);
|
|
159
|
+
return match === null ? undefined : this.#sessions.get(match[1] as string);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** List sessions owned by the current Pi process. */
|
|
163
|
+
list(): readonly DebugSession[] {
|
|
164
|
+
return [...this.#sessions.values()];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Return immutable presentation data without exposing the adapter client. */
|
|
168
|
+
snapshot(session: DebugSession): DebugSessionSnapshot {
|
|
169
|
+
return {
|
|
170
|
+
id: session.id,
|
|
171
|
+
source: session.source,
|
|
172
|
+
options: session.options,
|
|
173
|
+
status: session.status,
|
|
174
|
+
breakpoints: [...session.breakpoints.values()].map((breakpoint) => ({ ...breakpoint })),
|
|
175
|
+
...(session.stop === undefined ? {} : { stop: session.stop }),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Observe session state changes used by debugger activity UI. */
|
|
180
|
+
onDidChange(listener: DebugSessionChangeListener): () => void {
|
|
181
|
+
this.#changeListeners.add(listener);
|
|
182
|
+
return () => this.#changeListeners.delete(listener);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Find breakpoints for a file, optionally scoped to one debug session. */
|
|
186
|
+
breakpointsForFile(file: string, sessionSource?: string): readonly DebugBreakpoint[] {
|
|
187
|
+
const absolute = path.resolve(file);
|
|
188
|
+
return this.list()
|
|
189
|
+
.filter((session) => sessionSource === undefined || session.source === sessionSource)
|
|
190
|
+
.flatMap((session) => [...session.breakpoints.values()])
|
|
191
|
+
.filter((breakpoint) => path.resolve(breakpoint.file) === absolute);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Return the source file represented by a session-owned source URI. */
|
|
195
|
+
sourceFile(source: string): string | undefined {
|
|
196
|
+
const session = this.get(source);
|
|
197
|
+
return session !== undefined && source === `${session.source}/source`
|
|
198
|
+
? session.options.sourceFile
|
|
199
|
+
: undefined;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Create the stable session-owned URI for source text. */
|
|
203
|
+
sourceResource(session: DebugSession): string {
|
|
204
|
+
return `${session.source}/source`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Read fresh source text so normal anchors detect edits before breakpoint creation. */
|
|
208
|
+
readSource(source: string): Promise<string> {
|
|
209
|
+
const file = this.sourceFile(source);
|
|
210
|
+
if (file === undefined) return Promise.reject(new Error(`Unknown debug source ${source}`));
|
|
211
|
+
return readFile(file, "utf8");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Store one breakpoint selected against a fresh source snapshot. */
|
|
215
|
+
async addBreakpoint(
|
|
216
|
+
source: string,
|
|
217
|
+
line: number,
|
|
218
|
+
signal?: AbortSignal,
|
|
219
|
+
): Promise<DebugBreakpoint> {
|
|
220
|
+
const session = this.get(source);
|
|
221
|
+
const file = this.sourceFile(source);
|
|
222
|
+
if (session === undefined || file === undefined)
|
|
223
|
+
throw new Error(`Unknown debug source ${source}`);
|
|
224
|
+
if (session.status === "terminated")
|
|
225
|
+
throw new Error("Cannot add a breakpoint to a terminated session");
|
|
226
|
+
const id = randomBytes(5).toString("hex");
|
|
227
|
+
const breakpoint: DebugBreakpoint = {
|
|
228
|
+
id,
|
|
229
|
+
source: `${session.source}/breakpoint/${id}`,
|
|
230
|
+
file,
|
|
231
|
+
line,
|
|
232
|
+
verified: false,
|
|
233
|
+
};
|
|
234
|
+
session.breakpoints.set(id, breakpoint);
|
|
235
|
+
if (session.client !== undefined)
|
|
236
|
+
await this.#configureBreakpointFile(session, session.client, file, signal);
|
|
237
|
+
this.#notify(session);
|
|
238
|
+
return breakpoint;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Resolve one stored breakpoint URI. */
|
|
242
|
+
breakpoint(source: string): DebugBreakpoint | undefined {
|
|
243
|
+
const session = this.get(source);
|
|
244
|
+
return session === undefined
|
|
245
|
+
? undefined
|
|
246
|
+
: [...session.breakpoints.values()].find((breakpoint) => breakpoint.source === source);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Launch the debuggee, configure breakpoints, and wait for a stop or termination. */
|
|
250
|
+
async start(session: DebugSession, signal?: AbortSignal): Promise<DebugSession> {
|
|
251
|
+
return this.#start(session, signal, 2);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async #start(
|
|
255
|
+
session: DebugSession,
|
|
256
|
+
signal: AbortSignal | undefined,
|
|
257
|
+
retriesLeft: number,
|
|
258
|
+
): Promise<DebugSession> {
|
|
259
|
+
if (session.status !== "configured") throw new Error(`Session is already ${session.status}`);
|
|
260
|
+
if (session.options.adapter === "powershell") {
|
|
261
|
+
session.adapterTemporaryDirectory = await mkdtemp(
|
|
262
|
+
path.join(tmpdir(), "pi-powershell-debug-"),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
const recipe = adapterRecipe(session.options, session.adapterTemporaryDirectory);
|
|
266
|
+
const client =
|
|
267
|
+
session.options.adapter === "node"
|
|
268
|
+
? await this.#startNodeAdapter(session)
|
|
269
|
+
: session.options.adapter === "delve"
|
|
270
|
+
? await this.#startDelveAdapter(session)
|
|
271
|
+
: session.options.adapter === "ruby"
|
|
272
|
+
? await this.#startRubyAdapter(session)
|
|
273
|
+
: session.options.adapter === "julia"
|
|
274
|
+
? await this.#startJuliaAdapter(session)
|
|
275
|
+
: session.options.adapter === "r"
|
|
276
|
+
? await this.#startRAdapter(session)
|
|
277
|
+
: DapClient.start(recipe.command, recipe.args, session.options.cwd);
|
|
278
|
+
session.client = client;
|
|
279
|
+
session.controlClient = client;
|
|
280
|
+
session.clients = [client];
|
|
281
|
+
if (session.options.adapter === "node") {
|
|
282
|
+
session.targetReady = new Promise((resolve) => {
|
|
283
|
+
session.resolveTargetReady = resolve;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
session.status = "running";
|
|
287
|
+
this.#notify(session);
|
|
288
|
+
try {
|
|
289
|
+
if (session.options.adapter !== "r") {
|
|
290
|
+
await initializeClient(client, recipe.adapterID, signal);
|
|
291
|
+
}
|
|
292
|
+
const initialized = client.waitForAnyEvent(["initialized"], 30_000, signal);
|
|
293
|
+
const launch = client.request(recipe.request, recipe.launch, { signal });
|
|
294
|
+
await initialized;
|
|
295
|
+
await this.#configureBreakpoints(session, client, signal);
|
|
296
|
+
const configurationDone = client.request("configurationDone", undefined, { signal });
|
|
297
|
+
if (session.options.adapter === "java" || session.options.adapter === "kotlin") {
|
|
298
|
+
// kotlin-debug-adapter deliberately keeps this response pending for the session lifetime.
|
|
299
|
+
void configurationDone.catch(() => {});
|
|
300
|
+
} else {
|
|
301
|
+
await configurationDone;
|
|
302
|
+
}
|
|
303
|
+
await launch;
|
|
304
|
+
if (session.options.adapter === "r") session.rStarted = true;
|
|
305
|
+
if (session.targetReady !== undefined) await session.targetReady;
|
|
306
|
+
await this.#waitForStop(session, signal);
|
|
307
|
+
if (
|
|
308
|
+
this.snapshot(session).status === "terminated" &&
|
|
309
|
+
retriesLeft > 0 &&
|
|
310
|
+
(session.options.adapter === "dart" || session.options.adapter === "kotlin") &&
|
|
311
|
+
session.breakpoints.size > 0
|
|
312
|
+
) {
|
|
313
|
+
// These adapters can start the debuggee before source breakpoints bind under load.
|
|
314
|
+
// Relaunching creates a fresh suspended VM and gives breakpoint binding another chance.
|
|
315
|
+
for (const activeClient of session.clients ?? [client]) activeClient.close();
|
|
316
|
+
session.adapterProcess?.kill();
|
|
317
|
+
await removeAdapterTemporaryDirectory(session);
|
|
318
|
+
session.client = undefined;
|
|
319
|
+
session.controlClient = undefined;
|
|
320
|
+
session.clients = undefined;
|
|
321
|
+
session.adapterProcess = undefined;
|
|
322
|
+
session.status = "configured";
|
|
323
|
+
for (const breakpoint of session.breakpoints.values()) breakpoint.verified = false;
|
|
324
|
+
this.#notify(session);
|
|
325
|
+
return await this.#start(session, signal, retriesLeft - 1);
|
|
326
|
+
}
|
|
327
|
+
return session;
|
|
328
|
+
} catch (error) {
|
|
329
|
+
for (const activeClient of session.clients ?? [client]) activeClient.close();
|
|
330
|
+
session.adapterProcess?.kill();
|
|
331
|
+
await removeAdapterTemporaryDirectory(session);
|
|
332
|
+
session.client = undefined;
|
|
333
|
+
session.controlClient = undefined;
|
|
334
|
+
session.clients = undefined;
|
|
335
|
+
session.adapterProcess = undefined;
|
|
336
|
+
session.targetReady = undefined;
|
|
337
|
+
session.resolveTargetReady = undefined;
|
|
338
|
+
session.status = "configured";
|
|
339
|
+
this.#notify(session);
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** Continue or step and wait for the next observable execution state. */
|
|
345
|
+
async command(
|
|
346
|
+
session: DebugSession,
|
|
347
|
+
command: "continue" | "next" | "stepIn" | "stepOut",
|
|
348
|
+
signal?: AbortSignal,
|
|
349
|
+
): Promise<DebugSession> {
|
|
350
|
+
if (session.status !== "stopped" || session.stop === undefined) {
|
|
351
|
+
throw new Error(`Cannot ${command} while session is ${session.status}`);
|
|
352
|
+
}
|
|
353
|
+
const client = requiredClient(session);
|
|
354
|
+
const threadId = session.stop.threadId;
|
|
355
|
+
await client.request(command, { threadId }, { signal });
|
|
356
|
+
session.stop = undefined;
|
|
357
|
+
session.status = "running";
|
|
358
|
+
this.#notify(session);
|
|
359
|
+
await this.#waitForStop(session, signal);
|
|
360
|
+
return session;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Terminate an owned debuggee and remove its session. */
|
|
364
|
+
async delete(source: string, signal?: AbortSignal): Promise<void> {
|
|
365
|
+
const session = this.get(source);
|
|
366
|
+
if (session === undefined) throw new Error(`Unknown debug session ${source}`);
|
|
367
|
+
const breakpointMatch = /\/breakpoint\/([a-f\d]{10})$/u.exec(source);
|
|
368
|
+
if (breakpointMatch !== null) {
|
|
369
|
+
const breakpoint = session.breakpoints.get(breakpointMatch[1] as string);
|
|
370
|
+
if (breakpoint === undefined) throw new Error(`Unknown debug breakpoint ${source}`);
|
|
371
|
+
session.breakpoints.delete(breakpoint.id);
|
|
372
|
+
if (session.client !== undefined && session.status !== "terminated") {
|
|
373
|
+
await this.#configureBreakpointFile(session, session.client, breakpoint.file, signal);
|
|
374
|
+
}
|
|
375
|
+
this.#notify(session);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (source !== session.source) throw new Error(`Cannot delete debug resource ${source}`);
|
|
379
|
+
if (session.client !== undefined) {
|
|
380
|
+
void (session.controlClient ?? session.client)
|
|
381
|
+
.request("disconnect", { terminateDebuggee: true }, { signal, timeoutMs: 500 })
|
|
382
|
+
.catch(() => {});
|
|
383
|
+
for (const client of session.clients ?? [session.client]) client.close();
|
|
384
|
+
session.adapterProcess?.kill();
|
|
385
|
+
}
|
|
386
|
+
await removeAdapterTemporaryDirectory(session);
|
|
387
|
+
session.status = "terminated";
|
|
388
|
+
this.#notify(session);
|
|
389
|
+
this.#sessions.delete(session.id);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Stop all owned adapter processes during Pi shutdown. */
|
|
393
|
+
dispose(): void {
|
|
394
|
+
for (const session of this.#sessions.values()) {
|
|
395
|
+
for (const client of session.clients ??
|
|
396
|
+
(session.client === undefined ? [] : [session.client])) {
|
|
397
|
+
client.close();
|
|
398
|
+
}
|
|
399
|
+
session.adapterProcess?.kill();
|
|
400
|
+
if (session.adapterTemporaryDirectory !== undefined) {
|
|
401
|
+
rmSync(session.adapterTemporaryDirectory, { recursive: true, force: true });
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
this.#sessions.clear();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async #startRubyAdapter(session: DebugSession): Promise<DapClient> {
|
|
408
|
+
const port = await availablePort();
|
|
409
|
+
const command = process.env.PI_RUBY_DEBUG_PATH ?? "rdbg";
|
|
410
|
+
session.adapterProcess = spawn(
|
|
411
|
+
command,
|
|
412
|
+
[
|
|
413
|
+
"--open",
|
|
414
|
+
"--host",
|
|
415
|
+
"127.0.0.1",
|
|
416
|
+
"--port",
|
|
417
|
+
String(port),
|
|
418
|
+
"--no-rc",
|
|
419
|
+
"--",
|
|
420
|
+
session.options.program,
|
|
421
|
+
...session.options.args,
|
|
422
|
+
],
|
|
423
|
+
{
|
|
424
|
+
cwd: session.options.cwd,
|
|
425
|
+
env: process.env,
|
|
426
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
427
|
+
},
|
|
428
|
+
);
|
|
429
|
+
await waitForAdapterReady(session.adapterProcess, "Debugger can attach via TCP/IP", "rdbg");
|
|
430
|
+
return DapClient.connect(port);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async #startDelveAdapter(session: DebugSession): Promise<DapClient> {
|
|
434
|
+
const port = await availablePort();
|
|
435
|
+
const command = process.env.PI_DELVE_PATH ?? "dlv";
|
|
436
|
+
session.adapterProcess = spawn(
|
|
437
|
+
command,
|
|
438
|
+
["dap", `--listen=127.0.0.1:${String(port)}`, "--log=false"],
|
|
439
|
+
{
|
|
440
|
+
cwd: session.options.cwd,
|
|
441
|
+
env: process.env,
|
|
442
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
443
|
+
},
|
|
444
|
+
);
|
|
445
|
+
session.adapterProcess.stderr?.on("data", () => {
|
|
446
|
+
// Delve status output is not DAP transport.
|
|
447
|
+
});
|
|
448
|
+
await waitForAdapterReady(session.adapterProcess, "DAP server listening", "Delve");
|
|
449
|
+
return DapClient.connect(port);
|
|
450
|
+
}
|
|
451
|
+
async #startJuliaAdapter(session: DebugSession): Promise<DapClient> {
|
|
452
|
+
const port = await availablePort();
|
|
453
|
+
const command = process.env.PI_JULIA_PATH ?? "julia";
|
|
454
|
+
const project = process.env.PI_JULIA_DEBUG_PROJECT ?? "/opt/pi-debug-adapters/julia";
|
|
455
|
+
const script =
|
|
456
|
+
'using Sockets, DebugAdapter; server = listen(ip"127.0.0.1", parse(Int, ARGS[1])); conn = accept(server); run(DebugAdapter.DebugSession(conn)); close(server)';
|
|
457
|
+
session.adapterProcess = spawn(
|
|
458
|
+
command,
|
|
459
|
+
[
|
|
460
|
+
"--startup-file=no",
|
|
461
|
+
"--history-file=no",
|
|
462
|
+
`--project=${project}`,
|
|
463
|
+
"-e",
|
|
464
|
+
script,
|
|
465
|
+
String(port),
|
|
466
|
+
],
|
|
467
|
+
{ cwd: session.options.cwd, env: process.env, stdio: ["ignore", "pipe", "pipe"] },
|
|
468
|
+
);
|
|
469
|
+
traceAdapterProcess(session.adapterProcess, `DebugAdapter.jl:${String(port)}`);
|
|
470
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
471
|
+
return connectWithRetry(port, "DebugAdapter.jl");
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
async #startRAdapter(session: DebugSession): Promise<DapClient> {
|
|
475
|
+
const listener = net.createServer();
|
|
476
|
+
await new Promise<void>((resolve, reject) => {
|
|
477
|
+
listener.once("error", reject);
|
|
478
|
+
listener.listen(0, "127.0.0.1", () => resolve());
|
|
479
|
+
});
|
|
480
|
+
const address = listener.address();
|
|
481
|
+
if (address === null || typeof address === "string") {
|
|
482
|
+
listener.close();
|
|
483
|
+
throw new Error("Could not start the vscDebugger DAP listener");
|
|
484
|
+
}
|
|
485
|
+
const clientPromise = new Promise<DapClient>((resolve, reject) => {
|
|
486
|
+
listener.once("connection", (socket) => {
|
|
487
|
+
listener.close();
|
|
488
|
+
const client = DapClient.fromSocket(socket, 2);
|
|
489
|
+
client.onEvent((event) => this.#handleRAdapterEvent(session, event));
|
|
490
|
+
resolve(client);
|
|
491
|
+
});
|
|
492
|
+
listener.once("error", reject);
|
|
493
|
+
});
|
|
494
|
+
const command = process.env.PI_R_PATH ?? "R";
|
|
495
|
+
session.rPromptInputs = [];
|
|
496
|
+
session.rAtBrowserPrompt = false;
|
|
497
|
+
session.rStarted = false;
|
|
498
|
+
session.adapterProcess = spawn(command, ["--vanilla", "--quiet"], {
|
|
499
|
+
cwd: session.options.cwd,
|
|
500
|
+
env: process.env,
|
|
501
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
502
|
+
});
|
|
503
|
+
traceAdapterProcess(session.adapterProcess, `vscDebugger:${String(address.port)}`);
|
|
504
|
+
this.#watchRPrompts(session);
|
|
505
|
+
const initialize = dapFrame({
|
|
506
|
+
seq: 1,
|
|
507
|
+
type: "request",
|
|
508
|
+
command: "initialize",
|
|
509
|
+
arguments: {
|
|
510
|
+
clientID: "pi-agent-ide",
|
|
511
|
+
adapterID: "R-Debugger",
|
|
512
|
+
pathFormat: "path",
|
|
513
|
+
linesStartAt1: true,
|
|
514
|
+
columnsStartAt1: true,
|
|
515
|
+
supportsVariableType: true,
|
|
516
|
+
supportsVariablePaging: true,
|
|
517
|
+
supportsWriteToStdinEvent: true,
|
|
518
|
+
supportsStdoutReading: true,
|
|
519
|
+
rStrings: {
|
|
520
|
+
packageName: "vscDebugger",
|
|
521
|
+
prompt: "__PI_R_PROMPT__",
|
|
522
|
+
continue: "__PI_R_CONTINUE__",
|
|
523
|
+
attachName: "tools:vscDebugger",
|
|
524
|
+
},
|
|
525
|
+
useDapSocket: true,
|
|
526
|
+
dapHost: "127.0.0.1",
|
|
527
|
+
dapPort: address.port,
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
session.adapterProcess.stdin?.write(
|
|
531
|
+
`library(vscDebugger); vscDebugger:::.vsc.handleDap(${JSON.stringify(initialize)})\n`,
|
|
532
|
+
);
|
|
533
|
+
return waitForRAdapterConnection(clientPromise, session.adapterProcess, listener);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
#handleRAdapterEvent(session: DebugSession, event: DapEvent): void {
|
|
537
|
+
if (process.env.PI_DEBUG_DAP_TRACE === "1") {
|
|
538
|
+
process.stderr.write(`[vscDebugger:event] ${JSON.stringify(event)}\n`);
|
|
539
|
+
}
|
|
540
|
+
if (event.event !== "custom") return;
|
|
541
|
+
const body = asRecord(event.body);
|
|
542
|
+
const reason = typeof body.reason === "string" ? body.reason : "";
|
|
543
|
+
const text = typeof body.text === "string" ? body.text : "";
|
|
544
|
+
if (reason !== "writeToStdin" || text.length === 0) return;
|
|
545
|
+
if (body.when === "browserPrompt" && session.rAtBrowserPrompt === true) {
|
|
546
|
+
session.rAtBrowserPrompt = false;
|
|
547
|
+
session.adapterProcess?.stdin?.write(`${text}\n`);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
session.rPromptInputs?.push(text);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
#watchRPrompts(session: DebugSession): void {
|
|
554
|
+
let output = "";
|
|
555
|
+
session.adapterProcess?.stdout?.on("data", (chunk: Buffer) => {
|
|
556
|
+
output += chunk.toString("utf8");
|
|
557
|
+
for (;;) {
|
|
558
|
+
const browser = /Browse\[\d+\]> /u.exec(output);
|
|
559
|
+
const topLevel = /(?:^|\r?\n)__PI_R_PROMPT__(?:\r?\n|$)/u.exec(output);
|
|
560
|
+
const browserIndex = browser?.index ?? Number.POSITIVE_INFINITY;
|
|
561
|
+
const topLevelIndex = topLevel?.index ?? Number.POSITIVE_INFINITY;
|
|
562
|
+
if (!Number.isFinite(browserIndex) && !Number.isFinite(topLevelIndex)) {
|
|
563
|
+
output = output.slice(-128);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
if (browserIndex < topLevelIndex) {
|
|
567
|
+
output = output.slice(browserIndex + (browser?.[0].length ?? 0));
|
|
568
|
+
const input = session.rPromptInputs?.shift();
|
|
569
|
+
if (input === undefined) {
|
|
570
|
+
session.rAtBrowserPrompt = true;
|
|
571
|
+
// Prompt output can arrive just before its flow-control event on the DAP socket.
|
|
572
|
+
setTimeout(() => {
|
|
573
|
+
if (session.rAtBrowserPrompt !== true) return;
|
|
574
|
+
session.rAtBrowserPrompt = false;
|
|
575
|
+
session.adapterProcess?.stdin?.write("vscDebugger::.vsc.listenForDAP(timeout=-1)\n");
|
|
576
|
+
}, 100);
|
|
577
|
+
} else {
|
|
578
|
+
session.adapterProcess?.stdin?.write(`${input}\n`);
|
|
579
|
+
}
|
|
580
|
+
} else {
|
|
581
|
+
output = output.slice(topLevelIndex + (topLevel?.[0].length ?? 0));
|
|
582
|
+
session.adapterProcess?.stdin?.write("vscDebugger::.vsc.listenForDAP(timeout=-1)\n");
|
|
583
|
+
if (session.rStarted === true) {
|
|
584
|
+
void session.client
|
|
585
|
+
?.request("custom", { reason: "showingPrompt", which: "topLevel" })
|
|
586
|
+
.catch(() => {});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
async #startNodeAdapter(session: DebugSession): Promise<DapClient> {
|
|
594
|
+
const port = await availablePort();
|
|
595
|
+
const server =
|
|
596
|
+
process.env.PI_JS_DEBUG_PATH ?? "/opt/pi-debug-adapters/js-debug/src/dapDebugServer.js";
|
|
597
|
+
session.adapterProcess = spawn(process.execPath, [server, String(port), "127.0.0.1"], {
|
|
598
|
+
cwd: session.options.cwd,
|
|
599
|
+
env: process.env,
|
|
600
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
601
|
+
});
|
|
602
|
+
session.adapterProcess.stderr?.on("data", () => {
|
|
603
|
+
// Server stderr is diagnostic output, not DAP transport.
|
|
604
|
+
});
|
|
605
|
+
await waitForJsDebugReady(session.adapterProcess);
|
|
606
|
+
const client = await connectWithRetry(port);
|
|
607
|
+
client.onReverseRequest(this.#handleNodeReverseRequest(session, port));
|
|
608
|
+
return client;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
#handleNodeReverseRequest(
|
|
612
|
+
session: DebugSession,
|
|
613
|
+
port: number,
|
|
614
|
+
): (request: DapReverseRequest) => Promise<unknown> {
|
|
615
|
+
return async (request) => {
|
|
616
|
+
if (request.command !== "startDebugging") {
|
|
617
|
+
throw new Error(`Client does not support reverse request ${request.command}`);
|
|
618
|
+
}
|
|
619
|
+
const arguments_ = asRecord(request.arguments);
|
|
620
|
+
const configuration = asRecord(arguments_.configuration);
|
|
621
|
+
const child = await DapClient.connect(port);
|
|
622
|
+
session.clients?.push(child);
|
|
623
|
+
child.onReverseRequest(this.#handleNodeReverseRequest(session, port));
|
|
624
|
+
await initializeClient(child, "pwa-node");
|
|
625
|
+
const initialized = child.waitForEvent("initialized");
|
|
626
|
+
const launch = child.request(
|
|
627
|
+
typeof arguments_.request === "string" ? arguments_.request : "launch",
|
|
628
|
+
{
|
|
629
|
+
...configuration,
|
|
630
|
+
sourceMaps: true,
|
|
631
|
+
pauseForSourceMap: true,
|
|
632
|
+
outFiles: [path.join(path.dirname(session.options.program), "**", "*.js")],
|
|
633
|
+
},
|
|
634
|
+
);
|
|
635
|
+
await initialized;
|
|
636
|
+
session.client = child;
|
|
637
|
+
await this.#configureBreakpoints(session, child);
|
|
638
|
+
await child.request("configurationDone");
|
|
639
|
+
await launch;
|
|
640
|
+
session.resolveTargetReady?.();
|
|
641
|
+
return {};
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
async #configureBreakpoints(
|
|
646
|
+
session: DebugSession,
|
|
647
|
+
client: DapClient,
|
|
648
|
+
signal?: AbortSignal,
|
|
649
|
+
): Promise<void> {
|
|
650
|
+
const files = new Set([...session.breakpoints.values()].map((breakpoint) => breakpoint.file));
|
|
651
|
+
for (const file of files) await this.#configureBreakpointFile(session, client, file, signal);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
async #configureBreakpointFile(
|
|
655
|
+
session: DebugSession,
|
|
656
|
+
client: DapClient,
|
|
657
|
+
file: string,
|
|
658
|
+
signal?: AbortSignal,
|
|
659
|
+
): Promise<void> {
|
|
660
|
+
const breakpoints = [...session.breakpoints.values()].filter(
|
|
661
|
+
(breakpoint) => breakpoint.file === file,
|
|
662
|
+
);
|
|
663
|
+
const response = await client.request<SetBreakpointsBody>(
|
|
664
|
+
"setBreakpoints",
|
|
665
|
+
{
|
|
666
|
+
source: { path: file, name: path.basename(file) },
|
|
667
|
+
breakpoints: breakpoints.map(({ line }) => ({ line })),
|
|
668
|
+
sourceModified: false,
|
|
669
|
+
},
|
|
670
|
+
{ signal },
|
|
671
|
+
);
|
|
672
|
+
for (const [index, breakpoint] of breakpoints.entries()) {
|
|
673
|
+
breakpoint.verified = response.breakpoints?.[index]?.verified === true;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
async #waitForStop(session: DebugSession, signal?: AbortSignal): Promise<void> {
|
|
678
|
+
const event = await requiredClient(session).waitForAnyEvent(
|
|
679
|
+
["stopped", "terminated", "exited", "loadedSource", "breakpoint", "custom"],
|
|
680
|
+
30_000,
|
|
681
|
+
signal,
|
|
682
|
+
);
|
|
683
|
+
const body = asRecord(event.body);
|
|
684
|
+
if (event.event === "custom" && session.options.adapter === "r") {
|
|
685
|
+
await this.#waitForStop(session, signal);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
if (event.event === "loadedSource") {
|
|
689
|
+
const source = asRecord(body.source);
|
|
690
|
+
const loadedPath = typeof source.path === "string" ? path.resolve(source.path) : undefined;
|
|
691
|
+
const breakpointFile =
|
|
692
|
+
loadedPath === undefined
|
|
693
|
+
? undefined
|
|
694
|
+
: [...session.breakpoints.values()].find(
|
|
695
|
+
(breakpoint) => path.resolve(breakpoint.file) === loadedPath,
|
|
696
|
+
)?.file;
|
|
697
|
+
if (breakpointFile !== undefined)
|
|
698
|
+
await this.#configureBreakpointFile(
|
|
699
|
+
session,
|
|
700
|
+
requiredClient(session),
|
|
701
|
+
breakpointFile,
|
|
702
|
+
signal,
|
|
703
|
+
);
|
|
704
|
+
await this.#waitForStop(session, signal);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
if (event.event === "breakpoint") {
|
|
708
|
+
const changed = asRecord(body.breakpoint);
|
|
709
|
+
const changedSource = asRecord(changed.source);
|
|
710
|
+
for (const breakpoint of session.breakpoints.values()) {
|
|
711
|
+
if (
|
|
712
|
+
changed.verified === true &&
|
|
713
|
+
typeof changed.line === "number" &&
|
|
714
|
+
changed.line === breakpoint.line &&
|
|
715
|
+
typeof changedSource.path === "string" &&
|
|
716
|
+
path.resolve(changedSource.path) === path.resolve(breakpoint.file)
|
|
717
|
+
) {
|
|
718
|
+
breakpoint.verified = true;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
await this.#waitForStop(session, signal);
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
if (body.reason === "exit") {
|
|
725
|
+
session.status = "terminated";
|
|
726
|
+
session.stop = undefined;
|
|
727
|
+
this.#notify(session);
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
if (session.options.adapter === "node" && body.reason === "entry") {
|
|
731
|
+
await this.#configureBreakpoints(session, requiredClient(session), signal);
|
|
732
|
+
const threadId = typeof body.threadId === "number" ? body.threadId : 1;
|
|
733
|
+
await requiredClient(session).request("continue", { threadId }, { signal });
|
|
734
|
+
await this.#waitForStop(session, signal);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
if (
|
|
738
|
+
(session.options.adapter === "dart" || session.options.adapter === "kotlin") &&
|
|
739
|
+
body.reason === "entry"
|
|
740
|
+
) {
|
|
741
|
+
const client = requiredClient(session);
|
|
742
|
+
await this.#configureBreakpoints(session, client, signal);
|
|
743
|
+
if (session.options.adapter === "kotlin") {
|
|
744
|
+
// The Kotlin adapter can acknowledge an unbound source breakpoint while the VM is
|
|
745
|
+
// stopped on entry. Keep the VM suspended until the class has loaded and the adapter
|
|
746
|
+
// confirms the breakpoint; continuing earlier races the entire short-lived program.
|
|
747
|
+
const deadline = Date.now() + 5_000;
|
|
748
|
+
while (
|
|
749
|
+
[...session.breakpoints.values()].some((breakpoint) => !breakpoint.verified) &&
|
|
750
|
+
Date.now() < deadline
|
|
751
|
+
) {
|
|
752
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
753
|
+
await this.#configureBreakpoints(session, client, signal);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const threadId = typeof body.threadId === "number" ? body.threadId : 1;
|
|
757
|
+
await client.request("continue", { threadId }, { signal });
|
|
758
|
+
await this.#waitForStop(session, signal);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (event.event !== "stopped") {
|
|
762
|
+
session.status = "terminated";
|
|
763
|
+
session.stop = undefined;
|
|
764
|
+
this.#notify(session);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
await this.#captureStop(session, event, session.options.adapter !== "shell");
|
|
768
|
+
if (session.options.adapter === "r" && session.stop?.frame?.source?.path === undefined) {
|
|
769
|
+
session.stopGeneration--;
|
|
770
|
+
session.stop = undefined;
|
|
771
|
+
session.status = "running";
|
|
772
|
+
await this.#waitForStop(session, signal);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (
|
|
776
|
+
session.options.adapter === "shell" &&
|
|
777
|
+
session.stop?.frame !== undefined &&
|
|
778
|
+
![...session.breakpoints.values()].some(
|
|
779
|
+
(breakpoint) =>
|
|
780
|
+
path.resolve(breakpoint.file) === path.resolve(session.stop?.frame?.source?.path ?? "") &&
|
|
781
|
+
breakpoint.line === session.stop?.frame?.line,
|
|
782
|
+
)
|
|
783
|
+
) {
|
|
784
|
+
const threadId = session.stop.threadId;
|
|
785
|
+
session.stopGeneration--;
|
|
786
|
+
session.stop = undefined;
|
|
787
|
+
session.status = "running";
|
|
788
|
+
await requiredClient(session).request("continue", { threadId }, { signal });
|
|
789
|
+
await this.#waitForStop(session, signal);
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
if (session.options.adapter === "shell") this.#notify(session);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
async #captureStop(session: DebugSession, event: DapEvent, notify = true): Promise<void> {
|
|
796
|
+
const client = requiredClient(session);
|
|
797
|
+
const body = asRecord(event.body);
|
|
798
|
+
const fallbackThread = (await client.request<ThreadsBody>("threads")).threads?.[0]?.id;
|
|
799
|
+
const threadId = typeof body.threadId === "number" ? body.threadId : fallbackThread;
|
|
800
|
+
if (threadId === undefined) throw new Error("Debugger stopped without a thread");
|
|
801
|
+
const frame = (await requestStackTrace(client, threadId, session.options.adapter === "dart"))
|
|
802
|
+
.stackFrames?.[0];
|
|
803
|
+
if (frame?.source?.path !== undefined) {
|
|
804
|
+
for (const breakpoint of session.breakpoints.values()) {
|
|
805
|
+
if (
|
|
806
|
+
path.resolve(breakpoint.file) === path.resolve(frame.source.path) &&
|
|
807
|
+
breakpoint.line === frame.line
|
|
808
|
+
) {
|
|
809
|
+
breakpoint.verified = true;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
const variables: DebugVariable[] = [];
|
|
814
|
+
if (frame !== undefined) {
|
|
815
|
+
const scopes =
|
|
816
|
+
(await client.request<ScopesBody>("scopes", { frameId: frame.id })).scopes ?? [];
|
|
817
|
+
const localScopes =
|
|
818
|
+
session.options.adapter === "r"
|
|
819
|
+
? scopes
|
|
820
|
+
: scopes.filter((item) =>
|
|
821
|
+
[item.name.toLowerCase(), item.presentationHint?.toLowerCase()].some(
|
|
822
|
+
(value) => value?.includes("local") === true || value === "variables",
|
|
823
|
+
),
|
|
824
|
+
);
|
|
825
|
+
for (const scope of localScopes) {
|
|
826
|
+
const values = await client.request<VariablesBody>("variables", {
|
|
827
|
+
variablesReference: scope.variablesReference,
|
|
828
|
+
start: 0,
|
|
829
|
+
count: 100,
|
|
830
|
+
});
|
|
831
|
+
variables.push(...(values.variables ?? []));
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
session.stopGeneration++;
|
|
835
|
+
session.stop = {
|
|
836
|
+
generation: session.stopGeneration,
|
|
837
|
+
reason: typeof body.reason === "string" ? body.reason : "stopped",
|
|
838
|
+
threadId,
|
|
839
|
+
...(frame === undefined ? {} : { frame }),
|
|
840
|
+
variables,
|
|
841
|
+
sourceLines: frame === undefined ? [] : await sourceWindow(frame),
|
|
842
|
+
};
|
|
843
|
+
session.status = "stopped";
|
|
844
|
+
if (notify) this.#notify(session);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
#notify(session: DebugSession): void {
|
|
848
|
+
const snapshot = this.snapshot(session);
|
|
849
|
+
for (const listener of this.#changeListeners) listener(snapshot);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
async function sourceWindow(frame: DebugFrame): Promise<readonly DebugSourceLine[]> {
|
|
854
|
+
const file = frame.source?.path;
|
|
855
|
+
if (file === undefined) return [];
|
|
856
|
+
try {
|
|
857
|
+
const lines = (await readFile(file, "utf8")).split(/\r?\n/u);
|
|
858
|
+
const start = Math.max(1, frame.line - 2);
|
|
859
|
+
const end = Math.min(lines.length, frame.line + 2);
|
|
860
|
+
return lines.slice(start - 1, end).map((content, index) => ({
|
|
861
|
+
lineNumber: start + index,
|
|
862
|
+
content,
|
|
863
|
+
current: start + index === frame.line,
|
|
864
|
+
}));
|
|
865
|
+
} catch {
|
|
866
|
+
return [];
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
async function requestStackTrace(
|
|
871
|
+
client: DapClient,
|
|
872
|
+
threadId: number,
|
|
873
|
+
retryCollected: boolean,
|
|
874
|
+
): Promise<StackTraceBody> {
|
|
875
|
+
const deadline = Date.now() + 1_000;
|
|
876
|
+
let lastError: unknown;
|
|
877
|
+
do {
|
|
878
|
+
try {
|
|
879
|
+
const response = await client.request<StackTraceBody>("stackTrace", { threadId });
|
|
880
|
+
if (!retryCollected || (response.stackFrames?.length ?? 0) > 0) return response;
|
|
881
|
+
lastError = new Error("Debugger stack is not ready");
|
|
882
|
+
} catch (error) {
|
|
883
|
+
lastError = error;
|
|
884
|
+
if (!retryCollected) throw error;
|
|
885
|
+
}
|
|
886
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
887
|
+
} while (Date.now() < deadline);
|
|
888
|
+
throw lastError instanceof Error ? lastError : new Error("Could not read debugger stack");
|
|
889
|
+
}
|
|
890
|
+
/** Render the compact state returned by read and semantic commands. */
|
|
891
|
+
export function renderDebugSession(session: DebugSession): string {
|
|
892
|
+
const lines = [
|
|
893
|
+
`Session: ${session.source}`,
|
|
894
|
+
`Adapter: ${session.options.adapter}`,
|
|
895
|
+
`Program: ${path.relative(session.options.cwd, session.options.program) || session.options.program}`,
|
|
896
|
+
`Status: ${session.status}`,
|
|
897
|
+
];
|
|
898
|
+
if (session.breakpoints.size > 0) {
|
|
899
|
+
lines.push("", "Breakpoints:");
|
|
900
|
+
for (const breakpoint of session.breakpoints.values()) {
|
|
901
|
+
lines.push(
|
|
902
|
+
`- ${breakpoint.source} ${path.relative(session.options.cwd, breakpoint.file)}:${breakpoint.line} (${breakpoint.verified ? "verified" : "pending"})`,
|
|
903
|
+
);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (session.stop !== undefined) {
|
|
907
|
+
const { stop } = session;
|
|
908
|
+
lines.push("", `Stop: ${stop.generation} (${stop.reason})`, `Thread: ${stop.threadId}`);
|
|
909
|
+
if (stop.frame !== undefined) {
|
|
910
|
+
lines.push(
|
|
911
|
+
`Frame: ${stop.frame.name} at ${stop.frame.source?.path ?? stop.frame.source?.name ?? "unknown"}:${stop.frame.line}`,
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
if (stop.variables.length > 0) {
|
|
915
|
+
lines.push("", "Locals:");
|
|
916
|
+
for (const variable of stop.variables) {
|
|
917
|
+
lines.push(
|
|
918
|
+
`- ${variable.name}: ${variable.value}${variable.type === undefined ? "" : ` (${variable.type})`}`,
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return lines.join("\n");
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
function requiredClient(session: DebugSession): DapClient {
|
|
927
|
+
if (session.client === undefined) throw new Error("Debug adapter is not running");
|
|
928
|
+
return session.client;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
function asRecord(value: unknown): Readonly<Record<string, unknown>> {
|
|
932
|
+
return typeof value === "object" && value !== null
|
|
933
|
+
? (value as Readonly<Record<string, unknown>>)
|
|
934
|
+
: {};
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
function dapFrame(message: unknown): string {
|
|
938
|
+
const payload = JSON.stringify(message);
|
|
939
|
+
return `Content-Length: ${Buffer.byteLength(payload, "utf8")}\r\n\r\n${payload}`;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
function initializeClient(
|
|
943
|
+
client: DapClient,
|
|
944
|
+
adapterID: string,
|
|
945
|
+
signal?: AbortSignal,
|
|
946
|
+
): Promise<unknown> {
|
|
947
|
+
return client.request(
|
|
948
|
+
"initialize",
|
|
949
|
+
{
|
|
950
|
+
clientID: "pi-agent-ide",
|
|
951
|
+
adapterID,
|
|
952
|
+
pathFormat: "path",
|
|
953
|
+
linesStartAt1: true,
|
|
954
|
+
columnsStartAt1: true,
|
|
955
|
+
supportsVariableType: true,
|
|
956
|
+
supportsVariablePaging: true,
|
|
957
|
+
supportsRunInTerminalRequest: false,
|
|
958
|
+
supportsStartDebuggingRequest: true,
|
|
959
|
+
},
|
|
960
|
+
{ signal },
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
function availablePort(): Promise<number> {
|
|
965
|
+
return new Promise((resolve, reject) => {
|
|
966
|
+
const server = net.createServer();
|
|
967
|
+
server.once("error", reject);
|
|
968
|
+
server.listen(0, "127.0.0.1", () => {
|
|
969
|
+
const address = server.address();
|
|
970
|
+
if (address === null || typeof address === "string") {
|
|
971
|
+
server.close();
|
|
972
|
+
reject(new Error("Could not allocate a debug adapter port"));
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
server.close((error) => (error === undefined ? resolve(address.port) : reject(error)));
|
|
976
|
+
});
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
function traceAdapterProcess(child: ChildProcess, adapter: string): void {
|
|
981
|
+
if (process.env.PI_DEBUG_DAP_TRACE !== "1") return;
|
|
982
|
+
process.stderr.write(`[${adapter}] pid=${String(child.pid)}\n`);
|
|
983
|
+
child.once("exit", (code, signal) =>
|
|
984
|
+
process.stderr.write(`[${adapter}] exit code=${String(code)} signal=${String(signal)}\n`),
|
|
985
|
+
);
|
|
986
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
987
|
+
stream?.on("data", (chunk: Buffer) =>
|
|
988
|
+
process.stderr.write(`[${adapter}] ${chunk.toString("utf8")}`),
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function waitForRAdapterConnection(
|
|
994
|
+
connection: Promise<DapClient>,
|
|
995
|
+
child: ChildProcess,
|
|
996
|
+
listener: net.Server,
|
|
997
|
+
): Promise<DapClient> {
|
|
998
|
+
return new Promise((resolve, reject) => {
|
|
999
|
+
const timer = setTimeout(() => fail(new Error("Timed out starting vscDebugger")), 5_000);
|
|
1000
|
+
const cleanup = (): void => {
|
|
1001
|
+
clearTimeout(timer);
|
|
1002
|
+
child.off("error", fail);
|
|
1003
|
+
child.off("exit", onExit);
|
|
1004
|
+
};
|
|
1005
|
+
const fail = (error: Error): void => {
|
|
1006
|
+
cleanup();
|
|
1007
|
+
listener.close();
|
|
1008
|
+
if (!child.killed) child.kill();
|
|
1009
|
+
reject(error);
|
|
1010
|
+
};
|
|
1011
|
+
const onExit = (code: number | null): void =>
|
|
1012
|
+
fail(new Error(`vscDebugger exited with code ${String(code)} before connecting`));
|
|
1013
|
+
child.once("error", fail);
|
|
1014
|
+
child.once("exit", onExit);
|
|
1015
|
+
void connection.then((client) => {
|
|
1016
|
+
cleanup();
|
|
1017
|
+
resolve(client);
|
|
1018
|
+
}, fail);
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
function waitForAdapterReady(child: ChildProcess, marker: string, adapter: string): Promise<void> {
|
|
1023
|
+
return new Promise((resolve, reject) => {
|
|
1024
|
+
const streams = [child.stdout, child.stderr].filter((stream) => stream !== null);
|
|
1025
|
+
const timer = setTimeout(
|
|
1026
|
+
() => reject(new Error(`Timed out starting ${adapter} server`)),
|
|
1027
|
+
5_000,
|
|
1028
|
+
);
|
|
1029
|
+
const cleanup = (): void => {
|
|
1030
|
+
clearTimeout(timer);
|
|
1031
|
+
for (const stream of streams) stream.off("data", onData);
|
|
1032
|
+
};
|
|
1033
|
+
const onData = (chunk: Buffer): void => {
|
|
1034
|
+
if (!chunk.toString("utf8").includes(marker)) return;
|
|
1035
|
+
cleanup();
|
|
1036
|
+
resolve();
|
|
1037
|
+
};
|
|
1038
|
+
for (const stream of streams) stream.on("data", onData);
|
|
1039
|
+
child.once("error", (error) => {
|
|
1040
|
+
cleanup();
|
|
1041
|
+
reject(error);
|
|
1042
|
+
});
|
|
1043
|
+
child.once("exit", (code) => {
|
|
1044
|
+
cleanup();
|
|
1045
|
+
reject(new Error(`${adapter} server exited with code ${String(code)}`));
|
|
1046
|
+
});
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
function waitForJsDebugReady(child: ChildProcess): Promise<void> {
|
|
1050
|
+
return new Promise((resolve, reject) => {
|
|
1051
|
+
const stdout = child.stdout;
|
|
1052
|
+
if (stdout === null) {
|
|
1053
|
+
reject(new Error("js-debug server stdout is unavailable"));
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
1056
|
+
const timer = setTimeout(() => reject(new Error("Timed out starting js-debug server")), 5_000);
|
|
1057
|
+
const onData = (chunk: Buffer): void => {
|
|
1058
|
+
if (!chunk.toString("utf8").includes("Debug server listening")) return;
|
|
1059
|
+
clearTimeout(timer);
|
|
1060
|
+
stdout.off("data", onData);
|
|
1061
|
+
resolve();
|
|
1062
|
+
};
|
|
1063
|
+
stdout.on("data", onData);
|
|
1064
|
+
child.once("error", reject);
|
|
1065
|
+
child.once("exit", (code) => reject(new Error(`js-debug server exited with code ${code}`)));
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
async function connectWithRetry(port: number, adapter = "js-debug"): Promise<DapClient> {
|
|
1069
|
+
let lastError: unknown;
|
|
1070
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
1071
|
+
try {
|
|
1072
|
+
return await DapClient.connect(port);
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
lastError = error;
|
|
1075
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
throw lastError instanceof Error ? lastError : new Error(`Could not connect to ${adapter}`);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
async function removeAdapterTemporaryDirectory(session: DebugSession): Promise<void> {
|
|
1082
|
+
if (session.adapterTemporaryDirectory === undefined) return;
|
|
1083
|
+
await rm(session.adapterTemporaryDirectory, { recursive: true, force: true });
|
|
1084
|
+
session.adapterTemporaryDirectory = undefined;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
interface AdapterRecipe {
|
|
1088
|
+
readonly command: string;
|
|
1089
|
+
readonly args: readonly string[];
|
|
1090
|
+
readonly adapterID: string;
|
|
1091
|
+
readonly request: "attach" | "launch";
|
|
1092
|
+
readonly launch: Readonly<Record<string, unknown>>;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
function adapterRecipe(
|
|
1096
|
+
options: DebugSessionOptions,
|
|
1097
|
+
adapterTemporaryDirectory?: string,
|
|
1098
|
+
): AdapterRecipe {
|
|
1099
|
+
const common = {
|
|
1100
|
+
name: "Pi Agent IDE debug session",
|
|
1101
|
+
request: "launch",
|
|
1102
|
+
program: options.program,
|
|
1103
|
+
cwd: options.cwd,
|
|
1104
|
+
args: [...options.args],
|
|
1105
|
+
};
|
|
1106
|
+
if (options.adapter === "dart") {
|
|
1107
|
+
return {
|
|
1108
|
+
command: process.env.PI_DART_PATH ?? "dart",
|
|
1109
|
+
args: ["debug_adapter"],
|
|
1110
|
+
adapterID: "dart",
|
|
1111
|
+
request: "launch",
|
|
1112
|
+
launch: {
|
|
1113
|
+
...common,
|
|
1114
|
+
type: "dart",
|
|
1115
|
+
debugSdkLibraries: false,
|
|
1116
|
+
debugExternalPackageLibraries: false,
|
|
1117
|
+
stopOnEntry: true,
|
|
1118
|
+
vmAdditionalArgs: ["--pause-isolates-on-start"],
|
|
1119
|
+
},
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
if (options.adapter === "debugpy") {
|
|
1123
|
+
return {
|
|
1124
|
+
command: "python3",
|
|
1125
|
+
args: ["-m", "debugpy.adapter"],
|
|
1126
|
+
adapterID: "debugpy",
|
|
1127
|
+
request: "launch",
|
|
1128
|
+
launch: { ...common, type: "python", console: "internalConsole", justMyCode: false },
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
if (options.adapter === "java" || options.adapter === "kotlin") {
|
|
1132
|
+
if (options.mainClass === undefined) {
|
|
1133
|
+
throw new Error("Java and Kotlin debug sessions require mainClass");
|
|
1134
|
+
}
|
|
1135
|
+
return {
|
|
1136
|
+
command: process.env.PI_KOTLIN_DEBUG_ADAPTER_PATH ?? "kotlin-debug-adapter",
|
|
1137
|
+
args: [],
|
|
1138
|
+
adapterID: options.adapter,
|
|
1139
|
+
request: "launch",
|
|
1140
|
+
launch: {
|
|
1141
|
+
...common,
|
|
1142
|
+
type: "kotlin",
|
|
1143
|
+
mainClass: options.mainClass,
|
|
1144
|
+
projectRoot: options.cwd,
|
|
1145
|
+
stopOnEntry: true,
|
|
1146
|
+
},
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
if (options.adapter === "netcoredbg") {
|
|
1150
|
+
return {
|
|
1151
|
+
command: process.env.PI_NETCOREDBG_PATH ?? "netcoredbg",
|
|
1152
|
+
args: ["--interpreter=vscode"],
|
|
1153
|
+
adapterID: "coreclr",
|
|
1154
|
+
request: "launch",
|
|
1155
|
+
launch: { ...common, type: "coreclr", console: "internalConsole" },
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
if (options.adapter === "elixir") {
|
|
1159
|
+
return {
|
|
1160
|
+
command:
|
|
1161
|
+
process.env.PI_ELIXIR_LS_DEBUG_PATH ?? "/opt/pi-debug-adapters/elixir-ls/debug_adapter.sh",
|
|
1162
|
+
args: [],
|
|
1163
|
+
adapterID: "mix_task",
|
|
1164
|
+
request: "launch",
|
|
1165
|
+
launch: {
|
|
1166
|
+
name: common.name,
|
|
1167
|
+
request: "launch",
|
|
1168
|
+
type: "mix_task",
|
|
1169
|
+
task: "run",
|
|
1170
|
+
taskArgs: [options.program, ...options.args],
|
|
1171
|
+
projectDir: options.cwd,
|
|
1172
|
+
startApps: true,
|
|
1173
|
+
exitAfterTaskReturns: true,
|
|
1174
|
+
},
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
if (options.adapter === "julia") {
|
|
1178
|
+
return {
|
|
1179
|
+
command: process.env.PI_JULIA_PATH ?? "julia",
|
|
1180
|
+
args: [],
|
|
1181
|
+
adapterID: "julia",
|
|
1182
|
+
request: "launch",
|
|
1183
|
+
launch: { ...common, type: "julia", stopOnEntry: false },
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
if (options.adapter === "lldb-dap") {
|
|
1187
|
+
return {
|
|
1188
|
+
command: process.env.PI_LLDB_DAP_PATH ?? "lldb-dap-18",
|
|
1189
|
+
args: [],
|
|
1190
|
+
adapterID: "lldb-dap",
|
|
1191
|
+
request: "launch",
|
|
1192
|
+
launch: { ...common, type: "lldb-dap" },
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
if (options.adapter === "delve") {
|
|
1196
|
+
return {
|
|
1197
|
+
command: process.env.PI_DELVE_PATH ?? "dlv",
|
|
1198
|
+
args: [],
|
|
1199
|
+
adapterID: "go",
|
|
1200
|
+
request: "launch",
|
|
1201
|
+
launch: { ...common, type: "go", mode: "debug" },
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
if (options.adapter === "r") {
|
|
1205
|
+
return {
|
|
1206
|
+
command: process.env.PI_R_PATH ?? "R",
|
|
1207
|
+
args: [],
|
|
1208
|
+
adapterID: "R-Debugger",
|
|
1209
|
+
request: "launch",
|
|
1210
|
+
launch: {
|
|
1211
|
+
name: common.name,
|
|
1212
|
+
request: "launch",
|
|
1213
|
+
type: "R-Debugger",
|
|
1214
|
+
debugMode: "file",
|
|
1215
|
+
file: options.program,
|
|
1216
|
+
workingDirectory: options.cwd,
|
|
1217
|
+
commandLineArgs: [...options.args],
|
|
1218
|
+
allowGlobalDebugging: false,
|
|
1219
|
+
loadPackages: [],
|
|
1220
|
+
supportsStdoutReading: true,
|
|
1221
|
+
supportsWriteToStdinEvent: true,
|
|
1222
|
+
overwriteHelp: false,
|
|
1223
|
+
},
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
if (options.adapter === "ruby") {
|
|
1227
|
+
return {
|
|
1228
|
+
command: process.env.PI_RUBY_DEBUG_PATH ?? "rdbg",
|
|
1229
|
+
args: [],
|
|
1230
|
+
adapterID: "rdbg",
|
|
1231
|
+
request: "launch",
|
|
1232
|
+
launch: { ...common, type: "rdbg" },
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
if (options.adapter === "php") {
|
|
1236
|
+
return {
|
|
1237
|
+
command: process.execPath,
|
|
1238
|
+
args: [
|
|
1239
|
+
process.env.PI_PHP_DEBUG_PATH ??
|
|
1240
|
+
"/opt/pi-debug-adapters/php-debug/extension/out/phpDebug.js",
|
|
1241
|
+
],
|
|
1242
|
+
adapterID: "php",
|
|
1243
|
+
request: "launch",
|
|
1244
|
+
launch: {
|
|
1245
|
+
...common,
|
|
1246
|
+
type: "php",
|
|
1247
|
+
runtimeExecutable: process.env.PI_PHP_PATH ?? "php",
|
|
1248
|
+
runtimeArgs: ["-dxdebug.start_with_request=yes"],
|
|
1249
|
+
console: "internalConsole",
|
|
1250
|
+
port: 0,
|
|
1251
|
+
env: { XDEBUG_MODE: "debug,develop", XDEBUG_CONFIG: "client_port=${port}" },
|
|
1252
|
+
},
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
if (options.adapter === "lua") {
|
|
1256
|
+
return {
|
|
1257
|
+
command: process.execPath,
|
|
1258
|
+
args: [
|
|
1259
|
+
process.env.PI_LUA_DEBUG_PATH ??
|
|
1260
|
+
"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js",
|
|
1261
|
+
],
|
|
1262
|
+
adapterID: "lua-local",
|
|
1263
|
+
request: "launch",
|
|
1264
|
+
launch: {
|
|
1265
|
+
...common,
|
|
1266
|
+
type: "lua-local",
|
|
1267
|
+
program: { lua: process.env.PI_LUA_PATH ?? "lua", file: options.program },
|
|
1268
|
+
extensionPath: path.dirname(
|
|
1269
|
+
path.dirname(
|
|
1270
|
+
process.env.PI_LUA_DEBUG_PATH ??
|
|
1271
|
+
"/opt/pi-debug-adapters/lua-debug/extension/extension/debugAdapter.js",
|
|
1272
|
+
),
|
|
1273
|
+
),
|
|
1274
|
+
workspacePath: options.cwd,
|
|
1275
|
+
},
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
if (options.adapter === "shell") {
|
|
1279
|
+
const extension =
|
|
1280
|
+
process.env.PI_BASH_DEBUG_ROOT ?? "/opt/pi-debug-adapters/bash-debug/extension";
|
|
1281
|
+
return {
|
|
1282
|
+
command: process.execPath,
|
|
1283
|
+
args: [process.env.PI_BASH_DEBUG_PATH ?? path.join(extension, "out/bashDebug.js")],
|
|
1284
|
+
adapterID: "bashdb",
|
|
1285
|
+
request: "launch",
|
|
1286
|
+
launch: {
|
|
1287
|
+
...common,
|
|
1288
|
+
type: "bashdb",
|
|
1289
|
+
pathBash: process.env.PI_BASH_PATH ?? "/usr/bin/bash",
|
|
1290
|
+
pathBashdb: path.join(extension, "bashdb_dir/bashdb"),
|
|
1291
|
+
pathBashdbLib: path.join(extension, "bashdb_dir"),
|
|
1292
|
+
pathCat: "/usr/bin/cat",
|
|
1293
|
+
pathMkfifo: "/usr/bin/mkfifo",
|
|
1294
|
+
pathPkill: "/usr/bin/pkill",
|
|
1295
|
+
terminalKind: "debugConsole",
|
|
1296
|
+
argsString: "",
|
|
1297
|
+
env: {},
|
|
1298
|
+
showDebugOutput: false,
|
|
1299
|
+
trace: false,
|
|
1300
|
+
},
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
if (options.adapter === "powershell") {
|
|
1304
|
+
const bundle =
|
|
1305
|
+
process.env.PI_POWERSHELL_EDITOR_SERVICES_PATH ??
|
|
1306
|
+
"/opt/pi-debug-adapters/powershell-editor-services";
|
|
1307
|
+
if (adapterTemporaryDirectory === undefined) {
|
|
1308
|
+
throw new Error("PowerShell debugger temporary directory was not created");
|
|
1309
|
+
}
|
|
1310
|
+
return {
|
|
1311
|
+
command: process.env.PI_PWSH_PATH ?? "pwsh",
|
|
1312
|
+
args: [
|
|
1313
|
+
"-NoLogo",
|
|
1314
|
+
"-NoProfile",
|
|
1315
|
+
"-Command",
|
|
1316
|
+
`& '${path.join(bundle, "PowerShellEditorServices/Start-EditorServices.ps1").replaceAll("'", "''")}' -LogPath '${path.join(adapterTemporaryDirectory, "logs").replaceAll("'", "''")}' -LogLevel Warning -SessionDetailsPath '${path.join(adapterTemporaryDirectory, "session.json").replaceAll("'", "''")}' -FeatureFlags @() -AdditionalModules @() -HostName 'Pi Agent IDE' -HostProfileId 'pi-agent-ide' -HostVersion '1.0.0' -BundledModulesPath '${bundle.replaceAll("'", "''")}' -Stdio -DebugServiceOnly`,
|
|
1317
|
+
],
|
|
1318
|
+
adapterID: "PowerShell",
|
|
1319
|
+
request: "launch",
|
|
1320
|
+
launch: {
|
|
1321
|
+
...common,
|
|
1322
|
+
script: options.program,
|
|
1323
|
+
createTemporaryIntegratedConsole: false,
|
|
1324
|
+
executeMode: "Call",
|
|
1325
|
+
},
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
return {
|
|
1329
|
+
command: process.execPath,
|
|
1330
|
+
args: [],
|
|
1331
|
+
adapterID: "pwa-node",
|
|
1332
|
+
request: "launch",
|
|
1333
|
+
launch: {
|
|
1334
|
+
...common,
|
|
1335
|
+
type: "pwa-node",
|
|
1336
|
+
console: "internalConsole",
|
|
1337
|
+
autoAttachChildProcesses: false,
|
|
1338
|
+
stopOnEntry: true,
|
|
1339
|
+
sourceMaps: true,
|
|
1340
|
+
pauseForSourceMap: true,
|
|
1341
|
+
outFiles: [path.join(path.dirname(options.program), "**", "*.js")],
|
|
1342
|
+
},
|
|
1343
|
+
};
|
|
1344
|
+
}
|