nolo-cli 0.228.0-alpha.2 → 0.228.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.
Files changed (260) hide show
  1. package/README.md +3 -5
  2. package/{_executeModel-VYCHHZVT.js → _executeModel-AKCTHGMP.js} +89 -83
  3. package/{accountResolver-QETKNC7T.js → accountResolver-NGICIMEE.js} +1 -1
  4. package/{action-GDZDXPMB.js → action-C6IQAKN4.js} +8 -5
  5. package/{addContentAction-7RO4AMRI.js → addContentAction-53364YDW.js} +13 -12
  6. package/{addDialogAgentAction-EVYBGTXB.js → addDialogAgentAction-U5DD5EN5.js} +16 -15
  7. package/{agentDeleteCommand-QWQKT54A.js → agentDeleteCommand-2E5FAGUO.js} +128 -115
  8. package/{agentEmailCommands-EISMBIRE.js → agentEmailCommands-UGZZAH7E.js} +128 -111
  9. package/{agentListCommands-4WLG32IW.js → agentListCommands-JCTW3J2K.js} +398 -179
  10. package/{agentMachineCommands-DC6NKWTU.js → agentMachineCommands-QPG5ZXF4.js} +58 -47
  11. package/{agentProviderCommands-STI3DQ6A.js → agentProviderCommands-QLTABYR7.js} +2 -2
  12. package/{agentPullCommand-KHV4EELF.js → agentPullCommand-2EYJ5ENC.js} +1 -1
  13. package/agentRecordCommands-4NTVR6MZ.js +194 -0
  14. package/agentRunCommand-VHF34PYC.js +232 -0
  15. package/{agentRunControl-MBG4U6SL.js → agentRunControl-QYTXUQGY.js} +14 -9
  16. package/{agentRuntimeLocal-HOXKWCYO.js → agentRuntimeLocal-U54AKHXH.js} +58 -43
  17. package/{agentSlice-UG76KEBH.js → agentSlice-4JGDEXWK.js} +14 -13
  18. package/{appDeleteCommands-WWCC6WA5.js → appDeleteCommands-XBE5QJ6P.js} +58 -47
  19. package/{appDeployCommands-AU4IUN33.js → appDeployCommands-QIYLXXGA.js} +58 -47
  20. package/{appDeployStatusCommands-STUW7WXL.js → appDeployStatusCommands-JXS6ZQZZ.js} +58 -47
  21. package/{appGetCommands-BGTLIQ4K.js → appGetCommands-SZS7SJPK.js} +58 -47
  22. package/{appListCommands-CUCPRUXW.js → appListCommands-B3GBJSNV.js} +58 -47
  23. package/{authCommand-OZ2KTP4Z.js → authCommand-V6EOMZX6.js} +25 -19
  24. package/{authCommands-55OGQGCR.js → authCommands-T5FODCEG.js} +12 -6
  25. package/{builtinSkillRegistry-BAE2LDXF.js → builtinSkillRegistry-ZQC3IIO2.js} +8 -7
  26. package/{chromeCommands-G5UDKVSV.js → chromeCommands-O4IIKTBD.js} +384 -7
  27. package/{chromeOpsCommands-WAA45NCS.js → chromeOpsCommands-OFX7ZGKP.js} +3 -3
  28. package/{chunk-DBUR22G5.js → chunk-223KZUJ6.js} +19 -15
  29. package/{chunk-3U44JB3O.js → chunk-2C5VN7NH.js} +1 -1
  30. package/{chunk-PWTNI4N7.js → chunk-2E4BYAUE.js} +22 -0
  31. package/{chunk-L32W3PRP.js → chunk-2FZVXOFX.js} +234 -18
  32. package/{chunk-HBRDSQ3M.js → chunk-2JHGUL5K.js} +3 -2
  33. package/chunk-2SXN7LAY.js +15 -0
  34. package/chunk-3A5NNQCN.js +64 -0
  35. package/chunk-3F2FRLIO.js +372 -0
  36. package/{chunk-DEA37IUY.js → chunk-46FETNLF.js} +2 -2
  37. package/{chunk-ZEVQHCLM.js → chunk-4GYVS4PM.js} +8 -6
  38. package/{chunk-CBUZ6DKA.js → chunk-4YPH5KRA.js} +1 -1
  39. package/chunk-4ZCTKB27.js +31 -0
  40. package/chunk-53W5BXLN.js +340 -0
  41. package/{chunk-7FEP5USX.js → chunk-5AYP5QBB.js} +5 -5
  42. package/{chunk-XAG3FWBE.js → chunk-5ISNPTQH.js} +5 -5
  43. package/{chunk-EVGU5P4U.js → chunk-5P3PPQVP.js} +1 -1
  44. package/{chunk-XSW4EXQV.js → chunk-6BMTKYAO.js} +55 -18
  45. package/chunk-6PAHSSD2.js +33401 -0
  46. package/{chunk-ZOHO6MOF.js → chunk-6RSNVJGO.js} +2 -99
  47. package/{chunk-7JGMNKKG.js → chunk-6SOWMEAY.js} +30 -9
  48. package/{chunk-RG2DGNL6.js → chunk-6VEO7Z3Y.js} +3 -3
  49. package/{chunk-PDCV7P5W.js → chunk-6XIE5ZGI.js} +1 -1
  50. package/{chunk-DGYCDA6W.js → chunk-7BIJFGKS.js} +36 -17
  51. package/{chunk-WFDNADFX.js → chunk-7OVOZRZF.js} +8 -8
  52. package/{chunk-WCFFRBL5.js → chunk-7PON4LBY.js} +45 -27
  53. package/{chunk-QRGDJA4B.js → chunk-7WHCIA5V.js} +33 -7
  54. package/{chunk-CMMI3DAT.js → chunk-ADYWV732.js} +59 -30
  55. package/{chunk-QYB23WUH.js → chunk-AIFQKNPP.js} +1 -1
  56. package/{chunk-HGDKT2D6.js → chunk-BPB3T5EU.js} +174 -1
  57. package/{chunk-DUUDXSLX.js → chunk-BZLGPM5B.js} +28 -4
  58. package/{chunk-ATEKLSLR.js → chunk-BZMDWGQQ.js} +14 -9
  59. package/chunk-C5A54QS7.js +108 -0
  60. package/{chunk-S6K5F3KP.js → chunk-CEKRIR22.js} +1 -1
  61. package/{chunk-42OKN2LI.js → chunk-D634SL2Y.js} +9 -107
  62. package/{chunk-DLXMMTGM.js → chunk-DHRPLRIR.js} +1283 -786
  63. package/{chunk-LKA64WH4.js → chunk-DMPZMYH4.js} +37 -1
  64. package/{chunk-OBIC6EG7.js → chunk-DNNPARJK.js} +9 -5
  65. package/{chunk-X3E6EHJW.js → chunk-E3LSO6EI.js} +292 -207
  66. package/{chunk-OQHIVPG4.js → chunk-E6A5NHDH.js} +4 -1
  67. package/chunk-EHFBP6IK.js +791 -0
  68. package/chunk-EJQE5HB7.js +21 -0
  69. package/{chunk-VQ5N5GSV.js → chunk-EL5NRJHI.js} +4 -4
  70. package/chunk-EUGTFFO6.js +42 -0
  71. package/{chunk-7BCG67EI.js → chunk-EVHTYVD2.js} +1199 -442
  72. package/{chunk-6XRPBZRS.js → chunk-EYLGAEB4.js} +0 -134
  73. package/{chunk-262R3XNN.js → chunk-FEIVARWR.js} +377 -112
  74. package/{chunk-3VZLEKV2.js → chunk-FLBJ7IJI.js} +14 -14
  75. package/{chunk-EEOOBRA7.js → chunk-FXEPZKNJ.js} +13 -6
  76. package/{chunk-XTJKU3Z4.js → chunk-FYAMUU55.js} +677 -140
  77. package/{chunk-M3OZRQNH.js → chunk-FZANZZ63.js} +1 -1
  78. package/chunk-GAHJLSDO.js +107 -0
  79. package/{chunk-WWTSEBDF.js → chunk-GIXWVN2W.js} +1 -1
  80. package/{chunk-4N6G2CKP.js → chunk-HDKMVYNJ.js} +47 -1
  81. package/chunk-HEVRQGGH.js +106 -0
  82. package/{chunk-BIWI5M4E.js → chunk-HFHJPHFK.js} +1 -1
  83. package/{chunk-R6Z5S5GA.js → chunk-HPDLPEUG.js} +60 -17
  84. package/{chunk-YKY4OVOX.js → chunk-HQUGB2HM.js} +17 -170
  85. package/chunk-IIRJ4P4I.js +24 -0
  86. package/chunk-IVK2KT3H.js +209 -0
  87. package/{chunk-ALAES342.js → chunk-IYLUK67R.js} +9 -5
  88. package/{chunk-N5Z2V73W.js → chunk-J55F3IEZ.js} +1 -1
  89. package/{chunk-S6FDXXZV.js → chunk-J7JRCOIW.js} +2 -2
  90. package/{chunk-OWKNSIXL.js → chunk-JAKRY74O.js} +470 -83
  91. package/{chunk-VS276URX.js → chunk-JCQ3WCQ3.js} +4 -2
  92. package/chunk-JLZJL3WC.js +988 -0
  93. package/{chunk-OBSEKCVK.js → chunk-JPXACKSW.js} +219 -52
  94. package/{chunk-OTKSESZR.js → chunk-KDBDOXOM.js} +138 -54
  95. package/{chunk-VP3BINY7.js → chunk-KDDHQMSH.js} +31 -1
  96. package/{chunk-RBPUNSG5.js → chunk-KG27JIG4.js} +18 -108
  97. package/{chunk-4WVJLODK.js → chunk-KHYSFS3W.js} +88 -7
  98. package/{chunk-TCZ2VJZQ.js → chunk-KKIQAVDR.js} +9 -9
  99. package/{chunk-4JVNURX4.js → chunk-KQHEGELM.js} +68 -16
  100. package/chunk-KXOPLLFP.js +190 -0
  101. package/{chunk-HS7MLR74.js → chunk-KZ4A7EIV.js} +3 -5
  102. package/{chunk-HYLRQDEE.js → chunk-LLUBUHNT.js} +6 -6
  103. package/{chunk-QJTZ76CP.js → chunk-LS5KAVFQ.js} +1 -0
  104. package/{chunk-RTHFJZ6M.js → chunk-LVZVSLKO.js} +29 -9
  105. package/{chunk-TI2EPRHE.js → chunk-MNFUKRRU.js} +3 -3
  106. package/chunk-MVOZ22RZ.js +26 -0
  107. package/{chunk-CNMY2XM6.js → chunk-O3A2CHAL.js} +6 -6
  108. package/{chunk-TSPMLCWI.js → chunk-OB4FBZXJ.js} +5 -5
  109. package/{chunk-LYD6C7OU.js → chunk-OJSJJKHF.js} +6 -6
  110. package/{chunk-M4SFKP5L.js → chunk-OKAXQFON.js} +3 -3
  111. package/{chunk-CD3RU7XL.js → chunk-OKH74FML.js} +121 -14
  112. package/{chunk-U2HBB7RS.js → chunk-OOV5JN25.js} +130 -30
  113. package/{chunk-ZH3KXFHS.js → chunk-OOVOAG4Q.js} +1 -1
  114. package/chunk-OQFOE4SJ.js +405 -0
  115. package/{chunk-M3JEW6N6.js → chunk-OYUMJMC5.js} +15 -0
  116. package/chunk-P27E22MA.js +203 -0
  117. package/{chunk-SRCCSTIM.js → chunk-P4R5KXU7.js} +4 -4
  118. package/{chunk-FJ23FZXF.js → chunk-PHREU2KZ.js} +5 -3
  119. package/{chunk-HSSBDZLD.js → chunk-PIVTQRX6.js} +43 -13
  120. package/{chunk-XFXFPUO7.js → chunk-PJL7OJRC.js} +13 -39
  121. package/{chunk-RRDRQOEC.js → chunk-PNLDLUMO.js} +276 -303
  122. package/{chunk-4I2MXV5Q.js → chunk-PVFYPUIM.js} +2 -0
  123. package/{chunk-HHFGE2WF.js → chunk-QGFLVQ6E.js} +5 -5
  124. package/{chunk-EGHP7KOY.js → chunk-QONAOHVW.js} +38 -29
  125. package/chunk-R3FZHW4Q.js +103 -0
  126. package/{chunk-ZYKJBRZ3.js → chunk-R3MV2GII.js} +1 -47
  127. package/chunk-R72QWIFO.js +50 -0
  128. package/{chunk-5FUN7EG4.js → chunk-RD3QLZQV.js} +83 -47
  129. package/{chunk-ILHQ2AXT.js → chunk-RIWKZT7E.js} +36 -8
  130. package/{chunk-OOJNQK6V.js → chunk-S25VJYXV.js} +8 -2
  131. package/{chunk-45CAVC35.js → chunk-S7H4KTMB.js} +2568 -337
  132. package/{chunk-OJ45MEEI.js → chunk-SA356NGW.js} +1 -1
  133. package/{chunk-F6Z6ZCUV.js → chunk-SCAC3NM5.js} +3 -3
  134. package/{chunk-YVFH2MFB.js → chunk-SLUN7W6S.js} +7 -7
  135. package/chunk-SQL7YNED.js +650 -0
  136. package/chunk-SR4FE5VD.js +9 -0
  137. package/{chunk-HF7BLF3F.js → chunk-SSOR2EDT.js} +107 -104
  138. package/chunk-TRRXYFTR.js +46 -0
  139. package/{chunk-3QIYD3VM.js → chunk-TUOHSUK5.js} +20068 -18402
  140. package/chunk-TYJCIA2O.js +835 -0
  141. package/{chunk-S2NTVGA2.js → chunk-U35UUM5K.js} +2 -1
  142. package/{chunk-GAYNXB6T.js → chunk-U3BUWDUP.js} +1031 -2155
  143. package/{chunk-BP5ZJ6B4.js → chunk-U6QNVOR5.js} +1 -1
  144. package/{chunk-UAIHKQIA.js → chunk-U6RD332P.js} +18 -2
  145. package/chunk-UAF5VQCE.js +77 -0
  146. package/{chunk-TQEKUOTI.js → chunk-UFGUJ2IH.js} +12 -12
  147. package/{chunk-VMJVAJ6W.js → chunk-UP7KBWLE.js} +109 -33
  148. package/{chunk-2X7WFDT6.js → chunk-UUCYUN6Y.js} +1 -1
  149. package/{chunk-5YMA6DDZ.js → chunk-UZKBVQUX.js} +1 -1
  150. package/chunk-V5TI7HJH.js +133 -0
  151. package/{chunk-WFGNWWJI.js → chunk-VH7UO6E5.js} +252 -114
  152. package/{chunk-MNEZUL5S.js → chunk-VJFDG3ZG.js} +63 -94
  153. package/{chunk-G7IUT2V3.js → chunk-WC3J5SL2.js} +635 -350
  154. package/{chunk-HXB4VDGK.js → chunk-WD5547ZF.js} +33 -30
  155. package/chunk-WDWZPASX.js +29 -0
  156. package/{chunk-4ZGPHFLE.js → chunk-WS36XPJD.js} +2 -2
  157. package/{chunk-6QHKRARD.js → chunk-WSLL7VV4.js} +29 -5
  158. package/chunk-XRGBJHZX.js +136 -0
  159. package/{chunk-MZG5CETE.js → chunk-Y2KWJTOZ.js} +4 -4
  160. package/{dialogUsageCommand-W2WCSGKF.js → chunk-Y2TCTNUD.js} +27 -20
  161. package/chunk-YJPK35HB.js +175 -0
  162. package/{chunk-6OVNSQHN.js → chunk-YLAHYLDQ.js} +5 -0
  163. package/{chunk-547ENH5T.js → chunk-YN23INFZ.js} +4 -4
  164. package/{chunk-4QYJPWHH.js → chunk-YXK3GJF5.js} +232 -10
  165. package/{chunk-MJI3UAXN.js → chunk-Z2OWAYMI.js} +77 -51
  166. package/{chunk-7Z6EW7AH.js → chunk-ZTHAJU3O.js} +106 -14
  167. package/{chunk-YFLVRVYK.js → chunk-ZYPXOQS2.js} +1 -1
  168. package/{cliAgentConfigHelpers-BTRHMPW2.js → cliAgentConfigHelpers-BXHQ3PXP.js} +9 -9
  169. package/{cliAuthorityBrokerClient-XHH7MH2P.js → cliAuthorityBrokerClient-TFNXJLXL.js} +1 -1
  170. package/cliAuthorityBrokerProcess-5ZFBTHLB.js +22 -0
  171. package/cliLocalAgentRecordReader-47PXMHPH.js +104 -0
  172. package/{commandRegistry-FVYPE2IN.js → commandRegistry-CTMPAQH2.js} +111 -162
  173. package/{contentThunks-GNFPG32S.js → contentThunks-CAHIIZO5.js} +38 -36
  174. package/{cooldownCommands-YB5H5BBK.js → cooldownCommands-WDOI5VD7.js} +3 -3
  175. package/{createAgentAutomationAction-PB4QIFQ4.js → createAgentAutomationAction-M25XZSPD.js} +38 -36
  176. package/{createDialogAction-EVTOPY7A.js → createDialogAction-4SN7FKI7.js} +39 -37
  177. package/{createPageAction-2UYF2IDZ.js → createPageAction-N7QPDN3M.js} +43 -41
  178. package/{db-M7FU2GNK.js → db-VR74ADGC.js} +7 -2
  179. package/{dbSlice-XRUZOGSU.js → dbSlice-RWPSVHBC.js} +12 -11
  180. package/{deleteFile-6URDHYRB.js → deleteFile-ECU6FU5C.js} +15 -7
  181. package/{dialogCommands-6SZD4TYP.js → dialogCommands-BBHWCKDP.js} +69 -53
  182. package/dialogMessageRecord-OAV77LT7.js +7 -0
  183. package/{dialogNotifyCommand-SHGPCU22.js → dialogNotifyCommand-IASQGEMW.js} +11 -11
  184. package/{dialogSlice-5EQ2A6LY.js → dialogSlice-JI3J22RV.js} +39 -37
  185. package/dialogTraceCommand-EW2KK6A4.js +961 -0
  186. package/dialogUsageCommand-WJ3U6KZU.js +27 -0
  187. package/{docCreateCommands-25E6PGN3.js → docCreateCommands-QSX3X5U4.js} +57 -46
  188. package/{docDeleteCommands-F7ZVGEHW.js → docDeleteCommands-63JBG2HQ.js} +59 -48
  189. package/{docReadCommands-JY2E5XEN.js → docReadCommands-CQFKRQUI.js} +57 -46
  190. package/{docStore-OKKIKLT3.js → docStore-XLBKGGNM.js} +14 -13
  191. package/{docUpdateCommands-OZ4CUSIQ.js → docUpdateCommands-534LUK25.js} +57 -46
  192. package/ebookDownloaderAgentCommand-DYSKF5ZY.js +677 -0
  193. package/fetchMessages-TQEUZD7H.js +1 -1
  194. package/{getPricing-LF5C4XSI.js → getPricing-5BLZRPTM.js} +4 -4
  195. package/{handleSendMessageAction-LNT7SZND.js → handleSendMessageAction-Q2VMEVOR.js} +127 -81
  196. package/{hostCredentialCreate-XUU2CSHI.js → hostCredentialCreate-C57T7YPE.js} +127 -109
  197. package/index.js +23 -11
  198. package/{localDialogRead-CCOCVGAP.js → localDialogRead-BJJT3TF5.js} +1 -1
  199. package/{localRuntimeAdapter-IBSTMSX7.js → localRuntimeAdapter-OALZPFZU.js} +134 -115
  200. package/localRuntimeAuthority-UF2DAQ3F.js +28 -0
  201. package/{localRuntimeDb-N7KHDXS2.js → localRuntimeDb-ZJFGNHML.js} +1 -1
  202. package/{machineCommands-HSQHDHOT.js → machineCommands-N6IVWRZT.js} +262 -325
  203. package/machineWsRunDispatch-PDWYB33B.js +209 -0
  204. package/markdownToSlate-PXYAIBVL.js +8 -0
  205. package/mcpLocalAuthorizeCommand-KYI4EGF5.js +110 -0
  206. package/{memberThunks-7Y3OYSJQ.js → memberThunks-43B7UYC5.js} +21 -16
  207. package/{models-H5NNZRLH.js → models-ZX2BYIMB.js} +2 -2
  208. package/{overlay-BBQZXGYI.js → overlay-JA3SPVUS.js} +5 -3
  209. package/package.json +2 -1
  210. package/{projectArchive-FQO654Z3.js → projectArchive-TJNW5DLM.js} +46 -44
  211. package/{providerPresetApply-WHAMP2D5.js → providerPresetApply-NTJUINI6.js} +36 -17
  212. package/{providerRegistry-ZI2KORJ7.js → providerRegistry-W45SLUV6.js} +6 -6
  213. package/{read-TYMBGEXO.js → read-KG6INYUT.js} +13 -7
  214. package/{readDocTool-SKQVHBLO.js → readDocTool-N3GA52JR.js} +1 -1
  215. package/{readlineWorkspace-7U272DSA.js → readlineWorkspace-PJZJVGA5.js} +7486 -4492
  216. package/rememberExplicit-CPAPONSI.js +15 -0
  217. package/{removeDialogAgentAction-F5QE2O2B.js → removeDialogAgentAction-EEVSOQOJ.js} +18 -17
  218. package/{runAgentClientLoop-AF4JQIJ7.js → runAgentClientLoop-3VC5TCDW.js} +107 -76
  219. package/{runtimeDoctorCommands-RRKPBGVO.js → runtimeDoctorCommands-V3M3JTUV.js} +14 -11
  220. package/{secretCommands-KZWBZIYS.js → secretCommands-KVVZS7A6.js} +3 -3
  221. package/{setDialogExtraReferencesAction-72L27ERM.js → setDialogExtraReferencesAction-DNO5POHA.js} +15 -14
  222. package/{setPrimaryDialogAgentAction-GJJDUSGJ.js → setPrimaryDialogAgentAction-QABBEO4C.js} +18 -17
  223. package/{settingThunks-ZRGWVGZD.js → settingThunks-DVKG4X4S.js} +181 -66
  224. package/{skillDiscovery-BHHPCUHZ.js → skillDiscovery-ZMJH36AK.js} +4 -3
  225. package/{spaceCommands-5VNWMDBE.js → spaceCommands-AGGZXPY3.js} +235 -87
  226. package/{streamAgentChatTurn-YSPEFY4K.js → streamAgentChatTurn-4GTLL2OF.js} +242 -169
  227. package/{switchDialogAgentAction-IIJBPND3.js → switchDialogAgentAction-KYWJSGOO.js} +16 -15
  228. package/{tableCommands-FTAOCBTX.js → tableCommands-EFA754RE.js} +7 -4
  229. package/{toolApiClient-OGQEBQVX.js → toolApiClient-N5PYW2R3.js} +8 -6
  230. package/{tools-M35PTIFB.js → tools-5AGPOPLW.js} +69 -65
  231. package/{tuiRestart-2IL37YIB.js → tuiRestart-77E7PL4R.js} +11 -10
  232. package/{tuiSummaryLlmCaller-W2QN4VAC.js → tuiSummaryLlmCaller-HROLGN4F.js} +16 -15
  233. package/{updateCommands-CPATDG6J.js → updateCommands-GJGRS6JK.js} +3 -3
  234. package/{updateDialogTitleAction-IMIRJRQQ.js → updateDialogTitleAction-5OSEDGRK.js} +40 -38
  235. package/{usageCommand-2BF74MKF.js → usageCommand-WI6SQOPB.js} +2 -2
  236. package/{usageRebuildCommand-UHB55BQM.js → usageRebuildCommand-WQRLLZAT.js} +3 -3
  237. package/webapi-QVV65DQF.js +2487 -0
  238. package/{windowsSelfUpdate-ZFD6J5HF.js → windowsSelfUpdate-C7LGVWYX.js} +2 -2
  239. package/workContext-Y3ADAPZU.js +14 -0
  240. package/workContextAccess-VU5I4LKZ.js +11 -0
  241. package/workContextWriteNotice-YCSSMHN4.js +7 -0
  242. package/{workloadLifecycle-HFJIN5IZ.js → workloadLifecycle-P2SJVV3S.js} +2 -2
  243. package/agentRecordCommands-IZYUVHME.js +0 -177
  244. package/agentRunCommand-QM7ETUTX.js +0 -209
  245. package/chunk-2YGBI2XB.js +0 -30
  246. package/chunk-5ZMIIR23.js +0 -265
  247. package/chunk-5ZUOVCKT.js +0 -32
  248. package/chunk-62HXNQVV.js +0 -134
  249. package/chunk-FJSNBZXR.js +0 -142
  250. package/chunk-FPBJM2BW.js +0 -689
  251. package/chunk-JQZRSXS5.js +0 -90
  252. package/chunk-P2ZLUIW2.js +0 -795
  253. package/chunk-PPJYZRSQ.js +0 -160
  254. package/chunk-TUSTONB3.js +0 -81
  255. package/chunk-ZXF6D3I6.js +0 -359
  256. package/cliLocalAgentRecordReader-H3HYQRRR.js +0 -91
  257. package/lib-OT5OTXRU.js +0 -21046
  258. package/localRuntimeAuthority-IBJAT62G.js +0 -16
  259. package/machineWsRunDispatch-L6H7J66T.js +0 -192
  260. package/{chunk-W6RFEDN4.js → chunk-AETZ7AD6.js} +3 -3
