counterparts 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/CHANGELOG.md +153 -0
  2. package/docs/module-map.md +3 -2
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/NOTES.md +28 -0
  5. package/src/adapters/claude-code/bin/hook.ts +85 -22
  6. package/src/adapters/claude-code/config.ts +7 -0
  7. package/src/adapters/claude-code/doctor.ts +166 -4
  8. package/src/adapters/claude-code/hooks.ts +185 -6
  9. package/src/adapters/claude-code/index.ts +3 -0
  10. package/src/adapters/claude-code/transcript.ts +7 -0
  11. package/src/adapters/cli/CONTRACT.md +11 -0
  12. package/src/adapters/cli/INTERFACE-GAPS.md +16 -0
  13. package/src/adapters/cli/NOTES.md +25 -0
  14. package/src/adapters/cli/commands.ts +184 -4
  15. package/src/adapters/cli/dream-core.ts +126 -0
  16. package/src/adapters/cli/help.ts +17 -0
  17. package/src/adapters/cli/mechanisms.ts +199 -106
  18. package/src/adapters/dashboard/CONTRACT.md +5 -0
  19. package/src/adapters/dashboard/INTERFACE-GAPS.md +12 -0
  20. package/src/adapters/dashboard/NOTES.md +38 -0
  21. package/src/adapters/dashboard/registries.ts +35 -1
  22. package/src/adapters/dashboard/web/README.md +63 -26
  23. package/src/adapters/dashboard/web/app.html +2 -0
  24. package/src/adapters/dashboard/web/flow.ts +14 -0
  25. package/src/adapters/dashboard/web/lanes.ts +141 -0
  26. package/src/adapters/dashboard/web/mechanisms/association/index.js +1 -2
  27. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +8 -5
  28. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +7 -7
  29. package/src/adapters/dashboard/web/mechanisms/decay/index.js +1 -2
  30. package/src/adapters/dashboard/web/mechanisms/dreaming/index.js +19 -0
  31. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +9 -6
  32. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +4 -5
  33. package/src/adapters/dashboard/web/mechanisms/index.js +5 -3
  34. package/src/adapters/dashboard/web/mechanisms/interference/index.js +1 -2
  35. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +7 -5
  36. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +1 -2
  37. package/src/adapters/dashboard/web/mechanisms/regions.js +1 -1
  38. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +1 -2
  39. package/src/adapters/dashboard/web/mechanisms/salience/index.js +1 -2
  40. package/src/adapters/dashboard/web/mechanisms/schema/index.js +1 -2
  41. package/src/adapters/dashboard/web/narrate.ts +76 -13
  42. package/src/adapters/dashboard/web/pages/health/sections/checks.js +17 -1
  43. package/src/adapters/dashboard/web/pages/home/home.css +29 -13
  44. package/src/adapters/dashboard/web/pages/home/index.js +2 -0
  45. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +22 -7
  46. package/src/adapters/dashboard/web/pages/home/sections/hero.js +15 -3
  47. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +15 -9
  48. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +6 -2
  49. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +35 -18
  50. package/src/adapters/dashboard/web/pages/memories/index.js +30 -36
  51. package/src/adapters/dashboard/web/pages/memories/memories.css +97 -72
  52. package/src/adapters/dashboard/web/pages/memories/row.js +51 -0
  53. package/src/adapters/dashboard/web/pages/memories/sections/feel.js +176 -0
  54. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +67 -0
  55. package/src/adapters/dashboard/web/pages/memories/sections/list.js +65 -43
  56. package/src/adapters/dashboard/web/pages/memories/sections/search.js +26 -23
  57. package/src/adapters/dashboard/web/pages/memories/state.js +12 -5
  58. package/src/adapters/dashboard/web/pages/self/index.js +57 -16
  59. package/src/adapters/dashboard/web/pages/self/sections/dreams.js +76 -0
  60. package/src/adapters/dashboard/web/pages/self/sections/journal.js +75 -19
  61. package/src/adapters/dashboard/web/pages/self/sections/page.js +108 -65
  62. package/src/adapters/dashboard/web/pages/self/sections/settling.js +129 -104
  63. package/src/adapters/dashboard/web/pages/self/sections/wake.js +31 -15
  64. package/src/adapters/dashboard/web/pages/self/self.css +122 -59
  65. package/src/adapters/dashboard/web/pages/self/state.js +21 -0
  66. package/src/adapters/dashboard/web/server.ts +9 -0
  67. package/src/adapters/dashboard/web/shared/memory-marks.css +17 -0
  68. package/src/adapters/dashboard/web/shared/memory-marks.js +81 -0
  69. package/src/adapters/dashboard/web/shared/memory-modal.js +240 -53
  70. package/src/adapters/dashboard/web/shared/modal.css +67 -0
  71. package/src/adapters/dashboard/web/shared/tip.js +1 -1
  72. package/src/adapters/dashboard/web/shared/widgets/feed.css +4 -0
  73. package/src/adapters/dashboard/web/shared/widgets/feed.js +56 -14
  74. package/src/adapters/dashboard/web/shared/widgets/light.css +1 -0
  75. package/src/adapters/dashboard/web/shared/widgets/light.js +7 -5
  76. package/src/adapters/dashboard/web/shared/widgets/tips.css +19 -0
  77. package/src/adapters/dashboard/web/shared/widgets/tips.js +56 -0
  78. package/src/adapters/dashboard/web/views/activity.ts +18 -2
  79. package/src/adapters/dashboard/web/views/archive-words.ts +27 -10
  80. package/src/adapters/dashboard/web/views/dreams.ts +199 -0
  81. package/src/adapters/dashboard/web/views/mechanism-panel.ts +116 -35
  82. package/src/adapters/dashboard/web/views/mechanisms.ts +81 -255
  83. package/src/adapters/dashboard/web/views/memories.ts +245 -43
  84. package/src/adapters/dashboard/web/views/memory-words.ts +133 -0
  85. package/src/adapters/dashboard/web/views/memory.ts +226 -4
  86. package/src/adapters/dashboard/web/views/mind.ts +261 -61
  87. package/src/adapters/dashboard/web/views/overview.ts +80 -42
  88. package/src/adapters/dashboard/web/views/search.ts +35 -1
  89. package/src/adapters/dashboard/web/views/shared.ts +14 -0
  90. package/src/adapters/dashboard/web/views.ts +2 -0
  91. package/src/adapters/feelings-line.ts +74 -0
  92. package/src/adapters/fired.ts +163 -23
  93. package/src/adapters/mcp/CONTRACT.md +8 -0
  94. package/src/adapters/mcp/NOTES.md +56 -0
  95. package/src/adapters/mcp/server.ts +254 -6
  96. package/src/adapters/mcp/tools.ts +180 -5
  97. package/src/adapters/mechanism-evidence.ts +465 -0
  98. package/src/core/bridge.ts +21 -16
  99. package/src/core/counterpart.ts +422 -10
  100. package/src/core/dream/CONTRACT.md +143 -0
  101. package/src/core/dream/INTERFACE-GAPS.md +24 -0
  102. package/src/core/dream/NOTES.md +84 -0
  103. package/src/core/dream/index.ts +1067 -0
  104. package/src/core/dream/mark.ts +14 -0
  105. package/src/core/dream/tunables.ts +56 -0
  106. package/src/core/encode/CONTRACT.md +7 -1
  107. package/src/core/feelings-wheel.ts +171 -13
  108. package/src/core/mint.ts +9 -0
  109. package/src/core/physics/CONTRACT.md +132 -21
  110. package/src/core/physics/NOTES.md +233 -0
  111. package/src/core/physics/index.ts +419 -50
  112. package/src/core/prospective/CONTRACT.md +35 -6
  113. package/src/core/prospective/INTERFACE-GAPS.md +10 -5
  114. package/src/core/prospective/NOTES.md +175 -4
  115. package/src/core/prospective/derive.ts +32 -3
  116. package/src/core/prospective/index.ts +362 -39
  117. package/src/core/prospective/tunables.ts +18 -1
  118. package/src/core/prospective/windows.ts +104 -46
  119. package/src/core/recall/CONTRACT.md +28 -0
  120. package/src/core/recall/NOTES.md +55 -0
  121. package/src/core/recall/activate.ts +32 -5
  122. package/src/core/recall/gate.ts +7 -1
  123. package/src/core/recall/index.ts +28 -2
  124. package/src/core/recall/mood.ts +106 -0
  125. package/src/core/recall/tunables.ts +26 -0
  126. package/src/core/remember/CONTRACT.md +5 -0
  127. package/src/core/remember/index.ts +1 -0
  128. package/src/core/remember/proposals.ts +86 -3
  129. package/src/core/remember/spans.ts +11 -1
  130. package/src/core/self/CONTRACT.md +3 -0
  131. package/src/core/self/INTERFACE-GAPS.md +7 -0
  132. package/src/core/self/NOTES.md +30 -0
  133. package/src/core/self/identity.ts +115 -6
  134. package/src/core/self/index.ts +17 -0
  135. package/src/core/self/tunables.ts +17 -0
  136. package/src/core/sleep/CONTRACT.md +17 -1
  137. package/src/core/sleep/INTERFACE-GAPS.md +19 -0
  138. package/src/core/sleep/NOTES.md +36 -0
  139. package/src/core/sleep/consolidate.ts +149 -96
  140. package/src/core/sleep/decay.ts +11 -0
  141. package/src/core/sleep/index.ts +4 -1
  142. package/src/core/sleep/tunables.ts +9 -0
  143. package/src/core/sleep/types.ts +17 -0
  144. package/src/core/sleep/upgrade.ts +168 -0
  145. package/src/core/store/CONTRACT.md +21 -2
  146. package/src/core/store/NOTES.md +68 -0
  147. package/src/core/store/feelings.ts +23 -6
  148. package/src/core/store/index.ts +716 -17
  149. package/src/core/store/operational.ts +329 -4
  150. package/src/core/store/owner-op-seam.ts +79 -1
  151. package/src/core/types.ts +37 -0
  152. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +0 -178
  153. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +0 -42
