@wirecat/cli-core 0.675.0 → 0.677.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 (74) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/dist/calendar/mcp/index.d.ts +12 -12
  3. package/dist/cli/command-runs.d.ts +2 -0
  4. package/dist/cli/command-runs.js +2 -0
  5. package/dist/cli/documents/words.d.ts +1 -1
  6. package/dist/cli/index.d.ts +2 -2
  7. package/dist/cli/index.js +1 -1
  8. package/dist/cli/list-query.d.ts +3 -2
  9. package/dist/cli/list-query.js +5 -2
  10. package/dist/cli/setup-command.js +9 -3
  11. package/dist/crm/cli/index.d.ts +7 -1
  12. package/dist/crm/cli/index.js +104 -20
  13. package/dist/crm/cli/pipeline-view.js +15 -1
  14. package/dist/crm/cli/records.js +11 -3
  15. package/dist/crm/cli/search-all.d.ts +5 -2
  16. package/dist/crm/cli/search-all.js +15 -3
  17. package/dist/crm/source.d.ts +3 -2
  18. package/dist/crm/stage-tasks.js +1 -1
  19. package/dist/crm/sync.js +13 -11
  20. package/dist/crm/testing/write-contract.js +5 -1
  21. package/dist/crm/viewer.d.ts +28 -0
  22. package/dist/crm/viewer.js +63 -0
  23. package/dist/crm/writer.d.ts +3 -0
  24. package/dist/crm/writes.d.ts +7 -2
  25. package/dist/crm/writes.js +24 -14
  26. package/dist/domain/crm.d.ts +9 -9
  27. package/dist/domain/moment.d.ts +2 -0
  28. package/dist/domain/moment.js +2 -0
  29. package/dist/entities/business-context.js +1 -1
  30. package/dist/entities/deal.d.ts +86 -39
  31. package/dist/entities/deal.js +45 -4
  32. package/dist/entities/index.d.ts +20 -32
  33. package/dist/errors/reasons.js +2 -0
  34. package/dist/meetings/mcp/index.d.ts +15 -15
  35. package/dist/services/metadata.d.ts +1 -1
  36. package/dist/services/search-all.d.ts +3 -1
  37. package/dist/services/search-all.js +1 -0
  38. package/dist/setup/define.d.ts +17 -2
  39. package/dist/store/exports.d.ts +1 -0
  40. package/dist/store/exports.js +1 -0
  41. package/dist/store/identity-links.d.ts +73 -0
  42. package/dist/store/identity-links.js +14 -0
  43. package/dist/store/index.d.ts +1 -1
  44. package/dist/store/index.js +1 -1
  45. package/dist/store/people.d.ts +23 -1
  46. package/dist/store/people.js +12 -1
  47. package/dist/store/sqlite/agent-links.d.ts +34 -0
  48. package/dist/store/sqlite/agent-links.js +184 -0
  49. package/dist/store/sqlite/copy-viewer.d.ts +16 -0
  50. package/dist/store/sqlite/copy-viewer.js +11 -0
  51. package/dist/store/sqlite/crm-activities.d.ts +7 -1
  52. package/dist/store/sqlite/crm-activities.js +32 -5
  53. package/dist/store/sqlite/crm-contacts.d.ts +5 -2
  54. package/dist/store/sqlite/crm-contacts.js +30 -14
  55. package/dist/store/sqlite/crm-rows.d.ts +7 -0
  56. package/dist/store/sqlite/crm-rows.js +37 -5
  57. package/dist/store/sqlite/crm-settings.d.ts +2 -1
  58. package/dist/store/sqlite/crm-settings.js +3 -2
  59. package/dist/store/sqlite/crm-stage-entries.d.ts +24 -4
  60. package/dist/store/sqlite/crm-stage-entries.js +77 -18
  61. package/dist/store/sqlite/crm.d.ts +14 -4
  62. package/dist/store/sqlite/crm.js +59 -7
  63. package/dist/store/sqlite/deals.d.ts +47 -29
  64. package/dist/store/sqlite/deals.js +64 -76
  65. package/dist/store/sqlite/identity-proposals.d.ts +2 -0
  66. package/dist/store/sqlite/identity-proposals.js +2 -0
  67. package/dist/store/sqlite/person-match-scan.d.ts +29 -0
  68. package/dist/store/sqlite/person-match-scan.js +4 -4
  69. package/dist/store/sqlite/person-merges.d.ts +3 -0
  70. package/dist/store/sqlite/pipeline-period.d.ts +85 -0
  71. package/dist/store/sqlite/pipeline-period.js +199 -0
  72. package/dist/store/sqlite/stage-amounts.d.ts +6 -2
  73. package/dist/store/sqlite/stage-amounts.js +8 -5
  74. package/package.json +3 -3
