counterparts 0.3.11 → 0.3.13

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 (150) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/docs/QUICKSTART.md +5 -0
  3. package/docs/README.md +2 -2
  4. package/docs/module-map.md +3 -3
  5. package/package.json +1 -1
  6. package/src/adapters/claude-code/CONTRACT.md +36 -10
  7. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  8. package/src/adapters/claude-code/NOTES.md +182 -0
  9. package/src/adapters/claude-code/bin/hook.ts +46 -12
  10. package/src/adapters/claude-code/bin/runner.ts +7 -1
  11. package/src/adapters/claude-code/doctor.ts +632 -18
  12. package/src/adapters/claude-code/hooks.ts +61 -16
  13. package/src/adapters/claude-code/index.ts +11 -0
  14. package/src/adapters/claude-code/night-run.ts +150 -14
  15. package/src/adapters/claude-code/transcript.ts +268 -1
  16. package/src/adapters/cli/CONTRACT.md +5 -0
  17. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  18. package/src/adapters/cli/NOTES.md +111 -0
  19. package/src/adapters/cli/commands.ts +134 -92
  20. package/src/adapters/cli/dream-core.ts +57 -42
  21. package/src/adapters/cli/export.ts +320 -21
  22. package/src/adapters/cli/help.ts +2 -1
  23. package/src/adapters/cli/index.ts +1 -0
  24. package/src/adapters/cli/install.ts +39 -7
  25. package/src/adapters/cli/mechanisms.ts +7 -1
  26. package/src/adapters/cli/uninstall.ts +13 -5
  27. package/src/adapters/cli/wire.ts +189 -63
  28. package/src/adapters/config.ts +2 -0
  29. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  30. package/src/adapters/dashboard/NOTES.md +79 -0
  31. package/src/adapters/dashboard/registries.ts +34 -2
  32. package/src/adapters/dashboard/web/README.md +19 -14
  33. package/src/adapters/dashboard/web/actions.ts +23 -1
  34. package/src/adapters/dashboard/web/flow.ts +14 -0
  35. package/src/adapters/dashboard/web/lanes.ts +10 -0
  36. package/src/adapters/dashboard/web/narrate.ts +88 -2
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  38. package/src/adapters/dashboard/web/pages/health/sections/checks.js +2 -0
  39. package/src/adapters/dashboard/web/pages/health/sections/wake.js +3 -1
  40. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  41. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  43. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  44. package/src/adapters/dashboard/web/server.ts +0 -5
  45. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  46. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  47. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  48. package/src/adapters/dashboard/web/views/health.ts +21 -3
  49. package/src/adapters/dashboard/web/views/search.ts +4 -45
  50. package/src/adapters/dashboard/web/views.ts +2 -2
  51. package/src/adapters/fired.ts +430 -28
  52. package/src/adapters/host-wiring.ts +300 -0
  53. package/src/adapters/hosts.ts +11 -0
  54. package/src/adapters/lifecycle.ts +42 -2
  55. package/src/adapters/log/index.ts +9 -0
  56. package/src/adapters/mcp/CONTRACT.md +151 -11
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  58. package/src/adapters/mcp/NOTES.md +313 -1
  59. package/src/adapters/mcp/bin/serve.ts +74 -1
  60. package/src/adapters/mcp/deliberate.ts +169 -651
  61. package/src/adapters/mcp/facts.ts +1094 -0
  62. package/src/adapters/mcp/index.ts +25 -7
  63. package/src/adapters/mcp/meaning.ts +1610 -0
  64. package/src/adapters/mcp/server.ts +835 -150
  65. package/src/adapters/mcp/stdio.ts +3 -1
  66. package/src/adapters/mcp/stood-down.ts +51 -0
  67. package/src/adapters/mcp/tools.ts +167 -41
  68. package/src/adapters/plugin-run.sh +133 -0
  69. package/src/adapters/plugin.ts +329 -0
  70. package/src/adapters/sessions.ts +18 -4
  71. package/src/core/associate/CONTRACT.md +2 -1
  72. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  73. package/src/core/associate/NOTES.md +45 -0
  74. package/src/core/briefing.ts +12 -3
  75. package/src/core/contradictions.ts +184 -0
  76. package/src/core/counterpart.ts +797 -51
  77. package/src/core/dream/CONTRACT.md +36 -4
  78. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  79. package/src/core/dream/NOTES.md +107 -0
  80. package/src/core/dream/feeling-weeks.ts +198 -0
  81. package/src/core/dream/index.ts +109 -18
  82. package/src/core/dream/reflect.ts +346 -87
  83. package/src/core/dream/tunables.ts +24 -4
  84. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  85. package/src/core/encode/NOTES.md +7 -0
  86. package/src/core/encode/words.ts +45 -0
  87. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  88. package/src/core/fit/NOTES.md +39 -1
  89. package/src/core/fit/index.ts +40 -0
  90. package/src/core/handoff/CONTRACT.md +37 -2
  91. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  92. package/src/core/handoff/NOTES.md +72 -0
  93. package/src/core/handoff/index.ts +214 -12
  94. package/src/core/handoff/last-here.ts +6 -4
  95. package/src/core/mint.ts +12 -2
  96. package/src/core/physics/CONTRACT.md +14 -2
  97. package/src/core/physics/NOTES.md +33 -1
  98. package/src/core/physics/index.ts +28 -5
  99. package/src/core/prospective/CONTRACT.md +45 -6
  100. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  101. package/src/core/prospective/NOTES.md +138 -0
  102. package/src/core/prospective/derive.ts +33 -5
  103. package/src/core/prospective/index.ts +90 -5
  104. package/src/core/prospective/windows.ts +72 -1
  105. package/src/core/recall/CONTRACT.md +31 -12
  106. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  107. package/src/core/recall/NOTES.md +70 -1
  108. package/src/core/recall/feeling-ask.ts +10 -1
  109. package/src/core/recall/index.ts +3 -1
  110. package/src/core/recall/probe.ts +58 -0
  111. package/src/core/recall/session.ts +46 -2
  112. package/src/core/recall/time-ask.ts +487 -0
  113. package/src/core/remember/CONTRACT.md +4 -1
  114. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  115. package/src/core/remember/NOTES.md +8 -0
  116. package/src/core/remember/proposals.ts +47 -5
  117. package/src/core/revision.ts +18 -1
  118. package/src/core/schemas/CONTRACT.md +21 -1
  119. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  120. package/src/core/schemas/NOTES.md +144 -0
  121. package/src/core/schemas/aliases.ts +55 -5
  122. package/src/core/schemas/index.ts +93 -1
  123. package/src/core/schemas/types.ts +2 -0
  124. package/src/core/self/CONTRACT.md +32 -5
  125. package/src/core/self/INTERFACE-GAPS.md +7 -2
  126. package/src/core/self/NOTES.md +102 -1
  127. package/src/core/self/behind.ts +43 -3
  128. package/src/core/self/briefing.ts +12 -2
  129. package/src/core/self/chapter-address.ts +254 -0
  130. package/src/core/self/episodes.ts +27 -0
  131. package/src/core/self/index.ts +83 -8
  132. package/src/core/self/page.ts +88 -0
  133. package/src/core/self/tunables.ts +5 -0
  134. package/src/core/self/work.ts +35 -2
  135. package/src/core/self/writer.ts +30 -0
  136. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  137. package/src/core/sleep/NOTES.md +20 -1
  138. package/src/core/sleep/consolidate.ts +59 -7
  139. package/src/core/sleep/index.ts +3 -0
  140. package/src/core/sleep/prune.ts +6 -2
  141. package/src/core/sleep/types.ts +7 -0
  142. package/src/core/store/CONTRACT.md +16 -0
  143. package/src/core/store/NOTES.md +66 -0
  144. package/src/core/store/feelings.ts +14 -1
  145. package/src/core/store/index.ts +483 -16
  146. package/src/core/store/operational.ts +95 -2
  147. package/src/core/store/owner-op-seam.ts +23 -0
  148. package/src/core/time.ts +152 -0
  149. package/tools/install-loop/run.sh +48 -12
  150. package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
