counterparts 0.3.0 → 0.3.2

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 (207) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/docs/module-map.md +2 -0
  3. package/package.json +2 -1
  4. package/src/adapters/claude-code/CONTRACT.md +2 -1
  5. package/src/adapters/claude-code/NOTES.md +90 -2
  6. package/src/adapters/claude-code/bin/hook.ts +17 -2
  7. package/src/adapters/claude-code/bin/runner.ts +4 -1
  8. package/src/adapters/claude-code/config.ts +23 -0
  9. package/src/adapters/claude-code/doctor.ts +148 -26
  10. package/src/adapters/claude-code/hooks.ts +37 -12
  11. package/src/adapters/claude-code/index.ts +2 -0
  12. package/src/adapters/claude-code/standdown.ts +12 -1
  13. package/src/adapters/claude-code/transcript.ts +79 -6
  14. package/src/adapters/cli/INTERFACE-GAPS.md +4 -0
  15. package/src/adapters/cli/commands.ts +209 -61
  16. package/src/adapters/cli/export.ts +27 -3
  17. package/src/adapters/cli/help.ts +22 -8
  18. package/src/adapters/cli/install.ts +3 -5
  19. package/src/adapters/cli/mechanisms.ts +295 -0
  20. package/src/adapters/cli/repair-dates.ts +3 -1
  21. package/src/adapters/cli/snapshot.ts +4 -27
  22. package/src/adapters/dashboard/CONTRACT.md +13 -9
  23. package/src/adapters/dashboard/INTERFACE-GAPS.md +4 -0
  24. package/src/adapters/dashboard/NOTES.md +3 -2
  25. package/src/adapters/dashboard/activity.ts +2 -1
  26. package/src/adapters/dashboard/bin/dashboard.ts +18 -3
  27. package/src/adapters/dashboard/upgrade.ts +23 -0
  28. package/src/adapters/dashboard/web/README.md +153 -0
  29. package/src/adapters/dashboard/web/actions.ts +631 -0
  30. package/src/adapters/dashboard/web/app.html +40 -1703
  31. package/src/adapters/dashboard/web/app.js +55 -0
  32. package/src/adapters/dashboard/web/mechanisms/association/index.js +15 -0
  33. package/src/adapters/dashboard/web/mechanisms/association/panel.js +17 -0
  34. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +15 -0
  35. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +23 -0
  36. package/src/adapters/dashboard/web/mechanisms/decay/index.js +15 -0
  37. package/src/adapters/dashboard/web/mechanisms/decay/panel.js +45 -0
  38. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +15 -0
  39. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +15 -0
  40. package/src/adapters/dashboard/web/mechanisms/index.js +60 -0
  41. package/src/adapters/dashboard/web/mechanisms/interference/index.js +15 -0
  42. package/src/adapters/dashboard/web/mechanisms/picture.js +28 -0
  43. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +15 -0
  44. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +15 -0
  45. package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +15 -0
  46. package/src/adapters/dashboard/web/mechanisms/regions.js +30 -0
  47. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +15 -0
  48. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +20 -0
  49. package/src/adapters/dashboard/web/mechanisms/salience/index.js +15 -0
  50. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +14 -0
  51. package/src/adapters/dashboard/web/mechanisms/schema/index.js +15 -0
  52. package/src/adapters/dashboard/web/narrate.ts +10 -10
  53. package/src/adapters/dashboard/web/pages/flow/flow.css +38 -0
  54. package/src/adapters/dashboard/web/pages/flow/index.js +117 -0
  55. package/src/adapters/dashboard/web/pages/flow/sections/blind.js +12 -0
  56. package/src/adapters/dashboard/web/pages/flow/sections/detail.js +45 -0
  57. package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +291 -0
  58. package/src/adapters/dashboard/web/pages/flow/sections/feed.js +11 -0
  59. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +41 -0
  60. package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +25 -0
  61. package/src/adapters/dashboard/web/pages/flow/sections/records.js +24 -0
  62. package/src/adapters/dashboard/web/pages/flow/sections/symmetry.js +17 -0
  63. package/src/adapters/dashboard/web/pages/flow/state.js +3 -0
  64. package/src/adapters/dashboard/web/pages/health/health.css +93 -0
  65. package/src/adapters/dashboard/web/pages/health/index.js +41 -0
  66. package/src/adapters/dashboard/web/pages/health/sections/archive.js +84 -0
  67. package/src/adapters/dashboard/web/pages/health/sections/checks.js +172 -0
  68. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +37 -0
  69. package/src/adapters/dashboard/web/pages/health/sections/verify.js +54 -0
  70. package/src/adapters/dashboard/web/pages/home/brain.js +375 -0
  71. package/src/adapters/dashboard/web/pages/home/home.css +134 -0
  72. package/src/adapters/dashboard/web/pages/home/index.js +84 -0
  73. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +206 -0
  74. package/src/adapters/dashboard/web/pages/home/sections/hero.js +22 -0
  75. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +25 -0
  76. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +13 -0
  77. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +52 -0
  78. package/src/adapters/dashboard/web/pages/memories/index.js +75 -0
  79. package/src/adapters/dashboard/web/pages/memories/memories.css +143 -0
  80. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +178 -0
  81. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +42 -0
  82. package/src/adapters/dashboard/web/pages/memories/sections/list.js +114 -0
  83. package/src/adapters/dashboard/web/pages/memories/sections/search.js +102 -0
  84. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +155 -0
  85. package/src/adapters/dashboard/web/pages/memories/state.js +22 -0
  86. package/src/adapters/dashboard/web/pages/self/diff.js +79 -0
  87. package/src/adapters/dashboard/web/pages/self/index.js +43 -0
  88. package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
  89. package/src/adapters/dashboard/web/pages/self/sections/journal.js +32 -0
  90. package/src/adapters/dashboard/web/pages/self/sections/page.js +149 -0
  91. package/src/adapters/dashboard/web/pages/self/sections/settling.js +150 -0
  92. package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
  93. package/src/adapters/dashboard/web/pages/self/sections/wake.js +74 -0
  94. package/src/adapters/dashboard/web/pages/self/self.css +182 -0
  95. package/src/adapters/dashboard/web/server.ts +305 -28
  96. package/src/adapters/dashboard/web/shared/absence.js +14 -0
  97. package/src/adapters/dashboard/web/shared/actions.js +48 -0
  98. package/src/adapters/dashboard/web/shared/api.js +17 -0
  99. package/src/adapters/dashboard/web/shared/base.css +34 -0
  100. package/src/adapters/dashboard/web/shared/canvas.js +68 -0
  101. package/src/adapters/dashboard/web/shared/colors.js +6 -0
  102. package/src/adapters/dashboard/web/shared/dom.js +4 -0
  103. package/src/adapters/dashboard/web/shared/event-modal.js +25 -0
  104. package/src/adapters/dashboard/web/shared/fonts/OFL-courier-prime.txt +93 -0
  105. package/src/adapters/dashboard/web/shared/fonts/OFL-outfit.txt +93 -0
  106. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-400.woff2 +0 -0
  107. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-700.woff2 +0 -0
  108. package/src/adapters/dashboard/web/shared/fonts/outfit-latin-wght.woff2 +0 -0
  109. package/src/adapters/dashboard/web/shared/format.js +31 -0
  110. package/src/adapters/dashboard/web/shared/layout.css +32 -0
  111. package/src/adapters/dashboard/web/shared/memory-modal.js +124 -0
  112. package/src/adapters/dashboard/web/shared/modal.css +24 -0
  113. package/src/adapters/dashboard/web/shared/modal.js +22 -0
  114. package/src/adapters/dashboard/web/shared/state.js +12 -0
  115. package/src/adapters/dashboard/web/shared/tip.css +4 -0
  116. package/src/adapters/dashboard/web/shared/tip.js +12 -0
  117. package/src/adapters/dashboard/web/shared/tokens.css +50 -0
  118. package/src/adapters/dashboard/web/shared/type.css +52 -0
  119. package/src/adapters/dashboard/web/shared/utilities.css +5 -0
  120. package/src/adapters/dashboard/web/shared/vendor/MIT-three.txt +21 -0
  121. package/src/adapters/dashboard/web/shared/vendor/three.module.min.js +6 -0
  122. package/src/adapters/dashboard/web/shared/widgets/bar.css +9 -0
  123. package/src/adapters/dashboard/web/shared/widgets/card.css +6 -0
  124. package/src/adapters/dashboard/web/shared/widgets/chapters.js +15 -0
  125. package/src/adapters/dashboard/web/shared/widgets/chart.css +4 -0
  126. package/src/adapters/dashboard/web/shared/widgets/confirm.css +31 -0
  127. package/src/adapters/dashboard/web/shared/widgets/confirm.js +52 -0
  128. package/src/adapters/dashboard/web/shared/widgets/feed.css +13 -0
  129. package/src/adapters/dashboard/web/shared/widgets/feed.js +41 -0
  130. package/src/adapters/dashboard/web/shared/widgets/light.css +4 -0
  131. package/src/adapters/dashboard/web/shared/widgets/light.js +15 -0
  132. package/src/adapters/dashboard/web/shared/widgets/rows.css +7 -0
  133. package/src/adapters/dashboard/web/shared/widgets/table.css +17 -0
  134. package/src/adapters/dashboard/web/shared/widgets/tiles.css +14 -0
  135. package/src/adapters/dashboard/web/shell/pages.js +15 -0
  136. package/src/adapters/dashboard/web/shell/pulse.js +86 -0
  137. package/src/adapters/dashboard/web/shell/tabs.js +49 -0
  138. package/src/adapters/dashboard/web/static.ts +76 -0
  139. package/src/adapters/dashboard/web/views/activity.ts +80 -0
  140. package/src/adapters/dashboard/web/views/archive-words.ts +57 -0
  141. package/src/adapters/dashboard/web/views/flow-view.ts +217 -0
  142. package/src/adapters/dashboard/web/views/health.ts +328 -0
  143. package/src/adapters/dashboard/web/views/mechanism-panel.ts +370 -0
  144. package/src/adapters/dashboard/web/views/mechanisms.ts +302 -0
  145. package/src/adapters/dashboard/web/views/memories.ts +342 -0
  146. package/src/adapters/dashboard/web/views/memory.ts +210 -0
  147. package/src/adapters/dashboard/web/views/meta.ts +64 -0
  148. package/src/adapters/dashboard/web/views/mind.ts +729 -0
  149. package/src/adapters/dashboard/web/views/overview.ts +282 -0
  150. package/src/adapters/dashboard/web/views/pulse.ts +19 -0
  151. package/src/adapters/dashboard/web/views/rows.ts +207 -0
  152. package/src/adapters/dashboard/web/views/search.ts +62 -0
  153. package/src/adapters/dashboard/web/views/shared.ts +161 -0
  154. package/src/adapters/dashboard/web/views.ts +34 -1724
  155. package/src/adapters/fired.ts +138 -31
  156. package/src/adapters/mcp/INTERFACE-GAPS.md +4 -1
  157. package/src/adapters/mcp/NOTES.md +43 -0
  158. package/src/adapters/mcp/bin/serve.ts +9 -1
  159. package/src/adapters/mcp/index.ts +7 -0
  160. package/src/adapters/mcp/server.ts +167 -6
  161. package/src/adapters/mcp/tools.ts +42 -0
  162. package/src/adapters/mcp/write-up.ts +1 -1
  163. package/src/adapters/sessions.ts +18 -1
  164. package/src/adapters/snapshots.ts +71 -39
  165. package/src/core/associate/INTERFACE-GAPS.md +8 -0
  166. package/src/core/counterpart.ts +86 -7
  167. package/src/core/encode/INTERFACE-GAPS.md +12 -0
  168. package/src/core/feelings-wheel.ts +218 -0
  169. package/src/core/handoff/INTERFACE-GAPS.md +2 -0
  170. package/src/core/mint.ts +14 -2
  171. package/src/core/prospective/INTERFACE-GAPS.md +14 -0
  172. package/src/core/prospective/windows.ts +10 -48
  173. package/src/core/recall/INTERFACE-GAPS.md +6 -0
  174. package/src/core/remember/INTERFACE-GAPS.md +10 -0
  175. package/src/core/schemas/INTERFACE-GAPS.md +8 -0
  176. package/src/core/schemas/NOTES.md +118 -1
  177. package/src/core/schemas/index.ts +330 -40
  178. package/src/core/schemas/tunables.ts +23 -0
  179. package/src/core/schemas/types.ts +64 -1
  180. package/src/core/self/CONTRACT.md +3 -0
  181. package/src/core/self/INTERFACE-GAPS.md +10 -0
  182. package/src/core/self/NOTES.md +33 -2
  183. package/src/core/self/calendar.ts +7 -78
  184. package/src/core/self/episodes.ts +52 -12
  185. package/src/core/self/index.ts +40 -12
  186. package/src/core/self/writer.ts +22 -22
  187. package/src/core/sleep/NOTES.md +36 -0
  188. package/src/core/sleep/cycle.ts +38 -3
  189. package/src/core/sleep/fade.ts +76 -0
  190. package/src/core/sleep/index.ts +4 -1
  191. package/src/core/sleep/prune.ts +8 -1
  192. package/src/core/sleep/tunables.ts +5 -0
  193. package/src/core/sleep/types.ts +24 -0
  194. package/src/core/store/CONTRACT.md +36 -7
  195. package/src/core/store/NOTES.md +197 -0
  196. package/src/core/store/errors.ts +22 -0
  197. package/src/core/store/feelings.ts +182 -0
  198. package/src/core/store/index.ts +339 -45
  199. package/src/core/store/operational.ts +240 -22
  200. package/src/core/store/owner-op-seam.ts +13 -3
  201. package/src/core/store/paths.ts +15 -1
  202. package/src/core/store/pre-migration.ts +258 -0
  203. package/src/core/store/prose.ts +8 -1
  204. package/src/core/store/render.ts +3 -0
  205. package/src/core/time.ts +374 -0
  206. package/src/core/types.ts +13 -0
  207. package/src/adapters/dashboard/web/brain.html +0 -463
