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
@@ -1,19 +1,27 @@
1
- /* The self page — the heart of the tab — and its history as a line of dots.
2
- Clicking a dot shows that version and what changed from the one before it.
3
- Read-only: there is no write door here (the doors are the MCP tool and the
4
- console's `self-page`). */
1
+ /* The self page — the heart of the tab — on the left, whole and untrimmed; and
2
+ in the side column, when it was last rewritten and by whom, what the page
3
+ writer did on its last night, and its history as a line of dots. Clicking a
4
+ dot opens that version and what changed from the one before it; nothing is
5
+ open until then. Read-only: there is no write door here (the doors are the
6
+ MCP tool and the console's `self-page`). */
5
7
  import { absenceLine } from "../../../shared/absence.js";
6
8
  import { $, esc } from "../../../shared/dom.js";
7
9
  import { diffStats, diffText } from "../diff.js";
8
10
  import { renderMarkdown } from "../markdown.js";
11
+ import { ui } from "../state.js";
12
+ import { q, wireTips } from "../../../shared/widgets/tips.js";
9
13
 
10
- export const markup = `
11
- <section class="sp-card" id="self-page"></section>
12
- <div id="self-history"></div>`;
14
+ /** The left column: an opened version (when one is), then the page. */
15
+ export const mainMarkup = `
16
+ <div id="self-version"></div>
17
+ <section class="sp-card" id="self-page"></section>`;
18
+
19
+ /** The side column's top: the page's facts, then its history. */
20
+ export const sideMarkup = `
21
+ <div class="side-block" id="self-meta"></div>
22
+ <div class="side-block" id="self-history"></div>`;
13
23
 
14
24
  let steps = [];
15
- let chosen = -1;
16
- let showWhole = false;
17
25
 
18
26
  const WHO = { owner: "you, by hand", session: "a session", writer: "the page writer" };
19
27
  export const who = (by) => (by ? WHO[by] || by : "someone unrecorded");
@@ -27,91 +35,126 @@ export function shortDate(iso) {
27
35
  return d.toLocaleDateString("en-US", opts);
28
36
  }
29
37
 