@@ -48,11 +48,14 @@ import {
48
48
  daysBetween,
49
49
  isCalendarDate,
50
50
  isDay,
51
+ isRecurrence,
51
52
  localDate,
53
+ parseCalendarDate,
52
54
  resolveZone,
53
55
  utcDate,
54
56
  } from "../time.js";
55
- import { checkFeelings } from "./feelings.js";
57
+ import type { Recurrence } from "../time.js";
58
+ import { LATER_FEELING_SOURCES, checkFeelings } from "./feelings.js";
56
59
  import type { AddFeelingsResult, FeelingInput, FeelingRow, FeelingSource } from "./feelings.js";
57
60
  import { checkTraitsRepaired } from "./traits.js";
58
61
  import type { TraitRepair } from "./traits.js";
@@ -142,6 +145,9 @@ export * from "./paths.js";
142
145
  export * from "./prose.js";
143
146
  export * from "./render.js";
144
147
  export * from "./feelings.js";
148
+
149
+ /** `LATER_FEELING_SOURCES` as a SQL list — the sources `feeling_peak_lived` leaves out. Constants only, never input. */
150
+ const LATER_SQL = LATER_FEELING_SOURCES.map((x) => `'${x}'`).join(", ");
145
151
  export * from "./traits.js";
146
152
  export type { Db, Statement, WalFold } from "./db.js";
