@agimon-ai/po-runner 0.0.0-alpha.21 → 0.0.0-alpha.211
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/LICENSE +21 -149
- package/README.md +34 -206
- package/dist/apiContracts.cjs +45 -2
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +45 -2
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/{bashResult-BqDa7sbC.mjs → bashResult-BLCLerXE.mjs} +57 -7
- package/dist/bashResult-BLCLerXE.mjs.map +1 -0
- package/dist/{bashResult-C2iKhHpD.cjs → bashResult-CZYiyl4p.cjs} +74 -6
- package/dist/bashResult-CZYiyl4p.cjs.map +1 -0
- package/dist/{bashResult-DcrRaBLv.d.mts → bashResult-CgVS_JpL.d.mts} +8 -3
- package/dist/{bashResult-DcrRaBLv.d.mts.map → bashResult-CgVS_JpL.d.mts.map} +1 -1
- package/dist/{bashRunService-DjOH5kye.cjs → bashRunService-DmuA1mKL.cjs} +52 -31
- package/dist/bashRunService-DmuA1mKL.cjs.map +1 -0
- package/dist/{bashRunService-Ci0cGdYO.d.mts → bashRunService-Iotfc_nV.d.mts} +21 -2
- package/dist/bashRunService-Iotfc_nV.d.mts.map +1 -0
- package/dist/{bashRunService-Cl3pYccr.mjs → bashRunService-Luy2hPMS.mjs} +52 -31
- package/dist/bashRunService-Luy2hPMS.mjs.map +1 -0
- package/dist/bashRunService.cjs +1 -1
- package/dist/bashRunService.d.mts +4 -4
- package/dist/bashRunService.d.mts.map +1 -1
- package/dist/bashRunService.mjs +1 -1
- package/dist/bashSchema.cjs +1 -1
- package/dist/bashSchema.d.mts +1 -1
- package/dist/bashSchema.mjs +1 -1
- package/dist/bashTool-D2ECDAhc.cjs +43 -0
- package/dist/bashTool-D2ECDAhc.cjs.map +1 -0
- package/dist/{bashTool-B1EwZLo_.d.mts → bashTool-Dc1ld2E3.d.mts} +3 -9
- package/dist/bashTool-Dc1ld2E3.d.mts.map +1 -0
- package/dist/bashTool-vg8uhbkj.mjs +26 -0
- package/dist/bashTool-vg8uhbkj.mjs.map +1 -0
- package/dist/bashTool.cjs +3 -3
- package/dist/bashTool.cjs.map +1 -1
- package/dist/bashTool.d.mts +4 -4
- package/dist/bashTool.d.mts.map +1 -1
- package/dist/bashTool.mjs +3 -3
- package/dist/bashTool.mjs.map +1 -1
- package/dist/bin/cli.cjs +372 -9
- package/dist/bin/cli.cjs.map +1 -1
- package/dist/bin/cli.d.mts.map +1 -1
- package/dist/bin/cli.mjs +369 -8
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/bin/logSink.cjs +27 -24
- package/dist/bin/logSink.cjs.map +1 -1
- package/dist/bin/logSink.mjs +24 -21
- package/dist/bin/logSink.mjs.map +1 -1
- package/dist/bin/runnerHost.cjs +141 -53
- package/dist/bin/runnerHost.cjs.map +1 -1
- package/dist/bin/runnerHost.d.mts.map +1 -1
- package/dist/bin/runnerHost.mjs +141 -53
- package/dist/bin/runnerHost.mjs.map +1 -1
- package/dist/cliApp-7iTUx5KZ.cjs +351 -0
- package/dist/cliApp-7iTUx5KZ.cjs.map +1 -0
- package/dist/cliApp-S4iEO-fi.mjs +338 -0
- package/dist/cliApp-S4iEO-fi.mjs.map +1 -0
- package/dist/cliApp.cjs +2 -1
- package/dist/cliApp.d.mts +9 -4
- package/dist/cliApp.d.mts.map +1 -1
- package/dist/cliApp.mjs +1 -1
- package/dist/compaction.d.mts +1 -1
- package/dist/extensions/mcp-ui.mjs +7 -6
- package/dist/extensions/mcp-ui.mjs.map +1 -1
- package/dist/extensions/mcp.cjs +37 -17
- package/dist/extensions/mcp.cjs.map +1 -1
- package/dist/extensions/mcp.d.mts.map +1 -1
- package/dist/extensions/mcp.mjs +37 -17
- package/dist/extensions/mcp.mjs.map +1 -1
- package/dist/extensions/native.mjs +1225 -374
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +900 -221
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +908 -227
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +924 -766
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/headless-CMj9hunm.cjs +237 -0
- package/dist/headless-CMj9hunm.cjs.map +1 -0
- package/dist/headless-CUJt5Ihx.mjs +226 -0
- package/dist/headless-CUJt5Ihx.mjs.map +1 -0
- package/dist/{index-DM7yJpMs.d.mts → index-7_nuKoVm.d.mts} +6 -6
- package/dist/index-7_nuKoVm.d.mts.map +1 -0
- package/dist/index-BCCF1sGD.d.mts.map +1 -1
- package/dist/{index-CzCF_OP9.d.mts → index-CH-z0BX3.d.mts} +11 -4
- package/dist/index-CH-z0BX3.d.mts.map +1 -0
- package/dist/{index-C-IC35d9.d.mts → index-CJNsR-Ir.d.mts} +10 -7
- package/dist/index-CJNsR-Ir.d.mts.map +1 -0
- package/dist/{index--xF7DvsE.d.mts → index-CNCb1usM.d.mts} +8 -2
- package/dist/index-CNCb1usM.d.mts.map +1 -0
- package/dist/index-EMbmq9gu.d.mts +45 -0
- package/dist/index-EMbmq9gu.d.mts.map +1 -0
- package/dist/index-QlfncPRs.d.mts +58 -0
- package/dist/index-QlfncPRs.d.mts.map +1 -0
- package/dist/index-qSi4-EJW.d.mts +49 -0
- package/dist/index-qSi4-EJW.d.mts.map +1 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/launch.cjs +4 -0
- package/dist/launch.d.mts +55 -0
- package/dist/launch.d.mts.map +1 -0
- package/dist/launch.mjs +1 -0
- package/dist/{launcher-CCYsFBM9.mjs → launcher-3xMxw72I.mjs} +45 -31
- package/dist/launcher-3xMxw72I.mjs.map +1 -0
- package/dist/{launcher-BG5t9nvG.d.mts → launcher-CDDBTvZq.d.mts} +4 -3
- package/dist/launcher-CDDBTvZq.d.mts.map +1 -0
- package/dist/{launcher-ZgDdyXpq.cjs → launcher-D7qAhSRL.cjs} +47 -33
- package/dist/launcher-D7qAhSRL.cjs.map +1 -0
- package/dist/launcher.cjs +1 -1
- package/dist/launcher.d.mts +5 -5
- package/dist/launcher.d.mts.map +1 -1
- package/dist/launcher.mjs +1 -1
- package/dist/lifeline-26IaW5w7.d.mts +34 -0
- package/dist/lifeline-26IaW5w7.d.mts.map +1 -0
- package/dist/lifeline-B4cjtrBe.cjs +27 -0
- package/dist/lifeline-B4cjtrBe.cjs.map +1 -0
- package/dist/lifeline-C1v2ItCY.mjs +214 -0
- package/dist/lifeline-C1v2ItCY.mjs.map +1 -0
- package/dist/lifeline-D4_ZRAhO.cjs +229 -0
- package/dist/lifeline-D4_ZRAhO.cjs.map +1 -0
- package/dist/lifeline-nPh3cx5A.mjs +10 -0
- package/dist/lifeline-nPh3cx5A.mjs.map +1 -0
- package/dist/lifeline.cjs +4 -1
- package/dist/lifeline.d.mts +4 -21
- package/dist/lifeline.mjs +3 -3
- package/dist/logFile-B9FSwmE0.cjs +44 -0
- package/dist/logFile-B9FSwmE0.cjs.map +1 -0
- package/dist/{logFile-C7oQ_v-g.d.mts → logFile-BirfZtS1.d.mts} +4 -4
- package/dist/logFile-BirfZtS1.d.mts.map +1 -0
- package/dist/logFile-D1EOKqmL.mjs +39 -0
- package/dist/logFile-D1EOKqmL.mjs.map +1 -0
- package/dist/logFile.cjs +1 -1
- package/dist/logFile.d.mts +3 -3
- package/dist/logFile.d.mts.map +1 -1
- package/dist/logFile.mjs +1 -1
- package/dist/{logReader-mq9uVurh.mjs → logReader-BYKii_s_.mjs} +99 -52
- package/dist/logReader-BYKii_s_.mjs.map +1 -0
- package/dist/{logReader-MdW9ffvV.d.mts → logReader-Bn3WEdjg.d.mts} +4 -2
- package/dist/{logReader-MdW9ffvV.d.mts.map → logReader-Bn3WEdjg.d.mts.map} +1 -1
- package/dist/{logReader-DHCK2BEr.cjs → logReader-DpMjBqfn.cjs} +101 -54
- package/dist/logReader-DpMjBqfn.cjs.map +1 -0
- package/dist/logReader.cjs +1 -1
- package/dist/logReader.d.mts +2 -2
- package/dist/logReader.mjs +1 -1
- package/dist/po-runtime-identity.json +1 -0
- package/dist/{ptyHost-D35hNmtd.cjs → ptyHost-C-oWV455.cjs} +20 -14
- package/dist/ptyHost-C-oWV455.cjs.map +1 -0
- package/dist/{ptyHost-CwbLLr90.mjs → ptyHost-C2zu-ZfO.mjs} +19 -13
- package/dist/ptyHost-C2zu-ZfO.mjs.map +1 -0
- package/dist/{ptyHost-DWWtRrGn.d.mts → ptyHost-C_6x2xuJ.d.mts} +2 -2
- package/dist/{ptyHost-DWWtRrGn.d.mts.map → ptyHost-C_6x2xuJ.d.mts.map} +1 -1
- package/dist/ptyHost.cjs +1 -1
- package/dist/ptyHost.d.mts +2 -2
- package/dist/ptyHost.d.mts.map +1 -1
- package/dist/ptyHost.mjs +1 -1
- package/dist/{reconcile-wNYQJZF-.mjs → reconcile-DUaX_vKZ.mjs} +2 -2
- package/dist/reconcile-DUaX_vKZ.mjs.map +1 -0
- package/dist/{reconcile-5cZ11jSD.cjs → reconcile-DjF9T1hN.cjs} +2 -2
- package/dist/reconcile-DjF9T1hN.cjs.map +1 -0
- package/dist/reconcile.cjs +1 -1
- package/dist/reconcile.d.mts +3 -3
- package/dist/reconcile.mjs +1 -1
- package/dist/responseEnvelope.cjs +5 -2
- package/dist/responseEnvelope.d.mts +15 -6
- package/dist/responseEnvelope.d.mts.map +1 -1
- package/dist/responseEnvelope.mjs +3 -3
- package/dist/{rmuxBackend-Dh0CYVAL.cjs → rmuxBackend-9tHTx1vf.cjs} +82 -48
- package/dist/rmuxBackend-9tHTx1vf.cjs.map +1 -0
- package/dist/{rmuxBackend-rjrVTG6K.mjs → rmuxBackend-BaK-R35I.mjs} +79 -45
- package/dist/rmuxBackend-BaK-R35I.mjs.map +1 -0
- package/dist/{rmuxBackend-CaEWooWn.d.mts → rmuxBackend-xFzlANM9.d.mts} +4 -4
- package/dist/rmuxBackend-xFzlANM9.d.mts.map +1 -0
- package/dist/rmuxBackend.cjs +1 -1
- package/dist/rmuxBackend.d.mts +2 -2
- package/dist/rmuxBackend.mjs +1 -1
- package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → rolldown-runtime-C0BPl7ul.cjs} +15 -0
- package/dist/{rtkProcessor-Iw9gP5Xp.mjs → rtkProcessor-DOXcp51z.mjs} +6 -5
- package/dist/rtkProcessor-DOXcp51z.mjs.map +1 -0
- package/dist/{rtkProcessor-DSGbM-Cm.cjs → rtkProcessor-J2gLQvM4.cjs} +8 -6
- package/dist/rtkProcessor-J2gLQvM4.cjs.map +1 -0
- package/dist/rtkProcessor.cjs +1 -1
- package/dist/rtkProcessor.mjs +1 -1
- package/dist/{runnerDependencies-DSun3xO-.cjs → runnerDependencies-CABYjW7H.cjs} +97 -64
- package/dist/runnerDependencies-CABYjW7H.cjs.map +1 -0
- package/dist/{runnerDependencies-7h_cxOva.mjs → runnerDependencies-DmvIcpZi.mjs} +95 -62
- package/dist/runnerDependencies-DmvIcpZi.mjs.map +1 -0
- package/dist/runnerDependencies.cjs +1 -1
- package/dist/runnerDependencies.d.mts +1 -1
- package/dist/runnerDependencies.mjs +1 -1
- package/dist/runnerHost-BvNYPMeh.mjs +165 -0
- package/dist/runnerHost-BvNYPMeh.mjs.map +1 -0
- package/dist/runnerHost-C2F5oxzn.cjs +184 -0
- package/dist/runnerHost-C2F5oxzn.cjs.map +1 -0
- package/dist/runnerLaunch-BAf7hXMr.cjs +192 -0
- package/dist/runnerLaunch-BAf7hXMr.cjs.map +1 -0
- package/dist/runnerLaunch-Bimgdh4h.mjs +175 -0
- package/dist/runnerLaunch-Bimgdh4h.mjs.map +1 -0
- package/dist/runnerNamer.d.mts +1 -1
- package/dist/{runnerPaths-B41rMOY6.cjs → runnerPaths-CSkswyjR.cjs} +97 -179
- package/dist/runnerPaths-CSkswyjR.cjs.map +1 -0
- package/dist/{runnerPaths-Dibbvyx_.mjs → runnerPaths-D3P7_EhW.mjs} +91 -179
- package/dist/runnerPaths-D3P7_EhW.mjs.map +1 -0
- package/dist/runnerPaths.cjs +1 -1
- package/dist/runnerPaths.d.mts +7 -9
- package/dist/runnerPaths.d.mts.map +1 -1
- package/dist/runnerPaths.mjs +1 -1
- package/dist/{runnerRegistry-dQYlMSpQ.cjs → runnerRegistry-B8K1L3lq.cjs} +68 -45
- package/dist/runnerRegistry-B8K1L3lq.cjs.map +1 -0
- package/dist/{runnerRegistry-V-Ocaf4N.d.mts → runnerRegistry-BlZhS9yL.d.mts} +2 -2
- package/dist/{runnerRegistry-V-Ocaf4N.d.mts.map → runnerRegistry-BlZhS9yL.d.mts.map} +1 -1
- package/dist/{runnerRegistry-BgaR5O86.mjs → runnerRegistry-Dqca6SD3.mjs} +53 -29
- package/dist/runnerRegistry-Dqca6SD3.mjs.map +1 -0
- package/dist/runnerRegistry-NW6oAJ71.cjs +60 -0
- package/dist/runnerRegistry-NW6oAJ71.cjs.map +1 -0
- package/dist/runnerRegistry-l0C_55oO.mjs +13 -0
- package/dist/runnerRegistry-l0C_55oO.mjs.map +1 -0
- package/dist/runnerRegistry.cjs +1 -1
- package/dist/runnerRegistry.d.mts +2 -2
- package/dist/runnerRegistry.mjs +1 -1
- package/dist/runnerSequence-ZTYgZ_2W.cjs +32 -0
- package/dist/runnerSequence-ZTYgZ_2W.cjs.map +1 -0
- package/dist/runnerSequence-k-_Fd77y.mjs +9 -0
- package/dist/runnerSequence-k-_Fd77y.mjs.map +1 -0
- package/dist/runnerSequenceStore-CaY7S_Sd.mjs +76 -0
- package/dist/runnerSequenceStore-CaY7S_Sd.mjs.map +1 -0
- package/dist/runnerSequenceStore-Ck6M-8r_.cjs +89 -0
- package/dist/runnerSequenceStore-Ck6M-8r_.cjs.map +1 -0
- package/dist/services/lifeline/client.cjs +88 -4
- package/dist/services/lifeline/client.cjs.map +1 -1
- package/dist/services/lifeline/client.d.mts +16 -0
- package/dist/services/lifeline/client.d.mts.map +1 -1
- package/dist/services/lifeline/client.mjs +83 -2
- package/dist/services/lifeline/client.mjs.map +1 -1
- package/dist/services/runnerSupervisor/index.cjs +36 -22
- package/dist/services/runnerSupervisor/index.cjs.map +1 -1
- package/dist/services/runnerSupervisor/index.d.mts +7 -5
- package/dist/services/runnerSupervisor/index.d.mts.map +1 -1
- package/dist/services/runnerSupervisor/index.mjs +35 -21
- package/dist/services/runnerSupervisor/index.mjs.map +1 -1
- package/dist/session-CdVeSD7F.mjs +8 -0
- package/dist/session-CdVeSD7F.mjs.map +1 -0
- package/dist/session-DnUj8Q71.cjs +25 -0
- package/dist/session-DnUj8Q71.cjs.map +1 -0
- package/dist/session-ISEGK4z9.mjs +26 -0
- package/dist/session-ISEGK4z9.mjs.map +1 -0
- package/dist/session-PQd3azWf.cjs +43 -0
- package/dist/session-PQd3azWf.cjs.map +1 -0
- package/dist/session.cjs +4 -3
- package/dist/session.d.mts +3 -1
- package/dist/session.d.mts.map +1 -1
- package/dist/session.mjs +3 -3
- package/dist/{type-DwMZoINK.d.mts → type-BWY9vvSq.d.mts} +6 -4
- package/dist/type-BWY9vvSq.d.mts.map +1 -0
- package/dist/{type-Do0YxwVQ.d.mts → type-bZgYQ7hv.d.mts} +11 -11
- package/dist/{type-Do0YxwVQ.d.mts.map → type-bZgYQ7hv.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/llms.txt +2 -1
- package/locales/vi.json +169 -0
- package/locales/zh-CN.json +169 -0
- package/package.json +95 -30
- package/skills/po-runner/SKILL.md +32 -14
- package/src/prompts/codemode-how-to-runner/SKILL.md +85 -0
- package/src/prompts/help-how-to-runner/SKILL.md +51 -0
- package/dist/bashResult-BqDa7sbC.mjs.map +0 -1
- package/dist/bashResult-C2iKhHpD.cjs.map +0 -1
- package/dist/bashRunService-Ci0cGdYO.d.mts.map +0 -1
- package/dist/bashRunService-Cl3pYccr.mjs.map +0 -1
- package/dist/bashRunService-DjOH5kye.cjs.map +0 -1
- package/dist/bashTool-B1EwZLo_.d.mts.map +0 -1
- package/dist/bashTool-BvC3YOgG.mjs +0 -24
- package/dist/bashTool-BvC3YOgG.mjs.map +0 -1
- package/dist/bashTool-euL6zMDl.cjs +0 -41
- package/dist/bashTool-euL6zMDl.cjs.map +0 -1
- package/dist/cliApp-T8Fx_-1j.cjs +0 -244
- package/dist/cliApp-T8Fx_-1j.cjs.map +0 -1
- package/dist/cliApp-q97eVh4E.mjs +0 -237
- package/dist/cliApp-q97eVh4E.mjs.map +0 -1
- package/dist/headless-DOlCixyf.mjs +0 -169
- package/dist/headless-DOlCixyf.mjs.map +0 -1
- package/dist/headless-Dko_yBiy.cjs +0 -180
- package/dist/headless-Dko_yBiy.cjs.map +0 -1
- package/dist/index--xF7DvsE.d.mts.map +0 -1
- package/dist/index-BzeXJk6V.d.mts +0 -12
- package/dist/index-BzeXJk6V.d.mts.map +0 -1
- package/dist/index-C-IC35d9.d.mts.map +0 -1
- package/dist/index-CzCF_OP9.d.mts.map +0 -1
- package/dist/index-DM7yJpMs.d.mts.map +0 -1
- package/dist/launcher-BG5t9nvG.d.mts.map +0 -1
- package/dist/launcher-CCYsFBM9.mjs.map +0 -1
- package/dist/launcher-ZgDdyXpq.cjs.map +0 -1
- package/dist/lifeline-Bm-bHIjS.mjs +0 -88
- package/dist/lifeline-Bm-bHIjS.mjs.map +0 -1
- package/dist/lifeline-eJdZV0nN.d.mts +0 -19
- package/dist/lifeline-eJdZV0nN.d.mts.map +0 -1
- package/dist/lifeline-m7laIzIP.cjs +0 -98
- package/dist/lifeline-m7laIzIP.cjs.map +0 -1
- package/dist/lifeline.d.mts.map +0 -1
- package/dist/logFile-C7oQ_v-g.d.mts.map +0 -1
- package/dist/logFile-CnPKtxPy.cjs +0 -67
- package/dist/logFile-CnPKtxPy.cjs.map +0 -1
- package/dist/logFile-XcDHBwu1.mjs +0 -60
- package/dist/logFile-XcDHBwu1.mjs.map +0 -1
- package/dist/logReader-DHCK2BEr.cjs.map +0 -1
- package/dist/logReader-mq9uVurh.mjs.map +0 -1
- package/dist/ptyHost-CwbLLr90.mjs.map +0 -1
- package/dist/ptyHost-D35hNmtd.cjs.map +0 -1
- package/dist/reconcile-5cZ11jSD.cjs.map +0 -1
- package/dist/reconcile-wNYQJZF-.mjs.map +0 -1
- package/dist/rmuxBackend-CaEWooWn.d.mts.map +0 -1
- package/dist/rmuxBackend-Dh0CYVAL.cjs.map +0 -1
- package/dist/rmuxBackend-rjrVTG6K.mjs.map +0 -1
- package/dist/rtkProcessor-DSGbM-Cm.cjs.map +0 -1
- package/dist/rtkProcessor-Iw9gP5Xp.mjs.map +0 -1
- package/dist/runnerDependencies-7h_cxOva.mjs.map +0 -1
- package/dist/runnerDependencies-DSun3xO-.cjs.map +0 -1
- package/dist/runnerPaths-B41rMOY6.cjs.map +0 -1
- package/dist/runnerPaths-Dibbvyx_.mjs.map +0 -1
- package/dist/runnerRegistry-BgaR5O86.mjs.map +0 -1
- package/dist/runnerRegistry-dQYlMSpQ.cjs.map +0 -1
- package/dist/session-BKYnH4R6.mjs +0 -18
- package/dist/session-BKYnH4R6.mjs.map +0 -1
- package/dist/session-BvqzhXZY.cjs +0 -29
- package/dist/session-BvqzhXZY.cjs.map +0 -1
- package/dist/session-DE2Acesp.mjs +0 -6
- package/dist/session-DE2Acesp.mjs.map +0 -1
- package/dist/session-SfIPtdZO.cjs +0 -11
- package/dist/session-SfIPtdZO.cjs.map +0 -1
- package/dist/type-DwMZoINK.d.mts.map +0 -1
- package/src/prompts/po-use-runner/SKILL.md +0 -47
package/dist/bin/runnerHost.mjs
CHANGED
|
@@ -1,38 +1,46 @@
|
|
|
1
|
-
import { LIFELINE_ENV, watchOwner } from "../services/lifeline/client.mjs";
|
|
2
|
-
import
|
|
1
|
+
import { LIFELINE_ENV, observeSessions, watchOwner } from "../services/lifeline/client.mjs";
|
|
2
|
+
import "../lifeline-nPh3cx5A.mjs";
|
|
3
|
+
import { a as REGISTRY_PATH_ENV } from "../runnerRegistry-l0C_55oO.mjs";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
3
5
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
6
|
+
import { execFile, spawn } from "node:child_process";
|
|
5
7
|
import os from "node:os";
|
|
6
|
-
import { createPoTelemetry } from "@agimon-ai/po-telemetry";
|
|
7
8
|
//#region src/bin/runnerHost.ts
|
|
8
9
|
const POLL_MS = 10;
|
|
9
10
|
const FORWARDED_SIGNAL_GRACE_MS = 2e3;
|
|
10
|
-
const HOST_FAILED_EVENT = "po_runner.host_failed";
|
|
11
11
|
const INVALID_COMMAND_SPEC_ERROR = "invalid runner command spec";
|
|
12
|
+
const OWNER_LOST_EXIT = {
|
|
13
|
+
reason: "stopped",
|
|
14
|
+
terminationReason: "owner_lost",
|
|
15
|
+
stopReason: "owner session ended"
|
|
16
|
+
};
|
|
12
17
|
async function main(argv = process.argv.slice(2)) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
env: process.env,
|
|
18
|
-
enableLogs: true,
|
|
19
|
-
enableTraces: true
|
|
20
|
-
});
|
|
18
|
+
if (argv[0] === "--observe-sessions") {
|
|
19
|
+
observeSessions(cleanupSessions);
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
21
22
|
const [specPath, gatePath, exitPath] = argv;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
if (!specPath || !gatePath || !exitPath) throw new Error("runnerHost requires spec, gate, and exit paths");
|
|
24
|
+
const spec = await readSpec(specPath);
|
|
25
|
+
let ownerLost = false;
|
|
26
|
+
let onOwnerLost = () => void 0;
|
|
27
|
+
const detachLifeline = watchOwner(() => {
|
|
28
|
+
ownerLost = true;
|
|
29
|
+
onOwnerLost();
|
|
30
|
+
}, spec.env[LIFELINE_ENV]);
|
|
31
|
+
if (!await waitForGate(gatePath, () => ownerLost)) {
|
|
32
|
+
detachLifeline();
|
|
33
|
+
await writeAtomic(exitPath, {
|
|
34
|
+
code: null,
|
|
35
|
+
signal: null,
|
|
36
|
+
...OWNER_LOST_EXIT
|
|
37
|
+
});
|
|
38
|
+
await cleanupOwnerSession(spec);
|
|
39
|
+
return 1;
|
|
31
40
|
}
|
|
32
41
|
let child;
|
|
33
42
|
let forwardedSignal = null;
|
|
34
43
|
let escalationTimer;
|
|
35
|
-
let ownerLost = false;
|
|
36
44
|
const signalChild = (signal) => {
|
|
37
45
|
if (!child?.pid) return;
|
|
38
46
|
try {
|
|
@@ -59,10 +67,7 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
59
67
|
detached: true
|
|
60
68
|
});
|
|
61
69
|
if (forwardedSignal) forward(forwardedSignal);
|
|
62
|
-
|
|
63
|
-
ownerLost = true;
|
|
64
|
-
forward("SIGTERM");
|
|
65
|
-
}, spec.env[LIFELINE_ENV]);
|
|
70
|
+
onOwnerLost = () => forward("SIGTERM");
|
|
66
71
|
try {
|
|
67
72
|
const result = await new Promise((resolve, reject) => {
|
|
68
73
|
child?.once("error", reject);
|
|
@@ -71,49 +76,60 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
71
76
|
signal: signal ?? forwardedSignal
|
|
72
77
|
}));
|
|
73
78
|
});
|
|
74
|
-
writeAtomic(exitPath, {
|
|
79
|
+
await writeAtomic(exitPath, {
|
|
75
80
|
...result,
|
|
76
|
-
...ownerLost ? {
|
|
77
|
-
reason: "stopped",
|
|
78
|
-
terminationReason: "owner_lost",
|
|
79
|
-
stopReason: "owner session ended"
|
|
80
|
-
} : {}
|
|
81
|
-
});
|
|
82
|
-
const exitCode = result.code !== null ? result.code : result.signal ? 128 + os.constants.signals[result.signal] : 1;
|
|
83
|
-
await telemetry.recordEvent("po_runner.host_finished", {
|
|
84
|
-
outcome: result.signal || forwardedSignal ? "signaled" : exitCode === 0 ? "completed" : "failed",
|
|
85
|
-
"runner.exit_code": exitCode,
|
|
86
|
-
...result.signal || forwardedSignal ? { "runner.signal": result.signal ?? forwardedSignal ?? "" } : {},
|
|
87
|
-
duration_ms: Date.now() - startedAt
|
|
81
|
+
...ownerLost ? OWNER_LOST_EXIT : {}
|
|
88
82
|
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
await telemetry.recordError(HOST_FAILED_EVENT, error, { duration_ms: Date.now() - startedAt });
|
|
92
|
-
throw error;
|
|
83
|
+
if (ownerLost) await cleanupOwnerSession(spec);
|
|
84
|
+
return result.code !== null ? result.code : result.signal ? 128 + os.constants.signals[result.signal] : 1;
|
|
93
85
|
} finally {
|
|
94
86
|
detachLifeline();
|
|
95
87
|
if (escalationTimer) clearTimeout(escalationTimer);
|
|
96
|
-
await telemetry.shutdown();
|
|
97
88
|
}
|
|
98
89
|
}
|
|
99
|
-
|
|
100
|
-
|
|
90
|
+
/** The backend supplies an exact kill-session argv, never a shared-server shutdown. */
|
|
91
|
+
async function cleanupOwnerSession(spec) {
|
|
92
|
+
const [binary, ...args] = spec.ownerLostCleanup ?? [];
|
|
93
|
+
if (!binary) return;
|
|
94
|
+
await new Promise((resolve, reject) => {
|
|
95
|
+
execFile(binary, args, {
|
|
96
|
+
env: spec.env,
|
|
97
|
+
timeout: 1e4
|
|
98
|
+
}, (error) => {
|
|
99
|
+
if (error) reject(error);
|
|
100
|
+
else resolve();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async function readSpec(target) {
|
|
105
|
+
const value = JSON.parse(await fs.readFile(target, "utf8"));
|
|
101
106
|
if (typeof value !== "object" || value === null) throw new Error(INVALID_COMMAND_SPEC_ERROR);
|
|
102
107
|
const spec = value;
|
|
103
108
|
if (typeof spec.command !== "string" || typeof spec.cwd !== "string" || !spec.env) throw new Error(INVALID_COMMAND_SPEC_ERROR);
|
|
104
109
|
return {
|
|
105
110
|
command: spec.command,
|
|
106
111
|
cwd: spec.cwd,
|
|
107
|
-
env: spec.env
|
|
112
|
+
env: spec.env,
|
|
113
|
+
ownerLostCleanup: spec.ownerLostCleanup
|
|
108
114
|
};
|
|
109
115
|
}
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
/** False once the owner is gone, since only the owner opens the gate. */
|
|
117
|
+
async function waitForGate(target, abandoned) {
|
|
118
|
+
while (!abandoned()) {
|
|
119
|
+
try {
|
|
120
|
+
await fs.access(target);
|
|
121
|
+
return true;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (error.code !== "ENOENT") throw error;
|
|
124
|
+
}
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
112
128
|
}
|
|
113
|
-
function writeAtomic(target, value) {
|
|
129
|
+
async function writeAtomic(target, value) {
|
|
114
130
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
115
|
-
fs.
|
|
116
|
-
fs.
|
|
131
|
+
await fs.writeFile(temporary, `${JSON.stringify(value)}\n`, { mode: 384 });
|
|
132
|
+
await fs.rename(temporary, target);
|
|
117
133
|
}
|
|
118
134
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main().then((code) => {
|
|
119
135
|
process.exitCode = code;
|
|
@@ -121,6 +137,78 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
121
137
|
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
122
138
|
process.exitCode = 1;
|
|
123
139
|
});
|
|
140
|
+
/** Loaded on the first session an owner leaves behind, then shared by every later one. */
|
|
141
|
+
let cleaner;
|
|
142
|
+
let telemetry;
|
|
143
|
+
/**
|
|
144
|
+
* A separate process survives SIGKILL of the owner, even if that session has no active runners.
|
|
145
|
+
* The owner cleans up each session it ends with its own shared services and removes its marker,
|
|
146
|
+
* so only a session still marked with its generation is left here; the rest load nothing.
|
|
147
|
+
*/
|
|
148
|
+
async function cleanupSessions(watches) {
|
|
149
|
+
const failures = [];
|
|
150
|
+
for (const watch of watches) try {
|
|
151
|
+
if (await readMarker(watch.marker) !== watch.generation) continue;
|
|
152
|
+
await (await (cleaner ??= loadCleaner()))(watch);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
failures.push({
|
|
155
|
+
watch,
|
|
156
|
+
error
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const [first] = failures;
|
|
160
|
+
if (!first) return;
|
|
161
|
+
const log = await (telemetry ??= loadTelemetry(first.watch.environment));
|
|
162
|
+
for (const { watch, error } of failures) await log.recordError("po_runner.observer_cleanup_failed", error, { "session.id": watch.sessionId }, { includeException: true });
|
|
163
|
+
await log.flush();
|
|
164
|
+
throw new AggregateError(failures.map(({ error }) => error), `Could not clean up runner sessions ${failures.map(({ watch }) => watch.sessionId).join(", ")}`);
|
|
165
|
+
}
|
|
166
|
+
async function readMarker(marker) {
|
|
167
|
+
try {
|
|
168
|
+
return await fs.readFile(marker, "utf8");
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error.code === "ENOENT") return void 0;
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** One registry per registry path, held until the observer runs out of work. */
|
|
175
|
+
async function loadCleaner() {
|
|
176
|
+
const [{ cleanupRunnerSession }, { RunnerPaths }, { createDefaultProcessRegistry }] = await Promise.all([
|
|
177
|
+
import("../runnerHost-BvNYPMeh.mjs").then((n) => n.r),
|
|
178
|
+
import("../runnerPaths-D3P7_EhW.mjs").then((n) => n.r),
|
|
179
|
+
import("../runnerRegistry-Dqca6SD3.mjs").then((n) => n.r)
|
|
180
|
+
]);
|
|
181
|
+
const registries = /* @__PURE__ */ new Map();
|
|
182
|
+
process.once("beforeExit", () => {
|
|
183
|
+
for (const registry of registries.values()) registry.close();
|
|
184
|
+
});
|
|
185
|
+
return (watch) => {
|
|
186
|
+
const registryPath = watch.environment[REGISTRY_PATH_ENV];
|
|
187
|
+
let registry = registries.get(registryPath);
|
|
188
|
+
if (!registry) {
|
|
189
|
+
registry = createDefaultProcessRegistry(watch.environment);
|
|
190
|
+
registries.set(registryPath, registry);
|
|
191
|
+
}
|
|
192
|
+
return cleanupRunnerSession({
|
|
193
|
+
sessionId: watch.sessionId,
|
|
194
|
+
paths: new RunnerPaths(watch.repository, watch.environment),
|
|
195
|
+
processRegistry: registry,
|
|
196
|
+
ownerPid: watch.ownerPid,
|
|
197
|
+
generation: watch.generation
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
async function loadTelemetry(environment) {
|
|
202
|
+
const { createPoTelemetry } = await import("@agimon-ai/po-core/telemetry");
|
|
203
|
+
const shared = createPoTelemetry({
|
|
204
|
+
serviceName: "po-runner-host",
|
|
205
|
+
packageName: "@agimon-ai/po-runner",
|
|
206
|
+
env: environment,
|
|
207
|
+
enableLogs: true
|
|
208
|
+
});
|
|
209
|
+
process.once("beforeExit", () => void shared.shutdown());
|
|
210
|
+
return shared;
|
|
211
|
+
}
|
|
124
212
|
//#endregion
|
|
125
213
|
export { main };
|
|
126
214
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runnerHost.mjs","names":[],"sources":["../../src/bin/runnerHost.ts"],"sourcesContent":["import { type ChildProcess, spawn } from 'node:child_process';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport { pathToFileURL } from 'node:url';\n\nimport { createPoTelemetry } from '@agimon-ai/po-telemetry';\n\nimport { LIFELINE_ENV, watchOwner } from '../services/lifeline/client';\n\ninterface CommandSpec {\n command: string;\n cwd: string;\n env: Record<string, string>;\n}\n\nconst POLL_MS = 10;\nconst FORWARDED_SIGNAL_GRACE_MS = 2_000;\nconst HOST_FAILED_EVENT = 'po_runner.host_failed';\nconst INVALID_COMMAND_SPEC_ERROR = 'invalid runner command spec';\n\nexport async function main(argv: readonly string[] = process.argv.slice(2)): Promise<number> {\n const startedAt = Date.now();\n const telemetry = createPoTelemetry({\n serviceName: 'po-runner-host',\n packageName: '@agimon-ai/po-runner',\n env: process.env,\n enableLogs: true,\n enableTraces: true,\n });\n const [specPath, gatePath, exitPath] = argv;\n let spec: CommandSpec;\n try {\n if (!specPath || !gatePath || !exitPath) throw new Error('runnerHost requires spec, gate, and exit paths');\n spec = readSpec(specPath);\n await waitForGate(gatePath);\n } catch (error) {\n await telemetry.recordError(HOST_FAILED_EVENT, error, { duration_ms: Date.now() - startedAt });\n await telemetry.shutdown();\n throw error;\n }\n let child: ChildProcess | undefined;\n let forwardedSignal: NodeJS.Signals | null = null;\n let escalationTimer: NodeJS.Timeout | undefined;\n let ownerLost = false;\n const signalChild = (signal: NodeJS.Signals): void => {\n if (!child?.pid) return;\n try {\n process.kill(-child.pid, signal);\n } catch {\n child.kill(signal);\n }\n };\n const forward = (signal: NodeJS.Signals): void => {\n forwardedSignal = signal;\n signalChild(signal);\n escalationTimer ??= setTimeout(() => signalChild('SIGKILL'), FORWARDED_SIGNAL_GRACE_MS);\n };\n const signals: NodeJS.Signals[] = ['SIGTERM', 'SIGINT', 'SIGHUP'];\n for (const signal of signals) process.once(signal, () => forward(signal));\n\n child = spawn(spec.command, {\n cwd: spec.cwd,\n env: spec.env,\n shell: '/bin/bash',\n stdio: 'inherit',\n detached: true,\n });\n if (forwardedSignal) forward(forwardedSignal);\n\n // This process supervises the command for its whole life, so it is also the\n // right place to notice an owner that died without stopping it.\n //\n // The lifeline comes from the spec rather than this process's environment: an\n // rmux server outlives the session that started it, so its own environment can\n // still name a previous session's socket.\n const detachLifeline = watchOwner(() => {\n ownerLost = true;\n forward('SIGTERM');\n }, spec.env[LIFELINE_ENV]);\n\n try {\n const result = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve, reject) => {\n child?.once('error', reject);\n child?.once('exit', (code, signal) => resolve({ code, signal: signal ?? forwardedSignal }));\n });\n writeAtomic(exitPath, {\n ...result,\n ...(ownerLost ? { reason: 'stopped', terminationReason: 'owner_lost', stopReason: 'owner session ended' } : {}),\n });\n const exitCode = result.code !== null ? result.code : result.signal ? 128 + os.constants.signals[result.signal] : 1;\n await telemetry.recordEvent('po_runner.host_finished', {\n outcome: result.signal || forwardedSignal ? 'signaled' : exitCode === 0 ? 'completed' : 'failed',\n 'runner.exit_code': exitCode,\n ...(result.signal || forwardedSignal ? { 'runner.signal': result.signal ?? forwardedSignal ?? '' } : {}),\n duration_ms: Date.now() - startedAt,\n });\n return exitCode;\n } catch (error) {\n await telemetry.recordError(HOST_FAILED_EVENT, error, { duration_ms: Date.now() - startedAt });\n throw error;\n } finally {\n detachLifeline();\n if (escalationTimer) clearTimeout(escalationTimer);\n await telemetry.shutdown();\n }\n}\n\nfunction readSpec(target: string): CommandSpec {\n const value: unknown = JSON.parse(fs.readFileSync(target, 'utf8'));\n if (typeof value !== 'object' || value === null) throw new Error(INVALID_COMMAND_SPEC_ERROR);\n const spec = value as Partial<CommandSpec>;\n if (typeof spec.command !== 'string' || typeof spec.cwd !== 'string' || !spec.env) {\n throw new Error(INVALID_COMMAND_SPEC_ERROR);\n }\n return { command: spec.command, cwd: spec.cwd, env: spec.env };\n}\n\nasync function waitForGate(target: string): Promise<void> {\n while (!fs.existsSync(target)) await new Promise((resolve) => setTimeout(resolve, POLL_MS));\n}\n\nfunction writeAtomic(target: string, value: unknown): void {\n const temporary = `${target}.${process.pid}.tmp`;\n fs.writeFileSync(temporary, `${JSON.stringify(value)}\\n`, { mode: 0o600 });\n fs.renameSync(temporary, target);\n}\n\nif (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {\n main().then(\n (code) => {\n process.exitCode = code;\n },\n (error: unknown) => {\n process.stderr.write(`${error instanceof Error ? error.message : String(error)}\\n`);\n process.exitCode = 1;\n },\n );\n}\n"],"mappings":";;;;;;;AAeA,MAAM,UAAU;AAChB,MAAM,4BAA4B;AAClC,MAAM,oBAAoB;AAC1B,MAAM,6BAA6B;AAEnC,eAAsB,KAAK,OAA0B,QAAQ,KAAK,MAAM,CAAC,GAAoB;CAC3F,MAAM,YAAY,KAAK,I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zD,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,IAAI;CAC3C,GAAG,cAAc,WAAW,GAAG,KAAK,UAAU,KAAK,EAAE,KAAK,EAAE,MAAM,IAAM,CAAC;CACzE,GAAG,WAAW,WAAW,MAAM;AACjC;AAEA,IAAI,QAAQ,KAAK,MAAM,YAAY,QAAQ,cAAc,QAAQ,KAAK,EAAE,CAAC,CAAC,MACxE,KAAK,CAAC,CAAC,MACJ,SAAS;CACR,QAAQ,WAAW;AACrB,IACC,UAAmB;CAClB,QAAQ,OAAO,MAAM,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAAE,GAAG;CAClF,QAAQ,WAAW;AACrB,CACF"}
|
|
1
|
+
{"version":3,"file":"runnerHost.mjs","names":[],"sources":["../../src/bin/runnerHost.ts"],"sourcesContent":["import { type ChildProcess, execFile, spawn } from 'node:child_process';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport { pathToFileURL } from 'node:url';\n\nimport type { PoTelemetry } from '@agimon-ai/po-core/telemetry';\n\nimport { OBSERVE_SESSIONS_FLAG } from '../constants/lifeline';\nimport { REGISTRY_PATH_ENV } from '../constants/runnerRegistry';\nimport { LIFELINE_ENV, observeSessions, watchOwner } from '../services/lifeline/client';\nimport type { ProcessRegistryPort } from '../services/runnerRegistry';\nimport type { LifelineWatch } from '../types/lifeline';\n\n// Everything heavier loads on first use: the observer idles for its owner's whole life and\n// these imports alone would more than double its memory. A command's host loads none of it:\n// the server records the runner when it completes the record from this host's exit file.\n\ninterface CommandSpec {\n command: string;\n cwd: string;\n env: Record<string, string>;\n ownerLostCleanup?: string[];\n}\n\nconst POLL_MS = 10;\nconst FORWARDED_SIGNAL_GRACE_MS = 2_000;\nconst INVALID_COMMAND_SPEC_ERROR = 'invalid runner command spec';\nconst OWNER_LOST_EXIT = { reason: 'stopped', terminationReason: 'owner_lost', stopReason: 'owner session ended' };\n\nexport async function main(argv: readonly string[] = process.argv.slice(2)): Promise<number> {\n if (argv[0] === OBSERVE_SESSIONS_FLAG) {\n observeSessions(cleanupSessions);\n return 0;\n }\n const [specPath, gatePath, exitPath] = argv;\n if (!specPath || !gatePath || !exitPath) throw new Error('runnerHost requires spec, gate, and exit paths');\n const spec = await readSpec(specPath);\n let ownerLost = false;\n let onOwnerLost = (): void => undefined;\n // Watched from before the gate: an owner that dies before opening it never will, and nothing\n // else would end that wait.\n //\n // The lifeline comes from the spec rather than this process's environment: an\n // rmux server outlives the session that started it, so its own environment can\n // still name a previous session's socket.\n const detachLifeline = watchOwner(() => {\n ownerLost = true;\n onOwnerLost();\n }, spec.env[LIFELINE_ENV]);\n if (!(await waitForGate(gatePath, () => ownerLost))) {\n detachLifeline();\n await writeAtomic(exitPath, { code: null, signal: null, ...OWNER_LOST_EXIT });\n await cleanupOwnerSession(spec);\n return 1;\n }\n let child: ChildProcess | undefined;\n let forwardedSignal: NodeJS.Signals | null = null;\n let escalationTimer: NodeJS.Timeout | undefined;\n const signalChild = (signal: NodeJS.Signals): void => {\n if (!child?.pid) return;\n try {\n process.kill(-child.pid, signal);\n } catch {\n child.kill(signal);\n }\n };\n const forward = (signal: NodeJS.Signals): void => {\n forwardedSignal = signal;\n signalChild(signal);\n escalationTimer ??= setTimeout(() => signalChild('SIGKILL'), FORWARDED_SIGNAL_GRACE_MS);\n };\n const signals: NodeJS.Signals[] = ['SIGTERM', 'SIGINT', 'SIGHUP'];\n for (const signal of signals) process.once(signal, () => forward(signal));\n\n child = spawn(spec.command, {\n cwd: spec.cwd,\n env: spec.env,\n shell: '/bin/bash',\n stdio: 'inherit',\n detached: true,\n });\n if (forwardedSignal) forward(forwardedSignal);\n\n // This process supervises the command for its whole life, so it is also the\n // right place to notice an owner that died without stopping it.\n onOwnerLost = () => forward('SIGTERM');\n\n try {\n const result = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>((resolve, reject) => {\n child?.once('error', reject);\n child?.once('exit', (code, signal) => resolve({ code, signal: signal ?? forwardedSignal }));\n });\n await writeAtomic(exitPath, { ...result, ...(ownerLost ? OWNER_LOST_EXIT : {}) });\n if (ownerLost) await cleanupOwnerSession(spec);\n return result.code !== null ? result.code : result.signal ? 128 + os.constants.signals[result.signal] : 1;\n } finally {\n detachLifeline();\n if (escalationTimer) clearTimeout(escalationTimer);\n }\n}\n\n/** The backend supplies an exact kill-session argv, never a shared-server shutdown. */\nasync function cleanupOwnerSession(spec: CommandSpec): Promise<void> {\n const [binary, ...args] = spec.ownerLostCleanup ?? [];\n if (!binary) return;\n await new Promise<void>((resolve, reject) => {\n execFile(binary, args, { env: spec.env, timeout: 10_000 }, (error) => {\n if (error) reject(error);\n else resolve();\n });\n });\n}\n\nasync function readSpec(target: string): Promise<CommandSpec> {\n const value: unknown = JSON.parse(await fs.readFile(target, 'utf8'));\n if (typeof value !== 'object' || value === null) throw new Error(INVALID_COMMAND_SPEC_ERROR);\n const spec = value as Partial<CommandSpec>;\n if (typeof spec.command !== 'string' || typeof spec.cwd !== 'string' || !spec.env) {\n throw new Error(INVALID_COMMAND_SPEC_ERROR);\n }\n return { command: spec.command, cwd: spec.cwd, env: spec.env, ownerLostCleanup: spec.ownerLostCleanup };\n}\n\n/** False once the owner is gone, since only the owner opens the gate. */\nasync function waitForGate(target: string, abandoned: () => boolean): Promise<boolean> {\n while (!abandoned()) {\n try {\n await fs.access(target);\n return true;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;\n }\n await new Promise((resolve) => setTimeout(resolve, POLL_MS));\n }\n return false;\n}\n\nasync function writeAtomic(target: string, value: unknown): Promise<void> {\n const temporary = `${target}.${process.pid}.tmp`;\n await fs.writeFile(temporary, `${JSON.stringify(value)}\\n`, { mode: 0o600 });\n await fs.rename(temporary, target);\n}\n\nif (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {\n main().then(\n (code) => {\n process.exitCode = code;\n },\n (error: unknown) => {\n process.stderr.write(`${error instanceof Error ? error.message : String(error)}\\n`);\n process.exitCode = 1;\n },\n );\n}\n\n/** Loaded on the first session an owner leaves behind, then shared by every later one. */\nlet cleaner: Promise<(watch: LifelineWatch) => Promise<void>> | undefined;\nlet telemetry: Promise<PoTelemetry> | undefined;\n\n/**\n * A separate process survives SIGKILL of the owner, even if that session has no active runners.\n * The owner cleans up each session it ends with its own shared services and removes its marker,\n * so only a session still marked with its generation is left here; the rest load nothing.\n */\nasync function cleanupSessions(watches: readonly LifelineWatch[]): Promise<void> {\n const failures: { watch: LifelineWatch; error: unknown }[] = [];\n // One session failing to clean up must not stop the others.\n for (const watch of watches) {\n try {\n // The same fence cleanupRunnerSession applies, checked before anything loads for it.\n if ((await readMarker(watch.marker)) !== watch.generation) continue;\n const clean = await (cleaner ??= loadCleaner());\n await clean(watch);\n } catch (error) {\n failures.push({ watch, error });\n }\n }\n const [first] = failures;\n if (!first) return;\n const log = await (telemetry ??= loadTelemetry(first.watch.environment));\n for (const { watch, error } of failures) {\n await log.recordError(\n 'po_runner.observer_cleanup_failed',\n error,\n { 'session.id': watch.sessionId },\n { includeException: true },\n );\n }\n await log.flush();\n throw new AggregateError(\n failures.map(({ error }) => error),\n `Could not clean up runner sessions ${failures.map(({ watch }) => watch.sessionId).join(', ')}`,\n );\n}\n\nasync function readMarker(marker: string): Promise<string | undefined> {\n try {\n return await fs.readFile(marker, 'utf8');\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined;\n throw error;\n }\n}\n\n/** One registry per registry path, held until the observer runs out of work. */\nasync function loadCleaner(): Promise<(watch: LifelineWatch) => Promise<void>> {\n const [{ cleanupRunnerSession }, { RunnerPaths }, { createDefaultProcessRegistry }] = await Promise.all([\n import('../services/runnerHost'),\n import('../services/runnerPaths'),\n import('../services/runnerRegistry'),\n ]);\n const registries = new Map<string | undefined, ProcessRegistryPort>();\n process.once('beforeExit', () => {\n for (const registry of registries.values()) registry.close();\n });\n return (watch) => {\n const registryPath = watch.environment[REGISTRY_PATH_ENV];\n let registry = registries.get(registryPath);\n if (!registry) {\n registry = createDefaultProcessRegistry(watch.environment);\n registries.set(registryPath, registry);\n }\n return cleanupRunnerSession({\n sessionId: watch.sessionId,\n paths: new RunnerPaths(watch.repository, watch.environment),\n processRegistry: registry,\n ownerPid: watch.ownerPid,\n generation: watch.generation,\n });\n };\n}\n\nasync function loadTelemetry(environment: LifelineWatch['environment']): Promise<PoTelemetry> {\n const { createPoTelemetry } = await import('@agimon-ai/po-core/telemetry');\n const shared = createPoTelemetry({\n serviceName: 'po-runner-host',\n packageName: '@agimon-ai/po-runner',\n env: environment,\n enableLogs: true,\n });\n process.once('beforeExit', () => void shared.shutdown());\n return shared;\n}\n"],"mappings":";;;;;;;;AAwBA,MAAM,UAAU;AAChB,MAAM,4BAA4B;AAClC,MAAM,6BAA6B;AACnC,MAAM,kBAAkB;CAAE,QAAQ;CAAW,mBAAmB;CAAc,YAAY;AAAsB;AAEhH,eAAsB,KAAK,OAA0B,QAAQ,KAAK,MAAM,CAAC,GAAoB;CAC3F,IAAI,KAAK,OAAA,sBAA8B;EACrC,gBAAgB,eAAe;EAC/B,OAAO;CACT;CACA,MAAM,CAAC,UAAU,UAAU,YAAY;CACvC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,UAAU,MAAM,IAAI,MAAM,gDAAgD;CACzG,MAAM,OAAO,MAAM,SAAS,QAAQ;CACpC,IAAI,YAAY;CAChB,IAAI,oBAA0B,KAAA;CAO9B,MAAM,iBAAiB,iBAAiB;EACtC,YAAY;EACZ,YAAY;CACd,GAAG,KAAK,IAAI,aAAa;CACzB,IAAI,CAAE,MAAM,YAAY,gBAAgB,SAAS,GAAI;EACnD,eAAe;EACf,MAAM,YAAY,UAAU;GAAE,MAAM;GAAM,QAAQ;GAAM,GAAG;EAAgB,CAAC;EAC5E,MAAM,oBAAoB,IAAI;EAC9B,OAAO;CACT;CACA,IAAI;CACJ,IAAI,kBAAyC;CAC7C,IAAI;CACJ,MAAM,eAAe,WAAiC;EACpD,IAAI,CAAC,OAAO,KAAK;EAC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IAAI,CAAC,UAAU;GACb,WAAW,6BAA6B,MAAM,WAAW;GACzD,WAAW,IAAI,cAAc,QAAQ;EACvC;EACA,OAAO,qBAAqB;GAC1B,WAAW,MAAM;GACjB,OAAO,IAAI,YAAY,MAAM,YAAY,MAAM,WAAW;GAC1D,iBAAiB;GACjB,UAAU,MAAM;GAChB,YAAY,MAAM;EACpB,CAAC;CACH;AACF;AAEA,eAAe,cAAc,aAAiE;CAC5F,MAAM,EAAE,sBAAsB,MAAM,OAAO;CAC3C,MAAM,SAAS,kBAAkB;EAC/B,aAAa;EACb,aAAa;EACb,KAAK;EACL,YAAY;CACd,CAAC;CACD,QAAQ,KAAK,oBAAoB,KAAK,OAAO,SAAS,CAAC;CACvD,OAAO;AACT"}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_bashResult = require("./bashResult-CZYiyl4p.cjs");
|
|
3
|
+
const require_reconcile = require("./reconcile-DjF9T1hN.cjs");
|
|
4
|
+
const require_runnerSequenceStore = require("./runnerSequenceStore-Ck6M-8r_.cjs");
|
|
5
|
+
const require_session = require("./session-PQd3azWf.cjs");
|
|
6
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
|
+
let _agimon_ai_po_core_locale = require("@agimon-ai/po-core/locale");
|
|
8
|
+
let node_fs = require("node:fs");
|
|
9
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
10
|
+
const STOPPED_REASON = "stopped";
|
|
11
|
+
const TERMINATION_SIGNAL = "SIGTERM";
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/services/cliApp/index.ts
|
|
14
|
+
const englishCliText = (_key, fallback, vars) => (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars);
|
|
15
|
+
const MULTIPLEXER_BACKENDS = /* @__PURE__ */ new Set(["rmux", "tmux"]);
|
|
16
|
+
async function runCli(argv, dependencies) {
|
|
17
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
18
|
+
const [command, ...args] = argv;
|
|
19
|
+
if (command !== void 0 && command !== "--help" && command !== "-h" && !require_session.inheritedSessionId(dependencies.env)) {
|
|
20
|
+
dependencies.stderr(cliText("runner.cli.sessionRequired", "PO_SESSION_ID is required for po-runner commands"));
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
if (command && args[0] && require_runnerSequenceStore.isSequenceId(args[0])) return sequenceCommand(command, args, dependencies);
|
|
24
|
+
switch (command) {
|
|
25
|
+
case "list": return list(args, dependencies);
|
|
26
|
+
case "status": return status(args, dependencies);
|
|
27
|
+
case "logs": return logs(args, dependencies);
|
|
28
|
+
case "stop": return stop(args, dependencies);
|
|
29
|
+
case "stop-all": return stopAll(args, dependencies);
|
|
30
|
+
case "input": return input(args, dependencies);
|
|
31
|
+
case "--help":
|
|
32
|
+
case "-h":
|
|
33
|
+
case void 0:
|
|
34
|
+
dependencies.stdout(runnerCliHelp(cliText));
|
|
35
|
+
return 0;
|
|
36
|
+
default:
|
|
37
|
+
dependencies.stderr(cliText("runner.cli.unknownCommand", "Unknown command: {command}\n\n{help}", {
|
|
38
|
+
command,
|
|
39
|
+
help: runnerCliHelp(cliText)
|
|
40
|
+
}));
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function sequenceCommand(command, args, dependencies) {
|
|
45
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
46
|
+
const store = dependencies.sequences;
|
|
47
|
+
if (!store) {
|
|
48
|
+
dependencies.stderr(cliText("runner.cli.sequenceUnavailable", "Sequence controls are unavailable."));
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
const record = await store.get(args[0]);
|
|
52
|
+
if (!record) {
|
|
53
|
+
dependencies.stderr(cliText("runner.cli.sequenceMissing", "No sequence with id {id}", { id: args[0] }));
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
if (command === "stop") {
|
|
57
|
+
if (record.state !== "running") {
|
|
58
|
+
dependencies.stderr(cliText("runner.cli.sequenceCompleted", "Sequence {id} is already completed", { id: record.id }));
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
await store.requestStop(record.id, option(args, "--reason"));
|
|
62
|
+
dependencies.stdout(cliText("runner.cli.sequenceStop", "Stop requested for sequence {id}", { id: record.id }));
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
65
|
+
if (command === "status") {
|
|
66
|
+
dependencies.stdout([
|
|
67
|
+
cliText("runner.cli.labelId", "ID: {value}", { value: record.id }),
|
|
68
|
+
cliText("runner.cli.labelName", "Name: {value}", { value: record.name }),
|
|
69
|
+
cliText("runner.cli.labelState", "State: {value}", { value: record.state }),
|
|
70
|
+
cliText("runner.cli.labelSession", "Session: {value}", { value: record.sessionId }),
|
|
71
|
+
...record.outcome ? [cliText("runner.cli.labelOutcome", "Outcome: {value}", { value: record.outcome })] : [],
|
|
72
|
+
...record.stages.map((stage) => cliText("runner.cli.stage", "Stage {index}: {state}{id}", {
|
|
73
|
+
index: stage.index + 1,
|
|
74
|
+
state: stage.state,
|
|
75
|
+
id: stage.id ? ` (${stage.id})` : ""
|
|
76
|
+
}))
|
|
77
|
+
].join("\n"));
|
|
78
|
+
return 0;
|
|
79
|
+
}
|
|
80
|
+
if (command === "logs") {
|
|
81
|
+
if (args.includes("--follow")) {
|
|
82
|
+
dependencies.stderr(cliText("runner.cli.sequenceLogs", "Sequence logs are finite snapshots; inspect status before reading again."));
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
if (record.result) dependencies.stdout(record.result.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n"));
|
|
86
|
+
else dependencies.stdout([cliText("runner.cli.sequenceRunning", "Sequence {id} is running.", { id: record.id }), ...record.stages.filter((stage) => stage.logPath).map((stage) => `${stage.index + 1}. ${stage.logPath}`)].join("\n"));
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
89
|
+
dependencies.stderr(command === "input" ? cliText("runner.cli.sequenceNoninteractive", "Command sequences are noninteractive.") : cliText("runner.cli.sequenceUnknown", "Unknown sequence command: {command}", { command }));
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
async function list(args, dependencies) {
|
|
93
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
94
|
+
const sessionId = require_session.requiredSessionId(dependencies.env);
|
|
95
|
+
const records = args.includes("--all") ? await dependencies.registry.listAll(sessionId) : await dependencies.registry.listBySession(sessionId);
|
|
96
|
+
const sequences = await dependencies.sequences?.list(args.includes("--all")) ?? [];
|
|
97
|
+
const rows = [...records.map((record) => formatRecord(record, cliText)), ...sequences.map((record) => `${record.id} ${record.state} sequence ${record.name}`)];
|
|
98
|
+
dependencies.stdout(rows.length > 0 ? rows.join("\n") : cliText("runner.cli.empty", "No runners"));
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
async function status(args, dependencies) {
|
|
102
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
103
|
+
const record = await requiredRecord(args[0], dependencies);
|
|
104
|
+
if (!record) return 1;
|
|
105
|
+
dependencies.stdout([
|
|
106
|
+
cliText("runner.cli.labelId", "ID: {value}", { value: record.id }),
|
|
107
|
+
cliText("runner.cli.labelName", "Name: {value}", { value: record.name }),
|
|
108
|
+
cliText("runner.cli.labelState", "State: {value}", { value: record.state }),
|
|
109
|
+
cliText("runner.cli.labelBackend", "Backend: {value}", { value: record.backend }),
|
|
110
|
+
...record.backendTarget ? [cliText("runner.cli.labelBackendTarget", "Backend target: {value}", { value: record.backendTarget })] : [],
|
|
111
|
+
cliText("runner.cli.labelPid", "PID: {value}", { value: record.pid }),
|
|
112
|
+
cliText("runner.cli.labelCommand", "Command: {value}", { value: record.command }),
|
|
113
|
+
cliText("runner.cli.labelCwd", "CWD: {value}", { value: record.cwd }),
|
|
114
|
+
cliText("runner.cli.labelSession", "Session: {value}", { value: record.sessionId }),
|
|
115
|
+
cliText("runner.cli.labelLog", "Log: {value}", { value: record.logPath }),
|
|
116
|
+
...record.exit ? [cliText("runner.cli.labelExit", "Exit: {value}", { value: formatExit(record) })] : []
|
|
117
|
+
].join("\n"));
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
async function logs(args, dependencies) {
|
|
121
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
122
|
+
const record = await requiredRecord(args[0], dependencies);
|
|
123
|
+
if (!record) return 1;
|
|
124
|
+
const lines = positiveInteger(option(args, "--lines")) ?? 200;
|
|
125
|
+
const result = await dependencies.logReader.read(record.logPath, { lines });
|
|
126
|
+
if (!result.exists) {
|
|
127
|
+
dependencies.stderr(cliText("runner.cli.noLog", "Runner {id} has not written a log yet", { id: record.id }));
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
if (result.text) dependencies.stdout(result.text);
|
|
131
|
+
if (!args.includes("--follow")) return 0;
|
|
132
|
+
return follow(record, result.fileSize, dependencies);
|
|
133
|
+
}
|
|
134
|
+
async function stop(args, dependencies) {
|
|
135
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
136
|
+
const record = await requiredRecord(args[0], dependencies);
|
|
137
|
+
if (!record) return 1;
|
|
138
|
+
if (record.state !== "running") {
|
|
139
|
+
dependencies.stderr(cliText("runner.cli.alreadyState", "Runner {id} is already {state}", {
|
|
140
|
+
id: record.id,
|
|
141
|
+
state: record.state
|
|
142
|
+
}));
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
const reason = option(args, "--reason");
|
|
146
|
+
if (!await stopRecord(record, dependencies, reason)) {
|
|
147
|
+
dependencies.stderr(cliText("runner.cli.stopFailed", "Could not stop runner {id}", { id: record.id }));
|
|
148
|
+
return 1;
|
|
149
|
+
}
|
|
150
|
+
await dependencies.registry.complete(record.id, {
|
|
151
|
+
reason: STOPPED_REASON,
|
|
152
|
+
code: null,
|
|
153
|
+
signal: TERMINATION_SIGNAL,
|
|
154
|
+
...reason ? { stopReason: reason } : {}
|
|
155
|
+
}, record.sessionId);
|
|
156
|
+
dependencies.stdout(cliText("runner.cli.stopped", "Stopped {id}\nLog: {path}", {
|
|
157
|
+
id: record.id,
|
|
158
|
+
path: record.logPath
|
|
159
|
+
}));
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
async function stopAll(args, dependencies) {
|
|
163
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
164
|
+
const sessionId = require_session.requiredSessionId(dependencies.env);
|
|
165
|
+
const records = await dependencies.registry.listBySession(sessionId);
|
|
166
|
+
const reason = option(args, "--reason");
|
|
167
|
+
for (const sequence of await dependencies.sequences?.list() ?? []) {
|
|
168
|
+
await dependencies.sequences.requestStop(sequence.id, reason);
|
|
169
|
+
dependencies.stdout(cliText("runner.cli.sequenceStop", "Stop requested for sequence {id}", { id: sequence.id }));
|
|
170
|
+
}
|
|
171
|
+
const stopped = [];
|
|
172
|
+
for (const record of records) {
|
|
173
|
+
if (!await stopRecord(record, dependencies, reason)) continue;
|
|
174
|
+
await dependencies.registry.complete(record.id, {
|
|
175
|
+
reason: STOPPED_REASON,
|
|
176
|
+
code: null,
|
|
177
|
+
signal: TERMINATION_SIGNAL,
|
|
178
|
+
...reason ? { stopReason: reason } : {}
|
|
179
|
+
}, record.sessionId);
|
|
180
|
+
stopped.push(record);
|
|
181
|
+
}
|
|
182
|
+
dependencies.stdout(records.length === 0 ? cliText("runner.cli.noActive", "No active runners for session {session}", { session: sessionId }) : cliText("runner.cli.stoppedMany", "Stopped {count} runner(s) for session {session}: {ids}", {
|
|
183
|
+
count: stopped.length,
|
|
184
|
+
session: sessionId,
|
|
185
|
+
ids: stopped.map((record) => record.id).join(", ")
|
|
186
|
+
}));
|
|
187
|
+
if (stopped.length !== records.length) {
|
|
188
|
+
dependencies.stderr(cliText("runner.cli.stopManyFailed", "Could not stop {count} runner(s) for session {session}", {
|
|
189
|
+
count: records.length - stopped.length,
|
|
190
|
+
session: sessionId
|
|
191
|
+
}));
|
|
192
|
+
return 1;
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
async function input(args, dependencies) {
|
|
197
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
198
|
+
const record = await requiredRecord(args[0], dependencies);
|
|
199
|
+
if (!record) return 1;
|
|
200
|
+
if (record.state === "completed") {
|
|
201
|
+
dependencies.stderr(cliText("runner.cli.completed", "Runner {id} is already completed; use po-runner logs {id}", { id: record.id }));
|
|
202
|
+
return 1;
|
|
203
|
+
}
|
|
204
|
+
if (!record.interactive) {
|
|
205
|
+
dependencies.stderr(cliText("runner.cli.notInteractive", "Runner {id} was not started with interactive: true", { id: record.id }));
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
const text = option(args, "--text") ?? await dependencies.readStdin();
|
|
209
|
+
const payload = args.includes("--enter") && !text.endsWith("\n") ? `${text}\n` : text;
|
|
210
|
+
if (!MULTIPLEXER_BACKENDS.has(record.backend) || !record.backendTarget) {
|
|
211
|
+
dependencies.stderr(cliText("runner.cli.noInput", "Runner {id} uses the {backend} backend, which does not expose CLI input", {
|
|
212
|
+
id: record.id,
|
|
213
|
+
backend: record.backend
|
|
214
|
+
}));
|
|
215
|
+
return 1;
|
|
216
|
+
}
|
|
217
|
+
if (!await dependencies.rmuxBackend.input(record.backendTarget, payload)) {
|
|
218
|
+
dependencies.stderr(cliText("runner.cli.inputClosed", "Runner {id} is no longer accepting RMUX input", { id: record.id }));
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
dependencies.stdout(cliText("runner.cli.inputSent", "Sent input to {id}", { id: record.id }));
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
async function requiredRecord(id, dependencies) {
|
|
225
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
226
|
+
if (!id) {
|
|
227
|
+
dependencies.stderr(cliText("runner.cli.idRequired", "A runner ID is required"));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const sessionId = require_session.requiredSessionId(dependencies.env);
|
|
231
|
+
const scopedRecord = await dependencies.registry.get(id, sessionId);
|
|
232
|
+
if (!scopedRecord) {
|
|
233
|
+
dependencies.stderr(cliText("runner.cli.missing", "No runner with id {id}", { id }));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
return scopedRecord;
|
|
237
|
+
}
|
|
238
|
+
function formatRecord(record, cliText) {
|
|
239
|
+
const active = cliText("runner.cli.activeLine", "{name} pid {pid} up {uptime}{mode} {command}", {
|
|
240
|
+
name: record.name,
|
|
241
|
+
pid: record.pid,
|
|
242
|
+
uptime: require_bashResult.formatUptime(record.startedAt, Date.now()),
|
|
243
|
+
mode: record.interactive ? cliText("runner.cli.interactive", " interactive") : "",
|
|
244
|
+
command: record.command
|
|
245
|
+
});
|
|
246
|
+
return `${record.id} ${record.state} ${record.backend} ${active}`;
|
|
247
|
+
}
|
|
248
|
+
function formatExit(record) {
|
|
249
|
+
const exit = record.exit;
|
|
250
|
+
if (!exit) return "unknown";
|
|
251
|
+
const detail = exit.code !== null ? ` code ${exit.code}` : exit.signal ? ` ${exit.signal}` : "";
|
|
252
|
+
const attribution = exit.terminationReason ? ` [${exit.terminationReason}]` : "";
|
|
253
|
+
const note = exit.stopReason ? ` (${exit.stopReason})` : "";
|
|
254
|
+
return `${exit.reason}${detail}${attribution}${note}`;
|
|
255
|
+
}
|
|
256
|
+
function option(args, name) {
|
|
257
|
+
const index = args.indexOf(name);
|
|
258
|
+
return index >= 0 ? args[index + 1] : void 0;
|
|
259
|
+
}
|
|
260
|
+
function positiveInteger(value) {
|
|
261
|
+
if (value === void 0) return void 0;
|
|
262
|
+
const parsed = Number(value);
|
|
263
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
264
|
+
}
|
|
265
|
+
async function follow(record, initialSize, dependencies) {
|
|
266
|
+
const cliText = dependencies.translate ?? englishCliText;
|
|
267
|
+
let offset = initialSize;
|
|
268
|
+
return new Promise((resolve) => {
|
|
269
|
+
let stopped = false;
|
|
270
|
+
let stateTimer;
|
|
271
|
+
let reads = Promise.resolve();
|
|
272
|
+
const drain = async (current) => {
|
|
273
|
+
if (current.size < offset) offset = 0;
|
|
274
|
+
if (current.size === offset) return;
|
|
275
|
+
const length = current.size - offset;
|
|
276
|
+
const buffer = Buffer.alloc(length);
|
|
277
|
+
const descriptor = await (0, node_fs_promises.open)(record.logPath, "r");
|
|
278
|
+
try {
|
|
279
|
+
const { bytesRead } = await descriptor.read(buffer, 0, length, offset);
|
|
280
|
+
if (bytesRead > 0) dependencies.stdout(buffer.subarray(0, bytesRead).toString("utf8"));
|
|
281
|
+
offset += bytesRead;
|
|
282
|
+
} finally {
|
|
283
|
+
await descriptor.close();
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
const report = (error) => {
|
|
287
|
+
if (error.code !== "ENOENT") dependencies.stderr(cliText("runner.cli.flushFailed", "Runner {id} failed to flush its final log output: {error}", {
|
|
288
|
+
id: record.id,
|
|
289
|
+
error: String(error)
|
|
290
|
+
}));
|
|
291
|
+
};
|
|
292
|
+
const listener = (current) => {
|
|
293
|
+
if (stopped) return;
|
|
294
|
+
reads = reads.then(() => drain(current)).catch(report);
|
|
295
|
+
};
|
|
296
|
+
const stopFollowing = () => {
|
|
297
|
+
if (stopped) return;
|
|
298
|
+
stopped = true;
|
|
299
|
+
node_fs.default.unwatchFile(record.logPath, listener);
|
|
300
|
+
clearInterval(stateTimer);
|
|
301
|
+
process.off("SIGINT", stopFollowing);
|
|
302
|
+
reads = reads.then(async () => drain(await (0, node_fs_promises.stat)(record.logPath))).catch(report);
|
|
303
|
+
reads.then(() => resolve(0));
|
|
304
|
+
};
|
|
305
|
+
process.once("SIGINT", stopFollowing);
|
|
306
|
+
node_fs.default.watchFile(record.logPath, { interval: 250 }, listener);
|
|
307
|
+
stateTimer = setInterval(() => {
|
|
308
|
+
dependencies.registry.get(record.id).then((current) => {
|
|
309
|
+
if (current?.state === "completed") stopFollowing();
|
|
310
|
+
});
|
|
311
|
+
}, 250);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async function stopRecord(record, dependencies, reason) {
|
|
315
|
+
return require_reconcile.stopRunnerProcess(record, dependencies.launcher, dependencies.rmuxBackend, {
|
|
316
|
+
registry: dependencies.registry,
|
|
317
|
+
intent: {
|
|
318
|
+
reason: STOPPED_REASON,
|
|
319
|
+
terminationReason: "user_stop",
|
|
320
|
+
...reason ? { stopReason: reason } : {}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function runnerCliHelp(cliText = englishCliText) {
|
|
325
|
+
return [
|
|
326
|
+
cliText("runner.cli.usage", "Usage: po-runner <command>"),
|
|
327
|
+
"",
|
|
328
|
+
cliText("runner.cli.commands", "Commands:"),
|
|
329
|
+
" list [--all]",
|
|
330
|
+
" status <id>",
|
|
331
|
+
" logs <id> [--lines N] [--follow]",
|
|
332
|
+
" stop <id> [--reason <text>]",
|
|
333
|
+
" stop-all [--reason <text>]",
|
|
334
|
+
" input <id> [--text <text>] [--enter]"
|
|
335
|
+
].join("\n");
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
Object.defineProperty(exports, "runCli", {
|
|
339
|
+
enumerable: true,
|
|
340
|
+
get: function() {
|
|
341
|
+
return runCli;
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
Object.defineProperty(exports, "runnerCliHelp", {
|
|
345
|
+
enumerable: true,
|
|
346
|
+
get: function() {
|
|
347
|
+
return runnerCliHelp;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
//# sourceMappingURL=cliApp-7iTUx5KZ.cjs.map
|