@wirecat/cli-core 0.635.0 → 0.636.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 (34) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/cli/bot/people.js +1 -1
  3. package/dist/cli/messenger/contacts-command.js +6 -2
  4. package/dist/domain/display-names.d.ts +16 -0
  5. package/dist/domain/display-names.js +16 -0
  6. package/dist/entities/contact-activity.d.ts +2 -0
  7. package/dist/entities/contact-activity.js +2 -0
  8. package/dist/entities/contact-context.d.ts +3 -0
  9. package/dist/entities/index.d.ts +3 -0
  10. package/dist/errors/reasons.js +4 -0
  11. package/dist/services/people.d.ts +5 -1
  12. package/dist/services/people.js +18 -5
  13. package/dist/services/stored-project-gathering.d.ts +2 -0
  14. package/dist/services/stored-project-gathering.js +1 -1
  15. package/dist/store/identity-links.d.ts +3 -1
  16. package/dist/store/index.d.ts +1 -1
  17. package/dist/store/people.d.ts +7 -1
  18. package/dist/store/people.js +10 -3
  19. package/dist/store/sqlite/identity-proposals.js +24 -6
  20. package/dist/store/sqlite/identity-split-proposals.d.ts +5 -0
  21. package/dist/store/sqlite/identity-split-proposals.js +26 -0
  22. package/dist/store/sqlite/manifest.js +1 -0
  23. package/dist/store/sqlite/migrations.generated.js +8 -0
  24. package/dist/store/sqlite/people-list.js +11 -9
  25. package/dist/store/sqlite/person-doubts.d.ts +11 -0
  26. package/dist/store/sqlite/person-doubts.js +47 -7
  27. package/dist/store/sqlite/person-links.js +8 -2
  28. package/dist/store/sqlite/person-match-scan.d.ts +14 -0
  29. package/dist/store/sqlite/person-match-scan.js +28 -2
  30. package/dist/store/sqlite/person-merges.d.ts +1 -0
  31. package/dist/store/sqlite/person-merges.js +1 -1
  32. package/dist/store/types.d.ts +2 -0
  33. package/package.json +3 -3
  34. package/parity.json +6 -3
package/CHANGELOG.md CHANGED
@@ -5,6 +5,52 @@ 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.636.0 — 11.11.2026
9
+
10
+ ### Added
11
+
12
+ - **"This is the company's mailbox" can close every pair on the address at once.** `people.decideLink` with
13
+ `company: { all: true }` turns down every open proposal on the same shared mailbox in one decision, gives the
14
+ address to the one organization, and lists the proposals it closed as `closed` in the decided proposal's result.
15
+ Without `all` it closes only the pair asked about, as before ([ARCHITECTURE.md](docs/dev/ARCHITECTURE.md)).
16
+
17
+ - **Every rule's people proposal has a score on one scale**, so `linkProposals({ order: "score" })` lists the
18
+ strongest first. 0.7: a phone two people alone have that does not join them (a CRM's or a card's), one name with a
19
+ phone or an address only they hold, or a rejected pair met on new evidence. 0.5: one name with a chat or a company
20
+ domain in one source, or a meeting guest's typed address. 0.4: each pair on a phone or a personal address three to
21
+ six people share. A shared mailbox stays 0.1 to 0.8. An agent's proposal keeps the agent's own score or none, and an
22
+ account under another name has none. The first people scan after the upgrade reads everything once and fills in the
23
+ score of open proposals made before; decided ones stay as they are ([ARCHITECTURE.md](docs/dev/ARCHITECTURE.md)).
24
+ - **The owner can say a person in doubt is right: `people.keep(person, "owner")`.** The identities in doubt stop being
25
+ listed by `people.doubts()` until one of them moves; an identity that joins later is in doubt again. It is recorded
26
+ as a split the owner turned down, so an agent's split of them is refused (`identity.kept-together`) and an open one
27
+ is turned down. An agent is refused with `identity.owner-only`, a person with nothing in doubt with
28
+ `person.no-doubt`, one in doubt only as test data with `person.test-data`, an unknown one with `person.unknown`. The
29
+ answer is `{ person: "person:<uid>", kept: ["<provider>:<id>", …] }`.
30
+ - **A person's record carries `displayName`**, the name `people.list` shows for them: their own, else the first readable
31
+ account name, a username, phone or address. `people.personOf()` and `people.personByUid()` return it.
32
+
33
+ ### Changed — may break callers
34
+
35
+ - **`contacts unlink` needs `--from`, the person the identity leaves.** `tg`, `max` and `wa contacts unlink <person>
36
+ --from person:<uid>|person:me` (and `services.people.unlink(person, { by, from })`) take the identity off that person
37
+ only. Without `--from` the command is refused with `validation_error`, reason `person.from-required`, and the message
38
+ names who holds the identity and the `--from` to run it again with. An identity on someone else is refused with
39
+ `identity.held-elsewhere`, as memo's `people unlink` is, and nothing moves.
40
+ - **`bot search messages --from` shows its value as `<person>`**, the placeholder cli-base 0.96.0's vocabulary gives
41
+ `--from`; it still takes an id, @username or part of a name, repeated for any of several.
42
+ - **`PeopleStore` has a new method, `keep`.** A store implemented outside cli-core must add it.
43
+
44
+ ### Fixed
45
+
46
+ - **`people.doubts()` no longer lists a person the owner linked by hand under mixed names.** A link moves
47
+ only the identities of the person who joins, so the ones already there kept a rule's method and came back as a doubt.
48
+ An identity on the person when the owner linked into it no longer counts as a different name; one that joins later
49
+ is still checked. A shared address and the owner's own person are checked as before.
50
+ - **Store version 66: a person with no name of their own has their kind and name order worked out again when an
51
+ account's name changes.** The migration also clears the stored kind of every person with no name of their own once.
52
+ Triggers only otherwise; `minCompatible` stays 56.
53
+
8
54
  ## 0.635.0 — 10.11.2026
9
55
 
10
56
  ### Added
