@chrisjowen/wheelhouse 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -1
- package/build/client/_app/immutable/assets/0.CS9-5c8D.css +1 -0
- package/build/client/_app/immutable/assets/0.CS9-5c8D.css.br +0 -0
- package/build/client/_app/immutable/assets/0.CS9-5c8D.css.gz +0 -0
- package/build/client/_app/immutable/chunks/{B597Cbe1.js → 8JUY7TGF.js} +1 -1
- package/build/client/_app/immutable/chunks/8JUY7TGF.js.br +0 -0
- package/build/client/_app/immutable/chunks/8JUY7TGF.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{Cbm0yS9E.js → B78SKOml.js} +1 -1
- package/build/client/_app/immutable/chunks/B78SKOml.js.br +0 -0
- package/build/client/_app/immutable/chunks/B78SKOml.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{CPQbfMGI.js → BIJDRvOc.js} +1 -1
- package/build/client/_app/immutable/chunks/BIJDRvOc.js.br +0 -0
- package/build/client/_app/immutable/chunks/BIJDRvOc.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{DVeiiKip.js → BYUAxBPx.js} +1 -1
- package/build/client/_app/immutable/chunks/BYUAxBPx.js.br +0 -0
- package/build/client/_app/immutable/chunks/BYUAxBPx.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BezBg3rs.js +1 -0
- package/build/client/_app/immutable/chunks/BezBg3rs.js.br +0 -0
- package/build/client/_app/immutable/chunks/BezBg3rs.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{DnBZO8Il.js → BrlWJk4r.js} +1 -1
- package/build/client/_app/immutable/chunks/BrlWJk4r.js.br +0 -0
- package/build/client/_app/immutable/chunks/BrlWJk4r.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{BiiAyXOY.js → Bw22EWRR.js} +1 -1
- package/build/client/_app/immutable/chunks/Bw22EWRR.js.br +0 -0
- package/build/client/_app/immutable/chunks/Bw22EWRR.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{CC5Ts_xe.js → C6B0JAFe.js} +1 -1
- package/build/client/_app/immutable/chunks/C6B0JAFe.js.br +0 -0
- package/build/client/_app/immutable/chunks/C6B0JAFe.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{BEKG1Stw.js → C8OIAOGW.js} +1 -1
- package/build/client/_app/immutable/chunks/C8OIAOGW.js.br +0 -0
- package/build/client/_app/immutable/chunks/C8OIAOGW.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{60JlvdhQ.js → CEHCs8E4.js} +1 -1
- package/build/client/_app/immutable/chunks/CEHCs8E4.js.br +0 -0
- package/build/client/_app/immutable/chunks/CEHCs8E4.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{ChjkQemt.js → CL60_qsS.js} +1 -1
- package/build/client/_app/immutable/chunks/CL60_qsS.js.br +0 -0
- package/build/client/_app/immutable/chunks/CL60_qsS.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{C69eHrL5.js → CeuOu7QI.js} +1 -1
- package/build/client/_app/immutable/chunks/CeuOu7QI.js.br +0 -0
- package/build/client/_app/immutable/chunks/CeuOu7QI.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{CSntU4ww.js → Cn9pLe1S.js} +1 -1
- package/build/client/_app/immutable/chunks/Cn9pLe1S.js.br +0 -0
- package/build/client/_app/immutable/chunks/Cn9pLe1S.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{CvZklcJq.js → D1QZsS_n.js} +1 -1
- package/build/client/_app/immutable/chunks/D1QZsS_n.js.br +0 -0
- package/build/client/_app/immutable/chunks/D1QZsS_n.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{IKqZ9EUq.js → D3z87-GH.js} +5 -5
- package/build/client/_app/immutable/chunks/D3z87-GH.js.br +0 -0
- package/build/client/_app/immutable/chunks/D3z87-GH.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{DSAFUgJn.js → D69HGG2e.js} +1 -1
- package/build/client/_app/immutable/chunks/D69HGG2e.js.br +0 -0
- package/build/client/_app/immutable/chunks/D69HGG2e.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{B-rYWQGG.js → DGZVZsEx.js} +1 -1
- package/build/client/_app/immutable/chunks/DGZVZsEx.js.br +0 -0
- package/build/client/_app/immutable/chunks/DGZVZsEx.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{rZ2-WaWD.js → Dbi_7cO_.js} +2 -2
- package/build/client/_app/immutable/chunks/Dbi_7cO_.js.br +0 -0
- package/build/client/_app/immutable/chunks/Dbi_7cO_.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{DjCsArDj.js → Dq4WC4aT.js} +1 -1
- package/build/client/_app/immutable/chunks/Dq4WC4aT.js.br +0 -0
- package/build/client/_app/immutable/chunks/Dq4WC4aT.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{Gbvs-EZ4.js → QrHSSdjC.js} +1 -1
- package/build/client/_app/immutable/chunks/QrHSSdjC.js.br +2 -0
- package/build/client/_app/immutable/chunks/QrHSSdjC.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{BPAziDlG.js → bOtONP_M.js} +1 -1
- package/build/client/_app/immutable/chunks/bOtONP_M.js.br +0 -0
- package/build/client/_app/immutable/chunks/bOtONP_M.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.B0SozPUz.js +2 -0
- package/build/client/_app/immutable/entry/app.B0SozPUz.js.br +0 -0
- package/build/client/_app/immutable/entry/app.B0SozPUz.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.BgyXy-5i.js +1 -0
- package/build/client/_app/immutable/entry/start.BgyXy-5i.js.br +0 -0
- package/build/client/_app/immutable/entry/start.BgyXy-5i.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{0.CPXJEdVC.js → 0.BH-p6KNP.js} +1 -1
- package/build/client/_app/immutable/nodes/0.BH-p6KNP.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.BH-p6KNP.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{1.BsHjzKoN.js → 1.5bKMe7me.js} +1 -1
- package/build/client/_app/immutable/nodes/1.5bKMe7me.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.5bKMe7me.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{10.JvkeSj5x.js → 10.CuyB--Be.js} +1 -1
- package/build/client/_app/immutable/nodes/10.CuyB--Be.js.br +0 -0
- package/build/client/_app/immutable/nodes/10.CuyB--Be.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{11.C9viE404.js → 11.Cp96bYst.js} +1 -1
- package/build/client/_app/immutable/nodes/11.Cp96bYst.js.br +0 -0
- package/build/client/_app/immutable/nodes/11.Cp96bYst.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{12.BWVqITW1.js → 12.B9kS4-UK.js} +1 -1
- package/build/client/_app/immutable/nodes/12.B9kS4-UK.js.br +0 -0
- package/build/client/_app/immutable/nodes/12.B9kS4-UK.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{13.D0u53Jpp.js → 13.ie4sMrRi.js} +1 -1
- package/build/client/_app/immutable/nodes/13.ie4sMrRi.js.br +0 -0
- package/build/client/_app/immutable/nodes/13.ie4sMrRi.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{14.CNClDl2g.js → 14.CqfbcQC3.js} +1 -1
- package/build/client/_app/immutable/nodes/14.CqfbcQC3.js.br +0 -0
- package/build/client/_app/immutable/nodes/14.CqfbcQC3.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{15.BJShjxpx.js → 15.ClcEiTus.js} +1 -1
- package/build/client/_app/immutable/nodes/15.ClcEiTus.js.br +0 -0
- package/build/client/_app/immutable/nodes/15.ClcEiTus.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{16.Bb3PPsch.js → 16.Lubye7rY.js} +1 -1
- package/build/client/_app/immutable/nodes/16.Lubye7rY.js.br +0 -0
- package/build/client/_app/immutable/nodes/16.Lubye7rY.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{17.COjMgZvi.js → 17.CZsgvMnU.js} +1 -1
- package/build/client/_app/immutable/nodes/17.CZsgvMnU.js.br +0 -0
- package/build/client/_app/immutable/nodes/17.CZsgvMnU.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{19.BbeSGQyg.js → 19.nb4PEk6e.js} +1 -1
- package/build/client/_app/immutable/nodes/19.nb4PEk6e.js.br +0 -0
- package/build/client/_app/immutable/nodes/19.nb4PEk6e.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.DBpcacIW.js +26 -0
- package/build/client/_app/immutable/nodes/2.DBpcacIW.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.DBpcacIW.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{20.2D2FCLQq.js → 20.DKDJA76m.js} +1 -1
- package/build/client/_app/immutable/nodes/20.DKDJA76m.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.DKDJA76m.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{21.xQ_KUjAi.js → 21.DDSJrVwV.js} +1 -1
- package/build/client/_app/immutable/nodes/21.DDSJrVwV.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.DDSJrVwV.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{22.DuszjIrq.js → 22.Bf2Y4qtK.js} +1 -1
- package/build/client/_app/immutable/nodes/22.Bf2Y4qtK.js.br +0 -0
- package/build/client/_app/immutable/nodes/22.Bf2Y4qtK.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{23.CKoLeDhM.js → 23.CgSRzQDr.js} +1 -1
- package/build/client/_app/immutable/nodes/23.CgSRzQDr.js.br +0 -0
- package/build/client/_app/immutable/nodes/23.CgSRzQDr.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{24.CH1byq7o.js → 24.fKJczgYC.js} +1 -1
- package/build/client/_app/immutable/nodes/24.fKJczgYC.js.br +0 -0
- package/build/client/_app/immutable/nodes/24.fKJczgYC.js.gz +0 -0
- package/build/client/_app/immutable/nodes/25.BzI2N_Dl.js +14 -0
- package/build/client/_app/immutable/nodes/25.BzI2N_Dl.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.BzI2N_Dl.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{26.CHB__H6C.js → 26.Bl7bQZez.js} +1 -1
- package/build/client/_app/immutable/nodes/26.Bl7bQZez.js.br +0 -0
- package/build/client/_app/immutable/nodes/26.Bl7bQZez.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{28.pI-7Vnsb.js → 28.B9EWyQv6.js} +1 -1
- package/build/client/_app/immutable/nodes/28.B9EWyQv6.js.br +0 -0
- package/build/client/_app/immutable/nodes/28.B9EWyQv6.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{3.6gLsJ5iP.js → 3.DMxCWZ16.js} +1 -1
- package/build/client/_app/immutable/nodes/3.DMxCWZ16.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.DMxCWZ16.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{4.uKPQRIJV.js → 4.Bj_V5H0A.js} +1 -1
- package/build/client/_app/immutable/nodes/4.Bj_V5H0A.js.br +0 -0
- package/build/client/_app/immutable/nodes/4.Bj_V5H0A.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{6.CmppqGHA.js → 6.BAzIGIXP.js} +1 -1
- package/build/client/_app/immutable/nodes/6.BAzIGIXP.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.BAzIGIXP.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{7.DDZOqRAy.js → 7.CpRItf5T.js} +1 -1
- package/build/client/_app/immutable/nodes/7.CpRItf5T.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.CpRItf5T.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{8.DH6CiiFf.js → 8.BRbaXe0L.js} +1 -1
- package/build/client/_app/immutable/nodes/8.BRbaXe0L.js.br +0 -0
- package/build/client/_app/immutable/nodes/8.BRbaXe0L.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{9.jlOFlXh8.js → 9.DpQmfi7O.js} +1 -1
- package/build/client/_app/immutable/nodes/9.DpQmfi7O.js.br +0 -0
- package/build/client/_app/immutable/nodes/9.DpQmfi7O.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/handler.js +4 -4
- package/build/index.js +4 -4
- package/build/server/chunks/chunks/{DecisionCard.js-DQls79M-.js → DecisionCard.js-Cim80Nvw.js} +2 -2
- package/build/server/chunks/chunks/{OpenDecision.js-1bnVd2CO.js → OpenDecision.js-BVAXM8UF.js} +3 -3
- package/build/server/chunks/chunks/{chat.svelte.js-t_sykiqk.js → chat.svelte.js-BcKQjH6T.js} +5 -1
- package/build/server/chunks/chunks/{detail.js-BHgTIrxq.js → detail.js-BBCxJBpU.js} +2 -2
- package/build/server/chunks/chunks/{feedback.js-CNjq89nb.js → feedback.js-DHLUCzN_.js} +2 -2
- package/build/server/chunks/chunks/harness.js-DPojOlFJ.js +16 -0
- package/build/server/chunks/chunks/{insights.svelte.js-jvJ6zpkP.js → insights.svelte.js-CLCl4593.js} +4 -4
- package/build/server/chunks/chunks/{internal.js-DxO60Agy.js → internal.js-CedW099c.js} +3 -3
- package/build/server/chunks/chunks/{keychain.js-CTV5MMKd.js → keychain.js-CspIw1lK.js} +2 -2
- package/build/server/chunks/chunks/{marketplace-service.js-DZ7N3g7i.js → marketplace-service.js-O-2c34nr.js} +2 -2
- package/build/server/chunks/chunks/{page.js-slDjdKdN.js → page.js-BRRl6mg_.js} +2 -2
- package/build/server/chunks/chunks/{previewhelper2.js-D62yPZ3-.js → previewhelper2.js-CLYvgGeM.js} +2 -2
- package/build/server/chunks/chunks/{repo.js-CpMWC7Dl.js → repo.js-BQv7p3Qv.js} +2 -2
- package/build/server/chunks/chunks/{runtime.js-n2Nl0Kn0.js → runtime.js-ja9fpm3a.js} +2111 -788
- package/build/server/chunks/chunks/{service.js-BBKBSt-r.js → service.js-CHB5De_m.js} +2 -2
- package/build/server/chunks/chunks/{service2.js-D8unm3Dr.js → service2.js-BSXaHqaf.js} +24 -10
- package/build/server/chunks/chunks/{starter.js-BJtAaz_v.js → starter.js-BL6kYdY7.js} +2 -2
- package/build/server/chunks/chunks/{terminal.js-BckfZrAP.js → terminal.js-s8yEF1TY.js} +3 -1
- package/build/server/chunks/chunks/{view.js-DY3ke6NQ.js → view.js-DvrTXTsb.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/apps/_op_/{_server.ts.js-DU337wCA.js → _server.ts.js-DJDX8mej.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/cloud/{_server.ts.js-DUjwvbDq.js → _server.ts.js-ZpNBOdE6.js} +3 -3
- package/build/server/chunks/entries/endpoints/api/cloud/previews/{_server.ts.js-fB_wI3kP.js → _server.ts.js-cLGgBi-L.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/events/{_server.ts.js-HZjTDOIW.js → _server.ts.js-DyA-Ftti.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/files/{_server.ts.js-vtgE6dmd.js → _server.ts.js-BRutjWld.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/chat/{_server.ts.js-CBUM_cHq.js → _server.ts.js-CSUsZ_Uy.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/commands/{_server.ts.js-gqNm0NgZ.js → _server.ts.js-CyMAbBop.js} +9 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/dismiss/{_server.ts.js-DVTt9exZ.js → _server.ts.js-C1QNh7Fv.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/input/{_server.ts.js-DI8pSLdx.js → _server.ts.js-xAS3zgy6.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/interrupt/{_server.ts.js-DwNKcPAZ.js → _server.ts.js-C0ChpkPv.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/messages/{_server.ts.js-gn9Pb6xh.js → _server.ts.js-Dg8UqJYL.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/firstmate/pick/{_server.ts.js-BsuIck0U.js → _server.ts.js-KtXAKUKl.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/reactions/{_server.ts.js-Du1j3gY1.js → _server.ts.js-SfyGIsms.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/firstmate/start/{_server.ts.js-D5_z22cM.js → _server.ts.js-uKjVaQqO.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/fleet/{_server.ts.js-CqUodLtV.js → _server.ts.js-Bh09YMSB.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/gateway/{_server.ts.js-Bqvpqc3W.js → _server.ts.js-DiOWY9as.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/health/{_server.ts.js-U1yy4XTd.js → _server.ts.js-BRjxK-9y.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/inbox/{_server.ts.js-Bt1HEbxQ.js → _server.ts.js-CA3XQih9.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/inbox/report/{_server.ts.js-B1QGwJJx.js → _server.ts.js-B5MRXVz2.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/insights/{_server.ts.js-4D31QJkx.js → _server.ts.js-Hj5j2VEd.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/plugins/_plugin_/config/{_server.ts.js-BB9t2sPI.js → _server.ts.js-CG5hVtIr.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/plugins/_plugin_/feedback/{_server.ts.js-C0lNGC_e.js → _server.ts.js-CbfYfN4W.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/plugins/_plugin_/feedback/summary/{_server.ts.js-BCucQ7kV.js → _server.ts.js-Cntqh4w-.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/plugins/_plugin_/icon/_icon_/{_server.ts.js-K051c2NK.js → _server.ts.js-DbaYfmK8.js} +5 -4
- package/build/server/chunks/entries/endpoints/api/plugins/_plugin_/load/{_server.ts.js-DXp7CBKJ.js → _server.ts.js-CMC6khtq.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/plugins/_plugin_/ui/_...path_/{_server.ts.js-BZjRhE_E.js → _server.ts.js-DiCaOT3E.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/plugins/_plugin_/update/{_server.ts.js-C6pSTIZl.js → _server.ts.js-DQZxZKa4.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/plugins/{_server.ts.js-CPTGODgJ.js → _server.ts.js-CaQ772k3.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/plugins/inspect/{_server.ts.js-CYyhaWOu.js → _server.ts.js-DkjBSjdS.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/plugins/install/{_server.ts.js-LOfrDPqm.js → _server.ts.js-BLEOrgEt.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/plugins/marketplace/{_server.ts.js-CqJSn65A.js → _server.ts.js-rrfRBhVX.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/plugins/marketplace/icon/_name_/{_server.ts.js-vWLUvqe2.js → _server.ts.js-DEaeguu1.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/plugins/marketplace/registries/{_server.ts.js-CIy3Yxnj.js → _server.ts.js-DGviOddp.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/plugins/updates/{_server.ts.js-BXKekEzg.js → _server.ts.js-BfwOLICk.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/previews/check/{_server.ts.js-DZnqmxa7.js → _server.ts.js-C3dZCo79.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/projects/_id_/passage/{_server.ts.js-clRCP6Vz.js → _server.ts.js-QCxCUoaZ.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/projects/_id_/passage/commands/{_server.ts.js-C0v3Eifj.js → _server.ts.js-CIHZWmY6.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/projects/_id_/passage/consent/{_server.ts.js-B1P26NiL.js → _server.ts.js-9MZ6ZU7W.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/projects/_id_/passage/draft/{_server.ts.js-_BWFybXT.js → _server.ts.js-YJgYZpm2.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/projects/_id_/passage/file/{_server.ts.js-DM_qs0_P.js → _server.ts.js-DRO0yFlG.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/projects/_id_/passage/test/{_server.ts.js-Cp4DC5RF.js → _server.ts.js--78Nc6jj.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/second-mates/_id_/peek/{_server.ts.js-CFQmNKZw.js → _server.ts.js-B92-w9Jt.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/services/{_server.ts.js-C0Hp3ghu.js → _server.ts.js-BlgDs2xk.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/setup/{_server.ts.js-OI33JqAV.js → _server.ts.js-Cc70st9n.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/slots/{_server.ts.js-BOetbdrI.js → _server.ts.js-COmpO5sc.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/tasks/_id_/{_server.ts.js-BE02dpgR.js → _server.ts.js-DcHNA_QH.js} +7 -6
- package/build/server/chunks/entries/endpoints/api/tasks/_id_/artifacts/_...name_/{_server.ts.js-eXiYz0dl.js → _server.ts.js-BIBAGkdF.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/tasks/_id_/diff/{_server.ts.js-BzPQmqhd.js → _server.ts.js-DXKDhcRn.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/tasks/_id_/output/{_server.ts.js-DernPNNa.js → _server.ts.js-BgJD7i53.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/tasks/_id_/preview/{_server.ts.js-CIJerTYj.js → _server.ts.js-CxKGr5ok.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/tasks/_id_/preview/helper/{_server.ts.js-wMw-B2LV.js → _server.ts.js-k2erXAMq.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/vault/{_server.ts.js-BQVOZ_2W.js → _server.ts.js-BUmsnNMT.js} +6 -5
- package/build/server/chunks/entries/endpoints/api/wheelhouse/source/{_server.ts.js-CBdZ3Hvx.js → _server.ts.js-Dic1r8FA.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/wheelhouse/update/{_server.ts.js-BjmmYFHq.js → _server.ts.js-DCDFOP3H.js} +2 -2
- package/build/server/chunks/entries/endpoints/api/wheelhouse/upgrade/{_server.ts.js-DxsJBLJe.js → _server.ts.js-DyaR3iKq.js} +2 -2
- package/build/server/chunks/entries/endpoints/tasks/_id_/review/{_server.ts.js-DXYaC6o9.js → _server.ts.js-Ds9qnblb.js} +6 -5
- package/build/server/chunks/entries/{hooks.server.js-CN-DQ0lm.js → hooks.server.js-BLsrrww8.js} +6 -5
- package/build/server/chunks/entries/pages/{_layout.server.ts.js-B3IyG3tO.js → _layout.server.ts.js-CWJXWFa8.js} +2 -2
- package/build/server/chunks/entries/pages/{_layout.svelte.js-ClwzCpuE.js → _layout.svelte.js-CuWnZ-US.js} +2 -2
- package/build/server/chunks/entries/pages/{_page.server.ts.js-DF3mUKXU.js → _page.server.ts.js-DcIo1Fkt.js} +2 -2
- package/build/server/chunks/entries/pages/{_page.svelte.js-DotNRhUC.js → _page.svelte.js-CGR2VowD.js} +33 -19
- package/build/server/chunks/entries/pages/decisions/{_page.server.ts.js-BPsRMW1m.js → _page.server.ts.js-Cumc04zT.js} +2 -2
- package/build/server/chunks/entries/pages/deck/{_page.server.ts.js-CRoejRrt.js → _page.server.ts.js-BvnBsHnq.js} +2 -2
- package/build/server/chunks/entries/pages/deck/{_page.svelte.js-DK__ZtkS.js → _page.svelte.js-zqjb3tWK.js} +5 -5
- package/build/server/chunks/entries/pages/files/{_page.server.ts.js-CEQlok_v.js → _page.server.ts.js-DVzHoqMO.js} +2 -2
- package/build/server/chunks/entries/pages/harbour/{_page.server.ts.js-aNzCSnrW.js → _page.server.ts.js-BK7WgAXR.js} +2 -2
- package/build/server/chunks/entries/pages/headroom/{_page.server.ts.js-DYPjOXZ7.js → _page.server.ts.js-B_et4vbk.js} +2 -2
- package/build/server/chunks/entries/pages/inbox/{_page.server.ts.js-CvLRSeh7.js → _page.server.ts.js-DWY01zRh.js} +2 -2
- package/build/server/chunks/entries/pages/inbox/{_page.svelte.js-aP2FP_cG.js → _page.svelte.js-DLpzhD2s.js} +3 -3
- package/build/server/chunks/entries/pages/plugins/_plugin_/_page_/{_page.server.ts.js-CF2qEBQz.js → _page.server.ts.js-Be_vf2s9.js} +2 -2
- package/build/server/chunks/entries/pages/projects/_id_/{_page.server.ts.js-Drm6Ahc4.js → _page.server.ts.js-euICzR6h.js} +3 -3
- package/build/server/chunks/entries/pages/projects/_id_/_plugin_/_tab_/{_page.server.ts.js-DdJMUWNL.js → _page.server.ts.js-CO-iqBAD.js} +3 -3
- package/build/server/chunks/entries/pages/projects/_id_/passage/{_page.server.ts.js-1GII3zKY.js → _page.server.ts.js-DzQmyVut.js} +4 -4
- package/build/server/chunks/entries/pages/projects/_id_/passage/edit/{_page.server.ts.js-CVsOhaVz.js → _page.server.ts.js-ByePQa4g.js} +2 -2
- package/build/server/chunks/entries/pages/remotes/{_page.server.ts.js-Cva09MAW.js → _page.server.ts.js-DRj_7nDd.js} +2 -2
- package/build/server/chunks/entries/pages/settings/cloud/{_page.server.ts.js-CMMEHMa0.js → _page.server.ts.js-QWGL2-Cn.js} +2 -2
- package/build/server/chunks/entries/pages/settings/gateway/{_page.server.ts.js-CaBLC48A.js → _page.server.ts.js-DAOkZ-fE.js} +2 -2
- package/build/server/chunks/entries/pages/settings/plugins/{_page.server.ts.js-C80JIole.js → _page.server.ts.js-jeZvTAgT.js} +2 -2
- package/build/server/chunks/entries/pages/settings/plugins/_plugin_/{_page.server.ts.js-GcEMXNzE.js → _page.server.ts.js-Bzo5Uals.js} +2 -2
- package/build/server/chunks/entries/pages/settings/setup/{_page.server.ts.js-fmudFG1R.js → _page.server.ts.js-1XiCbDhc.js} +2 -2
- package/build/server/chunks/entries/pages/settings/update/{_page.server.ts.js-Ck0V4NqF.js → _page.server.ts.js-DwYnrxXG.js} +2 -2
- package/build/server/chunks/entries/pages/setup/{_page.server.ts.js-BT2aSao4.js → _page.server.ts.js-DP--6Ko6.js} +3 -3
- package/build/server/chunks/entries/pages/setup/{_page.svelte.js-BvrzY0TN.js → _page.svelte.js-CB6DNUFE.js} +108 -85
- package/build/server/chunks/entries/pages/tasks/_id_/{_page.server.ts.js-DQ9XiVXC.js → _page.server.ts.js-Dl0z8pkQ.js} +3 -3
- package/build/server/chunks/entries/pages/tasks/_id_/{_page.svelte.js-zRkAX1kt.js → _page.svelte.js-Cali_YuK.js} +4 -4
- package/build/server/chunks/entries/pages/tasks/_id_/doc/{_page.server.ts.js-DYUzrHEd.js → _page.server.ts.js-CyPpYkuJ.js} +2 -2
- package/build/server/chunks/entries/pages/time/{_page.server.ts.js-PjptcjBY.js → _page.server.ts.js-DlcJgtrb.js} +2 -2
- package/build/server/chunks/{handler-DhhKWgIp.js → handler-pU2T6cxW.js} +3 -3
- package/build/server/chunks/{index.js-utiPQsQj.js → index.js-B3YyBD1_.js} +2 -2
- package/build/server/chunks/{manifest.js-1v5Twa8d.js → manifest.js-D3OqJAbv.js} +86 -86
- package/build/server/chunks/nodes/{0.js-t5p4uwR-.js → 0.js-DapnlcBu.js} +10 -9
- package/build/server/chunks/nodes/{1.js-B23tX379.js → 1.js-B2zVBiHu.js} +2 -2
- package/build/server/chunks/nodes/{10.js-BYgrUxes.js → 10.js-CwfaDBrN.js} +2 -2
- package/build/server/chunks/nodes/{11.js-D8KeSOxn.js → 11.js-BSKCzLBk.js} +8 -7
- package/build/server/chunks/nodes/{12.js-CSqzXf2C.js → 12.js-Cw0R3pzN.js} +9 -8
- package/build/server/chunks/nodes/{13.js-BucPbiJc.js → 13.js-1CllvmKU.js} +9 -8
- package/build/server/chunks/nodes/{14.js-D5KFW0LX.js → 14.js-Duo10iYX.js} +10 -9
- package/build/server/chunks/nodes/{15.js-DMi0cMxP.js → 15.js-yyKjbIPm.js} +9 -8
- package/build/server/chunks/nodes/{16.js-garu2VVL.js → 16.js-Bw3O413k.js} +6 -6
- package/build/server/chunks/nodes/{17.js-CIGvZ14P.js → 17.js-CKJWbBiG.js} +2 -2
- package/build/server/chunks/nodes/{19.js-D0EE2SJv.js → 19.js-gqmNp-1X.js} +6 -6
- package/build/server/chunks/nodes/{2.js-CGs6HugM.js → 2.js-DbAE0QSU.js} +9 -8
- package/build/server/chunks/nodes/{20.js-CVajTuJ7.js → 20.js-DyVwaMHk.js} +8 -7
- package/build/server/chunks/nodes/{21.js-C53DsYbm.js → 21.js-UWLpwye1.js} +8 -7
- package/build/server/chunks/nodes/{22.js-IhEljvpJ.js → 22.js-DjQqtx9a.js} +8 -7
- package/build/server/chunks/nodes/{23.js-xMwn6OS_.js → 23.js-BRxy911D.js} +9 -8
- package/build/server/chunks/nodes/{24.js-Bf2yyWwh.js → 24.js-QS0KOwss.js} +4 -4
- package/build/server/chunks/nodes/{25.js-B4yvgFEW.js → 25.js-PQ5YJuMR.js} +10 -9
- package/build/server/chunks/nodes/{26.js-BgrkaBRi.js → 26.js-CVgNTrxq.js} +10 -9
- package/build/server/chunks/nodes/{27.js-CmaLV07r.js → 27.js-D362fjZ7.js} +8 -7
- package/build/server/chunks/nodes/{28.js-D5cRvkTM.js → 28.js-CquKiHnq.js} +8 -7
- package/build/server/chunks/nodes/{3.js-Dm2pmcK2.js → 3.js-_ZrsIscU.js} +8 -7
- package/build/server/chunks/nodes/{4.js-C4ho5OJp.js → 4.js-CMBAdl6x.js} +9 -8
- package/build/server/chunks/nodes/{5.js-y4HoD1YR.js → 5.js-DRAnyeo0.js} +7 -6
- package/build/server/chunks/nodes/{6.js-CjlWBc3h.js → 6.js-CWsHGKdF.js} +8 -7
- package/build/server/chunks/nodes/{7.js-Bu-qbDJ5.js → 7.js-BzkPQGE-.js} +8 -7
- package/build/server/chunks/nodes/{8.js-qv_Z5rCa.js → 8.js-DppreJ1j.js} +9 -8
- package/build/server/chunks/nodes/{9.js-txPQIe_t.js → 9.js-CWCKh6Lz.js} +2 -2
- package/dist/cli.js +389 -241
- package/dist/wh-vault.js +1 -1
- package/package.json +1 -1
- package/build/client/_app/immutable/assets/0.C7-9O7Er.css +0 -1
- package/build/client/_app/immutable/assets/0.C7-9O7Er.css.br +0 -0
- package/build/client/_app/immutable/assets/0.C7-9O7Er.css.gz +0 -0
- package/build/client/_app/immutable/chunks/60JlvdhQ.js.br +0 -0
- package/build/client/_app/immutable/chunks/60JlvdhQ.js.gz +0 -0
- package/build/client/_app/immutable/chunks/B-rYWQGG.js.br +0 -0
- package/build/client/_app/immutable/chunks/B-rYWQGG.js.gz +0 -0
- package/build/client/_app/immutable/chunks/B597Cbe1.js.br +0 -0
- package/build/client/_app/immutable/chunks/B597Cbe1.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BEKG1Stw.js.br +0 -0
- package/build/client/_app/immutable/chunks/BEKG1Stw.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BPAziDlG.js.br +0 -0
- package/build/client/_app/immutable/chunks/BPAziDlG.js.gz +0 -0
- package/build/client/_app/immutable/chunks/BiiAyXOY.js.br +0 -0
- package/build/client/_app/immutable/chunks/BiiAyXOY.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C69eHrL5.js.br +0 -0
- package/build/client/_app/immutable/chunks/C69eHrL5.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CC5Ts_xe.js.br +0 -0
- package/build/client/_app/immutable/chunks/CC5Ts_xe.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CPQbfMGI.js.br +0 -0
- package/build/client/_app/immutable/chunks/CPQbfMGI.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CSntU4ww.js.br +0 -0
- package/build/client/_app/immutable/chunks/CSntU4ww.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Cbm0yS9E.js.br +0 -0
- package/build/client/_app/immutable/chunks/Cbm0yS9E.js.gz +0 -0
- package/build/client/_app/immutable/chunks/ChjkQemt.js.br +0 -0
- package/build/client/_app/immutable/chunks/ChjkQemt.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CvZklcJq.js.br +0 -0
- package/build/client/_app/immutable/chunks/CvZklcJq.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DSAFUgJn.js.br +0 -0
- package/build/client/_app/immutable/chunks/DSAFUgJn.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DVeiiKip.js.br +0 -0
- package/build/client/_app/immutable/chunks/DVeiiKip.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DjCsArDj.js.br +0 -0
- package/build/client/_app/immutable/chunks/DjCsArDj.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DnBZO8Il.js.br +0 -0
- package/build/client/_app/immutable/chunks/DnBZO8Il.js.gz +0 -0
- package/build/client/_app/immutable/chunks/Gbvs-EZ4.js.br +0 -1
- package/build/client/_app/immutable/chunks/Gbvs-EZ4.js.gz +0 -0
- package/build/client/_app/immutable/chunks/IKqZ9EUq.js.br +0 -0
- package/build/client/_app/immutable/chunks/IKqZ9EUq.js.gz +0 -0
- package/build/client/_app/immutable/chunks/rZ2-WaWD.js.br +0 -0
- package/build/client/_app/immutable/chunks/rZ2-WaWD.js.gz +0 -0
- package/build/client/_app/immutable/chunks/wU4H_Xw3.js +0 -1
- package/build/client/_app/immutable/chunks/wU4H_Xw3.js.br +0 -0
- package/build/client/_app/immutable/chunks/wU4H_Xw3.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.ERrI8AQ5.js +0 -2
- package/build/client/_app/immutable/entry/app.ERrI8AQ5.js.br +0 -0
- package/build/client/_app/immutable/entry/app.ERrI8AQ5.js.gz +0 -0
- package/build/client/_app/immutable/entry/start.Dw33pepJ.js +0 -1
- package/build/client/_app/immutable/entry/start.Dw33pepJ.js.br +0 -0
- package/build/client/_app/immutable/entry/start.Dw33pepJ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/0.CPXJEdVC.js.br +0 -0
- package/build/client/_app/immutable/nodes/0.CPXJEdVC.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.BsHjzKoN.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.BsHjzKoN.js.gz +0 -0
- package/build/client/_app/immutable/nodes/10.JvkeSj5x.js.br +0 -0
- package/build/client/_app/immutable/nodes/10.JvkeSj5x.js.gz +0 -0
- package/build/client/_app/immutable/nodes/11.C9viE404.js.br +0 -0
- package/build/client/_app/immutable/nodes/11.C9viE404.js.gz +0 -0
- package/build/client/_app/immutable/nodes/12.BWVqITW1.js.br +0 -0
- package/build/client/_app/immutable/nodes/12.BWVqITW1.js.gz +0 -0
- package/build/client/_app/immutable/nodes/13.D0u53Jpp.js.br +0 -0
- package/build/client/_app/immutable/nodes/13.D0u53Jpp.js.gz +0 -0
- package/build/client/_app/immutable/nodes/14.CNClDl2g.js.br +0 -0
- package/build/client/_app/immutable/nodes/14.CNClDl2g.js.gz +0 -0
- package/build/client/_app/immutable/nodes/15.BJShjxpx.js.br +0 -0
- package/build/client/_app/immutable/nodes/15.BJShjxpx.js.gz +0 -0
- package/build/client/_app/immutable/nodes/16.Bb3PPsch.js.br +0 -0
- package/build/client/_app/immutable/nodes/16.Bb3PPsch.js.gz +0 -0
- package/build/client/_app/immutable/nodes/17.COjMgZvi.js.br +0 -0
- package/build/client/_app/immutable/nodes/17.COjMgZvi.js.gz +0 -0
- package/build/client/_app/immutable/nodes/19.BbeSGQyg.js.br +0 -0
- package/build/client/_app/immutable/nodes/19.BbeSGQyg.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.CBjl08IG.js +0 -25
- package/build/client/_app/immutable/nodes/2.CBjl08IG.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CBjl08IG.js.gz +0 -0
- package/build/client/_app/immutable/nodes/20.2D2FCLQq.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.2D2FCLQq.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.xQ_KUjAi.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.xQ_KUjAi.js.gz +0 -0
- package/build/client/_app/immutable/nodes/22.DuszjIrq.js.br +0 -0
- package/build/client/_app/immutable/nodes/22.DuszjIrq.js.gz +0 -0
- package/build/client/_app/immutable/nodes/23.CKoLeDhM.js.br +0 -0
- package/build/client/_app/immutable/nodes/23.CKoLeDhM.js.gz +0 -0
- package/build/client/_app/immutable/nodes/24.CH1byq7o.js.br +0 -0
- package/build/client/_app/immutable/nodes/24.CH1byq7o.js.gz +0 -0
- package/build/client/_app/immutable/nodes/25.BFrDgbR3.js +0 -12
- package/build/client/_app/immutable/nodes/25.BFrDgbR3.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.BFrDgbR3.js.gz +0 -0
- package/build/client/_app/immutable/nodes/26.CHB__H6C.js.br +0 -0
- package/build/client/_app/immutable/nodes/26.CHB__H6C.js.gz +0 -0
- package/build/client/_app/immutable/nodes/28.pI-7Vnsb.js.br +0 -0
- package/build/client/_app/immutable/nodes/28.pI-7Vnsb.js.gz +0 -0
- package/build/client/_app/immutable/nodes/3.6gLsJ5iP.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.6gLsJ5iP.js.gz +0 -0
- package/build/client/_app/immutable/nodes/4.uKPQRIJV.js.br +0 -0
- package/build/client/_app/immutable/nodes/4.uKPQRIJV.js.gz +0 -0
- package/build/client/_app/immutable/nodes/6.CmppqGHA.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.CmppqGHA.js.gz +0 -0
- package/build/client/_app/immutable/nodes/7.DDZOqRAy.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.DDZOqRAy.js.gz +0 -0
- package/build/client/_app/immutable/nodes/8.DH6CiiFf.js.br +0 -0
- package/build/client/_app/immutable/nodes/8.DH6CiiFf.js.gz +0 -0
- package/build/client/_app/immutable/nodes/9.jlOFlXh8.js.br +0 -0
- package/build/client/_app/immutable/nodes/9.jlOFlXh8.js.gz +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { readFile, readdir, stat, open, realpath, mkdir, writeFile, rename, rm, access, constants, lstat, chmod, appendFile } from 'node:fs/promises';
|
|
2
|
+
import os, { homedir, tmpdir } from 'node:os';
|
|
2
3
|
import path from 'node:path';
|
|
3
|
-
import { v as version, d as defaultKeychain } from './keychain.js-
|
|
4
|
+
import { v as version, d as defaultKeychain } from './keychain.js-CspIw1lK.js';
|
|
4
5
|
import { readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, openSync, closeSync, watch, statSync, fstatSync, readSync, accessSync, constants as constants$1, realpathSync, lstatSync, rmSync } from 'node:fs';
|
|
5
6
|
import { spawn, execFileSync } from 'node:child_process';
|
|
6
|
-
import os, { tmpdir } from 'node:os';
|
|
7
7
|
import { l as loopbackPreview, f as frameRefusal } from './preview.js-CbgkVvT_.js';
|
|
8
8
|
import { p as previewNoteOf, a as pageOf } from './previewnote.js-DB6VK2fp.js';
|
|
9
9
|
import { p as plainStatus, c as clean } from './plain.js-Dc97sYaJ.js';
|
|
@@ -15,9 +15,9 @@ import { s as shortTitle } from './format.js-D3lWEg6U.js';
|
|
|
15
15
|
import { r as runStep, c as checksLine } from './checks.js-DGdGhp1G.js';
|
|
16
16
|
import net, { createServer } from 'node:net';
|
|
17
17
|
import { D as DECIDED_MAX, d as detectHosted, p as portInHost, h as hostedAddress } from './decisionform.js-Ds5LU9Wh.js';
|
|
18
|
-
import { T as TERMINAL_PATH, a as TERMINAL_PROTOCOL, b as TERMINAL_CLOSE, S as SETUP_TERMINAL_PATH, c as TOKEN_PROTOCOL_PREFIX } from './terminal.js-
|
|
18
|
+
import { T as TERMINAL_PATH, a as TERMINAL_PROTOCOL, b as TERMINAL_CLOSE, S as SETUP_TERMINAL_PATH, c as TOKEN_PROTOCOL_PREFIX } from './terminal.js-s8yEF1TY.js';
|
|
19
19
|
import WebSocket, { WebSocketServer } from 'ws';
|
|
20
|
-
import { timingSafeEqual, randomBytes, createHash, createHmac } from 'node:crypto';
|
|
20
|
+
import { timingSafeEqual, randomBytes, randomUUID, createHash, createHmac } from 'node:crypto';
|
|
21
21
|
import { r as roundId, t as testLine } from './buildlog.js-BCKtSKOt.js';
|
|
22
22
|
import { a as alertsFor, r as raise, s as sessionAlert, d as digest, A as ALERT_KINDS } from './bell.js-DuW71LLn.js';
|
|
23
23
|
import { C as CHOICES, N as NOTE_MAX, b as closable, p as picksLine, d as closeText, e as answerText, D as DECIDED_LABEL, f as choiceLabel, g as awaitsAnswer, o as optionsFor, h as holdCardId, q as questionLine, a as answerOf } from './inbox.js-CnikIOgr.js';
|
|
@@ -31,6 +31,7 @@ import { p as projectTabHref, a as parseSlotKey } from './keys.js-iHygUPeb.js';
|
|
|
31
31
|
import { v as validPullRequestQuery } from './pullrequests.js-CCzk2sqm.js';
|
|
32
32
|
import { createServer as createServer$1 } from 'node:http';
|
|
33
33
|
import { n as needsYou } from './harbour.js-D3N7u1_p.js';
|
|
34
|
+
import { p as parseHarness, H as HARNESS_NAMES } from './harness.js-DPojOlFJ.js';
|
|
34
35
|
import './urls.js-CM6aklCF.js';
|
|
35
36
|
import './previewhelper.js-D_I_aa96.js';
|
|
36
37
|
|
|
@@ -215,8 +216,8 @@ const CREW_STATES = [
|
|
|
215
216
|
"failed",
|
|
216
217
|
"unknown"
|
|
217
218
|
];
|
|
218
|
-
function parseJson$1(
|
|
219
|
-
const trimmed =
|
|
219
|
+
function parseJson$1(text2, what) {
|
|
220
|
+
const trimmed = text2.trim();
|
|
220
221
|
if (!trimmed) throw new ContractError(`${what} printed nothing`);
|
|
221
222
|
try {
|
|
222
223
|
return JSON.parse(trimmed);
|
|
@@ -298,8 +299,8 @@ function parseTask(v) {
|
|
|
298
299
|
backlog: parseBacklogRecord(v.backlog)
|
|
299
300
|
};
|
|
300
301
|
}
|
|
301
|
-
function parseFleetSnapshot(
|
|
302
|
-
const v = parseJson$1(
|
|
302
|
+
function parseFleetSnapshot(text2) {
|
|
303
|
+
const v = parseJson$1(text2, "fm-fleet-snapshot.sh --json");
|
|
303
304
|
if (!isObj$2(v)) throw new ContractError("fleet snapshot is not a JSON object");
|
|
304
305
|
if (v.schema !== FLEET_SNAPSHOT_SCHEMA) {
|
|
305
306
|
throw new ContractError(
|
|
@@ -324,7 +325,7 @@ function parseFleetSnapshot(text) {
|
|
|
324
325
|
secondMates: parseSecondMates(v.secondmate_current)
|
|
325
326
|
};
|
|
326
327
|
}
|
|
327
|
-
function list(v, f) {
|
|
328
|
+
function list$1(v, f) {
|
|
328
329
|
return Array.isArray(v) ? v.filter(isObj$2).map(f).filter((x) => x !== null) : [];
|
|
329
330
|
}
|
|
330
331
|
function withId(o, f) {
|
|
@@ -357,7 +358,7 @@ function parseSecondMate(v) {
|
|
|
357
358
|
observedAt: nonBlank(freshness.observed_at),
|
|
358
359
|
ageSeconds: num$2(freshness.age_seconds)
|
|
359
360
|
},
|
|
360
|
-
active: list(
|
|
361
|
+
active: list$1(
|
|
361
362
|
v.active_children,
|
|
362
363
|
(c) => withId(c, (cid) => ({
|
|
363
364
|
id: cid,
|
|
@@ -368,7 +369,7 @@ function parseSecondMate(v) {
|
|
|
368
369
|
doing: nonBlank(c.doing)
|
|
369
370
|
}))
|
|
370
371
|
),
|
|
371
|
-
decisions: list(
|
|
372
|
+
decisions: list$1(
|
|
372
373
|
v.decisions_open,
|
|
373
374
|
(d) => withId(d, (did) => ({
|
|
374
375
|
id: did,
|
|
@@ -380,7 +381,7 @@ function parseSecondMate(v) {
|
|
|
380
381
|
source: nonBlank(d.source)
|
|
381
382
|
}))
|
|
382
383
|
),
|
|
383
|
-
holds: list(
|
|
384
|
+
holds: list$1(
|
|
384
385
|
v.holds,
|
|
385
386
|
(h) => withId(h, (hid) => ({
|
|
386
387
|
id: hid,
|
|
@@ -390,7 +391,7 @@ function parseSecondMate(v) {
|
|
|
390
391
|
source: nonBlank(h.source)
|
|
391
392
|
}))
|
|
392
393
|
),
|
|
393
|
-
queued: list(
|
|
394
|
+
queued: list$1(
|
|
394
395
|
v.queued,
|
|
395
396
|
(q) => withId(q, (qid) => ({
|
|
396
397
|
id: qid,
|
|
@@ -406,7 +407,7 @@ function parseSecondMate(v) {
|
|
|
406
407
|
since: nonBlank(q.since)
|
|
407
408
|
}))
|
|
408
409
|
),
|
|
409
|
-
landed: list(
|
|
410
|
+
landed: list$1(
|
|
410
411
|
v.landed,
|
|
411
412
|
(l) => withId(l, (lid) => {
|
|
412
413
|
const completion = obj(l.completion);
|
|
@@ -420,7 +421,7 @@ function parseSecondMate(v) {
|
|
|
420
421
|
};
|
|
421
422
|
})
|
|
422
423
|
),
|
|
423
|
-
endpoints: list(
|
|
424
|
+
endpoints: list$1(
|
|
424
425
|
v.endpoints,
|
|
425
426
|
(e) => withId(e, (eid) => {
|
|
426
427
|
const ep = obj(e.endpoint);
|
|
@@ -440,15 +441,15 @@ function parseSecondMate(v) {
|
|
|
440
441
|
}
|
|
441
442
|
function parseSecondMates(v) {
|
|
442
443
|
if (!isObj$2(v)) return null;
|
|
443
|
-
const records2 = list(v.records, parseSecondMate);
|
|
444
|
+
const records2 = list$1(v.records, parseSecondMate);
|
|
444
445
|
return {
|
|
445
446
|
records: records2,
|
|
446
447
|
total: num$2(v.total) ?? records2.length,
|
|
447
448
|
truncated: num$2(v.truncated) ?? 0
|
|
448
449
|
};
|
|
449
450
|
}
|
|
450
|
-
function parsePrimaryReady(
|
|
451
|
-
const v = parseJson$1(
|
|
451
|
+
function parsePrimaryReady(text2) {
|
|
452
|
+
const v = parseJson$1(text2, "fm-inbox.sh ready");
|
|
452
453
|
if (!isObj$2(v)) throw new ContractError("readiness is not a JSON object");
|
|
453
454
|
if (v.schema !== PRIMARY_READY_SCHEMA) {
|
|
454
455
|
throw new ContractError(
|
|
@@ -472,8 +473,8 @@ function parsePrimaryReady(text) {
|
|
|
472
473
|
canReceive: recv === true ? true : recv === false ? false : "unknown"
|
|
473
474
|
};
|
|
474
475
|
}
|
|
475
|
-
function parseInboxNote(
|
|
476
|
-
const v = parseJson$1(
|
|
476
|
+
function parseInboxNote(text2) {
|
|
477
|
+
const v = parseJson$1(text2, "fm-inbox.sh note --json");
|
|
477
478
|
if (!isObj$2(v)) throw new ContractError("note result is not a JSON object");
|
|
478
479
|
if (v.schema !== INBOX_NOTE_SCHEMA) {
|
|
479
480
|
throw new ContractError(
|
|
@@ -517,8 +518,8 @@ function parseReceipt(v, acknowledged) {
|
|
|
517
518
|
reply: parseReply(v.reply)
|
|
518
519
|
};
|
|
519
520
|
}
|
|
520
|
-
function parseInboxReceipts(
|
|
521
|
-
const v = parseJson$1(
|
|
521
|
+
function parseInboxReceipts(text2) {
|
|
522
|
+
const v = parseJson$1(text2, "fm-inbox.sh receipts");
|
|
522
523
|
if (!isObj$2(v)) throw new ContractError("receipts are not a JSON object");
|
|
523
524
|
if (v.schema !== INBOX_RECEIPTS_SCHEMA) {
|
|
524
525
|
throw new ContractError(
|
|
@@ -541,8 +542,8 @@ function parseInboxReceipts(text) {
|
|
|
541
542
|
}
|
|
542
543
|
const ANSI$1 = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b[@-_]/g;
|
|
543
544
|
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f]/g;
|
|
544
|
-
function parsePeekOutput(
|
|
545
|
-
const lines =
|
|
545
|
+
function parsePeekOutput(text2, maxLines) {
|
|
546
|
+
const lines = text2.replace(/\r\n?/g, "\n").replace(ANSI$1, "").replace(CONTROL, "").split("\n");
|
|
546
547
|
while (lines.length && lines[lines.length - 1].trim() === "") lines.pop();
|
|
547
548
|
return lines.slice(-maxLines);
|
|
548
549
|
}
|
|
@@ -686,13 +687,13 @@ async function checkScript(firstmateDir, s) {
|
|
|
686
687
|
} catch {
|
|
687
688
|
return { ...base, ok: false, problem: `${s.name} is not executable` };
|
|
688
689
|
}
|
|
689
|
-
let
|
|
690
|
+
let text2;
|
|
690
691
|
try {
|
|
691
|
-
|
|
692
|
+
text2 = await readHead$1(file);
|
|
692
693
|
} catch (e) {
|
|
693
694
|
return { ...base, ok: false, problem: `${s.name} could not be read: ${e.message}` };
|
|
694
695
|
}
|
|
695
|
-
const missing = s.markers.filter((m) => !
|
|
696
|
+
const missing = s.markers.filter((m) => !text2.includes(m));
|
|
696
697
|
if (missing.length) {
|
|
697
698
|
return {
|
|
698
699
|
...base,
|
|
@@ -785,7 +786,7 @@ const SAFE_REL = /^(?![./])[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*$/;
|
|
|
785
786
|
const REMOTE_PEEK_MAX_LINES = 100;
|
|
786
787
|
const REMOTE_UNREACHABLE = 255;
|
|
787
788
|
const PEEK_DEFAULT_LINES = 40;
|
|
788
|
-
const REQUEST_ID = /^(?!\.)[A-Za-z0-9._:-]{1,128}$/;
|
|
789
|
+
const REQUEST_ID$1 = /^(?!\.)[A-Za-z0-9._:-]{1,128}$/;
|
|
789
790
|
const NOTE_MAX_BYTES = 16 * 1024;
|
|
790
791
|
const NOTE_EXIT_UNANNOUNCED = 3;
|
|
791
792
|
const SNAPSHOT_MAX_BYTES = 8 * 1024 * 1024;
|
|
@@ -957,7 +958,7 @@ function createScriptAdapter(install, opts = {}) {
|
|
|
957
958
|
},
|
|
958
959
|
mateNote: async (mate, requestId, body) => {
|
|
959
960
|
if (!TASK_ID$1.test(mate.id)) return invalid("fm-inbox.sh", "invalid second mate id");
|
|
960
|
-
if (!REQUEST_ID.test(requestId)) return invalid("fm-inbox.sh", "invalid request id");
|
|
961
|
+
if (!REQUEST_ID$1.test(requestId)) return invalid("fm-inbox.sh", "invalid request id");
|
|
961
962
|
if (!body.trim()) return invalid("fm-inbox.sh", "the message is empty");
|
|
962
963
|
if (Buffer.byteLength(body) > NOTE_MAX_BYTES) {
|
|
963
964
|
return invalid("fm-inbox.sh", `the message is longer than ${NOTE_MAX_BYTES} bytes`);
|
|
@@ -987,7 +988,7 @@ function createScriptAdapter(install, opts = {}) {
|
|
|
987
988
|
observedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
988
989
|
error: { kind: "invalid-argument", script: "fm-inbox.sh", message: message2 }
|
|
989
990
|
});
|
|
990
|
-
if (!REQUEST_ID.test(requestId)) return invalid2("invalid request id");
|
|
991
|
+
if (!REQUEST_ID$1.test(requestId)) return invalid2("invalid request id");
|
|
991
992
|
if (!body.trim()) return invalid2("the message is empty");
|
|
992
993
|
if (Buffer.byteLength(body) > NOTE_MAX_BYTES) {
|
|
993
994
|
return invalid2(`the message is longer than ${NOTE_MAX_BYTES} bytes`);
|
|
@@ -1134,7 +1135,9 @@ const DROP = /* @__PURE__ */ new Set([
|
|
|
1134
1135
|
"CLAUDE_PID",
|
|
1135
1136
|
"CLAUDE_SESSION_ID",
|
|
1136
1137
|
"CLAUDE_PROJECT_DIR",
|
|
1137
|
-
"CLAUDE_ENV_FILE"
|
|
1138
|
+
"CLAUDE_ENV_FILE",
|
|
1139
|
+
"CODEX_THREAD_ID",
|
|
1140
|
+
"CODEX_INTERNAL_ORIGINATOR_OVERRIDE"
|
|
1138
1141
|
]);
|
|
1139
1142
|
function sessionEnv(env) {
|
|
1140
1143
|
const out = {};
|
|
@@ -1144,14 +1147,189 @@ function sessionEnv(env) {
|
|
|
1144
1147
|
}
|
|
1145
1148
|
return out;
|
|
1146
1149
|
}
|
|
1150
|
+
const FIRSTMATE_TMUX = "wh-firstmate";
|
|
1151
|
+
const TMUX_TIMEOUT_MS$1 = 1e4;
|
|
1152
|
+
const TMUX_FORMAT = "#{socket_path},#{pid},#{session_id}";
|
|
1153
|
+
const BUFFER = "wh-firstmate-input";
|
|
1154
|
+
const PASTE_MAX_INPUT_BYTES = 65 * 1024;
|
|
1155
|
+
const SESSION_OPTIONS = [
|
|
1156
|
+
["mouse", "on"],
|
|
1157
|
+
["status", "off"],
|
|
1158
|
+
["history-limit", "20000"]
|
|
1159
|
+
];
|
|
1160
|
+
const TMUX_KEYS = {
|
|
1161
|
+
Enter: "Enter",
|
|
1162
|
+
Escape: "Escape",
|
|
1163
|
+
Up: "Up",
|
|
1164
|
+
Down: "Down",
|
|
1165
|
+
"0": "0",
|
|
1166
|
+
"1": "1",
|
|
1167
|
+
"2": "2",
|
|
1168
|
+
"3": "3",
|
|
1169
|
+
"4": "4",
|
|
1170
|
+
"5": "5",
|
|
1171
|
+
"6": "6",
|
|
1172
|
+
"7": "7",
|
|
1173
|
+
"8": "8",
|
|
1174
|
+
"9": "9"
|
|
1175
|
+
};
|
|
1176
|
+
function launchArgv(spec) {
|
|
1177
|
+
return [
|
|
1178
|
+
"new-session",
|
|
1179
|
+
"-d",
|
|
1180
|
+
"-s",
|
|
1181
|
+
FIRSTMATE_TMUX,
|
|
1182
|
+
"-x",
|
|
1183
|
+
"160",
|
|
1184
|
+
"-y",
|
|
1185
|
+
"48",
|
|
1186
|
+
"-c",
|
|
1187
|
+
spec.cwd,
|
|
1188
|
+
...Object.entries(spec.env).flatMap(([k, v]) => ["-e", `${k}=${v}`]),
|
|
1189
|
+
"--",
|
|
1190
|
+
...spec.argv
|
|
1191
|
+
];
|
|
1192
|
+
}
|
|
1193
|
+
const attachHint = (socket) => shellLine(["tmux", "-L", socket, "attach", "-t", FIRSTMATE_TMUX]);
|
|
1194
|
+
class TmuxBackend {
|
|
1195
|
+
label = "tmux";
|
|
1196
|
+
socket;
|
|
1197
|
+
env;
|
|
1198
|
+
find;
|
|
1199
|
+
run;
|
|
1200
|
+
constructor(opts) {
|
|
1201
|
+
this.socket = opts.socket || DEFAULT_TMUX_SOCKET;
|
|
1202
|
+
this.env = opts.env;
|
|
1203
|
+
this.find = opts.find;
|
|
1204
|
+
this.run = opts.run ?? runBounded;
|
|
1205
|
+
}
|
|
1206
|
+
unavailable() {
|
|
1207
|
+
if (!TMUX_SOCKET.test(this.socket)) {
|
|
1208
|
+
return `The tmux socket name ${JSON.stringify(this.socket)} is not valid; use letters, digits, '.', '_' or '-'.`;
|
|
1209
|
+
}
|
|
1210
|
+
if (!this.find("tmux")) {
|
|
1211
|
+
return "tmux is not installed or not on PATH. Install tmux (for example `brew install tmux`) and restart Wheelhouse.";
|
|
1212
|
+
}
|
|
1213
|
+
return null;
|
|
1214
|
+
}
|
|
1215
|
+
/** Run tmux on Wheelhouse's own server only; nothing reaches tmux any other way. */
|
|
1216
|
+
tmux(args, extra = {}) {
|
|
1217
|
+
const tmux = this.find("tmux");
|
|
1218
|
+
if (!tmux) return Promise.reject(new Error("tmux is missing"));
|
|
1219
|
+
return this.run(tmux, ["-L", this.socket, ...args], {
|
|
1220
|
+
env: this.env,
|
|
1221
|
+
timeoutMs: TMUX_TIMEOUT_MS$1,
|
|
1222
|
+
maxOutputBytes: 256 * 1024,
|
|
1223
|
+
...extra
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
async running() {
|
|
1227
|
+
if (!this.find("tmux") || !TMUX_SOCKET.test(this.socket)) return null;
|
|
1228
|
+
const r = await this.tmux(["list-sessions", "-F", "#{session_name}"]);
|
|
1229
|
+
if (r.ok) return r.stdout.split("\n").includes(FIRSTMATE_TMUX);
|
|
1230
|
+
if (r.kind === "exit" && NO_SERVER.test(r.stderr)) return false;
|
|
1231
|
+
return null;
|
|
1232
|
+
}
|
|
1233
|
+
async start(spec) {
|
|
1234
|
+
const r = await this.tmux(launchArgv(spec), { cwd: spec.cwd });
|
|
1235
|
+
if (!r.ok) {
|
|
1236
|
+
return {
|
|
1237
|
+
ok: false,
|
|
1238
|
+
error: `tmux could not start Firstmate: ${r.stderr.trim() || r.message}`
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
for (const [name2, value] of SESSION_OPTIONS) {
|
|
1242
|
+
await this.tmux(["set-option", "-t", `=${FIRSTMATE_TMUX}:`, name2, value]);
|
|
1243
|
+
}
|
|
1244
|
+
return { ok: true };
|
|
1245
|
+
}
|
|
1246
|
+
async variable(name2) {
|
|
1247
|
+
const r = await this.tmux(["show-environment", "-t", FIRSTMATE_TMUX, name2]);
|
|
1248
|
+
if (r.ok) return r.stdout.trim().replace(new RegExp(`^${name2}=`), "");
|
|
1249
|
+
return /unknown variable/.test(r.stderr) ? "" : null;
|
|
1250
|
+
}
|
|
1251
|
+
async screen() {
|
|
1252
|
+
const r = await this.tmux(["capture-pane", "-p", "-t", `=${FIRSTMATE_TMUX}:`]);
|
|
1253
|
+
return r.ok ? r.stdout : null;
|
|
1254
|
+
}
|
|
1255
|
+
async paste(text2) {
|
|
1256
|
+
const load2 = await this.tmux(["load-buffer", "-b", BUFFER, "-"], {
|
|
1257
|
+
input: text2,
|
|
1258
|
+
maxInputBytes: PASTE_MAX_INPUT_BYTES
|
|
1259
|
+
});
|
|
1260
|
+
if (!load2.ok) {
|
|
1261
|
+
return {
|
|
1262
|
+
ok: false,
|
|
1263
|
+
error: `tmux could not take the message: ${load2.stderr.trim() || load2.message}`
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
const paste = await this.tmux([
|
|
1267
|
+
"paste-buffer",
|
|
1268
|
+
"-d",
|
|
1269
|
+
"-p",
|
|
1270
|
+
"-b",
|
|
1271
|
+
BUFFER,
|
|
1272
|
+
"-t",
|
|
1273
|
+
`=${FIRSTMATE_TMUX}:`
|
|
1274
|
+
]);
|
|
1275
|
+
if (!paste.ok) {
|
|
1276
|
+
return {
|
|
1277
|
+
ok: false,
|
|
1278
|
+
error: `tmux could not paste the message: ${paste.stderr.trim() || paste.message}`
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
return { ok: true };
|
|
1282
|
+
}
|
|
1283
|
+
async key(key) {
|
|
1284
|
+
const r = await this.tmux(["send-keys", "-t", `=${FIRSTMATE_TMUX}:`, TMUX_KEYS[key]]);
|
|
1285
|
+
if (!r.ok) {
|
|
1286
|
+
return { ok: false, error: `tmux could not send a key: ${r.stderr.trim() || r.message}` };
|
|
1287
|
+
}
|
|
1288
|
+
return { ok: true };
|
|
1289
|
+
}
|
|
1290
|
+
attach() {
|
|
1291
|
+
return {
|
|
1292
|
+
argv: [
|
|
1293
|
+
this.find("tmux"),
|
|
1294
|
+
"-L",
|
|
1295
|
+
this.socket,
|
|
1296
|
+
"attach-session",
|
|
1297
|
+
"-t",
|
|
1298
|
+
`=${FIRSTMATE_TMUX}`
|
|
1299
|
+
],
|
|
1300
|
+
env: { ...this.env, TERM: "xterm-256color" }
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
attachHint() {
|
|
1304
|
+
return attachHint(this.socket);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
function firstmateTmux(opts) {
|
|
1308
|
+
const socket = opts.tmuxSocket || DEFAULT_TMUX_SOCKET;
|
|
1309
|
+
const env = sessionEnv(opts.env ?? process.env);
|
|
1310
|
+
const find = opts.find ?? ((name2) => which(name2, env.PATH));
|
|
1311
|
+
const run = opts.run ?? runBounded;
|
|
1312
|
+
return async () => {
|
|
1313
|
+
const tmux = find("tmux");
|
|
1314
|
+
if (!tmux || !TMUX_SOCKET.test(socket)) return null;
|
|
1315
|
+
const r = await run(
|
|
1316
|
+
tmux,
|
|
1317
|
+
["-L", socket, "display-message", "-p", "-t", `=${FIRSTMATE_TMUX}:`, TMUX_FORMAT],
|
|
1318
|
+
{ env, timeoutMs: TMUX_TIMEOUT_MS$1, maxOutputBytes: 64 * 1024 }
|
|
1319
|
+
);
|
|
1320
|
+
if (!r.ok) return null;
|
|
1321
|
+
const value = r.stdout.trim().replace(/,\$(\d+)$/, ",$1");
|
|
1322
|
+
return /^\/.*,\d+,\d+$/.test(value) ? value : null;
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1147
1325
|
const CREW_FALLBACK = DEFAULT_SERVER;
|
|
1148
|
-
const TMUX_TIMEOUT_MS
|
|
1326
|
+
const TMUX_TIMEOUT_MS = 5e3;
|
|
1149
1327
|
const META_MAX_BYTES$1 = 64 * 1024;
|
|
1150
1328
|
const LIST_MAX_BYTES$1 = 1024 * 1024;
|
|
1151
1329
|
const WINDOW_FORMAT = "#{socket_path},#{pid},#{session_id} #{window_id} #{window_index} #{session_name} #{window_name}";
|
|
1152
|
-
function metaGet(
|
|
1330
|
+
function metaGet(text2, key) {
|
|
1153
1331
|
let value = "";
|
|
1154
|
-
for (const line of
|
|
1332
|
+
for (const line of text2.split("\n"))
|
|
1155
1333
|
if (line.startsWith(`${key}=`)) value = line.slice(key.length + 1);
|
|
1156
1334
|
return value;
|
|
1157
1335
|
}
|
|
@@ -1228,7 +1406,7 @@ function crewTmux(opts) {
|
|
|
1228
1406
|
servers().map(async (server) => {
|
|
1229
1407
|
const r = await run(tmux, [...server, "list-windows", "-a", "-F", WINDOW_FORMAT], {
|
|
1230
1408
|
env,
|
|
1231
|
-
timeoutMs: TMUX_TIMEOUT_MS
|
|
1409
|
+
timeoutMs: TMUX_TIMEOUT_MS,
|
|
1232
1410
|
maxOutputBytes: LIST_MAX_BYTES$1
|
|
1233
1411
|
});
|
|
1234
1412
|
return r.ok ? parseWindows(r.stdout) : [];
|
|
@@ -1318,8 +1496,8 @@ const MAX_STAGES = 24;
|
|
|
1318
1496
|
const MAX_CHECKS = 16;
|
|
1319
1497
|
const MAX_COND_DEPTH = 8;
|
|
1320
1498
|
const UNITS = { s: 1e3, m: 6e4, h: 36e5, d: 864e5 };
|
|
1321
|
-
function durationMs(
|
|
1322
|
-
const m = DURATION.exec(
|
|
1499
|
+
function durationMs(text2) {
|
|
1500
|
+
const m = DURATION.exec(text2);
|
|
1323
1501
|
return m ? Number(m[1]) * UNITS[m[2]] : null;
|
|
1324
1502
|
}
|
|
1325
1503
|
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -1449,8 +1627,8 @@ function note(p, where, v) {
|
|
|
1449
1627
|
}
|
|
1450
1628
|
fields(p, where, v, ["when", "text"]);
|
|
1451
1629
|
const when = cond(p, `${where}.when`, v.when);
|
|
1452
|
-
const
|
|
1453
|
-
return when !== void 0 &&
|
|
1630
|
+
const text2 = str$4(p, `${where}.text`, v.text, { required: true, max: 1e3 });
|
|
1631
|
+
return when !== void 0 && text2 !== void 0 ? { when, text: text2 } : void 0;
|
|
1454
1632
|
}
|
|
1455
1633
|
const COMMIT_VALUES = ["merge.commit", "pr.head"];
|
|
1456
1634
|
function check(p, where, v, opts) {
|
|
@@ -1839,11 +2017,11 @@ function validatePassage(doc, opts) {
|
|
|
1839
2017
|
}
|
|
1840
2018
|
return p.list.length ? { ok: false, errors: p.list } : { ok: true, value: out };
|
|
1841
2019
|
}
|
|
1842
|
-
function parsePassage(
|
|
1843
|
-
if (Buffer.byteLength(
|
|
2020
|
+
function parsePassage(text2, opts) {
|
|
2021
|
+
if (Buffer.byteLength(text2) > MAX_FILE_BYTES$1) {
|
|
1844
2022
|
return { ok: false, errors: [`the file is larger than ${MAX_FILE_BYTES$1 / 1024} KiB`] };
|
|
1845
2023
|
}
|
|
1846
|
-
const doc = parseDocument(
|
|
2024
|
+
const doc = parseDocument(text2, { prettyErrors: false, uniqueKeys: true });
|
|
1847
2025
|
if (doc.errors.length) {
|
|
1848
2026
|
return {
|
|
1849
2027
|
ok: false,
|
|
@@ -1951,8 +2129,8 @@ stages:
|
|
|
1951
2129
|
reached_when: backlog.done
|
|
1952
2130
|
evidence: [landed]
|
|
1953
2131
|
`;
|
|
1954
|
-
function load(
|
|
1955
|
-
const r = parsePassage(
|
|
2132
|
+
function load(text2) {
|
|
2133
|
+
const r = parsePassage(text2, { kind: "base" });
|
|
1956
2134
|
if (!r.ok) throw new Error(`built-in passage is invalid: ${r.errors.join("; ")}`);
|
|
1957
2135
|
return r.value;
|
|
1958
2136
|
}
|
|
@@ -2020,7 +2198,7 @@ function fromBase(file) {
|
|
|
2020
2198
|
liveStep: file.headline?.live ?? null
|
|
2021
2199
|
};
|
|
2022
2200
|
}
|
|
2023
|
-
const give = (
|
|
2201
|
+
const give = (text2) => ({ text: text2, ms: durationMs(text2) ?? 0 });
|
|
2024
2202
|
const CONDITION_FIELDS = ["reached_when", "skip_when", "skip_note", "failed_when"];
|
|
2025
2203
|
function applyLayer(base, layer) {
|
|
2026
2204
|
const errors = [];
|
|
@@ -2569,8 +2747,8 @@ async function gitContains(spec, ctx, deps) {
|
|
|
2569
2747
|
}
|
|
2570
2748
|
const COMMAND_OUTPUT_BYTES = 16 * 1024;
|
|
2571
2749
|
const DEFAULT_COMMAND_TIMEOUT = "5m";
|
|
2572
|
-
function plainOutput(
|
|
2573
|
-
return
|
|
2750
|
+
function plainOutput(text2) {
|
|
2751
|
+
return text2.replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, "").replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, "").split("\n").map((line) => {
|
|
2574
2752
|
const parts = line.replace(/\r$/, "").split("\r");
|
|
2575
2753
|
return parts[parts.length - 1];
|
|
2576
2754
|
}).join("\n").replace(/[\x00-\x08\x0b-\x1f\x7f]/g, "");
|
|
@@ -2951,9 +3129,9 @@ function trackOf(kind) {
|
|
|
2951
3129
|
}
|
|
2952
3130
|
const isYoloOn = (yolo) => (yolo ?? "").toLowerCase() === "on";
|
|
2953
3131
|
const isoSeconds = (ts) => new Date(ts * 1e3).toISOString();
|
|
2954
|
-
function parseProjectsRegistry(
|
|
3132
|
+
function parseProjectsRegistry(text2) {
|
|
2955
3133
|
const out = [];
|
|
2956
|
-
for (const line of
|
|
3134
|
+
for (const line of text2.split("\n")) {
|
|
2957
3135
|
const m = /^-\s+([A-Za-z0-9._-]+)(?:\s+\[([^\]]*)\])?(?:\s+-\s+(.*))?$/.exec(line.trim());
|
|
2958
3136
|
if (!m) continue;
|
|
2959
3137
|
const description = (m[3] ?? "").replace(/\s*\(added [^)]*\)\s*$/, "").trim();
|
|
@@ -2990,9 +3168,9 @@ function latestStatus(task2, ledger, nowSeconds) {
|
|
|
2990
3168
|
function historySummary(task2, ledger, nowSeconds) {
|
|
2991
3169
|
const last = latestStatus(task2, ledger, nowSeconds);
|
|
2992
3170
|
if (!last) return null;
|
|
2993
|
-
const
|
|
3171
|
+
const text2 = plainStatus(last.state, last.text);
|
|
2994
3172
|
return {
|
|
2995
|
-
text: last.ageSeconds === null ?
|
|
3173
|
+
text: last.ageSeconds === null ? text2 : `${text2} (${ageText(last.ageSeconds)})`,
|
|
2996
3174
|
raw: last.text.trim()
|
|
2997
3175
|
};
|
|
2998
3176
|
}
|
|
@@ -3419,11 +3597,11 @@ const unquote = (s) => {
|
|
|
3419
3597
|
const TABLE = /^([\w-]+)\[\d+\]\{([^}]*)\}:\s*$/;
|
|
3420
3598
|
const LIST = /^([\w-]+)\[\d+\]:\s*(.*)$/;
|
|
3421
3599
|
const FIELD = /^([\w-]+):\s*(.*)$/;
|
|
3422
|
-
function parseToon(
|
|
3600
|
+
function parseToon(text2) {
|
|
3423
3601
|
const root = {};
|
|
3424
3602
|
const stack = [{ indent: -1, block: root }];
|
|
3425
3603
|
let table = null;
|
|
3426
|
-
for (const raw of
|
|
3604
|
+
for (const raw of text2.replace(/\r\n?/g, "\n").split("\n")) {
|
|
3427
3605
|
if (!raw.trim()) continue;
|
|
3428
3606
|
const indent = raw.length - raw.trimStart().length;
|
|
3429
3607
|
const line = raw.trim();
|
|
@@ -3475,8 +3653,8 @@ const num$1 = (s) => {
|
|
|
3475
3653
|
const n = Number(s);
|
|
3476
3654
|
return Number.isFinite(n) ? n : 0;
|
|
3477
3655
|
};
|
|
3478
|
-
function parseRunStatus(
|
|
3479
|
-
const doc = parseToon(
|
|
3656
|
+
function parseRunStatus(text2) {
|
|
3657
|
+
const doc = parseToon(text2);
|
|
3480
3658
|
const run = [doc.run, doc.other_branch_run, doc.current_run].find(isBlock) ?? doc;
|
|
3481
3659
|
const id = scalar(run, "id");
|
|
3482
3660
|
const status2 = scalar(run, "status");
|
|
@@ -3789,8 +3967,8 @@ class EvidenceReader {
|
|
|
3789
3967
|
if (!runId || !RUN_ID$2.test(runId)) return Promise.resolve(null);
|
|
3790
3968
|
const dir = this.logsDir ? path.join(this.logsDir, runId) : null;
|
|
3791
3969
|
return this.pipelines.get(`${runId} ${worktree ?? ""}`, async () => {
|
|
3792
|
-
const
|
|
3793
|
-
const run =
|
|
3970
|
+
const text2 = worktree && path.isAbsolute(worktree) && this.runStatus ? await this.runStatus(runId, worktree).catch(() => null) : null;
|
|
3971
|
+
const run = text2 ? parseRunStatus(text2) : null;
|
|
3794
3972
|
const fromLogs = dir ? await readPipeline(dir).catch(() => null) : null;
|
|
3795
3973
|
if (!run || run.id !== runId || !run.steps.length) return fromLogs;
|
|
3796
3974
|
const fixes = /* @__PURE__ */ new Map();
|
|
@@ -4174,8 +4352,8 @@ async function readRunStatus(runId, worktree, env) {
|
|
|
4174
4352
|
});
|
|
4175
4353
|
return r.ok ? r.stdout : null;
|
|
4176
4354
|
}
|
|
4177
|
-
function diffBody(
|
|
4178
|
-
const all =
|
|
4355
|
+
function diffBody(text2) {
|
|
4356
|
+
const all = text2.replace(/\r\n?/g, "\n").split("\n");
|
|
4179
4357
|
if (all.at(-1) === "") all.pop();
|
|
4180
4358
|
const first = all.findIndex((l) => l.startsWith("@@"));
|
|
4181
4359
|
if (first < 0) return { lines: [], binary: all.some((l) => /^Binary files .* differ$/.test(l)) };
|
|
@@ -4340,11 +4518,11 @@ function parsePrFeedback(answer) {
|
|
|
4340
4518
|
if (a?.__typename === "Bot" || login?.endsWith("[bot]")) return false;
|
|
4341
4519
|
return !login || login !== author || author === viewer;
|
|
4342
4520
|
};
|
|
4343
|
-
const
|
|
4521
|
+
const text2 = (v) => (str2(v) ?? "").trim().slice(0, FEEDBACK_TEXT_MAX);
|
|
4344
4522
|
const items = [];
|
|
4345
4523
|
for (const r of nodes(p?.reviews)) {
|
|
4346
4524
|
const at = seconds(r.submittedAt);
|
|
4347
|
-
const body =
|
|
4525
|
+
const body = text2(r.body);
|
|
4348
4526
|
const asks = r.state === "CHANGES_REQUESTED" || r.state === "COMMENTED" && body;
|
|
4349
4527
|
if (at === null || !asks || !person(r.author) || !str2(r.id)) continue;
|
|
4350
4528
|
items.push({
|
|
@@ -4370,7 +4548,7 @@ function parsePrFeedback(answer) {
|
|
|
4370
4548
|
kind: "thread",
|
|
4371
4549
|
state: null,
|
|
4372
4550
|
author: str2(c.author?.login),
|
|
4373
|
-
text:
|
|
4551
|
+
text: text2(c.body),
|
|
4374
4552
|
at,
|
|
4375
4553
|
url: githubUrl(c.url),
|
|
4376
4554
|
path: str2(t.path),
|
|
@@ -4380,7 +4558,7 @@ function parsePrFeedback(answer) {
|
|
|
4380
4558
|
}
|
|
4381
4559
|
for (const c of nodes(p?.comments)) {
|
|
4382
4560
|
const at = seconds(c.createdAt);
|
|
4383
|
-
const body =
|
|
4561
|
+
const body = text2(c.body);
|
|
4384
4562
|
if (at === null || isApprovalChatter(body) || !person(c.author) || !str2(c.id)) continue;
|
|
4385
4563
|
items.push({
|
|
4386
4564
|
id: c.id,
|
|
@@ -4691,12 +4869,12 @@ const REMOTE_LOOK_MS = 5e3;
|
|
|
4691
4869
|
const REFRESH_AT_ONCE = 2;
|
|
4692
4870
|
const PULL = /https?:\/\/[^\s)]+\/pull\/\d+/g;
|
|
4693
4871
|
const LINE = /^([A-Za-z][A-Za-z_-]*)((?:\s*\[[^\]]*\])*)\s*:\s?(.*)$/;
|
|
4694
|
-
function parseStatusLog(
|
|
4872
|
+
function parseStatusLog(text2) {
|
|
4695
4873
|
const lines = [];
|
|
4696
4874
|
let preview2 = null;
|
|
4697
4875
|
let board2 = null;
|
|
4698
4876
|
let pr = null;
|
|
4699
|
-
for (const raw of
|
|
4877
|
+
for (const raw of text2.split("\n")) {
|
|
4700
4878
|
const m = LINE.exec(raw.trim());
|
|
4701
4879
|
if (!m) continue;
|
|
4702
4880
|
const at = /\[at=(\d{9,11})\]/.exec(m[2])?.[1];
|
|
@@ -4714,21 +4892,21 @@ function parseStatusLog(text) {
|
|
|
4714
4892
|
}
|
|
4715
4893
|
return { lines, preview: preview2, board: board2, pr, truncated: false, cut: false };
|
|
4716
4894
|
}
|
|
4717
|
-
function parseMetaProject(
|
|
4718
|
-
const repo = metaGet(
|
|
4895
|
+
function parseMetaProject(text2, home) {
|
|
4896
|
+
const repo = metaGet(text2, "repo").trim();
|
|
4719
4897
|
if (repo) return repo;
|
|
4720
|
-
const project = metaGet(
|
|
4898
|
+
const project = metaGet(text2, "project").trim();
|
|
4721
4899
|
if (!project) return null;
|
|
4722
4900
|
if (home && path.posix.resolve(project) === path.posix.resolve(home)) return "firstmate";
|
|
4723
4901
|
return path.posix.basename(project) || null;
|
|
4724
4902
|
}
|
|
4725
|
-
function parseMetaPr(
|
|
4726
|
-
return metaGet(
|
|
4903
|
+
function parseMetaPr(text2) {
|
|
4904
|
+
return metaGet(text2, "pr").trim().match(PULL)?.[0] ?? null;
|
|
4727
4905
|
}
|
|
4728
4906
|
function tailText(buf, max) {
|
|
4729
4907
|
if (buf.length <= max) return { text: buf.toString("utf8"), truncated: false };
|
|
4730
|
-
const
|
|
4731
|
-
return { text:
|
|
4908
|
+
const text2 = buf.subarray(buf.length - max).toString("utf8");
|
|
4909
|
+
return { text: text2.slice(text2.indexOf("\n") + 1), truncated: true };
|
|
4732
4910
|
}
|
|
4733
4911
|
const OFFLINE = (host) => `Offline: Firstmate could not reach ${host ?? "its host"}. Wheelhouse does not try again by itself.`;
|
|
4734
4912
|
const tasksOf = (m) => [...m.inFlight, ...m.queued, ...m.landed];
|
|
@@ -5014,19 +5192,19 @@ class MateTasks {
|
|
|
5014
5192
|
const now = this.now();
|
|
5015
5193
|
if (hit && (hit.value && !again ? true : now - hit.at < META_RETRY_MS)) return false;
|
|
5016
5194
|
const rel = `state/${task2.id}.meta`;
|
|
5017
|
-
let
|
|
5195
|
+
let text2;
|
|
5018
5196
|
if (route.remote) {
|
|
5019
5197
|
const r = await this.deps.adapter.remoteFile(mate.id, rel, META_MAX_BYTES);
|
|
5020
5198
|
if (!r.ok && r.error.exitCode === REMOTE_UNREACHABLE) return "offline";
|
|
5021
|
-
|
|
5199
|
+
text2 = r.ok ? r.value : null;
|
|
5022
5200
|
} else {
|
|
5023
|
-
|
|
5201
|
+
text2 = (await readInside(route.home, rel, META_MAX_BYTES))?.text ?? null;
|
|
5024
5202
|
}
|
|
5025
|
-
const value =
|
|
5026
|
-
projectId: parseMetaProject(
|
|
5027
|
-
pr: parseMetaPr(
|
|
5028
|
-
worktree: metaGet(
|
|
5029
|
-
branch: metaGet(
|
|
5203
|
+
const value = text2 === null ? hit?.value ?? null : {
|
|
5204
|
+
projectId: parseMetaProject(text2, mate.home),
|
|
5205
|
+
pr: parseMetaPr(text2),
|
|
5206
|
+
worktree: metaGet(text2, "worktree").trim() || null,
|
|
5207
|
+
branch: metaGet(text2, "branch").trim() || null
|
|
5030
5208
|
};
|
|
5031
5209
|
this.metas.set(id, { at: now, value });
|
|
5032
5210
|
return true;
|
|
@@ -5035,8 +5213,8 @@ class MateTasks {
|
|
|
5035
5213
|
const id = mateTaskId(mate.id, task2.id);
|
|
5036
5214
|
const rel = `state/${task2.id}.status`;
|
|
5037
5215
|
const observedAt = new Date(this.now()).toISOString();
|
|
5038
|
-
const log = ({ text, truncated }) => ({
|
|
5039
|
-
...parseStatusLog(
|
|
5216
|
+
const log = ({ text: text2, truncated }) => ({
|
|
5217
|
+
...parseStatusLog(text2),
|
|
5040
5218
|
truncated
|
|
5041
5219
|
});
|
|
5042
5220
|
if (!route.remote) {
|
|
@@ -5174,12 +5352,12 @@ class MateTasks {
|
|
|
5174
5352
|
* mate's inbox, `Re: <task>` as Wheelhouse's own notes are, with the task's
|
|
5175
5353
|
* `<task>@<mate>` name in the text put back to the id that home knows it by.
|
|
5176
5354
|
*/
|
|
5177
|
-
async send(id, requestId,
|
|
5355
|
+
async send(id, requestId, text2) {
|
|
5178
5356
|
const f = this.find(id);
|
|
5179
5357
|
if (!f.ok) return f;
|
|
5180
5358
|
const { mate, task: task2, route } = f.value;
|
|
5181
5359
|
const body = `Re: ${task2.id}
|
|
5182
|
-
${
|
|
5360
|
+
${text2.split(mateTaskId(mate.id, task2.id)).join(task2.id)}`;
|
|
5183
5361
|
const r = await this.deps.adapter.mateNote(route, requestId, body);
|
|
5184
5362
|
if (r.ok)
|
|
5185
5363
|
return { ok: true, created: r.value.outcome === "created", announced: r.value.announced };
|
|
@@ -5221,8 +5399,8 @@ ${text.split(mateTaskId(mate.id, task2.id)).join(task2.id)}`;
|
|
|
5221
5399
|
async readBrief({ mate, task: task2, route }) {
|
|
5222
5400
|
const rel = `data/${task2.id}/brief.md`;
|
|
5223
5401
|
const none = `${mate.id} kept no brief for this task.`;
|
|
5224
|
-
const value = (
|
|
5225
|
-
...parseBrief(
|
|
5402
|
+
const value = (text2, bytes, truncated, remote) => ({
|
|
5403
|
+
...parseBrief(text2),
|
|
5226
5404
|
path: rel,
|
|
5227
5405
|
bytes,
|
|
5228
5406
|
truncated,
|
|
@@ -5338,8 +5516,8 @@ async function readInside(root, rel, max) {
|
|
|
5338
5516
|
const start = Math.max(0, size - max);
|
|
5339
5517
|
const buf = Buffer.alloc(Math.min(size, max));
|
|
5340
5518
|
const { bytesRead } = await fh.read(buf, 0, buf.length, start);
|
|
5341
|
-
const
|
|
5342
|
-
return start > 0 ? { text:
|
|
5519
|
+
const text2 = buf.subarray(0, bytesRead).toString("utf8");
|
|
5520
|
+
return start > 0 ? { text: text2.slice(text2.indexOf("\n") + 1), truncated: true } : { text: text2, truncated: false };
|
|
5343
5521
|
} finally {
|
|
5344
5522
|
await fh.close();
|
|
5345
5523
|
}
|
|
@@ -5519,7 +5697,7 @@ class RemoteGit {
|
|
|
5519
5697
|
const STOPPED = "The worker will bring it back; it shows here again as soon as it answers.";
|
|
5520
5698
|
const CLOSED = "This work has landed, so its preview is no longer running.";
|
|
5521
5699
|
const TTL_MS = 5e3;
|
|
5522
|
-
const TIMEOUT_MS$
|
|
5700
|
+
const TIMEOUT_MS$2 = 2e3;
|
|
5523
5701
|
class PreviewProber {
|
|
5524
5702
|
fetch;
|
|
5525
5703
|
now;
|
|
@@ -5530,7 +5708,7 @@ class PreviewProber {
|
|
|
5530
5708
|
constructor(opts = {}) {
|
|
5531
5709
|
this.fetch = opts.fetch ?? fetch;
|
|
5532
5710
|
this.now = opts.now ?? Date.now;
|
|
5533
|
-
this.timeoutMs = opts.timeoutMs ?? TIMEOUT_MS$
|
|
5711
|
+
this.timeoutMs = opts.timeoutMs ?? TIMEOUT_MS$2;
|
|
5534
5712
|
}
|
|
5535
5713
|
/**
|
|
5536
5714
|
* The check for a page served at `pageOrigin`, which is what the preview
|
|
@@ -5630,8 +5808,8 @@ function writeRemembered(configDir, r) {
|
|
|
5630
5808
|
}
|
|
5631
5809
|
const SESSION_HEADER = "x-wheelhouse-session";
|
|
5632
5810
|
const LOOPBACK_HOST = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i;
|
|
5633
|
-
function servedOrigin(
|
|
5634
|
-
return `http://${(
|
|
5811
|
+
function servedOrigin(request2) {
|
|
5812
|
+
return `http://${(request2.headers.get("host") ?? "").toLowerCase()}`;
|
|
5635
5813
|
}
|
|
5636
5814
|
const KEY$2 = /* @__PURE__ */ Symbol.for("wheelhouse.session-token");
|
|
5637
5815
|
const g$2 = globalThis;
|
|
@@ -5652,10 +5830,10 @@ function tokenMatches(given) {
|
|
|
5652
5830
|
}
|
|
5653
5831
|
const SAFE_METHODS$1 = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
5654
5832
|
const isMutating = (method) => !SAFE_METHODS$1.has(method.toUpperCase());
|
|
5655
|
-
function refuseMutation(
|
|
5833
|
+
function refuseMutation(request2, servedOrigin2) {
|
|
5656
5834
|
return refuseCaller(
|
|
5657
|
-
|
|
5658
|
-
|
|
5835
|
+
request2.headers.get("origin"),
|
|
5836
|
+
request2.headers.get(SESSION_HEADER),
|
|
5659
5837
|
servedOrigin2
|
|
5660
5838
|
);
|
|
5661
5839
|
}
|
|
@@ -5675,10 +5853,10 @@ const MAX_ROWS = 500;
|
|
|
5675
5853
|
const HIGH_WATER = 1024 * 1024;
|
|
5676
5854
|
const LOW_WATER = 128 * 1024;
|
|
5677
5855
|
const MAX_CLOSE_REASON_BYTES = 123;
|
|
5678
|
-
function closeReason(
|
|
5856
|
+
function closeReason(text2) {
|
|
5679
5857
|
let out = "";
|
|
5680
5858
|
let bytes = 0;
|
|
5681
|
-
for (const ch of
|
|
5859
|
+
for (const ch of text2) {
|
|
5682
5860
|
bytes += Buffer.byteLength(ch);
|
|
5683
5861
|
if (bytes > MAX_CLOSE_REASON_BYTES) break;
|
|
5684
5862
|
out += ch;
|
|
@@ -5964,13 +6142,13 @@ class LedgerReader {
|
|
|
5964
6142
|
skipFirstLine = true;
|
|
5965
6143
|
}
|
|
5966
6144
|
const length = Math.min(size - start, MAX_READ_BYTES$1);
|
|
5967
|
-
let
|
|
6145
|
+
let text2;
|
|
5968
6146
|
try {
|
|
5969
6147
|
const fh = await open(this.file, "r");
|
|
5970
6148
|
try {
|
|
5971
6149
|
const buf = Buffer.alloc(length);
|
|
5972
6150
|
const { bytesRead } = await fh.read(buf, 0, length, start);
|
|
5973
|
-
|
|
6151
|
+
text2 = buf.subarray(0, bytesRead).toString("utf8");
|
|
5974
6152
|
this.offset = start + bytesRead;
|
|
5975
6153
|
} finally {
|
|
5976
6154
|
await fh.close();
|
|
@@ -5979,8 +6157,8 @@ class LedgerReader {
|
|
|
5979
6157
|
this.problem = `Could not read the fleet ledger: ${e.message}`;
|
|
5980
6158
|
return 0;
|
|
5981
6159
|
}
|
|
5982
|
-
|
|
5983
|
-
const lines =
|
|
6160
|
+
text2 = this.partial + text2;
|
|
6161
|
+
const lines = text2.split("\n");
|
|
5984
6162
|
this.partial = lines.pop() ?? "";
|
|
5985
6163
|
if (skipFirstLine) lines.shift();
|
|
5986
6164
|
let count = 0;
|
|
@@ -6447,8 +6625,8 @@ function outputAfter(lines, i, stop) {
|
|
|
6447
6625
|
return bound(out);
|
|
6448
6626
|
}
|
|
6449
6627
|
function parseTestOutput(raw) {
|
|
6450
|
-
const
|
|
6451
|
-
const lines =
|
|
6628
|
+
const text2 = raw.replace(ANSI, "").replace(/\r\n?/g, "\n");
|
|
6629
|
+
const lines = text2.split("\n");
|
|
6452
6630
|
let passed = null;
|
|
6453
6631
|
let failed2 = null;
|
|
6454
6632
|
let skipped = null;
|
|
@@ -6552,11 +6730,11 @@ function failuresIn(lines) {
|
|
|
6552
6730
|
return out;
|
|
6553
6731
|
}
|
|
6554
6732
|
function narration(log) {
|
|
6555
|
-
const
|
|
6556
|
-
const starts = [...
|
|
6733
|
+
const text2 = log.replace(ANSI, "").replace(/\r\n?/g, "\n");
|
|
6734
|
+
const starts = [...text2.matchAll(/^(?:\S+ )?started pid=\d+\s*$/gm)];
|
|
6557
6735
|
const last = starts.at(-1);
|
|
6558
6736
|
if (!last || last.index === void 0) return [];
|
|
6559
|
-
const rest2 =
|
|
6737
|
+
const rest2 = text2.slice(last.index + last[0].length);
|
|
6560
6738
|
const end = /^(?:\S+ )?exited pid=\d+.*$/m.exec(rest2);
|
|
6561
6739
|
const body = (end ? rest2.slice(0, end.index) : rest2).trim();
|
|
6562
6740
|
return body.split(/(?<=[.!?])\s*(?=[A-Z])|\n+/).map((s) => clean(s.trim())).filter((s) => s.length > 2).slice(-12);
|
|
@@ -6566,8 +6744,8 @@ function agentExit(log) {
|
|
|
6566
6744
|
return m ? m[1] === "success" ? "success" : "failure" : null;
|
|
6567
6745
|
}
|
|
6568
6746
|
function parsePrTesting(body) {
|
|
6569
|
-
const
|
|
6570
|
-
const m = /^## Testing\s*\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(
|
|
6747
|
+
const text2 = body.replace(/\r\n?/g, "\n");
|
|
6748
|
+
const m = /^## Testing\s*\n([\s\S]*?)(?=^## |(?![\s\S]))/m.exec(text2);
|
|
6571
6749
|
if (!m) return null;
|
|
6572
6750
|
const section = m[1].replace(/<details>[\s\S]*?<\/details>/g, "");
|
|
6573
6751
|
const scenarios = [];
|
|
@@ -6639,7 +6817,7 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6639
6817
|
tests: null,
|
|
6640
6818
|
docs: null
|
|
6641
6819
|
};
|
|
6642
|
-
const
|
|
6820
|
+
const text2 = log ?? "";
|
|
6643
6821
|
const upcoming = state === "upcoming";
|
|
6644
6822
|
const skipped = state === "skipped";
|
|
6645
6823
|
const asked = i.decided.filter((d) => d.step === key);
|
|
@@ -6652,12 +6830,12 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6652
6830
|
r.summary = upcoming ? "Not started" : "Read what the change is for";
|
|
6653
6831
|
break;
|
|
6654
6832
|
case "rebase":
|
|
6655
|
-
r.summary = upcoming ? "Not started" : /conflict/i.test(
|
|
6833
|
+
r.summary = upcoming ? "Not started" : /conflict/i.test(text2) ? "Ran into a conflict with the main branch" : /up to date|already/i.test(text2) ? "Already up to date with the main branch" : state === "done" ? "Brought up to date with the main branch" : "Bringing the branch up to date";
|
|
6656
6834
|
break;
|
|
6657
6835
|
case "review": {
|
|
6658
|
-
const rounds = (
|
|
6659
|
-
const found = [...
|
|
6660
|
-
const fixes = (
|
|
6836
|
+
const rounds = (text2.match(/^reviewing changes/gm) ?? []).length;
|
|
6837
|
+
const found = [...text2.matchAll(/found (\d+) findings?/g)].map((m) => Number(m[1]));
|
|
6838
|
+
const fixes = (text2.match(/^committed agent fixes/gm) ?? []).length;
|
|
6661
6839
|
const total = found.reduce((a, b) => a + b, 0) || findings;
|
|
6662
6840
|
if (upcoming) r.summary = "Not started";
|
|
6663
6841
|
else if (!total && state === "done") r.summary = "Found nothing to change";
|
|
@@ -6671,7 +6849,7 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6671
6849
|
break;
|
|
6672
6850
|
}
|
|
6673
6851
|
case "test": {
|
|
6674
|
-
const parsed = parseTestOutput(
|
|
6852
|
+
const parsed = parseTestOutput(text2);
|
|
6675
6853
|
const scenarios = testing?.scenarios ?? [];
|
|
6676
6854
|
if (parsed || scenarios.length) {
|
|
6677
6855
|
r.tests = {
|
|
@@ -6683,12 +6861,12 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6683
6861
|
basis: parsed ? scenarios.length ? "the test run’s own summary and the pull request’s testing notes" : "the test run’s own summary" : "the pull request’s testing notes"
|
|
6684
6862
|
};
|
|
6685
6863
|
}
|
|
6686
|
-
r.notes = narration(
|
|
6687
|
-
const exit = agentExit(
|
|
6864
|
+
r.notes = narration(text2);
|
|
6865
|
+
const exit = agentExit(text2);
|
|
6688
6866
|
if (upcoming) r.summary = "Not started";
|
|
6689
6867
|
else if (skipped) r.summary = "Skipped for this change";
|
|
6690
6868
|
else if (r.tests) r.summary = testLine(r.tests);
|
|
6691
|
-
else if (/configured test command failed/.test(
|
|
6869
|
+
else if (/configured test command failed/.test(text2) || state === "failed" || exit === "failure")
|
|
6692
6870
|
r.summary = "Tests failed";
|
|
6693
6871
|
else if (state === "done")
|
|
6694
6872
|
r.summary = findings ? `Tests raised ${plural(findings, "problem")}` : "Tests passed";
|
|
@@ -6700,14 +6878,14 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6700
6878
|
}
|
|
6701
6879
|
case "document": {
|
|
6702
6880
|
const commits = [
|
|
6703
|
-
...
|
|
6881
|
+
...text2.matchAll(/^committed agent fixes: (?:no-mistakes\(document\): )?(.+)$/gm)
|
|
6704
6882
|
].map((m) => m[1].trim());
|
|
6705
6883
|
const bullets = i.prBody ? docBullets(i.prBody) : [];
|
|
6706
6884
|
r.docs = { files: i.docs, summary: [...commits, ...bullets] };
|
|
6707
|
-
r.notes = narration(
|
|
6885
|
+
r.notes = narration(text2);
|
|
6708
6886
|
const left = Number(
|
|
6709
6887
|
/document findings: (\d+) unresolved/.exec(
|
|
6710
|
-
[...
|
|
6888
|
+
[...text2.matchAll(/document findings: \d+ unresolved/g)].at(-1)?.[0] ?? ""
|
|
6711
6889
|
)?.[1] ?? 0
|
|
6712
6890
|
);
|
|
6713
6891
|
if (upcoming) r.summary = "Not started";
|
|
@@ -6716,14 +6894,14 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6716
6894
|
r.summary = `Updated the docs${i.docs.length ? `: ${plural(i.docs.length, "document")} changed in all` : ""}`;
|
|
6717
6895
|
else if (i.docs.length)
|
|
6718
6896
|
r.summary = `${plural(i.docs.length, "document")} changed; the docs step had nothing to add`;
|
|
6719
|
-
else if (/no agent changes to commit/.test(
|
|
6897
|
+
else if (/no agent changes to commit/.test(text2) || state === "done")
|
|
6720
6898
|
r.summary = "No documentation changes needed";
|
|
6721
6899
|
else r.summary = "Checking the docs match the change";
|
|
6722
6900
|
if (left) r.summary += `; ${plural(left, "item")} left open`;
|
|
6723
6901
|
break;
|
|
6724
6902
|
}
|
|
6725
6903
|
case "lint": {
|
|
6726
|
-
const m = [...
|
|
6904
|
+
const m = [...text2.matchAll(/(\d+) unresolved items?/g)].at(-1);
|
|
6727
6905
|
r.summary = upcoming ? "Not started" : skipped ? "Skipped for this change" : m ? Number(m[1]) ? `${plural(Number(m[1]), "lint problem")} left` : "No lint problems" : state === "done" ? "No lint problems" : "Checking style and lint";
|
|
6728
6906
|
break;
|
|
6729
6907
|
}
|
|
@@ -6731,13 +6909,13 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6731
6909
|
r.summary = upcoming ? "Not started" : state === "done" ? "Pushed the branch" : "Pushing the branch";
|
|
6732
6910
|
break;
|
|
6733
6911
|
case "pr":
|
|
6734
|
-
r.summary = upcoming ? "Not started" : /updat/i.test(
|
|
6912
|
+
r.summary = upcoming ? "Not started" : /updat/i.test(text2) ? "Updated the pull request" : state === "done" ? "Opened the pull request" : "Opening the pull request";
|
|
6735
6913
|
break;
|
|
6736
6914
|
case "ci": {
|
|
6737
|
-
const ci = log === null ? "unknown" : ciResultFromLog(
|
|
6915
|
+
const ci = log === null ? "unknown" : ciResultFromLog(text2);
|
|
6738
6916
|
if (state === "running" && ci === "green") r.state = "done";
|
|
6739
|
-
r.summary = upcoming ? "Not started" : /no_ci: true|declares no CI/.test(
|
|
6740
|
-
if (/CI repair/i.test(
|
|
6917
|
+
r.summary = upcoming ? "Not started" : /no_ci: true|declares no CI/.test(text2) ? "This repository has no CI checks" : ci === "green" ? "CI checks passed" : ci === "red" ? "CI checks failed" : "Waiting for CI checks";
|
|
6918
|
+
if (/CI repair/i.test(text2)) r.notes = ["Pushed a repair for a failing CI check"];
|
|
6741
6919
|
break;
|
|
6742
6920
|
}
|
|
6743
6921
|
}
|
|
@@ -6751,8 +6929,8 @@ function report(key, label2, state, findings, durationMs2, log, i, testing) {
|
|
|
6751
6929
|
}
|
|
6752
6930
|
return r;
|
|
6753
6931
|
}
|
|
6754
|
-
function parseInboxRecord(name2,
|
|
6755
|
-
const t =
|
|
6932
|
+
function parseInboxRecord(name2, text2, handled) {
|
|
6933
|
+
const t = text2.replace(/\r\n?/g, "\n");
|
|
6756
6934
|
const sep = t.indexOf("\n--\n");
|
|
6757
6935
|
const head2 = sep >= 0 && /^schema=/.test(t) ? t.slice(0, sep) : "";
|
|
6758
6936
|
const body = head2 ? t.slice(sep + 4) : t;
|
|
@@ -6763,9 +6941,9 @@ function parseInboxRecord(name2, text, handled) {
|
|
|
6763
6941
|
const OPS$1 = /\s*(?:In the same response|Run:? no-mistakes|Keep driving|Do not use --yes|Then (?:run|re-?attach)|Reattach with|Acknowledge by moving)[\s\S]*$/;
|
|
6764
6942
|
const PREVIEW = /^Review feedback on the live preview \([^)\n]*\):\n/;
|
|
6765
6943
|
const MAX_BODY$1 = 4e3;
|
|
6766
|
-
function plainBody(
|
|
6944
|
+
function plainBody(text2) {
|
|
6767
6945
|
const out = [];
|
|
6768
|
-
for (const raw of
|
|
6946
|
+
for (const raw of text2.replace(OPS$1, "").split("\n")) {
|
|
6769
6947
|
const line = raw.trim();
|
|
6770
6948
|
if (!line) {
|
|
6771
6949
|
if (out.length && out.at(-1) !== "") out.push("");
|
|
@@ -6778,8 +6956,8 @@ function plainBody(text) {
|
|
|
6778
6956
|
const s = out.join("\n").trim();
|
|
6779
6957
|
return s.length > MAX_BODY$1 ? `${s.slice(0, MAX_BODY$1 - 1)}…` : s;
|
|
6780
6958
|
}
|
|
6781
|
-
function firstLine(
|
|
6782
|
-
const first =
|
|
6959
|
+
function firstLine(text2, max = 140) {
|
|
6960
|
+
const first = text2.split("\n").find((l) => l.trim()) ?? "";
|
|
6783
6961
|
const s = first.replace(/^- /, "").split(/(?<=[.!?])\s/)[0].trim();
|
|
6784
6962
|
return s.length > max ? `${s.slice(0, max - 1).trimEnd()}…` : s;
|
|
6785
6963
|
}
|
|
@@ -6835,11 +7013,11 @@ function conversation(i) {
|
|
|
6835
7013
|
if (at < 0) continue;
|
|
6836
7014
|
const [o] = open2.splice(at, 1);
|
|
6837
7015
|
const answered = /^answered:/i.test(s.text.trim());
|
|
6838
|
-
const
|
|
7016
|
+
const text2 = s.text.replace(/^answered:\s*/i, "").replace(/\s*\[truncated\]\s*$/, "");
|
|
6839
7017
|
const decidedFor = o.entry.questions.some((q) => q.verdict);
|
|
6840
|
-
const msg = answered ? answerMessage(
|
|
7018
|
+
const msg = answered ? answerMessage(text2, s.ts, o.entry.kind === "review") : null;
|
|
6841
7019
|
if (msg) used.add(msg.name);
|
|
6842
|
-
const full = plainBody(msg?.body ??
|
|
7020
|
+
const full = plainBody(msg?.body ?? text2);
|
|
6843
7021
|
o.entry.reply = decidedFor ? null : {
|
|
6844
7022
|
at: iso$1(s.ts),
|
|
6845
7023
|
from: answered ? "firstmate" : "worker",
|
|
@@ -6857,9 +7035,9 @@ function conversation(i) {
|
|
|
6857
7035
|
const fromCaptain = PREVIEW.test(m.body);
|
|
6858
7036
|
const n = norm(m.body);
|
|
6859
7037
|
if (captainProbes.some((p) => p.length > 8 && n.includes(p))) continue;
|
|
6860
|
-
const
|
|
6861
|
-
if (!
|
|
6862
|
-
const title = firstLine(
|
|
7038
|
+
const text2 = plainBody(m.body.replace(PREVIEW, ""));
|
|
7039
|
+
if (!text2) continue;
|
|
7040
|
+
const title = firstLine(text2);
|
|
6863
7041
|
out.push({
|
|
6864
7042
|
id: `inbox-${m.name}`,
|
|
6865
7043
|
at: iso$1(m.at ?? i.dispatchedAt) ?? (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -6867,7 +7045,7 @@ function conversation(i) {
|
|
|
6867
7045
|
from: fromCaptain ? "captain" : "firstmate",
|
|
6868
7046
|
to: "worker",
|
|
6869
7047
|
title: fromCaptain ? "Your feedback from the live preview, passed on to the worker" : title,
|
|
6870
|
-
body: fromCaptain ?
|
|
7048
|
+
body: fromCaptain ? text2 : rest(text2, title),
|
|
6871
7049
|
questions: [],
|
|
6872
7050
|
reply: null,
|
|
6873
7051
|
outcome: m.handled ? { state: "read", label: "The worker has read it" } : { state: "unread", label: "Not read by the worker yet" }
|
|
@@ -6875,7 +7053,7 @@ function conversation(i) {
|
|
|
6875
7053
|
}
|
|
6876
7054
|
for (const m of i.captain) {
|
|
6877
7055
|
const preview2 = PREVIEW.test(m.text);
|
|
6878
|
-
const
|
|
7056
|
+
const text2 = m.text.replace(PREVIEW, "").trim();
|
|
6879
7057
|
out.push({
|
|
6880
7058
|
id: `captain-${m.requestId}`,
|
|
6881
7059
|
at: m.submittedAt,
|
|
@@ -6883,7 +7061,7 @@ function conversation(i) {
|
|
|
6883
7061
|
from: "captain",
|
|
6884
7062
|
to: "firstmate",
|
|
6885
7063
|
title: preview2 ? "You sent feedback from the live preview" : "You wrote to Firstmate",
|
|
6886
|
-
body:
|
|
7064
|
+
body: text2,
|
|
6887
7065
|
questions: [],
|
|
6888
7066
|
reply: m.reply ? { at: m.reply.at, from: "firstmate", text: m.reply.body } : null,
|
|
6889
7067
|
outcome: {
|
|
@@ -6894,9 +7072,9 @@ function conversation(i) {
|
|
|
6894
7072
|
}
|
|
6895
7073
|
return out.sort((a, b) => a.at.localeCompare(b.at));
|
|
6896
7074
|
}
|
|
6897
|
-
function rest(
|
|
7075
|
+
function rest(text2, title) {
|
|
6898
7076
|
const t = title.replace(/…$/, "");
|
|
6899
|
-
const r =
|
|
7077
|
+
const r = text2.startsWith(t) && !title.endsWith("…") ? text2.slice(t.length).trim() : text2;
|
|
6900
7078
|
return r && r !== title ? r : null;
|
|
6901
7079
|
}
|
|
6902
7080
|
const lower = (s) => s ? s.charAt(0).toLowerCase() + s.slice(1) : s;
|
|
@@ -6950,11 +7128,11 @@ function readableName(p) {
|
|
|
6950
7128
|
}
|
|
6951
7129
|
function docTitle(md, p) {
|
|
6952
7130
|
if (docKind(p) === "readme") return readableName(p);
|
|
6953
|
-
const
|
|
6954
|
-
const front = /^---\n([\s\S]*?)\n---/.exec(
|
|
7131
|
+
const text2 = md.replace(/\r\n?/g, "\n");
|
|
7132
|
+
const front = /^---\n([\s\S]*?)\n---/.exec(text2);
|
|
6955
7133
|
const named = front && /^(?:title|name):\s*["']?(.+?)["']?\s*$/m.exec(front[1]);
|
|
6956
7134
|
if (named) return named[1].trim();
|
|
6957
|
-
const body = front ?
|
|
7135
|
+
const body = front ? text2.slice(front[0].length) : text2;
|
|
6958
7136
|
const h = /^#{1,2}\s+(.+?)\s*#*\s*$/m.exec(body) ?? /^(.+)\n=+\s*$/m.exec(body);
|
|
6959
7137
|
const t = h?.[1].replace(/`([^`]+)`/g, "$1").replace(/\*\*?([^*]+)\*\*?/g, "$1").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").trim();
|
|
6960
7138
|
return t || readableName(p);
|
|
@@ -7160,8 +7338,8 @@ class BuildReader {
|
|
|
7160
7338
|
let startedAt = null;
|
|
7161
7339
|
await Promise.all(
|
|
7162
7340
|
STEP_KEYS.map(async (k) => {
|
|
7163
|
-
const
|
|
7164
|
-
if (
|
|
7341
|
+
const text2 = await readTail(path.join(dir, `${k}.log`), STEP_LOG_BYTES);
|
|
7342
|
+
if (text2 !== null) logs.set(k, text2);
|
|
7165
7343
|
})
|
|
7166
7344
|
);
|
|
7167
7345
|
const first = await stat(path.join(dir, "intent.log")).catch(() => null);
|
|
@@ -7307,8 +7485,8 @@ class BuildReader {
|
|
|
7307
7485
|
const key = `${c.task.id} ${p}`;
|
|
7308
7486
|
const known = this.titles.get(key);
|
|
7309
7487
|
if (known) return known;
|
|
7310
|
-
const
|
|
7311
|
-
const t =
|
|
7488
|
+
const text2 = await this.docText(c, p, TITLE_BYTES).catch(() => null);
|
|
7489
|
+
const t = text2 ? docTitle(text2.text, p) : readableName(p);
|
|
7312
7490
|
this.titles.set(key, t);
|
|
7313
7491
|
return t;
|
|
7314
7492
|
}
|
|
@@ -7346,8 +7524,8 @@ class BuildReader {
|
|
|
7346
7524
|
const ref = docs.value.find((d) => d.path === p);
|
|
7347
7525
|
if (!ref)
|
|
7348
7526
|
return { available: false, reason: "That document is not in this task’s list of docs." };
|
|
7349
|
-
const
|
|
7350
|
-
if (!
|
|
7527
|
+
const text2 = await this.docText(c, p, DOC_BYTES$1);
|
|
7528
|
+
if (!text2) {
|
|
7351
7529
|
return {
|
|
7352
7530
|
available: false,
|
|
7353
7531
|
reason: ref.github ? "Its text is not on this machine any more; it can still be read on GitHub." : "Its text is not on this machine any more."
|
|
@@ -7355,15 +7533,15 @@ class BuildReader {
|
|
|
7355
7533
|
}
|
|
7356
7534
|
return {
|
|
7357
7535
|
available: true,
|
|
7358
|
-
source:
|
|
7536
|
+
source: text2.from,
|
|
7359
7537
|
observedAt: new Date(this.now()).toISOString(),
|
|
7360
7538
|
value: {
|
|
7361
7539
|
path: ref.path,
|
|
7362
7540
|
name: ref.name,
|
|
7363
7541
|
title: ref.title,
|
|
7364
7542
|
kind: ref.kind,
|
|
7365
|
-
markdown:
|
|
7366
|
-
truncated: !
|
|
7543
|
+
markdown: text2.text,
|
|
7544
|
+
truncated: !text2.whole,
|
|
7367
7545
|
github: ref.github,
|
|
7368
7546
|
changed: ref.changed
|
|
7369
7547
|
}
|
|
@@ -8071,13 +8249,13 @@ function pairRounds(statuses) {
|
|
|
8071
8249
|
} else if (s.state === "resolved" && open2.has(key)) {
|
|
8072
8250
|
const round = open2.get(key);
|
|
8073
8251
|
open2.delete(key);
|
|
8074
|
-
const
|
|
8075
|
-
if (!/^answered:/i.test(s.text) ||
|
|
8252
|
+
const text2 = s.text.replace(/^answered:\s*/i, "");
|
|
8253
|
+
if (!/^answered:/i.test(s.text) || text2.replace(CUT, "").trim().length < 3) {
|
|
8076
8254
|
round.closed = true;
|
|
8077
8255
|
continue;
|
|
8078
8256
|
}
|
|
8079
8257
|
round.decidedAt = s.ts;
|
|
8080
|
-
round.answer =
|
|
8258
|
+
round.answer = text2;
|
|
8081
8259
|
}
|
|
8082
8260
|
}
|
|
8083
8261
|
return out;
|
|
@@ -8093,9 +8271,9 @@ function pairDecisions(statuses) {
|
|
|
8093
8271
|
answer
|
|
8094
8272
|
}));
|
|
8095
8273
|
}
|
|
8096
|
-
function parseFindings(
|
|
8274
|
+
function parseFindings(text2) {
|
|
8097
8275
|
const out = [];
|
|
8098
|
-
for (const block of
|
|
8276
|
+
for (const block of text2.split(/\n\s*\n/)) {
|
|
8099
8277
|
const f = {};
|
|
8100
8278
|
let last = null;
|
|
8101
8279
|
for (const l of block.split("\n")) {
|
|
@@ -8133,11 +8311,11 @@ function fullAnswer(answer, messages) {
|
|
|
8133
8311
|
}
|
|
8134
8312
|
return { text: head2.replace(OPS, "").trim(), cut: cut2 };
|
|
8135
8313
|
}
|
|
8136
|
-
function verdictOf(
|
|
8137
|
-
const none = /\bNO (?:CODE )?CHANGES?\b/.test(
|
|
8138
|
-
const fix = /\bFIX\b/.test(
|
|
8139
|
-
const keep = /\bKEEP\b/.test(
|
|
8140
|
-
const defer = /\bDEFER/.test(
|
|
8314
|
+
function verdictOf(text2) {
|
|
8315
|
+
const none = /\bNO (?:CODE )?CHANGES?\b/.test(text2) || /\bDISCARD\b/.test(text2);
|
|
8316
|
+
const fix = /\bFIX\b/.test(text2) || /:\s*fix it\b/i.test(text2);
|
|
8317
|
+
const keep = /\bKEEP\b/.test(text2) || /keep the omission/i.test(text2);
|
|
8318
|
+
const defer = /\bDEFER/.test(text2) || !fix && !keep && !none && /\bdefer/i.test(text2);
|
|
8141
8319
|
if ([fix, keep, defer, none].filter(Boolean).length > 1) return "Mixed";
|
|
8142
8320
|
return fix ? "Fix it" : keep ? "Keep as is" : none ? "No change" : defer ? "Defer" : "Decided";
|
|
8143
8321
|
}
|
|
@@ -8167,8 +8345,8 @@ function callsFor(answer, findings) {
|
|
|
8167
8345
|
const lead = marks.length ? body.slice(0, marks[0].at) : body;
|
|
8168
8346
|
return findings.map((f) => {
|
|
8169
8347
|
const own = parts.get(f.id);
|
|
8170
|
-
const
|
|
8171
|
-
return { finding: f, verdict: verdictOf(
|
|
8348
|
+
const text2 = own && own.replace(/^[\s:–—-]*/, "").trim() ? own : lead;
|
|
8349
|
+
return { finding: f, verdict: verdictOf(text2), reason: reasonOf$1(text2) };
|
|
8172
8350
|
});
|
|
8173
8351
|
}
|
|
8174
8352
|
function idAt(id, anchored) {
|
|
@@ -8194,8 +8372,8 @@ const RAISED_IN$1 = {
|
|
|
8194
8372
|
lint: "the code style check",
|
|
8195
8373
|
ci: "CI"
|
|
8196
8374
|
};
|
|
8197
|
-
function scrub(
|
|
8198
|
-
let s =
|
|
8375
|
+
function scrub(text2, homeDir) {
|
|
8376
|
+
let s = text2;
|
|
8199
8377
|
if (homeDir) {
|
|
8200
8378
|
const home = homeDir.replace(/\/+$/, "");
|
|
8201
8379
|
s = s.split(home + "/").join("");
|
|
@@ -8544,18 +8722,18 @@ class TranscriptUsage {
|
|
|
8544
8722
|
}
|
|
8545
8723
|
const length = Math.min(size - f.offset, budget);
|
|
8546
8724
|
if (length <= 0) return 0;
|
|
8547
|
-
let
|
|
8725
|
+
let text2;
|
|
8548
8726
|
const fh = await open(file, "r").catch(() => null);
|
|
8549
8727
|
if (!fh) return 0;
|
|
8550
8728
|
try {
|
|
8551
8729
|
const buf = Buffer.alloc(length);
|
|
8552
8730
|
const { bytesRead } = await fh.read(buf, 0, length, f.offset);
|
|
8553
|
-
|
|
8731
|
+
text2 = buf.subarray(0, bytesRead).toString("utf8");
|
|
8554
8732
|
f.offset += bytesRead;
|
|
8555
8733
|
} finally {
|
|
8556
8734
|
await fh.close();
|
|
8557
8735
|
}
|
|
8558
|
-
const lines = (f.partial +
|
|
8736
|
+
const lines = (f.partial + text2).split("\n");
|
|
8559
8737
|
f.partial = lines.pop() ?? "";
|
|
8560
8738
|
for (const l of lines) this.line(f, l, ctx);
|
|
8561
8739
|
return length;
|
|
@@ -8807,8 +8985,8 @@ class InsightsService {
|
|
|
8807
8985
|
this.runTried.set(run, this.now());
|
|
8808
8986
|
let task2 = null;
|
|
8809
8987
|
for (const step of ["rebase", "push", "pr"]) {
|
|
8810
|
-
const
|
|
8811
|
-
const m =
|
|
8988
|
+
const text2 = await head(path.join(this.opts.logsDir, run, `${step}.log`), HEAD_BYTES);
|
|
8989
|
+
const m = text2 ? BRANCH.exec(text2) : null;
|
|
8812
8990
|
if (m) {
|
|
8813
8991
|
task2 = m[1];
|
|
8814
8992
|
break;
|
|
@@ -8870,8 +9048,8 @@ class InsightsService {
|
|
|
8870
9048
|
for (const dir of [inbox, path.join(inbox, "handled")]) {
|
|
8871
9049
|
const names = (await readdir(dir).catch(() => [])).filter((n) => n.endsWith(".msg")).sort().slice(-40);
|
|
8872
9050
|
for (const n of names) {
|
|
8873
|
-
const
|
|
8874
|
-
if (
|
|
9051
|
+
const text2 = await head(path.join(dir, n), 64 * 1024);
|
|
9052
|
+
if (text2) bodies.push(text2);
|
|
8875
9053
|
}
|
|
8876
9054
|
}
|
|
8877
9055
|
if (bodies.length) this.handled.set(t.id, bodies);
|
|
@@ -9118,9 +9296,9 @@ const RETRY_BASE_MS = 15e3;
|
|
|
9118
9296
|
const RETRY_MAX_MS = 5 * 6e4;
|
|
9119
9297
|
const RETRIES_PER_ROUND = 5;
|
|
9120
9298
|
const REPLY_PAGES_PER_ROUND = 10;
|
|
9121
|
-
function noteBody(
|
|
9299
|
+
function noteBody(text2, taskId) {
|
|
9122
9300
|
return taskId ? `Re: ${taskId}
|
|
9123
|
-
${
|
|
9301
|
+
${text2}` : text2;
|
|
9124
9302
|
}
|
|
9125
9303
|
function toBridgeMessage(m) {
|
|
9126
9304
|
return {
|
|
@@ -9137,17 +9315,17 @@ function toBridgeMessage(m) {
|
|
|
9137
9315
|
}
|
|
9138
9316
|
const UNANNOUNCED = "Firstmate has the message but was not woken for it yet. Wheelhouse will retry.";
|
|
9139
9317
|
const UNCERTAIN = "Wheelhouse could not confirm delivery. It is checking with the same request id.";
|
|
9140
|
-
function validateSend(requestId,
|
|
9318
|
+
function validateSend(requestId, text2, taskId) {
|
|
9141
9319
|
if (!requestId)
|
|
9142
9320
|
return { ok: false, status: 400, error: "An Idempotency-Key header is required." };
|
|
9143
|
-
if (!REQUEST_ID.test(requestId)) {
|
|
9321
|
+
if (!REQUEST_ID$1.test(requestId)) {
|
|
9144
9322
|
return {
|
|
9145
9323
|
ok: false,
|
|
9146
9324
|
status: 400,
|
|
9147
9325
|
error: "The Idempotency-Key must be 1-128 characters of A-Z a-z 0-9 . _ : - (no leading dot)."
|
|
9148
9326
|
};
|
|
9149
9327
|
}
|
|
9150
|
-
if (typeof
|
|
9328
|
+
if (typeof text2 !== "string" || !text2.trim()) {
|
|
9151
9329
|
return { ok: false, status: 400, error: "The message is empty." };
|
|
9152
9330
|
}
|
|
9153
9331
|
if (taskId !== void 0 && taskId !== null && (typeof taskId !== "string" || !TASK_ID$1.test(taskId))) {
|
|
@@ -9155,7 +9333,7 @@ function validateSend(requestId, text, taskId) {
|
|
|
9155
9333
|
}
|
|
9156
9334
|
const input = {
|
|
9157
9335
|
requestId,
|
|
9158
|
-
text:
|
|
9336
|
+
text: text2.trim(),
|
|
9159
9337
|
taskId: taskId ?? null
|
|
9160
9338
|
};
|
|
9161
9339
|
const room = isChangeRequest(input) ? ROUTE_ALLOWANCE_BYTES : 0;
|
|
@@ -9514,17 +9692,17 @@ function lettered(body) {
|
|
|
9514
9692
|
if (marks.length < 2) return null;
|
|
9515
9693
|
const then = [];
|
|
9516
9694
|
const options = marks.map((m, i) => {
|
|
9517
|
-
let
|
|
9695
|
+
let text2 = body.slice(m.end, marks[i + 1] ? marks[i + 1].at : body.length);
|
|
9518
9696
|
if (i === marks.length - 1) {
|
|
9519
|
-
const parts = sentences(
|
|
9697
|
+
const parts = sentences(text2);
|
|
9520
9698
|
while (parts.length > 1 && parts[parts.length - 1].endsWith("?")) then.unshift(parts.pop());
|
|
9521
|
-
|
|
9699
|
+
text2 = parts.join(" ");
|
|
9522
9700
|
}
|
|
9523
|
-
const rec = m.rec || isRec(
|
|
9701
|
+
const rec = m.rec || isRec(text2);
|
|
9524
9702
|
return {
|
|
9525
9703
|
id: m.letter,
|
|
9526
9704
|
label: m.letter,
|
|
9527
|
-
detail: trimEnd(
|
|
9705
|
+
detail: trimEnd(text2.replace(REC, "")) || null,
|
|
9528
9706
|
recommended: rec
|
|
9529
9707
|
};
|
|
9530
9708
|
});
|
|
@@ -9621,8 +9799,8 @@ function recommendFirst(calls) {
|
|
|
9621
9799
|
}
|
|
9622
9800
|
}
|
|
9623
9801
|
const isYesNo = (c) => c.options.length === 2 && c.options[0].id === "yes";
|
|
9624
|
-
function choicesIn(
|
|
9625
|
-
const s = tidy(
|
|
9802
|
+
function choicesIn(text2) {
|
|
9803
|
+
const s = tidy(text2 ?? "");
|
|
9626
9804
|
if (!s) return null;
|
|
9627
9805
|
let follow = 0;
|
|
9628
9806
|
const followUps = (qs) => qs.map((q) => questionCall(`then-${++follow}`, null, q, false));
|
|
@@ -9652,41 +9830,41 @@ function choicesIn(text) {
|
|
|
9652
9830
|
}
|
|
9653
9831
|
return null;
|
|
9654
9832
|
}
|
|
9655
|
-
function reportIn(
|
|
9656
|
-
for (const m of (
|
|
9833
|
+
function reportIn(text2) {
|
|
9834
|
+
for (const m of (text2 ?? "").matchAll(/[^\s()'"`]+\.md\b/g)) {
|
|
9657
9835
|
if (/(?:^|\/)data\/[^/]+\//.test(m[0])) return m[0];
|
|
9658
9836
|
}
|
|
9659
9837
|
return null;
|
|
9660
9838
|
}
|
|
9661
9839
|
const FINDINGS = /findings=(\S+)\s+file=(.+?\.txt)\b/;
|
|
9662
9840
|
const RECOMMEND = /\b(?:Firstmate\s+)?recommend(?:s|ed|ation)?(?:\s+is)?\s*[:=–—-]\s*([^\n]+?)(?:\.\s|\.$|\n|$)/i;
|
|
9663
|
-
function recommendationIn(
|
|
9664
|
-
const m =
|
|
9841
|
+
function recommendationIn(text2) {
|
|
9842
|
+
const m = text2 ? RECOMMEND.exec(text2) : null;
|
|
9665
9843
|
return m?.[1]?.trim() || null;
|
|
9666
9844
|
}
|
|
9667
|
-
function withoutRecommendation(
|
|
9668
|
-
const m = RECOMMEND.exec(
|
|
9669
|
-
if (!m) return
|
|
9670
|
-
const out = (
|
|
9671
|
-
return out ||
|
|
9845
|
+
function withoutRecommendation(text2) {
|
|
9846
|
+
const m = RECOMMEND.exec(text2);
|
|
9847
|
+
if (!m) return text2;
|
|
9848
|
+
const out = (text2.slice(0, m.index) + text2.slice(m.index + m[0].length)).trim();
|
|
9849
|
+
return out || text2;
|
|
9672
9850
|
}
|
|
9673
|
-
function reasonOf(
|
|
9674
|
-
const r =
|
|
9675
|
-
return r ? r.charAt(0).toUpperCase() + r.slice(1) :
|
|
9851
|
+
function reasonOf(text2) {
|
|
9852
|
+
const r = text2.replace(/^(?:FIX|KEEP|DEFER\w*|DISCARD|APPROVE|SKIP|MERGE)\b(?:\s+it)?[\s.:,;–—-]*/i, "").trim();
|
|
9853
|
+
return r ? r.charAt(0).toUpperCase() + r.slice(1) : text2;
|
|
9676
9854
|
}
|
|
9677
|
-
function choiceOf(
|
|
9678
|
-
const v = verdictOf(
|
|
9855
|
+
function choiceOf(text2) {
|
|
9856
|
+
const v = verdictOf(text2);
|
|
9679
9857
|
if (v === "Fix it") return "fix";
|
|
9680
9858
|
if (v === "Keep as is") return "approve";
|
|
9681
9859
|
if (v === "Defer" || v === "No change") return "skip";
|
|
9682
|
-
if (/\b(?:approve|merge|go ahead|proceed|accept|ship it|yes)\b/i.test(
|
|
9683
|
-
if (/\b(?:fix|change|rework)\b/i.test(
|
|
9684
|
-
if (/\b(?:skip|defer|later|hold off|leave it)\b/i.test(
|
|
9860
|
+
if (/\b(?:approve|merge|go ahead|proceed|accept|ship it|yes)\b/i.test(text2)) return "approve";
|
|
9861
|
+
if (/\b(?:fix|change|rework)\b/i.test(text2)) return "fix";
|
|
9862
|
+
if (/\b(?:skip|defer|later|hold off|leave it)\b/i.test(text2)) return "skip";
|
|
9685
9863
|
return null;
|
|
9686
9864
|
}
|
|
9687
|
-
function findingRecommendations(
|
|
9865
|
+
function findingRecommendations(text2) {
|
|
9688
9866
|
const out = /* @__PURE__ */ new Map();
|
|
9689
|
-
for (const block of
|
|
9867
|
+
for (const block of text2.split(/\n\s*\n/)) {
|
|
9690
9868
|
const id = /^id:\s?(.*)$/m.exec(block)?.[1]?.trim();
|
|
9691
9869
|
const rec = /^recommend(?:ation)?:\s?(.*)$/m.exec(block)?.[1]?.trim().replace(/\.$/, "");
|
|
9692
9870
|
if (id && rec) out.set(id, rec);
|
|
@@ -9694,13 +9872,13 @@ function findingRecommendations(text) {
|
|
|
9694
9872
|
return out;
|
|
9695
9873
|
}
|
|
9696
9874
|
const META = /\[(?:key|at)=[^\]]*\]/g;
|
|
9697
|
-
const reportOf = (
|
|
9698
|
-
const p = reportIn(
|
|
9875
|
+
const reportOf = (text2) => {
|
|
9876
|
+
const p = reportIn(text2);
|
|
9699
9877
|
return p ? { path: p, url: null } : null;
|
|
9700
9878
|
};
|
|
9701
9879
|
const iso = (ts) => new Date(ts * 1e3).toISOString();
|
|
9702
|
-
function isoOf(
|
|
9703
|
-
const ms =
|
|
9880
|
+
function isoOf(text2) {
|
|
9881
|
+
const ms = text2 ? Date.parse(text2) : NaN;
|
|
9704
9882
|
return Number.isNaN(ms) ? null : new Date(ms).toISOString();
|
|
9705
9883
|
}
|
|
9706
9884
|
function openingLine(ledger, key) {
|
|
@@ -9751,9 +9929,9 @@ function decisionCards(t, src) {
|
|
|
9751
9929
|
let recommendation = recommendationIn(raw);
|
|
9752
9930
|
if (m) {
|
|
9753
9931
|
const ids = m[1].split(",").filter(Boolean);
|
|
9754
|
-
const
|
|
9755
|
-
const all =
|
|
9756
|
-
const recs =
|
|
9932
|
+
const text2 = src.findings(t.id, m[2]);
|
|
9933
|
+
const all = text2 ? parseFindings(text2) : [];
|
|
9934
|
+
const recs = text2 ? findingRecommendations(text2) : /* @__PURE__ */ new Map();
|
|
9757
9935
|
const raised = ids.map(
|
|
9758
9936
|
(id) => all.find((f) => f.id === id) ?? {
|
|
9759
9937
|
id,
|
|
@@ -9915,7 +10093,7 @@ function mateCards(rec, src) {
|
|
|
9915
10093
|
evidence: { ...c.evidence, ...where },
|
|
9916
10094
|
secondMate: { id: rec.id, taskId: null, taskTitle: null }
|
|
9917
10095
|
}));
|
|
9918
|
-
const home = (
|
|
10096
|
+
const home = (text2) => scrub(scrub(text2, rec.home), src.homeDir);
|
|
9919
10097
|
const out = [...own];
|
|
9920
10098
|
rec.decisions.forEach((d, i) => {
|
|
9921
10099
|
const hold = d.verb === "captain-hold" || d.source === "backlog";
|
|
@@ -9990,8 +10168,8 @@ class FindingsFiles {
|
|
|
9990
10168
|
return;
|
|
9991
10169
|
}
|
|
9992
10170
|
if (this.cache.get(resolved)?.mtimeMs === st.mtimeMs) return;
|
|
9993
|
-
const
|
|
9994
|
-
this.cache.set(resolved, { mtimeMs: st.mtimeMs, text });
|
|
10171
|
+
const text2 = await readFile(resolved, "utf8").catch(() => null);
|
|
10172
|
+
this.cache.set(resolved, { mtimeMs: st.mtimeMs, text: text2 });
|
|
9995
10173
|
})
|
|
9996
10174
|
);
|
|
9997
10175
|
}
|
|
@@ -10005,8 +10183,8 @@ function findingsWanted(tasks, row, ledger) {
|
|
|
10005
10183
|
const out = [];
|
|
10006
10184
|
for (const t of tasks) {
|
|
10007
10185
|
for (const d of row(t.id)?.openDecisions ?? []) {
|
|
10008
|
-
const
|
|
10009
|
-
const m = FINDINGS.exec(
|
|
10186
|
+
const text2 = openingLine(ledger(t.id), d.key)?.text ?? d.summary ?? "";
|
|
10187
|
+
const m = FINDINGS.exec(text2) ?? FINDINGS.exec(d.summary ?? "");
|
|
10010
10188
|
if (m) out.push({ taskId: t.id, file: m[2] });
|
|
10011
10189
|
}
|
|
10012
10190
|
}
|
|
@@ -10135,8 +10313,8 @@ class InboxService {
|
|
|
10135
10313
|
if (!p.ok) return { ok: false, status: 400, error: p.error };
|
|
10136
10314
|
line = p.line;
|
|
10137
10315
|
}
|
|
10138
|
-
const
|
|
10139
|
-
const valid = validateSend(requestId,
|
|
10316
|
+
const text2 = closing ? closeText(card, note2 || null) : answerText(card, choice, note2 || null, decided ? null : line, decided || null);
|
|
10317
|
+
const valid = validateSend(requestId, text2, card.taskId);
|
|
10140
10318
|
if (!valid.ok) return valid;
|
|
10141
10319
|
const sent = await messenger.send(valid.input);
|
|
10142
10320
|
if (sent.ok && sent.message.delivery !== "failed") {
|
|
@@ -10256,7 +10434,7 @@ class AnsweredLog {
|
|
|
10256
10434
|
return this.queued;
|
|
10257
10435
|
}
|
|
10258
10436
|
async write() {
|
|
10259
|
-
const
|
|
10437
|
+
const text2 = `${JSON.stringify(
|
|
10260
10438
|
{ schema: ANSWERED_SCHEMA, home: this.home, answered: this.records },
|
|
10261
10439
|
null,
|
|
10262
10440
|
" "
|
|
@@ -10265,7 +10443,7 @@ class AnsweredLog {
|
|
|
10265
10443
|
await mkdir(path.dirname(this.file), { recursive: true });
|
|
10266
10444
|
const tmp = `${this.file}.${randomBytes(6).toString("hex")}.tmp`;
|
|
10267
10445
|
try {
|
|
10268
|
-
await writeFile(tmp,
|
|
10446
|
+
await writeFile(tmp, text2, { mode: 384 });
|
|
10269
10447
|
await rename(tmp, this.file);
|
|
10270
10448
|
} catch (e) {
|
|
10271
10449
|
await rm(tmp, { force: true });
|
|
@@ -10318,12 +10496,12 @@ class ReactionStore {
|
|
|
10318
10496
|
return write2;
|
|
10319
10497
|
}
|
|
10320
10498
|
async write() {
|
|
10321
|
-
const
|
|
10499
|
+
const text2 = `${JSON.stringify({ schema: REACTIONS_SCHEMA, home: this.home, liked: this.ids }, null, " ")}
|
|
10322
10500
|
`;
|
|
10323
10501
|
await mkdir(path.dirname(this.file), { recursive: true });
|
|
10324
10502
|
const tmp = `${this.file}.${randomBytes(6).toString("hex")}.tmp`;
|
|
10325
10503
|
try {
|
|
10326
|
-
await writeFile(tmp,
|
|
10504
|
+
await writeFile(tmp, text2, { mode: 384 });
|
|
10327
10505
|
await rename(tmp, this.file);
|
|
10328
10506
|
} catch (e) {
|
|
10329
10507
|
await rm(tmp, { force: true });
|
|
@@ -10490,7 +10668,7 @@ class WatchStore {
|
|
|
10490
10668
|
save() {
|
|
10491
10669
|
const file = this.file;
|
|
10492
10670
|
if (!file) return Promise.resolve();
|
|
10493
|
-
const
|
|
10671
|
+
const text2 = `${JSON.stringify(
|
|
10494
10672
|
{ schema: WATCH_SCHEMA, projects: Object.fromEntries(this.projects) },
|
|
10495
10673
|
null,
|
|
10496
10674
|
" "
|
|
@@ -10500,7 +10678,7 @@ class WatchStore {
|
|
|
10500
10678
|
await mkdir(path.dirname(file), { recursive: true });
|
|
10501
10679
|
const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
|
|
10502
10680
|
try {
|
|
10503
|
-
await writeFile(tmp,
|
|
10681
|
+
await writeFile(tmp, text2, { mode: 384 });
|
|
10504
10682
|
await rename(tmp, file);
|
|
10505
10683
|
} catch (e) {
|
|
10506
10684
|
await rm(tmp, { force: true });
|
|
@@ -10576,8 +10754,8 @@ class IssueWatcher {
|
|
|
10576
10754
|
*/
|
|
10577
10755
|
async handOver(issue, projectId) {
|
|
10578
10756
|
if (!this.opts.send) return false;
|
|
10579
|
-
const
|
|
10580
|
-
const r = await this.opts.send({ requestId: issueRequestId(issue.url), text, taskId: null });
|
|
10757
|
+
const text2 = `${handoffText(issue, projectId)} Sent by Wheelhouse's issue watcher (auto pick-up).`;
|
|
10758
|
+
const r = await this.opts.send({ requestId: issueRequestId(issue.url), text: text2, taskId: null });
|
|
10581
10759
|
if (r.ok) return r.message.delivery !== "failed";
|
|
10582
10760
|
if (r.status === 422) return true;
|
|
10583
10761
|
this.opts.log?.(`Issue watcher: could not hand ${issue.url} to Firstmate: ${r.error}`);
|
|
@@ -10760,14 +10938,14 @@ async function loadOne(dir, id, r, o = {}) {
|
|
|
10760
10938
|
});
|
|
10761
10939
|
if (!ID$1.test(id)) return fail(`"${id}" is not a plugin id.`);
|
|
10762
10940
|
const root = path.join(dir, id);
|
|
10763
|
-
let
|
|
10941
|
+
let text2 = null;
|
|
10764
10942
|
let readError = "";
|
|
10765
10943
|
try {
|
|
10766
|
-
|
|
10944
|
+
text2 = await readFile(manifestPath(root), "utf8");
|
|
10767
10945
|
} catch (e) {
|
|
10768
10946
|
readError = message$2(e);
|
|
10769
10947
|
}
|
|
10770
|
-
const parsed =
|
|
10948
|
+
const parsed = text2 === null ? null : parseManifest(text2);
|
|
10771
10949
|
if (parsed?.ok) m = parsed.manifest;
|
|
10772
10950
|
if (r && !r.enabled) return { ok: false, status: status(id, r, m, "disabled", null) };
|
|
10773
10951
|
if (!parsed) return fail(`its manifest could not be read: ${readError}`);
|
|
@@ -11581,7 +11759,7 @@ class PluginRegistry {
|
|
|
11581
11759
|
if (hit?.value && !hit.pending && now - hit.at < hit.ttl) return Promise.resolve(hit.value);
|
|
11582
11760
|
const stale = hit?.value?.available && now - hit.at < hit.ttl + MAX_STALE_MS ? hit.value : null;
|
|
11583
11761
|
if (hit?.pending) return stale ? Promise.resolve(stale) : hit.pending;
|
|
11584
|
-
const
|
|
11762
|
+
const pending2 = this.call(plugin, provider, scope).then((value) => {
|
|
11585
11763
|
const ttl = value.available ? provider.ttlMs : Math.min(provider.ttlMs, MAX_FAILURE_TTL_MS);
|
|
11586
11764
|
const at = this.now();
|
|
11587
11765
|
for (const [k, e] of this.cache) {
|
|
@@ -11594,9 +11772,9 @@ class PluginRegistry {
|
|
|
11594
11772
|
at: hit?.at ?? now,
|
|
11595
11773
|
ttl: hit?.ttl ?? 0,
|
|
11596
11774
|
value: hit?.value ?? null,
|
|
11597
|
-
pending
|
|
11775
|
+
pending: pending2
|
|
11598
11776
|
});
|
|
11599
|
-
return stale ? Promise.resolve(stale) :
|
|
11777
|
+
return stale ? Promise.resolve(stale) : pending2;
|
|
11600
11778
|
}
|
|
11601
11779
|
async call(plugin, provider, scope) {
|
|
11602
11780
|
const timeoutMs = Math.min(
|
|
@@ -11861,8 +12039,8 @@ class ServiceManager {
|
|
|
11861
12039
|
* launches of one service share one start.
|
|
11862
12040
|
*/
|
|
11863
12041
|
launch(key, spec) {
|
|
11864
|
-
const
|
|
11865
|
-
if (
|
|
12042
|
+
const pending2 = this.launches.get(key);
|
|
12043
|
+
if (pending2) return pending2.done;
|
|
11866
12044
|
const refused = refuseSpec(spec);
|
|
11867
12045
|
if (refused) {
|
|
11868
12046
|
return Promise.resolve({
|
|
@@ -12026,8 +12204,8 @@ function tail(file) {
|
|
|
12026
12204
|
const size = fstatSync(fd).size;
|
|
12027
12205
|
const buf = Buffer.alloc(Math.min(size, LOG_TAIL));
|
|
12028
12206
|
const n = readSync(fd, buf, 0, buf.length, size - buf.length);
|
|
12029
|
-
const
|
|
12030
|
-
return size > LOG_TAIL ? `…${
|
|
12207
|
+
const text2 = buf.subarray(0, n).toString("utf8");
|
|
12208
|
+
return size > LOG_TAIL ? `…${text2}` : text2;
|
|
12031
12209
|
} catch {
|
|
12032
12210
|
return "";
|
|
12033
12211
|
} finally {
|
|
@@ -12223,9 +12401,9 @@ class McpHttpClient {
|
|
|
12223
12401
|
class Expired extends Error {
|
|
12224
12402
|
}
|
|
12225
12403
|
const isRecord$1 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
12226
|
-
function parseJson(
|
|
12404
|
+
function parseJson(text2) {
|
|
12227
12405
|
try {
|
|
12228
|
-
return JSON.parse(
|
|
12406
|
+
return JSON.parse(text2);
|
|
12229
12407
|
} catch {
|
|
12230
12408
|
throw new McpError("the MCP server answered with something that is not JSON.");
|
|
12231
12409
|
}
|
|
@@ -12711,13 +12889,13 @@ function signedBy(key, csp, sig) {
|
|
|
12711
12889
|
return got.length === want.length && timingSafeEqual(got, want);
|
|
12712
12890
|
}
|
|
12713
12891
|
const sandboxHandler = (key, hosted2 = () => null, hostedPage = () => null) => (req, res) => {
|
|
12714
|
-
const send2 = (status2,
|
|
12892
|
+
const send2 = (status2, text2) => {
|
|
12715
12893
|
res.writeHead(status2, {
|
|
12716
12894
|
"content-type": "text/plain; charset=utf-8",
|
|
12717
12895
|
"cache-control": "no-store",
|
|
12718
12896
|
"x-content-type-options": "nosniff"
|
|
12719
12897
|
});
|
|
12720
|
-
res.end(
|
|
12898
|
+
res.end(text2);
|
|
12721
12899
|
};
|
|
12722
12900
|
const there = hosted2();
|
|
12723
12901
|
const atHosted = !!there && (req.headers.host ?? "").toLowerCase() === there.host;
|
|
@@ -12927,13 +13105,13 @@ class ConsentStore {
|
|
|
12927
13105
|
projects: Object.fromEntries(this.projects),
|
|
12928
13106
|
...this.commands.size ? { commands: Object.fromEntries(this.commands) } : {}
|
|
12929
13107
|
};
|
|
12930
|
-
const
|
|
13108
|
+
const text2 = `${JSON.stringify(doc, null, " ")}
|
|
12931
13109
|
`;
|
|
12932
13110
|
const write2 = this.writing.then(async () => {
|
|
12933
13111
|
await mkdir(path.dirname(this.file), { recursive: true });
|
|
12934
13112
|
const tmp = `${this.file}.${randomBytes(6).toString("hex")}.tmp`;
|
|
12935
13113
|
try {
|
|
12936
|
-
await writeFile(tmp,
|
|
13114
|
+
await writeFile(tmp, text2, { mode: 384 });
|
|
12937
13115
|
await rename(tmp, this.file);
|
|
12938
13116
|
} catch (e) {
|
|
12939
13117
|
await rm(tmp, { force: true });
|
|
@@ -13054,7 +13232,7 @@ class ReachedStore {
|
|
|
13054
13232
|
return this.queued;
|
|
13055
13233
|
}
|
|
13056
13234
|
async write() {
|
|
13057
|
-
const
|
|
13235
|
+
const text2 = `${JSON.stringify(
|
|
13058
13236
|
{ schema: REACHED_SCHEMA, home: this.home, tasks: [...this.entries.values()] },
|
|
13059
13237
|
null,
|
|
13060
13238
|
" "
|
|
@@ -13063,7 +13241,7 @@ class ReachedStore {
|
|
|
13063
13241
|
await mkdir(path.dirname(this.file), { recursive: true });
|
|
13064
13242
|
const tmp = `${this.file}.${randomBytes(6).toString("hex")}.tmp`;
|
|
13065
13243
|
try {
|
|
13066
|
-
await writeFile(tmp,
|
|
13244
|
+
await writeFile(tmp, text2, { mode: 384 });
|
|
13067
13245
|
await rename(tmp, this.file);
|
|
13068
13246
|
} catch (e) {
|
|
13069
13247
|
await rm(tmp, { force: true });
|
|
@@ -13073,7 +13251,7 @@ class ReachedStore {
|
|
|
13073
13251
|
}
|
|
13074
13252
|
const PROJECT_FILE = ".wheelhouse.yaml";
|
|
13075
13253
|
const PROJECT_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
13076
|
-
const digestOf = (
|
|
13254
|
+
const digestOf = (text2) => createHash("sha256").update(text2).digest("hex");
|
|
13077
13255
|
async function defaultRef(dir, deps) {
|
|
13078
13256
|
const head2 = await deps.git(dir, [
|
|
13079
13257
|
"symbolic-ref",
|
|
@@ -13155,8 +13333,8 @@ async function readCaptainFile(configDir, projectId) {
|
|
|
13155
13333
|
problem: `The file is larger than ${MAX_FILE_BYTES$1 / 1024} KiB.`
|
|
13156
13334
|
};
|
|
13157
13335
|
}
|
|
13158
|
-
const
|
|
13159
|
-
return { state: "read", location: file, text, digest: digestOf(
|
|
13336
|
+
const text2 = buf.subarray(0, bytesRead).toString("utf8");
|
|
13337
|
+
return { state: "read", location: file, text: text2, digest: digestOf(text2), problem: null };
|
|
13160
13338
|
} catch (e) {
|
|
13161
13339
|
return { ...none, state: "unreadable", problem: `Could not read it: ${e.message}` };
|
|
13162
13340
|
} finally {
|
|
@@ -13204,15 +13382,15 @@ async function readEditorFile(target, file) {
|
|
|
13204
13382
|
problem: `The file is larger than ${MAX_FILE_BYTES$1 / 1024} KiB.`
|
|
13205
13383
|
};
|
|
13206
13384
|
}
|
|
13207
|
-
const
|
|
13208
|
-
return { target, exists: true, text, digest: digestOf(
|
|
13385
|
+
const text2 = buf.subarray(0, bytesRead).toString("utf8");
|
|
13386
|
+
return { target, exists: true, text: text2, digest: digestOf(text2), location: file, problem: null };
|
|
13209
13387
|
} catch (e) {
|
|
13210
13388
|
return { ...none, exists: true, problem: `Could not read it: ${e.message}` };
|
|
13211
13389
|
} finally {
|
|
13212
13390
|
await fh?.close();
|
|
13213
13391
|
}
|
|
13214
13392
|
}
|
|
13215
|
-
async function writeEditorFile(target, file,
|
|
13393
|
+
async function writeEditorFile(target, file, text2, baseDigest) {
|
|
13216
13394
|
const now = await readEditorFile(target, file);
|
|
13217
13395
|
if (now.problem && now.exists) return { ok: false, status: 409, message: now.problem };
|
|
13218
13396
|
if (now.digest !== baseDigest) {
|
|
@@ -13227,7 +13405,7 @@ async function writeEditorFile(target, file, text, baseDigest) {
|
|
|
13227
13405
|
if (target === "captain") await mkdir(dir, { recursive: true });
|
|
13228
13406
|
const tmp = path.join(dir, `.${path.basename(file)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
13229
13407
|
try {
|
|
13230
|
-
await writeFile(tmp,
|
|
13408
|
+
await writeFile(tmp, text2, { mode: 420, flag: "wx" });
|
|
13231
13409
|
await rename(tmp, file);
|
|
13232
13410
|
} catch (e) {
|
|
13233
13411
|
await rm(tmp, { force: true });
|
|
@@ -13240,7 +13418,7 @@ async function writeEditorFile(target, file, text, baseDigest) {
|
|
|
13240
13418
|
message: `Wheelhouse could not save the file: ${e.message}`
|
|
13241
13419
|
};
|
|
13242
13420
|
}
|
|
13243
|
-
return { ok: true, digest: digestOf(
|
|
13421
|
+
return { ok: true, digest: digestOf(text2) };
|
|
13244
13422
|
}
|
|
13245
13423
|
class Scheduler {
|
|
13246
13424
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -13746,16 +13924,16 @@ class PassageService {
|
|
|
13746
13924
|
terminal: (r) => r.merged && !!r.refs.mergeCommit
|
|
13747
13925
|
};
|
|
13748
13926
|
const s = this.refs.status(job.key)?.result;
|
|
13749
|
-
const
|
|
13927
|
+
const pending2 = (summary2, state = "waiting") => ({
|
|
13750
13928
|
ok: false,
|
|
13751
13929
|
internal: { ...waiting(summary2, state), refsJob: job }
|
|
13752
13930
|
});
|
|
13753
|
-
if (!s) return
|
|
13754
|
-
if (s.problem) return
|
|
13755
|
-
if (need === "merge.commit" && !f.merged && !s.merged) return
|
|
13931
|
+
if (!s) return pending2("Looking up the pull request’s commits.");
|
|
13932
|
+
if (s.problem) return pending2(`Can't read the pull request: ${s.problem}.`, "unknown");
|
|
13933
|
+
if (need === "merge.commit" && !f.merged && !s.merged) return pending2("Waits for the merge.");
|
|
13756
13934
|
const sha = need === "merge.commit" ? s.refs.mergeCommit : s.refs.prHead;
|
|
13757
13935
|
if (!sha) {
|
|
13758
|
-
return
|
|
13936
|
+
return pending2(
|
|
13759
13937
|
need === "merge.commit" ? "GitHub reports no merge commit yet." : "GitHub reports no head commit."
|
|
13760
13938
|
);
|
|
13761
13939
|
}
|
|
@@ -13975,9 +14153,9 @@ class PassageService {
|
|
|
13975
14153
|
};
|
|
13976
14154
|
}
|
|
13977
14155
|
/** Validate an edited file as it would apply (shape and references). */
|
|
13978
|
-
draft(projectId, target,
|
|
14156
|
+
draft(projectId, target, text2) {
|
|
13979
14157
|
const l = this.loaded.get(projectId);
|
|
13980
|
-
const r = parsePassage(
|
|
14158
|
+
const r = parsePassage(text2, {
|
|
13981
14159
|
kind: "overlay",
|
|
13982
14160
|
captain: target === "captain",
|
|
13983
14161
|
project: projectId
|
|
@@ -14004,7 +14182,7 @@ class PassageService {
|
|
|
14004
14182
|
return { errors, both, track };
|
|
14005
14183
|
}
|
|
14006
14184
|
/** Save an edited file when it still matches what the editor loaded, then re-read the passage. */
|
|
14007
|
-
async saveFile(projectId, target,
|
|
14185
|
+
async saveFile(projectId, target, text2, baseDigest) {
|
|
14008
14186
|
await this.load(projectId);
|
|
14009
14187
|
const l = this.loaded.get(projectId);
|
|
14010
14188
|
const file = this.filePath(projectId, l, target);
|
|
@@ -14015,7 +14193,7 @@ class PassageService {
|
|
|
14015
14193
|
message: target === "project" ? l?.cloneProblem ?? "Firstmate has no clone of this project." : this.opts.configProblem ?? "There is no captain-owned Wheelhouse config directory."
|
|
14016
14194
|
};
|
|
14017
14195
|
}
|
|
14018
|
-
const d = this.draft(projectId, target,
|
|
14196
|
+
const d = this.draft(projectId, target, text2);
|
|
14019
14197
|
if (d.errors.length) {
|
|
14020
14198
|
return {
|
|
14021
14199
|
ok: false,
|
|
@@ -14024,7 +14202,7 @@ class PassageService {
|
|
|
14024
14202
|
errors: d.errors
|
|
14025
14203
|
};
|
|
14026
14204
|
}
|
|
14027
|
-
const w = await writeEditorFile(target, file,
|
|
14205
|
+
const w = await writeEditorFile(target, file, text2, baseDigest);
|
|
14028
14206
|
if (w.ok) {
|
|
14029
14207
|
this.loaded.delete(projectId);
|
|
14030
14208
|
await this.load(projectId);
|
|
@@ -14042,7 +14220,7 @@ class PassageService {
|
|
|
14042
14220
|
* captain ticked the box under, and it is still exactly what the file runs;
|
|
14043
14221
|
* nothing is recorded or cached.
|
|
14044
14222
|
*/
|
|
14045
|
-
async dryRun(projectId, target,
|
|
14223
|
+
async dryRun(projectId, target, text2, taskId, opts) {
|
|
14046
14224
|
const l = this.loaded.get(projectId);
|
|
14047
14225
|
const seen = this.lastFacts.get(taskId);
|
|
14048
14226
|
if (!seen || seen.projectId !== projectId) {
|
|
@@ -14052,7 +14230,7 @@ class PassageService {
|
|
|
14052
14230
|
message: "Wheelhouse has not seen that task in this project recently."
|
|
14053
14231
|
};
|
|
14054
14232
|
}
|
|
14055
|
-
const r = parsePassage(
|
|
14233
|
+
const r = parsePassage(text2, {
|
|
14056
14234
|
kind: "overlay",
|
|
14057
14235
|
captain: target === "captain",
|
|
14058
14236
|
project: projectId
|
|
@@ -14386,11 +14564,11 @@ async function call(transport, token, version2, method, route, what, body) {
|
|
|
14386
14564
|
await sleep(Math.min(10, Math.max(0.1, Number(j.retry_after) || 1)) * 1e3);
|
|
14387
14565
|
continue;
|
|
14388
14566
|
}
|
|
14389
|
-
const
|
|
14567
|
+
const text2 = await res.text().catch(() => "");
|
|
14390
14568
|
if (!res.ok) {
|
|
14391
14569
|
let said = "";
|
|
14392
14570
|
try {
|
|
14393
|
-
said = str$1(JSON.parse(
|
|
14571
|
+
said = str$1(JSON.parse(text2).message) ?? "";
|
|
14394
14572
|
} catch {
|
|
14395
14573
|
}
|
|
14396
14574
|
throw new DiscordError(
|
|
@@ -14398,7 +14576,7 @@ async function call(transport, token, version2, method, route, what, body) {
|
|
|
14398
14576
|
redact(`Discord would not ${what} (${res.status}${said ? `: ${said}` : ""}).`)
|
|
14399
14577
|
);
|
|
14400
14578
|
}
|
|
14401
|
-
return
|
|
14579
|
+
return text2 ? JSON.parse(text2) : void 0;
|
|
14402
14580
|
}
|
|
14403
14581
|
}
|
|
14404
14582
|
function components(buttons) {
|
|
@@ -14690,7 +14868,7 @@ class DiscordAdapter {
|
|
|
14690
14868
|
"add a reaction"
|
|
14691
14869
|
);
|
|
14692
14870
|
}
|
|
14693
|
-
async ack(e,
|
|
14871
|
+
async ack(e, text2) {
|
|
14694
14872
|
const at = e.handle.indexOf(":");
|
|
14695
14873
|
const id = e.handle.slice(0, at);
|
|
14696
14874
|
const token = e.handle.slice(at + 1);
|
|
@@ -14702,7 +14880,7 @@ class DiscordAdapter {
|
|
|
14702
14880
|
`/interactions/${id}/${token}/callback`,
|
|
14703
14881
|
"acknowledge a button",
|
|
14704
14882
|
// 4 with the ephemeral flag answers only the presser; 6 says the message is about to change.
|
|
14705
|
-
|
|
14883
|
+
text2 ? { type: 4, data: { content: text2, flags: 64 } } : { type: 6 }
|
|
14706
14884
|
);
|
|
14707
14885
|
}
|
|
14708
14886
|
}
|
|
@@ -14711,8 +14889,8 @@ const GATEWAY_CHANNELS = [
|
|
|
14711
14889
|
];
|
|
14712
14890
|
const DEFAULT_GATEWAY_ALERTS = ["question", "pr-green", "stuck"];
|
|
14713
14891
|
const PAIRING_MS = 10 * 6e4;
|
|
14714
|
-
function normaliseCode(
|
|
14715
|
-
return
|
|
14892
|
+
function normaliseCode(text2) {
|
|
14893
|
+
return text2.replace(/[\s-]/g, "").toUpperCase();
|
|
14716
14894
|
}
|
|
14717
14895
|
const ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
14718
14896
|
const CODE_LENGTH = 8;
|
|
@@ -14755,9 +14933,9 @@ class Pairing {
|
|
|
14755
14933
|
* account that is not paired, anything else counts as a wrong try; the
|
|
14756
14934
|
* paired account's ordinary messages (`count: false`) do not.
|
|
14757
14935
|
*/
|
|
14758
|
-
offer(
|
|
14936
|
+
offer(text2, { count = true } = {}) {
|
|
14759
14937
|
if (!this.open() || !this.code) return "closed";
|
|
14760
|
-
const given = Buffer.from(normaliseCode(
|
|
14938
|
+
const given = Buffer.from(normaliseCode(text2));
|
|
14761
14939
|
const want = Buffer.from(this.code);
|
|
14762
14940
|
if (given.length === want.length && timingSafeEqual(given, want)) {
|
|
14763
14941
|
this.code = null;
|
|
@@ -14902,14 +15080,14 @@ const HELP_TEXT = [
|
|
|
14902
15080
|
"help: this message.",
|
|
14903
15081
|
"Questions Firstmate asks in its own session, and its permission prompts, are answered at the keyboard only."
|
|
14904
15082
|
].join("\n");
|
|
14905
|
-
function localCommand(
|
|
14906
|
-
const t =
|
|
15083
|
+
function localCommand(text2) {
|
|
15084
|
+
const t = text2.trim().toLowerCase();
|
|
14907
15085
|
return t === "status" || t === "help" ? t : null;
|
|
14908
15086
|
}
|
|
14909
|
-
function splitText(
|
|
15087
|
+
function splitText(text2, limit) {
|
|
14910
15088
|
const out = [];
|
|
14911
15089
|
let cur = "";
|
|
14912
|
-
for (const line of
|
|
15090
|
+
for (const line of text2.split("\n")) {
|
|
14913
15091
|
let rest2 = line;
|
|
14914
15092
|
while (rest2.length > limit) {
|
|
14915
15093
|
if (cur) {
|
|
@@ -14967,11 +15145,11 @@ function parseChannel(v, fallback) {
|
|
|
14967
15145
|
titlesOnly: typeof v.titlesOnly === "boolean" ? v.titlesOnly : fallback.titlesOnly
|
|
14968
15146
|
};
|
|
14969
15147
|
}
|
|
14970
|
-
async function writeAtomic(file,
|
|
15148
|
+
async function writeAtomic(file, text2) {
|
|
14971
15149
|
await mkdir(path.dirname(file), { recursive: true, mode: 448 });
|
|
14972
15150
|
const tmp = `${file}.tmp-${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
14973
15151
|
try {
|
|
14974
|
-
await writeFile(tmp,
|
|
15152
|
+
await writeFile(tmp, text2, { mode: 384 });
|
|
14975
15153
|
await rename(tmp, file);
|
|
14976
15154
|
} catch (e) {
|
|
14977
15155
|
await rm(tmp, { force: true });
|
|
@@ -14994,16 +15172,16 @@ class GatewaySettings {
|
|
|
14994
15172
|
/** The settings, with defaults for anything missing; an unreadable file reads as the defaults, with why. */
|
|
14995
15173
|
async read() {
|
|
14996
15174
|
const settings = defaultSettings();
|
|
14997
|
-
let
|
|
15175
|
+
let text2;
|
|
14998
15176
|
try {
|
|
14999
|
-
|
|
15177
|
+
text2 = await readFile(this.file, "utf8");
|
|
15000
15178
|
} catch (e) {
|
|
15001
15179
|
if (e.code === "ENOENT") return { settings, error: null };
|
|
15002
15180
|
return { settings, error: `${this.file} could not be read: ${e.message}` };
|
|
15003
15181
|
}
|
|
15004
15182
|
let parsed;
|
|
15005
15183
|
try {
|
|
15006
|
-
parsed = JSON.parse(
|
|
15184
|
+
parsed = JSON.parse(text2);
|
|
15007
15185
|
} catch {
|
|
15008
15186
|
return { settings, error: `${this.file} is not valid JSON.` };
|
|
15009
15187
|
}
|
|
@@ -15343,7 +15521,7 @@ class Gateway {
|
|
|
15343
15521
|
await this.change(channel, (s) => s.paired && (s.paired.dm = e.chat));
|
|
15344
15522
|
const peer = { id: captain.id, dm: e.chat };
|
|
15345
15523
|
const ref = { chat: e.chat, id: e.id };
|
|
15346
|
-
const say = (
|
|
15524
|
+
const say = (text22) => this.post(channel, adapter, peer, notice(text22), ref);
|
|
15347
15525
|
const command = localCommand(e.text);
|
|
15348
15526
|
if (command) {
|
|
15349
15527
|
this.log(channel, { event: "accept", from: e.from, id: e.id, what: command });
|
|
@@ -15352,8 +15530,8 @@ class Gateway {
|
|
|
15352
15530
|
);
|
|
15353
15531
|
return;
|
|
15354
15532
|
}
|
|
15355
|
-
const
|
|
15356
|
-
if (!
|
|
15533
|
+
const text2 = e.text.trim();
|
|
15534
|
+
if (!text2) {
|
|
15357
15535
|
this.log(channel, { event: "refuse", from: e.from, id: e.id, reason: "no text" });
|
|
15358
15536
|
if (e.extras)
|
|
15359
15537
|
await say(
|
|
@@ -15364,7 +15542,7 @@ class Gateway {
|
|
|
15364
15542
|
const requestId = `${channel}:${e.id}`;
|
|
15365
15543
|
const taskId = e.inReplyTo ? this.deps.record.sentAt(e.inReplyTo)?.taskId ?? null : null;
|
|
15366
15544
|
const valid = validateSend(requestId, `${provenance(label(channel))}
|
|
15367
|
-
${
|
|
15545
|
+
${text2}`, taskId);
|
|
15368
15546
|
if (!valid.ok) {
|
|
15369
15547
|
this.log(channel, { event: "refuse", from: e.from, id: e.id, reason: valid.error });
|
|
15370
15548
|
await say(valid.error);
|
|
@@ -15540,10 +15718,10 @@ ${text}`, taskId);
|
|
|
15540
15718
|
await this.deps.record.save();
|
|
15541
15719
|
if (!ref) return;
|
|
15542
15720
|
const sent = this.deps.record.sentAt(ref);
|
|
15543
|
-
const
|
|
15721
|
+
const text2 = sent?.text ? `${sent.text}
|
|
15544
15722
|
|
|
15545
15723
|
✓ ${outcome.settled}` : `✓ ${outcome.settled}`;
|
|
15546
|
-
await adapter.update(ref, { text, buttons: (sent?.links ?? []).map((l) => ({ ...l })) }).catch((err) => this.log(channel, { event: "error", reason: err.message }));
|
|
15724
|
+
await adapter.update(ref, { text: text2, buttons: (sent?.links ?? []).map((l) => ({ ...l })) }).catch((err) => this.log(channel, { event: "error", reason: err.message }));
|
|
15547
15725
|
}
|
|
15548
15726
|
/* ------------------------------------------------------------ out */
|
|
15549
15727
|
/** Delivery marks and Firstmate's replies for the notes that came from a channel. */
|
|
@@ -15673,8 +15851,8 @@ ${text}`, taskId);
|
|
|
15673
15851
|
return ref;
|
|
15674
15852
|
}
|
|
15675
15853
|
}
|
|
15676
|
-
function notice(
|
|
15677
|
-
return { text, taskId: null, actions: [], links: [] };
|
|
15854
|
+
function notice(text2) {
|
|
15855
|
+
return { text: text2, taskId: null, actions: [], links: [] };
|
|
15678
15856
|
}
|
|
15679
15857
|
const RECORD_SCHEMA = "wheelhouse-gateway-record.v1";
|
|
15680
15858
|
const sameRef = (a, b) => !!a && !!b && a.chat === b.chat && a.id === b.id;
|
|
@@ -15692,15 +15870,15 @@ class GatewayRecord {
|
|
|
15692
15870
|
/** Load the record; a missing or unreadable one starts empty (an unreadable one is moved aside). */
|
|
15693
15871
|
static async open(file, now = Date.now) {
|
|
15694
15872
|
const r = new GatewayRecord(file, now);
|
|
15695
|
-
let
|
|
15873
|
+
let text2 = null;
|
|
15696
15874
|
try {
|
|
15697
|
-
|
|
15875
|
+
text2 = await readFile(file, "utf8");
|
|
15698
15876
|
} catch (e) {
|
|
15699
15877
|
if (e.code !== "ENOENT") throw e;
|
|
15700
15878
|
}
|
|
15701
|
-
if (
|
|
15879
|
+
if (text2 === null) return r;
|
|
15702
15880
|
try {
|
|
15703
|
-
const parsed = JSON.parse(
|
|
15881
|
+
const parsed = JSON.parse(text2);
|
|
15704
15882
|
if (parsed.schema !== RECORD_SCHEMA) throw new Error("not a gateway record");
|
|
15705
15883
|
r.notes = Array.isArray(parsed.notes) ? parsed.notes : [];
|
|
15706
15884
|
r.sent = Array.isArray(parsed.sent) ? parsed.sent : [];
|
|
@@ -15773,17 +15951,17 @@ class GatewayRecord {
|
|
|
15773
15951
|
sent: this.sent,
|
|
15774
15952
|
buttons: this.buttons
|
|
15775
15953
|
};
|
|
15776
|
-
const
|
|
15954
|
+
const text2 = JSON.stringify(data, null, " ") + "\n";
|
|
15777
15955
|
this.writing = this.writing.catch(() => {
|
|
15778
|
-
}).then(() => write(this.file,
|
|
15956
|
+
}).then(() => write(this.file, text2));
|
|
15779
15957
|
return this.writing;
|
|
15780
15958
|
}
|
|
15781
15959
|
}
|
|
15782
|
-
async function write(file,
|
|
15960
|
+
async function write(file, text2) {
|
|
15783
15961
|
await mkdir(path.dirname(file), { recursive: true, mode: 448 });
|
|
15784
15962
|
const tmp = `${file}.tmp-${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
15785
15963
|
try {
|
|
15786
|
-
await writeFile(tmp,
|
|
15964
|
+
await writeFile(tmp, text2, { mode: 384 });
|
|
15787
15965
|
await rename(tmp, file);
|
|
15788
15966
|
} catch (e) {
|
|
15789
15967
|
await rm(tmp, { force: true });
|
|
@@ -15819,7 +15997,7 @@ class AuditLog {
|
|
|
15819
15997
|
return this.writing;
|
|
15820
15998
|
}
|
|
15821
15999
|
}
|
|
15822
|
-
const OPTION = /^\s*(❯\s+)?(\d{1,2})\.\s+(?:\[([ ✔✓x])\]\s+)?(.*?)\s*$/;
|
|
16000
|
+
const OPTION$1 = /^\s*(❯\s+)?(\d{1,2})\.\s+(?:\[([ ✔✓x])\]\s+)?(.*?)\s*$/;
|
|
15823
16001
|
const SUBMIT_ROW = /^\s*(❯\s+)?Submit\s*$/;
|
|
15824
16002
|
const SEPARATOR = /^\s*[─━-]{8,}\s*$/;
|
|
15825
16003
|
const OVERLINE = /^\s*▔{8,}/;
|
|
@@ -15834,7 +16012,7 @@ function parsePicker(screen) {
|
|
|
15834
16012
|
let last = end;
|
|
15835
16013
|
while (last >= 0) {
|
|
15836
16014
|
const l = lines[last];
|
|
15837
|
-
if (OPTION.test(l) || SUBMIT_ROW.test(l)) break;
|
|
16015
|
+
if (OPTION$1.test(l) || SUBMIT_ROW.test(l)) break;
|
|
15838
16016
|
if (l.trim() && !FOOTER.test(l) && !SEPARATOR.test(l)) return null;
|
|
15839
16017
|
last--;
|
|
15840
16018
|
}
|
|
@@ -15845,7 +16023,7 @@ function parsePicker(screen) {
|
|
|
15845
16023
|
let pendingDescription = [];
|
|
15846
16024
|
for (let i = last; i >= 0; i--) {
|
|
15847
16025
|
const l = lines[i];
|
|
15848
|
-
const m = OPTION.exec(l);
|
|
16026
|
+
const m = OPTION$1.exec(l);
|
|
15849
16027
|
if (m) {
|
|
15850
16028
|
const n = Number(m[2]);
|
|
15851
16029
|
options.unshift({
|
|
@@ -15918,6 +16096,10 @@ function pickerKeys(picker, action) {
|
|
|
15918
16096
|
if ("press" in action) {
|
|
15919
16097
|
const o = picker.options.find((x) => x.n === action.press);
|
|
15920
16098
|
if (!o || o.freeText || o.n > 9) return null;
|
|
16099
|
+
if (picker.navigation) {
|
|
16100
|
+
const moves = o.n - picker.navigation.selected;
|
|
16101
|
+
return [...Array(Math.abs(moves)).fill(moves > 0 ? "Down" : "Up"), "Enter"];
|
|
16102
|
+
}
|
|
15921
16103
|
return [String(o.n)];
|
|
15922
16104
|
}
|
|
15923
16105
|
if (picker.submitMoves === null) return null;
|
|
@@ -16006,410 +16188,283 @@ function registerTrust(store, dir) {
|
|
|
16006
16188
|
}
|
|
16007
16189
|
return `${file} did not keep the trust entry for ${target}`;
|
|
16008
16190
|
}
|
|
16009
|
-
const
|
|
16010
|
-
const
|
|
16011
|
-
|
|
16012
|
-
|
|
16013
|
-
const
|
|
16014
|
-
const
|
|
16015
|
-
|
|
16016
|
-
|
|
16017
|
-
|
|
16018
|
-
|
|
16019
|
-
|
|
16020
|
-
|
|
16021
|
-
const
|
|
16022
|
-
const
|
|
16023
|
-
|
|
16024
|
-
|
|
16025
|
-
|
|
16026
|
-
]
|
|
16027
|
-
|
|
16028
|
-
|
|
16029
|
-
|
|
16030
|
-
|
|
16031
|
-
|
|
16032
|
-
};
|
|
16033
|
-
if (skipPermissions) settings.skipDangerousModePermissionPrompt = true;
|
|
16034
|
-
return JSON.stringify(settings);
|
|
16035
|
-
}
|
|
16036
|
-
function claudeArgv(claude, hookFile, skipPermissions) {
|
|
16037
|
-
const argv = [claude];
|
|
16038
|
-
if (skipPermissions) argv.push("--dangerously-skip-permissions");
|
|
16039
|
-
argv.push("--settings", sessionSettings(hookFile, skipPermissions));
|
|
16040
|
-
return argv;
|
|
16041
|
-
}
|
|
16042
|
-
function launchArgv(claude, firstmateDir, hookFile, skipPermissions, fmHome) {
|
|
16043
|
-
return [
|
|
16044
|
-
"new-session",
|
|
16045
|
-
"-d",
|
|
16046
|
-
"-s",
|
|
16047
|
-
FIRSTMATE_TMUX,
|
|
16048
|
-
"-x",
|
|
16049
|
-
"160",
|
|
16050
|
-
"-y",
|
|
16051
|
-
"48",
|
|
16052
|
-
"-c",
|
|
16053
|
-
firstmateDir,
|
|
16054
|
-
...fmHome ? ["-e", `FM_HOME=${fmHome}`] : [],
|
|
16055
|
-
"--",
|
|
16056
|
-
...claudeArgv(claude, hookFile, skipPermissions)
|
|
16057
|
-
];
|
|
16058
|
-
}
|
|
16059
|
-
const attachHint = (socket) => shellLine(["tmux", "-L", socket, "attach", "-t", FIRSTMATE_TMUX]);
|
|
16060
|
-
function firstmateTmux(opts) {
|
|
16061
|
-
const socket = opts.tmuxSocket || DEFAULT_TMUX_SOCKET;
|
|
16062
|
-
const env = sessionEnv(opts.env ?? process.env);
|
|
16063
|
-
const find = opts.find ?? ((name2) => which(name2, env.PATH));
|
|
16064
|
-
const run = opts.run ?? runBounded;
|
|
16065
|
-
return async () => {
|
|
16066
|
-
const tmux = find("tmux");
|
|
16067
|
-
if (!tmux || !TMUX_SOCKET.test(socket)) return null;
|
|
16068
|
-
const r = await run(
|
|
16069
|
-
tmux,
|
|
16070
|
-
["-L", socket, "display-message", "-p", "-t", `=${FIRSTMATE_TMUX}:`, TMUX_FORMAT],
|
|
16071
|
-
{ env, timeoutMs: TMUX_TIMEOUT_MS, maxOutputBytes: 64 * 1024 }
|
|
16072
|
-
);
|
|
16073
|
-
if (!r.ok) return null;
|
|
16074
|
-
const value = r.stdout.trim().replace(/,\$(\d+)$/, ",$1");
|
|
16075
|
-
return /^\/.*,\d+,\d+$/.test(value) ? value : null;
|
|
16076
|
-
};
|
|
16077
|
-
}
|
|
16078
|
-
class FirstmateSession {
|
|
16079
|
-
firstmateDir;
|
|
16080
|
-
homeDir;
|
|
16081
|
-
hookFile;
|
|
16082
|
-
skipPermissions;
|
|
16083
|
-
tmuxSocket;
|
|
16084
|
-
stateDir;
|
|
16085
|
-
lock;
|
|
16086
|
-
env;
|
|
16087
|
-
find;
|
|
16088
|
-
run;
|
|
16089
|
-
trustStore;
|
|
16090
|
-
sleep;
|
|
16091
|
-
starting = null;
|
|
16092
|
-
/** One input at a time, in order, so two messages never interleave in the paste buffer. */
|
|
16093
|
-
queue = Promise.resolve();
|
|
16094
|
-
constructor(opts) {
|
|
16095
|
-
this.firstmateDir = path.resolve(opts.firstmateDir);
|
|
16096
|
-
this.homeDir = path.resolve(opts.homeDir);
|
|
16097
|
-
this.stateDir = path.resolve(opts.stateDir);
|
|
16098
|
-
this.hookFile = path.join(this.stateDir, HOOK_RECORD);
|
|
16099
|
-
this.lock = opts.lock;
|
|
16100
|
-
this.skipPermissions = opts.skipPermissions ?? true;
|
|
16101
|
-
this.tmuxSocket = opts.tmuxSocket || DEFAULT_TMUX_SOCKET;
|
|
16102
|
-
this.env = sessionEnv(opts.env ?? process.env);
|
|
16103
|
-
this.find = opts.find ?? ((name2) => which(name2, this.env.PATH));
|
|
16104
|
-
this.run = opts.run ?? runBounded;
|
|
16105
|
-
this.trustStore = opts.trustStore === void 0 ? claudeStore(this.env) : opts.trustStore;
|
|
16106
|
-
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
16107
|
-
}
|
|
16108
|
-
/** Why Wheelhouse cannot start or talk to a session here, or null. */
|
|
16109
|
-
unavailable() {
|
|
16110
|
-
if (!TMUX_SOCKET.test(this.tmuxSocket)) {
|
|
16111
|
-
return `The tmux socket name ${JSON.stringify(this.tmuxSocket)} is not valid; use letters, digits, '.', '_' or '-'.`;
|
|
16112
|
-
}
|
|
16113
|
-
if (!this.find("tmux")) {
|
|
16114
|
-
return "tmux is not installed or not on PATH. Install tmux (for example `brew install tmux`) and restart Wheelhouse.";
|
|
16115
|
-
}
|
|
16116
|
-
if (!this.find("claude")) {
|
|
16117
|
-
return "Claude Code (`claude`) is not installed or not on PATH. Install it and restart Wheelhouse.";
|
|
16191
|
+
const OPTION = /^\s*(›\s*)?(\d+)\.\s+(.+)$/;
|
|
16192
|
+
const CONFIRM = /\benter\b.*\b(?:confirm|select|submit|continue)\b/i;
|
|
16193
|
+
function codexScreen(text2) {
|
|
16194
|
+
if (text2 === null) return { kind: "blocked", title: "Codex’s screen could not be read." };
|
|
16195
|
+
const lines = text2.replace(/\r/g, "").trimEnd().split("\n");
|
|
16196
|
+
const cursor = lines.findLastIndex((line) => /^\s*›(?:\s|$)/.test(line));
|
|
16197
|
+
if (cursor < 0) return { kind: "blocked", title: "Codex needs attention in its terminal." };
|
|
16198
|
+
if (OPTION.test(lines[cursor])) {
|
|
16199
|
+
let start = cursor;
|
|
16200
|
+
while (start > 0 && OPTION.test(lines[start - 1])) start--;
|
|
16201
|
+
let end = cursor + 1;
|
|
16202
|
+
while (end < lines.length && OPTION.test(lines[end])) end++;
|
|
16203
|
+
const options = [];
|
|
16204
|
+
for (const line of lines.slice(start, end)) {
|
|
16205
|
+
const m = OPTION.exec(line);
|
|
16206
|
+
if (!m) return { kind: "blocked", title: "Use the terminal to answer Codex." };
|
|
16207
|
+
options.push({
|
|
16208
|
+
n: Number(m[2]),
|
|
16209
|
+
label: m[3],
|
|
16210
|
+
description: "",
|
|
16211
|
+
checked: null,
|
|
16212
|
+
freeText: false
|
|
16213
|
+
});
|
|
16118
16214
|
}
|
|
16119
|
-
if (
|
|
16120
|
-
return
|
|
16215
|
+
if (options.some((option, index) => option.n !== index + 1) || !CONFIRM.test(lines.slice(end).join("\n"))) {
|
|
16216
|
+
return { kind: "blocked", title: "Use the terminal to answer Codex." };
|
|
16121
16217
|
}
|
|
16122
|
-
return null;
|
|
16123
|
-
}
|
|
16124
|
-
opts(extra = {}) {
|
|
16125
|
-
return { env: this.env, timeoutMs: TMUX_TIMEOUT_MS, maxOutputBytes: 256 * 1024, ...extra };
|
|
16126
|
-
}
|
|
16127
|
-
/** Run tmux on Wheelhouse's own server only; nothing reaches tmux any other way. */
|
|
16128
|
-
tmux(args, extra) {
|
|
16129
|
-
const tmux = this.find("tmux");
|
|
16130
|
-
if (!tmux) return Promise.reject(new Error("tmux is missing"));
|
|
16131
|
-
return this.run(tmux, ["-L", this.tmuxSocket, ...args], this.opts(extra));
|
|
16132
|
-
}
|
|
16133
|
-
/** Whether Wheelhouse's `wh-firstmate` session is running; null when tmux cannot say. */
|
|
16134
|
-
async running() {
|
|
16135
|
-
if (!this.find("tmux") || !TMUX_SOCKET.test(this.tmuxSocket)) return null;
|
|
16136
|
-
const r = await this.tmux(["list-sessions", "-F", "#{session_name}"]);
|
|
16137
|
-
if (r.ok) return r.stdout.split("\n").includes(FIRSTMATE_TMUX);
|
|
16138
|
-
if (r.kind === "exit" && NO_SERVER.test(r.stderr)) return false;
|
|
16139
|
-
return null;
|
|
16140
|
-
}
|
|
16141
|
-
view(state, reason, screen = { picker: null, menu: null, busy: false }) {
|
|
16142
16218
|
return {
|
|
16143
|
-
|
|
16144
|
-
|
|
16145
|
-
|
|
16146
|
-
|
|
16147
|
-
|
|
16148
|
-
|
|
16149
|
-
|
|
16219
|
+
kind: "picker",
|
|
16220
|
+
picker: {
|
|
16221
|
+
title: lines.slice(0, start).join("\n").trim(),
|
|
16222
|
+
tabs: [],
|
|
16223
|
+
options,
|
|
16224
|
+
multiSelect: false,
|
|
16225
|
+
submitMoves: null,
|
|
16226
|
+
navigation: { selected: cursor - start + 1 },
|
|
16227
|
+
// Include the command and every visible option, not only the repeated Yes/No labels.
|
|
16228
|
+
signature: createHash("sha256").update(text2).digest("hex").slice(0, 16)
|
|
16229
|
+
}
|
|
16150
16230
|
};
|
|
16151
16231
|
}
|
|
16152
|
-
|
|
16153
|
-
|
|
16154
|
-
|
|
16155
|
-
|
|
16156
|
-
}
|
|
16157
|
-
/** The menu Claude Code is waiting on in Wheelhouse's session, read off its screen, or null. */
|
|
16158
|
-
async picker() {
|
|
16159
|
-
const text = await this.screen();
|
|
16160
|
-
return text === null ? null : parsePicker(text);
|
|
16161
|
-
}
|
|
16162
|
-
/**
|
|
16163
|
-
* What the screen says: a menu Claude Code waits on (as choices when it has
|
|
16164
|
-
* numbered ones), and whether it is busy (it shows "esc to interrupt" while
|
|
16165
|
-
* working, before anything reaches the transcript).
|
|
16166
|
-
*/
|
|
16167
|
-
async onScreen() {
|
|
16168
|
-
const text = await this.screen().catch(() => null);
|
|
16169
|
-
if (text === null) return { picker: null, menu: null, busy: false };
|
|
16232
|
+
const input = lines[cursor].replace(/^\s*›\s*/, "").trim();
|
|
16233
|
+
if (input && !/^(?:Ask Codex to do anything|Ask for changes|Use \/skills to list available skills|Find and fix a bug in @filename|Explain this codebase|Summarize recent commits|Write tests for @filename|Improve documentation in @filename|Implement \{feature\})$/.test(
|
|
16234
|
+
input
|
|
16235
|
+
)) {
|
|
16170
16236
|
return {
|
|
16171
|
-
|
|
16172
|
-
|
|
16173
|
-
busy: /\besc to interrupt\b/i.test(text)
|
|
16237
|
+
kind: "blocked",
|
|
16238
|
+
title: "Codex has unsent input. Send or clear it in the terminal first."
|
|
16174
16239
|
};
|
|
16175
16240
|
}
|
|
16176
|
-
|
|
16177
|
-
|
|
16178
|
-
const reason = this.unavailable();
|
|
16179
|
-
const ours = reason ? null : await this.running();
|
|
16180
|
-
if (ours) return this.view("ours", null, await this.onScreen());
|
|
16181
|
-
const lock = await this.lock();
|
|
16182
|
-
if (lock === "held") {
|
|
16183
|
-
return this.view(
|
|
16184
|
-
"external",
|
|
16185
|
-
"Firstmate is running in another terminal, so Wheelhouse shows its conversation read-only and sends your messages to its inbox. To talk to it here directly, close it there and start it from Wheelhouse."
|
|
16186
|
-
);
|
|
16187
|
-
}
|
|
16188
|
-
if (reason) return this.view("unavailable", reason);
|
|
16189
|
-
if (ours === null)
|
|
16190
|
-
return this.view("unavailable", "Wheelhouse could not ask tmux about the session.");
|
|
16191
|
-
if (this.starting) return this.view("starting", null);
|
|
16192
|
-
return this.view("none", "No Firstmate session is running.");
|
|
16241
|
+
if (cursor < lines.length - 7 || CONFIRM.test(lines.slice(cursor + 1).join("\n"))) {
|
|
16242
|
+
return { kind: "blocked", title: "Codex needs attention in its terminal." };
|
|
16193
16243
|
}
|
|
16194
|
-
|
|
16195
|
-
|
|
16196
|
-
|
|
16197
|
-
|
|
16198
|
-
|
|
16199
|
-
|
|
16200
|
-
|
|
16201
|
-
|
|
16202
|
-
|
|
16203
|
-
|
|
16204
|
-
|
|
16205
|
-
|
|
16206
|
-
|
|
16207
|
-
|
|
16208
|
-
|
|
16209
|
-
|
|
16210
|
-
|
|
16211
|
-
|
|
16212
|
-
|
|
16213
|
-
|
|
16214
|
-
|
|
16215
|
-
|
|
16216
|
-
|
|
16217
|
-
|
|
16218
|
-
|
|
16219
|
-
|
|
16220
|
-
|
|
16221
|
-
|
|
16222
|
-
|
|
16223
|
-
|
|
16224
|
-
|
|
16225
|
-
|
|
16226
|
-
|
|
16227
|
-
|
|
16228
|
-
|
|
16229
|
-
|
|
16230
|
-
|
|
16231
|
-
|
|
16232
|
-
|
|
16233
|
-
|
|
16234
|
-
|
|
16235
|
-
|
|
16236
|
-
|
|
16237
|
-
|
|
16238
|
-
|
|
16239
|
-
|
|
16240
|
-
|
|
16241
|
-
|
|
16242
|
-
|
|
16243
|
-
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
|
|
16251
|
-
|
|
16252
|
-
|
|
16253
|
-
|
|
16254
|
-
|
|
16255
|
-
|
|
16256
|
-
|
|
16257
|
-
|
|
16258
|
-
|
|
16259
|
-
|
|
16260
|
-
|
|
16261
|
-
|
|
16262
|
-
|
|
16263
|
-
|
|
16264
|
-
|
|
16265
|
-
|
|
16266
|
-
|
|
16267
|
-
|
|
16268
|
-
|
|
16269
|
-
|
|
16270
|
-
|
|
16271
|
-
|
|
16272
|
-
|
|
16273
|
-
|
|
16274
|
-
|
|
16275
|
-
|
|
16276
|
-
|
|
16277
|
-
|
|
16278
|
-
|
|
16279
|
-
|
|
16280
|
-
|
|
16281
|
-
|
|
16282
|
-
|
|
16283
|
-
|
|
16284
|
-
|
|
16285
|
-
|
|
16286
|
-
|
|
16287
|
-
|
|
16288
|
-
|
|
16289
|
-
|
|
16244
|
+
return { kind: "prompt", busy: /\besc to interrupt\b/i.test(text2) };
|
|
16245
|
+
}
|
|
16246
|
+
const RECEIPT_BYTES$1 = 64 * 1024;
|
|
16247
|
+
const SESSION_BYTES = 32 * 1024 * 1024;
|
|
16248
|
+
const MAX_RECORDS$1 = 6e3;
|
|
16249
|
+
function piExtensionSource() {
|
|
16250
|
+
return `import { mkdirSync, writeFileSync, renameSync } from 'node:fs';
|
|
16251
|
+
import path from 'node:path';
|
|
16252
|
+
export default function(pi) {
|
|
16253
|
+
const file = process.env.WH_SESSION_RECORD;
|
|
16254
|
+
const nonce = process.env.WH_SESSION_NONCE;
|
|
16255
|
+
if (!file || !nonce) return;
|
|
16256
|
+
let context = null, timer = null, previous = '';
|
|
16257
|
+
const save = () => {
|
|
16258
|
+
if (!context) return;
|
|
16259
|
+
try {
|
|
16260
|
+
const manager = context.sessionManager;
|
|
16261
|
+
const value = JSON.stringify({ wheelhouse_nonce: nonce, session_id: manager.getSessionId(), transcript_path: manager.getSessionFile() ?? null, cwd: context.cwd, leaf_id: manager.getLeafId(), busy: !context.isIdle() });
|
|
16262
|
+
if (value === previous || Buffer.byteLength(value) > 65536) return;
|
|
16263
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
16264
|
+
const temp = file + '.tmp.' + process.pid;
|
|
16265
|
+
writeFileSync(temp, value, { mode: 0o600 });
|
|
16266
|
+
renameSync(temp, file);
|
|
16267
|
+
previous = value;
|
|
16268
|
+
} catch { /* Observation must not interrupt Pi's session. */ }
|
|
16269
|
+
};
|
|
16270
|
+
pi.on('session_start', (_event, ctx) => {
|
|
16271
|
+
context = ctx;
|
|
16272
|
+
save();
|
|
16273
|
+
if (timer) clearInterval(timer);
|
|
16274
|
+
// message_end fires before persistence; observe the manager after it has appended the entry.
|
|
16275
|
+
timer = setInterval(save, 250);
|
|
16276
|
+
timer.unref?.();
|
|
16277
|
+
});
|
|
16278
|
+
for (const event of ['session_tree', 'session_compact', 'agent_end']) {
|
|
16279
|
+
pi.on(event, (_event, ctx) => { context = ctx; save(); });
|
|
16280
|
+
}
|
|
16281
|
+
pi.on('session_shutdown', () => { context = null; if (timer) clearInterval(timer); timer = null; });
|
|
16282
|
+
}
|
|
16283
|
+
`;
|
|
16284
|
+
}
|
|
16285
|
+
function object$2(value) {
|
|
16286
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
16287
|
+
}
|
|
16288
|
+
async function readBounded(file, limit) {
|
|
16289
|
+
const handle = await open(file, "r");
|
|
16290
|
+
try {
|
|
16291
|
+
const size = (await handle.stat()).size;
|
|
16292
|
+
if (size > limit) return null;
|
|
16293
|
+
const buffer = Buffer.alloc(size);
|
|
16294
|
+
let offset = 0;
|
|
16295
|
+
while (offset < size) {
|
|
16296
|
+
const { bytesRead } = await handle.read(buffer, offset, size - offset, offset);
|
|
16297
|
+
if (!bytesRead) break;
|
|
16298
|
+
offset += bytesRead;
|
|
16299
|
+
}
|
|
16300
|
+
return buffer.subarray(0, offset).toString("utf8");
|
|
16301
|
+
} finally {
|
|
16302
|
+
await handle.close();
|
|
16303
|
+
}
|
|
16304
|
+
}
|
|
16305
|
+
function contentText(content) {
|
|
16306
|
+
if (typeof content === "string") return content;
|
|
16307
|
+
if (!Array.isArray(content)) return "";
|
|
16308
|
+
return content.flatMap((part) => {
|
|
16309
|
+
const block = object$2(part);
|
|
16310
|
+
if (block?.type === "text" && typeof block.text === "string") return [block.text];
|
|
16311
|
+
return block?.type === "image" ? ["[image]"] : [];
|
|
16312
|
+
}).join("\n");
|
|
16313
|
+
}
|
|
16314
|
+
function normalize(entry, sessionId) {
|
|
16315
|
+
if (entry.type !== "message" || typeof entry.id !== "string" || typeof entry.timestamp !== "string")
|
|
16316
|
+
return [];
|
|
16317
|
+
const message2 = object$2(entry.message);
|
|
16318
|
+
if (!message2 || !Number.isFinite(Date.parse(entry.timestamp))) return [];
|
|
16319
|
+
const uuid = `pi:${sessionId}:${entry.id}`;
|
|
16320
|
+
const timestamp2 = entry.timestamp;
|
|
16321
|
+
if (message2.role === "user") {
|
|
16322
|
+
const content2 = contentText(message2.content);
|
|
16323
|
+
return content2.trim() ? [{ type: "user", uuid, timestamp: timestamp2, message: { role: "user", content: content2 } }] : [];
|
|
16324
|
+
}
|
|
16325
|
+
if (message2.role === "toolResult" && typeof message2.toolCallId === "string") {
|
|
16326
|
+
return [
|
|
16327
|
+
{
|
|
16328
|
+
type: "user",
|
|
16329
|
+
uuid,
|
|
16330
|
+
timestamp: timestamp2,
|
|
16331
|
+
message: {
|
|
16332
|
+
role: "user",
|
|
16333
|
+
content: [
|
|
16334
|
+
{
|
|
16335
|
+
type: "tool_result",
|
|
16336
|
+
tool_use_id: `pi:${sessionId}:${message2.toolCallId}`,
|
|
16337
|
+
content: contentText(message2.content),
|
|
16338
|
+
is_error: message2.isError === true
|
|
16339
|
+
}
|
|
16340
|
+
]
|
|
16341
|
+
}
|
|
16290
16342
|
}
|
|
16291
|
-
|
|
16292
|
-
if (refused) return refused;
|
|
16293
|
-
const shown = await this.onScreen();
|
|
16294
|
-
if (shown.picker || shown.menu) return { ok: false, status: 409, error: MENU_OPEN };
|
|
16295
|
-
const load2 = await this.tmux(["load-buffer", "-b", BUFFER, "-"], {
|
|
16296
|
-
input: body,
|
|
16297
|
-
maxInputBytes: INPUT_MAX_BYTES + 1024
|
|
16298
|
-
});
|
|
16299
|
-
if (!load2.ok)
|
|
16300
|
-
return {
|
|
16301
|
-
ok: false,
|
|
16302
|
-
status: 500,
|
|
16303
|
-
error: `tmux could not take the message: ${load2.stderr.trim() || load2.message}`
|
|
16304
|
-
};
|
|
16305
|
-
const paste = await this.tmux([
|
|
16306
|
-
"paste-buffer",
|
|
16307
|
-
"-d",
|
|
16308
|
-
"-p",
|
|
16309
|
-
"-b",
|
|
16310
|
-
BUFFER,
|
|
16311
|
-
"-t",
|
|
16312
|
-
`=${FIRSTMATE_TMUX}:`
|
|
16313
|
-
]);
|
|
16314
|
-
if (!paste.ok)
|
|
16315
|
-
return {
|
|
16316
|
-
ok: false,
|
|
16317
|
-
status: 500,
|
|
16318
|
-
error: `tmux could not paste the message: ${paste.stderr.trim() || paste.message}`
|
|
16319
|
-
};
|
|
16320
|
-
await this.sleep(PASTE_SETTLE_MS);
|
|
16321
|
-
return this.keys(["Enter"]);
|
|
16322
|
-
});
|
|
16323
|
-
}
|
|
16324
|
-
/** Press Escape: Claude Code stops what it is doing. */
|
|
16325
|
-
interrupt() {
|
|
16326
|
-
return this.serial(async () => await this.ours() ?? this.keys(["Escape"]));
|
|
16343
|
+
];
|
|
16327
16344
|
}
|
|
16328
|
-
|
|
16329
|
-
|
|
16330
|
-
|
|
16331
|
-
|
|
16332
|
-
|
|
16333
|
-
|
|
16334
|
-
|
|
16335
|
-
|
|
16336
|
-
|
|
16337
|
-
|
|
16338
|
-
|
|
16339
|
-
|
|
16340
|
-
|
|
16341
|
-
|
|
16342
|
-
|
|
16343
|
-
|
|
16345
|
+
if (message2.role !== "assistant" || !Array.isArray(message2.content)) return [];
|
|
16346
|
+
const names = {
|
|
16347
|
+
bash: "Bash",
|
|
16348
|
+
read: "Read",
|
|
16349
|
+
edit: "Edit",
|
|
16350
|
+
write: "Write",
|
|
16351
|
+
grep: "Grep",
|
|
16352
|
+
find: "Glob",
|
|
16353
|
+
ls: "Glob"
|
|
16354
|
+
};
|
|
16355
|
+
const content = message2.content.flatMap((part) => {
|
|
16356
|
+
const block = object$2(part);
|
|
16357
|
+
if (!block) return [];
|
|
16358
|
+
if (block.type === "text" && typeof block.text === "string")
|
|
16359
|
+
return [{ type: "text", text: block.text }];
|
|
16360
|
+
if (block.type === "thinking") return [{ type: "thinking", thinking: "", signature: "" }];
|
|
16361
|
+
if (block.type !== "toolCall" || typeof block.id !== "string" || typeof block.name !== "string")
|
|
16362
|
+
return [];
|
|
16363
|
+
const input = object$2(block.arguments);
|
|
16364
|
+
if (!input) return [];
|
|
16365
|
+
return [
|
|
16366
|
+
{
|
|
16367
|
+
type: "tool_use",
|
|
16368
|
+
id: `pi:${sessionId}:${block.id}`,
|
|
16369
|
+
name: names[block.name] ?? block.name,
|
|
16370
|
+
input: { ...input, ...typeof input.path === "string" ? { file_path: input.path } : {} }
|
|
16344
16371
|
}
|
|
16345
|
-
|
|
16346
|
-
|
|
16347
|
-
|
|
16372
|
+
];
|
|
16373
|
+
});
|
|
16374
|
+
if (message2.stopReason === "error" && typeof message2.errorMessage === "string")
|
|
16375
|
+
content.push({ type: "text", text: message2.errorMessage });
|
|
16376
|
+
const records2 = content.length ? [{ type: "assistant", uuid, timestamp: timestamp2, message: { id: uuid, role: "assistant", content } }] : [];
|
|
16377
|
+
if (message2.stopReason === "aborted")
|
|
16378
|
+
records2.push({
|
|
16379
|
+
type: "user",
|
|
16380
|
+
uuid: `${uuid}:interrupted`,
|
|
16381
|
+
timestamp: timestamp2,
|
|
16382
|
+
message: { role: "user", content: "[Request interrupted by user]" }
|
|
16348
16383
|
});
|
|
16349
|
-
|
|
16350
|
-
|
|
16351
|
-
|
|
16352
|
-
|
|
16353
|
-
|
|
16354
|
-
|
|
16355
|
-
|
|
16356
|
-
* Firstmate's own question or permission prompt, which has no heading of
|
|
16357
|
-
* Claude Code's, is the captain's to answer and is never closed.
|
|
16358
|
-
*/
|
|
16359
|
-
dismiss() {
|
|
16360
|
-
return this.serial(async () => {
|
|
16361
|
-
const refused = await this.ours();
|
|
16362
|
-
if (refused) return refused;
|
|
16363
|
-
let text = await this.screen().catch(() => null);
|
|
16364
|
-
for (let i = 0; i < DISMISS_MAX; i++) {
|
|
16365
|
-
const menu = text === null ? null : parseMenu(text);
|
|
16366
|
-
if (!menu) return { ok: true };
|
|
16367
|
-
if (!menu.title && parsePicker(text)) {
|
|
16368
|
-
if (i > 0) return { ok: true };
|
|
16369
|
-
return {
|
|
16370
|
-
ok: false,
|
|
16371
|
-
status: 409,
|
|
16372
|
-
error: "Firstmate is asking you something now; answer it in the chat."
|
|
16373
|
-
};
|
|
16374
|
-
}
|
|
16375
|
-
const r = await this.keys(["Escape"]);
|
|
16376
|
-
if (!r.ok) return r;
|
|
16377
|
-
const before = menuPart(text);
|
|
16378
|
-
for (let w = 0; w < MENU_REDRAW_WAITS && menuPart(text) === before; w++) {
|
|
16379
|
-
await this.sleep(MENU_SETTLE_MS);
|
|
16380
|
-
text = await this.screen().catch(() => null);
|
|
16381
|
-
}
|
|
16382
|
-
if (menuPart(text) === before) break;
|
|
16383
|
-
}
|
|
16384
|
-
return {
|
|
16385
|
-
ok: false,
|
|
16386
|
-
status: 409,
|
|
16387
|
-
error: "The menu is still open after pressing Escape; close it in Firstmate’s terminal."
|
|
16388
|
-
};
|
|
16384
|
+
if (["stop", "length", "error", "aborted"].includes(String(message2.stopReason)))
|
|
16385
|
+
records2.push({
|
|
16386
|
+
type: "system",
|
|
16387
|
+
subtype: "turn_duration",
|
|
16388
|
+
uuid: `${uuid}:done`,
|
|
16389
|
+
timestamp: timestamp2,
|
|
16390
|
+
durationMs: null
|
|
16389
16391
|
});
|
|
16390
|
-
|
|
16391
|
-
|
|
16392
|
-
|
|
16393
|
-
|
|
16394
|
-
|
|
16395
|
-
|
|
16392
|
+
return records2;
|
|
16393
|
+
}
|
|
16394
|
+
async function piSnapshot(opts) {
|
|
16395
|
+
if (!opts.sessionNonce?.trim()) return null;
|
|
16396
|
+
try {
|
|
16397
|
+
const receiptText = await readBounded(opts.hookFile, RECEIPT_BYTES$1);
|
|
16398
|
+
const receipt = receiptText === null ? null : object$2(JSON.parse(receiptText));
|
|
16399
|
+
if (!receipt || receipt.wheelhouse_nonce !== opts.sessionNonce || typeof receipt.session_id !== "string" || !receipt.session_id || typeof receipt.transcript_path !== "string" || !path.isAbsolute(receipt.transcript_path) || typeof receipt.cwd !== "string" || !path.isAbsolute(receipt.cwd) || !(receipt.leaf_id === null || typeof receipt.leaf_id === "string"))
|
|
16400
|
+
return null;
|
|
16401
|
+
const sessionId = receipt.session_id;
|
|
16402
|
+
const [cwd, receiptCwd, root, file] = await Promise.all([
|
|
16403
|
+
realpath(opts.firstmateDir),
|
|
16404
|
+
realpath(receipt.cwd),
|
|
16405
|
+
realpath(path.join(opts.agentDir, "sessions")),
|
|
16406
|
+
realpath(receipt.transcript_path)
|
|
16407
|
+
]);
|
|
16408
|
+
const relative = path.relative(root, file);
|
|
16409
|
+
if (cwd !== receiptCwd || !relative || relative.startsWith("..") || path.isAbsolute(relative))
|
|
16410
|
+
return null;
|
|
16411
|
+
const text2 = await readBounded(file, SESSION_BYTES);
|
|
16412
|
+
if (text2 === null) return null;
|
|
16413
|
+
const lines = text2.split("\n");
|
|
16414
|
+
lines.pop();
|
|
16415
|
+
const header = object$2(JSON.parse(lines.shift() ?? "null"));
|
|
16416
|
+
if (!header || header.type !== "session" || header.version !== 3 || header.id !== receipt.session_id || typeof header.cwd !== "string" || await realpath(header.cwd) !== cwd)
|
|
16417
|
+
return null;
|
|
16418
|
+
const entries = /* @__PURE__ */ new Map();
|
|
16419
|
+
for (const line of lines) {
|
|
16420
|
+
if (!line.trim()) continue;
|
|
16421
|
+
const entry = object$2(JSON.parse(line));
|
|
16422
|
+
if (!entry || typeof entry.id !== "string" || !(entry.parentId === null || typeof entry.parentId === "string") || entries.has(entry.id))
|
|
16423
|
+
return null;
|
|
16424
|
+
entries.set(entry.id, entry);
|
|
16396
16425
|
}
|
|
16397
|
-
const
|
|
16398
|
-
|
|
16399
|
-
|
|
16400
|
-
|
|
16401
|
-
|
|
16402
|
-
|
|
16403
|
-
|
|
16404
|
-
|
|
16405
|
-
|
|
16406
|
-
|
|
16407
|
-
|
|
16426
|
+
const branch = [];
|
|
16427
|
+
const seen = /* @__PURE__ */ new Set();
|
|
16428
|
+
let leaf = receipt.leaf_id;
|
|
16429
|
+
while (leaf !== null) {
|
|
16430
|
+
if (seen.has(leaf)) return null;
|
|
16431
|
+
seen.add(leaf);
|
|
16432
|
+
const entry = entries.get(leaf);
|
|
16433
|
+
if (!entry) return null;
|
|
16434
|
+
branch.push(entry);
|
|
16435
|
+
leaf = typeof entry.parentId === "string" ? entry.parentId : null;
|
|
16436
|
+
}
|
|
16437
|
+
const records2 = branch.reverse().flatMap((entry) => normalize(entry, sessionId));
|
|
16438
|
+
return {
|
|
16439
|
+
source: { how: "hook", file, truncated: records2.length > MAX_RECORDS$1 },
|
|
16440
|
+
records: records2.slice(-MAX_RECORDS$1)
|
|
16408
16441
|
};
|
|
16409
|
-
|
|
16410
|
-
|
|
16442
|
+
} catch {
|
|
16443
|
+
return null;
|
|
16444
|
+
}
|
|
16411
16445
|
}
|
|
16412
|
-
|
|
16446
|
+
function piScreen(text2) {
|
|
16447
|
+
const blocked = { kind: "blocked", title: "Pi needs attention in its terminal." };
|
|
16448
|
+
if (text2 === null) return blocked;
|
|
16449
|
+
const lines = text2.replace(/\r/g, "").trimEnd().split("\n");
|
|
16450
|
+
const rule = /^\s*─{12,}\s*$/;
|
|
16451
|
+
const bottom = lines.findLastIndex((line) => rule.test(line));
|
|
16452
|
+
if (bottom < 2 || bottom < lines.length - 5 || bottom >= lines.length - 1) return blocked;
|
|
16453
|
+
const footer = lines.slice(bottom + 1);
|
|
16454
|
+
if (!/^\s*(?:\/|~(?:\/|$))/.test(footer[0]) || footer.some((line) => /\b(?:select|confirm|cancel)\b/i.test(line)))
|
|
16455
|
+
return blocked;
|
|
16456
|
+
let top = bottom - 1;
|
|
16457
|
+
while (top >= Math.max(0, bottom - 12) && !rule.test(lines[top]) && !/^── .*\bWorking\b.*─{8,}\s*$/.test(lines[top]))
|
|
16458
|
+
top--;
|
|
16459
|
+
if (top < 0 || top < bottom - 12) return blocked;
|
|
16460
|
+
if (lines.slice(top + 1, bottom).some((line) => line.trim()))
|
|
16461
|
+
return {
|
|
16462
|
+
kind: "blocked",
|
|
16463
|
+
title: "Pi has unsent input or a dialog. Send or clear it in the terminal first."
|
|
16464
|
+
};
|
|
16465
|
+
return { kind: "prompt", busy: /\bWorking\b/.test(lines[top]) };
|
|
16466
|
+
}
|
|
16467
|
+
const UUID$1 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
16413
16468
|
const INITIAL_BYTES = 8 * 1024 * 1024;
|
|
16414
16469
|
const MAX_RECORDS = 6e3;
|
|
16415
16470
|
const MAX_RESULT_CHARS = 16e3;
|
|
@@ -16439,7 +16494,7 @@ async function real(p) {
|
|
|
16439
16494
|
async function lockSessionId(homeDir) {
|
|
16440
16495
|
try {
|
|
16441
16496
|
const id = (await readFile(path.join(homeDir, "state", ".lock-session"), "utf8")).split("\n")[0].trim();
|
|
16442
|
-
return UUID.test(id) ? id : null;
|
|
16497
|
+
return UUID$1.test(id) ? id : null;
|
|
16443
16498
|
} catch {
|
|
16444
16499
|
return null;
|
|
16445
16500
|
}
|
|
@@ -16548,7 +16603,7 @@ async function newestCached(o, dir) {
|
|
|
16548
16603
|
const KEEP_TYPES = /* @__PURE__ */ new Set(["user", "assistant", "system", "attachment", "ai-title"]);
|
|
16549
16604
|
const KEEP_ATTACHMENTS = /* @__PURE__ */ new Set(["queued_command", "hook_additional_context"]);
|
|
16550
16605
|
const KEEP_SYSTEM = /* @__PURE__ */ new Set(["turn_duration", "away_summary", "local_command"]);
|
|
16551
|
-
const cut = (s) => s.length > MAX_RESULT_CHARS ? `${s.slice(0, MAX_RESULT_CHARS)}
|
|
16606
|
+
const cut$1 = (s) => s.length > MAX_RESULT_CHARS ? `${s.slice(0, MAX_RESULT_CHARS)}
|
|
16552
16607
|
… (${s.length - MAX_RESULT_CHARS} more characters in the terminal)` : s;
|
|
16553
16608
|
function slim(r) {
|
|
16554
16609
|
if (!r || typeof r !== "object" || !KEEP_TYPES.has(r.type)) return null;
|
|
@@ -16581,8 +16636,8 @@ function slim(r) {
|
|
|
16581
16636
|
if (Array.isArray(content)) {
|
|
16582
16637
|
content = content.map((b) => {
|
|
16583
16638
|
if (b?.type !== "tool_result") return b;
|
|
16584
|
-
const c = typeof b.content === "string" ? cut(b.content) : Array.isArray(b.content) ? b.content.map(
|
|
16585
|
-
(x) => x?.type === "text" ? { ...x, text: cut(String(x.text ?? "")) } : x?.type === "image" ? { type: "image" } : x
|
|
16639
|
+
const c = typeof b.content === "string" ? cut$1(b.content) : Array.isArray(b.content) ? b.content.map(
|
|
16640
|
+
(x) => x?.type === "text" ? { ...x, text: cut$1(String(x.text ?? "")) } : x?.type === "image" ? { type: "image" } : x
|
|
16586
16641
|
) : b.content;
|
|
16587
16642
|
return { ...b, content: c };
|
|
16588
16643
|
});
|
|
@@ -16591,7 +16646,7 @@ function slim(r) {
|
|
|
16591
16646
|
}
|
|
16592
16647
|
return out;
|
|
16593
16648
|
}
|
|
16594
|
-
function toolContent(content) {
|
|
16649
|
+
function toolContent$1(content) {
|
|
16595
16650
|
const blocks = typeof content === "string" ? [{ type: "text", text: content }] : Array.isArray(content) ? content.filter((b) => b?.type === "text").map((b) => ({ type: "text", text: String(b.text ?? "") })) : [];
|
|
16596
16651
|
const bytes = blocks.reduce((n, b) => n + Buffer.byteLength(b.text), 0);
|
|
16597
16652
|
return bytes > MAX_TOOL_RESULT_BYTES ? null : blocks;
|
|
@@ -16647,11 +16702,44 @@ class ChatFeed {
|
|
|
16647
16702
|
}
|
|
16648
16703
|
async step() {
|
|
16649
16704
|
const session = await this.opts.status();
|
|
16650
|
-
if (
|
|
16651
|
-
|
|
16652
|
-
|
|
16705
|
+
if (this.opts.snapshot && (session.harness === "opencode" || session.harness === "pi")) {
|
|
16706
|
+
let snapshot;
|
|
16707
|
+
try {
|
|
16708
|
+
snapshot = await this.opts.snapshot(session);
|
|
16709
|
+
} catch (error) {
|
|
16710
|
+
this.publishSession({
|
|
16711
|
+
...session,
|
|
16712
|
+
canSend: false,
|
|
16713
|
+
reason: error instanceof Error ? error.message : "The conversation could not be read."
|
|
16714
|
+
});
|
|
16715
|
+
return;
|
|
16716
|
+
}
|
|
16717
|
+
this.publishSession(session);
|
|
16718
|
+
this.watcher?.close();
|
|
16719
|
+
this.watcher = null;
|
|
16720
|
+
const source = snapshot?.source ?? null;
|
|
16721
|
+
const changed = source?.file !== this.source?.file;
|
|
16722
|
+
if (changed) this.emit({ type: "reset", data: source });
|
|
16723
|
+
this.source = source;
|
|
16724
|
+
const records2 = [];
|
|
16725
|
+
this.calls.clear();
|
|
16726
|
+
for (const record of snapshot?.records ?? []) {
|
|
16727
|
+
this.noteToolCalls(record);
|
|
16728
|
+
const compact = slim(record);
|
|
16729
|
+
if (compact) records2.push(compact);
|
|
16730
|
+
}
|
|
16731
|
+
if (records2.length > MAX_RECORDS) {
|
|
16732
|
+
records2.splice(0, records2.length - MAX_RECORDS);
|
|
16733
|
+
if (source) source.truncated = true;
|
|
16734
|
+
}
|
|
16735
|
+
if (changed || JSON.stringify(records2) !== JSON.stringify(this.records)) {
|
|
16736
|
+
this.records = records2;
|
|
16737
|
+
this.emit({ type: "replace", data: records2 });
|
|
16738
|
+
}
|
|
16739
|
+
return;
|
|
16653
16740
|
}
|
|
16654
|
-
|
|
16741
|
+
this.publishSession(session);
|
|
16742
|
+
const found = session.harness && session.harness !== "claude" && !this.opts.decode ? null : await this.opts.locate(session.state, session.harness ?? "claude");
|
|
16655
16743
|
if (found?.file !== this.source?.file) {
|
|
16656
16744
|
this.watcher?.close();
|
|
16657
16745
|
this.watcher = null;
|
|
@@ -16672,98 +16760,1304 @@ class ChatFeed {
|
|
|
16672
16760
|
} catch {
|
|
16673
16761
|
}
|
|
16674
16762
|
}
|
|
16675
|
-
this.emit({ type: "reset", data: this.source });
|
|
16763
|
+
this.emit({ type: "reset", data: this.source });
|
|
16764
|
+
}
|
|
16765
|
+
if (this.source && !this.watcher) {
|
|
16766
|
+
try {
|
|
16767
|
+
this.watcher = watch(this.source.file, () => void this.refresh());
|
|
16768
|
+
this.watcher.on("error", () => {
|
|
16769
|
+
});
|
|
16770
|
+
} catch {
|
|
16771
|
+
}
|
|
16772
|
+
}
|
|
16773
|
+
if (this.source) await this.read(this.source.file);
|
|
16774
|
+
}
|
|
16775
|
+
publishSession(session) {
|
|
16776
|
+
if (JSON.stringify(session) !== JSON.stringify(this.session)) {
|
|
16777
|
+
this.session = session;
|
|
16778
|
+
this.emit({ type: "session", data: session });
|
|
16779
|
+
}
|
|
16780
|
+
}
|
|
16781
|
+
async read(file) {
|
|
16782
|
+
let fh;
|
|
16783
|
+
try {
|
|
16784
|
+
const { size } = await stat(file);
|
|
16785
|
+
if (size < this.offset) {
|
|
16786
|
+
this.records = [];
|
|
16787
|
+
this.calls.clear();
|
|
16788
|
+
this.offset = 0;
|
|
16789
|
+
this.partial = Buffer.alloc(0);
|
|
16790
|
+
this.emit({ type: "reset", data: this.source });
|
|
16791
|
+
}
|
|
16792
|
+
if (size === this.offset) return;
|
|
16793
|
+
fh = await open(file, "r");
|
|
16794
|
+
const buf = Buffer.alloc(size - this.offset);
|
|
16795
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, this.offset);
|
|
16796
|
+
const startedMidway = this.offset > 0 && this.records.length === 0 && this.partial.length === 0 && this.source?.truncated;
|
|
16797
|
+
this.offset += bytesRead;
|
|
16798
|
+
const chunk = Buffer.concat([this.partial, buf.subarray(0, bytesRead)]);
|
|
16799
|
+
const end = chunk.lastIndexOf(10) + 1;
|
|
16800
|
+
this.partial = chunk.subarray(end);
|
|
16801
|
+
const lines = chunk.subarray(0, end).toString("utf8").split("\n");
|
|
16802
|
+
lines.pop();
|
|
16803
|
+
if (startedMidway) lines.shift();
|
|
16804
|
+
const fresh = [];
|
|
16805
|
+
const seen = new Set(this.records.map((record) => record.uuid));
|
|
16806
|
+
for (const line of lines) {
|
|
16807
|
+
if (!line.trim()) continue;
|
|
16808
|
+
try {
|
|
16809
|
+
const raw = JSON.parse(line);
|
|
16810
|
+
const decoded = this.opts.decode ? this.opts.decode(raw, this.session?.harness ?? "claude") : [raw];
|
|
16811
|
+
for (const record of decoded) {
|
|
16812
|
+
if (this.opts.decode && this.session?.harness !== "claude" && seen.has(record.uuid))
|
|
16813
|
+
continue;
|
|
16814
|
+
this.noteToolCalls(record);
|
|
16815
|
+
const r = slim(record);
|
|
16816
|
+
if (r) {
|
|
16817
|
+
fresh.push(r);
|
|
16818
|
+
seen.add(r.uuid);
|
|
16819
|
+
}
|
|
16820
|
+
}
|
|
16821
|
+
} catch {
|
|
16822
|
+
}
|
|
16823
|
+
}
|
|
16824
|
+
if (!fresh.length) return;
|
|
16825
|
+
this.records.push(...fresh);
|
|
16826
|
+
if (this.records.length > MAX_RECORDS)
|
|
16827
|
+
this.records.splice(0, this.records.length - MAX_RECORDS);
|
|
16828
|
+
this.emit({ type: "records", data: fresh });
|
|
16829
|
+
} catch {
|
|
16830
|
+
} finally {
|
|
16831
|
+
await fh?.close();
|
|
16832
|
+
}
|
|
16833
|
+
}
|
|
16834
|
+
/** Keep the MCP tool calls in a raw record, and the results they get, for the chat's apps. */
|
|
16835
|
+
noteToolCalls(r) {
|
|
16836
|
+
if (!r || typeof r !== "object" || r.isSidechain) return;
|
|
16837
|
+
const content = r.message?.content;
|
|
16838
|
+
if (!Array.isArray(content)) return;
|
|
16839
|
+
for (const b of content) {
|
|
16840
|
+
if (r.type === "assistant" && b?.type === "tool_use" && typeof b.id === "string") {
|
|
16841
|
+
const name2 = String(b.name ?? "");
|
|
16842
|
+
if (!name2.startsWith("mcp__")) continue;
|
|
16843
|
+
const input = b.input && typeof b.input === "object" && !Array.isArray(b.input) ? b.input : {};
|
|
16844
|
+
this.calls.set(b.id, { id: b.id, name: name2, input, result: null });
|
|
16845
|
+
if (this.calls.size > MAX_TOOL_CALLS) {
|
|
16846
|
+
this.calls.delete(this.calls.keys().next().value);
|
|
16847
|
+
}
|
|
16848
|
+
} else if (r.type === "user" && b?.type === "tool_result") {
|
|
16849
|
+
const call2 = this.calls.get(b.tool_use_id);
|
|
16850
|
+
if (!call2) continue;
|
|
16851
|
+
const c = toolContent$1(b.content);
|
|
16852
|
+
call2.result = c ? { content: c, isError: !!b.is_error } : { tooLarge: true };
|
|
16853
|
+
}
|
|
16854
|
+
}
|
|
16855
|
+
}
|
|
16856
|
+
/** An MCP tool call in the transcript, by its `tool_use` id, or null. */
|
|
16857
|
+
toolCall(id) {
|
|
16858
|
+
return this.calls.get(id) ?? null;
|
|
16859
|
+
}
|
|
16860
|
+
/** Records currently held (newest last). */
|
|
16861
|
+
snapshot() {
|
|
16862
|
+
return this.records;
|
|
16863
|
+
}
|
|
16864
|
+
stop() {
|
|
16865
|
+
if (this.timer) clearInterval(this.timer);
|
|
16866
|
+
this.timer = null;
|
|
16867
|
+
this.watcher?.close();
|
|
16868
|
+
this.watcher = null;
|
|
16869
|
+
}
|
|
16870
|
+
}
|
|
16871
|
+
class OpenCodeError extends Error {
|
|
16872
|
+
constructor(message2, status2 = 503) {
|
|
16873
|
+
super(message2);
|
|
16874
|
+
this.status = status2;
|
|
16875
|
+
}
|
|
16876
|
+
status;
|
|
16877
|
+
}
|
|
16878
|
+
const REQUEST_BYTES = 8 * 1024 * 1024;
|
|
16879
|
+
const TIMEOUT_MS$1 = 5e3;
|
|
16880
|
+
const SESSION_ID = /^ses_[A-Za-z0-9_-]{1,120}$/;
|
|
16881
|
+
const REQUEST_ID = /^(?:per|que)_[A-Za-z0-9_-]{1,120}$/;
|
|
16882
|
+
function object$1(value) {
|
|
16883
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
16884
|
+
throw new OpenCodeError("OpenCode returned an invalid object.");
|
|
16885
|
+
return value;
|
|
16886
|
+
}
|
|
16887
|
+
function list(value) {
|
|
16888
|
+
if (!Array.isArray(value)) throw new OpenCodeError("OpenCode returned an invalid list.");
|
|
16889
|
+
return value;
|
|
16890
|
+
}
|
|
16891
|
+
function text(value) {
|
|
16892
|
+
if (typeof value !== "string") throw new OpenCodeError("OpenCode returned invalid text.");
|
|
16893
|
+
return value;
|
|
16894
|
+
}
|
|
16895
|
+
function parseOpenCodeConnection(raw) {
|
|
16896
|
+
const value = object$1(raw);
|
|
16897
|
+
const url = text(value.url);
|
|
16898
|
+
let endpoint;
|
|
16899
|
+
try {
|
|
16900
|
+
endpoint = new URL(url);
|
|
16901
|
+
} catch {
|
|
16902
|
+
throw new OpenCodeError("The OpenCode endpoint must be a loopback HTTP URL.");
|
|
16903
|
+
}
|
|
16904
|
+
if (endpoint.protocol !== "http:" || !["127.0.0.1", "[::1]"].includes(endpoint.hostname) || !endpoint.port || url !== endpoint.origin && url !== `${endpoint.origin}/`)
|
|
16905
|
+
throw new OpenCodeError(
|
|
16906
|
+
"The OpenCode endpoint must use 127.0.0.1 or [::1] and an explicit HTTP port."
|
|
16907
|
+
);
|
|
16908
|
+
const sessionId = text(value.sessionId);
|
|
16909
|
+
if (!SESSION_ID.test(sessionId)) throw new OpenCodeError("The OpenCode session ID is invalid.");
|
|
16910
|
+
const directory = text(value.directory);
|
|
16911
|
+
if (!path.isAbsolute(directory) || directory.includes("\0"))
|
|
16912
|
+
throw new OpenCodeError("The OpenCode directory must be absolute.");
|
|
16913
|
+
const username = text(value.username);
|
|
16914
|
+
const password = text(value.password);
|
|
16915
|
+
if (!username || username.length > 128 || /[:\r\n\0]/.test(username) || !password || password.length > 512 || /[\r\n\0]/.test(password))
|
|
16916
|
+
throw new OpenCodeError("The OpenCode connection needs valid private credentials.");
|
|
16917
|
+
return {
|
|
16918
|
+
url: endpoint.origin,
|
|
16919
|
+
sessionId,
|
|
16920
|
+
username,
|
|
16921
|
+
password,
|
|
16922
|
+
directory: path.resolve(directory)
|
|
16923
|
+
};
|
|
16924
|
+
}
|
|
16925
|
+
async function request(connection, route, body, signal, allowMissing = false) {
|
|
16926
|
+
const conn = parseOpenCodeConnection(connection);
|
|
16927
|
+
const controller = new AbortController();
|
|
16928
|
+
const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS$1);
|
|
16929
|
+
try {
|
|
16930
|
+
const response = await fetch(`${conn.url}${route}`, {
|
|
16931
|
+
method: body === void 0 ? "GET" : "POST",
|
|
16932
|
+
redirect: "error",
|
|
16933
|
+
signal: signal ? AbortSignal.any([signal, controller.signal]) : controller.signal,
|
|
16934
|
+
headers: {
|
|
16935
|
+
authorization: `Basic ${Buffer.from(`${conn.username}:${conn.password}`).toString("base64")}`,
|
|
16936
|
+
...body === void 0 ? {} : { "content-type": "application/json" }
|
|
16937
|
+
},
|
|
16938
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
16939
|
+
});
|
|
16940
|
+
if (response.status === 404 && allowMissing) {
|
|
16941
|
+
await response.body?.cancel();
|
|
16942
|
+
return null;
|
|
16943
|
+
}
|
|
16944
|
+
if (!response.ok) {
|
|
16945
|
+
await response.body?.cancel();
|
|
16946
|
+
throw new OpenCodeError(
|
|
16947
|
+
`OpenCode returned HTTP ${response.status}.`,
|
|
16948
|
+
response.status === 404 ? 409 : 503
|
|
16949
|
+
);
|
|
16950
|
+
}
|
|
16951
|
+
if (response.status === 204) return null;
|
|
16952
|
+
const reader = response.body?.getReader();
|
|
16953
|
+
if (!reader) throw new OpenCodeError("OpenCode returned an empty response.");
|
|
16954
|
+
const chunks = [];
|
|
16955
|
+
let bytes = 0;
|
|
16956
|
+
while (true) {
|
|
16957
|
+
const part = await reader.read();
|
|
16958
|
+
if (part.done) break;
|
|
16959
|
+
bytes += part.value.length;
|
|
16960
|
+
if (bytes > REQUEST_BYTES) {
|
|
16961
|
+
await reader.cancel();
|
|
16962
|
+
throw new OpenCodeError("The OpenCode response exceeded the size limit.");
|
|
16963
|
+
}
|
|
16964
|
+
chunks.push(part.value);
|
|
16965
|
+
}
|
|
16966
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
16967
|
+
} catch (error) {
|
|
16968
|
+
if (error instanceof OpenCodeError) throw error;
|
|
16969
|
+
throw new OpenCodeError(
|
|
16970
|
+
"Could not read OpenCode. Check that its private session server is running."
|
|
16971
|
+
);
|
|
16972
|
+
} finally {
|
|
16973
|
+
clearTimeout(timeout);
|
|
16974
|
+
}
|
|
16975
|
+
}
|
|
16976
|
+
function sessionRoute(conn) {
|
|
16977
|
+
return `/api/session/${encodeURIComponent(conn.sessionId)}`;
|
|
16978
|
+
}
|
|
16979
|
+
function verifySession(raw, conn) {
|
|
16980
|
+
const session = object$1(object$1(raw).data);
|
|
16981
|
+
const location = object$1(session.location);
|
|
16982
|
+
if (session.id !== conn.sessionId || typeof location.directory !== "string" || !path.isAbsolute(location.directory) || path.resolve(location.directory) !== path.resolve(conn.directory))
|
|
16983
|
+
throw new OpenCodeError("The OpenCode session does not match this Firstmate checkout.");
|
|
16984
|
+
}
|
|
16985
|
+
async function boundSession(conn, signal) {
|
|
16986
|
+
verifySession(await request(conn, sessionRoute(conn), void 0, signal), conn);
|
|
16987
|
+
}
|
|
16988
|
+
async function createOpenCodeSession(connection) {
|
|
16989
|
+
const conn = parseOpenCodeConnection(connection);
|
|
16990
|
+
const existing = await request(conn, sessionRoute(conn), void 0, void 0, true);
|
|
16991
|
+
if (existing) {
|
|
16992
|
+
verifySession(existing, conn);
|
|
16993
|
+
return;
|
|
16994
|
+
}
|
|
16995
|
+
try {
|
|
16996
|
+
verifySession(
|
|
16997
|
+
await request(conn, "/api/session", {
|
|
16998
|
+
id: conn.sessionId,
|
|
16999
|
+
location: { directory: conn.directory }
|
|
17000
|
+
}),
|
|
17001
|
+
conn
|
|
17002
|
+
);
|
|
17003
|
+
} catch (error) {
|
|
17004
|
+
const created = await request(conn, sessionRoute(conn), void 0, void 0, true);
|
|
17005
|
+
if (!created) throw error;
|
|
17006
|
+
verifySession(created, conn);
|
|
17007
|
+
}
|
|
17008
|
+
}
|
|
17009
|
+
async function selectOpenCodeSession(conn) {
|
|
17010
|
+
await boundSession(conn);
|
|
17011
|
+
const selected = await request(
|
|
17012
|
+
conn,
|
|
17013
|
+
`/tui/select-session?directory=${encodeURIComponent(conn.directory)}`,
|
|
17014
|
+
{ sessionID: conn.sessionId }
|
|
17015
|
+
);
|
|
17016
|
+
if (selected !== true) throw new OpenCodeError("OpenCode did not select the bound session.");
|
|
17017
|
+
}
|
|
17018
|
+
function timestamp(value) {
|
|
17019
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isFinite(new Date(value).getTime()))
|
|
17020
|
+
throw new OpenCodeError("OpenCode returned an invalid message timestamp.");
|
|
17021
|
+
return new Date(value).toISOString();
|
|
17022
|
+
}
|
|
17023
|
+
function cut(value) {
|
|
17024
|
+
return value.length > MAX_RESULT_CHARS ? `${value.slice(0, MAX_RESULT_CHARS)}
|
|
17025
|
+
… (more in the terminal)` : value;
|
|
17026
|
+
}
|
|
17027
|
+
function toolContent(value) {
|
|
17028
|
+
if (!Array.isArray(value)) return "";
|
|
17029
|
+
return cut(
|
|
17030
|
+
value.flatMap((raw) => {
|
|
17031
|
+
const part = object$1(raw);
|
|
17032
|
+
return part.type === "text" && typeof part.text === "string" ? [part.text] : [];
|
|
17033
|
+
}).join("\n")
|
|
17034
|
+
);
|
|
17035
|
+
}
|
|
17036
|
+
function messageRecords(raw) {
|
|
17037
|
+
const message2 = object$1(raw);
|
|
17038
|
+
const id = text(message2.id);
|
|
17039
|
+
const time = object$1(message2.time);
|
|
17040
|
+
const at = timestamp(time.created);
|
|
17041
|
+
const base = { uuid: `opencode:${id}`, timestamp: at };
|
|
17042
|
+
if (message2.type === "user" || message2.type === "synthetic") {
|
|
17043
|
+
return [
|
|
17044
|
+
{
|
|
17045
|
+
...base,
|
|
17046
|
+
type: "user",
|
|
17047
|
+
isMeta: message2.type === "synthetic",
|
|
17048
|
+
message: { role: "user", content: text(message2.text) }
|
|
17049
|
+
}
|
|
17050
|
+
];
|
|
17051
|
+
}
|
|
17052
|
+
if (message2.type === "compaction")
|
|
17053
|
+
return [
|
|
17054
|
+
{ ...base, type: "system", subtype: "away_summary", content: cut(text(message2.summary)) }
|
|
17055
|
+
];
|
|
17056
|
+
if (message2.type !== "assistant") return [];
|
|
17057
|
+
const records2 = [];
|
|
17058
|
+
const assistant = (suffix, content) => ({
|
|
17059
|
+
type: "assistant",
|
|
17060
|
+
uuid: `${base.uuid}:${suffix}`,
|
|
17061
|
+
timestamp: at,
|
|
17062
|
+
message: { id: base.uuid, role: "assistant", content }
|
|
17063
|
+
});
|
|
17064
|
+
for (const rawPart of list(message2.content)) {
|
|
17065
|
+
const part = object$1(rawPart);
|
|
17066
|
+
const partId = text(part.id);
|
|
17067
|
+
if (part.type === "text")
|
|
17068
|
+
records2.push(assistant(partId, [{ type: "text", text: text(part.text) }]));
|
|
17069
|
+
else if (part.type === "reasoning")
|
|
17070
|
+
records2.push(assistant(partId, [{ type: "thinking", thinking: cut(text(part.text)) }]));
|
|
17071
|
+
else if (part.type === "tool") {
|
|
17072
|
+
const state = object$1(part.state);
|
|
17073
|
+
const name2 = text(part.name);
|
|
17074
|
+
const names = {
|
|
17075
|
+
bash: "Bash",
|
|
17076
|
+
shell: "Bash",
|
|
17077
|
+
read: "Read",
|
|
17078
|
+
write: "Write",
|
|
17079
|
+
edit: "Edit",
|
|
17080
|
+
glob: "Glob",
|
|
17081
|
+
grep: "Grep"
|
|
17082
|
+
};
|
|
17083
|
+
const toolId = `opencode:${partId}`;
|
|
17084
|
+
const input = typeof state.input === "string" ? { input: cut(state.input) } : object$1(state.input);
|
|
17085
|
+
records2.push(
|
|
17086
|
+
assistant(`${partId}:call`, [
|
|
17087
|
+
{ type: "tool_use", id: toolId, name: names[name2] ?? name2, input }
|
|
17088
|
+
])
|
|
17089
|
+
);
|
|
17090
|
+
if (state.status === "completed" || state.status === "error") {
|
|
17091
|
+
const error = state.error ? object$1(state.error) : null;
|
|
17092
|
+
const result2 = toolContent(state.content) || (typeof error?.message === "string" ? cut(error.message) : "");
|
|
17093
|
+
records2.push({
|
|
17094
|
+
type: "user",
|
|
17095
|
+
uuid: `${base.uuid}:${partId}:result`,
|
|
17096
|
+
timestamp: at,
|
|
17097
|
+
message: {
|
|
17098
|
+
role: "user",
|
|
17099
|
+
content: [
|
|
17100
|
+
{
|
|
17101
|
+
type: "tool_result",
|
|
17102
|
+
tool_use_id: toolId,
|
|
17103
|
+
content: result2,
|
|
17104
|
+
is_error: state.status === "error"
|
|
17105
|
+
}
|
|
17106
|
+
]
|
|
17107
|
+
}
|
|
17108
|
+
});
|
|
17109
|
+
}
|
|
17110
|
+
}
|
|
17111
|
+
}
|
|
17112
|
+
if (message2.error) {
|
|
17113
|
+
const error = object$1(message2.error);
|
|
17114
|
+
records2.push(assistant("error", [{ type: "text", text: cut(text(error.message)) }]));
|
|
17115
|
+
}
|
|
17116
|
+
if (time.completed !== void 0 && (message2.error || message2.finish !== "tool-calls")) {
|
|
17117
|
+
const completed = timestamp(time.completed);
|
|
17118
|
+
records2.push({
|
|
17119
|
+
type: "system",
|
|
17120
|
+
uuid: `${base.uuid}:completed`,
|
|
17121
|
+
timestamp: completed,
|
|
17122
|
+
subtype: "turn_duration",
|
|
17123
|
+
durationMs: Math.max(0, Date.parse(completed) - Date.parse(at))
|
|
17124
|
+
});
|
|
17125
|
+
}
|
|
17126
|
+
return records2;
|
|
17127
|
+
}
|
|
17128
|
+
const histories = /* @__PURE__ */ new Map();
|
|
17129
|
+
async function admissions(conn, signal) {
|
|
17130
|
+
const key = JSON.stringify([conn.url, conn.sessionId, conn.directory]);
|
|
17131
|
+
let history = histories.get(key);
|
|
17132
|
+
if (!history) {
|
|
17133
|
+
history = { sequence: 0, admissions: /* @__PURE__ */ new Map() };
|
|
17134
|
+
histories.set(key, history);
|
|
17135
|
+
if (histories.size > 8) histories.delete(histories.keys().next().value ?? "");
|
|
17136
|
+
}
|
|
17137
|
+
for (let page = 0; page < 24; page++) {
|
|
17138
|
+
const response = object$1(
|
|
17139
|
+
await request(
|
|
17140
|
+
conn,
|
|
17141
|
+
`${sessionRoute(conn)}/history?after=${history.sequence}&limit=100`,
|
|
17142
|
+
void 0,
|
|
17143
|
+
signal
|
|
17144
|
+
)
|
|
17145
|
+
);
|
|
17146
|
+
const rows = list(response.data);
|
|
17147
|
+
let sequence = history.sequence;
|
|
17148
|
+
for (const raw of rows) {
|
|
17149
|
+
const event = object$1(raw);
|
|
17150
|
+
const durable = object$1(event.durable);
|
|
17151
|
+
const data = object$1(event.data);
|
|
17152
|
+
if (durable.aggregateID !== conn.sessionId || data.sessionID !== conn.sessionId || typeof durable.seq !== "number" || !Number.isSafeInteger(durable.seq) || durable.seq <= sequence)
|
|
17153
|
+
throw new OpenCodeError("OpenCode returned history outside the bound session or cursor.");
|
|
17154
|
+
sequence = durable.seq;
|
|
17155
|
+
if (event.type === "session.next.prompt.admitted" || event.type === "session.next.prompted") {
|
|
17156
|
+
const prompt = object$1(data.prompt);
|
|
17157
|
+
const id = text(data.messageID);
|
|
17158
|
+
timestamp(data.timestamp);
|
|
17159
|
+
if (typeof data.timestamp !== "number")
|
|
17160
|
+
throw new OpenCodeError("Invalid OpenCode admission timestamp.");
|
|
17161
|
+
history.admissions.set(id, {
|
|
17162
|
+
id,
|
|
17163
|
+
type: "user",
|
|
17164
|
+
text: text(prompt.text),
|
|
17165
|
+
time: { created: data.timestamp }
|
|
17166
|
+
});
|
|
17167
|
+
if (history.admissions.size > MAX_RECORDS)
|
|
17168
|
+
history.admissions.delete(history.admissions.keys().next().value ?? "");
|
|
17169
|
+
}
|
|
17170
|
+
}
|
|
17171
|
+
history.sequence = Math.max(history.sequence, sequence);
|
|
17172
|
+
if (response.hasMore === false) return [...history.admissions.values()];
|
|
17173
|
+
if (response.hasMore !== true || !rows.length)
|
|
17174
|
+
throw new OpenCodeError("OpenCode returned an invalid history cursor.");
|
|
17175
|
+
}
|
|
17176
|
+
throw new OpenCodeError("OpenCode conversation history is still catching up. Retry shortly.");
|
|
17177
|
+
}
|
|
17178
|
+
async function openCodeSnapshot(connection) {
|
|
17179
|
+
const conn = parseOpenCodeConnection(connection);
|
|
17180
|
+
const signal = AbortSignal.timeout(15e3);
|
|
17181
|
+
await boundSession(conn, signal);
|
|
17182
|
+
const messages = [];
|
|
17183
|
+
let cursor = null;
|
|
17184
|
+
let more = false;
|
|
17185
|
+
const seen = /* @__PURE__ */ new Set();
|
|
17186
|
+
do {
|
|
17187
|
+
const query = cursor ? `cursor=${encodeURIComponent(cursor)}` : "order=desc";
|
|
17188
|
+
const page = object$1(
|
|
17189
|
+
await request(conn, `${sessionRoute(conn)}/message?limit=200&${query}`, void 0, signal)
|
|
17190
|
+
);
|
|
17191
|
+
messages.push(...list(page.data));
|
|
17192
|
+
const next = object$1(page.cursor).next;
|
|
17193
|
+
if (next !== null && typeof next !== "string")
|
|
17194
|
+
throw new OpenCodeError("OpenCode returned an invalid message cursor.");
|
|
17195
|
+
cursor = next;
|
|
17196
|
+
more = cursor !== null;
|
|
17197
|
+
if (cursor && seen.has(cursor)) throw new OpenCodeError("OpenCode repeated a message cursor.");
|
|
17198
|
+
if (cursor) seen.add(cursor);
|
|
17199
|
+
} while (more && messages.length < MAX_RECORDS);
|
|
17200
|
+
messages.reverse();
|
|
17201
|
+
const projected = new Set(messages.map((raw) => text(object$1(raw).id)));
|
|
17202
|
+
const queued = (await admissions(conn, signal)).filter((entry) => !projected.has(entry.id));
|
|
17203
|
+
const combined = [...messages, ...queued].map((raw) => {
|
|
17204
|
+
const value = object$1(raw);
|
|
17205
|
+
const at = Date.parse(timestamp(object$1(value.time).created));
|
|
17206
|
+
return { raw, at };
|
|
17207
|
+
}).sort((a, b) => a.at - b.at);
|
|
17208
|
+
const records2 = combined.flatMap(({ raw }) => messageRecords(raw));
|
|
17209
|
+
return {
|
|
17210
|
+
source: {
|
|
17211
|
+
how: "api",
|
|
17212
|
+
file: `opencode:${conn.url}/${conn.sessionId}`,
|
|
17213
|
+
truncated: more || records2.length > MAX_RECORDS
|
|
17214
|
+
},
|
|
17215
|
+
records: records2.slice(-MAX_RECORDS)
|
|
17216
|
+
};
|
|
17217
|
+
}
|
|
17218
|
+
async function pending(conn) {
|
|
17219
|
+
await boundSession(conn);
|
|
17220
|
+
const [permissions, questions] = await Promise.all([
|
|
17221
|
+
request(conn, `${sessionRoute(conn)}/permission`),
|
|
17222
|
+
request(conn, `${sessionRoute(conn)}/question`)
|
|
17223
|
+
]);
|
|
17224
|
+
const permissionList = list(object$1(permissions).data);
|
|
17225
|
+
const questionList = list(object$1(questions).data);
|
|
17226
|
+
const raw = permissionList[0] ?? questionList[0];
|
|
17227
|
+
if (!raw) return null;
|
|
17228
|
+
const item = object$1(raw);
|
|
17229
|
+
const id = text(item.id);
|
|
17230
|
+
if (!REQUEST_ID.test(id) || item.sessionID !== conn.sessionId)
|
|
17231
|
+
throw new OpenCodeError("OpenCode returned an interaction outside the bound session.");
|
|
17232
|
+
const kind = permissionList.length ? "permission" : "question";
|
|
17233
|
+
const signature = `opencode:${createHash("sha256").update(JSON.stringify([conn.sessionId, kind, item])).digest("hex").slice(0, 32)}`;
|
|
17234
|
+
let title;
|
|
17235
|
+
let options;
|
|
17236
|
+
if (kind === "permission") {
|
|
17237
|
+
title = `Allow ${text(item.action)}?
|
|
17238
|
+
${list(item.resources).map(text).join("\n")}`;
|
|
17239
|
+
options = [
|
|
17240
|
+
{
|
|
17241
|
+
n: 1,
|
|
17242
|
+
label: "Allow once",
|
|
17243
|
+
description: "Allow this request only.",
|
|
17244
|
+
checked: null,
|
|
17245
|
+
freeText: false
|
|
17246
|
+
},
|
|
17247
|
+
{
|
|
17248
|
+
n: 2,
|
|
17249
|
+
label: "Reject",
|
|
17250
|
+
description: "Do not allow this request.",
|
|
17251
|
+
checked: null,
|
|
17252
|
+
freeText: false
|
|
17253
|
+
}
|
|
17254
|
+
];
|
|
17255
|
+
} else {
|
|
17256
|
+
const entries = list(item.questions);
|
|
17257
|
+
if (entries.length !== 1)
|
|
17258
|
+
return { menu: { title: "Answer OpenCode’s questions in its terminal.", canDismiss: false } };
|
|
17259
|
+
const question = object$1(entries[0]);
|
|
17260
|
+
if (question.multiple === true)
|
|
17261
|
+
return {
|
|
17262
|
+
menu: {
|
|
17263
|
+
title: "Answer OpenCode’s multiple-choice question in its terminal.",
|
|
17264
|
+
canDismiss: false
|
|
17265
|
+
}
|
|
17266
|
+
};
|
|
17267
|
+
title = text(question.question);
|
|
17268
|
+
options = list(question.options).map((rawOption, i) => {
|
|
17269
|
+
const option = object$1(rawOption);
|
|
17270
|
+
return {
|
|
17271
|
+
n: i + 1,
|
|
17272
|
+
label: text(option.label),
|
|
17273
|
+
description: text(option.description),
|
|
17274
|
+
checked: null,
|
|
17275
|
+
freeText: false
|
|
17276
|
+
};
|
|
17277
|
+
});
|
|
17278
|
+
if (!options.length || options.length > 20)
|
|
17279
|
+
return {
|
|
17280
|
+
menu: { title: "Answer this OpenCode question in its terminal.", canDismiss: false }
|
|
17281
|
+
};
|
|
17282
|
+
if (question.custom !== false)
|
|
17283
|
+
options.push({
|
|
17284
|
+
n: options.length + 1,
|
|
17285
|
+
label: "Type an answer",
|
|
17286
|
+
description: "",
|
|
17287
|
+
checked: null,
|
|
17288
|
+
freeText: true
|
|
17289
|
+
});
|
|
17290
|
+
}
|
|
17291
|
+
if (title.length > 16e3)
|
|
17292
|
+
return { menu: { title: "Review this OpenCode request in its terminal.", canDismiss: false } };
|
|
17293
|
+
return {
|
|
17294
|
+
id,
|
|
17295
|
+
kind,
|
|
17296
|
+
picker: { title, signature, options, tabs: [], multiSelect: false, submitMoves: null }
|
|
17297
|
+
};
|
|
17298
|
+
}
|
|
17299
|
+
async function openCodeStatus(conn) {
|
|
17300
|
+
const [interaction, active] = await Promise.all([
|
|
17301
|
+
pending(conn),
|
|
17302
|
+
request(conn, "/api/session/active")
|
|
17303
|
+
]);
|
|
17304
|
+
const running2 = object$1(object$1(active).data)[conn.sessionId];
|
|
17305
|
+
if (running2 !== void 0 && object$1(running2).type !== "running")
|
|
17306
|
+
throw new OpenCodeError("OpenCode returned an unknown execution state.");
|
|
17307
|
+
return {
|
|
17308
|
+
picker: interaction && "picker" in interaction ? interaction.picker : null,
|
|
17309
|
+
menu: interaction && "menu" in interaction ? interaction.menu : null,
|
|
17310
|
+
busy: running2 !== void 0
|
|
17311
|
+
};
|
|
17312
|
+
}
|
|
17313
|
+
async function pendingOpenCodePicker(conn) {
|
|
17314
|
+
const interaction = await pending(conn);
|
|
17315
|
+
return interaction && "picker" in interaction ? interaction.picker : null;
|
|
17316
|
+
}
|
|
17317
|
+
async function answerOpenCodePicker(conn, signature, action) {
|
|
17318
|
+
const current = await pending(conn);
|
|
17319
|
+
if (!current || !("picker" in current) || current.picker.signature !== signature)
|
|
17320
|
+
throw new OpenCodeError("That OpenCode choice is no longer waiting for an answer.", 409);
|
|
17321
|
+
if (!("press" in action) || !Number.isInteger(action.press))
|
|
17322
|
+
throw new OpenCodeError("Choose one of the available answers.", 400);
|
|
17323
|
+
const option = current.picker.options.find((entry) => entry.n === action.press);
|
|
17324
|
+
if (!option || option.freeText)
|
|
17325
|
+
throw new OpenCodeError("Choose an available answer, or type in the terminal.", 400);
|
|
17326
|
+
const route = `${sessionRoute(conn)}/${current.kind}/${encodeURIComponent(current.id)}/reply`;
|
|
17327
|
+
await request(
|
|
17328
|
+
conn,
|
|
17329
|
+
route,
|
|
17330
|
+
current.kind === "permission" ? { reply: action.press === 1 ? "once" : "reject" } : { answers: [[option.label]] }
|
|
17331
|
+
);
|
|
17332
|
+
}
|
|
17333
|
+
async function sendOpenCode(conn, text2) {
|
|
17334
|
+
const message2 = text2.replace(/\r\n?/g, "\n").trim();
|
|
17335
|
+
if (!message2 || message2.includes("\0") || Buffer.byteLength(message2) > 64 * 1024)
|
|
17336
|
+
throw new OpenCodeError("The message must be valid text of at most 64 KiB.", 400);
|
|
17337
|
+
if (await pending(conn))
|
|
17338
|
+
throw new OpenCodeError(
|
|
17339
|
+
"Answer OpenCode’s pending request before sending another message.",
|
|
17340
|
+
409
|
|
17341
|
+
);
|
|
17342
|
+
await request(conn, `${sessionRoute(conn)}/prompt`, {
|
|
17343
|
+
id: `msg_${randomUUID().replace(/-/g, "")}`,
|
|
17344
|
+
prompt: { text: message2 },
|
|
17345
|
+
delivery: "steer"
|
|
17346
|
+
});
|
|
17347
|
+
}
|
|
17348
|
+
async function interruptOpenCode(conn) {
|
|
17349
|
+
await boundSession(conn);
|
|
17350
|
+
await request(conn, `${sessionRoute(conn)}/interrupt`, {});
|
|
17351
|
+
}
|
|
17352
|
+
const INPUT_MAX_BYTES = 64 * 1024;
|
|
17353
|
+
const HOOK_RECORD = path.join("firstmate", "session-start.json");
|
|
17354
|
+
const PASTE_SETTLE_MS = 400;
|
|
17355
|
+
const KEY_GAP_MS = 120;
|
|
17356
|
+
const DISMISS_MAX = 5;
|
|
17357
|
+
const MENU_SETTLE_MS = 400;
|
|
17358
|
+
const MENU_REDRAW_WAITS = 5;
|
|
17359
|
+
const menuPart = (text2) => text2?.slice(Math.max(0, text2.lastIndexOf("▔"))) ?? null;
|
|
17360
|
+
const MENU_OPEN = "A Claude Code menu is open in Firstmate’s session, so nothing was typed. Answer or close it, then send again.";
|
|
17361
|
+
function sessionSettings(hookFile, skipPermissions) {
|
|
17362
|
+
const tmp = `${hookFile}.tmp`;
|
|
17363
|
+
const command = `cat > ${shellLine([tmp])} && mv -f ${shellLine([tmp])} ${shellLine([hookFile])}`;
|
|
17364
|
+
const settings = {
|
|
17365
|
+
hooks: { SessionStart: [{ hooks: [{ type: "command", command, timeout: 10 }] }] }
|
|
17366
|
+
};
|
|
17367
|
+
if (skipPermissions) settings.skipDangerousModePermissionPrompt = true;
|
|
17368
|
+
return JSON.stringify(settings);
|
|
17369
|
+
}
|
|
17370
|
+
function claudeArgv(claude, hookFile, skipPermissions) {
|
|
17371
|
+
const argv = [claude];
|
|
17372
|
+
if (skipPermissions) argv.push("--dangerously-skip-permissions");
|
|
17373
|
+
argv.push("--settings", sessionSettings(hookFile, skipPermissions));
|
|
17374
|
+
return argv;
|
|
17375
|
+
}
|
|
17376
|
+
function codexArgv(binary) {
|
|
17377
|
+
const script = `const fs = require('node:fs');
|
|
17378
|
+
let input = '';
|
|
17379
|
+
process.stdin.setEncoding('utf8');
|
|
17380
|
+
process.stdin.on('data', chunk => { input += chunk; if (Buffer.byteLength(input) > 65536) process.exit(1); });
|
|
17381
|
+
process.stdin.on('end', () => {
|
|
17382
|
+
const record = JSON.parse(input);
|
|
17383
|
+
const file = process.env.WH_SESSION_RECORD;
|
|
17384
|
+
if (!file || !process.env.WH_SESSION_NONCE) process.exit(1);
|
|
17385
|
+
fs.writeFileSync(file + '.tmp', JSON.stringify({...record, wheelhouse_nonce: process.env.WH_SESSION_NONCE}), {mode: 0o600});
|
|
17386
|
+
fs.renameSync(file + '.tmp', file);
|
|
17387
|
+
});`;
|
|
17388
|
+
const command = shellLine([process.execPath, "-e", script]);
|
|
17389
|
+
return [
|
|
17390
|
+
binary,
|
|
17391
|
+
"-c",
|
|
17392
|
+
`hooks.SessionStart=[{hooks=[{type="command",command=${JSON.stringify(command)},timeout=10}]}]`
|
|
17393
|
+
];
|
|
17394
|
+
}
|
|
17395
|
+
function launchSpec(options) {
|
|
17396
|
+
const { binary, firstmateDir, hookFile, fmHome } = options;
|
|
17397
|
+
let command;
|
|
17398
|
+
const environment = [`WHEELHOUSE_HARNESS=${options.harness}`];
|
|
17399
|
+
switch (options.harness) {
|
|
17400
|
+
case "claude":
|
|
17401
|
+
command = claudeArgv(binary, hookFile, options.skipPermissions);
|
|
17402
|
+
break;
|
|
17403
|
+
case "codex":
|
|
17404
|
+
environment.push(`WH_SESSION_RECORD=${hookFile}`, `WH_SESSION_NONCE=${options.sessionNonce}`);
|
|
17405
|
+
command = codexArgv(binary);
|
|
17406
|
+
break;
|
|
17407
|
+
case "pi":
|
|
17408
|
+
environment.push(`WH_SESSION_RECORD=${hookFile}`, `WH_SESSION_NONCE=${options.sessionNonce}`);
|
|
17409
|
+
command = [binary, "--extension", options.extensionFile];
|
|
17410
|
+
break;
|
|
17411
|
+
case "opencode":
|
|
17412
|
+
environment.push(`WH_OPENCODE_CONNECTION=${options.connectionFile}`);
|
|
17413
|
+
command = [
|
|
17414
|
+
process.execPath,
|
|
17415
|
+
"-e",
|
|
17416
|
+
`const fs = require('node:fs');
|
|
17417
|
+
const {spawn} = require('node:child_process');
|
|
17418
|
+
const connection = JSON.parse(fs.readFileSync(process.argv[1], 'utf8'));
|
|
17419
|
+
const child = spawn(process.argv[2], ['--hostname', '127.0.0.1', '--port', new URL(connection.url).port], {
|
|
17420
|
+
stdio: 'inherit', env: {...process.env, OPENCODE_SERVER_USERNAME: connection.username, OPENCODE_SERVER_PASSWORD: connection.password}
|
|
17421
|
+
});
|
|
17422
|
+
child.on('error', () => { console.error('OpenCode could not start.'); process.exitCode = 1; });
|
|
17423
|
+
child.on('exit', code => { process.exitCode = code ?? 1; })`,
|
|
17424
|
+
options.connectionFile,
|
|
17425
|
+
binary
|
|
17426
|
+
];
|
|
17427
|
+
break;
|
|
17428
|
+
}
|
|
17429
|
+
if (fmHome) environment.push(`FM_HOME=${fmHome}`);
|
|
17430
|
+
const env = {};
|
|
17431
|
+
for (const value of environment) {
|
|
17432
|
+
const at = value.indexOf("=");
|
|
17433
|
+
env[value.slice(0, at)] = value.slice(at + 1);
|
|
17434
|
+
}
|
|
17435
|
+
return { cwd: firstmateDir, argv: command, env };
|
|
17436
|
+
}
|
|
17437
|
+
class FirstmateSession {
|
|
17438
|
+
harness;
|
|
17439
|
+
activeHarness;
|
|
17440
|
+
nativeRecorder = false;
|
|
17441
|
+
nativeNonce = null;
|
|
17442
|
+
openCode = null;
|
|
17443
|
+
get openCodeConnection() {
|
|
17444
|
+
return this.openCode;
|
|
17445
|
+
}
|
|
17446
|
+
get sessionNonce() {
|
|
17447
|
+
return this.nativeNonce;
|
|
17448
|
+
}
|
|
17449
|
+
firstmateDir;
|
|
17450
|
+
homeDir;
|
|
17451
|
+
hookFile;
|
|
17452
|
+
skipPermissions;
|
|
17453
|
+
backend;
|
|
17454
|
+
stateDir;
|
|
17455
|
+
lock;
|
|
17456
|
+
env;
|
|
17457
|
+
find;
|
|
17458
|
+
trustStore;
|
|
17459
|
+
sleep;
|
|
17460
|
+
starting = null;
|
|
17461
|
+
/** One input at a time, in order, so two messages never interleave in the paste buffer. */
|
|
17462
|
+
queue = Promise.resolve();
|
|
17463
|
+
constructor(opts) {
|
|
17464
|
+
this.harness = opts.harness ?? parseHarness((opts.env ?? process.env).WHEELHOUSE_HARNESS);
|
|
17465
|
+
this.activeHarness = this.harness;
|
|
17466
|
+
this.firstmateDir = path.resolve(opts.firstmateDir);
|
|
17467
|
+
this.homeDir = path.resolve(opts.homeDir);
|
|
17468
|
+
this.stateDir = path.resolve(opts.stateDir);
|
|
17469
|
+
this.hookFile = path.join(this.stateDir, HOOK_RECORD);
|
|
17470
|
+
this.lock = opts.lock;
|
|
17471
|
+
this.skipPermissions = this.harness === "claude" && (opts.skipPermissions ?? true);
|
|
17472
|
+
this.env = sessionEnv(opts.env ?? process.env);
|
|
17473
|
+
this.find = opts.find ?? ((name2) => which(name2, this.env.PATH));
|
|
17474
|
+
this.backend = opts.backend ?? new TmuxBackend({ socket: opts.tmuxSocket, env: this.env, find: this.find, run: opts.run });
|
|
17475
|
+
this.trustStore = opts.trustStore === void 0 ? claudeStore(this.env) : opts.trustStore;
|
|
17476
|
+
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
17477
|
+
}
|
|
17478
|
+
/** Why Wheelhouse cannot start or talk to a session here, or null. */
|
|
17479
|
+
unavailable(requireHarness = true) {
|
|
17480
|
+
const backend = this.backend.unavailable();
|
|
17481
|
+
if (backend) return backend;
|
|
17482
|
+
if (requireHarness && !this.find(this.harness)) {
|
|
17483
|
+
return `${HARNESS_NAMES[this.harness]} (\`${this.harness}\`) is not installed or not on PATH. Install it and restart Wheelhouse.`;
|
|
17484
|
+
}
|
|
17485
|
+
if (isInside(this.stateDir, this.homeDir)) {
|
|
17486
|
+
return `The Wheelhouse state directory ${this.stateDir} is inside the Firstmate home; choose one outside it.`;
|
|
17487
|
+
}
|
|
17488
|
+
return null;
|
|
17489
|
+
}
|
|
17490
|
+
/** The backend could not say whether the session runs. */
|
|
17491
|
+
get cannotAsk() {
|
|
17492
|
+
return `Wheelhouse could not ask ${this.backend.label} about the session.`;
|
|
17493
|
+
}
|
|
17494
|
+
/**
|
|
17495
|
+
* Whether the backend's Firstmate session is running; null when the backend
|
|
17496
|
+
* cannot say. A running session's harness, and the recorder or connection
|
|
17497
|
+
* it was started with, are read back from the variables it was launched with.
|
|
17498
|
+
*/
|
|
17499
|
+
async running() {
|
|
17500
|
+
const running2 = await this.backend.running();
|
|
17501
|
+
if (running2 === false) this.activeHarness = this.harness;
|
|
17502
|
+
if (!running2) return running2;
|
|
17503
|
+
const saved = await this.backend.variable("WHEELHOUSE_HARNESS");
|
|
17504
|
+
if (saved === null) return null;
|
|
17505
|
+
try {
|
|
17506
|
+
this.activeHarness = parseHarness(saved || "claude");
|
|
17507
|
+
} catch {
|
|
17508
|
+
return null;
|
|
17509
|
+
}
|
|
17510
|
+
if (this.activeHarness === "codex" || this.activeHarness === "pi") {
|
|
17511
|
+
this.nativeRecorder = await this.backend.variable("WH_SESSION_RECORD") === this.hookFile;
|
|
17512
|
+
const value = await this.backend.variable("WH_SESSION_NONCE") ?? "";
|
|
17513
|
+
this.nativeNonce = /^[0-9a-f-]{36}$/.test(value) ? value : null;
|
|
17514
|
+
this.nativeRecorder &&= this.nativeNonce !== null;
|
|
17515
|
+
}
|
|
17516
|
+
if (this.activeHarness === "opencode") {
|
|
17517
|
+
this.openCode = null;
|
|
17518
|
+
const file = await this.backend.variable("WH_OPENCODE_CONNECTION") ?? "";
|
|
17519
|
+
try {
|
|
17520
|
+
if (!/^opencode-[0-9a-f-]{36}\.json$/.test(path.basename(file)) || await realpath(path.dirname(file)) !== await realpath(path.dirname(this.hookFile)))
|
|
17521
|
+
throw new Error("Wrong state directory");
|
|
17522
|
+
const connection = parseOpenCodeConnection(JSON.parse(await readFile(file, "utf8")));
|
|
17523
|
+
if (await realpath(connection.directory) !== await realpath(this.firstmateDir))
|
|
17524
|
+
throw new Error("Wrong Firstmate checkout");
|
|
17525
|
+
this.openCode = connection;
|
|
17526
|
+
} catch {
|
|
17527
|
+
}
|
|
17528
|
+
}
|
|
17529
|
+
return true;
|
|
17530
|
+
}
|
|
17531
|
+
view(state, reason, screen = { picker: null, menu: null, busy: false }) {
|
|
17532
|
+
const needsRestart = state === "ours" && (this.activeHarness === "codex" || this.activeHarness === "pi" ? !this.nativeRecorder : this.activeHarness === "opencode" && !this.openCode);
|
|
17533
|
+
return {
|
|
17534
|
+
schema: "wheelhouse-firstmate-session.v1",
|
|
17535
|
+
harness: this.activeHarness,
|
|
17536
|
+
state,
|
|
17537
|
+
reason: needsRestart ? `This ${this.activeHarness} session predates chat integration or belongs to another Wheelhouse state directory. Exit it in the terminal, then start Firstmate here again.` : reason,
|
|
17538
|
+
canSend: state === "ours" && !needsRestart,
|
|
17539
|
+
attach: state === "ours" ? this.backend.attachHint() : null,
|
|
17540
|
+
skipPermissions: this.activeHarness === "claude" && this.skipPermissions,
|
|
17541
|
+
...screen
|
|
17542
|
+
};
|
|
17543
|
+
}
|
|
17544
|
+
/** Wheelhouse's session's screen as text, or null. */
|
|
17545
|
+
screen() {
|
|
17546
|
+
return this.backend.screen();
|
|
17547
|
+
}
|
|
17548
|
+
/** The menu Claude Code is waiting on in Wheelhouse's session, read off its screen, or null. */
|
|
17549
|
+
async picker() {
|
|
17550
|
+
if (this.activeHarness === "opencode")
|
|
17551
|
+
return this.openCode ? pendingOpenCodePicker(this.openCode) : null;
|
|
17552
|
+
const text2 = await this.screen();
|
|
17553
|
+
if (this.activeHarness === "codex") {
|
|
17554
|
+
const shown = codexScreen(text2);
|
|
17555
|
+
return shown.kind === "picker" ? shown.picker : null;
|
|
17556
|
+
}
|
|
17557
|
+
if (this.activeHarness !== "claude") return null;
|
|
17558
|
+
return text2 === null ? null : parsePicker(text2);
|
|
17559
|
+
}
|
|
17560
|
+
/**
|
|
17561
|
+
* What the screen says: a menu Claude Code waits on (as choices when it has
|
|
17562
|
+
* numbered ones), and whether it is busy (it shows "esc to interrupt" while
|
|
17563
|
+
* working, before anything reaches the transcript).
|
|
17564
|
+
*/
|
|
17565
|
+
async onScreen() {
|
|
17566
|
+
if (this.activeHarness === "opencode") {
|
|
17567
|
+
try {
|
|
17568
|
+
if (this.openCode) return await openCodeStatus(this.openCode);
|
|
17569
|
+
} catch {
|
|
17570
|
+
}
|
|
17571
|
+
return {
|
|
17572
|
+
picker: null,
|
|
17573
|
+
menu: {
|
|
17574
|
+
title: "OpenCode’s session API is not ready. Retry shortly or open its terminal.",
|
|
17575
|
+
canDismiss: false
|
|
17576
|
+
},
|
|
17577
|
+
busy: false
|
|
17578
|
+
};
|
|
17579
|
+
}
|
|
17580
|
+
if (this.activeHarness === "codex" || this.activeHarness === "pi") {
|
|
17581
|
+
const text22 = await this.screen().catch(() => null);
|
|
17582
|
+
const shown = this.activeHarness === "codex" ? codexScreen(text22) : piScreen(text22);
|
|
17583
|
+
return {
|
|
17584
|
+
picker: shown.kind === "picker" ? shown.picker : null,
|
|
17585
|
+
menu: shown.kind === "blocked" ? { title: shown.title, canDismiss: false } : null,
|
|
17586
|
+
busy: shown.kind === "prompt" && shown.busy
|
|
17587
|
+
};
|
|
17588
|
+
}
|
|
17589
|
+
if (this.activeHarness !== "claude") return { picker: null, menu: null, busy: false };
|
|
17590
|
+
const text2 = await this.screen().catch(() => null);
|
|
17591
|
+
if (text2 === null) return { picker: null, menu: null, busy: false };
|
|
17592
|
+
return {
|
|
17593
|
+
picker: parsePicker(text2),
|
|
17594
|
+
menu: parseMenu(text2),
|
|
17595
|
+
busy: /\besc to interrupt\b/i.test(text2)
|
|
17596
|
+
};
|
|
17597
|
+
}
|
|
17598
|
+
/** Where the Firstmate session stands, as the page shows it. */
|
|
17599
|
+
async status() {
|
|
17600
|
+
const reason = this.unavailable();
|
|
17601
|
+
const ours = this.unavailable(false) ? null : await this.running();
|
|
17602
|
+
if (ours) return this.view("ours", null, await this.onScreen());
|
|
17603
|
+
const lock = await this.lock();
|
|
17604
|
+
if (lock === "held") {
|
|
17605
|
+
return this.view(
|
|
17606
|
+
"external",
|
|
17607
|
+
"Firstmate is running in another terminal, so Wheelhouse shows its conversation read-only and sends your messages to its inbox. To talk to it here directly, close it there and start it from Wheelhouse."
|
|
17608
|
+
);
|
|
17609
|
+
}
|
|
17610
|
+
if (reason) return this.view("unavailable", reason);
|
|
17611
|
+
if (ours === null) return this.view("unavailable", this.cannotAsk);
|
|
17612
|
+
if (this.starting) return this.view("starting", null);
|
|
17613
|
+
return this.view("none", "No Firstmate session is running.");
|
|
17614
|
+
}
|
|
17615
|
+
/**
|
|
17616
|
+
* Start the Firstmate session unless one is already running here or holds
|
|
17617
|
+
* Firstmate's session lock elsewhere. Safe to call repeatedly.
|
|
17618
|
+
*/
|
|
17619
|
+
ensure() {
|
|
17620
|
+
this.starting ??= this.start().finally(() => this.starting = null);
|
|
17621
|
+
return this.starting;
|
|
17622
|
+
}
|
|
17623
|
+
async start() {
|
|
17624
|
+
const boundary = this.unavailable(false);
|
|
17625
|
+
if (boundary) return this.view("unavailable", boundary);
|
|
17626
|
+
const ours = await this.running();
|
|
17627
|
+
if (ours) return this.view("ours", null);
|
|
17628
|
+
const reason = this.unavailable();
|
|
17629
|
+
if (reason) return this.view("unavailable", reason);
|
|
17630
|
+
if (ours === null) return this.view("unavailable", this.cannotAsk);
|
|
17631
|
+
const lock = await this.lock();
|
|
17632
|
+
if (lock === "held") return this.status();
|
|
17633
|
+
if (lock === "unknown") {
|
|
17634
|
+
return this.view(
|
|
17635
|
+
"unavailable",
|
|
17636
|
+
"Wheelhouse could not read Firstmate's session lock, so it did not start a session (it never risks a second one)."
|
|
17637
|
+
);
|
|
17638
|
+
}
|
|
17639
|
+
const binary = this.find(this.harness);
|
|
17640
|
+
if (!binary) return this.view("unavailable", `${this.harness} is no longer on PATH.`);
|
|
17641
|
+
try {
|
|
17642
|
+
await mkdir(path.dirname(this.hookFile), { recursive: true });
|
|
17643
|
+
} catch (e) {
|
|
17644
|
+
return this.view(
|
|
17645
|
+
"unavailable",
|
|
17646
|
+
`Wheelhouse could not create ${path.dirname(this.hookFile)}: ${e.message}`
|
|
17647
|
+
);
|
|
17648
|
+
}
|
|
17649
|
+
if (this.harness === "claude" && this.trustStore)
|
|
17650
|
+
registerTrust(this.trustStore, this.firstmateDir);
|
|
17651
|
+
const fmHome = this.homeDir !== this.firstmateDir ? this.homeDir : null;
|
|
17652
|
+
const nonce = randomUUID();
|
|
17653
|
+
const common = { binary, firstmateDir: this.firstmateDir, hookFile: this.hookFile, fmHome };
|
|
17654
|
+
let launch;
|
|
17655
|
+
try {
|
|
17656
|
+
switch (this.harness) {
|
|
17657
|
+
case "claude":
|
|
17658
|
+
launch = { ...common, harness: "claude", skipPermissions: this.skipPermissions };
|
|
17659
|
+
break;
|
|
17660
|
+
case "codex":
|
|
17661
|
+
launch = { ...common, harness: "codex", sessionNonce: nonce };
|
|
17662
|
+
break;
|
|
17663
|
+
case "pi": {
|
|
17664
|
+
const extensionFile = path.join(path.dirname(this.hookFile), "pi-extension.mjs");
|
|
17665
|
+
await writeFile(`${extensionFile}.${nonce}.tmp`, piExtensionSource(), { mode: 384 });
|
|
17666
|
+
await rename(`${extensionFile}.${nonce}.tmp`, extensionFile);
|
|
17667
|
+
launch = { ...common, harness: "pi", sessionNonce: nonce, extensionFile };
|
|
17668
|
+
break;
|
|
17669
|
+
}
|
|
17670
|
+
case "opencode": {
|
|
17671
|
+
const port = await new ServicePorts(path.join(this.stateDir, "primary-ports.json")).port(
|
|
17672
|
+
"opencode",
|
|
17673
|
+
null,
|
|
17674
|
+
4096,
|
|
17675
|
+
[],
|
|
17676
|
+
[]
|
|
17677
|
+
);
|
|
17678
|
+
const connection = parseOpenCodeConnection({
|
|
17679
|
+
url: `http://127.0.0.1:${port}`,
|
|
17680
|
+
directory: this.firstmateDir,
|
|
17681
|
+
sessionId: `ses_${nonce.replace(/-/g, "")}`,
|
|
17682
|
+
username: "wheelhouse",
|
|
17683
|
+
password: randomBytes(32).toString("hex")
|
|
17684
|
+
});
|
|
17685
|
+
const connectionFile = path.join(path.dirname(this.hookFile), `opencode-${nonce}.json`);
|
|
17686
|
+
await writeFile(connectionFile, JSON.stringify(connection), { mode: 384, flag: "wx" });
|
|
17687
|
+
this.openCode = connection;
|
|
17688
|
+
launch = { ...common, harness: "opencode", connectionFile };
|
|
17689
|
+
break;
|
|
17690
|
+
}
|
|
17691
|
+
}
|
|
17692
|
+
} catch (error) {
|
|
17693
|
+
return this.view(
|
|
17694
|
+
"unavailable",
|
|
17695
|
+
`Could not prepare ${this.harness}: ${error instanceof Error ? error.message : String(error)}`
|
|
17696
|
+
);
|
|
17697
|
+
}
|
|
17698
|
+
const r = await this.backend.start(launchSpec(launch));
|
|
17699
|
+
if (!r.ok) return this.view("unavailable", r.error);
|
|
17700
|
+
this.activeHarness = this.harness;
|
|
17701
|
+
this.nativeRecorder = this.harness === "codex" || this.harness === "pi";
|
|
17702
|
+
this.nativeNonce = this.nativeRecorder ? nonce : null;
|
|
17703
|
+
if (this.openCode && this.harness === "opencode") {
|
|
17704
|
+
const until = Date.now() + 2e4;
|
|
17705
|
+
let failure2 = "The native TUI is not ready.";
|
|
17706
|
+
while (Date.now() < until) {
|
|
17707
|
+
try {
|
|
17708
|
+
if (!(await this.screen())?.includes("┃"))
|
|
17709
|
+
throw new Error("The native TUI is not ready.");
|
|
17710
|
+
await createOpenCodeSession(this.openCode);
|
|
17711
|
+
await selectOpenCodeSession(this.openCode);
|
|
17712
|
+
return this.view("ours", null);
|
|
17713
|
+
} catch (error) {
|
|
17714
|
+
failure2 = error instanceof Error ? error.message : String(error);
|
|
17715
|
+
}
|
|
17716
|
+
await this.sleep(250);
|
|
17717
|
+
}
|
|
17718
|
+
return this.view(
|
|
17719
|
+
"ours",
|
|
17720
|
+
`OpenCode started but its chat could not be connected: ${failure2} Open its terminal, finish setup, then restart the primary.`
|
|
17721
|
+
);
|
|
16676
17722
|
}
|
|
16677
|
-
|
|
16678
|
-
|
|
16679
|
-
|
|
16680
|
-
|
|
16681
|
-
|
|
16682
|
-
|
|
16683
|
-
|
|
17723
|
+
return this.view("ours", null);
|
|
17724
|
+
}
|
|
17725
|
+
serial(work) {
|
|
17726
|
+
const next = this.queue.then(work, work);
|
|
17727
|
+
this.queue = next.catch(() => {
|
|
17728
|
+
});
|
|
17729
|
+
return next;
|
|
17730
|
+
}
|
|
17731
|
+
async ours() {
|
|
17732
|
+
const reason = this.unavailable(false);
|
|
17733
|
+
if (reason) return { ok: false, status: 503, error: reason };
|
|
17734
|
+
const running2 = await this.running();
|
|
17735
|
+
if (running2 === null) return { ok: false, status: 503, error: this.cannotAsk };
|
|
17736
|
+
if (!running2) {
|
|
17737
|
+
return {
|
|
17738
|
+
ok: false,
|
|
17739
|
+
status: 409,
|
|
17740
|
+
error: "Firstmate is not running in Wheelhouse, so there is nothing here to type into."
|
|
17741
|
+
};
|
|
16684
17742
|
}
|
|
16685
|
-
|
|
17743
|
+
return null;
|
|
16686
17744
|
}
|
|
16687
|
-
async
|
|
16688
|
-
|
|
16689
|
-
|
|
16690
|
-
|
|
16691
|
-
|
|
16692
|
-
|
|
16693
|
-
|
|
16694
|
-
|
|
16695
|
-
|
|
16696
|
-
|
|
16697
|
-
|
|
16698
|
-
|
|
16699
|
-
|
|
16700
|
-
|
|
16701
|
-
|
|
16702
|
-
|
|
16703
|
-
|
|
16704
|
-
|
|
16705
|
-
|
|
16706
|
-
|
|
16707
|
-
|
|
16708
|
-
lines.pop();
|
|
16709
|
-
if (startedMidway) lines.shift();
|
|
16710
|
-
const fresh = [];
|
|
16711
|
-
for (const line of lines) {
|
|
16712
|
-
if (!line.trim()) continue;
|
|
16713
|
-
try {
|
|
16714
|
-
const raw = JSON.parse(line);
|
|
16715
|
-
this.noteToolCalls(raw);
|
|
16716
|
-
const r = slim(raw);
|
|
16717
|
-
if (r) fresh.push(r);
|
|
16718
|
-
} catch {
|
|
16719
|
-
}
|
|
17745
|
+
async keys(keys) {
|
|
17746
|
+
for (const key of keys) {
|
|
17747
|
+
const r = await this.backend.key(key);
|
|
17748
|
+
if (!r.ok) return { ok: false, status: 500, error: r.error };
|
|
17749
|
+
await this.sleep(KEY_GAP_MS);
|
|
17750
|
+
}
|
|
17751
|
+
return { ok: true };
|
|
17752
|
+
}
|
|
17753
|
+
/** Type a message into the session and submit it. */
|
|
17754
|
+
send(text2) {
|
|
17755
|
+
return this.serial(async () => {
|
|
17756
|
+
const body = text2.replace(/\r\n?/g, "\n").trim();
|
|
17757
|
+
if (!body) return { ok: false, status: 400, error: "There is nothing to send." };
|
|
17758
|
+
if (body.includes("\0"))
|
|
17759
|
+
return { ok: false, status: 400, error: "The message is not valid text." };
|
|
17760
|
+
if (Buffer.byteLength(body) > INPUT_MAX_BYTES) {
|
|
17761
|
+
return {
|
|
17762
|
+
ok: false,
|
|
17763
|
+
status: 413,
|
|
17764
|
+
error: `A message is limited to ${INPUT_MAX_BYTES / 1024} KiB.`
|
|
17765
|
+
};
|
|
16720
17766
|
}
|
|
16721
|
-
|
|
16722
|
-
|
|
16723
|
-
if (this.
|
|
16724
|
-
|
|
16725
|
-
|
|
16726
|
-
|
|
16727
|
-
|
|
16728
|
-
|
|
17767
|
+
const refused = await this.ours();
|
|
17768
|
+
if (refused) return refused;
|
|
17769
|
+
if ((this.activeHarness === "codex" || this.activeHarness === "pi") && !this.nativeRecorder)
|
|
17770
|
+
return {
|
|
17771
|
+
ok: false,
|
|
17772
|
+
status: 409,
|
|
17773
|
+
error: `Restart the ${this.activeHarness} session from Wheelhouse to enable its chat recorder.`
|
|
17774
|
+
};
|
|
17775
|
+
if (this.activeHarness === "opencode")
|
|
17776
|
+
return this.openCodeAction((connection) => sendOpenCode(connection, body));
|
|
17777
|
+
const shown = await this.onScreen();
|
|
17778
|
+
if (shown.picker || shown.menu)
|
|
17779
|
+
return {
|
|
17780
|
+
ok: false,
|
|
17781
|
+
status: 409,
|
|
17782
|
+
error: this.activeHarness !== "claude" ? `${this.activeHarness} is waiting for attention. Answer the choice or open its terminal before sending.` : MENU_OPEN
|
|
17783
|
+
};
|
|
17784
|
+
const paste = await this.backend.paste(body);
|
|
17785
|
+
if (!paste.ok) return { ok: false, status: 500, error: paste.error };
|
|
17786
|
+
await this.sleep(PASTE_SETTLE_MS);
|
|
17787
|
+
return this.keys(["Enter"]);
|
|
17788
|
+
});
|
|
17789
|
+
}
|
|
17790
|
+
/** Press Escape: Claude Code stops what it is doing. */
|
|
17791
|
+
interrupt() {
|
|
17792
|
+
return this.serial(async () => {
|
|
17793
|
+
const refused = await this.ours();
|
|
17794
|
+
if (refused) return refused;
|
|
17795
|
+
return this.activeHarness === "opencode" ? this.openCodeAction(interruptOpenCode) : this.keys(["Escape"]);
|
|
17796
|
+
});
|
|
17797
|
+
}
|
|
17798
|
+
async openCodeAction(action) {
|
|
17799
|
+
if (!this.openCode)
|
|
17800
|
+
return {
|
|
17801
|
+
ok: false,
|
|
17802
|
+
status: 409,
|
|
17803
|
+
error: "Restart the OpenCode primary from Wheelhouse to enable chat."
|
|
17804
|
+
};
|
|
17805
|
+
try {
|
|
17806
|
+
await action(this.openCode);
|
|
17807
|
+
return { ok: true };
|
|
17808
|
+
} catch (error) {
|
|
17809
|
+
return {
|
|
17810
|
+
ok: false,
|
|
17811
|
+
status: error instanceof OpenCodeError ? error.status : 503,
|
|
17812
|
+
error: error instanceof Error ? error.message : "OpenCode is unavailable."
|
|
17813
|
+
};
|
|
16729
17814
|
}
|
|
16730
17815
|
}
|
|
16731
|
-
/**
|
|
16732
|
-
|
|
16733
|
-
|
|
16734
|
-
|
|
16735
|
-
|
|
16736
|
-
|
|
16737
|
-
|
|
16738
|
-
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
this.
|
|
16742
|
-
|
|
16743
|
-
|
|
17816
|
+
/**
|
|
17817
|
+
* Choose in the menu Claude Code is waiting on. `signature` names the menu
|
|
17818
|
+
* the page showed; if the screen now shows another (or none), nothing is
|
|
17819
|
+
* pressed. The keys come from the menu on screen, never from the page.
|
|
17820
|
+
*/
|
|
17821
|
+
pick(signature, action) {
|
|
17822
|
+
return this.serial(async () => {
|
|
17823
|
+
const refused = await this.ours();
|
|
17824
|
+
if (refused) return refused;
|
|
17825
|
+
if (this.activeHarness === "opencode")
|
|
17826
|
+
return this.openCodeAction(
|
|
17827
|
+
(connection) => answerOpenCodePicker(connection, signature, action)
|
|
17828
|
+
);
|
|
17829
|
+
const now = await this.picker().catch(() => null);
|
|
17830
|
+
if (!now || now.signature !== signature) {
|
|
17831
|
+
return {
|
|
17832
|
+
ok: false,
|
|
17833
|
+
status: 409,
|
|
17834
|
+
error: "That choice is no longer on Firstmate’s screen."
|
|
17835
|
+
};
|
|
17836
|
+
}
|
|
17837
|
+
const keys = pickerKeys(now, action);
|
|
17838
|
+
if (!keys) return { ok: false, status: 400, error: "That is not one of the choices." };
|
|
17839
|
+
return this.keys(keys);
|
|
17840
|
+
});
|
|
17841
|
+
}
|
|
17842
|
+
/**
|
|
17843
|
+
* Close the menu one of Claude Code's commands opened (such as /mcp):
|
|
17844
|
+
* Escape, as often as it takes to back out of its nested screens. After each
|
|
17845
|
+
* press the screen is read until the menu has redrawn, and only another menu
|
|
17846
|
+
* gets another press, so Escape never reaches the prompt, where it would stop
|
|
17847
|
+
* Firstmate's work or (pressed twice) open the rewind menu.
|
|
17848
|
+
* Firstmate's own question or permission prompt, which has no heading of
|
|
17849
|
+
* Claude Code's, is the captain's to answer and is never closed.
|
|
17850
|
+
*/
|
|
17851
|
+
dismiss() {
|
|
17852
|
+
return this.serial(async () => {
|
|
17853
|
+
const refused = await this.ours();
|
|
17854
|
+
if (refused) return refused;
|
|
17855
|
+
if (this.activeHarness !== "claude")
|
|
17856
|
+
return {
|
|
17857
|
+
ok: false,
|
|
17858
|
+
status: 409,
|
|
17859
|
+
error: "Use the browser terminal to close this harness’s menus."
|
|
17860
|
+
};
|
|
17861
|
+
let text2 = await this.screen().catch(() => null);
|
|
17862
|
+
for (let i = 0; i < DISMISS_MAX; i++) {
|
|
17863
|
+
const menu = text2 === null ? null : parseMenu(text2);
|
|
17864
|
+
if (!menu) return { ok: true };
|
|
17865
|
+
if (!menu.title && parsePicker(text2)) {
|
|
17866
|
+
if (i > 0) return { ok: true };
|
|
17867
|
+
return {
|
|
17868
|
+
ok: false,
|
|
17869
|
+
status: 409,
|
|
17870
|
+
error: "Firstmate is asking you something now; answer it in the chat."
|
|
17871
|
+
};
|
|
16744
17872
|
}
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
17873
|
+
const r = await this.keys(["Escape"]);
|
|
17874
|
+
if (!r.ok) return r;
|
|
17875
|
+
const before = menuPart(text2);
|
|
17876
|
+
for (let w = 0; w < MENU_REDRAW_WAITS && menuPart(text2) === before; w++) {
|
|
17877
|
+
await this.sleep(MENU_SETTLE_MS);
|
|
17878
|
+
text2 = await this.screen().catch(() => null);
|
|
17879
|
+
}
|
|
17880
|
+
if (menuPart(text2) === before) break;
|
|
16750
17881
|
}
|
|
17882
|
+
return {
|
|
17883
|
+
ok: false,
|
|
17884
|
+
status: 409,
|
|
17885
|
+
error: "The menu is still open after pressing Escape; close it in Firstmate’s terminal."
|
|
17886
|
+
};
|
|
17887
|
+
});
|
|
17888
|
+
}
|
|
17889
|
+
/** What the terminal drawer may attach to: only Wheelhouse's own running session, through its backend. */
|
|
17890
|
+
terminal = async () => {
|
|
17891
|
+
const refused = await this.ours();
|
|
17892
|
+
if (refused && !refused.ok) {
|
|
17893
|
+
return { ok: false, status: refused.status === 409 ? 409 : 503, error: refused.error };
|
|
16751
17894
|
}
|
|
17895
|
+
return { ok: true, target: { ...this.backend.attach(), cwd: this.firstmateDir } };
|
|
17896
|
+
};
|
|
17897
|
+
}
|
|
17898
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17899
|
+
const RECEIPT_BYTES = 64 * 1024;
|
|
17900
|
+
const META_BYTES = 1024 * 1024;
|
|
17901
|
+
function object(value) {
|
|
17902
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
17903
|
+
}
|
|
17904
|
+
async function readJson(file, limit, firstLine2 = false) {
|
|
17905
|
+
const handle = await open(file, "r");
|
|
17906
|
+
try {
|
|
17907
|
+
const size = (await handle.stat()).size;
|
|
17908
|
+
if (!firstLine2 && size > limit) return null;
|
|
17909
|
+
const buffer = Buffer.alloc(Math.min(size, limit));
|
|
17910
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
|
|
17911
|
+
const text2 = buffer.subarray(0, bytesRead).toString("utf8");
|
|
17912
|
+
const newline = text2.indexOf("\n");
|
|
17913
|
+
if (firstLine2 && newline < 0) return null;
|
|
17914
|
+
return JSON.parse(firstLine2 ? text2.slice(0, newline) : text2);
|
|
17915
|
+
} finally {
|
|
17916
|
+
await handle.close();
|
|
16752
17917
|
}
|
|
16753
|
-
|
|
16754
|
-
|
|
16755
|
-
|
|
17918
|
+
}
|
|
17919
|
+
async function locateCodexTranscript(opts, state) {
|
|
17920
|
+
if (state !== "ours" || !opts.sessionNonce?.trim()) return null;
|
|
17921
|
+
try {
|
|
17922
|
+
const receipt = object(await readJson(opts.hookFile, RECEIPT_BYTES));
|
|
17923
|
+
if (!receipt || receipt.wheelhouse_nonce !== opts.sessionNonce || typeof receipt.session_id !== "string" || !UUID.test(receipt.session_id) || typeof receipt.transcript_path !== "string" || !path.isAbsolute(receipt.transcript_path) || typeof receipt.cwd !== "string" || !path.isAbsolute(receipt.cwd))
|
|
17924
|
+
return null;
|
|
17925
|
+
const [cwd, receiptCwd, root, file] = await Promise.all([
|
|
17926
|
+
realpath(opts.firstmateDir),
|
|
17927
|
+
realpath(receipt.cwd),
|
|
17928
|
+
realpath(path.join(opts.codexHome, "sessions")),
|
|
17929
|
+
realpath(receipt.transcript_path)
|
|
17930
|
+
]);
|
|
17931
|
+
const relative = path.relative(root, file);
|
|
17932
|
+
if (cwd !== receiptCwd || !relative || relative.startsWith("..") || path.isAbsolute(relative))
|
|
17933
|
+
return null;
|
|
17934
|
+
const record = object(await readJson(file, META_BYTES, true));
|
|
17935
|
+
const meta = object(record?.payload);
|
|
17936
|
+
if (record?.type !== "session_meta" || !meta || meta.id !== receipt.session_id || meta.originator !== "codex-tui" || meta.source !== "cli" && meta.source !== "vscode" || typeof meta.cwd !== "string" || !path.isAbsolute(meta.cwd) || await realpath(meta.cwd) !== cwd)
|
|
17937
|
+
return null;
|
|
17938
|
+
return { how: "hook", file };
|
|
17939
|
+
} catch {
|
|
17940
|
+
return null;
|
|
16756
17941
|
}
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
|
|
17942
|
+
}
|
|
17943
|
+
function textContent(value) {
|
|
17944
|
+
if (!Array.isArray(value)) return "";
|
|
17945
|
+
return value.flatMap((part) => {
|
|
17946
|
+
const block = object(part);
|
|
17947
|
+
if (!block) return [];
|
|
17948
|
+
if ((block.type === "text" || block.type === "Text") && typeof block.text === "string")
|
|
17949
|
+
return [block.text];
|
|
17950
|
+
if (block.type === "image" || block.type === "localImage") return ["[image]"];
|
|
17951
|
+
return [];
|
|
17952
|
+
}).join("\n");
|
|
17953
|
+
}
|
|
17954
|
+
function mcpResult(value) {
|
|
17955
|
+
if (typeof value === "string") return value;
|
|
17956
|
+
const result2 = object(value);
|
|
17957
|
+
if (!result2) return "";
|
|
17958
|
+
if (Array.isArray(result2.content)) {
|
|
17959
|
+
return result2.content.flatMap((part) => {
|
|
17960
|
+
const block = object(part);
|
|
17961
|
+
return block?.type === "text" && typeof block.text === "string" ? [{ type: "text", text: block.text }] : [];
|
|
17962
|
+
});
|
|
16760
17963
|
}
|
|
16761
|
-
|
|
16762
|
-
|
|
16763
|
-
|
|
16764
|
-
|
|
16765
|
-
|
|
17964
|
+
return typeof result2.message === "string" ? result2.message : "";
|
|
17965
|
+
}
|
|
17966
|
+
function codexRecords(raw) {
|
|
17967
|
+
const record = object(raw);
|
|
17968
|
+
const payload = object(record?.payload);
|
|
17969
|
+
if (record?.type !== "event_msg" || !payload || typeof record.timestamp !== "string" || !Number.isFinite(Date.parse(record.timestamp)))
|
|
17970
|
+
return [];
|
|
17971
|
+
const timestamp2 = record.timestamp;
|
|
17972
|
+
const turnId = typeof payload.turn_id === "string" ? payload.turn_id : null;
|
|
17973
|
+
if (payload.type === "task_complete" && turnId) {
|
|
17974
|
+
return [
|
|
17975
|
+
{
|
|
17976
|
+
type: "system",
|
|
17977
|
+
uuid: `codex:${turnId}:completed`,
|
|
17978
|
+
timestamp: timestamp2,
|
|
17979
|
+
subtype: "turn_duration",
|
|
17980
|
+
durationMs: typeof payload.duration_ms === "number" && Number.isFinite(payload.duration_ms) ? Math.max(0, payload.duration_ms) : null
|
|
17981
|
+
}
|
|
17982
|
+
];
|
|
17983
|
+
}
|
|
17984
|
+
if (payload.type === "turn_aborted" && turnId) {
|
|
17985
|
+
return [
|
|
17986
|
+
{
|
|
17987
|
+
type: "user",
|
|
17988
|
+
uuid: `codex:${turnId}:interrupted`,
|
|
17989
|
+
timestamp: timestamp2,
|
|
17990
|
+
message: { role: "user", content: "[Request interrupted by user]" }
|
|
17991
|
+
}
|
|
17992
|
+
];
|
|
17993
|
+
}
|
|
17994
|
+
if (payload.type !== "item_started" && payload.type !== "item_completed") return [];
|
|
17995
|
+
const completed = payload.type === "item_completed";
|
|
17996
|
+
const item = object(payload.item);
|
|
17997
|
+
if (!item || typeof item.id !== "string" || !item.id || typeof item.type !== "string") return [];
|
|
17998
|
+
const id = `codex:${item.id}`;
|
|
17999
|
+
const assistant = (suffix, content) => ({
|
|
18000
|
+
type: "assistant",
|
|
18001
|
+
uuid: `${id}:${suffix}`,
|
|
18002
|
+
timestamp: timestamp2,
|
|
18003
|
+
message: { id, role: "assistant", content }
|
|
18004
|
+
});
|
|
18005
|
+
if (item.type === "UserMessage" || item.type === "AgentMessage") {
|
|
18006
|
+
if (!completed) return [];
|
|
18007
|
+
const text2 = textContent(item.content);
|
|
18008
|
+
if (!text2.trim()) return [];
|
|
18009
|
+
return item.type === "UserMessage" ? [{ type: "user", uuid: `${id}:user`, timestamp: timestamp2, message: { role: "user", content: text2 } }] : [assistant("text", [{ type: "text", text: text2 }])];
|
|
18010
|
+
}
|
|
18011
|
+
if (item.type === "Reasoning") {
|
|
18012
|
+
return completed ? [assistant("thinking", [{ type: "thinking", thinking: "", signature: "" }])] : [];
|
|
18013
|
+
}
|
|
18014
|
+
let name2;
|
|
18015
|
+
let input;
|
|
18016
|
+
let result2 = "";
|
|
18017
|
+
let isError = item.status === "failed" || item.status === "declined";
|
|
18018
|
+
switch (item.type) {
|
|
18019
|
+
case "CommandExecution":
|
|
18020
|
+
if (typeof item.command !== "string" && !(Array.isArray(item.command) && item.command.every((part) => typeof part === "string")))
|
|
18021
|
+
return [];
|
|
18022
|
+
name2 = "Bash";
|
|
18023
|
+
input = {
|
|
18024
|
+
command: typeof item.command === "string" ? item.command : shellLine(item.command)
|
|
18025
|
+
};
|
|
18026
|
+
result2 = typeof item.aggregated_output === "string" ? item.aggregated_output : "";
|
|
18027
|
+
isError ||= typeof item.exit_code === "number" && item.exit_code !== 0;
|
|
18028
|
+
break;
|
|
18029
|
+
case "McpToolCall": {
|
|
18030
|
+
if (typeof item.server !== "string" || typeof item.tool !== "string") return [];
|
|
18031
|
+
name2 = `mcp__${item.server}__${item.tool}`;
|
|
18032
|
+
input = object(item.arguments) ?? {};
|
|
18033
|
+
result2 = mcpResult(item.result ?? item.error);
|
|
18034
|
+
isError ||= object(item.result)?.isError === true || item.error != null;
|
|
18035
|
+
break;
|
|
18036
|
+
}
|
|
18037
|
+
case "FileChange": {
|
|
18038
|
+
const changes = object(item.changes);
|
|
18039
|
+
if (!changes || !Object.keys(changes).length) return [];
|
|
18040
|
+
name2 = "Edit";
|
|
18041
|
+
input = { file_path: Object.keys(changes).join(", ") };
|
|
18042
|
+
result2 = [item.stdout, item.stderr].filter((value) => typeof value === "string").join("\n");
|
|
18043
|
+
break;
|
|
18044
|
+
}
|
|
18045
|
+
default:
|
|
18046
|
+
return [];
|
|
16766
18047
|
}
|
|
18048
|
+
const start = assistant("call", [{ type: "tool_use", id, name: name2, input }]);
|
|
18049
|
+
return completed ? [
|
|
18050
|
+
start,
|
|
18051
|
+
{
|
|
18052
|
+
type: "user",
|
|
18053
|
+
uuid: `${id}:result`,
|
|
18054
|
+
timestamp: timestamp2,
|
|
18055
|
+
message: {
|
|
18056
|
+
role: "user",
|
|
18057
|
+
content: [{ type: "tool_result", tool_use_id: id, content: result2, is_error: isError }]
|
|
18058
|
+
}
|
|
18059
|
+
}
|
|
18060
|
+
] : [start];
|
|
16767
18061
|
}
|
|
16768
18062
|
const SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
16769
18063
|
const MISDIRECTED = "Misdirected request";
|
|
@@ -16878,8 +18172,8 @@ class SeenAddresses {
|
|
|
16878
18172
|
try {
|
|
16879
18173
|
const texts = [];
|
|
16880
18174
|
for (const source of await this.opts.sources()) collect(source, texts, 0);
|
|
16881
|
-
for (const
|
|
16882
|
-
for (const address of loopbackAddresses(
|
|
18175
|
+
for (const text2 of texts) {
|
|
18176
|
+
for (const address of loopbackAddresses(text2)) {
|
|
16883
18177
|
this.seen.delete(address);
|
|
16884
18178
|
this.seen.add(address);
|
|
16885
18179
|
}
|
|
@@ -17296,7 +18590,15 @@ async function create(env, opts = {}) {
|
|
|
17296
18590
|
});
|
|
17297
18591
|
const chat = new ChatFeed({
|
|
17298
18592
|
status: () => firstmate.status(),
|
|
17299
|
-
locate: (state) =>
|
|
18593
|
+
locate: (state, harness) => harness === "codex" ? locateCodexTranscript(
|
|
18594
|
+
{
|
|
18595
|
+
firstmateDir: install.firstmateDir,
|
|
18596
|
+
hookFile: firstmate.hookFile,
|
|
18597
|
+
sessionNonce: firstmate.sessionNonce,
|
|
18598
|
+
codexHome: env.CODEX_HOME || path.join(env.HOME || homedir(), ".codex")
|
|
18599
|
+
},
|
|
18600
|
+
state
|
|
18601
|
+
) : harness === "claude" ? locateTranscript(
|
|
17300
18602
|
{
|
|
17301
18603
|
firstmateDir: install.firstmateDir,
|
|
17302
18604
|
homeDir: install.homeDir,
|
|
@@ -17304,7 +18606,24 @@ async function create(env, opts = {}) {
|
|
|
17304
18606
|
projectsDir: projectsDir(env)
|
|
17305
18607
|
},
|
|
17306
18608
|
state
|
|
17307
|
-
)
|
|
18609
|
+
) : Promise.resolve(null),
|
|
18610
|
+
decode: (raw, harness) => harness === "codex" ? codexRecords(raw) : harness === "claude" && raw !== null && typeof raw === "object" && !Array.isArray(raw) ? [raw] : [],
|
|
18611
|
+
snapshot: async (session) => {
|
|
18612
|
+
if (session.state !== "ours") return null;
|
|
18613
|
+
if (session.harness === "pi")
|
|
18614
|
+
return piSnapshot({
|
|
18615
|
+
firstmateDir: install.firstmateDir,
|
|
18616
|
+
hookFile: firstmate.hookFile,
|
|
18617
|
+
sessionNonce: firstmate.sessionNonce,
|
|
18618
|
+
agentDir: env.PI_CODING_AGENT_DIR || path.join(env.HOME || homedir(), ".pi", "agent")
|
|
18619
|
+
});
|
|
18620
|
+
if (session.harness === "opencode") {
|
|
18621
|
+
if (!firstmate.openCodeConnection)
|
|
18622
|
+
throw new OpenCodeError("Restart the OpenCode primary from Wheelhouse to enable chat.");
|
|
18623
|
+
return openCodeSnapshot(firstmate.openCodeConnection);
|
|
18624
|
+
}
|
|
18625
|
+
return null;
|
|
18626
|
+
}
|
|
17308
18627
|
});
|
|
17309
18628
|
const ownPort = Number(URL.parse(env.WHEELHOUSE_URL ?? "")?.port) || null;
|
|
17310
18629
|
const sandbox = new Sandboxes({
|
|
@@ -17335,7 +18654,11 @@ async function create(env, opts = {}) {
|
|
|
17335
18654
|
const seen = new SeenAddresses({
|
|
17336
18655
|
sources: async () => [collector.getFleet(), await inbox.view(), chat.snapshot()]
|
|
17337
18656
|
});
|
|
17338
|
-
const reservedPorts = () => [
|
|
18657
|
+
const reservedPorts = () => [
|
|
18658
|
+
...ownPort ? [ownPort] : [],
|
|
18659
|
+
...sandbox.ports(),
|
|
18660
|
+
...firstmate.openCodeConnection ? [Number(new URL(firstmate.openCodeConnection.url).port)] : []
|
|
18661
|
+
];
|
|
17339
18662
|
const forwards = new PreviewForwards({ env });
|
|
17340
18663
|
const mateTasks = new MateTasks({
|
|
17341
18664
|
adapter,
|
|
@@ -17781,7 +19104,7 @@ async function startFirstmate(session) {
|
|
|
17781
19104
|
const v = await session.ensure();
|
|
17782
19105
|
if (v.state === "ours") {
|
|
17783
19106
|
console.log(
|
|
17784
|
-
`Firstmate: running in
|
|
19107
|
+
`Firstmate: running in ${session.backend.label} (${v.attach}); talk to it on the home page.${v.harness !== "claude" ? ` Using ${v.harness} in chat.` : v.skipPermissions ? "" : " Started without --dangerously-skip-permissions."}`
|
|
17785
19108
|
);
|
|
17786
19109
|
} else {
|
|
17787
19110
|
console.log(`Firstmate: ${v.reason ?? v.state}`);
|
|
@@ -17970,5 +19293,5 @@ const runtime = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
17970
19293
|
upgradeRuntime
|
|
17971
19294
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
17972
19295
|
|
|
17973
|
-
export { checkCompatibility as $, currentPlugins as A, currentPluginPage as B, watchSettingsError as C, changePluginConfig as D, runBounded as E, which as F, GATEWAY_CHANNELS as G, pluginIconFile as H, INPUT_MAX_BYTES as I, pluginUiFile as J, previewProber as K, LOOPBACK_HOST as L, MAX_CHAT_CALLS as M, MAX_FILE_BYTES$1 as N, PEEK_DEFAULT_LINES as O, PROJECT_ID as P, pluginService as Q, REQUEST_ID as R, refusesSetup as S, findFirstmateDir as T, looksLikeFirstmate as U, SETUP_SUGGESTIONS as V, WATCH_PLUGIN as W, writeRemembered as X, reconnectRuntime as Y, setupWorkDir as Z, setupTerminals as _, sessionToken as a, bundledPluginsDir as a0, currentSlots as a1, GAPS as a2, WORKTREE_GONE as a3, PEEK_MAX_LINES as a4, parseChange as a5, MAX_VALUE_BYTES as a6, currentDecisions as a7, readDoc as a8, currentTime as a9, runtime as aa, currentHostedPreviews as b, currentPullRequestTabs as c, currentAddressRewrites as d, currentInbox as e, currentHeadroom as f, getRuntime as g, currentHealth as h, isMutating as i, currentFleet as j, currentRailInsights as k, loadSlots as l, currentPreviewPorts as m, currentMessages as n, serverInstance as o, unconfiguredHealth as p, currentFileRoots as q, refuseMutation as r, servedOrigin as s, readAsset as t, unconfiguredFleet as u, unavailableFirstmate as v, parseMateTaskId as w, validateSend as x, isReactionId as y, currentGateway as z };
|
|
17974
|
-
//# sourceMappingURL=runtime.js-
|
|
19296
|
+
export { checkCompatibility as $, currentPlugins as A, currentPluginPage as B, watchSettingsError as C, changePluginConfig as D, runBounded as E, which as F, GATEWAY_CHANNELS as G, pluginIconFile as H, INPUT_MAX_BYTES as I, pluginUiFile as J, previewProber as K, LOOPBACK_HOST as L, MAX_CHAT_CALLS as M, MAX_FILE_BYTES$1 as N, PEEK_DEFAULT_LINES as O, PROJECT_ID as P, pluginService as Q, REQUEST_ID$1 as R, refusesSetup as S, findFirstmateDir as T, looksLikeFirstmate as U, SETUP_SUGGESTIONS as V, WATCH_PLUGIN as W, writeRemembered as X, reconnectRuntime as Y, setupWorkDir as Z, setupTerminals as _, sessionToken as a, bundledPluginsDir as a0, currentSlots as a1, GAPS as a2, WORKTREE_GONE as a3, PEEK_MAX_LINES as a4, parseChange as a5, MAX_VALUE_BYTES as a6, currentDecisions as a7, readDoc as a8, currentTime as a9, runtime as aa, currentHostedPreviews as b, currentPullRequestTabs as c, currentAddressRewrites as d, currentInbox as e, currentHeadroom as f, getRuntime as g, currentHealth as h, isMutating as i, currentFleet as j, currentRailInsights as k, loadSlots as l, currentPreviewPorts as m, currentMessages as n, serverInstance as o, unconfiguredHealth as p, currentFileRoots as q, refuseMutation as r, servedOrigin as s, readAsset as t, unconfiguredFleet as u, unavailableFirstmate as v, parseMateTaskId as w, validateSend as x, isReactionId as y, currentGateway as z };
|
|
19297
|
+
//# sourceMappingURL=runtime.js-ja9fpm3a.js.map
|