nolo-cli 0.213.0 → 0.220.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/README.md +3 -2
  2. package/{_executeModel-CUJLCFWR.js → _executeModel-BNEMFCAO.js} +125 -96
  3. package/{accountResolver-4LKIHEKL.js → accountResolver-QETKNC7T.js} +4 -4
  4. package/{action-DF5UYSJF.js → action-GDZDXPMB.js} +14 -13
  5. package/{addContentAction-WERAONNY.js → addContentAction-7RO4AMRI.js} +21 -20
  6. package/{addDialogAgentAction-7VI7YRML.js → addDialogAgentAction-EVYBGTXB.js} +26 -25
  7. package/{agentDeleteCommand-XJORXPGU.js → agentDeleteCommand-7QTQNFCO.js} +145 -137
  8. package/{agentEmailCommands-XTYYFR6Z.js → agentEmailCommands-I7SHOSD6.js} +146 -139
  9. package/{agentFavoriteCommands-EDK743YA.js → agentFavoriteCommands-7LOP3HUD.js} +11 -12
  10. package/{agentGrantCommands-RQWK2TEV.js → agentGrantCommands-L6O2HVJI.js} +9 -9
  11. package/{agentListCommands-OBLRBLHS.js → agentListCommands-GUGMORTK.js} +180 -103
  12. package/{agentMachineCommands-5FMT3OT5.js → agentMachineCommands-UMDKILU3.js} +75 -66
  13. package/{agentProviderCommands-Q5O33MED.js → agentProviderCommands-STI3DQ6A.js} +8 -8
  14. package/{agentPullCommand-6EM3URVK.js → agentPullCommand-KHV4EELF.js} +11 -11
  15. package/agentRecordCommands-YTAMTHOY.js +175 -0
  16. package/agentRunCommand-DBM6YNO6.js +207 -0
  17. package/{agentRunControl-TAMHJQSR.js → agentRunControl-MBG4U6SL.js} +40 -19
  18. package/{agentRuntimeLocal-SOO2OPJG.js → agentRuntimeLocal-TU4LA353.js} +55 -48
  19. package/{agentSlice-CHR6KOZN.js → agentSlice-DPG7Q7IA.js} +24 -23
  20. package/{appDeleteCommands-GUP6P5YE.js → appDeleteCommands-JWP3XPUA.js} +67 -58
  21. package/{appDeployCommands-MH2FX4O5.js → appDeployCommands-6E4TQCWI.js} +67 -58
  22. package/{appDeployStatusCommands-SUHN3HPJ.js → appDeployStatusCommands-ALU4SADG.js} +67 -58
  23. package/{appGetCommands-YWDEX6Z4.js → appGetCommands-JEY4L6L4.js} +67 -58
  24. package/{appListCommands-ZQVMLPAY.js → appListCommands-PCAVHU7M.js} +67 -58
  25. package/{authCommand-PWX2ZNUP.js → authCommand-CGRIIOOV.js} +37 -33
  26. package/{authCommands-HV3EAU3V.js → authCommands-55OGQGCR.js} +16 -12
  27. package/{builtinSkillRegistry-2QETTQPM.js → builtinSkillRegistry-BAE2LDXF.js} +11 -13
  28. package/{chromeCommands-REEAH4SX.js → chromeCommands-G5UDKVSV.js} +3 -3
  29. package/{chromeOpsCommands-DIVM2K3T.js → chromeOpsCommands-WAA45NCS.js} +23 -13
  30. package/{chunk-VNYYOX3V.js → chunk-262R3XNN.js} +157 -50
  31. package/chunk-2MCB7CD7.js +98 -0
  32. package/{chunk-CTPXME7U.js → chunk-2NPD3FTX.js} +30 -7
  33. package/{chunk-YB3YZK56.js → chunk-2WZXXAQD.js} +1 -67
  34. package/{chunk-HRMJUN5J.js → chunk-2X7WFDT6.js} +1 -1
  35. package/chunk-2YGBI2XB.js +30 -0
  36. package/{chunk-TY3TIUJK.js → chunk-324FWHUA.js} +85 -3
  37. package/{chunk-KFLT5KAD.js → chunk-3NNXR7EH.js} +20 -20
  38. package/{chunk-ZRSNONOB.js → chunk-3P54D2E4.js} +8 -3
  39. package/{chunk-7OCO4TDT.js → chunk-3U44JB3O.js} +1 -1
  40. package/{chunk-TX5EYMGT.js → chunk-44J7Z5AQ.js} +34 -258
  41. package/chunk-4D4QD7FT.js +201 -0
  42. package/chunk-4I2MXV5Q.js +275 -0
  43. package/{chunk-MYOH447Z.js → chunk-4JVNURX4.js} +1 -1
  44. package/{chunk-COFEN36Z.js → chunk-4ZGPHFLE.js} +3 -3
  45. package/{chunk-ZXOUUDCG.js → chunk-53MFERZ3.js} +3869 -362
  46. package/chunk-547ENH5T.js +226 -0
  47. package/{chunk-YDH3FDFQ.js → chunk-5FUN7EG4.js} +1 -1
  48. package/{chunk-6DWMYIUY.js → chunk-5WKDR7HS.js} +14 -9
  49. package/chunk-5ZUOVCKT.js +32 -0
  50. package/{chunk-T43B7LB2.js → chunk-62HXNQVV.js} +1 -1
  51. package/{chunk-ZC3CMUKU.js → chunk-6OVNSQHN.js} +84 -2
  52. package/{chunk-IXNGOHV5.js → chunk-6QHKRARD.js} +12 -153
  53. package/{chunk-4T2WNOY7.js → chunk-6RDBLXVQ.js} +28 -17
  54. package/{chunk-EYLGAEB4.js → chunk-6XRPBZRS.js} +134 -0
  55. package/{chunk-KIM6CLW5.js → chunk-7JGMNKKG.js} +57 -26
  56. package/{chunk-P5L7CXOC.js → chunk-7Z6EW7AH.js} +3 -2
  57. package/chunk-AGYPUBFW.js +686 -0
  58. package/{chunk-Y63ZSOR6.js → chunk-AL3TYDIF.js} +1 -1
  59. package/{chunk-NOKUNJON.js → chunk-ALAES342.js} +75 -94
  60. package/{chunk-4I7ERB7F.js → chunk-ATEKLSLR.js} +2 -2
  61. package/{chunk-CRHOO2ZR.js → chunk-AUAJTAFM.js} +8 -8
  62. package/{chunk-LLRPJECG.js → chunk-AWIL6EHN.js} +15 -157
  63. package/chunk-BIDSIRTS.js +307 -0
  64. package/chunk-BIWI5M4E.js +62 -0
  65. package/{chunk-4VJAC32I.js → chunk-BNMPUQW6.js} +3 -2
  66. package/{chunk-RLBNLZVC.js → chunk-BP5ZJ6B4.js} +1 -1
  67. package/{chunk-NBTY7YJF.js → chunk-BR3GT6MR.js} +1 -0
  68. package/{chunk-7RFNTILS.js → chunk-BUDVRYES.js} +2 -2
  69. package/{chunk-SVYO6AO7.js → chunk-BV3FLP2L.js} +41 -1
  70. package/{chunk-ZL5RAEEB.js → chunk-CBUZ6DKA.js} +3 -3
  71. package/{chunk-SM3NSZJV.js → chunk-CD3RU7XL.js} +36 -2
  72. package/chunk-CMMI3DAT.js +1621 -0
  73. package/{chunk-J2NHJ7WX.js → chunk-CYWNWA77.js} +6 -6
  74. package/{chunk-MOIJOHA5.js → chunk-D6YNCNM6.js} +35 -21
  75. package/{chunk-H2TJUNCH.js → chunk-DBUR22G5.js} +16 -16
  76. package/chunk-DEA37IUY.js +271 -0
  77. package/{chunk-O2TZF4AI.js → chunk-DGYCDA6W.js} +4 -4
  78. package/{chunk-YWSEPJ7C.js → chunk-DUUDXSLX.js} +21 -7
  79. package/{chunk-KFHREHUQ.js → chunk-DXWGFL2Z.js} +89 -1
  80. package/{chunk-H5HF7TJA.js → chunk-EEOOBRA7.js} +6 -6
  81. package/{chunk-Y6ORVLSS.js → chunk-EVGU5P4U.js} +1 -1
  82. package/chunk-EWQ3HGNZ.js +90 -0
  83. package/{chunk-6VLJ6YA7.js → chunk-F6Z6ZCUV.js} +9 -9
  84. package/{chunk-75XIDFBW.js → chunk-FJ23FZXF.js} +72 -28
  85. package/chunk-FJSNBZXR.js +142 -0
  86. package/{chunk-WRYQ35LQ.js → chunk-G7IUT2V3.js} +860 -57
  87. package/{chunk-PCLE46CE.js → chunk-GBWGPTA7.js} +2 -1
  88. package/{chunk-H7PPIYWP.js → chunk-GPOV42YM.js} +19 -19
  89. package/{chunk-W4S457LU.js → chunk-GUXZK7SE.js} +42 -6
  90. package/{chunk-QHPRUL4O.js → chunk-GV6PRJBU.js} +4 -4
  91. package/{chunk-YUA6OAH5.js → chunk-HBRDSQ3M.js} +2 -2
  92. package/{chunk-G7MLNNEX.js → chunk-HHFGE2WF.js} +7 -7
  93. package/{chunk-OQPKUBPB.js → chunk-HSSBDZLD.js} +19 -7
  94. package/{chunk-EHSZD5OI.js → chunk-HXER7YJF.js} +4 -4
  95. package/{chunk-TAKB25RM.js → chunk-HYLRQDEE.js} +6 -6
  96. package/{chunk-LOEO7LRC.js → chunk-ILHQ2AXT.js} +10 -8
  97. package/{chunk-BBJ22CLB.js → chunk-JJMR2EA3.js} +64 -34
  98. package/{chunk-G2BQWAVT.js → chunk-JLAMNSBC.js} +4 -4
  99. package/{chunk-RSHTSUEG.js → chunk-JUSHVFNF.js} +2133 -622
  100. package/{chunk-YJAFKXMU.js → chunk-KHVFJSVE.js} +54 -49
  101. package/{chunk-X7SDOJUM.js → chunk-KRI6N5QZ.js} +16 -16
  102. package/{chunk-7BT37FK3.js → chunk-L32W3PRP.js} +675 -128
  103. package/chunk-LKA64WH4.js +227 -0
  104. package/{chunk-HUBHAQK2.js → chunk-LMRRCEDE.js} +31 -31
  105. package/chunk-M4SFKP5L.js +675 -0
  106. package/{chunk-MDB67IWP.js → chunk-MSMHU36U.js} +12 -12
  107. package/{chunk-7Y4YTDQF.js → chunk-MXKWTPUM.js} +288 -166
  108. package/{chunk-WYDI6TGM.js → chunk-MXRUXMZ3.js} +94 -135
  109. package/{chunk-AZMYUSVF.js → chunk-N5Z2V73W.js} +1 -1
  110. package/{chunk-QG4AOSON.js → chunk-NHY322ZU.js} +154 -32
  111. package/{chunk-UHJGXRJ4.js → chunk-OBIC6EG7.js} +6 -6
  112. package/{chunk-GOO6G4PY.js → chunk-OBSEKCVK.js} +123 -70
  113. package/{chunk-WMTBPBMP.js → chunk-OG6MQOQG.js} +130 -60
  114. package/{chunk-XJWWBO34.js → chunk-OJKUU3LP.js} +5 -7
  115. package/{chunk-ALQ3657A.js → chunk-OOJNQK6V.js} +21 -1
  116. package/{chunk-NSAPDIN2.js → chunk-OWKNSIXL.js} +679 -74
  117. package/{chunk-6XIE5ZGI.js → chunk-PDCV7P5W.js} +1 -1
  118. package/{chunk-A7TFUNZO.js → chunk-PPJYZRSQ.js} +6 -2
  119. package/{chunk-F6UUQOG6.js → chunk-Q3IVPFVO.js} +4 -4
  120. package/{chunk-VO4WSAVP.js → chunk-QBZCGP34.js} +3 -3
  121. package/chunk-QCB42576.js +13 -0
  122. package/chunk-QHEN7NZ7.js +46 -0
  123. package/{chunk-3UKL3HPD.js → chunk-QJTZ76CP.js} +32 -84
  124. package/{chunk-V5Y3R6BT.js → chunk-QRGDJA4B.js} +215 -212
  125. package/{chunk-4KB6WQUL.js → chunk-QYB23WUH.js} +1 -1
  126. package/{chunk-ZNWI6OVT.js → chunk-R44TU3MZ.js} +85 -11
  127. package/{chunk-PYRUW7XN.js → chunk-R6Z5S5GA.js} +139 -57
  128. package/{chunk-VL5KOY2C.js → chunk-R7XWZDOH.js} +125 -29
  129. package/{chunk-R5O4QAWG.js → chunk-RBPUNSG5.js} +11 -77
  130. package/{chunk-NJLL224W.js → chunk-RG2DGNL6.js} +3 -3
  131. package/{chunk-C6KNNXWU.js → chunk-RGQ4UUWZ.js} +25 -2
  132. package/{chunk-TCZHTTUU.js → chunk-RTHFJZ6M.js} +11 -11
  133. package/{chunk-RZOV7OMV.js → chunk-RYOLWYBK.js} +146 -200
  134. package/{chunk-OWYYDMGJ.js → chunk-S2NTVGA2.js} +4 -2
  135. package/{chunk-XHQC4PXX.js → chunk-S5NA3C52.js} +488 -226
  136. package/{secretCommands-LXDWOLZ6.js → chunk-S6FDXXZV.js} +190 -15
  137. package/chunk-S6K5F3KP.js +99 -0
  138. package/{chunk-INN4LTAJ.js → chunk-SRCCSTIM.js} +8 -8
  139. package/{chunk-JY5NGFFH.js → chunk-SYTHYBMI.js} +5 -5
  140. package/{chunk-UYD5HQ6T.js → chunk-SZVMASJ2.js} +3300 -1396
  141. package/{chunk-FUGMREBO.js → chunk-TGNIKIHR.js} +3 -3
  142. package/{chunk-HPFCI4SK.js → chunk-TI2EPRHE.js} +4 -4
  143. package/chunk-TLE77UJ5.js +230 -0
  144. package/chunk-TSPMLCWI.js +364 -0
  145. package/{chunk-YGILMZ7N.js → chunk-TUSTONB3.js} +1 -1
  146. package/{chunk-4VNS5WPM.js → chunk-U67V476Y.js} +1 -8
  147. package/{chunk-F7CI2ZC5.js → chunk-UAIHKQIA.js} +2 -1
  148. package/{chunk-WPORQFYN.js → chunk-UVLYNWIE.js} +2 -2
  149. package/{chunk-H4UOTUOX.js → chunk-VMJVAJ6W.js} +152 -19
  150. package/{chunk-KC4XDTT3.js → chunk-VS276URX.js} +4 -4
  151. package/{chunk-YTF4WH7J.js → chunk-WWTSEBDF.js} +1 -1
  152. package/{chunk-E2BESSAW.js → chunk-X4O7FJF5.js} +2 -0
  153. package/{chunk-RPQXPZZF.js → chunk-XSW4EXQV.js} +976 -17
  154. package/{chunk-7QTZCMKL.js → chunk-XTETTSKN.js} +3036 -2468
  155. package/{chunk-J5JTMQIA.js → chunk-YFLVRVYK.js} +1 -1
  156. package/chunk-YKY4OVOX.js +1141 -0
  157. package/{chunk-MMA3LZ3W.js → chunk-YNIYE47Z.js} +1 -1
  158. package/chunk-YZMNK53S.js +68 -0
  159. package/{chunk-FY7F4Q6X.js → chunk-Z4PCXPUE.js} +2 -2
  160. package/{chunk-INUFILG6.js → chunk-ZH3KXFHS.js} +11 -3
  161. package/chunk-ZOHO6MOF.js +376 -0
  162. package/{cliAgentConfigHelpers-WJBZQTLW.js → cliAgentConfigHelpers-BTRHMPW2.js} +18 -19
  163. package/{cliAuthorityBrokerClient-PM3U6Q6J.js → cliAuthorityBrokerClient-XHH7MH2P.js} +1 -1
  164. package/{cliAuthorityStoreDriver-TKLXNNTG.js → cliAuthorityStoreDriver-6FE3BJNB.js} +1 -1
  165. package/{cliEnvHelpers-BVYTMUPJ.js → cliEnvHelpers-CNMP3RDX.js} +3 -3
  166. package/{cliExecutor-BWBF2MTI.js → cliExecutor-K6FDZTQ2.js} +4 -2
  167. package/cliLocalAgentRecordReader-M3F76NIP.js +90 -0
  168. package/{commandRegistry-W63CYRZJ.js → commandRegistry-T3UBK6OA.js} +105 -97
  169. package/{contentThunks-U7PL5MQD.js → contentThunks-YEPZAHXU.js} +53 -48
  170. package/{cooldownCommands-TIGUHXTD.js → cooldownCommands-YB5H5BBK.js} +5 -4
  171. package/{createAgentAutomationAction-OLBQDD6R.js → createAgentAutomationAction-TBIIO5WT.js} +51 -48
  172. package/{createDialogAction-SVH6B3SB.js → createDialogAction-KBKMYFTQ.js} +52 -53
  173. package/{createPageAction-F4DIWZ2Z.js → createPageAction-3FGAPLJO.js} +56 -53
  174. package/{cursorProvider-YGGNMVWX.js → cursorProvider-2RACMEMF.js} +1 -1
  175. package/{db-HUCI5R4G.js → db-M7FU2GNK.js} +10 -7
  176. package/{dbSlice-BVH2YZPQ.js → dbSlice-XRUZOGSU.js} +20 -19
  177. package/{deleteFile-5YOEKV4U.js → deleteFile-6URDHYRB.js} +12 -12
  178. package/{desktopFolderProjects-SFY5EZS3.js → desktopFolderProjects-4POAMVJN.js} +2 -2
  179. package/{dialogCommands-KHIEPY3M.js → dialogCommands-NRLCOPJR.js} +71 -64
  180. package/dialogNotifyCommand-SHGPCU22.js +36 -0
  181. package/{dialogSlice-ZCTDV2PZ.js → dialogSlice-DP2WTMNO.js} +48 -45
  182. package/{dialogUsageCommand-7KCPYGHG.js → dialogUsageCommand-W2WCSGKF.js} +11 -10
  183. package/{docCreateCommands-DPMZI7G5.js → docCreateCommands-YJRDA3RX.js} +66 -59
  184. package/{docDeleteCommands-IRQQLUBT.js → docDeleteCommands-A5QIHZNF.js} +69 -62
  185. package/{docReadCommands-LK37XH6L.js → docReadCommands-CF2LTMYH.js} +66 -59
  186. package/{docStore-V2KECILA.js → docStore-NDY3K3PK.js} +25 -24
  187. package/{docUpdateCommands-O6T3HJHH.js → docUpdateCommands-QRKV4ZXE.js} +69 -62
  188. package/{fetchMessages-NR4KNQLO.js → fetchMessages-TQEUZD7H.js} +8 -7
  189. package/{getPricing-2MNMXEVG.js → getPricing-LF5C4XSI.js} +7 -7
  190. package/{handleSendMessageAction-2PE25WM3.js → handleSendMessageAction-IUGVVJ43.js} +206 -314
  191. package/{hostCredentialCreate-S233UMAP.js → hostCredentialCreate-X2ZFRXDR.js} +132 -124
  192. package/index.js +65 -27
  193. package/{keys-BEGDOTRL.js → keys-RWF7UCB4.js} +5 -4
  194. package/legacyMigration-TF4SYJCZ.js +19 -0
  195. package/{lib-5KKIBFIT.js → lib-OT5OTXRU.js} +7087 -6664
  196. package/{localDialogRead-7NNDVVF7.js → localDialogRead-CCOCVGAP.js} +3 -3
  197. package/{localFirstLog-DHNOY2NA.js → localFirstLog-OIETGK66.js} +1 -1
  198. package/localRecall-BDYKXB46.js +17 -0
  199. package/{localRuntimeAdapter-KY6WXNBR.js → localRuntimeAdapter-KAG3T4LF.js} +138 -130
  200. package/{localRuntimeAuthority-OYH4AE4G.js → localRuntimeAuthority-IBJAT62G.js} +1 -1
  201. package/{localRuntimeDb-VBIMCWUC.js → localRuntimeDb-N7KHDXS2.js} +2 -2
  202. package/{machineCommands-Q6HA3IXF.js → machineCommands-6NIQJE2A.js} +143 -135
  203. package/{machineInfo-UKPTZO5Y.js → machineInfo-LWHTEBHJ.js} +1 -1
  204. package/machineWsRunDispatch-RA5NOSGG.js +190 -0
  205. package/{memberThunks-7EDJADWU.js → memberThunks-7Y3OYSJQ.js} +30 -29
  206. package/{memoryCommands-ASCE5STX.js → memoryCommands-BC6REPQB.js} +7 -7
  207. package/models-H5NNZRLH.js +9 -0
  208. package/{oauthTokenStore-OEERZFUC.js → oauthTokenStore-RUYNYALS.js} +1 -1
  209. package/{offlineMarxistsAgentCommand-2QTHJCHV.js → offlineMarxistsAgentCommand-XVXUE6G5.js} +6 -6
  210. package/overlay-BBQZXGYI.js +13 -0
  211. package/package.json +2 -2
  212. package/{pdf-U6KSUEZZ.js → pdf-KE3QI2V7.js} +1 -1
  213. package/{processSpawn-ZU5QFM43.js → processSpawn-6GEO77KV.js} +1 -1
  214. package/{profileConfig-KN3N2BLF.js → profileConfig-KOWK4HOG.js} +1 -1
  215. package/{projectArchive-DRTDIMEV.js → projectArchive-OIUP63MV.js} +59 -56
  216. package/{providerPresetApply-YXGV6NXB.js → providerPresetApply-WHAMP2D5.js} +20 -13
  217. package/{providerRegistry-S6UL6UNA.js → providerRegistry-ZI2KORJ7.js} +11 -11
  218. package/{read-4V2RMG7N.js → read-TYMBGEXO.js} +13 -13
  219. package/{readDocTool-BH6ATGQO.js → readDocTool-SKQVHBLO.js} +2 -2
  220. package/{readlineWorkspace-2W4WRCOU.js → readlineWorkspace-ZGC4KSXG.js} +7760 -6499
  221. package/{removeDialogAgentAction-LYAZGNKW.js → removeDialogAgentAction-F5QE2O2B.js} +29 -28
  222. package/{runAgentClientLoop-J2VQBS2Z.js → runAgentClientLoop-NKUW2DSJ.js} +94 -88
  223. package/{runtimeDoctorCommands-QAI3MBKQ.js → runtimeDoctorCommands-RRKPBGVO.js} +19 -19
  224. package/{runtimeModeArgs-2Y7BALTO.js → runtimeModeArgs-X7DL7PUN.js} +1 -1
  225. package/secretCommands-KZWBZIYS.js +24 -0
  226. package/{setDialogExtraReferencesAction-OCRPGPYH.js → setDialogExtraReferencesAction-72L27ERM.js} +25 -24
  227. package/{setPrimaryDialogAgentAction-HFJDQIBU.js → setPrimaryDialogAgentAction-GJJDUSGJ.js} +29 -28
  228. package/{settingThunks-RAMHMTGM.js → settingThunks-ZRGWVGZD.js} +99 -90
  229. package/{skillDiscovery-XKHROSH2.js → skillDiscovery-I37M5KJC.js} +4 -4
  230. package/{skillSummaryMarker-42HKSXYY.js → skillSummaryMarker-62UW7HI7.js} +1 -1
  231. package/{slateToRenderMarkdown-Y5IYN73U.js → slateToRenderMarkdown-R3X74MCX.js} +1 -1
  232. package/{slateUtils-NGV2NMKM.js → slateUtils-ESQAJ6RN.js} +1 -1
  233. package/{spaceCommands-KVJZVKVO.js → spaceCommands-MEH3HJBC.js} +66 -57
  234. package/store-Z53ICFL3.js +48 -0
  235. package/{streamAgentChatTurn-GHBMJJ6S.js → streamAgentChatTurn-FJTUUXHJ.js} +886 -668
  236. package/{switchDialogAgentAction-EBRMW3RA.js → switchDialogAgentAction-IIJBPND3.js} +26 -25
  237. package/{tableCommands-MP6VFSVT.js → tableCommands-FTAOCBTX.js} +13 -13
  238. package/tombstones-FQQMEDOW.js +32 -0
  239. package/{toolApiClient-HGNO53TC.js → toolApiClient-OGQEBQVX.js} +4 -4
  240. package/{tools-EWKCPKMS.js → tools-ZXHIAOSP.js} +82 -81
  241. package/tuiRestart-2IL37YIB.js +41 -0
  242. package/tuiSummaryLlmCaller-W2QN4VAC.js +44 -0
  243. package/{updateCommands-ZQYU6SCI.js → updateCommands-CPATDG6J.js} +11 -7
  244. package/{updateDialogTitleAction-5GGMBTDF.js → updateDialogTitleAction-JMKLKL4P.js} +54 -51
  245. package/{usageCommand-F4IPVMIZ.js → usageCommand-2BF74MKF.js} +11 -10
  246. package/{usageRebuildCommand-HAW2AD5N.js → usageRebuildCommand-UHB55BQM.js} +12 -11
  247. package/userDataMerge-HT2ZVHBJ.js +13 -0
  248. package/{windowsSelfUpdate-257DV2T6.js → windowsSelfUpdate-ZFD6J5HF.js} +3 -3
  249. package/{workloadLifecycle-4C42SVBD.js → workloadLifecycle-HFJIN5IZ.js} +4 -4
  250. package/agentRecordCommands-ZQ7SVYGG.js +0 -167
  251. package/agentRunCommand-WS7IGO2W.js +0 -196
  252. package/chunk-3CGG2PAL.js +0 -594
  253. package/chunk-5MQRBSMW.js +0 -862
  254. package/chunk-5XBUWM6I.js +0 -89
  255. package/chunk-CJEIOP3E.js +0 -0
  256. package/chunk-EHGEOAHI.js +0 -636
  257. package/chunk-FW6YHHLI.js +0 -842
  258. package/chunk-GPVRUGGY.js +0 -115
  259. package/chunk-HSVBJRF4.js +0 -339
  260. package/chunk-LEC5ALIN.js +0 -91
  261. package/chunk-WACI5I6V.js +0 -147
  262. package/chunk-WJZOQR2J.js +0 -151
  263. package/chunk-ZCWRMUWT.js +0 -89
  264. package/dist-M676ULYG.js +0 -7314
  265. package/machineWsRunDispatch-WWJQ6WR3.js +0 -182
  266. package/models-PJBE6JDV.js +0 -9
  267. package/tuiSummaryLlmCaller-ALQYUUWB.js +0 -189
  268. package/{chunk-AGP3YSEC.js → chunk-4N6G2CKP.js} +3 -3
  269. package/{chunk-BLVSFYQ3.js → chunk-LISC7BD4.js} +3 -3
  270. package/{chunk-2QHFH3DR.js → chunk-USGHJSGO.js} +3 -3
  271. package/{chunk-AETZ7AD6.js → chunk-W6RFEDN4.js} +3 -3
