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.
Files changed (195) hide show
  1. package/CONSTITUTION.md +68 -0
  2. package/LICENSE +21 -0
  3. package/README.md +348 -0
  4. package/docs/ELI5.md +84 -0
  5. package/docs/QUICKSTART.md +1258 -0
  6. package/docs/module-map.md +81 -0
  7. package/package.json +63 -0
  8. package/src/adapters/claude-code/CONTRACT.md +606 -0
  9. package/src/adapters/claude-code/INTERFACE-GAPS.md +655 -0
  10. package/src/adapters/claude-code/NOTES.md +1055 -0
  11. package/src/adapters/claude-code/bin/hook.ts +820 -0
  12. package/src/adapters/claude-code/bin/runner.ts +522 -0
  13. package/src/adapters/claude-code/config.ts +778 -0
  14. package/src/adapters/claude-code/credentials.ts +199 -0
  15. package/src/adapters/claude-code/doctor.ts +2557 -0
  16. package/src/adapters/claude-code/embed-client.ts +617 -0
  17. package/src/adapters/claude-code/hooks.ts +2240 -0
  18. package/src/adapters/claude-code/index.ts +224 -0
  19. package/src/adapters/claude-code/interpret-client.ts +395 -0
  20. package/src/adapters/claude-code/page-writer.ts +462 -0
  21. package/src/adapters/claude-code/primacy.ts +162 -0
  22. package/src/adapters/claude-code/spawn.ts +241 -0
  23. package/src/adapters/claude-code/standdown.ts +536 -0
  24. package/src/adapters/claude-code/transcript.ts +661 -0
  25. package/src/adapters/claude-code/vectors.ts +415 -0
  26. package/src/adapters/cli/CONTRACT.md +255 -0
  27. package/src/adapters/cli/INTERFACE-GAPS.md +350 -0
  28. package/src/adapters/cli/NOTES.md +936 -0
  29. package/src/adapters/cli/bin/counterparts.ts +74 -0
  30. package/src/adapters/cli/commands.ts +6095 -0
  31. package/src/adapters/cli/export.ts +766 -0
  32. package/src/adapters/cli/index.ts +103 -0
  33. package/src/adapters/cli/install.ts +670 -0
  34. package/src/adapters/cli/removal.ts +1186 -0
  35. package/src/adapters/cli/repair-dates.ts +659 -0
  36. package/src/adapters/cli/self-page.ts +229 -0
  37. package/src/adapters/cli/snapshot.ts +279 -0
  38. package/src/adapters/cli/start-fresh.ts +1228 -0
  39. package/src/adapters/config-path.ts +342 -0
  40. package/src/adapters/dashboard/CONTRACT.md +67 -0
  41. package/src/adapters/dashboard/INTERFACE-GAPS.md +139 -0
  42. package/src/adapters/dashboard/NOTES.md +474 -0
  43. package/src/adapters/dashboard/activity.ts +121 -0
  44. package/src/adapters/dashboard/ansi.ts +82 -0
  45. package/src/adapters/dashboard/bin/dashboard.ts +479 -0
  46. package/src/adapters/dashboard/browse.ts +298 -0
  47. package/src/adapters/dashboard/identity.ts +182 -0
  48. package/src/adapters/dashboard/index.ts +183 -0
  49. package/src/adapters/dashboard/layout.ts +149 -0
  50. package/src/adapters/dashboard/registries.ts +291 -0
  51. package/src/adapters/dashboard/resolve.ts +206 -0
  52. package/src/adapters/dashboard/source.ts +48 -0
  53. package/src/adapters/dashboard/status.ts +327 -0
  54. package/src/adapters/dashboard/stories.ts +194 -0
  55. package/src/adapters/dashboard/web/app.html +1731 -0
  56. package/src/adapters/dashboard/web/brain.html +463 -0
  57. package/src/adapters/dashboard/web/fired.ts +31 -0
  58. package/src/adapters/dashboard/web/flow.ts +457 -0
  59. package/src/adapters/dashboard/web/narrate.ts +1042 -0
  60. package/src/adapters/dashboard/web/reveal.ts +135 -0
  61. package/src/adapters/dashboard/web/server.ts +287 -0
  62. package/src/adapters/dashboard/web/views.ts +1744 -0
  63. package/src/adapters/expansions.ts +569 -0
  64. package/src/adapters/fired.ts +1580 -0
  65. package/src/adapters/mcp/CONTRACT.md +240 -0
  66. package/src/adapters/mcp/INTERFACE-GAPS.md +271 -0
  67. package/src/adapters/mcp/NOTES.md +205 -0
  68. package/src/adapters/mcp/bin/serve.ts +349 -0
  69. package/src/adapters/mcp/deliberate.ts +619 -0
  70. package/src/adapters/mcp/index.ts +101 -0
  71. package/src/adapters/mcp/protocol.ts +170 -0
  72. package/src/adapters/mcp/server.ts +1740 -0
  73. package/src/adapters/mcp/stdio.ts +56 -0
  74. package/src/adapters/mcp/tools.ts +779 -0
  75. package/src/adapters/scopes.ts +657 -0
  76. package/src/adapters/sessions.ts +402 -0
  77. package/src/adapters/snapshots.ts +1069 -0
  78. package/src/adapters/stance-env.ts +137 -0
  79. package/src/core/associate/CONTRACT.md +118 -0
  80. package/src/core/associate/INTERFACE-GAPS.md +173 -0
  81. package/src/core/associate/NOTES.md +194 -0
  82. package/src/core/associate/buffer.ts +66 -0
  83. package/src/core/associate/edges.ts +188 -0
  84. package/src/core/associate/index.ts +570 -0
  85. package/src/core/associate/pending.ts +383 -0
  86. package/src/core/associate/spread.ts +149 -0
  87. package/src/core/associate/tunables.ts +123 -0
  88. package/src/core/bridge.ts +272 -0
  89. package/src/core/briefing.ts +67 -0
  90. package/src/core/counterpart.ts +3855 -0
  91. package/src/core/encode/CONTRACT.md +151 -0
  92. package/src/core/encode/INTERFACE-GAPS.md +135 -0
  93. package/src/core/encode/NOTES.md +146 -0
  94. package/src/core/encode/aliases.ts +71 -0
  95. package/src/core/encode/battery.ts +284 -0
  96. package/src/core/encode/chunk.ts +265 -0
  97. package/src/core/encode/emotion.ts +119 -0
  98. package/src/core/encode/floor.ts +76 -0
  99. package/src/core/encode/index.ts +100 -0
  100. package/src/core/encode/precision.ts +162 -0
  101. package/src/core/encode/preselect.ts +269 -0
  102. package/src/core/encode/salience.ts +108 -0
  103. package/src/core/encode/secrets.ts +265 -0
  104. package/src/core/encode/tunables.ts +99 -0
  105. package/src/core/encode/types.ts +286 -0
  106. package/src/core/encode/words.ts +75 -0
  107. package/src/core/handoff/CONTRACT.md +199 -0
  108. package/src/core/handoff/INTERFACE-GAPS.md +166 -0
  109. package/src/core/handoff/NOTES.md +206 -0
  110. package/src/core/handoff/index.ts +957 -0
  111. package/src/core/mint.ts +279 -0
  112. package/src/core/observer.ts +28 -0
  113. package/src/core/physics/CONTRACT.md +341 -0
  114. package/src/core/physics/NOTES.md +155 -0
  115. package/src/core/physics/clock.ts +51 -0
  116. package/src/core/physics/index.ts +1054 -0
  117. package/src/core/prospective/CONTRACT.md +137 -0
  118. package/src/core/prospective/INTERFACE-GAPS.md +112 -0
  119. package/src/core/prospective/NOTES.md +160 -0
  120. package/src/core/prospective/derive.ts +188 -0
  121. package/src/core/prospective/index.ts +1030 -0
  122. package/src/core/prospective/tunables.ts +72 -0
  123. package/src/core/prospective/windows.ts +187 -0
  124. package/src/core/recall/CONTRACT.md +326 -0
  125. package/src/core/recall/INTERFACE-GAPS.md +163 -0
  126. package/src/core/recall/NOTES.md +472 -0
  127. package/src/core/recall/activate.ts +521 -0
  128. package/src/core/recall/cues.ts +275 -0
  129. package/src/core/recall/gate.ts +441 -0
  130. package/src/core/recall/index.ts +692 -0
  131. package/src/core/recall/probe.ts +239 -0
  132. package/src/core/recall/reference.ts +201 -0
  133. package/src/core/recall/render.ts +285 -0
  134. package/src/core/recall/session.ts +403 -0
  135. package/src/core/recall/tunables.ts +329 -0
  136. package/src/core/remember/CONTRACT.md +293 -0
  137. package/src/core/remember/INTERFACE-GAPS.md +189 -0
  138. package/src/core/remember/NOTES.md +373 -0
  139. package/src/core/remember/fallback.ts +452 -0
  140. package/src/core/remember/index.ts +103 -0
  141. package/src/core/remember/owner-strike-seam.ts +479 -0
  142. package/src/core/remember/proposals.ts +609 -0
  143. package/src/core/remember/spans.ts +1310 -0
  144. package/src/core/remember/tunables.ts +111 -0
  145. package/src/core/remember/updates.ts +198 -0
  146. package/src/core/retrieval.ts +96 -0
  147. package/src/core/revision.ts +441 -0
  148. package/src/core/schemas/CONTRACT.md +190 -0
  149. package/src/core/schemas/INTERFACE-GAPS.md +172 -0
  150. package/src/core/schemas/NOTES.md +260 -0
  151. package/src/core/schemas/aliases.ts +160 -0
  152. package/src/core/schemas/index.ts +1459 -0
  153. package/src/core/schemas/tunables.ts +44 -0
  154. package/src/core/schemas/types.ts +387 -0
  155. package/src/core/self/CONTRACT.md +459 -0
  156. package/src/core/self/INTERFACE-GAPS.md +284 -0
  157. package/src/core/self/NOTES.md +1057 -0
  158. package/src/core/self/briefing.ts +980 -0
  159. package/src/core/self/episodes.ts +483 -0
  160. package/src/core/self/freeze.ts +103 -0
  161. package/src/core/self/identity.ts +604 -0
  162. package/src/core/self/index.ts +2130 -0
  163. package/src/core/self/journal-file.ts +760 -0
  164. package/src/core/self/page.ts +404 -0
  165. package/src/core/self/tunables.ts +244 -0
  166. package/src/core/self/writer.ts +714 -0
  167. package/src/core/sleep/CONTRACT.md +298 -0
  168. package/src/core/sleep/INTERFACE-GAPS.md +262 -0
  169. package/src/core/sleep/NOTES.md +770 -0
  170. package/src/core/sleep/briefing.ts +86 -0
  171. package/src/core/sleep/consolidate.ts +241 -0
  172. package/src/core/sleep/cycle.ts +598 -0
  173. package/src/core/sleep/decay.ts +237 -0
  174. package/src/core/sleep/dedup.ts +373 -0
  175. package/src/core/sleep/index.ts +112 -0
  176. package/src/core/sleep/log.ts +116 -0
  177. package/src/core/sleep/markers.ts +164 -0
  178. package/src/core/sleep/prune.ts +170 -0
  179. package/src/core/sleep/strength-cache.ts +176 -0
  180. package/src/core/sleep/tunables.ts +135 -0
  181. package/src/core/sleep/types.ts +542 -0
  182. package/src/core/store/CONTRACT.md +446 -0
  183. package/src/core/store/NOTES.md +1068 -0
  184. package/src/core/store/cache.ts +709 -0
  185. package/src/core/store/db.ts +275 -0
  186. package/src/core/store/errors.ts +134 -0
  187. package/src/core/store/index.ts +2450 -0
  188. package/src/core/store/operational.ts +610 -0
  189. package/src/core/store/owner-op-seam.ts +428 -0
  190. package/src/core/store/paths.ts +494 -0
  191. package/src/core/store/prose.ts +165 -0
  192. package/src/core/store/render.ts +87 -0
  193. package/src/core/store/walk-seam.ts +78 -0
  194. package/src/core/types.ts +68 -0
  195. package/tools/install-loop/run.sh +1063 -0
