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,17 +1,28 @@
1
- /* Every memory, with its words — newest first, a page at a time. The server
2
- filters and pages (`/api/memories/list`), so a store of twenty thousand rows
3
- sends fifty. Click a row to open the memory. */
1
+ /* Every memory, with its words — newest first (or oldest), a page at a time.
2
+ The server filters, sorts and pages (`/api/memories/list`), so a store of
3
+ twenty thousand rows sends fifty. The kinds are chips in the filter row, each
4
+ with its icon and count. Click a row to open the memory. */
4
5
  import { absenceLine } from "../../../shared/absence.js";
5
6
  import { api, fail } from "../../../shared/api.js";
6
- import { BANDCOL } from "../../../shared/colors.js";
7
7
  import { $, esc } from "../../../shared/dom.js";
8
+ import { kindMark, kindOf } from "../../../shared/memory-marks.js";
9
+ import { memRow, wireRows } from "../row.js";
8
10
  import { filters, onFilter, setFilter, toggle } from "../state.js";
11
+ import { q, wireTips } from "../../../shared/widgets/tips.js";
9
12
 
10
13
  const PAGE = 50;
11
- const KIND_LABEL = { self: "about me", person: "people", entity: "things", skill: "skills", place: "places", fact: "facts" };
14
+
15
+ /** What each kind is, how fast it fades and how easily it is corrected — the
16
+ * words that used to be the six kind cards, now behind the `?`. */
17
+ const KIND_TIP = "Kinds: about me (who I am — fades slowly, hardest to argue out of) · people (fade slowly, hard to correct) · " +
18
+ "things (fade fairly fast) · skills (fade slowest, easy to correct) · places (fade fairly fast, easy to correct) · " +
19
+ "facts (fade fastest, easiest to correct). ★ core is what has become part of who I am; journal is the chapters I wrote, kept as written.";
12
20
 
13
21
  export const markup = `
14
- <h2 id="mlist-h">Every memory <small id="mlist-sub"></small></h2>
22
+ <div class="mlist-head">
23
+ <h2 id="mlist-h">Every memory <small id="mlist-sub"></small></h2>
24
+ <div class="msort seggroup" id="msort" role="group" aria-label="order"></div>
25
+ </div>
15
26
  <div class="mfilters" id="mfilters"></div>
16
27
  <div class="card mlist" id="mlist"></div>
17
28
  <div class="mpager" id="mpager"></div>`;
