@wirecat/yandex-disk-cli 0.0.0-stage → 0.1.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 (235) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +204 -0
  3. package/README.md +243 -2
  4. package/contracts/wirecat.json +1554 -0
  5. package/dist/bin/ydisk.d.ts +3 -0
  6. package/dist/bin/ydisk.d.ts.map +1 -0
  7. package/dist/bin/ydisk.js +40 -0
  8. package/dist/bin/ydisk.js.map +1 -0
  9. package/dist/bundle/all-profiles-4OLZF3RT.js +279 -0
  10. package/dist/bundle/anthropic-DKB4OJXZ.js +91 -0
  11. package/dist/bundle/app-server-G4545SSV.js +247 -0
  12. package/dist/bundle/bun-RXEQKFED.js +169 -0
  13. package/dist/bundle/bun-sqlite-VHT5LN7U.js +76 -0
  14. package/dist/bundle/chunk-2BITUXGC.js +12289 -0
  15. package/dist/bundle/chunk-2CLWDQKA.js +39330 -0
  16. package/dist/bundle/chunk-2JFDOPKA.js +9575 -0
  17. package/dist/bundle/chunk-3GVI2MAO.js +106 -0
  18. package/dist/bundle/chunk-3SZBWBMI.js +131 -0
  19. package/dist/bundle/chunk-44VSEXW6.js +4054 -0
  20. package/dist/bundle/chunk-4YPRRQBE.js +95 -0
  21. package/dist/bundle/chunk-5COYRL5B.js +379 -0
  22. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  23. package/dist/bundle/chunk-5DM7DIZL.js +1402 -0
  24. package/dist/bundle/chunk-6R2DVTVZ.js +24 -0
  25. package/dist/bundle/chunk-762BS35H.js +2787 -0
  26. package/dist/bundle/chunk-AG64V7AB.js +1233 -0
  27. package/dist/bundle/chunk-BC5HGIXB.js +334 -0
  28. package/dist/bundle/chunk-BH7LFEX7.js +36 -0
  29. package/dist/bundle/chunk-BLNPGY7N.js +53 -0
  30. package/dist/bundle/chunk-CNIA2LJF.js +372 -0
  31. package/dist/bundle/chunk-COSXMDC7.js +230 -0
  32. package/dist/bundle/chunk-D72URWJE.js +532 -0
  33. package/dist/bundle/chunk-D7FO33KU.js +785 -0
  34. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  35. package/dist/bundle/chunk-DJH26PQ3.js +1396 -0
  36. package/dist/bundle/chunk-DJPT7IUC.js +64567 -0
  37. package/dist/bundle/chunk-DTMSCZDW.js +209 -0
  38. package/dist/bundle/chunk-E6LGZ5LX.js +16 -0
  39. package/dist/bundle/chunk-E6YRIHS5.js +92 -0
  40. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  41. package/dist/bundle/chunk-F3DDSZTF.js +78 -0
  42. package/dist/bundle/chunk-F4WWTQNL.js +188 -0
  43. package/dist/bundle/chunk-FDDAUASC.js +1028 -0
  44. package/dist/bundle/chunk-FMNPG6N2.js +170 -0
  45. package/dist/bundle/chunk-FOKJ4POB.js +274 -0
  46. package/dist/bundle/chunk-G22C7JG6.js +731 -0
  47. package/dist/bundle/chunk-GA442SYZ.js +161 -0
  48. package/dist/bundle/chunk-GEBSW7UK.js +6848 -0
  49. package/dist/bundle/chunk-GGRKWAOK.js +594 -0
  50. package/dist/bundle/chunk-HHINRNZA.js +788 -0
  51. package/dist/bundle/chunk-HUZCL33L.js +128 -0
  52. package/dist/bundle/chunk-IALSIQVT.js +142 -0
  53. package/dist/bundle/chunk-IOXR2QBX.js +398 -0
  54. package/dist/bundle/chunk-J5CXR6VX.js +63 -0
  55. package/dist/bundle/chunk-J5PWSTOX.js +82 -0
  56. package/dist/bundle/chunk-J7BVAEHR.js +364 -0
  57. package/dist/bundle/chunk-JH46HMZW.js +1334 -0
  58. package/dist/bundle/chunk-JOBO7F6W.js +52 -0
  59. package/dist/bundle/chunk-JXZ5B3L5.js +2333 -0
  60. package/dist/bundle/chunk-KBIAMDZN.js +66 -0
  61. package/dist/bundle/chunk-KFVDL2QS.js +146 -0
  62. package/dist/bundle/chunk-LNHTLSR5.js +288 -0
  63. package/dist/bundle/chunk-M24RAKMJ.js +58 -0
  64. package/dist/bundle/chunk-MDQ57Q3H.js +1197 -0
  65. package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
  66. package/dist/bundle/chunk-MLXQ4X5L.js +206 -0
  67. package/dist/bundle/chunk-NQAKARHE.js +54 -0
  68. package/dist/bundle/chunk-OF7VVUDQ.js +23 -0
  69. package/dist/bundle/chunk-OQVPE3XK.js +324 -0
  70. package/dist/bundle/chunk-OR3QG7UR.js +259 -0
  71. package/dist/bundle/chunk-OUUYVROP.js +76 -0
  72. package/dist/bundle/chunk-PQBAM64O.js +168 -0
  73. package/dist/bundle/chunk-PYVIA7WF.js +88 -0
  74. package/dist/bundle/chunk-Q6HK3PHE.js +72 -0
  75. package/dist/bundle/chunk-QB3KECV2.js +218 -0
  76. package/dist/bundle/chunk-QGWXSFYN.js +73 -0
  77. package/dist/bundle/chunk-RC5QAAAE.js +29 -0
  78. package/dist/bundle/chunk-RMJ26HLB.js +18 -0
  79. package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
  80. package/dist/bundle/chunk-T7ZUDA4C.js +72 -0
  81. package/dist/bundle/chunk-TRCSMVV5.js +72 -0
  82. package/dist/bundle/chunk-UD2BQEKA.js +46 -0
  83. package/dist/bundle/chunk-V4TL55GS.js +1068 -0
  84. package/dist/bundle/chunk-VJNWN5VU.js +4072 -0
  85. package/dist/bundle/chunk-VRRNBLMA.js +1227 -0
  86. package/dist/bundle/chunk-WUCMMNFJ.js +771 -0
  87. package/dist/bundle/chunk-XDESE3NY.js +44 -0
  88. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  89. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  90. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  91. package/dist/bundle/chunk-Z2QEON7B.js +2275 -0
  92. package/dist/bundle/chunk-ZMJ56GME.js +7 -0
  93. package/dist/bundle/chunk-ZTSB3D7Q.js +100 -0
  94. package/dist/bundle/chunk-ZVJWD3FK.js +38 -0
  95. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  96. package/dist/bundle/command-contract-YIOYGPJA.js +40 -0
  97. package/dist/bundle/command-server-entry-MHBQDXS4.js +169 -0
  98. package/dist/bundle/decode-NUGJIOUW.js +297 -0
  99. package/dist/bundle/definitions-AILHKEQT.js +2005 -0
  100. package/dist/bundle/dispatch-5LC4UEGY.js +411 -0
  101. package/dist/bundle/dist-4I2W6X2I.js +7577 -0
  102. package/dist/bundle/echarts-MHSH6PGC.js +42501 -0
  103. package/dist/bundle/embed-ZDXTHHYS.js +38 -0
  104. package/dist/bundle/embedder-XFEELFUL.js +111 -0
  105. package/dist/bundle/failure-5S7VPBYK.js +25 -0
  106. package/dist/bundle/first-run-JHCHT3RJ.js +29 -0
  107. package/dist/bundle/first-screen-FHGQ6QRV.js +40 -0
  108. package/dist/bundle/instructions-WKSMBUFX.js +11 -0
  109. package/dist/bundle/mcp-HS2ZDUVR.js +167 -0
  110. package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
  111. package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
  112. package/dist/bundle/meeting-combined-K4U4NYRZ.js +25 -0
  113. package/dist/bundle/meeting-model-KCEG6Y5O.js +26 -0
  114. package/dist/bundle/meeting-semantic-VYGSV3H6.js +22 -0
  115. package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
  116. package/dist/bundle/node-CM6NC6UE.js +176 -0
  117. package/dist/bundle/node-KM3CUABH.js +2340 -0
  118. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  119. package/dist/bundle/node-sqlite-5YDQ3LIJ.js +74 -0
  120. package/dist/bundle/notes-search-PGO7KM2U.js +62 -0
  121. package/dist/bundle/oauth-NY4C5UCK.js +20 -0
  122. package/dist/bundle/open-YNUTA6ZE.js +23 -0
  123. package/dist/bundle/openai-4CVT5PHH.js +241 -0
  124. package/dist/bundle/process-2XT3TL27.js +91 -0
  125. package/dist/bundle/program-FMIVF5T6.js +31904 -0
  126. package/dist/bundle/prompt-VNWY3H6S.js +17 -0
  127. package/dist/bundle/recognize-JS4PBPSZ.js +26 -0
  128. package/dist/bundle/remote-RCLFH4V2.js +32 -0
  129. package/dist/bundle/rerank-EG6VKYGO.js +52 -0
  130. package/dist/bundle/schemas-ED2LHKXK.js +645 -0
  131. package/dist/bundle/serve-AHG25QXB.js +199 -0
  132. package/dist/bundle/server-5FTB7WM3.js +78 -0
  133. package/dist/bundle/server-JNZVSAZE.js +209 -0
  134. package/dist/bundle/sqlite-runtime-XSZOAQPF.js +20 -0
  135. package/dist/bundle/state-XGVAJFF7.js +36 -0
  136. package/dist/bundle/store-OHSCWZEV.js +177 -0
  137. package/dist/bundle/store-PKSPKJXL.js +293 -0
  138. package/dist/bundle/store-maintenance-command-KAWGBSWK.js +69 -0
  139. package/dist/bundle/ydisk.js +183 -0
  140. package/dist/commands/api.d.ts +9 -0
  141. package/dist/commands/api.d.ts.map +1 -0
  142. package/dist/commands/api.js +59 -0
  143. package/dist/commands/api.js.map +1 -0
  144. package/dist/commands/comments.d.ts +3 -0
  145. package/dist/commands/comments.d.ts.map +1 -0
  146. package/dist/commands/comments.js +114 -0
  147. package/dist/commands/comments.js.map +1 -0
  148. package/dist/commands/files.d.ts +3 -0
  149. package/dist/commands/files.d.ts.map +1 -0
  150. package/dist/commands/files.js +272 -0
  151. package/dist/commands/files.js.map +1 -0
  152. package/dist/commands/library.d.ts +13 -0
  153. package/dist/commands/library.d.ts.map +1 -0
  154. package/dist/commands/library.js +118 -0
  155. package/dist/commands/library.js.map +1 -0
  156. package/dist/commands/session.d.ts +3 -0
  157. package/dist/commands/session.d.ts.map +1 -0
  158. package/dist/commands/session.js +99 -0
  159. package/dist/commands/session.js.map +1 -0
  160. package/dist/config.d.ts +18 -0
  161. package/dist/config.d.ts.map +1 -0
  162. package/dist/config.js +62 -0
  163. package/dist/config.js.map +1 -0
  164. package/dist/context.d.ts +80 -0
  165. package/dist/context.d.ts.map +1 -0
  166. package/dist/context.js +77 -0
  167. package/dist/context.js.map +1 -0
  168. package/dist/generated/definitions.d.ts +3 -0
  169. package/dist/generated/definitions.d.ts.map +1 -0
  170. package/dist/generated/definitions.js +2001 -0
  171. package/dist/generated/definitions.js.map +1 -0
  172. package/dist/generated/manifest.d.ts +6 -0
  173. package/dist/generated/manifest.d.ts.map +1 -0
  174. package/dist/generated/manifest.js +1473 -0
  175. package/dist/generated/manifest.js.map +1 -0
  176. package/dist/generated/schemas.d.ts +127 -0
  177. package/dist/generated/schemas.d.ts.map +1 -0
  178. package/dist/generated/schemas.js +545 -0
  179. package/dist/generated/schemas.js.map +1 -0
  180. package/dist/generated/types.d.ts +829 -0
  181. package/dist/generated/types.d.ts.map +1 -0
  182. package/dist/generated/types.js +5 -0
  183. package/dist/generated/types.js.map +1 -0
  184. package/dist/identity.d.ts +10 -0
  185. package/dist/identity.d.ts.map +1 -0
  186. package/dist/identity.js +33 -0
  187. package/dist/identity.js.map +1 -0
  188. package/dist/index.d.ts +3 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +3 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/program.d.ts +6 -0
  193. package/dist/program.d.ts.map +1 -0
  194. package/dist/program.js +65 -0
  195. package/dist/program.js.map +1 -0
  196. package/dist/sample/comments.d.ts +61 -0
  197. package/dist/sample/comments.d.ts.map +1 -0
  198. package/dist/sample/comments.js +39 -0
  199. package/dist/sample/comments.js.map +1 -0
  200. package/dist/sample/records.d.ts +16 -0
  201. package/dist/sample/records.d.ts.map +1 -0
  202. package/dist/sample/records.js +22 -0
  203. package/dist/sample/records.js.map +1 -0
  204. package/dist/sample/transport.d.ts +42 -0
  205. package/dist/sample/transport.d.ts.map +1 -0
  206. package/dist/sample/transport.js +153 -0
  207. package/dist/sample/transport.js.map +1 -0
  208. package/dist/version.d.ts +2 -0
  209. package/dist/version.d.ts.map +1 -0
  210. package/dist/version.js +2 -0
  211. package/dist/version.js.map +1 -0
  212. package/dist/wcat.d.ts +3 -0
  213. package/dist/wcat.d.ts.map +1 -0
  214. package/dist/wcat.js +4 -0
  215. package/dist/wcat.js.map +1 -0
  216. package/dist/yandex/source.d.ts +39 -0
  217. package/dist/yandex/source.d.ts.map +1 -0
  218. package/dist/yandex/source.js +189 -0
  219. package/dist/yandex/source.js.map +1 -0
  220. package/dist/yandex/transport.d.ts +41 -0
  221. package/dist/yandex/transport.d.ts.map +1 -0
  222. package/dist/yandex/transport.js +152 -0
  223. package/dist/yandex/transport.js.map +1 -0
  224. package/dist/yandex/writes.d.ts +27 -0
  225. package/dist/yandex/writes.d.ts.map +1 -0
  226. package/dist/yandex/writes.js +61 -0
  227. package/dist/yandex/writes.js.map +1 -0
  228. package/package.json +88 -4
  229. package/skills/yandex-disk-cli/SKILL.md +46 -0
  230. package/skills/yandex-disk-cli/references/api/api-disk-operations-operation-id.md +13 -0
  231. package/skills/yandex-disk-cli/references/api/api-disk-public-resources.md +50 -0
  232. package/skills/yandex-disk-cli/references/api/api-disk-resources.md +171 -0
  233. package/skills/yandex-disk-cli/references/api/api-disk-trash-resources.md +48 -0
  234. package/skills/yandex-disk-cli/references/api/api-disk.md +13 -0
  235. package/skills/yandex-disk-cli/references/api.md +17 -0
