@wirecat/cli-core 0.630.0 → 0.632.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 (60) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/background/daily-archive-timer.d.ts +1 -1
  3. package/dist/calendar/mcp/index.d.ts +12 -12
  4. package/dist/cli/messenger/context.d.ts +2 -0
  5. package/dist/cli/messenger/reply-stats-command.js +1 -1
  6. package/dist/cli/messenger/serve-relay.d.ts +1 -0
  7. package/dist/cli/messenger/stats-answers.d.ts +5 -2
  8. package/dist/cli/messenger/stats-answers.js +8 -2
  9. package/dist/cli/messenger/tasks-command.js +5 -3
  10. package/dist/crm/cli/index.js +22 -2
  11. package/dist/crm/sync.d.ts +3 -1
  12. package/dist/crm/sync.js +5 -0
  13. package/dist/domain/crm.d.ts +2 -1
  14. package/dist/domain/test-data.d.ts +15 -0
  15. package/dist/domain/test-data.js +18 -0
  16. package/dist/entities/chat-stats.d.ts +2 -0
  17. package/dist/entities/chat-stats.js +2 -0
  18. package/dist/entities/index.d.ts +1 -0
  19. package/dist/errors/reasons.js +9 -0
  20. package/dist/kit/seed.js +6 -7
  21. package/dist/search/lucene/registry.js +11 -0
  22. package/dist/services/metadata.d.ts +1 -1
  23. package/dist/services/proposals/kinds/identity-split.d.ts +4 -0
  24. package/dist/services/proposals/kinds/identity-split.js +65 -0
  25. package/dist/services/proposals/registry.js +2 -0
  26. package/dist/services/reply-stats.js +11 -3
  27. package/dist/services/task-stats.d.ts +7 -2
  28. package/dist/services/task-stats.js +53 -20
  29. package/dist/services/tasks.d.ts +1 -0
  30. package/dist/services/tasks.js +16 -4
  31. package/dist/store/decisions.js +3 -1
  32. package/dist/store/drivers/bun-sqlite.js +2 -0
  33. package/dist/store/drivers/node-sqlite.js +2 -0
  34. package/dist/store/identity-splits.d.ts +60 -0
  35. package/dist/store/identity-splits.js +5 -0
  36. package/dist/store/index.d.ts +3 -1
  37. package/dist/store/index.js +3 -1
  38. package/dist/store/people.d.ts +23 -0
  39. package/dist/store/people.js +6 -0
  40. package/dist/store/sqlite/accounts.d.ts +7 -0
  41. package/dist/store/sqlite/accounts.js +17 -5
  42. package/dist/store/sqlite/crm-contacts.d.ts +26 -0
  43. package/dist/store/sqlite/crm-contacts.js +138 -0
  44. package/dist/store/sqlite/crm-settings.d.ts +2 -0
  45. package/dist/store/sqlite/crm-settings.js +5 -0
  46. package/dist/store/sqlite/crm.d.ts +12 -0
  47. package/dist/store/sqlite/crm.js +7 -2
  48. package/dist/store/sqlite/identity-link-rows.d.ts +5 -0
  49. package/dist/store/sqlite/identity-link-rows.js +5 -3
  50. package/dist/store/sqlite/identity-split-proposals.d.ts +29 -0
  51. package/dist/store/sqlite/identity-split-proposals.js +195 -0
  52. package/dist/store/sqlite/lucene-fields.js +3 -0
  53. package/dist/store/sqlite/manifest.js +1 -0
  54. package/dist/store/sqlite/migrations.generated.js +15 -0
  55. package/dist/store/sqlite/person-doubts.d.ts +36 -0
  56. package/dist/store/sqlite/person-doubts.js +229 -0
  57. package/dist/store/sqlite/proposed-actions.js +6 -0
  58. package/dist/store/sqlite/reply-times.d.ts +3 -1
  59. package/dist/store/sqlite/reply-times.js +11 -6
  60. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,65 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.632.0 — 10.11.2026
