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
@@ -9,7 +9,11 @@ import { NEVER, NONE } from "../../layout.js";
9
9
  import { DURABLE_EVENTS, DURABLE_EVENT_NAMES } from "../../registries.js";
10
10
  import type { DurableEventName } from "../../registries.js";
11
11
  import type { DashboardSource } from "../../source.js";
12
+ import type { EventRow } from "../../../../core/store/index.js";
13
+ import { payloadOf } from "../../../mechanism-evidence.js";
12
14
  import { FLOW_NODES, eventsOfNode } from "../flow.js";
15
+ import { laneOf } from "../lanes.js";
16
+ import type { Lane } from "../lanes.js";
13
17
  import { narrate } from "../narrate.js";
14
18
  import type { NarratedEvent } from "../narrate.js";
15
19
  import { FEED_LIMIT, LOG_CEILING, eventCountsByName } from "./shared.js";
@@ -30,7 +34,7 @@ export interface ActivityView {
30
34
 
31
35
  export function activityView(
32
36
  src: DashboardSource,
33
- opts: { limit?: number; name?: string; sinceSeq?: number } = {},
37
+ opts: { limit?: number; name?: string; sinceSeq?: number; lane?: Lane } = {},
34
38
  ): ActivityView {
35
39
  const store = src.store;
36
40
  const limit = opts.limit ?? FEED_LIMIT;
@@ -38,7 +42,9 @@ export function activityView(
38
42
  if (opts.name !== undefined && opts.name.length > 0) filter.name = opts.name;
39
43
  const all = store.eventLog(filter);
40
44
  const since = opts.sinceSeq;
41
- const window = since === undefined ? all.slice(-limit).reverse() : all.filter((r) => r.seq > since);
45
+ const lane = opts.lane;
46
+ const inLane = (r: EventRow): boolean => lane === undefined || laneOf(r.name, payloadOf(r)) === lane;
47
+ const window = since === undefined ? newestIn(all, limit, inLane) : all.filter((r) => r.seq > since);
42
48
  const events = window.map((row) => narrate(store, row));
43
49
  const lastSeq = all.length === 0 ? 0 : (all[all.length - 1]?.seq ?? 0);
44
50
  const everLived = store.livedDay() > 0 || store.list().length > 0;
@@ -66,6 +72,16 @@ export function activityView(
66
72
  };
67
73
  }
68
74
 
75
+ /** The newest `limit` rows that pass `keep`, newest first. */
76
+ function newestIn(rows: readonly EventRow[], limit: number, keep: (r: EventRow) => boolean): EventRow[] {
77
+ const out: EventRow[] = [];
78
+ for (let i = rows.length - 1; i >= 0 && out.length < limit; i--) {
79
+ const r = rows[i];
80
+ if (r !== undefined && keep(r)) out.push(r);
81
+ }
82
+ return out;
83
+ }
84
+
69
85
  /** One record, opened. `when` is its moment on the reader's clock, converted
70
86
  * here (`core/time.ts`), so the page never builds a date itself. */
71
87
  export function eventDetail(
@@ -13,24 +13,32 @@ import { MERGE_ARCHIVE_REASON, PRUNE_ARCHIVE_REASON } from "../../../../core/sle
13
13
  * store's WRITE seam and this directory imports no write seam. */
14
14
  export const REMOVED_BY_OWNER = "removed-by-owner";
15
15
 
16
+ /**
17
+ * What kind of leaving it was, for the home page's "replaced" tile (2026-09-26,
18
+ * an experiment): an older reading REPLACED by a newer one (nothing forgotten),
19
+ * a memory LET GO because it faded, or one REMOVED by the owner.
20
+ */
21
+ export type ArchiveGroup = "replaced" | "let-go" | "removed";
22
+
16
23
  export interface ArchiveReasonWords {
17
24
  readonly reason: string;
18
25
  readonly many: string;
19
26
  readonly one: string;
27
+ readonly group: ArchiveGroup;
20
28
  }
21
29
 
22
30
  /** EVERY `archived_reason` the code writes, in the order the health bar draws them. */
23
31
  export const ARCHIVE_WORDS: readonly ArchiveReasonWords[] = [
24
- { reason: "handoff-cleared", many: "old handoff notes cleared", one: "old handoff note cleared" },
25
- { reason: "handoff-duplicate", many: "duplicate handoff notes retired", one: "a repeated handoff note, cleared" },
26
- { reason: SCHEMA_TUNABLES.REVISED_REASON, many: "revised", one: "revised — a newer version replaced it" },
27
- { reason: SCHEMA_TUNABLES.REPLACED_REASON, many: "replaced by a correction", one: "replaced by a correction" },
28
- { reason: "supersede", many: "replaced by a newer version", one: "replaced by a newer version" },
29
- { reason: "episode-regrown", many: "rebuilt from the journal", one: "regrown from its episode — a newer reading replaced it" },
30
- { reason: SCHEMA_TUNABLES.FADE_REASON, many: "faded from use", one: "faded away — nothing mentions it any more" },
31
- { reason: PRUNE_ARCHIVE_REASON, many: "let go at the floor", one: "let go at the floor — too weak for too long" },
32
- { reason: MERGE_ARCHIVE_REASON, many: "merged duplicates", one: "merged into a near-duplicate" },
33
- { reason: REMOVED_BY_OWNER, many: "removed by you", one: "removed by you" },
32
+ { reason: "handoff-cleared", many: "old handoff notes cleared", one: "old handoff note cleared", group: "replaced" },
33
+ { reason: "handoff-duplicate", many: "duplicate handoff notes retired", one: "a repeated handoff note, cleared", group: "replaced" },
34
+ { reason: SCHEMA_TUNABLES.REVISED_REASON, many: "revised", one: "revised — a newer version replaced it", group: "replaced" },
35
+ { reason: SCHEMA_TUNABLES.REPLACED_REASON, many: "replaced by a correction", one: "replaced by a correction", group: "replaced" },
36
+ { reason: "supersede", many: "replaced by a newer version", one: "replaced by a newer version", group: "replaced" },
37
+ { reason: "episode-regrown", many: "rebuilt from the journal", one: "regrown from its episode — a newer reading replaced it", group: "replaced" },
38
+ { reason: SCHEMA_TUNABLES.FADE_REASON, many: "faded from use", one: "faded away — nothing mentions it any more", group: "let-go" },
39
+ { reason: PRUNE_ARCHIVE_REASON, many: "let go at the floor", one: "let go at the floor — too weak for too long", group: "let-go" },
40
+ { reason: MERGE_ARCHIVE_REASON, many: "merged duplicates", one: "merged into a near-duplicate", group: "replaced" },
41
+ { reason: REMOVED_BY_OWNER, many: "removed by you", one: "removed by you", group: "removed" },
34
42
  ];
35
43
 
36
44
  /** `[reason, many]` pairs, in the bar's order. */
@@ -55,3 +63,12 @@ export function archiveWords(reason: string | null, superseded: boolean): string
55
63
  if (superseded) return "revised — a newer version replaced it";
56
64
  return unmappedArchiveWords(reason);
57
65
  }
66
+
67
+ /** Which group an archived row falls in. A reason nobody mapped counts as
68
+ * replaced only when a newer version superseded it; otherwise it stays apart
69
+ * (`null`), so the tile never files it under a word it has not earned. */
70
+ export function archiveGroup(reason: string | null, superseded = false): ArchiveGroup | null {
71
+ const entry = archiveEntry(reason);
72
+ if (entry !== undefined) return entry.group;
73
+ return superseded ? "replaced" : null;
74
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * THE DREAM JOURNAL and THE CORE'S HISTORY, as the owner reads them
3
+ * (2026-09-26, dreaming + consolidation).
4
+ *
5
+ * dreams — each dream, newest first: its date, its state (begun,
6
+ * journaled, undone), its title and journal — the dream's own
7
+ * words, kept in the `dreams` table and never as a memory — and
8
+ * every change it made, in order, each naming the memories it
9
+ * touched (clickable) and marked when it was undone.
10
+ * coreHistory — the recent crossings into the core with the LANE that carried
11
+ * each, the owner's demotions with the reason he gave, and the
12
+ * memories dreams nominated (a nomination is not a promotion;
13
+ * only a lane at consolidation promotes).
14
+ *
15
+ * Read-only, like everything in this directory: `dreams`, `dreamChanges` and
16
+ * `coreEvents` are reads. Memory words go through `reveal` (a merged original
17
+ * through `revealHere`, so it reads as it stood, not as what it became), so a
18
+ * confidential memory is withheld here exactly as everywhere else.
19
+ */
20
+ import type { CoreEventRow, DreamChangeRow, DreamRow } from "../../../../core/store/index.js";
21
+ import type { DashboardSource } from "../../source.js";
22
+ import { reveal, revealHere } from "../reveal.js";
23
+
24
+ /** How many dreams the journal carries; the rest are counted, not sent. */
25
+ export const DREAM_LIMIT = 12;
26
+ /** How many rows of core history each list carries. */
27
+ export const CORE_HISTORY_LIMIT = 8;
28
+
29
+ export interface DreamMemoryRef {
30
+ readonly id: string;
31
+ readonly text: string;
32
+ readonly confidential: boolean;
33
+ }
34
+
35
+ export interface DreamChangeView {
36
+ readonly seq: number;
37
+ readonly action: string;
38
+ /** The change in plain words ("merged 2 near-copies into one"). */
39
+ readonly said: string;
40
+ /** The memories it touched: the one it made or changed first, then the rest. */
41
+ readonly memories: readonly DreamMemoryRef[];
42
+ readonly undone: boolean;
43
+ }
44
+
45
+ export interface DreamView {
46
+ readonly id: string;
47
+ readonly date: string | null;
48
+ readonly day: number;
49
+ readonly state: string;
50
+ readonly title: string | null;
51
+ /** The journal entry, whole. Null while the dream has not written one. */
52
+ readonly journal: string | null;
53
+ /** Changes still standing, by action. */
54
+ readonly counts: Readonly<Record<string, number>>;
55
+ readonly changes: readonly DreamChangeView[];
56
+ }
57
+
58
+ export interface DreamsView {
59
+ readonly dreams: readonly DreamView[];
60
+ /** Dreams past the ones sent. */
61
+ readonly more: number;
62
+ /** The day of the newest dream, or null when this store has never dreamed. */
63
+ readonly lastDreamed: string | null;
64
+ }
65
+
66
+ export interface CoreHistoryRow {
67
+ readonly id: string;
68
+ readonly text: string;
69
+ readonly confidential: boolean;
70
+ readonly day: number;
71
+ /** promoted: the lane; demoted: null; nominated: null. */
72
+ readonly lane: string | null;
73
+ /** The owner's reason (demoted) or the dream's (nominated). */
74
+ readonly reason: string | null;
75
+ /** nominated: the dream that nominated it. */
76
+ readonly dream: string | null;
77
+ }
78
+
79
+ export interface CoreHistory {
80
+ readonly promoted: readonly CoreHistoryRow[];
81
+ readonly demoted: readonly CoreHistoryRow[];
82
+ readonly nominated: readonly CoreHistoryRow[];
83
+ }
84
+
85
+ function ref(src: DashboardSource, id: string | null, here = false): DreamMemoryRef | null {
86
+ if (id === null) return null;
87
+ const r = here ? revealHere(src.store, id, 90) : reveal(src.store, id, 90);
88
+ return { id, text: r.text ?? r.label, confidential: r.confidential };
89
+ }
90
+
91
+ function detailOf(c: DreamChangeRow): Record<string, unknown> {
92
+ try {
93
+ const v: unknown = JSON.parse(c.detail);
94
+ return v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record<string, unknown>) : {};
95
+ } catch {
96
+ return {};
97
+ }
98
+ }
99
+
100
+ const idList = (v: unknown): string[] => (Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []);
101
+
102
+ function changeView(src: DashboardSource, c: DreamChangeRow): DreamChangeView {
103
+ const d = detailOf(c);
104
+ const memories: DreamMemoryRef[] = [];
105
+ const push = (m: DreamMemoryRef | null): void => {
106
+ if (m !== null && !memories.some((x) => x.id === m.id)) memories.push(m);
107
+ };
108
+ let said: string;
109
+ switch (c.action) {
110
+ case "merge": {
111
+ // Destructured, not indexed: this directory's import scan reads a quote
112
+ // straight after the word it looks for as a module path.
113
+ const { from: merged } = d as { from?: unknown };
114
+ const originals = idList(merged);
115
+ push(ref(src, c.ref));
116
+ for (const f of originals) push(ref(src, f, true));
117
+ said = `merged ${originals.length} near-copies into one`;
118
+ break;
119
+ }
120
+ case "link":
121
+ push(ref(src, c.ref));
122
+ push(ref(src, c.ref2));
123
+ said = "linked two memories";
124
+ break;
125
+ case "replayed":
126
+ push(ref(src, c.ref));
127
+ said = d["counted"] === true ? "replayed it (a return: it fades a little more slowly)" : "replayed it";
128
+ break;
129
+ case "gist":
130
+ push(ref(src, c.ref));
131
+ for (const s of idList(d["sources"])) push(ref(src, s));
132
+ said = "wrote down a pattern, in its own words (dreamed; it starts low)";
133
+ break;
134
+ case "contradiction":
135
+ push(ref(src, c.ref));
136
+ push(ref(src, c.ref2));
137
+ said = "flagged two memories that disagree (not settled — raised awake)";
138
+ break;
139
+ case "feeling-now":
140
+ push(ref(src, c.ref));
141
+ said = "recorded how an old feeling sits now";
142
+ break;
143
+ case "nominate-core":
144
+ push(ref(src, c.ref));
145
+ said = "nominated it for the core (only a lane promotes)";
146
+ break;
147
+ default:
148
+ push(ref(src, c.ref));
149
+ push(ref(src, c.ref2));
150
+ said = c.action;
151
+ }
152
+ return { seq: c.seq, action: c.action, said, memories, undone: c.undone === 1 };
153
+ }
154
+
155
+ function dreamView(src: DashboardSource, row: DreamRow): DreamView {
156
+ const changes = src.store.dreamChanges(row.id);
157
+ const counts: Record<string, number> = {};
158
+ for (const c of changes) if (c.undone === 0) counts[c.action] = (counts[c.action] ?? 0) + 1;
159
+ return {
160
+ id: row.id,
161
+ date: row.date,
162
+ day: row.day,
163
+ state: row.state,
164
+ title: row.title,
165
+ journal: row.journal,
166
+ counts,
167
+ changes: changes.map((c) => changeView(src, c)),
168
+ };
169
+ }
170
+
171
+ export function dreamsView(src: DashboardSource, limit = DREAM_LIMIT): DreamsView {
172
+ const rows = src.store.dreams({ limit: limit + 1 });
173
+ const shown = rows.slice(0, limit);
174
+ return {
175
+ dreams: shown.map((r) => dreamView(src, r)),
176
+ // One past the limit says "there are more"; the exact count is not worth a scan.
177
+ more: rows.length > limit ? rows.length - limit : 0,
178
+ lastDreamed: rows[0] === undefined ? null : (rows[0].date ?? `lived day ${String(rows[0].day)}`),
179
+ };
180
+ }
181
+
182
+ function historyRow(src: DashboardSource, e: CoreEventRow): CoreHistoryRow {
183
+ const r = reveal(src.store, e.memory_id, 90);
184
+ return {
185
+ id: e.memory_id,
186
+ text: r.text ?? r.label,
187
+ confidential: r.confidential,
188
+ day: e.day,
189
+ lane: e.lane,
190
+ reason: e.reason,
191
+ dream: e.dream_id,
192
+ };
193
+ }
194
+
195
+ export function coreHistory(src: DashboardSource, limit = CORE_HISTORY_LIMIT): CoreHistory {
196
+ const of = (action: string): CoreHistoryRow[] =>
197
+ src.store.coreEvents({ action, limit }).map((e) => historyRow(src, e));
198
+ return { promoted: of("promoted"), demoted: of("demoted"), nominated: of("nominated") };
199
+ }
@@ -17,15 +17,16 @@
17
17
  * Read-only, like everything in this directory. Memory words go through
18
18
  * `reveal`, so a confidential row is withheld here exactly as everywhere else.
19
19
  */
20
- import { TUNABLES, promotionEligibility, strength } from "../../../../core/physics/index.js";
21
- import { isJournal } from "../../../../core/sleep/index.js";
20
+ import { TUNABLES, promotionEligibility, pruneVerdict, strength } from "../../../../core/physics/index.js";
21
+ import type { MemoryPhysics } from "../../../../core/types.js";
22
+ import { aboutMe, isJournal, ownerNames } from "../../../../core/sleep/index.js";
22
23
  import type { EventRow } from "../../../../core/store/index.js";
23
24
  import type { Band, Kind } from "../../../../core/types.js";
24
25
  import type { DashboardSource } from "../../source.js";
25
26
  import { narrate } from "../narrate.js";
26
27
  import type { NarratedEvent } from "../narrate.js";
27
28
  import { reveal, revealHere } from "../reveal.js";
28
- import { MECHANISM_PROOFS, amount, payloadOf } from "./mechanisms.js";
29
+ import { MECHANISM_PROOFS, counted, payloadOf } from "./mechanisms.js";
29
30
  import { census } from "./shared.js";
30
31
  import type { MemoryLine } from "./shared.js";
31
32
 
@@ -87,10 +88,19 @@ export type Picture =
87
88
  }
88
89
  | {
89
90
  readonly kind: "consolidation";
90
- readonly threshold: number;
91
+ /** Fast lane: how strongly felt it must be. */
92
+ readonly needFeeling: number;
93
+ /** Slow lane: returns on this many separate lived days… */
91
94
  readonly requiredDays: number;
92
- readonly climbing: readonly (Said & { readonly base: number; readonly days: number })[];
93
- readonly promoted: readonly (Said & { readonly day: number })[];
95
+ /** …spanning this many lived days. */
96
+ readonly needSpan: number;
97
+ readonly climbing: readonly (Said & {
98
+ readonly feeling: number;
99
+ readonly days: number;
100
+ readonly span: number;
101
+ readonly returned: boolean;
102
+ })[];
103
+ readonly promoted: readonly (Said & { readonly day: number; readonly lane: string | null })[];
94
104
  readonly core: number;
95
105
  }
96
106
  | {
@@ -120,31 +130,61 @@ export interface MechanismPanelView {
120
130
  readonly found: boolean;
121
131
  readonly built: boolean;
122
132
  readonly livedDay: number;
123
- /** The newest few rows that count as this mechanism firing, narrated. */
124
- readonly activity: readonly NarratedEvent[];
133
+ /** The newest few rows that count as this mechanism firing, narrated; a run
134
+ * of lines that read the same is one line with `repeats` (its newest row). */
135
+ readonly activity: readonly (NarratedEvent & { readonly repeats: number })[];
125
136
  /** Null for a grey mechanism, and for a built one with no picture of its own. */
126
137
  readonly picture: Picture | null;
127
138
  }
128
139
 
140
+ /**
141
+ * "I wrote something down and every gate was clear" four times is one line,
142
+ * ×4 (2026-09-26, an experiment). Only NEIGHBOURS that read the same merge, so
143
+ * the order of what happened is kept; the merged line keeps its newest row, so
144
+ * a click opens the latest record behind it.
145
+ */
146
+ export function mergeRepeats(lines: readonly NarratedEvent[]): (NarratedEvent & { repeats: number })[] {
147
+ const out: (NarratedEvent & { repeats: number })[] = [];
148
+ for (const line of lines) {
149
+ const last = out[out.length - 1];
150
+ if (last !== undefined && last.text === line.text && last.name === line.name) last.repeats += 1;
151
+ else out.push({ ...line, repeats: 1 });
152
+ }
153
+ return out;
154
+ }
155
+
129
156
  export function mechanismPanel(src: DashboardSource, id: string): MechanismPanelView {
130
157
  const store = src.store;
131
158
  const livedDay = store.livedDay();
132
159
  const proof = MECHANISM_PROOFS.find((m) => m.id === id);
133
160
  if (proof === undefined) return { id, found: false, built: false, livedDay, activity: [], picture: null };
134
- if (!proof.built) return { id, found: true, built: false, livedDay, activity: [], picture: null };
161
+ if (proof.build === "not") return { id, found: true, built: false, livedDay, activity: [], picture: null };
135
162
 
136
163
  const backing: EventRow[] = [];
137
164
  for (const p of proof.proofs) {
138
165
  for (const row of store.eventLog({ name: p.event, order: "desc", limit: ACTIVITY_LOOKBACK })) {
139
- if (amount(p, payloadOf(row)) > 0) backing.push(row);
166
+ if (counted(p, row, store) > 0) backing.push(row);
140
167
  }
141
168
  }
142
169
  const seen = new Set<number>();
143
- const activity = backing
170
+ const ordered = backing
144
171
  .sort((a, b) => b.seq - a.seq)
145
- .filter((r) => (seen.has(r.seq) ? false : (seen.add(r.seq), true)))
146
- .slice(0, PANEL_ACTIVITY)
147
- .map((r) => narrate(store, r));
172
+ .filter((r) => (seen.has(r.seq) ? false : (seen.add(r.seq), true)));
173
+ // Narrate newest first and stop once one line more than the panel shows has
174
+ // begun: every shown line's count is then whole (within the lookback).
175
+ const lines: NarratedEvent[] = [];
176
+ let groups = 0;
177
+ let lastText: string | null = null;
178
+ for (const row of ordered) {
179
+ const line = narrate(store, row);
180
+ if (line.text !== lastText) {
181
+ groups += 1;
182
+ lastText = line.text;
183
+ if (groups > PANEL_ACTIVITY) break;
184
+ }
185
+ lines.push(line);
186
+ }
187
+ const activity = mergeRepeats(lines).slice(0, PANEL_ACTIVITY);
148
188
 
149
189
  return { id, found: true, built: true, livedDay, activity, picture: pictureOf(src, id, livedDay) };
150
190
  }
@@ -191,16 +231,9 @@ function decayPicture(src: DashboardSource, day: number): Picture {
191
231
  let from = day;
192
232
  const curves: FadeCurve[] = picks.map((m) => {
193
233
  const physics = store.physicsOf(m.id);
194
- const start = Math.max(physics.lastUsedDay, day - FADE_BEHIND);
195
- from = Math.min(from, start);
196
- const points: [number, number][] = [];
197
- let archiveDay: number | null = null;
198
- for (let d = start; d <= to; d++) {
199
- const s = strength(physics, d);
200
- points.push([d, round(s)]);
201
- if (archiveDay === null && d > day && s < TUNABLES.PHI_PRUNE) archiveDay = d;
202
- }
203
- return { ...saidLine(m), kind: m.kind, band: m.band, lastUsedDay: physics.lastUsedDay, now: round(m.strength), points, archiveDay };
234
+ const curve = fadeCurve(physics, day);
235
+ from = Math.min(from, curve.from);
236
+ return { ...saidLine(m), kind: m.kind, band: m.band, lastUsedDay: physics.lastUsedDay, now: round(m.strength), points: curve.points, archiveDay: curve.archiveDay };
204
237
  });
205
238
  return {
206
239
  kind: "decay",
@@ -264,32 +297,41 @@ function retrievalPicture(src: DashboardSource): Picture {
264
297
  // ── consolidation ───────────────────────────────────────────────────────────
265
298
 
266
299
  /**
267
- * Becoming core takes two things at once: a strong enough base, and real use on
268
- * three separate lived days. Each climber shows both, against the bar; the
269
- * nearest six are listed, with the last few that made it.
300
+ * Becoming core (2026-09-26): only memories about me or about us, by one of two
301
+ * lanes — strongly felt and come back once after a gap (fast), or come back on
302
+ * several separate days over weeks (slow). Each climber shows how far along
303
+ * both lanes it is; the nearest six are listed, with the last few that made it
304
+ * and the lane that carried them.
270
305
  */
271
306
  function consolidationPicture(src: DashboardSource): Picture {
272
307
  const store = src.store;
273
308
  const rows = census(src).filter((m) => !m.schema && !m.unreadable);
274
309
  const core = rows.filter((m) => m.promoted).length;
310
+ const owner = ownerNames(store);
275
311
  const climbing = rows
276
- .filter((m) => !m.promoted)
312
+ .filter((m) => !m.promoted && aboutMe(store, { id: m.id, kind: m.kind }, owner))
277
313
  .map((m) => {
278
- const v = promotionEligibility(store.physicsOf(m.id));
279
- const progress = Math.min(1, v.base / v.threshold) + Math.min(1, v.reinforcedDays / v.requiredDays);
280
- return { m, base: v.base, days: v.reinforcedDays, progress };
314
+ const v = promotionEligibility(store.physicsOf(m.id), { aboutMe: true });
315
+ const fast = Math.min(1, v.fast.intensity / v.fast.needIntensity) + (v.fast.gap !== null && v.fast.gap >= v.fast.needGap ? 1 : 0);
316
+ const slow = Math.min(1, v.slow.days / v.slow.needDays) + Math.min(1, v.slow.span / v.slow.needSpan);
317
+ const returned = v.fast.gap !== null && v.fast.gap >= v.fast.needGap;
318
+ return { m, feeling: v.fast.intensity, days: v.slow.days, span: v.slow.span, returned, progress: Math.max(fast, slow) };
281
319
  })
282
320
  .sort((a, b) => b.progress - a.progress || (a.m.id < b.m.id ? -1 : 1))
283
321
  .slice(0, 6)
284
- .map((c) => ({ ...saidLine(c.m), base: round(c.base), days: c.days }));
322
+ .map((c) => ({ ...saidLine(c.m), feeling: round(c.feeling), days: c.days, span: c.span, returned: c.returned }));
285
323
  const promoted = store
286
324
  .eventLog({ name: "band.promoted", order: "desc", limit: 3 })
287
325
  .filter((r) => r.ref !== null)
288
- .map((r) => ({ ...said(src, r.ref as string), day: r.day }));
326
+ .map((r) => {
327
+ const lane = payloadOf(r)["lane"];
328
+ return { ...said(src, r.ref as string), day: r.day, lane: typeof lane === "string" ? lane : null };
329
+ });
289
330
  return {
290
331
  kind: "consolidation",
291
- threshold: TUNABLES.THETA_ID,
292
- requiredDays: TUNABLES.N_PROMOTION_DAYS,
332
+ needFeeling: TUNABLES.CORE_FAST_FEELING,
333
+ requiredDays: TUNABLES.CORE_SLOW_DAYS,
334
+ needSpan: TUNABLES.CORE_SLOW_SPAN_DAYS,
293
335
  climbing,
294
336
  promoted,
295
337
  core,
@@ -364,6 +406,45 @@ function reconsolidationPicture(src: DashboardSource): Picture {
364
406
  return { kind: "reconsolidation", revisions };
365
407
  }
366
408
 
409
+ /**
410
+ * One memory's fade, as the physics computes it: from its last use (at most
411
+ * `FADE_BEHIND` lived days back) to `FADE_AHEAD` days past `day`, one
412
+ * [lived day, strength] pair per day, and the first day ahead on which it falls
413
+ * below the archive line if nobody uses it. The Forgetting panel draws a few of
414
+ * these; the memory card draws its own one (`memory.ts`).
415
+ */
416
+ export function fadeCurve(
417
+ physics: MemoryPhysics,
418
+ day: number,
419
+ ): { from: number; to: number; points: [number, number][]; archiveDay: number | null } {
420
+ const from = Math.max(physics.lastUsedDay, day - FADE_BEHIND);
421
+ const to = day + FADE_AHEAD;
422
+ const points: [number, number][] = [];
423
+ let archiveDay: number | null = null;
424
+ for (let d = from; d <= to; d++) {
425
+ const s = strength(physics, d);
426
+ points.push([d, round(s)]);
427
+ if (archiveDay === null && d > day && s < TUNABLES.PHI_PRUNE) archiveDay = d;
428
+ }
429
+ return { from, to, points, archiveDay };
430
+ }
431
+
432
+ /**
433
+ * The first lived day within `horizon` days ahead on which prune's own verdict
434
+ * (`physics#pruneVerdict`: under the floor, long enough unused, episodic, not
435
+ * protected) would let this memory go if nobody used it — or null. The
436
+ * revision-chain gate is not checked here (it needs the store), so this can
437
+ * only say "sooner than it will be", never "later".
438
+ */
439
+ export function letGoDay(physics: MemoryPhysics, day: number, horizon: number): number | null {
440
+ // Unused, strength only falls: still over the floor at the horizon means never inside it.
441
+ if (strength(physics, day + horizon) >= TUNABLES.PHI_PRUNE) return null;
442
+ for (let d = day; d <= day + horizon; d++) {
443
+ if (pruneVerdict(physics, d, { inLiveRevisionChain: false }).prune) return d;
444
+ }
445
+ return null;
446
+ }
447
+
367
448
  function round(x: number): number {
368
449
  return Number.isFinite(x) ? Math.round(x * 1000) / 1000 : 0;
369
450
  }