@wirecat/cli-core 0.618.0 → 0.619.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 (274) hide show
  1. package/CHANGELOG.md +339 -1
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES +3 -0
  4. package/dist/background/daily-archive-timer.d.ts +1 -1
  5. package/dist/background/deliver.d.ts +5 -2
  6. package/dist/background/deliver.js +30 -12
  7. package/dist/background/report/render.d.ts +3 -1
  8. package/dist/background/report/render.js +3 -1
  9. package/dist/calendar/cli/answers.d.ts +1 -0
  10. package/dist/calendar/cli/answers.js +6 -1
  11. package/dist/calendar/cli/index.js +2 -14
  12. package/dist/calendar/cli/people-link.d.ts +3 -0
  13. package/dist/calendar/cli/people-link.js +23 -0
  14. package/dist/calendar/index.d.ts +1 -1
  15. package/dist/calendar/index.js +1 -1
  16. package/dist/calendar/mcp/index.d.ts +12 -12
  17. package/dist/cli/base-stages-command.d.ts +22 -0
  18. package/dist/cli/base-stages-command.js +174 -0
  19. package/dist/cli/command-runs.d.ts +2 -0
  20. package/dist/cli/command-runs.js +3 -1
  21. package/dist/cli/config-command.js +6 -1
  22. package/dist/cli/context.js +1 -0
  23. package/dist/cli/group-lock.d.ts +42 -0
  24. package/dist/cli/group-lock.js +130 -0
  25. package/dist/cli/index.d.ts +7 -2
  26. package/dist/cli/index.js +7 -2
  27. package/dist/cli/messenger/backfill-command.js +27 -15
  28. package/dist/cli/messenger/contacts-command.js +10 -3
  29. package/dist/cli/messenger/context.js +1 -0
  30. package/dist/cli/messenger/doctor-command.js +3 -1
  31. package/dist/cli/messenger/models-command.js +1 -1
  32. package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
  33. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  34. package/dist/cli/model-catalogue-command.d.ts +3 -1
  35. package/dist/cli/model-catalogue-command.js +46 -2
  36. package/dist/cli/profile.d.ts +8 -0
  37. package/dist/cli/profile.js +25 -0
  38. package/dist/cli/program.js +2 -0
  39. package/dist/cli/runs/search-query.d.ts +1 -1
  40. package/dist/cli/runs/search-query.js +4 -0
  41. package/dist/cli/runs/search.d.ts +5 -1
  42. package/dist/cli/runs/search.js +12 -1
  43. package/dist/cli/search-left-out.d.ts +6 -1
  44. package/dist/cli/search-left-out.js +9 -4
  45. package/dist/cli/settings.d.ts +8 -0
  46. package/dist/cli/settings.js +17 -2
  47. package/dist/cli/shared-command-exports.d.ts +16 -0
  48. package/dist/cli/store-recover.d.ts +3 -3
  49. package/dist/cli/store-recover.js +26 -26
  50. package/dist/cli/store-settings.d.ts +2 -0
  51. package/dist/cli/store-settings.js +37 -9
  52. package/dist/crm/cli/index.js +38 -6
  53. package/dist/crm/group-hint.d.ts +8 -0
  54. package/dist/crm/group-hint.js +13 -0
  55. package/dist/crm/source.d.ts +12 -1
  56. package/dist/crm/sync.d.ts +31 -2
  57. package/dist/crm/sync.js +110 -3
  58. package/dist/crm/testing/acme-scenario.d.ts +40 -0
  59. package/dist/crm/testing/acme-scenario.js +170 -0
  60. package/dist/crm/testing/index.d.ts +1 -0
  61. package/dist/crm/testing/index.js +1 -0
  62. package/dist/crm/testing/source-contract.js +12 -0
  63. package/dist/crm/testing/source.d.ts +2 -0
  64. package/dist/crm/testing/source.js +1 -0
  65. package/dist/domain/addresses.d.ts +13 -0
  66. package/dist/domain/addresses.js +63 -0
  67. package/dist/domain/categories.d.ts +3 -0
  68. package/dist/domain/categories.js +2 -0
  69. package/dist/domain/crm.d.ts +23 -0
  70. package/dist/domain/crm.js +7 -0
  71. package/dist/domain/mentions.d.ts +2 -12
  72. package/dist/domain/mentions.js +2 -19
  73. package/dist/domain/orders.d.ts +8 -1
  74. package/dist/domain/orders.js +6 -2
  75. package/dist/domain/phones.d.ts +26 -0
  76. package/dist/domain/phones.js +48 -0
  77. package/dist/domain/record-types.d.ts +1 -1
  78. package/dist/domain/record-types.js +1 -0
  79. package/dist/domain/records.d.ts +5 -0
  80. package/dist/domain/ref-summaries.d.ts +39 -0
  81. package/dist/domain/ref-summaries.js +51 -3
  82. package/dist/domain/relations.d.ts +12 -2
  83. package/dist/domain/relations.js +14 -3
  84. package/dist/domain/vcard.d.ts +2 -2
  85. package/dist/domain/vcard.js +4 -10
  86. package/dist/embeddings/models.d.ts +11 -3
  87. package/dist/embeddings/models.js +28 -4
  88. package/dist/entities/business-context.d.ts +149 -0
  89. package/dist/entities/business-context.js +192 -0
  90. package/dist/entities/contact-activity.d.ts +2 -0
  91. package/dist/entities/contact-activity.js +7 -1
  92. package/dist/entities/contact-context.d.ts +157 -0
  93. package/dist/entities/contact-context.js +2 -0
  94. package/dist/entities/deal.d.ts +10 -0
  95. package/dist/entities/deal.js +2 -0
  96. package/dist/entities/index.d.ts +23 -3
  97. package/dist/entities/index.js +5 -0
  98. package/dist/entities/mention.d.ts +4 -3
  99. package/dist/entities/mention.js +2 -1
  100. package/dist/entities/message-transfer.d.ts +4 -2
  101. package/dist/entities/message-transfer.js +2 -2
  102. package/dist/entities/model.d.ts +2 -2
  103. package/dist/entities/model.js +1 -1
  104. package/dist/entities/relationship.d.ts +4 -0
  105. package/dist/entities/relationship.js +4 -0
  106. package/dist/errors/reasons.js +37 -4
  107. package/dist/fetch/page.js +2 -1
  108. package/dist/index.d.ts +3 -2
  109. package/dist/index.js +3 -2
  110. package/dist/meetings/context-store.d.ts +2 -0
  111. package/dist/meetings/findings-rules.d.ts +4 -0
  112. package/dist/meetings/findings-rules.js +5 -2
  113. package/dist/meetings/result-items.d.ts +1 -0
  114. package/dist/meetings/result-items.js +1 -0
  115. package/dist/models/index.js +22 -5
  116. package/dist/runs/events.d.ts +11 -1
  117. package/dist/runs/events.js +3 -1
  118. package/dist/runs/log-attributes.js +4 -0
  119. package/dist/runs/log-events.js +2 -0
  120. package/dist/runs/recording.d.ts +3 -0
  121. package/dist/runs/recording.js +36 -12
  122. package/dist/runs/run.d.ts +12 -3
  123. package/dist/runs/run.js +32 -13
  124. package/dist/search/account-list.d.ts +6 -0
  125. package/dist/search/account-list.js +9 -3
  126. package/dist/search/groups.d.ts +68 -0
  127. package/dist/search/groups.js +172 -0
  128. package/dist/services/account-groups.d.ts +28 -0
  129. package/dist/services/account-groups.js +89 -0
  130. package/dist/services/archive.d.ts +7 -1
  131. package/dist/services/archive.js +19 -3
  132. package/dist/services/business-context.d.ts +113 -0
  133. package/dist/services/business-context.js +156 -0
  134. package/dist/services/communications.d.ts +50 -0
  135. package/dist/services/communications.js +140 -0
  136. package/dist/services/deal-context.d.ts +90 -0
  137. package/dist/services/deal-context.js +131 -0
  138. package/dist/services/deps.d.ts +2 -0
  139. package/dist/services/enrichment.d.ts +7 -2
  140. package/dist/services/enrichment.js +46 -5
  141. package/dist/services/events-search.js +2 -1
  142. package/dist/services/group-guard.d.ts +28 -0
  143. package/dist/services/group-guard.js +131 -0
  144. package/dist/services/index.d.ts +15 -2
  145. package/dist/services/index.js +9 -2
  146. package/dist/services/ingest.d.ts +12 -0
  147. package/dist/services/ingest.js +4 -0
  148. package/dist/services/meaning-model.d.ts +7 -0
  149. package/dist/services/meaning-model.js +20 -0
  150. package/dist/services/meeting-context.d.ts +6 -1
  151. package/dist/services/meeting-context.js +12 -5
  152. package/dist/services/message-resolution.js +2 -3
  153. package/dist/services/messages-meaning.js +4 -5
  154. package/dist/services/messages-search.d.ts +5 -1
  155. package/dist/services/messages-search.js +1 -1
  156. package/dist/services/model-downloads.d.ts +1 -1
  157. package/dist/services/model-downloads.js +6 -4
  158. package/dist/services/money-context.d.ts +73 -0
  159. package/dist/services/money-context.js +77 -0
  160. package/dist/services/notes-search.d.ts +4 -1
  161. package/dist/services/notes-search.js +19 -7
  162. package/dist/services/organization-context.d.ts +80 -0
  163. package/dist/services/organization-context.js +154 -0
  164. package/dist/services/people.d.ts +22 -6
  165. package/dist/services/people.js +38 -8
  166. package/dist/services/person-business.d.ts +43 -0
  167. package/dist/services/person-business.js +67 -0
  168. package/dist/services/person-context.d.ts +9 -1
  169. package/dist/services/person-context.js +5 -3
  170. package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
  171. package/dist/services/proposals/kinds/identity-link.js +48 -0
  172. package/dist/services/proposals/kinds/orders.js +1 -1
  173. package/dist/services/proposals/registry.js +2 -0
  174. package/dist/services/search-kind.d.ts +12 -5
  175. package/dist/services/search-kind.js +49 -10
  176. package/dist/services/text-model-choice.js +1 -1
  177. package/dist/store/accounts.d.ts +18 -0
  178. package/dist/store/accounts.js +18 -3
  179. package/dist/store/damage.d.ts +43 -10
  180. package/dist/store/damage.js +119 -36
  181. package/dist/store/decisions.js +3 -1
  182. package/dist/store/evidence-findings.d.ts +14 -0
  183. package/dist/store/evidence-findings.js +2 -0
  184. package/dist/store/exports.d.ts +2 -1
  185. package/dist/store/identity-links.d.ts +92 -0
  186. package/dist/store/identity-links.js +6 -0
  187. package/dist/store/index.d.ts +11 -5
  188. package/dist/store/index.js +5 -2
  189. package/dist/store/journal.d.ts +10 -0
  190. package/dist/store/journal.js +33 -0
  191. package/dist/store/marks.d.ts +19 -1
  192. package/dist/store/marks.js +23 -1
  193. package/dist/store/people.d.ts +22 -0
  194. package/dist/store/people.js +15 -1
  195. package/dist/store/sqlite/accounts.js +2 -0
  196. package/dist/store/sqlite/base-stages.d.ts +122 -0
  197. package/dist/store/sqlite/base-stages.js +443 -0
  198. package/dist/store/sqlite/base-suggest.d.ts +13 -0
  199. package/dist/store/sqlite/base-suggest.js +62 -0
  200. package/dist/store/sqlite/business-contracts.js +10 -1
  201. package/dist/store/sqlite/crm-settings.d.ts +12 -2
  202. package/dist/store/sqlite/crm-settings.js +56 -13
  203. package/dist/store/sqlite/crm.d.ts +13 -1
  204. package/dist/store/sqlite/crm.js +20 -4
  205. package/dist/store/sqlite/deals.d.ts +33 -0
  206. package/dist/store/sqlite/deals.js +42 -4
  207. package/dist/store/sqlite/decision-requests.js +7 -3
  208. package/dist/store/sqlite/email-index.js +8 -4
  209. package/dist/store/sqlite/evidence-findings.js +29 -5
  210. package/dist/store/sqlite/findings-core.js +4 -2
  211. package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
  212. package/dist/store/sqlite/identity-link-rows.js +146 -0
  213. package/dist/store/sqlite/identity-proposals.d.ts +53 -0
  214. package/dist/store/sqlite/identity-proposals.js +234 -0
  215. package/dist/store/sqlite/knowledge.js +2 -2
  216. package/dist/store/sqlite/link-kinds.d.ts +1 -0
  217. package/dist/store/sqlite/link-kinds.js +1 -0
  218. package/dist/store/sqlite/link-row.d.ts +6 -0
  219. package/dist/store/sqlite/link-row.js +35 -0
  220. package/dist/store/sqlite/link-source.d.ts +10 -0
  221. package/dist/store/sqlite/link-source.js +16 -0
  222. package/dist/store/sqlite/manifest.js +1 -0
  223. package/dist/store/sqlite/meeting-context-links.js +9 -6
  224. package/dist/store/sqlite/memories.js +9 -7
  225. package/dist/store/sqlite/mentions.d.ts +4 -1
  226. package/dist/store/sqlite/mentions.js +14 -9
  227. package/dist/store/sqlite/migrations.generated.js +8 -0
  228. package/dist/store/sqlite/notes.d.ts +1 -2
  229. package/dist/store/sqlite/notes.js +4 -29
  230. package/dist/store/sqlite/open-store.js +3 -0
  231. package/dist/store/sqlite/open.js +11 -2
  232. package/dist/store/sqlite/orders.d.ts +2 -0
  233. package/dist/store/sqlite/orders.js +9 -3
  234. package/dist/store/sqlite/organization-categories.d.ts +18 -0
  235. package/dist/store/sqlite/organization-categories.js +34 -0
  236. package/dist/store/sqlite/organizations.d.ts +5 -1
  237. package/dist/store/sqlite/organizations.js +14 -4
  238. package/dist/store/sqlite/person-links.d.ts +19 -4
  239. package/dist/store/sqlite/person-links.js +49 -11
  240. package/dist/store/sqlite/person-match-scan.d.ts +13 -0
  241. package/dist/store/sqlite/person-match-scan.js +251 -0
  242. package/dist/store/sqlite/person-matcher.d.ts +16 -0
  243. package/dist/store/sqlite/person-matcher.js +32 -0
  244. package/dist/store/sqlite/proposed-actions.js +6 -0
  245. package/dist/store/sqlite/record-matching.d.ts +2 -8
  246. package/dist/store/sqlite/record-matching.js +8 -40
  247. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  248. package/dist/store/sqlite/record-relationships.d.ts +52 -0
  249. package/dist/store/sqlite/record-relationships.js +243 -0
  250. package/dist/store/sqlite/record-run.d.ts +5 -0
  251. package/dist/store/sqlite/record-run.js +62 -2
  252. package/dist/store/sqlite/record-writes.d.ts +1 -1
  253. package/dist/store/sqlite/record-writes.js +4 -2
  254. package/dist/store/sqlite/records.js +27 -2
  255. package/dist/store/sqlite/ref-accounts.d.ts +13 -0
  256. package/dist/store/sqlite/ref-accounts.js +117 -0
  257. package/dist/store/sqlite/ref-summaries.js +5 -1
  258. package/dist/store/sqlite/relation-list.d.ts +4 -1
  259. package/dist/store/sqlite/relation-list.js +18 -2
  260. package/dist/store/sqlite/relation-proposals.d.ts +6 -0
  261. package/dist/store/sqlite/relation-proposals.js +3 -0
  262. package/dist/store/sqlite/relation-roles.js +12 -6
  263. package/dist/store/sqlite/reported-relations.d.ts +11 -1
  264. package/dist/store/sqlite/reported-relations.js +59 -18
  265. package/dist/store/sqlite/schema.d.ts +32 -0
  266. package/dist/store/sqlite/schema.js +3 -0
  267. package/dist/store/sqlite/transaction.js +11 -1
  268. package/dist/store/store.d.ts +3 -0
  269. package/dist/store/store.js +5 -0
  270. package/dist/store/write-events.d.ts +18 -0
  271. package/dist/store/write-events.js +88 -0
  272. package/package.json +3 -3
  273. package/parity.json +11 -4
  274. package/schemas/records-envelope.v1.schema.json +3 -0
