@wirecat/cli-core 0.604.0 → 0.606.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 +159 -0
- package/dist/calendar/prepare.d.ts +4 -2
- package/dist/calendar/prepare.js +8 -8
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +2 -1
- package/dist/cli/messenger/contacts-command.js +3 -2
- package/dist/cli/messenger/doctor-command.js +14 -7
- package/dist/cli/messenger/store-maintenance-command.d.ts +34 -2
- package/dist/cli/messenger/store-maintenance-command.js +31 -4
- package/dist/cli/program.js +11 -2
- package/dist/cli/steps.js +9 -1
- package/dist/cli/store-recover.d.ts +10 -2
- package/dist/cli/store-recover.js +18 -4
- package/dist/cli/store-settings.js +38 -4
- package/dist/crm/cli/index.js +3 -1
- package/dist/crm/index.d.ts +2 -2
- package/dist/crm/index.js +1 -1
- package/dist/crm/source.d.ts +35 -5
- package/dist/crm/sync.d.ts +15 -7
- package/dist/crm/sync.js +169 -11
- package/dist/domain/crm.d.ts +41 -2
- package/dist/domain/deals.d.ts +5 -2
- package/dist/domain/deals.js +5 -2
- package/dist/domain/record-types.d.ts +61 -0
- package/dist/domain/record-types.js +26 -0
- package/dist/domain/records.d.ts +3 -5
- package/dist/domain/records.js +10 -13
- package/dist/domain/relations.d.ts +125 -0
- package/dist/domain/relations.js +107 -0
- package/dist/entities/contact-activity.d.ts +4 -0
- package/dist/entities/contact-activity.js +1 -0
- package/dist/entities/contact-context.d.ts +20 -0
- package/dist/entities/contact-context.js +2 -0
- package/dist/entities/deal.d.ts +2 -2
- package/dist/entities/deal.js +2 -1
- package/dist/entities/index.d.ts +39 -13
- package/dist/entities/relationship.d.ts +8 -2
- package/dist/entities/relationship.js +8 -2
- package/dist/entities/task-results.d.ts +10 -10
- package/dist/errors/failures.d.ts +17 -1
- package/dist/errors/failures.js +57 -1
- package/dist/errors/reasons.js +28 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/mail/cli/review.js +20 -6
- package/dist/mail/index.d.ts +1 -1
- package/dist/mail/marks.d.ts +10 -5
- package/dist/mail/marks.js +16 -8
- package/dist/mail/review.d.ts +5 -0
- package/dist/mcp/tool.js +2 -1
- package/dist/runs/recording.js +13 -4
- package/dist/services/deps.js +4 -6
- package/dist/services/index.d.ts +1 -1
- package/dist/services/link-scorers/chat-senders.d.ts +3 -2
- package/dist/services/link-scorers/chat-senders.js +7 -4
- package/dist/services/link-scorers/mail-thread.js +1 -0
- package/dist/services/link-scorers/member-chats.js +1 -0
- package/dist/services/link-scorers/member-dialog.d.ts +1 -1
- package/dist/services/link-scorers/member-dialog.js +4 -3
- package/dist/services/link-scorers/scan.d.ts +5 -2
- package/dist/services/link-scorers/scan.js +100 -54
- package/dist/services/link-scorers/shared.d.ts +2 -2
- package/dist/services/link-scorers/shared.js +8 -4
- package/dist/services/link-scorers/types.d.ts +3 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/services/person-context.d.ts +24 -7
- package/dist/services/person-context.js +45 -11
- package/dist/services/person-preparation.js +4 -5
- package/dist/services/project-status/index.js +2 -1
- package/dist/services/stored-project-gathering.js +4 -3
- package/dist/store/damage.d.ts +3 -1
- package/dist/store/damage.js +19 -12
- package/dist/store/document-transfer/index.js +7 -0
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +7 -1
- package/dist/store/index.js +2 -0
- package/dist/store/marks.d.ts +57 -0
- package/dist/store/marks.js +121 -0
- package/dist/store/project-transfer/preview.js +12 -7
- package/dist/store/project-transfer/request.d.ts +4 -1
- package/dist/store/project-transfer/schema.d.ts +9 -2
- package/dist/store/project-transfer/schema.js +4 -0
- package/dist/store/project-transfer/snapshot-model.d.ts +8 -2
- package/dist/store/recover.js +16 -1
- package/dist/store/sqlite/crm-settings.d.ts +28 -0
- package/dist/store/sqlite/crm-settings.js +80 -0
- package/dist/store/sqlite/crm.d.ts +42 -2
- package/dist/store/sqlite/crm.js +397 -36
- package/dist/store/sqlite/deals.js +3 -2
- package/dist/store/sqlite/finance.d.ts +8 -1
- package/dist/store/sqlite/finance.js +10 -3
- package/dist/store/sqlite/involvement-queue.js +4 -3
- package/dist/store/sqlite/knowledge.d.ts +7 -3
- package/dist/store/sqlite/knowledge.js +43 -31
- package/dist/store/sqlite/link-kinds.d.ts +2 -3
- package/dist/store/sqlite/link-kinds.js +4 -2
- package/dist/store/sqlite/manifest.js +5 -0
- package/dist/store/sqlite/memories.d.ts +1 -1
- package/dist/store/sqlite/memories.js +33 -7
- package/dist/store/sqlite/migrations.generated.js +31 -0
- package/dist/store/sqlite/notes.d.ts +3 -2
- package/dist/store/sqlite/notes.js +23 -6
- package/dist/store/sqlite/open-store.js +4 -1
- package/dist/store/sqlite/organizations.d.ts +8 -0
- package/dist/store/sqlite/organizations.js +14 -0
- package/dist/store/sqlite/own-identities.d.ts +1 -1
- package/dist/store/sqlite/own-identities.js +7 -5
- package/dist/store/sqlite/person-links.d.ts +5 -2
- package/dist/store/sqlite/person-links.js +24 -18
- package/dist/store/sqlite/person-preparation.d.ts +1 -1
- package/dist/store/sqlite/person-preparation.js +3 -2
- package/dist/store/sqlite/person-separation.d.ts +5 -0
- package/dist/store/sqlite/person-separation.js +26 -0
- package/dist/store/sqlite/project-transfer/records.js +14 -3
- package/dist/store/sqlite/project-transfer/snapshot.d.ts +4 -1
- package/dist/store/sqlite/project-transfer/snapshot.js +6 -0
- package/dist/store/sqlite/record-projectors.d.ts +44 -0
- package/dist/store/sqlite/record-projectors.js +72 -0
- package/dist/store/sqlite/records.js +12 -70
- package/dist/store/sqlite/relation-list.d.ts +43 -0
- package/dist/store/sqlite/relation-list.js +133 -0
- package/dist/store/sqlite/relation-proposals.d.ts +28 -6
- package/dist/store/sqlite/relation-proposals.js +134 -10
- package/dist/store/sqlite/relation-reads.d.ts +8 -0
- package/dist/store/sqlite/relation-reads.js +7 -0
- package/dist/store/sqlite/relation-roles.d.ts +26 -0
- package/dist/store/sqlite/relation-roles.js +91 -0
- package/dist/store/sqlite/reported-relations.d.ts +63 -0
- package/dist/store/sqlite/reported-relations.js +132 -0
- package/dist/store/sqlite/schema/link-revisions.d.ts +136 -0
- package/dist/store/sqlite/schema/link-revisions.js +11 -0
- package/dist/store/sqlite/schema/links.d.ts +360 -0
- package/dist/store/sqlite/schema/links.js +32 -0
- package/dist/store/sqlite/schema.d.ts +2 -296
- package/dist/store/sqlite/schema.js +2 -24
- package/dist/store/sqlite/transaction.js +2 -5
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/store/types.d.ts +5 -0
- package/package.json +5 -5
package/dist/mail/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { dropMissing, type Gone, tooManyGone } from "./gone.js";
|
|
|
9
9
|
export { type AuthVerdicts, HEADER_FIELDS, headersOf, type MailHeaders, mailHeadersOf } from "./headers.js";
|
|
10
10
|
export { type MailIdsInput, mailIds } from "./ids.js";
|
|
11
11
|
export { decodedLabelName, decodeMailboxName, labelName, systemLabel } from "./labels.js";
|
|
12
|
-
export { acknowledgeMark, advancePastSkipped, type BulkExcerpt, cursorOf, HOLD_PARTIAL_MS, HOLDER, MARK_BATCH, type MailMark, type MailWaiting, type MarkRead, type MarkRewind, mailWaiting, markOf, marksOf, type RewoundMark, readPastMark, rewindMark, type SkipReason, } from "./marks.js";
|
|
12
|
+
export { acknowledgeMark, advancePastSkipped, type BulkExcerpt, cursorOf, HOLD_PARTIAL_MS, HOLDER, MARK_BATCH, type MailMark, type MailWaiting, type MarkedHit, type MarkRead, type MarkRewind, mailWaiting, markOf, marksOf, type RewoundMark, readPastMark, rewindMark, type SkipReason, } from "./marks.js";
|
|
13
13
|
export { BULK_TRIAGE_DEFAULTS, type BulkSorted, type BulkTriage, excerptOf, NEWSLETTER_DEFAULTS, NEWSLETTER_SENDERS, NEWSLETTER_WORDS, type NewsletterCues, newsletterSorter, ORDER_WORDS, } from "./newsletter.js";
|
|
14
14
|
export { type MailTurn, mailTurn } from "./owed.js";
|
|
15
15
|
export { type Address, htmlToText, looksLikeHtml, MAX_ATTACHMENTS, MAX_BODY_CHARS, type ParsedMail, parseMail, } from "./parse.js";
|
package/dist/mail/marks.d.ts
CHANGED
|
@@ -34,13 +34,18 @@ export declare const marksOf: (store: MessageStore, mailbox: AccountKey) => Prom
|
|
|
34
34
|
export declare const cursorOf: (throughId: number, readAt: number) => string;
|
|
35
35
|
/**
|
|
36
36
|
* The findings key of one run: `<holder>:<through_id>`, and `-r<resets>` once the owner moved the mark back, so the
|
|
37
|
-
* runs after a reset never reach a key a batch staged before it holds.
|
|
38
|
-
*
|
|
37
|
+
* runs after a reset never reach a key a batch staged before it holds. A batch that ends at the mark itself, held
|
|
38
|
+
* emails only, adds `-h<highest held id>`: the run that set the mark already holds the plain key. The same review
|
|
39
|
+
* gives the same key: a retry of one run stages nothing twice.
|
|
39
40
|
*/
|
|
40
|
-
export declare const findingsKeyOf: (holder: string, throughId: number, resets: number) => string;
|
|
41
|
+
export declare const findingsKeyOf: (holder: string, throughId: number, resets: number, heldThrough?: number) => string;
|
|
41
42
|
/** A bulk email that is not surely a newsletter: the holder gets its subject and first lines only. */
|
|
43
|
+
/** An email as a hit, with its store id: the order a mark counts by. */
|
|
44
|
+
export type MarkedHit = StoredHit & {
|
|
45
|
+
storeId: number;
|
|
46
|
+
};
|
|
42
47
|
export interface BulkExcerpt {
|
|
43
|
-
email:
|
|
48
|
+
email: MarkedHit;
|
|
44
49
|
/** The first lines of its own text, without the subject. */
|
|
45
50
|
excerpt: string;
|
|
46
51
|
/** What kept it, or the newsletter signs too few to leave it out. */
|
|
@@ -50,7 +55,7 @@ export interface BulkExcerpt {
|
|
|
50
55
|
}
|
|
51
56
|
export interface MarkRead {
|
|
52
57
|
/** The emails for the holder, oldest first; bulk, envelopes, drafts, suspicious senders and partial mail left out. */
|
|
53
|
-
emails:
|
|
58
|
+
emails: MarkedHit[];
|
|
54
59
|
/** Bulk mail past the mark that is not surely a newsletter, oldest first; none when the triage gives no excerpts. */
|
|
55
60
|
excerpts: BulkExcerpt[];
|
|
56
61
|
/** What `acknowledge --cursor` takes once the holder is done with these. */
|
package/dist/mail/marks.js
CHANGED
|
@@ -85,10 +85,11 @@ const verdict = (email, now) => {
|
|
|
85
85
|
export const cursorOf = (throughId, readAt) => `${throughId}.${readAt}`;
|
|
86
86
|
/**
|
|
87
87
|
* The findings key of one run: `<holder>:<through_id>`, and `-r<resets>` once the owner moved the mark back, so the
|
|
88
|
-
* runs after a reset never reach a key a batch staged before it holds.
|
|
89
|
-
*
|
|
88
|
+
* runs after a reset never reach a key a batch staged before it holds. A batch that ends at the mark itself, held
|
|
89
|
+
* emails only, adds `-h<highest held id>`: the run that set the mark already holds the plain key. The same review
|
|
90
|
+
* gives the same key: a retry of one run stages nothing twice.
|
|
90
91
|
*/
|
|
91
|
-
export const findingsKeyOf = (holder, throughId, resets) => `${holder}:${throughId}${resets > 0 ? `-r${resets}` : ""}`;
|
|
92
|
+
export const findingsKeyOf = (holder, throughId, resets, heldThrough) => `${holder}:${throughId}${heldThrough === undefined ? "" : `-h${heldThrough}`}${resets > 0 ? `-r${resets}` : ""}`;
|
|
92
93
|
const parseCursor = (cursor) => {
|
|
93
94
|
const match = /^(\d+)\.(\d+)$/.exec(cursor.trim());
|
|
94
95
|
if (!match)
|
|
@@ -106,7 +107,14 @@ export const readPastMark = async (store, mailbox, holder, options = {}) => {
|
|
|
106
107
|
const one = sorted.get(id);
|
|
107
108
|
return one ? [{ email: one.email, excerpt: one.excerpt, cues: one.cues, partial: one.partial }] : [];
|
|
108
109
|
});
|
|
109
|
-
const
|
|
110
|
+
const ids = wanted.filter((one) => !sorted.has(one));
|
|
111
|
+
const hits = await store.mail.emailHits(ids);
|
|
112
|
+
// emailHits keeps the ids' order and drops an email deleted since; only then is each one asked for alone.
|
|
113
|
+
const emails = hits.length === ids.length ? hits.map((hit, index) => ({ ...hit, storeId: ids[index] })) : [];
|
|
114
|
+
if (hits.length !== ids.length)
|
|
115
|
+
for (const id of ids)
|
|
116
|
+
for (const hit of await store.mail.emailHits([id]))
|
|
117
|
+
emails.push({ ...hit, storeId: id });
|
|
110
118
|
return { emails, excerpts, ...read };
|
|
111
119
|
};
|
|
112
120
|
/**
|
|
@@ -132,7 +140,7 @@ const sortBulk = async (store, batch, triage) => {
|
|
|
132
140
|
return { sorted, end: index };
|
|
133
141
|
if (one.verdict === "excerpt")
|
|
134
142
|
excerpts += 1;
|
|
135
|
-
sorted.set(marked.id, { ...one, email, partial: marked.partial });
|
|
143
|
+
sorted.set(marked.id, { ...one, email: { ...email, storeId: marked.id }, partial: marked.partial });
|
|
136
144
|
}
|
|
137
145
|
return { sorted, end: batch.length };
|
|
138
146
|
};
|
|
@@ -149,9 +157,9 @@ const examine = async (store, mailbox, holder, { now = Date.now(), limit = MARK_
|
|
|
149
157
|
skipped: noneSkipped(),
|
|
150
158
|
mark: saved,
|
|
151
159
|
};
|
|
152
|
-
const keyed = (throughId) => ({
|
|
160
|
+
const keyed = (throughId, heldThrough) => ({
|
|
153
161
|
cursor: cursorOf(throughId, now),
|
|
154
|
-
findingsKey: throughId > 0 ? findingsKeyOf(holder, throughId, saved?.resets ?? 0) : undefined,
|
|
162
|
+
findingsKey: throughId > 0 ? findingsKeyOf(holder, throughId, saved?.resets ?? 0, heldThrough) : undefined,
|
|
155
163
|
});
|
|
156
164
|
if (!account)
|
|
157
165
|
return { ...empty, ...keyed(0) };
|
|
@@ -192,7 +200,7 @@ const examine = async (store, mailbox, holder, { now = Date.now(), limit = MARK_
|
|
|
192
200
|
wanted: wanted.sort((a, b) => a - b),
|
|
193
201
|
sorted: new Map([...sorted].filter(([, one]) => one.verdict === "excerpt")),
|
|
194
202
|
oldestStoredAt,
|
|
195
|
-
...keyed(batch.at(-1)?.id ?? mark.throughId),
|
|
203
|
+
...(batch.length > 0 ? keyed(batch.at(-1)?.id ?? mark.throughId) : keyed(mark.throughId, wanted.at(-1))),
|
|
196
204
|
more: newer.length > batch.length,
|
|
197
205
|
held,
|
|
198
206
|
skipped,
|
package/dist/mail/review.d.ts
CHANGED
|
@@ -23,6 +23,11 @@ export type MailHit = StoredHit & {
|
|
|
23
23
|
marks?: EmailMarks;
|
|
24
24
|
excerptOnly?: true;
|
|
25
25
|
partialExcerpt?: true;
|
|
26
|
+
/** A holder's read: the cursor and findings key that end the batch at this email. */
|
|
27
|
+
through?: {
|
|
28
|
+
cursor: string;
|
|
29
|
+
findingsKey: string;
|
|
30
|
+
};
|
|
26
31
|
};
|
|
27
32
|
export interface MailReview extends Review {
|
|
28
33
|
chats: (Omit<ReviewChat, "messages"> & {
|
package/dist/mcp/tool.js
CHANGED
|
@@ -8,6 +8,7 @@ import { DEFAULT_OUTPUT_BYTES } from "../cli/execution.js";
|
|
|
8
8
|
import { MAX_BUFFERED_INPUT } from "../cli/input-policy.js";
|
|
9
9
|
import { refuseLacking } from "../cli/messenger/lacks.js";
|
|
10
10
|
import { ENTITIES } from "../entities/index.js";
|
|
11
|
+
import { storeDamaged } from "../errors/failures.js";
|
|
11
12
|
import { failureContext } from "../errors/reasons.js";
|
|
12
13
|
import { startRecording } from "../runs/recording.js";
|
|
13
14
|
import { newRunId } from "../runs/run.js";
|
|
@@ -317,7 +318,7 @@ export const answered = (answer, maxBytes = DEFAULT_OUTPUT_BYTES, targets) => {
|
|
|
317
318
|
export const failed = (error, errors, effects) => {
|
|
318
319
|
const judged = judgedEffects(effects);
|
|
319
320
|
const context = { ...failureContext(errors), ...(judged ? { effects: judged } : {}) };
|
|
320
|
-
return mcpErrorResult(JSON.parse(agentJson(errorObjectOf(error, context))));
|
|
321
|
+
return mcpErrorResult(JSON.parse(agentJson(errorObjectOf(storeDamaged(error), context))));
|
|
321
322
|
};
|
|
322
323
|
/** An option's name as an MCP argument: `beforeId` is `before_id`. */
|
|
323
324
|
export const snakeOf = (key) => key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
package/dist/runs/recording.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { processStreams } from "@wirecat/cli-base";
|
|
2
|
-
import { isCliFailure } from "../errors/failures.js";
|
|
2
|
+
import { isCliFailure, storeDamaged } from "../errors/failures.js";
|
|
3
|
+
import { markStoreDamaged } from "../store/marks.js";
|
|
4
|
+
import { storePath } from "../store/path.js";
|
|
3
5
|
import { endpointTemplate, errorDetailOf, framesOf } from "./error-detail.js";
|
|
4
6
|
import { providerErrorKey, renderEvent } from "./events.js";
|
|
5
7
|
import { DIAGNOSTIC_LOG_EVENTS } from "./log-events.js";
|
|
@@ -106,7 +108,14 @@ export const startRecording = (options) => {
|
|
|
106
108
|
...(partial ? { partial } : {}),
|
|
107
109
|
});
|
|
108
110
|
},
|
|
109
|
-
fail: async (
|
|
111
|
+
fail: async (thrown) => {
|
|
112
|
+
const error = storeDamaged(thrown);
|
|
113
|
+
markStoreDamaged(thrown, {
|
|
114
|
+
store: storePath(options.env),
|
|
115
|
+
command: `${options.app.command} ${options.command}`,
|
|
116
|
+
version: options.app.version,
|
|
117
|
+
runId,
|
|
118
|
+
});
|
|
110
119
|
const failed = run ?? (held ? keep(open({ startedAt })) : undefined);
|
|
111
120
|
if (failed) {
|
|
112
121
|
if (!isCliFailure(error))
|
|
@@ -121,8 +130,8 @@ export const startRecording = (options) => {
|
|
|
121
130
|
...(run ? {} : { keptBecauseFailed: true }),
|
|
122
131
|
});
|
|
123
132
|
}
|
|
124
|
-
if (typeof
|
|
125
|
-
settled.add(
|
|
133
|
+
if (typeof thrown === "object" && thrown !== null)
|
|
134
|
+
settled.add(thrown);
|
|
126
135
|
},
|
|
127
136
|
};
|
|
128
137
|
};
|
package/dist/services/deps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import { isCliFailure } from "../errors/failures.js";
|
|
2
|
+
import { isCliFailure, sqliteCode } from "../errors/failures.js";
|
|
3
3
|
import { typedCommand } from "../runs/scope.js";
|
|
4
4
|
/** The store with the running account bound: the default for a service's reads and writes. */
|
|
5
5
|
export const accountStore = async (deps) => (await deps.store()).forAccount(await deps.account());
|
|
@@ -10,16 +10,14 @@ export const accountStore = async (deps) => (await deps.store()).forAccount(awai
|
|
|
10
10
|
export const crossAccount = (deps, _reason) => deps.store();
|
|
11
11
|
const NO_LOCAL_STORE = "this answer comes from the messenger, not from the local store";
|
|
12
12
|
/**
|
|
13
|
-
* Busy: another process (`serve`) held the write lock past `busy_timeout
|
|
14
|
-
*
|
|
13
|
+
* Busy: another process (`serve`) held the write lock past `busy_timeout`; `sqliteCode` is the primary code, so the
|
|
14
|
+
* extended BUSY codes match too.
|
|
15
15
|
*/
|
|
16
16
|
const SQLITE_BUSY = 5;
|
|
17
17
|
const storeAbsent = (error) => {
|
|
18
18
|
if (isCliFailure(error))
|
|
19
19
|
return error.code === "validation_error" && error.message === NO_LOCAL_STORE;
|
|
20
|
-
|
|
21
|
-
const code = errcode ?? errno;
|
|
22
|
-
return error instanceof Error && typeof code === "number" && (code & 0xff) === SQLITE_BUSY;
|
|
20
|
+
return error instanceof Error && sqliteCode(error) === SQLITE_BUSY;
|
|
23
21
|
};
|
|
24
22
|
/** `not_found`: nothing has recorded whose account this profile is; `authentication_error`: the connection has no self. */
|
|
25
23
|
const accountUnknown = (error) => isCliFailure(error) && (error.code === "not_found" || error.code === "authentication_error");
|
package/dist/services/index.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export type { ModerateOptions, ModerationService, ShownRules } from "./moderatio
|
|
|
96
96
|
export { moderationService } from "./moderation.js";
|
|
97
97
|
export type { ContactSync, PeopleService } from "./people.js";
|
|
98
98
|
export { linkPeople, peopleService, phoneOf } from "./people.js";
|
|
99
|
-
export type { ContextEvent, ContextMessage, ContextOptions, NotReadReason, PersonContext, SharedChat, } from "./person-context.js";
|
|
99
|
+
export type { AccountScope, ContextEvent, ContextMessage, ContextOptions, NotReadReason, PersonContext, SharedChat, } from "./person-context.js";
|
|
100
100
|
export { CONTEXT_BYTES, CONTEXT_MESSAGES, identityIn, personContext } from "./person-context.js";
|
|
101
101
|
export type { PersonPreparation, WaitingDialog } from "./person-preparation.js";
|
|
102
102
|
export { PREPARE_BYTES, personPreparation } from "./person-preparation.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { LinkScorer } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
* A person who wrote 5 or more messages in the window in one of the project's confirmed chats,
|
|
4
|
-
* identity, never by the name a message shows. In a group of more
|
|
3
|
+
* A person who wrote 5 or more messages in the window in one of the project's confirmed chats, or any in a dialog or a
|
|
4
|
+
* group of 10 people or fewer, found by the sender's identity, never by the name a message shows. In a group of more
|
|
5
|
+
* than 30 people writing there says less.
|
|
5
6
|
*/
|
|
6
7
|
export declare const chatSenders: LinkScorer;
|
|
@@ -3,15 +3,18 @@ import { contactRef, personRefOf, sameAccount } from "./shared.js";
|
|
|
3
3
|
const WEIGHT = 0.5;
|
|
4
4
|
const LARGE_GROUP_WEIGHT = 0.2;
|
|
5
5
|
const LARGE_GROUP = 30;
|
|
6
|
+
const SMALL_CHAT = 10;
|
|
6
7
|
const MIN_MESSAGES = 5;
|
|
7
8
|
const READ_LIMIT = 2000;
|
|
8
9
|
/**
|
|
9
|
-
* A person who wrote 5 or more messages in the window in one of the project's confirmed chats,
|
|
10
|
-
* identity, never by the name a message shows. In a group of more
|
|
10
|
+
* A person who wrote 5 or more messages in the window in one of the project's confirmed chats, or any in a dialog or a
|
|
11
|
+
* group of 10 people or fewer, found by the sender's identity, never by the name a message shows. In a group of more
|
|
12
|
+
* than 30 people writing there says less.
|
|
11
13
|
*/
|
|
12
14
|
export const chatSenders = {
|
|
13
15
|
id: "chat-senders",
|
|
14
|
-
version:
|
|
16
|
+
version: 2,
|
|
17
|
+
spreads: true,
|
|
15
18
|
candidates: async ({ store, project, confirmed, sources, since, owner, signal }) => {
|
|
16
19
|
if (!project)
|
|
17
20
|
return [];
|
|
@@ -35,7 +38,7 @@ export const chatSenders = {
|
|
|
35
38
|
const size = Math.max((await store.roster.members(key, reference.chat)).length, senders.size);
|
|
36
39
|
const weight = size > LARGE_GROUP ? LARGE_GROUP_WEIGHT : WEIGHT;
|
|
37
40
|
for (const [id, { count, last }] of senders) {
|
|
38
|
-
if (count < MIN_MESSAGES)
|
|
41
|
+
if (size > SMALL_CHAT && count < MIN_MESSAGES)
|
|
39
42
|
continue;
|
|
40
43
|
const person = await personRefOf(store, key.provider, id);
|
|
41
44
|
if (!person || person === owner)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LinkScorer } from "./types.js";
|
|
2
|
-
/** A dialog with a
|
|
2
|
+
/** A dialog with a person member, divided by how many projects that person is a member of, this one counted. */
|
|
3
3
|
export declare const memberDialog: LinkScorer;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { chatRef, identitiesIn, projectsOf } from "./shared.js";
|
|
2
2
|
const WEIGHT = 0.6;
|
|
3
|
-
/** A dialog with a
|
|
3
|
+
/** A dialog with a person member, divided by how many projects that person is a member of, this one counted. */
|
|
4
4
|
export const memberDialog = {
|
|
5
5
|
id: "member-dialog",
|
|
6
|
-
version:
|
|
6
|
+
version: 2,
|
|
7
|
+
spreads: true,
|
|
7
8
|
candidates: async ({ store, project, confirmed, sources, owner, signal }) => {
|
|
8
9
|
if (!project)
|
|
9
10
|
return [];
|
|
@@ -17,7 +18,7 @@ export const memberDialog = {
|
|
|
17
18
|
if (chat.kind !== "dialog")
|
|
18
19
|
continue;
|
|
19
20
|
if (!projects.has(person))
|
|
20
|
-
projects.set(person,
|
|
21
|
+
projects.set(person, await projectsOf(store, person, project.ref));
|
|
21
22
|
const shared = projects.get(person) ?? 1;
|
|
22
23
|
found.push({
|
|
23
24
|
from: chatRef(key, chat.id),
|
|
@@ -14,6 +14,8 @@ export declare const DEFAULT_THRESHOLD = 0.5;
|
|
|
14
14
|
/** A person ↔ person scan keeps the old rule's reach: one weak signal is enough to ask the owner. */
|
|
15
15
|
export declare const PERSON_THRESHOLD = 0.3;
|
|
16
16
|
export declare const DEFAULT_LIMIT = 20;
|
|
17
|
+
/** How many times one scan spreads from what it found; a project's links are rarely more than a few steps apart. */
|
|
18
|
+
export declare const MAX_HOPS = 4;
|
|
17
19
|
export interface ScanInput {
|
|
18
20
|
/** A project's key, name, alias or `project:<id>`; `null` runs the person ↔ person rules. */
|
|
19
21
|
project: string | null;
|
|
@@ -33,8 +35,9 @@ export interface ScanInput {
|
|
|
33
35
|
export declare const combinedScore: (weights: readonly number[]) => number;
|
|
34
36
|
/**
|
|
35
37
|
* Runs the scorers for one project over the sources named, combines their signals per pair, and proposes what scores
|
|
36
|
-
* `threshold` or more, highest first, at most `limit` new ones.
|
|
37
|
-
*
|
|
38
|
+
* `threshold` or more, highest first, at most `limit` new ones. What scores `threshold` or more is spread from as if
|
|
39
|
+
* linked, up to `MAX_HOPS` times, so one run reaches a member's chats in every messenger. A pair a link joins, or that
|
|
40
|
+
* was rejected once, is never proposed; a pending one is updated in place. People are matched by identity only. With `write: false`
|
|
38
41
|
* nothing is written.
|
|
39
42
|
*/
|
|
40
43
|
export declare const scanProjectLinks: (store: MessageStore, input: ScanInput) => Promise<ScanResult>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { parseReference } from "../../domain/references.js";
|
|
3
|
+
import { isUsable } from "../../domain/relations.js";
|
|
3
4
|
import { BUILT_IN_PURPOSES } from "../project-purposes.js";
|
|
4
5
|
import { canonicalProjectRef } from "../stored-project-gathering.js";
|
|
5
6
|
import { aliasHits } from "./alias-hits.js";
|
|
@@ -20,6 +21,8 @@ export const DEFAULT_THRESHOLD = 0.5;
|
|
|
20
21
|
/** A person ↔ person scan keeps the old rule's reach: one weak signal is enough to ask the owner. */
|
|
21
22
|
export const PERSON_THRESHOLD = 0.3;
|
|
22
23
|
export const DEFAULT_LIMIT = 20;
|
|
24
|
+
/** How many times one scan spreads from what it found; a project's links are rarely more than a few steps apart. */
|
|
25
|
+
export const MAX_HOPS = 4;
|
|
23
26
|
const projectOf = async (store, reference) => {
|
|
24
27
|
const ref = await canonicalProjectRef(store, reference);
|
|
25
28
|
const entry = (await store.knowledge.vocabulary({ kind: "project" })).entries.find((one) => one.id === ref.slice(8));
|
|
@@ -30,7 +33,7 @@ const projectOf = async (store, reference) => {
|
|
|
30
33
|
const confirmedOf = async (store, project) => {
|
|
31
34
|
if (!project)
|
|
32
35
|
return { chats: [], people: [] };
|
|
33
|
-
const members = (await store.knowledge.relations(null, project.ref)).filter((one) => one.
|
|
36
|
+
const members = (await store.knowledge.relations(null, project.ref)).filter((one) => isUsable(one.standing) && one.kind === "member-of" && one.to === project.ref);
|
|
34
37
|
return {
|
|
35
38
|
chats: [...new Set(members.map((one) => one.from).filter((ref) => ref.startsWith("chat:")))].sort(),
|
|
36
39
|
people: [...new Set(members.map((one) => one.from).filter((ref) => ref.startsWith("person:")))].sort(),
|
|
@@ -57,8 +60,9 @@ const pairKey = ({ from, to, kind }) => `${from}\u0000${to}\u0000${kind}`;
|
|
|
57
60
|
export const combinedScore = (weights) => Math.round((1 - weights.reduce((left, weight) => left * (1 - weight), 1)) * 1000) / 1000;
|
|
58
61
|
/**
|
|
59
62
|
* Runs the scorers for one project over the sources named, combines their signals per pair, and proposes what scores
|
|
60
|
-
* `threshold` or more, highest first, at most `limit` new ones.
|
|
61
|
-
*
|
|
63
|
+
* `threshold` or more, highest first, at most `limit` new ones. What scores `threshold` or more is spread from as if
|
|
64
|
+
* linked, up to `MAX_HOPS` times, so one run reaches a member's chats in every messenger. A pair a link joins, or that
|
|
65
|
+
* was rejected once, is never proposed; a pending one is updated in place. People are matched by identity only. With `write: false`
|
|
62
66
|
* nothing is written.
|
|
63
67
|
*/
|
|
64
68
|
export const scanProjectLinks = async (store, input) => {
|
|
@@ -93,60 +97,28 @@ export const scanProjectLinks = async (store, input) => {
|
|
|
93
97
|
nameOnly: 0,
|
|
94
98
|
unresolved: 0,
|
|
95
99
|
};
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
skipped.unresolved++;
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const weight = Math.min(1, Math.max(0, candidate.weight));
|
|
116
|
-
const held = pairs.get(key) ?? { candidate, signals: new Map() };
|
|
117
|
-
const scorerId = `${scorer.id}@${scorer.version}`;
|
|
118
|
-
const before = held.signals.get(scorerId);
|
|
119
|
-
if (!before || before.weight < weight)
|
|
120
|
-
held.signals.set(scorerId, {
|
|
121
|
-
scorer: scorerId,
|
|
122
|
-
weight,
|
|
123
|
-
why: candidate.why.slice(0, 500),
|
|
124
|
-
...(candidate.purpose && scorerInput.purposes.includes(candidate.purpose)
|
|
125
|
-
? { purpose: candidate.purpose }
|
|
126
|
-
: {}),
|
|
127
|
-
});
|
|
128
|
-
held.candidate = {
|
|
129
|
-
...held.candidate,
|
|
130
|
-
evidence: [...new Set([...held.candidate.evidence, ...candidate.evidence])],
|
|
131
|
-
};
|
|
132
|
-
pairs.set(key, held);
|
|
133
|
-
}
|
|
100
|
+
const fixed = new Map();
|
|
101
|
+
const candidatesOf = async (scorer, seeds) => {
|
|
102
|
+
if (scorer.spreads)
|
|
103
|
+
return scorer.candidates({ ...scorerInput, confirmed: seeds });
|
|
104
|
+
const held = fixed.get(scorer) ?? (await scorer.candidates(scorerInput));
|
|
105
|
+
fixed.set(scorer, held);
|
|
106
|
+
return held;
|
|
107
|
+
};
|
|
108
|
+
let seeds = scorerInput.confirmed;
|
|
109
|
+
let collected = await collect(store, scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
|
|
110
|
+
for (let hop = 0; hop < MAX_HOPS && scorers.some((one) => one.spreads); hop++) {
|
|
111
|
+
const grown = await seedsOf(store, seeds, collected.scored, threshold);
|
|
112
|
+
if (!grown)
|
|
113
|
+
break;
|
|
114
|
+
seeds = grown;
|
|
115
|
+
collected = await collect(store, scorerInput, scorers, (scorer) => candidatesOf(scorer, seeds));
|
|
134
116
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const list = [...signals.values()].sort((a, b) => b.weight - a.weight || a.scorer.localeCompare(b.scorer));
|
|
138
|
-
const purpose = list.find((one) => one.purpose)?.purpose;
|
|
139
|
-
return {
|
|
140
|
-
candidate,
|
|
141
|
-
purpose,
|
|
142
|
-
signals: list.map(({ scorer, weight, why }) => ({ scorer, weight, why })),
|
|
143
|
-
score: combinedScore(list.map((one) => one.weight)),
|
|
144
|
-
};
|
|
145
|
-
})
|
|
146
|
-
.sort((a, b) => b.score - a.score || a.candidate.from.localeCompare(b.candidate.from));
|
|
117
|
+
skipped.nameOnly = collected.nameOnly;
|
|
118
|
+
skipped.unresolved = collected.unresolved;
|
|
147
119
|
const proposals = [];
|
|
148
120
|
let fresh = 0;
|
|
149
|
-
for (const { candidate, purpose, signals, score } of scored) {
|
|
121
|
+
for (const { candidate, purpose, signals, score } of collected.scored) {
|
|
150
122
|
const state = await store.knowledge.relationState(null, candidate);
|
|
151
123
|
if (!state) {
|
|
152
124
|
skipped.unresolved++;
|
|
@@ -207,6 +179,80 @@ export const scanProjectLinks = async (store, input) => {
|
|
|
207
179
|
}
|
|
208
180
|
return { project: project?.ref ?? null, proposals, skipped };
|
|
209
181
|
};
|
|
182
|
+
/** Every scorer's candidates, combined per pair and scored, highest first. */
|
|
183
|
+
const collect = async (store, input, scorers, candidatesOf) => {
|
|
184
|
+
const pairs = new Map();
|
|
185
|
+
const nameOnly = new Set();
|
|
186
|
+
let unresolved = 0;
|
|
187
|
+
for (const scorer of scorers) {
|
|
188
|
+
input.signal?.throwIfAborted();
|
|
189
|
+
for (const candidate of await candidatesOf(scorer)) {
|
|
190
|
+
const key = pairKey(candidate);
|
|
191
|
+
const verdict = await admissible(store, input, candidate);
|
|
192
|
+
if (verdict === "owner")
|
|
193
|
+
continue;
|
|
194
|
+
if (verdict === "name-only") {
|
|
195
|
+
nameOnly.add(key);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (verdict !== "ok") {
|
|
199
|
+
unresolved++;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const weight = Math.min(1, Math.max(0, candidate.weight));
|
|
203
|
+
const held = pairs.get(key) ?? { candidate, signals: new Map() };
|
|
204
|
+
const scorerId = `${scorer.id}@${scorer.version}`;
|
|
205
|
+
const before = held.signals.get(scorerId);
|
|
206
|
+
if (!before || before.weight < weight)
|
|
207
|
+
held.signals.set(scorerId, {
|
|
208
|
+
scorer: scorerId,
|
|
209
|
+
weight,
|
|
210
|
+
why: candidate.why.slice(0, 500),
|
|
211
|
+
...(candidate.purpose && input.purposes.includes(candidate.purpose) ? { purpose: candidate.purpose } : {}),
|
|
212
|
+
});
|
|
213
|
+
held.candidate = {
|
|
214
|
+
...held.candidate,
|
|
215
|
+
evidence: [...new Set([...held.candidate.evidence, ...candidate.evidence])],
|
|
216
|
+
};
|
|
217
|
+
pairs.set(key, held);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const scored = [...pairs.values()]
|
|
221
|
+
.map(({ candidate, signals }) => {
|
|
222
|
+
const list = [...signals.values()].sort((a, b) => b.weight - a.weight || a.scorer.localeCompare(b.scorer));
|
|
223
|
+
const purpose = list.find((one) => one.purpose)?.purpose;
|
|
224
|
+
return {
|
|
225
|
+
candidate,
|
|
226
|
+
purpose,
|
|
227
|
+
signals: list.map(({ scorer, weight, why }) => ({ scorer, weight, why })),
|
|
228
|
+
score: combinedScore(list.map((one) => one.weight)),
|
|
229
|
+
};
|
|
230
|
+
})
|
|
231
|
+
.sort((a, b) => b.score - a.score || a.candidate.from.localeCompare(b.candidate.from));
|
|
232
|
+
return { scored, nameOnly: nameOnly.size, unresolved };
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* The links to spread from, grown by what scored `threshold` or more and was never rejected; `undefined` when
|
|
236
|
+
* nothing new was found. Spreading in one run reaches what the owner would otherwise confirm round after round.
|
|
237
|
+
*/
|
|
238
|
+
const seedsOf = async (store, seeds, scored, threshold) => {
|
|
239
|
+
const chats = new Set(seeds.chats);
|
|
240
|
+
const people = new Set(seeds.people);
|
|
241
|
+
const size = chats.size + people.size;
|
|
242
|
+
for (const { candidate, score } of scored) {
|
|
243
|
+
if (score < threshold || candidate.kind !== "member-of")
|
|
244
|
+
continue;
|
|
245
|
+
if (chats.has(candidate.from) || people.has(candidate.from))
|
|
246
|
+
continue;
|
|
247
|
+
if ((await store.knowledge.relationState(null, candidate))?.rejected !== false)
|
|
248
|
+
continue;
|
|
249
|
+
if (candidate.from.startsWith("chat:"))
|
|
250
|
+
chats.add(candidate.from);
|
|
251
|
+
else if (candidate.from.startsWith("person:"))
|
|
252
|
+
people.add(candidate.from);
|
|
253
|
+
}
|
|
254
|
+
return chats.size + people.size === size ? undefined : { chats: [...chats].sort(), people: [...people].sort() };
|
|
255
|
+
};
|
|
210
256
|
/** A person candidate stands only on an identity that is that person's; a chat only in a source the scan reads. */
|
|
211
257
|
const admissible = async (store, input, candidate) => {
|
|
212
258
|
if (candidate.from === candidate.to || !Number.isFinite(candidate.weight))
|
|
@@ -16,8 +16,8 @@ export declare const sameAccount: (a: AccountKey, b: {
|
|
|
16
16
|
}) => boolean;
|
|
17
17
|
/** The person an identity is, as `person:<uid>`; `undefined` when the store has no person for it. */
|
|
18
18
|
export declare const personRefOf: (store: MessageStore, provider: string, id: Id) => Promise<string | undefined>;
|
|
19
|
-
/** How many projects a person is a confirmed member of. */
|
|
20
|
-
export declare const projectsOf: (store: MessageStore, person: string) => Promise<number>;
|
|
19
|
+
/** How many projects a person is a confirmed member of, counting `project` whether confirmed or only found. */
|
|
20
|
+
export declare const projectsOf: (store: MessageStore, person: string, project: string) => Promise<number>;
|
|
21
21
|
/** Each confirmed member's identities in one messenger, by member. */
|
|
22
22
|
export declare const identitiesIn: (store: MessageStore, people: readonly string[], provider: string) => Promise<{
|
|
23
23
|
person: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatReference } from "../../domain/references.js";
|
|
2
|
+
import { isUsable } from "../../domain/relations.js";
|
|
2
3
|
import { normalizeVocabularyName } from "../../domain/vocabulary.js";
|
|
3
4
|
const escaped = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4
5
|
const folded = (text) => text.normalize("NFKC").toLowerCase().replace(/\s+/gu, " ");
|
|
@@ -30,10 +31,13 @@ export const personRefOf = async (store, provider, id) => {
|
|
|
30
31
|
const person = await store.people.personOf({ provider, id });
|
|
31
32
|
return person ? `person:${person.uid}` : undefined;
|
|
32
33
|
};
|
|
33
|
-
/** How many projects a person is a confirmed member of. */
|
|
34
|
-
export const projectsOf = async (store, person) => new Set(
|
|
35
|
-
|
|
36
|
-
.
|
|
34
|
+
/** How many projects a person is a confirmed member of, counting `project` whether confirmed or only found. */
|
|
35
|
+
export const projectsOf = async (store, person, project) => new Set([
|
|
36
|
+
project,
|
|
37
|
+
...(await store.knowledge.relations(null, person))
|
|
38
|
+
.filter((one) => isUsable(one.standing) && one.kind === "member-of" && one.from === person && one.to.startsWith("project:"))
|
|
39
|
+
.map((one) => one.to),
|
|
40
|
+
]).size;
|
|
37
41
|
/** Each confirmed member's identities in one messenger, by member. */
|
|
38
42
|
export const identitiesIn = async (store, people, provider) => {
|
|
39
43
|
const found = [];
|
|
@@ -31,6 +31,7 @@ export interface ScorerInput {
|
|
|
31
31
|
store: MessageStore;
|
|
32
32
|
/** `null` for a scan with no project, which only person ↔ person rules answer. */
|
|
33
33
|
project: ScannedProject | null;
|
|
34
|
+
/** The project's confirmed chats and people, and, within one scan, what the scan already found above threshold. */
|
|
34
35
|
confirmed: {
|
|
35
36
|
chats: string[];
|
|
36
37
|
people: string[];
|
|
@@ -48,6 +49,8 @@ export interface ScorerInput {
|
|
|
48
49
|
export interface LinkScorer {
|
|
49
50
|
readonly id: string;
|
|
50
51
|
readonly version: number;
|
|
52
|
+
/** Reads `confirmed`, so a scan runs it again each time the links it spreads from grow. */
|
|
53
|
+
readonly spreads?: boolean;
|
|
51
54
|
candidates(input: ScorerInput): Promise<LinkCandidate[]>;
|
|
52
55
|
}
|
|
53
56
|
export type Signal = NonNullable<ProposalRow["signals"]>[number];
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
+
error?: undefined;
|
|
17
18
|
chatId: string;
|
|
18
19
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
19
20
|
algorithm: string;
|
|
20
21
|
fetchedAt: string | null;
|
|
21
22
|
source: string;
|
|
22
|
-
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|