@wirecat/cli-core 0.614.0 → 0.616.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/dist/background/report/messages.d.ts +108 -0
  3. package/dist/background/report/messages.js +230 -0
  4. package/dist/background/report/render.d.ts +41 -5
  5. package/dist/background/report/render.js +115 -25
  6. package/dist/background/report/schema.d.ts +7 -1
  7. package/dist/background/report/schema.js +9 -3
  8. package/dist/background/report/stored-templates.d.ts +66 -0
  9. package/dist/background/report/stored-templates.js +85 -0
  10. package/dist/background/report/templates/morning-digest.email.en.liquid +3 -0
  11. package/dist/background/report/templates/morning-digest.email.ru.liquid +3 -0
  12. package/dist/background/report/templates/morning-digest.sample.json +157 -0
  13. package/dist/background/report/templates/morning-digest.telegram.en.liquid +3 -0
  14. package/dist/background/report/templates/morning-digest.telegram.ru.liquid +3 -0
  15. package/dist/background/report/templates/morning-digest.text.en.liquid +3 -0
  16. package/dist/background/report/templates/morning-digest.text.ru.liquid +3 -0
  17. package/dist/background/report/templates/schedule-failed.email.en.liquid +12 -0
  18. package/dist/background/report/templates/schedule-failed.email.ru.liquid +12 -0
  19. package/dist/background/report/templates/schedule-failed.sample.json +10 -0
  20. package/dist/background/report/templates/schedule-failed.telegram.en.liquid +9 -0
  21. package/dist/background/report/templates/schedule-failed.telegram.ru.liquid +9 -0
  22. package/dist/background/report/templates/schedule-failed.text.en.liquid +9 -0
  23. package/dist/background/report/templates/schedule-failed.text.ru.liquid +9 -0
  24. package/dist/background/report/templates/weekly-gaps.email.en.liquid +19 -0
  25. package/dist/background/report/templates/weekly-gaps.email.ru.liquid +19 -0
  26. package/dist/background/report/templates/weekly-gaps.sample.json +33 -0
  27. package/dist/background/report/templates/weekly-gaps.telegram.en.liquid +15 -0
  28. package/dist/background/report/templates/weekly-gaps.telegram.ru.liquid +15 -0
  29. package/dist/background/report/templates/weekly-gaps.text.en.liquid +14 -0
  30. package/dist/background/report/templates/weekly-gaps.text.ru.liquid +14 -0
  31. package/dist/background/report/view.d.ts +5 -0
  32. package/dist/background/report/view.js +9 -1
  33. package/dist/background/schedules.d.ts +13 -2
  34. package/dist/background/schedules.js +128 -30
  35. package/dist/cli/help/sections.js +1 -0
  36. package/dist/cli/index.d.ts +2 -1
  37. package/dist/cli/index.js +1 -1
  38. package/dist/cli/schedule/schedule-command.d.ts +2 -0
  39. package/dist/cli/schedule/schedule-command.js +21 -2
  40. package/dist/cli/shared-command-exports.d.ts +1 -0
  41. package/dist/cli/shared-command-exports.js +2 -0
  42. package/dist/cli/templates-command.d.ts +16 -0
  43. package/dist/cli/templates-command.js +266 -0
  44. package/dist/domain/links.d.ts +1 -1
  45. package/dist/domain/links.js +1 -1
  46. package/dist/entities/fact.d.ts +4 -0
  47. package/dist/entities/fact.js +2 -1
  48. package/dist/entities/fields.d.ts +5 -0
  49. package/dist/entities/fields.js +3 -0
  50. package/dist/entities/index.d.ts +21 -1
  51. package/dist/entities/index.js +3 -1
  52. package/dist/entities/list-results.d.ts +4 -2
  53. package/dist/entities/list-results.js +4 -2
  54. package/dist/entities/memory.d.ts +4 -0
  55. package/dist/entities/memory.js +2 -1
  56. package/dist/entities/template.d.ts +11 -0
  57. package/dist/entities/template.js +12 -0
  58. package/dist/errors/reasons.js +13 -0
  59. package/dist/meetings/mcp/index.d.ts +15 -15
  60. package/dist/services/metadata.d.ts +1 -1
  61. package/dist/store/exports.d.ts +2 -0
  62. package/dist/store/exports.js +2 -0
  63. package/dist/store/index.d.ts +4 -2
  64. package/dist/store/index.js +1 -0
  65. package/dist/store/people.d.ts +7 -0
  66. package/dist/store/people.js +4 -0
  67. package/dist/store/source-review.d.ts +21 -0
  68. package/dist/store/sqlite/accounts.d.ts +3 -1
  69. package/dist/store/sqlite/accounts.js +10 -3
  70. package/dist/store/sqlite/added-sources.d.ts +16 -0
  71. package/dist/store/sqlite/added-sources.js +22 -0
  72. package/dist/store/sqlite/facts.js +3 -2
  73. package/dist/store/sqlite/imported-documents.js +3 -2
  74. package/dist/store/sqlite/knowledge.js +6 -4
  75. package/dist/store/sqlite/manifest.js +1 -0
  76. package/dist/store/sqlite/memories.js +5 -4
  77. package/dist/store/sqlite/mention-drain.js +9 -1
  78. package/dist/store/sqlite/merged-persons.d.ts +24 -0
  79. package/dist/store/sqlite/merged-persons.js +59 -0
  80. package/dist/store/sqlite/migrations.generated.js +8 -0
  81. package/dist/store/sqlite/notes.js +5 -4
  82. package/dist/store/sqlite/person-links.d.ts +10 -1
  83. package/dist/store/sqlite/person-links.js +14 -6
  84. package/dist/store/sqlite/person-merges.d.ts +39 -0
  85. package/dist/store/sqlite/person-merges.js +136 -0
  86. package/dist/store/sqlite/person-preparation.js +11 -8
  87. package/dist/store/sqlite/person-resolution.js +2 -1
  88. package/dist/store/sqlite/person-scope.js +2 -1
  89. package/dist/store/sqlite/relation-list.js +3 -2
  90. package/dist/store/sqlite/reported-relations.js +6 -3
  91. package/dist/store/sqlite/schema/templates.d.ts +242 -0
  92. package/dist/store/sqlite/schema/templates.js +23 -0
  93. package/dist/store/sqlite/schema.d.ts +1 -0
  94. package/dist/store/sqlite/schema.js +1 -0
  95. package/dist/store/sqlite/source-review.d.ts +20 -1
  96. package/dist/store/sqlite/source-review.js +74 -3
  97. package/dist/store/sqlite/task-board.d.ts +6 -1
  98. package/dist/store/sqlite/task-board.js +22 -4
  99. package/dist/store/sqlite/templates.d.ts +38 -0
  100. package/dist/store/sqlite/templates.js +69 -0
  101. package/dist/store/sqlite/work-tasks.js +8 -9
  102. package/dist/store/store.d.ts +3 -0
  103. package/dist/store/store.js +5 -0
  104. package/dist/store/types.d.ts +2 -0
  105. package/package.json +4 -4
  106. package/parity.json +19 -0