@@ -32,7 +32,8 @@
32
32
  * nobody needed).
33
33
  */
34
34
  import { spawnSync } from "node:child_process";
35
- import { existsSync, statSync } from "node:fs";
35
+ import { addDays, isDay, localDate, resolveZone } from "../../core/time.js";
36
+ import { existsSync, mkdirSync, rmSync, statSync } from "node:fs";
36
37
  import { homedir } from "node:os";
37
38
  import { dirname, join } from "node:path";
38
39
  import { fileURLToPath } from "node:url";
@@ -53,7 +54,15 @@ import {
53
54
  SWEEP_GATE_EVENT,
54
55
  } from "../../core/counterpart.js";
55
56
  import { Counterpart } from "../../core/counterpart.js";
56
- import { STORE_CREATED_KEY, Store, dateOf, isStoreError, paths } from "../../core/store/index.js";
57
+ import {
58
+ STORE_CREATED_KEY,
59
+ Store,
60
+ assertPreMigrationTarget,
61
+ isStoreError,
62
+ paths,
63
+ pendingMigration,
64
+ preMigrationDir,
65
+ } from "../../core/store/index.js";
57
66
  import { BUSY_TIMEOUT_MS, journalModeOf } from "../../core/store/db.js";
58
67
  import type { EventRow } from "../../core/store/index.js";
