@wirecat/bitrix24-cli 0.3.0 → 0.5.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 (255) hide show
  1. package/CHANGELOG.md +130 -0
  2. package/README.md +84 -9
  3. package/dist/api-keys.d.ts +36 -9
  4. package/dist/api-keys.d.ts.map +1 -1
  5. package/dist/api-keys.js +139 -19
  6. package/dist/api-keys.js.map +1 -1
  7. package/dist/bin/b24.js +2 -2
  8. package/dist/bitrix/errors.js +1 -1
  9. package/dist/bitrix/errors.js.map +1 -1
  10. package/dist/bitrix/methods.d.ts.map +1 -1
  11. package/dist/bitrix/methods.js +7 -3
  12. package/dist/bitrix/methods.js.map +1 -1
  13. package/dist/bitrix/transport.d.ts +4 -7
  14. package/dist/bitrix/transport.d.ts.map +1 -1
  15. package/dist/bitrix/transport.js +29 -19
  16. package/dist/bitrix/transport.js.map +1 -1
  17. package/dist/body.d.ts +14 -0
  18. package/dist/body.d.ts.map +1 -0
  19. package/dist/body.js +44 -0
  20. package/dist/body.js.map +1 -0
  21. package/dist/bundle/{chunk-QIPTIUMJ.js → all-profiles-CANIDIDS.js} +12 -7
  22. package/dist/bundle/{anthropic-RHRAVHC2.js → anthropic-JUJB4DCF.js} +5 -5
  23. package/dist/bundle/{app-server-QIT6S7AZ.js → app-server-3V5Z4PTK.js} +68 -54
  24. package/dist/bundle/b24.js +18 -12
  25. package/dist/bundle/{bun-H6RSODZ3.js → bun-LKMV5TY7.js} +2 -2
  26. package/dist/bundle/{bun-sqlite-BO4LTQHX.js → bun-sqlite-S56EF74S.js} +3 -3
  27. package/dist/bundle/{chunk-D5S6QV6R.js → chunk-2I4KWS3H.js} +6 -6
  28. package/dist/bundle/chunk-36PO5NWY.js +147 -0
  29. package/dist/bundle/{chunk-ZIAQPTUS.js → chunk-42F7Q7V6.js} +3 -3
  30. package/dist/bundle/{chunk-6WY72XVQ.js → chunk-4D3K6GZW.js} +18 -4
  31. package/dist/bundle/chunk-5D4MJQ6X.js +22 -0
  32. package/dist/bundle/chunk-5JOPERVF.js +84 -0
  33. package/dist/bundle/chunk-6A4UPWDC.js +15 -0
  34. package/dist/bundle/{chunk-P33NDCDI.js → chunk-6MGWIZG4.js} +1 -1
  35. package/dist/bundle/{chunk-ZDQQCXFG.js → chunk-6YJTNZ7U.js} +13 -13
  36. package/dist/bundle/{chunk-MBDK4YXG.js → chunk-7FBFJ6B4.js} +4 -2
  37. package/dist/bundle/chunk-7VCMOTQP.js +55 -0
  38. package/dist/bundle/{chunk-P364PLIK.js → chunk-A5IMMGYU.js} +36 -34
  39. package/dist/bundle/{chunk-45AKJVKV.js → chunk-ASEHTBNK.js} +1 -1
  40. package/dist/bundle/{chunk-HGL63O5V.js → chunk-B6LPJYPQ.js} +2 -2
  41. package/dist/bundle/{chunk-LSPIOT6Z.js → chunk-BHEE2K6C.js} +7 -7
  42. package/dist/bundle/chunk-BYZQBE63.js +971 -0
  43. package/dist/bundle/{program-H3TGGRQ6.js → chunk-COKGNTDQ.js} +15761 -16685
  44. package/dist/bundle/{chunk-XJXONOB5.js → chunk-DVFYRQGE.js} +1 -1
  45. package/dist/bundle/{chunk-FLUEXJ4X.js → chunk-DVSIBZ3G.js} +1 -1
  46. package/dist/bundle/chunk-EJEIXC6Y.js +273 -0
  47. package/dist/bundle/chunk-EYTGCM44.js +130 -0
  48. package/dist/bundle/{chunk-IRV2PCQ2.js → chunk-EYYOKT23.js} +26 -26
  49. package/dist/bundle/{chunk-PH5FZX6E.js → chunk-FCWPIWSR.js} +2 -2
  50. package/dist/bundle/{chunk-YZ5LHE5Q.js → chunk-FSWRMQWX.js} +2 -2
  51. package/dist/bundle/{chunk-ADLS6FVG.js → chunk-FXBHOCJK.js} +1 -1
  52. package/dist/bundle/chunk-G5MW6RCM.js +723 -0
  53. package/dist/bundle/{chunk-VEWWAGTD.js → chunk-GLTKRLFT.js} +8 -8
  54. package/dist/bundle/chunk-GUUZQ7NE.js +581 -0
  55. package/dist/bundle/{chunk-QSNROIJL.js → chunk-H6RIPOOI.js} +42 -9
  56. package/dist/bundle/{chunk-H2ADPPSH.js → chunk-HGFNC4CR.js} +1819 -597
  57. package/dist/bundle/{chunk-7GRZAKBB.js → chunk-IERYD2N2.js} +6 -6
  58. package/dist/bundle/{chunk-N6FLBXZS.js → chunk-IGCLMEMB.js} +3 -3
  59. package/dist/bundle/{chunk-U5ACMCAQ.js → chunk-J7WCSZ2Q.js} +411 -919
  60. package/dist/bundle/{chunk-W5YAO5G5.js → chunk-JZYHQ4HB.js} +9 -4
  61. package/dist/bundle/{chunk-EVYSBZ3I.js → chunk-K4QM3X5F.js} +4 -4
  62. package/dist/bundle/{chunk-DTXERR44.js → chunk-KFSMY7SZ.js} +2 -2
  63. package/dist/bundle/{chunk-LRGYKOCP.js → chunk-KPEDH5T4.js} +1 -1
  64. package/dist/bundle/{chunk-XRFJWHY5.js → chunk-KUY7LII2.js} +4 -4
  65. package/dist/bundle/{chunk-QC53QBNC.js → chunk-LFXDHLFR.js} +3 -3
  66. package/dist/bundle/{chunk-CNNEA2M4.js → chunk-LGLT4JB6.js} +3 -3
  67. package/dist/bundle/{chunk-QGMDQ2PM.js → chunk-LM4OOBAW.js} +3 -3
  68. package/dist/bundle/chunk-M74BSKMA.js +234 -0
  69. package/dist/bundle/{chunk-2KCZ7BKW.js → chunk-MMMT6ORT.js} +11 -11
  70. package/dist/bundle/{chunk-WII44RXN.js → chunk-NGYD6QTE.js} +2 -2
  71. package/dist/bundle/{chunk-FOTREPNS.js → chunk-NO6QOPVT.js} +10 -19
  72. package/dist/bundle/chunk-O6XC7DZI.js +804 -0
  73. package/dist/bundle/chunk-OE3NFB53.js +64 -0
  74. package/dist/bundle/{chunk-XD4FRDSL.js → chunk-OUMFNB34.js} +13 -149
  75. package/dist/bundle/{chunk-ZGZT5S6B.js → chunk-P2RQTNVJ.js} +806 -850
  76. package/dist/bundle/{chunk-RRJNNPR4.js → chunk-PBIBGIZ7.js} +1 -1
  77. package/dist/bundle/{chunk-EXOOKUEA.js → chunk-Q6VQHTRW.js} +2 -2
  78. package/dist/bundle/{chunk-TE3FR6MI.js → chunk-QHBCNVUG.js} +5 -5
  79. package/dist/bundle/{chunk-SGRYYE4X.js → chunk-QNOXAQ6Y.js} +4 -4
  80. package/dist/bundle/{chunk-QQXH2OPB.js → chunk-R5F2O5GX.js} +15 -272
  81. package/dist/bundle/{chunk-SFRNX2TI.js → chunk-R5PBSKJL.js} +1 -1
  82. package/dist/bundle/{chunk-OTD2ZRXD.js → chunk-RS2BARUU.js} +4 -4
  83. package/dist/bundle/chunk-TG3DSPT5.js +14 -0
  84. package/dist/bundle/{chunk-BCF7P4FZ.js → chunk-U22JMKUO.js} +6 -125
  85. package/dist/bundle/chunk-U66Q5TVK.js +106 -0
  86. package/dist/bundle/{chunk-QMPN6WKD.js → chunk-UCHMQWON.js} +211 -89
  87. package/dist/bundle/{chunk-POC3V3AO.js → chunk-VMJS7FJZ.js} +526 -467
  88. package/dist/bundle/{chunk-FZL7F5NR.js → chunk-VMVAQHDC.js} +77 -615
  89. package/dist/bundle/{chunk-K3UIB6ZF.js → chunk-WWMCJFMT.js} +2 -2
  90. package/dist/bundle/{chunk-CXL33BFL.js → chunk-XTA5TN3H.js} +1 -1
  91. package/dist/bundle/{chunk-WTPMJYMD.js → chunk-XUHHBEA7.js} +652 -131
  92. package/dist/bundle/{chunk-WKRQ44EH.js → chunk-YDZHO4LT.js} +13 -13
  93. package/dist/bundle/{chunk-2SNUMZ7S.js → chunk-ZKINZFIT.js} +6 -6
  94. package/dist/bundle/{chunk-HAXNUIGQ.js → chunk-ZSQXSIFQ.js} +89 -39
  95. package/dist/bundle/{chunk-YYO7D2MO.js → chunk-ZZEHDIEG.js} +58 -54
  96. package/dist/bundle/command-contract-OQV6H7SR.js +36 -0
  97. package/dist/bundle/{decode-5ZPLTYV6.js → decode-QSTBX4MG.js} +3 -3
  98. package/dist/bundle/{echarts-J6LAPIX7.js → echarts-JZELFH2N.js} +2 -2
  99. package/dist/bundle/{embed-YG5LDHME.js → embed-4RIW2LVH.js} +4 -4
  100. package/dist/bundle/{embedder-7FNUA5OZ.js → embedder-SW7DTWSL.js} +7 -7
  101. package/dist/bundle/{first-run-JPZNWIJN.js → first-run-7AISOSOM.js} +8 -8
  102. package/dist/bundle/first-screen-NMHNFZ2B.js +34 -0
  103. package/dist/bundle/{instructions-AXWTQHMR.js → instructions-BZE5YUGG.js} +1 -1
  104. package/dist/bundle/{mcp-7F46P6AM.js → mcp-SDWHDJTY.js} +2 -2
  105. package/dist/bundle/{node-P4E63KXA.js → node-KM3CUABH.js} +9 -9
  106. package/dist/bundle/{node-CWKAIOEM.js → node-LTKZIO4U.js} +2 -2
  107. package/dist/bundle/{node-sqlite-LSEKVRDA.js → node-sqlite-HQ5PN2RH.js} +4 -4
  108. package/dist/bundle/{oauth-THYNLRLD.js → oauth-UH6FOZQL.js} +5 -5
  109. package/dist/bundle/{open-E47QYKFC.js → open-TSUP3XGL.js} +3 -3
  110. package/dist/bundle/{openai-EWSGC3BC.js → openai-GVEE52E3.js} +14 -14
  111. package/dist/bundle/{process-WKTEA3WE.js → process-AGXY76ZE.js} +1 -1
  112. package/dist/bundle/program-BI4A4HFJ.js +2247 -0
  113. package/dist/bundle/{prompt-CAQ7QR3U.js → prompt-NRSUY7FA.js} +3 -3
  114. package/dist/bundle/{recognize-6KGHNZC3.js → recognize-NPDPQ6PJ.js} +2 -2
  115. package/dist/bundle/{remote-3UO2WDC3.js → remote-HFASMVLB.js} +5 -5
  116. package/dist/bundle/{rerank-2JVDPZBX.js → rerank-TL6Z6F7K.js} +5 -5
  117. package/dist/bundle/{chunk-VL6SPMZV.js → serve-VB4DHDZQ.js} +8 -6
  118. package/dist/bundle/server-T5EDRPJI.js +68 -0
  119. package/dist/bundle/{chunk-ZEW4P6AH.js → server-Z6MW6C37.js} +50 -14
  120. package/dist/bundle/source-4IGO5J7E.js +237 -0
  121. package/dist/bundle/sqlite-runtime-YS4POY3W.js +17 -0
  122. package/dist/bundle/{state-7NH5G4XJ.js → state-ISZVVZGR.js} +4 -4
  123. package/dist/bundle/store-IZJBAKJV.js +58 -0
  124. package/dist/bundle/{store-7O4JQD2Z.js → store-L76MSQC3.js} +17 -12
  125. package/dist/bundle/store-PBTIB7BD.js +207 -0
  126. package/dist/bundle/store-maintenance-command-YFKII7TF.js +58 -0
  127. package/dist/bundle/writer-3O5EYMFE.js +214 -0
  128. package/dist/commands/api.d.ts.map +1 -1
  129. package/dist/commands/api.js +81 -30
  130. package/dist/commands/api.js.map +1 -1
  131. package/dist/commands/crm-shared.d.ts +4 -0
  132. package/dist/commands/crm-shared.d.ts.map +1 -0
  133. package/dist/commands/crm-shared.js +94 -0
  134. package/dist/commands/crm-shared.js.map +1 -0
  135. package/dist/commands/crm-writes.d.ts +0 -1
  136. package/dist/commands/crm-writes.d.ts.map +1 -1
  137. package/dist/commands/crm-writes.js +43 -88
  138. package/dist/commands/crm-writes.js.map +1 -1
  139. package/dist/commands/crm.d.ts.map +1 -1
  140. package/dist/commands/crm.js +30 -48
  141. package/dist/commands/crm.js.map +1 -1
  142. package/dist/commands/session.d.ts.map +1 -1
  143. package/dist/commands/session.js +1 -0
  144. package/dist/commands/session.js.map +1 -1
  145. package/dist/commands/write.d.ts +6 -6
  146. package/dist/commands/write.d.ts.map +1 -1
  147. package/dist/commands/write.js +11 -18
  148. package/dist/commands/write.js.map +1 -1
  149. package/dist/config.d.ts +0 -5
  150. package/dist/config.d.ts.map +1 -1
  151. package/dist/config.js +6 -8
  152. package/dist/config.js.map +1 -1
  153. package/dist/crm/capabilities.d.ts +7 -0
  154. package/dist/crm/capabilities.d.ts.map +1 -0
  155. package/dist/crm/capabilities.js +7 -0
  156. package/dist/crm/capabilities.js.map +1 -0
  157. package/dist/crm/conditions.d.ts +1 -1
  158. package/dist/crm/conditions.d.ts.map +1 -1
  159. package/dist/crm/conditions.js +4 -6
  160. package/dist/crm/conditions.js.map +1 -1
  161. package/dist/crm/custom-query.d.ts +19 -0
  162. package/dist/crm/custom-query.d.ts.map +1 -0
  163. package/dist/crm/custom-query.js +79 -0
  164. package/dist/crm/custom-query.js.map +1 -0
  165. package/dist/crm/deal.d.ts +4 -27
  166. package/dist/crm/deal.d.ts.map +1 -1
  167. package/dist/crm/deal.js +15 -48
  168. package/dist/crm/deal.js.map +1 -1
  169. package/dist/crm/fields.d.ts +20 -0
  170. package/dist/crm/fields.d.ts.map +1 -0
  171. package/dist/crm/fields.js +78 -0
  172. package/dist/crm/fields.js.map +1 -0
  173. package/dist/crm/items.d.ts +7 -1
  174. package/dist/crm/items.d.ts.map +1 -1
  175. package/dist/crm/items.js +21 -18
  176. package/dist/crm/items.js.map +1 -1
  177. package/dist/crm/lead.d.ts +5 -36
  178. package/dist/crm/lead.d.ts.map +1 -1
  179. package/dist/crm/lead.js +15 -61
  180. package/dist/crm/lead.js.map +1 -1
  181. package/dist/crm/organization.d.ts +1 -0
  182. package/dist/crm/organization.d.ts.map +1 -1
  183. package/dist/crm/person.d.ts +1 -0
  184. package/dist/crm/person.d.ts.map +1 -1
  185. package/dist/crm/pipelines.d.ts +5 -0
  186. package/dist/crm/pipelines.d.ts.map +1 -0
  187. package/dist/crm/pipelines.js +54 -0
  188. package/dist/crm/pipelines.js.map +1 -0
  189. package/dist/crm/product.d.ts.map +1 -1
  190. package/dist/crm/product.js +2 -2
  191. package/dist/crm/product.js.map +1 -1
  192. package/dist/crm/rest3-fields.d.ts +3 -0
  193. package/dist/crm/rest3-fields.d.ts.map +1 -0
  194. package/dist/crm/rest3-fields.js +38 -0
  195. package/dist/crm/rest3-fields.js.map +1 -0
  196. package/dist/crm/source.d.ts +15 -0
  197. package/dist/crm/source.d.ts.map +1 -0
  198. package/dist/crm/source.js +122 -0
  199. package/dist/crm/source.js.map +1 -0
  200. package/dist/crm/user.d.ts.map +1 -1
  201. package/dist/crm/user.js +2 -2
  202. package/dist/crm/user.js.map +1 -1
  203. package/dist/crm/values.d.ts +26 -5
  204. package/dist/crm/values.d.ts.map +1 -1
  205. package/dist/crm/values.js +40 -5
  206. package/dist/crm/values.js.map +1 -1
  207. package/dist/crm/writer.d.ts +9 -0
  208. package/dist/crm/writer.d.ts.map +1 -0
  209. package/dist/crm/writer.js +119 -0
  210. package/dist/crm/writer.js.map +1 -0
  211. package/dist/program.d.ts.map +1 -1
  212. package/dist/program.js +53 -5
  213. package/dist/program.js.map +1 -1
  214. package/dist/reasons.d.ts.map +1 -1
  215. package/dist/reasons.js +6 -1
  216. package/dist/reasons.js.map +1 -1
  217. package/dist/store.d.ts +15 -0
  218. package/dist/store.d.ts.map +1 -0
  219. package/dist/store.js +33 -0
  220. package/dist/store.js.map +1 -0
  221. package/dist/version.d.ts +1 -1
  222. package/dist/version.js +1 -1
  223. package/package.json +4 -6
  224. package/skills/bitrix24-cli/SKILL.md +16 -10
  225. package/dist/bundle/all-profiles-QJ444GSX.js +0 -24
  226. package/dist/bundle/chunk-XNHSPHUN.js +0 -48
  227. package/dist/bundle/command-contract-OKQOE6G4.js +0 -30
  228. package/dist/bundle/first-screen-VQM4MTS7.js +0 -28
  229. package/dist/bundle/mcp-5RSWNTHS.js +0 -160
  230. package/dist/bundle/mcp-J5R5A65I.js +0 -87
  231. package/dist/bundle/serve-ES7AG5IK.js +0 -19
  232. package/dist/bundle/server-5LE5LNUQ.js +0 -45
  233. package/dist/bundle/server-BU4VBM6S.js +0 -58
  234. package/dist/bundle/store-maintenance-command-UDVGEY2D.js +0 -47
  235. package/dist/commands/doctor.d.ts +0 -77
  236. package/dist/commands/doctor.d.ts.map +0 -1
  237. package/dist/commands/doctor.js +0 -74
  238. package/dist/commands/doctor.js.map +0 -1
  239. package/dist/commands/mcp.d.ts +0 -3
  240. package/dist/commands/mcp.d.ts.map +0 -1
  241. package/dist/commands/mcp.js +0 -97
  242. package/dist/commands/mcp.js.map +0 -1
  243. package/dist/crm/pipeline.d.ts +0 -17
  244. package/dist/crm/pipeline.d.ts.map +0 -1
  245. package/dist/crm/pipeline.js +0 -42
  246. package/dist/crm/pipeline.js.map +0 -1
  247. package/dist/crm/stage.d.ts +0 -20
  248. package/dist/crm/stage.d.ts.map +0 -1
  249. package/dist/crm/stage.js +0 -65
  250. package/dist/crm/stage.js.map +0 -1
  251. package/dist/mcp.d.ts +0 -29
  252. package/dist/mcp.d.ts.map +0 -1
  253. package/dist/mcp.js +0 -99
  254. package/dist/mcp.js.map +0 -1
  255. /package/dist/bundle/{chunk-4PDYYS5K.js → chunk-ZQ3GWKDQ.js} +0 -0
