@agimon-ai/po-runner 0.0.0-alpha.21 → 0.0.0-alpha.211
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -149
- package/README.md +34 -206
- package/dist/apiContracts.cjs +45 -2
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +45 -2
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/{bashResult-BqDa7sbC.mjs → bashResult-BLCLerXE.mjs} +57 -7
- package/dist/bashResult-BLCLerXE.mjs.map +1 -0
- package/dist/{bashResult-C2iKhHpD.cjs → bashResult-CZYiyl4p.cjs} +74 -6
- package/dist/bashResult-CZYiyl4p.cjs.map +1 -0
- package/dist/{bashResult-DcrRaBLv.d.mts → bashResult-CgVS_JpL.d.mts} +8 -3
- package/dist/{bashResult-DcrRaBLv.d.mts.map → bashResult-CgVS_JpL.d.mts.map} +1 -1
- package/dist/{bashRunService-DjOH5kye.cjs → bashRunService-DmuA1mKL.cjs} +52 -31
- package/dist/bashRunService-DmuA1mKL.cjs.map +1 -0
- package/dist/{bashRunService-Ci0cGdYO.d.mts → bashRunService-Iotfc_nV.d.mts} +21 -2
- package/dist/bashRunService-Iotfc_nV.d.mts.map +1 -0
- package/dist/{bashRunService-Cl3pYccr.mjs → bashRunService-Luy2hPMS.mjs} +52 -31
- package/dist/bashRunService-Luy2hPMS.mjs.map +1 -0
- package/dist/bashRunService.cjs +1 -1
- package/dist/bashRunService.d.mts +4 -4
- package/dist/bashRunService.d.mts.map +1 -1
- package/dist/bashRunService.mjs +1 -1
- package/dist/bashSchema.cjs +1 -1
- package/dist/bashSchema.d.mts +1 -1
- package/dist/bashSchema.mjs +1 -1
- package/dist/bashTool-D2ECDAhc.cjs +43 -0
- package/dist/bashTool-D2ECDAhc.cjs.map +1 -0
- package/dist/{bashTool-B1EwZLo_.d.mts → bashTool-Dc1ld2E3.d.mts} +3 -9
- package/dist/bashTool-Dc1ld2E3.d.mts.map +1 -0
- package/dist/bashTool-vg8uhbkj.mjs +26 -0
- package/dist/bashTool-vg8uhbkj.mjs.map +1 -0
- package/dist/bashTool.cjs +3 -3
- package/dist/bashTool.cjs.map +1 -1
- package/dist/bashTool.d.mts +4 -4
- package/dist/bashTool.d.mts.map +1 -1
- package/dist/bashTool.mjs +3 -3
- package/dist/bashTool.mjs.map +1 -1
- package/dist/bin/cli.cjs +372 -9
- package/dist/bin/cli.cjs.map +1 -1
- package/dist/bin/cli.d.mts.map +1 -1
- package/dist/bin/cli.mjs +369 -8
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/bin/logSink.cjs +27 -24
- package/dist/bin/logSink.cjs.map +1 -1
- package/dist/bin/logSink.mjs +24 -21
- package/dist/bin/logSink.mjs.map +1 -1
- package/dist/bin/runnerHost.cjs +141 -53
- package/dist/bin/runnerHost.cjs.map +1 -1
- package/dist/bin/runnerHost.d.mts.map +1 -1
- package/dist/bin/runnerHost.mjs +141 -53
- package/dist/bin/runnerHost.mjs.map +1 -1
- package/dist/cliApp-7iTUx5KZ.cjs +351 -0
- package/dist/cliApp-7iTUx5KZ.cjs.map +1 -0
- package/dist/cliApp-S4iEO-fi.mjs +338 -0
- package/dist/cliApp-S4iEO-fi.mjs.map +1 -0
- package/dist/cliApp.cjs +2 -1
- package/dist/cliApp.d.mts +9 -4
- package/dist/cliApp.d.mts.map +1 -1
- package/dist/cliApp.mjs +1 -1
- package/dist/compaction.d.mts +1 -1
- package/dist/extensions/mcp-ui.mjs +7 -6
- package/dist/extensions/mcp-ui.mjs.map +1 -1
- package/dist/extensions/mcp.cjs +37 -17
- package/dist/extensions/mcp.cjs.map +1 -1
- package/dist/extensions/mcp.d.mts.map +1 -1
- package/dist/extensions/mcp.mjs +37 -17
- package/dist/extensions/mcp.mjs.map +1 -1
- package/dist/extensions/native.mjs +1225 -374
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +900 -221
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +908 -227
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +924 -766
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/headless-CMj9hunm.cjs +237 -0
- package/dist/headless-CMj9hunm.cjs.map +1 -0
- package/dist/headless-CUJt5Ihx.mjs +226 -0
- package/dist/headless-CUJt5Ihx.mjs.map +1 -0
- package/dist/{index-DM7yJpMs.d.mts → index-7_nuKoVm.d.mts} +6 -6
- package/dist/index-7_nuKoVm.d.mts.map +1 -0
- package/dist/index-BCCF1sGD.d.mts.map +1 -1
- package/dist/{index-CzCF_OP9.d.mts → index-CH-z0BX3.d.mts} +11 -4
- package/dist/index-CH-z0BX3.d.mts.map +1 -0
- package/dist/{index-C-IC35d9.d.mts → index-CJNsR-Ir.d.mts} +10 -7
- package/dist/index-CJNsR-Ir.d.mts.map +1 -0
- package/dist/{index--xF7DvsE.d.mts → index-CNCb1usM.d.mts} +8 -2
- package/dist/index-CNCb1usM.d.mts.map +1 -0
- package/dist/index-EMbmq9gu.d.mts +45 -0
- package/dist/index-EMbmq9gu.d.mts.map +1 -0
- package/dist/index-QlfncPRs.d.mts +58 -0
- package/dist/index-QlfncPRs.d.mts.map +1 -0
- package/dist/index-qSi4-EJW.d.mts +49 -0
- package/dist/index-qSi4-EJW.d.mts.map +1 -0
- package/dist/index.cjs +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/launch.cjs +4 -0
- package/dist/launch.d.mts +55 -0
- package/dist/launch.d.mts.map +1 -0
- package/dist/launch.mjs +1 -0
- package/dist/{launcher-CCYsFBM9.mjs → launcher-3xMxw72I.mjs} +45 -31
- package/dist/launcher-3xMxw72I.mjs.map +1 -0
- package/dist/{launcher-BG5t9nvG.d.mts → launcher-CDDBTvZq.d.mts} +4 -3
- package/dist/launcher-CDDBTvZq.d.mts.map +1 -0
- package/dist/{launcher-ZgDdyXpq.cjs → launcher-D7qAhSRL.cjs} +47 -33
- package/dist/launcher-D7qAhSRL.cjs.map +1 -0
- package/dist/launcher.cjs +1 -1
- package/dist/launcher.d.mts +5 -5
- package/dist/launcher.d.mts.map +1 -1
- package/dist/launcher.mjs +1 -1
- package/dist/lifeline-26IaW5w7.d.mts +34 -0
- package/dist/lifeline-26IaW5w7.d.mts.map +1 -0
- package/dist/lifeline-B4cjtrBe.cjs +27 -0
- package/dist/lifeline-B4cjtrBe.cjs.map +1 -0
- package/dist/lifeline-C1v2ItCY.mjs +214 -0
- package/dist/lifeline-C1v2ItCY.mjs.map +1 -0
- package/dist/lifeline-D4_ZRAhO.cjs +229 -0
- package/dist/lifeline-D4_ZRAhO.cjs.map +1 -0
- package/dist/lifeline-nPh3cx5A.mjs +10 -0
- package/dist/lifeline-nPh3cx5A.mjs.map +1 -0
- package/dist/lifeline.cjs +4 -1
- package/dist/lifeline.d.mts +4 -21
- package/dist/lifeline.mjs +3 -3
- package/dist/logFile-B9FSwmE0.cjs +44 -0
- package/dist/logFile-B9FSwmE0.cjs.map +1 -0
- package/dist/{logFile-C7oQ_v-g.d.mts → logFile-BirfZtS1.d.mts} +4 -4
- package/dist/logFile-BirfZtS1.d.mts.map +1 -0
- package/dist/logFile-D1EOKqmL.mjs +39 -0
- package/dist/logFile-D1EOKqmL.mjs.map +1 -0
- package/dist/logFile.cjs +1 -1
- package/dist/logFile.d.mts +3 -3
- package/dist/logFile.d.mts.map +1 -1
- package/dist/logFile.mjs +1 -1
- package/dist/{logReader-mq9uVurh.mjs → logReader-BYKii_s_.mjs} +99 -52
- package/dist/logReader-BYKii_s_.mjs.map +1 -0
- package/dist/{logReader-MdW9ffvV.d.mts → logReader-Bn3WEdjg.d.mts} +4 -2
- package/dist/{logReader-MdW9ffvV.d.mts.map → logReader-Bn3WEdjg.d.mts.map} +1 -1
- package/dist/{logReader-DHCK2BEr.cjs → logReader-DpMjBqfn.cjs} +101 -54
- package/dist/logReader-DpMjBqfn.cjs.map +1 -0
- package/dist/logReader.cjs +1 -1
- package/dist/logReader.d.mts +2 -2
- package/dist/logReader.mjs +1 -1
- package/dist/po-runtime-identity.json +1 -0
- package/dist/{ptyHost-D35hNmtd.cjs → ptyHost-C-oWV455.cjs} +20 -14
- package/dist/ptyHost-C-oWV455.cjs.map +1 -0
- package/dist/{ptyHost-CwbLLr90.mjs → ptyHost-C2zu-ZfO.mjs} +19 -13
- package/dist/ptyHost-C2zu-ZfO.mjs.map +1 -0
- package/dist/{ptyHost-DWWtRrGn.d.mts → ptyHost-C_6x2xuJ.d.mts} +2 -2
- package/dist/{ptyHost-DWWtRrGn.d.mts.map → ptyHost-C_6x2xuJ.d.mts.map} +1 -1
- package/dist/ptyHost.cjs +1 -1
- package/dist/ptyHost.d.mts +2 -2
- package/dist/ptyHost.d.mts.map +1 -1
- package/dist/ptyHost.mjs +1 -1
- package/dist/{reconcile-wNYQJZF-.mjs → reconcile-DUaX_vKZ.mjs} +2 -2
- package/dist/reconcile-DUaX_vKZ.mjs.map +1 -0
- package/dist/{reconcile-5cZ11jSD.cjs → reconcile-DjF9T1hN.cjs} +2 -2
- package/dist/reconcile-DjF9T1hN.cjs.map +1 -0
- package/dist/reconcile.cjs +1 -1
- package/dist/reconcile.d.mts +3 -3
- package/dist/reconcile.mjs +1 -1
- package/dist/responseEnvelope.cjs +5 -2
- package/dist/responseEnvelope.d.mts +15 -6
- package/dist/responseEnvelope.d.mts.map +1 -1
- package/dist/responseEnvelope.mjs +3 -3
- package/dist/{rmuxBackend-Dh0CYVAL.cjs → rmuxBackend-9tHTx1vf.cjs} +82 -48
- package/dist/rmuxBackend-9tHTx1vf.cjs.map +1 -0
- package/dist/{rmuxBackend-rjrVTG6K.mjs → rmuxBackend-BaK-R35I.mjs} +79 -45
- package/dist/rmuxBackend-BaK-R35I.mjs.map +1 -0
- package/dist/{rmuxBackend-CaEWooWn.d.mts → rmuxBackend-xFzlANM9.d.mts} +4 -4
- package/dist/rmuxBackend-xFzlANM9.d.mts.map +1 -0
- package/dist/rmuxBackend.cjs +1 -1
- package/dist/rmuxBackend.d.mts +2 -2
- package/dist/rmuxBackend.mjs +1 -1
- package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → rolldown-runtime-C0BPl7ul.cjs} +15 -0
- package/dist/{rtkProcessor-Iw9gP5Xp.mjs → rtkProcessor-DOXcp51z.mjs} +6 -5
- package/dist/rtkProcessor-DOXcp51z.mjs.map +1 -0
- package/dist/{rtkProcessor-DSGbM-Cm.cjs → rtkProcessor-J2gLQvM4.cjs} +8 -6
- package/dist/rtkProcessor-J2gLQvM4.cjs.map +1 -0
- package/dist/rtkProcessor.cjs +1 -1
- package/dist/rtkProcessor.mjs +1 -1
- package/dist/{runnerDependencies-DSun3xO-.cjs → runnerDependencies-CABYjW7H.cjs} +97 -64
- package/dist/runnerDependencies-CABYjW7H.cjs.map +1 -0
- package/dist/{runnerDependencies-7h_cxOva.mjs → runnerDependencies-DmvIcpZi.mjs} +95 -62
- package/dist/runnerDependencies-DmvIcpZi.mjs.map +1 -0
- package/dist/runnerDependencies.cjs +1 -1
- package/dist/runnerDependencies.d.mts +1 -1
- package/dist/runnerDependencies.mjs +1 -1
- package/dist/runnerHost-BvNYPMeh.mjs +165 -0
- package/dist/runnerHost-BvNYPMeh.mjs.map +1 -0
- package/dist/runnerHost-C2F5oxzn.cjs +184 -0
- package/dist/runnerHost-C2F5oxzn.cjs.map +1 -0
- package/dist/runnerLaunch-BAf7hXMr.cjs +192 -0
- package/dist/runnerLaunch-BAf7hXMr.cjs.map +1 -0
- package/dist/runnerLaunch-Bimgdh4h.mjs +175 -0
- package/dist/runnerLaunch-Bimgdh4h.mjs.map +1 -0
- package/dist/runnerNamer.d.mts +1 -1
- package/dist/{runnerPaths-B41rMOY6.cjs → runnerPaths-CSkswyjR.cjs} +97 -179
- package/dist/runnerPaths-CSkswyjR.cjs.map +1 -0
- package/dist/{runnerPaths-Dibbvyx_.mjs → runnerPaths-D3P7_EhW.mjs} +91 -179
- package/dist/runnerPaths-D3P7_EhW.mjs.map +1 -0
- package/dist/runnerPaths.cjs +1 -1
- package/dist/runnerPaths.d.mts +7 -9
- package/dist/runnerPaths.d.mts.map +1 -1
- package/dist/runnerPaths.mjs +1 -1
- package/dist/{runnerRegistry-dQYlMSpQ.cjs → runnerRegistry-B8K1L3lq.cjs} +68 -45
- package/dist/runnerRegistry-B8K1L3lq.cjs.map +1 -0
- package/dist/{runnerRegistry-V-Ocaf4N.d.mts → runnerRegistry-BlZhS9yL.d.mts} +2 -2
- package/dist/{runnerRegistry-V-Ocaf4N.d.mts.map → runnerRegistry-BlZhS9yL.d.mts.map} +1 -1
- package/dist/{runnerRegistry-BgaR5O86.mjs → runnerRegistry-Dqca6SD3.mjs} +53 -29
- package/dist/runnerRegistry-Dqca6SD3.mjs.map +1 -0
- package/dist/runnerRegistry-NW6oAJ71.cjs +60 -0
- package/dist/runnerRegistry-NW6oAJ71.cjs.map +1 -0
- package/dist/runnerRegistry-l0C_55oO.mjs +13 -0
- package/dist/runnerRegistry-l0C_55oO.mjs.map +1 -0
- package/dist/runnerRegistry.cjs +1 -1
- package/dist/runnerRegistry.d.mts +2 -2
- package/dist/runnerRegistry.mjs +1 -1
- package/dist/runnerSequence-ZTYgZ_2W.cjs +32 -0
- package/dist/runnerSequence-ZTYgZ_2W.cjs.map +1 -0
- package/dist/runnerSequence-k-_Fd77y.mjs +9 -0
- package/dist/runnerSequence-k-_Fd77y.mjs.map +1 -0
- package/dist/runnerSequenceStore-CaY7S_Sd.mjs +76 -0
- package/dist/runnerSequenceStore-CaY7S_Sd.mjs.map +1 -0
- package/dist/runnerSequenceStore-Ck6M-8r_.cjs +89 -0
- package/dist/runnerSequenceStore-Ck6M-8r_.cjs.map +1 -0
- package/dist/services/lifeline/client.cjs +88 -4
- package/dist/services/lifeline/client.cjs.map +1 -1
- package/dist/services/lifeline/client.d.mts +16 -0
- package/dist/services/lifeline/client.d.mts.map +1 -1
- package/dist/services/lifeline/client.mjs +83 -2
- package/dist/services/lifeline/client.mjs.map +1 -1
- package/dist/services/runnerSupervisor/index.cjs +36 -22
- package/dist/services/runnerSupervisor/index.cjs.map +1 -1
- package/dist/services/runnerSupervisor/index.d.mts +7 -5
- package/dist/services/runnerSupervisor/index.d.mts.map +1 -1
- package/dist/services/runnerSupervisor/index.mjs +35 -21
- package/dist/services/runnerSupervisor/index.mjs.map +1 -1
- package/dist/session-CdVeSD7F.mjs +8 -0
- package/dist/session-CdVeSD7F.mjs.map +1 -0
- package/dist/session-DnUj8Q71.cjs +25 -0
- package/dist/session-DnUj8Q71.cjs.map +1 -0
- package/dist/session-ISEGK4z9.mjs +26 -0
- package/dist/session-ISEGK4z9.mjs.map +1 -0
- package/dist/session-PQd3azWf.cjs +43 -0
- package/dist/session-PQd3azWf.cjs.map +1 -0
- package/dist/session.cjs +4 -3
- package/dist/session.d.mts +3 -1
- package/dist/session.d.mts.map +1 -1
- package/dist/session.mjs +3 -3
- package/dist/{type-DwMZoINK.d.mts → type-BWY9vvSq.d.mts} +6 -4
- package/dist/type-BWY9vvSq.d.mts.map +1 -0
- package/dist/{type-Do0YxwVQ.d.mts → type-bZgYQ7hv.d.mts} +11 -11
- package/dist/{type-Do0YxwVQ.d.mts.map → type-bZgYQ7hv.d.mts.map} +1 -1
- package/dist/types.d.mts +1 -1
- package/llms.txt +2 -1
- package/locales/vi.json +169 -0
- package/locales/zh-CN.json +169 -0
- package/package.json +95 -30
- package/skills/po-runner/SKILL.md +32 -14
- package/src/prompts/codemode-how-to-runner/SKILL.md +85 -0
- package/src/prompts/help-how-to-runner/SKILL.md +51 -0
- package/dist/bashResult-BqDa7sbC.mjs.map +0 -1
- package/dist/bashResult-C2iKhHpD.cjs.map +0 -1
- package/dist/bashRunService-Ci0cGdYO.d.mts.map +0 -1
- package/dist/bashRunService-Cl3pYccr.mjs.map +0 -1
- package/dist/bashRunService-DjOH5kye.cjs.map +0 -1
- package/dist/bashTool-B1EwZLo_.d.mts.map +0 -1
- package/dist/bashTool-BvC3YOgG.mjs +0 -24
- package/dist/bashTool-BvC3YOgG.mjs.map +0 -1
- package/dist/bashTool-euL6zMDl.cjs +0 -41
- package/dist/bashTool-euL6zMDl.cjs.map +0 -1
- package/dist/cliApp-T8Fx_-1j.cjs +0 -244
- package/dist/cliApp-T8Fx_-1j.cjs.map +0 -1
- package/dist/cliApp-q97eVh4E.mjs +0 -237
- package/dist/cliApp-q97eVh4E.mjs.map +0 -1
- package/dist/headless-DOlCixyf.mjs +0 -169
- package/dist/headless-DOlCixyf.mjs.map +0 -1
- package/dist/headless-Dko_yBiy.cjs +0 -180
- package/dist/headless-Dko_yBiy.cjs.map +0 -1
- package/dist/index--xF7DvsE.d.mts.map +0 -1
- package/dist/index-BzeXJk6V.d.mts +0 -12
- package/dist/index-BzeXJk6V.d.mts.map +0 -1
- package/dist/index-C-IC35d9.d.mts.map +0 -1
- package/dist/index-CzCF_OP9.d.mts.map +0 -1
- package/dist/index-DM7yJpMs.d.mts.map +0 -1
- package/dist/launcher-BG5t9nvG.d.mts.map +0 -1
- package/dist/launcher-CCYsFBM9.mjs.map +0 -1
- package/dist/launcher-ZgDdyXpq.cjs.map +0 -1
- package/dist/lifeline-Bm-bHIjS.mjs +0 -88
- package/dist/lifeline-Bm-bHIjS.mjs.map +0 -1
- package/dist/lifeline-eJdZV0nN.d.mts +0 -19
- package/dist/lifeline-eJdZV0nN.d.mts.map +0 -1
- package/dist/lifeline-m7laIzIP.cjs +0 -98
- package/dist/lifeline-m7laIzIP.cjs.map +0 -1
- package/dist/lifeline.d.mts.map +0 -1
- package/dist/logFile-C7oQ_v-g.d.mts.map +0 -1
- package/dist/logFile-CnPKtxPy.cjs +0 -67
- package/dist/logFile-CnPKtxPy.cjs.map +0 -1
- package/dist/logFile-XcDHBwu1.mjs +0 -60
- package/dist/logFile-XcDHBwu1.mjs.map +0 -1
- package/dist/logReader-DHCK2BEr.cjs.map +0 -1
- package/dist/logReader-mq9uVurh.mjs.map +0 -1
- package/dist/ptyHost-CwbLLr90.mjs.map +0 -1
- package/dist/ptyHost-D35hNmtd.cjs.map +0 -1
- package/dist/reconcile-5cZ11jSD.cjs.map +0 -1
- package/dist/reconcile-wNYQJZF-.mjs.map +0 -1
- package/dist/rmuxBackend-CaEWooWn.d.mts.map +0 -1
- package/dist/rmuxBackend-Dh0CYVAL.cjs.map +0 -1
- package/dist/rmuxBackend-rjrVTG6K.mjs.map +0 -1
- package/dist/rtkProcessor-DSGbM-Cm.cjs.map +0 -1
- package/dist/rtkProcessor-Iw9gP5Xp.mjs.map +0 -1
- package/dist/runnerDependencies-7h_cxOva.mjs.map +0 -1
- package/dist/runnerDependencies-DSun3xO-.cjs.map +0 -1
- package/dist/runnerPaths-B41rMOY6.cjs.map +0 -1
- package/dist/runnerPaths-Dibbvyx_.mjs.map +0 -1
- package/dist/runnerRegistry-BgaR5O86.mjs.map +0 -1
- package/dist/runnerRegistry-dQYlMSpQ.cjs.map +0 -1
- package/dist/session-BKYnH4R6.mjs +0 -18
- package/dist/session-BKYnH4R6.mjs.map +0 -1
- package/dist/session-BvqzhXZY.cjs +0 -29
- package/dist/session-BvqzhXZY.cjs.map +0 -1
- package/dist/session-DE2Acesp.mjs +0 -6
- package/dist/session-DE2Acesp.mjs.map +0 -1
- package/dist/session-SfIPtdZO.cjs +0 -11
- package/dist/session-SfIPtdZO.cjs.map +0 -1
- package/dist/type-DwMZoINK.d.mts.map +0 -1
- package/src/prompts/po-use-runner/SKILL.md +0 -47
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_rolldown_runtime = require("../../rolldown-runtime-
|
|
3
|
-
let
|
|
4
|
-
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
2
|
+
const require_rolldown_runtime = require("../../rolldown-runtime-C0BPl7ul.cjs");
|
|
3
|
+
let node_fs_promises = require("node:fs/promises");
|
|
5
4
|
let node_path = require("node:path");
|
|
6
5
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
6
|
+
let node_fs = require("node:fs");
|
|
7
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
8
|
let node_url = require("node:url");
|
|
8
9
|
//#region src/services/runnerSupervisor/index.ts
|
|
9
10
|
/**
|
|
@@ -32,12 +33,12 @@ function supervisorPaths(directory, id) {
|
|
|
32
33
|
logDone: node_path.default.join(directory, `${id}.log.done`)
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
function writeCommandSpec(target, spec) {
|
|
36
|
-
|
|
36
|
+
async function writeCommandSpec(target, spec) {
|
|
37
|
+
await (0, node_fs_promises.writeFile)(target, `${JSON.stringify(spec)}\n`, { mode: SPEC_MODE });
|
|
37
38
|
}
|
|
38
|
-
function readExitMetadata(target) {
|
|
39
|
+
async function readExitMetadata(target) {
|
|
39
40
|
try {
|
|
40
|
-
const value = JSON.parse(
|
|
41
|
+
const value = JSON.parse(await (0, node_fs_promises.readFile)(target, "utf8"));
|
|
41
42
|
if (typeof value !== "object" || value === null) return void 0;
|
|
42
43
|
const metadata = value;
|
|
43
44
|
return {
|
|
@@ -52,9 +53,9 @@ function readExitMetadata(target) {
|
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
function cleanupSupervisorFiles(paths) {
|
|
56
|
+
async function cleanupSupervisorFiles(paths) {
|
|
56
57
|
for (const target of Object.values(paths)) try {
|
|
57
|
-
|
|
58
|
+
await (0, node_fs_promises.unlink)(target);
|
|
58
59
|
} catch (error) {
|
|
59
60
|
if (error.code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));
|
|
60
61
|
}
|
|
@@ -65,14 +66,18 @@ function cleanupSupervisorFiles(paths) {
|
|
|
65
66
|
* different depths. Source modules select built subprocess entries so Node can resolve their imports. A hardcoded depth stays silent
|
|
66
67
|
* until the shell tries to exec it.
|
|
67
68
|
*/
|
|
68
|
-
function runtimeEntry(name, moduleUrl = require("url").pathToFileURL(__filename).href) {
|
|
69
|
+
async function runtimeEntry(name, moduleUrl = require("url").pathToFileURL(__filename).href) {
|
|
69
70
|
const modulePath = (0, node_url.fileURLToPath)(moduleUrl);
|
|
70
71
|
const source = node_path.default.extname(modulePath) === ".ts";
|
|
71
72
|
const extension = "mjs";
|
|
72
73
|
let directory = node_path.default.dirname(modulePath);
|
|
73
74
|
while (true) {
|
|
74
75
|
const entry = source ? node_path.default.join(directory, "dist", "bin", `${name}.${extension}`) : node_path.default.join(directory, "bin", `${name}.${extension}`);
|
|
75
|
-
|
|
76
|
+
try {
|
|
77
|
+
return await (0, node_fs_promises.realpath)(entry);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.code !== NOT_FOUND_ERROR_CODE) throw error;
|
|
80
|
+
}
|
|
76
81
|
const parent = node_path.default.dirname(directory);
|
|
77
82
|
if (parent === directory) break;
|
|
78
83
|
directory = parent;
|
|
@@ -83,10 +88,10 @@ function runtimeEntry(name, moduleUrl = require("url").pathToFileURL(__filename)
|
|
|
83
88
|
* Replaces the shell rather than nesting under it, so the pid handed back is the
|
|
84
89
|
* supervisor's and a group signal reaches it directly.
|
|
85
90
|
*/
|
|
86
|
-
function supervisorCommand(paths) {
|
|
91
|
+
async function supervisorCommand(paths) {
|
|
87
92
|
return `exec ${shellJoin([
|
|
88
93
|
process.execPath,
|
|
89
|
-
runtimeEntry("runnerHost"),
|
|
94
|
+
await runtimeEntry("runnerHost"),
|
|
90
95
|
paths.spec,
|
|
91
96
|
paths.gate,
|
|
92
97
|
paths.exit
|
|
@@ -158,22 +163,31 @@ function watchForFile(filePath) {
|
|
|
158
163
|
let released = false;
|
|
159
164
|
let found = false;
|
|
160
165
|
let notify;
|
|
161
|
-
const settle = () => {
|
|
162
|
-
if (found ||
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
const settle = async () => {
|
|
167
|
+
if (found || released) return;
|
|
168
|
+
try {
|
|
169
|
+
await (0, node_fs_promises.access)(filePath);
|
|
170
|
+
if (released) return;
|
|
171
|
+
found = true;
|
|
172
|
+
notify?.();
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error.code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const probe = () => {
|
|
178
|
+
settle();
|
|
165
179
|
};
|
|
166
180
|
const listeners = entry.waiters.get(name) ?? /* @__PURE__ */ new Set();
|
|
167
|
-
listeners.add(
|
|
181
|
+
listeners.add(probe);
|
|
168
182
|
entry.waiters.set(name, listeners);
|
|
169
|
-
|
|
183
|
+
probe();
|
|
170
184
|
return {
|
|
171
185
|
async appeared(withinMs) {
|
|
172
186
|
if (found) return true;
|
|
173
187
|
return await new Promise((resolve) => {
|
|
174
|
-
const timer = setTimeout(() => {
|
|
188
|
+
const timer = setTimeout(async () => {
|
|
175
189
|
notify = void 0;
|
|
176
|
-
settle();
|
|
190
|
+
await settle();
|
|
177
191
|
resolve(found);
|
|
178
192
|
}, withinMs);
|
|
179
193
|
notify = () => {
|
|
@@ -187,7 +201,7 @@ function watchForFile(filePath) {
|
|
|
187
201
|
if (released) return;
|
|
188
202
|
released = true;
|
|
189
203
|
notify = void 0;
|
|
190
|
-
listeners.delete(
|
|
204
|
+
listeners.delete(probe);
|
|
191
205
|
if (listeners.size === 0) entry.waiters.delete(name);
|
|
192
206
|
releaseDirectoryWatch(directory, entry);
|
|
193
207
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["path","fs","fileURLToPath"],"sources":["../../../src/services/runnerSupervisor/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ExitResult } from '../../types/spawner';\n/** What a supervisor needs to run one command. */\nexport interface CommandSpec {\n command: string;\n cwd: string;\n env: Record<string, string>;\n}\n\n/** Exit status the supervisor records once its command is gone. */\nexport type ExitMetadata = ExitResult;\n\n/** Sidecars a supervised run reads and writes beside its log. */\nexport interface SupervisorPaths {\n spec: string;\n gate: string;\n exit: string;\n logDone: string;\n}\n\n/**\n * Settings that make a terminal safe for a caller with no keyboard.\n *\n * Commands run inside an rmux pane, so their stdout is a real tty. Git and\n * friends take that as permission to open a pager, and `less` then waits at\n * `(END)` for a keypress nobody is there to send, so the run hangs until its\n * timeout. The same tty invites credential prompts, which hang the same way.\n * A conventional piped stdout disables both automatically; a pane has to be\n * told. A command that genuinely wants a pager can still ask for one, as in\n * `git -c core.pager=less log`.\n */\nexport const NO_TERMINAL_INPUT_ENV = {\n GIT_PAGER: 'cat',\n PAGER: 'cat',\n GIT_TERMINAL_PROMPT: '0',\n};\n\nconst SPEC_MODE = 0o600;\nconst NOT_FOUND_ERROR_CODE = 'ENOENT';\n\nexport function supervisorPaths(directory: string, id: string): SupervisorPaths {\n return {\n spec: path.join(directory, `${id}.command.json`),\n gate: path.join(directory, `${id}.gate`),\n exit: path.join(directory, `${id}.exit.json`),\n logDone: path.join(directory, `${id}.log.done`),\n };\n}\n\nexport function writeCommandSpec(target: string, spec: CommandSpec): void {\n fs.writeFileSync(target, `${JSON.stringify(spec)}\\n`, { mode: SPEC_MODE });\n}\n\nexport function readExitMetadata(target: string): ExitMetadata | undefined {\n try {\n const value: unknown = JSON.parse(fs.readFileSync(target, 'utf8'));\n if (typeof value !== 'object' || value === null) return undefined;\n const metadata = value as Partial<ExitMetadata>;\n const code = typeof metadata.code === 'number' ? metadata.code : null;\n const signal = typeof metadata.signal === 'string' ? (metadata.signal as NodeJS.Signals) : null;\n return {\n code,\n signal,\n ...(metadata.reason === 'stopped' ? { reason: metadata.reason } : {}),\n ...(metadata.terminationReason === 'owner_lost' ? { terminationReason: metadata.terminationReason } : {}),\n ...(typeof metadata.stopReason === 'string' ? { stopReason: metadata.stopReason } : {}),\n };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) {\n process.emitWarning(`Could not read runner exit metadata ${target}: ${String(error)}`);\n }\n return undefined;\n }\n}\n\nexport function cleanupSupervisorFiles(paths: SupervisorPaths): void {\n for (const target of Object.values(paths)) {\n try {\n fs.unlinkSync(target);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));\n }\n }\n}\n\n/**\n * Resolves an executable entry point by walking up to the `bin` directory that\n * ships beside this module. Source and published layouts nest services at\n * different depths. Source modules select built subprocess entries so Node can resolve their imports. A hardcoded depth stays silent\n * until the shell tries to exec it.\n */\nexport function runtimeEntry(name: 'runnerHost' | 'logSink', moduleUrl = import.meta.url): string {\n const modulePath = fileURLToPath(moduleUrl);\n const source = path.extname(modulePath) === '.ts';\n const extension = 'mjs';\n let directory = path.dirname(modulePath);\n\n while (true) {\n const entry = source\n ? path.join(directory, 'dist', 'bin', `${name}.${extension}`)\n : path.join(directory, 'bin', `${name}.${extension}`);\n if (fs.existsSync(entry)) return fs.realpathSync(entry);\n\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n\n throw new Error(`Cannot find bin/${name}.${extension} by walking up from ${modulePath}.`);\n}\n\n/**\n * Replaces the shell rather than nesting under it, so the pid handed back is the\n * supervisor's and a group signal reaches it directly.\n */\nexport function supervisorCommand(paths: SupervisorPaths): string {\n return `exec ${shellJoin([process.execPath, runtimeEntry('runnerHost'), paths.spec, paths.gate, paths.exit])}`;\n}\n\nexport function shellJoin(values: readonly string[]): string {\n return values.map((value) => `'${value.replaceAll(\"'\", `'\"'\"'`)}'`).join(' ');\n}\n\n/** A pending appearance of one supervisor sidecar, watched rather than polled for. */\nexport interface FileWatch {\n /** Resolves true once the file exists, or false when the slice elapses. */\n appeared(withinMs: number): Promise<boolean>;\n close(): void;\n}\n\ninterface DirectoryWatch {\n watcher: fs.FSWatcher | undefined;\n readonly waiters: Map<string, Set<() => void>>;\n references: number;\n}\n\n/**\n * One watcher per directory, shared by every waiter inside it.\n *\n * A session's runners share a runs directory, and `PO_LOG_DIR` makes every\n * session using it share one. A watcher per waited file would then put a watcher\n * per in-flight runner on the same directory, each woken by every other runner's\n * sidecar writes, so the watchers are pooled and reference counted instead.\n */\nconst directoryWatches = new Map<string, DirectoryWatch>();\n\nfunction acquireDirectoryWatch(directory: string): DirectoryWatch {\n const existing = directoryWatches.get(directory);\n if (existing) {\n existing.references += 1;\n return existing;\n }\n const entry: DirectoryWatch = { watcher: undefined, waiters: new Map(), references: 1 };\n try {\n entry.watcher = fs.watch(directory, (_event, changed) => {\n // A rename can arrive without a name, and then the only safe reading is\n // that any waiter in this directory might be the one it belongs to.\n const named = changed === null ? undefined : String(changed);\n const targets = named === undefined ? [...entry.waiters.values()] : [entry.waiters.get(named)];\n for (const listeners of targets) {\n if (!listeners) continue;\n for (const listener of listeners) listener();\n }\n });\n // A watcher that cannot report is a watcher whose slices time out, which the\n // caller's own probe already covers.\n entry.watcher.on('error', () => undefined);\n } catch {\n entry.watcher = undefined;\n }\n directoryWatches.set(directory, entry);\n return entry;\n}\n\nfunction releaseDirectoryWatch(directory: string, entry: DirectoryWatch): void {\n entry.references -= 1;\n if (entry.references > 0) return;\n entry.watcher?.close();\n entry.watcher = undefined;\n entry.waiters.clear();\n directoryWatches.delete(directory);\n}\n\n/**\n * Reports a supervisor sidecar landing on disk without polling for it.\n *\n * The sidecars are written once and never rewritten, so the directory's own\n * create event answers the only question a waiter has. Polling for them costs a\n * full poll interval on every run that finishes inside one, and the runs that\n * finish fastest are the ones that pay that tax most often.\n *\n * The watch is best effort: a platform or a directory that cannot deliver events\n * leaves every slice to time out, which is exactly the poll the caller already\n * runs as its fallback.\n */\nexport function watchForFile(filePath: string): FileWatch {\n const directory = path.dirname(filePath);\n const name = path.basename(filePath);\n const entry = acquireDirectoryWatch(directory);\n let released = false;\n let found = false;\n let notify: (() => void) | undefined;\n\n const settle = (): void => {\n if (found || !fs.existsSync(filePath)) return;\n found = true;\n notify?.();\n };\n const listeners = entry.waiters.get(name) ?? new Set<() => void>();\n listeners.add(settle);\n entry.waiters.set(name, listeners);\n\n // The file can land between opening the watcher and the first wait, and that\n // create event has nobody listening for it yet.\n settle();\n\n return {\n async appeared(withinMs: number): Promise<boolean> {\n if (found) return true;\n return await new Promise<boolean>((resolve) => {\n const timer = setTimeout(() => {\n notify = undefined;\n // The watcher is an optimisation, not the answer. A create event that\n // was coalesced, reported under the temporary name of a rename, or\n // never delivered at all must not outlive the slice it belongs to, so\n // every slice ends by asking the filesystem itself.\n settle();\n resolve(found);\n }, withinMs);\n // Deliberately left holding the event loop. A run still being waited on\n // is work, and a process that exits during the gap between two probes\n // drops the result its caller is awaiting.\n notify = () => {\n clearTimeout(timer);\n notify = undefined;\n resolve(true);\n };\n });\n },\n close(): void {\n if (released) return;\n released = true;\n notify = undefined;\n listeners.delete(settle);\n if (listeners.size === 0) entry.waiters.delete(name);\n releaseDirectoryWatch(directory, entry);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkCA,MAAa,wBAAwB;CACnC,WAAW;CACX,OAAO;CACP,qBAAqB;AACvB;AAEA,MAAM,YAAY;AAClB,MAAM,uBAAuB;AAE7B,SAAgB,gBAAgB,WAAmB,IAA6B;CAC9E,OAAO;EACL,MAAMA,UAAAA,QAAK,KAAK,WAAW,GAAG,GAAG,cAAc;EAC/C,MAAMA,UAAAA,QAAK,KAAK,WAAW,GAAG,GAAG,MAAM;EACvC,MAAMA,UAAAA,QAAK,KAAK,WAAW,GAAG,GAAG,WAAW;EAC5C,SAASA,UAAAA,QAAK,KAAK,WAAW,GAAG,GAAG,UAAU;CAChD;AACF;AAEA,SAAgB,iBAAiB,QAAgB,MAAyB;CACxE,QAAA,QAAG,cAAc,QAAQ,GAAG,KAAK,UAAU,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC3E;AAEA,SAAgB,iBAAiB,QAA0C;CACzE,IAAI;EACF,MAAM,QAAiB,KAAK,MAAMC,QAAAA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sB,WAAmB,OAA6B;CAC7E,MAAM,cAAc;CACpB,IAAI,MAAM,aAAa,GAAG;CAC1B,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,KAAA;CAChB,MAAM,QAAQ,MAAM;CACpB,iBAAiB,OAAO,SAAS;AACnC;;;;;;;;;;;;;AAcA,SAAgB,aAAa,UAA6B;CACxD,MAAM,YAAYD,UAAAA,QAAK,QAAQ,QAAQ;CACvC,MAAM,OAAOA,UAAAA,QAAK,SAAS,QAAQ;CACnC,MAAM,QAAQ,sBAAsB,SAAS;CAC7C,IAAI,WAAW;CACf,IAAI,QAAQ;CACZ,IAAI;CAEJ,MAAM,eAAqB;EACzB,IAAI,SAAS,CAACC,QAAAA,QAAG,WAAW,QAAQ,GAAG;EACvC,QAAQ;EACR,SAAS;CACX;CACA,MAAM,YAAY,MAAM,QAAQ,IAAI,IAAI,qBAAK,IAAI,IAAgB;CACjE,UAAU,IAAI,MAAM;CACpB,MAAM,QAAQ,IAAI,MAAM,SAAS;CAIjC,OAAO;CAEP,OAAO;EACL,MAAM,SAAS,UAAoC;GACjD,IAAI,OAAO,OAAO;GAClB,OAAO,MAAM,IAAI,SAAkB,YAAY;IAC7C,MAAM,QAAQ,iBAAiB;KAC7B,SAAS,KAAA;KAKT,OAAO;KACP,QAAQ,KAAK;IACf,GAAG,QAAQ;IAIX,eAAe;KACb,aAAa,KAAK;KAClB,SAAS,KAAA;KACT,QAAQ,IAAI;IACd;GACF,CAAC;EACH;EACA,QAAc;GACZ,IAAI,UAAU;GACd,WAAW;GACX,SAAS,KAAA;GACT,UAAU,OAAO,MAAM;GACvB,IAAI,UAAU,SAAS,GAAG,MAAM,QAAQ,OAAO,IAAI;GACnD,sBAAsB,WAAW,KAAK;EACxC;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["path","writeFile","readFile","unlink","fileURLToPath","realpath","fs","access"],"sources":["../../../src/services/runnerSupervisor/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { access, readFile, realpath, unlink, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ExitResult } from '../../types/spawner';\n/** What a supervisor needs to run one command. */\nexport interface CommandSpec {\n command: string;\n cwd: string;\n env: Record<string, string>;\n /** Close only this command's mux session after owner loss. */\n ownerLostCleanup?: string[];\n}\n\n/** Exit status the supervisor records once its command is gone. */\nexport type ExitMetadata = ExitResult;\n\n/** Sidecars a supervised run reads and writes beside its log. */\nexport interface SupervisorPaths {\n spec: string;\n gate: string;\n exit: string;\n logDone: string;\n}\n\n/**\n * Settings that make a terminal safe for a caller with no keyboard.\n *\n * Commands run inside an rmux pane, so their stdout is a real tty. Git and\n * friends take that as permission to open a pager, and `less` then waits at\n * `(END)` for a keypress nobody is there to send, so the run hangs until its\n * timeout. The same tty invites credential prompts, which hang the same way.\n * A conventional piped stdout disables both automatically; a pane has to be\n * told. A command that genuinely wants a pager can still ask for one, as in\n * `git -c core.pager=less log`.\n */\nexport const NO_TERMINAL_INPUT_ENV = {\n GIT_PAGER: 'cat',\n PAGER: 'cat',\n GIT_TERMINAL_PROMPT: '0',\n};\n\nconst SPEC_MODE = 0o600;\nconst NOT_FOUND_ERROR_CODE = 'ENOENT';\n\nexport function supervisorPaths(directory: string, id: string): SupervisorPaths {\n return {\n spec: path.join(directory, `${id}.command.json`),\n gate: path.join(directory, `${id}.gate`),\n exit: path.join(directory, `${id}.exit.json`),\n logDone: path.join(directory, `${id}.log.done`),\n };\n}\n\nexport async function writeCommandSpec(target: string, spec: CommandSpec): Promise<void> {\n await writeFile(target, `${JSON.stringify(spec)}\\n`, { mode: SPEC_MODE });\n}\n\nexport async function readExitMetadata(target: string): Promise<ExitMetadata | undefined> {\n try {\n const value: unknown = JSON.parse(await readFile(target, 'utf8'));\n if (typeof value !== 'object' || value === null) return undefined;\n const metadata = value as Partial<ExitMetadata>;\n const code = typeof metadata.code === 'number' ? metadata.code : null;\n const signal = typeof metadata.signal === 'string' ? (metadata.signal as NodeJS.Signals) : null;\n return {\n code,\n signal,\n ...(metadata.reason === 'stopped' ? { reason: metadata.reason } : {}),\n ...(metadata.terminationReason === 'owner_lost' ? { terminationReason: metadata.terminationReason } : {}),\n ...(typeof metadata.stopReason === 'string' ? { stopReason: metadata.stopReason } : {}),\n };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) {\n process.emitWarning(`Could not read runner exit metadata ${target}: ${String(error)}`);\n }\n return undefined;\n }\n}\n\nexport async function cleanupSupervisorFiles(paths: SupervisorPaths): Promise<void> {\n for (const target of Object.values(paths)) {\n try {\n await unlink(target);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));\n }\n }\n}\n\n/**\n * Resolves an executable entry point by walking up to the `bin` directory that\n * ships beside this module. Source and published layouts nest services at\n * different depths. Source modules select built subprocess entries so Node can resolve their imports. A hardcoded depth stays silent\n * until the shell tries to exec it.\n */\nexport async function runtimeEntry(name: 'runnerHost' | 'logSink', moduleUrl = import.meta.url): Promise<string> {\n const modulePath = fileURLToPath(moduleUrl);\n const source = path.extname(modulePath) === '.ts';\n const extension = 'mjs';\n let directory = path.dirname(modulePath);\n\n while (true) {\n const entry = source\n ? path.join(directory, 'dist', 'bin', `${name}.${extension}`)\n : path.join(directory, 'bin', `${name}.${extension}`);\n try {\n return await realpath(entry);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) throw error;\n }\n\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n\n throw new Error(`Cannot find bin/${name}.${extension} by walking up from ${modulePath}.`);\n}\n\n/**\n * Replaces the shell rather than nesting under it, so the pid handed back is the\n * supervisor's and a group signal reaches it directly.\n */\nexport async function supervisorCommand(paths: SupervisorPaths): Promise<string> {\n return `exec ${shellJoin([process.execPath, await runtimeEntry('runnerHost'), paths.spec, paths.gate, paths.exit])}`;\n}\n\nexport function shellJoin(values: readonly string[]): string {\n return values.map((value) => `'${value.replaceAll(\"'\", `'\"'\"'`)}'`).join(' ');\n}\n\n/** A pending appearance of one supervisor sidecar, watched rather than polled for. */\nexport interface FileWatch {\n /** Resolves true once the file exists, or false when the slice elapses. */\n appeared(withinMs: number): Promise<boolean>;\n close(): void;\n}\n\ninterface DirectoryWatch {\n watcher: fs.FSWatcher | undefined;\n readonly waiters: Map<string, Set<() => void>>;\n references: number;\n}\n\n/**\n * One watcher per directory, shared by every waiter inside it.\n *\n * A session's runners share a runs directory, and `PO_LOG_DIR` makes every\n * session using it share one. A watcher per waited file would then put a watcher\n * per in-flight runner on the same directory, each woken by every other runner's\n * sidecar writes, so the watchers are pooled and reference counted instead.\n */\nconst directoryWatches = new Map<string, DirectoryWatch>();\n\nfunction acquireDirectoryWatch(directory: string): DirectoryWatch {\n const existing = directoryWatches.get(directory);\n if (existing) {\n existing.references += 1;\n return existing;\n }\n const entry: DirectoryWatch = { watcher: undefined, waiters: new Map(), references: 1 };\n try {\n entry.watcher = fs.watch(directory, (_event, changed) => {\n // A rename can arrive without a name, and then the only safe reading is\n // that any waiter in this directory might be the one it belongs to.\n const named = changed === null ? undefined : String(changed);\n const targets = named === undefined ? [...entry.waiters.values()] : [entry.waiters.get(named)];\n for (const listeners of targets) {\n if (!listeners) continue;\n for (const listener of listeners) listener();\n }\n });\n // A watcher that cannot report is a watcher whose slices time out, which the\n // caller's own probe already covers.\n entry.watcher.on('error', () => undefined);\n } catch {\n entry.watcher = undefined;\n }\n directoryWatches.set(directory, entry);\n return entry;\n}\n\nfunction releaseDirectoryWatch(directory: string, entry: DirectoryWatch): void {\n entry.references -= 1;\n if (entry.references > 0) return;\n entry.watcher?.close();\n entry.watcher = undefined;\n entry.waiters.clear();\n directoryWatches.delete(directory);\n}\n\n/**\n * Reports a supervisor sidecar landing on disk without polling for it.\n *\n * The sidecars are written once and never rewritten, so the directory's own\n * create event answers the only question a waiter has. Polling for them costs a\n * full poll interval on every run that finishes inside one, and the runs that\n * finish fastest are the ones that pay that tax most often.\n *\n * The watch is best effort: a platform or a directory that cannot deliver events\n * leaves every slice to time out, which is exactly the poll the caller already\n * runs as its fallback.\n */\nexport function watchForFile(filePath: string): FileWatch {\n const directory = path.dirname(filePath);\n const name = path.basename(filePath);\n const entry = acquireDirectoryWatch(directory);\n let released = false;\n let found = false;\n let notify: (() => void) | undefined;\n\n const settle = async (): Promise<void> => {\n if (found || released) return;\n try {\n await access(filePath);\n if (released) return;\n found = true;\n notify?.();\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));\n }\n };\n const probe = (): void => {\n void settle();\n };\n const listeners = entry.waiters.get(name) ?? new Set<() => void>();\n listeners.add(probe);\n entry.waiters.set(name, listeners);\n\n // The file can land between opening the watcher and the first wait, and that\n // create event has nobody listening for it yet.\n probe();\n\n return {\n async appeared(withinMs: number): Promise<boolean> {\n if (found) return true;\n return await new Promise<boolean>((resolve) => {\n const timer = setTimeout(async () => {\n notify = undefined;\n // The watcher is an optimisation, not the answer. A create event that\n // was coalesced, reported under the temporary name of a rename, or\n // never delivered at all must not outlive the slice it belongs to, so\n // every slice ends by asking the filesystem itself.\n await settle();\n resolve(found);\n }, withinMs);\n // Deliberately left holding the event loop. A run still being waited on\n // is work, and a process that exits during the gap between two probes\n // drops the result its caller is awaiting.\n notify = () => {\n clearTimeout(timer);\n notify = undefined;\n resolve(true);\n };\n });\n },\n close(): void {\n if (released) return;\n released = true;\n notify = undefined;\n listeners.delete(probe);\n if (listeners.size === 0) entry.waiters.delete(name);\n releaseDirectoryWatch(directory, entry);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,wBAAwB;CACnC,WAAW;CACX,OAAO;CACP,qBAAqB;AACvB;AAEA,MAAM,YAAY;AAClB,MAAM,uBAAuB;AAE7B,SAAgB,gBAAgB,WAAmB,IAA6B;CAC9E,OAAO;EACL,MAAMA,UAAAA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AQ,IAAI,IAAI,qBAAK,IAAI,IAAgB;CACjE,UAAU,IAAI,KAAK;CACnB,MAAM,QAAQ,IAAI,MAAM,SAAS;CAIjC,MAAM;CAEN,OAAO;EACL,MAAM,SAAS,UAAoC;GACjD,IAAI,OAAO,OAAO;GAClB,OAAO,MAAM,IAAI,SAAkB,YAAY;IAC7C,MAAM,QAAQ,WAAW,YAAY;KACnC,SAAS,KAAA;KAKT,MAAM,OAAO;KACb,QAAQ,KAAK;IACf,GAAG,QAAQ;IAIX,eAAe;KACb,aAAa,KAAK;KAClB,SAAS,KAAA;KACT,QAAQ,IAAI;IACd;GACF,CAAC;EACH;EACA,QAAc;GACZ,IAAI,UAAU;GACd,WAAW;GACX,SAAS,KAAA;GACT,UAAU,OAAO,KAAK;GACtB,IAAI,UAAU,SAAS,GAAG,MAAM,QAAQ,OAAO,IAAI;GACnD,sBAAsB,WAAW,KAAK;EACxC;CACF;AACF"}
|
|
@@ -5,6 +5,8 @@ export interface CommandSpec {
|
|
|
5
5
|
command: string;
|
|
6
6
|
cwd: string;
|
|
7
7
|
env: Record<string, string>;
|
|
8
|
+
/** Close only this command's mux session after owner loss. */
|
|
9
|
+
ownerLostCleanup?: string[];
|
|
8
10
|
}
|
|
9
11
|
/** Exit status the supervisor records once its command is gone. */
|
|
10
12
|
export type ExitMetadata = ExitResult;
|
|
@@ -32,21 +34,21 @@ export declare const NO_TERMINAL_INPUT_ENV: {
|
|
|
32
34
|
GIT_TERMINAL_PROMPT: string;
|
|
33
35
|
};
|
|
34
36
|
export declare function supervisorPaths(directory: string, id: string): SupervisorPaths;
|
|
35
|
-
export declare function writeCommandSpec(target: string, spec: CommandSpec): void
|
|
36
|
-
export declare function readExitMetadata(target: string): ExitMetadata | undefined
|
|
37
|
-
export declare function cleanupSupervisorFiles(paths: SupervisorPaths): void
|
|
37
|
+
export declare function writeCommandSpec(target: string, spec: CommandSpec): Promise<void>;
|
|
38
|
+
export declare function readExitMetadata(target: string): Promise<ExitMetadata | undefined>;
|
|
39
|
+
export declare function cleanupSupervisorFiles(paths: SupervisorPaths): Promise<void>;
|
|
38
40
|
/**
|
|
39
41
|
* Resolves an executable entry point by walking up to the `bin` directory that
|
|
40
42
|
* ships beside this module. Source and published layouts nest services at
|
|
41
43
|
* different depths. Source modules select built subprocess entries so Node can resolve their imports. A hardcoded depth stays silent
|
|
42
44
|
* until the shell tries to exec it.
|
|
43
45
|
*/
|
|
44
|
-
export declare function runtimeEntry(name: 'runnerHost' | 'logSink', moduleUrl?: string): string
|
|
46
|
+
export declare function runtimeEntry(name: 'runnerHost' | 'logSink', moduleUrl?: string): Promise<string>;
|
|
45
47
|
/**
|
|
46
48
|
* Replaces the shell rather than nesting under it, so the pid handed back is the
|
|
47
49
|
* supervisor's and a group signal reaches it directly.
|
|
48
50
|
*/
|
|
49
|
-
export declare function supervisorCommand(paths: SupervisorPaths): string
|
|
51
|
+
export declare function supervisorCommand(paths: SupervisorPaths): Promise<string>;
|
|
50
52
|
export declare function shellJoin(values: readonly string[]): string;
|
|
51
53
|
/** A pending appearance of one supervisor sidecar, watched rather than polled for. */
|
|
52
54
|
export interface FileWatch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/runnerSupervisor/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/runnerSupervisor/index.ts"],"mappings":";;;iBAOiB;EACf;EACA;EACA,KAAK;;EAEL;;;YAIU,eAAe;;iBAGV;EACf;EACA;EACA;EACA;;;;;;;;;;;;;qBAcW;EACX;EACA;EACA;;wBAMc,gBAAgB,mBAAmB,aAAa;wBAS1C,iBAAiB,gBAAgB,MAAM,cAAc;wBAIrD,iBAAiB,iBAAiB,QAAQ;wBAsB1C,uBAAuB,OAAO,kBAAkB;;;;;;;wBAgBhD,aAAa,gCAAgC,qBAA8B;;;;;wBA4B3E,kBAAkB,OAAO,kBAAkB;wBAIjD,UAAU;;iBAKT;;EAEf,SAAS,mBAAmB;EAC5B;;;;;;;;;;;;;;wBAoEc,aAAa,mBAAmB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { access, readFile, realpath, unlink, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import fs$1 from "node:fs";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
//#region src/services/runnerSupervisor/index.ts
|
|
5
6
|
/**
|
|
@@ -28,12 +29,12 @@ function supervisorPaths(directory, id) {
|
|
|
28
29
|
logDone: path.join(directory, `${id}.log.done`)
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
|
-
function writeCommandSpec(target, spec) {
|
|
32
|
-
|
|
32
|
+
async function writeCommandSpec(target, spec) {
|
|
33
|
+
await writeFile(target, `${JSON.stringify(spec)}\n`, { mode: SPEC_MODE });
|
|
33
34
|
}
|
|
34
|
-
function readExitMetadata(target) {
|
|
35
|
+
async function readExitMetadata(target) {
|
|
35
36
|
try {
|
|
36
|
-
const value = JSON.parse(
|
|
37
|
+
const value = JSON.parse(await readFile(target, "utf8"));
|
|
37
38
|
if (typeof value !== "object" || value === null) return void 0;
|
|
38
39
|
const metadata = value;
|
|
39
40
|
return {
|
|
@@ -48,9 +49,9 @@ function readExitMetadata(target) {
|
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
function cleanupSupervisorFiles(paths) {
|
|
52
|
+
async function cleanupSupervisorFiles(paths) {
|
|
52
53
|
for (const target of Object.values(paths)) try {
|
|
53
|
-
|
|
54
|
+
await unlink(target);
|
|
54
55
|
} catch (error) {
|
|
55
56
|
if (error.code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));
|
|
56
57
|
}
|
|
@@ -61,14 +62,18 @@ function cleanupSupervisorFiles(paths) {
|
|
|
61
62
|
* different depths. Source modules select built subprocess entries so Node can resolve their imports. A hardcoded depth stays silent
|
|
62
63
|
* until the shell tries to exec it.
|
|
63
64
|
*/
|
|
64
|
-
function runtimeEntry(name, moduleUrl = import.meta.url) {
|
|
65
|
+
async function runtimeEntry(name, moduleUrl = import.meta.url) {
|
|
65
66
|
const modulePath = fileURLToPath(moduleUrl);
|
|
66
67
|
const source = path.extname(modulePath) === ".ts";
|
|
67
68
|
const extension = "mjs";
|
|
68
69
|
let directory = path.dirname(modulePath);
|
|
69
70
|
while (true) {
|
|
70
71
|
const entry = source ? path.join(directory, "dist", "bin", `${name}.${extension}`) : path.join(directory, "bin", `${name}.${extension}`);
|
|
71
|
-
|
|
72
|
+
try {
|
|
73
|
+
return await realpath(entry);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error.code !== NOT_FOUND_ERROR_CODE) throw error;
|
|
76
|
+
}
|
|
72
77
|
const parent = path.dirname(directory);
|
|
73
78
|
if (parent === directory) break;
|
|
74
79
|
directory = parent;
|
|
@@ -79,10 +84,10 @@ function runtimeEntry(name, moduleUrl = import.meta.url) {
|
|
|
79
84
|
* Replaces the shell rather than nesting under it, so the pid handed back is the
|
|
80
85
|
* supervisor's and a group signal reaches it directly.
|
|
81
86
|
*/
|
|
82
|
-
function supervisorCommand(paths) {
|
|
87
|
+
async function supervisorCommand(paths) {
|
|
83
88
|
return `exec ${shellJoin([
|
|
84
89
|
process.execPath,
|
|
85
|
-
runtimeEntry("runnerHost"),
|
|
90
|
+
await runtimeEntry("runnerHost"),
|
|
86
91
|
paths.spec,
|
|
87
92
|
paths.gate,
|
|
88
93
|
paths.exit
|
|
@@ -112,7 +117,7 @@ function acquireDirectoryWatch(directory) {
|
|
|
112
117
|
references: 1
|
|
113
118
|
};
|
|
114
119
|
try {
|
|
115
|
-
entry.watcher = fs.watch(directory, (_event, changed) => {
|
|
120
|
+
entry.watcher = fs$1.watch(directory, (_event, changed) => {
|
|
116
121
|
const named = changed === null ? void 0 : String(changed);
|
|
117
122
|
const targets = named === void 0 ? [...entry.waiters.values()] : [entry.waiters.get(named)];
|
|
118
123
|
for (const listeners of targets) {
|
|
@@ -154,22 +159,31 @@ function watchForFile(filePath) {
|
|
|
154
159
|
let released = false;
|
|
155
160
|
let found = false;
|
|
156
161
|
let notify;
|
|
157
|
-
const settle = () => {
|
|
158
|
-
if (found ||
|
|
159
|
-
|
|
160
|
-
|
|
162
|
+
const settle = async () => {
|
|
163
|
+
if (found || released) return;
|
|
164
|
+
try {
|
|
165
|
+
await access(filePath);
|
|
166
|
+
if (released) return;
|
|
167
|
+
found = true;
|
|
168
|
+
notify?.();
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error.code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const probe = () => {
|
|
174
|
+
settle();
|
|
161
175
|
};
|
|
162
176
|
const listeners = entry.waiters.get(name) ?? /* @__PURE__ */ new Set();
|
|
163
|
-
listeners.add(
|
|
177
|
+
listeners.add(probe);
|
|
164
178
|
entry.waiters.set(name, listeners);
|
|
165
|
-
|
|
179
|
+
probe();
|
|
166
180
|
return {
|
|
167
181
|
async appeared(withinMs) {
|
|
168
182
|
if (found) return true;
|
|
169
183
|
return await new Promise((resolve) => {
|
|
170
|
-
const timer = setTimeout(() => {
|
|
184
|
+
const timer = setTimeout(async () => {
|
|
171
185
|
notify = void 0;
|
|
172
|
-
settle();
|
|
186
|
+
await settle();
|
|
173
187
|
resolve(found);
|
|
174
188
|
}, withinMs);
|
|
175
189
|
notify = () => {
|
|
@@ -183,7 +197,7 @@ function watchForFile(filePath) {
|
|
|
183
197
|
if (released) return;
|
|
184
198
|
released = true;
|
|
185
199
|
notify = void 0;
|
|
186
|
-
listeners.delete(
|
|
200
|
+
listeners.delete(probe);
|
|
187
201
|
if (listeners.size === 0) entry.waiters.delete(name);
|
|
188
202
|
releaseDirectoryWatch(directory, entry);
|
|
189
203
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/services/runnerSupervisor/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ExitResult } from '../../types/spawner';\n/** What a supervisor needs to run one command. */\nexport interface CommandSpec {\n command: string;\n cwd: string;\n env: Record<string, string>;\n}\n\n/** Exit status the supervisor records once its command is gone. */\nexport type ExitMetadata = ExitResult;\n\n/** Sidecars a supervised run reads and writes beside its log. */\nexport interface SupervisorPaths {\n spec: string;\n gate: string;\n exit: string;\n logDone: string;\n}\n\n/**\n * Settings that make a terminal safe for a caller with no keyboard.\n *\n * Commands run inside an rmux pane, so their stdout is a real tty. Git and\n * friends take that as permission to open a pager, and `less` then waits at\n * `(END)` for a keypress nobody is there to send, so the run hangs until its\n * timeout. The same tty invites credential prompts, which hang the same way.\n * A conventional piped stdout disables both automatically; a pane has to be\n * told. A command that genuinely wants a pager can still ask for one, as in\n * `git -c core.pager=less log`.\n */\nexport const NO_TERMINAL_INPUT_ENV = {\n GIT_PAGER: 'cat',\n PAGER: 'cat',\n GIT_TERMINAL_PROMPT: '0',\n};\n\nconst SPEC_MODE = 0o600;\nconst NOT_FOUND_ERROR_CODE = 'ENOENT';\n\nexport function supervisorPaths(directory: string, id: string): SupervisorPaths {\n return {\n spec: path.join(directory, `${id}.command.json`),\n gate: path.join(directory, `${id}.gate`),\n exit: path.join(directory, `${id}.exit.json`),\n logDone: path.join(directory, `${id}.log.done`),\n };\n}\n\nexport function writeCommandSpec(target: string, spec: CommandSpec): void {\n fs.writeFileSync(target, `${JSON.stringify(spec)}\\n`, { mode: SPEC_MODE });\n}\n\nexport function readExitMetadata(target: string): ExitMetadata | undefined {\n try {\n const value: unknown = JSON.parse(fs.readFileSync(target, 'utf8'));\n if (typeof value !== 'object' || value === null) return undefined;\n const metadata = value as Partial<ExitMetadata>;\n const code = typeof metadata.code === 'number' ? metadata.code : null;\n const signal = typeof metadata.signal === 'string' ? (metadata.signal as NodeJS.Signals) : null;\n return {\n code,\n signal,\n ...(metadata.reason === 'stopped' ? { reason: metadata.reason } : {}),\n ...(metadata.terminationReason === 'owner_lost' ? { terminationReason: metadata.terminationReason } : {}),\n ...(typeof metadata.stopReason === 'string' ? { stopReason: metadata.stopReason } : {}),\n };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) {\n process.emitWarning(`Could not read runner exit metadata ${target}: ${String(error)}`);\n }\n return undefined;\n }\n}\n\nexport function cleanupSupervisorFiles(paths: SupervisorPaths): void {\n for (const target of Object.values(paths)) {\n try {\n fs.unlinkSync(target);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));\n }\n }\n}\n\n/**\n * Resolves an executable entry point by walking up to the `bin` directory that\n * ships beside this module. Source and published layouts nest services at\n * different depths. Source modules select built subprocess entries so Node can resolve their imports. A hardcoded depth stays silent\n * until the shell tries to exec it.\n */\nexport function runtimeEntry(name: 'runnerHost' | 'logSink', moduleUrl = import.meta.url): string {\n const modulePath = fileURLToPath(moduleUrl);\n const source = path.extname(modulePath) === '.ts';\n const extension = 'mjs';\n let directory = path.dirname(modulePath);\n\n while (true) {\n const entry = source\n ? path.join(directory, 'dist', 'bin', `${name}.${extension}`)\n : path.join(directory, 'bin', `${name}.${extension}`);\n if (fs.existsSync(entry)) return fs.realpathSync(entry);\n\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n\n throw new Error(`Cannot find bin/${name}.${extension} by walking up from ${modulePath}.`);\n}\n\n/**\n * Replaces the shell rather than nesting under it, so the pid handed back is the\n * supervisor's and a group signal reaches it directly.\n */\nexport function supervisorCommand(paths: SupervisorPaths): string {\n return `exec ${shellJoin([process.execPath, runtimeEntry('runnerHost'), paths.spec, paths.gate, paths.exit])}`;\n}\n\nexport function shellJoin(values: readonly string[]): string {\n return values.map((value) => `'${value.replaceAll(\"'\", `'\"'\"'`)}'`).join(' ');\n}\n\n/** A pending appearance of one supervisor sidecar, watched rather than polled for. */\nexport interface FileWatch {\n /** Resolves true once the file exists, or false when the slice elapses. */\n appeared(withinMs: number): Promise<boolean>;\n close(): void;\n}\n\ninterface DirectoryWatch {\n watcher: fs.FSWatcher | undefined;\n readonly waiters: Map<string, Set<() => void>>;\n references: number;\n}\n\n/**\n * One watcher per directory, shared by every waiter inside it.\n *\n * A session's runners share a runs directory, and `PO_LOG_DIR` makes every\n * session using it share one. A watcher per waited file would then put a watcher\n * per in-flight runner on the same directory, each woken by every other runner's\n * sidecar writes, so the watchers are pooled and reference counted instead.\n */\nconst directoryWatches = new Map<string, DirectoryWatch>();\n\nfunction acquireDirectoryWatch(directory: string): DirectoryWatch {\n const existing = directoryWatches.get(directory);\n if (existing) {\n existing.references += 1;\n return existing;\n }\n const entry: DirectoryWatch = { watcher: undefined, waiters: new Map(), references: 1 };\n try {\n entry.watcher = fs.watch(directory, (_event, changed) => {\n // A rename can arrive without a name, and then the only safe reading is\n // that any waiter in this directory might be the one it belongs to.\n const named = changed === null ? undefined : String(changed);\n const targets = named === undefined ? [...entry.waiters.values()] : [entry.waiters.get(named)];\n for (const listeners of targets) {\n if (!listeners) continue;\n for (const listener of listeners) listener();\n }\n });\n // A watcher that cannot report is a watcher whose slices time out, which the\n // caller's own probe already covers.\n entry.watcher.on('error', () => undefined);\n } catch {\n entry.watcher = undefined;\n }\n directoryWatches.set(directory, entry);\n return entry;\n}\n\nfunction releaseDirectoryWatch(directory: string, entry: DirectoryWatch): void {\n entry.references -= 1;\n if (entry.references > 0) return;\n entry.watcher?.close();\n entry.watcher = undefined;\n entry.waiters.clear();\n directoryWatches.delete(directory);\n}\n\n/**\n * Reports a supervisor sidecar landing on disk without polling for it.\n *\n * The sidecars are written once and never rewritten, so the directory's own\n * create event answers the only question a waiter has. Polling for them costs a\n * full poll interval on every run that finishes inside one, and the runs that\n * finish fastest are the ones that pay that tax most often.\n *\n * The watch is best effort: a platform or a directory that cannot deliver events\n * leaves every slice to time out, which is exactly the poll the caller already\n * runs as its fallback.\n */\nexport function watchForFile(filePath: string): FileWatch {\n const directory = path.dirname(filePath);\n const name = path.basename(filePath);\n const entry = acquireDirectoryWatch(directory);\n let released = false;\n let found = false;\n let notify: (() => void) | undefined;\n\n const settle = (): void => {\n if (found || !fs.existsSync(filePath)) return;\n found = true;\n notify?.();\n };\n const listeners = entry.waiters.get(name) ?? new Set<() => void>();\n listeners.add(settle);\n entry.waiters.set(name, listeners);\n\n // The file can land between opening the watcher and the first wait, and that\n // create event has nobody listening for it yet.\n settle();\n\n return {\n async appeared(withinMs: number): Promise<boolean> {\n if (found) return true;\n return await new Promise<boolean>((resolve) => {\n const timer = setTimeout(() => {\n notify = undefined;\n // The watcher is an optimisation, not the answer. A create event that\n // was coalesced, reported under the temporary name of a rename, or\n // never delivered at all must not outlive the slice it belongs to, so\n // every slice ends by asking the filesystem itself.\n settle();\n resolve(found);\n }, withinMs);\n // Deliberately left holding the event loop. A run still being waited on\n // is work, and a process that exits during the gap between two probes\n // drops the result its caller is awaiting.\n notify = () => {\n clearTimeout(timer);\n notify = undefined;\n resolve(true);\n };\n });\n },\n close(): void {\n if (released) return;\n released = true;\n notify = undefined;\n listeners.delete(settle);\n if (listeners.size === 0) entry.waiters.delete(name);\n releaseDirectoryWatch(directory, entry);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkCA,MAAa,wBAAwB;CACnC,WAAW;CACX,OAAO;CACP,qBAAqB;AACvB;AAEA,MAAM,YAAY;AAClB,MAAM,uBAAuB;AAE7B,SAAgB,gBAAgB,WAAmB,IAA6B;CAC9E,OAAO;EACL,MAAM,KAAK,KAAK,WAAW,GAAG,GAAG,cAAc;EAC/C,MAAM,KAAK,KAAK,WAAW,GAAG,GAAG,MAAM;EACvC,MAAM,KAAK,KAAK,WAAW,GAAG,GAAG,WAAW;EAC5C,SAAS,KAAK,KAAK,WAAW,GAAG,GAAG,UAAU;CAChD;AACF;AAEA,SAAgB,iBAAiB,QAAgB,MAAyB;CACxE,GAAG,cAAc,QAAQ,GAA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,WAAmB,OAA6B;CAC7E,MAAM,cAAc;CACpB,IAAI,MAAM,aAAa,GAAG;CAC1B,MAAM,SAAS,MAAM;CACrB,MAAM,UAAU,KAAA;CAChB,MAAM,QAAQ,MAAM;CACpB,iBAAiB,OAAO,SAAS;AACnC;;;;;;;;;;;;;AAcA,SAAgB,aAAa,UAA6B;CACxD,MAAM,YAAY,KAAK,QAAQ,QAAQ;CACvC,MAAM,OAAO,KAAK,SAAS,QAAQ;CACnC,MAAM,QAAQ,sBAAsB,SAAS;CAC7C,IAAI,WAAW;CACf,IAAI,QAAQ;CACZ,IAAI;CAEJ,MAAM,eAAqB;EACzB,IAAI,SAAS,CAAC,GAAG,WAAW,QAAQ,GAAG;EACvC,QAAQ;EACR,SAAS;CACX;CACA,MAAM,YAAY,MAAM,QAAQ,IAAI,IAAI,qBAAK,IAAI,IAAgB;CACjE,UAAU,IAAI,MAAM;CACpB,MAAM,QAAQ,IAAI,MAAM,SAAS;CAIjC,OAAO;CAEP,OAAO;EACL,MAAM,SAAS,UAAoC;GACjD,IAAI,OAAO,OAAO;GAClB,OAAO,MAAM,IAAI,SAAkB,YAAY;IAC7C,MAAM,QAAQ,iBAAiB;KAC7B,SAAS,KAAA;KAKT,OAAO;KACP,QAAQ,KAAK;IACf,GAAG,QAAQ;IAIX,eAAe;KACb,aAAa,KAAK;KAClB,SAAS,KAAA;KACT,QAAQ,IAAI;IACd;GACF,CAAC;EACH;EACA,QAAc;GACZ,IAAI,UAAU;GACd,WAAW;GACX,SAAS,KAAA;GACT,UAAU,OAAO,MAAM;GACvB,IAAI,UAAU,SAAS,GAAG,MAAM,QAAQ,OAAO,IAAI;GACnD,sBAAsB,WAAW,KAAK;EACxC;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["fs"],"sources":["../../../src/services/runnerSupervisor/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport { access, readFile, realpath, unlink, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ExitResult } from '../../types/spawner';\n/** What a supervisor needs to run one command. */\nexport interface CommandSpec {\n command: string;\n cwd: string;\n env: Record<string, string>;\n /** Close only this command's mux session after owner loss. */\n ownerLostCleanup?: string[];\n}\n\n/** Exit status the supervisor records once its command is gone. */\nexport type ExitMetadata = ExitResult;\n\n/** Sidecars a supervised run reads and writes beside its log. */\nexport interface SupervisorPaths {\n spec: string;\n gate: string;\n exit: string;\n logDone: string;\n}\n\n/**\n * Settings that make a terminal safe for a caller with no keyboard.\n *\n * Commands run inside an rmux pane, so their stdout is a real tty. Git and\n * friends take that as permission to open a pager, and `less` then waits at\n * `(END)` for a keypress nobody is there to send, so the run hangs until its\n * timeout. The same tty invites credential prompts, which hang the same way.\n * A conventional piped stdout disables both automatically; a pane has to be\n * told. A command that genuinely wants a pager can still ask for one, as in\n * `git -c core.pager=less log`.\n */\nexport const NO_TERMINAL_INPUT_ENV = {\n GIT_PAGER: 'cat',\n PAGER: 'cat',\n GIT_TERMINAL_PROMPT: '0',\n};\n\nconst SPEC_MODE = 0o600;\nconst NOT_FOUND_ERROR_CODE = 'ENOENT';\n\nexport function supervisorPaths(directory: string, id: string): SupervisorPaths {\n return {\n spec: path.join(directory, `${id}.command.json`),\n gate: path.join(directory, `${id}.gate`),\n exit: path.join(directory, `${id}.exit.json`),\n logDone: path.join(directory, `${id}.log.done`),\n };\n}\n\nexport async function writeCommandSpec(target: string, spec: CommandSpec): Promise<void> {\n await writeFile(target, `${JSON.stringify(spec)}\\n`, { mode: SPEC_MODE });\n}\n\nexport async function readExitMetadata(target: string): Promise<ExitMetadata | undefined> {\n try {\n const value: unknown = JSON.parse(await readFile(target, 'utf8'));\n if (typeof value !== 'object' || value === null) return undefined;\n const metadata = value as Partial<ExitMetadata>;\n const code = typeof metadata.code === 'number' ? metadata.code : null;\n const signal = typeof metadata.signal === 'string' ? (metadata.signal as NodeJS.Signals) : null;\n return {\n code,\n signal,\n ...(metadata.reason === 'stopped' ? { reason: metadata.reason } : {}),\n ...(metadata.terminationReason === 'owner_lost' ? { terminationReason: metadata.terminationReason } : {}),\n ...(typeof metadata.stopReason === 'string' ? { stopReason: metadata.stopReason } : {}),\n };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) {\n process.emitWarning(`Could not read runner exit metadata ${target}: ${String(error)}`);\n }\n return undefined;\n }\n}\n\nexport async function cleanupSupervisorFiles(paths: SupervisorPaths): Promise<void> {\n for (const target of Object.values(paths)) {\n try {\n await unlink(target);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));\n }\n }\n}\n\n/**\n * Resolves an executable entry point by walking up to the `bin` directory that\n * ships beside this module. Source and published layouts nest services at\n * different depths. Source modules select built subprocess entries so Node can resolve their imports. A hardcoded depth stays silent\n * until the shell tries to exec it.\n */\nexport async function runtimeEntry(name: 'runnerHost' | 'logSink', moduleUrl = import.meta.url): Promise<string> {\n const modulePath = fileURLToPath(moduleUrl);\n const source = path.extname(modulePath) === '.ts';\n const extension = 'mjs';\n let directory = path.dirname(modulePath);\n\n while (true) {\n const entry = source\n ? path.join(directory, 'dist', 'bin', `${name}.${extension}`)\n : path.join(directory, 'bin', `${name}.${extension}`);\n try {\n return await realpath(entry);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) throw error;\n }\n\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n\n throw new Error(`Cannot find bin/${name}.${extension} by walking up from ${modulePath}.`);\n}\n\n/**\n * Replaces the shell rather than nesting under it, so the pid handed back is the\n * supervisor's and a group signal reaches it directly.\n */\nexport async function supervisorCommand(paths: SupervisorPaths): Promise<string> {\n return `exec ${shellJoin([process.execPath, await runtimeEntry('runnerHost'), paths.spec, paths.gate, paths.exit])}`;\n}\n\nexport function shellJoin(values: readonly string[]): string {\n return values.map((value) => `'${value.replaceAll(\"'\", `'\"'\"'`)}'`).join(' ');\n}\n\n/** A pending appearance of one supervisor sidecar, watched rather than polled for. */\nexport interface FileWatch {\n /** Resolves true once the file exists, or false when the slice elapses. */\n appeared(withinMs: number): Promise<boolean>;\n close(): void;\n}\n\ninterface DirectoryWatch {\n watcher: fs.FSWatcher | undefined;\n readonly waiters: Map<string, Set<() => void>>;\n references: number;\n}\n\n/**\n * One watcher per directory, shared by every waiter inside it.\n *\n * A session's runners share a runs directory, and `PO_LOG_DIR` makes every\n * session using it share one. A watcher per waited file would then put a watcher\n * per in-flight runner on the same directory, each woken by every other runner's\n * sidecar writes, so the watchers are pooled and reference counted instead.\n */\nconst directoryWatches = new Map<string, DirectoryWatch>();\n\nfunction acquireDirectoryWatch(directory: string): DirectoryWatch {\n const existing = directoryWatches.get(directory);\n if (existing) {\n existing.references += 1;\n return existing;\n }\n const entry: DirectoryWatch = { watcher: undefined, waiters: new Map(), references: 1 };\n try {\n entry.watcher = fs.watch(directory, (_event, changed) => {\n // A rename can arrive without a name, and then the only safe reading is\n // that any waiter in this directory might be the one it belongs to.\n const named = changed === null ? undefined : String(changed);\n const targets = named === undefined ? [...entry.waiters.values()] : [entry.waiters.get(named)];\n for (const listeners of targets) {\n if (!listeners) continue;\n for (const listener of listeners) listener();\n }\n });\n // A watcher that cannot report is a watcher whose slices time out, which the\n // caller's own probe already covers.\n entry.watcher.on('error', () => undefined);\n } catch {\n entry.watcher = undefined;\n }\n directoryWatches.set(directory, entry);\n return entry;\n}\n\nfunction releaseDirectoryWatch(directory: string, entry: DirectoryWatch): void {\n entry.references -= 1;\n if (entry.references > 0) return;\n entry.watcher?.close();\n entry.watcher = undefined;\n entry.waiters.clear();\n directoryWatches.delete(directory);\n}\n\n/**\n * Reports a supervisor sidecar landing on disk without polling for it.\n *\n * The sidecars are written once and never rewritten, so the directory's own\n * create event answers the only question a waiter has. Polling for them costs a\n * full poll interval on every run that finishes inside one, and the runs that\n * finish fastest are the ones that pay that tax most often.\n *\n * The watch is best effort: a platform or a directory that cannot deliver events\n * leaves every slice to time out, which is exactly the poll the caller already\n * runs as its fallback.\n */\nexport function watchForFile(filePath: string): FileWatch {\n const directory = path.dirname(filePath);\n const name = path.basename(filePath);\n const entry = acquireDirectoryWatch(directory);\n let released = false;\n let found = false;\n let notify: (() => void) | undefined;\n\n const settle = async (): Promise<void> => {\n if (found || released) return;\n try {\n await access(filePath);\n if (released) return;\n found = true;\n notify?.();\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== NOT_FOUND_ERROR_CODE) process.emitWarning(String(error));\n }\n };\n const probe = (): void => {\n void settle();\n };\n const listeners = entry.waiters.get(name) ?? new Set<() => void>();\n listeners.add(probe);\n entry.waiters.set(name, listeners);\n\n // The file can land between opening the watcher and the first wait, and that\n // create event has nobody listening for it yet.\n probe();\n\n return {\n async appeared(withinMs: number): Promise<boolean> {\n if (found) return true;\n return await new Promise<boolean>((resolve) => {\n const timer = setTimeout(async () => {\n notify = undefined;\n // The watcher is an optimisation, not the answer. A create event that\n // was coalesced, reported under the temporary name of a rename, or\n // never delivered at all must not outlive the slice it belongs to, so\n // every slice ends by asking the filesystem itself.\n await settle();\n resolve(found);\n }, withinMs);\n // Deliberately left holding the event loop. A run still being waited on\n // is work, and a process that exits during the gap between two probes\n // drops the result its caller is awaiting.\n notify = () => {\n clearTimeout(timer);\n notify = undefined;\n resolve(true);\n };\n });\n },\n close(): void {\n if (released) return;\n released = true;\n notify = undefined;\n listeners.delete(probe);\n if (listeners.size === 0) entry.waiters.delete(name);\n releaseDirectoryWatch(directory, entry);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,wBAAwB;CACnC,WAAW;CACX,OAAO;CACP,qBAAqB;AACvB;AAEA,MAAM,YAAY;AAClB,MAAM,uBAAuB;AAE7B,SAAgB,gBAAgB,WAAmB,IAA6B;CAC9E,OAAO;EACL,MAAM,KAAK,KAAK,WAAW,GAAG,GAAG,cAAc;EAC/C,MAAM,KAAK,KAAK,WAAW,GAAG,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;KAClB,SAAS,KAAA;KACT,QAAQ,IAAI;IACd;GACF,CAAC;EACH;EACA,QAAc;GACZ,IAAI,UAAU;GACd,WAAW;GACX,SAAS,KAAA;GACT,UAAU,OAAO,KAAK;GACtB,IAAI,UAAU,SAAS,GAAG,MAAM,QAAQ,OAAO,IAAI;GACnD,sBAAsB,WAAW,KAAK;EACxC;CACF;AACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/constants/session.ts
|
|
2
|
+
const PO_SESSION_ID_ENV = "PO_SESSION_ID";
|
|
3
|
+
const PO_SESSION_TEMP_DIR_ENV = "PO_SESSION_TEMP_DIR";
|
|
4
|
+
const SUBAGENT_ROOT_SESSION_ENV = "PI_SUBAGENT_ROOT_SESSION";
|
|
5
|
+
//#endregion
|
|
6
|
+
export { PO_SESSION_TEMP_DIR_ENV as n, SUBAGENT_ROOT_SESSION_ENV as r, PO_SESSION_ID_ENV as t };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=session-CdVeSD7F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-CdVeSD7F.mjs","names":[],"sources":["../src/constants/session.ts"],"sourcesContent":["export const PO_SESSION_ID_ENV = 'PO_SESSION_ID';\n\n// Copies of po-core's `PO_SESSION_TEMP_DIR` and `SUBAGENT_ROOT_SESSION_ENV`. The per-command runner\n// host would otherwise load po-core/platform and po-core/childProcess (about 60 MB RSS) for two strings.\nexport const PO_SESSION_TEMP_DIR_ENV = 'PO_SESSION_TEMP_DIR';\nexport const SUBAGENT_ROOT_SESSION_ENV = 'PI_SUBAGENT_ROOT_SESSION';\n"],"mappings":";AAAA,MAAa,oBAAoB;AAIjC,MAAa,0BAA0B;AACvC,MAAa,4BAA4B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/constants/session.ts
|
|
2
|
+
const PO_SESSION_ID_ENV = "PO_SESSION_ID";
|
|
3
|
+
const PO_SESSION_TEMP_DIR_ENV = "PO_SESSION_TEMP_DIR";
|
|
4
|
+
const SUBAGENT_ROOT_SESSION_ENV = "PI_SUBAGENT_ROOT_SESSION";
|
|
5
|
+
//#endregion
|
|
6
|
+
Object.defineProperty(exports, "PO_SESSION_ID_ENV", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return PO_SESSION_ID_ENV;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "PO_SESSION_TEMP_DIR_ENV", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function() {
|
|
15
|
+
return PO_SESSION_TEMP_DIR_ENV;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "SUBAGENT_ROOT_SESSION_ENV", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function() {
|
|
21
|
+
return SUBAGENT_ROOT_SESSION_ENV;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=session-DnUj8Q71.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-DnUj8Q71.cjs","names":[],"sources":["../src/constants/session.ts"],"sourcesContent":["export const PO_SESSION_ID_ENV = 'PO_SESSION_ID';\n\n// Copies of po-core's `PO_SESSION_TEMP_DIR` and `SUBAGENT_ROOT_SESSION_ENV`. The per-command runner\n// host would otherwise load po-core/platform and po-core/childProcess (about 60 MB RSS) for two strings.\nexport const PO_SESSION_TEMP_DIR_ENV = 'PO_SESSION_TEMP_DIR';\nexport const SUBAGENT_ROOT_SESSION_ENV = 'PI_SUBAGENT_ROOT_SESSION';\n"],"mappings":";AAAA,MAAa,oBAAoB;AAIjC,MAAa,0BAA0B;AACvC,MAAa,4BAA4B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { r as SUBAGENT_ROOT_SESSION_ENV, t as PO_SESSION_ID_ENV } from "./session-CdVeSD7F.mjs";
|
|
2
|
+
//#region src/services/session/index.ts
|
|
3
|
+
/** Session identity inherited by commands launched from a Pi session. */
|
|
4
|
+
/** Returns a usable inherited session id, failing closed on blank values. */
|
|
5
|
+
function inheritedSessionId(env = process.env) {
|
|
6
|
+
const value = env[PO_SESSION_ID_ENV]?.trim();
|
|
7
|
+
return value ? value : void 0;
|
|
8
|
+
}
|
|
9
|
+
/** Returns the inherited Pi session id or fails closed outside a session. */
|
|
10
|
+
function requiredSessionId(env = process.env) {
|
|
11
|
+
const sessionId = inheritedSessionId(env);
|
|
12
|
+
if (!sessionId) throw new Error(`${PO_SESSION_ID_ENV} is required for po-runner`);
|
|
13
|
+
return sessionId;
|
|
14
|
+
}
|
|
15
|
+
/** Copy of po-core's `resolveRootSessionId`: the inherited subagent root, else the current session. */
|
|
16
|
+
function resolveRootSessionId(currentSessionId, environment) {
|
|
17
|
+
const inherited = environment[SUBAGENT_ROOT_SESSION_ENV]?.trim();
|
|
18
|
+
if (inherited) return inherited;
|
|
19
|
+
const current = currentSessionId.trim();
|
|
20
|
+
if (!current) throw new Error("A root session requires a non-empty current session id.");
|
|
21
|
+
return current;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { requiredSessionId as n, resolveRootSessionId as r, inheritedSessionId as t };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=session-ISEGK4z9.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-ISEGK4z9.mjs","names":[],"sources":["../src/services/session/index.ts"],"sourcesContent":["import { PO_SESSION_ID_ENV, SUBAGENT_ROOT_SESSION_ENV } from '../../constants/session';\n/** Session identity inherited by commands launched from a Pi session. */\n\n/** Returns a usable inherited session id, failing closed on blank values. */\nexport function inheritedSessionId(env: NodeJS.ProcessEnv = process.env): string | undefined {\n const value = env[PO_SESSION_ID_ENV]?.trim();\n return value ? value : undefined;\n}\n\n/** Returns the inherited Pi session id or fails closed outside a session. */\nexport function requiredSessionId(env: NodeJS.ProcessEnv = process.env): string {\n const sessionId = inheritedSessionId(env);\n if (!sessionId) throw new Error(`${PO_SESSION_ID_ENV} is required for po-runner`);\n return sessionId;\n}\n\n/** Copy of po-core's `resolveRootSessionId`: the inherited subagent root, else the current session. */\nexport function resolveRootSessionId(\n currentSessionId: string,\n environment: Readonly<Record<string, string | undefined>>,\n): string {\n const inherited = environment[SUBAGENT_ROOT_SESSION_ENV]?.trim();\n if (inherited) return inherited;\n const current = currentSessionId.trim();\n if (!current) throw new Error('A root session requires a non-empty current session id.');\n return current;\n}\n"],"mappings":";;;;AAIA,SAAgB,mBAAmB,MAAyB,QAAQ,KAAyB;CAC3F,MAAM,QAAQ,IAAI,kBAAkB,EAAE,KAAK;CAC3C,OAAO,QAAQ,QAAQ,KAAA;AACzB;;AAGA,SAAgB,kBAAkB,MAAyB,QAAQ,KAAa;CAC9E,MAAM,YAAY,mBAAmB,GAAG;CACxC,IAAI,CAAC,WAAW,MAAM,IAAI,MAAM,GAAG,kBAAkB,2BAA2B;CAChF,OAAO;AACT;;AAGA,SAAgB,qBACd,kBACA,aACQ;CACR,MAAM,YAAY,YAAY,0BAA0B,EAAE,KAAK;CAC/D,IAAI,WAAW,OAAO;CACtB,MAAM,UAAU,iBAAiB,KAAK;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,yDAAyD;CACvF,OAAO;AACT"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const require_session = require("./session-DnUj8Q71.cjs");
|
|
2
|
+
//#region src/services/session/index.ts
|
|
3
|
+
/** Session identity inherited by commands launched from a Pi session. */
|
|
4
|
+
/** Returns a usable inherited session id, failing closed on blank values. */
|
|
5
|
+
function inheritedSessionId(env = process.env) {
|
|
6
|
+
const value = env[require_session.PO_SESSION_ID_ENV]?.trim();
|
|
7
|
+
return value ? value : void 0;
|
|
8
|
+
}
|
|
9
|
+
/** Returns the inherited Pi session id or fails closed outside a session. */
|
|
10
|
+
function requiredSessionId(env = process.env) {
|
|
11
|
+
const sessionId = inheritedSessionId(env);
|
|
12
|
+
if (!sessionId) throw new Error(`${require_session.PO_SESSION_ID_ENV} is required for po-runner`);
|
|
13
|
+
return sessionId;
|
|
14
|
+
}
|
|
15
|
+
/** Copy of po-core's `resolveRootSessionId`: the inherited subagent root, else the current session. */
|
|
16
|
+
function resolveRootSessionId(currentSessionId, environment) {
|
|
17
|
+
const inherited = environment[require_session.SUBAGENT_ROOT_SESSION_ENV]?.trim();
|
|
18
|
+
if (inherited) return inherited;
|
|
19
|
+
const current = currentSessionId.trim();
|
|
20
|
+
if (!current) throw new Error("A root session requires a non-empty current session id.");
|
|
21
|
+
return current;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
Object.defineProperty(exports, "inheritedSessionId", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function() {
|
|
27
|
+
return inheritedSessionId;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "requiredSessionId", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function() {
|
|
33
|
+
return requiredSessionId;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "resolveRootSessionId", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function() {
|
|
39
|
+
return resolveRootSessionId;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=session-PQd3azWf.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-PQd3azWf.cjs","names":["PO_SESSION_ID_ENV","SUBAGENT_ROOT_SESSION_ENV"],"sources":["../src/services/session/index.ts"],"sourcesContent":["import { PO_SESSION_ID_ENV, SUBAGENT_ROOT_SESSION_ENV } from '../../constants/session';\n/** Session identity inherited by commands launched from a Pi session. */\n\n/** Returns a usable inherited session id, failing closed on blank values. */\nexport function inheritedSessionId(env: NodeJS.ProcessEnv = process.env): string | undefined {\n const value = env[PO_SESSION_ID_ENV]?.trim();\n return value ? value : undefined;\n}\n\n/** Returns the inherited Pi session id or fails closed outside a session. */\nexport function requiredSessionId(env: NodeJS.ProcessEnv = process.env): string {\n const sessionId = inheritedSessionId(env);\n if (!sessionId) throw new Error(`${PO_SESSION_ID_ENV} is required for po-runner`);\n return sessionId;\n}\n\n/** Copy of po-core's `resolveRootSessionId`: the inherited subagent root, else the current session. */\nexport function resolveRootSessionId(\n currentSessionId: string,\n environment: Readonly<Record<string, string | undefined>>,\n): string {\n const inherited = environment[SUBAGENT_ROOT_SESSION_ENV]?.trim();\n if (inherited) return inherited;\n const current = currentSessionId.trim();\n if (!current) throw new Error('A root session requires a non-empty current session id.');\n return current;\n}\n"],"mappings":";;;;AAIA,SAAgB,mBAAmB,MAAyB,QAAQ,KAAyB;CAC3F,MAAM,QAAQ,IAAIA,gBAAAA,kBAAkB,EAAE,KAAK;CAC3C,OAAO,QAAQ,QAAQ,KAAA;AACzB;;AAGA,SAAgB,kBAAkB,MAAyB,QAAQ,KAAa;CAC9E,MAAM,YAAY,mBAAmB,GAAG;CACxC,IAAI,CAAC,WAAW,MAAM,IAAI,MAAM,GAAGA,gBAAAA,kBAAkB,2BAA2B;CAChF,OAAO;AACT;;AAGA,SAAgB,qBACd,kBACA,aACQ;CACR,MAAM,YAAY,YAAYC,gBAAAA,0BAA0B,EAAE,KAAK;CAC/D,IAAI,WAAW,OAAO;CACtB,MAAM,UAAU,iBAAiB,KAAK;CACtC,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,yDAAyD;CACvF,OAAO;AACT"}
|
package/dist/session.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_session = require("./session-
|
|
3
|
-
const require_session$1 = require("./session-
|
|
4
|
-
exports.
|
|
2
|
+
const require_session = require("./session-DnUj8Q71.cjs");
|
|
3
|
+
const require_session$1 = require("./session-PQd3azWf.cjs");
|
|
4
|
+
exports.PO_SESSION_ID_ENV = require_session.PO_SESSION_ID_ENV;
|
|
5
5
|
exports.inheritedSessionId = require_session$1.inheritedSessionId;
|
|
6
6
|
exports.requiredSessionId = require_session$1.requiredSessionId;
|
|
7
|
+
exports.resolveRootSessionId = require_session$1.resolveRootSessionId;
|
package/dist/session.d.mts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
export declare function inheritedSessionId(env?: NodeJS.ProcessEnv): string | undefined;
|
|
5
5
|
/** Returns the inherited Pi session id or fails closed outside a session. */
|
|
6
6
|
export declare function requiredSessionId(env?: NodeJS.ProcessEnv): string;
|
|
7
|
+
/** Copy of po-core's `resolveRootSessionId`: the inherited subagent root, else the current session. */
|
|
8
|
+
export declare function resolveRootSessionId(currentSessionId: string, environment: Readonly<Record<string, string | undefined>>): string;
|
|
7
9
|
//#endregion
|
|
8
10
|
//#region src/constants/session.d.ts
|
|
9
|
-
export declare const
|
|
11
|
+
export declare const PO_SESSION_ID_ENV = "PO_SESSION_ID";
|
|
10
12
|
//#endregion
|
|
11
13
|
//# sourceMappingURL=session.d.mts.map
|
package/dist/session.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.mts","names":[],"sources":["../src/services/session/index.ts","../src/constants/session.ts"],"mappings":";;;wBAIgB,mBAAmB,MAAK,OAAO;;wBAM/B,kBAAkB,MAAK,OAAO;;;
|
|
1
|
+
{"version":3,"file":"session.d.mts","names":[],"sources":["../src/services/session/index.ts","../src/constants/session.ts"],"mappings":";;;wBAIgB,mBAAmB,MAAK,OAAO;;wBAM/B,kBAAkB,MAAK,OAAO;;wBAO9B,qBACd,0BACA,aAAa,SAAS;;;qBCnBX"}
|
package/dist/session.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { n as requiredSessionId, t as inheritedSessionId } from "./session-
|
|
3
|
-
export {
|
|
1
|
+
import { t as PO_SESSION_ID_ENV } from "./session-CdVeSD7F.mjs";
|
|
2
|
+
import { n as requiredSessionId, r as resolveRootSessionId, t as inheritedSessionId } from "./session-ISEGK4z9.mjs";
|
|
3
|
+
export { PO_SESSION_ID_ENV, inheritedSessionId, requiredSessionId, resolveRootSessionId };
|
|
@@ -6,7 +6,7 @@ interface LogSweepResult {
|
|
|
6
6
|
/** Filesystem layout for runner state, scoped to one Pi session. */
|
|
7
7
|
interface IRunnerPaths {
|
|
8
8
|
/** Worktree root, used as the registry scope key. */
|
|
9
|
-
repositoryPath(): string
|
|
9
|
+
repositoryPath(): Promise<string>;
|
|
10
10
|
/** Adopt the Pi session before the extension reads or writes runner state. */
|
|
11
11
|
setSessionId(sessionId: string): void;
|
|
12
12
|
/** Directory holding one session's runner logs. */
|
|
@@ -26,7 +26,9 @@ interface IRunnerPaths {
|
|
|
26
26
|
*/
|
|
27
27
|
rawLogPathFor(id: string, sessionId?: string): string;
|
|
28
28
|
statePathFor(id: string, sessionId?: string): string;
|
|
29
|
-
ensureDirectories(sessionId?: string): void
|
|
29
|
+
ensureDirectories(sessionId?: string): Promise<void>;
|
|
30
|
+
/** Purge only session runner files after writers have stopped. */
|
|
31
|
+
removeSessionFiles?(sessionId?: string, generation?: string): Promise<void>;
|
|
30
32
|
/** The directory every session's runner state lives under, or the pinned log directory's parent. */
|
|
31
33
|
storeDirectory(): string;
|
|
32
34
|
/**
|
|
@@ -35,10 +37,10 @@ interface IRunnerPaths {
|
|
|
35
37
|
* directories keep their lifeline and are only trimmed record by record; by default it is the
|
|
36
38
|
* one session this layout adopted.
|
|
37
39
|
*/
|
|
38
|
-
sweepHistory(ttlMs: number, now?: number, live?: ReadonlySet<string>): LogSweepResult
|
|
40
|
+
sweepHistory(ttlMs: number, now?: number, live?: ReadonlySet<string>): Promise<LogSweepResult>;
|
|
39
41
|
/** Async startup-safe form of history retention cleanup. */
|
|
40
42
|
sweepHistoryAsync?(ttlMs: number, now?: number, live?: ReadonlySet<string>): Promise<LogSweepResult>;
|
|
41
43
|
}
|
|
42
44
|
//#endregion
|
|
43
45
|
export { LogSweepResult as n, IRunnerPaths as t };
|
|
44
|
-
//# sourceMappingURL=type-
|
|
46
|
+
//# sourceMappingURL=type-BWY9vvSq.d.mts.map
|