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
@@ -1,207 +1,61 @@
1
1
  /**
2
2
  * `/api/mechanisms` — the eleven memory mechanisms the site names, each with a
3
- * light: grey (not built), green (built, and fired in the last 7 LIVED days),
4
- * amber (built, and not firing).
3
+ * light:
4
+ *
5
+ * - grey: not built;
6
+ * - green: built, and fired in the last 7 LIVED days;
7
+ * - waiting: built, and not due — a scheduled phase that ran on time and
8
+ * comes round again in N days, or a mechanism holding nothing to act on;
9
+ * - amber: built, and quiet when it should not be.
5
10
  *
6
11
  * The list, its order and its four families are the site's
7
12
  * (`counterparts-site/features/home-v2/content/regions.ts`, minus the two it
8
- * parks). What each one says about Counterparts lives beside the page, in
9
- * `web/mechanisms/<id>/index.js`; this file owns only the one question the page
10
- * cannot answer for itself: did it fire, and which rows say so.
11
- *
12
- * BUILT OR NOT comes from `docs/research/mechanism-audit-2026-09-24.md`, not
13
- * from the site's "in development" badge — the two disagree on consolidation
14
- * (site: in development; audit: built, narrow) and association (site: in
15
- * development; audit: built but starved). The light answers "does the code
16
- * run", so it takes the audit's word; the badge stays the site's, on the
17
- * client module.
13
+ * parks). WHICH ROWS COUNT AS A FIRING, and how much of each is built, is
14
+ * `adapters/mechanism-evidence.ts` — shared with `counterparts mechanisms`, so
15
+ * the two cannot judge a mechanism differently. This file owns only the window
16
+ * (lived days) and the dashboard's words. What each one says about Counterparts
17
+ * lives beside the page, in `web/mechanisms/<id>/index.js`.
18
18
  *
19
- * Read-only, like everything in this directory: `eventLog` reads and nothing
20
- * else. Rules 1–4 of `views.ts` apply; no row text is emitted, only counts and
21
- * event `seq`s the page can open with `/api/event`.
19
+ * Read-only, like everything in this directory. Rules 1–4 of `views.ts` apply;
20
+ * no row text is emitted, only counts and event `seq`s the page can open with
21
+ * `/api/event`.
22
22
  */
23
- import type { EventRow } from "../../../../core/store/index.js";
24
- import type { DurableEventName } from "../../registries.js";
23
+ import {
24
+ FAMILIES,
25
+ MECHANISM_EVIDENCE,
26
+ RECENT_IDS,
27
+ amount,
28
+ counted,
29
+ builtCount,
30
+ mechanismEvidence,
31
+ payloadOf,
32
+ } from "../../../mechanism-evidence.js";
33
+ import type { Build, Family, MechanismEvidence, Payload, Proof, Verdict } from "../../../mechanism-evidence.js";
25
34
  import type { DashboardSource } from "../../source.js";
26
35
 
27
- /** The window: today's lived day and the six before it. */
28
- export const MECHANISM_DAYS = 7;
29
- /** How many backing event seqs each mechanism hands the page. */
30
- export const RECENT_IDS = 3;
31
- /** Ceiling on one name's read inside the window — reported, never silent. */
32
- const WINDOW_CEILING = 50_000;
33
- /** How far back an amber row looks for "last seen", newest first. */
34
- const LOOKBACK = 500;
35
-
36
- export type Family = "encoding" | "storage" | "retrieval" | "transformation";
37
- export const FAMILIES: readonly Family[] = ["encoding", "storage", "retrieval", "transformation"];
38
-
39
- export type Payload = Record<string, unknown>;
40
-
41
- /** One kind of row that proves a mechanism fired. */
42
- export interface Proof {
43
- readonly event: DurableEventName;
44
- /** What a unit of it is, after the number — [one, many]:
45
- * ["memory archived at the floor", "memories archived at the floor"]. */
46
- readonly says: readonly [string, string];
47
- /** Sum this numeric payload field instead of counting rows; a row whose
48
- * field is not a number above zero does not count at all (the `positive`
49
- * rule of `adapters/fired.ts`: a row that lands whether or not the
50
- * mechanism did anything is not a firing). */
51
- readonly sum?: string;
52
- /** Only rows this accepts count. */
53
- readonly where?: (p: Payload) => boolean;
54
- }
55
-
56
- interface MechanismProof {
57
- readonly id: string;
58
- readonly family: Family;
59
- /** Per the audit. A mechanism that is not built is grey and never counted. */
60
- readonly built: boolean;
61
- /** Empty when not built. */
62
- readonly proofs: readonly Proof[];
63
- /** For a grey light: the one plain line it shows instead of evidence. */
64
- readonly grey?: string;
65
- }
36
+ export { FAMILIES, RECENT_IDS, amount, builtCount, counted, payloadOf };
37
+ export type { Build, Family, Payload, Proof };
66
38
 
