@wirecat/cli-core 0.604.0 → 0.605.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 +61 -0
- package/dist/calendar/prepare.d.ts +4 -2
- package/dist/calendar/prepare.js +8 -8
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -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/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/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/index.d.ts +22 -0
- package/dist/errors/failures.d.ts +17 -1
- package/dist/errors/failures.js +57 -1
- package/dist/errors/reasons.js +16 -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 +98 -53
- package/dist/services/link-scorers/shared.d.ts +2 -2
- package/dist/services/link-scorers/shared.js +7 -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/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/index.d.ts +1 -0
- package/dist/store/index.js +1 -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/recover.js +16 -1
- package/dist/store/sqlite/finance.d.ts +8 -1
- package/dist/store/sqlite/finance.js +10 -3
- package/dist/store/sqlite/open-store.js +4 -1
- 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-separation.d.ts +5 -0
- package/dist/store/sqlite/person-separation.js +26 -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/transaction.js +2 -5
- package/dist/store/types.d.ts +5 -0
- package/package.json +3 -3
package/dist/domain/records.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { holdsCredential, secretNamed } from "../runs/secrets.js";
|
|
3
|
+
import { AMOUNT_ROLES, TYPE_PATTERN, TYPE_RULE, WORD_BODY } from "./record-types.js";
|
|
4
|
+
export { RECORD_ENTITY_TYPES } from "./record-types.js";
|
|
3
5
|
export const RECORDS_SCHEMA_VERSION = 1;
|
|
4
6
|
export const RECORD_OPERATIONS = ["upsert", "delete"];
|
|
5
|
-
|
|
6
|
-
export const RECORD_ENTITY_TYPES = ["invoice", "payment", "person", "organization", "project"];
|
|
7
|
-
const WORD = "^[a-z0-9][a-z0-9_-]{0,62}$";
|
|
8
|
-
const TYPE = "^(invoice|payment|person|organization|project|custom:[a-z0-9][a-z0-9_-]{0,62})$";
|
|
7
|
+
const WORD = `^${WORD_BODY}$`;
|
|
9
8
|
const MAX_ID = 512;
|
|
10
9
|
const MAX_FIELDS_BYTES = 65_536;
|
|
11
10
|
const MAX_RELATIONS = 100;
|
|
@@ -41,7 +40,7 @@ export const RECORDS_ENVELOPE_SCHEMA = {
|
|
|
41
40
|
additionalProperties: false,
|
|
42
41
|
properties: {
|
|
43
42
|
key: { type: "string", minLength: 1, maxLength: MAX_ID },
|
|
44
|
-
type: { type: "string", pattern:
|
|
43
|
+
type: { type: "string", pattern: TYPE_PATTERN },
|
|
45
44
|
external_id: { type: "string", minLength: 1, maxLength: MAX_ID },
|
|
46
45
|
operation: { enum: [...RECORD_OPERATIONS] },
|
|
47
46
|
fields: {
|
|
@@ -58,7 +57,7 @@ export const RECORDS_ENVELOPE_SCHEMA = {
|
|
|
58
57
|
additionalProperties: false,
|
|
59
58
|
properties: {
|
|
60
59
|
role: { type: "string", pattern: WORD },
|
|
61
|
-
type: { type: "string", pattern:
|
|
60
|
+
type: { type: "string", pattern: TYPE_PATTERN },
|
|
62
61
|
external_id: { type: "string", minLength: 1, maxLength: MAX_ID },
|
|
63
62
|
amount: {
|
|
64
63
|
type: "string",
|
|
@@ -70,7 +69,7 @@ export const RECORDS_ENVELOPE_SCHEMA = {
|
|
|
70
69
|
},
|
|
71
70
|
};
|
|
72
71
|
const wordPattern = new RegExp(WORD);
|
|
73
|
-
const typePattern = new RegExp(
|
|
72
|
+
const typePattern = new RegExp(TYPE_PATTERN);
|
|
74
73
|
const decimalPattern = new RegExp(DECIMAL);
|
|
75
74
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
76
75
|
const escapePointer = (segment) => String(segment).replaceAll("~", "~0").replaceAll("/", "~1");
|
|
@@ -115,13 +114,13 @@ const relationErrors = (relations, at) => {
|
|
|
115
114
|
if (typeof relation.role !== "string" || !wordPattern.test(relation.role))
|
|
116
115
|
return [invalid([...here, "role"], "a role is lowercase letters, digits, - and _")];
|
|
117
116
|
if (typeof relation.type !== "string" || !typePattern.test(relation.type))
|
|
118
|
-
return [invalid([...here, "type"],
|
|
117
|
+
return [invalid([...here, "type"], TYPE_RULE)];
|
|
119
118
|
if (!idText(relation.external_id))
|
|
120
119
|
return [invalid([...here, "external_id"], `an external id takes 1–${MAX_ID} characters`)];
|
|
121
120
|
if (relation.amount !== undefined && (typeof relation.amount !== "string" || !decimalPattern.test(relation.amount)))
|
|
122
121
|
return [invalid([...here, "amount"], 'an amount is a decimal string, such as "13000.00"')];
|
|
123
|
-
if (relation.amount !== undefined && relation.role
|
|
124
|
-
return [invalid([...here, "amount"],
|
|
122
|
+
if (relation.amount !== undefined && !AMOUNT_ROLES.includes(relation.role))
|
|
123
|
+
return [invalid([...here, "amount"], `only a ${AMOUNT_ROLES.join(" or ")} relation carries an amount`)];
|
|
125
124
|
return [];
|
|
126
125
|
});
|
|
127
126
|
};
|
|
@@ -143,9 +142,7 @@ export const recordErrors = (record, index) => {
|
|
|
143
142
|
if (!idText(record.key))
|
|
144
143
|
return [invalid([...at, "key"], `a key takes 1–${MAX_ID} characters`)];
|
|
145
144
|
if (typeof record.type !== "string" || !typePattern.test(record.type))
|
|
146
|
-
return withKey([
|
|
147
|
-
invalid([...at, "type"], `a type is one of ${RECORD_ENTITY_TYPES.join(", ")} or custom:<name>`, "record.type"),
|
|
148
|
-
]);
|
|
145
|
+
return withKey([invalid([...at, "type"], TYPE_RULE, "record.type")]);
|
|
149
146
|
if (!idText(record.external_id))
|
|
150
147
|
return withKey([invalid([...at, "external_id"], `an external id takes 1–${MAX_ID} characters`)]);
|
|
151
148
|
if (!RECORD_OPERATIONS.includes(record.operation))
|
|
@@ -9,6 +9,10 @@ export declare const linkedPerson: v.StrictObjectSchema<{
|
|
|
9
9
|
readonly username: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
10
10
|
readonly is_bot: v.NullableSchema<v.BooleanSchema<undefined>, undefined>;
|
|
11
11
|
readonly accounts: v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
12
|
+
readonly seen_in: v.ArraySchema<v.StrictObjectSchema<{
|
|
13
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
14
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
15
|
+
}, undefined>, undefined>;
|
|
12
16
|
readonly method: v.StringSchema<undefined>;
|
|
13
17
|
readonly linked_by: v.StringSchema<undefined>;
|
|
14
18
|
readonly linked_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
@@ -8,6 +8,7 @@ const linkedIdentity = v.strictObject({
|
|
|
8
8
|
username: v.nullable(text),
|
|
9
9
|
is_bot: v.nullable(v.boolean()),
|
|
10
10
|
accounts: v.array(id),
|
|
11
|
+
seen_in: v.array(v.strictObject({ account: id, scope: v.picklist(["personal", "work"]) })),
|
|
11
12
|
method: text,
|
|
12
13
|
linked_by: text,
|
|
13
14
|
linked_at: time,
|
|
@@ -669,6 +669,10 @@ export declare const contactContext: v.UnionSchema<[v.StrictObjectSchema<{
|
|
|
669
669
|
readonly username: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
670
670
|
readonly is_bot: v.NullableSchema<v.BooleanSchema<undefined>, undefined>;
|
|
671
671
|
readonly accounts: v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
672
|
+
readonly seen_in: v.ArraySchema<v.StrictObjectSchema<{
|
|
673
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
674
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
675
|
+
}, undefined>, undefined>;
|
|
672
676
|
readonly method: v.StringSchema<undefined>;
|
|
673
677
|
readonly linked_by: v.StringSchema<undefined>;
|
|
674
678
|
readonly linked_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
@@ -676,6 +680,12 @@ export declare const contactContext: v.UnionSchema<[v.StrictObjectSchema<{
|
|
|
676
680
|
readonly provider: v.StringSchema<undefined>;
|
|
677
681
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
678
682
|
}, undefined>;
|
|
683
|
+
/** The accounts read: only those of the scopes the caller may read. */
|
|
684
|
+
readonly accounts: v.ArraySchema<v.StrictObjectSchema<{
|
|
685
|
+
readonly provider: v.StringSchema<undefined>;
|
|
686
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
687
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
688
|
+
}, undefined>, undefined>;
|
|
679
689
|
readonly shared: v.ArraySchema<v.StrictObjectSchema<{
|
|
680
690
|
readonly provider: v.StringSchema<undefined>;
|
|
681
691
|
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
@@ -1459,6 +1469,10 @@ export declare const contactPreparation: v.StrictObjectSchema<{
|
|
|
1459
1469
|
readonly username: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
1460
1470
|
readonly is_bot: v.NullableSchema<v.BooleanSchema<undefined>, undefined>;
|
|
1461
1471
|
readonly accounts: v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
1472
|
+
readonly seen_in: v.ArraySchema<v.StrictObjectSchema<{
|
|
1473
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
1474
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
1475
|
+
}, undefined>, undefined>;
|
|
1462
1476
|
readonly method: v.StringSchema<undefined>;
|
|
1463
1477
|
readonly linked_by: v.StringSchema<undefined>;
|
|
1464
1478
|
readonly linked_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
@@ -1466,6 +1480,12 @@ export declare const contactPreparation: v.StrictObjectSchema<{
|
|
|
1466
1480
|
readonly provider: v.StringSchema<undefined>;
|
|
1467
1481
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
1468
1482
|
}, undefined>;
|
|
1483
|
+
/** The accounts read: only those of the scopes the caller may read. */
|
|
1484
|
+
readonly accounts: v.ArraySchema<v.StrictObjectSchema<{
|
|
1485
|
+
readonly provider: v.StringSchema<undefined>;
|
|
1486
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
1487
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
1488
|
+
}, undefined>, undefined>;
|
|
1469
1489
|
readonly shared: v.ArraySchema<v.StrictObjectSchema<{
|
|
1470
1490
|
readonly provider: v.StringSchema<undefined>;
|
|
1471
1491
|
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
@@ -36,6 +36,8 @@ export const contextEvent = v.strictObject({
|
|
|
36
36
|
});
|
|
37
37
|
const context = v.strictObject({
|
|
38
38
|
person: contextPerson,
|
|
39
|
+
/** The accounts read: only those of the scopes the caller may read. */
|
|
40
|
+
accounts: v.array(v.strictObject({ provider: text, account: id, scope: v.picklist(["personal", "work"]) })),
|
|
39
41
|
shared: v.array(sharedChat),
|
|
40
42
|
last: v.strictObject({
|
|
41
43
|
from_them: v.nullable(contextMessage),
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -2689,6 +2689,10 @@ export declare const ENTITIES: {
|
|
|
2689
2689
|
readonly username: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
2690
2690
|
readonly is_bot: v.NullableSchema<v.BooleanSchema<undefined>, undefined>;
|
|
2691
2691
|
readonly accounts: v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
2692
|
+
readonly seen_in: v.ArraySchema<v.StrictObjectSchema<{
|
|
2693
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
2694
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
2695
|
+
}, undefined>, undefined>;
|
|
2692
2696
|
readonly method: v.StringSchema<undefined>;
|
|
2693
2697
|
readonly linked_by: v.StringSchema<undefined>;
|
|
2694
2698
|
readonly linked_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
@@ -2696,6 +2700,11 @@ export declare const ENTITIES: {
|
|
|
2696
2700
|
readonly provider: v.StringSchema<undefined>;
|
|
2697
2701
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
2698
2702
|
}, undefined>;
|
|
2703
|
+
readonly accounts: v.ArraySchema<v.StrictObjectSchema<{
|
|
2704
|
+
readonly provider: v.StringSchema<undefined>;
|
|
2705
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
2706
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
2707
|
+
}, undefined>, undefined>;
|
|
2699
2708
|
readonly shared: v.ArraySchema<v.StrictObjectSchema<{
|
|
2700
2709
|
readonly provider: v.StringSchema<undefined>;
|
|
2701
2710
|
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
@@ -3465,6 +3474,10 @@ export declare const ENTITIES: {
|
|
|
3465
3474
|
readonly username: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
3466
3475
|
readonly is_bot: v.NullableSchema<v.BooleanSchema<undefined>, undefined>;
|
|
3467
3476
|
readonly accounts: v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
3477
|
+
readonly seen_in: v.ArraySchema<v.StrictObjectSchema<{
|
|
3478
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
3479
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
3480
|
+
}, undefined>, undefined>;
|
|
3468
3481
|
readonly method: v.StringSchema<undefined>;
|
|
3469
3482
|
readonly linked_by: v.StringSchema<undefined>;
|
|
3470
3483
|
readonly linked_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
@@ -3472,6 +3485,11 @@ export declare const ENTITIES: {
|
|
|
3472
3485
|
readonly provider: v.StringSchema<undefined>;
|
|
3473
3486
|
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
3474
3487
|
}, undefined>;
|
|
3488
|
+
readonly accounts: v.ArraySchema<v.StrictObjectSchema<{
|
|
3489
|
+
readonly provider: v.StringSchema<undefined>;
|
|
3490
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
3491
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
3492
|
+
}, undefined>, undefined>;
|
|
3475
3493
|
readonly shared: v.ArraySchema<v.StrictObjectSchema<{
|
|
3476
3494
|
readonly provider: v.StringSchema<undefined>;
|
|
3477
3495
|
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
@@ -3748,6 +3766,10 @@ export declare const ENTITIES: {
|
|
|
3748
3766
|
readonly username: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
3749
3767
|
readonly is_bot: v.NullableSchema<v.BooleanSchema<undefined>, undefined>;
|
|
3750
3768
|
readonly accounts: v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>, undefined>;
|
|
3769
|
+
readonly seen_in: v.ArraySchema<v.StrictObjectSchema<{
|
|
3770
|
+
readonly account: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
3771
|
+
readonly scope: v.PicklistSchema<["personal", "work"], undefined>;
|
|
3772
|
+
}, undefined>, undefined>;
|
|
3751
3773
|
readonly method: v.StringSchema<undefined>;
|
|
3752
3774
|
readonly linked_by: v.StringSchema<undefined>;
|
|
3753
3775
|
readonly linked_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
/**
|
|
3
3
|
* **By shape, not by class.** A package linked during development brings its own copy of
|
|
4
4
|
* cli-base, and an error built with one copy is not an `instanceof` the other's `CliError` —
|
|
@@ -14,3 +14,19 @@ export declare const isCommanderFailure: (value: unknown) => value is Error & {
|
|
|
14
14
|
};
|
|
15
15
|
/** What failed, never what it said: a messenger's refusal can quote the message back. */
|
|
16
16
|
export declare const failureKey: (error: unknown) => string;
|
|
17
|
+
/**
|
|
18
|
+
* SQLite's primary result code: node:sqlite's `errcode`, or `errno` only on bun:sqlite's `SQLiteError`. A filesystem
|
|
19
|
+
* error's errno shares the low byte with SQLite's codes: Windows' EIO, -4070, reads as SQLITE_NOTADB.
|
|
20
|
+
*/
|
|
21
|
+
export declare const sqliteCode: (error: unknown) => number | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* A damaged store file as the owner's problem, not a bug: SQLITE_CORRUPT or SQLITE_NOTADB becomes `store.damaged`.
|
|
24
|
+
* `next` is the command line that says what to do, such as `tg store recover`, only where that command exists.
|
|
25
|
+
* Only for the CLI's own store: a file the owner named goes through `damagedFile`. Any other failure is returned as
|
|
26
|
+
* it came.
|
|
27
|
+
*/
|
|
28
|
+
export declare const storeDamaged: (error: unknown, next?: string) => unknown;
|
|
29
|
+
/** Runs `work` on store files the owner named, so a damaged one is named rather than taken for the CLI's own. */
|
|
30
|
+
export declare const damagedFile: <T>(files: readonly string[], work: () => Promise<T>) => Promise<T>;
|
|
31
|
+
/** Whether `error` is SQLite saying the database file is damaged. */
|
|
32
|
+
export declare const isStoreDamage: (error: unknown) => boolean;
|
package/dist/errors/failures.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { errorCodes } from "@wirecat/cli-base";
|
|
1
|
+
import { CliError, errorCodes } from "@wirecat/cli-base";
|
|
2
2
|
/**
|
|
3
3
|
* **By shape, not by class.** A package linked during development brings its own copy of
|
|
4
4
|
* cli-base, and an error built with one copy is not an `instanceof` the other's `CliError` —
|
|
@@ -16,3 +16,59 @@ export const isCommanderFailure = (value) => {
|
|
|
16
16
|
};
|
|
17
17
|
/** What failed, never what it said: a messenger's refusal can quote the message back. */
|
|
18
18
|
export const failureKey = (error) => isCliFailure(error) ? error.code : error instanceof Error ? error.name : "error";
|
|
19
|
+
const SQLITE_CORRUPT = 11;
|
|
20
|
+
const SQLITE_NOTADB = 26;
|
|
21
|
+
const DAMAGED_TEXT = /database disk image is malformed|file is not a database|fts5: corruption/i;
|
|
22
|
+
/**
|
|
23
|
+
* SQLite's primary result code: node:sqlite's `errcode`, or `errno` only on bun:sqlite's `SQLiteError`. A filesystem
|
|
24
|
+
* error's errno shares the low byte with SQLite's codes: Windows' EIO, -4070, reads as SQLITE_NOTADB.
|
|
25
|
+
*/
|
|
26
|
+
export const sqliteCode = (error) => {
|
|
27
|
+
const { errcode, errno, name } = (error ?? {});
|
|
28
|
+
const code = typeof errcode === "number" ? errcode : name === "SQLiteError" && typeof errno === "number" ? errno : null;
|
|
29
|
+
return code === null ? undefined : code & 0xff;
|
|
30
|
+
};
|
|
31
|
+
/** The SQLite failure that says the database file is damaged, on the error or up to five `cause`s behind it. */
|
|
32
|
+
const damageIn = (error) => {
|
|
33
|
+
if (isCliFailure(error) || isCommanderFailure(error))
|
|
34
|
+
return undefined;
|
|
35
|
+
let at = error;
|
|
36
|
+
for (let depth = 0; depth < 5 && at instanceof Error; depth += 1) {
|
|
37
|
+
const code = sqliteCode(at);
|
|
38
|
+
if ((code !== undefined && [SQLITE_CORRUPT, SQLITE_NOTADB].includes(code)) || DAMAGED_TEXT.test(at.message))
|
|
39
|
+
return at;
|
|
40
|
+
at = at.cause;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|
|
44
|
+
// The record's frames are where SQLite failed, not where the failure was renamed.
|
|
45
|
+
const wrapping = (error, original) => {
|
|
46
|
+
Object.defineProperty(error, "cause", { value: original, configurable: true, writable: true });
|
|
47
|
+
if (original instanceof Error && original.stack)
|
|
48
|
+
error.stack = original.stack;
|
|
49
|
+
return error;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A damaged store file as the owner's problem, not a bug: SQLITE_CORRUPT or SQLITE_NOTADB becomes `store.damaged`.
|
|
53
|
+
* `next` is the command line that says what to do, such as `tg store recover`, only where that command exists.
|
|
54
|
+
* Only for the CLI's own store: a file the owner named goes through `damagedFile`. Any other failure is returned as
|
|
55
|
+
* it came.
|
|
56
|
+
*/
|
|
57
|
+
export const storeDamaged = (error, next) => damageIn(error)
|
|
58
|
+
? wrapping(new CliError("configuration_error", `the store file is damaged${next ? `; \`${next}\` says what is damaged and what to do` : ""}`, { reason: "store.damaged" }), error)
|
|
59
|
+
: error;
|
|
60
|
+
/** Runs `work` on store files the owner named, so a damaged one is named rather than taken for the CLI's own. */
|
|
61
|
+
export const damagedFile = async (files, work) => {
|
|
62
|
+
try {
|
|
63
|
+
return await work();
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (!damageIn(error))
|
|
67
|
+
throw error;
|
|
68
|
+
throw wrapping(new CliError("validation_error", `${files.join(" or ")} is damaged or not a database`, {
|
|
69
|
+
reason: "store.file-damaged",
|
|
70
|
+
}), error);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** Whether `error` is SQLite saying the database file is damaged. */
|
|
74
|
+
export const isStoreDamage = (error) => damageIn(error) !== undefined;
|
package/dist/errors/reasons.js
CHANGED
|
@@ -157,6 +157,17 @@ const OTHERS = [
|
|
|
157
157
|
],
|
|
158
158
|
validation("store.refused", "the local store refused the document text"),
|
|
159
159
|
["store.not-writable", "permission_error", "the message store cannot be written from this process"],
|
|
160
|
+
[
|
|
161
|
+
"store.damaged",
|
|
162
|
+
"configuration_error",
|
|
163
|
+
"the store file is damaged; store recover says what is lost and recovers it",
|
|
164
|
+
],
|
|
165
|
+
validation("store.file-damaged", "the named store file is damaged or not a database"),
|
|
166
|
+
[
|
|
167
|
+
"store.unreadable",
|
|
168
|
+
"configuration_error",
|
|
169
|
+
"the store file's header or schema is damaged, so it cannot be recovered",
|
|
170
|
+
],
|
|
160
171
|
validation("store.in-use", "a process or a scheduled timer has the store open; stop it, then recover the store"),
|
|
161
172
|
[
|
|
162
173
|
"store.sqlite3-missing",
|
|
@@ -240,6 +251,11 @@ const OTHERS = [
|
|
|
240
251
|
validation("order.status", "a rejected or deleted order's status does not change"),
|
|
241
252
|
["model.not-downloaded", "not_found", "the model is not downloaded on this machine"],
|
|
242
253
|
["person.no-owner", "not_found", "no person is marked as the owner in the store"],
|
|
254
|
+
[
|
|
255
|
+
"identity.separated",
|
|
256
|
+
"conflict",
|
|
257
|
+
"the owner separated this identity from that person; only the owner links it again",
|
|
258
|
+
],
|
|
243
259
|
["transcription.no-key", "authentication_error", "no OpenAI key is set for transcription"],
|
|
244
260
|
validation("transcription.too-large", "the audio is over the transcription provider's size limit"),
|
|
245
261
|
[
|
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>;
|