@@ -38,6 +38,7 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
+ limit?: undefined;
41
42
  event_id?: undefined;
42
43
  series_id?: undefined;
43
44
  page?: undefined;
@@ -53,11 +54,11 @@ export declare const meetingTools: ({
53
54
  format?: undefined;
54
55
  transcript_id?: undefined;
55
56
  query?: undefined;
56
- limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
+ limit?: undefined;
61
62
  event_id?: undefined;
62
63
  series_id?: undefined;
63
64
  page?: undefined;
@@ -75,11 +76,11 @@ export declare const meetingTools: ({
75
76
  format?: undefined;
76
77
  transcript_id?: undefined;
77
78
  query?: undefined;
78
- limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
+ limit?: undefined;
83
84
  event_id?: undefined;
84
85
  series_id?: undefined;
85
86
  page?: undefined;
@@ -101,7 +102,6 @@ export declare const meetingTools: ({
101
102
  minimum: number;
102
103
  };
103
104
  query?: undefined;
104
- limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,6 +188,7 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
+ limit?: undefined;
191
192
  event_id?: undefined;
192
193
  series_id?: undefined;
193
194
  page?: undefined;
@@ -203,11 +204,11 @@ export declare const meetingTools: ({
203
204
  format?: undefined;
204
205
  transcript_id?: undefined;
205
206
  query?: undefined;
206
- limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
+ limit?: undefined;
211
212
  event_id?: undefined;
212
213
  series_id?: undefined;
213
214
  page?: undefined;
@@ -225,11 +226,11 @@ export declare const meetingTools: ({
225
226
  format?: undefined;
226
227
  transcript_id?: undefined;
227
228
  query?: undefined;
228
- limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
+ limit?: undefined;
233
234
  event_id?: undefined;
234
235
  series_id?: undefined;
235
236
  page?: undefined;
@@ -251,7 +252,6 @@ export declare const meetingTools: ({
251
252
  minimum: number;
252
253
  };
253
254
  query?: undefined;
254
- limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,6 +338,7 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
+ limit?: undefined;
341
342
  event_id?: undefined;
342
343
  series_id?: undefined;
343
344
  page?: undefined;
@@ -353,11 +354,11 @@ export declare const meetingTools: ({
353
354
  format?: undefined;
354
355
  transcript_id?: undefined;
355
356
  query?: undefined;
356
- limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
+ limit?: undefined;
361
362
  event_id?: undefined;
362
363
  series_id?: undefined;
363
364
  page?: undefined;
@@ -375,11 +376,11 @@ export declare const meetingTools: ({
375
376
  format?: undefined;
376
377
  transcript_id?: undefined;
377
378
  query?: undefined;
378
- limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
+ limit?: undefined;
383
384
  event_id?: undefined;
384
385
  series_id?: undefined;
385
386
  page?: undefined;
@@ -401,7 +402,6 @@ export declare const meetingTools: ({
401
402
  minimum: number;
402
403
  };
403
404
  query?: undefined;
404
- limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,6 +488,7 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
+ limit?: undefined;
491
492
  event_id?: undefined;
492
493
  series_id?: undefined;
493
494
  page?: undefined;
@@ -503,11 +504,11 @@ export declare const meetingTools: ({
503
504
  format?: undefined;
504
505
  transcript_id?: undefined;
505
506
  query?: undefined;
506
- limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
+ limit?: undefined;
511
512
  event_id?: undefined;
512
513
  series_id?: undefined;
513
514
  page?: undefined;
@@ -525,11 +526,11 @@ export declare const meetingTools: ({
525
526
  format?: undefined;
526
527
  transcript_id?: undefined;
527
528
  query?: undefined;
528
- limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
+ limit?: undefined;
533
534
  event_id?: undefined;
534
535
  series_id?: undefined;
535
536
  page?: undefined;
@@ -551,7 +552,6 @@ export declare const meetingTools: ({
551
552
  minimum: number;
552
553
  };
553
554
  query?: undefined;
554
- limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,6 +638,7 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
+ limit?: undefined;
641
642
  event_id?: undefined;
642
643
  series_id?: undefined;
643
644
  page?: undefined;
@@ -653,11 +654,11 @@ export declare const meetingTools: ({
653
654
  format?: undefined;
654
655
  transcript_id?: undefined;
655
656
  query?: undefined;
656
- limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
+ limit?: undefined;
661
662
  event_id?: undefined;
662
663
  series_id?: undefined;
663
664
  page?: undefined;
@@ -675,11 +676,11 @@ export declare const meetingTools: ({
675
676
  format?: undefined;
676
677
  transcript_id?: undefined;
677
678
  query?: undefined;
678
- limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
+ limit?: undefined;
683
684
  event_id?: undefined;
684
685
  series_id?: undefined;
685
686
  page?: undefined;
@@ -701,7 +702,6 @@ export declare const meetingTools: ({
701
702
  minimum: number;
702
703
  };
703
704
  query?: undefined;
704
- limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -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;
@@ -3,7 +3,7 @@ import { type HitFile } from "../domain/attachments.js";
3
3
  import type { DealKind } from "../domain/deals.js";
4
4
  import { type MailFields } from "../domain/models.js";
5
5
  import type { MessengerTraits } from "../ports/traits.js";
6
- import type { AccountKey, BusinessKind, BusinessSource, MessageStore, StoredAccount } from "../store/store.js";
6
+ import type { AccountKey, BusinessKind, BusinessSource, CopyViewer, MessageStore, StoredAccount } from "../store/store.js";
7
7
  import type { SearchFound, SearchQuery } from "./messages.js";
8
8
  import { type MeaningLane, type MeaningSkipped } from "./messages-discovery.js";
9
9
  import type { SearchCoverage } from "./messages-search.js";
@@ -150,6 +150,8 @@ export interface SearchAllRequest {
150
150
  meetingsAsked?: boolean;
151
151
  /** The CRM kinds `crm` reads; absent, deals and leads. */
152
152
  crmKinds?: readonly DealKind[];
153
+ /** The CRM accounts' copies a CRM CLI's profile may read only part of, each by its own rule (SEC-197). */
154
+ crmViewers?: CopyViewer[];
153
155
  /**
154
156
  * Search harder: a hosted model reorders the first 30 hits, only with the owner's consent and a key. Absent, nothing
155
157
  * is read of the consent or the key and nothing is sent.
@@ -331,6 +331,7 @@ export const searchAll = async (store, account, asked, messenger = {}, searchMes
331
331
  anyWord: anyWord || discover,
332
332
  ...(request.exact ? { exact: true } : {}),
333
333
  ...(request.crmKinds === undefined ? {} : { kinds: request.crmKinds }),
334
+ ...(request.crmViewers === undefined ? {} : { viewers: request.crmViewers }),
334
335
  limit: Math.min(depth, 500),
335
336
  ...(chosen === undefined ? {} : { accounts: chosen }),
336
337
  });
@@ -15,8 +15,23 @@ export interface SetupCheckInput {
15
15
  /** The sign-in events (`progress`, `needs`…) Desktop reads on stderr. */
16
16
  steps: SignInSteps;
17
17
  }
18
- /** The CLI's own proof that the answers work, as its `session start` checks. A throw saves nothing. */
19
- export type SetupCheck = (input: SetupCheckInput) => Promise<Record<string, unknown> | undefined>;
18
+ /**
19
+ * What `apply` keeps in place of its defaults, for a CLI whose `session start` keeps more than the typed secret (an
20
+ * account address beside a token) or knows the account the profile signs in to.
21
+ */
22
+ export interface SetupKeep {
23
+ /** By secret name, the value to keep instead of the one typed; a name the path gave no secret for is refused. */
24
+ secrets?: Readonly<Record<string, string>>;
25
+ /** The account the profile is, as `session start` remembers it; the profile's name when left out. */
26
+ account?: string;
27
+ }
28
+ /**
29
+ * The CLI's own proof that the answers work, as its `session start` checks. A throw saves nothing. `keep` is taken
30
+ * out of the result, never printed.
31
+ */
32
+ export type SetupCheck = (input: SetupCheckInput) => Promise<(Record<string, unknown> & {
33
+ keep?: SetupKeep;
34
+ }) | undefined>;
20
35
  export interface SetupDefinition {
21
36
  app: AppIdentity;
22
37
  configuration: Pick<Configuration, "allSettings" | "settingSchema" | "resolveSettings" | "changeSetting">;
@@ -26,6 +26,7 @@ export { CHAT_COLUMNS, TRACKED_CHAT_COLUMNS, titlePart } from "./sqlite/chats.js
26
26
  export { storeClients } from "./sqlite/clients.js";
27
27
  export { CHAT_LIST_KEY, type ChatCompleteness, type ChatCoverage, fetchedKey, historyStartKey, } from "./sqlite/completeness.js";
28
28
  export { CONVERSATION_COLUMNS } from "./sqlite/conversations.js";
29
+ export { type CopyViewer, seenBy } from "./sqlite/copy-viewer.js";
29
30
  export type { CounterTarget } from "./sqlite/counters.js";
30
31
  export { crmSettingsOf, parseCrmSetting, parseCrmSettingValue, saveCrmSetting } from "./sqlite/crm-settings.js";
31
32
  export { type EmailMarks, MAIL_AGENDA_COLUMNS, type MarkedEmail, type NewestEmail, type ThreadActivity, } from "./sqlite/email-activity.js";
@@ -8,6 +8,7 @@ export { CHAT_COLUMNS, TRACKED_CHAT_COLUMNS, titlePart } from "./sqlite/chats.js
8
8
  export { storeClients } from "./sqlite/clients.js";
9
9
  export { CHAT_LIST_KEY, fetchedKey, historyStartKey, } from "./sqlite/completeness.js";
10
10
  export { CONVERSATION_COLUMNS } from "./sqlite/conversations.js";
11
+ export { seenBy } from "./sqlite/copy-viewer.js";
11
12
  export { crmSettingsOf, parseCrmSetting, parseCrmSettingValue, saveCrmSetting } from "./sqlite/crm-settings.js";
12
13
  export { MAIL_AGENDA_COLUMNS, } from "./sqlite/email-activity.js";
13
14
  export { messageOfEmail, threadConversation } from "./sqlite/emails.js";
@@ -32,6 +32,79 @@ export interface IdentityLinkPayload {
32
32
  shared?: SharedMailbox;
33
33
  /** The shared mailbox's address, with `shared`. */
34
34
  mailbox?: string;
35
+ /** What the store found between the two people when an agent linked them, and whether it was strong. */
36
+ strength?: LinkEvidence;
37
+ /** The agent's run (`meta.run_id`) that linked them. */
38
+ run?: string;
39
+ /** `agent`: an agent's link the store applied at once on strong evidence; the row records it, decided. */
40
+ applied?: "agent";
41
+ }
42
+ /**
43
+ * Why a shared phone or address is not strong enough for an agent to merge on: an office's number, more people have
44
+ * it, a company's line or mailbox, a role or no-reply address, only one source gives it, or for a phone no source that
45
+ * keeps its user's own number (a CRM's or a card's is someone's word, NEED-2445).
46
+ */
47
+ export declare const LINK_WEAKNESSES: readonly ["landline", "shared", "company", "role-address", "no-reply", "one-source", "not-own-number"];
48
+ export type LinkWeakness = (typeof LINK_WEAKNESSES)[number];
49
+ /** A phone or address both people hold. */
50
+ export interface LinkFact {
51
+ kind: "phone" | "email";
52
+ /** E.164 for a phone, lower case for an address. */
53
+ value: string;
54
+ /** `provider:id` of the identities that hold it, on each of the two people. */
55
+ holders: [string[], string[]];
56
+ /** How many other people hold it. */
57
+ others: number;
58
+ strong: boolean;
59
+ weak: LinkWeakness | null;
60
+ }
61
+ /**
62
+ * Why an agent's link did not merge at once: the evidence is weak (`LinkWeakness`), they share no phone or address
63
+ * (`nothing-shared`), one is the owner's person, the owner rejected the pair before, or the owner's setting says
64
+ * agents only propose.
65
+ */
66
+ export type LinkHold = LinkWeakness | "nothing-shared" | "owner" | "rejected" | "propose-only";
67
+ /**
68
+ * What the store finds between two people, never what an agent says. Strong is one value that is a mobile number or a
69
+ * personal address, that only these two people hold, from two different sources, and for a phone at least one that
70
+ * keeps its user's own number: a messenger account or a call's number.
71
+ */
72
+ export interface LinkEvidence {
73
+ /** `person:<uid>` of each. */
74
+ persons: [string, string];
75
+ strong: boolean;
76
+ facts: LinkFact[];
77
+ /** `null` when strong. */
78
+ weak: LinkHold | null;
79
+ }
80
+ export interface AgentLinkInput {
81
+ identity: IdentityRef;
82
+ with: IdentityRef;
83
+ /** The agent's name, as `whoRuns` gives it. */
84
+ bot: string;
85
+ run?: string;
86
+ reason: string;
87
+ /** False when the owner's setting says agents only propose. */
88
+ apply: boolean;
89
+ }
90
+ export type AgentLink = {
91
+ outcome: "merged";
92
+ person: string;
93
+ merge: string;
94
+ proposal: string;
95
+ evidence: LinkEvidence;
96
+ } | {
97
+ outcome: "proposed";
98
+ proposal: string;
99
+ evidence: LinkEvidence;
100
+ };
101
+ /** An agent's merge still in place, newest first: what the owner sees to undo. */
102
+ export interface AgentMerge {
103
+ proposal: string;
104
+ bot: string;
105
+ run: string | null;
106
+ reason: string | null;
107
+ evidence: LinkEvidence | null;
35
108
  }
36
109
  export interface IdentityLinkInput {
37
110
  identity: IdentityRef;
@@ -5,3 +5,17 @@ export const IDENTITY_LINK_KIND = "identity_link";
5
5
  * an account the owner connected carries another name than the owner's (`account`).
6
6
  */
7
7
  export const IDENTITY_LINK_SIGNALS = ["agent", "phone", "email", "guest-email", "name", "account"];
8
+ /**
9
+ * Why a shared phone or address is not strong enough for an agent to merge on: an office's number, more people have
10
+ * it, a company's line or mailbox, a role or no-reply address, only one source gives it, or for a phone no source that
11
+ * keeps its user's own number (a CRM's or a card's is someone's word, NEED-2445).
12
+ */
13
+ export const LINK_WEAKNESSES = [
14
+ "landline",
15
+ "shared",
16
+ "company",
17
+ "role-address",
18
+ "no-reply",
19
+ "one-source",
20
+ "not-own-number",
21
+ ];
@@ -20,7 +20,7 @@ export type { CacheDatabase, CacheStatement, OpenDatabase, SqlValue } from "./dr
20
20
  export { PRAGMAS } from "./driver.js";
21
21
  export { type CitableRecord, EVIDENCE_FINDINGS_KIND, type EvidenceFindingsBatch, type EvidenceFindingsDecider, type EvidenceFindingsReceipt, type EvidenceFindingsStore, validateEvidenceFindings, } from "./evidence-findings.js";
22
22
  export { type DamagedTable, type InvalidJson, QUICK_HEALTH_CHECKS, type SearchIndexHealth, type StoreHealth, storeHealth, } from "./health.js";
23
- export { IDENTITY_LINK_KIND, IDENTITY_LINK_SIGNALS, type IdentityLinkDecision, type IdentityLinkFilter, type IdentityLinkInput, type IdentityLinkPayload, type IdentityLinkRow, type IdentityLinkSignal, type MatchScan, type SharedMailbox, } from "./identity-links.js";
23
+ export { type AgentLink, type AgentLinkInput, type AgentMerge, IDENTITY_LINK_KIND, IDENTITY_LINK_SIGNALS, type IdentityLinkDecision, type IdentityLinkFilter, type IdentityLinkInput, type IdentityLinkPayload, type IdentityLinkRow, type IdentityLinkSignal, LINK_WEAKNESSES, type LinkEvidence, type LinkFact, type LinkHold, type LinkWeakness, type MatchScan, type SharedMailbox, } from "./identity-links.js";
24
24
  export { IDENTITY_SPLIT_KIND, type IdentitySplitDecision, type IdentitySplitFilter, type IdentitySplitInput, type IdentitySplitMove, type IdentitySplitPayload, type IdentitySplitRow, } from "./identity-splits.js";
25
25
  export { ORGANIZATIONS_QUERY, organization, PROJECTS_QUERY, project, REMINDERS_QUERY, reminder, } from "./knowledge-query.js";
26
26
  export { MAIL_FINDINGS_KIND, type MailFindingsBatch, type MailFindingsCheck, type MailFindingsStore, } from "./mail-findings.js";
@@ -12,7 +12,7 @@ export { applyDocumentTransfer, previewDocumentTransfer } from "./document-trans
12
12
  export { PRAGMAS } from "./driver.js";
13
13
  export { EVIDENCE_FINDINGS_KIND, validateEvidenceFindings, } from "./evidence-findings.js";
14
14
  export { QUICK_HEALTH_CHECKS, storeHealth, } from "./health.js";
15
- export { IDENTITY_LINK_KIND, IDENTITY_LINK_SIGNALS, } from "./identity-links.js";
15
+ export { IDENTITY_LINK_KIND, IDENTITY_LINK_SIGNALS, LINK_WEAKNESSES, } from "./identity-links.js";
16
16
  export { IDENTITY_SPLIT_KIND, } from "./identity-splits.js";
17
17
  export { ORGANIZATIONS_QUERY, organization, PROJECTS_QUERY, project, REMINDERS_QUERY, reminder, } from "./knowledge-query.js";
18
18
  export { MAIL_FINDINGS_KIND, } from "./mail-findings.js";
@@ -2,7 +2,7 @@ import type { Contact, Id, Page, PersonAlias, Provider } from "../domain/models.
2
2
  import type { PersonKind } from "../domain/person-kinds.js";
3
3
  import type { PeopleLookup } from "../resolve.js";
4
4
  import type { Decider } from "./decisions.js";
5
- import type { IdentityLinkDecision, IdentityLinkFilter, IdentityLinkInput, IdentityLinkRow, MatchScan } from "./identity-links.js";
5
+ import type { AgentLink, AgentLinkInput, AgentMerge, IdentityLinkDecision, IdentityLinkFilter, IdentityLinkInput, IdentityLinkRow, LinkEvidence, MatchScan } from "./identity-links.js";
6
6
  import type { IdentitySplitDecision, IdentitySplitFilter, IdentitySplitInput, IdentitySplitRow } from "./identity-splits.js";
7
7
  import type { ContactFilter } from "./sqlite/identities.js";
8
8
  import { type IdentityRekey, type IdentityRekeys } from "./sqlite/identity-rekey.js";
@@ -100,6 +100,28 @@ export interface PeopleStore extends AccountPeople {
100
100
  * owner's separation or rejection; an open proposal for the same two people is given back instead of a second.
101
101
  */
102
102
  proposeLink(input: IdentityLinkInput): Promise<ProposedAction>;
103
+ /**
104
+ * An agent's link. It merges at once only on strong evidence the store finds itself, never on the agent's word:
105
+ * one value only these two people hold, a mobile number or a personal address, from two different sources, and for a
106
+ * phone at least one that keeps its user's own number (a messenger account or a call's number; NEED-2445, NEED-2600).
107
+ * A landline, a value more people share, a company's line, a role address, a name or a CRM's word alone is weak. The
108
+ * merge is recorded as an `identity_link` the agent decided, with the evidence, the reason and the run, and the owner
109
+ * undoes it with `undoMerge`. Weak evidence, the owner's person, a pair the owner rejected, or `apply: false` (the
110
+ * owner's setting) open a proposal instead, which says why. Refused over the owner's separation.
111
+ */
112
+ agentLink(input: AgentLinkInput): Promise<AgentLink>;
113
+ /** What two people share and whether it is strong, for each pair of `person:<uid>` or uids; reads the store once. */
114
+ linkEvidence(pairs: readonly (readonly [string, string])[]): Promise<LinkEvidence[]>;
115
+ /** The merges agents made that are still in place, newest first. */
116
+ agentMerges(page: {
117
+ limit: number;
118
+ offset: number;
119
+ }): Promise<{
120
+ items: (PersonMerge & {
121
+ agent: AgentMerge;
122
+ })[];
123
+ hasMore: boolean;
124
+ }>;
103
125
  /**
104
126
  * The owner's decision on an `identity_link`; confirm is refused with `identity.stale` when either person changed.
105
127
  * `company` turns down a shared-mailbox proposal and gives its address to an organization (NEED-2528);
@@ -1,6 +1,7 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { keysOver } from "./keys.js";
3
3
  import { ownerPerson } from "./sqlite/actors.js";
4
+ import { agentLink, agentMergeOf, agentMerges, linkEvidenceOver } from "./sqlite/agent-links.js";
4
5
  import * as identities from "./sqlite/identities.js";
5
6
  import * as identityProposals from "./sqlite/identity-proposals.js";
6
7
  import { rekeyIdentities } from "./sqlite/identity-rekey.js";
@@ -131,10 +132,20 @@ export const peopleStoreOver = (context, keyed) => {
131
132
  linkPhones(context, new Set(done.touched));
132
133
  return done;
133
134
  },
134
- merges: async (uid) => personMerges.merges(context, uid),
135
+ merges: async (uid) => personMerges.merges(context, uid).map((merge) => {
136
+ const agent = merge.method === "agent" ? agentMergeOf(context, merge.id) : undefined;
137
+ return agent === undefined ? merge : { ...merge, agent };
138
+ }),
135
139
  undoMerge: async (to, from, by) => write(database, () => personMerges.undoMerge(context, to, from, by)),
136
140
  split: async (uid, chosen, by) => write(database, () => personMerges.split(context, uid, chosen, by)),
137
141
  proposeLink: async (input) => identityProposals.proposeIdentityLink(context, input),
142
+ agentLink: async (input) => agentLink(context, input),
143
+ linkEvidence: async (pairs) => {
144
+ const evidence = linkEvidenceOver(context);
145
+ const uid = (person) => Number(person.replace(/^person:/, ""));
146
+ return pairs.map(([a, b]) => evidence(uid(a), uid(b)));
147
+ },
148
+ agentMerges: async (page) => agentMerges(context, page),
138
149
  decideLink: async (id, decision) => identityProposals.decideIdentityLink(context, id, decision),
139
150
  scanMatches: async (options) => scanMatches(context, options),
140
151
  linkProposals: async (filter) => identityProposals.identityLinkRows(context, filter),
@@ -0,0 +1,34 @@
1
+ import { type AgentLink, type AgentLinkInput, type AgentMerge, type LinkEvidence } from "../identity-links.js";
2
+ import type { StoreContext } from "./open.js";
3
+ /**
4
+ * Reads every phone and address once, then answers for any number of pairs of people: what they share, and whether it
5
+ * is strong enough for an agent to merge them.
6
+ */
7
+ export declare const linkEvidenceOver: (context: StoreContext) => ((a: number, b: number) => LinkEvidence);
8
+ /**
9
+ * An agent's link: merged at once on strong evidence the store finds itself, recorded as an `identity_link` decided by
10
+ * the agent, with the evidence, its reason and its run; otherwise it waits for the owner as a proposal, which says why
11
+ * it is not strong. Refused over the owner's separation, as any agent's link is.
12
+ */
13
+ export declare const agentLink: (context: StoreContext, input: AgentLinkInput) => AgentLink;
14
+ /** Who merged, why and in which run, for a merge an agent made; `undefined` for any other. */
15
+ export declare const agentMergeOf: (context: StoreContext, merge: string) => AgentMerge | undefined;
16
+ /** The merges agents made that are still in place, newest first: what the owner may want to undo. */
17
+ export declare const agentMerges: (context: StoreContext, { limit, offset }: {
18
+ limit: number;
19
+ offset: number;
20
+ }) => {
21
+ items: {
22
+ id: string;
23
+ from: string;
24
+ to: string;
25
+ identities: (import("../types.js").IdentityRef & {
26
+ name: string | null;
27
+ })[];
28
+ method: string;
29
+ by: string;
30
+ at: string;
31
+ agent: AgentMerge;
32
+ }[];
33
+ hasMore: boolean;
34
+ };