@wirecat/tg-cli 0.101.0 → 0.102.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 (95) hide show
  1. package/dist/bin/tg.js +1 -1
  2. package/dist/bot/transport.d.ts.map +1 -1
  3. package/dist/bot/transport.js +14 -17
  4. package/dist/bot/transport.js.map +1 -1
  5. package/dist/bundle/{adapter-A3VD4Y6Z.js → adapter-M2HRSFFL.js} +90 -28
  6. package/dist/bundle/{all-profiles-UPVNHXB2.js → all-profiles-GOD2QNTK.js} +29 -8
  7. package/dist/bundle/{anthropic-IRKNWPIB.js → anthropic-LKU7RWMA.js} +3 -3
  8. package/dist/bundle/{bot-api-UNTQG2M5.js → bot-api-X3MPFVPL.js} +42 -46
  9. package/dist/bundle/{bot-history-V4RTY5K7.js → bot-history-OUMVVG22.js} +10 -10
  10. package/dist/bundle/{bun-2JZPG2NL.js → bun-LIZ6MKFS.js} +2 -2
  11. package/dist/bundle/{bun-sqlite-TZHKM225.js → bun-sqlite-2IFQYQ44.js} +2 -2
  12. package/dist/bundle/{chunk-VA5YEJS3.js → chunk-264DAFJV.js} +4 -4
  13. package/dist/bundle/{chunk-ZV24I2UJ.js → chunk-2SUTCDGO.js} +1 -1
  14. package/dist/bundle/{chunk-BX6HH4F6.js → chunk-334UBWOB.js} +10 -10
  15. package/dist/bundle/{chunk-2DGOFLDA.js → chunk-4PDEQL6T.js} +1 -1
  16. package/dist/bundle/chunk-4QB4WDLT.js +922 -0
  17. package/dist/bundle/{chunk-MLLJ74LM.js → chunk-5D6OJREA.js} +1 -1
  18. package/dist/bundle/{chunk-RF54YDBB.js → chunk-5DFGJPT6.js} +4 -4
  19. package/dist/bundle/{chunk-TGREFJVA.js → chunk-5VSR5ENL.js} +7 -7
  20. package/dist/bundle/{chunk-VCGL2ETF.js → chunk-AUOXTGTU.js} +1 -1
  21. package/dist/bundle/{chunk-X4Y2ROJI.js → chunk-BBC546ZA.js} +91 -2
  22. package/dist/bundle/{chunk-QOWSVDPZ.js → chunk-BQYTIYGB.js} +106 -95
  23. package/dist/bundle/{chunk-XCKD54TN.js → chunk-CLWYQNSC.js} +5 -5
  24. package/dist/bundle/{chunk-7CBUCTB6.js → chunk-CRZPQQHE.js} +27 -33
  25. package/dist/bundle/chunk-DE7LFMY2.js +440 -0
  26. package/dist/bundle/{chunk-ODSVNH3H.js → chunk-ENE5CSVY.js} +2373 -1266
  27. package/dist/bundle/{chunk-G2US6LJB.js → chunk-ERQDBK5I.js} +1 -1
  28. package/dist/bundle/{chunk-W2336E7Y.js → chunk-F2TG3BA2.js} +4 -4
  29. package/dist/bundle/{chunk-DYNSP6FW.js → chunk-FBWOQMPE.js} +1442 -769
  30. package/dist/bundle/{chunk-5TPT2S2Z.js → chunk-FOUE7XLK.js} +1 -1
  31. package/dist/bundle/{chunk-RVCS7Q3A.js → chunk-GSKFAE3I.js} +1287 -512
  32. package/dist/bundle/{chunk-6IPY2QRG.js → chunk-HLAZ65AW.js} +1 -1
  33. package/dist/bundle/{chunk-A5JSTZZZ.js → chunk-JFSVXMN6.js} +2 -2
  34. package/dist/bundle/{chunk-N5UFBWDM.js → chunk-M5UH5CF3.js} +5 -7
  35. package/dist/bundle/{chunk-F7TDFWXY.js → chunk-MGG7JSNO.js} +2 -2
  36. package/dist/bundle/{chunk-H6OXALTJ.js → chunk-OCWARAFE.js} +1 -1
  37. package/dist/bundle/{chunk-S7ZNLLY5.js → chunk-OHBHHBYL.js} +2 -2
  38. package/dist/bundle/{chunk-5GKXETRP.js → chunk-PSH7K6TL.js} +610 -51
  39. package/dist/bundle/{chunk-VYDTI254.js → chunk-Q2NYEX4A.js} +53 -34
  40. package/dist/bundle/{chunk-G3ZRY436.js → chunk-QEPZUFPL.js} +46 -46
  41. package/dist/bundle/{chunk-BXQS5RCE.js → chunk-QL7CQ6VZ.js} +253 -78
  42. package/dist/bundle/{chunk-NC5WS7OP.js → chunk-SRU3OF4R.js} +1 -1
  43. package/dist/bundle/{chunk-PUBS2F5J.js → chunk-TV5DGHBT.js} +242 -242
  44. package/dist/bundle/{chunk-ZEOCU24Z.js → chunk-TXBUDJ3P.js} +1 -1
  45. package/dist/bundle/{chunk-ACGTFLEB.js → chunk-U4RRZUNP.js} +8 -8
  46. package/dist/bundle/{chunk-LPB2MDUW.js → chunk-UK3GAN7Q.js} +6 -6
  47. package/dist/bundle/{chunk-UN6CKIBN.js → chunk-UR6ASUSG.js} +8 -5
  48. package/dist/bundle/{chunk-U46UNBMT.js → chunk-V52SBQYF.js} +236 -13
  49. package/dist/bundle/{chunk-S2JSZWEC.js → chunk-VUJ34PEQ.js} +9 -9
  50. package/dist/bundle/{chunk-QYVVRQTN.js → chunk-W5EB4JLV.js} +2 -2
  51. package/dist/bundle/{chunk-3KHKYYCR.js → chunk-WMOEOVWZ.js} +1 -0
  52. package/dist/bundle/{chunk-VRSN7VLO.js → chunk-WVEHUKCZ.js} +1 -1
  53. package/dist/bundle/{chunk-64DK7S4F.js → chunk-XXTJUZMB.js} +1 -1
  54. package/dist/bundle/{chunk-54R2GDQ3.js → chunk-Y4XSWI22.js} +3 -3
  55. package/dist/bundle/{chunk-4ZS73HTJ.js → chunk-YHB57PFN.js} +1 -1
  56. package/dist/bundle/{chunk-G77QOTXE.js → chunk-ZRNRQFTF.js} +1 -1
  57. package/dist/bundle/{command-contract-TKDI7E56.js → command-contract-A6VZN3ZR.js} +11 -11
  58. package/dist/bundle/{echarts-QZ6PR3VC.js → echarts-27W2CIBD.js} +2 -2
  59. package/dist/bundle/{embed-UBXCXSRD.js → embed-FGJ273X2.js} +2 -2
  60. package/dist/bundle/{embedder-B4ZTKC23.js → embedder-7ELL3CQ3.js} +5 -5
  61. package/dist/bundle/{entry-BTUTHO5M.js → entry-SEE5YWIX.js} +3 -3
  62. package/dist/bundle/{first-run-UC4HRIFV.js → first-run-BD7FEC3W.js} +5 -5
  63. package/dist/bundle/{first-screen-SMCX6YKY.js → first-screen-ASZV6LSA.js} +12 -12
  64. package/dist/bundle/{identity-QSDEGDH7.js → identity-QR4F42T6.js} +1 -1
  65. package/dist/bundle/{instructions-BBGLZKO3.js → instructions-L74K64PV.js} +1 -1
  66. package/dist/bundle/{node-LZZX22VR.js → node-RSL3HANO.js} +2 -2
  67. package/dist/bundle/{node-sqlite-BPGT6T5U.js → node-sqlite-7R3PYQGJ.js} +2 -2
  68. package/dist/bundle/{oauth-XNE2KPKJ.js → oauth-4ESGXF6U.js} +5 -5
  69. package/dist/bundle/{open-SXGYZLB5.js → open-DFYEUGTA.js} +1 -1
  70. package/dist/bundle/{process-GPUXC4PG.js → process-RMV3AKLB.js} +1 -1
  71. package/dist/bundle/{program-NEXEAL7T.js → program-PIUYQHBF.js} +54 -59
  72. package/dist/bundle/{prompt-SORGLEYI.js → prompt-H7GYQQLL.js} +2 -2
  73. package/dist/bundle/{recognize-UJBXORVD.js → recognize-3GMOLZF4.js} +3 -3
  74. package/dist/bundle/{remote-W72AR7KH.js → remote-IRWTCI2B.js} +3 -3
  75. package/dist/bundle/{rerank-3Y2VZM3J.js → rerank-W3OSXXBN.js} +3 -3
  76. package/dist/bundle/{serve-VDZIVOPR.js → serve-ZCPO44NO.js} +7 -7
  77. package/dist/bundle/{server-ZFHN4GUF.js → server-FXU4QFRB.js} +35 -32
  78. package/dist/bundle/{server-BERXP4GW.js → server-YWL4HDOP.js} +68 -59
  79. package/dist/bundle/{state-DGR4EE3E.js → state-MJPTDIB5.js} +3 -3
  80. package/dist/bundle/{store-MRCFSCZD.js → store-6VNQG56O.js} +7 -7
  81. package/dist/bundle/store-maintenance-command-62TQTMER.js +43 -0
  82. package/dist/bundle/tg.js +2 -2
  83. package/dist/telegram/sending.d.ts.map +1 -1
  84. package/dist/telegram/sending.js +52 -3
  85. package/dist/telegram/sending.js.map +1 -1
  86. package/dist/version.d.ts +1 -1
  87. package/dist/version.js +1 -1
  88. package/package.json +2 -2
  89. package/dist/bundle/chunk-22PQUX72.js +0 -190
  90. package/dist/bundle/chunk-CJ6IYCYP.js +0 -583
  91. package/dist/bundle/chunk-NKJJJAIJ.js +0 -237
  92. package/dist/bundle/chunk-NMGO6LW6.js +0 -1950
  93. package/dist/bundle/chunk-OILBDLWL.js +0 -724
  94. package/dist/bundle/chunk-OPBTNQ35.js +0 -1007
  95. package/dist/bundle/store-maintenance-command-DCMZDMYS.js +0 -46