@@ -0,0 +1,1227 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ formatMeetingReference,
5
+ parseMeetingReference
6
+ } from "./chunk-VJNWN5VU.js";
7
+ import {
8
+ createRecordLog,
9
+ resolvePaths,
10
+ traceIdOf,
11
+ writeSecurely
12
+ } from "./chunk-762BS35H.js";
13
+ import {
14
+ CliError,
15
+ singleLine
16
+ } from "./chunk-T7ZUDA4C.js";
17
+ import {
18
+ __name
19
+ } from "./chunk-ZVVMGPBJ.js";
20
+
21
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/runs/scope.js
22
+ import { AsyncLocalStorage } from "node:async_hooks";
23
+ import { randomBytes } from "node:crypto";
24
+
25
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/runs/run.js
26
+ import { randomUUID } from "node:crypto";
27
+ import { appendFileSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
28
+ import { userInfo } from "node:os";
29
+ import { join, sep } from "node:path";
30
+
31
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/runs/log-keys.js
32
+ var snake = /* @__PURE__ */ __name((key) => key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), "snake");
33
+ var camel = /* @__PURE__ */ __name((key) => key.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase()), "camel");
34
+ var renamed = /* @__PURE__ */ __name((record, name) => Object.fromEntries(Object.entries(record).map(([key, value]) => [name(key), value])), "renamed");
35
+ var logAttributes = /* @__PURE__ */ __name((event) => renamed(event, snake), "logAttributes");
36
+ var fromLogAttributes = /* @__PURE__ */ __name((attributes) => renamed(attributes, camel), "fromLogAttributes");
37
+ var snakeLogger = /* @__PURE__ */ __name((logger) => ({
38
+ debug: /* @__PURE__ */ __name((event, message) => logger.debug(logAttributes(event), message), "debug"),
39
+ info: /* @__PURE__ */ __name((event, message) => logger.info(logAttributes(event), message), "info"),
40
+ warn: /* @__PURE__ */ __name((event, message) => logger.warn(logAttributes(event), message), "warn"),
41
+ error: /* @__PURE__ */ __name((event, message) => logger.error(logAttributes(event), message), "error")
42
+ }), "snakeLogger");
43
+
44
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/runs/log-attributes.js
45
+ var diagnostic = {
46
+ event: true,
47
+ operation: true,
48
+ opcode: true,
49
+ seq: true,
50
+ status: true,
51
+ method: true,
52
+ endpointTemplate: true,
53
+ bytes: true,
54
+ ids: true,
55
+ counts: true,
56
+ durationMs: true,
57
+ outcome: true,
58
+ errorCode: true,
59
+ providerError: true,
60
+ level: true,
61
+ transport: true,
62
+ attempt: true,
63
+ waitMs: true,
64
+ code: true,
65
+ detail: true,
66
+ reason: true,
67
+ ageMs: true,
68
+ kind: true,
69
+ table: true,
70
+ op: true,
71
+ n: true
72
+ };
73
+ var send = {
74
+ profile: true,
75
+ chatId: true,
76
+ outcome: true,
77
+ kind: true,
78
+ action: true,
79
+ people: true,
80
+ messageId: true,
81
+ key: true,
82
+ count: true,
83
+ forEveryone: true,
84
+ sendId: true,
85
+ operationId: true,
86
+ parentOperationId: true,
87
+ replyTo: true,
88
+ threadId: true,
89
+ sendAs: true,
90
+ resultChatId: true,
91
+ length: true,
92
+ attachments: true,
93
+ scheduledFor: true,
94
+ notify: true,
95
+ origin: true,
96
+ reservation: true,
97
+ errorCode: true
98
+ };
99
+ var background = [
100
+ "job",
101
+ "pid",
102
+ "schedule",
103
+ "exitCode",
104
+ "tool",
105
+ "tier",
106
+ "actorType",
107
+ "actorId",
108
+ "agent",
109
+ "targetType",
110
+ "targetId"
111
+ ];
112
+ var crash = ["errorClass", "frames"];
113
+ var dropped = ["dropped"];
114
+ var LOG_ATTRIBUTES = [
115
+ ...new Set([...Object.keys(diagnostic), ...Object.keys(send), ...background, ...crash, ...dropped].map((key) => Object.keys(logAttributes({ [key]: true }))[0]))
116
+ ].sort();
117
+
118
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/runs/run.js
119
+ var KEEP_RUNS_FOR_DAYS = 30;
120
+ var KEEP_SUCCESSFUL_RUNS_FOR_DAYS = 7;
121
+ var KEEP_STORE_RUNS_FOR_DAYS = 3;
122
+ var RUNS_SIZE_LIMIT_MB = 200;
123
+ var runsDirFor = /* @__PURE__ */ __name((app, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "runs"), "runsDirFor");
124
+ var startRun = /* @__PURE__ */ __name((options) => {
125
+ const now = options.now ?? (() => /* @__PURE__ */ new Date());
126
+ const startedAt = options.startedAt ?? now();
127
+ const id = options.runId ?? newRunId(startedAt, options.command);
128
+ const dir = join(options.runsDir, day(startedAt), id);
129
+ pruneRuns(options.runsDir, {
130
+ keepDays: options.keepDays ?? KEEP_RUNS_FOR_DAYS,
131
+ keepSuccessDays: options.keepSuccessDays ?? KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
132
+ keepStoreDays: options.keepStoreDays ?? KEEP_STORE_RUNS_FOR_DAYS,
133
+ maxBytes: options.maxBytes ?? RUNS_SIZE_LIMIT_MB * 1024 * 1024,
134
+ now: startedAt
135
+ });
136
+ refuseRealStateInTests(dir);
137
+ const metadata = {
138
+ runId: id,
139
+ command: options.command,
140
+ ...options.profile === void 0 ? {} : { profile: options.profile },
141
+ startedAt: startedAt.toISOString(),
142
+ status: "running",
143
+ cliVersion: options.cliVersion,
144
+ runtime: runtime(),
145
+ platform: process.platform,
146
+ arch: process.arch,
147
+ ...options.traceId === void 0 ? {} : { traceId: options.traceId },
148
+ ...options.context
149
+ };
150
+ let file;
151
+ const opened = /* @__PURE__ */ __name(() => {
152
+ if (file)
153
+ return file;
154
+ mkdirSync(dir, { recursive: true, mode: 448 });
155
+ const events = join(dir, "events.jsonl");
156
+ writeFileSync(events, "", { flag: "a", mode: 384 });
157
+ file = snakeLogger(createRecordLog({
158
+ to: events,
159
+ runId: id,
160
+ command: options.command,
161
+ resource: { service: options.service, version: options.cliVersion },
162
+ allow: LOG_ATTRIBUTES,
163
+ ...options.traceId === void 0 ? {} : { traceId: options.traceId },
164
+ ...options.onError === void 0 ? {} : { onError: options.onError }
165
+ }));
166
+ writeRunFile(dir, metadata);
167
+ return file;
168
+ }, "opened");
169
+ if (!options.lazy)
170
+ opened();
171
+ let finished = false;
172
+ const operations = /* @__PURE__ */ new Set();
173
+ const codes = /* @__PURE__ */ new Set();
174
+ const tables = /* @__PURE__ */ new Set();
175
+ const noted = /* @__PURE__ */ __name((level) => (event, message) => {
176
+ const { operation, errorCode, error_code, code, kind: kind2, table } = event;
177
+ if (typeof operation === "string")
178
+ operations.add(operation);
179
+ if (kind2 === "store" && typeof table === "string")
180
+ tables.add(table);
181
+ for (const value of [errorCode, error_code, code])
182
+ if (typeof value === "string")
183
+ codes.add(value);
184
+ if (finished)
185
+ return;
186
+ opened()[level](event, message);
187
+ }, "noted");
188
+ const logger = { debug: noted("debug"), info: noted("info"), warn: noted("warn"), error: noted("error") };
189
+ return {
190
+ id,
191
+ dir,
192
+ logger,
193
+ finish: /* @__PURE__ */ __name(async (status, extra = {}) => {
194
+ if (finished)
195
+ return;
196
+ finished = true;
197
+ const completedAt = now();
198
+ const final = {
199
+ ...metadata,
200
+ ...extra,
201
+ status,
202
+ completedAt: completedAt.toISOString(),
203
+ durationMs: completedAt.getTime() - startedAt.getTime(),
204
+ operations: [...operations].sort(),
205
+ codes: [...codes].sort(),
206
+ ...tables.size > 0 ? { tables: [...tables].sort() } : {}
207
+ };
208
+ if (file || status !== "success") {
209
+ opened();
210
+ writeRunFile(dir, final);
211
+ return;
212
+ }
213
+ try {
214
+ mkdirSync(join(dir, ".."), { recursive: true, mode: 448 });
215
+ appendIndex(join(dir, ".."), runFileOf(final));
216
+ } catch (error) {
217
+ options.onError?.(error);
218
+ }
219
+ }, "finish")
220
+ };
221
+ }, "startRun");
222
+ var refuseRealStateInTests = /* @__PURE__ */ __name((dir, env = process.env) => {
223
+ if (env.VITEST === void 0)
224
+ return;
225
+ let home;
226
+ try {
227
+ home = userInfo().homedir;
228
+ } catch {
229
+ return;
230
+ }
231
+ if (dir.startsWith(join(home, ".local", "share") + sep))
232
+ throw new Error(`a test opened a run in the real data folder: ${dir}`);
233
+ }, "refuseRealStateInTests");
234
+ var runtime = /* @__PURE__ */ __name(() => {
235
+ const bun = process.versions.bun;
236
+ return bun ? `bun ${bun}` : `node ${process.versions.node}`;
237
+ }, "runtime");
238
+ var newRunId = /* @__PURE__ */ __name((startedAt, command) => {
239
+ const stamp = startedAt.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
240
+ const slug = command.replace(/[^a-z0-9]+/gi, "-").toLowerCase();
241
+ return `${stamp}-${slug}-${randomUUID().slice(0, 6)}`;
242
+ }, "newRunId");
243
+ var INDEX = "index.jsonl";
244
+ var appendIndex = /* @__PURE__ */ __name((dayDir, written) => {
245
+ appendFileSync(join(dayDir, INDEX), `${JSON.stringify(written)}
246
+ `, { mode: 384 });
247
+ }, "appendIndex");
248
+ var writeRunFile = /* @__PURE__ */ __name((dir, metadata) => {
249
+ const written = runFileOf(metadata);
250
+ writeSecurely(join(dir, "run.json"), `${JSON.stringify(written, null, 2)}
251
+ `, 384);
252
+ try {
253
+ appendIndex(join(dir, ".."), written);
254
+ } catch {
255
+ }
256
+ }, "writeRunFile");
257
+ var matchesListFilter = /* @__PURE__ */ __name((run, filter) => (filter.runId === void 0 || run.runId === filter.runId) && (filter.command === void 0 || run.command === filter.command) && (filter.profile === void 0 || run.profile === filter.profile) && (filter.status === void 0 || run.status === filter.status) && (filter.errorCode === void 0 || run.errorCode === filter.errorCode), "matchesListFilter");
258
+ var listRuns = /* @__PURE__ */ __name((runsDir, { since, atLeast = Number.POSITIVE_INFINITY, filter = {} } = {}) => {
259
+ const first = since === void 0 ? void 0 : day(new Date(since));
260
+ const runs = [];
261
+ for (const date of days(runsDir).sort().reverse()) {
262
+ if (first !== void 0 && date < first || runs.length >= atLeast)
263
+ break;
264
+ for (const metadata of runsOfDay(join(runsDir, date))) {
265
+ if (matchesListFilter(metadata, filter))
266
+ runs.push(metadata);
267
+ }
268
+ }
269
+ return runs;
270
+ }, "listRuns");
271
+ var indexedRuns = /* @__PURE__ */ __name((dayDir) => {
272
+ const latest = /* @__PURE__ */ new Map();
273
+ let raw = "";
274
+ try {
275
+ raw = readFileSync(join(dayDir, INDEX), "utf8");
276
+ } catch {
277
+ }
278
+ for (const line of raw.split("\n")) {
279
+ if (line.trim() === "")
280
+ continue;
281
+ try {
282
+ const metadata = metadataOf(JSON.parse(line));
283
+ if (typeof metadata.runId === "string")
284
+ latest.set(metadata.runId, metadata);
285
+ } catch {
286
+ }
287
+ }
288
+ return latest;
289
+ }, "indexedRuns");
290
+ var runsOfDay = /* @__PURE__ */ __name((dayDir) => {
291
+ const latest = indexedRuns(dayDir);
292
+ for (const entry of safeReaddir(dayDir)) {
293
+ if (entry === INDEX || entry.startsWith(".") || latest.has(entry))
294
+ continue;
295
+ const metadata = readRun(join(dayDir, entry));
296
+ if (metadata)
297
+ latest.set(metadata.runId, metadata);
298
+ }
299
+ return [...latest.values()].sort((a, b) => a.runId < b.runId ? 1 : a.runId > b.runId ? -1 : 0);
300
+ }, "runsOfDay");
301
+ var findRun = /* @__PURE__ */ __name((runsDir, id) => {
302
+ const stamped = /^(\d{4})(\d{2})(\d{2})T/.exec(id);
303
+ const likely = stamped ? [`${stamped[1]}-${stamped[2]}-${stamped[3]}`] : [];
304
+ const dates = [.../* @__PURE__ */ new Set([...likely, ...days(runsDir)])];
305
+ for (const date of dates) {
306
+ const dir = join(runsDir, date, id);
307
+ const metadata = readRun(dir);
308
+ if (metadata)
309
+ return { dir, metadata };
310
+ }
311
+ for (const date of dates) {
312
+ const metadata = indexedRuns(join(runsDir, date)).get(id);
313
+ if (metadata)
314
+ return { dir: join(runsDir, date, id), metadata };
315
+ }
316
+ return void 0;
317
+ }, "findRun");
318
+ var readEvents = /* @__PURE__ */ __name((dir) => {
319
+ let raw;
320
+ try {
321
+ raw = readFileSync(join(dir, "events.jsonl"), "utf8");
322
+ } catch {
323
+ return [];
324
+ }
325
+ const events = [];
326
+ for (const line of raw.split("\n")) {
327
+ if (line.trim() === "")
328
+ continue;
329
+ try {
330
+ const parsed = JSON.parse(line);
331
+ if (parsed !== null && typeof parsed === "object")
332
+ events.push(eventOf(parsed));
333
+ } catch {
334
+ }
335
+ }
336
+ return events;
337
+ }, "readEvents");
338
+ var eventOf = /* @__PURE__ */ __name((line) => {
339
+ const { attributes, time, severity } = line;
340
+ if (attributes === null || typeof attributes !== "object")
341
+ return logAttributes(line);
342
+ return { time, severity, ...logAttributes(attributes) };
343
+ }, "eventOf");
344
+ var pruneRuns = /* @__PURE__ */ __name((runsDir, { keepDays, keepSuccessDays = keepDays, keepStoreDays = KEEP_STORE_RUNS_FOR_DAYS, maxBytes, now }) => {
345
+ const cutoff = day(new Date(now.getTime() - keepDays * DAY_MS));
346
+ const before = /* @__PURE__ */ __name((days2) => day(new Date(now.getTime() - Math.min(days2, keepDays) * DAY_MS)), "before");
347
+ const successCutoff = before(keepSuccessDays);
348
+ const storeCutoff = before(keepStoreDays);
349
+ const keptFor = /* @__PURE__ */ __name((metadata) => metadata.keptBecauseStore ? keepStoreDays : metadata.operations?.includes(STORE_WRITE) ? Math.max(keepSuccessDays, keepStoreDays) : keepSuccessDays, "keptFor");
350
+ let removed = 0;
351
+ for (const date of days(runsDir)) {
352
+ if (date >= cutoff) {
353
+ if (date < storeCutoff)
354
+ dropSuccesses(join(runsDir, date), STORE_RUNS_DROPPED, (metadata) => keptFor(metadata) <= keepStoreDays);
355
+ if (date < successCutoff)
356
+ dropSuccesses(join(runsDir, date), SUCCESSES_DROPPED, (metadata) => keptFor(metadata) <= keepSuccessDays);
357
+ continue;
358
+ }
359
+ try {
360
+ rmSync(join(runsDir, date), { recursive: true, force: true });
361
+ removed += 1;
362
+ } catch {
363
+ }
364
+ }
365
+ if (maxBytes !== void 0)
366
+ removed += fitSize(runsDir, maxBytes, now);
367
+ return removed;
368
+ }, "pruneRuns");
369
+ var DAY_MS = 24 * 60 * 60 * 1e3;
370
+ var STORE_WRITE = "store.write";
371
+ var SUCCESSES_DROPPED = ".successes-dropped";
372
+ var STORE_RUNS_DROPPED = ".store-runs-dropped";
373
+ var SIZE_CHECKED = ".size-checked";
374
+ var dropSuccesses = /* @__PURE__ */ __name((dayDir, marker = SUCCESSES_DROPPED, drops = () => true) => {
375
+ const done = join(dayDir, marker);
376
+ try {
377
+ statSync(done);
378
+ return;
379
+ } catch {
380
+ }
381
+ const dropped2 = /* @__PURE__ */ __name((metadata) => metadata?.status === "success" && drops(metadata), "dropped");
382
+ try {
383
+ const kept = [];
384
+ for (const [id, metadata] of indexedRuns(dayDir)) {
385
+ if (dropped2(metadata))
386
+ rmSync(join(dayDir, id), { recursive: true, force: true });
387
+ else
388
+ kept.push(JSON.stringify(runFileOf(metadata)));
389
+ }
390
+ for (const entry of safeReaddir(dayDir)) {
391
+ if (entry === INDEX || entry.startsWith("."))
392
+ continue;
393
+ if (dropped2(readRun(join(dayDir, entry))))
394
+ rmSync(join(dayDir, entry), { recursive: true, force: true });
395
+ }
396
+ writeSecurely(join(dayDir, INDEX), kept.map((line) => `${line}
397
+ `).join(""), 384);
398
+ writeFileSync(done, "", { mode: 384 });
399
+ } catch {
400
+ }
401
+ }, "dropSuccesses");
402
+ var sizeOf = /* @__PURE__ */ __name((path) => {
403
+ let total = 0;
404
+ for (const entry of safeReaddir(path)) {
405
+ const full = join(path, entry);
406
+ try {
407
+ const stat = statSync(full);
408
+ total += stat.isDirectory() ? sizeOf(full) : stat.size;
409
+ } catch {
410
+ }
411
+ }
412
+ return total;
413
+ }, "sizeOf");
414
+ var fitSize = /* @__PURE__ */ __name((runsDir, maxBytes, now) => {
415
+ const stamp = join(runsDir, SIZE_CHECKED);
416
+ const today = day(now);
417
+ try {
418
+ if (readFileSync(stamp, "utf8").trim() === today)
419
+ return 0;
420
+ } catch {
421
+ }
422
+ const dates = days(runsDir).sort();
423
+ const sizes = new Map(dates.map((date) => [date, sizeOf(join(runsDir, date))]));
424
+ let total = [...sizes.values()].reduce((sum, size) => sum + size, 0);
425
+ let removed = 0;
426
+ for (const date of dates) {
427
+ if (total <= maxBytes || date === today)
428
+ break;
429
+ dropSuccesses(join(runsDir, date));
430
+ const after = sizeOf(join(runsDir, date));
431
+ total -= (sizes.get(date) ?? 0) - after;
432
+ sizes.set(date, after);
433
+ }
434
+ for (const date of dates) {
435
+ if (total <= maxBytes || date === today)
436
+ break;
437
+ try {
438
+ rmSync(join(runsDir, date), { recursive: true, force: true });
439
+ total -= sizes.get(date) ?? 0;
440
+ removed += 1;
441
+ } catch {
442
+ }
443
+ }
444
+ try {
445
+ mkdirSync(runsDir, { recursive: true, mode: 448 });
446
+ writeFileSync(stamp, today, { mode: 384 });
447
+ } catch {
448
+ }
449
+ return removed;
450
+ }, "fitSize");
451
+ var day = /* @__PURE__ */ __name((date) => date.toISOString().slice(0, 10), "day");
452
+ var days = /* @__PURE__ */ __name((runsDir) => safeReaddir(runsDir).filter((entry) => /^\d{4}-\d{2}-\d{2}$/.test(entry)), "days");
453
+ var readRun = /* @__PURE__ */ __name((dir) => {
454
+ try {
455
+ return metadataOf(JSON.parse(readFileSync(join(dir, "run.json"), "utf8")));
456
+ } catch {
457
+ return void 0;
458
+ }
459
+ }, "readRun");
460
+ var safeReaddir = /* @__PURE__ */ __name((dir) => {
461
+ try {
462
+ return readdirSync(dir);
463
+ } catch {
464
+ return [];
465
+ }
466
+ }, "safeReaddir");
467
+ var runFileOf = /* @__PURE__ */ __name(({ partial, ...metadata }) => ({
468
+ ...logAttributes(metadata),
469
+ ...partial ? { partial: { ...logAttributes(partial), failures: partial.failures.map((failure) => logAttributes(failure)) } } : {}
470
+ }), "runFileOf");
471
+ var metadataOf = /* @__PURE__ */ __name((parsed) => {
472
+ const { partial, ...metadata } = fromLogAttributes(parsed);
473
+ if (partial === null || typeof partial !== "object")
474
+ return metadata;
475
+ const { failures, ...rest } = fromLogAttributes(partial);
476
+ return {
477
+ ...metadata,
478
+ partial: {
479
+ ...rest,
480
+ failures: Array.isArray(failures) ? failures.map((failure) => fromLogAttributes(failure)) : []
481
+ }
482
+ };
483
+ }, "metadataOf");
484
+
485
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/runs/scope.js
486
+ var scopes = new AsyncLocalStorage();
487
+ var processScope;
488
+ var ownProcesses = new AsyncLocalStorage();
489
+ var asOwnProcess = /* @__PURE__ */ __name((body) => ownProcesses.run({}, body), "asOwnProcess");
490
+ var currentRun = /* @__PURE__ */ __name(() => {
491
+ const scope = scopes.getStore();
492
+ if (scope)
493
+ return scope;
494
+ const own = ownProcesses.getStore();
495
+ const fresh = /* @__PURE__ */ __name(() => ({
496
+ runId: newRunId(/* @__PURE__ */ new Date(), "process"),
497
+ command: "",
498
+ startedAt: Date.now(),
499
+ ...traceOf(process.env)
500
+ }), "fresh");
501
+ if (own) {
502
+ own.scope ??= fresh();
503
+ return own.scope;
504
+ }
505
+ processScope ??= fresh();
506
+ return processScope;
507
+ }, "currentRun");
508
+ var inRun = /* @__PURE__ */ __name((scope, body) => scopes.run(scope, body), "inRun");
509
+ var runEvent = /* @__PURE__ */ __name((event) => scopes.getStore()?.events?.(event), "runEvent");
510
+ var typedCommand = /* @__PURE__ */ __name((tool, words, profile = currentRun().profile) => [tool, profile, words].filter((part) => part !== void 0 && part !== "").join(" "), "typedCommand");
511
+ var useAsProcessRun = /* @__PURE__ */ __name((scope) => {
512
+ const own = ownProcesses.getStore();
513
+ if (own)
514
+ own.scope = scope;
515
+ else
516
+ processScope = scope;
517
+ }, "useAsProcessRun");
518
+ var processRun = /* @__PURE__ */ __name(() => {
519
+ const own = ownProcesses.getStore();
520
+ return own ? own.scope : processScope;
521
+ }, "processRun");
522
+ var enclosingTraceId = /* @__PURE__ */ __name(() => scopes.getStore()?.traceId, "enclosingTraceId");
523
+ var traceOf = /* @__PURE__ */ __name((env) => {
524
+ const traceId = traceIdOf(env.TRACEPARENT);
525
+ return traceId === void 0 ? {} : { traceId };
526
+ }, "traceOf");
527
+ var childTrace = /* @__PURE__ */ __name(() => {
528
+ const hex = /* @__PURE__ */ __name((bytes) => randomBytes(bytes).toString("hex"), "hex");
529
+ const traceId = hex(16);
530
+ return { traceId, traceparent: `00-${traceId}-${hex(8)}-01` };
531
+ }, "childTrace");
532
+ var attempts = new AsyncLocalStorage();
533
+ var withAttempt = /* @__PURE__ */ __name((attempt, work) => attempts.run(attempt, work), "withAttempt");
534
+ var currentAttempt = /* @__PURE__ */ __name(() => attempts.getStore(), "currentAttempt");
535
+
536
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/domain/locator.js
537
+ var SCHEME = "msg:";
538
+ var formatLocator = /* @__PURE__ */ __name(({ provider, account, chat, message }) => SCHEME + [provider, account, chat, message].map(encodeURIComponent).join("/"), "formatLocator");
539
+ var isLocator = /* @__PURE__ */ __name((reference) => reference.trim().startsWith(SCHEME), "isLocator");
540
+ var parseLocator = /* @__PURE__ */ __name((reference) => {
541
+ const trimmed = reference.trim();
542
+ const parts2 = trimmed.startsWith(SCHEME) ? trimmed.slice(SCHEME.length).split("/") : [];
543
+ const malformed2 = /* @__PURE__ */ __name(() => new CliError("validation_error", `"${singleLine(reference)}" is not a message locator \u2014 expected msg:<provider>/<account>/<chat>/<message>`), "malformed");
544
+ if (parts2.length !== 4 || parts2.some((part) => part === ""))
545
+ throw malformed2();
546
+ const decoded2 = /* @__PURE__ */ __name((part) => {
547
+ try {
548
+ return decodeURIComponent(part);
549
+ } catch {
550
+ throw malformed2();
551
+ }
552
+ }, "decoded");
553
+ const [provider, account, chat, message] = parts2.map(decoded2);
554
+ return { provider, account, chat, message };
555
+ }, "parseLocator");
556
+
557
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/domain/references.js
558
+ var SIMPLE_REFERENCES = [
559
+ "note",
560
+ "document",
561
+ "person",
562
+ "organization",
563
+ "project",
564
+ "task",
565
+ "memory",
566
+ "fact",
567
+ "bot",
568
+ "event",
569
+ "invoice",
570
+ "payment",
571
+ "order",
572
+ "deal",
573
+ "lead",
574
+ "pipeline",
575
+ "product",
576
+ "contract",
577
+ "subscription",
578
+ "wallet",
579
+ "transaction",
580
+ "entity"
581
+ ];
582
+ var malformed = /* @__PURE__ */ __name((text, shape) => new CliError("validation_error", `"${singleLine(text)}" is not a reference \u2014 expected ${shape}`, {
583
+ reason: "ref.malformed"
584
+ }), "malformed");
585
+ var decoded = /* @__PURE__ */ __name((part, text, shape) => {
586
+ try {
587
+ return decodeURIComponent(part);
588
+ } catch {
589
+ throw malformed(text, shape);
590
+ }
591
+ }, "decoded");
592
+ var parts = /* @__PURE__ */ __name((rest, count, text, shape) => {
593
+ const split = rest.split("/");
594
+ if (split.length !== count || split.some((part) => part === ""))
595
+ throw malformed(text, shape);
596
+ return split.map((part) => decoded(part, text, shape));
597
+ }, "parts");
598
+ var encoded = /* @__PURE__ */ __name((...values) => values.map(encodeURIComponent).join("/"), "encoded");
599
+ var folderPath = /* @__PURE__ */ __name((path) => {
600
+ const clean = path.split("/").filter((part) => part !== "" && part !== ".").join("/");
601
+ return clean === "" ? path.trim() === "" ? "" : null : clean;
602
+ }, "folderPath");
603
+ var MEETING_SHAPE = "meeting:<account>/<meeting>[/<transcript>[/<cue>]] with safe integer ids";
604
+ var kind = /* @__PURE__ */ __name((spec) => spec, "kind");
605
+ var simple = /* @__PURE__ */ __name((prefix) => kind({
606
+ prefix,
607
+ type: prefix,
608
+ shape: `${prefix}:<id>`,
609
+ parse: /* @__PURE__ */ __name((rest, text) => {
610
+ if (!rest.trim())
611
+ throw new CliError("validation_error", `"${singleLine(text)}" names no ${prefix}`, {
612
+ reason: "ref.malformed"
613
+ });
614
+ return { type: prefix, id: rest };
615
+ }, "parse"),
616
+ format: /* @__PURE__ */ __name((reference) => `${reference.type}:${reference.id}`, "format")
617
+ }), "simple");
618
+ var REF_KINDS = [
619
+ kind({
620
+ prefix: "msg",
621
+ type: "message",
622
+ shape: "msg:<provider>/<account>/<chat>/<message>",
623
+ parse: /* @__PURE__ */ __name((_, text) => {
624
+ try {
625
+ return { type: "message", ...parseLocator(text) };
626
+ } catch {
627
+ throw malformed(text, "msg:<provider>/<account>/<chat>/<message>");
628
+ }
629
+ }, "parse"),
630
+ format: formatLocator
631
+ }),
632
+ kind({
633
+ prefix: "chat",
634
+ type: "chat",
635
+ shape: "chat:<provider>/<account>/<chat>",
636
+ parse: /* @__PURE__ */ __name((rest, text) => {
637
+ const [provider, account, chat] = parts(rest, 3, text, "chat:<provider>/<account>/<chat>");
638
+ return { type: "chat", provider, account, chat };
639
+ }, "parse"),
640
+ format: /* @__PURE__ */ __name(({ provider, account, chat }) => `chat:${encoded(provider, account, chat)}`, "format")
641
+ }),
642
+ kind({
643
+ prefix: "contact",
644
+ type: "contact",
645
+ shape: "contact:<provider>/<id>",
646
+ parse: /* @__PURE__ */ __name((rest, text) => {
647
+ const [provider, id] = parts(rest, 2, text, "contact:<provider>/<id>");
648
+ return { type: "contact", provider, id };
649
+ }, "parse"),
650
+ format: /* @__PURE__ */ __name(({ provider, id }) => `contact:${encoded(provider, id)}`, "format")
651
+ }),
652
+ kind({
653
+ prefix: "folder",
654
+ type: "folder",
655
+ shape: "folder:<id>[/<path>]",
656
+ parse: /* @__PURE__ */ __name((rest, text) => {
657
+ const slash = rest.indexOf("/");
658
+ const id = decoded(slash < 0 ? rest : rest.slice(0, slash), text, "folder:<id>[/<path>]");
659
+ const path = slash < 0 ? null : folderPath(decoded(rest.slice(slash + 1), text, "folder:<id>[/<path>]"));
660
+ if (!id.trim() || path === "")
661
+ throw malformed(text, "folder:<id>[/<path>]");
662
+ return { type: "folder", id, path };
663
+ }, "parse"),
664
+ format: /* @__PURE__ */ __name(({ id, path }) => path === null ? `folder:${encodeURIComponent(id)}` : `folder:${encoded(id, path)}`, "format")
665
+ }),
666
+ kind({
667
+ prefix: "meeting",
668
+ type: "meeting",
669
+ shape: MEETING_SHAPE,
670
+ parse: /* @__PURE__ */ __name((_, text) => {
671
+ try {
672
+ return parseMeetingReference(text);
673
+ } catch {
674
+ throw malformed(text, MEETING_SHAPE);
675
+ }
676
+ }, "parse"),
677
+ format: formatMeetingReference
678
+ }),
679
+ ...SIMPLE_REFERENCES.map(simple)
680
+ ];
681
+ var byPrefix = new Map(REF_KINDS.map((spec) => [spec.prefix, spec]));
682
+ var byType = new Map(REF_KINDS.map((spec) => [spec.type, spec]));
683
+ var offered = REF_KINDS.map(({ prefix }) => prefix).filter((prefix) => prefix !== "entity");
684
+ var distance = /* @__PURE__ */ __name((a, b) => {
685
+ let row = Array.from({ length: b.length + 1 }, (_, at) => at);
686
+ for (const [i, x] of [...a].entries()) {
687
+ const next = [i + 1];
688
+ for (const [j, y] of [...b].entries())
689
+ next.push(Math.min(row[j + 1] + 1, next[j] + 1, row[j] + (x === y ? 0 : 1)));
690
+ row = next;
691
+ }
692
+ return row[b.length];
693
+ }, "distance");
694
+ var nearest = /* @__PURE__ */ __name((typed) => offered.find((prefix) => typed.length >= 2 && prefix.startsWith(typed)) ?? offered.map((prefix) => ({ prefix, far: distance(typed, prefix) })).filter(({ far }) => far <= 2).sort((a, b) => a.far - b.far)[0]?.prefix, "nearest");
695
+ var unknownKind = /* @__PURE__ */ __name((text, prefix, rest) => {
696
+ const near = prefix === "" ? void 0 : nearest(prefix);
697
+ const kinds = offered.map((one) => `${one}:`).join(", ");
698
+ const hint = near === void 0 ? `; kinds: ${kinds}` : `; did you mean ${near}:${singleLine(rest)}? Kinds: ${kinds}`;
699
+ return new CliError("validation_error", `"${singleLine(text)}" is no kind of reference${hint}`, {
700
+ reason: "ref.unknown-kind"
701
+ });
702
+ }, "unknownKind");
703
+ var formatReference = /* @__PURE__ */ __name((reference) => byType.get(reference.type).format(reference), "formatReference");
704
+ var parseReference = /* @__PURE__ */ __name((text) => {
705
+ const reference = text.trim();
706
+ const colon = reference.indexOf(":");
707
+ const prefix = colon < 0 ? "" : reference.slice(0, colon);
708
+ const rest = reference.slice(colon + 1);
709
+ const spec = byPrefix.get(prefix);
710
+ if (!spec)
711
+ throw unknownKind(reference, prefix, rest);
712
+ return spec.parse(rest, reference);
713
+ }, "parseReference");
714
+ var canonicalReference = /* @__PURE__ */ __name((text) => formatReference(parseReference(text)), "canonicalReference");
715
+ var looksLikeReference = /* @__PURE__ */ __name((text) => {
716
+ const match = /^([a-z]+):\S+$/.exec(text.trim());
717
+ return match !== null && byPrefix.has(match[1]);
718
+ }, "looksLikeReference");
719
+
720
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/domain/providers.js
721
+ var KINDS = ["messages", "mail", "notes", "documents", "meetings", "events", "crm"];
722
+ var MESSENGER_OPENS = { chat: "messages list", message: "messages show", contact: "contacts show" };
723
+ var PROVIDERS = [
724
+ { name: "telegram", kind: "messages", aliases: ["tg"], command: "tg", opens: MESSENGER_OPENS },
725
+ { name: "telegram-bot", kind: "messages", aliases: ["tg-bot"] },
726
+ { name: "max", kind: "messages", aliases: [], command: "max", opens: MESSENGER_OPENS },
727
+ { name: "max-bot", kind: "messages", aliases: [] },
728
+ { name: "whatsapp", kind: "messages", aliases: ["wa"], command: "wa", opens: MESSENGER_OPENS },
729
+ { name: "whatsapp-bot", kind: "messages", aliases: ["wa-bot"] },
730
+ { name: "email", kind: "mail", aliases: [] },
731
+ { name: "notes", kind: "notes", aliases: [] },
732
+ { name: "local", kind: "notes", aliases: [] },
733
+ { name: "obsidian", kind: "notes", aliases: [] },
734
+ { name: "added", kind: "notes", aliases: [] },
735
+ { name: "zoom", kind: "meetings", aliases: [] },
736
+ // Google Meet has no tool of its own: its meetings are gcal's, since every meeting is on the calendar.
737
+ { name: "google-meet", kind: "meetings", aliases: [], command: "gcal" },
738
+ { name: "google-drive", kind: "documents", aliases: [] },
739
+ // Its meetings come from the notes Telemost mails (`keeper@telemost.yandex.ru`), read by a mail rule.
740
+ { name: "telemost", kind: "meetings", aliases: [] },
741
+ // A phone export's records: its SMS and its calls in the one account the import names.
742
+ { name: "phone", kind: "messages", kinds: ["messages", "events"], aliases: [], imported: true },
743
+ // Any other import: a folder of notes, a CRM's export, a script's records, under `import:<what it is>`.
744
+ { name: "import", kind: "documents", kinds: ["documents", "messages", "events"], aliases: [], imported: true }
745
+ ];
746
+ var LABELS = {
747
+ telegram: "Telegram",
748
+ "telegram-bot": "Telegram bot",
749
+ max: "MAX",
750
+ "max-bot": "MAX bot",
751
+ whatsapp: "WhatsApp",
752
+ "whatsapp-bot": "WhatsApp bot",
753
+ "google-drive": "Google Drive",
754
+ "google-meet": "Google Meet",
755
+ added: "added by hand",
756
+ email: "mail",
757
+ telemost: "Telemost"
758
+ };
759
+ var providerLabel = /* @__PURE__ */ __name((provider) => LABELS[provider] ?? provider, "providerLabel");
760
+ var FOLDER_PROVIDERS = ["local", "obsidian", "folder"];
761
+ var isFolderProvider = /* @__PURE__ */ __name((provider) => FOLDER_PROVIDERS.includes(provider), "isFolderProvider");
762
+ var folderProviderSql = /* @__PURE__ */ __name((column = "provider") => `${column} IN (${FOLDER_PROVIDERS.map((name) => `'${name}'`).join(", ")})`, "folderProviderSql");
763
+ var folderProviderOf = /* @__PURE__ */ __name((format) => format === "markdown" ? "local" : "obsidian", "folderProviderOf");
764
+ var documentAccountProviders = /* @__PURE__ */ __name(() => registry.filter((entry) => entry.kind === "documents" && entry.imported !== true).map(({ name }) => name), "documentAccountProviders");
765
+ var isDocumentAccountProvider = /* @__PURE__ */ __name((provider) => typeof provider === "string" && documentAccountProviders().includes(provider), "isDocumentAccountProvider");
766
+ var documentAccountProvidersSql = /* @__PURE__ */ __name(() => documentAccountProviders().map((name) => `'${name}'`).join(", ") || "NULL", "documentAccountProvidersSql");
767
+ var ADDED_PROVIDER = "added";
768
+ var ADDED_ACCOUNT = "owner";
769
+ var notAdded = `d.account_id NOT IN (SELECT id FROM accounts WHERE provider = '${ADDED_PROVIDER}')`;
770
+ var filesAccountSql = /* @__PURE__ */ __name((column = "provider") => `${column} IN (${[...FOLDER_PROVIDERS, ...documentAccountProviders(), ADDED_PROVIDER].map((name) => `'${name}'`).join(", ")})`, "filesAccountSql");
771
+ var INTERNAL_NOTES = "internal";
772
+ var UNKNOWN_PROVIDER = "unknown provider \u2014 run its CLI once";
773
+ var WORD = /^[a-z0-9][a-z0-9_-]*$/;
774
+ var invalid = /* @__PURE__ */ __name((message) => {
775
+ throw new CliError("validation_error", message);
776
+ }, "invalid");
777
+ var wordOf = /* @__PURE__ */ __name((value, what) => typeof value === "string" && WORD.test(value) ? value : invalid(`${what} is lowercase letters, digits, - and _ \u2014 not ${JSON.stringify(value)}`), "wordOf");
778
+ var OPEN_KINDS = new Set(REF_KINDS.map(({ type }) => type).filter((type) => type !== "entity"));
779
+ var COMMAND_WORDS = /^[a-z0-9][a-z0-9_-]*( [a-z0-9][a-z0-9_-]*)*$/;
780
+ var opensOf = /* @__PURE__ */ __name((value, named) => {
781
+ if (typeof value !== "object" || value === null || Array.isArray(value))
782
+ return invalid(`provider ${named}'s opens maps a kind of reference to a command`);
783
+ const known = Object.entries(value).filter(([kind2]) => OPEN_KINDS.has(kind2));
784
+ for (const [kind2, command] of known)
785
+ if (typeof command !== "string" || !COMMAND_WORDS.test(command))
786
+ invalid(`provider ${named} opens a ${kind2} with command words, not ${JSON.stringify(command)}`);
787
+ return Object.fromEntries(known);
788
+ }, "opensOf");
789
+ var providerEntryOf = /* @__PURE__ */ __name((value) => {
790
+ if (typeof value !== "object" || value === null || Array.isArray(value))
791
+ return invalid("a provider entry is an object");
792
+ const { name, kind: kind2, kinds, aliases = [], command, opens, imported } = value;
793
+ const named = wordOf(name, "a provider's name");
794
+ const isKindWord = /* @__PURE__ */ __name((one) => typeof one === "string" && KINDS.includes(one), "isKindWord");
795
+ const given = kinds === void 0 ? [kind2] : Array.isArray(kinds) && kinds.length > 0 ? kinds : [void 0];
796
+ for (const one of given)
797
+ if (!isKindWord(one))
798
+ invalid(`provider ${named}'s kind is one of ${KINDS.join(", ")} \u2014 not ${JSON.stringify(one)}`);
799
+ const list = [...new Set(given)];
800
+ if (kind2 !== void 0 && kind2 !== list[0])
801
+ invalid(`provider ${named}'s kind is the first of its kinds`);
802
+ if (!Array.isArray(aliases))
803
+ invalid(`provider ${named}'s aliases are a list`);
804
+ if (imported !== void 0 && typeof imported !== "boolean")
805
+ invalid(`provider ${named}'s imported is true or false`);
806
+ return {
807
+ name: named,
808
+ kind: list[0],
809
+ ...list.length > 1 ? { kinds: list } : {},
810
+ ...imported === true ? { imported: true } : {},
811
+ aliases: [...new Set(aliases.map((alias) => wordOf(alias, `an alias of ${named}`)))],
812
+ ...command === void 0 ? {} : { command: wordOf(command, `the command of ${named}`) },
813
+ ...opens === void 0 ? {} : { opens: opensOf(opens, named) }
814
+ };
815
+ }, "providerEntryOf");
816
+ var kindsOfEntry = /* @__PURE__ */ __name((entry) => entry.kinds ?? [entry.kind], "kindsOfEntry");
817
+ var describe = /* @__PURE__ */ __name((entry) => `${entry.name} (${kindsOfEntry(entry).join(", ")}${entry.command ? `, from ${entry.command}` : ""})`, "describe");
818
+ var unitedKinds = /* @__PURE__ */ __name((known, entry) => [
819
+ .../* @__PURE__ */ new Set([...known, ...entry])
820
+ ], "unitedKinds");
821
+ var wordsOf = /* @__PURE__ */ __name(({ name, aliases }) => [name, ...aliases], "wordsOf");
822
+ var joined = /* @__PURE__ */ __name((known, entry) => {
823
+ const same = known.find(({ name }) => name === entry.name);
824
+ const kinds = same ? unitedKinds(kindsOfEntry(same), kindsOfEntry(entry)) : kindsOfEntry(entry);
825
+ if (same && same.kind !== entry.kind)
826
+ invalid(`two provider entries disagree on the kind: ${describe(same)} and ${describe(entry)}`);
827
+ if (same && entry.imported === true && same.imported !== true)
828
+ invalid(`provider ${entry.name} is synced, so an entry cannot make it import-only`);
829
+ const merged = same ? {
830
+ ...same,
831
+ ...kinds.length > 1 ? { kinds } : {},
832
+ aliases: [.../* @__PURE__ */ new Set([...same.aliases, ...entry.aliases])],
833
+ ...entry.command ? { command: entry.command } : {},
834
+ ...entry.opens ? { opens: { ...same.opens, ...entry.opens } } : {}
835
+ } : entry;
836
+ const others = known.filter((one) => one !== same);
837
+ for (const word of wordsOf(merged)) {
838
+ const owner = others.find((one) => wordsOf(one).includes(word));
839
+ if (owner)
840
+ invalid(`"${word}" names two providers: ${describe(owner)} and ${describe(merged)}`);
841
+ }
842
+ return same ? known.map((one) => one === same ? merged : one) : [...known, merged];
843
+ }, "joined");
844
+ var registry = PROVIDERS;
845
+ var providers = /* @__PURE__ */ __name(() => registry, "providers");
846
+ var useStoredProviders = /* @__PURE__ */ __name((entries) => {
847
+ const left = [];
848
+ registry = entries.reduce((known, entry) => {
849
+ try {
850
+ return joined(known, providerEntryOf(entry));
851
+ } catch (error) {
852
+ if (!(error instanceof CliError))
853
+ throw error;
854
+ left.push(entry);
855
+ return known;
856
+ }
857
+ }, PROVIDERS);
858
+ return left;
859
+ }, "useStoredProviders");
860
+ var addProvider = /* @__PURE__ */ __name((entry) => {
861
+ registry = joined(registry, providerEntryOf(entry));
862
+ }, "addProvider");
863
+ var isKind = /* @__PURE__ */ __name((word) => KINDS.includes(word.toLowerCase()), "isKind");
864
+ var providerNamed = /* @__PURE__ */ __name((word) => {
865
+ const wanted = word.toLowerCase();
866
+ return registry.find((entry) => wordsOf(entry).includes(wanted));
867
+ }, "providerNamed");
868
+ var kindIn = /* @__PURE__ */ __name((provider) => isFolderProvider(provider) ? "notes" : registry.find(({ name }) => name === provider)?.kind, "kindIn");
869
+ var kindsIn = /* @__PURE__ */ __name((provider) => {
870
+ if (isFolderProvider(provider))
871
+ return ["notes"];
872
+ const entry = registry.find(({ name }) => name === provider);
873
+ if (!entry)
874
+ return [];
875
+ return entry.imported ? unitedKinds(kindsOfEntry(entry), ["documents"]) : kindsOfEntry(entry);
876
+ }, "kindsIn");
877
+ var importedOf = /* @__PURE__ */ __name((entry, held) => {
878
+ const builtIn = PROVIDERS.find(({ name }) => name === entry.name);
879
+ if (builtIn) {
880
+ if (entry.imported === true && builtIn.imported !== true)
881
+ invalid(`provider ${entry.name} is synced, so an entry cannot make it import-only`);
882
+ return builtIn.imported === true;
883
+ }
884
+ if (held === void 0)
885
+ return entry.imported === true;
886
+ if (entry.imported === true && held.imported !== true)
887
+ invalid(`provider ${entry.name} was registered without imported: an entry cannot make it import-only later`);
888
+ return held.imported === true;
889
+ }, "importedOf");
890
+ var isImportedProvider = /* @__PURE__ */ __name((provider) => registry.find(({ name }) => name === provider)?.imported === true, "isImportedProvider");
891
+ var holdsKind = /* @__PURE__ */ __name((provider, kind2) => kindsIn(provider).includes(kind2), "holdsKind");
892
+ var holdsKindOf = /* @__PURE__ */ __name((provider, kind2) => kindIn(provider) === void 0 ? kind2 === "messages" : holdsKind(provider, kind2), "holdsKindOf");
893
+ var kindOf = /* @__PURE__ */ __name((provider) => kindIn(provider) ?? "messages", "kindOf");
894
+
895
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/search/query.js
896
+ var isBotProvider = /* @__PURE__ */ __name((provider) => provider.endsWith("-bot"), "isBotProvider");
897
+ var inSource = /* @__PURE__ */ __name((source, provider) => source === "all" || source === "bots" && isBotProvider(provider) || source === "personal" && !isBotProvider(provider) || source === provider || providerNamed(source)?.name === provider || isKind(source) && holdsKindOf(provider, source), "inSource");
898
+ var fail = /* @__PURE__ */ __name((message) => {
899
+ throw new CliError("validation_error", message);
900
+ }, "fail");
901
+ var sourceOf = /* @__PURE__ */ __name((name, value, providers2) => {
902
+ const sources = [...providers2, "personal", "bots", "all"];
903
+ const source = value.toLowerCase();
904
+ if (sources.includes(source))
905
+ return source;
906
+ if (source === "mail")
907
+ return "email";
908
+ if (source === "messages")
909
+ return source;
910
+ if (isKind(source))
911
+ fail(`${name}${source} names ${source}, which a message search does not read \u2014 search ${source === "meetings" || source === "events" ? `all --source ${source}` : "notes"} does`);
912
+ const named = providerNamed(source);
913
+ if (named && providers2.includes(named.name))
914
+ return named.name;
915
+ return fail(`${name} takes ${[...sources, "messages", "mail"].join(", ")} \u2014 not "${value}"`);
916
+ }, "sourceOf");
917
+
918
+ // node_modules/.pnpm/@wirecat+cli-core@0.692.0_@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_comm_daa46dda8170ab81fe68d59b38277e40/node_modules/@wirecat/cli-core/dist/search/account-list.js
919
+ var ACCOUNT_GROUPS = "accountGroups";
920
+ var ACCOUNT_GROUPS_SETTING = "account_groups";
921
+ var GROUP_NAME = /^[a-z0-9][a-z0-9_-]*$/i;
922
+ var fail2 = /* @__PURE__ */ __name((message) => {
923
+ throw new CliError("validation_error", message);
924
+ }, "fail");
925
+ var isAccountList = /* @__PURE__ */ __name((value) => value.includes(",") || value.includes(":"), "isAccountList");
926
+ var itemsOf = /* @__PURE__ */ __name((value) => {
927
+ const items = value.split(",").map((item) => item.trim());
928
+ if (items.some((item) => item === ""))
929
+ fail2(`"${value}" has an empty entry \u2014 separate accounts with one comma`);
930
+ return items;
931
+ }, "itemsOf");
932
+ var isGroupName = /* @__PURE__ */ __name((name) => GROUP_NAME.test(name), "isGroupName");
933
+ var groupName = /* @__PURE__ */ __name((name) => isGroupName(name) ? name : fail2(`a group name is letters, digits, - and _ \u2014 not "${name}"`), "groupName");
934
+ var groupMembers = /* @__PURE__ */ __name((value) => itemsOf(value).map((item) => item.toLowerCase().startsWith("group:") ? fail2(`a group lists accounts, not other groups \u2014 "${item}"`) : item.includes(":") && item.split(":")[1] === "" ? fail2(`"${item}" names no account after the colon`) : item), "groupMembers");
935
+ var describe2 = /* @__PURE__ */ __name((accounts) => accounts.map(({ provider, account, name }) => `${provider}:${account}${name ? ` (${name})` : ""}`).join(", "), "describe");
936
+ var listedHolds = /* @__PURE__ */ __name((account, kind2) => (account.kinds ?? (account.kind === void 0 ? [] : [account.kind])).includes(kind2), "listedHolds");
937
+ var kindHere = /* @__PURE__ */ __name((provider, running) => provider === running.provider ? kindOf(provider) : kindIn(provider), "kindHere");
938
+ var kindsOfHere = /* @__PURE__ */ __name((provider, running) => {
939
+ const kinds = kindsIn(provider);
940
+ return { kind: kindHere(provider, running), ...kinds.length > 1 ? { kinds } : {} };
941
+ }, "kindsOfHere");
942
+ var heldOf = /* @__PURE__ */ __name((stored, running) => [
943
+ ...stored.filter(({ provider }) => kindIn(provider) !== "notes" && !isDocumentAccountProvider(provider)).map(({ provider, account, name }) => ({ provider, account, name, ...kindsOfHere(provider, running) })),
944
+ { provider: "notes", account: INTERNAL_NOTES, name: null, kind: "notes" },
945
+ ...stored.filter(({ provider }) => isFolderProvider(provider)).map(({ id, name, provider, account }) => ({
946
+ provider: "notes",
947
+ account: String(id),
948
+ name,
949
+ kind: "notes",
950
+ stored: { provider, account }
951
+ })),
952
+ ...stored.filter(({ provider }) => isDocumentAccountProvider(provider) || provider === ADDED_PROVIDER).map(({ id, provider, account, name }) => ({
953
+ provider: "notes",
954
+ account: String(id),
955
+ name,
956
+ kind: "notes",
957
+ stored: { provider, account }
958
+ }))
959
+ ], "heldOf");
960
+ var storedAs = /* @__PURE__ */ __name((held, key) => held.filter(({ stored }) => stored?.provider === key.provider && (key.account === "" || stored.account === key.account)), "storedAs");
961
+ var registry2 = /* @__PURE__ */ __name(() => providers().map(({ name, aliases }) => aliases.length ? `${name} (${aliases.join(", ")})` : name).join(", "), "registry");
962
+ var providerOf = /* @__PURE__ */ __name((prefix, held, { running, profiles }) => {
963
+ const wanted = prefix.toLowerCase();
964
+ if (wanted === running.command?.toLowerCase())
965
+ return running.provider;
966
+ const providers2 = [...new Set(held.map(({ provider }) => provider))];
967
+ if (providers2.includes(wanted) || isDocumentAccountProvider(wanted))
968
+ return wanted;
969
+ const named = providerNamed(wanted);
970
+ if (named)
971
+ return named.name;
972
+ const recorded = Object.values(profiles[wanted] ?? {})[0];
973
+ if (recorded)
974
+ return recorded.provider;
975
+ return fail2(`${prefix} is not a provider \u2014 they are ${registry2()}; the store holds ${providers2.join(", ")}`);
976
+ }, "providerOf");
977
+ var profilesOf = /* @__PURE__ */ __name((provider, profiles) => Object.values(profiles).flatMap((named) => Object.entries(named).filter(([, key]) => key.provider === provider)), "profilesOf");
978
+ var accountOf = /* @__PURE__ */ __name((prefix, ref, held, context) => {
979
+ const provider = providerOf(prefix, held, context);
980
+ if (isDocumentAccountProvider(provider) && !context.profiles[prefix.toLowerCase()]?.[ref]) {
981
+ const stored = storedAs(held, { provider, account: ref })[0];
982
+ if (stored)
983
+ return stored;
984
+ }
985
+ const folder = isFolderProvider(provider);
986
+ const ofProvider = folder ? storedAs(held, { provider, account: "" }) : held.filter((one) => one.provider === provider);
987
+ const byId = ofProvider.find(({ account, stored }) => account === ref || account === ref.toLowerCase() || folder && stored?.account === ref.toUpperCase());
988
+ if (byId)
989
+ return byId;
990
+ const keyed = /* @__PURE__ */ __name((key) => ofProvider.find(({ account }) => account === key.account) ?? {
991
+ ...key,
992
+ name: null,
993
+ ...kindsOfHere(key.provider, context.running)
994
+ }, "keyed");
995
+ const recorded = context.profiles[prefix.toLowerCase()]?.[ref];
996
+ if (recorded && isFolderProvider(recorded.provider)) {
997
+ const folder2 = held.find((one) => one.provider === "notes" && one.name === recorded.account);
998
+ if (folder2)
999
+ return folder2;
1000
+ return fail2(`no stored folder for ${prefix}:${ref}; sync that profile first`);
1001
+ }
1002
+ if (recorded && isDocumentAccountProvider(recorded.provider)) {
1003
+ const account = storedAs(held, recorded)[0];
1004
+ if (account)
1005
+ return account;
1006
+ return fail2(`no stored documents for ${prefix}:${ref}; sync that profile first`);
1007
+ }
1008
+ if (recorded)
1009
+ return keyed(recorded);
1010
+ const byProfile = [
1011
+ ...new Map(profilesOf(provider, context.profiles).filter(([name]) => name === ref).map(([, key]) => [key.account, key])).values()
1012
+ ];
1013
+ if (byProfile.length === 1)
1014
+ return keyed(byProfile[0]);
1015
+ const byName = ofProvider.filter(({ name }) => name?.toLowerCase() === ref.toLowerCase());
1016
+ if (byName.length === 1)
1017
+ return byName[0];
1018
+ if (byName.length > 1 || byProfile.length > 1)
1019
+ fail2(`${provider}:${ref} names more than one account \u2014 use the id: ${describe2(ofProvider)}`);
1020
+ const names = profilesOf(provider, context.profiles).map(([name]) => name);
1021
+ return fail2(`no ${provider} account "${ref}" \u2014 the store holds ${describe2(ofProvider) || "none"}` + (names.length ? `; profiles: ${[...new Set(names)].join(", ")}` : ""));
1022
+ }, "accountOf");
1023
+ var accountsOfWord = /* @__PURE__ */ __name((word, held, context) => {
1024
+ const wanted = word.toLowerCase();
1025
+ if (wanted === "all")
1026
+ return [...held];
1027
+ if (wanted === "personal" || wanted === "bots")
1028
+ return held.filter((one) => listedHolds(one, "messages") && isBotProvider(one.provider) === (wanted === "bots"));
1029
+ if (wanted === "documents")
1030
+ return held.filter((one) => listedHolds(one, "documents") || isDocumentAccount(one));
1031
+ if (isKind(wanted))
1032
+ return held.filter((one) => listedHolds(one, wanted));
1033
+ const recorded = context.profiles[wanted];
1034
+ if (recorded && Object.values(recorded).every((key) => isFolderProvider(key.provider) || isDocumentAccountProvider(key.provider)))
1035
+ return Object.keys(recorded).map((profile) => accountOf(word, profile, held, context));
1036
+ const provider = providerOf(word, held, context);
1037
+ if (isDocumentAccountProvider(provider) || isFolderProvider(provider))
1038
+ return storedAs(held, { provider, account: "" });
1039
+ return held.filter((one) => one.provider === provider);
1040
+ }, "accountsOfWord");
1041
+ var isDocumentAccount = /* @__PURE__ */ __name(({ stored }) => stored !== void 0 && isDocumentAccountProvider(stored.provider), "isDocumentAccount");
1042
+ var choices = /* @__PURE__ */ __name((held) => {
1043
+ const kinds = held.flatMap((one) => one.kinds ?? (one.kind ? [one.kind] : []));
1044
+ const messengers = held.filter((one) => listedHolds(one, "messages"));
1045
+ const providers2 = held.flatMap(({ stored, provider }) => stored?.provider === ADDED_PROVIDER ? [] : [stored?.provider ?? provider]);
1046
+ return [
1047
+ .../* @__PURE__ */ new Set([
1048
+ "all",
1049
+ ...messengers.some((one) => !isBotProvider(one.provider)) ? ["personal"] : [],
1050
+ ...messengers.some((one) => isBotProvider(one.provider)) ? ["bots"] : [],
1051
+ ...kinds,
1052
+ ...held.some(isDocumentAccount) ? ["documents"] : [],
1053
+ ...providers2
1054
+ ])
1055
+ ].join(", ");
1056
+ }, "choices");
1057
+ var keyOf = /* @__PURE__ */ __name(({ provider, account }) => `${provider}\0${account}`, "keyOf");
1058
+ var sourceOf2 = /* @__PURE__ */ __name(({ provider, account }) => `${provider}:${account}`, "sourceOf");
1059
+ var sameAs = /* @__PURE__ */ __name((key) => (one) => one.provider === key.provider && one.account === key.account, "sameAs");
1060
+ var entriesOfList = /* @__PURE__ */ __name((value, context) => {
1061
+ const held = heldOf(context.held, context.running);
1062
+ const entries = [];
1063
+ const entry = /* @__PURE__ */ __name((item, group) => {
1064
+ const colon = item.indexOf(":");
1065
+ if (colon === -1) {
1066
+ try {
1067
+ const accounts = accountsOfWord(item, held, context);
1068
+ entries.push({ entry: item, accounts, ...accounts.length === 0 && !group ? { holds: choices(held) } : {} });
1069
+ } catch (error) {
1070
+ if (!group || !(error instanceof CliError))
1071
+ throw error;
1072
+ fail2(`"${item}" in group ${group}: ${error.message}`);
1073
+ }
1074
+ return;
1075
+ }
1076
+ const prefix = item.slice(0, colon);
1077
+ const ref = item.slice(colon + 1).trim();
1078
+ if (ref === "")
1079
+ fail2(`"${item}" names no account after the colon`);
1080
+ if (prefix.toLowerCase() === "group") {
1081
+ if (group)
1082
+ fail2(`group ${group} lists another group \u2014 a group lists accounts`);
1083
+ const members = context.groups[ref];
1084
+ if (!members) {
1085
+ const known = Object.keys(context.groups);
1086
+ fail2(`no account group "${ref}" \u2014 ${known.length ? `there are ${known.join(", ")}` : "none saved yet"}; \`config set ${ACCOUNT_GROUPS_SETTING}.${ref} <accounts>\` saves one`);
1087
+ }
1088
+ for (const member of members)
1089
+ entry(member, ref);
1090
+ return;
1091
+ }
1092
+ entries.push({ entry: item, accounts: [accountOf(prefix, ref, held, context)] });
1093
+ }, "entry");
1094
+ for (const item of itemsOf(value))
1095
+ entry(item);
1096
+ const { only } = context;
1097
+ return entries.map(({ entry: entry2, accounts, holds }) => ({
1098
+ entry: entry2,
1099
+ ...holds === void 0 ? {} : { holds },
1100
+ accounts: accounts.filter((one) => only === void 0 || only.has(keyOf(one))).map(({ provider, account, kind: kind2, kinds }) => ({
1101
+ provider,
1102
+ account,
1103
+ kind: kind2,
1104
+ ...kinds === void 0 ? {} : { kinds }
1105
+ }))
1106
+ }));
1107
+ }, "entriesOfList");
1108
+ var accountsOfList = /* @__PURE__ */ __name((value, context) => {
1109
+ const chosen = /* @__PURE__ */ new Map();
1110
+ for (const { accounts } of entriesOfList(value, context))
1111
+ for (const one of accounts)
1112
+ if (!chosen.has(keyOf(one)))
1113
+ chosen.set(keyOf(one), one);
1114
+ return [...chosen.values()];
1115
+ }, "accountsOfList");
1116
+ var READS = {
1117
+ messages: "messenger messages \u2014 search messages reads them",
1118
+ mail: "a mailbox \u2014 memo search mail reads it",
1119
+ notes: "notes \u2014 search notes reads them",
1120
+ documents: "documents \u2014 search notes reads them",
1121
+ meetings: "meetings \u2014 search all reads them",
1122
+ events: "calendar events \u2014 no search reads them yet",
1123
+ crm: "CRM deals and leads \u2014 search all reads them"
1124
+ };
1125
+ var fitting = /* @__PURE__ */ __name((entries, kinds, what, reasonOf = (kind2) => READS[kind2], alsoFits = () => false) => {
1126
+ const chosen = /* @__PURE__ */ new Map();
1127
+ const skipped = [];
1128
+ for (const { entry, accounts } of entries) {
1129
+ const fits = accounts.filter((one) => kinds.some((kind2) => listedHolds(one, kind2)) || alsoFits(one));
1130
+ for (const { provider, account } of fits)
1131
+ if (!chosen.has(keyOf({ provider, account })))
1132
+ chosen.set(keyOf({ provider, account }), { provider, account });
1133
+ const known = accounts.filter(({ kind: kind2 }) => kind2 !== void 0);
1134
+ const unknown = accounts.filter((one) => one.kind === void 0 && !alsoFits(one));
1135
+ if (known.length)
1136
+ for (const { provider, account } of unknown)
1137
+ skipped.push({ source: `${provider}:${account}`, code: "not_found", reason: UNKNOWN_PROVIDER });
1138
+ if (fits.length)
1139
+ continue;
1140
+ const other = known[0];
1141
+ skipped.push(other?.kind ? { source: entry, code: "validation_error", reason: reasonOf(other.kind) } : unknown.length ? { source: entry, code: "not_found", reason: UNKNOWN_PROVIDER } : { source: entry, code: "not_found", reason: "no account in the store" });
1142
+ }
1143
+ if (chosen.size === 0) {
1144
+ const words = entries.length === 1 ? entries[0]?.holds : void 0;
1145
+ fail2(`--source names nothing ${what} reads: ${skipped.map(({ source, reason }) => `${source} (${reason})`).join(", ")}` + (words === void 0 ? "" : ` \u2014 the store holds ${words}`));
1146
+ }
1147
+ return { accounts: [...chosen.values()], skipped };
1148
+ }, "fitting");
1149
+
1150
+ export {
1151
+ formatLocator,
1152
+ isLocator,
1153
+ parseLocator,
1154
+ SIMPLE_REFERENCES,
1155
+ formatReference,
1156
+ parseReference,
1157
+ canonicalReference,
1158
+ looksLikeReference,
1159
+ logAttributes,
1160
+ fromLogAttributes,
1161
+ snakeLogger,
1162
+ LOG_ATTRIBUTES,
1163
+ KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
1164
+ KEEP_STORE_RUNS_FOR_DAYS,
1165
+ RUNS_SIZE_LIMIT_MB,
1166
+ runsDirFor,
1167
+ startRun,
1168
+ runtime,
1169
+ newRunId,
1170
+ listRuns,
1171
+ findRun,
1172
+ readEvents,
1173
+ asOwnProcess,
1174
+ currentRun,
1175
+ inRun,
1176
+ runEvent,
1177
+ typedCommand,
1178
+ useAsProcessRun,
1179
+ processRun,
1180
+ enclosingTraceId,
1181
+ traceOf,
1182
+ childTrace,
1183
+ withAttempt,
1184
+ currentAttempt,
1185
+ providerLabel,
1186
+ isFolderProvider,
1187
+ folderProviderSql,
1188
+ folderProviderOf,
1189
+ documentAccountProviders,
1190
+ isDocumentAccountProvider,
1191
+ documentAccountProvidersSql,
1192
+ ADDED_PROVIDER,
1193
+ ADDED_ACCOUNT,
1194
+ notAdded,
1195
+ filesAccountSql,
1196
+ INTERNAL_NOTES,
1197
+ UNKNOWN_PROVIDER,
1198
+ providerEntryOf,
1199
+ kindsOfEntry,
1200
+ unitedKinds,
1201
+ providers,
1202
+ useStoredProviders,
1203
+ addProvider,
1204
+ isKind,
1205
+ providerNamed,
1206
+ kindIn,
1207
+ importedOf,
1208
+ isImportedProvider,
1209
+ holdsKind,
1210
+ holdsKindOf,
1211
+ isBotProvider,
1212
+ inSource,
1213
+ sourceOf,
1214
+ ACCOUNT_GROUPS,
1215
+ ACCOUNT_GROUPS_SETTING,
1216
+ isAccountList,
1217
+ isGroupName,
1218
+ groupName,
1219
+ groupMembers,
1220
+ listedHolds,
1221
+ keyOf,
1222
+ sourceOf2,
1223
+ sameAs,
1224
+ entriesOfList,
1225
+ accountsOfList,
1226
+ fitting
1227
+ };