67
- const num = (v: unknown): number => (typeof v === "number" && Number.isFinite(v) ? v : 0);
39
+ /** The one table, under the name this directory has always read it by. */
40
+ export const MECHANISM_PROOFS: readonly MechanismEvidence[] = MECHANISM_EVIDENCE;
68
41
 
69
- // ── THE TABLE ───────────────────────────────────────────────────────────────
70
- // One row per mechanism, in the site's order. Read it top to bottom: what
71
- // counts as the mechanism firing, in the rows the store already keeps.
72
- export const MECHANISM_PROOFS: readonly MechanismProof[] = [
73
- // ── Encoding ──
74
- {
75
- // Salience writes no row of its own: the score is columns on the memory.
76
- // Every memory is scored at the gate, so the gate's row IS the scoring.
77
- id: "salience",
78
- family: "encoding",
79
- built: true,
80
- proofs: [
81
- { event: "gate.deposit", sum: "accepted", says: ["memory scored as it was written", "memories scored as they were written"] },
82
- { event: "gate.chunk", sum: "accepted", says: ["memory scored from a crash write-up", "memories scored from a crash write-up"] },
83
- ],
84
- },
85
- {
86
- // The quoted feeling is stored as a label with no weight, the classifier
87
- // ships off, and the numeric emotional score rides the salience columns —
88
- // there is no row that could say "feeling changed this memory".
89
- id: "emotional",
90
- family: "encoding",
91
- built: false,
92
- proofs: [],
93
- grey: "In development: a feeling is stored as a label but does not yet weigh anything.",
94
- },
95
- // ── Storage ──
96
- {
97
- id: "decay",
98
- family: "storage",
99
- built: true,
100
- proofs: [
101
- // The decay site also records the CROSSING into identity (direction
102
- // up), which is not a fade; only a move down counts here.
103
- { event: "band.transition", where: (p) => p["site"] === "decay" && p["direction"] !== "up", says: ["memory faded a band", "memories faded a band"] },
104
- { event: "memory.pruned", says: ["memory archived at the floor", "memories archived at the floor"] },
105
- // The entity-card fade has no row of its own; it is a count on the
106
- // nightly cycle row, so only nights that faded something count.
107
- { event: "sleep.cycle", sum: "faded", says: ["unused card faded", "unused cards faded"] },
108
- ],
109
- },
110
- {
111
- // Only byte-identical bodies merge (that is consolidation's, below); two
112
- // near-duplicates are left alone on purpose. Nothing competes.
113
- id: "interference",
114
- family: "storage",
115
- built: false,
116
- proofs: [],
117
- grey: "In development: similar memories do not compete yet.",
118
- },
119
- // ── Retrieval ──
120
- {
121
- id: "retrieval",
122
- family: "retrieval",
123
- built: true,
124
- proofs: [
125
- {
126
- event: "recall.decision",
127
- where: (p) => num(p["surfacedCount"]) + num(p["footnoteCount"]) > 0,
128
- says: ["turn brought memories to mind", "turns brought memories to mind"],
129
- },
130
- { event: "mcp.recall", says: ["deliberate look-up", "deliberate look-ups"] },
131
- { event: "recall.credit", sum: "credited", says: ["memory strengthened by being used", "memories strengthened by being used"] },
132
- ],
133
- },
134
- {
135
- // Built but starved (audit): links form only between memories used in
136
- // the same turn, and a hop only boosts what the turn already reached. A
137
- // flush that wrote no link rows is not a firing.
138
- id: "association",
139
- family: "retrieval",
140
- built: true,
141
- proofs: [{ event: "associate.flush", sum: "rows", says: ["link written", "links written"] }],
142
- },
143
- {
144
- // `prospective.fire` exists and only the demo seeder calls `fire()`: no
145
- // live path spends the budget, so the rows prove nothing about real use.
146
- id: "prospective",
147
- family: "retrieval",
148
- built: false,
149
- proofs: [],
150
- grey: "In development: dated reminders can be stored, but nothing brings them back on the day yet.",
151
- },
152
- // ── Transformation ──
153
- {
154
- // Narrow (audit): only exact duplicates merge, promotion needs a high score
155
- // and use on three separate days, and it runs every three lived days.
156
- // The cycle row itself is NOT a proof: it lands every night regardless.
157
- id: "consolidation",
158
- family: "transformation",
159
- built: true,
160
- proofs: [
161
- { event: "band.promoted", says: ["memory became core", "memories became core"] },
162
- { event: "memory.merged", says: ["exact duplicate merged", "exact duplicates merged"] },
163
- { event: "band.transition", where: (p) => p["site"] === "consolidate", says: ["memory rose a band", "memories rose a band"] },
164
- ],
165
- },
166
- {
167
- // Partial (audit): it revises only what a writer declared with `updates:`,
168
- // for beliefs and identity lines, under pressure over several days. The
169
- // supersede itself (`memory.superseded`) is not durable; the pressure row is.
170
- id: "reconsolidation",
171
- family: "transformation",
172
- built: true,
173
- proofs: [{ event: "revision.pressure", says: ["correction weighed against an old memory", "corrections weighed against old memories"] }],
174
- },
175
- {
176
- // A band label only; nothing distils episodes into knowledge.
177
- id: "episodic-semantic",
178
- family: "transformation",
179
- built: false,
180
- proofs: [],
181
- grey: "In development: sessions do not turn into general knowledge yet.",
182
- },
183
- {
184
- // Beliefs have no live producer (`addBelief` is called only by the demo
185
- // seeder). `revision.pressure` is shared with reconsolidation above and is
186
- // counted there, not here.
187
- id: "schema",
188
- family: "transformation",
189
- built: false,
190
- proofs: [],
191
- grey: "In development: beliefs about people and projects are not formed yet.",
192
- },
193
- ];
42
+ /** The window: today's lived day and the six before it. */
43
+ export const MECHANISM_DAYS = 7;
194
44
 
