@wirecat/cli-core 0.634.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 (66) hide show
  1. package/CHANGELOG.md +112 -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 +20 -2
  5. package/dist/domain/display-names.js +21 -2
  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 +9 -0
  11. package/dist/search/groups.d.ts +2 -0
  12. package/dist/search/groups.js +1 -0
  13. package/dist/services/account-groups.d.ts +30 -1
  14. package/dist/services/account-groups.js +27 -0
  15. package/dist/services/index.d.ts +1 -1
  16. package/dist/services/index.js +1 -1
  17. package/dist/services/metadata.d.ts +1 -1
  18. package/dist/services/people.d.ts +5 -1
  19. package/dist/services/people.js +18 -5
  20. package/dist/services/stored-project-gathering.d.ts +2 -0
  21. package/dist/services/stored-project-gathering.js +1 -1
  22. package/dist/store/accounts.d.ts +10 -1
  23. package/dist/store/accounts.js +3 -2
  24. package/dist/store/chats.d.ts +5 -0
  25. package/dist/store/chats.js +6 -0
  26. package/dist/store/exports.d.ts +1 -1
  27. package/dist/store/identity-links.d.ts +23 -0
  28. package/dist/store/identity-splits.d.ts +2 -0
  29. package/dist/store/index.d.ts +2 -2
  30. package/dist/store/keys.d.ts +1 -1
  31. package/dist/store/keys.js +1 -1
  32. package/dist/store/people.d.ts +17 -5
  33. package/dist/store/people.js +10 -3
  34. package/dist/store/sqlite/accounts.d.ts +12 -2
  35. package/dist/store/sqlite/accounts.js +42 -3
  36. package/dist/store/sqlite/address-organization.d.ts +18 -0
  37. package/dist/store/sqlite/address-organization.js +48 -0
  38. package/dist/store/sqlite/chats.d.ts +3 -1
  39. package/dist/store/sqlite/chats.js +8 -0
  40. package/dist/store/sqlite/identity-link-rows.d.ts +5 -1
  41. package/dist/store/sqlite/identity-link-rows.js +9 -3
  42. package/dist/store/sqlite/identity-proposals.d.ts +5 -3
  43. package/dist/store/sqlite/identity-proposals.js +85 -8
  44. package/dist/store/sqlite/identity-split-proposals.d.ts +5 -0
  45. package/dist/store/sqlite/identity-split-proposals.js +29 -1
  46. package/dist/store/sqlite/mail-findings.js +10 -44
  47. package/dist/store/sqlite/manifest.js +2 -0
  48. package/dist/store/sqlite/migrations.generated.js +14 -0
  49. package/dist/store/sqlite/name-traces.d.ts +5 -2
  50. package/dist/store/sqlite/name-traces.js +8 -5
  51. package/dist/store/sqlite/open-store.js +2 -0
  52. package/dist/store/sqlite/people-list.js +15 -9
  53. package/dist/store/sqlite/person-doubts.d.ts +15 -1
  54. package/dist/store/sqlite/person-doubts.js +51 -9
  55. package/dist/store/sqlite/person-links.d.ts +7 -2
  56. package/dist/store/sqlite/person-links.js +33 -2
  57. package/dist/store/sqlite/person-match-scan.d.ts +14 -0
  58. package/dist/store/sqlite/person-match-scan.js +101 -5
  59. package/dist/store/sqlite/person-merges.d.ts +1 -0
  60. package/dist/store/sqlite/person-merges.js +4 -8
  61. package/dist/store/sqlite/task-titles.d.ts +12 -1
  62. package/dist/store/sqlite/task-titles.js +42 -1
  63. package/dist/store/sqlite/tasks.js +6 -1
  64. package/dist/store/types.d.ts +6 -0
  65. package/package.json +3 -3
  66. package/parity.json +6 -3