@@ -198,7 +198,7 @@ export const botSearchCommand = (bot) => {
198
198
  .option("--limit <n>", "how many", positiveCount("--limit"))
199
199
  .option("--page <n>", "which page, starting at 1", positiveCount("--page"))
200
200
  .option("--newest", "newest first instead of best first")
201
- .option("--from <who>", "only what this person wrote — an id, @username or part of a name; repeat it for any of several", (value, previous = []) => [...previous, value])
201
+ .option("--from <person>", "only what this person wrote — an id, @username or part of a name; repeat it for any of several", (value, previous = []) => [...previous, value])
202
202
  .description("search the messages this bot has read, sent or received on this machine — the local copy only, best " +
203
203
  'match first; a Lucene query: every word must appear; "a phrase", -word, a OR b, from: chat: date: has:; ' +
204
204
  "by text, by --from, or both")
@@ -273,9 +273,13 @@ export const contactsCommand = (messenger) => {
273
273
  annotate(contacts.command("unlink"), { effects: LOCAL_WRITE, output: { entity: "linked_person" } })
274
274
  .description("undo contacts link for one identity: it is a person of its own again")
275
275
  .argument("<person>", "their id, @username, or part of their name; <messenger>:<person> for another messenger")
276
+ .option("--from <person>", "the person it leaves, person:<uid> or person:me; refused when it sits on another")
276
277
  .action(async function (person) {
277
278
  const context = messengerContext(this, messenger);
278
- renderAnswer(this, context, itemOf(snakeKeys(await context.withServices((services) => services.people.unlink(person, { by: actorOf(this) })))));
279
+ const { from } = this.opts();
280
+ const by = actorOf(this);
281
+ const unlinked = await context.withServices((services) => services.people.unlink(person, { by, from: from ?? "" }));
282
+ renderAnswer(this, context, itemOf(snakeKeys(unlinked)));
279
283
  });
280
284
  /**
281
285
  * ⚠ **The number is asked for or piped, never an argument**: argv is read by `ps` and kept by shell
@@ -329,7 +333,7 @@ export const contactsCommand = (messenger) => {
329
333
  sync: "",
330
334
  events: '"Alex Example" --limit 10',
331
335
  unblock: '"Alex Example"',
332
- unlink: '"Alex Example"',
336
+ unlink: '"Alex Example" --from person:me',
333
337
  };
334
338
  for (const [path, args] of Object.entries(examples)) {
335
339
  const command = commandAt(contacts, path);
@@ -12,6 +12,22 @@ export interface NameFallbacks {
12
12
  * the stored name stays as it came.
13
13
  */
14
14
  export declare const displayName: (name: string | null | undefined, fallbacks?: NameFallbacks) => string | null;
15
+ /** One identity of a person, as `takeFallbacks` reads it. */
16
+ export interface FallbackSource {
17
+ provider: string;
18
+ id: string;
19
+ name: string | null;
20
+ username: string | null;
21
+ phone?: string | null;
22
+ email?: string | null;
23
+ }
24
+ /**
25
+ * Fills what is still missing in `into` from one more identity, read in the order the identities were stored: the first
26
+ * readable name that is no handle, the first username, phone and address. `people list` and a person's record give
27
+ * the same shown name because both fill it here.
28
+ */
29
+ export declare const takeFallbacks: (into: Required<NameFallbacks>, identity: FallbackSource) => Required<NameFallbacks>;
30
+ export declare const noFallbacks: () => Required<NameFallbacks>;
15
31
  /**
16
32
  * The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
17
33
  * `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
@@ -43,6 +43,22 @@ export const displayName = (name, fallbacks = {}) => {
43
43
  given(fallbacks.email) ??
44
44
  (cleaned === "" ? null : cleaned));
45
45
  };
46
+ const present = (value) => typeof value === "string" && value !== "" ? value : null;
47
+ /**
48
+ * Fills what is still missing in `into` from one more identity, read in the order the identities were stored: the first
49
+ * readable name that is no handle, the first username, phone and address. `people list` and a person's record give
50
+ * the same shown name because both fill it here.
51
+ */
52
+ export const takeFallbacks = (into, identity) => {
53
+ const named = displayName(identity.name);
54
+ if (into.name === null && isReadable(named) && !named?.startsWith("@"))
55
+ into.name = named;
56
+ into.username ??= present(identity.username);
57
+ into.phone ??= present(identity.phone) ?? (identity.provider === "phone" ? identity.id : null);
58
+ into.email ??= present(identity.email) ?? (identity.provider === "email" ? identity.id : null);
59
+ return into;
60
+ };
61
+ export const noFallbacks = () => ({ name: null, username: null, phone: null, email: null });
46
62
  /**
47
63
  * The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
48
64
  * `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
@@ -2,6 +2,8 @@ import * as v from "valibot";
2
2
  export declare const linkedPerson: v.StrictObjectSchema<{
3
3
  readonly uid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
4
4
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
5
+ /** The name `people list` shows: the person's own, else an account's, a username, phone or address. */
6
+ readonly display_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
5
7
  readonly identities: v.ArraySchema<v.StrictObjectSchema<{
6
8
  readonly provider: v.StringSchema<undefined>;
7
9
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -18,6 +18,8 @@ const linkedIdentity = v.strictObject({
18
18
  export const linkedPerson = v.strictObject({
19
19
  uid: id,
20
20
  name: v.nullable(text),
21
+ /** The name `people list` shows: the person's own, else an account's, a username, phone or address. */
22
+ display_name: v.optional(v.nullable(text)),
21
23
  identities: v.array(linkedIdentity),
22
24
  /** An agent's link: the `identity_link` proposal the owner decides; the person is still as it was. */
23
25
  proposal: v.optional(text),
@@ -25,6 +25,7 @@ declare const context: v.StrictObjectSchema<{
25
25
  readonly person: v.StrictObjectSchema<{
26
26
  readonly uid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
27
27
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
28
+ readonly display_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
28
29
  readonly identities: v.ArraySchema<v.StrictObjectSchema<{
29
30
  readonly provider: v.StringSchema<undefined>;
30
31
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -817,6 +818,7 @@ export declare const contactContext: v.UnionSchema<[v.StrictObjectSchema<{
817
818
  readonly person: v.StrictObjectSchema<{
818
819
  readonly uid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
819
820
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
821
+ readonly display_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
820
822
  readonly identities: v.ArraySchema<v.StrictObjectSchema<{
821
823
  readonly provider: v.StringSchema<undefined>;
822
824
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -1620,6 +1622,7 @@ export declare const contactPreparation: v.StrictObjectSchema<{
1620
1622
  readonly person: v.StrictObjectSchema<{
1621
1623
  readonly uid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
1622
1624
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
1625
+ readonly display_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
1623
1626
  readonly identities: v.ArraySchema<v.StrictObjectSchema<{
1624
1627
  readonly provider: v.StringSchema<undefined>;
1625
1628
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -2710,6 +2710,7 @@ export declare const ENTITIES: {
2710
2710
  readonly person: v.StrictObjectSchema<{
2711
2711
  readonly uid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
2712
2712
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
2713
+ readonly display_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
2713
2714
  readonly identities: v.ArraySchema<v.StrictObjectSchema<{
2714
2715
  readonly provider: v.StringSchema<undefined>;
2715
2716
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -3498,6 +3499,7 @@ export declare const ENTITIES: {
3498
3499
  readonly person: v.StrictObjectSchema<{
3499
3500
  readonly uid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
3500
3501
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
3502
+ readonly display_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
3501
3503
  readonly identities: v.ArraySchema<v.StrictObjectSchema<{
3502
3504
  readonly provider: v.StringSchema<undefined>;
3503
3505
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -3800,6 +3802,7 @@ export declare const ENTITIES: {
3800
3802
  readonly linked_person: v.StrictObjectSchema<{
3801
3803
  readonly uid: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
3802
3804
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
3805
+ readonly display_name: v.OptionalSchema<v.NullableSchema<v.StringSchema<undefined>, undefined>, undefined>;
3803
3806
  readonly identities: v.ArraySchema<v.StrictObjectSchema<{
3804
3807
  readonly provider: v.StringSchema<undefined>;
3805
3808
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -376,6 +376,10 @@ const OTHERS = [
376
376
  validation("order.status", "a rejected or deleted order's status does not change"),
377
377
  ["model.not-downloaded", "not_found", "the model is not downloaded on this machine"],
378
378
  ["person.no-owner", "not_found", "no person is marked as the owner in the store"],
379
+ ["person.unknown", "not_found", "the store has no person by that reference; people list gives person:<uid>"],
380
+ ["person.no-doubt", "not_found", "nothing about that person is in doubt; people links check lists who is"],
381
+ validation("person.test-data", "the person is in doubt only as test data, which is not kept; remove the test data"),
382
+ validation("person.from-required", "say whom the identity leaves: --from person:<uid>, or person:me for the owner"),
379
383
  [
380
384
  "identity.separated",
381
385
  "conflict",
@@ -74,9 +74,13 @@ export interface PeopleService {
74
74
  }): Promise<PersonMessages>;
75
75
  /** `other` may name another messenger of the store: `max:Ana`. */
76
76
  link(person: string, other: string, options: LinkPeopleOptions): Promise<LinkedPeople>;
77
- /** The owner's alone: an unlink separates two people, and nothing links them again on its own. */
77
+ /**
78
+ * The owner's alone: an unlink separates two people, and nothing links them again on its own. `from` names the person
79
+ * the identity leaves, `person:<uid>` or `person:me`; it is refused when the identity sits on someone else.
80
+ */
78
81
  unlink(person: string, options: {
79
82
  by: string;
83
+ from: string;
80
84
  }): Promise<PersonRecord>;
81
85
  /**
82
86
  * Only counts and the people recognised: never a number. `IMPORT_CHUNK` numbers a request, each request
@@ -1,5 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { queryError } from "@wirecat/cli-base/query";
3
+ import { displayName } from "../domain/display-names.js";
3
4
  import { isCliFailure } from "../errors/failures.js";
4
5
  import { capability } from "../ports/messenger.js";
5
6
  import { pickPerson } from "../resolve.js";
@@ -11,6 +12,7 @@ import { CHAT_MESSAGES, identityIn, personContext, personMessages, } from "./per
11
12
  import { personPreparation } from "./person-preparation.js";
12
13
  import { personProfile } from "./person-profile.js";
13
14
  import { personTimeline } from "./person-timeline.js";
15
+ import { withOwner } from "./stored-project-gathering.js";
14
16
  export const peopleService = (deps) => {
15
17
  const localCard = async (card, includeNotes = false) => {
16
18
  const held = await storeIfOpen(deps);
@@ -110,16 +112,21 @@ export const peopleService = (deps) => {
110
112
  });
111
113
  },
112
114
  link: async (person, other, options) => linkPeople(await deps.store(), await deps.account(), person, other, options),
113
- unlink: async (person, { by }) => {
115
+ unlink: async (person, { by, from }) => {
114
116
  if (by !== "owner")
115
117
  throw new CliError("permission_error", "only the owner unlinks an identity; the owner runs this", {
116
118
  reason: "identity.owner-only",
117
119
  });
118
120
  const store = await deps.store();
119
- return store.people.unlinkIdentity(await identityIn(store, await deps.account(), person), {
120
- method: "manual",
121
- by: "owner",
122
- });
121
+ const identity = await identityIn(store, await deps.account(), person);
122
+ if (from.trim() === "") {
123
+ const holder = await store.people.personOf(identity);
124
+ if (holder !== undefined && holder.identities.length > 1)
125
+ throw fromRequired(identity, holder);
126
+ return store.people.unlinkIdentity(identity, { method: "manual", by: "owner" });
127
+ }
128
+ const uid = await withOwner(store, from);
129
+ return store.people.unlinkIdentity(identity, { method: "manual", by: "owner", from: uid });
123
130
  },
124
131
  lookup: async (phone) => capability(await deps.connection(), "lookup", "find a person by phone")(phone),
125
132
  sync: async () => {
@@ -192,6 +199,12 @@ export const peopleService = (deps) => {
192
199
  };
193
200
  /** Numbers per request: one big list in one request is what a contact-scraping account sends. */
194
201
  const IMPORT_CHUNK = 10;
202
+ /** Never guessed from the identity: a guess takes it off whoever holds it, who may not be the person meant. */
203
+ const fromRequired = (identity, holder) => {
204
+ const name = displayName(holder.name, { name: holder.identities.find((one) => one.name)?.name ?? null });
205
+ return new CliError("validation_error", `say whom it leaves with --from: ${identity.provider}:${identity.id} sits on ${name ?? "a person with no name"} ` +
206
+ `(person:${holder.uid}); run it again with --from person:${holder.uid}, or --from person:me for you`, { reason: "person.from-required", param: "from", reference: `person:${holder.uid}` });
207
+ };
195
208
  /**
196
209
  * Links two people, each read in the account's messenger unless prefixed (`max:Ana`, `email:ana@x.com`, `person:12`);
197
210
  * `me` links the first to the owner. The owner's link is made at once; an agent's opens an `identity_link` proposal
@@ -54,6 +54,8 @@ export type ChatCounter = (account: AccountKey, chatId: string, window: {
54
54
  export declare const storedChatCount: (store: MessageStore) => ChatCounter;
55
55
  /** `project:<id>`, or the one project a key, name or alias names; several or none is refused, never guessed. */
56
56
  export declare const canonicalProjectRef: (store: MessageStore, reference: string) => Promise<string>;
57
+ /** `person:me` as the owner's `person:<uid>`; any other reference as written. */
58
+ export declare const withOwner: (store: MessageStore, reference: string) => Promise<string>;
57
59
  export interface ProjectMember {
58
60
  person: string;
59
61
  state: "read" | "member-limit" | "no-identity";
@@ -58,7 +58,7 @@ const projectOf = async (store, reference) => {
58
58
  return { ref, name: entry.name, key: entry.key, aliases: entry.aliases.map((alias) => alias.name) };
59
59
  };
60
60
  /** `person:me` as the owner's `person:<uid>`; any other reference as written. */
61
- const withOwner = async (store, reference) => {
61
+ export const withOwner = async (store, reference) => {
62
62
  if (reference.trim() !== "person:me")
63
63
  return reference;
64
64
  const owner = await store.people.owner();
@@ -50,11 +50,13 @@ export interface IdentityLinkDecision {
50
50
  /**
51
51
  * With `confirm: false` on a shared-mailbox proposal: the address is this organization's, not one of the two people.
52
52
  * `organization` names one; otherwise the one holding the address or its company domain, or one of `name`, or a new
53
- * company named `name` or the domain.
53
+ * company named `name` or the domain. `all` closes every open proposal on the same mailbox in this one decision;
54
+ * the decided proposal's result lists them all as `closed`.
54
55
  */
55
56
  company?: {
56
57
  organization?: number;
57
58
  name?: string;
59
+ all?: boolean;
58
60
  };
59
61
  }
60
62
  /** One `identity_link`, naming the people as they are now, not as they were when it was proposed. */
@@ -80,7 +80,7 @@ export type { Order, OrderDetail, OrderFilter, OrderInput, OrdersStore } from ".
80
80
  export type { OrganizationFilter } from "./sqlite/organization-categories.js";
81
81
  export { DEFAULT_OWNER_LANGUAGES, ownerLanguages } from "./sqlite/owner-languages.js";
82
82
  export { type ListedPerson, PEOPLE_SORTS, type PeopleList, type PeopleListOptions, type PeopleSort, type SimilarPerson, } from "./sqlite/people-list.js";
83
- export { DOUBT_REASONS, type DoubtIdentity, type DoubtMove, type DoubtReason, type PersonDoubt, type PersonDoubts, } from "./sqlite/person-doubts.js";
83
+ export { DOUBT_REASONS, type DoubtIdentity, type DoubtMove, type DoubtReason, type KeptPerson, type PersonDoubt, type PersonDoubts, } from "./sqlite/person-doubts.js";
84
84
  export { mergeId, type PersonMerge, parseMergeId } from "./sqlite/person-merges.js";
85
85
  export { ALWAYS_SHOWN, PERSON_TIES, type PersonTie, type ShownBecause, SMALL_GROUP_MEMBERS, } from "./sqlite/person-ties.js";
86
86
  export type { PrivateContact, PrivateContactNote } from "./sqlite/private-people.js";
@@ -1,12 +1,13 @@
1
1
  import type { Contact, Id, Page, PersonAlias, Provider } from "../domain/models.js";
2
2
  import type { PersonKind } from "../domain/person-kinds.js";
3
3
  import type { PeopleLookup } from "../resolve.js";
4
+ import type { Decider } from "./decisions.js";
4
5
  import type { IdentityLinkDecision, IdentityLinkFilter, IdentityLinkInput, IdentityLinkRow, MatchScan } from "./identity-links.js";
5
6
  import type { IdentitySplitDecision, IdentitySplitFilter, IdentitySplitInput, IdentitySplitRow } from "./identity-splits.js";
6
7
  import type { ContactFilter } from "./sqlite/identities.js";
7
8
  import type { StoreContext } from "./sqlite/open.js";
8
9
  import { type PeopleList, type PeopleListOptions, type SimilarPerson } from "./sqlite/people-list.js";
9
- import { type PersonDoubts } from "./sqlite/person-doubts.js";
10
+ import { type KeptPerson, type PersonDoubts } from "./sqlite/person-doubts.js";
10
11
  import type { PersonMerge } from "./sqlite/person-merges.js";
11
12
  import { type PersonPreparationRead } from "./sqlite/person-preparation.js";
12
13
  import { type ShownBecause } from "./sqlite/person-ties.js";
@@ -127,6 +128,11 @@ export interface PeopleStore extends AccountPeople {
127
128
  limit: number;
128
129
  offset: number;
129
130
  }): Promise<PersonDoubts>;
131
+ /**
132
+ * The owner says a person in doubt is right as they are: the identities in doubt stop being listed until one of them
133
+ * moves. The owner's alone; refused with `person.no-doubt` when nothing about the person is in doubt.
134
+ */
135
+ keep(person: string, by: Decider): Promise<KeptPerson>;
130
136
  /** The identity, and everyone linked with it, is the owner. */
131
137
  linkToOwner(identity: IdentityRef): Promise<PersonRecord>;
132
138
  /** A person known by name only, with no identity yet: someone to assign a task to before any message names them. */
@@ -6,9 +6,9 @@ import * as identityProposals from "./sqlite/identity-proposals.js";
6
6
  import * as identitySplits from "./sqlite/identity-split-proposals.js";
7
7
  import { linkToOwner } from "./sqlite/own-identities.js";
8
8
  import { countPeople, listPeople, similarPeople, } from "./sqlite/people-list.js";
9
- import { personDoubts } from "./sqlite/person-doubts.js";
9
+ import { keepPerson, personDoubts } from "./sqlite/person-doubts.js";
10
10
  import * as personLinks from "./sqlite/person-links.js";
11
- import { RULE, scanMatches } from "./sqlite/person-match-scan.js";
11
+ import { PROPOSAL_SCORE, RULE, scanMatches } from "./sqlite/person-match-scan.js";
12
12
  import * as personMerges from "./sqlite/person-merges.js";
13
13
  import { personPreparation } from "./sqlite/person-preparation.js";
14
14
  import { personSeenInAccounts } from "./sqlite/person-scope.js";
@@ -32,7 +32,13 @@ export const accountPeopleOver = (context) => {
32
32
  continue;
33
33
  const held = personLinks.joinByAddress(context, { provider: key.provider, id: person.id }, person.email, key.provider);
34
34
  if (held)
35
- identityProposals.openIdentityLink(context, { ...held, joins: "person", signal: "email", by: RULE });
35
+ identityProposals.openIdentityLink(context, {
36
+ ...held,
37
+ joins: "person",
38
+ signal: "email",
39
+ by: RULE,
40
+ score: PROPOSAL_SCORE.newEvidence,
41
+ });
36
42
  }
37
43
  return saved;
38
44
  };
@@ -129,6 +135,7 @@ export const peopleStoreOver = (context, keyed) => {
129
135
  decideSplit: async (id, decision) => identitySplits.decideIdentitySplit(context, id, decision),
130
136
  splitProposals: async (filter) => identitySplits.identitySplitRows(context, filter),
131
137
  doubts: async (page) => personDoubts(context, page),
138
+ keep: async (person, by) => write(database, () => keepPerson(context, person, by)),
132
139
  linkToOwner: async (identity) => linkToOwner(context, identity),
133
140
  list: async (options) => listPeople(database, options),
134
141
  counts: async (query) => countPeople(database, query),
@@ -42,8 +42,17 @@ export const openIdentityLink = (context, opening, index) => write(context.datab
42
42
  const operations = proposalOperationsOver(context);
43
43
  const links = index ?? linkIndex(context.database);
44
44
  const open = links.open(from, to);
45
- if (open)
45
+ if (open) {
46
+ // NEED-2529: a rule's proposal from before scores were recorded takes its score when the scan meets it again.
47
+ if (open.payload.score === null && opening.score !== undefined && open.payload.signal === opening.signal) {
48
+ context.database
49
+ .prepare("UPDATE proposed_actions SET payload = json_set(payload, '$.score', ?), updated_at = ? " +
50
+ "WHERE id = ? AND status = 'proposed'")
51
+ .run(opening.score, context.now(), Number(open.id));
52
+ open.payload.score = opening.score;
53
+ }
46
54
  return { outcome: "open", action: operations.get(open.id) };
55
+ }
47
56
  const identity = refOf(context, opening.identity);
48
57
  const other = opening.with === null ? null : refOf(context, opening.with);
49
58
  if (links.rejected(from, to)?.has(evidenceKeyOf({ signal: opening.signal, identity, with: other })))
@@ -188,11 +197,20 @@ const toCompany = (context, proposal, company, author, noted) => {
188
197
  reason: "organization.ambiguous",
189
198
  });
190
199
  }
191
- const rejected = proposalOperationsOver(context).reject(proposal.id, author, {
192
- dismissed: true,
193
- organization: `organization:${organization}`,
194
- ...noted,
195
- });
200
+ const operations = proposalOperationsOver(context);
201
+ const others = company.all
202
+ ? context.database
203
+ .prepare("SELECT id FROM proposed_actions WHERE kind = ? AND status = 'proposed' AND id <> ? " +
204
+ "AND json_extract(payload, '$.mailbox') = ? ORDER BY id")
205
+ .all(IDENTITY_LINK_KIND, Number(proposal.id), address)
206
+ .map((row) => String(row.id))
207
+ : [];
208
+ const result = { dismissed: true, organization: `organization:${organization}`, ...noted };
209
+ for (const other of others) {
210
+ const closed = operations.reject(other, author, { ...result, with: proposal.id });
211
+ settleMentions(context, closed.payload, "found");
212
+ }
213
+ const rejected = operations.reject(proposal.id, author, { ...result, closed: [proposal.id, ...others] });
196
214
  settleMentions(context, payload, "found");
197
215
  return rejected;
198
216
  };
@@ -7,6 +7,11 @@ import { type ProposedAction } from "./proposed-actions.js";
7
7
  * `people doubts` leaves them out. One that moved since counts no longer.
8
8
  */
9
9
  export declare const keptTogether: (database: CacheDatabase) => Map<number, Set<string>>;
10
+ /**
11
+ * The owner says these identities belong on this person: recorded as a split the owner turned down, which is what
12
+ * `keptTogether` reads, so it lapses as soon as one of them moves. An agent's open split of any of them is turned down.
13
+ */
14
+ export declare const keepTogether: (context: StoreContext, person: number, identities: readonly string[]) => ProposedAction;
10
15
  /**
11
16
  * Proposes to take identities off their person, or to undo a merge, as an `identity_split` only the owner decides. An
12
17
  * open proposal for the same identities is given back instead of a second, brought up to date with the person as it
@@ -75,6 +75,32 @@ export const keptTogether = (database) => {
75
75
  }
76
76
  return kept;
77
77
  };
78
+ /**
79
+ * The owner says these identities belong on this person: recorded as a split the owner turned down, which is what
80
+ * `keptTogether` reads, so it lapses as soon as one of them moves. An agent's open split of any of them is turned down.
81
+ */
82
+ export const keepTogether = (context, person, identities) => {
83
+ const operations = proposalOperationsOver(context);
84
+ const payload = {
85
+ split: "unlink",
86
+ person: String(person),
87
+ identities: [...identities],
88
+ merge: null,
89
+ side: sideOf(context.database, person),
90
+ evidence: [],
91
+ };
92
+ const keeping = new Set(identities);
93
+ for (const row of splitRows(context.database, ["proposed"]))
94
+ if (holder(context.database, row.payload) === person && row.payload.identities.some((ref) => keeping.has(ref)))
95
+ operations.reject(row.id, "owner", { reason: "the owner kept them" });
96
+ const proposed = operations.propose({
97
+ kind: IDENTITY_SPLIT_KIND,
98
+ by: "owner",
99
+ payload,
100
+ reason: "the owner kept them",
101
+ });
102
+ return operations.reject(proposed.id, "owner", { reason: "the owner kept them" });
103
+ };
78
104
  /**
79
105
  * Proposes to take identities off their person, or to undo a merge, as an `identity_split` only the owner decides. An
80
106
  * open proposal for the same identities is given back instead of a second, brought up to date with the person as it
@@ -130,6 +130,7 @@ export const MANIFEST = [
130
130
  { name: "20261110020704_version-63-people-ties-messages-crm", version: 63, minCompatible: 56 },
131
131
  { name: "20261110084658_version-64-deal-link-triggers", version: 64, minCompatible: 56 },
132
132
  { name: "20261110182602_version-65-found-task-titles", version: 65, minCompatible: 56 },
133
+ { name: "20261110233711_version-66-identity-name-trigger", version: 66, minCompatible: 56 },
133
134
  ];
134
135
  export const generatedMigrations = (manifest = MANIFEST, generated = GENERATED) => {
135
136
  const migrations = [];
@@ -1327,5 +1327,13 @@ export const GENERATED = [
1327
1327
  "statements": [
1328
1328
  "-- A found task's title was its message's first line only while reading, so it went blank when the message was deleted.\n-- The line comes from displayTitleOf in code, so the next writable open stores it for the tasks still titled\n-- `<kind> — <source>` and deletes this key (fillFoundTaskTitles). A store with no such task gets no key.\nINSERT OR REPLACE INTO store_settings (key, value, at)\nSELECT 'found_task_titles_to_fill', '1', unixepoch() * 1000 WHERE EXISTS (\n SELECT 1 FROM tasks WHERE package_id IS NOT NULL AND deleted_at IS NULL AND source_locator LIKE 'msg:%'\n AND title = type || ' — ' || source_locator\n);"
1329
1329
  ]
1330
+ },
1331
+ {
1332
+ "name": "20261110233711_version-66-identity-name-trigger",
1333
+ "statements": [
1334
+ "DROP TRIGGER IF EXISTS person_kind_identity_au;",
1335
+ "CREATE TRIGGER person_kind_identity_au AFTER UPDATE OF provider, external_id, name, username, phone, email, bot ON identities\nWHEN OLD.provider IS NOT NEW.provider OR OLD.external_id IS NOT NEW.external_id OR OLD.name IS NOT NEW.name OR OLD.username IS NOT NEW.username OR OLD.phone IS NOT NEW.phone OR OLD.email IS NOT NEW.email OR OLD.bot IS NOT NEW.bot BEGIN\n UPDATE persons SET kind = NULL WHERE kind IS NOT NULL AND id IN (SELECT person_id FROM identity_links WHERE identity_id = NEW.id);\nEND;",
1336
+ "UPDATE persons SET kind = NULL WHERE kind IS NOT NULL AND trim(coalesce(name, '')) = '';"
1337
+ ]
1330
1338
  }
1331
1339
  ];
@@ -1,6 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { isNoReplyAddress, isRoleAddress } from "../../domain/addresses.js";
3
- import { displayName, isReadable, nameKey } from "../../domain/display-names.js";
3
+ import { displayName, isReadable, nameKey, takeFallbacks } from "../../domain/display-names.js";
4
4
  import { spellings, variantKey } from "../../domain/name-variants.js";
5
5
  import { isAutomatedName, isCompanyName, PERSON_KINDS, } from "../../domain/person-kinds.js";
6
6
  import { isQueryOnly } from "../driver.js";
@@ -78,15 +78,17 @@ const factsOf = (database, scope) => {
78
78
  organization: false,
79
79
  };
80
80
  const email = text(row.email) ?? (row.provider === "email" ? text(row.external_id) : null);
81
- const named = displayName(text(row.name));
82
- if (one.name === null && isReadable(named) && !named?.startsWith("@"))
83
- one.name = named;
84
- if (one.username === null && text(row.username) !== null) {
85
- one.username = text(row.username);
81
+ const hadUsername = one.username !== null;
82
+ takeFallbacks(one, {
83
+ provider: String(row.provider),
84
+ id: String(row.external_id),
85
+ name: text(row.name),
86
+ username: text(row.username),
87
+ phone: text(row.phone),
88
+ email: text(row.email),
89
+ });
90
+ if (!hadUsername && one.username !== null)
86
91
  one.usernameSource = String(row.provider);
87
- }
88
- one.phone ??= text(row.phone) ?? (row.provider === "phone" ? text(row.external_id) : null);
89
- one.email ??= email;
90
92
  if (email !== null)
91
93
  one.emails.push(email);
92
94
  one.bot ||= Number(row.bot) === 1;
@@ -1,3 +1,4 @@
1
+ import type { Decider } from "../decisions.js";
1
2
  import type { StoreContext } from "./open.js";
2
3
  /** Why a person may be wrong, most urgent first: the owner's own person holding someone else matters most. */
3
4
  export declare const DOUBT_REASONS: readonly ["owner-other-name", "test-data", "shared-address", "mixed-names"];
@@ -47,3 +48,13 @@ export declare const personDoubts: (context: StoreContext, { limit, offset }: {
47
48
  limit: number;
48
49
  offset: number;
49
50
  }) => PersonDoubts;
51
+ export interface KeptPerson {
52
+ person: string;
53
+ /** The identities the owner said belong here; a doubt about them comes back once one of them moves. */
54
+ kept: string[];
55
+ }
56
+ /**
57
+ * The owner's answer to a doubt: this person is right as they are. Test data is not a link and stays listed. Refused
58
+ * when nothing about the person is in doubt.
59
+ */
60
+ export declare const keepPerson: (context: StoreContext, uid: string, by: Decider) => KeptPerson;
@@ -2,8 +2,9 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { displayName } from "../../domain/display-names.js";
3
3
  import { nameSkeletons } from "../../domain/name-variants.js";
4
4
  import { RESERVED_ADDRESS_GLOBS, SEED_ID_GLOBS, SEED_PEOPLE } from "../../domain/test-data.js";
5
- import { keptTogether } from "./identity-split-proposals.js";
6
- import { merges } from "./person-merges.js";
5
+ import { keepTogether, keptTogether } from "./identity-split-proposals.js";
6
+ import { currentPerson } from "./merged-persons.js";
7
+ import { merges, ownerOnly } from "./person-merges.js";
7
8
  /** Why a person may be wrong, most urgent first: the owner's own person holding someone else matters most. */
8
9
  export const DOUBT_REASONS = ["owner-other-name", "test-data", "shared-address", "mixed-names"];
9
10
  const COLUMNS = "l.person_id AS person, p.owner, p.name AS person_name, i.id AS pk, i.provider, i.external_id, i.name, i.phone, " +
@@ -121,7 +122,7 @@ const doubtsOf = (held, kept, test) => {
121
122
  .filter(({ by, ref }) => by !== "owner" && !kept.has(ref));
122
123
  const base = { person: first.person, owner: first.owner, name: first.personName };
123
124
  if (first.owner)
124
- return outside.length ? [{ ...base, reason: "owner-other-name", held: outside }] : [];
125
+ return outside.length ? [{ ...base, reason: "owner-other-name", held: outside, doubted: outside }] : [];
125
126
  const found = [];
126
127
  const mixed = [];
127
128
  for (const one of outside) {
@@ -129,12 +130,16 @@ const doubtsOf = (held, kept, test) => {
129
130
  continue;
130
131
  const address = one.email === null ? undefined : main.find(({ email }) => email === one.email)?.email;
131
132
  if (typeof address === "string")
132
- found.push({ ...base, reason: "shared-address", held: [one], address });
133
+ found.push({ ...base, reason: "shared-address", held: [one], address, doubted: [one] });
133
134
  else
134
135
  mixed.push(one);
135
136
  }
136
- if (mixed.length)
137
- found.push({ ...base, reason: "mixed-names", held: [...main, ...mixed] });
137
+ // A link only moves the identities of the person joining, so the ones already here keep a rule's method, though the
138
+ // owner saw their names beside the new one. A shared address is not something a name shows, so it stays.
139
+ const vouched = held.reduce((newest, { by, at }) => (by === "owner" && at > newest ? at : newest), -Infinity);
140
+ const unseen = mixed.filter(({ at }) => at > vouched);
141
+ if (unseen.length)
142
+ found.push({ ...base, reason: "mixed-names", held: [...main, ...unseen], doubted: unseen });
138
143
  return found;
139
144
  };
140
145
  const byPerson = (held) => {
@@ -160,7 +165,14 @@ const everyDoubt = (database) => {
160
165
  found.push(one);
161
166
  for (const held of byPerson(test).values()) {
162
167
  const [first] = held;
163
- found.push({ person: first.person, owner: first.owner, name: first.personName, reason: "test-data", held });
168
+ found.push({
169
+ person: first.person,
170
+ owner: first.owner,
171
+ name: first.personName,
172
+ reason: "test-data",
173
+ held,
174
+ doubted: [],
175
+ });
164
176
  }
165
177
  return found.sort((a, b) => Number(b.owner) - Number(a.owner) ||
166
178
  (ORDER.get(a.reason) ?? 0) - (ORDER.get(b.reason) ?? 0) ||
@@ -231,3 +243,31 @@ export const personDoubts = (context, { limit, offset }) => {
231
243
  hasMore: found.length > offset + limit,
232
244
  };
233
245
  };
246
+ /**
247
+ * The owner's answer to a doubt: this person is right as they are. Test data is not a link and stays listed. Refused
248
+ * when nothing about the person is in doubt.
249
+ */
250
+ export const keepPerson = (context, uid, by) => {
251
+ ownerOnly(by, "says a person's links are right");
252
+ const asked = /^(?:person:)?([1-9]\d*)$/u.exec(uid.trim())?.[1];
253
+ const known = asked === undefined || !Number.isSafeInteger(Number(asked))
254
+ ? undefined
255
+ : context.database.prepare("SELECT id FROM persons WHERE id = ?").get(Number(asked));
256
+ if (known === undefined)
257
+ throw new CliError("not_found", `the store has no person for "${uid}"`, { reason: "person.unknown" });
258
+ const person = currentPerson(context.database, Number(known.id));
259
+ const held = context.database.prepare(`SELECT ${COLUMNS} WHERE l.person_id = ? ORDER BY i.id`).all(person).map(heldOf);
260
+ const test = new Set(testData(context.database).map(({ pk }) => pk));
261
+ const doubted = [
262
+ ...new Set(doubtsOf(held, keptTogether(context.database).get(person) ?? new Set(), test).flatMap((found) => found.doubted.map(({ ref }) => ref))),
263
+ ];
264
+ if (doubted.length === 0) {
265
+ if (held.some(({ pk }) => test.has(pk)))
266
+ throw new CliError("validation_error", `person:${person} is in doubt only as test data, which is not kept`, {
267
+ reason: "person.test-data",
268
+ });
269
+ throw new CliError("not_found", `nothing about person:${person} is in doubt`, { reason: "person.no-doubt" });
270
+ }
271
+ keepTogether(context, person, doubted);
272
+ return { person: `person:${person}`, kept: doubted };
273
+ };
@@ -1,6 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { isEmailAddress, isRoleAddress } from "../../domain/addresses.js";
3
- import { displayName } from "../../domain/display-names.js";
3
+ import { displayName, noFallbacks, takeFallbacks } from "../../domain/display-names.js";
4
4
  import { and, eq, inArray, isNull, sql } from "./drizzle/core.js";
5
5
  import { identityOf } from "./identities.js";
6
6
  import { rejectedEvidence, settleLinks } from "./identity-link-rows.js";
@@ -62,7 +62,13 @@ export const recordOf = ({ orm }, personPk) => {
62
62
  linkedAt: new Date(linkedAt).toISOString(),
63
63
  };
64
64
  });
65
- return { uid: String(person.id), name: person.name, identities: identitiesOf };
65
+ const fallbacks = [...rows].sort((a, b) => a.pk - b.pk).reduce(takeFallbacks, noFallbacks());
66
+ return {
67
+ uid: String(person.id),
68
+ name: person.name,
69
+ displayName: displayName(person.name, fallbacks),
70
+ identities: identitiesOf,
71
+ };
66
72
  };
67
73
  /**
68
74
  * A person by the uid a `person:` reference holds, with every identity linked to them. A uid merged into someone
@@ -2,6 +2,20 @@ import type { MatchScan } from "../identity-links.js";
2
2
  import type { Author } from "./memories.js";
3
3
  import type { StoreContext } from "./open.js";
4
4
  export declare const RULE: Author;
5
+ /**
6
+ * NEED-2529: every rule's proposal on the scale of `SHARED_SCORE`, so the review lists the strongest first. A phone two
7
+ * people alone have but that does not join (a CRM's or a card's), one name with a phone or an address only these two
8
+ * hold, and a pair the owner rejected that meets new evidence of that kind are 0.7; one name with a chat or a company
9
+ * domain in one source, and a meeting guest's typed address, 0.5; a phone or personal address 3–6 people share, 0.4.
10
+ */
11
+ export declare const PROPOSAL_SCORE: {
12
+ ownPhone: number;
13
+ nameAndOwnTrace: number;
14
+ newEvidence: number;
15
+ nameAndPlace: number;
16
+ guestEmail: number;
17
+ group: number;
18
+ };
5
19
  /**
6
20
  * One pass of the people matcher. It reads what may match outside any transaction and takes the write lock only for
7
21
  * each group it changes, so other writers are never kept waiting for the whole pass. After the first pass, only the
@@ -17,12 +17,26 @@ export const RULE = { bot: "rule", kind: "rule" };
17
17
  const MOST_SHARING = 6;
18
18
  const CURSOR = "people.scan";
19
19
  /** Raised when a rule changes what a pass finds in values nobody touched: the next pass then reads everything once. */
20
- const RULES = 2;
20
+ const RULES = 3;
21
21
  /**
22
22
  * NEED-2526: a shared mailbox says little alone, so its proposal is scored by what else the two people have in common.
23
23
  * The role word itself does not move the score: the list does not tell a department's inbox from a company's.
24
24
  */
25
25
  const SHARED_SCORE = { alone: 0.1, name: 0.4, trace: 0.3, weakTrace: 0.2 };
26
+ /**
27
+ * NEED-2529: every rule's proposal on the scale of `SHARED_SCORE`, so the review lists the strongest first. A phone two
28
+ * people alone have but that does not join (a CRM's or a card's), one name with a phone or an address only these two
29
+ * hold, and a pair the owner rejected that meets new evidence of that kind are 0.7; one name with a chat or a company
30
+ * domain in one source, and a meeting guest's typed address, 0.5; a phone or personal address 3–6 people share, 0.4.
31
+ */
32
+ export const PROPOSAL_SCORE = {
33
+ ownPhone: 0.7,
34
+ nameAndOwnTrace: 0.7,
35
+ newEvidence: 0.7,
36
+ nameAndPlace: 0.5,
37
+ guestEmail: 0.5,
38
+ group: 0.4,
39
+ };
26
40
  /**
27
41
  * NEED-2445, safe option until the owner rules: a number two people share joins them only when a messenger, which
28
42
  * keeps its user's own number, holds it; a CRM's or a card's number is someone's word and waits as a proposal.
@@ -159,7 +173,15 @@ const join = (pass, sides, signal) => {
159
173
  if (touchesOwner(pass, from, into, method))
160
174
  return into;
161
175
  if (index.rejected(from, into) !== undefined) {
162
- propose(pass, { identity: sides.identity, with: sides.with, from, to: into, joins: "person", signal });
176
+ propose(pass, {
177
+ identity: sides.identity,
178
+ with: sides.with,
179
+ from,
180
+ to: into,
181
+ joins: "person",
182
+ signal,
183
+ score: PROPOSAL_SCORE.newEvidence,
184
+ });
163
185
  return into;
164
186
  }
165
187
  const kept = mergePerson(context, from, into, { method, by: BY });
@@ -192,6 +214,7 @@ const propose = (pass, opening) => {
192
214
  result.proposed.push({ id: opened.action.id, persons, signal: opening.signal, opened: opened.outcome === "proposed" });
193
215
  };
194
216
  const proposeEachPair = (pass, people, signal) => {
217
+ const score = people.size === 2 ? PROPOSAL_SCORE.ownPhone : PROPOSAL_SCORE.group;
195
218
  const persons = [...people.keys()].sort((a, b) => a - b);
196
219
  for (const [at, from] of persons.entries())
197
220
  for (const to of persons.slice(at + 1))
@@ -203,6 +226,7 @@ const proposeEachPair = (pass, people, signal) => {
203
226
  joins: "person",
204
227
  signal,
205
228
  candidates: persons,
229
+ score,
206
230
  });
207
231
  };
208
232
  const tooMany = (pass, people, reason, signal) => {
@@ -355,6 +379,7 @@ const sameName = (pass, people, name) => {
355
379
  to,
356
380
  joins: "person",
357
381
  signal: "name",
382
+ score: trace.value === undefined ? PROPOSAL_SCORE.nameAndPlace : PROPOSAL_SCORE.nameAndOwnTrace,
358
383
  evidence: trace.evidence,
359
384
  reason: trace.reason,
360
385
  });
@@ -378,6 +403,7 @@ const guestEmail = (pass, row) => {
378
403
  to: others[0],
379
404
  joins: "identity",
380
405
  signal: "guest-email",
406
+ score: PROPOSAL_SCORE.guestEmail,
381
407
  ...(meeting === undefined ? {} : { evidence: [meeting] }),
382
408
  });
383
409
  };
@@ -18,6 +18,7 @@ export declare const parseMergeId: (id: string) => {
18
18
  to: string;
19
19
  from: string;
20
20
  };
21
+ export declare const ownerOnly: (by: unknown, what: string) => void;
21
22
  /**
22
23
  * The people merged into this person, each with the identities from it that are still here. Grouped by person, not
23
24
  * by time: a merge stamps each identity on its own.
@@ -16,7 +16,7 @@ const personPk = ({ database }, uid) => {
16
16
  throw new CliError("not_found", `no person:${uid} in the store`);
17
17
  return Number(found.id);
18
18
  };
19
- const ownerOnly = (by, what) => {
19
+ export const ownerOnly = (by, what) => {
20
20
  if (by !== "owner")
21
21
  throw new CliError("permission_error", `only the owner ${what}`, { reason: "identity.owner-only" });
22
22
  };
@@ -73,6 +73,8 @@ export interface LinkedIdentity extends IdentityRef {
73
73
  export interface PersonRecord {
74
74
  uid: string;
75
75
  name: string | null;
76
+ /** The name to show, by the rule `people list` uses: the person's own, else an account's, a username, phone, email. */
77
+ displayName?: string | null;
76
78
  identities: LinkedIdentity[];
77
79
  /** Set when the uid asked for was merged away: the uid of the person its identities are now, the same as `uid`. */
78
80
  mergedInto?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.635.0",
3
+ "version": "0.636.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",
@@ -15,7 +15,7 @@
15
15
  "type": "module",
16
16
  "wirecat": {
17
17
  "store": {
18
- "speaks": 65,
18
+ "speaks": 66,
19
19
  "minCompatible": 56
20
20
  }
21
21
  },
@@ -278,7 +278,7 @@
278
278
  "@types/node": "^22.20.5",
279
279
  "@types/pngjs": "6.0.5",
280
280
  "@vitest/coverage-v8": "^5.0.5",
281
- "@wirecat/cli-base": "0.94.0",
281
+ "@wirecat/cli-base": "0.96.0",
282
282
  "@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
283
283
  "ajv": "8.17.1",
284
284
  "commander": "15.0.0",
package/parity.json CHANGED
@@ -442,8 +442,8 @@
442
442
  "note": "the shared `store export` takes `jsonl` or `markdown`, max's own takes `jsonl` or `md` (e4)"
443
443
  },
444
444
  "--from": {
445
- "value": "<who>",
446
- "meaning": "sender to match in `bot search messages`"
445
+ "value": "<person>",
446
+ "meaning": "a person: the one an identity leaves in `contacts unlink`, the sender in `bot search messages`"
447
447
  },
448
448
  "--from-dir": {
449
449
  "value": "<dir>",
@@ -2985,7 +2985,10 @@
2985
2985
  "in": "all"
2986
2986
  },
2987
2987
  "contacts unlink": {
2988
- "in": "all"
2988
+ "in": "all",
2989
+ "options": {
2990
+ "--from": "all"
2991
+ }
2989
2992
  },
2990
2993
  "conversations": {
2991
2994
  "in": "all"