@wirecat/amo-cli 0.4.0 → 0.6.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 (173) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/contracts/wirecat.json +2 -1
  3. package/dist/amo/allow-list.d.ts +1 -1
  4. package/dist/amo/allow-list.d.ts.map +1 -1
  5. package/dist/amo/oauth.d.ts.map +1 -1
  6. package/dist/amo/oauth.js +3 -4
  7. package/dist/amo/oauth.js.map +1 -1
  8. package/dist/amo/operation.d.ts +1 -1
  9. package/dist/amo/operation.d.ts.map +1 -1
  10. package/dist/amo/transport.d.ts.map +1 -1
  11. package/dist/amo/transport.js +3 -6
  12. package/dist/amo/transport.js.map +1 -1
  13. package/dist/bin/amo.js +2 -2
  14. package/dist/bundle/agent-VVACEKSX.js +42 -0
  15. package/dist/bundle/{all-profiles-PRNXEZRH.js → all-profiles-QNUKL4NA.js} +11 -11
  16. package/dist/bundle/amo.js +28 -28
  17. package/dist/bundle/{anthropic-FDI24DU2.js → anthropic-PQN6MNP7.js} +5 -5
  18. package/dist/bundle/{app-server-WAKJVDLN.js → app-server-Q2QEA7GP.js} +71 -69
  19. package/dist/bundle/areas-27FRPBF3.js +71 -0
  20. package/dist/bundle/{bun-YPXUXMBI.js → bun-F4M4KCNA.js} +2 -2
  21. package/dist/bundle/{bun-sqlite-UBQ5M47X.js → bun-sqlite-P5IDBDVR.js} +6 -6
  22. package/dist/bundle/{chunk-G3LAYJJJ.js → chunk-22KAQPX7.js} +4 -4
  23. package/dist/bundle/{chunk-XEYT2EQT.js → chunk-2JGNMZ55.js} +6 -6
  24. package/dist/bundle/{chunk-PL7TNKAY.js → chunk-2VDHC7QO.js} +2 -2
  25. package/dist/bundle/{chunk-BCIZAUDV.js → chunk-34ZOMVUK.js} +9 -9
  26. package/dist/bundle/{chunk-SHOSFYI7.js → chunk-3J3EDSXF.js} +20 -84
  27. package/dist/bundle/{chunk-ELAKOEIO.js → chunk-3TYER5IK.js} +14 -6
  28. package/dist/bundle/{chunk-NFWD4QX3.js → chunk-5NGLCDYQ.js} +2 -2
  29. package/dist/bundle/{chunk-NKYWQTS2.js → chunk-5SQTHOBI.js} +270 -252
  30. package/dist/bundle/{chunk-Z2B3VNRI.js → chunk-6GE36KUE.js} +11 -11
  31. package/dist/bundle/{chunk-GQKEMBM6.js → chunk-6GZKY3HV.js} +121 -36
  32. package/dist/bundle/{chunk-M54YKD3I.js → chunk-6OV2TRGF.js} +7 -7
  33. package/dist/bundle/{chunk-MW7HUD6R.js → chunk-7CPIZFOE.js} +9 -9
  34. package/dist/bundle/{chunk-TIR3AB35.js → chunk-A5K2NU3K.js} +913 -795
  35. package/dist/bundle/{chunk-5HZMXHRH.js → chunk-AEC4H5WZ.js} +6 -6
  36. package/dist/bundle/{chunk-WAFB3IWJ.js → chunk-APBEDWOE.js} +5 -5
  37. package/dist/bundle/{chunk-V5SETIQK.js → chunk-AQ5RIOUE.js} +1 -1
  38. package/dist/bundle/{chunk-RQPB2BSH.js → chunk-B7L5MSRP.js} +2 -2
  39. package/dist/bundle/{chunk-HZZ56JO7.js → chunk-C7JPYWYQ.js} +1 -1
  40. package/dist/bundle/{chunk-KRD375P7.js → chunk-DIZEHPS6.js} +39 -30
  41. package/dist/bundle/{chunk-TCSVW7BA.js → chunk-DNCLQPOM.js} +1 -1
  42. package/dist/bundle/{chunk-WASBOYI2.js → chunk-DPV53EZC.js} +4 -4
  43. package/dist/bundle/{chunk-HDZNSOV5.js → chunk-DUPCDJ3W.js} +14 -10
  44. package/dist/bundle/{chunk-YHVHDRED.js → chunk-DWT24UVR.js} +6 -6
  45. package/dist/bundle/chunk-DXWJORSY.js +1703 -0
  46. package/dist/bundle/{chunk-E3EWS6DF.js → chunk-DY3PLWIH.js} +6 -6
  47. package/dist/bundle/{chunk-A4W7J6VN.js → chunk-DYWHAJRK.js} +37 -190
  48. package/dist/bundle/{chunk-LAR2DLTI.js → chunk-EXRM3ML4.js} +4 -4
  49. package/dist/bundle/{chunk-ZJC2XJQC.js → chunk-FFER7KJI.js} +13 -13
  50. package/dist/bundle/{chunk-V2QWX6B3.js → chunk-FIP2DG7W.js} +3 -3
  51. package/dist/bundle/{chunk-5II6TAJE.js → chunk-FTH6WGYO.js} +1 -1
  52. package/dist/bundle/{chunk-2AIG2SSJ.js → chunk-FWRLGIF6.js} +1668 -169
  53. package/dist/bundle/{chunk-DWD3KDJA.js → chunk-FYOPPKAN.js} +1 -1
  54. package/dist/bundle/{chunk-ABMPZL2P.js → chunk-G3N2RHGF.js} +19 -15
  55. package/dist/bundle/{chunk-GBQ76X6T.js → chunk-G46PNDWL.js} +2 -2
  56. package/dist/bundle/{chunk-VG26HDKH.js → chunk-G6NY7LFB.js} +4 -4
  57. package/dist/bundle/{chunk-5SJEJYQZ.js → chunk-GOCMJBEE.js} +3 -3
  58. package/dist/bundle/{chunk-3K6T2G52.js → chunk-GRGCZSES.js} +6 -6
  59. package/dist/bundle/{chunk-4PQECIU2.js → chunk-GVSKLZRD.js} +2 -2
  60. package/dist/bundle/{chunk-UEN5NWNW.js → chunk-GZ7WBU5Y.js} +1 -1
  61. package/dist/bundle/{chunk-KQZTX4LM.js → chunk-HN2LCLGT.js} +19 -19
  62. package/dist/bundle/{chunk-SFZVMKB6.js → chunk-HO4JGD4Q.js} +1 -1
  63. package/dist/bundle/{chunk-SZX7EPPY.js → chunk-HOF7GQWW.js} +4 -4
  64. package/dist/bundle/chunk-HUAHLO6N.js +29 -0
  65. package/dist/bundle/chunk-IDCZ4LWS.js +150 -0
  66. package/dist/bundle/{chunk-23AQD7JU.js → chunk-IN3VL7UU.js} +18 -17
  67. package/dist/bundle/{chunk-QGFURWEP.js → chunk-ISQ23VKV.js} +8 -1
  68. package/dist/bundle/{chunk-PLU2IQXC.js → chunk-JVBCQHCS.js} +3 -3
  69. package/dist/bundle/{chunk-VEFAYLKX.js → chunk-K5W7YEHB.js} +187 -114
  70. package/dist/bundle/{chunk-PIOR6PIO.js → chunk-KAFSS35C.js} +2 -2
  71. package/dist/bundle/{chunk-VG2ERHFJ.js → chunk-KLRCTMES.js} +3 -3
  72. package/dist/bundle/{chunk-KORZEYZN.js → chunk-KYRYD4CR.js} +1 -1
  73. package/dist/bundle/{chunk-FEUNZG7U.js → chunk-LBZSURLL.js} +38 -38
  74. package/dist/bundle/{chunk-EAX5RO7S.js → chunk-LC7ZD2RW.js} +1 -1
  75. package/dist/bundle/{chunk-O3WE5IGP.js → chunk-LH6FJYMO.js} +6 -6
  76. package/dist/bundle/{chunk-DWA5TZMP.js → chunk-LJKINNWC.js} +8 -8
  77. package/dist/bundle/{chunk-U46RNOEQ.js → chunk-M36XP74N.js} +3 -3
  78. package/dist/bundle/chunk-MNPGZCKE.js +361 -0
  79. package/dist/bundle/{chunk-WR2FPZTE.js → chunk-MRPMORLH.js} +8 -8
  80. package/dist/bundle/{chunk-CEBX63XY.js → chunk-NNREILWP.js} +8 -8
  81. package/dist/bundle/chunk-NSOY4FMN.js +159 -0
  82. package/dist/bundle/{chunk-SNBYFQHT.js → chunk-OEEWVKJX.js} +1 -1
  83. package/dist/bundle/{chunk-YREKMP24.js → chunk-OGJFDKDL.js} +4 -4
  84. package/dist/bundle/chunk-PATZAYFZ.js +453 -0
  85. package/dist/bundle/chunk-PCR6GFNP.js +1171 -0
  86. package/dist/bundle/{chunk-3PCVQCCV.js → chunk-Q4MH2O5E.js} +2 -2
  87. package/dist/bundle/{chunk-7OVTUADG.js → chunk-QFOP3KUP.js} +8 -8
  88. package/dist/bundle/{chunk-YFRTEJ6V.js → chunk-QQRJEWKB.js} +7 -7
  89. package/dist/bundle/{chunk-GJBOZAUD.js → chunk-RNWUCAJJ.js} +3 -3
  90. package/dist/bundle/{chunk-AP3CWDRK.js → chunk-S6JG4YUH.js} +2 -2
  91. package/dist/bundle/{chunk-KBAOJISR.js → chunk-SDVUGWD7.js} +7 -7
  92. package/dist/bundle/{chunk-WEWJA42Q.js → chunk-SEFE6PGL.js} +12 -12
  93. package/dist/bundle/{chunk-6PILR4AX.js → chunk-SWCJM3YD.js} +2 -2
  94. package/dist/bundle/{chunk-TEGQVVCZ.js → chunk-SYRDEMQE.js} +16709 -13048
  95. package/dist/bundle/{chunk-NXNUCGGO.js → chunk-SYYQZDHJ.js} +6 -6
  96. package/dist/bundle/{chunk-SMM7GS4Q.js → chunk-T3W4V4A6.js} +1 -1
  97. package/dist/bundle/{chunk-EBNCUQLV.js → chunk-TCT5D2X2.js} +1 -1
  98. package/dist/bundle/{chunk-ASU63X5C.js → chunk-TES7MB6I.js} +2 -2
  99. package/dist/bundle/{chunk-745FMNI5.js → chunk-TXDR6YSF.js} +1 -1
  100. package/dist/bundle/{chunk-3WG4MTQI.js → chunk-TY7NDMFY.js} +1 -1
  101. package/dist/bundle/{chunk-AN6IJYH3.js → chunk-U6XPWCWM.js} +5 -5
  102. package/dist/bundle/{chunk-LZ4IWN43.js → chunk-UFKC7TIX.js} +1617 -1990
  103. package/dist/bundle/{chunk-IPNIF5JE.js → chunk-UNWF3TH5.js} +4 -4
  104. package/dist/bundle/{chunk-6QMSKJB4.js → chunk-W3BOR6AT.js} +8 -8
  105. package/dist/bundle/{chunk-SCMB4LI6.js → chunk-WIHN3ELW.js} +19 -19
  106. package/dist/bundle/{chunk-UCM7C773.js → chunk-X76RS6JO.js} +178 -61
  107. package/dist/bundle/{chunk-GMHRPX5M.js → chunk-YF3S26TS.js} +61 -61
  108. package/dist/bundle/{chunk-ZKRWNL4T.js → chunk-ZCQ4H7CA.js} +2 -2
  109. package/dist/bundle/{chunk-CYHIM5SL.js → chunk-ZOZV32IR.js} +3 -3
  110. package/dist/bundle/{chunk-OYMHPQF7.js → chunk-ZTKHXDEU.js} +4 -4
  111. package/dist/bundle/{cli-QDPKC2HJ.js → cli-EAD3WZLR.js} +119 -105
  112. package/dist/bundle/command-contract-SMEJ2ICG.js +40 -0
  113. package/dist/bundle/{command-server-entry-TX7WNN7G.js → command-server-entry-YTZP6I4T.js} +29 -28
  114. package/dist/bundle/{decode-BLPC7OYE.js → decode-57BE5OBT.js} +5 -5
  115. package/dist/bundle/{dispatch-5JUT55CS.js → dispatch-56FECRCU.js} +8 -8
  116. package/dist/bundle/{echarts-54D3FOCL.js → echarts-QMAA7HH5.js} +2 -2
  117. package/dist/bundle/{embed-O7KMDYM7.js → embed-NFGFYUO4.js} +6 -6
  118. package/dist/bundle/{embedder-4PE67CLX.js → embedder-SRBOJMXX.js} +9 -9
  119. package/dist/bundle/{failure-NNQYTB3Z.js → failure-WDSX6H3B.js} +2 -2
  120. package/dist/bundle/{first-run-EAU5SHBI.js → first-run-HWRUL2GR.js} +12 -12
  121. package/dist/bundle/first-screen-ATN4D3FQ.js +41 -0
  122. package/dist/bundle/{instructions-ONXP5DZQ.js → instructions-4H7UREH2.js} +1 -1
  123. package/dist/bundle/{mcp-ZNULRPZ4.js → mcp-5HFPWC3W.js} +2 -2
  124. package/dist/bundle/meeting-combined-BGDEHCWY.js +26 -0
  125. package/dist/bundle/{meeting-model-FWIZRKVN.js → meeting-model-WWGVRXPL.js} +11 -11
  126. package/dist/bundle/{meeting-semantic-M4YVJ57W.js → meeting-semantic-ZQ47BL2Z.js} +6 -6
  127. package/dist/bundle/{node-UTQCYQF5.js → node-P3PUHKYH.js} +2 -2
  128. package/dist/bundle/{node-sqlite-APJG6MGL.js → node-sqlite-JOTSNH3P.js} +7 -7
  129. package/dist/bundle/{oauth-TY7RMIBL.js → oauth-XPSAL6VO.js} +7 -7
  130. package/dist/bundle/{open-WDVEQL75.js → open-PO52FVA5.js} +5 -5
  131. package/dist/bundle/{openai-H5UJHSEZ.js → openai-WITYLMY5.js} +15 -15
  132. package/dist/bundle/{process-MGMXXPMY.js → process-AFIXYXWL.js} +1 -1
  133. package/dist/bundle/{program-IF36C6VR.js → program-JODTZNBZ.js} +331 -196
  134. package/dist/bundle/{prompt-4RLIWLMF.js → prompt-XORLAXHY.js} +5 -5
  135. package/dist/bundle/{recognize-UIRTMWM4.js → recognize-JKMZHDYS.js} +4 -4
  136. package/dist/bundle/{remote-L3MNWZQK.js → remote-3IMEJTEH.js} +9 -9
  137. package/dist/bundle/{rerank-F4KZQTY6.js → rerank-3F2E6NNN.js} +7 -7
  138. package/dist/bundle/{serve-37AUYTWS.js → serve-6BWU3NMB.js} +9 -9
  139. package/dist/bundle/{server-UBG676ZJ.js → server-GPSB5WFG.js} +63 -61
  140. package/dist/bundle/server-HMCC64ZU.js +88 -0
  141. package/dist/bundle/source-E72OS27D.js +47 -0
  142. package/dist/bundle/{sqlite-runtime-CI3RW7VA.js → sqlite-runtime-YHYQDUXE.js} +6 -6
  143. package/dist/bundle/{state-JOHLSLUO.js → state-R7W4U6T4.js} +6 -6
  144. package/dist/bundle/{store-OSOUXBYL.js → store-HTVRL7FB.js} +56 -43
  145. package/dist/bundle/store-IWW6U6QN.js +34 -0
  146. package/dist/bundle/{store-2MBG4IUS.js → store-TBZ3ZS6H.js} +25 -23
  147. package/dist/bundle/store-maintenance-command-CJM2VLMW.js +75 -0
  148. package/dist/bundle/surface-5GBWNYBE.js +74 -0
  149. package/dist/bundle/writer-TW2Q55VJ.js +49 -0
  150. package/dist/commands/crm-shared.js +1 -1
  151. package/dist/commands/crm-shared.js.map +1 -1
  152. package/dist/commands/session.d.ts.map +1 -1
  153. package/dist/commands/session.js +1 -6
  154. package/dist/commands/session.js.map +1 -1
  155. package/dist/version.d.ts +1 -1
  156. package/dist/version.js +1 -1
  157. package/package.json +4 -4
  158. package/skills/amo-cli/SKILL.md +6 -0
  159. package/dist/bundle/agent-43BMVBX2.js +0 -40
  160. package/dist/bundle/chunk-2UJ7ZZZC.js +0 -79
  161. package/dist/bundle/chunk-FQRP6JWX.js +0 -29
  162. package/dist/bundle/chunk-IBEHYGG6.js +0 -721
  163. package/dist/bundle/chunk-M33XHJTM.js +0 -1266
  164. package/dist/bundle/chunk-S6DTLAOB.js +0 -761
  165. package/dist/bundle/command-contract-KWNCP3MQ.js +0 -39
  166. package/dist/bundle/first-screen-APSNGZYZ.js +0 -39
  167. package/dist/bundle/meeting-combined-W2XIYXFU.js +0 -24
  168. package/dist/bundle/server-CRF4QSZR.js +0 -86
  169. package/dist/bundle/source-Z7GH7T4B.js +0 -44
  170. package/dist/bundle/store-SNW6U32Y.js +0 -34
  171. package/dist/bundle/store-maintenance-command-W7V54SLT.js +0 -73
  172. package/dist/bundle/surface-ESJS2FUI.js +0 -72
  173. package/dist/bundle/writer-BJDQMKUV.js +0 -46
@@ -1,26 +1,66 @@
1
1
  import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ WIRECAT_TOOLS