30
- export function paint(d) {
38
+ /** The writer's outcome → a tone for its line. */
39
+ const WRITER_TONE = { revised: "ok", "nothing-to-say": "ok", refused: "warn", failed: "warn" };
40
+
41
+ export function paintPage(d) {
31
42
  const p = d.page;
32
43
  $("self-page").innerHTML = d.pageAbsent
33
- ? '<h2 class="sp-title">Who I am</h2>' +
34
- absenceLine(d.pageAbsent, "no page has been written yet — it is written at the end of a session, from what keeps coming up, and you can amend it by hand")
35
- : '<div class="sp-head"><h2 class="sp-title">Who I am <small>— in my own words; the next session opens with this</small></h2>' +
36
- '<div class="sp-chips">' +
37
- '<span class="chip">version ' + p.version + "</span>" +
38
- '<span class="chip">revised ' + esc(shortDate(p.revisedOn) || p.revisedOn || "on an unrecorded date") + "</span>" +
39
- '<span class="chip">by ' + esc(who(p.by)) + "</span>" +
40
- (p.stale ? '<span class="chip warn">not revised in a while</span>' : "") +
41
- "</div></div>" +
42
- (p.reason ? '<div class="sp-reason">Last change: ' + esc(p.reason) + "</div>" : "") +
43
- '<div class="sp-body">' + renderMarkdown(p.body) + "</div>";
44
+ ? absenceLine(d.pageAbsent, "no page has been written yet — it is written at the end of a session, from what keeps coming up, and you can amend it by hand")
45
+ : '<div class="sp-body">' + renderMarkdown(p.body) + "</div>";
46
+ }
44
47
 
45
- // Stay on the standing page when a new version lands; otherwise stay put.
46
- const wasLast = chosen === steps.length - 1;
47
- steps = d.pageHistory || [];
48
- if (wasLast || chosen < 0 || chosen >= steps.length) chosen = steps.length - 1;
49
- paintHistory();
48
+ export function paintMeta(d) {
49
+ const p = d.page;
50
+ const w = d.writer;
51
+ const rows = [];
52
+ if (p) {
53
+ rows.push('<div class="sb-line"><span class="sb-k">Rewritten</span><span>' +
54
+ esc(shortDate(p.revisedOn) || p.revisedOn || "on an unrecorded date") + " · by " + esc(who(p.by)) +
55
+ " · version " + p.version + "</span></div>");
56
+ if (p.stale) rows.push('<div class="sb-line"><span class="chip warn" title="not rewritten in over ' + p.staleAfter + ' days">not rewritten in a while</span></div>');
57
+ if (p.reason) rows.push('<div class="sb-why" title="' + esc(p.reason) + '">“' + esc(p.reason) + "”</div>");
58
+ }
59
+ if (w) {
60
+ rows.push('<div class="sb-writer' + (WRITER_TONE[w.outcome] ? " " + WRITER_TONE[w.outcome] : "") + '">' +
61
+ (w.absent ? '<span class="sb-absent">' + esc(w.absent) + "</span> " : "") + esc(w.line) +
62
+ q("writer", "The page writer reads the day just gone, once a night, and rewrites the page when something about who I am moved. This is its newest run.") +
63
+ "</div>");
64
+ }
65
+ $("self-meta").innerHTML = rows.join("");
66
+ wireTips($("self-meta"));
50
67
  }
51
68
 
52
- function paintHistory() {
69
+ export function paintHistory(d) {
70
+ if (d) steps = d.pageHistory || [];
53
71
  const el = $("self-history");
54
- if (steps.length === 0) { el.innerHTML = ""; return; }
72
+ // A version that is no longer in the history (a cleared page) closes.
73
+ if (ui.version !== null && !steps.some((s) => s.seq === ui.version)) ui.version = null;
74
+ if (steps.length === 0) { el.innerHTML = ""; el.hidden = true; paintVersion(); return; }
75
+ el.hidden = false;
55
76
  if (steps.length === 1) {
56
- el.innerHTML = '<p class="foot sp-once">The page has been written once; there is no earlier version to compare.</p>';
77
+ el.innerHTML = '<h3 class="sb-h">How the page changed</h3>' +
78
+ '<p class="foot sp-once">Written once; there is no earlier version to compare.</p>';
79
+ paintVersion();
57
80
  return;
58
81
  }
59
- const dots = steps.map((s, i) =>
60
- '<button type="button" class="tl-step' + (i === chosen ? " on" : "") + (s.current ? " now" : "") +
61
- '" data-i="' + i + '" aria-pressed="' + (i === chosen) + '" title="' + esc(s.reason || "") + '">' +
82
+ const keep = el.querySelector(".tl");
83
+ const scrollLeft = keep ? keep.scrollLeft : null;
84
+ const dots = steps.map((s) => {
85
+ const on = s.seq === ui.version;
86
+ return '<button type="button" class="tl-step' + (on ? " on" : "") + (s.current ? " now" : "") +
87
+ '" data-seq="' + s.seq + '" aria-pressed="' + on + '" title="' + esc(s.reason || "") + '">' +
62
88
  '<span class="tl-dot"></span>' +
63
89
  '<span class="tl-date">' + esc(shortDate(s.date) || (s.day !== null ? "day " + s.day : "undated")) + "</span>" +
64
90
  '<span class="tl-who">' + esc(s.current ? "now" : "v" + (s.seq - 1)) + " · " + esc(s.by === "owner" ? "you" : s.by || "?") + "</span>" +
65
- "</button>").join("");
91
+ "</button>";
92
+ }).join("");
66
93
  el.innerHTML =
67
- '<h2>How the page changed <small>— ' + steps.length + " versions; click one to see what changed</small></h2>" +
68
- '<div class="tl"><div class="tl-track">' + dots + "</div></div>" +
69
- '<div class="card pad tl-detail" id="self-version"></div>';
94
+ '<h3 class="sb-h">How the page changed ' +
95
+ q("history", steps.length + " versions, oldest on the left. Click one to see what changed from the version before it; click it again to close.") + "</h3>" +
96
+ '<div class="tl"><div class="tl-track">' + dots + "</div></div>";
97
+ const tl = el.querySelector(".tl");
98
+ // Where the line was scrolled stays; the first time, it shows the newest end.
99
+ tl.scrollLeft = scrollLeft === null ? tl.scrollWidth : scrollLeft;
70
100
  el.querySelectorAll(".tl-step").forEach((b) => b.addEventListener("click", () => {
71
- chosen = Number(b.dataset.i);
101
+ const seq = Number(b.dataset.seq);
102
+ ui.version = ui.version === seq ? null : seq;
103
+ ui.whole = false;
72
104
  paintHistory();
105
+ // Only on a click, never on a refresh: bring the opened view into sight.
106
+ const v = $("self-version");
107
+ if (ui.version !== null && v.scrollIntoView) v.scrollIntoView({ block: "nearest" });
73
108
  }));
74
- // Keep the chosen dot in view on a long history.
75
- const on = el.querySelector(".tl-step.on");
76
- if (on && on.scrollIntoView) on.scrollIntoView({ block: "nearest", inline: "nearest" });
109
+ wireTips(el);
77
110
  paintVersion();
78
111
  }
79
112
 
80
113
  function paintVersion() {
81
- const s = steps[chosen];
82
- const prev = chosen > 0 ? steps[chosen - 1] : null;
114
+ const box = $("self-version");
115
+ const i = ui.version === null ? -1 : steps.findIndex((s) => s.seq === ui.version);
116
+ if (i < 0) { box.innerHTML = ""; box.hidden = true; return; }
117
+ box.hidden = false;
118
+ const s = steps[i];
119
+ const prev = i > 0 ? steps[i - 1] : null;
83
120
  const head =
84
121
  '<div class="tl-vhead"><b>' + (s.current ? "The page as it stands" : "Version " + (s.seq - 1)) + "</b>" +
85
122
  '<span class="tl-meta">' + esc(shortDate(s.date) || "undated") + (s.day !== null ? " · lived day " + s.day : "") +
86
- " · written by " + esc(who(s.by)) + (s.bytes !== null ? " · " + s.bytes + " bytes" : "") + "</span></div>" +
123
+ " · written by " + esc(who(s.by)) + (s.bytes !== null ? " · " + s.bytes + " bytes" : "") + "</span>" +
124
+ '<button type="button" class="tl-close" id="self-version-close" aria-label="Close this version">close</button></div>' +
87
125
  (s.reason ? '<div class="tl-why">“' + esc(s.reason) + "”</div>" : "");
88
- if (s.body === null) {
89
- $("self-version").innerHTML = head + '<div class="foot">This version\'s words could not be read.</div>';
90
- return;
91
- }
92
- const canDiff = prev !== null && prev.body !== null;
93
- const toggle = canDiff
94
- ? '<div class="tl-toggle" role="group">' +
95
- '<button type="button" class="seg' + (showWhole ? "" : " on") + '" data-whole="0">What changed</button>' +
96
- '<button type="button" class="seg' + (showWhole ? " on" : "") + '" data-whole="1">The whole version</button></div>'
97
- : "";
126
+ let toggle = "";
98
127
  let body;
99
- if (!canDiff || showWhole) {
100
- body = (prev === null ? '<div class="foot">The first page — nothing came before it.</div>' : "") +
101
- '<div class="sp-body">' + renderMarkdown(s.body) + "</div>";
128
+ if (s.body === null) {
129
+ body = '<div class="foot">This version\'s words could not be read.</div>';
102
130
  } else {
103
- const rows = diffText(prev.body, s.body);
104
- const st = diffStats(rows);
105
- body = '<div class="foot">Compared with ' + "version " + (prev.seq - 1) + ": " +
106
- '<span class="d-add">' + st.added + " line" + (st.added === 1 ? "" : "s") + " added or changed</span>, " +
107
- '<span class="d-del">' + st.removed + " taken out or changed</span>.</div>" +
108
- renderDiff(rows);
131
+ const canDiff = prev !== null && prev.body !== null;
132
+ toggle = canDiff
133
+ ? '<div class="tl-toggle" role="group">' +
134
+ '<button type="button" class="seg' + (ui.whole ? "" : " on") + '" data-whole="0">What changed</button>' +
135
+ '<button type="button" class="seg' + (ui.whole ? " on" : "") + '" data-whole="1">The whole version</button></div>'
136
+ : "";
137
+ if (!canDiff || ui.whole) {
138
+ body = (prev === null ? '<div class="foot">The first page — nothing came before it.</div>' : "") +
139
+ '<div class="sp-body">' + renderMarkdown(s.body) + "</div>";
140
+ } else {
141
+ const rows = diffText(prev.body, s.body);
142
+ const st = diffStats(rows);
143
+ body = '<div class="foot">Compared with version ' + (prev.seq - 1) + ": " +
144
+ '<span class="d-add">' + st.added + " line" + (st.added === 1 ? "" : "s") + " added or changed</span>, " +
145
+ '<span class="d-del">' + st.removed + " taken out or changed</span>.</div>" +
146
+ renderDiff(rows);
147
+ }
109
148
  }
110
- $("self-version").innerHTML = head + toggle + body;
111
- $("self-version").querySelectorAll(".seg").forEach((b) => b.addEventListener("click", () => {
112
- showWhole = b.dataset.whole === "1";
149
+ box.innerHTML = '<div class="card pad tl-detail">' + head + toggle + body + "</div>";
150
+ box.querySelectorAll(".seg").forEach((b) => b.addEventListener("click", () => {
151
+ ui.whole = b.dataset.whole === "1";
113
152
  paintVersion();
114
153
  }));
154
+ $("self-version-close").addEventListener("click", () => {
155
+ ui.version = null;
156
+ paintHistory();
157
+ });
115
158
  }
116
159
 
117
160
  /** Unchanged runs longer than a few lines fold to one line saying so. */
@@ -1,33 +1,48 @@
1
- /* What it's settling into: the core (identity band), what is protected, the
2
- beliefs under challenge — and, while those are empty or few, the memories
3
- closest to the core, measured against physics' own promotion rule (the view
4
- computes it; this only draws it). One line for anything genuinely empty. */
5
- import { absenceLine } from "../../../shared/absence.js";
1
+ /* Settling into the core, as one compact chart: a line of counts (in the core,
2
+ protected, being argued with — each opens the list behind it), then each
3
+ memory closest to the core as one row: a short name, a bar filling toward
4
+ the threshold (earned, with the tick where the core begins), and the day
5
+ dots. The candidates are measured against physics' own promotion rule (the
6
+ view computes it; this only draws it). The explaining words sit behind `?`. */
6
7
  import { $, esc } from "../../../shared/dom.js";
7
8
  import { headline, n2, said } from "../../../shared/format.js";
8
9
  import { openModal } from "../../../shared/modal.js";
10
+ import { ui } from "../state.js";
11
+ import { q, wireTips } from "../../../shared/widgets/tips.js";
9
12
  import { storyCard } from "./stories.js";
10
13
 
11
14
  export const markup = `
12
- <h2 id="self-settling-h">What it's settling into <small>— the core, what's protected, what's being argued with</small></h2>
15
+ <h2 id="self-settling-h">Settling into the core <span id="self-settling-q"></span></h2>
13
16
  <div class="card pad" id="self-settling"></div>`;
14
17
 
15
- const SHOW = 5;
16
18
  let stories = [];
19
+ let last = null;
20
+
21
+ const plural = (n, one, many) => n + " " + (n === 1 ? one : many);
17
22
 
18
23
  export function paint(d) {
24
+ if (d) last = d;
25
+ d = last;
19
26
  const s = d.settling;
20
27
  stories = d.stories || [];
21
- const plural = (n, one, many) => n + " " + (n === 1 ? one : many);
22
- const parts = [];
28
+ $("self-settling-q").innerHTML = q("settling", "The core is what repetition and weight earned; it no longer fades. " +
29
+ "Protected is permanent, including permanently wrong. Being argued with is a belief under pressure against the bar it has to clear to change.");
23
30
 
24
- // ── the one-line summary ──
31
+ // A list that emptied closes.
32
+ if (ui.count && listOf(s, ui.count).length === 0) ui.count = null;
33
+
34
+ const parts = [];
35
+ // ── the one line of counts; each opens its list ──
25
36
  const counts = [
26
- plural(s.core.length, "memory in the core", "memories in the core"),
27
- plural(s.guarded.length, "protected", "protected"),
28
- plural(s.contested.length, "belief being argued with", "beliefs being argued with"),
37
+ ["core", s.core.length, plural(s.core.length, "in the core", "in the core")],
38
+ ["guarded", s.guarded.length, plural(s.guarded.length, "protected", "protected")],
39
+ ["contested", s.contested.length, plural(s.contested.length, "being argued with", "being argued with")],
29
40
  ];
30
- parts.push('<div class="st-sum">' + counts.map((c) => "<span>" + esc(c) + "</span>").join("") + "</div>");
41
+ parts.push('<div class="st-counts">' + counts.map(([key, n, label]) =>
42
+ '<button type="button" class="st-count k-' + key + (ui.count === key ? " on" : "") + '" data-count="' + key + '"' +
43
+ (n === 0 ? " disabled" : "") + ' aria-expanded="' + (ui.count === key) + '">' + esc(label) + "</button>").join('<span class="st-sep" aria-hidden="true">·</span>') +
44
+ "</div>");
45
+ if (ui.count) parts.push('<div class="st-list">' + list(s, ui.count) + "</div>");
31
46
 
32
47
  // ── rows it could not read: always shown when it happens (never folded) ──
33
48
  if (s.unreadable.length > 0) {
@@ -35,116 +50,126 @@ export function paint(d) {
35
50
  " could not be read just now:</b> " + s.unreadable.map((u) => esc(u.label)).join(" · ") + "</div>");
36
51
  }
37
52
 
38
- // ── the core ──
39
- if (s.core.length > 0) parts.push(group("In the core", "what repetition and weight earned; it no longer fades", s.core, "core"));
40
- // ── protected ──
41
- // When nothing protected stands in the core, the two lists are the same rows:
42
- // say it once, in the gloss, rather than printing them twice.
43
- const sameRows = s.outside.length > 0 && s.outside.length === s.guarded.length;
44
- if (s.guarded.length > 0) {
45
- parts.push(group("Protected", sameRows
46
- ? "permanent, including permanently wrong — and none of it has earned the core"
47
- : "permanent — including permanently wrong", s.guarded, "guarded"));
48
- }
49
- if (s.outside.length > 0 && !sameRows) {
50
- parts.push(group("Permanent but not in the core", "worth a look: nothing earned these their place", s.outside, "outside"));
51
- }
52
- // ── contested ──
53
- if (s.contested.length > 0) {
54
- parts.push('<h4 class="st-h">Being argued with <small>— pressure against the bar it has to clear to change</small></h4>' +
55
- s.contested.map((c, i) =>
56
- '<button type="button" class="st-row st-story" data-i="' + i + '">' +
57
- '<span class="st-text"><span class="st-about">about ' + esc(c.about) + "</span>" + esc(headline(c.now)) + "</span>" +
58
- (c.revised
59
- ? '<span class="st-tag changed">changed its mind</span>'
60
- : '<span class="st-bar" title="pressure ' + n2(c.pressure) + " of " + n2(c.bar) + '"><span style="width:' +
61
- Math.round(Math.min(1, c.fraction) * 100) + '%"></span></span>') +
62
- "</button>").join(""));
63
- }
64
-
65
- // ── the honest absences, in one line ──
66
- const empty = [];
67
- if (s.coreAbsent) empty.push("nothing in the core yet");
68
- if (s.guardedAbsent) empty.push("nothing protected");
69
- if (s.contestedAbsent) empty.push("no belief under challenge");
70
- if (empty.length > 0) {
71
- const marker = s.coreAbsent || s.guardedAbsent || s.contestedAbsent;
72
- parts.push('<div class="st-none"><b>' + esc(marker) + "</b> " + esc(empty.join(" · ")) +
73
- (s.coreAbsent && s.candidates.length > 0 ? " — here's what's closest." : ".") + "</div>");
74
- }
53
+ // ── what crossed lately: became core, sent back, nominated ──
54
+ parts.push(history(s.history));
75
55
 
76
56
  // ── on the way ──
77
57
  parts.push(candidates(s));
78
58
 
79
- $("self-settling").innerHTML = parts.join("");
80
- $("self-settling").querySelectorAll(".st-story").forEach((b) => b.addEventListener("click", () => {
59
+ const box = $("self-settling");
60
+ box.innerHTML = parts.join("");
61
+ box.querySelectorAll(".st-count").forEach((b) => b.addEventListener("click", () => {
62
+ ui.count = ui.count === b.dataset.count ? null : b.dataset.count;
63
+ paint();
64
+ }));
65
+ box.querySelectorAll(".st-story").forEach((b) => b.addEventListener("click", () => {
81
66
  const story = stories[Number(b.dataset.i)];
82
67
  if (story) openModal("<h3>How I changed my mind — or didn't</h3>" + storyCard(story));
83
68
  }));
84
- $("self-settling").querySelectorAll(".st-more").forEach((b) => b.addEventListener("click", () => {
85
- b.closest(".st-group").classList.add("all");
86
- b.remove();
87
- }));
69
+ wireTips($("self-settling-q"));
70
+ wireTips(box);
71
+ }
72
+
73
+ /**
74
+ * WHAT CROSSED LATELY (2026-09-26): the newest crossings into the core with
75
+ * the lane that carried each, the owner's demotions with his reason, and the
76
+ * memories a dream nominated. Nothing is drawn when all three are empty.
77
+ */
78
+ function history(h) {
79
+ if (!h) return "";
80
+ const LANE = { fast: "strongly felt, and came back", slow: "kept coming back over weeks" };
81
+ const row = (r, tail) =>
82
+ '<button type="button" class="st-row click" onclick="openMemory(\'' + esc(r.id) + '\')">' +
83
+ '<span class="st-text">' + said(headline(r.text), r.confidential) + "</span>" +
84
+ '<span class="st-hist-tail">' + esc(tail) + "</span></button>";
85
+ const out = [];
86
+ if (h.promoted.length > 0) {
87
+ out.push('<h4 class="st-h">Became core</h4>' + h.promoted.map((r) =>
88
+ row(r, "day " + r.day + (r.lane ? " · " + (LANE[r.lane] || r.lane) : ""))).join(""));
89
+ }
90
+ if (h.demoted.length > 0) {
91
+ out.push('<h4 class="st-h">Sent back to ordinary fading</h4>' + h.demoted.map((r) =>
92
+ row(r, "day " + r.day + (r.reason ? " · " + r.reason : ""))).join(""));
93
+ }
94
+ if (h.nominated.length > 0) {
95
+ out.push('<h4 class="st-h">Nominated in a dream ' + q("nominated", "A dream can say a memory belongs to who I am. That is recorded here and nothing more: only coming back awake, by a lane, makes a memory core.") + "</h4>" +
96
+ h.nominated.map((r) => row(r, "day " + r.day + (r.reason ? " · " + r.reason : ""))).join(""));
97
+ }
98
+ return out.length === 0 ? "" : '<div class="st-hist">' + out.join("") + "</div>";
88
99
  }
89
100
 
90
- function group(title, gloss, rows, key) {
91
- const more = rows.length > SHOW;
92
- return '<div class="st-group" data-k="' + key + '"><h4 class="st-h">' + esc(title) + " <small>— " + esc(gloss) + "</small></h4>" +
93
- rows.map((r, i) =>
94
- '<div class="st-row click' + (i >= SHOW ? " extra" : "") + '" onclick="openMemory(\'' + r.id + '\')">' +
95
- '<span class="st-text">' + said(r.text, r.confidential) + "</span></div>").join("") +
96
- (more ? '<button type="button" class="st-more">show all ' + rows.length + "</button>" : "") +
97
- "</div>";
101
+ function listOf(s, key) {
102
+ return key === "core" ? s.core : key === "guarded" ? s.guarded : key === "contested" ? s.contested : [];
103
+ }
104
+
105
+ function list(s, key) {
106
+ if (key === "contested") {
107
+ return s.contested.map((c, i) =>
108
+ '<button type="button" class="st-row st-story" data-i="' + i + '">' +
109
+ '<span class="st-text"><span class="st-about">about ' + esc(c.about) + "</span>" + esc(headline(c.now)) + "</span>" +
110
+ (c.revised
111
+ ? '<span class="st-tag changed">changed its mind</span>'
112
+ : '<span class="st-bar" title="pressure ' + n2(c.pressure) + " of " + n2(c.bar) + '"><span style="width:' +
113
+ Math.round(Math.min(1, c.fraction) * 100) + '%"></span></span>') +
114
+ "</button>").join("");
115
+ }
116
+ const rows = listOf(s, key);
117
+ // When nothing protected stands in the core, the protected list IS the
118
+ // "permanent but not in the core" list: say so once rather than twice.
119
+ const sameRows = s.outside.length > 0 && s.outside.length === s.guarded.length;
120
+ const note = key === "guarded" && sameRows
121
+ ? '<p class="foot st-note">None of these has earned the core.</p>'
122
+ : "";
123
+ const outside = key === "guarded" && s.outside.length > 0 && !sameRows
124
+ ? '<h4 class="st-h">Permanent but not in the core</h4>' + s.outside.map(row).join("")
125
+ : "";
126
+ return rows.map(row).join("") + note + outside;
127
+ }
128
+
129
+ function row(r) {
130
+ return '<button type="button" class="st-row click" onclick="openMemory(\'' + r.id + '\')">' +
131
+ '<span class="st-text">' + said(r.text, r.confidential) + "</span></button>";
98
132
  }
99
133
 
100
134
  function candidates(s) {
101
135
  const r = s.rule;
102
136
  const c = s.candidates;
103
- const rule = "A memory joins the core once what it has earned reaches " + n2(r.threshold) +
104
- " and it has been used on " + r.days + " different days. That is checked every " + r.everyDays + " lived days.";
137
+ const foot = ["Only a memory about me or about us joins the core, by one of two lanes: strongly felt (" + n2(r.needFeeling) +
138
+ " or more) and come back at least once, " + r.needGap + " or more days after it was made; or come back on " + r.days +
139
+ " different days over " + r.span + ". That is checked every " + r.everyDays + " lived days, at most " + r.cap + " a night."];
140
+ if (s.onTheWay > 0) foot.push(plural(s.onTheWay, "memory about us has", "memories about us have") + " come back at least once.");
141
+ if (s.unused > 0) foot.push(s.unused + " more about us haven't come back yet.");
142
+ if (s.outOfReach > 0) {
143
+ foot.push(s.outOfReach + (s.outOfReach === 1 ? " memory is" : " memories are") +
144
+ " not about me or about us, so the core is not for them however often they come back.");
145
+ }
146
+ const tip = q("rule", foot.join(" "));
105
147
  if (c.length === 0) {
106
- return '<h4 class="st-h">On the way to the core</h4>' +
107
- absenceLine("(none yet)", "no memory is on its way to the core yet") +
108
- '<p class="foot">' + esc(rule) + (s.outOfReach > 0 ? " " + esc(outOfReachLine(s)) : "") + "</p>";
148
+ return '<h4 class="st-h">On the way to the core ' + tip + "</h4>" +
149
+ '<div class="empty"><b>(none yet)</b> nothing is on its way to the core yet.</div>';
109
150
  }
110
- const lead = c[0];
111
- const title = s.onTheWay > 0
112
- ? s.onTheWay + (s.onTheWay === 1 ? " memory is" : " memories are") + " on the way to the core" +
113
- (lead.days > 0 ? ": the closest has been used on " + Math.min(lead.days, lead.requiredDays) + " of the " + lead.requiredDays + " days it needs" : "")
114
- : "Closest to the core — strong enough, not yet used on a later day";
151
+ const scale = 1.2; // the bar is drawn from 0 to 1.2 so the fast lane's mark sits right of centre
115
152
  const rows = c.map((m) => {
116
153
  const ready = m.eligible;
117
- const scale = 1.2; // the bar is drawn from 0 to 1.2 so 0.85 sits right of centre
118
- const have = Math.min(m.base, scale) / scale * 100;
119
- const ghost = m.consolidated ? 0 : Math.min(m.bonus, scale - Math.min(m.base, scale)) / scale * 100;
120
- const strong = m.base >= m.threshold;
154
+ const have = Math.min(m.feeling, scale) / scale * 100;
155
+ const felt = m.feeling >= m.needFeeling;
121
156
  const dots = Array.from({ length: m.requiredDays }, (_, i) =>
122
157
  '<span class="dd' + (i < m.days ? " on" : "") + '"></span>').join("");
123
158
  const status = ready
124
- ? "ready — it crosses at the next check"
125
- : (strong ? "strong enough" : "needs " + n2(m.threshold - m.base) + " more" + (m.consolidated ? "" : " (settling adds " + n2(m.bonus) + " once)")) +
126
- " · used on " + Math.min(m.days, m.requiredDays) + " of " + m.requiredDays + " days";
127
- return '<div class="cand click' + (ready ? " ready" : "") + '" onclick="openMemory(\'' + m.id + '\')">' +
128
- '<div class="cand-text">' + said(m.text, m.confidential) + "</div>" +
129
- '<div class="cand-meters">' +
130
- '<span class="cm-lab">earned</span>' +
131
- '<span class="cm-track" title="earned ' + n2(m.base) + " — the core needs " + n2(m.threshold) + '">' +
132
- '<span class="cm-fill' + (strong ? " ok" : "") + '" style="width:' + have.toFixed(1) + '%"></span>' +
133
- (ghost > 0 ? '<span class="cm-ghost" style="left:' + have.toFixed(1) + "%;width:" + ghost.toFixed(1) + '%"></span>' : "") +
134
- '<span class="cm-mark" style="left:' + (m.threshold / scale * 100).toFixed(1) + '%"></span>' +
135
- "</span>" +
136
- '<span class="cm-lab">days</span><span class="cm-dots" title="used on ' + m.days + " distinct days; " + m.requiredDays + ' needed">' + dots + "</span>" +
137
- "</div>" +
138
- '<div class="cand-status">' + esc(status) + "</div></div>";
159
+ ? "ready (" + m.lane + " lane) — it crosses at the next check"
160
+ : (felt ? "strongly felt" + (m.returned ? "" : " — one return after a gap makes it core") : "felt " + n2(m.feeling) + " of " + n2(m.needFeeling)) +
161
+ " · came back on " + Math.min(m.days, m.requiredDays) + " of " + m.requiredDays + " days, over " + m.span + " of " + m.needSpan;
162
+ return '<button type="button" class="cr' + (ready ? " ready" : "") + '" onclick="openMemory(\'' + m.id + '\')" title="' +
163
+ esc((m.confidential ? "" : m.text + " — ") + status) + '">' +
164
+ '<span class="cr-name">' + (ready ? '<span class="cr-ready">ready</span>' : "") + said(headline(m.text), m.confidential) + "</span>" +
165
+ '<span class="cm-track" aria-label="felt ' + n2(m.feeling) + " of " + n2(m.needFeeling) + '">' +
166
+ '<span class="cm-fill' + (felt ? " ok" : "") + '" style="width:' + have.toFixed(1) + '%"></span>' +
167
+ '<span class="cm-mark" style="left:' + (m.needFeeling / scale * 100).toFixed(1) + '%"></span>' +
168
+ "</span>" +
169
+ '<span class="cm-dots" aria-label="came back on ' + m.days + " of " + m.requiredDays + ' days">' + dots + "</span>" +
170
+ "</button>";
139
171
  }).join("");
140
- const foot = [rule];
141
- if (s.unused > 0 && s.onTheWay > 0) foot.push(s.unused + " more could get there but haven't been used on a later day yet.");
142
- if (s.outOfReach > 0) foot.push(outOfReachLine(s));
143
- return '<h4 class="st-h">' + esc(title) + "</h4>" + rows + '<p class="foot">' + esc(foot.join(" ")) + "</p>";
144
- }
145
-
146
- function outOfReachLine(s) {
147
- const top = s.rule.repCap + s.rule.bonus;
148
- return s.outOfReach + (s.outOfReach === 1 ? " memory was" : " memories were") +
149
- " scored too low to get there by use alone (use tops out at " + n2(top) + ").";
172
+ return '<h4 class="st-h">' + esc(plural(c.length, "memory", "memories")) + " closest to the core " + tip + "</h4>" +
173
+ '<div class="cr-head" aria-hidden="true"><span></span><span>felt</span><span>came back</span></div>' +
174
+ '<div class="cr-list">' + rows + "</div>";
150
175
  }
@@ -1,19 +1,25 @@
1
- /* What the next session wakes up with — folded to one line and a stacked bar of
2
- its parts; click to read the whole text. And the one management door on this
3
- tab: rebuild it now (`counterparts rebrief`, through the actions seam). */
1
+ /* What the next session wakes up with — one line and a stacked bar of its
2
+ parts, in the side column; "read it" opens the whole text in place. The
3
+ rebuild door (`counterparts rebrief`, through the actions seam) is shown but
4
+ not offered for now: rebrief is one step of sleep, and it comes back with
5
+ the sleep work. The console's `counterparts rebrief` is unchanged. */
4
6
  import { absenceLine } from "../../../shared/absence.js";
5
7
  import { act, resultHtml } from "../../../shared/actions.js";
6
8
  import { $, esc } from "../../../shared/dom.js";
9
+ import { ui } from "../state.js";
10
+ import { q, wireTips } from "../../../shared/widgets/tips.js";
7
11
 
8
12
  export const markup = `
9
- <h2>What the next session wakes up with</h2>
10
- <div class="card pad" id="self-wake"></div>
13
+ <div class="side-block">
14
+ <h3 class="sb-h" id="self-wake-h">What the next session wakes up with <span id="self-wake-q"></span></h3>
15
+ <div id="self-wake"></div>
11
16
  <div class="wk-act">
12
- <button type="button" class="act-btn" id="rebrief-go">Rebuild what the next session wakes up with</button>
17
+ <button type="button" class="act-btn" id="rebrief-go" disabled aria-disabled="true"
18
+ title="comes with the sleep work">Rebuild it now</button><span class="soon" title="comes with the sleep work">coming soon</span>
13
19
  <div id="rebrief-out"></div>
14
- </div>`;
20
+ </div>
21
+ </div>`;
15
22
 
16
- let open = false;
17
23
  let onDone = null;
18
24
 
19
25
  export const kb = (b) => (b / 1000).toFixed(1) + " KB";
@@ -21,10 +27,15 @@ export const kb = (b) => (b / 1000).toFixed(1) + " KB";
21
27
  /** The parts, in reading order, with a colour each. */
22
28
  const TONE = { furniture: "p-furn", page: "p-page", identity: "p-page", craft: "p-craft", threads: "p-threads", hints: "p-hints", horizon: "p-horizon" };
23
29
 
30
+ const EXPLAIN = "When a session starts, a line with today's date goes on top, and in a folder with a handoff note, a pointer to it. " +
31
+ "It is composed without a model, at the end of each day.";
32
+
24
33
  export function mount(refresh) {
25
34
  onDone = refresh;
35
+ // The action stays wired, so turning the button back on is one attribute.
26
36
  $("rebrief-go").addEventListener("click", async () => {
27
37
  const go = $("rebrief-go");
38
+ if (go.disabled) return;
28
39
  go.disabled = true;
29
40
  $("rebrief-out").innerHTML = resultHtml({ out: ["rebuilding…"] });
30
41
  const r = await act("rebrief", {});
@@ -34,7 +45,13 @@ export function mount(refresh) {
34
45
  });
35
46
  }
36
47
 
48
+ let last = null;
49
+
37
50
  export function paint(d) {
51
+ if (d) last = d;
52
+ d = last;
53
+ $("self-wake-q").innerHTML = q("wake", EXPLAIN);
54
+ wireTips($("self-wake-q"));
38
55
  const w = d.wake;
39
56
  if (!w.ok) {
40
57
  $("self-wake").innerHTML = absenceLine(w.absent || "(never run)", "no wake has been composed yet (" + w.reason + ")");
@@ -50,16 +67,15 @@ export function paint(d) {
50
67
  '<span class="wk-key"><i class="' + (TONE[p.key] || "p-furn") + '"></i>' + esc(p.label) + " <em>" + kb(p.bytes) + "</em></span>").join("") +
51
68
  (budget && budget > w.bytes ? '<span class="wk-key"><i class="p-room"></i>room left <em>' + kb(budget - w.bytes) + "</em></span>" : "");
52
69
  $("self-wake").innerHTML =
53
- '<button type="button" class="wk-sum" id="wake-toggle" aria-expanded="' + open + '">' +
54
- '<span class="wk-line"><b>' + kb(w.bytes) + "</b>" +
55
- (budget ? " of " + kb(budget) : " <small>(the size it may take was not recorded)</small>") + "</span>" +
56
- '<span class="wk-open">' + (open ? "hide the text" : "read it") + "</span>" +
70
+ '<button type="button" class="wk-sum" id="wake-toggle" aria-expanded="' + ui.wake + '">' +
71
+ '<span class="wk-line">Next session gets <b>' + (w.bytes / 1000).toFixed(1) + "</b>" +
72
+ (budget ? " of " + kb(budget) : " KB <small>(its ceiling was not recorded)</small>") + "</span>" +
73
+ '<span class="wk-open">' + (ui.wake ? "hide it" : "read it") + "</span>" +
57
74
  "</button>" +
58
75
  '<div class="wk-bar" role="img" aria-label="' + esc(parts.map((p) => p.label + " " + p.bytes + " bytes").join(", ")) + '">' + seg + "</div>" +
59
76
  '<div class="wk-legend">' + legend + "</div>" +
60
- '<div class="wk-full"' + (open ? "" : " hidden") + ">" + fullText(w) + "</div>" +
61
- '<p class="foot">When a session starts, a line with today\'s date goes on top, and in a folder with a handoff note, a pointer to it. It is composed without a model, at the end of each day.</p>';
62
- $("wake-toggle").addEventListener("click", () => { open = !open; paint(d); });
77
+ '<div class="wk-full" id="wake-full"' + (ui.wake ? "" : " hidden") + ">" + fullText(w) + "</div>";
78
+ $("wake-toggle").addEventListener("click", () => { ui.wake = !ui.wake; paint(); });
63
79
  }
64
80
 
65
81
  function fullText(w) {