@@ -0,0 +1,988 @@
1
+ import {
2
+ loadCliAuthorityBrokerTls
3
+ } from "./chunk-3A5NNQCN.js";
4
+ import {
5
+ Level,
6
+ createLevelAuthorityStore
7
+ } from "./chunk-R3MV2GII.js";
8
+ import {
9
+ createCliAuthorityBrokerClient,
10
+ createCliAuthorityBrokerSocketInvoker
11
+ } from "./chunk-SQL7YNED.js";
12
+ import {
13
+ getLogger
14
+ } from "./chunk-EYLGAEB4.js";
15
+ import {
16
+ getHostRuntimeExecutable,
17
+ isCompiledBinary,
18
+ resolveCliEntrypointPath
19
+ } from "./chunk-BIDSIRTS.js";
20
+ import {
21
+ toErrorMessage
22
+ } from "./chunk-HNMXYYJR.js";
23
+
24
+ // packages/cli/cliAuthorityBrokerProcess.ts
25
+ import { spawn } from "node:child_process";
26
+ import { dirname, isAbsolute, resolve } from "node:path";
27
+ import { setTimeout as delay } from "node:timers/promises";
28
+
29
+ // packages/database-engine/cliAuthorityBrokerServer.ts
30
+ import fs3 from "node:fs";
31
+ import path3 from "node:path";
32
+ import { createServer } from "node:net";
33
+ import { createServer as createTlsServer } from "node:tls";
34
+
35
+ // packages/database-engine/levelDbCorruptionRecovery.ts
36
+ import fs from "node:fs";
37
+ import path from "node:path";
38
+ var CORRUPTION_CODE = "LEVEL_CORRUPTION";
39
+ var CORRUPTION_MESSAGE = /Corruption:|missing files/i;
40
+ var levelClassWithRepair = Level;
41
+ function isLevelCorruptionError(error) {
42
+ const seen = /* @__PURE__ */ new Set();
43
+ let current = error;
44
+ while (current && !seen.has(current)) {
45
+ seen.add(current);
46
+ if (current.code === CORRUPTION_CODE) return true;
47
+ if (CORRUPTION_MESSAGE.test(toErrorMessage(current))) return true;
48
+ current = current.cause;
49
+ }
50
+ return false;
51
+ }
52
+ function formatUtcStamp(now) {
53
+ return new Date(now).toISOString().replace(/[-:]/g, "").replace(/\.\d{3}Z$/, "").replace("T", "-");
54
+ }
55
+ function resolveBackupPath(dbPath, now) {
56
+ const base = `${dbPath}.corrupt-${formatUtcStamp(now)}`;
57
+ let candidate = base;
58
+ for (let index = 2; fs.existsSync(candidate); index += 1) {
59
+ candidate = `${base}-${index}`;
60
+ }
61
+ return candidate;
62
+ }
63
+ async function repairLevelDatabase(dbPath) {
64
+ await levelClassWithRepair.repair(dbPath);
65
+ }
66
+ async function recoverCorruptedLevelDb(options) {
67
+ const { dbPath } = options;
68
+ const log = options.log ?? ((message) => console.warn(message));
69
+ const repair = options.repair ?? repairLevelDatabase;
70
+ const backupPath = resolveBackupPath(dbPath, (options.now ?? Date.now)());
71
+ fs.renameSync(dbPath, backupPath);
72
+ try {
73
+ fs.cpSync(backupPath, dbPath, { recursive: true, preserveTimestamps: true });
74
+ await repair(dbPath);
75
+ } catch (error) {
76
+ try {
77
+ fs.rmSync(dbPath, { recursive: true, force: true });
78
+ fs.renameSync(backupPath, dbPath);
79
+ } catch (rollbackError) {
80
+ throw Object.assign(
81
+ new Error(
82
+ `Failed to repair the local database at ${dbPath} and could not restore the original. The untouched copy is at ${backupPath}; stop every Nolo process before retrying. Do not delete ${path.join(dbPath, "LOCK")} and do not reinstall Nolo: ${toErrorMessage(error)}`,
83
+ { cause: new AggregateError([error, rollbackError], "LevelDB repair and rollback both failed") }
84
+ ),
85
+ { code: CORRUPTION_CODE, backupPath }
86
+ );
87
+ }
88
+ throw Object.assign(
89
+ new Error(
90
+ `Failed to repair the local database at ${dbPath}; the original database was restored unchanged. Stop every Nolo process and run the CLI again. Do not delete ${path.join(dbPath, "LOCK")} and do not reinstall Nolo: ${toErrorMessage(error)}`,
91
+ { cause: error }
92
+ ),
93
+ { code: CORRUPTION_CODE, backupPath }
94
+ );
95
+ }
96
+ log(
97
+ `[nolo] local database corruption detected; preserved original at ${backupPath} and repaired a copy.`
98
+ );
99
+ return { backupPath };
100
+ }
101
+
102
+ // packages/database-engine/levelDbOwnershipLock.ts
103
+ import fs2 from "node:fs";
104
+ import path2 from "node:path";
105
+ var LOCKED_CODE = "LEVEL_LOCKED";
106
+ var UNWRITTEN_LOCK_GRACE_MS = 5e3;
107
+ function createLockError(lockPath, ownerPid) {
108
+ const detail = ownerPid === void 0 ? `the lock file ${lockPath} exists but its owner process is unknown` : `it is held by process ${ownerPid}`;
109
+ return Object.assign(
110
+ new Error(
111
+ `CLI authority database is already open by another process: ${detail} (${lockPath}). Wait for that process to exit, or stop it before starting Nolo again.`
112
+ ),
113
+ { code: LOCKED_CODE, lockPath, ownerPid }
114
+ );
115
+ }
116
+ function isProcessAlive(pid) {
117
+ try {
118
+ process.kill(pid, 0);
119
+ return true;
120
+ } catch (error) {
121
+ return error.code === "EPERM";
122
+ }
123
+ }
124
+ function readLockHolder(lockPath) {
125
+ let raw;
126
+ try {
127
+ raw = fs2.readFileSync(lockPath, "utf8");
128
+ } catch (error) {
129
+ if (error.code === "ENOENT") return void 0;
130
+ throw error;
131
+ }
132
+ let pid;
133
+ try {
134
+ const parsed = JSON.parse(raw);
135
+ if (typeof parsed.pid === "number" && Number.isInteger(parsed.pid) && parsed.pid > 0) {
136
+ pid = parsed.pid;
137
+ }
138
+ } catch {
139
+ }
140
+ let mtimeMs = Date.now();
141
+ try {
142
+ mtimeMs = fs2.statSync(lockPath).mtimeMs;
143
+ } catch {
144
+ }
145
+ return { pid, mtimeMs };
146
+ }
147
+ function acquireLevelDbOwnershipLock(dbPath) {
148
+ const lockPath = `${dbPath}.owner`;
149
+ fs2.mkdirSync(path2.dirname(lockPath), { recursive: true });
150
+ const content = `${JSON.stringify({ pid: process.pid, startedAt: (/* @__PURE__ */ new Date()).toISOString() })}
151
+ `;
152
+ for (let attempt = 0; attempt < 3; attempt += 1) {
153
+ let fd;
154
+ try {
155
+ fd = fs2.openSync(lockPath, "wx", 420);
156
+ } catch (error) {
157
+ if (error.code !== "EEXIST") throw error;
158
+ const holder = readLockHolder(lockPath);
159
+ if (!holder) continue;
160
+ if (holder.pid !== void 0 && isProcessAlive(holder.pid)) {
161
+ throw createLockError(lockPath, holder.pid);
162
+ }
163
+ if (holder.pid === void 0 && Date.now() - holder.mtimeMs < UNWRITTEN_LOCK_GRACE_MS) {
164
+ throw createLockError(lockPath);
165
+ }
166
+ const quarantine = `${lockPath}.stale-${process.pid}-${Date.now()}`;
167
+ try {
168
+ fs2.renameSync(lockPath, quarantine);
169
+ fs2.rmSync(quarantine, { force: true });
170
+ } catch (renameError) {
171
+ if (renameError.code !== "ENOENT") throw renameError;
172
+ }
173
+ continue;
174
+ }
175
+ try {
176
+ fs2.writeSync(fd, content);
177
+ } catch (error) {
178
+ try {
179
+ fs2.closeSync(fd);
180
+ } catch {
181
+ }
182
+ try {
183
+ fs2.rmSync(lockPath, { force: true });
184
+ } catch {
185
+ }
186
+ throw error;
187
+ }
188
+ let released = false;
189
+ return {
190
+ lockPath,
191
+ release() {
192
+ if (released) return;
193
+ released = true;
194
+ try {
195
+ fs2.closeSync(fd);
196
+ } catch {
197
+ }
198
+ try {
199
+ fs2.rmSync(lockPath, { force: true });
200
+ } catch {
201
+ }
202
+ }
203
+ };
204
+ }
205
+ throw createLockError(lockPath);
206
+ }
207
+
208
+ // packages/database-engine/cliAuthorityBrokerServer.ts
209
+ var brokerRegistry = /* @__PURE__ */ new Map();
210
+ var databaseOwners = /* @__PURE__ */ new Map();
211
+ var DEFAULT_ITERATOR_LIMIT = 200;
212
+ var MAX_BROKER_FRAME_CHARS = 64 * 1024 * 1024;
213
+ function resolveBrokerListenTarget(endpoint) {
214
+ if (endpoint.startsWith("unix://")) {
215
+ return { kind: "unix", path: endpoint.slice("unix://".length) };
216
+ }
217
+ if (endpoint.startsWith("tcp://")) {
218
+ const url = new URL(endpoint);
219
+ return {
220
+ kind: "tcp",
221
+ host: url.hostname,
222
+ port: Number(url.port)
223
+ };
224
+ }
225
+ throw new Error(`Unsupported CLI authority broker endpoint: ${endpoint}`);
226
+ }
227
+ function buildListeningEndpoint(server, target) {
228
+ if (target.kind === "unix") {
229
+ return `unix://${target.path}`;
230
+ }
231
+ const address = server.address();
232
+ if (!address || typeof address === "string") {
233
+ return `tcp://${target.host}:${target.port}`;
234
+ }
235
+ const info = address;
236
+ return `tcp://${target.host}:${info.port}`;
237
+ }
238
+ function ensureParentDir(filePath) {
239
+ fs3.mkdirSync(path3.dirname(filePath), { recursive: true });
240
+ }
241
+ function writeJsonFile(filePath, data) {
242
+ if (!filePath) return;
243
+ ensureParentDir(filePath);
244
+ fs3.writeFileSync(filePath, `${JSON.stringify(data, null, 2)}
245
+ `, "utf8");
246
+ }
247
+ function removeFileIfPresent(filePath) {
248
+ if (!filePath) return;
249
+ try {
250
+ fs3.rmSync(filePath, { force: true });
251
+ } catch {
252
+ }
253
+ }
254
+ async function buildIteratorPage(store, request) {
255
+ const base = request.options ?? {};
256
+ const reverse = base.reverse === true;
257
+ const cursor = typeof request.cursor === "string" && request.cursor.length > 0 ? request.cursor : void 0;
258
+ const iterOptions = { ...base };
259
+ if (cursor) {
260
+ if (reverse) {
261
+ if (iterOptions.lte !== void 0 && iterOptions.lte < cursor) {
262
+ } else {
263
+ delete iterOptions.lte;
264
+ iterOptions.lt = iterOptions.lt !== void 0 && iterOptions.lt < cursor ? iterOptions.lt : cursor;
265
+ }
266
+ } else {
267
+ if (iterOptions.gte !== void 0 && iterOptions.gte > cursor) {
268
+ } else {
269
+ delete iterOptions.gte;
270
+ iterOptions.gt = iterOptions.gt !== void 0 && iterOptions.gt > cursor ? iterOptions.gt : cursor;
271
+ }
272
+ }
273
+ }
274
+ const limit = Math.max(0, Math.floor(request.limit ?? DEFAULT_ITERATOR_LIMIT));
275
+ const entries = [];
276
+ let hasMore = false;
277
+ for await (const entry of store.iterator(iterOptions)) {
278
+ const [key] = entry;
279
+ if (cursor && (reverse ? key >= cursor : key <= cursor)) {
280
+ continue;
281
+ }
282
+ if (base.gt !== void 0 && key <= base.gt) {
283
+ continue;
284
+ }
285
+ if (entries.length >= limit) {
286
+ hasMore = true;
287
+ break;
288
+ }
289
+ entries.push(entry);
290
+ }
291
+ const lastEntry = entries.at(-1) ?? null;
292
+ return {
293
+ entries,
294
+ nextCursor: lastEntry ? lastEntry[0] : null,
295
+ done: !hasMore
296
+ };
297
+ }
298
+ function createErrorResponse(error) {
299
+ if (typeof error === "object" && error !== null && typeof error.code === "string" && typeof error.message === "string") {
300
+ return {
301
+ ok: false,
302
+ error: {
303
+ code: error.code,
304
+ message: error.message,
305
+ retryable: error.retryable === true
306
+ }
307
+ };
308
+ }
309
+ return {
310
+ ok: false,
311
+ error: {
312
+ code: "BROKER_INTERNAL_ERROR",
313
+ message: toErrorMessage(error)
314
+ }
315
+ };
316
+ }
317
+ var ownerQueues = /* @__PURE__ */ new WeakMap();
318
+ function ownerQueue(store) {
319
+ let state = ownerQueues.get(store);
320
+ if (!state) {
321
+ state = { tail: Promise.resolve(), active: /* @__PURE__ */ new Set(), closed: false };
322
+ ownerQueues.set(store, state);
323
+ }
324
+ return state;
325
+ }
326
+ function validConditionalPut(request) {
327
+ const expected = request.expectedRevision;
328
+ const value = request.value;
329
+ return Object.keys(request).length === 4 && Object.keys(request).every((key) => ["type", "key", "expectedRevision", "value"].includes(key)) && typeof request.key === "string" && request.key.length > 0 && (expected === null || Number.isSafeInteger(expected) && expected >= 0 && expected < Number.MAX_SAFE_INTEGER) && typeof value === "object" && value !== null && !Array.isArray(value) && Object.hasOwn(value, "revision") && value.revision === (expected === null ? 1 : expected + 1);
330
+ }
331
+ function dispatchCliAuthorityBrokerRequest(store, request) {
332
+ const state = ownerQueue(store);
333
+ if (state.closed) return Promise.resolve({ ok: false, error: { code: "BROKER_CLOSING", message: "Authority broker is closing" } });
334
+ const isRead = request?.type === "get" || request?.type === "batchGet" || request?.type === "status" || request?.type === "iterator" || request?.type === "close";
335
+ const execute = () => executeCliAuthorityBrokerRequest(store, request);
336
+ const result = isRead ? Promise.resolve().then(execute) : state.tail.then(execute);
337
+ if (!isRead) state.tail = result.catch(() => void 0);
338
+ const settled = result.then(() => void 0, () => void 0);
339
+ state.active.add(settled);
340
+ void settled.then(() => state.active.delete(settled));
341
+ return result;
342
+ }
343
+ async function executeCliAuthorityBrokerRequest(store, request) {
344
+ try {
345
+ if (!request || typeof request !== "object") {
346
+ return { ok: false, error: { code: "BROKER_INVALID_REQUEST", message: "Invalid broker request" } };
347
+ }
348
+ switch (request.type) {
349
+ case "conditionalPut": {
350
+ if (!validConditionalPut(request)) {
351
+ return { ok: false, error: { code: "BROKER_INVALID_REQUEST", message: "Invalid conditionalPut request" } };
352
+ }
353
+ let current;
354
+ try {
355
+ current = await store.get(request.key);
356
+ } catch (error) {
357
+ if (error?.code !== "LEVEL_NOT_FOUND") throw error;
358
+ }
359
+ const matches = request.expectedRevision === null ? current === void 0 : typeof current === "object" && current !== null && !Array.isArray(current) && Object.hasOwn(current, "revision") && current.revision === request.expectedRevision;
360
+ if (!matches) return { ok: true, result: { type: "conditionalPut", status: "conflict" } };
361
+ await store.put(request.key, request.value);
362
+ return { ok: true, result: { type: "conditionalPut", status: "updated" } };
363
+ }
364
+ case "status":
365
+ return { ok: true, result: { type: "status", ...request.includeLocation && store.location ? { location: store.location } : {} } };
366
+ case "open":
367
+ await store.open();
368
+ return { ok: true, result: { type: "open" } };
369
+ case "close":
370
+ return { ok: true, result: { type: "close" } };
371
+ case "get":
372
+ return { ok: true, result: { type: "get", value: await store.get(request.key) } };
373
+ case "batchGet": {
374
+ if (!Array.isArray(request.keys) || !request.keys.every((key) => typeof key === "string")) {
375
+ return { ok: false, error: { code: "BROKER_INVALID_REQUEST", message: "Invalid batchGet request" } };
376
+ }
377
+ const items = await Promise.all(
378
+ request.keys.map(async (key) => {
379
+ try {
380
+ return { ok: true, value: await store.get(key) };
381
+ } catch (error) {
382
+ const errRes = createErrorResponse(error);
383
+ return {
384
+ ok: false,
385
+ error: errRes.ok ? { code: "BROKER_INTERNAL_ERROR", message: "Unknown error" } : errRes.error
386
+ };
387
+ }
388
+ })
389
+ );
390
+ return { ok: true, result: { type: "batchGet", items } };
391
+ }
392
+ case "put":
393
+ await store.put(request.key, request.value);
394
+ return { ok: true, result: { type: "put" } };
395
+ case "del":
396
+ await store.del(request.key);
397
+ return { ok: true, result: { type: "del" } };
398
+ case "batchWrite":
399
+ await store.batchWrite(request.ops);
400
+ return { ok: true, result: { type: "batchWrite" } };
401
+ case "iterator":
402
+ return {
403
+ ok: true,
404
+ result: {
405
+ type: "iterator",
406
+ page: await buildIteratorPage(store, request)
407
+ }
408
+ };
409
+ default:
410
+ return { ok: false, error: { code: "BROKER_UNSUPPORTED_REQUEST", message: "Unsupported broker request" } };
411
+ }
412
+ } catch (error) {
413
+ if (request?.type === "conditionalPut") {
414
+ return { ok: false, error: { code: "BROKER_CONDITIONAL_WRITE_FAILED", message: "Conditional write failed" } };
415
+ }
416
+ return createErrorResponse(error);
417
+ }
418
+ }
419
+ async function openAuthorityStoreWithCorruptionRecovery(options, track) {
420
+ let attemptStore;
421
+ try {
422
+ attemptStore = await options.createStore();
423
+ track(attemptStore);
424
+ await attemptStore.open();
425
+ return attemptStore;
426
+ } catch (error) {
427
+ if (!options.dbPath || !isLevelCorruptionError(error)) throw error;
428
+ if (attemptStore) {
429
+ try {
430
+ await attemptStore.close();
431
+ } catch (closeError) {
432
+ throw Object.assign(
433
+ new Error(
434
+ `LevelDB corruption detected at ${options.dbPath}, but the failed database handle could not be closed; on-disk files were left untouched. Stop every Nolo process and retry: ${toErrorMessage(closeError)}`,
435
+ { cause: closeError }
436
+ ),
437
+ { code: "LEVEL_CORRUPTION" }
438
+ );
439
+ }
440
+ track(void 0);
441
+ attemptStore = void 0;
442
+ }
443
+ const { backupPath } = await recoverCorruptedLevelDb({
444
+ dbPath: options.dbPath,
445
+ now: options.now
446
+ });
447
+ try {
448
+ attemptStore = await options.createStore();
449
+ track(attemptStore);
450
+ await attemptStore.open();
451
+ return attemptStore;
452
+ } catch (retryError) {
453
+ throw Object.assign(
454
+ new Error(
455
+ `Local database corruption at ${options.dbPath} was preserved at ${backupPath}, but reopening the repaired copy failed: ${toErrorMessage(retryError)}. Do not reinstall Nolo and do not delete ${path3.join(options.dbPath, "LOCK")}; the preserved original database is at ${backupPath}.`,
456
+ { cause: retryError }
457
+ ),
458
+ { code: "LEVEL_CORRUPTION", backupPath }
459
+ );
460
+ }
461
+ }
462
+ }
463
+ async function createBrokerHandle(options) {
464
+ const target = resolveBrokerListenTarget(options.endpoint);
465
+ const socketMode = (options.transportMode ?? "socket") === "socket";
466
+ let store;
467
+ let ownershipLock;
468
+ const sockets = /* @__PURE__ */ new Set();
469
+ const onConnection = (socket) => {
470
+ sockets.add(socket);
471
+ socket.once("close", () => sockets.delete(socket));
472
+ socket.on("error", () => {
473
+ });
474
+ if (!storeReady || !store) {
475
+ socket.once("data", () => {
476
+ socket.end(`${JSON.stringify({ ok: false, error: { code: "BROKER_UNAVAILABLE", message: "CLI authority broker is starting", retryable: true } })}
477
+ `);
478
+ });
479
+ return;
480
+ }
481
+ bindSocketRequestHandler({ socket, store, maxFrameChars: options.maxFrameChars });
482
+ };
483
+ const server = options.tls ? createTlsServer({ ...options.tls, requestCert: true, rejectUnauthorized: true, handshakeTimeout: 5e3 }, onConnection) : createServer(onConnection);
484
+ let storeReady = false;
485
+ try {
486
+ if (socketMode) {
487
+ if (target.kind === "unix") ensureParentDir(target.path);
488
+ await new Promise((resolve2, reject) => {
489
+ server.once("error", reject);
490
+ const onListening = () => {
491
+ server.off("error", reject);
492
+ resolve2();
493
+ };
494
+ if (target.kind === "unix") server.listen(target.path, onListening);
495
+ else server.listen(target.port, target.host, onListening);
496
+ });
497
+ if (!options.keepProcessAlive) server.unref();
498
+ }
499
+ if (options.dbPath) {
500
+ ownershipLock = acquireLevelDbOwnershipLock(options.dbPath);
501
+ }
502
+ store = await openAuthorityStoreWithCorruptionRecovery(options, (created) => {
503
+ store = created;
504
+ });
505
+ storeReady = true;
506
+ const readyStore = store;
507
+ const now = options.now ?? Date.now;
508
+ const listeningEndpoint = (options.transportMode ?? "socket") === "socket" ? buildListeningEndpoint(server, target) : options.endpoint;
509
+ writeJsonFile(options.metadataPath, {
510
+ pid: process.pid,
511
+ ...options.tls ? { transportSecurity: "mutual-tls" } : {},
512
+ ...options.supervisorPid === void 0 ? {} : { supervisorPid: options.supervisorPid },
513
+ endpoint: listeningEndpoint,
514
+ location: readyStore.location ?? listeningEndpoint,
515
+ startedAt: new Date(now()).toISOString()
516
+ });
517
+ writeJsonFile(options.healthPath, {
518
+ ok: true,
519
+ pid: process.pid,
520
+ endpoint: listeningEndpoint,
521
+ checkedAt: new Date(now()).toISOString()
522
+ });
523
+ let closing;
524
+ return {
525
+ endpoint: options.endpoint,
526
+ listeningEndpoint,
527
+ authorityStore: {
528
+ ...createCliAuthorityBrokerClient({
529
+ endpoint: listeningEndpoint,
530
+ invoke: (request) => dispatchCliAuthorityBrokerRequest(readyStore, request)
531
+ }),
532
+ get location() {
533
+ return readyStore.location;
534
+ },
535
+ get status() {
536
+ return readyStore.status;
537
+ }
538
+ },
539
+ request(request) {
540
+ return dispatchCliAuthorityBrokerRequest(readyStore, request);
541
+ },
542
+ async close() {
543
+ closing ??= (async () => {
544
+ storeReady = false;
545
+ const queue = ownerQueue(readyStore);
546
+ queue.closed = true;
547
+ await Promise.all(queue.active);
548
+ for (const socket of sockets) socket.destroy();
549
+ if (server.listening) {
550
+ await new Promise((resolve2, reject) => {
551
+ server.close((error) => error ? reject(error) : resolve2());
552
+ });
553
+ }
554
+ await readyStore.close();
555
+ brokerRegistry.delete(options.endpoint);
556
+ releaseDatabaseOwnership(options);
557
+ ownershipLock?.release();
558
+ ownershipLock = void 0;
559
+ removeFileIfPresent(options.metadataPath);
560
+ removeFileIfPresent(options.healthPath);
561
+ })().catch((error) => {
562
+ closing = void 0;
563
+ throw error;
564
+ });
565
+ return closing;
566
+ }
567
+ };
568
+ } catch (error) {
569
+ storeReady = false;
570
+ for (const socket of sockets) socket.destroy();
571
+ if (server.listening) {
572
+ await new Promise((resolve2) => server.close(() => resolve2()));
573
+ }
574
+ if (store) {
575
+ try {
576
+ await store.close();
577
+ } catch (closeError) {
578
+ throw Object.assign(new AggregateError([error, closeError], "Broker startup failed and the native authority store could not close"), { retainAuthorityOwnership: true });
579
+ }
580
+ }
581
+ ownershipLock?.release();
582
+ throw error;
583
+ }
584
+ }
585
+ function isMultiplexedEnvelope(value) {
586
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
587
+ const record = value;
588
+ return (typeof record.id === "number" || typeof record.id === "string") && "request" in record && typeof record.request === "object" && record.request !== null && !("type" in record);
589
+ }
590
+ function firstNonWhitespaceChar(text) {
591
+ for (let i = 0; i < text.length; i += 1) {
592
+ const ch = text[i];
593
+ if (ch === " " || ch === " " || ch === "\r" || ch === "\n") {
594
+ continue;
595
+ }
596
+ return ch;
597
+ }
598
+ return void 0;
599
+ }
600
+ function bindSocketRequestHandler(args) {
601
+ const maxFrameChars = args.maxFrameChars ?? MAX_BROKER_FRAME_CHARS;
602
+ let buffer = "";
603
+ let inFlight = 0;
604
+ let clientEnded = false;
605
+ let sawLegacyBareRequest = false;
606
+ let protocolRejected = false;
607
+ let currentFrameVerifiedObjectStart = false;
608
+ args.socket.setEncoding("utf8");
609
+ args.socket.setNoDelay?.(true);
610
+ const maybeFinishHalfOpen = () => {
611
+ if (clientEnded && inFlight === 0 && !args.socket.destroyed) {
612
+ args.socket.end();
613
+ }
614
+ };
615
+ const rejectAndDestroy = () => {
616
+ protocolRejected = true;
617
+ buffer = "";
618
+ currentFrameVerifiedObjectStart = false;
619
+ if (!args.socket.destroyed) {
620
+ args.socket.destroy();
621
+ }
622
+ };
623
+ const handleParsedPayload = async (parsed) => {
624
+ inFlight += 1;
625
+ args.socket.ref?.();
626
+ if (isMultiplexedEnvelope(parsed)) {
627
+ let response2;
628
+ try {
629
+ response2 = await dispatchCliAuthorityBrokerRequest(args.store, parsed.request);
630
+ } catch (error) {
631
+ response2 = createErrorResponse(error);
632
+ }
633
+ inFlight -= 1;
634
+ if (!args.socket.destroyed && args.socket.writable) {
635
+ args.socket.write(`${JSON.stringify({ id: parsed.id, response: response2 })}
636
+ `);
637
+ }
638
+ if (inFlight === 0 && !clientEnded) {
639
+ args.socket.unref?.();
640
+ }
641
+ maybeFinishHalfOpen();
642
+ return;
643
+ }
644
+ let response;
645
+ try {
646
+ response = await dispatchCliAuthorityBrokerRequest(
647
+ args.store,
648
+ parsed
649
+ );
650
+ } catch (error) {
651
+ response = createErrorResponse(error);
652
+ }
653
+ inFlight -= 1;
654
+ if (!args.socket.destroyed && args.socket.writable) {
655
+ args.socket.end(`${JSON.stringify(response)}
656
+ `);
657
+ }
658
+ };
659
+ args.socket.on("data", (chunk) => {
660
+ if (protocolRejected || sawLegacyBareRequest) return;
661
+ const textChunk = typeof chunk === "string" ? chunk : chunk.toString("utf8");
662
+ if (!currentFrameVerifiedObjectStart) {
663
+ const firstChar = firstNonWhitespaceChar(textChunk);
664
+ if (firstChar !== void 0) {
665
+ if (firstChar !== "{") {
666
+ rejectAndDestroy();
667
+ return;
668
+ }
669
+ currentFrameVerifiedObjectStart = true;
670
+ }
671
+ }
672
+ buffer += textChunk;
673
+ let newlineIndex;
674
+ while ((newlineIndex = buffer.indexOf("\n")) !== -1) {
675
+ if (newlineIndex > maxFrameChars) {
676
+ rejectAndDestroy();
677
+ break;
678
+ }
679
+ const rawLine = buffer.slice(0, newlineIndex).trim();
680
+ buffer = buffer.slice(newlineIndex + 1);
681
+ currentFrameVerifiedObjectStart = false;
682
+ if (!rawLine) continue;
683
+ if (rawLine[0] !== "{") {
684
+ rejectAndDestroy();
685
+ break;
686
+ }
687
+ let parsed;
688
+ try {
689
+ parsed = JSON.parse(rawLine);
690
+ } catch (error) {
691
+ protocolRejected = true;
692
+ buffer = "";
693
+ args.socket.pause?.();
694
+ if (!args.socket.destroyed && args.socket.writable) {
695
+ args.socket.end(`${JSON.stringify(createErrorResponse(error))}
696
+ `, () => {
697
+ if (!args.socket.destroyed) args.socket.destroy();
698
+ });
699
+ } else if (!args.socket.destroyed) {
700
+ args.socket.destroy();
701
+ }
702
+ break;
703
+ }
704
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
705
+ rejectAndDestroy();
706
+ break;
707
+ }
708
+ if (!isMultiplexedEnvelope(parsed)) {
709
+ sawLegacyBareRequest = true;
710
+ }
711
+ void handleParsedPayload(parsed);
712
+ if (sawLegacyBareRequest) break;
713
+ }
714
+ if (!protocolRejected && !sawLegacyBareRequest) {
715
+ if (buffer.length > maxFrameChars) {
716
+ rejectAndDestroy();
717
+ return;
718
+ }
719
+ if (!currentFrameVerifiedObjectStart && buffer.length > 0) {
720
+ const remainingFirstChar = firstNonWhitespaceChar(buffer);
721
+ if (remainingFirstChar !== void 0) {
722
+ if (remainingFirstChar !== "{") {
723
+ rejectAndDestroy();
724
+ return;
725
+ }
726
+ currentFrameVerifiedObjectStart = true;
727
+ }
728
+ }
729
+ }
730
+ });
731
+ args.socket.on("end", () => {
732
+ if (protocolRejected) {
733
+ if (!args.socket.destroyed) args.socket.destroy();
734
+ return;
735
+ }
736
+ clientEnded = true;
737
+ maybeFinishHalfOpen();
738
+ });
739
+ }
740
+ function canonicalDatabasePath(dbPath) {
741
+ const absolute = path3.resolve(dbPath);
742
+ try {
743
+ return fs3.realpathSync(absolute);
744
+ } catch (error) {
745
+ if (error.code !== "ENOENT") throw error;
746
+ const parent = path3.dirname(absolute);
747
+ if (parent === absolute) throw error;
748
+ return path3.join(canonicalDatabasePath(parent), path3.basename(absolute));
749
+ }
750
+ }
751
+ function releaseDatabaseOwnership(options) {
752
+ if (!options.dbPath) return;
753
+ const identity = options.dbPath;
754
+ if (databaseOwners.get(identity) === options.endpoint) databaseOwners.delete(identity);
755
+ }
756
+ function getOrCreateCliAuthorityBrokerServer(options) {
757
+ options = { ...options, dbPath: options.dbPath ? canonicalDatabasePath(options.dbPath) : void 0 };
758
+ const existing = brokerRegistry.get(options.endpoint);
759
+ if (existing) {
760
+ if (options.dbPath && databaseOwners.get(options.dbPath) !== options.endpoint) {
761
+ return Promise.reject(new Error(`CLI authority endpoint ${options.endpoint} already owns another database`));
762
+ }
763
+ return existing;
764
+ }
765
+ if (options.dbPath) {
766
+ const identity = canonicalDatabasePath(options.dbPath);
767
+ const owner = databaseOwners.get(identity);
768
+ if (owner) {
769
+ return Promise.reject(Object.assign(new Error(`CLI authority database already owned by ${owner}`), { code: "LEVEL_LOCKED" }));
770
+ }
771
+ databaseOwners.set(identity, options.endpoint);
772
+ }
773
+ const pending = createBrokerHandle(options).catch((error) => {
774
+ if (!error?.retainAuthorityOwnership) releaseDatabaseOwnership(options);
775
+ brokerRegistry.delete(options.endpoint);
776
+ throw error;
777
+ });
778
+ brokerRegistry.set(options.endpoint, pending);
779
+ return pending;
780
+ }
781
+
782
+ // packages/cli/cliAuthorityBrokerProcess.ts
783
+ var testOwnedBroker = () => process.env.NOLO_TEST_AUTHORITY_BROKER_LIFETIME === "1";
784
+ function stopOnParentExit(stop) {
785
+ process.stdin.once("end", stop);
786
+ process.stdin.once("error", stop);
787
+ process.stdin.resume();
788
+ }
789
+ function describeFailure(error, depth = 0) {
790
+ if (!(error instanceof Error)) return { message: String(error) };
791
+ const { message, code, ownerPid, cause } = error;
792
+ return {
793
+ message,
794
+ ...typeof code === "string" ? { code } : {},
795
+ ...typeof ownerPid === "number" ? { ownerPid } : {},
796
+ ...cause !== void 0 && depth < 4 ? { cause: describeFailure(cause, depth + 1) } : {}
797
+ };
798
+ }
799
+ async function startCliAuthorityBrokerProcess(options) {
800
+ const child = await launchBroker(options, true);
801
+ child.unref();
802
+ }
803
+ async function launchBroker(options, detached) {
804
+ const { endpoint, dbPath, metadataPath, healthPath } = options;
805
+ if (!dbPath || !metadataPath || !healthPath) throw new Error("Missing authority broker paths");
806
+ const entrypoint = isCompiledBinary() ? [] : [resolveCliEntrypointPath(import.meta.url)];
807
+ const { PATH, HOME, USERPROFILE, LOCALAPPDATA, SystemRoot, TMPDIR, TEMP, TMP } = process.env;
808
+ const testOwned = testOwnedBroker();
809
+ const child = spawn(getHostRuntimeExecutable(), [
810
+ ...entrypoint,
811
+ detached ? "__authority-broker-supervise" : "__authority-broker",
812
+ endpoint,
813
+ resolve(dbPath),
814
+ resolve(metadataPath),
815
+ resolve(healthPath),
816
+ ...detached ? [] : [String(process.pid)]
817
+ ], {
818
+ detached,
819
+ windowsHide: true,
820
+ // Only tests hold a lifetime pipe. Production deliberately outlives its launcher.
821
+ stdio: [testOwned ? "pipe" : "ignore", "pipe", "ignore"],
822
+ env: {
823
+ PATH,
824
+ HOME,
825
+ USERPROFILE,
826
+ LOCALAPPDATA,
827
+ SystemRoot,
828
+ TMPDIR,
829
+ TEMP,
830
+ TMP,
831
+ NOLO_HOME: dirname(dirname(resolve(dbPath))),
832
+ ...testOwned ? { NOLO_TEST_AUTHORITY_BROKER_LIFETIME: "1" } : {}
833
+ }
834
+ });
835
+ child.stdin?.on("error", () => {
836
+ });
837
+ const output = child.stdout;
838
+ try {
839
+ await new Promise((resolve2, reject) => {
840
+ let response = "";
841
+ const timer = setTimeout(() => reject(new Error(`Authority broker startup timed out at ${endpoint}`)), 3e4);
842
+ const done = (error) => {
843
+ clearTimeout(timer);
844
+ if (error) reject(error);
845
+ else resolve2();
846
+ };
847
+ child.once("error", done);
848
+ child.once("exit", (_code, signal) => {
849
+ if (signal) done(new Error(`Authority broker exited during startup (${signal})`));
850
+ });
851
+ output.once("error", done);
852
+ output.once("end", () => done(new Error("Authority broker exited before reporting readiness")));
853
+ output.setEncoding("utf8");
854
+ output.on("data", (chunk) => {
855
+ response += chunk;
856
+ if (response.length > 64 * 1024) return done(new Error("Oversized authority broker startup response"));
857
+ const newline = response.indexOf("\n");
858
+ if (newline < 0) return;
859
+ try {
860
+ const result = JSON.parse(response.slice(0, newline));
861
+ if (result.ok === true) done();
862
+ else if (result.error) done(Object.assign(new Error(result.error.message), result.error));
863
+ else done(new Error("Invalid authority broker startup response"));
864
+ } catch {
865
+ done(new Error("Invalid authority broker startup response"));
866
+ }
867
+ });
868
+ });
869
+ return child;
870
+ } catch (error) {
871
+ child.stdin?.end();
872
+ child.unref();
873
+ throw error;
874
+ } finally {
875
+ output.destroy();
876
+ }
877
+ }
878
+ async function superviseCliAuthorityBrokerProcess(args) {
879
+ const [endpoint, dbPath, metadataPath, healthPath] = args;
880
+ const options = { endpoint: endpoint ?? "", dbPath, metadataPath, healthPath };
881
+ const logger = getLogger("cli.authorityBroker");
882
+ const stop = new AbortController();
883
+ const requestStop = () => stop.abort();
884
+ process.once("SIGTERM", requestStop);
885
+ process.once("SIGINT", requestStop);
886
+ if (testOwnedBroker()) stopOnParentExit(requestStop);
887
+ process.stdout.on("error", () => {
888
+ });
889
+ let ready = false;
890
+ try {
891
+ if (!metadataPath) throw new Error("Missing authority broker metadata path");
892
+ const tls = await loadCliAuthorityBrokerTls(metadataPath);
893
+ while (!stop.signal.aborted) {
894
+ const child = await launchBroker(options, false);
895
+ logger.info("Authority broker worker ready", { endpoint, workerPid: child.pid, supervisorPid: process.pid });
896
+ if (!ready) {
897
+ process.stdout.write('{"ok":true}\n');
898
+ ready = true;
899
+ }
900
+ const workerExit = new AbortController();
901
+ const exited = child.exitCode !== null || child.signalCode !== null ? Promise.resolve(workerExit.abort()) : new Promise((resolve2) => child.once("exit", () => {
902
+ workerExit.abort();
903
+ resolve2();
904
+ }));
905
+ const workerRunning = AbortSignal.any([workerExit.signal, stop.signal]);
906
+ const invoke = createCliAuthorityBrokerSocketInvoker({ endpoint: options.endpoint, timeoutMs: 2e3, tls });
907
+ let failures = 0;
908
+ while (!workerRunning.aborted && failures < 3) {
909
+ await delay(5e3, void 0, { signal: workerRunning }).catch(() => {
910
+ });
911
+ if (workerRunning.aborted) break;
912
+ try {
913
+ const health = await invoke({ type: "get", key: "cli-authority-broker-health" });
914
+ failures = health.ok && health.result.type === "get" ? 0 : failures + 1;
915
+ } catch (error) {
916
+ failures += 1;
917
+ logger.warn("Authority broker storage probe failed", error, { endpoint, workerPid: child.pid, failures });
918
+ }
919
+ }
920
+ invoke.close?.();
921
+ if (child.exitCode === null && child.signalCode === null) {
922
+ if (!stop.signal.aborted) logger.warn("Restarting unresponsive authority broker worker", { endpoint, workerPid: child.pid });
923
+ if (child.stdin) child.stdin.end();
924
+ else child.kill("SIGTERM");
925
+ const killed = await Promise.race([exited.then(() => true), delay(5e3, false, { ref: false })]);
926
+ if (!killed) {
927
+ child.kill("SIGKILL");
928
+ await exited;
929
+ }
930
+ }
931
+ if (!stop.signal.aborted) await delay(1e3);
932
+ }
933
+ } catch (error) {
934
+ process.exitCode = 1;
935
+ const failure = JSON.stringify({ ok: false, error: describeFailure(error) });
936
+ if (!ready) process.stdout.write(`${failure}
937
+ `);
938
+ logger.error("Authority broker supervisor stopped", error, { endpoint, ready });
939
+ } finally {
940
+ process.off("SIGTERM", requestStop);
941
+ process.off("SIGINT", requestStop);
942
+ if (testOwnedBroker()) process.stdin.destroy();
943
+ }
944
+ }
945
+ async function runCliAuthorityBrokerProcess(args) {
946
+ const [endpoint, dbPath, metadataPath, healthPath, supervisor] = args;
947
+ process.stdout.on("error", () => {
948
+ });
949
+ try {
950
+ if (args.length !== 4 && args.length !== 5 || ![dbPath, metadataPath, healthPath].every(isAbsolute)) {
951
+ throw new Error("Expected authority broker endpoint and absolute database, metadata and health paths");
952
+ }
953
+ if (!/^tcp:\/\/127\.0\.0\.1:[0-9]+$/.test(endpoint)) {
954
+ throw new Error("Authority broker must listen on IPv4 loopback");
955
+ }
956
+ const broker = await getOrCreateCliAuthorityBrokerServer({
957
+ endpoint,
958
+ dbPath,
959
+ metadataPath,
960
+ healthPath,
961
+ keepProcessAlive: true,
962
+ tls: await loadCliAuthorityBrokerTls(metadataPath),
963
+ ...supervisor === String(process.ppid) ? { supervisorPid: process.ppid } : {},
964
+ createStore: () => createLevelAuthorityStore(dbPath)
965
+ });
966
+ const close = () => {
967
+ if (testOwnedBroker()) process.stdin.destroy();
968
+ void broker.close().catch((error) => {
969
+ getLogger("cli.authorityBroker").error("Authority broker worker shutdown failed", error);
970
+ process.exit(1);
971
+ });
972
+ };
973
+ process.once("SIGTERM", close);
974
+ process.once("SIGINT", close);
975
+ if (testOwnedBroker()) stopOnParentExit(close);
976
+ process.stdout.write('{"ok":true}\n');
977
+ } catch (error) {
978
+ process.exitCode = 1;
979
+ process.stdout.write(`${JSON.stringify({ ok: false, error: describeFailure(error) })}
980
+ `);
981
+ }
982
+ }
983
+
984
+ export {
985
+ startCliAuthorityBrokerProcess,
986
+ superviseCliAuthorityBrokerProcess,
987
+ runCliAuthorityBrokerProcess
988
+ };