9
+
10
+ ### Added
11
+
12
+ - **`PeopleStore.doubts` lists people that may be wrong**, a page at a time, the owner first, each with a plain reason,
13
+ the identities in doubt, the evidence and the owner's commands that would fix it: the owner's person holding an
14
+ identity under another name (spelling and script aside; what the owner linked by hand never counts), test data (the
15
+ contract seed's people, an address at a reserved domain such as `.test` or `example.com`), an identity joined by an
16
+ address that a person of another name has, and one person with different names and no phone or address in common.
17
+ It reads only the people with more than one identity and one pass over identities: about 0.1 s on a store of 150k
18
+ people.
19
+ - **An agent's unlink or unmerge waits for the owner.** `PeopleStore.proposeSplit` stores an `identity_split`
20
+ proposal (the identities that leave, all of one person, or a `merge:<to>-<from>`) with its reason;
21
+ `decideSplit` is the owner's alone and carries it out as the owner's own unlink, split or undo of the merge, refused
22
+ with `identity.stale` when the person changed since. `splitProposals` lists them, and the shared review
23
+ (`proposalRegistry`) shows and decides them as kind `identity_split`, owner-only. Proposing an open split again
24
+ renews it after the person changed. A split the owner turned down is not proposed again while its identities stay
25
+ on that person, and `doubts` leaves them out. Removing a CRM contact or erasing an identity deletes the splits that
26
+ name it. No store migration: older builds see the kind as a plain action, and one they approve is never carried
27
+ out (`splitProposals` shows it as `dropped`).
28
+ - `SEED_PEOPLE`, `RESERVED_ADDRESS_GLOBS` and `SEED_ID_GLOBS` in the domain, which the contract seed now uses.
29
+ - **`muted:` in the query language.** `muted:true` matches messages in chats the owner muted, until the mute runs
30
+ out; `muted:false` matches every other chat, so `stats messages show 'muted:false date>=30d'` counts only what the
31
+ sync still reads. A messenger that keeps no mute state counts its chats as not muted. `stats messages responses`
32
+ and `stats messages waiting` take it too.
33
+ - **`stats tasks show` can count every account at once.** A `Messenger` that sets `accountsOf(command)` gets one answer
34
+ across the accounts it returns, when the command names none: memo uses it so `memo stats tasks show` needs no
35
+ `--source`. The answer lists them in `accounts`, and each chat row's `chat` names its own account. `--chat` and a
36
+ `chat:` naming one chat are then refused, since a chat belongs to one account.
37
+
38
+ ### Fixed
39
+
40
+ - **A test can no longer reach the owner's real store through `openCache` either.** The refusal of 0.560.0 covered
41
+ `openStore` and `openSqlite`; `openCache` and `openFile`, which first-run, store settings, schedules and store
42
+ backups use, opened the file without it. The check now sits in both SQLite drivers, so every opening under vitest
43
+ refuses a file in the owner's WireCat folder.
44
+
45
+ ## 0.631.0 — 10.11.2026
46
+
47
+ ### Added
48
+
49
+ - **A CRM copy under scope `mine` keeps only its clients' contacts.** After a sync that narrowed the copy or ran with
50
+ `--rescan`, and finished every kind, one transaction removes each contact that no kept deal or lead of the chosen
51
+ users names, and that is no contact of a kept company. The person it made goes too, unless anything else is left on
52
+ them: another identity such as mail, a note, an alias, a mention, the owner's link decision. A contact the owner
53
+ linked or unlinked himself stays. People named after a contact lose an import's `null` / `null #<id>` from their
54
+ name; the owner's person is never renamed. The sync answer gives the counts as `contacts_removed`. Before, a
55
+ narrowed copy kept every contact for good: the CRM's deletion check skips contacts.
56
+ - **`store apply`** does the same for the contacts already stored, for the users scope `mine` keeps (`self` and
57
+ `unassigned`) whatever the scope is now: counts only, unless `--yes` under scope `mine`.
58
+ - `CrmCopies.removeContacts`.
59
+
60
+ ### Fixed
61
+
62
+ - **Saving, changing or removing a deal's or lead's link to a person no longer reads every link to a person.**
63
+ Store version 64 recreates version 63's person-kind triggers on deal links and on a deal owner's moves so they look
64
+ a deal's people up by the deal. On a store with 118k person links, removing 635 links took 15 s and now takes
65
+ 0.4 s.
66
+
8
67
  ## 0.630.0 — 10.11.2026
9
68
 
10
69
  ### Added
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
24
24
  }
25
25
  export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
26
26
  export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
27
+ action?: undefined;
27
28
  name: string;
28
29
  installed: boolean;
29
30
  active: boolean;
30
31
  servicePath: string;
31
32
  timerPath: string;