@@ -19,14 +30,20 @@ export const markup = `
19
30
  let seq = 0;
20
31
 
21
32
  export function mount() {
33
+ wireRows($("mlist"));
22
34
  $("mfilters").addEventListener("click", (e) => {
23
35
  const b = e.target.closest("button[data-f]");
24
36
  if (!b) return;
25
37
  const f = b.dataset.f, v = b.dataset.v || null;
26
38
  if (f === "state") setFilter({ state: v });
27
- else if (f === "clear") setFilter({ kind: null, band: null });
39
+ else if (f === "clear") setFilter({ kind: null, core: false, journal: false, hold: null, feeling: null, feelingCore: null });
40
+ else if (f === "feeling") setFilter({ feeling: null, feelingCore: null });
28
41
  else toggle(f, v);
29
42
  });
43
+ $("msort").addEventListener("click", (e) => {
44
+ const b = e.target.closest("button[data-sort]");
45
+ if (b && b.dataset.sort !== filters.sort) setFilter({ sort: b.dataset.sort });
46
+ });
30
47
  $("mpager").addEventListener("click", (e) => {
31
48
  const b = e.target.closest("button[data-off]");
32
49
  if (!b || b.disabled) return;
@@ -38,67 +55,71 @@ export function mount() {
38
55
 
39
56
  export async function render() {
40
57
  const mine = ++seq;
41
- const qs = new URLSearchParams({ state: filters.state, offset: String(filters.offset), limit: String(PAGE) });
58
+ const qs = new URLSearchParams({ state: filters.state, sort: filters.sort, offset: String(filters.offset), limit: String(PAGE) });
42
59
  if (filters.kind) qs.set("kind", filters.kind);
43
- if (filters.band) qs.set("band", filters.band);
60
+ if (filters.core) qs.set("core", "1");
61
+ if (filters.journal) qs.set("journal", "1");
62
+ if (filters.hold) qs.set("hold", filters.hold);
63
+ if (filters.feeling) { qs.set("feeling", filters.feeling.word); qs.set("whose", filters.feeling.whose); }
64
+ else if (filters.feelingCore) qs.set("feelingCore", filters.feelingCore);
44
65
  let d;
45
66
  try { d = await api("/api/memories/list?" + qs.toString()); }
46
67
  catch (e) { return fail("The memory list", e); }
47
68
  if (mine !== seq) return; // a newer filter already asked
69
+ paintSort(d);
48
70
  paintFilters(d);
49
71
  paintRows(d);
50
72
  paintPager(d);
51
73
  }
52
74
 
53
- function chip(f, v, label, n, on, extraClass) {
75
+ function paintSort(d) {
76
+ $("msort").innerHTML = [["newest", "newest first"], ["oldest", "oldest first"]].map(([v, l]) =>
77
+ '<button type="button" class="fchip' + (d.sort === v ? " on" : "") + '" data-sort="' + v + '" aria-pressed="' +
78
+ (d.sort === v) + '">' + l + "</button>").join("");
79
+ }
80
+
81
+ function chip(f, v, inner, on, extraClass, title) {
54
82
  return '<button type="button" class="fchip' + (on ? " on" : "") + (extraClass ? " " + extraClass : "") +
55
- '" data-f="' + f + '"' + (v ? ' data-v="' + esc(v) + '"' : "") + ' aria-pressed="' + on + '">' +
56
- esc(label) + (n === undefined ? "" : ' <span class="fn">' + n + "</span>") + "</button>";
83
+ '" data-f="' + f + '"' + (v ? ' data-v="' + esc(v) + '"' : "") + ' aria-pressed="' + on + '"' +
84
+ (title ? ' title="' + esc(title) + '"' : "") + ">" + inner + "</button>";
57
85
  }
86
+ const count = (n) => ' <span class="fn">' + n + "</span>";
58
87
 
59
88
  function paintFilters(d) {
60
89
  const c = d.counts;
61
- const state = [["live", "live", c.live], ["archived", "archived", c.archived], ["all", "all", c.live + c.archived]]
62
- .map(([v, l, n]) => chip("state", v, l, n, d.state === v, "seg")).join("");
63
- const kinds = Object.keys(c.kinds).map((k) => chip("kind", k, KIND_LABEL[k] || k, c.kinds[k], d.kind === k,
64
- c.kinds[k] === 0 ? "zero" : "")).join("");
65
- const bands = Object.keys(c.bands).map((b) => chip("band", b, b, c.bands[b], d.band === b,
66
- c.bands[b] === 0 ? "zero" : "")).join("");
90
+ const state = [["live", c.live], ["archived", c.archived], ["all", c.live + c.archived]]
91
+ .map(([v, n]) => chip("state", v, esc(v) + count(n), d.state === v, "seg")).join("");
92
+ const kinds = Object.keys(c.kinds).map((k) => chip("kind", k, kindMark(k, false) + esc(kindOf(k).label) + count(c.kinds[k]),
93
+ d.kind === k, "kchip" + (c.kinds[k] === 0 ? " zero" : ""))).join("");
94
+ const special =
95
+ chip("core", null, '<span class="star">★</span>core' + count(c.core), d.core, c.core === 0 ? "zero" : "", "in the core: part of who I am") +
96
+ chip("journal", null, "journal" + count(c.journal), d.journal, c.journal === 0 ? "zero" : "", "journal chapters, kept as written");
97
+ const any = d.kind || d.core || d.journal || d.hold || d.feeling || d.feelingCore;
98
+ const feelingChip = d.feeling || d.feelingCore
99
+ ? chip("feeling", null, "feeling: " + esc(d.feeling ? d.feeling.word + " · " + (d.feeling.whose === "owner" ? "yours" : "mine") : d.feelingCore) +
100
+ ' <span class="fx" aria-hidden="true">✕</span>', true, "", "from “How it feels” — click to clear")
101
+ : "";
102
+ const holdChip = d.hold ? chip("hold", d.hold, '<span class="hdot ' + esc(d.hold) + '"></span>' + esc(d.hold) +
103
+ count(c.hold[d.hold]), true, "", "from the bar above — click to show all again") : "";
67
104
  $("mfilters").innerHTML =
68
105
  '<div class="fgroup seggroup" role="group" aria-label="live or archived">' + state + "</div>" +
69
- '<div class="fgroup" role="group" aria-label="kind">' + kinds + "</div>" +
70
- '<div class="fgroup" role="group" aria-label="band">' + bands +
71
- (d.kind || d.band ? chip("clear", null, "show every kind and band", undefined, false, "clear") : "") + "</div>";
106
+ '<div class="fgroup" role="group" aria-label="kind">' + kinds + special + holdChip + feelingChip +
107
+ (any ? chip("clear", null, "show all", false, "clear") : "") + q("kinds", KIND_TIP) + "</div>";
108
+ wireTips($("mfilters"));
72
109
  }
73
110
 
74
111
  function paintRows(d) {
75
112
  const from = d.total === 0 ? 0 : d.offset + 1;
76
113
  const to = Math.min(d.total, d.offset + d.rows.length);
77
- $("mlist-sub").textContent = "— newest first · " + (d.total === 0 ? "none match" : from + "–" + to + " of " + d.total);
114
+ $("mlist-sub").textContent = d.total === 0 ? "— none match" : "— " + from + "–" + to + " of " + d.total;
78
115
  if (d.rows.length === 0) {
116
+ const narrowed = d.kind || d.core || d.journal || d.hold || d.feeling || d.feelingCore;
79
117
  $("mlist").innerHTML = absenceLine(d.absent || "(none yet)",
80
- d.state === "archived" ? "nothing has been archived" + (d.kind || d.band ? " that matches these filters" : "")
118
+ d.state === "archived" ? "nothing has been archived" + (narrowed ? " that matches these filters" : "")
81
119
  : "no memory matches these filters");
82
120
  return;
83
121
  }
84
- $("mlist").innerHTML = d.rows.map((r) => {
85
- const words = r.confidential
86
- ? '<span class="withheld">' + esc(r.line) + "</span>"
87
- : (r.title ? "<b>" + esc(r.title) + "</b>" + (r.line && r.line !== r.title ? " " + esc(r.line) : "") : esc(r.line));
88
- const pct = Math.round(Math.max(0, Math.min(1, r.strength)) * 100);
89
- return '<div class="mrow click' + (r.archived ? " arch" : "") + '" role="button" tabindex="0" ' +
90
- "onclick=\"openMemory('" + esc(r.id) + "')\" onkeydown=\"if(event.key==='Enter')openMemory('" + esc(r.id) + "')\">" +
91
- '<div class="mwords">' + words +
92
- (r.archived ? '<div class="mwhy">archived: ' + esc(r.archived) + "</div>" : "") + "</div>" +
93
- '<div class="mmeta">' +
94
- '<span class="mkind">' + esc(KIND_LABEL[r.kind] || r.kind) + (r.schemaRole ? " · " + esc(r.schemaRole) : "") + "</span>" +
95
- '<span class="mstr" title="' + pct + '% strong"><span class="strack"><span style="width:' + pct + '%;background:' +
96
- (BANDCOL[r.band] || "var(--dim)") + '"></span></span><span class="spct">' + pct + "%</span></span>" +
97
- '<span class="mage">' + (r.livedDays === 0 ? "today" : r.livedDays + (r.livedDays === 1 ? " day" : " days")) + "</span>" +
98
- '<span class="mband"><span class="bdot" style="background:' + (BANDCOL[r.band] || "var(--dim)") + '"></span>' +
99
- esc(r.band) + "</span>" +
100
- "</div></div>";
101
- }).join("");
122
+ $("mlist").innerHTML = d.rows.map((r) => memRow(r)).join("");
102
123
  }
103
124
 
104
125
  function paintPager(d) {
@@ -107,8 +128,9 @@ function paintPager(d) {
107
128
  const next = d.offset + d.limit;
108
129
  const page = Math.floor(d.offset / d.limit) + 1;
109
130
  const pages = Math.ceil(d.total / d.limit);
131
+ const [back, fwd] = d.sort === "oldest" ? ["← older", "newer →"] : ["← newer", "older →"];
110
132
  $("mpager").innerHTML =
111
- '<button type="button" class="mbtn" data-off="' + prev + '"' + (d.offset === 0 ? " disabled" : "") + ">← newer</button>" +
133
+ '<button type="button" class="mbtn" data-off="' + prev + '"' + (d.offset === 0 ? " disabled" : "") + ">" + back + "</button>" +
112
134
  '<span class="mpage">page ' + page + " of " + pages + "</span>" +
113
- '<button type="button" class="mbtn" data-off="' + next + '"' + (next >= d.total ? " disabled" : "") + ">older →</button>";
135
+ '<button type="button" class="mbtn" data-off="' + next + '"' + (next >= d.total ? " disabled" : "") + ">" + fwd + "</button>";
114
136
  }
@@ -1,12 +1,12 @@
1
1
  /* Find a memory: search by its words (live, as you type) and ask a question
2
2
  (the console's own `counterparts ask`, through the actions seam). Both lists
3
- open the memory on click. */
3
+ use the list's row shape and open the memory on click; Ask's answers are
4
+ bright when they came clearly to mind and dim when they are a faint lead. */
4
5
  import { absenceLine } from "../../../shared/absence.js";
5
6
  import { act, resultHtml } from "../../../shared/actions.js";
6
7
  import { api, fail } from "../../../shared/api.js";
7
8
  import { $, esc } from "../../../shared/dom.js";
8
- import { said } from "../../../shared/format.js";
9
- import { BANDCOL } from "../../../shared/colors.js";
9
+ import { memRow, wireRows } from "../row.js";
10
10
 
11
11
  export const markup = `