package/CHANGELOG.md CHANGED
@@ -5,6 +5,118 @@ 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
+
54
+ ## 0.635.0 — 10.11.2026
55
+
56
+ ### Added
57
+
58
+ - **The owner sets an account's scope, personal or work, and pins or clears a chat's.** `setAccountScope` and
59
+ `setChatScope` (from `/services`) take an account as `--source` names it (`bitrix24:acme.bitrix24.ru`, `tg:work`),
60
+ refuse a run locked to a group, and are for an owner-only command (`grantsAuthority`). An account's change moves
61
+ what search copied of its old scope: its conversation pieces and involvements, its other search pieces, and the word
62
+ indexes of its documents, mail and calendar events, which are built again on the next search. A chat with its own
63
+ scope keeps it; memories and facts keep the scope they were written with. A chat's change is recorded in its
64
+ history as the owner's. The store methods are `accounts.setScope` and `chats.setChatScope`.
65
+ - **A CLI chooses the scope its new accounts start as.** `accounts.saveAccount(key, { name, scope: "work" })` makes a
66
+ new account work; an account already stored keeps its scope, so a sync never undoes the owner's choice. A `scope`
67
+ in the `AccountKey` itself still overwrites the stored one on every save.
68
+ - **Each member of an account group carries its account's `scope`**, so a groups view shows and switches it in place.
69
+ - **The owner can answer a shared-mailbox proposal with "this is the company's mailbox".** `people.decideLink` with
70
+ `company` (`{}`, `{ organization }` or `{ name }`) gives the address to an organization: the one named, else the one
71
+ that holds the address or its company domain, else one of that name, else a new company named after the domain. The
72
+ proposal is turned down, so the two people are not joined and are not proposed again on that address. Only the
73
+ owner decides it; a proposal that is not about a shared mailbox is refused with `identity.not-shared`
74
+ ([ARCHITECTURE.md](docs/dev/ARCHITECTURE.md)).
75
+
76
+ - **`IdentityLinkRow.mailbox` names the shared address**, beside `shared`, so a review can show which mailbox it is.
77
+
78
+ - **`people.linkProposals({ order: "score" })` lists the highest score first**, proposals with no score last, each
79
+ newest first. Without `order` the list stays newest first.
80
+ - **A shared mailbox proposes the people who have it again, scored, and still never joins them.** A role address such
81
+ as `info@` or `office@`, and a company's address (one an organization holds, or two people of one source list have),
82
+ now opens a proposal for each pair of its people instead of being skipped; a no-reply address still proposes no one,
83
+ and the owner is still never proposed. The proposal's `score` says what else the two share: 0.1 for the mailbox
84
+ alone, more for one name, a phone or another address only they hold, a chat or a company's domain
85
+ ([ARCHITECTURE.md](docs/dev/ARCHITECTURE.md)). The first people scan after the upgrade reads every address once,
86
+ so mailboxes nobody touched since are proposed too. Proposals already stored stay as they are.
87
+
88
+ - **`IdentityLinkRow.shared`: `role`, `line` or `null`.** Says that the address behind an `identity_link` proposal is
89
+ a shared mailbox, so a review can show it as one; `null` on proposals made before this release.
90
+
91
+ ### Changed — may break callers
92
+
93
+ - **A person with no readable name of their own is shown by an account's name before its username.** `people.list`
94
+ gave such a person `displayName` `@Xorlov` although their Telegram account is named «Ярослав Орлов» (a person left
95
+ with no name after a split, for one). The first readable account name now comes first, then the username, phone and
96
+ email as before; `displayName(name, { name })` takes it. The shown name also drives the sort by name and the
97
+ automated and company checks, so such a person may move in the list or between kinds.
98
+ - **Taking identities off a person can name that person, and is refused when they sit on someone else.**
99
+ `people.unlinkIdentity(ref, { from })` and `people.proposeSplit({ identities, from })` take the uid of the person the
100
+ identities leave; `people.split(uid, …)` checks its `uid` the same way. An identity on another person is refused with
101
+ `validation_error`, reason `identity.held-elsewhere`, `param: "from"` and `reference: "person:<uid>"` of whoever holds
102
+ it, and the message names them, so nothing moves. Before, a script that meant to take a colleague's mailbox off the
103
+ owner's card took it off the colleague. `split`'s refusal for an identity of another person is now this one (it said
104
+ "is not an identity of person:<n>").
105
+ - **A doubt's unlink names the person it takes the identities from.** `people.doubts()` gives each `unlink` move a
106
+ `from` (`person:<uid>`), and its `fix` command ends in `--from person:<uid>`, which memo's `people unlink` needs.
107
+
108
+ ### Fixed
109
+
110
+ - **A task found in a message keeps the message's first line as its title after the message is deleted.** The line is
111
+ now stored as the title when the task is found, as store version 65 did for the tasks found before. A task found
112
+ before its message is saved still shows the line once the message arrives, and a title the finder or a person sets
113
+ replaces it as before.
114
+ - **Tasks found in messages before 0.630 keep their message's first line as their title (store version 65).** Since
115
+ 0.630 such a task showed the first line only while its message was in the store, and its title went back to
116
+ `question — msg:…` once the message was deleted. Store version 65 stores that line as the title of every live
117
+ found task still titled `<kind> — <source>`, once, on the next writable open, in batches. A title a person wrote, a
118
+ project task, and a task whose message is missing, deleted or empty keep their title.
119
+
8
120
  ## 0.634.0 — 10.11.2026
