@wirecat/cli-core 1.0.0-rc.0 → 1.0.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 +97 -0
- package/THIRD_PARTY_NOTICES +4 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/cli/account-rename.js +1 -1
- package/dist/cli/bot/api-input.d.ts +5 -0
- package/dist/cli/bot/api-input.js +6 -1
- package/dist/cli/bot/api.js +7 -1
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/service-api.js +3 -1
- package/dist/crm/manifest/map.d.ts +5 -2
- package/dist/crm/manifest/map.js +14 -2
- package/dist/domain/organization-sectors.d.ts +10 -0
- package/dist/domain/organization-sectors.generated.d.ts +11 -0
- package/dist/domain/organization-sectors.generated.js +14 -0
- package/dist/domain/organization-sectors.js +9 -0
- package/dist/domain/person-kinds.d.ts +1 -1
- package/dist/entities/index.d.ts +1 -0
- package/dist/entities/knowledge-lists.d.ts +1 -0
- package/dist/entities/knowledge-lists.js +2 -0
- package/dist/errors/reasons.js +12 -3
- package/dist/mail/score.d.ts +2 -0
- package/dist/mail/score.js +9 -2
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/search-all-rank.d.ts +44 -0
- package/dist/services/search-all-rank.js +112 -0
- package/dist/services/search-all-tracker.d.ts +58 -0
- package/dist/services/search-all-tracker.js +155 -0
- package/dist/services/search-all.d.ts +1 -8
- package/dist/services/search-all.js +18 -199
- package/dist/services/tracker-meaning.js +1 -1
- package/dist/store/areas.d.ts +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/people.d.ts +22 -1
- package/dist/store/people.js +15 -1
- package/dist/store/sqlite/domain-organizations.d.ts +33 -0
- package/dist/store/sqlite/domain-organizations.js +230 -0
- package/dist/store/sqlite/knowledge.d.ts +2 -9
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +21 -0
- package/dist/store/sqlite/organizations.d.ts +12 -1
- package/dist/store/sqlite/organizations.js +9 -1
- package/dist/store/sqlite/people-list.d.ts +6 -1
- package/dist/store/sqlite/people-list.js +66 -14
- package/dist/store/sqlite/person-match-scan.js +11 -1
- package/dist/store/sqlite/schema/sender-bots.d.ts +288 -0
- package/dist/store/sqlite/schema/sender-bots.js +22 -0
- package/dist/store/sqlite/schema.d.ts +1 -0
- package/dist/store/sqlite/schema.js +2 -0
- package/dist/store/sqlite/sender-bots.d.ts +43 -0
- package/dist/store/sqlite/sender-bots.js +189 -0
- package/dist/store/sqlite/sender-signals.d.ts +5 -2
- package/dist/store/sqlite/sender-signals.js +6 -6
- package/dist/store/sqlite/tracker.d.ts +11 -9
- package/dist/store/sqlite/tracker.js +27 -12
- package/dist/store/sqlite/work-tasks.js +2 -0
- package/dist/tracker/cli/index.d.ts +1 -1
- package/dist/tracker/cli/index.js +83 -24
- package/dist/tracker/sync.js +43 -20
- package/dist/tracker/writes.d.ts +28 -0
- package/dist/tracker/writes.js +141 -19
- package/package.json +3 -3
|
@@ -6,7 +6,7 @@ import { type MeetingProjectsStore } from "./meeting-projects.js";
|
|
|
6
6
|
import type { Author } from "./memories.js";
|
|
7
7
|
import { type Link } from "./notes.js";
|
|
8
8
|
import type { StoreContext } from "./open.js";
|
|
9
|
-
import { type OrganizationsStore } from "./organizations.js";
|
|
9
|
+
import { type Organization, type OrganizationsStore } from "./organizations.js";
|
|
10
10
|
import type { ProposedAction } from "./proposed-actions.js";
|
|
11
11
|
import { type KnowledgeRelation, type LinkDecision, type RelateInput, type RelationUpdate, type Scored } from "./relation-proposals.js";
|
|
12
12
|
import { type RelationReads } from "./relation-reads.js";
|
|
@@ -74,14 +74,7 @@ export interface Annotation {
|
|
|
74
74
|
export declare const ORGANIZATION_KINDS: readonly ["company", "team", "family", "community"];
|
|
75
75
|
export declare const PROJECT_TYPES: readonly ["work", "client", "personal", "oss", "other"];
|
|
76
76
|
export declare const SCOPES: readonly ["personal", "work"];
|
|
77
|
-
export
|
|
78
|
-
id: string;
|
|
79
|
-
ref: string;
|
|
80
|
-
kind: (typeof ORGANIZATION_KINDS)[number];
|
|
81
|
-
name: string;
|
|
82
|
-
scope: (typeof SCOPES)[number];
|
|
83
|
-
createdAt: string;
|
|
84
|
-
}
|
|
77
|
+
export type { Organization } from "./organizations.js";
|
|
85
78
|
export interface Project {
|
|
86
79
|
id: string;
|
|
87
80
|
ref: string;
|
|
@@ -247,6 +247,8 @@ export const MANIFEST = [
|
|
|
247
247
|
{ name: "20261123022342_version-72-document-history", version: 72, minCompatible: 56 },
|
|
248
248
|
{ name: "20261123022347_version-72-document-changes-trigger", version: 72, minCompatible: 56 },
|
|
249
249
|
{ name: "20261123230507_version-73-autoincrement", version: 73, minCompatible: 73, tables: V73_TABLES },
|
|
250
|
+
{ name: "20261125025700_version-74-sender-bots", version: 74, minCompatible: 73 },
|
|
251
|
+
{ name: "20261125025709_version-74-sender-bot-triggers", version: 74, minCompatible: 73 },
|
|
250
252
|
];
|
|
251
253
|
export const generatedMigrations = (manifest = MANIFEST, generated = GENERATED) => {
|
|
252
254
|
const migrations = [];
|
|
@@ -2093,5 +2093,26 @@ export const GENERATED = [
|
|
|
2093
2093
|
"CREATE INDEX `transaction_splits_by_category_folded` ON `transaction_splits` (`category_folded`);",
|
|
2094
2094
|
"CREATE INDEX `transaction_splits_by_project_id` ON `transaction_splits` (`project_id`);"
|
|
2095
2095
|
]
|
|
2096
|
+
},
|
|
2097
|
+
{
|
|
2098
|
+
"name": "20261125025700_version-74-sender-bots",
|
|
2099
|
+
"statements": [
|
|
2100
|
+
"CREATE TABLE `sender_bot_moves` (\n\t`id` integer PRIMARY KEY AUTOINCREMENT,\n\t`identity_id` integer NOT NULL,\n\t`from_person_id` integer,\n\t`from_bot_id` integer,\n\t`to_person_id` integer,\n\t`to_bot_id` integer,\n\t`author` text NOT NULL,\n\t`reason` text,\n\t`created_at` integer NOT NULL\n);",
|
|
2101
|
+
"CREATE TABLE `sender_bots` (\n\t`id` integer PRIMARY KEY AUTOINCREMENT,\n\t`person_id` integer NOT NULL UNIQUE,\n\t`name` text,\n\t`organization_id` integer,\n\t`author` text NOT NULL,\n\t`reason` text,\n\t`created_at` integer NOT NULL,\n\t`updated_at` integer NOT NULL\n);",
|
|
2102
|
+
"CREATE INDEX `emails_by_list_id` ON `emails` (coalesce(json_extract(headers, '$.\"list-id\"'), json_extract(metadata, '$.listId')));",
|
|
2103
|
+
"CREATE INDEX `sender_bot_moves_by_identity_id` ON `sender_bot_moves` (`identity_id`);"
|
|
2104
|
+
]
|
|
2105
|
+
},
|
|
2106
|
+
{
|
|
2107
|
+
"name": "20261125025709_version-74-sender-bot-triggers",
|
|
2108
|
+
"statements": [
|
|
2109
|
+
"-- No foreign keys on the bot tables, so an older build that erases a person or an organization, or purges an account,\n-- still can; these drop or clear their rows with it.\nCREATE TRIGGER sender_bots_person_ad AFTER DELETE ON persons BEGIN\n DELETE FROM sender_bots WHERE person_id = OLD.id;\nEND;",
|
|
2110
|
+
"CREATE TRIGGER sender_bots_organization_ad AFTER DELETE ON organizations BEGIN\n UPDATE sender_bots SET organization_id = NULL WHERE organization_id = OLD.id;\nEND;",
|
|
2111
|
+
"CREATE TRIGGER sender_bot_moves_identity_ad AFTER DELETE ON identities BEGIN\n DELETE FROM sender_bot_moves WHERE identity_id = OLD.id;\nEND;",
|
|
2112
|
+
"CREATE TRIGGER person_kind_sender_bot_ai AFTER INSERT ON sender_bots BEGIN\n UPDATE persons SET kind = NULL WHERE kind IS NOT NULL AND id = NEW.person_id;\nEND;",
|
|
2113
|
+
"CREATE TRIGGER person_kind_sender_bot_ad AFTER DELETE ON sender_bots BEGIN\n UPDATE persons SET kind = NULL WHERE kind IS NOT NULL AND id = OLD.person_id;\nEND;",
|
|
2114
|
+
"CREATE TRIGGER person_kind_sender_bot_au AFTER UPDATE OF person_id, author, name ON sender_bots BEGIN\n UPDATE persons SET kind = NULL WHERE kind IS NOT NULL AND id IN (OLD.person_id, NEW.person_id);\nEND;",
|
|
2115
|
+
"CREATE TRIGGER person_kind_sender_bot_move_ai AFTER INSERT ON sender_bot_moves BEGIN\n UPDATE persons SET kind = NULL WHERE kind IS NOT NULL AND id IN (SELECT person_id FROM identity_links WHERE identity_id = NEW.identity_id);\nEND;"
|
|
2116
|
+
]
|
|
2096
2117
|
}
|
|
2097
2118
|
];
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { type QueryAst } from "@wirecat/cli-base/query";
|
|
2
|
+
import type { Sector } from "../../domain/organization-sectors.js";
|
|
2
3
|
import type { Decider } from "../decisions.js";
|
|
3
|
-
import type {
|
|
4
|
+
import type { ORGANIZATION_KINDS, SCOPES } from "./knowledge.js";
|
|
4
5
|
import type { StoreContext } from "./open.js";
|
|
5
6
|
import { type OrganizationFilter } from "./organization-categories.js";
|
|
6
7
|
import { type OrganizationErasure } from "./organization-erase.js";
|
|
7
8
|
type Row = Record<string, unknown>;
|
|
9
|
+
export interface Organization {
|
|
10
|
+
id: string;
|
|
11
|
+
ref: string;
|
|
12
|
+
kind: (typeof ORGANIZATION_KINDS)[number];
|
|
13
|
+
name: string;
|
|
14
|
+
scope: (typeof SCOPES)[number];
|
|
15
|
+
/** What it does, from the company domains it holds (`domain-organizations.ts`); none for most. */
|
|
16
|
+
sector: Sector | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
}
|
|
8
19
|
export declare const organizationOf: (row: Row) => Organization;
|
|
9
20
|
export interface OrganizationsStore {
|
|
10
21
|
/** At most 500, by name; with `filter.category`, only that category's, chosen in SQL. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { evaluate, timezoneOf, walkQuery } from "@wirecat/cli-base/query";
|
|
3
3
|
import { ORGANIZATIONS_QUERY } from "../knowledge-query.js";
|
|
4
|
+
import { refuseDomainsOf } from "./domain-organizations.js";
|
|
4
5
|
import { categorySql } from "./organization-categories.js";
|
|
5
6
|
import { eraseOrganization } from "./organization-erase.js";
|
|
6
7
|
import { queryFilter } from "./query-filter.js";
|
|
@@ -12,10 +13,17 @@ export const organizationOf = (row) => ({
|
|
|
12
13
|
kind: row.kind,
|
|
13
14
|
name: String(row.name),
|
|
14
15
|
scope: row.scope,
|
|
16
|
+
sector: JSON.parse(String(row.metadata ?? "{}")).sector ?? null,
|
|
15
17
|
createdAt: new Date(Number(row.created_at)).toISOString(),
|
|
16
18
|
});
|
|
17
19
|
export const organizationsStoreOver = (context) => ({
|
|
18
|
-
eraseOrganization: async (organization, by, { apply }) => write(context.database, () =>
|
|
20
|
+
eraseOrganization: async (organization, by, { apply }) => write(context.database, () => {
|
|
21
|
+
const id = Number(/([1-9]\d*)$/u.exec(organization.trim())?.[1]);
|
|
22
|
+
// Read before the erase takes the addresses; kept only if the erase goes through.
|
|
23
|
+
if (apply && Number.isInteger(id))
|
|
24
|
+
refuseDomainsOf(context.database, id, context.now());
|
|
25
|
+
return eraseOrganization(context, organization, by, apply);
|
|
26
|
+
}),
|
|
19
27
|
...organizationsReadsOver(context),
|
|
20
28
|
});
|
|
21
29
|
const organizationsReadsOver = ({ database, now }) => ({
|
|
@@ -38,8 +38,13 @@ export interface ListedPerson {
|
|
|
38
38
|
messagesFrom: number;
|
|
39
39
|
/** The newest of their messages, their mail and their one-to-one chat's last message, as ISO time. */
|
|
40
40
|
lastContact: string | null;
|
|
41
|
-
/** Why they are shown; empty for someone hidden by default. */
|
|
41
|
+
/** Why they are shown; empty for someone hidden by default, and for a bot. */
|
|
42
42
|
ties: ShownBecause[];
|
|
43
|
+
/**
|
|
44
|
+
* The sender bot this row is (`sender-bot:<id>`), listed as `automated` under its person row's ref; `null` for a
|
|
45
|
+
* person.
|
|
46
|
+
*/
|
|
47
|
+
bot: string | null;
|
|
43
48
|
/** How their messages reached the owner (`senderSignalsOf`); `null` when nothing says. Worked out for the page. */
|
|
44
49
|
reach: Reach | null;
|
|
45
50
|
/** What their mail and addresses show about who writes and how it reached the owner. Worked out for the page. */
|
|
@@ -5,8 +5,10 @@ import { spellings, variantKey } from "../../domain/name-variants.js";
|
|
|
5
5
|
import { isAutomatedName, isCompanyName, PERSON_KINDS, } from "../../domain/person-kinds.js";
|
|
6
6
|
import { isQueryOnly } from "../driver.js";
|
|
7
7
|
import { fold } from "../normalize.js";
|
|
8
|
+
import { groupByDomain } from "./domain-organizations.js";
|
|
8
9
|
import { mergedAwaySql } from "./merged-persons.js";
|
|
9
10
|
import { ALWAYS_SHOWN, shownReasons } from "./person-ties.js";
|
|
11
|
+
import { ownerPeopleOf, ruleMove, SENDER_BOT_PREFIX, senderBotsOf } from "./sender-bots.js";
|
|
10
12
|
import { senderSignalsOf, sentMailOf } from "./sender-signals.js";
|
|
11
13
|
import { mergedAssignees } from "./task-board.js";
|
|
12
14
|
import { hiddenTestPeople } from "./test-people.js";
|
|
@@ -108,6 +110,8 @@ const factsOf = (database, scope) => {
|
|
|
108
110
|
organization: false,
|
|
109
111
|
twoWay: false,
|
|
110
112
|
messages: 0,
|
|
113
|
+
identities: held.length,
|
|
114
|
+
programIdentities: 0,
|
|
111
115
|
};
|
|
112
116
|
const source = (row) => ({
|
|
113
117
|
provider: String(row.provider),
|
|
@@ -129,6 +133,8 @@ const factsOf = (database, scope) => {
|
|
|
129
133
|
one.organization ||= owned.has(identity);
|
|
130
134
|
one.twoWay ||= twoWay.has(identity);
|
|
131
135
|
one.messages += messages.get(identity) ?? 0;
|
|
136
|
+
if (Number(row.bot) === 1 || (email !== null && (isNoReplyAddress(email) || isNotificationAddress(email))))
|
|
137
|
+
one.programIdentities += 1;
|
|
132
138
|
}
|
|
133
139
|
const contact = noFallbacks();
|
|
134
140
|
// Stable: equal counts keep the identities' stored order.
|
|
@@ -156,13 +162,19 @@ const lastContacts = (database, scope) => new Map(database
|
|
|
156
162
|
.map((row) => [Number(row.person), Number(row.at)]));
|
|
157
163
|
/** One misfiled letter is no newsletter. */
|
|
158
164
|
const BULK_MIN = 3;
|
|
165
|
+
/** A program writes: enough to move a sender to a bot. A name or a bulk mailbox alone may be a human's newsletter. */
|
|
166
|
+
const PROGRAM_SIGNALS = [
|
|
167
|
+
"bot",
|
|
168
|
+
"no-reply",
|
|
169
|
+
"notification-address",
|
|
170
|
+
"auto-submitted",
|
|
171
|
+
"null-return-path",
|
|
172
|
+
"bulk-never-replied",
|
|
173
|
+
];
|
|
159
174
|
/** The first rule that holds; the list's contract in the people-clients-digests plan names the same order. */
|
|
160
|
-
const kindOf = (shown, facts, ties, mail, test) => {
|
|
175
|
+
const kindOf = (shown, facts, ties, mail, test, held) => {
|
|
161
176
|
if (test)
|
|
162
177
|
return { kind: "test", signals: ["test-data"] };
|
|
163
|
-
const always = ties.filter((tie) => ALWAYS_SHOWN.includes(tie));
|
|
164
|
-
if (always.length > 0)
|
|
165
|
-
return { kind: "person", signals: ties };
|
|
166
178
|
const emails = facts?.emails ?? [];
|
|
167
179
|
const automated = [
|
|
168
180
|
...(facts?.bot ? ["bot"] : []),
|
|
@@ -177,8 +189,13 @@ const kindOf = (shown, facts, ties, mail, test) => {
|
|
|
177
189
|
? ["null-return-path"]
|
|
178
190
|
: []),
|
|
179
191
|
];
|
|
192
|
+
if (held === "bot")
|
|
193
|
+
return { kind: "automated", signals: automated.length > 0 ? automated : ["owner-choice"] };
|
|
194
|
+
const always = ties.filter((tie) => ALWAYS_SHOWN.includes(tie));
|
|
195
|
+
if (always.length > 0)
|
|
196
|
+
return { kind: "person", signals: ties };
|
|
180
197
|
// One mailbox's newsletter signal must not hide someone the owner talks to in a private chat.
|
|
181
|
-
if (automated.length > 0 && (facts?.bot || !facts?.twoWay))
|
|
198
|
+
if (held !== "person" && automated.length > 0 && (facts?.bot || !facts?.twoWay))
|
|
182
199
|
return { kind: "automated", signals: automated };
|
|
183
200
|
const organization = [
|
|
184
201
|
...(facts?.organization ? ["organization"] : []),
|
|
@@ -195,10 +212,22 @@ const kindOf = (shown, facts, ties, mail, test) => {
|
|
|
195
212
|
return { kind: "stranger", signals: ["no-tie"] };
|
|
196
213
|
return { kind: "person", signals: ties };
|
|
197
214
|
};
|
|
215
|
+
/**
|
|
216
|
+
* A program's signal the owner never wrote against, on a person whose every identity is the program's: a person who
|
|
217
|
+
* also has a human's identity linked stays a person with the mark.
|
|
218
|
+
*/
|
|
219
|
+
const isProgram = ({ kind, signals }, facts, ties) => kind === "automated" &&
|
|
220
|
+
facts !== undefined &&
|
|
221
|
+
signals.some((signal) => PROGRAM_SIGNALS.includes(signal)) &&
|
|
222
|
+
(facts.bot || (!facts.twoWay && !ties.includes("mail"))) &&
|
|
223
|
+
(facts.identities === 1 || facts.programIdentities === facts.identities);
|
|
224
|
+
const moveOf = (bot, program) => bot === undefined ? (program ? "bot" : undefined) : bot.author === "rules" && !program ? "person" : undefined;
|
|
198
225
|
/** Each person with their kind, contact and counts; the last contact is added for the page alone. */
|
|
199
226
|
const classified = (database, people, scope, reasons = shownReasons(database, scope === "all" ? undefined : scope)) => {
|
|
200
227
|
const facts = factsOf(database, scope);
|
|
201
228
|
const test = hiddenTestPeople(database);
|
|
229
|
+
const bots = senderBotsOf(database);
|
|
230
|
+
const ownerPeople = ownerPeopleOf(database);
|
|
202
231
|
const tasks = countsOf(database, TASK_COUNTS, mergedAssignees(database));
|
|
203
232
|
const mail = new Map(database
|
|
204
233
|
.prepare(MAIL_COUNTS(scope))
|
|
@@ -212,22 +241,29 @@ const classified = (database, people, scope, reasons = shownReasons(database, sc
|
|
|
212
241
|
const contact = { username: own?.username ?? null, phone: own?.phone ?? null, email: own?.email ?? null };
|
|
213
242
|
const shown = displayName(name, { ...contact, name: own?.name ?? null });
|
|
214
243
|
const ties = reasons.get(id) ?? [];
|
|
215
|
-
const
|
|
244
|
+
const bot = bots.get(id);
|
|
245
|
+
const held = bot?.author === "owner" ? "bot" : ownerPeople.has(id) && bot === undefined ? "person" : undefined;
|
|
246
|
+
const worked = kindOf(shown, own, ties, mail.get(id), test.has(id), held);
|
|
247
|
+
const move = held === undefined && !owner && worked.kind !== "test" ? moveOf(bot, isProgram(worked, own, ties)) : undefined;
|
|
248
|
+
const isBot = (bot !== undefined && move !== "person") || move === "bot";
|
|
249
|
+
const named = bot?.name ?? shown;
|
|
216
250
|
return {
|
|
217
251
|
id,
|
|
218
|
-
|
|
252
|
+
...(move === undefined ? {} : { move }),
|
|
253
|
+
nameOrder: nameOrderOf(named),
|
|
219
254
|
person: `person:${id}`,
|
|
220
255
|
name,
|
|
221
|
-
displayName:
|
|
222
|
-
kind,
|
|
223
|
-
kindSignals: signals,
|
|
256
|
+
displayName: named,
|
|
257
|
+
kind: worked.kind,
|
|
258
|
+
kindSignals: worked.signals,
|
|
224
259
|
owner,
|
|
225
260
|
tasks: tasks.get(id) ?? 0,
|
|
226
261
|
contact: contact.phone ?? contact.email ?? (contact.username === null ? null : `@${contact.username.replace(/^@/, "")}`),
|
|
227
262
|
...contact,
|
|
228
263
|
usernameSource: own?.usernameSource ?? null,
|
|
229
264
|
messagesFrom: (own?.messages ?? 0) + (mail.get(id)?.n ?? 0),
|
|
230
|
-
ties,
|
|
265
|
+
ties: isBot ? [] : ties,
|
|
266
|
+
bot: bot !== undefined && move !== "person" ? `${SENDER_BOT_PREFIX}${bot.id}` : null,
|
|
231
267
|
emails: own?.emails ?? [],
|
|
232
268
|
twoWay: own?.twoWay ?? false,
|
|
233
269
|
};
|
|
@@ -237,7 +273,7 @@ const withLastContact = (database, people, known) => {
|
|
|
237
273
|
const at = known ??
|
|
238
274
|
lastContacts(database, people.map(({ id }) => id));
|
|
239
275
|
const sent = sentMailOf(database, people.map(({ id }) => id));
|
|
240
|
-
return people.map(({ id, nameOrder: _, emails, twoWay, ...person }) => {
|
|
276
|
+
return people.map(({ id, nameOrder: _, emails, twoWay, move: __, ...person }) => {
|
|
241
277
|
const time = at.get(id);
|
|
242
278
|
const { ties } = person;
|
|
243
279
|
return {
|
|
@@ -258,7 +294,7 @@ const byName = (a, b) => a.nameOrder < b.nameOrder ? -1 : a.nameOrder > b.nameOr
|
|
|
258
294
|
* Bump when what decides a kind, a name's order or a count changes in code (the word lists, `BULK_MIN`, the ties):
|
|
259
295
|
* every stored one is worked out again on the next list.
|
|
260
296
|
*/
|
|
261
|
-
const KIND_RULES = "
|
|
297
|
+
const KIND_RULES = "9";
|
|
262
298
|
const RULES_KEY = "people.kind_rules";
|
|
263
299
|
/** Past this many people to work out, one pass over everyone beats a lookup per person. */
|
|
264
300
|
const WHOLE_PASS = 20_000;
|
|
@@ -298,6 +334,22 @@ const workOut = (database, all, most) => {
|
|
|
298
334
|
}));
|
|
299
335
|
};
|
|
300
336
|
const keep = (database, worked) => {
|
|
337
|
+
const at = Date.now();
|
|
338
|
+
// Before the kinds: a move clears the person's kind through its triggers.
|
|
339
|
+
for (const person of worked)
|
|
340
|
+
if (person.move !== undefined && person.kind !== MERGED)
|
|
341
|
+
ruleMove(database, person.id, person.move, person.kindSignals.join(", "), at);
|
|
342
|
+
const keptAsPeople = ownerPeopleOf(database);
|
|
343
|
+
groupByDomain(database, worked
|
|
344
|
+
.filter((person) => !person.owner && person.kind !== MERGED && person.kind !== "test")
|
|
345
|
+
.map((person) => ({
|
|
346
|
+
id: person.id,
|
|
347
|
+
displayName: person.displayName,
|
|
348
|
+
holds: !keptAsPeople.has(person.id) &&
|
|
349
|
+
(person.bot !== null ||
|
|
350
|
+
person.move === "bot" ||
|
|
351
|
+
(person.kind === "organization" && person.kindSignals.includes("role-address"))),
|
|
352
|
+
})), at);
|
|
301
353
|
const row = database.prepare("UPDATE persons SET kind = ?, name_order = ?, messages_from = ?, task_count = ?, last_contact = ? WHERE id = ?");
|
|
302
354
|
for (const person of worked)
|
|
303
355
|
row.run(person.kind, person.nameOrder, person.messagesFrom, person.tasks, person.lastContact ?? null, person.id);
|
|
@@ -500,7 +552,7 @@ export const similarPeople = (database, typed, limit) => {
|
|
|
500
552
|
}));
|
|
501
553
|
const byId = new Map(people.map((person) => [person.id, person]));
|
|
502
554
|
const ordered = [...sameName.keys()].flatMap((id) => byId.get(id) ?? []);
|
|
503
|
-
const rows = classified(database, ordered, [...sameName.keys()], ties).filter(({ kind }) => kind !== "test");
|
|
555
|
+
const rows = classified(database, ordered, [...sameName.keys()], ties).filter(({ kind, bot }) => kind !== "test" && bot === null);
|
|
504
556
|
const same = rows.map(({ id }) => sameName.get(id) === true);
|
|
505
557
|
return withLastContact(database, rows).map((person, at) => ({ ...person, sameName: same[at] === true }));
|
|
506
558
|
};
|
|
@@ -203,7 +203,7 @@ const join = (pass, sides, signal) => {
|
|
|
203
203
|
result.skipped.push({ persons: [String(from), String(into)], signal: method, reason: "identity.separated" });
|
|
204
204
|
return into;
|
|
205
205
|
}
|
|
206
|
-
if (touchesOwner(pass, from, into, method))
|
|
206
|
+
if (touchesOwner(pass, from, into, method) || touchesBot(pass, from, into, method))
|
|
207
207
|
return into;
|
|
208
208
|
if (index.rejected(from, into) !== undefined) {
|
|
209
209
|
propose(pass, {
|
|
@@ -233,10 +233,20 @@ const touchesOwner = ({ context, result }, from, to, signal) => {
|
|
|
233
233
|
result.skipped.push({ persons: [String(from), String(to)], signal, reason: "identity.owner" });
|
|
234
234
|
return true;
|
|
235
235
|
};
|
|
236
|
+
/** A sender bot is never proposed as the same person, by any signal; the owner moves it by hand. */
|
|
237
|
+
const touchesBot = ({ context, result }, from, to, signal) => {
|
|
238
|
+
const held = context.database.prepare("SELECT 1 FROM sender_bots WHERE person_id IN (?, ?) LIMIT 1").get(from, to);
|
|
239
|
+
if (held === undefined)
|
|
240
|
+
return false;
|
|
241
|
+
result.skipped.push({ persons: [String(from), String(to)], signal, reason: "identity.not-a-person" });
|
|
242
|
+
return true;
|
|
243
|
+
};
|
|
236
244
|
const propose = (pass, opening) => {
|
|
237
245
|
const { context, index, result } = pass;
|
|
238
246
|
if (touchesOwner(pass, opening.from, opening.to, opening.signal))
|
|
239
247
|
return;
|
|
248
|
+
if (touchesBot(pass, opening.from, opening.to, opening.signal))
|
|
249
|
+
return;
|
|
240
250
|
const opened = openIdentityLink(context, { ...opening, by: RULE }, index);
|
|
241
251
|
const persons = [String(opening.from), String(opening.to)];
|
|
242
252
|
if (opened.outcome === "skipped") {
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
export declare const senderBots: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
2
|
+
name: "sender_bots";
|
|
3
|
+
schema: undefined;
|
|
4
|
+
columns: {
|
|
5
|
+
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
6
|
+
name: string;
|
|
7
|
+
tableName: "sender_bots";
|
|
8
|
+
dataType: "number int53";
|
|
9
|
+
data: number;
|
|
10
|
+
driverParam: number;
|
|
11
|
+
notNull: true;
|
|
12
|
+
hasDefault: true;
|
|
13
|
+
isPrimaryKey: true;
|
|
14
|
+
isAutoincrement: false;
|
|
15
|
+
hasRuntimeDefault: false;
|
|
16
|
+
enumValues: undefined;
|
|
17
|
+
baseColumn: never;
|
|
18
|
+
identity: undefined;
|
|
19
|
+
generated: undefined;
|
|
20
|
+
}, {}>;
|
|
21
|
+
personId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
22
|
+
name: string;
|
|
23
|
+
tableName: "sender_bots";
|
|
24
|
+
dataType: "number int53";
|
|
25
|
+
data: number;
|
|
26
|
+
driverParam: number;
|
|
27
|
+
notNull: true;
|
|
28
|
+
hasDefault: false;
|
|
29
|
+
isPrimaryKey: false;
|
|
30
|
+
isAutoincrement: false;
|
|
31
|
+
hasRuntimeDefault: false;
|
|
32
|
+
enumValues: undefined;
|
|
33
|
+
baseColumn: never;
|
|
34
|
+
identity: undefined;
|
|
35
|
+
generated: undefined;
|
|
36
|
+
}, {}>;
|
|
37
|
+
name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
38
|
+
name: string;
|
|
39
|
+
tableName: "sender_bots";
|
|
40
|
+
dataType: "string";
|
|
41
|
+
data: string;
|
|
42
|
+
driverParam: string;
|
|
43
|
+
notNull: false;
|
|
44
|
+
hasDefault: false;
|
|
45
|
+
isPrimaryKey: false;
|
|
46
|
+
isAutoincrement: false;
|
|
47
|
+
hasRuntimeDefault: false;
|
|
48
|
+
enumValues: [string, ...string[]];
|
|
49
|
+
baseColumn: never;
|
|
50
|
+
identity: undefined;
|
|
51
|
+
generated: undefined;
|
|
52
|
+
}, {}>;
|
|
53
|
+
organizationId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
54
|
+
name: string;
|
|
55
|
+
tableName: "sender_bots";
|
|
56
|
+
dataType: "number int53";
|
|
57
|
+
data: number;
|
|
58
|
+
driverParam: number;
|
|
59
|
+
notNull: false;
|
|
60
|
+
hasDefault: false;
|
|
61
|
+
isPrimaryKey: false;
|
|
62
|
+
isAutoincrement: false;
|
|
63
|
+
hasRuntimeDefault: false;
|
|
64
|
+
enumValues: undefined;
|
|
65
|
+
baseColumn: never;
|
|
66
|
+
identity: undefined;
|
|
67
|
+
generated: undefined;
|
|
68
|
+
}, {}>;
|
|
69
|
+
author: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
70
|
+
name: string;
|
|
71
|
+
tableName: "sender_bots";
|
|
72
|
+
dataType: "string";
|
|
73
|
+
data: string;
|
|
74
|
+
driverParam: string;
|
|
75
|
+
notNull: true;
|
|
76
|
+
hasDefault: false;
|
|
77
|
+
isPrimaryKey: false;
|
|
78
|
+
isAutoincrement: false;
|
|
79
|
+
hasRuntimeDefault: false;
|
|
80
|
+
enumValues: [string, ...string[]];
|
|
81
|
+
baseColumn: never;
|
|
82
|
+
identity: undefined;
|
|
83
|
+
generated: undefined;
|
|
84
|
+
}, {}>;
|
|
85
|
+
reason: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
86
|
+
name: string;
|
|
87
|
+
tableName: "sender_bots";
|
|
88
|
+
dataType: "string";
|
|
89
|
+
data: string;
|
|
90
|
+
driverParam: string;
|
|
91
|
+
notNull: false;
|
|
92
|
+
hasDefault: false;
|
|
93
|
+
isPrimaryKey: false;
|
|
94
|
+
isAutoincrement: false;
|
|
95
|
+
hasRuntimeDefault: false;
|
|
96
|
+
enumValues: [string, ...string[]];
|
|
97
|
+
baseColumn: never;
|
|
98
|
+
identity: undefined;
|
|
99
|
+
generated: undefined;
|
|
100
|
+
}, {}>;
|
|
101
|
+
createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
102
|
+
name: string;
|
|
103
|
+
tableName: "sender_bots";
|
|
104
|
+
dataType: "number int53";
|
|
105
|
+
data: number;
|
|
106
|
+
driverParam: number;
|
|
107
|
+
notNull: true;
|
|
108
|
+
hasDefault: false;
|
|
109
|
+
isPrimaryKey: false;
|
|
110
|
+
isAutoincrement: false;
|
|
111
|
+
hasRuntimeDefault: false;
|
|
112
|
+
enumValues: undefined;
|
|
113
|
+
baseColumn: never;
|
|
114
|
+
identity: undefined;
|
|
115
|
+
generated: undefined;
|
|
116
|
+
}, {}>;
|
|
117
|
+
updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
118
|
+
name: string;
|
|
119
|
+
tableName: "sender_bots";
|
|
120
|
+
dataType: "number int53";
|
|
121
|
+
data: number;
|
|
122
|
+
driverParam: number;
|
|
123
|
+
notNull: true;
|
|
124
|
+
hasDefault: false;
|
|
125
|
+
isPrimaryKey: false;
|
|
126
|
+
isAutoincrement: false;
|
|
127
|
+
hasRuntimeDefault: false;
|
|
128
|
+
enumValues: undefined;
|
|
129
|
+
baseColumn: never;
|
|
130
|
+
identity: undefined;
|
|
131
|
+
generated: undefined;
|
|
132
|
+
}, {}>;
|
|
133
|
+
};
|
|
134
|
+
dialect: 'sqlite';
|
|
135
|
+
isAlias: false;
|
|
136
|
+
}>;
|
|
137
|
+
export declare const senderBotMoves: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
138
|
+
name: "sender_bot_moves";
|
|
139
|
+
schema: undefined;
|
|
140
|
+
columns: {
|
|
141
|
+
id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
142
|
+
name: string;
|
|
143
|
+
tableName: "sender_bot_moves";
|
|
144
|
+
dataType: "number int53";
|
|
145
|
+
data: number;
|
|
146
|
+
driverParam: number;
|
|
147
|
+
notNull: true;
|
|
148
|
+
hasDefault: true;
|
|
149
|
+
isPrimaryKey: true;
|
|
150
|
+
isAutoincrement: false;
|
|
151
|
+
hasRuntimeDefault: false;
|
|
152
|
+
enumValues: undefined;
|
|
153
|
+
baseColumn: never;
|
|
154
|
+
identity: undefined;
|
|
155
|
+
generated: undefined;
|
|
156
|
+
}, {}>;
|
|
157
|
+
identityId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
158
|
+
name: string;
|
|
159
|
+
tableName: "sender_bot_moves";
|
|
160
|
+
dataType: "number int53";
|
|
161
|
+
data: number;
|
|
162
|
+
driverParam: number;
|
|
163
|
+
notNull: true;
|
|
164
|
+
hasDefault: false;
|
|
165
|
+
isPrimaryKey: false;
|
|
166
|
+
isAutoincrement: false;
|
|
167
|
+
hasRuntimeDefault: false;
|
|
168
|
+
enumValues: undefined;
|
|
169
|
+
baseColumn: never;
|
|
170
|
+
identity: undefined;
|
|
171
|
+
generated: undefined;
|
|
172
|
+
}, {}>;
|
|
173
|
+
fromPersonId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
174
|
+
name: string;
|
|
175
|
+
tableName: "sender_bot_moves";
|
|
176
|
+
dataType: "number int53";
|
|
177
|
+
data: number;
|
|
178
|
+
driverParam: number;
|
|
179
|
+
notNull: false;
|
|
180
|
+
hasDefault: false;
|
|
181
|
+
isPrimaryKey: false;
|
|
182
|
+
isAutoincrement: false;
|
|
183
|
+
hasRuntimeDefault: false;
|
|
184
|
+
enumValues: undefined;
|
|
185
|
+
baseColumn: never;
|
|
186
|
+
identity: undefined;
|
|
187
|
+
generated: undefined;
|
|
188
|
+
}, {}>;
|
|
189
|
+
fromBotId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
190
|
+
name: string;
|
|
191
|
+
tableName: "sender_bot_moves";
|
|
192
|
+
dataType: "number int53";
|
|
193
|
+
data: number;
|
|
194
|
+
driverParam: number;
|
|
195
|
+
notNull: false;
|
|
196
|
+
hasDefault: false;
|
|
197
|
+
isPrimaryKey: false;
|
|
198
|
+
isAutoincrement: false;
|
|
199
|
+
hasRuntimeDefault: false;
|
|
200
|
+
enumValues: undefined;
|
|
201
|
+
baseColumn: never;
|
|
202
|
+
identity: undefined;
|
|
203
|
+
generated: undefined;
|
|
204
|
+
}, {}>;
|
|
205
|
+
toPersonId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
206
|
+
name: string;
|
|
207
|
+
tableName: "sender_bot_moves";
|
|
208
|
+
dataType: "number int53";
|
|
209
|
+
data: number;
|
|
210
|
+
driverParam: number;
|
|
211
|
+
notNull: false;
|
|
212
|
+
hasDefault: false;
|
|
213
|
+
isPrimaryKey: false;
|
|
214
|
+
isAutoincrement: false;
|
|
215
|
+
hasRuntimeDefault: false;
|
|
216
|
+
enumValues: undefined;
|
|
217
|
+
baseColumn: never;
|
|
218
|
+
identity: undefined;
|
|
219
|
+
generated: undefined;
|
|
220
|
+
}, {}>;
|
|
221
|
+
toBotId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
222
|
+
name: string;
|
|
223
|
+
tableName: "sender_bot_moves";
|
|
224
|
+
dataType: "number int53";
|
|
225
|
+
data: number;
|
|
226
|
+
driverParam: number;
|
|
227
|
+
notNull: false;
|
|
228
|
+
hasDefault: false;
|
|
229
|
+
isPrimaryKey: false;
|
|
230
|
+
isAutoincrement: false;
|
|
231
|
+
hasRuntimeDefault: false;
|
|
232
|
+
enumValues: undefined;
|
|
233
|
+
baseColumn: never;
|
|
234
|
+
identity: undefined;
|
|
235
|
+
generated: undefined;
|
|
236
|
+
}, {}>;
|
|
237
|
+
author: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
238
|
+
name: string;
|
|
239
|
+
tableName: "sender_bot_moves";
|
|
240
|
+
dataType: "string";
|
|
241
|
+
data: string;
|
|
242
|
+
driverParam: string;
|
|
243
|
+
notNull: true;
|
|
244
|
+
hasDefault: false;
|
|
245
|
+
isPrimaryKey: false;
|
|
246
|
+
isAutoincrement: false;
|
|
247
|
+
hasRuntimeDefault: false;
|
|
248
|
+
enumValues: [string, ...string[]];
|
|
249
|
+
baseColumn: never;
|
|
250
|
+
identity: undefined;
|
|
251
|
+
generated: undefined;
|
|
252
|
+
}, {}>;
|
|
253
|
+
reason: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
254
|
+
name: string;
|
|
255
|
+
tableName: "sender_bot_moves";
|
|
256
|
+
dataType: "string";
|
|
257
|
+
data: string;
|
|
258
|
+
driverParam: string;
|
|
259
|
+
notNull: false;
|
|
260
|
+
hasDefault: false;
|
|
261
|
+
isPrimaryKey: false;
|
|
262
|
+
isAutoincrement: false;
|
|
263
|
+
hasRuntimeDefault: false;
|
|
264
|
+
enumValues: [string, ...string[]];
|
|
265
|
+
baseColumn: never;
|
|
266
|
+
identity: undefined;
|
|
267
|
+
generated: undefined;
|
|
268
|
+
}, {}>;
|
|
269
|
+
createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
|
|
270
|
+
name: string;
|
|
271
|
+
tableName: "sender_bot_moves";
|
|
272
|
+
dataType: "number int53";
|
|
273
|
+
data: number;
|
|
274
|
+
driverParam: number;
|
|
275
|
+
notNull: true;
|
|
276
|
+
hasDefault: false;
|
|
277
|
+
isPrimaryKey: false;
|
|
278
|
+
isAutoincrement: false;
|
|
279
|
+
hasRuntimeDefault: false;
|
|
280
|
+
enumValues: undefined;
|
|
281
|
+
baseColumn: never;
|
|
282
|
+
identity: undefined;
|
|
283
|
+
generated: undefined;
|
|
284
|
+
}, {}>;
|
|
285
|
+
};
|
|
286
|
+
dialect: 'sqlite';
|
|
287
|
+
isAlias: false;
|
|
288
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { index, integer, sqliteTable, text } from "../drizzle/core.js";
|
|
2
|
+
export const senderBots = sqliteTable("sender_bots", {
|
|
3
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
4
|
+
personId: integer("person_id").notNull().unique(),
|
|
5
|
+
name: text("name"),
|
|
6
|
+
organizationId: integer("organization_id"),
|
|
7
|
+
author: text("author").notNull(),
|
|
8
|
+
reason: text("reason"),
|
|
9
|
+
createdAt: integer("created_at").notNull(),
|
|
10
|
+
updatedAt: integer("updated_at").notNull(),
|
|
11
|
+
});
|
|
12
|
+
export const senderBotMoves = sqliteTable("sender_bot_moves", {
|
|
13
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
14
|
+
identityId: integer("identity_id").notNull(),
|
|
15
|
+
fromPersonId: integer("from_person_id"),
|
|
16
|
+
fromBotId: integer("from_bot_id"),
|
|
17
|
+
toPersonId: integer("to_person_id"),
|
|
18
|
+
toBotId: integer("to_bot_id"),
|
|
19
|
+
author: text("author").notNull(),
|
|
20
|
+
reason: text("reason"),
|
|
21
|
+
createdAt: integer("created_at").notNull(),
|
|
22
|
+
}, (table) => [index("sender_bot_moves_by_identity_id").on(table.identityId)]);
|
|
@@ -2433,6 +2433,7 @@ export declare const bots: import("drizzle-orm/sqlite-core").SQLiteTableWithColu
|
|
|
2433
2433
|
dialect: 'sqlite';
|
|
2434
2434
|
isAlias: false;
|
|
2435
2435
|
}>;
|
|
2436
|
+
export { senderBotMoves, senderBots } from "./schema/sender-bots.js";
|
|
2436
2437
|
export declare const chats: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
2437
2438
|
name: "chats";
|
|
2438
2439
|
schema: undefined;
|