195
- export type MechanismStatus = "grey" | "green" | "amber";
45
+ export type MechanismStatus = "grey" | "green" | "waiting" | "amber";
196
46
 
197
47
  export interface MechanismLight {
198
48
  readonly id: string;
199
49
  readonly family: Family;
50
+ /** How much of it is built: the pill's tag (none / "partly built"). */
51
+ readonly build: Build;
200
52
  readonly status: MechanismStatus;
201
53
  /** One plain-English line. */
202
54
  readonly evidence: string;
203
55
  /** The newest few event `seq`s that back a green light. Empty otherwise. */
204
56
  readonly events: readonly number[];
57
+ /** A scheduled mechanism's next run, in lived days (0 = at the next session's end). */
58
+ readonly nextInDays: number | null;
205
59
  }
206
60
 
207
61
  export interface MechanismsView {
@@ -214,22 +68,50 @@ export interface MechanismsView {
214
68
  readonly truncated: boolean;
215
69
  }
216
70
 
217
- export function payloadOf(row: EventRow): Payload {
218
- if (row.payload === null) return {};
219
- try {
220
- const v: unknown = JSON.parse(row.payload);
221
- return v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Payload) : {};
222
- } catch {
223
- return {};
224
- }
71
+ const plural = (n: number, says: readonly [string, string]): string => `${n} ${n === 1 ? says[0] : says[1]}`;
72
+
73
+ /** "in 2 lived days" / "at the next session's end". */
74
+ export function nextRunWords(nextInDays: number): string {
75
+ if (nextInDays <= 0) return "at the next session's end";
76
+ return `in ${nextInDays} lived ${nextInDays === 1 ? "day" : "days"}`;
225
77
  }
226
78
 
227
- /** The amount this row contributes, or 0 when it does not count. */
228
- export function amount(proof: Proof, p: Payload): number {
229
- if (proof.where !== undefined && !proof.where(p)) return 0;
230
- if (proof.sum === undefined) return 1;
231
- const v = num(p[proof.sum]);
232
- return v > 0 ? v : 0;
79
+ /** One verdict → one light, in the dashboard's words. */
80
+ export function lightOf(v: Verdict): MechanismLight {
81
+ const row = MECHANISM_EVIDENCE.find((m) => m.id === v.id);
82
+ const base = { id: v.id, family: v.family, build: v.build, nextInDays: v.schedule?.nextInDays ?? null };
83
+ if (v.build === "not" || row === undefined) {
84
+ return { ...base, status: "grey", evidence: row?.grey ?? "Not built yet.", events: [] };
85
+ }
86
+ const heldLine = row.held === undefined || v.held === null ? "" : ` ${plural(v.held, row.held.says)}.`;
87
+ if (v.fired) {
88
+ const said = v.parts.filter((p) => p.count > 0).map((p) => plural(p.count, p.says));
89
+ const todayLine = v.today === null ? "" : ` ${v.today} today.`;
90
+ return {
91
+ ...base,
92
+ status: "green",
93
+ evidence: `${said.join(", ")} in the last ${MECHANISM_DAYS} lived days.${todayLine}${heldLine}`,
94
+ events: v.events,
95
+ };
96
+ }
97
+ if (row.held !== undefined && v.held === 0) {
98
+ return { ...base, status: "waiting", evidence: row.held.none, events: [] };
99
+ }
100
+ if (v.schedule !== null && v.schedule.onTime && v.schedule.lastRanDay !== null) {
101
+ return {
102
+ ...base,
103
+ status: "waiting",
104
+ evidence:
105
+ `Ran on schedule on lived day ${v.schedule.lastRanDay} with nothing to change; ` +
106
+ `next run ${nextRunWords(v.schedule.nextInDays)}.`,
107
+ events: [],
108
+ };
109
+ }
110
+ const evidence =
111
+ v.lastFiredDay === null
112
+ ? `Built, and no record of it firing yet.`
113
+ : `Built, but quiet for ${MECHANISM_DAYS} lived days (last fired on lived day ${v.lastFiredDay}).`;
114
+ return { ...base, status: "amber", evidence: `${evidence}${heldLine}`, events: [] };
233
115
  }
234
116
 
235
117
  export function mechanismsView(src: DashboardSource): MechanismsView {
@@ -241,62 +123,6 @@ export function mechanismsView(src: DashboardSource): MechanismsView {
241
123
  livedDay = 0;
242
124
  }
243
125
  const fromDay = Math.max(0, livedDay - (MECHANISM_DAYS - 1));
244
- let truncated = false;
245
- // One read per event name, shared by every proof that names it.
246
- const windowRows = new Map<string, EventRow[]>();
247
- const rowsFor = (name: string): EventRow[] => {
248
- let rows = windowRows.get(name);
249
- if (rows === undefined) {
250
- rows = store.eventLog({ name, sinceDay: fromDay, limit: WINDOW_CEILING, order: "desc" });
251
- if (rows.length >= WINDOW_CEILING) truncated = true;
252
- windowRows.set(name, rows);
253
- }
254
- return rows;
255
- };
256
-
257
- const mechanisms = MECHANISM_PROOFS.map((m): MechanismLight => {
258
- if (!m.built) {
259
- return { id: m.id, family: m.family, status: "grey", evidence: m.grey ?? "Not built yet.", events: [] };
260
- }
261
- const parts: string[] = [];
262
- const backing: EventRow[] = [];
263
- for (const proof of m.proofs) {
264
- let total = 0;
265
- for (const row of rowsFor(proof.event)) {
266
- const n = amount(proof, payloadOf(row));
267
- if (n > 0) {
268
- total += n;
269
- backing.push(row);
270
- }
271
- }
272
- if (total > 0) parts.push(`${total} ${total === 1 ? proof.says[0] : proof.says[1]}`);
273
- }
274
- if (parts.length > 0) {
275
- const events = backing
276
- .sort((a, b) => b.seq - a.seq)
277
- .slice(0, RECENT_IDS)
278
- .map((r) => r.seq);
279
- return { id: m.id, family: m.family, status: "green", evidence: `${parts.join(", ")} in the last ${MECHANISM_DAYS} lived days.`, events };
280
- }
281
- // Built, and nothing inside the window: when was it last seen at all? Only
282
- // the newest LOOKBACK rows of each name are searched, so a name with that
283
- // many non-counting rows since its last real firing reads "no record" —
284
- // acceptable for a scaffold; a real "last fired" wants its own query.
285
- let lastDay: number | null = null;
286
- for (const proof of m.proofs) {
287
- for (const row of store.eventLog({ name: proof.event, order: "desc", limit: LOOKBACK })) {
288
- if (amount(proof, payloadOf(row)) > 0) {
289
- if (lastDay === null || row.day > lastDay) lastDay = row.day;
290
- break;
291
- }
292
- }
293
- }
294
- const evidence =
295
- lastDay === null
296
- ? `Built, and no record of it firing yet.`
297
- : `Built, but quiet for ${MECHANISM_DAYS} lived days (last fired on lived day ${lastDay}).`;
298
- return { id: m.id, family: m.family, status: "amber", evidence, events: [] };
299
- });
300
-
301
- return { livedDay, fromDay, days: MECHANISM_DAYS, mechanisms, truncated };
126
+ const { verdicts, truncated } = mechanismEvidence(store, { sinceDay: fromDay, today: livedDay });
127
+ return { livedDay, fromDay, days: MECHANISM_DAYS, mechanisms: verdicts.map(lightOf), truncated };
302
128
  }