9
121
 
10
122
  ### 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);
@@ -1,15 +1,33 @@
1
1
  /** What a person can be shown as when their name has nothing to read. */
2
2
  export interface NameFallbacks {
3
+ /** A name one of the person's accounts carries: a real name beats a handle. */
4
+ name?: string | null;
3
5
  username?: string | null;
4
6
  phone?: string | null;
5
7
  email?: string | null;
6
8
  }
7
9
  /**
8
10
  * A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`), or a
9
- * placeholder such as `null` or «Без имени», gives way to the username, then the phone, then the email; the stored name
10
- * stays as it came.
11
+ * placeholder such as `null` or «Без имени», gives way to an account's name, then the username, the phone, the email;
12
+ * the stored name stays as it came.
11
13
  */
12
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>;
13
31
  /**
14
32
  * The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
15
33
  * `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
@@ -26,20 +26,39 @@ const given = (value) => {
26
26
  };
27
27
  /**
28
28
  * A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`), or a
29
- * placeholder such as `null` or «Без имени», gives way to the username, then the phone, then the email; the stored name
30
- * stays as it came.
29
+ * placeholder such as `null` or «Без имени», gives way to an account's name, then the username, the phone, the email;
30
+ * the stored name stays as it came.
31
31
  */
32
32
  export const displayName = (name, fallbacks = {}) => {
33
33
  const unwrapped = typeof name === "string" ? unquoted(name) : "";
34
34
  const cleaned = PLACEHOLDERS.has(unwrapped.toLowerCase()) ? "" : unwrapped;
35
35
  if (READABLE.test(cleaned))
36
36
  return cleaned;
37
+ const borrowed = fallbacks.name === undefined || fallbacks.name === null ? null : displayName(fallbacks.name);
38
+ if (borrowed !== null && READABLE.test(borrowed) && !borrowed.startsWith("@"))
39
+ return borrowed;
37
40
  const username = given(fallbacks.username);
38
41
  return ((username === undefined ? undefined : username.startsWith("@") ? username : `@${username}`) ??
39
42
  given(fallbacks.phone) ??
40
43
  given(fallbacks.email) ??
41
44
  (cleaned === "" ? null : cleaned));
42
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 });
43
62
  /**
44
63
  * The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
45
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",
@@ -392,6 +396,7 @@ const OTHERS = [
392
396
  "the people a merge or a proposed link names changed since; undo the later merge, or propose the link again",
393
397
  ],
394
398
  ["identity.no-merge", "not_found", "nothing of that person is merged into the other; people show lists the merges"],
399
+ validation("identity.held-elsewhere", "the identity sits on another person than the one named; name that person to take it off them"),
395
400
  validation("identity.several-persons", "the identities that leave a person are all of that one person"),
396
401
  validation("identity.nothing-left", "a split leaves at least one identity with the person"),
397
402
  [
@@ -405,6 +410,10 @@ const OTHERS = [
405
410
  "the owner rejected linking these people on this evidence; only a new signal or identity proposes them again",
406
411
  ],
407
412
  validation("identity.same", "the two identities are one person already"),
413
+ validation("identity.not-shared", "only a match on a shared mailbox can say the mailbox is a company's"),
414
+ ["organization.not-found", "not_found", "no stored organization has that id"],
415
+ validation("organization.unnamed", "a free mailbox names no company; name the organization or the company"),
416
+ validation("organization.ambiguous", "more than one organization matches; name the one meant as a reference"),
408
417
  validation("identity.shared-phone", "more than six people share the phone number, so it proposes no one"),
409
418
  validation("identity.common-name", "more than six people have the name, so it proposes no one"),
410
419
  validation("identity.owner", "one side is the owner's person, and only the owner joins anyone to themselves"),
@@ -9,6 +9,8 @@ export declare const NOT_GROUP_NAMES: ReadonlySet<string>;
9
9
  /** `setting`: a saved group lists it; `all`: the default group, which holds every account. */