12
12
  <div class="find">
@@ -17,7 +17,7 @@ export const markup = `
17
17
  placeholder="a word the memory would use…">
18
18
  <span id="qn"></span>
19
19
  </div>
20
- <div class="card rows" id="qout" hidden></div>
20
+ <div class="card mlist" id="qout" hidden></div>
21
21
  </div>
22
22
  <div class="find-col">
23
23
  <label class="find-lab" for="ask-q">Ask your memory a question</label>
@@ -30,18 +30,10 @@ export const markup = `
30
30
  </div>
31
31
  </div>`;
32
32
 
33
- /** One found memory as a row: words, then kind · band · strength. */
34
- function hitRow(id, title, text, confidential, kind, band, extra) {
35
- const words = confidential ? said(text, true)
36
- : (title ? "<b>" + esc(title) + "</b> " : "") + esc(text);
37
- return '<div class="r click" onclick="openMemory(\'' + esc(id) + '\')">' + words +
38
- '<div class="meta"><span class="k">' + esc(kind) + "</span>" +
39
- (band ? '<span><span class="bdot" style="background:' + (BANDCOL[band] || "var(--dim)") + '"></span>' + esc(band) + "</span>" : "") +
40
- (extra || "") + "</div></div>";
41
- }
42
-
43
33
  let qtimer = null;
44
34
  export function mount() {
35
+ wireRows($("qout"));
36
+ wireRows($("ask-out"));
45
37
  $("q").addEventListener("input", () => {
46
38
  clearTimeout(qtimer);
47
39
  qtimer = setTimeout(runSearch, 180);
@@ -61,12 +53,23 @@ async function runSearch() {
61
53
  $("qn").textContent = d.hits.length + (d.hits.length === 1 ? " match" : " matches");
62
54
  out.innerHTML = d.absent
63
55
  ? absenceLine(d.absent, "nothing I hold matches those words")
64
- : d.hits.map((h) => hitRow(h.id, null, h.text, h.confidential, h.kind, h.band,
65
- "<span>strength " + Math.round(h.strength * 100) + "%</span>")).join("");
56
+ : d.hits.map((h) => memRow({ ...h, text: h.shown, archived: null })).join("");
66
57
  }
67
58
 
68
- /** The tiers `ask` sorts answers into, in the words a person would use. */
59
+ /** The tiers `ask` sorts answers into, in the words a person would use, and
60
+ * the brightness each is drawn at. */
69
61
  const TIER = { vivid: "came clearly to mind", quiet: "came quietly", dim: "a faint lead" };
62
+ const TIER_LIT = { vivid: 5, quiet: 3, dim: 1 };
63
+
64
+ /** An answer's words as a row shows them: headings dropped, a date written at
65
+ * the front lifted off (display only — the memory is untouched). */
66
+ export function answerWords(body) {
67
+ const flat = String(body || "").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#")).join(" ");
68
+ const m = /^(\d{4}-\d{2}-\d{2})(?:[ \t]*[:,—–-][ \t]*|[ \t]+)(?=\S)/.exec(flat);
69
+ let rest = m ? flat.slice(m[0].length) : flat;
70
+ if (m) rest = rest.charAt(0).toUpperCase() + rest.slice(1);
71
+ return { date: m ? m[1] : null, text: rest.length > 320 ? rest.slice(0, 319) + "…" : rest };
72
+ }
70
73
 
71
74
  async function ask() {
72
75
  const q = $("ask-q").value.trim();
@@ -92,11 +95,11 @@ async function ask() {
92
95
  }
93
96
  out.innerHTML = '<div class="ask-head">What came to mind — ' + mems.length +
94
97
  (mems.length === 1 ? " memory" : " memories") + ", best first</div>" +
95
- '<div class="card rows">' + mems.map((m) => {
96
- const body = String(m.body || "");
97
- const first = body.split("\n").map((l) => l.trim()).find((l) => l && !l.startsWith("#")) || body;
98
- const text = first.length > 200 ? first.slice(0, 199) + "…" : first;
99
- return hitRow(m.id, m.title, text, false, m.journal ? "journal" : m.kind, null,
100
- '<span class="tier tier-' + esc(m.tier) + '">' + esc(TIER[m.tier] || m.tier) + "</span>");
98
+ '<div class="card mlist ask-list">' + mems.map((m) => {
99
+ const w = answerWords(m.body);
100
+ return memRow({
101
+ id: m.id, title: m.title, text: w.text, confidential: false, kind: m.kind, strength: m.strength,
102
+ date: w.date, dateFrom: w.date ? "text" : null, journal: !!m.journal, feelings: [], archived: null,
103
+ }, { lit: TIER_LIT[m.tier] || 3, tier: TIER[m.tier] || m.tier });
101
104
  }).join("") + "</div>";
102
105
  }
@@ -1,6 +1,11 @@
1
- /* What the memories page is filtered to, shared by the legend (a band chip),
2
- the kind cards and the list's own filter bar. One listener: the list. */
3
- export const filters = { state: "live", kind: null, band: null, offset: 0 };
1
+ /* What the memories page is filtered to, kept apart from the markup so a live refresh redraws and leaves every choice as it was.
2
+ One filter listener: the list. */
3
+ /** `hold`: firm / settling / fading, set from the "How firmly it's held" bar.
4
+ * `feeling` ({ word, whose }) and `feelingCore`: set from the "How it feels"
5
+ * radar — one or the other, never both. */
6
+ export const filters = {
7
+ state: "live", kind: null, core: false, journal: false, hold: null, feeling: null, feelingCore: null, sort: "newest", offset: 0,
8
+ };
4
9
 
5
10
  const listeners = [];
6
11
  export function onFilter(fn) { listeners.push(fn); }
@@ -13,9 +18,11 @@ export function setFilter(patch) {
13
18
  for (const fn of listeners) fn(filters);
14
19
  }
15
20
 
16
- /** A band or kind chip is a toggle: click it again to show everything. */
21
+ /** A kind chip (or a part of the hold bar) is a toggle: click it again to
22
+ * show everything. Core and journal chips are on/off. */
17
23
  export function toggle(key, value) {
18
- setFilter({ [key]: filters[key] === value ? null : value });
24
+ if (key === "core" || key === "journal") setFilter({ [key]: !filters[key] });
25
+ else setFilter({ [key]: filters[key] === value ? null : value });
19
26
  }
20
27
 
21
28
  /** Tell the page the store changed on purpose (a note, a removal). */
@@ -1,40 +1,81 @@
1
- /* The self tab (was "mind"): the self page on top with its history as a line of
2
- dots, what is settling into the core (and what is closest), the wake folded to
3
- one line, and the journal by day. One fetch (`/api/mind`). */
1
+ /* The self tab (was "mind"): the self page on the left with a side column
2
+ beside it (when it was rewritten and by whom, what the page writer did last,
3
+ the page's history as a line of dots, what the next session wakes up with);
4
+ under them, what is settling into the core and the journal as a strip of
5
+ days. One fetch (`/api/mind`).
6
+
7
+ LIVE. The pulse calls `refresh()` when the store moves. Only the panels whose
8
+ data changed are redrawn, each from `state.js`, so whatever was open — a
9
+ picked day, expanded chapters, an opened version, a pinned `?`, the wake's
10
+ text — is drawn open again, and the scroll position is put back. */
4
11
  import { api, fail } from "../../shared/api.js";
5
- import { $ } from "../../shared/dom.js";
12
+ import { $, esc } from "../../shared/dom.js";
13
+ import * as dreams from "./sections/dreams.js";
6
14
  import * as journal from "./sections/journal.js";
7
15
  import * as page from "./sections/page.js";
8
16
  import * as settling from "./sections/settling.js";
9
17
  import * as wake from "./sections/wake.js";
18
+ import { q, wireTips } from "../../shared/widgets/tips.js";
10
19
 
11
20
  const markup = `
