@wirecat/amo-cli 0.5.0 → 0.7.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 (281) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +2 -2
  3. package/contracts/wirecat.json +14 -0
  4. package/dist/amo/button.js +1 -1
  5. package/dist/amo/json.js +1 -1
  6. package/dist/amo/oauth.js +3 -5
  7. package/dist/amo/transport.js +3 -7
  8. package/dist/api-keys.js +1 -1
  9. package/dist/bin/amo.js +11 -11
  10. package/dist/bundle/amo.js +5 -183
  11. package/dist/bundle/{chunk-3PYE55JY.js → chunk-3HWD4BKU.js} +4 -6
  12. package/dist/bundle/{chunk-M6VZXAJC.js → chunk-4EXURQQQ.js} +21 -19
  13. package/dist/bundle/chunk-AEWYRB6F.js +8 -0
  14. package/dist/bundle/{chunk-WUFX4TKA.js → chunk-GL7CRTHR.js} +3 -3
  15. package/dist/bundle/chunk-N2UB32VN.js +76 -0
  16. package/dist/bundle/{chunk-KZ2FIDI3.js → chunk-PVVSHDMQ.js} +7 -15
  17. package/dist/bundle/program-SQH3SPOW.js +2352 -0
  18. package/dist/bundle/{instructions-AMH5RWVJ.js → source-C65ZJUTW.js} +5 -6
  19. package/dist/bundle/store-SJ2TOUGU.js +12 -0
  20. package/dist/bundle/writer-I7GBI3VE.js +12 -0
  21. package/dist/commands/account.js +1 -1
  22. package/dist/commands/api.js +1 -3
  23. package/dist/commands/crm-shared.js +2 -3
  24. package/dist/commands/schedule.js +1 -1
  25. package/dist/commands/session.js +1 -8
  26. package/dist/commands/write.js +1 -2
  27. package/dist/config.js +1 -2
  28. package/dist/context.js +1 -2
  29. package/dist/crm/activities.js +1 -1
  30. package/dist/crm/records.js +1 -1
  31. package/dist/crm/source.js +1 -1
  32. package/dist/crm/writer.js +1 -1
  33. package/dist/identity.js +4 -0
  34. package/dist/program.js +1 -2
  35. package/dist/setup/flow.js +1 -1
  36. package/dist/store.js +1 -1
  37. package/dist/version.js +1 -1
  38. package/dist/whoami.js +1 -1
  39. package/package.json +3 -3
  40. package/scenarios/first-sync.md +13 -11
  41. package/scenarios/keep-in-sync.md +7 -6
  42. package/scenarios/safe-agent-writes.md +10 -9
  43. package/dist/amo/account.d.ts +0 -18
  44. package/dist/amo/account.d.ts.map +0 -1
  45. package/dist/amo/account.js.map +0 -1
  46. package/dist/amo/allow-list.d.ts +0 -31
  47. package/dist/amo/allow-list.d.ts.map +0 -1
  48. package/dist/amo/allow-list.js.map +0 -1
  49. package/dist/amo/button.d.ts +0 -53
  50. package/dist/amo/button.d.ts.map +0 -1
  51. package/dist/amo/button.js.map +0 -1
  52. package/dist/amo/errors.d.ts +0 -12
  53. package/dist/amo/errors.d.ts.map +0 -1
  54. package/dist/amo/errors.js.map +0 -1
  55. package/dist/amo/json.d.ts +0 -3
  56. package/dist/amo/json.d.ts.map +0 -1
  57. package/dist/amo/json.js.map +0 -1
  58. package/dist/amo/oauth.d.ts +0 -64
  59. package/dist/amo/oauth.d.ts.map +0 -1
  60. package/dist/amo/oauth.js.map +0 -1
  61. package/dist/amo/operation.d.ts +0 -45
  62. package/dist/amo/operation.d.ts.map +0 -1
  63. package/dist/amo/operation.js.map +0 -1
  64. package/dist/amo/operations.d.ts +0 -3
  65. package/dist/amo/operations.d.ts.map +0 -1
  66. package/dist/amo/operations.js.map +0 -1
  67. package/dist/amo/routes.d.ts +0 -67
  68. package/dist/amo/routes.d.ts.map +0 -1
  69. package/dist/amo/routes.js.map +0 -1
  70. package/dist/amo/transport.d.ts +0 -62
  71. package/dist/amo/transport.d.ts.map +0 -1
  72. package/dist/amo/transport.js.map +0 -1
  73. package/dist/api-keys.d.ts +0 -47
  74. package/dist/api-keys.d.ts.map +0 -1
  75. package/dist/api-keys.js.map +0 -1
  76. package/dist/bin/amo.d.ts +0 -3
  77. package/dist/bin/amo.d.ts.map +0 -1
  78. package/dist/bin/amo.js.map +0 -1
  79. package/dist/bundle/agent-EFMUK732.js +0 -41
  80. package/dist/bundle/all-profiles-PIWUQWBA.js +0 -320
  81. package/dist/bundle/anthropic-47CMXBPQ.js +0 -90
  82. package/dist/bundle/app-server-QRBQODF2.js +0 -257
  83. package/dist/bundle/areas-QVHVU57Z.js +0 -63
  84. package/dist/bundle/bun-OPDGMZZQ.js +0 -169
  85. package/dist/bundle/bun-sqlite-7I4X7CZW.js +0 -75
  86. package/dist/bundle/chunk-2JHVQMVC.js +0 -16
  87. package/dist/bundle/chunk-2XBDILVW.js +0 -53
  88. package/dist/bundle/chunk-3DEQUYEG.js +0 -185
  89. package/dist/bundle/chunk-3GX6KM2E.js +0 -5302
  90. package/dist/bundle/chunk-3HC5F3P7.js +0 -24
  91. package/dist/bundle/chunk-3YM4B2GT.js +0 -63
  92. package/dist/bundle/chunk-43OW5NTG.js +0 -338
  93. package/dist/bundle/chunk-43PMSR33.js +0 -357
  94. package/dist/bundle/chunk-4N7PP76S.js +0 -6848
  95. package/dist/bundle/chunk-4VN7RI4I.js +0 -1718
  96. package/dist/bundle/chunk-57HFPNMF.js +0 -189
  97. package/dist/bundle/chunk-5UTB3ADZ.js +0 -360
  98. package/dist/bundle/chunk-633NQY2R.js +0 -80
  99. package/dist/bundle/chunk-63N46DJU.js +0 -12278
  100. package/dist/bundle/chunk-6D4VWSJD.js +0 -259
  101. package/dist/bundle/chunk-6JTHXWPE.js +0 -64
  102. package/dist/bundle/chunk-6QGUK3H7.js +0 -161
  103. package/dist/bundle/chunk-6WS6GJ4V.js +0 -30
  104. package/dist/bundle/chunk-7IR2G5XY.js +0 -559
  105. package/dist/bundle/chunk-7IWIFVXH.js +0 -52
  106. package/dist/bundle/chunk-ABX7BBS4.js +0 -388
  107. package/dist/bundle/chunk-ADLS6FVG.js +0 -24600
  108. package/dist/bundle/chunk-ADTI5RUO.js +0 -1007
  109. package/dist/bundle/chunk-AKRIUNYP.js +0 -1197
  110. package/dist/bundle/chunk-BIKOE2IW.js +0 -614
  111. package/dist/bundle/chunk-BVVMIAQ6.js +0 -37727
  112. package/dist/bundle/chunk-CGW5R4UD.js +0 -362
  113. package/dist/bundle/chunk-D4NE7EON.js +0 -170
  114. package/dist/bundle/chunk-D72URWJE.js +0 -532
  115. package/dist/bundle/chunk-DFDN6AUB.js +0 -21
  116. package/dist/bundle/chunk-DNCLQPOM.js +0 -7
  117. package/dist/bundle/chunk-DPV53EZC.js +0 -206
  118. package/dist/bundle/chunk-DQ6S5TFZ.js +0 -9539
  119. package/dist/bundle/chunk-DSJ6EAOA.js +0 -4172
  120. package/dist/bundle/chunk-DVZ75WZJ.js +0 -3752
  121. package/dist/bundle/chunk-EH6ZEJGT.js +0 -932
  122. package/dist/bundle/chunk-EHK73OSW.js +0 -2017
  123. package/dist/bundle/chunk-FNV5HLHX.js +0 -1068
  124. package/dist/bundle/chunk-FV4GQNIK.js +0 -136
  125. package/dist/bundle/chunk-G2TU5RYY.js +0 -332
  126. package/dist/bundle/chunk-GDK7ETSB.js +0 -218
  127. package/dist/bundle/chunk-GGMAIIVE.js +0 -38
  128. package/dist/bundle/chunk-GLYWZQY4.js +0 -86
  129. package/dist/bundle/chunk-H4AFNENN.js +0 -1343
  130. package/dist/bundle/chunk-HOF7GQWW.js +0 -142
  131. package/dist/bundle/chunk-HSPEU6S7.js +0 -209
  132. package/dist/bundle/chunk-IA7LLLEI.js +0 -100
  133. package/dist/bundle/chunk-IB55P46L.js +0 -334
  134. package/dist/bundle/chunk-IG2TJQJ7.js +0 -79
  135. package/dist/bundle/chunk-JG6LCSEX.js +0 -407
  136. package/dist/bundle/chunk-JLXXUEAM.js +0 -72
  137. package/dist/bundle/chunk-JXT6GY4V.js +0 -1023
  138. package/dist/bundle/chunk-K7YY6SXR.js +0 -738
  139. package/dist/bundle/chunk-KEKXERBE.js +0 -67181
  140. package/dist/bundle/chunk-KZN2BG3P.js +0 -721
  141. package/dist/bundle/chunk-LKH3UKLO.js +0 -230
  142. package/dist/bundle/chunk-LZPKBN3C.js +0 -193
  143. package/dist/bundle/chunk-MDEPJZYJ.js +0 -106
  144. package/dist/bundle/chunk-NB7EOAUZ.js +0 -123
  145. package/dist/bundle/chunk-NISH4UXM.js +0 -58
  146. package/dist/bundle/chunk-NSKMNIY6.js +0 -460
  147. package/dist/bundle/chunk-PL5P7UKW.js +0 -25216
  148. package/dist/bundle/chunk-PPSAWFJD.js +0 -1293
  149. package/dist/bundle/chunk-Q7ICVP25.js +0 -18
  150. package/dist/bundle/chunk-QFOP3KUP.js +0 -2603
  151. package/dist/bundle/chunk-R53XXHEI.js +0 -76
  152. package/dist/bundle/chunk-RIMPFMZE.js +0 -1251
  153. package/dist/bundle/chunk-RN6RT5CB.js +0 -58
  154. package/dist/bundle/chunk-RRTMPSQR.js +0 -29
  155. package/dist/bundle/chunk-S4ZHQMNM.js +0 -133
  156. package/dist/bundle/chunk-S6JG4YUH.js +0 -72
  157. package/dist/bundle/chunk-TAVI73RW.js +0 -288
  158. package/dist/bundle/chunk-TLG6ECZ2.js +0 -54
  159. package/dist/bundle/chunk-TXDR6YSF.js +0 -23
  160. package/dist/bundle/chunk-TY7NDMFY.js +0 -46
  161. package/dist/bundle/chunk-U5RJJ2EC.js +0 -353
  162. package/dist/bundle/chunk-UDSL3MUU.js +0 -2333
  163. package/dist/bundle/chunk-V2CNGXWX.js +0 -798
  164. package/dist/bundle/chunk-VB7FZOYX.js +0 -633
  165. package/dist/bundle/chunk-VZ5PPYDG.js +0 -77
  166. package/dist/bundle/chunk-W5JRXIG6.js +0 -27995
  167. package/dist/bundle/chunk-WIHN3ELW.js +0 -2793
  168. package/dist/bundle/chunk-WOPVBRPV.js +0 -29
  169. package/dist/bundle/chunk-WXJYMMEL.js +0 -95
  170. package/dist/bundle/chunk-XCCU2E3Z.js +0 -274
  171. package/dist/bundle/chunk-XEQQJBBO.js +0 -92
  172. package/dist/bundle/chunk-XUT7DSM5.js +0 -108
  173. package/dist/bundle/chunk-Y5E2WNWB.js +0 -35
  174. package/dist/bundle/chunk-YWDFYQOU.js +0 -82
  175. package/dist/bundle/chunk-ZLUIRFJX.js +0 -780
  176. package/dist/bundle/chunk-ZVVMGPBJ.js +0 -50
  177. package/dist/bundle/cli-3NXOSENF.js +0 -1239
  178. package/dist/bundle/command-contract-LNSAV5LA.js +0 -39
  179. package/dist/bundle/command-server-entry-4ZQPNUL4.js +0 -168
  180. package/dist/bundle/decode-K7U7X5EL.js +0 -296
  181. package/dist/bundle/dispatch-56FECRCU.js +0 -411
  182. package/dist/bundle/dist-PAKDDIBT.js +0 -191
  183. package/dist/bundle/dist-T54K3FJV.js +0 -7577
  184. package/dist/bundle/echarts-O3TNDAXJ.js +0 -42501
  185. package/dist/bundle/embed-SWLVG73O.js +0 -37
  186. package/dist/bundle/embedder-EJN75BPV.js +0 -110
  187. package/dist/bundle/failure-WDSX6H3B.js +0 -24
  188. package/dist/bundle/first-run-WPGUUC4Z.js +0 -28
  189. package/dist/bundle/first-screen-JMNEUQ46.js +0 -40
  190. package/dist/bundle/mcp-5HFPWC3W.js +0 -167
  191. package/dist/bundle/meeting-combined-5TKG2RYD.js +0 -24
  192. package/dist/bundle/meeting-model-YXXNETKC.js +0 -24
  193. package/dist/bundle/meeting-semantic-U7EUB3ET.js +0 -21
  194. package/dist/bundle/node-EGMCBAO7.js +0 -176
  195. package/dist/bundle/node-P4E63KXA.js +0 -2340
  196. package/dist/bundle/node-TLZSIHIJ.js +0 -21
  197. package/dist/bundle/node-sqlite-YVOGMDSP.js +0 -73
  198. package/dist/bundle/oauth-2SNRBIJM.js +0 -19
  199. package/dist/bundle/open-ABCPY5IH.js +0 -22
  200. package/dist/bundle/openai-4D6PXJR7.js +0 -237
  201. package/dist/bundle/process-SGHEN6MQ.js +0 -91
  202. package/dist/bundle/program-CBDQBZZ3.js +0 -4971
  203. package/dist/bundle/prompt-2QUK5QST.js +0 -16
  204. package/dist/bundle/recognize-QMQSJRIH.js +0 -25
  205. package/dist/bundle/remote-U7TC2BLZ.js +0 -30
  206. package/dist/bundle/rerank-5UPVXGVV.js +0 -51
  207. package/dist/bundle/serve-VX6GUM6J.js +0 -198
  208. package/dist/bundle/server-FOPC6DJ3.js +0 -219
  209. package/dist/bundle/server-OIVNOMVK.js +0 -87
  210. package/dist/bundle/source-HWS5SJIV.js +0 -46
  211. package/dist/bundle/sqlite-runtime-77NKDEXN.js +0 -19
  212. package/dist/bundle/state-X2HU6GB2.js +0 -35
  213. package/dist/bundle/store-2U4U6KL4.js +0 -184
  214. package/dist/bundle/store-3CHPHFP7.js +0 -301
  215. package/dist/bundle/store-Z3747L5F.js +0 -34
  216. package/dist/bundle/store-maintenance-command-UOSZJTVP.js +0 -74
  217. package/dist/bundle/surface-MUT72QON.js +0 -73
  218. package/dist/bundle/writer-RBKQ64ZM.js +0 -48
  219. package/dist/commands/account.d.ts +0 -4
  220. package/dist/commands/account.d.ts.map +0 -1
  221. package/dist/commands/account.js.map +0 -1
  222. package/dist/commands/api.d.ts +0 -3
  223. package/dist/commands/api.d.ts.map +0 -1
  224. package/dist/commands/api.js.map +0 -1
  225. package/dist/commands/crm-shared.d.ts +0 -8
  226. package/dist/commands/crm-shared.d.ts.map +0 -1
  227. package/dist/commands/crm-shared.js.map +0 -1
  228. package/dist/commands/schedule.d.ts +0 -3
  229. package/dist/commands/schedule.d.ts.map +0 -1
  230. package/dist/commands/schedule.js.map +0 -1
  231. package/dist/commands/session.d.ts +0 -35
  232. package/dist/commands/session.d.ts.map +0 -1
  233. package/dist/commands/session.js.map +0 -1
  234. package/dist/commands/write.d.ts +0 -14
  235. package/dist/commands/write.d.ts.map +0 -1
  236. package/dist/commands/write.js.map +0 -1
  237. package/dist/config.d.ts +0 -4
  238. package/dist/config.d.ts.map +0 -1
  239. package/dist/config.js.map +0 -1
  240. package/dist/context.d.ts +0 -62
  241. package/dist/context.d.ts.map +0 -1
  242. package/dist/context.js.map +0 -1
  243. package/dist/crm/activities.d.ts +0 -32
  244. package/dist/crm/activities.d.ts.map +0 -1
  245. package/dist/crm/activities.js.map +0 -1
  246. package/dist/crm/records.d.ts +0 -20
  247. package/dist/crm/records.d.ts.map +0 -1
  248. package/dist/crm/records.js.map +0 -1
  249. package/dist/crm/source.d.ts +0 -41
  250. package/dist/crm/source.d.ts.map +0 -1
  251. package/dist/crm/source.js.map +0 -1
  252. package/dist/crm/writer.d.ts +0 -14
  253. package/dist/crm/writer.d.ts.map +0 -1
  254. package/dist/crm/writer.js.map +0 -1
  255. package/dist/identity.d.ts +0 -7
  256. package/dist/identity.d.ts.map +0 -1
  257. package/dist/identity.js.map +0 -1
  258. package/dist/index.d.ts +0 -3
  259. package/dist/index.d.ts.map +0 -1
  260. package/dist/index.js.map +0 -1
  261. package/dist/program.d.ts +0 -6
  262. package/dist/program.d.ts.map +0 -1
  263. package/dist/program.js.map +0 -1
  264. package/dist/reasons.d.ts +0 -10
  265. package/dist/reasons.d.ts.map +0 -1
  266. package/dist/reasons.js.map +0 -1
  267. package/dist/setup/flow.d.ts +0 -2
  268. package/dist/setup/flow.d.ts.map +0 -1
  269. package/dist/setup/flow.js.map +0 -1
  270. package/dist/store.d.ts +0 -15
  271. package/dist/store.d.ts.map +0 -1
  272. package/dist/store.js.map +0 -1
  273. package/dist/version.d.ts +0 -2
  274. package/dist/version.d.ts.map +0 -1
  275. package/dist/version.js.map +0 -1
  276. package/dist/wcat.d.ts +0 -3
  277. package/dist/wcat.d.ts.map +0 -1
  278. package/dist/wcat.js.map +0 -1
  279. package/dist/whoami.d.ts +0 -24
  280. package/dist/whoami.d.ts.map +0 -1
  281. package/dist/whoami.js.map +0 -1
