@wirecat/cli-core 0.618.0 → 0.619.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +339 -1
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES +3 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/background/deliver.d.ts +5 -2
- package/dist/background/deliver.js +30 -12
- package/dist/background/report/render.d.ts +3 -1
- package/dist/background/report/render.js +3 -1
- package/dist/calendar/cli/answers.d.ts +1 -0
- package/dist/calendar/cli/answers.js +6 -1
- package/dist/calendar/cli/index.js +2 -14
- package/dist/calendar/cli/people-link.d.ts +3 -0
- package/dist/calendar/cli/people-link.js +23 -0
- package/dist/calendar/index.d.ts +1 -1
- package/dist/calendar/index.js +1 -1
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/base-stages-command.d.ts +22 -0
- package/dist/cli/base-stages-command.js +174 -0
- package/dist/cli/command-runs.d.ts +2 -0
- package/dist/cli/command-runs.js +3 -1
- package/dist/cli/config-command.js +6 -1
- package/dist/cli/context.js +1 -0
- package/dist/cli/group-lock.d.ts +42 -0
- package/dist/cli/group-lock.js +130 -0
- package/dist/cli/index.d.ts +7 -2
- package/dist/cli/index.js +7 -2
- package/dist/cli/messenger/backfill-command.js +27 -15
- package/dist/cli/messenger/contacts-command.js +10 -3
- package/dist/cli/messenger/context.js +1 -0
- package/dist/cli/messenger/doctor-command.js +3 -1
- package/dist/cli/messenger/models-command.js +1 -1
- package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
- package/dist/cli/messenger/store-maintenance-command.js +9 -4
- package/dist/cli/model-catalogue-command.d.ts +3 -1
- package/dist/cli/model-catalogue-command.js +46 -2
- package/dist/cli/profile.d.ts +8 -0
- package/dist/cli/profile.js +25 -0
- package/dist/cli/program.js +2 -0
- package/dist/cli/runs/search-query.d.ts +1 -1
- package/dist/cli/runs/search-query.js +4 -0
- package/dist/cli/runs/search.d.ts +5 -1
- package/dist/cli/runs/search.js +12 -1
- package/dist/cli/search-left-out.d.ts +6 -1
- package/dist/cli/search-left-out.js +9 -4
- package/dist/cli/settings.d.ts +8 -0
- package/dist/cli/settings.js +17 -2
- package/dist/cli/shared-command-exports.d.ts +16 -0
- package/dist/cli/store-recover.d.ts +3 -3
- package/dist/cli/store-recover.js +26 -26
- package/dist/cli/store-settings.d.ts +2 -0
- package/dist/cli/store-settings.js +37 -9
- package/dist/crm/cli/index.js +38 -6
- package/dist/crm/group-hint.d.ts +8 -0
- package/dist/crm/group-hint.js +13 -0
- package/dist/crm/source.d.ts +12 -1
- package/dist/crm/sync.d.ts +31 -2
- package/dist/crm/sync.js +110 -3
- package/dist/crm/testing/acme-scenario.d.ts +40 -0
- package/dist/crm/testing/acme-scenario.js +170 -0
- package/dist/crm/testing/index.d.ts +1 -0
- package/dist/crm/testing/index.js +1 -0
- package/dist/crm/testing/source-contract.js +12 -0
- package/dist/crm/testing/source.d.ts +2 -0
- package/dist/crm/testing/source.js +1 -0
- package/dist/domain/addresses.d.ts +13 -0
- package/dist/domain/addresses.js +63 -0
- package/dist/domain/categories.d.ts +3 -0
- package/dist/domain/categories.js +2 -0
- package/dist/domain/crm.d.ts +23 -0
- package/dist/domain/crm.js +7 -0
- package/dist/domain/mentions.d.ts +2 -12
- package/dist/domain/mentions.js +2 -19
- package/dist/domain/orders.d.ts +8 -1
- package/dist/domain/orders.js +6 -2
- package/dist/domain/phones.d.ts +26 -0
- package/dist/domain/phones.js +48 -0
- package/dist/domain/record-types.d.ts +1 -1
- package/dist/domain/record-types.js +1 -0
- package/dist/domain/records.d.ts +5 -0
- package/dist/domain/ref-summaries.d.ts +39 -0
- package/dist/domain/ref-summaries.js +51 -3
- package/dist/domain/relations.d.ts +12 -2
- package/dist/domain/relations.js +14 -3
- package/dist/domain/vcard.d.ts +2 -2
- package/dist/domain/vcard.js +4 -10
- package/dist/embeddings/models.d.ts +11 -3
- package/dist/embeddings/models.js +28 -4
- package/dist/entities/business-context.d.ts +149 -0
- package/dist/entities/business-context.js +192 -0
- package/dist/entities/contact-activity.d.ts +2 -0
- package/dist/entities/contact-activity.js +7 -1
- package/dist/entities/contact-context.d.ts +157 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/deal.d.ts +10 -0
- package/dist/entities/deal.js +2 -0
- package/dist/entities/index.d.ts +23 -3
- package/dist/entities/index.js +5 -0
- package/dist/entities/mention.d.ts +4 -3
- package/dist/entities/mention.js +2 -1
- package/dist/entities/message-transfer.d.ts +4 -2
- package/dist/entities/message-transfer.js +2 -2
- package/dist/entities/model.d.ts +2 -2
- package/dist/entities/model.js +1 -1
- package/dist/entities/relationship.d.ts +4 -0
- package/dist/entities/relationship.js +4 -0
- package/dist/errors/reasons.js +37 -4
- package/dist/fetch/page.js +2 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/meetings/context-store.d.ts +2 -0
- package/dist/meetings/findings-rules.d.ts +4 -0
- package/dist/meetings/findings-rules.js +5 -2
- package/dist/meetings/result-items.d.ts +1 -0
- package/dist/meetings/result-items.js +1 -0
- package/dist/models/index.js +22 -5
- package/dist/runs/events.d.ts +11 -1
- package/dist/runs/events.js +3 -1
- package/dist/runs/log-attributes.js +4 -0
- package/dist/runs/log-events.js +2 -0
- package/dist/runs/recording.d.ts +3 -0
- package/dist/runs/recording.js +36 -12
- package/dist/runs/run.d.ts +12 -3
- package/dist/runs/run.js +32 -13
- package/dist/search/account-list.d.ts +6 -0
- package/dist/search/account-list.js +9 -3
- package/dist/search/groups.d.ts +68 -0
- package/dist/search/groups.js +172 -0
- package/dist/services/account-groups.d.ts +28 -0
- package/dist/services/account-groups.js +89 -0
- package/dist/services/archive.d.ts +7 -1
- package/dist/services/archive.js +19 -3
- package/dist/services/business-context.d.ts +113 -0
- package/dist/services/business-context.js +156 -0
- package/dist/services/communications.d.ts +50 -0
- package/dist/services/communications.js +140 -0
- package/dist/services/deal-context.d.ts +90 -0
- package/dist/services/deal-context.js +131 -0
- package/dist/services/deps.d.ts +2 -0
- package/dist/services/enrichment.d.ts +7 -2
- package/dist/services/enrichment.js +46 -5
- package/dist/services/events-search.js +2 -1
- package/dist/services/group-guard.d.ts +28 -0
- package/dist/services/group-guard.js +131 -0
- package/dist/services/index.d.ts +15 -2
- package/dist/services/index.js +9 -2
- package/dist/services/ingest.d.ts +12 -0
- package/dist/services/ingest.js +4 -0
- package/dist/services/meaning-model.d.ts +7 -0
- package/dist/services/meaning-model.js +20 -0
- package/dist/services/meeting-context.d.ts +6 -1
- package/dist/services/meeting-context.js +12 -5
- package/dist/services/message-resolution.js +2 -3
- package/dist/services/messages-meaning.js +4 -5
- package/dist/services/messages-search.d.ts +5 -1
- package/dist/services/messages-search.js +1 -1
- package/dist/services/model-downloads.d.ts +1 -1
- package/dist/services/model-downloads.js +6 -4
- package/dist/services/money-context.d.ts +73 -0
- package/dist/services/money-context.js +77 -0
- package/dist/services/notes-search.d.ts +4 -1
- package/dist/services/notes-search.js +19 -7
- package/dist/services/organization-context.d.ts +80 -0
- package/dist/services/organization-context.js +154 -0
- package/dist/services/people.d.ts +22 -6
- package/dist/services/people.js +38 -8
- package/dist/services/person-business.d.ts +43 -0
- package/dist/services/person-business.js +67 -0
- package/dist/services/person-context.d.ts +9 -1
- package/dist/services/person-context.js +5 -3
- package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
- package/dist/services/proposals/kinds/identity-link.js +48 -0
- package/dist/services/proposals/kinds/orders.js +1 -1
- package/dist/services/proposals/registry.js +2 -0
- package/dist/services/search-kind.d.ts +12 -5
- package/dist/services/search-kind.js +49 -10
- package/dist/services/text-model-choice.js +1 -1
- package/dist/store/accounts.d.ts +18 -0
- package/dist/store/accounts.js +18 -3
- package/dist/store/damage.d.ts +43 -10
- package/dist/store/damage.js +119 -36
- package/dist/store/decisions.js +3 -1
- package/dist/store/evidence-findings.d.ts +14 -0
- package/dist/store/evidence-findings.js +2 -0
- package/dist/store/exports.d.ts +2 -1
- package/dist/store/identity-links.d.ts +92 -0
- package/dist/store/identity-links.js +6 -0
- package/dist/store/index.d.ts +11 -5
- package/dist/store/index.js +5 -2
- package/dist/store/journal.d.ts +10 -0
- package/dist/store/journal.js +33 -0
- package/dist/store/marks.d.ts +19 -1
- package/dist/store/marks.js +23 -1
- package/dist/store/people.d.ts +22 -0
- package/dist/store/people.js +15 -1
- package/dist/store/sqlite/accounts.js +2 -0
- package/dist/store/sqlite/base-stages.d.ts +122 -0
- package/dist/store/sqlite/base-stages.js +443 -0
- package/dist/store/sqlite/base-suggest.d.ts +13 -0
- package/dist/store/sqlite/base-suggest.js +62 -0
- package/dist/store/sqlite/business-contracts.js +10 -1
- package/dist/store/sqlite/crm-settings.d.ts +12 -2
- package/dist/store/sqlite/crm-settings.js +56 -13
- package/dist/store/sqlite/crm.d.ts +13 -1
- package/dist/store/sqlite/crm.js +20 -4
- package/dist/store/sqlite/deals.d.ts +33 -0
- package/dist/store/sqlite/deals.js +42 -4
- package/dist/store/sqlite/decision-requests.js +7 -3
- package/dist/store/sqlite/email-index.js +8 -4
- package/dist/store/sqlite/evidence-findings.js +29 -5
- package/dist/store/sqlite/findings-core.js +4 -2
- package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
- package/dist/store/sqlite/identity-link-rows.js +146 -0
- package/dist/store/sqlite/identity-proposals.d.ts +53 -0
- package/dist/store/sqlite/identity-proposals.js +234 -0
- package/dist/store/sqlite/knowledge.js +2 -2
- package/dist/store/sqlite/link-kinds.d.ts +1 -0
- package/dist/store/sqlite/link-kinds.js +1 -0
- package/dist/store/sqlite/link-row.d.ts +6 -0
- package/dist/store/sqlite/link-row.js +35 -0
- package/dist/store/sqlite/link-source.d.ts +10 -0
- package/dist/store/sqlite/link-source.js +16 -0
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/meeting-context-links.js +9 -6
- package/dist/store/sqlite/memories.js +9 -7
- package/dist/store/sqlite/mentions.d.ts +4 -1
- package/dist/store/sqlite/mentions.js +14 -9
- package/dist/store/sqlite/migrations.generated.js +8 -0
- package/dist/store/sqlite/notes.d.ts +1 -2
- package/dist/store/sqlite/notes.js +4 -29
- package/dist/store/sqlite/open-store.js +3 -0
- package/dist/store/sqlite/open.js +11 -2
- package/dist/store/sqlite/orders.d.ts +2 -0
- package/dist/store/sqlite/orders.js +9 -3
- package/dist/store/sqlite/organization-categories.d.ts +18 -0
- package/dist/store/sqlite/organization-categories.js +34 -0
- package/dist/store/sqlite/organizations.d.ts +5 -1
- package/dist/store/sqlite/organizations.js +14 -4
- package/dist/store/sqlite/person-links.d.ts +19 -4
- package/dist/store/sqlite/person-links.js +49 -11
- package/dist/store/sqlite/person-match-scan.d.ts +13 -0
- package/dist/store/sqlite/person-match-scan.js +251 -0
- package/dist/store/sqlite/person-matcher.d.ts +16 -0
- package/dist/store/sqlite/person-matcher.js +32 -0
- package/dist/store/sqlite/proposed-actions.js +6 -0
- package/dist/store/sqlite/record-matching.d.ts +2 -8
- package/dist/store/sqlite/record-matching.js +8 -40
- package/dist/store/sqlite/record-projectors-phone.js +2 -1
- package/dist/store/sqlite/record-relationships.d.ts +52 -0
- package/dist/store/sqlite/record-relationships.js +243 -0
- package/dist/store/sqlite/record-run.d.ts +5 -0
- package/dist/store/sqlite/record-run.js +62 -2
- package/dist/store/sqlite/record-writes.d.ts +1 -1
- package/dist/store/sqlite/record-writes.js +4 -2
- package/dist/store/sqlite/records.js +27 -2
- package/dist/store/sqlite/ref-accounts.d.ts +13 -0
- package/dist/store/sqlite/ref-accounts.js +117 -0
- package/dist/store/sqlite/ref-summaries.js +5 -1
- package/dist/store/sqlite/relation-list.d.ts +4 -1
- package/dist/store/sqlite/relation-list.js +18 -2
- package/dist/store/sqlite/relation-proposals.d.ts +6 -0
- package/dist/store/sqlite/relation-proposals.js +3 -0
- package/dist/store/sqlite/relation-roles.js +12 -6
- package/dist/store/sqlite/reported-relations.d.ts +11 -1
- package/dist/store/sqlite/reported-relations.js +59 -18
- package/dist/store/sqlite/schema.d.ts +32 -0
- package/dist/store/sqlite/schema.js +3 -0
- package/dist/store/sqlite/transaction.js +11 -1
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/store/write-events.d.ts +18 -0
- package/dist/store/write-events.js +88 -0
- package/package.json +3 -3
- package/parity.json +11 -4
- package/schemas/records-envelope.v1.schema.json +3 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { markJournalLost } from "./marks.js";
|
|
4
|
+
const watched = new WeakMap();
|
|
5
|
+
const walInode = (store) => statSync(`${store}-wal`, { throwIfNoEntry: false })?.ino;
|
|
6
|
+
/** Before the open. SQLite creates `-wal` before `-shm` and deletes it after, so it never leaves `-shm` alone itself. */
|
|
7
|
+
export const noteShmWithoutWal = (store, command) => {
|
|
8
|
+
if (existsSync(`${store}-shm`) && !existsSync(`${store}-wal`))
|
|
9
|
+
markJournalLost(store, { seen: "shm-without-wal", command });
|
|
10
|
+
};
|
|
11
|
+
export const watchJournal = (database, store, command) => {
|
|
12
|
+
watched.set(database, { store, command, inode: walInode(store) });
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Called before each outermost commit. A connection keeps writing into a `-wal` that was unlinked under it while the
|
|
16
|
+
* next process starts a fresh one, and the two journals then overwrite each other's pages: refusing the commit is
|
|
17
|
+
* the only point at which this process can still keep out of it.
|
|
18
|
+
*/
|
|
19
|
+
export const checkJournal = (database) => {
|
|
20
|
+
const watch = watched.get(database);
|
|
21
|
+
if (!watch)
|
|
22
|
+
return;
|
|
23
|
+
const inode = walInode(watch.store);
|
|
24
|
+
if (watch.inode === undefined) {
|
|
25
|
+
watch.inode = inode;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (inode === watch.inode)
|
|
29
|
+
return;
|
|
30
|
+
markJournalLost(watch.store, { seen: inode === undefined ? "missing" : "replaced", command: watch.command });
|
|
31
|
+
throw new CliError("conflict", "the store's journal file was deleted or replaced by another program while this command had the store open, " +
|
|
32
|
+
"so nothing more is written; `store recover` says what to do", { reason: "store.journal-replaced" });
|
|
33
|
+
};
|
package/dist/store/marks.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { StoreHealth } from "./health.js";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const damageMarkPath: (store: string) => string;
|
|
7
7
|
export declare const healthMarkPath: (store: string) => string;
|
|
8
|
+
export declare const journalMarkPath: (store: string) => string;
|
|
8
9
|
/** A run saw SQLite say the store is damaged. Every writable open refuses while it names the file in place. */
|
|
9
10
|
export interface DamageMark {
|
|
10
11
|
at: string;
|
|
@@ -25,6 +26,15 @@ export interface HealthMark {
|
|
|
25
26
|
cli_version?: string;
|
|
26
27
|
last_ok_at: string | null;
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The store's `-wal` file went away or was swapped while a run held the store open, or a `-shm` stood without it at
|
|
31
|
+
* open: another program deleted or replaced the journal. Evidence for the damage report, not a refusal.
|
|
32
|
+
*/
|
|
33
|
+
export interface JournalMark {
|
|
34
|
+
at: string;
|
|
35
|
+
command: string;
|
|
36
|
+
seen: "missing" | "replaced" | "shm-without-wal";
|
|
37
|
+
}
|
|
28
38
|
/**
|
|
29
39
|
* Leaves the damage mark when `error` is SQLite saying the store is damaged; the first sighting is kept. Never
|
|
30
40
|
* throws: the failure being reported matters more than the mark.
|
|
@@ -41,10 +51,18 @@ export declare const readDamageMark: (store: string) => DamageMark | null;
|
|
|
41
51
|
export declare const clearDamageMark: (store: string) => void;
|
|
42
52
|
/** Thrown by a writable open of a store a run found damaged, so timers fail fast instead of writing into it. */
|
|
43
53
|
export declare const refuseDamagedStore: (store: string, cli?: string) => void;
|
|
54
|
+
/** Keeps the first sighting; never throws. */
|
|
55
|
+
export declare const markJournalLost: (store: string, { seen, command, now }: {
|
|
56
|
+
seen: JournalMark["seen"];
|
|
57
|
+
command: string;
|
|
58
|
+
now?: () => number;
|
|
59
|
+
}) => void;
|
|
60
|
+
export declare const readJournalMark: (store: string) => JournalMark | null;
|
|
44
61
|
export declare const readHealthMark: (store: string) => HealthMark | null;
|
|
45
62
|
/**
|
|
46
63
|
* Records a deep check of the store. One that passed also removes the damage mark: the file reads whole. Returns the
|
|
47
|
-
* mark it replaced, whose `last_ok_at` is the last known good before this check, and the damage mark it removed.
|
|
64
|
+
* mark it replaced, whose `last_ok_at` is the last known good before this check, and the damage mark it removed. A pass
|
|
65
|
+
* also removes the journal mark: whatever the lost journal held is gone or was never needed.
|
|
48
66
|
*/
|
|
49
67
|
export declare const recordDeepCheck: (store: string, health: Pick<StoreHealth, "ok" | "problems">, { cli, version, schema, now, }: {
|
|
50
68
|
cli: string;
|
package/dist/store/marks.js
CHANGED
|
@@ -8,6 +8,7 @@ import { refuseOwnerStoreInTests } from "./path.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export const damageMarkPath = (store) => `${store}.damaged.json`;
|
|
10
10
|
export const healthMarkPath = (store) => `${store}.health.json`;
|
|
11
|
+
export const journalMarkPath = (store) => `${store}.journal.json`;
|
|
11
12
|
const inodeOf = (store) => statSync(store, { throwIfNoEntry: false })?.ino;
|
|
12
13
|
const readJson = (path) => {
|
|
13
14
|
try {
|
|
@@ -84,6 +85,24 @@ export const refuseDamagedStore = (store, cli) => {
|
|
|
84
85
|
throw new CliError("configuration_error", `the store was found damaged at ${mark.at} by \`${mark.command}\` (${mark.error}), so nothing writes to it until ` +
|
|
85
86
|
`it is recovered; \`${cli ?? "<cli>"} store recover\` says what is damaged and what to do`, { reason: "store.damaged" });
|
|
86
87
|
};
|
|
88
|
+
/** Keeps the first sighting; never throws. */
|
|
89
|
+
export const markJournalLost = (store, { seen, command, now = Date.now }) => {
|
|
90
|
+
if (ownerStoreInTests(store))
|
|
91
|
+
return;
|
|
92
|
+
const mark = { at: new Date(now()).toISOString(), command, seen };
|
|
93
|
+
try {
|
|
94
|
+
writeFileSync(journalMarkPath(store), `${JSON.stringify(mark, null, 2)}\n`, { flag: "wx", mode: 0o600 });
|
|
95
|
+
}
|
|
96
|
+
catch { }
|
|
97
|
+
};
|
|
98
|
+
export const readJournalMark = (store) => {
|
|
99
|
+
try {
|
|
100
|
+
return readJson(journalMarkPath(store));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
87
106
|
export const readHealthMark = (store) => {
|
|
88
107
|
try {
|
|
89
108
|
return readJson(healthMarkPath(store));
|
|
@@ -94,7 +113,8 @@ export const readHealthMark = (store) => {
|
|
|
94
113
|
};
|
|
95
114
|
/**
|
|
96
115
|
* Records a deep check of the store. One that passed also removes the damage mark: the file reads whole. Returns the
|
|
97
|
-
* mark it replaced, whose `last_ok_at` is the last known good before this check, and the damage mark it removed.
|
|
116
|
+
* mark it replaced, whose `last_ok_at` is the last known good before this check, and the damage mark it removed. A pass
|
|
117
|
+
* also removes the journal mark: whatever the lost journal held is gone or was never needed.
|
|
98
118
|
*/
|
|
99
119
|
export const recordDeepCheck = (store, health, { cli, version, schema, now = Date.now, }) => {
|
|
100
120
|
const previous = readHealthMark(store);
|
|
@@ -117,5 +137,7 @@ export const recordDeepCheck = (store, health, { cli, version, schema, now = Dat
|
|
|
117
137
|
catch { }
|
|
118
138
|
if (cleared)
|
|
119
139
|
clearDamageMark(store);
|
|
140
|
+
if (health.ok)
|
|
141
|
+
rmSync(journalMarkPath(store), { force: true });
|
|
120
142
|
return { previous, cleared };
|
|
121
143
|
};
|
package/dist/store/people.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { Contact, Id, Page, PersonAlias, Provider } from "../domain/models.js";
|
|
2
2
|
import type { PeopleLookup } from "../resolve.js";
|
|
3
|
+
import type { IdentityLinkDecision, IdentityLinkFilter, IdentityLinkInput, IdentityLinkRow, MatchScan } from "./identity-links.js";
|
|
3
4
|
import type { ContactFilter } from "./sqlite/identities.js";
|
|
4
5
|
import type { StoreContext } from "./sqlite/open.js";
|
|
5
6
|
import type { PersonMerge } from "./sqlite/person-merges.js";
|
|
6
7
|
import { type PersonPreparationRead } from "./sqlite/person-preparation.js";
|
|
7
8
|
import type { PrivateContact, PrivateContactNote } from "./sqlite/private-people.js";
|
|
9
|
+
import type { ProposedAction } from "./sqlite/proposed-actions.js";
|
|
8
10
|
import type { AccountKey, IdentityRef, LinkOptions, PersonFacts, PersonRecord } from "./types.js";
|
|
9
11
|
export interface AccountPeople {
|
|
10
12
|
savePeople(key: AccountKey, people: PersonFacts[]): Promise<void>;
|
|
@@ -64,6 +66,26 @@ export interface PeopleStore extends AccountPeople {
|
|
|
64
66
|
undoMerge(to: string, from: string, by: string): Promise<PersonRecord>;
|
|
65
67
|
/** The owner's split: the chosen identities become one new person, which this gives. */
|
|
66
68
|
split(uid: string, identities: IdentityRef[], by: string): Promise<PersonRecord>;
|
|
69
|
+
/**
|
|
70
|
+
* Proposes that two identities' people are one, as an `identity_link` only the owner decides. Refused over the
|
|
71
|
+
* owner's separation or rejection; an open proposal for the same two people is given back instead of a second.
|
|
72
|
+
*/
|
|
73
|
+
proposeLink(input: IdentityLinkInput): Promise<ProposedAction>;
|
|
74
|
+
/** The owner's decision on an `identity_link`; confirm is refused with `identity.stale` when either person changed. */
|
|
75
|
+
decideLink(id: string, decision: IdentityLinkDecision): Promise<ProposedAction>;
|
|
76
|
+
/**
|
|
77
|
+
* One pass of the people matcher: the same address joins people in every scope, a phone exactly two people have
|
|
78
|
+
* joins them, a phone more people share, a role address such as `info@` and a meeting guest's typed address become
|
|
79
|
+
* proposals. Never over the owner's separation; a pair the owner rejected is proposed again only on new evidence.
|
|
80
|
+
*/
|
|
81
|
+
scanMatches(options?: {
|
|
82
|
+
full?: boolean;
|
|
83
|
+
}): Promise<MatchScan>;
|
|
84
|
+
/** The `identity_link` proposals, newest first, naming the people as they are now; `proposed` unless `status` says. */
|
|
85
|
+
linkProposals(filter: IdentityLinkFilter): Promise<{
|
|
86
|
+
items: IdentityLinkRow[];
|
|
87
|
+
hasMore: boolean;
|
|
88
|
+
}>;
|
|
67
89
|
/** The identity, and everyone linked with it, is the owner. */
|
|
68
90
|
linkToOwner(identity: IdentityRef): Promise<PersonRecord>;
|
|
69
91
|
/** A person known by name only, with no identity yet: someone to assign a task to before any message names them. */
|
package/dist/store/people.js
CHANGED
|
@@ -2,8 +2,10 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { keysOver } from "./keys.js";
|
|
3
3
|
import { ownerPerson } from "./sqlite/actors.js";
|
|
4
4
|
import * as identities from "./sqlite/identities.js";
|
|
5
|
+
import * as identityProposals from "./sqlite/identity-proposals.js";
|
|
5
6
|
import { linkToOwner } from "./sqlite/own-identities.js";
|
|
6
7
|
import * as personLinks from "./sqlite/person-links.js";
|
|
8
|
+
import { RULE, scanMatches } from "./sqlite/person-match-scan.js";
|
|
7
9
|
import * as personMerges from "./sqlite/person-merges.js";
|
|
8
10
|
import { personPreparation } from "./sqlite/person-preparation.js";
|
|
9
11
|
import { personSeenInAccounts } from "./sqlite/person-scope.js";
|
|
@@ -18,7 +20,15 @@ export const accountPeopleOver = (context) => {
|
|
|
18
20
|
for (const person of people) {
|
|
19
21
|
identityPk(accountKey, key.provider, person.id, person.name, person);
|
|
20
22
|
if (person.email)
|
|
21
|
-
personLinks.
|
|
23
|
+
personLinks.noteAddress(context, { provider: key.provider, id: person.id }, person.email);
|
|
24
|
+
}
|
|
25
|
+
// Every address of the batch is noted before any joins, so one shared by the whole batch is seen as shared.
|
|
26
|
+
for (const person of people) {
|
|
27
|
+
if (!person.email)
|
|
28
|
+
continue;
|
|
29
|
+
const held = personLinks.joinByAddress(context, { provider: key.provider, id: person.id }, person.email, key.provider);
|
|
30
|
+
if (held)
|
|
31
|
+
identityProposals.openIdentityLink(context, { ...held, joins: "person", signal: "email", by: RULE });
|
|
22
32
|
}
|
|
23
33
|
}),
|
|
24
34
|
contacts: async (key, options) => {
|
|
@@ -95,6 +105,10 @@ export const peopleStoreOver = (context, keyed) => {
|
|
|
95
105
|
merges: async (uid) => personMerges.merges(context, uid),
|
|
96
106
|
undoMerge: async (to, from, by) => write(database, () => personMerges.undoMerge(context, to, from, by)),
|
|
97
107
|
split: async (uid, chosen, by) => write(database, () => personMerges.split(context, uid, chosen, by)),
|
|
108
|
+
proposeLink: async (input) => identityProposals.proposeIdentityLink(context, input),
|
|
109
|
+
decideLink: async (id, decision) => identityProposals.decideIdentityLink(context, id, decision),
|
|
110
|
+
scanMatches: async (options) => scanMatches(context, options),
|
|
111
|
+
linkProposals: async (filter) => identityProposals.identityLinkRows(context, filter),
|
|
98
112
|
linkToOwner: async (identity) => linkToOwner(context, identity),
|
|
99
113
|
};
|
|
100
114
|
};
|
|
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
2
2
|
import { and, asc, eq, inArray, sql } from "./drizzle/core.js";
|
|
3
3
|
import { pointerPairs } from "./entity-types.js";
|
|
4
4
|
import { forgetDanglingEvidence, forgetEvidenceTo } from "./evidence-signature.js";
|
|
5
|
+
import { forgetErasedLinks } from "./identity-link-rows.js";
|
|
5
6
|
import { mergeSql } from "./merged-persons.js";
|
|
6
7
|
import { accountIdentities, accounts, aliases, botUpdates, chatEventPeople, chatEvents, chatMembers, chats, chunks, fetchLeases, involvements, memberCounts, memberObservationMembers, memberObservations, memberStays, messageReactions, messageRevisions, messages, messageTranscripts, pollVotes, projects, syncCursors, syncRanges, syncs, } from "./schema.js";
|
|
7
8
|
import { dropUnusedVectors } from "./vector-index.js";
|
|
@@ -198,6 +199,7 @@ export const dropOrphanPeople = (database, unseenBefore) => {
|
|
|
198
199
|
for (const table of ["identity_revisions", "identity_link_events", "identity_links"])
|
|
199
200
|
database.prepare(`DELETE FROM ${table} WHERE identity_id IN (SELECT value FROM json_each(?))`).run(gone);
|
|
200
201
|
database.prepare("DELETE FROM identities WHERE id IN (SELECT value FROM json_each(?))").run(gone);
|
|
202
|
+
forgetErasedLinks(database);
|
|
201
203
|
database
|
|
202
204
|
.prepare(`DELETE FROM persons WHERE id IN (SELECT value FROM json_each(?)) AND owner = 0
|
|
203
205
|
AND NOT EXISTS (SELECT 1 FROM identity_links l WHERE l.person_id = persons.id)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type DealKind, type StageOutcome } from "../../domain/deals.js";
|
|
2
|
+
import type { AccountKey } from "../types.js";
|
|
3
|
+
import type { StoreContext } from "./open.js";
|
|
4
|
+
export interface StageName {
|
|
5
|
+
/** `stage:<id>`: a stage of any pipeline, as these commands name it. */
|
|
6
|
+
ref: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
/** One column of a base set: the open deals or leads whose stage maps to it, and how many stages do. */
|
|
10
|
+
export interface BaseColumn extends Omit<StageName, "ref"> {
|
|
11
|
+
/** `null` only in a set read from a read-only store before its first use made it. */
|
|
12
|
+
ref: string | null;
|
|
13
|
+
position: number;
|
|
14
|
+
outcome: StageOutcome;
|
|
15
|
+
open: number;
|
|
16
|
+
/** Stages of other pipelines confirmed onto it. */
|
|
17
|
+
mapped: number;
|
|
18
|
+
}
|
|
19
|
+
export interface BaseSet {
|
|
20
|
+
kind: DealKind;
|
|
21
|
+
/** The owner's own pipeline that holds the set; `null` while a read-only read shows the defaults not made yet. */
|
|
22
|
+
pipeline: string | null;
|
|
23
|
+
stages: BaseColumn[];
|
|
24
|
+
/** What no column holds yet: open rows whose stage is unmapped or only suggested, and those stages. */
|
|
25
|
+
unsorted: {
|
|
26
|
+
open: number;
|
|
27
|
+
stages: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** A stage of a pipeline outside the base set, and the base stage it maps to. */
|
|
31
|
+
export interface StageMapping extends StageName {
|
|
32
|
+
position: number;
|
|
33
|
+
outcome: StageOutcome;
|
|
34
|
+
/** The CRM's own id of the stage, which a CRM CLI's move matches first; `null` in an own pipeline. */
|
|
35
|
+
externalId: string | null;
|
|
36
|
+
kind: DealKind;
|
|
37
|
+
pipeline: string;
|
|
38
|
+
pipelineName: string;
|
|
39
|
+
account: AccountKey | null;
|
|
40
|
+
/** Suggested or confirmed; `null` until the base set exists or when nothing fits. */
|
|
41
|
+
baseStage: StageName | null;
|
|
42
|
+
confirmed: boolean;
|
|
43
|
+
open: number;
|
|
44
|
+
}
|
|
45
|
+
export interface BaseScope {
|
|
46
|
+
/** Only these CRM accounts' pipelines, with the owner's own; absent, every one. */
|
|
47
|
+
accounts?: readonly AccountKey[];
|
|
48
|
+
}
|
|
49
|
+
export interface MappingFilter extends BaseScope {
|
|
50
|
+
kind?: DealKind;
|
|
51
|
+
/** `pipeline:<id>`, or a name only one pipeline has. */
|
|
52
|
+
pipeline?: string;
|
|
53
|
+
unconfirmed?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/** The base set of each kind, the mapping of every other pipeline's stages onto it, and moves by base stage. */
|
|
56
|
+
export interface BaseStagesStore {
|
|
57
|
+
/** The set with its board counts; the first use makes the default set and suggests every stage's mapping. */
|
|
58
|
+
show(kind: DealKind, scope?: BaseScope): Promise<BaseSet>;
|
|
59
|
+
/** Open stages go before the first won or lost one unless `position` says where. */
|
|
60
|
+
add(kind: DealKind, input: {
|
|
61
|
+
name: string;
|
|
62
|
+
outcome?: StageOutcome;
|
|
63
|
+
position?: number;
|
|
64
|
+
}): Promise<BaseSet>;
|
|
65
|
+
rename(kind: DealKind, stage: string, name: string): Promise<BaseSet>;
|
|
66
|
+
move(kind: DealKind, stage: string, position: number): Promise<BaseSet>;
|
|
67
|
+
/** Refused for the last stage of its outcome and for one the owner's own rows stand or stood in. */
|
|
68
|
+
remove(kind: DealKind, stage: string): Promise<BaseSet>;
|
|
69
|
+
mappings(filter?: MappingFilter): Promise<StageMapping[]>;
|
|
70
|
+
/** Maps `stage:<id>` onto a base stage of its kind, confirmed unless `confirmed: false` (an agent's suggestion). */
|
|
71
|
+
map(stage: string, base: string, scope?: BaseScope, options?: {
|
|
72
|
+
confirmed?: boolean;
|
|
73
|
+
}): Promise<StageMapping>;
|
|
74
|
+
/** Confirms every suggestion of one pipeline, or of all of them in scope; answers how many. */
|
|
75
|
+
confirm(target: {
|
|
76
|
+
pipeline: string;
|
|
77
|
+
} | {
|
|
78
|
+
all: true;
|
|
79
|
+
kind?: DealKind;
|
|
80
|
+
}, scope?: BaseScope): Promise<number>;
|
|
81
|
+
/**
|
|
82
|
+
* The stage of the row's own pipeline confirmed onto `base` (a base stage by `stage:<id>` or name), or `base` itself
|
|
83
|
+
* when it is a `stage:<id>` of that pipeline. Refused with `stage.choice-required` and the candidates when several
|
|
84
|
+
* are confirmed onto it, and with `stage.unmapped` when none is.
|
|
85
|
+
*/
|
|
86
|
+
resolve(item: string, base: string): Promise<{
|
|
87
|
+
stage: StageName & {
|
|
88
|
+
externalId: string | null;
|
|
89
|
+
outcome: StageOutcome;
|
|
90
|
+
};
|
|
91
|
+
}>;
|
|
92
|
+
}
|
|
93
|
+
export declare const baseStagesOver: (context: StoreContext) => {
|
|
94
|
+
show: (kind: DealKind, scope?: BaseScope) => BaseSet;
|
|
95
|
+
add: (kind: DealKind, input: {
|
|
96
|
+
name: string;
|
|
97
|
+
outcome?: StageOutcome;
|
|
98
|
+
position?: number;
|
|
99
|
+
}) => BaseSet;
|
|
100
|
+
rename: (kind: DealKind, stage: string, name: string) => BaseSet;
|
|
101
|
+
move: (kind: DealKind, stage: string, position: number) => BaseSet;
|
|
102
|
+
remove: (kind: DealKind, stage: string) => BaseSet;
|
|
103
|
+
mappings: (filter?: MappingFilter) => StageMapping[];
|
|
104
|
+
map: (stage: string, base: string, scope?: BaseScope, { confirmed }?: {
|
|
105
|
+
confirmed?: boolean;
|
|
106
|
+
}) => StageMapping;
|
|
107
|
+
confirm: (target: {
|
|
108
|
+
pipeline: string;
|
|
109
|
+
} | {
|
|
110
|
+
all: true;
|
|
111
|
+
kind?: DealKind;
|
|
112
|
+
}, scope?: BaseScope) => number;
|
|
113
|
+
resolve: (item: string, base: string) => {
|
|
114
|
+
stage: {
|
|
115
|
+
ref: string;
|
|
116
|
+
name: string;
|
|
117
|
+
externalId: string | null;
|
|
118
|
+
outcome: StageOutcome;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export declare const baseStagesStoreOver: (context: StoreContext) => BaseStagesStore;
|