package/dist/runs/run.js CHANGED
@@ -7,6 +7,7 @@ import { LOG_ATTRIBUTES } from "./log-attributes.js";
7
7
  import { fromLogAttributes, logAttributes, snakeLogger } from "./log-keys.js";
8
8
  export const KEEP_RUNS_FOR_DAYS = 30;
9
9
  export const KEEP_SUCCESSFUL_RUNS_FOR_DAYS = 7;
10
+ export const KEEP_STORE_RUNS_FOR_DAYS = 3;
10
11
  export const RUNS_SIZE_LIMIT_MB = 200;
11
12
  /** `<state dir>/runs` — never the cache directory: a cache is deleted to fix a cache, and a run cannot be rebuilt. */
12
13
  export const runsDirFor = (app, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "runs");
@@ -35,6 +36,7 @@ export const startRun = (options) => {
35
36
  pruneRuns(options.runsDir, {
36
37
  keepDays: options.keepDays ?? KEEP_RUNS_FOR_DAYS,
37
38
  keepSuccessDays: options.keepSuccessDays ?? KEEP_SUCCESSFUL_RUNS_FOR_DAYS,
39
+ keepStoreDays: options.keepStoreDays ?? KEEP_STORE_RUNS_FOR_DAYS,
38
40
  maxBytes: options.maxBytes ?? RUNS_SIZE_LIMIT_MB * 1024 * 1024,
39
41
  now: startedAt,
40
42
  });
@@ -79,10 +81,13 @@ export const startRun = (options) => {
79
81
  let finished = false;
80
82
  const operations = new Set();
81
83
  const codes = new Set();
84
+ const tables = new Set();
82
85
  const noted = (level) => (event, message) => {
83
- const { operation, errorCode, error_code, code } = event;
86
+ const { operation, errorCode, error_code, code, kind, table } = event;
84
87
  if (typeof operation === "string")
85
88
  operations.add(operation);
89
+ if (kind === "store" && typeof table === "string")
90
+ tables.add(table);
86
91
  for (const value of [errorCode, error_code, code])
87
92
  if (typeof value === "string")
88
93
  codes.add(value);
@@ -109,6 +114,7 @@ export const startRun = (options) => {
109
114
  durationMs: completedAt.getTime() - startedAt.getTime(),
110
115
  operations: [...operations].sort(),
111
116
  codes: [...codes].sort(),
117
+ ...(tables.size > 0 ? { tables: [...tables].sort() } : {}),
112
118
  };
113
119
  if (file || status !== "success") {
114
120
  opened();
@@ -285,20 +291,30 @@ const eventOf = (line) => {
285
291
  };
286
292
  /**
287
293
  * Removes every day older than `keepDays`, then the successful runs of every day older than `keepSuccessDays`, and
288
- * answers how many days went. Then, once a day, the folder is measured against `maxBytes`: successful runs go first,
289
- * oldest day first, then whole days, until it fits.
294
+ * answers how many days went. A success that wrote the store is kept for `keepStoreDays` instead when that is longer,
295
+ * and one kept only because it wrote the store goes after `keepStoreDays`. Then, once a day, the folder is measured
296
+ * against `maxBytes`: successful runs go first, oldest day first, then whole days, until it fits.
290
297
  *
291
298
  * A day at a time, by the directory name and the day's index, so no run has to be opened to decide — and a directory
292
299
  * that is not a date is left alone rather than guessed at.
293
300
  */
294
- export const pruneRuns = (runsDir, { keepDays, keepSuccessDays = keepDays, maxBytes, now, }) => {
301
+ export const pruneRuns = (runsDir, { keepDays, keepSuccessDays = keepDays, keepStoreDays = KEEP_STORE_RUNS_FOR_DAYS, maxBytes, now, }) => {
295
302
  const cutoff = day(new Date(now.getTime() - keepDays * DAY_MS));
296
- const successCutoff = day(new Date(now.getTime() - Math.min(keepSuccessDays, keepDays) * DAY_MS));
303
+ const before = (days) => day(new Date(now.getTime() - Math.min(days, keepDays) * DAY_MS));
304
+ const successCutoff = before(keepSuccessDays);
305
+ const storeCutoff = before(keepStoreDays);
306
+ const keptFor = (metadata) => metadata.keptBecauseStore
307
+ ? keepStoreDays
308
+ : metadata.operations?.includes(STORE_WRITE)
309
+ ? Math.max(keepSuccessDays, keepStoreDays)
310
+ : keepSuccessDays;
297
311
  let removed = 0;
298
312
  for (const date of days(runsDir)) {
299
313
  if (date >= cutoff) {
314
+ if (date < storeCutoff)
315
+ dropSuccesses(join(runsDir, date), STORE_RUNS_DROPPED, (metadata) => keptFor(metadata) <= keepStoreDays);
300
316
  if (date < successCutoff)
301
- dropSuccesses(join(runsDir, date));
317
+ dropSuccesses(join(runsDir, date), SUCCESSES_DROPPED, (metadata) => keptFor(metadata) <= keepSuccessDays);
302
318
  continue;
303
319
  }
304
320
  try {
@@ -314,20 +330,23 @@ export const pruneRuns = (runsDir, { keepDays, keepSuccessDays = keepDays, maxBy
314
330
  return removed;
315
331
  };
316
332
  const DAY_MS = 24 * 60 * 60 * 1000;
333
+ const STORE_WRITE = "store.write";
317
334
  const SUCCESSES_DROPPED = ".successes-dropped";
335
+ const STORE_RUNS_DROPPED = ".store-runs-dropped";
318
336
  const SIZE_CHECKED = ".size-checked";
319
- /** A day's successful runs, out of its index and off the disk; once per day, marked by a file beside them. */
320
- const dropSuccesses = (dayDir) => {
321
- const marker = join(dayDir, SUCCESSES_DROPPED);
337
+ /** A day's successful runs that `drops`, out of its index and off the disk; once per day and marker. */
338
+ const dropSuccesses = (dayDir, marker = SUCCESSES_DROPPED, drops = () => true) => {
339
+ const done = join(dayDir, marker);
322
340
  try {
323
- statSync(marker);
341
+ statSync(done);
324
342
  return;
325
343
  }
326
344
  catch { }
345
+ const dropped = (metadata) => metadata?.status === "success" && drops(metadata);
327
346
  try {
328
347
  const kept = [];
329
348
  for (const [id, metadata] of indexedRuns(dayDir)) {
330
- if (metadata.status === "success")
349
+ if (dropped(metadata))
331
350
  rmSync(join(dayDir, id), { recursive: true, force: true });
332
351
  else
333
352
  kept.push(JSON.stringify(runFileOf(metadata)));
@@ -335,11 +354,11 @@ const dropSuccesses = (dayDir) => {
335
354
  for (const entry of safeReaddir(dayDir)) {
336
355
  if (entry === INDEX || entry.startsWith("."))
337
356
  continue;
338
- if (readRun(join(dayDir, entry))?.status === "success")
357
+ if (dropped(readRun(join(dayDir, entry))))
339
358
  rmSync(join(dayDir, entry), { recursive: true, force: true });
340
359
  }
341
360
  writeSecurely(join(dayDir, INDEX), kept.map((line) => `${line}\n`).join(""), 0o600);
342
- writeFileSync(marker, "", { mode: 0o600 });
361
+ writeFileSync(done, "", { mode: 0o600 });
343
362
  }
344
363
  catch {
345
364
  // Tried again at the next run's start.
@@ -9,6 +9,7 @@ export declare const ACCOUNT_GROUPS_SETTING = "account_groups";
9
9
  export type AccountGroups = Record<string, string[]>;
10
10
  /** A bare `all` or `telegram` keeps meaning what it always did; a comma or a `:` makes it a list. */
11
11
  export declare const isAccountList: (value: string) => boolean;
12
+ export declare const isGroupName: (name: string) => boolean;
12
13
  export declare const groupName: (name: string) => string;
13
14
  /** What `config set account_groups.<name>` saves: the entries as written, so each app resolves its own profiles. */
14
15
  export declare const groupMembers: (value: string) => string[];
@@ -23,6 +24,8 @@ export interface ListContext {
23
24
  provider: Provider;
24
25
  command?: string;
25
26
  };
27
+ /** Under a group lock, the only accounts (by `keyOf`) a list may name; every other one resolves to nothing. */
28
+ only?: ReadonlySet<string>;
26
29
  }
27
30
  /**
28
31
  * An account as `--source` and a hit name it: a notes folder is `notes:<its id>`, never the store's ulid. The kind is
@@ -40,6 +43,9 @@ export interface ListedEntry {
40
43
  entry: string;
41
44
  accounts: ListedAccount[];
42
45
  }
46
+ export declare const keyOf: ({ provider, account }: AccountKey) => string;
47
+ export declare const sourceOf: ({ provider, account }: AccountKey) => string;
48
+ export declare const sameAs: (key: AccountKey) => (one: AccountKey) => boolean;
43
49
  /**
44
50
  * What `--source group:work,tg:tg3,max:Alice,email,notes:4` names, entry by entry, a group's members in its
45
51
  * place. An entry is a group, `provider:account` — the account's id, a profile of any app that recorded it, or
@@ -17,7 +17,8 @@ const itemsOf = (value) => {
17
17
  fail(`"${value}" has an empty entry — separate accounts with one comma`);
18
18
  return items;
19
19
  };
20
- export const groupName = (name) => GROUP_NAME.test(name) ? name : fail(`a group name is letters, digits, - and _ — not "${name}"`);
20
+ export const isGroupName = (name) => GROUP_NAME.test(name);
21
+ export const groupName = (name) => isGroupName(name) ? name : fail(`a group name is letters, digits, - and _ — not "${name}"`);
21
22
  /** What `config set account_groups.<name>` saves: the entries as written, so each app resolves its own profiles. */
22
23
  export const groupMembers = (value) => itemsOf(value).map((item) => item.toLowerCase().startsWith("group:")
23
24
  ? fail(`a group lists accounts, not other groups — "${item}"`)
@@ -145,7 +146,9 @@ const accountsOfWord = (word, held, context) => {
145
146
  return storedAs(held, { provider, account: "" });
146
147
  return held.filter((one) => one.provider === provider);
147
148
  };
148
- const keyOf = ({ provider, account }) => `${provider}\u0000${account}`;
149
+ export const keyOf = ({ provider, account }) => `${provider}\u0000${account}`;
150
+ export const sourceOf = ({ provider, account }) => `${provider}:${account}`;
151
+ export const sameAs = (key) => (one) => one.provider === key.provider && one.account === key.account;
149
152
  /**
150
153
  * What `--source group:work,tg:tg3,max:Alice,email,notes:4` names, entry by entry, a group's members in its
151
154
  * place. An entry is a group, `provider:account` — the account's id, a profile of any app that recorded it, or
@@ -188,9 +191,12 @@ export const entriesOfList = (value, context) => {
188
191
  };
189
192
  for (const item of itemsOf(value))
190
193
  entry(item);
194
+ const { only } = context;
191
195
  return entries.map(({ entry, accounts }) => ({
192
196
  entry,
193
- accounts: accounts.map(({ provider, account, kind, kinds }) => ({
197
+ accounts: accounts
198
+ .filter((one) => only === undefined || only.has(keyOf(one)))
199
+ .map(({ provider, account, kind, kinds }) => ({
194
200
  provider,
195
201
  account,
196
202
  kind,
@@ -0,0 +1,68 @@
1
+ import type { AccountKey } from "../store/store.js";
2
+ import { type AccountGroups, type ListContext } from "./account-list.js";
3
+ /** The default group: every account, never saved. Reading without a group reads it. */
4
+ export declare const ALL = "all";
5
+ /** memo's own notes: the owner's, so `search notes` reads them in every group, though no group lists them. */
6
+ export declare const OWNER_NOTES: AccountKey;
7
+ /** Words a source list already gives a meaning of its own, so no group may be saved under them. */
8
+ export declare const NOT_GROUP_NAMES: ReadonlySet<string>;
9
+ /** `setting`: a saved group lists it; `all`: the default group, which holds every account. */
10
+ export type GroupReason = "setting" | "all";
11
+ export interface GroupMember extends AccountKey {
12
+ /** Every saved entry that names it; its `provider:account` in `all`. */
13
+ entries: string[];
14
+ reason: GroupReason;
15
+ /** Every profile recorded for the account, as `<app> <profile>`. */
16
+ profiles: string[];
17
+ /** The other saved groups that hold it too: allowed, and shown so the owner sees it. */
18
+ also_in: string[];
19
+ }
20
+ /** A profile name another app's profile or a saved group shares, for an account not in that group: never applied. */
21
+ export interface GroupSuggestion {
22
+ group: string;
23
+ member: string;
24
+ because: string;
25
+ }
26
+ export interface GroupMembership {
27
+ /** The saved groups, then `all`. */
28
+ groups: Record<string, GroupMember[]>;
29
+ /** Each account in more than one saved group, with those groups. */
30
+ duplicates: {
31
+ member: string;
32
+ groups: string[];
33
+ }[];
34
+ suggested: GroupSuggestion[];
35
+ /** Saved entries that name no account. */
36
+ unresolved: string[];
37
+ }
38
+ /** A source-list context with who is in each group and why. */
39
+ export interface GroupContext extends ListContext {
40
+ membership: GroupMembership;
41
+ }
42
+ export declare const hasGroup: (groups: object, name: string) => boolean;
43
+ /**
44
+ * Who is in each group (WC-ACCT-13): a saved `account_groups.<name>` is its whole list, and `all`, never saved, is
45
+ * every account. One account may be in several groups. A profile's name never puts an account in a group; it is
46
+ * only `suggested`.
47
+ */
48
+ export declare const groupMembership: (context: ListContext) => GroupMembership;
49
+ /** Whether an account is in `group`; every account is in `all`. `context` is a `listContextOf`. */
50
+ export declare const inGroupOf: (context: GroupContext, group: string) => (key: AccountKey) => boolean;
51
+ /** The groups as a source list reads them: the saved entries as written, and `group:all` as every account. */
52
+ export declare const groupEntries: (saved: AccountGroups) => AccountGroups;
53
+ /** The group a run is scoped to, where it was named, and whether a lock pins it. */
54
+ export interface RunGroup {
55
+ name: string;
56
+ from: string;
57
+ locked: boolean;
58
+ }
59
+ export interface GroupRequest {
60
+ source?: string;
61
+ account?: string;
62
+ }
63
+ /**
64
+ * A run in a group reads only the group: no `--source` becomes `group:<name>`, a bare provider or kind keeps the
65
+ * group's accounts of it, and an account outside the group is refused, as is a write's `--account`. `context` is a
66
+ * `listContextOf`. Without a lock this is a convenience, not a boundary.
67
+ */
68
+ export declare const scopeToGroup: (run: RunGroup, request: GroupRequest, context: GroupContext) => GroupRequest;
@@ -0,0 +1,172 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { INTERNAL_NOTES } from "../domain/providers.js";
3
+ import { accountsOfList, isGroupName, keyOf, sameAs, sourceOf, } from "./account-list.js";
4
+ /** The default group: every account, never saved. Reading without a group reads it. */
5
+ export const ALL = "all";
6
+ /** memo's own notes: the owner's, so `search notes` reads them in every group, though no group lists them. */
7
+ export const OWNER_NOTES = { provider: "notes", account: INTERNAL_NOTES };
8
+ /** Words a source list already gives a meaning of its own, so no group may be saved under them. */
9
+ export const NOT_GROUP_NAMES = new Set([ALL, "bots"]);
10
+ export const hasGroup = (groups, name) => Object.hasOwn(groups, name);
11
+ const membersOf = (entries, context, unresolved) => {
12
+ const members = new Map();
13
+ for (const entry of entries)
14
+ try {
15
+ for (const { provider, account } of accountsOfList(entry, context)) {
16
+ const known = members.get(keyOf({ provider, account }));
17
+ if (known)
18
+ known.entries.push(entry);
19
+ else
20
+ members.set(keyOf({ provider, account }), {
21
+ provider,
22
+ account,
23
+ entries: [entry],
24
+ reason: "setting",
25
+ profiles: [],
26
+ also_in: [],
27
+ });
28
+ }
29
+ }
30
+ catch (error) {
31
+ // One stale entry must not break every read of every group; the group's own read still names it.
32
+ if (!(error instanceof CliError))
33
+ throw error;
34
+ unresolved.push(entry);
35
+ }
36
+ return [...members.values()];
37
+ };
38
+ /**
39
+ * Who is in each group (WC-ACCT-13): a saved `account_groups.<name>` is its whole list, and `all`, never saved, is
40
+ * every account. One account may be in several groups. A profile's name never puts an account in a group; it is
41
+ * only `suggested`.
42
+ */
43
+ export const groupMembership = (context) => {
44
+ const plain = { ...context, groups: {} };
45
+ const unresolved = [];
46
+ const groups = {};
47
+ for (const [name, entries] of Object.entries(context.groups))
48
+ if (name !== ALL)
49
+ groups[name] = membersOf(entries, plain, unresolved);
50
+ // Not accounts of anyone's: memo's own notes, and the row a fresh store lacks for the account running (id 0).
51
+ const system = [OWNER_NOTES, ...context.held.filter(({ id }) => id === 0)].map(keyOf);
52
+ const every = accountsOfList(ALL, plain)
53
+ .filter((one) => !system.includes(keyOf(one)))
54
+ .map(({ provider, account }) => ({
55
+ provider,
56
+ account,
57
+ entries: [sourceOf({ provider, account })],
58
+ reason: "all",
59
+ profiles: [],
60
+ also_in: [],
61
+ }));
62
+ const recorded = Object.entries(context.profiles).flatMap(([app, named]) => Object.entries(named).map(([profile, key]) => ({ app, profile, key })));
63
+ const holding = new Map();
64
+ for (const [name, members] of Object.entries(groups))
65
+ for (const one of members)
66
+ holding.set(keyOf(one), [...(holding.get(keyOf(one)) ?? []), name]);
67
+ for (const [name, members] of [...Object.entries(groups), [ALL, every]])
68
+ for (const one of members) {
69
+ one.profiles = recorded.filter(({ key }) => sameAs(key)(one)).map(({ app, profile }) => `${app} ${profile}`);
70
+ one.also_in = (holding.get(keyOf(one)) ?? []).filter((other) => other !== name);
71
+ }
72
+ const duplicates = [...holding.entries()]
73
+ .filter(([, names]) => names.length > 1)
74
+ .map(([key, names]) => ({ member: key.replace("\u0000", ":"), groups: names }));
75
+ // A name only one app uses, such as `default`, says nothing about which accounts belong together.
76
+ const shared = (app, profile) => hasGroup(context.groups, profile) || recorded.some((other) => other.app !== app && other.profile === profile);
77
+ const suggested = recorded
78
+ .filter(({ app, profile, key }) => isGroupName(profile) &&
79
+ !NOT_GROUP_NAMES.has(profile.toLowerCase()) &&
80
+ shared(app, profile) &&
81
+ !holding.get(keyOf(key))?.includes(profile))
82
+ .map(({ app, profile, key }) => ({
83
+ group: profile,
84
+ member: sourceOf(key),
85
+ because: `profile named ${profile} (${app} ${profile})`,
86
+ }));
87
+ return { groups: { ...groups, [ALL]: every }, duplicates, suggested, unresolved };
88
+ };
89
+ /** Whether an account is in `group`; every account is in `all`. `context` is a `listContextOf`. */
90
+ export const inGroupOf = (context, group) => (key) => group === ALL ||
91
+ (hasGroup(context.membership.groups, group) ? (context.membership.groups[group] ?? []) : []).some(sameAs(key));
92
+ /** The groups as a source list reads them: the saved entries as written, and `group:all` as every account. */
93
+ export const groupEntries = (saved) => ({
94
+ ...Object.fromEntries(Object.entries(saved).filter(([name]) => name !== ALL)),
95
+ [ALL]: [ALL],
96
+ });
97
+ const fail = (code, message, details) => {
98
+ throw new CliError(code, message, details);
99
+ };
100
+ const unknownGroup = (run, context) => {
101
+ const names = Object.keys(context.groups);
102
+ const unknown = run.from === "first word"
103
+ ? `"${run.name}" is neither a command nor a group`
104
+ : `no group "${run.name}" (${run.from})`;
105
+ const suggested = context.membership.suggested.filter(({ group }) => group === run.name);
106
+ const offer = suggested.length
107
+ ? `; profiles named ${run.name} suggest ${suggested.map(({ member }) => member).join(", ")}`
108
+ : "";
109
+ return fail("validation_error", `${unknown} — groups here: ${names.join(", ")}${offer}`, {
110
+ groups: names,
111
+ ...(suggested.length ? { suggested } : {}),
112
+ });
113
+ };
114
+ /**
115
+ * A run in a group reads only the group: no `--source` becomes `group:<name>`, a bare provider or kind keeps the
116
+ * group's accounts of it, and an account outside the group is refused, as is a write's `--account`. `context` is a
117
+ * `listContextOf`. Without a lock this is a convenience, not a boundary.
118
+ */
119
+ export const scopeToGroup = (run, request, context) => {
120
+ if (!hasGroup(context.groups, run.name))
121
+ unknownGroup(run, context);
122
+ const code = run.locked ? "permission_error" : "validation_error";
123
+ const why = run.locked
124
+ ? `this process is locked to group ${run.name} (${run.from})`
125
+ : `this run is in group ${run.name}`;
126
+ if (!context.membership.groups[run.name]?.length)
127
+ fail("validation_error", `group ${run.name} is empty`);
128
+ const inGroup = new Set(accountsOfList(`group:${run.name}`, context).map(keyOf));
129
+ const outside = (accounts) => accounts.filter((one) => !inGroup.has(keyOf(one)));
130
+ // Under a lock the context holds only the group, so a name outside it fails to resolve: that is the refusal.
131
+ const namedBy = (item) => {
132
+ try {
133
+ return accountsOfList(item, context);
134
+ }
135
+ catch (error) {
136
+ if (run.locked && error instanceof CliError)
137
+ return [];
138
+ throw error;
139
+ }
140
+ };
141
+ const scoped = {};
142
+ if (request.source === undefined)
143
+ scoped.source = `group:${run.name}`;
144
+ else {
145
+ const items = request.source.split(",").map((item) => item.trim());
146
+ if (items.some((item) => item.toLowerCase() === "all"))
147
+ fail(code, `${why} — --source all reads outside it`);
148
+ const kept = [];
149
+ let narrowed = false;
150
+ for (const item of items) {
151
+ const accounts = namedBy(item);
152
+ const away = outside(accounts);
153
+ if (item.includes(":") && (away.length || accounts.length === 0))
154
+ fail(code, `${why} — ${item} is outside it${away.length ? ` (${away.map(sourceOf).join(", ")})` : ""}`);
155
+ if (away.length)
156
+ narrowed = true;
157
+ for (const one of accounts)
158
+ if (inGroup.has(keyOf(one)))
159
+ kept.push(sourceOf(one));
160
+ }
161
+ if (kept.length === 0)
162
+ fail("validation_error", `${why} — --source ${request.source} names none of its accounts`);
163
+ scoped.source = narrowed ? [...new Set(kept)].join(",") : request.source;
164
+ }
165
+ if (request.account !== undefined) {
166
+ const accounts = namedBy(request.account);
167
+ if (accounts.length === 0 || outside(accounts).length)
168
+ fail(code, `${why} — --account ${request.account} is outside it`);
169
+ scoped.account = request.account;
170
+ }
171
+ return scoped;
172
+ };
@@ -0,0 +1,28 @@
1
+ import type { AppIdentity } from "../ports/app.js";
2
+ import { type GroupMembership } from "../search/groups.js";
3
+ import type { AccountKey, MessageStore } from "../store/store.js";
4
+ /** The store, the account running and its app: what every group edit resolves members against. */
5
+ export interface GroupStore {
6
+ store: MessageStore;
7
+ account: AccountKey;
8
+ app?: AppIdentity;
9
+ /** The run's environment: under a group lock only that group is listed and changed. */
10
+ env?: NodeJS.ProcessEnv;
11
+ }
12
+ export interface GroupMemberChange {
13
+ group: string;
14
+ /** One account, as `--source` names it: `telegram:102`, `tg:work`, `email:me@work.example`. */
15
+ member: string;
16
+ /** Words that may not name a group, such as memo's command words. */
17
+ reserved?: ReadonlySet<string>;
18
+ }
19
+ export interface GroupMemberMove extends Omit<GroupMemberChange, "group"> {
20
+ from: string;
21
+ to: string;
22
+ }
23
+ /** Every group with its members, why each is in, its profiles and other groups, the duplicates and the suggestions. */
24
+ export declare const listAccountGroups: (at: GroupStore) => Promise<GroupMembership>;
25
+ export declare const addGroupMember: (at: GroupStore, change: GroupMemberChange) => Promise<GroupMembership>;
26
+ export declare const removeGroupMember: (at: GroupStore, change: GroupMemberChange) => Promise<GroupMembership>;
27
+ /** Out of one group and into another in one write: what a drag between groups does. */
28
+ export declare const moveGroupMember: (at: GroupStore, move: GroupMemberMove) => Promise<GroupMembership>;
@@ -0,0 +1,89 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import { accountsOfList, groupName, sameAs, sourceOf } from "../search/account-list.js";
3
+ import { ALL, hasGroup, NOT_GROUP_NAMES } from "../search/groups.js";
4
+ import { groupLockOf, listContextOf } from "./search-kind.js";
5
+ const fail = (code, message) => {
6
+ throw new CliError(code, message);
7
+ };
8
+ const contextOf = ({ store, account, app, env }) => listContextOf(store, account, app, undefined, env);
9
+ /** Under a lock the groups are the owner's to change, never the locked process's. */
10
+ const unlocked = (at) => {
11
+ const lock = groupLockOf(at.app, at.env);
12
+ if (lock !== undefined)
13
+ throw new CliError("permission_error", `this process is locked to group ${lock} — groups are changed without the lock`);
14
+ };
15
+ const usableGroup = (name, reserved = new Set()) => {
16
+ groupName(name);
17
+ if (NOT_GROUP_NAMES.has(name.toLowerCase()) || reserved.has(name))
18
+ fail("validation_error", `"${name}" cannot name a group — it already means something on the command line`);
19
+ return name;
20
+ };
21
+ /** A group holds accounts, so a member is saved as the one account it names, under its stable key. */
22
+ const accountOf = (context, member) => {
23
+ if (member.toLowerCase().startsWith("group:"))
24
+ fail("validation_error", "a group lists accounts, not other groups");
25
+ const accounts = accountsOfList(member, { ...context, groups: {} });
26
+ if (accounts.length !== 1)
27
+ fail("validation_error", `${member} names ${accounts.length} accounts — name one: ${accounts.map(sourceOf).join(", ")}`);
28
+ return accounts[0];
29
+ };
30
+ /**
31
+ * Whether a saved entry is to go when `key` leaves its group: every entry naming only this account does. One that
32
+ * names more, such as a bare `email`, would take the others with it, so the change is refused instead.
33
+ */
34
+ const namesOnly = (context, key) => (entry) => {
35
+ let accounts;
36
+ try {
37
+ accounts = accountsOfList(entry, { ...context, groups: {} });
38
+ }
39
+ catch {
40
+ return false;
41
+ }
42
+ if (!accounts.some(sameAs(key)))
43
+ return false;
44
+ if (accounts.length > 1)
45
+ fail("validation_error", `${entry} names more than this account — change the group with config set`);
46
+ return true;
47
+ };
48
+ const isIn = (context, group, key) => {
49
+ if (!hasGroup(context.membership.groups, group))
50
+ fail("not_found", `no group "${group}" — groups here: ${Object.keys(context.membership.groups).join(", ")}`);
51
+ return (context.membership.groups[group] ?? []).some(sameAs(key));
52
+ };
53
+ /** Every group with its members, why each is in, its profiles and other groups, the duplicates and the suggestions. */
54
+ export const listAccountGroups = async (at) => (await contextOf(at)).membership;
55
+ export const addGroupMember = async (at, change) => {
56
+ unlocked(at);
57
+ const group = usableGroup(change.group, change.reserved);
58
+ const key = accountOf(await contextOf(at), change.member);
59
+ await at.store.accounts.changeAccountGroups({ add: { group, entry: sourceOf(key) } });
60
+ return listAccountGroups(at);
61
+ };
62
+ export const removeGroupMember = async (at, change) => {
63
+ unlocked(at);
64
+ const group = usableGroup(change.group);
65
+ const context = await contextOf(at);
66
+ const key = accountOf(context, change.member);
67
+ isIn(context, group, key);
68
+ const { removed } = await at.store.accounts.changeAccountGroups({
69
+ remove: { group, drop: namesOnly(context, key) },
70
+ });
71
+ if (removed.length === 0)
72
+ fail("not_found", `${change.member} is not in group ${group}`);
73
+ return listAccountGroups(at);
74
+ };
75
+ /** Out of one group and into another in one write: what a drag between groups does. */
76
+ export const moveGroupMember = async (at, move) => {
77
+ unlocked(at);
78
+ const to = usableGroup(move.to, move.reserved);
79
+ const context = await contextOf(at);
80
+ const key = accountOf(context, move.member);
81
+ if (!isIn(context, move.from, key))
82
+ fail("not_found", `${move.member} is not in group ${move.from}`);
83
+ // Out of `all` nothing can go: a move from it puts the account in `to` and leaves it in every account.
84
+ await at.store.accounts.changeAccountGroups({
85
+ ...(move.from === ALL ? {} : { remove: { group: move.from, drop: namesOnly(context, key) } }),
86
+ add: { group: to, entry: sourceOf(key) },
87
+ });
88
+ return listAccountGroups(at);
89
+ };
@@ -48,6 +48,8 @@ export interface FetchOptions {
48
48
  }) => void;
49
49
  /** Past the history limits for this chat (`--full-history`). */
50
50
  fullHistory?: boolean;
51
+ /** `fetchAll` only: read muted chats too (`--with-muted`); `history_muted` decides when unset. */
52
+ withMuted?: boolean;
51
53
  /** The chat's kind and size as the messenger lists it, for a chat the store does not hold yet. */
52
54
  shape?: ChatShape;
53
55
  }
@@ -89,10 +91,14 @@ export type FetchedAll = {
89
91
  issue?: ActionableError;
90
92
  limited?: "group_too_large" | "older_than_window";
91
93
  }[];
92
- /** How many chats the history limits left unread (big groups) or read only to the window's start. */
94
+ /**
95
+ * How many chats the history limits left unread (big groups) or read only to the window's start, and how many muted
96
+ * chats were not read (`history_muted`); those are not in `chats` or `items`.
97
+ */
93
98
  limited?: {
94
99
  groupTooLarge: number;
95
100
  olderThanWindow: number;
101
+ muted?: number;
96
102
  };
97
103
  };
98
104
  /** The local store of messages: what it holds, filling it from the messenger, and reading it out. */
@@ -147,17 +147,21 @@ export const archiveService = (deps) => {
147
147
  pushed(deps, "`messages sync --all`");
148
148
  const connection = await deps.connection();
149
149
  const list = capability(connection, "chats", "list its chats");
150
- const chats = [];
150
+ const listed = [];
151
151
  for (let offset = 0;;) {
152
152
  const page = await patiently(() => list({ offset, limit: 100 }), options.note, options.stop);
153
- chats.push(...page.items);
153
+ listed.push(...page.items);
154
154
  offset += page.items.length;
155
155
  if (!page.hasMore || page.items.length === 0)
156
156
  break;
157
157
  }
158
- chats.sort((one, other) => (other.lastMessageAt ?? "").localeCompare(one.lastMessageAt ?? ""));
158
+ listed.sort((one, other) => (other.lastMessageAt ?? "").localeCompare(one.lastMessageAt ?? ""));
159
+ const muted = await mutedSkips(deps, listed, options.withMuted ?? deps.historyMuted ?? false);
160
+ const chats = listed.filter((chat) => !muted.has(chat.id));
159
161
  const own = archiveService({ ...deps, withConnection: undefined, connection: async () => connection });
160
162
  const answer = { chats: chats.length, fetched: 0, complete: false, items: [] };
163
+ if (muted.size > 0)
164
+ answer.limited = { groupTooLarge: 0, olderThanWindow: 0, muted: muted.size };
161
165
  const batch = batchProgress(deps.env);
162
166
  const catchingUp = Boolean(options.catchUp ?? deps.searchCatchUp);
163
167
  const upToDate = heldToNewest(await deps.store(), await deps.account(), deps.messenger.fetching ?? FETCHING, {
@@ -222,6 +226,18 @@ export const archiveService = (deps) => {
222
226
  },
223
227
  };
224
228
  };
229
+ const mutedNow = (chat, now) => chat.muted === true && (chat.mutedUntil == null || Date.parse(chat.mutedUntil) > now);
230
+ /** The muted chats `--all` leaves out unless asked to read them; a chat kept in full (`--full-history`) is read. */
231
+ const mutedSkips = async (deps, chats, readMuted) => {
232
+ if (readMuted)
233
+ return new Set();
234
+ const now = Date.now();
235
+ const muted = chats.filter((chat) => mutedNow(chat, now)).map((chat) => chat.id);
236
+ if (muted.length === 0)
237
+ return new Set();
238
+ const shapes = await (await deps.store()).chats.historyShapes(await deps.account(), muted);
239
+ return new Set(muted.filter((id) => shapes.get(id)?.included !== true));
240
+ };
225
241
  /**
226
242
  * Where the history limits stop this chat's read: not at all for a group above the cap, else at the window's start.
227
243
  * None for a lifted chat or without limits. A chat the store does not hold yet is judged by the shape the list gave.