@@ -804,3 +804,39 @@ What changed:
804
804
  2026-09-25: `adapters/fired.ts` lists it now — row `fade`, read off the `sleep.cycle` row
805
805
  only where `faded > 0` (the new `Evidence.positive` filter) — with no refusal column, because
806
806
  `fade/blocked:*` counts every blocker of every card that stayed, not the deciding one.
807
+
808
+ ## 18. The core's lanes, the cap, and the upgrade census — 2026-09-26
809
+
810
+ *Owner decisions of 2026-09-26 (dreaming + consolidation). Physics NOTES "Returns, core
811
+ lanes and the v8 upgrade" has the arithmetic and the simulations; this is the phase.*
812
+
813
+ - **The order inside the phase is unchanged**: legacy marking, then the crossing. The
814
+ marking now refuses every post-upgrade row `not-legacy` (physics' own reason, mirrored
815
+ into the skip map like the others).
816
+ - **Who is "about me" is read here**, because it needs words: `self` kind always; a
817
+ `person` memory when its title, body, `meta.name` or `meta.entity` names the owner as a
818
+ whole word — the names come off the identity core (`kind: self`, `role: entity`), read
819
+ structurally like `isThePage`, so `sleep/` still imports nothing from `self/`. With no
820
+ name configured, only `self` qualifies. The prose read is paid by `self` and `person`
821
+ rows alone.
822
+ - **The cap collects, then crosses**: eligible rows are gathered over the pass, sorted by
823
+ strength (ties by id), and the first `CORE_MAX_PER_SLEEP` cross. The rest are counted
824
+ `promotion:cap`; they are still eligible at the next consolidation (three lived days
825
+ on). A budget-truncated pass caps only what it visited — a budget is not a debt.
826
+ - **A crossing writes four things, record first**: the meta record, the durable
827
+ `band.promoted` event (now with `lane`, `intensity`, `returnDays`), a `core_events`
828
+ row, then the flag and the band. A port without `appendCoreEvent` writes the other three.
829
+ - **The census** (`upgrade.ts`) runs at the start of the first decay pass after a v8
830
+ upgrade and never again (the meta row is its latch). It compares each row by the v8
831
+ arithmetic and by the same row with its returns set aside — which IS the pre-v8
832
+ formula, since the returns factor is the only term v8 added and a legacy row keeps its
833
+ path. Measured on a real v7 demo store: 145 rows, 0 down, 0 weaker, 0 prune sooner.
834
+ A failure is an event and never costs the tick.
835
+
836
+
837
+ **After the review of #251 (2026-09-26, working defaults).**
838
+ - The slow lane needs the semantic floor on the day it promotes (physics
839
+ `CORE_SLOW_FLOOR`); `promote` passes the day.
840
+ - The upgrade census also counts `v7WouldPromote`: legacy rows the old rules were about
841
+ to make core. They are let go under the new rule and take the durability route (their
842
+ reinforcement days became legacy returns at the migration). Doctor says so, in green.
@@ -1,41 +1,46 @@
1
1
  /**
2
- * Consolidation marking, and the ONE place identity promotion happens.
2
+ * Consolidation, and the ONE place identity promotion happens.
3
3
  *
4
- * Two jobs, in this order, because the second depends on the first:
4
+ * Redesigned 2026-09-26 with the owner (dreaming + consolidation). Two jobs:
5
5
  *
6
- * 1. **Consolidation marking.** A memory that has survived at least one lived day
7
- * past its birth and now sits at or above the semantic floor gets
8
- * `consolidated = true`, which is worth `+CONS_BONUS` to `base` for the rest
9
- * of its life (`physics/` §5.2). This is the replay-and-integrate pass, on
10
- * v0's 3-lived-day cadence.
6
+ * 1. **The LEGACY consolidation marking.** Until schema v8 a memory that had
7
+ * survived a lived day at or above the semantic floor was marked
8
+ * `consolidated`, worth a one-time `+CONS_BONUS` to `base` for the rest of
9
+ * its life. That path is now open ONLY to memories born before the upgrade
10
+ * (`legacy`, physics §5.2) — exactly the rows that had it — so the upgrade
11
+ * moves nothing down a band and prunes nothing sooner. Every memory made
12
+ * since earns durability from RETURNS instead (physics §5.11): each spaced
13
+ * return slows its fading, credited at the moment of the use (or of a
14
+ * dream's replay), not here. The criterion is still physics'
15
+ * (`consolidationEligibility`), and a post-upgrade memory is refused
16
+ * `not-legacy` by it.
11
17
  *
12
- * The criterion MOVED to `physics.consolidationEligibility()` on 2026-08-25
13
- * (SEAMS item M, INTERFACE-GAPS.md §5). This phase now executes a crossing it
14
- * does not define — the shape the whole contract is built on, and the same
15
- * relationship it already had with `promotionEligibility`. The property the
16
- * old inline criterion was written to protect travelled with it: there is
17
- * deliberately NO reinforcement requirement, because "a formative one-shot
18
- * consolidates without repetition" is a property physics protects with a
19
- * `max`, and a repetition gate would quietly repeal it.
18
+ * 2. **Core promotion — HERE AND ONLY HERE**, now by LANES (physics §5.3):
19
+ * only a memory about me or about us (`self`, or a `person` memory about the
20
+ * owner) can become core, by the fast lane (strongly felt, and it came back
21
+ * after a gap) or the slow lane (it kept coming back over weeks). Physics
22
+ * decides eligibility; this phase decides who is ABOUT ME (it can read the
23
+ * words and the owner's names), honours the owner's demotions, and caps the
24
+ * night at `CORE_MAX_PER_SLEEP`, strongest first — the rest wait for the
25
+ * next consolidation. The crossing is an EXPLICIT, COUNTED EVENT with a
26
+ * persisted record carrying its lane, never an emergent side effect of a
27
+ * number drifting past a line (scar §2.4). Nothing is born into identity;
28
+ * this and revision inheritance are the only two doors, and a dream's
29
+ * nomination is not one (`core/dream/`).
20
30
  *
21
- * 2. **Identity promotion — HERE AND ONLY HERE.** Physics decides eligibility
22
- * (`base >= THETA_ID` AND reinforcement on >= N = 3 DISTINCT lived days);
23
- * sleep executes the crossing. The crossing is an EXPLICIT, COUNTED EVENT
24
- * with a persisted §5.3 record — never an emergent side effect of a number
25
- * drifting past a line (scar §2.4). Nothing is born into identity; this and
26
- * revision inheritance are the only two doors.
27
- *
28
- * Ordering matters: consolidation runs first *within* this phase, so the
29
- * `+0.2` it grants is visible to the promotion test in the same cycle. That
30
- * is the intended path into the identity band, not an accident of sequencing.
31
+ * Arithmetic only: this phase never calls a model.
31
32
  */
