counterparts 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/docs/module-map.md +2 -0
  3. package/package.json +2 -1
  4. package/src/adapters/claude-code/CONTRACT.md +2 -1
  5. package/src/adapters/claude-code/NOTES.md +90 -2
  6. package/src/adapters/claude-code/bin/hook.ts +17 -2
  7. package/src/adapters/claude-code/bin/runner.ts +4 -1
  8. package/src/adapters/claude-code/config.ts +23 -0
  9. package/src/adapters/claude-code/doctor.ts +148 -26
  10. package/src/adapters/claude-code/hooks.ts +37 -12
  11. package/src/adapters/claude-code/index.ts +2 -0
  12. package/src/adapters/claude-code/standdown.ts +12 -1
  13. package/src/adapters/claude-code/transcript.ts +79 -6
  14. package/src/adapters/cli/INTERFACE-GAPS.md +4 -0
  15. package/src/adapters/cli/commands.ts +209 -61
  16. package/src/adapters/cli/export.ts +27 -3
  17. package/src/adapters/cli/help.ts +22 -8
  18. package/src/adapters/cli/install.ts +3 -5
  19. package/src/adapters/cli/mechanisms.ts +295 -0
  20. package/src/adapters/cli/repair-dates.ts +3 -1
  21. package/src/adapters/cli/snapshot.ts +4 -27
  22. package/src/adapters/dashboard/CONTRACT.md +13 -9
  23. package/src/adapters/dashboard/INTERFACE-GAPS.md +4 -0
  24. package/src/adapters/dashboard/NOTES.md +3 -2
  25. package/src/adapters/dashboard/activity.ts +2 -1
  26. package/src/adapters/dashboard/bin/dashboard.ts +18 -3
  27. package/src/adapters/dashboard/upgrade.ts +23 -0
  28. package/src/adapters/dashboard/web/README.md +153 -0
  29. package/src/adapters/dashboard/web/actions.ts +631 -0
  30. package/src/adapters/dashboard/web/app.html +40 -1703
  31. package/src/adapters/dashboard/web/app.js +55 -0
  32. package/src/adapters/dashboard/web/mechanisms/association/index.js +15 -0
  33. package/src/adapters/dashboard/web/mechanisms/association/panel.js +17 -0
  34. package/src/adapters/dashboard/web/mechanisms/consolidation/index.js +15 -0
  35. package/src/adapters/dashboard/web/mechanisms/consolidation/panel.js +23 -0
  36. package/src/adapters/dashboard/web/mechanisms/decay/index.js +15 -0
  37. package/src/adapters/dashboard/web/mechanisms/decay/panel.js +45 -0
  38. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +15 -0
  39. package/src/adapters/dashboard/web/mechanisms/episodic-semantic/index.js +15 -0
  40. package/src/adapters/dashboard/web/mechanisms/index.js +60 -0
  41. package/src/adapters/dashboard/web/mechanisms/interference/index.js +15 -0
  42. package/src/adapters/dashboard/web/mechanisms/picture.js +28 -0
  43. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +15 -0
  44. package/src/adapters/dashboard/web/mechanisms/reconsolidation/index.js +15 -0
  45. package/src/adapters/dashboard/web/mechanisms/reconsolidation/panel.js +15 -0
  46. package/src/adapters/dashboard/web/mechanisms/regions.js +30 -0
  47. package/src/adapters/dashboard/web/mechanisms/retrieval/index.js +15 -0
  48. package/src/adapters/dashboard/web/mechanisms/retrieval/panel.js +20 -0
  49. package/src/adapters/dashboard/web/mechanisms/salience/index.js +15 -0
  50. package/src/adapters/dashboard/web/mechanisms/salience/panel.js +14 -0
  51. package/src/adapters/dashboard/web/mechanisms/schema/index.js +15 -0
  52. package/src/adapters/dashboard/web/narrate.ts +10 -10
  53. package/src/adapters/dashboard/web/pages/flow/flow.css +38 -0
  54. package/src/adapters/dashboard/web/pages/flow/index.js +117 -0
  55. package/src/adapters/dashboard/web/pages/flow/sections/blind.js +12 -0
  56. package/src/adapters/dashboard/web/pages/flow/sections/detail.js +45 -0
  57. package/src/adapters/dashboard/web/pages/flow/sections/diagram.js +291 -0
  58. package/src/adapters/dashboard/web/pages/flow/sections/feed.js +11 -0
  59. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +41 -0
  60. package/src/adapters/dashboard/web/pages/flow/sections/heatmap.js +25 -0
  61. package/src/adapters/dashboard/web/pages/flow/sections/records.js +24 -0
  62. package/src/adapters/dashboard/web/pages/flow/sections/symmetry.js +17 -0
  63. package/src/adapters/dashboard/web/pages/flow/state.js +3 -0
  64. package/src/adapters/dashboard/web/pages/health/health.css +93 -0
  65. package/src/adapters/dashboard/web/pages/health/index.js +41 -0
  66. package/src/adapters/dashboard/web/pages/health/sections/archive.js +84 -0
  67. package/src/adapters/dashboard/web/pages/health/sections/checks.js +172 -0
  68. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +37 -0
  69. package/src/adapters/dashboard/web/pages/health/sections/verify.js +54 -0
  70. package/src/adapters/dashboard/web/pages/home/brain.js +375 -0
  71. package/src/adapters/dashboard/web/pages/home/home.css +134 -0
  72. package/src/adapters/dashboard/web/pages/home/index.js +84 -0
  73. package/src/adapters/dashboard/web/pages/home/sections/explorer.js +206 -0
  74. package/src/adapters/dashboard/web/pages/home/sections/hero.js +22 -0
  75. package/src/adapters/dashboard/web/pages/home/sections/live-activity.js +25 -0
  76. package/src/adapters/dashboard/web/pages/home/sections/recent-chapters.js +13 -0
  77. package/src/adapters/dashboard/web/pages/home/sections/tiles.js +52 -0
  78. package/src/adapters/dashboard/web/pages/memories/index.js +75 -0
  79. package/src/adapters/dashboard/web/pages/memories/memories.css +143 -0
  80. package/src/adapters/dashboard/web/pages/memories/sections/constellation.js +178 -0
  81. package/src/adapters/dashboard/web/pages/memories/sections/kinds.js +42 -0
  82. package/src/adapters/dashboard/web/pages/memories/sections/list.js +114 -0
  83. package/src/adapters/dashboard/web/pages/memories/sections/search.js +102 -0
  84. package/src/adapters/dashboard/web/pages/memories/sections/tools.js +155 -0
  85. package/src/adapters/dashboard/web/pages/memories/state.js +22 -0
  86. package/src/adapters/dashboard/web/pages/self/diff.js +79 -0
  87. package/src/adapters/dashboard/web/pages/self/index.js +43 -0
  88. package/src/adapters/dashboard/web/pages/self/markdown.js +61 -0
  89. package/src/adapters/dashboard/web/pages/self/sections/journal.js +32 -0
  90. package/src/adapters/dashboard/web/pages/self/sections/page.js +149 -0
  91. package/src/adapters/dashboard/web/pages/self/sections/settling.js +150 -0
  92. package/src/adapters/dashboard/web/pages/self/sections/stories.js +47 -0
  93. package/src/adapters/dashboard/web/pages/self/sections/wake.js +74 -0
  94. package/src/adapters/dashboard/web/pages/self/self.css +182 -0
  95. package/src/adapters/dashboard/web/server.ts +305 -28
  96. package/src/adapters/dashboard/web/shared/absence.js +14 -0
  97. package/src/adapters/dashboard/web/shared/actions.js +48 -0
  98. package/src/adapters/dashboard/web/shared/api.js +17 -0
  99. package/src/adapters/dashboard/web/shared/base.css +34 -0
  100. package/src/adapters/dashboard/web/shared/canvas.js +68 -0
  101. package/src/adapters/dashboard/web/shared/colors.js +6 -0
  102. package/src/adapters/dashboard/web/shared/dom.js +4 -0
  103. package/src/adapters/dashboard/web/shared/event-modal.js +25 -0
  104. package/src/adapters/dashboard/web/shared/fonts/OFL-courier-prime.txt +93 -0
  105. package/src/adapters/dashboard/web/shared/fonts/OFL-outfit.txt +93 -0
  106. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-400.woff2 +0 -0
  107. package/src/adapters/dashboard/web/shared/fonts/courier-prime-latin-700.woff2 +0 -0
  108. package/src/adapters/dashboard/web/shared/fonts/outfit-latin-wght.woff2 +0 -0
  109. package/src/adapters/dashboard/web/shared/format.js +31 -0
  110. package/src/adapters/dashboard/web/shared/layout.css +32 -0
  111. package/src/adapters/dashboard/web/shared/memory-modal.js +124 -0
  112. package/src/adapters/dashboard/web/shared/modal.css +24 -0
  113. package/src/adapters/dashboard/web/shared/modal.js +22 -0
  114. package/src/adapters/dashboard/web/shared/state.js +12 -0
  115. package/src/adapters/dashboard/web/shared/tip.css +4 -0
  116. package/src/adapters/dashboard/web/shared/tip.js +12 -0
  117. package/src/adapters/dashboard/web/shared/tokens.css +50 -0
  118. package/src/adapters/dashboard/web/shared/type.css +52 -0
  119. package/src/adapters/dashboard/web/shared/utilities.css +5 -0
  120. package/src/adapters/dashboard/web/shared/vendor/MIT-three.txt +21 -0
  121. package/src/adapters/dashboard/web/shared/vendor/three.module.min.js +6 -0
  122. package/src/adapters/dashboard/web/shared/widgets/bar.css +9 -0
  123. package/src/adapters/dashboard/web/shared/widgets/card.css +6 -0
  124. package/src/adapters/dashboard/web/shared/widgets/chapters.js +15 -0
  125. package/src/adapters/dashboard/web/shared/widgets/chart.css +4 -0
  126. package/src/adapters/dashboard/web/shared/widgets/confirm.css +31 -0
  127. package/src/adapters/dashboard/web/shared/widgets/confirm.js +52 -0
  128. package/src/adapters/dashboard/web/shared/widgets/feed.css +13 -0
  129. package/src/adapters/dashboard/web/shared/widgets/feed.js +41 -0
  130. package/src/adapters/dashboard/web/shared/widgets/light.css +4 -0
  131. package/src/adapters/dashboard/web/shared/widgets/light.js +15 -0
  132. package/src/adapters/dashboard/web/shared/widgets/rows.css +7 -0
  133. package/src/adapters/dashboard/web/shared/widgets/table.css +17 -0
  134. package/src/adapters/dashboard/web/shared/widgets/tiles.css +14 -0
  135. package/src/adapters/dashboard/web/shell/pages.js +15 -0
  136. package/src/adapters/dashboard/web/shell/pulse.js +86 -0
  137. package/src/adapters/dashboard/web/shell/tabs.js +49 -0
  138. package/src/adapters/dashboard/web/static.ts +76 -0
  139. package/src/adapters/dashboard/web/views/activity.ts +80 -0
  140. package/src/adapters/dashboard/web/views/archive-words.ts +57 -0
  141. package/src/adapters/dashboard/web/views/flow-view.ts +217 -0
  142. package/src/adapters/dashboard/web/views/health.ts +328 -0
  143. package/src/adapters/dashboard/web/views/mechanism-panel.ts +370 -0
  144. package/src/adapters/dashboard/web/views/mechanisms.ts +302 -0
  145. package/src/adapters/dashboard/web/views/memories.ts +342 -0
  146. package/src/adapters/dashboard/web/views/memory.ts +210 -0
  147. package/src/adapters/dashboard/web/views/meta.ts +64 -0
  148. package/src/adapters/dashboard/web/views/mind.ts +729 -0
  149. package/src/adapters/dashboard/web/views/overview.ts +282 -0
  150. package/src/adapters/dashboard/web/views/pulse.ts +19 -0
  151. package/src/adapters/dashboard/web/views/rows.ts +207 -0
  152. package/src/adapters/dashboard/web/views/search.ts +62 -0
  153. package/src/adapters/dashboard/web/views/shared.ts +161 -0
  154. package/src/adapters/dashboard/web/views.ts +34 -1724
  155. package/src/adapters/fired.ts +138 -31
  156. package/src/adapters/mcp/INTERFACE-GAPS.md +4 -1
  157. package/src/adapters/mcp/NOTES.md +43 -0
  158. package/src/adapters/mcp/bin/serve.ts +9 -1
  159. package/src/adapters/mcp/index.ts +7 -0
  160. package/src/adapters/mcp/server.ts +167 -6
  161. package/src/adapters/mcp/tools.ts +42 -0
  162. package/src/adapters/mcp/write-up.ts +1 -1
  163. package/src/adapters/sessions.ts +18 -1
  164. package/src/adapters/snapshots.ts +71 -39
  165. package/src/core/associate/INTERFACE-GAPS.md +8 -0
  166. package/src/core/counterpart.ts +86 -7
  167. package/src/core/encode/INTERFACE-GAPS.md +12 -0
  168. package/src/core/feelings-wheel.ts +218 -0
  169. package/src/core/handoff/INTERFACE-GAPS.md +2 -0
  170. package/src/core/mint.ts +14 -2
  171. package/src/core/prospective/INTERFACE-GAPS.md +14 -0
  172. package/src/core/prospective/windows.ts +10 -48
  173. package/src/core/recall/INTERFACE-GAPS.md +6 -0
  174. package/src/core/remember/INTERFACE-GAPS.md +10 -0
  175. package/src/core/schemas/INTERFACE-GAPS.md +8 -0
  176. package/src/core/schemas/NOTES.md +118 -1
  177. package/src/core/schemas/index.ts +330 -40
  178. package/src/core/schemas/tunables.ts +23 -0
  179. package/src/core/schemas/types.ts +64 -1
  180. package/src/core/self/CONTRACT.md +3 -0
  181. package/src/core/self/INTERFACE-GAPS.md +10 -0
  182. package/src/core/self/NOTES.md +33 -2
  183. package/src/core/self/calendar.ts +7 -78
  184. package/src/core/self/episodes.ts +52 -12
  185. package/src/core/self/index.ts +40 -12
  186. package/src/core/self/writer.ts +22 -22
  187. package/src/core/sleep/NOTES.md +36 -0
  188. package/src/core/sleep/cycle.ts +38 -3
  189. package/src/core/sleep/fade.ts +76 -0
  190. package/src/core/sleep/index.ts +4 -1
  191. package/src/core/sleep/prune.ts +8 -1
  192. package/src/core/sleep/tunables.ts +5 -0
  193. package/src/core/sleep/types.ts +24 -0
  194. package/src/core/store/CONTRACT.md +36 -7
  195. package/src/core/store/NOTES.md +197 -0
  196. package/src/core/store/errors.ts +22 -0
  197. package/src/core/store/feelings.ts +182 -0
  198. package/src/core/store/index.ts +339 -45
  199. package/src/core/store/operational.ts +240 -22
  200. package/src/core/store/owner-op-seam.ts +13 -3
  201. package/src/core/store/paths.ts +15 -1
  202. package/src/core/store/pre-migration.ts +258 -0
  203. package/src/core/store/prose.ts +8 -1
  204. package/src/core/store/render.ts +3 -0
  205. package/src/core/time.ts +374 -0
  206. package/src/core/types.ts +13 -0
  207. package/src/adapters/dashboard/web/brain.html +0 -463
