@agimon-ai/po-runner 0.0.0-alpha.21 → 0.0.0-alpha.210
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
|
@@ -1,21 +1,34 @@
|
|
|
1
|
-
import { c as getLogTtlMs } from "../runnerConfig-XXMq4VQA.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
1
|
+
import { c as getLogTtlMs, t as getBackgroundThresholdMs } from "../runnerConfig-XXMq4VQA.mjs";
|
|
2
|
+
import { i as SEQUENCE_PREFIX, t as MAX_SEQUENCE_COMMAND_LENGTH } from "../runnerSequence-k-_Fd77y.mjs";
|
|
3
|
+
import { r as BashParamsSchema } from "../bashTool-vg8uhbkj.mjs";
|
|
4
|
+
import { d as formatRunResult, h as parseResultPragma, i as boundExcerpt, n as bashFailureError, r as bashFailureReason, t as bashFailure } from "../bashResult-BLCLerXE.mjs";
|
|
5
|
+
import { r as summarizeLog, t as LogReader } from "../logReader-BYKii_s_.mjs";
|
|
6
|
+
import { n as createHeadlessRunnersCommand, t as createHeadlessBashTool } from "../headless-CUJt5Ihx.mjs";
|
|
7
|
+
import { n as stopRunnerProcess, t as reconcileActiveRunners } from "../reconcile-DUaX_vKZ.mjs";
|
|
8
|
+
import { n as isSequenceId, t as createRunnerSequenceStore } from "../runnerSequenceStore-CaY7S_Sd.mjs";
|
|
5
9
|
import { t as SystemClock } from "../clock-Cv2pddgo.mjs";
|
|
6
10
|
import { t as activeRunnerRecovery } from "../compaction-nNlE6e5I.mjs";
|
|
7
|
-
import { t as RmuxBackend } from "../rmuxBackend-
|
|
8
|
-
import { n as TERM_GRACE_MS } from "../launcher-
|
|
9
|
-
import {
|
|
10
|
-
import { n as
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
11
|
+
import { t as RmuxBackend } from "../rmuxBackend-BaK-R35I.mjs";
|
|
12
|
+
import { n as TERM_GRACE_MS } from "../launcher-3xMxw72I.mjs";
|
|
13
|
+
import { t as LifelineObserver } from "../lifeline-C1v2ItCY.mjs";
|
|
14
|
+
import { n as TmuxBackend, r as PtyBackendChain, t as createRunnerDependencies } from "../runnerDependencies-DmvIcpZi.mjs";
|
|
15
|
+
import { i as runnerStateDirFor, n as resolveRunnerStoreDirectory, t as RunnerPaths } from "../runnerPaths-D3P7_EhW.mjs";
|
|
16
|
+
import "../runnerRegistry-l0C_55oO.mjs";
|
|
17
|
+
import { a as formatRunnerFinishedNotice, i as formatRunnerFinished, n as createDefaultProcessRegistry, o as formatRunnerStatus, s as isRunnerRecord } from "../runnerRegistry-Dqca6SD3.mjs";
|
|
18
|
+
import { n as createRunnerLaunch, t as PO_RUNNER_LAUNCH_SERVICE } from "../runnerLaunch-Bimgdh4h.mjs";
|
|
19
|
+
import { n as createRunnerHost, t as cleanupRunnerSession } from "../runnerHost-BvNYPMeh.mjs";
|
|
20
|
+
import fs from "node:fs/promises";
|
|
13
21
|
import path from "node:path";
|
|
14
|
-
import {
|
|
22
|
+
import { formatMessage, readPoLang, readPoPersonLocale } from "@agimon-ai/po-core/locale";
|
|
23
|
+
import { BACKGROUND_CONTEXT, PO_SESSION_TEMP_DIR, readPoFs, readTextIfExists } from "@agimon-ai/po-core/platform";
|
|
15
24
|
import { composeServerProviderOverrides, defineServerPlugin, packageResourcePath, readPackageResource } from "@agimon-ai/po-core/serverPlugin";
|
|
16
25
|
import { composeRootHooks, composeRootInjects, defineChannel, defineHook, defineResource, defineRoot, defineRoute, defineServerCommand, defineServerTool, runCleanups } from "@agimon-ai/po-core/extensionFile";
|
|
17
|
-
import {
|
|
18
|
-
import { createPoTelemetry } from "@agimon-ai/po-telemetry";
|
|
26
|
+
import { PO_CODEMODE_SERVICE, readPoCodemode } from "@agimon-ai/po-core/codemode";
|
|
27
|
+
import { createPoTelemetry } from "@agimon-ai/po-core/telemetry";
|
|
28
|
+
import { readPoWorkflowContextService } from "@agimon-ai/po-core/workflow";
|
|
29
|
+
import { BACKGROUND_SERVICE_STATUS, PO_BACKGROUND_WORK_SERVICE, readPoBackgroundWorkService } from "@agimon-ai/po-core/backgroundWork";
|
|
30
|
+
import { Value } from "typebox/value";
|
|
31
|
+
import { resolveRootSessionId } from "@agimon-ai/po-core/childProcess";
|
|
19
32
|
import { CONFIG_DIR_NAME } from "@earendil-works/pi-coding-agent";
|
|
20
33
|
import { Hono } from "hono";
|
|
21
34
|
import { streamSSE } from "hono/streaming";
|
|
@@ -31,107 +44,630 @@ const MAX_RESULT_BYTES_CEILING = 262144;
|
|
|
31
44
|
const MAX_RESULT_LINES_CEILING = 5e3;
|
|
32
45
|
const MAX_RESULT_TOKENS_CEILING = 1e5;
|
|
33
46
|
//#endregion
|
|
34
|
-
//#region src/
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
//#region src/constants/runnerLogApi.ts
|
|
48
|
+
const LOG_DIR_NAME = "logs";
|
|
49
|
+
const STATE_EXTENSION = ".json";
|
|
50
|
+
const RUNNING_STATE = "running";
|
|
51
|
+
const STATE_POLL_MS = 1e3;
|
|
52
|
+
const HEARTBEAT_MS = 15e3;
|
|
53
|
+
const MAX_LINES = 5e3;
|
|
54
|
+
const SAFE_SEGMENT = /^[\w.@-]+$/;
|
|
55
|
+
const RAW_LOG_SUFFIX = ".raw";
|
|
56
|
+
const MAX_INPUT_CHARS = 4096;
|
|
57
|
+
/** Ceiling for one finite log/screen read, before base64 encoding. */
|
|
58
|
+
const MAX_OUTPUT_BYTES = 65536;
|
|
59
|
+
const NOT_ATTACHABLE = "No attachable runner by that name in this session.";
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/services/runnerOperations/index.ts
|
|
62
|
+
function runnerId(value) {
|
|
63
|
+
if (typeof value !== "string" || value.length > 256 || value === "." || value === ".." || !SAFE_SEGMENT.test(value)) throw new Error("id must be a non-empty runner ID, not a path.");
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
/** Session-owned controls shared by native code mode and the CLI. */
|
|
67
|
+
function createRunnerOperations(options) {
|
|
68
|
+
const { sessionId, registry } = options;
|
|
69
|
+
if (!sessionId) throw new Error("Runner controls require a session.");
|
|
70
|
+
const owned = (record) => {
|
|
71
|
+
runnerId(record.id);
|
|
72
|
+
if (record.sessionId !== sessionId) throw new Error("Runner belongs to another session.");
|
|
73
|
+
return record;
|
|
74
|
+
};
|
|
75
|
+
const status = async (id) => {
|
|
76
|
+
runnerId(id);
|
|
77
|
+
const record = await registry.get(id, sessionId);
|
|
78
|
+
if (!record || record.id !== id) throw new Error(`No runner with id ${id} in this session.`);
|
|
79
|
+
return owned(record);
|
|
80
|
+
};
|
|
81
|
+
const list = async (all = false) => (await (all ? registry.listAll(sessionId) : registry.listBySession(sessionId))).map(owned);
|
|
82
|
+
const stop = async (id, reason, assertAvailable = () => void 0) => {
|
|
83
|
+
const record = await status(id);
|
|
84
|
+
assertAvailable();
|
|
85
|
+
if (record.state !== "running") return {
|
|
86
|
+
id,
|
|
87
|
+
stopped: false,
|
|
88
|
+
reason: "Runner is already completed."
|
|
89
|
+
};
|
|
90
|
+
const stopped = await stopRunnerProcess(record, options.launcher, options.rmuxBackend, {
|
|
91
|
+
registry,
|
|
92
|
+
intent: {
|
|
93
|
+
reason: "stopped",
|
|
94
|
+
terminationReason: "user_stop",
|
|
95
|
+
...reason ? { stopReason: reason } : {}
|
|
96
|
+
}
|
|
48
97
|
});
|
|
98
|
+
if (stopped) await registry.complete(id, {
|
|
99
|
+
reason: "stopped",
|
|
100
|
+
code: null,
|
|
101
|
+
signal: "SIGTERM",
|
|
102
|
+
...reason ? { stopReason: reason } : {}
|
|
103
|
+
}, sessionId);
|
|
104
|
+
return {
|
|
105
|
+
id,
|
|
106
|
+
stopped
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
list,
|
|
111
|
+
status,
|
|
112
|
+
async logs(id, query = {}, assertAvailable = () => void 0) {
|
|
113
|
+
const record = await status(id);
|
|
114
|
+
assertAvailable();
|
|
115
|
+
const expected = options.paths.logPathFor(id, sessionId);
|
|
116
|
+
if (record.logPath !== expected) throw new Error("Runner log is outside its admitted session path.");
|
|
117
|
+
const exists = await options.fs.exists(expected, BACKGROUND_CONTEXT);
|
|
118
|
+
if (!exists.ok) throw exists.error;
|
|
119
|
+
if (exists.value) {
|
|
120
|
+
const [root, file] = await Promise.all([options.fs.canonicalPath(options.paths.logDirectory(sessionId), BACKGROUND_CONTEXT), options.fs.canonicalPath(expected, BACKGROUND_CONTEXT)]);
|
|
121
|
+
if (!root.ok) throw root.error;
|
|
122
|
+
if (!file.ok) throw file.error;
|
|
123
|
+
if (!file.value.startsWith(`${root.value.replace(/\/$/u, "")}/`)) throw new Error("Runner log resolves outside its session.");
|
|
124
|
+
}
|
|
125
|
+
const lines = query.lines ?? 200;
|
|
126
|
+
if (!Number.isInteger(lines) || lines < 1 || lines > 5e3) throw new Error(`lines must be an integer between 1 and ${MAX_LINES}.`);
|
|
127
|
+
if (query.contextLines !== void 0 && (!Number.isInteger(query.contextLines) || query.contextLines < 0 || query.contextLines > 5e3)) throw new Error(`contextLines must be an integer between 0 and ${MAX_LINES}.`);
|
|
128
|
+
assertAvailable();
|
|
129
|
+
const slice = await options.logReader.read(expected, {
|
|
130
|
+
...query,
|
|
131
|
+
lines
|
|
132
|
+
});
|
|
133
|
+
const bounded = boundExcerpt(slice.text, lines, MAX_OUTPUT_BYTES);
|
|
134
|
+
const { lineNumbers, ...metadata } = slice;
|
|
135
|
+
return {
|
|
136
|
+
...metadata,
|
|
137
|
+
text: bounded.text,
|
|
138
|
+
lineCount: bounded.lines,
|
|
139
|
+
truncated: slice.truncated || bounded.truncated || slice.lineCount < slice.totalLines,
|
|
140
|
+
...lineNumbers && !bounded.truncated ? { lineNumbers } : {}
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
stop,
|
|
144
|
+
async stopAll(reason, assertAvailable = () => void 0) {
|
|
145
|
+
const results = [];
|
|
146
|
+
for (const record of await list()) {
|
|
147
|
+
assertAvailable();
|
|
148
|
+
try {
|
|
149
|
+
results.push(await stop(record.id, reason, assertAvailable));
|
|
150
|
+
} catch (error) {
|
|
151
|
+
results.push({
|
|
152
|
+
id: record.id,
|
|
153
|
+
stopped: false,
|
|
154
|
+
reason: String(error)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return results;
|
|
159
|
+
},
|
|
160
|
+
async input(id, text = "", enter = false, assertAvailable = () => void 0) {
|
|
161
|
+
const record = await status(id);
|
|
162
|
+
assertAvailable();
|
|
163
|
+
if (record.state !== "running" || !record.interactive || !["rmux", "tmux"].includes(record.backend) || !record.backendTarget) throw new Error("Input requires a running interactive RMUX or tmux runner.");
|
|
164
|
+
runnerId(record.backendTarget);
|
|
165
|
+
const payload = enter && !text.endsWith("\n") ? `${text}\n` : text;
|
|
166
|
+
if (!payload || payload.length > 4096) throw new Error(`Input must contain between 1 and ${MAX_INPUT_CHARS} characters.`);
|
|
167
|
+
if (!await options.rmuxBackend.input(record.backendTarget, payload)) throw new Error("The runner is no longer accepting input.");
|
|
168
|
+
return {
|
|
169
|
+
id,
|
|
170
|
+
delivered: true
|
|
171
|
+
};
|
|
172
|
+
}
|
|
49
173
|
};
|
|
50
|
-
arm();
|
|
51
|
-
return { async stop() {
|
|
52
|
-
stopped = true;
|
|
53
|
-
cancel?.();
|
|
54
|
-
await running;
|
|
55
|
-
} };
|
|
56
174
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/services/runnerNamespace/index.ts
|
|
177
|
+
const DECLARATIONS = `declare namespace Runner {
|
|
178
|
+
interface Record {
|
|
179
|
+
id: string; name: string; command: string; cwd: string; sessionId: string;
|
|
180
|
+
state: 'running' | 'completed'; backend: 'rmux' | 'tmux' | 'native';
|
|
181
|
+
pid: number; logPath: string; interactive: boolean; startedAt: string; promoted: boolean;
|
|
182
|
+
exit?: { reason: string; code: number | null; signal: string | null; finishedAt: string; stopReason?: string };
|
|
183
|
+
}
|
|
184
|
+
interface Stage {
|
|
185
|
+
index: number; command: string; state: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' | 'denied';
|
|
186
|
+
id?: string; logPath?: string; exitCode?: number | null;
|
|
187
|
+
}
|
|
188
|
+
interface Result { content: { type: string; text?: string }[]; details?: unknown; isError?: boolean; }
|
|
189
|
+
interface Sequence {
|
|
190
|
+
id: string; sessionId: string; name: string; state: 'running' | 'completed';
|
|
191
|
+
outcome?: string; promoted: boolean; createdAt: string; stages?: Stage[]; result?: Result;
|
|
192
|
+
}
|
|
193
|
+
interface Logs {
|
|
194
|
+
text: string; lineCount: number; totalLines: number; fileSize: number; completeBytes: number;
|
|
195
|
+
path: string; exists: boolean; truncated: boolean; lineNumbers?: number[];
|
|
196
|
+
}
|
|
197
|
+
interface Stop { id: string; stopped?: boolean; requested?: boolean; reason?: string; }
|
|
198
|
+
}
|
|
199
|
+
declare const runner: {
|
|
200
|
+
/** Active runners and sequences in this session; all includes retained history. */
|
|
201
|
+
list(input?: { all?: boolean }): Promise<(Runner.Record | Runner.Sequence)[]>;
|
|
202
|
+
/** Running sequences expose stages. Completed sequences expose only the guarded result, including its allowed manifest. */
|
|
203
|
+
status(input: { id: string }): Promise<Runner.Record | Runner.Sequence>;
|
|
204
|
+
/** Finite process log snapshot, or a sequence manifest with its guarded final result. */
|
|
205
|
+
logs(input: { id: string; lines?: number; grep?: string; ignoreCase?: boolean; contextLines?: number }): Promise<Runner.Logs | Runner.Sequence>;
|
|
206
|
+
/** Stop a process or request cancellation of an entire sequence. Requested is not confirmed stopped. */
|
|
207
|
+
stop(input: { id: string; reason?: string }): Promise<Runner.Stop>;
|
|
208
|
+
/** Stop this session's active work. Outcomes are per ID, not unconditional success. */
|
|
209
|
+
stopAll(input?: { reason?: string }): Promise<Runner.Stop[]>;
|
|
210
|
+
/** Send input to a running interactive process, never to a sequence. */
|
|
211
|
+
input(input: { id: string; text?: string; enter?: boolean }): Promise<{ id: string; delivered: boolean }>;
|
|
212
|
+
};`;
|
|
213
|
+
function parameters(input, fields, optional = false) {
|
|
214
|
+
if (input === void 0 && optional) return {};
|
|
215
|
+
if (typeof input === "string" && fields.includes("id")) return { id: input };
|
|
216
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) throw new Error(`Expected an object with the documented runner fields: ${fields.join(", ")}.`);
|
|
217
|
+
for (const key of Object.keys(input)) if (!fields.includes(key)) throw new Error(`Unknown runner field: ${key}. Allowed: ${fields.join(", ")}.`);
|
|
218
|
+
return input;
|
|
219
|
+
}
|
|
220
|
+
function optionalString(record, field) {
|
|
221
|
+
const value = record[field];
|
|
222
|
+
if (value !== void 0 && (typeof value !== "string" || value.length > 4096)) throw new Error(`${field} must be a string of at most ${MAX_INPUT_CHARS} characters.`);
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
function optionalBoolean(record, field) {
|
|
226
|
+
const value = record[field];
|
|
227
|
+
if (value !== void 0 && typeof value !== "boolean") throw new Error(`${field} must be a boolean.`);
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
function sequenceView(record) {
|
|
231
|
+
const { id, sessionId, name, state, outcome, promoted, createdAt, stages, result } = record;
|
|
232
|
+
return {
|
|
233
|
+
id,
|
|
234
|
+
sessionId,
|
|
235
|
+
name,
|
|
236
|
+
state,
|
|
237
|
+
outcome,
|
|
238
|
+
promoted,
|
|
239
|
+
createdAt,
|
|
240
|
+
...state === "running" ? { stages } : {},
|
|
241
|
+
result
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function createRunnerNamespace(options) {
|
|
245
|
+
return {
|
|
246
|
+
name: "runner",
|
|
247
|
+
summary: "Inspect supervised Bash processes and sequential command groups, read saved logs, provide interactive input, and stop unused work.",
|
|
248
|
+
declarations: DECLARATIONS,
|
|
249
|
+
bind(run) {
|
|
250
|
+
if (run.sessionId !== options.sessionId) throw new Error("Runner namespace belongs to another session.");
|
|
251
|
+
const disposal = new AbortController();
|
|
252
|
+
const signal = AbortSignal.any([run.signal, disposal.signal]);
|
|
253
|
+
run.onDispose(() => disposal.abort(/* @__PURE__ */ new Error("Runner namespace run is disposed.")));
|
|
254
|
+
const check = () => {
|
|
255
|
+
signal.throwIfAborted();
|
|
256
|
+
options.assertAvailable();
|
|
257
|
+
};
|
|
258
|
+
const detached = async (work) => {
|
|
259
|
+
check();
|
|
260
|
+
const value = await work();
|
|
261
|
+
check();
|
|
262
|
+
return JSON.parse(JSON.stringify(value));
|
|
263
|
+
};
|
|
264
|
+
const sequence = async (id) => {
|
|
265
|
+
if (!isSequenceId(id)) return void 0;
|
|
266
|
+
const record = await options.sequences?.get(id);
|
|
267
|
+
check();
|
|
268
|
+
if (record && (record.id !== id || record.sessionId !== options.sessionId)) throw new Error("Sequence belongs to another session.");
|
|
269
|
+
return record;
|
|
270
|
+
};
|
|
271
|
+
const stop = async (id, reason) => {
|
|
272
|
+
if (await sequence(id)) return options.sequences.stop(id, reason);
|
|
273
|
+
check();
|
|
274
|
+
return options.operations.stop(id, reason, check);
|
|
275
|
+
};
|
|
276
|
+
const members = Object.create(null);
|
|
277
|
+
members.list = (input) => detached(async () => {
|
|
278
|
+
const all = optionalBoolean(parameters(input, ["all"], true), "all");
|
|
279
|
+
const processes = await options.operations.list(all);
|
|
280
|
+
check();
|
|
281
|
+
const sequences = await options.sequences?.list(all) ?? [];
|
|
282
|
+
for (const item of sequences) if (item.sessionId !== options.sessionId) throw new Error("Sequence belongs to another session.");
|
|
283
|
+
return [...processes, ...sequences.map(sequenceView)];
|
|
284
|
+
});
|
|
285
|
+
members.status = (input) => detached(async () => {
|
|
286
|
+
const id = runnerId(parameters(input, ["id"]).id);
|
|
287
|
+
const found = await sequence(id);
|
|
288
|
+
return found ? sequenceView(found) : options.operations.status(id);
|
|
289
|
+
});
|
|
290
|
+
members.logs = (input) => detached(async () => {
|
|
291
|
+
const record = parameters(input, [
|
|
292
|
+
"id",
|
|
293
|
+
"lines",
|
|
294
|
+
"grep",
|
|
295
|
+
"ignoreCase",
|
|
296
|
+
"contextLines"
|
|
297
|
+
]);
|
|
298
|
+
const id = runnerId(record.id);
|
|
299
|
+
const grep = optionalString(record, "grep");
|
|
300
|
+
const ignoreCase = optionalBoolean(record, "ignoreCase");
|
|
301
|
+
for (const [field, minimum] of [["lines", 1], ["contextLines", 0]]) {
|
|
302
|
+
const value = record[field];
|
|
303
|
+
if (value !== void 0 && (!Number.isInteger(value) || Number(value) < minimum || Number(value) > 5e3)) throw new Error(`${field} must be an integer between ${minimum} and ${MAX_LINES}.`);
|
|
304
|
+
}
|
|
305
|
+
const found = await sequence(id);
|
|
306
|
+
if (found) return sequenceView(found);
|
|
307
|
+
return options.operations.logs(id, {
|
|
308
|
+
lines: record.lines,
|
|
309
|
+
contextLines: record.contextLines,
|
|
310
|
+
grep,
|
|
311
|
+
ignoreCase
|
|
312
|
+
}, check);
|
|
313
|
+
});
|
|
314
|
+
members.stop = (input) => detached(async () => {
|
|
315
|
+
const record = parameters(input, ["id", "reason"]);
|
|
316
|
+
return stop(runnerId(record.id), optionalString(record, "reason"));
|
|
317
|
+
});
|
|
318
|
+
members.stopAll = (input) => detached(async () => {
|
|
319
|
+
const reason = optionalString(parameters(input, ["reason"], true), "reason");
|
|
320
|
+
const outcomes = [];
|
|
321
|
+
const sequences = await options.sequences?.list() ?? [];
|
|
322
|
+
for (const item of sequences) {
|
|
323
|
+
check();
|
|
324
|
+
if (item.sessionId !== options.sessionId) throw new Error("Sequence belongs to another session.");
|
|
325
|
+
try {
|
|
326
|
+
outcomes.push(await options.sequences.stop(item.id, reason));
|
|
327
|
+
} catch (error) {
|
|
328
|
+
outcomes.push({
|
|
329
|
+
id: item.id,
|
|
330
|
+
stopped: false,
|
|
331
|
+
reason: String(error)
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
check();
|
|
336
|
+
return [...outcomes, ...await options.operations.stopAll(reason, check)];
|
|
337
|
+
});
|
|
338
|
+
members.input = (input) => detached(async () => {
|
|
339
|
+
const record = parameters(input, [
|
|
340
|
+
"id",
|
|
341
|
+
"text",
|
|
342
|
+
"enter"
|
|
343
|
+
]);
|
|
344
|
+
const id = runnerId(record.id);
|
|
345
|
+
const text = optionalString(record, "text");
|
|
346
|
+
const enter = optionalBoolean(record, "enter");
|
|
347
|
+
if (await sequence(id)) throw new Error("Input is only available for an interactive process, not a sequence.");
|
|
348
|
+
return options.operations.input(id, text, enter, check);
|
|
349
|
+
});
|
|
350
|
+
return members;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/services/runnerSequence/index.ts
|
|
356
|
+
function validateSequenceCommands(command) {
|
|
357
|
+
if (!Array.isArray(command) || command.length === 0 || command.length > 32 || command.some((item) => typeof item !== "string" || !item.trim() || item.length > 65536)) throw bashFailureError(`command must contain 1 to 32 nonempty Bash strings, each at most ${MAX_SEQUENCE_COMMAND_LENGTH} characters.`, "invalid_arguments");
|
|
358
|
+
}
|
|
359
|
+
function validateTimeout(timeout) {
|
|
360
|
+
if (timeout !== void 0 && (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0)) throw bashFailureError("A sequence timeout must be a finite positive number of seconds.", "invalid_arguments");
|
|
361
|
+
}
|
|
362
|
+
const textResult = (text, details, isError = false) => ({
|
|
363
|
+
content: [{
|
|
364
|
+
type: "text",
|
|
365
|
+
text
|
|
366
|
+
}],
|
|
367
|
+
...details ? { details } : {},
|
|
368
|
+
...isError ? { isError: true } : {}
|
|
369
|
+
});
|
|
370
|
+
/** The session owns continuation, not the tool-call signal that expires on promotion. */
|
|
371
|
+
function createRunnerSequenceService(options) {
|
|
372
|
+
const { dependencies, store } = options;
|
|
373
|
+
const owner = crypto.randomUUID();
|
|
374
|
+
const active = /* @__PURE__ */ new Map();
|
|
375
|
+
const notifications = /* @__PURE__ */ new Map();
|
|
376
|
+
let disposed = false;
|
|
377
|
+
let refreshing;
|
|
378
|
+
const assertAvailable = () => {
|
|
379
|
+
if (disposed) throw new Error("Runner sequence service is disposed.");
|
|
380
|
+
options.signal?.throwIfAborted();
|
|
381
|
+
};
|
|
382
|
+
const save = async (record) => {
|
|
383
|
+
await store.save(record);
|
|
384
|
+
options.onChange();
|
|
385
|
+
};
|
|
386
|
+
let recovery;
|
|
387
|
+
const recover = () => {
|
|
388
|
+
recovery ??= (async () => {
|
|
389
|
+
for (const record of await store.list(true)) {
|
|
390
|
+
if (disposed) return;
|
|
391
|
+
if (record.state === "running") {
|
|
392
|
+
record.state = "completed";
|
|
393
|
+
record.outcome = "interrupted";
|
|
394
|
+
record.notificationPending = false;
|
|
395
|
+
record.result = textResult("Sequence interrupted because its owning runtime ended. Pending commands were not replayed.", {
|
|
396
|
+
id: record.id,
|
|
397
|
+
sequenceId: record.id,
|
|
398
|
+
sequence: true
|
|
399
|
+
}, true);
|
|
400
|
+
await save(record);
|
|
401
|
+
} else if (record.notificationPending) active.set(record.id, { record });
|
|
402
|
+
}
|
|
403
|
+
})().catch((error) => {
|
|
404
|
+
recovery = void 0;
|
|
405
|
+
throw error;
|
|
406
|
+
});
|
|
407
|
+
return recovery;
|
|
408
|
+
};
|
|
409
|
+
const notify = (record) => {
|
|
410
|
+
const pending = notifications.get(record.id);
|
|
411
|
+
if (pending) return pending;
|
|
412
|
+
if (!record.notificationPending || !record.result || disposed) return Promise.resolve();
|
|
413
|
+
const work = (async () => {
|
|
73
414
|
try {
|
|
74
|
-
await
|
|
415
|
+
await options.onComplete?.(record);
|
|
416
|
+
await store.save({
|
|
417
|
+
...record,
|
|
418
|
+
notificationPending: false
|
|
419
|
+
});
|
|
420
|
+
record.notificationPending = false;
|
|
421
|
+
options.onChange();
|
|
75
422
|
} catch (error) {
|
|
76
|
-
options.onWarning(`Could not
|
|
423
|
+
options.onWarning(`Could not report sequence ${record.id}: ${String(error)}`);
|
|
77
424
|
}
|
|
78
|
-
}
|
|
425
|
+
})().finally(() => notifications.delete(record.id));
|
|
426
|
+
notifications.set(record.id, work);
|
|
427
|
+
return work;
|
|
79
428
|
};
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
429
|
+
const details = (record, tail = "") => ({
|
|
430
|
+
id: record.id,
|
|
431
|
+
sequenceId: record.id,
|
|
432
|
+
sequence: true,
|
|
433
|
+
runner: record.name,
|
|
434
|
+
stages: structuredClone(record.stages),
|
|
435
|
+
tail
|
|
436
|
+
});
|
|
437
|
+
const execute = async (record, controller, params, context, toolCallId, onInteractiveStarted, onUpdate) => {
|
|
438
|
+
let last = textResult("No command was executed.");
|
|
439
|
+
let finalArgs = {
|
|
440
|
+
...params,
|
|
441
|
+
command: record.stages[0].command,
|
|
442
|
+
background: false,
|
|
443
|
+
interactive: false
|
|
444
|
+
};
|
|
445
|
+
const continuation = context.toolContinuation;
|
|
446
|
+
try {
|
|
447
|
+
for (const stage of record.stages) {
|
|
448
|
+
assertAvailable();
|
|
449
|
+
if (await store.stopRequested(record.id)) controller.abort(/* @__PURE__ */ new Error("Sequence stop requested."));
|
|
450
|
+
controller.signal.throwIfAborted();
|
|
451
|
+
const interactive = params.interactive === true && stage.index === record.stages.length - 1;
|
|
452
|
+
finalArgs = {
|
|
453
|
+
...params,
|
|
454
|
+
command: stage.command,
|
|
455
|
+
background: false,
|
|
456
|
+
interactive
|
|
457
|
+
};
|
|
458
|
+
const args = await continuation.admit({
|
|
459
|
+
toolCallId: `${toolCallId}:${record.id}:${stage.index}`,
|
|
460
|
+
toolName: "bash",
|
|
461
|
+
args: finalArgs,
|
|
462
|
+
signal: controller.signal
|
|
463
|
+
});
|
|
464
|
+
if (typeof args.command !== "string" || !Value.Check(BashParamsSchema, {
|
|
465
|
+
...args,
|
|
466
|
+
command: [args.command]
|
|
467
|
+
}) || args.interactive === true && !interactive || args.background === true) throw bashFailureError("A sequence hook must return one foreground Bash command; only the last may be interactive.", "invalid_arguments");
|
|
468
|
+
validateSequenceCommands([args.command]);
|
|
469
|
+
validateTimeout(args.timeout);
|
|
470
|
+
stage.command = args.command;
|
|
471
|
+
finalArgs = args;
|
|
472
|
+
controller.signal.throwIfAborted();
|
|
473
|
+
if (await store.stopRequested(record.id)) throw bashFailureError("Sequence stop requested.", "cancelled");
|
|
474
|
+
stage.state = "running";
|
|
475
|
+
await save(record);
|
|
476
|
+
if (!record.promoted) onUpdate?.(textResult(`Running command ${stage.index + 1}/${record.stages.length}: ${stage.command}`, details(record)));
|
|
477
|
+
const result = await dependencies.bashRunService.run({
|
|
478
|
+
command: stage.command,
|
|
479
|
+
cwd: context.cwd,
|
|
480
|
+
sessionId: options.sessionId,
|
|
481
|
+
waitForExit: true,
|
|
482
|
+
interactive: args.interactive === true,
|
|
483
|
+
...typeof args.name === "string" ? { name: args.name } : {},
|
|
484
|
+
signal: controller.signal,
|
|
485
|
+
...typeof args.timeout === "number" ? { timeoutMs: args.timeout * 1e3 } : {},
|
|
486
|
+
onStarted: async (run) => {
|
|
487
|
+
stage.id = run.id;
|
|
488
|
+
stage.logPath = run.logPath;
|
|
489
|
+
await save(record);
|
|
490
|
+
if (args.interactive === true) onInteractiveStarted();
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
if (result.kind !== "failed") {
|
|
494
|
+
stage.id = result.id;
|
|
495
|
+
stage.logPath = result.logPath;
|
|
87
496
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const now = options.clock.now();
|
|
93
|
-
const result = first.paths.sweepHistoryAsync ? await first.paths.sweepHistoryAsync(first.historyTtlMs, now, live) : first.paths.sweepHistory(first.historyTtlMs, now, live);
|
|
94
|
-
for (const error of result.errors) options.onWarning(error);
|
|
497
|
+
try {
|
|
498
|
+
last = await formatRunResult(result, parseResultPragma(stage.command), options.summarizeLog, dependencies.settings, dependencies.environment, false);
|
|
499
|
+
} catch (error) {
|
|
500
|
+
last = textResult(error instanceof Error ? error.message : String(error), { failure: bashFailure(bashFailureReason(error, "result_format_failed")) }, true);
|
|
95
501
|
}
|
|
96
|
-
|
|
97
|
-
|
|
502
|
+
const succeeded = result.kind === "completed" && result.exitCode === 0 && result.signal === null && !result.timedOut && !result.aborted;
|
|
503
|
+
stage.state = succeeded ? "completed" : controller.signal.aborted ? "cancelled" : "failed";
|
|
504
|
+
if (result.kind === "completed") stage.exitCode = result.exitCode;
|
|
505
|
+
if (!succeeded) {
|
|
506
|
+
record.outcome = controller.signal.aborted ? "cancelled" : result.kind === "completed" && result.timedOut ? "timed_out" : "failed";
|
|
507
|
+
last.isError = true;
|
|
508
|
+
if (result.kind === "promoted") last = textResult(`Could not stop command ${stage.index + 1}; runner ${result.id} remains supervised.`, { failure: bashFailure("stop_failed") }, true);
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
await save(record);
|
|
98
512
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
513
|
+
record.outcome ??= "completed";
|
|
514
|
+
} catch (error) {
|
|
515
|
+
const reason = controller.signal.aborted ? "cancelled" : bashFailureReason(error, "internal_error");
|
|
516
|
+
const state = reason === "cancelled" ? "cancelled" : reason === "approval_denied" ? "denied" : "failed";
|
|
517
|
+
record.outcome = state;
|
|
518
|
+
const stage = record.stages.find((item) => item.state === "running" || item.state === "pending");
|
|
519
|
+
if (stage) stage.state = state;
|
|
520
|
+
last = textResult(error instanceof Error ? error.message : String(error), { failure: bashFailure(reason) }, true);
|
|
521
|
+
}
|
|
522
|
+
for (const stage of record.stages) if (stage.state === "pending") stage.state = "cancelled";
|
|
523
|
+
const lastDetails = typeof last.details === "object" && last.details !== null ? last.details : {};
|
|
524
|
+
const tail = typeof lastDetails.tail === "string" ? lastDetails.tail : last.content.map((part) => "text" in part ? part.text : "").join("\n");
|
|
525
|
+
const manifest = record.stages.filter((stage) => stage.logPath).map((stage) => `${stage.index + 1}. ${stage.logPath}`).join("\n");
|
|
526
|
+
const aggregate = {
|
|
527
|
+
...last,
|
|
528
|
+
content: [{
|
|
529
|
+
type: "text",
|
|
530
|
+
text: [manifest ? `Command logs:\n${manifest}` : "No command logs were created.", last.content.map((part) => "text" in part ? part.text : "").join("\n")].join("\n\n")
|
|
531
|
+
}],
|
|
532
|
+
details: {
|
|
533
|
+
...lastDetails,
|
|
534
|
+
...details(record, tail),
|
|
535
|
+
...record.outcome === "timed_out" ? { timedOut: true } : {}
|
|
536
|
+
},
|
|
537
|
+
...record.outcome !== "completed" ? { isError: true } : {}
|
|
538
|
+
};
|
|
539
|
+
try {
|
|
540
|
+
record.result = await continuation.finalize({
|
|
541
|
+
toolCallId: `${toolCallId}:${record.id}:result`,
|
|
542
|
+
toolName: "bash",
|
|
543
|
+
args: finalArgs,
|
|
544
|
+
result: aggregate,
|
|
545
|
+
...options.signal ? { signal: options.signal } : {}
|
|
546
|
+
});
|
|
547
|
+
} catch (error) {
|
|
548
|
+
record.outcome = "finalization_failed";
|
|
549
|
+
record.result = textResult("Sequence finished, but its result could not pass the session result policy.", {
|
|
550
|
+
id: record.id,
|
|
551
|
+
sequenceId: record.id,
|
|
552
|
+
sequence: true,
|
|
553
|
+
failure: bashFailure("result_policy_failed")
|
|
554
|
+
}, true);
|
|
555
|
+
options.onWarning(`Could not finalize sequence ${record.id}: ${String(error)}`);
|
|
556
|
+
}
|
|
557
|
+
record.state = "completed";
|
|
558
|
+
record.notificationPending = record.promoted && record.notify;
|
|
559
|
+
await save(record);
|
|
560
|
+
await notify(record);
|
|
103
561
|
};
|
|
104
|
-
const polling = repeat(options.clock, options.statusPollMs, refreshAll);
|
|
105
|
-
const sweeper = repeat(options.clock, options.historySweepMs, sweepAll);
|
|
106
562
|
return {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
563
|
+
store,
|
|
564
|
+
async run(params, context, toolCallId, signal, onUpdate, wakeOnExit = true) {
|
|
565
|
+
assertAvailable();
|
|
566
|
+
if (context.sessionId !== options.sessionId) throw new Error("Sequence belongs to another session.");
|
|
567
|
+
validateSequenceCommands(params.command);
|
|
568
|
+
validateTimeout(params.timeout);
|
|
569
|
+
if (!context.toolContinuation) throw new Error("This host does not support guarded Bash command sequences.");
|
|
570
|
+
signal?.throwIfAborted();
|
|
571
|
+
await recover();
|
|
572
|
+
assertAvailable();
|
|
573
|
+
signal?.throwIfAborted();
|
|
574
|
+
const controller = new AbortController();
|
|
575
|
+
const abort = () => controller.abort(signal?.reason);
|
|
576
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
577
|
+
const ownerAbort = () => controller.abort(options.signal?.reason);
|
|
578
|
+
options.signal?.addEventListener("abort", ownerAbort, { once: true });
|
|
579
|
+
const record = {
|
|
580
|
+
id: `${SEQUENCE_PREFIX}${crypto.randomUUID()}`,
|
|
581
|
+
owner,
|
|
582
|
+
sessionId: options.sessionId,
|
|
583
|
+
name: params.name ?? "command-sequence",
|
|
584
|
+
state: "running",
|
|
585
|
+
promoted: params.background === true,
|
|
586
|
+
notify: wakeOnExit && params.background !== true,
|
|
587
|
+
notificationPending: false,
|
|
588
|
+
createdAt: new Date(dependencies.clock.now()).toISOString(),
|
|
589
|
+
stages: params.command.map((command, index) => ({
|
|
590
|
+
index,
|
|
591
|
+
command,
|
|
592
|
+
state: "pending"
|
|
593
|
+
}))
|
|
122
594
|
};
|
|
595
|
+
let cancelTimer;
|
|
596
|
+
let promoteInteractive;
|
|
597
|
+
const promotion = new Promise((resolve) => {
|
|
598
|
+
promoteInteractive = () => resolve("promoted");
|
|
599
|
+
if (params.background) resolve("promoted");
|
|
600
|
+
else cancelTimer = dependencies.clock.after(getBackgroundThresholdMs(dependencies.environment), () => resolve("promoted"));
|
|
601
|
+
});
|
|
602
|
+
const entry = {
|
|
603
|
+
record,
|
|
604
|
+
controller,
|
|
605
|
+
work: Promise.resolve()
|
|
606
|
+
};
|
|
607
|
+
active.set(record.id, entry);
|
|
608
|
+
entry.work = save(record).then(() => execute(record, controller, params, context, toolCallId, promoteInteractive, onUpdate)).finally(() => {
|
|
609
|
+
options.signal?.removeEventListener("abort", ownerAbort);
|
|
610
|
+
if (!record.notificationPending) active.delete(record.id);
|
|
611
|
+
});
|
|
612
|
+
entry.work.catch((error) => options.onWarning(`Sequence ${record.id} failed: ${String(error)}`));
|
|
613
|
+
try {
|
|
614
|
+
if (await Promise.race([entry.work.then(() => "completed"), promotion]) === "completed" || record.state === "completed") {
|
|
615
|
+
await entry.work;
|
|
616
|
+
return record.result;
|
|
617
|
+
}
|
|
618
|
+
record.promoted = true;
|
|
619
|
+
await save(record);
|
|
620
|
+
return textResult([`Sequence ${record.name} (${record.id}) continues in the background. Inspect its status before retrying.`, ...params.interactive ? ["Only the last command is interactive. Inspect its stage runner ID and logs, then send input with runner.input or po-runner input using that stage ID, not the sequence ID."] : []].join("\n"), {
|
|
621
|
+
...details(record),
|
|
622
|
+
promoted: true
|
|
623
|
+
});
|
|
624
|
+
} finally {
|
|
625
|
+
cancelTimer?.();
|
|
626
|
+
signal?.removeEventListener("abort", abort);
|
|
627
|
+
}
|
|
628
|
+
},
|
|
629
|
+
async stop(id, reason) {
|
|
630
|
+
const requested = await store.requestStop(id, reason);
|
|
631
|
+
active.get(id)?.controller?.abort(new Error(reason ?? "Sequence stop requested."));
|
|
632
|
+
return requested;
|
|
633
|
+
},
|
|
634
|
+
list: (includeCompleted) => store.list(includeCompleted),
|
|
635
|
+
get: (id) => store.get(id),
|
|
636
|
+
activeWork() {
|
|
637
|
+
return [...active.values()].filter(({ record }) => record.state === "running" || record.notificationPending).map(({ record }) => ({
|
|
638
|
+
id: record.id,
|
|
639
|
+
sessionId: record.sessionId,
|
|
640
|
+
label: record.name,
|
|
641
|
+
...record.state === "running" ? { status: record.notify ? "running" : BACKGROUND_SERVICE_STATUS } : {}
|
|
642
|
+
}));
|
|
643
|
+
},
|
|
644
|
+
refresh() {
|
|
645
|
+
if (disposed) return Promise.resolve();
|
|
646
|
+
refreshing ??= (async () => {
|
|
647
|
+
await recover();
|
|
648
|
+
for (const { record, controller } of active.values()) {
|
|
649
|
+
if (disposed) return;
|
|
650
|
+
if (record.state === "running" && controller && await store.stopRequested(record.id)) controller.abort(/* @__PURE__ */ new Error("Sequence stop requested."));
|
|
651
|
+
await notify(record);
|
|
652
|
+
if (record.state === "completed" && !record.notificationPending) active.delete(record.id);
|
|
653
|
+
}
|
|
654
|
+
})().finally(() => {
|
|
655
|
+
refreshing = void 0;
|
|
656
|
+
});
|
|
657
|
+
return refreshing;
|
|
658
|
+
},
|
|
659
|
+
async recoveryText() {
|
|
660
|
+
return (await store.list()).map((record) => `Active sequence ${record.name} (${record.id}), inspect runner.status({ id: ${JSON.stringify(record.id)} }).`).join("\n");
|
|
123
661
|
},
|
|
124
662
|
async dispose() {
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
await Promise.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
sweeping
|
|
663
|
+
if (disposed) return;
|
|
664
|
+
disposed = true;
|
|
665
|
+
for (const { controller } of active.values()) controller?.abort(/* @__PURE__ */ new Error("Runner session ended."));
|
|
666
|
+
await Promise.allSettled([
|
|
667
|
+
recovery,
|
|
668
|
+
refreshing,
|
|
669
|
+
...[...active.values()].map(({ work }) => work)
|
|
133
670
|
]);
|
|
134
|
-
options.processRegistry.close();
|
|
135
671
|
}
|
|
136
672
|
};
|
|
137
673
|
}
|
|
@@ -190,15 +726,7 @@ function presentRunnerRuns(records, now) {
|
|
|
190
726
|
//#endregion
|
|
191
727
|
//#region src/services/runnerServerRuntime/index.ts
|
|
192
728
|
const COMPLETION_RETRY_MS = 1e3;
|
|
193
|
-
function createRunnerServerRuntime(container, host, directEvents, wakeAgent, execution) {
|
|
194
|
-
const telemetry = execution ? createPoTelemetry({
|
|
195
|
-
serviceName: "po-runner",
|
|
196
|
-
packageName: "@agimon-ai/po-runner",
|
|
197
|
-
cwd: execution.cwd,
|
|
198
|
-
env: execution.environment,
|
|
199
|
-
enableLogs: true,
|
|
200
|
-
enableTraces: true
|
|
201
|
-
}) : void 0;
|
|
729
|
+
function createRunnerServerRuntime(container, host, directEvents, wakeAgent, execution, telemetry) {
|
|
202
730
|
let sessionId;
|
|
203
731
|
let recoveredCompactionId;
|
|
204
732
|
let supervision;
|
|
@@ -213,6 +741,9 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
213
741
|
let retryTimer;
|
|
214
742
|
/** Stops the shared loop refreshing this session and sweeping around it. */
|
|
215
743
|
let detach;
|
|
744
|
+
let startFailure;
|
|
745
|
+
let startFailures = 0;
|
|
746
|
+
let sequences;
|
|
216
747
|
/** Every runner of every session the registry knows, reclaimed when its owning process is gone. */
|
|
217
748
|
const reclaimOrphans = async () => {
|
|
218
749
|
const reclaimed = await reconcileActiveRunners({
|
|
@@ -276,6 +807,7 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
276
807
|
const ownedSessionId = sessionId;
|
|
277
808
|
if (ownedSessionId === void 0) return;
|
|
278
809
|
await runCleanups([
|
|
810
|
+
() => sequences?.dispose(),
|
|
279
811
|
async () => {
|
|
280
812
|
const records = await container.runnerRegistry.listBySession(ownedSessionId);
|
|
281
813
|
const errors = (await Promise.allSettled(records.map(async (record) => {
|
|
@@ -303,6 +835,13 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
303
835
|
},
|
|
304
836
|
() => container.ptyHost.disposeAll(),
|
|
305
837
|
() => container.lifeline.dispose(),
|
|
838
|
+
() => cleanupRunnerSession({
|
|
839
|
+
sessionId: ownedSessionId,
|
|
840
|
+
paths: container.paths,
|
|
841
|
+
processRegistry: container.processRegistry,
|
|
842
|
+
ownerPid: process.pid,
|
|
843
|
+
generation: container.lifeline.generation?.()
|
|
844
|
+
}),
|
|
306
845
|
() => container.runnerRegistry.close()
|
|
307
846
|
], "Runner runtime cleanup failed.");
|
|
308
847
|
})();
|
|
@@ -319,6 +858,7 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
319
858
|
const refreshNow = async (ownedSessionId) => {
|
|
320
859
|
if (closing) return;
|
|
321
860
|
try {
|
|
861
|
+
await sequences?.refresh();
|
|
322
862
|
const reconciled = await reconcileActiveRunners({
|
|
323
863
|
registry: container.runnerRegistry,
|
|
324
864
|
launcher: container.launcher,
|
|
@@ -337,6 +877,7 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
337
877
|
process.emitWarning(`Could not refresh po-runner: ${String(error)}`);
|
|
338
878
|
}
|
|
339
879
|
};
|
|
880
|
+
let sentRuns;
|
|
340
881
|
const publishRuns = async (ownedSessionId) => {
|
|
341
882
|
try {
|
|
342
883
|
const records = await container.runnerRegistry.listAll(ownedSessionId);
|
|
@@ -352,13 +893,23 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
352
893
|
id: record.id,
|
|
353
894
|
sessionId: record.sessionId,
|
|
354
895
|
label: record.name,
|
|
355
|
-
...record.state === "running" ? { status: record.state } : {}
|
|
896
|
+
...record.state === "running" ? { status: watched.has(record.id) ? record.state : BACKGROUND_SERVICE_STATUS } : {}
|
|
356
897
|
}));
|
|
898
|
+
nextBackgroundWork.push(...sequences?.activeWork() ?? []);
|
|
357
899
|
if (JSON.stringify(nextBackgroundWork) !== JSON.stringify(backgroundWorkItems)) {
|
|
358
900
|
backgroundWorkItems = nextBackgroundWork;
|
|
359
901
|
backgroundWorkProvider?.update();
|
|
360
902
|
}
|
|
361
|
-
|
|
903
|
+
const runs = {
|
|
904
|
+
runs: presentRunnerRuns(records, Date.now()),
|
|
905
|
+
...execution ? { sessionDirectory: execution.cwd } : {},
|
|
906
|
+
...startFailure ? { startFailure } : {}
|
|
907
|
+
};
|
|
908
|
+
const serialized = JSON.stringify(runs);
|
|
909
|
+
if (serialized !== sentRuns) {
|
|
910
|
+
sentRuns = serialized;
|
|
911
|
+
directEvents.publish(RUNNER_RUNS_TYPE, ownedSessionId, runs);
|
|
912
|
+
}
|
|
362
913
|
} catch (error) {
|
|
363
914
|
process.emitWarning(`Could not publish runner state: ${String(error)}`);
|
|
364
915
|
}
|
|
@@ -394,11 +945,6 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
394
945
|
if (closing) return;
|
|
395
946
|
if (record?.state === "running") continue;
|
|
396
947
|
if (record) await wakeAgent?.(formatRunnerFinished(record), `runner-finished:${JSON.stringify([ownedSessionId, id])}`, formatRunnerFinishedNotice(record));
|
|
397
|
-
if (record) await telemetry?.recordEvent("po_runner.process_finished", {
|
|
398
|
-
outcome: "completed",
|
|
399
|
-
"runner.exit_code": record.exit?.code ?? 0,
|
|
400
|
-
"runner.backend": record.backend
|
|
401
|
-
});
|
|
402
948
|
watched.delete(id);
|
|
403
949
|
requestPublish(ownedSessionId);
|
|
404
950
|
} catch (error) {
|
|
@@ -443,20 +989,38 @@ function createRunnerServerRuntime(container, host, directEvents, wakeAgent, exe
|
|
|
443
989
|
},
|
|
444
990
|
ensureSession,
|
|
445
991
|
watchRunner,
|
|
992
|
+
setSequences(service) {
|
|
993
|
+
sequences = service;
|
|
994
|
+
},
|
|
995
|
+
sequenceChanged() {
|
|
996
|
+
if (sessionId !== void 0) requestPublish(sessionId);
|
|
997
|
+
},
|
|
998
|
+
reportStart(startedSessionId, failure) {
|
|
999
|
+
startFailures += 1;
|
|
1000
|
+
startFailure = failure === void 0 ? void 0 : {
|
|
1001
|
+
id: `${String(Date.now())}-${String(startFailures)}`,
|
|
1002
|
+
message: failure
|
|
1003
|
+
};
|
|
1004
|
+
requestPublish(startedSessionId);
|
|
1005
|
+
},
|
|
446
1006
|
async recoverCompaction(event) {
|
|
447
1007
|
if (event.status !== "completed" || closing || !execution || typeof event.entryId !== "string" || event.entryId === recoveredCompactionId) return;
|
|
448
|
-
const compacted = (await execution.session.entries(
|
|
1008
|
+
const compacted = (await execution.session.entries({
|
|
1009
|
+
type: "compaction",
|
|
1010
|
+
limit: 1
|
|
1011
|
+
})).findLast((entry) => entry.type === "compaction");
|
|
449
1012
|
if (closing || compacted?.id !== event.entryId) return;
|
|
450
1013
|
await ensureSession(execution.sessionId);
|
|
451
1014
|
let records;
|
|
452
1015
|
try {
|
|
453
1016
|
records = await container.runnerRegistry.listBySession(execution.sessionId);
|
|
454
|
-
} catch {
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
process.emitWarning(`Could not read runner compaction recovery: ${String(error)}`);
|
|
455
1019
|
return;
|
|
456
1020
|
}
|
|
457
1021
|
if (closing) return;
|
|
458
1022
|
const active = records.filter((record) => record.state === "running");
|
|
459
|
-
const text = activeRunnerRecovery(active);
|
|
1023
|
+
const text = [activeRunnerRecovery(active), await sequences?.recoveryText()].filter(Boolean).join("\n");
|
|
460
1024
|
if (!text) return;
|
|
461
1025
|
await execution.session.appendMessage?.({
|
|
462
1026
|
type: "po-runner-compaction",
|
|
@@ -548,11 +1112,18 @@ const CEILINGS = {
|
|
|
548
1112
|
errorMaxVariantsJoined: 100
|
|
549
1113
|
};
|
|
550
1114
|
var RunnerSettingsLoader = class {
|
|
551
|
-
|
|
1115
|
+
files;
|
|
1116
|
+
constructor(files) {
|
|
1117
|
+
this.files = files;
|
|
1118
|
+
}
|
|
1119
|
+
async load(cwd, trusted) {
|
|
552
1120
|
if (!trusted) return EMPTY;
|
|
553
1121
|
let raw;
|
|
554
1122
|
try {
|
|
555
|
-
|
|
1123
|
+
const target = path.join(cwd, CONFIG_DIR_NAME, RUNNER_SETTINGS_FILE);
|
|
1124
|
+
const text = this.files ? await readTextIfExists(this.files, target, BACKGROUND_CONTEXT) : await fs.readFile(target, "utf8");
|
|
1125
|
+
if (text === void 0) return EMPTY;
|
|
1126
|
+
raw = text;
|
|
556
1127
|
} catch (error) {
|
|
557
1128
|
if (error.code === "ENOENT") return EMPTY;
|
|
558
1129
|
return {
|
|
@@ -627,16 +1198,18 @@ function validate(parsed) {
|
|
|
627
1198
|
//#endregion
|
|
628
1199
|
//#region src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts
|
|
629
1200
|
const RUNNER_SERVER_SCOPE_SERVICE = "po/runner-server-scope";
|
|
630
|
-
const createRunnerServerRoot = async ({ host, agent, signal, resources }) => {
|
|
1201
|
+
const createRunnerServerRoot = async ({ context, host, agent, signal, resources }) => {
|
|
631
1202
|
if (!host.context.directEvents) throw new Error("Runner server plugin requires the session direct event bus.");
|
|
632
1203
|
if (!host.context.cwd || !host.context.environment) throw new Error("Runner server plugin requires session cwd and environment.");
|
|
633
|
-
const
|
|
1204
|
+
const fs = readPoFs(context);
|
|
1205
|
+
const loaded = await new RunnerSettingsLoader(fs).load(host.context.cwd, true);
|
|
634
1206
|
const settings = Object.freeze({
|
|
635
1207
|
...loaded.settings,
|
|
636
1208
|
...loaded.settings.errorPatterns ? { errorPatterns: Object.freeze([...loaded.settings.errorPatterns]) } : {}
|
|
637
1209
|
});
|
|
638
1210
|
for (const issue of loaded.issues) process.emitWarning(`${RUNNER_SETTINGS_FILE}: ${issue}`);
|
|
639
1211
|
const environment = host.context.environment;
|
|
1212
|
+
if (!environment[PO_SESSION_TEMP_DIR]) throw new Error("Runner requires the host-admitted session temporary directory.");
|
|
640
1213
|
const runnerHost = await resources.acquire(["runner-host", environment["PROCESS_REGISTRY_PATH"] ?? null], () => createRunnerHost({
|
|
641
1214
|
processRegistry: createDefaultProcessRegistry(environment),
|
|
642
1215
|
clock: new SystemClock(),
|
|
@@ -644,14 +1217,25 @@ const createRunnerServerRoot = async ({ host, agent, signal, resources }) => {
|
|
|
644
1217
|
historySweepMs: HISTORY_SWEEP_INTERVAL_MS,
|
|
645
1218
|
onWarning: (message) => process.emitWarning(message)
|
|
646
1219
|
}), (shared) => shared.dispose());
|
|
1220
|
+
const lifelineObserver = await resources.acquire(["runner-lifeline-observer", environment["PROCESS_REGISTRY_PATH"] ?? null], () => new LifelineObserver(environment), (shared) => shared.close());
|
|
1221
|
+
const execution = agent?.context;
|
|
1222
|
+
const telemetry = execution ? createPoTelemetry({
|
|
1223
|
+
serviceName: "po-runner",
|
|
1224
|
+
packageName: "@agimon-ai/po-runner",
|
|
1225
|
+
cwd: execution.cwd,
|
|
1226
|
+
env: execution.environment,
|
|
1227
|
+
enableLogs: true,
|
|
1228
|
+
enableTraces: true
|
|
1229
|
+
}) : void 0;
|
|
647
1230
|
const dependencies = createRunnerDependencies({
|
|
648
1231
|
settings,
|
|
649
1232
|
cwd: host.context.cwd,
|
|
650
1233
|
environment,
|
|
651
1234
|
processRegistry: runnerHost.processRegistry,
|
|
1235
|
+
lifelineObserver,
|
|
1236
|
+
...telemetry === void 0 ? {} : { telemetry },
|
|
652
1237
|
...host.context.executionBudget === void 0 ? {} : { executionBudget: host.context.executionBudget }
|
|
653
1238
|
});
|
|
654
|
-
const execution = agent?.context;
|
|
655
1239
|
const wakeAgent = execution && (async (content, requestId, notice) => {
|
|
656
1240
|
try {
|
|
657
1241
|
if (!execution.session.admitMessage) throw new Error("The session cannot admit a runner notification.");
|
|
@@ -669,32 +1253,98 @@ const createRunnerServerRoot = async ({ host, agent, signal, resources }) => {
|
|
|
669
1253
|
throw error;
|
|
670
1254
|
}
|
|
671
1255
|
});
|
|
672
|
-
const runtime = createRunnerServerRuntime(dependencies, runnerHost, host.context.directEvents, wakeAgent, execution);
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
1256
|
+
const runtime = createRunnerServerRuntime(dependencies, runnerHost, host.context.directEvents, wakeAgent, execution, telemetry);
|
|
1257
|
+
const sequences = fs && execution ? createRunnerSequenceService({
|
|
1258
|
+
dependencies,
|
|
1259
|
+
store: createRunnerSequenceStore(fs, dependencies.paths, execution.sessionId),
|
|
1260
|
+
sessionId: execution.sessionId,
|
|
1261
|
+
signal,
|
|
1262
|
+
summarizeLog: (path, lines, bytes, tokens) => summarizeLog(path, lines, bytes, tokens, settings),
|
|
1263
|
+
onChange: () => runtime.sequenceChanged(),
|
|
1264
|
+
onWarning: (message) => process.emitWarning(message),
|
|
1265
|
+
onComplete: async (record) => {
|
|
1266
|
+
if (!record.result) return;
|
|
1267
|
+
await wakeAgent?.(record.result.content.flatMap((part) => part.type === "text" ? [part.text] : []).join("\n"), `runner-sequence-finished:${JSON.stringify([record.sessionId, record.id])}`, `Command sequence ${record.name} finished: ${record.outcome ?? record.state}`);
|
|
1268
|
+
}
|
|
1269
|
+
}) : void 0;
|
|
1270
|
+
if (sequences) runtime.setSequences(sequences);
|
|
1271
|
+
const bash = (wakeOnExit) => createHeadlessBashTool(sequences ? async (params, context, toolCallId, callSignal, onUpdate) => {
|
|
1272
|
+
await runtime.ensureSession(context.sessionId);
|
|
1273
|
+
return sequences.run(params, context, toolCallId, callSignal, onUpdate, wakeOnExit);
|
|
1274
|
+
} : void 0, dependencies.environment);
|
|
682
1275
|
const value = {
|
|
1276
|
+
sequences,
|
|
683
1277
|
tool: bash(true),
|
|
684
1278
|
remoteTool: bash(false),
|
|
685
|
-
command: createHeadlessRunnersCommand(dependencies
|
|
1279
|
+
command: createHeadlessRunnersCommand(dependencies, {
|
|
1280
|
+
translate: (key, fallback, vars) => readPoLang(context)?.t(readPoPersonLocale(context)?.read(), key, fallback, vars) ?? formatMessage(fallback, vars),
|
|
1281
|
+
fs,
|
|
1282
|
+
sequences,
|
|
1283
|
+
onStart: (startedSessionId, failure) => runtime.reportStart(startedSessionId, failure)
|
|
1284
|
+
}),
|
|
686
1285
|
recoverCompaction: runtime.recoverCompaction
|
|
687
1286
|
};
|
|
1287
|
+
let controlsDisposed = false;
|
|
1288
|
+
let launch;
|
|
1289
|
+
let unregisterOwner;
|
|
1290
|
+
if (fs && execution) {
|
|
1291
|
+
const operations = createRunnerOperations({
|
|
1292
|
+
...dependencies,
|
|
1293
|
+
registry: dependencies.runnerRegistry,
|
|
1294
|
+
fs,
|
|
1295
|
+
sessionId: execution.sessionId
|
|
1296
|
+
});
|
|
1297
|
+
const assertAvailable = () => {
|
|
1298
|
+
signal?.throwIfAborted();
|
|
1299
|
+
if (controlsDisposed) throw new Error("Runner session is disposed.");
|
|
1300
|
+
};
|
|
1301
|
+
launch = createRunnerLaunch({
|
|
1302
|
+
sessionId: execution.sessionId,
|
|
1303
|
+
ownerSessionId: readPoWorkflowContextService(context)?.run.ownerSessionId ?? execution.sessionId,
|
|
1304
|
+
getOwner: (ownerSessionId) => runnerHost.getOwner(ownerSessionId),
|
|
1305
|
+
runService: dependencies.bashRunService,
|
|
1306
|
+
registry: dependencies.runnerRegistry,
|
|
1307
|
+
operations,
|
|
1308
|
+
ensureSession: (sessionId) => runtime.ensureSession(sessionId),
|
|
1309
|
+
watchRunner: (id) => runtime.watchRunner(id),
|
|
1310
|
+
assertAvailable
|
|
1311
|
+
});
|
|
1312
|
+
unregisterOwner = runnerHost.registerOwner(execution.sessionId, launch);
|
|
1313
|
+
const namespace = createRunnerNamespace({
|
|
1314
|
+
sessionId: execution.sessionId,
|
|
1315
|
+
operations,
|
|
1316
|
+
sequences,
|
|
1317
|
+
assertAvailable
|
|
1318
|
+
});
|
|
1319
|
+
context.inject([PO_CODEMODE_SERVICE], (scoped) => {
|
|
1320
|
+
const registration = readPoCodemode(scoped)?.register("@agimon-ai/po-runner", namespace);
|
|
1321
|
+
return () => registration?.dispose();
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
688
1324
|
return {
|
|
689
1325
|
value,
|
|
690
1326
|
services: [runtime.backgroundWorkPlugin, (context) => {
|
|
691
|
-
context.plugin((providerContext) =>
|
|
1327
|
+
context.plugin((providerContext) => {
|
|
1328
|
+
providerContext.provide(RUNNER_SERVER_SCOPE_SERVICE, value);
|
|
1329
|
+
if (launch) providerContext.provide(PO_RUNNER_LAUNCH_SERVICE, launch);
|
|
1330
|
+
});
|
|
692
1331
|
}],
|
|
693
1332
|
activities: [runtime.activity],
|
|
694
1333
|
onStart: execution ? () => {
|
|
695
1334
|
runtime.ensureSession(execution.sessionId).catch((error) => process.emitWarning(`Could not initialize headless runner supervision: ${String(error)}`));
|
|
696
1335
|
} : void 0,
|
|
697
|
-
onStop:
|
|
1336
|
+
onStop: async () => {
|
|
1337
|
+
controlsDisposed = true;
|
|
1338
|
+
unregisterOwner?.();
|
|
1339
|
+
const failures = [];
|
|
1340
|
+
for (const release of [() => launch?.dispose(), () => runtime.dispose()]) try {
|
|
1341
|
+
await release();
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
failures.push(error);
|
|
1344
|
+
}
|
|
1345
|
+
if (failures.length === 1) throw failures[0];
|
|
1346
|
+
if (failures.length > 1) throw new AggregateError(failures, "Runner session cleanup failed.");
|
|
1347
|
+
}
|
|
698
1348
|
};
|
|
699
1349
|
};
|
|
700
1350
|
//#endregion
|
|
@@ -751,19 +1401,6 @@ var runnerRuns_server_default = defineChannel(function runnerRunsChannel() {
|
|
|
751
1401
|
return createRunnersChannel();
|
|
752
1402
|
});
|
|
753
1403
|
//#endregion
|
|
754
|
-
//#region src/constants/runnerLogApi.ts
|
|
755
|
-
const LOG_DIR_NAME = "logs";
|
|
756
|
-
const STATE_EXTENSION = ".json";
|
|
757
|
-
const RUNNING_STATE = "running";
|
|
758
|
-
const STATE_POLL_MS = 1e3;
|
|
759
|
-
const HEARTBEAT_MS = 15e3;
|
|
760
|
-
const MAX_LINES = 5e3;
|
|
761
|
-
const SAFE_SEGMENT = /^[\w.@-]+$/;
|
|
762
|
-
const RAW_LOG_SUFFIX = ".raw";
|
|
763
|
-
/** Ceiling for one finite log/screen read, before base64 encoding. */
|
|
764
|
-
const MAX_OUTPUT_BYTES = 65536;
|
|
765
|
-
const NOT_ATTACHABLE = "No attachable runner by that name in this session.";
|
|
766
|
-
//#endregion
|
|
767
1404
|
//#region src/constants/webRunnerLog.ts
|
|
768
1405
|
const RUNNER_API_BASE_PATH = "runner";
|
|
769
1406
|
const RUN_ID_PARAM = "runId";
|
|
@@ -791,7 +1428,7 @@ var LogTail = class {
|
|
|
791
1428
|
let offset = options.from;
|
|
792
1429
|
let pending = "";
|
|
793
1430
|
let closed = false;
|
|
794
|
-
const drain = (size) => {
|
|
1431
|
+
const drain = async (size) => {
|
|
795
1432
|
if (size < offset) {
|
|
796
1433
|
offset = 0;
|
|
797
1434
|
pending = "";
|
|
@@ -799,27 +1436,32 @@ var LogTail = class {
|
|
|
799
1436
|
if (size === offset) return;
|
|
800
1437
|
const length = size - offset;
|
|
801
1438
|
const buffer = Buffer.alloc(length);
|
|
802
|
-
const descriptor = fs.
|
|
1439
|
+
const descriptor = await fs.open(logPath, "r");
|
|
803
1440
|
let bytesRead;
|
|
804
1441
|
try {
|
|
805
|
-
bytesRead =
|
|
1442
|
+
({bytesRead} = await descriptor.read(buffer, 0, length, offset));
|
|
806
1443
|
} finally {
|
|
807
|
-
|
|
1444
|
+
await descriptor.close();
|
|
808
1445
|
}
|
|
809
|
-
|
|
1446
|
+
if (closed) return;
|
|
1447
|
+
offset += bytesRead;
|
|
810
1448
|
if (bytesRead <= 0) return;
|
|
811
1449
|
pending += buffer.subarray(0, bytesRead).toString("utf8");
|
|
812
1450
|
const lines = pending.split("\n");
|
|
813
1451
|
pending = lines.pop() ?? "";
|
|
814
1452
|
if (lines.length > 0) options.onLines(lines, offset - Buffer.byteLength(pending, "utf8"));
|
|
815
1453
|
};
|
|
816
|
-
|
|
817
|
-
|
|
1454
|
+
let reading = false;
|
|
1455
|
+
const tick = async () => {
|
|
1456
|
+
if (closed || reading) return;
|
|
1457
|
+
reading = true;
|
|
818
1458
|
try {
|
|
819
|
-
drain(fs.
|
|
1459
|
+
await drain((await fs.stat(logPath)).size);
|
|
820
1460
|
} catch (error) {
|
|
821
1461
|
if (error.code === "ENOENT") return;
|
|
822
|
-
options.onError(error instanceof Error ? error : new Error(String(error)));
|
|
1462
|
+
if (!closed) options.onError(error instanceof Error ? error : new Error(String(error)));
|
|
1463
|
+
} finally {
|
|
1464
|
+
reading = false;
|
|
823
1465
|
}
|
|
824
1466
|
};
|
|
825
1467
|
const timer = setInterval(tick, 250);
|
|
@@ -934,13 +1576,13 @@ function isSafeSegment(value) {
|
|
|
934
1576
|
return value !== "" && value !== "." && value !== ".." && SAFE_SEGMENT.test(value);
|
|
935
1577
|
}
|
|
936
1578
|
/** A log must stay inside its session even when a path component is a symlink. Missing files are normal. */
|
|
937
|
-
function isSessionLog(file, logsDir) {
|
|
1579
|
+
async function isSessionLog(file, logsDir) {
|
|
938
1580
|
const resolved = path.resolve(file);
|
|
939
1581
|
if (resolved !== logsDir && !resolved.startsWith(`${logsDir}${path.sep}`)) return false;
|
|
940
1582
|
try {
|
|
941
|
-
if (fs.
|
|
942
|
-
const realFile = fs.
|
|
943
|
-
const realLogs = fs.
|
|
1583
|
+
if ((await fs.lstat(file)).isSymbolicLink()) return false;
|
|
1584
|
+
const realFile = await fs.realpath(file);
|
|
1585
|
+
const realLogs = await fs.realpath(logsDir);
|
|
944
1586
|
return realFile.startsWith(`${realLogs}${path.sep}`);
|
|
945
1587
|
} catch (error) {
|
|
946
1588
|
return isRecord(error) && error.code === "ENOENT";
|
|
@@ -955,17 +1597,17 @@ function isSessionLog(file, logsDir) {
|
|
|
955
1597
|
* session's own logs directory. Without that check a doctored record would
|
|
956
1598
|
* turn this route into an arbitrary file read.
|
|
957
1599
|
*/
|
|
958
|
-
function resolveLogFile(stateDir, logsDir, sessionId, runId) {
|
|
1600
|
+
async function resolveLogFile(stateDir, logsDir, sessionId, runId) {
|
|
959
1601
|
const statePath = path.join(stateDir, `${runId}${STATE_EXTENSION}`);
|
|
960
1602
|
let raw;
|
|
961
1603
|
try {
|
|
962
|
-
raw = fs.
|
|
1604
|
+
raw = await fs.readFile(statePath, "utf8");
|
|
963
1605
|
} catch {
|
|
964
1606
|
return;
|
|
965
1607
|
}
|
|
966
1608
|
const record = parseRunnerRecord(raw);
|
|
967
1609
|
if (record === void 0 || record.id !== runId || record.sessionId !== sessionId) return void 0;
|
|
968
|
-
if (!isSessionLog(record.logPath, logsDir)) return void 0;
|
|
1610
|
+
if (!await isSessionLog(record.logPath, logsDir)) return void 0;
|
|
969
1611
|
return record;
|
|
970
1612
|
}
|
|
971
1613
|
function isRecord(value) {
|
|
@@ -977,10 +1619,10 @@ function numberParam(value, fallback, max) {
|
|
|
977
1619
|
return Math.min(parsed, max);
|
|
978
1620
|
}
|
|
979
1621
|
/** Missing output is normal before the sink opens it; other IO failures must not look like an empty read. */
|
|
980
|
-
function readOutput(file, from, running, priorGeneration, screen = false) {
|
|
1622
|
+
async function readOutput(file, from, running, priorGeneration, screen = false) {
|
|
981
1623
|
let descriptor;
|
|
982
1624
|
try {
|
|
983
|
-
descriptor = fs.
|
|
1625
|
+
descriptor = await fs.open(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);
|
|
984
1626
|
} catch (error) {
|
|
985
1627
|
if (!isRecord(error) || error.code !== "ENOENT") throw error;
|
|
986
1628
|
return {
|
|
@@ -993,14 +1635,14 @@ function readOutput(file, from, running, priorGeneration, screen = false) {
|
|
|
993
1635
|
};
|
|
994
1636
|
}
|
|
995
1637
|
try {
|
|
996
|
-
const stat =
|
|
1638
|
+
const stat = await descriptor.stat({ bigint: true });
|
|
997
1639
|
const size = Number(stat.size);
|
|
998
1640
|
const generation = screen ? `${stat.dev}:${stat.ino}:${stat.birthtimeNs}` : void 0;
|
|
999
1641
|
const reset = from > size || priorGeneration !== void 0 && generation !== priorGeneration;
|
|
1000
1642
|
const start = reset ? 0 : from;
|
|
1001
1643
|
const length = Math.min(size - start, MAX_OUTPUT_BYTES);
|
|
1002
1644
|
const buffer = Buffer.alloc(length);
|
|
1003
|
-
const read = length === 0 ? 0 :
|
|
1645
|
+
const read = length === 0 ? 0 : (await descriptor.read(buffer, 0, length, start)).bytesRead;
|
|
1004
1646
|
const offset = start + read;
|
|
1005
1647
|
const hasMore = offset < size;
|
|
1006
1648
|
return {
|
|
@@ -1013,7 +1655,7 @@ function readOutput(file, from, running, priorGeneration, screen = false) {
|
|
|
1013
1655
|
ended: !running && !hasMore
|
|
1014
1656
|
};
|
|
1015
1657
|
} finally {
|
|
1016
|
-
|
|
1658
|
+
await descriptor.close();
|
|
1017
1659
|
}
|
|
1018
1660
|
}
|
|
1019
1661
|
function logQueryOf(url) {
|
|
@@ -1056,7 +1698,7 @@ function createRunnerLogApi(options) {
|
|
|
1056
1698
|
return paneBackend;
|
|
1057
1699
|
};
|
|
1058
1700
|
/** The record behind a request, or undefined when this session has no such run. */
|
|
1059
|
-
const runnerOf = (runId) => isSafeSegment(runId) ? resolveLogFile(stateDir, logsDir, sessionId, runId) : void 0;
|
|
1701
|
+
const runnerOf = async (runId) => isSafeSegment(runId) ? resolveLogFile(stateDir, logsDir, sessionId, runId) : void 0;
|
|
1060
1702
|
/**
|
|
1061
1703
|
* The owned pane whose recorded output a request may read.
|
|
1062
1704
|
*
|
|
@@ -1066,8 +1708,8 @@ function createRunnerLogApi(options) {
|
|
|
1066
1708
|
* interactive. A non-interactive run has no terminal to type into, and a
|
|
1067
1709
|
* subprocess-backed run has no pane at all.
|
|
1068
1710
|
*/
|
|
1069
|
-
const paneOf = (runId) => {
|
|
1070
|
-
const record = runnerOf(runId);
|
|
1711
|
+
const paneOf = async (runId) => {
|
|
1712
|
+
const record = await runnerOf(runId);
|
|
1071
1713
|
if (record === void 0 || record.interactive !== true) return void 0;
|
|
1072
1714
|
const target = record.backendTarget;
|
|
1073
1715
|
if (target === void 0 || !MULTIPLEXER_BACKENDS.has(record.backend) || !isSafeSegment(target)) return void 0;
|
|
@@ -1076,35 +1718,35 @@ function createRunnerLogApi(options) {
|
|
|
1076
1718
|
target
|
|
1077
1719
|
};
|
|
1078
1720
|
};
|
|
1079
|
-
const attachableOf = (runId) => {
|
|
1080
|
-
const owned = paneOf(runId);
|
|
1721
|
+
const attachableOf = async (runId) => {
|
|
1722
|
+
const owned = await paneOf(runId);
|
|
1081
1723
|
return owned?.record.state === "running" ? owned : void 0;
|
|
1082
1724
|
};
|
|
1083
|
-
for (const [route, screen] of [[routes.logRead, false], [routes.screenRead, true]]) app.get(route.path, (context) => {
|
|
1725
|
+
for (const [route, screen] of [[routes.logRead, false], [routes.screenRead, true]]) app.get(route.path, async (context) => {
|
|
1084
1726
|
const runId = context.req.param(RUN_ID_PARAM);
|
|
1085
|
-
const record = screen ? paneOf(runId)?.record : runnerOf(runId);
|
|
1727
|
+
const record = screen ? (await paneOf(runId))?.record : await runnerOf(runId);
|
|
1086
1728
|
if (record === void 0) return context.json({ error: screen ? NOT_ATTACHABLE : `No runner '${runId}' in this session.` }, 404);
|
|
1087
1729
|
const value = context.req.query(RUNNER_LOG_PARAMS.from);
|
|
1088
1730
|
const from = value === void 0 ? 0 : Number(value);
|
|
1089
1731
|
if (value !== void 0 && !/^\d+$/.test(value) || !Number.isSafeInteger(from) || from < 0) return context.json({ error: "Expected a non-negative safe integer byte offset." }, 400);
|
|
1090
1732
|
const file = screen ? `${record.logPath}${RAW_LOG_SUFFIX}` : record.logPath;
|
|
1091
|
-
if (!isSessionLog(file, logsDir)) return context.json({ error: "No readable output in this session." }, 404);
|
|
1092
|
-
return context.json(readOutput(file, from, record.state === RUNNING_STATE, screen ? context.req.query(RUNNER_LOG_PARAMS.generation) : void 0, screen));
|
|
1733
|
+
if (!await isSessionLog(file, logsDir)) return context.json({ error: "No readable output in this session." }, 404);
|
|
1734
|
+
return context.json(await readOutput(file, from, record.state === RUNNING_STATE, screen ? context.req.query(RUNNER_LOG_PARAMS.generation) : void 0, screen));
|
|
1093
1735
|
});
|
|
1094
|
-
app.get(routes.log.path, (context) => {
|
|
1736
|
+
app.get(routes.log.path, async (context) => {
|
|
1095
1737
|
const runId = context.req.param(RUN_ID_PARAM);
|
|
1096
|
-
const record = runnerOf(runId);
|
|
1738
|
+
const record = await runnerOf(runId);
|
|
1097
1739
|
if (record === void 0) return context.json({ error: `No runner '${runId}' in this session.` }, 404);
|
|
1098
1740
|
const body = {
|
|
1099
|
-
...logReader.read(record.logPath, logQueryOf(new URL(context.req.url))),
|
|
1741
|
+
...await logReader.read(record.logPath, logQueryOf(new URL(context.req.url))),
|
|
1100
1742
|
runId,
|
|
1101
1743
|
running: record.state === RUNNING_STATE
|
|
1102
1744
|
};
|
|
1103
1745
|
return context.json(body);
|
|
1104
1746
|
});
|
|
1105
|
-
app.get(routes.logStream.path, (context) => {
|
|
1747
|
+
app.get(routes.logStream.path, async (context) => {
|
|
1106
1748
|
const runId = context.req.param(RUN_ID_PARAM);
|
|
1107
|
-
const record = runnerOf(runId);
|
|
1749
|
+
const record = await runnerOf(runId);
|
|
1108
1750
|
if (record === void 0) return context.json({ error: `No runner '${runId}' in this session.` }, 404);
|
|
1109
1751
|
const from = numberParam(new URL(context.req.url).searchParams.get(RUNNER_LOG_PARAMS.from) ?? void 0, 0, Number.MAX_SAFE_INTEGER);
|
|
1110
1752
|
return streamSSE(context, async (stream) => {
|
|
@@ -1128,8 +1770,8 @@ function createRunnerLogApi(options) {
|
|
|
1128
1770
|
}),
|
|
1129
1771
|
onError: () => finish()
|
|
1130
1772
|
});
|
|
1131
|
-
const poll = setInterval(() => {
|
|
1132
|
-
const current = runnerOf(runId);
|
|
1773
|
+
const poll = setInterval(async () => {
|
|
1774
|
+
const current = await runnerOf(runId);
|
|
1133
1775
|
if (current !== void 0 && current.state === "running") return;
|
|
1134
1776
|
queue({
|
|
1135
1777
|
lines: [],
|
|
@@ -1151,9 +1793,9 @@ function createRunnerLogApi(options) {
|
|
|
1151
1793
|
await pump;
|
|
1152
1794
|
});
|
|
1153
1795
|
});
|
|
1154
|
-
app.get(routes.screenStream.path, (context) => {
|
|
1796
|
+
app.get(routes.screenStream.path, async (context) => {
|
|
1155
1797
|
const runId = context.req.param(RUN_ID_PARAM);
|
|
1156
|
-
const attachable = attachableOf(runId);
|
|
1798
|
+
const attachable = await attachableOf(runId);
|
|
1157
1799
|
if (attachable === void 0) return context.json({ error: NOT_ATTACHABLE }, 404);
|
|
1158
1800
|
const rawPath = `${attachable.record.logPath}${RAW_LOG_SUFFIX}`;
|
|
1159
1801
|
const from = numberParam(new URL(context.req.url).searchParams.get(RUNNER_LOG_PARAMS.from) ?? void 0, 0, Number.MAX_SAFE_INTEGER);
|
|
@@ -1170,10 +1812,10 @@ function createRunnerLogApi(options) {
|
|
|
1170
1812
|
finish = resolve;
|
|
1171
1813
|
});
|
|
1172
1814
|
let offset = from;
|
|
1173
|
-
const drain = () => {
|
|
1815
|
+
const drain = async () => {
|
|
1174
1816
|
let size;
|
|
1175
1817
|
try {
|
|
1176
|
-
size = fs.
|
|
1818
|
+
size = (await fs.stat(rawPath)).size;
|
|
1177
1819
|
} catch {
|
|
1178
1820
|
return;
|
|
1179
1821
|
}
|
|
@@ -1181,12 +1823,12 @@ function createRunnerLogApi(options) {
|
|
|
1181
1823
|
if (size === offset) return;
|
|
1182
1824
|
const length = size - offset;
|
|
1183
1825
|
const buffer = Buffer.alloc(length);
|
|
1184
|
-
const descriptor = fs.
|
|
1826
|
+
const descriptor = await fs.open(rawPath, "r");
|
|
1185
1827
|
let read;
|
|
1186
1828
|
try {
|
|
1187
|
-
read =
|
|
1829
|
+
({bytesRead: read} = await descriptor.read(buffer, 0, length, offset));
|
|
1188
1830
|
} finally {
|
|
1189
|
-
|
|
1831
|
+
await descriptor.close();
|
|
1190
1832
|
}
|
|
1191
1833
|
if (read <= 0) return;
|
|
1192
1834
|
offset += read;
|
|
@@ -1195,20 +1837,32 @@ function createRunnerLogApi(options) {
|
|
|
1195
1837
|
offset
|
|
1196
1838
|
});
|
|
1197
1839
|
};
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
if (
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1840
|
+
let polling = false;
|
|
1841
|
+
let stopped = false;
|
|
1842
|
+
const poll = setInterval(async () => {
|
|
1843
|
+
if (polling || stopped) return;
|
|
1844
|
+
polling = true;
|
|
1845
|
+
try {
|
|
1846
|
+
const current = await runnerOf(runId);
|
|
1847
|
+
await drain();
|
|
1848
|
+
if (stopped) return;
|
|
1849
|
+
if (current === void 0 || current.state !== "running") {
|
|
1850
|
+
queue({
|
|
1851
|
+
chunk: "",
|
|
1852
|
+
offset,
|
|
1853
|
+
ended: true
|
|
1854
|
+
});
|
|
1855
|
+
finish();
|
|
1856
|
+
}
|
|
1857
|
+
} catch {
|
|
1207
1858
|
finish();
|
|
1859
|
+
} finally {
|
|
1860
|
+
polling = false;
|
|
1208
1861
|
}
|
|
1209
1862
|
}, 100);
|
|
1210
1863
|
stream.onAbort(() => finish());
|
|
1211
1864
|
await done;
|
|
1865
|
+
stopped = true;
|
|
1212
1866
|
clearInterval(poll);
|
|
1213
1867
|
await pump;
|
|
1214
1868
|
});
|
|
@@ -1222,7 +1876,7 @@ function createRunnerLogApi(options) {
|
|
|
1222
1876
|
*/
|
|
1223
1877
|
app.post(routes.input.path, async (context) => {
|
|
1224
1878
|
const runId = context.req.param(RUN_ID_PARAM);
|
|
1225
|
-
const attachable = attachableOf(runId);
|
|
1879
|
+
const attachable = await attachableOf(runId);
|
|
1226
1880
|
if (attachable === void 0) return context.json({ error: NOT_ATTACHABLE }, 404);
|
|
1227
1881
|
let body;
|
|
1228
1882
|
try {
|
|
@@ -1238,17 +1892,8 @@ function createRunnerLogApi(options) {
|
|
|
1238
1892
|
});
|
|
1239
1893
|
return app;
|
|
1240
1894
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
/**
|
|
1244
|
-
* Mounts this package's HTTP API at `runner`, which the folder names.
|
|
1245
|
-
*
|
|
1246
|
-
* The folder is the declaration: the build reads the base path off it and hands
|
|
1247
|
-
* the browser a client bound to the same segment, so the mount is stated once
|
|
1248
|
-
* rather than in a constant and in four URL builders that were each free to
|
|
1249
|
-
* drift.
|
|
1250
|
-
*/
|
|
1251
|
-
var route_server_default = defineRoute({
|
|
1895
|
+
/** The named export a host imports from this package's built session entry. */
|
|
1896
|
+
const api = {
|
|
1252
1897
|
basePath: RUNNER_API_BASE_PATH,
|
|
1253
1898
|
start(context) {
|
|
1254
1899
|
const app = createRunnerLogApi({
|
|
@@ -1261,25 +1906,53 @@ var route_server_default = defineRoute({
|
|
|
1261
1906
|
close: () => void 0
|
|
1262
1907
|
};
|
|
1263
1908
|
}
|
|
1264
|
-
}
|
|
1909
|
+
};
|
|
1910
|
+
/** The edge build reads its run records from the session root (`index.edge.ts`). Node has its own registry. */
|
|
1911
|
+
function createRunnerApi(_root) {
|
|
1912
|
+
return api;
|
|
1913
|
+
}
|
|
1914
|
+
//#endregion
|
|
1915
|
+
//#region src/extensions/workspaces/sessions/(backend)/api/runner/route.server.ts
|
|
1916
|
+
/**
|
|
1917
|
+
* Mounts this package's HTTP API at `runner`, which the folder names.
|
|
1918
|
+
*
|
|
1919
|
+
* The folder is the declaration: the build reads the base path off it and hands
|
|
1920
|
+
* the browser a client bound to the same segment, so the mount is stated once
|
|
1921
|
+
* rather than in a constant and in four URL builders that were each free to
|
|
1922
|
+
* drift.
|
|
1923
|
+
*/
|
|
1924
|
+
var route_server_default = defineRoute(({ root }) => createRunnerApi(root));
|
|
1265
1925
|
//#endregion
|
|
1266
1926
|
//#region src/extensions/workspaces/sessions/(backend)/command/runners.server.ts
|
|
1267
1927
|
var runners_server_default = defineServerCommand((context) => context.root.command);
|
|
1268
1928
|
//#endregion
|
|
1269
1929
|
//#region src/extensions/workspaces/sessions/(backend)/hook/session-compact.server.ts
|
|
1270
1930
|
var session_compact_server_default = defineHook(({ root }) => ({
|
|
1931
|
+
name: "restore-runner-compaction-context",
|
|
1932
|
+
description: "For a new completed compaction in a live runner session, append recovery context for running processes and sequences when available.",
|
|
1271
1933
|
event: "session_compact",
|
|
1272
1934
|
handle: root.recoverCompaction
|
|
1273
1935
|
}));
|
|
1274
1936
|
//#endregion
|
|
1275
|
-
//#region src/extensions/workspaces/sessions/(backend)/resource/
|
|
1276
|
-
|
|
1277
|
-
|
|
1937
|
+
//#region src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-runner.server.ts
|
|
1938
|
+
const skillFile = "src/prompts/codemode-how-to-runner/SKILL.md";
|
|
1939
|
+
var codemode_how_to_runner_server_default = defineResource({
|
|
1940
|
+
name: "codemode-how-to-runner",
|
|
1941
|
+
description: "Inspect supervised shell commands and sequential command groups, read saved logs, provide interactive input, and stop unused work through the runner namespace in code mode.",
|
|
1942
|
+
kind: "skill",
|
|
1943
|
+
pinned: true,
|
|
1944
|
+
path: packageResourcePath(import.meta.url, skillFile),
|
|
1945
|
+
read: () => readPackageResource(import.meta.url, skillFile)
|
|
1946
|
+
});
|
|
1947
|
+
//#endregion
|
|
1948
|
+
//#region src/extensions/workspaces/sessions/(backend)/resource/help-how-to-runner.server.ts
|
|
1949
|
+
var help_how_to_runner_server_default = defineResource({
|
|
1950
|
+
name: "help-how-to-runner",
|
|
1278
1951
|
description: "Use Po Pi Runner to supervise shell commands, inspect durable logs, provide interactive input, and stop background runs.",
|
|
1279
1952
|
when: PO_HELP_WHEN,
|
|
1280
1953
|
kind: "skill",
|
|
1281
|
-
path: packageResourcePath(import.meta.url, "src/prompts/
|
|
1282
|
-
read: () => readPackageResource(import.meta.url, "src/prompts/
|
|
1954
|
+
path: packageResourcePath(import.meta.url, "src/prompts/help-how-to-runner/SKILL.md"),
|
|
1955
|
+
read: () => readPackageResource(import.meta.url, "src/prompts/help-how-to-runner/SKILL.md")
|
|
1283
1956
|
});
|
|
1284
1957
|
//#endregion
|
|
1285
1958
|
//#region src/extensions/workspaces/sessions/(backend)/tool/bash.server.ts
|
|
@@ -1289,19 +1962,27 @@ var bash_server_default = defineServerTool((context) => context.root.tool);
|
|
|
1289
1962
|
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
1290
1963
|
/* v8 ignore next -- generated normalization branch */
|
|
1291
1964
|
const defined = (values) => values.filter((value) => value !== void 0);
|
|
1292
|
-
const via = (identity, value) =>
|
|
1293
|
-
|
|
1294
|
-
|
|
1965
|
+
const via = (identity, value) => {
|
|
1966
|
+
if (value === void 0) return void 0;
|
|
1967
|
+
const declaration = value;
|
|
1968
|
+
return {
|
|
1969
|
+
...identity,
|
|
1970
|
+
...declaration,
|
|
1971
|
+
...declaration.relations === void 0 ? {} : { relations: declaration.relations.map((relation) => ({
|
|
1972
|
+
evidence: "declared",
|
|
1973
|
+
...relation
|
|
1974
|
+
})) }
|
|
1975
|
+
};
|
|
1295
1976
|
};
|
|
1296
1977
|
const serverPlugin = defineServerPlugin({
|
|
1297
1978
|
name: "@agimon-ai/po-runner",
|
|
1298
1979
|
providerOverrides: composeServerProviderOverrides(root_server_default),
|
|
1299
1980
|
injects: composeRootInjects({ session: [root_server_default] }),
|
|
1300
|
-
|
|
1301
|
-
return [() => via({ frameType: "runner_runs" }, runnerRuns_server_default
|
|
1981
|
+
host: (context) => ({ get channels() {
|
|
1982
|
+
return [() => via({ frameType: "runner_runs" }, at(runnerRuns_server_default, context))];
|
|
1302
1983
|
} }),
|
|
1303
1984
|
workspace: (context) => ({ get channels() {
|
|
1304
|
-
return defined([context.hosted("
|
|
1985
|
+
return defined([context.hosted("host") ? void 0 : () => via({ frameType: "runner_runs" }, at(runnerRuns_server_default, context))]);
|
|
1305
1986
|
} }),
|
|
1306
1987
|
session: async (context) => {
|
|
1307
1988
|
const scopeSession = await context.scopeRoot("session", root_server_default, context);
|
|
@@ -1315,7 +1996,7 @@ const serverPlugin = defineServerPlugin({
|
|
|
1315
1996
|
return [at(route_server_default, contextSession)];
|
|
1316
1997
|
},
|
|
1317
1998
|
get channels() {
|
|
1318
|
-
return defined([context.hosted("
|
|
1999
|
+
return defined([context.hosted("host") ? void 0 : () => via({ frameType: "runner_runs" }, at(runnerRuns_server_default, context))]);
|
|
1319
2000
|
},
|
|
1320
2001
|
get commands() {
|
|
1321
2002
|
return [via({ name: "runners" }, at(runners_server_default, contextSession))];
|
|
@@ -1324,7 +2005,7 @@ const serverPlugin = defineServerPlugin({
|
|
|
1324
2005
|
return [via({ event: "session_compact" }, at(session_compact_server_default, contextSession))];
|
|
1325
2006
|
},
|
|
1326
2007
|
get resources() {
|
|
1327
|
-
return [at(
|
|
2008
|
+
return [at(codemode_how_to_runner_server_default, contextSession), at(help_how_to_runner_server_default, contextSession)];
|
|
1328
2009
|
},
|
|
1329
2010
|
get tools() {
|
|
1330
2011
|
return [via({ name: "bash" }, at(bash_server_default, contextSession))];
|