@@ -0,0 +1,457 @@
1
+ /**
2
+ * The flow page's map: COUNTERPARTS' own architecture as a diagram, and the
3
+ * rule that every durable event has a place on it.
4
+ *
5
+ * Three things live here and nowhere else:
6
+ *
7
+ * 1. **The nodes** — one per module (plus the two seams a reader can see: the
8
+ * session the host holds, and the crash-fallback sweep). Each carries what
9
+ * it does in plain language and its BRAIN ANALOG, quoted in substance from
10
+ * the module's own `CONTRACT.md` §2 — including where the analogy
11
+ * deliberately breaks, because a comparison that only says where it holds
12
+ * is advertising (constitution line 12: deviations are named).
13
+ * 2. **The edges** — the pipeline, drawn once. `dotted` marks the path that is
14
+ * supposed to be silent: the crash fallback (`remember/fallback.ts`).
15
+ * 3. **The event→node map**, with a TOTALITY rule of exactly the kind
16
+ * `registries.ts` keeps for the axes: `EVENT_NODE` is declared
17
+ * `satisfies Record<DurableEventName, NodeKey>`, so a durable event added
18
+ * to the core fails `tsc` HERE until someone decides which part of the
19
+ * machine it belongs to. A particle with nowhere to land would otherwise
20
+ * just never be drawn, which is the silent-starvation failure again
21
+ * (scar §2.17).
22
+ *
23
+ * Geometry lives here too — normalized 0..1 coordinates — so the page is a dumb
24
+ * renderer and the diagram's shape is reviewable as data.
25
+ */
26
+ import type { DurableEventName } from "../registries.js";
27
+
28
+ export const NODE_KEYS = [
29
+ "session",
30
+ "spans",
31
+ "remember",
32
+ "sweep",
33
+ "encode",
34
+ "store",
35
+ "physics",
36
+ "recall",
37
+ "associate",
38
+ "schemas",
39
+ "prospective",
40
+ "sleep",
41
+ "wake",
42
+ "self",
43
+ ] as const;
44
+
45
+ export type NodeKey = (typeof NODE_KEYS)[number];
46
+
47
+ export interface FlowNode {
48
+ readonly key: NodeKey;
49
+ readonly label: string;
50
+ /** The one-line subtitle under the title in the box. */
51
+ readonly sub: string;
52
+ /** Plain language: what this part of the machine actually does. */
53
+ readonly what: string;
54
+ /** Where the brain comparison holds. */
55
+ readonly analog: string;
56
+ /** Where it deliberately breaks. Never omitted; "none named" is a value. */
57
+ readonly breaks: string;
58
+ /** Normalized 0..1 box, laid out left-to-right along the pipeline. */
59
+ readonly x: number;
60
+ readonly y: number;
61
+ readonly w: number;
62
+ readonly h: number;
63
+ /** Accent colour role the page maps to a CSS variable. */
64
+ readonly accent: "cyan" | "purple" | "amber" | "teal";
65
+ }
66
+
67
+ /**
68
+ * The one-line honest answer for a node that CANNOT light, because nothing in
69
+ * the core writes a durable event for it. Not a gap in the diagram — a fact
70
+ * about the log, said out loud rather than left as an empty panel (scar §2.4).
71
+ */
72
+ export const NO_EVENT_OF_ITS_OWN: Partial<Record<NodeKey, string>> = {
73
+ spans: "Turn capture is silent by design — a captured turn writes no durable event, only a row in the buffer. What it did shows as the buffer's own depth, not as a line in the log.",
74
+ // ASSOCIATE HAD AN ENTRY HERE until 2026-09-17, and the reasoning in it was
75
+ // the trap: "an edge IS its own record" is true of an edge that exists, and
76
+ // says nothing at all about a wiring pass that wrote none. The buffer was
77
+ // filled in the hook process and flushed in the detached worker, so nothing
78
+ // was ever published — and with no event of its own, no surface could tell
79
+ // that from a graph with nothing to add. The hook now leaves its deltas on
80
+ // disk and the worker applies them; `associate.flush` is that apply's row,
81
+ // and the node's.
82
+ // PROSPECTIVE HAD AN ENTRY HERE until 2026-09-20, and it was the associate
83
+ // trap again: "the rows are the record" is true of a window that exists and
84
+ // says nothing about a firing that did or did not happen. `fires` is a
85
+ // counter and `last_fired_day` a single day, so the store could say a window
86
+ // had ever fired and never when, why one did not, or which brake held — and
87
+ // the owner's fourteen windows carried v1 counters with `last_fired_day` null
88
+ // on every one. `prospective.fire` and `prospective.fire.refused` are the
89
+ // node's rows now.
90
+ physics: "Physics writes no event of its own, ever. It is arithmetic; the phase that ACTS on a verdict is what records it — so a promotion reads as sleep's line, not as physics'.",
91
+ self: "Identity and episodes are written through the store like anything else. The one name that ever reached the log from here is historical.",
92
+ };
93
+
94
+ /**
95
+ * THE THIRD ABSENCE WORD — a slot that is EMPTY today, and kept for the reason
96
+ * it was built.
97
+ *
98
+ * `(none yet)` means asked, and the answer is zero. `(never run)` means never
99
+ * asked. Both were wrong for ENCODE, which rendered `(never run)` beside STORE's
100
+ * `143 memories held` on the same diagram — a flat contradiction to anyone who
101
+ * did not click it. The gate battery HAD run, on all 143; it simply wrote a
102
+ * durable record on one of its two paths. The crash-sweep path recorded what it
103
+ * gated because nobody watched it happen; the authored path was gated in line,
104
+ * in front of the person who asked, and wrote nothing durable.
105
+ *
106
+ * **That is no longer true, and this entry went away with it (2026-09-05).**
107
+ * `gate.deposit` is the authored door's own row — the same battery, the same
108
+ * content-by-reference rules, one row per deposit that reached it — so both of
109
+ * encode's paths are in the log and the node has an ordinary count to show.
110
+ * Replay §2a, which named this as the place it would change, is closed.
111
+ *
112
+ * The map stays because the WORD is still needed: a node whose work is real but
113
+ * deliberately unrecorded must say so in its own words rather than borrow an
114
+ * absence word that means something else. Keyed separately from
115
+ * `NO_EVENT_OF_ITS_OWN` for the same reason as before — a node with an event
116
+ * name is not a node without events. Empty is the honest state of it now.
117
+ */
118
+ export const UNLOGGED_PATH: Partial<Record<NodeKey, string>> = {};
119
+
120
+ export const FLOW_NODES: readonly FlowNode[] = [
121
+ {
122
+ key: "session",
123
+ label: "SESSION",
124
+ sub: "you and the assistant",
125
+ what: "The live conversation in the host. Three things cross this line: the wake bundle arrives at the start, recall arrives quietly during, and the turns leave for the buffer as they happen.",
126
+ analog: "The present moment — working memory, holding what is being said right now.",
127
+ breaks: "A session ends absolutely. Human working memory has no boundary event; here the boundary is the most important moment in the day, because it is when the author writes.",
128
+ x: 0.02,
129
+ y: 0.42,
130
+ w: 0.13,
131
+ h: 0.15,
132
+ accent: "teal",
133
+ },
134
+ {
135
+ key: "spans",
136
+ label: "SPANS BUFFER",
137
+ sub: "turns, held briefly",
138
+ what: "Every turn is captured to a buffer as it happens. Nothing here is memory yet — it is raw material with a cursor, and its only real customer is the crash fallback.",
139
+ analog: "The few seconds of echoic hold before anything is encoded.",
140
+ breaks: "The brain's buffer decays in seconds and cannot be replayed. This one persists on disk until a boundary claims it, which is the whole reason a crashed session can still be recovered.",
141
+ x: 0.02,
142
+ y: 0.68,
143
+ w: 0.13,
144
+ h: 0.13,
145
+ accent: "teal",
146
+ },
147
+ {
148
+ key: "remember",
149
+ label: "REMEMBER",
150
+ sub: "the authored door",
151
+ what: "The front door: what the assistant itself writes at a boundary (session_end), in the moment (note), and as the day's own chapter. The author decides what was learned; nothing here is scraped.",
152
+ analog: "Hippocampal encoding — binding a lived experience into a durable trace while its context is still present.",
153
+ breaks: "In humans encoding is involuntary. Here it is authored, and an author can decline to write where a hippocampus cannot. The mitigation is that the ask is ambient and its coverage is measured, not assumed.",
154
+ x: 0.20,
155
+ y: 0.40,
156
+ w: 0.15,
157
+ h: 0.17,
158
+ accent: "cyan",
159
+ },
160
+ {
161
+ key: "sweep",
162
+ label: "CRASH SWEEP",
163
+ sub: "the fallback, normally silent",
164
+ what: "For the day the author never got to write. It reads the buffer of a session that crashed, chunks it, and puts each chunk through the gate battery. Its ordinary answer is 'nothing crashed'.",
165
+ analog: "Nothing in the brain corresponds to this. It is an engineering backstop.",
166
+ breaks: "The whole node is a named deviation: memory that recovers from a process crash is not a property biology has or needs.",
167
+ x: 0.20,
168
+ y: 0.76,
169
+ w: 0.15,
170
+ h: 0.13,
171
+ accent: "amber",
172
+ },
173
+ {
174
+ key: "encode",
175
+ label: "ENCODE",
176
+ sub: "secrets · precision · salience · novelty",
177
+ what: "The bouncer. Strips secrets, refuses what is too thin to keep, scores how much this matters (relevance, feeling, predictive value) and how new it is against what is already believed. Both paths leave a durable record of what the gates did: `gate.chunk` for a swept chunk, `gate.deposit` for something the author wrote.",
178
+ analog: "Attention selecting what is worth encoding, plus amygdala tagging that marks emotional material for preferential consolidation.",
179
+ breaks: "The secrets gate has no biological analog — the brain has no interlock that refuses to encode a credential. It is a deliberate, non-ablatable addition.",
180
+ x: 0.40,
181
+ y: 0.40,
182
+ w: 0.15,
183
+ h: 0.17,
184
+ accent: "amber",
185
+ },
186
+ {
187
+ key: "store",
188
+ label: "STORE",
189
+ sub: "three boxes",
190
+ what: "Prose markdown you can open in any editor (canonical), one small SQLite of operational state (canonical), and a cache of search indexes that can always be thrown away and rebuilt.",
191
+ analog: "None, deliberately. This is the engineering floor the brain does not have.",
192
+ breaks: "Exactness where the brain is reconstructive. Human memory has no separable substrate; conflating the two is how the first version ended up with canonical state spread across half a dozen sidecars.",
193
+ x: 0.60,
194
+ y: 0.38,
195
+ w: 0.16,
196
+ h: 0.21,
197
+ accent: "cyan",
198
+ },
199
+ {
200
+ key: "physics",
201
+ label: "PHYSICS",
202
+ sub: "one page of arithmetic",
203
+ what: "How strong a memory is today, how fast it fades, how much a real use reinforces it, how much accumulated pressure it takes to revise a belief. No opinions, no model calls.",
204
+ analog: "Synaptic plasticity and the forgetting curve: potentiation from use, downscaling from disuse, consolidation moving a trace from episodic to semantic.",
205
+ breaks: "Three named deviations: identity-band memories do not decay (flashbulb memories do fade in humans); traces never blend, so there is no substrate confabulation; and only a retrieval the assistant actually USED resets the curve, where in humans every retrieval reconsolidates.",
206
+ x: 0.60,
207
+ y: 0.68,
208
+ w: 0.16,
209
+ h: 0.13,
210
+ accent: "purple",
211
+ },
212
+ {
213
+ key: "recall",
214
+ label: "RECALL",
215
+ sub: "cues → activation → gate",
216
+ what: "Turns what you just said into cues, activates what they reach, and judges each candidate against this turn's own background. Most of what surfaces arrives as a footnote; rarely, one memory speaks up.",
217
+ analog: "Cue-driven spreading activation with a relevance gate, and behavioural-relevance tagging afterwards.",
218
+ breaks: "Surfacing is judged relative to this turn's own background distribution, not against an absolute threshold — where a design wants 'if x > threshold', suspect a flattened gradient. And only a retrieval the reply actually used reconsolidates.",
219
+ x: 0.40,
220
+ y: 0.12,
221
+ w: 0.15,
222
+ h: 0.17,
223
+ accent: "purple",
224
+ },
225
+ {
226
+ key: "associate",
227
+ label: "ASSOCIATE",
228
+ sub: "what fires together, wires",
229
+ what: "Memories that come up together get an edge between them, and activation spreads along those edges at the next recall.",
230
+ analog: "Hebbian plasticity — cells that fire together wire together — plus spreading activation through the resulting network.",
231
+ breaks: "Credit is retrospective and graded: full only when the reply actually used the memory, weak when it surfaced unused, zero for the merely footnoted — where in humans every retrieval trains. Homeostasis is structural (an edge cap, a bounded outgoing weight) rather than metabolic.",
232
+ x: 0.82,
233
+ y: 0.66,
234
+ w: 0.15,
235
+ h: 0.13,
236
+ accent: "teal",
237
+ },
238
+ {
239
+ key: "schemas",
240
+ label: "SCHEMAS",
241
+ sub: "entities · beliefs · pressure",
242
+ what: "What is believed about people and things. Entities are born by mention; each carries beliefs and current facts. A belief is revised only when accumulated pressure crosses its bar, and the challenge log survives.",
243
+ analog: "Schema formation and semantic memory: repeated episodes abstract into a structure that new experience is compared against, which is what makes prediction error possible.",
244
+ breaks: "Beliefs never blend into each other. Generalization is only ever an explicit, provenance-carrying revision — biology's interference and source confusion are the bugs, not the architecture.",
245
+ x: 0.82,
246
+ y: 0.38,
247
+ w: 0.15,
248
+ h: 0.17,
249
+ accent: "purple",
250
+ },
251
+ {
252
+ key: "prospective",
253
+ label: "PROSPECTIVE",
254
+ sub: "intentions, held",
255
+ what: "Future commitments that resurface on their own when their moment arrives, rather than sitting in a list you have to check.",
256
+ analog: "Time-based prospective memory — the intention that comes back by itself when the moment comes.",
257
+ breaks: "Human prospective memory fails toward forgetting; this fails toward tact. A system that surfaces every stored commitment at first retrievability is a task queue wearing memory's clothes. Hold debts, lose deadlines.",
258
+ x: 0.82,
259
+ y: 0.86,
260
+ w: 0.15,
261
+ h: 0.11,
262
+ accent: "amber",
263
+ },
264
+ {
265
+ key: "sleep",
266
+ label: "SLEEP",
267
+ sub: "decay · prune · consolidate · dedup",
268
+ what: "Housekeeping at the boundary: fade what was not used, delete at the floor, promote what has proven itself over separate days, merge duplicates, then re-render the briefing. Pure arithmetic, no model calls.",
269
+ analog: "Systems consolidation during sleep: replay, schema integration, synaptic downscaling, and the pruning of what was never used.",
270
+ breaks: "It runs as boundary-time micro-sleeps rather than one nightly block, because a session end is when the material is freshest and the host is idle. And it PRUNES at the floor: human forgetting is loss of access, not deletion — this deletes, loudly, on physics' verdict alone.",
271
+ x: 0.60,
272
+ y: 0.10,
273
+ w: 0.16,
274
+ h: 0.17,
275
+ accent: "cyan",
276
+ },
277
+ {
278
+ key: "wake",
279
+ label: "WAKE",
280
+ sub: "the briefing, waiting",
281
+ what: "The bundle the next session opens with: who this has been, in its own words, in lanes with a byte budget the host reports. Rendered without a model.",
282
+ analog: "Re-inhabiting yourself on waking — the self-schema you resume rather than look up.",
283
+ breaks: "A human wakes into their self continuously. Here the briefing is composed at one moment and handed over at another, so its arrival can be verified — and is, by a sentinel.",
284
+ x: 0.20,
285
+ y: 0.10,
286
+ w: 0.15,
287
+ h: 0.17,
288
+ accent: "cyan",
289
+ },
290
+ {
291
+ key: "self",
292
+ label: "SELF",
293
+ sub: "identity · episodes",
294
+ what: "The autobiography: identity elements that strength earned or the owner made permanent, and the episode journal written in chapters, in the first person, at the boundary.",
295
+ analog: "Autobiographical memory and the narrative self — episodic replay feeding a stable self-schema.",
296
+ breaks: "Humans never author their episodes; here it is a ritual, which is the authorship thesis. Identity-band memories do not decay here. And transcript-derived self-reinforcement is deliberately not copied — it is the rumination pathway, a documented bug of human cognition rather than architecture.",
297
+ x: 0.82,
298
+ y: 0.10,
299
+ w: 0.15,
300
+ h: 0.17,
301
+ accent: "purple",
302
+ },
303
+ ];
304
+
305
+ export interface FlowEdge {
306
+ readonly from: NodeKey;
307
+ readonly to: NodeKey;
308
+ /** The crash path, drawn dotted: it is supposed to be silent. */
309
+ readonly dotted?: boolean;
310
+ /** Bow direction: 0 straight, negative arcs above, positive below. */
311
+ readonly bow?: number;
312
+ readonly label?: string;
313
+ }
314
+
315
+ export const FLOW_EDGES: readonly FlowEdge[] = [
316
+ { from: "session", to: "spans", label: "every turn" },
317
+ { from: "session", to: "remember", label: "what was learned" },
318
+ { from: "spans", to: "sweep", dotted: true, label: "only if it crashed" },
319
+ { from: "sweep", to: "encode", dotted: true },
320
+ { from: "remember", to: "encode" },
321
+ { from: "encode", to: "store", label: "what got in" },
322
+ { from: "store", to: "physics" },
323
+ { from: "store", to: "schemas" },
324
+ { from: "store", to: "associate" },
325
+ { from: "store", to: "prospective" },
326
+ { from: "store", to: "self" },
327
+ { from: "store", to: "recall", label: "candidates" },
328
+ { from: "associate", to: "recall", bow: 0.3, label: "spreads" },
329
+ { from: "recall", to: "session", label: "footnotes · one loud" },
330
+ { from: "store", to: "sleep", label: "at every boundary" },
331
+ { from: "sleep", to: "store", bow: -0.18 },
332
+ { from: "self", to: "wake", bow: -0.35, label: "composes" },
333
+ { from: "sleep", to: "wake", label: "re-renders" },
334
+ { from: "wake", to: "session", label: "at session start" },
335
+ ];
336
+
337
+ /**
338
+ * EVENT → NODE. **Exhaustive by type**, the way `BAND_ORDER` and
339
+ * `DURABLE_EVENTS` are: a durable event the core learns to write has to be given
340
+ * a home here before `tsc` will pass, so no particle is ever dropped on the
341
+ * floor. Where an event belongs to the phase that RECORDED it rather than to the
342
+ * module whose arithmetic decided it, that is deliberate and noted.
343
+ */
344
+ export const EVENT_NODE = {
345
+ // The sleep cycle's four durable records. `band.promoted` and
346
+ // `band.transition` are physics' verdicts, but sleep is what wrote them —
347
+ // and the honest answer to "who did this" is the phase, not the arithmetic.
348
+ "band.promoted": "sleep",
349
+ "band.transition": "sleep",
350
+ "memory.pruned": "sleep",
351
+ "memory.merged": "sleep",
352
+ // The repair is the owner's, but the row it puts back is the store's.
353
+ "memory.unmerged": "store",
354
+ // The gate battery, wherever it runs: the chunk record is the encode door's.
355
+ "gate.chunk": "encode",
356
+ // Both gate doors light the SAME node. The battery is one battery; which door
357
+ // walked a proposal up to it is a field on the row, not a second node.
358
+ "gate.deposit": "encode",
359
+ // The fallback's own record, including the runs that swept nothing.
360
+ "sweep.gate": "sweep",
361
+ // The self the fallback was woken with. It is `self/`'s composition, but what
362
+ // the row describes is the SWEEP's prompt, so it lights the sweep node beside
363
+ // the gate row it always arrives with.
364
+ "sweep.wake": "sweep",
365
+ // The cycle's own record (U9). Same call as the four above: the honest answer
366
+ // to "who did this" is the phase that ran, and the run is the whole of sleep.
367
+ "sleep.cycle": "sleep",
368
+ // The wake render's record. It is `self/`'s composition and `sleep/`'s order,
369
+ // but what the row DESCRIBES is the bundle — what rendered, what was trimmed —
370
+ // so it lights the node the owner will actually read it against.
371
+ "self.briefing": "wake",
372
+ // The page is what the wake now LEADS with, so both of its rows belong to the
373
+ // wake node: written at one boundary, read at every one after it.
374
+ "self.page.revised": "wake",
375
+ "self.page.refused": "wake",
376
+ // The nightly writer belongs to the same node for the same reason: what it
377
+ // produces is the first thing the next wake prints.
378
+ "self.page.writer.ran": "wake",
379
+ // The handoff is working context for a directory, written at a boundary and
380
+ // spliced into the wake of the next session that opens there. It is not a
381
+ // memory and never becomes one, so it lights the wake node — where the owner
382
+ // reads it — and not `store` or `remember`.
383
+ "handoff.written": "wake",
384
+ "handoff.shown": "wake",
385
+ "handoff.refused": "wake",
386
+ "handoff.cleared": "wake",
387
+ // Reference resolution: the boundary's credit decision (recall §9.2).
388
+ "recall.credit": "recall",
389
+ // The wiring that follows that decision: what the reply used together got
390
+ // linked together, by the worker the boundary spawned. `recall.credit` says
391
+ // which memories; this says what the graph did about it.
392
+ "associate.flush": "associate",
393
+ // Retrieval: the decision, and the adapter's composed injection.
394
+ "recall.decision": "recall",
395
+ "adapter.recall": "recall",
396
+ "adapter.semantic.lag": "recall",
397
+ // The briefing's two halves: handed over, and confirmed as arrived.
398
+ "adapter.wake.injected": "wake",
399
+ "adapter.wake.delivered": "wake",
400
+ // The host's session boundary and the parallel run's two delivery guards.
401
+ "adapter.boundary": "session",
402
+ "adapter.primacy.deliver": "session",
403
+ "adapter.primacy.standdown": "session",
404
+ // The ask that asks for memories — the authored door's pacing.
405
+ "adapter.ask": "remember",
406
+ "adapter.authorship.ask": "remember",
407
+ // The episode half of the old two-ask Stop belonged to the journal.
408
+ "adapter.episode.ask": "self",
409
+ // The worker giving vectors to memories that had none: box 3's business.
410
+ "adapter.embed.backfill": "store",
411
+ // The three spawn-seam records (I32). The worker carries the crash fallback,
412
+ // the flush and the cycle; when it cannot start or cannot finish, the node
413
+ // that did not happen is the sweep's.
414
+ "adapter.spawn.refused": "sweep",
415
+ "adapter.spawn.failed": "sweep",
416
+ "adapter.runner.failed": "sweep",
417
+ // The other half of those three: the worker that DID start, same node.
418
+ "adapter.spawn.started": "sweep",
419
+ // The deliberate look is a retrieval, so it lands where the ambient one does.
420
+ "mcp.recall": "recall",
421
+ // A reminder arriving is a CUE offered into the turn (§12: arrival is a cue,
422
+ // not a command), so both rows land on the prospective node.
423
+ "prospective.fire": "prospective",
424
+ "prospective.fire.refused": "prospective",
425
+ // Which checkout was live at a session start. It belongs to the SESSION node:
426
+ // it is a fact about the process the host started, recorded on the way in,
427
+ // before anything was read or written.
428
+ "adapter.checkout": "session",
429
+ // The daily rotating snapshot is upkeep on the store itself — the same node
430
+ // the backfill lands on, because what it is about is the boxes, not a memory.
431
+ "snapshot.taken": "store",
432
+ "snapshot.failed": "store",
433
+ "snapshot.rotated": "store",
434
+ // The journal's markdown copy is upkeep on the store's own directory — the
435
+ // words are the episode row's and this is the file beside it — and the hand
436
+ // export is the same node for the same reason: both are about the boxes.
437
+ "journal.copy.written": "store",
438
+ "journal.copy.failed": "store",
439
+ "store.export": "store",
440
+ // A credited challenge, from either arm (belief or identity element).
441
+ "revision.pressure": "schemas",
442
+ } as const satisfies Record<DurableEventName, NodeKey>;
443
+
444
+ export function nodeOf(name: string): NodeKey | null {
445
+ return (EVENT_NODE as Record<string, NodeKey>)[name] ?? null;
446
+ }
447
+
448
+ export function findNode(key: string): FlowNode | undefined {
449
+ return FLOW_NODES.find((n) => n.key === key);
450
+ }
451
+
452
+ /** Every event name that lands on one node. Used for the node's own feed. */
453
+ export function eventsOfNode(key: NodeKey): string[] {
454
+ return Object.entries(EVENT_NODE)
455
+ .filter(([, node]) => node === key)
456
+ .map(([name]) => name);
457
+ }