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
@@ -28,12 +28,15 @@
28
28
  */
29
29
 
30
30
  import type { Kind } from "../types.js";
31
+ import { todayIn } from "../time.js";
31
32
  import { TUNABLES as PHYSICS, symmetryCheck } from "../physics/index.js";
32
33
  import { runBriefing } from "./briefing.js";
33
34
  import type { RenderFn } from "./briefing.js";
34
35
  import { runConsolidate } from "./consolidate.js";
35
36
  import { runDecay } from "./decay.js";
36
37
  import { runDedup } from "./dedup.js";
38
+ import { runFade } from "./fade.js";
39
+ import type { FadeFn } from "./fade.js";
37
40
  import type { DedupCandidateSource } from "./dedup.js";
38
41
  import { runLogSweep } from "./log.js";
39
42
  import { advanceMarker, budgetFor, cadenceFor, markerDue, readMarker } from "./markers.js";
@@ -75,6 +78,12 @@ export interface SleepOptions {
75
78
  * hidden in a lambda between a host's real cliff and the render (scar §2.18).
76
79
  */
77
80
  budgetBytes?: number;
81
+ /**
82
+ * `schemas/`' fade sweep, injected like `render` (this module does not import
83
+ * `schemas/`). Absent ⇒ the fade phase reports `no-fade-fn`, and entity cards
84
+ * stay where they are: the floor prune does not take them either.
85
+ */
86
+ fade?: FadeFn;
78
87
  /** Injected ranking cache. Absent ⇒ the box-3 SQLite one, opened lazily. */
79
88
  strengthCache?: StrengthCache;
80
89
  /** Extra dedup candidates (embeddings). Isolated: a throw degrades to lexical. */
@@ -91,9 +100,14 @@ export interface SleepOptions {
91
100
 
92
101
  const EVENT_RING = 500;
93
102
 
94
- /** UTC calendar date. The lived-day mapping is the store's, not this module's. */
103
+ /**
104
+ * Today's calendar date in the machine's zone — the fallback when a caller
105
+ * hands the cycle no date. UTC until 2026-09-25, local since (docs/time.md): the
106
+ * hooks' `at` moved the same day, and the two must stay one calendar. The
107
+ * lived-day mapping is the store's, not this module's.
108
+ */
95
109
  export function todayDate(): string {
96
- return new Date().toISOString().slice(0, 10);
110
+ return todayIn();
97
111
  }
98
112
 
99
113
  export function runCycle(opts: SleepOptions): CycleReport {
@@ -128,6 +142,7 @@ export function runCycle(opts: SleepOptions): CycleReport {
128
142
  const promoted: PromotionRecord[] = [];
129
143
  const pruned: PrunedRecord[] = [];
130
144
  const merged: MergeRecord[] = [];
145
+ const faded: string[] = [];
131
146
  const bandTransitions: BandTransition[] = [];
132
147
 
133
148
  // The ranking cache is opened LAZILY by the decay phase, and never at all
@@ -284,6 +299,16 @@ export function runCycle(opts: SleepOptions): CycleReport {
284
299
  },
285
300
  );
286
301
 
302
+ // ── phase 4b: the entity fade (archival, `schemas/`' gentle verdict) ──
303
+ runPhase(
304
+ "fade",
305
+ (ctx) => runFade(ctx, opts.fade, date),
306
+ (r) => {
307
+ faded.push(...r.faded);
308
+ },
309
+ () => (opts.fade === undefined ? "no-fade-fn" : null),
310
+ );
311
+
287
312
  // ── phase 5: dedup ────────────────────────────────────────────────────
288
313
  runPhase(
289
314
  "dedup",
@@ -347,9 +372,10 @@ export function runCycle(opts: SleepOptions): CycleReport {
347
372
  promoted,
348
373
  pruned,
349
374
  merged,
375
+ faded,
350
376
  bandTransitions,
351
377
  symmetry,
352
- census: census(store, day, pruned, merged),
378
+ census: census(store, day, pruned, merged, faded),
353
379
  events,
354
380
  };
355
381
  emit("sleep.cycle.done", undefined, {
@@ -358,6 +384,7 @@ export function runCycle(opts: SleepOptions): CycleReport {
358
384
  promoted: promoted.length,
359
385
  pruned: pruned.length,
360
386
  merged: merged.length,
387
+ faded: faded.length,
361
388
  bandUp: bandTransitions.filter((t) => t.direction === "up").length,
362
389
  bandDown: bandTransitions.filter((t) => t.direction === "down").length,
363
390
  failed: reports.filter((p) => p.status === "failed").length,
@@ -560,6 +587,7 @@ export function census(
560
587
  day: number,
561
588
  pruned: readonly PrunedRecord[],
562
589
  merged: readonly MergeRecord[],
590
+ faded: readonly string[] = [],
563
591
  ): Record<Kind, KindCensus> {
564
592
  const kinds = Object.keys(PHYSICS.KINDS) as Kind[];
565
593
  const created = new Map<Kind, number>();
@@ -580,6 +608,13 @@ export function census(
580
608
  if (row === undefined) continue;
581
609
  exited.set(row.kind, (exited.get(row.kind) ?? 0) + 1);
582
610
  }
611
+ // A faded card is an exit for its kind — the prune no longer takes cards, so
612
+ // without this `person`, `place` and `entity` would read as never exiting.
613
+ for (const id of faded) {
614
+ const row = store.row(id);
615
+ if (row === undefined) continue;
616
+ exited.set(row.kind, (exited.get(row.kind) ?? 0) + 1);
617
+ }
583
618
  const out = {} as Record<Kind, KindCensus>;
584
619
  for (const kind of kinds) {
585
620
  out[kind] = { created: created.get(kind) ?? 0, exited: exited.get(kind) ?? 0 };
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The entity fade — where a card nobody has mentioned in a long while is
3
+ * ARCHIVED. A state, not a deletion: the card keeps its id, stays resolvable,
4
+ * and stops surfacing.
5
+ *
6
+ * `schemas/` owns the verdict (`Schemas#fadeSweep`: physics' prune verdict, the
7
+ * attached-elements blocker, and gentle lived + calendar floors, slower for
8
+ * people). `sleep/` owns only the cadence (schemas INTERFACE-GAPS §6). This
9
+ * module does not import `schemas/`: the sweep is handed in as a `FadeFn`, the
10
+ * same seam the briefing's `RenderFn` uses, and the composition root wires it.
11
+ *
12
+ * Entity cards leave ONLY through here. The floor prune skips them
13
+ * (`types.ts#isEntityCard`) — before this phase existed, the prune was the
14
+ * thing archiving them, at physics' 90 lived days and blind to the beliefs
15
+ * still attached (NOTES §17).
16
+ *
17
+ * A missing sweep is `did-not-run` with reason `no-fade-fn`, not a failure and
18
+ * not "ran and found nothing".
19
+ */
20
+
21
+ import type { PhaseCtx, PhaseOutcome } from "./types.js";
22
+ import { countSkip, emptyOutcome } from "./types.js";
23
+
24
+ export interface FadeInput {
25
+ readonly day: number;
26
+ /** The cycle's calendar date — the calendar floors are counted to it. */
27
+ readonly date: string;
28
+ /** False under observer: compute every verdict, write nothing. */
29
+ readonly apply: boolean;
30
+ /** Cards to examine at most. */
31
+ readonly budget: number;
32
+ }
33
+
34
+ export interface FadeSweepOutcome {
35
+ readonly examined: number;
36
+ /** Faded (or, when `apply` is false, would have). Ids only. */
37
+ readonly faded: readonly string[];
38
+ /** Every blocker, counted, across the cards that stayed. */
39
+ readonly blocked: Readonly<Record<string, number>>;
40
+ /** Calendar anchors written this sweep. */
41
+ readonly anchored: number;
42
+ readonly skippedForLimit: number;
43
+ }
44
+
45
+ export type FadeFn = (input: FadeInput) => FadeSweepOutcome;
46
+
47
+ export interface FadeResult extends PhaseOutcome {
48
+ readonly faded: readonly string[];
49
+ readonly anchored: number;
50
+ }
51
+
52
+ export function runFade(ctx: PhaseCtx, fade: FadeFn | undefined, date: string): FadeResult {
53
+ const out = emptyOutcome();
54
+ if (fade === undefined) {
55
+ out.skipped["no-fade-fn"] = 1;
56
+ return { ...out, faded: [], anchored: 0 };
57
+ }
58
+ const r = fade({ day: ctx.day, date, apply: ctx.apply, budget: ctx.budget });
59
+ out.examined = r.examined;
60
+ out.changed = r.faded.length;
61
+ out.budgetExhausted = r.skippedForLimit > 0;
62
+ out.skippedForBudget = r.skippedForLimit;
63
+ // Mirrored under one namespace, like prune's `blocked:` — most of these are
64
+ // "not yet" (the floors), not refusals.
65
+ for (const [reason, n] of Object.entries(r.blocked)) countSkip(out, `blocked:${reason}`, n);
66
+ for (const id of r.faded) {
67
+ ctx.event("sleep.faded", id, { day: ctx.day, applied: ctx.apply });
68
+ }
69
+ ctx.event("sleep.fade.sweep", undefined, {
70
+ day: ctx.day,
71
+ examined: r.examined,
72
+ faded: r.faded.length,
73
+ anchored: r.anchored,
74
+ });
75
+ return { ...out, faded: r.faded, anchored: r.anchored };
76
+ }
@@ -85,13 +85,16 @@ export {
85
85
  } from "./dedup.js";
86
86
  export type { DedupCandidateInput, DedupCandidateSource, DedupPair, DedupResult } from "./dedup.js";
87
87
 
88
+ export { runFade } from "./fade.js";
89
+ export type { FadeFn, FadeInput, FadeResult, FadeSweepOutcome } from "./fade.js";
90
+
88
91
  export { runBriefing } from "./briefing.js";
89
92
  export type { BriefingContext, BriefingOutcome, BriefingResult, RenderFn } from "./briefing.js";
90
93
 
91
94
  export { LOG_SWEEP_EVENT, LOG_SWEEP_SKIPS, runLogSweep } from "./log.js";
92
95
  export type { LogSweepResult, LogSweepSkip } from "./log.js";
93
96
 
94
- export { BAND_TRANSITION_EVENT, BAND_TRANSITION_FIELDS, CycleKilled, PHASES, attachCyclePartial, countSkip, cyclePartial, emptyOutcome, isJournal, isSchemaRow, phaseReport } from "./types.js";
97
+ export { BAND_TRANSITION_EVENT, BAND_TRANSITION_FIELDS, CycleKilled, PHASES, attachCyclePartial, countSkip, cyclePartial, emptyOutcome, isEntityCard, isJournal, isSchemaRow, phaseReport } from "./types.js";
95
98
  export type {
96
99
  CyclePartial,
97
100
  CycleReport,
@@ -27,7 +27,7 @@ import type { MemoryPhysics, PruneReason } from "../physics/index.js";
27
27
  import { rowToPhysics } from "../store/operational.js";
28
28
  import { PRUNE_ARCHIVE_REASON, PRUNE_RECORD_PREFIX } from "./tunables.js";
29
29
  import type { MemoryRow, PhaseCtx, PhaseOutcome, PrunedRecord } from "./types.js";
30
- import { countSkip, emptyOutcome, isJournal } from "./types.js";
30
+ import { countSkip, emptyOutcome, isEntityCard, isJournal } from "./types.js";
31
31
 
32
32
  export interface PruneResult extends PhaseOutcome {
33
33
  readonly pruned: readonly PrunedRecord[];
@@ -69,6 +69,7 @@ export function runPrune(ctx: PhaseCtx): PruneResult {
69
69
  out.skipped["archived"] = 0;
70
70
  out.skipped["removed"] = 0;
71
71
  out.skipped["journal"] = 0;
72
+ out.skipped["entity-card"] = 0;
72
73
  const blocked: Record<string, number> = {};
73
74
  const pruned: PrunedRecord[] = [];
74
75
  const recordFailures: { id: string; error: string }[] = [];
@@ -105,6 +106,12 @@ export function runPrune(ctx: PhaseCtx): PruneResult {
105
106
  countSkip(out, "journal");
106
107
  continue;
107
108
  }
109
+ // An entity card fades in the next phase, under `schemas/`' gentler verdict
110
+ // (`types.ts#isEntityCard`, NOTES §17) — not here, at physics' floor alone.
111
+ if (isEntityCard(row)) {
112
+ countSkip(out, "entity-card");
113
+ continue;
114
+ }
108
115
  out.examined += 1;
109
116
 
110
117
  const p = rowToPhysics(row);
@@ -29,6 +29,8 @@ export const TUNABLES = {
29
29
  decay: 20_000,
30
30
  consolidate: 5_000,
31
31
  prune: 1_000,
32
+ /** Entity cards examined per fade sweep. Sized so a personal store's cards all fit in one pass. */
33
+ fade: 5_000,
32
34
  dedup: 1_000,
33
35
  versions: 1,
34
36
  briefing: 1,
@@ -52,6 +54,9 @@ export const TUNABLES = {
52
54
  decay: 1,
53
55
  consolidate: 3,
54
56
  prune: 1,
57
+ /** Every third lived day: the fade floors are months long, so a card that
58
+ * fades a day or two late costs nothing, and the sweep reads every card. */
59
+ fade: 3,
55
60
  dedup: 1,
56
61
  versions: 1,
57
62
  briefing: 1,
@@ -135,6 +135,8 @@ export interface SleepStore {
135
135
  * the strength cache is materialized.
136
136
  * - revision-dependent work (`prune`, `dedup`, `versions`) runs after
137
137
  * `consolidate`, so it sees this boundary's own supersedes and promotions.
138
+ * - `fade` runs right after `prune`, so a card whose last beliefs were
139
+ * pruned tonight is free to fade tonight (its floors permitting).
138
140
  * - `briefing` is the cycle's final CONTENT write. `log` runs after it and
139
141
  * writes no content: it deletes telemetry rows past the retention window
140
142
  * (§5 G16), and it is last so "what the cycle forgot" and "what the log
@@ -146,6 +148,7 @@ export const PHASES = [
146
148
  "decay",
147
149
  "consolidate",
148
150
  "prune",
151
+ "fade",
149
152
  "dedup",
150
153
  "versions",
151
154
  "briefing",
@@ -164,6 +167,7 @@ export type PhaseReason =
164
167
  | "not-due-this-cadence"
165
168
  | "observer-report"
166
169
  | "no-render-fn"
170
+ | "no-fade-fn"
167
171
  | "no-durable-event-log"
168
172
  | "failed";
169
173
 
@@ -412,6 +416,8 @@ export interface CycleReport {
412
416
  readonly promoted: readonly PromotionRecord[];
413
417
  readonly pruned: readonly PrunedRecord[];
414
418
  readonly merged: readonly MergeRecord[];
419
+ /** Entity cards the fade phase archived this cycle (or, under observer, would have). Ids only. */
420
+ readonly faded: readonly string[];
415
421
  /** Band crossings THIS cycle, by direction (guarantee 12's input). */
416
422
  readonly bandTransitions: readonly BandTransition[];
417
423
  /**
@@ -530,6 +536,24 @@ export function isSchemaRow(row: MemoryRow): boolean {
530
536
  return row.type === "schema";
531
537
  }
532
538
 
539
+ /**
540
+ * AN ENTITY CARD LEAVES THROUGH THE FADE PHASE, NOT THE FLOOR PRUNE — read by
541
+ * `prune.ts`. The card's own row is a stub at salience zero, so physics alone
542
+ * lets it go after its dwell; `schemas/` adds what physics cannot see (beliefs
543
+ * still attached, the calendar, slower people) and `fade.ts` runs it. Beliefs
544
+ * and current-state rows stay ordinary prune candidates. Read structurally —
545
+ * `meta.role` — rather than by importing `schemas/` (NOTES §17).
546
+ */
547
+ export function isEntityCard(row: MemoryRow): boolean {
548
+ if (row.type !== "schema") return false;
549
+ try {
550
+ const meta = JSON.parse(row.meta) as { role?: unknown } | null;
551
+ return meta !== null && typeof meta === "object" && meta.role === "entity";
552
+ } catch {
553
+ return false;
554
+ }
555
+ }
556
+
533
557
  export function countSkip(out: PhaseOutcome, reason: string, n = 1): void {
534
558
  out.skipped[reason] = (out.skipped[reason] ?? 0) + n;
535
559
  }
@@ -331,12 +331,14 @@ store property is the `VACUUM INTO`, and that is G19. The code's numbering wins.
331
331
  database**. FILENAMES are the evidence deliberately: reading the schema version would
332
332
  mean opening a WAL store whose `-wal` a close could checkpoint away, moving the bytes
333
333
  the refusal exists to leave alone. All three names, because a store whose database was
334
- moved by hand still holds every one of its words in files. `ADDED_COLUMNS` is empty and
335
- may never name a v6 column, which is the second lock: `openOperational` migrates
336
- anything below `SCHEMA_VERSION`, and `body` added that way would be NULL on every row
337
- while the words sat in files, stamping the store v6 and unreadable by the build that can
338
- read it. `OBSERVER_READ_FLOOR` is `SCHEMA_VERSION`: there is no floor below v6, because
339
- a v6 instrument on a v5 store would report an empty store rather than an unreadable one.
334
+ moved by hand still holds every one of its words in files. `ADDED_COLUMNS` may never
335
+ name a v6 column (it was empty at v6 and holds v7's eleven since 2026-09-25), which is
336
+ the second lock: `openOperational` migrates anything below `SCHEMA_VERSION`, and `body`
337
+ added that way would be NULL on every row while the words sat in files, stamping the
338
+ store current and unreadable by the build that can read it. `OBSERVER_READ_FLOOR` is
339
+ `SCHEMA_VERSION`: there is no floor below the current version, because every read names
340
+ the current columns and an instrument on an older store would report an empty or broken
341
+ store rather than one waiting for its upgrade.
340
342
  There is no migration and there is not going to be one (owner ruling 6, 2026-09-18: the
341
343
  cut-over carries nothing). `test/store-portable.test.ts` builds a real v5 store by hand
342
344
  and proves the directory is byte-identical after a refused writer open, a refused
@@ -380,6 +382,33 @@ store property is the `VACUUM INTO`, and that is G19. The code's numbering wins.
380
382
  wiped database (owner ruling 3, 2026-09-18). Rotation, which DELETES, lives in an
381
383
  adapter and never here (G2) — and it never deletes a folder holding pre-rows markers, so
382
384
  the copies of the parked store survive cut-over.
385
+ 20. **[M] A copy before a schema migration.** A writer open that finds box 2 on an older
386
+ schema copies the database (`VACUUM INTO`, G19) before it changes anything, under the
387
+ same write lock that decides who migrates. This is the one write the store makes
388
+ outside its own directory: into the snapshots directory beside it (`<base>/snapshots`),
389
+ or the one named by `StoreOptions.snapshotsDir`. A store outside `<base>/store` with
390
+ none named does not migrate. If the copy cannot be made, nothing migrates and the open
391
+ throws `MIGRATION_SNAPSHOT_FAILED`, whose `remedy` says why; the store stays on its old
392
+ version. A later open reuses a copy already taken for the same upgrade that day, or one
393
+ the live store has not been written since. Observers never migrate and never copy.
394
+ `NOTES.md` (2026-09-24) has the rollback steps.
395
+ 21. **[M] Two kinds of time, one conversion module** (docs/time.md, 2026-09-25). A
396
+ MOMENT is UTC milliseconds from the injected clock (`store.now()`): `created_at` /
397
+ `updated_at` on `memories`, `edges` and `prospective`, a version's `created_at` and
398
+ `archived_at`, an event's `at`. A CALENDAR DATE a person said is text at its stated
399
+ precision — `happened_on`, and `event_date` (day, month, year or `a..b` range, refused
400
+ as `EVENT_DATE_INVALID` when `core/time.ts` cannot read it) — and is never turned into
401
+ a moment. A person's day (`today()`, a new row's `learned_on`, the day the store began)
402
+ is the local date of a moment in `zone()`: `StoreOptions.timeZone` when it names a real
403
+ zone, else the machine's current zone, resolved per call. Rows written before
404
+ 2026-09-25 keep the UTC `learned_on` they were given. `datedMemories(from, to)` answers
405
+ which live rows carry an `event_date` overlapping a window, from an index.
406
+ 22. **[M] Feelings are rows beside a memory, spelled on the wheel** (schema v7). A
407
+ `feelings` row names `whose`, one of six cores, a wheel emotion or `other` with the
408
+ word kept, a strength recorded once, and optionally the feeling on the same memory it
409
+ sits beneath. A write is all-or-none and refused by name (`FEELING_INVALID`) rather
410
+ than guessed; an unknown emotion is kept as `other`, never mapped. The owner's
411
+ removal deletes them with the memory. They move no physics.
383
412
 
384
413
  ## 6. Scars honored
385
414
 
@@ -402,7 +431,7 @@ Each line: the scar, what carries it on this floor, and where it is pinned.
402
431
  | **I22** the copied-store bug | G15 — criterion kept, mechanism deleted | `test/store-portable.test.ts` "(a) `cp -R` the store, DESTROY the source outright, and the copy still reads its own words"; "(b) an owner removal run in the COPY leaves the SOURCE byte-identical"; "(d) a `backup` snapshot opens standalone and HOLDS THE WORDS after the source is gone" |
403
432
  | **I38 / I39** "database is locked" | G18 | `test/store.test.ts` "busy_timeout is set FIRST, before every other pragma (I39)"; "a second handle WAITS for a held write lock instead of failing instantly"; "a WRITER converts the file to WAL; an INSTRUMENT opening a DELETE store leaves it alone" |
404
433
  | **the stage→commit→rename crash window** (`NOTES.md` §5, deleted): a crash never leaves a row whose words are missing | G5, G6 — structurally true: the words commit with the row | `test/store.test.ts` "SIGKILL mid-write leaves the store readable, every row's words intact" |
405
- | **the floor's own hazard**: migrate-at-open would have destroyed the pre-rows store | G16 | `test/store-portable.test.ts` "a WRITER open throws STORE_PRE_ROWS and the directory is byte-identical afterwards"; "an OBSERVER open, and a whole session, meet the same refusal and write nothing"; "ADDED_COLUMNS is EMPTY at v6, and may never name a column the floor introduced" |
434
+ | **the floor's own hazard**: migrate-at-open would have destroyed the pre-rows store | G16 | `test/store-portable.test.ts` "a WRITER open throws STORE_PRE_ROWS and the directory is byte-identical afterwards"; "an OBSERVER open, and a whole session, meet the same refusal and write nothing"; "ADDED_COLUMNS may never name a column the floor introduced" |
406
435
 
407
436
  **Scars that no longer apply**, named so nobody re-ports them: temp-file naming (§16 G4's
408
437
  "a crash-leaked stage must not load as a duplicate" — there is no stage), the
@@ -1383,3 +1383,200 @@ close that is no longer always a fold; not built.
1383
1383
  the adapter maps identically, and it typechecks; nobody has run it under Node.
1384
1384
  `Store.close()` returns early on a second call, so neither handle is closed twice —
1385
1385
  `node:sqlite` throws on a double close where `bun:sqlite` shrugs.
1386
+
1387
+ ## 2026-09-24 — a copy before a schema migration
1388
+
1389
+ A writer open that finds box 2 on an older schema now copies the database before it
1390
+ changes anything (`pre-migration.ts`, called from `openOperational`):
1391
+
1392
+ - **One process copies and migrates.** The migration transaction is `BEGIN IMMEDIATE`;
1393
+ the version is read again under that lock, and a process that finds it current does
1394
+ neither. The test holds the lock while three child processes queue on it.
1395
+ - **The copy is `VACUUM INTO` on its own connection**, taken while the migrating
1396
+ connection holds the write lock and has written nothing, so it is the last committed
1397
+ state before the migration. Database only: the migration touches nothing else in the
1398
+ store.
1399
+ - **Where:** the snapshots directory the daily copies use (`<base>/snapshots`, or
1400
+ `snapshotsDir` / the host's `snapshots.dir` — the hook, the worker, the MCP server and
1401
+ the console's `openCounterpart` all pass it), named
1402
+ `<instant>-pre-migration-v<from>-to-v<to>` by the wall clock (an injected or replayed
1403
+ clock once named a copy that collided with its own earlier one). A store outside
1404
+ `<base>/store` with no directory named refuses to migrate rather than go without a copy.
1405
+ - **One copy per upgrade, not per attempt.** A migration that fails AFTER its copy (a
1406
+ commit that loses its lock, a bad trigger) would otherwise take a new full copy at every
1407
+ open. So an open reuses a copy already there for the same from→to when it was taken
1408
+ today (UTC), or when neither the live file nor its `-wal` has been written since the
1409
+ copy's instant. The cost: rows an older build writes between the copy and the upgrade
1410
+ that finally lands are not in the copy.
1411
+ - **If the copy fails, nothing migrates**: the transaction rolls back and the open
1412
+ throws `MIGRATION_SNAPSHOT_FAILED`, whose `remedy` says why; the store stays on the
1413
+ old version and the build that wrote it still opens it. An abandoned `.partial-…`
1414
+ is left for the daily sweep (the store deletes nothing).
1415
+ - **Observers never get here** — they refuse an old store `STORE_UNINITIALIZED` first.
1416
+ So doctor asks separately: it reads the stamp, and when the store is behind it
1417
+ dry-runs the copy's preconditions (the destination passes the same checks, and a probe
1418
+ directory can be made there and removed) and grades Store open amber (the next session
1419
+ upgrades it) or red (every hook will refuse), instead of reading green or failing.
1420
+ - **Box 3 is not copied.** It is declared rebuildable, is outside the backup set, and
1421
+ its vectors are recomputed for free by the static tier.
1422
+ - **Rotation** keeps these apart from `keep`: one is removed only when it is at least
1423
+ 14 days old (`PRE_MIGRATION_KEEP_DAYS`) and `keep` newer daily copies exist. Doctor's
1424
+ Snapshot line names the newest.
1425
+
1426
+ **What it costs to hold the lock.** The copy runs while this connection holds the write
1427
+ lock, so every other opener waits on it. Measured in review: ~1.3 s for a 200 MB database
1428
+ with a 418 MB `-wal`. Past roughly 1 GB the copy can outlast `BUSY_TIMEOUT_MS` (5 s); the
1429
+ openers that lose then get "database is locked", which the hooks stand down on as
1430
+ transient, and the next turn opens the upgraded store. No code change for that.
1431
+
1432
+ The store deletes nothing, so a copy that fails (a full disk) leaves its `.partial-…`
1433
+ directory, possibly empty, for the daily sweep to remove once it is stale.
1434
+
1435
+ **To roll a migration back:** stop every session, move the store's
1436
+ `counterparts.sqlite` (and its `-wal`/`-shm`) aside, and move `cache/` aside too — it
1437
+ rebuilds, and a cache the newer build stamped would make the old MCP server refuse every
1438
+ tool. Copy the pre-migration copy's `counterparts.sqlite` into the store directory and run
1439
+ the build that matches its `v<from>` (the newer build would migrate it again). Rows
1440
+ written since the upgrade are lost; they are not in the copy.
1441
+
1442
+ ## 2026-09-25 — schema v7: moments, the model, a reminder date, and the person's day
1443
+
1444
+ docs/time.md (agreed with the owner that day) is the plan; this is what the store did
1445
+ about it. `core/time.ts` is the one conversion module; the store imports it and converts
1446
+ nothing by hand.
1447
+
1448
+ **The migration.** The first additive one since the copy seam (#214) shipped: eleven
1449
+ nullable columns through `ADDED_COLUMNS`, one partial index after them
1450
+ (`DDL_AFTER_COLUMNS`, because on a v6 file the column does not exist yet while `DDL`
1451
+ runs). `OBSERVER_READ_FLOOR` moved to 7 with it, so an instrument (doctor, the
1452
+ dashboard, `status`) meets a v6 store as `STORE_UNINITIALIZED` until the next hook — a
1453
+ writer — takes the copy and migrates; doctor already grades that amber ("the next session
1454
+ upgrades it"). Measured on a store seeded by the 0.3.1 checkout (b66a736): doctor amber
1455
+ before, one `…-pre-migration-v6-to-v7` folder after the first SessionStart, 172 memories /
1456
+ 2 versions / 252 edges / 5 prospective rows and 153 distinct content hashes both sides,
1457
+ doctor green after, and the 0.3.1 build refusing it `SCHEMA_AHEAD` — at open, and in an
1458
+ MCP server that was already running (`schema-ahead`, "Run /mcp and Reconnect").
1459
+
1460
+ **Table by table.**
1461
+
1462
+ | table | v7 columns | why |
1463
+ |---|---|---|
1464
+ | `memories` | `created_at`, `updated_at`, `model`, `event_date` | the records. `updated_at` moves when the words or the state change — `revise`, `supersede`, `archive`, an owner's unarchive — and NOT on physics bookkeeping (`updatePhysics`, `reinforce`, `setBand`): decay touches every row nightly, and an `updated_at` that meant "last sleep" would say nothing. |
1465
+ | `versions` | `created_at`, `model`, `event_date` | a version is written once and never updated, and `archived_at` is already the moment it stopped being current; `created_at` is when its WORDS were written (the head's `updated_at`, else `created_at`, at archive), so a version has both ends. `model` and `event_date` travel with the words, like `learned_on` / `happened_on` already did. No `updated_at`: nothing updates a version but the removal chase, which blanks it. |
1466
+ | `edges` | `created_at`, `updated_at` | first linked, last re-weighted. `link` / `linkMany` became an UPSERT: `INSERT OR REPLACE` deletes the row first and would reset `created_at` at every re-weighting. |
1467
+ | `prospective` | `created_at`, `updated_at` | window first recorded, last changed state; UPSERT for the same reason. |
1468
+ | `feelings` (new) | `created_at`, `updated_at` NOT NULL | a new table, so no row predates its moments; see below. |
1469
+ | `events` | none | `at` IS its moment, and the log is append-only. |
1470
+ | `removal_record`, `removal_tombstone` | none | append-only, each with its own `at`. |
1471
+ | `gate_session` | none | per-session working state, pruned by lived day; not a record anyone reads back later. |
1472
+ | `meta` | none | key/value settings, not records. |
1473
+ | box 3 (the cache) | none | declared rebuildable. |
1474
+
1475
+ **Backfill: none.** Old rows carry NULL moments. Nothing durable holds the moment a v6
1476
+ row was written — `store.put` goes to the in-process ring, not the event log — and
1477
+ `learned_on` is a date, not a moment; the owner ruled old dates stay as they are
1478
+ (docs/time.md rule 6). NULL reads "not recorded", never a made-up time.
1479
+
1480
+ **`model`.** The model id that wrote the current words, screened by `isModelId` (moved
1481
+ from `self/episodes.ts` to `core/types.ts` so the store can use it; `self/` re-exports
1482
+ it). The relay is the chapters' (self NOTES §24): the transcript's last assistant model →
1483
+ the session registry record → the MCP server's `sessionModel()` → `note`, `session_end`
1484
+ entries, `chapter`, and `self_page`. A server with no bound session (a `note` before any
1485
+ tool named one) records NULL, as does the sweep, the owner's console and anything the host
1486
+ did not name. On `revise`, new words with no model named set it NULL (they are no longer
1487
+ the last model's); a revise that leaves the body alone keeps it. Each version keeps the
1488
+ model that wrote IT.
1489
+
1490
+ **The reminder date: a new `event_date` column, not a widened `happened_on`.**
1491
+ `happened_on` is already written with PAST dates that are not reminders — `schemas/`
1492
+ stamps every belief's and current-state's `statedOn` into it, and episodes pass one — so
1493
+ an index over it would hand prospective every schema row stated this week as an
1494
+ "arrival". A reminder is a different fact from when something happened, and a memory can
1495
+ carry both ("on the 20th we agreed taxes are due Oct 15"). `event_date` holds a day, a
1496
+ month, a year or a range, is refused when unreadable (`EVENT_DATE_INVALID`), travels in
1497
+ versions, is cleared by `revise({ eventDate: null })`, and is blanked by the removal chase
1498
+ along with the moments and the model. `datedMemories(from, to)` bounds the SQL loosely
1499
+ (`event_date <= to || '~'`, which the partial index answers) and decides overlap in
1500
+ `time.ts`: a month `2026-10` sorts before `2026-10-01` as text and a range's text runs
1501
+ past its first day, so a `BETWEEN` would miss both. prospective's `meta.eventDate`
1502
+ convention is still read by `contentDates`; nothing in `src/` writes it, and
1503
+ `datedMemories` does not look at it. Nothing writes `event_date` yet either — that door
1504
+ (and firing off it) is PR B.
1505
+
1506
+ **The person's day.** `today()`, a new row's default `learned_on`, and `store.created`
1507
+ are the local date of `now()` in `zone()` — `StoreOptions.timeZone` (the host config's
1508
+ `timeZone`, threaded through `Counterpart.open`) or the machine's current zone, resolved
1509
+ per call. `dateOf` / `today` (the module functions) stay UTC under their old names, for
1510
+ the callers that mean UTC on purpose: tools, the dashboard's `todayUtc`, reading pre-v7
1511
+ rows, and the file names below. The hooks' `at` moved with it, and that date is also what
1512
+ the boundary hands `advanceClock`: west of UTC, on the evening of the upgrade (or after
1513
+ flying west), a session can present a local date one day BEHIND `lastActiveDate`. The
1514
+ store refuses it (`CLOCK_BACKWARDS`), the cycle names it (`sleep.clock.failed`) and stays
1515
+ on the lived day it already believed, and the next local date moves it on —
1516
+ `test/local-day.test.ts` "the lived clock across the change". No special case was added.
1517
+
1518
+ **What stayed UTC, on purpose** (file names and legacy readers, not a person's day):
1519
+ snapshot folder names and their retention cutoffs (`adapters/snapshots.ts`), the
1520
+ pre-migration copy's "taken today" check (its folder name begins with a UTC instant),
1521
+ the parked-store suffix and plan date in `start-fresh` / `uninstall`, `repair-dates`
1522
+ (it repairs pre-v7 rows, whose dates were UTC), and ISO instants in log lines and file
1523
+ names. Changing a folder name's calendar is a question for the owner, not a fix.
1524
+
1525
+ **A SQLite quirk found building the v6 fixture.** `ALTER TABLE … DROP COLUMN` fails with
1526
+ "incomplete input" when the column being dropped is the LAST one and `--` comment lines
1527
+ precede it in the stored `CREATE TABLE` text. The v7 columns on `memories` therefore sit
1528
+ with no SQL comment among them; their explanation is a JS comment above the DDL.
1529
+
1530
+ ### The `feelings` table, in the same v7 migration (owner-approved 2026-09-25)
1531
+
1532
+ One row per feeling on a memory: `whose` (`owner` | `self` today — TEXT, so a person's
1533
+ entity id can join later without a migration), `core` (one of six), `emotion` (a key on
1534
+ the wheel, `core/feelings-wheel.ts`, or `other` with the word in `other_word`),
1535
+ `strength` 0..1 as recorded and never rewritten, `beneath_id` (another feeling on the
1536
+ SAME memory it sits on top of), `carried_by` (≤280 chars: what in the moment carried
1537
+ it), `model`, and the two moments. Indexed on `memory_id`, `(whose, core)`,
1538
+ `(whose, emotion)`. `CREATE TABLE IF NOT EXISTS` in `DDL`, so a v6 store gains it in the
1539
+ migration transaction and a fresh store has it from birth.
1540
+
1541
+ - **`addFeelings(memoryId, inputs, { model })`** is all-or-none. `checkFeelings` is pure
1542
+ and exported, so a door can run it BEFORE minting the memory and never leave one with
1543
+ its feelings dropped. Refused (`FEELING_INVALID`, `{ index, reason }`): unknown
1544
+ `whose` or `core`, strength out of range, an emotion the wheel files under ANOTHER
1545
+ core, a `beneath` that is off this memory or loops. An emotion simply not on the wheel
1546
+ is kept as `other`, and the result's `notices` carry the nearest keys under that core
1547
+ (edit distance) so the caller can rewrite. `beneath` may be an existing id or another
1548
+ input's index; rows are inserted first and linked second, so order does not matter.
1549
+ - **`feelingsFor(id)`**, and **`feelingCounts({ by, whose?, from?, to? })`** — counts by
1550
+ `(whose, core|emotion)`, with the date range read as the person's days in `zone()`.
1551
+ The filter runs in TypeScript over the (whose-indexed) rows; fine at today's sizes, and
1552
+ the obvious place to push into SQL once there are many.
1553
+ - **Removal** deletes a memory's feelings in one statement (they carry words), beside its
1554
+ edges and windows. The tombstone gained no `feelings` count — that would be a column on
1555
+ `removal_tombstone`, and nothing needs it yet.
1556
+ - **Nothing reads them.** Salience, decay and recall are untouched; the `emotional`
1557
+ dimension and `meta.feeling` are exactly as before. `Counterpart#addFeelings` runs
1558
+ `carried_by` and an `other` word through `redactSecrets` first.
1559
+
1560
+ ### What the adversarial review of #231 changed (2026-09-25)
1561
+
1562
+ The review is `docs/adversarial-review-v7-2026-09-25.md`.
1563
+
1564
+ - **S1, the lived clock on the upgrade evening.** The review reproduced doctor going RED
1565
+ on Sleep from 6 pm to midnight west of UTC. The old build's last boundary had stamped
1566
+ UTC's tomorrow into `lastActiveDate`, and the first local date after the upgrade was
1567
+ refused with `CLOCK_BACKWARDS`. There are two fixes, and either would do it alone:
1568
+ - The v7 migration clamps `lastActiveDate` to the person's today (`localToday`, passed
1569
+ in by the constructor). This costs at most one lived day counted twice, once; decay
1570
+ does not notice a day.
1571
+ - `advanceClock` treats a date ONE calendar day behind the last as the same lived day:
1572
+ no advance, no rewrite, and no failure row, just a ring event (`store.clock.held`).
1573
+ It covers flying west as well as the upgrade. A jump back of more than a day is still
1574
+ `CLOCK_BACKWARDS`.
1575
+ - **N5.** An event date is stored trimmed. Year 0000 is not a calendar date. `isZone`
1576
+ refuses bare offsets such as "+05:30", because an offset has no daylight-saving rules.
1577
+ - **N4, accepted.** A long-running MCP server resolves the machine zone at each call, but
1578
+ a server that outlives a flight keeps the process's `TZ`. On bun that `TZ` is fixed at
1579
+ start, so `note` writes the old zone's day until the next Reconnect.
1580
+ - **N9, accepted.** A 0.3.1 worker already mid-run during the upgrade keeps writing
1581
+ v6-shaped SQL until its watchdog ends it. Its `INSERT OR REPLACE` on edges leaves
1582
+ `created_at` NULL on the edges it touches. That is harmless and bounded.
@@ -55,6 +55,21 @@ export type StoreErrorCode =
55
55
  * file to restore. Doctor's Store-open finding already has the no-path arm.
56
56
  */
57
57
  | "MEMORY_BODY_MISSING"
58
+ /**
59
+ * A reminder date (`PutInput.eventDate`, schema v7) that `time.ts` cannot
60
+ * read as a day, month, year or range. Refused rather than stored: a date
61
+ * nothing can parse is a reminder that silently never comes up.
62
+ * `detail` carries `{ id, date }`.
63
+ */
64
+ | "EVENT_DATE_INVALID"
65
+ /**
66
+ * A feeling (`Store#addFeelings`, schema v7) that cannot be stored as given:
67
+ * an unknown `whose` or `core`, a strength outside 0..1, an emotion the wheel
68
+ * files under another core, a `beneath` that is not on the same memory or
69
+ * loops. `detail` carries `{ index, reason }`; the whole call wrote nothing.
70
+ * An emotion simply not on the wheel is NOT this — it is kept as `other`.
71
+ */
72
+ | "FEELING_INVALID"
58
73
  | "ID_MALFORMED"
59
74
  | "ID_UNKNOWN"
60
75
  | "ID_CYCLE"
@@ -110,6 +125,13 @@ export type StoreErrorCode =
110
125
  * a dead end. The old store is untouched and stays on disk.
111
126
  */
112
127
  | "STORE_PRE_ROWS"
128
+ /**
129
+ * The store needs a schema migration and the copy that comes before one
130
+ * could not be made, so nothing was migrated: the store is still on its old
131
+ * version and the build that wrote it still opens it. `detail` carries
132
+ * `{ path, found, expected, dir, reason, remedy }`.
133
+ */
134
+ | "MIGRATION_SNAPSHOT_FAILED"
113
135
  | "SQLITE_UNAVAILABLE"
114
136
  | "LAYOUT_UNCLASSIFIED";
115
137