@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.
- package/CHANGELOG.md +112 -0
- package/dist/cli/bot/people.js +1 -1
- package/dist/cli/messenger/contacts-command.js +6 -2
- package/dist/domain/display-names.d.ts +20 -2
- package/dist/domain/display-names.js +21 -2
- package/dist/entities/contact-activity.d.ts +2 -0
- package/dist/entities/contact-activity.js +2 -0
- package/dist/entities/contact-context.d.ts +3 -0
- package/dist/entities/index.d.ts +3 -0
- package/dist/errors/reasons.js +9 -0
- package/dist/search/groups.d.ts +2 -0
- package/dist/search/groups.js +1 -0
- package/dist/services/account-groups.d.ts +30 -1
- package/dist/services/account-groups.js +27 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/people.d.ts +5 -1
- package/dist/services/people.js +18 -5
- package/dist/services/stored-project-gathering.d.ts +2 -0
- package/dist/services/stored-project-gathering.js +1 -1
- package/dist/store/accounts.d.ts +10 -1
- package/dist/store/accounts.js +3 -2
- package/dist/store/chats.d.ts +5 -0
- package/dist/store/chats.js +6 -0
- package/dist/store/exports.d.ts +1 -1
- package/dist/store/identity-links.d.ts +23 -0
- package/dist/store/identity-splits.d.ts +2 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/keys.d.ts +1 -1
- package/dist/store/keys.js +1 -1
- package/dist/store/people.d.ts +17 -5
- package/dist/store/people.js +10 -3
- package/dist/store/sqlite/accounts.d.ts +12 -2
- package/dist/store/sqlite/accounts.js +42 -3
- package/dist/store/sqlite/address-organization.d.ts +18 -0
- package/dist/store/sqlite/address-organization.js +48 -0
- package/dist/store/sqlite/chats.d.ts +3 -1
- package/dist/store/sqlite/chats.js +8 -0
- package/dist/store/sqlite/identity-link-rows.d.ts +5 -1
- package/dist/store/sqlite/identity-link-rows.js +9 -3
- package/dist/store/sqlite/identity-proposals.d.ts +5 -3
- package/dist/store/sqlite/identity-proposals.js +85 -8
- package/dist/store/sqlite/identity-split-proposals.d.ts +5 -0
- package/dist/store/sqlite/identity-split-proposals.js +29 -1
- package/dist/store/sqlite/mail-findings.js +10 -44
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +14 -0
- package/dist/store/sqlite/name-traces.d.ts +5 -2
- package/dist/store/sqlite/name-traces.js +8 -5
- package/dist/store/sqlite/open-store.js +2 -0
- package/dist/store/sqlite/people-list.js +15 -9
- package/dist/store/sqlite/person-doubts.d.ts +15 -1
- package/dist/store/sqlite/person-doubts.js +51 -9
- package/dist/store/sqlite/person-links.d.ts +7 -2
- package/dist/store/sqlite/person-links.js +33 -2
- package/dist/store/sqlite/person-match-scan.d.ts +14 -0
- package/dist/store/sqlite/person-match-scan.js +101 -5
- package/dist/store/sqlite/person-merges.d.ts +1 -0
- package/dist/store/sqlite/person-merges.js +4 -8
- package/dist/store/sqlite/task-titles.d.ts +12 -1
- package/dist/store/sqlite/task-titles.js +42 -1
- package/dist/store/sqlite/tasks.js +6 -1
- package/dist/store/types.d.ts +6 -0
- package/package.json +3 -3
- package/parity.json +6 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { isEmailAddress, isRoleAddress } from "../../domain/addresses.js";
|
|
3
|
+
import { displayName, noFallbacks, takeFallbacks } from "../../domain/display-names.js";
|
|
3
4
|
import { and, eq, inArray, isNull, sql } from "./drizzle/core.js";
|
|
4
5
|
import { identityOf } from "./identities.js";
|
|
5
6
|
import { rejectedEvidence, settleLinks } from "./identity-link-rows.js";
|
|
@@ -61,7 +62,13 @@ export const recordOf = ({ orm }, personPk) => {
|
|
|
61
62
|
linkedAt: new Date(linkedAt).toISOString(),
|
|
62
63
|
};
|
|
63
64
|
});
|
|
64
|
-
|
|
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
|
+
};
|
|
65
72
|
};
|
|
66
73
|
/**
|
|
67
74
|
* A person by the uid a `person:` reference holds, with every identity linked to them. A uid merged into someone
|
|
@@ -262,8 +269,32 @@ export const renameAfterLeaving = (context, person, left) => {
|
|
|
262
269
|
.prepare("UPDATE persons SET name = ?, updated_at = ? WHERE id = ?")
|
|
263
270
|
.run(typeof kept === "string" ? kept : null, context.now(), person);
|
|
264
271
|
};
|
|
272
|
+
const shownAs = (person) => `${displayName(person.name, { name: person.identities.find((identity) => identity.name)?.name ?? null }) ?? "a person with no name"} (person:${person.uid})`;
|
|
273
|
+
/**
|
|
274
|
+
* Refuses identities that sit on anyone but `from` (a uid, or `person:<uid>` as doubts and refusals give it), so a
|
|
275
|
+
* caller that guessed the person never takes them off someone else. The refusal names who holds them.
|
|
276
|
+
*/
|
|
277
|
+
export const heldBy = (context, from, refs) => {
|
|
278
|
+
const uid = from.startsWith("person:") ? from.slice("person:".length) : from;
|
|
279
|
+
const found = /^[1-9]\d*$/.test(uid)
|
|
280
|
+
? context.database.prepare("SELECT id FROM persons WHERE id = ?").get(uid)
|
|
281
|
+
: undefined;
|
|
282
|
+
if (found === undefined)
|
|
283
|
+
throw new CliError("not_found", `no person:${uid} in the store`, { param: "from" });
|
|
284
|
+
const pk = currentPerson(context.database, Number(found.id));
|
|
285
|
+
for (const ref of refs) {
|
|
286
|
+
const row = required(context, ref);
|
|
287
|
+
if (row.personPk === pk)
|
|
288
|
+
continue;
|
|
289
|
+
const holder = recordOf(context, row.personPk);
|
|
290
|
+
throw new CliError("validation_error", `${ref.provider}:${ref.id} sits on ${shownAs(holder)}, not on ${shownAs(recordOf(context, pk))}; nothing changed. ` +
|
|
291
|
+
`Name person:${holder.uid} to take it off them`, { reason: "identity.held-elsewhere", param: "from", reference: `person:${holder.uid}` });
|
|
292
|
+
}
|
|
293
|
+
};
|
|
265
294
|
/** Gives the identity a person of its own again; the ones left keep theirs. */
|
|
266
295
|
export const unlinkIdentity = (context, ref, options) => {
|
|
296
|
+
if (options.from !== undefined)
|
|
297
|
+
heldBy(context, options.from, [ref]);
|
|
267
298
|
const found = required(context, ref);
|
|
268
299
|
const others = context.orm
|
|
269
300
|
.select({ n: sql `count(*)` })
|
|
@@ -279,7 +310,7 @@ export const unlinkIdentity = (context, ref, options) => {
|
|
|
279
310
|
.values({ name: named?.name ?? null, createdAt: at, updatedAt: at })
|
|
280
311
|
.returning({ pk: persons.id })
|
|
281
312
|
.get()?.pk);
|
|
282
|
-
move(context, found.pk, found.personPk, alone, {
|
|
313
|
+
move(context, found.pk, found.personPk, alone, { method: "unlink", by: options.by });
|
|
283
314
|
renameAfterLeaving(context, found.personPk, [found.pk]);
|
|
284
315
|
return recordOf(context, alone);
|
|
285
316
|
};
|
|
@@ -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
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isEmailAddress, isNoReplyAddress, isRoleAddress } from "../../domain/addresses.js";
|
|
2
|
+
import { variantKey } from "../../domain/name-variants.js";
|
|
2
3
|
import { BARE_INTERNATIONAL_PROVIDERS, storedPhone } from "../../domain/phones.js";
|
|
3
4
|
import { linkIndex, settleLinks } from "./identity-link-rows.js";
|
|
4
5
|
import { openIdentityLink } from "./identity-proposals.js";
|
|
@@ -15,6 +16,27 @@ export const RULE = { bot: "rule", kind: "rule" };
|
|
|
15
16
|
/** More people than this on one number or address is a shared line or mailbox: nobody is proposed from it. */
|
|
16
17
|
const MOST_SHARING = 6;
|
|
17
18
|
const CURSOR = "people.scan";
|
|
19
|
+
/** Raised when a rule changes what a pass finds in values nobody touched: the next pass then reads everything once. */
|
|
20
|
+
const RULES = 3;
|
|
21
|
+
/**
|
|
22
|
+
* NEED-2526: a shared mailbox says little alone, so its proposal is scored by what else the two people have in common.
|
|
23
|
+
* The role word itself does not move the score: the list does not tell a department's inbox from a company's.
|
|
24
|
+
*/
|
|
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
|
+
};
|
|
18
40
|
/**
|
|
19
41
|
* NEED-2445, safe option until the owner rules: a number two people share joins them only when a messenger, which
|
|
20
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.
|
|
@@ -54,10 +76,12 @@ const cursorNow = (database) => ({
|
|
|
54
76
|
revision: maxOf(database, "SELECT max(id) AS n FROM identity_revisions"),
|
|
55
77
|
participant: maxOf(database, "SELECT max(id) AS n FROM meeting_participants"),
|
|
56
78
|
at: maxOf(database, "SELECT max(updated_at) AS n FROM identities"),
|
|
79
|
+
rules: RULES,
|
|
57
80
|
});
|
|
58
81
|
const savedCursor = (database) => {
|
|
59
82
|
const value = database.prepare("SELECT value FROM store_settings WHERE key = ?").get(CURSOR)?.value;
|
|
60
|
-
|
|
83
|
+
const cursor = value === undefined ? undefined : JSON.parse(String(value));
|
|
84
|
+
return cursor?.rules === RULES ? cursor : undefined;
|
|
61
85
|
};
|
|
62
86
|
/** The identities changed since `since`: new ones, moved ones, edited ones and ones a new meeting guest row names. */
|
|
63
87
|
const changedSince = (database, since) => new Set(database
|
|
@@ -149,7 +173,15 @@ const join = (pass, sides, signal) => {
|
|
|
149
173
|
if (touchesOwner(pass, from, into, method))
|
|
150
174
|
return into;
|
|
151
175
|
if (index.rejected(from, into) !== undefined) {
|
|
152
|
-
propose(pass, {
|
|
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
|
+
});
|
|
153
185
|
return into;
|
|
154
186
|
}
|
|
155
187
|
const kept = mergePerson(context, from, into, { method, by: BY });
|
|
@@ -182,6 +214,7 @@ const propose = (pass, opening) => {
|
|
|
182
214
|
result.proposed.push({ id: opened.action.id, persons, signal: opening.signal, opened: opened.outcome === "proposed" });
|
|
183
215
|
};
|
|
184
216
|
const proposeEachPair = (pass, people, signal) => {
|
|
217
|
+
const score = people.size === 2 ? PROPOSAL_SCORE.ownPhone : PROPOSAL_SCORE.group;
|
|
185
218
|
const persons = [...people.keys()].sort((a, b) => a - b);
|
|
186
219
|
for (const [at, from] of persons.entries())
|
|
187
220
|
for (const to of persons.slice(at + 1))
|
|
@@ -193,6 +226,7 @@ const proposeEachPair = (pass, people, signal) => {
|
|
|
193
226
|
joins: "person",
|
|
194
227
|
signal,
|
|
195
228
|
candidates: persons,
|
|
229
|
+
score,
|
|
196
230
|
});
|
|
197
231
|
};
|
|
198
232
|
const tooMany = (pass, people, reason, signal) => {
|
|
@@ -218,9 +252,63 @@ const samePhone = (pass, holders) => {
|
|
|
218
252
|
else
|
|
219
253
|
proposeEachPair(pass, people, "phone");
|
|
220
254
|
};
|
|
255
|
+
const nameOf = ({ database }, person) => {
|
|
256
|
+
const name = database.prepare("SELECT name FROM persons WHERE id = ?").get(person)?.name;
|
|
257
|
+
return typeof name === "string" ? name : null;
|
|
258
|
+
};
|
|
259
|
+
const TRACE_WORDS = {
|
|
260
|
+
phone: "the same phone",
|
|
261
|
+
email: "another address only they have",
|
|
262
|
+
chat: "a chat they are both in",
|
|
263
|
+
"email-domain": "mail at the same company",
|
|
264
|
+
};
|
|
265
|
+
/** What two people on one shared mailbox have in common besides it, as a score and the words that say why. */
|
|
266
|
+
const sharedMailboxCase = (context, address, from, to) => {
|
|
267
|
+
const reasons = [`both have the shared mailbox ${address}`];
|
|
268
|
+
let score = SHARED_SCORE.alone;
|
|
269
|
+
const name = nameOf(context, from);
|
|
270
|
+
const key = variantKey(name);
|
|
271
|
+
if (key !== null && key === variantKey(nameOf(context, to))) {
|
|
272
|
+
score += SHARED_SCORE.name;
|
|
273
|
+
reasons.push(`the same name «${name}»`);
|
|
274
|
+
}
|
|
275
|
+
let evidence = [];
|
|
276
|
+
for (const trace of sharedTraces(context.database, from, to, name ?? "", address))
|
|
277
|
+
if (!(trace.kind === "email" && isRoleAddress(trace.value ?? "")) && strongEnough(context, from, to, trace)) {
|
|
278
|
+
score += trace.value === undefined ? SHARED_SCORE.weakTrace : SHARED_SCORE.trace;
|
|
279
|
+
reasons.push(TRACE_WORDS[trace.kind]);
|
|
280
|
+
evidence = trace.evidence;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
return { score: Math.round(score * 10) / 10, reason: reasons.join("; "), evidence };
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* NEED-2526: a shared mailbox never joins anyone (SEC-177), but each pair on it is proposed to the owner, scored by
|
|
287
|
+
* what else they share.
|
|
288
|
+
*/
|
|
289
|
+
const proposeShared = (pass, { address, holders, shared }) => {
|
|
290
|
+
const people = peopleOf(pass.context, holders);
|
|
291
|
+
if (people.size < 2)
|
|
292
|
+
return;
|
|
293
|
+
const persons = [...people.keys()].sort((a, b) => a - b);
|
|
294
|
+
for (const [at, from] of persons.entries())
|
|
295
|
+
for (const to of persons.slice(at + 1))
|
|
296
|
+
propose(pass, {
|
|
297
|
+
identity: people.get(from),
|
|
298
|
+
with: people.get(to),
|
|
299
|
+
from,
|
|
300
|
+
to,
|
|
301
|
+
joins: "person",
|
|
302
|
+
signal: "email",
|
|
303
|
+
candidates: persons,
|
|
304
|
+
shared,
|
|
305
|
+
mailbox: address,
|
|
306
|
+
...sharedMailboxCase(pass.context, address, from, to),
|
|
307
|
+
});
|
|
308
|
+
};
|
|
221
309
|
/**
|
|
222
310
|
* One address is one person in any scope (NEED-2382), unless more than two people have it (NEED-2446). A no-reply
|
|
223
|
-
* address is no one's
|
|
311
|
+
* address is no one's. A role address such as `info@` and a company's mailbox only propose (NEED-2526).
|
|
224
312
|
*/
|
|
225
313
|
const sameEmail = (pass, address, holders) => {
|
|
226
314
|
if (isNoReplyAddress(address))
|
|
@@ -228,8 +316,11 @@ const sameEmail = (pass, address, holders) => {
|
|
|
228
316
|
const people = peopleOf(pass.context, holders);
|
|
229
317
|
if (people.size < 2 || tooMany(pass, people, "identity.shared-email", "email"))
|
|
230
318
|
return;
|
|
231
|
-
|
|
232
|
-
|
|
319
|
+
const role = isRoleAddress(address);
|
|
320
|
+
if (role || sharedLine(pass.context, holders)) {
|
|
321
|
+
pass.shared.push({ address, holders, shared: role ? "role" : "line" });
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
233
324
|
if (!addressGroupJoins(people.size))
|
|
234
325
|
return proposeEachPair(pass, people, "email");
|
|
235
326
|
const contact = holders.find(({ provider }) => provider === "email");
|
|
@@ -288,6 +379,7 @@ const sameName = (pass, people, name) => {
|
|
|
288
379
|
to,
|
|
289
380
|
joins: "person",
|
|
290
381
|
signal: "name",
|
|
382
|
+
score: trace.value === undefined ? PROPOSAL_SCORE.nameAndPlace : PROPOSAL_SCORE.nameAndOwnTrace,
|
|
291
383
|
evidence: trace.evidence,
|
|
292
384
|
reason: trace.reason,
|
|
293
385
|
});
|
|
@@ -311,6 +403,7 @@ const guestEmail = (pass, row) => {
|
|
|
311
403
|
to: others[0],
|
|
312
404
|
joins: "identity",
|
|
313
405
|
signal: "guest-email",
|
|
406
|
+
score: PROPOSAL_SCORE.guestEmail,
|
|
314
407
|
...(meeting === undefined ? {} : { evidence: [meeting] }),
|
|
315
408
|
});
|
|
316
409
|
};
|
|
@@ -343,6 +436,7 @@ export const scanMatches = (context, { full = false } = {}) => {
|
|
|
343
436
|
context,
|
|
344
437
|
index: linkIndex(database),
|
|
345
438
|
result: { full: changed === undefined, merged: [], proposed: [], skipped: [] },
|
|
439
|
+
shared: [],
|
|
346
440
|
};
|
|
347
441
|
for (const [address, holders] of emailHolders(database))
|
|
348
442
|
if (holders.length > 1 && touched(holders))
|
|
@@ -350,6 +444,8 @@ export const scanMatches = (context, { full = false } = {}) => {
|
|
|
350
444
|
for (const holders of phoneHolders(database).values())
|
|
351
445
|
if (holders.length > 1 && touched(holders))
|
|
352
446
|
write(database, () => samePhone(pass, holders));
|
|
447
|
+
for (const group of pass.shared)
|
|
448
|
+
write(database, () => proposeShared(pass, group));
|
|
353
449
|
for (const row of guestRows(database))
|
|
354
450
|
if ((changed === undefined || changed.has(row.identity)) && !pass.index.names(row.ref))
|
|
355
451
|
write(database, () => guestEmail(pass, row));
|
|
@@ -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.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { currentPerson, mergeSql, SEPARATIONS } from "./merged-persons.js";
|
|
3
|
-
import { move, recordOf, renameAfterLeaving, required } from "./person-links.js";
|
|
3
|
+
import { heldBy, move, recordOf, renameAfterLeaving, required } from "./person-links.js";
|
|
4
4
|
import { persons } from "./schema.js";
|
|
5
5
|
export const mergeId = (to, from) => `merge:${to}-${from}`;
|
|
6
6
|
/** The two uids a `merge:<to>-<from>` id names. */
|
|
@@ -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
|
};
|
|
@@ -116,12 +116,8 @@ export const split = (context, uid, refs, by) => {
|
|
|
116
116
|
const chosen = [...new Map(refs.map((ref) => [`${ref.provider}:${ref.id}`, ref])).values()];
|
|
117
117
|
if (chosen.length === 0)
|
|
118
118
|
throw new CliError("validation_error", "name at least one identity to split off");
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (row.personPk !== person)
|
|
122
|
-
throw new CliError("validation_error", `${ref.provider}:${ref.id} is not an identity of person:${person}`);
|
|
123
|
-
return row;
|
|
124
|
-
});
|
|
119
|
+
heldBy(context, uid, chosen);
|
|
120
|
+
const found = chosen.map((ref) => required(context, ref));
|
|
125
121
|
if (found.length === recordOf(context, person).identities.length)
|
|
126
122
|
throw new CliError("validation_error", "a split leaves at least one identity with the person");
|
|
127
123
|
const at = context.now();
|
|
@@ -6,7 +6,18 @@ export declare const placeholderTitleOf: (row: Row) => string;
|
|
|
6
6
|
export declare const PLACEHOLDER_TITLE_SQL = "title = type || ' \u2014 ' || coalesce(source_locator, '')";
|
|
7
7
|
/**
|
|
8
8
|
* What to show as a task's title: the first line of its source message while the stored title is still the
|
|
9
|
-
* placeholder, the stored title otherwise.
|
|
9
|
+
* placeholder, the stored title otherwise. A found task stores it when it is found, and store version 65 stored it for
|
|
10
|
+
* the tasks found before; read time covers a task found before its message was saved.
|
|
10
11
|
*/
|
|
11
12
|
export declare const displayTitleOf: (database: CacheDatabase, row: Row) => string;
|
|
13
|
+
/** Set by store version 65 and deleted once every found task's title is stored. */
|
|
14
|
+
export declare const FOUND_TASK_TITLES_TO_FILL = "found_task_titles_to_fill";
|
|
15
|
+
/**
|
|
16
|
+
* Stores the title `displayTitleOf` shows for each live found task still titled `<kind> — <source>`, so it stays
|
|
17
|
+
* when the message is deleted. One short write per batch; a task whose message is missing, deleted or empty keeps
|
|
18
|
+
* its title. A failure keeps the key for the next open and only warns.
|
|
19
|
+
*/
|
|
20
|
+
export declare const fillFoundTaskTitles: (database: CacheDatabase, warn: (line: string) => void, { batch }?: {
|
|
21
|
+
batch?: number;
|
|
22
|
+
}) => number;
|
|
12
23
|
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { isLocator } from "../../domain/locator.js";
|
|
2
|
+
import { folded } from "./folded.js";
|
|
2
3
|
import { thingOf } from "./things.js";
|
|
4
|
+
import { writeBatch } from "./transaction.js";
|
|
3
5
|
const MAX_TITLE = 120;
|
|
4
6
|
/** The title a rule gives a task it finds in a message: no message text is stored, so it is only a reference. */
|
|
5
7
|
export const placeholderTitleOf = (row) => `${String(row.type)} — ${String(row.source_locator ?? "")}`;
|
|
@@ -20,7 +22,8 @@ const firstLine = (text) => {
|
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* What to show as a task's title: the first line of its source message while the stored title is still the
|
|
23
|
-
* placeholder, the stored title otherwise.
|
|
25
|
+
* placeholder, the stored title otherwise. A found task stores it when it is found, and store version 65 stored it for
|
|
26
|
+
* the tasks found before; read time covers a task found before its message was saved.
|
|
24
27
|
*/
|
|
25
28
|
export const displayTitleOf = (database, row) => {
|
|
26
29
|
const stored = String(row.title);
|
|
@@ -40,3 +43,41 @@ export const displayTitleOf = (database, row) => {
|
|
|
40
43
|
return stored;
|
|
41
44
|
}
|
|
42
45
|
};
|
|
46
|
+
/** Set by store version 65 and deleted once every found task's title is stored. */
|
|
47
|
+
export const FOUND_TASK_TITLES_TO_FILL = "found_task_titles_to_fill";
|
|
48
|
+
/**
|
|
49
|
+
* Stores the title `displayTitleOf` shows for each live found task still titled `<kind> — <source>`, so it stays
|
|
50
|
+
* when the message is deleted. One short write per batch; a task whose message is missing, deleted or empty keeps
|
|
51
|
+
* its title. A failure keeps the key for the next open and only warns.
|
|
52
|
+
*/
|
|
53
|
+
export const fillFoundTaskTitles = (database, warn, { batch = 500 } = {}) => {
|
|
54
|
+
if (!database.prepare("SELECT 1 AS found FROM store_settings WHERE key = ?").get(FOUND_TASK_TITLES_TO_FILL))
|
|
55
|
+
return 0;
|
|
56
|
+
const next = database.prepare("SELECT id, type, title, source_locator FROM tasks WHERE id > ? AND package_id IS NOT NULL AND deleted_at IS NULL " +
|
|
57
|
+
`AND source_locator LIKE 'msg:%' AND ${PLACEHOLDER_TITLE_SQL} ORDER BY id LIMIT ?`);
|
|
58
|
+
const store = database.prepare(`UPDATE tasks SET title = ?, title_folded = ? WHERE id = ? AND ${PLACEHOLDER_TITLE_SQL}`);
|
|
59
|
+
let filled = 0;
|
|
60
|
+
let after = 0;
|
|
61
|
+
try {
|
|
62
|
+
for (;;) {
|
|
63
|
+
const rows = writeBatch(database, () => {
|
|
64
|
+
const page = next.all(after, batch);
|
|
65
|
+
for (const row of page) {
|
|
66
|
+
const title = displayTitleOf(database, row);
|
|
67
|
+
if (title !== String(row.title))
|
|
68
|
+
filled += store.run(title, folded(title), Number(row.id)).changes;
|
|
69
|
+
}
|
|
70
|
+
if (page.length < batch)
|
|
71
|
+
database.prepare("DELETE FROM store_settings WHERE key = ?").run(FOUND_TASK_TITLES_TO_FILL);
|
|
72
|
+
return page;
|
|
73
|
+
});
|
|
74
|
+
if (rows.length < batch)
|
|
75
|
+
return filled;
|
|
76
|
+
after = Number(rows.at(-1)?.id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
warn(`could not store the titles of found tasks; the next open tries again: ${String(error)}`);
|
|
81
|
+
return filled;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
@@ -161,12 +161,17 @@ export const taskStoreOver = (context) => {
|
|
|
161
161
|
const key = typedKey(database, task.kind);
|
|
162
162
|
const author = actorOfOrigin(database, task.origin);
|
|
163
163
|
const closedBy = task.closedBy ? actorOfOrigin(database, task.closedBy) : undefined;
|
|
164
|
+
const title = displayTitleOf(database, {
|
|
165
|
+
type: task.kind,
|
|
166
|
+
title: `${task.kind} — ${task.source}`,
|
|
167
|
+
source_locator: task.source,
|
|
168
|
+
});
|
|
164
169
|
const made = database
|
|
165
170
|
.prepare("INSERT INTO tasks (project_id, number, key, title, type, status, due_at, closed_at, closed_by_type, closed_by_id, " +
|
|
166
171
|
"close_reason, author_type, author_id, source, package_id, source_locator, source_kind, source_group, created_at, updated_at, " +
|
|
167
172
|
"title_folded, close_reason_folded, category) " +
|
|
168
173
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id")
|
|
169
|
-
.get(project, number, key,
|
|
174
|
+
.get(project, number, key, title, task.kind, task.state, time(task.dueAt), time(task.closedAt), closedBy?.type ?? null, closedBy?.id ?? null, task.reason ?? null, author.type, author.id, task.origin, task.id, task.source, task.sourceKind, task.group, task.createdAt.getTime(), now(), folded(title), folded(task.reason), task.category ?? null);
|
|
170
175
|
recordTaskEvent(database, Number(made?.id), author, "created", null, task.createdAt.getTime());
|
|
171
176
|
});
|
|
172
177
|
},
|
package/dist/store/types.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export interface LinkOptions {
|
|
|
47
47
|
method: string;
|
|
48
48
|
by: string;
|
|
49
49
|
}
|
|
50
|
+
export interface UnlinkOptions extends LinkOptions {
|
|
51
|
+
/** The uid of the person the identity is taken from; refused when it sits on someone else. */
|
|
52
|
+
from?: string;
|
|
53
|
+
}
|
|
50
54
|
export interface LinkedIdentity extends IdentityRef {
|
|
51
55
|
name: string | null;
|
|
52
56
|
username: string | null;
|
|
@@ -69,6 +73,8 @@ export interface LinkedIdentity extends IdentityRef {
|
|
|
69
73
|
export interface PersonRecord {
|
|
70
74
|
uid: string;
|
|
71
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;
|
|
72
78
|
identities: LinkedIdentity[];
|
|
73
79
|
/** Set when the uid asked for was merged away: the uid of the person its identities are now, the same as `uid`. */
|
|
74
80
|
mergedInto?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "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":
|
|
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.
|
|
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": "<
|
|
446
|
-
"meaning": "
|
|
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"
|