@@ -46,11 +46,13 @@ export const scheduledJob = v.strictObject({
46
46
  failing_since: v.optional(time),
47
47
  failures: v.optional(v.number()),
48
48
  cost_usd: v.optional(v.number()),
49
- /** The last time a run did not start, and why: the day's cost cap, or too little new mail. */
49
+ input_hash: v.optional(text),
50
+ /** The last time a run did not start, and why: the day's cost cap, too little new mail, or the same input. */
50
51
  skipped: v.optional(v.strictObject({
51
52
  at: time,
52
53
  why: text,
53
- /** A dotted id for `why`, so a client can translate it: `cost.day-cap`, `mail.none-new`, `mail.below-threshold`. */
54
+ /** A dotted id for `why`, so a client can translate it: `cost.day-cap`, `mail.none-new`, `mail.below-threshold`,
55
+ * `mail.same-input`. */
54
56
  reason: v.optional(v.pipe(text, v.regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/))),
55
57
  })),
56
58
  /** How the run's result went along each route; `reason` a dotted id, `error` the sending CLI's code and reason id. */
@@ -34,6 +34,10 @@ export declare const memory: v.StrictObjectSchema<{
34
34
  readonly missing: v.BooleanSchema<undefined>;
35
35
  }, undefined>, undefined>, undefined>;
36
36
  readonly last_verified_at: v.NullableSchema<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`">]>, undefined>;
37
+ readonly source_review: v.OptionalSchema<v.NullableSchema<v.StrictObjectSchema<{
38
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
39
+ readonly cause: v.PicklistSchema<readonly ["changed", "outdated", "deleted", "contradicted"], undefined>;
40
+ }, undefined>, undefined>, undefined>;
37
41
  readonly created_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`">]>;
38
42
  readonly updated_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`">]>;
39
43
  }, undefined>;
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { MEMORY_KINDS, MEMORY_SCOPES, MEMORY_STATUSES } from "../domain/knowledge.js";
3
- import { author, evidenceSource, id, reference, text, time } from "./fields.js";
3
+ import { author, evidenceSource, id, reference, sourceReview, text, time } from "./fields.js";
4
4
  export const memory = v.strictObject({
5
5
  ref: reference,
6
6
  id,
@@ -23,6 +23,7 @@ export const memory = v.strictObject({
23
23
  /** With `--sources`: each piece of evidence read back. */
24
24
  sources: v.optional(v.array(evidenceSource)),
25
25
  last_verified_at: v.nullable(time),
26
+ source_review: v.optional(sourceReview),
26
27
  created_at: time,
27
28
  updated_at: time,
28
29
  });
@@ -0,0 +1,11 @@
1
+ import * as v from "valibot";
2
+ export declare const template: v.StrictObjectSchema<{
3
+ readonly key: v.StringSchema<undefined>;
4
+ readonly channel: v.PicklistSchema<["telegram", "email", "text"], undefined>;
5
+ readonly language: v.StringSchema<undefined>;
6
+ readonly about: v.StringSchema<undefined>;
7
+ readonly renders: v.BooleanSchema<undefined>;
8
+ readonly source: v.PicklistSchema<["stored", "default"], undefined>;
9
+ readonly updated_at: v.NullableSchema<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`">]>, undefined>;
10
+ readonly updated_by: v.NullableSchema<v.StringSchema<undefined>, undefined>;
11
+ }, undefined>;
@@ -0,0 +1,12 @@
1
+ import * as v from "valibot";
2
+ import { text, time } from "./fields.js";
3
+ export const template = v.strictObject({
4
+ key: text,
5
+ channel: v.picklist(["telegram", "email", "text"]),
6
+ language: text,
7
+ about: text,
8
+ renders: v.boolean(),
9
+ source: v.picklist(["stored", "default"]),
10
+ updated_at: v.nullable(time),
11
+ updated_by: v.nullable(text),
12
+ });
@@ -338,6 +338,12 @@ const OTHERS = [
338
338
  "conflict",
339
339
  "the owner separated this identity from that person; only the owner links it again",
340
340
  ],