12
- <p class="lede" id="mind-opening"></p>${page.markup}
21
+ <h2 class="sp-title" id="mind-opening"></h2>
22
+ <div class="self-top">
23
+ <div class="self-main">${page.mainMarkup}
24
+ </div>
25
+ <aside class="self-side">${page.sideMarkup}${wake.markup}
26
+ </aside>
27
+ </div>
13
28
  <div class="cols self-cols">
14
29
  <div>${settling.markup}
15
30
  </div>
16
- <div>${wake.markup}
31
+ <div>${journal.markup}${dreams.markup}
17
32
  </div>
18
- </div>${journal.markup}
33
+ </div>
19
34
  `;
20
35
 
21
- async function render() {
36
+ /** Each panel, the slice of the view it draws from, and how it draws. */
37
+ const PANELS = [
38
+ { name: "opening", slice: (d) => [d.opening], paint: paintOpening },
39
+ { name: "page", slice: (d) => [d.page, d.pageAbsent], paint: page.paintPage },
40
+ { name: "meta", slice: (d) => [d.page, d.writer], paint: page.paintMeta },
41
+ { name: "history", slice: (d) => [d.pageHistory], paint: page.paintHistory },
42
+ { name: "wake", slice: (d) => [d.wake, d.wakeParts, d.wakeBudget], paint: wake.paint },
43
+ { name: "settling", slice: (d) => [d.settling, d.stories], paint: settling.paint },
44
+ { name: "journal", slice: (d) => [d.journal, d.journalAbsent, d.journalMore], paint: journal.paint },
45
+ { name: "dreams", slice: (d) => [d.dreams, d.dreamsAbsent], paint: dreams.paint },
46
+ ];
47
+
48
+ /** What each panel was last drawn from. */
49
+ const drawn = {};
50
+
51
+ function paintOpening(d) {
52
+ $("mind-opening").innerHTML = esc(d.opening) + " " +
53
+ q("opening", "In my own words; the next session opens with this. Under it: how it has changed, what is slowly settling into the core, what the next session will be handed, and the journal.");
54
+ wireTips($("mind-opening"));
55
+ }
56
+
57
+ /** Draw every panel whose data moved (all of them when `force`). */
58
+ async function draw(force) {
22
59
  let d;
23
- try { d = await api("/api/mind"); } catch (e) { return fail("The self page", e); }
24
- $("mind-opening").textContent = d.opening;
25
- page.paint(d);
26
- settling.paint(d);
27
- wake.paint(d);
28
- journal.paint(d);
60
+ try { d = await api("/api/mind"); } catch (e) { if (force) fail("The self page", e); return; }
61
+ const x = scrollX, y = scrollY;
62
+ for (const p of PANELS) {
63
+ const key = JSON.stringify(p.slice(d));
64
+ if (!force && drawn[p.name] === key) continue;
65
+ p.paint(d);
66
+ drawn[p.name] = key;
67
+ }
68
+ if (scrollX !== x || scrollY !== y) scrollTo(x, y);
29
69
  }
30
70
 
31
71
  export default {
32
72
  name: "self",
33
73
  mount(section) {
34
74
  section.innerHTML = markup;
35
- wake.mount(render);
75
+ wake.mount(() => draw(false));
36
76
  },
37
- render,
77
+ render: () => draw(true),
78
+ refresh: () => draw(false),
38
79
  /** `#self/settling`, `#self/journal`: open the tab at that section. */