5
+ } from "./chunk-ISQ23VKV.js";
3
6
  import {
4
7
  LIST_QUERY_GUIDE,
5
- timeBounds
6
- } from "./chunk-ABMPZL2P.js";
8
+ queryTerms,
9
+ termField,
10
+ timeBounds,
11
+ withQuery
12
+ } from "./chunk-G3N2RHGF.js";
7
13
  import {
14
+ API_UNTRUSTED,
15
+ Command,
8
16
  MESSENGER_CHANGE_REFUSAL,
17
+ NO_EFFECTS,
18
+ Option,
19
+ REMOTE_READ,
20
+ REMOTE_WRITE,
21
+ ancestorValue,
22
+ annotate,
23
+ baseContext,
9
24
  envName,
25
+ environmentOf,
10
26
  guardedWrite,
27
+ issueMessage,
28
+ itemOf,
29
+ listOf,
30
+ marksUntrusted,
31
+ metaOf,
32
+ outputFor,
33
+ permissionIssues,
11
34
  progressLine,
12
35
  progressOf,
36
+ publicIssue,
37
+ readOnlyLockOf,
13
38
  readOnlyRefusal,
14
- runBudget
15
- } from "./chunk-NKYWQTS2.js";
39
+ renderAnswer,
40
+ rootOf,
41
+ runBudget,
42
+ startRecording,
43
+ wasSettled
44
+ } from "./chunk-5SQTHOBI.js";
45
+ import {
46
+ keepsSuccess,
47
+ providerErrorKey,
48
+ runContextOf,
49
+ secretInput
50
+ } from "./chunk-6OV2TRGF.js";
16
51
  import {
17
52
  crmIdentityId,
18
53
  crmSettingKey,
19
54
  seenBy
20
- } from "./chunk-TEGQVVCZ.js";
55
+ } from "./chunk-SYRDEMQE.js";
21
56
  import {
57
+ KEEP_RUNS_FOR_DAYS,
58
+ KEEP_STORE_RUNS_FOR_DAYS,
59
+ KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
22
60
  LOG_ATTRIBUTES,
61
+ RUNS_SIZE_LIMIT_MB,
23
62
  accountsOfList,
63
+ currentAttempt,
24
64
  currentRun,
25
65
  entriesOfList,
26
66
  fitting,
@@ -29,52 +69,71 @@ import {
29
69
  isGroupName,
30
70
  keyOf,
31
71
  logAttributes,
72
+ runEvent,
32
73
  sameAs,
33
74
  sourceOf3 as sourceOf
34
- } from "./chunk-M33XHJTM.js";
75
+ } from "./chunk-PCR6GFNP.js";
35
76
  import {
36
77
  isCliFailure
37
- } from "./chunk-ELAKOEIO.js";
78
+ } from "./chunk-3TYER5IK.js";
38
79
  import {
80
+ hostFetch,
81
+ providerWaitMs,
82
+ readJsonResponse,
83
+ statusToCode
84
+ } from "./chunk-DY3PLWIH.js";
85
+ import {
86
+ AUTHORITY_KEY,
39
87
  CEILING_KEY,
40
88
  DEFAULT_PERMISSIONS,
89
+ KEYED_UNDER_HOUSEKEEPING,
41
90
  STORE_ONLY_KEYS,
91
+ WRITE_KEYS,
92
+ keyForCommand,
42
93
  keyForWrite,
43
94
  levelFor,
44
95
  skipFlagFor,
45
96
  stops
46
- } from "./chunk-KBAOJISR.js";
97
+ } from "./chunk-SDVUGWD7.js";
47
98
  import {
48
99
  e164Of,
49
100
  foldName
50
- } from "./chunk-SHOSFYI7.js";
101
+ } from "./chunk-3J3EDSXF.js";
51
102
  import {
52
103
  CRM_KINDS,
53
104
  DEAL_KINDS,
54
- INTERNAL_NOTES,
55
105
  STAGE_OUTCOMES,
56
106
  currencyOf,
57
- holdsKindOf,
58
107
  isCrmUserId,
108
+ isItemKind,
109
+ minorUnits,
110
+ normalCrmUserId
111
+ } from "./chunk-MNPGZCKE.js";
112
+ import {
113
+ INTERNAL_NOTES,
114
+ alsoListedByKey,
115
+ holdsKindOf,
59
116
  isDocumentAccountProvider,
60
117
  isFolderProvider,
61
- isItemKind,
62
118
  isKind,
63
- minorUnits,
64
- normalCrmUserId,
65
119
  providerNamed
66
- } from "./chunk-S6DTLAOB.js";
120
+ } from "./chunk-PATZAYFZ.js";
67
121
  import {
68
122
  parseLucene,
69
123
  walkQuery
70
- } from "./chunk-GMHRPX5M.js";
124
+ } from "./chunk-YF3S26TS.js";
125
+ import {
126
+ storePath,
127
+ wirecatDirectory
128
+ } from "./chunk-ZCQ4H7CA.js";
71
129
  import {
72
130
  backoffMs,
73
131
  logRecordOf,
74
132
  realSleep,
75
133
  resolvePaths,
134
+ wallClock,
76
135
  writeSecurely
77
- } from "./chunk-SCMB4LI6.js";
136
+ } from "./chunk-WIHN3ELW.js";
78
137
  import {
79
138
  array,
80
139
  boolean,
@@ -95,17 +154,233 @@ import {
95
154
  string,
96
155
  union,
97
156
  unknown
98
- } from "./chunk-7OVTUADG.js";
157
+ } from "./chunk-QFOP3KUP.js";
99
158
  import {
100
159
  CliError,
101
160
  isCliError
102
- } from "./chunk-AP3CWDRK.js";
161
+ } from "./chunk-S6JG4YUH.js";
103
162
  import {
104
163
  __export,
105
164
  __name
106
165
  } from "./chunk-ZVVMGPBJ.js";
107
166
 
108
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/values.js
167
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/upload.js
168
+ import { openAsBlob, realpathSync } from "node:fs";
169
+ import { open, stat } from "node:fs/promises";
170
+ import { basename, dirname, extname, isAbsolute, relative, resolve, sep } from "node:path";
171
+ var MAX_BUFFERED_UPLOAD_BYTES = 256 * 1024 * 1024;
172
+ var uploadSize = /* @__PURE__ */ __name((source) => source.kind === "file" ? source.size : source.bytes.byteLength, "uploadSize");
173
+ var PHOTO = /* @__PURE__ */ new Set([".jpg", ".jpeg", ".png", ".webp"]);
174
+ var VOICE = /* @__PURE__ */ new Set([".ogg", ".oga", ".opus"]);
175
+ var JPEG = /* @__PURE__ */ __name((head) => head[0] === 255 && head[1] === 216 && head[2] === 255, "JPEG");
176
+ var SIGNATURES = {
177
+ ".jpg": JPEG,
178
+ ".jpeg": JPEG,
179
+ ".png": /* @__PURE__ */ __name((head) => Buffer.from(head.subarray(0, 8)).toString("latin1") === "\x89PNG\r\n\n", ".png"),
180
+ ".webp": /* @__PURE__ */ __name((head) => {
181
+ const text2 = Buffer.from(head).toString("latin1");
182
+ return text2.startsWith("RIFF") && text2.slice(8, 12) === "WEBP";
183
+ }, ".webp")
184
+ };
185
+ var fileHead = /* @__PURE__ */ __name(async (path2) => {
186
+ const file = await open(path2, "r");
187
+ try {
188
+ const head = new Uint8Array(12);
189
+ const { bytesRead } = await file.read(head, 0, head.length, 0);
190
+ return head.subarray(0, bytesRead);
191
+ } finally {
192
+ await file.close();
193
+ }
194
+ }, "fileHead");
195
+ var typesText = /* @__PURE__ */ __name((types) => types.length < 2 ? types[0] ?? "" : `${types.slice(0, -1).join(", ")} or ${types.at(-1)}`, "typesText");
196
+ var CREDENTIAL_PARTS = /* @__PURE__ */ new Set([
197
+ ".ssh",
198
+ ".gnupg",
199
+ ".aws",
200
+ ".azure",
201
+ ".kube",
202
+ ".secrets",
203
+ "secrets",
204
+ ".password-store",
205
+ ".mozilla",
206
+ ".env",
207
+ ".npmrc",
208
+ ".pypirc",
209
+ ".netrc",
210
+ "_netrc",
211
+ ".git-credentials",
212
+ "credentials.yml.enc",
213
+ "master.key"
214
+ ]);
215
+ var CREDENTIAL_RUNS = [
216
+ [".config", "autostart"],
217
+ [".config", "git", "credentials"],
218
+ [".config", "gh"],
219
+ [".config", "gcloud"],
220
+ [".config", "google-chrome"],
221
+ [".config", "chromium"],
222
+ [".config", "microsoft-edge"],
223
+ [".config", "BraveSoftware"],
224
+ [".docker", "config.json"],
225
+ [".claude", ".credentials.json"],
226
+ [".codex", "auth.json"],
227
+ [".local", "share", "keyrings"],
228
+ ["Library", "Keychains"],
229
+ ["Library", "Cookies"],
230
+ ["Library", "Safari"],
231
+ ["Library", "Application Support", "Google", "Chrome"],
232
+ ["Library", "Application Support", "Chromium"],
233
+ ["Library", "Application Support", "Microsoft Edge"],
234
+ ["Library", "Application Support", "BraveSoftware"],
235
+ ["Library", "Application Support", "Firefox"],
236
+ ["AppData", "Local", "Google", "Chrome"],
237
+ ["AppData", "Local", "Chromium"],
238
+ ["AppData", "Local", "Microsoft", "Edge"],
239
+ ["AppData", "Local", "BraveSoftware"],
240
+ ["AppData", "Roaming", "Mozilla", "Firefox"],
241
+ ["AppData", "Local", "Microsoft", "Credentials"],
242
+ ["AppData", "Roaming", "Microsoft", "Credentials"],
243
+ ["AppData", "Roaming", "Microsoft", "Protect"],
244
+ ["AppData", "Roaming", "gcloud"],
245
+ ["AppData", "Roaming", "GitHub CLI"]
246
+ ];
247
+ var WIRECAT_APPS = [
248
+ ...WIRECAT_TOOLS.map(({ appName, envPrefix }) => ({ appName, prefix: envPrefix })),
249
+ { appName: "beeline-cli", prefix: "BEELINE" },
250
+ { appName: "zm", prefix: "ZM" },
251
+ { appName: "cli-messaging", prefix: "MESSAGING" },
252
+ { appName: "cli-common", prefix: "CLI_COMMON" }
253
+ ];
254
+ var SYSTEM_ROOTS = ["/proc", "/sys", "/dev"];
255
+ var systemPlace = /* @__PURE__ */ __name((path2, platform) => platform !== "win32" && SYSTEM_ROOTS.some((root) => inside(path2, root)), "systemPlace");
256
+ var realPathOf = /* @__PURE__ */ __name((path2) => {
257
+ let ancestor = resolve(path2);
258
+ for (; ; ) {
259
+ try {
260
+ return resolve(realpathSync(ancestor), relative(ancestor, resolve(path2)));
261
+ } catch {
262
+ const parent = dirname(ancestor);
263
+ if (parent === ancestor)
264
+ return resolve(path2);
265
+ ancestor = parent;
266
+ }
267
+ }
268
+ }, "realPathOf");
269
+ var refuseLockedOutput = /* @__PURE__ */ __name((path2, app, env, flag) => {
270
+ const lock = readOnlyLockOf(app, env);
271
+ if (lock === void 0)
272
+ return;
273
+ const named2 = ancestorValue(envName(app, "WORK_FOLDER"), env);
274
+ const work = named2 ? realPathOf(named2) : void 0;
275
+ const real = realPathOf(path2);
276
+ if (work !== void 0 && (real === work || real.startsWith(`${work}${sep}`)))
277
+ return;
278
+ throw new CliError("permission_error", work === void 0 ? `this process is read-only (${lock}) \u2014 ${flag} writes a file only inside a scheduled run's work folder` : `this process is read-only (${lock}) \u2014 ${flag} writes only inside its run's work folder, ${work}`, { reason: "read-only.output-outside", param: flag });
279
+ }, "refuseLockedOutput");
280
+ var refusedPlace = /* @__PURE__ */ __name((path2, app, env, platform = process.platform) => {
281
+ const own = [
282
+ ...[{ appName: app.appName, prefix: app.envPrefix }, ...WIRECAT_APPS].flatMap((one) => Object.values(resolvePaths({ ...one, env, platform }))),
283
+ // The shared WireCat folder: the store, its backups beside it, the models.
284
+ wirecatDirectory(env, platform)
285
+ ];
286
+ const store = resolve(storePath(env));
287
+ const real = realPathOf(path2);
288
+ const folded = platform === "darwin" || platform === "win32";
289
+ const fold = /* @__PURE__ */ __name((text2) => folded ? text2.toLowerCase() : text2, "fold");
290
+ const parts = new Set([...CREDENTIAL_PARTS].map(fold));
291
+ const runs = CREDENTIAL_RUNS.map((run) => run.map(fold));
292
+ const named2 = /* @__PURE__ */ __name((candidate) => {
293
+ const names = candidate.split(sep).map(fold);
294
+ return names.some((name, index) => parts.has(name) || /^\.env\./.test(name) || runs.some((run) => run.every((part, offset) => names[index + offset] === part)));
295
+ }, "named");
296
+ const same = /* @__PURE__ */ __name((a, b) => fold(a) === fold(b), "same");
297
+ return [resolve(path2), real].some((candidate) => systemPlace(candidate, platform) || named2(candidate) || own.some((dir) => inside(fold(candidate), fold(dir))) || [store, `${store}-wal`, `${store}-shm`].some((file) => same(candidate, file)));
298
+ }, "refusedPlace");
299
+ var inside = /* @__PURE__ */ __name((path2, dir) => {
300
+ const way = relative(resolve(dir), path2);
301
+ return way === "" || !way.startsWith("..") && !isAbsolute(way);
302
+ }, "inside");
303
+ var readUpload = /* @__PURE__ */ __name(async (kind2, path2, { app, env = process.env, anyFile = false, photoTypes }) => {
304
+ const extension = extname(path2).toLowerCase();
305
+ if (kind2 === "photo" && photoTypes !== void 0 && !photoTypes.includes(extension)) {
306
+ throw new CliError("validation_error", `this photo must be a ${typesText(photoTypes)} file, not ${path2}`);
307
+ }
308
+ if (kind2 === "photo" && photoTypes === void 0 && !PHOTO.has(extension)) {
309
+ throw new CliError("validation_error", `a photo is a .jpg, .png or .webp \u2014 send ${path2} as a file instead`);
310
+ }
311
+ if (kind2 === "voice" && !VOICE.has(extension)) {
312
+ throw new CliError("validation_error", `a voice message is Ogg Opus: .ogg, .oga or .opus \u2014 send ${path2} as a file`);
313
+ }
314
+ if ([resolve(path2), realPathOf(path2)].some((candidate) => systemPlace(candidate, process.platform))) {
315
+ throw new CliError("validation_error", `cannot send ${path2}: a file under /proc, /sys or /dev is never sent`);
316
+ }
317
+ if (!anyFile && refusedPlace(path2, app, env)) {
318
+ throw new CliError("validation_error", `cannot send ${path2}: known credential files, browser profiles, the WireCat apps' folders and the message store are not sent \u2014 the owner adds --allow-any-file to the command if this file is meant to go`);
319
+ }
320
+ let size;
321
+ let head;
322
+ try {
323
+ const info = await stat(path2);
324
+ if (!info.isFile())
325
+ throw Object.assign(new Error("not a file"), { code: "EISDIR" });
326
+ size = info.size;
327
+ if (photoTypes !== void 0 && SIGNATURES[extension] !== void 0)
328
+ head = await fileHead(path2);
329
+ } catch (error) {
330
+ const code = error.code;
331
+ const reason = code === "ENOENT" ? "no such file" : code === "EISDIR" ? "it is a folder" : "it cannot be read";
332
+ throw new CliError("validation_error", `cannot send ${path2}: ${reason}`);
333
+ }
334
+ if (head !== void 0 && SIGNATURES[extension]?.(head) !== true) {
335
+ throw new CliError("validation_error", `${path2} is not a ${typesText(photoTypes ?? [])} image inside`);
336
+ }
337
+ return { kind: kind2, name: basename(path2), source: { kind: "file", path: resolve(path2), size } };
338
+ }, "readUpload");
339
+ var checkFilename = /* @__PURE__ */ __name((filename, files) => {
340
+ if (files.length === 0)
341
+ throw new CliError("validation_error", "--filename names a --file; give one");
342
+ if (files.length > 1)
343
+ throw new CliError("validation_error", "--filename names one --file; an album keeps its names");
344
+ if (filename.trim() === "" || /[/\\\0]/.test(filename) || filename.length > 255)
345
+ throw new CliError("validation_error", "--filename is a name, not a path: no / or \\, at most 255 characters");
346
+ }, "checkFilename");
347
+ var listOf2 = /* @__PURE__ */ __name((value) => value === void 0 ? [] : typeof value === "string" ? [value] : value, "listOf");
348
+ var readAttachments = /* @__PURE__ */ __name(async ({ photo, file, voice, asFile, filename, text: text2 }, read) => {
349
+ const photos = listOf2(photo);
350
+ const files = listOf2(file);
351
+ if (voice !== void 0 && (photos.length > 0 || files.length > 0 || (text2 ?? "").trim() !== "")) {
352
+ throw new CliError("validation_error", "a voice message goes alone \u2014 no text, no file, no photo beside it");
353
+ }
354
+ if (asFile && files.length === 0)
355
+ throw new CliError("validation_error", "--as-file is about a --file; give one");
356
+ if (filename !== void 0)
357
+ checkFilename(filename, files);
358
+ const uploads = [];
359
+ for (const one of photos)
360
+ uploads.push(await readUpload("photo", one, read));
361
+ for (const one of files)
362
+ uploads.push({
363
+ ...await readUpload("file", one, read),
364
+ ...filename === void 0 ? {} : { name: filename },
365
+ ...asFile ? { asFile: true } : {}
366
+ });
367
+ if (voice !== void 0)
368
+ uploads.push(await readUpload("voice", voice, read));
369
+ return uploads;
370
+ }, "readAttachments");
371
+ var readStickerFile = /* @__PURE__ */ __name(async (path2, maxBytes, read) => {
372
+ if (extname(path2).toLowerCase() !== ".webp")
373
+ throw new CliError("validation_error", `a sticker is a .webp \u2014 send ${path2} as a photo or a file instead`);
374
+ const { name, source } = await readUpload("file", path2, read);
375
+ if (SIGNATURES[".webp"]?.(await fileHead(path2)) !== true)
376
+ throw new CliError("validation_error", `${path2} is named .webp but is not a WebP image \u2014 nothing was sent`);
377
+ const size = uploadSize(source);
378
+ if (size > maxBytes)
379
+ throw new CliError("validation_error", `the sticker is ${Math.ceil(size / 1024)} KiB, and this messenger takes at most ${Math.floor(maxBytes / 1024)} KiB \u2014 nothing was sent`);
380
+ return { name, source };
381
+ }, "readStickerFile");
382
+
383
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/values.js
109
384
  var values_exports = {};