32
33
 
33
- import { consolidationEligibility, promote } from "../physics/index.js";
34
- import type { PromotionReason } from "../physics/index.js";
34
+ import { consolidationEligibility, promote, strength } from "../physics/index.js";
35
+ import type { PromotionCrossing, PromotionReason } from "../physics/index.js";
35
36
  import { rowToPhysics } from "../store/operational.js";
37
+ import type { MemoryRow } from "../store/operational.js";
36
38
  import { readCursor, resumeIndex, writeCursor } from "./markers.js";
37
- import { PROMOTION_RECORD_PREFIX } from "./tunables.js";
38
- import type { Phase, PhaseCtx, PhaseOutcome, PromotionRecord } from "./types.js";
39
+ import { PROMOTION_RECORD_PREFIX, TUNABLES } from "./tunables.js";
40
+ import type { Phase, PhaseCtx, PhaseOutcome, PromotionRecord, SleepStore } from "./types.js";
41
+
42
+ /** The two reads "who is this about" needs — a read-only store has both. */
43
+ export type ReadsDocs = Pick<SleepStore, "list" | "read">;
39
44
  import { countSkip, emptyOutcome, isJournal } from "./types.js";
40
45
 
41
46
  /** This phase's own name, for the cursor it keeps. Typed, so a rename in the
@@ -48,6 +53,7 @@ export const CONSOLIDATION_SKIPS = [
48
53
  "archived",
49
54
  "removed",
50
55
  "journal",
56
+ "not-legacy",
51
57
  "already-consolidated",
52
58
  "born-today",
53
59
  "below-semantic-floor",
@@ -71,10 +77,6 @@ export function promotionRecordKey(id: string): string {
71
77
  * `self/page.ts` — `sleep/` depends on nothing in `self/`, and a shape check
72
78
  * that fails reads as "not the page", which is master's behaviour and therefore
73
79
  * the safe direction. The role string's owner is `self/page.ts#SELF_PAGE_ROLE`.
74
- *
75
- * Only ever called for a `type: "schema"`, `kind: "self"` row, so the prose read
76
- * costs the page, the identity core and any belief held about the self — two or
77
- * three rows on a real store, once per cycle each.
78
80
  */