@@ -1,59 +1,59 @@
1
1
  import { createRequire as __tgRequire } from "node:module";
2
2
  const require = __tgRequire(import.meta.url);
3
- import {
4
- FloodMemory,
5
- RecipientList,
6
- ceilingRefusal,
7
- floodPathFor,
8
- guardFor,
9
- holdEnd,
10
- recipientsPathFor,
11
- withFileLockAsync
12
- } from "./chunk-CJ6IYCYP.js";
13
3
  import {
14
4
  OFFLINE,
15
5
  capability,
16
6
  chatIdIn,
7
+ foldName,
8
+ isId,
9
+ pickPerson,
17
10
  refuseLacking,
18
11
  servicesFor,
19
12
  throughWrapper
20
- } from "./chunk-DYNSP6FW.js";
21
- import {
22
- foldName,
23
- isId,
24
- pickPerson
25
- } from "./chunk-OILBDLWL.js";
13
+ } from "./chunk-FBWOQMPE.js";
26
14
  import {
15
+ CEILING_KEY,
16
+ LOG_ATTRIBUTES,
17
+ WRITE_KEYS,
27
18
  asFirstWord,
28
19
  baseContext,
20
+ codeOf,
21
+ currentOperation,
22
+ currentRun,
29
23
  environmentOf,
30
- isCliFailure,
24
+ fromLogAttributes,
31
25
  issueMessage,
26
+ keyForCommand,
27
+ keyForWrite,
28
+ levelFor,
29
+ logAttributes,
32
30
  permissionIssues,
33
- providerErrorKey,
34
31
  publicIssue,
32
+ readKeysForCommand,
35
33
  recalledAccount,
36
34
  rememberAccount,
37
- rootOf2 as rootOf
38
- } from "./chunk-RVCS7Q3A.js";
39
- import {
40
- CEILING_KEY,
41
- WRITE_KEYS,
42
- codeOf,
43
- currentOperation,
44
- keyForCommand,
45
- levelFor,
46
- readKeysForCommand,
35
+ rootOf2 as rootOf,
47
36
  skipFlagFor
48
- } from "./chunk-OPBTNQ35.js";
37
+ } from "./chunk-GSKFAE3I.js";
38
+ import {
39
+ isCliFailure,
40
+ providerErrorKey
41
+ } from "./chunk-DE7LFMY2.js";
42
+ import {
43
+ MESSENGER_CHANGE_REFUSAL,
44
+ readOnlyRefusal
45
+ } from "./chunk-2SUTCDGO.js";
49
46
  import {
50
47
  servingProfiles
51
- } from "./chunk-QYVVRQTN.js";
48
+ } from "./chunk-W5EB4JLV.js";
52
49
  import {
53
50
  openStore
54
- } from "./chunk-PUBS2F5J.js";
51
+ } from "./chunk-TV5DGHBT.js";
55
52
  import {
56
- resolvePaths
53
+ logRecordOf,
54
+ realSleep,
55
+ resolvePaths,
56
+ writeSecurely
57
57
  } from "./chunk-DG62L57H.js";
