counterparts 0.3.2 → 0.3.4

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 (153) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/docs/module-map.md +3 -2
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/NOTES.md +28 -0
  5. package/src/adapters/claude-code/bin/hook.ts +85 -22
  6. package/src/adapters/claude-code/config.ts +7 -0
  7. package/src/adapters/claude-code/doctor.ts +166 -4
  8. package/src/adapters/claude-code/hooks.ts +185 -6
  9. package/src/adapters/claude-code/index.ts +3 -0
  10. package/src/adapters/claude-code/transcript.ts +7 -0
  11. package/src/adapters/cli/CONTRACT.md +11 -0
  12. package/src/adapters/cli/INTERFACE-GAPS.md +16 -0
  13. package/src/adapters/cli/NOTES.md +25 -0
  14. package/src/adapters/cli/commands.ts +184 -4
  15. package/src/adapters/cli/dream-core.ts +126 -0
  16. package/src/adapters/cli/help.ts +17 -0
  17. package/src/adapters/cli/mechanisms.ts +199 -106
  18. package/src/adapters/dashboard/CONTRACT.md +5 -0
  19. package/src/adapters/dashboard/INTERFACE-GAPS.md +12 -0
  20. package/src/adapters/dashboard/NOTES.md +38 -0
  21. package/src/adapters/dashboard/registries.ts +35 -1
  22. package/src/adapters/dashboard/web/README.md +63 -26
  23. package/src/adapters/dashboard/web/app.html +2 -0
  24. package/src/adapters/dashboard/web/flow.ts +14 -0
  25. package/src/adapters/dashboard/web/lanes.ts +141 -0
  26. package/src/adapters/dashboard/web/mechanisms/association/index.js +1 -2
  27. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +8 -5
  28. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +7 -7
  29. package/src/adapters/dashboard/web/mechanisms/decay/index.js +1 -2
  30. package/src/adapters/dashboard/web/mechanisms/dreaming/index.js +19 -0
  31. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +9 -6
  32. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +4 -5
  33. package/src/adapters/dashboard/web/mechanisms/index.js +5 -3
  34. package/src/adapters/dashboard/web/mechanisms/interference/index.js +1 -2
  35. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +7 -5
  36. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +1 -2
  37. package/src/adapters/dashboard/web/mechanisms/regions.js +1 -1
  38. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +1 -2
  39. package/src/adapters/dashboard/web/mechanisms/salience/index.js +1 -2
  40. package/src/adapters/dashboard/web/mechanisms/schema/index.js +1 -2
  41. package/src/adapters/dashboard/web/narrate.ts +76 -13
  42. package/src/adapters/dashboard/web/pages/health/sections/checks.js +17 -1
  43. package/src/adapters/dashboard/web/pages/home/home.css +29 -13
  44. package/src/adapters/dashboard/web/pages/home/index.js +2 -0
  45. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +22 -7
  46. package/src/adapters/dashboard/web/pages/home/sections/hero.js +15 -3
  47. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +15 -9
  48. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +6 -2
  49. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +35 -18
  50. package/src/adapters/dashboard/web/pages/memories/index.js +30 -36
  51. package/src/adapters/dashboard/web/pages/memories/memories.css +97 -72
  52. package/src/adapters/dashboard/web/pages/memories/row.js +51 -0
  53. package/src/adapters/dashboard/web/pages/memories/sections/feel.js +176 -0
  54. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +67 -0
  55. package/src/adapters/dashboard/web/pages/memories/sections/list.js +65 -43
  56. package/src/adapters/dashboard/web/pages/memories/sections/search.js +26 -23
  57. package/src/adapters/dashboard/web/pages/memories/state.js +12 -5
  58. package/src/adapters/dashboard/web/pages/self/index.js +57 -16
  59. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +76 -0
  60. package/src/adapters/dashboard/web/pages/self/sections/journal.js +75 -19
  61. package/src/adapters/dashboard/web/pages/self/sections/page.js +108 -65
  62. package/src/adapters/dashboard/web/pages/self/sections/settling.js +129 -104
  63. package/src/adapters/dashboard/web/pages/self/sections/wake.js +31 -15
  64. package/src/adapters/dashboard/web/pages/self/self.css +122 -59
  65. package/src/adapters/dashboard/web/pages/self/state.js +21 -0
  66. package/src/adapters/dashboard/web/server.ts +9 -0
  67. package/src/adapters/dashboard/web/shared/memory-marks.css +17 -0
  68. package/src/adapters/dashboard/web/shared/memory-marks.js +81 -0
  69. package/src/adapters/dashboard/web/shared/memory-modal.js +240 -53
  70. package/src/adapters/dashboard/web/shared/modal.css +67 -0
  71. package/src/adapters/dashboard/web/shared/tip.js +1 -1
  72. package/src/adapters/dashboard/web/shared/widgets/feed.css +4 -0
  73. package/src/adapters/dashboard/web/shared/widgets/feed.js +56 -14
  74. package/src/adapters/dashboard/web/shared/widgets/light.css +1 -0
  75. package/src/adapters/dashboard/web/shared/widgets/light.js +7 -5
  76. package/src/adapters/dashboard/web/shared/widgets/tips.css +19 -0
  77. package/src/adapters/dashboard/web/shared/widgets/tips.js +56 -0
  78. package/src/adapters/dashboard/web/views/activity.ts +18 -2
  79. package/src/adapters/dashboard/web/views/archive-words.ts +27 -10
  80. package/src/adapters/dashboard/web/views/dreams.ts +199 -0
  81. package/src/adapters/dashboard/web/views/mechanism-panel.ts +116 -35
  82. package/src/adapters/dashboard/web/views/mechanisms.ts +81 -255
  83. package/src/adapters/dashboard/web/views/memories.ts +245 -43
  84. package/src/adapters/dashboard/web/views/memory-words.ts +133 -0
  85. package/src/adapters/dashboard/web/views/memory.ts +226 -4
  86. package/src/adapters/dashboard/web/views/mind.ts +261 -61
  87. package/src/adapters/dashboard/web/views/overview.ts +80 -42
  88. package/src/adapters/dashboard/web/views/search.ts +35 -1
  89. package/src/adapters/dashboard/web/views/shared.ts +14 -0
  90. package/src/adapters/dashboard/web/views.ts +2 -0
  91. package/src/adapters/feelings-line.ts +74 -0
  92. package/src/adapters/fired.ts +163 -23
  93. package/src/adapters/mcp/CONTRACT.md +8 -0
  94. package/src/adapters/mcp/NOTES.md +56 -0
  95. package/src/adapters/mcp/server.ts +254 -6
  96. package/src/adapters/mcp/tools.ts +180 -5
  97. package/src/adapters/mechanism-evidence.ts +465 -0
  98. package/src/core/bridge.ts +21 -16
  99. package/src/core/counterpart.ts +422 -10
  100. package/src/core/dream/CONTRACT.md +143 -0
  101. package/src/core/dream/INTERFACE-GAPS.md +24 -0
  102. package/src/core/dream/NOTES.md +84 -0
  103. package/src/core/dream/index.ts +1067 -0
  104. package/src/core/dream/mark.ts +14 -0
  105. package/src/core/dream/tunables.ts +56 -0
  106. package/src/core/encode/CONTRACT.md +7 -1
  107. package/src/core/feelings-wheel.ts +171 -13
  108. package/src/core/mint.ts +9 -0
  109. package/src/core/physics/CONTRACT.md +132 -21
  110. package/src/core/physics/NOTES.md +233 -0
  111. package/src/core/physics/index.ts +419 -50
  112. package/src/core/prospective/CONTRACT.md +35 -6
  113. package/src/core/prospective/INTERFACE-GAPS.md +10 -5
  114. package/src/core/prospective/NOTES.md +175 -4
  115. package/src/core/prospective/derive.ts +32 -3
  116. package/src/core/prospective/index.ts +362 -39
  117. package/src/core/prospective/tunables.ts +18 -1
  118. package/src/core/prospective/windows.ts +104 -46
  119. package/src/core/recall/CONTRACT.md +28 -0
  120. package/src/core/recall/NOTES.md +55 -0
  121. package/src/core/recall/activate.ts +32 -5
  122. package/src/core/recall/gate.ts +7 -1
  123. package/src/core/recall/index.ts +28 -2
  124. package/src/core/recall/mood.ts +106 -0
  125. package/src/core/recall/tunables.ts +26 -0
  126. package/src/core/remember/CONTRACT.md +5 -0
  127. package/src/core/remember/index.ts +1 -0
  128. package/src/core/remember/proposals.ts +86 -3
  129. package/src/core/remember/spans.ts +11 -1
  130. package/src/core/self/CONTRACT.md +3 -0
  131. package/src/core/self/INTERFACE-GAPS.md +7 -0
  132. package/src/core/self/NOTES.md +30 -0
  133. package/src/core/self/identity.ts +115 -6
  134. package/src/core/self/index.ts +17 -0
  135. package/src/core/self/tunables.ts +17 -0
  136. package/src/core/sleep/CONTRACT.md +17 -1
  137. package/src/core/sleep/INTERFACE-GAPS.md +19 -0
  138. package/src/core/sleep/NOTES.md +36 -0
  139. package/src/core/sleep/consolidate.ts +149 -96
  140. package/src/core/sleep/decay.ts +11 -0
  141. package/src/core/sleep/index.ts +4 -1
  142. package/src/core/sleep/tunables.ts +9 -0
  143. package/src/core/sleep/types.ts +17 -0
  144. package/src/core/sleep/upgrade.ts +168 -0
  145. package/src/core/store/CONTRACT.md +21 -2
  146. package/src/core/store/NOTES.md +68 -0
  147. package/src/core/store/feelings.ts +23 -6
  148. package/src/core/store/index.ts +716 -17
  149. package/src/core/store/operational.ts +329 -4
  150. package/src/core/store/owner-op-seam.ts +79 -1
  151. package/src/core/types.ts +37 -0
  152. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +0 -178
  153. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +0 -42