147
153
  export type {
@@ -186,6 +192,7 @@ export {
186
192
  V9_UPGRADE_KEY,
187
193
  V10_UPGRADE_KEY,
188
194
  V11_UPGRADE_KEY,
195
+ V12_UPGRADE_KEY,
189
196
  carriedPairId,
190
197
  refileFeelingsV11,
191
198
  refileStrayV10Cores,
@@ -346,8 +353,58 @@ export interface PutInput {
346
353
  */
347
354
  about?: AboutMark;
348
355
  aboutBy?: AboutSetter;
356
+ /**
357
+ * v12: THE WRITER'S THREE FIELDS (`WriteFacts`) — when the thing happened
358
+ * (a day, month, year or range, `time.ts#parseCalendarDate`), who said it,
359
+ * and what kind of thing it is. Absent writes NULL. A belt, not the check:
360
+ * an unreadable date or an unknown word writes NULL here rather than
361
+ * refusing the memory (the doors drop them with a note before this).
362
+ */
363
+ occurredOn?: string;
364
+ saidBy?: SaidBy;
365
+ status?: MemoryStatus;
366
+ }
367
+
368
+ /**
369
+ * v12 (2026-10-03): WHO SAID IT — the owner, me (`self`), or my inference
370
+ * (`inferred`). Not which channel wrote the row (`source` says that): a note
371
+ * I write can record something the owner said.
372
+ */
373
+ export const SAID_BY = ["owner", "self", "inferred"] as const;
374
+ export type SaidBy = (typeof SAID_BY)[number];
375
+ /**
376
+ * v12 (2026-10-03): WHAT KIND OF THING IT IS — `done` (it happened),
377
+ * `planned` (decided, not yet done), `proposed` (put forward, not decided),
378
+ * `asked` (a question or request still open). `kind` is taken (physics kind).
379
+ */
380
+ export const STATUSES = ["done", "planned", "proposed", "asked"] as const;
381
+ export type MemoryStatus = (typeof STATUSES)[number];
382
+
383
+ /** The writer's three fields, as one value (v12). Each one optional. */
384
+ export interface WriteFacts {
385
+ readonly occurredOn?: string;
386
+ readonly saidBy?: SaidBy;
387
+ readonly status?: MemoryStatus;
349
388
  }
350
389
 
390
+ /** A value read as who-said-it: anything else is unknown (null). */
391
+ export function saidByOf(v: unknown): SaidBy | null {
392
+ return typeof v === "string" && (SAID_BY as readonly string[]).includes(v) ? (v as SaidBy) : null;
393
+ }
394
+
395
+ /** A value read as a status: anything else is unknown (null). */
396
+ export function statusOf(v: unknown): MemoryStatus | null {
397
+ return typeof v === "string" && (STATUSES as readonly string[]).includes(v) ? (v as MemoryStatus) : null;
398
+ }
399
+
400
+ /** An occurred-on date as stored — the `time.ts` reading's text — or null when unreadable. */
401
+ export function occurredOnOf(v: unknown): string | null {
402
+ return parseCalendarDate(v)?.text ?? null;
403
+ }
404
+
405
+ /** How a subject link was found (`memory_subjects.via`, v12). */
406
+ export type SubjectLinkVia = "write" | "birth" | "backfill";
407
+
351
408
  /**
352
409
  * A memory's confidentiality class, from its `meta`.
353
410
  *
@@ -421,6 +478,69 @@ export interface DatedMemory {
421
478
  readonly eventDate: string;
422
479
  }
423
480
 
481
+ /**
482
+ * HOW OFTEN A REMINDER DATE COMES ROUND (2026-10-09, the owner's design, held
483
+ * lightly): `daily`, `weekly`, `monthly` or `yearly` (`time.ts#RECURRENCES`),
484
+ * anchored on the memory's `event_date`, in the memory's meta bag under this
485
+ * key — beside `remind`, and for the same reason: NO SCHEMA BUMP, so a store
486
+ * written with it opens in a build that never heard of it, which reads the
487
+ * anchor as a one-off date already passed. Only a DAY repeats; on a month, a
488
+ * range or a year the key is inert. `prospective/` is its reader.
489
+ */
490
+ export const RECURRING_META = "recurring";
491
+
492
+ /**
493
+ * The repeat a ROW carries, or null: a day `event_date` and a recurrence word
494
+ * in its meta — the one predicate `recurringMemories` and the prune's
495
+ * `recurring` gate (`sleep/prune.ts`, 2026-10-09) both read. Unreadable meta,
496
+ * a month or a range, or `recurring` dropped: null, the date is once.
497
+ */
498
+ export function recurrenceOfRow(row: { readonly event_date: string | null; readonly meta: string }): Recurrence | null {
499
+ if (!isDay(row.event_date)) return null;
500
+ if (!row.meta.includes(`"${RECURRING_META}"`)) return null;
501
+ let rule: unknown;
502
+ try {
503
+ rule = (JSON.parse(row.meta) as Record<string, unknown>)[RECURRING_META];
504
+ } catch {
505
+ return null;
506
+ }
507
+ return isRecurrence(rule) ? rule : null;
508
+ }
509
+
510
+ /** One memory whose reminder date repeats, as `Store.recurringMemories` returns it. */
511
+ export interface RecurringMemory {
512
+ readonly id: string;
513
+ /** The day as stated — the anchor every occurrence is counted from. */
514
+ readonly eventDate: string;
515
+ readonly recurring: Recurrence;
516
+ }
517
+
518
+ /**
519
+ * ONE LIVE ROW as deliberate recall's facts mode ranks and labels it (Release
520
+ * B, 2026-10-03): the columns, never the body (`Store#recallRows`). The
521
+ * writer's three fields are null on a row from before v12, and on a file
522
+ * that has not been upgraded.
523
+ */
524
+ export interface RecallRow {
525
+ readonly id: string;
526
+ readonly type: string;
527
+ readonly kind: string;
528
+ readonly title: string | null;
529
+ readonly learned_on: string;
530
+ readonly created_at: number | null;
531
+ readonly updated_at: number | null;
532
+ readonly occurred_on: string | null;
533
+ readonly said_by: string | null;
534
+ readonly status: string | null;
535
+ readonly source: string | null;
536
+ readonly origin_session: string | null;
537
+ readonly origin_scope: string | null;
538
+ readonly origin_ref: string | null;
539
+ readonly confidential: number;
540
+ /** `meta` for a schema or an episode row (a role, a session); null for a memory. */
541
+ readonly meta: string | null;
542
+ }
543
+
424
544
  export interface PruneReport {
425
545
  pruned: number;
426
546
  cutoffDay: number;
@@ -752,6 +872,8 @@ export const WRITE_METHODS = [
752
872
  "withdrawContradiction",
753
873
  "settleContradiction",
754
874
  "undoContradictionSettle",
875
+ // v12 (2026-10-03): a card's birth and the backfill link what names it.
876
+ "linkSubjects",
755
877
  ] as const;
756
878
 
757
879
  export type WriteMethod = (typeof WRITE_METHODS)[number];
@@ -776,7 +898,7 @@ export type WriteMethod = (typeof WRITE_METHODS)[number];
776
898
  * A type, not a wrapper: it narrows what a caller can NAME, and a cast gets
777
899
  * round it. The stance (`observer: true`) is still what the seam refuses on.
778
900
  */
779
- export type ReadOnlyStore = Omit<Store, WriteMethod | "close" | "guardWrites">;
901
+ export type ReadOnlyStore = Omit<Store, WriteMethod | "close" | "guardWrites" | "findSubjectsWith">;
780
902
 
781
903
  const MAX_CHAIN = 32;
782
904
  const EVENT_RING = 500;
@@ -858,6 +980,12 @@ export interface MemoryFilter {
858
980
  * session wrote without reading every row.
859
981
  */
860
982
  originSession?: string;
983
+ /**
984
+ * MARKED ABOUT THIS — v9's `about` column (`ABOUT_MARKS`). Exact match; an
985
+ * unmarked row never matches. Added 2026-10-03 for recall's meaning mode,
986
+ * where "us" is the memories marked `us`.
987
+ */
988
+ about?: AboutMark;
861
989
  }
862
990
 
863
991
  function memoryWhere(filter: MemoryFilter): { clause: string; args: (string | number)[] } {
@@ -899,6 +1027,10 @@ function memoryWhere(filter: MemoryFilter): { clause: string; args: (string | nu
899
1027
  where.push("origin_session = ?");
900
1028
  args.push(filter.originSession);
901
1029
  }
1030
+ if (filter.about !== undefined) {
1031
+ where.push("about = ?");
1032
+ args.push(filter.about);
1033
+ }
902
1034
  return { clause: where.length ? `WHERE ${where.join(" AND ")}` : "", args };
903
1035
  }
904
1036
 
@@ -1489,6 +1621,10 @@ export class Store {
1489
1621
  happenedOn?: string;
1490
1622
  /** A new reminder date, or `null` to clear it (a reschedule, a cancel). */
1491
1623
  eventDate?: string | null;
1624
+ /** v12: the writer's three fields, or `null` to clear one. Absent keeps it. */
1625
+ occurredOn?: string | null;
1626
+ saidBy?: SaidBy | null;
1627
+ status?: MemoryStatus | null;
1492
1628
  /** Who wrote the new words (see `PutInput.model`). A revise that changes
1493
1629
  * the BODY and names no model records NULL: the words are no longer the
1494
1630
  * last model's. A revise that leaves the body alone keeps the model. */
@@ -1511,8 +1647,9 @@ export class Store {
1511
1647
  this.ops.run(
1512
1648
  `INSERT INTO versions
1513
1649
  (memory_id, seq, reason, version_day, archived_at, content_hash, successor_id,
1514
- title, body, meta, learned_on, happened_on, created_at, model, event_date)
1515
- VALUES (?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?)`,
1650
+ title, body, meta, learned_on, happened_on, created_at, model, event_date,
1651
+ occurred_on, said_by, status)
1652
+ VALUES (?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1516
1653
  id,
1517
1654
  seq,
1518
1655
  patch.reason ?? "revise",
@@ -1528,6 +1665,9 @@ export class Store {
1528
1665
  row.updated_at ?? row.created_at,
1529
1666
  row.model,
1530
1667
  row.event_date,
1668
+ row.occurred_on ?? null,
1669
+ row.said_by ?? null,
1670
+ row.status ?? null,
1531
1671
  );
1532
1672
  const next: ProseDoc = {
1533
1673
  ...prior,
@@ -1553,11 +1693,17 @@ export class Store {
1553
1693
  // Whitespace-only and a lone surrogate go through it too.
1554
1694
  next.body = bodyForStorage(next.body, id);
1555
1695
  const nextHash = hashText(next.body);
1696
+ // v12: the writer's three fields — a patch's, else the row's as they were.
1697
+ const occurredOn =
1698
+ patch.occurredOn === undefined ? (row.occurred_on ?? null) : patch.occurredOn === null ? null : occurredOnOf(patch.occurredOn);
1699
+ const saidBy = patch.saidBy === undefined ? (row.said_by ?? null) : saidByOf(patch.saidBy);
1700
+ const status = patch.status === undefined ? (row.status ?? null) : statusOf(patch.status);
1556
1701
  this.ops.run(
1557
1702
  `UPDATE memories
1558
1703
  SET content_hash = ?, revision = ?, title = ?, body = ?, meta = ?,
1559
1704
  confidential = ?, learned_on = ?, happened_on = ?,
1560
- event_date = ?, model = ?, updated_at = ?
1705
+ event_date = ?, model = ?, updated_at = ?,
1706
+ occurred_on = ?, said_by = ?, status = ?
1561
1707
  WHERE id = ?`,
1562
1708
  nextHash,
1563
1709
  seq,
@@ -1573,8 +1719,17 @@ export class Store {
1573
1719
  next.eventDate ?? null,
1574
1720
  model,
1575
1721
  at,
1722
+ occurredOn,
1723
+ saidBy,
1724
+ status,
1576
1725
  id,
1577
1726
  );
1727
+ // v12: NEW WORDS, NEW SUBJECTS — a revise that changes the title or the
1728
+ // body links what the words name now (a chapter copy regrows here); a
1729
+ // meta-only revise (a reminder moved, a thread closed) rescans nothing.
1730
+ if (row.type === "memory" && (patch.body !== undefined || patch.title !== undefined)) {
1731
+ this.relinkSubjects(id, next.title ?? null, next.body);
1732
+ }
1578
1733
  return { doc: next, seq, hash: nextHash };
1579
1734
  });
1580
1735
  this.indexOne(doc);
@@ -1600,8 +1755,9 @@ export class Store {
1600
1755
  this.ops.run(
1601
1756
  `INSERT INTO versions
1602
1757
  (memory_id, seq, reason, version_day, archived_at, content_hash, successor_id,
1603
- title, body, meta, learned_on, happened_on, created_at, model, event_date)
1604
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1758
+ title, body, meta, learned_on, happened_on, created_at, model, event_date,
1759
+ occurred_on, said_by, status)
1760
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1605
1761
  oldId,
1606
1762
  row.revision + 1,
1607
1763
  reason,
@@ -1617,6 +1773,9 @@ export class Store {
1617
1773
  row.updated_at ?? row.created_at,
1618
1774
  row.model,
1619
1775
  row.event_date,
1776
+ row.occurred_on ?? null,
1777
+ row.said_by ?? null,
1778
+ row.status ?? null,
1620
1779
  );
1621
1780
  this.ops.run(
1622
1781
  `UPDATE memories SET superseded_by = ?, archived = 1, archived_reason = ?, revision = ?,
@@ -1631,6 +1790,7 @@ export class Store {
1631
1790
  // v9: THE ABOUT-ME MARK TRAVELS with the memory to its successor, unless
1632
1791
  // the successor was given its own — a revision is still the same memory.
1633
1792
  carryAboutMark(this.ops, oldId, created.id);
1793
+ carryWriteFacts(this.ops, oldId, created.id);
1634
1794
  return { doc: created, newId: created.id };
1635
1795
  });
1636
1796
  this.indexOne(doc);
@@ -1990,8 +2150,9 @@ export class Store {
1990
2150
  this.ops.run(
1991
2151
  `INSERT INTO versions
1992
2152
  (memory_id, seq, reason, version_day, archived_at, content_hash, successor_id,
1993
- title, body, meta, learned_on, happened_on, created_at, model, event_date)
1994
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2153
+ title, body, meta, learned_on, happened_on, created_at, model, event_date,
2154
+ occurred_on, said_by, status)
2155
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1995
2156
  oldId,
1996
2157
  row.revision + 1,
1997
2158
  reason,
@@ -2007,6 +2168,9 @@ export class Store {
2007
2168
  row.updated_at ?? row.created_at,
2008
2169
  row.model,
2009
2170
  row.event_date,
2171
+ row.occurred_on ?? null,
2172
+ row.said_by ?? null,
2173
+ row.status ?? null,
2010
2174
  );
2011
2175
  this.ops.run(
2012
2176
  `UPDATE memories SET superseded_by = ?, archived = 1, archived_reason = ?, revision = ?, updated_at = ?
@@ -2019,6 +2183,7 @@ export class Store {
2019
2183
  );
2020
2184
  // v9: the about-me mark travels too (the first original that has one).
2021
2185
  carryAboutMark(this.ops, oldId, successorId);
2186
+ carryWriteFacts(this.ops, oldId, successorId);
2022
2187
  if (opts.carryReturns === true) {
2023
2188
  this.ops.run(
2024
2189
  `INSERT OR IGNORE INTO returns (memory_id, day, source, weight, gap, dream_id, at)
@@ -2318,6 +2483,11 @@ export class Store {
2318
2483
  );
2319
2484
  }
2320
2485
 
2486
+ /** How many reflections the store holds, counted in SQL — so a caller that wants every one (`export --markdown`) can ask for exactly that many. */
2487
+ reflectionCount(): number {
2488
+ return this.ops.get<{ n: number }>("SELECT COUNT(*) AS n FROM reflections")?.n ?? 0;
2489
+ }
2490
+
2321
2491
  /** True when the owner's latest word on this memory's core membership is a demotion. */
2322
2492
  coreDemoted(id: string): boolean {
2323
2493
  const last = this.ops.get<{ action: string }>(
@@ -3026,8 +3196,12 @@ export class Store {
3026
3196
  * reflection's feeling-now). Absent: felt at the time. */
3027
3197
  recordedLater?: string;
3028
3198
  /** Per input, overriding the two above — a merge carries each
3029
- * original's own (`dream/`). Indexed like `inputs`. */
3030
- provenance?: readonly ({ source?: string | null; recordedLater?: string | null } | undefined)[];
3199
+ * original's own (`dream/`). Indexed like `inputs`. `createdAt`
3200
+ * (2026-10-02): the moment it was first recorded — a feeling is a
3201
+ * moment's, so a merge does not make it new (as a trait nudge's,
3202
+ * below); before, every feeling a merge carried was dated the merge
3203
+ * night, and the reflection's weeks of feelings read it as felt then. */
3204
+ provenance?: readonly ({ source?: string | null; recordedLater?: string | null; createdAt?: number | null } | undefined)[];
3031
3205
  } = {},
3032
3206
  ): AddFeelingsResult {
3033
3207
  const { rows, notices, repairs } = checkFeelings(inputs);
@@ -3046,6 +3220,7 @@ export class Store {
3046
3220
  const source = opts.source ?? "session";
3047
3221
  rows.forEach((r, i) => {
3048
3222
  const own = opts.provenance?.[i];
3223
+ const first = typeof own?.createdAt === "number" && Number.isFinite(own.createdAt) ? own.createdAt : at;
3049
3224
  insert.run(
3050
3225
  ids[i] as string,
3051
3226
  memoryId,
@@ -3056,7 +3231,7 @@ export class Store {
3056
3231
  r.strength,
3057
3232
  r.carriedBy,
3058
3233
  model,
3059
- at,
3234
+ first,
3060
3235
  at,
3061
3236
  own?.source ?? source,
3062
3237
  own === undefined ? later : (own.recordedLater ?? null),
@@ -3963,12 +4138,14 @@ export class Store {
3963
4138
  row(id: string): (MemoryRow & FeelingPeak) | undefined {
3964
4139
  // v9: `feeling_peak_lived` is the same peak WITHOUT the feelings a
3965
4140
  // reflection recorded later — the one the core's fast lane reads unless
3966
- // `CORE_FAST_ACCEPTS_REFLECTED_FEELING` is set (physics §5.3).
4141
+ // `CORE_FAST_ACCEPTS_REFLECTED_FEELING` is set (physics §5.3). Since
4142
+ // 2026-10-02 an awake feeling-now (`awake`) is left out the same way
4143
+ // (`LATER_FEELING_SOURCES`).
3967
4144
  return this.ops.get<MemoryRow & FeelingPeak>(
3968
4145
  `SELECT m.*,
3969
4146
  (SELECT MAX(f.strength) FROM feelings f WHERE f.memory_id = m.id) AS feeling_peak,
3970
4147
  (SELECT MAX(f.strength) FROM feelings f
3971
- WHERE f.memory_id = m.id AND (f.source IS NULL OR f.source != 'reflection')) AS feeling_peak_lived
4148
+ WHERE f.memory_id = m.id AND (f.source IS NULL OR f.source NOT IN (${LATER_SQL}))) AS feeling_peak_lived
3972
4149
  FROM memories m WHERE m.id = ?`,
3973
4150
  id,
3974
4151
  );
@@ -4097,6 +4274,46 @@ export class Store {
4097
4274
  .map((r) => r.id);
4098
4275
  }
4099
4276
 
4277
+ /**
4278
+ * WHAT A SESSION WROTE IN ONE DIRECTORY AFTER A MOMENT THAT MAY BE A PLAN
4279
+ * (2026-10-09, the handoff's "since" line): live memories a session wrote
4280
+ * itself (`source = 'authored'`: a note, a `session_end` entry) under one of
4281
+ * `scopes`, born after `after` (epoch ms), whose v12 `status` is one of
4282
+ * `statuses` or whose meta may say `unresolved` — a loose text match the
4283
+ * caller confirms on the prose. Not archived, superseded or emptied, and
4284
+ * not confidential unless `confidential`. Newest first, then id, at most
4285
+ * `limit`. The columns only, as `workCandidates`. A store without the v12
4286
+ * column throws; the caller wraps it.
4287
+ */
4288
+ planCandidates(input: {
4289
+ readonly scopes: readonly string[];
4290
+ readonly after: number;
4291
+ readonly statuses: readonly MemoryStatus[];
4292
+ readonly limit: number;
4293
+ readonly confidential?: boolean;
4294
+ }): string[] {
4295
+ const scopes = input.scopes.filter((s) => s.length > 0);
4296
+ const statuses = input.statuses.filter((s) => (STATUSES as readonly string[]).includes(s));
4297
+ if (scopes.length === 0 || input.limit <= 0) return [];
4298
+ const marks = (n: number): string => Array.from({ length: n }, () => "?").join(", ");
4299
+ const status = statuses.length === 0 ? "" : `status IN (${marks(statuses.length)}) OR `;
4300
+ return this.ops
4301
+ .all<{ id: string }>(
4302
+ `SELECT id FROM memories
4303
+ WHERE type = 'memory' AND archived = 0 AND superseded_by IS NULL AND body != ''
4304
+ AND source = 'authored' AND origin_scope IN (${marks(scopes.length)}) AND created_at > ?
4305
+ ${input.confidential === true ? "" : "AND confidential = 0"}
4306
+ AND (${status}meta LIKE '%"unresolved":true%')
4307
+ ORDER BY created_at DESC, id
4308
+ LIMIT ?`,
4309
+ ...scopes,
4310
+ input.after,
4311
+ ...statuses,
4312
+ Math.max(0, Math.floor(input.limit)),
4313
+ )
4314
+ .map((r) => r.id);
4315
+ }
4316
+
4100
4317
  /**
4101
4318
  * How many rows `list()` would return, counted in SQL rather than materialized.
4102
4319
  * The same filter, the same WHERE, one number — for the callers that want the
@@ -4138,6 +4355,29 @@ export class Store {
4138
4355
  .map((r) => ({ id: r.id, eventDate: r.event_date }));
4139
4356
  }
4140
4357
 
4358
+ /**
4359
+ * LIVE memories whose reminder date REPEATS (`RECURRING_META`, 2026-10-09):
4360
+ * a day `event_date` and a recurrence word in meta. `datedMemories` asks
4361
+ * whether the date AS STATED reaches a span, and a birthday stated as
4362
+ * `1990-05-14` never reaches this year's; this is the other half, and
4363
+ * `prospective/` asks it for the occurrence that does. The SQL match is
4364
+ * loose (a text match on the meta, as `planCandidates` does for
4365
+ * `unresolved`) and the parsed meta decides. Ordered by id.
4366
+ */
4367
+ recurringMemories(opts: { archived?: boolean } = {}): RecurringMemory[] {
4368
+ const rows = this.ops.all<{ id: string; event_date: string; meta: string }>(
4369
+ `SELECT id, event_date, meta FROM memories
4370
+ WHERE event_date IS NOT NULL AND meta LIKE '%"${RECURRING_META}":"%'${opts.archived === true ? "" : " AND archived = 0"}
4371
+ ORDER BY id`,
4372
+ );
4373
+ const out: RecurringMemory[] = [];
4374
+ for (const r of rows) {
4375
+ const rule = recurrenceOfRow(r);
4376
+ if (rule !== null) out.push({ id: r.id, eventDate: r.event_date, recurring: rule });
4377
+ }
4378
+ return out;
4379
+ }
4380
+
4141
4381
  /** A memory's feelings, oldest first (then in the order written). A removed memory has none. */
4142
4382
  feelingsFor(memoryId: string): FeelingRow[] {
4143
4383
  return this.ops.all<FeelingRow>(
@@ -4287,6 +4527,200 @@ export class Store {
4287
4527
  return false;
4288
4528
  }
4289
4529
 
4530
+ /** Whether `table` has `column` — for a reader that may meet a file from
4531
+ * before the column (v12's fields are read below `OBSERVER_READ_FLOOR`). */
4532
+ hasColumn(table: string, column: string): boolean {
4533
+ try {
4534
+ return this.ops.all<{ name: string }>(`PRAGMA table_info(${table.replace(/[^A-Za-z0-9_]/g, "")})`).some((c) => c.name === column);
4535
+ } catch {
4536
+ return false;
4537
+ }
4538
+ }
4539
+
4540
+ // ── what a memory names (v12, `memory_subjects`) ──────────────────────────
4541
+
4542
+ /** The one slot `findSubjectsWith` fills. */
4543
+ private subjectFinder: ((text: string) => readonly string[]) | null = null;
4544
+
4545
+ /**
4546
+ * THE FUNCTION THAT SAYS WHICH ENTITY CARDS A TEXT NAMES (v12, 2026-10-03)
4547
+ * — installed by the composition root (`Counterpart`, from `schemas/`'s
4548
+ * alias index: the store cannot import it). With one installed, every
4549
+ * memory written through `put` / `putMany` / `supersede`, and every revise
4550
+ * that changes a memory's words, links the cards its title and body name,
4551
+ * in the same transaction. None installed (a bare store, a tool): nothing
4552
+ * is linked, and nothing else changes. One slot; null removes it.
4553
+ */
4554
+ findSubjectsWith(finder: ((text: string) => readonly string[]) | null): void {
4555
+ this.subjectFinder = finder;
4556
+ }
4557
+
4558
+ /**
4559
+ * Inside a write's transaction: the memory's links become what its words
4560
+ * name now — added (`via`), and dropped where the words no longer name a
4561
+ * card. Fail-open: a finder that throws, or a store without the table,
4562
+ * costs the links and never the write (an event says so).
4563
+ */
4564
+ private relinkSubjects(id: string, title: string | null, body: string, via: SubjectLinkVia = "write"): void {
4565
+ const finder = this.subjectFinder;
4566
+ if (finder === null) return;
4567
+ try {
4568
+ if (!this.hasTable("memory_subjects")) return;
4569
+ const want = new Set(finder(title === null || title.length === 0 ? body : `${title}\n${body}`).filter((s) => s !== id));
4570
+ const have = this.ops
4571
+ .all<{ subject_id: string }>("SELECT subject_id FROM memory_subjects WHERE memory_id = ?", id)
4572
+ .map((r) => r.subject_id);
4573
+ for (const s of have) {
4574
+ if (!want.has(s)) this.ops.run("DELETE FROM memory_subjects WHERE memory_id = ? AND subject_id = ?", id, s);
4575
+ }
4576
+ const at = this.nowFn();
4577
+ for (const s of [...want].sort()) {
4578
+ this.ops.run(
4579
+ "INSERT OR IGNORE INTO memory_subjects (memory_id, subject_id, via, created_at) VALUES (?, ?, ?, ?)",
4580
+ id,
4581
+ s,
4582
+ via,
4583
+ at,
4584
+ );
4585
+ }
4586
+ } catch (err) {
4587
+ this.emit("store.subjects.failed", id, { code: err instanceof StoreError ? err.code : "UNKNOWN" });
4588
+ }
4589
+ }
4590
+
4591
+ /**
4592
+ * Links found outside a memory's own write — a card born after the memories
4593
+ * that name it (`via: birth`), and the one pass after the v12 upgrade
4594
+ * (`backfill`). One transaction; idempotent (an existing link stays as it
4595
+ * was found). Returns how many were new. A link to itself is skipped.
4596
+ */
4597
+ linkSubjects(links: readonly { readonly memoryId: string; readonly subjectId: string }[], via: SubjectLinkVia): number {
4598
+ return this.mutate("linkSubjects", () => {
4599
+ if (!this.hasTable("memory_subjects")) return 0;
4600
+ const insert = this.ops.prepare(
4601
+ "INSERT OR IGNORE INTO memory_subjects (memory_id, subject_id, via, created_at) VALUES (?, ?, ?, ?)",
4602
+ );
4603
+ const at = this.nowFn();
4604
+ let added = 0;
4605
+ for (const l of links) {
4606
+ if (l.memoryId === l.subjectId) continue;
4607
+ insert.run(l.memoryId, l.subjectId, via, at);
4608
+ added += (this.ops.get<{ n: number }>("SELECT changes() AS n")?.n ?? 0) > 0 ? 1 : 0;
4609
+ }
4610
+ return added;
4611
+ });
4612
+ }
4613
+
4614
+ /** The cards a memory names (v12), sorted. Empty on a store without the table. */
4615
+ subjectsOf(memoryId: string): string[] {
4616
+ if (!this.hasTable("memory_subjects")) return [];
4617
+ return this.ops
4618
+ .all<{ subject_id: string }>("SELECT subject_id FROM memory_subjects WHERE memory_id = ? ORDER BY subject_id", memoryId)
4619
+ .map((r) => r.subject_id);
4620
+ }
4621
+
4622
+ /** Every link a memory has, with how it was found (v12). */
4623
+ subjectLinksOf(memoryId: string): { subjectId: string; via: string; createdAt: number }[] {
4624
+ if (!this.hasTable("memory_subjects")) return [];
4625
+ return this.ops
4626
+ .all<{ subject_id: string; via: string; created_at: number }>(
4627
+ "SELECT subject_id, via, created_at FROM memory_subjects WHERE memory_id = ? ORDER BY subject_id",
4628
+ memoryId,
4629
+ )
4630
+ .map((r) => ({ subjectId: r.subject_id, via: r.via, createdAt: r.created_at }));
4631
+ }
4632
+
4633
+ /**
4634
+ * The memories that name a card (v12), by id. Live ones only unless
4635
+ * `archived` is true; a removed memory has no links (the owner-op seam
4636
+ * deletes them).
4637
+ */
4638
+ memoriesNaming(subjectId: string, opts: { archived?: boolean } = {}): string[] {
4639
+ if (!this.hasTable("memory_subjects")) return [];
4640
+ return this.ops
4641
+ .all<{ memory_id: string }>(
4642
+ `SELECT s.memory_id FROM memory_subjects s JOIN memories m ON m.id = s.memory_id
4643
+ WHERE s.subject_id = ?${opts.archived === true ? "" : " AND m.archived = 0"}
4644
+ ORDER BY s.memory_id`,
4645
+ subjectId,
4646
+ )
4647
+ .map((r) => r.memory_id);
4648
+ }
4649
+
4650
+ /**
4651
+ * EVERY LIVE ROW deliberate recall's facts mode can answer with (Release B,
4652
+ * 2026-10-03), in one read: memories, episodes and schemas that are not
4653
+ * archived, not superseded and not a tombstone, with the columns facts mode
4654
+ * ranks and labels by — never a body. One query for the whole store, so a
4655
+ * question's pool is matched in memory rather than with a row read per
4656
+ * candidate. A read; nothing here crosses the write seam.
4657
+ */
4658
+ recallRows(): RecallRow[] {
4659
+ const v12 = this.hasColumn("memories", "occurred_on");
4660
+ return this.ops.all<RecallRow>(
4661
+ `SELECT id, type, kind, title, learned_on, created_at, updated_at,
4662
+ ${v12 ? "occurred_on, said_by, status" : "NULL AS occurred_on, NULL AS said_by, NULL AS status"},
4663
+ source, origin_session, origin_scope, origin_ref, confidential,
4664
+ CASE WHEN type = 'memory' THEN NULL ELSE meta END AS meta
4665
+ FROM memories
4666
+ WHERE archived = 0 AND superseded_by IS NULL AND NOT (body = '' AND content_hash = '')
4667
+ ORDER BY id`,
4668
+ );
4669
+ }
4670
+
4671
+ /**
4672
+ * The words of every memory with words — live and archived, never a
4673
+ * tombstone — for a scan that must look at all of them once (a card's
4674
+ * birth, the v12 backfill). Ids, titles and bodies only.
4675
+ */
4676
+ memoryTexts(): { id: string; title: string | null; body: string }[] {
4677
+ return this.ops.all<{ id: string; title: string | null; body: string }>(
4678
+ "SELECT id, title, body FROM memories WHERE type = 'memory' AND body != '' ORDER BY id",
4679
+ );
4680
+ }
4681
+
4682
+ /** How many subject links there are, and on how many memories (v12). Null without the table. */
4683
+ subjectLinkCount(): { links: number; memories: number; subjects: number } | null {
4684
+ if (!this.hasTable("memory_subjects")) return null;
4685
+ const row = this.ops.get<{ links: number; memories: number; subjects: number }>(
4686
+ "SELECT COUNT(*) AS links, COUNT(DISTINCT memory_id) AS memories, COUNT(DISTINCT subject_id) AS subjects FROM memory_subjects",
4687
+ );
4688
+ return { links: row?.links ?? 0, memories: row?.memories ?? 0, subjects: row?.subjects ?? 0 };
4689
+ }
4690
+
4691
+ /**
4692
+ * DOCTOR'S `Write fields` READING (v12): of the memories written since
4693
+ * `since` (UTC ms; null = all) by a door that takes the writer's three
4694
+ * fields — `note`, `session_end` (its write-ups too), a dream's gist — how
4695
+ * many carry each. A dream's MERGE is left out (its words are a dream's,
4696
+ * its `source` the strongest original's, and it takes no fields), as are
4697
+ * chapter copies, the sweep and reflection entries. Null when this file has
4698
+ * no v12 columns yet.
4699
+ */
4700
+ writeFieldShare(since: number | null): { written: number; occurredOn: number; saidBy: number; status: number; all: number } | null {
4701
+ if (!this.hasColumn("memories", "occurred_on")) return null;
4702
+ const row = this.ops.get<{ written: number; occurred_on: number; said_by: number; status: number; all_three: number }>(
4703
+ `SELECT COUNT(*) AS written,
4704
+ COALESCE(SUM(occurred_on IS NOT NULL), 0) AS occurred_on,
4705
+ COALESCE(SUM(said_by IS NOT NULL), 0) AS said_by,
4706
+ COALESCE(SUM(status IS NOT NULL), 0) AS status,
4707
+ COALESCE(SUM(occurred_on IS NOT NULL AND said_by IS NOT NULL AND status IS NOT NULL), 0) AS all_three
4708
+ FROM memories
4709
+ WHERE type = 'memory' AND body != ''
4710
+ AND (source = 'dreamed' OR (source = 'authored' AND (origin_ref IS NULL OR origin_ref NOT LIKE 'dream:%')))
4711
+ AND (? IS NULL OR created_at >= ?)`,
4712
+ since,
4713
+ since,
4714
+ );
4715
+ return {
4716
+ written: row?.written ?? 0,
4717
+ occurredOn: row?.occurred_on ?? 0,
4718
+ saidBy: row?.said_by ?? 0,
4719
+ status: row?.status ?? 0,
4720
+ all: row?.all_three ?? 0,
4721
+ };
4722
+ }
4723
+
4290
4724
  private readonly tablesSeen = new Set<string>();
4291
4725
 
4292
4726
  private traitReads(rows: (TraitRow & { confidential: number })[], includeConfidential: boolean): TraitRead[] {
@@ -4752,8 +5186,8 @@ export class Store {
4752
5186
  archived_reason, superseded_by, revision, content_hash,
4753
5187
  learned_on, happened_on, source, origin_session, origin_scope, origin_ref,
4754
5188
  title, body, meta, confidential, created_at, updated_at, model, event_date, legacy,
4755
- about, about_by)
4756
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, NULL, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
5189
+ about, about_by, occurred_on, said_by, status)
5190
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, NULL, NULL, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
4757
5191
  id,
4758
5192
  input.type,
4759
5193
  input.kind,
@@ -4793,7 +5227,17 @@ export class Store {
4793
5227
  input.physics?.legacy === true ? 1 : 0,
4794
5228
  input.about !== undefined && aboutMarkOf(input.about) !== null ? input.about : null,
4795
5229
  input.about !== undefined && aboutMarkOf(input.about) !== null ? (input.aboutBy ?? "writer") : null,
5230
+ // v12: the writer's three fields. Unreadable or unknown writes NULL —
5231
+ // the belt; the doors drop them with a note before they get here.
5232
+ input.occurredOn === undefined ? null : occurredOnOf(input.occurredOn),
5233
+ input.saidBy === undefined ? null : saidByOf(input.saidBy),
5234
+ input.status === undefined ? null : statusOf(input.status),
4796
5235
  );
5236
+ // v12: WHAT IT NAMES, linked in the same transaction as the row — every
5237
+ // door that writes a memory passes here (a note, a session's dump, a
5238
+ // write-up, the sweep, a chapter copy, a dream's merge or gist, a
5239
+ // reflection's entry), so no door can forget. Memories only.
5240
+ if (input.type === "memory") this.relinkSubjects(id, doc.title ?? null, doc.body, "write");
4797
5241
  return doc;
4798
5242
  }
4799
5243
 
@@ -5133,6 +5577,29 @@ function carryAboutMark(ops: Db, fromId: string, toId: string): void {
5133
5577
  );
5134
5578
  }
5135
5579
 
5580
+ /**
5581
+ * v12: a successor takes each of the writer's three fields its predecessor
5582
+ * had and it was not given — a revision or a merge is still the same memory
5583
+ * (as `carryAboutMark`). Of several originals merged, the first that has one
5584
+ * gives it. Inside the caller's transaction; a file without the columns is
5585
+ * left alone.
5586
+ */
5587
+ function carryWriteFacts(ops: Db, fromId: string, toId: string): void {
5588
+ for (const col of ["occurred_on", "said_by", "status"] as const) {
5589
+ try {
5590
+ ops.run(
5591
+ `UPDATE memories SET ${col} = (SELECT ${col} FROM memories WHERE id = ?)
5592
+ WHERE id = ? AND ${col} IS NULL AND (SELECT ${col} FROM memories WHERE id = ?) IS NOT NULL`,
5593
+ fromId,
5594
+ toId,
5595
+ fromId,
5596
+ );
5597
+ } catch {
5598
+ return;
5599
+ }
5600
+ }
5601
+ }
5602
+
5136
5603
  function modelOrNull(model: string | undefined): string | null {
5137
5604
  return model !== undefined && isModelId(model) ? model : null;
5138
5605
  }