59
68
  // The ask allowance the amber hint names, read rather than retyped: a number in
@@ -200,7 +209,8 @@ export interface DoctorInput {
200
209
  readonly dir: string;
201
210
  /** Null when there is no store at `dir` — the store findings then say so. */
202
211
  readonly store: Store | null;
203
- /** Today, UTC, `YYYY-MM-DD` — the same spelling every `date` field uses. */
212
+ /** Today in the person's zone, `YYYY-MM-DD` — the same spelling every `date`
213
+ * field uses (UTC until 2026-09-25; docs/time.md). */
204
214
  readonly today: string;
205
215
  /**
206
216
  * The persisted spawn-refusal counters, `reason -> count`
@@ -553,6 +563,46 @@ export interface OpenReading {
553
563
  * `MEMORY_BODY_MISSING` carries one and no path, because on this floor the
554
564
  * words are the row and there is no file to restore (review B, MAJOR-3). */
555
565
  readonly id: string | null;
566
+ /**
567
+ * The schema upgrade the next session will run, when the store is behind —
568
+ * and whether the copy it takes first can be made. An observer never
569
+ * migrates, so without this the open reads fine (or merely "behind") while
570
+ * every hook refuses `MIGRATION_SNAPSHOT_FAILED`. Absent: not behind.
571
+ */
572
+ readonly migration?: MigrationReading;
573
+ }
574
+
575
+ export interface MigrationReading {
576
+ readonly found: string;
577
+ readonly expected: number;
578
+ /** Where the copy would go; null when there is nowhere. */
579
+ readonly dir: string | null;
580
+ /** Why the copy could not be made, or null when the dry run passed. */
581
+ readonly problem: string | null;
582
+ }
583
+
584
+ /**
585
+ * The pre-migration copy's preconditions, tried without taking it: the
586
+ * destination passes the store's own checks, and a probe directory can be
587
+ * made there and removed again (only what the probe itself created goes). The
588
+ * probe's name is a `.partial-…` one, so if its removal failed the daily sweep
589
+ * would take it.
590
+ */
591
+ export function probePreMigration(storeDir: string, snapshotsDir?: string): MigrationReading | null {
592
+ const dbPath = paths.operational(storeDir);
593
+ const pending = pendingMigration(dbPath);
594
+ if (pending === null) return null;
595
+ const dir = preMigrationDir(dbPath, snapshotsDir);
596
+ try {
597
+ const real = assertPreMigrationTarget(dbPath, dir);
598
+ const instant = new Date().toISOString().replace(/[:.]/g, "-");
599
+ const probe = join(real, `.partial-${instant}-${String(process.pid)}`);
600
+ const first = mkdirSync(probe, { recursive: true });
601
+ rmSync(first ?? probe, { recursive: true, force: true });
602
+ return { ...pending, dir, problem: null };
603
+ } catch (err) {
604
+ return { ...pending, dir, problem: err instanceof Error ? err.message : String(err) };
605
+ }
556
606
  }
557
607
 
558
608
  /**
@@ -568,13 +618,18 @@ export function readCounterpartOpen(
568
618
  /** Injectable so the failure branches are provable without a broken fixture;
569
619
  * the fixture test is still the one that proves the real path. */