@@ -0,0 +1,465 @@
1
+ /**
2
+ * Did a memory mechanism fire, and which rows say so — the ONE judgement the
3
+ * dashboard's lights (`dashboard/web/views/mechanisms.ts`) and the console's
4
+ * short view (`cli/mechanisms.ts`) both call.
5
+ *
6
+ * **Why it exists** (2026-09-26, an experiment). The two surfaces kept their
7
+ * own rules and disagreed on five of the eleven: the console called a bare
8
+ * sleep-cycle row consolidation AND forgetting, counted a deposit row that
9
+ * accepted nothing as salience, and a flush that wrote no link as association.
10
+ * Now the rules are here, once. Each surface keeps its own table of WORDS and
11
+ * its own window (lived days on the dashboard, calendar days in the console),
12
+ * and both hand the window in.
13
+ *
14
+ * **Where it sits.** Beside `fired.ts`, for the reason that file gives: two
15
+ * adapters need it and adapters never import each other. It imports
16
+ * `dashboard/registries.ts` for the same reason `fired.ts` does — a registry,
17
+ * not a view — and nothing else of the dashboard's, so the console loads no
18
+ * dashboard code.
19
+ *
20
+ * **Built / partly / not** is `build` below, one table: the pills' tags and the
21
+ * home page's "N of 11 built" read it. The calls are from
22
+ * `docs/research/mechanism-audit-2026-09-24.md` plus what shipped since (emotion
23
+ * part A, prospective reminders, the entity-card fade). A working default,
24
+ * revisable.
25
+ *
26
+ * Read-only: `eventLog`, two counts and one meta read. No row text.
27
+ */
28
+ import { cadenceFor, readMarker, MARKER_UNSET } from "../core/sleep/index.js";
29
+ import type { Phase } from "../core/sleep/index.js";
30
+ import type { EventRow, ReadOnlyStore } from "../core/store/index.js";
31
+ import type { DurableEventName } from "./dashboard/registries.js";
32
+
33
+ /** How many backing event seqs a verdict keeps. */
34
+ export const RECENT_IDS = 3;
35
+ /** Ceiling on one name's read inside a window — reported, never silent. */
36
+ const WINDOW_CEILING = 50_000;
37
+ /** How far back "last fired" looks, per event name, newest first. */
38
+ const LOOKBACK = 500;
39
+
40
+ export type Family = "encoding" | "storage" | "retrieval" | "transformation";
41
+ export const FAMILIES: readonly Family[] = ["encoding", "storage", "retrieval", "transformation"];
42
+
43
+ /** How much of a mechanism is built. Grey with no tag, a "partly built" tag, no tag. */
44
+ export type Build = "built" | "partly" | "not";
45
+
46
+ export type Payload = Record<string, unknown>;
47
+
48
+ /** One kind of row that proves a mechanism fired. */
49
+ export interface Proof {
50
+ /** A name the surfaces can ask for this proof's count by. */
51
+ readonly key: string;
52
+ readonly event: DurableEventName;
53
+ /** The dashboard's words for a unit of it — [one, many]. */
54
+ readonly says: readonly [string, string];
55
+ /** Sum this numeric payload field instead of counting rows; a row whose field
56
+ * is not a number above zero does not count at all (`fired.ts`'s `positive`
57
+ * rule: a row that lands whether or not the mechanism acted is not a firing). */
58
+ readonly sum?: string;
59
+ /** Only rows this accepts count. */
60
+ readonly where?: (p: Payload) => boolean;
61
+ /**
62
+ * Only rows whose act STILL STANDS count — for an act the owner can take
63
+ * back after it fired (a dream, undone). Read against the store, so it is
64
+ * asked of a row only after `where` and `sum` said it counts.
65
+ */
66
+ readonly stands?: (store: ReadOnlyStore, row: EventRow) => boolean;
67
+ }
68
+
69
+ export interface MechanismEvidence {
70
+ readonly id: string;
71
+ readonly family: Family;
72
+ readonly build: Build;
73
+ /** Empty when not built. */
74
+ readonly proofs: readonly Proof[];
75
+ /**
76
+ * A mechanism whose firing is ARITHMETIC ON A ROW rather than an event (the
77
+ * emotion lift): rows it acted on born inside the window, counted from the
78
+ * store. Backs no event seq.
79
+ */
80
+ readonly census?: {
81
+ readonly key: string;
82
+ readonly count: (store: ReadOnlyStore, sinceDay: number) => number;
83
+ readonly says: readonly [string, string];
84
+ };
85
+ /** For a mechanism that is not built: the one plain line shown instead. */
86
+ readonly grey?: string;
87
+ /**
88
+ * WHAT THE MECHANISM IS HOLDING, when that decides whether it can fire at all
89
+ * (prospective: dated memories). Zero, with nothing fired, means there is
90
+ * truly nothing for it to do.
91
+ */
92
+ readonly held?: {
93
+ readonly count: (store: ReadOnlyStore) => number;
94
+ readonly says: readonly [string, string];
95
+ readonly none: string;
96
+ };
97
+ /** Also count how many firings landed TODAY (the window's `today`). */
98
+ readonly today?: boolean;
99
+ /**
100
+ * The sleep phase it runs in, when it runs on a SCHEDULE rather than every
101
+ * day (consolidation: every `CADENCE.consolidate` lived days). A quiet week
102
+ * of a phase that ran on time is "next run in N days", not "quiet".
103
+ */
104
+ readonly schedule?: Phase;
105
+ }
106
+
107
+ const num = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) ? v : 0);
108
+
109
+ // ── THE TABLE ───────────────────────────────────────────────────────────────
110
+ // One row per mechanism, in the site's order. What counts as it firing, in the
111
+ // rows the store already keeps; and how much of it is built.
112
+ export const MECHANISM_EVIDENCE: readonly MechanismEvidence[] = [
113
+ // ── Encoding ──
114
+ {
115
+ // Salience writes no row of its own: the score is columns on the memory.
116
+ // Every memory is scored at the gate, so the gate's ACCEPTED count is it.
117
+ id: "salience",
118
+ family: "encoding",
119
+ build: "built",
120
+ proofs: [
121
+ { key: "deposit", event: "gate.deposit", sum: "accepted", says: ["memory scored as it was written", "memories scored as they were written"] },
122
+ { key: "chunk", event: "gate.chunk", sum: "accepted", says: ["memory scored from a crash write-up", "memories scored from a crash write-up"] },
123
+ ],
124
+ },
125
+ {
126
+ // PARTLY: emotion part A (2026-09-26) weighs recorded feelings — the lift
127
+ // and the slower fade are arithmetic on the row (the census), the mood
128
+ // match is a count on the turn's row. Nothing reads feeling from words yet.
129
+ id: "emotional",
130
+ family: "encoding",
131
+ build: "partly",
132
+ proofs: [
133
+ { key: "moodMatched", event: "recall.decision", sum: "moodMatched", says: ["memory a matching mood brought closer", "memories a matching mood brought closer"] },
134
+ ],
135
+ census: {
136
+ key: "weighted",
137
+ count: (store, sinceDay) => store.emotionCensus({ sinceDay }).weighted,
138
+ says: ["new memory held higher and fading slower for the feeling it carries", "new memories held higher and fading slower for the feeling they carry"],
139
+ },
140
+ },
141
+ // ── Storage ──
142
+ {
143
+ id: "decay",
144
+ family: "storage",
145
+ build: "built",
146
+ proofs: [
147
+ // The decay site also records the CROSSING into identity (direction up),
148
+ // which is not a fade; only a move down counts.
149
+ { key: "faded", event: "band.transition", where: (p) => p["site"] === "decay" && p["direction"] !== "up", says: ["memory faded a band", "memories faded a band"] },
150
+ { key: "pruned", event: "memory.pruned", says: ["memory archived at the floor", "memories archived at the floor"] },
151
+ // The entity-card fade has no row of its own; it is a count on the cycle row.
152
+ { key: "cards", event: "sleep.cycle", sum: "faded", says: ["unused card faded", "unused cards faded"] },
153
+ ],
154
+ },
155
+ {
156
+ // Only byte-identical bodies merge (consolidation's); near-duplicates are
157
+ // left alone on purpose. Nothing competes.
158
+ id: "interference",
159
+ family: "storage",
160
+ build: "not",
161
+ proofs: [],
162
+ grey: "In development: similar memories do not compete yet.",
163
+ },
164
+ // ── Retrieval ──
165
+ {
166
+ id: "retrieval",
167
+ family: "retrieval",
168
+ build: "built",
169
+ proofs: [
170
+ {
171
+ key: "turns",
172
+ event: "recall.decision",
173
+ where: (p) => num(p["surfacedCount"]) + num(p["footnoteCount"]) > 0,
174
+ says: ["turn brought memories to mind", "turns brought memories to mind"],
175
+ },
176
+ { key: "lookups", event: "mcp.recall", says: ["deliberate look-up", "deliberate look-ups"] },
177
+ { key: "credited", event: "recall.credit", sum: "credited", says: ["memory strengthened by being used", "memories strengthened by being used"] },
178
+ ],
179
+ },
180
+ {
181
+ // PARTLY (audit: built but starved): links form only between memories used
182
+ // in the same turn, and a hop only lifts what the turn already reached.
183
+ id: "association",
184
+ family: "retrieval",
185
+ build: "partly",
186
+ proofs: [{ key: "links", event: "associate.flush", sum: "rows", says: ["link written", "links written"] }],
187
+ },
188
+ {
189
+ // Built end to end since 2026-09-26 (#243, #247): a date on a note or a
190
+ // session's memories; quiet ones come back as footnotes, plain ones are said.
191
+ id: "prospective",
192
+ family: "retrieval",
193
+ build: "built",
194
+ proofs: [
195
+ { key: "plain", event: "prospective.plain", says: ["reminder said plainly", "reminders said plainly"] },
196
+ { key: "quiet", event: "prospective.fire", says: ["reminder came back as a quiet footnote", "reminders came back as quiet footnotes"] },
197
+ ],
198
+ held: {
199
+ count: (store) => store.datedMemories("0001-01-01", "9999-12-31").length,
200
+ says: ["dated memory held", "dated memories held"],
201
+ none: "Nothing dated yet: a note or a memory given a date comes back around that day.",
202
+ },
203
+ today: true,
204
+ },
205
+ // ── Transformation ──
206
+ {
207
+ // BUILT (2026-09-26, dreaming + consolidation): durability now comes from
208
+ // RETURNS — every spaced return makes a memory fade more slowly, credited
209
+ // the moment it happens (the census) — and the core from its two lanes,
210
+ // decided every three lived days (the schedule). A dream's merges are
211
+ // consolidation too. The cycle row itself is not a proof (it lands every
212
+ // night).
213
+ id: "consolidation",
214
+ family: "transformation",
215
+ build: "built",
216
+ proofs: [
217
+ { key: "promoted", event: "band.promoted", says: ["memory became core", "memories became core"] },
218
+ { key: "merged", event: "memory.merged", says: ["exact duplicate merged", "exact duplicates merged"] },
219
+ { key: "dreamMerged", event: "dream.changed", sum: "merge", stands: dreamStands, says: ["near-copy merged in a dream", "near-copies merged in a dream"] },
220
+ { key: "rose", event: "band.transition", where: (p) => p["site"] === "consolidate", says: ["memory rose a band", "memories rose a band"] },
221
+ ],
222
+ census: {
223
+ key: "returns",
224
+ count: (store, sinceDay) => {
225
+ const r = store.returnCounts({ sinceDay });
226
+ return r.awake + r.dream;
227
+ },
228
+ says: ["return that will make a memory fade more slowly", "returns that will make memories fade more slowly"],
229
+ },
230
+ schedule: "consolidate",
231
+ },
232
+ {
233
+ // BUILT (2026-09-26): a few minutes of replay the owner says yes to, by a
234
+ // background agent — merges, links, replays, patterns, flagged
235
+ // contradictions, a journal. A dream is proved by its journal and the
236
+ // changes it made; an ask alone is not a dream.
237
+ id: "dreaming",
238
+ family: "transformation",
239
+ build: "built",
240
+ proofs: [
241
+ // An undone dream is taken back: it no longer lights the mechanism.
242
+ { key: "dreams", event: "dream.journaled", stands: dreamStands, says: ["dream", "dreams"] },
243
+ { key: "changes", event: "dream.changed", sum: "applied", stands: dreamStands, says: ["change a dream made", "changes dreams made"] },
244
+ ],
245
+ },
246
+ {
247
+ // PARTLY (audit): it revises only what a writer declared with `updates:`,
248
+ // for beliefs and identity lines, under pressure over several days.
249
+ id: "reconsolidation",
250
+ family: "transformation",
251
+ build: "partly",
252
+ proofs: [{ key: "pressure", event: "revision.pressure", says: ["correction weighed against an old memory", "corrections weighed against old memories"] }],
253
+ },
254
+ {
255
+ // PARTLY (2026-09-26): a dream can write the pattern it sees across
256
+ // memories as a gist of its own (source `dreamed`, starting low). Nothing
257
+ // does it awake yet, and many sessions are not distilled on a schedule.
258
+ id: "episodic-semantic",
259
+ family: "transformation",
260
+ build: "partly",
261
+ proofs: [{ key: "gist", event: "dream.changed", sum: "gist", stands: dreamStands, says: ["pattern dreamed into a memory of its own", "patterns dreamed into memories of their own"] }],
262
+ },
263
+ {
264
+ // Entity cards exist (and fade, under Forgetting), but beliefs about them
265
+ // have no live producer (`addBelief` is called only by the demo seeder),
266
+ // and a card's birth leaves no durable row. Not built, for the light.
267
+ id: "schema",
268
+ family: "transformation",
269
+ build: "not",
270
+ proofs: [],
271
+ grey: "In development: beliefs about people and projects are not formed yet.",
272
+ },
273
+ ];
274
+
275
+ /** The window a surface judges over. */
276
+ export interface EvidenceWindow {
277
+ /** The lowest lived day a row may carry — the SQL bound, and the census's. */
278
+ readonly sinceDay: number;
279
+ /** The lived day that counts as today. */
280
+ readonly today: number;
281
+ /** Whether a row falls inside the window. Default: `row.day >= sinceDay`. */
282
+ readonly contains?: (row: EventRow) => boolean;
283
+ }
284
+
285
+ export interface EvidencePart {
286
+ readonly key: string;
287
+ readonly count: number;
288
+ readonly says: readonly [string, string];
289
+ }
290
+
291
+ /** A scheduled mechanism's clock: when its phase last ran, and when it runs next. */
292
+ export interface Schedule {
293
+ readonly phase: Phase;
294
+ readonly cadence: number;
295
+ /** The lived day its phase last completed, or null when it never has. */
296
+ readonly lastRanDay: number | null;
297
+ /** Lived days until it is due again; 0 = due at the next session's end. */
298
+ readonly nextInDays: number;
299
+ /** True while the phase is on time: it ran within one cadence of today. */
300
+ readonly onTime: boolean;
301
+ }
302
+
303
+ export interface Verdict {
304
+ readonly id: string;
305
+ readonly family: Family;
306
+ readonly build: Build;
307
+ /** Some proof counted above zero inside the window. */
308
+ readonly fired: boolean;
309
+ /** Every proof's count inside the window (zeros included), census last. */
310
+ readonly parts: readonly EvidencePart[];
311
+ /** The newest backing event seqs, newest first (at most RECENT_IDS). */
312
+ readonly events: readonly number[];
313
+ /** Of the window's firings, how many landed today (only when asked for). */
314
+ readonly today: number | null;
315
+ /** What it holds, when the row declares it; null when unasked or unreadable. */
316
+ readonly held: number | null;
317
+ /** When it did not fire in the window: the newest lived day it ever did. */
318
+ readonly lastFiredDay: number | null;
319
+ readonly schedule: Schedule | null;
320
+ }
321
+
322
+ export function payloadOf(row: EventRow): Payload {
323
+ if (row.payload === null) return {};
324
+ try {
325
+ const v: unknown = JSON.parse(row.payload);
326
+ return v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Payload) : {};
327
+ } catch {
328
+ return {};
329
+ }
330
+ }
331
+
332
+ /** The amount this row contributes, or 0 when it does not count. */
333
+ /** `amount`, and zero for a row whose act no longer stands (`Proof.stands`). */
334
+ export function counted(proof: Proof, row: EventRow, store: ReadOnlyStore): number {
335
+ const n = amount(proof, payloadOf(row));
336
+ if (n <= 0 || proof.stands === undefined) return n;
337
+ try {
338
+ return proof.stands(store, row) ? n : 0;
339
+ } catch {
340
+ return n;
341
+ }
342
+ }
343
+
344
+ /** A dream's row counts while the dream is not undone (review of #251). */
345
+ function dreamStands(store: ReadOnlyStore, row: EventRow): boolean {
346
+ return row.ref === null || store.dream(row.ref)?.state !== "undone";
347
+ }
348
+
349
+ export function amount(proof: Proof, p: Payload): number {
350
+ if (proof.where !== undefined && !proof.where(p)) return 0;
351
+ if (proof.sum === undefined) return 1;
352
+ const v = num(p[proof.sum]);
353
+ return v > 0 ? v : 0;
354
+ }
355
+
356
+ function scheduleOf(store: ReadOnlyStore, phase: Phase, today: number): Schedule {
357
+ const cadence = cadenceFor(phase);
358
+ let lastRanDay: number | null = null;
359
+ try {
360
+ const m = readMarker(store, phase);
361
+ if (m.health === "ok" && m.day !== MARKER_UNSET) lastRanDay = m.day;
362
+ } catch {
363
+ lastRanDay = null;
364
+ }
365
+ if (lastRanDay === null) return { phase, cadence, lastRanDay, nextInDays: 0, onTime: false };
366
+ const nextInDays = Math.max(0, lastRanDay + cadence - today);
367
+ return { phase, cadence, lastRanDay, nextInDays, onTime: today - lastRanDay <= cadence };
368
+ }
369
+
370
+ /**
371
+ * Every mechanism's verdict over one window. One read per event name inside the
372
+ * window, shared by every proof that names it.
373
+ */
374
+ export function mechanismEvidence(
375
+ store: ReadOnlyStore,
376
+ window: EvidenceWindow,
377
+ ): { verdicts: Verdict[]; truncated: boolean } {
378
+ const contains = window.contains ?? ((row: EventRow) => row.day >= window.sinceDay);
379
+ let truncated = false;
380
+ const windowRows = new Map<string, EventRow[]>();
381
+ const rowsFor = (name: string): EventRow[] => {
382
+ let rows = windowRows.get(name);
383
+ if (rows === undefined) {
384
+ const read = store.eventLog({ name, sinceDay: window.sinceDay, limit: WINDOW_CEILING, order: "desc" });
385
+ if (read.length >= WINDOW_CEILING) truncated = true;
386
+ rows = read.filter(contains);
387
+ windowRows.set(name, rows);
388
+ }
389
+ return rows;
390
+ };
391
+
392
+ const verdicts = MECHANISM_EVIDENCE.map((m): Verdict => {
393
+ const empty = { id: m.id, family: m.family, build: m.build };
394
+ if (m.build === "not") {
395
+ return { ...empty, fired: false, parts: [], events: [], today: null, held: null, lastFiredDay: null, schedule: null };
396
+ }
397
+ const parts: EvidencePart[] = [];
398
+ const backing: EventRow[] = [];
399
+ let today = 0;
400
+ for (const proof of m.proofs) {
401
+ let total = 0;
402
+ for (const row of rowsFor(proof.event)) {
403
+ const n = counted(proof, row, store);
404
+ if (n > 0) {
405
+ total += n;
406
+ backing.push(row);
407
+ if (row.day === window.today) today += n;
408
+ }
409
+ }
410
+ parts.push({ key: proof.key, count: total, says: proof.says });
411
+ }
412
+ if (m.census !== undefined) {
413
+ let count = 0;
414
+ try {
415
+ count = m.census.count(store, window.sinceDay);
416
+ } catch {
417
+ // A store that cannot answer the census simply has no census count.
418
+ }
419
+ parts.push({ key: m.census.key, count, says: m.census.says });
420
+ }
421
+ // A store that will not answer reads as unknown (null), never as zero —
422
+ // zero turns the light grey, and a failed read is not evidence of nothing.
423
+ let held: number | null = null;
424
+ if (m.held !== undefined) {
425
+ try {
426
+ held = m.held.count(store);
427
+ } catch {
428
+ held = null;
429
+ }
430
+ }
431
+ const fired = parts.some((p) => p.count > 0);
432
+ const events = backing
433
+ .sort((a, b) => b.seq - a.seq)
434
+ .slice(0, RECENT_IDS)
435
+ .map((r) => r.seq);
436
+ let lastFiredDay: number | null = null;
437
+ if (!fired) {
438
+ // Only the newest LOOKBACK rows of each name are searched.
439
+ for (const proof of m.proofs) {
440
+ for (const row of store.eventLog({ name: proof.event, order: "desc", limit: LOOKBACK })) {
441
+ if (counted(proof, row, store) > 0) {
442
+ if (lastFiredDay === null || row.day > lastFiredDay) lastFiredDay = row.day;
443
+ break;
444
+ }
445
+ }
446
+ }
447
+ }
448
+ return {
449
+ ...empty,
450
+ fired,
451
+ parts,
452
+ events,
453
+ today: m.today === true ? today : null,
454
+ held,
455
+ lastFiredDay,
456
+ schedule: m.schedule === undefined ? null : scheduleOf(store, m.schedule, window.today),
457
+ };
458
+ });
459
+ return { verdicts, truncated };
460
+ }
461
+
462
+ /** How many of the twelve are built at all ("partly" counts), for a headline. */
463
+ export function builtCount(): number {
464
+ return MECHANISM_EVIDENCE.filter((m) => m.build !== "not").length;
465
+ }
@@ -186,27 +186,32 @@ function verdictFor(
186
186
  }