39
80
  route({ anchor }) {
40
81
  const h = anchor && $("self-" + anchor + "-h");
@@ -0,0 +1,76 @@
1
+ /* The dream journal (2026-09-26): each dream, newest first — its date, its
2
+ state, its title — and, opened, the journal entry in the dream's own words
3
+ and every change it made, each naming the memories it touched (clickable).
4
+ A change the owner undid is struck through. The journal is a dream, kept
5
+ apart from the memories: nothing here is something that happened. */
6
+ import { absenceLine } from "../../../shared/absence.js";
7
+ import { $, esc } from "../../../shared/dom.js";
8
+ import { said } from "../../../shared/format.js";
9
+ import { renderMarkdown } from "../markdown.js";
10
+ import { q, wireTips } from "../../../shared/widgets/tips.js";
11
+
12
+ export const markup = `
13
+ <h2 id="self-dreams-h">Dreams <span id="self-dreams-q"></span></h2>
14
+ <div id="self-dreams"></div>`;
15
+
16
+ let last = null;
17
+ /** Which dreams are open, by id — kept across redraws. */
18
+ const openIds = new Set();
19
+
20
+ const STATE = { begun: "dreaming", journaled: "woke", undone: "undone" };
21
+
22
+ function memoryRef(m) {
23
+ return '<span class="dr-mem' + (m.confidential ? " withheld" : "") + '" role="button" tabindex="0" onclick="openMemory(\'' +
24
+ esc(m.id) + '\')" onkeydown="if(event.key===\'Enter\')openMemory(\'' + esc(m.id) + '\')">' + said(m.text, m.confidential) + "</span>";
25
+ }
26
+
27
+ function change(c) {
28
+ return '<li class="dr-change' + (c.undone ? " undone" : "") + '">' +
29
+ '<span class="dr-said">' + esc(c.said) + (c.undone ? " · undone" : "") + "</span>" +
30
+ (c.memories.length > 0 ? '<span class="dr-mems">' + c.memories.map(memoryRef).join(" · ") + "</span>" : "") +
31
+ "</li>";
32
+ }
33
+
34
+ function countsLine(counts) {
35
+ const parts = Object.entries(counts).map(([k, n]) => n + " " + k);
36
+ return parts.length === 0 ? "no changes" : parts.join(", ");
37
+ }
38
+
39
+ export function paint(d) {
40
+ if (d) last = d;
41
+ d = last;
42
+ $("self-dreams-q").innerHTML = q("dreams", "Once a day, with the owner's yes, I dream for a few minutes over what was lived since the last dream: merging near-copies, linking what belongs together, replaying what matters, writing down a pattern. Every change can be undone as a whole (counterparts dream --undo <id>). A dream is never a memory of something that happened.");
43
+ wireTips($("self-dreams-q"));
44
+ const box = $("self-dreams");
45
+ if (d.dreamsAbsent) {
46
+ box.innerHTML = absenceLine(d.dreamsAbsent, "no dream yet");
47
+ return;
48
+ }
49
+ const v = d.dreams;
50
+ box.innerHTML = '<div class="card pad dr-list">' + v.dreams.map((x) => {
51
+ const open = openIds.has(x.id);
52
+ return '<div class="dr' + (open ? " open" : "") + (x.state === "undone" ? " undone" : "") + '">' +
53
+ '<button type="button" class="dr-top" data-id="' + esc(x.id) + '" aria-expanded="' + open + '">' +
54
+ '<span class="dr-date">' + esc(x.date || "day " + x.day) + "</span>" +
55
+ '<span class="dr-title">' + esc(x.title || "(no journal yet)") + "</span>" +
56
+ '<span class="chip">' + esc(STATE[x.state] || x.state) + "</span>" +
57
+ '<span class="dr-counts">' + esc(countsLine(x.counts)) + "</span>" +
58
+ "</button>" +
59
+ (open
60
+ ? '<div class="dr-body">' +
61
+ (x.journal ? '<div class="dr-journal">' + renderMarkdown(x.journal) + "</div>" : '<p class="foot">No journal written.</p>') +
62
+ (x.changes.length > 0 ? '<ol class="dr-changes">' + x.changes.map(change).join("") + "</ol>" : "") +
63
+ '<p class="foot">Undo it all: <code>counterparts dream --undo ' + esc(x.id) + "</code></p>" +
64
+ "</div>"
65
+ : "") +
66
+ "</div>";
67
+ }).join("") +
68
+ (v.more > 0 ? '<p class="foot">…and older dreams: <code>counterparts dream --list</code></p>' : "") +
69
+ "</div>";
70
+ box.querySelectorAll(".dr-top").forEach((b) => b.addEventListener("click", () => {
71
+ const id = b.dataset.id;
72
+ if (openIds.has(id)) openIds.delete(id);
73
+ else openIds.add(id);
74
+ paint();
75
+ }));
76
+ }
@@ -1,32 +1,88 @@
1
- /* The journal: chapters grouped by the day they were written, newest first,
2
- each with its title, the model that wrote it (when recorded) and its first
3
- line. Click one to read it in full; the whole entry opens as a record. */
1
+ /* The journal as a strip of days: each day its date, its lived day and a dot
2
+ per chapter, newest first. It opens on the newest day; picking a day lists
3
+ that day's chapters as titles with the model that wrote each (when
4
+ recorded), and picking a title opens its text in place. The whole entry
5
+ still opens as a record. */
4
6
  import { absenceLine } from "../../../shared/absence.js";
5
7
  import { $, esc } from "../../../shared/dom.js";
6
- import { said } from "../../../shared/format.js";
7
8
  import { renderMarkdown } from "../markdown.js";
9
+ import { chapterKey, ui } from "../state.js";
10
+ import { q, wireTips } from "../../../shared/widgets/tips.js";
8
11
 
9
12
  export const markup = `
10
- <h2 id="self-journal-h">Journal <small>— a chapter at the end of a session; these do not fade</small></h2>
13
+ <h2 id="self-journal-h">Journal <span id="self-journal-q"></span></h2>
11
14
  <div id="self-journal"></div>`;
12
15
 
16
+ let last = null;
17
+
18
+ /** "Fri 10 Jul 2026" → "10 Jul"; anything else as it came. */
19
+ export function dayLabel(day) {
20
+ if (!day.date) return "day " + day.day;
21
+ const m = /^\w{3},?\s+(\d{1,2})\s+(\w{3})\w*\s+\d{4}$/.exec(day.date.trim());
22
+ return m ? m[1] + " " + m[2] : day.date;
23
+ }
24
+
13
25
  export function paint(d) {
26
+ if (d) last = d;
27
+ d = last;
28
+ $("self-journal-q").innerHTML = q("journal", "A chapter is written at the end of a session; these do not fade.");
29
+ wireTips($("self-journal-q"));
30
+ const box = $("self-journal");
14
31
  if (d.journalAbsent) {
15
- $("self-journal").innerHTML = absenceLine(d.journalAbsent, "no chapter has been written yet");
32
+ box.innerHTML = absenceLine(d.journalAbsent, "no chapter has been written yet");
16
33
  return;
17
34
  }
18
- $("self-journal").innerHTML = d.journal.map((day) =>
19
- '<div class="jd"><div class="jd-h"><b>' + esc(day.date || "lived day " + day.day) + "</b>" +
20
- (day.date ? "<span>lived day " + day.day + "</span>" : "") + "</div>" +
21
- day.chapters.map((c) =>
22
- '<details class="jc"><summary>' +
23
- '<span class="jc-top"><span class="jc-title">' + esc(c.title) + "</span>" +
24
- (c.model ? '<span class="chip model" title="the model that wrote it">' + esc(c.model) + "</span>" : "") + "</span>" +
25
- '<span class="jc-first">' + said(c.first, c.confidential) + "</span>" +
26
- "</summary>" +
27
- '<div class="jc-body">' + (c.text === null ? '<p class="foot">This chapter is withheld here, as it is everywhere.</p>' : renderMarkdown(c.text)) +
28
- '<button type="button" class="act-btn jc-open" onclick="openMemory(\'' + c.id + '\')">open the whole entry</button></div>' +
29
- "</details>").join("") +
30
- "</div>").join("") +
35
+ const days = d.journal;
36
+ // A picked day that is no longer sent falls back to the newest.
37
+ const picked = days.find((x) => x.day === ui.day) || days[0];
38
+ const strip = box.querySelector(".jd-strip");
39
+ const scrollLeft = strip ? strip.scrollLeft : 0;
40
+
41
+ const cells = days.map((x) => {
42
+ const on = x === picked;
43
+ const n = x.chapters.length;
44
+ const marks = n <= 5
45
+ ? '<span class="jd-dots" aria-hidden="true">' + '<i></i>'.repeat(n) + "</span>"
46
+ : '<span class="jd-n" aria-hidden="true">' + n + "</span>";
47
+ return '<button type="button" class="jd-day' + (on ? " on" : "") + '" data-day="' + x.day + '" aria-pressed="' + on + '"' +
48
+ ' aria-label="' + esc((x.date || "lived day " + x.day) + ", " + n + (n === 1 ? " chapter" : " chapters")) + '">' +
49
+ '<b>' + esc(dayLabel(x)) + "</b>" +
50
+ (x.date ? '<span class="jd-lived">day ' + x.day + "</span>" : "") + marks + "</button>";
51
+ }).join("");
52
+
53
+ const chapters = picked.chapters.map((c) => {
54
+ const key = chapterKey(c);
55
+ const open = ui.chapters.has(key);
56
+ return '<div class="jc' + (open ? " open" : "") + '">' +
57
+ '<button type="button" class="jc-top" data-key="' + esc(key) + '" aria-expanded="' + open + '">' +
58
+ '<span class="jc-title">' + esc(c.title) + "</span>" +
59
+ (c.model ? '<span class="chip model" title="the model that wrote it">' + esc(c.model) + "</span>" : "") +
60
+ "</button>" +
61
+ (open
62
+ ? '<div class="jc-body">' + (c.text === null ? '<p class="foot">This chapter is withheld here, as it is everywhere.</p>' : renderMarkdown(c.text)) +
63
+ '<button type="button" class="act-btn jc-open" onclick="openMemory(\'' + c.id + '\')">open the whole entry</button></div>'
64
+ : "") +
65
+ "</div>";
66
+ }).join("");
67
+
68
+ box.innerHTML =
69
+ '<div class="jd-strip" role="group" aria-label="Days">' + cells + "</div>" +
70
+ '<div class="jd-head"><b>' + esc(picked.date || "lived day " + picked.day) + "</b>" +
71
+ (picked.date ? "<span>lived day " + picked.day + "</span>" : "") + "</div>" +
72
+ '<div class="jd-list">' + chapters + "</div>" +
31
73
  (d.journalMore > 0 ? '<p class="foot">' + d.journalMore + " older chapters are not shown here.</p>" : "");
74
+ box.querySelector(".jd-strip").scrollLeft = scrollLeft;
75
+
76
+ box.querySelectorAll(".jd-day").forEach((b) => b.addEventListener("click", () => {
77
+ ui.day = Number(b.dataset.day);
78
+ paint();
79
+ }));
80
+ box.querySelectorAll(".jc-top").forEach((b) => b.addEventListener("click", () => {
81
+ const key = b.dataset.key;
82
+ if (ui.chapters.has(key)) ui.chapters.delete(key); else ui.chapters.add(key);
83
+ // Reading a day's chapter pins that day: a new day landing on a refresh
84
+ // must not move the strip out from under an open chapter.
85
+ if (ui.day === null) ui.day = picked.day;
86
+ paint();
87
+ }));
32
88
  }