@@ -0,0 +1,729 @@
1
+ /**
2
+ * `/api/mind` — identity, the briefing, the journal, the revision stories.
3
+ *
4
+ * Split out of `web/views.ts`, which re-exports every public name from here;
5
+ * the four rules in that file's header apply to every line below.
6
+ */
7
+ import { TUNABLES as PHYSICS, kindPhysics, promotionEligibility, sal } from "../../../../core/physics/index.js";
8
+ import { isConfidential } from "../../../../core/recall/index.js";
9
+ import {
10
+ FRAMING,
11
+ LANE_ORDER,
12
+ SELF_PAGE_REVISED_EVENT,
13
+ chapterModels,
14
+ pageSections,
15
+ readChapterLead,
16
+ } from "../../../../core/self/index.js";
17
+ import type { PageVersion } from "../../../../core/self/index.js";
18
+ import { TUNABLES as SLEEP, isJournal } from "../../../../core/sleep/index.js";
19
+ import type { Band, Kind } from "../../../../core/types.js";
20
+ import { NEVER, NONE } from "../../layout.js";
21
+ import { localDate } from "../../../../core/time.js";
22
+ import type { DashboardSource } from "../../source.js";
23
+ import { WITHHELD, reveal } from "../reveal.js";
24
+ import { chapters, contestedRows, livedDays } from "./rows.js";
25
+ import type { ChapterRow, ContestedRow } from "./rows.js";
26
+
27
+ // ─────────────────────────────────────────────────────────────────────────────
28
+ // mind — identity, the briefing, the journal, the revision stories
29
+ // ─────────────────────────────────────────────────────────────────────────────
30
+
31
+ export interface WakeLane {
32
+ /** The lane's own heading, as the briefing writes it. */
33
+ readonly heading: string;
34
+ /** The lane name, when this is one of `self/`'s lanes; null for the preface. */
35
+ readonly lane: string | null;
36
+ /** One element per line, bullets stripped. Verbatim otherwise. */
37
+ readonly items: string[];
38
+ }
39
+
40
+ export interface StoryBeat {
41
+ readonly day: number;
42
+ readonly challenger: string;
43
+ readonly force: number;
44
+ readonly pressureAfter: number;
45
+ readonly bar: number;
46
+ readonly fraction: number;
47
+ /** One clause, in prose. Never an id: an id in a sentence is a leak. */
48
+ readonly verdict: string;
49
+ /** What it became, when it became something — as words, resolved now. */
50
+ readonly became: string | null;
51
+ /** The successor's address, for a link. Kept OUT of `verdict`. */
52
+ readonly becameId: string | null;
53
+ readonly crossed: boolean;
54
+ }
55
+
56
+ export interface StoryView extends ContestedRow {
57
+ readonly beats: StoryBeat[];
58
+ readonly beatsAbsent: string | null;
59
+ }
60
+
61
+ export interface MindView {
62
+ readonly opening: string;
63
+ readonly identity: { id: string; text: string; kind: Kind; band: Band; strength: number; bytes: number; bornDay: number; lastUsedDay: number; confidential: boolean }[];
64
+ readonly identityAbsent: string | null;
65
+ readonly guarded: { id: string; text: string; kind: Kind; band: Band; strength: number; bytes: number; bornDay: number; lastUsedDay: number; confidential: boolean }[];
66
+ readonly guardedAbsent: string | null;
67
+ readonly both: string[];
68
+ readonly protectedOutsideIdentity: { id: string; text: string }[];
69
+ readonly unreadable: { id: string; label: string }[];
70
+ readonly wake: {
71
+ readonly ok: boolean;
72
+ readonly reason: string;
73
+ readonly bytes: number;
74
+ readonly preface: string | null;
75
+ readonly lanes: WakeLane[];
76
+ readonly absent: string | null;
77
+ };
78
+ /**
79
+ * THE WRITTEN PAGE, and what it used to say (2026-09-18, S1). Read-only, like
80
+ * everything else here: the dashboard shows the page and its versions and
81
+ * offers no door to write one — the doors are the MCP tool and the console.
82
+ *
83
+ * The BODIES ride along; the self tab draws them as a timeline and diffs
84
+ * neighbouring versions in the browser (`pages/self/diff.js`).
85
+ */
86
+ readonly page: {
87
+ readonly present: boolean;
88
+ readonly body: string;
89
+ readonly bytes: number;
90
+ readonly revisedOn: string;
91
+ readonly by: string | null;
92
+ readonly reason: string | null;
93
+ readonly version: number;
94
+ readonly stale: boolean;
95
+ readonly core: string;
96
+ readonly lately: string;
97
+ readonly headed: boolean;
98
+ } | null;
99
+ /** The honest absence line when no page has been written. */
100
+ readonly pageAbsent: string | null;
101
+ /** Each body labelled with the write that PRODUCED it, and with what replaced
102
+ * it named separately — `store.revise` stores the replacing reason on the row
103
+ * it archives, so the two must not share a word (adversarial review M3). */
104
+ readonly pageVersions: PageVersion[];
105
+ readonly chapters: ChapterRow[];
106
+ readonly chaptersAbsent: string | null;
107
+ readonly stories: StoryView[];
108
+ readonly storiesAbsent: string | null;
109
+ /** The page's whole life, OLDEST first, the standing page last. */
110
+ readonly pageHistory: PageStep[];
111
+ /** What is settling into the core, and what is closest to it. */
112
+ readonly settling: SettlingView;
113
+ /** The published wake cut into its parts, in the order it reads. */
114
+ readonly wakeParts: WakePart[];
115
+ /** The ceiling the last render was composed to; null when no render recorded one. */
116
+ readonly wakeBudget: number | null;
117
+ /** The journal by lived day, newest first. */
118
+ readonly journal: JournalDay[];
119
+ readonly journalAbsent: string | null;
120
+ /** Chapters past the ones sent. 0 when all of them are here. */
121
+ readonly journalMore: number;
122
+ }
123
+
124
+ /** One state of the page: an archived version, or the one standing now. */
125
+ export interface PageStep {
126
+ /** 1-based, oldest first — the number a person would count. */
127
+ readonly n: number;
128
+ /** The store's version seq; for the standing page, its `version` + 1. */
129
+ readonly seq: number;
130
+ readonly current: boolean;
131
+ readonly day: number | null;
132
+ /** Calendar date of the write that produced it (the durable row's clock); null when unrecorded. */
133
+ readonly date: string | null;
134
+ readonly by: string | null;
135
+ readonly reason: string | null;
136
+ readonly body: string | null;
137
+ readonly bytes: number | null;
138
+ }
139
+
140
+ export interface Candidate {
141
+ readonly id: string;
142
+ readonly text: string;
143
+ readonly confidential: boolean;
144
+ readonly kind: Kind;
145
+ /** What the memory has earned (`physics#base`), and the bar it must reach. */
146
+ readonly base: number;
147
+ readonly threshold: number;
148
+ /** True when consolidation's one-time bonus is already in `base`. */
149
+ readonly consolidated: boolean;
150
+ readonly bonus: number;
151
+ /** Distinct lived days a use was credited, and how many the rule needs. */
152
+ readonly days: number;
153
+ readonly requiredDays: number;
154
+ /** Both conditions met: the next consolidation pass crosses it. */
155
+ readonly eligible: boolean;
156
+ }
157
+
158
+ export interface SettlingRow {
159
+ readonly id: string;
160
+ readonly text: string;
161
+ readonly confidential: boolean;
162
+ readonly kind: Kind;
163
+ }
164
+
165
+ export interface SettlingView {
166
+ /** The identity band — the core. */
167
+ readonly core: SettlingRow[];
168
+ /** Protected (permanent) rows. */
169
+ readonly guarded: SettlingRow[];
170
+ /** Beliefs under challenge, or already revised. */
171
+ readonly contested: { id: string; about: string; now: string; revised: boolean; fraction: number; pressure: number; bar: number }[];
172
+ /** Permanent rows that do not stand in the band. */
173
+ readonly outside: SettlingRow[];
174
+ /** Identity-band rows that would not read. Shown whenever there are any. */
175
+ readonly unreadable: { id: string; label: string }[];
176
+ /** The closest candidates, closest first. */
177
+ readonly candidates: Candidate[];
178
+ /** Memories that could reach the core by use and have at least one credited day. */
179
+ readonly onTheWay: number;
180
+ /** Memories that could reach it but have never been used on a later day. */
181
+ readonly unused: number;
182
+ /** Memories whose score and kind put the core out of reach by use alone. */
183
+ readonly outOfReach: number;
184
+ /** The rule, as numbers, so the page states it rather than restating it. */
185
+ readonly rule: { threshold: number; days: number; everyDays: number; repCap: number; bonus: number };
186
+ /** Two-word absences, for each list that is empty. */
187
+ readonly coreAbsent: string | null;
188
+ readonly guardedAbsent: string | null;
189
+ readonly contestedAbsent: string | null;
190
+ }
191
+
192
+ export interface WakePart {
193
+ readonly label: string;
194
+ /** The lane name, "page", "furniture" — a stable key for colour. */
195
+ readonly key: string;
196
+ readonly bytes: number;
197
+ }
198
+
199
+ export interface JournalChapter {
200
+ readonly id: string;
201
+ /** The chapter number inside its session's entry. */
202
+ readonly chapter: number;
203
+ readonly title: string;
204
+ readonly model: string | null;
205
+ readonly first: string;
206
+ /** The chapter's own text, headings off. Null when withheld. */
207
+ readonly text: string | null;
208
+ readonly bytes: number;
209
+ readonly confidential: boolean;
210
+ }
211
+
212
+ export interface JournalDay {
213
+ readonly day: number;
214
+ /** As the chapter heading wrote it (`Wed 23 Sep 2026`); null when it named none. */
215
+ readonly date: string | null;
216
+ readonly chapters: JournalChapter[];
217
+ }
218
+
219
+ export function mindView(src: DashboardSource): MindView {
220
+ const store = src.store;
221
+ const day = store.livedDay();
222
+ const e = src.self.enumerate(day);
223
+ const wake = src.self.wake();
224
+ const page = src.self.page();
225
+ const sections = pageSections(page?.body ?? "");
226
+ const everLived = day > 0 || store.list().length > 0;
227
+ const seen = new Set(e.identity.map((el) => el.id));
228
+ const unreadable = store
229
+ .list({ band: "identity", archived: false })
230
+ .filter((id) => !seen.has(id))
231
+ .map((id) => ({ id, label: reveal(store, id, 72).label }));
232
+
233
+ const shape = (el: { id: string; kind: Kind; band: Band; strength: number; bytes: number }): MindView["identity"][number] => {
234
+ const r = reveal(store, el.id, 120);
235
+ return {
236
+ id: el.id,
237
+ text: r.text ?? r.label,
238
+ kind: el.kind,
239
+ band: el.band,
240
+ strength: el.strength,
241
+ bytes: el.bytes,
242
+ ...livedDays(src, el.id),
243
+ confidential: r.confidential,
244
+ };
245
+ };
246
+
247
+ const identity = e.identity.map(shape);
248
+ const guarded = e.protected.map(shape);
249
+ const outside = e.protectedOutsideIdentity.map((id) => {
250
+ const r = reveal(store, id, 90);
251
+ return { id, text: r.text ?? r.label };
252
+ });
253
+ const stories = storyViews(src);
254
+
255
+ return {
256
+ opening:
257
+ `Lived day ${day}. Who I am, in my own words — and, under it, how that has changed, ` +
258
+ "what is slowly settling into the core, what the next session will be handed, and the journal.",
259
+ identity,
260
+ identityAbsent: e.identity.length === 0 ? (everLived ? NONE : NEVER) : null,
261
+ guarded,
262
+ guardedAbsent: e.protected.length === 0 ? (everLived ? NONE : NEVER) : null,
263
+ both: e.both,
264
+ protectedOutsideIdentity: outside,
265
+ unreadable,
266
+ wake: {
267
+ ok: wake.ok,
268
+ reason: wake.reason,
269
+ bytes: wake.bytes,
270
+ preface: wake.preface,
271
+ lanes: wake.ok ? wakeLanes(wake.text) : [],
272
+ absent: wake.ok ? null : everLived ? NONE : NEVER,
273
+ },
274
+ page:
275
+ page === null
276
+ ? null
277
+ : {
278
+ present: true,
279
+ body: page.body,
280
+ bytes: page.bytes,
281
+ revisedOn: page.revisedOn,
282
+ by: page.by,
283
+ reason: page.reason,
284
+ version: page.version,
285
+ stale: src.self.pageStale(page),
286
+ // The three the type declares, NAMED — a spread of `pageSections`
287
+ // also carried `preamble` into the JSON, which `tsc` cannot catch
288
+ // through a spread (adversarial review n2).
289
+ core: sections.core,
290
+ lately: sections.lately,
291
+ headed: sections.headed,
292
+ },
293
+ pageAbsent: page === null ? (everLived ? NONE : NEVER) : null,
294
+ // NOT guarded on the live page: a CLEARED page has no live row and still has
295
+ // a history, and the console lists it. Two surfaces answering "what did the
296
+ // page used to say" differently is the same class of mismatch the version
297
+ // reasons were (M3). `pageVersions` handles the no-live-row case itself.
298
+ pageVersions: src.self.pageVersions(),
299
+ chapters: chapters(src, 12),
300
+ chaptersAbsent: chapters(src, 1).length === 0 ? (everLived ? NONE : NEVER) : null,
301
+ stories,
302
+ storiesAbsent: stories.length === 0 ? (everLived ? NONE : NEVER) : null,
303
+ pageHistory: pageHistory(src, page),
304
+ settling: settlingView(src, {
305
+ core: identity,
306
+ guarded,
307
+ outside,
308
+ unreadable,
309
+ stories,
310
+ pageId: page?.id ?? null,
311
+ absent: everLived ? NONE : NEVER,
312
+ }),
313
+ wakeParts: wake.ok ? wakeParts(wake.text, page !== null) : [],
314
+ wakeBudget: lastBudget(src),
315
+ ...journal(src, JOURNAL_LIMIT, everLived ? NONE : NEVER),
316
+ };
317
+ }
318
+
319
+ /** How many chapters the journal sends. The rest are counted, not dropped silently. */
320
+ const JOURNAL_LIMIT = 60;
321
+
322
+ // ─────────────────────────────────────────────────────────────────────────────
323
+ // the page's history — a timeline, oldest first
324
+ // ─────────────────────────────────────────────────────────────────────────────
325
+
326
+ /** The person's calendar day for a clock reading, in the store's zone (`core/time.ts`). */
327
+ function dateOfMs(at: number, zone: string): string | null {
328
+ if (!Number.isFinite(at) || at <= 0) return null;
329
+ return localDate(at, zone);
330
+ }
331
+
332
+ /**
333
+ * Every state the page has been in, OLDEST first, the standing page last.
334
+ *
335
+ * `pageVersions()` already says who wrote each archived body and why; the
336
+ * calendar date comes from the same durable `self.page.revised` rows, matched
337
+ * the same way (the write that produced version `seq` recorded `version: seq - 1`).
338
+ * A cleared page has no standing row and keeps its history, so the timeline
339
+ * still draws.
340
+ */
341
+ function pageHistory(src: DashboardSource, page: ReturnType<DashboardSource["self"]["page"]>): PageStep[] {
342
+ const versions = src.self.pageVersions().slice().sort((a, b) => a.seq - b.seq);
343
+ const at = new Map<number, number>();
344
+ const pageId = page?.id ?? null;
345
+ const zone = src.store.zone();
346
+ try {
347
+ const rows = pageId === null
348
+ ? src.store.eventLog({ name: SELF_PAGE_REVISED_EVENT, limit: LOG_LIMIT })
349
+ : src.store.eventLog({ name: SELF_PAGE_REVISED_EVENT, ref: pageId, limit: LOG_LIMIT });
350
+ for (const row of rows) {
351
+ const payload = JSON.parse(row.payload ?? "{}") as Record<string, unknown>;
352
+ const v = payload["version"];
353
+ if (typeof v === "number") at.set(v, row.at);
354
+ }
355
+ } catch {
356
+ /* unreadable log: every date reads as unrecorded, never as a guess */
357
+ }
358
+ const steps: PageStep[] = versions.map((v, i) => ({
359
+ n: i + 1,
360
+ seq: v.seq,
361
+ current: false,
362
+ day: v.day,
363
+ date: at.has(v.seq - 1) ? dateOfMs(at.get(v.seq - 1) as number, zone) : null,
364
+ by: v.by,
365
+ reason: v.reason,
366
+ body: v.body,
367
+ bytes: v.bytes,
368
+ }));
369
+ if (page !== null) {
370
+ steps.push({
371
+ n: steps.length + 1,
372
+ seq: page.version + 1,
373
+ current: true,
374
+ day: page.revisedDay,
375
+ date: page.revisedOn.length > 0 ? page.revisedOn : at.has(page.version) ? dateOfMs(at.get(page.version) as number, zone) : null,
376
+ by: page.by,
377
+ reason: page.reason,
378
+ body: page.body,
379
+ bytes: page.bytes,
380
+ });
381
+ }
382
+ return steps;
383
+ }
384
+
385
+ const LOG_LIMIT = 2_000;
386
+
387
+ // ─────────────────────────────────────────────────────────────────────────────
388
+ // what it's settling into — the core, and what is closest to it
389
+ // ─────────────────────────────────────────────────────────────────────────────
390
+
391
+ type Shaped = MindView["identity"][number];
392
+
393
+ /**
394
+ * The core as it stands, and — the part a young store needs — what is on its way.
395
+ *
396
+ * The candidates are computed with physics' OWN rule, `promotionEligibility`
397
+ * (base >= THETA_ID and credited use on N distinct lived days); nothing here
398
+ * restates the thresholds. What this adds is one honest distinction the rule
399
+ * implies: `base` is `max(wSal x sal, wRep x rep) + cons`, repetition caps at
400
+ * REP_CAP and consolidation adds CONS_BONUS once, so a memory whose best case
401
+ * stays under the bar can never get there by being used (mechanism audit
402
+ * 2026-09-24, Consolidation). Those are counted apart, not listed as "on their
403
+ * way". Schema rows (the page, the identity core, beliefs) are not memories and
404
+ * are left out, as are journal rows.
405
+ */
406
+ function settlingView(
407
+ src: DashboardSource,
408
+ x: {
409
+ core: Shaped[];
410
+ guarded: Shaped[];
411
+ outside: { id: string; text: string }[];
412
+ unreadable: { id: string; label: string }[];
413
+ stories: StoryView[];
414
+ pageId: string | null;
415
+ absent: string;
416
+ },
417
+ ): SettlingView {
418
+ const store = src.store;
419
+ const raw: { id: string; kind: Kind; base: number; consolidated: boolean; days: number; eligible: boolean }[] = [];
420
+ let outOfReach = 0;
421
+ for (const id of store.list({ archived: false })) {
422
+ const row = store.row(id);
423
+ if (row === undefined || isJournal(row) || row.type === "schema" || id === x.pageId) continue;
424
+ let p;
425
+ try {
426
+ p = store.physicsOf(id);
427
+ } catch {
428
+ continue;
429
+ }
430
+ const v = promotionEligibility(p);
431
+ if (v.blockedBy.includes("already-identity")) continue;
432
+ const k = kindPhysics(p.kind);
433
+ const best = Math.max(k.wSal * sal(p.salience), k.wRep * PHYSICS.REP_CAP) + PHYSICS.CONS_BONUS;
434
+ if (best < v.threshold) {
435
+ outOfReach += 1;
436
+ continue;
437
+ }
438
+ raw.push({ id, kind: p.kind, base: v.base, consolidated: p.consolidated, days: v.reinforcedDays, eligible: v.eligible });
439
+ }
440
+ // Closest first: how much of each condition is met, both halves weighted
441
+ // alike; ties by days, then by what it has earned.
442
+ const closeness = (r: (typeof raw)[number]): number =>
443
+ Math.min(1, r.base / PHYSICS.THETA_ID) + Math.min(1, r.days / PHYSICS.N_PROMOTION_DAYS);
444
+ raw.sort((a, b) => closeness(b) - closeness(a) || b.days - a.days || b.base - a.base || (a.id < b.id ? -1 : 1));
445
+ const candidates: Candidate[] = raw.slice(0, CANDIDATE_LIMIT).map((r) => {
446
+ const t = reveal(store, r.id, 110);
447
+ return {
448
+ id: r.id,
449
+ text: t.text ?? t.label,
450
+ confidential: t.confidential,
451
+ kind: r.kind,
452
+ base: r.base,
453
+ threshold: PHYSICS.THETA_ID,
454
+ consolidated: r.consolidated,
455
+ bonus: PHYSICS.CONS_BONUS,
456
+ days: r.days,
457
+ requiredDays: PHYSICS.N_PROMOTION_DAYS,
458
+ eligible: r.eligible,
459
+ };
460
+ });
461
+ const row = (el: { id: string; text: string; confidential?: boolean; kind?: Kind }): SettlingRow => ({
462
+ id: el.id,
463
+ text: el.text,
464
+ confidential: el.confidential === true,
465
+ kind: el.kind ?? "fact",
466
+ });
467
+ return {
468
+ core: x.core.map(row),
469
+ guarded: x.guarded.map(row),
470
+ contested: x.stories.map((s) => ({
471
+ id: s.id,
472
+ about: s.about,
473
+ now: s.nowFull,
474
+ revised: s.revised,
475
+ fraction: s.fraction,
476
+ pressure: s.pressure,
477
+ bar: s.bar,
478
+ })),
479
+ outside: x.outside.map((o) => ({ id: o.id, text: o.text, confidential: false, kind: "fact" as Kind })),
480
+ unreadable: x.unreadable,
481
+ candidates,
482
+ onTheWay: raw.filter((r) => r.days > 0).length,
483
+ unused: raw.filter((r) => r.days === 0).length,
484
+ outOfReach,
485
+ rule: {
486
+ threshold: PHYSICS.THETA_ID,
487
+ days: PHYSICS.N_PROMOTION_DAYS,
488
+ everyDays: SLEEP.CADENCE.consolidate,
489
+ repCap: PHYSICS.REP_CAP,
490
+ bonus: PHYSICS.CONS_BONUS,
491
+ },
492
+ coreAbsent: x.core.length === 0 ? x.absent : null,
493
+ guardedAbsent: x.guarded.length === 0 ? x.absent : null,
494
+ contestedAbsent: x.stories.length === 0 ? x.absent : null,
495
+ };
496
+ }
497
+
498
+ const CANDIDATE_LIMIT = 5;
499
+
500
+ // ─────────────────────────────────────────────────────────────────────────────
501
+ // the wake, in parts
502
+ // ─────────────────────────────────────────────────────────────────────────────
503
+
504
+ const PART_LABEL: Record<string, string> = {
505
+ furniture: "headers",
506
+ page: "self page",
507
+ identity: "who I am",
508
+ craft: "how I work",
509
+ threads: "still open",
510
+ hints: "nearby memories",
511
+ horizon: "arriving",
512
+ };
513
+
514
+ /**
515
+ * The published bundle cut at its OWN lane headings (`FRAMING`, from `self/`),
516
+ * measured in raw bytes, so the parts add up to `wake.bytes` exactly. Unlike
517
+ * `wakeLanes`, a markdown heading does NOT start a part here: the page carries
518
+ * `## Core` and `## Lately`, and those belong to the page's slice. Everything
519
+ * outside a lane (the framing line, the comments, the sentinel) is "headers".
520
+ */
521
+ export function wakeParts(text: string, hasPage: boolean): WakePart[] {
522
+ const headings = new Map<string, string>();
523
+ for (const lane of LANE_ORDER) headings.set(FRAMING[lane], lane);
524
+ const bytes = new Map<string, number>();
525
+ const order: string[] = [];
526
+ const add = (key: string, n: number): void => {
527
+ if (!bytes.has(key)) order.push(key);
528
+ bytes.set(key, (bytes.get(key) ?? 0) + n);
529
+ };
530
+ let current = "furniture";
531
+ const lines = text.split("\n");
532
+ lines.forEach((raw, i) => {
533
+ const n = new TextEncoder().encode(raw).length + (i < lines.length - 1 ? 1 : 0);
534
+ const line = raw.trim();
535
+ const lane = headings.get(line);
536
+ if (lane !== undefined) {
537
+ current = lane === "identity" && hasPage ? "page" : lane;
538
+ add("furniture", n);
539
+ return;
540
+ }
541
+ if (line.startsWith("<!--") || line === FRAMING.context) {
542
+ add("furniture", n);
543
+ return;
544
+ }
545
+ add(current, n);
546
+ });
547
+ return order
548
+ .map((key) => ({ key, label: PART_LABEL[key] ?? key, bytes: bytes.get(key) ?? 0 }))
549
+ .filter((p) => p.bytes > 0);
550
+ }
551
+
552
+ /** The ceiling the newest durable render recorded, or null when none did. */
553
+ function lastBudget(src: DashboardSource): number | null {
554
+ try {
555
+ const [row] = src.store.eventLog({ name: "self.briefing", order: "desc", limit: 1 });
556
+ if (row === undefined) return null;
557
+ const budget = (JSON.parse(row.payload ?? "{}") as Record<string, unknown>)["budget"];
558
+ return typeof budget === "number" && budget > 0 ? budget : null;
559
+ } catch {
560
+ return null;
561
+ }
562
+ }
563
+
564
+ // ─────────────────────────────────────────────────────────────────────────────
565
+ // the journal — chapters by lived day
566
+ // ─────────────────────────────────────────────────────────────────────────────
567
+
568
+ const CHAPTER_SPLIT = /^(?=[ \t]*#{1,6}[ \t]*chapter[ \t]+\d+)/im;
569
+
570
+ /**
571
+ * Every chapter, grouped by the lived day it was written on, newest first.
572
+ *
573
+ * One journal row is one session's entry and can hold several chapters, each
574
+ * under its own `## chapter N — <date> · <model> · lived day D` heading, so a
575
+ * row is split at those headings and each part read with `self/`'s own
576
+ * `readChapterLead`. The model falls back to the entry's `meta.models`; a
577
+ * chapter written before either existed shows none.
578
+ */
579
+ function journal(src: DashboardSource, limit: number, absent: string): Pick<MindView, "journal" | "journalAbsent" | "journalMore"> {
580
+ const store = src.store;
581
+ const all: (JournalChapter & { day: number; date: string | null })[] = [];
582
+ for (const id of store.list({ archived: false })) {
583
+ const row = store.row(id);
584
+ if (row === undefined || !isJournal(row)) continue;
585
+ let doc;
586
+ try {
587
+ doc = store.readProse(id);
588
+ } catch {
589
+ all.push({ id, chapter: 1, title: reveal(store, id, 60).label, model: null, first: "", text: null, bytes: 0, confidential: false, day: 0, date: null });
590
+ continue;
591
+ }
592
+ const withheld = isConfidential(doc);
593
+ const models = chapterModels(doc.meta ?? {});
594
+ const parts = doc.body.split(CHAPTER_SPLIT).filter((p) => p.trim().length > 0);
595
+ const title = doc.title ?? "an unnamed chapter";
596
+ parts.forEach((part, i) => {
597
+ const lead = readChapterLead(part);
598
+ const n = lead.chapters[0] ?? i + 1;
599
+ const rest = lead.rest.trim();
600
+ const first = rest.split("\n").map((l) => l.trim()).find((l) => l.length > 0 && !l.startsWith("#") && !l.startsWith("<!--")) ?? "";
601
+ all.push({
602
+ id,
603
+ chapter: n,
604
+ title: parts.length > 1 ? `${title} · chapter ${n}` : title,
605
+ model: lead.model ?? models[String(n)] ?? null,
606
+ first: withheld ? WITHHELD : first.length > 200 ? `${first.slice(0, 200).trimEnd()}…` : first,
607
+ text: withheld ? null : rest,
608
+ bytes: new TextEncoder().encode(rest).length,
609
+ confidential: withheld,
610
+ day: lead.livedDay ?? doc.bornDay,
611
+ date: lead.date,
612
+ });
613
+ });
614
+ }
615
+ all.sort((a, b) => b.day - a.day || (a.id < b.id ? 1 : a.id > b.id ? -1 : b.chapter - a.chapter));
616
+ const sent = all.slice(0, limit);
617
+ const days: JournalDay[] = [];
618
+ for (const c of sent) {
619
+ let d = days[days.length - 1];
620
+ if (d === undefined || d.day !== c.day) {
621
+ d = { day: c.day, date: c.date, chapters: [] };
622
+ days.push(d);
623
+ }
624
+ if (d.date === null && c.date !== null) (d as { date: string | null }).date = c.date;
625
+ const { day: _day, date: _date, ...chapter } = c;
626
+ d.chapters.push(chapter);
627
+ }
628
+ return { journal: days, journalAbsent: all.length === 0 ? absent : null, journalMore: all.length - sent.length };
629
+ }
630
+
631
+ /**
632
+ * The briefing as it actually renders, split at its own lane headings.
633
+ *
634
+ * This is the one place the dashboard shows composed TEXT rather than a shape,
635
+ * and it is deliberate: the wake bundle is what the next session will read, so
636
+ * "what would I say on waking" is unanswerable from a byte count. Nothing is
637
+ * persisted — the bundle is read from the store at request time like every other
638
+ * value on the page, and its own trailing sentinel comment is dropped because it
639
+ * is bookkeeping, not something the assistant says.
640
+ */
641
+ export function wakeLanes(text: string): WakeLane[] {
642
+ // The lane names and their headings are TAKEN FROM `self/` — `LANE_ORDER` and
643
+ // `FRAMING` — never retyped here. A renamed lane heading would otherwise leave
644
+ // this splitter silently returning one enormous lane called "the preface",
645
+ // which is precisely the quiet-wrong-answer shape the registries exist against.
646
+ const headings = new Map<string, string>();
647
+ for (const lane of LANE_ORDER) headings.set(FRAMING[lane], lane);
648
+
649
+ const lanes: { heading: string; lane: string | null; items: string[] }[] = [];
650
+ let current: { heading: string; lane: string | null; items: string[] } = {
651
+ heading: "How this arrives",
652
+ lane: null,
653
+ items: [],
654
+ };
655
+ for (const raw of text.split("\n")) {
656
+ const line = raw.trim();
657
+ // The sentinel is bookkeeping, not something the assistant says.
658
+ if (line.startsWith("<!--")) continue;
659
+ if (line.length === 0) continue;
660
+ const lane = headings.get(line);
661
+ // A markdown heading counts too, so a future briefing that uses one still
662
+ // splits rather than collapsing into a single block.
663
+ const mdHeading = /^#{1,6}\s+(.*)$/.exec(line);
664
+ if (lane !== undefined || mdHeading !== null) {
665
+ if (current.items.length > 0) lanes.push(current);
666
+ current = {
667
+ heading: lane === undefined ? (mdHeading?.[1] ?? line) : line,
668
+ lane: lane ?? null,
669
+ items: [],
670
+ };
671
+ continue;
672
+ }
673
+ current.items.push(line.replace(/^[-*]\s+/, ""));
674
+ }
675
+ if (current.items.length > 0) lanes.push(current);
676
+ return lanes;
677
+ }
678
+
679
+ function storyViews(src: DashboardSource): StoryView[] {
680
+ const store = src.store;
681
+ return contestedRows(src).map((row) => {
682
+ let story;
683
+ try {
684
+ story = src.schemas.story(row.id);
685
+ } catch {
686
+ return { ...row, beats: [], beatsAbsent: NONE };
687
+ }
688
+
689
+ const beats: StoryBeat[] = story.increments
690
+ .slice()
691
+ .sort((a, b) => a.day - b.day)
692
+ .map((inc) => {
693
+ const crossed = inc.pressureAfter >= inc.bar;
694
+ const step = story.lineage.find((l) => l.id === inc.targetId && l.successorId !== null);
695
+ const successorId = crossed ? (step?.successorId ?? null) : null;
696
+ const became = successorId === null ? null : reveal(store, successorId, 96).text;
697
+ // The verdict is a CLAUSE, and the numbers it is about are already in
698
+ // their own fields: "0.598 of 0.470" beside the word REVISED read as a
699
+ // numerator larger than its denominator with nothing saying that is
700
+ // exactly what clearing a bar looks like.
701
+ const verdict = crossed
702
+ ? step === undefined || step.successorId === null
703
+ ? "it cleared the bar — but I find no supersession recorded"
704
+ : "it cleared the bar, and I changed my mind"
705
+ : "under the bar — held";
706
+ const c = reveal(store, inc.challengerId, 72);
707
+ return {
708
+ day: inc.day,
709
+ challenger: c.text ?? c.label,
710
+ force: inc.force,
711
+ pressureAfter: inc.pressureAfter,
712
+ bar: inc.bar,
713
+ fraction: inc.bar > 0 ? Math.min(1.3, inc.pressureAfter / inc.bar) : 0,
714
+ verdict,
715
+ became,
716
+ becameId: successorId,
717
+ crossed,
718
+ };
719
+ });
720
+ return {
721
+ ...row,
722
+ beats,
723
+ beatsAbsent:
724
+ beats.length === 0
725
+ ? "(none yet) — this belief carries pressure but I hold no credited challenge for it: the increments predate the durable log, or were swept."
726
+ : null,
727
+ };
728
+ });
729
+ }