570
620
  open: (d: string) => { close: () => void } = (d) => Counterpart.open({ dir: d, observer: true }),
621
+ /** The host configuration's `snapshots.dir`, for the pre-migration dry run. */
622
+ snapshotsDir?: string,
571
623
  ): OpenReading {
572
624
  let opened: { close: () => void } | null = null;
625
+ const migration = probePreMigration(dir, snapshotsDir);
626
+ const behind = migration === null ? {} : { migration };
573
627
  try {
574
628
  // OBSERVER, because `doctor` is an instrument: it reads and never writes,
575
629
  // and an owner open of a store that is not there would MINT one.
576
630
  opened = open(dir);
577
631
  return {
632
+ ...behind,
578
633
  dir,
579
634
  ok: true,
580
635
  code: null,
@@ -587,6 +642,7 @@ export function readCounterpartOpen(
587
642
  } catch (err) {
588
643
  const fault = describeFault(err);
589
644
  return {
645
+ ...behind,
590
646
  dir,
591
647
  ok: false,
592
648
  code: fault.code,
@@ -609,6 +665,18 @@ export function readCounterpartOpen(
609
665
 
610
666
  // ── the groups ──────────────────────────────────────────────────────────────
611
667
 
668
+ /** The Memory line for a store this build reads only after its upgrade. */
669
+ function behindFinding(dir: string, m: MigrationReading): Finding {
670
+ return finding(
671
+ "store",
672
+ "amber",
673
+ MEMORY_TITLE,
674
+ `${tilde(dir)} is on schema v${m.found}; this build reads it once a session has upgraded it (see Store open)`,
675
+ "",
676
+ { dir, exists: true, found: m.found, expected: m.expected },
677
+ );
678
+ }
679
+
612
680
  /** A finding, with `data` defaulted so each group below stays one expression. */
613
681
  function finding(
614
682
  key: string,
@@ -712,10 +780,17 @@ function payloadOf(row: EventRow | undefined): Record<string, unknown> {
712
780
 
713
781
  /** The CALENDAR date a row is about: its own field, else the wall clock it was
714
782
  * written at. `day` is the lived-day column and answers a different question. */
783
+ /**
784
+ * The zone this reading names days in — the config's `timeZone`, else the
785
+ * machine's — set once at the top of `doctorFindings` (which is synchronous)
786
+ * so the dozen `rowDate` calls below need no extra argument.
787
+ */
788
+ let readingZone: string = resolveZone(undefined);
789
+
715
790
  function rowDate(row: EventRow | undefined): string | null {
716
791
  if (row === undefined) return null;
717
792
  const p = payloadOf(row);
718
- return typeof p["date"] === "string" && p["date"].length > 0 ? p["date"] : dateOf(row.at);
793
+ return typeof p["date"] === "string" && p["date"].length > 0 ? p["date"] : localDate(row.at, readingZone);
719
794
  }
720
795
 
721
796
  function num(p: Record<string, unknown>, key: string): number | null {
@@ -792,8 +867,11 @@ function configFindings(input: DoctorInput): Finding[] {
792
867
  // same number because it is the same number, and rule 3 of this module —
793
868
  // it is on the hot path, so it is bounded — is kept by not asking twice.
794
869
  const held = input.store === null ? null : memoryCount(input.store);
870
+ const behind = input.store === null ? input.open?.migration : undefined;
795
871
  out.push(
796
- input.store === null
872
+ behind !== undefined
873
+ ? behindFinding(input.dir, behind)
874
+ : input.store === null
797
875
  ? finding("store", "red", MEMORY_TITLE, `no store at ${tilde(input.dir)}`, "Check the path you gave --dir.", {
798
876
  dir: input.dir,
799
877
  exists: false,
@@ -859,7 +937,9 @@ function configFindings(input: DoctorInput): Finding[] {
859
937
  // shape: the hooks and another entry point named different stores and nothing
860
938
  // noticed, because each was internally consistent.
861
939
  const named = input.config.dataDir;
862
- if (input.store === null) {
940
+ if (input.store === null && input.open?.migration !== undefined) {
941
+ out.push(behindFinding(input.dir, input.open.migration));
942
+ } else if (input.store === null) {
863
943
  out.push(
864
944
  finding("store", "red", MEMORY_TITLE, `no store at ${tilde(input.dir)}`, "Run: counterparts install, or name the store with --dir.", {
865
945
  dir: input.dir,
@@ -1240,6 +1320,18 @@ function retentionFindings(input: DoctorInput, store: Store): Finding[] {
1240
1320
  return [finding("retention", "green", TITLE, `${policy} · ${counts}`, "", data)];
1241
1321
  }
1242
1322
 
1323
+ /**
1324
+ * THE ZONE IN USE, on the Clock line (docs/time.md, 2026-09-25): `(America/Denver)`,
1325
+ * and when the config names a zone this machine does not know, that too — it
1326
+ * was ignored, and this is where the owner sees it.
1327
+ */
1328
+ function zoneNote(input: DoctorInput): string {
1329
+ const unknown = input.config.timeZoneUnknown;
1330
+ return unknown === undefined
1331
+ ? `(${readingZone})`
1332
+ : `(${readingZone}; timeZone "${unknown}" in the config is not a zone this machine knows, so it was ignored)`;
1333
+ }
1334
+
1243
1335
  /** The two clocks, and the gap that IS I32's signature. */
1244
1336
  function clockFindings(input: DoctorInput, store: Store): Finding[] {
1245
1337
  const livedDay = store.livedDay();
@@ -1255,13 +1347,13 @@ function clockFindings(input: DoctorInput, store: Store): Finding[] {
1255
1347
  // the clock, so the comparison is not made and the line says why.
1256
1348
  if (read.unknown) {
1257
1349
  const facts =
1258
- `lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, today ${input.today} (UTC) — ` +
1350
+ `lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, today ${input.today} ${zoneNote(input)} — ` +
1259
1351
  undetermined(BOUNDARY_EVENT);
1260
1352
  return [finding("clock", "green", "Clock", facts, "", data)];
1261
1353
  }
1262
1354
  const facts =
1263
1355
  `lived day ${livedDay}, lastActiveDate ${lastActive ?? "(unset)"}, ` +
1264
- `newest boundary ${boundary ?? "(none)"}, today ${input.today} (UTC)`;
1356
+ `newest boundary ${boundary ?? "(none)"}, today ${input.today} ${zoneNote(input)}`;
1265
1357
  if (boundary !== null && (lastActive === null || lastActive < boundary)) {
1266
1358
  return [
1267
1359
  finding(
@@ -1559,25 +1651,25 @@ function storeFirstDay(store: Store): string | null {
1559
1651
  return readings.length === 0 ? null : readings.reduce((a, b) => (b < a ? b : a));
1560
1652
  }
1561
1653
 
1562
- /** The calendar day (UTC) of the EARLIEST `at` among the store's event rows,
1563
- * or null when it has none, or none that can be read. */
1654
+ /** The calendar day (the person's zone) of the EARLIEST `at` among the store's
1655
+ * event rows, or null when it has none, or none that can be read. */
1564
1656
  function oldestEventDay(store: Store): string | null {
1565
1657
  try {
1566
1658
  const at = store.eventLogCensus().oldestAt;
1567
- return typeof at === "number" && Number.isFinite(at) && at > 0 ? dateOf(at) : null;
1659
+ return typeof at === "number" && Number.isFinite(at) && at > 0 ? localDate(at, readingZone) : null;
1568
1660
  } catch {
1569
1661
  return null;
1570
1662
  }
1571
1663
  }
1572
1664
 
1573
- /** The calendar day (UTC) the store's database file was born, or null when the
1665
+ /** The calendar day (the person's zone) the store's database file was born, or null when the
1574
1666
  * filesystem keeps no birth time — zero, or a "birth" no earlier than the last
1575
1667
  * change, which is what a filesystem without one may report instead. */
1576
1668
  function databaseBirthDay(dir: string): string | null {
1577
1669
  try {
1578
1670
  const stat = statSync(paths.operational(dir));
1579
1671
  const born = stat.birthtimeMs;
1580
- return Number.isFinite(born) && born > 0 && born < stat.ctimeMs ? dateOf(born) : null;
1672
+ return Number.isFinite(born) && born > 0 && born < stat.ctimeMs ? localDate(born, readingZone) : null;
1581
1673
  } catch {
1582
1674
  return null;
1583
1675
  }
@@ -1605,11 +1697,9 @@ function windowPhrase(shown: string, today: string): string {
1605
1697
  return shown === today ? `since ${today}` : `${shown}→${today}`;
1606
1698
  }
1607
1699
 
1608
- /** `YYYY-MM-DD`, `back` days before `today`. UTC, like every date in this store. */
1700
+ /** `YYYY-MM-DD`, `back` days before `today` — label arithmetic (`time.ts`). */
1609
1701
  function daysBefore(today: string, back: number): string {
1610
- const at = Date.parse(`${today}T00:00:00Z`);
1611
- if (Number.isNaN(at)) return today;
1612
- return new Date(at - back * 86_400_000).toISOString().slice(0, 10);
1702
+ return isDay(today) ? addDays(today, -back) : today;
1613
1703
  }
1614
1704
 
1615
1705
  /** Every row of one name whose CALENDAR date is on or after `from`. */
@@ -1829,7 +1919,7 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
1829
1919
  `this store is on lived day ${String(report.livedDay)} — too new to grade; nothing has fired ` +
1830
1920
  `because nothing has happened yet` +
1831
1921
  (c.blocked === 0 ? "" : `, though ${String(c.blocked)} was already stopped by something`),
1832
- c.blocked === 0 ? "" : "Run: counterparts fired — the blocked rows say by what.",
1922
+ c.blocked === 0 ? "" : "Run: counterparts mechanisms --all — the blocked rows say by what.",
1833
1923
  data,
1834
1924
  ),
1835
1925
  ];
@@ -1866,8 +1956,8 @@ function firedFindings(input: DoctorInput, store: Store): Finding[] {
1866
1956
  "Fired",
1867
1957
  `${roll}. ${changed.join(". ")}`,
1868
1958
  report.wentBlocked.length > 0
1869
- ? `Run: counterparts fired — ${STATE_MEANING.blocked}, and the reason on the row names what to fix.`
1870
- : `Run: counterparts fired — ${STATE_MEANING.quiet}, which is a wiring fault more often than a verdict.`,
1959
+ ? `Run: counterparts mechanisms --all — ${STATE_MEANING.blocked}, and the reason on the row names what to fix.`
1960
+ : `Run: counterparts mechanisms --all — ${STATE_MEANING.quiet}, which is a wiring fault more often than a verdict.`,
1871
1961
  data,
1872
1962
  ),
1873
1963
  ];
@@ -2023,6 +2113,31 @@ function openFindings(reading: OpenReading): Finding[] {
2023
2113
  busy: reading.busy,
2024
2114
  path: reading.path,
2025
2115
  };
2116
+ // A STORE BEHIND THIS BUILD is graded on what a SESSION will meet, not on
2117
+ // what this observer open met: the session copies it, then upgrades it.
2118
+ const m = reading.migration;
2119
+ if (m !== undefined) {
2120
+ const upgrade = { ...data, found: m.found, expected: m.expected, snapshotsDir: m.dir, problem: m.problem };
2121
+ return [
2122
+ m.problem !== null
2123
+ ? finding(
2124
+ "store-open",
2125
+ "red",
2126
+ "Store open",
2127
+ `${reading.dir} is on schema v${m.found} and this build needs v${m.expected}; the copy taken before the upgrade cannot be made (${m.problem}), so every hook stands down with MIGRATION_SNAPSHOT_FAILED`,
2128
+ `Make ${m.dir ?? "a snapshots directory"} writable${m.dir === null ? " and name it in snapshots.dir" : " (or point snapshots.dir at one outside the store)"}; the store is unchanged, and the previous build still opens it.`,
2129
+ upgrade,
2130
+ )
2131
+ : finding(
2132
+ "store-open",
2133
+ "amber",
2134
+ "Store open",
2135
+ `${reading.dir} is on schema v${m.found}; the next session copies it to ${m.dir ?? "?"} and upgrades it to v${m.expected}`,
2136
+ "Nothing to do: start a session, then run counterparts doctor again.",
2137
+ upgrade,
2138
+ ),
2139
+ ];
2140
+ }
2026
2141
  if (reading.ok) {
2027
2142
  return [
2028
2143
  finding("store-open", "green", "Store open", `${reading.dir} opens as a session opens it`, "", data),
@@ -2257,7 +2372,7 @@ export function selfPageFindings(store: Store): Finding[] {
2257
2372
  ),
2258
2373
  ];
2259
2374
  }
2260
- const stale = pageStaleOn(page.revisedOn, dateOf(store.now()), SELF_TUNABLES.PAGE_STALE_DAYS);
2375
+ const stale = pageStaleOn(page.revisedOn, store.today(), SELF_TUNABLES.PAGE_STALE_DAYS);
2261
2376
  const detail =
2262
2377
  `${page.bytes} bytes, version ${page.version}, last revised ${page.revisedOn === "" ? "(unrecorded)" : page.revisedOn}` +
2263
2378
  `${page.by === null ? "" : ` by ${page.by}`}`;
@@ -2396,7 +2511,7 @@ export function pageWriterFindings(store: Store, config: AdapterConfig): Finding
2396
2511
  "Page writer",
2397
2512
  detail,
2398
2513
  bad || overdue
2399
- ? "counterparts fired --dir <store> --observer shows the run's own row. A night that is owed but never delivered is usually the host's injection ceiling: the block is deferred rather than truncated, so raise injectionBudgetBytes or run the writer in host mode. counterparts self-page --write amends the page by hand meanwhile."
2514
+ ? "counterparts mechanisms --all --dir <store> --observer shows the run's own row. A night that is owed but never delivered is usually the host's injection ceiling: the block is deferred rather than truncated, so raise injectionBudgetBytes or run the writer in host mode. counterparts self-page --write amends the page by hand meanwhile."
2400
2515
  : "",
2401
2516
  {
2402
2517
  ...data,
@@ -2544,6 +2659,10 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
2544
2659
  disk.preRows.length === 0
2545
2660
  ? ""
2546
2661
  : `; ${String(disk.preRows.length)} older-format cop${disk.preRows.length === 1 ? "y" : "ies"} this build cannot open — kept, never rotated, read by the build tagged floor/v5-last: ${disk.preRows.slice(0, 3).join(", ")}${disk.preRows.length > 3 ? ` and ${String(disk.preRows.length - 3)} more` : ""}`;
2662
+ // The newest copy the store took before a schema migration, when there is
2663
+ // one: a clause, not a grade — it is the copy to roll an upgrade back to.
2664
+ const lastUpgrade = disk.preMigration[disk.preMigration.length - 1] ?? null;
2665
+ const upgrade = lastUpgrade === null ? "" : `; before the last schema upgrade: ${lastUpgrade}`;
2547
2666
  const held = {
2548
2667
  ...data,
2549
2668
  onDisk,
@@ -2553,6 +2672,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
2553
2672
  future,
2554
2673
  unrecognised: disk.unrecognised.length,
2555
2674
  preRows: disk.preRows.length,
2675
+ preMigration: lastUpgrade,
2556
2676
  };
2557
2677
 
2558
2678
  const read = newestRows(store, SNAPSHOT_TAKEN_EVENT, 1, livedDay);
@@ -2567,7 +2687,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
2567
2687
  "snapshot",
2568
2688
  "amber",
2569
2689
  "Snapshots",
2570
- `${disk.readable ? "the snapshots directory is empty" : "the snapshots directory is missing or unreadable"} — but a snapshot.taken row says one was made${rowDated === null ? "" : ` on ${rowDated}`}. There is nothing to restore from.${strange}`,
2690
+ `${disk.readable ? "the snapshots directory is empty" : "the snapshots directory is missing or unreadable"} — but a snapshot.taken row says one was made${rowDated === null ? "" : ` on ${rowDated}`}. There is nothing to restore from.${strange}${upgrade}`,
2571
2691
  RESTORE_STEPS,
2572
2692
  { ...held, rows: 1 },
2573
2693
  ),
@@ -2592,7 +2712,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
2592
2712
  "snapshot",
2593
2713
  "amber",
2594
2714
  "Snapshots",
2595
- `no snapshot has ever been taken here${why}${strange}${misread}`,
2715
+ `no snapshot has ever been taken here${why}${strange}${upgrade}${misread}`,
2596
2716
  "The worker takes one after the sleep cycle; the next boundary should leave a snapshot.taken row.",
2597
2717
  { ...held, rows: 0 },
2598
2718
  )
@@ -2600,7 +2720,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
2600
2720
  "snapshot",
2601
2721
  "green",
2602
2722
  "Snapshots",
2603
- `no snapshot yet — and no boundary has been reached here yet${strange}${misread}`,
2723
+ `no snapshot yet — and no boundary has been reached here yet${strange}${upgrade}${misread}`,
2604
2724
  "",
2605
2725
  { ...held, rows: 0 },
2606
2726
  ),
@@ -2623,6 +2743,7 @@ function snapshotFindings(input: DoctorInput, store: Store): Finding[] {
2623
2743
  : "") +
2624
2744
  strange +
2625
2745
  older +
2746
+ upgrade +
2626
2747
  misread;
2627
2748
  // Two or more calendar days back is a daily mechanism that has missed one, so
2628
2749
  // the boundary day itself is already amber.
@@ -2877,6 +2998,7 @@ export function summaryLine(t: Record<Lowercase<GradeWord>, number>): string {
2877
2998
  * I32's own signature.
2878
2999
  */
2879
3000
  export function doctorFindings(input: DoctorInput): Finding[] {
3001
+ readingZone = resolveZone(input.config.timeZone);
2880
3002
  const now = input.now ?? ((): number => Date.now());
2881
3003
  const deadline = input.budgetMs === undefined ? null : now() + input.budgetMs;
2882
3004
  const unread = input.configReason === "not-read";
@@ -3146,7 +3268,7 @@ const TITLE_COLUMN = 20;
3146
3268
  * not green. */
3147
3269
  export function reportLines(findings: readonly Finding[], today: string): string[] {
3148
3270
  const ordered = worstFirst(findings);
3149
- const lines = [`counterparts doctor — ${today} (UTC)`, ""];
3271
+ const lines = [`counterparts doctor — ${today}`, ""];
3150
3272
  for (const f of ordered) lines.push(...findingLines(f));
3151
3273
  lines.push("");
3152
3274
  lines.push(summaryLine(tally(ordered)));
@@ -98,6 +98,7 @@ import {
98
98
  writerInstruction,
99
99
  writerInstructionOverhead,
100
100
  } from "../../core/self/index.js";
101
+ import { localClock, localDate } from "../../core/time.js";
101
102
  import { capabilities, pageWriterMode } from "./config.js";
102
103
  import { TUNABLES } from "./config.js";
103
104
  import type { AdapterConfig, CapabilityReport } from "./config.js";
@@ -162,6 +163,8 @@ export interface HookInput {
162
163
  * file read for the one thing that parse deliberately skips.
163
164
  */
164
165
  readonly transcriptPath?: string;
166
+ /** The model that wrote the transcript's last assistant entry, when known. */
167
+ readonly model?: string;
165
168
  /** Today's calendar date, for the temporal channel and the horizon lane. */
166
169
  readonly at?: string;
167
170
  /**
@@ -688,10 +691,19 @@ export class ClaudeCodeAdapter {
688
691
  // running (mechanism inventory 2026-09-17, S2).
689
692
  this.noteWakeExpectation(input, woke.sentinel);
690
693
 
691
- if (budget !== undefined && woke.bytes > budget) {
694
+ // THE PERSON'S CLOCK, as the wake's first line (docs/time.md rule 5,
695
+ // 2026-09-25): `Now: Fri 25 Sep 2026, 1:40 pm MDT`, in the store's zone.
696
+ // OUTSIDE the wake block, above its opening comment, so the block's own
697
+ // byte count, both sentinels and the preface's reserve are untouched —
698
+ // the delivery check finds its sentinels by prefix, not by line number.
699
+ // It is counted wherever the host's ceiling is: the over-budget event
700
+ // and the room an ask may take both measure `sent`, not `woke.bytes`.
701
+ const lead = woke.text.length === 0 ? "" : `${this.nowLine()}\n`;
702
+ const sent = woke.bytes + Buffer.byteLength(lead, "utf8");
703
+ if (budget !== undefined && sent > budget) {
692
704
  // Exceeding a reported limit is an EVENT, never silent degradation. The
693
705
  // bundle still goes: truncated-and-detectable beats absent.
694
- this.emit("adapter.injection.overbudget", { bytes: woke.bytes, budget });
706
+ this.emit("adapter.injection.overbudget", { bytes: sent, budget });
695
707
  }
696
708
  this.record(WAKE_INJECTED_EVENT, input, {
697
709
  ok: woke.ok,
@@ -736,22 +748,22 @@ export class ClaudeCodeAdapter {
736
748
  // question is advisory and returns at the next session; a night that
737
749
  // passes is a day missing from the page for good (S2 review, MINOR-5).
738
750
  const scopeFirst = wantsAsk && !this.writerStarvedByScope();
739
- const ask = scopeFirst ? this.deliverScopeAsk(input, woke.bytes, budget) : "";
751
+ const ask = scopeFirst ? this.deliverScopeAsk(input, sent, budget) : "";
740
752
  const chosen =
741
- ask.length > 0 ? ask : this.deliverPageWriterAsk(input, woke.bytes, budget, false);
742
- if (ask.length > 0) this.deliverPageWriterAsk(input, woke.bytes, budget, true);
753
+ ask.length > 0 ? ask : this.deliverPageWriterAsk(input, sent, budget, false);
754
+ if (ask.length > 0) this.deliverPageWriterAsk(input, sent, budget, true);
743
755
  // THE WRITE-UP POINTER RIDES AFTER WHICHEVER ASK TOOK THE FIELD, never
744
756
  // instead of it (C2): it may coincide with either, it is measured against
745
757
  // the room BOTH of them left, and it is fail-open by construction — a
746
758
  // throw inside it costs the pointer and never the wake or the other ask.
747
759
  const chosenBytes = chosen.length === 0 ? 0 : Buffer.byteLength(`\n\n${chosen}`, "utf8");
748
- const writeUp = this.deliverWriteUpAsk(input, woke.bytes + chosenBytes);
760
+ const writeUp = this.deliverWriteUpAsk(input, sent + chosenBytes);
749
761
  const asks = [chosen, writeUp].filter((a) => a.length > 0).join("\n\n");
750
762
  return {
751
763
  ...out,
752
764
  ok: woke.ok,
753
765
  reason: woke.reason,
754
- injection: woke.text,
766
+ injection: `${lead}${woke.text}`,
755
767
  bytes: woke.bytes,
756
768
  sentinel: woke.sentinel,
757
769
  ask: asks.length === 0 ? null : asks,
@@ -1110,7 +1122,7 @@ export class ClaudeCodeAdapter {
1110
1122
  const text = writeUpPointer({
1111
1123
  waiting: owed.length,
1112
1124
  ended: held.session,
1113
- endedOn: calendarDate(held.clockFrom),
1125
+ endedOn: calendarDate(held.clockFrom, this.counterpart.store.zone()),
1114
1126
  bytes: cut.slice(done).reduce((n, p) => n + Buffer.byteLength(p, "utf8"), 0),
1115
1127
  part: Math.min(done + 1, partsCount),
1116
1128
  of: partsCount,
@@ -1198,7 +1210,7 @@ export class ClaudeCodeAdapter {
1198
1210
  this.checkWakeArrival(input);
1199
1211
  const text = input.prompt ?? "";
1200
1212
  if (text.trim().length === 0) {
1201
- return { ...out, ok: true, reason: "empty-prompt" };
1213
+ return { ...out, ok: true, reason: "empty-prompt", injection: this.nowLine() };
1202
1214
  }
1203
1215
  const result = this.counterpart.recallForTurn(
1204
1216
  {
@@ -1234,7 +1246,12 @@ export class ClaudeCodeAdapter {
1234
1246
  ...out,
1235
1247
  ok: true,
1236
1248
  reason: decision.reason,
1237
- injection: result.injection,
1249
+ // The current local time, EVERY turn (docs/time.md rule 5; the owner
1250
+ // asked for it on quiet turns too, 2026-09-25 — ~40 bytes), because a
1251
+ // session can run for hours. One line ABOVE the recall note when there
1252
+ // is one, outside it like the wake's, so the note's byte count and
1253
+ // sentinel stand; alone when recall surfaced nothing.
1254
+ injection: result.injection.length === 0 ? this.nowLine() : `${this.nowLine()}\n${result.injection}`,
1238
1255
  bytes: decision.bytes,
1239
1256
  sentinel: decision.sentinel,
1240
1257
  // The footnote tier is carried SEPARATELY from the loud one, because the
@@ -1245,6 +1262,11 @@ export class ClaudeCodeAdapter {
1245
1262
  });
1246
1263
  }
1247
1264
 
1265
+ /** `Now: Fri 25 Sep 2026, 1:40 pm MDT` — this adapter's clock, in the store's zone. */
1266
+ private nowLine(): string {
1267
+ return `Now: ${localClock(this.nowFn(), this.counterpart.store.zone())}`;
1268
+ }
1269
+
1248
1270
  /**
1249
1271
  * "COUNTERPARTS WAS UPDATED" — the line this session's terminal gets, once,
1250
1272
  * when the MCP server it is talking to runs an older build than the one
@@ -1848,6 +1870,9 @@ export class ClaudeCodeAdapter {
1848
1870
  ...(this.configPath === undefined || this.configPath.length === 0
1849
1871
  ? {}
1850
1872
  : { config: this.configPath }),
1873
+ // Which model answered last. A Stop writes this before its ask goes out,
1874
+ // so the chapter that answers the ask finds it on the record.
1875
+ ...(input.model === undefined ? {} : { model: input.model }),
1851
1876
  });
1852
1877
  this.emit("adapter.session.registry", { phase, ok: record !== null });
1853
1878
  // Bounded growth, once per session rather than once per turn — and never on
@@ -2113,7 +2138,7 @@ export class ClaudeCodeAdapter {
2113
2138
  */
2114
2139
  private noteSpawnStart(input?: HookInput): void {
2115
2140
  if (this.observer) return;
2116
- const date = input?.at ?? new Date(this.nowFn()).toISOString().slice(0, 10);
2141
+ const date = input?.at ?? localDate(this.nowFn(), this.counterpart.store.zone());
2117
2142
  try {
2118
2143
  this.bumpStart(date);
2119
2144
  this.counterpart.noteAdapterEvent(
@@ -2249,7 +2274,7 @@ export class ClaudeCodeAdapter {
2249
2274
  ): string | null {
2250
2275
  if (this.observer) return null;
2251
2276
  try {
2252
- const today = input.at ?? new Date(this.nowFn()).toISOString().slice(0, 10);
2277
+ const today = input.at ?? localDate(this.nowFn(), this.counterpart.store.zone());
2253
2278
  // WHICH CODE IS LIVE, read before anything else and RECORDED. The reading
2254
2279
  // is bounded and never throws (`readCheckout`); the row is the mechanized
2255
2280
  // half — a day on master leaves one latched row, and a day the tree
@@ -159,11 +159,13 @@ export function openAdapter(
159
159
  // and the LIVE face the novelty seam and the sweep's warm call use.
160
160
  ...(embedder === null ? {} : { embed: embedder.embed, vectors: embedder }),
161
161
  ...(config.dataDir === undefined ? {} : { dir: config.dataDir }),
162
+ ...(config.snapshots?.dir === undefined ? {} : { snapshotsDir: config.snapshots.dir }),
162
163
  ...(config.injectionBudgetBytes === undefined
163
164
  ? {}
164
165
  : { budgetBytes: config.injectionBudgetBytes }),
165
166
  ...(config.observer === undefined ? {} : { observer: config.observer }),
166
167
  ...(config.owner === undefined ? {} : { owner: config.owner }),
168
+ ...(config.timeZone === undefined ? {} : { timeZone: config.timeZone }),
167
169
  ...(config.identity === undefined
168
170
  ? {}
169
171
  : { identity: { name: config.identity.name, aliases: [...(config.identity.aliases ?? [])] } }),
@@ -132,6 +132,7 @@ const PLAIN_WORDS: Partial<Record<StoreErrorCode, string>> = {
132
132
  // out (review A, NIT-2). It fits the 200-character reason cap with room.
133
133
  STORE_PRE_ROWS:
134
134
  "this store keeps its memories in files, which this build does not read — it was written before the floor changed; the build that reads it is the tag floor/v5-last",
135
+ MIGRATION_SNAPSHOT_FAILED: "upgrade not run — the copy taken first failed; the store is unchanged",
135
136
  SQLITE_UNAVAILABLE: "this runtime has no SQLite binding",
136
137
  DATA_DIR_FORBIDDEN: "the configured data dir is one this build refuses to open",
137
138
  STORE_UNINITIALIZED: "there is no store here yet, or it is a schema behind",
@@ -167,6 +168,16 @@ function preRowsReason(err: unknown): string | null {
167
168
  );
168
169
  }
169
170
 
171
+ /** The failed pre-migration copy, with what stopped it — doctor opens as an
172
+ * observer and never migrates, so this is the one place the why is said. */
173
+ function migrationReason(err: unknown): string | null {
174
+ if (!isStoreError(err, "MIGRATION_SNAPSHOT_FAILED")) return null;
175
+ const why = err.detail["reason"];
176
+ const base = PLAIN_WORDS.MIGRATION_SNAPSHOT_FAILED ?? OPEN_FAILED_WORDS;
177
+ // The reason first, so the 200-character cap trims the preamble, not the why.
178
+ return typeof why === "string" && why.length > 0 ? `${why} (${base})` : base;
179
+ }
180
+
170
181
  export function describeFault(err: unknown): StandDownFault {
171
182
  // TOTAL, and the reason is not theoretical politeness: this runs inside the
172
183
  // handler that exists so a hook never fails the host, and everything below
@@ -190,7 +201,7 @@ function readFault(err: unknown): StandDownFault {
190
201
  if (isStoreError(err)) {
191
202
  return {
192
203
  code: err.code,
193
- reason: preRowsReason(err) ?? PLAIN_WORDS[err.code] ?? OPEN_FAILED_WORDS,
204
+ reason: preRowsReason(err) ?? migrationReason(err) ?? PLAIN_WORDS[err.code] ?? OPEN_FAILED_WORDS,
194
205
  kind,
195
206
  };
196
207
  }