nolo-cli 0.264.0-alpha.2 → 0.266.0-alpha.1
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/{chunk-LXP53WGF.js → chunk-05wkntba.js} +44 -40
- package/{chunk-XFYFMTOM.js → chunk-08ts2q1n.js} +9 -11
- package/{chromeCommands-MVEEIY4R.js → chunk-0a3m1n6h.js} +182 -238
- package/chunk-0gfvc7g8.js +13 -0
- package/{chunk-CF7PE763.js → chunk-0h0sncy4.js} +3 -4
- package/{chunk-3UH7SS4W.js → chunk-0nsxwrge.js} +232 -241
- package/chunk-0ra8cne4.js +11 -0
- package/{chunk-MRACVEPZ.js → chunk-0sgwk7am.js} +1 -3
- package/{chunk-PEXGRTTQ.js → chunk-0tsfn0dk.js} +44 -45
- package/{chunk-WOAZVUSN.js → chunk-0y8cbwzy.js} +26 -30
- package/chunk-12gz55kk.js +6 -0
- package/{chunk-GLKOYSRU.js → chunk-186gshgw.js} +3 -6
- package/chunk-19w4ss38.js +44 -0
- package/{chunk-RF576RYE.js → chunk-1cakzp6r.js} +23 -23
- package/chunk-1fbfwbzp.js +27 -0
- package/{chunk-4IVMDQBA.js → chunk-1fv9k8zt.js} +103 -68
- package/{chunk-Q5FJJ6XI.js → chunk-1js4cdzp.js} +11 -19
- package/{chunk-YECCIUYU.js → chunk-1nhx0er5.js} +63 -63
- package/chunk-1p152b7g.js +12 -0
- package/{chunk-HXEO5DNV.js → chunk-1ynbq3yr.js} +322 -353
- package/{chunk-6UBGXX2W.js → chunk-1zrg4h5n.js} +3 -4
- package/{chunk-Y5GCAMGP.js → chunk-2g6zsfq8.js} +1 -3
- package/chunk-2hekb0eh.js +17 -0
- package/chunk-2pj6qzq5.js +12 -0
- package/chunk-2tvd4jyp.js +226 -0
- package/chunk-2ygg7azv.js +846 -0
- package/chunk-33405wtv.js +50 -0
- package/chunk-34axejtd.js +30 -0
- package/{tableCommands-FCPDULSU.js → chunk-3700dvt3.js} +224 -276
- package/{pdf-KE3QI2V7.js → chunk-3j08t1nm.js} +12505 -10133
- package/chunk-3j9gq18v.js +111 -0
- package/{chunk-LYPJYBE5.js → chunk-3qfpcdkm.js} +486 -505
- package/{settingThunks-PNC7ZISV.js → chunk-3r2x7h64.js} +189 -272
- package/{agentGrantCommands-2VLLXGIU.js → chunk-3tbj5fxt.js} +61 -56
- package/chunk-40whhjj5.js +168 -0
- package/chunk-4301919y.js +7 -0
- package/chunk-43adz39e.js +77 -0
- package/{chunk-5ZUL4CUO.js → chunk-49v3zc4g.js} +1 -3
- package/chunk-4dd7mxkb.js +72 -0
- package/{chunk-BKP325XS.js → chunk-4hapfzpq.js} +66 -62
- package/chunk-4mm7dz0m.js +95 -0
- package/chunk-4pqxempz.js +440 -0
- package/chunk-4x9zf5pv.js +10 -0
- package/{chunk-CA7LGAHV.js → chunk-511q8qzv.js} +66 -57
- package/{chunk-U7OULUMF.js → chunk-53v9g0np.js} +49 -64
- package/chunk-572mg6q5.js +19 -0
- package/{chunk-QAW6BEWQ.js → chunk-57eyhmwr.js} +17173 -16165
- package/chunk-5hsr0zjm.js +156 -0
- package/chunk-5k883yyd.js +20 -0
- package/chunk-5m0wsee4.js +639 -0
- package/{memberThunks-NEZRAW5K.js → chunk-5r1sq2gt.js} +299 -373
- package/chunk-648rq4np.js +255 -0
- package/{chunk-IYRZKHA6.js → chunk-666yjw5c.js} +63 -86
- package/{chunk-4O22PGNQ.js → chunk-6cdcbmtp.js} +19 -19
- package/chunk-6dbyqcf7.js +59 -0
- package/{agentProviderCommands-2W3VXDLV.js → chunk-6e8mgp1x.js} +82 -105
- package/chunk-6n0pw7sx.js +44 -0
- package/chunk-6q1b7381.js +361 -0
- package/chunk-6sj756ry.js +23 -0
- package/{chunk-4UNN45DS.js → chunk-6t7a7zck.js} +14785 -14454
- package/chunk-6yarwtxh.js +776 -0
- package/chunk-708h542p.js +18 -0
- package/chunk-76f076t8.js +266 -0
- package/chunk-782rrrwv.js +523 -0
- package/{workloadLifecycle-P2SJVV3S.js → chunk-7gk330wp.js} +77 -84
- package/{chunk-EZKIRVLJ.js → chunk-7ks60vxy.js} +146 -128
- package/{chunk-FI4DPLR7.js → chunk-7mrqbxe8.js} +342 -228
- package/chunk-7sztayrd.js +169 -0
- package/chunk-7vgt2mxz.js +15 -0
- package/{localFirstLog-OIETGK66.js → chunk-7z8y4k6y.js} +0 -2
- package/{chunk-KDDXC2IH.js → chunk-82htft2m.js} +49 -11
- package/{updateDialogTitleAction-XOSLNRT3.js → chunk-88vrtxxg.js} +65 -137
- package/{chunk-LS5KAVFQ.js → chunk-8dtjbp79.js} +293 -229
- package/chunk-8fajbkaz.js +50 -0
- package/chunk-8m1ebxpw.js +65 -0
- package/{accountResolver-JYG5L7YP.js → chunk-8mgfeg0w.js} +37 -30
- package/{chunk-LPXBBC32.js → chunk-8myksy35.js} +156 -160
- package/{chunk-BMQ2MJUK.js → chunk-8nrj7dc7.js} +75 -66
- package/{commandRegistry-ENNFT77C.js → chunk-8t8x64ec.js} +228 -286
- package/chunk-8yj4pq79.js +458 -0
- package/{chunk-5MKPNTJP.js → chunk-8z6pepcx.js} +43 -48
- package/{chunk-UYQILGDR.js → chunk-90egc9vb.js} +122 -102
- package/{chunk-EODBQPRM.js → chunk-91q5dc5r.js} +10 -14
- package/{chunk-U6VC4MU4.js → chunk-96jtrqk1.js} +2 -4
- package/{chunk-H57T64RA.js → chunk-996j61av.js} +28 -31
- package/{chunk-Q6FKWH66.js → chunk-9cxgb9jy.js} +137 -243
- package/{chunk-2ZBPWX7N.js → chunk-9q1gbmet.js} +62 -104
- package/chunk-9qtjh73q.js +344 -0
- package/{chunk-SR57FDTX.js → chunk-9raka469.js} +72 -155
- package/{chunk-V6K5U4YE.js → chunk-9vh4v046.js} +32 -41
- package/{chunk-AGIM7IMJ.js → chunk-9yr1fy7j.js} +14 -49
- package/{chunk-FGFJUFPS.js → chunk-a16x0wt6.js} +11 -18
- package/chunk-a5b2rvzs.js +131 -0
- package/{chunk-7DPNBQSV.js → chunk-a7bz6nc3.js} +3 -4
- package/chunk-ac85azv9.js +29 -0
- package/{chunk-VXL2FZTP.js → chunk-ahhbkad4.js} +16 -20
- package/{chunk-37DGW762.js → chunk-anhksj2j.js} +16 -29
- package/{cliAuthorityBrokerServer-27C5YBYP.js → chunk-atvmx76t.js} +180 -186
- package/{chunk-E6A5NHDH.js → chunk-av2mzeqz.js} +16 -17
- package/chunk-avbwrb0z.js +614 -0
- package/chunk-avr6rqe5.js +544 -0
- package/{workContextQueryProjection-CACY5VFE.js → chunk-axx60d5a.js} +7 -7
- package/{chunk-EWQ3HGNZ.js → chunk-b00vzjkb.js} +30 -23
- package/chunk-b0m6ezxr.js +132 -0
- package/chunk-bbd5mgdt.js +47 -0
- package/chunk-bcecft0r.js +28 -0
- package/chunk-beyr4pyp.js +33 -0
- package/{chunk-BR3GT6MR.js → chunk-bge0cagn.js} +7 -18
- package/{offlineMarxistsAgentCommand-MFURGWHL.js → chunk-bh53zg3t.js} +33 -43
- package/chunk-bmx1cw89.js +37 -0
- package/chunk-br2195h4.js +22 -0
- package/chunk-bsqkwveq.js +56 -0
- package/{chunk-QAU6KM2U.js → chunk-c09s2z1m.js} +139 -98
- package/chunk-c235kypv.js +24636 -0
- package/{chunk-2JMYAH5O.js → chunk-c30j6pyh.js} +213 -256
- package/chunk-c3v6r6sq.js +29 -0
- package/{chunk-PDSXYHNI.js → chunk-c5z7qspt.js} +1177 -1196
- package/{chunk-GWB6AGME.js → chunk-c6jvz0mp.js} +34 -50
- package/{chunk-PRJ473FK.js → chunk-cd6h9qqs.js} +14 -12
- package/chunk-cdt0amyy.js +37 -0
- package/{chunk-2AJLG6PY.js → chunk-cfh6tfc3.js} +73 -86
- package/{chunk-WIVVNJUS.js → chunk-ch4ck1yz.js} +38 -68
- package/chunk-chtvrtp5.js +55 -0
- package/{chunk-EYLGAEB4.js → chunk-ckvz7abv.js} +170 -165
- package/{chunk-YZMNK53S.js → chunk-csf18m5w.js} +32 -25
- package/{chunk-C36L6ZID.js → chunk-cwnvf8dt.js} +2 -10
- package/chunk-cy7thb6n.js +19877 -0
- package/{dialogPortabilityCommands-YQJNB2KL.js → chunk-d61q9nah.js} +439 -487
- package/chunk-d6xdy0gp.js +142 -0
- package/{chunk-EBH4RFJ6.js → chunk-dh69vqbd.js} +6390 -6496
- package/{chunk-KJ4J2XQB.js → chunk-dj4ggbc6.js} +17 -19
- package/{chunk-LISC7BD4.js → chunk-djrrhbk3.js} +29 -37
- package/chunk-drqzzzvr.js +822 -0
- package/chunk-e1n7edjk.js +33 -0
- package/chunk-e3atr4hk.js +59 -0
- package/chunk-e9bn2aav.js +13 -0
- package/chunk-ed396rfq.js +87 -0
- package/chunk-eha8ggh6.js +10 -0
- package/{chunk-MALPQFGT.js → chunk-ek122zzt.js} +893 -948
- package/chunk-epnmvek4.js +22 -0
- package/{chunk-S25VJYXV.js → chunk-eqzvk3xm.js} +69 -80
- package/chunk-ex34n71b.js +2874 -0
- package/{chunk-56OAS5RZ.js → chunk-f3ad6q4h.js} +7 -11
- package/{chunk-3PVYUPXK.js → chunk-f8jepva1.js} +6 -7
- package/{chunk-GH34JXNV.js → chunk-f9yvy9t9.js} +114 -92
- package/chunk-fbdz4f0j.js +90 -0
- package/{chunk-J44TXB4J.js → chunk-fcsc2day.js} +216 -164
- package/chunk-fevdhnbh.js +19 -0
- package/chunk-fkrgqq8w.js +3300 -0
- package/{chunk-TSBJVMNW.js → chunk-fs3bvh2p.js} +42 -57
- package/chunk-fvwzyhah.js +134 -0
- package/chunk-g0mpxdp9.js +101 -0
- package/{chunk-LTQ6ECCF.js → chunk-g35f20d1.js} +450 -414
- package/{chunk-3L2WKC3W.js → chunk-g5fhtjqg.js} +13 -16
- package/{chunk-DBEOW57U.js → chunk-gcq01td7.js} +270 -227
- package/{chunk-ADMRXWXJ.js → chunk-ge97b11r.js} +121 -42
- package/chunk-ghjtgbkw.js +180 -0
- package/chunk-gkra36c1.js +16 -0
- package/chunk-gmz86t60.js +1000 -0
- package/{localDialogRead-GWGWSL5K.js → chunk-gszpesze.js} +5 -12
- package/chunk-gvsfec9m.js +16536 -0
- package/{chunk-QSJ3HFEF.js → chunk-h1hzmqph.js} +1 -3
- package/chunk-h30dg154.js +17 -0
- package/chunk-h3hkb7cw.js +241 -0
- package/chunk-h40py996.js +28 -0
- package/{chunk-47T3QP4V.js → chunk-h60gnewh.js} +112 -116
- package/{agentPullCommand-XEGOUYQT.js → chunk-hkwsv9xf.js} +33 -45
- package/chunk-hnyg0gwj.js +28 -0
- package/{chunk-KSV6T4AH.js → chunk-hqqqph5w.js} +12 -4
- package/{chunk-YQJEXXDK.js → chunk-hrngs1wy.js} +157 -246
- package/{chunk-LRLLWD4P.js → chunk-htf69s94.js} +14 -12
- package/chunk-j0yxesh3.js +83 -0
- package/{chunk-VF4K2QE6.js → chunk-j22t9g05.js} +3 -6
- package/{chunk-3R4AYHJR.js → chunk-j4a8m2zn.js} +5 -34
- package/chunk-j9p4jnwg.js +27 -0
- package/{chunk-R72QWIFO.js → chunk-jdycmfsm.js} +9 -9
- package/chunk-jdyvrne0.js +52 -0
- package/{spacePruneCommand-YKIEUIDQ.js → chunk-je0b66qf.js} +44 -62
- package/{chunk-HNMXYYJR.js → chunk-jec44fkj.js} +3 -4
- package/{chunk-526GLZJE.js → chunk-jf1ex00r.js} +107 -73
- package/chunk-jgqdec9b.js +31 -0
- package/{chunk-56GBUMO5.js → chunk-jkw9n4h5.js} +16 -25
- package/{chunk-7422ZLGL.js → chunk-jmnzdwjt.js} +867 -965
- package/chunk-jqq57s0a.js +58 -0
- package/{chunk-OKUSDVRS.js → chunk-jtkn5aj6.js} +27 -38
- package/chunk-jwvzn9r0.js +316 -0
- package/chunk-k1re0fc7.js +107 -0
- package/chunk-k2ep3rb2.js +103 -0
- package/{chunk-JEXVIMYZ.js → chunk-k6ycb24w.js} +5 -8
- package/{chunk-RI7SXDJW.js → chunk-kawvydbk.js} +383 -195
- package/chunk-kf2ghpzh.js +10 -0
- package/{chunk-S6FAHQDH.js → chunk-kgah9e46.js} +28 -59
- package/{chunk-T3MWVUBE.js → chunk-kjjepkvc.js} +71 -82
- package/chunk-kn4dgg4j.js +4113 -0
- package/{chunk-2LFYMWM3.js → chunk-kn5p91n8.js} +43 -53
- package/{chunk-MVOZ22RZ.js → chunk-kntqrbwc.js} +8 -12
- package/{chunk-I6YIA2TY.js → chunk-kq3vr7mx.js} +25 -20
- package/chunk-kz1x1d8n.js +15 -0
- package/{mcpLocalAuthorizeCommand-IKOFKY5U.js → chunk-m22e7tt2.js} +53 -71
- package/{chunk-ZNFJWEN4.js → chunk-m32rwr4d.js} +11 -8
- package/chunk-m39e9m18.js +93 -0
- package/{chunk-4D4QD7FT.js → chunk-m5518371.js} +64 -56
- package/{chunk-LHTXSC2E.js → chunk-mb5hnfyp.js} +9 -11
- package/chunk-mexet11v.js +11 -0
- package/chunk-mg2hgfgh.js +185 -0
- package/chunk-mmdhm4kx.js +10317 -0
- package/chunk-mz002yz8.js +2821 -0
- package/chunk-mzadqnyq.js +56 -0
- package/{chunk-VIDPVFP3.js → chunk-n3r1ebdm.js} +5 -6
- package/chunk-n438qea7.js +33 -0
- package/chunk-n5ffnhnb.js +93 -0
- package/chunk-nbvd87fy.js +9 -0
- package/{chunk-E36V7MPY.js → chunk-ndej7jc9.js} +53 -43
- package/{chunk-B767MA64.js → chunk-nen6rwe4.js} +62 -22
- package/chunk-nf06tr3v.js +16 -0
- package/chunk-ng8z355q.js +16 -0
- package/{chunk-4MEKE5D3.js → chunk-nhtxfv8k.js} +78 -63
- package/{runAgentClientLoop-2SFASHDS.js → chunk-nj62jscj.js} +132 -214
- package/{chunk-GBWGPTA7.js → chunk-nkryrkyp.js} +16 -19
- package/chunk-nmesxem8.js +197 -0
- package/{chunk-YR4J7RFS.js → chunk-nmq0qwbn.js} +117 -164
- package/chunk-nph8brvw.js +7 -0
- package/chunk-nr8fees9.js +10 -0
- package/{chunk-DFI7MVCQ.js → chunk-nvewvf7h.js} +1441 -1427
- package/{chunk-G7Y4GXTY.js → chunk-nyamhphs.js} +70 -79
- package/chunk-nz1c8tcg.js +111 -0
- package/{chunk-GPLUFN2E.js → chunk-nzc5yffh.js} +176 -217
- package/{chunk-G3SUCT4W.js → chunk-p1vg4bx8.js} +2 -4
- package/chunk-p3k3abe8.js +202 -0
- package/chunk-p4zy30q5.js +8 -0
- package/{chunk-ZJACPM5O.js → chunk-p6se1rx0.js} +102 -102
- package/chunk-p9dpshev.js +6968 -0
- package/chunk-pa42wxr0.js +116 -0
- package/{chunk-TA5QI4MM.js → chunk-paxthgqp.js} +56 -107
- package/{readlineWorkspace-ZH5FGDMI.js → chunk-pb35s8d9.js} +5395 -5786
- package/{chunk-XT6C2QZW.js → chunk-pbebzbcq.js} +8 -8
- package/chunk-pbx7e1mb.js +11 -0
- package/chunk-pe5czfn9.js +8 -0
- package/chunk-pextk1j4.js +62 -0
- package/chunk-pf5rywc6.js +575 -0
- package/chunk-pjfhd3fz.js +136 -0
- package/{chunk-ZCMAKAZM.js → chunk-pkhqb0fs.js} +118 -59
- package/chunk-pm5xb9jh.js +26 -0
- package/{chunk-Y3KGWZKF.js → chunk-ppdmmdkx.js} +110 -97
- package/chunk-pqp6y2hs.js +9 -0
- package/{chunk-QHEN7NZ7.js → chunk-ptz8fm2n.js} +12 -17
- package/{chunk-EUHMI5KG.js → chunk-pwqnvbt7.js} +65 -46
- package/chunk-pzr31nz7.js +12 -0
- package/{chunk-WWC7I6TA.js → chunk-q3cx89sw.js} +2 -4
- package/chunk-q5pe7be3.js +78 -0
- package/{chunk-ZHWTBHT3.js → chunk-q6zqbxp2.js} +418 -409
- package/chunk-q7r0e1p3.js +15 -0
- package/chunk-q8t2fecd.js +6 -0
- package/{chunk-2QAZCYOM.js → chunk-q94zx4d0.js} +721 -753
- package/{runtimeDoctorCommands-52MBG5JN.js → chunk-qarz1az1.js} +65 -85
- package/{chunk-4INJGWE3.js → chunk-qdcvr25b.js} +72 -53
- package/{streamAgentChatTurn-KOUWITHH.js → chunk-qxs27wfg.js} +1079 -1475
- package/{chunk-GIXWVN2W.js → chunk-r06ycjjr.js} +50 -47
- package/{chunk-63W5N6P3.js → chunk-r20jw5hb.js} +57 -38
- package/{chunk-I5BYFTYK.js → chunk-r7sfwdka.js} +1201 -1142
- package/{chunk-UMADT6B2.js → chunk-r9sp1yyb.js} +6 -8
- package/{handleSendMessageAction-FHGUFT2X.js → chunk-rbd2vgb3.js} +627 -757
- package/chunk-rc37js46.js +12 -0
- package/{chunk-5YI447UL.js → chunk-rmngk6r3.js} +67 -76
- package/chunk-rnhbnbrq.js +15 -0
- package/{chunk-WRHVVIGI.js → chunk-rsfnmrt5.js} +111 -131
- package/{chunk-YFSM2366.js → chunk-rvvn2rhj.js} +28 -22
- package/{chunk-4Y6CZ2N4.js → chunk-s0fpz7ht.js} +37 -33
- package/{chunk-VI4SWTUO.js → chunk-s1cqzb2r.js} +77 -65
- package/{chunk-6QDYSCPW.js → chunk-s8q81tda.js} +73 -65
- package/chunk-s9hy639e.js +6 -0
- package/{chunk-R5GO3YZP.js → chunk-s9vbwme8.js} +115 -106
- package/chunk-sger1m1b.js +20 -0
- package/chunk-spe6crvk.js +60 -0
- package/chunk-spwsrvh9.js +70 -0
- package/chunk-sr05zpk7.js +573 -0
- package/{chunk-M2EJHDJP.js → chunk-srncrd3f.js} +1 -12
- package/{chunk-QXHFIX7W.js → chunk-sry80bpx.js} +71 -53
- package/{chunk-PSCNXBYA.js → chunk-t6q69p83.js} +3 -4
- package/{chunk-UAD2WT54.js → chunk-t714r4q0.js} +9 -28
- package/chunk-t7vbraqe.js +42 -0
- package/{chunk-CVMMWN6P.js → chunk-td7653rr.js} +10 -20
- package/{chunk-3BQDF4QB.js → chunk-tmytcetz.js} +17 -21
- package/{chunk-AMWMV56B.js → chunk-tta4prwg.js} +16 -15
- package/chunk-tvh8azgq.js +4829 -0
- package/{chunk-ID4G2MAR.js → chunk-v08kbfm8.js} +10 -11
- package/{chunk-OKPOQGQJ.js → chunk-v1x702q8.js} +801 -852
- package/{chunk-KHCLMKZZ.js → chunk-v39fea91.js} +576 -247
- package/{chunk-OW765XBU.js → chunk-vejtd8p2.js} +3 -4
- package/chunk-vep7zkha.js +368 -0
- package/chunk-vfwn1k7n.js +142 -0
- package/chunk-vg68vxhx.js +20 -0
- package/chunk-vgcqgnsm.js +31 -0
- package/{chunk-NF64D32W.js → chunk-vnzyjdea.js} +1 -3
- package/{chunk-ZCLSM5AK.js → chunk-vqgtw1px.js} +800 -717
- package/chunk-vv1gr5xz.js +76 -0
- package/{spaceCommands-Z2CTQD6G.js → chunk-w1qeadpq.js} +176 -242
- package/chunk-w468ez1p.js +13 -0
- package/chunk-w49s0t79.js +14 -0
- package/{mcpLocalManageCommands-KUDZQRM4.js → chunk-w58zhfbn.js} +91 -93
- package/chunk-w5b74aq6.js +11 -0
- package/chunk-w7y41qyw.js +117 -0
- package/chunk-w820gg1w.js +4165 -0
- package/{chunk-DBJAJ4UD.js → chunk-wdsmaqmt.js} +399 -453
- package/{chunk-3EUW3WEO.js → chunk-wfvvnmmj.js} +1 -3
- package/{chunk-QY4NZCDA.js → chunk-wkr04bhk.js} +432 -651
- package/{chunk-KUG52IAP.js → chunk-ws402twv.js} +1 -3
- package/chunk-wzwh311q.js +164 -0
- package/{runtimeModeArgs-X7DL7PUN.js → chunk-x5vtgvwn.js} +6 -5
- package/{agentMachineCommands-COJD2KPZ.js → chunk-x8h2csmq.js} +152 -195
- package/{chunk-BAZCS5XG.js → chunk-x9zfjnrc.js} +59 -47
- package/{chunk-WTIJKWCI.js → chunk-xcarc2rf.js} +50 -56
- package/chunk-xf33gz0a.js +8 -0
- package/{chunk-PVFYPUIM.js → chunk-y7b3gwx1.js} +78 -71
- package/{memoryCommands-SVLAVFCV.js → chunk-y7sphmnh.js} +119 -95
- package/{agentListCommands-436FHOIT.js → chunk-ycvaafhc.js} +260 -374
- package/chunk-yd7zprb0.js +9 -0
- package/chunk-yfz3d27k.js +40 -0
- package/{chunk-MKR6KDD3.js → chunk-ykv9g3m4.js} +141 -125
- package/chunk-ystjgb9e.js +544 -0
- package/chunk-yysxn7ep.js +12 -0
- package/{chunk-AL3TYDIF.js → chunk-z17eyawk.js} +18 -16
- package/{machineCommands-RVB5OG2X.js → chunk-z17q416p.js} +442 -563
- package/chunk-z1n98pcf.js +12 -0
- package/{dialogTraceCommand-HWXGIGZX.js → chunk-z566jx5r.js} +292 -397
- package/chunk-zjxd6942.js +6 -0
- package/{versionChangeNotice-RFABJGJE.js → chunk-zk11x9y5.js} +7 -9
- package/{chunk-TEFD5E2D.js → chunk-zt73yc33.js} +48 -51
- package/chunk-zvs2fra1.js +5 -0
- package/{chunk-SVFFKLMR.js → chunk-zwee84rh.js} +117 -141
- package/chunk-zxgfqv72.js +8 -0
- package/index.js +53 -69
- package/package.json +4 -4
- package/_executeModel-YQNZNR2Y.js +0 -341
- package/action-UK3HXGXF.js +0 -30
- package/addContentAction-CAKFVBDM.js +0 -38
- package/addDialogAgentAction-KLJ2YWWM.js +0 -77
- package/agentDeleteCommand-S5FVPYKT.js +0 -523
- package/agentEmailCommands-ZEFMGVKM.js +0 -742
- package/agentRecordCommands-JZ35AC5A.js +0 -211
- package/agentRun-UIO43TUG.js +0 -251
- package/agentRunCommand-ATLKKD6O.js +0 -249
- package/agentRunControl-U2MV74WR.js +0 -211
- package/agentRuntimeLocal-P4MMGIR6.js +0 -189
- package/agentSlice-HHNKNNYM.js +0 -52
- package/appConfigCommands-W4JQHMOJ.js +0 -417
- package/appDeleteCommands-IXR47IAV.js +0 -183
- package/appDeployCommands-LB6DHDF4.js +0 -232
- package/appDeployStatusCommands-UQ6MJL6D.js +0 -204
- package/appGetCommands-M5JCTDDQ.js +0 -185
- package/appListCommands-TE3ZHE3I.js +0 -186
- package/appMigrateCommands-FOXH6R4B.js +0 -230
- package/appSourceCommands-3ACYB6I7.js +0 -279
- package/authCommand-I5OBJP5S.js +0 -66
- package/authCommands-I6KCGOCN.js +0 -54
- package/builtinSkillRegistry-MIXYSZUU.js +0 -35
- package/chromeOpsCommands-IZRCYDSW.js +0 -579
- package/chunk-24BICQPB.js +0 -25
- package/chunk-2E4BYAUE.js +0 -69
- package/chunk-2O72G3U2.js +0 -17157
- package/chunk-2OROOEOQ.js +0 -229
- package/chunk-2R6M34JP.js +0 -27225
- package/chunk-2SXN7LAY.js +0 -15
- package/chunk-35JIFLIG.js +0 -30
- package/chunk-3VXVE2LF.js +0 -12
- package/chunk-4DBTBNTX.js +0 -477
- package/chunk-4JH2UMJR.js +0 -40
- package/chunk-4RUQ2PFX.js +0 -432
- package/chunk-4SN6J65J.js +0 -38
- package/chunk-5MMAK75Q.js +0 -15
- package/chunk-6NYQHXMV.js +0 -1737
- package/chunk-6R4IY46J.js +0 -14
- package/chunk-7E6YXSFZ.js +0 -441
- package/chunk-7K4J76JQ.js +0 -917
- package/chunk-7LR2IFUH.js +0 -100
- package/chunk-AETZ7AD6.js +0 -274
- package/chunk-ATNTHIZI.js +0 -13
- package/chunk-BPB3T5EU.js +0 -791
- package/chunk-BV3FLP2L.js +0 -133
- package/chunk-BVYHE6QD.js +0 -110
- package/chunk-BWJLEN6X.js +0 -1388
- package/chunk-CHOZJMJS.js +0 -78
- package/chunk-D2LTQAGN.js +0 -464
- package/chunk-DALXH7BG.js +0 -3392
- package/chunk-DBCWXGOC.js +0 -15210
- package/chunk-DLXL4NSL.js +0 -1179
- package/chunk-DSBRIUX5.js +0 -23
- package/chunk-DWLEOOGR.js +0 -8
- package/chunk-E2KZNP6C.js +0 -13
- package/chunk-E5JV4DCB.js +0 -272
- package/chunk-EUGTFFO6.js +0 -42
- package/chunk-FBNVJ2TO.js +0 -294
- package/chunk-FGXG6OLW.js +0 -34
- package/chunk-G22P2J7O.js +0 -1775
- package/chunk-HEVRQGGH.js +0 -106
- package/chunk-HHXF57CL.js +0 -180
- package/chunk-HI5RS2O4.js +0 -2109
- package/chunk-HJTI7RZV.js +0 -94
- package/chunk-HRWRIPTB.js +0 -531
- package/chunk-HYCVEESH.js +0 -2824
- package/chunk-I42VC5KR.js +0 -15
- package/chunk-IB5AR52X.js +0 -15
- package/chunk-IIRJ4P4I.js +0 -24
- package/chunk-IT3ZZRJE.js +0 -12
- package/chunk-IV6VUVLJ.js +0 -88
- package/chunk-J42X32PV.js +0 -472
- package/chunk-JDMWYVUF.js +0 -449
- package/chunk-JKVOKKMQ.js +0 -53
- package/chunk-JRTNUU5Z.js +0 -54
- package/chunk-K7HLFORE.js +0 -226
- package/chunk-KGBASAB5.js +0 -74
- package/chunk-KGKTN2NX.js +0 -25
- package/chunk-KX6YBIHG.js +0 -8
- package/chunk-KYHNSSL2.js +0 -62
- package/chunk-KZO2MTVM.js +0 -140
- package/chunk-LKZPX6YH.js +0 -0
- package/chunk-LLP2NDED.js +0 -201
- package/chunk-LOFRSJX2.js +0 -47
- package/chunk-M75RM77T.js +0 -3970
- package/chunk-MDAYRIP7.js +0 -1889
- package/chunk-MI6HRMCK.js +0 -25
- package/chunk-MTNQNLSE.js +0 -1029
- package/chunk-NH4PUEWK.js +0 -762
- package/chunk-NHLLXINQ.js +0 -8
- package/chunk-NTUNHTJV.js +0 -40
- package/chunk-OJKUU3LP.js +0 -67
- package/chunk-OQH3TAB7.js +0 -299
- package/chunk-P62DHV4F.js +0 -443
- package/chunk-PHIERFHT.js +0 -574
- package/chunk-PKDFU6MY.js +0 -102
- package/chunk-PL5RKESU.js +0 -40
- package/chunk-PSJJBBWV.js +0 -42
- package/chunk-QKM55LP2.js +0 -739
- package/chunk-QQ56R7KS.js +0 -88
- package/chunk-QYPE3TS3.js +0 -43
- package/chunk-REAE2SZK.js +0 -62
- package/chunk-RGQ4UUWZ.js +0 -208
- package/chunk-RIRFHJTW.js +0 -353
- package/chunk-RYMLMTPZ.js +0 -547
- package/chunk-SSGTV4FC.js +0 -303
- package/chunk-SVKWZ3EG.js +0 -607
- package/chunk-T7KODHYS.js +0 -317
- package/chunk-TGVVE5BA.js +0 -3085
- package/chunk-TKLBBR7P.js +0 -779
- package/chunk-TZXPT53C.js +0 -8
- package/chunk-U67V476Y.js +0 -35
- package/chunk-UEILX4EV.js +0 -15
- package/chunk-VIWDGTDA.js +0 -8
- package/chunk-VXUQWCEZ.js +0 -138
- package/chunk-W5GKF5ZW.js +0 -32
- package/chunk-WDWZPASX.js +0 -29
- package/chunk-WX266G2C.js +0 -9594
- package/chunk-YCITCYSJ.js +0 -356
- package/chunk-Z3KTXWWB.js +0 -76
- package/chunk-ZC3CMUKU.js +0 -322
- package/chunk-ZSZBHRLP.js +0 -1710
- package/chunk-ZV7ZY46L.js +0 -1343
- package/cliAgentConfigHelpers-WB2S7PDO.js +0 -47
- package/cliAuthorityBrokerClient-3SKOA7OZ.js +0 -23
- package/cliAuthorityBrokerProcess-BMBVXPKU.js +0 -24
- package/cliAuthorityStoreDriver-6FE3BJNB.js +0 -20
- package/cliEnvHelpers-7V5ZWUJA.js +0 -34
- package/cliExecutor-N3445G2Z.js +0 -45
- package/cliLocalAgentRecordReader-QKKRK53P.js +0 -113
- package/cloudAutomationCommands-S52NKCLL.js +0 -310
- package/contentThunks-ERA42OXW.js +0 -100
- package/cooldownCommands-ZFDAL4MR.js +0 -79
- package/createAgentAutomationAction-DMD2VDPI.js +0 -173
- package/createDialogAction-3SPOJQAK.js +0 -87
- package/createPageAction-AVXUMZVT.js +0 -91
- package/cursorProvider-2RACMEMF.js +0 -6123
- package/db-LTHLW7QA.js +0 -178
- package/dbSlice-WNUHTF4C.js +0 -76
- package/deleteDbKey-KV6MYBAI.js +0 -87
- package/desktopFolderProjects-4POAMVJN.js +0 -45
- package/dialogCommands-4MOLJW4G.js +0 -165
- package/dialogMessageRecord-2HJTEXQX.js +0 -7
- package/dialogNotifyCommand-YL2GFKLO.js +0 -45
- package/dialogSlice-Q7H2YVNO.js +0 -200
- package/dialogUsageCommand-IO2BQKL2.js +0 -31
- package/docCreateCommands-OYLRBK2M.js +0 -255
- package/docDeleteCommands-3NF6QPJU.js +0 -226
- package/docReadCommands-CBAERJAP.js +0 -184
- package/docStore-GWPFDV6Y.js +0 -89
- package/docUpdateCommands-BAMCGX6F.js +0 -326
- package/ebookDownloaderAgentCommand-NOIZ6U7Y.js +0 -675
- package/fetchMessages-P7FSCSXV.js +0 -19
- package/getPricing-KNXVEIUI.js +0 -40
- package/hostCredentialCreate-2VEYBXJV.js +0 -402
- package/i18n-SAK6DDY4.js +0 -51
- package/keys-FXEGMKSG.js +0 -183
- package/legacyMigration-TF4SYJCZ.js +0 -19
- package/levelAuthorityStore-L5SVDM5O.js +0 -10
- package/localAutomationCommands-XSK7SM7I.js +0 -199
- package/localAutomationRuntime-5WBO7HGQ.js +0 -61
- package/localRecall-BDYKXB46.js +0 -17
- package/localRuntimeAdapter-Y6H6XRIH.js +0 -310
- package/localRuntimeAuthority-Q5C2KWGF.js +0 -45
- package/localRuntimeDb-MM3DINZM.js +0 -12
- package/machineInfo-HNPJHQFU.js +0 -14
- package/machineWsRunDispatch-Y5SJGCEE.js +0 -228
- package/models-TOXYINNM.js +0 -10
- package/oauthTokenStore-RUYNYALS.js +0 -24
- package/overlay-JA3SPVUS.js +0 -15
- package/parityCommands-5OCBPVES.js +0 -613
- package/processSpawn-6GEO77KV.js +0 -11
- package/profileConfig-KOWK4HOG.js +0 -49
- package/projectArchive-WE3VVPZ2.js +0 -132
- package/providerPresetApply-YCVSP2WX.js +0 -235
- package/providerRegistry-26PAUYH2.js +0 -24
- package/read-D4WYJQJQ.js +0 -32
- package/readDocTool-3S3OQFOH.js +0 -22
- package/rememberExplicit-ZPI6KK5M.js +0 -16
- package/remove-AHRMUDMH.js +0 -32
- package/removeDialogAgentAction-AALRBFSA.js +0 -81
- package/secretCommands-2PSS3QNZ.js +0 -24
- package/setDialogExtraReferencesAction-SLHQ3GYL.js +0 -39
- package/setPrimaryDialogAgentAction-XKCSGJ7M.js +0 -96
- package/skillDiscovery-IUEZZG2B.js +0 -29
- package/skillSummaryMarker-62UW7HI7.js +0 -9
- package/slateToRenderMarkdown-R3X74MCX.js +0 -7
- package/slateUtils-ESQAJ6RN.js +0 -19
- package/store-WSAVTR32.js +0 -50
- package/switchDialogAgentAction-YJIWQGIR.js +0 -70
- package/tombstones-FQQMEDOW.js +0 -32
- package/toolApiClient-FVXTIIEN.js +0 -42
- package/tools-WN4AVSNS.js +0 -147
- package/tuiRestart-LU2BDLAW.js +0 -50
- package/tuiSummaryLlmCaller-Z2ZVBIGN.js +0 -53
- package/updateCommands-4QP7WJLA.js +0 -63
- package/usageCommand-AZX7D3LB.js +0 -31
- package/usageRebuildCommand-XV5QQCHK.js +0 -623
- package/userDataMerge-HT2ZVHBJ.js +0 -13
- package/windowsSelfUpdate-5OFKSW6Y.js +0 -14
- package/workContext-ZAW6VXT7.js +0 -18
- package/workContextAccess-VU5I4LKZ.js +0 -11
- package/workContextWriteNotice-YCSSMHN4.js +0 -7
- /package/{chunk-BYXBJQAS.js → chunk-0bcc25vg.js} +0 -0
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
AGENT_RUN_PROTOCOL,
|
|
3
|
+
RuntimeVersionMismatchError,
|
|
4
|
+
getHostRuntimeExecutable,
|
|
5
|
+
HOST_RUNTIME_CONTENT_IDENTITY,
|
|
6
|
+
resolveExactRuntimeEntrypoint,
|
|
7
|
+
isCompiledBinary2,
|
|
8
|
+
resolveCliEntrypointPath2
|
|
9
|
+
} from "./chunk-cfh6tfc3.js";
|
|
9
10
|
import {
|
|
10
11
|
resolveModelTier
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-k2ep3rb2.js";
|
|
13
|
+
import {
|
|
14
|
+
isAgentRunTerminalStatus,
|
|
15
|
+
shortAgentKey,
|
|
16
|
+
normalizeRunTitle
|
|
17
|
+
} from "./chunk-eqzvk3xm.js";
|
|
12
18
|
import {
|
|
13
19
|
AUTH_ERROR_PATTERNS
|
|
14
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-b00vzjkb.js";
|
|
21
|
+
import {
|
|
22
|
+
findPowerShellExecutable
|
|
23
|
+
} from "./chunk-q94zx4d0.js";
|
|
15
24
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from "./chunk-
|
|
25
|
+
resolveRuntimeServerUrl,
|
|
26
|
+
resolveRuntimeAuthToken
|
|
27
|
+
} from "./chunk-cwnvf8dt.js";
|
|
19
28
|
import {
|
|
20
29
|
isRecord
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import {
|
|
23
|
-
AGENT_RUN_PROTOCOL,
|
|
24
|
-
HOST_RUNTIME_CONTENT_IDENTITY,
|
|
25
|
-
RuntimeVersionMismatchError,
|
|
26
|
-
getHostRuntimeExecutable,
|
|
27
|
-
isCompiledBinary,
|
|
28
|
-
resolveCliEntrypointPath,
|
|
29
|
-
resolveExactRuntimeEntrypoint
|
|
30
|
-
} from "./chunk-2AJLG6PY.js";
|
|
30
|
+
} from "./chunk-ws402twv.js";
|
|
31
31
|
|
|
32
32
|
// packages/cli/mcp/mcpApprovalTransport.ts
|
|
33
33
|
import { randomUUID, createHash } from "node:crypto";
|
|
@@ -40,28 +40,33 @@ function sendInheritedApproval(channel, kind, message, failed) {
|
|
|
40
40
|
}
|
|
41
41
|
try {
|
|
42
42
|
channel.send({ kind, ...message }, (error) => {
|
|
43
|
-
if (error)
|
|
43
|
+
if (error)
|
|
44
|
+
failed();
|
|
44
45
|
});
|
|
45
46
|
} catch {
|
|
46
47
|
failed();
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
function bindInheritedApprovalLifetime(channel, close, signal) {
|
|
50
|
-
for (const event of ["disconnect", "exit", "error"])
|
|
51
|
+
for (const event of ["disconnect", "exit", "error"])
|
|
52
|
+
channel.on(event, close);
|
|
51
53
|
signal?.addEventListener("abort", close, { once: true });
|
|
52
54
|
return () => {
|
|
53
|
-
for (const event of ["disconnect", "exit", "error"])
|
|
55
|
+
for (const event of ["disconnect", "exit", "error"])
|
|
56
|
+
channel.removeListener(event, close);
|
|
54
57
|
signal?.removeEventListener("abort", close);
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
// packages/cli/mcp/mcpApprovalTransport.ts
|
|
59
62
|
var KIND = "nolo.mcp-approval.v1";
|
|
60
|
-
var TTL =
|
|
63
|
+
var TTL = 60000;
|
|
61
64
|
var MAX = 256;
|
|
62
65
|
function canonical(value) {
|
|
63
|
-
if (Array.isArray(value))
|
|
64
|
-
|
|
66
|
+
if (Array.isArray(value))
|
|
67
|
+
return `[${value.map(canonical).join(",")}]`;
|
|
68
|
+
if (value && typeof value === "object")
|
|
69
|
+
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
|
|
65
70
|
return JSON.stringify(value);
|
|
66
71
|
}
|
|
67
72
|
function snapshot(preview) {
|
|
@@ -75,32 +80,34 @@ function attachMcpApprovalHost(channel, host) {
|
|
|
75
80
|
const binding = Object.freeze({ ...host.binding });
|
|
76
81
|
let closed = false;
|
|
77
82
|
let count = 0;
|
|
78
|
-
const seen =
|
|
79
|
-
const active =
|
|
80
|
-
const
|
|
81
|
-
let unbind = () => {
|
|
82
|
-
};
|
|
83
|
+
const seen = new Set;
|
|
84
|
+
const active = new Map;
|
|
85
|
+
const send = (message) => sendInheritedApproval(channel, KIND, message, close);
|
|
86
|
+
let unbind = () => {};
|
|
83
87
|
const close = () => {
|
|
84
|
-
if (closed)
|
|
88
|
+
if (closed)
|
|
89
|
+
return;
|
|
85
90
|
closed = true;
|
|
86
|
-
for (const controller of active.values())
|
|
91
|
+
for (const controller of active.values())
|
|
92
|
+
controller.abort();
|
|
87
93
|
active.clear();
|
|
88
|
-
sendInheritedApproval(channel, KIND, { type: "revoke" }, () => {
|
|
89
|
-
});
|
|
94
|
+
sendInheritedApproval(channel, KIND, { type: "revoke" }, () => {});
|
|
90
95
|
channel.removeListener("message", receive);
|
|
91
96
|
unbind();
|
|
92
97
|
};
|
|
93
98
|
const receive = (m) => {
|
|
94
|
-
if (closed || m?.kind !== KIND)
|
|
99
|
+
if (closed || m?.kind !== KIND)
|
|
100
|
+
return;
|
|
95
101
|
if (m.type === "hello") {
|
|
96
|
-
|
|
102
|
+
send({ type: "binding", binding });
|
|
97
103
|
return;
|
|
98
104
|
}
|
|
99
105
|
if (m.type === "cancel") {
|
|
100
106
|
active.get(m.id)?.abort();
|
|
101
107
|
return;
|
|
102
108
|
}
|
|
103
|
-
if (m.type !== "request")
|
|
109
|
+
if (m.type !== "request")
|
|
110
|
+
return;
|
|
104
111
|
if (++count > MAX || typeof m.id !== "string" || seen.has(m.id)) {
|
|
105
112
|
close();
|
|
106
113
|
return;
|
|
@@ -108,58 +115,65 @@ function attachMcpApprovalHost(channel, host) {
|
|
|
108
115
|
seen.add(m.id);
|
|
109
116
|
let preview;
|
|
110
117
|
try {
|
|
111
|
-
if (typeof m.snapshot !== "string" || JSON.stringify(m.preview).length > 262144)
|
|
118
|
+
if (typeof m.snapshot !== "string" || JSON.stringify(m.preview).length > 262144)
|
|
119
|
+
throw new Error("invalid preview");
|
|
112
120
|
preview = structuredClone(m.preview);
|
|
113
|
-
if (m.runId !== binding.runId || !valid(preview, binding) || snapshot(preview) !== m.snapshot)
|
|
121
|
+
if (m.runId !== binding.runId || !valid(preview, binding) || snapshot(preview) !== m.snapshot)
|
|
122
|
+
throw new Error("binding mismatch");
|
|
114
123
|
} catch {
|
|
115
|
-
|
|
124
|
+
send({ type: "decision", id: m.id, runId: binding.runId, snapshot: m.snapshot, decision: "deny" });
|
|
116
125
|
return;
|
|
117
126
|
}
|
|
118
|
-
const controller = new AbortController
|
|
127
|
+
const controller = new AbortController;
|
|
119
128
|
active.set(m.id, controller);
|
|
120
129
|
const timer = setTimeout(() => controller.abort(), Math.max(0, preview.expiresAt - Date.now()));
|
|
121
|
-
|
|
122
|
-
controller.signal.addEventListener("abort", () =>
|
|
123
|
-
Promise.resolve().then(() => closed || controller.signal.aborted ? "deny" : host.confirm(preview, controller.signal, { runId: binding.runId, requestId: m.id })).then(
|
|
130
|
+
new Promise((resolve) => {
|
|
131
|
+
controller.signal.addEventListener("abort", () => resolve("deny"), { once: true });
|
|
132
|
+
Promise.resolve().then(() => closed || controller.signal.aborted ? "deny" : host.confirm(preview, controller.signal, { runId: binding.runId, requestId: m.id })).then(resolve, () => resolve("unavailable"));
|
|
124
133
|
}).then((decision) => {
|
|
125
134
|
clearTimeout(timer);
|
|
126
135
|
active.delete(m.id);
|
|
127
|
-
if (!closed)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
if (!closed)
|
|
137
|
+
send({
|
|
138
|
+
type: "decision",
|
|
139
|
+
id: m.id,
|
|
140
|
+
runId: binding.runId,
|
|
141
|
+
snapshot: m.snapshot,
|
|
142
|
+
decision: !controller.signal.aborted && Date.now() < preview.expiresAt ? decision : "deny"
|
|
143
|
+
});
|
|
134
144
|
});
|
|
135
145
|
};
|
|
136
146
|
channel.on("message", receive);
|
|
137
147
|
unbind = bindInheritedApprovalLifetime(channel, close, host.signal);
|
|
138
|
-
if (host.signal.aborted || channel.connected === false)
|
|
148
|
+
if (host.signal.aborted || channel.connected === false)
|
|
149
|
+
close();
|
|
139
150
|
return close;
|
|
140
151
|
}
|
|
141
152
|
function createMcpApprovalChild(channel) {
|
|
142
|
-
const lifetime = new AbortController
|
|
153
|
+
const lifetime = new AbortController;
|
|
143
154
|
let binding;
|
|
144
155
|
let count = 0;
|
|
145
156
|
let closed = false;
|
|
146
|
-
const pending =
|
|
147
|
-
const readyResolvers =
|
|
148
|
-
let unbind = () => {
|
|
149
|
-
};
|
|
157
|
+
const pending = new Map;
|
|
158
|
+
const readyResolvers = new Set;
|
|
159
|
+
let unbind = () => {};
|
|
150
160
|
const close = () => {
|
|
151
|
-
if (closed)
|
|
161
|
+
if (closed)
|
|
162
|
+
return;
|
|
152
163
|
closed = true;
|
|
153
164
|
lifetime.abort();
|
|
154
|
-
for (const entry of pending.values())
|
|
155
|
-
|
|
165
|
+
for (const entry of pending.values())
|
|
166
|
+
entry.finish("unavailable");
|
|
167
|
+
for (const resolve of readyResolvers)
|
|
168
|
+
resolve();
|
|
156
169
|
readyResolvers.clear();
|
|
157
170
|
channel.removeListener("message", receive);
|
|
158
171
|
unbind();
|
|
159
172
|
};
|
|
160
|
-
const
|
|
173
|
+
const send = (message) => sendInheritedApproval(channel, KIND, message, close);
|
|
161
174
|
const receive = (m) => {
|
|
162
|
-
if (closed || m?.kind !== KIND)
|
|
175
|
+
if (closed || m?.kind !== KIND)
|
|
176
|
+
return;
|
|
163
177
|
if (m.type === "revoke") {
|
|
164
178
|
close();
|
|
165
179
|
return;
|
|
@@ -170,51 +184,61 @@ function createMcpApprovalChild(channel) {
|
|
|
170
184
|
return;
|
|
171
185
|
}
|
|
172
186
|
binding = Object.freeze({ ...m.binding });
|
|
173
|
-
for (const
|
|
187
|
+
for (const resolve of readyResolvers)
|
|
188
|
+
resolve();
|
|
174
189
|
readyResolvers.clear();
|
|
175
190
|
return;
|
|
176
191
|
}
|
|
177
|
-
if (m.type !== "decision")
|
|
192
|
+
if (m.type !== "decision")
|
|
193
|
+
return;
|
|
178
194
|
const entry = pending.get(m.id);
|
|
179
|
-
if (!entry)
|
|
195
|
+
if (!entry)
|
|
196
|
+
return;
|
|
180
197
|
const matches = binding && m.runId === binding.runId && m.snapshot === entry.snapshot && Date.now() < entry.expiresAt;
|
|
181
198
|
entry.finish(!matches ? "deny" : m.decision === "approve" ? "approve" : m.decision === "unavailable" ? "unavailable" : "deny");
|
|
182
199
|
};
|
|
183
200
|
channel.on("message", receive);
|
|
184
201
|
unbind = bindInheritedApprovalLifetime(channel, close);
|
|
185
|
-
|
|
202
|
+
send({ type: "hello" });
|
|
186
203
|
const confirm = async (input, signal) => {
|
|
187
|
-
if (closed || signal.aborted || ++count > MAX)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
if (closed || signal.aborted || ++count > MAX)
|
|
205
|
+
return "unavailable";
|
|
206
|
+
if (!binding)
|
|
207
|
+
await new Promise((resolve) => {
|
|
208
|
+
const done = () => {
|
|
209
|
+
clearTimeout(timer);
|
|
210
|
+
readyResolvers.delete(done);
|
|
211
|
+
signal.removeEventListener("abort", done);
|
|
212
|
+
resolve();
|
|
213
|
+
};
|
|
214
|
+
const timer = setTimeout(done, Math.max(0, Math.min(TTL, input.expiresAt - Date.now())));
|
|
215
|
+
readyResolvers.add(done);
|
|
216
|
+
signal.addEventListener("abort", done, { once: true });
|
|
217
|
+
});
|
|
218
|
+
if (closed || !binding)
|
|
219
|
+
return "unavailable";
|
|
220
|
+
if (signal.aborted || !valid(input, binding))
|
|
221
|
+
return "deny";
|
|
201
222
|
const preview = structuredClone(input), id = randomUUID(), digest = snapshot(preview);
|
|
202
|
-
return new Promise((
|
|
223
|
+
return new Promise((resolve) => {
|
|
203
224
|
const abort = () => {
|
|
204
|
-
|
|
225
|
+
send({ type: "cancel", id });
|
|
205
226
|
finish("deny");
|
|
206
227
|
};
|
|
207
228
|
const timer = setTimeout(abort, Math.max(0, preview.expiresAt - Date.now()));
|
|
208
229
|
const finish = (value) => {
|
|
209
|
-
if (!pending.delete(id))
|
|
230
|
+
if (!pending.delete(id))
|
|
231
|
+
return;
|
|
210
232
|
clearTimeout(timer);
|
|
211
233
|
signal.removeEventListener("abort", abort);
|
|
212
|
-
|
|
234
|
+
resolve(value);
|
|
213
235
|
};
|
|
214
236
|
pending.set(id, { finish, snapshot: digest, expiresAt: preview.expiresAt });
|
|
215
237
|
signal.addEventListener("abort", abort, { once: true });
|
|
216
|
-
if (signal.aborted)
|
|
217
|
-
|
|
238
|
+
if (signal.aborted)
|
|
239
|
+
abort();
|
|
240
|
+
else
|
|
241
|
+
send({ type: "request", id, runId: binding.runId, snapshot: digest, preview });
|
|
218
242
|
});
|
|
219
243
|
};
|
|
220
244
|
return { confirm, signal: lifetime.signal, close };
|
|
@@ -233,13 +257,13 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
233
257
|
const binding = { ...deps.binding };
|
|
234
258
|
const now = deps.now ?? Date.now;
|
|
235
259
|
const createRequestId = deps.createRequestId ?? (() => crypto.randomUUID());
|
|
236
|
-
const timeoutMs = deps.timeoutMs ??
|
|
237
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs >
|
|
260
|
+
const timeoutMs = deps.timeoutMs ?? 60000;
|
|
261
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0 || timeoutMs > 300000) {
|
|
238
262
|
throw new Error("Shell approval timeout must be finite, > 0 and <= 300000ms");
|
|
239
263
|
}
|
|
240
|
-
const requests =
|
|
264
|
+
const requests = new Map;
|
|
241
265
|
const fail = (reason) => ({ ok: false, reason });
|
|
242
|
-
const
|
|
266
|
+
const snapshot = (request) => ({ ok: true, request: { ...request } });
|
|
243
267
|
const validIdentity = (call) => {
|
|
244
268
|
try {
|
|
245
269
|
return IDENTITY_KEYS.every((key) => typeof call[key] === "string" && call[key].trim().length > 0 && call[key] === binding[key]) && isAbsolute(call.workspaceRoot) && deps.resolveWorkspace(call.workspaceRoot) === binding.workspaceRoot;
|
|
@@ -247,7 +271,8 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
247
271
|
return false;
|
|
248
272
|
}
|
|
249
273
|
};
|
|
250
|
-
if (!validIdentity(binding))
|
|
274
|
+
if (!validIdentity(binding))
|
|
275
|
+
throw new Error("Shell approval requires a canonical host binding");
|
|
251
276
|
const timeout = () => {
|
|
252
277
|
const time = now();
|
|
253
278
|
let expired = 0;
|
|
@@ -261,53 +286,63 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
261
286
|
};
|
|
262
287
|
const lookup = (id, call) => {
|
|
263
288
|
timeout();
|
|
264
|
-
if (!validIdentity(call))
|
|
289
|
+
if (!validIdentity(call))
|
|
290
|
+
return fail("identity_mismatch");
|
|
265
291
|
const request = requests.get(id);
|
|
266
|
-
if (!request)
|
|
267
|
-
|
|
268
|
-
|
|
292
|
+
if (!request)
|
|
293
|
+
return fail("unknown_request");
|
|
294
|
+
if (!CALL_KEYS.every((key) => request[key] === call[key]))
|
|
295
|
+
return fail("call_mismatch");
|
|
296
|
+
return snapshot(request);
|
|
269
297
|
};
|
|
270
298
|
return {
|
|
271
299
|
request(call) {
|
|
272
300
|
timeout();
|
|
273
|
-
if (!validIdentity(call))
|
|
274
|
-
|
|
275
|
-
if (
|
|
301
|
+
if (!validIdentity(call))
|
|
302
|
+
return fail("identity_mismatch");
|
|
303
|
+
if (typeof call.toolName !== "string" || !call.toolName.trim() || typeof call.command !== "string" || !call.command.trim())
|
|
304
|
+
return fail("invalid_request");
|
|
305
|
+
if (requests.size >= MAX_REQUESTS_PER_BRIDGE)
|
|
306
|
+
return fail("capacity");
|
|
276
307
|
const createdAt = now();
|
|
277
|
-
if (!Number.isFinite(createdAt) || !Number.isFinite(createdAt + timeoutMs))
|
|
308
|
+
if (!Number.isFinite(createdAt) || !Number.isFinite(createdAt + timeoutMs))
|
|
309
|
+
return fail("invalid_request");
|
|
278
310
|
let requestId;
|
|
279
311
|
try {
|
|
280
312
|
requestId = createRequestId();
|
|
281
313
|
} catch {
|
|
282
314
|
return fail("invalid_request");
|
|
283
315
|
}
|
|
284
|
-
if (typeof requestId !== "string" || !requestId.trim() || requests.has(requestId))
|
|
316
|
+
if (typeof requestId !== "string" || !requestId.trim() || requests.has(requestId))
|
|
317
|
+
return fail("invalid_request");
|
|
285
318
|
const request = {
|
|
286
319
|
...binding,
|
|
287
320
|
toolName: call.toolName,
|
|
288
321
|
command: call.command,
|
|
289
|
-
...call.executionPayload !==
|
|
322
|
+
...call.executionPayload !== undefined ? { executionPayload: call.executionPayload } : {},
|
|
290
323
|
requestId,
|
|
291
324
|
createdAt,
|
|
292
325
|
expiresAt: createdAt + timeoutMs,
|
|
293
326
|
state: "pending"
|
|
294
327
|
};
|
|
295
328
|
requests.set(requestId, request);
|
|
296
|
-
return
|
|
329
|
+
return snapshot(request);
|
|
297
330
|
},
|
|
298
331
|
decide(id, call, decision) {
|
|
299
332
|
const result = lookup(id, call);
|
|
300
|
-
if (!result.ok)
|
|
333
|
+
if (!result.ok)
|
|
334
|
+
return result;
|
|
301
335
|
if (result.request.state !== "pending") {
|
|
302
336
|
return fail(result.request.state === "approved" ? "invalid_request" : result.request.state);
|
|
303
337
|
}
|
|
304
|
-
if (decision !== "approve" && decision !== "deny")
|
|
338
|
+
if (decision !== "approve" && decision !== "deny")
|
|
339
|
+
return fail("invalid_request");
|
|
305
340
|
const request = {
|
|
306
341
|
...result.request,
|
|
307
342
|
state: decision === "approve" ? "approved" : "denied"
|
|
308
343
|
};
|
|
309
344
|
requests.set(id, request);
|
|
310
|
-
return
|
|
345
|
+
return snapshot(request);
|
|
311
346
|
},
|
|
312
347
|
revoke() {
|
|
313
348
|
for (const [id, request] of requests) {
|
|
@@ -319,11 +354,13 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
319
354
|
timeout,
|
|
320
355
|
consume(id, call) {
|
|
321
356
|
const result = lookup(id, call);
|
|
322
|
-
if (!result.ok)
|
|
323
|
-
|
|
357
|
+
if (!result.ok)
|
|
358
|
+
return result;
|
|
359
|
+
if (result.request.state !== "approved")
|
|
360
|
+
return fail(result.request.state);
|
|
324
361
|
const request = { ...result.request, state: "consumed" };
|
|
325
362
|
requests.set(id, request);
|
|
326
|
-
return
|
|
363
|
+
return snapshot(request);
|
|
327
364
|
}
|
|
328
365
|
};
|
|
329
366
|
}
|
|
@@ -331,10 +368,11 @@ function createOriginShellApprovalBridge(deps) {
|
|
|
331
368
|
// packages/cli/client/originShellApprovalTransport.ts
|
|
332
369
|
var KIND2 = "nolo.shell-approval.v1";
|
|
333
370
|
var MAX2 = 256;
|
|
334
|
-
var TTL2 =
|
|
371
|
+
var TTL2 = 60000;
|
|
335
372
|
var NOTICE = "Executes with this local user's reachable permissions; workspace is NOT a directory sandbox.";
|
|
336
373
|
function payloadCall(payload, binding) {
|
|
337
|
-
if (typeof payload !== "string" || payload.length > 262144)
|
|
374
|
+
if (typeof payload !== "string" || payload.length > 262144)
|
|
375
|
+
throw new Error("Invalid approval payload");
|
|
338
376
|
const execution = JSON.parse(JSON.parse(payload).binding);
|
|
339
377
|
if (execution.workspaceRoot !== binding.workspaceRoot || typeof execution.input?.command !== "string") {
|
|
340
378
|
throw new Error("Approval binding mismatch");
|
|
@@ -342,10 +380,11 @@ function payloadCall(payload, binding) {
|
|
|
342
380
|
return { ...binding, toolName: "execShell", command: execution.input.command, executionPayload: payload };
|
|
343
381
|
}
|
|
344
382
|
function send(channel, message) {
|
|
345
|
-
if (channel.connected === false || !channel.send)
|
|
383
|
+
if (channel.connected === false || !channel.send)
|
|
384
|
+
throw new Error("Approval channel disconnected");
|
|
346
385
|
channel.send({ kind: KIND2, ...message });
|
|
347
386
|
}
|
|
348
|
-
var liveApprovalHosts =
|
|
387
|
+
var liveApprovalHosts = new Set;
|
|
349
388
|
function hasLiveShellApprovalHosts() {
|
|
350
389
|
return liveApprovalHosts.size > 0;
|
|
351
390
|
}
|
|
@@ -355,25 +394,26 @@ function attachShellApprovalHost(channel, host) {
|
|
|
355
394
|
const connection = {};
|
|
356
395
|
let closed = false;
|
|
357
396
|
let count = 0;
|
|
358
|
-
const active =
|
|
359
|
-
let unbindLifetime = () => {
|
|
360
|
-
};
|
|
397
|
+
const active = new Set;
|
|
398
|
+
let unbindLifetime = () => {};
|
|
361
399
|
const close = () => {
|
|
362
|
-
if (closed)
|
|
400
|
+
if (closed)
|
|
401
|
+
return;
|
|
363
402
|
closed = true;
|
|
364
403
|
liveApprovalHosts.delete(connection);
|
|
365
404
|
bridge.revoke();
|
|
366
|
-
for (const controller of active)
|
|
405
|
+
for (const controller of active)
|
|
406
|
+
controller.abort();
|
|
367
407
|
active.clear();
|
|
368
408
|
try {
|
|
369
409
|
send(channel, { type: "revoke" });
|
|
370
|
-
} catch {
|
|
371
|
-
}
|
|
410
|
+
} catch {}
|
|
372
411
|
channel.removeListener("message", receive);
|
|
373
412
|
unbindLifetime();
|
|
374
413
|
};
|
|
375
414
|
const receive = (message) => {
|
|
376
|
-
if (closed || message?.kind !== KIND2)
|
|
415
|
+
if (closed || message?.kind !== KIND2)
|
|
416
|
+
return;
|
|
377
417
|
if (message.type === "hello") {
|
|
378
418
|
try {
|
|
379
419
|
send(channel, { type: "binding", binding });
|
|
@@ -382,24 +422,27 @@ function attachShellApprovalHost(channel, host) {
|
|
|
382
422
|
}
|
|
383
423
|
return;
|
|
384
424
|
}
|
|
385
|
-
if (message.type !== "request")
|
|
425
|
+
if (message.type !== "request")
|
|
426
|
+
return;
|
|
386
427
|
if (++count > MAX2 || typeof message.id !== "string" || message.id.length > 100) {
|
|
387
428
|
close();
|
|
388
429
|
return;
|
|
389
430
|
}
|
|
390
431
|
const id = message.id;
|
|
391
|
-
|
|
432
|
+
(async () => {
|
|
392
433
|
let controller;
|
|
393
434
|
let timer;
|
|
394
435
|
try {
|
|
395
|
-
if (message.runId !== binding.runId)
|
|
436
|
+
if (message.runId !== binding.runId)
|
|
437
|
+
throw new Error("Wrong run");
|
|
396
438
|
const call = payloadCall(message.payload, binding);
|
|
397
439
|
const pending = bridge.request(call);
|
|
398
|
-
if (!pending.ok)
|
|
399
|
-
|
|
440
|
+
if (!pending.ok)
|
|
441
|
+
throw new Error("Request refused");
|
|
442
|
+
controller = new AbortController;
|
|
400
443
|
active.add(controller);
|
|
401
|
-
const cancelled = new Promise((
|
|
402
|
-
controller.signal.addEventListener("abort", () =>
|
|
444
|
+
const cancelled = new Promise((resolve) => {
|
|
445
|
+
controller.signal.addEventListener("abort", () => resolve(false), { once: true });
|
|
403
446
|
});
|
|
404
447
|
timer = setTimeout(() => controller.abort(), Math.max(0, pending.request.expiresAt - Date.now()));
|
|
405
448
|
const approved = await Promise.race([
|
|
@@ -412,10 +455,12 @@ function attachShellApprovalHost(channel, host) {
|
|
|
412
455
|
}, controller.signal),
|
|
413
456
|
cancelled
|
|
414
457
|
]);
|
|
415
|
-
if (closed || controller.signal.aborted || approved !== true)
|
|
458
|
+
if (closed || controller.signal.aborted || approved !== true)
|
|
459
|
+
throw new Error("Not approved");
|
|
416
460
|
const decided = bridge.decide(pending.request.requestId, call, "approve");
|
|
417
461
|
const consumed = decided.ok && bridge.consume(pending.request.requestId, call);
|
|
418
|
-
if (!consumed || !consumed.ok)
|
|
462
|
+
if (!consumed || !consumed.ok)
|
|
463
|
+
throw new Error("Approval expired");
|
|
419
464
|
send(channel, {
|
|
420
465
|
type: "decision",
|
|
421
466
|
id,
|
|
@@ -426,12 +471,14 @@ function attachShellApprovalHost(channel, host) {
|
|
|
426
471
|
});
|
|
427
472
|
} catch {
|
|
428
473
|
try {
|
|
429
|
-
if (!closed)
|
|
474
|
+
if (!closed)
|
|
475
|
+
send(channel, { type: "decision", id, runId: binding.runId, approved: false });
|
|
430
476
|
} catch {
|
|
431
477
|
close();
|
|
432
478
|
}
|
|
433
479
|
} finally {
|
|
434
|
-
if (timer)
|
|
480
|
+
if (timer)
|
|
481
|
+
clearTimeout(timer);
|
|
435
482
|
if (controller) {
|
|
436
483
|
controller.abort();
|
|
437
484
|
active.delete(controller);
|
|
@@ -442,17 +489,19 @@ function attachShellApprovalHost(channel, host) {
|
|
|
442
489
|
channel.on("message", receive);
|
|
443
490
|
unbindLifetime = bindInheritedApprovalLifetime(channel, close, host.signal);
|
|
444
491
|
liveApprovalHosts.add(connection);
|
|
445
|
-
if (host.signal.aborted || channel.connected === false)
|
|
492
|
+
if (host.signal.aborted || channel.connected === false)
|
|
493
|
+
close();
|
|
446
494
|
return close;
|
|
447
495
|
}
|
|
448
496
|
function createShellApprovalChild(channel, timeoutMs = TTL2) {
|
|
449
497
|
let closed = false;
|
|
450
498
|
let binding;
|
|
451
499
|
let count = 0;
|
|
452
|
-
const pending =
|
|
453
|
-
const tickets =
|
|
500
|
+
const pending = new Map;
|
|
501
|
+
const tickets = new Map;
|
|
454
502
|
const close = () => {
|
|
455
|
-
if (closed)
|
|
503
|
+
if (closed)
|
|
504
|
+
return;
|
|
456
505
|
closed = true;
|
|
457
506
|
tickets.clear();
|
|
458
507
|
for (const entry of pending.values()) {
|
|
@@ -464,7 +513,8 @@ function createShellApprovalChild(channel, timeoutMs = TTL2) {
|
|
|
464
513
|
channel.removeListener("disconnect", close);
|
|
465
514
|
};
|
|
466
515
|
const receive = (message) => {
|
|
467
|
-
if (closed || message?.kind !== KIND2)
|
|
516
|
+
if (closed || message?.kind !== KIND2)
|
|
517
|
+
return;
|
|
468
518
|
if (message.type === "revoke") {
|
|
469
519
|
close();
|
|
470
520
|
return;
|
|
@@ -477,9 +527,11 @@ function createShellApprovalChild(channel, timeoutMs = TTL2) {
|
|
|
477
527
|
binding = Object.freeze({ ...message.binding });
|
|
478
528
|
return;
|
|
479
529
|
}
|
|
480
|
-
if (message.type !== "decision")
|
|
530
|
+
if (message.type !== "decision")
|
|
531
|
+
return;
|
|
481
532
|
const entry = pending.get(message.id);
|
|
482
|
-
if (!entry)
|
|
533
|
+
if (!entry)
|
|
534
|
+
return;
|
|
483
535
|
pending.delete(message.id);
|
|
484
536
|
clearTimeout(entry.timer);
|
|
485
537
|
if (!binding || message.runId !== binding.runId || message.approved !== true || typeof message.ticket !== "string" || !Number.isFinite(message.expiresAt) || message.expiresAt <= Date.now() || message.expiresAt > Date.now() + TTL2 || tickets.has(message.ticket)) {
|
|
@@ -500,18 +552,21 @@ function createShellApprovalChild(channel, timeoutMs = TTL2) {
|
|
|
500
552
|
close,
|
|
501
553
|
authority: {
|
|
502
554
|
async request(payload) {
|
|
503
|
-
if (++count > MAX2)
|
|
555
|
+
if (++count > MAX2)
|
|
556
|
+
throw new Error("Shell approval capacity exceeded");
|
|
504
557
|
const deadline = Date.now() + Math.min(timeoutMs, TTL2);
|
|
505
|
-
while (!binding && !closed && Date.now() < deadline)
|
|
506
|
-
|
|
558
|
+
while (!binding && !closed && Date.now() < deadline)
|
|
559
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
560
|
+
if (closed || !binding)
|
|
561
|
+
throw new Error("Shell approval unavailable");
|
|
507
562
|
payloadCall(payload, binding);
|
|
508
563
|
const id = randomUUID2();
|
|
509
|
-
return new Promise((
|
|
564
|
+
return new Promise((resolve, reject) => {
|
|
510
565
|
const timer = setTimeout(() => {
|
|
511
566
|
pending.delete(id);
|
|
512
567
|
reject(new Error("Shell approval timeout"));
|
|
513
568
|
}, Math.min(timeoutMs, TTL2));
|
|
514
|
-
pending.set(id, { payload, resolve
|
|
569
|
+
pending.set(id, { payload, resolve, reject, timer });
|
|
515
570
|
try {
|
|
516
571
|
send(channel, { type: "request", id, runId: binding.runId, payload });
|
|
517
572
|
} catch {
|
|
@@ -539,23 +594,24 @@ function stripFrontmatter(markdown) {
|
|
|
539
594
|
}
|
|
540
595
|
function parseStructuredReview(text) {
|
|
541
596
|
const body = stripFrontmatter(text).trim();
|
|
542
|
-
if (!body.startsWith("{"))
|
|
597
|
+
if (!body.startsWith("{"))
|
|
598
|
+
return { kind: "legacy" };
|
|
543
599
|
const nonempty = (v) => typeof v === "string" && v.trim().length > 0;
|
|
544
600
|
try {
|
|
545
601
|
const value = JSON.parse(body);
|
|
546
602
|
const keys = ["schemaVersion", "revision", "status", "reason", "findings"];
|
|
547
|
-
if (!value || value.schemaVersion !== 1 || Object.keys(value).some((k) => !keys.includes(k)) || !["completed", "incomplete"].includes(value.status) || !nonempty(value.revision) || !Array.isArray(value.findings) || value.reason !==
|
|
548
|
-
return { kind: "invalid", reason: "
|
|
549
|
-
const ids =
|
|
603
|
+
if (!value || value.schemaVersion !== 1 || Object.keys(value).some((k) => !keys.includes(k)) || !["completed", "incomplete"].includes(value.status) || !nonempty(value.revision) || !Array.isArray(value.findings) || value.reason !== undefined && (value.status !== "incomplete" || !nonempty(value.reason)) || value.status === "incomplete" && !nonempty(value.reason))
|
|
604
|
+
return { kind: "invalid", reason: "结构化审查字段无效或未完成原因缺失" };
|
|
605
|
+
const ids = new Set;
|
|
550
606
|
const findingKeys = ["id", "severity", "file", "line", "evidence", "impact"];
|
|
551
607
|
for (const f of value.findings) {
|
|
552
608
|
if (!f || Object.keys(f).some((k) => !findingKeys.includes(k)) || !nonempty(f.id) || ids.has(f.id.trim()) || !SEVERITIES.includes(f.severity) || !nonempty(f.file) || !Number.isSafeInteger(f.line) || f.line < 1 || !nonempty(f.evidence) || !nonempty(f.impact))
|
|
553
|
-
return { kind: "invalid", reason: "
|
|
609
|
+
return { kind: "invalid", reason: "结构化 finding 无效或 id 重复" };
|
|
554
610
|
ids.add(f.id.trim());
|
|
555
611
|
}
|
|
556
612
|
return { kind: "structured", review: value };
|
|
557
613
|
} catch {
|
|
558
|
-
return { kind: "invalid", reason: "
|
|
614
|
+
return { kind: "invalid", reason: "结构化审查 JSON 无效" };
|
|
559
615
|
}
|
|
560
616
|
}
|
|
561
617
|
function structuredReviewVerdict(review) {
|
|
@@ -570,20 +626,14 @@ var REDACTED_COMMAND = "[REDACTED_COMMAND]";
|
|
|
570
626
|
var REDACTED_ARGS = "[REDACTED_ARGS]";
|
|
571
627
|
var REDACTED_PATH = "[REDACTED_PATH]";
|
|
572
628
|
var SECRET_RULES = [
|
|
573
|
-
// Authorization: Bearer <token>
|
|
574
629
|
{
|
|
575
630
|
re: /\bBearer\s+[A-Za-z0-9_\-.\~+/=]{8,}/gi,
|
|
576
631
|
replacement: `Bearer ${REDACTED_TOKEN}`
|
|
577
632
|
},
|
|
578
|
-
// GitHub 家族前缀 token(ghp_/gho_/ghu_/ghs_/ghr_)
|
|
579
633
|
{
|
|
580
634
|
re: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{20,}\b/g,
|
|
581
635
|
replacement: REDACTED_TOKEN
|
|
582
636
|
},
|
|
583
|
-
// key=value / key: value。key 名自带凭据关键词才脱敏,避免把普通日志打花。
|
|
584
|
-
// key 字符类含 `-`/`_`,故 `NOLO_WORKER_TOKEN=`(env 前缀)、
|
|
585
|
-
// `x-nolo-machine-lease:`、`x-worker-token:` 都在命中面内。
|
|
586
|
-
// 同时支持带闭合双/单引号的 JSON 键,如 {"apiKey":"..."} 或 {"token": "..."}。
|
|
587
637
|
{
|
|
588
638
|
re: /(["']?)\b([A-Za-z0-9_-]*(?:token|secret|password|passwd|credential|api[_-]?key|machine[_-]lease|workspace[_-]lease)[A-Za-z0-9_-]*)\1(\s*[:=]\s*)(["']?)[^\s"',;}{]{4,}\4/gi,
|
|
589
639
|
replacement: `$1$2$1$3$4${REDACTED_CREDENTIAL}$4`
|
|
@@ -598,12 +648,10 @@ var PATH_RULES = [
|
|
|
598
648
|
re: /(^|[\s"'`(=:])[A-Za-z]:\\[^\s"'`),;:]+/g,
|
|
599
649
|
replacement: `$1${REDACTED_PATH}`
|
|
600
650
|
},
|
|
601
|
-
// `~/.nolo` / `/home/x/.nolo`(凭据与机器身份落点)
|
|
602
651
|
{
|
|
603
652
|
re: /~?\/\.nolo(\/[^\s"'`),;:]*)?/g,
|
|
604
653
|
replacement: REDACTED_PATH
|
|
605
654
|
},
|
|
606
|
-
// process.execPath / bunPath / BUN_PATH
|
|
607
655
|
{
|
|
608
656
|
re: /\b((?:process\.execPath|bunPath|execPath|BUN_PATH)\s*[:=]\s*)(["']?)[^\s"']+\2/gi,
|
|
609
657
|
replacement: `$1$2${REDACTED_PATH}$2`
|
|
@@ -620,9 +668,11 @@ function redactStageStartJson(line) {
|
|
|
620
668
|
} catch {
|
|
621
669
|
return { line, hit: false };
|
|
622
670
|
}
|
|
623
|
-
if (!isRecord(parsed))
|
|
671
|
+
if (!isRecord(parsed))
|
|
672
|
+
return { line, hit: false };
|
|
624
673
|
const isStageStart = parsed.type === "stage-start" || parsed.event === "stage_start" || parsed.phase === "stage_start" || "command" in parsed && "args" in parsed;
|
|
625
|
-
if (!isStageStart)
|
|
674
|
+
if (!isStageStart)
|
|
675
|
+
return { line, hit: false };
|
|
626
676
|
let hits = 0;
|
|
627
677
|
if ("command" in parsed) {
|
|
628
678
|
parsed.command = REDACTED_COMMAND;
|
|
@@ -632,7 +682,8 @@ function redactStageStartJson(line) {
|
|
|
632
682
|
parsed.args = [REDACTED_ARGS];
|
|
633
683
|
hits += 1;
|
|
634
684
|
}
|
|
635
|
-
if (hits === 0)
|
|
685
|
+
if (hits === 0)
|
|
686
|
+
return { line, hit: false };
|
|
636
687
|
return { line: JSON.stringify(parsed), hit: true };
|
|
637
688
|
}
|
|
638
689
|
function applyRules(line, rules) {
|
|
@@ -640,7 +691,8 @@ function applyRules(line, rules) {
|
|
|
640
691
|
let hit = false;
|
|
641
692
|
for (const rule of rules) {
|
|
642
693
|
rule.re.lastIndex = 0;
|
|
643
|
-
if (!rule.re.test(out))
|
|
694
|
+
if (!rule.re.test(out))
|
|
695
|
+
continue;
|
|
644
696
|
rule.re.lastIndex = 0;
|
|
645
697
|
out = out.replace(rule.re, rule.replacement);
|
|
646
698
|
hit = true;
|
|
@@ -648,7 +700,8 @@ function applyRules(line, rules) {
|
|
|
648
700
|
return { line: out, hit };
|
|
649
701
|
}
|
|
650
702
|
function redactLogLine(rawLine) {
|
|
651
|
-
if (typeof rawLine !== "string")
|
|
703
|
+
if (typeof rawLine !== "string")
|
|
704
|
+
return { line: "", hit: false };
|
|
652
705
|
const jsonCheck = redactStageStartJson(rawLine);
|
|
653
706
|
let line = jsonCheck.hit ? jsonCheck.line : rawLine;
|
|
654
707
|
let hit = jsonCheck.hit;
|
|
@@ -662,14 +715,15 @@ function redactLogLine(rawLine) {
|
|
|
662
715
|
}
|
|
663
716
|
function redactLogLines(lines, options = {}) {
|
|
664
717
|
const input = Array.isArray(lines) ? lines : [];
|
|
665
|
-
const requested = options.tailLines !==
|
|
718
|
+
const requested = options.tailLines !== undefined && Number.isFinite(options.tailLines) && options.tailLines > 0 ? Math.floor(options.tailLines) : TAIL_LINES_MAX;
|
|
666
719
|
const clampedTail = Math.min(Math.max(1, requested), TAIL_LINES_MAX);
|
|
667
720
|
const truncated = input.length > clampedTail;
|
|
668
721
|
const sliced = input.slice(-clampedTail);
|
|
669
722
|
let redactedCount = 0;
|
|
670
723
|
const redactedLines = sliced.map((raw) => {
|
|
671
724
|
const { line, hit } = redactLogLine(typeof raw === "string" ? raw : String(raw));
|
|
672
|
-
if (hit)
|
|
725
|
+
if (hit)
|
|
726
|
+
redactedCount += 1;
|
|
673
727
|
return line;
|
|
674
728
|
});
|
|
675
729
|
return {
|
|
@@ -698,7 +752,7 @@ var PROC_SELF_CGROUP_PATH = "/proc/self/cgroup";
|
|
|
698
752
|
var SANDBOX_CGROUP_PATTERN = /(docker|kubepods|instabox|containerd)/;
|
|
699
753
|
var MEMORY_AVAILABLE_RATIO_THRESHOLD = 0.15;
|
|
700
754
|
var SWAP_USED_RATIO_THRESHOLD = 0.7;
|
|
701
|
-
var HOST_MEMORY_PRESSURE_HINT = "
|
|
755
|
+
var HOST_MEMORY_PRESSURE_HINT = "⚠ 内存偏紧,建议重活放沙盒/远端或减少并发";
|
|
702
756
|
var BYTES_PER_MB = 1024 * 1024;
|
|
703
757
|
function toMbFromBytes(bytes) {
|
|
704
758
|
return Math.round(bytes / BYTES_PER_MB);
|
|
@@ -725,16 +779,20 @@ function tryExists(deps, path) {
|
|
|
725
779
|
}
|
|
726
780
|
function readKbValue(text, key) {
|
|
727
781
|
const match = new RegExp(`^${key}:\\s*(\\d+)`, "m").exec(text);
|
|
728
|
-
if (!match)
|
|
782
|
+
if (!match)
|
|
783
|
+
return null;
|
|
729
784
|
const value = Number.parseInt(match[1], 10);
|
|
730
785
|
return Number.isFinite(value) ? value : null;
|
|
731
786
|
}
|
|
732
787
|
function parseProcMeminfo(text) {
|
|
733
|
-
if (typeof text !== "string" || text.length === 0)
|
|
788
|
+
if (typeof text !== "string" || text.length === 0)
|
|
789
|
+
return null;
|
|
734
790
|
const totalKb = readKbValue(text, "MemTotal");
|
|
735
791
|
const availableKb = readKbValue(text, "MemAvailable");
|
|
736
|
-
if (totalKb === null || availableKb === null)
|
|
737
|
-
|
|
792
|
+
if (totalKb === null || availableKb === null)
|
|
793
|
+
return null;
|
|
794
|
+
if (!(totalKb > 0))
|
|
795
|
+
return null;
|
|
738
796
|
const swapTotalKb = readKbValue(text, "SwapTotal") ?? 0;
|
|
739
797
|
const swapFreeKb = readKbValue(text, "SwapFree") ?? 0;
|
|
740
798
|
return {
|
|
@@ -748,9 +806,11 @@ function parseProcMeminfo(text) {
|
|
|
748
806
|
}
|
|
749
807
|
function detectSandbox(deps = {}) {
|
|
750
808
|
const platform = deps.platform ?? process.platform;
|
|
751
|
-
if (platform !== "linux")
|
|
809
|
+
if (platform !== "linux")
|
|
810
|
+
return false;
|
|
752
811
|
for (const marker of SANDBOX_MARKER_PATHS) {
|
|
753
|
-
if (tryExists(deps, marker))
|
|
812
|
+
if (tryExists(deps, marker))
|
|
813
|
+
return true;
|
|
754
814
|
}
|
|
755
815
|
const selfCgroup = tryReadText(deps, PROC_SELF_CGROUP_PATH);
|
|
756
816
|
return selfCgroup !== null && SANDBOX_CGROUP_PATTERN.test(selfCgroup);
|
|
@@ -760,12 +820,12 @@ function readOsView(deps) {
|
|
|
760
820
|
try {
|
|
761
821
|
const totalMb = toMbFromBytes(os.totalmem());
|
|
762
822
|
const availableMb = toMbFromBytes(os.freemem());
|
|
763
|
-
if (!(totalMb > 0) || !Number.isFinite(availableMb))
|
|
823
|
+
if (!(totalMb > 0) || !Number.isFinite(availableMb))
|
|
824
|
+
return null;
|
|
764
825
|
return {
|
|
765
826
|
source: "os",
|
|
766
827
|
totalMb,
|
|
767
828
|
availableMb: Math.max(0, availableMb),
|
|
768
|
-
// os 没有可移植的 swap 口径:按契约显示 n/a,而不是编一个数字。
|
|
769
829
|
swapTotalMb: null,
|
|
770
830
|
swapUsedMb: null,
|
|
771
831
|
hostAvailableMb: null
|
|
@@ -780,30 +840,39 @@ function readHostView(deps) {
|
|
|
780
840
|
const text = tryReadText(deps, PROC_MEMINFO_PATH);
|
|
781
841
|
if (text !== null) {
|
|
782
842
|
const parsed = parseProcMeminfo(text);
|
|
783
|
-
if (parsed)
|
|
843
|
+
if (parsed)
|
|
844
|
+
return parsed;
|
|
784
845
|
}
|
|
785
846
|
}
|
|
786
847
|
return readOsView(deps);
|
|
787
848
|
}
|
|
788
849
|
function parseCgroup2RelativePath(text) {
|
|
789
|
-
for (const line of text.split(
|
|
850
|
+
for (const line of text.split(`
|
|
851
|
+
`)) {
|
|
790
852
|
const trimmed = line.trim();
|
|
791
|
-
if (!trimmed)
|
|
853
|
+
if (!trimmed)
|
|
854
|
+
continue;
|
|
792
855
|
const parts = trimmed.split(":");
|
|
793
|
-
if (parts.length < 3 || parts[0] !== "0" || parts[1] !== "")
|
|
856
|
+
if (parts.length < 3 || parts[0] !== "0" || parts[1] !== "")
|
|
857
|
+
continue;
|
|
794
858
|
const path = parts.slice(2).join(":").trim();
|
|
795
|
-
if (!path)
|
|
859
|
+
if (!path)
|
|
860
|
+
continue;
|
|
796
861
|
return path.startsWith("/") ? path : `/${path}`;
|
|
797
862
|
}
|
|
798
863
|
return null;
|
|
799
864
|
}
|
|
800
865
|
function parseCgroup2MountPoint(mountsText) {
|
|
801
|
-
for (const line of mountsText.split(
|
|
866
|
+
for (const line of mountsText.split(`
|
|
867
|
+
`)) {
|
|
802
868
|
const fields = line.trim().split(/\s+/);
|
|
803
|
-
if (fields.length < 3)
|
|
804
|
-
|
|
869
|
+
if (fields.length < 3)
|
|
870
|
+
continue;
|
|
871
|
+
if (fields[2] !== "cgroup2")
|
|
872
|
+
continue;
|
|
805
873
|
const mountPoint = fields[1].replace(/\\040/g, " ");
|
|
806
|
-
if (mountPoint.startsWith("/"))
|
|
874
|
+
if (mountPoint.startsWith("/"))
|
|
875
|
+
return mountPoint;
|
|
807
876
|
}
|
|
808
877
|
return null;
|
|
809
878
|
}
|
|
@@ -813,7 +882,7 @@ function cgroupAncestorDirs(mountPoint, relativePath) {
|
|
|
813
882
|
if (relativePath && relativePath !== "/") {
|
|
814
883
|
const rel = relativePath.startsWith("/") ? relativePath : `/${relativePath}`;
|
|
815
884
|
const segments = rel.split("/").filter(Boolean);
|
|
816
|
-
for (let depth = segments.length;
|
|
885
|
+
for (let depth = segments.length;depth >= 1; depth -= 1) {
|
|
817
886
|
dirs.push(`${base}/${segments.slice(0, depth).join("/")}`);
|
|
818
887
|
}
|
|
819
888
|
}
|
|
@@ -822,11 +891,14 @@ function cgroupAncestorDirs(mountPoint, relativePath) {
|
|
|
822
891
|
}
|
|
823
892
|
function readCgroupMaxMb(deps, dir) {
|
|
824
893
|
const maxText = tryReadText(deps, `${dir}/memory.max`);
|
|
825
|
-
if (maxText === null)
|
|
894
|
+
if (maxText === null)
|
|
895
|
+
return null;
|
|
826
896
|
const maxRaw = maxText.trim();
|
|
827
|
-
if (maxRaw === "" || maxRaw === "max")
|
|
897
|
+
if (maxRaw === "" || maxRaw === "max")
|
|
898
|
+
return null;
|
|
828
899
|
const maxBytes = Number.parseInt(maxRaw, 10);
|
|
829
|
-
if (!Number.isFinite(maxBytes) || maxBytes <= 0)
|
|
900
|
+
if (!Number.isFinite(maxBytes) || maxBytes <= 0)
|
|
901
|
+
return null;
|
|
830
902
|
const totalMb = toMbFromBytes(maxBytes);
|
|
831
903
|
return totalMb > 0 ? totalMb : null;
|
|
832
904
|
}
|
|
@@ -843,7 +915,6 @@ function buildCgroupSnapshot(deps, dir, totalMb, hostView) {
|
|
|
843
915
|
source: "cgroup",
|
|
844
916
|
totalMb,
|
|
845
917
|
availableMb: usedMb === null ? null : Math.max(0, totalMb - usedMb),
|
|
846
|
-
// swap 不是 cgroup 配额的一部分,只能借宿主视角(Linux 上就是 /proc/meminfo)。
|
|
847
918
|
swapTotalMb: hostView?.swapTotalMb ?? null,
|
|
848
919
|
swapUsedMb: hostView?.swapUsedMb ?? null,
|
|
849
920
|
hostAvailableMb: hostView?.availableMb ?? null
|
|
@@ -858,13 +929,15 @@ function readCgroupLimitView(deps, hostView) {
|
|
|
858
929
|
let limitingMb = Number.POSITIVE_INFINITY;
|
|
859
930
|
for (const dir of cgroupAncestorDirs(mountPoint, relativePath)) {
|
|
860
931
|
const totalMb = readCgroupMaxMb(deps, dir);
|
|
861
|
-
if (totalMb === null)
|
|
932
|
+
if (totalMb === null)
|
|
933
|
+
continue;
|
|
862
934
|
if (totalMb < limitingMb) {
|
|
863
935
|
limitingMb = totalMb;
|
|
864
936
|
limitingDir = dir;
|
|
865
937
|
}
|
|
866
938
|
}
|
|
867
|
-
if (limitingDir === null)
|
|
939
|
+
if (limitingDir === null)
|
|
940
|
+
return null;
|
|
868
941
|
return buildCgroupSnapshot(deps, limitingDir, limitingMb, hostView);
|
|
869
942
|
}
|
|
870
943
|
function readHostMemory(deps = {}) {
|
|
@@ -874,14 +947,16 @@ function readHostMemory(deps = {}) {
|
|
|
874
947
|
}
|
|
875
948
|
const hostView = readHostView(deps);
|
|
876
949
|
const cgroupView = readCgroupLimitView(deps, hostView);
|
|
877
|
-
if (!cgroupView)
|
|
950
|
+
if (!cgroupView)
|
|
951
|
+
return hostView;
|
|
878
952
|
return {
|
|
879
953
|
...cgroupView,
|
|
880
954
|
scope: detectSandbox(deps) ? "sandbox" : "cgroup-limit"
|
|
881
955
|
};
|
|
882
956
|
}
|
|
883
957
|
function isHostMemoryTight(mem) {
|
|
884
|
-
if (!(mem.totalMb > 0))
|
|
958
|
+
if (!(mem.totalMb > 0))
|
|
959
|
+
return false;
|
|
885
960
|
if (mem.availableMb !== null && mem.availableMb / mem.totalMb < MEMORY_AVAILABLE_RATIO_THRESHOLD) {
|
|
886
961
|
return true;
|
|
887
962
|
}
|
|
@@ -892,11 +967,13 @@ function isHostMemoryTight(mem) {
|
|
|
892
967
|
}
|
|
893
968
|
function formatHostMemoryMb(mb) {
|
|
894
969
|
const value = Math.max(0, Math.round(Number.isFinite(mb) ? mb : 0));
|
|
895
|
-
if (value >= 1024)
|
|
970
|
+
if (value >= 1024)
|
|
971
|
+
return `${(value / 1024).toFixed(1)}G`;
|
|
896
972
|
return `${value}M`;
|
|
897
973
|
}
|
|
898
974
|
function formatSwapPart(mem) {
|
|
899
|
-
if (mem.swapTotalMb === null || mem.swapUsedMb === null)
|
|
975
|
+
if (mem.swapTotalMb === null || mem.swapUsedMb === null)
|
|
976
|
+
return "swap n/a";
|
|
900
977
|
return `swap ${formatHostMemoryMb(mem.swapUsedMb)}/${formatHostMemoryMb(mem.swapTotalMb)}`;
|
|
901
978
|
}
|
|
902
979
|
function formatHostMemoryLine(mem) {
|
|
@@ -904,14 +981,14 @@ function formatHostMemoryLine(mem) {
|
|
|
904
981
|
let line;
|
|
905
982
|
if (mem.source === "cgroup") {
|
|
906
983
|
const hostAvailable = mem.hostAvailableMb === null ? "n/a" : formatHostMemoryMb(mem.hostAvailableMb);
|
|
907
|
-
const prefix = (mem.scope ?? "sandbox") === "cgroup-limit" ? "[
|
|
908
|
-
const usage = usedMb === null ? "
|
|
909
|
-
line = `${prefix} ${usage}/${formatHostMemoryMb(mem.totalMb)}
|
|
984
|
+
const prefix = (mem.scope ?? "sandbox") === "cgroup-limit" ? "[限额] 本进程内存" : "[sandbox] 容器内存";
|
|
985
|
+
const usage = usedMb === null ? "占用未知" : formatHostMemoryMb(usedMb);
|
|
986
|
+
line = `${prefix} ${usage}/${formatHostMemoryMb(mem.totalMb)}` + ` · 宿主可用 ${hostAvailable}`;
|
|
910
987
|
} else {
|
|
911
988
|
const available = mem.availableMb === null ? "n/a" : formatHostMemoryMb(mem.availableMb);
|
|
912
|
-
line =
|
|
989
|
+
line = `本地内存 ${formatHostMemoryMb(usedMb ?? 0)}/${formatHostMemoryMb(mem.totalMb)}` + `(可用 ${available})· ${formatSwapPart(mem)}`;
|
|
913
990
|
}
|
|
914
|
-
return isHostMemoryTight(mem) ? `${line}
|
|
991
|
+
return isHostMemoryTight(mem) ? `${line} · ${HOST_MEMORY_PRESSURE_HINT}` : line;
|
|
915
992
|
}
|
|
916
993
|
|
|
917
994
|
// packages/cli/client/hostMemoryReservation.ts
|
|
@@ -922,7 +999,8 @@ import * as nodeFs from "fs";
|
|
|
922
999
|
var LOCAL_AGENT_RUN_MIN_AVAILABLE_MB = 512;
|
|
923
1000
|
var STARTUP_WINDOW_MS = 1e4;
|
|
924
1001
|
var STARTUP_WINDOW_RESERVED_MB_PER_RUN = 384;
|
|
925
|
-
|
|
1002
|
+
|
|
1003
|
+
class HostMemoryAdmissionError extends Error {
|
|
926
1004
|
code = "HOST_MEMORY_ADMISSION_DENIED";
|
|
927
1005
|
details;
|
|
928
1006
|
constructor(message, details) {
|
|
@@ -930,56 +1008,52 @@ var HostMemoryAdmissionError = class extends Error {
|
|
|
930
1008
|
this.name = "HostMemoryAdmissionError";
|
|
931
1009
|
this.details = details;
|
|
932
1010
|
}
|
|
933
|
-
}
|
|
1011
|
+
}
|
|
934
1012
|
function assertHostMemoryAdmission(deps = {}) {
|
|
935
1013
|
const readMem = deps.readHostMemory ?? readHostMemory;
|
|
936
|
-
const
|
|
1014
|
+
const snapshot = readMem(deps.hostMemoryDeps);
|
|
937
1015
|
const minAvailableMb = deps.minAvailableMb ?? LOCAL_AGENT_RUN_MIN_AVAILABLE_MB;
|
|
938
1016
|
const startupWindowMs = deps.startupWindowMs ?? STARTUP_WINDOW_MS;
|
|
939
1017
|
const reservedMbPerRun = deps.reservedMbPerRun ?? STARTUP_WINDOW_RESERVED_MB_PER_RUN;
|
|
940
1018
|
const now = deps.now ? deps.now().getTime() : Date.now();
|
|
941
1019
|
for (const [name, value] of Object.entries({ minAvailableMb, startupWindowMs, reservedMbPerRun, now })) {
|
|
942
|
-
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
1020
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
1021
|
+
throw new Error(`Invalid ${name}`);
|
|
1022
|
+
}
|
|
1023
|
+
if (!snapshot) {
|
|
1024
|
+
throw new HostMemoryAdmissionError(`[host-memory-admission] 无法测定本机可用内存(快照为 null),拒绝本地 fork。` + `需确保 /proc/meminfo 或 OS 内存指标可读。`, {
|
|
1025
|
+
effectiveAvailableMb: null,
|
|
1026
|
+
requiredMinMb: minAvailableMb,
|
|
1027
|
+
source: "null",
|
|
1028
|
+
limitingSource: "unknown",
|
|
1029
|
+
activeStartupRuns: 0,
|
|
1030
|
+
reservedStartupMb: 0,
|
|
1031
|
+
unreservedAvailableMb: null
|
|
1032
|
+
});
|
|
943
1033
|
}
|
|
944
|
-
if (!
|
|
945
|
-
throw new
|
|
946
|
-
|
|
947
|
-
|
|
1034
|
+
if (!["cgroup", "proc-meminfo", "os"].includes(snapshot.source))
|
|
1035
|
+
throw new Error("Unknown host memory source");
|
|
1036
|
+
let effectiveAvailableMb = null;
|
|
1037
|
+
let limitingSource = "host";
|
|
1038
|
+
if (snapshot.source === "cgroup") {
|
|
1039
|
+
const cgroupAvail = snapshot.availableMb;
|
|
1040
|
+
const hostAvail = snapshot.hostAvailableMb;
|
|
1041
|
+
if (cgroupAvail === null || typeof cgroupAvail !== "number" || Number.isNaN(cgroupAvail) || !Number.isFinite(cgroupAvail) || cgroupAvail < 0) {
|
|
1042
|
+
throw new HostMemoryAdmissionError(`[host-memory-admission] cgroup 配额内存占用未知或无效,拒绝无声当充足。`, {
|
|
948
1043
|
effectiveAvailableMb: null,
|
|
949
1044
|
requiredMinMb: minAvailableMb,
|
|
950
|
-
source:
|
|
951
|
-
limitingSource: "
|
|
1045
|
+
source: snapshot.source,
|
|
1046
|
+
limitingSource: "cgroup",
|
|
952
1047
|
activeStartupRuns: 0,
|
|
953
1048
|
reservedStartupMb: 0,
|
|
954
1049
|
unreservedAvailableMb: null
|
|
955
|
-
}
|
|
956
|
-
);
|
|
957
|
-
}
|
|
958
|
-
if (!["cgroup", "proc-meminfo", "os"].includes(snapshot2.source)) throw new Error("Unknown host memory source");
|
|
959
|
-
let effectiveAvailableMb = null;
|
|
960
|
-
let limitingSource = "host";
|
|
961
|
-
if (snapshot2.source === "cgroup") {
|
|
962
|
-
const cgroupAvail = snapshot2.availableMb;
|
|
963
|
-
const hostAvail = snapshot2.hostAvailableMb;
|
|
964
|
-
if (cgroupAvail === null || typeof cgroupAvail !== "number" || Number.isNaN(cgroupAvail) || !Number.isFinite(cgroupAvail) || cgroupAvail < 0) {
|
|
965
|
-
throw new HostMemoryAdmissionError(
|
|
966
|
-
`[host-memory-admission] cgroup \u914D\u989D\u5185\u5B58\u5360\u7528\u672A\u77E5\u6216\u65E0\u6548\uFF0C\u62D2\u7EDD\u65E0\u58F0\u5F53\u5145\u8DB3\u3002`,
|
|
967
|
-
{
|
|
968
|
-
effectiveAvailableMb: null,
|
|
969
|
-
requiredMinMb: minAvailableMb,
|
|
970
|
-
source: snapshot2.source,
|
|
971
|
-
limitingSource: "cgroup",
|
|
972
|
-
activeStartupRuns: 0,
|
|
973
|
-
reservedStartupMb: 0,
|
|
974
|
-
unreservedAvailableMb: null
|
|
975
|
-
}
|
|
976
|
-
);
|
|
1050
|
+
});
|
|
977
1051
|
}
|
|
978
1052
|
if (typeof hostAvail !== "number" || !Number.isFinite(hostAvail) || hostAvail < 0) {
|
|
979
|
-
throw new HostMemoryAdmissionError("[host-memory-admission]
|
|
1053
|
+
throw new HostMemoryAdmissionError("[host-memory-admission] 宿主可用内存未知或无效,拒绝本地 fork。", {
|
|
980
1054
|
effectiveAvailableMb: null,
|
|
981
1055
|
requiredMinMb: minAvailableMb,
|
|
982
|
-
source:
|
|
1056
|
+
source: snapshot.source,
|
|
983
1057
|
limitingSource: "host",
|
|
984
1058
|
activeStartupRuns: 0,
|
|
985
1059
|
reservedStartupMb: 0,
|
|
@@ -999,70 +1073,59 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
999
1073
|
limitingSource = "cgroup";
|
|
1000
1074
|
}
|
|
1001
1075
|
} else {
|
|
1002
|
-
if (
|
|
1003
|
-
throw new HostMemoryAdmissionError(
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
unreservedAvailableMb: null
|
|
1013
|
-
}
|
|
1014
|
-
);
|
|
1076
|
+
if (snapshot.availableMb === null || typeof snapshot.availableMb !== "number" || Number.isNaN(snapshot.availableMb) || !Number.isFinite(snapshot.availableMb) || snapshot.availableMb < 0) {
|
|
1077
|
+
throw new HostMemoryAdmissionError(`[host-memory-admission] 宿主可用内存未知或无效,拒绝无声当充足。`, {
|
|
1078
|
+
effectiveAvailableMb: null,
|
|
1079
|
+
requiredMinMb: minAvailableMb,
|
|
1080
|
+
source: snapshot.source,
|
|
1081
|
+
limitingSource: "host",
|
|
1082
|
+
activeStartupRuns: 0,
|
|
1083
|
+
reservedStartupMb: 0,
|
|
1084
|
+
unreservedAvailableMb: null
|
|
1085
|
+
});
|
|
1015
1086
|
}
|
|
1016
|
-
effectiveAvailableMb =
|
|
1087
|
+
effectiveAvailableMb = snapshot.availableMb;
|
|
1017
1088
|
limitingSource = "host";
|
|
1018
1089
|
}
|
|
1019
1090
|
let activeStartupRuns = 0;
|
|
1020
1091
|
if (deps.listRecentRuns) {
|
|
1021
1092
|
const records = deps.listRecentRuns();
|
|
1022
1093
|
if (!Array.isArray(records)) {
|
|
1023
|
-
throw new HostMemoryAdmissionError(
|
|
1024
|
-
|
|
1025
|
-
|
|
1094
|
+
throw new HostMemoryAdmissionError(`[host-memory-admission] 获取最近运行记录列表失败,拒绝未知当归零。`, {
|
|
1095
|
+
effectiveAvailableMb,
|
|
1096
|
+
requiredMinMb: minAvailableMb,
|
|
1097
|
+
source: snapshot.source,
|
|
1098
|
+
limitingSource,
|
|
1099
|
+
activeStartupRuns: 0,
|
|
1100
|
+
reservedStartupMb: 0,
|
|
1101
|
+
unreservedAvailableMb: effectiveAvailableMb
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
for (const rec of records) {
|
|
1105
|
+
if (!rec || typeof rec !== "object") {
|
|
1106
|
+
throw new HostMemoryAdmissionError(`[host-memory-admission] 运行记录损坏,拒绝未知当归零。`, {
|
|
1026
1107
|
effectiveAvailableMb,
|
|
1027
1108
|
requiredMinMb: minAvailableMb,
|
|
1028
|
-
source:
|
|
1109
|
+
source: snapshot.source,
|
|
1029
1110
|
limitingSource,
|
|
1030
1111
|
activeStartupRuns: 0,
|
|
1031
1112
|
reservedStartupMb: 0,
|
|
1032
1113
|
unreservedAvailableMb: effectiveAvailableMb
|
|
1033
|
-
}
|
|
1034
|
-
);
|
|
1035
|
-
}
|
|
1036
|
-
for (const rec of records) {
|
|
1037
|
-
if (!rec || typeof rec !== "object") {
|
|
1038
|
-
throw new HostMemoryAdmissionError(
|
|
1039
|
-
`[host-memory-admission] \u8FD0\u884C\u8BB0\u5F55\u635F\u574F\uFF0C\u62D2\u7EDD\u672A\u77E5\u5F53\u5F52\u96F6\u3002`,
|
|
1040
|
-
{
|
|
1041
|
-
effectiveAvailableMb,
|
|
1042
|
-
requiredMinMb: minAvailableMb,
|
|
1043
|
-
source: snapshot2.source,
|
|
1044
|
-
limitingSource,
|
|
1045
|
-
activeStartupRuns: 0,
|
|
1046
|
-
reservedStartupMb: 0,
|
|
1047
|
-
unreservedAvailableMb: effectiveAvailableMb
|
|
1048
|
-
}
|
|
1049
|
-
);
|
|
1114
|
+
});
|
|
1050
1115
|
}
|
|
1051
|
-
if (rec.status !== "running")
|
|
1116
|
+
if (rec.status !== "running")
|
|
1117
|
+
continue;
|
|
1052
1118
|
const startedTime = new Date(rec.startedAt).getTime();
|
|
1053
1119
|
if (!Number.isFinite(startedTime) || Number.isNaN(startedTime)) {
|
|
1054
|
-
throw new HostMemoryAdmissionError(
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
unreservedAvailableMb: effectiveAvailableMb
|
|
1064
|
-
}
|
|
1065
|
-
);
|
|
1120
|
+
throw new HostMemoryAdmissionError(`[host-memory-admission] 运行记录 startedAt 无效,拒绝未知当归零。`, {
|
|
1121
|
+
effectiveAvailableMb,
|
|
1122
|
+
requiredMinMb: minAvailableMb,
|
|
1123
|
+
source: snapshot.source,
|
|
1124
|
+
limitingSource,
|
|
1125
|
+
activeStartupRuns: 0,
|
|
1126
|
+
reservedStartupMb: 0,
|
|
1127
|
+
unreservedAvailableMb: effectiveAvailableMb
|
|
1128
|
+
});
|
|
1066
1129
|
}
|
|
1067
1130
|
if (now - startedTime >= 0 && now - startedTime < startupWindowMs) {
|
|
1068
1131
|
activeStartupRuns += 1;
|
|
@@ -1072,26 +1135,23 @@ function assertHostMemoryAdmission(deps = {}) {
|
|
|
1072
1135
|
const reservedStartupMb = activeStartupRuns * reservedMbPerRun;
|
|
1073
1136
|
const netAvailableMb = effectiveAvailableMb - reservedStartupMb;
|
|
1074
1137
|
if (netAvailableMb < minAvailableMb) {
|
|
1075
|
-
const detailMsg =
|
|
1076
|
-
throw new HostMemoryAdmissionError(
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
unreservedAvailableMb: effectiveAvailableMb
|
|
1086
|
-
}
|
|
1087
|
-
);
|
|
1138
|
+
const detailMsg = `当前有效可用 ${formatHostMemoryMb(effectiveAvailableMb)}(受限源: ${limitingSource})` + (activeStartupRuns > 0 ? `,并发启动窗口内有 ${activeStartupRuns} 个进行中任务(预留 ${formatHostMemoryMb(reservedStartupMb)},折算剩余 ${formatHostMemoryMb(netAvailableMb)})` : "") + `,低于安全阈值 ${formatHostMemoryMb(minAvailableMb)}。`;
|
|
1139
|
+
throw new HostMemoryAdmissionError(`[host-memory-admission] 拒绝本地派发:${detailMsg}为避免触发宿主/cgroup OOM-killer 崩溃,请等待其他任务完成或释放内存后再试。`, {
|
|
1140
|
+
effectiveAvailableMb: netAvailableMb,
|
|
1141
|
+
requiredMinMb: minAvailableMb,
|
|
1142
|
+
source: snapshot.source,
|
|
1143
|
+
limitingSource,
|
|
1144
|
+
activeStartupRuns,
|
|
1145
|
+
reservedStartupMb,
|
|
1146
|
+
unreservedAvailableMb: effectiveAvailableMb
|
|
1147
|
+
});
|
|
1088
1148
|
}
|
|
1089
1149
|
return {
|
|
1090
1150
|
allowed: true,
|
|
1091
1151
|
effectiveAvailableMb: netAvailableMb,
|
|
1092
1152
|
requiredMinMb: minAvailableMb,
|
|
1093
1153
|
activeStartupRuns,
|
|
1094
|
-
snapshot
|
|
1154
|
+
snapshot
|
|
1095
1155
|
};
|
|
1096
1156
|
}
|
|
1097
1157
|
|
|
@@ -1101,7 +1161,8 @@ function resolveReservationsDir(runsDir) {
|
|
|
1101
1161
|
return join(runsDir, "reservations");
|
|
1102
1162
|
}
|
|
1103
1163
|
function defaultIsProcessAlive(pid) {
|
|
1104
|
-
if (!Number.isInteger(pid) || pid <= 0)
|
|
1164
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
1165
|
+
throw new Error("Invalid PID");
|
|
1105
1166
|
try {
|
|
1106
1167
|
process.kill(pid, 0);
|
|
1107
1168
|
return true;
|
|
@@ -1113,13 +1174,13 @@ function defaultIsProcessAlive(pid) {
|
|
|
1113
1174
|
}
|
|
1114
1175
|
}
|
|
1115
1176
|
function sleepSync(ms) {
|
|
1116
|
-
if (ms <= 0)
|
|
1177
|
+
if (ms <= 0)
|
|
1178
|
+
return;
|
|
1117
1179
|
try {
|
|
1118
1180
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
1119
1181
|
} catch {
|
|
1120
1182
|
const end = Date.now() + ms;
|
|
1121
|
-
while (Date.now() < end) {
|
|
1122
|
-
}
|
|
1183
|
+
while (Date.now() < end) {}
|
|
1123
1184
|
}
|
|
1124
1185
|
}
|
|
1125
1186
|
function updateReservationFile(filePath, fs, updater) {
|
|
@@ -1144,32 +1205,29 @@ function scanActiveReservations(reservationsDir, deps) {
|
|
|
1144
1205
|
try {
|
|
1145
1206
|
entries = fs.readdirSync(reservationsDir);
|
|
1146
1207
|
} catch (err) {
|
|
1147
|
-
throw new Error(
|
|
1148
|
-
`[host-memory-reservation] \u8BFB\u53D6\u9884\u7559\u76EE\u5F55\u5931\u8D25: ${err instanceof Error ? err.message : String(err)}`
|
|
1149
|
-
);
|
|
1208
|
+
throw new Error(`[host-memory-reservation] 读取预留目录失败: ${err instanceof Error ? err.message : String(err)}`);
|
|
1150
1209
|
}
|
|
1151
1210
|
let activeStartupRuns = 0;
|
|
1152
1211
|
let reservedStartupMb = 0;
|
|
1153
1212
|
for (const entry of entries) {
|
|
1154
|
-
if (!entry.endsWith(".json") || !entry.startsWith("reservation-"))
|
|
1213
|
+
if (!entry.endsWith(".json") || !entry.startsWith("reservation-"))
|
|
1214
|
+
continue;
|
|
1155
1215
|
const filePath = join(reservationsDir, entry);
|
|
1156
1216
|
let record;
|
|
1157
1217
|
try {
|
|
1158
1218
|
const raw = fs.readFileSync(filePath, "utf8");
|
|
1159
1219
|
record = JSON.parse(raw);
|
|
1160
1220
|
} catch (err) {
|
|
1161
|
-
throw new Error(
|
|
1162
|
-
`[host-memory-reservation] \u89E3\u6790\u9884\u7559\u8BB0\u5F55\u6587\u4EF6\u5931\u8D25 (${filePath}): ${err instanceof Error ? err.message : String(err)}\uFF0C\u62D2\u7EDD\u672A\u77E5\u5F53\u5F52\u96F6`
|
|
1163
|
-
);
|
|
1221
|
+
throw new Error(`[host-memory-reservation] 解析预留记录文件失败 (${filePath}): ${err instanceof Error ? err.message : String(err)},拒绝未知当归零`);
|
|
1164
1222
|
}
|
|
1165
1223
|
if (!record || typeof record !== "object") {
|
|
1166
|
-
throw new Error(`[host-memory-reservation]
|
|
1224
|
+
throw new Error(`[host-memory-reservation] 预留记录格式损坏 (${filePath}),拒绝未知当归零`);
|
|
1167
1225
|
}
|
|
1168
1226
|
if (typeof record.reservedMb !== "number" || Number.isNaN(record.reservedMb) || !Number.isFinite(record.reservedMb) || record.reservedMb < 0) {
|
|
1169
|
-
throw new Error(`[host-memory-reservation]
|
|
1227
|
+
throw new Error(`[host-memory-reservation] 预留记录包含无效 reservedMb (${filePath})`);
|
|
1170
1228
|
}
|
|
1171
1229
|
if (typeof record.createdAtMs !== "number" || Number.isNaN(record.createdAtMs) || !Number.isFinite(record.createdAtMs) || record.createdAtMs < 0) {
|
|
1172
|
-
throw new Error(`[host-memory-reservation]
|
|
1230
|
+
throw new Error(`[host-memory-reservation] 预留记录包含无效 createdAtMs (${filePath})`);
|
|
1173
1231
|
}
|
|
1174
1232
|
if (record.status === "released" || record.status === "reclaimed") {
|
|
1175
1233
|
continue;
|
|
@@ -1187,9 +1245,9 @@ function scanActiveReservations(reservationsDir, deps) {
|
|
|
1187
1245
|
let actualStart;
|
|
1188
1246
|
try {
|
|
1189
1247
|
alive = isProcessAlive(pid);
|
|
1190
|
-
if (alive && expectedStart)
|
|
1191
|
-
|
|
1192
|
-
}
|
|
1248
|
+
if (alive && expectedStart)
|
|
1249
|
+
actualStart = deps.getProcessStartTime?.(pid);
|
|
1250
|
+
} catch {}
|
|
1193
1251
|
const reused = expectedStart && actualStart && Number.isFinite(actualStart.getTime()) && actualStart.toISOString() !== expectedStart;
|
|
1194
1252
|
if (!alive || reused || record.status === "active" && !!expectedStart && record.childIdentity !== "unverified" && ageMs >= startupWindowMs) {
|
|
1195
1253
|
updateReservationFile(filePath, fs, (r) => {
|
|
@@ -1201,7 +1259,8 @@ function scanActiveReservations(reservationsDir, deps) {
|
|
|
1201
1259
|
}
|
|
1202
1260
|
activeStartupRuns += 1;
|
|
1203
1261
|
reservedStartupMb += record.reservedMb;
|
|
1204
|
-
if (!Number.isFinite(reservedStartupMb))
|
|
1262
|
+
if (!Number.isFinite(reservedStartupMb))
|
|
1263
|
+
throw new Error("Invalid reservation total");
|
|
1205
1264
|
}
|
|
1206
1265
|
return { activeStartupRuns, reservedStartupMb };
|
|
1207
1266
|
}
|
|
@@ -1209,7 +1268,7 @@ function reserveHostMemory(deps) {
|
|
|
1209
1268
|
const fs = deps.fs ?? nodeFs;
|
|
1210
1269
|
const runsDir = deps.runsDir;
|
|
1211
1270
|
const reservationsDir = resolveReservationsDir(runsDir);
|
|
1212
|
-
const now = deps.now ? deps.now() :
|
|
1271
|
+
const now = deps.now ? deps.now() : new Date;
|
|
1213
1272
|
let nowMs = now.getTime();
|
|
1214
1273
|
const minAvailableMb = deps.minAvailableMb ?? LOCAL_AGENT_RUN_MIN_AVAILABLE_MB;
|
|
1215
1274
|
const startupWindowMs = deps.startupWindowMs ?? STARTUP_WINDOW_MS;
|
|
@@ -1222,20 +1281,25 @@ function reserveHostMemory(deps) {
|
|
|
1222
1281
|
throw new Error(`[host-memory-reservation] invalid ${name}: ${value}`);
|
|
1223
1282
|
}
|
|
1224
1283
|
}
|
|
1225
|
-
if (!Number.isInteger(maxAttempts) || maxAttempts < 1)
|
|
1226
|
-
|
|
1284
|
+
if (!Number.isInteger(maxAttempts) || maxAttempts < 1)
|
|
1285
|
+
throw new Error("Invalid lock attempts");
|
|
1286
|
+
if (!deps.withLock)
|
|
1287
|
+
throw new Error("[host-memory-reservation] exclusive lock required");
|
|
1227
1288
|
fs.mkdirSync(reservationsDir, { recursive: true });
|
|
1228
1289
|
const locked = (fn) => {
|
|
1229
|
-
for (let attempt = 0;
|
|
1290
|
+
for (let attempt = 0;attempt < maxAttempts; attempt++) {
|
|
1230
1291
|
const result = deps.withLock(MEMORY_RESERVATION_LOCK_ID, () => ({ value: fn() }), { strict: true });
|
|
1231
|
-
if (result !==
|
|
1232
|
-
|
|
1292
|
+
if (result !== undefined)
|
|
1293
|
+
return result.value;
|
|
1294
|
+
if (attempt + 1 < maxAttempts)
|
|
1295
|
+
sleepSync(delayMs);
|
|
1233
1296
|
}
|
|
1234
1297
|
throw new Error("[host-memory-reservation] exclusive lock timeout");
|
|
1235
1298
|
};
|
|
1236
1299
|
const executeReservation = () => {
|
|
1237
|
-
nowMs = (deps.now ? deps.now() :
|
|
1238
|
-
if (!Number.isFinite(nowMs))
|
|
1300
|
+
nowMs = (deps.now ? deps.now() : new Date).getTime();
|
|
1301
|
+
if (!Number.isFinite(nowMs))
|
|
1302
|
+
throw new Error("Invalid reservation time");
|
|
1239
1303
|
const { activeStartupRuns, reservedStartupMb } = scanActiveReservations(reservationsDir, {
|
|
1240
1304
|
fs,
|
|
1241
1305
|
nowMs,
|
|
@@ -1268,25 +1332,30 @@ function reserveHostMemory(deps) {
|
|
|
1268
1332
|
reservedMb: requestedMb,
|
|
1269
1333
|
recordPath,
|
|
1270
1334
|
associate(params) {
|
|
1271
|
-
if (!params.runId || !Number.isInteger(params.pid) || params.pid <= 0)
|
|
1335
|
+
if (!params.runId || !Number.isInteger(params.pid) || params.pid <= 0)
|
|
1336
|
+
throw new Error("Invalid child association");
|
|
1272
1337
|
const validStart = !!params.processStartedAt && Number.isFinite(Date.parse(params.processStartedAt));
|
|
1273
1338
|
locked(() => updateReservationFile(recordPath, fs, (r) => {
|
|
1274
|
-
if (r.status !== "reserved")
|
|
1339
|
+
if (r.status !== "reserved")
|
|
1340
|
+
throw new Error("Reservation is not reserved");
|
|
1275
1341
|
r.status = "active";
|
|
1276
1342
|
r.childIdentity = validStart ? "verified" : "unverified";
|
|
1277
1343
|
if (validStart) {
|
|
1278
1344
|
r.childStartedAt = params.processStartedAt;
|
|
1279
1345
|
}
|
|
1280
|
-
if (params.runId)
|
|
1281
|
-
|
|
1346
|
+
if (params.runId)
|
|
1347
|
+
r.runId = params.runId;
|
|
1348
|
+
if (typeof params.pid === "number")
|
|
1349
|
+
r.childPid = params.pid;
|
|
1282
1350
|
}));
|
|
1283
1351
|
},
|
|
1284
1352
|
release(reason) {
|
|
1285
1353
|
locked(() => updateReservationFile(recordPath, fs, (r) => {
|
|
1286
1354
|
if (r.status === "reserved" || r.status === "active") {
|
|
1287
1355
|
r.status = "released";
|
|
1288
|
-
r.releasedAt =
|
|
1289
|
-
if (reason)
|
|
1356
|
+
r.releasedAt = new Date().toISOString();
|
|
1357
|
+
if (reason)
|
|
1358
|
+
r.reason = reason;
|
|
1290
1359
|
}
|
|
1291
1360
|
}));
|
|
1292
1361
|
}
|
|
@@ -1294,20 +1363,18 @@ function reserveHostMemory(deps) {
|
|
|
1294
1363
|
};
|
|
1295
1364
|
if (deps.withLock) {
|
|
1296
1365
|
const withLock = deps.withLock;
|
|
1297
|
-
for (let attempt = 0;
|
|
1366
|
+
for (let attempt = 0;attempt < maxAttempts; attempt++) {
|
|
1298
1367
|
const handle = withLock(MEMORY_RESERVATION_LOCK_ID, executeReservation, {
|
|
1299
1368
|
strict: true
|
|
1300
1369
|
});
|
|
1301
|
-
if (handle !==
|
|
1370
|
+
if (handle !== undefined) {
|
|
1302
1371
|
return handle;
|
|
1303
1372
|
}
|
|
1304
1373
|
if (attempt < maxAttempts - 1) {
|
|
1305
1374
|
sleepSync(delayMs);
|
|
1306
1375
|
}
|
|
1307
1376
|
}
|
|
1308
|
-
throw new Error(
|
|
1309
|
-
`[host-memory-reservation] \u83B7\u53D6\u9884\u7559\u4E92\u65A5\u9501\u8D85\u65F6\uFF08\u5C1D\u8BD5 ${maxAttempts} \u6B21\uFF09\uFF0C\u62D2\u7EDD\u5E76\u53D1\u51FB\u7A7F`
|
|
1310
|
-
);
|
|
1377
|
+
throw new Error(`[host-memory-reservation] 获取预留互斥锁超时(尝试 ${maxAttempts} 次),拒绝并发击穿`);
|
|
1311
1378
|
}
|
|
1312
1379
|
throw new Error("[host-memory-reservation] exclusive lock required");
|
|
1313
1380
|
}
|
|
@@ -1322,24 +1389,30 @@ function resolveResultServerMeta(input) {
|
|
|
1322
1389
|
}
|
|
1323
1390
|
return {
|
|
1324
1391
|
server: serverOriginForDialog(serverUrl),
|
|
1325
|
-
serverSync: input.hasSubjectRefs ===
|
|
1392
|
+
serverSync: input.hasSubjectRefs === undefined ? undefined : input.hasSubjectRefs ? "awaited" : "best-effort"
|
|
1326
1393
|
};
|
|
1327
1394
|
}
|
|
1328
|
-
var resultHeaderMeta =
|
|
1395
|
+
var resultHeaderMeta = new WeakMap;
|
|
1329
1396
|
function recordRunResultHeaderMeta(result, meta) {
|
|
1330
1397
|
const clean = {};
|
|
1331
|
-
if (meta.commandObservations?.length)
|
|
1332
|
-
|
|
1333
|
-
if (meta.
|
|
1334
|
-
|
|
1335
|
-
if (
|
|
1398
|
+
if (meta.commandObservations?.length)
|
|
1399
|
+
clean.commandObservations = meta.commandObservations;
|
|
1400
|
+
if (meta.model)
|
|
1401
|
+
clean.model = meta.model;
|
|
1402
|
+
if (meta.dialogServer)
|
|
1403
|
+
clean.dialogServer = meta.dialogServer;
|
|
1404
|
+
if (meta.serverSync)
|
|
1405
|
+
clean.serverSync = meta.serverSync;
|
|
1406
|
+
if (Object.keys(clean).length > 0)
|
|
1407
|
+
resultHeaderMeta.set(result, clean);
|
|
1336
1408
|
}
|
|
1337
1409
|
function getRunResultHeaderMeta(result) {
|
|
1338
1410
|
return result && resultHeaderMeta.get(result) || {};
|
|
1339
1411
|
}
|
|
1340
1412
|
function serverOriginForDialog(serverUrl) {
|
|
1341
1413
|
const raw = serverUrl?.trim();
|
|
1342
|
-
if (!raw)
|
|
1414
|
+
if (!raw)
|
|
1415
|
+
return "local";
|
|
1343
1416
|
try {
|
|
1344
1417
|
return new URL(raw).origin;
|
|
1345
1418
|
} catch {
|
|
@@ -1347,7 +1420,8 @@ function serverOriginForDialog(serverUrl) {
|
|
|
1347
1420
|
}
|
|
1348
1421
|
}
|
|
1349
1422
|
function yamlScalar(value) {
|
|
1350
|
-
if (value === null)
|
|
1423
|
+
if (value === null)
|
|
1424
|
+
return "null";
|
|
1351
1425
|
return typeof value === "number" ? String(value) : JSON.stringify(value);
|
|
1352
1426
|
}
|
|
1353
1427
|
function buildResultFrontMatter(input) {
|
|
@@ -1360,16 +1434,9 @@ function buildResultFrontMatter(input) {
|
|
|
1360
1434
|
["endedAt", input.endedAt],
|
|
1361
1435
|
["durationMs", input.durationMs],
|
|
1362
1436
|
["toolCallCount", input.toolCallCount],
|
|
1363
|
-
// 缓存命中观测(见 ai/token/cacheRunSummary):
|
|
1364
|
-
// - cacheInputTokens:本 run 输入 token 总量(各次调用相加,含命中部分)
|
|
1365
|
-
// - cacheCachedTokens:其中命中缓存被复用的量;**null = 未知**(provider
|
|
1366
|
-
// 未提供 cached 字段),0 才是「确实命中 0」——两者不可混
|
|
1367
|
-
// - cacheHitRatio:派生的 cached/input(4 位小数);input=0 时为 0,
|
|
1368
|
-
// cached 未知时为 null
|
|
1369
1437
|
["cacheInputTokens", input.cacheUsage?.input_tokens],
|
|
1370
1438
|
["cacheCachedTokens", input.cacheUsage?.cached_tokens],
|
|
1371
1439
|
["cacheHitRatio", input.cacheUsage?.cache_hit_ratio],
|
|
1372
|
-
// run 级 token 总量与生效档位(结构化回溯用;缺省省略,绝不写 0/unknown)
|
|
1373
1440
|
["inputTokens", input.inputTokens],
|
|
1374
1441
|
["outputTokens", input.outputTokens],
|
|
1375
1442
|
["modelTier", input.modelTier],
|
|
@@ -1378,11 +1445,12 @@ function buildResultFrontMatter(input) {
|
|
|
1378
1445
|
["serverSync", input.serverSync],
|
|
1379
1446
|
["cwd", input.cwd],
|
|
1380
1447
|
["continuedFrom", input.continuedFrom],
|
|
1381
|
-
["acceptance", input.acceptance ? JSON.stringify(input.acceptance) :
|
|
1448
|
+
["acceptance", input.acceptance ? JSON.stringify(input.acceptance) : undefined]
|
|
1382
1449
|
];
|
|
1383
|
-
const lines = entries.filter(([, v]) => v !==
|
|
1450
|
+
const lines = entries.filter(([, v]) => v !== undefined && v !== "").map(([k, v]) => `${k}: ${yamlScalar(v)}`);
|
|
1384
1451
|
return `---
|
|
1385
|
-
${lines.join(
|
|
1452
|
+
${lines.join(`
|
|
1453
|
+
`)}
|
|
1386
1454
|
---
|
|
1387
1455
|
`;
|
|
1388
1456
|
}
|
|
@@ -1403,7 +1471,7 @@ var TOOL_ERROR_PATTERN = /tool.?error|tool.?fail|工具/i;
|
|
|
1403
1471
|
function classifyRunFailure(input) {
|
|
1404
1472
|
const status = typeof input.status === "string" ? input.status : "";
|
|
1405
1473
|
if (status === "done" || status === "killed" || status === "cancelled") {
|
|
1406
|
-
return
|
|
1474
|
+
return;
|
|
1407
1475
|
}
|
|
1408
1476
|
const reason = typeof input.failureReason === "string" ? input.failureReason : "";
|
|
1409
1477
|
const message = typeof input.errorMessage === "string" ? input.errorMessage : "";
|
|
@@ -1433,7 +1501,7 @@ function classifyRunFailure(input) {
|
|
|
1433
1501
|
case "config_unresolved":
|
|
1434
1502
|
return { failureClass: "unknown", retryable: false };
|
|
1435
1503
|
case "cancelled":
|
|
1436
|
-
return
|
|
1504
|
+
return;
|
|
1437
1505
|
default:
|
|
1438
1506
|
break;
|
|
1439
1507
|
}
|
|
@@ -1457,7 +1525,7 @@ function classifyRunFailure(input) {
|
|
|
1457
1525
|
if (status === "failed" || status === "timeout" || status === "orphaned") {
|
|
1458
1526
|
return { failureClass: "unknown", retryable: false };
|
|
1459
1527
|
}
|
|
1460
|
-
return
|
|
1528
|
+
return;
|
|
1461
1529
|
}
|
|
1462
1530
|
|
|
1463
1531
|
// packages/cli/agentRunControl.ts
|
|
@@ -1472,9 +1540,12 @@ function stripVerdictDecoration(line) {
|
|
|
1472
1540
|
function leadingColumns(line) {
|
|
1473
1541
|
let col = 0;
|
|
1474
1542
|
for (const ch of line) {
|
|
1475
|
-
if (ch === " ")
|
|
1476
|
-
|
|
1477
|
-
else
|
|
1543
|
+
if (ch === " ")
|
|
1544
|
+
col += 1;
|
|
1545
|
+
else if (ch === "\t")
|
|
1546
|
+
col += 4 - col % 4;
|
|
1547
|
+
else
|
|
1548
|
+
break;
|
|
1478
1549
|
}
|
|
1479
1550
|
return col;
|
|
1480
1551
|
}
|
|
@@ -1485,32 +1556,38 @@ function assertionLines(text) {
|
|
|
1485
1556
|
const indent = leadingColumns(rawLine);
|
|
1486
1557
|
const content = rawLine.replace(/^[ \t]*/, "");
|
|
1487
1558
|
if (fence) {
|
|
1488
|
-
if (indent >= 4)
|
|
1489
|
-
|
|
1559
|
+
if (indent >= 4)
|
|
1560
|
+
continue;
|
|
1561
|
+
if (new RegExp(`^\\${fence.char}{${fence.length},}\\s*$`).test(content))
|
|
1562
|
+
fence = null;
|
|
1490
1563
|
continue;
|
|
1491
1564
|
}
|
|
1492
|
-
if (indent >= 4)
|
|
1565
|
+
if (indent >= 4)
|
|
1566
|
+
continue;
|
|
1493
1567
|
const open = /^(`{3,}|~{3,})/.exec(content);
|
|
1494
1568
|
if (open) {
|
|
1495
1569
|
fence = { char: open[1][0], length: open[1].length };
|
|
1496
1570
|
continue;
|
|
1497
1571
|
}
|
|
1498
|
-
if (/^>/.test(content))
|
|
1572
|
+
if (/^>/.test(content))
|
|
1573
|
+
continue;
|
|
1499
1574
|
kept.push(rawLine);
|
|
1500
1575
|
}
|
|
1501
1576
|
return kept;
|
|
1502
1577
|
}
|
|
1503
1578
|
function parseWholeTextJson(text) {
|
|
1504
1579
|
const trimmed = text.trim();
|
|
1505
|
-
if (!trimmed)
|
|
1580
|
+
if (!trimmed)
|
|
1581
|
+
return;
|
|
1506
1582
|
try {
|
|
1507
1583
|
return { value: JSON.parse(trimmed) };
|
|
1508
1584
|
} catch {
|
|
1509
|
-
return
|
|
1585
|
+
return;
|
|
1510
1586
|
}
|
|
1511
1587
|
}
|
|
1512
1588
|
function deriveRunFinalObservation(text) {
|
|
1513
|
-
if (typeof text !== "string" || !text.trim())
|
|
1589
|
+
if (typeof text !== "string" || !text.trim())
|
|
1590
|
+
return { escalated: false };
|
|
1514
1591
|
const lines = assertionLines(text);
|
|
1515
1592
|
const wholeJson = parseWholeTextJson(text);
|
|
1516
1593
|
const escalated = wholeJson ? typeof wholeJson.value === "object" && wholeJson.value !== null && !Array.isArray(wholeJson.value) && wholeJson.value.status === "need_escalation" : lines.some((line) => {
|
|
@@ -1521,43 +1598,47 @@ function deriveRunFinalObservation(text) {
|
|
|
1521
1598
|
if (structured.kind === "structured") {
|
|
1522
1599
|
return { escalated, reviewVerdict: structuredReviewVerdict(structured.review) };
|
|
1523
1600
|
}
|
|
1524
|
-
if (structured.kind === "invalid" || wholeJson)
|
|
1525
|
-
|
|
1601
|
+
if (structured.kind === "invalid" || wholeJson)
|
|
1602
|
+
return { escalated };
|
|
1603
|
+
const found = new Set;
|
|
1526
1604
|
for (const line of lines) {
|
|
1527
1605
|
const bare = stripVerdictDecoration(line);
|
|
1528
1606
|
const hit = LABELED_VERDICT_RE.exec(bare) ?? STANDALONE_VERDICT_RE.exec(bare);
|
|
1529
|
-
if (!hit)
|
|
1607
|
+
if (!hit)
|
|
1608
|
+
continue;
|
|
1530
1609
|
found.add(hit[1].toUpperCase());
|
|
1531
1610
|
}
|
|
1532
|
-
if (found.size !== 1)
|
|
1611
|
+
if (found.size !== 1)
|
|
1612
|
+
return { escalated };
|
|
1533
1613
|
return { escalated, reviewVerdict: [...found][0] };
|
|
1534
1614
|
}
|
|
1535
|
-
var RUN_TERMINAL_STATUSES =
|
|
1615
|
+
var RUN_TERMINAL_STATUSES = new Set([
|
|
1536
1616
|
"done",
|
|
1537
1617
|
"failed",
|
|
1538
1618
|
"timeout",
|
|
1539
1619
|
"killed",
|
|
1540
1620
|
"orphaned"
|
|
1541
1621
|
]);
|
|
1542
|
-
function
|
|
1622
|
+
function isRunTerminalStatus2(status) {
|
|
1543
1623
|
return isAgentRunTerminalStatus(status);
|
|
1544
1624
|
}
|
|
1545
1625
|
function resolveNoloHome(env, homedir = nodeHomedir) {
|
|
1546
1626
|
const fromEnv = env?.NOLO_HOME;
|
|
1547
|
-
if (typeof fromEnv === "string" && fromEnv.length > 0)
|
|
1627
|
+
if (typeof fromEnv === "string" && fromEnv.length > 0)
|
|
1628
|
+
return fromEnv;
|
|
1548
1629
|
return join2(homedir(), ".nolo");
|
|
1549
1630
|
}
|
|
1550
|
-
function
|
|
1631
|
+
function resolveRunsDir2(env, homedir = nodeHomedir) {
|
|
1551
1632
|
return join2(resolveNoloHome(env, homedir), "runs");
|
|
1552
1633
|
}
|
|
1553
1634
|
function resolveRunRecordPath(runId, env, homedir = nodeHomedir) {
|
|
1554
|
-
return join2(
|
|
1635
|
+
return join2(resolveRunsDir2(env, homedir), `${runId}.json`);
|
|
1555
1636
|
}
|
|
1556
1637
|
function resolveRunLogPath(runId, env, homedir = nodeHomedir) {
|
|
1557
|
-
return join2(
|
|
1638
|
+
return join2(resolveRunsDir2(env, homedir), `${runId}.log`);
|
|
1558
1639
|
}
|
|
1559
|
-
function
|
|
1560
|
-
return join2(
|
|
1640
|
+
function resolveRunQueuePath2(runId, env, homedir = nodeHomedir) {
|
|
1641
|
+
return join2(resolveRunsDir2(env, homedir), `${runId}.queue.jsonl`);
|
|
1561
1642
|
}
|
|
1562
1643
|
function defaultGenerateQueueEntryId() {
|
|
1563
1644
|
const ts = Date.now().toString(36);
|
|
@@ -1565,8 +1646,10 @@ function defaultGenerateQueueEntryId() {
|
|
|
1565
1646
|
return `qmsg-${ts}-${rand}`;
|
|
1566
1647
|
}
|
|
1567
1648
|
function _parseQueueLines(content) {
|
|
1568
|
-
if (!content.trim())
|
|
1569
|
-
|
|
1649
|
+
if (!content.trim())
|
|
1650
|
+
return [];
|
|
1651
|
+
const lines = content.split(`
|
|
1652
|
+
`).map((l) => l.trim()).filter(Boolean);
|
|
1570
1653
|
const entries = [];
|
|
1571
1654
|
for (const line of lines) {
|
|
1572
1655
|
try {
|
|
@@ -1590,32 +1673,17 @@ function _parseQueueLines(content) {
|
|
|
1590
1673
|
}
|
|
1591
1674
|
return entries;
|
|
1592
1675
|
}
|
|
1593
|
-
var parseQueueLines = _parseQueueLines;
|
|
1594
1676
|
function _serializeQueueEntries(entries) {
|
|
1595
|
-
if (entries.length === 0)
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
if (!fs.existsSync(queuePath)) return 0;
|
|
1601
|
-
try {
|
|
1602
|
-
const content = fs.readFileSync(queuePath, "utf8");
|
|
1603
|
-
return _parseQueueLines(content).length;
|
|
1604
|
-
} catch {
|
|
1605
|
-
return 0;
|
|
1606
|
-
}
|
|
1677
|
+
if (entries.length === 0)
|
|
1678
|
+
return "";
|
|
1679
|
+
return entries.map((e) => JSON.stringify(e)).join(`
|
|
1680
|
+
`) + `
|
|
1681
|
+
`;
|
|
1607
1682
|
}
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
const content = fs.readFileSync(queuePath, "utf8");
|
|
1612
|
-
return _parseQueueLines(content).map((e) => e.text);
|
|
1613
|
-
} catch {
|
|
1683
|
+
var serializeQueueEntries2 = _serializeQueueEntries;
|
|
1684
|
+
function _readQueueEntriesLocked2(queuePath, fs = nodeFs2) {
|
|
1685
|
+
if (!fs.existsSync(queuePath))
|
|
1614
1686
|
return [];
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
function _readQueueEntriesLocked(queuePath, fs = nodeFs2) {
|
|
1618
|
-
if (!fs.existsSync(queuePath)) return [];
|
|
1619
1687
|
try {
|
|
1620
1688
|
const content = fs.readFileSync(queuePath, "utf8");
|
|
1621
1689
|
return _parseQueueLines(content);
|
|
@@ -1624,7 +1692,8 @@ function _readQueueEntriesLocked(queuePath, fs = nodeFs2) {
|
|
|
1624
1692
|
}
|
|
1625
1693
|
}
|
|
1626
1694
|
function tryUnlinkFile(fs, path) {
|
|
1627
|
-
if (typeof path !== "string" || path.length === 0)
|
|
1695
|
+
if (typeof path !== "string" || path.length === 0)
|
|
1696
|
+
return true;
|
|
1628
1697
|
try {
|
|
1629
1698
|
if (fs.existsSync(path)) {
|
|
1630
1699
|
fs.unlinkSync(path);
|
|
@@ -1636,7 +1705,8 @@ function tryUnlinkFile(fs, path) {
|
|
|
1636
1705
|
}
|
|
1637
1706
|
}
|
|
1638
1707
|
function tryRmdir(fs, path) {
|
|
1639
|
-
if (typeof path !== "string" || path.length === 0)
|
|
1708
|
+
if (typeof path !== "string" || path.length === 0)
|
|
1709
|
+
return true;
|
|
1640
1710
|
try {
|
|
1641
1711
|
if (typeof fs.rmdirSync === "function") {
|
|
1642
1712
|
fs.rmdirSync(path);
|
|
@@ -1645,11 +1715,12 @@ function tryRmdir(fs, path) {
|
|
|
1645
1715
|
}
|
|
1646
1716
|
return true;
|
|
1647
1717
|
} catch (error) {
|
|
1648
|
-
if (error?.code === "ENOENT")
|
|
1718
|
+
if (error?.code === "ENOENT")
|
|
1719
|
+
return true;
|
|
1649
1720
|
return false;
|
|
1650
1721
|
}
|
|
1651
1722
|
}
|
|
1652
|
-
var QUEUE_LOCK_STALE_MS =
|
|
1723
|
+
var QUEUE_LOCK_STALE_MS = 60000;
|
|
1653
1724
|
var QUEUE_LOCK_RETRIES = 20;
|
|
1654
1725
|
var QUEUE_LOCK_RETRY_INTERVAL_MS = 10;
|
|
1655
1726
|
function defaultGenerateOwnerTokenId() {
|
|
@@ -1658,13 +1729,14 @@ function defaultGenerateOwnerTokenId() {
|
|
|
1658
1729
|
return `own-${ts}-${rand}`;
|
|
1659
1730
|
}
|
|
1660
1731
|
function normalizeQueueDeps(depsOrFs) {
|
|
1661
|
-
if (!depsOrFs)
|
|
1732
|
+
if (!depsOrFs)
|
|
1733
|
+
return {};
|
|
1662
1734
|
if ("mkdirSync" in depsOrFs) {
|
|
1663
1735
|
return { fs: depsOrFs };
|
|
1664
1736
|
}
|
|
1665
1737
|
return depsOrFs;
|
|
1666
1738
|
}
|
|
1667
|
-
async function
|
|
1739
|
+
async function withQueueLock2(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
1668
1740
|
let fn;
|
|
1669
1741
|
let rawDeps;
|
|
1670
1742
|
let opts = maybeOpts ?? {};
|
|
@@ -1672,7 +1744,7 @@ async function withQueueLock(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
|
1672
1744
|
fn = fnOrDeps;
|
|
1673
1745
|
if (depsOrFnOrOpts && typeof depsOrFnOrOpts === "object" && !("mkdirSync" in depsOrFnOrOpts) && !("fs" in depsOrFnOrOpts) && !("env" in depsOrFnOrOpts)) {
|
|
1674
1746
|
opts = { ...depsOrFnOrOpts, ...maybeOpts };
|
|
1675
|
-
rawDeps =
|
|
1747
|
+
rawDeps = undefined;
|
|
1676
1748
|
} else {
|
|
1677
1749
|
rawDeps = depsOrFnOrOpts;
|
|
1678
1750
|
}
|
|
@@ -1682,7 +1754,7 @@ async function withQueueLock(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
|
1682
1754
|
}
|
|
1683
1755
|
const deps = normalizeQueueDeps(rawDeps);
|
|
1684
1756
|
const fs = deps.fs ?? nodeFs2;
|
|
1685
|
-
const now = deps.now ?? (() =>
|
|
1757
|
+
const now = deps.now ?? (() => new Date);
|
|
1686
1758
|
const staleLockMs = opts.staleLockMs ?? QUEUE_LOCK_STALE_MS;
|
|
1687
1759
|
const retries = opts.retries ?? QUEUE_LOCK_RETRIES;
|
|
1688
1760
|
const retryIntervalMs = opts.retryIntervalMs ?? QUEUE_LOCK_RETRY_INTERVAL_MS;
|
|
@@ -1690,8 +1762,7 @@ async function withQueueLock(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
|
1690
1762
|
const tokenPath = join2(lockPath, "owner.json");
|
|
1691
1763
|
try {
|
|
1692
1764
|
fs.mkdirSync(dirname(lockPath), { recursive: true });
|
|
1693
|
-
} catch {
|
|
1694
|
-
}
|
|
1765
|
+
} catch {}
|
|
1695
1766
|
const myOwnerId = defaultGenerateOwnerTokenId();
|
|
1696
1767
|
let held = false;
|
|
1697
1768
|
const tryAcquire = () => {
|
|
@@ -1708,17 +1779,14 @@ async function withQueueLock(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
|
1708
1779
|
try {
|
|
1709
1780
|
tryUnlinkFile(fs, tokenPath);
|
|
1710
1781
|
tryRmdir(fs, lockPath);
|
|
1711
|
-
} catch {
|
|
1712
|
-
}
|
|
1782
|
+
} catch {}
|
|
1713
1783
|
try {
|
|
1714
1784
|
fs.mkdirSync(lockPath);
|
|
1715
1785
|
created = true;
|
|
1716
|
-
} catch {
|
|
1717
|
-
}
|
|
1786
|
+
} catch {}
|
|
1718
1787
|
}
|
|
1719
1788
|
}
|
|
1720
|
-
} catch {
|
|
1721
|
-
}
|
|
1789
|
+
} catch {}
|
|
1722
1790
|
}
|
|
1723
1791
|
if (created) {
|
|
1724
1792
|
try {
|
|
@@ -1737,13 +1805,13 @@ async function withQueueLock(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
|
1737
1805
|
}
|
|
1738
1806
|
return false;
|
|
1739
1807
|
};
|
|
1740
|
-
for (let attempt = 0;
|
|
1808
|
+
for (let attempt = 0;attempt <= retries; attempt++) {
|
|
1741
1809
|
if (tryAcquire()) {
|
|
1742
1810
|
held = true;
|
|
1743
1811
|
break;
|
|
1744
1812
|
}
|
|
1745
1813
|
if (attempt < retries && retryIntervalMs > 0) {
|
|
1746
|
-
await new Promise((
|
|
1814
|
+
await new Promise((resolve) => setTimeout(resolve, retryIntervalMs));
|
|
1747
1815
|
}
|
|
1748
1816
|
}
|
|
1749
1817
|
if (!held) {
|
|
@@ -1761,16 +1829,14 @@ async function withQueueLock(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
|
1761
1829
|
const parsed = JSON.parse(raw);
|
|
1762
1830
|
currentOwnerId = parsed?.ownerId;
|
|
1763
1831
|
} catch {
|
|
1764
|
-
currentOwnerId =
|
|
1832
|
+
currentOwnerId = undefined;
|
|
1765
1833
|
}
|
|
1766
1834
|
}
|
|
1767
1835
|
if (currentOwnerId === myOwnerId) {
|
|
1768
1836
|
tryUnlinkFile(fs, tokenPath);
|
|
1769
1837
|
tryRmdir(fs, lockPath);
|
|
1770
1838
|
} else {
|
|
1771
|
-
console.error(
|
|
1772
|
-
`[nolo] Warning: queue lock for ${queuePath} was taken over by another process (owner mismatch: expected ${myOwnerId}, found ${currentOwnerId ?? "none"}). Will not release.`
|
|
1773
|
-
);
|
|
1839
|
+
console.error(`[nolo] Warning: queue lock for ${queuePath} was taken over by another process (owner mismatch: expected ${myOwnerId}, found ${currentOwnerId ?? "none"}). Will not release.`);
|
|
1774
1840
|
}
|
|
1775
1841
|
} catch (releaseErr) {
|
|
1776
1842
|
console.error(`[nolo] Warning: failed to release queue lock for ${queuePath}:`, releaseErr);
|
|
@@ -1778,15 +1844,16 @@ async function withQueueLock(queuePath, fnOrDeps, depsOrFnOrOpts, maybeOpts) {
|
|
|
1778
1844
|
}
|
|
1779
1845
|
}
|
|
1780
1846
|
}
|
|
1781
|
-
async function
|
|
1847
|
+
async function appendRunQueue2(queuePath, input, depsOrFs = {}) {
|
|
1782
1848
|
const deps = normalizeQueueDeps(depsOrFs);
|
|
1783
1849
|
const fs = deps.fs ?? nodeFs2;
|
|
1784
|
-
const now = deps.now ?? (() =>
|
|
1850
|
+
const now = deps.now ?? (() => new Date);
|
|
1785
1851
|
const text = typeof input === "string" ? input : input.text;
|
|
1786
1852
|
const entryId = typeof input === "object" && typeof input.id === "string" && input.id.trim() ? input.id.trim() : defaultGenerateQueueEntryId();
|
|
1787
1853
|
const entry = { id: entryId, ts: now().getTime(), text };
|
|
1788
|
-
const line = JSON.stringify(entry) +
|
|
1789
|
-
|
|
1854
|
+
const line = JSON.stringify(entry) + `
|
|
1855
|
+
`;
|
|
1856
|
+
return await withQueueLock2(queuePath, deps, async () => {
|
|
1790
1857
|
if (typeof fs.appendFileSync === "function") {
|
|
1791
1858
|
fs.appendFileSync(queuePath, line, "utf8");
|
|
1792
1859
|
} else {
|
|
@@ -1797,46 +1864,12 @@ async function appendRunQueue(queuePath, input, depsOrFs = {}) {
|
|
|
1797
1864
|
return { queuedCount: _parseQueueLines(currentContent).length, entryId };
|
|
1798
1865
|
});
|
|
1799
1866
|
}
|
|
1800
|
-
async function
|
|
1801
|
-
const deps = normalizeQueueDeps(depsOrFs);
|
|
1802
|
-
const fs = deps.fs ?? nodeFs2;
|
|
1803
|
-
if (!fs.existsSync(queuePath)) return 0;
|
|
1804
|
-
return await withQueueLock(queuePath, deps, async () => {
|
|
1805
|
-
return _countQueueMessagesLocked(queuePath, fs);
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
1808
|
-
async function readQueueMessages(queuePath, depsOrFs = {}) {
|
|
1809
|
-
const deps = normalizeQueueDeps(depsOrFs);
|
|
1810
|
-
const fs = deps.fs ?? nodeFs2;
|
|
1811
|
-
if (!fs.existsSync(queuePath)) return [];
|
|
1812
|
-
return await withQueueLock(queuePath, deps, async () => {
|
|
1813
|
-
return _readQueueMessagesLocked(queuePath, fs);
|
|
1814
|
-
});
|
|
1815
|
-
}
|
|
1816
|
-
async function readQueueEntries(queuePath, depsOrFs = {}) {
|
|
1867
|
+
async function popSingleQueueMessage2(queuePath, depsOrFs = {}) {
|
|
1817
1868
|
const deps = normalizeQueueDeps(depsOrFs);
|
|
1818
1869
|
const fs = deps.fs ?? nodeFs2;
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
});
|
|
1823
|
-
}
|
|
1824
|
-
async function popAllQueueEntries(queuePath, depsOrFs = {}) {
|
|
1825
|
-
const deps = normalizeQueueDeps(depsOrFs);
|
|
1826
|
-
const fs = deps.fs ?? nodeFs2;
|
|
1827
|
-
return await withQueueLock(queuePath, deps, async () => {
|
|
1828
|
-
if (!fs.existsSync(queuePath)) return [];
|
|
1829
|
-
const content = fs.readFileSync(queuePath, "utf8");
|
|
1830
|
-
const entries = _parseQueueLines(content);
|
|
1831
|
-
tryUnlinkFile(fs, queuePath);
|
|
1832
|
-
return entries;
|
|
1833
|
-
});
|
|
1834
|
-
}
|
|
1835
|
-
async function popSingleQueueMessage(queuePath, depsOrFs = {}) {
|
|
1836
|
-
const deps = normalizeQueueDeps(depsOrFs);
|
|
1837
|
-
const fs = deps.fs ?? nodeFs2;
|
|
1838
|
-
return await withQueueLock(queuePath, deps, async () => {
|
|
1839
|
-
if (!fs.existsSync(queuePath)) return null;
|
|
1870
|
+
return await withQueueLock2(queuePath, deps, async () => {
|
|
1871
|
+
if (!fs.existsSync(queuePath))
|
|
1872
|
+
return null;
|
|
1840
1873
|
const content = fs.readFileSync(queuePath, "utf8");
|
|
1841
1874
|
const entries = _parseQueueLines(content);
|
|
1842
1875
|
if (entries.length === 0) {
|
|
@@ -1852,25 +1885,21 @@ async function popSingleQueueMessage(queuePath, depsOrFs = {}) {
|
|
|
1852
1885
|
return first;
|
|
1853
1886
|
});
|
|
1854
1887
|
}
|
|
1855
|
-
|
|
1856
|
-
const
|
|
1857
|
-
return entries.map((e) => e.text);
|
|
1858
|
-
}
|
|
1859
|
-
function defaultGenerateRunId() {
|
|
1860
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
1888
|
+
function defaultGenerateRunId2() {
|
|
1889
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
1861
1890
|
const random = Math.random().toString(36).slice(2, 8);
|
|
1862
1891
|
return `run-${timestamp}-${random}`;
|
|
1863
1892
|
}
|
|
1864
1893
|
function defaultGenerateBatchId() {
|
|
1865
|
-
const timestamp =
|
|
1894
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
1866
1895
|
const random = Math.random().toString(36).slice(2, 8);
|
|
1867
1896
|
return `batch-${timestamp}-${random}`;
|
|
1868
1897
|
}
|
|
1869
|
-
var LOCK_STALE_MS =
|
|
1870
|
-
var TMP_STALE_MS =
|
|
1898
|
+
var LOCK_STALE_MS = 5000;
|
|
1899
|
+
var TMP_STALE_MS = 60000;
|
|
1871
1900
|
function withRunRecordLock(runId, deps, fn, opts = {}) {
|
|
1872
1901
|
const fs = deps.fs ?? nodeFs2;
|
|
1873
|
-
const now = deps.now ?? (() =>
|
|
1902
|
+
const now = deps.now ?? (() => new Date);
|
|
1874
1903
|
const lockPath = `${resolveRunRecordPath(runId, deps.env, deps.homedir)}.lock`;
|
|
1875
1904
|
let held = false;
|
|
1876
1905
|
try {
|
|
@@ -1885,31 +1914,30 @@ function withRunRecordLock(runId, deps, fn, opts = {}) {
|
|
|
1885
1914
|
try {
|
|
1886
1915
|
const stat = fs.statSync?.(lockPath);
|
|
1887
1916
|
const ageMs = stat ? now().getTime() - stat.mtimeMs : Number.POSITIVE_INFINITY;
|
|
1888
|
-
const ownerPid = opts.requireDeadOwner ? Number(String(fs.readFileSync(lockPath, "utf8"))) :
|
|
1889
|
-
const ownerGone = !opts.requireDeadOwner || Number.isSafeInteger(ownerPid) && ownerPid > 0 &&
|
|
1917
|
+
const ownerPid = opts.requireDeadOwner ? Number(String(fs.readFileSync(lockPath, "utf8"))) : undefined;
|
|
1918
|
+
const ownerGone = !opts.requireDeadOwner || Number.isSafeInteger(ownerPid) && ownerPid > 0 && isPidGone2(ownerPid, deps);
|
|
1890
1919
|
if (ageMs > LOCK_STALE_MS && ownerGone) {
|
|
1891
1920
|
fs.unlinkSync(lockPath);
|
|
1892
1921
|
fs.writeFileSync(lockPath, String(process.pid), { flag: "wx" });
|
|
1893
1922
|
held = true;
|
|
1894
1923
|
}
|
|
1895
|
-
} catch {
|
|
1896
|
-
}
|
|
1924
|
+
} catch {}
|
|
1897
1925
|
}
|
|
1898
|
-
if (!held && opts.strict)
|
|
1926
|
+
if (!held && opts.strict)
|
|
1927
|
+
return;
|
|
1899
1928
|
return fn();
|
|
1900
1929
|
} finally {
|
|
1901
1930
|
if (held) {
|
|
1902
1931
|
try {
|
|
1903
1932
|
fs.unlinkSync(lockPath);
|
|
1904
|
-
} catch {
|
|
1905
|
-
}
|
|
1933
|
+
} catch {}
|
|
1906
1934
|
}
|
|
1907
1935
|
}
|
|
1908
1936
|
}
|
|
1909
1937
|
function writeRunRecord(record, deps = {}) {
|
|
1910
1938
|
const fs = deps.fs ?? nodeFs2;
|
|
1911
1939
|
const path = resolveRunRecordPath(record.runId, deps.env, deps.homedir);
|
|
1912
|
-
fs.mkdirSync(
|
|
1940
|
+
fs.mkdirSync(resolveRunsDir2(deps.env, deps.homedir), { recursive: true });
|
|
1913
1941
|
const payload = JSON.stringify(record, null, 2);
|
|
1914
1942
|
if (typeof fs.renameSync === "function") {
|
|
1915
1943
|
const tmp = `${path}.${process.pid}.${Math.random().toString(36).slice(2, 8)}.tmp`;
|
|
@@ -1920,27 +1948,29 @@ function writeRunRecord(record, deps = {}) {
|
|
|
1920
1948
|
} catch (error) {
|
|
1921
1949
|
try {
|
|
1922
1950
|
fs.unlinkSync(tmp);
|
|
1923
|
-
} catch {
|
|
1924
|
-
|
|
1925
|
-
|
|
1951
|
+
} catch {}
|
|
1952
|
+
if (record.writerLaunch)
|
|
1953
|
+
throw error;
|
|
1926
1954
|
}
|
|
1927
1955
|
}
|
|
1928
|
-
if (record.writerLaunch)
|
|
1956
|
+
if (record.writerLaunch)
|
|
1957
|
+
throw new Error("[local-writer-resource] fenced launch requires atomic rename");
|
|
1929
1958
|
fs.writeFileSync(path, payload);
|
|
1930
1959
|
}
|
|
1931
|
-
function
|
|
1932
|
-
const processStartedAt = new Date(Date.now() - process.uptime() *
|
|
1960
|
+
function reportRunProcessIdentity2(runId, deps = {}) {
|
|
1961
|
+
const processStartedAt = new Date(Date.now() - process.uptime() * 1000).toISOString();
|
|
1933
1962
|
withRunRecordLock(runId, deps, () => {
|
|
1934
|
-
const record =
|
|
1935
|
-
if (!record || record.pid !==
|
|
1963
|
+
const record = readRunRecord2(runId, deps);
|
|
1964
|
+
if (!record || record.pid !== undefined && record.pid !== process.pid)
|
|
1965
|
+
return;
|
|
1936
1966
|
record.pid = process.pid;
|
|
1937
1967
|
record.processStartedAt = processStartedAt;
|
|
1938
1968
|
record.processIdentity = "verified";
|
|
1939
1969
|
writeRunRecord(record, deps);
|
|
1940
1970
|
}, { strict: true });
|
|
1941
1971
|
}
|
|
1942
|
-
var FILE_EDIT_TOOL_NAMES =
|
|
1943
|
-
var DEFAULT_ACTIVITY_WRITE_INTERVAL_MS =
|
|
1972
|
+
var FILE_EDIT_TOOL_NAMES = new Set(["writeFile", "editFile"]);
|
|
1973
|
+
var DEFAULT_ACTIVITY_WRITE_INTERVAL_MS = 2000;
|
|
1944
1974
|
var CREDENTIAL_ASSIGNMENT_PATTERN = /(["']?\b[A-Za-z0-9_-]*(?:token|secret|password|passwd|credential|api[_-]?key|machine[_-]?lease|workspace[_-]?lease)[A-Za-z0-9_-]*["']?\s*[:=]\s*)[\s\S]*$/gi;
|
|
1945
1975
|
var BEARER_PATTERN = /\bBearer\s+[\s\S]*$/gi;
|
|
1946
1976
|
var GITHUB_TOKEN_PATTERN = /\b(?:ghp|gho|ghu|ghs|ghr)_[\s\S]*/g;
|
|
@@ -1956,11 +1986,12 @@ function createCredentialScanner() {
|
|
|
1956
1986
|
const KEYWORD = /token|secret|password|passwd|credential|api[_-]?key|machine[_-]?lease|workspace[_-]?lease/i;
|
|
1957
1987
|
const GH = /(?:ghp|gho|ghu|ghs|ghr)_/gi;
|
|
1958
1988
|
function startsAtWordBoundary(run, index, runLength) {
|
|
1959
|
-
if (index > 0)
|
|
1989
|
+
if (index > 0)
|
|
1990
|
+
return !/[A-Za-z0-9_]/.test(run[index - 1]);
|
|
1960
1991
|
return runLength === run.length;
|
|
1961
1992
|
}
|
|
1962
1993
|
function feed(text) {
|
|
1963
|
-
for (let i = 0;
|
|
1994
|
+
for (let i = 0;i < text.length; i++) {
|
|
1964
1995
|
const ch = text[i];
|
|
1965
1996
|
if (/[A-Za-z0-9_-]/.test(ch)) {
|
|
1966
1997
|
if (pendingSeparator) {
|
|
@@ -1992,8 +2023,7 @@ function createCredentialScanner() {
|
|
|
1992
2023
|
reset();
|
|
1993
2024
|
return i + 1;
|
|
1994
2025
|
}
|
|
1995
|
-
if (/\s/.test(ch) || ch === '"' || ch === "'") {
|
|
1996
|
-
} else {
|
|
2026
|
+
if (/\s/.test(ch) || ch === '"' || ch === "'") {} else {
|
|
1997
2027
|
reset();
|
|
1998
2028
|
}
|
|
1999
2029
|
} else if (identHasKeyword) {
|
|
@@ -2022,9 +2052,9 @@ function createCredentialScanner() {
|
|
|
2022
2052
|
}
|
|
2023
2053
|
return { feed, reset };
|
|
2024
2054
|
}
|
|
2025
|
-
function
|
|
2055
|
+
function createRunActivityTracker2(runId, deps = {}, options = {}) {
|
|
2026
2056
|
const fs = deps.fs ?? nodeFs2;
|
|
2027
|
-
const now = deps.now ?? (() =>
|
|
2057
|
+
const now = deps.now ?? (() => new Date);
|
|
2028
2058
|
const minWriteIntervalMs = options.minWriteIntervalMs ?? DEFAULT_ACTIVITY_WRITE_INTERVAL_MS;
|
|
2029
2059
|
const keepAlive = options.keepAlive ?? true;
|
|
2030
2060
|
let disposed = false;
|
|
@@ -2046,7 +2076,7 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2046
2076
|
let partialUpdatedAt;
|
|
2047
2077
|
let sourceRound;
|
|
2048
2078
|
let currentLlmRound;
|
|
2049
|
-
const PARTIAL_LIMIT =
|
|
2079
|
+
const PARTIAL_LIMIT = 32000;
|
|
2050
2080
|
const OMITTED_LINE = "[checkpoint: overlong line omitted]";
|
|
2051
2081
|
const OMITTED_CREDENTIAL = "[checkpoint: credential content omitted]";
|
|
2052
2082
|
function closeLine() {
|
|
@@ -2059,33 +2089,39 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2059
2089
|
if (!maskedPrefix.endsWith(REDACTED_CREDENTIAL) && !maskedPrefix.endsWith("[REDACTED_TOKEN]")) {
|
|
2060
2090
|
maskedPrefix += REDACTED_CREDENTIAL;
|
|
2061
2091
|
}
|
|
2062
|
-
if (partialText.length <
|
|
2063
|
-
partialText += maskedPrefix +
|
|
2092
|
+
if (partialText.length < 4000) {
|
|
2093
|
+
partialText += maskedPrefix + `
|
|
2094
|
+
`;
|
|
2064
2095
|
} else {
|
|
2065
2096
|
partialTruncated = true;
|
|
2066
2097
|
}
|
|
2067
|
-
if (partialText.length >
|
|
2098
|
+
if (partialText.length > 4000)
|
|
2099
|
+
partialTruncated = true;
|
|
2068
2100
|
droppingCredential = true;
|
|
2069
2101
|
partialTruncated = true;
|
|
2070
2102
|
} else {
|
|
2071
2103
|
const safe = redactLogLines([pendingLine]);
|
|
2072
2104
|
partialRedacted += safe.redacted;
|
|
2073
|
-
if (partialText.length <
|
|
2074
|
-
partialText += (droppingLine ? OMITTED_LINE : safe.lines[0]) +
|
|
2105
|
+
if (partialText.length < 4000) {
|
|
2106
|
+
partialText += (droppingLine ? OMITTED_LINE : safe.lines[0]) + `
|
|
2107
|
+
`;
|
|
2075
2108
|
} else {
|
|
2076
2109
|
partialTruncated = true;
|
|
2077
2110
|
}
|
|
2078
|
-
if (partialText.length >
|
|
2111
|
+
if (partialText.length > 4000 || droppingLine)
|
|
2112
|
+
partialTruncated = true;
|
|
2079
2113
|
}
|
|
2080
|
-
partialText = partialText.slice(0,
|
|
2114
|
+
partialText = partialText.slice(0, 4000);
|
|
2081
2115
|
pendingLine = "";
|
|
2082
2116
|
droppingLine = false;
|
|
2083
2117
|
lineCredentialHit = false;
|
|
2084
2118
|
}
|
|
2085
2119
|
function checkpoint() {
|
|
2086
|
-
if (!partialUpdatedAt)
|
|
2120
|
+
if (!partialUpdatedAt)
|
|
2121
|
+
return;
|
|
2087
2122
|
const text = partialText || (droppingLine ? OMITTED_LINE : droppingCredential ? OMITTED_CREDENTIAL : "");
|
|
2088
|
-
if (!text)
|
|
2123
|
+
if (!text)
|
|
2124
|
+
return;
|
|
2089
2125
|
return {
|
|
2090
2126
|
final: false,
|
|
2091
2127
|
source: "local-run.text-delta",
|
|
@@ -2114,39 +2150,40 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2114
2150
|
};
|
|
2115
2151
|
}
|
|
2116
2152
|
function doWrite() {
|
|
2117
|
-
if (disposed)
|
|
2118
|
-
|
|
2153
|
+
if (disposed)
|
|
2154
|
+
return;
|
|
2155
|
+
writeTimer = undefined;
|
|
2119
2156
|
const attemptAt = now().getTime();
|
|
2120
|
-
withRunRecordLock(
|
|
2121
|
-
runId,
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
if (lastWriteAt < attemptAt) lastWriteAt = attemptAt;
|
|
2138
|
-
if (keepAlive) scheduleWrite();
|
|
2157
|
+
withRunRecordLock(runId, deps, () => {
|
|
2158
|
+
const record = readRunRecord2(runId, deps);
|
|
2159
|
+
if (!record || isRunTerminalStatus2(record.status))
|
|
2160
|
+
return;
|
|
2161
|
+
const activity = serializeActivity();
|
|
2162
|
+
const partialCheckpoint = checkpoint();
|
|
2163
|
+
writeRunRecord({
|
|
2164
|
+
...record,
|
|
2165
|
+
activity,
|
|
2166
|
+
...partialCheckpoint ? { partialCheckpoint } : {}
|
|
2167
|
+
}, deps);
|
|
2168
|
+
lastWriteAt = now().getTime();
|
|
2169
|
+
}, { strict: true });
|
|
2170
|
+
if (lastWriteAt < attemptAt)
|
|
2171
|
+
lastWriteAt = attemptAt;
|
|
2172
|
+
if (keepAlive)
|
|
2173
|
+
scheduleWrite();
|
|
2139
2174
|
}
|
|
2140
2175
|
scheduleWrite();
|
|
2141
2176
|
function scheduleWrite() {
|
|
2142
|
-
if (writeTimer !==
|
|
2177
|
+
if (writeTimer !== undefined)
|
|
2178
|
+
return;
|
|
2143
2179
|
const elapsed = now().getTime() - lastWriteAt;
|
|
2144
2180
|
const delay = Math.max(0, minWriteIntervalMs - elapsed);
|
|
2145
2181
|
writeTimer = setTimeout(doWrite, delay);
|
|
2146
2182
|
}
|
|
2147
2183
|
let partialRoundStarted = false;
|
|
2148
2184
|
function onLoopEvent(event) {
|
|
2149
|
-
if (disposed)
|
|
2185
|
+
if (disposed)
|
|
2186
|
+
return;
|
|
2150
2187
|
lastEventAt = new Date(event.atMs).toISOString();
|
|
2151
2188
|
lastProgressAt = lastEventAt;
|
|
2152
2189
|
switch (event.kind) {
|
|
@@ -2201,11 +2238,14 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2201
2238
|
}
|
|
2202
2239
|
break;
|
|
2203
2240
|
}
|
|
2204
|
-
if (event.kind === "llm-end" && !event.ok)
|
|
2205
|
-
|
|
2241
|
+
if (event.kind === "llm-end" && !event.ok)
|
|
2242
|
+
doWrite();
|
|
2243
|
+
else
|
|
2244
|
+
scheduleWrite();
|
|
2206
2245
|
}
|
|
2207
2246
|
function onPartialText(chunk) {
|
|
2208
|
-
if (disposed || !chunk)
|
|
2247
|
+
if (disposed || !chunk)
|
|
2248
|
+
return;
|
|
2209
2249
|
lastProgressAt = now().toISOString();
|
|
2210
2250
|
if (partialRoundStarted) {
|
|
2211
2251
|
droppingCredential = false;
|
|
@@ -2215,8 +2255,9 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2215
2255
|
lineCredentialHit = false;
|
|
2216
2256
|
partialRoundStarted = false;
|
|
2217
2257
|
}
|
|
2218
|
-
for (let start = 0;
|
|
2219
|
-
const newline = chunk.indexOf(
|
|
2258
|
+
for (let start = 0;start < chunk.length; ) {
|
|
2259
|
+
const newline = chunk.indexOf(`
|
|
2260
|
+
`, start);
|
|
2220
2261
|
const end = newline < 0 ? chunk.length : newline;
|
|
2221
2262
|
const segment = chunk.slice(start, end);
|
|
2222
2263
|
const hit = scanner.feed(segment);
|
|
@@ -2248,7 +2289,8 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2248
2289
|
}
|
|
2249
2290
|
}
|
|
2250
2291
|
if (newline >= 0) {
|
|
2251
|
-
const nlHit = scanner.feed(
|
|
2292
|
+
const nlHit = scanner.feed(`
|
|
2293
|
+
`);
|
|
2252
2294
|
if (nlHit >= 0 && !droppingCredential && !lineCredentialHit) {
|
|
2253
2295
|
lineCredentialHit = true;
|
|
2254
2296
|
if (droppingLine) {
|
|
@@ -2266,11 +2308,13 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2266
2308
|
sourceRound = currentLlmRound;
|
|
2267
2309
|
droppingCredential = false;
|
|
2268
2310
|
}
|
|
2269
|
-
if (newline >= 0)
|
|
2311
|
+
if (newline >= 0)
|
|
2312
|
+
closeLine();
|
|
2270
2313
|
}
|
|
2271
2314
|
start = end + 1;
|
|
2272
2315
|
}
|
|
2273
|
-
if (sourceRound === currentLlmRound)
|
|
2316
|
+
if (sourceRound === currentLlmRound)
|
|
2317
|
+
partialUpdatedAt = now().toISOString();
|
|
2274
2318
|
scheduleWrite();
|
|
2275
2319
|
}
|
|
2276
2320
|
function getActivity() {
|
|
@@ -2281,43 +2325,47 @@ function createRunActivityTracker(runId, deps = {}, options = {}) {
|
|
|
2281
2325
|
}
|
|
2282
2326
|
function dispose() {
|
|
2283
2327
|
disposed = true;
|
|
2284
|
-
if (writeTimer !==
|
|
2328
|
+
if (writeTimer !== undefined) {
|
|
2285
2329
|
clearTimeout(writeTimer);
|
|
2286
|
-
writeTimer =
|
|
2330
|
+
writeTimer = undefined;
|
|
2287
2331
|
}
|
|
2288
2332
|
}
|
|
2289
2333
|
return { onLoopEvent, onPartialText, getActivity, flush, dispose };
|
|
2290
2334
|
}
|
|
2291
2335
|
function parseRunRecord(text, runId) {
|
|
2292
2336
|
const record = JSON.parse(text);
|
|
2293
|
-
if (record === null || typeof record !== "object" || !runId || !("runId" in record) || record.runId !== runId)
|
|
2337
|
+
if (record === null || typeof record !== "object" || !runId || !("runId" in record) || record.runId !== runId)
|
|
2338
|
+
return null;
|
|
2294
2339
|
return record;
|
|
2295
2340
|
}
|
|
2296
|
-
function
|
|
2341
|
+
function readRunRecord2(runId, deps = {}) {
|
|
2297
2342
|
const fs = deps.fs ?? nodeFs2;
|
|
2298
2343
|
const path = resolveRunRecordPath(runId, deps.env, deps.homedir);
|
|
2299
|
-
for (let attempt = 0;
|
|
2344
|
+
for (let attempt = 0;attempt < 2; attempt += 1) {
|
|
2300
2345
|
try {
|
|
2301
2346
|
return parseRunRecord(fs.readFileSync(path, "utf8"), runId);
|
|
2302
2347
|
} catch {
|
|
2303
|
-
if (attempt === 1)
|
|
2348
|
+
if (attempt === 1)
|
|
2349
|
+
return null;
|
|
2304
2350
|
}
|
|
2305
2351
|
}
|
|
2306
2352
|
return null;
|
|
2307
2353
|
}
|
|
2308
|
-
function
|
|
2309
|
-
if (!parentDialogId)
|
|
2354
|
+
function backfillRunRecordParentDialog2(runId, parentDialogId, deps = {}) {
|
|
2355
|
+
if (!parentDialogId)
|
|
2356
|
+
return false;
|
|
2310
2357
|
const updated = withRunRecordLock(runId, deps, () => {
|
|
2311
|
-
const record =
|
|
2312
|
-
if (!record || record.parentDialogId)
|
|
2358
|
+
const record = readRunRecord2(runId, deps);
|
|
2359
|
+
if (!record || record.parentDialogId)
|
|
2360
|
+
return false;
|
|
2313
2361
|
writeRunRecord({ ...record, parentDialogId }, deps);
|
|
2314
2362
|
return true;
|
|
2315
2363
|
});
|
|
2316
2364
|
return updated === true;
|
|
2317
2365
|
}
|
|
2318
|
-
function
|
|
2366
|
+
function listRunRecords2(deps = {}) {
|
|
2319
2367
|
const fs = deps.fs ?? nodeFs2;
|
|
2320
|
-
const dir =
|
|
2368
|
+
const dir = resolveRunsDir2(deps.env, deps.homedir);
|
|
2321
2369
|
let entries = [];
|
|
2322
2370
|
try {
|
|
2323
2371
|
entries = fs.readdirSync(dir);
|
|
@@ -2326,20 +2374,21 @@ function listRunRecords(deps = {}) {
|
|
|
2326
2374
|
}
|
|
2327
2375
|
const records = [];
|
|
2328
2376
|
for (const entry of entries) {
|
|
2329
|
-
if (!entry.endsWith(".json"))
|
|
2377
|
+
if (!entry.endsWith(".json"))
|
|
2378
|
+
continue;
|
|
2330
2379
|
const runId = entry.slice(0, -".json".length);
|
|
2331
|
-
const record =
|
|
2332
|
-
if (record)
|
|
2380
|
+
const record = readRunRecord2(runId, deps);
|
|
2381
|
+
if (record)
|
|
2382
|
+
records.push(record);
|
|
2333
2383
|
}
|
|
2334
|
-
return records.sort(
|
|
2335
|
-
(a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
|
|
2336
|
-
);
|
|
2384
|
+
return records.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());
|
|
2337
2385
|
}
|
|
2338
|
-
function
|
|
2386
|
+
function listRecentRunRecords2(deps = {}) {
|
|
2339
2387
|
const limit = deps.limit ?? 400;
|
|
2340
|
-
if (!Number.isFinite(limit) || limit <= 0)
|
|
2388
|
+
if (!Number.isFinite(limit) || limit <= 0)
|
|
2389
|
+
return [];
|
|
2341
2390
|
const fs = deps.fs ?? nodeFs2;
|
|
2342
|
-
const dir =
|
|
2391
|
+
const dir = resolveRunsDir2(deps.env, deps.homedir);
|
|
2343
2392
|
let entries = [];
|
|
2344
2393
|
try {
|
|
2345
2394
|
entries = fs.readdirSync(dir);
|
|
@@ -2362,17 +2411,17 @@ function listRecentRunRecords(deps = {}) {
|
|
|
2362
2411
|
const candidates = timestampedRuns.length >= limit ? timestampedRuns : [...timestampedRuns, ...customRuns.sort((a, b) => a < b ? 1 : a > b ? -1 : 0)];
|
|
2363
2412
|
const records = [];
|
|
2364
2413
|
for (const entry of candidates) {
|
|
2365
|
-
if (records.length >= limit)
|
|
2414
|
+
if (records.length >= limit)
|
|
2415
|
+
break;
|
|
2366
2416
|
const runId = entry.slice(0, -".json".length);
|
|
2367
|
-
const record =
|
|
2368
|
-
if (record)
|
|
2417
|
+
const record = readRunRecord2(runId, deps);
|
|
2418
|
+
if (record)
|
|
2419
|
+
records.push(record);
|
|
2369
2420
|
}
|
|
2370
|
-
return records.sort(
|
|
2371
|
-
(a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
|
|
2372
|
-
);
|
|
2421
|
+
return records.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());
|
|
2373
2422
|
}
|
|
2374
|
-
async function
|
|
2375
|
-
const dir =
|
|
2423
|
+
async function listRunRecordsAsync2(deps = {}) {
|
|
2424
|
+
const dir = resolveRunsDir2(deps.env, deps.homedir);
|
|
2376
2425
|
let entries;
|
|
2377
2426
|
try {
|
|
2378
2427
|
entries = await nodeFs2.promises.readdir(dir);
|
|
@@ -2385,15 +2434,15 @@ async function listRunRecordsAsync(deps = {}) {
|
|
|
2385
2434
|
while (next < entries.length) {
|
|
2386
2435
|
const index = next++;
|
|
2387
2436
|
const entry = entries[index];
|
|
2388
|
-
if (!entry.endsWith(".json"))
|
|
2437
|
+
if (!entry.endsWith(".json"))
|
|
2438
|
+
continue;
|
|
2389
2439
|
const runId = entry.slice(0, -5);
|
|
2390
2440
|
const path = resolveRunRecordPath(runId, deps.env, deps.homedir);
|
|
2391
|
-
for (let attempt = 0;
|
|
2441
|
+
for (let attempt = 0;attempt < 2; attempt++) {
|
|
2392
2442
|
try {
|
|
2393
|
-
records[index] = parseRunRecord(await nodeFs2.promises.readFile(path, "utf8"), runId) ??
|
|
2443
|
+
records[index] = parseRunRecord(await nodeFs2.promises.readFile(path, "utf8"), runId) ?? undefined;
|
|
2394
2444
|
break;
|
|
2395
|
-
} catch {
|
|
2396
|
-
}
|
|
2445
|
+
} catch {}
|
|
2397
2446
|
}
|
|
2398
2447
|
}
|
|
2399
2448
|
};
|
|
@@ -2401,46 +2450,50 @@ async function listRunRecordsAsync(deps = {}) {
|
|
|
2401
2450
|
return records.filter((record) => Boolean(record)).sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());
|
|
2402
2451
|
}
|
|
2403
2452
|
function findRunRecordByPid(pid, deps = {}) {
|
|
2404
|
-
return
|
|
2453
|
+
return listRunRecords2(deps).find((record) => record.pid === pid);
|
|
2405
2454
|
}
|
|
2406
|
-
function
|
|
2455
|
+
function findRunRecord2(target, deps = {}) {
|
|
2407
2456
|
if (/^\d+$/.test(target)) {
|
|
2408
2457
|
const pid = Number(target);
|
|
2409
2458
|
const byPid = findRunRecordByPid(pid, deps);
|
|
2410
|
-
if (byPid)
|
|
2459
|
+
if (byPid)
|
|
2460
|
+
return byPid;
|
|
2411
2461
|
}
|
|
2412
|
-
return
|
|
2462
|
+
return readRunRecord2(target, deps) ?? undefined;
|
|
2413
2463
|
}
|
|
2414
2464
|
var DEFAULT_LIST_LIMIT = 20;
|
|
2415
2465
|
var MAX_LIST_LIMIT = 200;
|
|
2416
2466
|
function parseStatusFilter(status) {
|
|
2417
2467
|
if (typeof status !== "string" || status.trim() === "" || status === "all") {
|
|
2418
|
-
return
|
|
2468
|
+
return;
|
|
2419
2469
|
}
|
|
2420
2470
|
const parts = status.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
2421
|
-
return parts.length > 0 ? new Set(parts) :
|
|
2471
|
+
return parts.length > 0 ? new Set(parts) : undefined;
|
|
2422
2472
|
}
|
|
2423
2473
|
function clampLimit(limit) {
|
|
2424
2474
|
if (typeof limit !== "number" || !Number.isFinite(limit) || limit <= 0) {
|
|
2425
2475
|
return DEFAULT_LIST_LIMIT;
|
|
2426
2476
|
}
|
|
2427
2477
|
const floored = Math.floor(limit);
|
|
2428
|
-
if (floored > MAX_LIST_LIMIT)
|
|
2429
|
-
|
|
2478
|
+
if (floored > MAX_LIST_LIMIT)
|
|
2479
|
+
return MAX_LIST_LIMIT;
|
|
2480
|
+
if (floored < 1)
|
|
2481
|
+
return 1;
|
|
2430
2482
|
return floored;
|
|
2431
2483
|
}
|
|
2432
|
-
function
|
|
2433
|
-
let records =
|
|
2434
|
-
records = records.map(
|
|
2435
|
-
(record) => record.status === "running" ? checkStaleRun(record.runId, deps) ?? record : record
|
|
2436
|
-
);
|
|
2484
|
+
function queryRunRecords2(query, deps = {}) {
|
|
2485
|
+
let records = listRunRecords2(deps);
|
|
2486
|
+
records = records.map((record) => record.status === "running" ? checkStaleRun2(record.runId, deps) ?? record : record);
|
|
2437
2487
|
const statusSet = parseStatusFilter(query.status);
|
|
2438
|
-
const batchId = typeof query.batchId === "string" && query.batchId.trim() !== "" ? query.batchId.trim() :
|
|
2439
|
-
const parentDialogId = typeof query.parentDialogId === "string" && query.parentDialogId.trim() !== "" ? query.parentDialogId.trim() :
|
|
2488
|
+
const batchId = typeof query.batchId === "string" && query.batchId.trim() !== "" ? query.batchId.trim() : undefined;
|
|
2489
|
+
const parentDialogId = typeof query.parentDialogId === "string" && query.parentDialogId.trim() !== "" ? query.parentDialogId.trim() : undefined;
|
|
2440
2490
|
const filtered = records.filter((record) => {
|
|
2441
|
-
if (batchId && record.batchId !== batchId)
|
|
2442
|
-
|
|
2443
|
-
if (
|
|
2491
|
+
if (batchId && record.batchId !== batchId)
|
|
2492
|
+
return false;
|
|
2493
|
+
if (parentDialogId && record.parentDialogId !== parentDialogId)
|
|
2494
|
+
return false;
|
|
2495
|
+
if (statusSet && !statusSet.has(record.status))
|
|
2496
|
+
return false;
|
|
2444
2497
|
return true;
|
|
2445
2498
|
});
|
|
2446
2499
|
filtered.sort((a, b) => {
|
|
@@ -2458,46 +2511,49 @@ function queryRunRecords(query, deps = {}) {
|
|
|
2458
2511
|
const hasMore = offset + sliced.length < total;
|
|
2459
2512
|
return { runs: sliced, total, hasMore };
|
|
2460
2513
|
}
|
|
2461
|
-
var DEFAULT_GC_RETENTION_MS = 7 * 24 * 60 * 60 *
|
|
2462
|
-
async function
|
|
2514
|
+
var DEFAULT_GC_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
2515
|
+
async function gcRunRecords2(deps = {}, options = {}) {
|
|
2463
2516
|
const fs = deps.fs ?? nodeFs2;
|
|
2464
|
-
const now = (deps.now ?? (() =>
|
|
2517
|
+
const now = (deps.now ?? (() => new Date))();
|
|
2465
2518
|
const nowMs = now instanceof Date ? now.getTime() : Date.parse(String(now));
|
|
2466
2519
|
const retentionMs = typeof options.retentionMs === "number" && options.retentionMs >= 0 ? options.retentionMs : DEFAULT_GC_RETENTION_MS;
|
|
2467
|
-
const records =
|
|
2520
|
+
const records = listRunRecords2(deps);
|
|
2468
2521
|
const sweptIds = [];
|
|
2469
2522
|
const failedIds = [];
|
|
2470
2523
|
for (const record of records) {
|
|
2471
|
-
if (!
|
|
2472
|
-
|
|
2524
|
+
if (!isRunTerminalStatus2(record.status))
|
|
2525
|
+
continue;
|
|
2526
|
+
if (localWriterStillOwns(record, deps))
|
|
2527
|
+
continue;
|
|
2473
2528
|
if (!/^[A-Za-z0-9._-]{1,128}$/.test(record.runId) || record.runId === "." || record.runId === "..") {
|
|
2474
2529
|
failedIds.push(record.runId);
|
|
2475
2530
|
continue;
|
|
2476
2531
|
}
|
|
2477
2532
|
const ts = record.reconciledAt ?? record.endedAt ?? record.startedAt;
|
|
2478
2533
|
const ageMs = nowMs - new Date(ts).getTime();
|
|
2479
|
-
if (!Number.isFinite(ageMs) || ageMs < retentionMs)
|
|
2534
|
+
if (!Number.isFinite(ageMs) || ageMs < retentionMs)
|
|
2535
|
+
continue;
|
|
2480
2536
|
if (fs.existsSync(`${resolveRunRecordPath(record.runId, deps.env, deps.homedir)}.lock`)) {
|
|
2481
2537
|
failedIds.push(record.runId);
|
|
2482
2538
|
continue;
|
|
2483
2539
|
}
|
|
2484
2540
|
const jsonPath = resolveRunRecordPath(record.runId, deps.env, deps.homedir);
|
|
2485
2541
|
const logPath = resolveRunLogPath(record.runId, deps.env, deps.homedir);
|
|
2486
|
-
const queuePath = record.queuePath ??
|
|
2487
|
-
const msgPath = record.msgFile ?? join2(
|
|
2542
|
+
const queuePath = record.queuePath ?? resolveRunQueuePath2(record.runId, deps.env, deps.homedir);
|
|
2543
|
+
const msgPath = record.msgFile ?? join2(resolveRunsDir2(deps.env, deps.homedir), `${record.runId}.msg.md`);
|
|
2488
2544
|
const logOk = tryUnlinkFile(fs, logPath);
|
|
2489
2545
|
const msgOk = tryUnlinkFile(fs, msgPath);
|
|
2490
2546
|
let queueOk = true;
|
|
2491
2547
|
if (fs.existsSync(queuePath)) {
|
|
2492
2548
|
try {
|
|
2493
|
-
await
|
|
2549
|
+
await withQueueLock2(queuePath, deps, () => {
|
|
2494
2550
|
tryUnlinkFile(fs, queuePath);
|
|
2495
2551
|
});
|
|
2496
2552
|
} catch {
|
|
2497
2553
|
queueOk = false;
|
|
2498
2554
|
}
|
|
2499
2555
|
}
|
|
2500
|
-
const runsDirForLegacy =
|
|
2556
|
+
const runsDirForLegacy = resolveRunsDir2(deps.env, deps.homedir);
|
|
2501
2557
|
tryUnlinkFile(fs, join2(runsDirForLegacy, `${record.runId}.report.md`));
|
|
2502
2558
|
tryUnlinkFile(fs, join2(runsDirForLegacy, `${record.runId}.report.json`));
|
|
2503
2559
|
let resultOk = false;
|
|
@@ -2509,20 +2565,24 @@ async function gcRunRecords(deps = {}, options = {}) {
|
|
|
2509
2565
|
const prefix = `${record.runId}.result.md.`;
|
|
2510
2566
|
const name = artifact.path.slice(join2(runsDirForLegacy, prefix).length);
|
|
2511
2567
|
const uuid = "[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
|
|
2512
|
-
if (artifact.publisher !== "run-result-v1" || !/^[A-Za-z0-9._-]+$/.test(record.runId) || !["pending", "bak"].includes(artifact.kind) || !new RegExp(`^${uuid}\\.${artifact.kind}$`).test(name) || artifact.path !== join2(runsDirForLegacy, prefix + name))
|
|
2513
|
-
|
|
2568
|
+
if (artifact.publisher !== "run-result-v1" || !/^[A-Za-z0-9._-]+$/.test(record.runId) || !["pending", "bak"].includes(artifact.kind) || !new RegExp(`^${uuid}\\.${artifact.kind}$`).test(name) || artifact.path !== join2(runsDirForLegacy, prefix + name))
|
|
2569
|
+
throw new Error("unsafe artifact ownership");
|
|
2570
|
+
if (!fs.existsSync(artifact.path))
|
|
2571
|
+
continue;
|
|
2514
2572
|
const stat = fs.lstatSync?.(artifact.path);
|
|
2515
2573
|
if (!stat || !stat.isFile() || stat.isSymbolicLink() || fs.realpathSync?.(artifact.path) !== resolve(artifact.path) || String(stat.dev) !== artifact.dev || String(stat.ino) !== artifact.ino || createHash2("sha256").update(fs.readFileSync(artifact.path)).digest("hex") !== artifact.sha256) {
|
|
2516
2574
|
throw new Error("artifact identity changed");
|
|
2517
2575
|
}
|
|
2518
|
-
if (!tryUnlinkFile(fs, artifact.path))
|
|
2576
|
+
if (!tryUnlinkFile(fs, artifact.path))
|
|
2577
|
+
artifactsOk = false;
|
|
2519
2578
|
} catch {
|
|
2520
2579
|
artifactsOk = false;
|
|
2521
2580
|
}
|
|
2522
2581
|
}
|
|
2523
2582
|
return true;
|
|
2524
2583
|
}, { strict: true });
|
|
2525
|
-
if (!artifactSweep)
|
|
2584
|
+
if (!artifactSweep)
|
|
2585
|
+
artifactsOk = false;
|
|
2526
2586
|
if (!logOk || !msgOk || !queueOk || !resultOk || !artifactsOk) {
|
|
2527
2587
|
failedIds.push(record.runId);
|
|
2528
2588
|
continue;
|
|
@@ -2535,27 +2595,29 @@ async function gcRunRecords(deps = {}, options = {}) {
|
|
|
2535
2595
|
}
|
|
2536
2596
|
}
|
|
2537
2597
|
try {
|
|
2538
|
-
const dir =
|
|
2539
|
-
const
|
|
2598
|
+
const dir = resolveRunsDir2(deps.env, deps.homedir);
|
|
2599
|
+
const statSync = fs.statSync;
|
|
2540
2600
|
for (const entry of fs.readdirSync(dir)) {
|
|
2541
|
-
if (typeof entry !== "string" || !entry.endsWith(".tmp"))
|
|
2601
|
+
if (typeof entry !== "string" || !entry.endsWith(".tmp"))
|
|
2602
|
+
continue;
|
|
2542
2603
|
const tmpPath = join2(dir, entry);
|
|
2543
2604
|
try {
|
|
2544
|
-
const stat =
|
|
2545
|
-
if (stat && nowMs - stat.mtimeMs <= TMP_STALE_MS)
|
|
2605
|
+
const stat = statSync?.(tmpPath);
|
|
2606
|
+
if (stat && nowMs - stat.mtimeMs <= TMP_STALE_MS)
|
|
2607
|
+
continue;
|
|
2546
2608
|
} catch {
|
|
2547
2609
|
continue;
|
|
2548
2610
|
}
|
|
2549
2611
|
tryUnlinkFile(fs, tmpPath);
|
|
2550
2612
|
}
|
|
2551
|
-
} catch {
|
|
2552
|
-
}
|
|
2613
|
+
} catch {}
|
|
2553
2614
|
return { swept: sweptIds.length, sweptIds, failedIds };
|
|
2554
2615
|
}
|
|
2555
2616
|
function stripBackgroundFlag(args) {
|
|
2556
2617
|
const result = [];
|
|
2557
2618
|
for (const arg of args) {
|
|
2558
|
-
if (arg === "--bg" || arg.startsWith("--bg="))
|
|
2619
|
+
if (arg === "--bg" || arg.startsWith("--bg="))
|
|
2620
|
+
continue;
|
|
2559
2621
|
result.push(arg);
|
|
2560
2622
|
}
|
|
2561
2623
|
return result;
|
|
@@ -2563,11 +2625,12 @@ function stripBackgroundFlag(args) {
|
|
|
2563
2625
|
function absolutizeSkillArgs(args, baseCwd = process.cwd()) {
|
|
2564
2626
|
const result = [];
|
|
2565
2627
|
const resolveIfPath = (value) => {
|
|
2566
|
-
if (isAbsolute2(value))
|
|
2628
|
+
if (isAbsolute2(value))
|
|
2629
|
+
return value;
|
|
2567
2630
|
const looksLikePath = value.includes("/") || value.endsWith(".md");
|
|
2568
2631
|
return looksLikePath ? resolve(baseCwd, value) : value;
|
|
2569
2632
|
};
|
|
2570
|
-
for (let i = 0;
|
|
2633
|
+
for (let i = 0;i < args.length; i++) {
|
|
2571
2634
|
const arg = args[i];
|
|
2572
2635
|
if (arg === "--skill" && typeof args[i + 1] === "string") {
|
|
2573
2636
|
result.push(arg, resolveIfPath(args[i + 1]));
|
|
@@ -2585,7 +2648,7 @@ function absolutizeSkillArgs(args, baseCwd = process.cwd()) {
|
|
|
2585
2648
|
}
|
|
2586
2649
|
function rewriteMsgFileArg(args, messagePath) {
|
|
2587
2650
|
const result = [];
|
|
2588
|
-
for (let i = 0;
|
|
2651
|
+
for (let i = 0;i < args.length; i++) {
|
|
2589
2652
|
const arg = args[i];
|
|
2590
2653
|
if (arg === "--msg-file" && typeof args[i + 1] === "string") {
|
|
2591
2654
|
result.push(arg, messagePath);
|
|
@@ -2601,8 +2664,9 @@ function rewriteMsgFileArg(args, messagePath) {
|
|
|
2601
2664
|
return result;
|
|
2602
2665
|
}
|
|
2603
2666
|
function resolveValidCliEntrypoint(cliEntrypointPath, fs = nodeFs2) {
|
|
2604
|
-
const entrypoint = cliEntrypointPath ??
|
|
2605
|
-
if (!fs.existsSync(entrypoint))
|
|
2667
|
+
const entrypoint = cliEntrypointPath ?? resolveCliEntrypointPath2();
|
|
2668
|
+
if (!fs.existsSync(entrypoint))
|
|
2669
|
+
throw new RuntimeVersionMismatchError("runtime entrypoint missing");
|
|
2606
2670
|
return fs === nodeFs2 ? resolveExactRuntimeEntrypoint(entrypoint) : String(fs.realpathSync?.(entrypoint) ?? entrypoint);
|
|
2607
2671
|
}
|
|
2608
2672
|
function buildAgentRunChildCommand(options, deps = {}) {
|
|
@@ -2614,8 +2678,8 @@ function buildAgentRunChildCommand(options, deps = {}) {
|
|
|
2614
2678
|
strippedArgs = rewriteMsgFileArg(strippedArgs, options.messagePath);
|
|
2615
2679
|
}
|
|
2616
2680
|
strippedArgs = absolutizeSkillArgs(strippedArgs);
|
|
2617
|
-
if (
|
|
2618
|
-
const fixed = resolveValidCliEntrypoint(
|
|
2681
|
+
if (isCompiledBinary2() || options.cliEntrypointPath === process.execPath || options.cliEntrypointPath === execPath) {
|
|
2682
|
+
const fixed = resolveValidCliEntrypoint(isCompiledBinary2() ? execPath : options.cliEntrypointPath ?? execPath, fs);
|
|
2619
2683
|
return { execPath: fixed, childArgs: [...commandParts, ...strippedArgs] };
|
|
2620
2684
|
}
|
|
2621
2685
|
const entrypoint = resolveValidCliEntrypoint(options.cliEntrypointPath, fs);
|
|
@@ -2625,12 +2689,13 @@ function buildAgentRunChildCommand(options, deps = {}) {
|
|
|
2625
2689
|
return { execPath, childArgs: [entrypoint, ...commandParts, ...strippedArgs] };
|
|
2626
2690
|
}
|
|
2627
2691
|
function emitHostMemoryNotice(mem, output) {
|
|
2628
|
-
if (!mem || !output)
|
|
2692
|
+
if (!mem || !output)
|
|
2693
|
+
return;
|
|
2629
2694
|
let notice;
|
|
2630
2695
|
try {
|
|
2631
2696
|
notice = formatHostMemoryLine(mem);
|
|
2632
2697
|
} catch {
|
|
2633
|
-
return
|
|
2698
|
+
return;
|
|
2634
2699
|
}
|
|
2635
2700
|
try {
|
|
2636
2701
|
output.write(`${notice}
|
|
@@ -2644,44 +2709,57 @@ function trustedLocalWorktree(cwd, deps) {
|
|
|
2644
2709
|
const fs = deps.fs ?? nodeFs2;
|
|
2645
2710
|
try {
|
|
2646
2711
|
const env = { ...process.env, ...deps.env };
|
|
2647
|
-
for (const key of Object.keys(env))
|
|
2712
|
+
for (const key of Object.keys(env))
|
|
2713
|
+
if (key.startsWith("GIT_"))
|
|
2714
|
+
delete env[key];
|
|
2648
2715
|
const exec = deps.execFileSync ?? nodeExecFileSync;
|
|
2649
2716
|
const git = (args) => exec("git", args, {
|
|
2650
2717
|
cwd,
|
|
2651
2718
|
env,
|
|
2652
2719
|
encoding: "utf8",
|
|
2653
2720
|
stdio: ["ignore", "pipe", "ignore"],
|
|
2654
|
-
timeout:
|
|
2721
|
+
timeout: 3000
|
|
2655
2722
|
}).trim();
|
|
2656
2723
|
const real = (path) => String((fs.realpathSync ?? nodeFs2.realpathSync)(path));
|
|
2657
|
-
const [dir, top, common] = git(["rev-parse", "--path-format=absolute", "--git-dir", "--show-toplevel", "--git-common-dir"]).split(
|
|
2658
|
-
|
|
2724
|
+
const [dir, top, common] = git(["rev-parse", "--path-format=absolute", "--git-dir", "--show-toplevel", "--git-common-dir"]).split(`
|
|
2725
|
+
`);
|
|
2726
|
+
if (!dir || !top || !common || ![dir, top, common].every(isAbsolute2))
|
|
2727
|
+
return;
|
|
2659
2728
|
const root = real(top), gitDir = real(dir), commonDir = real(common);
|
|
2660
2729
|
const marker = join2(root, ".git");
|
|
2661
2730
|
const stat = (path) => (fs.lstatSync ?? nodeFs2.lstatSync)(path);
|
|
2662
|
-
if (stat(marker).isSymbolicLink() || stat(commonDir).isSymbolicLink())
|
|
2731
|
+
if (stat(marker).isSymbolicLink() || stat(commonDir).isSymbolicLink())
|
|
2732
|
+
return;
|
|
2663
2733
|
if (gitDir === commonDir) {
|
|
2664
|
-
if (!stat(marker).isDirectory() || real(marker) !== commonDir)
|
|
2734
|
+
if (!stat(marker).isDirectory() || real(marker) !== commonDir)
|
|
2735
|
+
return;
|
|
2665
2736
|
} else {
|
|
2666
2737
|
const registry = join2(commonDir, "worktrees");
|
|
2667
|
-
if (stat(registry).isSymbolicLink() || dirname(gitDir) !== real(registry) || !stat(gitDir).isDirectory() || stat(gitDir).isSymbolicLink() || !stat(marker).isFile())
|
|
2738
|
+
if (stat(registry).isSymbolicLink() || dirname(gitDir) !== real(registry) || !stat(gitDir).isDirectory() || stat(gitDir).isSymbolicLink() || !stat(marker).isFile())
|
|
2739
|
+
return;
|
|
2668
2740
|
const text = String(fs.readFileSync(marker, "utf8")).trim();
|
|
2669
|
-
if (!text.startsWith("gitdir: ") || real(resolve(root, text.slice(8))) !== gitDir)
|
|
2741
|
+
if (!text.startsWith("gitdir: ") || real(resolve(root, text.slice(8))) !== gitDir)
|
|
2742
|
+
return;
|
|
2670
2743
|
const back = String(fs.readFileSync(join2(gitDir, "gitdir"), "utf8")).trim();
|
|
2671
2744
|
const commonBack = String(fs.readFileSync(join2(gitDir, "commondir"), "utf8")).trim();
|
|
2672
|
-
if (real(resolve(gitDir, back)) !== real(marker) || real(resolve(gitDir, commonBack)) !== commonDir)
|
|
2745
|
+
if (real(resolve(gitDir, back)) !== real(marker) || real(resolve(gitDir, commonBack)) !== commonDir)
|
|
2746
|
+
return;
|
|
2673
2747
|
}
|
|
2674
|
-
const registered = git(["worktree", "list", "--porcelain"]).split(
|
|
2675
|
-
|
|
2748
|
+
const registered = git(["worktree", "list", "--porcelain"]).split(`
|
|
2749
|
+
`).filter((line) => line.startsWith("worktree ")).map((line) => line.slice(9));
|
|
2750
|
+
if (!registered.some((path) => real(path) === root))
|
|
2751
|
+
return;
|
|
2676
2752
|
const mainMarker = registered[0] && join2(registered[0], ".git");
|
|
2677
|
-
if (!mainMarker || stat(mainMarker).isSymbolicLink() || !stat(mainMarker).isDirectory() || real(mainMarker) !== commonDir)
|
|
2753
|
+
if (!mainMarker || stat(mainMarker).isSymbolicLink() || !stat(mainMarker).isDirectory() || real(mainMarker) !== commonDir)
|
|
2754
|
+
return;
|
|
2678
2755
|
return { root, gitDir, commonDir };
|
|
2679
2756
|
} catch {
|
|
2680
2757
|
return;
|
|
2681
2758
|
}
|
|
2682
2759
|
}
|
|
2683
|
-
function
|
|
2684
|
-
if (record.localWriterClaim?.state !== "held" || typeof record.pid === "number" && record.pid > 0)
|
|
2760
|
+
function localWriterRecovery2(record) {
|
|
2761
|
+
if (record.localWriterClaim?.state !== "held" || typeof record.pid === "number" && record.pid > 0)
|
|
2762
|
+
return;
|
|
2685
2763
|
return {
|
|
2686
2764
|
state: "required",
|
|
2687
2765
|
reason: "owner-unpublished",
|
|
@@ -2691,18 +2769,24 @@ function localWriterRecovery(record) {
|
|
|
2691
2769
|
requiredEvidence: "native launch receipt proving no live child; parent death/timeouts/process-name search are insufficient"
|
|
2692
2770
|
};
|
|
2693
2771
|
}
|
|
2694
|
-
function
|
|
2695
|
-
if (!/^[A-Za-z0-9_-]+$/.test(runId) || !attemptId)
|
|
2772
|
+
function revokePreparedWriterLaunch2(runId, attemptId, deps = {}) {
|
|
2773
|
+
if (!/^[A-Za-z0-9_-]+$/.test(runId) || !attemptId)
|
|
2774
|
+
return "blocked";
|
|
2696
2775
|
return withRunRecordLock("local-writer-admission", deps, () => {
|
|
2697
|
-
const
|
|
2698
|
-
if (!
|
|
2776
|
+
const snapshot = readRunRecord2(runId, deps);
|
|
2777
|
+
if (!snapshot)
|
|
2778
|
+
return "blocked";
|
|
2699
2779
|
return withRunRecordLock(runId, deps, () => {
|
|
2700
|
-
const latest =
|
|
2701
|
-
if (!latest || JSON.stringify(latest) !== JSON.stringify(
|
|
2780
|
+
const latest = readRunRecord2(runId, deps);
|
|
2781
|
+
if (!latest || JSON.stringify(latest) !== JSON.stringify(snapshot))
|
|
2782
|
+
return "blocked";
|
|
2702
2783
|
const launch = latest.writerLaunch;
|
|
2703
|
-
if (launch?.protocol !== "fenced-launch-v1" || launch.attemptId !== attemptId)
|
|
2704
|
-
|
|
2705
|
-
if (launch.phase
|
|
2784
|
+
if (launch?.protocol !== "fenced-launch-v1" || launch.attemptId !== attemptId)
|
|
2785
|
+
return "blocked";
|
|
2786
|
+
if (launch.phase === "revoked")
|
|
2787
|
+
return latest.localWriterClaim?.state === "released" ? "already-revoked" : "blocked";
|
|
2788
|
+
if (launch.phase !== "prepared" || latest.localWriterClaim?.state !== "held" || latest.execution?.state !== "known" || latest.execution.owner.state !== "unknown" || latest.execution.canonicalCwd !== latest.localWriterClaim.cwd || latest.pid !== undefined || latest.cwd !== latest.localWriterClaim.cwd || latest.execution.kind !== "host-local" || latest.execution.permissions.readOnly || !latest.execution.permissions.hostWritesAuthorized)
|
|
2789
|
+
return "blocked";
|
|
2706
2790
|
launch.phase = "revoked";
|
|
2707
2791
|
latest.localWriterClaim.state = "released";
|
|
2708
2792
|
writeRunRecord(latest, deps);
|
|
@@ -2711,16 +2795,20 @@ function revokePreparedWriterLaunch(runId, attemptId, deps = {}) {
|
|
|
2711
2795
|
}, { strict: true, requireDeadOwner: true }) ?? "blocked";
|
|
2712
2796
|
}
|
|
2713
2797
|
function localWriterStillOwns(record, deps) {
|
|
2714
|
-
if (record.localWriterClaim?.state !== "held")
|
|
2715
|
-
|
|
2798
|
+
if (record.localWriterClaim?.state !== "held")
|
|
2799
|
+
return false;
|
|
2800
|
+
if (typeof record.pid !== "number" || record.pid <= 0)
|
|
2801
|
+
return true;
|
|
2716
2802
|
const e = record.execution;
|
|
2717
|
-
const observed = e?.state === "known" && e.owner.state === "verified" ? nativeOwner(record.pid, deps) :
|
|
2803
|
+
const observed = e?.state === "known" && e.owner.state === "verified" ? nativeOwner(record.pid, deps) : undefined;
|
|
2718
2804
|
const reused = observed?.state === "verified" && e?.state === "known" && e.owner.state === "verified" && (observed.startedAt !== e.owner.startedAt || (observed.linux?.bootId !== e.owner.linux?.bootId || observed.linux?.startTicks !== e.owner.linux?.startTicks));
|
|
2719
|
-
if (!
|
|
2720
|
-
|
|
2805
|
+
if (!isPidGone2(record.pid, deps) && !reused)
|
|
2806
|
+
return true;
|
|
2807
|
+
const snapshot = JSON.stringify(record);
|
|
2721
2808
|
const released = withRunRecordLock(record.runId, deps, () => {
|
|
2722
|
-
const latest =
|
|
2723
|
-
if (!latest || JSON.stringify(latest) !==
|
|
2809
|
+
const latest = readRunRecord2(record.runId, deps);
|
|
2810
|
+
if (!latest || JSON.stringify(latest) !== snapshot)
|
|
2811
|
+
return false;
|
|
2724
2812
|
latest.localWriterClaim.state = "released";
|
|
2725
2813
|
writeRunRecord(latest, deps);
|
|
2726
2814
|
return true;
|
|
@@ -2729,25 +2817,29 @@ function localWriterStillOwns(record, deps) {
|
|
|
2729
2817
|
}
|
|
2730
2818
|
function acquireLocalWriterClaim(runId, cwd, deps) {
|
|
2731
2819
|
const fs = deps.fs ?? nodeFs2;
|
|
2732
|
-
const
|
|
2733
|
-
const worktree = trustedLocalWorktree(
|
|
2820
|
+
const canonical = String((fs.realpathSync ?? nodeFs2.realpathSync)(cwd));
|
|
2821
|
+
const worktree = trustedLocalWorktree(canonical, deps);
|
|
2734
2822
|
const acquired = withRunRecordLock("local-writer-admission", deps, () => {
|
|
2735
2823
|
const updated = withRunRecordLock(runId, deps, () => {
|
|
2736
|
-
const record =
|
|
2737
|
-
if (!record)
|
|
2738
|
-
|
|
2739
|
-
record.
|
|
2824
|
+
const record = readRunRecord2(runId, deps);
|
|
2825
|
+
if (!record)
|
|
2826
|
+
throw new Error(`[local-writer-resource] missing run ${runId}`);
|
|
2827
|
+
if (record.writerLaunch?.phase === "revoked")
|
|
2828
|
+
throw new Error("[local-writer-resource] claim attempt revoked");
|
|
2829
|
+
record.localWriterClaim = { cwd: canonical, ...worktree ? { worktree } : {}, state: "held" };
|
|
2740
2830
|
if (record.writerLaunch && record.execution?.state === "known" && record.execution.owner.state === "verified" && record.pid === process.pid) {
|
|
2741
2831
|
record.writerLaunch.phase = "granted";
|
|
2742
2832
|
}
|
|
2743
2833
|
writeRunRecord(record, deps);
|
|
2744
2834
|
return true;
|
|
2745
2835
|
}, { strict: true });
|
|
2746
|
-
if (!updated)
|
|
2836
|
+
if (!updated)
|
|
2837
|
+
throw new Error(`[local-writer-resource] run lock busy: ${runId}`);
|
|
2747
2838
|
return true;
|
|
2748
2839
|
}, { strict: true, requireDeadOwner: true });
|
|
2749
|
-
if (!acquired)
|
|
2750
|
-
|
|
2840
|
+
if (!acquired)
|
|
2841
|
+
throw new Error("[local-writer-resource] admission lock busy; no child spawned");
|
|
2842
|
+
return canonical;
|
|
2751
2843
|
}
|
|
2752
2844
|
function nativeOwner(pid, deps) {
|
|
2753
2845
|
const first = probeProcessStartTime(pid, deps);
|
|
@@ -2757,41 +2849,50 @@ function nativeOwner(pid, deps) {
|
|
|
2757
2849
|
const stat = nodeFs2.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
2758
2850
|
const startTicks = stat.slice(stat.lastIndexOf(")") + 2).split(/\s+/)[19];
|
|
2759
2851
|
const bootId = nodeFs2.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
|
|
2760
|
-
if (/^\d+$/.test(startTicks) && bootId)
|
|
2852
|
+
if (/^\d+$/.test(startTicks) && bootId)
|
|
2853
|
+
linux = { startTicks, bootId };
|
|
2761
2854
|
} catch {
|
|
2762
2855
|
return { state: "unknown" };
|
|
2763
2856
|
}
|
|
2764
2857
|
}
|
|
2765
2858
|
const second = probeProcessStartTime(pid, deps);
|
|
2766
|
-
if (!first || !second || first.getTime() !== second.getTime() ||
|
|
2859
|
+
if (!first || !second || first.getTime() !== second.getTime() || isPidGone2(pid, deps) || (deps.platform ?? process.platform) === "linux" && !linux)
|
|
2860
|
+
return { state: "unknown" };
|
|
2767
2861
|
return { state: "verified", pid, startedAt: first.toISOString(), source: "parent-native", ...linux ? { linux } : {} };
|
|
2768
2862
|
}
|
|
2769
2863
|
function validateLocalWriterChild(runId, cwd, policy, deps = {}) {
|
|
2770
2864
|
const fail = (reason = "facts") => {
|
|
2771
2865
|
throw new Error(`[local-writer-resource] child binding unknown or mismatched: ${reason}`);
|
|
2772
2866
|
};
|
|
2773
|
-
if (!/^[A-Za-z0-9_-]+$/.test(runId))
|
|
2867
|
+
if (!/^[A-Za-z0-9_-]+$/.test(runId))
|
|
2868
|
+
fail();
|
|
2774
2869
|
const validated = withRunRecordLock(runId, deps, () => {
|
|
2775
|
-
const r =
|
|
2870
|
+
const r = readRunRecord2(runId, deps), e = r?.execution;
|
|
2776
2871
|
const launch = r?.writerLaunch;
|
|
2777
|
-
if (launch && (launch.protocol !== "fenced-launch-v1" || launch.phase !== "granted" || launch.attemptId !== deps.env?.NOLO_WRITER_LAUNCH_ATTEMPT))
|
|
2872
|
+
if (launch && (launch.protocol !== "fenced-launch-v1" || launch.phase !== "granted" || launch.attemptId !== deps.env?.NOLO_WRITER_LAUNCH_ATTEMPT))
|
|
2873
|
+
fail("launch grant missing/revoked");
|
|
2778
2874
|
const native = nativeOwner(process.pid, deps);
|
|
2779
2875
|
const real = String((deps.fs?.realpathSync ?? nodeFs2.realpathSync)(cwd));
|
|
2780
|
-
if (!r || r.runId !== runId || r.pid !== process.pid || r.status !== "running" || e?.state !== "known" || e.kind !== "host-local" || e.runtimeKey !== "local" || e.device.kind !== "localhost" || e.device.hostname !== nodeHostname() || e.device.platform !== process.platform || !["cli-command-authorized", "cli-tool-dispatch-authorized"].includes(e.provenance) || e.owner.state !== "verified" || native.state !== "verified" || e.owner.pid !== process.pid || e.owner.startedAt !== native.startedAt || (e.owner.linux?.bootId !== native.linux?.bootId || e.owner.linux?.startTicks !== native.linux?.startTicks) || r.processIdentity !== "verified" || r.processStartedAt !== e.owner.startedAt || e.canonicalCwd !== real || r.cwd !== real || e.permissions.hostWritesAuthorized !== policy.hostWritesAuthorized || e.permissions.readOnly !== policy.readOnly)
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2876
|
+
if (!r || r.runId !== runId || r.pid !== process.pid || r.status !== "running" || e?.state !== "known" || e.kind !== "host-local" || e.runtimeKey !== "local" || e.device.kind !== "localhost" || e.device.hostname !== nodeHostname() || e.device.platform !== process.platform || !["cli-command-authorized", "cli-tool-dispatch-authorized"].includes(e.provenance) || e.owner.state !== "verified" || native.state !== "verified" || e.owner.pid !== process.pid || e.owner.startedAt !== native.startedAt || (e.owner.linux?.bootId !== native.linux?.bootId || e.owner.linux?.startTicks !== native.linux?.startTicks) || r.processIdentity !== "verified" || r.processStartedAt !== e.owner.startedAt || e.canonicalCwd !== real || r.cwd !== real || e.permissions.hostWritesAuthorized !== policy.hostWritesAuthorized || e.permissions.readOnly !== policy.readOnly)
|
|
2877
|
+
fail("native identity/authorization");
|
|
2878
|
+
if (e?.state !== "known")
|
|
2879
|
+
return fail();
|
|
2880
|
+
const set = (v) => JSON.stringify(v === undefined ? null : [...new Set(v)].sort());
|
|
2881
|
+
if (set(e.permissions.allowedToolNames) !== set(policy.allowedToolNames) || !policy.readOnly && set(e.permissions.blockedToolNames) !== set(policy.blockedToolNames) || JSON.stringify(e.worktree) !== JSON.stringify(trustedLocalWorktree(real, deps)))
|
|
2882
|
+
fail("scope/worktree");
|
|
2883
|
+
if (!policy.readOnly && (!policy.hostWritesAuthorized || r?.localWriterClaim?.state !== "held" || r.localWriterClaim.cwd !== real || e.worktree && (r.localWriterClaim.worktree?.root !== e.worktree.root || r.localWriterClaim.worktree.gitDir !== e.worktree.gitDir)))
|
|
2884
|
+
fail();
|
|
2885
|
+
const blockedToolNames = policy.readOnly ? [...new Set([...e.permissions.blockedToolNames ?? [], ...policy.blockedToolNames ?? []])] : policy.blockedToolNames;
|
|
2786
2886
|
return { blockedToolNames };
|
|
2787
2887
|
}, { strict: true, requireDeadOwner: true });
|
|
2788
2888
|
return validated ?? fail("registry lock busy");
|
|
2789
2889
|
}
|
|
2790
|
-
async function
|
|
2791
|
-
if (!/^[A-Za-z0-9_-]+$/.test(runId))
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2890
|
+
async function awaitLocalWriterChild2(runId, cwd, policy, deps = {}) {
|
|
2891
|
+
if (!/^[A-Za-z0-9_-]+$/.test(runId))
|
|
2892
|
+
throw new Error("[local-writer-resource] child binding invalid id");
|
|
2893
|
+
const deadline = Date.now() + 2000;
|
|
2894
|
+
for (;; ) {
|
|
2895
|
+
const r = readRunRecord2(runId, deps);
|
|
2795
2896
|
const publication = r?.ownerPublication;
|
|
2796
2897
|
if (r?.writerLaunch && (r.writerLaunch.phase === "revoked" || r.writerLaunch.attemptId !== deps.env?.NOLO_WRITER_LAUNCH_ATTEMPT)) {
|
|
2797
2898
|
throw new Error("[local-writer-resource] child binding launch revoked/mismatched");
|
|
@@ -2803,37 +2904,46 @@ async function awaitLocalWriterChild(runId, cwd, policy, deps = {}) {
|
|
|
2803
2904
|
} catch (error) {
|
|
2804
2905
|
const lockBusy = String(error).includes("registry lock busy");
|
|
2805
2906
|
const pending = publication?.state === "pending" && r?.execution?.state === "known" && r.execution.owner.state === "unknown";
|
|
2806
|
-
if (!parentLive || !pending && !lockBusy || Date.now() >= deadline)
|
|
2807
|
-
|
|
2907
|
+
if (!parentLive || !pending && !lockBusy || Date.now() >= deadline)
|
|
2908
|
+
throw error;
|
|
2909
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
2808
2910
|
}
|
|
2809
2911
|
}
|
|
2810
2912
|
}
|
|
2811
|
-
function
|
|
2913
|
+
function resolveLocalContinuation2(record, deps = {}) {
|
|
2812
2914
|
const fail = (why) => {
|
|
2813
2915
|
throw new Error(`[local-continuation] ${why}; dispatch a fresh explicitly authorized run`);
|
|
2814
2916
|
};
|
|
2815
2917
|
const e = record.execution;
|
|
2816
|
-
if (e?.state !== "known" || e.kind !== "host-local" || e.runtimeKey !== "local" || e.device?.kind !== "localhost" || e.device.hostname !== nodeHostname() || e.device.platform !== process.platform || !["cli-command-authorized", "cli-tool-dispatch-authorized"].includes(e.provenance) || typeof e.permissions?.readOnly !== "boolean" || typeof e.permissions.hostWritesAuthorized !== "boolean" || !e.permissions.readOnly && !e.permissions.hostWritesAuthorized)
|
|
2918
|
+
if (e?.state !== "known" || e.kind !== "host-local" || e.runtimeKey !== "local" || e.device?.kind !== "localhost" || e.device.hostname !== nodeHostname() || e.device.platform !== process.platform || !["cli-command-authorized", "cli-tool-dispatch-authorized"].includes(e.provenance) || typeof e.permissions?.readOnly !== "boolean" || typeof e.permissions.hostWritesAuthorized !== "boolean" || !e.permissions.readOnly && !e.permissions.hostWritesAuthorized)
|
|
2919
|
+
return fail("execution unknown or unsupported");
|
|
2817
2920
|
const lists = [e.permissions.allowedToolNames, e.permissions.blockedToolNames];
|
|
2818
|
-
if (lists.some((v) => v !==
|
|
2921
|
+
if (lists.some((v) => v !== undefined && (!Array.isArray(v) || v.some((t) => typeof t !== "string" || !t || t.startsWith("--")))))
|
|
2922
|
+
return fail("tool scope invalid");
|
|
2819
2923
|
let cwd;
|
|
2820
2924
|
try {
|
|
2821
|
-
if (!e.canonicalCwd || !isAbsolute2(e.canonicalCwd) || record.cwd !== e.canonicalCwd)
|
|
2925
|
+
if (!e.canonicalCwd || !isAbsolute2(e.canonicalCwd) || record.cwd !== e.canonicalCwd)
|
|
2926
|
+
return fail("cwd identity missing");
|
|
2822
2927
|
const fs = deps.fs ?? nodeFs2;
|
|
2823
2928
|
cwd = String((fs.realpathSync ?? nodeFs2.realpathSync)(e.canonicalCwd));
|
|
2824
|
-
if (cwd !== e.canonicalCwd || !(fs.statSync ?? nodeFs2.statSync)(cwd).isDirectory())
|
|
2825
|
-
|
|
2929
|
+
if (cwd !== e.canonicalCwd || !(fs.statSync ?? nodeFs2.statSync)(cwd).isDirectory())
|
|
2930
|
+
return fail("cwd drift");
|
|
2931
|
+
if (JSON.stringify(e.worktree) !== JSON.stringify(trustedLocalWorktree(cwd, deps)))
|
|
2932
|
+
return fail("cwd worktree changed");
|
|
2826
2933
|
} catch {
|
|
2827
2934
|
return fail("cwd missing or moved");
|
|
2828
2935
|
}
|
|
2829
2936
|
const death = record.ownerDeath;
|
|
2830
2937
|
const hasDeath = !record.pid && death && death.pid > 0 && JSON.stringify(death.executionOwner) === JSON.stringify(e.owner) && (!record.localWriterClaim || record.localWriterClaim.state === "released");
|
|
2831
|
-
if (!hasDeath && (typeof record.pid !== "number" || record.pid <= 0))
|
|
2938
|
+
if (!hasDeath && (typeof record.pid !== "number" || record.pid <= 0))
|
|
2939
|
+
return fail("old owner unknown");
|
|
2832
2940
|
const current = hasDeath ? { state: "unknown" } : nativeOwner(record.pid, deps);
|
|
2833
2941
|
const old = e.owner;
|
|
2834
2942
|
const reused = old?.state === "verified" && current.state === "verified" && (old.pid !== current.pid || old.startedAt !== current.startedAt || old.linux?.bootId !== current.linux?.bootId || old.linux?.startTicks !== current.linux?.startTicks);
|
|
2835
|
-
if (!hasDeath && !
|
|
2836
|
-
|
|
2943
|
+
if (!hasDeath && !isPidGone2(record.pid, deps) && !reused)
|
|
2944
|
+
return fail("old owner live or unknown");
|
|
2945
|
+
if (!e.permissions.readOnly && (record.localWriterClaim?.cwd !== cwd || !["held", "released"].includes(record.localWriterClaim.state)))
|
|
2946
|
+
return fail("writer claim unknown");
|
|
2837
2947
|
const policy = { runtimeKey: "local", ...e.permissions, provenance: "cli-tool-dispatch-authorized" };
|
|
2838
2948
|
const rawArgs = [
|
|
2839
2949
|
"--runtime-key",
|
|
@@ -2845,22 +2955,22 @@ function resolveLocalContinuation(record, deps = {}) {
|
|
|
2845
2955
|
];
|
|
2846
2956
|
return { cwd, policy, rawArgs };
|
|
2847
2957
|
}
|
|
2848
|
-
function
|
|
2958
|
+
function registerLocalForegroundWriter2(cwd, policy, agentKey, deps = {}) {
|
|
2849
2959
|
const fs = deps.fs ?? nodeFs2;
|
|
2850
|
-
const
|
|
2960
|
+
const canonical = String((fs.realpathSync ?? nodeFs2.realpathSync)(cwd));
|
|
2851
2961
|
const owner = nativeOwner(process.pid, deps);
|
|
2852
2962
|
if (owner.state !== "verified" || policy.readOnly || !policy.hostWritesAuthorized) {
|
|
2853
2963
|
throw new Error("[local-writer-resource] foreground native identity/authorization unknown");
|
|
2854
2964
|
}
|
|
2855
|
-
const runId =
|
|
2856
|
-
fs.mkdirSync(
|
|
2857
|
-
const worktree = trustedLocalWorktree(
|
|
2965
|
+
const runId = defaultGenerateRunId2();
|
|
2966
|
+
fs.mkdirSync(resolveRunsDir2(deps.env, deps.homedir), { recursive: true });
|
|
2967
|
+
const worktree = trustedLocalWorktree(canonical, deps);
|
|
2858
2968
|
const record = {
|
|
2859
2969
|
runId,
|
|
2860
2970
|
agentKey,
|
|
2861
2971
|
writerLaunch: { protocol: "fenced-launch-v1", attemptId: randomUUID3(), phase: "prepared" },
|
|
2862
|
-
cwd:
|
|
2863
|
-
startedAt: (deps.now?.() ??
|
|
2972
|
+
cwd: canonical,
|
|
2973
|
+
startedAt: (deps.now?.() ?? new Date).toISOString(),
|
|
2864
2974
|
status: "running",
|
|
2865
2975
|
logPath: resolveRunLogPath(runId, deps.env, deps.homedir),
|
|
2866
2976
|
pid: process.pid,
|
|
@@ -2870,7 +2980,7 @@ function registerLocalForegroundWriter(cwd, policy, agentKey, deps = {}) {
|
|
|
2870
2980
|
state: "known",
|
|
2871
2981
|
kind: "host-local",
|
|
2872
2982
|
runtimeKey: "local",
|
|
2873
|
-
canonicalCwd:
|
|
2983
|
+
canonicalCwd: canonical,
|
|
2874
2984
|
device: { kind: "localhost", hostname: nodeHostname(), platform: process.platform },
|
|
2875
2985
|
...worktree ? { worktree } : {},
|
|
2876
2986
|
permissions: {
|
|
@@ -2885,7 +2995,7 @@ function registerLocalForegroundWriter(cwd, policy, agentKey, deps = {}) {
|
|
|
2885
2995
|
};
|
|
2886
2996
|
writeRunRecord(record, deps);
|
|
2887
2997
|
try {
|
|
2888
|
-
acquireLocalWriterClaim(runId,
|
|
2998
|
+
acquireLocalWriterClaim(runId, canonical, deps);
|
|
2889
2999
|
} catch (error) {
|
|
2890
3000
|
finalizeRunRecord(runId, { status: "failed", exitCode: 1, note: String(error) }, deps);
|
|
2891
3001
|
throw error;
|
|
@@ -2894,75 +3004,85 @@ function registerLocalForegroundWriter(cwd, policy, agentKey, deps = {}) {
|
|
|
2894
3004
|
}
|
|
2895
3005
|
function releaseUnspawnedLocalWriterClaim(runId, deps) {
|
|
2896
3006
|
const released = withRunRecordLock(runId, deps, () => {
|
|
2897
|
-
const record =
|
|
3007
|
+
const record = readRunRecord2(runId, deps);
|
|
2898
3008
|
if (record?.localWriterClaim) {
|
|
2899
|
-
if (record.writerLaunch?.phase === "prepared")
|
|
3009
|
+
if (record.writerLaunch?.phase === "prepared")
|
|
3010
|
+
record.writerLaunch.phase = "revoked";
|
|
2900
3011
|
record.localWriterClaim.state = "released";
|
|
2901
3012
|
writeRunRecord(record, deps);
|
|
2902
3013
|
}
|
|
2903
3014
|
return true;
|
|
2904
3015
|
}, { strict: true });
|
|
2905
|
-
if (!released)
|
|
3016
|
+
if (!released)
|
|
3017
|
+
throw new Error(`[local-writer-resource] release lock busy: ${runId}`);
|
|
2906
3018
|
}
|
|
2907
3019
|
var startupPhaseOrder = { spawn: 0, initializing: 1, protocol_validated: 2, model: 3 };
|
|
2908
|
-
async function
|
|
3020
|
+
async function recordRunStartup2(runId, phase, deps = {}) {
|
|
2909
3021
|
const attempt = () => withRunRecordLock(runId, deps, () => {
|
|
2910
|
-
const record =
|
|
2911
|
-
if (!record ||
|
|
2912
|
-
|
|
2913
|
-
if (record.
|
|
3022
|
+
const record = readRunRecord2(runId, deps);
|
|
3023
|
+
if (!record || isRunTerminalStatus2(record.status))
|
|
3024
|
+
return true;
|
|
3025
|
+
if (record.pid != null && record.pid !== process.pid)
|
|
3026
|
+
return true;
|
|
3027
|
+
if (record.startup && startupPhaseOrder[record.startup.phase] >= startupPhaseOrder[phase])
|
|
3028
|
+
return true;
|
|
2914
3029
|
record.startup = { protocol: AGENT_RUN_PROTOCOL, phase };
|
|
2915
3030
|
writeRunRecord(record, deps);
|
|
2916
3031
|
return true;
|
|
2917
3032
|
}, { strict: true });
|
|
2918
|
-
const deadline = Date.now() +
|
|
3033
|
+
const deadline = Date.now() + 2000;
|
|
2919
3034
|
while (!attempt()) {
|
|
2920
|
-
if (Date.now() >= deadline)
|
|
2921
|
-
|
|
3035
|
+
if (Date.now() >= deadline)
|
|
3036
|
+
throw new Error(`Startup evidence lock busy: ${runId}`);
|
|
3037
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
2922
3038
|
}
|
|
2923
3039
|
}
|
|
2924
3040
|
async function settleBackgroundProcessExit(runId, code, signal, deps = {}) {
|
|
2925
|
-
const deadline = Date.now() +
|
|
3041
|
+
const deadline = Date.now() + 2000;
|
|
2926
3042
|
while (true) {
|
|
2927
3043
|
const settled = withRunRecordLock(runId, deps, () => {
|
|
2928
|
-
const record =
|
|
2929
|
-
if (!record)
|
|
2930
|
-
|
|
3044
|
+
const record = readRunRecord2(runId, deps);
|
|
3045
|
+
if (!record)
|
|
3046
|
+
return true;
|
|
3047
|
+
if (isRunTerminalStatus2(record.status)) {
|
|
2931
3048
|
record.processExit = { code, signal };
|
|
2932
3049
|
writeRunRecord(record, deps);
|
|
2933
3050
|
return true;
|
|
2934
3051
|
}
|
|
2935
3052
|
return false;
|
|
2936
3053
|
}, { strict: true });
|
|
2937
|
-
if (settled === true)
|
|
3054
|
+
if (settled === true)
|
|
3055
|
+
return;
|
|
2938
3056
|
if (settled === false) {
|
|
2939
|
-
const result =
|
|
3057
|
+
const result = transitionRunToTerminal2(runId, {
|
|
2940
3058
|
status: signal === "SIGTERM" || signal === "SIGKILL" ? "killed" : "failed",
|
|
2941
3059
|
exitCode: code ?? 1,
|
|
2942
3060
|
processExit: { code, signal },
|
|
2943
3061
|
failureReason: signal === "SIGTERM" || signal === "SIGKILL" ? "cancelled" : "startup_failed",
|
|
2944
3062
|
note: `Child exited without terminal result (code=${code}, signal=${signal})`
|
|
2945
3063
|
}, deps);
|
|
2946
|
-
if (result.kind !== "contended")
|
|
3064
|
+
if (result.kind !== "contended")
|
|
3065
|
+
return;
|
|
2947
3066
|
}
|
|
2948
|
-
if (Date.now() >= deadline)
|
|
3067
|
+
if (Date.now() >= deadline)
|
|
3068
|
+
throw new Error(`Process exit settlement lock busy: ${runId}`);
|
|
2949
3069
|
await (deps.sleep ?? defaultSleep)(20);
|
|
2950
3070
|
}
|
|
2951
3071
|
}
|
|
2952
|
-
async function
|
|
3072
|
+
async function spawnLocalBackgroundRun2(input, deps = {}) {
|
|
2953
3073
|
const homedir = deps.homedir ?? nodeHomedir;
|
|
2954
3074
|
const env = deps.env ?? (deps.homedir ? { ...process.env, NOLO_HOME: join2(homedir(), ".nolo") } : process.env);
|
|
2955
3075
|
const resolvedDeps = { ...deps, env, homedir };
|
|
2956
3076
|
const fs = deps.fs ?? nodeFs2;
|
|
2957
3077
|
const spawn = deps.spawn ?? nodeSpawn;
|
|
2958
|
-
const generateRunId = deps.generateRunId ??
|
|
2959
|
-
const now = deps.now ?? (() =>
|
|
3078
|
+
const generateRunId = deps.generateRunId ?? defaultGenerateRunId2;
|
|
3079
|
+
const now = deps.now ?? (() => new Date);
|
|
2960
3080
|
const runId = generateRunId();
|
|
2961
3081
|
const batchId = input.batchId ?? (deps.generateBatchId ?? defaultGenerateBatchId)();
|
|
2962
3082
|
const logPath = resolveRunLogPath(runId, env, homedir);
|
|
2963
|
-
const queuePath =
|
|
3083
|
+
const queuePath = resolveRunQueuePath2(runId, env, homedir);
|
|
2964
3084
|
const recordPath = resolveRunRecordPath(runId, env, homedir);
|
|
2965
|
-
const runsDir =
|
|
3085
|
+
const runsDir = resolveRunsDir2(env, homedir);
|
|
2966
3086
|
fs.mkdirSync(runsDir, { recursive: true });
|
|
2967
3087
|
let messagePath;
|
|
2968
3088
|
if (typeof input.message === "string") {
|
|
@@ -2971,14 +3091,14 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
2971
3091
|
}
|
|
2972
3092
|
const rawDodCommands = [];
|
|
2973
3093
|
if (Array.isArray(input.rawArgs)) {
|
|
2974
|
-
for (let index = 0;
|
|
3094
|
+
for (let index = 0;index < input.rawArgs.length; index += 1) {
|
|
2975
3095
|
if (input.rawArgs[index] === "--dod" && input.rawArgs[index + 1]) {
|
|
2976
3096
|
rawDodCommands.push(input.rawArgs[index + 1]);
|
|
2977
3097
|
index += 1;
|
|
2978
3098
|
}
|
|
2979
3099
|
}
|
|
2980
3100
|
}
|
|
2981
|
-
const dodCommands = input.dodCommands && input.dodCommands.length > 0 ? input.dodCommands : rawDodCommands.length > 0 ? rawDodCommands :
|
|
3101
|
+
const dodCommands = input.dodCommands && input.dodCommands.length > 0 ? input.dodCommands : rawDodCommands.length > 0 ? rawDodCommands : undefined;
|
|
2982
3102
|
let spawnHead;
|
|
2983
3103
|
const targetCwd = input.cwd ?? process.cwd();
|
|
2984
3104
|
try {
|
|
@@ -2987,19 +3107,18 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
2987
3107
|
cwd: targetCwd,
|
|
2988
3108
|
encoding: "utf8",
|
|
2989
3109
|
stdio: ["ignore", "pipe", "ignore"],
|
|
2990
|
-
timeout:
|
|
3110
|
+
timeout: 3000
|
|
2991
3111
|
}).trim();
|
|
2992
3112
|
if (out && /^[0-9a-fA-F]{7,40}$/.test(out)) {
|
|
2993
3113
|
spawnHead = out;
|
|
2994
3114
|
}
|
|
2995
|
-
} catch {
|
|
2996
|
-
}
|
|
3115
|
+
} catch {}
|
|
2997
3116
|
const executionRequest = input.localExecution;
|
|
2998
3117
|
if (executionRequest && (executionRequest.runtimeKey !== "local" || typeof executionRequest.readOnly !== "boolean" || typeof executionRequest.hostWritesAuthorized !== "boolean" || !executionRequest.readOnly && !executionRequest.hostWritesAuthorized)) {
|
|
2999
3118
|
throw new Error("Invalid authorized local execution facts");
|
|
3000
3119
|
}
|
|
3001
|
-
const canonicalCwd = executionRequest ? String((fs.realpathSync ?? nodeFs2.realpathSync)(targetCwd)) :
|
|
3002
|
-
const executionWorktree = canonicalCwd ? trustedLocalWorktree(canonicalCwd, resolvedDeps) :
|
|
3120
|
+
const canonicalCwd = executionRequest ? String((fs.realpathSync ?? nodeFs2.realpathSync)(targetCwd)) : undefined;
|
|
3121
|
+
const executionWorktree = canonicalCwd ? trustedLocalWorktree(canonicalCwd, resolvedDeps) : undefined;
|
|
3003
3122
|
const execution = executionRequest ? {
|
|
3004
3123
|
state: "known",
|
|
3005
3124
|
kind: "host-local",
|
|
@@ -3050,28 +3169,24 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
3050
3169
|
...typeof input.continuedFrom === "string" && input.continuedFrom.trim() ? { continuedFrom: input.continuedFrom.trim() } : {}
|
|
3051
3170
|
};
|
|
3052
3171
|
fs.writeFileSync(recordPath, JSON.stringify(record, null, 2));
|
|
3053
|
-
const rawArgsWithQueue = (input.rawArgs ?? []).some(
|
|
3054
|
-
(arg) => arg === "--queue-file" || arg.startsWith("--queue-file=")
|
|
3055
|
-
) ? input.rawArgs : [...input.rawArgs ?? [], "--queue-file", queuePath];
|
|
3172
|
+
const rawArgsWithQueue = (input.rawArgs ?? []).some((arg) => arg === "--queue-file" || arg.startsWith("--queue-file=")) ? input.rawArgs : [...input.rawArgs ?? [], "--queue-file", queuePath];
|
|
3056
3173
|
let childCommand;
|
|
3057
3174
|
try {
|
|
3058
|
-
childCommand = buildAgentRunChildCommand(
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
},
|
|
3065
|
-
deps
|
|
3066
|
-
);
|
|
3175
|
+
childCommand = buildAgentRunChildCommand({
|
|
3176
|
+
rawArgs: rawArgsWithQueue,
|
|
3177
|
+
commandPath: input.commandPath,
|
|
3178
|
+
cliEntrypointPath: input.cliEntrypointPath,
|
|
3179
|
+
messagePath
|
|
3180
|
+
}, deps);
|
|
3067
3181
|
} catch (error) {
|
|
3068
|
-
const result = await
|
|
3182
|
+
const result = await settleRunTerminalAuthoritatively2(runId, {
|
|
3069
3183
|
status: "failed",
|
|
3070
3184
|
exitCode: 1,
|
|
3071
3185
|
failureReason: error instanceof RuntimeVersionMismatchError ? "runtime_version_mismatch" : "startup_failed",
|
|
3072
3186
|
note: String(error)
|
|
3073
|
-
}, resolvedDeps, (id, update, d) =>
|
|
3074
|
-
if (result.kind === "contended")
|
|
3187
|
+
}, resolvedDeps, (id, update, d) => transitionRunToTerminal2(id, update, d));
|
|
3188
|
+
if (result.kind === "contended")
|
|
3189
|
+
throw new Error(`Startup settlement lock busy: ${runId}; ${error}`);
|
|
3075
3190
|
throw error;
|
|
3076
3191
|
}
|
|
3077
3192
|
const { execPath, childArgs } = childCommand;
|
|
@@ -3083,7 +3198,8 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
3083
3198
|
NOLO_AGENT_RUN_ID: runId,
|
|
3084
3199
|
...record.writerLaunch ? { NOLO_WRITER_LAUNCH_ATTEMPT: record.writerLaunch.attemptId } : {}
|
|
3085
3200
|
};
|
|
3086
|
-
if (!record.writerLaunch)
|
|
3201
|
+
if (!record.writerLaunch)
|
|
3202
|
+
delete childEnv.NOLO_WRITER_LAUNCH_ATTEMPT;
|
|
3087
3203
|
delete childEnv.NOLO_SUBTASK_MAX_TOOL_CALLS;
|
|
3088
3204
|
delete childEnv.NOLO_SUBTASK_MAX_WALL_CLOCK_MS;
|
|
3089
3205
|
let hostMemory = null;
|
|
@@ -3108,28 +3224,28 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
3108
3224
|
fs: reservationFs,
|
|
3109
3225
|
now: resolvedDeps.now,
|
|
3110
3226
|
readHostMemory: () => hostMemory = (resolvedDeps.readHostMemory ?? readHostMemory)(),
|
|
3111
|
-
// Admission remains conservative for existing reservations; no OS probes on startup.
|
|
3112
3227
|
getProcessStartTime: () => null,
|
|
3113
3228
|
withLock: (id, fn, opts) => withRunRecordLock(id, resolvedDeps, fn, opts)
|
|
3114
3229
|
});
|
|
3115
3230
|
const spawnCwd = input.claimLocalWrites ? acquireLocalWriterClaim(runId, input.cwd ?? process.cwd(), resolvedDeps) : canonicalCwd ?? input.cwd;
|
|
3116
3231
|
if (record.writerLaunch) {
|
|
3117
|
-
const prepared =
|
|
3118
|
-
if (!prepared || prepared.writerLaunch?.phase !== "prepared" || prepared.writerLaunch.attemptId !== record.writerLaunch.attemptId)
|
|
3232
|
+
const prepared = readRunRecord2(runId, resolvedDeps);
|
|
3233
|
+
if (!prepared || prepared.writerLaunch?.phase !== "prepared" || prepared.writerLaunch.attemptId !== record.writerLaunch.attemptId)
|
|
3234
|
+
throw new Error("[local-writer-resource] launch attempt revoked before spawn");
|
|
3119
3235
|
preparedScope = launchScope(prepared);
|
|
3120
3236
|
}
|
|
3121
3237
|
proc = spawn(execPath, childArgs, {
|
|
3122
3238
|
cwd: spawnCwd,
|
|
3123
3239
|
env: childEnv,
|
|
3124
3240
|
detached: true,
|
|
3125
|
-
// Detached on Windows means no console; hide the one its children would create.
|
|
3126
3241
|
windowsHide: true,
|
|
3127
3242
|
stdio: deps.shellApprovalHost || deps.mcpApprovalHost ? ["ignore", logFd, logFd, "ipc"] : ["ignore", logFd, logFd]
|
|
3128
3243
|
});
|
|
3129
3244
|
} catch (error) {
|
|
3130
3245
|
try {
|
|
3131
3246
|
reservation?.release("spawn_sync_failed");
|
|
3132
|
-
if (input.claimLocalWrites)
|
|
3247
|
+
if (input.claimLocalWrites)
|
|
3248
|
+
releaseUnspawnedLocalWriterClaim(runId, resolvedDeps);
|
|
3133
3249
|
} finally {
|
|
3134
3250
|
finalizeRunRecord(runId, { status: "failed", exitCode: 1, failureReason: error instanceof RuntimeVersionMismatchError ? "runtime_version_mismatch" : "startup_failed", note: String(error) }, resolvedDeps);
|
|
3135
3251
|
}
|
|
@@ -3144,20 +3260,21 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
3144
3260
|
} catch (releaseError) {
|
|
3145
3261
|
note += `; reservation release failed: ${releaseError}`;
|
|
3146
3262
|
}
|
|
3147
|
-
|
|
3263
|
+
settleRunTerminalAuthoritatively2(runId, {
|
|
3148
3264
|
status: "failed",
|
|
3149
3265
|
exitCode: 1,
|
|
3150
3266
|
failureReason: "startup_failed",
|
|
3151
3267
|
note
|
|
3152
|
-
}, resolvedDeps, (id, update, d) =>
|
|
3153
|
-
if (result.kind === "contended")
|
|
3154
|
-
|
|
3155
|
-
|
|
3268
|
+
}, resolvedDeps, (id, update, d) => transitionRunToTerminal2(id, update, d)).then((result) => {
|
|
3269
|
+
if (result.kind === "contended")
|
|
3270
|
+
throw new Error(`Startup settlement lock busy: ${runId}`);
|
|
3271
|
+
}).catch((error) => {
|
|
3272
|
+
input.output?.write(`[nolo] background error settlement failed: ${error}
|
|
3156
3273
|
`);
|
|
3157
3274
|
});
|
|
3158
3275
|
});
|
|
3159
3276
|
proc.once?.("exit", (code, signal) => {
|
|
3160
|
-
|
|
3277
|
+
settleBackgroundProcessExit(runId, code, signal, resolvedDeps).catch((error) => {
|
|
3161
3278
|
input.output?.write(`[nolo] background exit settlement failed: ${error}
|
|
3162
3279
|
`);
|
|
3163
3280
|
});
|
|
@@ -3177,21 +3294,23 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
3177
3294
|
const stat = String(nodeFs2.readFileSync(`/proc/${proc.pid}/stat`, "utf8"));
|
|
3178
3295
|
const startTicks = stat.slice(stat.lastIndexOf(")") + 2).split(/\s+/)[19];
|
|
3179
3296
|
const bootId = nodeFs2.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
|
|
3180
|
-
if (/^\d+$/.test(startTicks) && bootId)
|
|
3181
|
-
|
|
3182
|
-
}
|
|
3297
|
+
if (/^\d+$/.test(startTicks) && bootId)
|
|
3298
|
+
linuxIdentity = { bootId, startTicks };
|
|
3299
|
+
} catch {}
|
|
3183
3300
|
}
|
|
3184
3301
|
const confirmedStart = executionRequest ? probeProcessStartTime(proc.pid, resolvedDeps) : null;
|
|
3185
|
-
const stableNativeIdentity = nativeStartedAt && confirmedStart && nativeStartedAt.getTime() === confirmedStart.getTime() && !
|
|
3302
|
+
const stableNativeIdentity = nativeStartedAt && confirmedStart && nativeStartedAt.getTime() === confirmedStart.getTime() && !isPidGone2(proc.pid, resolvedDeps);
|
|
3186
3303
|
const publishOwner = () => withRunRecordLock(runId, resolvedDeps, () => {
|
|
3187
|
-
const latest =
|
|
3188
|
-
if (!latest)
|
|
3304
|
+
const latest = readRunRecord2(runId, resolvedDeps);
|
|
3305
|
+
if (!latest)
|
|
3306
|
+
throw new Error("[local-writer-resource] publication record missing");
|
|
3189
3307
|
if (record.writerLaunch) {
|
|
3190
3308
|
const launch = latest.writerLaunch;
|
|
3191
3309
|
if (launch?.protocol !== "fenced-launch-v1" || launch.attemptId !== record.writerLaunch.attemptId || launch.phase !== "prepared") {
|
|
3192
3310
|
throw new Error("[local-writer-resource] publication attempt revoked/mismatched");
|
|
3193
3311
|
}
|
|
3194
|
-
if (launchScope(latest) !== preparedScope)
|
|
3312
|
+
if (launchScope(latest) !== preparedScope)
|
|
3313
|
+
throw new Error("[local-writer-resource] publication scope changed");
|
|
3195
3314
|
}
|
|
3196
3315
|
latest.pid = proc.pid;
|
|
3197
3316
|
if (latest.execution?.state === "known") {
|
|
@@ -3204,26 +3323,29 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
3204
3323
|
...linuxIdentity ? { linux: linuxIdentity } : {}
|
|
3205
3324
|
} : { state: "unknown" };
|
|
3206
3325
|
latest.processIdentity = verified ? "verified" : "unverified";
|
|
3207
|
-
latest.processStartedAt = verified ? nativeStartedAt.toISOString() :
|
|
3326
|
+
latest.processStartedAt = verified ? nativeStartedAt.toISOString() : undefined;
|
|
3208
3327
|
} else {
|
|
3209
3328
|
latest.processIdentity ??= "unverified";
|
|
3210
3329
|
}
|
|
3211
3330
|
if (latest.writerLaunch && latest.execution?.state === "known" && latest.execution.owner.state === "verified") {
|
|
3212
3331
|
latest.writerLaunch.phase = "granted";
|
|
3213
3332
|
}
|
|
3214
|
-
if (latest.ownerPublication)
|
|
3333
|
+
if (latest.ownerPublication)
|
|
3334
|
+
latest.ownerPublication.state = "complete";
|
|
3215
3335
|
writeRunRecord(latest, resolvedDeps);
|
|
3216
3336
|
return true;
|
|
3217
3337
|
}, { strict: true, requireDeadOwner: true });
|
|
3218
|
-
const publicationDeadline = Date.now() +
|
|
3338
|
+
const publicationDeadline = Date.now() + 2000;
|
|
3219
3339
|
while (!publishOwner()) {
|
|
3220
|
-
if (Date.now() >= publicationDeadline)
|
|
3221
|
-
|
|
3340
|
+
if (Date.now() >= publicationDeadline)
|
|
3341
|
+
throw new Error("[local-writer-resource] parent owner publication lock busy");
|
|
3342
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
3222
3343
|
}
|
|
3223
3344
|
try {
|
|
3224
|
-
const persisted =
|
|
3345
|
+
const persisted = readRunRecord2(runId, resolvedDeps);
|
|
3225
3346
|
reservation.associate({ runId, pid: proc.pid, processStartedAt: persisted?.processStartedAt });
|
|
3226
|
-
if (persisted?.pid !== proc.pid)
|
|
3347
|
+
if (persisted?.pid !== proc.pid)
|
|
3348
|
+
throw new Error("Child identity persistence failed: pid not bound");
|
|
3227
3349
|
} catch (error) {
|
|
3228
3350
|
throw new Error(`[host-memory-reservation] child ${proc.pid}, run ${runId}: association failed: ${error}`);
|
|
3229
3351
|
}
|
|
@@ -3258,140 +3380,153 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
|
|
|
3258
3380
|
...hostMemoryNotice ? { hostMemoryNotice } : {}
|
|
3259
3381
|
};
|
|
3260
3382
|
}
|
|
3261
|
-
function
|
|
3383
|
+
function ackRunRecord2(runId, deps = {}) {
|
|
3262
3384
|
withRunRecordLock(runId, deps, () => {
|
|
3263
|
-
const record =
|
|
3264
|
-
if (!record)
|
|
3265
|
-
|
|
3385
|
+
const record = readRunRecord2(runId, deps);
|
|
3386
|
+
if (!record)
|
|
3387
|
+
return;
|
|
3388
|
+
if (record.ack)
|
|
3389
|
+
return;
|
|
3266
3390
|
record.ack = true;
|
|
3267
3391
|
delete record.ackLease;
|
|
3268
3392
|
writeRunRecord(record, deps);
|
|
3269
3393
|
});
|
|
3270
3394
|
}
|
|
3271
|
-
var DEFAULT_ACK_LEASE_TTL_MS = 15 * 60 *
|
|
3395
|
+
var DEFAULT_ACK_LEASE_TTL_MS = 15 * 60 * 1000;
|
|
3272
3396
|
function isAckLeaseExpired(lease, nowMs) {
|
|
3273
|
-
if (!lease)
|
|
3397
|
+
if (!lease)
|
|
3398
|
+
return true;
|
|
3274
3399
|
const ttl = typeof lease.ttlMs === "number" && lease.ttlMs > 0 ? lease.ttlMs : DEFAULT_ACK_LEASE_TTL_MS;
|
|
3275
3400
|
const claimedAt = typeof lease.claimedAt === "number" ? lease.claimedAt : 0;
|
|
3276
3401
|
return nowMs - claimedAt >= ttl;
|
|
3277
3402
|
}
|
|
3278
|
-
function
|
|
3279
|
-
if (!record)
|
|
3280
|
-
|
|
3403
|
+
function isRunRecordClaimed2(record, nowMs) {
|
|
3404
|
+
if (!record)
|
|
3405
|
+
return false;
|
|
3406
|
+
if (record.ack === true && !record.ackLease)
|
|
3407
|
+
return true;
|
|
3281
3408
|
return !isAckLeaseExpired(record.ackLease, nowMs);
|
|
3282
3409
|
}
|
|
3283
|
-
function
|
|
3284
|
-
const now = deps.now ?? (() =>
|
|
3410
|
+
function claimRunRecord2(runId, deps = {}) {
|
|
3411
|
+
const now = deps.now ?? (() => new Date);
|
|
3285
3412
|
const nowMs = now().getTime();
|
|
3286
|
-
return withRunRecordLock(
|
|
3287
|
-
runId,
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
{ strict: true }
|
|
3305
|
-
) ?? null;
|
|
3413
|
+
return withRunRecordLock(runId, deps, () => {
|
|
3414
|
+
const record = readRunRecord2(runId, deps);
|
|
3415
|
+
if (!record)
|
|
3416
|
+
return null;
|
|
3417
|
+
if (record.ack === true && !record.ackLease)
|
|
3418
|
+
return null;
|
|
3419
|
+
if (!isAckLeaseExpired(record.ackLease, nowMs))
|
|
3420
|
+
return null;
|
|
3421
|
+
const token = `${nowMs.toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
|
|
3422
|
+
record.ack = true;
|
|
3423
|
+
record.ackLease = {
|
|
3424
|
+
token,
|
|
3425
|
+
claimedAt: nowMs,
|
|
3426
|
+
ttlMs: deps.ttlMs && deps.ttlMs > 0 ? deps.ttlMs : DEFAULT_ACK_LEASE_TTL_MS
|
|
3427
|
+
};
|
|
3428
|
+
writeRunRecord(record, deps);
|
|
3429
|
+
return token;
|
|
3430
|
+
}, { strict: true }) ?? null;
|
|
3306
3431
|
}
|
|
3307
|
-
function
|
|
3432
|
+
function commitRunRecordClaim2(runId, token, deps = {}) {
|
|
3308
3433
|
withRunRecordLock(runId, deps, () => {
|
|
3309
|
-
const record =
|
|
3310
|
-
if (!record)
|
|
3311
|
-
|
|
3434
|
+
const record = readRunRecord2(runId, deps);
|
|
3435
|
+
if (!record)
|
|
3436
|
+
return;
|
|
3437
|
+
if (record.ackLease && record.ackLease.token !== token)
|
|
3438
|
+
return;
|
|
3312
3439
|
record.ack = true;
|
|
3313
3440
|
delete record.ackLease;
|
|
3314
3441
|
writeRunRecord(record, deps);
|
|
3315
3442
|
});
|
|
3316
3443
|
}
|
|
3317
|
-
function
|
|
3444
|
+
function releaseRunRecordAck2(runId, token, deps = {}) {
|
|
3318
3445
|
withRunRecordLock(runId, deps, () => {
|
|
3319
|
-
const record =
|
|
3320
|
-
if (!record)
|
|
3321
|
-
|
|
3446
|
+
const record = readRunRecord2(runId, deps);
|
|
3447
|
+
if (!record)
|
|
3448
|
+
return;
|
|
3449
|
+
if (!record.ackLease || record.ackLease.token !== token)
|
|
3450
|
+
return;
|
|
3322
3451
|
delete record.ackLease;
|
|
3323
3452
|
delete record.ack;
|
|
3324
3453
|
writeRunRecord(record, deps);
|
|
3325
3454
|
});
|
|
3326
3455
|
}
|
|
3327
|
-
function
|
|
3456
|
+
function transitionRunToTerminal2(runId, update, deps = {}, options = {}) {
|
|
3328
3457
|
const settled = withRunRecordLock(runId, deps, () => {
|
|
3329
|
-
const
|
|
3330
|
-
if (!
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3458
|
+
const record = readRunRecord2(runId, deps);
|
|
3459
|
+
if (!record)
|
|
3460
|
+
return { kind: "not_found" };
|
|
3461
|
+
if (options.expectedPid != null && record.pid != null && record.pid !== options.expectedPid) {
|
|
3462
|
+
return { kind: "kept", record };
|
|
3463
|
+
}
|
|
3464
|
+
const orphanCorrection = options.allowOverOrphaned === true && record.status === "orphaned" && (update.status === "done" || update.status === "failed");
|
|
3465
|
+
if (isAgentRunTerminalStatus(record.status) && !orphanCorrection) {
|
|
3336
3466
|
if (update.processExit) {
|
|
3337
|
-
|
|
3338
|
-
writeRunRecord(
|
|
3467
|
+
record.processExit = update.processExit;
|
|
3468
|
+
writeRunRecord(record, deps);
|
|
3339
3469
|
}
|
|
3340
|
-
return { kind: "kept", record
|
|
3341
|
-
}
|
|
3342
|
-
const now = deps.now ?? (() =>
|
|
3343
|
-
|
|
3344
|
-
if (update.processExit)
|
|
3345
|
-
|
|
3346
|
-
if (update.
|
|
3470
|
+
return { kind: "kept", record };
|
|
3471
|
+
}
|
|
3472
|
+
const now = deps.now ?? (() => new Date);
|
|
3473
|
+
record.status = update.status;
|
|
3474
|
+
if (update.processExit)
|
|
3475
|
+
record.processExit = update.processExit;
|
|
3476
|
+
if (typeof update.exitCode === "number")
|
|
3477
|
+
record.exitCode = update.exitCode;
|
|
3478
|
+
if (update.dialogId)
|
|
3479
|
+
record.dialogId = update.dialogId;
|
|
3347
3480
|
if (typeof update.credits === "number" && Number.isFinite(update.credits)) {
|
|
3348
|
-
|
|
3481
|
+
record.credits = update.credits;
|
|
3349
3482
|
}
|
|
3350
3483
|
if (update.dodResults && update.dodResults.length > 0) {
|
|
3351
|
-
|
|
3484
|
+
record.dodResults = update.dodResults;
|
|
3352
3485
|
}
|
|
3353
3486
|
if (update.failureReason) {
|
|
3354
|
-
|
|
3487
|
+
record.failureReason = update.failureReason;
|
|
3355
3488
|
} else if (update.status === "killed") {
|
|
3356
|
-
|
|
3489
|
+
record.failureReason = "cancelled";
|
|
3357
3490
|
}
|
|
3358
3491
|
const classification = classifyRunFailure({
|
|
3359
3492
|
status: update.status,
|
|
3360
|
-
failureReason:
|
|
3361
|
-
errorMessage: update.note ??
|
|
3493
|
+
failureReason: record.failureReason,
|
|
3494
|
+
errorMessage: update.note ?? record.note
|
|
3362
3495
|
});
|
|
3363
3496
|
if (classification) {
|
|
3364
|
-
|
|
3365
|
-
|
|
3497
|
+
record.failureClass = classification.failureClass;
|
|
3498
|
+
record.retryable = classification.retryable;
|
|
3366
3499
|
}
|
|
3367
|
-
const resolvedToolCount = typeof update.toolCallCount === "number" ? update.toolCallCount :
|
|
3500
|
+
const resolvedToolCount = typeof update.toolCallCount === "number" ? update.toolCallCount : record.activity?.counters?.toolCalls;
|
|
3368
3501
|
if (typeof resolvedToolCount === "number") {
|
|
3369
|
-
|
|
3502
|
+
record.toolCallCount = resolvedToolCount;
|
|
3370
3503
|
}
|
|
3371
3504
|
if (typeof update.lastAssistantText === "string" && update.lastAssistantText) {
|
|
3372
|
-
|
|
3505
|
+
record.lastAssistantText = update.lastAssistantText.slice(0, 2000);
|
|
3373
3506
|
}
|
|
3374
3507
|
if (typeof update.model === "string" && update.model.trim()) {
|
|
3375
|
-
|
|
3508
|
+
record.model = update.model.trim();
|
|
3376
3509
|
}
|
|
3377
3510
|
const finalObservation = deriveRunFinalObservation(update.lastAssistantText);
|
|
3378
|
-
if (finalObservation.escalated)
|
|
3379
|
-
|
|
3511
|
+
if (finalObservation.escalated)
|
|
3512
|
+
record.escalated = true;
|
|
3513
|
+
if (finalObservation.reviewVerdict)
|
|
3514
|
+
record.reviewVerdict = finalObservation.reviewVerdict;
|
|
3380
3515
|
if (update.cacheUsage) {
|
|
3381
|
-
|
|
3382
|
-
|
|
3516
|
+
record.cacheHitRatio = update.cacheUsage.cache_hit_ratio;
|
|
3517
|
+
record.cacheCachedTokens = update.cacheUsage.cached_tokens;
|
|
3383
3518
|
if (typeof update.cacheUsage.input_tokens === "number") {
|
|
3384
|
-
|
|
3519
|
+
record.inputTokens = update.cacheUsage.input_tokens;
|
|
3385
3520
|
}
|
|
3386
3521
|
if (typeof update.cacheUsage.output_tokens === "number") {
|
|
3387
|
-
|
|
3522
|
+
record.outputTokens = update.cacheUsage.output_tokens;
|
|
3388
3523
|
}
|
|
3389
3524
|
}
|
|
3390
|
-
const resolvedTier =
|
|
3391
|
-
if (resolvedTier !== "unknown" ||
|
|
3392
|
-
|
|
3525
|
+
const resolvedTier = record.selectionCheck?.modelTier ?? resolveModelTier(record.model);
|
|
3526
|
+
if (resolvedTier !== "unknown" || record.selectionCheck?.modelTier) {
|
|
3527
|
+
record.modelTier = resolvedTier;
|
|
3393
3528
|
}
|
|
3394
|
-
|
|
3529
|
+
record.endedAt = now().toISOString();
|
|
3395
3530
|
let resultWriteFailed = false;
|
|
3396
3531
|
let pendingResultFile;
|
|
3397
3532
|
let stagingComplete = false;
|
|
@@ -3400,7 +3535,8 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
|
|
|
3400
3535
|
const registerArtifact = (path, kind) => {
|
|
3401
3536
|
const fs = deps.fs ?? nodeFs2;
|
|
3402
3537
|
const stat = fs.lstatSync?.(path);
|
|
3403
|
-
if (!stat || !stat.isFile() || stat.isSymbolicLink())
|
|
3538
|
+
if (!stat || !stat.isFile() || stat.isSymbolicLink())
|
|
3539
|
+
return;
|
|
3404
3540
|
const artifact = {
|
|
3405
3541
|
publisher: "run-result-v1",
|
|
3406
3542
|
path,
|
|
@@ -3409,44 +3545,43 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
|
|
|
3409
3545
|
ino: String(stat.ino),
|
|
3410
3546
|
sha256: createHash2("sha256").update(fs.readFileSync(path)).digest("hex")
|
|
3411
3547
|
};
|
|
3412
|
-
|
|
3548
|
+
record.resultArtifacts = [...(record.resultArtifacts ?? []).filter((a) => a.path !== path), artifact];
|
|
3413
3549
|
};
|
|
3414
3550
|
if (typeof update.lastAssistantText === "string" && update.lastAssistantText || update.acceptance?.checks.observations?.length || update.failureReason === "startup_failed" || update.failureReason === "runtime_protocol_mismatch" || update.failureReason === "runtime_version_mismatch") {
|
|
3415
3551
|
try {
|
|
3416
3552
|
const fs = deps.fs ?? nodeFs2;
|
|
3417
|
-
const resultFile = join2(
|
|
3418
|
-
const startedMs = Date.parse(
|
|
3419
|
-
const endedMs = Date.parse(
|
|
3420
|
-
const content = buildResultFileContent(
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
);
|
|
3443
|
-
if (typeof fs.renameSync !== "function") throw new Error("atomic result publication requires renameSync");
|
|
3553
|
+
const resultFile = join2(resolveRunsDir2(deps.env, deps.homedir), `${runId}.result.md`);
|
|
3554
|
+
const startedMs = Date.parse(record.startedAt);
|
|
3555
|
+
const endedMs = Date.parse(record.endedAt);
|
|
3556
|
+
const content = buildResultFileContent({
|
|
3557
|
+
runId,
|
|
3558
|
+
acceptance: update.acceptance,
|
|
3559
|
+
status: record.status,
|
|
3560
|
+
agentName: record.agentName,
|
|
3561
|
+
model: update.model,
|
|
3562
|
+
startedAt: record.startedAt,
|
|
3563
|
+
endedAt: record.endedAt,
|
|
3564
|
+
...Number.isFinite(startedMs) && Number.isFinite(endedMs) ? { durationMs: Math.max(0, endedMs - startedMs) } : {},
|
|
3565
|
+
toolCallCount: record.toolCallCount,
|
|
3566
|
+
dialogId: record.dialogId,
|
|
3567
|
+
server: update.dialogServer ?? "local",
|
|
3568
|
+
serverSync: update.serverSync,
|
|
3569
|
+
cwd: record.cwd,
|
|
3570
|
+
continuedFrom: record.continuedFrom,
|
|
3571
|
+
...update.cacheUsage ? { cacheUsage: update.cacheUsage } : {},
|
|
3572
|
+
...typeof record.inputTokens === "number" ? { inputTokens: record.inputTokens } : {},
|
|
3573
|
+
...typeof record.outputTokens === "number" ? { outputTokens: record.outputTokens } : {},
|
|
3574
|
+
...record.modelTier ? { modelTier: record.modelTier } : {}
|
|
3575
|
+
}, update.lastAssistantText ?? "");
|
|
3576
|
+
if (typeof fs.renameSync !== "function")
|
|
3577
|
+
throw new Error("atomic result publication requires renameSync");
|
|
3444
3578
|
pendingResultFile = `${resultFile}.${randomUUID3()}.pending`;
|
|
3445
3579
|
try {
|
|
3446
3580
|
fs.writeFileSync(pendingResultFile, content, { encoding: "utf8", flag: "wx" });
|
|
3447
3581
|
stagingComplete = true;
|
|
3448
3582
|
} finally {
|
|
3449
|
-
if (fs.existsSync(pendingResultFile))
|
|
3583
|
+
if (fs.existsSync(pendingResultFile))
|
|
3584
|
+
registerArtifact(pendingResultFile, "pending");
|
|
3450
3585
|
}
|
|
3451
3586
|
if (fs.existsSync(resultFile)) {
|
|
3452
3587
|
const previous = fs.readFileSync(resultFile);
|
|
@@ -3455,7 +3590,8 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
|
|
|
3455
3590
|
try {
|
|
3456
3591
|
fs.writeFileSync(backup, previous, { flag: "wx" });
|
|
3457
3592
|
} finally {
|
|
3458
|
-
if (fs.existsSync(backup))
|
|
3593
|
+
if (fs.existsSync(backup))
|
|
3594
|
+
registerArtifact(backup, "bak");
|
|
3459
3595
|
}
|
|
3460
3596
|
const sameBytes = (a, b) => Buffer.from(a).equals(Buffer.from(b));
|
|
3461
3597
|
if (!sameBytes(previous, fs.readFileSync(backup)) || !sameBytes(previous, fs.readFileSync(resultFile))) {
|
|
@@ -3464,71 +3600,70 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
|
|
|
3464
3600
|
backupVerified = true;
|
|
3465
3601
|
}
|
|
3466
3602
|
fs.renameSync(pendingResultFile, resultFile);
|
|
3467
|
-
|
|
3468
|
-
pendingResultFile =
|
|
3469
|
-
|
|
3603
|
+
record.resultArtifacts = record.resultArtifacts?.filter((a) => a.path !== pendingResultFile);
|
|
3604
|
+
pendingResultFile = undefined;
|
|
3605
|
+
record.resultFile = resultFile;
|
|
3470
3606
|
} catch {
|
|
3471
3607
|
resultWriteFailed = true;
|
|
3472
|
-
delete
|
|
3473
|
-
if (
|
|
3474
|
-
|
|
3475
|
-
|
|
3608
|
+
delete record.resultFile;
|
|
3609
|
+
if (record.status === "done") {
|
|
3610
|
+
record.status = "failed";
|
|
3611
|
+
record.exitCode = 1;
|
|
3476
3612
|
}
|
|
3477
3613
|
}
|
|
3478
3614
|
}
|
|
3479
3615
|
if (typeof update.note === "string" && update.note.trim()) {
|
|
3480
|
-
|
|
3616
|
+
record.note = update.note.trim();
|
|
3481
3617
|
}
|
|
3482
3618
|
if (resultWriteFailed) {
|
|
3483
|
-
if (
|
|
3619
|
+
if (record.note?.startsWith("orphaned:"))
|
|
3620
|
+
record.note = undefined;
|
|
3484
3621
|
const fs = deps.fs ?? nodeFs2;
|
|
3485
3622
|
const stagingNote = pendingResultFile ? fs.existsSync(pendingResultFile) ? `${stagingComplete ? "complete staging copy" : "incomplete staging fragment"}: ${pendingResultFile}` : `staging not created: ${pendingResultFile}` : "staging not created";
|
|
3486
3623
|
const backupNote = backupFile ? `${fs.existsSync(backupFile) ? backupVerified ? "full verified backup" : "partial backup" : "backup not created"}: ${backupFile}` : "backup not created";
|
|
3487
|
-
|
|
3624
|
+
record.note = [record.note, `result file write failed; complete final report was not saved; ${stagingNote}; ${backupNote}`].filter(Boolean).join("; ");
|
|
3488
3625
|
}
|
|
3489
|
-
if (
|
|
3490
|
-
|
|
3491
|
-
|
|
3626
|
+
if (record.note?.startsWith("orphaned:"))
|
|
3627
|
+
record.note = undefined;
|
|
3628
|
+
writeRunRecord(record, deps);
|
|
3629
|
+
return { kind: "transitioned", record };
|
|
3492
3630
|
}, { strict: true });
|
|
3493
|
-
if (settled !==
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
if (
|
|
3631
|
+
if (settled !== undefined)
|
|
3632
|
+
return settled;
|
|
3633
|
+
const record = readRunRecord2(runId, deps);
|
|
3634
|
+
if (!record)
|
|
3635
|
+
return { kind: "not_found" };
|
|
3636
|
+
if (isAgentRunTerminalStatus(record.status))
|
|
3637
|
+
return { kind: "kept", record };
|
|
3497
3638
|
return { kind: "contended", record };
|
|
3498
3639
|
}
|
|
3499
3640
|
var AUTHORITATIVE_SETTLE_MAX_ATTEMPTS = 4;
|
|
3500
3641
|
var AUTHORITATIVE_SETTLE_RETRY_DELAY_MS = 15;
|
|
3501
|
-
async function
|
|
3642
|
+
async function settleRunTerminalAuthoritatively2(runId, update, deps = {}, transition = transitionRunToTerminal2, options = {}) {
|
|
3502
3643
|
const attempt = () => transition(runId, update, deps, {
|
|
3503
3644
|
allowOverOrphaned: true,
|
|
3504
3645
|
...options.expectedPid != null ? { expectedPid: options.expectedPid } : {}
|
|
3505
3646
|
});
|
|
3506
3647
|
let result = attempt();
|
|
3507
|
-
for (let attemptNo = 1;
|
|
3648
|
+
for (let attemptNo = 1;result?.kind === "contended" && attemptNo < AUTHORITATIVE_SETTLE_MAX_ATTEMPTS; attemptNo += 1) {
|
|
3508
3649
|
await (deps.sleep ?? defaultSleep)(AUTHORITATIVE_SETTLE_RETRY_DELAY_MS);
|
|
3509
3650
|
result = attempt();
|
|
3510
3651
|
}
|
|
3511
3652
|
if (result?.kind === "contended") {
|
|
3512
|
-
console.error(
|
|
3513
|
-
`[nolo] authoritative settlement for run ${runId} lost the record lock ${AUTHORITATIVE_SETTLE_MAX_ATTEMPTS} times; durable record still ${result.record.status} \u2014 terminal status pending reconcile, child outcome (exitCode/dialogId/credits/DoD) may be lost`
|
|
3514
|
-
);
|
|
3653
|
+
console.error(`[nolo] authoritative settlement for run ${runId} lost the record lock ` + `${AUTHORITATIVE_SETTLE_MAX_ATTEMPTS} times; durable record still ` + `${result.record.status} — terminal status pending reconcile, child ` + `outcome (exitCode/dialogId/credits/DoD) may be lost`);
|
|
3515
3654
|
} else if (result?.kind === "kept" && result.record.status !== update.status) {
|
|
3516
3655
|
if (options.expectedPid != null && result.record.pid != null && result.record.pid !== options.expectedPid) {
|
|
3517
|
-
console.warn(
|
|
3518
|
-
`[nolo] run ${runId} belongs to PID ${result.record.pid}, not ${options.expectedPid}; keeping the durable record (${result.record.status}) over intended ${update.status}`
|
|
3519
|
-
);
|
|
3656
|
+
console.warn(`[nolo] run ${runId} belongs to PID ${result.record.pid}, not ${options.expectedPid}; ` + `keeping the durable record (${result.record.status}) over intended ${update.status}`);
|
|
3520
3657
|
} else {
|
|
3521
|
-
console.warn(
|
|
3522
|
-
`[nolo] run ${runId} already terminal (${result.record.status}); keeping the durable outcome over intended ${update.status}`
|
|
3523
|
-
);
|
|
3658
|
+
console.warn(`[nolo] run ${runId} already terminal (${result.record.status}); ` + `keeping the durable outcome over intended ${update.status}`);
|
|
3524
3659
|
}
|
|
3525
3660
|
}
|
|
3526
3661
|
return result ?? { kind: "not_found" };
|
|
3527
3662
|
}
|
|
3528
3663
|
function finalizeRunRecord(runId, update, deps = {}) {
|
|
3529
|
-
|
|
3664
|
+
transitionRunToTerminal2(runId, update, deps);
|
|
3530
3665
|
}
|
|
3531
|
-
function
|
|
3666
|
+
function isPidGone2(pid, deps = {}) {
|
|
3532
3667
|
const kill = deps.kill ?? ((p, s) => process.kill(p, s));
|
|
3533
3668
|
try {
|
|
3534
3669
|
kill(pid, 0);
|
|
@@ -3538,14 +3673,15 @@ function isPidGone(pid, deps = {}) {
|
|
|
3538
3673
|
}
|
|
3539
3674
|
}
|
|
3540
3675
|
function defaultGetProcessStartTime(pid, deps = {}) {
|
|
3541
|
-
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
3676
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
3677
|
+
return null;
|
|
3542
3678
|
try {
|
|
3543
3679
|
const execFileSync = deps.execFileSync ?? nodeExecFileSync;
|
|
3544
3680
|
if ((deps.platform ?? process.platform) === "win32") {
|
|
3545
3681
|
const resolvePowerShell = deps.resolvePowerShellExecutable ?? findPowerShellExecutable;
|
|
3546
3682
|
const systemRoot = (deps.env ?? process.env).SystemRoot;
|
|
3547
3683
|
const shell = resolvePowerShell() ?? (systemRoot ? join2(systemRoot, "System32", "WindowsPowerShell", "v1.0", "powershell.exe") : "powershell.exe");
|
|
3548
|
-
const
|
|
3684
|
+
const output = execFileSync(shell, [
|
|
3549
3685
|
"-NoProfile",
|
|
3550
3686
|
"-NonInteractive",
|
|
3551
3687
|
"-Command",
|
|
@@ -3553,34 +3689,30 @@ function defaultGetProcessStartTime(pid, deps = {}) {
|
|
|
3553
3689
|
], {
|
|
3554
3690
|
encoding: "utf8",
|
|
3555
3691
|
stdio: ["ignore", "pipe", "ignore"],
|
|
3556
|
-
timeout:
|
|
3692
|
+
timeout: 5000,
|
|
3557
3693
|
windowsHide: true
|
|
3558
3694
|
}).trim();
|
|
3559
|
-
if (!
|
|
3560
|
-
|
|
3695
|
+
if (!output)
|
|
3696
|
+
return null;
|
|
3697
|
+
const date = new Date(output);
|
|
3561
3698
|
return Number.isFinite(date.getTime()) ? date : null;
|
|
3562
3699
|
}
|
|
3563
3700
|
const output = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
3564
3701
|
encoding: "utf8",
|
|
3565
3702
|
stdio: ["ignore", "pipe", "ignore"],
|
|
3566
|
-
timeout:
|
|
3567
|
-
// `ps -o lstart` 的日期串随系统 locale 变化:
|
|
3568
|
-
// LANG=en_US.UTF-8 → "Thu Oct 8 08:54:18 2026"(new Date 可解析)
|
|
3569
|
-
// LANG=zh_CN.UTF-8 → "四 10月 8 08:54:18 2026"(new Date → NaN → null)
|
|
3570
|
-
// 这会让 isPidReused 的结论依赖调用者环境:同一条 run 记录在英文
|
|
3571
|
-
// locale 下被判 pid reused → orphaned,中文 locale 下不判。强制 C
|
|
3572
|
-
// locale 让输出恒为可解析的英文格式,结果与 locale 无关。
|
|
3703
|
+
timeout: 1000,
|
|
3573
3704
|
env: { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC" }
|
|
3574
3705
|
}).trim();
|
|
3575
|
-
if (!output)
|
|
3706
|
+
if (!output)
|
|
3707
|
+
return null;
|
|
3576
3708
|
const d = new Date(output.endsWith("Z") || /[+-]\d\d:\d\d$/.test(output) ? output : `${output} UTC`);
|
|
3577
3709
|
return isNaN(d.getTime()) ? null : d;
|
|
3578
3710
|
} catch {
|
|
3579
3711
|
return null;
|
|
3580
3712
|
}
|
|
3581
3713
|
}
|
|
3582
|
-
var MAX_PROCESS_START_TIME_DIFF_MS =
|
|
3583
|
-
var MAX_PERSISTED_PROCESS_START_TIME_DIFF_MS =
|
|
3714
|
+
var MAX_PROCESS_START_TIME_DIFF_MS = 30000;
|
|
3715
|
+
var MAX_PERSISTED_PROCESS_START_TIME_DIFF_MS = 2000;
|
|
3584
3716
|
function probeProcessStartTime(pid, deps) {
|
|
3585
3717
|
try {
|
|
3586
3718
|
const date = deps.getProcessStartTime ? deps.getProcessStartTime(pid) : defaultGetProcessStartTime(pid, deps);
|
|
@@ -3591,7 +3723,8 @@ function probeProcessStartTime(pid, deps) {
|
|
|
3591
3723
|
}
|
|
3592
3724
|
var ORPHAN_HEARTBEAT_GRACE_MS = 1e4;
|
|
3593
3725
|
function readTimestampMs(value) {
|
|
3594
|
-
if (!value)
|
|
3726
|
+
if (!value)
|
|
3727
|
+
return null;
|
|
3595
3728
|
const ms = new Date(value).getTime();
|
|
3596
3729
|
return Number.isNaN(ms) ? null : ms;
|
|
3597
3730
|
}
|
|
@@ -3601,32 +3734,42 @@ function isPidReused(pid, expectedStartedAt, deps = {}, maxDiffMs = MAX_PROCESS_
|
|
|
3601
3734
|
return false;
|
|
3602
3735
|
}
|
|
3603
3736
|
const recordTime = new Date(expectedStartedAt).getTime();
|
|
3604
|
-
if (isNaN(recordTime))
|
|
3737
|
+
if (isNaN(recordTime))
|
|
3738
|
+
return false;
|
|
3605
3739
|
const diffMs = Math.abs(procStartTime.getTime() - recordTime);
|
|
3606
3740
|
return diffMs > maxDiffMs;
|
|
3607
3741
|
}
|
|
3608
|
-
function
|
|
3609
|
-
const record =
|
|
3610
|
-
if (!record)
|
|
3611
|
-
|
|
3612
|
-
if (
|
|
3613
|
-
|
|
3742
|
+
function checkStaleRun2(runId, deps = {}) {
|
|
3743
|
+
const record = readRunRecord2(runId, deps);
|
|
3744
|
+
if (!record)
|
|
3745
|
+
return null;
|
|
3746
|
+
if (record.status !== "running")
|
|
3747
|
+
return record;
|
|
3748
|
+
if (typeof record.pid !== "number")
|
|
3749
|
+
return record;
|
|
3750
|
+
const pidGone = isPidGone2(record.pid, deps);
|
|
3614
3751
|
const expectedStartedAt = record.processStartedAt ?? record.startedAt;
|
|
3615
3752
|
const maxStartTimeDiffMs = record.processStartedAt ? MAX_PERSISTED_PROCESS_START_TIME_DIFF_MS : MAX_PROCESS_START_TIME_DIFF_MS;
|
|
3616
3753
|
const pidReused = !pidGone && record.processIdentity !== "unverified" && isPidReused(record.pid, expectedStartedAt, deps, maxStartTimeDiffMs);
|
|
3617
|
-
if (!pidGone && !pidReused)
|
|
3618
|
-
|
|
3754
|
+
if (!pidGone && !pidReused)
|
|
3755
|
+
return record;
|
|
3756
|
+
const now = deps.now ?? (() => new Date);
|
|
3619
3757
|
const heartbeatAt = readTimestampMs(record.activity?.updatedAt);
|
|
3620
3758
|
if (heartbeatAt !== null) {
|
|
3621
3759
|
const silentMs = now().getTime() - heartbeatAt;
|
|
3622
|
-
if (silentMs < ORPHAN_HEARTBEAT_GRACE_MS)
|
|
3760
|
+
if (silentMs < ORPHAN_HEARTBEAT_GRACE_MS)
|
|
3761
|
+
return record;
|
|
3623
3762
|
}
|
|
3624
3763
|
return withRunRecordLock(runId, deps, () => {
|
|
3625
|
-
const latest =
|
|
3626
|
-
if (!latest)
|
|
3627
|
-
|
|
3628
|
-
if (latest.
|
|
3629
|
-
|
|
3764
|
+
const latest = readRunRecord2(runId, deps);
|
|
3765
|
+
if (!latest)
|
|
3766
|
+
return record;
|
|
3767
|
+
if (latest.status !== "running")
|
|
3768
|
+
return latest;
|
|
3769
|
+
if (latest.pid !== record.pid || latest.processStartedAt !== record.processStartedAt || latest.processIdentity !== record.processIdentity)
|
|
3770
|
+
return latest;
|
|
3771
|
+
if (latest.activity?.updatedAt !== record.activity?.updatedAt)
|
|
3772
|
+
return latest;
|
|
3630
3773
|
const at = now().toISOString();
|
|
3631
3774
|
latest.status = "orphaned";
|
|
3632
3775
|
latest.note = pidReused ? "orphaned: process gone (pid reused by another process)" : "orphaned: process gone without writing terminal status";
|
|
@@ -3651,7 +3794,7 @@ function checkStaleRun(runId, deps = {}) {
|
|
|
3651
3794
|
...latest.execution?.state === "known" ? { executionOwner: latest.execution.owner } : {},
|
|
3652
3795
|
confirmedAt: at
|
|
3653
3796
|
};
|
|
3654
|
-
latest.pid =
|
|
3797
|
+
latest.pid = undefined;
|
|
3655
3798
|
writeRunRecord(latest, deps);
|
|
3656
3799
|
return latest;
|
|
3657
3800
|
}) ?? record;
|
|
@@ -3660,9 +3803,9 @@ function formatDuration(startedAt, endedAt) {
|
|
|
3660
3803
|
const start = new Date(startedAt).getTime();
|
|
3661
3804
|
const end = endedAt ? new Date(endedAt).getTime() : Date.now();
|
|
3662
3805
|
const elapsedMs = Math.max(0, end - start);
|
|
3663
|
-
const seconds = Math.floor(elapsedMs /
|
|
3664
|
-
const minutes = Math.floor(elapsedMs /
|
|
3665
|
-
const hours = Math.floor(elapsedMs /
|
|
3806
|
+
const seconds = Math.floor(elapsedMs / 1000) % 60;
|
|
3807
|
+
const minutes = Math.floor(elapsedMs / 60000) % 60;
|
|
3808
|
+
const hours = Math.floor(elapsedMs / 3600000);
|
|
3666
3809
|
if (hours > 0) {
|
|
3667
3810
|
return `${hours}h ${minutes}m ${seconds}s`;
|
|
3668
3811
|
}
|
|
@@ -3675,8 +3818,10 @@ function readLastLogLines(logPath, count, deps) {
|
|
|
3675
3818
|
const fs = deps.fs ?? nodeFs2;
|
|
3676
3819
|
try {
|
|
3677
3820
|
const content = fs.readFileSync(logPath, "utf8");
|
|
3678
|
-
const lines = content.split(
|
|
3679
|
-
|
|
3821
|
+
const lines = content.split(`
|
|
3822
|
+
`);
|
|
3823
|
+
if (lines.length > 0 && lines[lines.length - 1] === "")
|
|
3824
|
+
lines.pop();
|
|
3680
3825
|
return lines.slice(-count);
|
|
3681
3826
|
} catch {
|
|
3682
3827
|
return [];
|
|
@@ -3687,9 +3832,12 @@ function readLogContent(logPath, tailCount, deps) {
|
|
|
3687
3832
|
try {
|
|
3688
3833
|
const content = fs.readFileSync(logPath, "utf8");
|
|
3689
3834
|
if (typeof tailCount === "number" && tailCount > 0) {
|
|
3690
|
-
const lines = content.split(
|
|
3691
|
-
|
|
3692
|
-
|
|
3835
|
+
const lines = content.split(`
|
|
3836
|
+
`);
|
|
3837
|
+
if (lines.length > 0 && lines[lines.length - 1] === "")
|
|
3838
|
+
lines.pop();
|
|
3839
|
+
return `${lines.slice(-tailCount).join(`
|
|
3840
|
+
`)}
|
|
3693
3841
|
`;
|
|
3694
3842
|
}
|
|
3695
3843
|
return content;
|
|
@@ -3697,7 +3845,7 @@ function readLogContent(logPath, tailCount, deps) {
|
|
|
3697
3845
|
return "";
|
|
3698
3846
|
}
|
|
3699
3847
|
}
|
|
3700
|
-
var RUNNING_STATUSES =
|
|
3848
|
+
var RUNNING_STATUSES = new Set(["running"]);
|
|
3701
3849
|
function isRunningStatus(status) {
|
|
3702
3850
|
return RUNNING_STATUSES.has(status);
|
|
3703
3851
|
}
|
|
@@ -3719,32 +3867,33 @@ function parseJsonFlag(args) {
|
|
|
3719
3867
|
return { json, rest };
|
|
3720
3868
|
}
|
|
3721
3869
|
function defaultSleep(ms) {
|
|
3722
|
-
return new Promise((
|
|
3870
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3723
3871
|
}
|
|
3724
|
-
async function
|
|
3872
|
+
async function runAgentPsCommand2(args, deps) {
|
|
3725
3873
|
const { json } = parseJsonFlag(args);
|
|
3726
|
-
const records =
|
|
3874
|
+
const records = listRunRecords2(deps);
|
|
3727
3875
|
for (const record of records) {
|
|
3728
3876
|
if (record.status === "running" && typeof record.pid === "number") {
|
|
3729
|
-
|
|
3877
|
+
checkStaleRun2(record.runId, deps);
|
|
3730
3878
|
}
|
|
3731
3879
|
}
|
|
3732
|
-
const refreshed = records.map((r) =>
|
|
3880
|
+
const refreshed = records.map((r) => readRunRecord2(r.runId, deps)).filter(Boolean);
|
|
3733
3881
|
if (json) {
|
|
3734
|
-
deps.output.write(JSON.stringify(refreshed) +
|
|
3882
|
+
deps.output.write(JSON.stringify(refreshed) + `
|
|
3883
|
+
`);
|
|
3735
3884
|
return 0;
|
|
3736
3885
|
}
|
|
3737
3886
|
if (refreshed.length === 0) {
|
|
3738
|
-
deps.output.write(
|
|
3887
|
+
deps.output.write(`No local runs found.
|
|
3888
|
+
`);
|
|
3739
3889
|
return 0;
|
|
3740
3890
|
}
|
|
3741
|
-
deps.output.write(
|
|
3891
|
+
deps.output.write(`RUN ID STATUS PID AGENT
|
|
3892
|
+
`);
|
|
3742
3893
|
for (const record of refreshed) {
|
|
3743
3894
|
const pid = record.pid?.toString() ?? "-";
|
|
3744
|
-
deps.output.write(
|
|
3745
|
-
|
|
3746
|
-
`
|
|
3747
|
-
);
|
|
3895
|
+
deps.output.write(`${record.runId.padEnd(32)} ${record.status.padEnd(8)} ${pid.padEnd(8)} ${record.agentKey}
|
|
3896
|
+
`);
|
|
3748
3897
|
}
|
|
3749
3898
|
return 0;
|
|
3750
3899
|
}
|
|
@@ -3752,8 +3901,8 @@ function parseStatusArgs(args) {
|
|
|
3752
3901
|
let target = "";
|
|
3753
3902
|
let json = false;
|
|
3754
3903
|
let watch = false;
|
|
3755
|
-
let intervalMs =
|
|
3756
|
-
for (let i = 0;
|
|
3904
|
+
let intervalMs = 2000;
|
|
3905
|
+
for (let i = 0;i < args.length; i++) {
|
|
3757
3906
|
const arg = args[i];
|
|
3758
3907
|
if (arg === "--json") {
|
|
3759
3908
|
json = true;
|
|
@@ -3783,7 +3932,8 @@ function parseStatusArgs(args) {
|
|
|
3783
3932
|
}
|
|
3784
3933
|
if (arg.startsWith("--interval-ms=")) {
|
|
3785
3934
|
const value = arg.slice("--interval-ms=".length);
|
|
3786
|
-
if (/^\d+$/.test(value))
|
|
3935
|
+
if (/^\d+$/.test(value))
|
|
3936
|
+
intervalMs = Number(value);
|
|
3787
3937
|
continue;
|
|
3788
3938
|
}
|
|
3789
3939
|
if (!arg.startsWith("-") && !target) {
|
|
@@ -3795,57 +3945,55 @@ function parseStatusArgs(args) {
|
|
|
3795
3945
|
function printStatusTick(record, deps) {
|
|
3796
3946
|
const elapsed = formatDuration(record.startedAt, record.endedAt);
|
|
3797
3947
|
const note = record.note ? ` (${record.note})` : "";
|
|
3798
|
-
deps.output.write(
|
|
3799
|
-
|
|
3800
|
-
`
|
|
3801
|
-
);
|
|
3948
|
+
deps.output.write(`[${new Date().toISOString()}] ${record.runId} status=${record.status} elapsed=${elapsed}${note}
|
|
3949
|
+
`);
|
|
3802
3950
|
}
|
|
3803
|
-
async function
|
|
3951
|
+
async function runAgentStatusCommand2(args, deps) {
|
|
3804
3952
|
const includeCheckpoint = args.includes("--include-checkpoint");
|
|
3805
|
-
const { target, json, watch, intervalMs } = parseStatusArgs(
|
|
3806
|
-
args.filter((arg) => arg !== "--include-checkpoint")
|
|
3807
|
-
);
|
|
3953
|
+
const { target, json, watch, intervalMs } = parseStatusArgs(args.filter((arg) => arg !== "--include-checkpoint"));
|
|
3808
3954
|
if (!target) {
|
|
3809
|
-
deps.output.write(
|
|
3955
|
+
deps.output.write(`Usage: nolo agent status <runId|pid> [--json] [--include-checkpoint] [--watch] [--interval-ms N]
|
|
3956
|
+
`);
|
|
3810
3957
|
return 1;
|
|
3811
3958
|
}
|
|
3812
|
-
const initial =
|
|
3959
|
+
const initial = findRunRecord2(target, deps);
|
|
3813
3960
|
if (!initial) {
|
|
3814
3961
|
deps.output.write(`Run not found: ${target}
|
|
3815
3962
|
`);
|
|
3816
3963
|
return 1;
|
|
3817
3964
|
}
|
|
3818
|
-
const reconciled =
|
|
3965
|
+
const reconciled = checkStaleRun2(initial.runId, deps) ?? initial;
|
|
3819
3966
|
if (json) {
|
|
3820
|
-
const record =
|
|
3967
|
+
const record = readRunRecord2(reconciled.runId, deps) ?? reconciled;
|
|
3821
3968
|
const { partialCheckpoint, ...summary } = record;
|
|
3822
3969
|
deps.output.write(JSON.stringify({
|
|
3823
3970
|
...summary,
|
|
3824
|
-
...
|
|
3971
|
+
...localWriterRecovery2(record) ? { writerRecovery: localWriterRecovery2(record) } : {},
|
|
3825
3972
|
...includeCheckpoint ? { checkpoint: partialCheckpoint ? { ...partialCheckpoint, available: true } : { available: false, final: false, reason: "checkpoint_missing" } } : {}
|
|
3826
|
-
}) +
|
|
3973
|
+
}) + `
|
|
3974
|
+
`);
|
|
3827
3975
|
return 0;
|
|
3828
3976
|
}
|
|
3829
3977
|
if (includeCheckpoint) {
|
|
3830
|
-
const record =
|
|
3978
|
+
const record = readRunRecord2(reconciled.runId, deps) ?? reconciled;
|
|
3831
3979
|
deps.output.write(record.partialCheckpoint ? `Partial checkpoint (not final; source LLM round: ${record.partialCheckpoint.sourceRound ?? "unknown"}; current LLM round: ${record.partialCheckpoint.currentLlmRound ?? "unknown"}):
|
|
3832
3980
|
${record.partialCheckpoint.text}
|
|
3833
|
-
` :
|
|
3981
|
+
` : `Partial checkpoint unavailable.
|
|
3982
|
+
`);
|
|
3834
3983
|
}
|
|
3835
3984
|
if (!watch) {
|
|
3836
|
-
const record =
|
|
3985
|
+
const record = readRunRecord2(reconciled.runId, deps) ?? reconciled;
|
|
3837
3986
|
return printStatusOnce(record, deps);
|
|
3838
3987
|
}
|
|
3839
3988
|
return runStatusWatch(reconciled.runId, intervalMs, deps);
|
|
3840
3989
|
}
|
|
3841
3990
|
function formatActivitySummary(activity) {
|
|
3842
|
-
if (!activity)
|
|
3991
|
+
if (!activity)
|
|
3992
|
+
return;
|
|
3843
3993
|
const { counters, inFlight, lastEventAt } = activity;
|
|
3844
3994
|
const parts = [`${counters.fileEdits} edits, ${counters.toolCalls} tools`];
|
|
3845
3995
|
if (inFlight) {
|
|
3846
|
-
const elapsedSec = Math.floor(
|
|
3847
|
-
(Date.now() - new Date(lastEventAt).getTime()) / 1e3
|
|
3848
|
-
);
|
|
3996
|
+
const elapsedSec = Math.floor((Date.now() - new Date(lastEventAt).getTime()) / 1000);
|
|
3849
3997
|
parts.push(`in-flight ${inFlight.kind}${inFlight.name ? ` ${inFlight.name}` : ""} ${elapsedSec}s`);
|
|
3850
3998
|
}
|
|
3851
3999
|
return `activity: ${parts.join(", ")}`;
|
|
@@ -3857,8 +4005,9 @@ function printStatusOnce(record, deps) {
|
|
|
3857
4005
|
`);
|
|
3858
4006
|
deps.output.write(`pid: ${record.pid ?? "-"}
|
|
3859
4007
|
`);
|
|
3860
|
-
const recovery =
|
|
3861
|
-
if (recovery)
|
|
4008
|
+
const recovery = localWriterRecovery2(record);
|
|
4009
|
+
if (recovery)
|
|
4010
|
+
deps.output.write(`writerRecovery: required (${recovery.reason}); automatic release forbidden; native launch evidence required
|
|
3862
4011
|
`);
|
|
3863
4012
|
deps.output.write(`agent: ${record.agentKey}
|
|
3864
4013
|
`);
|
|
@@ -3868,9 +4017,11 @@ function printStatusOnce(record, deps) {
|
|
|
3868
4017
|
`);
|
|
3869
4018
|
deps.output.write(`elapsed: ${formatDuration(record.startedAt, record.endedAt)}
|
|
3870
4019
|
`);
|
|
3871
|
-
if (record.endedAt)
|
|
4020
|
+
if (record.endedAt)
|
|
4021
|
+
deps.output.write(`ended: ${record.endedAt}
|
|
3872
4022
|
`);
|
|
3873
|
-
if (typeof record.exitCode === "number")
|
|
4023
|
+
if (typeof record.exitCode === "number")
|
|
4024
|
+
deps.output.write(`exitCode: ${record.exitCode}
|
|
3874
4025
|
`);
|
|
3875
4026
|
if (record.ephemeral) {
|
|
3876
4027
|
deps.output.write(`dialog: ephemeral (no persisted child dialog)
|
|
@@ -3879,28 +4030,31 @@ function printStatusOnce(record, deps) {
|
|
|
3879
4030
|
deps.output.write(`dialog: ${record.dialogId}
|
|
3880
4031
|
`);
|
|
3881
4032
|
}
|
|
3882
|
-
if (record.note)
|
|
4033
|
+
if (record.note)
|
|
4034
|
+
deps.output.write(`note: ${record.note}
|
|
3883
4035
|
`);
|
|
3884
|
-
if (record.failureReason)
|
|
4036
|
+
if (record.failureReason)
|
|
4037
|
+
deps.output.write(`failure: ${record.failureReason}
|
|
3885
4038
|
`);
|
|
3886
4039
|
if (record.failureClass) {
|
|
3887
|
-
deps.output.write(
|
|
3888
|
-
|
|
3889
|
-
`
|
|
3890
|
-
);
|
|
4040
|
+
deps.output.write(`class: ${record.failureClass}${typeof record.retryable === "boolean" ? ` (retryable=${record.retryable})` : ""}
|
|
4041
|
+
`);
|
|
3891
4042
|
}
|
|
3892
4043
|
if (record.credentialGroup) {
|
|
3893
4044
|
deps.output.write(`credGroup: ${record.credentialGroup}
|
|
3894
4045
|
`);
|
|
3895
4046
|
}
|
|
3896
4047
|
const activitySummary = formatActivitySummary(record.activity);
|
|
3897
|
-
if (activitySummary)
|
|
4048
|
+
if (activitySummary)
|
|
4049
|
+
deps.output.write(`${activitySummary}
|
|
3898
4050
|
`);
|
|
3899
4051
|
deps.output.write(`log: ${record.logPath}
|
|
3900
4052
|
`);
|
|
3901
4053
|
const logLines = readLastLogLines(record.logPath, 20, deps);
|
|
3902
4054
|
if (logLines.length > 0) {
|
|
3903
|
-
deps.output.write(
|
|
4055
|
+
deps.output.write(`
|
|
4056
|
+
--- last log lines ---
|
|
4057
|
+
`);
|
|
3904
4058
|
for (const line of logLines) {
|
|
3905
4059
|
deps.output.write(`${line}
|
|
3906
4060
|
`);
|
|
@@ -3910,7 +4064,7 @@ function printStatusOnce(record, deps) {
|
|
|
3910
4064
|
}
|
|
3911
4065
|
async function runStatusWatch(runId, intervalMs, deps) {
|
|
3912
4066
|
const sleep = deps.sleep ?? defaultSleep;
|
|
3913
|
-
const now = deps.now ?? (() =>
|
|
4067
|
+
const now = deps.now ?? (() => new Date);
|
|
3914
4068
|
let stopped = false;
|
|
3915
4069
|
const setSignalHandler = deps.setSignalHandler ?? ((handler) => {
|
|
3916
4070
|
process.once("SIGINT", handler);
|
|
@@ -3922,7 +4076,7 @@ async function runStatusWatch(runId, intervalMs, deps) {
|
|
|
3922
4076
|
stopped = true;
|
|
3923
4077
|
});
|
|
3924
4078
|
try {
|
|
3925
|
-
let record =
|
|
4079
|
+
let record = readRunRecord2(runId, deps);
|
|
3926
4080
|
if (!record) {
|
|
3927
4081
|
deps.output.write(`Run not found: ${runId}
|
|
3928
4082
|
`);
|
|
@@ -3931,8 +4085,9 @@ async function runStatusWatch(runId, intervalMs, deps) {
|
|
|
3931
4085
|
printStatusTick(record, deps);
|
|
3932
4086
|
while (!stopped && isRunningStatus(record.status)) {
|
|
3933
4087
|
await sleep(intervalMs);
|
|
3934
|
-
if (stopped)
|
|
3935
|
-
|
|
4088
|
+
if (stopped)
|
|
4089
|
+
break;
|
|
4090
|
+
record = checkStaleRun2(runId, deps);
|
|
3936
4091
|
if (!record) {
|
|
3937
4092
|
deps.output.write(`Run not found: ${runId}
|
|
3938
4093
|
`);
|
|
@@ -3951,7 +4106,7 @@ async function runStatusWatch(runId, intervalMs, deps) {
|
|
|
3951
4106
|
}
|
|
3952
4107
|
function parseLogsArgs(args, onTail) {
|
|
3953
4108
|
let runId = "";
|
|
3954
|
-
for (let i = 0;
|
|
4109
|
+
for (let i = 0;i < args.length; i++) {
|
|
3955
4110
|
const arg = args[i];
|
|
3956
4111
|
if (arg === "--tail") {
|
|
3957
4112
|
const next = args[i + 1];
|
|
@@ -3963,7 +4118,8 @@ function parseLogsArgs(args, onTail) {
|
|
|
3963
4118
|
}
|
|
3964
4119
|
if (arg.startsWith("--tail=")) {
|
|
3965
4120
|
const value = arg.slice("--tail=".length);
|
|
3966
|
-
if (/^\d+$/.test(value))
|
|
4121
|
+
if (/^\d+$/.test(value))
|
|
4122
|
+
onTail(Number(value));
|
|
3967
4123
|
continue;
|
|
3968
4124
|
}
|
|
3969
4125
|
if (!arg.startsWith("-") && !runId) {
|
|
@@ -3972,16 +4128,17 @@ function parseLogsArgs(args, onTail) {
|
|
|
3972
4128
|
}
|
|
3973
4129
|
return runId;
|
|
3974
4130
|
}
|
|
3975
|
-
async function
|
|
4131
|
+
async function runAgentLogsCommand2(args, deps) {
|
|
3976
4132
|
let tailCount;
|
|
3977
4133
|
const runId = parseLogsArgs(args, (count) => {
|
|
3978
4134
|
tailCount = count;
|
|
3979
4135
|
});
|
|
3980
4136
|
if (!runId) {
|
|
3981
|
-
deps.output.write(
|
|
4137
|
+
deps.output.write(`Usage: nolo agent logs <runId> [--tail N]
|
|
4138
|
+
`);
|
|
3982
4139
|
return 1;
|
|
3983
4140
|
}
|
|
3984
|
-
const record =
|
|
4141
|
+
const record = readRunRecord2(runId, deps) ?? findRunRecordByPid(Number(runId), deps);
|
|
3985
4142
|
if (!record) {
|
|
3986
4143
|
deps.output.write(`Run not found: ${runId}
|
|
3987
4144
|
`);
|
|
@@ -3999,10 +4156,11 @@ async function runAgentLogsCommand(args, deps) {
|
|
|
3999
4156
|
}
|
|
4000
4157
|
var TERMINATE_GRACE_MS = 1e4;
|
|
4001
4158
|
var TERMINATE_POLL_MS = 250;
|
|
4002
|
-
var TERMINATE_KILL_GRACE_MS =
|
|
4003
|
-
async function
|
|
4159
|
+
var TERMINATE_KILL_GRACE_MS = 5000;
|
|
4160
|
+
async function terminateRunProcess2(record, initialSignal, deps) {
|
|
4004
4161
|
const pid = record.pid;
|
|
4005
|
-
if (typeof pid !== "number" || pid <= 0)
|
|
4162
|
+
if (typeof pid !== "number" || pid <= 0)
|
|
4163
|
+
return true;
|
|
4006
4164
|
const kill = deps.kill ?? ((p, s) => {
|
|
4007
4165
|
process.kill(p, s);
|
|
4008
4166
|
});
|
|
@@ -4010,17 +4168,18 @@ async function terminateRunProcess(record, initialSignal, deps) {
|
|
|
4010
4168
|
const nowMs = () => deps.now ? deps.now().getTime() : Date.now();
|
|
4011
4169
|
const signalGroup = (sig) => {
|
|
4012
4170
|
const fail = (reason) => {
|
|
4013
|
-
throw new Error(`Run ${record.runId}, pid ${pid}, platform ${deps.platform ?? process.platform}:
|
|
4171
|
+
throw new Error(`Run ${record.runId}, pid ${pid}, platform ${deps.platform ?? process.platform}: 身份未验证,无法安全终止 (${reason}). 可先确认进程状态或重启该 run;确认身份后重试 stop/kill。`);
|
|
4014
4172
|
};
|
|
4015
4173
|
const expectedMs = readTimestampMs(record.processStartedAt ?? record.startedAt);
|
|
4016
|
-
if (expectedMs === null)
|
|
4174
|
+
if (expectedMs === null)
|
|
4175
|
+
fail("no trusted process start baseline");
|
|
4017
4176
|
const maxDiffMs = record.processStartedAt ? MAX_PERSISTED_PROCESS_START_TIME_DIFF_MS : MAX_PROCESS_START_TIME_DIFF_MS;
|
|
4018
4177
|
const actual = probeProcessStartTime(pid, deps);
|
|
4019
4178
|
if (!actual || Math.abs(actual.getTime() - expectedMs) > maxDiffMs) {
|
|
4020
4179
|
fail("identity probe failed or PID start time mismatch");
|
|
4021
4180
|
}
|
|
4022
4181
|
const persisted = withRunRecordLock(record.runId, deps, () => {
|
|
4023
|
-
const latest =
|
|
4182
|
+
const latest = readRunRecord2(record.runId, deps);
|
|
4024
4183
|
if (latest) {
|
|
4025
4184
|
if (latest.pid !== pid || latest.processStartedAt !== record.processStartedAt || latest.startedAt !== record.startedAt) {
|
|
4026
4185
|
fail("record changed");
|
|
@@ -4030,38 +4189,39 @@ async function terminateRunProcess(record, initialSignal, deps) {
|
|
|
4030
4189
|
}
|
|
4031
4190
|
return true;
|
|
4032
4191
|
}, { strict: true });
|
|
4033
|
-
if (persisted !== true)
|
|
4192
|
+
if (persisted !== true)
|
|
4193
|
+
fail("identity persistence lock contended");
|
|
4034
4194
|
try {
|
|
4035
4195
|
if ((deps.platform ?? process.platform) !== "win32") {
|
|
4036
4196
|
kill(-pid, sig);
|
|
4037
4197
|
} else {
|
|
4038
4198
|
kill(pid, sig);
|
|
4039
4199
|
}
|
|
4040
|
-
} catch {
|
|
4041
|
-
}
|
|
4200
|
+
} catch {}
|
|
4042
4201
|
};
|
|
4043
|
-
if (
|
|
4202
|
+
if (isPidGone2(pid, deps))
|
|
4203
|
+
return true;
|
|
4044
4204
|
signalGroup(initialSignal);
|
|
4045
4205
|
if (initialSignal === "SIGTERM") {
|
|
4046
4206
|
const deadline = nowMs() + TERMINATE_GRACE_MS;
|
|
4047
4207
|
const maxIterations = Math.ceil(TERMINATE_GRACE_MS / TERMINATE_POLL_MS) + 1;
|
|
4048
4208
|
let iterations = 0;
|
|
4049
|
-
while (!
|
|
4209
|
+
while (!isPidGone2(pid, deps) && nowMs() < deadline && iterations < maxIterations) {
|
|
4050
4210
|
iterations += 1;
|
|
4051
4211
|
await sleep(TERMINATE_POLL_MS);
|
|
4052
4212
|
}
|
|
4053
4213
|
}
|
|
4054
|
-
if (!
|
|
4214
|
+
if (!isPidGone2(pid, deps)) {
|
|
4055
4215
|
signalGroup("SIGKILL");
|
|
4056
4216
|
const killDeadline = nowMs() + TERMINATE_KILL_GRACE_MS;
|
|
4057
4217
|
const maxIterations = Math.ceil(TERMINATE_KILL_GRACE_MS / TERMINATE_POLL_MS) + 1;
|
|
4058
4218
|
let iterations = 0;
|
|
4059
|
-
while (!
|
|
4219
|
+
while (!isPidGone2(pid, deps) && nowMs() < killDeadline && iterations < maxIterations) {
|
|
4060
4220
|
iterations += 1;
|
|
4061
4221
|
await sleep(TERMINATE_POLL_MS);
|
|
4062
4222
|
}
|
|
4063
4223
|
}
|
|
4064
|
-
return
|
|
4224
|
+
return isPidGone2(pid, deps);
|
|
4065
4225
|
}
|
|
4066
4226
|
async function runSignalCommand(args, signal, verb, deps) {
|
|
4067
4227
|
const target = args[0];
|
|
@@ -4070,13 +4230,13 @@ async function runSignalCommand(args, signal, verb, deps) {
|
|
|
4070
4230
|
`);
|
|
4071
4231
|
return 1;
|
|
4072
4232
|
}
|
|
4073
|
-
const record =
|
|
4233
|
+
const record = findRunRecord2(target, deps);
|
|
4074
4234
|
if (!record) {
|
|
4075
4235
|
deps.output.write(`Run not found: ${target}
|
|
4076
4236
|
`);
|
|
4077
4237
|
return 1;
|
|
4078
4238
|
}
|
|
4079
|
-
const reconciled = record.status === "running" && typeof record.pid === "number" &&
|
|
4239
|
+
const reconciled = record.status === "running" && typeof record.pid === "number" && isPidGone2(record.pid, deps) ? checkStaleRun2(record.runId, deps) ?? record : record;
|
|
4080
4240
|
if (isAgentRunTerminalStatus(reconciled.status)) {
|
|
4081
4241
|
deps.output.write(`Run ${reconciled.runId} is already ${reconciled.status}.
|
|
4082
4242
|
`);
|
|
@@ -4089,141 +4249,40 @@ async function runSignalCommand(args, signal, verb, deps) {
|
|
|
4089
4249
|
}
|
|
4090
4250
|
let confirmed;
|
|
4091
4251
|
try {
|
|
4092
|
-
confirmed = await
|
|
4252
|
+
confirmed = await terminateRunProcess2(reconciled, signal, deps);
|
|
4093
4253
|
} catch (error) {
|
|
4094
4254
|
deps.output.write(`${error instanceof Error ? error.message : String(error)}
|
|
4095
4255
|
`);
|
|
4096
4256
|
return 1;
|
|
4097
4257
|
}
|
|
4098
4258
|
if (!confirmed) {
|
|
4099
|
-
deps.output.write(
|
|
4100
|
-
|
|
4101
|
-
`
|
|
4102
|
-
);
|
|
4259
|
+
deps.output.write(`Failed to ${verb} ${record.runId} (pid ${record.pid}): process still alive after SIGKILL.
|
|
4260
|
+
`);
|
|
4103
4261
|
return 1;
|
|
4104
4262
|
}
|
|
4105
|
-
const transition =
|
|
4106
|
-
deps.output.write(
|
|
4107
|
-
transition.kind === "contended" ? `Stopped ${reconciled.runId} (pid ${reconciled.pid}): process group confirmed gone; terminal status pending reconcile.
|
|
4263
|
+
const transition = transitionRunToTerminal2(reconciled.runId, { status: "killed" }, deps);
|
|
4264
|
+
deps.output.write(transition.kind === "contended" ? `Stopped ${reconciled.runId} (pid ${reconciled.pid}): process group confirmed gone; terminal status pending reconcile.
|
|
4108
4265
|
` : `Stopped ${reconciled.runId} (pid ${reconciled.pid}): process group confirmed gone.
|
|
4109
|
-
`
|
|
4110
|
-
);
|
|
4266
|
+
`);
|
|
4111
4267
|
return 0;
|
|
4112
4268
|
}
|
|
4113
|
-
async function
|
|
4269
|
+
async function runAgentStopCommand2(args, deps) {
|
|
4114
4270
|
return runSignalCommand(args, "SIGTERM", "stop", deps);
|
|
4115
4271
|
}
|
|
4116
|
-
async function
|
|
4272
|
+
async function runAgentKillCommand2(args, deps) {
|
|
4117
4273
|
return runSignalCommand(args, "SIGKILL", "kill", deps);
|
|
4118
4274
|
}
|
|
4119
|
-
async function
|
|
4275
|
+
async function runAgentRecoverPreparedWriterCommand2(args, deps) {
|
|
4120
4276
|
if (args.length !== 3 || args[1] !== "--attempt-id" || !/^[A-Za-z0-9_-]+$/.test(args[0] ?? "") || !args[2] || args[2].startsWith("-")) {
|
|
4121
|
-
deps.output.write(
|
|
4277
|
+
deps.output.write(`Usage: nolo agent recover-prepared-writer <runId> --attempt-id <attemptId>
|
|
4278
|
+
`);
|
|
4122
4279
|
return 1;
|
|
4123
4280
|
}
|
|
4124
4281
|
const [runId, , attemptId] = args;
|
|
4125
|
-
const outcome =
|
|
4126
|
-
deps.output.write(JSON.stringify({ action: "recoverPreparedWriter", runId, attemptId, outcome }) +
|
|
4282
|
+
const outcome = revokePreparedWriterLaunch2(runId, attemptId, deps);
|
|
4283
|
+
deps.output.write(JSON.stringify({ action: "recoverPreparedWriter", runId, attemptId, outcome }) + `
|
|
4284
|
+
`);
|
|
4127
4285
|
return outcome === "blocked" ? 1 : 0;
|
|
4128
4286
|
}
|
|
4129
4287
|
|
|
4130
|
-
export {
|
|
4131
|
-
createMcpApprovalChild,
|
|
4132
|
-
hasLiveShellApprovalHosts,
|
|
4133
|
-
createShellApprovalChild,
|
|
4134
|
-
TAIL_LINES_MAX,
|
|
4135
|
-
readHostMemory,
|
|
4136
|
-
assertHostMemoryAdmission,
|
|
4137
|
-
resolveResultServerMeta,
|
|
4138
|
-
recordRunResultHeaderMeta,
|
|
4139
|
-
getRunResultHeaderMeta,
|
|
4140
|
-
serverOriginForDialog,
|
|
4141
|
-
isHistoryIntegrityFailure,
|
|
4142
|
-
deriveRunFinalObservation,
|
|
4143
|
-
RUN_TERMINAL_STATUSES,
|
|
4144
|
-
isRunTerminalStatus,
|
|
4145
|
-
resolveNoloHome,
|
|
4146
|
-
resolveRunsDir,
|
|
4147
|
-
resolveRunRecordPath,
|
|
4148
|
-
resolveRunLogPath,
|
|
4149
|
-
resolveRunQueuePath,
|
|
4150
|
-
defaultGenerateQueueEntryId,
|
|
4151
|
-
_parseQueueLines,
|
|
4152
|
-
parseQueueLines,
|
|
4153
|
-
_serializeQueueEntries,
|
|
4154
|
-
serializeQueueEntries,
|
|
4155
|
-
_countQueueMessagesLocked,
|
|
4156
|
-
_readQueueMessagesLocked,
|
|
4157
|
-
_readQueueEntriesLocked,
|
|
4158
|
-
QUEUE_LOCK_STALE_MS,
|
|
4159
|
-
QUEUE_LOCK_RETRIES,
|
|
4160
|
-
QUEUE_LOCK_RETRY_INTERVAL_MS,
|
|
4161
|
-
defaultGenerateOwnerTokenId,
|
|
4162
|
-
withQueueLock,
|
|
4163
|
-
appendRunQueue,
|
|
4164
|
-
countQueueMessages,
|
|
4165
|
-
readQueueMessages,
|
|
4166
|
-
readQueueEntries,
|
|
4167
|
-
popAllQueueEntries,
|
|
4168
|
-
popSingleQueueMessage,
|
|
4169
|
-
popQueueMessages,
|
|
4170
|
-
defaultGenerateRunId,
|
|
4171
|
-
defaultGenerateBatchId,
|
|
4172
|
-
withRunRecordLock,
|
|
4173
|
-
writeRunRecord,
|
|
4174
|
-
reportRunProcessIdentity,
|
|
4175
|
-
createRunActivityTracker,
|
|
4176
|
-
readRunRecord,
|
|
4177
|
-
backfillRunRecordParentDialog,
|
|
4178
|
-
listRunRecords,
|
|
4179
|
-
listRecentRunRecords,
|
|
4180
|
-
listRunRecordsAsync,
|
|
4181
|
-
findRunRecordByPid,
|
|
4182
|
-
findRunRecord,
|
|
4183
|
-
DEFAULT_LIST_LIMIT,
|
|
4184
|
-
MAX_LIST_LIMIT,
|
|
4185
|
-
queryRunRecords,
|
|
4186
|
-
DEFAULT_GC_RETENTION_MS,
|
|
4187
|
-
gcRunRecords,
|
|
4188
|
-
stripBackgroundFlag,
|
|
4189
|
-
absolutizeSkillArgs,
|
|
4190
|
-
rewriteMsgFileArg,
|
|
4191
|
-
buildAgentRunChildCommand,
|
|
4192
|
-
localWriterRecovery,
|
|
4193
|
-
revokePreparedWriterLaunch,
|
|
4194
|
-
validateLocalWriterChild,
|
|
4195
|
-
awaitLocalWriterChild,
|
|
4196
|
-
resolveLocalContinuation,
|
|
4197
|
-
registerLocalForegroundWriter,
|
|
4198
|
-
recordRunStartup,
|
|
4199
|
-
settleBackgroundProcessExit,
|
|
4200
|
-
spawnLocalBackgroundRun,
|
|
4201
|
-
ackRunRecord,
|
|
4202
|
-
DEFAULT_ACK_LEASE_TTL_MS,
|
|
4203
|
-
isAckLeaseExpired,
|
|
4204
|
-
isRunRecordClaimed,
|
|
4205
|
-
claimRunRecord,
|
|
4206
|
-
commitRunRecordClaim,
|
|
4207
|
-
releaseRunRecordAck,
|
|
4208
|
-
transitionRunToTerminal,
|
|
4209
|
-
AUTHORITATIVE_SETTLE_MAX_ATTEMPTS,
|
|
4210
|
-
AUTHORITATIVE_SETTLE_RETRY_DELAY_MS,
|
|
4211
|
-
settleRunTerminalAuthoritatively,
|
|
4212
|
-
finalizeRunRecord,
|
|
4213
|
-
isPidGone,
|
|
4214
|
-
defaultGetProcessStartTime,
|
|
4215
|
-
MAX_PROCESS_START_TIME_DIFF_MS,
|
|
4216
|
-
ORPHAN_HEARTBEAT_GRACE_MS,
|
|
4217
|
-
isPidReused,
|
|
4218
|
-
checkStaleRun,
|
|
4219
|
-
runAgentPsCommand,
|
|
4220
|
-
runAgentStatusCommand,
|
|
4221
|
-
runAgentLogsCommand,
|
|
4222
|
-
TERMINATE_GRACE_MS,
|
|
4223
|
-
TERMINATE_POLL_MS,
|
|
4224
|
-
TERMINATE_KILL_GRACE_MS,
|
|
4225
|
-
terminateRunProcess,
|
|
4226
|
-
runAgentStopCommand,
|
|
4227
|
-
runAgentKillCommand,
|
|
4228
|
-
runAgentRecoverPreparedWriterCommand
|
|
4229
|
-
};
|
|
4288
|
+
export { createMcpApprovalChild, hasLiveShellApprovalHosts, createShellApprovalChild, TAIL_LINES_MAX, readHostMemory, assertHostMemoryAdmission, resolveResultServerMeta, recordRunResultHeaderMeta, getRunResultHeaderMeta, serverOriginForDialog, isHistoryIntegrityFailure, isRunTerminalStatus2, resolveRunsDir2, resolveRunQueuePath2, serializeQueueEntries2, _readQueueEntriesLocked2, withQueueLock2, appendRunQueue2, popSingleQueueMessage2, defaultGenerateRunId2, reportRunProcessIdentity2, createRunActivityTracker2, readRunRecord2, backfillRunRecordParentDialog2, listRunRecords2, listRecentRunRecords2, listRunRecordsAsync2, findRunRecord2, queryRunRecords2, gcRunRecords2, localWriterRecovery2, revokePreparedWriterLaunch2, awaitLocalWriterChild2, resolveLocalContinuation2, registerLocalForegroundWriter2, recordRunStartup2, spawnLocalBackgroundRun2, ackRunRecord2, isRunRecordClaimed2, claimRunRecord2, commitRunRecordClaim2, releaseRunRecordAck2, transitionRunToTerminal2, settleRunTerminalAuthoritatively2, isPidGone2, checkStaleRun2, runAgentPsCommand2, runAgentStatusCommand2, runAgentLogsCommand2, terminateRunProcess2, runAgentStopCommand2, runAgentKillCommand2, runAgentRecoverPreparedWriterCommand2 };
|