32
- action?: undefined;
33
33
  } | {
34
34
  active?: undefined;
35
35
  name: string;
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
10
10
  inputSchema: {
11
11
  type: string;
12
12
  properties: {
13
+ limit?: undefined;
13
14
  account_id: {
14
15
  type: string;
15
16
  minimum: number;
16
17
  };
17
18
  query?: undefined;
18
19
  timezone?: undefined;
19
- limit?: undefined;
20
20
  page?: undefined;
21
21
  event?: undefined;
22
22
  } | {
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
45
45
  };
46
46
  event?: undefined;
47
47
  } | {
48
+ limit?: undefined;
48
49
  query?: undefined;
49
50
  timezone?: undefined;
50
- limit?: undefined;
51
51
  page?: undefined;
52
52
  event: {
53
53
  type: string;
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
58
58
  minimum: number;
59
59
  };
60
60
  } | {
61
+ limit?: undefined;
61
62
  query?: undefined;
62
63
  timezone?: undefined;
63
- limit?: undefined;
64
64
  page?: undefined;
65
65
  event?: undefined;
66
66
  account_id?: undefined;
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
80
80
  inputSchema: {
81
81
  type: string;
82
82
  properties: {
83
+ limit?: undefined;
83
84
  account_id: {
84
85
  type: string;
85
86
  minimum: number;
86
87
  };
87
88
  query?: undefined;
88
89
  timezone?: undefined;
89
- limit?: undefined;
90
90
  page?: undefined;
91
91
  event?: undefined;
92
92
  } | {
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
115
115
  };
116
116
  event?: undefined;
117
117
  } | {
118
+ limit?: undefined;
118
119
  query?: undefined;
119
120
  timezone?: undefined;
120
- limit?: undefined;
121
121
  page?: undefined;
122
122
  event: {
123
123
  type: string;
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
128
128
  minimum: number;
129
129
  };
130
130
  } | {
131
+ limit?: undefined;
131
132
  query?: undefined;
132
133
  timezone?: undefined;
133
- limit?: undefined;
134
134
  page?: undefined;
135
135
  event?: undefined;
136
136
  account_id?: undefined;
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
150
150
  inputSchema: {
151
151
  type: string;
152
152
  properties: {
153
+ limit?: undefined;
153
154
  account_id: {
154
155
  type: string;
155
156
  minimum: number;
156
157
  };
157
158
  query?: undefined;
158
159
  timezone?: undefined;
159
- limit?: undefined;
160
160
  page?: undefined;
161
161
  event?: undefined;
162
162
  } | {
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
185
185
  };
186
186
  event?: undefined;
187
187
  } | {
188
+ limit?: undefined;
188
189
  query?: undefined;
189
190
  timezone?: undefined;
190
- limit?: undefined;
191
191
  page?: undefined;
192
192
  event: {
193
193
  type: string;
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
198
198
  minimum: number;
199
199
  };
200
200
  } | {
201
+ limit?: undefined;
201
202
  query?: undefined;
202
203
  timezone?: undefined;
203
- limit?: undefined;
204
204
  page?: undefined;
205
205
  event?: undefined;
206
206
  account_id?: undefined;
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
220
220
  inputSchema: {
221
221
  type: string;
222
222
  properties: {
223
+ limit?: undefined;
223
224
  account_id: {
224
225
  type: string;
225
226
  minimum: number;
226
227
  };
227
228
  query?: undefined;
228
229
  timezone?: undefined;
229
- limit?: undefined;
230
230
  page?: undefined;
231
231
  event?: undefined;
232
232
  } | {
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
255
255
  };
256
256
  event?: undefined;
257
257
  } | {
258
+ limit?: undefined;
258
259
  query?: undefined;
259
260
  timezone?: undefined;
260
- limit?: undefined;
261
261
  page?: undefined;
262
262
  event: {
263
263
  type: string;
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
268
268
  minimum: number;
269
269
  };
270
270
  } | {
271
+ limit?: undefined;
271
272
  query?: undefined;
272
273
  timezone?: undefined;
273
- limit?: undefined;
274
274
  page?: undefined;
275
275
  event?: undefined;
276
276
  account_id?: undefined;
@@ -201,6 +201,8 @@ export interface Messenger extends ServiceMessenger {
201
201
  * profile and mounts the local task builders with `--provider --account`.
202
202
  */
203
203
  accountOf?: (command: Command) => AccountKey | undefined;
204
+ /** Every account a read covers when the command names none: memo's `stats tasks show` without `--source`. */
205
+ accountsOf?: (command: Command) => readonly AccountKey[] | undefined;
204
206
  /**
205
207
  * Whether a stored chat may hold a message the messenger deleted without naming its chat. When
206
208
  * unset, the store applies Telegram's rule.
@@ -4,7 +4,7 @@ import { LOCAL_READ } from "../effects.js";
4
4
  import { renderAnswer } from "../envelope.js";
5
5
  import { messengerContext } from "./context.js";
6
6
  import { refuseJsonl, responsesAnswer, waitingAnswer } from "./stats-answers.js";
7
- const QUERY = "date:, chat: and kind: terms, AND-ed — date>=30d, date:[60d TO 30d]; none reads all time";
7
+ const QUERY = "date:, chat:, kind: and muted: terms, AND-ed — date>=30d, date:[60d TO 30d], muted:false; none reads all time";
8
8
  const GUIDE = "Guide: https://github.com/WireCatLabs/cli-core/blob/main/docs/rankings.md#reply-times-and-chats-waiting-on-you";
9
9
  const minutes = (ms) => (ms === null ? "—" : `${Math.round(ms / 60_000)} min`);
10
10
  export const replyResponsesCommand = (messenger) => annotate(new Command("responses"), { effects: LOCAL_READ, output: { entity: "response_times" } })
@@ -91,6 +91,7 @@ export declare const serveRelay: (command: Command, messenger: Messenger) => {
91
91
  adminRights?: readonly import("../../domain/models.js").AdminRight[];
92
92
  pickAdminRights?: boolean;
93
93
  accountOf?: (command: Command) => import("../../store/types.js").AccountKey | undefined;
94
+ accountsOf?: (command: Command) => readonly import("../../store/types.js").AccountKey[] | undefined;
94
95
  deletedWithoutChat?: import("../../store/types.js").DeletionScope;
95
96
  officialStats?: boolean;
96
97
  tracksMembers?: boolean;
@@ -71,8 +71,11 @@ export declare const refuseJsonl: (format: string) => void;
71
71
  export declare const chatStatsAnswer: (stats: ChatStats, account: AccountKey, meta?: Partial<Meta>) => ItemBody<Of<"chat_stats">>;
72
72
  /** Said where the store has kept no join, leave or other chat event for the chat: a 0 would read as nobody joined. */
73
73
  export declare const MEMBERS_UNRECORDED = "joins and leaves are not recorded for this chat yet, so they are not counted";
74
- /** `stats tasks show`, CLI and MCP alike. A row of `--by chat` also names its chat as `chat`, as it always has. */
75
- export declare const taskStatsAnswer: (stats: TaskStats, account: AccountKey) => ItemBody<Of<"task_stats">>;
74
+ /**
75
+ * `stats tasks show`, CLI and MCP alike. A row of `--by chat` also names its chat as `chat`, as it always has;
76
+ * `account` is the one account read, and an answer across several names each row's own.
77
+ */
78
+ export declare const taskStatsAnswer: (stats: TaskStats, account: AccountKey | undefined) => ItemBody<Of<"task_stats">>;
76
79
  export declare const responsesAnswer: (found: ReplyTimes) => ItemBody<Of<"response_times">>;
77
80
  export declare const waitingAnswer: (found: Waiting) => ItemBody<Of<"waiting_chats">>;
78
81
  export {};
@@ -1,5 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { formatLocator } from "../../domain/locator.js";
3
+ import { taskAccount } from "../../services/task-rules.js";
3
4
  import { itemOf, listOf } from "../envelope.js";
4
5
  import { nextStep } from "../steps.js";
5
6
  import { chatRef, contactRef } from "./chat-answers.js";
@@ -410,15 +411,20 @@ export const chatStatsAnswer = (stats, account, meta) => {
410
411
  };
411
412
  /** Said where the store has kept no join, leave or other chat event for the chat: a 0 would read as nobody joined. */
412
413
  export const MEMBERS_UNRECORDED = "joins and leaves are not recorded for this chat yet, so they are not counted";
413
- /** `stats tasks show`, CLI and MCP alike. A row of `--by chat` also names its chat as `chat`, as it always has. */
414
+ /**
415
+ * `stats tasks show`, CLI and MCP alike. A row of `--by chat` also names its chat as `chat`, as it always has;
416
+ * `account` is the one account read, and an answer across several names each row's own.
417
+ */
414
418
  export const taskStatsAnswer = (stats, account) => itemOf({
419
+ ...(stats.accounts ? { accounts: stats.accounts.map(taskAccount) } : {}),
415
420
  open: stats.open,
416
421
  created: stats.created,
417
422
  closed: stats.closed,
418
423
  median_close_ms: stats.medianCloseMs ?? null,
419
424
  mean_open_age_ms: stats.meanOpenAgeMs ?? null,
420
425
  rows: stats.rows.map((row) => {
421
- const chat = stats.by === "chat" ? chatRef(account, row.group) : undefined;
426
+ const own = row.account ?? account;
427
+ const chat = stats.by === "chat" && own ? chatRef(own, row.group) : undefined;
422
428
  return {
423
429
  ...(chat === undefined ? {} : { chat }),
424
430
  key: chat ?? (stats.by === "project" ? `project:${row.group}` : row.group),
@@ -566,6 +566,7 @@ export const tasksStatsCommand = (messenger) => {
566
566
  const { by, chat, type, timezone } = this.opts();
567
567
  refuseJsonl(context.format);
568
568
  const query = listQuery(typedQuery(words), TASK_STATS_QUERY, "stats tasks show");
569
+ const accounts = messenger.accountsOf?.(this);
569
570
  const { stats, account } = await context.withServices(async (services) => ({
570
571
  stats: await services.tasks.stats({
571
572
  ...(by === undefined ? {} : { by }),
@@ -573,16 +574,17 @@ export const tasksStatsCommand = (messenger) => {
573
574
  ...(type === undefined ? {} : { kind: type }),
574
575
  ...(query === undefined ? {} : { query }),
575
576
  ...(timezone === undefined ? {} : { timezone }),
577
+ ...(accounts === undefined ? {} : { accounts }),
576
578
  }),
577
- account: await services.messages.reader(),
579
+ account: accounts === undefined ? await services.messages.reader() : undefined,
578
580
  }));
579
581
  if (stats.rows.length === 0)
580
582
  context.renderer.note("no tasks yet");
581
583
  renderAnswer(this, context, taskStatsAnswer(stats, account), () => stats.rows.length === 0
582
584
  ? ""
583
585
  : `${stats.rows
584
- .map(({ group, name, open, created, closed, oldestOpenAt, medianCloseMs }) => [
585
- name ? `${name} (${group})` : group,
586
+ .map(({ group, account: own, name, open, created, closed, oldestOpenAt, medianCloseMs }) => [
587
+ `${name ? `${name} (${group})` : group}${own ? ` ${own.provider}:${own.account}` : ""}`,
586
588
  `${open} open`,
587
589
  `${created} created`,
588
590
  `${closed} closed`,
@@ -5,7 +5,7 @@ import * as v from "valibot";
5
5
  import { answerEntity } from "../../cli/answer-entity.js";
6
6
  import { environmentOf, inCommandRun, outputFor, runBudgetOf } from "../../cli/context.js";
7
7
  import { honoursDryRun } from "../../cli/dry-run-guard.js";
8
- import { FETCH, LOCAL_READ, NO_EFFECTS, REMOTE_WRITE } from "../../cli/effects.js";
8
+ import { FETCH, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS, REMOTE_WRITE } from "../../cli/effects.js";
9
9
  import { itemOf, listOf, renderAnswer, snakeKeys, snakeKeysKeeping } from "../../cli/envelope.js";
10
10
  import { queryTerms, termField, unfilteredQuery, withQuery } from "../../cli/list-query.js";
11
11
  import { terminalAsker } from "../../cli/messenger/ask.js";
@@ -14,7 +14,7 @@ import { CRM_KINDS } from "../../domain/crm.js";
14
14
  import { DEAL_KINDS, DEAL_STATUSES } from "../../domain/deals.js";
15
15
  import { deal as dealEntity } from "../../entities/deal.js";
16
16
  import { count, text } from "../../entities/fields.js";
17
- import { CRM_SCOPES } from "../../store/sqlite/crm-settings.js";
17
+ import { CRM_SCOPES, crmSettingKey } from "../../store/sqlite/crm-settings.js";
18
18
  import { crmStatus, syncCrm } from "../sync.js";
19
19
  import { closeCrmItem, createCrmItem, fieldPairsOf, moveCrmItem, pipelineOf, removeCrmItem, updateCrmItem, } from "../writes.js";
20
20
  import { csvFormatOption, renderCsv } from "./csv.js";
@@ -58,6 +58,13 @@ const DEAL_UNTRUSTED = [
58
58
  ];
59
59
  const PIPELINE_UNTRUSTED = ["name", "stages.name"];
60
60
  const STAGE_UNTRUSTED = ["name", "pipeline_name"];
61
+ const crmContactsRemoved = v.strictObject({
62
+ contacts: count,
63
+ persons: count,
64
+ persons_kept: count,
65
+ names: count,
66
+ });
67
+ const crmContactsApplied = v.strictObject({ ...crmContactsRemoved.entries, applied: v.boolean() });
61
68
  const crmSync = v.strictObject({
62
69
  provider: text,
63
70
  account: text,
@@ -68,6 +75,7 @@ const crmSync = v.strictObject({
68
75
  pipelines: count,
69
76
  users: v.optional(count),
70
77
  skipped_owner_rejected: count,
78
+ contacts_removed: v.optional(crmContactsRemoved),
71
79
  synced: v.array(v.strictObject({
72
80
  kind: v.picklist(CRM_KINDS),
73
81
  round: v.picklist(["full", "changes"]),
@@ -251,6 +259,18 @@ const addCrmCommandsDefinition = (program, options) => {
251
259
  });
252
260
  });
253
261
  });
262
+ example(answerEntity(annotate(store.command("apply"), { effects: LOCAL_WRITE }), "crm_contacts_removed", crmContactsApplied).description("apply scope mine to the contacts already stored: remove those no deal or lead of the chosen users and no " +
263
+ "kept company names, and the people they leave empty; counts only unless --yes, under scope all too. A " +
264
+ "sync that narrows the scope, or sync --rescan under mine, does this itself"), "store apply", "store apply --yes").action(async (_opts, command) => {
265
+ const yes = command.optsWithGlobals().yes === true;
266
+ await within(command, async (run) => {
267
+ const scope = crmSettingKey(run.account, "scope");
268
+ if (yes && (await run.store.crm.scope(run.account)).mode !== "mine")
269
+ throw new CliError("validation_error", `scope is all, so a sync would copy these contacts again: set ${scope} to mine first`, { setting: scope });
270
+ const removed = await run.store.crm.removeContacts(run.account, { before: now(), dryRun: !yes });
271
+ return itemOf(snakeKeys({ ...removed, applied: yes }));
272
+ });
273
+ });
254
274
  const items = (kind) => {
255
275
  const plural = `${kind}s`;
256
276
  const query = kind === "deal" ? DEALS_QUERY : LEADS_QUERY;
@@ -1,6 +1,6 @@
1
1
  import { type BudgetStop, type RunBudget } from "../background/budget.js";
2
2
  import { type CrmKind, type CrmScope } from "../domain/crm.js";
3
- import type { CrmRelationIssue, CrmSkipped } from "../store/sqlite/crm.js";
3
+ import type { CrmContactsRemoved, CrmRelationIssue, CrmSkipped } from "../store/sqlite/crm.js";
4
4
  import type { MessageStore } from "../store/store.js";
5
5
  import type { AccountKey } from "../store/types.js";
6
6
  import type { CrmGap, CrmSource } from "./source.js";
@@ -88,6 +88,8 @@ export interface CrmSyncReport {
88
88
  scope: CrmScope;
89
89
  /** Relationships left out because the owner removed or rejected that very one, role included. */
90
90
  skippedOwnerRejected: number;
91
+ /** After a complete run that narrowed the copy or listed it again under `mine`: the contacts outside it, removed. */
92
+ contactsRemoved?: CrmContactsRemoved;
91
93
  synced: CrmSyncResult[];
92
94
  issues: CrmSyncIssue[];
93
95
  /** Every kind finished its round and none failed. */
package/dist/crm/sync.js CHANGED
@@ -524,6 +524,11 @@ export const syncCrm = async (source, store, account, options = {}) => {
524
524
  }
525
525
  // A relationship held back for an end a later page or kind brought is written now; it costs no request.
526
526
  run.droppedPending += (await store.crm.retryPending(account)).dropped;
527
+ const narrowed = report.synced.some((one) => one.outOfScope > 0);
528
+ const whole = report.synced.every((one) => one.state === "complete" && one.error === undefined && !one.held && one.pass !== "held");
529
+ // Contacts have no scope of their own and no deletion check: they leave with the last deal or lead naming them.
530
+ if (scope.mode === "mine" && (options.rescan || narrowed) && whole && !stopped && kinds.includes("person"))
531
+ report.contactsRemoved = await store.crm.removeContacts(account, { users: scopeIds(scope) ?? [], before: now });
527
532
  if (run.unlistedUsers)
528
533
  report.issues.push({
529
534
  kind: "deal",
@@ -155,7 +155,8 @@ export type CrmScopeSetting = {
155
155
  };
156
156
  /**
157
157
  * Which deals and leads a sync copies: all, or those with no assignee or assigned to the sign-in's own user (`self`)
158
- * or to one of `also`. Contacts and companies are always copied whole. Ids are normalised (`normalCrmUserId`).
158
+ * or to one of `also`. Companies and contacts are what the source lists; under `mine`, a contact no kept deal, lead or
159
+ * company names is removed after a sync that narrowed the copy or listed it again. Ids are normalised (`normalCrmUserId`).
159
160
  */
160
161
  export type CrmScope = {
161
162
  mode: "all";
@@ -0,0 +1,15 @@
1
+ /** The people the shared contract seed (`src/kit/seed.ts`) makes, so a test run that reached a real store shows. */
2
+ export declare const SEED_PEOPLE: readonly [{
3
+ readonly name: "Owner";
4
+ readonly username: "owner";
5
+ }, {
6
+ readonly name: "Ann Lee";
7
+ readonly username: "ann";
8
+ }, {
9
+ readonly name: "Bob Ray";
10
+ readonly username: null;
11
+ }];
12
+ /** Domains no real mailbox has (RFC 2606 and RFC 6761), as SQLite `GLOB` patterns over a lower-cased address. */
13
+ export declare const RESERVED_ADDRESS_GLOBS: readonly ["*@example.com", "*@example.net", "*@example.org", "*.example", "*.test", "*.invalid", "*.localhost"];
14
+ /** Ids made by the seed's `wordIds`; numeric ids are real for some providers, so `digitIds` are not counted. */
15
+ export declare const SEED_ID_GLOBS: readonly ["person-[0-9]*"];
@@ -0,0 +1,18 @@
1
+ /** The people the shared contract seed (`src/kit/seed.ts`) makes, so a test run that reached a real store shows. */
2
+ export const SEED_PEOPLE = [
3
+ { name: "Owner", username: "owner" },
4
+ { name: "Ann Lee", username: "ann" },
5
+ { name: "Bob Ray", username: null },
6
+ ];
7
+ /** Domains no real mailbox has (RFC 2606 and RFC 6761), as SQLite `GLOB` patterns over a lower-cased address. */
8
+ export const RESERVED_ADDRESS_GLOBS = [
9
+ "*@example.com",
10
+ "*@example.net",
11
+ "*@example.org",
12
+ "*.example",
13
+ "*.test",
14
+ "*.invalid",
15
+ "*.localhost",
16
+ ];
17
+ /** Ids made by the seed's `wordIds`; numeric ids are real for some providers, so `digitIds` are not counted. */
18
+ export const SEED_ID_GLOBS = ["person-[0-9]*"];
@@ -67,6 +67,8 @@ export declare const chatStats: v.StrictObjectSchema<{
67
67
  * tasks opened and closed in the query's period, every task without one.
68
68
  */
69
69
  export declare const taskStats: v.StrictObjectSchema<{
70
+ /** Every account counted, `provider:account`, when the answer reads several (memo without `--source`). */
71
+ readonly accounts: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
70
72
  /** Open tasks across every row. */
71
73
  readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
72
74
  readonly created: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -60,6 +60,8 @@ const ms = v.nullable(v.pipe(v.number(), v.minValue(0)));
60
60
  * tasks opened and closed in the query's period, every task without one.
61
61
  */
62
62
  export const taskStats = v.strictObject({
63
+ /** Every account counted, `provider:account`, when the answer reads several (memo without `--source`). */
64
+ accounts: v.optional(v.array(text)),
63
65
  /** Open tasks across every row. */
64
66
  open: count,
65
67
  created: count,
@@ -11929,6 +11929,7 @@ export declare const ENTITIES: {
11929
11929
  readonly tracked: v.BooleanSchema<undefined>;
11930
11930
  }, undefined>;
11931
11931
  readonly task_stats: v.StrictObjectSchema<{
11932
+ readonly accounts: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
11932
11933
  readonly open: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
11933
11934
  readonly created: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
11934
11935
  readonly closed: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -391,6 +391,14 @@ const OTHERS = [
391
391
  "conflict",
392
392
  "the people a merge or a proposed link names changed since; undo the later merge, or propose the link again",
393
393
  ],
394
+ ["identity.no-merge", "not_found", "nothing of that person is merged into the other; people show lists the merges"],
395
+ validation("identity.several-persons", "the identities that leave a person are all of that one person"),
396
+ validation("identity.nothing-left", "a split leaves at least one identity with the person"),
397
+ [
398
+ "identity.kept-together",
399
+ "conflict",
400
+ "the owner kept these identities together by turning down their split; only the owner splits them",
401
+ ],
394
402
  [
395
403
  "identity.rejected",
396
404
  "conflict",
@@ -402,6 +410,7 @@ const OTHERS = [
402
410
  validation("identity.owner", "one side is the owner's person, and only the owner joins anyone to themselves"),
403
411
  validation("identity.shared-email", "more than six people share the address, so it proposes no one"),
404
412
  validation("identity-link.dedicated-review", "an identity link is staged and decided through the people review"),
413
+ validation("identity-split.dedicated-review", "a split of a person is staged and decided through the people review"),
405
414
  ["transcription.no-key", "authentication_error", "no OpenAI key is set for transcription"],
406
415
  validation("transcription.too-large", "the audio is over the transcription provider's size limit"),
407
416
  [
package/dist/kit/seed.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { SEED_PEOPLE } from "../domain/test-data.js";
1
2
  export const BUSY_PAGE = 3;
2
3
  const BUSY_MESSAGES = 10;
3
4
  /** Ids that are not numbers, so no code may take them for one. */
@@ -12,15 +13,13 @@ const START = Date.parse("2026-09-01T09:00:00.000Z");
12
13
  */
13
14
  export const contractSeed = ({ ids = wordIds, loggedIn = true } = {}) => {
14
15
  const at = (minute) => new Date(START + minute * 60_000);
15
- const owner = {
16
- id: ids("person", 1, at(0)),
17
- name: "Owner",
18
- username: "owner",
16
+ const [owner, ann, bob] = SEED_PEOPLE.map(({ name, username }, index) => ({
17
+ id: ids("person", index + 1, at(0)),
18
+ name,
19
+ username,
19
20
  description: null,
20
21
  lastMessagedAt: null,
21
- };
22
- const ann = { ...owner, id: ids("person", 2, at(0)), name: "Ann Lee", username: "ann" };
23
- const bob = { ...owner, id: ids("person", 3, at(0)), name: "Bob Ray", username: null };
22
+ }));
24
23
  let messageNumber = 0;
25
24
  const message = (chatId, minute, from, text) => {
26
25
  messageNumber += 1;
@@ -189,6 +189,17 @@ export const QUERY_FIELDS = [
189
189
  support: "A1",
190
190
  values: ["private", "saved", "bot", "service", "group", "channel", "unknown"],
191
191
  },
192
+ {
193
+ name: "muted",
194
+ example: "muted:false",
195
+ index: "chats.muted / chats.muted_until",
196
+ aliases: [],
197
+ type: "enum",
198
+ operators: terms,
199
+ normalization: "lowercase; true is a chat the owner muted, until the mute runs out; false is every other chat",
200
+ support: "A1",
201
+ values: ["true", "false"],
202
+ },
192
203
  {
193
204
  name: "has",
194
205
  example: "has:file",
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
14
14
  dryRun?: boolean;
15
15
  }) => Promise<{
16
16
  items: ({
17
+ error?: undefined;
17
18
  chatId: string;
18
19
  tags: import("../domain/channel-tags.js").ChannelTagMatch[];
19
20
  algorithm: string;
20
21
  fetchedAt: string | null;
21
22
  source: string;
22
- error?: undefined;
23
23
  } | {
24
24
  tags?: undefined;
25
25
  algorithm?: undefined;
@@ -0,0 +1,4 @@
1
+ import type { MessageStore } from "../../../store/index.js";
2
+ import type { ProposalKind } from "../types.js";
3
+ /** Identities that may not belong to their person; only the owner takes them off. */
4
+ export declare const identitySplitKind: (store: Pick<MessageStore, "people" | "proposedActions">) => ProposalKind;