sandforge 1.84.1 → 1.86.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 (277) hide show
  1. package/README.md +1 -1
  2. package/lib/{chunk-S42RBRH2.mjs → chunk-22L43JMK.mjs} +1 -1
  3. package/lib/{chunk-Y2DRK37K.mjs → chunk-2LSGWTWX.mjs} +1 -1
  4. package/lib/{chunk-24RFOFYT.mjs → chunk-2YJJTQNC.mjs} +1 -1
  5. package/lib/chunk-34SMB5PA.mjs +10 -0
  6. package/lib/chunk-35B73566.mjs +7 -0
  7. package/lib/{chunk-3TZSBHEY.mjs → chunk-35IJ4WEU.mjs} +1 -1
  8. package/lib/chunk-3EHPAFKV.mjs +7 -0
  9. package/lib/{chunk-6YL7BNYD.mjs → chunk-3HAVVEXF.mjs} +1 -1
  10. package/lib/{chunk-6JWWSDM6.mjs → chunk-3I6FXFCN.mjs} +1 -1
  11. package/lib/{chunk-WUUKFE2U.mjs → chunk-3KJCSYXY.mjs} +1 -1
  12. package/lib/{chunk-2HVOZUM4.mjs → chunk-3L6DVNCR.mjs} +1 -1
  13. package/lib/chunk-3LRFPGYZ.mjs +7 -0
  14. package/lib/{chunk-GWZRR3MM.mjs → chunk-3MVWGL5A.mjs} +1 -1
  15. package/lib/{chunk-KGU4SVIT.mjs → chunk-4CSBZZAL.mjs} +1 -1
  16. package/lib/{chunk-JE6SCT6R.mjs → chunk-4NSXPONF.mjs} +1 -1
  17. package/lib/{chunk-UIOMAX56.mjs → chunk-4VLP6RHC.mjs} +1 -1
  18. package/lib/{chunk-YA6ATMTB.mjs → chunk-4XROG5CT.mjs} +1 -1
  19. package/lib/chunk-54V4FVEY.mjs +7 -0
  20. package/lib/chunk-55OJJT2Q.mjs +7 -0
  21. package/lib/{chunk-6QE6R6RL.mjs → chunk-5EHHQ5UX.mjs} +1 -1
  22. package/lib/{chunk-FITPY3L4.mjs → chunk-5JMQXHJ2.mjs} +1 -1
  23. package/lib/{chunk-W6PN6TJG.mjs → chunk-65AMXOQU.mjs} +1 -1
  24. package/lib/{chunk-3Q353S2R.mjs → chunk-6HHSAPIM.mjs} +1 -1
  25. package/lib/chunk-6KVBCFVS.mjs +7 -0
  26. package/lib/chunk-6NG7C2U3.mjs +476 -0
  27. package/lib/chunk-6ROL3KBM.mjs +7 -0
  28. package/lib/{chunk-2JDAOWUW.mjs → chunk-72AWCN7U.mjs} +1 -1
  29. package/lib/{chunk-JLSIWO4Z.mjs → chunk-7KHA5UIQ.mjs} +1 -1
  30. package/lib/chunk-7O6EFNQS.mjs +10 -0
  31. package/lib/{chunk-WWTCWWZI.mjs → chunk-A2CH2QGX.mjs} +1 -1
  32. package/lib/chunk-A2TXLAC3.mjs +276 -0
  33. package/lib/chunk-ALWVNR34.mjs +7 -0
  34. package/lib/{chunk-D4GF4FAB.mjs → chunk-ATBQIE2V.mjs} +1 -1
  35. package/lib/{chunk-NED4MBIM.mjs → chunk-ATQML7ZK.mjs} +1 -1
  36. package/lib/chunk-AVY742BJ.mjs +7 -0
  37. package/lib/{chunk-YWEQQL3C.mjs → chunk-AXTB2HJS.mjs} +1 -1
  38. package/lib/chunk-BBZUGKBZ.mjs +10 -0
  39. package/lib/chunk-BIDXK7KA.mjs +7 -0
  40. package/lib/{chunk-O677VOGO.mjs → chunk-BLMJ4WVI.mjs} +1 -1
  41. package/lib/{chunk-RE7RYF3B.mjs → chunk-BNHJCJJM.mjs} +1 -1
  42. package/lib/{chunk-5M5FQ7RP.mjs → chunk-BNPQEQXC.mjs} +1 -1
  43. package/lib/chunk-C5AUNG6T.mjs +37 -0
  44. package/lib/{chunk-ETDCBLGU.mjs → chunk-C5EQ7GFC.mjs} +1 -1
  45. package/lib/{chunk-MJZU3U5O.mjs → chunk-C7CKDZMC.mjs} +61 -61
  46. package/lib/{chunk-HCGXK7G7.mjs → chunk-CB4U22NR.mjs} +1 -1
  47. package/lib/chunk-CJAWKLAL.mjs +7 -0
  48. package/lib/chunk-CL75DEMQ.mjs +9 -0
  49. package/lib/{chunk-VCUXCK36.mjs → chunk-CLUNF4FK.mjs} +1 -1
  50. package/lib/chunk-CSMGP53U.mjs +7 -0
  51. package/lib/{chunk-7YNM6KFZ.mjs → chunk-CT324C7I.mjs} +1 -1
  52. package/lib/{chunk-7UVKIWKV.mjs → chunk-CZXDJXQP.mjs} +1 -1
  53. package/lib/{chunk-43TOMFV4.mjs → chunk-D2X6U3MS.mjs} +1 -1
  54. package/lib/{chunk-M6K34KGF.mjs → chunk-DAUX63UB.mjs} +1 -1
  55. package/lib/chunk-DB7JNALQ.mjs +10 -0
  56. package/lib/chunk-DDNCJVZ2.mjs +17 -0
  57. package/lib/{chunk-FP7CYB2F.mjs → chunk-DLSU66MY.mjs} +1 -1
  58. package/lib/{chunk-JKJ74BX5.mjs → chunk-DO6PSHQZ.mjs} +1 -1
  59. package/lib/{chunk-MDMPJEV3.mjs → chunk-DUBECLZV.mjs} +1 -1
  60. package/lib/{chunk-KZTZDC7H.mjs → chunk-DYHF6DNT.mjs} +1 -1
  61. package/lib/chunk-E5FSPXYH.mjs +930 -0
  62. package/lib/{chunk-Q7GIJBCD.mjs → chunk-EGL3I3IX.mjs} +1 -1
  63. package/lib/chunk-EIYMQPMG.mjs +7 -0
  64. package/lib/{chunk-RHNTHGNU.mjs → chunk-EUIALBMX.mjs} +1 -1
  65. package/lib/{chunk-NCZKWSC7.mjs → chunk-FI3R5ZOQ.mjs} +1 -1
  66. package/lib/{chunk-PAXNWTYK.mjs → chunk-FM4QCTO7.mjs} +1 -1
  67. package/lib/{chunk-HV7VPEXP.mjs → chunk-FRSIEASH.mjs} +1 -1
  68. package/lib/{chunk-QAFPQ3YB.mjs → chunk-FV6MOSHD.mjs} +1 -1
  69. package/lib/chunk-FYG47CNA.mjs +7 -0
  70. package/lib/chunk-GB6W4Q56.mjs +7 -0
  71. package/lib/chunk-GEV2DCMK.mjs +7 -0
  72. package/lib/{chunk-NSQWI7ZY.mjs → chunk-GFB2DNCB.mjs} +1 -1
  73. package/lib/chunk-GFGMGFSH.mjs +7 -0
  74. package/lib/{chunk-RGUQOSBU.mjs → chunk-GIFQXB2Q.mjs} +1 -1
  75. package/lib/{chunk-JAEDM4SI.mjs → chunk-GP5J3DGS.mjs} +1 -1
  76. package/lib/chunk-GQZEX7LH.mjs +231 -0
  77. package/lib/{chunk-JSAJS3MY.mjs → chunk-GYDTM62J.mjs} +1 -1
  78. package/lib/{chunk-OPMO6I45.mjs → chunk-GYFIXUJG.mjs} +1 -1
  79. package/lib/chunk-GZW2GNFK.mjs +7 -0
  80. package/lib/chunk-H6BHWAX7.mjs +8 -0
  81. package/lib/{chunk-EAC5QCE3.mjs → chunk-HDDJ3CVN.mjs} +1 -1
  82. package/lib/{chunk-5SMWFNE7.mjs → chunk-HDWB4ZOG.mjs} +1 -1
  83. package/lib/chunk-HGVPBJR6.mjs +7 -0
  84. package/lib/{chunk-BBRWFKS5.mjs → chunk-HLROVOR6.mjs} +1 -1
  85. package/lib/{chunk-LKTNQEBS.mjs → chunk-HUOR4M2L.mjs} +1 -1
  86. package/lib/chunk-HZCS6EED.mjs +8 -0
  87. package/lib/{chunk-36JOHEJL.mjs → chunk-HZUI56KZ.mjs} +1 -1
  88. package/lib/chunk-IAB5H7WN.mjs +7 -0
  89. package/lib/{chunk-X4BXESMQ.mjs → chunk-IQ5UKRHU.mjs} +1 -1
  90. package/lib/{chunk-54WZUS7J.mjs → chunk-IRQ4WANV.mjs} +1 -1
  91. package/lib/{chunk-5IZTFMJM.mjs → chunk-IT3DGX37.mjs} +1 -1
  92. package/lib/chunk-J347SPU6.mjs +49 -0
  93. package/lib/{chunk-QO53K5W2.mjs → chunk-JANBNTR5.mjs} +1 -1
  94. package/lib/chunk-JFXQZPRY.mjs +9 -0
  95. package/lib/{chunk-KAZS5Z6W.mjs → chunk-JRLYWVF4.mjs} +1 -1
  96. package/lib/{chunk-GKY2JMHY.mjs → chunk-JSNMUTY6.mjs} +1 -1
  97. package/lib/chunk-JTNJKSAA.mjs +7 -0
  98. package/lib/{chunk-7WATA4SB.mjs → chunk-JV2LAKWQ.mjs} +1 -1
  99. package/lib/{chunk-WAPSSYMT.mjs → chunk-JV7K2ZHK.mjs} +1 -1
  100. package/lib/{chunk-ZBAWJUG2.mjs → chunk-K4TQ7YHX.mjs} +1 -1
  101. package/lib/chunk-K5PUMHZU.mjs +7 -0
  102. package/lib/chunk-KH4KLCYG.mjs +7 -0
  103. package/lib/{chunk-OLCVHL7I.mjs → chunk-KQVLZVOP.mjs} +1 -1
  104. package/lib/chunk-KWUS7UAV.mjs +19 -0
  105. package/lib/{chunk-JGZPD4IM.mjs → chunk-L6G73FXM.mjs} +1 -1
  106. package/lib/{chunk-BAWCOKRW.mjs → chunk-LG466Q5H.mjs} +1 -1
  107. package/lib/{chunk-GMIGWR6U.mjs → chunk-LHNAR6FC.mjs} +1 -1
  108. package/lib/chunk-LT4GHEI2.mjs +7 -0
  109. package/lib/{chunk-EC72TIEG.mjs → chunk-MR262Y3B.mjs} +1 -1
  110. package/lib/{chunk-LA4KIATH.mjs → chunk-NCCHOV2N.mjs} +1 -1
  111. package/lib/chunk-NICRSGLS.mjs +7 -0
  112. package/lib/chunk-NV5QA2HY.mjs +7 -0
  113. package/lib/{chunk-PR3XCSPO.mjs → chunk-O3GIN5TU.mjs} +1 -1
  114. package/lib/chunk-O6FHK6NQ.mjs +13 -0
  115. package/lib/{chunk-M4BLK6HJ.mjs → chunk-O7YIEFG7.mjs} +1 -1
  116. package/lib/chunk-OCUVAA5E.mjs +7 -0
  117. package/lib/chunk-OLCS7JCT.mjs +14 -0
  118. package/lib/chunk-ON7Y63FK.mjs +9 -0
  119. package/lib/{chunk-N4WPCWJO.mjs → chunk-OO2WY3UB.mjs} +1 -1
  120. package/lib/{chunk-MSIEU5MR.mjs → chunk-OT2NHL2V.mjs} +1 -1
  121. package/lib/{chunk-6WX5ZU7Q.mjs → chunk-P2M5ZXWU.mjs} +1 -1
  122. package/lib/{chunk-GNRSF65U.mjs → chunk-P4YOHLZ4.mjs} +1 -1
  123. package/lib/chunk-PBHDPTT6.mjs +343 -0
  124. package/lib/chunk-PE7CHD2W.mjs +7 -0
  125. package/lib/{chunk-PBY2O6OF.mjs → chunk-PIQ2I67B.mjs} +1 -1
  126. package/lib/chunk-PKYDNZJK.mjs +7 -0
  127. package/lib/chunk-PVZ72OOQ.mjs +7 -0
  128. package/lib/chunk-QACFTHJM.mjs +8 -0
  129. package/lib/{chunk-J3DND3BC.mjs → chunk-QGVL5EW3.mjs} +1 -1
  130. package/lib/chunk-QHE2RUWX.mjs +7 -0
  131. package/lib/{chunk-QKEKG2LD.mjs → chunk-RCW5BZNW.mjs} +1 -1
  132. package/lib/{chunk-4JE4BYXK.mjs → chunk-RJ6HHG7J.mjs} +1 -1
  133. package/lib/{chunk-ZQWIVYVM.mjs → chunk-RPTEEI4R.mjs} +1 -1
  134. package/lib/chunk-RQW5S67A.mjs +7 -0
  135. package/lib/chunk-RTCMYMED.mjs +7 -0
  136. package/lib/chunk-RWVX7XSD.mjs +7 -0
  137. package/lib/{chunk-WY5V5PR3.mjs → chunk-RZOINFNL.mjs} +1 -1
  138. package/lib/chunk-SOOTWGMQ.mjs +7 -0
  139. package/lib/chunk-STQ2JMIZ.mjs +7 -0
  140. package/lib/{chunk-6PD6K7LP.mjs → chunk-SUIPDW5O.mjs} +1 -1
  141. package/lib/{chunk-TNT27RBG.mjs → chunk-SZOJ7BEJ.mjs} +1 -1
  142. package/lib/{chunk-4EOHEDFP.mjs → chunk-T542Z54E.mjs} +1 -1
  143. package/lib/chunk-TAN2CIRI.mjs +21 -0
  144. package/lib/{chunk-A3MYSOOC.mjs → chunk-TCNBINOG.mjs} +1 -1
  145. package/lib/chunk-TFDF3DBN.mjs +7 -0
  146. package/lib/chunk-TICZXC53.mjs +9 -0
  147. package/lib/chunk-TLX45X5U.mjs +7 -0
  148. package/lib/{chunk-QTG6LUZT.mjs → chunk-TMIV3IWH.mjs} +1 -1
  149. package/lib/chunk-TQ6HEJ73.mjs +11 -0
  150. package/lib/chunk-TTU5EQZ6.mjs +7 -0
  151. package/lib/chunk-TYUYPFDJ.mjs +7 -0
  152. package/lib/chunk-TZXYVMZC.mjs +7 -0
  153. package/lib/chunk-UCUFLFNK.mjs +7 -0
  154. package/lib/chunk-UK3QLBHW.mjs +7 -0
  155. package/lib/{chunk-IZGCEOYO.mjs → chunk-UM2B4GR7.mjs} +1 -1
  156. package/lib/chunk-UZFTTNOP.mjs +7 -0
  157. package/lib/chunk-V3AXSKSU.mjs +7 -0
  158. package/lib/chunk-VA6EEI6X.mjs +21 -0
  159. package/lib/{chunk-OFTT7J2M.mjs → chunk-VFKG2G37.mjs} +1 -1
  160. package/lib/chunk-VJNEW5MQ.mjs +7 -0
  161. package/lib/{chunk-L53JWJ3S.mjs → chunk-VKREON6Q.mjs} +1 -1
  162. package/lib/{chunk-NOBQTEQD.mjs → chunk-VNNDYPBL.mjs} +1 -1
  163. package/lib/{chunk-ZJW6YOMV.mjs → chunk-VRBETPHY.mjs} +1 -1
  164. package/lib/{chunk-EPFCERGL.mjs → chunk-VT6P3X6R.mjs} +1 -1
  165. package/lib/{chunk-ZV7ZFQQC.mjs → chunk-VUTQY76O.mjs} +1 -1
  166. package/lib/chunk-WF5S4FW5.mjs +7 -0
  167. package/lib/{chunk-Z4LKKOFY.mjs → chunk-WJGK6VGU.mjs} +1 -1
  168. package/lib/{chunk-5CRLRHOJ.mjs → chunk-WJHMB3SL.mjs} +1 -1
  169. package/lib/{chunk-OUZQPYT3.mjs → chunk-WQCXOZEJ.mjs} +1 -1
  170. package/lib/{chunk-L2E5WBGD.mjs → chunk-WVVFR4E3.mjs} +1 -1
  171. package/lib/{chunk-PWRJRL5U.mjs → chunk-XBYXT74L.mjs} +1 -1
  172. package/lib/chunk-XJE3LJHP.mjs +7 -0
  173. package/lib/{chunk-CPQIZGG5.mjs → chunk-XV4CVZYD.mjs} +1 -1
  174. package/lib/chunk-Y37ED7AS.mjs +7 -0
  175. package/lib/{chunk-YTLUYSMF.mjs → chunk-YGBNZYT4.mjs} +1 -1
  176. package/lib/{chunk-4CVUUVGJ.mjs → chunk-YGTOX7IL.mjs} +1 -1
  177. package/lib/{chunk-OMNMLKDT.mjs → chunk-YJ27WHKR.mjs} +1 -1
  178. package/lib/chunk-YRULC27A.mjs +7 -0
  179. package/lib/{chunk-RMFU4BAL.mjs → chunk-YSVAHT4Q.mjs} +4 -4
  180. package/lib/chunk-YTOTMJTY.mjs +15 -0
  181. package/lib/{chunk-B63POIPQ.mjs → chunk-YZKZC62O.mjs} +1 -1
  182. package/lib/{chunk-DPMRIMUC.mjs → chunk-YZQN7BRB.mjs} +1 -1
  183. package/lib/{chunk-7SQSWVAU.mjs → chunk-Z5IUK2QO.mjs} +1 -1
  184. package/lib/{chunk-M2ABR4JM.mjs → chunk-ZEGSMW5A.mjs} +1 -1
  185. package/lib/{chunk-PR42EZSR.mjs → chunk-ZIKLQZBG.mjs} +1 -1
  186. package/lib/chunk-ZVU7MD2S.mjs +7 -0
  187. package/lib/sandforge-autopilot.mjs +33 -27
  188. package/lib/sandforge-backup.mjs +19 -19
  189. package/lib/sandforge-checkpoint.mjs +1 -1
  190. package/lib/sandforge-cleanup.mjs +1 -1
  191. package/lib/sandforge-clone.mjs +1 -1
  192. package/lib/sandforge-compare.mjs +32 -14
  193. package/lib/sandforge-dataops.mjs +1 -1
  194. package/lib/sandforge-empty.mjs +11 -13
  195. package/lib/sandforge-env.mjs +105 -105
  196. package/lib/sandforge-frozen.mjs +1 -1
  197. package/lib/sandforge-mcp.mjs +2 -2
  198. package/lib/sandforge-monitor.mjs +1 -1
  199. package/lib/sandforge-pipeline.mjs +13 -13
  200. package/lib/sandforge-seed.mjs +1 -1
  201. package/lib/sandforge-sync.mjs +1 -1
  202. package/lib/sandforge-users.mjs +13 -15
  203. package/lib/sandforge.mjs +1 -1
  204. package/lib/sf/sandforge/dataops.mjs +2 -2
  205. package/lib/sfPlugin.mjs +1 -1
  206. package/oclif.manifest.json +1 -1
  207. package/package.json +1 -1
  208. package/lib/chunk-23SEDORH.mjs +0 -11
  209. package/lib/chunk-26POJDIT.mjs +0 -7
  210. package/lib/chunk-2AZQHBEF.mjs +0 -7
  211. package/lib/chunk-2METQHGG.mjs +0 -7
  212. package/lib/chunk-2WFIVO4F.mjs +0 -13
  213. package/lib/chunk-2YHZBUZE.mjs +0 -7
  214. package/lib/chunk-326AJTIU.mjs +0 -272
  215. package/lib/chunk-3PVRGTVK.mjs +0 -7
  216. package/lib/chunk-5XTUSN72.mjs +0 -8
  217. package/lib/chunk-6I6TWNV5.mjs +0 -7
  218. package/lib/chunk-6O222PW6.mjs +0 -7
  219. package/lib/chunk-6ZLKIT3H.mjs +0 -7
  220. package/lib/chunk-7QYHEHMA.mjs +0 -9
  221. package/lib/chunk-B3FBHVNN.mjs +0 -21
  222. package/lib/chunk-BEA27DLS.mjs +0 -7
  223. package/lib/chunk-BRY3PLIZ.mjs +0 -7
  224. package/lib/chunk-CBH3TOWK.mjs +0 -341
  225. package/lib/chunk-CVHNXJH3.mjs +0 -7
  226. package/lib/chunk-DGDRQRCW.mjs +0 -7
  227. package/lib/chunk-DUN2EPRC.mjs +0 -7
  228. package/lib/chunk-E3A3LOCY.mjs +0 -7
  229. package/lib/chunk-F2424IKX.mjs +0 -7
  230. package/lib/chunk-F3AQW6IU.mjs +0 -7
  231. package/lib/chunk-FNJ4SGWO.mjs +0 -7
  232. package/lib/chunk-GOOVPVWX.mjs +0 -7
  233. package/lib/chunk-H2BHESDA.mjs +0 -9
  234. package/lib/chunk-H4CGM6YO.mjs +0 -7
  235. package/lib/chunk-HIDW7FNV.mjs +0 -9
  236. package/lib/chunk-HSBXRQTI.mjs +0 -7
  237. package/lib/chunk-HUZPBE47.mjs +0 -7
  238. package/lib/chunk-I6E6T6YY.mjs +0 -7
  239. package/lib/chunk-IUM4NFKI.mjs +0 -10
  240. package/lib/chunk-IVFVNNGB.mjs +0 -37
  241. package/lib/chunk-JCFBFF4Y.mjs +0 -7
  242. package/lib/chunk-JTJK2D36.mjs +0 -7
  243. package/lib/chunk-KB4ZHM4Q.mjs +0 -10
  244. package/lib/chunk-KJWFYBMU.mjs +0 -15
  245. package/lib/chunk-LC3NDW4N.mjs +0 -7
  246. package/lib/chunk-OM5NORJG.mjs +0 -7
  247. package/lib/chunk-OVNMB6Q2.mjs +0 -7
  248. package/lib/chunk-PEDQPM2P.mjs +0 -926
  249. package/lib/chunk-PH7SP4YK.mjs +0 -21
  250. package/lib/chunk-PMN4PAC3.mjs +0 -19
  251. package/lib/chunk-PMWAFDUB.mjs +0 -48
  252. package/lib/chunk-PPLVFX6N.mjs +0 -7
  253. package/lib/chunk-PZBZ7MNC.mjs +0 -7
  254. package/lib/chunk-QROPNEGY.mjs +0 -14
  255. package/lib/chunk-RGBGUCJA.mjs +0 -156
  256. package/lib/chunk-RKTFFCNS.mjs +0 -7
  257. package/lib/chunk-ROV3QXEF.mjs +0 -475
  258. package/lib/chunk-RT47RKLY.mjs +0 -7
  259. package/lib/chunk-SI267LYR.mjs +0 -8
  260. package/lib/chunk-SRPWW4A2.mjs +0 -10
  261. package/lib/chunk-T3G6VZNS.mjs +0 -7
  262. package/lib/chunk-T63U4OZJ.mjs +0 -7
  263. package/lib/chunk-TEIBWMJM.mjs +0 -7
  264. package/lib/chunk-TW3N6W5Z.mjs +0 -7
  265. package/lib/chunk-UBIKR5VO.mjs +0 -7
  266. package/lib/chunk-UI3JQVRU.mjs +0 -8
  267. package/lib/chunk-UX3BVH2Y.mjs +0 -7
  268. package/lib/chunk-VINGECAJ.mjs +0 -10
  269. package/lib/chunk-VOXJHJIE.mjs +0 -7
  270. package/lib/chunk-WB2RIVO3.mjs +0 -7
  271. package/lib/chunk-WXDLQT2O.mjs +0 -10
  272. package/lib/chunk-XBQGZGWR.mjs +0 -7
  273. package/lib/chunk-XGGOUNPP.mjs +0 -7
  274. package/lib/chunk-XKWW3GKF.mjs +0 -7
  275. package/lib/chunk-YHR4WQPR.mjs +0 -7
  276. package/lib/chunk-ZQQXSCVI.mjs +0 -7
  277. package/lib/chunk-ZRUDYB7O.mjs +0 -7
