@wirecat/wordpress-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 (256) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +204 -0
  3. package/README.md +248 -2
  4. package/contracts/wirecat.json +2535 -0
  5. package/dist/bin/wordpress.d.ts +3 -0
  6. package/dist/bin/wordpress.d.ts.map +1 -0
  7. package/dist/bin/wordpress.js +40 -0
  8. package/dist/bin/wordpress.js.map +1 -0
  9. package/dist/bundle/agent-LKBRYKNB.js +37 -0
  10. package/dist/bundle/all-profiles-OEV7VFQG.js +320 -0
  11. package/dist/bundle/anthropic-JKTZP2DW.js +91 -0
  12. package/dist/bundle/app-server-7LWLDDE2.js +249 -0
  13. package/dist/bundle/bun-2FLR4IV4.js +169 -0
  14. package/dist/bundle/bun-sqlite-GRSRX5P4.js +76 -0
  15. package/dist/bundle/chunk-2BI25SEE.js +259 -0
  16. package/dist/bundle/chunk-2UEGJ5AJ.js +52 -0
  17. package/dist/bundle/chunk-2XUV7HNE.js +58 -0
  18. package/dist/bundle/chunk-2Z7UOXFC.js +16 -0
  19. package/dist/bundle/chunk-3BM6KBWP.js +2788 -0
  20. package/dist/bundle/chunk-3BRAZVHR.js +1010 -0
  21. package/dist/bundle/chunk-3LMW7U7F.js +1233 -0
  22. package/dist/bundle/chunk-3LVTQFGB.js +2000 -0
  23. package/dist/bundle/chunk-3TKFFSFU.js +106 -0
  24. package/dist/bundle/chunk-3UX4VJWD.js +78 -0
  25. package/dist/bundle/chunk-4HEXAGKT.js +334 -0
  26. package/dist/bundle/chunk-4HP6KGBI.js +32 -0
  27. package/dist/bundle/chunk-4ZAQMDLD.js +1308 -0
  28. package/dist/bundle/chunk-4ZTB7LS3.js +87 -0
  29. package/dist/bundle/chunk-5XPHFV7H.js +2333 -0
  30. package/dist/bundle/chunk-5Z3P543G.js +80 -0
  31. package/dist/bundle/chunk-6UYDKCV6.js +794 -0
  32. package/dist/bundle/chunk-7GNB4LBX.js +50 -0
  33. package/dist/bundle/chunk-7HJFBOAT.js +161 -0
  34. package/dist/bundle/chunk-7JVKQ6NM.js +206 -0
  35. package/dist/bundle/chunk-7QH5BZUG.js +142 -0
  36. package/dist/bundle/chunk-A474OVIW.js +1392 -0
  37. package/dist/bundle/chunk-AENEMQL3.js +1068 -0
  38. package/dist/bundle/chunk-AL7I4DT4.js +65718 -0
  39. package/dist/bundle/chunk-ARGRGTPX.js +108 -0
  40. package/dist/bundle/chunk-AV2ZJ4WX.js +7 -0
  41. package/dist/bundle/chunk-BAXNAOOL.js +76 -0
  42. package/dist/bundle/chunk-BH63B66W.js +407 -0
  43. package/dist/bundle/chunk-CCOSG3F2.js +24616 -0
  44. package/dist/bundle/chunk-CFQQTDSA.js +46 -0
  45. package/dist/bundle/chunk-CGCUOT67.js +388 -0
  46. package/dist/bundle/chunk-CHPWBQUK.js +39 -0
  47. package/dist/bundle/chunk-D72URWJE.js +532 -0
  48. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  49. package/dist/bundle/chunk-DQSOYH6N.js +20 -0
  50. package/dist/bundle/chunk-ECYOTDJM.js +14 -0
  51. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  52. package/dist/bundle/chunk-EHW45LLT.js +100 -0
  53. package/dist/bundle/chunk-F3AV5ZSL.js +338 -0
  54. package/dist/bundle/chunk-F4BX7TH2.js +15 -0
  55. package/dist/bundle/chunk-F5ZAN7OC.js +6848 -0
  56. package/dist/bundle/chunk-FMMYBVCH.js +38 -0
  57. package/dist/bundle/chunk-FNB4SWTY.js +66 -0
  58. package/dist/bundle/chunk-FQROWBKV.js +12660 -0
  59. package/dist/bundle/chunk-FV2HJOSC.js +771 -0
  60. package/dist/bundle/chunk-GCAJW4SR.js +53 -0
  61. package/dist/bundle/chunk-GPRJXJC7.js +102 -0
  62. package/dist/bundle/chunk-HCOZUOSN.js +54 -0
  63. package/dist/bundle/chunk-HM6AMYHR.js +72 -0
  64. package/dist/bundle/chunk-HVXOA4FO.js +23 -0
  65. package/dist/bundle/chunk-HWQ7572G.js +95 -0
  66. package/dist/bundle/chunk-IJVTN5L3.js +82 -0
  67. package/dist/bundle/chunk-IZDDBOHU.js +3610 -0
  68. package/dist/bundle/chunk-JAE5B4G7.js +388 -0
  69. package/dist/bundle/chunk-K2Y5K37O.js +218 -0
  70. package/dist/bundle/chunk-KCH224US.js +9581 -0
  71. package/dist/bundle/chunk-KZJQPJK5.js +230 -0
  72. package/dist/bundle/chunk-L7P3LUDQ.js +286 -0
  73. package/dist/bundle/chunk-LECMHK2F.js +18 -0
  74. package/dist/bundle/chunk-LWEMZJLG.js +1332 -0
  75. package/dist/bundle/chunk-LWTETL2O.js +185 -0
  76. package/dist/bundle/chunk-MEYYH47C.js +25 -0
  77. package/dist/bundle/chunk-MJ6LTG4L.js +170 -0
  78. package/dist/bundle/chunk-NMQRSEZM.js +37 -0
  79. package/dist/bundle/chunk-ODVGFCBE.js +557 -0
  80. package/dist/bundle/chunk-OEQNP56V.js +633 -0
  81. package/dist/bundle/chunk-OV6WQY3L.js +39 -0
  82. package/dist/bundle/chunk-PL5P7UKW.js +25216 -0
  83. package/dist/bundle/chunk-PPNTY7LD.js +733 -0
  84. package/dist/bundle/chunk-PRZYRA66.js +358 -0
  85. package/dist/bundle/chunk-PV5UYGRJ.js +41594 -0
  86. package/dist/bundle/chunk-QYTOLPNI.js +52 -0
  87. package/dist/bundle/chunk-R7Y3XU66.js +362 -0
  88. package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
  89. package/dist/bundle/chunk-SD5CXGIG.js +188 -0
  90. package/dist/bundle/chunk-SXY5G62I.js +288 -0
  91. package/dist/bundle/chunk-T37TAXVL.js +29 -0
  92. package/dist/bundle/chunk-T5SOY3AE.js +1197 -0
  93. package/dist/bundle/chunk-TJ7OORSO.js +1876 -0
  94. package/dist/bundle/chunk-TRYYWV7J.js +291 -0
  95. package/dist/bundle/chunk-U6VLNYCO.js +73 -0
  96. package/dist/bundle/chunk-UC7JLE6J.js +58 -0
  97. package/dist/bundle/chunk-UUIOAZPH.js +156 -0
  98. package/dist/bundle/chunk-UXQ24OY6.js +4072 -0
  99. package/dist/bundle/chunk-VBRRMGON.js +1007 -0
  100. package/dist/bundle/chunk-VRIBES2C.js +319 -0
  101. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  102. package/dist/bundle/chunk-XT5XYQEZ.js +3414 -0
  103. package/dist/bundle/chunk-XTAS5Z3G.js +2231 -0
  104. package/dist/bundle/chunk-XYQVVW4R.js +24 -0
  105. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  106. package/dist/bundle/chunk-YHWFF6DN.js +39 -0
  107. package/dist/bundle/chunk-YUDVRFXN.js +63 -0
  108. package/dist/bundle/chunk-Z3I2MCUT.js +131 -0
  109. package/dist/bundle/chunk-ZDI3WC7V.js +353 -0
  110. package/dist/bundle/chunk-ZVQ7KFMT.js +274 -0
  111. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  112. package/dist/bundle/command-contract-P7YE4EKS.js +37 -0
  113. package/dist/bundle/command-server-entry-XIMCBWMV.js +166 -0
  114. package/dist/bundle/decode-6XK55WYV.js +297 -0
  115. package/dist/bundle/definitions-GIQCGYPR.js +7986 -0
  116. package/dist/bundle/dispatch-JQBAZWCL.js +411 -0
  117. package/dist/bundle/dist-2TV3NVE5.js +7577 -0
  118. package/dist/bundle/dist-PAKDDIBT.js +191 -0
  119. package/dist/bundle/echarts-YRRVLEX3.js +42501 -0
  120. package/dist/bundle/embed-L3EEQSGX.js +38 -0
  121. package/dist/bundle/embedder-BIKLBV3J.js +111 -0
  122. package/dist/bundle/failure-I6AAF5R5.js +25 -0
  123. package/dist/bundle/first-run-W6G6TYZ2.js +29 -0
  124. package/dist/bundle/first-screen-ITIAJIBU.js +37 -0
  125. package/dist/bundle/hast-util-from-html-ZHU6HGIE.js +10531 -0
  126. package/dist/bundle/hast-util-to-html-IIFHILP5.js +998 -0
  127. package/dist/bundle/hast-util-to-mdast-D62XX3NR.js +2272 -0
  128. package/dist/bundle/instructions-AG7SRWTR.js +11 -0
  129. package/dist/bundle/mcp-YGOAUNC3.js +167 -0
  130. package/dist/bundle/mdast-util-from-markdown-WVUJDSUO.js +1900 -0
  131. package/dist/bundle/mdast-util-gfm-KN2D32QS.js +1040 -0
  132. package/dist/bundle/mdast-util-to-hast-AYJV7KAE.js +879 -0
  133. package/dist/bundle/mdast-util-to-markdown-UCAJNHJO.js +18 -0
  134. package/dist/bundle/meeting-combined-CQJ3JHHU.js +24 -0
  135. package/dist/bundle/meeting-model-MZ7VVBNK.js +25 -0
  136. package/dist/bundle/meeting-semantic-DADWRRHP.js +22 -0
  137. package/dist/bundle/micromark-extension-gfm-EEJRRJ36.js +1771 -0
  138. package/dist/bundle/node-GJQYN4FT.js +176 -0
  139. package/dist/bundle/node-JJ3WDCNJ.js +2340 -0
  140. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  141. package/dist/bundle/node-sqlite-TPR62DT2.js +74 -0
  142. package/dist/bundle/oauth-WGY7JQVW.js +20 -0
  143. package/dist/bundle/open-DE7QZNAN.js +23 -0
  144. package/dist/bundle/openai-NHEFT3HS.js +238 -0
  145. package/dist/bundle/process-MEKCZMX3.js +91 -0
  146. package/dist/bundle/program-EP2S5BTM.js +38857 -0
  147. package/dist/bundle/prompt-PWY53BYH.js +17 -0
  148. package/dist/bundle/recognize-74TXHKMQ.js +26 -0
  149. package/dist/bundle/remote-F5TJZ5ER.js +31 -0
  150. package/dist/bundle/rerank-HWUO52UF.js +52 -0
  151. package/dist/bundle/schemas-4K6WWS5N.js +2157 -0
  152. package/dist/bundle/serve-I2USUY4X.js +199 -0
  153. package/dist/bundle/server-GDYDNO6K.js +79 -0
  154. package/dist/bundle/server-KYUW2AHB.js +212 -0
  155. package/dist/bundle/sqlite-runtime-N6VFGBJK.js +20 -0
  156. package/dist/bundle/state-L6JSCN77.js +36 -0
  157. package/dist/bundle/store-EPG2YPN3.js +291 -0
  158. package/dist/bundle/store-SQWQJE32.js +181 -0
  159. package/dist/bundle/store-maintenance-command-FTGSICVA.js +66 -0
  160. package/dist/bundle/surface-SNMHY6GP.js +65 -0
  161. package/dist/bundle/wordpress.js +183 -0
  162. package/dist/commands/api.d.ts +22 -0
  163. package/dist/commands/api.d.ts.map +1 -0
  164. package/dist/commands/api.js +37 -0
  165. package/dist/commands/api.js.map +1 -0
  166. package/dist/commands/content.d.ts +4 -0
  167. package/dist/commands/content.d.ts.map +1 -0
  168. package/dist/commands/content.js +94 -0
  169. package/dist/commands/content.js.map +1 -0
  170. package/dist/commands/session.d.ts +8 -0
  171. package/dist/commands/session.d.ts.map +1 -0
  172. package/dist/commands/session.js +28 -0
  173. package/dist/commands/session.js.map +1 -0
  174. package/dist/config.d.ts +13 -0
  175. package/dist/config.d.ts.map +1 -0
  176. package/dist/config.js +69 -0
  177. package/dist/config.js.map +1 -0
  178. package/dist/context.d.ts +37 -0
  179. package/dist/context.d.ts.map +1 -0
  180. package/dist/context.js +31 -0
  181. package/dist/context.js.map +1 -0
  182. package/dist/generated/definitions.d.ts +3 -0
  183. package/dist/generated/definitions.d.ts.map +1 -0
  184. package/dist/generated/definitions.js +7982 -0
  185. package/dist/generated/definitions.js.map +1 -0
  186. package/dist/generated/manifest.d.ts +6 -0
  187. package/dist/generated/manifest.d.ts.map +1 -0
  188. package/dist/generated/manifest.js +8830 -0
  189. package/dist/generated/manifest.js.map +1 -0
  190. package/dist/generated/schemas.d.ts +229 -0
  191. package/dist/generated/schemas.d.ts.map +1 -0
  192. package/dist/generated/schemas.js +2019 -0
  193. package/dist/generated/schemas.js.map +1 -0
  194. package/dist/generated/types.d.ts +3365 -0
  195. package/dist/generated/types.d.ts.map +1 -0
  196. package/dist/generated/types.js +5 -0
  197. package/dist/generated/types.js.map +1 -0
  198. package/dist/generated/wirecat-config.d.ts +11 -0
  199. package/dist/generated/wirecat-config.d.ts.map +1 -0
  200. package/dist/generated/wirecat-config.js +337 -0
  201. package/dist/generated/wirecat-config.js.map +1 -0
  202. package/dist/identity.d.ts +28 -0
  203. package/dist/identity.d.ts.map +1 -0
  204. package/dist/identity.js +29 -0
  205. package/dist/identity.js.map +1 -0
  206. package/dist/index.d.ts +3 -0
  207. package/dist/index.d.ts.map +1 -0
  208. package/dist/index.js +3 -0
  209. package/dist/index.js.map +1 -0
  210. package/dist/program.d.ts +6 -0
  211. package/dist/program.d.ts.map +1 -0
  212. package/dist/program.js +53 -0
  213. package/dist/program.js.map +1 -0
  214. package/dist/version.d.ts +2 -0
  215. package/dist/version.d.ts.map +1 -0
  216. package/dist/version.js +2 -0
  217. package/dist/version.js.map +1 -0
  218. package/dist/wcat.d.ts +3 -0
  219. package/dist/wcat.d.ts.map +1 -0
  220. package/dist/wcat.js +4 -0
  221. package/dist/wcat.js.map +1 -0
  222. package/package.json +87 -4
  223. package/skills/wordpress-cli/SKILL.md +88 -0
  224. package/skills/wordpress-cli/references/api/api-block-directory.md +17 -0
  225. package/skills/wordpress-cli/references/api/api-block-patterns.md +13 -0
  226. package/skills/wordpress-cli/references/api/api-block-types.md +34 -0
  227. package/skills/wordpress-cli/references/api/api-blocks.md +159 -0
  228. package/skills/wordpress-cli/references/api/api-categories.md +69 -0
  229. package/skills/wordpress-cli/references/api/api-comments.md +79 -0
  230. package/skills/wordpress-cli/references/api/api-font-collections.md +16 -0
  231. package/skills/wordpress-cli/references/api/api-font-families.md +122 -0
  232. package/skills/wordpress-cli/references/api/api-global-styles.md +29 -0
  233. package/skills/wordpress-cli/references/api/api-media.md +106 -0
  234. package/skills/wordpress-cli/references/api/api-menu-items.md +115 -0
  235. package/skills/wordpress-cli/references/api/api-menu-locations.md +22 -0
  236. package/skills/wordpress-cli/references/api/api-menus.md +69 -0
  237. package/skills/wordpress-cli/references/api/api-navigation.md +155 -0
  238. package/skills/wordpress-cli/references/api/api-pages.md +161 -0
  239. package/skills/wordpress-cli/references/api/api-pattern-directory.md +23 -0
  240. package/skills/wordpress-cli/references/api/api-plugins.md +25 -0
  241. package/skills/wordpress-cli/references/api/api-posts.md +166 -0
  242. package/skills/wordpress-cli/references/api/api-search.md +21 -0
  243. package/skills/wordpress-cli/references/api/api-settings.md +19 -0
  244. package/skills/wordpress-cli/references/api/api-sidebars.md +34 -0
  245. package/skills/wordpress-cli/references/api/api-statuses.md +22 -0
  246. package/skills/wordpress-cli/references/api/api-tags.md +69 -0
  247. package/skills/wordpress-cli/references/api/api-taxonomies.md +23 -0
  248. package/skills/wordpress-cli/references/api/api-template-parts.md +38 -0
  249. package/skills/wordpress-cli/references/api/api-templates.md +38 -0
  250. package/skills/wordpress-cli/references/api/api-themes.md +12 -0
  251. package/skills/wordpress-cli/references/api/api-types.md +22 -0
  252. package/skills/wordpress-cli/references/api/api-users.md +149 -0
  253. package/skills/wordpress-cli/references/api/api-widget-types.md +46 -0
  254. package/skills/wordpress-cli/references/api/api-widgets.md +57 -0
  255. package/skills/wordpress-cli/references/api/api-wp-pattern-category.md +69 -0
  256. package/skills/wordpress-cli/references/api.md +44 -0