@@ -1,58 +0,0 @@
1
- import { createRequire as __bundleRequire } from "node:module";
2
- const require = __bundleRequire(import.meta.url);
3
- import {
4
- importFrom
5
- } from "./chunk-Y5E2WNWB.js";
6
- import {
7
- CliError
8
- } from "./chunk-S6JG4YUH.js";
9
- import {
10
- __name
11
- } from "./chunk-ZVVMGPBJ.js";
12
-
13
- // node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
14
- import { readFileSync } from "node:fs";
15
- var musl = /* @__PURE__ */ __name(() => {
16
- if (process.platform !== "linux")
17
- return false;
18
- try {
19
- return readFileSync("/proc/self/maps", "utf8").includes("ld-musl");
20
- } catch {
21
- return false;
22
- }
23
- }, "musl");
24
- var found;
25
- var vectorExtension = /* @__PURE__ */ __name(() => {
26
- found ??= locate();
27
- return found;
28
- }, "vectorExtension");
29
- var locate = /* @__PURE__ */ __name(async () => {
30
- const onMusl = musl();
31
- const target = `${process.platform}-${process.arch}${onMusl ? "-musl" : ""}`;
32
- let path;
33
- try {
34
- const { extensionFor } = await importFrom(new URL("store/vector-extension.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-sqlite");
35
- path = extensionFor({ musl: onMusl });
36
- } catch {
37
- path = void 0;
38
- }
39
- if (path === void 0) {
40
- found = void 0;
41
- throw new CliError("configuration_error", `the message store needs the sqlite-vec extension, and @wirecat/cli-core-sqlite has none for ${target} \u2014 reinstall the CLI so its dependencies install with it (an install that skips optional or native packages leaves it out)`, { reason: "store.vector-extension-missing", target });
42
- }
43
- return path;
44
- }, "locate");
45
- var loadVectorExtension = /* @__PURE__ */ __name((database, path) => {
46
- try {
47
- database.loadExtension(path);
48
- } catch (error) {
49
- throw new CliError("configuration_error", `the sqlite-vec extension did not load on ${process.platform}-${process.arch} \u2014 reinstall the CLI; on macOS under Bun, @wirecat/cli-core-sqlite's SQLite must be installed, since the system's cannot load extensions`, { reason: "store.vector-extension-failed", cause: error instanceof Error ? error.message : String(error) });
50
- } finally {
51
- database.enableLoadExtension?.(false);
52
- }
53
- }, "loadVectorExtension");
54
-
55
- export {
56
- vectorExtension,
57
- loadVectorExtension
58
- };
@@ -1,460 +0,0 @@
1
- import { createRequire as __bundleRequire } from "node:module";
2
- const require = __bundleRequire(import.meta.url);
3
- import {
4
- LEVELS
5
- } from "./chunk-BIKOE2IW.js";
6
- import {
7
- WORD_BODY
8
- } from "./chunk-EHK73OSW.js";
9
- import {
10
- resolvePaths,
11
- writeSecurely
12
- } from "./chunk-WIHN3ELW.js";
13
- import {
14
- array,
15
- getDotPath,
16
- integer,
17
- minLength,
18
- minValue,
19
- nullable,
20
- number,
21
- optional,
22
- picklist,
23
- pipe,
24
- record,
25
- regex,
26
- safeParse,
27
- strictObject,
28
- string,
29
- transform,
30
- unknown
31
- } from "./chunk-QFOP3KUP.js";
32
- import {
33
- CliError,
34
- visibleControls
35
- } from "./chunk-S6JG4YUH.js";
36
- import {
37
- __name
38
- } from "./chunk-ZVVMGPBJ.js";
39
-
40
- // node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/domain/formatting.js
41
- var invalid = /* @__PURE__ */ __name(() => new CliError("validation_error", "the messenger formatter returned invalid text spans"), "invalid");
42
- var validateFormattedText = /* @__PURE__ */ __name((formatted) => {
43
- const { text, spans } = formatted;
44
- if (typeof text !== "string" || !Array.isArray(spans) || spans.length > 100)
45
- throw invalid();
46
- const boundary = /* @__PURE__ */ __name((at) => !(at > 0 && at < text.length && /[\uD800-\uDBFF]/u.test(text[at - 1] ?? "") && /[\uDC00-\uDFFF]/u.test(text[at] ?? "")), "boundary");
47
- for (const span of spans) {
48
- if (![
49
- "bold",
50
- "italic",
51
- "strike",
52
- "underline",
53
- "code",
54
- "pre",
55
- "link",
56
- "blockquote",
57
- "spoiler",
58
- "highlight",
59
- "heading"
60
- ].includes(span.type) || !Number.isInteger(span.from) || !Number.isInteger(span.length) || span.from < 0 || span.length <= 0 || span.from + span.length > text.length || !boundary(span.from) || !boundary(span.from + span.length))
61
- throw invalid();
62
- if (span.type === "link") {
63
- if (!span.url || Array.from(span.url).some((char) => char.charCodeAt(0) <= 32 || char.charCodeAt(0) === 127))
64
- throw new CliError("validation_error", "a Markdown link needs an absolute http, https or mailto URL");
65
- let url;
66
- try {
67
- url = new URL(span.url);
68
- } catch {
69
- throw new CliError("validation_error", "a Markdown link needs an absolute http, https or mailto URL");
70
- }
71
- if (!["http:", "https:", "mailto:"].includes(url.protocol))
72
- throw new CliError("validation_error", "Markdown links support http, https and mailto URLs");
73
- }
74
- }
75
- return formatted;
76
- }, "validateFormattedText");
77
- var visibleFormattedText = /* @__PURE__ */ __name((formatted) => {
78
- validateFormattedText(formatted);
79
- const text = visibleControls(formatted.text);
80
- const positions = /* @__PURE__ */ new Map([[0, 0]]);
81
- let original = 0;
82
- let visible = 0;
83
- for (const character of formatted.text) {
84
- const rendered = text.startsWith(character, visible) ? character : visibleControls(character);
85
- original += character.length;
86
- visible += rendered.length;
87
- positions.set(original, visible);
88
- }
89
- return {
90
- text,
91
- spans: formatted.spans.map((span) => ({
92
- ...span,
93
- from: positions.get(span.from),
94
- length: positions.get(span.from + span.length) - positions.get(span.from),
95
- ...span.url === void 0 ? {} : { url: visibleControls(span.url) }
96
- }))
97
- };
98
- }, "visibleFormattedText");
99
-
100
- // node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/domain/vcard.js
101
- var AS_WORD = new RegExp(`^${WORD_BODY}$`);
102
- var encoder = new TextEncoder();
103
-
104
- // node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/moderation/check.js
105
- var INVITE = /max\.ru\/join\/|(t|telegram)\.me\/(\+|joinchat\/)|tg:\/\/join/i;
106
- var LINK = /https?:\/\/\S+/i;
107
- var STRENGTH = { report: 0, delete: 1, remove: 2 };
108
- var judge = /* @__PURE__ */ __name(({ rules, messages, joined, answerers, service, now, invites }) => {
109
- const invite = invites ? new RegExp(`${INVITE.source}|${invites.source}`, "i") : INVITE;
110
- const trusted = new Set(rules.trusted);
111
- const blocked = /* @__PURE__ */ __name((id, name) => id !== null && rules.blocked.includes(id) || name !== null && rules.blockedNames.some((part) => name.toLocaleLowerCase().includes(part.toLocaleLowerCase())), "blocked");
112
- const young = /* @__PURE__ */ __name((member) => rules.newAccount.days > 0 && typeof member.registeredAt === "string" && now - Date.parse(member.registeredAt) < rules.newAccount.days * 864e5, "young");
113
- const found = [];
114
- const add = /* @__PURE__ */ __name((finding) => {
115
- if (finding.action === "remove" && found.some((f) => f.action === "remove" && f.personId === finding.personId)) {
116
- return;
117
- }
118
- found.push(finding);
119
- }, "add");
120
- for (const member of joined) {
121
- if (trusted.has(member.id) || answerers.has(member.id))
122
- continue;
123
- const person = { kind: "member", personId: member.id, personName: member.name };
124
- if (blocked(member.id, member.name)) {
125
- add({ ...person, rule: "blocked", action: rules.blockedPeople === "remove" ? "remove" : "report" });
126
- } else if (young(member)) {
127
- add({ ...person, rule: "newAccount", action: rules.newAccount.action });
128
- }
129
- }
130
- const flooding = floodOf(messages, rules.flood);
131
- for (const message of messages) {
132
- const id = message.senderId;
133
- if (id === null || message.outgoing === true || answerers.has(id) || trusted.has(id))
134
- continue;
135
- if (service.has(message.id) || message.attachments.some((attachment) => attachment.kind === "control"))
136
- continue;
137
- const base = { kind: "message", personId: id, personName: message.senderName, messageId: message.id };
138
- const text = message.text;
139
- const broken2 = [];
140
- if (blocked(id, message.senderName))
141
- broken2.push(["blocked", rules.blockedPeople]);
142
- if (invite.test(text))
143
- broken2.push(["invites", rules.invites]);
144
- if (LINK.test(text) || message.attachments.some((attachment) => attachment.kind === "share")) {
145
- broken2.push(["links", rules.links]);
146
- }
147
- if (message.forwardedFrom !== null)
148
- broken2.push(["forwards", rules.forwards]);
149
- if (flooding.has(message.id))
150
- broken2.push(["flood", rules.flood.action]);
151
- const strongest = broken2.reduce((best, rule) => best === void 0 || STRENGTH[rule[1]] > STRENGTH[best[1]] ? rule : best, void 0);
152
- if (strongest)
153
- add({ ...base, rule: strongest[0], action: strongest[1] });
154
- }
155
- return found;
156
- }, "judge");
157
- var floodOf = /* @__PURE__ */ __name((messages, flood) => {
158
- const window = flood.minutes * 6e4;
159
- const over = /* @__PURE__ */ new Set();
160
- const bySender = /* @__PURE__ */ new Map();
161
- for (const message of messages) {
162
- if (message.senderId === null)
163
- continue;
164
- const times = bySender.get(message.senderId) ?? [];
165
- const at = Date.parse(message.timestamp);
166
- times.push(at);
167
- bySender.set(message.senderId, times);
168
- if (times.filter((time) => at - time < window).length > flood.messages)
169
- over.add(message.id);
170
- }
171
- return over;
172
- }, "floodOf");
173
- var act = /* @__PURE__ */ __name(async (moderator, findings, options) => {
174
- const { chatId, rules, allowDangerous, dryRun, maxActions, confirm, command } = options;
175
- const typed = options.commandFor ?? ((chat, finding) => commandFor(command, chat, finding));
176
- const rows = [];
177
- let acted = 0;
178
- let stopped;
179
- for (const finding of findings) {
180
- if (finding.action === "report") {
181
- rows.push({ ...finding, outcome: "reported" });
182
- continue;
183
- }
184
- const consent = finding.action;
185
- const level2 = rules.consent[consent];
186
- const row = /* @__PURE__ */ __name((outcome, reason) => ({
187
- ...finding,
188
- outcome,
189
- ...reason ? { reason } : {},
190
- ...outcome === "done" || outcome === "reported" ? {} : { command: typed(chatId, finding) }
191
- }), "row");
192
- if (level2 === "deny") {
193
- rows.push(row("forbidden", `consent.${consent} is deny`));
194
- continue;
195
- }
196
- if (level2 === "readonly") {
197
- rows.push(row("reported", `consent.${consent} is readonly`));
198
- continue;
199
- }
200
- if (dryRun) {
201
- rows.push(row("planned", "--dry-run"));
202
- continue;
203
- }
204
- if (stopped || acted >= maxActions) {
205
- rows.push(row("skipped", stopped ?? `over the limit of ${maxActions} actions per check`));
206
- continue;
207
- }
208
- if (level2 === "ask" && !allowDangerous) {
209
- const yes = confirm ? await confirm(finding) : void 0;
210
- if (yes === void 0) {
211
- rows.push(row("planned", `consent.${consent} is ask, and nobody is there to answer \u2014 run with --allow-dangerous`));
212
- continue;
213
- }
214
- if (!yes) {
215
- rows.push(row("declined", "the answer was no"));
216
- continue;
217
- }
218
- }
219
- acted += 1;
220
- try {
221
- if (finding.action === "delete" && finding.messageId) {
222
- await moderator.deleteMessage(chatId, finding.messageId);
223
- } else {
224
- await moderator.removePerson(chatId, finding.personId);
225
- }
226
- rows.push(row("done"));
227
- } catch (error) {
228
- const failure = asCliError(error);
229
- if (failure.code === "rate_limited")
230
- stopped = failure.message;
231
- const refused = ["rate_limited", "permission_error", "confirmation_required"].includes(failure.code);
232
- rows.push(row(refused ? "refused" : "failed", failure.message));
233
- }
234
- }
235
- return rows;
236
- }, "act");
237
- var asCliError = /* @__PURE__ */ __name((error) => error instanceof CliError ? error : new CliError("provider_error", error instanceof Error ? error.message : String(error)), "asCliError");
238
- var who = /* @__PURE__ */ __name((finding) => finding.personName ?? finding.personId, "who");
239
- var describe = /* @__PURE__ */ __name((finding) => finding.action === "delete" ? `delete message ${finding.messageId} from ${who(finding)} for everyone (${finding.rule})` : `remove ${who(finding)} from the group (${finding.rule})`, "describe");
240
- var commandFor = /* @__PURE__ */ __name((command, chatId, finding) => finding.action === "delete" ? `${command} messages delete ${chatId} ${finding.messageId} --for-everyone --allow-dangerous` : finding.action === "remove" ? `${command} chats members remove ${chatId} ${finding.personId}` : "", "commandFor");
241
- var CHECK_READS = 1e3;
242
- var PAGE = 100;
243
- var gather = /* @__PURE__ */ __name(async (adapter, chatId, since) => {
244
- const notes = [];
245
- const historyAfter = adapter.historyAfter;
246
- if (!historyAfter)
247
- throw new CliError("validation_error", "this messenger cannot read a chat forward from a time");
248
- const messages = [];
249
- let more = true;
250
- while (more && messages.length < CHECK_READS) {
251
- const last = messages.at(-1);
252
- const page = await historyAfter.call(adapter, chatId, {
253
- limit: PAGE,
254
- after: last ? { id: last.id } : { time: since }
255
- });
256
- messages.push(...page.items);
257
- more = page.hasMore && page.items.length > 0;
258
- }
259
- const scanned = adapter.chatEvents ? (await adapter.chatEvents(chatId, { since })).events : [];
260
- const until = messages.at(-1)?.timestamp ?? null;
261
- const events = more && until !== null ? scanned.filter((event) => Date.parse(event.timestamp) <= Date.parse(until)) : scanned;
262
- if (!adapter.chatEvents)
263
- notes.push("this messenger does not say who joined, so only messages are judged");
264
- const joinedIds = new Set(events.filter((one) => one.event === "join" || one.event === "add").flatMap((one) => one.people.length > 0 ? one.people.map((person) => person.id) : one.by.id ? [one.by.id] : []));
265
- const joined = joinedIds.size === 0 || !adapter.members ? [] : (await adapter.members(chatId, { offset: 0 })).items.filter((member) => joinedIds.has(member.id));
266
- const admins = adapter.admins ? await adapter.admins(chatId) : null;
267
- if (admins === null)
268
- notes.push("the group's admins are not known, so only your own messages are exempt");
269
- return {
270
- messages,
271
- joined,
272
- answerers: new Set(admins ?? []),
273
- service: new Set(events.map((one) => one.messageId)),
274
- until,
275
- more,
276
- notes
277
- };
278
- }, "gather");
279
- var MAX_ACTIONS = 10;
280
- var undone = /* @__PURE__ */ __name((row) => ["planned", "skipped", "failed"].includes(row.outcome), "undone");
281
- var nextPoint = /* @__PURE__ */ __name((rows, found) => {
282
- const waiting = rows.filter(undone);
283
- if (waiting.some((row) => row.messageId === void 0))
284
- return null;
285
- const times = waiting.map((row) => found.messages.find((message) => message.id === row.messageId)?.timestamp).filter((time) => time !== void 0).map(Date.parse);
286
- if (times.length === 0)
287
- return found.until;
288
- return new Date(Math.min(...times) - 1).toISOString();
289
- }, "nextPoint");
290
- var someUndone = /* @__PURE__ */ __name((rows) => rows.some(undone), "someUndone");
291
-
292
- // node_modules/.pnpm/@wirecat+cli-core@1.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_dd5172c52281f8f1e2dd1d4e9555d5c3/node_modules/@wirecat/cli-core/dist/moderation/rules.js
293
- import { existsSync, readdirSync, readFileSync } from "node:fs";
294
- import { join } from "node:path";
295
- var RULE_ACTIONS = ["report", "delete", "remove"];
296
- var OLD_LEVELS = { forbid: "deny", flag: "ask", confirm: "ask", allow: "allow" };
297
- var level = pipe(picklist([...LEVELS, ...Object.keys(OLD_LEVELS)]), transform((typed) => OLD_LEVELS[typed] ?? typed));
298
- var action = picklist(RULE_ACTIONS);
299
- var personIds = array(pipe(string(), regex(/^-?\d+$/, "a person id is digits")));
300
- var atLeast = /* @__PURE__ */ __name((min) => pipe(number(), integer(), minValue(min)), "atLeast");
301
- var groupRules = pipe(strictObject({
302
- title: nullable(string()),
303
- trusted: personIds,
304
- blocked: personIds,
305
- blockedNames: array(pipe(string(), minLength(1))),
306
- links: action,
307
- invites: action,
308
- forwards: action,
309
- blockedPeople: action,
310
- flood: strictObject({ messages: atLeast(1), minutes: atLeast(1), action }),
311
- /** 0 days turns the rule off. */
312
- newAccount: strictObject({ days: atLeast(0), action: picklist(["report", "remove"]) }),
313
- requests: optional(unknown()),
314
- consent: strictObject({
315
- delete: level,
316
- remove: level,
317
- accept: optional(unknown()),
318
- decline: optional(unknown())
319
- })
320
- }), transform(({ requests: _, consent: { accept: _accept, decline: _decline, ...consent }, ...rules }) => ({
321
- ...rules,
322
- consent
323
- })));
324
- var file = strictObject({
325
- groups: record(string(), groupRules),
326
- /** Where each group's next `chats moderate` starts, ISO 8601. */
327
- checkedUntil: optional(record(string(), string()))
328
- });
329
- var defaultRules = /* @__PURE__ */ __name((title) => ({
330
- title,
331
- trusted: [],
332
- blocked: [],
333
- blockedNames: [],
334
- links: "report",
335
- invites: "report",
336
- forwards: "report",
337
- blockedPeople: "report",
338
- flood: { messages: 5, minutes: 1, action: "report" },
339
- newAccount: { days: 7, action: "report" },
340
- consent: { delete: "ask", remove: "ask" }
341
- }), "defaultRules");
342
- var list = /* @__PURE__ */ __name((value) => value.split(",").map((item) => item.trim()).filter(Boolean), "list");
343
- var whole = /* @__PURE__ */ __name((value) => /^\d+$/.test(value.trim()) ? Number(value) : Number.NaN, "whole");
344
- var KEYS = {
345
- trusted: { help: "person ids, comma-separated; never acted on", parse: list },
346
- blocked: { help: "person ids, comma-separated", parse: list },
347
- blockedNames: { help: "parts of a name, comma-separated, any case", parse: list },
348
- links: { help: RULE_ACTIONS.join("|"), parse: String },
349
- invites: { help: RULE_ACTIONS.join("|"), parse: String },
350
- forwards: { help: RULE_ACTIONS.join("|"), parse: String },
351
- blockedPeople: { help: RULE_ACTIONS.join("|"), parse: String },
352
- "flood.messages": { help: "a whole number, 1 or more", parse: whole },
353
- "flood.minutes": { help: "a whole number, 1 or more", parse: whole },
354
- "flood.action": { help: RULE_ACTIONS.join("|"), parse: String },
355
- "newAccount.days": { help: "a whole number; 0 turns it off", parse: whole },
356
- "newAccount.action": { help: "report|remove", parse: String },
357
- "consent.delete": { help: LEVELS.join("|"), parse: String },
358
- "consent.remove": { help: LEVELS.join("|"), parse: String }
359
- };
360
- var RULE_KEYS = Object.keys(KEYS);
361
- var stateFolder = /* @__PURE__ */ __name((app, env, folder) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, folder), "stateFolder");
362
- var profilesFolder = /* @__PURE__ */ __name((app, env) => stateFolder(app, env, "profiles"), "profilesFolder");
363
- var moderationPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(profilesFolder(app, env), `${profile}.moderation.json`), "moderationPathFor");
364
- var namesIn = /* @__PURE__ */ __name((folder, suffix) => existsSync(folder) ? readdirSync(folder).filter((name) => name.endsWith(suffix)).map((name) => name.slice(0, -suffix.length)) : [], "namesIn");
365
- var moderationProfiles = /* @__PURE__ */ __name((app, env = process.env) => [
366
- .../* @__PURE__ */ new Set([
367
- ...namesIn(stateFolder(app, env, "accounts"), ".json"),
368
- ...namesIn(profilesFolder(app, env), ".moderation.json")
369
- ])
370
- ].sort(), "moderationProfiles");
371
- var ModerationRules = class {
372
- static {
373
- __name(this, "ModerationRules");
374
- }
375
- path;
376
- constructor(path) {
377
- this.path = path;
378
- }
379
- /** `undefined` when this group has no section yet. */
380
- read(chatId) {
381
- return this.#file().groups[chatId];
382
- }
383
- /** Writes the group's whole section — the defaults first, if it had none — with one key changed. */
384
- set(chatId, title, key, value) {
385
- const known = KEYS[key];
386
- if (!known)
387
- throw invalid2(`no rule ${key} \u2014 one of: ${RULE_KEYS.join(", ")}`);
388
- const current = this.read(chatId) ?? defaultRules(title);
389
- const checked = safeParse(groupRules, assign(current, key, known.parse(value)));
390
- if (!checked.success)
391
- throw invalid2(`${key} ${JSON.stringify(value)} is not valid \u2014 ${known.help}`);
392
- const saved = this.#file();
393
- this.#write({ ...saved, groups: { ...saved.groups, [chatId]: checked.output } });
394
- return checked.output;
395
- }
396
- /** Puts one key back to its default. */
397
- unset(chatId, title, key) {
398
- if (!KEYS[key])
399
- throw invalid2(`no rule ${key} \u2014 one of: ${RULE_KEYS.join(", ")}`);
400
- const current = this.read(chatId) ?? defaultRules(title);
401
- const changed = assign(current, key, lookup(defaultRules(title), key));
402
- const saved = this.#file();
403
- this.#write({ ...saved, groups: { ...saved.groups, [chatId]: changed } });
404
- return changed;
405
- }
406
- checkedUntil(chatId) {
407
- return this.#file().checkedUntil?.[chatId];
408
- }
409
- markChecked(chatId, at) {
410
- const saved = this.#file();
411
- this.#write({ ...saved, checkedUntil: { ...saved.checkedUntil, [chatId]: at } });
412
- }
413
- #file() {
414
- if (!existsSync(this.path))
415
- return { groups: {} };
416
- let parsed;
417
- try {
418
- parsed = JSON.parse(readFileSync(this.path, "utf8"));
419
- } catch (error) {
420
- throw broken(this.path, error instanceof Error ? error.message : String(error));
421
- }
422
- const checked = safeParse(file, parsed);
423
- if (!checked.success) {
424
- const problems = checked.issues.map((issue) => `${getDotPath(issue) ?? "file"}: ${issue.message}`);
425
- throw broken(this.path, problems.join("; "));
426
- }
427
- return checked.output;
428
- }
429
- #write(content) {
430
- writeSecurely(this.path, `${JSON.stringify(content, null, 2)}
431
- `, 384);
432
- }
433
- };
434
- var invalid2 = /* @__PURE__ */ __name((message) => new CliError("validation_error", message), "invalid");
435
- var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the moderation rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
436
- var lookup = /* @__PURE__ */ __name((rules, key) => key.split(".").reduce((value, part) => value[part], rules), "lookup");
437
- var assign = /* @__PURE__ */ __name((rules, key, value) => {
438
- const [head, tail] = key.split(".");
439
- if (tail === void 0)
440
- return { ...rules, [head]: value };
441
- return { ...rules, [head]: { ...rules[head], [tail]: value } };
442
- }, "assign");
443
-
444
- export {
445
- validateFormattedText,
446
- visibleFormattedText,
447
- judge,
448
- act,
449
- describe,
450
- CHECK_READS,
451
- gather,
452
- MAX_ACTIONS,
453
- nextPoint,
454
- someUndone,
455
- defaultRules,
456
- RULE_KEYS,
457
- moderationPathFor,
458
- moderationProfiles,
459
- ModerationRules
460
- };