@@ -4,13 +4,13 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{c as ls,e as fs,g as ps,h as Ze}from"./chunk-QKEKG2LD.mjs";import{c as bs,d as ys,i as Rs}from"./chunk-KZTZDC7H.mjs";import{b as Ss,c as ks}from"./chunk-OLCVHL7I.mjs";import{g as ws}from"./chunk-DPMRIMUC.mjs";import{d as hs,g as He,i as ms,j as gs}from"./chunk-SI267LYR.mjs";import{a as Jr}from"./chunk-6YL7BNYD.mjs";import{a as Vr}from"./chunk-7UVKIWKV.mjs";import{a as Zr}from"./chunk-ZJW6YOMV.mjs";import{a as Je,b as Ft}from"./chunk-RE7RYF3B.mjs";import{a as _t,b as Qr}from"./chunk-54WZUS7J.mjs";import{f as Ve}from"./chunk-H4OBZIX3.mjs";import{b as us}from"./chunk-KAZS5Z6W.mjs";import{a as Wr}from"./chunk-PBY2O6OF.mjs";import{a as qr}from"./chunk-PAXNWTYK.mjs";import{H as Ur,J as Pt,K as Br,O as Nt,P as zr,Q as Kr}from"./chunk-CBH3TOWK.mjs";import{a as vr,b as Hr,d as Xr,e as Yr,f as ts,g as ns,h as rs,j as ss,k as os,l as Dt,m as Lt,p as as,q as is,r as ds,s as cs}from"./chunk-JSAJS3MY.mjs";import{d as es}from"./chunk-FITPY3L4.mjs";import{a as Gr}from"./chunk-BBRWFKS5.mjs";import{f as $r}from"./chunk-FQGHL7GR.mjs";import{I as Nr,J as Fr,L as _r,Q as Dr,R as Lr,S as Mr,T as xt,U as Ct,a as kr,c as Ar,j as jr,k as Or,u as Ir}from"./chunk-6I6TWNV5.mjs";import{a as Tr,c as Er}from"./chunk-JKJ74BX5.mjs";import{d as xr,e as Cr,f as Pr}from"./chunk-PR42EZSR.mjs";import{c as gn}from"./chunk-7SQSWVAU.mjs";import{Ab as wr,Bb as br,Cb as Ge,Db as yr,Eb as Rr,Fb as Sr,Xa as Ae,b as W,d as It,db as ur,e as er,eb as Tt,f as tr,g as nr,h as rr,i as sr,k as We,l as or,mb as lr,n as ar,o as ir,p as dr,qb as fr,rb as je,sb as pr,tb as Et,ub as hr,yb as mr,zb as gr}from"./chunk-PEDQPM2P.mjs";import{b as Ot,c as Qn,d as Yn}from"./chunk-EPFCERGL.mjs";import{a as ee,d as qn,j as qe,k as Wn}from"./chunk-2METQHGG.mjs";import{b as Ue,e as Be}from"./chunk-RKTFFCNS.mjs";import{a as pt,b as bn,c as Re,d as Y,e as yn,f as Rn,g as ht,h as Sn,j as kn}from"./chunk-6FARZYMJ.mjs";import{_ as $n,yc as Tn,zc as En}from"./chunk-XGGOUNPP.mjs";import{Ia as Gn,Xa as jt,Ya as Jn,eb as Vn,f as zn,g as Kn}from"./chunk-IVFVNNGB.mjs";import{b as An}from"./chunk-VINGECAJ.mjs";import{B as bt,M as Se,P as yt,a as vn}from"./chunk-H4CGM6YO.mjs";import{a as Zn,b as Hn,c as Xn}from"./chunk-IUM4NFKI.mjs";import{h as On,l as In,n as ze,p as Ke}from"./chunk-PMN4PAC3.mjs";import{a as De}from"./chunk-AL4C3GFT.mjs";import{b as ye,c as le}from"./chunk-OUZQPYT3.mjs";import{b as xn,c as Cn,g as Pn}from"./chunk-LC3NDW4N.mjs";import{Dc as vt,Sc as $t,Tc as At,Zb as Mn,eb as kt,i as Rt,j as ke,lc as Un,mb as Dn,o as Nn,p as Fn,pb as ve,pc as Bn,q as St,s as fe,tb as Ln,wc as $e}from"./chunk-KB4ZHM4Q.mjs";import{h as mt,j as gt}from"./chunk-23SEDORH.mjs";import{a as be,b as mn,f as lt}from"./chunk-W6PN6TJG.mjs";import{q as _n}from"./chunk-3Q353S2R.mjs";import{b as Me,d as wn,f as ft,h as cr}from"./chunk-LCDPCUXS.mjs";import{b as wt}from"./chunk-HFSBDM7B.mjs";import{q as ce}from"./chunk-TNT27RBG.mjs";import{d as jn}from"./chunk-TUACWKIH.mjs";import{Ea as at,Rb as it,Wd as ct,Xd as pn,Yd as hn,Zd as ut,bc as Le,cc as dt,e as ue,fc as cn,gc as un,h as dn,id as ln,td as fn}from"./chunk-PMWAFDUB.mjs";import{A as P}from"./chunk-WZQEK4WT.mjs";import{randomInt as ao,randomUUID as io}from"node:crypto";import{existsSync as qt,readFileSync as Ie,renameSync as co,writeFileSync as uo}from"node:fs";import{dirname as lo,join as fo}from"node:path";import{existsSync as $s,readFileSync as As}from"node:fs";import{dirname as vs,resolve as Mt}from"node:path";function Ut(t,n=e=>As(e,"utf8")){let e=dt.find(i=>i.id===t);if(e)return{pack:e,from:"built-in"};if(!$s(t))return{refusal:`--scenario takes the id of a scenario SandForge ships (${dt.map(i=>i.id).join(", ")}) or a scenario file, not "${t}".`};let r;try{r=n(t)}catch(i){return{refusal:`${t} could not be read: ${i instanceof Error?i.message:String(i)}`}}let o=ys(r);return"issues"in o?{refusal:`${t} is not a scenario pack:
7
+ import{c as Is,e as Ts,g as Es,h as xe}from"./chunk-RCW5BZNW.mjs";import{c as Ns,d as _s,i as Ds}from"./chunk-DYHF6DNT.mjs";import{b as Ls,c as Ms}from"./chunk-KQVLZVOP.mjs";import{g as Fs}from"./chunk-YZQN7BRB.mjs";import{d as xs,g as tt,i as Cs,j as Ps}from"./chunk-QACFTHJM.mjs";import{a as us}from"./chunk-3HAVVEXF.mjs";import{a as ls}from"./chunk-CZXDJXQP.mjs";import{a as fs}from"./chunk-VRBETPHY.mjs";import{a as Ye,b as Bt}from"./chunk-BNHJCJJM.mjs";import{a as zt,b as ms}from"./chunk-IRQ4WANV.mjs";import{f as et}from"./chunk-H4OBZIX3.mjs";import{b as Os}from"./chunk-JRLYWVF4.mjs";import{a as ds}from"./chunk-PIQ2I67B.mjs";import{a as is}from"./chunk-FM4QCTO7.mjs";import{J as rs,L as Mt,M as ss,Q as Ut,R as os,S as as}from"./chunk-PBHDPTT6.mjs";import{a as Mr,b as ps,d as hs,e as gs,f as bs,g as ys,h as Rs,j as Ss,k as ks,l as Kt,m as Wt,p as vs,q as $s,r as As,s as js}from"./chunk-GYDTM62J.mjs";import{d as ws}from"./chunk-5JMQXHJ2.mjs";import{a as cs}from"./chunk-HLROVOR6.mjs";import{M as Qr,N as Xr,P as Yr,U as es,V as ts,W as ns,X as Dt,Y as Lt,a as Lr,c as Ur,j as Nt,k as _t,l as Br,m as zr,n as Kr,o as Wr,y as qr}from"./chunk-WF5S4FW5.mjs";import{a as Gr,c as Jr}from"./chunk-DO6PSHQZ.mjs";import{d as Vr,e as Zr,f as Hr}from"./chunk-ZIKLQZBG.mjs";import{c as $n}from"./chunk-Z5IUK2QO.mjs";import{Ab as xr,Bb as Cr,Cb as Pr,Db as Fr,Eb as Xe,Fb as Nr,Gb as _r,Hb as Dr,Za as Te,b as Z,d as Ct,e as gr,f as wr,fb as jr,g as br,gb as Pt,h as yr,i as Rr,k as Qe,l as Sr,n as kr,o as vr,ob as Or,p as $r,sb as Ir,tb as Ee,ub as Tr,vb as Ft,wb as Er}from"./chunk-E5FSPXYH.mjs";import{b as xt,c as hr,d as mr}from"./chunk-VT6P3X6R.mjs";import{k as Zn,n as Hn}from"./chunk-ALWVNR34.mjs";import{a as te,d as ar,j as He,k as ir}from"./chunk-QHE2RUWX.mjs";import{a as yt,b as jn,c as Ae,d as ee,e as On,f as In,g as Rt,h as Tn,j as En}from"./chunk-6FARZYMJ.mjs";import{$ as Fn,Mc as Mn,Nc as Un}from"./chunk-CJAWKLAL.mjs";import{f as We,k as qe}from"./chunk-DDNCJVZ2.mjs";import{Ma as dr,Za as Et,_a as cr,f as sr,g as or,gb as ur}from"./chunk-C5AUNG6T.mjs";import{f as Nn}from"./chunk-7O6EFNQS.mjs";import{B as vt,M as he,a as xn}from"./chunk-3LRFPGYZ.mjs";import{a as lr,b as fr,c as pr}from"./chunk-34SMB5PA.mjs";import{h as Dn,l as Ln,n as Ve,p as Ze}from"./chunk-KWUS7UAV.mjs";import{s as Jn,t as Vn}from"./chunk-35B73566.mjs";import{f as Gn}from"./chunk-FQGHL7GR.mjs";import{a as Be,c as ke}from"./chunk-AL4C3GFT.mjs";import{b as $e,c as pe}from"./chunk-WQCXOZEJ.mjs";import{b as Bn,c as zn,g as Kn}from"./chunk-ZVU7MD2S.mjs";import{Cc as Ie,Jc as Ot,Yc as It,Zc as Tt,dc as tr,j as $t,k as je,kb as jt,q as Wn,r as qn,rc as nr,s as At,sb as Yn,vb as Oe,vc as rr,x as me,xa as Qn,zb as er}from"./chunk-OLCS7JCT.mjs";import{i as Ge,j as Pn,l as Je}from"./chunk-TQ6HEJ73.mjs";import{a as ve,b as vn,f as wt}from"./chunk-65AMXOQU.mjs";import{q as Xn}from"./chunk-6HHSAPIM.mjs";import{b as St,f as Cn}from"./chunk-K5PUMHZU.mjs";import{b as Ke,d as An,f as bt,h as Ar}from"./chunk-LCDPCUXS.mjs";import{b as kt}from"./chunk-HFSBDM7B.mjs";import{q as ue}from"./chunk-SZOJ7BEJ.mjs";import{d as _n}from"./chunk-TUACWKIH.mjs";import{Dd as Rn,Ha as ft,Ub as pt,e as fe,h as gn,ic as ze,jc as ht,je as mt,ke as Sn,le as kn,mc as wn,me as gt,nc as bn,qd as yn}from"./chunk-J347SPU6.mjs";import{A as N}from"./chunk-WZQEK4WT.mjs";import{randomInt as vo,randomUUID as $o}from"node:crypto";import{existsSync as Ht,readFileSync as Pe,renameSync as Ao,writeFileSync as jo}from"node:fs";import{dirname as Oo,join as Io}from"node:path";import{existsSync as Bs,readFileSync as zs}from"node:fs";import{dirname as Us,resolve as qt}from"node:path";function Gt(t,n=e=>zs(e,"utf8")){let e=ht.find(i=>i.id===t);if(e)return{pack:e,from:"built-in"};if(!Bs(t))return{refusal:`--scenario takes the id of a scenario SandForge ships (${ht.map(i=>i.id).join(", ")}) or a scenario file, not "${t}".`};let r;try{r=n(t)}catch(i){return{refusal:`${t} could not be read: ${i instanceof Error?i.message:String(i)}`}}let o=_s(r);return"issues"in o?{refusal:`${t} is not a scenario pack:
8
8
  ${o.issues.map(i=>` ${i}`).join(`
9
- `)}`}:{pack:o.pack,from:Mt(t)}}async function js(t,n,e){let r=ps(n,{caseStatus:await ls(t.query),knowledge:await fs(t.objectAccess,t.describe),...e!==void 0?{seed:e}:{}});if("issues"in r)return r;let{options:o}=r.preparation;return{...r,compiled:us(n,o),options:o}}function Os(t,n){let{options:e,knowledge:r,caseStatusFrom:o}=n;return[`scenario: ${t.id} (${t.name}), seed ${e.seed} (--scenario-seed ${e.seed} writes the same again)`,...n.objects.map(i=>` ${i.objectApiName}: ${i.recordCount} record(s)`+(i.optional?", skipped by an org without it":"")),` cases: open "${e.caseStatus.open}", closed "${e.caseStatus.closed}"`+(o.from==="org"?" (the org's)":` (a new org's: ${o.reason})`),r.available?" articles: published once written, each closed case linked to the article of its topic, "+(e.articleBodyField?`their body in ${e.articleBodyField}`+(e.articleBodyLength!==void 0?` (${e.articleBodyLength} characters, every fact kept)`:""):"with their summary alone: the org offers no field for a body"):` articles: skipped, ${r.reason}: the tests that answer from Knowledge are written, and the agent will have no article to cite`,` tests: ${n.tests}, written to a file once the run has ended (--test-file)`]}function Is(t){if(!t)return[];if(t.skipped!==void 0)return[`articles: ${t.skipped}`];let n=(e,r)=>r?[`${e}: ${r.done} of ${r.asked}`,...r.notDone.map(({key:o,reason:i})=>` ${o}: ${i}`)]:[];return[...n("articles published",t.publish),...n("closed cases linked to their article",t.links)]}async function Ts(t){let n=new Set(t.compiled.tests.flatMap(o=>o.openCase?[o.openCase.caseKey]:[])),e=Object.keys(t.caseIds).filter(o=>n.has(o)).length,r={packId:t.pack.id,tests:t.compiled.tests.length,openCases:n.size,openCasesWritten:e};if(e===0)return r;try{let o=await ms(He(),t.journalDir,hs({runId:t.runId,pack:t.pack,compiled:t.compiled,options:t.options,caseIds:t.caseIds}));return{...r,companion:o}}catch(o){return{...r,unkept:o instanceof Error?o.message:String(o)}}}function Bt(t,n,e){return[`${De("seed")} --test-file`,t,"--target",n,"--agent <agent API name>",...e.topics.map(r=>`--topic ${r.key}=<agent topic>`)].join(" ")}function eo(t){return t.flatMap(n=>[` ${n.name}${n.label?` (${n.label})`:""}`,...n.topics.map(e=>` topic ${e.name}`+(e.actions.length>0?`: ${e.actions.map(r=>r.name).join(", ")}`:""))])}var to={switches:["--overwrite","--json"],values:["--test-file","--target","--agent","--topic","--guard-topic","--test-runner","--scenario","--project"]},no=/^([a-z][a-z0-9-]*)=([^\s:=,]+)(?::([^\s:=]+))?$/;function ro(t){let n=t.slice(2);Me(n,to);let e=c=>{process.stderr.write(`${c}
10
- `),process.exit(2)},r=c=>{let b=n.indexOf(c);return b>=0&&b+1<n.length?n[b+1]:void 0},o=r("--test-file"),i=r("--target");(!o||!i)&&e("--test-file takes the file of a scenario run, or its run id, and --target the org it wrote to. Run with --help.");let s=[];for(let c=0;c<n.length;c++){if(n[c]!=="--topic")continue;let b=n[c+1]??"",w=no.exec(b);w||e(`--topic wants "<scenario topic>=<agent topic>" or "<scenario topic>=<agent topic>:<action>,<action>", not "${b}".`);let[,g,S,y]=w;s.push({packTopic:g,agentTopic:S,actions:y?y.split(","):[]})}let d=r("--test-runner")??"testing-center";it.includes(d)||e(`--test-runner takes ${it.join(" or ")}, not "${d}".`);let l=r("--agent"),f=r("--scenario");return{run:o,target:i,...l!==void 0?{agent:l}:{},topics:s,guardTopic:r("--guard-topic")??null,runner:d,...f!==void 0?{scenario:f}:{},project:Mt(r("--project")??process.cwd()),overwrite:n.includes("--overwrite"),json:n.includes("--json")}}function so(t,n){if($s(t)&&t.endsWith(".ndjson")){let e=ze(As(t,"utf8"));if(e)return{runId:e.runId,storagePath:vs(vs(Mt(t))),targetOrgId:e.targetOrgId,...e.targetOrganizationId?{targetOrganizationId:e.targetOrganizationId}:{}}}return{runId:t,storagePath:n}}async function Es(t,n,e){let r=ro(t),o=y=>{process[r.json?"stderr":"stdout"].write(`${y}
11
- `)},i=(y,x)=>{process.stderr.write(`${x}
12
- `),process.exitCode=y},s=so(r.run,e),d=await gs(He(),s.storagePath,s.runId);if(d.kind!=="read"){i(2,d.kind==="absent"?`${r.run}: no scenario run kept a companion file by that name, so there is no test file to write from it.`:d.message);return}let{sidecar:l}=d,f;if(r.scenario!==void 0){let y=Ut(r.scenario);if("refusal"in y){i(2,y.refusal);return}f=y.pack}let c=f??await Rs(bs(),[r.project],l.packId,l.packFingerprint),b=await n(r.target);if(s.targetOrganizationId!==void 0){let y=await b.organizationId();if(y!==void 0&&y.slice(0,15)!==s.targetOrganizationId.slice(0,15)){i(2,`${r.target} is not the org this run wrote to: give --target that org.`);return}}let w=await Ve(Ze(b.tooling));if(w.kind==="no-agent"){i(1,w.message);return}if(w.kind==="unreadable"){i(1,w.message);return}if(r.agent===void 0){o(`the agents of ${r.target}:`);for(let y of eo(w.catalog.agents))o(y);i(2,`--test-file takes --agent, the API name of the agent the tests are for, and a --topic for each topic of the scenario ${l.packId}`+(c?` (${c.topics.map(y=>y.key).join(", ")})`:"")+". Run with --help.");return}let g={agent:r.agent,runner:r.runner,topics:r.topics,guardTopic:r.guardTopic},S=await ks({sidecar:He(),spec:ws()},{runId:s.runId,storagePath:s.storagePath,project:await Ss([r.project]),alias:r.target,choice:g,overwrite:r.overwrite,readCatalog:async()=>w,findPack:async()=>c});r.json&&process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",outcome:S},null,2)}
13
- `);for(let y of oo(S))o(y);S.kind!=="written"&&(process.exitCode=S.kind==="no-agent"?1:2)}function oo(t){switch(t.kind){case"written":return[`test file: ${t.path}`,...t.leftOut.map(n=>` left out ${n.test}: ${n.message}`),...t.commands?["SandForge never deploys the test nor runs it, which spends the org's credits: from the project, run",` ${t.commands.create}`,` ${t.commands.run}`]:["This folder is no Salesforce DX project (no sfdx-project.json): sf agent test create runs from one, which it writes the test it creates into."]];case"exists":return[`${t.path} is there already: --overwrite writes over it.`];case"refused":return t.refusals.map(n=>`refused: ${n.message}`);case"no-agent":case"unavailable":return[t.message]}}var Wt=Object.keys($r),po=`sandforge seed \u2014 fill an org from a seed template, without the editor.
9
+ `)}`}:{pack:o.pack,from:qt(t)}}async function Ks(t,n,e){let r=Es(n,{caseStatus:await Is(t.query),knowledge:await Ts(t.objectAccess,t.describe),...e!==void 0?{seed:e}:{}});if("issues"in r)return r;let{options:o}=r.preparation;return{...r,compiled:Os(n,o),options:o}}function Ws(t,n){let{options:e,knowledge:r,caseStatusFrom:o}=n;return[`scenario: ${t.id} (${t.name}), seed ${e.seed} (--scenario-seed ${e.seed} writes the same again)`,...n.objects.map(i=>` ${i.objectApiName}: ${i.recordCount} record(s)`+(i.optional?", skipped by an org without it":"")),` cases: open "${e.caseStatus.open}", closed "${e.caseStatus.closed}"`+(o.from==="org"?" (the org's)":` (a new org's: ${o.reason})`),r.available?" articles: published once written, each closed case linked to the article of its topic, "+(e.articleBodyField?`their body in ${e.articleBodyField}`+(e.articleBodyLength!==void 0?` (${e.articleBodyLength} characters, every fact kept)`:""):"with their summary alone: the org offers no field for a body"):` articles: skipped, ${r.reason}: the tests that answer from Knowledge are written, and the agent will have no article to cite`,` tests: ${n.tests}, written to a file once the run has ended (--test-file)`]}function qs(t){if(!t)return[];if(t.skipped!==void 0)return[`articles: ${t.skipped}`];let n=(e,r)=>r?[`${e}: ${r.done} of ${r.asked}`,...r.notDone.map(({key:o,reason:i})=>` ${o}: ${i}`)]:[];return[...n("articles published",t.publish),...n("closed cases linked to their article",t.links)]}async function Gs(t){let n=new Set(t.compiled.tests.flatMap(o=>o.openCase?[o.openCase.caseKey]:[])),e=Object.keys(t.caseIds).filter(o=>n.has(o)).length,r={packId:t.pack.id,tests:t.compiled.tests.length,openCases:n.size,openCasesWritten:e};if(e===0)return r;try{let o=await Cs(tt(),t.journalDir,xs({runId:t.runId,pack:t.pack,compiled:t.compiled,options:t.options,caseIds:t.caseIds}));return{...r,companion:o}}catch(o){return{...r,unkept:o instanceof Error?o.message:String(o)}}}function Jt(t,n,e){return[`${Be("seed")} --test-file`,t,"--target",n,"--agent <agent API name>",...e.topics.map(r=>`--topic ${r.key}=<agent topic>`)].join(" ")}function wo(t){return t.flatMap(n=>[` ${n.name}${n.label?` (${n.label})`:""}`,...n.topics.map(e=>` topic ${e.name}`+(e.actions.length>0?`: ${e.actions.map(r=>r.name).join(", ")}`:""))])}var bo={switches:["--overwrite","--json"],values:["--test-file","--target","--agent","--topic","--guard-topic","--test-runner","--scenario","--project"]},yo=/^([a-z][a-z0-9-]*)=([^\s:=,]+)(?::([^\s:=]+))?$/;function Ro(t){let n=t.slice(2);Ke(n,bo);let e=c=>{process.stderr.write(`${c}
10
+ `),process.exit(2)},r=c=>{let w=n.indexOf(c);return w>=0&&w+1<n.length?n[w+1]:void 0},o=r("--test-file"),i=r("--target");(!o||!i)&&e("--test-file takes the file of a scenario run, or its run id, and --target the org it wrote to. Run with --help.");let s=[];for(let c=0;c<n.length;c++){if(n[c]!=="--topic")continue;let w=n[c+1]??"",b=yo.exec(w);b||e(`--topic wants "<scenario topic>=<agent topic>" or "<scenario topic>=<agent topic>:<action>,<action>", not "${w}".`);let[,g,S,y]=b;s.push({packTopic:g,agentTopic:S,actions:y?y.split(","):[]})}let d=r("--test-runner")??"testing-center";pt.includes(d)||e(`--test-runner takes ${pt.join(" or ")}, not "${d}".`);let l=r("--agent"),f=r("--scenario");return{run:o,target:i,...l!==void 0?{agent:l}:{},topics:s,guardTopic:r("--guard-topic")??null,runner:d,...f!==void 0?{scenario:f}:{},project:qt(r("--project")??process.cwd()),overwrite:n.includes("--overwrite"),json:n.includes("--json")}}function So(t,n){if(Bs(t)&&t.endsWith(".ndjson")){let e=Ve(zs(t,"utf8"));if(e)return{runId:e.runId,storagePath:Us(Us(qt(t))),targetOrgId:e.targetOrgId,...e.targetOrganizationId?{targetOrganizationId:e.targetOrganizationId}:{}}}return{runId:t,storagePath:n}}async function Js(t,n,e){let r=Ro(t),o=y=>{process[r.json?"stderr":"stdout"].write(`${y}
11
+ `)},i=(y,P)=>{process.stderr.write(`${P}
12
+ `),process.exitCode=y},s=So(r.run,e),d=await Ps(tt(),s.storagePath,s.runId);if(d.kind!=="read"){i(2,d.kind==="absent"?`${r.run}: no scenario run kept a companion file by that name, so there is no test file to write from it.`:d.message);return}let{sidecar:l}=d,f;if(r.scenario!==void 0){let y=Gt(r.scenario);if("refusal"in y){i(2,y.refusal);return}f=y.pack}let c=f??await Ds(Ns(),[r.project],l.packId,l.packFingerprint),w=await n(r.target);if(s.targetOrganizationId!==void 0){let y=await w.organizationId();if(y!==void 0&&y.slice(0,15)!==s.targetOrganizationId.slice(0,15)){i(2,`${r.target} is not the org this run wrote to: give --target that org.`);return}}let b=await et(xe(w.tooling));if(b.kind==="no-agent"){i(1,b.message);return}if(b.kind==="unreadable"){i(1,b.message);return}if(r.agent===void 0){o(`the agents of ${r.target}:`);for(let y of wo(b.catalog.agents))o(y);i(2,`--test-file takes --agent, the API name of the agent the tests are for, and a --topic for each topic of the scenario ${l.packId}`+(c?` (${c.topics.map(y=>y.key).join(", ")})`:"")+". Run with --help.");return}let g={agent:r.agent,runner:r.runner,topics:r.topics,guardTopic:r.guardTopic},S=await Ms({sidecar:tt(),spec:Fs()},{runId:s.runId,storagePath:s.storagePath,project:await Ls([r.project]),alias:r.target,choice:g,overwrite:r.overwrite,readCatalog:async()=>b,findPack:async()=>c});r.json&&process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",outcome:S},null,2)}
13
+ `);for(let y of ko(S))o(y);S.kind!=="written"&&(process.exitCode=S.kind==="no-agent"?1:2)}function ko(t){switch(t.kind){case"written":return[`test file: ${t.path}`,...t.leftOut.map(n=>` left out ${n.test}: ${n.message}`),...t.commands?["SandForge never deploys the test nor runs it, which spends the org's credits: from the project, run",` ${t.commands.create}`,` ${t.commands.run}`]:["This folder is no Salesforce DX project (no sfdx-project.json): sf agent test create runs from one, which it writes the test it creates into."]];case"exists":return[`${t.path} is there already: --overwrite writes over it.`];case"refused":return t.refusals.map(n=>`refused: ${n.message}`);case"no-agent":case"unavailable":return[t.message]}}var Qt=Object.keys(Gn),To=`sandforge seed \u2014 fill an org from a seed template, without the editor.
14
14
 
15
15
  Usage:
16
16
  npx sandforge seed \\
@@ -111,13 +111,13 @@ Options:
111
111
  share is taken of what the caps leave
112
112
  --fit-within <MB> with --fit or --fit-cap: take no more than this many
113
113
  MB, whatever the target has left
114
- ${er({run:"the run",simulation:"--dry-run"})}
114
+ ${gr({run:"the run",simulation:"--dry-run"})}
115
115
  --seed <n> draw as the run that printed this seed did: the
116
116
  same command with the same seed plans and writes
117
117
  the same numbers. Every run prints its seed
118
118
  (default: drawn)
119
119
  --locale <xx_XX> the names, addresses and phone numbers drawn:
120
- ${Wt.join(", ")}
120
+ ${Qt.join(", ")}
121
121
  (default: the org's default locale)
122
122
  --record-type <Object>=<Name>[,<Name>]
123
123
  with --object or --template-file, give that
@@ -377,70 +377,70 @@ sweep was refused or did not take all it was asked to (a --sweep-untied refused
377
377
  included), or the run was partial and --fail-on-partial was given; 130 a Ctrl-C
378
378
  stopped the run, 143 a SIGTERM (a CI job cancelled or timed out), 129 a SIGHUP:
379
379
  its file keeps what it created.
380
- `,Us=/^[A-Za-z][A-Za-z0-9_]{0,79}$/,Oe=2**32-1,ho=/^env-[a-z0-9][a-z0-9-]{0,195}$/;function zt(t){let n=t>>>0;return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var mo=2654435769,go=2246822507,wo=/^([A-Za-z][A-Za-z0-9_]{0,79})\.([A-Za-z][A-Za-z0-9_]{0,79})=([A-Za-z][A-Za-z0-9_]{0,79})$/,bo=10,xs="--parent-ids names the parents: it goes with neither --existing, --where nor --parent-limit.",yo=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function Ro(t,n){let e=(t??"").split(",").map(i=>i.trim()).filter(i=>i!==""),r=ue.maxExistingParents;e.length===0&&n("--parent-ids wants record ids, comma-separated."),e.length>r&&n(`--parent-ids takes ${r} ids at most, not ${e.length}.`);let o=e.filter(i=>!yo.test(i));return o.length>0&&n(`--parent-ids takes record ids, 15 or 18 letters and digits, not "${o.slice(0,3).join('", "')}".`),new Set(e.map(i=>i.slice(0,15))).size!==e.length&&n("--parent-ids names a record twice: give each parent once."),e}function So(t,n){let e=[],r=ue.maxPerParent,o=(s,d,l,f)=>{let c=Number(s);return(!Number.isInteger(c)||c<d||c>l)&&n(`${f} takes a whole number from ${d} to ${l}, not "${s??""}".`),c},i=s=>(s.parents.kind==="records"&&n(xs),s.parents.kind!=="existing"&&(s.parents={kind:"existing",limit:bo}),s.parents);for(let s=0;s<t.length;s++){let d=t[s],l=t[s+1];if(d==="--relation"){let w=wo.exec(l??"");w||n(`--relation wants "Child.Lookup=Parent", not "${l??""}".`);let[,g,S,y]=w;e.push({childObject:g,lookupField:S,parentObject:y,parents:{kind:"generated"},distribution:{mode:"perParent",count:1}}),s++;continue}if(!["--per-parent","--between","--ratio","--existing","--where","--parent-limit","--parent-ids"].includes(d))continue;let c=e.at(-1);c||n(`${d} applies to a relation: give --relation before it.`);let b=c;if(d==="--existing"){i(b);continue}if(s++,d==="--per-parent")b.distribution={mode:"perParent",count:o(l,1,r,d)};else if(d==="--between"){let w=/^(\d+)-(\d+)$/.exec(l??"");w||n(`--between wants "<min>-<max>", not "${l??""}".`);let[,g,S]=w,y=o(g,0,r,d),x=o(S,Math.max(1,y),r,d);b.distribution={mode:"range",min:y,max:x}}else if(d==="--ratio"){let w=Number(l);(!Number.isFinite(w)||w<ue.minRatio||w>r)&&n(`--ratio takes a number from ${ue.minRatio} to ${r}, not "${l??""}".`),b.distribution={mode:"ratio",ratio:w}}else d==="--where"?(l?.trim()||n("--where wants a SOQL condition."),i(b).where=l):d==="--parent-ids"?(b.parents.kind==="existing"&&n(xs),b.parents={kind:"records",ids:Ro(l,n)}):i(b).limit=o(l,1,ue.maxExistingParents,d)}return e}function ko(t,n,e){let r=t.map(o=>({...o}));for(let o of n){let i=`${o.childObject}.${o.lookupField}`,s=r.find(f=>f.objectApiName===o.childObject);s||e(`--relation ${i}: give ${o.childObject} with --object too.`);let d;if(o.parents.kind==="existing")d=o.parents.limit;else if(o.parents.kind==="records")d=o.parents.ids.length;else{let f=r.find(c=>c.objectApiName===o.parentObject);(!f||o.parentObject===o.childObject)&&e(`--relation ${i}: the ${o.parentObject} records this run writes cannot be the parents; give ${o.parentObject} with --object, or add --existing.`),d=f.recordCount}if(o.distribution.mode==="byKey")continue;let l=dn(o.distribution,d);l<1&&e(`--relation ${i} gives no parent a child: raise --ratio.`),s.recordCount=l}return r}var vo={switches:["--list-templates","--dry-run","--json","--existing","--fail-on-partial","--mute-automation","--accept-emails",...It.switches],values:["--target","--template","--template-file","--scenario","--scenario-seed","--run-id","--object","--batch-size","--seed","--locale","--record-type","--relation","--per-parent","--between","--ratio","--where","--parent-limit","--parent-ids","--fit","--fit-cap","--fit-within",...It.values]},Cs=1e5;function $o(t,n){let e=l=>t.flatMap((f,c)=>f===l&&c+1<t.length?[t[c+1]]:[]),r=l=>t.includes(l),o=e("--fit");r("--fit")&&(o.length!==1||o[0]!=="share")&&n(`--fit takes share, once, not "${o.join(" ")}".`);let i={objects:{}};for(let l of e("--fit-cap")){let f=/^(?:([A-Za-z][A-Za-z0-9_]{0,79})=)?(\d{1,6})$/.exec(l),c=f?Number(f[2]):NaN;(!f||c<1||c>Cs)&&n(`--fit-cap wants "<Object>=<n>" or "<n>", n a whole number from 1 to ${Cs}, not "${l}".`);let b=f[1];b===void 0?(i.all!==void 0&&n("--fit-cap <n> caps every object: give it once."),i.all=c):(i.objects[b]!==void 0&&n(`--fit-cap ${b}: give each object one cap.`),i.objects[b]=c)}let s=i.all!==void 0||Object.keys(i.objects).length>0,d;if(r("--fit-within")){let[l]=e("--fit-within");d=Number(l),!r("--fit")&&!s&&n("--fit-within goes with --fit share or --fit-cap."),(l===void 0||!/^\d+(?:\.\d+)?$/.test(l)||d<=0||d>1e6)&&n(`--fit-within takes a number of MB above 0, up to 1000000, not "${l??""}".`)}if(!(!r("--fit")&&!s))return{share:r("--fit"),...s?{caps:{...i.all!==void 0?{all:i.all}:{},...Object.keys(i.objects).length>0?{objects:i.objects}:{}}}:{},...d!==void 0?{withinMB:d}:{}}}function Ps(t){let n=t.slice(2);if((n.includes("--help")||n.includes("-h"))&&(process.stdout.write(po),process.exit(0)),Me(n,vo),n.includes("--list-templates")){for(let h of Le)process.stdout.write(`${h.id.padEnd(34)}${h.objects.length} object(s) ${Bs(h)}
381
- `);process.exit(0)}let e=(h,O)=>{let R=n.indexOf(h);return R>=0&&R+1<n.length?n[R+1]:O},r=h=>{process.stderr.write(`${h}
382
- `),process.exit(2)},o=h=>{let O=[];for(let R=0;R<n.length;R++)n[R]===h&&R+1<n.length&&O.push(n[R+1]);return O},i=e("--target"),s=e("--template"),d=e("--template-file"),l=e("--scenario"),f=o("--object");i||(process.stderr.write(`Missing --target. Run with --help.
380
+ `,ro=/^[A-Za-z][A-Za-z0-9_]{0,79}$/,Ce=2**32-1,Eo=/^env-[a-z0-9][a-z0-9-]{0,195}$/;function Vt(t){let n=t>>>0;return()=>{n=n+1831565813>>>0;let e=n;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var xo=2654435769,Co=2246822507,Po=/^([A-Za-z][A-Za-z0-9_]{0,79})\.([A-Za-z][A-Za-z0-9_]{0,79})=([A-Za-z][A-Za-z0-9_]{0,79})$/,Fo=10,Vs="--parent-ids names the parents: it goes with neither --existing, --where nor --parent-limit.",No=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;function _o(t,n){let e=(t??"").split(",").map(i=>i.trim()).filter(i=>i!==""),r=fe.maxExistingParents;e.length===0&&n("--parent-ids wants record ids, comma-separated."),e.length>r&&n(`--parent-ids takes ${r} ids at most, not ${e.length}.`);let o=e.filter(i=>!No.test(i));return o.length>0&&n(`--parent-ids takes record ids, 15 or 18 letters and digits, not "${o.slice(0,3).join('", "')}".`),new Set(e.map(i=>i.slice(0,15))).size!==e.length&&n("--parent-ids names a record twice: give each parent once."),e}function Do(t,n){let e=[],r=fe.maxPerParent,o=(s,d,l,f)=>{let c=Number(s);return(!Number.isInteger(c)||c<d||c>l)&&n(`${f} takes a whole number from ${d} to ${l}, not "${s??""}".`),c},i=s=>(s.parents.kind==="records"&&n(Vs),s.parents.kind!=="existing"&&(s.parents={kind:"existing",limit:Fo}),s.parents);for(let s=0;s<t.length;s++){let d=t[s],l=t[s+1];if(d==="--relation"){let b=Po.exec(l??"");b||n(`--relation wants "Child.Lookup=Parent", not "${l??""}".`);let[,g,S,y]=b;e.push({childObject:g,lookupField:S,parentObject:y,parents:{kind:"generated"},distribution:{mode:"perParent",count:1}}),s++;continue}if(!["--per-parent","--between","--ratio","--existing","--where","--parent-limit","--parent-ids"].includes(d))continue;let c=e.at(-1);c||n(`${d} applies to a relation: give --relation before it.`);let w=c;if(d==="--existing"){i(w);continue}if(s++,d==="--per-parent")w.distribution={mode:"perParent",count:o(l,1,r,d)};else if(d==="--between"){let b=/^(\d+)-(\d+)$/.exec(l??"");b||n(`--between wants "<min>-<max>", not "${l??""}".`);let[,g,S]=b,y=o(g,0,r,d),P=o(S,Math.max(1,y),r,d);w.distribution={mode:"range",min:y,max:P}}else if(d==="--ratio"){let b=Number(l);(!Number.isFinite(b)||b<fe.minRatio||b>r)&&n(`--ratio takes a number from ${fe.minRatio} to ${r}, not "${l??""}".`),w.distribution={mode:"ratio",ratio:b}}else d==="--where"?(l?.trim()||n("--where wants a SOQL condition."),i(w).where=l):d==="--parent-ids"?(w.parents.kind==="existing"&&n(Vs),w.parents={kind:"records",ids:_o(l,n)}):i(w).limit=o(l,1,fe.maxExistingParents,d)}return e}function Lo(t,n,e){let r=t.map(o=>({...o}));for(let o of n){let i=`${o.childObject}.${o.lookupField}`,s=r.find(f=>f.objectApiName===o.childObject);s||e(`--relation ${i}: give ${o.childObject} with --object too.`);let d;if(o.parents.kind==="existing")d=o.parents.limit;else if(o.parents.kind==="records")d=o.parents.ids.length;else{let f=r.find(c=>c.objectApiName===o.parentObject);(!f||o.parentObject===o.childObject)&&e(`--relation ${i}: the ${o.parentObject} records this run writes cannot be the parents; give ${o.parentObject} with --object, or add --existing.`),d=f.recordCount}if(o.distribution.mode==="byKey")continue;let l=gn(o.distribution,d);l<1&&e(`--relation ${i} gives no parent a child: raise --ratio.`),s.recordCount=l}return r}var Mo={switches:["--list-templates","--dry-run","--json","--existing","--fail-on-partial","--mute-automation","--accept-emails",...Ct.switches],values:["--target","--template","--template-file","--scenario","--scenario-seed","--run-id","--object","--batch-size","--seed","--locale","--record-type","--relation","--per-parent","--between","--ratio","--where","--parent-limit","--parent-ids","--fit","--fit-cap","--fit-within",...Ct.values]},Zs=1e5;function Uo(t,n){let e=l=>t.flatMap((f,c)=>f===l&&c+1<t.length?[t[c+1]]:[]),r=l=>t.includes(l),o=e("--fit");r("--fit")&&(o.length!==1||o[0]!=="share")&&n(`--fit takes share, once, not "${o.join(" ")}".`);let i={objects:{}};for(let l of e("--fit-cap")){let f=/^(?:([A-Za-z][A-Za-z0-9_]{0,79})=)?(\d{1,6})$/.exec(l),c=f?Number(f[2]):NaN;(!f||c<1||c>Zs)&&n(`--fit-cap wants "<Object>=<n>" or "<n>", n a whole number from 1 to ${Zs}, not "${l}".`);let w=f[1];w===void 0?(i.all!==void 0&&n("--fit-cap <n> caps every object: give it once."),i.all=c):(i.objects[w]!==void 0&&n(`--fit-cap ${w}: give each object one cap.`),i.objects[w]=c)}let s=i.all!==void 0||Object.keys(i.objects).length>0,d;if(r("--fit-within")){let[l]=e("--fit-within");d=Number(l),!r("--fit")&&!s&&n("--fit-within goes with --fit share or --fit-cap."),(l===void 0||!/^\d+(?:\.\d+)?$/.test(l)||d<=0||d>1e6)&&n(`--fit-within takes a number of MB above 0, up to 1000000, not "${l??""}".`)}if(!(!r("--fit")&&!s))return{share:r("--fit"),...s?{caps:{...i.all!==void 0?{all:i.all}:{},...Object.keys(i.objects).length>0?{objects:i.objects}:{}}}:{},...d!==void 0?{withinMB:d}:{}}}function Hs(t){let n=t.slice(2);if((n.includes("--help")||n.includes("-h"))&&(process.stdout.write(To),process.exit(0)),Ke(n,Mo),n.includes("--list-templates")){for(let m of ze)process.stdout.write(`${m.id.padEnd(34)}${m.objects.length} object(s) ${so(m)}
381
+ `);process.exit(0)}let e=(m,$)=>{let R=n.indexOf(m);return R>=0&&R+1<n.length?n[R+1]:$},r=m=>{process.stderr.write(`${m}
382
+ `),process.exit(2)},o=m=>{let $=[];for(let R=0;R<n.length;R++)n[R]===m&&R+1<n.length&&$.push(n[R+1]);return $},i=e("--target"),s=e("--template"),d=e("--template-file"),l=e("--scenario"),f=o("--object");i||(process.stderr.write(`Missing --target. Run with --help.
383
383
  `),process.exit(2)),!s&&d===void 0&&l===void 0&&f.length===0&&(process.stderr.write(`Nothing to seed: give --template, --template-file, --scenario or --object. Run with --help.
384
- `),process.exit(2)),l!==void 0&&(s!==void 0||d!==void 0||f.length>0||n.includes("--relation")||n.includes("--record-type"))&&r("Give --scenario alone: the scenario names its records and their links, so it goes with neither --template, --template-file, --object, --relation nor --record-type.");let c;if(n.includes("--scenario-seed")){let h=e("--scenario-seed");c=Number(h),l===void 0&&r("--scenario-seed goes with --scenario."),(h===void 0||!/^\d+$/.test(h)||!Number.isSafeInteger(c)||c>Oe)&&r(`--scenario-seed takes a whole number from 0 to ${Oe}, not "${h??""}".`)}d!==void 0&&(s!==void 0||f.length>0||n.includes("--relation"))&&r("Give --template-file alone: the file names its objects, their rules and their relations, so it goes with neither --template, --object nor --relation."),s&&f.length>0&&(process.stderr.write(`Give --template or --object, not both.
385
- `),process.exit(2));let b=e("--run-id");b!==void 0&&!ho.test(b)&&r(`--run-id takes "env-" then lowercase letters, digits and hyphens, 200 characters at most, not "${b}".`);let w=f.map(h=>{let O=h.lastIndexOf(":"),R=O>0?h.slice(0,O):h,A=O>0?Number(h.slice(O+1)):NaN;return Us.test(R)||(process.stderr.write(`Not an SObject API name: "${R}"
386
- `),process.exit(2)),(!Number.isInteger(A)||A<1||A>1e5)&&(process.stderr.write(`--object wants "Name:<count>", not "${h}".
384
+ `),process.exit(2)),l!==void 0&&(s!==void 0||d!==void 0||f.length>0||n.includes("--relation")||n.includes("--record-type"))&&r("Give --scenario alone: the scenario names its records and their links, so it goes with neither --template, --template-file, --object, --relation nor --record-type.");let c;if(n.includes("--scenario-seed")){let m=e("--scenario-seed");c=Number(m),l===void 0&&r("--scenario-seed goes with --scenario."),(m===void 0||!/^\d+$/.test(m)||!Number.isSafeInteger(c)||c>Ce)&&r(`--scenario-seed takes a whole number from 0 to ${Ce}, not "${m??""}".`)}d!==void 0&&(s!==void 0||f.length>0||n.includes("--relation"))&&r("Give --template-file alone: the file names its objects, their rules and their relations, so it goes with neither --template, --object nor --relation."),s&&f.length>0&&(process.stderr.write(`Give --template or --object, not both.
385
+ `),process.exit(2));let w=e("--run-id");w!==void 0&&!Eo.test(w)&&r(`--run-id takes "env-" then lowercase letters, digits and hyphens, 200 characters at most, not "${w}".`);let b=f.map(m=>{let $=m.lastIndexOf(":"),R=$>0?m.slice(0,$):m,A=$>0?Number(m.slice($+1)):NaN;return ro.test(R)||(process.stderr.write(`Not an SObject API name: "${R}"
386
+ `),process.exit(2)),(!Number.isInteger(A)||A<1||A>1e5)&&(process.stderr.write(`--object wants "Name:<count>", not "${m}".
387
387
  `),process.exit(2)),{objectApiName:R,recordCount:A}}),g=Number(e("--batch-size","200")??"200");(!Number.isInteger(g)||g<1||g>1e4)&&(process.stderr.write(`--batch-size takes a whole number between 1 and 10000.
388
- `),process.exit(2));let S=So(n,r);S.length>0&&s&&r("--relation goes with --object: a built-in template carries its own links.");let y;if(n.includes("--seed")){let h=e("--seed");y=Number(h),(h===void 0||!/^\d+$/.test(h)||!Number.isSafeInteger(y)||y>Oe)&&r(`--seed takes a whole number from 0 to ${Oe}, not "${h??""}".`)}let x=e("--locale");n.includes("--locale")&&(x===void 0||!Wt.includes(x))&&r(`--locale takes one of ${Wt.join(", ")}, not "${x??""}".`);let C={};for(let h of o("--record-type")){let O=/^([A-Za-z][A-Za-z0-9_]{0,79})=([A-Za-z][A-Za-z0-9_]{0,79}(?:,[A-Za-z][A-Za-z0-9_]{0,79})*)$/.exec(h);O||r(`--record-type wants "Object=Name" or "Object=Name,Other", not "${h}".`);let[,R,A]=O;d===void 0&&!w.some(M=>M.objectApiName===R)&&r(`--record-type ${R}: give ${R} with --object too.`),C[R]=[...new Set(A.split(","))]}let z=$o(n,r),v=tr(n);return{target:i,templateId:s,...d!==void 0?{templateFile:d}:{},...l!==void 0?{scenario:l}:{},...c!==void 0?{scenarioSeed:c}:{},...b!==void 0?{runId:b}:{},objects:ko(w,S,r),relations:S,batchSize:g,dryRun:n.includes("--dry-run"),json:n.includes("--json"),failOnPartial:n.includes("--fail-on-partial"),muteAutomation:n.includes("--mute-automation"),acceptEmails:n.includes("--accept-emails"),...y!==void 0?{seed:y}:{},...x!==void 0?{locale:x}:{},recordTypes:C,...z?{fit:z}:{},...v!==void 0?{checkpointFirst:v}:{}}}var Ao=fo(__dirname,"catalogue.en.json"),Xe;function jo(){if(Xe===void 0)try{Xe=JSON.parse(Ie(Ao,"utf8"))}catch{Xe=null}return Xe}function Bs(t,n=jo()){if(!t.name.startsWith("seed.templates.")||!n)return t.name;let e=n;for(let r of t.name.split(".")){if(e===null||typeof e!="object")return t.name;e=e[r]}return typeof e=="string"&&e.trim()!==""?e:t.name}var Oo=10;function Io(t,n){let e;try{e=Ie(t,"utf8")}catch(d){return{refusal:`--template-file ${t} cannot be read: ${d instanceof Error?d.message:String(d)}`}}let r;try{r=JSON.parse(e)}catch(d){return{refusal:`--template-file ${t} is not JSON: ${d instanceof Error?d.message:String(d)}`}}let o=$n.safeParse(r);if(!o.success){let{issues:d}=o.error,l=d.slice(0,Oo).map(c=>` ${c.path.join(".")||"(the template)"}: ${c.message}`),f=d.length-l.length;return{refusal:[`--template-file ${t} is not a seed template the panel would run:`,...l,...f>0?[` and ${f} more`]:[]].join(`
389
- `)}}let i=new Date().toISOString(),s=o.data;return{template:{...s,id:typeof s.id=="string"&&s.id!==""?s.id:`cli-${Date.now()}`,version:typeof s.version=="number"?s.version:1,createdAt:typeof s.createdAt=="string"?s.createdAt:i,updatedAt:typeof s.updatedAt=="string"?s.updatedAt:i,objects:o.data.objects.map(d=>({...d,batchSize:d.batchSize??n}))}}}function To(t,n){let e=Nt(t,n,Ot);return e===void 0?void 0:`--run-id ${t}: a run of that id is kept already, in ${e}. Give an id no run has.`}function Eo(t,n){for(let e of Object.keys(n)){let r=t.objects.find(o=>o.objectApiName===e);if(r===void 0)return`--record-type ${e}: the template file writes no ${e}; it writes ${t.objects.map(o=>o.objectApiName).join(", ")}.`;if(r.fieldRules.some(o=>o.fieldApiName==="RecordTypeId"))return`--record-type ${e}: the template file gives ${e} its record type already, by a RecordTypeId rule: give it in one place.`}}function xo(t){if(!t)return null;let n=Le.find(e=>e.id===t);if(!n){let e=Le.map(r=>r.id).join(", ");process.stderr.write(`No template "${t}". There is: ${e}
390
- `),process.exit(2)}return n}function Co(t,n,e="business"){let r=e==="person"&&n===ce,o=t.filter(s=>s.createable&&!ln(n??"",s.name,r?"person":"business")&&(s.name==="Name"||Po(s)||r&&No.has(s.name)||!s.nillable&&s.defaultedOnCreate!==!0)),i=[];for(let s of o){let d=un({fieldApiName:s.name,type:s.type,picklistValues:(s.picklistValues??[]).filter(l=>l.active!==!1&&typeof l.value=="string").map(l=>l.value),referenceTo:[],length:s.length??0,integerDigits:cn(s),objectApiName:n});d.ruleType==="static"&&d.config.staticValue===void 0||i.push({fieldApiName:s.name,fieldType:s.type,ruleType:d.ruleType,config:d.config})}return i}function Po(t){return(t.type==="email"||t.type==="phone")&&!t.name.includes("__")}var No=new Set(["FirstName","LastName"]),Fo="SELECT DeveloperName FROM RecordType WHERE SobjectType = 'Account' AND IsPersonType = true";async function _o(t){try{let n=await t.query(Fo);return new Set(n.records.flatMap(e=>typeof e.DeveloperName=="string"?[e.DeveloperName]:[]))}catch{return new Set}}function Do(t,n){let e=t.filter(o=>n.has(o));if(e.length===0)return{kind:"business"};if(e.length===t.length)return{kind:"person"};let r=t.filter(o=>!n.has(o));return{refusal:`--record-type ${ce}: ${e.join(", ")} ${e.length===1?"is a person account record type":"are person account record types"} and ${r.join(", ")} ${r.length===1?"is":"are"} not: a person account and a business account take different fields. Seed one kind in a run.`}}function Lo(t){return` ${ce}: ${t.join(", ")} ${t.length===1?"is a person account record type":"are person account record types"}: the accounts are written as person accounts, with a first and last name, the person\u2019s email and phones, and no Name, which the org builds from the two names`}function Ns(t,n,e){let r=wt(e).filter(s=>!s.master),o=r.filter(s=>s.active&&s.available),i=[];for(let s of n){let d=r.find(l=>l.developerName===s);if(!d||!d.active||!d.available){let l=o.map(f=>f.developerName).join(", ")||"none";return{refusal:`--record-type ${t}=${s}: `+(d?d.active?`the running user may not use record type ${s}`:`record type ${s} is inactive`:`${t} has no record type ${s}`)+`. Open to them: ${l}.`}}i.push(d.recordTypeId)}return{rule:i.length===1?{fieldApiName:"RecordTypeId",fieldType:"reference",ruleType:"static",config:{staticValue:i[0]}}:{fieldApiName:"RecordTypeId",fieldType:"reference",ruleType:"picklist_random",config:{picklistValues:i}}}}function Mo(t,n){let e=wt(n).filter(i=>!i.master&&i.active&&i.available);if(e.length<2)return;let r=e.find(i=>i.defaultRecordTypeMapping),o=qn()?.startsWith("sandforge env")===!0?`the resource's recordTypes for ${t}, in the file, chooses`:`${Wn("--record-type")} ${t}=<Name> chooses`;return` ${t}: ${e.length} record types open to you (${e.map(i=>i.developerName).join(", ")}); the records take ${r?`your default, ${r.developerName}`:"your default"}: ${o}`}function Uo(t){switch(t.mode){case"perParent":return`${t.count} per parent`;case"range":return`${t.min} to ${t.max} per parent`;case"ratio":return`${t.ratio} per parent on average`;case"byKey":return"each under the parent row its key names"}}function Bo(t){return new Nr({...t.signal?{signal:t.signal}:{},...t.onRowIds?{onRowIds:t.onRowIds}:{},...t.knowledge?{knowledge:t.knowledge}:{},validator:new qr,readExistingParentIds:t.readExistingParentIds,...t.readPresentParentIds?{readPresentParentIds:t.readPresentParentIds}:{},...t.describeKeyPrefix?{describeKeyPrefix:t.describeKeyPrefix}:{},describeCreateableFields:t.describeCreateableFields,...t.describeVisibleFields?{describeVisibleFields:t.describeVisibleFields}:{},...t.describeComputedFields?{describeComputedFields:t.describeComputedFields}:{},...t.describePicklistValues?{describePicklistValues:t.describePicklistValues}:{},...t.describeFieldLengths?{describeFieldLengths:t.describeFieldLengths}:{},...t.describeRequiredFields?{describeRequiredFields:t.describeRequiredFields}:{},...t.objectAccess?{objectAccess:t.objectAccess}:{},...t.readTarget?{readTarget:t.readTarget}:{},...t.update?{update:t.update}:{},planBuilder:new Wr,fieldMapper:new Jr({aiGenerator:new Gr(()=>{throw new Error("This template has an AI field rule. sandforge seed runs without an AI key: use the panel for it, or replace the rule with a faker one.")}),fakerFallback:new Zr(t.locale,{random:zt(t.seed^mo)}),random:zt(t.seed^go)}),referenceLinker:new Vr,insert:t.insert,generateId:()=>`cli-${Math.random().toString(36).slice(2)}`,now:()=>new Date().toISOString(),random:zt(t.seed)})}function zo(t,n,e){return t<=n?"(REST)":e===!0?"(REST: an active duplicate rule watches the object, which a Bulk API job cannot waive)":e===!1?"(a Bulk API job)":"(a Bulk API job, or REST when an active duplicate rule watches the object)"}function Ko(t,n){return Lr(t,n)}async function qo(t){let n=await as({org:t.target,objects:t.objects.map(r=>r.objectApiName),readAutomation:t.readAutomation,readLimits:t.readLimits}),e=ds(n,t.objects,t.target);return{lines:[...cs(n,t.target),...Un(e.checks,t.target),...(e.unknown??[]).map(r=>` emails: ${r}`)],gate:e}}function Wo(t,n,e,r){return{storage:{bytes:Dr(t,n),...e.check,...e.refusedFor==="storage"?{refusal:e.refusal}:{}},apiRequests:zs(e,r)}}function zs(t,n){return{...t.api,...n!==void 0?{sent:n}:{},...t.refusedFor==="apiRequests"?{refusal:t.refusal}:{}}}function Go(t){switch(t.kind){case"trigger":return`what Apex trigger ${t.name} on ${t.objectApiName} creates`;case"notRead":return`what "${t.name}" on ${t.objectApiName} creates: it was not read`;case"share":return`the ${t.name} rows the flows of ${t.objectApiName} create`}}function Jo(t){return`${Math.floor(t*1e3)/10} %`}function Fs(t,n,e){let{proposal:r}=t,o=r.budget,i=e.applied?"fit":"--fit share would seed";if(r.cannotFit!==void 0)return[`${i}: the seed cannot be fitted: ${r.cannotFit}`];if(t.heldBy==="whole")return[`${i}: the seed fits as it is, ${t.records} records, about ${$e(r.estimateMB)} MB: nothing cut`];let s=$e(o.budgetMB+o.automationMB),d=t.heldBy==="apiRequests"?`the largest whose writes leave ${n} a tenth of its daily API requests`:t.heldBy==="within"?`the largest that fits the ${o.withinMB??s} MB asked (--fit-within)`:`the largest that fits ${s} MB: ${o.share*100} % of the ${o.remainingMB} MB ${n} says it has left of ${o.maxMB}, ${o.roundingMB} MB kept first for the rounding of what it says`+Kn(o),l=e.roomUnread!==void 0?`no room kept for what its automation creates: it could not be read (${e.roomUnread})`:o.automationMB>0?`${$e(o.automationMB)} MB of it kept for what its flows still running create under these records`:"nothing kept for its flows: none still running creates records under these"+(e.muted?" (--mute-automation keeps the others quiet)":""),f=Math.max(...r.objects.map(c=>c.objectApiName.length));return[t.heldBy==="caps"?`${i}: the caps asked, within the ${s} MB that fit; ${l}`:`${i}: share ${Jo(r.share)}, ${d}; ${l}`,...r.objects.map(c=>` ${c.objectApiName.padEnd(f)} ${c.after} of ${c.before}`+(c.keptWhole==="rows"?" (kept whole: the rows the template gives)":c.keptWhole==="byKey"?" (kept whole: each under the parent row its key names)":"")),...(o.notCounted??[]).map(c=>` not counted: ${Go(c)}`),` fitted seed: ${t.records} records, about ${$e(r.estimateMB)} MB`+(o.automationMB>0?" with what its flows create under them":"")+`, ${t.requests} API requests`,` ${zn(n)}`]}function Vo(t,n,e){return{applied:n,...t.proposal,heldBy:t.heldBy,records:t.records,requests:t.requests,...e?.caps?{caps:e.caps}:{},...e?.withinMB!==void 0?{withinMB:e.withinMB}:{}}}async function Zo(t=process.argv){if(t.slice(2).includes("--remove"))return ca(t);if(t.slice(2).includes("--test-file"))return(t.slice(2).includes("--help")||t.slice(2).includes("-h"))&&Ps(t),Es(t,Ho,ee());let n=Date.now(),e=Ps(t),r;if(e.scenario!==void 0){let a=Ut(e.scenario);"refusal"in a&&(process.stderr.write(`${a.refusal}
391
- `),process.exit(2)),r=a.pack}let o;if(e.templateFile!==void 0){let a=Io(e.templateFile,e.batchSize);"refusal"in a&&(process.stderr.write(`${a.refusal}
392
- `),process.exit(2)),o=a.template;let u=Eo(o,e.recordTypes);u!==void 0&&(process.stderr.write(`${u}
393
- `),process.exit(2))}let i=e.runId!==void 0?To(e.runId,ee()):void 0;i!==void 0&&(process.stderr.write(`${i}
388
+ `),process.exit(2));let S=Do(n,r);S.length>0&&s&&r("--relation goes with --object: a built-in template carries its own links.");let y;if(n.includes("--seed")){let m=e("--seed");y=Number(m),(m===void 0||!/^\d+$/.test(m)||!Number.isSafeInteger(y)||y>Ce)&&r(`--seed takes a whole number from 0 to ${Ce}, not "${m??""}".`)}let P=e("--locale");n.includes("--locale")&&(P===void 0||!Qt.includes(P))&&r(`--locale takes one of ${Qt.join(", ")}, not "${P??""}".`);let C={};for(let m of o("--record-type")){let $=/^([A-Za-z][A-Za-z0-9_]{0,79})=([A-Za-z][A-Za-z0-9_]{0,79}(?:,[A-Za-z][A-Za-z0-9_]{0,79})*)$/.exec(m);$||r(`--record-type wants "Object=Name" or "Object=Name,Other", not "${m}".`);let[,R,A]=$;d===void 0&&!b.some(B=>B.objectApiName===R)&&r(`--record-type ${R}: give ${R} with --object too.`),C[R]=[...new Set(A.split(","))]}let K=Uo(n,r),k=wr(n);return{target:i,templateId:s,...d!==void 0?{templateFile:d}:{},...l!==void 0?{scenario:l}:{},...c!==void 0?{scenarioSeed:c}:{},...w!==void 0?{runId:w}:{},objects:Lo(b,S,r),relations:S,batchSize:g,dryRun:n.includes("--dry-run"),json:n.includes("--json"),failOnPartial:n.includes("--fail-on-partial"),muteAutomation:n.includes("--mute-automation"),acceptEmails:n.includes("--accept-emails"),...y!==void 0?{seed:y}:{},...P!==void 0?{locale:P}:{},recordTypes:C,...K?{fit:K}:{},...k!==void 0?{checkpointFirst:k}:{}}}var Bo=Io(__dirname,"catalogue.en.json"),nt;function zo(){if(nt===void 0)try{nt=JSON.parse(Pe(Bo,"utf8"))}catch{nt=null}return nt}function so(t,n=zo()){if(!t.name.startsWith("seed.templates.")||!n)return t.name;let e=n;for(let r of t.name.split(".")){if(e===null||typeof e!="object")return t.name;e=e[r]}return typeof e=="string"&&e.trim()!==""?e:t.name}var Ko=10;function Wo(t,n){let e;try{e=Pe(t,"utf8")}catch(d){return{refusal:`--template-file ${t} cannot be read: ${d instanceof Error?d.message:String(d)}`}}let r;try{r=JSON.parse(e)}catch(d){return{refusal:`--template-file ${t} is not JSON: ${d instanceof Error?d.message:String(d)}`}}let o=Fn.safeParse(r);if(!o.success){let{issues:d}=o.error,l=d.slice(0,Ko).map(c=>` ${c.path.join(".")||"(the template)"}: ${c.message}`),f=d.length-l.length;return{refusal:[`--template-file ${t} is not a seed template the panel would run:`,...l,...f>0?[` and ${f} more`]:[]].join(`
389
+ `)}}let i=new Date().toISOString(),s=o.data;return{template:{...s,id:typeof s.id=="string"&&s.id!==""?s.id:`cli-${Date.now()}`,version:typeof s.version=="number"?s.version:1,createdAt:typeof s.createdAt=="string"?s.createdAt:i,updatedAt:typeof s.updatedAt=="string"?s.updatedAt:i,objects:o.data.objects.map(d=>({...d,batchSize:d.batchSize??n}))}}}function qo(t,n){let e=Ut(t,n,xt);return e===void 0?void 0:`--run-id ${t}: a run of that id is kept already, in ${e}. Give an id no run has.`}function Go(t,n){for(let e of Object.keys(n)){let r=t.objects.find(o=>o.objectApiName===e);if(r===void 0)return`--record-type ${e}: the template file writes no ${e}; it writes ${t.objects.map(o=>o.objectApiName).join(", ")}.`;if(r.fieldRules.some(o=>o.fieldApiName==="RecordTypeId"))return`--record-type ${e}: the template file gives ${e} its record type already, by a RecordTypeId rule: give it in one place.`}}function Jo(t){if(!t)return null;let n=ze.find(e=>e.id===t);if(!n){let e=ze.map(r=>r.id).join(", ");process.stderr.write(`No template "${t}". There is: ${e}
390
+ `),process.exit(2)}return n}function Vo(t,n,e="business"){let r=e==="person"&&n===ue,o=t.filter(s=>s.createable&&!yn(n??"",s.name,r?"person":"business")&&(s.name==="Name"||Zo(s)||r&&Ho.has(s.name)||!s.nillable&&s.defaultedOnCreate!==!0)),i=[];for(let s of o){let d=bn({fieldApiName:s.name,type:s.type,picklistValues:(s.picklistValues??[]).filter(l=>l.active!==!1&&typeof l.value=="string").map(l=>l.value),referenceTo:[],length:s.length??0,integerDigits:wn(s),objectApiName:n});d.ruleType==="static"&&d.config.staticValue===void 0||i.push({fieldApiName:s.name,fieldType:s.type,ruleType:d.ruleType,config:d.config})}return i}function Zo(t){return(t.type==="email"||t.type==="phone")&&!t.name.includes("__")}var Ho=new Set(["FirstName","LastName"]),Qo="SELECT DeveloperName FROM RecordType WHERE SobjectType = 'Account' AND IsPersonType = true";async function Xo(t){try{let n=await t.query(Qo);return new Set(n.records.flatMap(e=>typeof e.DeveloperName=="string"?[e.DeveloperName]:[]))}catch{return new Set}}function Yo(t,n){let e=t.filter(o=>n.has(o));if(e.length===0)return{kind:"business"};if(e.length===t.length)return{kind:"person"};let r=t.filter(o=>!n.has(o));return{refusal:`--record-type ${ue}: ${e.join(", ")} ${e.length===1?"is a person account record type":"are person account record types"} and ${r.join(", ")} ${r.length===1?"is":"are"} not: a person account and a business account take different fields. Seed one kind in a run.`}}function ea(t){return` ${ue}: ${t.join(", ")} ${t.length===1?"is a person account record type":"are person account record types"}: the accounts are written as person accounts, with a first and last name, the person\u2019s email and phones, and no Name, which the org builds from the two names`}function Qs(t,n,e){let r=kt(e).filter(s=>!s.master),o=r.filter(s=>s.active&&s.available),i=[];for(let s of n){let d=r.find(l=>l.developerName===s);if(!d||!d.active||!d.available){let l=o.map(f=>f.developerName).join(", ")||"none";return{refusal:`--record-type ${t}=${s}: `+(d?d.active?`the running user may not use record type ${s}`:`record type ${s} is inactive`:`${t} has no record type ${s}`)+`. Open to them: ${l}.`}}i.push(d.recordTypeId)}return{rule:i.length===1?{fieldApiName:"RecordTypeId",fieldType:"reference",ruleType:"static",config:{staticValue:i[0]}}:{fieldApiName:"RecordTypeId",fieldType:"reference",ruleType:"picklist_random",config:{picklistValues:i}}}}function ta(t,n){let e=kt(n).filter(i=>!i.master&&i.active&&i.available);if(e.length<2)return;let r=e.find(i=>i.defaultRecordTypeMapping),o=ar()?.startsWith("sandforge env")===!0?`the resource's recordTypes for ${t}, in the file, chooses`:`${ir("--record-type")} ${t}=<Name> chooses`;return` ${t}: ${e.length} record types open to you (${e.map(i=>i.developerName).join(", ")}); the records take ${r?`your default, ${r.developerName}`:"your default"}: ${o}`}function na(t){switch(t.mode){case"perParent":return`${t.count} per parent`;case"range":return`${t.min} to ${t.max} per parent`;case"ratio":return`${t.ratio} per parent on average`;case"byKey":return"each under the parent row its key names"}}function ra(t){return new Qr({...t.signal?{signal:t.signal}:{},...t.onRowIds?{onRowIds:t.onRowIds}:{},...t.knowledge?{knowledge:t.knowledge}:{},validator:new is,readExistingParentIds:t.readExistingParentIds,...t.readPresentParentIds?{readPresentParentIds:t.readPresentParentIds}:{},...t.describeKeyPrefix?{describeKeyPrefix:t.describeKeyPrefix}:{},describeCreateableFields:t.describeCreateableFields,...t.describeVisibleFields?{describeVisibleFields:t.describeVisibleFields}:{},...t.describeComputedFields?{describeComputedFields:t.describeComputedFields}:{},...t.describePicklistValues?{describePicklistValues:t.describePicklistValues}:{},...t.describeFieldLengths?{describeFieldLengths:t.describeFieldLengths}:{},...t.describeRequiredFields?{describeRequiredFields:t.describeRequiredFields}:{},...t.objectAccess?{objectAccess:t.objectAccess}:{},...t.readTarget?{readTarget:t.readTarget}:{},...t.update?{update:t.update}:{},planBuilder:new ds,fieldMapper:new us({aiGenerator:new cs(()=>{throw new Error("This template has an AI field rule. sandforge seed runs without an AI key: use the panel for it, or replace the rule with a faker one.")}),fakerFallback:new fs(t.locale,{random:Vt(t.seed^xo)}),random:Vt(t.seed^Co)}),referenceLinker:new ls,insert:t.insert,generateId:()=>`cli-${Math.random().toString(36).slice(2)}`,now:()=>new Date().toISOString(),random:Vt(t.seed)})}function sa(t,n,e){return t<=n?"(REST)":e===!0?"(REST: an active duplicate rule watches the object, which a Bulk API job cannot waive)":e===!1?"(a Bulk API job)":"(a Bulk API job, or REST when an active duplicate rule watches the object)"}function oa(t,n){return ts(t,n)}async function aa(t){let n=await vs({org:t.target,objects:t.objects.map(r=>r.objectApiName),readAutomation:t.readAutomation,readLimits:t.readLimits}),e=As(n,t.objects,t.target);return{lines:[...js(n,t.target),...nr(e.checks,t.target),...(e.unknown??[]).map(r=>` emails: ${r}`)],gate:e}}function ia(t,n,e,r){return{storage:{bytes:es(t,n),...e.check,...e.refusedFor==="storage"?{refusal:e.refusal}:{}},apiRequests:oo(e,r)}}function oo(t,n){return{...t.api,...n!==void 0?{sent:n}:{},...t.refusedFor==="apiRequests"?{refusal:t.refusal}:{}}}function da(t){switch(t.kind){case"trigger":return`what Apex trigger ${t.name} on ${t.objectApiName} creates`;case"notRead":return`what "${t.name}" on ${t.objectApiName} creates: it was not read`;case"share":return`the ${t.name} rows the flows of ${t.objectApiName} create`}}function ca(t){return`${Math.floor(t*1e3)/10} %`}function Xs(t,n,e){let{proposal:r}=t,o=r.budget,i=e.applied?"fit":"--fit share would seed";if(r.cannotFit!==void 0)return[`${i}: the seed cannot be fitted: ${r.cannotFit}`];if(t.heldBy==="whole")return[`${i}: the seed fits as it is, ${t.records} records, about ${Ie(r.estimateMB)} MB: nothing cut`];let s=Ie(o.budgetMB+o.automationMB),d=t.heldBy==="apiRequests"?`the largest whose writes leave ${n} a tenth of its daily API requests`:t.heldBy==="within"?`the largest that fits the ${o.withinMB??s} MB asked (--fit-within)`:`the largest that fits ${s} MB: ${o.share*100} % of the ${o.remainingMB} MB ${n} says it has left of ${o.maxMB}, ${o.roundingMB} MB kept first for the rounding of what it says`+or(o),l=e.roomUnread!==void 0?`no room kept for what its automation creates: it could not be read (${e.roomUnread})`:o.automationMB>0?`${Ie(o.automationMB)} MB of it kept for what its flows still running create under these records`:"nothing kept for its flows: none still running creates records under these"+(e.muted?" (--mute-automation keeps the others quiet)":""),f=Math.max(...r.objects.map(c=>c.objectApiName.length));return[t.heldBy==="caps"?`${i}: the caps asked, within the ${s} MB that fit; ${l}`:`${i}: share ${ca(r.share)}, ${d}; ${l}`,...r.objects.map(c=>` ${c.objectApiName.padEnd(f)} ${c.after} of ${c.before}`+(c.keptWhole==="rows"?" (kept whole: the rows the template gives)":c.keptWhole==="byKey"?" (kept whole: each under the parent row its key names)":"")),...(o.notCounted??[]).map(c=>` not counted: ${da(c)}`),` fitted seed: ${t.records} records, about ${Ie(r.estimateMB)} MB`+(o.automationMB>0?" with what its flows create under them":"")+`, ${t.requests} API requests`,` ${sr(n)}`]}function ua(t,n,e){return{applied:n,...t.proposal,heldBy:t.heldBy,records:t.records,requests:t.requests,...e?.caps?{caps:e.caps}:{},...e?.withinMB!==void 0?{withinMB:e.withinMB}:{}}}async function la(t=process.argv){if(t.slice(2).includes("--remove"))return Aa(t);if(t.slice(2).includes("--test-file"))return(t.slice(2).includes("--help")||t.slice(2).includes("-h"))&&Hs(t),Js(t,fa,te());let n=Date.now(),e=Hs(t),r;if(e.scenario!==void 0){let a=Gt(e.scenario);"refusal"in a&&(process.stderr.write(`${a.refusal}
391
+ `),process.exit(2)),r=a.pack}let o;if(e.templateFile!==void 0){let a=Wo(e.templateFile,e.batchSize);"refusal"in a&&(process.stderr.write(`${a.refusal}
392
+ `),process.exit(2)),o=a.template;let u=Go(o,e.recordTypes);u!==void 0&&(process.stderr.write(`${u}
393
+ `),process.exit(2))}let i=e.runId!==void 0?qo(e.runId,te()):void 0;i!==void 0&&(process.stderr.write(`${i}
394
394
  `),process.exit(2));let s=a=>{process[e.json?"stderr":"stdout"].write(`${a}
395
- `)},d=e.seed??ao(0,Oe+1),l=new Date().toISOString();s(`sandforge seed -> ${e.target}`),s(`seed: ${d} (--seed ${d} draws the same again)`);let f=await ye(e.target),c=le(f),b=[lt(c)],w=()=>b.reduce((a,u)=>a+u(),0),g=e.dryRun?void 0:await gn(c,e.target,{tool:"sandforge seed",action:"write",readOnly:"--dry-run"}),S=await Yr(e.locale,c),y=a=>c.sobject(a).describe(),x=new Map,C=a=>{let u=x.get(a);return u||(u=y(a),x.set(a,u)),u};s(`locale: ${S}${e.locale?"":" (the org's; --locale draws in another)"}`);let z=new Date().toISOString(),v=o??xo(e.templateId),h;if(r!==void 0){let a=await js({query:async u=>(await c.query(u)).records,objectAccess:_t(c),describe:u=>c.sobject(u).describe()},r,e.scenarioSeed);"issues"in a&&(process.stderr.write(`The scenario cannot be compiled: ${a.issues.join("; ")}
396
- `),process.exit(2)),h=a,v=a.compiled.template;for(let u of Os(r,a.preparation))s(u)}for(let a of e.relations){let u=a.parents.kind==="generated"?`the ${a.parentObject} records this run writes`:a.parents.kind==="records"?`the ${a.parents.ids.length} ${a.parentObject} records named by id`:`at most ${a.parents.limit} ${a.parentObject} records already in the org`+(a.parents.where?` where ${a.parents.where}`:""),p=e.objects.find(E=>E.objectApiName===a.childObject)?.recordCount;s(` relation ${a.childObject}.${a.lookupField}: up to ${p} record(s), ${Uo(a.distribution)}, over ${u}`)}let O=[],R=[];if(o!==void 0&&Object.keys(e.recordTypes).length>0){let a=[];for(let u of o.objects){let p=e.recordTypes[u.objectApiName];if(!p){a.push(u);continue}let E=await C(u.objectApiName),N=Ns(u.objectApiName,p,E.recordTypeInfos);"refusal"in N&&(process.stderr.write(`${N.refusal}
397
- `),process.exit(2)),a.push({...u,fieldRules:[...u.fieldRules,N.rule]})}o={...o,objects:a},v=o}if(o?.objects.some(a=>a.objectApiName===ce)){let a=Xr(o,await Hr(c));"refusal"in a&&(process.stderr.write(`${a.refusal}
398
- `),process.exit(2)),v=a.template,R.push(...a.personObjects);for(let u of a.personObjects){let p=` ${u}: the template gives it person account record types: the accounts are written as person accounts, without Name, which the org builds from the two names`;s(p),O.push(p.trim())}}if(!v){let a=[];for(let[u,p]of e.objects.entries()){let E=await C(p.objectApiName),N=e.recordTypes[p.objectApiName],de="business";if(N&&p.objectApiName===ce){let L=Do(N,await _o(c));if("refusal"in L&&(process.stderr.write(`${L.refusal}
399
- `),process.exit(2)),de=L.kind,de==="person"){R.push(ce);let an=Lo(N);s(an),O.push(an.trim())}}let _e=E.createable===!1,on=E.fields,ot=Co(_e?on.map(L=>({...L,createable:!0})):on,p.objectApiName,de);if(N){let L=Ns(p.objectApiName,N,E.recordTypeInfos);"refusal"in L&&(process.stderr.write(`${L.refusal}
400
- `),process.exit(2)),ot.push(L.rule)}else{let L=Mo(p.objectApiName,E.recordTypeInfos);L&&s(L)}s(_e?` ${p.objectApiName}: the user this seed runs as may not create its records: skipped (give that user Create on it in a permission set)`:` ${p.objectApiName}: ${ot.map(L=>L.fieldApiName).join(", ")||"(none)"}`),a.push({objectApiName:p.objectApiName,recordCount:p.recordCount,fieldRules:ot,excludedFields:[],insertOrder:u,batchSize:e.batchSize})}v={id:`cli-${Date.now()}`,name:"sandforge seed",description:"Headless run",version:1,strategy:"faker",objects:a,...e.relations.length>0?{relations:e.relations}:{},tags:["cli"],createdAt:z,updatedAt:z}}for(let a of Object.keys(e.fit?.caps?.objects??{}))v.objects.some(u=>u.objectApiName===a)||(process.stderr.write(`--fit-cap ${a}: the seed writes no ${a}.
401
- `),process.exit(2));let A=await Ae(c).read(e.target,v.objects.map(a=>a.objectApiName)).catch(a=>({unread:a instanceof Error?a.message:String(a)})),M=rs(v,h!==void 0),k=(a,u=[])=>{throw e.json&&process.stdout.write(Rn({tool:"sandforge-seed",target:e.target,elapsedMs:W(n)},a,u)),new Error([a,...u].map(Re).join(`
402
- `))},j,U;if(e.muteAutomation)try{j=await St(async()=>Rt(c),A,{writes:M});for(let a of fe(j.muted,e.target))s(` ${a}`)}catch(a){if(!ke(a))throw a;U=a.refusal,e.dryRun&&s(` ${Y(a.refusal)}`)}let _=await os(v,A,Je(C).unset),B=ss(A,j?.plan,M,_),V={...B.unread!==void 0?{roomUnread:B.unread}:{},muted:(j?.plan?.assign.length??0)>0},Z=e.runId??`sandforge-seed-${io()}`,H=e.checkpointFirst?rr({module:"seed",operationId:Z,request:e.checkpointFirst,session:f,org:nr(f,g??await be(c)),connect:a=>{let u=le(a);return b.push(lt(u)),u},journalDir:ee(),say:s,own:{runId:Z}}):void 0,G,te=[],ne=a=>{let u={code:ve,message:a};te.push(u),e.dryRun&&s(` ${Y(u)}`)},pe=v.objects.filter(a=>a.recordCount>0);if(H&&pe.length>0){let a={written:pe.map(u=>u.objectApiName),running:B.running??{firing:[]}};try{G={ask:a,estimate:await H.scope(a)}}catch(u){ne(_n(u))}}let J=await Pn({read:A,...j?.plan?{plan:j.plan}:{},writes:M,readDeliverability:async()=>mn(g??await be(c))?xn:Cn(c),accepted:e.acceptEmails===!0,target:e.target,run:"seed",keepsAddresses:!0,mayMute:e.muteAutomation!==!0&&qe("--mute-automation")}),he=Bn(J.ofRun),m={...he,...Nn(j?.plan)},$=_t(c),T=await Qr(v,$),I=()=>w()-(he.deliverability??0),me=Je(C),X=await _r(T,{describeCreateableFields:me.createable,describeRequiredFields:Ft(me,R)}),re={duplicateRules:Gn(A),slices:X,bulkThreshold:at.bulk.threshold,typedFirst:e.dryRun,sentBefore:I()},D=await xt(kt(c,g?.id??f.orgId),T,R,e.target,G?.estimate,m,re,B.room),ge,Qe,Gt=a=>{Qe=a,e.dryRun&&s(` ${Y(a)}`)};if(e.fit&&D.refusedFor!=="checkpoint"&&te.length===0){let a=Ct(D,e.fit.withinMB);if("unread"in a)Gt({code:ts,message:`The seed was refused before it wrote anything: it cannot be fitted to ${e.target}, whose data storage left could not be read (${a.unread}): give --fit-within <MB>, the most it may take, to fit it to that. Nothing was written.`});else{let u=Lt({template:T,personObjects:R,budget:a,room:B.room,ask:e.fit,path:re});ge={applied:!0,fit:u};for(let p of Fs(u,e.target,{applied:!0,...V}))s(p);u.proposal.cannotFit!==void 0?Gt({code:ns,message:`The seed was refused before it wrote anything: it cannot be fitted to ${e.target}: ${u.proposal.cannotFit}. Nothing was written.`}):u.heldBy!=="whole"&&(v=Dt(v,u.proposal),T=Dt(T,u.proposal),re={...re,sentBefore:I()},D=await xt(kt(c,g?.id??f.orgId),T,R,e.target,G?.estimate,m,re,B.room))}}s(Ko(D.check,e.target));let Te;if(G)for(let a of sr(G.estimate))s(a);if(D.refusedFor==="checkpoint")ne(We({code:ve,message:D.refusal??"",...D.checkpointRefusal?{refusal:D.checkpointRefusal}:{}}));else if(D.refusal){if(!e.fit){let a=Ct(D);if(!("unread"in a)){let u=Lt({template:T,personObjects:R,budget:a,room:B.room,path:re});ge={applied:!1,fit:u};for(let p of Fs(u,e.target,{applied:!1,...V}))s(` ${p}`)}}Te={code:D.refusedFor==="apiRequests"?Dn:Mr,message:D.refusal},e.dryRun&&s(` ${Y(Te)}`)}let se=await qo({target:e.target,objects:v.objects,readAutomation:async()=>{let a=j?.automation??A;if(typeof a.unread=="string")throw new Error(a.unread);return a},readLimits:()=>Mn(c)});for(let a of se.lines)s(a);J.gate.line!==void 0&&s(` ${J.gate.line}`);let Ee=se.gate.refusal!==void 0?{code:is,message:se.gate.refusal}:void 0;Ee&&e.dryRun&&s(` ${Y(Ee)}`);let we=J.gate.stop;we&&e.dryRun&&s(` ${Y(we)}`);let Jt=[...U!==void 0?[U]:[],...te,...Qe!==void 0?[Qe]:[],...Te!==void 0?[Te]:[],...Ee!==void 0?[Ee]:[],...we?[we]:[]],[Vt,...Gs]=Jt;!e.dryRun&&Vt!==void 0&&k(Vt,Gs),s(`template: ${Bs(v)} (${v.objects.length} object(s))`);let Zt=e.dryRun?void 0:Yn(ee()),K=Zt?.recorder({runId:Z,targetOrgId:g?.id??e.target,targetAlias:e.target,startedAt:l,...g?{targetOrganizationId:g.id}:{}}),Ye;Vn(K&&{runUser:a=>{Ye=a,K.runUser?.(a)}},()=>c.identity(),"sandforge seed");let q=Zt?.pathOf(Z),oe=new AbortController,et,Js=a=>{et=a,process.stderr.write(`
395
+ `)},d=e.seed??vo(0,Ce+1),l=new Date().toISOString();s(`sandforge seed -> ${e.target}`),s(`seed: ${d} (--seed ${d} draws the same again)`);let f=await $e(e.target),c=pe(f),w=[wt(c)],b=()=>w.reduce((a,u)=>a+u(),0),g=e.dryRun?void 0:await $n(c,e.target,{tool:"sandforge seed",action:"write",readOnly:"--dry-run"}),S=await gs(e.locale,c),y=a=>c.sobject(a).describe(),P=new Map,C=a=>{let u=P.get(a);return u||(u=y(a),P.set(a,u)),u};s(`locale: ${S}${e.locale?"":" (the org's; --locale draws in another)"}`);let K=new Date().toISOString(),k=o??Jo(e.templateId),m;if(r!==void 0){let a=await Ks({query:async u=>(await c.query(u)).records,objectAccess:zt(c),describe:u=>c.sobject(u).describe()},r,e.scenarioSeed);"issues"in a&&(process.stderr.write(`The scenario cannot be compiled: ${a.issues.join("; ")}
396
+ `),process.exit(2)),m=a,k=a.compiled.template;for(let u of Ws(r,a.preparation))s(u)}for(let a of e.relations){let u=a.parents.kind==="generated"?`the ${a.parentObject} records this run writes`:a.parents.kind==="records"?`the ${a.parents.ids.length} ${a.parentObject} records named by id`:`at most ${a.parents.limit} ${a.parentObject} records already in the org`+(a.parents.where?` where ${a.parents.where}`:""),p=e.objects.find(T=>T.objectApiName===a.childObject)?.recordCount;s(` relation ${a.childObject}.${a.lookupField}: up to ${p} record(s), ${na(a.distribution)}, over ${u}`)}let $=[],R=[];if(o!==void 0&&Object.keys(e.recordTypes).length>0){let a=[];for(let u of o.objects){let p=e.recordTypes[u.objectApiName];if(!p){a.push(u);continue}let T=await C(u.objectApiName),D=Qs(u.objectApiName,p,T.recordTypeInfos);"refusal"in D&&(process.stderr.write(`${D.refusal}
397
+ `),process.exit(2)),a.push({...u,fieldRules:[...u.fieldRules,D.rule]})}o={...o,objects:a},k=o}if(o?.objects.some(a=>a.objectApiName===ue)){let a=hs(o,await ps(c));"refusal"in a&&(process.stderr.write(`${a.refusal}
398
+ `),process.exit(2)),k=a.template,R.push(...a.personObjects);for(let u of a.personObjects){let p=` ${u}: the template gives it person account record types: the accounts are written as person accounts, without Name, which the org builds from the two names`;s(p),$.push(p.trim())}}if(!k){let a=[];for(let[u,p]of e.objects.entries()){let T=await C(p.objectApiName),D=e.recordTypes[p.objectApiName],de="business";if(D&&p.objectApiName===ue){let z=Yo(D,await Xo(c));if("refusal"in z&&(process.stderr.write(`${z.refusal}
399
+ `),process.exit(2)),de=z.kind,de==="person"){R.push(ue);let mn=ea(D);s(mn),$.push(mn.trim())}}let ce=T.createable===!1,Ue=T.fields,Se=Vo(ce?Ue.map(z=>({...z,createable:!0})):Ue,p.objectApiName,de);if(D){let z=Qs(p.objectApiName,D,T.recordTypeInfos);"refusal"in z&&(process.stderr.write(`${z.refusal}
400
+ `),process.exit(2)),Se.push(z.rule)}else{let z=ta(p.objectApiName,T.recordTypeInfos);z&&s(z)}s(ce?` ${p.objectApiName}: the user this seed runs as may not create its records: skipped (give that user Create on it in a permission set)`:` ${p.objectApiName}: ${Se.map(z=>z.fieldApiName).join(", ")||"(none)"}`),a.push({objectApiName:p.objectApiName,recordCount:p.recordCount,fieldRules:Se,excludedFields:[],insertOrder:u,batchSize:e.batchSize})}k={id:`cli-${Date.now()}`,name:"sandforge seed",description:"Headless run",version:1,strategy:"faker",objects:a,...e.relations.length>0?{relations:e.relations}:{},tags:["cli"],createdAt:K,updatedAt:K}}for(let a of Object.keys(e.fit?.caps?.objects??{}))k.objects.some(u=>u.objectApiName===a)||(process.stderr.write(`--fit-cap ${a}: the seed writes no ${a}.
401
+ `),process.exit(2));let A=await Te(c).read(e.target,k.objects.map(a=>a.objectApiName)).catch(a=>({unread:a instanceof Error?a.message:String(a)})),B=Rs(k,m!==void 0),M=(a,u=[])=>{throw e.json&&process.stdout.write(In({tool:"sandforge-seed",target:e.target,elapsedMs:Z(n)},a,u)),new Error([a,...u].map(Ae).join(`
402
+ `))},x,q;if(e.muteAutomation)try{x=await At(async()=>$t(c),A,{writes:B});for(let a of me(x.muted,e.target))s(` ${a}`)}catch(a){if(!je(a))throw a;q=a.refusal,e.dryRun&&s(` ${ee(a.refusal)}`)}let j=await ks(k,A,Ye(C).unset),O=Ss(A,x?.plan,B,j),F={...O.unread!==void 0?{roomUnread:O.unread}:{},muted:(x?.plan?.assign.length??0)>0},L=e.runId??`sandforge-seed-${$o()}`,W=e.checkpointFirst?yr({module:"seed",operationId:L,request:e.checkpointFirst,session:f,org:br(f,g??await ve(c)),connect:a=>{let u=pe(a);return w.push(wt(u)),u},journalDir:te(),say:s,own:{runId:L}}):void 0,H,G=[],le=a=>{let u={code:Oe,message:a};G.push(u),e.dryRun&&s(` ${ee(u)}`)},ge=k.objects.filter(a=>a.recordCount>0);if(W&&ge.length>0){let a={written:ge.map(u=>u.objectApiName),running:O.running??{firing:[]}};try{H={ask:a,estimate:await W.scope(a)}}catch(u){le(Xn(u))}}let Q=await Kn({read:A,...x?.plan?{plan:x.plan}:{},writes:B,readDeliverability:async()=>vn(g??await ve(c))?Bn:zn(c),accepted:e.acceptEmails===!0,target:e.target,run:"seed",keepsAddresses:!0,mayMute:e.muteAutomation!==!0&&He("--mute-automation")}),we=rr(Q.ofRun),h={...we,...Wn(x?.plan)},v=zt(c),E=await ms(k,v),I=()=>b()-(we.deliverability??0),be=Ye(C),X=await Yr(E,{describeCreateableFields:be.createable,describeRequiredFields:Bt(be,R)}),ne={duplicateRules:dr(A),slices:X,bulkThreshold:ft.bulk.threshold,typedFirst:e.dryRun,sentBefore:I()},re=g?.id??f.orgId,_=await Dt(jt(c,re),E,R,e.target,H?.estimate,h,ne,O.room),ye,rt,Yt=a=>{rt=a,e.dryRun&&s(` ${ee(a)}`)};if(e.fit&&_.refusedFor!=="checkpoint"&&G.length===0){let a=Lt(_,e.fit.withinMB);if("unread"in a)Yt({code:bs,message:`The seed was refused before it wrote anything: it cannot be fitted to ${e.target}, whose data storage left could not be read (${a.unread}): give --fit-within <MB>, the most it may take, to fit it to that. Nothing was written.`});else{let u=Wt({template:E,personObjects:R,budget:a,room:O.room,ask:e.fit,path:ne});ye={applied:!0,fit:u};for(let p of Xs(u,e.target,{applied:!0,...F}))s(p);u.proposal.cannotFit!==void 0?Yt({code:ys,message:`The seed was refused before it wrote anything: it cannot be fitted to ${e.target}: ${u.proposal.cannotFit}. Nothing was written.`}):u.heldBy!=="whole"&&(k=Kt(k,u.proposal),E=Kt(E,u.proposal),ne={...ne,sentBefore:I()},_=await Dt(jt(c,re),E,R,e.target,H?.estimate,h,ne,O.room))}}s(oa(_.check,e.target));let Fe;if(H)for(let a of Rr(H.estimate))s(a);if(_.refusedFor==="checkpoint")le(Qe({code:Oe,message:_.refusal??"",..._.checkpointRefusal?{refusal:_.checkpointRefusal}:{}}));else if(_.refusal){if(!e.fit){let a=Lt(_);if(!("unread"in a)){let u=Wt({template:E,personObjects:R,budget:a,room:O.room,path:ne});ye={applied:!1,fit:u};for(let p of Xs(u,e.target,{applied:!1,...F}))s(` ${p}`)}}Fe={code:_.refusedFor==="apiRequests"?Yn:ns,message:_.refusal},e.dryRun&&s(` ${ee(Fe)}`)}let se=await aa({target:e.target,objects:k.objects,readAutomation:async()=>{let a=x?.automation??A;if(typeof a.unread=="string")throw new Error(a.unread);return a},readLimits:()=>tr(c)});for(let a of se.lines)s(a);Q.gate.line!==void 0&&s(` ${Q.gate.line}`);let Ne=se.gate.refusal!==void 0?{code:$s,message:se.gate.refusal}:void 0;Ne&&e.dryRun&&s(` ${ee(Ne)}`);let Re=Q.gate.stop;Re&&e.dryRun&&s(` ${ee(Re)}`);let en=[...q!==void 0?[q]:[],...G,...rt!==void 0?[rt]:[],...Fe!==void 0?[Fe]:[],...Ne!==void 0?[Ne]:[],...Re?[Re]:[]],[tn,...co]=en;!e.dryRun&&tn!==void 0&&M(tn,co),s(`template: ${so(k)} (${k.objects.length} object(s))`);let st=e.dryRun?void 0:mr(te()),J=st?.recorder({runId:L,targetOrgId:g?.id??e.target,targetAlias:e.target,startedAt:l,...g?{targetOrganizationId:g.id}:{}}),ot;ur(J&&{runUser:a=>{ot=a,J.runUser?.(a)}},()=>c.identity(),"sandforge seed");let V=st?.pathOf(L),oe=new AbortController,at,uo=a=>{at=a,process.stderr.write(`
403
403
  interrupted: the seed stops before its next call to the org, and says what it wrote
404
- `),oe.abort()},xe=at,Ht=new Map,Xt=!1,Vs=vr({conn:c,bulkThreshold:xe.bulk.threshold,bulkManager:new vn(xe.bulk.maxConcurrentJobs),retry:new kr({retryConfig:xe.retry,signal:oe.signal}),signal:oe.signal,label:"sandforge seed",log:a=>s(` ${a}`),onProgress:(a,u,p)=>{let E=u>0?Math.floor(a/u*10):10;(Ht.get(p)??-1)>=E||(Ht.set(p,E),s(` ${p}: ${a} of ${u}`))},...K?{calls:{sending:(a,u,p)=>K.sending(a,u,p),answered:(a,u)=>K.answered(a,u)}}:{}}),Ce=e.dryRun?xr():void 0,Zs=0,Hs=async(a,u,p,E)=>{if(e.dryRun){s(` [dry-run] ${u}: ${p.length} record(s) `+zo(p.length,xe.bulk.threshold,Fr(re.duplicateRules,u)));let de=p.map(()=>`dry-${Zs++}`);return Ce?.inserted(u,p,de),{successIds:de,errors:[],rows:de.map(_e=>({id:_e}))}}p.length>0&&(Xt=!0);let N=await Vs(a,u,p,E);return K?.note(u,N.successIds),s(` ${u}: ${N.successIds.length} written, ${N.errors.length} refused`+(N.stopped?", stopped":"")),N},ae=Je(a=>c.sobject(a).describe()),Qt={},Xs=Bo({readExistingParentIds:(a,u,p)=>Tr(c,a,u,p),readPresentParentIds:(a,u)=>Er(c,a,u),describeKeyPrefix:ae.keyPrefix,describeCreateableFields:ae.createable,describeVisibleFields:ae.visible,describeComputedFields:ae.computed,describePicklistValues:ae.picklistValues,describeFieldLengths:ae.lengths,describeRequiredFields:Ft(ae,R),objectAccess:$,insert:Hs,...Ce?{readTarget:Ce.readTarget,update:async(a,u,p)=>(s(` [dry-run] ${u}: ${p.length} record(s) the platform writes with their opportunity, given the fields generated for them (REST update)`),Ce.update(a,u,p))}:Pr(c),seed:d,locale:S,signal:oe.signal,...h?{onRowIds:(a,u)=>{a==="Case"&&Object.assign(Qt,u)}}:{},...h&&!e.dryRun?{knowledge:es({org:c,plan:{publish:!0,links:h.compiled.closedCaseArticles},...K?{journal:K}:{},signal:oe.signal})}:{}});s(e.dryRun?`
404
+ `),oe.abort()},_e=ft,nn=new Map,rn=!1,lo=Mr({conn:c,bulkThreshold:_e.bulk.threshold,bulkManager:new xn(_e.bulk.maxConcurrentJobs),retry:new Lr({retryConfig:_e.retry,signal:oe.signal}),signal:oe.signal,label:"sandforge seed",log:a=>s(` ${a}`),onProgress:(a,u,p)=>{let T=u>0?Math.floor(a/u*10):10;(nn.get(p)??-1)>=T||(nn.set(p,T),s(` ${p}: ${a} of ${u}`))},...J?{calls:{sending:(a,u,p)=>J.sending(a,u,p),answered:(a,u)=>J.answered(a,u)}}:{}}),De=e.dryRun?Vr():void 0,fo=0,sn=e.dryRun?Hn(async a=>[...await xe(Xt(c))(a)],Zn(c),Qn(c),{reads:!0}):void 0,on=new Set,po=async(a,u,p,T)=>{if(e.dryRun){if(s(` [dry-run] ${u}: ${p.length} record(s) `+sa(p.length,_e.bulk.threshold,Xr(ne.duplicateRules,u))),sn&&!on.has(u)){on.add(u);let ce=Jn(p),Ue=ce.length>0?await sn([u]).catch(()=>[]):[];for(let Se of Vn(Ue,ce))s(` [dry-run] ${u}: ${Se}`)}let de=p.map(()=>`dry-${fo++}`);return De?.inserted(u,p,de),{successIds:de,errors:[],rows:de.map(ce=>({id:ce}))}}p.length>0&&(rn=!0);let D=await lo(a,u,p,T);return J?.note(u,D.successIds),s(` ${u}: ${D.successIds.length} written, ${D.errors.length} refused`+(D.stopped?", stopped":"")),D},ae=Ye(a=>c.sobject(a).describe()),an={},ho=ra({readExistingParentIds:(a,u,p)=>Gr(c,a,u,p),readPresentParentIds:(a,u)=>Jr(c,a,u),describeKeyPrefix:ae.keyPrefix,describeCreateableFields:ae.createable,describeVisibleFields:ae.visible,describeComputedFields:ae.computed,describePicklistValues:ae.picklistValues,describeFieldLengths:ae.lengths,describeRequiredFields:Bt(ae,R),objectAccess:v,insert:po,...De?{readTarget:De.readTarget,update:async(a,u,p)=>(s(` [dry-run] ${u}: ${p.length} record(s) the platform writes with their opportunity, given the fields generated for them (REST update)`),De.update(a,u,p))}:Hr(c),seed:d,locale:S,signal:oe.signal,...m?{onRowIds:(a,u)=>{a==="Case"&&Object.assign(an,u)}}:{},...m&&!e.dryRun?{knowledge:ws({org:c,plan:{publish:!0,links:m.compiled.closedCaseArticles},...J?{journal:J}:{},signal:oe.signal})}:{}});s(e.dryRun?`
405
405
  executing\u2026 (DRY-RUN)`:`
406
- executing\u2026 (REAL)`),q!==void 0&&s(`run file: ${q} (--remove ${q} takes back what the run creates)`);let Qs=e.dryRun?()=>{}:Be(Js),F,tt,Yt=a=>{tt=a instanceof Error?a.message:String(a)},ie=j?.muted,nt,rt,en=async()=>{!H||!nt||rt||(rt=await ar(H,nt,Xt,e.target,s))};try{if(!e.dryRun&&H&&G){let p=G,E=await Ln(()=>H.take(p.ask,p.estimate,{signal:oe.signal}));if("stop"in E){E.stop.code===ve&&k({code:ve,message:We(E.stop)}),process.stderr.write(`${We(E.stop)}
407
- `),ft(Ue(et??"SIGINT"));return}nt=E.checkpoint,K?.checkpoint?.(E.checkpoint);for(let N of or(E.checkpoint,e.target,e.muteAutomation===!0))s(N)}let a=!e.dryRun&&j?.prepared?await j.prepared.acquire(Z).catch(p=>{if(!ke(p))throw p;return k(p.refusal)}):void 0;a&&(ie=a.outcome);let u=a?J.afterLease(a.outcome,e.acceptEmails===!0):void 0;if(a&&u){ie=await a.release();for(let p of fe(ie,e.target))s(p);k(u)}F=await Xs.execute(v,e.target,Z).finally(async()=>{if(a){ie=await a.release();for(let p of fe(ie,e.target))s(p)}}),ie&&!e.dryRun&&(F={...F,mutedAutomation:ie}),await en()}catch(a){throw await K?.end({status:"failure",finishedAt:new Date().toISOString(),objectResults:[]}).catch(Yt),await en(),q!==void 0&&qt(q)&&process.stderr.write(`the seed stopped on an error; what it created is kept in ${q}, and --remove ${q} takes it back
408
- `),a}finally{Qs()}await K?.end({finishedAt:new Date().toISOString(),status:F.status,...F.cancelled?{cancelled:!0}:{},objectResults:F.objectResults}).catch(Yt),tt!==void 0&&process.stderr.write(`what the run created could not all be written to ${q??"its file"} (${tt}): --remove takes it back from the --json summary
409
- `);let Q=q!==void 0&&qt(q)?q:void 0,Pe=h&&r&&Q!==void 0?await Ts({journalDir:ee(),runId:Z,pack:r,compiled:h.compiled,options:h.options,caseIds:Qt}):void 0,tn=Pe?.companion!==void 0?await Ve(Ze(Ks(c))).catch(()=>{}):void 0,nn=W(n),Ne=oe.signal.aborted;ft(Ne?Ue(et??"SIGINT"):wn(F.status,e.failOnPartial));let st=F.objectResults.reduce((a,u)=>a+u.createdIds.length,0),Fe=!e.dryRun&&st>0?g?.id??await qs(c):void 0;Fe!==void 0&&mt({action:"seed_execute",orgId:Fe,objects:F.objectResults.map(a=>({...gt(a.objectApiName),created:a.createdIds.length}))});let rn=e.dryRun?G?.estimate:rt,sn=se.gate.refusal??we?.message,Ys=Jt;if(e.json){process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",target:e.target,...Fe?{targetOrgId:Fe}:{},dryRun:e.dryRun,seed:d,startedAt:l,finishedAt:new Date().toISOString(),...O.length>0?{notes:O}:{},emails:{checks:se.gate.checks,...sn!==void 0?{refusal:sn}:{},...se.gate.unknown?{unknown:se.gate.unknown}:{},...J.gate.deliverability?{deliverability:J.gate.deliverability}:{}},...e.dryRun?Wo(T,R,D,w()):{apiRequests:zs(D,w())},...ge?{fit:Vo(ge.fit,ge.applied,e.fit)}:{},...e.dryRun?Fn(j):{},...rn?{checkpoint:rn}:{},...yn(Ys),result:Ye!==void 0?{...F,runUserId:Ye}:F,...Q?{runFile:Q}:{},...h&&r?{scenario:{packId:r.id,options:h.options,tests:h.compiled.tests.length,...Pe??{},...tn?.kind==="no-agent"?{agents:"none"}:{}}}:{},elapsedMs:nn,...Ne?{interrupted:!0}:{}},null,2)}
410
- `),Ne&&process.stderr.write(`${Ds(Q)}
406
+ executing\u2026 (REAL)`),V!==void 0&&s(`run file: ${V} (--remove ${ke(V)} takes back what the run creates)`);let mo=e.dryRun?()=>{}:qe(uo),U,it,dn=a=>{it=a instanceof Error?a.message:String(a)},ie=x?.muted,dt,ct,cn=async()=>{!W||!dt||ct||(ct=await kr(W,dt,rn,e.target,s))};try{if(!e.dryRun&&W&&H){let p=H,T=await er(()=>W.take(p.ask,p.estimate,{signal:oe.signal}));if("stop"in T){T.stop.code===Oe&&M({code:Oe,message:Qe(T.stop)}),process.stderr.write(`${Qe(T.stop)}
407
+ `),bt(We(at??"SIGINT"));return}dt=T.checkpoint,J?.checkpoint?.(T.checkpoint);for(let D of Sr(T.checkpoint,e.target,e.muteAutomation===!0))s(D)}let a=!e.dryRun&&x?.prepared?await x.prepared.acquire(L).catch(p=>{if(!je(p))throw p;return M(p.refusal)}):void 0;a&&(ie=a.outcome);let u=a?Q.afterLease(a.outcome,e.acceptEmails===!0):void 0;if(a&&u){ie=await a.release();for(let p of me(ie,e.target))s(p);M(u)}!e.dryRun&&re!==void 0&&Pn({action:"seed_execute",orgId:re,operationId:L},{mb:_.check.estimateMB,..._.rowBytes?{rowBytes:_.rowBytes}:{}}),U=await ho.execute(k,e.target,L).finally(async()=>{if(a){ie=await a.release();for(let p of me(ie,e.target))s(p)}}),ie&&!e.dryRun&&(U={...U,mutedAutomation:ie}),await cn()}catch(a){if(await J?.end({status:"failure",finishedAt:new Date().toISOString(),objectResults:[]}).catch(dn),!e.dryRun&&re!==void 0){let u=(await st?.get(L).catch(()=>{}))?.created??[];Ge({action:"seed_execute",orgId:re,operationId:L,objects:u.map(({objectApiName:p,ids:T})=>({...Je(p),created:T.length}))})}throw await cn(),V!==void 0&&Ht(V)&&process.stderr.write(`the seed stopped on an error; what it created is kept in ${V}, and --remove ${ke(V)} takes it back
408
+ `),a}finally{mo()}await J?.end({finishedAt:new Date().toISOString(),status:U.status,...U.cancelled?{cancelled:!0}:{},objectResults:U.objectResults}).catch(dn),it!==void 0&&process.stderr.write(`what the run created could not all be written to ${V??"its file"} (${it}): --remove takes it back from the --json summary
409
+ `);let Y=V!==void 0&&Ht(V)?V:void 0,Le=m&&r&&Y!==void 0?await Gs({journalDir:te(),runId:L,pack:r,compiled:m.compiled,options:m.options,caseIds:an}):void 0,un=Le?.companion!==void 0?await et(xe(Xt(c))).catch(()=>{}):void 0,ln=Z(n),Me=oe.signal.aborted;bt(Me?We(at??"SIGINT"):An(U.status,e.failOnPartial));let ut=U.objectResults.reduce((a,u)=>a+u.createdIds.length,0),lt=!e.dryRun&&ut>0?g?.id??await ao(c):void 0,fn=lt??(e.dryRun?void 0:re);fn!==void 0&&Ge({action:"seed_execute",orgId:fn,operationId:L,objects:U.objectResults.map(a=>({...Je(a.objectApiName),created:a.createdIds.length}))});let pn=e.dryRun?H?.estimate:ct,hn=se.gate.refusal??Re?.message,go=en;if(e.json){process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",target:e.target,...lt?{targetOrgId:lt}:{},dryRun:e.dryRun,seed:d,startedAt:l,finishedAt:new Date().toISOString(),...$.length>0?{notes:$}:{},emails:{checks:se.gate.checks,...hn!==void 0?{refusal:hn}:{},...se.gate.unknown?{unknown:se.gate.unknown}:{},...Q.gate.deliverability?{deliverability:Q.gate.deliverability}:{}},...e.dryRun?ia(E,R,_,b()):{apiRequests:oo(_,b())},...ye?{fit:ua(ye.fit,ye.applied,e.fit)}:{},...e.dryRun?qn(x):{},...pn?{checkpoint:pn}:{},...On(go),result:ot!==void 0?{...U,runUserId:ot}:U,...Y?{runFile:Y}:{},...m&&r?{scenario:{packId:r.id,options:m.options,tests:m.compiled.tests.length,...Le??{},...un?.kind==="no-agent"?{agents:"none"}:{}}}:{},elapsedMs:ln,...Me?{interrupted:!0}:{}},null,2)}
410
+ `),Me&&process.stderr.write(`${eo(Y)}
411
411
  `);return}s(`
412
- status: ${String(F.status??"unknown")}`),s(`created: ${String(F.totalRecordsCreated??0)}`);for(let a of F.objectResults??[]){s(` ${a.objectApiName}: ${a.recordsCreated} created, ${a.recordsFailed} failed`);let u=Cr(a.writtenByThePlatform);u!==void 0&&s(` ${u}`);for(let p of Qo(a.errors??[]))s(` ${p}`)}for(let a of Is(F.knowledge))s(a);if(s(`seed: ${d}`),!e.dryRun&&st>0&&s(`
413
- created ${st} record(s) in ${e.target}: `+(Q!==void 0?`--remove ${Q} takes them back`:"run with --json and save the summary to a file, and --remove takes them back from it")),r&&Pe&&Q!==void 0)for(let a of Xo(Pe,tn,Q,e.target,r))s(a);if(Ne){process.stderr.write(`${Ds(Q)}
412
+ status: ${String(U.status??"unknown")}`),s(`created: ${String(U.totalRecordsCreated??0)}`);for(let a of U.objectResults??[]){s(` ${a.objectApiName}: ${a.recordsCreated} created, ${a.recordsFailed} failed`);let u=Zr(a.writtenByThePlatform);u!==void 0&&s(` ${u}`);for(let p of ha(a.errors??[]))s(` ${p}`)}for(let a of qs(U.knowledge))s(a);if(s(`seed: ${d}`),!e.dryRun&&ut>0&&s(`
413
+ created ${ut} record(s) in ${e.target}: `+(Y!==void 0?`--remove ${ke(Y)} takes them back`:"run with --json and save the summary to a file, and --remove takes them back from it")),r&&Le&&Y!==void 0)for(let a of pa(Le,un,Y,e.target,r))s(a);if(Me){process.stderr.write(`${eo(Y)}
414
414
  `);return}s(`
415
- done in ${nn}ms`)}function Ks(t){return{query:async n=>t.tooling.query(n),queryMore:async n=>t.tooling.queryMore(n)}}async function Ho(t){let n=le(await ye(t));return{tooling:Ks(n),organizationId:()=>qs(n)}}function Xo(t,n,e,r,o){let i=`
416
- scenario ${t.packId}: ${t.openCasesWritten} of its ${t.openCases} open case(s) written, which its ${t.tests} test(s) are about`;return t.unkept!==void 0?[i,` the ids of its cases could not be kept (${t.unkept}): no test file can be written from this run`]:t.companion===void 0?[i," no open case was written: no test file can be written from this run"]:n?.kind==="no-agent"?[i,` ${n.message}`,` ${Bt(e,r,o)}`]:[i," the test file is written from this run, never deployed nor run:",` ${Bt(e,r,o)}`]}var _s=5;function Qo(t){let n=fn(t),e=n.slice(0,_s).flatMap(o=>{let i=o.fields.length>0?` (${o.fields.join(", ")})`:"",s=`${o.count} \xD7 ${o.code??o.example}${i}`;return o.code===null?[s]:[s,` ${o.example}`]}),r=n.length-_s;return r>0?[...e,`and ${r} other reason(s)`]:e}function Ds(t){return t!==void 0?`interrupted: the seed stopped before it was through; ${t} keeps what it wrote, and --remove ${t} takes it back`:"interrupted: the seed stopped before it was through; the summary above says what it wrote, and --remove takes it back from that summary saved to a file (--json)"}async function qs(t){try{let e=(await t.query("SELECT Id FROM Organization LIMIT 1")).records[0]?.Id;return typeof e=="string"?e:void 0}catch{return}}var Kt=new Set(["--remove","--target","--preview","--include-changed","--accept-automation","--mute-automation","--sweep","--sweep-list",...mr,"--leave-undeletable","--json"]),Yo=new Set(["--remove","--target"]);function ea(t){let n=t.slice(2);for(let s=0;s<n.length;s++){let d=n[s];if(Yo.has(d)){s++;continue}d==="--dry-run"&&(process.stderr.write(`--remove does not take --dry-run: a removal that did not read it would delete for real. --preview says what the removal would do, and writes nothing. Run with --help.
417
- `),process.exit(2)),Kt.has(d)||(process.stderr.write(`--remove takes --target, --preview, --include-changed, --accept-automation, --mute-automation, --sweep, --sweep-late, --sweep-untied, --sweep-list, --leave-undeletable and --json, not "${d}". Run with --help.
418
- `),process.exit(2))}let e=s=>{let d=n.indexOf(s);return d>=0&&d+1<n.length?n[d+1]:void 0},r=e("--remove"),o=e("--target");(!r||!o||Kt.has(r)||Kt.has(o))&&(process.stderr.write(`--remove takes the file a run printed its --json summary to, or the run file it named as it began, or its run id, and --target the org the run wrote to. Run with --help.
415
+ done in ${ln}ms`)}function Xt(t){return{query:async n=>t.tooling.query(n),queryMore:async n=>t.tooling.queryMore(n)}}async function fa(t){let n=pe(await $e(t));return{tooling:Xt(n),organizationId:()=>ao(n)}}function pa(t,n,e,r,o){let i=`
416
+ scenario ${t.packId}: ${t.openCasesWritten} of its ${t.openCases} open case(s) written, which its ${t.tests} test(s) are about`;return t.unkept!==void 0?[i,` the ids of its cases could not be kept (${t.unkept}): no test file can be written from this run`]:t.companion===void 0?[i," no open case was written: no test file can be written from this run"]:n?.kind==="no-agent"?[i,` ${n.message}`,` ${Jt(e,r,o)}`]:[i," the test file is written from this run, never deployed nor run:",` ${Jt(e,r,o)}`]}var Ys=5;function ha(t){let n=Rn(t),e=n.slice(0,Ys).flatMap(o=>{let i=o.fields.length>0?` (${o.fields.join(", ")})`:"",s=`${o.count} \xD7 ${o.code??o.example}${i}`;return o.code===null?[s]:[s,` ${o.example}`]}),r=n.length-Ys;return r>0?[...e,`and ${r} other reason(s)`]:e}function eo(t){return t!==void 0?`interrupted: the seed stopped before it was through; ${t} keeps what it wrote, and --remove ${ke(t)} takes it back`:"interrupted: the seed stopped before it was through; the summary above says what it wrote, and --remove takes it back from that summary saved to a file (--json)"}async function ao(t){try{let e=(await t.query("SELECT Id FROM Organization LIMIT 1")).records[0]?.Id;return typeof e=="string"?e:void 0}catch{return}}var Zt=new Set(["--remove","--target","--preview","--include-changed","--accept-automation","--mute-automation","--sweep","--sweep-list",...xr,"--leave-undeletable","--json"]),ma=new Set(["--remove","--target"]);function ga(t){let n=t.slice(2);for(let s=0;s<n.length;s++){let d=n[s];if(ma.has(d)){s++;continue}d==="--dry-run"&&(process.stderr.write(`--remove does not take --dry-run: a removal that did not read it would delete for real. --preview says what the removal would do, and writes nothing. Run with --help.
417
+ `),process.exit(2)),Zt.has(d)||(process.stderr.write(`--remove takes --target, --preview, --include-changed, --accept-automation, --mute-automation, --sweep, --sweep-late, --sweep-untied, --sweep-list, --leave-undeletable and --json, not "${d}". Run with --help.
418
+ `),process.exit(2))}let e=s=>{let d=n.indexOf(s);return d>=0&&d+1<n.length?n[d+1]:void 0},r=e("--remove"),o=e("--target");(!r||!o||Zt.has(r)||Zt.has(o))&&(process.stderr.write(`--remove takes the file a run printed its --json summary to, or the run file it named as it began, or its run id, and --target the org the run wrote to. Run with --help.
419
419
  `),process.exit(2)),n.includes("--sweep")&&n.includes("--sweep-list")&&(process.stderr.write(`--sweep deletes and --sweep-list only lists: give one of them. Run with --help.
420
420
  `),process.exit(2)),n.includes("--preview")&&n.includes("--sweep-list")&&(process.stderr.write(`--preview writes nothing, and --sweep-list lists what a sweep would take: give --preview without it, or with --sweep. Run with --help.
421
- `),process.exit(2));let i=gr(n);return"refusal"in i&&(process.stderr.write(`${i.refusal} Run with --help.
422
- `),process.exit(2)),{summaryPath:r,target:o,includeChanged:n.includes("--include-changed"),sweep:n.includes("--sweep"),sweepList:n.includes("--sweep-list"),...i,json:n.includes("--json"),leaveUndeletable:n.includes("--leave-undeletable"),acceptAutomation:n.includes("--accept-automation"),muteAutomation:n.includes("--mute-automation"),...n.includes("--preview")?{preview:!0}:{}}}var Ls=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,ta=P.object({tool:P.literal("sandforge-seed"),target:P.string().min(1),targetOrgId:P.string().regex(Ls).optional(),dryRun:P.boolean(),startedAt:P.string().min(1).max(40).optional(),finishedAt:P.string().min(1).max(40).optional(),runFile:P.string().min(1).max(4096).optional(),result:P.object({operationId:P.string().min(1).max(200).optional(),status:P.enum(["success","partial","failure"]),objectResults:P.array(P.object({objectApiName:P.string().regex(Us),createdIds:P.array(P.string().regex(Ls)),truncated:P.boolean().optional()}).loose())}).loose()}).loose();function na(t){let n;try{n=JSON.parse(t)}catch{return{refusal:"is not JSON: save the output of a run printed with --json."}}let e=Sn(n,"sandforge-seed");if(e)return{refusal:kn(e)};let r=ta.safeParse(n);if(!r.success){let o=r.error.issues[0];return{refusal:`is not the summary of a sandforge seed run (${o.path.join(".")||"summary"}: ${o.message}).`}}return r.data.dryRun?{refusal:"is the summary of a dry run, which wrote nothing: there is nothing to remove."}:r.data.result.objectResults.some(o=>o.truncated===!0)?{refusal:"names only the first of the records some object created: the rest cannot be told apart from the org\u2019s own."}:{summary:r.data}}function ra(t,n){return Qn({runId:t.result.operationId??"sandforge-seed",targetOrgId:t.target,...t.startedAt!==void 0?{startedAt:t.startedAt}:{},...t.finishedAt!==void 0?{finishedAt:t.finishedAt}:{},status:t.result.status,objectResults:t.result.objectResults},n)}var Ms=3;async function sa(t,n){let e=On(lo(t),""),r;try{r=ze(Ie(t,"utf8"))}catch(i){process.stderr.write(`--remove ${t} cannot be read: ${i instanceof Error?i.message:String(i)}
421
+ `),process.exit(2));let i=Cr(n);return"refusal"in i&&(process.stderr.write(`${i.refusal} Run with --help.
422
+ `),process.exit(2)),{summaryPath:r,target:o,includeChanged:n.includes("--include-changed"),sweep:n.includes("--sweep"),sweepList:n.includes("--sweep-list"),...i,json:n.includes("--json"),leaveUndeletable:n.includes("--leave-undeletable"),acceptAutomation:n.includes("--accept-automation"),muteAutomation:n.includes("--mute-automation"),...n.includes("--preview")?{preview:!0}:{}}}var to=/^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/,wa=N.object({tool:N.literal("sandforge-seed"),target:N.string().min(1),targetOrgId:N.string().regex(to).optional(),dryRun:N.boolean(),startedAt:N.string().min(1).max(40).optional(),finishedAt:N.string().min(1).max(40).optional(),runFile:N.string().min(1).max(4096).optional(),result:N.object({operationId:N.string().min(1).max(200).optional(),status:N.enum(["success","partial","failure"]),objectResults:N.array(N.object({objectApiName:N.string().regex(ro),createdIds:N.array(N.string().regex(to)),truncated:N.boolean().optional()}).loose())}).loose()}).loose();function ba(t){let n;try{n=JSON.parse(t)}catch{return{refusal:"is not JSON: save the output of a run printed with --json."}}let e=Tn(n,"sandforge-seed");if(e)return{refusal:En(e)};let r=wa.safeParse(n);if(!r.success){let o=r.error.issues[0];return{refusal:`is not the summary of a sandforge seed run (${o.path.join(".")||"summary"}: ${o.message}).`}}return r.data.dryRun?{refusal:"is the summary of a dry run, which wrote nothing: there is nothing to remove."}:r.data.result.objectResults.some(o=>o.truncated===!0)?{refusal:"names only the first of the records some object created: the rest cannot be told apart from the org\u2019s own."}:{summary:r.data}}function ya(t,n){return hr({runId:t.result.operationId??"sandforge-seed",targetOrgId:t.target,...t.startedAt!==void 0?{startedAt:t.startedAt}:{},...t.finishedAt!==void 0?{finishedAt:t.finishedAt}:{},status:t.result.status,objectResults:t.result.objectResults},n)}var no=3;async function Ra(t,n){let e=Dn(Oo(t),""),r;try{r=Ve(Pe(t,"utf8"))}catch(i){process.stderr.write(`--remove ${t} cannot be read: ${i instanceof Error?i.message:String(i)}
423
423
  `),process.exit(2)}(!r||r.configId!=="sandforge-seed")&&(process.stderr.write(`--remove ${t} names no run of sandforge seed.
424
424
  `),process.exit(2)),e.pathOf(r.runId)!==t&&(process.stderr.write(`--remove ${t} is the file of the run ${r.runId} under another name: give it as ${e.pathOf(r.runId)}, where what its removals did is kept beside it.
425
425
  `),process.exit(2));let o=await e.get(r.runId)??r;return o.targetOrganizationId===void 0&&o.targetOrgId!==n.target&&(process.stderr.write(`The run wrote to ${o.targetOrgId}, and what it created is removed from that org only: give --target ${o.targetOrgId}.
426
- `),process.exit(2)),{run:o,...o.targetOrganizationId!==void 0?{targetOrgId:o.targetOrganizationId}:{},...o.removal?{earlier:o.removal}:{},updateRemoval:i=>e.updateRemoval(o.runId,i),runs:e,...oa(o)}}function oa(t){let n=Tt(t.runUserId);return n?{runUserId:n}:{}}function aa(t){let n=Tt(t.runUserId),e=ur.safeParse(t.mutedAutomation);return{...n?{runUserId:n}:{},...e.success?{muted:e.data}:{}}}async function ia(t){if(qt(t.summaryPath))return;let n=await Zn(ee()).find(t.summaryPath);if(!n)return;let e=Xn(n,De("cleanup"),t.target);process.stderr.write(`${Re({code:"NOT_KEPT",message:`${Hn(n,e)} Or rewind the org to a checkpoint taken before it (sandforge checkpoint rewind), or empty its objects (sandforge empty), which deletes all their records.`})}
427
- `),process.exit(2)}function da(t,n){let e;try{e=Ie(t.summaryPath,"utf8")}catch(g){process.stderr.write(`--remove ${t.summaryPath} cannot be read: ${g instanceof Error?g.message:String(g)}
428
- `),process.exit(2)}let r=na(e);"refusal"in r&&(process.stderr.write(`--remove ${t.summaryPath} ${r.refusal}
426
+ `),process.exit(2)),{run:o,...o.targetOrganizationId!==void 0?{targetOrgId:o.targetOrganizationId}:{},...o.removal?{earlier:o.removal}:{},updateRemoval:i=>e.updateRemoval(o.runId,i),runs:e,...Sa(o)}}function Sa(t){let n=Pt(t.runUserId);return n?{runUserId:n}:{}}function ka(t){let n=Pt(t.runUserId),e=jr.safeParse(t.mutedAutomation);return{...n?{runUserId:n}:{},...e.success?{muted:e.data}:{}}}async function va(t){if(Ht(t.summaryPath))return;let n=await lr(te()).find(t.summaryPath);if(!n)return;let e=pr(n,Be("cleanup"),t.target);process.stderr.write(`${Ae({code:"NOT_KEPT",message:`${fr(n,e)} Or rewind the org to a checkpoint taken before it (sandforge checkpoint rewind), or empty its objects (sandforge empty), which deletes all their records.`})}
427
+ `),process.exit(2)}function $a(t,n){let e;try{e=Pe(t.summaryPath,"utf8")}catch(g){process.stderr.write(`--remove ${t.summaryPath} cannot be read: ${g instanceof Error?g.message:String(g)}
428
+ `),process.exit(2)}let r=ba(e);"refusal"in r&&(process.stderr.write(`--remove ${t.summaryPath} ${r.refusal}
429
429
  `),process.exit(2));let{summary:o}=r;o.targetOrgId===void 0&&o.target!==t.target&&(process.stderr.write(`The run wrote to ${o.target}, and what it created is removed from that org only: give --target ${o.target}.
430
- `),process.exit(2));let i=Ur(t.summaryPath),s=o.result.operationId??"sandforge-seed",d,l;try{l=Ie(i,"utf8")}catch(g){g?.code!=="ENOENT"&&(process.stderr.write(`${i} cannot be read: ${g instanceof Error?g.message:String(g)}
431
- `),process.exit(2))}if(l!==void 0){let g;try{g=JSON.parse(l)}catch{g=void 0}let S=g?.runId;d=S===s?In(g):void 0,S!==s?n(`${i} is of another run: it is not read, and this removal's takes its place`):d||(process.stderr.write(`${i} does not read as what earlier removals did.
432
- `),process.exit(2))}let f=ra(o,d),c=d??{},b=aa(o.result),w=b.runUserId??zr(o.runFile,s,"sandforge-seed");return{run:f,...o.targetOrgId!==void 0?{targetOrgId:o.targetOrgId}:{},...d?{earlier:d}:{},...b,...w!==void 0?{runUserId:w}:{},updateRemoval:async g=>{c=g(c);let S=`${i}.${process.pid}.tmp`;uo(S,`${JSON.stringify({version:1,runId:f.runId,...c},null,2)}
433
- `),co(S,i)}}}async function Ws(t,n,e,r,o,i){let{earlier:s}=o,d;try{d=await Ae(t).read(n,r.created.map(f=>f.objectApiName))}catch(f){d={error:f instanceof Error?f.message:String(f)}}let l=Sr({otherRuns:await Rr({organizationId:e,alias:n,span:yr(r),own:{runId:r.runId,ids:r.created.flatMap(f=>f.ids)}}),...o.muted?{muted:o.muted}:{},...s?.removalSpans?{removalSpans:s.removalSpans}:{},...s?.madeEarlier?{made:s.madeEarlier}:{},...s?.lateEarlier?{late:s.lateEarlier}:{}});return Or(Se(t,"sandforge seed --sweep"),r.created,d,i,void 0,[],{...o.runUserId?{runUserId:o.runUserId}:{},ties:l})}async function ca(t=process.argv){let n=Date.now(),e=ea(t),r=m=>{process[e.json?"stderr":"stdout"].write(`${m}
434
- `)},o=Nt(e.summaryPath,ee(),Ot);o===void 0&&await ia(e);let i=o!==void 0?await sa(o,e):da(e,r),{earlier:s}=i,d=i.run;if(jn(d)&&k({code:bn,message:`The run is still writing, in process ${d.writer?.pid??"?"}: remove it once it has ended. Nothing was deleted.`}),e.preview)return pa(e,i,d,r,n);let l,f=(m,$,T,I,me)=>{if(e.json){process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",action:"remove",summary:e.summaryPath,target:e.target,includeChanged:e.includeChanged,result:{status:m,planned:T,objects:$,...I?{sweep:I}:{},...l?{sweepListing:l}:{},...me?{mutedAutomation:me}:{}},elapsedMs:W(n)},null,2)}
435
- `);for(let X of Et($,e))r(X);return}for(let X of I?hr(I):[])r(X);for(let X of Br(m,$))r(X);for(let X of Et($,e))r(X);r(`
436
- done in ${W(n)}ms`)},c=i.runs!==void 0&&(d.jobs??[]).length>0;if(Ke(d).length===0&&!c&&!e.sweep&&!e.sweepList){r(s?.undo?`what the run created was removed already, on ${s.undo.removedAt}`:"The run created nothing: there is nothing of it to remove."),f("success",[],0);return}let b=await ye(e.target),w=le(b),g=await be(w),S=e.sweepList?void 0:Pt(e.target,g,"sandforge seed");if(S&&k({code:"PRODUCTION_TARGET",message:S}),i.targetOrgId!==void 0&&i.targetOrgId.slice(0,15)!==g.id.slice(0,15)&&k({code:pt,message:`${e.target} is not the org the run wrote to (${i.targetOrgId}), and what it created is removed from that org only. Nothing was deleted.`}),c&&i.runs){let m=i.runs,$=await Ar(m,d,w,()=>Se(w,"sandforge seed --remove").serverTime());for(let T of Kr($,e.target))r(T);$.some(T=>T.answered)&&(d=await m.get(d.runId)??d)}let y=Ke(d),x=m=>Ws(w,e.target,g.id,d,i,m);if(e.sweepList){let m=await jt(Ge(w,"sandforge seed --sweep-list"),await x(),s?.removalSpans??[]);for(let $ of je(m,e.target,e,!0))r($);e.json?process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",action:"sweep-list",summary:e.summaryPath,target:e.target,listing:m,elapsedMs:W(n)},null,2)}
430
+ `),process.exit(2));let i=rs(t.summaryPath),s=o.result.operationId??"sandforge-seed",d,l;try{l=Pe(i,"utf8")}catch(g){g?.code!=="ENOENT"&&(process.stderr.write(`${i} cannot be read: ${g instanceof Error?g.message:String(g)}
431
+ `),process.exit(2))}if(l!==void 0){let g;try{g=JSON.parse(l)}catch{g=void 0}let S=g?.runId;d=S===s?Ln(g):void 0,S!==s?n(`${i} is of another run: it is not read, and this removal's takes its place`):d||(process.stderr.write(`${i} does not read as what earlier removals did.
432
+ `),process.exit(2))}let f=ya(o,d),c=d??{},w=ka(o.result),b=w.runUserId??os(o.runFile,s,"sandforge-seed");return{run:f,...o.targetOrgId!==void 0?{targetOrgId:o.targetOrgId}:{},...d?{earlier:d}:{},...w,...b!==void 0?{runUserId:b}:{},updateRemoval:async g=>{c=g(c);let S=`${i}.${process.pid}.tmp`;jo(S,`${JSON.stringify({version:1,runId:f.runId,...c},null,2)}
433
+ `,{mode:St}),Cn(S,St),Ao(S,i)}}}async function io(t,n,e,r,o,i){let{earlier:s}=o,d;try{d=await Te(t).read(n,r.created.map(f=>f.objectApiName))}catch(f){d={error:f instanceof Error?f.message:String(f)}}let l=Dr({otherRuns:await _r({organizationId:e,alias:n,span:Nr(r),own:{runId:r.runId,ids:r.created.flatMap(f=>f.ids)}}),...o.muted?{muted:o.muted}:{},...s?.removalSpans?{removalSpans:s.removalSpans}:{},...s?.madeEarlier?{made:s.madeEarlier}:{},...s?.lateEarlier?{late:s.lateEarlier}:{}});return Wr(he(t,"sandforge seed --sweep"),r.created,d,i,void 0,[],{...o.runUserId?{runUserId:o.runUserId}:{},ties:l})}async function Aa(t=process.argv){let n=Date.now(),e=ga(t),r=h=>{process[e.json?"stderr":"stdout"].write(`${h}
434
+ `)},o=Ut(e.summaryPath,te(),xt);o===void 0&&await va(e);let i=o!==void 0?await Ra(o,e):$a(e,r),{earlier:s}=i,d=i.run;if(_n(d)&&q({code:jn,message:`The run is still writing, in process ${d.writer?.pid??"?"}: remove it once it has ended. Nothing was deleted.`}),e.preview)return Ta(e,i,d,r,n);let l,f=(h,v,E,I,be)=>{if(e.json){process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",action:"remove",summary:e.summaryPath,target:e.target,includeChanged:e.includeChanged,result:{status:h,planned:E,objects:v,...I?{sweep:I}:{},...l?{sweepListing:l}:{},...be?{mutedAutomation:be}:{}},elapsedMs:Z(n)},null,2)}
435
+ `);for(let X of Ft(v,e))r(X);return}for(let X of I?Er(I):[])r(X);for(let X of ss(h,v))r(X);for(let X of Ft(v,e))r(X);r(`
436
+ done in ${Z(n)}ms`)},c=i.runs!==void 0&&(d.jobs??[]).length>0;if(Ze(d).length===0&&!c&&!e.sweep&&!e.sweepList){r(s?.undo?`what the run created was removed already, on ${s.undo.removedAt}`:"The run created nothing: there is nothing of it to remove."),f("success",[],0);return}let w=await $e(e.target),b=pe(w),g=await ve(b),S=e.sweepList?void 0:Mt(e.target,g,"sandforge seed");if(S&&q({code:"PRODUCTION_TARGET",message:S}),i.targetOrgId!==void 0&&i.targetOrgId.slice(0,15)!==g.id.slice(0,15)&&q({code:yt,message:`${e.target} is not the org the run wrote to (${i.targetOrgId}), and what it created is removed from that org only. Nothing was deleted.`}),c&&i.runs){let h=i.runs,v=await Ur(h,d,b,()=>he(b,"sandforge seed --remove").serverTime());for(let E of as(v,e.target))r(E);v.some(E=>E.answered)&&(d=await h.get(d.runId)??d)}let y=Ze(d),P=h=>io(b,e.target,g.id,d,i,h);if(e.sweepList){let h=await Et(Xe(b,"sandforge seed --sweep-list"),await P(),s?.removalSpans??[]);for(let v of Ee(h,e.target,e,!0))r(v);e.json?process.stdout.write(`${JSON.stringify({tool:"sandforge-seed",action:"sweep-list",summary:e.summaryPath,target:e.target,listing:h,elapsedMs:Z(n)},null,2)}
437
437
  `):r(`
438
- done in ${W(n)}ms`),m.refusal!==void 0&&process.exit(Ms);return}r(`sandforge seed --remove ${e.summaryPath} from ${e.target}`);for(let{objectApiName:m,ids:$}of y)r(` ${m}: ${$.length} to remove`);y.length===0&&r("nothing left of the run to remove"),e.sweep&&r(`before them, a sweep deletes what the target's automation made for the run, as the run's user, tied to its records \u2014 run ${fr("--sweep-list")} to see what`);let C=new AbortController,z=Be(()=>C.abort()),v=s??{},h=e.sweep?Jn(Ge(w,"sandforge seed --sweep",C.signal),await x(C.signal),{includeChanged:e.includeChanged,removalSpans:v.removalSpans??[],...wr(e),approve:async m=>{l=m,r("");for(let $ of je(m,e.target,e))r($)}}):void 0;await h?.ask();let O=pr(h,l);if(O){l=O,r("");for(let m of je(O,e.target,e))r(m)}let R=[...new Set(y.map(({objectApiName:m})=>m))],A=ct({setToDraft:bt(R),delete:yt(R,[],{userKept:i.runUserId!==void 0})},h?.takes??[]),M=A.delete??[];function k(m){return process.stderr.write(`${Re(m)}
439
- `),e.json&&process.stdout.write(ht({tool:"sandforge-seed",...e.preview?{action:"remove-preview"}:{},summary:e.summaryPath,target:e.target,elapsedMs:W(n)},m)),process.exit(1)}let j=m=>(z(),k(m)),U;if(M.length>0&&!C.signal.aborted){let m=await Ae(w).read(e.target,M);r("");for(let I of $t(m,e.target,A))r(I);if(e.muteAutomation)try{U=await St(async()=>Rt(w),m,{writes:hn(A)});for(let I of fe(U.muted,e.target))r(` ${I}`)}catch(I){if(!ke(I))throw I;j(I.refusal)}let $=U?.automation??m,T=At($,e.target,{steps:A,assign:vt($,ut($,A)),mayMute:U===void 0&&qe("--mute-automation")});T&&!e.acceptAutomation&&j({code:"AUTOMATION_NOT_ACCEPTED",message:T})}let _,B,V=U?.muted,Z=async()=>{!U?.prepared||C.signal.aborted||(B=await U.prepared.acquire(`sandforge seed --remove ${d.runId}`).catch(m=>{if(!ke(m))throw m;return j(m.refusal)}),V=B.outcome)},H=Se(w,"sandforge seed --remove"),G=await jr(H,d.created),te;try{_=await Tn({run:d,org:H,includeChanged:e.includeChanged,...br(h),...i.runUserId?{runUserId:i.runUserId}:{},onUndeletable:dr(e.leaveUndeletable,e.target,m=>{te=m}),beforeFirstWrite:Z,signal:C.signal,store:{updateRemoval:(m,$)=>i.updateRemoval(T=>(v=$(T),v))}})}finally{z();let m=h?.made??new Set,$=h?.late??new Set,T=h?.gone??new Set;if((m.size>0||$.size>0||T.size>0)&&await i.updateRemoval(I=>Ir(I,m,$,T)).catch(I=>{process.stderr.write(`What the sweep found made for the run could not be kept (${I instanceof Error?I.message:String(I)}): a later --sweep may list it as tied to nothing.
440
- `)}),B){V=await B.release();for(let I of fe(V,e.target))r(I)}}V&&(_={..._,result:{..._.result,mutedAutomation:V}}),_.stoppedForUndeletable&&(te&&k(te),process.exit(1));let ne=_.result.status==="cancelled"?{}:await G.take(_.duplicateSets);for(let m of[..._.notes,...ne.note?[ne.note]:[]])process.stderr.write(`${m}
441
- `);let pe=h?.result(),J=An(_.result.status,pe);mt({action:"cleanup_delete",orgId:g.id,objects:_.result.objects.map(m=>({...gt(m.objectApiName),deleted:m.deleted}))});let he=ne.object?[..._.result.objects,ne.object]:_.result.objects;f(J,he,he.reduce((m,$)=>m+$.planned,0),pe,V),J!=="success"&&process.exit(Ms)}var ua="not read by a preview: what the target's automation does as the records go \u2014 a trigger or a flow that deletes, keeps or creates other records \u2014 and what hangs from them, which a removal reads at each object\u2019s turn: a record kept for records that stay is counted with those to delete";function la(t){return`${JSON.stringify({tool:"sandforge-seed",action:"remove-preview",summary:t.summary,target:t.target,includeChanged:t.includeChanged,preview:t.preview,...t.sweepListing?{sweepListing:t.sweepListing}:{},refusals:t.refusals.map(({message:n})=>n),refusalCodes:t.refusals.map(({code:n})=>n),notes:t.notes,elapsedMs:t.elapsedMs},null,2)}
442
- `}function fa(t,n,e,r){let o=s=>t.userNames[s]??s,i=["preview: what a removal would do; nothing was written"];for(let s of t.objects){let d=[s.toDelete>0?`${s.toDelete} to delete`:"",r&&s.changedSince>0?`${s.changedSince} of them changed since the run`:"",s.alreadyGone>0?`${s.alreadyGone} gone already`:"",s.notVisible>0?`${s.notVisible} not visible`:"",s.keptChanged>0?`${s.keptChanged} kept, changed since the run`:"",s.undeletable>0?`${s.undeletable} left, the user may not delete them`:"",s.unread>0?`${s.unread} left, not read`:""].filter(Boolean);i.push(` ${s.objectApiName}: ${d.join(", ")||"nothing"} of ${s.planned}${lr(s)}`);let l=Object.entries(s.changedBy).sort((f,c)=>c[1]-f[1]);l.length>0&&i.push(` last changed by: ${l.map(([f,c])=>`${o(f)} ${c}`).join(" \xB7 ")}`);for(let f of s.reasons)i.push(` ${f}`)}for(let s of n)i.push(Y(s,"a removal"));return[...i,...e]}async function pa(t,n,e,r,o){let i=Ke(e),s=[],d,l=n.runs!==void 0?(e.jobs??[]).length:0;l>0&&s.push(`the run's file names ${l} Bulk API job(s) no line of it answers: a removal reads back what they created first and removes it with the rest; this preview counts only what the file holds`);let f=(k,j)=>{if(s.push(ua),t.json){process.stdout.write(la({summary:t.summaryPath,target:t.target,includeChanged:t.includeChanged,preview:k,refusals:j,notes:s,elapsedMs:W(o),...d?{sweepListing:d}:{}}));return}r("");for(let U of fa(k,j,s,t.includeChanged))r(U);r(`
443
- done in ${W(o)}ms`)};if(r(`sandforge seed --remove ${t.summaryPath} --preview of ${t.target}`),i.length===0&&!t.sweep){s.push(n.earlier?.undo?`what the run created was removed already, on ${n.earlier.undo.removedAt}`:"The run created nothing: there is nothing of it to remove."),f({planned:0,objects:[],userNames:{}},[]);return}let c=await ye(t.target),b=le(c),w=await be(b);if(n.targetOrgId!==void 0&&n.targetOrgId.slice(0,15)!==w.id.slice(0,15)){let k={code:pt,message:`${t.target} is not the org the run wrote to (${n.targetOrgId}): its records are read in that org only. Nothing of the run was read.`};process.stderr.write(`${Re(k)}
444
- `),t.json&&process.stdout.write(ht({tool:"sandforge-seed",action:"remove-preview",summary:t.summaryPath,target:t.target,elapsedMs:W(o)},k)),process.exit(1)}let g=[],S=Pt(t.target,w,"sandforge seed");if(S&&g.push({code:"PRODUCTION_TARGET",message:S}),t.sweep){d=await jt(Ge(b,"sandforge seed --remove --preview --sweep"),await Ws(b,t.target,w.id,e,n),n.earlier?.removalSpans??[]),r("");for(let k of je(d,t.target,t,!0))r(k)}let y=[...new Set(i.map(({objectApiName:k})=>k))],x=ct({setToDraft:bt(y),delete:yt(y,[],{userKept:n.runUserId!==void 0})},d?pn(d,t):[]),C=await Ae(b).read(t.target,x.delete??[]);r("");for(let k of $t(C,t.target,x))r(k);let z=At(C,t.target,{steps:x,assign:vt(C,ut(C,x)),mayMute:!t.muteAutomation&&qe("--mute-automation")});if(z&&!t.acceptAutomation&&g.push({code:"AUTOMATION_NOT_ACCEPTED",message:z}),i.length===0){s.push("nothing left of the run to remove"),f({planned:0,objects:[],userNames:{}},g);return}let v=new AbortController,h,O=Be(k=>{h=k,v.abort()}),R;try{R=await En({run:e,org:Se(b,"sandforge seed --remove --preview"),includeChanged:t.includeChanged,...n.runUserId?{runUserId:n.runUserId}:{},signal:v.signal})}finally{O()}let A=R.outcome.preview;A||(process.stderr.write(`interrupted: the preview stopped before it was through, and wrote nothing
445
- `),process.exit(Ue(h??"SIGINT")));let M=R.outcome.undeletable??[];if(M.length>0&&!t.leaveUndeletable){let k=M.map(j=>`${j.objectApiName} (${j.records} records)`).join(", ");g.push({code:ir,message:`The user SandForge connects as may not delete the records of ${k} in ${t.target}: a removal stops before its first delete, unless given --leave-undeletable, which removes the rest and leaves those.`})}f({planned:A.objects.reduce((k,j)=>k+j.planned,0),objects:A.objects,...M.length>0?{undeletable:M}:{},userNames:A.userNames},g)}process.argv[1]?.includes("sandforge-seed")&&(cr(),Zo().then(()=>process.exit(process.exitCode??0)).catch(t=>{process.stderr.write(`${t instanceof Error?t.message:String(t)}
446
- `),process.exit(1)}));export{ho as a,zt as b,$o as c,Ps as d,Bs as e,Io as f,To as g,Eo as h,xo as i,Co as j,_o as k,Do as l,Lo as m,Ns as n,Mo as o,Uo as p,Bo as q,zo as r,Ko as s,qo as t,Wo as u,zs as v,Fs as w,Vo as x,Zo as y,Xo as z,Qo as A,Ds as B,ea as C,na as D,ra as E,ca as F,ua as G,la as H,fa as I};
438
+ done in ${Z(n)}ms`),h.refusal!==void 0&&process.exit(no);return}r(`sandforge seed --remove ${e.summaryPath} from ${e.target}`);for(let{objectApiName:h,ids:v}of y)r(` ${h}: ${v.length} to remove`);y.length===0&&r("nothing left of the run to remove"),e.sweep&&r(`before them, a sweep deletes what the target's automation made for the run, as the run's user, tied to its records \u2014 run ${Ir("--sweep-list")} to see what`);let C=new AbortController,K=qe(()=>C.abort()),k=s??{},m=e.sweep?cr(Xe(b,"sandforge seed --sweep",C.signal),await P(C.signal),{includeChanged:e.includeChanged,removalSpans:k.removalSpans??[],...Pr(e),approve:async h=>{l=h,r("");for(let v of Ee(h,e.target,e))r(v)}}):void 0;await m?.ask();let $=Tr(m,l);if($){l=$,r("");for(let h of Ee($,e.target,e))r(h)}let R=he(b,"sandforge seed --remove"),A=await Nt(R,d.created),B=[...new Set(y.map(({objectApiName:h})=>h))],M=mt({setToDraft:vt(B),delete:_t(B,A,{userKept:i.runUserId!==void 0})},m?.takes??[]),x=M.delete??[];function q(h){return process.stderr.write(`${Ae(h)}
439
+ `),e.json&&process.stdout.write(Rt({tool:"sandforge-seed",...e.preview?{action:"remove-preview"}:{},summary:e.summaryPath,target:e.target,elapsedMs:Z(n)},h)),process.exit(1)}let j=h=>(K(),q(h)),O;if(x.length>0&&!C.signal.aborted){let h=await Te(b).read(e.target,x);r("");for(let I of It(h,e.target,M))r(I);if(e.muteAutomation)try{O=await At(async()=>$t(b),h,{writes:kn(M)});for(let I of me(O.muted,e.target))r(` ${I}`)}catch(I){if(!je(I))throw I;j(I.refusal)}let v=O?.automation??h,E=Tt(v,e.target,{steps:M,assign:Ot(v,gt(v,M)),mayMute:O===void 0&&He("--mute-automation")});E&&!e.acceptAutomation&&j({code:"AUTOMATION_NOT_ACCEPTED",message:E})}let F,L,W=O?.muted,H=async()=>{!O?.prepared||C.signal.aborted||(L=await O.prepared.acquire(`sandforge seed --remove ${d.runId}`).catch(h=>{if(!je(h))throw h;return j(h.refusal)}),W=L.outcome)},G={},le;try{F=await Mn({run:d,org:R,includeChanged:e.includeChanged,...Fr(m),...i.runUserId?{runUserId:i.runUserId}:{},onUndeletable:$r(e.leaveUndeletable,e.target,h=>{le=h}),beforeFirstWrite:H,signal:C.signal,store:{updateRemoval:(h,v)=>i.updateRemoval(E=>(k=v(E),k))}}),F.result.status!=="cancelled"&&!F.stoppedForUndeletable&&(G=await A.take(F.duplicateSets))}finally{K();let h=m?.made??new Set,v=m?.late??new Set,E=m?.gone??new Set;if((h.size>0||v.size>0||E.size>0)&&await i.updateRemoval(I=>qr(I,h,v,E)).catch(I=>{process.stderr.write(`What the sweep found made for the run could not be kept (${I instanceof Error?I.message:String(I)}): a later --sweep may list it as tied to nothing.
440
+ `)}),L){W=await L.release();for(let I of me(W,e.target))r(I)}}W&&(F={...F,result:{...F.result,mutedAutomation:W}}),F.stoppedForUndeletable&&(le&&q(le),process.exit(1));for(let h of[...F.notes,...G.note?[G.note]:[]])process.stderr.write(`${h}
441
+ `);let ge=m?.result(),Q=Nn(Br(F.result.status,G),ge);if(e.json)for(let h of zr(G,e.target))r(h);Ge({action:"cleanup_delete",orgId:g.id,objects:F.result.objects.map(h=>({...Je(h.objectApiName),deleted:h.deleted}))});let we=G.object?[...F.result.objects,G.object]:F.result.objects;f(Q,we,we.reduce((h,v)=>h+v.planned,0),ge,W),Q!=="success"&&process.exit(no)}var ja="not read by a preview: what the target's automation does as the records go \u2014 a trigger or a flow that deletes, keeps or creates other records \u2014 and what hangs from them, which a removal reads at each object\u2019s turn: a record kept for records that stay is counted with those to delete";function Oa(t){return`${JSON.stringify({tool:"sandforge-seed",action:"remove-preview",summary:t.summary,target:t.target,includeChanged:t.includeChanged,preview:t.preview,...t.sweepListing?{sweepListing:t.sweepListing}:{},refusals:t.refusals.map(({message:n})=>n),refusalCodes:t.refusals.map(({code:n})=>n),notes:t.notes,elapsedMs:t.elapsedMs},null,2)}
442
+ `}function Ia(t,n,e,r){let o=s=>t.userNames[s]??s,i=["preview: what a removal would do; nothing was written"];for(let s of t.objects){let d=[s.toDelete>0?`${s.toDelete} to delete`:"",r&&s.changedSince>0?`${s.changedSince} of them changed since the run`:"",s.alreadyGone>0?`${s.alreadyGone} gone already`:"",s.notVisible>0?`${s.notVisible} not visible`:"",s.keptChanged>0?`${s.keptChanged} kept, changed since the run`:"",s.undeletable>0?`${s.undeletable} left, the user may not delete them`:"",s.unread>0?`${s.unread} left, not read`:""].filter(Boolean);i.push(` ${s.objectApiName}: ${d.join(", ")||"nothing"} of ${s.planned}${Or(s)}`);let l=Object.entries(s.changedBy).sort((f,c)=>c[1]-f[1]);l.length>0&&i.push(` last changed by: ${l.map(([f,c])=>`${o(f)} ${c}`).join(" \xB7 ")}`);for(let f of s.reasons)i.push(` ${f}`)}for(let s of n)i.push(ee(s,"a removal"));return[...i,...e]}async function Ta(t,n,e,r,o){let i=Ze(e),s=[],d,l=n.runs!==void 0?(e.jobs??[]).length:0;l>0&&s.push(`the run's file names ${l} Bulk API job(s) no line of it answers: a removal reads back what they created first and removes it with the rest; this preview counts only what the file holds`);let f=(j,O)=>{if(s.push(ja),t.json){process.stdout.write(Oa({summary:t.summaryPath,target:t.target,includeChanged:t.includeChanged,preview:j,refusals:O,notes:s,elapsedMs:Z(o),...d?{sweepListing:d}:{}}));return}r("");for(let F of Ia(j,O,s,t.includeChanged))r(F);r(`
443
+ done in ${Z(o)}ms`)};if(r(`sandforge seed --remove ${t.summaryPath} --preview of ${t.target}`),i.length===0&&!t.sweep){s.push(n.earlier?.undo?`what the run created was removed already, on ${n.earlier.undo.removedAt}`:"The run created nothing: there is nothing of it to remove."),f({planned:0,objects:[],userNames:{}},[]);return}let c=await $e(t.target),w=pe(c),b=await ve(w);if(n.targetOrgId!==void 0&&n.targetOrgId.slice(0,15)!==b.id.slice(0,15)){let j={code:yt,message:`${t.target} is not the org the run wrote to (${n.targetOrgId}): its records are read in that org only. Nothing of the run was read.`};process.stderr.write(`${Ae(j)}
444
+ `),t.json&&process.stdout.write(Rt({tool:"sandforge-seed",action:"remove-preview",summary:t.summaryPath,target:t.target,elapsedMs:Z(o)},j)),process.exit(1)}let g=[],S=Mt(t.target,b,"sandforge seed");if(S&&g.push({code:"PRODUCTION_TARGET",message:S}),t.sweep){d=await Et(Xe(w,"sandforge seed --remove --preview --sweep"),await io(w,t.target,b.id,e,n),n.earlier?.removalSpans??[]),r("");for(let j of Ee(d,t.target,t,!0))r(j)}let y=await Nt(he(w,"sandforge seed --remove --preview"),e.created),P=[...new Set(i.map(({objectApiName:j})=>j))],C=mt({setToDraft:vt(P),delete:_t(P,y,{userKept:n.runUserId!==void 0})},d?Sn(d,t):[]),K=await Te(w).read(t.target,C.delete??[]);r("");for(let j of It(K,t.target,C))r(j);let k=Tt(K,t.target,{steps:C,assign:Ot(K,gt(K,C)),mayMute:!t.muteAutomation&&He("--mute-automation")});if(k&&!t.acceptAutomation&&g.push({code:"AUTOMATION_NOT_ACCEPTED",message:k}),i.length===0){s.push("nothing left of the run to remove"),f({planned:0,objects:[],userNames:{}},g);return}let m=new AbortController,$,R=qe(j=>{$=j,m.abort()}),A;try{A=await Un({run:e,org:he(w,"sandforge seed --remove --preview"),includeChanged:t.includeChanged,...n.runUserId?{runUserId:n.runUserId}:{},signal:m.signal})}finally{R()}let B=A.outcome.preview;B||(process.stderr.write(`interrupted: the preview stopped before it was through, and wrote nothing
445
+ `),process.exit(We($??"SIGINT")));let M=A.outcome.undeletable??[];if(M.length>0&&!t.leaveUndeletable){let j=M.map(O=>`${O.objectApiName} (${O.records} records)`).join(", ");g.push({code:vr,message:`The user SandForge connects as may not delete the records of ${j} in ${t.target}: a removal stops before its first delete, unless given --leave-undeletable, which removes the rest and leaves those.`})}let x=await Kr(y,e.created,B.objects,{kept:A.outcome.previewKept??new Set,...A.outcome.duplicateSets?{taken:A.outcome.duplicateSets}:{}});x.note&&s.push(x.note);let q=x.object?[...B.objects,x.object]:B.objects;f({planned:q.reduce((j,O)=>j+O.planned,0),objects:q,...M.length>0?{undeletable:M}:{},userNames:B.userNames},g)}process.argv[1]?.includes("sandforge-seed")&&(Ar(),la().then(()=>process.exit(process.exitCode??0)).catch(t=>{process.stderr.write(`${t instanceof Error?t.message:String(t)}
446
+ `),process.exit(1)}));export{Eo as a,Vt as b,Uo as c,Hs as d,so as e,Wo as f,qo as g,Go as h,Jo as i,Vo as j,Xo as k,Yo as l,ea as m,Qs as n,ta as o,na as p,ra as q,sa as r,oa as s,aa as t,ia as u,oo as v,Xs as w,ua as x,la as y,pa as z,ha as A,eo as B,ga as C,ba as D,ya as E,Aa as F,ja as G,Oa as H,Ia as I};
@@ -4,4 +4,4 @@ import { dirname as __sandforgeDirname } from 'node:path';
4
4
  const require = __sandforgeRequire(import.meta.url);
5
5
  const __filename = __sandforgePath(import.meta.url);
6
6
  const __dirname = __sandforgeDirname(__filename);
7
- import{a,b}from"./chunk-ZJW6YOMV.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-PMWAFDUB.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as FakerFallback,b as generateByMethod};
7
+ import{a,b}from"./chunk-VRBETPHY.mjs";import"./chunk-FQGHL7GR.mjs";import"./chunk-J347SPU6.mjs";import"./chunk-WZQEK4WT.mjs";import"./chunk-NTOVCTRS.mjs";export{a as FakerFallback,b as generateByMethod};