79
81
  function isThePage(store: PhaseCtx["store"], id: string): boolean {
80
82
  try {
@@ -84,31 +86,91 @@ function isThePage(store: PhaseCtx["store"], id: string): boolean {
84
86
  }
85
87
  }
86
88
 
89
+ /**
90
+ * The OWNER's names, read off the identity core — the one `kind: "self"`
91
+ * schema row with `role: "entity"`, which install seeds with the owner's name
92
+ * (`self/identity.ts#IDENTITY_CORE_ROLE`, `init --name`). Read structurally for
93
+ * `isThePage`'s reason. Lower-cased; empty when no core was ever named, and then
94
+ * no `person` memory can be told to be about him and only `self` qualifies.
95
+ */
96
+ export function ownerNames(store: ReadsDocs): string[] {
97
+ const out: string[] = [];
98
+ for (const id of store.list({ type: "schema", kind: "self", archived: false })) {
99
+ try {
100
+ const meta = store.read(id).doc.meta;
101
+ if (meta["role"] !== "entity") continue;
102
+ const add = (v: unknown): void => {
103
+ if (typeof v === "string" && v.trim().length >= 2) out.push(v.trim().toLowerCase());
104
+ };
105
+ add(meta["name"]);
106
+ const aliases = meta["aliases"];
107
+ if (Array.isArray(aliases)) for (const a of aliases) add(a);
108
+ } catch {
109
+ continue;
110
+ }
111
+ }
112
+ return [...new Set(out)];
113
+ }
114
+
115
+ /** Does `text` name any of `names` as a whole word (case-insensitive)? */
116
+ function names(text: string, owner: readonly string[]): boolean {
117
+ const lower = text.toLowerCase();
118
+ for (const n of owner) {
119
+ const escaped = n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
120
+ if (new RegExp(`(^|[^\\p{L}\\p{N}])${escaped}($|[^\\p{L}\\p{N}])`, "u").test(lower)) return true;
121
+ }
122
+ return false;
123
+ }
124
+
125
+ /**
126
+ * IS THIS MEMORY ABOUT ME OR ABOUT US? — the core's first question (owner
127
+ * decision 2026-09-26). `self` kind always is. A `person` memory is when it
128
+ * names the owner (title, body, or its `name` / `entity` meta); a person memory
129
+ * about somebody else is not, and a `fact` that merely mentions him never is,
130
+ * whatever it says. Everything else is not.
131
+ */
132
+ export function aboutMe(store: ReadsDocs, row: Pick<MemoryRow, "id" | "kind">, owner: readonly string[]): boolean {
133
+ if (row.kind === "self") return true;
134
+ if (row.kind !== "person" || owner.length === 0) return false;
135
+ try {
136
+ const doc = store.read(row.id).doc;
137
+ const meta = doc.meta;
138
+ const fields = [doc.title ?? "", doc.body, String(meta["name"] ?? ""), String(meta["entity"] ?? "")];
139
+ return fields.some((f) => f.length > 0 && names(f, owner));
140
+ } catch {
141
+ return false;
142
+ }
143
+ }
144
+
87
145
  export function runConsolidate(ctx: PhaseCtx): ConsolidateResult {
88
146
  const out = emptyOutcome();
89
147
  for (const skip of CONSOLIDATION_SKIPS) out.skipped[skip] = 0;
90
148
  const promotionBlocked: Record<string, number> = {};
91
149
  const consolidated: string[] = [];
92
150
  const promoted: PromotionRecord[] = [];
151
+ const block = (reason: string): void => {
152
+ promotionBlocked[reason] = (promotionBlocked[reason] ?? 0) + 1;
153
+ countSkip(out, `promotion:${reason}`);
154
+ };
93
155
 
94
156
  const { store, day } = ctx;
95
157
  const denied = new Set(store.deniedIds());
96
158
  const ids = store.list();
159
+ const owner = ownerNames(store);
97
160
 
98
161
  // WHERE THE LAST RUN STOPPED. `store.list()` is `ORDER BY id`, so the rotation
99
162
  // is stable and a cursor means something: this run resumes strictly after it
100
163
  // and wraps to the head once it reaches the end, visiting each id at most once
101
- // per run. A store larger than the budget is therefore covered in
102
- // ceil(N / budget) runs instead of the first budget's worth being re-examined
103
- // every night and the rest never. Measured 2026-09-17
104
- // (`docs/promotion-diagnosis-2026-09-17.md`): 15,292 rows against a budget of
105
- // 5,000, and 10,000+ memories had never once been asked whether they belong to
106
- // who the owner is. A budget is still not a debt (§3) — the marker still
107
- // advances and nothing is owed; only the STARTING PLACE moved.
164
+ // per run. A budget is still not a debt (§3) — the marker still advances and
165
+ // nothing is owed; only the STARTING PLACE moved
166
+ // (`docs/promotion-diagnosis-2026-09-17.md`).
108
167
  const start = resumeIndex(ids, readCursor(store, CONSOLIDATE_PHASE));
109
168
  let visited = 0;
110
169
  let stoppedAt: string | null = null;
111
170
 
171
+ /** Tonight's eligible crossings, before the cap. */
172
+ const eligible: { id: string; index: number; crossing: PromotionCrossing; strength: number }[] = [];
173
+
112
174
  while (visited < ids.length) {
113
175
  if (out.examined >= ctx.budget) {
114
176
  out.budgetExhausted = true;
@@ -139,9 +201,7 @@ export function runConsolidate(ctx: PhaseCtx): ConsolidateResult {
139
201
 
140
202
  let p = rowToPhysics(row);
141
203
 
142
- // ── 1. consolidation marking ────────────────────────────────────────────
143
- // Physics decides; this phase executes and counts. The skip vocabulary below
144
- // IS physics' reason vocabulary, so a reason cannot drift between them.
204
+ // ── 1. the legacy consolidation marking ─────────────────────────────────
145
205
  const eligibility = consolidationEligibility(p, day);
146
206
  if (!eligibility.eligible) {
147
207
  countSkip(out, eligibility.reason);
@@ -154,85 +214,78 @@ export function runConsolidate(ctx: PhaseCtx): ConsolidateResult {
154
214
  ctx.step("item", { index, id });
155
215
  }
156
216
 
157
- // ── 2. the identity crossing ────────────────────────────────────────────
158
- //
159
- // THE SELF PAGE DOES NOT CROSS (2026-09-18) — and nothing else changes.
160
- //
161
- // The page can be promoted: give it the physics repeated recall credit
162
- // leaves and forty cycles later it carries `promoted_identity`, `band
163
- // identity` and a `band.promoted` crossing record, on a row `scanActive` can
164
- // never rank, counted by the promotion diagnostics and printed by `status`
165
- // as an identity-band memory. The wake is unaffected; the telemetry is not.
217
+ // ── 2. the core lanes ───────────────────────────────────────────────────
166
218
  //
167
- // **The guard is THE PAGE and not schema rows generally**, which is where a
168
- // first attempt went wrong and the second review caught it: `physics#decay`
169
- // returns 1 for a promoted row, so withholding the crossing from beliefs,
170
- // current-states and entities would stop them becoming decay-exempt — a
171
- // retention change for three row classes across the owner's whole store,
172
- // measured at four rows crossing on master and none here, inside a PR about
173
- // one page. Whether a belief should cross at all is a real question with a
174
- // one-query answer nobody has yet; it is not this change's to take.
175
- //
176
- // The prose read is gated on the row's own columns, so only a schema row of
177
- // the self kind pays for it — the page, the identity core, and any belief
178
- // held about the self. The identity core is deliberately NOT exempted: it
179
- // could cross on master, and exempting it would be the same kind of quiet
180
- // retention change.
219
+ // THE SELF PAGE DOES NOT CROSS (2026-09-18): it can be given the physics a
220
+ // lane wants and would then carry `promoted_identity` on a row the wake can
221
+ // never rank. The guard is THE PAGE, not schema rows generally — see
222
+ // `sleep/NOTES.md` for why the identity core and beliefs are not exempted.
181
223
  if (row.type === "schema" && row.kind === "self" && isThePage(store, id)) {
182
- promotionBlocked["self-page"] = (promotionBlocked["self-page"] ?? 0) + 1;
183
- countSkip(out, "promotion:self-page");
224
+ block("self-page");
225
+ continue;
226
+ }
227
+ if (p.promotedIdentity) {
228
+ block("already-identity");
184
229
  continue;
185
230
  }
186
- const outcome = promote(p, day);
231
+ // Who it is about is asked only where it can matter — `self` and `person`
232
+ // — so the prose read is paid by those rows alone.
233
+ const about = aboutMe(store, row, owner);
234
+ const outcome = promote(p, day, {
235
+ aboutMe: about,
236
+ demoted: about ? (store.coreDemoted?.(id) ?? false) : false,
237
+ });
187
238
  if (!outcome.promoted || outcome.crossing === null) {
188
- // Promotion needs ALL conditions, so ALL blocking reasons are reported —
189
- // "base too low" and "not enough distinct days" are different diagnoses,
190
- // and mirrored into the skip map they reach the cycle report as well.
191
- for (const reason of outcome.verdict.blockedBy) {
192
- promotionBlocked[reason] = (promotionBlocked[reason] ?? 0) + 1;
193
- countSkip(out, `promotion:${reason}`);
194
- }
239
+ // Every blocking reason is reported: "not about me" and "no lane yet"
240
+ // are different diagnoses.
241
+ for (const reason of outcome.verdict.blockedBy) block(reason);
242
+ continue;
243
+ }
244
+ eligible.push({ id, index, crossing: outcome.crossing, strength: strength(p, day) });
245
+ }
246
+
247
+ // ── the nightly cap: strongest first, the rest wait ──────────────────────
248
+ eligible.sort((a, b) => b.strength - a.strength || (a.id < b.id ? -1 : 1));
249
+ const cap = TUNABLES.CORE_MAX_PER_SLEEP;
250
+ for (const [i, e] of eligible.entries()) {
251
+ if (i >= cap) {
252
+ block("cap");
195
253
  continue;
196
254
  }
197
- const record: PromotionRecord = { id, ...outcome.crossing };
255
+ const record: PromotionRecord = { id: e.id, ...e.crossing };
198
256
  if (ctx.apply) {
199
257
  // Record BEFORE the flag: a crossing nobody could account for afterwards
200
258
  // is exactly the emergent promotion this phase exists to replace. If the
201
259
  // record cannot be written, the memory does not cross.
202
- store.setMeta(promotionRecordKey(id), JSON.stringify(record));
260
+ store.setMeta(promotionRecordKey(e.id), JSON.stringify(record));
203
261
  store.appendEvent?.({
204
262
  name: record.event,
205
263
  day,
206
- ref: id,
207
- dedupKey: promotionRecordKey(id),
264
+ ref: e.id,
265
+ dedupKey: promotionRecordKey(e.id),
208
266
  payload: { ...record },
209
267
  });
210
- store.updatePhysics(id, { promotedIdentity: true });
211
- // The band column in box 2 is canonical for a crossing (it is a decision,
212
- // not a decay reading), and the crossing writes it FIRST. Since U8
213
- // (2026-09-14) decay writes the same column too — it brings every other
214
- // row to `band(m, d)` — so this is no longer the only writer; what it
215
- // still is, is the only writer of `identity`. Decay touches no OTHER
216
- // canonical state: no `uses`, no `lastUsedDay`, no prose (`sleep/NOTES.md`
217
- // §5).
218
- store.setBand(id, "identity", day);
268
+ store.appendCoreEvent?.({ memoryId: e.id, action: "promoted", day, lane: record.lane, actor: "sleep" });
269
+ store.updatePhysics(e.id, { promotedIdentity: true });
270
+ // The band column is canonical for a crossing (a decision, not a decay
271
+ // reading), and this is the only writer of `identity`.
272
+ store.setBand(e.id, "identity", day);
219
273
  }
220
274
  promoted.push(record);
221
275
  out.changed += 1;
222
- ctx.event("sleep.promoted", id, {
276
+ ctx.event("sleep.promoted", e.id, {
223
277
  kind: record.kind,
224
- base: record.base,
225
- reinforcedDays: record.reinforcedDays,
278
+ lane: record.lane,
279
+ intensity: record.intensity,
280
+ returnDays: record.returnDays,
226
281
  day,
227
282
  });
228
- ctx.step("item", { index, id });
283
+ ctx.step("item", { index: e.index, id: e.id });
229
284
  }
230
285
 
231
286
  // The cursor moves only where a row was actually visited, and only under
232
287
  // `apply`: an observer's read-only report may not move the store's place in
233
- // the store (§5 G10). A run killed mid-phase leaves the cursor where it was
234
- // and re-walks the same stretch, which is the marker's own bargain — replay a
235
- // day exactly once rather than skip it.
288
+ // the store (§5 G10).
236
289
  if (ctx.apply && stoppedAt !== null) writeCursor(store, CONSOLIDATE_PHASE, stoppedAt);
237
290
 
238
291
  return { ...out, consolidated, promoted, promotionBlocked };
@@ -68,6 +68,7 @@ import { rowToPhysics } from "../store/operational.js";
68
68
  import { TUNABLES } from "./tunables.js";
69
69
  import type { BandTransition, PhaseCtx, PhaseOutcome } from "./types.js";
70
70
  import { countSkip, emptyOutcome, isJournal, recordBandTransition } from "./types.js";
71
+ import { censusDue, upgradeCensus } from "./upgrade.js";
71
72
  import type { StrengthCache, StrengthRow } from "./strength-cache.js";
72
73
 
73
74
  /** Skip categories, enumerated so a zero is distinguishable from an absence. */
@@ -114,6 +115,16 @@ export interface DecayResult extends PhaseOutcome {
114
115
  export function runDecay(ctx: PhaseCtx, cache: StrengthCache | null): DecayResult {
115
116
  const out = emptyOutcome();
116
117
  for (const skip of DECAY_SKIPS) out.skipped[skip] = 0;
118
+ // Once per store, the first decay pass after the v8 upgrade measures every
119
+ // row old-vs-new (`upgrade.ts`). It is a READ plus one meta row; a failure
120
+ // here is recorded and never costs the tick.
121
+ if (ctx.apply && censusDue(ctx.store)) {
122
+ try {
123
+ upgradeCensus(ctx);
124
+ } catch (err) {
125
+ ctx.event("sleep.upgrade.census.failed", undefined, { error: err instanceof Error ? err.name : "UNKNOWN" });
126
+ }
127
+ }
117
128
 
118
129
  const { store, day } = ctx;
119
130
  const denied = new Set(store.deniedIds());
@@ -69,7 +69,10 @@ export type { StrengthCache, StrengthRow } from "./strength-cache.js";
69
69
  export { DECAY_SKIPS, runDecay } from "./decay.js";
70
70
  export type { DecayResult, DecaySkip } from "./decay.js";
71
71
 
72
- export { CONSOLIDATION_SKIPS, promotionRecordKey, runConsolidate } from "./consolidate.js";
72
+ export { CONSOLIDATION_SKIPS, aboutMe, ownerNames, promotionRecordKey, runConsolidate } from "./consolidate.js";
73
+ export { V8_CENSUS_EVENT, V8_CENSUS_KEY, V8_UPGRADE_KEY, censusDue, preV8, projectedPruneDay, upgradeCensus, v7WouldPromote } from "./upgrade.js";
74
+ export type { UpgradeCensus } from "./upgrade.js";
75
+ export type { ReadsDocs } from "./consolidate.js";
73
76
  export type { ConsolidateResult, ConsolidationSkip } from "./consolidate.js";
74
77
 
75
78
  export { inLiveRevisionChain, pruneRecordKey, runPrune } from "./prune.js";
@@ -15,6 +15,15 @@ export const TUNABLES = {
15
15
  /** Auto-consolidation cadence, in LIVED days [v0: every 3 days]. */
16
16
  CONSOLIDATION_EVERY_DAYS: 3,
17
17
 
18
+ /**
19
+ * At most this many memories become core in one sleep, strongest first
20
+ * (owner decision 2026-09-26: "~3 per sleep"). The rest stay eligible and
21
+ * wait for the next consolidation, counted as `promotion:cap` — a rail so a
22
+ * store that has just grown a lane of eligible memories does not rewrite
23
+ * who it is overnight. CAL.
24
+ */
25
+ CORE_MAX_PER_SLEEP: 3,
26
+
18
27
  /**
19
28
  * Below this change in cached strength, the row is left alone — CALM BY
20
29
  * DEFAULT (§3, v1 §11 G8). Exponential decay moves a floor memory by ~1e-9 a
@@ -120,6 +120,23 @@ export interface SleepStore {
120
120
  */
121
121
  pruneEvents?(opts?: { limit?: number }): EventPruneReport;
122
122
  eventLogCensus?(): EventLogCensus;
123
+ /**
124
+ * The CORE's history (schema v8, 2026-09-26), OPTIONAL like the log. Where
125
+ * the port has it, a promotion is also written here with its lane, and an
126
+ * owner's demotion read from here keeps the lanes from re-promoting the
127
+ * memory; a port without it demotes nothing and records the crossing in the
128
+ * meta row and the event log only.
129
+ */
130
+ appendCoreEvent?(input: {
131
+ memoryId: string;
132
+ action: "promoted" | "demoted" | "nominated";
133
+ day: number;
134
+ lane?: string | null;
135
+ reason?: string | null;
136
+ dreamId?: string | null;
137
+ actor?: string | null;
138
+ }): number;
139
+ coreDemoted?(id: string): boolean;
123
140
  }
124
141
 
125
142
  // ---------------------------------------------------------------------------
@@ -0,0 +1,168 @@
1
+ /**
2
+ * THE V8 UPGRADE CENSUS — the proof, on the owner's own rows, that the
3
+ * dreaming + consolidation redesign (2026-09-26) moved no memory down.
4
+ *
5
+ * The migration (`store/operational.ts`) marks every row it finds `legacy` and
6
+ * records what it found under `physics.v8.upgrade`. The FIRST decay pass after
7
+ * that runs this once: for every live memory it reads the band and the
8
+ * projected prune day (no further use) two ways — by the v8 arithmetic, and by
9
+ * the pre-v8 arithmetic (the same row with its returns set to zero, which is
10
+ * exactly the old formula: the returns factor is the only term v8 added, and a
11
+ * legacy row keeps its consolidation path) — and counts every difference by
12
+ * direction. By construction the down counts are zero; the census is how that
13
+ * is SEEN rather than asserted (constitution 11). The result is one meta row,
14
+ * `physics.v8.census`, and one durable event, and doctor prints it.
15
+ *
16
+ * Arithmetic only. Runs at most once per store: the meta row is its latch.
17
+ */
18
+
19
+ import {
20
+ TUNABLES as PHYSICS,
21
+ band,
22
+ base,
23
+ consolidationEligibility,
24
+ kindPhysics,
25
+ reinforcedDays,
26
+ rep,
27
+ sal,
28
+ stability,
29
+ strength,
30
+ } from "../physics/index.js";
31
+ import type { MemoryPhysics } from "../physics/index.js";
32
+ import { rowToPhysics } from "../store/operational.js";
33
+ import type { PhaseCtx } from "./types.js";
34
+ import { isJournal } from "./types.js";
35
+
36
+ export const V8_UPGRADE_KEY = "physics.v8.upgrade";
37
+ export const V8_CENSUS_KEY = "physics.v8.census";
38
+ export const V8_CENSUS_EVENT = "physics.upgrade.census";
39
+
40
+ export interface UpgradeCensus {
41
+ readonly day: number;
42
+ readonly checked: number;
43
+ readonly bandDown: number;
44
+ readonly bandUp: number;
45
+ /** Rows whose strength today is lower by the v8 arithmetic than by the old. */
46
+ readonly weaker: number;
47
+ readonly pruneSooner: number;
48
+ readonly pruneLater: number;
49
+ readonly legacy: number;
50
+ readonly consolidated: number;
51
+ /**
52
+ * THE ROAD THE UPGRADE CLOSED (adversarial review of #251): live rows the
53
+ * pre-v8 rule would have made identity at its next consolidation — `base`
54
+ * without the emotion lift (+ the consolidation bonus the same pass would
55
+ * have granted) at or above 0.85, reinforced on 3+ distinct lived days — and
56
+ * that v8's core lanes do not promote. Every band/strength/prune count above
57
+ * compares a row with itself at one moment, so it cannot see these: nothing
58
+ * moves at the upgrade, but these rows no longer have the future the old
59
+ * rules gave them. Absent on a census recorded before the review.
60
+ */
61
+ readonly v7WouldPromote?: number;
62
+ }
63
+
64
+ /**
65
+ * The lived day a memory would reach the prune floor with no further use, or
66
+ * null when it never will (identity, protected). Exponential decay only — the
67
+ * shipped shape; the other two are replay tools' (physics §5.4).
68
+ */
69
+ export function projectedPruneDay(m: MemoryPhysics): number | null {
70
+ if (m.promotedIdentity || m.protected) return null;
71
+ const b = base(m);
72
+ if (b <= PHYSICS.PHI_PRUNE) return m.lastUsedDay + PHYSICS.D_FLOOR_DAYS;
73
+ const reach = m.lastUsedDay + stability(m) * Math.log(b / PHYSICS.PHI_PRUNE);
74
+ return Math.max(Math.ceil(reach), m.lastUsedDay + PHYSICS.D_FLOOR_DAYS);
75
+ }
76
+
77
+ /**
78
+ * Would the PRE-v8 rule have promoted this row at a consolidation on `day`?
79
+ * v7's `promotionBase` (`max(wSal x sal, wRep x rep) + cons`, no emotion lift)
80
+ * at or above its `THETA_ID` of 0.85, and reinforcement on at least its N = 3
81
+ * distinct lived days — with the consolidation mark the same pass would have
82
+ * set first counted in, as v7 ordered it. Legacy rows only: a row made since
83
+ * the upgrade never had the old rules.
84
+ */
85
+ export function v7WouldPromote(m: MemoryPhysics, day: number): boolean {
86
+ if (m.legacy !== true || m.promotedIdentity) return false;
87
+ const k = kindPhysics(m.kind);
88
+ const marked = m.consolidated || consolidationEligibility(m, day).eligible;
89
+ const b = Math.max(k.wSal * sal(m.salience), k.wRep * rep(m)) + (marked ? PHYSICS.CONS_BONUS : 0);
90
+ return b >= V7_THETA_ID && reinforcedDays(m) >= V7_PROMOTION_DAYS;
91
+ }
92
+
93
+ /** The pre-v8 identity threshold and distinct-day count, kept here for the census alone. */
94
+ const V7_THETA_ID = 0.85;
95
+ const V7_PROMOTION_DAYS = 3;
96
+
97
+ /** The same row by the pre-v8 formula: its returns set aside. */
98
+ export function preV8(m: MemoryPhysics): MemoryPhysics {
99
+ return { ...m, returns: 0 };
100
+ }
101
+
102
+ /** Is the census due — an upgrade recorded and no census yet? */
103
+ export function censusDue(store: PhaseCtx["store"]): boolean {
104
+ return store.getMeta(V8_UPGRADE_KEY) !== undefined && store.getMeta(V8_CENSUS_KEY) === undefined;
105
+ }
106
+
107
+ /** Run the census over every live memory and (under `apply`) record it once. */
108
+ export function upgradeCensus(ctx: PhaseCtx): UpgradeCensus {
109
+ const { store, day } = ctx;
110
+ const denied = new Set(store.deniedIds());
111
+ let checked = 0;
112
+ let bandDown = 0;
113
+ let bandUp = 0;
114
+ let pruneSooner = 0;
115
+ let pruneLater = 0;
116
+ let legacy = 0;
117
+ let consolidated = 0;
118
+ let weaker = 0;
119
+ let closedRoad = 0;
120
+ const rank = { episodic: 0, semantic: 1, identity: 2 } as const;
121
+ for (const id of store.list({ archived: false })) {
122
+ if (denied.has(id)) continue;
123
+ const row = store.row(id);
124
+ if (row === undefined || row.archived === 1 || isJournal(row)) continue;
125
+ const now = rowToPhysics(row);
126
+ const old = preV8(now);
127
+ checked += 1;
128
+ if (now.legacy === true) legacy += 1;
129
+ if (now.consolidated) consolidated += 1;
130
+ if (row.type !== "schema" || row.kind !== "self") {
131
+ if (v7WouldPromote(now, day)) closedRoad += 1;
132
+ }
133
+ const move = rank[band(now, day)] - rank[band(old, day)];
134
+ if (move < 0) bandDown += 1;
135
+ else if (move > 0) bandUp += 1;
136
+ // The strength too, so a drop inside a band could never hide behind "no band moved".
137
+ if (strength(now, day) < strength(old, day) - 1e-12) weaker += 1;
138
+ const pNow = projectedPruneDay(now);
139
+ const pOld = projectedPruneDay(old);
140
+ if (pNow !== null && pOld !== null) {
141
+ if (pNow < pOld) pruneSooner += 1;
142
+ else if (pNow > pOld) pruneLater += 1;
143
+ }
144
+ }
145
+ const census: UpgradeCensus = {
146
+ day,
147
+ checked,
148
+ bandDown,
149
+ bandUp,
150
+ weaker,
151
+ pruneSooner,
152
+ pruneLater,
153
+ legacy,
154
+ consolidated,
155
+ v7WouldPromote: closedRoad,
156
+ };
157
+ if (ctx.apply) {
158
+ store.setMeta(V8_CENSUS_KEY, JSON.stringify(census));
159
+ store.appendEvent?.({
160
+ name: V8_CENSUS_EVENT,
161
+ day,
162
+ dedupKey: V8_CENSUS_EVENT,
163
+ payload: { ...census },
164
+ });
165
+ }
166
+ ctx.event("sleep.upgrade.census", undefined, { ...census });
167
+ return census;
168
+ }