@@ -1,21 +1,30 @@
1
1
  import {
2
2
  resolveRuntimeAuthToken,
3
3
  resolveRuntimeServerUrl
4
- } from "./chunk-HRMJUN5J.js";
4
+ } from "./chunk-2X7WFDT6.js";
5
5
  import {
6
6
  isAgentRunTerminalStatus,
7
- normalizeRunTitle
8
- } from "./chunk-ALQ3657A.js";
7
+ normalizeRunTitle,
8
+ shortAgentKey
9
+ } from "./chunk-OOJNQK6V.js";
9
10
  import {
10
11
  findPowerShellExecutable
11
- } from "./chunk-H4UOTUOX.js";
12
+ } from "./chunk-VMJVAJ6W.js";
12
13
  import {
13
- isRecord
14
- } from "./chunk-KUG52IAP.js";
14
+ AUTH_ERROR_PATTERNS
15
+ } from "./chunk-EWQ3HGNZ.js";
15
16
  import {
17
+ AGENT_RUN_PROTOCOL,
18
+ HOST_RUNTIME_CONTENT_IDENTITY,
19
+ RuntimeVersionMismatchError,
20
+ getHostRuntimeExecutable,
16
21
  isCompiledBinary,
17
- resolveCliEntrypointPath
18
- } from "./chunk-WACI5I6V.js";
22
+ resolveCliEntrypointPath,
23
+ resolveExactRuntimeEntrypoint
24
+ } from "./chunk-BIDSIRTS.js";
25
+ import {
26
+ isRecord
27
+ } from "./chunk-KUG52IAP.js";
19
28
 
