counterparts 0.1.0
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.
- package/CONSTITUTION.md +68 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/docs/ELI5.md +84 -0
- package/docs/QUICKSTART.md +1258 -0
- package/docs/module-map.md +81 -0
- package/package.json +63 -0
- package/src/adapters/claude-code/CONTRACT.md +606 -0
- package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
- package/src/adapters/claude-code/NOTES.md +1055 -0
- package/src/adapters/claude-code/bin/hook.ts +820 -0
- package/src/adapters/claude-code/bin/runner.ts +522 -0
- package/src/adapters/claude-code/config.ts +778 -0
- package/src/adapters/claude-code/credentials.ts +199 -0
- package/src/adapters/claude-code/doctor.ts +2557 -0
- package/src/adapters/claude-code/embed-client.ts +617 -0
- package/src/adapters/claude-code/hooks.ts +2240 -0
- package/src/adapters/claude-code/index.ts +224 -0
- package/src/adapters/claude-code/interpret-client.ts +395 -0
- package/src/adapters/claude-code/page-writer.ts +462 -0
- package/src/adapters/claude-code/primacy.ts +162 -0
- package/src/adapters/claude-code/spawn.ts +241 -0
- package/src/adapters/claude-code/standdown.ts +536 -0
- package/src/adapters/claude-code/transcript.ts +661 -0
- package/src/adapters/claude-code/vectors.ts +415 -0
- package/src/adapters/cli/CONTRACT.md +255 -0
- package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
- package/src/adapters/cli/NOTES.md +936 -0
- package/src/adapters/cli/bin/counterparts.ts +74 -0
- package/src/adapters/cli/commands.ts +6095 -0
- package/src/adapters/cli/export.ts +766 -0
- package/src/adapters/cli/index.ts +103 -0
- package/src/adapters/cli/install.ts +670 -0
- package/src/adapters/cli/removal.ts +1186 -0
- package/src/adapters/cli/repair-dates.ts +659 -0
- package/src/adapters/cli/self-page.ts +229 -0
- package/src/adapters/cli/snapshot.ts +279 -0
- package/src/adapters/cli/start-fresh.ts +1228 -0
- package/src/adapters/config-path.ts +342 -0
- package/src/adapters/dashboard/CONTRACT.md +67 -0
- package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
- package/src/adapters/dashboard/NOTES.md +474 -0
- package/src/adapters/dashboard/activity.ts +121 -0
- package/src/adapters/dashboard/ansi.ts +82 -0
- package/src/adapters/dashboard/bin/dashboard.ts +479 -0
- package/src/adapters/dashboard/browse.ts +298 -0
- package/src/adapters/dashboard/identity.ts +182 -0
- package/src/adapters/dashboard/index.ts +183 -0
- package/src/adapters/dashboard/layout.ts +149 -0
- package/src/adapters/dashboard/registries.ts +291 -0
- package/src/adapters/dashboard/resolve.ts +206 -0
- package/src/adapters/dashboard/source.ts +48 -0
- package/src/adapters/dashboard/status.ts +327 -0
- package/src/adapters/dashboard/stories.ts +194 -0
- package/src/adapters/dashboard/web/app.html +1731 -0
- package/src/adapters/dashboard/web/brain.html +463 -0
- package/src/adapters/dashboard/web/fired.ts +31 -0
- package/src/adapters/dashboard/web/flow.ts +457 -0
- package/src/adapters/dashboard/web/narrate.ts +1042 -0
- package/src/adapters/dashboard/web/reveal.ts +135 -0
- package/src/adapters/dashboard/web/server.ts +287 -0
- package/src/adapters/dashboard/web/views.ts +1744 -0
- package/src/adapters/expansions.ts +569 -0
- package/src/adapters/fired.ts +1580 -0
- package/src/adapters/mcp/CONTRACT.md +240 -0
- package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
- package/src/adapters/mcp/NOTES.md +205 -0
- package/src/adapters/mcp/bin/serve.ts +349 -0
- package/src/adapters/mcp/deliberate.ts +619 -0
- package/src/adapters/mcp/index.ts +101 -0
- package/src/adapters/mcp/protocol.ts +170 -0
- package/src/adapters/mcp/server.ts +1740 -0
- package/src/adapters/mcp/stdio.ts +56 -0
- package/src/adapters/mcp/tools.ts +779 -0
- package/src/adapters/scopes.ts +657 -0
- package/src/adapters/sessions.ts +402 -0
- package/src/adapters/snapshots.ts +1069 -0
- package/src/adapters/stance-env.ts +137 -0
- package/src/core/associate/CONTRACT.md +118 -0
- package/src/core/associate/INTERFACE-GAPS.md +173 -0
- package/src/core/associate/NOTES.md +194 -0
- package/src/core/associate/buffer.ts +66 -0
- package/src/core/associate/edges.ts +188 -0
- package/src/core/associate/index.ts +570 -0
- package/src/core/associate/pending.ts +383 -0
- package/src/core/associate/spread.ts +149 -0
- package/src/core/associate/tunables.ts +123 -0
- package/src/core/bridge.ts +272 -0
- package/src/core/briefing.ts +67 -0
- package/src/core/counterpart.ts +3855 -0
- package/src/core/encode/CONTRACT.md +151 -0
- package/src/core/encode/INTERFACE-GAPS.md +135 -0
- package/src/core/encode/NOTES.md +146 -0
- package/src/core/encode/aliases.ts +71 -0
- package/src/core/encode/battery.ts +284 -0
- package/src/core/encode/chunk.ts +265 -0
- package/src/core/encode/emotion.ts +119 -0
- package/src/core/encode/floor.ts +76 -0
- package/src/core/encode/index.ts +100 -0
- package/src/core/encode/precision.ts +162 -0
- package/src/core/encode/preselect.ts +269 -0
- package/src/core/encode/salience.ts +108 -0
- package/src/core/encode/secrets.ts +265 -0
- package/src/core/encode/tunables.ts +99 -0
- package/src/core/encode/types.ts +286 -0
- package/src/core/encode/words.ts +75 -0
- package/src/core/handoff/CONTRACT.md +199 -0
- package/src/core/handoff/INTERFACE-GAPS.md +166 -0
- package/src/core/handoff/NOTES.md +206 -0
- package/src/core/handoff/index.ts +957 -0
- package/src/core/mint.ts +279 -0
- package/src/core/observer.ts +28 -0
- package/src/core/physics/CONTRACT.md +341 -0
- package/src/core/physics/NOTES.md +155 -0
- package/src/core/physics/clock.ts +51 -0
- package/src/core/physics/index.ts +1054 -0
- package/src/core/prospective/CONTRACT.md +137 -0
- package/src/core/prospective/INTERFACE-GAPS.md +112 -0
- package/src/core/prospective/NOTES.md +160 -0
- package/src/core/prospective/derive.ts +188 -0
- package/src/core/prospective/index.ts +1030 -0
- package/src/core/prospective/tunables.ts +72 -0
- package/src/core/prospective/windows.ts +187 -0
- package/src/core/recall/CONTRACT.md +326 -0
- package/src/core/recall/INTERFACE-GAPS.md +163 -0
- package/src/core/recall/NOTES.md +472 -0
- package/src/core/recall/activate.ts +521 -0
- package/src/core/recall/cues.ts +275 -0
- package/src/core/recall/gate.ts +441 -0
- package/src/core/recall/index.ts +692 -0
- package/src/core/recall/probe.ts +239 -0
- package/src/core/recall/reference.ts +201 -0
- package/src/core/recall/render.ts +285 -0
- package/src/core/recall/session.ts +403 -0
- package/src/core/recall/tunables.ts +329 -0
- package/src/core/remember/CONTRACT.md +293 -0
- package/src/core/remember/INTERFACE-GAPS.md +189 -0
- package/src/core/remember/NOTES.md +373 -0
- package/src/core/remember/fallback.ts +452 -0
- package/src/core/remember/index.ts +103 -0
- package/src/core/remember/owner-strike-seam.ts +479 -0
- package/src/core/remember/proposals.ts +609 -0
- package/src/core/remember/spans.ts +1310 -0
- package/src/core/remember/tunables.ts +111 -0
- package/src/core/remember/updates.ts +198 -0
- package/src/core/retrieval.ts +96 -0
- package/src/core/revision.ts +441 -0
- package/src/core/schemas/CONTRACT.md +190 -0
- package/src/core/schemas/INTERFACE-GAPS.md +172 -0
- package/src/core/schemas/NOTES.md +260 -0
- package/src/core/schemas/aliases.ts +160 -0
- package/src/core/schemas/index.ts +1459 -0
- package/src/core/schemas/tunables.ts +44 -0
- package/src/core/schemas/types.ts +387 -0
- package/src/core/self/CONTRACT.md +459 -0
- package/src/core/self/INTERFACE-GAPS.md +284 -0
- package/src/core/self/NOTES.md +1057 -0
- package/src/core/self/briefing.ts +980 -0
- package/src/core/self/episodes.ts +483 -0
- package/src/core/self/freeze.ts +103 -0
- package/src/core/self/identity.ts +604 -0
- package/src/core/self/index.ts +2130 -0
- package/src/core/self/journal-file.ts +760 -0
- package/src/core/self/page.ts +404 -0
- package/src/core/self/tunables.ts +244 -0
- package/src/core/self/writer.ts +714 -0
- package/src/core/sleep/CONTRACT.md +298 -0
- package/src/core/sleep/INTERFACE-GAPS.md +262 -0
- package/src/core/sleep/NOTES.md +770 -0
- package/src/core/sleep/briefing.ts +86 -0
- package/src/core/sleep/consolidate.ts +241 -0
- package/src/core/sleep/cycle.ts +598 -0
- package/src/core/sleep/decay.ts +237 -0
- package/src/core/sleep/dedup.ts +373 -0
- package/src/core/sleep/index.ts +112 -0
- package/src/core/sleep/log.ts +116 -0
- package/src/core/sleep/markers.ts +164 -0
- package/src/core/sleep/prune.ts +170 -0
- package/src/core/sleep/strength-cache.ts +176 -0
- package/src/core/sleep/tunables.ts +135 -0
- package/src/core/sleep/types.ts +542 -0
- package/src/core/store/CONTRACT.md +446 -0
- package/src/core/store/NOTES.md +1068 -0
- package/src/core/store/cache.ts +709 -0
- package/src/core/store/db.ts +275 -0
- package/src/core/store/errors.ts +134 -0
- package/src/core/store/index.ts +2450 -0
- package/src/core/store/operational.ts +610 -0
- package/src/core/store/owner-op-seam.ts +428 -0
- package/src/core/store/paths.ts +494 -0
- package/src/core/store/prose.ts +165 -0
- package/src/core/store/render.ts +87 -0
- package/src/core/store/walk-seam.ts +78 -0
- package/src/core/types.ts +68 -0
- package/tools/install-loop/run.sh +1063 -0
|
@@ -0,0 +1,1580 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fired` — which mechanisms have actually fired, and which have gone quiet.
|
|
3
|
+
*
|
|
4
|
+
* **Why it exists.** Constitution 11: every mechanism is verified in real use
|
|
5
|
+
* after it lands, done means seen firing rather than merged, a silent one is
|
|
6
|
+
* diagnosed before anyone considers removing it — and "the system itself shows
|
|
7
|
+
* what fired and what did not". In September 2026 several mechanisms were
|
|
8
|
+
* merged, tested and then never fired once on the live store, and no surface
|
|
9
|
+
* said so. The read-only inventory of 2026-09-17
|
|
10
|
+
* (`docs/mechanism-inventory-2026-09-17.md`) counted forty mechanisms:
|
|
11
|
+
* twenty-four seen firing, ten never, six that cannot be told either way. This
|
|
12
|
+
* module is the first version of the view its §5 proposed, built ONLY from rows
|
|
13
|
+
* the store already holds.
|
|
14
|
+
*
|
|
15
|
+
* **It reads and never writes.** Every call below is a read; the caller hands in
|
|
16
|
+
* a store it already opened, and every caller in this tree opens it in observer
|
|
17
|
+
* stance. Nothing here appends an event, mints a directory or touches box 3.
|
|
18
|
+
*
|
|
19
|
+
* **Where it sits.** Beside `sessions.ts` and `scopes.ts`, for the reason those
|
|
20
|
+
* two are there: three adapters need it — the console's `fired` command,
|
|
21
|
+
* `claude-code/doctor.ts`'s finding and the dashboard's health panel — and
|
|
22
|
+
* `mcp/INTERFACE-GAPS.md` §7 keeps adapters as leaves that never import each
|
|
23
|
+
* other. It DOES import `dashboard/registries.ts`, which is a registry rather
|
|
24
|
+
* than a view: that file exists precisely so the list of durable event names
|
|
25
|
+
* cannot be copied without going stale, and a second copy here would be the
|
|
26
|
+
* staleness it exists to prevent.
|
|
27
|
+
*
|
|
28
|
+
* **Three things shape the reading.**
|
|
29
|
+
*
|
|
30
|
+
* 1. **One pass over the log, not one query per mechanism.** `Store` offers no
|
|
31
|
+
* GROUP BY, so the events are read once — ascending, as `eventLog` returns
|
|
32
|
+
* them — and grouped here. A read that hits its ceiling says so and reports
|
|
33
|
+
* its totals as a floor rather than as a number.
|
|
34
|
+
* 2. **Windows are CALENDAR days, UTC.** The lived clock is advanced by the
|
|
35
|
+
* worker and has run seven lived days across fifteen calendar ones on the
|
|
36
|
+
* owner's own store, so a lived-day window would silently drop rows. The
|
|
37
|
+
* `sinceDay` bound is used only to keep the SQL cheap; a lived day is never
|
|
38
|
+
* longer than a calendar day, so it cannot cut a row inside the window.
|
|
39
|
+
* 3. **Absence is a fact, never a formatting hint.** A mechanism with no
|
|
40
|
+
* durable evidence is `blind` and says which row would fix it; a stood-down
|
|
41
|
+
* one is `disabled` and names the decision; one retired with a phase of the
|
|
42
|
+
* run is `retired`. None of the three is silence, and none is a fault.
|
|
43
|
+
* 4. **What was PREVENTED is read, not only what happened** (2026-09-20, E2).
|
|
44
|
+
* Until now a mechanism that was stopped at every attempt read exactly like
|
|
45
|
+
* one that had nothing to do: both said `never`. A mechanism whose refusals
|
|
46
|
+
* are durable — in its own row, or in another row that names them — and
|
|
47
|
+
* which did not fire inside the window is `blocked`, and the line says by
|
|
48
|
+
* what. `REFUSAL_READERS` is still the only place a refusal column comes
|
|
49
|
+
* from, and it still reads only fields a writer already fills.
|
|
50
|
+
*/
|
|
51
|
+
import { TUNABLES as ENCODE } from "../core/encode/tunables.js";
|
|
52
|
+
import { dateOf } from "../core/store/index.js";
|
|
53
|
+
import type { EventRow, Store } from "../core/store/index.js";
|
|
54
|
+
import type { DurableEventName } from "./dashboard/registries.js";
|
|
55
|
+
|
|
56
|
+
/** The window every count on this page is measured over. Seven CALENDAR days,
|
|
57
|
+
* inclusive of today — today and the six before it. */
|
|
58
|
+
export const FIRED_DAYS = 7;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The ceiling on the one event read. The owner's store held roughly twenty
|
|
62
|
+
* thousand rows on day 191 of the parallel run, so this is an order of magnitude
|
|
63
|
+
* of headroom; a read that reaches it is reported as a floor rather than as a
|
|
64
|
+
* number, because a confident wrong count is the one thing a diagnostic may
|
|
65
|
+
* never produce.
|
|
66
|
+
*/
|
|
67
|
+
export const EVENT_CEILING = 200_000;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The ceiling on the table probes' id scan. The probes cost a few queries per
|
|
71
|
+
* memory — `Store` has no aggregate over `edges`, `prospective` or `versions` —
|
|
72
|
+
* so the scan is bounded, and one that reaches this says so.
|
|
73
|
+
*/
|
|
74
|
+
export const PROBE_CEILING = 50_000;
|
|
75
|
+
|
|
76
|
+
// ── the vocabulary ──────────────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* What one mechanism's row says about it.
|
|
80
|
+
*
|
|
81
|
+
* - `firing` — a row landed inside the last seven days.
|
|
82
|
+
* - `quiet` — it has fired before, and not in the last seven days. The state
|
|
83
|
+
* worth reading first, because it is the one that says something changed.
|
|
84
|
+
* - `blocked` — it did not fire inside the window, and something durably said
|
|
85
|
+
* why: a refusal landed instead. The difference between "never needed" and
|
|
86
|
+
* "stopped every time", which nothing could tell before 2026-09-20.
|
|
87
|
+
* - `never` — durable evidence exists and has never carried a single row.
|
|
88
|
+
* - `new` — never fired, but its evidence is younger than the window, so there
|
|
89
|
+
* has not yet been time for it to be a worry.
|
|
90
|
+
* - `blind` — no durable evidence exists at all. The row says which row would
|
|
91
|
+
* fix it. NOT a synonym for silent: a blind mechanism may be running fine.
|
|
92
|
+
* - `disabled` — stood down by a named decision (Amendment 15), not a fault.
|
|
93
|
+
* - `retired` — a phase of the run ended and took the mechanism with it.
|
|
94
|
+
*/
|
|
95
|
+
export const FIRED_STATES = [
|
|
96
|
+
"quiet",
|
|
97
|
+
"blocked",
|
|
98
|
+
"never",
|
|
99
|
+
"blind",
|
|
100
|
+
"firing",
|
|
101
|
+
"new",
|
|
102
|
+
"disabled",
|
|
103
|
+
"retired",
|
|
104
|
+
] as const;
|
|
105
|
+
export type FiredState = (typeof FIRED_STATES)[number];
|
|
106
|
+
|
|
107
|
+
/** The order the report and every renderer print the groups in: SILENT FIRST.
|
|
108
|
+
* A view whose first screen is everything that worked is one nobody scrolls. */
|
|
109
|
+
export const STATE_ORDER: readonly FiredState[] = [
|
|
110
|
+
"quiet",
|
|
111
|
+
"blocked",
|
|
112
|
+
"never",
|
|
113
|
+
"blind",
|
|
114
|
+
"firing",
|
|
115
|
+
"new",
|
|
116
|
+
"disabled",
|
|
117
|
+
"retired",
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
/** The one-line gloss each state carries wherever it is printed. */
|
|
121
|
+
export const STATE_MEANING: Record<FiredState, string> = {
|
|
122
|
+
firing: "a row landed in the last 7 days",
|
|
123
|
+
quiet: "it has fired before, but not in the last 7 days",
|
|
124
|
+
blocked: "it did not fire this week, and a durable row says what stopped it",
|
|
125
|
+
never: "the evidence exists and has never carried a row",
|
|
126
|
+
new: "never fired, and its evidence is younger than the window — not yet a worry",
|
|
127
|
+
blind: "nothing durable records it, so firing and silence read alike",
|
|
128
|
+
disabled: "stood down by a named decision, not a fault",
|
|
129
|
+
retired: "a phase of the run ended and took it with it",
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The table reads that stand in for a mechanism with no event of its own — the
|
|
134
|
+
* five the inventory's §5(b) named, split where one table answers two questions.
|
|
135
|
+
* `versions:<reason>` is a template because the reason is the axis.
|
|
136
|
+
*/
|
|
137
|
+
export type ProbeId =
|
|
138
|
+
| "edges"
|
|
139
|
+
| "prospective.armed"
|
|
140
|
+
| "prospective.fired"
|
|
141
|
+
| "protected"
|
|
142
|
+
| "removals"
|
|
143
|
+
| `versions:${string}`;
|
|
144
|
+
|
|
145
|
+
export type Evidence =
|
|
146
|
+
| { readonly kind: "event"; readonly names: readonly DurableEventName[] }
|
|
147
|
+
/** `undated`: the one line to print when the probe yields a count and no date
|
|
148
|
+
* at all — a column with no history is blind however many rows it holds. */
|
|
149
|
+
| { readonly kind: "probe"; readonly probe: ProbeId; readonly undated?: string }
|
|
150
|
+
| { readonly kind: "none"; readonly reason: string };
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* WHERE A MECHANISM'S REFUSALS LIVE, when they are not in its own row (E2).
|
|
154
|
+
*
|
|
155
|
+
* Four of the night's mechanisms succeed under one name and are prevented under
|
|
156
|
+
* another: promotion's successes are `band.promoted` and its refusals ride the
|
|
157
|
+
* cycle row, the spawn seam's start and its refusals are three separate names.
|
|
158
|
+
* Naming the refusal rows here lets a row read "blocked, by X" without the
|
|
159
|
+
* refusal rows being mistaken for firings — `total` and `inWindow` still count
|
|
160
|
+
* only the EVIDENCE names.
|
|
161
|
+
*/
|
|
162
|
+
export interface RefusalSource {
|
|
163
|
+
readonly names: readonly DurableEventName[];
|
|
164
|
+
/**
|
|
165
|
+
* Take only the reasons under this prefix, and strip it for display. The
|
|
166
|
+
* cycle row carries four phases' refusals in one map, keyed `<phase>/<reason>`
|
|
167
|
+
* (`sleep/cycle.ts`), so one row answers for four mechanisms without any of
|
|
168
|
+
* them claiming another's.
|
|
169
|
+
*/
|
|
170
|
+
readonly under?: string;
|
|
171
|
+
/**
|
|
172
|
+
* THE ALLOW-LIST OF REAL GATES, and the most important field here.
|
|
173
|
+
*
|
|
174
|
+
* A namespace is not a refusal channel. Physics' `blockedBy` vocabularies are
|
|
175
|
+
* mostly **"not yet"** — `base-below-identity-threshold`, `dwell-too-short`,
|
|
176
|
+
* `above-floor`, `below-tau` — which describe the ordinary condition of
|
|
177
|
+
* nearly every memory on every healthy night and scale with store size ×
|
|
178
|
+
* nights. Reading a namespace wholesale made a store where NOTHING is wrong
|
|
179
|
+
* report `BLOCKED prune … dwell-too-short ×240`, permanently, in the first
|
|
180
|
+
* section printed. That is the `journal ×14` false alarm this field exists to
|
|
181
|
+
* stop, one namespace over, and it was found by running seven real boundaries
|
|
182
|
+
* over forty ordinary memories rather than by reading.
|
|
183
|
+
*
|
|
184
|
+
* So a reason counts as a refusal only if it is named here. The test is
|
|
185
|
+
* whether a NAMED RULE turned away a candidate that otherwise qualified —
|
|
186
|
+
* `protected` is the owner saying no; `dwell-too-short` is arithmetic saying
|
|
187
|
+
* not yet. A mechanism with no such reason in its vocabulary gets no refusal
|
|
188
|
+
* column at all, which is the honest answer rather than an empty one.
|
|
189
|
+
*/
|
|
190
|
+
readonly only?: readonly string[];
|
|
191
|
+
/**
|
|
192
|
+
* The date this refusal CHANNEL began carrying data, when it is recent.
|
|
193
|
+
*
|
|
194
|
+
* `wentBlocked` compares two windows, and a channel that did not exist in the
|
|
195
|
+
* older one makes a schema change look like a regression — "your prune phase
|
|
196
|
+
* stopped working on deploy day" when all that happened is that the rows
|
|
197
|
+
* started carrying a field. The state still reads `blocked`, which is true;
|
|
198
|
+
* only the WEEK-OVER-WEEK claim is withheld until both windows can answer.
|
|
199
|
+
*/
|
|
200
|
+
readonly since?: string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface Mechanism {
|
|
204
|
+
/** Stable machine name — the `--json` key, and what a test pins. */
|
|
205
|
+
readonly id: string;
|
|
206
|
+
/**
|
|
207
|
+
* WHAT IT DOES, in words a non-engineer reads once: "the session is asked to
|
|
208
|
+
* write its own memories", never "adapter.ask". The dotted name is evidence,
|
|
209
|
+
* printed beside it; it is not the label.
|
|
210
|
+
*/
|
|
211
|
+
readonly label: string;
|
|
212
|
+
/** Where the code lives, for the reader who wants to go and look. */
|
|
213
|
+
readonly module: string;
|
|
214
|
+
readonly evidence: Evidence;
|
|
215
|
+
/** Rows that say this mechanism was PREVENTED, when they are not its own. */
|
|
216
|
+
readonly refusals?: RefusalSource;
|
|
217
|
+
/**
|
|
218
|
+
* The calendar date the EVIDENCE was added, when it is recent. A mechanism
|
|
219
|
+
* that has never fired but whose row is three days old is `new`, not `never`:
|
|
220
|
+
* there has not been time yet, and grading it as a fault is how a view teaches
|
|
221
|
+
* its reader to ignore it.
|
|
222
|
+
*/
|
|
223
|
+
readonly since?: string;
|
|
224
|
+
/** A named stand-down, with its reason. Amendment 15 working, not a fault. */
|
|
225
|
+
readonly disabled?: string;
|
|
226
|
+
/** Retired with a phase of the run, with the phase named. */
|
|
227
|
+
readonly retired?: string;
|
|
228
|
+
/**
|
|
229
|
+
* Durable event names this row ACCOUNTS FOR in the coverage test, when they
|
|
230
|
+
* are not simply its own evidence. A blind mechanism can still be the row that
|
|
231
|
+
* speaks for a name — the spawn seam's three prove a failure and cannot prove
|
|
232
|
+
* a start — and a name nobody accounts for is the gap the test catches.
|
|
233
|
+
*/
|
|
234
|
+
readonly covers?: readonly DurableEventName[];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ── the registry ────────────────────────────────────────────────────────────
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* THE MECHANISMS, from the inventory's §2 table. Each row is something the
|
|
241
|
+
* design claims happens, and its evidence is whatever the store durably holds
|
|
242
|
+
* about it TODAY. Nothing here is aspirational: a mechanism whose evidence does
|
|
243
|
+
* not exist yet says so and names the row that would fix it, which is the blind
|
|
244
|
+
* list of §4 rendered rather than filed.
|
|
245
|
+
*
|
|
246
|
+
* Two rows of that table are deliberately absent: novelty (#9) and footnotes
|
|
247
|
+
* (#16) are sub-readings of the gate and of the surfacing decision, counted
|
|
248
|
+
* inside the same rows, and listing them again would double-count the log.
|
|
249
|
+
*/
|
|
250
|
+
export const MECHANISMS: readonly Mechanism[] = [
|
|
251
|
+
// ── what comes in ────────────────────────────────────────────────────────
|
|
252
|
+
{
|
|
253
|
+
id: "capture",
|
|
254
|
+
label: "the conversation is captured when a session pauses or ends",
|
|
255
|
+
module: "remember/spans",
|
|
256
|
+
evidence: { kind: "event", names: ["adapter.boundary"] },
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: "ask",
|
|
260
|
+
label: "the session is asked to write its own memories before it stops",
|
|
261
|
+
module: "claude-code/hooks.ts",
|
|
262
|
+
evidence: { kind: "event", names: ["adapter.ask"] },
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: "ask-two-part",
|
|
266
|
+
label: "the older two-part version of that ask — one for the chapter, one for the memories",
|
|
267
|
+
module: "claude-code/hooks.ts",
|
|
268
|
+
evidence: { kind: "event", names: ["adapter.authorship.ask", "adapter.episode.ask"] },
|
|
269
|
+
retired:
|
|
270
|
+
"replaced by a single ask on 2026-09-04; the days recorded under these names stay readable",
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
id: "deposit",
|
|
274
|
+
label: "a memory the session wrote for itself passed the gates and landed",
|
|
275
|
+
module: "mcp/ → encode/battery.ts",
|
|
276
|
+
evidence: { kind: "event", names: ["gate.deposit"] },
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
id: "journal-chapter",
|
|
280
|
+
label: "the session wrote a chapter of its own journal",
|
|
281
|
+
module: "mcp/chapter → self/",
|
|
282
|
+
evidence: { kind: "probe", probe: "versions:episode-chapter" },
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
id: "sweep-gate",
|
|
286
|
+
label: "the crash fallback checked whether a session died with something unsaid",
|
|
287
|
+
module: "remember/fallback.ts",
|
|
288
|
+
evidence: { kind: "event", names: ["sweep.gate"] },
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
id: "sweep-wake",
|
|
292
|
+
label: "that fallback was woken as me before it read a transcript",
|
|
293
|
+
module: "core/counterpart.ts",
|
|
294
|
+
evidence: { kind: "event", names: ["sweep.wake"] },
|
|
295
|
+
since: "2026-09-17",
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
id: "chunk-gate",
|
|
299
|
+
label: "a swept fragment met the gate battery and was scored at the door",
|
|
300
|
+
module: "encode/battery.ts",
|
|
301
|
+
evidence: { kind: "event", names: ["gate.chunk"] },
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
id: "gate-refusal",
|
|
305
|
+
label: "the gate battery turned a proposal away",
|
|
306
|
+
module: "encode/battery.ts",
|
|
307
|
+
evidence: {
|
|
308
|
+
kind: "none",
|
|
309
|
+
reason:
|
|
310
|
+
"refusals are counted inside the gate rows, and that count has been empty in every row ever written — so a gate that has never had to say no and a gate nothing reaches read exactly alike. Only a deliberate probe deposit separates them.",
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: "emotion",
|
|
315
|
+
label: "how something felt is read at the door and used to weight what comes back",
|
|
316
|
+
module: "encode/, recall/",
|
|
317
|
+
evidence: {
|
|
318
|
+
kind: "none",
|
|
319
|
+
reason:
|
|
320
|
+
"the gate records the channel as off in every row; nothing measures a classifier that does not run.",
|
|
321
|
+
},
|
|
322
|
+
// READ, not retyped: the stand-down is a tunable, and a view that hard-coded
|
|
323
|
+
// it would go on saying `disabled` the day the owner turns the classifier on.
|
|
324
|
+
...(ENCODE.EMOTION_CLASSIFIER_ENABLED
|
|
325
|
+
? {}
|
|
326
|
+
: {
|
|
327
|
+
disabled: `the classifier ships off until it clears its precision bar of ${String(
|
|
328
|
+
ENCODE.EMOTION_CLASSIFIER_PRECISION_BAR,
|
|
329
|
+
)} (encode/tunables.ts) — a named decision, not a fault`,
|
|
330
|
+
}),
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
id: "salience",
|
|
334
|
+
label: "every memory is scored for novelty, relevance, feeling and usefulness as it is written",
|
|
335
|
+
module: "encode/",
|
|
336
|
+
evidence: {
|
|
337
|
+
kind: "none",
|
|
338
|
+
reason:
|
|
339
|
+
"the scores are columns on each memory, not rows in the log, so the store can say what every memory scored and never when one was scored.",
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
id: "entity-birth",
|
|
344
|
+
label: "a name mentioned in passing becomes someone the system knows about",
|
|
345
|
+
module: "schemas/",
|
|
346
|
+
evidence: {
|
|
347
|
+
kind: "none",
|
|
348
|
+
reason:
|
|
349
|
+
"a birth shows only as another entity in the store, and a refusal shows nowhere at all — the reasons live in an in-process ring that dies with the hook.",
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
id: "accommodation",
|
|
354
|
+
label: "something the owner declared outright replaced what had been inferred",
|
|
355
|
+
module: "schemas/",
|
|
356
|
+
evidence: { kind: "probe", probe: "versions:replaced-by-declaration" },
|
|
357
|
+
},
|
|
358
|
+
|
|
359
|
+
// ── what comes back ──────────────────────────────────────────────────────
|
|
360
|
+
{
|
|
361
|
+
id: "recall-decision",
|
|
362
|
+
label: "each turn decides what comes to mind and what stays quiet",
|
|
363
|
+
module: "recall/",
|
|
364
|
+
evidence: { kind: "event", names: ["recall.decision"] },
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
id: "recall-injected",
|
|
368
|
+
label: "what came to mind was handed to the host for the model to read",
|
|
369
|
+
module: "claude-code/hooks.ts",
|
|
370
|
+
evidence: { kind: "event", names: ["adapter.recall"] },
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
id: "credit",
|
|
374
|
+
label: "memories the reply actually used are credited, so using one strengthens it",
|
|
375
|
+
module: "recall/, physics/",
|
|
376
|
+
evidence: { kind: "event", names: ["recall.credit"] },
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
id: "gate-session",
|
|
380
|
+
label: "what a session has already been shown, so it is not shown the same thing twice",
|
|
381
|
+
module: "recall/session.ts",
|
|
382
|
+
evidence: {
|
|
383
|
+
kind: "none",
|
|
384
|
+
reason:
|
|
385
|
+
"the table is written every turn and read by no surface at all — not this view, not the dashboard, not the daily. Nothing new is needed; the rows that exist simply have to be rendered.",
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
// Durable since 2026-09-20 (E2). The row carries what was asked as shapes
|
|
390
|
+
// and sizes — never the question — how much came back, and every verdict
|
|
391
|
+
// that kept something out, which is the refusal column below.
|
|
392
|
+
id: "deliberate-recall",
|
|
393
|
+
label: "the session went looking for a memory on purpose and opened it in full",
|
|
394
|
+
module: "mcp/deliberate.ts",
|
|
395
|
+
evidence: { kind: "event", names: ["mcp.recall"] },
|
|
396
|
+
since: "2026-09-20",
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
id: "association",
|
|
400
|
+
label: "two memories that came to mind together got wired to each other",
|
|
401
|
+
module: "associate/",
|
|
402
|
+
evidence: {
|
|
403
|
+
kind: "probe",
|
|
404
|
+
probe: "edges",
|
|
405
|
+
undated: "the links carry no date at all, so nothing says when one was last made.",
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
// The links table above says links EXIST; it could not say one was made this
|
|
410
|
+
// week, which is how this mechanism wrote nothing for two weeks unseen. Since
|
|
411
|
+
// 2026-09-17 the boundary's worker leaves a row each time it saves what the
|
|
412
|
+
// session's hooks noticed and left on disk for it.
|
|
413
|
+
id: "association-saved",
|
|
414
|
+
label: "the links noticed during a session were written down by the boundary's worker",
|
|
415
|
+
module: "associate/",
|
|
416
|
+
evidence: { kind: "event", names: ["associate.flush"] },
|
|
417
|
+
since: "2026-09-17",
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
id: "spreading",
|
|
421
|
+
label: "remembering one thing pulls its neighbours with it",
|
|
422
|
+
module: "associate/spread.ts",
|
|
423
|
+
evidence: {
|
|
424
|
+
kind: "none",
|
|
425
|
+
reason:
|
|
426
|
+
"the turn's record counts what surfaced but never which channel found it; a `channelCounts` field on the decision row that already exists would fix it without a new name.",
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
id: "temporal-channel",
|
|
431
|
+
label: "what happened around the same time is treated as a cue",
|
|
432
|
+
module: "core/retrieval.ts",
|
|
433
|
+
evidence: {
|
|
434
|
+
kind: "none",
|
|
435
|
+
reason:
|
|
436
|
+
"the same gap as spreading activation: folded into the turn's totals with no breakdown.",
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
id: "confidentiality",
|
|
441
|
+
label: "something confidential is held back rather than surfaced",
|
|
442
|
+
module: "recall/gate.ts",
|
|
443
|
+
evidence: {
|
|
444
|
+
kind: "none",
|
|
445
|
+
reason:
|
|
446
|
+
"the gate reports itself clear inside the deposit and turn records and is never broken out, so a withholding that happened and one that never had to are the same absence.",
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
|
|
450
|
+
// ── what the night does ──────────────────────────────────────────────────
|
|
451
|
+
{
|
|
452
|
+
id: "sleep-cycle",
|
|
453
|
+
label: "the consolidation cycle ran, with every phase by name",
|
|
454
|
+
module: "sleep/, bin/runner.ts",
|
|
455
|
+
evidence: { kind: "event", names: ["sleep.cycle"] },
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
id: "decay",
|
|
459
|
+
label: "memories weaken with time and drop to a lower band",
|
|
460
|
+
module: "physics/, sleep/decay.ts",
|
|
461
|
+
evidence: { kind: "event", names: ["band.transition"] },
|
|
462
|
+
// NO REFUSAL COLUMN, deliberately. Every entry in `DECAY_SKIPS` is a
|
|
463
|
+
// candidate filter — archived, removed, journal, identity-band,
|
|
464
|
+
// reinforced-today, at-floor, under-audit, unchanged — and not one of them
|
|
465
|
+
// is a gate saying no to a row it considered. Decay is arithmetic; there is
|
|
466
|
+
// nothing here for it to be blocked BY.
|
|
467
|
+
},
|
|
468
|
+
// The phases whose SUCCESS has always been durable and whose REFUSALS were an
|
|
469
|
+
// in-process ring until 2026-09-20 (E2).
|
|
470
|
+
//
|
|
471
|
+
// **A NAMESPACE IS NOT A REFUSAL CHANNEL, AND THAT COST TWO ROUNDS TO LEARN.**
|
|
472
|
+
// The first attempt read each phase's whole `skipped` map, which mixes
|
|
473
|
+
// candidate filters (`journal`, `archived`, `schema`) with refusals, and
|
|
474
|
+
// would have reported `blocked, most often journal ×14` every week. The
|
|
475
|
+
// second read only each phase's own refusal NAMESPACE (`promotion:`,
|
|
476
|
+
// `blocked:`, `left-alone:`) — and an adversarial review ran seven real
|
|
477
|
+
// boundaries over forty ordinary memories and found the same false alarm
|
|
478
|
+
// waiting there: `BLOCKED prune … dwell-too-short ×240` on a store where
|
|
479
|
+
// nothing whatever is wrong, because physics' refusal vocabulary is itself
|
|
480
|
+
// mostly "not yet".
|
|
481
|
+
//
|
|
482
|
+
// So every reason is classified by hand below, and only the GATES are read.
|
|
483
|
+
// The test: did a NAMED RULE turn away a candidate that otherwise qualified?
|
|
484
|
+
{
|
|
485
|
+
// NO REFUSAL COLUMN. `PromotionReason` is `already-identity` (it is already
|
|
486
|
+
// there — nothing to do), `base-below-identity-threshold` and
|
|
487
|
+
// `insufficient-distinct-days` (not yet). Not one of the three is a gate:
|
|
488
|
+
// promotion is a threshold, and a memory under a threshold has not been
|
|
489
|
+
// refused, it has not arrived. `docs/promotion-diagnosis-2026-09-17.md`'s
|
|
490
|
+
// real question — "did the phase even REACH these rows" — is answered by
|
|
491
|
+
// `budgetExhausted` and `skippedForBudget` on the same cycle row, which is
|
|
492
|
+
// where it belongs.
|
|
493
|
+
id: "promotion",
|
|
494
|
+
label: "a memory reinforced over several days is promoted into identity",
|
|
495
|
+
module: "sleep/consolidate.ts",
|
|
496
|
+
evidence: { kind: "event", names: ["band.promoted"] },
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
// TWO GATES out of six. `declared-revision-never-merged` and
|
|
500
|
+
// `revision-successor-never-merged` are rules refusing a merge that the
|
|
501
|
+
// similarity would otherwise have made — the owner declared a revision, and
|
|
502
|
+
// a revision is not a duplicate. The rest are not: `below-tau` and
|
|
503
|
+
// `identical-content-hash`/`cosine-at-or-above-tau` are measurements, and
|
|
504
|
+
// `no-similarity-supplied` is the embedder being off, which fires for EVERY
|
|
505
|
+
// pair on the default configuration and already has its own amber on
|
|
506
|
+
// doctor's Embedder line.
|
|
507
|
+
id: "dedup",
|
|
508
|
+
label: "a duplicate is merged into the memory it duplicates",
|
|
509
|
+
module: "sleep/dedup.ts",
|
|
510
|
+
evidence: { kind: "event", names: ["memory.merged"] },
|
|
511
|
+
refusals: {
|
|
512
|
+
names: ["sleep.cycle"],
|
|
513
|
+
under: "dedup/left-alone:",
|
|
514
|
+
only: ["declared-revision-never-merged", "revision-successor-never-merged"],
|
|
515
|
+
since: "2026-09-20",
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
// TWO GATES out of five. `protected` is the owner saying this may never be
|
|
520
|
+
// forgotten; `in-live-revision-chain` is a live chain holding a row that
|
|
521
|
+
// the floor would otherwise have let go. Both are a rule refusing a memory
|
|
522
|
+
// that qualified. `above-floor`, `dwell-too-short` and `band-not-episodic`
|
|
523
|
+
// are the ordinary condition of almost every memory on almost every night —
|
|
524
|
+
// the reviewer measured `dwell-too-short ×240` on a healthy forty-memory
|
|
525
|
+
// store after seven boundaries.
|
|
526
|
+
id: "prune",
|
|
527
|
+
label: "a memory that has sat at the floor long enough is let go",
|
|
528
|
+
module: "sleep/prune.ts",
|
|
529
|
+
evidence: { kind: "event", names: ["memory.pruned"] },
|
|
530
|
+
refusals: {
|
|
531
|
+
names: ["sleep.cycle"],
|
|
532
|
+
under: "prune/blocked:",
|
|
533
|
+
only: ["protected", "in-live-revision-chain"],
|
|
534
|
+
since: "2026-09-20",
|
|
535
|
+
},
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
id: "revision",
|
|
539
|
+
label: "a belief took a credited challenge and was revised under the pressure",
|
|
540
|
+
module: "schemas/index.ts",
|
|
541
|
+
evidence: { kind: "event", names: ["revision.pressure"] },
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
// NARROWED 2026-09-20 (E2). This used to name all four. Promotion, prune
|
|
545
|
+
// and dedup now carry their refusals on the rows above, read out of the
|
|
546
|
+
// cycle row's per-phase skip map under each phase's own reason namespace.
|
|
547
|
+
// Revision is the one left: its refusals never reach the cycle, because the
|
|
548
|
+
// pressure arm runs in `schemas/` off a credited challenge and not in a
|
|
549
|
+
// sleep phase at all.
|
|
550
|
+
id: "night-refusals",
|
|
551
|
+
label: "why a belief was NOT revised under a challenge it took",
|
|
552
|
+
module: "schemas/index.ts",
|
|
553
|
+
evidence: {
|
|
554
|
+
kind: "none",
|
|
555
|
+
reason:
|
|
556
|
+
"the credit is durable and the refusal is an in-process ring (`schemas/index.ts:682`), so a belief that refused a challenge and one that was never challenged read alike. A `refused` map on the `revision.pressure` row that already exists would fix it.",
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
id: "gist",
|
|
561
|
+
label: "the gist of many episodes is distilled into one lasting memory",
|
|
562
|
+
module: "—",
|
|
563
|
+
evidence: { kind: "none", reason: "not built yet; the storage spec marks it thin." },
|
|
564
|
+
},
|
|
565
|
+
|
|
566
|
+
// ── the self ─────────────────────────────────────────────────────────────
|
|
567
|
+
{
|
|
568
|
+
id: "briefing",
|
|
569
|
+
label: "the waking briefing was composed — who I am, what is live, what is owed",
|
|
570
|
+
module: "self/briefing.ts",
|
|
571
|
+
evidence: { kind: "event", names: ["self.briefing"] },
|
|
572
|
+
},
|
|
573
|
+
// The self page (2026-09-18, S1). ONE row: the accepted writes are the
|
|
574
|
+
// evidence, and the refusals are accounted for here rather than as a
|
|
575
|
+
// mechanism of their own — a cap turning a page away is this mechanism
|
|
576
|
+
// working, not a second one.
|
|
577
|
+
{
|
|
578
|
+
id: "self-page",
|
|
579
|
+
label: "the written page of who I am was amended — by me, by the owner, or by the nightly writer",
|
|
580
|
+
module: "self/page.ts",
|
|
581
|
+
evidence: { kind: "event", names: ["self.page.revised"] },
|
|
582
|
+
covers: ["self.page.refused"],
|
|
583
|
+
since: "2026-09-18",
|
|
584
|
+
},
|
|
585
|
+
// The nightly writer (2026-09-20, S2) is its own row and not a `covers` on the
|
|
586
|
+
// one above, because the two answer different questions. `self-page` asks "has
|
|
587
|
+
// the page ever been amended", and a page the owner typed makes it green
|
|
588
|
+
// forever; this asks "did last night happen", which is the question a page
|
|
589
|
+
// that has stopped growing is the symptom of. A night that read the day and
|
|
590
|
+
// had nothing to say still fires this row — that is the mechanism working.
|
|
591
|
+
//
|
|
592
|
+
// **NO `refusals` CHANNEL, on purpose** (checked against E2, 2026-09-20).
|
|
593
|
+
// This mechanism has plenty of named skips — `no-previous-day`,
|
|
594
|
+
// `already-claimed`, `asks-spent`, `no-memories`, `off`, and the two durable
|
|
595
|
+
// deferrals `no-room` and `scope-question` — and almost none of them is a
|
|
596
|
+
// GATE by the test `RefusalSource.only` sets. They are the ordinary condition
|
|
597
|
+
// of most of every day: after the first ask, `already-claimed` is what a
|
|
598
|
+
// healthy store says at every session start until midnight. Declaring them
|
|
599
|
+
// would reproduce the `dwell-too-short ×240` false alarm one namespace over.
|
|
600
|
+
// The one that is arguably a real gate — `no-room`, the host's ceiling
|
|
601
|
+
// turning away a block that qualified — already has a louder and better-aimed
|
|
602
|
+
// surface: doctor's Page writer line goes amber after two owed days and names
|
|
603
|
+
// `injectionBudgetBytes` in its fix. A second surface saying `blocked` for
|
|
604
|
+
// ever on a store with a tight ceiling would be the duplication E2's own
|
|
605
|
+
// review warned about.
|
|
606
|
+
{
|
|
607
|
+
id: "page-writer",
|
|
608
|
+
label: "the day just lived was read back and my page was offered a revision",
|
|
609
|
+
module: "self/writer.ts",
|
|
610
|
+
evidence: { kind: "event", names: ["self.page.writer.ran"] },
|
|
611
|
+
since: "2026-09-20",
|
|
612
|
+
},
|
|
613
|
+
// The per-directory handoff (2026-09-20, E1). TWO rows, for the reason the
|
|
614
|
+
// snapshot pair has two: "a session left one" and "a session was handed one"
|
|
615
|
+
// answer different questions, and the second is the one that goes quiet first
|
|
616
|
+
// — a pointer that stops being delivered (an expiry nobody meant, a budget
|
|
617
|
+
// with no room) leaves the writing row firing and the owner none the wiser.
|
|
618
|
+
// The refusals ride with the writing, because a cap turning a handoff away is
|
|
619
|
+
// that mechanism working rather than a third one.
|
|
620
|
+
{
|
|
621
|
+
id: "handoff-written",
|
|
622
|
+
label: "a session left a handoff for the next one in that directory",
|
|
623
|
+
module: "handoff/index.ts",
|
|
624
|
+
evidence: { kind: "event", names: ["handoff.written"] },
|
|
625
|
+
covers: ["handoff.refused", "handoff.cleared"],
|
|
626
|
+
since: "2026-09-20",
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
id: "handoff-shown",
|
|
630
|
+
label: "a session waking in that directory was handed the pointer to its handoff",
|
|
631
|
+
module: "handoff/index.ts",
|
|
632
|
+
evidence: { kind: "event", names: ["handoff.shown"] },
|
|
633
|
+
since: "2026-09-20",
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
id: "wake-injected",
|
|
637
|
+
label: "that briefing was handed to the host at the start of a session",
|
|
638
|
+
module: "claude-code/hooks.ts",
|
|
639
|
+
evidence: { kind: "event", names: ["adapter.wake.injected"] },
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
id: "wake-delivered",
|
|
643
|
+
label: "whether the briefing actually arrived was checked on the next turn",
|
|
644
|
+
module: "claude-code/hooks.ts",
|
|
645
|
+
evidence: { kind: "event", names: ["adapter.wake.delivered"] },
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
id: "primacy",
|
|
649
|
+
label: "the A/B hand-off that let the older system speak first during the parallel run",
|
|
650
|
+
module: "claude-code/hooks.ts",
|
|
651
|
+
evidence: { kind: "event", names: ["adapter.primacy.deliver", "adapter.primacy.standdown"] },
|
|
652
|
+
retired: "the parallel run left its primacy phase on 2026-09-04",
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
id: "protection",
|
|
656
|
+
label: "the owner marked a memory permanent, so nothing may revise or forget it",
|
|
657
|
+
module: "physics/, store/",
|
|
658
|
+
evidence: {
|
|
659
|
+
kind: "probe",
|
|
660
|
+
probe: "protected",
|
|
661
|
+
undated:
|
|
662
|
+
"protection is a flag on the row with no history behind it — the store can say which memories carry it and never when one was given it. A `versions` row with reason `protected` would fix it.",
|
|
663
|
+
},
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
id: "removal",
|
|
667
|
+
label: "the owner erased a memory, and the erasure left a record",
|
|
668
|
+
module: "store/owner-op-seam.ts",
|
|
669
|
+
evidence: { kind: "probe", probe: "removals" },
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
id: "unmerge",
|
|
673
|
+
label: "the owner put back a memory a merge had archived",
|
|
674
|
+
module: "store/owner-op-seam.ts",
|
|
675
|
+
evidence: { kind: "event", names: ["memory.unmerged"] },
|
|
676
|
+
},
|
|
677
|
+
{
|
|
678
|
+
id: "prospective-armed",
|
|
679
|
+
label: "something to remember at a future date was set",
|
|
680
|
+
module: "prospective/",
|
|
681
|
+
evidence: {
|
|
682
|
+
kind: "probe",
|
|
683
|
+
probe: "prospective.armed",
|
|
684
|
+
undated:
|
|
685
|
+
"the row records the date it is FOR and never the day it was set, so nothing says when one was armed.",
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
// STILL BLIND, and the rows are built and waiting (2026-09-20, E2).
|
|
690
|
+
//
|
|
691
|
+
// `prospective.fire` and `prospective.fire.refused` exist now and are
|
|
692
|
+
// written by `Prospective.fire()`. What does NOT exist is a caller: the
|
|
693
|
+
// only one in the tree is `tools/demo/seed.ts` (mechanism inventory §3 S4).
|
|
694
|
+
// So pointing this row's evidence at the new name would make it read `new`
|
|
695
|
+
// for two days and then `never` for ever — durable evidence asserted for a
|
|
696
|
+
// mechanism nothing can make fire, which is the blind case wearing a never
|
|
697
|
+
// label, and exactly the confusion this view exists to break.
|
|
698
|
+
//
|
|
699
|
+
// It goes back to event evidence the day the surfacing path spends a fire.
|
|
700
|
+
id: "prospective-fired",
|
|
701
|
+
label: "that future date arrived and the reminder came back",
|
|
702
|
+
module: "prospective/",
|
|
703
|
+
evidence: {
|
|
704
|
+
kind: "none",
|
|
705
|
+
reason:
|
|
706
|
+
"the two rows that would record it now exist (`prospective.fire`, `prospective.fire.refused`) and nothing calls `fire()` outside the demo seeder, so no row can land: `arrivals()` is read every turn but the fire budget is never spent. Wiring the surfacing path to spend it is what closes this, not another row.",
|
|
707
|
+
},
|
|
708
|
+
covers: ["prospective.fire", "prospective.fire.refused"],
|
|
709
|
+
},
|
|
710
|
+
|
|
711
|
+
// ── the machinery underneath ─────────────────────────────────────────────
|
|
712
|
+
{
|
|
713
|
+
id: "embed",
|
|
714
|
+
label: "memories without a vector were given one by the background worker",
|
|
715
|
+
module: "bin/runner.ts, store/cache.ts",
|
|
716
|
+
evidence: { kind: "event", names: ["adapter.embed.backfill"] },
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
id: "semantic-lag",
|
|
720
|
+
label: "the worker left the next turn's semantic cue ready",
|
|
721
|
+
module: "store/cache.ts",
|
|
722
|
+
evidence: { kind: "event", names: ["adapter.semantic.lag"] },
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
// The row the note below asked for, written since 2026-09-20 (E2) — one per
|
|
726
|
+
// calendar date, latched, because a boundary is a hot path. Its refusals
|
|
727
|
+
// come from the three rows of `worker-trouble`, which is what turns a week
|
|
728
|
+
// of silence from `never` into `blocked, by NO_CREDENTIAL`.
|
|
729
|
+
id: "worker-start",
|
|
730
|
+
label: "the background worker started when a session reached a boundary",
|
|
731
|
+
module: "claude-code/hooks.ts, bin/runner.ts",
|
|
732
|
+
evidence: { kind: "event", names: ["adapter.spawn.started"] },
|
|
733
|
+
refusals: {
|
|
734
|
+
names: ["adapter.spawn.refused", "adapter.spawn.failed", "adapter.runner.failed"],
|
|
735
|
+
},
|
|
736
|
+
since: "2026-09-20",
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
id: "worker-trouble",
|
|
740
|
+
label: "the worker was refused, could not be started, or failed after starting",
|
|
741
|
+
module: "claude-code/hooks.ts, bin/runner.ts",
|
|
742
|
+
evidence: {
|
|
743
|
+
kind: "event",
|
|
744
|
+
names: ["adapter.spawn.refused", "adapter.spawn.failed", "adapter.runner.failed"],
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
id: "checkout",
|
|
749
|
+
label: "which copy of the code the hooks were actually running",
|
|
750
|
+
module: "claude-code/doctor.ts",
|
|
751
|
+
evidence: { kind: "event", names: ["adapter.checkout"] },
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
id: "scope-verdict",
|
|
755
|
+
label: "a directory's own setting decided whether to remember there at all",
|
|
756
|
+
module: "adapters/scopes.ts",
|
|
757
|
+
evidence: {
|
|
758
|
+
kind: "none",
|
|
759
|
+
reason:
|
|
760
|
+
"off and paused are decided BEFORE the store is opened, so no store row is possible at that instant. A counter file beside the scope registry, read by doctor, is the only shape that fits.",
|
|
761
|
+
},
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
id: "snapshot",
|
|
765
|
+
label: "a whole copy of the store was set aside, and old copies were let go",
|
|
766
|
+
module: "adapters/snapshots.ts",
|
|
767
|
+
evidence: { kind: "event", names: ["snapshot.taken"] },
|
|
768
|
+
// The rotation row is the same mechanism saying what it discarded, and the
|
|
769
|
+
// failure row is the same mechanism saying it could not. Neither is evidence
|
|
770
|
+
// that a copy EXISTS, which is what this row's state is about — so they are
|
|
771
|
+
// accounted for here rather than given states of their own.
|
|
772
|
+
covers: ["snapshot.rotated"],
|
|
773
|
+
since: "2026-09-18",
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
// Split from the row above for the reason `worker-start` and
|
|
777
|
+
// `worker-trouble` are split: "a copy exists" and "a copy was attempted and
|
|
778
|
+
// could not be made" are different questions, and a failure counted as a
|
|
779
|
+
// firing would make a store with no backup at all read as covered. Its
|
|
780
|
+
// refusal column names the step and the reason (`REFUSAL_READERS`).
|
|
781
|
+
id: "snapshot-trouble",
|
|
782
|
+
label: "a copy of the store could not be made (the store itself is unharmed)",
|
|
783
|
+
module: "adapters/snapshots.ts",
|
|
784
|
+
evidence: { kind: "event", names: ["snapshot.failed"] },
|
|
785
|
+
since: "2026-09-18",
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
id: "backup",
|
|
789
|
+
label: "the store was backed up BY HAND, from the console",
|
|
790
|
+
module: "cli/commands.ts",
|
|
791
|
+
evidence: {
|
|
792
|
+
kind: "none",
|
|
793
|
+
reason:
|
|
794
|
+
"the `backup` command leaves no row at all, so one that ran and one that never has are the same silence. The AUTOMATIC daily copy has had its own rows since 2026-09-18 (the `snapshot` row above); the console command is the other half. One `store.backup` event would fix it.",
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
// F6, 2026-09-20. The plan called this row `journal-file`; the id here is
|
|
799
|
+
// what the owner's brief calls it — "the journal copy" — and both names are
|
|
800
|
+
// in the PR so neither gets lost. `covers` the failure row rather than
|
|
801
|
+
// splitting it the way `snapshot`/`snapshot-trouble` are: a copy that could
|
|
802
|
+
// not be written is a file missing beside a chapter that is safe, which is a
|
|
803
|
+
// doctor line (amber, and only while it stands), not a second mechanism.
|
|
804
|
+
id: "journal-copy",
|
|
805
|
+
label: "the journal was written out as markdown files you can open in any editor",
|
|
806
|
+
module: "core/self/journal-file.ts",
|
|
807
|
+
evidence: { kind: "event", names: ["journal.copy.written"] },
|
|
808
|
+
covers: ["journal.copy.failed"],
|
|
809
|
+
since: "2026-09-20",
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
// F7, 2026-09-20, and deliberately NOT the `backup` row above: that one is
|
|
813
|
+
// still blind and still says what would fix it. This is the other door —
|
|
814
|
+
// the one that answers "did anything leave this machine, and when".
|
|
815
|
+
id: "export",
|
|
816
|
+
label: "the owner took a readable copy of the memories off this machine, by hand",
|
|
817
|
+
module: "cli/export.ts",
|
|
818
|
+
evidence: { kind: "event", names: ["store.export"] },
|
|
819
|
+
since: "2026-09-20",
|
|
820
|
+
},
|
|
821
|
+
];
|
|
822
|
+
|
|
823
|
+
// ── the report ──────────────────────────────────────────────────────────────
|
|
824
|
+
|
|
825
|
+
export interface FiredRow {
|
|
826
|
+
readonly id: string;
|
|
827
|
+
readonly label: string;
|
|
828
|
+
readonly module: string;
|
|
829
|
+
readonly state: FiredState;
|
|
830
|
+
/** The calendar date of the newest row, or `lived day N` for a table that
|
|
831
|
+
* counts in lived days, or null when nothing has ever been recorded. */
|
|
832
|
+
readonly lastFired: string | null;
|
|
833
|
+
/** True when `lastFired` is a `YYYY-MM-DD` calendar date rather than a lived day. */
|
|
834
|
+
readonly lastFiredIsDate: boolean;
|
|
835
|
+
readonly firedInWindow: number;
|
|
836
|
+
readonly firedInPreviousWindow: number;
|
|
837
|
+
/** Everything the store still holds. A floor when the report is `truncated`. */
|
|
838
|
+
readonly total: number;
|
|
839
|
+
readonly refusedInWindow: number;
|
|
840
|
+
readonly topRefusal: string | null;
|
|
841
|
+
/** The dotted names or the table this row was read from, for the reader who greps. */
|
|
842
|
+
readonly evidence: string;
|
|
843
|
+
/** Present on `blind`, `disabled`, `retired` and `new` — the line that says why. */
|
|
844
|
+
readonly note: string | null;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
export interface FiredReport {
|
|
848
|
+
readonly today: string;
|
|
849
|
+
/** The first day of the window — today and the six before it. */
|
|
850
|
+
readonly from: string;
|
|
851
|
+
/** The seven days before that — the window a `quiet` verdict is measured against. */
|
|
852
|
+
readonly previousFrom: string;
|
|
853
|
+
readonly previousTo: string;
|
|
854
|
+
readonly rows: readonly FiredRow[];
|
|
855
|
+
/** Mechanism ids whose evidence is a table this pass did not read. */
|
|
856
|
+
readonly notRead: readonly string[];
|
|
857
|
+
/** The event read reached its ceiling, so every `total` is a floor. */
|
|
858
|
+
readonly truncated: boolean;
|
|
859
|
+
readonly probesRead: boolean;
|
|
860
|
+
/** The id scan reached its ceiling, so every probe count is a floor. */
|
|
861
|
+
readonly probesTruncated: boolean;
|
|
862
|
+
readonly counts: Record<FiredState, number>;
|
|
863
|
+
/**
|
|
864
|
+
* Mechanisms that fired in the PREVIOUS seven days and not once in this one,
|
|
865
|
+
* by label. The one list on this page that says something CHANGED.
|
|
866
|
+
*/
|
|
867
|
+
readonly wentQuiet: readonly string[];
|
|
868
|
+
/**
|
|
869
|
+
* Mechanisms that fired in the PREVIOUS seven days, not once in this one, and
|
|
870
|
+
* were REFUSED instead — `wentQuiet`'s sibling, and the more alarming of the
|
|
871
|
+
* two.
|
|
872
|
+
*
|
|
873
|
+
* It exists because `blocked` outranks `quiet` in the state machine, so a
|
|
874
|
+
* mechanism that fired last week and was turned away every day this week
|
|
875
|
+
* leaves `wentQuiet` and would have left no list at all. Doctor's Fired line
|
|
876
|
+
* grades on both, or adding a state that says MORE would have made the
|
|
877
|
+
* finding read greener.
|
|
878
|
+
*/
|
|
879
|
+
readonly wentBlocked: readonly string[];
|
|
880
|
+
/** The store's own clock — the number of days it has actually LIVED. */
|
|
881
|
+
readonly livedDay: number;
|
|
882
|
+
/** Calendar days between the oldest row this pass read and today, or null
|
|
883
|
+
* when the store holds no durable row at all. */
|
|
884
|
+
readonly calendarDays: number | null;
|
|
885
|
+
/**
|
|
886
|
+
* TOO NEW TO GRADE (2026-09-20, finding 2).
|
|
887
|
+
*
|
|
888
|
+
* A store minutes old opened this view with twenty-eight `never` lines, which
|
|
889
|
+
* is what a broken install looks like. Nothing had fired because nothing had
|
|
890
|
+
* happened yet, and no surface said so. `young` is that sentence as a fact the
|
|
891
|
+
* three renderers share rather than each deciding for itself.
|
|
892
|
+
*
|
|
893
|
+
* BOTH clocks have to agree. A lived day is advanced by the worker, so a store
|
|
894
|
+
* whose worker has been dead for a fortnight also reads lived day 0 — and that
|
|
895
|
+
* store must get the full list, because the full list is the diagnosis. So:
|
|
896
|
+
* fewer than `YOUNG_LIVED_DAYS` lived days AND no durable row older than
|
|
897
|
+
* `YOUNG_LIVED_DAYS` calendar days.
|
|
898
|
+
*/
|
|
899
|
+
readonly young: boolean;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/** Under this many lived days — and calendar days — a store is too new to grade. */
|
|
903
|
+
export const YOUNG_LIVED_DAYS = 2;
|
|
904
|
+
|
|
905
|
+
export interface FiredOptions {
|
|
906
|
+
/**
|
|
907
|
+
* Read the tables that stand in for a mechanism with no event — edges,
|
|
908
|
+
* prospective, protected, removals, versions. ON by default. The probes cost a
|
|
909
|
+
* few queries per memory, because `Store` offers no aggregate over tables
|
|
910
|
+
* keyed by memory id, so the one caller on a hook's hot path turns them off
|
|
911
|
+
* and the report NAMES what it did not read rather than guessing at it.
|
|
912
|
+
*/
|
|
913
|
+
readonly probes?: boolean;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/** `YYYY-MM-DD`, `back` days before `today`. UTC, like every date in this store. */
|
|
917
|
+
export function daysBefore(today: string, back: number): string {
|
|
918
|
+
const at = Date.parse(`${today}T00:00:00Z`);
|
|
919
|
+
if (Number.isNaN(at)) return today;
|
|
920
|
+
return new Date(at - back * 86_400_000).toISOString().slice(0, 10);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/** True when this mechanism's refusal channel is younger than the window the
|
|
924
|
+
* `wentBlocked` comparison measures against, so the two weeks are not
|
|
925
|
+
* comparable and the claim is withheld rather than made wrongly. */
|
|
926
|
+
function comparisonIsTooYoung(id: string, w: Window): boolean {
|
|
927
|
+
const since = MECHANISMS.find((m) => m.id === id)?.refusals?.since;
|
|
928
|
+
return since !== undefined && since > w.previousFrom;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/** Whole UTC days from `from` to `to`, 0 when either date does not parse. */
|
|
932
|
+
export function daysBetween(from: string, to: string): number {
|
|
933
|
+
const a = Date.parse(`${from}T00:00:00Z`);
|
|
934
|
+
const b = Date.parse(`${to}T00:00:00Z`);
|
|
935
|
+
if (Number.isNaN(a) || Number.isNaN(b)) return 0;
|
|
936
|
+
return Math.round((b - a) / 86_400_000);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/** The lived clock, or 0. A diagnostic may not become the thing that throws. */
|
|
940
|
+
function safeLivedDay(store: Store): number {
|
|
941
|
+
try {
|
|
942
|
+
return store.livedDay();
|
|
943
|
+
} catch {
|
|
944
|
+
return 0;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* THE READING. One pass over the log, one optional pass over the ids, and a row
|
|
950
|
+
* per mechanism. Pure over the store, and never a write.
|
|
951
|
+
*/
|
|
952
|
+
export function firedReport(store: Store, today: string, opts: FiredOptions = {}): FiredReport {
|
|
953
|
+
const window: Window = {
|
|
954
|
+
from: daysBefore(today, FIRED_DAYS - 1),
|
|
955
|
+
to: today,
|
|
956
|
+
previousFrom: daysBefore(today, FIRED_DAYS * 2 - 1),
|
|
957
|
+
previousTo: daysBefore(today, FIRED_DAYS),
|
|
958
|
+
};
|
|
959
|
+
const log = readLog(store, window);
|
|
960
|
+
const probed = opts.probes === false ? null : readProbes(store, window);
|
|
961
|
+
|
|
962
|
+
const rows: FiredRow[] = [];
|
|
963
|
+
const notRead: string[] = [];
|
|
964
|
+
for (const m of MECHANISMS) {
|
|
965
|
+
if (m.evidence.kind === "probe" && probed === null) {
|
|
966
|
+
notRead.push(m.id);
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
rows.push(rowFor(m, log, probed, window));
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
const counts = Object.fromEntries(FIRED_STATES.map((s) => [s, 0])) as Record<FiredState, number>;
|
|
973
|
+
for (const row of rows) counts[row.state] += 1;
|
|
974
|
+
|
|
975
|
+
const livedDay = safeLivedDay(store);
|
|
976
|
+
const calendarDays =
|
|
977
|
+
log.oldestDate === null ? null : Math.max(0, daysBetween(log.oldestDate, today));
|
|
978
|
+
|
|
979
|
+
return {
|
|
980
|
+
today,
|
|
981
|
+
from: window.from,
|
|
982
|
+
previousFrom: window.previousFrom,
|
|
983
|
+
previousTo: window.previousTo,
|
|
984
|
+
rows: sortRows(rows),
|
|
985
|
+
notRead,
|
|
986
|
+
truncated: log.truncated,
|
|
987
|
+
probesRead: probed !== null,
|
|
988
|
+
probesTruncated: probed?.truncated ?? false,
|
|
989
|
+
counts,
|
|
990
|
+
livedDay,
|
|
991
|
+
calendarDays,
|
|
992
|
+
young: livedDay < YOUNG_LIVED_DAYS && (calendarDays === null || calendarDays < YOUNG_LIVED_DAYS),
|
|
993
|
+
// WEEK OVER WEEK, and only where BOTH weeks could answer. A refusal channel
|
|
994
|
+
// younger than the older window makes a schema change read as a regression
|
|
995
|
+
// — "your prune phase stopped working on deploy day" when all that happened
|
|
996
|
+
// is that the rows started carrying a field. The row still says `blocked`,
|
|
997
|
+
// which is true of this week; the comparison is what is withheld.
|
|
998
|
+
wentBlocked: rows
|
|
999
|
+
.filter(
|
|
1000
|
+
(r) =>
|
|
1001
|
+
r.state === "blocked" &&
|
|
1002
|
+
r.firedInPreviousWindow > 0 &&
|
|
1003
|
+
!comparisonIsTooYoung(r.id, window),
|
|
1004
|
+
)
|
|
1005
|
+
.map((r) => `${r.label} (${r.topRefusal ?? UNNAMED_REFUSAL})`),
|
|
1006
|
+
wentQuiet: rows
|
|
1007
|
+
.filter((r) => r.state === "quiet" && r.firedInPreviousWindow > 0)
|
|
1008
|
+
// A row whose table keeps only LIVED days was compared on the lived clock,
|
|
1009
|
+
// which has run seven days across fifteen calendar ones — so the sentence
|
|
1010
|
+
// says which clock answered rather than claiming a calendar week it did
|
|
1011
|
+
// not measure.
|
|
1012
|
+
.map((r) => (r.lastFiredIsDate ? r.label : `${r.label} (measured in lived days)`)),
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/** Silent first, then by state, then most-recently-fired first inside a state —
|
|
1017
|
+
* with the rows a lived clock answered after the dated ones, because the two
|
|
1018
|
+
* spellings do not compare and an order that pretended they did would shuffle. */
|
|
1019
|
+
export function sortRows(rows: readonly FiredRow[]): FiredRow[] {
|
|
1020
|
+
return [...rows].sort((a, b) => {
|
|
1021
|
+
const byState = STATE_ORDER.indexOf(a.state) - STATE_ORDER.indexOf(b.state);
|
|
1022
|
+
if (byState !== 0) return byState;
|
|
1023
|
+
if (a.lastFiredIsDate !== b.lastFiredIsDate) return a.lastFiredIsDate ? -1 : 1;
|
|
1024
|
+
if (a.lastFired !== b.lastFired) {
|
|
1025
|
+
if (a.lastFired === null) return 1;
|
|
1026
|
+
if (b.lastFired === null) return -1;
|
|
1027
|
+
return a.lastFired < b.lastFired ? 1 : -1;
|
|
1028
|
+
}
|
|
1029
|
+
return a.id < b.id ? -1 : 1;
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// ── one row per mechanism ───────────────────────────────────────────────────
|
|
1034
|
+
|
|
1035
|
+
interface Window {
|
|
1036
|
+
readonly from: string;
|
|
1037
|
+
readonly to: string;
|
|
1038
|
+
readonly previousFrom: string;
|
|
1039
|
+
readonly previousTo: string;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/** A reading of one piece of evidence, before the state is decided. */
|
|
1043
|
+
interface Reading {
|
|
1044
|
+
readonly total: number;
|
|
1045
|
+
readonly lastFired: string | null;
|
|
1046
|
+
readonly lastFiredIsDate: boolean;
|
|
1047
|
+
readonly inWindow: number;
|
|
1048
|
+
readonly inPreviousWindow: number;
|
|
1049
|
+
readonly refused: number;
|
|
1050
|
+
readonly topRefusal: string | null;
|
|
1051
|
+
/** Every refusal reason and its count, so a source read from another row can
|
|
1052
|
+
* be merged in without re-reading the log. */
|
|
1053
|
+
readonly refusals: ReadonlyMap<string, number>;
|
|
1054
|
+
readonly evidence: string;
|
|
1055
|
+
/** The rows the refusal column came from — the same as `evidence` unless the
|
|
1056
|
+
* refusals live somewhere else (`Mechanism.refusals`). */
|
|
1057
|
+
readonly refusalEvidence: string;
|
|
1058
|
+
/** Set when this evidence cannot answer the question at all. */
|
|
1059
|
+
readonly blind: string | null;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
const EMPTY_READING: Reading = {
|
|
1063
|
+
total: 0,
|
|
1064
|
+
lastFired: null,
|
|
1065
|
+
lastFiredIsDate: false,
|
|
1066
|
+
inWindow: 0,
|
|
1067
|
+
inPreviousWindow: 0,
|
|
1068
|
+
refused: 0,
|
|
1069
|
+
topRefusal: null,
|
|
1070
|
+
refusals: new Map(),
|
|
1071
|
+
evidence: "",
|
|
1072
|
+
refusalEvidence: "",
|
|
1073
|
+
blind: null,
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
function rowFor(m: Mechanism, log: LogRead, probed: Probed | null, w: Window): FiredRow {
|
|
1077
|
+
const read = readEvidence(m, log, probed);
|
|
1078
|
+
const state = stateOf(m, read, w);
|
|
1079
|
+
return {
|
|
1080
|
+
id: m.id,
|
|
1081
|
+
label: m.label,
|
|
1082
|
+
module: m.module,
|
|
1083
|
+
state,
|
|
1084
|
+
lastFired: read.lastFired,
|
|
1085
|
+
lastFiredIsDate: read.lastFiredIsDate,
|
|
1086
|
+
firedInWindow: read.inWindow,
|
|
1087
|
+
firedInPreviousWindow: read.inPreviousWindow,
|
|
1088
|
+
total: read.total,
|
|
1089
|
+
refusedInWindow: read.refused,
|
|
1090
|
+
topRefusal: read.topRefusal,
|
|
1091
|
+
evidence: read.evidence,
|
|
1092
|
+
note: noteFor(m, read, state),
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
/**
|
|
1097
|
+
* THE STATE MACHINE, in the order the answers override each other: a named
|
|
1098
|
+
* stand-down and a retired phase are facts about the DESIGN and outrank every
|
|
1099
|
+
* count; blindness is a fact about the EVIDENCE and outranks the rest; only then
|
|
1100
|
+
* do the counts speak.
|
|
1101
|
+
*/
|
|
1102
|
+
function stateOf(m: Mechanism, read: Reading, w: Window): FiredState {
|
|
1103
|
+
if (m.disabled !== undefined) return "disabled";
|
|
1104
|
+
if (m.retired !== undefined) return "retired";
|
|
1105
|
+
if (read.blind !== null) return "blind";
|
|
1106
|
+
if (read.inWindow > 0) return "firing";
|
|
1107
|
+
// DID NOT FIRE, AND SOMETHING SAID WHY (E2). This outranks both `quiet` and
|
|
1108
|
+
// `never` because it answers the question they leave open: a mechanism that
|
|
1109
|
+
// was turned away every time it was reached is not one that had nothing to do.
|
|
1110
|
+
if (read.refused > 0) return "blocked";
|
|
1111
|
+
if (read.total > 0) return "quiet";
|
|
1112
|
+
// Never fired. A mechanism whose EVIDENCE is younger than the window has not
|
|
1113
|
+
// had time to be a worry yet, and grading it as one is how a view teaches its
|
|
1114
|
+
// reader to ignore it.
|
|
1115
|
+
if (m.since !== undefined && m.since >= w.from) return "new";
|
|
1116
|
+
return "never";
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function noteFor(m: Mechanism, read: Reading, state: FiredState): string | null {
|
|
1120
|
+
if (state === "disabled") return m.disabled ?? null;
|
|
1121
|
+
if (state === "retired") return m.retired ?? null;
|
|
1122
|
+
if (state === "blind") return read.blind;
|
|
1123
|
+
if (state === "new" && m.since !== undefined) return `its evidence was added ${m.since}`;
|
|
1124
|
+
if (state === "blocked") {
|
|
1125
|
+
// The whole point of the state, in one sentence: not "quiet", not "never" —
|
|
1126
|
+
// reached, and stopped, this many times, by this.
|
|
1127
|
+
const by = read.topRefusal === null ? "" : `, most often ${read.topRefusal}`;
|
|
1128
|
+
return `it did not fire this week; ${String(read.refused)} refusal${
|
|
1129
|
+
read.refused === 1 ? "" : "s"
|
|
1130
|
+
} landed instead${by} (${read.refusalEvidence})`;
|
|
1131
|
+
}
|
|
1132
|
+
return null;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
function readEvidence(m: Mechanism, log: LogRead, probed: Probed | null): Reading {
|
|
1136
|
+
const base =
|
|
1137
|
+
m.evidence.kind === "none"
|
|
1138
|
+
? { ...EMPTY_READING, evidence: "no durable row", blind: m.evidence.reason }
|
|
1139
|
+
: m.evidence.kind === "probe"
|
|
1140
|
+
? probeReading(m.evidence.probe, m.evidence.undated ?? null, probed)
|
|
1141
|
+
: eventReading(m.evidence.names, log);
|
|
1142
|
+
if (m.refusals === undefined) return base;
|
|
1143
|
+
// Refusals from ANOTHER row, folded in without touching the counts that say
|
|
1144
|
+
// whether this mechanism fired.
|
|
1145
|
+
const extra = refusalReading(m.refusals, log);
|
|
1146
|
+
if (extra.refused === 0) return { ...base, refusalEvidence: base.evidence };
|
|
1147
|
+
const merged = new Map<string, number>(extra.refusals);
|
|
1148
|
+
for (const [reason, n] of base.refusals) merged.set(reason, (merged.get(reason) ?? 0) + n);
|
|
1149
|
+
return {
|
|
1150
|
+
...base,
|
|
1151
|
+
refused: base.refused + extra.refused,
|
|
1152
|
+
refusals: merged,
|
|
1153
|
+
topRefusal: topOf(merged),
|
|
1154
|
+
refusalEvidence: m.refusals.names.join(", "),
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
/** The refusal half of a reading, from rows that are NOT this mechanism's
|
|
1159
|
+
* evidence. It contributes no `total`, no `lastFired` and no `inWindow`: a
|
|
1160
|
+
* refusal is the opposite of a firing, and counting it as one is the bug. */
|
|
1161
|
+
function refusalReading(src: RefusalSource, log: LogRead): { refused: number; refusals: Map<string, number> } {
|
|
1162
|
+
const refusals = new Map<string, number>();
|
|
1163
|
+
let refused = 0;
|
|
1164
|
+
for (const name of src.names) {
|
|
1165
|
+
const t = log.byName.get(name);
|
|
1166
|
+
if (t === undefined) continue;
|
|
1167
|
+
for (const [reason, n] of t.refusals) {
|
|
1168
|
+
if (src.under !== undefined && !reason.startsWith(src.under)) continue;
|
|
1169
|
+
const key = src.under === undefined ? reason : reason.slice(src.under.length);
|
|
1170
|
+
// THE ALLOW-LIST. Everything a phase counted that is not named here is a
|
|
1171
|
+
// candidate filter, not a refusal, and counting it is how this view
|
|
1172
|
+
// teaches its reader to ignore it.
|
|
1173
|
+
if (src.only !== undefined && !src.only.includes(key)) continue;
|
|
1174
|
+
refusals.set(key, (refusals.get(key) ?? 0) + n);
|
|
1175
|
+
refused += n;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
return { refused, refusals };
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
function eventReading(names: readonly DurableEventName[], log: LogRead): Reading {
|
|
1182
|
+
let total = 0;
|
|
1183
|
+
let inWindow = 0;
|
|
1184
|
+
let inPreviousWindow = 0;
|
|
1185
|
+
let refused = 0;
|
|
1186
|
+
let lastFired: string | null = null;
|
|
1187
|
+
const refusals = new Map<string, number>();
|
|
1188
|
+
for (const name of names) {
|
|
1189
|
+
const t = log.byName.get(name);
|
|
1190
|
+
if (t === undefined) continue;
|
|
1191
|
+
total += t.total;
|
|
1192
|
+
inWindow += t.inWindow;
|
|
1193
|
+
inPreviousWindow += t.inPreviousWindow;
|
|
1194
|
+
refused += t.refused;
|
|
1195
|
+
if (t.lastDate !== null && (lastFired === null || t.lastDate > lastFired)) {
|
|
1196
|
+
lastFired = t.lastDate;
|
|
1197
|
+
}
|
|
1198
|
+
for (const [reason, n] of t.refusals) refusals.set(reason, (refusals.get(reason) ?? 0) + n);
|
|
1199
|
+
}
|
|
1200
|
+
return {
|
|
1201
|
+
total,
|
|
1202
|
+
lastFired,
|
|
1203
|
+
lastFiredIsDate: lastFired !== null,
|
|
1204
|
+
inWindow,
|
|
1205
|
+
inPreviousWindow,
|
|
1206
|
+
refused,
|
|
1207
|
+
topRefusal: topOf(refusals),
|
|
1208
|
+
refusals,
|
|
1209
|
+
evidence: names.join(", "),
|
|
1210
|
+
refusalEvidence: names.join(", "),
|
|
1211
|
+
blind: null,
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/** The reason with the most against it; ties broken by name, so a line a test
|
|
1216
|
+
* pins does not depend on map order. */
|
|
1217
|
+
function topOf(refusals: ReadonlyMap<string, number>): string | null {
|
|
1218
|
+
let top: [string, number] | null = null;
|
|
1219
|
+
for (const [reason, n] of refusals) {
|
|
1220
|
+
if (top === null || n > top[1] || (n === top[1] && reason < top[0])) top = [reason, n];
|
|
1221
|
+
}
|
|
1222
|
+
return top === null ? null : `${top[0]} ×${String(top[1])}`;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// ── the one pass over the log ───────────────────────────────────────────────
|
|
1226
|
+
|
|
1227
|
+
interface NameTally {
|
|
1228
|
+
total: number;
|
|
1229
|
+
lastDate: string | null;
|
|
1230
|
+
inWindow: number;
|
|
1231
|
+
inPreviousWindow: number;
|
|
1232
|
+
refused: number;
|
|
1233
|
+
refusals: Map<string, number>;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
interface LogRead {
|
|
1237
|
+
readonly byName: ReadonlyMap<string, NameTally>;
|
|
1238
|
+
readonly truncated: boolean;
|
|
1239
|
+
/** The calendar date of the OLDEST row this pass saw, for the store's age.
|
|
1240
|
+
* A truncated read is the oldest rows, so this stays right when it happens. */
|
|
1241
|
+
readonly oldestDate: string | null;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
function emptyTally(): NameTally {
|
|
1245
|
+
return {
|
|
1246
|
+
total: 0,
|
|
1247
|
+
lastDate: null,
|
|
1248
|
+
inWindow: 0,
|
|
1249
|
+
inPreviousWindow: 0,
|
|
1250
|
+
refused: 0,
|
|
1251
|
+
refusals: new Map(),
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* The events, read once and grouped here — `Store` offers no GROUP BY, and a
|
|
1257
|
+
* query per mechanism per day would make this the slowest thing doctor does.
|
|
1258
|
+
*
|
|
1259
|
+
* `eventLog` orders ASCENDING and takes a LIMIT, so a read that comes back FULL
|
|
1260
|
+
* is the OLDEST rows and the newest days are exactly the ones missing — which is
|
|
1261
|
+
* the window this report is about. In that case a SECOND, day-bounded read
|
|
1262
|
+
* covers both windows, the two are joined on `seq` so nothing is counted twice,
|
|
1263
|
+
* and every total is declared a floor.
|
|
1264
|
+
*/
|
|
1265
|
+
function readLog(store: Store, w: Window): LogRead {
|
|
1266
|
+
const byName = new Map<string, NameTally>();
|
|
1267
|
+
const age = { oldest: null as string | null };
|
|
1268
|
+
const first = store.eventLog({ limit: EVENT_CEILING });
|
|
1269
|
+
for (const row of first) tallyRow(byName, row, w, age);
|
|
1270
|
+
if (first.length < EVENT_CEILING) {
|
|
1271
|
+
return { byName, truncated: false, oldestDate: age.oldest };
|
|
1272
|
+
}
|
|
1273
|
+
const lastSeq = first[first.length - 1]?.seq ?? 0;
|
|
1274
|
+
// A lived day is never longer than a calendar day, so `livedDay - 14` cannot
|
|
1275
|
+
// cut a row inside the fourteen calendar days the two windows cover.
|
|
1276
|
+
const recent = store.eventLog({
|
|
1277
|
+
sinceDay: Math.max(0, store.livedDay() - FIRED_DAYS * 2),
|
|
1278
|
+
limit: EVENT_CEILING,
|
|
1279
|
+
});
|
|
1280
|
+
for (const row of recent) {
|
|
1281
|
+
if (row.seq <= lastSeq) continue;
|
|
1282
|
+
tallyRow(byName, row, w, age);
|
|
1283
|
+
}
|
|
1284
|
+
return { byName, truncated: true, oldestDate: age.oldest };
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
function tallyRow(
|
|
1288
|
+
byName: Map<string, NameTally>,
|
|
1289
|
+
row: EventRow,
|
|
1290
|
+
w: Window,
|
|
1291
|
+
age: { oldest: string | null },
|
|
1292
|
+
): void {
|
|
1293
|
+
let t = byName.get(row.name);
|
|
1294
|
+
if (t === undefined) {
|
|
1295
|
+
t = emptyTally();
|
|
1296
|
+
byName.set(row.name, t);
|
|
1297
|
+
}
|
|
1298
|
+
t.total += 1;
|
|
1299
|
+
const payload = payloadOf(row);
|
|
1300
|
+
const date = rowDate(row, payload);
|
|
1301
|
+
if (age.oldest === null || date < age.oldest) age.oldest = date;
|
|
1302
|
+
if (t.lastDate === null || date > t.lastDate) t.lastDate = date;
|
|
1303
|
+
const inWindow = date >= w.from && date <= w.to;
|
|
1304
|
+
if (inWindow) t.inWindow += 1;
|
|
1305
|
+
else if (date >= w.previousFrom && date <= w.previousTo) t.inPreviousWindow += 1;
|
|
1306
|
+
if (!inWindow) return;
|
|
1307
|
+
const reader = REFUSAL_READERS[row.name];
|
|
1308
|
+
if (reader === undefined) return;
|
|
1309
|
+
for (const [reason, n] of reader(payload)) {
|
|
1310
|
+
if (n <= 0) continue;
|
|
1311
|
+
t.refused += n;
|
|
1312
|
+
t.refusals.set(reason, (t.refusals.get(reason) ?? 0) + n);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/** The CALENDAR date a row is about: its own field, else the wall clock it was
|
|
1317
|
+
* written at. `day` is the lived-day column and answers a different question. */
|
|
1318
|
+
function rowDate(row: EventRow, payload: Record<string, unknown>): string {
|
|
1319
|
+
const date = payload["date"];
|
|
1320
|
+
if (typeof date === "string" && date.length === 10) return date;
|
|
1321
|
+
return dateOf(row.at);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
function payloadOf(row: EventRow): Record<string, unknown> {
|
|
1325
|
+
if (row.payload === null) return {};
|
|
1326
|
+
try {
|
|
1327
|
+
const parsed: unknown = JSON.parse(row.payload);
|
|
1328
|
+
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)
|
|
1329
|
+
? (parsed as Record<string, unknown>)
|
|
1330
|
+
: {};
|
|
1331
|
+
} catch {
|
|
1332
|
+
return {};
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// ── refusals, read only from fields that exist today ────────────────────────
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* WHAT WAS TURNED AWAY, per event name — and ONLY from a payload field the
|
|
1340
|
+
* writer already fills. The inventory's §5(c) named five; this is that list as
|
|
1341
|
+
* code. Nothing here invents a refusal channel, and a name absent from this
|
|
1342
|
+
* table simply has no refusal column on the page, which is the honest answer.
|
|
1343
|
+
*/
|
|
1344
|
+
const REFUSAL_READERS: Record<string, (p: Record<string, unknown>) => [string, number][]> = {
|
|
1345
|
+
// `outcome` says what happened; `reason` says why, and is the one worth
|
|
1346
|
+
// reading — the old shared day cap and the per-session allowance are two
|
|
1347
|
+
// different verdicts that both spell themselves `capped`.
|
|
1348
|
+
"adapter.ask": (p) => {
|
|
1349
|
+
const outcome = str(p, "outcome");
|
|
1350
|
+
if (outcome === null || outcome === "asked") return [];
|
|
1351
|
+
return [[str(p, "reason") ?? outcome, 1]];
|
|
1352
|
+
},
|
|
1353
|
+
// TOTAL by reason since 2026-09-14, `SWEPT` included — and `SWEPT` is the one
|
|
1354
|
+
// entry that is not a refusal at all, so it is excluded rather than counted.
|
|
1355
|
+
"sweep.gate": (p) => countsIn(p, "refusals").filter(([reason]) => reason !== "SWEPT"),
|
|
1356
|
+
"gate.chunk": (p) => countsIn(p, "refusalsByReason"),
|
|
1357
|
+
"gate.deposit": (p) => countsIn(p, "refusalsByReason"),
|
|
1358
|
+
"recall.credit": (p) => countsIn(p, "refused"),
|
|
1359
|
+
// Every `snapshot.failed` row IS a refusal — a copy that should have happened
|
|
1360
|
+
// and did not — so the reason it carries is the whole column.
|
|
1361
|
+
"snapshot.failed": (p) => {
|
|
1362
|
+
const reason = str(p, "reason");
|
|
1363
|
+
return reason === null ? [] : [[reason, 1]];
|
|
1364
|
+
},
|
|
1365
|
+
// THE SPAWN SEAM'S THREE (E2). Each row IS a refusal; the reason it carries is
|
|
1366
|
+
// the whole column, exactly like `snapshot.failed` above.
|
|
1367
|
+
//
|
|
1368
|
+
// **Counted as ONE per row on purpose.** These three are the one durable
|
|
1369
|
+
// family that carries a `dedupKey` — one row per reason per calendar date
|
|
1370
|
+
// (I32) — so the honest unit here is DAYS the worker was stopped, not
|
|
1371
|
+
// attempts. The row's own `count` field is a running counter that a single
|
|
1372
|
+
// successful start resets, so summing it across days would invent a number
|
|
1373
|
+
// nothing measured.
|
|
1374
|
+
"adapter.spawn.refused": (p) => reasonOnce(p),
|
|
1375
|
+
"adapter.spawn.failed": (p) => reasonOnce(p),
|
|
1376
|
+
"adapter.runner.failed": (p) => reasonOnce(p),
|
|
1377
|
+
// THE NIGHT'S REFUSALS (E2). Every phase counts what it turned away by reason
|
|
1378
|
+
// and the cycle row has carried them since 2026-09-20, so "why did this not
|
|
1379
|
+
// promote" is answerable from the store. Keyed `<phase>/<reason>` because one
|
|
1380
|
+
// row answers for four mechanisms and none of them may claim another's — the
|
|
1381
|
+
// `under` prefix on `Mechanism.refusals` is how each takes only its own.
|
|
1382
|
+
"sleep.cycle": (p) => {
|
|
1383
|
+
const out: [string, number][] = [];
|
|
1384
|
+
const phases = p["phases"];
|
|
1385
|
+
if (!Array.isArray(phases)) return out;
|
|
1386
|
+
for (const entry of phases) {
|
|
1387
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
1388
|
+
const e = entry as Record<string, unknown>;
|
|
1389
|
+
const phase = typeof e["phase"] === "string" ? e["phase"] : null;
|
|
1390
|
+
if (phase === null) continue;
|
|
1391
|
+
for (const [reason, n] of countsIn(e, "skipped")) out.push([`${phase}/${reason}`, n]);
|
|
1392
|
+
}
|
|
1393
|
+
return out;
|
|
1394
|
+
},
|
|
1395
|
+
// Every refused write to the page IS a refusal, and the reason is the column.
|
|
1396
|
+
"self.page.refused": (p) => reasonOnce(p),
|
|
1397
|
+
// Same shape: the row IS the brake that held, named.
|
|
1398
|
+
"prospective.fire.refused": (p) => reasonOnce(p),
|
|
1399
|
+
/**
|
|
1400
|
+
* THE DELIBERATE LOOK'S CAPS, AND ONLY ITS CAPS.
|
|
1401
|
+
*
|
|
1402
|
+
* The row's `blockedBy` holds every verdict that kept something out, which is
|
|
1403
|
+
* what makes it a diagnostic. Most of those verdicts are not refusals:
|
|
1404
|
+
* `dark-uncued`, `below-floor` and `cue-fraction` mean "this memory was not
|
|
1405
|
+
* relevant", and `inhibited` means "a stronger twin already came back". One
|
|
1406
|
+
* ordinary question on a seventeen-memory store produced
|
|
1407
|
+
* `{"below-floor": 12}` — twelve memories that simply had nothing to do with
|
|
1408
|
+
* what was asked.
|
|
1409
|
+
*
|
|
1410
|
+
* `dim-cap:*` IS a refusal: those memories were reachable by effort and the
|
|
1411
|
+
* cap is what stopped them.
|
|
1412
|
+
*
|
|
1413
|
+
* `confidential-withheld` is deliberately NOT read, though the row keeps it.
|
|
1414
|
+
* It is the one verdict this package holds silent to the asker (§9.1 G5), and
|
|
1415
|
+
* every reader of this table renders to a screen — a console, a dashboard
|
|
1416
|
+
* panel — which is a third audience that gets screenshotted and screen-shared.
|
|
1417
|
+
* The row is for the owner reading their own store; a rendered line is not the
|
|
1418
|
+
* same thing, and the difference is the whole of the confidentiality rule.
|
|
1419
|
+
*/
|
|
1420
|
+
"mcp.recall": (p) =>
|
|
1421
|
+
countsIn(p, "blockedBy").filter(([reason]) => reason.startsWith("dim-cap:")),
|
|
1422
|
+
// `rendered` is the turn that surfaced something; every other reason is a turn
|
|
1423
|
+
// that decided to stay quiet, which is what a refusal is here.
|
|
1424
|
+
"recall.decision": (p) => {
|
|
1425
|
+
const reason = str(p, "reason");
|
|
1426
|
+
return reason === null || reason === "rendered" ? [] : [[reason, 1]];
|
|
1427
|
+
},
|
|
1428
|
+
};
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* A row that IS a refusal: its `reason`, counted once.
|
|
1432
|
+
*
|
|
1433
|
+
* A row with no readable `reason` still counts (2026-09-20). It used to return
|
|
1434
|
+
* nothing at all, so a store holding an `adapter.spawn.refused` row with a
|
|
1435
|
+
* malformed payload reported the worker as never refused — the store knew and
|
|
1436
|
+
* the view said otherwise, which is the exact failure this whole page is about.
|
|
1437
|
+
* `UNNAMED` is what a reader sees instead, and it is the truth: something was
|
|
1438
|
+
* turned away and the row does not say what by.
|
|
1439
|
+
*/
|
|
1440
|
+
export const UNNAMED_REFUSAL = "(no reason recorded)";
|
|
1441
|
+
|
|
1442
|
+
function reasonOnce(p: Record<string, unknown>): [string, number][] {
|
|
1443
|
+
return [[str(p, "reason") ?? UNNAMED_REFUSAL, 1]];
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
function countsIn(p: Record<string, unknown>, key: string): [string, number][] {
|
|
1447
|
+
const raw = p[key];
|
|
1448
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return [];
|
|
1449
|
+
const out: [string, number][] = [];
|
|
1450
|
+
for (const [reason, n] of Object.entries(raw as Record<string, unknown>)) {
|
|
1451
|
+
if (typeof n === "number" && n > 0) out.push([reason, n]);
|
|
1452
|
+
}
|
|
1453
|
+
return out;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
function str(p: Record<string, unknown>, key: string): string | null {
|
|
1457
|
+
const v = p[key];
|
|
1458
|
+
return typeof v === "string" && v.length > 0 ? v : null;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
// ── the table probes ────────────────────────────────────────────────────────
|
|
1462
|
+
|
|
1463
|
+
interface ProbeTally {
|
|
1464
|
+
total: number;
|
|
1465
|
+
/** The newest LIVED day this table records, or null when it records none. */
|
|
1466
|
+
lastLivedDay: number | null;
|
|
1467
|
+
/** The newest wall-clock instant, where the table keeps one. */
|
|
1468
|
+
lastAt: number | null;
|
|
1469
|
+
/** Counted PER ROW, like the log's: a table whose newest row is inside the
|
|
1470
|
+
* window has not put every row it holds inside the window. */
|
|
1471
|
+
inWindow: number;
|
|
1472
|
+
inPreviousWindow: number;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
interface Probed {
|
|
1476
|
+
readonly byId: ReadonlyMap<string, ProbeTally>;
|
|
1477
|
+
readonly livedDay: number;
|
|
1478
|
+
readonly truncated: boolean;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
/**
|
|
1482
|
+
* The five tables the inventory's §5(b) named, read in ONE pass over the ids.
|
|
1483
|
+
*
|
|
1484
|
+
* `Store` offers no aggregate over `edges`, `prospective` or `versions` and no
|
|
1485
|
+
* `protected` field on `MemoryFilter` — every one of those is keyed by a memory
|
|
1486
|
+
* id — so this costs a few queries per memory and is bounded by `PROBE_CEILING`.
|
|
1487
|
+
* It is the read the console and the dashboard pay and the session-start reading
|
|
1488
|
+
* does not.
|
|
1489
|
+
*/
|
|
1490
|
+
function readProbes(store: Store, w: Window): Probed {
|
|
1491
|
+
const byId = new Map<string, ProbeTally>();
|
|
1492
|
+
const livedDay = store.livedDay();
|
|
1493
|
+
const bump = (id: string, at: { livedDay?: number | null; at?: number | null } = {}): void => {
|
|
1494
|
+
let t = byId.get(id);
|
|
1495
|
+
if (t === undefined) {
|
|
1496
|
+
t = { total: 0, lastLivedDay: null, lastAt: null, inWindow: 0, inPreviousWindow: 0 };
|
|
1497
|
+
byId.set(id, t);
|
|
1498
|
+
}
|
|
1499
|
+
t.total += 1;
|
|
1500
|
+
const day = at.livedDay ?? null;
|
|
1501
|
+
if (day !== null && (t.lastLivedDay === null || day > t.lastLivedDay)) t.lastLivedDay = day;
|
|
1502
|
+
const when = at.at ?? null;
|
|
1503
|
+
if (when !== null && (t.lastAt === null || when > t.lastAt)) t.lastAt = when;
|
|
1504
|
+
// A wall clock answers in calendar days, which is the window this page uses.
|
|
1505
|
+
// A lived day is all some of these tables keep, and a lived day spans one
|
|
1506
|
+
// calendar day or more, so that window is a superset of the calendar one —
|
|
1507
|
+
// the row prints `lived day N` rather than a date so the reader can see
|
|
1508
|
+
// which clock answered.
|
|
1509
|
+
if (when !== null) {
|
|
1510
|
+
const date = dateOf(when);
|
|
1511
|
+
if (date >= w.from && date <= w.to) t.inWindow += 1;
|
|
1512
|
+
else if (date >= w.previousFrom && date <= w.previousTo) t.inPreviousWindow += 1;
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
if (day === null) return;
|
|
1516
|
+
const ago = livedDay - day;
|
|
1517
|
+
if (ago < FIRED_DAYS) t.inWindow += 1;
|
|
1518
|
+
else if (ago < FIRED_DAYS * 2) t.inPreviousWindow += 1;
|
|
1519
|
+
};
|
|
1520
|
+
|
|
1521
|
+
for (const record of store.removalRecord()) bump("removals", { at: record.at });
|
|
1522
|
+
|
|
1523
|
+
const ids = store.list();
|
|
1524
|
+
const scanned = ids.length > PROBE_CEILING ? ids.slice(0, PROBE_CEILING) : ids;
|
|
1525
|
+
for (const id of scanned) {
|
|
1526
|
+
const row = store.row(id);
|
|
1527
|
+
if (row !== undefined && row.archived === 0 && row.protected === 1) bump("protected");
|
|
1528
|
+
for (const edge of store.edgesFrom(id)) bump("edges", { livedDay: edge.last_day });
|
|
1529
|
+
for (const p of store.prospectiveFor(id)) {
|
|
1530
|
+
bump("prospective.armed");
|
|
1531
|
+
if (p.last_fired_day !== null) bump("prospective.fired", { livedDay: p.last_fired_day });
|
|
1532
|
+
}
|
|
1533
|
+
for (const v of store.versions(id)) {
|
|
1534
|
+
bump(`versions:${v.reason}`, { livedDay: v.version_day, at: v.archived_at });
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
return { byId, livedDay, truncated: scanned.length < ids.length };
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
function probeReading(probe: ProbeId, undated: string | null, probed: Probed | null): Reading {
|
|
1541
|
+
const base: Reading = {
|
|
1542
|
+
...EMPTY_READING,
|
|
1543
|
+
evidence: probeLabel(probe),
|
|
1544
|
+
refusalEvidence: probeLabel(probe),
|
|
1545
|
+
};
|
|
1546
|
+
if (probed === null) return { ...base, blind: "the tables were not read on this pass" };
|
|
1547
|
+
const t = probed.byId.get(probe);
|
|
1548
|
+
if (t === undefined || t.total === 0) return base;
|
|
1549
|
+
const counted = {
|
|
1550
|
+
...base,
|
|
1551
|
+
total: t.total,
|
|
1552
|
+
inWindow: t.inWindow,
|
|
1553
|
+
inPreviousWindow: t.inPreviousWindow,
|
|
1554
|
+
};
|
|
1555
|
+
if (t.lastAt !== null) {
|
|
1556
|
+
return { ...counted, lastFired: dateOf(t.lastAt), lastFiredIsDate: true };
|
|
1557
|
+
}
|
|
1558
|
+
if (t.lastLivedDay !== null) {
|
|
1559
|
+
return {
|
|
1560
|
+
...counted,
|
|
1561
|
+
lastFired: `lived day ${String(t.lastLivedDay)}`,
|
|
1562
|
+
lastFiredIsDate: false,
|
|
1563
|
+
};
|
|
1564
|
+
}
|
|
1565
|
+
// Rows, and no date of any kind behind them: a count that cannot answer the
|
|
1566
|
+
// question this page asks. `undated` is the line that says so.
|
|
1567
|
+
return {
|
|
1568
|
+
...base,
|
|
1569
|
+
total: t.total,
|
|
1570
|
+
blind: undated ?? "this table records no date, so nothing says when it last happened",
|
|
1571
|
+
};
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
function probeLabel(probe: ProbeId): string {
|
|
1575
|
+
if (probe.startsWith("versions:")) return `versions (${probe.slice("versions:".length)})`;
|
|
1576
|
+
if (probe === "protected") return "memories marked permanent";
|
|
1577
|
+
if (probe === "removals") return "the removal record";
|
|
1578
|
+
if (probe === "edges") return "the links table";
|
|
1579
|
+
return `the ${probe.replace(".", " ")} table`;
|
|
1580
|
+
}
|