341
+ ["identity.owner-only", "permission_error", "only the owner undoes a merge or splits a person"],
342
+ [
343
+ "identity.stale",
344
+ "conflict",
345
+ "an identity of the merge was merged on into another person since; undo that merge first",
346
+ ],
341
347
  ["transcription.no-key", "authentication_error", "no OpenAI key is set for transcription"],
342
348
  validation("transcription.too-large", "the audio is over the transcription provider's size limit"),
343
349
  [
@@ -396,6 +402,13 @@ const OTHERS = [
396
402
  validation("tag-review.required", "the tag needs the owner's review first"),
397
403
  ["tag-review.stale", "configuration_error", "the tag review changed meanwhile"],
398
404
  validation("tag.invalid", "the tag is not valid"),
405
+ validation("template.unknown-key", "there is no message template by that key"),
406
+ validation("template.no-renderer", "nothing renders that template key yet, so a template for it cannot be checked"),
407
+ validation("template.unknown-language", "cli-core ships no template in that language, so one would never be used"),
408
+ validation("template.check-failed", "the template failed its check and was not saved; the message says why"),
409
+ validation("template.no-history", "the template has no earlier body to put back"),
410
+ validation("template.no-editor", "no editor is set: set VISUAL or EDITOR, or pass the template with --file"),
411
+ ["template.owner-only", "permission_error", "only the owner changes a message template, not an agent"],
399
412
  ["reactions.list-hidden", "permission_error", "the chat does not let its members see who reacted"],
400
413
  ["reactions.broadcast", "permission_error", "a channel does not show who reacted to its posts"],
401
414
  validation("task.external-id", "an external id is <service>:<id>, such as avito:4512345678"),
@@ -38,6 +38,7 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
+ limit?: undefined;
41
42
  event_id?: undefined;
42
43
  series_id?: undefined;
43
44
  page?: undefined;
@@ -53,11 +54,11 @@ export declare const meetingTools: ({
53
54
  format?: undefined;
54
55
  transcript_id?: undefined;
55
56
  query?: undefined;
56
- limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
+ limit?: undefined;
61
62
  event_id?: undefined;
62
63
  series_id?: undefined;
63
64
  page?: undefined;
@@ -75,11 +76,11 @@ export declare const meetingTools: ({
75
76
  format?: undefined;
76
77
  transcript_id?: undefined;
77
78
  query?: undefined;
78
- limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
+ limit?: undefined;
83
84
  event_id?: undefined;
84
85
  series_id?: undefined;
85
86
  page?: undefined;
@@ -101,7 +102,6 @@ export declare const meetingTools: ({
101
102
  minimum: number;
102
103
  };
103
104
  query?: undefined;
104
- limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,6 +188,7 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
+ limit?: undefined;
191
192
  event_id?: undefined;
192
193
  series_id?: undefined;
193
194
  page?: undefined;
@@ -203,11 +204,11 @@ export declare const meetingTools: ({
203
204
  format?: undefined;
204
205
  transcript_id?: undefined;
205
206
  query?: undefined;
206
- limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
+ limit?: undefined;
211
212
  event_id?: undefined;
212
213
  series_id?: undefined;
213
214
  page?: undefined;
@@ -225,11 +226,11 @@ export declare const meetingTools: ({
225
226
  format?: undefined;
226
227
  transcript_id?: undefined;
227
228
  query?: undefined;
228
- limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
+ limit?: undefined;
233
234
  event_id?: undefined;
234
235
  series_id?: undefined;
235
236
  page?: undefined;
@@ -251,7 +252,6 @@ export declare const meetingTools: ({
251
252
  minimum: number;
252
253
  };
253
254
  query?: undefined;
254
- limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,6 +338,7 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
+ limit?: undefined;
341
342
  event_id?: undefined;
342
343
  series_id?: undefined;
343
344
  page?: undefined;
@@ -353,11 +354,11 @@ export declare const meetingTools: ({
353
354
  format?: undefined;
354
355
  transcript_id?: undefined;
355
356
  query?: undefined;
356
- limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
+ limit?: undefined;
361
362
  event_id?: undefined;
362
363
  series_id?: undefined;
363
364
  page?: undefined;
@@ -375,11 +376,11 @@ export declare const meetingTools: ({
375
376
  format?: undefined;
376
377
  transcript_id?: undefined;
377
378
  query?: undefined;
378
- limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
+ limit?: undefined;
383
384
  event_id?: undefined;
384
385
  series_id?: undefined;
385
386
  page?: undefined;
@@ -401,7 +402,6 @@ export declare const meetingTools: ({
401
402
  minimum: number;
402
403
  };
403
404
  query?: undefined;
404
- limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,6 +488,7 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
+ limit?: undefined;
491
492
  event_id?: undefined;
492
493
  series_id?: undefined;
493
494
  page?: undefined;
@@ -503,11 +504,11 @@ export declare const meetingTools: ({
503
504
  format?: undefined;
504
505
  transcript_id?: undefined;
505
506
  query?: undefined;
506
- limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
+ limit?: undefined;
511
512
  event_id?: undefined;
512
513
  series_id?: undefined;
513
514
  page?: undefined;
@@ -525,11 +526,11 @@ export declare const meetingTools: ({
525
526
  format?: undefined;
526
527
  transcript_id?: undefined;
527
528
  query?: undefined;
528
- limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
+ limit?: undefined;
533
534
  event_id?: undefined;
534
535
  series_id?: undefined;
535
536
  page?: undefined;
@@ -551,7 +552,6 @@ export declare const meetingTools: ({
551
552
  minimum: number;
552
553
  };
553
554
  query?: undefined;
554
- limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,6 +638,7 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
+ limit?: undefined;
641
642
  event_id?: undefined;
642
643
  series_id?: undefined;
643
644
  page?: undefined;
@@ -653,11 +654,11 @@ export declare const meetingTools: ({
653
654
  format?: undefined;
654
655
  transcript_id?: undefined;
655
656
  query?: undefined;
656
- limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
+ limit?: undefined;
661
662
  event_id?: undefined;
662
663
  series_id?: undefined;
663
664
  page?: undefined;
@@ -675,11 +676,11 @@ export declare const meetingTools: ({
675
676
  format?: undefined;
676
677
  transcript_id?: undefined;
677
678
  query?: undefined;
678
- limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
+ limit?: undefined;
683
684
  event_id?: undefined;
684
685
  series_id?: undefined;
685
686
  page?: undefined;
@@ -701,7 +702,6 @@ export declare const meetingTools: ({
701
702
  minimum: number;
702
703
  };
703
704
  query?: undefined;
704
- limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
14
14
  dryRun?: boolean;
15
15
  }) => Promise<{
16
16
  items: ({
17
- error?: undefined;
18
17
  chatId: string;
19
18
  tags: import("../domain/channel-tags.js").ChannelTagMatch[];
20
19
  algorithm: string;
21
20
  fetchedAt: string | null;
22
21
  source: string;
22
+ error?: undefined;
23
23
  } | {
24
24
  tags?: undefined;
25
25
  algorithm?: undefined;
@@ -40,6 +40,7 @@ export { drainNoteIndex, noteIndexState, resetNoteIndex } from "./sqlite/note-in
40
40
  export type { Link as ThingLink } from "./sqlite/notes.js";
41
41
  export { openSqlite } from "./sqlite/open.js";
42
42
  export { DEFAULT_OWNER_LANGUAGES, ownerLanguages, parseOwnerLanguages, savedOwnerLanguages, saveOwnerLanguages, } from "./sqlite/owner-languages.js";
43
+ export { mergeId, type PersonMerge, parseMergeId } from "./sqlite/person-merges.js";
43
44
  export type { PersonPreparationRead, PreparationFact, PreparationNote, PreparationTask, } from "./sqlite/person-preparation.js";
44
45
  export { savedPhoneCountries, saveStorePhoneCountries } from "./sqlite/phone-countries.js";
45
46
  export type { PrivateContact, PrivateContactNote } from "./sqlite/private-people.js";
@@ -60,6 +61,7 @@ export { savedTaskCategories } from "./sqlite/task-category-settings.js";
60
61
  export { DEFAULT_AGENT_CLOSE, savedAgentClose } from "./sqlite/task-close.js";
61
62
  export { DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, savedFirstPassPerChat } from "./sqlite/task-first-pass.js";
62
63
  export { inboxKey } from "./sqlite/tasks.js";
64
+ export { storedTemplateBodies, type TemplateAddress } from "./sqlite/templates.js";
63
65
  export { THREAD_COLUMNS } from "./sqlite/thread-columns.js";
64
66
  export { dropAllUnusedVectors, vectorIndexCounts } from "./sqlite/vector-index.js";
65
67
  export type { MatchPlace, ScoredHit } from "./sqlite/words.js";
@@ -19,6 +19,7 @@ export { MENTION_QUERY, MENTION_STATUSES, } from "./sqlite/mentions.js";
19
19
  export { drainNoteIndex, noteIndexState, resetNoteIndex } from "./sqlite/note-index.js";
20
20
  export { openSqlite } from "./sqlite/open.js";
21
21
  export { DEFAULT_OWNER_LANGUAGES, ownerLanguages, parseOwnerLanguages, savedOwnerLanguages, saveOwnerLanguages, } from "./sqlite/owner-languages.js";
22
+ export { mergeId, parseMergeId } from "./sqlite/person-merges.js";
22
23
  export { savedPhoneCountries, saveStorePhoneCountries } from "./sqlite/phone-countries.js";
23
24
  export { queryFilter } from "./sqlite/query-filter.js";
24
25
  export { AGENDA_COLUMNS } from "./sqlite/reads.js";
@@ -30,5 +31,6 @@ export { savedTaskCategories } from "./sqlite/task-category-settings.js";
30
31
  export { DEFAULT_AGENT_CLOSE, savedAgentClose } from "./sqlite/task-close.js";
31
32
  export { DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, savedFirstPassPerChat } from "./sqlite/task-first-pass.js";
32
33
  export { inboxKey } from "./sqlite/tasks.js";
34
+ export { storedTemplateBodies } from "./sqlite/templates.js";
33
35
  export { THREAD_COLUMNS } from "./sqlite/thread-columns.js";
34
36
  export { dropAllUnusedVectors, vectorIndexCounts } from "./sqlite/vector-index.js";
@@ -32,8 +32,8 @@ export { type ProjectAnnotationPreview, type ProjectAnnotationPreviewOptions, pr
32
32
  export { decodeProjectAnnotationSnapshot, type ProjectAnnotationSnapshot, type ProjectAnnotationSnapshotOptions, type ProjectAnnotationSnapshotResult, projectAnnotationSnapshotFingerprint, projectAnnotationSnapshotSchema, snapshotProjectAnnotations, } from "./project-transfer/snapshot.js";
33
33
  export { planProjectAnnotationSnapshot } from "./project-transfer/snapshot-plan.js";
34
34
  export type { ProjectAnnotationRestoreReceipt, ProjectAnnotationRestoreRequest, ProjectAnnotationStore, ProjectAnnotationTargetRequest, } from "./project-transfer/store.js";
35
- export { SOURCE_REVIEW_CAUSES, SOURCE_REVIEW_KIND, type SourceCheck, type SourceReviewCause, type SourceReviewChallenge, type SourceReviewMarker, type SourceReviewPayload, type SourceReviewSource, } from "./source-review.js";
36
- export { ADDED_KINDS, type AddedSource, type AddedSourceContent, type AddedSourceInput, addedSourceKeyOf, } from "./sqlite/added-sources.js";
35
+ export { type ChangedSource, SOURCE_REVIEW_CAUSES, SOURCE_REVIEW_KIND, type SourceCheck, type SourceReviewCause, type SourceReviewChallenge, type SourceReviewMarker, type SourceReviewPayload, type SourceReviewSource, type SourceReviewText, } from "./source-review.js";
36
+ export { ADDED_KINDS, type AddedSource, type AddedSourceContent, type AddedSourceDetails, type AddedSourceInput, addedSourceKeyOf, } from "./sqlite/added-sources.js";
37
37
  export type { AgentAction, AgentActionInput, AgentActionsStore } from "./sqlite/agent-actions.js";
38
38
  export { resetAttachmentWords } from "./sqlite/attachment-texts.js";
39
39
  export { backfillNormalized, pendingNormalization } from "./sqlite/backfill.js";
@@ -72,6 +72,7 @@ export { type NearestNote, NOTE_FIELDS, type NoteChunkToEmbed, type NoteHit, typ
72
72
  export type { FileNoteInput, Link, LinkInput, LinkListFilter, Note, NoteFolder, NotesStore, NoteTag, } from "./sqlite/notes.js";
73
73
  export type { Order, OrderDetail, OrderFilter, OrderInput, OrdersStore } from "./sqlite/orders.js";
74
74
  export { DEFAULT_OWNER_LANGUAGES, ownerLanguages } from "./sqlite/owner-languages.js";
75
+ export { mergeId, type PersonMerge, parseMergeId } from "./sqlite/person-merges.js";
75
76
  export type { PrivateContact, PrivateContactNote } from "./sqlite/private-people.js";
76
77
  export type { Product, ProductFilter, ProductInput, ProductsStore, ProductUpdate } from "./sqlite/products.js";
77
78
  export { assertGenericAction, PROPOSAL_STATUSES, type ProposalInput, type ProposedAction, type ProposedActionsStore, proposerOfAction, } from "./sqlite/proposed-actions.js";
@@ -99,6 +100,7 @@ export type { TaskRelation, TaskRelationKind, TaskRelationsStore } from "./sqlit
99
100
  export { TASK_RELATION_KINDS } from "./sqlite/task-relations.js";
100
101
  export type { TaskStatRow, TaskStatScope } from "./sqlite/task-stats.js";
101
102
  export type { StoreTaskStore } from "./sqlite/tasks.js";
103
+ export type { StoredTemplate, TemplateAddress, TemplateHistoryEntry, TemplateStore } from "./sqlite/templates.js";
102
104
  export type { TagPreflight, VocabularyAlias, VocabularyAliasReceipt, VocabularyAudit, VocabularyAuditOptions, VocabularyCatalog, VocabularyEntry, VocabularyKind, VocabularyOptions, VocabularyResolution, VocabularyStore, VocabularyTarget, } from "./sqlite/vocabulary.js";
103
105
  export type { Wallet, WalletFilter, WalletInput, WalletsStore, WalletUpdate } from "./sqlite/wallets.js";
104
106
  export type { BoardCounts, BoardOptions, EditedTask, MovedSubtask, NewWorkTask, RevisionCheck, TaskAssignment, TaskDetails, TaskEvent, TaskFields, TaskMove, TaskMoved, TaskRole, TaskType, WorkTaskType, } from "./sqlite/work-tasks.js";
@@ -35,6 +35,7 @@ export { IMPORTED_DOCUMENT_QUERY } from "./sqlite/imported-documents.js";
35
35
  export { ORGANIZATION_KINDS, PROJECT_TYPES, SCOPES } from "./sqlite/knowledge.js";
36
36
  export { NOTE_FIELDS, } from "./sqlite/note-search.js";
37
37
  export { DEFAULT_OWNER_LANGUAGES, ownerLanguages } from "./sqlite/owner-languages.js";
38
+ export { mergeId, parseMergeId } from "./sqlite/person-merges.js";
38
39
  export { assertGenericAction, PROPOSAL_STATUSES, proposerOfAction, } from "./sqlite/proposed-actions.js";
39
40
  export { waitingPointer, } from "./sqlite/records.js";
40
41
  export { fillSearchIndex, resetSearchIndex, searchIndexState, } from "./sqlite/search-index.js";
@@ -2,6 +2,7 @@ import type { Contact, Id, Page, PersonAlias, Provider } from "../domain/models.
2
2
  import type { PeopleLookup } from "../resolve.js";
3
3
  import type { ContactFilter } from "./sqlite/identities.js";
4
4
  import type { StoreContext } from "./sqlite/open.js";
5
+ import type { PersonMerge } from "./sqlite/person-merges.js";
5
6
  import { type PersonPreparationRead } from "./sqlite/person-preparation.js";
6
7
  import type { PrivateContact, PrivateContactNote } from "./sqlite/private-people.js";
7
8
  import type { AccountKey, IdentityRef, LinkOptions, PersonFacts, PersonRecord } from "./types.js";
@@ -57,6 +58,12 @@ export interface PeopleStore extends AccountPeople {
57
58
  /** Records the decision in `identity_link_events`; `unlinkIdentity` undoes it. */
58
59
  linkIdentities(person: IdentityRef, other: IdentityRef, options: LinkOptions): Promise<PersonRecord>;
59
60
  unlinkIdentity(identity: IdentityRef, options: LinkOptions): Promise<PersonRecord>;
61
+ /** The people merged into this one, newest first, each with the identities that came from it. */
62
+ merges(uid: string): Promise<PersonMerge[]>;
63
+ /** The owner's undo of a merge: the identities that came from `from` go back to it. Gives `from` again. */
64
+ undoMerge(to: string, from: string, by: string): Promise<PersonRecord>;
65
+ /** The owner's split: the chosen identities become one new person, which this gives. */
66
+ split(uid: string, identities: IdentityRef[], by: string): Promise<PersonRecord>;
60
67
  /** The identity, and everyone linked with it, is the owner. */
61
68
  linkToOwner(identity: IdentityRef): Promise<PersonRecord>;
62
69
  /** A person known by name only, with no identity yet: someone to assign a task to before any message names them. */
@@ -4,6 +4,7 @@ import { ownerPerson } from "./sqlite/actors.js";
4
4
  import * as identities from "./sqlite/identities.js";
5
5
  import { linkToOwner } from "./sqlite/own-identities.js";
6
6
  import * as personLinks from "./sqlite/person-links.js";
7
+ import * as personMerges from "./sqlite/person-merges.js";
7
8
  import { personPreparation } from "./sqlite/person-preparation.js";
8
9
  import { personSeenInAccounts } from "./sqlite/person-scope.js";
9
10
  import * as privatePeople from "./sqlite/private-people.js";
@@ -91,6 +92,9 @@ export const peopleStoreOver = (context, keyed) => {
91
92
  unlinkIdentity: async (identity, options) => {
92
93
  return write(database, () => personLinks.unlinkIdentity(context, identity, options));
93
94
  },
95
+ merges: async (uid) => personMerges.merges(context, uid),
96
+ undoMerge: async (to, from, by) => write(database, () => personMerges.undoMerge(context, to, from, by)),
97
+ split: async (uid, chosen, by) => write(database, () => personMerges.split(context, uid, chosen, by)),
94
98
  linkToOwner: async (identity) => linkToOwner(context, identity),
95
99
  };
96
100
  };
@@ -57,6 +57,27 @@ export interface SourceCheck {
57
57
  refreshed: number;
58
58
  /** Open reviews of a memory or fact met in this run that no longer holds, closed. */
59
59
  closed: number;
60
+ /**
61
+ * Sources found changed in this run, raised or signed anew, that no open `evidence_findings` batch cites: what an
62
+ * agent may read again for new facts. Deleted sources and cited memories or facts are left out.
63
+ */
64
+ changedRefs: string[];
65
+ }
66
+ /** A cited source found changed since it was cited, by a check at `checkedAt`. */
67
+ export interface ChangedSource {
68
+ ref: string;
69
+ checkedAt: string;
70
+ }
71
+ /** One source of a review as it was cited and as it is now, for the owner to compare; both are the source's text. */
72
+ export interface SourceReviewText {
73
+ link: number;
74
+ ref: string | null;
75
+ /** The words the claim rested on, as its author quoted them. */
76
+ quote: string | null;
77
+ /** `null` where the store keeps no history for the kind, or the source is gone. */
78
+ cited: string | null;
79
+ /** `null` where the store keeps no text for the kind, or the source is deleted. */
80
+ now: string | null;
60
81
  }
61
82
  /** What stands in a review for words about a source that was erased since. */
62
83
  export declare const ERASED_TEXT = "[source erased]";
@@ -15,6 +15,8 @@ export declare const unreferenced: (database: CacheDatabase, table: "identities"
15
15
  /**
16
16
  * People only the purged account had seen go with it. An identity stays while anything else points at it
17
17
  * (another account, a tag, a note, a link), or while its person is kept: the owner, a person something
18
- * points at, or one linked to an identity that stays.
18
+ * points at, or one linked to an identity that stays. An identity also stays while a person it was merged out of is
19
+ * pointed at, so that person stays merged away and its references keep meaning the person it is now. A person the
20
+ * identity was merged out of goes too, unless another identity's move or anything else still points at it.
19
21
  */
20
22
  export declare const dropOrphanPeople: (database: CacheDatabase, unseenBefore: Set<number>) => void;
@@ -2,6 +2,7 @@ import { CliError } from "@wirecat/cli-base";
2
2
  import { and, asc, eq, inArray, sql } from "./drizzle/core.js";
3
3
  import { pointerPairs } from "./entity-types.js";
4
4
  import { forgetDanglingEvidence, forgetEvidenceTo } from "./evidence-signature.js";
5
+ import { mergeSql } from "./merged-persons.js";
5
6
  import { accountIdentities, accounts, aliases, botUpdates, chatEventPeople, chatEvents, chatMembers, chats, chunks, fetchLeases, involvements, memberCounts, memberObservationMembers, memberObservations, memberStays, messageReactions, messageRevisions, messages, messageTranscripts, pollVotes, projects, syncCursors, syncRanges, syncs, } from "./schema.js";
6
7
  import { dropUnusedVectors } from "./vector-index.js";
7
8
  /** An account's row, made on first sight; a name only replaces what was known when there is one. */
@@ -167,7 +168,9 @@ export const unreferenced = (database, table) => new Set(database
167
168
  /**
168
169
  * People only the purged account had seen go with it. An identity stays while anything else points at it
169
170
  * (another account, a tag, a note, a link), or while its person is kept: the owner, a person something
170
- * points at, or one linked to an identity that stays.
171
+ * points at, or one linked to an identity that stays. An identity also stays while a person it was merged out of is
172
+ * pointed at, so that person stays merged away and its references keep meaning the person it is now. A person the
173
+ * identity was merged out of goes too, unless another identity's move or anything else still points at it.
171
174
  */
172
175
  export const dropOrphanPeople = (database, unseenBefore) => {
173
176
  const orphans = [...unreferenced(database, "identities")].filter((id) => !unseenBefore.has(id));
@@ -179,14 +182,18 @@ export const dropOrphanPeople = (database, unseenBefore) => {
179
182
  .prepare(`SELECT DISTINCT l.identity_id AS id FROM identity_links l JOIN persons p ON p.id = l.person_id
180
183
  WHERE l.identity_id IN (SELECT value FROM json_each(?)) AND (p.owner <> 0
181
184
  OR p.id IN (SELECT id FROM (${personRefs}) WHERE id IS NOT NULL)
185
+ OR EXISTS (SELECT 1 FROM identity_link_events e WHERE e.identity_id = l.identity_id AND ${mergeSql("e")}
186
+ AND e.from_person_id IN (SELECT id FROM (${personRefs}) WHERE id IS NOT NULL))
182
187
  OR EXISTS (SELECT 1 FROM identity_links o WHERE o.person_id = p.id
183
188
  AND o.identity_id NOT IN (SELECT value FROM json_each(?))))`)
184
189
  .all(ids, ids)
185
190
  .map(({ id }) => Number(id)));
186
191
  const gone = JSON.stringify(orphans.filter((id) => !kept.has(id)));
187
192
  const persons = database
188
- .prepare("SELECT DISTINCT person_id AS id FROM identity_links WHERE identity_id IN (SELECT value FROM json_each(?))")
189
- .all(gone)
193
+ .prepare(`SELECT person_id AS id FROM identity_links WHERE identity_id IN (SELECT value FROM json_each(?))
194
+ UNION SELECT from_person_id FROM identity_link_events WHERE identity_id IN (SELECT value FROM json_each(?))
195
+ AND from_person_id IS NOT NULL`)
196
+ .all(gone, gone)
190
197
  .map(({ id }) => Number(id));
191
198
  for (const table of ["identity_revisions", "identity_link_events", "identity_links"])
192
199
  database.prepare(`DELETE FROM ${table} WHERE identity_id IN (SELECT value FROM json_each(?))`).run(gone);
@@ -41,6 +41,8 @@ export interface AddedSources {
41
41
  saveAddedSource(input: AddedSourceInput): Promise<AddedSource>;
42
42
  /** The account of the sources added by hand, once one was saved. */
43
43
  addedAccount(): Promise<NoteFolder | undefined>;
44
+ /** A live source added by hand, with what was kept of it; `undefined` for any other document or reference. */
45
+ addedSource(reference: string): Promise<AddedSourceDetails | undefined>;
44
46
  /**
45
47
  * What saving this content would find, read only: the live added source it repeats, or the folder or Drive document
46
48
  * it duplicates. A caller that keeps a copy of the file asks this first, and writes the copy only when both are null.
@@ -70,6 +72,20 @@ export interface AddedSource {
70
72
  /** Every subject the document is about now, the ones linked before included. */
71
73
  subjects: string[];
72
74
  }
75
+ /** What a source added by hand is, beyond the document every reader shows. */
76
+ export interface AddedSourceDetails {
77
+ note: Note;
78
+ kind: (typeof ADDED_KINDS)[number];
79
+ /** The page's address as given, or where a file came from. */
80
+ url: string | null;
81
+ fileName: string | null;
82
+ mime: string | null;
83
+ /** Bytes of the file or the page as read. */
84
+ size: number | null;
85
+ kept: "text" | "copy";
86
+ /** Where the caller keeps the copy, when one was kept. */
87
+ copy: string | null;
88
+ }
73
89
  /**
74
90
  * The key an added source is stored under, `sha256:<hash>` (a file's bytes; pasted text or a page by its normalized
75
91
  * text, or its address when it has none), and every hash a folder or Drive document of the same content may carry.
@@ -125,6 +125,28 @@ export const addedSourcesOver = (context) => {
125
125
  const row = accountRow();
126
126
  return row ? folderOf(row) : undefined;
127
127
  },
128
+ addedSource: async (reference) => {
129
+ const id = /^document:[1-9]\d*$/.test(reference) ? Number(reference.slice("document:".length)) : undefined;
130
+ const row = id === undefined
131
+ ? undefined
132
+ : database
133
+ .prepare("SELECT d.* FROM documents d JOIN accounts a ON a.id = d.account_id WHERE d.id = ? AND a.provider = ? " +
134
+ "AND d.deleted_at IS NULL")
135
+ .get(id, ADDED_PROVIDER);
136
+ if (!row)
137
+ return undefined;
138
+ const copy = row.storage === "copy" && row.local_path != null ? String(row.local_path) : null;
139
+ return {
140
+ note: documentOf(row),
141
+ kind: oneOf(String(row.kind), ADDED_KINDS, "an added source's kind"),
142
+ url: row.url == null ? null : String(row.url),
143
+ fileName: row.file_name == null ? null : String(row.file_name),
144
+ mime: row.mime == null ? null : String(row.mime),
145
+ size: row.size == null ? null : Number(row.size),
146
+ kept: copy === null ? "text" : "copy",
147
+ copy,
148
+ };
149
+ },
128
150
  findAddedSource: async (content) => {
129
151
  const key = addedSourceKeyOf(content);
130
152
  const own = ownRow(key.externalId);
@@ -6,6 +6,7 @@ import { proposedBySql, proposerOf } from "./actors.js";
6
6
  import { evidenceSourcesOf } from "./evidence-sources.js";
7
7
  import { linkKind } from "./link-kinds.js";
8
8
  import { authorActor, authorOf, dropLinksOf, erase, evidenceOf, keepHighestId, linkEvidence, nextId, projectOf, subjectOf, } from "./memories.js";
9
+ import { idsOf } from "./merged-persons.js";
9
10
  import { requiredThing } from "./notes.js";
10
11
  import { closeSourceReviews, eraseSourceReviews, sourceReviewOf } from "./source-review-marks.js";
11
12
  import { write } from "./transaction.js";
@@ -139,9 +140,9 @@ export const factOperationsOver = (context) => {
139
140
  const order = options.order === "created" ? "f.created_at" : "coalesce(f.occurred_at, f.created_at)";
140
141
  return database
141
142
  .prepare(`${NAMED} WHERE f.deleted_at IS NULL AND (? IS NULL OR f.type = ?) AND (? IS NULL OR f.project_id = ?) ` +
142
- "AND (? IS NULL OR (f.subject_type = ? AND f.subject_id = ?)) AND (? IS NULL OR f.status = ?) " +
143
+ "AND (? IS NULL OR (f.subject_type = ? AND f.subject_id IN (SELECT value FROM json_each(?)))) AND (? IS NULL OR f.status = ?) " +
143
144
  `AND ${by.sql} ORDER BY ${order} DESC, f.id DESC LIMIT ?`)
144
- .all(options.type ?? null, options.type ?? null, project?.id ?? null, project?.id ?? null, subject?.type ?? null, subject?.type ?? null, subject?.id ?? null, options.status ?? null, options.status ?? null, ...by.params, Math.min(Math.max(options.limit ?? 100, 1), 500))
145
+ .all(options.type ?? null, options.type ?? null, project?.id ?? null, project?.id ?? null, subject?.type ?? null, subject?.type ?? null, subject ? idsOf(database, subject.type, subject.id) : null, options.status ?? null, options.status ?? null, ...by.params, Math.min(Math.max(options.limit ?? 100, 1), 500))
145
146
  .map(factOf);
146
147
  },
147
148
  accept: (reference, by, reason) => {
@@ -1,5 +1,6 @@
1
1
  import { defineQuery, validateQuery } from "@wirecat/cli-base/query";
2
2
  import { normalizeTag } from "../../domain/tags.js";
3
+ import { idsOf } from "./merged-persons.js";
3
4
  import { queryFilter } from "./query-filter.js";
4
5
  import { canonicalTagNamed } from "./tags.js";
5
6
  import { thingOf } from "./things.js";
@@ -44,8 +45,8 @@ export const importedDocumentWhere = (database, query) => {
44
45
  return { sql: "0", params: [] };
45
46
  return {
46
47
  sql: "EXISTS (SELECT 1 FROM links l WHERE l.from_type = 'document' AND l.from_id = d.id " +
47
- "AND l.to_type = ? AND l.to_id = ?)",
48
- params: [found.type, found.id],
48
+ "AND l.to_type = ? AND l.to_id IN (SELECT value FROM json_each(?)))",
49
+ params: [found.type, idsOf(database, found.type, found.id)],
49
50
  };
50
51
  },
51
52
  },