10
10
  export type GroupReason = "setting" | "all";
11
11
  export interface GroupMember extends AccountKey {
12
+ /** The account's scope as the store holds it, so a group view shows and switches it in place. */
13
+ scope?: "personal" | "work";
12
14
  /** Every saved entry that names it; its `provider:account` in `all`. */
13
15
  entries: string[];
14
16
  reason: GroupReason;
@@ -66,6 +66,7 @@ export const groupMembership = (context) => {
66
66
  holding.set(keyOf(one), [...(holding.get(keyOf(one)) ?? []), name]);
67
67
  for (const [name, members] of [...Object.entries(groups), [ALL, every]])
68
68
  for (const one of members) {
69
+ one.scope = context.held.find(sameAs(one))?.scope ?? "personal";
69
70
  one.profiles = recorded.filter(({ key }) => sameAs(key)(one)).map(({ app, profile }) => `${app} ${profile}`);
70
71
  one.also_in = (holding.get(keyOf(one)) ?? []).filter((other) => other !== name);
71
72
  }
@@ -1,6 +1,7 @@
1
+ import type { Id } from "../domain/models.js";
1
2
  import type { AppIdentity } from "../ports/app.js";
2
3
  import { type GroupMembership } from "../search/groups.js";
3
- import type { AccountKey, MessageStore } from "../store/store.js";
4
+ import type { AccountKey, MessageStore, StoredAccount } from "../store/store.js";
4
5
  /** The store, the account running and its app: what every group edit resolves members against. */
5
6
  export interface GroupStore {
6
7
  store: MessageStore;
@@ -20,9 +21,37 @@ export interface GroupMemberMove extends Omit<GroupMemberChange, "group"> {
20
21
  from: string;
21
22
  to: string;
22
23
  }
24
+ type Scope = StoredAccount["scope"];
25
+ export interface AccountScopeChange {
26
+ /** One account, as `--source` names it: `bitrix24:acme.bitrix24.ru`, `tg:work`. */
27
+ member: string;
28
+ scope: Scope;
29
+ }
30
+ export interface ChatScopeChange {
31
+ member: string;
32
+ /** The chat's id in that account. */
33
+ chat: Id;
34
+ /** `null` takes the chat's own scope off, so it follows its account again. */
35
+ scope: Scope | null;
36
+ }
37
+ export interface ChatScope extends AccountKey {
38
+ chat: Id;
39
+ /** The chat's own scope; `null` when it follows its account. */
40
+ own: Scope | null;
41
+ /** What every reader applies: its own, or else its account's. */
42
+ scope: Scope;
43
+ }
23
44
  /** Every group with its members, why each is in, its profiles and other groups, the duplicates and the suggestions. */
24
45
  export declare const listAccountGroups: (at: GroupStore) => Promise<GroupMembership>;
25
46
  export declare const addGroupMember: (at: GroupStore, change: GroupMemberChange) => Promise<GroupMembership>;
26
47
  export declare const removeGroupMember: (at: GroupStore, change: GroupMemberChange) => Promise<GroupMembership>;
27
48
  /** Out of one group and into another in one write: what a drag between groups does. */
28
49
  export declare const moveGroupMember: (at: GroupStore, move: GroupMemberMove) => Promise<GroupMembership>;
50
+ /**
51
+ * The owner's choice of which side of his life an account is on, as the store now holds it. Moving an account to work
52
+ * lets work views and meeting preparation read it, so a command over this is the owner's alone (`grantsAuthority`).
53
+ */
54
+ export declare const setAccountScope: (at: GroupStore, change: AccountScopeChange) => Promise<StoredAccount>;
55
+ /** The owner pins one chat to a scope, or with `null` lets it follow its account; the owner's alone, as above. */
56
+ export declare const setChatScope: (at: GroupStore, change: ChatScopeChange) => Promise<ChatScope>;
57
+ export {};
@@ -2,6 +2,12 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { accountsOfList, groupName, sameAs, sourceOf } from "../search/account-list.js";
3
3
  import { ALL, hasGroup, NOT_GROUP_NAMES } from "../search/groups.js";
4
4
  import { groupLockOf, listContextOf } from "./search-kind.js";
5
+ const SCOPES = ["personal", "work"];
6
+ const scopeOf = (scope) => {
7
+ if (!SCOPES.includes(scope))
8
+ throw new CliError("validation_error", `${scope} is not a scope — personal or work`, { reason: "input.invalid" });
9
+ return scope;
10
+ };
5
11
  const fail = (code, message) => {
6
12
  throw new CliError(code, message);
7
13
  };
@@ -87,3 +93,24 @@ export const moveGroupMember = async (at, move) => {
87
93
  });
88
94
  return listAccountGroups(at);
89
95
  };
96
+ /**
97
+ * The owner's choice of which side of his life an account is on, as the store now holds it. Moving an account to work
98
+ * lets work views and meeting preparation read it, so a command over this is the owner's alone (`grantsAuthority`).
99
+ */
100
+ export const setAccountScope = async (at, change) => {
101
+ unlocked(at);
102
+ const scope = scopeOf(change.scope);
103
+ const { provider, account } = accountOf(await contextOf(at), change.member);
104
+ return at.store.accounts.setScope({ provider, account }, scope);
105
+ };
106
+ /** The owner pins one chat to a scope, or with `null` lets it follow its account; the owner's alone, as above. */
107
+ export const setChatScope = async (at, change) => {
108
+ unlocked(at);
109
+ const scope = change.scope === null ? null : scopeOf(change.scope);
110
+ const { provider, account } = accountOf(await contextOf(at), change.member);
111
+ const key = { provider, account };
112
+ if (!(await at.store.chats.setChatScope(key, change.chat, scope)))
113
+ fail("not_found", `no chat ${change.chat} stored in ${sourceOf(key)}`);
114
+ const effective = (await at.store.chats.chatScopes(key, [change.chat])).get(change.chat) ?? "personal";
115
+ return { ...key, chat: change.chat, own: scope, scope: effective };
116
+ };
@@ -174,7 +174,7 @@ export { QUERY_LIMITS, QUERY_VERSION } from "../search/lucene/types.js";
174
174
  export { questionLookup } from "../search/question-plan.js";
175
175
  export { type SearchTotal, TOTAL_CAP } from "../search/total.js";
176
176
  export { TASK_KINDS, TASK_ORIGINS, type TaskKind, type TaskOrigin } from "../tasks/index.js";
177
- export { addGroupMember, type GroupMemberChange, type GroupMemberMove, type GroupStore, listAccountGroups, moveGroupMember, removeGroupMember, } from "./account-groups.js";
177
+ export { type AccountScopeChange, addGroupMember, type ChatScope, type ChatScopeChange, type GroupMemberChange, type GroupMemberMove, type GroupStore, listAccountGroups, moveGroupMember, removeGroupMember, setAccountScope, setChatScope, } from "./account-groups.js";
178
178
  export type { AdminFound, AdminQuery, AdminSelection, AdminStatisticsService } from "./admin-statistics.js";
179
179
  export { adminStatisticsService } from "./admin-statistics.js";
180
180
  export { GAP_BOUNDS, type GapPlan, type GapRepair, gapsService, type RepairOptions } from "./archive-gaps.js";
@@ -133,7 +133,7 @@ export { QUERY_LIMITS, QUERY_VERSION } from "../search/lucene/types.js";
133
133
  export { questionLookup } from "../search/question-plan.js";
134
134
  export { TOTAL_CAP } from "../search/total.js";
135
135
  export { TASK_KINDS, TASK_ORIGINS } from "../tasks/index.js";
136
- export { addGroupMember, listAccountGroups, moveGroupMember, removeGroupMember, } from "./account-groups.js";
136
+ export { addGroupMember, listAccountGroups, moveGroupMember, removeGroupMember, setAccountScope, setChatScope, } from "./account-groups.js";
137
137
  export { adminStatisticsService } from "./admin-statistics.js";
138
138
  export { GAP_BOUNDS, gapsService } from "./archive-gaps.js";
139
139
  export { countersService } from "./counters.js";
@@ -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;
@@ -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();
@@ -3,9 +3,13 @@ import { type AccountGroups, type Profiles } from "../search/account-list.js";
3
3
  import type { StoreContext } from "./sqlite/open.js";
4
4
  import type { AccountKey, StoredAccount } from "./types.js";
5
5
  export interface AccountAccounts {
6
- /** Answers the store's id for the account, which `meetings` and `mail` take. */
6
+ /**
7
+ * Answers the store's id for the account, which `meetings` and `mail` take. `scope` is what a new account starts
8
+ * as (a CRM's `work`); an account already stored keeps the scope it has.
9
+ */
7
10
  saveAccount(key: AccountKey, account: {
8
11
  name: string | null;
12
+ scope?: StoredAccount["scope"];
9
13
  }): Promise<number>;
10
14
  /** One account by provider and external id, never created: `not_found` when the store has none. */
11
15
  storedAccount(key: AccountKey): Promise<StoredAccount>;
@@ -33,6 +37,11 @@ export interface AccountsStore extends AccountAccounts {
33
37
  accounts(): Promise<AccountKey[]>;
34
38
  /** Every account with the store's id for it, by provider then external id. */
35
39
  storedAccounts(): Promise<StoredAccount[]>;
40
+ /**
41
+ * The owner's choice of an account's scope, personal or work; what search copied of the old one follows. A
42
+ * missing account is `not_found`.
43
+ */
44
+ setScope(key: AccountKey, scope: StoredAccount["scope"]): Promise<StoredAccount>;
36
45
  /** The account groups `--source group:<name>` reads: each group's entries as saved, store-wide. */
37
46
  accountGroups(): Promise<AccountGroups>;
38
47
  /** Saves one group's entries; `undefined` removes the group. */
@@ -10,9 +10,9 @@ export const accountAccountsOver = (context) => {
10
10
  const { database } = context;
11
11
  const { accountPk, findAccountPk } = keysOver(context);
12
12
  return {
13
- saveAccount: async (key, { name }) => {
13
+ saveAccount: async (key, { name, scope }) => {
14
14
  const pk = write(database, () => {
15
- const made = accountPk(key, name);
15
+ const made = accountPk(key, name, scope);
16
16
  linkInbox(database, `${key.provider}:${key.account}`, made);
17
17
  return made;
18
18
  });
@@ -38,6 +38,7 @@ export const accountsStoreOver = (context, keyed) => {
38
38
  ...keyed,
39
39
  accounts: async () => accounts.heldAccounts(context),
40
40
  storedAccounts: async () => accounts.storedAccounts(context),
41
+ setScope: async (key, scope) => write(database, () => accounts.setAccountScope(context, key, scope)),
41
42
  accountGroups: async () => accountGroupsOf(database),
42
43
  profiles: async () => profilesOf(database),
43
44
  saveProfile: async (app, profile, key) => write(database, () => saveProfile(database, app, profile, key, context.now())),