110
385
  __export(values_exports, {
111
386
  amountOf: () => amountOf,
@@ -122,10 +397,10 @@ __export(values_exports, {
122
397
  time: () => time
123
398
  });
124
399
 
125
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/source.js
400
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/source.js
126
401
  var CRM_FILE_SOURCES = ["record", "field", "document", "activity", "comment"];
127
402
 
128
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/files.js
403
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/files.js
129
404
  var parseCrmFileId = /* @__PURE__ */ __name((id2) => {
130
405
  const [kind2 = "", owner = "", source = "", ...rest] = id2.trim().split(":");
131
406
  const providerId = rest.join(":");
@@ -158,7 +433,7 @@ var withoutFileLinks = /* @__PURE__ */ __name((body) => {
158
433
  return walk2(body);
159
434
  }, "withoutFileLinks");
160
435
 
161
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/values.js
436
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/values.js
162
437
  var isRaw = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isRaw");
163
438
  var fieldOf = /* @__PURE__ */ __name((value, key) => isRaw(value) ? value[key] : void 0, "fieldOf");
164
439
  var rawsOf = /* @__PURE__ */ __name((value) => Array.isArray(value) ? value.filter(isRaw) : [], "rawsOf");
@@ -217,10 +492,10 @@ var crmValuesOf = /* @__PURE__ */ __name((values, fields2) => {
217
492
  }));
218
493
  }, "crmValuesOf");
219
494
 
220
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/cli/bot/api-input.js
495
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/bot/api-input.js
221
496
  import { readFileSync } from "node:fs";
222
497
 
223
- // node_modules/.pnpm/@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/names.js
498
+ // node_modules/.pnpm/@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/names.js
224
499
  var pascal = /* @__PURE__ */ __name((text2) => text2.split(/[^A-Za-z0-9]+/).filter(Boolean).map((word) => word[0]?.toUpperCase() + word.slice(1)).join(""), "pascal");
225
500
  var GLOBALS = /* @__PURE__ */ new Set([
226
501
  "Array",
@@ -256,7 +531,16 @@ var identifier = /* @__PURE__ */ __name((id2) => {
256
531
  return GLOBALS.has(name) ? `Api${name}` : name;
257
532
  }, "identifier");
258
533
 
259
- // node_modules/.pnpm/@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/sign-in.js
534
+ // node_modules/.pnpm/@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/selection.js
535
+ var graphqlDocument = /* @__PURE__ */ __name((binding, selection = binding.selection) => {
536
+ const variables = Object.entries(binding.variables);
537
+ const declared = variables.length ? `(${variables.map(([name, type]) => `$${name}: ${type}`).join(", ")})` : "";
538
+ const passed = variables.length ? `(${variables.map(([name]) => `${name}: $${name}`).join(", ")})` : "";
539
+ const inner = selection.trim() ? ` { ${selection.trim()} }` : "";
540
+ return `${binding.operation} ${binding.field[0]?.toUpperCase()}${binding.field.slice(1)}${declared} { ${binding.field}${passed}${inner} }`;
541
+ }, "graphqlDocument");
542
+
543
+ // node_modules/.pnpm/@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/sign-in.js
260
544
  var BEARER = { in: "header", name: "authorization", value: /* @__PURE__ */ __name((token) => `Bearer ${token}`, "value") };
261
545
  var signInPlace = /* @__PURE__ */ __name((scheme) => {
262
546
  if (scheme.type === "apiKey") {
@@ -289,63 +573,10 @@ var signInRequirements = /* @__PURE__ */ __name((operation, document) => {
289
573
  return requirements?.some((one) => Object.keys(one).length > 0) ? requirements : void 0;
290
574
  }, "signInRequirements");
291
575
 
292
- // node_modules/.pnpm/@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/graphql.js
293
- var graphqlDocument = /* @__PURE__ */ __name((binding, selection = binding.selection) => {
294
- const variables = Object.entries(binding.variables);
295
- const declared = variables.length ? `(${variables.map(([name, type]) => `$${name}: ${type}`).join(", ")})` : "";
296
- const passed = variables.length ? `(${variables.map(([name]) => `${name}: $${name}`).join(", ")})` : "";
297
- const inner = selection.trim() ? ` { ${selection.trim()} }` : "";
298
- return `${binding.operation} ${binding.field[0]?.toUpperCase()}${binding.field.slice(1)}${declared} { ${binding.field}${passed}${inner} }`;
299
- }, "graphqlDocument");
300
-
301
- // node_modules/.pnpm/@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/runtime.js
576
+ // node_modules/.pnpm/@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/runtime.js
302
577
  var INT64_MIN = -(2n ** 63n);
303
578
  var INT64_MAX = 2n ** 63n - 1n;
304
579
 
305
- // node_modules/.pnpm/@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/codegen/openapi.js
306
- var IGNORED = /* @__PURE__ */ new Set([
307
- "readOnly",
308
- "example",
309
- "examples",
310
- "externalDocs",
311
- "title",
312
- "xml",
313
- "writeOnly",
314
- "not",
315
- "minProperties",
316
- "maxProperties"
317
- ]);
318
- var KNOWN = /* @__PURE__ */ new Set([
319
- ...IGNORED,
320
- "type",
321
- "format",
322
- "description",
323
- "nullable",
324
- "deprecated",
325
- "default",
326
- "enum",
327
- "const",
328
- "minLength",
329
- "maxLength",
330
- "pattern",
331
- "minimum",
332
- "maximum",
333
- "items",
334
- "prefixItems",
335
- "minItems",
336
- "maxItems",
337
- "uniqueItems",
338
- "properties",
339
- "required",
340
- "additionalProperties",
341
- "allOf",
342
- "oneOf",
343
- "anyOf",
344
- "$ref",
345
- "discriminator"
346
- ]);
347
- var LARGEST_EXAMPLE = 8 * 1024;
348
-
349
580
  // node_modules/.pnpm/lossless-json@4.3.3/node_modules/lossless-json/lib/esm/utils.js
350
581
  function isInteger(value) {
351
582
  return INTEGER_REGEX.test(value);
@@ -869,17 +1100,17 @@ function isDeepEqual(a, b) {
869
1100
  if (Array.isArray(a) && Array.isArray(b)) {
870
1101
  return a.length === b.length && a.every((item, index) => isDeepEqual(item, b[index]));
871
1102
  }
872
- if (isObject2(a) && isObject2(b)) {
1103
+ if (isObject(a) && isObject(b)) {
873
1104
  const keys = [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])];
874
1105
  return keys.every((key) => isDeepEqual(a[key], b[key]));
875
1106
  }
876
1107
  return false;
877
1108
  }
878
1109
  __name(isDeepEqual, "isDeepEqual");
879
- function isObject2(value) {
1110
+ function isObject(value) {
880
1111
  return typeof value === "object" && value !== null;
881
1112
  }
882
- __name(isObject2, "isObject");
1113
+ __name(isObject, "isObject");
883
1114
  var escapeCharacters = {
884
1115
  '"': '"',
885
1116
  "\\": "\\",
@@ -1030,7 +1261,7 @@ function resolveSpace(space) {
1030
1261
  }
1031
1262
  __name(resolveSpace, "resolveSpace");
1032
1263
 
1033
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/cli/bot/api-input.js
1264
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/bot/api-input.js
1034
1265
  var RENAMED = { timeout: "poll-timeout" };
1035
1266
  var apiFlagOf = /* @__PURE__ */ __name((name) => RENAMED[name] ?? name.replace(/_/g, "-").replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), "apiFlagOf");
1036
1267
  var apiOptionKey = /* @__PURE__ */ __name((name) => apiFlagOf(name).replace(/-([a-z0-9])/g, (_, letter) => letter.toUpperCase()), "apiOptionKey");
@@ -1122,6 +1353,7 @@ var finite = /* @__PURE__ */ __name((key, value) => {
1122
1353
  }, "finite");
1123
1354
  var apiJson = /* @__PURE__ */ __name((value) => stringify(value, finite) ?? "null", "apiJson");
1124
1355
  var apiPlainJson = /* @__PURE__ */ __name((value) => JSON.parse(stringify(value, (key, inner) => isLosslessNumber(inner) && !isSafeNumber(inner.value) ? inner.toString() : finite(key, inner)) ?? "null"), "apiPlainJson");
1356
+ var isBlank = /* @__PURE__ */ __name((value) => typeof value === "string" && value.trim() === "", "isBlank");
1125
1357
  var isVariables = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value) && !isLosslessNumber(value), "isVariables");
1126
1358
  var graphqlVariables = /* @__PURE__ */ __name((operation, body, fields2) => {
1127
1359
  const { binding } = operation;
@@ -1142,7 +1374,7 @@ var graphqlVariables = /* @__PURE__ */ __name((operation, body, fields2) => {
1142
1374
  throw new CliError("validation_error", `${operation.command} has no variable ${unknown2.join(", ")}`, {
1143
1375
  sent: false
1144
1376
  });
1145
- const missing = Object.entries(binding.variables).filter(([name, type]) => type.endsWith("!") && variables[name] == null).map(([name]) => `--${apiFlagOf(name)}`);
1377
+ const missing = Object.entries(binding.variables).filter(([name, type]) => type.endsWith("!") && (variables[name] == null || isBlank(variables[name]))).map(([name]) => `--${apiFlagOf(name)}`);
1146
1378
  if (missing.length > 0)
1147
1379
  throw new CliError("validation_error", `${operation.command} needs ${missing.join(", ")}`, { sent: false });
1148
1380
  return variables;
@@ -1169,7 +1401,7 @@ var flagValue = /* @__PURE__ */ __name((operation, name, raw, type) => {
1169
1401
  return raw;
1170
1402
  }, "flagValue");
1171
1403
 
1172
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/cli/service-api-manifest.js
1404
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/service-api-manifest.js
1173
1405
  var manifestBaseUrl = /* @__PURE__ */ __name((manifest, given, variables = {}) => {
1174
1406
  const server = manifest.servers?.[0];
1175
1407
  if (given === void 0 && !server)
@@ -1297,12 +1529,12 @@ var nextPage = /* @__PURE__ */ __name((pagination, input, answer, headers) => {
1297
1529
  }
1298
1530
  }, "nextPage");
1299
1531
 
1300
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/guard.js
1532
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/guard.js
1301
1533
  import { randomUUID } from "node:crypto";
1302
1534
 
1303
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/flood.js
1535
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/flood.js
1304
1536
  import { mkdirSync, readFileSync as readFileSync2, renameSync, writeFileSync } from "node:fs";
1305
- import { dirname, join } from "node:path";
1537
+ import { dirname as dirname2, join } from "node:path";
1306
1538
  var MOST_DEADLINES = 50;
1307
1539
  var LIMITED_HOLD_MS = 60 * 60 * 1e3;
1308
1540
  var FROZEN_HOLD_MS = 24 * 60 * 60 * 1e3;
@@ -1376,7 +1608,7 @@ var FloodMemory = class {
1376
1608
  }
1377
1609
  #write({ sendBlock, ...rest }) {
1378
1610
  const state = sendBlock ? { ...rest, sendBlock: { ...sendBlock, until: sendBlock.until ?? NO_END } } : rest;
1379
- mkdirSync(dirname(this.path), { recursive: true, mode: 448 });
1611
+ mkdirSync(dirname2(this.path), { recursive: true, mode: 448 });
1380
1612
  const temporary = `${this.path}.${process.pid}.tmp`;
1381
1613
  writeFileSync(temporary, `${JSON.stringify(state)}
1382
1614
  `, { mode: 384 });
@@ -1384,39 +1616,39 @@ var FloodMemory = class {
1384
1616
  }
1385
1617
  };
1386
1618
 
1387
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/journal.js
1619
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/journal.js
1388
1620
  import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync3 } from "node:fs";
1389
- import { dirname as dirname3, join as join2 } from "node:path";
1621
+ import { dirname as dirname4, join as join2 } from "node:path";
1390
1622
 
1391
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/file-lock.js
1623
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/file-lock.js
1392
1624
  import { closeSync, mkdirSync as mkdirSync2, openSync, statSync, unlinkSync } from "node:fs";
1393
- import { dirname as dirname2 } from "node:path";
1625
+ import { dirname as dirname3 } from "node:path";
1394
1626
  var LOCK_WAIT_MS = 5e3;
1395
1627
  var LOCK_STALE_MS = 3e4;
1396
1628
  var RETRY_MS = 20;
1397
1629
  var pause = new Int32Array(new SharedArrayBuffer(4));
1398
- var withFileLock = /* @__PURE__ */ __name((path2, what, body, waitMs = LOCK_WAIT_MS) => {
1630
+ var withFileLock = /* @__PURE__ */ __name((path2, what2, body, waitMs = LOCK_WAIT_MS) => {
1399
1631
  const lock = lockFor(path2);
1400
1632
  const deadline = Date.now() + waitMs;
1401
1633
  while (!taken(lock)) {
1402
1634
  if (Date.now() >= deadline)
1403
- throw lockTimeout(what, waitMs, lock);
1635
+ throw lockTimeout(what2, waitMs, lock);
1404
1636
  Atomics.wait(pause, 0, 0, RETRY_MS);
1405
1637
  }
1406
1638
  return holding(lock, body);
1407
1639
  }, "withFileLock");
1408
- var withFileLockAsync = /* @__PURE__ */ __name(async (path2, what, body, waitMs = LOCK_WAIT_MS, sleep = realSleep) => {
1640
+ var withFileLockAsync = /* @__PURE__ */ __name(async (path2, what2, body, waitMs = LOCK_WAIT_MS, sleep = realSleep) => {
1409
1641
  const lock = lockFor(path2);
1410
1642
  const deadline = Date.now() + waitMs;
1411
1643
  while (!taken(lock)) {
1412
1644
  if (Date.now() >= deadline)
1413
- throw lockTimeout(what, waitMs, lock);
1645
+ throw lockTimeout(what2, waitMs, lock);
1414
1646
  await sleep(RETRY_MS);
1415
1647
  }
1416
1648
  return holding(lock, body);
1417
1649
  }, "withFileLockAsync");
1418
1650
  var lockFor = /* @__PURE__ */ __name((path2) => {
1419
- mkdirSync2(dirname2(path2), { recursive: true, mode: 448 });
1651
+ mkdirSync2(dirname3(path2), { recursive: true, mode: 448 });
1420
1652
  return `${path2}.lock`;
1421
1653
  }, "lockFor");
1422
1654
  var taken = /* @__PURE__ */ __name((lock) => {
@@ -1446,7 +1678,7 @@ var holding = /* @__PURE__ */ __name((lock, body) => {
1446
1678
  }
1447
1679
  }
1448
1680
  }, "holding");
1449
- var lockTimeout = /* @__PURE__ */ __name((what, waitMs, lock) => new CliError("timeout", `${what} stayed locked for ${waitMs / 1e3}s (${lock})`), "lockTimeout");
1681
+ var lockTimeout = /* @__PURE__ */ __name((what2, waitMs, lock) => new CliError("timeout", `${what2} stayed locked for ${waitMs / 1e3}s (${lock})`), "lockTimeout");
1450
1682
  var lockTime = /* @__PURE__ */ __name((lock) => {
1451
1683
  try {
1452
1684
  return statSync(lock).mtimeMs;
@@ -1455,7 +1687,7 @@ var lockTime = /* @__PURE__ */ __name((lock) => {
1455
1687
  }
1456
1688
  }, "lockTime");
1457
1689
 
1458
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/journal.js
1690
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/journal.js
1459
1691
  var sendsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join2(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "sends", `${profile}.jsonl`), "sendsPathFor");
1460
1692
  var SendJournal = class {
1461
1693
  static {
@@ -1491,7 +1723,7 @@ var SendJournal = class {
1491
1723
  resource: this.resource,
1492
1724
  allow: LOG_ATTRIBUTES
1493
1725
  });
1494
- mkdirSync3(dirname3(this.path), { recursive: true, mode: 448 });
1726
+ mkdirSync3(dirname4(this.path), { recursive: true, mode: 448 });
1495
1727
  appendFileSync(this.path, `${JSON.stringify(record2)}
1496
1728
  `, { mode: 384 });
1497
1729
  }
@@ -1532,7 +1764,7 @@ var withSendId = /* @__PURE__ */ __name((entry) => {
1532
1764
  return cid === void 0 || rest.sendId !== void 0 ? rest : { ...rest, sendId: String(cid) };
1533
1765
  }, "withSendId");
1534
1766
 
1535
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/recipients.js
1767
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/recipients.js
1536
1768
  import { existsSync, readFileSync as readFileSync4, rmSync } from "node:fs";
1537
1769
  import { join as join3 } from "node:path";
1538
1770
  var recipientsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "profiles", `${profile}.recipients.json`), "recipientsPathFor");
@@ -1644,7 +1876,7 @@ var RecipientList = class {
1644
1876
  }
1645
1877
  };
1646
1878
 
1647
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/guard.js
1879
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/guard.js
1648
1880
  var HOUR_MS = 60 * 60 * 1e3;
1649
1881
  var countsTowardLimit = /* @__PURE__ */ __name(({ kind: kind2 = "message", action, notify }) => kind2 === "message" || kind2 === "forward" || kind2 === "edit" || kind2 === "delete" || kind2 === "pin" && notify === true || action === "create" || action === "members.add" || action === "requests.accept" || action === "join" || action === "contact-import", "countsTowardLimit");
1650
1882
  var weightOf = /* @__PURE__ */ __name(({ kind: kind2 = "message", action, count, people }) => kind2 === "delete" || kind2 === "message" && action === void 0 ? Math.max(1, count ?? 1) : action === "create" || action === "members.add" || action === "requests.accept" || action === "contact-import" ? Math.max(1, people ?? count ?? 1) : 1, "weightOf");
@@ -1832,7 +2064,569 @@ var guardFor = /* @__PURE__ */ __name((app, settings, warn, env = process.env, a
1832
2064
  }), "guardFor");
1833
2065
  var journalFailure = /* @__PURE__ */ __name((error) => error?.code ?? (error instanceof Error ? error.name : "error"), "journalFailure");
1834
2066
 
1835
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/keyed-guard.js
2067
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/command-runs.js
2068
+ import { AsyncLocalStorage } from "node:async_hooks";
2069
+ var runSettings = /* @__PURE__ */ __name((flag, saved = {}) => {
2070
+ const record2 = flag ?? saved.record ?? true;
2071
+ return {
2072
+ record: record2,
2073
+ keepFailedRuns: record2 || flag !== false,
2074
+ keepRunsForDays: saved.keepRunsForDays ?? KEEP_RUNS_FOR_DAYS,
2075
+ keepSuccessfulRunsForDays: saved.keepSuccessfulRunsForDays ?? KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
2076
+ keepStoreRunsForDays: saved.keepStoreRunsForDays ?? KEEP_STORE_RUNS_FOR_DAYS,
2077
+ runsSizeLimitMb: saved.runsSizeLimitMb ?? RUNS_SIZE_LIMIT_MB
2078
+ };
2079
+ }, "runSettings");
2080
+ var SKIPPED = /* @__PURE__ */ new Set(["runs", "help"]);
2081
+ var pathOf = /* @__PURE__ */ __name((command) => {
2082
+ const words = [];
2083
+ for (let at2 = command; at2?.parent; at2 = at2.parent)
2084
+ words.unshift(at2.name());
2085
+ return words;
2086
+ }, "pathOf");
2087
+ var tracker = /* @__PURE__ */ __name((options, typed) => {
2088
+ let recording;
2089
+ const open2 = /* @__PURE__ */ __name((program, words, flag, format, lifetime) => {
2090
+ recording = void 0;
2091
+ if (SKIPPED.has(words[0] ?? ""))
2092
+ return;
2093
+ const environment = environmentOf(program);
2094
+ let saved = {};
2095
+ try {
2096
+ saved = options.settings();
2097
+ } catch {
2098
+ saved = { recordInput: false };
2099
+ }
2100
+ let profile;
2101
+ try {
2102
+ profile = options.profile?.() || void 0;
2103
+ } catch {
2104
+ }
2105
+ const settings = runSettings(flag, saved);
2106
+ const agent = options.agent ?? environment.agent !== void 0;
2107
+ const streams = options.streams ?? environment.streams;
2108
+ const env = options.env ?? environment.env;
2109
+ const command = `${agent ? "mcp " : ""}${words.join(" ") || options.app.command}`;
2110
+ const caller = environment.agent?.caller;
2111
+ recording = startRecording({
2112
+ app: options.app,
2113
+ command,
2114
+ ...profile === void 0 ? {} : { profile },
2115
+ record: keepsSuccess({
2116
+ record: settings.record,
2117
+ fromFlag: flag !== void 0,
2118
+ env: env ?? process.env,
2119
+ caller,
2120
+ persistent: lifetime === "persistent"
2121
+ }),
2122
+ keepFailed: settings.keepFailedRuns,
2123
+ keepDays: settings.keepRunsForDays,
2124
+ keepSuccessDays: settings.keepSuccessfulRunsForDays,
2125
+ keepStoreDays: settings.keepStoreRunsForDays,
2126
+ maxBytes: settings.runsSizeLimitMb * 1024 * 1024,
2127
+ trace: false,
2128
+ format,
2129
+ ...streams ? { streams } : {},
2130
+ ...env ? { env } : {},
2131
+ context: runContextOf({
2132
+ bin: options.app.command,
2133
+ command: words.length > 0 ? command : "",
2134
+ program: rootOf(program),
2135
+ ...environment.argv ?? typed ? { argv: environment.argv ?? typed } : {},
2136
+ env: env ?? process.env,
2137
+ recordInput: saved.recordInput ?? true,
2138
+ caller
2139
+ })
2140
+ });
2141
+ }, "open");
2142
+ const finish = /* @__PURE__ */ __name(() => {
2143
+ const done = recording;
2144
+ recording = void 0;
2145
+ return done;
2146
+ }, "finish");
2147
+ return {
2148
+ start(action) {
2149
+ const flags = action.optsWithGlobals();
2150
+ const json = flags.json !== void 0 && flags.json !== false || Boolean(flags.jsonl);
2151
+ open2(action, pathOf(action), flags.record, options.format?.() ?? (json ? "json" : "pretty"), metaOf(action).lifetime);
2152
+ },
2153
+ async succeed() {
2154
+ await finish()?.succeed();
2155
+ },
2156
+ async fail(error) {
2157
+ await finish()?.fail(options.recognise ? options.recognise(error) : error);
2158
+ },
2159
+ runId: /* @__PURE__ */ __name(() => recording?.runId, "runId"),
2160
+ events: /* @__PURE__ */ __name((event) => recording?.events(event), "events"),
2161
+ open: open2
2162
+ };
2163
+ }, "tracker");
2164
+ var commandRuns = /* @__PURE__ */ __name((options) => tracker(options), "commandRuns");
2165
+ var parses = new AsyncLocalStorage();
2166
+ var commandRunId = /* @__PURE__ */ __name(() => parses.getStore()?.runs.runId(), "commandRunId");
2167
+ var providerEvent = /* @__PURE__ */ __name((event) => {
2168
+ const parse2 = parses.getStore();
2169
+ if (parse2)
2170
+ parse2.runs.events(event);
2171
+ else
2172
+ runEvent(event);
2173
+ }, "providerEvent");
2174
+ var providerRequest = /* @__PURE__ */ __name((operation, sink = providerEvent, call2 = {}) => {
2175
+ const { bytes: sent, ...shape } = call2;
2176
+ const wire = { operation, level: "wire", ...call2.attempt === void 0 ? currentAttempt() : {}, ...shape };
2177
+ sink({ event: "request", ...wire, ...sent === void 0 ? {} : { bytes: sent } });
2178
+ const started = performance.now();
2179
+ return ({ status, error, errorCode, providerError, bytes, counts, ids: ids2 } = {}) => {
2180
+ const failed = error !== void 0 || errorCode !== void 0;
2181
+ const key = providerErrorKey(providerError);
2182
+ sink({
2183
+ event: "response",
2184
+ ...wire,
2185
+ ...status === void 0 ? {} : { status },
2186
+ durationMs: Math.round(performance.now() - started),
2187
+ outcome: failed ? "error" : "ok",
2188
+ ...failed ? { errorCode: errorCode ?? (isCliError(error) ? error.code : "provider_error") } : {},
2189
+ ...key ? { providerError: key } : {},
2190
+ ...bytes === void 0 ? {} : { bytes },
2191
+ ...counts ? { counts } : {},
2192
+ ...ids2 ? { ids: ids2 } : {}
2193
+ });
2194
+ };
2195
+ }, "providerRequest");
2196
+ var pathFromArgs = /* @__PURE__ */ __name((program, args, profileWord) => {
2197
+ const words = [];
2198
+ let at2 = program;
2199
+ let skipped = !profileWord;
2200
+ for (const arg of args) {
2201
+ if (arg.startsWith("-"))
2202
+ continue;
2203
+ const next = at2.commands.find((one) => one.name() === arg || one.aliases().includes(arg));
2204
+ if (next) {
2205
+ words.push(arg);
2206
+ at2 = next;
2207
+ } else if (words.length === 0 && !skipped)
2208
+ skipped = true;
2209
+ else
2210
+ break;
2211
+ }
2212
+ return words;
2213
+ }, "pathFromArgs");
2214
+ var isHelpExit = /* @__PURE__ */ __name((error) => {
2215
+ const { code, exitCode } = error ?? {};
2216
+ return typeof code === "string" && code.startsWith("commander.") && (exitCode === 0 || code === "commander.help");
2217
+ }, "isHelpExit");
2218
+ var recordRuns = /* @__PURE__ */ __name((program, options) => {
2219
+ program.option("--record", "keep this run even where the config says record false; record_input false leaves the typed words out").option("--no-record", "do not keep this run, even if it fails");
2220
+ program.hook("preAction", (_root, action) => {
2221
+ const parse2 = parses.getStore();
2222
+ if (!parse2)
2223
+ return;
2224
+ parse2.started = true;
2225
+ parse2.runs.start(action);
2226
+ });
2227
+ const parseAsync = program.parseAsync.bind(program);
2228
+ program.parseAsync = (argv, settings) => {
2229
+ const args = settings?.from === "user" ? argv ?? [] : (argv ?? process.argv).slice(2);
2230
+ const parse2 = { runs: tracker(options, args), started: false };
2231
+ return parses.run(parse2, async () => {
2232
+ try {
2233
+ const parsed = await parseAsync(argv, settings);
2234
+ await parse2.runs.succeed();
2235
+ return parsed;
2236
+ } catch (error) {
2237
+ if (!isHelpExit(error) && !wasSettled(error)) {
2238
+ try {
2239
+ if (!parse2.started) {
2240
+ const flag = args.includes("--no-record") ? false : args.includes("--record") ? true : void 0;
2241
+ const json = args.some((arg) => arg === "--json" || arg.startsWith("--json=") || arg === "--jsonl");
2242
+ const words = pathFromArgs(program, args, options.profile !== void 0);
2243
+ const format = options.format?.() ?? (json ? "json" : "pretty");
2244
+ parse2.runs.open(program, words, flag, format);
2245
+ }
2246
+ await parse2.runs.fail(error);
2247
+ } catch {
2248
+ }
2249
+ }
2250
+ throw error;
2251
+ }
2252
+ });
2253
+ };
2254
+ }, "recordRuns");
2255
+
2256
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/bot/api-http.js
2257
+ var LARGEST_ANSWER = 16 * 1024 * 1024;
2258
+ var segment = /* @__PURE__ */ __name((name, value) => {
2259
+ if (value === void 0 || value === "" || value === "." || value === "..")
2260
+ throw new CliError("validation_error", `${name} must name one item; an empty, "." or ".." id is refused`);
2261
+ return encodeURIComponent(value);
2262
+ }, "segment");
2263
+ var unsendableBody = /* @__PURE__ */ __name((operation) => {
2264
+ const type = operation.request?.contentType;
2265
+ return type === void 0 || sendsBytes(operation) ? void 0 : `it sends ${type}, which the generated command cannot send`;
2266
+ }, "unsendableBody");
2267
+ var httpApiRequest = /* @__PURE__ */ __name((operation, input, baseUrl) => {
2268
+ const { binding } = operation;
2269
+ if (binding.kind !== "http" && binding.kind !== "graphql")
2270
+ throw new CliError("configuration_error", `${operation.command} is not an HTTP operation`);
2271
+ if (unsendableBody(operation))
2272
+ throw new CliError("validation_error", `${operation.command} sends ${operation.request?.contentType}, which the generated command cannot send; nothing was sent`, { sent: false });
2273
+ if (operation.response?.sensitive)
2274
+ throw new CliError("validation_error", `${operation.command} answers with a credential, which the generated command never prints; nothing was sent`, { sent: false });
2275
+ if (binding.kind === "graphql")
2276
+ return graphqlRequest(operation, binding, input, baseUrl);
2277
+ if (Object.keys(input.fields).length > 0)
2278
+ throw new CliError("configuration_error", `${operation.command} has body fields as flags, which HTTP cannot send`);
2279
+ if (!/^\/(?!\/)/.test(binding.path))
2280
+ throw new CliError("configuration_error", `${operation.command} has a path that does not start with one /`);
2281
+ const base = new URL(baseUrl);
2282
+ const path2 = binding.path.replace(/\{([^}]+)\}/g, (_, name) => segment(name, input.path[name]));
2283
+ const url = new URL(`${base.pathname.replace(/\/$/, "")}${path2}`, base.origin);
2284
+ for (const [name, raw] of Object.entries(input.query)) {
2285
+ const parameter = operation.parameters.find((one) => one.in === "query" && one.name === name);
2286
+ if (parameter?.schema.type === "array")
2287
+ for (const item of raw.split(","))
2288
+ url.searchParams.append(name, item.trim());
2289
+ else
2290
+ url.searchParams.set(name, raw);
2291
+ }
2292
+ const headers = new Headers(input.headers);
2293
+ headers.set("accept", "application/json");
2294
+ if (sendsBytes(operation)) {
2295
+ if (input.bytes === void 0)
2296
+ return { method: binding.method, url, headers };
2297
+ headers.set("content-type", operation.request?.contentType);
2298
+ return { method: binding.method, url, headers, body: input.bytes };
2299
+ }
2300
+ const body = input.body?.trim() ? input.body : void 0;
2301
+ if (body !== void 0)
2302
+ parseApiJson(body);
2303
+ if (body !== void 0)
2304
+ headers.set("content-type", "application/json");
2305
+ return { method: binding.method, url, headers, ...body === void 0 ? {} : { body } };
2306
+ }, "httpApiRequest");
2307
+ var graphqlRequest = /* @__PURE__ */ __name((operation, binding, input, baseUrl) => {
2308
+ const variables = graphqlVariables(operation, input.body, input.fields);
2309
+ const headers = new Headers(input.headers);
2310
+ headers.set("accept", "application/json");
2311
+ headers.set("content-type", "application/json");
2312
+ const query = graphqlDocument(binding, input.selection);
2313
+ return { method: "POST", url: new URL(baseUrl), headers, body: apiJson({ query, variables }), redirect: "error" };
2314
+ }, "graphqlRequest");
2315
+ var templateOf = /* @__PURE__ */ __name((path2) => path2.replace(/\{([^}]+)\}/g, ":$1"), "templateOf");
2316
+ var endpointOf = /* @__PURE__ */ __name((operation) => operation.binding.kind === "http" ? templateOf(operation.binding.path) : operation.binding.kind === "graphql" ? `${operation.binding.operation}/${operation.binding.field}` : "", "endpointOf");
2317
+ var GRAPHQL_CODES = {
2318
+ UNAUTHENTICATED: "authentication_error",
2319
+ AUTHENTICATION_ERROR: "authentication_error",
2320
+ FORBIDDEN: "permission_error",
2321
+ RATELIMITED: "rate_limited",
2322
+ BAD_USER_INPUT: "validation_error",
2323
+ GRAPHQL_VALIDATION_FAILED: "validation_error",
2324
+ INVALID_INPUT: "validation_error"
2325
+ };
2326
+ var NOTHING_RAN = /* @__PURE__ */ new Set(["authentication_error", "permission_error", "rate_limited", "validation_error"]);
2327
+ var graphqlAnswer = /* @__PURE__ */ __name((options, operation, answer) => {
2328
+ const { binding } = operation;
2329
+ if (binding.kind !== "graphql")
2330
+ return answer;
2331
+ const { data, errors } = answer ?? {};
2332
+ if (Array.isArray(errors) && errors.length > 0) {
2333
+ const own = options.failure?.(200, answer, operation);
2334
+ if (own)
2335
+ throw own;
2336
+ const raw = errors[0]?.extensions?.code;
2337
+ const code = typeof raw === "string" && /^[A-Z][A-Z0-9_]{0,40}$/.test(raw) ? raw : void 0;
2338
+ const known = code && GRAPHQL_CODES[code] || "provider_error";
2339
+ const writes = operation.effect !== "read";
2340
+ if (writes && (!NOTHING_RAN.has(known) || data?.[binding.field] != null))
2341
+ return outcomeUnknown(options.service);
2342
+ throw new CliError(known, `${options.service} refused ${operation.command}${code ? ` (${code})` : ""}`, {
2343
+ retryable: known === "rate_limited"
2344
+ });
2345
+ }
2346
+ if (!data || !(binding.field in data))
2347
+ throw new CliError("invalid_response", `${options.service} answered ${operation.command} without data.${binding.field}`);
2348
+ return data[binding.field];
2349
+ }, "graphqlAnswer");
2350
+ var outcomeUnknown = /* @__PURE__ */ __name((service) => {
2351
+ throw new CliError("outcome_unknown", `${service} did not confirm a write; check it before repeating the write`, {
2352
+ retryable: false
2353
+ });
2354
+ }, "outcomeUnknown");
2355
+ var answerOf = /* @__PURE__ */ __name(async (response, maxBytes) => {
2356
+ if (response.status === 204 || !response.body || response.headers.get("content-length") === "0")
2357
+ return {};
2358
+ return readJsonResponse(response, { maxBytes });
2359
+ }, "answerOf");
2360
+ var httpApiExchange = /* @__PURE__ */ __name((options) => async (command, operation, request) => {
2361
+ const writes = operation.effect !== "read";
2362
+ const template = endpointOf(operation);
2363
+ const end = providerRequest(`${request.method} ${template}`, void 0, {
2364
+ method: request.method,
2365
+ endpointTemplate: template,
2366
+ transport: "http"
2367
+ });
2368
+ let response;
2369
+ try {
2370
+ response = await options.fetch(command)(request.url, {
2371
+ method: request.method,
2372
+ headers: request.headers,
2373
+ ...request.body === void 0 ? {} : { body: request.body },
2374
+ ...request.redirect === void 0 ? {} : { redirect: request.redirect }
2375
+ });
2376
+ } catch (error) {
2377
+ const failed = unanswered(options.service, writes, error);
2378
+ end({ error: failed });
2379
+ throw failed;
2380
+ }
2381
+ const { status } = response;
2382
+ let answer;
2383
+ try {
2384
+ answer = await answerOf(response, options.maxBytes ?? LARGEST_ANSWER);
2385
+ } catch {
2386
+ if (response.ok) {
2387
+ end({ status });
2388
+ throw unreadable(options.service, writes, status);
2389
+ }
2390
+ }
2391
+ if (!response.ok) {
2392
+ const failed = status >= 500 && writes ? refusal(options.service, operation, response, writes) : options.failure?.(status, answer, operation) ?? refusal(options.service, operation, response, writes, innerStatus(answer));
2393
+ end({ status, error: failed });
2394
+ throw failed;
2395
+ }
2396
+ try {
2397
+ const result = graphqlAnswer(options, operation, answer);
2398
+ const refused = operation.binding.kind === "http" ? options.failedAnswer?.(answer, operation) : void 0;
2399
+ if (refused)
2400
+ throw refused;
2401
+ end({ status });
2402
+ return { answer: result, headers: response.headers };
2403
+ } catch (error) {
2404
+ end({ status, error });
2405
+ throw error;
2406
+ }
2407
+ }, "httpApiExchange");
2408
+ var httpApiSend = /* @__PURE__ */ __name((options) => {
2409
+ const exchange = httpApiExchange(options);
2410
+ return async (command, operation, request) => (await exchange(command, operation, request)).answer;
2411
+ }, "httpApiSend");
2412
+ var httpApiExecutor = /* @__PURE__ */ __name((options) => async (command, operation, input) => {
2413
+ const request = httpApiRequest(operation, input, options.baseUrl);
2414
+ for (const [name, value] of Object.entries(await options.headers(command, operation)))
2415
+ request.headers.set(name, value);
2416
+ const send = /* @__PURE__ */ __name(() => httpApiSend(options)(command, operation, request), "send");
2417
+ const answer = operation.effect !== "read" ? await options.write(command, operation, send) : await (options.read ?? ((_command, _operation, call2) => call2()))(command, operation, send);
2418
+ renderAnswer(command, outputFor(command), itemOf(answer));
2419
+ }, "httpApiExecutor");
2420
+ var unanswered = /* @__PURE__ */ __name((service, writes, error) => {
2421
+ if (error instanceof CliError && (!writes || error.details?.sent === false))
2422
+ return error;
2423
+ if (writes)
2424
+ return new CliError("outcome_unknown", `${service} did not answer a write; check it before repeating the write`, {
2425
+ retryable: false
2426
+ });
2427
+ return error?.name === "TimeoutError" ? new CliError("timeout", `${service} did not answer in time`, { retryable: true }) : new CliError("network_error", `${service} could not be reached`, { retryable: true });
2428
+ }, "unanswered");
2429
+ var unreadable = /* @__PURE__ */ __name((service, writes, status) => writes ? new CliError("outcome_unknown", `${service} took the write but its answer could not be read; check it before repeating the write`, {
2430
+ status,
2431
+ retryable: false
2432
+ }) : new CliError("invalid_response", `${service} sent an answer that could not be read`, { status, retryable: true }), "unreadable");
2433
+ var innerStatus = /* @__PURE__ */ __name((answer) => {
2434
+ const find = /* @__PURE__ */ __name((value, depth, inDetails) => {
2435
+ if (depth > 5 || typeof value !== "object" || value === null || Array.isArray(value))
2436
+ return void 0;
2437
+ for (const [key, one] of Object.entries(value)) {
2438
+ if (inDetails && key === "status" && typeof one === "number" && one >= 400 && one < 600)
2439
+ return one;
2440
+ const found = find(one, depth + 1, inDetails || key === "details");
2441
+ if (found !== void 0)
2442
+ return found;
2443
+ }
2444
+ return void 0;
2445
+ }, "find");
2446
+ return find(answer, 0, false);
2447
+ }, "innerStatus");
2448
+ var refusal = /* @__PURE__ */ __name((service, operation, response, writes, inner) => {
2449
+ const { status } = response;
2450
+ if (status === 429) {
2451
+ const wait = providerWaitMs(response.headers, wallClock);
2452
+ return new CliError("rate_limited", `${service} asked to slow down; retry the command later`, {
2453
+ status,
2454
+ retryable: true,
2455
+ ...wait === void 0 ? {} : { retry_after_ms: wait }
2456
+ });
2457
+ }
2458
+ if (status >= 500 && writes)
2459
+ return new CliError("outcome_unknown", `${service} failed during a write; check it before repeating the write`, {
2460
+ status,
2461
+ retryable: false
2462
+ });
2463
+ if (status === 401)
2464
+ return new CliError("authentication_error", `${service} refused the sign-in; sign in again`, {
2465
+ reason: "auth.failed",
2466
+ status
2467
+ });
2468
+ if (status === 403)
2469
+ return new CliError("permission_error", `${service} denied ${operation.command} to this account`, {
2470
+ reason: "access.denied",
2471
+ status
2472
+ });
2473
+ const location = status >= 300 && status < 400 ? response.headers.get("location") : null;
2474
+ if (location !== null) {
2475
+ const to = URL.canParse(location, response.url || void 0) ? new URL(location, response.url || void 0) : void 0;
2476
+ const where = to ? `${to.origin}${to.pathname}` : "another address";
2477
+ return new CliError(statusToCode(status), `${service} moved ${operation.command} to ${where} (HTTP ${status}); nothing was sent there`, { status, retryable: false });
2478
+ }
2479
+ return new CliError(statusToCode(status), `${service} refused ${operation.command} (HTTP ${status})`, {
2480
+ status,
2481
+ retryable: status >= 500,
2482
+ ...inner === void 0 || inner === status ? {} : { inner_status: inner }
2483
+ });
2484
+ }, "refusal");
2485
+
2486
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
2487
+ import { openSync as openSync2 } from "node:fs";
2488
+ import { createInterface } from "node:readline";
2489
+ import { ReadStream } from "node:tty";
2490
+ var fromTerminal = /* @__PURE__ */ __name(async (question) => {
2491
+ if (!process.stdin.isTTY || !process.stderr.isTTY)
2492
+ return null;
2493
+ let input;
2494
+ try {
2495
+ input = new ReadStream(openSync2("/dev/tty", "r"));
2496
+ } catch {
2497
+ return null;
2498
+ }
2499
+ const reader = createInterface({ input, output: process.stderr, terminal: true });
2500
+ try {
2501
+ return await new Promise((resolve2, reject) => {
2502
+ const cancel = /* @__PURE__ */ __name(() => reject(new CliError("cancelled", "cancelled \u2014 nothing was done")), "cancel");
2503
+ reader.once("SIGINT", cancel);
2504
+ reader.once("close", cancel);
2505
+ reader.question(question, resolve2);
2506
+ });
2507
+ } finally {
2508
+ reader.close();
2509
+ input.destroy();
2510
+ }
2511
+ }, "fromTerminal");
2512
+ var what = /* @__PURE__ */ __name((key, { chatId, count, personIds, forEveryone }) => [
2513
+ key,
2514
+ forEveryone ? "for everyone" : void 0,
2515
+ count !== void 0 ? `${count} ${count === 1 ? "item" : "items"}` : void 0,
2516
+ personIds?.length ? `${personIds.length} ${personIds.length === 1 ? "person" : "people"}` : void 0,
2517
+ chatId !== null ? `in chat ${chatId}` : void 0
2518
+ ].filter(Boolean).join(", "), "what");
2519
+ var answerOf2 = /* @__PURE__ */ __name(async (command, question) => {
2520
+ const given = command.optsWithGlobals();
2521
+ if (given.json === true || given.jsonl === true)
2522
+ return null;
2523
+ return (environmentOf(command).answer ?? fromTerminal)(question);
2524
+ }, "answerOf");
2525
+ var terminalAsker = /* @__PURE__ */ __name((command) => async (key, request) => {
2526
+ if (environmentOf(command).agent)
2527
+ return;
2528
+ const flag = skipFlagFor(key);
2529
+ const given = command.optsWithGlobals();
2530
+ if (flag === "--yes" ? given.yes === true : given.allowDangerous === true)
2531
+ return;
2532
+ const machine = given.json === true || given.jsonl === true;
2533
+ const answer = machine ? null : await (environmentOf(command).answer ?? fromTerminal)(`${what(key, request)} \u2014 go ahead? [y/N] `);
2534
+ if (answer === null) {
2535
+ throw new CliError("confirmation_required", `${key} asks before it acts (its permission level is ask), and nobody is at a terminal to answer \u2014 add ${flag} to go ahead`, { permission: key });
2536
+ }
2537
+ if (!/^\s*y(es)?\s*$/i.test(answer))
2538
+ throw new CliError("cancelled", `${key}: not done \u2014 the answer was no`);
2539
+ }, "terminalAsker");
2540
+
2541
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
2542
+ var HOUSEKEEPING = /* @__PURE__ */ new Set([
2543
+ "help",
2544
+ "guide",
2545
+ "config",
2546
+ "session",
2547
+ "doctor",
2548
+ "commands",
2549
+ "complete",
2550
+ "upgrade",
2551
+ "skill",
2552
+ "mcp",
2553
+ "runs"
2554
+ ]);
2555
+ var commandPathKey = /* @__PURE__ */ __name((path2) => path2[0] === void 0 || HOUSEKEEPING.has(path2[0]) && !KEYED_UNDER_HOUSEKEEPING.has(path2.join(".")) ? null : path2.join("."), "commandPathKey");
2556
+ var commandPermissions = /* @__PURE__ */ __name(({ keyOf: keyOf4 = commandPathKey, extra = [], defaults = {}, alsoChecks } = {}) => ({
2557
+ keyOf: keyOf4,
2558
+ extra: [AUTHORITY_KEY, ...extra],
2559
+ defaults: { ...DEFAULT_PERMISSIONS, ...defaults },
2560
+ ...alsoChecks ? { alsoChecks } : {}
2561
+ }), "commandPermissions");
2562
+ var pathOf2 = /* @__PURE__ */ __name((command) => {
2563
+ const words = [];
2564
+ for (let at2 = command; at2?.parent; at2 = at2.parent)
2565
+ words.unshift(at2.name());
2566
+ return words;
2567
+ }, "pathOf");
2568
+ var rootOf2 = /* @__PURE__ */ __name((command) => {
2569
+ let at2 = command;
2570
+ while (at2.parent)
2571
+ at2 = at2.parent;
2572
+ return at2;
2573
+ }, "rootOf");
2574
+ var everyCommand = /* @__PURE__ */ __name((command) => [command, ...command.commands.flatMap(everyCommand)], "everyCommand");
2575
+ var knownPermissionKeys = /* @__PURE__ */ __name((command, keyOf4 = (one) => keyForCommand(pathOf2(one)), extra = []) => {
2576
+ const known = /* @__PURE__ */ new Set();
2577
+ const add = /* @__PURE__ */ __name((key) => {
2578
+ for (let parts = key.split("."); parts.length > 0; parts = parts.slice(0, -1))
2579
+ known.add(parts.join("."));
2580
+ }, "add");
2581
+ if (typeof keyOf4 !== "function") {
2582
+ for (const one of everyCommand(rootOf2(command))) {
2583
+ const key = keyOf4.keyOf(pathOf2(one));
2584
+ if (key)
2585
+ add(key);
2586
+ }
2587
+ for (const key of [...keyOf4.extra, ...extra])
2588
+ add(key);
2589
+ return known;
2590
+ }
2591
+ for (const one of everyCommand(rootOf2(command))) {
2592
+ const own = keyOf4(one);
2593
+ const key = own === void 0 ? keyForCommand(pathOf2(one)) : own;
2594
+ if (key)
2595
+ add(key);
2596
+ }
2597
+ for (const key of [...WRITE_KEYS, ...extra])
2598
+ add(key);
2599
+ return known;
2600
+ }, "knownPermissionKeys");
2601
+ var RENAMED2 = /* @__PURE__ */ new WeakMap();
2602
+ var markRenamedPermissionKeys = /* @__PURE__ */ __name((command, renamed) => {
2603
+ if (renamed.size > 0)
2604
+ RENAMED2.set(command, renamed);
2605
+ }, "markRenamedPermissionKeys");
2606
+ var renamedPermissionKeys = /* @__PURE__ */ __name((command) => new Map(everyCommand(rootOf2(command)).flatMap((one) => [...RENAMED2.get(one) ?? []])), "renamedPermissionKeys");
2607
+ var knownBeside = /* @__PURE__ */ __name((key, known) => {
2608
+ const parent = key.split(".").slice(0, -1).join(".");
2609
+ const depth = parent === "" ? 1 : parent.split(".").length + 1;
2610
+ return [...known].filter((one) => one.split(".").length === depth && (parent === "" || one.startsWith(`${parent}.`))).sort();
2611
+ }, "knownBeside");
2612
+ var unknownPermissionKeys = /* @__PURE__ */ __name((levels, known) => Object.keys(levels).filter((key) => key !== CEILING_KEY && !known.has(key)), "unknownPermissionKeys");
2613
+ var unknownPermissionIssues = /* @__PURE__ */ __name((command, settings, tool, keyOf4) => {
2614
+ const saved = settings.savedPermissions ?? Object.keys(settings.permissions).filter((key) => key !== CEILING_KEY && settings.permissionSources[key] !== "flag").map((key) => ({ key, at: ["profiles", settings.profile, "permissions", key] }));
2615
+ return permissionIssues(saved, knownPermissionKeys(command, keyOf4), { file: settings.configPath, tool }, renamedPermissionKeys(command)).map(publicIssue);
2616
+ }, "unknownPermissionIssues");
2617
+ var refuseUnknownPermissionKeys = /* @__PURE__ */ __name((command, settings, tool, keyOf4) => {
2618
+ const issues = unknownPermissionIssues(command, settings, tool, keyOf4);
2619
+ if (issues.length > 0)
2620
+ throw new CliError("configuration_error", issueMessage(issues), { permission: issues[0]?.key });
2621
+ const flagged = Object.keys(settings.permissions).filter((key2) => settings.permissionSources[key2] === "flag");
2622
+ const [key] = unknownPermissionKeys(Object.fromEntries(flagged.map((one) => [one, true])), knownPermissionKeys(command, keyOf4));
2623
+ if (key === void 0)
2624
+ return;
2625
+ const now = renamedPermissionKeys(command).get(key);
2626
+ throw new CliError("validation_error", `--permission ${key} names no command${now === void 0 ? "" : `: its command moved, so use ${now}`}`, { permission: key });
2627
+ }, "refuseUnknownPermissionKeys");
2628
+
2629
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/keyed-guard.js
1836
2630
  var keyedGuard = /* @__PURE__ */ __name((build, ask, levelOf, extra) => {
1837
2631
  let question;
1838
2632
  let answered = false;
@@ -1875,19 +2669,523 @@ var keyedGuard = /* @__PURE__ */ __name((build, ask, levelOf, extra) => {
1875
2669
  };
1876
2670
  }, "keyedGuard");
1877
2671
 
1878
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/send-id.js
2672
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/send-id.js
1879
2673
  import { randomBytes } from "node:crypto";
1880
2674
  var newSendId = /* @__PURE__ */ __name(() => randomBytes(8).readBigInt64BE().toString(), "newSendId");
1881
2675
  var newOperationId = newSendId;
1882
2676
 
1883
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/foreign-contacts.js
2677
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/bot/api.js
2678
+ var apiPathOf = /* @__PURE__ */ __name((operation) => {
2679
+ const { command, group } = operation;
2680
+ if (!group)
2681
+ return [command];
2682
+ return [group, command.startsWith(`${group}-`) ? command.slice(group.length + 1) : command];
2683
+ }, "apiPathOf");
2684
+ var scalarOf = /* @__PURE__ */ __name((value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : void 0, "scalarOf");
2685
+ var generatedApiCommand = /* @__PURE__ */ __name((api) => {
2686
+ const group = new Command("api").description(api.description ?? "every operation of the official Bot API, generated from its schema");
2687
+ group.option("--store-token <profile>", "keep a returned authentication token only in this bot profile's OS keyring; never print it");
2688
+ const subgroups = /* @__PURE__ */ new Set();
2689
+ for (const operation of api.operations) {
2690
+ const binding = operation.binding.kind === "http" ? `${operation.binding.method} ${operation.binding.path}` : operation.binding.kind === "graphql" ? `${operation.binding.operation} ${operation.binding.field}` : operation.binding.name;
2691
+ const path2 = apiPathOf(operation);
2692
+ const command = annotate(new Command(path2.at(-1)), {
2693
+ effects: operation.effect === "read" ? REMOTE_READ : REMOTE_WRITE
2694
+ }).description(`${operation.summary ?? operation.id} \u2014 ${operation.effect} (${binding})`);
2695
+ for (const parameter of operation.parameters) {
2696
+ if (parameter.sensitive)
2697
+ continue;
2698
+ const option = new Option(`--${apiFlagOf(parameter.name)} <value>`, parameter.description?.split("\n")[0] ?? parameter.name);
2699
+ if (operation.binding.kind === "graphql" && parameter.in === "body")
2700
+ secretInput(option);
2701
+ if (parameter.required && parameter.in !== "body") {
2702
+ const fallback = scalarOf(parameter.schema.default);
2703
+ if (fallback === void 0)
2704
+ option.makeOptionMandatory();
2705
+ else
2706
+ option.default(fallback);
2707
+ }
2708
+ command.addOption(option);
2709
+ }
2710
+ if (operation.request && sendsBytes(operation)) {
2711
+ command.option("--body-file <path>", `the file to upload, sent as ${operation.request.contentType}; - is stdin`);
2712
+ } else if (operation.request) {
2713
+ command.addOption(secretInput(new Option("--body <json>", "the request body as JSON; - reads it from stdin")));
2714
+ command.option("--body-file <path>", "the request body from a JSON file; - is stdin");
2715
+ }
2716
+ marksUntrusted(command, API_UNTRUSTED);
2717
+ annotate(command, {
2718
+ origin: "generated",
2719
+ api_operation: operation.id,
2720
+ effects: { remote: operation.effect === "read" ? "read" : "write", local: "none" }
2721
+ });
2722
+ command.action(async function() {
2723
+ await api.before?.(this, operation);
2724
+ const options = this.opts();
2725
+ const input = { path: {}, query: {}, headers: {}, fields: {} };
2726
+ const tokenProfile = group.opts().storeToken;
2727
+ if (operation.response?.sensitive) {
2728
+ if (!tokenProfile?.trim())
2729
+ throw new CliError("validation_error", "--store-token <profile> is required for this credential-returning operation");
2730
+ input.tokenProfile = tokenProfile;
2731
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(tokenProfile))
2732
+ throw new CliError("validation_error", "--store-token needs a bot profile name using letters, digits, underscores or hyphens");
2733
+ } else if (tokenProfile !== void 0) {
2734
+ throw new CliError("validation_error", "--store-token is only supported for credential-returning operations");
2735
+ }
2736
+ for (const parameter of operation.parameters) {
2737
+ const raw = options[apiOptionKey(parameter.name)];
2738
+ if (raw === void 0)
2739
+ continue;
2740
+ if (parameter.required && parameter.in !== "body" && isBlank(raw))
2741
+ throw new CliError("validation_error", `--${apiFlagOf(parameter.name)} of ${operation.command} is empty`, {
2742
+ sent: false
2743
+ });
2744
+ if (parameter.in !== "body") {
2745
+ const problem = api.checkParameter(parameter.name, parameter.schema, raw);
2746
+ if (problem)
2747
+ throw new CliError("validation_error", problem);
2748
+ }
2749
+ const target = parameter.in === "body" ? input.fields : parameter.in === "header" ? input.headers : input[parameter.in];
2750
+ target[parameter.name] = raw;
2751
+ }
2752
+ if (sendsBytes(operation)) {
2753
+ const path3 = options.bodyFile;
2754
+ if (path3 === void 0 && operation.request?.required)
2755
+ throw new CliError("validation_error", `${operation.command} uploads a file: give --body-file <path>, or - for stdin`);
2756
+ if (path3 !== void 0) {
2757
+ input.bytes = (api.readBytes ?? ((_command, from) => readApiBytes(from)))(this, path3);
2758
+ input.bodySource = path3 === "-" ? "stdin" : "file";
2759
+ }
2760
+ await api.execute(this, operation, input);
2761
+ return;
2762
+ }
2763
+ const text2 = (api.readBody ?? ((_command, body2) => readApiBody(body2)))(this, options);
2764
+ if (options.body !== void 0)
2765
+ input.bodySource = options.body === "-" ? "stdin" : "argument";
2766
+ else if (options.bodyFile !== void 0)
2767
+ input.bodySource = options.bodyFile === "-" ? "stdin" : "file";
2768
+ const given = operation.binding.kind === "graphql" ? apiJson(graphqlVariables(operation, text2, input.fields)) : text2;
2769
+ if (operation.binding.kind === "graphql")
2770
+ input.fields = {};
2771
+ const body = operation.binding.kind === "rpc" ? text2 : api.checkBody ? api.checkBody(operation, given) : given;
2772
+ if (body !== void 0)
2773
+ input.body = body;
2774
+ await api.execute(this, operation, input);
2775
+ });
2776
+ api.configure?.(command, operation);
2777
+ const [first] = path2;
2778
+ const taken2 = group.commands.find((one) => one.name() === first);
2779
+ if (taken2 && (path2.length === 1 || !subgroups.has(taken2)))
2780
+ throw new CliError("configuration_error", `api ${first} is both a group and an operation: rename one`);
2781
+ if (path2.length === 1 || first === void 0) {
2782
+ group.addCommand(command);
2783
+ continue;
2784
+ }
2785
+ const subgroup = taken2 ?? annotate(new Command(first), { effects: NO_EFFECTS }).description(`the ${first} operations`);
2786
+ if (!taken2) {
2787
+ subgroups.add(subgroup);
2788
+ group.addCommand(subgroup);
2789
+ }
2790
+ subgroup.addCommand(command);
2791
+ }
2792
+ return group;
2793
+ }, "generatedApiCommand");
2794
+
2795
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/service-api.js
2796
+ var serviceApiOperations = /* @__PURE__ */ __name((manifest) => {
2797
+ const reasonOf = /* @__PURE__ */ __name((operation) => operation.response?.sensitive ? "it returns a credential, which is never printed" : unsendableBody(operation), "reasonOf");
2798
+ return {
2799
+ offered: manifest.operations.filter((operation) => reasonOf(operation) === void 0),
2800
+ left: manifest.operations.flatMap((operation) => {
2801
+ const reason = reasonOf(operation);
2802
+ return reason ? [{ id: operation.id, reason }] : [];
2803
+ })
2804
+ };
2805
+ }, "serviceApiOperations");
2806
+ var MOST_PAGES = 500;
2807
+ var isObject2 = /* @__PURE__ */ __name((value) => !!value && typeof value === "object" && !Array.isArray(value), "isObject");
2808
+ var keyOf2 = /* @__PURE__ */ __name((operation) => ["api", ...apiPathOf(operation)].join("."), "keyOf");
2809
+ var pathOf3 = /* @__PURE__ */ __name((operation) => apiPathOf(operation).join(" "), "pathOf");
2810
+ var formerKeyOf = /* @__PURE__ */ __name((operation) => {
2811
+ const former = `api.${operation.command}`;
2812
+ return former === keyOf2(operation) ? void 0 : former;
2813
+ }, "formerKeyOf");
2814
+ var permissionsOf = /* @__PURE__ */ __name((operation) => operation.permissions ?? [], "permissionsOf");
2815
+ var destructive = /* @__PURE__ */ __name((operation) => operation.effect === "destructive" || operation.binding.kind === "http" && operation.binding.method === "DELETE", "destructive");
2816
+ var flagsOf = /* @__PURE__ */ __name(({ body = [], query = [] }) => [...body, ...query], "flagsOf");
2817
+ var valuesOf = /* @__PURE__ */ __name(({ values = {} }) => Object.entries(values), "valuesOf");
2818
+ var unlessOf = /* @__PURE__ */ __name(({ unless = {} }) => Object.entries(unless), "unlessOf");
2819
+ var whenOf = /* @__PURE__ */ __name((permission) => {
2820
+ const flags = flagsOf(permission);
2821
+ const values = valuesOf(permission).map(([field, listed2]) => `${field} ${listed2.join(" or ")}`);
2822
+ if (flags.length === 0 && values.length === 0)
2823
+ return void 0;
2824
+ const unless = unlessOf(permission).map(([field, listed2]) => `${field} ${listed2.join(" or ")}`);
2825
+ return `with ${[...values, ...flags.length > 0 ? [`${flags.join(" or ")} set`] : []].join(" or ")}${unless.length > 0 && flags.length > 0 ? `, unless ${unless.join(" or ")}` : ""}`;
2826
+ }, "whenOf");
2827
+ var holds = /* @__PURE__ */ __name((value, listed2) => typeof value === "string" && listed2.includes(value), "holds");
2828
+ var set = /* @__PURE__ */ __name((value) => value !== void 0 && value !== null && value !== false && value !== "false", "set");
2829
+ var applies = /* @__PURE__ */ __name((permission, body, input) => {
2830
+ const sends = /* @__PURE__ */ __name(([field, listed2]) => isObject2(body) && holds(body[field], listed2) || holds(input.query[field], listed2), "sends");
2831
+ const sent = permission.values === void 0 ? set : (value) => value !== void 0;
2832
+ const flagged = flagsOf(permission).some((name) => isObject2(body) && sent(body[name]) || sent(input.query[name]));
2833
+ return whenOf(permission) === void 0 || valuesOf(permission).some(sends) || flagged && !unlessOf(permission).some(sends);
2834
+ }, "applies");
2835
+ var serviceApiKeys = /* @__PURE__ */ __name((input, operation, call2) => {
2836
+ const body = call2.body?.trim() ? parseApiJson(call2.body) : void 0;
2837
+ const keys = [
2838
+ ...permissionsOf(operation).filter((permission) => applies(permission, body, call2)).map(({ key }) => key),
2839
+ ...(input.bodyPermissions?.[operation.command] ?? []).filter((one) => one.applies(body)).map(({ key }) => key)
2840
+ ];
2841
+ return [...new Set(keys)];
2842
+ }, "serviceApiKeys");
2843
+ var serviceApiPermissions = /* @__PURE__ */ __name((input) => {
2844
+ const checks = /* @__PURE__ */ new Map();
2845
+ for (const operation of input.manifest.operations) {
2846
+ checks.set(pathOf3(operation), [
2847
+ ...permissionsOf(operation).map((permission) => {
2848
+ const when = whenOf(permission);
2849
+ return when === void 0 ? permission.key : { key: permission.key, when };
2850
+ }),
2851
+ ...(input.bodyPermissions?.[operation.command] ?? []).map(({ key, when }) => ({ key, when }))
2852
+ ]);
2853
+ }
2854
+ const keys = [...new Set([...checks.values()].flat().map((one) => typeof one === "string" ? one : one.key))];
2855
+ return {
2856
+ extra: keys,
2857
+ alsoChecks: /* @__PURE__ */ __name((path2) => path2[0] === "api" ? checks.get(path2.slice(1).join(" ")) ?? [] : [], "alsoChecks"),
2858
+ defaults: {
2859
+ ...Object.fromEntries(keys.map((key) => [key, "ask"])),
2860
+ ...Object.fromEntries(input.manifest.operations.filter(destructive).map((operation) => [keyOf2(operation), "ask"]))
2861
+ }
2862
+ };
2863
+ }, "serviceApiPermissions");
2864
+ var rowOf = /* @__PURE__ */ __name((operation) => ({
2865
+ command: pathOf3(operation),
2866
+ group: apiPathOf(operation).length > 1 ? apiPathOf(operation)[0] : null,
2867
+ method: operation.binding.kind === "http" ? operation.binding.method : operation.binding.kind === "graphql" ? "POST" : "",
2868
+ path: operation.binding.kind === "http" ? operation.binding.path : operation.binding.kind === "graphql" ? `${operation.binding.operation} ${operation.binding.field}` : "",
2869
+ effect: operation.effect,
2870
+ summary: operation.summary ?? ""
2871
+ }), "rowOf");
2872
+ var API_QUERY = {
2873
+ entity: "api_operation",
2874
+ backend: "native",
2875
+ fields: [
2876
+ termField("effect", "enum", "effect:destructive", { values: ["read", "write", "destructive"] }),
2877
+ termField("tag", "kw", "tag:Pages")
2878
+ ]
2879
+ };
2880
+ var serviceApiCore = /* @__PURE__ */ __name((options) => {
2881
+ const { app, configuration, manifest } = options;
2882
+ const { offered: operations, left } = serviceApiOperations(manifest);
2883
+ if (!options.serverVariables)
2884
+ manifestBaseUrl(manifest, options.baseUrl);
2885
+ const baseUrlOf = /* @__PURE__ */ __name((command) => manifestBaseUrl(manifest, options.baseUrl, options.serverVariables?.(command)), "baseUrlOf");
2886
+ const own = serviceApiPermissions(options);
2887
+ const defaults = { ...own.defaults, ...configuration.permissions?.defaults };
2888
+ const unguarded = operations.filter((operation) => destructive(operation) && !permissionsOf(operation).some(({ key }) => key.endsWith(".delete")));
2889
+ if (unguarded.length > 0)
2890
+ throw new CliError("configuration_error", `${unguarded.map(({ command }) => command).join(", ")} can delete, but the manifest gives no delete key: generate with \`permissions\``);
2891
+ const named2 = new Set(manifest.operations.flatMap((operation) => permissionsOf(operation).map(({ key }) => key)));
2892
+ const unnamed = Object.values(options.bodyPermissions ?? {}).flat().filter(({ key }) => !named2.has(key));
2893
+ if (unnamed.length > 0)
2894
+ throw new CliError("configuration_error", `bodyPermissions name ${unnamed.map(({ key }) => key).join(", ")}, which the manifest does not: the keys come from \`permissions\``);
2895
+ const exchange = httpApiExchange({
2896
+ service: options.service,
2897
+ fetch: options.fetch,
2898
+ ...options.failure ? { failure: options.failure } : {},
2899
+ ...options.failedAnswer ? { failedAnswer: options.failedAnswer } : {}
2900
+ });
2901
+ const operationOf2 = /* @__PURE__ */ __name((name) => {
2902
+ const named3 = /* @__PURE__ */ __name((one) => pathOf3(one) === name || one.command === name || one.id === name, "named");
2903
+ const found = operations.find(named3);
2904
+ if (found)
2905
+ return found;
2906
+ const id2 = manifest.operations.find(named3)?.id ?? name;
2907
+ const why = options.excluded?.find((one) => one.id === name) ?? left.find((one) => one.id === id2);
2908
+ throw new CliError("not_found", why ? `${name} is not offered: ${why.reason}` : `no ${options.service} API operation ${name}; see ${app.command} api list`);
2909
+ }, "operationOf");
2910
+ const signed = /* @__PURE__ */ __name(async (command, operation, request) => {
2911
+ const { token } = options;
2912
+ const baseUrl = baseUrlOf(command);
2913
+ if (!underBase(request.url, baseUrl))
2914
+ throw new CliError("validation_error", `${operation.command} would leave ${baseUrl}`, { sent: false });
2915
+ await signRequest(manifest, operation, request, token && (() => token(command)));
2916
+ if (options.serverVariables)
2917
+ request.redirect = "manual";
2918
+ for (const [name, value] of Object.entries(options.headers?.(command, operation) ?? {}))
2919
+ request.headers.set(name, value);
2920
+ return request;
2921
+ }, "signed");
2922
+ const guardOf2 = /* @__PURE__ */ __name((command, extra, confirmed = [], own2) => {
2923
+ const { settings, env, renderer } = baseContext(command, configuration.resolveSettings);
2924
+ const levelOf = /* @__PURE__ */ __name((key) => levelFor(settings.permissions, key, defaults).level, "levelOf");
2925
+ const asker = terminalAsker(command);
2926
+ return keyedGuard((ask) => guardFor(app, { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, renderer.warn, env, ask), confirmed.length === 0 ? asker : async (_key, asked) => {
2927
+ const asking = [...own2 ? [own2] : [], ...extra].filter((key) => levelOf(key) === "ask" && !confirmed.includes(key));
2928
+ if (asking.length > 0)
2929
+ await asker(asking.join(" and "), asked);
2930
+ }, levelOf, extra);
2931
+ }, "guardOf");
2932
+ const readsFreely = /* @__PURE__ */ __name((command, operation, extra) => {
2933
+ if (operation.effect !== "read")
2934
+ return false;
2935
+ if (extra.length === 0)
2936
+ return true;
2937
+ guardOf2(command, extra).refuse({ chatId: null, kind: "edit", key: keyOf2(operation), operationId: newOperationId() });
2938
+ const { settings } = baseContext(command, configuration.resolveSettings);
2939
+ return extra.every((key) => levelFor(settings.permissions, key, defaults).level !== "ask");
2940
+ }, "readsFreely");
2941
+ const write2 = /* @__PURE__ */ __name(async (command, operation, extra, request, confirmed = []) => {
2942
+ const { run } = baseContext(command, configuration.resolveSettings);
2943
+ const operationId = newOperationId();
2944
+ const guard = guardOf2(command, extra, confirmed, keyOf2(operation));
2945
+ const guarded = { chatId: null, kind: "edit", key: keyOf2(operation), operationId };
2946
+ guard.refuse(guarded);
2947
+ try {
2948
+ const result = await guardedWrite(guard, guarded, () => run(async () => (await exchange(command, operation, request)).answer));
2949
+ return { operation_id: operationId, result };
2950
+ } catch (error) {
2951
+ if (isCliError(error) && error.code === "outcome_unknown")
2952
+ throw new CliError("outcome_unknown", error.message, { ...error.details, operation_id: operationId });
2953
+ throw error;
2954
+ }
2955
+ }, "write");
2956
+ const refuseBeforeBody = /* @__PURE__ */ __name((command, operation) => {
2957
+ const extra = permissionsOf(operation).filter((permission) => whenOf(permission) === void 0).map(({ key }) => key);
2958
+ if (operation.effect === "read" && extra.length === 0)
2959
+ return;
2960
+ guardOf2(command, extra).refuse({ chatId: null, kind: "edit", key: keyOf2(operation), operationId: newOperationId() });
2961
+ }, "refuseBeforeBody");
2962
+ return {
2963
+ operations,
2964
+ left,
2965
+ baseUrlOf,
2966
+ defaults,
2967
+ exchange,
2968
+ operationOf: operationOf2,
2969
+ readsFreely,
2970
+ refuseBeforeBody,
2971
+ signed,
2972
+ write: write2
2973
+ };
2974
+ }, "serviceApiCore");
2975
+ var serviceApiCommand = /* @__PURE__ */ __name((options) => {
2976
+ const { app, configuration, manifest } = options;
2977
+ const { operations, baseUrlOf, exchange, operationOf: operationOf2, readsFreely, refuseBeforeBody, signed, write: write2 } = serviceApiCore(options);
2978
+ const send = /* @__PURE__ */ __name(async (command, operation, request) => (await exchange(command, operation, request)).answer, "send");
2979
+ let schemas;
2980
+ const loaded = /* @__PURE__ */ __name(() => {
2981
+ if (!schemas)
2982
+ throw new CliError("configuration_error", "the api schemas were not loaded before the command ran");
2983
+ return schemas;
2984
+ }, "loaded");
2985
+ const load = /* @__PURE__ */ __name(async () => {
2986
+ schemas ??= await options.schemas();
2987
+ }, "load");
2988
+ const allPages = /* @__PURE__ */ __name(async (command, operation, input) => {
2989
+ const pagination = operation.pagination;
2990
+ if (pagination.style === "page" && pagination.start === void 0 && parameterValue(input, pagination.page) === void 0)
2991
+ throw new CliError("validation_error", `--all on ${operation.command} needs the first page: give --${pagination.page.name} 0 or 1, as ${options.service} counts`);
2992
+ const items = [];
2993
+ const asked = /* @__PURE__ */ new Set();
2994
+ const baseUrl = baseUrlOf(command);
2995
+ let call2 = input;
2996
+ let url;
2997
+ await baseContext(command, configuration.resolveSettings).run(async () => {
2998
+ for (let page = 0; ; page++) {
2999
+ if (page >= MOST_PAGES)
3000
+ throw new CliError("validation_error", `${operation.command} has more than ${MOST_PAGES} pages; narrow it with its own flags, or page it yourself`);
3001
+ const unsigned = httpApiRequest(operation, call2, baseUrl);
3002
+ if (url !== void 0)
3003
+ unsigned.url = new URL(url);
3004
+ const request = await signed(command, operation, unsigned);
3005
+ const key = `${request.url.href} ${request.body ?? ""}`;
3006
+ if (asked.has(key))
3007
+ throw new CliError("invalid_response", `${options.service} gave the same next page twice; nothing more read`);
3008
+ asked.add(key);
3009
+ const { answer, headers } = await exchange(command, operation, request);
3010
+ const step = nextPage(pagination, call2, answer, headers);
3011
+ for (const item of step.items)
3012
+ items.push(item);
3013
+ if (!step.next)
3014
+ return;
3015
+ if ("url" in step.next) {
3016
+ url = new URL(step.next.url, request.url);
3017
+ if (!underBase(url, baseUrl))
3018
+ throw new CliError("invalid_response", `${options.service} pointed the next page outside ${baseUrl}`);
3019
+ } else
3020
+ call2 = step.next.input;
3021
+ }
3022
+ });
3023
+ renderAnswer(command, outputFor(command), listOf(`api ${pathOf3(operation)}`, { items, limit: items.length, has_more: false }));
3024
+ }, "allPages");
3025
+ const refuseOwnFiles = /* @__PURE__ */ __name((command, path2) => {
3026
+ if (path2 === "-")
3027
+ return;
3028
+ const { env } = baseContext(command, configuration.resolveSettings);
3029
+ if (refusedPlace(path2, app, env))
3030
+ throw new CliError("validation_error", `--body-file may not read ${path2}: it holds sign-ins or state`);
3031
+ }, "refuseOwnFiles");
3032
+ const generated = generatedApiCommand({
3033
+ operations,
3034
+ checkParameter: /* @__PURE__ */ __name((name, schema2, raw) => checkApiParameter(name, schema2, raw, loaded()), "checkParameter"),
3035
+ before: refuseBeforeBody,
3036
+ checkBody: /* @__PURE__ */ __name((operation, text2) => checkApiBody(operation, text2, loaded()), "checkBody"),
3037
+ readBody: /* @__PURE__ */ __name((command, body) => {
3038
+ if (body.bodyFile !== void 0)
3039
+ refuseOwnFiles(command, body.bodyFile);
3040
+ return readApiBody(body);
3041
+ }, "readBody"),
3042
+ readBytes: /* @__PURE__ */ __name((command, path2) => {
3043
+ refuseOwnFiles(command, path2);
3044
+ return readApiBytes(path2);
3045
+ }, "readBytes"),
3046
+ configure: /* @__PURE__ */ __name((command, operation) => {
3047
+ if (operation.pagination && !operation.parameters.some(({ name }) => name === "all"))
3048
+ command.option("--all", "read every page, as the API pages it");
3049
+ command.hook("preAction", load);
3050
+ }, "configure"),
3051
+ execute: /* @__PURE__ */ __name(async (command, operation, input) => {
3052
+ const extra = serviceApiKeys(options, operation, input);
3053
+ const read = readsFreely(command, operation, extra);
3054
+ if (operation.pagination && command.opts().all === true) {
3055
+ if (!read)
3056
+ throw new CliError("validation_error", `--all reads only; this call of ${operation.command} is guarded by ${extra.join(", ") || "its write"}`);
3057
+ return allPages(command, operation, input);
3058
+ }
3059
+ const request = await signed(command, operation, httpApiRequest(operation, input, baseUrlOf(command)));
3060
+ const answer = read ? await baseContext(command, configuration.resolveSettings).run(() => send(command, operation, request)) : await write2(command, operation, extra, request);
3061
+ renderAnswer(command, outputFor(command), itemOf(answer));
3062
+ }, "execute")
3063
+ });
3064
+ const list = withQuery(annotate(new Command("list"), {
3065
+ effects: NO_EFFECTS,
3066
+ examples: [`${app.command} api list`, `${app.command} api list effect:destructive --json=command,path`]
3067
+ }), API_QUERY).description(`list every ${options.service} API operation this CLI offers, without calling ${options.service}`).action(function(words) {
3068
+ const terms = queryTerms(words, API_QUERY, "api list");
3069
+ const effect = terms.get("effect");
3070
+ const tag = terms.get("tag");
3071
+ const items = operations.filter((one) => (!effect || one.effect === effect) && (!tag || one.tags.includes(tag))).map(rowOf);
3072
+ renderAnswer(this, outputFor(this), listOf("api list", { items, limit: items.length, has_more: false }));
3073
+ });
3074
+ const show = annotate(new Command("show"), {
3075
+ effects: NO_EFFECTS,
3076
+ examples: [
3077
+ `${app.command} api show ${operations[0] ? JSON.stringify(pathOf3(operations[0])) : "<operation>"} --json`
3078
+ ]
3079
+ }).description(`show one operation's parameters and request schema, without calling ${options.service}`).argument("<operation>", "the operation as api list prints it (quoted), its old name, or its operation id").action(async function(name) {
3080
+ const operation = operationOf2(name);
3081
+ const definitions = await options.definitions();
3082
+ const schema2 = operation.request?.schema ? definitions[operation.request.schema] : void 0;
3083
+ renderAnswer(this, outputFor(this), itemOf({ operation, ...options.shown, ...schema2 ? { request_schema: schema2 } : {} }));
3084
+ });
3085
+ const graphql = operations.length > 0 && operations.every((one) => one.binding.kind === "graphql");
3086
+ const described = options.spec ?? (graphql ? "its GraphQL schema" : "its OpenAPI document");
3087
+ const group = annotate(new Command("api"), { effects: NO_EFFECTS }).description(`the raw ${options.service} API, one command per operation of ${described}`);
3088
+ group.addCommand(list).addCommand(show);
3089
+ for (const child of [...generated.commands])
3090
+ group.addCommand(child);
3091
+ markRenamedPermissionKeys(group, new Map(manifest.operations.flatMap((operation) => {
3092
+ const former = formerKeyOf(operation);
3093
+ return former ? [[former, keyOf2(operation)]] : [];
3094
+ })));
3095
+ return group;
3096
+ }, "serviceApiCommand");
3097
+ var flagText = /* @__PURE__ */ __name((raw) => Array.isArray(raw) ? raw.join(",") : String(raw), "flagText");
3098
+ var writerBody = /* @__PURE__ */ __name((operation, input, schemas) => {
3099
+ if (sendsBytes(operation) || operation.binding.kind === "rpc")
3100
+ return input;
3101
+ const graphql = operation.binding.kind === "graphql";
3102
+ const given = graphql ? apiJson(graphqlVariables(operation, input.body, input.fields ?? {})) : input.body;
3103
+ const body = checkApiBody(operation, given, schemas);
3104
+ return { ...input, ...graphql ? { fields: {} } : {}, ...body === void 0 ? {} : { body } };
3105
+ }, "writerBody");
3106
+ var serviceApiWriter = /* @__PURE__ */ __name((options) => {
3107
+ const { baseUrlOf, operationOf: operationOf2, signed, write: write2 } = serviceApiCore(options);
3108
+ return async (command, name, input, { confirmed } = {}) => {
3109
+ const operation = operationOf2(name);
3110
+ const undeclared = Object.keys(input.query).filter((one) => !operation.parameters.some((parameter) => parameter.in === "query" && parameter.name === one));
3111
+ const overriding = Object.keys(input.headers ?? {}).filter((one) => !operation.parameters.some((parameter) => parameter.in === "header" && parameter.name.toLowerCase() === one.toLowerCase()));
3112
+ if (undeclared.length > 0 || overriding.length > 0)
3113
+ throw new CliError("configuration_error", `${operation.command} does not take ${[...undeclared, ...overriding].join(", ")}`, { sent: false });
3114
+ const extra = serviceApiKeys(options, operation, input);
3115
+ if (operation.effect === "read" && extra.length === 0)
3116
+ throw new CliError("configuration_error", `${operation.command} is a read; send it with serviceApiCall`);
3117
+ const schemas = await options.schemas();
3118
+ const headers = Object.entries(input.headers ?? {});
3119
+ for (const parameter of operation.parameters) {
3120
+ const raw = parameter.in === "header" ? headers.find(([one]) => one.toLowerCase() === parameter.name.toLowerCase())?.[1] : parameter.in === "query" || parameter.in === "path" ? input[parameter.in][parameter.name] : void 0;
3121
+ if (parameter.required && raw !== void 0 && isBlank(flagText(raw)))
3122
+ throw new CliError("validation_error", `${parameter.name} of ${operation.command} is empty`, { sent: false });
3123
+ const problem = raw === void 0 ? void 0 : checkApiParameter(parameter.name, parameter.schema, flagText(raw), schemas);
3124
+ if (problem)
3125
+ throw new CliError("validation_error", problem);
3126
+ }
3127
+ const request = await signed(command, operation, httpApiRequest(operation, writerBody(operation, input, schemas), baseUrlOf(command)));
3128
+ return write2(command, operation, extra, request, confirmed);
3129
+ };
3130
+ }, "serviceApiWriter");
3131
+
3132
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/cli/service-api-call.js
3133
+ var hostsFetch = /* @__PURE__ */ __name((hosts, fetch, credentialScope) => hostFetch({ hosts, ...fetch ? { fetch } : {}, ...credentialScope ? { credentialScope } : {} }), "hostsFetch");
3134
+ var NO_COMMAND = new Command("source");
3135
+ var sender = /* @__PURE__ */ __name((options, writes) => {
3136
+ const baseUrl = manifestBaseUrl(options.manifest, options.baseUrl, options.serverVariables);
3137
+ const operations = new Map(options.manifest.operations.map((one) => [one.id, one]));
3138
+ const exchange = httpApiExchange({
3139
+ service: options.service,
3140
+ fetch: /* @__PURE__ */ __name(() => options.fetch, "fetch"),
3141
+ failure: options.failure,
3142
+ failedAnswer: options.failedAnswer
3143
+ });
3144
+ return async (id2, input) => {
3145
+ const operation = operations.get(id2);
3146
+ if (!operation)
3147
+ throw new CliError("configuration_error", `no ${options.service} API operation ${id2}`);
3148
+ if (!writes && operation.effect !== "read")
3149
+ throw new CliError("configuration_error", `${operation.command} is not a read; a source only reads`);
3150
+ const request = httpApiRequest(operation, input, baseUrl);
3151
+ if (!underBase(request.url, baseUrl))
3152
+ throw new CliError("validation_error", `${operation.command} would leave ${baseUrl}`, { sent: false });
3153
+ const extra = Object.entries(options.headers?.(operation) ?? {});
3154
+ for (const [name, value] of extra)
3155
+ request.headers.set(name, value);
3156
+ await signRequest(options.manifest, operation, request, options.token);
3157
+ if (extra.length || options.serverVariables)
3158
+ request.redirect = "manual";
3159
+ const { answer, headers } = await exchange(NO_COMMAND, operation, request);
3160
+ return { body: answer, headers };
3161
+ };
3162
+ }, "sender");
3163
+ var serviceApiCall = /* @__PURE__ */ __name((options) => {
3164
+ const withHeaders = sender(options, false);
3165
+ return Object.assign(async (id2, input) => (await withHeaders(id2, input)).body, {
3166
+ withHeaders
3167
+ });
3168
+ }, "serviceApiCall");
3169
+
3170
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/profile-writes.js
3171
+ var levelsOf = /* @__PURE__ */ __name((writes, defaults) => {
3172
+ const settings = writes.settings();
3173
+ return { settings, defaults: { ...DEFAULT_PERMISSIONS, ...defaults, ...settings.permissionDefaults } };
3174
+ }, "levelsOf");
3175
+ var profileWriteGuard = /* @__PURE__ */ __name((writes, ask, builtIn, extra) => {
3176
+ const { settings, defaults } = levelsOf(writes, builtIn);
3177
+ return keyedGuard((asker) => guardFor(writes.app, { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, writes.warn ?? (() => {
3178
+ }), writes.env, asker), ask, (key) => levelFor(settings.permissions, key, defaults).level, extra);
3179
+ }, "profileWriteGuard");
3180
+
3181
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/foreign-contacts.js
1884
3182
  import { readFileSync as readFileSync5 } from "node:fs";
1885
3183
  import { join as join4 } from "node:path";
1886
3184
 
1887
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/state-folders.js
3185
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/state-folders.js
1888
3186
  var CRM_SHARED_FOLDERS = { files: "files", foreignContacts: "foreign-contacts" };
1889
3187
 
1890
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/foreign-contacts.js
3188
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/foreign-contacts.js
1891
3189
  var DAILY_FOREIGN_CONTACTS = 100;
1892
3190
  var foreignContactsPathFor = /* @__PURE__ */ __name((app, account, env = process.env, user) => join4(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "crm", CRM_SHARED_FOLDERS.foreignContacts, `${[account.provider, account.account, ...user ? [user] : []].join("-").replace(/[^\w.-]+/gu, "_")}.json`), "foreignContactsPathFor");
1893
3191
  var shownIn = /* @__PURE__ */ __name((file, day) => {
@@ -1965,7 +3263,7 @@ var refuseForeignClientReads = /* @__PURE__ */ __name(async (source, readsClient
1965
3263
  throw new CliError("permission_error", `${method} reads contacts or companies, which only the CRM's administrator reads through api call: your clients come with sync, and another one with people show or organizations show, ${DAILY_FOREIGN_CONTACTS} a day`, { reason: "crm.client-reads-admin-only", sent: false });
1966
3264
  }, "refuseForeignClientReads");
1967
3265
 
1968
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/writer.js
3266
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/writer.js
1969
3267
  var CRM_ASSIGN_OTHERS_KEY = "crm.assign-others";
1970
3268
  var CRM_WRITE_KEYS = [CRM_ASSIGN_OTHERS_KEY];
1971
3269
  var PLURALS = {
@@ -1981,8 +3279,15 @@ var VERB_OF = {
1981
3279
  close: "close",
1982
3280
  delete: "remove"
1983
3281
  };
1984
- var crmAlsoChecks = /* @__PURE__ */ __name((also) => (path2) => {
3282
+ var crmAlsoChecks = /* @__PURE__ */ __name((also, activities) => (path2) => {
1985
3283
  const [noun, command] = path2;
3284
+ if (noun === "activities" && command === "close" && path2.length === 2)
3285
+ return activities?.("close") ?? [];
3286
+ if (noun === "activities" && command === "create" && path2.length === 2)
3287
+ return [
3288
+ { key: CRM_ASSIGN_OTHERS_KEY, when: "--owner other than the sign-in's user" },
3289
+ ...["comment", "task"].flatMap((write2) => (activities?.(write2) ?? []).map((key) => ({ key, when: `a ${write2}` })))
3290
+ ];
1986
3291
  const kind2 = noun === void 0 ? void 0 : PLURALS[noun];
1987
3292
  const verb = command === void 0 ? void 0 : VERB_OF[command];
1988
3293
  if (path2.length !== 2 || kind2 === void 0 || verb === void 0)
@@ -1998,7 +3303,7 @@ var CRM_WRITE_DEFAULTS = {
1998
3303
  [CRM_ASSIGN_OTHERS_KEY]: "deny"
1999
3304
  };
2000
3305
 
2001
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/writes.js
3306
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/writes.js
2002
3307
  var moneyChecked = /* @__PURE__ */ __name((check, param) => {
2003
3308
  try {
2004
3309
  check();
@@ -2021,7 +3326,7 @@ var COMMAND = {
2021
3326
  close: "close",
2022
3327
  remove: "delete"
2023
3328
  };
2024
- var keyOf2 = /* @__PURE__ */ __name((kind2, verb) => `${PLURAL[kind2]}.${COMMAND[verb]}`, "keyOf");
3329
+ var keyOf3 = /* @__PURE__ */ __name((kind2, verb) => `${PLURAL[kind2]}.${COMMAND[verb]}`, "keyOf");
2025
3330
  var OPERATION_ID = /^[\x21-\x7e]{1,255}$/u;
2026
3331
  var DECIMAL2 = /^\d{1,16}(\.\d{1,6})?$/u;
2027
3332
  var CURRENCY = /^[A-Z]{3}$/u;
@@ -2070,8 +3375,8 @@ var pipelineOf = /* @__PURE__ */ __name(async (context, kind2, reference, param
2070
3375
  const all = await context.store.deals.pipelines(scope);
2071
3376
  if (all.length === 1)
2072
3377
  return context.store.deals.pipeline(all[0].ref, scope);
2073
- const what = kind2 ? `${kind2} pipeline` : "pipeline";
2074
- throw new CliError("validation_error", all.length === 0 ? `no ${what} of this CRM is stored; run sync first` : `this CRM has ${all.length} ${what}s; name one${param.startsWith("--") ? ` with ${param}` : ""}: ` + all.map(({ name, ref }) => `${name} (${ref})`).join(", "), { reason: "crm.pipeline-required", param, allowed: all.map(({ ref }) => ref) });
3378
+ const what2 = kind2 ? `${kind2} pipeline` : "pipeline";
3379
+ throw new CliError("validation_error", all.length === 0 ? `no ${what2} of this CRM is stored; run sync first` : `this CRM has ${all.length} ${what2}s; name one${param.startsWith("--") ? ` with ${param}` : ""}: ` + all.map(({ name, ref }) => `${name} (${ref})`).join(", "), { reason: "crm.pipeline-required", param, allowed: all.map(({ ref }) => ref) });
2075
3380
  }, "pipelineOf");
2076
3381
  var stageOf = /* @__PURE__ */ __name((pipeline, given) => {
2077
3382
  const byId = pipeline.stages.find((stage) => stage.externalId === given);
@@ -2204,22 +3509,18 @@ var crmCustomValues = /* @__PURE__ */ __name((fields2, pairs) => {
2204
3509
  }));
2205
3510
  }, "crmCustomValues");
2206
3511
  var customOf = /* @__PURE__ */ __name(async (context, kind2, pairs) => pairs?.length ? crmCustomValues(await context.store.crm.fields(context.account, kind2), pairs) : void 0, "customOf");
2207
- var keysOf = /* @__PURE__ */ __name((context, kind2, verb, { stage, owner }) => {
3512
+ var selfOf = /* @__PURE__ */ __name(async ({ writes: { self } }) => (typeof self === "function" ? await self() : self) || void 0, "selfOf");
3513
+ var keysOf = /* @__PURE__ */ __name(async (context, kind2, verb, { stage, owner }) => {
2208
3514
  const extra = [];
2209
3515
  if (stage && verb !== "move")
2210
- extra.push(keyOf2(kind2, "move"));
3516
+ extra.push(keyOf3(kind2, "move"));
2211
3517
  if (stage && stage.outcome !== "open")
2212
- extra.push(keyOf2(kind2, "close"));
2213
- if (owner != null && owner !== context.writes.self)
3518
+ extra.push(keyOf3(kind2, "close"));
3519
+ if (owner != null && owner !== await selfOf(context))
2214
3520
  extra.push(CRM_ASSIGN_OTHERS_KEY);
2215
- return { key: keyOf2(kind2, verb), extra: [...extra, ...context.writes.alsoChecks?.(kind2, verb) ?? []] };
3521
+ return { key: keyOf3(kind2, verb), extra: [...extra, ...context.writes.alsoChecks?.(kind2, verb) ?? []] };
2216
3522
  }, "keysOf");
2217
- var guardOf = /* @__PURE__ */ __name((context, extra) => {
2218
- const settings = context.writes.settings();
2219
- const defaults = { ...DEFAULT_PERMISSIONS, ...CRM_WRITE_DEFAULTS, ...settings.permissionDefaults };
2220
- return keyedGuard((ask) => guardFor(context.writes.app, { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, context.writes.warn ?? (() => {
2221
- }), context.writes.env, ask), context.ask, (key) => levelFor(settings.permissions, key, defaults).level, extra);
2222
- }, "guardOf");
3523
+ var guardOf = /* @__PURE__ */ __name((context, extra) => profileWriteGuard(context.writes, context.ask, CRM_WRITE_DEFAULTS, extra), "guardOf");
2223
3524
  var written = /* @__PURE__ */ __name(async (context, { key, extra }, operationId, act) => {
2224
3525
  try {
2225
3526
  const done = await guardedWrite(guardOf(context, extra), { chatId: null, kind: "edit", key, operationId }, async () => {
@@ -2272,8 +3573,14 @@ var createCrmItem = /* @__PURE__ */ __name(async (context, kind2, input, options
2272
3573
  const custom = await customOf(context, kind2, input.custom);
2273
3574
  if (custom)
2274
3575
  fields2.custom = custom;
3576
+ if (fields2.owner === void 0 && context.writes.ownedByDefault?.includes(kind2)) {
3577
+ const self = await selfOf(context);
3578
+ if (self === void 0)
3579
+ throw invalid(`a new ${kind2} needs --owner: the sign-in names no CRM user`, "--owner");
3580
+ fields2.owner = self;
3581
+ }
2275
3582
  const operationId = operationOf(context, options.operationId);
2276
- const item = await written(context, keysOf(context, kind2, "create", { stage, owner: fields2.owner }), operationId, () => writer.create(kind2, fields2, { operationId }));
3583
+ const item = await written(context, await keysOf(context, kind2, "create", { stage, owner: fields2.owner }), operationId, () => writer.create(kind2, fields2, { operationId }));
2277
3584
  return { operationId, item: await kept(context, kind2, item, operationId) };
2278
3585
  }, "createCrmItem");
2279
3586
  var updateCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, input, options = {}) => {
@@ -2290,7 +3597,7 @@ var updateCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, inp
2290
3597
  if (Object.keys(fields2).length === 0)
2291
3598
  throw invalid("nothing to change: name a field");
2292
3599
  const operationId = operationOf(context, options.operationId);
2293
- const item = await written(context, keysOf(context, kind2, "update", { stage, owner: fields2.owner }), operationId, () => writer.update(kind2, copy.externalId, fields2, { operationId }));
3600
+ const item = await written(context, await keysOf(context, kind2, "update", { stage, owner: fields2.owner }), operationId, () => writer.update(kind2, copy.externalId, fields2, { operationId }));
2294
3601
  return { operationId, item: await kept(context, kind2, item, operationId) };
2295
3602
  }, "updateCrmItem");
2296
3603
  var moveCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, stageName, options = {}) => {
@@ -2299,7 +3606,7 @@ var moveCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, stage
2299
3606
  const copy = await copyOf(context, kind2, reference);
2300
3607
  const stage = stageOf(await pipelineOf(context, kind2, copy.pipeline), stageName);
2301
3608
  const operationId = operationOf(context, options.operationId);
2302
- const item = await written(context, keysOf(context, kind2, "move", { stage }), operationId, () => writer.move(kind2, copy.externalId, stage.externalId, { operationId }));
3609
+ const item = await written(context, await keysOf(context, kind2, "move", { stage }), operationId, () => writer.move(kind2, copy.externalId, stage.externalId, { operationId }));
2303
3610
  return { operationId, item: await kept(context, kind2, item, operationId) };
2304
3611
  }, "moveCrmItem");
2305
3612
  var closeCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, outcome, options = {}) => {
@@ -2312,7 +3619,7 @@ var closeCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, outc
2312
3619
  if (reason !== void 0 && (reason === "" || reason.length > 2e3))
2313
3620
  throw invalid("--reason is 1 to 2000 characters", "--reason");
2314
3621
  const operationId = operationOf(context, options.operationId);
2315
- const item = await written(context, keysOf(context, kind2, "close", {}), operationId, () => writer.close(kind2, copy.externalId, outcome, { operationId, ...reason ? { reason } : {} }));
3622
+ const item = await written(context, await keysOf(context, kind2, "close", {}), operationId, () => writer.close(kind2, copy.externalId, outcome, { operationId, ...reason ? { reason } : {} }));
2316
3623
  return { operationId, item: await kept(context, kind2, item, operationId) };
2317
3624
  }, "closeCrmItem");
2318
3625
  var removeCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, options = {}) => {
@@ -2320,7 +3627,7 @@ var removeCrmItem = /* @__PURE__ */ __name(async (context, kind2, reference, opt
2320
3627
  supported(writer, kind2, "remove");
2321
3628
  const copy = await copyOf(context, kind2, reference);
2322
3629
  const operationId = operationOf(context, options.operationId);
2323
- await written(context, keysOf(context, kind2, "remove", {}), operationId, () => writer.remove(kind2, copy.externalId, { operationId }));
3630
+ await written(context, await keysOf(context, kind2, "remove", {}), operationId, () => writer.remove(kind2, copy.externalId, { operationId }));
2324
3631
  const removed = await context.store.crm.remove(context.account, kind2, [copy.externalId]);
2325
3632
  return { operationId, ref: copy.ref, removed };
2326
3633
  }, "removeCrmItem");
@@ -2393,7 +3700,7 @@ var writeRecord = /* @__PURE__ */ __name(async (context, kind2, verb, fields2, o
2393
3700
  if (!context.source)
2394
3701
  throw new CliError("configuration_error", "a contact or company write needs the CRM source to tell your clients");
2395
3702
  const rule2 = foreignContacts(context.source(), void 0);
2396
- const record2 = await written(context, keysOf(context, kind2, verb, { owner: fields2.owner }), operationId, act);
3703
+ const record2 = await written(context, await keysOf(context, kind2, verb, { owner: fields2.owner }), operationId, act);
2397
3704
  const stored = await rule2.own(kind2, record2);
2398
3705
  let removed;
2399
3706
  try {
@@ -2444,11 +3751,122 @@ var updateCrmRecord = /* @__PURE__ */ __name(async (context, kind2, externalId,
2444
3751
  const operationId = operationOf(context, options.operationId);
2445
3752
  return writeRecord(context, kind2, "update", fields2, operationId, () => writer.update(kind2, externalId, fields2, { operationId }));
2446
3753
  }, "updateCrmRecord");
3754
+ var MOST_SUBJECT = 500;
3755
+ var MOST_BODY = 2e4;
3756
+ var activityInvalid = /* @__PURE__ */ __name((message, param) => new CliError("validation_error", message, { reason: "crm.activity-field", ...param ? { param } : {} }), "activityInvalid");
3757
+ var activityUnsupported = /* @__PURE__ */ __name((what2) => new CliError("validation_error", `this CRM does not take ${what2}`, { reason: "crm.write-unsupported", sent: false }), "activityUnsupported");
3758
+ var activityTargetOf = /* @__PURE__ */ __name(async (context, given) => {
3759
+ const at2 = given.indexOf(":");
3760
+ const kind2 = given.slice(0, at2);
3761
+ const id2 = given.slice(at2 + 1);
3762
+ if (kind2 === "deal" || kind2 === "lead") {
3763
+ const copy = await copyOf(context, kind2, given.trim());
3764
+ return { kind: kind2, externalId: copy.externalId, ref: copy.ref, title: copy.title };
3765
+ }
3766
+ if (kind2 === "person" || kind2 === "organization") {
3767
+ const crmId = id2.startsWith("crm:") ? id2.slice(4) : /^\d+$/.test(id2) ? void 0 : id2;
3768
+ if (crmId !== void 0 && RECORD_ID.test(crmId))
3769
+ return { kind: kind2, externalId: crmId, ref: null, title: null };
3770
+ if (crmId === void 0) {
3771
+ const ids2 = await context.store.crm.externalIdsOf(context.account, given);
3772
+ if (ids2.length > 1)
3773
+ throw new CliError("validation_error", `${given} is ${ids2.length} records of the CRM; name one as ${kind2}:crm:<id>`, {
3774
+ reason: "crm.record-ambiguous",
3775
+ param: "--subject",
3776
+ candidates: ids2.map((one) => ({ id: `${kind2}:crm:${one}` })),
3777
+ sent: false
3778
+ });
3779
+ if (ids2[0])
3780
+ return { kind: kind2, externalId: ids2[0], ref: given, title: null };
3781
+ throw new CliError("not_found", `the copy holds no ${given}; a ${kind2} by the CRM's id, as ${kind2 === "person" ? "people" : "organizations"} list prints it, is ${kind2}:crm:<id>`, { param: "--subject", sent: false });
3782
+ }
3783
+ }
3784
+ throw new CliError("validation_error", `--subject takes deal:<id>, lead:<id>, person:<id> or organization:<id> as the copy's lists and deals show give them, or person:crm:<id> or organization:crm:<id> by the CRM's id; got ${given}`, { reason: "ref.malformed", param: "--subject" });
3785
+ }, "activityTargetOf");
3786
+ var activityKeys = /* @__PURE__ */ __name(async (context, key, owner, write2) => ({
3787
+ key,
3788
+ extra: [
3789
+ ...owner !== void 0 && owner !== await selfOf(context) ? [CRM_ASSIGN_OTHERS_KEY] : [],
3790
+ ...context.writes.activityChecks?.(write2) ?? []
3791
+ ]
3792
+ }), "activityKeys");
3793
+ var keptActivity = /* @__PURE__ */ __name(async (context, activity, operationId) => {
3794
+ try {
3795
+ if (!await context.store.crm.activitiesOn(context.account))
3796
+ return false;
3797
+ return (await context.store.crm.saveActivities(context.account, [activity])).saved === 1;
3798
+ } catch (error) {
3799
+ throw new CliError("invalid_response", `the CRM wrote activity ${activity.externalId}, but the local store did not keep it (${error instanceof Error ? error.message : String(error)}); sync to store it \u2014 do not write it again`, { external_id: activity.externalId, operation_id: operationId, sent: true });
3800
+ }
3801
+ }, "keptActivity");
3802
+ var answeredTargets = /* @__PURE__ */ __name(async (context, activity, known) => Promise.all(activity.on.map(async ({ kind: kind2, externalId }) => known.find((one) => one.kind === kind2 && one.externalId === externalId) ?? {
3803
+ kind: kind2,
3804
+ externalId,
3805
+ ref: isItemKind(kind2) ? await context.store.crm.refOf(context.account, kind2, externalId) : null,
3806
+ title: null
3807
+ })), "answeredTargets");
3808
+ var createCrmActivity = /* @__PURE__ */ __name(async (context, kind2, input, options = {}) => {
3809
+ const { writer } = context.writes;
3810
+ const create = writer.createActivity?.bind(writer);
3811
+ if (!create || !writer.capabilities.activities?.includes(kind2))
3812
+ throw activityUnsupported(`a new ${kind2}`);
3813
+ const subject = input.title?.trim();
3814
+ const body = input.body?.trim();
3815
+ if (subject !== void 0 && (subject === "" || subject.length > MOST_SUBJECT))
3816
+ throw activityInvalid(`--title is 1 to ${MOST_SUBJECT} characters`, "--title");
3817
+ if (body !== void 0 && (body === "" || body.length > MOST_BODY))
3818
+ throw activityInvalid(`--text is 1 to ${MOST_BODY} characters`, "--text");
3819
+ if (kind2 === "task" && subject === void 0)
3820
+ throw activityInvalid("a new task needs --title", "--title");
3821
+ if (kind2 === "comment" && body === void 0)
3822
+ throw activityInvalid("a new comment needs --text", "--text");
3823
+ if (kind2 === "comment" && input.dueAt !== void 0)
3824
+ throw activityInvalid("a comment has no --due", "--due");
3825
+ if (kind2 === "comment" && input.owner !== void 0)
3826
+ throw activityInvalid("a comment has no --owner", "--owner");
3827
+ const owner = input.owner?.trim();
3828
+ if (owner !== void 0 && !owner)
3829
+ throw activityInvalid("--owner is the CRM user's id", "--owner");
3830
+ if (input.on.length === 0)
3831
+ throw activityInvalid("name the record it is on with --subject, such as deal:12", "--subject");
3832
+ const targets = [];
3833
+ for (const given of input.on) {
3834
+ const target = await activityTargetOf(context, given);
3835
+ if (!targets.some((one) => one.kind === target.kind && one.externalId === target.externalId))
3836
+ targets.push(target);
3837
+ }
3838
+ const draft = {
3839
+ kind: kind2,
3840
+ ...subject === void 0 ? {} : { subject },
3841
+ ...body === void 0 ? {} : { body },
3842
+ ...input.dueAt === void 0 ? {} : { dueAt: input.dueAt },
3843
+ ...owner === void 0 ? {} : { assignee: owner },
3844
+ on: targets.map(({ kind: kind3, externalId }) => ({ kind: kind3, externalId }))
3845
+ };
3846
+ const operationId = operationOf(context, options.operationId);
3847
+ const activity = await written(context, await activityKeys(context, "activities.create", owner, kind2), operationId, () => create(draft, { operationId }));
3848
+ const stored = await keptActivity(context, activity, operationId);
3849
+ return { operationId, activity, stored, on: await answeredTargets(context, activity, targets) };
3850
+ }, "createCrmActivity");
3851
+ var completeCrmActivity = /* @__PURE__ */ __name(async (context, externalId, options = {}) => {
3852
+ const { writer } = context.writes;
3853
+ const complete = writer.completeActivity?.bind(writer);
3854
+ if (!complete || !writer.capabilities.activities?.includes("task"))
3855
+ throw activityUnsupported("a task marked done");
3856
+ if (!RECORD_ID.test(externalId))
3857
+ throw new CliError("validation_error", "name the task by the CRM's id, as activities list prints it", {
3858
+ reason: "ref.malformed"
3859
+ });
3860
+ const operationId = operationOf(context, options.operationId);
3861
+ const activity = await written(context, await activityKeys(context, "activities.close", void 0, "close"), operationId, () => complete(externalId, { operationId }));
3862
+ const stored = await keptActivity(context, activity, operationId);
3863
+ return { operationId, activity, stored, on: await answeredTargets(context, activity, []) };
3864
+ }, "completeCrmActivity");
2447
3865
 
2448
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/file-fetch.js
3866
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/file-fetch.js
2449
3867
  var EXCHANGE_MS = 60 * 60 * 1e3;
2450
3868
 
2451
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/manifest/map.js
3869
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/manifest/map.js
2452
3870
  var at = /* @__PURE__ */ __name((value, path2) => path2 === "." ? value : path2.split(".").reduce((inner, key) => inner === null ? null : Array.isArray(inner) && /^\d+$/.test(key) ? inner[Number(key)] ?? null : isRaw(inner) ? inner[key] : void 0, value), "at");
2453
3871
  var TIMES = { createdAt: "epoch", updatedAt: "epoch" };
2454
3872
  var ITEM = {
@@ -2501,7 +3919,7 @@ var FIELDS = {
2501
3919
  lead: ITEM
2502
3920
  };
2503
3921
 
2504
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/manifest/manifest.js
3922
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/manifest/manifest.js
2505
3923
  var path = pipe(string(), regex(/^[^.\s]+(\.[^.\s]+)*$/, "a dotted path such as properties.name"));
2506
3924
  var paths = pipe(array(path), minLength(1));
2507
3925
  var crmRuleSchema = union([
@@ -2575,6 +3993,22 @@ var fields = strictObject({
2575
3993
  keep: optional(union([strictObject({ path, is: unknown() }), function_()]))
2576
3994
  });
2577
3995
  var kind = picklist(CRM_KINDS);
3996
+ var writeShape = {
3997
+ each: optional(unknown()),
3998
+ list: optional(literal(true)),
3999
+ number: optional(literal(true)),
4000
+ decimals: optional(pipe(number(), integer(), minValue(0)))
4001
+ };
4002
+ var writeRule = strictObject({ to: pipe(string(), minLength(1)), ...writeShape });
4003
+ var write = strictObject({
4004
+ create: optional(call),
4005
+ update: optional(call),
4006
+ remove: optional(call),
4007
+ id: optional(path),
4008
+ fields: record(string(), union([writeRule, literal("implied"), strictObject({ fixed: call, at: path })])),
4009
+ custom: optional(strictObject(writeShape)),
4010
+ clear: optional(unknown())
4011
+ });
2578
4012
  var schema = strictObject({
2579
4013
  provider: pipe(string(), regex(/^[a-z][a-z0-9-]*$/, "a registry name such as hubspot")),
2580
4014
  kinds: pipe(array(kind), minLength(1)),
@@ -2591,13 +4025,14 @@ var schema = strictObject({
2591
4025
  position: optional(rule),
2592
4026
  active: optional(rule)
2593
4027
  })
2594
- }))
4028
+ })),
4029
+ writes: optional(record(kind, optional(write)))
2595
4030
  });
2596
4031
 
2597
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/manifest/source.js
4032
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/manifest/source.js
2598
4033
  var OVERLAP_MS = 10 * 6e4;
2599
4034
 
2600
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/sends/pace.js
4035
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/sends/pace.js
2601
4036
  import { readFileSync as readFileSync6, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
2602
4037
  import { join as join5 } from "node:path";
2603
4038
  var DEFAULT_PACE = { perMinute: 60, burst: 20 };
@@ -2689,13 +4124,13 @@ var waitForTurn = /* @__PURE__ */ __name(async (pacer, options) => {
2689
4124
  counts: { seconds }
2690
4125
  });
2691
4126
  }
2692
- await (options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(waitMs);
4127
+ await (options.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms))))(waitMs);
2693
4128
  }, "waitForTurn");
2694
4129
 
2695
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/provider-call.js
4130
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/provider-call.js
2696
4131
  var RETRY = { retries: 3, baseDelayMs: 1e3, maxDelayMs: 1e4, maxRetryAfterMs: 3e4 };
2697
4132
  var UNANSWERED = /* @__PURE__ */ new Set(["timeout", "network_error", "provider_unavailable", "cancelled", "invalid_response"]);
2698
- var unanswered = /* @__PURE__ */ __name((error) => !isCliError(error) || UNANSWERED.has(error.code) && error.details.sent !== false, "unanswered");
4133
+ var unanswered2 = /* @__PURE__ */ __name((error) => !isCliError(error) || UNANSWERED.has(error.code) && error.details.sent !== false, "unanswered");
2699
4134
  var providerCall = /* @__PURE__ */ __name(async (options) => {
2700
4135
  const retries = options.retries ?? RETRY.retries;
2701
4136
  const sleep = options.sleep ?? ((ms) => realSleep(ms));
@@ -2712,7 +4147,7 @@ var providerCall = /* @__PURE__ */ __name(async (options) => {
2712
4147
  continue;
2713
4148
  throw error;
2714
4149
  }
2715
- if (options.write && unanswered(error))
4150
+ if (options.write && unanswered2(error))
2716
4151
  throw new CliError("outcome_unknown", `${error instanceof Error ? error.message : String(error)}; the CRM may or may not have carried it out`, { ...isCliError(error) ? error.details : {}, retryable: false });
2717
4152
  if (!isCliError(error))
2718
4153
  throw error;
@@ -2728,7 +4163,7 @@ var providerCall = /* @__PURE__ */ __name(async (options) => {
2728
4163
  }
2729
4164
  }, "providerCall");
2730
4165
 
2731
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/query.js
4166
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/query.js
2732
4167
  var valueFor = /* @__PURE__ */ __name((kind2, raw, name) => {
2733
4168
  if (kind2 === "id") {
2734
4169
  if (!/^[\w.:-]{1,100}$/u.test(raw))
@@ -2829,7 +4264,7 @@ var selectedCodes = /* @__PURE__ */ __name((fields2, wanted) => {
2829
4264
  });
2830
4265
  }, "selectedCodes");
2831
4266
 
2832
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/search/groups.js
4267
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/search/groups.js
2833
4268
  var ALL = "all";
2834
4269
  var OWNER_NOTES = { provider: "notes", account: INTERNAL_NOTES };
2835
4270
  var NOT_GROUP_NAMES = /* @__PURE__ */ new Set([ALL, "bots"]);
@@ -2901,7 +4336,7 @@ var groupEntries = /* @__PURE__ */ __name((saved) => ({
2901
4336
  [ALL]: [ALL]
2902
4337
  }), "groupEntries");
2903
4338
 
2904
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/services/search-kind.js
4339
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/services/search-kind.js
2905
4340
  var NO_MAIL = "no_mail";
2906
4341
  var MAIL = "email";
2907
4342
  var groupLockOf = /* @__PURE__ */ __name((app, env) => {
@@ -2926,10 +4361,10 @@ var listContextOf = /* @__PURE__ */ __name(async (store, account, app, stored, e
2926
4361
  if (!members)
2927
4362
  throw new CliError("permission_error", `this process is locked to group ${lock} (${envName(app, "GROUP_LOCK")}), which does not exist`);
2928
4363
  const only = new Set([...members, OWNER_NOTES].map(keyOf));
2929
- const listedAs = /* @__PURE__ */ __name((one) => isFolderProvider(one.provider) || isDocumentAccountProvider(one.provider) ? { provider: "notes", account: String(one.id) } : one, "listedAs");
4364
+ const listedAs = /* @__PURE__ */ __name((one) => isFolderProvider(one.provider) || isDocumentAccountProvider(one.provider) ? [{ provider: "notes", account: String(one.id) }, ...alsoListedByKey(one.provider) ? [one] : []] : [one], "listedAs");
2930
4365
  return {
2931
4366
  ...context,
2932
- held: held.filter((one) => only.has(keyOf(listedAs(one)))),
4367
+ held: held.filter((one) => listedAs(one).some((key) => only.has(keyOf(key)))),
2933
4368
  groups: { [lock]: groups[lock] ?? [] },
2934
4369
  membership: {
2935
4370
  groups: { [lock]: members },
@@ -2975,7 +4410,7 @@ var accountsOfKind = /* @__PURE__ */ __name((kind2, chosen, held, explicit, comm
2975
4410
  return chosenMail.map(({ provider, account }) => ({ provider, account }));
2976
4411
  }, "accountsOfKind");
2977
4412
 
2978
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/group-hint.js
4413
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/group-hint.js
2979
4414
  var workGroupHint = /* @__PURE__ */ __name((key) => `add it to a work group: \`memo groups add work ${key.provider}:${key.account}\``, "workGroupHint");
2980
4415
  var ungroupedHint = /* @__PURE__ */ __name(async (store, key) => {
2981
4416
  const { groups } = (await listContextOf(store, key, void 0)).membership;
@@ -2983,7 +4418,7 @@ var ungroupedHint = /* @__PURE__ */ __name(async (store, key) => {
2983
4418
  return grouped ? void 0 : workGroupHint(key);
2984
4419
  }, "ungroupedHint");
2985
4420
 
2986
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/viewer.js
4421
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/viewer.js
2987
4422
  var VIEWERS = "crm:viewers";
2988
4423
  var viewersOf = /* @__PURE__ */ __name(async (store, account) => {
2989
4424
  try {
@@ -3058,7 +4493,7 @@ var ownerOf = /* @__PURE__ */ __name(async (run, owner) => {
3058
4493
  return crmIdentityId(run.account, normalCrmUserId(owner), "user");
3059
4494
  }, "ownerOf");
3060
4495
 
3061
- // node_modules/.pnpm/@wirecat+cli-core@0.722.0_@wirecat+cli-base@0.127.0_commander@15.0.0_esbuild@0.28.2_typ_d2bed0cfbe6b4358c89d465b9e07afcb/node_modules/@wirecat/cli-core/dist/crm/sync.js
4496
+ // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/crm/sync.js
3062
4497
  var DAY2 = 864e5;
3063
4498
  var CLOCK_MARGIN = 60 * 6e4;
3064
4499
  var MOST_UNLISTED = 0.5;
@@ -3075,7 +4510,7 @@ var parseCrmCursor = /* @__PURE__ */ __name((value) => {
3075
4510
  const pass = cursor.pass;
3076
4511
  if (round != null && (!isToken(round.from) || !isToken(round.page) || typeof round.reset !== "boolean"))
3077
4512
  return null;
3078
- if (pass != null && (!isToken(pass.page) || typeof pass.startedAt !== "number" || !Array.isArray(pass.seen) || pass.seen.some((id2) => typeof id2 !== "string")))
4513
+ if (pass != null && (!isToken(pass.page) || typeof pass.startedAt !== "number" || !Array.isArray(pass.seen) || pass.seen.some((id2) => typeof id2 !== "string") || pass.unread !== void 0 && pass.unread !== true))
3079
4514
  return null;
3080
4515
  return {
3081
4516
  v: 1,
@@ -3110,7 +4545,7 @@ var scopeOf = /* @__PURE__ */ __name((error) => {
3110
4545
  const scope = error instanceof CliError ? error.details?.scope : void 0;
3111
4546
  return typeof scope === "string" && scope ? scope : void 0;
3112
4547
  }, "scopeOf");
3113
- var refusal = /* @__PURE__ */ __name((kind2, consequence, error, provider) => {
4548
+ var refusal2 = /* @__PURE__ */ __name((kind2, consequence, error, provider) => {
3114
4549
  const code = error instanceof CliError ? error.code : "error";
3115
4550
  const scope = scopeOf(error);
3116
4551
  const message = scope ? `${scope} scope missing: ${consequence}` : `${provider} did not list ${kind2} (${code}): ${consequence}`;
@@ -3157,7 +4592,7 @@ var readUsers = /* @__PURE__ */ __name(async (run) => {
3157
4592
  } catch (error) {
3158
4593
  if (run.signal?.aborted || error instanceof BudgetSpent)
3159
4594
  throw error;
3160
- gap(refusal("users", "nothing stored about them changed", error, source.provider));
4595
+ gap(refusal2("users", "nothing stored about them changed", error, source.provider));
3161
4596
  return null;
3162
4597
  }
3163
4598
  let departments;
@@ -3176,7 +4611,7 @@ var readUsers = /* @__PURE__ */ __name(async (run) => {
3176
4611
  } catch (error) {
3177
4612
  if (run.signal?.aborted || error instanceof BudgetSpent)
3178
4613
  throw error;
3179
- gap(refusal("departments", "reporting lines unknown", error, source.provider));
4614
+ gap(refusal2("departments", "reporting lines unknown", error, source.provider));
3180
4615
  }
3181
4616
  }
3182
4617
  noted(run, "user", await run.store.crm.saveUsers(run.account, users, departments));
@@ -3193,14 +4628,33 @@ var activityCursor = /* @__PURE__ */ __name((value) => {
3193
4628
  return void 0;
3194
4629
  }
3195
4630
  }, "activityCursor");
3196
- var readActivities = /* @__PURE__ */ __name(async (run) => {
4631
+ var removeUnlistedActivities = /* @__PURE__ */ __name(async (run, options, seen) => {
4632
+ const { store, account, source } = run;
4633
+ const { stored, unlisted } = await store.crm.removeUnlistedActivities(account, seen, { dryRun: true });
4634
+ if (unlisted === 0)
4635
+ return;
4636
+ if (!options.rescan && (seen.length === 0 || stored >= GUARDED_FROM && unlisted > stored * MOST_UNLISTED)) {
4637
+ run.report.issues.push({
4638
+ kind: "deal",
4639
+ reason: "crm.activities-unlisted-held",
4640
+ message: `${source.provider} listed ${seen.length} activities, so ${unlisted} of the ${stored} stored would be marked deleted; nothing was \u2014 check the sign-in's rights, then run sync --rescan to let it through`
4641
+ });
4642
+ return;
4643
+ }
4644
+ const done = await store.crm.removeUnlistedActivities(account, seen);
4645
+ if (run.report.activities)
4646
+ run.report.activities.removed += done.unlisted;
4647
+ }, "removeUnlistedActivities");
4648
+ var readActivities = /* @__PURE__ */ __name(async (run, options) => {
3197
4649
  const { source, store, account } = run;
3198
4650
  if (!source.activities || !await store.crm.activitiesOn(account))
3199
4651
  return null;
3200
- const read = { saved: 0, outOfScope: 0, state: "partial" };
4652
+ const read = { saved: 0, outOfScope: 0, removed: 0, state: "partial" };
3201
4653
  run.report.activities = read;
3202
4654
  const saved = activityCursor((await store.sync.syncState(account, ACTIVITIES))?.value);
3203
4655
  const cursor = saved ?? { since: run.now - ACTIVITY_DAYS * DAY2, newest: 0 };
4656
+ const seen = cursor.page === void 0 ? /* @__PURE__ */ new Set() : void 0;
4657
+ const gaps = run.gaps.length;
3204
4658
  for (; ; ) {
3205
4659
  const why = run.budget.take();
3206
4660
  if (why)
@@ -3213,12 +4667,16 @@ var readActivities = /* @__PURE__ */ __name(async (run) => {
3213
4667
  throw error;
3214
4668
  if (!scopeOf(error))
3215
4669
  throw error;
3216
- run.gaps.push(refusal("activities", "no activity or task was read", error, source.provider));
4670
+ run.gaps.push(refusal2("activities", "no activity or task was read", error, source.provider));
3217
4671
  return null;
3218
4672
  }
3219
4673
  const done = await store.crm.saveActivities(account, page.items);
3220
4674
  read.saved += done.saved;
3221
4675
  read.outOfScope += done.outOfScope;
4676
+ if (page.removed?.length)
4677
+ read.removed += await store.crm.removeActivities(account, page.removed);
4678
+ for (const one of page.items)
4679
+ seen?.add(one.externalId);
3222
4680
  cursor.newest = Math.max(cursor.newest, ...page.items.map((one) => one.updatedAt));
3223
4681
  run.moved();
3224
4682
  if (page.hasMore && page.nextCursor !== void 0) {
@@ -3228,6 +4686,8 @@ var readActivities = /* @__PURE__ */ __name(async (run) => {
3228
4686
  return "cancelled";
3229
4687
  continue;
3230
4688
  }
4689
+ if (page.listedAll && seen && run.gaps.length === gaps)
4690
+ await removeUnlistedActivities(run, options, [...seen]);
3231
4691
  const next = page.cursor != null ? Number(page.cursor) : cursor.newest || cursor.since;
3232
4692
  await store.sync.setSyncState(account, ACTIVITIES, JSON.stringify({ since: next, newest: 0 }));
3233
4693
  read.state = "complete";
@@ -3442,6 +4902,8 @@ var syncKind = /* @__PURE__ */ __name(async (run, kind2, options, result) => {
3442
4902
  if (page.hasMore && page.nextCursor === void 0)
3443
4903
  throw new CliError("invalid_response", `${source.provider} said there are more ids but gave no cursor`);
3444
4904
  pass = { ...pass, seen: [...pass.seen, ...page.items], page: page.hasMore ? page.nextCursor ?? null : null };
4905
+ if (run.gaps.some((gap) => gap.kind === kind2))
4906
+ pass = { ...pass, unread: true };
3445
4907
  run.moved();
3446
4908
  if (!page.hasMore)
3447
4909
  break;
@@ -3451,12 +4913,14 @@ var syncKind = /* @__PURE__ */ __name(async (run, kind2, options, result) => {
3451
4913
  const stored = await store.crm.count(account, kind2);
3452
4914
  const unlisted = await store.crm.removeUnlisted(account, kind2, pass.seen, before2, { ...listedOf, dryRun: true });
3453
4915
  const emptied = pass.seen.length === 0 && unlisted > 0;
3454
- if (!options.rescan && (emptied || stored >= GUARDED_FROM && unlisted > stored * MOST_UNLISTED)) {
4916
+ const many = emptied || stored >= GUARDED_FROM && unlisted > stored * MOST_UNLISTED;
4917
+ const unread = pass.unread === true || run.gaps.some((gap) => gap.kind === kind2);
4918
+ if (unlisted > 0 && (unread || many && unlisted > (options.allowDeletions ?? 0))) {
3455
4919
  result.pass = "held";
3456
4920
  run.report.issues.push({
3457
4921
  kind: kind2,
3458
4922
  reason: "crm.unlisted-held",
3459
- message: `${source.provider} listed ${pass.seen.length} ${kind2} ids, so ${unlisted} of the ${stored} stored would be marked deleted; nothing was \u2014 check the sign-in's rights, then run sync --rescan to let it through`
4923
+ message: unread ? `${source.provider} could not read all ${kind2}s, so the ${unlisted} it did not list stay; nothing was marked deleted \u2014 check the sign-in's rights, then run sync again` : `${source.provider} listed ${pass.seen.length} ${kind2} ids, so ${unlisted} of the ${stored} stored would be marked deleted; nothing was \u2014 check the sign-in's rights, then run sync --allow-deletions ${unlisted} to let them through`
3460
4924
  });
3461
4925
  } else {
3462
4926
  result.unlisted = await store.crm.removeUnlisted(account, kind2, pass.seen, before2, listedOf);
@@ -3598,7 +5062,7 @@ var syncCrm = /* @__PURE__ */ __name(async (source, store, account, options = {}
3598
5062
  continue;
3599
5063
  }
3600
5064
  if (scopeOf(error))
3601
- run.gaps.push(refusal(kind2, `no ${kind2} was read`, error, source.provider));
5065
+ run.gaps.push(refusal2(kind2, `no ${kind2} was read`, error, source.provider));
3602
5066
  result.error = isCliFailure(error) ? error.message : `the ${kind2} copy could not be synced`;
3603
5067
  }
3604
5068
  }
@@ -3606,7 +5070,7 @@ var syncCrm = /* @__PURE__ */ __name(async (source, store, account, options = {}
3606
5070
  const rowsStopped = stopped;
3607
5071
  if (!stopped && kinds.some(isItemKind)) {
3608
5072
  try {
3609
- stopped = await stopping(() => readActivities(run));
5073
+ stopped = await stopping(() => readActivities(run, options));
3610
5074
  } catch (error) {
3611
5075
  if (options.signal?.aborted)
3612
5076
  stopped = "cancelled";
@@ -3723,6 +5187,15 @@ export {
3723
5187
  listContextOf,
3724
5188
  listedAccounts,
3725
5189
  accountsOfKind,
5190
+ uploadSize,
5191
+ typesText,
5192
+ realPathOf,
5193
+ refuseLockedOutput,
5194
+ refusedPlace,
5195
+ inside,
5196
+ readUpload,
5197
+ readAttachments,
5198
+ readStickerFile,
3726
5199
  parseCrmFileId,
3727
5200
  withoutFileLinks,
3728
5201
  CRM_SHARED_FOLDERS,
@@ -3732,7 +5205,6 @@ export {
3732
5205
  values_exports,
3733
5206
  at,
3734
5207
  identifier,
3735
- graphqlDocument,
3736
5208
  LosslessNumber,
3737
5209
  isLosslessNumber,
3738
5210
  apiFlagOf,
@@ -3745,18 +5217,11 @@ export {
3745
5217
  parseApiJson,
3746
5218
  apiJson,
3747
5219
  apiPlainJson,
3748
- graphqlVariables,
3749
5220
  manifestBaseUrl,
3750
5221
  siteValue,
3751
5222
  signRequest,
3752
5223
  underBase,
3753
- parameterValue,
3754
5224
  nextPage,
3755
- DEFAULT_PACE,
3756
- pacePathFor,
3757
- Pacer,
3758
- waitForTurn,
3759
- providerCall,
3760
5225
  holdEnd,
3761
5226
  floodPathFor,
3762
5227
  FloodMemory,
@@ -3769,6 +5234,33 @@ export {
3769
5234
  sendGuard,
3770
5235
  guardFor,
3771
5236
  keyedGuard,
5237
+ generatedApiCommand,
5238
+ runSettings,
5239
+ commandRuns,
5240
+ commandRunId,
5241
+ providerEvent,
5242
+ providerRequest,
5243
+ recordRuns,
5244
+ unsendableBody,
5245
+ httpApiRequest,
5246
+ httpApiExecutor,
5247
+ answerOf2 as answerOf,
5248
+ terminalAsker,
5249
+ commandPathKey,
5250
+ commandPermissions,
5251
+ knownPermissionKeys,
5252
+ renamedPermissionKeys,
5253
+ knownBeside,
5254
+ unknownPermissionKeys,
5255
+ unknownPermissionIssues,
5256
+ refuseUnknownPermissionKeys,
5257
+ serviceApiOperations,
5258
+ serviceApiKeys,
5259
+ serviceApiPermissions,
5260
+ serviceApiCommand,
5261
+ serviceApiWriter,
5262
+ hostsFetch,
5263
+ serviceApiCall,
3772
5264
  CRM_ASSIGN_OTHERS_KEY,
3773
5265
  CRM_WRITE_KEYS,
3774
5266
  crmAlsoChecks,
@@ -3786,6 +5278,13 @@ export {
3786
5278
  RECORD_ID,
3787
5279
  createCrmRecord,
3788
5280
  updateCrmRecord,
5281
+ createCrmActivity,
5282
+ completeCrmActivity,
5283
+ DEFAULT_PACE,
5284
+ pacePathFor,
5285
+ Pacer,
5286
+ waitForTurn,
5287
+ providerCall,
3789
5288
  conditionsOf,
3790
5289
  customNames,
3791
5290
  filterableFields,