187
187
 
188
188
  /**
189
- * All three author dimensions or nothing — a partial claim is not padded.
189
+ * The author's dimensions, as given — a missing one reads 0, exactly as
190
+ * `mint.ts` has always stored it.
190
191
  *
191
- * NAMED GAP (2026-09-04): the obvious source for `emotional` when the author
192
- * gave none is the stated-emotion gate, and it cannot supply one.
193
- * `encode/emotion.ts#gateEmotion` yields a `DurableFeeling` of `{type, subject}`
194
- * — a feeling that SURVIVED, with no magnitude on it anywhere — so there is no
195
- * number to read across, and manufacturing one from "a feeling was stated" is
196
- * retro-typing emotion, which encode §3 forbids outright. Left open rather than
197
- * approximated; the MCP adapter's contract carries the same gap as its §7.4.
192
+ * CHANGED 2026-09-26 (emotion part A, owner decision 1: "stop dropping a lone
193
+ * `emotional` score"). This used to be all three or nothing, so a note that
194
+ * said only `emotional: 0.9` reached the battery with no dimensions at all —
195
+ * while `mint.ts`, reading the same draft, stored the 0.9 on the row. The two
196
+ * readings of one note disagreed; now they agree. Padding a missing dimension
197
+ * with 0 claims nothing the author did not say: 0 is what an unsaid dimension
198
+ * has always been on the row. The SWEEP's intake (`counterpart.ts#applySweep`)
199
+ * keeps its all-three rule on purpose — a retelling author's lone number is not
200
+ * testimony, and it would now lift height and slow decay (physics §5.10).
201
+ *
202
+ * Still NOT manufactured from a stated feeling: `encode/emotion.ts#gateEmotion`
203
+ * yields `{type, subject}` with no magnitude, and inventing one from "a feeling
204
+ * was stated" is retro-typing emotion, which encode §3 forbids. Recorded
205
+ * FEELINGS (the `feelings` table) carry their own strength and reach physics
206
+ * beside the row (`feelingPeak`), not through this function.
198
207
  */
199
208
  function dimensionsFrom(
200
209
  s: Partial<{ relevance: number; emotional: number; predictive: number }>,
201
210
  ): ClaimedDimensions | null {
202
- if (
203
- typeof s.relevance === "number" &&
204
- typeof s.emotional === "number" &&
205
- typeof s.predictive === "number"
206
- ) {
207
- return { relevance: s.relevance, emotional: s.emotional, predictive: s.predictive };
208
- }
209
- return null;
211
+ const given = [s.relevance, s.emotional, s.predictive].some((v) => typeof v === "number");
212
+ if (!given) return null;
213
+ const n = (v: number | undefined): number => (typeof v === "number" ? v : 0);
214
+ return { relevance: n(s.relevance), emotional: n(s.emotional), predictive: n(s.predictive) };
210
215
  }
211
216
 
212
217
  /**