@@ -0,0 +1,723 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ CliError,
5
+ createRecordLog,
6
+ isCliError,
7
+ resolvePaths,
8
+ traceIdOf,
9
+ writeSecurely
10
+ } from "./chunk-EYYOKT23.js";
11
+ import {
12
+ __name
13
+ } from "./chunk-ZVVMGPBJ.js";
14
+
15
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/ports/app.js
16
+ var envName = /* @__PURE__ */ __name((app, name) => `${app.envPrefix}_${name}`, "envName");
17
+ var readOnlyLockOf = /* @__PURE__ */ __name((app, env) => {
18
+ const name = envName(app, "READ_ONLY");
19
+ const value = env[name];
20
+ return value === void 0 || value.trim() === "" || value === "0" ? void 0 : name;
21
+ }, "readOnlyLockOf");
22
+ var mailHolderVariable = /* @__PURE__ */ __name((app) => envName(app, "MAIL_HOLDER"), "mailHolderVariable");
23
+ var MESSENGER_CHANGE_REFUSAL = "send, react, change chats or change the account";
24
+ var readOnlyRefusal = /* @__PURE__ */ __name((lock, what) => new CliError("permission_error", `this process is read-only (${lock}) \u2014 it cannot ${what}`), "readOnlyRefusal");
25
+
26
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/runs/log-keys.js
27
+ var snake = /* @__PURE__ */ __name((key) => key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), "snake");
28
+ var camel = /* @__PURE__ */ __name((key) => key.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase()), "camel");
29
+ var renamed = /* @__PURE__ */ __name((record, name) => Object.fromEntries(Object.entries(record).map(([key, value]) => [name(key), value])), "renamed");
30
+ var logAttributes = /* @__PURE__ */ __name((event) => renamed(event, snake), "logAttributes");
31
+ var fromLogAttributes = /* @__PURE__ */ __name((attributes) => renamed(attributes, camel), "fromLogAttributes");
32
+ var snakeLogger = /* @__PURE__ */ __name((logger) => ({
33
+ debug: /* @__PURE__ */ __name((event, message) => logger.debug(logAttributes(event), message), "debug"),
34
+ info: /* @__PURE__ */ __name((event, message) => logger.info(logAttributes(event), message), "info"),
35
+ warn: /* @__PURE__ */ __name((event, message) => logger.warn(logAttributes(event), message), "warn"),
36
+ error: /* @__PURE__ */ __name((event, message) => logger.error(logAttributes(event), message), "error")
37
+ }), "snakeLogger");
38
+
39
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/runs/log-attributes.js
40
+ var diagnostic = {
41
+ event: true,
42
+ operation: true,
43
+ opcode: true,
44
+ seq: true,
45
+ status: true,
46
+ method: true,
47
+ endpointTemplate: true,
48
+ bytes: true,
49
+ ids: true,
50
+ counts: true,
51
+ durationMs: true,
52
+ outcome: true,
53
+ errorCode: true,
54
+ providerError: true,
55
+ level: true,
56
+ transport: true,
57
+ attempt: true,
58
+ waitMs: true,
59
+ code: true,
60
+ detail: true,
61
+ reason: true,
62
+ ageMs: true
63
+ };
64
+ var send = {
65
+ profile: true,
66
+ chatId: true,
67
+ outcome: true,
68
+ kind: true,
69
+ action: true,
70
+ people: true,
71
+ messageId: true,
72
+ key: true,
73
+ count: true,
74
+ forEveryone: true,
75
+ sendId: true,
76
+ operationId: true,
77
+ parentOperationId: true,
78
+ replyTo: true,
79
+ threadId: true,
80
+ sendAs: true,
81
+ resultChatId: true,
82
+ length: true,
83
+ attachments: true,
84
+ scheduledFor: true,
85
+ notify: true,
86
+ origin: true,
87
+ reservation: true,
88
+ errorCode: true
89
+ };
90
+ var background = [
91
+ "job",
92
+ "pid",
93
+ "schedule",
94
+ "exitCode",
95
+ "tool",
96
+ "tier",
97
+ "actorType",
98
+ "actorId",
99
+ "agent",
100
+ "targetType",
101
+ "targetId"
102
+ ];
103
+ var crash = ["errorClass", "frames"];
104
+ var dropped = ["dropped"];
105
+ var LOG_ATTRIBUTES = [
106
+ ...new Set([...Object.keys(diagnostic), ...Object.keys(send), ...background, ...crash, ...dropped].map((key) => Object.keys(logAttributes({ [key]: true }))[0]))
107
+ ].sort();
108
+
109
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/runs/run.js
110
+ import { randomUUID } from "node:crypto";
111
+ import { appendFileSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
112
+ import { userInfo } from "node:os";
113
+ import { join, sep } from "node:path";
114
+ var KEEP_RUNS_FOR_DAYS = 30;
115
+ var KEEP_SUCCESSFUL_RUNS_FOR_DAYS = 7;
116
+ var RUNS_SIZE_LIMIT_MB = 200;
117
+ var runsDirFor = /* @__PURE__ */ __name((app, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "runs"), "runsDirFor");
118
+ var startRun = /* @__PURE__ */ __name((options) => {
119
+ const now = options.now ?? (() => /* @__PURE__ */ new Date());
120
+ const startedAt = options.startedAt ?? now();
121
+ const id = options.runId ?? newRunId(startedAt, options.command);
122
+ const dir = join(options.runsDir, day(startedAt), id);
123
+ pruneRuns(options.runsDir, {
124
+ keepDays: options.keepDays ?? KEEP_RUNS_FOR_DAYS,
125
+ keepSuccessDays: options.keepSuccessDays ?? KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
126
+ maxBytes: options.maxBytes ?? RUNS_SIZE_LIMIT_MB * 1024 * 1024,
127
+ now: startedAt
128
+ });
129
+ refuseRealStateInTests(dir);
130
+ const metadata = {
131
+ runId: id,
132
+ command: options.command,
133
+ ...options.profile === void 0 ? {} : { profile: options.profile },
134
+ startedAt: startedAt.toISOString(),
135
+ status: "running",
136
+ cliVersion: options.cliVersion,
137
+ runtime: runtime(),
138
+ platform: process.platform,
139
+ arch: process.arch,
140
+ ...options.traceId === void 0 ? {} : { traceId: options.traceId },
141
+ ...options.context
142
+ };
143
+ let file;
144
+ const opened = /* @__PURE__ */ __name(() => {
145
+ if (file)
146
+ return file;
147
+ mkdirSync(dir, { recursive: true, mode: 448 });
148
+ const events = join(dir, "events.jsonl");
149
+ writeFileSync(events, "", { flag: "a", mode: 384 });
150
+ file = snakeLogger(createRecordLog({
151
+ to: events,
152
+ runId: id,
153
+ command: options.command,
154
+ resource: { service: options.service, version: options.cliVersion },
155
+ allow: LOG_ATTRIBUTES,
156
+ ...options.traceId === void 0 ? {} : { traceId: options.traceId },
157
+ ...options.onError === void 0 ? {} : { onError: options.onError }
158
+ }));
159
+ writeRunFile(dir, metadata);
160
+ return file;
161
+ }, "opened");
162
+ if (!options.lazy)
163
+ opened();
164
+ let finished = false;
165
+ const operations = /* @__PURE__ */ new Set();
166
+ const codes = /* @__PURE__ */ new Set();
167
+ const noted = /* @__PURE__ */ __name((level) => (event, message) => {
168
+ const { operation, errorCode, error_code, code } = event;
169
+ if (typeof operation === "string")
170
+ operations.add(operation);
171
+ for (const value of [errorCode, error_code, code])
172
+ if (typeof value === "string")
173
+ codes.add(value);
174
+ if (finished)
175
+ return;
176
+ opened()[level](event, message);
177
+ }, "noted");
178
+ const logger = { debug: noted("debug"), info: noted("info"), warn: noted("warn"), error: noted("error") };
179
+ return {
180
+ id,
181
+ dir,
182
+ logger,
183
+ finish: /* @__PURE__ */ __name(async (status, extra = {}) => {
184
+ if (finished)
185
+ return;
186
+ finished = true;
187
+ const completedAt = now();
188
+ const final = {
189
+ ...metadata,
190
+ ...extra,
191
+ status,
192
+ completedAt: completedAt.toISOString(),
193
+ durationMs: completedAt.getTime() - startedAt.getTime(),
194
+ operations: [...operations].sort(),
195
+ codes: [...codes].sort()
196
+ };
197
+ if (file || status !== "success") {
198
+ opened();
199
+ writeRunFile(dir, final);
200
+ return;
201
+ }
202
+ try {
203
+ mkdirSync(join(dir, ".."), { recursive: true, mode: 448 });
204
+ appendIndex(join(dir, ".."), runFileOf(final));
205
+ } catch (error) {
206
+ options.onError?.(error);
207
+ }
208
+ }, "finish")
209
+ };
210
+ }, "startRun");
211
+ var refuseRealStateInTests = /* @__PURE__ */ __name((dir, env = process.env) => {
212
+ if (env.VITEST === void 0)
213
+ return;
214
+ let home;
215
+ try {
216
+ home = userInfo().homedir;
217
+ } catch {
218
+ return;
219
+ }
220
+ if (dir.startsWith(join(home, ".local", "share") + sep))
221
+ throw new Error(`a test opened a run in the real data folder: ${dir}`);
222
+ }, "refuseRealStateInTests");
223
+ var runtime = /* @__PURE__ */ __name(() => {
224
+ const bun = process.versions.bun;
225
+ return bun ? `bun ${bun}` : `node ${process.versions.node}`;
226
+ }, "runtime");
227
+ var newRunId = /* @__PURE__ */ __name((startedAt, command) => {
228
+ const stamp = startedAt.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
229
+ const slug = command.replace(/[^a-z0-9]+/gi, "-").toLowerCase();
230
+ return `${stamp}-${slug}-${randomUUID().slice(0, 6)}`;
231
+ }, "newRunId");
232
+ var INDEX = "index.jsonl";
233
+ var appendIndex = /* @__PURE__ */ __name((dayDir, written) => {
234
+ appendFileSync(join(dayDir, INDEX), `${JSON.stringify(written)}
235
+ `, { mode: 384 });
236
+ }, "appendIndex");
237
+ var writeRunFile = /* @__PURE__ */ __name((dir, metadata) => {
238
+ const written = runFileOf(metadata);
239
+ writeSecurely(join(dir, "run.json"), `${JSON.stringify(written, null, 2)}
240
+ `, 384);
241
+ try {
242
+ appendIndex(join(dir, ".."), written);
243
+ } catch {
244
+ }
245
+ }, "writeRunFile");
246
+ var matchesListFilter = /* @__PURE__ */ __name((run, filter) => (filter.runId === void 0 || run.runId === filter.runId) && (filter.command === void 0 || run.command === filter.command) && (filter.profile === void 0 || run.profile === filter.profile) && (filter.status === void 0 || run.status === filter.status) && (filter.errorCode === void 0 || run.errorCode === filter.errorCode), "matchesListFilter");
247
+ var listRuns = /* @__PURE__ */ __name((runsDir, { since, atLeast = Number.POSITIVE_INFINITY, filter = {} } = {}) => {
248
+ const first = since === void 0 ? void 0 : day(new Date(since));
249
+ const runs = [];
250
+ for (const date of days(runsDir).sort().reverse()) {
251
+ if (first !== void 0 && date < first || runs.length >= atLeast)
252
+ break;
253
+ for (const metadata of runsOfDay(join(runsDir, date))) {
254
+ if (matchesListFilter(metadata, filter))
255
+ runs.push(metadata);
256
+ }
257
+ }
258
+ return runs;
259
+ }, "listRuns");
260
+ var indexedRuns = /* @__PURE__ */ __name((dayDir) => {
261
+ const latest = /* @__PURE__ */ new Map();
262
+ let raw = "";
263
+ try {
264
+ raw = readFileSync(join(dayDir, INDEX), "utf8");
265
+ } catch {
266
+ }
267
+ for (const line of raw.split("\n")) {
268
+ if (line.trim() === "")
269
+ continue;
270
+ try {
271
+ const metadata = metadataOf(JSON.parse(line));
272
+ if (typeof metadata.runId === "string")
273
+ latest.set(metadata.runId, metadata);
274
+ } catch {
275
+ }
276
+ }
277
+ return latest;
278
+ }, "indexedRuns");
279
+ var runsOfDay = /* @__PURE__ */ __name((dayDir) => {
280
+ const latest = indexedRuns(dayDir);
281
+ for (const entry of safeReaddir(dayDir)) {
282
+ if (entry === INDEX || entry.startsWith(".") || latest.has(entry))
283
+ continue;
284
+ const metadata = readRun(join(dayDir, entry));
285
+ if (metadata)
286
+ latest.set(metadata.runId, metadata);
287
+ }
288
+ return [...latest.values()].sort((a, b) => a.runId < b.runId ? 1 : a.runId > b.runId ? -1 : 0);
289
+ }, "runsOfDay");
290
+ var findRun = /* @__PURE__ */ __name((runsDir, id) => {
291
+ const stamped = /^(\d{4})(\d{2})(\d{2})T/.exec(id);
292
+ const likely = stamped ? [`${stamped[1]}-${stamped[2]}-${stamped[3]}`] : [];
293
+ const dates = [.../* @__PURE__ */ new Set([...likely, ...days(runsDir)])];
294
+ for (const date of dates) {
295
+ const dir = join(runsDir, date, id);
296
+ const metadata = readRun(dir);
297
+ if (metadata)
298
+ return { dir, metadata };
299
+ }
300
+ for (const date of dates) {
301
+ const metadata = indexedRuns(join(runsDir, date)).get(id);
302
+ if (metadata)
303
+ return { dir: join(runsDir, date, id), metadata };
304
+ }
305
+ return void 0;
306
+ }, "findRun");
307
+ var readEvents = /* @__PURE__ */ __name((dir) => {
308
+ let raw;
309
+ try {
310
+ raw = readFileSync(join(dir, "events.jsonl"), "utf8");
311
+ } catch {
312
+ return [];
313
+ }
314
+ const events = [];
315
+ for (const line of raw.split("\n")) {
316
+ if (line.trim() === "")
317
+ continue;
318
+ try {
319
+ const parsed = JSON.parse(line);
320
+ if (parsed !== null && typeof parsed === "object")
321
+ events.push(eventOf(parsed));
322
+ } catch {
323
+ }
324
+ }
325
+ return events;
326
+ }, "readEvents");
327
+ var eventOf = /* @__PURE__ */ __name((line) => {
328
+ const { attributes, time, severity } = line;
329
+ if (attributes === null || typeof attributes !== "object")
330
+ return logAttributes(line);
331
+ return { time, severity, ...logAttributes(attributes) };
332
+ }, "eventOf");
333
+ var pruneRuns = /* @__PURE__ */ __name((runsDir, { keepDays, keepSuccessDays = keepDays, maxBytes, now }) => {
334
+ const cutoff = day(new Date(now.getTime() - keepDays * DAY_MS));
335
+ const successCutoff = day(new Date(now.getTime() - Math.min(keepSuccessDays, keepDays) * DAY_MS));
336
+ let removed = 0;
337
+ for (const date of days(runsDir)) {
338
+ if (date >= cutoff) {
339
+ if (date < successCutoff)
340
+ dropSuccesses(join(runsDir, date));
341
+ continue;
342
+ }
343
+ try {
344
+ rmSync(join(runsDir, date), { recursive: true, force: true });
345
+ removed += 1;
346
+ } catch {
347
+ }
348
+ }
349
+ if (maxBytes !== void 0)
350
+ removed += fitSize(runsDir, maxBytes, now);
351
+ return removed;
352
+ }, "pruneRuns");
353
+ var DAY_MS = 24 * 60 * 60 * 1e3;
354
+ var SUCCESSES_DROPPED = ".successes-dropped";
355
+ var SIZE_CHECKED = ".size-checked";
356
+ var dropSuccesses = /* @__PURE__ */ __name((dayDir) => {
357
+ const marker = join(dayDir, SUCCESSES_DROPPED);
358
+ try {
359
+ statSync(marker);
360
+ return;
361
+ } catch {
362
+ }
363
+ try {
364
+ const kept = [];
365
+ for (const [id, metadata] of indexedRuns(dayDir)) {
366
+ if (metadata.status === "success")
367
+ rmSync(join(dayDir, id), { recursive: true, force: true });
368
+ else
369
+ kept.push(JSON.stringify(runFileOf(metadata)));
370
+ }
371
+ for (const entry of safeReaddir(dayDir)) {
372
+ if (entry === INDEX || entry.startsWith("."))
373
+ continue;
374
+ if (readRun(join(dayDir, entry))?.status === "success")
375
+ rmSync(join(dayDir, entry), { recursive: true, force: true });
376
+ }
377
+ writeSecurely(join(dayDir, INDEX), kept.map((line) => `${line}
378
+ `).join(""), 384);
379
+ writeFileSync(marker, "", { mode: 384 });
380
+ } catch {
381
+ }
382
+ }, "dropSuccesses");
383
+ var sizeOf = /* @__PURE__ */ __name((path) => {
384
+ let total = 0;
385
+ for (const entry of safeReaddir(path)) {
386
+ const full = join(path, entry);
387
+ try {
388
+ const stat = statSync(full);
389
+ total += stat.isDirectory() ? sizeOf(full) : stat.size;
390
+ } catch {
391
+ }
392
+ }
393
+ return total;
394
+ }, "sizeOf");
395
+ var fitSize = /* @__PURE__ */ __name((runsDir, maxBytes, now) => {
396
+ const stamp = join(runsDir, SIZE_CHECKED);
397
+ const today = day(now);
398
+ try {
399
+ if (readFileSync(stamp, "utf8").trim() === today)
400
+ return 0;
401
+ } catch {
402
+ }
403
+ const dates = days(runsDir).sort();
404
+ const sizes = new Map(dates.map((date) => [date, sizeOf(join(runsDir, date))]));
405
+ let total = [...sizes.values()].reduce((sum, size) => sum + size, 0);
406
+ let removed = 0;
407
+ for (const date of dates) {
408
+ if (total <= maxBytes || date === today)
409
+ break;
410
+ dropSuccesses(join(runsDir, date));
411
+ const after = sizeOf(join(runsDir, date));
412
+ total -= (sizes.get(date) ?? 0) - after;
413
+ sizes.set(date, after);
414
+ }
415
+ for (const date of dates) {
416
+ if (total <= maxBytes || date === today)
417
+ break;
418
+ try {
419
+ rmSync(join(runsDir, date), { recursive: true, force: true });
420
+ total -= sizes.get(date) ?? 0;
421
+ removed += 1;
422
+ } catch {
423
+ }
424
+ }
425
+ try {
426
+ mkdirSync(runsDir, { recursive: true, mode: 448 });
427
+ writeFileSync(stamp, today, { mode: 384 });
428
+ } catch {
429
+ }
430
+ return removed;
431
+ }, "fitSize");
432
+ var day = /* @__PURE__ */ __name((date) => date.toISOString().slice(0, 10), "day");
433
+ var days = /* @__PURE__ */ __name((runsDir) => safeReaddir(runsDir).filter((entry) => /^\d{4}-\d{2}-\d{2}$/.test(entry)), "days");
434
+ var readRun = /* @__PURE__ */ __name((dir) => {
435
+ try {
436
+ return metadataOf(JSON.parse(readFileSync(join(dir, "run.json"), "utf8")));
437
+ } catch {
438
+ return void 0;
439
+ }
440
+ }, "readRun");
441
+ var safeReaddir = /* @__PURE__ */ __name((dir) => {
442
+ try {
443
+ return readdirSync(dir);
444
+ } catch {
445
+ return [];
446
+ }
447
+ }, "safeReaddir");
448
+ var runFileOf = /* @__PURE__ */ __name(({ partial, ...metadata }) => ({
449
+ ...logAttributes(metadata),
450
+ ...partial ? { partial: { ...logAttributes(partial), failures: partial.failures.map((failure) => logAttributes(failure)) } } : {}
451
+ }), "runFileOf");
452
+ var metadataOf = /* @__PURE__ */ __name((parsed) => {
453
+ const { partial, ...metadata } = fromLogAttributes(parsed);
454
+ if (partial === null || typeof partial !== "object")
455
+ return metadata;
456
+ const { failures, ...rest } = fromLogAttributes(partial);
457
+ return {
458
+ ...metadata,
459
+ partial: {
460
+ ...rest,
461
+ failures: Array.isArray(failures) ? failures.map((failure) => fromLogAttributes(failure)) : []
462
+ }
463
+ };
464
+ }, "metadataOf");
465
+
466
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/runs/scope.js
467
+ import { AsyncLocalStorage } from "node:async_hooks";
468
+ import { randomBytes } from "node:crypto";
469
+ var scopes = new AsyncLocalStorage();
470
+ var processScope;
471
+ var currentRun = /* @__PURE__ */ __name(() => {
472
+ const scope = scopes.getStore();
473
+ if (scope)
474
+ return scope;
475
+ processScope ??= {
476
+ runId: newRunId(/* @__PURE__ */ new Date(), "process"),
477
+ command: "",
478
+ startedAt: Date.now(),
479
+ ...traceOf(process.env)
480
+ };
481
+ return processScope;
482
+ }, "currentRun");
483
+ var inRun = /* @__PURE__ */ __name((scope, body) => scopes.run(scope, body), "inRun");
484
+ var runEvent = /* @__PURE__ */ __name((event) => scopes.getStore()?.events?.(event), "runEvent");
485
+ var typedCommand = /* @__PURE__ */ __name((tool, words, profile = currentRun().profile) => [tool, profile, words].filter((part) => part !== void 0 && part !== "").join(" "), "typedCommand");
486
+ var useAsProcessRun = /* @__PURE__ */ __name((scope) => {
487
+ processScope = scope;
488
+ }, "useAsProcessRun");
489
+ var processRun = /* @__PURE__ */ __name(() => processScope, "processRun");
490
+ var enclosingTraceId = /* @__PURE__ */ __name(() => scopes.getStore()?.traceId, "enclosingTraceId");
491
+ var traceOf = /* @__PURE__ */ __name((env) => {
492
+ const traceId = traceIdOf(env.TRACEPARENT);
493
+ return traceId === void 0 ? {} : { traceId };
494
+ }, "traceOf");
495
+ var childTrace = /* @__PURE__ */ __name(() => {
496
+ const hex = /* @__PURE__ */ __name((bytes) => randomBytes(bytes).toString("hex"), "hex");
497
+ const traceId = hex(16);
498
+ return { traceId, traceparent: `00-${traceId}-${hex(8)}-01` };
499
+ }, "childTrace");
500
+ var attempts = new AsyncLocalStorage();
501
+ var withAttempt = /* @__PURE__ */ __name((attempt, work) => attempts.run(attempt, work), "withAttempt");
502
+ var currentAttempt = /* @__PURE__ */ __name(() => attempts.getStore(), "currentAttempt");
503
+
504
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/background/budget.js
505
+ var DEADLINE_MARGIN_MS = 5e3;
506
+ var DEADLINE_MARGIN_SHARE = 0.15;
507
+ var DEFAULT_REQUEST_MS = 2e3;
508
+ var deadlineMargin = /* @__PURE__ */ __name((deadline) => Math.max(DEADLINE_MARGIN_MS, deadline.ms * DEADLINE_MARGIN_SHARE), "deadlineMargin");
509
+ var requestsFor = /* @__PURE__ */ __name((deadline, requestMs = DEFAULT_REQUEST_MS) => deadline === void 0 ? null : Math.max(1, Math.floor((deadline.ms - deadlineMargin(deadline)) / requestMs)), "requestsFor");
510
+ var runBudget = /* @__PURE__ */ __name(({ requests, deadline, requestMs, signal, now = Date.now } = {}) => {
511
+ const fits = requestsFor(deadline, requestMs);
512
+ const limit = fits === null ? requests ?? null : Math.min(fits, requests ?? fits);
513
+ const margin = deadline ? deadlineMargin(deadline) : 0;
514
+ let used = 0;
515
+ let stopped2 = null;
516
+ let last;
517
+ let slowest = 0;
518
+ return {
519
+ take() {
520
+ if (stopped2)
521
+ return stopped2;
522
+ const at = now();
523
+ if (last !== void 0)
524
+ slowest = Math.max(slowest, at - last);
525
+ if (signal?.aborted)
526
+ stopped2 = "cancelled";
527
+ else if (limit !== null && used >= limit)
528
+ stopped2 = "requests";
529
+ else if (deadline && at + margin + slowest >= deadline.endsAt)
530
+ stopped2 = "deadline";
531
+ if (stopped2)
532
+ return stopped2;
533
+ used += 1;
534
+ last = at;
535
+ return null;
536
+ },
537
+ get used() {
538
+ return used;
539
+ },
540
+ limit,
541
+ get stopped() {
542
+ return stopped2;
543
+ }
544
+ };
545
+ }, "runBudget");
546
+
547
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/sends/guarded.js
548
+ import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
549
+ var sentIds = /* @__PURE__ */ __name((typed, message) => ({
550
+ messageId: message.id,
551
+ ...message.chatId && message.chatId !== typed ? { resultChatId: message.chatId } : {}
552
+ }), "sentIds");
553
+ var current = new AsyncLocalStorage2();
554
+ var writesInFlight = new AsyncLocalStorage2();
555
+ var parents = /* @__PURE__ */ new WeakMap();
556
+ var stopped = /* @__PURE__ */ new WeakMap();
557
+ var scopesFor = /* @__PURE__ */ __name((scope = writesInFlight.getStore()) => {
558
+ const result = [];
559
+ for (let at = scope; at; at = parents.get(at))
560
+ result.push(at);
561
+ return result;
562
+ }, "scopesFor");
563
+ var withWriteScope = /* @__PURE__ */ __name((scope, body) => {
564
+ const parent = writesInFlight.getStore();
565
+ if (parent && parent !== scope)
566
+ parents.set(scope, parent);
567
+ return writesInFlight.run(scope, body);
568
+ }, "withWriteScope");
569
+ var stopWrites = /* @__PURE__ */ __name((scope, reason) => {
570
+ stopped.set(scope, reason);
571
+ for (const write of scope)
572
+ write.cut();
573
+ }, "stopWrites");
574
+ var refuseStopped = /* @__PURE__ */ __name((scopes2) => {
575
+ for (const scope of scopes2)
576
+ if (stopped.has(scope))
577
+ throw stopped.get(scope);
578
+ }, "refuseStopped");
579
+ var currentOperation = /* @__PURE__ */ __name(() => current.getStore(), "currentOperation");
580
+ var guardedWrite = /* @__PURE__ */ __name(async (guard, attempt, act, settled = () => ({}), prepare) => {
581
+ const scopes2 = scopesFor();
582
+ refuseStopped(scopes2);
583
+ try {
584
+ await guard.ask?.(attempt);
585
+ refuseStopped(scopes2);
586
+ if (guard.reserve) {
587
+ guard.check(attempt, { reserve: false });
588
+ await guard.reserve(attempt);
589
+ } else
590
+ guard.check(attempt);
591
+ } catch (error) {
592
+ guard.record({ ...attempt, outcome: "refused", errorCode: codeOf(error) });
593
+ throw error;
594
+ }
595
+ try {
596
+ refuseStopped(scopes2);
597
+ } catch (error) {
598
+ guard.record({ ...attempt, outcome: "failed", errorCode: codeOf(error) });
599
+ throw error;
600
+ }
601
+ let recorded = false;
602
+ const once = /* @__PURE__ */ __name((entry) => {
603
+ if (recorded)
604
+ return;
605
+ recorded = true;
606
+ guard.record(entry);
607
+ }, "once");
608
+ let cancelled = false;
609
+ const flight = {
610
+ operationId: attempt.operationId,
611
+ preparing: prepare !== void 0,
612
+ cut: /* @__PURE__ */ __name(() => {
613
+ cancelled = true;
614
+ once({
615
+ ...attempt,
616
+ outcome: flight.preparing ? "failed" : "outcome_unknown",
617
+ errorCode: flight.preparing ? "timeout" : "outcome_unknown"
618
+ });
619
+ }, "cut")
620
+ };
621
+ for (const scope of scopes2)
622
+ scope.add(flight);
623
+ try {
624
+ if (prepare !== void 0)
625
+ await prepare();
626
+ if (cancelled)
627
+ throw new CliError("timeout", "the command ended before sending; nothing was sent", { sent: false });
628
+ flight.preparing = false;
629
+ const done = await current.run(attempt.operationId, act);
630
+ if (cancelled)
631
+ throw new CliError("outcome_unknown", "the command ended with a write in flight; check its result before continuing", { operation_id: attempt.operationId });
632
+ once({ ...attempt, ...settled(done), outcome: "sent" });
633
+ return done;
634
+ } catch (error) {
635
+ const code = codeOf(error);
636
+ once({ ...attempt, outcome: code === "outcome_unknown" ? "outcome_unknown" : "failed", errorCode: code });
637
+ if (code === "outcome_unknown" && error instanceof Error)
638
+ throw new CliError("outcome_unknown", error.message, {
639
+ ...error.details,
640
+ operation_id: attempt.operationId,
641
+ retryable: false
642
+ });
643
+ if (flight.preparing && isCliError(error) && error.details.sent === void 0)
644
+ throw new CliError(error.code, error.message, { ...error.details, sent: false });
645
+ throw error;
646
+ } finally {
647
+ for (const scope of scopes2)
648
+ scope.delete(flight);
649
+ }
650
+ }, "guardedWrite");
651
+ var codeOf = /* @__PURE__ */ __name((error) => typeof error?.code === "string" ? error.code : "unknown", "codeOf");
652
+
653
+ // node_modules/.pnpm/@wirecat+cli-core@0.601.0_@wirecat+cli-base@0.80.9_commander@15.0.0_esbuild@0.28.2_type_4fddd50439ae4e4f952967ea26554e7b/node_modules/@wirecat/cli-core/dist/background/checkpoints.js
654
+ var progressOf = /* @__PURE__ */ __name((input) => {
655
+ const total = input.total ?? null;
656
+ const updated = input.updatedAt ?? null;
657
+ return {
658
+ job: input.job,
659
+ profile: input.profile,
660
+ done: input.done,
661
+ total,
662
+ remaining: total === null ? null : Math.max(0, total - input.done),
663
+ state: input.complete ?? (total !== null && input.done >= total) ? "complete" : "partial",
664
+ updated_at: updated,
665
+ cursor_age_ms: updated === null ? null : Math.max(0, (input.now ?? /* @__PURE__ */ new Date()).getTime() - Date.parse(updated))
666
+ };
667
+ }, "progressOf");
668
+ var ago = /* @__PURE__ */ __name((ms) => {
669
+ const minutes = Math.round(ms / 6e4);
670
+ if (minutes < 1)
671
+ return "just now";
672
+ if (minutes < 60)
673
+ return `${minutes}m ago`;
674
+ const hours = Math.round(minutes / 60);
675
+ return hours < 48 ? `${hours}h ago` : `${Math.round(hours / 24)}d ago`;
676
+ }, "ago");
677
+ var progressLine = /* @__PURE__ */ __name((progress) => {
678
+ const count = /* @__PURE__ */ __name((n) => n.toLocaleString("en-US"), "count");
679
+ const of = progress.total === null ? count(progress.done) : `${count(progress.done)} of ${count(progress.total)} (${progress.total === 0 ? 100 : Math.floor(progress.done / progress.total * 100)}%), ${count(progress.remaining ?? 0)} left`;
680
+ const when = progress.cursor_age_ms === null ? "" : `, updated ${ago(progress.cursor_age_ms)}`;
681
+ return `${progress.job} ${progress.profile}: ${of} \u2014 ${progress.state}${when}`;
682
+ }, "progressLine");
683
+
684
+ export {
685
+ progressOf,
686
+ progressLine,
687
+ envName,
688
+ readOnlyLockOf,
689
+ mailHolderVariable,
690
+ MESSENGER_CHANGE_REFUSAL,
691
+ readOnlyRefusal,
692
+ logAttributes,
693
+ fromLogAttributes,
694
+ snakeLogger,
695
+ LOG_ATTRIBUTES,
696
+ KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
697
+ RUNS_SIZE_LIMIT_MB,
698
+ runsDirFor,
699
+ startRun,
700
+ runtime,
701
+ newRunId,
702
+ listRuns,
703
+ findRun,
704
+ readEvents,
705
+ currentRun,
706
+ inRun,
707
+ runEvent,
708
+ typedCommand,
709
+ useAsProcessRun,
710
+ processRun,
711
+ enclosingTraceId,
712
+ traceOf,
713
+ childTrace,
714
+ withAttempt,
715
+ currentAttempt,
716
+ runBudget,
717
+ sentIds,
718
+ withWriteScope,
719
+ stopWrites,
720
+ currentOperation,
721
+ guardedWrite,
722
+ codeOf
723
+ };