58
58
  import {
59
59
  CliError
@@ -62,7 +62,7 @@ import {
62
62
  __name
63
63
  } from "./chunk-AFV74GK3.js";
64
64
 
65
- // node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
65
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
66
66
  import { openSync } from "node:fs";
67
67
  import { createInterface } from "node:readline";
68
68
  import { ReadStream } from "node:tty";
@@ -117,11 +117,551 @@ var terminalAsker = /* @__PURE__ */ __name((command) => async (key, request) =>
117
117
  throw new CliError("cancelled", `${key}: not done \u2014 the answer was no`);
118
118
  }, "terminalAsker");
119
119
 
120
- // node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/sends/pace.js
121
- import { readFileSync, renameSync, writeFileSync } from "node:fs";
122
- import { join } from "node:path";
120
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/guard.js
121
+ import { randomUUID } from "node:crypto";
122
+
123
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/flood.js
124
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
125
+ import { dirname, join } from "node:path";
126
+ var MOST_DEADLINES = 50;
127
+ var LIMITED_HOLD_MS = 60 * 60 * 1e3;
128
+ var FROZEN_HOLD_MS = 24 * 60 * 60 * 1e3;
129
+ var NO_END = "9999-12-31T23:59:59.999Z";
130
+ var holdEnd = /* @__PURE__ */ __name((block, show = (iso) => iso) => block.until === null ? "until lifted" : `until ${show(block.until)}`, "holdEnd");
131
+ var floodPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "flood", `${profile}.json`), "floodPathFor");
132
+ var FloodMemory = class {
133
+ static {
134
+ __name(this, "FloodMemory");
135
+ }
136
+ path;
137
+ now;
138
+ constructor(path, now = Date.now) {
139
+ this.path = path;
140
+ this.now = now;
141
+ }
142
+ /** What is still in force; anything expired is left out. */
143
+ read() {
144
+ const now = this.now();
145
+ let raw;
146
+ try {
147
+ raw = JSON.parse(readFileSync(this.path, "utf8"));
148
+ } catch {
149
+ return { deadlines: [] };
150
+ }
151
+ const alive = /* @__PURE__ */ __name((until) => typeof until === "string" && Date.parse(until) > now, "alive");
152
+ const deadlines = Array.isArray(raw.deadlines) ? raw.deadlines.filter((one) => typeof one?.operation === "string" && alive(one.until)) : [];
153
+ const block = raw.sendBlock && (raw.sendBlock.until === NO_END ? { ...raw.sendBlock, until: null } : raw.sendBlock);
154
+ const held = block && (block.until === null || alive(block.until));
155
+ return { deadlines, ...held ? { sendBlock: block } : {} };
156
+ }
157
+ /** The deadline this call is still under: one for its chat, or one for the call in every chat. */
158
+ owed(operation, chatId) {
159
+ return this.read().deadlines.filter((one) => one.operation === operation && (one.chatId === void 0 || one.chatId === chatId)).sort((a, b) => b.until.localeCompare(a.until))[0];
160
+ }
161
+ remember(deadline) {
162
+ const { waitMs, ...rest } = deadline;
163
+ const kept = { ...rest, until: new Date(this.now() + waitMs).toISOString() };
164
+ const state = this.read();
165
+ const others = state.deadlines.filter((one) => one.operation !== kept.operation || one.chatId !== kept.chatId);
166
+ const deadlines = [...others, kept].sort((a, b) => b.until.localeCompare(a.until)).slice(0, MOST_DEADLINES);
167
+ this.#write({ ...state, deadlines });
168
+ return kept;
169
+ }
170
+ sendBlock() {
171
+ return this.read().sendBlock;
172
+ }
173
+ /** A ban the messenger gave no end for holds until lifted; a spam limit or a freeze without one, for a while. */
174
+ block(block) {
175
+ const now = this.now();
176
+ const holdMs = { limited: LIMITED_HOLD_MS, frozen: FROZEN_HOLD_MS, banned: void 0 }[block.state];
177
+ const kept = {
178
+ ...block,
179
+ since: new Date(now).toISOString(),
180
+ until: block.until ?? (holdMs === void 0 ? null : new Date(now + holdMs).toISOString())
181
+ };
182
+ this.#write({ ...this.read(), sendBlock: kept });
183
+ return kept;
184
+ }
185
+ /** Lifts only a block of this state: an account found not frozen may still be limited for spam. */
186
+ unblock(state) {
187
+ const { sendBlock, ...rest } = this.read();
188
+ if (sendBlock?.state === state)
189
+ this.#write(rest);
190
+ }
191
+ /** Forgets every wait and lifts the hold, and answers with what was still in force. */
192
+ clear() {
193
+ const cleared = this.read();
194
+ this.#write({ deadlines: [] });
195
+ return cleared;
196
+ }
197
+ #write({ sendBlock, ...rest }) {
198
+ const state = sendBlock ? { ...rest, sendBlock: { ...sendBlock, until: sendBlock.until ?? NO_END } } : rest;
199
+ mkdirSync(dirname(this.path), { recursive: true, mode: 448 });
200
+ const temporary = `${this.path}.${process.pid}.tmp`;
201
+ writeFileSync(temporary, `${JSON.stringify(state)}
202
+ `, { mode: 384 });
203
+ renameSync(temporary, this.path);
204
+ }
205
+ };
206
+
207
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/journal.js
208
+ import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2 } from "node:fs";
209
+ import { dirname as dirname3, join as join2 } from "node:path";
210
+
211
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/file-lock.js
212
+ import { closeSync, mkdirSync as mkdirSync2, openSync as openSync2, statSync, unlinkSync } from "node:fs";
213
+ import { dirname as dirname2 } from "node:path";
214
+ var LOCK_WAIT_MS = 5e3;
215
+ var LOCK_STALE_MS = 3e4;
216
+ var RETRY_MS = 20;
217
+ var pause = new Int32Array(new SharedArrayBuffer(4));
218
+ var withFileLock = /* @__PURE__ */ __name((path, what2, body, waitMs = LOCK_WAIT_MS) => {
219
+ const lock = lockFor(path);
220
+ const deadline = Date.now() + waitMs;
221
+ while (!taken(lock)) {
222
+ if (Date.now() >= deadline)
223
+ throw lockTimeout(what2, waitMs, lock);
224
+ Atomics.wait(pause, 0, 0, RETRY_MS);
225
+ }
226
+ return holding(lock, body);
227
+ }, "withFileLock");
228
+ var withFileLockAsync = /* @__PURE__ */ __name(async (path, what2, body, waitMs = LOCK_WAIT_MS, sleep = realSleep) => {
229
+ const lock = lockFor(path);
230
+ const deadline = Date.now() + waitMs;
231
+ while (!taken(lock)) {
232
+ if (Date.now() >= deadline)
233
+ throw lockTimeout(what2, waitMs, lock);
234
+ await sleep(RETRY_MS);
235
+ }
236
+ return holding(lock, body);
237
+ }, "withFileLockAsync");
238
+ var lockFor = /* @__PURE__ */ __name((path) => {
239
+ mkdirSync2(dirname2(path), { recursive: true, mode: 448 });
240
+ return `${path}.lock`;
241
+ }, "lockFor");
242
+ var taken = /* @__PURE__ */ __name((lock) => {
243
+ for (; ; ) {
244
+ try {
245
+ closeSync(openSync2(lock, "wx", 384));
246
+ return true;
247
+ } catch (error) {
248
+ if (error.code !== "EEXIST")
249
+ throw error;
250
+ if (Date.now() - lockTime(lock) <= LOCK_STALE_MS)
251
+ return false;
252
+ try {
253
+ unlinkSync(lock);
254
+ } catch {
255
+ }
256
+ }
257
+ }
258
+ }, "taken");
259
+ var holding = /* @__PURE__ */ __name((lock, body) => {
260
+ try {
261
+ return body();
262
+ } finally {
263
+ try {
264
+ unlinkSync(lock);
265
+ } catch {
266
+ }
267
+ }
268
+ }, "holding");
269
+ var lockTimeout = /* @__PURE__ */ __name((what2, waitMs, lock) => new CliError("timeout", `${what2} stayed locked for ${waitMs / 1e3}s (${lock})`), "lockTimeout");
270
+ var lockTime = /* @__PURE__ */ __name((lock) => {
271
+ try {
272
+ return statSync(lock).mtimeMs;
273
+ } catch {
274
+ return Date.now();
275
+ }
276
+ }, "lockTime");
277
+
278
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/journal.js
279
+ var sendsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join2(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "sends", `${profile}.jsonl`), "sendsPathFor");
280
+ var SendJournal = class {
281
+ static {
282
+ __name(this, "SendJournal");
283
+ }
284
+ path;
285
+ resource;
286
+ constructor(path, resource = { service: "unknown", version: "unknown" }) {
287
+ this.path = path;
288
+ this.resource = resource;
289
+ }
290
+ /**
291
+ * Runs `body` with the journal to itself, across processes: two sends at the limit must not both
292
+ * read "one left". A lock file opened with `wx`, because `flock` is not there on Windows.
293
+ */
294
+ locked(body) {
295
+ return withFileLock(this.path, "the send journal", body);
296
+ }
297
+ /** `locked` without blocking the thread while another process holds the journal: what `serve` uses. */
298
+ lockedAsync(body) {
299
+ return withFileLockAsync(this.path, "the send journal", body);
300
+ }
301
+ append(entry) {
302
+ const { at, ...attributes } = entry;
303
+ const { runId, command, traceId } = currentRun();
304
+ const record = logRecordOf({
305
+ severity: entry.outcome === "sent" || entry.outcome === "reserved" ? "info" : "warn",
306
+ event: logAttributes({ event: "send.recorded", ...attributes }),
307
+ time: at,
308
+ runId,
309
+ ...traceId === void 0 ? {} : { traceId },
310
+ command,
311
+ resource: this.resource,
312
+ allow: LOG_ATTRIBUTES
313
+ });
314
+ mkdirSync3(dirname3(this.path), { recursive: true, mode: 448 });
315
+ appendFileSync(this.path, `${JSON.stringify(record)}
316
+ `, { mode: 384 });
317
+ }
318
+ /**
319
+ * Oldest first, each reservation folded into its outcome; one with no outcome yet is in flight,
320
+ * or its process died. A line that does not parse is skipped: a torn last write must not block sending.
321
+ */
322
+ entries(filter) {
323
+ const lines = this.#lines();
324
+ const settled2 = new Set(lines.filter((entry) => entry.outcome !== "reserved").map((entry) => entry.reservation));
325
+ const entries = lines.filter((entry) => entry.outcome !== "reserved" || !settled2.has(entry.reservation)).map(({ reservation, ...entry }) => entry.outcome === "reserved" ? { ...entry, reservation } : entry).map(withSendId);
326
+ return filter === void 0 ? entries : entries.filter((entry) => (filter.outcome === void 0 || entry.outcome === filter.outcome) && (filter.chatId === void 0 || entry.chatId === filter.chatId) && (filter.operationId === void 0 || entry.operationId === filter.operationId) && (filter.errorCode === void 0 || entry.errorCode === filter.errorCode) && (filter.key === void 0 || entry.key === filter.key));
327
+ }
328
+ #lines() {
329
+ let text;
330
+ try {
331
+ text = readFileSync2(this.path, "utf8");
332
+ } catch {
333
+ return [];
334
+ }
335
+ return text.split("\n").filter((line) => line.trim() !== "").flatMap((line) => {
336
+ try {
337
+ return [entryOf(JSON.parse(line))];
338
+ } catch {
339
+ return [];
340
+ }
341
+ });
342
+ }
343
+ };
344
+ var entryOf = /* @__PURE__ */ __name((line) => {
345
+ if (!("attributes" in line))
346
+ return line;
347
+ const { event: _, ...attributes } = line.attributes;
348
+ return { at: line.time, ...fromLogAttributes(attributes) };
349
+ }, "entryOf");
350
+ var withSendId = /* @__PURE__ */ __name((entry) => {
351
+ const { cid, ...rest } = entry;
352
+ return cid === void 0 || rest.sendId !== void 0 ? rest : { ...rest, sendId: String(cid) };
353
+ }, "withSendId");
354
+
355
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/recipients.js
356
+ import { existsSync, readFileSync as readFileSync3, rmSync } from "node:fs";
357
+ import { join as join3 } from "node:path";
358
+ var recipientsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "profiles", `${profile}.recipients.json`), "recipientsPathFor");
359
+ var RecipientList = class {
360
+ static {
361
+ __name(this, "RecipientList");
362
+ }
363
+ path;
364
+ command;
365
+ lockWaitMs;
366
+ /** `command` names the program in the hint that turns the list off. */
367
+ constructor(path, command, lockWaitMs) {
368
+ this.path = path;
369
+ this.command = command;
370
+ this.lockWaitMs = lockWaitMs;
371
+ }
372
+ /** `undefined` when the list is off. A file that cannot be read refuses rather than opening up. */
373
+ read() {
374
+ if (!existsSync(this.path))
375
+ return void 0;
376
+ try {
377
+ const parsed = JSON.parse(readFileSync3(this.path, "utf8"));
378
+ if (!Array.isArray(parsed.chats))
379
+ throw new Error("no `chats` array");
380
+ return parsed.chats;
381
+ } catch (error) {
382
+ throw new CliError("configuration_error", `the recipient list ${this.path} cannot be read (${error instanceof Error ? error.message : String(error)}) \u2014 fix the file or turn the list off with \`${this.command} recipients clear\``);
383
+ }
384
+ }
385
+ list(filter = {}) {
386
+ const chats = this.read();
387
+ return {
388
+ state: chats === void 0 ? "off" : chats.length === 0 ? "empty" : "on",
389
+ items: (chats ?? []).filter((chat) => (filter.id === void 0 || chat.id === filter.id) && (filter.title === void 0 || chat.title?.toLocaleLowerCase() === filter.title.toLocaleLowerCase()))
390
+ };
391
+ }
392
+ /** Whether it was new. Adding one again fills in a partner an older entry was stored without. */
393
+ add(recipient) {
394
+ return this.#locked(() => this.#added(recipient));
395
+ }
396
+ /** `add` waiting for the lock on timers: `recipients add` connects, so it runs inside `serve` when one holds the account. */
397
+ addAsync(recipient) {
398
+ return withFileLockAsync(this.path, "the recipient list", () => this.#added(recipient), this.lockWaitMs);
399
+ }
400
+ #added(recipient) {
401
+ const chats = this.read() ?? [];
402
+ const known = chats.find((chat) => chat.id === recipient.id);
403
+ if (known) {
404
+ if (recipient.partnerId && !known.partnerId) {
405
+ this.#write(chats.map((chat) => chat === known ? { ...known, partnerId: recipient.partnerId } : chat));
406
+ }
407
+ return false;
408
+ }
409
+ this.#write([...chats, recipient]);
410
+ return true;
411
+ }
412
+ /** The id or the title as it was stored; `undefined` when neither matched. */
413
+ remove(reference) {
414
+ return this.#locked(() => {
415
+ const chats = this.read() ?? [];
416
+ const wanted = reference.trim();
417
+ const gone = chats.find((chat) => chat.id === wanted) ?? chats.find((chat) => chat.title?.toLocaleLowerCase() === wanted.toLocaleLowerCase());
418
+ if (gone)
419
+ this.#write(chats.filter((chat) => chat !== gone));
420
+ return gone;
421
+ });
422
+ }
423
+ /**
424
+ * The chat the messenger now names `to`: its entry, and a partner of that id, follow it. Only an entry already there
425
+ * changes, and no list is created, so the list never opens up. Whether anything changed.
426
+ */
427
+ async rekey(from, to) {
428
+ if (from === to)
429
+ return false;
430
+ return withFileLockAsync(this.path, "the recipient list", () => {
431
+ const chats = this.read();
432
+ if (!chats?.some((chat) => chat.id === from || chat.partnerId === from))
433
+ return false;
434
+ const held = chats.some((chat) => chat.id === to);
435
+ this.#write(chats.filter((chat) => !(held && chat.id === from)).map((chat) => ({
436
+ ...chat,
437
+ ...chat.id === from ? { id: to } : {},
438
+ ...chat.partnerId === from ? { partnerId: to } : {}
439
+ })));
440
+ return true;
441
+ }, this.lockWaitMs);
442
+ }
443
+ /** Whether there was a list to turn off. */
444
+ off() {
445
+ return this.#locked(() => {
446
+ if (!existsSync(this.path))
447
+ return false;
448
+ rmSync(this.path);
449
+ return true;
450
+ });
451
+ }
452
+ /**
453
+ * Every change reads and writes under one lock: a `serve` re-keying while the owner removes a chat must not write
454
+ * the removed chat back. A lock held too long refuses the change and leaves the list as it was. Blocks the thread
455
+ * while it waits: for callers that cannot be async, and `recipients remove` and `clear`, which never
456
+ * connect and so never run inside `serve`.
457
+ */
458
+ #locked(body) {
459
+ return withFileLock(this.path, "the recipient list", body, this.lockWaitMs);
460
+ }
461
+ #write(chats) {
462
+ writeSecurely(this.path, `${JSON.stringify({ chats }, null, 2)}
463
+ `, 384);
464
+ }
465
+ };
466
+
467
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/guard.js
468
+ var HOUR_MS = 60 * 60 * 1e3;
469
+ var READS_UNDER_HOLD = /* @__PURE__ */ new Set([
470
+ "attachments.extract",
471
+ "conversations.embeddings",
472
+ "conversations.links",
473
+ "messages.server-search",
474
+ "messages.sync-first",
475
+ "stats.contacts.top.sync-first",
476
+ "stats.messages.counters.sync",
477
+ "stats.messages.show.sync-first",
478
+ "stats.messages.top.sync-first",
479
+ "store.gaps.repair"
480
+ ]);
481
+ var countsTowardLimit = /* @__PURE__ */ __name(({ kind = "message", action, notify }) => kind === "message" || kind === "forward" || kind === "edit" || kind === "delete" || kind === "pin" && notify === true || action === "create" || action === "members.add" || action === "requests.accept" || action === "join" || action === "contact-import", "countsTowardLimit");
482
+ var weightOf = /* @__PURE__ */ __name(({ kind = "message", action, count, people }) => kind === "delete" || kind === "message" && action === void 0 ? Math.max(1, count ?? 1) : action === "create" || action === "members.add" || action === "requests.accept" || action === "contact-import" ? Math.max(1, people ?? count ?? 1) : 1, "weightOf");
483
+ var timeOf = /* @__PURE__ */ __name((entry) => Date.parse(entry.scheduledFor ?? entry.at), "timeOf");
484
+ var ceilingRefusal = /* @__PURE__ */ __name((key, command) => new CliError("permission_error", `${key} is not allowed: setup's answer keeps every WireCat tool read-only; the owner changes it at a terminal with \`${command} setup\``, { permission: key }), "ceilingRefusal");
485
+ var levelRefusal = /* @__PURE__ */ __name((refused, fix = `${refused.command} ${refused.profile} config set permissions.${refused.key} allow`) => refused.named === CEILING_KEY ? ceilingRefusal(refused.key, refused.command) : new CliError("permission_error", `profile ${refused.profile} does not let ${refused.key} write (permissions.${refused.named} is ${refused.level}, from the ${refused.permissionSources[refused.named ?? ""] ?? "default"}); to allow it: ${fix}`, { permission: refused.key }), "levelRefusal");
486
+ var sendGuard = /* @__PURE__ */ __name(({ profile, recipients, command = recipients.command, readOnlyLock, permissions, permissionSources = {}, permissionDefaults, permissionFix, ask = refuseToAsk, sendsPerHour, journal, flood, warn, now = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now") }) => {
487
+ const currentPermissions = /* @__PURE__ */ __name(() => typeof permissions === "function" ? permissions() : permissions, "currentPermissions");
488
+ let reservation;
489
+ const answered = /* @__PURE__ */ new WeakSet();
490
+ const refuseReadOnly = /* @__PURE__ */ __name(() => {
491
+ if (readOnlyLock)
492
+ throw readOnlyRefusal(readOnlyLock, MESSENGER_CHANGE_REFUSAL);
493
+ }, "refuseReadOnly");
494
+ const refuseHeld = /* @__PURE__ */ __name(({ key }) => {
495
+ if (key !== void 0 && READS_UNDER_HOLD.has(key))
496
+ return;
497
+ const block = flood?.sendBlock();
498
+ if (!block)
499
+ return;
500
+ throw new CliError("permission_error", `profile ${profile} holds its writes ${holdEnd(block)}: ${block.hint} \u2014 reads still work; do not retry: the owner checks the account with \`${command} ${profile} doctor --online\`, and lifts the hold with \`${command} ${profile} flood clear\` once it is over`, { sendBlock: block, standing: { state: block.state, hint: block.hint } });
501
+ }, "refuseHeld");
502
+ const permitted = /* @__PURE__ */ __name((request) => {
503
+ const { chatId, kind = "message", action, personIds } = request;
504
+ refuseReadOnly();
505
+ const levels = currentPermissions();
506
+ if (levels !== void 0) {
507
+ const key = request.key ?? keyForWrite(kind, action);
508
+ const { level, key: named } = levelFor(levels, key, permissionDefaults);
509
+ if (level === "deny" || level === "readonly")
510
+ throw levelRefusal({ profile, command, key, level, named, permissionSources }, permissionFix?.(request, key));
511
+ if (level === "ask" && !answered.has(request)) {
512
+ throw new CliError("confirmation_required", `${key} asks before it acts, and it was not asked`);
513
+ }
514
+ }
515
+ const allowed = recipients.read();
516
+ if (chatId !== null && allowed && !allowed.some((chat) => chat.id === chatId)) {
517
+ throw new CliError("confirmation_required", `chat ${chatId} is not on the recipient list of profile ${profile} \u2014 the owner adds it with \`${command} ${profile} recipients add ${chatId}\``, { chat_id: chatId });
518
+ }
519
+ const strangers = allowed ? (personIds ?? []).filter((id) => !allowed.some((chat) => chat.partnerId === id)) : [];
520
+ if (strangers.length > 0) {
521
+ throw new CliError("confirmation_required", `${strangers.join(", ")} ${strangers.length === 1 ? "is" : "are"} not on the recipient list of profile ${profile} \u2014 the owner adds the one-to-one chat with each person (\`${command} ${profile} recipients add <chat>\`); a chat added to the list earlier is added again to be recognised`, { person_ids: strangers });
522
+ }
523
+ }, "permitted");
524
+ const withinLimit = /* @__PURE__ */ __name((request, entries) => {
525
+ const { chatId, sendId } = request;
526
+ const asked = { ...request, people: request.personIds?.length ?? request.count };
527
+ const count = weightOf(asked);
528
+ if (count > sendsPerHour) {
529
+ throw new CliError("rate_limited", `${count} at once is more than the hourly limit of profile ${profile} (sendsPerHour ${sendsPerHour}) \u2014 do fewer at a time`);
530
+ }
531
+ const at = request.scheduledFor ? Date.parse(request.scheduledFor) : now().getTime();
532
+ const counted = entries.filter(countsTowardLimit).filter((entry) => entry.outcome === "sent" || entry.outcome === "outcome_unknown" || entry.outcome === "reserved").filter((entry) => Math.abs(timeOf(entry) - at) < HOUR_MS);
533
+ const unsure = /* @__PURE__ */ __name((entry) => entry.outcome === "outcome_unknown", "unsure");
534
+ const same = /* @__PURE__ */ __name((a, b) => a.sendId !== void 0 && a.sendId === b.sendId && a.chatId === b.chatId, "same");
535
+ const last = [...counted].reverse().find((entry) => same(entry, { chatId, sendId }));
536
+ if (sendId !== void 0 && last && unsure(last)) {
537
+ if (last.sendAs !== request.sendAs) {
538
+ throw new CliError("validation_error", "this send id was tried under another identity; repeat it with the same --send-as, or it may post twice", { operation_id: sendId, retryable: false });
539
+ }
540
+ return false;
541
+ }
542
+ const recent = counted.filter((entry, index) => !(unsure(entry) && counted.slice(index + 1).some((later) => same(later, entry)))).map((entry) => ({ time: timeOf(entry), weight: weightOf(entry) })).sort((a, b) => a.time - b.time);
543
+ const used = recent.reduce((sum, { weight }) => sum + weight, 0);
544
+ if (used + count > sendsPerHour) {
545
+ let freed = 0;
546
+ const opening = recent.find(({ weight }) => {
547
+ freed += weight;
548
+ return used - freed + count <= sendsPerHour;
549
+ });
550
+ const nextMs = (opening?.time ?? 0) + HOUR_MS;
551
+ const next = new Date(nextMs).toISOString();
552
+ throw new CliError("rate_limited", `profile ${profile} has sent ${used} messages in the hour around ${new Date(at).toISOString()}, and its limit is ${sendsPerHour} (sendsPerHour) \u2014 the next send is possible at ${next}`, { retry_after_ms: nextMs - now().getTime(), retry_at: next });
553
+ }
554
+ return true;
555
+ }, "withinLimit");
556
+ const counting = /* @__PURE__ */ __name((request) => {
557
+ permitted(request);
558
+ refuseHeld(request);
559
+ const asked = { ...request, people: request.personIds?.length ?? request.count };
560
+ const creatingTopic = request.kind === "chat" && request.action === "topic-create";
561
+ if (!countsTowardLimit(asked) && !creatingTopic)
562
+ return void 0;
563
+ const checked = /* @__PURE__ */ __name((entries) => {
564
+ if (!creatingTopic)
565
+ return withinLimit(request, entries);
566
+ if (request.sendId === void 0)
567
+ throw new CliError("validation_error", "a topic creation needs an attempt id");
568
+ if (entries.some((entry) => entry.action === "topic-create" && entry.sendId === request.sendId && ["sent", "outcome_unknown", "reserved"].includes(entry.outcome))) {
569
+ throw new CliError("validation_error", "this topic creation was already attempted; check topics list and do not repeat an unknown creation", { operation_id: request.sendId, retryable: false });
570
+ }
571
+ return true;
572
+ }, "checked");
573
+ const reserving = /* @__PURE__ */ __name(() => {
574
+ if (!checked(journal.entries()))
575
+ return;
576
+ const id = randomUUID();
577
+ const { chatId, kind, action, sendId, operationId, scheduledFor, notify } = request;
578
+ journal.append({
579
+ at: now().toISOString(),
580
+ profile,
581
+ chatId,
582
+ outcome: "reserved",
583
+ reservation: id,
584
+ ...kind ? { kind } : {},
585
+ ...action ? { action } : {},
586
+ ...asked.people === void 0 ? {} : kind === "delete" || kind === "message" || kind === void 0 ? { count: asked.people } : { people: asked.people },
587
+ ...sendId === void 0 ? {} : { sendId },
588
+ ...operationId === void 0 ? {} : { operationId },
589
+ ...scheduledFor ? { scheduledFor } : {},
590
+ ...notify === void 0 ? {} : { notify }
591
+ });
592
+ reservation = id;
593
+ }, "reserving");
594
+ return { checked, reserving };
595
+ }, "counting");
596
+ return {
597
+ ask: /* @__PURE__ */ __name(async (request) => {
598
+ refuseReadOnly();
599
+ const levels = currentPermissions();
600
+ if (levels === void 0)
601
+ return;
602
+ const key = request.key ?? keyForWrite(request.kind ?? "message", request.action);
603
+ if (levelFor(levels, key, permissionDefaults).level !== "ask")
604
+ return;
605
+ refuseHeld(request);
606
+ await ask(key, request);
607
+ answered.add(request);
608
+ }, "ask"),
609
+ check: /* @__PURE__ */ __name((request, { reserve = true } = {}) => {
610
+ const counted = counting(request);
611
+ if (!counted)
612
+ return;
613
+ if (reserve)
614
+ journal.locked(counted.reserving);
615
+ else
616
+ counted.checked(journal.entries());
617
+ }, "check"),
618
+ reserve: /* @__PURE__ */ __name(async (request) => {
619
+ const counted = counting(request);
620
+ if (counted)
621
+ await journal.lockedAsync(counted.reserving);
622
+ }, "reserve"),
623
+ // After a send, a failure to write here must not become the command's answer: the message is
624
+ // already with a person, and an error would invite the caller to send it again.
625
+ record: /* @__PURE__ */ __name((entry) => {
626
+ const { personIds: _, ...kept } = entry;
627
+ const settles = entry.outcome === "refused" ? void 0 : reservation;
628
+ reservation = void 0;
629
+ try {
630
+ journal.append({ at: now().toISOString(), profile, ...kept, ...settles ? { reservation: settles } : {} });
631
+ } catch (error) {
632
+ warn(`this send is not in the send journal: ${journalFailure(error)}`, {
633
+ event: "warning",
634
+ code: "send_not_journaled",
635
+ operation: "sends.journal"
636
+ });
637
+ }
638
+ }, "record")
639
+ };
640
+ }, "sendGuard");
641
+ var refuseToAsk = /* @__PURE__ */ __name(async (key) => {
642
+ throw new CliError("confirmation_required", `${key} asks before it acts (its permission level is ask), and nobody is here to answer \u2014 add ${skipFlagFor(key)} to go ahead`);
643
+ }, "refuseToAsk");
644
+ var guardFor = /* @__PURE__ */ __name((app, settings, warn, env = process.env, ask) => sendGuard({
645
+ profile: settings.profile,
646
+ command: app.command,
647
+ ...settings.readOnlyLock ? { readOnlyLock: settings.readOnlyLock } : {},
648
+ permissions: /* @__PURE__ */ __name(() => settings.permissions, "permissions"),
649
+ permissionSources: settings.permissionSources,
650
+ ...settings.permissionDefaults ? { permissionDefaults: settings.permissionDefaults } : {},
651
+ ...ask ? { ask } : {},
652
+ sendsPerHour: settings.sendsPerHour,
653
+ journal: new SendJournal(sendsPathFor(app, settings.profile, env), { service: app.command, version: app.version }),
654
+ recipients: new RecipientList(recipientsPathFor(app, settings.profile, env), app.command),
655
+ flood: new FloodMemory(floodPathFor(app, settings.profile, env)),
656
+ warn
657
+ }), "guardFor");
658
+ var journalFailure = /* @__PURE__ */ __name((error) => error?.code ?? (error instanceof Error ? error.name : "error"), "journalFailure");
659
+
660
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/sends/pace.js
661
+ import { readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
662
+ import { join as join4 } from "node:path";
123
663
  var DEFAULT_PACE = { perMinute: 60, burst: 20 };
124
- var pacePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "pace", `${profile}.json`), "pacePathFor");
664
+ var pacePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join4(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "pace", `${profile}.json`), "pacePathFor");
125
665
  var Pacer = class {
126
666
  static {
127
667
  __name(this, "Pacer");
@@ -163,7 +703,7 @@ var Pacer = class {
163
703
  }
164
704
  read() {
165
705
  try {
166
- const tat = Number(JSON.parse(readFileSync(this.path, "utf8")).tat);
706
+ const tat = Number(JSON.parse(readFileSync4(this.path, "utf8")).tat);
167
707
  return Number.isFinite(tat) ? tat : 0;
168
708
  } catch {
169
709
  return 0;
@@ -171,12 +711,12 @@ var Pacer = class {
171
711
  }
172
712
  write(tat) {
173
713
  const temporary = `${this.path}.${process.pid}.tmp`;
174
- writeFileSync(temporary, JSON.stringify({ tat }), { mode: 384 });
175
- renameSync(temporary, this.path);
714
+ writeFileSync2(temporary, JSON.stringify({ tat }), { mode: 384 });
715
+ renameSync2(temporary, this.path);
176
716
  }
177
717
  };
178
718
 
179
- // node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
719
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
180
720
  var pathOf = /* @__PURE__ */ __name((command) => {
181
721
  const words = [];
182
722
  for (let at = command; at?.parent; at = at.parent)
@@ -236,7 +776,7 @@ var refuseUnknownPermissionKeys = /* @__PURE__ */ __name((command, settings, too
236
776
  throw new CliError("validation_error", `--permission ${key} names no command`, { permission: key });
237
777
  }, "refuseUnknownPermissionKeys");
238
778
 
239
- // node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/cli/messenger/flooded.js
779
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/cli/messenger/flooded.js
240
780
  var LONG_LIVED = /* @__PURE__ */ new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
241
781
  var LISTENING = /* @__PURE__ */ new Set(["watch", "feed", "listen", "listenHistory"]);
242
782
  var BLOCKING = /* @__PURE__ */ new Set(["frozen", "limited", "banned"]);
@@ -355,23 +895,31 @@ var flooded = /* @__PURE__ */ __name((messenger, memory, { name, warn, pacer })
355
895
  });
356
896
  }, "flooded");
357
897
 
358
- // node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
898
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
359
899
  var observed = /* @__PURE__ */ __name((messenger, events) => {
360
900
  const timed = /* @__PURE__ */ __name(async (operation, named, work, after) => {
361
901
  const write = currentOperation();
362
902
  const marked = /* @__PURE__ */ __name((part = {}) => write === void 0 ? part : { ...part, ids: { ...part.ids, operation: write } }, "marked");
363
- events({ event: "request", operation, ...marked(named) });
903
+ events({ event: "request", operation, level: "operation", ...marked(named) });
364
904
  const started = performance.now();
365
905
  const durationMs = /* @__PURE__ */ __name(() => Math.round(performance.now() - started), "durationMs");
366
906
  try {
367
907
  const answer = await work();
368
- events({ event: "response", operation, durationMs: durationMs(), outcome: "ok", ...marked(after?.(answer)) });
908
+ events({
909
+ event: "response",
910
+ operation,
911
+ level: "operation",
912
+ durationMs: durationMs(),
913
+ outcome: "ok",
914
+ ...marked(after?.(answer))
915
+ });
369
916
  return answer;
370
917
  } catch (error) {
371
918
  const providerError = isCliFailure(error) ? providerErrorKey(error.details?.provider_error) : void 0;
372
919
  events({
373
920
  event: "response",
374
921
  operation,
922
+ level: "operation",
375
923
  durationMs: durationMs(),
376
924
  outcome: "error",
377
925
  errorCode: isCliFailure(error) ? error.code : "generic_failure",
@@ -446,7 +994,7 @@ var byPart = /* @__PURE__ */ __name((batch, counts) => {
446
994
  counts[part] = (counts[part] ?? 0) + items.length;
447
995
  }, "byPart");
448
996
 
449
- // node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
997
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
450
998
  var REKEY_PACING = { lockMs: 50, pauseMs: 25 };
451
999
  var stored = /* @__PURE__ */ __name((messenger, { account, store, warn, events, pending, announcing, deletedWithoutChat, profile, rekeyed, rekeyPacing = REKEY_PACING, closing, namesFromStore, recipientIds, countsUnread = false }) => {
452
1000
  let warned = false;
@@ -537,13 +1085,13 @@ var stored = /* @__PURE__ */ __name((messenger, { account, store, warn, events,
537
1085
  }
538
1086
  if (round !== rekeyRound)
539
1087
  return;
540
- const taken = pass?.taken ?? rest.length;
541
- rekeysQueued -= taken;
1088
+ const taken2 = pass?.taken ?? rest.length;
1089
+ rekeysQueued -= taken2;
542
1090
  for (const { from, to } of pass?.applied ?? [])
543
1091
  await Promise.resolve().then(() => rekeyed?.(from, to)).catch((error) => notWritten("history.rekey", error));
544
1092
  for (const { error } of pass?.refused ?? [])
545
1093
  notWritten("history.rekey", error);
546
- rest = rest.slice(taken);
1094
+ rest = rest.slice(taken2);
547
1095
  if (rest.length > 0)
548
1096
  await new Promise((resolve) => setTimeout(resolve, rekeyPacing.pauseMs));
549
1097
  }
@@ -938,7 +1486,7 @@ var keep = /* @__PURE__ */ __name(async (store, account, event, seenAt, among, c
938
1486
  }
939
1487
  }, "keep");
940
1488
 
941
- // node_modules/.pnpm/@wirecat+cli-core@0.466.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._f7e4048410ccbe1e801fd184c043d197/node_modules/@wirecat/cli-core/dist/cli/messenger/context.js
1489
+ // node_modules/.pnpm/@wirecat+cli-core@0.467.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.64.0_commander@15._7a700db966f96e9df6d3178e7072efc2/node_modules/@wirecat/cli-core/dist/cli/messenger/context.js
942
1490
  var lazyStore = /* @__PURE__ */ __name((env, command, version) => {
943
1491
  let opened;
944
1492
  return {
@@ -1272,7 +1820,7 @@ var messengerContext = /* @__PURE__ */ __name((command, messenger, resolving = {
1272
1820
  offline: base.settings.offline,
1273
1821
  reads: messenger.history ?? "server",
1274
1822
  // Turning recording off by name (--no-record, or record: false) keeps no search history either.
1275
- history: base.settings.keepFailedRuns,
1823
+ history: base.settings.record,
1276
1824
  searchCatchUp: base.settings.searchCatchUp,
1277
1825
  pictures: base.settings.pictureSearch,
1278
1826
  reranker: base.settings.searchReranker,
@@ -1332,6 +1880,17 @@ var messengerContext = /* @__PURE__ */ __name((command, messenger, resolving = {
1332
1880
  export {
1333
1881
  answerOf,
1334
1882
  terminalAsker,
1883
+ holdEnd,
1884
+ floodPathFor,
1885
+ FloodMemory,
1886
+ sendsPathFor,
1887
+ SendJournal,
1888
+ recipientsPathFor,
1889
+ RecipientList,
1890
+ ceilingRefusal,
1891
+ levelRefusal,
1892
+ sendGuard,
1893
+ guardFor,
1335
1894
  DEFAULT_PACE,
1336
1895
  pacePathFor,
1337
1896
  Pacer,