20
29
  // packages/cli/client/originShellApprovalTransport.ts
21
30
  import { realpathSync } from "node:fs";
@@ -444,9 +453,10 @@ function redactLogLines(lines, options = {}) {
444
453
  }
445
454
 
446
455
  // packages/cli/agentRunControl.ts
447
- import { homedir as nodeHomedir } from "node:os";
456
+ import { hostname as nodeHostname, homedir as nodeHomedir } from "node:os";
448
457
  import { dirname, isAbsolute as isAbsolute2, join as join2, resolve } from "node:path";
449
458
  import * as nodeFs2 from "node:fs";
459
+ import { randomUUID as randomUUID2, createHash } from "node:crypto";
450
460
  import { execFileSync as nodeExecFileSync, spawn as nodeSpawn } from "node:child_process";
451
461
 
452
462
  // packages/cli/client/hostMemory.ts
@@ -1090,6 +1100,7 @@ function resolveResultServerMeta(input) {
1090
1100
  var resultHeaderMeta = /* @__PURE__ */ new WeakMap();
1091
1101
  function recordRunResultHeaderMeta(result, meta) {
1092
1102
  const clean = {};
1103
+ if (meta.commandObservations?.length) clean.commandObservations = meta.commandObservations;
1093
1104
  if (meta.model) clean.model = meta.model;
1094
1105
  if (meta.dialogServer) clean.dialogServer = meta.dialogServer;
1095
1106
  if (meta.serverSync) clean.serverSync = meta.serverSync;
@@ -1134,7 +1145,8 @@ function buildResultFrontMatter(input) {
1134
1145
  ["server", input.server],
1135
1146
  ["serverSync", input.serverSync],
1136
1147
  ["cwd", input.cwd],
1137
- ["continuedFrom", input.continuedFrom]
1148
+ ["continuedFrom", input.continuedFrom],
1149
+ ["acceptance", input.acceptance ? JSON.stringify(input.acceptance) : void 0]
1138
1150
  ];
1139
1151
  const lines = entries.filter(([, v]) => v !== void 0 && v !== "").map(([k, v]) => `${k}: ${yamlScalar(v)}`);
1140
1152
  return `---
@@ -1147,7 +1159,11 @@ function buildResultFileContent(input, body) {
1147
1159
  }
1148
1160
 
1149
1161
  // packages/ai/tools/agent/runFailureClass.ts
1150
- var RATE_LIMIT_PATTERN = /429|rate.?limit|quota|insufficient.?balance|UPSTREAM_402|cooling|冷却/i;
1162
+ function isHistoryIntegrityFailure(message) {
1163
+ return /^Strict continuation history load failed for [^\r\n]+:/i.test(message.trim());
1164
+ }
1165
+ var BALANCE_PATTERN = /\bUPSTREAM_402\b|\b402\b|insufficient[_\s-]+balance|余额不足|wallet\s+balance\s+is\s+insufficient|top\s+up\s+your\s+wallet|payment[_ ]required/i;
1166
+ var RATE_LIMIT_PATTERN = /429|rate.?limit|quota|cooling|冷却/i;
1151
1167
  var PROVIDER_ERROR_PATTERN = /provider|upstream|5\d\d|bad.?gateway|service.?unavailable|overloaded/i;
1152
1168
  var MALFORMED_PATTERN = /MALFORMED_FUNCTION_CALL|malformed|invalid.?function.?call|invalid.?tool.?call/i;
1153
1169
  var STALLED_PATTERN = /stall|no.?progress|repetition|stagnant|无进展|卡死/i;
@@ -1159,6 +1175,20 @@ function classifyRunFailure(input) {
1159
1175
  }
1160
1176
  const reason = typeof input.failureReason === "string" ? input.failureReason : "";
1161
1177
  const message = typeof input.errorMessage === "string" ? input.errorMessage : "";
1178
+ if (reason === "history_integrity" || isHistoryIntegrityFailure(message)) {
1179
+ return { failureClass: "history_integrity", retryable: false };
1180
+ }
1181
+ if (!reason || reason === "provider_rate_limited" || reason === "provider_error") {
1182
+ if (BALANCE_PATTERN.test(message)) {
1183
+ return { failureClass: "balance_exhausted", retryable: false };
1184
+ }
1185
+ if (AUTH_ERROR_PATTERNS.some((pattern) => pattern.test(message))) {
1186
+ return { failureClass: "auth", retryable: false };
1187
+ }
1188
+ if (reason === "provider_error" && RATE_LIMIT_PATTERN.test(message)) {
1189
+ return { failureClass: "rate_limited", retryable: true };
1190
+ }
1191
+ }
1162
1192
  switch (reason) {
1163
1193
  case "provider_rate_limited":
1164
1194
  return { failureClass: "rate_limited", retryable: true };
@@ -1552,7 +1582,9 @@ function withRunRecordLock(runId, deps, fn, opts = {}) {
1552
1582
  try {
1553
1583
  const stat = fs.statSync?.(lockPath);
1554
1584
  const ageMs = stat ? now().getTime() - stat.mtimeMs : Number.POSITIVE_INFINITY;
1555
- if (ageMs > LOCK_STALE_MS) {
1585
+ const ownerPid = opts.requireDeadOwner ? Number(String(fs.readFileSync(lockPath, "utf8"))) : void 0;
1586
+ const ownerGone = !opts.requireDeadOwner || Number.isSafeInteger(ownerPid) && ownerPid > 0 && isPidGone(ownerPid, deps);
1587
+ if (ageMs > LOCK_STALE_MS && ownerGone) {
1556
1588
  fs.unlinkSync(lockPath);
1557
1589
  fs.writeFileSync(lockPath, String(process.pid), { flag: "wx" });
1558
1590
  held = true;
@@ -1582,13 +1614,15 @@ function writeRunRecord(record, deps = {}) {
1582
1614
  fs.writeFileSync(tmp, payload);
1583
1615
  fs.renameSync(tmp, path);
1584
1616
  return;
1585
- } catch {
1617
+ } catch (error) {
1586
1618
  try {
1587
1619
  fs.unlinkSync(tmp);
1588
1620
  } catch {
1589
1621
  }
1622
+ if (record.writerLaunch) throw error;
1590
1623
  }
1591
1624
  }
1625
+ if (record.writerLaunch) throw new Error("[local-writer-resource] fenced launch requires atomic rename");
1592
1626
  fs.writeFileSync(path, payload);
1593
1627
  }
1594
1628
  function reportRunProcessIdentity(runId, deps = {}) {
@@ -1993,6 +2027,34 @@ function listRunRecords(deps = {}) {
1993
2027
  (a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime()
1994
2028
  );
1995
2029
  }
2030
+ async function listRunRecordsAsync(deps = {}) {
2031
+ const dir = resolveRunsDir(deps.env, deps.homedir);
2032
+ let entries;
2033
+ try {
2034
+ entries = await nodeFs2.promises.readdir(dir);
2035
+ } catch {
2036
+ return [];
2037
+ }
2038
+ const records = new Array(entries.length);
2039
+ let next = 0;
2040
+ const readNext = async () => {
2041
+ while (next < entries.length) {
2042
+ const index = next++;
2043
+ const entry = entries[index];
2044
+ if (!entry.endsWith(".json")) continue;
2045
+ const path = resolveRunRecordPath(entry.slice(0, -5), deps.env, deps.homedir);
2046
+ for (let attempt = 0; attempt < 2; attempt++) {
2047
+ try {
2048
+ records[index] = JSON.parse(await nodeFs2.promises.readFile(path, "utf8"));
2049
+ break;
2050
+ } catch {
2051
+ }
2052
+ }
2053
+ }
2054
+ };
2055
+ await Promise.all(Array.from({ length: Math.min(16, entries.length) }, readNext));
2056
+ return records.filter((record) => Boolean(record)).sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());
2057
+ }
1996
2058
  function findRunRecordByPid(pid, deps = {}) {
1997
2059
  return listRunRecords(deps).find((record) => record.pid === pid);
1998
2060
  }
@@ -2054,9 +2116,18 @@ async function gcRunRecords(deps = {}, options = {}) {
2054
2116
  const failedIds = [];
2055
2117
  for (const record of records) {
2056
2118
  if (!isRunTerminalStatus(record.status)) continue;
2119
+ if (localWriterStillOwns(record, deps)) continue;
2120
+ if (!/^[A-Za-z0-9._-]{1,128}$/.test(record.runId) || record.runId === "." || record.runId === "..") {
2121
+ failedIds.push(record.runId);
2122
+ continue;
2123
+ }
2057
2124
  const ts = record.reconciledAt ?? record.endedAt ?? record.startedAt;
2058
2125
  const ageMs = nowMs - new Date(ts).getTime();
2059
2126
  if (!Number.isFinite(ageMs) || ageMs < retentionMs) continue;
2127
+ if (fs.existsSync(`${resolveRunRecordPath(record.runId, deps.env, deps.homedir)}.lock`)) {
2128
+ failedIds.push(record.runId);
2129
+ continue;
2130
+ }
2060
2131
  const jsonPath = resolveRunRecordPath(record.runId, deps.env, deps.homedir);
2061
2132
  const logPath = resolveRunLogPath(record.runId, deps.env, deps.homedir);
2062
2133
  const queuePath = record.queuePath ?? resolveRunQueuePath(record.runId, deps.env, deps.homedir);
@@ -2076,8 +2147,30 @@ async function gcRunRecords(deps = {}, options = {}) {
2076
2147
  const runsDirForLegacy = resolveRunsDir(deps.env, deps.homedir);
2077
2148
  tryUnlinkFile(fs, join2(runsDirForLegacy, `${record.runId}.report.md`));
2078
2149
  tryUnlinkFile(fs, join2(runsDirForLegacy, `${record.runId}.report.json`));
2079
- tryUnlinkFile(fs, record.resultFile ?? join2(runsDirForLegacy, `${record.runId}.result.md`));
2080
- if (!logOk || !msgOk || !queueOk) {
2150
+ let resultOk = false;
2151
+ let artifactsOk = true;
2152
+ const artifactSweep = withRunRecordLock(record.runId, deps, () => {
2153
+ resultOk = tryUnlinkFile(fs, join2(runsDirForLegacy, `${record.runId}.result.md`));
2154
+ for (const artifact of record.resultArtifacts ?? []) {
2155
+ try {
2156
+ const prefix = `${record.runId}.result.md.`;
2157
+ const name = artifact.path.slice(join2(runsDirForLegacy, prefix).length);
2158
+ const uuid = "[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
2159
+ 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)) throw new Error("unsafe artifact ownership");
2160
+ if (!fs.existsSync(artifact.path)) continue;
2161
+ const stat = fs.lstatSync?.(artifact.path);
2162
+ if (!stat || !stat.isFile() || stat.isSymbolicLink() || fs.realpathSync?.(artifact.path) !== resolve(artifact.path) || String(stat.dev) !== artifact.dev || String(stat.ino) !== artifact.ino || createHash("sha256").update(fs.readFileSync(artifact.path)).digest("hex") !== artifact.sha256) {
2163
+ throw new Error("artifact identity changed");
2164
+ }
2165
+ if (!tryUnlinkFile(fs, artifact.path)) artifactsOk = false;
2166
+ } catch {
2167
+ artifactsOk = false;
2168
+ }
2169
+ }
2170
+ return true;
2171
+ }, { strict: true });
2172
+ if (!artifactSweep) artifactsOk = false;
2173
+ if (!logOk || !msgOk || !queueOk || !resultOk || !artifactsOk) {
2081
2174
  failedIds.push(record.runId);
2082
2175
  continue;
2083
2176
  }
@@ -2090,12 +2183,12 @@ async function gcRunRecords(deps = {}, options = {}) {
2090
2183
  }
2091
2184
  try {
2092
2185
  const dir = resolveRunsDir(deps.env, deps.homedir);
2093
- const statSync = fs.statSync;
2186
+ const statSync2 = fs.statSync;
2094
2187
  for (const entry of fs.readdirSync(dir)) {
2095
2188
  if (typeof entry !== "string" || !entry.endsWith(".tmp")) continue;
2096
2189
  const tmpPath = join2(dir, entry);
2097
2190
  try {
2098
- const stat = statSync?.(tmpPath);
2191
+ const stat = statSync2?.(tmpPath);
2099
2192
  if (stat && nowMs - stat.mtimeMs <= TMP_STALE_MS) continue;
2100
2193
  } catch {
2101
2194
  continue;
@@ -2155,38 +2248,22 @@ function rewriteMsgFileArg(args, messagePath) {
2155
2248
  return result;
2156
2249
  }
2157
2250
  function resolveValidCliEntrypoint(cliEntrypointPath, fs = nodeFs2) {
2158
- if (cliEntrypointPath && fs.existsSync(cliEntrypointPath)) {
2159
- return cliEntrypointPath;
2160
- }
2161
- const fallback = resolveCliEntrypointPath();
2162
- if (fs.existsSync(fallback)) {
2163
- return fallback;
2164
- }
2165
- const candidates = [
2166
- join2(dirname(fallback), "cli", "index.ts"),
2167
- join2(dirname(fallback), "cli", "index.js"),
2168
- join2(dirname(fallback), "..", "packages", "cli", "index.ts"),
2169
- join2(dirname(fallback), "..", "packages", "cli", "index.js"),
2170
- join2(dirname(fallback), "..", "index.js")
2171
- ];
2172
- for (const cand of candidates) {
2173
- if (fs.existsSync(cand)) {
2174
- return cand;
2175
- }
2176
- }
2177
- return fallback;
2251
+ const entrypoint = cliEntrypointPath ?? resolveCliEntrypointPath();
2252
+ if (!fs.existsSync(entrypoint)) throw new RuntimeVersionMismatchError("runtime entrypoint missing");
2253
+ return fs === nodeFs2 ? resolveExactRuntimeEntrypoint(entrypoint) : String(fs.realpathSync?.(entrypoint) ?? entrypoint);
2178
2254
  }
2179
2255
  function buildAgentRunChildCommand(options, deps = {}) {
2180
2256
  const fs = deps.fs ?? nodeFs2;
2181
- const execPath = process.execPath;
2257
+ const execPath = getHostRuntimeExecutable();
2182
2258
  const commandParts = options.commandPath ?? [];
2183
2259
  let strippedArgs = stripBackgroundFlag(options.rawArgs);
2184
2260
  if (options.messagePath) {
2185
2261
  strippedArgs = rewriteMsgFileArg(strippedArgs, options.messagePath);
2186
2262
  }
2187
2263
  strippedArgs = absolutizeSkillArgs(strippedArgs);
2188
- if (isCompiledBinary() || options.cliEntrypointPath === execPath) {
2189
- return { execPath, childArgs: [...commandParts, ...strippedArgs] };
2264
+ if (isCompiledBinary() || options.cliEntrypointPath === process.execPath || options.cliEntrypointPath === execPath) {
2265
+ const fixed = resolveValidCliEntrypoint(isCompiledBinary() ? execPath : options.cliEntrypointPath ?? execPath, fs);
2266
+ return { execPath: fixed, childArgs: [...commandParts, ...strippedArgs] };
2190
2267
  }
2191
2268
  const entrypoint = resolveValidCliEntrypoint(options.cliEntrypointPath, fs);
2192
2269
  if (entrypoint === execPath) {
@@ -2210,6 +2287,312 @@ function emitHostMemoryNotice(mem, output) {
2210
2287
  }
2211
2288
  return notice;
2212
2289
  }
2290
+ function trustedLocalWorktree(cwd, deps) {
2291
+ const fs = deps.fs ?? nodeFs2;
2292
+ try {
2293
+ const env = { ...process.env, ...deps.env };
2294
+ for (const key of Object.keys(env)) if (key.startsWith("GIT_")) delete env[key];
2295
+ const exec = deps.execFileSync ?? nodeExecFileSync;
2296
+ const git = (args) => exec("git", args, {
2297
+ cwd,
2298
+ env,
2299
+ encoding: "utf8",
2300
+ stdio: ["ignore", "pipe", "ignore"],
2301
+ timeout: 3e3
2302
+ }).trim();
2303
+ const real = (path) => String((fs.realpathSync ?? nodeFs2.realpathSync)(path));
2304
+ const [dir, top, common] = git(["rev-parse", "--path-format=absolute", "--git-dir", "--show-toplevel", "--git-common-dir"]).split("\n");
2305
+ if (!dir || !top || !common || ![dir, top, common].every(isAbsolute2)) return;
2306
+ const root = real(top), gitDir = real(dir), commonDir = real(common);
2307
+ const marker = join2(root, ".git");
2308
+ const stat = (path) => (fs.lstatSync ?? nodeFs2.lstatSync)(path);
2309
+ if (stat(marker).isSymbolicLink() || stat(commonDir).isSymbolicLink()) return;
2310
+ if (gitDir === commonDir) {
2311
+ if (!stat(marker).isDirectory() || real(marker) !== commonDir) return;
2312
+ } else {
2313
+ const registry = join2(commonDir, "worktrees");
2314
+ if (stat(registry).isSymbolicLink() || dirname(gitDir) !== real(registry) || !stat(gitDir).isDirectory() || stat(gitDir).isSymbolicLink() || !stat(marker).isFile()) return;
2315
+ const text = String(fs.readFileSync(marker, "utf8")).trim();
2316
+ if (!text.startsWith("gitdir: ") || real(resolve(root, text.slice(8))) !== gitDir) return;
2317
+ const back = String(fs.readFileSync(join2(gitDir, "gitdir"), "utf8")).trim();
2318
+ const commonBack = String(fs.readFileSync(join2(gitDir, "commondir"), "utf8")).trim();
2319
+ if (real(resolve(gitDir, back)) !== real(marker) || real(resolve(gitDir, commonBack)) !== commonDir) return;
2320
+ }
2321
+ const registered = git(["worktree", "list", "--porcelain"]).split("\n").filter((line) => line.startsWith("worktree ")).map((line) => line.slice(9));
2322
+ if (!registered.some((path) => real(path) === root)) return;
2323
+ const mainMarker = registered[0] && join2(registered[0], ".git");
2324
+ if (!mainMarker || stat(mainMarker).isSymbolicLink() || !stat(mainMarker).isDirectory() || real(mainMarker) !== commonDir) return;
2325
+ return { root, gitDir, commonDir };
2326
+ } catch {
2327
+ return;
2328
+ }
2329
+ }
2330
+ function localWriterRecovery(record) {
2331
+ if (record.localWriterClaim?.state !== "held" || typeof record.pid === "number" && record.pid > 0) return;
2332
+ return {
2333
+ state: "required",
2334
+ reason: "owner-unpublished",
2335
+ automaticReleaseAllowed: false,
2336
+ runId: record.runId,
2337
+ canonicalCwd: record.localWriterClaim.cwd,
2338
+ requiredEvidence: "native launch receipt proving no live child; parent death/timeouts/process-name search are insufficient"
2339
+ };
2340
+ }
2341
+ function revokePreparedWriterLaunch(runId, attemptId, deps = {}) {
2342
+ if (!/^[A-Za-z0-9_-]+$/.test(runId) || !attemptId) return "blocked";
2343
+ return withRunRecordLock("local-writer-admission", deps, () => {
2344
+ const snapshot = readRunRecord(runId, deps);
2345
+ if (!snapshot) return "blocked";
2346
+ return withRunRecordLock(runId, deps, () => {
2347
+ const latest = readRunRecord(runId, deps);
2348
+ if (!latest || JSON.stringify(latest) !== JSON.stringify(snapshot)) return "blocked";
2349
+ const launch = latest.writerLaunch;
2350
+ if (launch?.protocol !== "fenced-launch-v1" || launch.attemptId !== attemptId) return "blocked";
2351
+ if (launch.phase === "revoked") return latest.localWriterClaim?.state === "released" ? "already-revoked" : "blocked";
2352
+ 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 !== void 0 || latest.cwd !== latest.localWriterClaim.cwd || latest.execution.kind !== "host-local" || latest.execution.permissions.readOnly || !latest.execution.permissions.hostWritesAuthorized) return "blocked";
2353
+ launch.phase = "revoked";
2354
+ latest.localWriterClaim.state = "released";
2355
+ writeRunRecord(latest, deps);
2356
+ return "revoked";
2357
+ }, { strict: true, requireDeadOwner: true }) ?? "blocked";
2358
+ }, { strict: true, requireDeadOwner: true }) ?? "blocked";
2359
+ }
2360
+ function localWriterStillOwns(record, deps) {
2361
+ if (record.localWriterClaim?.state !== "held") return false;
2362
+ if (typeof record.pid !== "number" || record.pid <= 0) return true;
2363
+ const e = record.execution;
2364
+ const observed = e?.state === "known" && e.owner.state === "verified" ? nativeOwner(record.pid, deps) : void 0;
2365
+ 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));
2366
+ if (!isPidGone(record.pid, deps) && !reused) return true;
2367
+ const snapshot = JSON.stringify(record);
2368
+ const released = withRunRecordLock(record.runId, deps, () => {
2369
+ const latest = readRunRecord(record.runId, deps);
2370
+ if (!latest || JSON.stringify(latest) !== snapshot) return false;
2371
+ latest.localWriterClaim.state = "released";
2372
+ writeRunRecord(latest, deps);
2373
+ return true;
2374
+ }, { strict: true });
2375
+ return released !== true;
2376
+ }
2377
+ function acquireLocalWriterClaim(runId, cwd, deps) {
2378
+ const fs = deps.fs ?? nodeFs2;
2379
+ const canonical = String((fs.realpathSync ?? nodeFs2.realpathSync)(cwd));
2380
+ const worktree = trustedLocalWorktree(canonical, deps);
2381
+ const acquired = withRunRecordLock("local-writer-admission", deps, () => {
2382
+ const updated = withRunRecordLock(runId, deps, () => {
2383
+ const record = readRunRecord(runId, deps);
2384
+ if (!record) throw new Error(`[local-writer-resource] missing run ${runId}`);
2385
+ if (record.writerLaunch?.phase === "revoked") throw new Error("[local-writer-resource] claim attempt revoked");
2386
+ record.localWriterClaim = { cwd: canonical, ...worktree ? { worktree } : {}, state: "held" };
2387
+ if (record.writerLaunch && record.execution?.state === "known" && record.execution.owner.state === "verified" && record.pid === process.pid) {
2388
+ record.writerLaunch.phase = "granted";
2389
+ }
2390
+ writeRunRecord(record, deps);
2391
+ return true;
2392
+ }, { strict: true });
2393
+ if (!updated) throw new Error(`[local-writer-resource] run lock busy: ${runId}`);
2394
+ return true;
2395
+ }, { strict: true, requireDeadOwner: true });
2396
+ if (!acquired) throw new Error("[local-writer-resource] admission lock busy; no child spawned");
2397
+ return canonical;
2398
+ }
2399
+ function nativeOwner(pid, deps) {
2400
+ const first = probeProcessStartTime(pid, deps);
2401
+ let linux;
2402
+ if ((deps.platform ?? process.platform) === "linux") {
2403
+ try {
2404
+ const stat = nodeFs2.readFileSync(`/proc/${pid}/stat`, "utf8");
2405
+ const startTicks = stat.slice(stat.lastIndexOf(")") + 2).split(/\s+/)[19];
2406
+ const bootId = nodeFs2.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
2407
+ if (/^\d+$/.test(startTicks) && bootId) linux = { startTicks, bootId };
2408
+ } catch {
2409
+ return { state: "unknown" };
2410
+ }
2411
+ }
2412
+ const second = probeProcessStartTime(pid, deps);
2413
+ if (!first || !second || first.getTime() !== second.getTime() || isPidGone(pid, deps) || (deps.platform ?? process.platform) === "linux" && !linux) return { state: "unknown" };
2414
+ return { state: "verified", pid, startedAt: first.toISOString(), source: "parent-native", ...linux ? { linux } : {} };
2415
+ }
2416
+ function validateLocalWriterChild(runId, cwd, policy, deps = {}) {
2417
+ const fail = (reason = "facts") => {
2418
+ throw new Error(`[local-writer-resource] child binding unknown or mismatched: ${reason}`);
2419
+ };
2420
+ if (!/^[A-Za-z0-9_-]+$/.test(runId)) fail();
2421
+ const validated = withRunRecordLock(runId, deps, () => {
2422
+ const r = readRunRecord(runId, deps), e = r?.execution;
2423
+ const launch = r?.writerLaunch;
2424
+ if (launch && (launch.protocol !== "fenced-launch-v1" || launch.phase !== "granted" || launch.attemptId !== deps.env?.NOLO_WRITER_LAUNCH_ATTEMPT)) fail("launch grant missing/revoked");
2425
+ const native = nativeOwner(process.pid, deps);
2426
+ const real = String((deps.fs?.realpathSync ?? nodeFs2.realpathSync)(cwd));
2427
+ 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) fail("native identity/authorization");
2428
+ if (e?.state !== "known") return fail();
2429
+ const set = (v) => JSON.stringify(v === void 0 ? null : [...new Set(v)].sort());
2430
+ if (set(e.permissions.allowedToolNames) !== set(policy.allowedToolNames) || set(e.permissions.blockedToolNames) !== set(policy.blockedToolNames) || JSON.stringify(e.worktree) !== JSON.stringify(trustedLocalWorktree(real, deps))) fail("scope/worktree");
2431
+ 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))) fail();
2432
+ return true;
2433
+ }, { strict: true, requireDeadOwner: true });
2434
+ if (!validated) fail("registry lock busy");
2435
+ }
2436
+ async function awaitLocalWriterChild(runId, cwd, policy, deps = {}) {
2437
+ if (!/^[A-Za-z0-9_-]+$/.test(runId)) throw new Error("[local-writer-resource] child binding invalid id");
2438
+ const deadline = Date.now() + 2e3;
2439
+ for (; ; ) {
2440
+ const r = readRunRecord(runId, deps);
2441
+ const publication = r?.ownerPublication;
2442
+ if (r?.writerLaunch && (r.writerLaunch.phase === "revoked" || r.writerLaunch.attemptId !== deps.env?.NOLO_WRITER_LAUNCH_ATTEMPT)) {
2443
+ throw new Error("[local-writer-resource] child binding launch revoked/mismatched");
2444
+ }
2445
+ const native = publication ? nativeOwner(publication.parent.pid, deps) : { state: "unknown" };
2446
+ const parentLive = publication && native.state === "verified" && publication.parent.startedAt === native.startedAt && publication.parent.linux?.bootId === native.linux?.bootId && publication.parent.linux?.startTicks === native.linux?.startTicks;
2447
+ try {
2448
+ validateLocalWriterChild(runId, cwd, policy, deps);
2449
+ return;
2450
+ } catch (error) {
2451
+ const lockBusy = String(error).includes("registry lock busy");
2452
+ const pending = publication?.state === "pending" && r?.execution?.state === "known" && r.execution.owner.state === "unknown";
2453
+ if (!parentLive || !pending && !lockBusy || Date.now() >= deadline) throw error;
2454
+ await new Promise((resolve2) => setTimeout(resolve2, 20));
2455
+ }
2456
+ }
2457
+ }
2458
+ function resolveLocalContinuation(record, deps = {}) {
2459
+ const fail = (why) => {
2460
+ throw new Error(`[local-continuation] ${why}; dispatch a fresh explicitly authorized run`);
2461
+ };
2462
+ const e = record.execution;
2463
+ 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) return fail("execution unknown or unsupported");
2464
+ const lists = [e.permissions.allowedToolNames, e.permissions.blockedToolNames];
2465
+ if (lists.some((v) => v !== void 0 && (!Array.isArray(v) || v.some((t) => typeof t !== "string" || !t || t.startsWith("--"))))) return fail("tool scope invalid");
2466
+ let cwd;
2467
+ try {
2468
+ if (!e.canonicalCwd || !isAbsolute2(e.canonicalCwd) || record.cwd !== e.canonicalCwd) return fail("cwd identity missing");
2469
+ const fs = deps.fs ?? nodeFs2;
2470
+ cwd = String((fs.realpathSync ?? nodeFs2.realpathSync)(e.canonicalCwd));
2471
+ if (cwd !== e.canonicalCwd || !(fs.statSync ?? nodeFs2.statSync)(cwd).isDirectory()) return fail("cwd drift");
2472
+ if (JSON.stringify(e.worktree) !== JSON.stringify(trustedLocalWorktree(cwd, deps))) return fail("cwd worktree changed");
2473
+ } catch {
2474
+ return fail("cwd missing or moved");
2475
+ }
2476
+ const death = record.ownerDeath;
2477
+ const hasDeath = !record.pid && death && death.pid > 0 && JSON.stringify(death.executionOwner) === JSON.stringify(e.owner) && (!record.localWriterClaim || record.localWriterClaim.state === "released");
2478
+ if (!hasDeath && (typeof record.pid !== "number" || record.pid <= 0)) return fail("old owner unknown");
2479
+ const current = hasDeath ? { state: "unknown" } : nativeOwner(record.pid, deps);
2480
+ const old = e.owner;
2481
+ 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);
2482
+ if (!hasDeath && !isPidGone(record.pid, deps) && !reused) return fail("old owner live or unknown");
2483
+ if (!e.permissions.readOnly && (record.localWriterClaim?.cwd !== cwd || !["held", "released"].includes(record.localWriterClaim.state))) return fail("writer claim unknown");
2484
+ const policy = { runtimeKey: "local", ...e.permissions, provenance: "cli-tool-dispatch-authorized" };
2485
+ const rawArgs = [
2486
+ "--runtime-key",
2487
+ "local",
2488
+ ...policy.hostWritesAuthorized ? ["--allow-host-writes"] : [],
2489
+ ...policy.readOnly ? ["--read-only"] : [],
2490
+ ...(policy.allowedToolNames ?? []).flatMap((t) => ["--allowed-tool", t]),
2491
+ ...(policy.blockedToolNames ?? []).flatMap((t) => ["--blocked-tool", t])
2492
+ ];
2493
+ return { cwd, policy, rawArgs };
2494
+ }
2495
+ function registerLocalForegroundWriter(cwd, policy, agentKey, deps = {}) {
2496
+ const fs = deps.fs ?? nodeFs2;
2497
+ const canonical = String((fs.realpathSync ?? nodeFs2.realpathSync)(cwd));
2498
+ const owner = nativeOwner(process.pid, deps);
2499
+ if (owner.state !== "verified" || policy.readOnly || !policy.hostWritesAuthorized) {
2500
+ throw new Error("[local-writer-resource] foreground native identity/authorization unknown");
2501
+ }
2502
+ const runId = defaultGenerateRunId();
2503
+ fs.mkdirSync(resolveRunsDir(deps.env, deps.homedir), { recursive: true });
2504
+ const worktree = trustedLocalWorktree(canonical, deps);
2505
+ const record = {
2506
+ runId,
2507
+ agentKey,
2508
+ writerLaunch: { protocol: "fenced-launch-v1", attemptId: randomUUID2(), phase: "prepared" },
2509
+ cwd: canonical,
2510
+ startedAt: (deps.now?.() ?? /* @__PURE__ */ new Date()).toISOString(),
2511
+ status: "running",
2512
+ logPath: resolveRunLogPath(runId, deps.env, deps.homedir),
2513
+ pid: process.pid,
2514
+ processStartedAt: owner.startedAt,
2515
+ processIdentity: "verified",
2516
+ execution: {
2517
+ state: "known",
2518
+ kind: "host-local",
2519
+ runtimeKey: "local",
2520
+ canonicalCwd: canonical,
2521
+ device: { kind: "localhost", hostname: nodeHostname(), platform: process.platform },
2522
+ ...worktree ? { worktree } : {},
2523
+ permissions: {
2524
+ hostWritesAuthorized: policy.hostWritesAuthorized,
2525
+ readOnly: policy.readOnly,
2526
+ ...policy.allowedToolNames ? { allowedToolNames: [...policy.allowedToolNames] } : {},
2527
+ ...policy.blockedToolNames ? { blockedToolNames: [...policy.blockedToolNames] } : {}
2528
+ },
2529
+ provenance: policy.provenance,
2530
+ owner
2531
+ }
2532
+ };
2533
+ writeRunRecord(record, deps);
2534
+ try {
2535
+ acquireLocalWriterClaim(runId, canonical, deps);
2536
+ } catch (error) {
2537
+ finalizeRunRecord(runId, { status: "failed", exitCode: 1, note: String(error) }, deps);
2538
+ throw error;
2539
+ }
2540
+ return runId;
2541
+ }
2542
+ function releaseUnspawnedLocalWriterClaim(runId, deps) {
2543
+ const released = withRunRecordLock(runId, deps, () => {
2544
+ const record = readRunRecord(runId, deps);
2545
+ if (record?.localWriterClaim) {
2546
+ if (record.writerLaunch?.phase === "prepared") record.writerLaunch.phase = "revoked";
2547
+ record.localWriterClaim.state = "released";
2548
+ writeRunRecord(record, deps);
2549
+ }
2550
+ return true;
2551
+ }, { strict: true });
2552
+ if (!released) throw new Error(`[local-writer-resource] release lock busy: ${runId}`);
2553
+ }
2554
+ async function recordRunStartup(runId, phase, deps = {}) {
2555
+ const attempt = () => withRunRecordLock(runId, deps, () => {
2556
+ const record = readRunRecord(runId, deps);
2557
+ if (!record || isRunTerminalStatus(record.status)) return true;
2558
+ record.startup = { protocol: AGENT_RUN_PROTOCOL, phase };
2559
+ writeRunRecord(record, deps);
2560
+ return true;
2561
+ }, { strict: true });
2562
+ const deadline = Date.now() + 2e3;
2563
+ while (!attempt()) {
2564
+ if (Date.now() >= deadline) throw new Error(`Startup evidence lock busy: ${runId}`);
2565
+ await new Promise((resolve2) => setTimeout(resolve2, 20));
2566
+ }
2567
+ }
2568
+ async function settleBackgroundProcessExit(runId, code, signal, deps = {}) {
2569
+ const deadline = Date.now() + 2e3;
2570
+ while (true) {
2571
+ const settled = withRunRecordLock(runId, deps, () => {
2572
+ const record = readRunRecord(runId, deps);
2573
+ if (!record) return true;
2574
+ if (isRunTerminalStatus(record.status)) {
2575
+ record.processExit = { code, signal };
2576
+ writeRunRecord(record, deps);
2577
+ return true;
2578
+ }
2579
+ return false;
2580
+ }, { strict: true });
2581
+ if (settled === true) return;
2582
+ if (settled === false) {
2583
+ const result = transitionRunToTerminal(runId, {
2584
+ status: signal === "SIGTERM" || signal === "SIGKILL" ? "killed" : "failed",
2585
+ exitCode: code ?? 1,
2586
+ processExit: { code, signal },
2587
+ failureReason: signal === "SIGTERM" || signal === "SIGKILL" ? "cancelled" : "startup_failed",
2588
+ note: `Child exited without terminal result (code=${code}, signal=${signal})`
2589
+ }, deps);
2590
+ if (result.kind !== "contended") return;
2591
+ }
2592
+ if (Date.now() >= deadline) throw new Error(`Process exit settlement lock busy: ${runId}`);
2593
+ await (deps.sleep ?? defaultSleep)(20);
2594
+ }
2595
+ }
2213
2596
  async function spawnLocalBackgroundRun(input, deps = {}) {
2214
2597
  const homedir = deps.homedir ?? nodeHomedir;
2215
2598
  const env = deps.env ?? (deps.homedir ? { ...process.env, NOLO_HOME: join2(homedir(), ".nolo") } : process.env);
@@ -2255,13 +2638,44 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
2255
2638
  }
2256
2639
  } catch {
2257
2640
  }
2641
+ const executionRequest = input.localExecution;
2642
+ if (executionRequest && (executionRequest.runtimeKey !== "local" || typeof executionRequest.readOnly !== "boolean" || typeof executionRequest.hostWritesAuthorized !== "boolean" || !executionRequest.readOnly && !executionRequest.hostWritesAuthorized)) {
2643
+ throw new Error("Invalid authorized local execution facts");
2644
+ }
2645
+ const canonicalCwd = executionRequest ? String((fs.realpathSync ?? nodeFs2.realpathSync)(targetCwd)) : void 0;
2646
+ const executionWorktree = canonicalCwd ? trustedLocalWorktree(canonicalCwd, resolvedDeps) : void 0;
2647
+ const execution = executionRequest ? {
2648
+ state: "known",
2649
+ kind: "host-local",
2650
+ runtimeKey: "local",
2651
+ device: { kind: "localhost", hostname: nodeHostname(), platform: deps.platform ?? process.platform },
2652
+ canonicalCwd,
2653
+ ...executionWorktree ? { worktree: executionWorktree } : {},
2654
+ permissions: {
2655
+ hostWritesAuthorized: executionRequest.hostWritesAuthorized,
2656
+ readOnly: executionRequest.readOnly,
2657
+ ...executionRequest.allowedToolNames ? { allowedToolNames: [...executionRequest.allowedToolNames] } : {},
2658
+ ...executionRequest.blockedToolNames ? { blockedToolNames: [...executionRequest.blockedToolNames] } : {}
2659
+ },
2660
+ provenance: executionRequest.provenance,
2661
+ owner: { state: "unknown" }
2662
+ } : { state: "unknown", reason: "missing-host-facts" };
2258
2663
  const title = normalizeRunTitle(input.title);
2259
2664
  const record = {
2665
+ ...input.evidenceScope ? { evidenceScope: input.evidenceScope } : {},
2666
+ ...input.dispatchSpeedProvenance ? { dispatchSpeedProvenance: input.dispatchSpeedProvenance } : {},
2260
2667
  runId,
2668
+ startup: { protocol: AGENT_RUN_PROTOCOL, phase: "spawn" },
2261
2669
  agentKey: input.agentKey,
2262
- ...typeof input.agentName === "string" && input.agentName.trim() ? { agentName: input.agentName.trim() } : {},
2670
+ agentName: input.agentName?.trim() || shortAgentKey(input.agentKey),
2263
2671
  ...title ? { title } : {},
2264
- cwd: input.cwd,
2672
+ cwd: canonicalCwd ?? input.cwd,
2673
+ execution,
2674
+ ...executionRequest ? { writerLaunch: { protocol: "fenced-launch-v1", attemptId: randomUUID2(), phase: "prepared" } } : {},
2675
+ ...executionRequest ? (() => {
2676
+ const parent = nativeOwner(process.pid, resolvedDeps);
2677
+ return parent.state === "verified" ? { ownerPublication: { state: "pending", parent } } : {};
2678
+ })() : {},
2265
2679
  ...messagePath ? { msgFile: messagePath } : input.msgFile ? { msgFile: input.msgFile } : {},
2266
2680
  startedAt: now().toISOString(),
2267
2681
  ...typeof input.timeoutMs === "number" ? { timeoutMs: input.timeoutMs } : {},
@@ -2269,6 +2683,7 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
2269
2683
  logPath,
2270
2684
  queuePath,
2271
2685
  batchId,
2686
+ ...input.selectionCheck ? { selectionCheck: input.selectionCheck } : {},
2272
2687
  ...typeof input.credentialGroup === "string" && input.credentialGroup.trim() ? { credentialGroup: input.credentialGroup.trim() } : {},
2273
2688
  ...typeof input.parentDialogId === "string" && input.parentDialogId.trim() ? { parentDialogId: input.parentDialogId.trim() } : {},
2274
2689
  ...typeof input.dialogId === "string" && input.dialogId.trim() ? { dialogId: input.dialogId.trim() } : {},
@@ -2281,24 +2696,39 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
2281
2696
  const rawArgsWithQueue = (input.rawArgs ?? []).some(
2282
2697
  (arg) => arg === "--queue-file" || arg.startsWith("--queue-file=")
2283
2698
  ) ? input.rawArgs : [...input.rawArgs ?? [], "--queue-file", queuePath];
2284
- const { execPath, childArgs } = buildAgentRunChildCommand(
2285
- {
2286
- rawArgs: rawArgsWithQueue,
2287
- commandPath: input.commandPath,
2288
- cliEntrypointPath: input.cliEntrypointPath,
2289
- messagePath
2290
- },
2291
- deps
2292
- );
2699
+ let childCommand;
2700
+ try {
2701
+ childCommand = buildAgentRunChildCommand(
2702
+ {
2703
+ rawArgs: rawArgsWithQueue,
2704
+ commandPath: input.commandPath,
2705
+ cliEntrypointPath: input.cliEntrypointPath,
2706
+ messagePath
2707
+ },
2708
+ deps
2709
+ );
2710
+ } catch (error) {
2711
+ const result = await settleRunTerminalAuthoritatively(runId, {
2712
+ status: "failed",
2713
+ exitCode: 1,
2714
+ failureReason: error instanceof RuntimeVersionMismatchError ? "runtime_version_mismatch" : "startup_failed",
2715
+ note: String(error)
2716
+ }, resolvedDeps, (id, update, d) => transitionRunToTerminal(id, update, d));
2717
+ if (result.kind === "contended") throw new Error(`Startup settlement lock busy: ${runId}; ${error}`);
2718
+ throw error;
2719
+ }
2720
+ const { execPath, childArgs } = childCommand;
2293
2721
  const childEnv = {
2294
2722
  ...env,
2723
+ NOLO_AGENT_RUN_PROTOCOL: AGENT_RUN_PROTOCOL,
2724
+ NOLO_AGENT_RUN_CONTENT_IDENTITY: HOST_RUNTIME_CONTENT_IDENTITY,
2295
2725
  NOLO_AGENT_RUN_CHILD: "1",
2296
2726
  NOLO_AGENT_RUN_ID: runId,
2297
- ...input.subtaskBudgetLimits ? {
2298
- NOLO_SUBTASK_MAX_TOOL_CALLS: String(input.subtaskBudgetLimits.maxToolCalls),
2299
- NOLO_SUBTASK_MAX_WALL_CLOCK_MS: String(input.subtaskBudgetLimits.maxWallClockMs)
2300
- } : {}
2727
+ ...record.writerLaunch ? { NOLO_WRITER_LAUNCH_ATTEMPT: record.writerLaunch.attemptId } : {}
2301
2728
  };
2729
+ if (!record.writerLaunch) delete childEnv.NOLO_WRITER_LAUNCH_ATTEMPT;
2730
+ delete childEnv.NOLO_SUBTASK_MAX_TOOL_CALLS;
2731
+ delete childEnv.NOLO_SUBTASK_MAX_WALL_CLOCK_MS;
2302
2732
  let hostMemory = null;
2303
2733
  let reservation;
2304
2734
  const logFd = fs.openSync(logPath, "a");
@@ -2312,6 +2742,8 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
2312
2742
  ...fs.statSync ? { statSync: (path) => ({ mtimeMs: fs.statSync(path).mtimeMs }) } : {}
2313
2743
  };
2314
2744
  let proc;
2745
+ let preparedScope;
2746
+ const launchScope = (r) => JSON.stringify({ cwd: r.cwd, execution: r.execution, claim: r.localWriterClaim, publication: r.ownerPublication });
2315
2747
  try {
2316
2748
  reservation = reserveHostMemory({
2317
2749
  runsDir,
@@ -2323,8 +2755,14 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
2323
2755
  getProcessStartTime: () => null,
2324
2756
  withLock: (id, fn, opts) => withRunRecordLock(id, resolvedDeps, fn, opts)
2325
2757
  });
2758
+ const spawnCwd = input.claimLocalWrites ? acquireLocalWriterClaim(runId, input.cwd ?? process.cwd(), resolvedDeps) : canonicalCwd ?? input.cwd;
2759
+ if (record.writerLaunch) {
2760
+ const prepared = readRunRecord(runId, resolvedDeps);
2761
+ if (!prepared || prepared.writerLaunch?.phase !== "prepared" || prepared.writerLaunch.attemptId !== record.writerLaunch.attemptId) throw new Error("[local-writer-resource] launch attempt revoked before spawn");
2762
+ preparedScope = launchScope(prepared);
2763
+ }
2326
2764
  proc = spawn(execPath, childArgs, {
2327
- cwd: input.cwd,
2765
+ cwd: spawnCwd,
2328
2766
  env: childEnv,
2329
2767
  detached: true,
2330
2768
  // Detached on Windows means no console; hide the one its children would create.
@@ -2334,35 +2772,97 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
2334
2772
  } catch (error) {
2335
2773
  try {
2336
2774
  reservation?.release("spawn_sync_failed");
2775
+ if (input.claimLocalWrites) releaseUnspawnedLocalWriterClaim(runId, resolvedDeps);
2337
2776
  } finally {
2338
- finalizeRunRecord(runId, { status: "failed", exitCode: 1, note: String(error) }, resolvedDeps);
2777
+ finalizeRunRecord(runId, { status: "failed", exitCode: 1, failureReason: error instanceof RuntimeVersionMismatchError ? "runtime_version_mismatch" : "startup_failed", note: String(error) }, resolvedDeps);
2339
2778
  }
2340
2779
  throw error;
2341
2780
  } finally {
2342
2781
  fs.closeSync?.(logFd);
2343
2782
  }
2344
2783
  proc.once?.("error", (error) => {
2784
+ let note = String(error);
2345
2785
  try {
2346
2786
  reservation.release("child_error");
2347
2787
  } catch (releaseError) {
2348
- finalizeRunRecord(runId, {
2349
- status: "failed",
2350
- exitCode: 1,
2351
- note: `${error}; reservation release failed: ${releaseError}`
2352
- }, resolvedDeps);
2353
- return;
2788
+ note += `; reservation release failed: ${releaseError}`;
2789
+ }
2790
+ void settleRunTerminalAuthoritatively(runId, {
2791
+ status: "failed",
2792
+ exitCode: 1,
2793
+ failureReason: "startup_failed",
2794
+ note
2795
+ }, resolvedDeps, (id, update, d) => transitionRunToTerminal(id, update, d)).then((result) => {
2796
+ if (result.kind === "contended") throw new Error(`Startup settlement lock busy: ${runId}`);
2797
+ }).catch((error2) => {
2798
+ input.output?.write(`[nolo] background error settlement failed: ${error2}
2799
+ `);
2800
+ });
2801
+ });
2802
+ proc.once?.("exit", (code, signal) => {
2803
+ void settleBackgroundProcessExit(runId, code, signal, resolvedDeps).catch((error) => {
2804
+ input.output?.write(`[nolo] background exit settlement failed: ${error}
2805
+ `);
2806
+ });
2807
+ try {
2808
+ reservation.release("child_exit");
2809
+ } catch (error) {
2810
+ input.output?.write(`[nolo] reservation release failed: ${error}
2811
+ `);
2354
2812
  }
2355
- finalizeRunRecord(runId, { status: "failed", exitCode: 1, note: String(error) }, resolvedDeps);
2356
2813
  });
2357
2814
  const hostMemoryNotice = emitHostMemoryNotice(hostMemory, input.output);
2358
2815
  if (typeof proc.pid === "number") {
2359
- withRunRecordLock(runId, resolvedDeps, () => {
2360
- const latest = readRunRecord(runId, resolvedDeps) ?? record;
2816
+ const nativeStartedAt = executionRequest ? probeProcessStartTime(proc.pid, resolvedDeps) : null;
2817
+ let linuxIdentity;
2818
+ if (executionRequest && (deps.platform ?? process.platform) === "linux") {
2819
+ try {
2820
+ const stat = String(nodeFs2.readFileSync(`/proc/${proc.pid}/stat`, "utf8"));
2821
+ const startTicks = stat.slice(stat.lastIndexOf(")") + 2).split(/\s+/)[19];
2822
+ const bootId = nodeFs2.readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
2823
+ if (/^\d+$/.test(startTicks) && bootId) linuxIdentity = { bootId, startTicks };
2824
+ } catch {
2825
+ }
2826
+ }
2827
+ const confirmedStart = executionRequest ? probeProcessStartTime(proc.pid, resolvedDeps) : null;
2828
+ const stableNativeIdentity = nativeStartedAt && confirmedStart && nativeStartedAt.getTime() === confirmedStart.getTime() && !isPidGone(proc.pid, resolvedDeps);
2829
+ const publishOwner = () => withRunRecordLock(runId, resolvedDeps, () => {
2830
+ const latest = readRunRecord(runId, resolvedDeps);
2831
+ if (!latest) throw new Error("[local-writer-resource] publication record missing");
2832
+ if (record.writerLaunch) {
2833
+ const launch = latest.writerLaunch;
2834
+ if (launch?.protocol !== "fenced-launch-v1" || launch.attemptId !== record.writerLaunch.attemptId || launch.phase !== "prepared") {
2835
+ throw new Error("[local-writer-resource] publication attempt revoked/mismatched");
2836
+ }
2837
+ if (launchScope(latest) !== preparedScope) throw new Error("[local-writer-resource] publication scope changed");
2838
+ }
2361
2839
  latest.pid = proc.pid;
2362
- latest.processIdentity ??= "unverified";
2840
+ if (latest.execution?.state === "known") {
2841
+ const verified = stableNativeIdentity && ((deps.platform ?? process.platform) !== "linux" || linuxIdentity);
2842
+ latest.execution.owner = verified ? {
2843
+ state: "verified",
2844
+ pid: proc.pid,
2845
+ startedAt: nativeStartedAt.toISOString(),
2846
+ source: "parent-native",
2847
+ ...linuxIdentity ? { linux: linuxIdentity } : {}
2848
+ } : { state: "unknown" };
2849
+ latest.processIdentity = verified ? "verified" : "unverified";
2850
+ latest.processStartedAt = verified ? nativeStartedAt.toISOString() : void 0;
2851
+ } else {
2852
+ latest.processIdentity ??= "unverified";
2853
+ }
2854
+ if (latest.writerLaunch && latest.execution?.state === "known" && latest.execution.owner.state === "verified") {
2855
+ latest.writerLaunch.phase = "granted";
2856
+ }
2857
+ if (latest.ownerPublication) latest.ownerPublication.state = "complete";
2363
2858
  writeRunRecord(latest, resolvedDeps);
2364
2859
  return true;
2365
- }, { strict: true });
2860
+ }, { strict: true, requireDeadOwner: true });
2861
+ const publicationDeadline = Date.now() + 2e3;
2862
+ while (!publishOwner()) {
2863
+ if (Date.now() >= publicationDeadline) throw new Error("[local-writer-resource] parent owner publication lock busy");
2864
+ await new Promise((resolve2) => setTimeout(resolve2, 20));
2865
+ }
2366
2866
  try {
2367
2867
  const persisted = readRunRecord(runId, resolvedDeps);
2368
2868
  reservation.associate({ runId, pid: proc.pid, processStartedAt: persisted?.processStartedAt });
@@ -2387,6 +2887,8 @@ async function spawnLocalBackgroundRun(input, deps = {}) {
2387
2887
  logPath,
2388
2888
  queuePath,
2389
2889
  batchId,
2890
+ agentName: record.agentName ?? shortAgentKey(input.agentKey),
2891
+ ...input.selectionCheck ? { selectionCheck: input.selectionCheck } : {},
2390
2892
  ...hostMemoryNotice ? { hostMemoryNotice } : {}
2391
2893
  };
2392
2894
  }
@@ -2462,10 +2964,15 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
2462
2964
  if (!record2) return { kind: "not_found" };
2463
2965
  const orphanCorrection = options.allowOverOrphaned === true && record2.status === "orphaned" && (update.status === "done" || update.status === "failed");
2464
2966
  if (isAgentRunTerminalStatus(record2.status) && !orphanCorrection) {
2967
+ if (update.processExit) {
2968
+ record2.processExit = update.processExit;
2969
+ writeRunRecord(record2, deps);
2970
+ }
2465
2971
  return { kind: "kept", record: record2 };
2466
2972
  }
2467
2973
  const now = deps.now ?? (() => /* @__PURE__ */ new Date());
2468
2974
  record2.status = update.status;
2975
+ if (update.processExit) record2.processExit = update.processExit;
2469
2976
  if (typeof update.exitCode === "number") record2.exitCode = update.exitCode;
2470
2977
  if (update.dialogId) record2.dialogId = update.dialogId;
2471
2978
  if (typeof update.credits === "number" && Number.isFinite(update.credits)) {
@@ -2495,8 +3002,31 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
2495
3002
  if (typeof update.lastAssistantText === "string" && update.lastAssistantText) {
2496
3003
  record2.lastAssistantText = update.lastAssistantText.slice(0, 2e3);
2497
3004
  }
3005
+ if (update.cacheUsage) {
3006
+ record2.cacheHitRatio = update.cacheUsage.cache_hit_ratio;
3007
+ record2.cacheCachedTokens = update.cacheUsage.cached_tokens;
3008
+ }
2498
3009
  record2.endedAt = now().toISOString();
2499
- if (typeof update.lastAssistantText === "string" && update.lastAssistantText) {
3010
+ let resultWriteFailed = false;
3011
+ let pendingResultFile;
3012
+ let stagingComplete = false;
3013
+ let backupFile;
3014
+ let backupVerified = false;
3015
+ const registerArtifact = (path, kind) => {
3016
+ const fs = deps.fs ?? nodeFs2;
3017
+ const stat = fs.lstatSync?.(path);
3018
+ if (!stat || !stat.isFile() || stat.isSymbolicLink()) return;
3019
+ const artifact = {
3020
+ publisher: "run-result-v1",
3021
+ path,
3022
+ kind,
3023
+ dev: String(stat.dev),
3024
+ ino: String(stat.ino),
3025
+ sha256: createHash("sha256").update(fs.readFileSync(path)).digest("hex")
3026
+ };
3027
+ record2.resultArtifacts = [...(record2.resultArtifacts ?? []).filter((a) => a.path !== path), artifact];
3028
+ };
3029
+ 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") {
2500
3030
  try {
2501
3031
  const fs = deps.fs ?? nodeFs2;
2502
3032
  const resultFile = join2(resolveRunsDir(deps.env, deps.homedir), `${runId}.result.md`);
@@ -2505,6 +3035,7 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
2505
3035
  const content = buildResultFileContent(
2506
3036
  {
2507
3037
  runId,
3038
+ acceptance: update.acceptance,
2508
3039
  status: record2.status,
2509
3040
  agentName: record2.agentName,
2510
3041
  model: update.model,
@@ -2519,16 +3050,54 @@ function transitionRunToTerminal(runId, update, deps = {}, options = {}) {
2519
3050
  continuedFrom: record2.continuedFrom,
2520
3051
  ...update.cacheUsage ? { cacheUsage: update.cacheUsage } : {}
2521
3052
  },
2522
- update.lastAssistantText
3053
+ update.lastAssistantText ?? ""
2523
3054
  );
2524
- fs.writeFileSync(resultFile, content, "utf8");
3055
+ if (typeof fs.renameSync !== "function") throw new Error("atomic result publication requires renameSync");
3056
+ pendingResultFile = `${resultFile}.${randomUUID2()}.pending`;
3057
+ try {
3058
+ fs.writeFileSync(pendingResultFile, content, { encoding: "utf8", flag: "wx" });
3059
+ stagingComplete = true;
3060
+ } finally {
3061
+ if (fs.existsSync(pendingResultFile)) registerArtifact(pendingResultFile, "pending");
3062
+ }
3063
+ if (fs.existsSync(resultFile)) {
3064
+ const previous = fs.readFileSync(resultFile);
3065
+ const backup = `${resultFile}.${randomUUID2()}.bak`;
3066
+ backupFile = backup;
3067
+ try {
3068
+ fs.writeFileSync(backup, previous, { flag: "wx" });
3069
+ } finally {
3070
+ if (fs.existsSync(backup)) registerArtifact(backup, "bak");
3071
+ }
3072
+ const sameBytes = (a, b) => Buffer.from(a).equals(Buffer.from(b));
3073
+ if (!sameBytes(previous, fs.readFileSync(backup)) || !sameBytes(previous, fs.readFileSync(resultFile))) {
3074
+ throw new Error("previous result backup verification failed");
3075
+ }
3076
+ backupVerified = true;
3077
+ }
3078
+ fs.renameSync(pendingResultFile, resultFile);
3079
+ record2.resultArtifacts = record2.resultArtifacts?.filter((a) => a.path !== pendingResultFile);
3080
+ pendingResultFile = void 0;
2525
3081
  record2.resultFile = resultFile;
2526
3082
  } catch {
3083
+ resultWriteFailed = true;
3084
+ delete record2.resultFile;
3085
+ if (record2.status === "done") {
3086
+ record2.status = "failed";
3087
+ record2.exitCode = 1;
3088
+ }
2527
3089
  }
2528
3090
  }
2529
3091
  if (typeof update.note === "string" && update.note.trim()) {
2530
3092
  record2.note = update.note.trim();
2531
3093
  }
3094
+ if (resultWriteFailed) {
3095
+ if (record2.note?.startsWith("orphaned:")) record2.note = void 0;
3096
+ const fs = deps.fs ?? nodeFs2;
3097
+ const stagingNote = pendingResultFile ? fs.existsSync(pendingResultFile) ? `${stagingComplete ? "complete staging copy" : "incomplete staging fragment"}: ${pendingResultFile}` : `staging not created: ${pendingResultFile}` : "staging not created";
3098
+ const backupNote = backupFile ? `${fs.existsSync(backupFile) ? backupVerified ? "full verified backup" : "partial backup" : "backup not created"}: ${backupFile}` : "backup not created";
3099
+ record2.note = [record2.note, `result file write failed; complete final report was not saved; ${stagingNote}; ${backupNote}`].filter(Boolean).join("; ");
3100
+ }
2532
3101
  if (record2.note?.startsWith("orphaned:")) record2.note = void 0;
2533
3102
  writeRunRecord(record2, deps);
2534
3103
  return { kind: "transitioned", record: record2 };
@@ -2604,10 +3173,10 @@ function defaultGetProcessStartTime(pid, deps = {}) {
2604
3173
  // 这会让 isPidReused 的结论依赖调用者环境:同一条 run 记录在英文
2605
3174
  // locale 下被判 pid reused → orphaned,中文 locale 下不判。强制 C
2606
3175
  // locale 让输出恒为可解析的英文格式,结果与 locale 无关。
2607
- env: { ...process.env, LC_ALL: "C", LANG: "C" }
3176
+ env: { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC" }
2608
3177
  }).trim();
2609
3178
  if (!output) return null;
2610
- const d = new Date(output);
3179
+ const d = new Date(output.endsWith("Z") || /[+-]\d\d:\d\d$/.test(output) ? output : `${output} UTC`);
2611
3180
  return isNaN(d.getTime()) ? null : d;
2612
3181
  } catch {
2613
3182
  return null;
@@ -2659,6 +3228,7 @@ function checkStaleRun(runId, deps = {}) {
2659
3228
  const latest = readRunRecord(runId, deps);
2660
3229
  if (!latest) return record;
2661
3230
  if (latest.status !== "running") return latest;
3231
+ if (latest.pid !== record.pid || latest.processStartedAt !== record.processStartedAt || latest.processIdentity !== record.processIdentity) return latest;
2662
3232
  if (latest.activity?.updatedAt !== record.activity?.updatedAt) return latest;
2663
3233
  const at = now().toISOString();
2664
3234
  latest.status = "orphaned";
@@ -2674,6 +3244,16 @@ function checkStaleRun(runId, deps = {}) {
2674
3244
  }
2675
3245
  latest.endedAt = at;
2676
3246
  latest.reconciledAt = at;
3247
+ if ((pidGone || pidReused) && latest.localWriterClaim?.state === "held") {
3248
+ latest.localWriterClaim.state = "released";
3249
+ }
3250
+ latest.ownerDeath = {
3251
+ pid: latest.pid,
3252
+ processStartedAt: latest.processStartedAt,
3253
+ processIdentity: latest.processIdentity,
3254
+ ...latest.execution?.state === "known" ? { executionOwner: latest.execution.owner } : {},
3255
+ confirmedAt: at
3256
+ };
2677
3257
  latest.pid = void 0;
2678
3258
  writeRunRecord(latest, deps);
2679
3259
  return latest;
@@ -2844,6 +3424,7 @@ async function runAgentStatusCommand(args, deps) {
2844
3424
  const { partialCheckpoint, ...summary } = record;
2845
3425
  deps.output.write(JSON.stringify({
2846
3426
  ...summary,
3427
+ ...localWriterRecovery(record) ? { writerRecovery: localWriterRecovery(record) } : {},
2847
3428
  ...includeCheckpoint ? { checkpoint: partialCheckpoint ? { ...partialCheckpoint, available: true } : { available: false, final: false, reason: "checkpoint_missing" } } : {}
2848
3429
  }) + "\n");
2849
3430
  return 0;
@@ -2878,6 +3459,9 @@ function printStatusOnce(record, deps) {
2878
3459
  deps.output.write(`status: ${record.status}
2879
3460
  `);
2880
3461
  deps.output.write(`pid: ${record.pid ?? "-"}
3462
+ `);
3463
+ const recovery = localWriterRecovery(record);
3464
+ if (recovery) deps.output.write(`writerRecovery: required (${recovery.reason}); automatic release forbidden; native launch evidence required
2881
3465
  `);
2882
3466
  deps.output.write(`agent: ${record.agentKey}
2883
3467
  `);
@@ -3135,6 +3719,16 @@ async function runAgentStopCommand(args, deps) {
3135
3719
  async function runAgentKillCommand(args, deps) {
3136
3720
  return runSignalCommand(args, "SIGKILL", "kill", deps);
3137
3721
  }
3722
+ async function runAgentRecoverPreparedWriterCommand(args, deps) {
3723
+ if (args.length !== 3 || args[1] !== "--attempt-id" || !/^[A-Za-z0-9_-]+$/.test(args[0] ?? "") || !args[2] || args[2].startsWith("-")) {
3724
+ deps.output.write("Usage: nolo agent recover-prepared-writer <runId> --attempt-id <attemptId>\n");
3725
+ return 1;
3726
+ }
3727
+ const [runId, , attemptId] = args;
3728
+ const outcome = revokePreparedWriterLaunch(runId, attemptId, deps);
3729
+ deps.output.write(JSON.stringify({ action: "recoverPreparedWriter", runId, attemptId, outcome }) + "\n");
3730
+ return outcome === "blocked" ? 1 : 0;
3731
+ }
3138
3732
 
3139
3733
  export {
3140
3734
  createShellApprovalChild,
@@ -3145,6 +3739,7 @@ export {
3145
3739
  recordRunResultHeaderMeta,
3146
3740
  getRunResultHeaderMeta,
3147
3741
  serverOriginForDialog,
3742
+ isHistoryIntegrityFailure,
3148
3743
  RUN_TERMINAL_STATUSES,
3149
3744
  isRunTerminalStatus,
3150
3745
  resolveNoloHome,
@@ -3181,6 +3776,7 @@ export {
3181
3776
  readRunRecord,
3182
3777
  backfillRunRecordParentDialog,
3183
3778
  listRunRecords,
3779
+ listRunRecordsAsync,
3184
3780
  findRunRecordByPid,
3185
3781
  findRunRecord,
3186
3782
  DEFAULT_LIST_LIMIT,
@@ -3192,6 +3788,14 @@ export {
3192
3788
  absolutizeSkillArgs,
3193
3789
  rewriteMsgFileArg,
3194
3790
  buildAgentRunChildCommand,
3791
+ localWriterRecovery,
3792
+ revokePreparedWriterLaunch,
3793
+ validateLocalWriterChild,
3794
+ awaitLocalWriterChild,
3795
+ resolveLocalContinuation,
3796
+ registerLocalForegroundWriter,
3797
+ recordRunStartup,
3798
+ settleBackgroundProcessExit,
3195
3799
  spawnLocalBackgroundRun,
3196
3800
  ackRunRecord,
3197
3801
  DEFAULT_ACK_LEASE_TTL_MS,
@@ -3219,5 +3823,6 @@ export {
3219
3823
  TERMINATE_KILL_GRACE_MS,
3220
3824
  terminateRunProcess,
3221
3825
  runAgentStopCommand,
3222
- runAgentKillCommand
3826
+ runAgentKillCommand,
3827
+ runAgentRecoverPreparedWriterCommand
3223
3828
  };