@@ -0,0 +1,2000 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ isCliFailure,
5
+ isStoreDamage
6
+ } from "./chunk-UUIOAZPH.js";
7
+ import {
8
+ formatMeetingReference,
9
+ parseMeetingReference
10
+ } from "./chunk-UXQ24OY6.js";
11
+ import {
12
+ refuseOwnerStoreInTests
13
+ } from "./chunk-HCOZUOSN.js";
14
+ import {
15
+ createRecordLog,
16
+ resolvePaths,
17
+ traceIdOf,
18
+ writeSecurely
19
+ } from "./chunk-3BM6KBWP.js";
20
+ import {
21
+ isoTime,
22
+ reference
23
+ } from "./chunk-3LMW7U7F.js";
24
+ import {
25
+ array,
26
+ boolean,
27
+ description,
28
+ integer,
29
+ maxLength,
30
+ minLength,
31
+ minValue,
32
+ nullable,
33
+ number,
34
+ optional,
35
+ picklist,
36
+ pipe,
37
+ record,
38
+ strictObject,
39
+ string,
40
+ unknown
41
+ } from "./chunk-S4UUN6LD.js";
42
+ import {
43
+ CliError,
44
+ singleLine
45
+ } from "./chunk-HM6AMYHR.js";
46
+ import {
47
+ __name
48
+ } from "./chunk-ZVVMGPBJ.js";
49
+
50
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/runs/run.js
51
+ import { randomUUID } from "node:crypto";
52
+ import { appendFileSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
53
+ import { userInfo } from "node:os";
54
+ import { join, sep } from "node:path";
55
+
56
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/runs/log-keys.js
57
+ var snake = /* @__PURE__ */ __name((key) => key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`), "snake");
58
+ var camel = /* @__PURE__ */ __name((key) => key.replace(/_([a-z0-9])/g, (_, letter) => letter.toUpperCase()), "camel");
59
+ var renamed = /* @__PURE__ */ __name((record2, name) => Object.fromEntries(Object.entries(record2).map(([key, value]) => [name(key), value])), "renamed");
60
+ var logAttributes = /* @__PURE__ */ __name((event) => renamed(event, snake), "logAttributes");
61
+ var fromLogAttributes = /* @__PURE__ */ __name((attributes) => renamed(attributes, camel), "fromLogAttributes");
62
+ var snakeLogger = /* @__PURE__ */ __name((logger) => ({
63
+ debug: /* @__PURE__ */ __name((event, message) => logger.debug(logAttributes(event), message), "debug"),
64
+ info: /* @__PURE__ */ __name((event, message) => logger.info(logAttributes(event), message), "info"),
65
+ warn: /* @__PURE__ */ __name((event, message) => logger.warn(logAttributes(event), message), "warn"),
66
+ error: /* @__PURE__ */ __name((event, message) => logger.error(logAttributes(event), message), "error")
67
+ }), "snakeLogger");
68
+
69
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/runs/log-attributes.js
70
+ var diagnostic = {
71
+ event: true,
72
+ operation: true,
73
+ opcode: true,
74
+ seq: true,
75
+ status: true,
76
+ method: true,
77
+ endpointTemplate: true,
78
+ bytes: true,
79
+ ids: true,
80
+ counts: true,
81
+ durationMs: true,
82
+ outcome: true,
83
+ errorCode: true,
84
+ providerError: true,
85
+ level: true,
86
+ transport: true,
87
+ attempt: true,
88
+ waitMs: true,
89
+ code: true,
90
+ detail: true,
91
+ reason: true,
92
+ ageMs: true,
93
+ kind: true,
94
+ table: true,
95
+ op: true,
96
+ n: true
97
+ };
98
+ var send = {
99
+ profile: true,
100
+ chatId: true,
101
+ outcome: true,
102
+ kind: true,
103
+ action: true,
104
+ people: true,
105
+ messageId: true,
106
+ key: true,
107
+ count: true,
108
+ forEveryone: true,
109
+ sendId: true,
110
+ operationId: true,
111
+ parentOperationId: true,
112
+ replyTo: true,
113
+ threadId: true,
114
+ sendAs: true,
115
+ resultChatId: true,
116
+ length: true,
117
+ attachments: true,
118
+ scheduledFor: true,
119
+ notify: true,
120
+ origin: true,
121
+ reservation: true,
122
+ errorCode: true
123
+ };
124
+ var background = [
125
+ "job",
126
+ "pid",
127
+ "schedule",
128
+ "exitCode",
129
+ "tool",
130
+ "tier",
131
+ "actorType",
132
+ "actorId",
133
+ "agent",
134
+ "targetType",
135
+ "targetId"
136
+ ];
137
+ var crash = ["errorClass", "frames"];
138
+ var dropped = ["dropped"];
139
+ var LOG_ATTRIBUTES = [
140
+ ...new Set([...Object.keys(diagnostic), ...Object.keys(send), ...background, ...crash, ...dropped].map((key) => Object.keys(logAttributes({ [key]: true }))[0]))
141
+ ].sort();
142
+
143
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/runs/run.js
144
+ var KEEP_RUNS_FOR_DAYS = 30;
145
+ var KEEP_SUCCESSFUL_RUNS_FOR_DAYS = 7;
146
+ var KEEP_STORE_RUNS_FOR_DAYS = 3;
147
+ var RUNS_SIZE_LIMIT_MB = 200;
148
+ var runsDirFor = /* @__PURE__ */ __name((app, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "runs"), "runsDirFor");
149
+ var startRun = /* @__PURE__ */ __name((options) => {
150
+ const now = options.now ?? (() => /* @__PURE__ */ new Date());
151
+ const startedAt = options.startedAt ?? now();
152
+ const id2 = options.runId ?? newRunId(startedAt, options.command);
153
+ const dir = join(options.runsDir, day(startedAt), id2);
154
+ pruneRuns(options.runsDir, {
155
+ keepDays: options.keepDays ?? KEEP_RUNS_FOR_DAYS,
156
+ keepSuccessDays: options.keepSuccessDays ?? KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
157
+ keepStoreDays: options.keepStoreDays ?? KEEP_STORE_RUNS_FOR_DAYS,
158
+ maxBytes: options.maxBytes ?? RUNS_SIZE_LIMIT_MB * 1024 * 1024,
159
+ now: startedAt
160
+ });
161
+ refuseRealStateInTests(dir);
162
+ const metadata = {
163
+ runId: id2,
164
+ command: options.command,
165
+ ...options.profile === void 0 ? {} : { profile: options.profile },
166
+ startedAt: startedAt.toISOString(),
167
+ status: "running",
168
+ cliVersion: options.cliVersion,
169
+ runtime: runtime(),
170
+ platform: process.platform,
171
+ arch: process.arch,
172
+ ...options.traceId === void 0 ? {} : { traceId: options.traceId },
173
+ ...options.context
174
+ };
175
+ let file;
176
+ const opened = /* @__PURE__ */ __name(() => {
177
+ if (file)
178
+ return file;
179
+ mkdirSync(dir, { recursive: true, mode: 448 });
180
+ const events = join(dir, "events.jsonl");
181
+ writeFileSync(events, "", { flag: "a", mode: 384 });
182
+ file = snakeLogger(createRecordLog({
183
+ to: events,
184
+ runId: id2,
185
+ command: options.command,
186
+ resource: { service: options.service, version: options.cliVersion },
187
+ allow: LOG_ATTRIBUTES,
188
+ ...options.traceId === void 0 ? {} : { traceId: options.traceId },
189
+ ...options.onError === void 0 ? {} : { onError: options.onError }
190
+ }));
191
+ writeRunFile(dir, metadata);
192
+ return file;
193
+ }, "opened");
194
+ if (!options.lazy)
195
+ opened();
196
+ let finished = false;
197
+ const operations = /* @__PURE__ */ new Set();
198
+ const codes = /* @__PURE__ */ new Set();
199
+ const tables = /* @__PURE__ */ new Set();
200
+ const noted = /* @__PURE__ */ __name((level) => (event, message) => {
201
+ const { operation, errorCode, error_code, code, kind: kind2, table } = event;
202
+ if (typeof operation === "string")
203
+ operations.add(operation);
204
+ if (kind2 === "store" && typeof table === "string")
205
+ tables.add(table);
206
+ for (const value of [errorCode, error_code, code])
207
+ if (typeof value === "string")
208
+ codes.add(value);
209
+ if (finished)
210
+ return;
211
+ opened()[level](event, message);
212
+ }, "noted");
213
+ const logger = { debug: noted("debug"), info: noted("info"), warn: noted("warn"), error: noted("error") };
214
+ return {
215
+ id: id2,
216
+ dir,
217
+ logger,
218
+ finish: /* @__PURE__ */ __name(async (status, extra = {}) => {
219
+ if (finished)
220
+ return;
221
+ finished = true;
222
+ const completedAt = now();
223
+ const final = {
224
+ ...metadata,
225
+ ...extra,
226
+ status,
227
+ completedAt: completedAt.toISOString(),
228
+ durationMs: completedAt.getTime() - startedAt.getTime(),
229
+ operations: [...operations].sort(),
230
+ codes: [...codes].sort(),
231
+ ...tables.size > 0 ? { tables: [...tables].sort() } : {}
232
+ };
233
+ if (file || status !== "success") {
234
+ opened();
235
+ writeRunFile(dir, final);
236
+ return;
237
+ }
238
+ try {
239
+ mkdirSync(join(dir, ".."), { recursive: true, mode: 448 });
240
+ appendIndex(join(dir, ".."), runFileOf(final));
241
+ } catch (error) {
242
+ options.onError?.(error);
243
+ }
244
+ }, "finish")
245
+ };
246
+ }, "startRun");
247
+ var refuseRealStateInTests = /* @__PURE__ */ __name((dir, env = process.env) => {
248
+ if (env.VITEST === void 0)
249
+ return;
250
+ let home;
251
+ try {
252
+ home = userInfo().homedir;
253
+ } catch {
254
+ return;
255
+ }
256
+ if (dir.startsWith(join(home, ".local", "share") + sep))
257
+ throw new Error(`a test opened a run in the real data folder: ${dir}`);
258
+ }, "refuseRealStateInTests");
259
+ var runtime = /* @__PURE__ */ __name(() => {
260
+ const bun = process.versions.bun;
261
+ return bun ? `bun ${bun}` : `node ${process.versions.node}`;
262
+ }, "runtime");
263
+ var newRunId = /* @__PURE__ */ __name((startedAt, command) => {
264
+ const stamp = startedAt.toISOString().replace(/[-:]/g, "").replace(/\.\d+Z$/, "Z");
265
+ const slug = command.replace(/[^a-z0-9]+/gi, "-").toLowerCase();
266
+ return `${stamp}-${slug}-${randomUUID().slice(0, 6)}`;
267
+ }, "newRunId");
268
+ var INDEX = "index.jsonl";
269
+ var appendIndex = /* @__PURE__ */ __name((dayDir, written) => {
270
+ appendFileSync(join(dayDir, INDEX), `${JSON.stringify(written)}
271
+ `, { mode: 384 });
272
+ }, "appendIndex");
273
+ var writeRunFile = /* @__PURE__ */ __name((dir, metadata) => {
274
+ const written = runFileOf(metadata);
275
+ writeSecurely(join(dir, "run.json"), `${JSON.stringify(written, null, 2)}
276
+ `, 384);
277
+ try {
278
+ appendIndex(join(dir, ".."), written);
279
+ } catch {
280
+ }
281
+ }, "writeRunFile");
282
+ 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");
283
+ var listRuns = /* @__PURE__ */ __name((runsDir, { since, atLeast = Number.POSITIVE_INFINITY, filter = {} } = {}) => {
284
+ const first = since === void 0 ? void 0 : day(new Date(since));
285
+ const runs = [];
286
+ for (const date of days(runsDir).sort().reverse()) {
287
+ if (first !== void 0 && date < first || runs.length >= atLeast)
288
+ break;
289
+ for (const metadata of runsOfDay(join(runsDir, date))) {
290
+ if (matchesListFilter(metadata, filter))
291
+ runs.push(metadata);
292
+ }
293
+ }
294
+ return runs;
295
+ }, "listRuns");
296
+ var indexedRuns = /* @__PURE__ */ __name((dayDir) => {
297
+ const latest = /* @__PURE__ */ new Map();
298
+ let raw = "";
299
+ try {
300
+ raw = readFileSync(join(dayDir, INDEX), "utf8");
301
+ } catch {
302
+ }
303
+ for (const line of raw.split("\n")) {
304
+ if (line.trim() === "")
305
+ continue;
306
+ try {
307
+ const metadata = metadataOf(JSON.parse(line));
308
+ if (typeof metadata.runId === "string")
309
+ latest.set(metadata.runId, metadata);
310
+ } catch {
311
+ }
312
+ }
313
+ return latest;
314
+ }, "indexedRuns");
315
+ var runsOfDay = /* @__PURE__ */ __name((dayDir) => {
316
+ const latest = indexedRuns(dayDir);
317
+ for (const entry of safeReaddir(dayDir)) {
318
+ if (entry === INDEX || entry.startsWith(".") || latest.has(entry))
319
+ continue;
320
+ const metadata = readRun(join(dayDir, entry));
321
+ if (metadata)
322
+ latest.set(metadata.runId, metadata);
323
+ }
324
+ return [...latest.values()].sort((a, b) => a.runId < b.runId ? 1 : a.runId > b.runId ? -1 : 0);
325
+ }, "runsOfDay");
326
+ var findRun = /* @__PURE__ */ __name((runsDir, id2) => {
327
+ const stamped = /^(\d{4})(\d{2})(\d{2})T/.exec(id2);
328
+ const likely = stamped ? [`${stamped[1]}-${stamped[2]}-${stamped[3]}`] : [];
329
+ const dates = [.../* @__PURE__ */ new Set([...likely, ...days(runsDir)])];
330
+ for (const date of dates) {
331
+ const dir = join(runsDir, date, id2);
332
+ const metadata = readRun(dir);
333
+ if (metadata)
334
+ return { dir, metadata };
335
+ }
336
+ for (const date of dates) {
337
+ const metadata = indexedRuns(join(runsDir, date)).get(id2);
338
+ if (metadata)
339
+ return { dir: join(runsDir, date, id2), metadata };
340
+ }
341
+ return void 0;
342
+ }, "findRun");
343
+ var readEvents = /* @__PURE__ */ __name((dir) => {
344
+ let raw;
345
+ try {
346
+ raw = readFileSync(join(dir, "events.jsonl"), "utf8");
347
+ } catch {
348
+ return [];
349
+ }
350
+ const events = [];
351
+ for (const line of raw.split("\n")) {
352
+ if (line.trim() === "")
353
+ continue;
354
+ try {
355
+ const parsed = JSON.parse(line);
356
+ if (parsed !== null && typeof parsed === "object")
357
+ events.push(eventOf(parsed));
358
+ } catch {
359
+ }
360
+ }
361
+ return events;
362
+ }, "readEvents");
363
+ var eventOf = /* @__PURE__ */ __name((line) => {
364
+ const { attributes, time: time2, severity: severity2 } = line;
365
+ if (attributes === null || typeof attributes !== "object")
366
+ return logAttributes(line);
367
+ return { time: time2, severity: severity2, ...logAttributes(attributes) };
368
+ }, "eventOf");
369
+ var pruneRuns = /* @__PURE__ */ __name((runsDir, { keepDays, keepSuccessDays = keepDays, keepStoreDays = KEEP_STORE_RUNS_FOR_DAYS, maxBytes, now }) => {
370
+ const cutoff = day(new Date(now.getTime() - keepDays * DAY_MS));
371
+ const before = /* @__PURE__ */ __name((days2) => day(new Date(now.getTime() - Math.min(days2, keepDays) * DAY_MS)), "before");
372
+ const successCutoff = before(keepSuccessDays);
373
+ const storeCutoff = before(keepStoreDays);
374
+ const keptFor = /* @__PURE__ */ __name((metadata) => metadata.keptBecauseStore ? keepStoreDays : metadata.operations?.includes(STORE_WRITE) ? Math.max(keepSuccessDays, keepStoreDays) : keepSuccessDays, "keptFor");
375
+ let removed = 0;
376
+ for (const date of days(runsDir)) {
377
+ if (date >= cutoff) {
378
+ if (date < storeCutoff)
379
+ dropSuccesses(join(runsDir, date), STORE_RUNS_DROPPED, (metadata) => keptFor(metadata) <= keepStoreDays);
380
+ if (date < successCutoff)
381
+ dropSuccesses(join(runsDir, date), SUCCESSES_DROPPED, (metadata) => keptFor(metadata) <= keepSuccessDays);
382
+ continue;
383
+ }
384
+ try {
385
+ rmSync(join(runsDir, date), { recursive: true, force: true });
386
+ removed += 1;
387
+ } catch {
388
+ }
389
+ }
390
+ if (maxBytes !== void 0)
391
+ removed += fitSize(runsDir, maxBytes, now);
392
+ return removed;
393
+ }, "pruneRuns");
394
+ var DAY_MS = 24 * 60 * 60 * 1e3;
395
+ var STORE_WRITE = "store.write";
396
+ var SUCCESSES_DROPPED = ".successes-dropped";
397
+ var STORE_RUNS_DROPPED = ".store-runs-dropped";
398
+ var SIZE_CHECKED = ".size-checked";
399
+ var dropSuccesses = /* @__PURE__ */ __name((dayDir, marker = SUCCESSES_DROPPED, drops = () => true) => {
400
+ const done = join(dayDir, marker);
401
+ try {
402
+ statSync(done);
403
+ return;
404
+ } catch {
405
+ }
406
+ const dropped2 = /* @__PURE__ */ __name((metadata) => metadata?.status === "success" && drops(metadata), "dropped");
407
+ try {
408
+ const kept = [];
409
+ for (const [id2, metadata] of indexedRuns(dayDir)) {
410
+ if (dropped2(metadata))
411
+ rmSync(join(dayDir, id2), { recursive: true, force: true });
412
+ else
413
+ kept.push(JSON.stringify(runFileOf(metadata)));
414
+ }
415
+ for (const entry of safeReaddir(dayDir)) {
416
+ if (entry === INDEX || entry.startsWith("."))
417
+ continue;
418
+ if (dropped2(readRun(join(dayDir, entry))))
419
+ rmSync(join(dayDir, entry), { recursive: true, force: true });
420
+ }
421
+ writeSecurely(join(dayDir, INDEX), kept.map((line) => `${line}
422
+ `).join(""), 384);
423
+ writeFileSync(done, "", { mode: 384 });
424
+ } catch {
425
+ }
426
+ }, "dropSuccesses");
427
+ var sizeOf = /* @__PURE__ */ __name((path) => {
428
+ let total = 0;
429
+ for (const entry of safeReaddir(path)) {
430
+ const full = join(path, entry);
431
+ try {
432
+ const stat = statSync(full);
433
+ total += stat.isDirectory() ? sizeOf(full) : stat.size;
434
+ } catch {
435
+ }
436
+ }
437
+ return total;
438
+ }, "sizeOf");
439
+ var fitSize = /* @__PURE__ */ __name((runsDir, maxBytes, now) => {
440
+ const stamp = join(runsDir, SIZE_CHECKED);
441
+ const today = day(now);
442
+ try {
443
+ if (readFileSync(stamp, "utf8").trim() === today)
444
+ return 0;
445
+ } catch {
446
+ }
447
+ const dates = days(runsDir).sort();
448
+ const sizes = new Map(dates.map((date) => [date, sizeOf(join(runsDir, date))]));
449
+ let total = [...sizes.values()].reduce((sum, size) => sum + size, 0);
450
+ let removed = 0;
451
+ for (const date of dates) {
452
+ if (total <= maxBytes || date === today)
453
+ break;
454
+ dropSuccesses(join(runsDir, date));
455
+ const after = sizeOf(join(runsDir, date));
456
+ total -= (sizes.get(date) ?? 0) - after;
457
+ sizes.set(date, after);
458
+ }
459
+ for (const date of dates) {
460
+ if (total <= maxBytes || date === today)
461
+ break;
462
+ try {
463
+ rmSync(join(runsDir, date), { recursive: true, force: true });
464
+ total -= sizes.get(date) ?? 0;
465
+ removed += 1;
466
+ } catch {
467
+ }
468
+ }
469
+ try {
470
+ mkdirSync(runsDir, { recursive: true, mode: 448 });
471
+ writeFileSync(stamp, today, { mode: 384 });
472
+ } catch {
473
+ }
474
+ return removed;
475
+ }, "fitSize");
476
+ var day = /* @__PURE__ */ __name((date) => date.toISOString().slice(0, 10), "day");
477
+ var days = /* @__PURE__ */ __name((runsDir) => safeReaddir(runsDir).filter((entry) => /^\d{4}-\d{2}-\d{2}$/.test(entry)), "days");
478
+ var readRun = /* @__PURE__ */ __name((dir) => {
479
+ try {
480
+ return metadataOf(JSON.parse(readFileSync(join(dir, "run.json"), "utf8")));
481
+ } catch {
482
+ return void 0;
483
+ }
484
+ }, "readRun");
485
+ var safeReaddir = /* @__PURE__ */ __name((dir) => {
486
+ try {
487
+ return readdirSync(dir);
488
+ } catch {
489
+ return [];
490
+ }
491
+ }, "safeReaddir");
492
+ var runFileOf = /* @__PURE__ */ __name(({ partial, ...metadata }) => ({
493
+ ...logAttributes(metadata),
494
+ ...partial ? { partial: { ...logAttributes(partial), failures: partial.failures.map((failure) => logAttributes(failure)) } } : {}
495
+ }), "runFileOf");
496
+ var metadataOf = /* @__PURE__ */ __name((parsed) => {
497
+ const { partial, ...metadata } = fromLogAttributes(parsed);
498
+ if (partial === null || typeof partial !== "object")
499
+ return metadata;
500
+ const { failures, ...rest } = fromLogAttributes(partial);
501
+ return {
502
+ ...metadata,
503
+ partial: {
504
+ ...rest,
505
+ failures: Array.isArray(failures) ? failures.map((failure) => fromLogAttributes(failure)) : []
506
+ }
507
+ };
508
+ }, "metadataOf");
509
+
510
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/runs/scope.js
511
+ import { AsyncLocalStorage } from "node:async_hooks";
512
+ import { randomBytes } from "node:crypto";
513
+ var scopes = new AsyncLocalStorage();
514
+ var processScope;
515
+ var ownProcesses = new AsyncLocalStorage();
516
+ var asOwnProcess = /* @__PURE__ */ __name((body) => ownProcesses.run({}, body), "asOwnProcess");
517
+ var currentRun = /* @__PURE__ */ __name(() => {
518
+ const scope = scopes.getStore();
519
+ if (scope)
520
+ return scope;
521
+ const own = ownProcesses.getStore();
522
+ const fresh = /* @__PURE__ */ __name(() => ({
523
+ runId: newRunId(/* @__PURE__ */ new Date(), "process"),
524
+ command: "",
525
+ startedAt: Date.now(),
526
+ ...traceOf(process.env)
527
+ }), "fresh");
528
+ if (own) {
529
+ own.scope ??= fresh();
530
+ return own.scope;
531
+ }
532
+ processScope ??= fresh();
533
+ return processScope;
534
+ }, "currentRun");
535
+ var inRun = /* @__PURE__ */ __name((scope, body) => scopes.run(scope, body), "inRun");
536
+ var runEvent = /* @__PURE__ */ __name((event) => scopes.getStore()?.events?.(event), "runEvent");
537
+ var typedCommand = /* @__PURE__ */ __name((tool, words, profile = currentRun().profile) => [tool, profile, words].filter((part) => part !== void 0 && part !== "").join(" "), "typedCommand");
538
+ var useAsProcessRun = /* @__PURE__ */ __name((scope) => {
539
+ const own = ownProcesses.getStore();
540
+ if (own)
541
+ own.scope = scope;
542
+ else
543
+ processScope = scope;
544
+ }, "useAsProcessRun");
545
+ var processRun = /* @__PURE__ */ __name(() => {
546
+ const own = ownProcesses.getStore();
547
+ return own ? own.scope : processScope;
548
+ }, "processRun");
549
+ var enclosingTraceId = /* @__PURE__ */ __name(() => scopes.getStore()?.traceId, "enclosingTraceId");
550
+ var traceOf = /* @__PURE__ */ __name((env) => {
551
+ const traceId = traceIdOf(env.TRACEPARENT);
552
+ return traceId === void 0 ? {} : { traceId };
553
+ }, "traceOf");
554
+ var childTrace = /* @__PURE__ */ __name(() => {
555
+ const hex = /* @__PURE__ */ __name((bytes) => randomBytes(bytes).toString("hex"), "hex");
556
+ const traceId = hex(16);
557
+ return { traceId, traceparent: `00-${traceId}-${hex(8)}-01` };
558
+ }, "childTrace");
559
+ var attempts = new AsyncLocalStorage();
560
+ var withAttempt = /* @__PURE__ */ __name((attempt, work) => attempts.run(attempt, work), "withAttempt");
561
+ var currentAttempt = /* @__PURE__ */ __name(() => attempts.getStore(), "currentAttempt");
562
+
563
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/tasks/model.js
564
+ var TASK_KINDS = ["question", "request", "mention", "promise"];
565
+ var TASK_STATES = ["open", "todo", "in_progress", "done", "dismissed"];
566
+ var CLOSED_STATES = ["done", "dismissed"];
567
+ var TASK_ORIGINS = ["rule", "agent", "owner"];
568
+ var TASK_VERDICTS = ["useful", "not_useful"];
569
+ var isClosedState = /* @__PURE__ */ __name((state) => CLOSED_STATES.includes(state), "isClosedState");
570
+ function closeTask(task, state, by, at, reason) {
571
+ if (isClosedState(task.state))
572
+ throw new CliError("validation_error", `task ${task.id} is already ${task.state}`, { reason: "task.closed" });
573
+ const { claimedBy: _by, claimedUntil: _until, ...unclaimed } = task;
574
+ return { ...unclaimed, state, closedAt: at, closedBy: by, ...reason === void 0 ? {} : { reason } };
575
+ }
576
+ __name(closeTask, "closeTask");
577
+
578
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/tasks/priority.js
579
+ var PRIORITY_LABELS = ["low", "medium", "high", "critical"];
580
+ var MIDDLE = { low: 0.125, medium: 0.375, high: 0.625, critical: 0.875 };
581
+ var LEGACY_PRIORITY_SCORES = [0.875, 0.625, 0.375, 0.1875, 0.0625];
582
+ var priorityLabel = /* @__PURE__ */ __name((score) => score === null ? null : PRIORITY_LABELS[Math.min(3, Math.max(0, Math.floor(score * 4)))], "priorityLabel");
583
+ var priorityBand = /* @__PURE__ */ __name((label) => {
584
+ const at = PRIORITY_LABELS.indexOf(label);
585
+ return { from: at / 4, to: (at + 1) / 4 };
586
+ }, "priorityBand");
587
+ var legacyPriority = /* @__PURE__ */ __name((score) => score === null ? null : score < 0.125 ? 4 : 3 - PRIORITY_LABELS.indexOf(priorityLabel(score)), "legacyPriority");
588
+ var checkedScore = /* @__PURE__ */ __name((score) => {
589
+ if (!Number.isFinite(score) || score < 0 || score > 1)
590
+ throw new CliError("validation_error", "a priority score is 0 to 1");
591
+ return score;
592
+ }, "checkedScore");
593
+ var priorityOf = /* @__PURE__ */ __name((value) => {
594
+ const word = value.trim().toLowerCase();
595
+ if (word === "none")
596
+ return null;
597
+ if (PRIORITY_LABELS.includes(word))
598
+ return MIDDLE[word];
599
+ if (/^[0-4]$/.test(word))
600
+ return LEGACY_PRIORITY_SCORES[Number(word)];
601
+ if (/^(0?\.\d+|[01]\.\d*)$/.test(word) && Number(word) <= 1)
602
+ return Number(word);
603
+ throw new CliError("validation_error", `a priority is ${PRIORITY_LABELS.join(", ")}, none, or a score from 0.0 to 1.0 with its decimal point; 0 (urgent) \u2026 4 (low) still work as critical, high, medium, low, low`);
604
+ }, "priorityOf");
605
+ var priorityOption = /* @__PURE__ */ __name((value) => priorityOf(value) ?? "none", "priorityOption");
606
+
607
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/tasks/service.js
608
+ function createTaskService({ store, now = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now"), newId = /* @__PURE__ */ __name(() => crypto.randomUUID(), "newId") }) {
609
+ async function find(id2) {
610
+ const task = await store.get(id2);
611
+ if (!task)
612
+ throw new CliError("not_found", `no task ${id2}`);
613
+ return task;
614
+ }
615
+ __name(find, "find");
616
+ return {
617
+ /**
618
+ * A rule never makes a second task from a source it has seen, whatever that task's state, so a
619
+ * dismissed one stays dismissed — nor from a message attached or merged into a task. A person or an agent may
620
+ * add a task of another kind to it. A task a rule opens goes through the host's duplicate check.
621
+ */
622
+ async add(input) {
623
+ const rule = input.origin === "rule";
624
+ const existing = await store.findBySource(input.account, input.source, rule ? { linked: true } : void 0);
625
+ const same = rule ? existing[0] : existing.find((task2) => task2.kind === input.kind);
626
+ if (same)
627
+ return { task: same, created: false };
628
+ const task = { ...input, id: newId(), state: "open", createdAt: now() };
629
+ await store.insert(task);
630
+ if (!rule || !store.reviewDuplicates)
631
+ return { task, created: true };
632
+ return { task, created: true, review: await store.reviewDuplicates(task.id) };
633
+ },
634
+ async close(id2, { as, by, reason }) {
635
+ const task = closeTask(await find(id2), as, by, now(), reason);
636
+ await store.update(task);
637
+ return task;
638
+ },
639
+ list: /* @__PURE__ */ __name((filter = {}) => store.list(filter), "list"),
640
+ async stats(filter = {}) {
641
+ const byGroup = /* @__PURE__ */ new Map();
642
+ for (const task of await store.list(filter))
643
+ byGroup.set(task.group, [...byGroup.get(task.group) ?? [], task]);
644
+ return [...byGroup].map(([group, tasks]) => {
645
+ const open = tasks.filter((task) => !isClosedState(task.state));
646
+ const closeMs = tasks.flatMap((task) => task.closedAt ? [task.closedAt.getTime() - task.createdAt.getTime()] : []);
647
+ const oldestOpenAt = open.map((task) => task.createdAt).sort((a, b) => a.getTime() - b.getTime())[0];
648
+ return {
649
+ group,
650
+ open: open.length,
651
+ ...oldestOpenAt ? { oldestOpenAt } : {},
652
+ ...closeMs.length > 0 ? { medianCloseMs: median(closeMs) } : {}
653
+ };
654
+ });
655
+ }
656
+ };
657
+ }
658
+ __name(createTaskService, "createTaskService");
659
+ function median(values) {
660
+ const sorted = [...values].sort((a, b) => a - b);
661
+ const middle = Math.floor(sorted.length / 2);
662
+ const upper = sorted[middle] ?? 0;
663
+ return sorted.length % 2 === 1 ? upper : ((sorted[middle - 1] ?? 0) + upper) / 2;
664
+ }
665
+ __name(median, "median");
666
+
667
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/tasks/store.js
668
+ function matches(task, filter) {
669
+ return (filter.account === void 0 || task.account === filter.account) && (filter.state === void 0 || task.state === filter.state) && (filter.group === void 0 || task.group === filter.group) && (filter.kind === void 0 || task.kind === filter.kind) && (filter.createdBefore === void 0 || task.createdAt < filter.createdBefore);
670
+ }
671
+ __name(matches, "matches");
672
+
673
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/store/source-review.js
674
+ var SOURCE_REVIEW_KIND = "memory_source_review";
675
+ var SOURCE_REVIEW_CAUSES = ["changed", "outdated", "deleted", "contradicted"];
676
+ var ERASED_TEXT = "[source erased]";
677
+ var severity = /* @__PURE__ */ __name((cause) => SOURCE_REVIEW_CAUSES.indexOf(cause), "severity");
678
+ var graver = /* @__PURE__ */ __name((a, b) => severity(b) > severity(a) ? b : a, "graver");
679
+
680
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/entities/fields.js
681
+ var text = string();
682
+ var id = pipe(string(), minLength(1));
683
+ var time = isoTime;
684
+ var typedTime = pipe(string(), minLength(1), maxLength(64), description("an ISO 8601 date or time, in the computer's zone without one; or 30m, 2h, 7d ago"));
685
+ var count = pipe(number(), integer(), minValue(0));
686
+ var untrusted = optional(array(text));
687
+ var providerMetadata = optional(record(string(), unknown()));
688
+ var evidenceSource = strictObject({
689
+ ref: nullable(reference),
690
+ kind: text,
691
+ title: nullable(text),
692
+ sender: nullable(text),
693
+ at: nullable(time),
694
+ excerpt: nullable(text),
695
+ tool: nullable(text),
696
+ missing: boolean()
697
+ });
698
+ var sourceReview = nullable(strictObject({ id, cause: picklist(SOURCE_REVIEW_CAUSES) }));
699
+ var author = strictObject({
700
+ type: picklist(["person", "bot"]),
701
+ id,
702
+ name: nullable(text)
703
+ });
704
+
705
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/entities/knowledge-lists.js
706
+ var organization = strictObject({
707
+ id,
708
+ ref: reference,
709
+ kind: picklist(["company", "team", "family", "community"]),
710
+ name: text,
711
+ scope: picklist(["personal", "work"]),
712
+ created_at: time
713
+ });
714
+ var project = strictObject({
715
+ id,
716
+ ref: reference,
717
+ key: text,
718
+ name: text,
719
+ kind: picklist(["project", "inbox"]),
720
+ type: picklist(["work", "client", "personal", "oss", "other"]),
721
+ organization_id: nullable(id),
722
+ scope: picklist(["personal", "work"]),
723
+ created_at: time
724
+ });
725
+ var reminder = strictObject({
726
+ id,
727
+ task: text,
728
+ due_at: time,
729
+ timezone: text,
730
+ state: picklist(["pending", "leased", "delivered", "cancelled"]),
731
+ revision: number(),
732
+ receipt: nullable(text)
733
+ });
734
+
735
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/store/marks.js
736
+ import { readFileSync as readFileSync2, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
737
+ var damageMarkPath = /* @__PURE__ */ __name((store) => `${store}.damaged.json`, "damageMarkPath");
738
+ var healthMarkPath = /* @__PURE__ */ __name((store) => `${store}.health.json`, "healthMarkPath");
739
+ var journalMarkPath = /* @__PURE__ */ __name((store) => `${store}.journal.json`, "journalMarkPath");
740
+ var inodeOf = /* @__PURE__ */ __name((store) => statSync2(store, { throwIfNoEntry: false })?.ino, "inodeOf");
741
+ var readJson = /* @__PURE__ */ __name((path) => {
742
+ try {
743
+ return JSON.parse(readFileSync2(path, "utf8"));
744
+ } catch (error) {
745
+ if (error.code === "ENOENT")
746
+ return null;
747
+ throw error;
748
+ }
749
+ }, "readJson");
750
+ var ownerStoreInTests = /* @__PURE__ */ __name((store) => {
751
+ try {
752
+ refuseOwnerStoreInTests(store);
753
+ return false;
754
+ } catch {
755
+ return true;
756
+ }
757
+ }, "ownerStoreInTests");
758
+ var sqliteFailure = /* @__PURE__ */ __name((error) => isCliFailure(error) && error.details?.reason === "store.damaged" ? error.cause : error, "sqliteFailure");
759
+ var markStoreDamaged = /* @__PURE__ */ __name((error, { store, command, version, runId, now = Date.now }) => {
760
+ const failure = sqliteFailure(error);
761
+ if (!isStoreDamage(failure) || ownerStoreInTests(store))
762
+ return false;
763
+ const inode = inodeOf(store);
764
+ if (inode === void 0)
765
+ return false;
766
+ const mark = {
767
+ at: new Date(now()).toISOString(),
768
+ command,
769
+ ...version ? { cli_version: version } : {},
770
+ ...runId ? { run_id: runId } : {},
771
+ error: failure.message.slice(0, 500),
772
+ inode
773
+ };
774
+ try {
775
+ writeFileSync2(damageMarkPath(store), `${JSON.stringify(mark, null, 2)}
776
+ `, { flag: "wx", mode: 384 });
777
+ return true;
778
+ } catch {
779
+ return false;
780
+ }
781
+ }, "markStoreDamaged");
782
+ var readDamageMark = /* @__PURE__ */ __name((store) => {
783
+ const path = damageMarkPath(store);
784
+ let mark;
785
+ try {
786
+ mark = readJson(path);
787
+ } catch {
788
+ return { at: "unknown", command: "unknown", error: `${path} cannot be read`, inode: inodeOf(store) ?? 0 };
789
+ }
790
+ if (mark === null)
791
+ return null;
792
+ if (mark.inode !== inodeOf(store)) {
793
+ clearDamageMark(store);
794
+ return null;
795
+ }
796
+ return mark;
797
+ }, "readDamageMark");
798
+ var clearDamageMark = /* @__PURE__ */ __name((store) => rmSync2(damageMarkPath(store), { force: true }), "clearDamageMark");
799
+ var refuseDamagedStore = /* @__PURE__ */ __name((store, cli) => {
800
+ const mark = readDamageMark(store);
801
+ if (!mark)
802
+ return;
803
+ throw new CliError("configuration_error", `the store was found damaged at ${mark.at} by \`${mark.command}\` (${mark.error}), so nothing writes to it until it is recovered; \`${cli ?? "<cli>"} store recover\` says what is damaged and what to do`, { reason: "store.damaged" });
804
+ }, "refuseDamagedStore");
805
+ var markJournalLost = /* @__PURE__ */ __name((store, { seen, command, now = Date.now }) => {
806
+ if (ownerStoreInTests(store))
807
+ return;
808
+ const mark = { at: new Date(now()).toISOString(), command, seen };
809
+ try {
810
+ writeFileSync2(journalMarkPath(store), `${JSON.stringify(mark, null, 2)}
811
+ `, { flag: "wx", mode: 384 });
812
+ } catch {
813
+ }
814
+ }, "markJournalLost");
815
+ var readJournalMark = /* @__PURE__ */ __name((store) => {
816
+ try {
817
+ return readJson(journalMarkPath(store));
818
+ } catch {
819
+ return null;
820
+ }
821
+ }, "readJournalMark");
822
+ var readHealthMark = /* @__PURE__ */ __name((store) => {
823
+ try {
824
+ return readJson(healthMarkPath(store));
825
+ } catch {
826
+ return null;
827
+ }
828
+ }, "readHealthMark");
829
+ var recordDeepCheck = /* @__PURE__ */ __name((store, health, { cli, version, schema, now = Date.now }) => {
830
+ const previous = readHealthMark(store);
831
+ if (ownerStoreInTests(store))
832
+ return { previous, cleared: null };
833
+ const checkedAt = new Date(now()).toISOString();
834
+ const mark = {
835
+ checked_at: checkedAt,
836
+ ok: health.ok,
837
+ problems: health.problems ?? 0,
838
+ schema,
839
+ cli,
840
+ ...version ? { cli_version: version } : {},
841
+ last_ok_at: health.ok ? checkedAt : previous?.last_ok_at ?? null
842
+ };
843
+ const cleared = health.ok ? readDamageMark(store) : null;
844
+ try {
845
+ writeFileSync2(healthMarkPath(store), `${JSON.stringify(mark, null, 2)}
846
+ `, { mode: 384 });
847
+ } catch {
848
+ }
849
+ if (cleared)
850
+ clearDamageMark(store);
851
+ if (health.ok)
852
+ rmSync2(journalMarkPath(store), { force: true });
853
+ return { previous, cleared };
854
+ }, "recordDeepCheck");
855
+
856
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/money.js
857
+ var CURRENCY_SCALES = {
858
+ AED: 2,
859
+ AMD: 2,
860
+ AUD: 2,
861
+ BHD: 3,
862
+ BYN: 2,
863
+ CAD: 2,
864
+ CHF: 2,
865
+ CLP: 0,
866
+ CNY: 2,
867
+ CZK: 2,
868
+ DKK: 2,
869
+ EUR: 2,
870
+ GBP: 2,
871
+ GEL: 2,
872
+ HUF: 2,
873
+ ILS: 2,
874
+ INR: 2,
875
+ ISK: 0,
876
+ JPY: 0,
877
+ KGS: 2,
878
+ KRW: 0,
879
+ KWD: 3,
880
+ KZT: 2,
881
+ NOK: 2,
882
+ PLN: 2,
883
+ RSD: 2,
884
+ RUB: 2,
885
+ SEK: 2,
886
+ THB: 2,
887
+ TRY: 2,
888
+ UAH: 2,
889
+ USD: 2,
890
+ UZS: 2,
891
+ VND: 0
892
+ };
893
+ var refuse = /* @__PURE__ */ __name((message, reason) => {
894
+ throw new CliError("validation_error", message, { reason });
895
+ }, "refuse");
896
+ var DECIMAL = /^(\d{1,15})(?:\.(\d+))?$/;
897
+ var parseDecimal = /* @__PURE__ */ __name((text2, scale) => {
898
+ const match = DECIMAL.exec(text2.trim());
899
+ if (!match || (match[2] ?? "").length > scale)
900
+ return void 0;
901
+ return BigInt(`${match[1]}${(match[2] ?? "").padEnd(scale, "0")}`);
902
+ }, "parseDecimal");
903
+ var formatDecimal = /* @__PURE__ */ __name((units, scale) => {
904
+ const value = BigInt(units);
905
+ if (value < 0n)
906
+ return `-${formatDecimal(-value, scale)}`;
907
+ const digits = value.toString().padStart(scale + 1, "0");
908
+ return scale === 0 ? digits : `${digits.slice(0, -scale)}.${digits.slice(-scale)}`;
909
+ }, "formatDecimal");
910
+ var groupDigits = /* @__PURE__ */ __name((decimal) => {
911
+ const [whole = "0", fraction] = decimal.split(".");
912
+ const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
913
+ return fraction === void 0 ? grouped : `${grouped}.${fraction}`;
914
+ }, "groupDigits");
915
+ var currencyOf = /* @__PURE__ */ __name((text2) => {
916
+ const code = typeof text2 === "string" ? text2.trim().toUpperCase() : "";
917
+ if (CURRENCY_SCALES[code] === void 0)
918
+ return refuse(`${typeof text2 === "string" && text2.trim() ? text2.trim() : "an empty currency"} is not a currency the store keeps; use one of ${Object.keys(CURRENCY_SCALES).join(", ")}`, "money.currency");
919
+ return code;
920
+ }, "currencyOf");
921
+ var scaleOf = /* @__PURE__ */ __name((currency) => CURRENCY_SCALES[currencyOf(currency)], "scaleOf");
922
+ var minorUnits = /* @__PURE__ */ __name((amount, currency, what = "an amount") => {
923
+ const scale = scaleOf(currency);
924
+ const units = typeof amount === "string" ? parseDecimal(amount, scale) : void 0;
925
+ if (units === void 0 || units > BigInt(Number.MAX_SAFE_INTEGER))
926
+ return refuse(`${what} is a decimal string with at most ${scale} decimal${scale === 1 ? "" : "s"} for ${currency}, such as "${formatDecimal(5e3 * 10 ** scale, scale)}"`, "money.amount");
927
+ return Number(units);
928
+ }, "minorUnits");
929
+ var signedMinorUnits = /* @__PURE__ */ __name((amount, currency, what = "an amount") => {
930
+ if (typeof amount !== "string" || !amount.trim().startsWith("-"))
931
+ return minorUnits(amount, currency, what);
932
+ const units = minorUnits(amount.trim().slice(1), currency, what);
933
+ return units === 0 ? 0 : -units;
934
+ }, "signedMinorUnits");
935
+ var moneyOf = /* @__PURE__ */ __name((units, currency) => ({
936
+ amount: formatDecimal(units, scaleOf(currency)),
937
+ currency
938
+ }), "moneyOf");
939
+ var moneyLabel = /* @__PURE__ */ __name((units, currency) => `${groupDigits(formatDecimal(units, scaleOf(currency)))} ${currency}`, "moneyLabel");
940
+ var QUANTITY_SCALE = 3;
941
+ var quantityOf = /* @__PURE__ */ __name((text2) => {
942
+ const thousandths = typeof text2 === "string" ? parseDecimal(text2, QUANTITY_SCALE) : void 0;
943
+ if (thousandths === void 0 || thousandths === 0n)
944
+ return refuse('a quantity is a decimal string above 0 with at most 3 decimals, such as "1.5"', "money.quantity");
945
+ const plain = formatDecimal(thousandths, QUANTITY_SCALE).replace(/\.?0+$/, "");
946
+ return { text: plain, thousandths };
947
+ }, "quantityOf");
948
+ var lineUnits = /* @__PURE__ */ __name((thousandths, unitPrice) => Number((thousandths * BigInt(unitPrice) + 500n) / 1000n), "lineUnits");
949
+
950
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/finance.js
951
+ var INVOICE_DIRECTIONS = ["receivable", "payable"];
952
+ var INVOICE_STATUSES = ["draft", "issued", "partly_paid", "paid", "void"];
953
+ var MONEY_DIRECTIONS = ["in", "out"];
954
+ var FINANCE_REVIEWS = ["proposed", "confirmed", "rejected"];
955
+ var settledStatus = /* @__PURE__ */ __name((current, total, paid) => {
956
+ if (current === "draft" || current === "void")
957
+ return current;
958
+ if (paid <= 0)
959
+ return "issued";
960
+ return paid < total ? "partly_paid" : "paid";
961
+ }, "settledStatus");
962
+ var dayMonth = /* @__PURE__ */ __name((date) => date === null ? null : `${date.slice(8, 10)}.${date.slice(5, 7)}`, "dayMonth");
963
+ var notes = /* @__PURE__ */ __name((...words) => {
964
+ const kept = words.filter((word) => word !== null);
965
+ return kept.length === 0 ? "" : ` (${kept.join(", ")})`;
966
+ }, "notes");
967
+ var invoiceLine = /* @__PURE__ */ __name((invoice) => {
968
+ const party = invoice.counterpartyName === null ? "" : `${invoice.direction === "receivable" ? " to" : " from"} ${invoice.counterpartyName}`;
969
+ const due = invoice.dueDate === null ? "" : `, due ${dayMonth(invoice.dueDate)}`;
970
+ return `${invoice.number ?? `#${invoice.id}`} \xB7 ${moneyLabel(invoice.total, invoice.currency)}${party}${due}` + notes(invoice.status.replace("_", " "), invoice.review === "confirmed" ? null : invoice.review);
971
+ }, "invoiceLine");
972
+ var paymentLine = /* @__PURE__ */ __name((payment) => {
973
+ const party = payment.partyName === null ? "" : `${payment.direction === "in" ? " from" : " to"} ${payment.partyName}`;
974
+ return `${moneyLabel(payment.amount, payment.currency)}${party}, ${dayMonth(payment.date)}` + notes(payment.review === "confirmed" ? null : payment.review);
975
+ }, "paymentLine");
976
+ var invoiceTitle = /* @__PURE__ */ __name((invoice) => `Invoice ${invoiceLine(invoice)}`, "invoiceTitle");
977
+ var paymentEntryTitle = /* @__PURE__ */ __name((payment) => `Payment \xB7 ${paymentLine(payment)}`, "paymentEntryTitle");
978
+
979
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/business.js
980
+ var CATALOG_KINDS = ["product", "service"];
981
+ var BUSINESS_KINDS = ["invoice", "payment", "order", "contract", "subscription", "product", "wallet"];
982
+ var CONTRACT_KINDS = ["sale", "purchase", "service", "lease", "employment", "nda", "license", "other"];
983
+ var CONTRACT_STATUSES = ["draft", "active", "ended", "terminated"];
984
+ var SUBSCRIPTION_STATUSES = ["trial", "active", "paused", "cancelled", "ended"];
985
+ var WALLET_KINDS = ["bank", "card", "cash", "wallet", "other"];
986
+ var TRANSACTION_STATUSES = ["pending", "booked"];
987
+ var ORDER_DIRECTIONS = ["purchase", "sale"];
988
+ var intervalOf = /* @__PURE__ */ __name((text2, reason = "subscription.interval") => {
989
+ const match = typeof text2 === "string" ? /^(?:([1-9]\d{0,2})-)?(day|week|month|year)$/.exec(text2.trim()) : null;
990
+ if (!match)
991
+ throw new CliError("validation_error", "an interval is a count and a unit, such as 1-month or 2-week", { reason });
992
+ return { count: match[1] === void 0 ? 1 : Number(match[1]), unit: match[2] };
993
+ }, "intervalOf");
994
+ var intervalText = /* @__PURE__ */ __name(({ count: count2, unit }) => `${count2}-${unit}`, "intervalText");
995
+ var priced = /* @__PURE__ */ __name((units, currency) => units === null || currency === null ? "" : `, ${moneyLabel(units, currency)}`, "priced");
996
+ var pending = /* @__PURE__ */ __name((review) => review === "confirmed" ? null : review, "pending");
997
+ var productLine = /* @__PURE__ */ __name((product) => {
998
+ const price = product.unitPrice === null || product.currency === null ? "" : moneyLabel(product.unitPrice, product.currency);
999
+ const per = price && product.unit !== null ? ` per ${product.unit}` : "";
1000
+ return `${product.name}${price ? ` \xB7 ${price}${per}` : ""}${notes(product.kind, product.archived ? "archived" : null)}`;
1001
+ }, "productLine");
1002
+ var contractLine = /* @__PURE__ */ __name((contract) => `${contract.number ?? `#${contract.id}`} \xB7 ${contract.name}${priced(contract.value, contract.currency)}` + notes(contract.status, pending(contract.review)), "contractLine");
1003
+ var subscriptionLine = /* @__PURE__ */ __name((subscription) => `${subscription.name}${priced(subscription.price, subscription.currency)} every ${intervalText(subscription.interval)}` + notes(subscription.status, pending(subscription.review)), "subscriptionLine");
1004
+ var walletLine = /* @__PURE__ */ __name((wallet) => `${wallet.name} \xB7 ${wallet.kind}, ${wallet.currency}${wallet.numberHint === null ? "" : `, \u2026${wallet.numberHint}`}` + notes(wallet.closed ? "closed" : null), "walletLine");
1005
+ var transactionLine = /* @__PURE__ */ __name((transaction) => `${moneyLabel(transaction.amount, transaction.currency)} ${transaction.direction}${transaction.label === null ? "" : ` \xB7 ${transaction.label}`}, ${dayMonth(transaction.date)}` + notes(transaction.status === "pending" ? "pending" : null, pending(transaction.review)), "transactionLine");
1006
+
1007
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/knowledge.js
1008
+ var FACT_STATUSES = ["proposed", "accepted", "superseded", "reversed", "rejected"];
1009
+ var MEMORY_KINDS = ["summary", "digest", "preference"];
1010
+ var MEMORY_STATUSES = ["proposed", "confirmed", "stale", "superseded"];
1011
+ var MEMORY_SCOPES = ["personal", "work"];
1012
+ var WORK_TASK_TYPES = ["bug", "feature", "chore"];
1013
+ var TASK_TYPES = [...WORK_TASK_TYPES, ...TASK_KINDS];
1014
+
1015
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/locator.js
1016
+ var SCHEME = "msg:";
1017
+ var formatLocator = /* @__PURE__ */ __name(({ provider, account, chat, message }) => SCHEME + [provider, account, chat, message].map(encodeURIComponent).join("/"), "formatLocator");
1018
+ var isLocator = /* @__PURE__ */ __name((reference2) => reference2.trim().startsWith(SCHEME), "isLocator");
1019
+ var parseLocator = /* @__PURE__ */ __name((reference2) => {
1020
+ const trimmed = reference2.trim();
1021
+ const parts2 = trimmed.startsWith(SCHEME) ? trimmed.slice(SCHEME.length).split("/") : [];
1022
+ const malformed2 = /* @__PURE__ */ __name(() => new CliError("validation_error", `"${singleLine(reference2)}" is not a message locator \u2014 expected msg:<provider>/<account>/<chat>/<message>`), "malformed");
1023
+ if (parts2.length !== 4 || parts2.some((part) => part === ""))
1024
+ throw malformed2();
1025
+ const decoded2 = /* @__PURE__ */ __name((part) => {
1026
+ try {
1027
+ return decodeURIComponent(part);
1028
+ } catch {
1029
+ throw malformed2();
1030
+ }
1031
+ }, "decoded");
1032
+ const [provider, account, chat, message] = parts2.map(decoded2);
1033
+ return { provider, account, chat, message };
1034
+ }, "parseLocator");
1035
+
1036
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/references.js
1037
+ var SIMPLE_REFERENCES = [
1038
+ "note",
1039
+ "document",
1040
+ "person",
1041
+ "organization",
1042
+ "project",
1043
+ "task",
1044
+ "memory",
1045
+ "fact",
1046
+ "bot",
1047
+ "event",
1048
+ "invoice",
1049
+ "payment",
1050
+ "order",
1051
+ "deal",
1052
+ "lead",
1053
+ "pipeline",
1054
+ "product",
1055
+ "contract",
1056
+ "subscription",
1057
+ "wallet",
1058
+ "transaction",
1059
+ "entity"
1060
+ ];
1061
+ var malformed = /* @__PURE__ */ __name((text2, shape) => new CliError("validation_error", `"${singleLine(text2)}" is not a reference \u2014 expected ${shape}`, {
1062
+ reason: "ref.malformed"
1063
+ }), "malformed");
1064
+ var decoded = /* @__PURE__ */ __name((part, text2, shape) => {
1065
+ try {
1066
+ return decodeURIComponent(part);
1067
+ } catch {
1068
+ throw malformed(text2, shape);
1069
+ }
1070
+ }, "decoded");
1071
+ var parts = /* @__PURE__ */ __name((rest, count2, text2, shape) => {
1072
+ const split = rest.split("/");
1073
+ if (split.length !== count2 || split.some((part) => part === ""))
1074
+ throw malformed(text2, shape);
1075
+ return split.map((part) => decoded(part, text2, shape));
1076
+ }, "parts");
1077
+ var encoded = /* @__PURE__ */ __name((...values) => values.map(encodeURIComponent).join("/"), "encoded");
1078
+ var folderPath = /* @__PURE__ */ __name((path) => {
1079
+ const clean = path.split("/").filter((part) => part !== "" && part !== ".").join("/");
1080
+ return clean === "" ? path.trim() === "" ? "" : null : clean;
1081
+ }, "folderPath");
1082
+ var MEETING_SHAPE = "meeting:<account>/<meeting>[/<transcript>[/<cue>]] with safe integer ids";
1083
+ var kind = /* @__PURE__ */ __name((spec) => spec, "kind");
1084
+ var simple = /* @__PURE__ */ __name((prefix) => kind({
1085
+ prefix,
1086
+ type: prefix,
1087
+ shape: `${prefix}:<id>`,
1088
+ parse: /* @__PURE__ */ __name((rest, text2) => {
1089
+ if (!rest.trim())
1090
+ throw new CliError("validation_error", `"${singleLine(text2)}" names no ${prefix}`, {
1091
+ reason: "ref.malformed"
1092
+ });
1093
+ return { type: prefix, id: rest };
1094
+ }, "parse"),
1095
+ format: /* @__PURE__ */ __name((reference2) => `${reference2.type}:${reference2.id}`, "format")
1096
+ }), "simple");
1097
+ var REF_KINDS = [
1098
+ kind({
1099
+ prefix: "msg",
1100
+ type: "message",
1101
+ shape: "msg:<provider>/<account>/<chat>/<message>",
1102
+ parse: /* @__PURE__ */ __name((_, text2) => {
1103
+ try {
1104
+ return { type: "message", ...parseLocator(text2) };
1105
+ } catch {
1106
+ throw malformed(text2, "msg:<provider>/<account>/<chat>/<message>");
1107
+ }
1108
+ }, "parse"),
1109
+ format: formatLocator
1110
+ }),
1111
+ kind({
1112
+ prefix: "chat",
1113
+ type: "chat",
1114
+ shape: "chat:<provider>/<account>/<chat>",
1115
+ parse: /* @__PURE__ */ __name((rest, text2) => {
1116
+ const [provider, account, chat] = parts(rest, 3, text2, "chat:<provider>/<account>/<chat>");
1117
+ return { type: "chat", provider, account, chat };
1118
+ }, "parse"),
1119
+ format: /* @__PURE__ */ __name(({ provider, account, chat }) => `chat:${encoded(provider, account, chat)}`, "format")
1120
+ }),
1121
+ kind({
1122
+ prefix: "contact",
1123
+ type: "contact",
1124
+ shape: "contact:<provider>/<id>",
1125
+ parse: /* @__PURE__ */ __name((rest, text2) => {
1126
+ const [provider, id2] = parts(rest, 2, text2, "contact:<provider>/<id>");
1127
+ return { type: "contact", provider, id: id2 };
1128
+ }, "parse"),
1129
+ format: /* @__PURE__ */ __name(({ provider, id: id2 }) => `contact:${encoded(provider, id2)}`, "format")
1130
+ }),
1131
+ kind({
1132
+ prefix: "folder",
1133
+ type: "folder",
1134
+ shape: "folder:<id>[/<path>]",
1135
+ parse: /* @__PURE__ */ __name((rest, text2) => {
1136
+ const slash = rest.indexOf("/");
1137
+ const id2 = decoded(slash < 0 ? rest : rest.slice(0, slash), text2, "folder:<id>[/<path>]");
1138
+ const path = slash < 0 ? null : folderPath(decoded(rest.slice(slash + 1), text2, "folder:<id>[/<path>]"));
1139
+ if (!id2.trim() || path === "")
1140
+ throw malformed(text2, "folder:<id>[/<path>]");
1141
+ return { type: "folder", id: id2, path };
1142
+ }, "parse"),
1143
+ format: /* @__PURE__ */ __name(({ id: id2, path }) => path === null ? `folder:${encodeURIComponent(id2)}` : `folder:${encoded(id2, path)}`, "format")
1144
+ }),
1145
+ kind({
1146
+ prefix: "meeting",
1147
+ type: "meeting",
1148
+ shape: MEETING_SHAPE,
1149
+ parse: /* @__PURE__ */ __name((_, text2) => {
1150
+ try {
1151
+ return parseMeetingReference(text2);
1152
+ } catch {
1153
+ throw malformed(text2, MEETING_SHAPE);
1154
+ }
1155
+ }, "parse"),
1156
+ format: formatMeetingReference
1157
+ }),
1158
+ ...SIMPLE_REFERENCES.map(simple)
1159
+ ];
1160
+ var byPrefix = new Map(REF_KINDS.map((spec) => [spec.prefix, spec]));
1161
+ var byType = new Map(REF_KINDS.map((spec) => [spec.type, spec]));
1162
+ var offered = REF_KINDS.map(({ prefix }) => prefix).filter((prefix) => prefix !== "entity");
1163
+ var distance = /* @__PURE__ */ __name((a, b) => {
1164
+ let row = Array.from({ length: b.length + 1 }, (_, at) => at);
1165
+ for (const [i, x] of [...a].entries()) {
1166
+ const next = [i + 1];
1167
+ for (const [j, y] of [...b].entries())
1168
+ next.push(Math.min(row[j + 1] + 1, next[j] + 1, row[j] + (x === y ? 0 : 1)));
1169
+ row = next;
1170
+ }
1171
+ return row[b.length];
1172
+ }, "distance");
1173
+ 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");
1174
+ var unknownKind = /* @__PURE__ */ __name((text2, prefix, rest) => {
1175
+ const near = prefix === "" ? void 0 : nearest(prefix);
1176
+ const kinds = offered.map((one) => `${one}:`).join(", ");
1177
+ const hint = near === void 0 ? `; kinds: ${kinds}` : `; did you mean ${near}:${singleLine(rest)}? Kinds: ${kinds}`;
1178
+ return new CliError("validation_error", `"${singleLine(text2)}" is no kind of reference${hint}`, {
1179
+ reason: "ref.unknown-kind"
1180
+ });
1181
+ }, "unknownKind");
1182
+ var formatReference = /* @__PURE__ */ __name((reference2) => byType.get(reference2.type).format(reference2), "formatReference");
1183
+ var parseReference = /* @__PURE__ */ __name((text2) => {
1184
+ const reference2 = text2.trim();
1185
+ const colon = reference2.indexOf(":");
1186
+ const prefix = colon < 0 ? "" : reference2.slice(0, colon);
1187
+ const rest = reference2.slice(colon + 1);
1188
+ const spec = byPrefix.get(prefix);
1189
+ if (!spec)
1190
+ throw unknownKind(reference2, prefix, rest);
1191
+ return spec.parse(rest, reference2);
1192
+ }, "parseReference");
1193
+ var canonicalReference = /* @__PURE__ */ __name((text2) => formatReference(parseReference(text2)), "canonicalReference");
1194
+ var looksLikeReference = /* @__PURE__ */ __name((text2) => {
1195
+ const match = /^([a-z]+):\S+$/.exec(text2.trim());
1196
+ return match !== null && byPrefix.has(match[1]);
1197
+ }, "looksLikeReference");
1198
+
1199
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/providers.js
1200
+ var KINDS = ["messages", "mail", "notes", "documents", "meetings", "events", "crm"];
1201
+ var MESSENGER_OPENS = { chat: "messages list", message: "messages show", contact: "contacts show" };
1202
+ var PROVIDERS = [
1203
+ { name: "telegram", kind: "messages", aliases: ["tg"], command: "tg", opens: MESSENGER_OPENS },
1204
+ { name: "telegram-bot", kind: "messages", aliases: ["tg-bot"] },
1205
+ { name: "max", kind: "messages", aliases: [], command: "max", opens: MESSENGER_OPENS },
1206
+ { name: "max-bot", kind: "messages", aliases: [] },
1207
+ { name: "whatsapp", kind: "messages", aliases: ["wa"], command: "wa", opens: MESSENGER_OPENS },
1208
+ { name: "whatsapp-bot", kind: "messages", aliases: ["wa-bot"] },
1209
+ { name: "email", kind: "mail", aliases: [] },
1210
+ { name: "notes", kind: "notes", aliases: [] },
1211
+ { name: "local", kind: "notes", aliases: [] },
1212
+ { name: "obsidian", kind: "notes", aliases: [] },
1213
+ { name: "added", kind: "notes", aliases: [] },
1214
+ { name: "zoom", kind: "meetings", aliases: [] },
1215
+ // Google Meet has no tool of its own: its meetings are gcal's, since every meeting is on the calendar.
1216
+ { name: "google-meet", kind: "meetings", aliases: [], command: "gcal" },
1217
+ { name: "google-drive", kind: "documents", aliases: [] },
1218
+ // Its meetings come from the notes Telemost mails (`keeper@telemost.yandex.ru`), read by a mail rule.
1219
+ { name: "telemost", kind: "meetings", aliases: [] },
1220
+ // A phone export's records: its SMS and its calls in the one account the import names.
1221
+ { name: "phone", kind: "messages", kinds: ["messages", "events"], aliases: [], imported: true },
1222
+ // Any other import: a folder of notes, a CRM's export, a script's records, under `import:<what it is>`.
1223
+ { name: "import", kind: "documents", kinds: ["documents", "messages", "events"], aliases: [], imported: true }
1224
+ ];
1225
+ var LABELS = {
1226
+ telegram: "Telegram",
1227
+ "telegram-bot": "Telegram bot",
1228
+ max: "MAX",
1229
+ "max-bot": "MAX bot",
1230
+ whatsapp: "WhatsApp",
1231
+ "whatsapp-bot": "WhatsApp bot",
1232
+ "google-drive": "Google Drive",
1233
+ "google-meet": "Google Meet",
1234
+ added: "added by hand",
1235
+ email: "mail",
1236
+ telemost: "Telemost"
1237
+ };
1238
+ var providerLabel = /* @__PURE__ */ __name((provider) => LABELS[provider] ?? provider, "providerLabel");
1239
+ var FOLDER_PROVIDERS = ["local", "obsidian", "folder"];
1240
+ var isFolderProvider = /* @__PURE__ */ __name((provider) => FOLDER_PROVIDERS.includes(provider), "isFolderProvider");
1241
+ var folderProviderSql = /* @__PURE__ */ __name((column = "provider") => `${column} IN (${FOLDER_PROVIDERS.map((name) => `'${name}'`).join(", ")})`, "folderProviderSql");
1242
+ var folderProviderOf = /* @__PURE__ */ __name((format) => format === "markdown" ? "local" : "obsidian", "folderProviderOf");
1243
+ var documentAccountProviders = /* @__PURE__ */ __name(() => registry.filter((entry) => entry.kind === "documents" && entry.imported !== true).map(({ name }) => name), "documentAccountProviders");
1244
+ var isDocumentAccountProvider = /* @__PURE__ */ __name((provider) => typeof provider === "string" && documentAccountProviders().includes(provider), "isDocumentAccountProvider");
1245
+ var documentAccountProvidersSql = /* @__PURE__ */ __name(() => documentAccountProviders().map((name) => `'${name}'`).join(", ") || "NULL", "documentAccountProvidersSql");
1246
+ var ADDED_PROVIDER = "added";
1247
+ var ADDED_ACCOUNT = "owner";
1248
+ var notAdded = `d.account_id NOT IN (SELECT id FROM accounts WHERE provider = '${ADDED_PROVIDER}')`;
1249
+ var filesAccountSql = /* @__PURE__ */ __name((column = "provider") => `${column} IN (${[...FOLDER_PROVIDERS, ...documentAccountProviders(), ADDED_PROVIDER].map((name) => `'${name}'`).join(", ")})`, "filesAccountSql");
1250
+ var INTERNAL_NOTES = "internal";
1251
+ var UNKNOWN_PROVIDER = "unknown provider \u2014 run its CLI once";
1252
+ var WORD = /^[a-z0-9][a-z0-9_-]*$/;
1253
+ var invalid = /* @__PURE__ */ __name((message) => {
1254
+ throw new CliError("validation_error", message);
1255
+ }, "invalid");
1256
+ 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");
1257
+ var OPEN_KINDS = new Set(REF_KINDS.map(({ type }) => type).filter((type) => type !== "entity"));
1258
+ var COMMAND_WORDS = /^[a-z0-9][a-z0-9_-]*( [a-z0-9][a-z0-9_-]*)*$/;
1259
+ var opensOf = /* @__PURE__ */ __name((value, named) => {
1260
+ if (typeof value !== "object" || value === null || Array.isArray(value))
1261
+ return invalid(`provider ${named}'s opens maps a kind of reference to a command`);
1262
+ const known = Object.entries(value).filter(([kind2]) => OPEN_KINDS.has(kind2));
1263
+ for (const [kind2, command] of known)
1264
+ if (typeof command !== "string" || !COMMAND_WORDS.test(command))
1265
+ invalid(`provider ${named} opens a ${kind2} with command words, not ${JSON.stringify(command)}`);
1266
+ return Object.fromEntries(known);
1267
+ }, "opensOf");
1268
+ var providerEntryOf = /* @__PURE__ */ __name((value) => {
1269
+ if (typeof value !== "object" || value === null || Array.isArray(value))
1270
+ return invalid("a provider entry is an object");
1271
+ const { name, kind: kind2, kinds, aliases = [], command, opens, imported } = value;
1272
+ const named = wordOf(name, "a provider's name");
1273
+ const isKindWord = /* @__PURE__ */ __name((one) => typeof one === "string" && KINDS.includes(one), "isKindWord");
1274
+ const given = kinds === void 0 ? [kind2] : Array.isArray(kinds) && kinds.length > 0 ? kinds : [void 0];
1275
+ for (const one of given)
1276
+ if (!isKindWord(one))
1277
+ invalid(`provider ${named}'s kind is one of ${KINDS.join(", ")} \u2014 not ${JSON.stringify(one)}`);
1278
+ const list = [...new Set(given)];
1279
+ if (kind2 !== void 0 && kind2 !== list[0])
1280
+ invalid(`provider ${named}'s kind is the first of its kinds`);
1281
+ if (!Array.isArray(aliases))
1282
+ invalid(`provider ${named}'s aliases are a list`);
1283
+ if (imported !== void 0 && typeof imported !== "boolean")
1284
+ invalid(`provider ${named}'s imported is true or false`);
1285
+ return {
1286
+ name: named,
1287
+ kind: list[0],
1288
+ ...list.length > 1 ? { kinds: list } : {},
1289
+ ...imported === true ? { imported: true } : {},
1290
+ aliases: [...new Set(aliases.map((alias) => wordOf(alias, `an alias of ${named}`)))],
1291
+ ...command === void 0 ? {} : { command: wordOf(command, `the command of ${named}`) },
1292
+ ...opens === void 0 ? {} : { opens: opensOf(opens, named) }
1293
+ };
1294
+ }, "providerEntryOf");
1295
+ var kindsOfEntry = /* @__PURE__ */ __name((entry) => entry.kinds ?? [entry.kind], "kindsOfEntry");
1296
+ var describe = /* @__PURE__ */ __name((entry) => `${entry.name} (${kindsOfEntry(entry).join(", ")}${entry.command ? `, from ${entry.command}` : ""})`, "describe");
1297
+ var unitedKinds = /* @__PURE__ */ __name((known, entry) => [
1298
+ .../* @__PURE__ */ new Set([...known, ...entry])
1299
+ ], "unitedKinds");
1300
+ var wordsOf = /* @__PURE__ */ __name(({ name, aliases }) => [name, ...aliases], "wordsOf");
1301
+ var joined = /* @__PURE__ */ __name((known, entry) => {
1302
+ const same = known.find(({ name }) => name === entry.name);
1303
+ const kinds = same ? unitedKinds(kindsOfEntry(same), kindsOfEntry(entry)) : kindsOfEntry(entry);
1304
+ if (same && same.kind !== entry.kind)
1305
+ invalid(`two provider entries disagree on the kind: ${describe(same)} and ${describe(entry)}`);
1306
+ if (same && entry.imported === true && same.imported !== true)
1307
+ invalid(`provider ${entry.name} is synced, so an entry cannot make it import-only`);
1308
+ const merged = same ? {
1309
+ ...same,
1310
+ ...kinds.length > 1 ? { kinds } : {},
1311
+ aliases: [.../* @__PURE__ */ new Set([...same.aliases, ...entry.aliases])],
1312
+ ...entry.command ? { command: entry.command } : {},
1313
+ ...entry.opens ? { opens: { ...same.opens, ...entry.opens } } : {}
1314
+ } : entry;
1315
+ const others = known.filter((one) => one !== same);
1316
+ for (const word of wordsOf(merged)) {
1317
+ const owner = others.find((one) => wordsOf(one).includes(word));
1318
+ if (owner)
1319
+ invalid(`"${word}" names two providers: ${describe(owner)} and ${describe(merged)}`);
1320
+ }
1321
+ return same ? known.map((one) => one === same ? merged : one) : [...known, merged];
1322
+ }, "joined");
1323
+ var registry = PROVIDERS;
1324
+ var providers = /* @__PURE__ */ __name(() => registry, "providers");
1325
+ var useStoredProviders = /* @__PURE__ */ __name((entries) => {
1326
+ const left = [];
1327
+ registry = entries.reduce((known, entry) => {
1328
+ try {
1329
+ return joined(known, providerEntryOf(entry));
1330
+ } catch (error) {
1331
+ if (!(error instanceof CliError))
1332
+ throw error;
1333
+ left.push(entry);
1334
+ return known;
1335
+ }
1336
+ }, PROVIDERS);
1337
+ return left;
1338
+ }, "useStoredProviders");
1339
+ var addProvider = /* @__PURE__ */ __name((entry) => {
1340
+ registry = joined(registry, providerEntryOf(entry));
1341
+ }, "addProvider");
1342
+ var isKind = /* @__PURE__ */ __name((word) => KINDS.includes(word.toLowerCase()), "isKind");
1343
+ var providerNamed = /* @__PURE__ */ __name((word) => {
1344
+ const wanted = word.toLowerCase();
1345
+ return registry.find((entry) => wordsOf(entry).includes(wanted));
1346
+ }, "providerNamed");
1347
+ var kindIn = /* @__PURE__ */ __name((provider) => isFolderProvider(provider) ? "notes" : registry.find(({ name }) => name === provider)?.kind, "kindIn");
1348
+ var kindsIn = /* @__PURE__ */ __name((provider) => {
1349
+ if (isFolderProvider(provider))
1350
+ return ["notes"];
1351
+ const entry = registry.find(({ name }) => name === provider);
1352
+ if (!entry)
1353
+ return [];
1354
+ return entry.imported ? unitedKinds(kindsOfEntry(entry), ["documents"]) : kindsOfEntry(entry);
1355
+ }, "kindsIn");
1356
+ var importedOf = /* @__PURE__ */ __name((entry, held) => {
1357
+ const builtIn = PROVIDERS.find(({ name }) => name === entry.name);
1358
+ if (builtIn) {
1359
+ if (entry.imported === true && builtIn.imported !== true)
1360
+ invalid(`provider ${entry.name} is synced, so an entry cannot make it import-only`);
1361
+ return builtIn.imported === true;
1362
+ }
1363
+ if (held === void 0)
1364
+ return entry.imported === true;
1365
+ if (entry.imported === true && held.imported !== true)
1366
+ invalid(`provider ${entry.name} was registered without imported: an entry cannot make it import-only later`);
1367
+ return held.imported === true;
1368
+ }, "importedOf");
1369
+ var isImportedProvider = /* @__PURE__ */ __name((provider) => registry.find(({ name }) => name === provider)?.imported === true, "isImportedProvider");
1370
+ var holdsKind = /* @__PURE__ */ __name((provider, kind2) => kindsIn(provider).includes(kind2), "holdsKind");
1371
+ var holdsKindOf = /* @__PURE__ */ __name((provider, kind2) => kindIn(provider) === void 0 ? kind2 === "messages" : holdsKind(provider, kind2), "holdsKindOf");
1372
+ var kindOf = /* @__PURE__ */ __name((provider) => kindIn(provider) ?? "messages", "kindOf");
1373
+
1374
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/deals.js
1375
+ var DEAL_KINDS = ["deal", "lead"];
1376
+ var DEAL_STATUSES = ["open", "won", "lost"];
1377
+ var STAGE_OUTCOMES = DEAL_STATUSES;
1378
+ var DEAL_ROLES = ["owner", "contact", "decision-maker", "influencer"];
1379
+ var dealLine = /* @__PURE__ */ __name((deal) => {
1380
+ const money = deal.amount === null || deal.currency === null ? "" : `, ${moneyLabel(deal.amount, deal.currency)}`;
1381
+ return `${deal.title} \xB7 ${deal.stage}${money}${deal.status === "open" ? "" : ` (${deal.status})`}`;
1382
+ }, "dealLine");
1383
+
1384
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/orders.js
1385
+ var ORDER_STATUSES = ["placed", "shipped", "delivered", "cancelled", "returned"];
1386
+ var ORDER_PURPOSES = ["personal", "business", "client", "other"];
1387
+ var orderLine = /* @__PURE__ */ __name((order) => {
1388
+ const party = order.direction === "sale" && order.customerName !== null ? `to ${order.customerName}` : order.supplierName;
1389
+ const money = order.total === null || order.currency === null ? "" : `, ${moneyLabel(order.total, order.currency)}`;
1390
+ const notes2 = [order.status, order.review === "confirmed" ? null : order.review].filter(Boolean).join(", ");
1391
+ return `${order.number ?? `#${order.id}`} \xB7 ${party}${money} (${notes2})`;
1392
+ }, "orderLine");
1393
+ var orderTitle = /* @__PURE__ */ __name((order) => `Order ${orderLine(order)}`, "orderTitle");
1394
+
1395
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/relations.js
1396
+ var ORGANIZATION_ROLES = [
1397
+ "employee",
1398
+ "contractor",
1399
+ "founder",
1400
+ "owner",
1401
+ "manager",
1402
+ "adviser",
1403
+ "contact"
1404
+ ];
1405
+ var PROJECT_ROLES = ["owner", "manager", "contributor", "client-contact", "approver"];
1406
+ var CONTRACT_ROLES = ["customer", "supplier", "signatory", "guarantor"];
1407
+ var RELATED_ROLES = ["colleague", "adviser", "investor", "mentor", "family", "friend"];
1408
+ var ENGAGEMENT_LEVELS = ["none", "low", "medium", "high"];
1409
+ var isEngagement = /* @__PURE__ */ __name((value) => typeof value === "string" && ENGAGEMENT_LEVELS.includes(value), "isEngagement");
1410
+ var checkEngagement = /* @__PURE__ */ __name((kind2, from, to, level) => {
1411
+ if (kind2 !== "member-of" || from !== "person" || to !== "project")
1412
+ throw new CliError("validation_error", "an engagement level is set only on a person's member-of a project", {
1413
+ reason: "relationship.engagement-ends"
1414
+ });
1415
+ if (!isEngagement(level))
1416
+ throw new CliError("validation_error", `an engagement level is one of ${ENGAGEMENT_LEVELS.join(", ")}`, {
1417
+ reason: "relationship.engagement-unknown"
1418
+ });
1419
+ return level;
1420
+ }, "checkEngagement");
1421
+ var RELATIONS = {
1422
+ "member-of": {
1423
+ from: ["person", "organization", "project", "chat", "email_thread"],
1424
+ to: ["organization", "project"],
1425
+ roles: { to: { organization: ORGANIZATION_ROLES, project: PROJECT_ROLES } }
1426
+ },
1427
+ "reports-to": { from: ["person"], to: ["person"], inverse: "manages" },
1428
+ "customer-of": { from: ["person", "organization"], to: ["organization"], inverse: "supplier of" },
1429
+ "partner-of": { from: ["organization"], to: ["organization"], symmetric: true },
1430
+ "related-to": {
1431
+ from: ["person", "organization", "project", "task", "deal", "lead", "contract"],
1432
+ to: ["person", "organization", "project", "task"],
1433
+ roles: { from: { deal: DEAL_ROLES, lead: DEAL_ROLES, contract: CONTRACT_ROLES } }
1434
+ }
1435
+ };
1436
+ var RELATION_KINDS = Object.keys(RELATIONS);
1437
+ var specOf = /* @__PURE__ */ __name((kind2) => Object.hasOwn(RELATIONS, kind2) ? RELATIONS[kind2] : void 0, "specOf");
1438
+ var isRelationKind = /* @__PURE__ */ __name((kind2) => specOf(kind2) !== void 0, "isRelationKind");
1439
+ var memberOnly = /* @__PURE__ */ __name((type) => type === "chat" || type === "email_thread", "memberOnly");
1440
+ var partyOnly = /* @__PURE__ */ __name((from, to) => from === "contract" && to !== "person" && to !== "organization", "partyOnly");
1441
+ var checkEnds = /* @__PURE__ */ __name((kind2, from, to) => {
1442
+ const spec = specOf(kind2);
1443
+ if (!spec)
1444
+ throw new CliError("validation_error", `a relationship's kind is one of ${RELATION_KINDS.join(", ")}`);
1445
+ if (memberOnly(from) && (kind2 !== "member-of" || to !== "project"))
1446
+ throw new CliError("validation_error", `a ${from === "chat" ? "chat" : "mail thread"} is related only as member-of a project`);
1447
+ if (partyOnly(from, to))
1448
+ throw new CliError("validation_error", "a contract is related only to a person or an organization");
1449
+ if (!spec.from.includes(from) || !spec.to.includes(to))
1450
+ throw new CliError("validation_error", `${kind2} joins ${spec.from.join(", ")} to ${spec.to.join(", ")}, not ${from} to ${to}`);
1451
+ return spec;
1452
+ }, "checkEnds");
1453
+ var isParty = /* @__PURE__ */ __name((type) => type === "person" || type === "organization", "isParty");
1454
+ var rolesOf = /* @__PURE__ */ __name((kind2, from, to) => {
1455
+ const spec = specOf(kind2);
1456
+ if (kind2 === "member-of" && from !== "person")
1457
+ return void 0;
1458
+ return spec?.roles?.from?.[from] ?? spec?.roles?.to?.[to];
1459
+ }, "rolesOf");
1460
+ var ROLE_LISTS = {
1461
+ organization: ORGANIZATION_ROLES,
1462
+ project: PROJECT_ROLES,
1463
+ deal: DEAL_ROLES,
1464
+ contract: CONTRACT_ROLES,
1465
+ related: RELATED_ROLES
1466
+ };
1467
+ var roleListOf = /* @__PURE__ */ __name((kind2, from, to) => {
1468
+ if (kind2 === "related-to" && isParty(from) && isParty(to))
1469
+ return "related";
1470
+ const roles = rolesOf(kind2, from, to);
1471
+ return Object.keys(ROLE_LISTS).find((list) => ROLE_LISTS[list] === roles);
1472
+ }, "roleListOf");
1473
+ var checkRole = /* @__PURE__ */ __name((kind2, from, to, role, extra = []) => {
1474
+ const roles = rolesOf(kind2, from, to)?.concat(extra);
1475
+ if (roles && !roles.includes(role))
1476
+ throw new CliError("validation_error", `a ${from}'s role on ${kind2} ${to} is one of ${roles.join(", ")}`, {
1477
+ reason: "relationship.role-unknown"
1478
+ });
1479
+ return role;
1480
+ }, "checkRole");
1481
+ var isSymmetric = /* @__PURE__ */ __name((kind2) => specOf(kind2)?.symmetric === true, "isSymmetric");
1482
+ var inverseOf = /* @__PURE__ */ __name((kind2) => specOf(kind2)?.symmetric ? kind2 : specOf(kind2)?.inverse ?? null, "inverseOf");
1483
+ var STANDINGS = ["confirmed", "reported", "proposed", "ended"];
1484
+ var standingOf = /* @__PURE__ */ __name((link, now) => {
1485
+ if (link.endsAt != null && link.endsAt <= now)
1486
+ return "ended";
1487
+ if (link.confirmed)
1488
+ return "confirmed";
1489
+ if (link.deletedAt != null)
1490
+ return "ended";
1491
+ return link.accountId != null ? "reported" : "proposed";
1492
+ }, "standingOf");
1493
+ var isUsable = /* @__PURE__ */ __name((standing) => standing === "confirmed" || standing === "reported", "isUsable");
1494
+ var KEYED = "kind IN ('member-of', 'related-to', 'reports-to', 'customer-of', 'partner-of') AND to_id IS NOT NULL";
1495
+ var notOverriddenSql = /* @__PURE__ */ __name((alias) => `NOT EXISTS (SELECT 1 FROM links override WHERE ${KEYED} AND override.kind = ${alias}.kind AND override.from_type = ${alias}.from_type AND override.from_id = ${alias}.from_id AND override.to_type = ${alias}.to_type AND override.to_id = ${alias}.to_id AND json_extract(override.metadata, '$.overrides') = ${alias}.id)`, "notOverriddenSql");
1496
+ var usableLinkSql = /* @__PURE__ */ __name((alias, now) => `(${alias}.confirmed = 1 OR (${alias}.account_id IS NOT NULL AND ${alias}.deleted_at IS NULL))` + (now === void 0 ? "" : ` AND (${alias}.ends_at IS NULL OR ${alias}.ends_at > ${Math.trunc(now)})`), "usableLinkSql");
1497
+
1498
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/crm.js
1499
+ var CRM_KINDS = ["organization", "person", "deal", "lead"];
1500
+ var CRM_ACTIVITY_KINDS = ["call", "email", "meeting", "todo", "task", "comment", "other"];
1501
+ var isCrmUserId = /* @__PURE__ */ __name((id2) => /^\d{1,20}$/.test(id2), "isCrmUserId");
1502
+ var normalCrmUserId = /* @__PURE__ */ __name((id2) => {
1503
+ const text2 = id2.trim();
1504
+ return /^\d+$/.test(text2) ? text2.replace(/^0+(?=\d)/, "") : text2;
1505
+ }, "normalCrmUserId");
1506
+ var isItemKind = /* @__PURE__ */ __name((kind2) => kind2 === "deal" || kind2 === "lead", "isItemKind");
1507
+
1508
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/store/sqlite/link-source.js
1509
+ var REPORTER_SQL = "(SELECT provider || ':' || external_id FROM accounts r WHERE r.id = links.account_id) AS reporter";
1510
+ var sourceOf = /* @__PURE__ */ __name((database, row, metadata) => {
1511
+ const reporter = row.account_id == null ? void 0 : "reporter" in row ? row.reporter : database.prepare("SELECT provider || ':' || external_id AS key FROM accounts WHERE id = ?").get(Number(row.account_id))?.key;
1512
+ return {
1513
+ ...typeof reporter === "string" ? { account: reporter } : {},
1514
+ ...typeof metadata.derived === "string" ? { derived: metadata.derived } : {}
1515
+ };
1516
+ }, "sourceOf");
1517
+
1518
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/store/sqlite/link-kinds.js
1519
+ var LINK_KINDS = [
1520
+ "links-to",
1521
+ "blocked-by",
1522
+ "follow-up-of",
1523
+ "about",
1524
+ "member-of",
1525
+ "labelled",
1526
+ "answered-by",
1527
+ "evidence",
1528
+ "created-from",
1529
+ "duplicate-of",
1530
+ "related-to",
1531
+ "reports-to",
1532
+ "customer-of",
1533
+ "partner-of",
1534
+ "assigned-to",
1535
+ "attached"
1536
+ ];
1537
+ var LINK_ORIGINS = ["file", "owner", "suggested", "message"];
1538
+ var LINK_SOURCES = [...LINK_ORIGINS, "calendar", "meeting"];
1539
+ var linkKind = /* @__PURE__ */ __name((kind2) => `'${kind2}'`, "linkKind");
1540
+ var COUNTERPART_ROLE = "counterpart";
1541
+
1542
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/search/query.js
1543
+ var isBotProvider = /* @__PURE__ */ __name((provider) => provider.endsWith("-bot"), "isBotProvider");
1544
+ 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");
1545
+ var fail = /* @__PURE__ */ __name((message) => {
1546
+ throw new CliError("validation_error", message);
1547
+ }, "fail");
1548
+ var sourceOf2 = /* @__PURE__ */ __name((name, value, providers2) => {
1549
+ const sources = [...providers2, "personal", "bots", "all"];
1550
+ const source = value.toLowerCase();
1551
+ if (sources.includes(source))
1552
+ return source;
1553
+ if (source === "mail")
1554
+ return "email";
1555
+ if (source === "messages")
1556
+ return source;
1557
+ if (isKind(source))
1558
+ fail(`${name}${source} names ${source}, which a message search does not read \u2014 search ${source === "meetings" || source === "events" ? `all --source ${source}` : "notes"} does`);
1559
+ const named = providerNamed(source);
1560
+ if (named && providers2.includes(named.name))
1561
+ return named.name;
1562
+ return fail(`${name} takes ${[...sources, "messages", "mail"].join(", ")} \u2014 not "${value}"`);
1563
+ }, "sourceOf");
1564
+
1565
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/search/account-list.js
1566
+ var ACCOUNT_GROUPS = "accountGroups";
1567
+ var ACCOUNT_GROUPS_SETTING = "account_groups";
1568
+ var GROUP_NAME = /^[a-z0-9][a-z0-9_-]*$/i;
1569
+ var fail2 = /* @__PURE__ */ __name((message) => {
1570
+ throw new CliError("validation_error", message);
1571
+ }, "fail");
1572
+ var isAccountList = /* @__PURE__ */ __name((value) => value.includes(",") || value.includes(":"), "isAccountList");
1573
+ var itemsOf = /* @__PURE__ */ __name((value) => {
1574
+ const items = value.split(",").map((item) => item.trim());
1575
+ if (items.some((item) => item === ""))
1576
+ fail2(`"${value}" has an empty entry \u2014 separate accounts with one comma`);
1577
+ return items;
1578
+ }, "itemsOf");
1579
+ var isGroupName = /* @__PURE__ */ __name((name) => GROUP_NAME.test(name), "isGroupName");
1580
+ var groupName = /* @__PURE__ */ __name((name) => isGroupName(name) ? name : fail2(`a group name is letters, digits, - and _ \u2014 not "${name}"`), "groupName");
1581
+ 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");
1582
+ var describe2 = /* @__PURE__ */ __name((accounts) => accounts.map(({ provider, account, name }) => `${provider}:${account}${name ? ` (${name})` : ""}`).join(", "), "describe");
1583
+ var listedHolds = /* @__PURE__ */ __name((account, kind2) => (account.kinds ?? (account.kind === void 0 ? [] : [account.kind])).includes(kind2), "listedHolds");
1584
+ var kindHere = /* @__PURE__ */ __name((provider, running) => provider === running.provider ? kindOf(provider) : kindIn(provider), "kindHere");
1585
+ var kindsOfHere = /* @__PURE__ */ __name((provider, running) => {
1586
+ const kinds = kindsIn(provider);
1587
+ return { kind: kindHere(provider, running), ...kinds.length > 1 ? { kinds } : {} };
1588
+ }, "kindsOfHere");
1589
+ var heldOf = /* @__PURE__ */ __name((stored, running) => [
1590
+ ...stored.filter(({ provider }) => kindIn(provider) !== "notes" && !isDocumentAccountProvider(provider)).map(({ provider, account, name }) => ({ provider, account, name, ...kindsOfHere(provider, running) })),
1591
+ { provider: "notes", account: INTERNAL_NOTES, name: null, kind: "notes" },
1592
+ ...stored.filter(({ provider }) => isFolderProvider(provider)).map(({ id: id2, name, provider, account }) => ({
1593
+ provider: "notes",
1594
+ account: String(id2),
1595
+ name,
1596
+ kind: "notes",
1597
+ stored: { provider, account }
1598
+ })),
1599
+ ...stored.filter(({ provider }) => isDocumentAccountProvider(provider) || provider === ADDED_PROVIDER).map(({ id: id2, provider, account, name }) => ({
1600
+ provider: "notes",
1601
+ account: String(id2),
1602
+ name,
1603
+ kind: "notes",
1604
+ stored: { provider, account }
1605
+ }))
1606
+ ], "heldOf");
1607
+ var storedAs = /* @__PURE__ */ __name((held, key) => held.filter(({ stored }) => stored?.provider === key.provider && (key.account === "" || stored.account === key.account)), "storedAs");
1608
+ var registry2 = /* @__PURE__ */ __name(() => providers().map(({ name, aliases }) => aliases.length ? `${name} (${aliases.join(", ")})` : name).join(", "), "registry");
1609
+ var providerOf = /* @__PURE__ */ __name((prefix, held, { running, profiles }) => {
1610
+ const wanted = prefix.toLowerCase();
1611
+ if (wanted === running.command?.toLowerCase())
1612
+ return running.provider;
1613
+ const providers2 = [...new Set(held.map(({ provider }) => provider))];
1614
+ if (providers2.includes(wanted) || isDocumentAccountProvider(wanted))
1615
+ return wanted;
1616
+ const named = providerNamed(wanted);
1617
+ if (named)
1618
+ return named.name;
1619
+ const recorded = Object.values(profiles[wanted] ?? {})[0];
1620
+ if (recorded)
1621
+ return recorded.provider;
1622
+ return fail2(`${prefix} is not a provider \u2014 they are ${registry2()}; the store holds ${providers2.join(", ")}`);
1623
+ }, "providerOf");
1624
+ var profilesOf = /* @__PURE__ */ __name((provider, profiles) => Object.values(profiles).flatMap((named) => Object.entries(named).filter(([, key]) => key.provider === provider)), "profilesOf");
1625
+ var accountOf = /* @__PURE__ */ __name((prefix, ref, held, context) => {
1626
+ const provider = providerOf(prefix, held, context);
1627
+ if (isDocumentAccountProvider(provider) && !context.profiles[prefix.toLowerCase()]?.[ref]) {
1628
+ const stored = storedAs(held, { provider, account: ref })[0];
1629
+ if (stored)
1630
+ return stored;
1631
+ }
1632
+ const folder = isFolderProvider(provider);
1633
+ const ofProvider = folder ? storedAs(held, { provider, account: "" }) : held.filter((one) => one.provider === provider);
1634
+ const byId = ofProvider.find(({ account, stored }) => account === ref || account === ref.toLowerCase() || folder && stored?.account === ref.toUpperCase());
1635
+ if (byId)
1636
+ return byId;
1637
+ const keyed = /* @__PURE__ */ __name((key) => ofProvider.find(({ account }) => account === key.account) ?? {
1638
+ ...key,
1639
+ name: null,
1640
+ ...kindsOfHere(key.provider, context.running)
1641
+ }, "keyed");
1642
+ const recorded = context.profiles[prefix.toLowerCase()]?.[ref];
1643
+ if (recorded && isFolderProvider(recorded.provider)) {
1644
+ const folder2 = held.find((one) => one.provider === "notes" && one.name === recorded.account);
1645
+ if (folder2)
1646
+ return folder2;
1647
+ return fail2(`no stored folder for ${prefix}:${ref}; sync that profile first`);
1648
+ }
1649
+ if (recorded && isDocumentAccountProvider(recorded.provider)) {
1650
+ const account = storedAs(held, recorded)[0];
1651
+ if (account)
1652
+ return account;
1653
+ return fail2(`no stored documents for ${prefix}:${ref}; sync that profile first`);
1654
+ }
1655
+ if (recorded)
1656
+ return keyed(recorded);
1657
+ const byProfile = [
1658
+ ...new Map(profilesOf(provider, context.profiles).filter(([name]) => name === ref).map(([, key]) => [key.account, key])).values()
1659
+ ];
1660
+ if (byProfile.length === 1)
1661
+ return keyed(byProfile[0]);
1662
+ const byName = ofProvider.filter(({ name }) => name?.toLowerCase() === ref.toLowerCase());
1663
+ if (byName.length === 1)
1664
+ return byName[0];
1665
+ if (byName.length > 1 || byProfile.length > 1)
1666
+ fail2(`${provider}:${ref} names more than one account \u2014 use the id: ${describe2(ofProvider)}`);
1667
+ const names = profilesOf(provider, context.profiles).map(([name]) => name);
1668
+ return fail2(`no ${provider} account "${ref}" \u2014 the store holds ${describe2(ofProvider) || "none"}` + (names.length ? `; profiles: ${[...new Set(names)].join(", ")}` : ""));
1669
+ }, "accountOf");
1670
+ var accountsOfWord = /* @__PURE__ */ __name((word, held, context) => {
1671
+ const wanted = word.toLowerCase();
1672
+ if (wanted === "all")
1673
+ return [...held];
1674
+ if (wanted === "personal" || wanted === "bots")
1675
+ return held.filter((one) => listedHolds(one, "messages") && isBotProvider(one.provider) === (wanted === "bots"));
1676
+ if (wanted === "documents")
1677
+ return held.filter((one) => listedHolds(one, "documents") || isDocumentAccount(one));
1678
+ if (isKind(wanted))
1679
+ return held.filter((one) => listedHolds(one, wanted));
1680
+ const recorded = context.profiles[wanted];
1681
+ if (recorded && Object.values(recorded).every((key) => isFolderProvider(key.provider) || isDocumentAccountProvider(key.provider)))
1682
+ return Object.keys(recorded).map((profile) => accountOf(word, profile, held, context));
1683
+ const provider = providerOf(word, held, context);
1684
+ if (isDocumentAccountProvider(provider) || isFolderProvider(provider))
1685
+ return storedAs(held, { provider, account: "" });
1686
+ return held.filter((one) => one.provider === provider);
1687
+ }, "accountsOfWord");
1688
+ var isDocumentAccount = /* @__PURE__ */ __name(({ stored }) => stored !== void 0 && isDocumentAccountProvider(stored.provider), "isDocumentAccount");
1689
+ var choices = /* @__PURE__ */ __name((held) => {
1690
+ const kinds = held.flatMap((one) => one.kinds ?? (one.kind ? [one.kind] : []));
1691
+ const messengers = held.filter((one) => listedHolds(one, "messages"));
1692
+ const providers2 = held.flatMap(({ stored, provider }) => stored?.provider === ADDED_PROVIDER ? [] : [stored?.provider ?? provider]);
1693
+ return [
1694
+ .../* @__PURE__ */ new Set([
1695
+ "all",
1696
+ ...messengers.some((one) => !isBotProvider(one.provider)) ? ["personal"] : [],
1697
+ ...messengers.some((one) => isBotProvider(one.provider)) ? ["bots"] : [],
1698
+ ...kinds,
1699
+ ...held.some(isDocumentAccount) ? ["documents"] : [],
1700
+ ...providers2
1701
+ ])
1702
+ ].join(", ");
1703
+ }, "choices");
1704
+ var keyOf = /* @__PURE__ */ __name(({ provider, account }) => `${provider}\0${account}`, "keyOf");
1705
+ var sourceOf3 = /* @__PURE__ */ __name(({ provider, account }) => `${provider}:${account}`, "sourceOf");
1706
+ var sameAs = /* @__PURE__ */ __name((key) => (one) => one.provider === key.provider && one.account === key.account, "sameAs");
1707
+ var entriesOfList = /* @__PURE__ */ __name((value, context) => {
1708
+ const held = heldOf(context.held, context.running);
1709
+ const entries = [];
1710
+ const entry = /* @__PURE__ */ __name((item, group) => {
1711
+ const colon = item.indexOf(":");
1712
+ if (colon === -1) {
1713
+ try {
1714
+ const accounts = accountsOfWord(item, held, context);
1715
+ entries.push({ entry: item, accounts, ...accounts.length === 0 && !group ? { holds: choices(held) } : {} });
1716
+ } catch (error) {
1717
+ if (!group || !(error instanceof CliError))
1718
+ throw error;
1719
+ fail2(`"${item}" in group ${group}: ${error.message}`);
1720
+ }
1721
+ return;
1722
+ }
1723
+ const prefix = item.slice(0, colon);
1724
+ const ref = item.slice(colon + 1).trim();
1725
+ if (ref === "")
1726
+ fail2(`"${item}" names no account after the colon`);
1727
+ if (prefix.toLowerCase() === "group") {
1728
+ if (group)
1729
+ fail2(`group ${group} lists another group \u2014 a group lists accounts`);
1730
+ const members = context.groups[ref];
1731
+ if (!members) {
1732
+ const known = Object.keys(context.groups);
1733
+ fail2(`no account group "${ref}" \u2014 ${known.length ? `there are ${known.join(", ")}` : "none saved yet"}; \`config set ${ACCOUNT_GROUPS_SETTING}.${ref} <accounts>\` saves one`);
1734
+ }
1735
+ for (const member of members)
1736
+ entry(member, ref);
1737
+ return;
1738
+ }
1739
+ entries.push({ entry: item, accounts: [accountOf(prefix, ref, held, context)] });
1740
+ }, "entry");
1741
+ for (const item of itemsOf(value))
1742
+ entry(item);
1743
+ const { only } = context;
1744
+ return entries.map(({ entry: entry2, accounts, holds }) => ({
1745
+ entry: entry2,
1746
+ ...holds === void 0 ? {} : { holds },
1747
+ accounts: accounts.filter((one) => only === void 0 || only.has(keyOf(one))).map(({ provider, account, kind: kind2, kinds }) => ({
1748
+ provider,
1749
+ account,
1750
+ kind: kind2,
1751
+ ...kinds === void 0 ? {} : { kinds }
1752
+ }))
1753
+ }));
1754
+ }, "entriesOfList");
1755
+ var accountsOfList = /* @__PURE__ */ __name((value, context) => {
1756
+ const chosen = /* @__PURE__ */ new Map();
1757
+ for (const { accounts } of entriesOfList(value, context))
1758
+ for (const one of accounts)
1759
+ if (!chosen.has(keyOf(one)))
1760
+ chosen.set(keyOf(one), one);
1761
+ return [...chosen.values()];
1762
+ }, "accountsOfList");
1763
+ var READS = {
1764
+ messages: "messenger messages \u2014 search messages reads them",
1765
+ mail: "a mailbox \u2014 memo search mail reads it",
1766
+ notes: "notes \u2014 search notes reads them",
1767
+ documents: "documents \u2014 search notes reads them",
1768
+ meetings: "meetings \u2014 search all reads them",
1769
+ events: "calendar events \u2014 no search reads them yet",
1770
+ crm: "CRM deals and leads \u2014 search all reads them"
1771
+ };
1772
+ var fitting = /* @__PURE__ */ __name((entries, kinds, what, reasonOf = (kind2) => READS[kind2], alsoFits = () => false) => {
1773
+ const chosen = /* @__PURE__ */ new Map();
1774
+ const skipped = [];
1775
+ for (const { entry, accounts } of entries) {
1776
+ const fits = accounts.filter((one) => kinds.some((kind2) => listedHolds(one, kind2)) || alsoFits(one));
1777
+ for (const { provider, account } of fits)
1778
+ if (!chosen.has(keyOf({ provider, account })))
1779
+ chosen.set(keyOf({ provider, account }), { provider, account });
1780
+ const known = accounts.filter(({ kind: kind2 }) => kind2 !== void 0);
1781
+ const unknown2 = accounts.filter((one) => one.kind === void 0 && !alsoFits(one));
1782
+ if (known.length)
1783
+ for (const { provider, account } of unknown2)
1784
+ skipped.push({ source: `${provider}:${account}`, code: "not_found", reason: UNKNOWN_PROVIDER });
1785
+ if (fits.length)
1786
+ continue;
1787
+ const other = known[0];
1788
+ skipped.push(other?.kind ? { source: entry, code: "validation_error", reason: reasonOf(other.kind) } : unknown2.length ? { source: entry, code: "not_found", reason: UNKNOWN_PROVIDER } : { source: entry, code: "not_found", reason: "no account in the store" });
1789
+ }
1790
+ if (chosen.size === 0) {
1791
+ const words = entries.length === 1 ? entries[0]?.holds : void 0;
1792
+ fail2(`--source names nothing ${what} reads: ${skipped.map(({ source, reason }) => `${source} (${reason})`).join(", ")}` + (words === void 0 ? "" : ` \u2014 the store holds ${words}`));
1793
+ }
1794
+ return { accounts: [...chosen.values()], skipped };
1795
+ }, "fitting");
1796
+
1797
+ // node_modules/.pnpm/@wirecat+cli-core@0.707.0_@wirecat+cli-base@0.124.0_commander@15.0.0_esbuild@0.28.2_typ_1ab7200af0919d16d129ae0ece32d37f/node_modules/@wirecat/cli-core/dist/domain/categories.js
1798
+ var CATEGORIES = ["client", "supplier", "partner", "employer"];
1799
+
1800
+ export {
1801
+ formatLocator,
1802
+ isLocator,
1803
+ parseLocator,
1804
+ SIMPLE_REFERENCES,
1805
+ formatReference,
1806
+ parseReference,
1807
+ canonicalReference,
1808
+ looksLikeReference,
1809
+ logAttributes,
1810
+ fromLogAttributes,
1811
+ snakeLogger,
1812
+ LOG_ATTRIBUTES,
1813
+ KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
1814
+ KEEP_STORE_RUNS_FOR_DAYS,
1815
+ RUNS_SIZE_LIMIT_MB,
1816
+ runsDirFor,
1817
+ startRun,
1818
+ runtime,
1819
+ newRunId,
1820
+ listRuns,
1821
+ findRun,
1822
+ readEvents,
1823
+ asOwnProcess,
1824
+ currentRun,
1825
+ inRun,
1826
+ runEvent,
1827
+ typedCommand,
1828
+ useAsProcessRun,
1829
+ processRun,
1830
+ enclosingTraceId,
1831
+ traceOf,
1832
+ childTrace,
1833
+ withAttempt,
1834
+ currentAttempt,
1835
+ providerLabel,
1836
+ isFolderProvider,
1837
+ folderProviderSql,
1838
+ folderProviderOf,
1839
+ documentAccountProviders,
1840
+ isDocumentAccountProvider,
1841
+ documentAccountProvidersSql,
1842
+ ADDED_PROVIDER,
1843
+ ADDED_ACCOUNT,
1844
+ notAdded,
1845
+ filesAccountSql,
1846
+ INTERNAL_NOTES,
1847
+ UNKNOWN_PROVIDER,
1848
+ providerEntryOf,
1849
+ kindsOfEntry,
1850
+ unitedKinds,
1851
+ providers,
1852
+ useStoredProviders,
1853
+ addProvider,
1854
+ isKind,
1855
+ providerNamed,
1856
+ kindIn,
1857
+ importedOf,
1858
+ isImportedProvider,
1859
+ holdsKind,
1860
+ holdsKindOf,
1861
+ CATEGORIES,
1862
+ parseDecimal,
1863
+ formatDecimal,
1864
+ groupDigits,
1865
+ currencyOf,
1866
+ scaleOf,
1867
+ minorUnits,
1868
+ signedMinorUnits,
1869
+ moneyOf,
1870
+ moneyLabel,
1871
+ quantityOf,
1872
+ lineUnits,
1873
+ DEAL_KINDS,
1874
+ DEAL_STATUSES,
1875
+ STAGE_OUTCOMES,
1876
+ DEAL_ROLES,
1877
+ dealLine,
1878
+ INVOICE_DIRECTIONS,
1879
+ INVOICE_STATUSES,
1880
+ MONEY_DIRECTIONS,
1881
+ FINANCE_REVIEWS,
1882
+ settledStatus,
1883
+ invoiceLine,
1884
+ paymentLine,
1885
+ invoiceTitle,
1886
+ paymentEntryTitle,
1887
+ ORDER_STATUSES,
1888
+ ORDER_PURPOSES,
1889
+ orderLine,
1890
+ orderTitle,
1891
+ isEngagement,
1892
+ checkEngagement,
1893
+ RELATION_KINDS,
1894
+ isRelationKind,
1895
+ checkEnds,
1896
+ rolesOf,
1897
+ ROLE_LISTS,
1898
+ roleListOf,
1899
+ checkRole,
1900
+ isSymmetric,
1901
+ inverseOf,
1902
+ STANDINGS,
1903
+ standingOf,
1904
+ isUsable,
1905
+ KEYED,
1906
+ notOverriddenSql,
1907
+ usableLinkSql,
1908
+ TASK_KINDS,
1909
+ TASK_STATES,
1910
+ CLOSED_STATES,
1911
+ TASK_ORIGINS,
1912
+ TASK_VERDICTS,
1913
+ isClosedState,
1914
+ PRIORITY_LABELS,
1915
+ priorityLabel,
1916
+ priorityBand,
1917
+ legacyPriority,
1918
+ checkedScore,
1919
+ priorityOf,
1920
+ priorityOption,
1921
+ createTaskService,
1922
+ matches,
1923
+ SOURCE_REVIEW_KIND,
1924
+ SOURCE_REVIEW_CAUSES,
1925
+ ERASED_TEXT,
1926
+ severity,
1927
+ graver,
1928
+ text,
1929
+ id,
1930
+ time,
1931
+ typedTime,
1932
+ count,
1933
+ untrusted,
1934
+ providerMetadata,
1935
+ evidenceSource,
1936
+ sourceReview,
1937
+ author,
1938
+ CRM_KINDS,
1939
+ CRM_ACTIVITY_KINDS,
1940
+ isCrmUserId,
1941
+ normalCrmUserId,
1942
+ isItemKind,
1943
+ organization,
1944
+ project,
1945
+ reminder,
1946
+ damageMarkPath,
1947
+ healthMarkPath,
1948
+ journalMarkPath,
1949
+ markStoreDamaged,
1950
+ readDamageMark,
1951
+ clearDamageMark,
1952
+ refuseDamagedStore,
1953
+ markJournalLost,
1954
+ readJournalMark,
1955
+ readHealthMark,
1956
+ recordDeepCheck,
1957
+ isBotProvider,
1958
+ inSource,
1959
+ sourceOf2 as sourceOf,
1960
+ CATALOG_KINDS,
1961
+ BUSINESS_KINDS,
1962
+ CONTRACT_KINDS,
1963
+ CONTRACT_STATUSES,
1964
+ SUBSCRIPTION_STATUSES,
1965
+ WALLET_KINDS,
1966
+ TRANSACTION_STATUSES,
1967
+ ORDER_DIRECTIONS,
1968
+ intervalOf,
1969
+ productLine,
1970
+ contractLine,
1971
+ subscriptionLine,
1972
+ walletLine,
1973
+ transactionLine,
1974
+ REPORTER_SQL,
1975
+ sourceOf as sourceOf2,
1976
+ LINK_KINDS,
1977
+ LINK_ORIGINS,
1978
+ LINK_SOURCES,
1979
+ linkKind,
1980
+ COUNTERPART_ROLE,
1981
+ FACT_STATUSES,
1982
+ MEMORY_KINDS,
1983
+ MEMORY_STATUSES,
1984
+ MEMORY_SCOPES,
1985
+ WORK_TASK_TYPES,
1986
+ TASK_TYPES,
1987
+ ACCOUNT_GROUPS,
1988
+ ACCOUNT_GROUPS_SETTING,
1989
+ isAccountList,
1990
+ isGroupName,
1991
+ groupName,
1992
+ groupMembers,
1993
+ listedHolds,
1994
+ keyOf,
1995
+ sourceOf3,
1996
+ sameAs,
1997
+ entriesOfList,
1998
+ accountsOfList,
1999
+ fitting
2000
+ };