counterparts 0.3.12 → 0.3.13

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 (116) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/docs/module-map.md +1 -1
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/CONTRACT.md +36 -10
  5. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  6. package/src/adapters/claude-code/NOTES.md +131 -0
  7. package/src/adapters/claude-code/bin/hook.ts +35 -2
  8. package/src/adapters/claude-code/doctor.ts +155 -21
  9. package/src/adapters/claude-code/hooks.ts +49 -7
  10. package/src/adapters/claude-code/index.ts +11 -0
  11. package/src/adapters/claude-code/night-run.ts +133 -12
  12. package/src/adapters/claude-code/transcript.ts +268 -1
  13. package/src/adapters/cli/CONTRACT.md +5 -0
  14. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  15. package/src/adapters/cli/NOTES.md +111 -0
  16. package/src/adapters/cli/commands.ts +65 -14
  17. package/src/adapters/cli/dream-core.ts +57 -42
  18. package/src/adapters/cli/export.ts +320 -21
  19. package/src/adapters/cli/index.ts +1 -0
  20. package/src/adapters/cli/install.ts +39 -7
  21. package/src/adapters/cli/mechanisms.ts +7 -1
  22. package/src/adapters/cli/uninstall.ts +13 -5
  23. package/src/adapters/cli/wire.ts +189 -63
  24. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  25. package/src/adapters/dashboard/NOTES.md +79 -0
  26. package/src/adapters/dashboard/registries.ts +10 -2
  27. package/src/adapters/dashboard/web/README.md +19 -14
  28. package/src/adapters/dashboard/web/actions.ts +23 -1
  29. package/src/adapters/dashboard/web/flow.ts +4 -1
  30. package/src/adapters/dashboard/web/lanes.ts +3 -0
  31. package/src/adapters/dashboard/web/narrate.ts +30 -2
  32. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  33. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  34. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  35. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  36. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  37. package/src/adapters/dashboard/web/server.ts +0 -5
  38. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  39. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  40. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  41. package/src/adapters/dashboard/web/views/health.ts +1 -1
  42. package/src/adapters/dashboard/web/views/search.ts +4 -45
  43. package/src/adapters/dashboard/web/views.ts +2 -2
  44. package/src/adapters/fired.ts +410 -25
  45. package/src/adapters/host-wiring.ts +300 -0
  46. package/src/adapters/lifecycle.ts +14 -0
  47. package/src/adapters/log/index.ts +2 -0
  48. package/src/adapters/mcp/CONTRACT.md +33 -3
  49. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  50. package/src/adapters/mcp/NOTES.md +136 -0
  51. package/src/adapters/mcp/bin/serve.ts +30 -0
  52. package/src/adapters/mcp/facts.ts +13 -1
  53. package/src/adapters/mcp/meaning.ts +208 -13
  54. package/src/adapters/mcp/server.ts +87 -15
  55. package/src/adapters/mcp/stdio.ts +3 -1
  56. package/src/adapters/mcp/stood-down.ts +51 -0
  57. package/src/adapters/mcp/tools.ts +27 -7
  58. package/src/adapters/plugin-run.sh +133 -0
  59. package/src/adapters/plugin.ts +329 -0
  60. package/src/core/associate/CONTRACT.md +2 -1
  61. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  62. package/src/core/associate/NOTES.md +45 -0
  63. package/src/core/briefing.ts +12 -3
  64. package/src/core/contradictions.ts +184 -0
  65. package/src/core/counterpart.ts +451 -18
  66. package/src/core/dream/CONTRACT.md +5 -2
  67. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  68. package/src/core/dream/NOTES.md +21 -0
  69. package/src/core/dream/index.ts +33 -1
  70. package/src/core/dream/reflect.ts +20 -5
  71. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  72. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  73. package/src/core/fit/NOTES.md +5 -2
  74. package/src/core/fit/index.ts +4 -1
  75. package/src/core/handoff/CONTRACT.md +37 -2
  76. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  77. package/src/core/handoff/NOTES.md +66 -0
  78. package/src/core/handoff/index.ts +214 -12
  79. package/src/core/mint.ts +8 -2
  80. package/src/core/physics/CONTRACT.md +11 -1
  81. package/src/core/physics/NOTES.md +30 -0
  82. package/src/core/physics/index.ts +26 -4
  83. package/src/core/prospective/CONTRACT.md +45 -6
  84. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  85. package/src/core/prospective/NOTES.md +138 -0
  86. package/src/core/prospective/derive.ts +33 -5
  87. package/src/core/prospective/index.ts +90 -5
  88. package/src/core/prospective/windows.ts +72 -1
  89. package/src/core/recall/CONTRACT.md +6 -2
  90. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  91. package/src/core/recall/NOTES.md +57 -1
  92. package/src/core/recall/probe.ts +58 -0
  93. package/src/core/recall/session.ts +27 -3
  94. package/src/core/recall/time-ask.ts +116 -18
  95. package/src/core/remember/CONTRACT.md +4 -1
  96. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  97. package/src/core/remember/proposals.ts +38 -5
  98. package/src/core/revision.ts +5 -0
  99. package/src/core/schemas/CONTRACT.md +13 -1
  100. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  101. package/src/core/schemas/NOTES.md +127 -0
  102. package/src/core/schemas/types.ts +2 -0
  103. package/src/core/self/CONTRACT.md +15 -4
  104. package/src/core/self/INTERFACE-GAPS.md +7 -2
  105. package/src/core/self/NOTES.md +49 -0
  106. package/src/core/self/briefing.ts +12 -2
  107. package/src/core/self/index.ts +82 -8
  108. package/src/core/self/page.ts +88 -0
  109. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  110. package/src/core/sleep/NOTES.md +11 -0
  111. package/src/core/sleep/prune.ts +6 -2
  112. package/src/core/store/NOTES.md +14 -0
  113. package/src/core/store/index.ts +107 -0
  114. package/src/core/time.ts +152 -0
  115. package/tools/install-loop/run.sh +48 -12
  116. package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
@@ -1,17 +1,33 @@
1
1
  /* Find a memory: ONE box (round 4, 2026-09-28) with a switch beside it
2
- (2026-09-30): "by word" finds memories by their words as you type
3
- (`/api/search`), Enter only runs it at once; "by meaning" asks, on Enter (the
4
- console's own `counterparts ask`, through the actions seam). The switch never
5
- flips by itself. Either way the answers take the list's place — never a
6
- second list — and the "×" gives the list back.
7
- How close an answer came is said plainly: strong match, match, weak match.
8
- Ask is the owner talking to me, so the server turns the question into my
9
- voice before it searches (`web/ask-voice.ts`); that is not shown. */
2
+ (2026-09-30). Three ways since 2026-10-09, when recall took a mode (0.3.12):
3
+
4
+ - "by word" finds memories by their words as you type (`/api/search`);
5
+ Enter only runs it at once.
6
+ - "facts" asks on Enter, in facts mode: every memory that answers the
7
+ question, counted and paged, best first — each with who said it, when it
8
+ happened or was learned, and whether it still holds.
9
+ - "by meaning" asks on Enter, in meaning mode: what a person, a project or
10
+ a feeling has been over time — the journal chapters that hold it, in time
11
+ order, with their moments and the feelings recorded in them.
12
+
13
+ Both asks are the console's own `counterparts ask --json` (with `--mode`),
14
+ through the actions seam, and the page draws the answer the command
15
+ returned: no label here stands for a field the answer does not carry. The
16
+ drawing is pure (`factsRows`, `meaningRows`, …) and the tests feed it real
17
+ answers from a temp store (`test/dashboard-ask-answers.test.ts`) — the page
18
+ read the old answer's shape for a release after it changed, and nothing
19
+ failed, because its tests were fed by hand.
20
+
21
+ The switch never flips by itself. Either way the answers take the list's
22
+ place — never a second list — and the "×" gives the list back. Ask is the
23
+ owner talking to me, so the server turns the question into my voice before
24
+ it searches (`web/ask-voice.ts`); that is not shown. */
10
25
  import { absenceLine } from "../../../shared/absence.js";
11
26
  import { act, resultHtml } from "../../../shared/actions.js";
12
27
  import { api, fail } from "../../../shared/api.js";
28
+ import { dateOr } from "../../../shared/dates.js";
13
29
  import { $, esc } from "../../../shared/dom.js";
14
- import { foldChapters, fromWords } from "../fold.js";
30
+ import { withIdMarks } from "../../../shared/memory-marks.js";
15
31
  import { memRow, searchWords } from "../row.js";
16
32
  import { find, onFilter, setFilter } from "../state.js";
17
33
 
@@ -30,11 +46,14 @@ export const markup = `
30
46
 
31
47
  let qtimer = null;
32
48
  let seq = 0;
49
+ /** The question and mode the answer on the page is for, so its pager asks the same again. */
50
+ let asked = null;
33
51
 
34
- /** The two ways to find, as the switch says them, and what the box says for each. */
52
+ /** The three ways to find, as the switch says them, and what the box says for each. */
35
53
  export const MODES = {
36
54
  word: { label: "by word", placeholder: "a word or two — the answers come as you type" },
37
- meaning: { label: "by meaning", placeholder: "ask a question, then press Enter" },
55
+ facts: { label: "facts", placeholder: "ask a question, then press Enter — every memory that answers it" },
56
+ meaning: { label: "by meaning", placeholder: "who or what, over time — ask, then press Enter" },
38
57
  };
39
58
 
40
59
  /** The switch and the box's placeholder, as `find.mode` says. */
@@ -57,7 +76,7 @@ export function mount() {
57
76
  if (e.key === "Enter") {
58
77
  e.preventDefault();
59
78
  clearTimeout(qtimer);
60
- if (find.mode === "word") runSearch(); else ask();
79
+ if (find.mode === "word") runSearch(); else ask(box.value.trim(), find.mode, 1);
61
80
  } else if (e.key === "Escape" && box.value) { e.preventDefault(); clear(); }
62
81
  });
63
82
  $("q-x").addEventListener("click", () => { clear(); box.focus(); });
@@ -70,7 +89,7 @@ export function mount() {
70
89
  const words = box.value;
71
90
  if (!words.trim()) return;
72
91
  if (find.mode === "word") { runSearch(); return; }
73
- // By meaning waits for Enter: the list comes back, the question stays.
92
+ // An ask waits for Enter: the list comes back, the question stays.
74
93
  seq++;
75
94
  if (find.on) setFilter({});
76
95
  box.value = words;
@@ -78,6 +97,14 @@ export function mount() {
78
97
  $("find-head").hidden = false;
79
98
  $("find-head").innerHTML = '<span class="find-hint">press Enter to ask</span>';
80
99
  });
100
+ // An answer's pages: the same question, in the same mode, again. (The
101
+ // list's own pager buttons carry `data-off`; these carry `data-ask-page`.)
102
+ $("mpager").addEventListener("click", (e) => {
103
+ const b = e.target.closest("button[data-ask-page]");
104
+ if (!b || b.disabled || !asked || !find.on) return;
105
+ ask(asked.q, asked.mode, Number(b.dataset.askPage));
106
+ $("q").scrollIntoView({ block: "start", behavior: "smooth" });
107
+ });
81
108
  // A filter chosen anywhere else (a chip, the chart, a link from Home) ends
82
109
  // the find: the box empties so it never shows words the list isn't answering.
83
110
  onFilter(() => {
@@ -127,7 +154,7 @@ async function runSearch() {
127
154
  const close = d.close || [];
128
155
  takeList(esc(findHead(d.hits.length, d.total, close.length)));
129
156
  $("mlist").innerHTML = d.absent
130
- ? absenceLine(d.absent, "nothing I hold uses those words — try finding it by meaning")
157
+ ? absenceLine(d.absent, "nothing I hold uses those words — try asking for the facts")
131
158
  : d.hits.map((h) => memRow({ ...h, text: h.shown, archived: null }, { mark: searchWords(q) })).join("") +
132
159
  (close.length > 0
133
160
  ? '<div class="mclose-h">Close matches <span>· a letter or two off</span></div>' +
@@ -150,61 +177,253 @@ export function questionWords(q) {
150
177
  return searchWords(q).filter((w) => w.length >= 4 && !QUESTION_WORDS.has(w));
151
178
  }
152
179
 
153
- /** The tiers `ask` sorts answers into, in plain words. */
154
- export const TIER = { vivid: "strong match", quiet: "match", dim: "weak match" };
155
-
156
- /** An answer's words as a row shows them: headings dropped, a date written at
157
- * the front lifted off (display only — the memory is untouched). */
158
- export function answerWords(body) {
159
- const flat = String(body || "").split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("#")).join(" ");
160
- const m = /^(\d{4}-\d{2}-\d{2})(?:[ \t]*[:,—–-][ \t]*|[ \t]+)(?=\S)/.exec(flat);
161
- let rest = m ? flat.slice(m[0].length) : flat;
162
- if (m) rest = rest.charAt(0).toUpperCase() + rest.slice(1);
163
- return { date: m ? m[1] : null, text: rest.length > 320 ? rest.slice(0, 319) + "…" : rest };
164
- }
165
-
166
- async function ask() {
167
- const q = $("q").value.trim();
180
+ /** Ask the console, in `mode`, and put its answer where the list is. */
181
+ async function ask(q, mode, page) {
168
182
  if (!q) return;
169
183
  const mine = ++seq;
184
+ asked = { q, mode };
170
185
  takeList("thinking…");
171
186
  $("mlist").innerHTML = "";
172
- const r = await act("ask", { question: q, json: true });
187
+ const r = await act("ask", { question: q, json: true, mode, ...(page > 1 ? { page } : {}) });
173
188
  if (mine !== seq) return;
174
189
  let result = null;
175
190
  if (r && r.ok && Array.isArray(r.out)) {
176
191
  try { result = JSON.parse(r.out.join("\n")); } catch (e) { result = null; }
177
192
  }
178
- if (!result) { takeList("I couldn't ask that"); $("mlist").innerHTML = resultHtml(r); return; }
179
- const raw = Array.isArray(result.memories) ? result.memories : [];
180
- // A chapter and the memory drawn from it are one answer (`fold.js`). The
181
- // links are a read; without them the answers show as they came.
182
- let links = {};
183
- if (raw.length > 0) {
184
- try { links = (await api("/api/chapters?ids=" + encodeURIComponent(raw.map((m) => m.id).join(",")))).links || {}; }
185
- catch (e) { links = {}; }
193
+ // An answer in another mode than the one asked is not drawn as if it were.
194
+ if (!result || result.mode !== mode) { takeList("I couldn't ask that"); $("mlist").innerHTML = resultHtml(r); return; }
195
+ const meaning = mode === "meaning";
196
+ takeList(meaning ? meaningHead(result) : factsHead(result));
197
+ $("mlist").innerHTML = meaning ? meaningRows(result) : factsRows(result, q);
198
+ $("mpager").innerHTML = askPager(result);
199
+ }
200
+
201
+ // ── the answers, drawn (pure: no DOM, so `bun test` draws real ones) ─────────
202
+
203
+ /** Results on one page of a facts answer: `mcp/facts.ts#FACTS_PAGE_SIZE` (a test holds the two equal). */
204
+ export const FACTS_PAGE = 10;
205
+
206
+ /** Who said it (`FactItem.saidBy`), in my voice — the console's words (`facts.ts`). */
207
+ export const SAID = { owner: "you said", self: "I said", inferred: "inferred" };
208
+
209
+ const plural = (n, one, many) => n + " " + (n === 1 ? one : many || one + "s");
210
+
211
+ /** Why words alone answered, when they did (`facts.ts#channelWords`); null when meaning searched too. */
212
+ export function channelWords(semantic) {
213
+ if (semantic === "embedder-off") return "by words only — recall by meaning is off";
214
+ if (semantic === "embed-failed") return "by words only — the question could not be embedded";
215
+ return null;
216
+ }
217
+
218
+ /** The notes under a head line, quieter, or nothing. */
219
+ const noteLine = (notes) => (notes.length > 0 ? '<span class="find-note">' + esc(notes.join(" · ")) + "</span>" : "");
220
+
221
+ /** The open ends of a window ("before 7/22", "after 7/22"): `recall/time-ask.ts`'s
222
+ * `OPEN_START` and `OPEN_END` (2026-10-09). */
223
+ const OPEN_START = "0001-01-01";
224
+ const OPEN_END = "9999-12-31";
225
+
226
+ /** A window of days: "Sep 21st – Sep 27th", one day, "through Jul 21st" or "Jul 23rd onward". */
227
+ function span(w) {
228
+ if (!w) return "";
229
+ if (w.from === OPEN_START) return "through " + dateOr(w.to);
230
+ if (w.to === OPEN_END) return dateOr(w.from) + " onward";
231
+ return w.from === w.to ? dateOr(w.from) : dateOr(w.from) + " – " + dateOr(w.to);
232
+ }
233
+
234
+ /** The time a facts question named (`FactsResult.time`), in a line; "" when it named none. */
235
+ export function timeWords(t) {
236
+ if (!t) return "";
237
+ const outside = t.outside > 0 ? ", " + t.outside + " more outside it" : "";
238
+ if (t.anchor && t.anchor.date === null) {
239
+ return t.anchor.kind === "event"
240
+ ? "nothing I hold names “" + t.anchor.phrase + "”, so time left nothing out"
241
+ : "no earlier session found, so time left nothing out";
186
242
  }
187
- if (mine !== seq) return;
188
- const mems = foldChapters(raw, links);
189
- if (mems.length === 0) {
190
- takeList("nothing came to mind");
191
- $("mlist").innerHTML = '<div class="empty">' +
192
- (result.considered === 0
193
- ? "Nothing I hold shared a word with the question."
194
- : esc(String(result.considered)) + " memories were weighed and none was close enough.") +
195
- " Try the words the memory itself would use.</div>";
196
- return;
243
+ if (t.anchor) {
244
+ return (t.anchor.kind === "event" ? t.anchor.phrase : t.cue) + " → " + dateOr(t.anchor.date) +
245
+ (t.anchor.kind === "event" && t.window ? " (" + span(t.window) + ")" : "") + outside;
197
246
  }
198
- takeList(mems.length + (mems.length === 1 ? " memory came to mind" : " memories came to mind") + ", best match first");
199
- $("mlist").innerHTML = mems.map((m) => {
200
- const w = answerWords(m.body);
201
- return memRow({
202
- id: m.id, title: m.title, text: w.text, confidential: false, kind: m.kind,
203
- date: w.date, dateFrom: w.date ? "text" : null, journal: false, core: false, feelings: [], archived: null,
204
- }, {
205
- tier: TIER[m.tier] || m.tier,
206
- from: m.from ? { id: m.from.episodeId, words: fromWords(m.from) } : null,
207
- mark: questionWords(q),
208
- });
209
- }).join("");
247
+ return t.cue + " → " + span(t.said) + (t.stretch > 0 ? ", give or take " + plural(t.stretch, "day") : "") + outside;
248
+ }
249
+
250
+ /** A facts answer's head: how many answer it, then the quieter notes. Markup. */
251
+ export function factsHead(r) {
252
+ const lead = r.matched === 0
253
+ ? (r.fadedTotal > 0 ? "only faded memories answer it" : "nothing answers it")
254
+ : plural(r.matched, "memory answers it", "memories answer it") + (r.matched > 1 ? ", best first" : "");
255
+ const notes = [];
256
+ if (r.subjects.length > 0) notes.push("about " + r.subjects.map((s) => s.name).join(", "));
257
+ const t = timeWords(r.time);
258
+ if (t) notes.push(t);
259
+ const ch = channelWords(r.semantic);
260
+ if (ch) notes.push(ch);
261
+ if (r.weak > 0) notes.push(plural(r.weak, "weak match", "weak matches") + " not shown");
262
+ if (r.meaningCapped) notes.push("the search by meaning stopped at its cap, so this may not be everything");
263
+ if (r.duplicates > 0) notes.push(plural(r.duplicates, "near-copy", "near-copies") + " of an answer left out");
264
+ return esc(lead) + noteLine(notes);
265
+ }
266
+
267
+ /** A chapter's heading at the front of its words ("chapter 2 — Mon 1 Jun 2026 ·
268
+ * lived day 3"), stacked or not, taken off — the row's title says the day and
269
+ * its line says which chapter (`self/episodes.ts#readChapterLead`, flattened).
270
+ * Display only. */
271
+ export function withoutChapterHeading(text) {
272
+ const lead = /^\s*chapter\s+\d+(?:\s*[—–-]\s*(?:[A-Za-z]{3} \d{1,2} [A-Za-z]{3} \d{4}\s*·\s*)?(?:[A-Za-z0-9][A-Za-z0-9._:[\]-]*\s*·\s*)?lived day\s+\d+)?\s*/i;
273
+ let rest = String(text || "");
274
+ for (let m = lead.exec(rest); m && m[0].length > 0; m = lead.exec(rest)) rest = rest.slice(m[0].length);
275
+ return rest;
276
+ }
277
+
278
+ /** Under one fact's words: who said it, its status, when it was learned
279
+ * (when the right-hand date is when it happened), which chapter, and what it
280
+ * was before. Only what the answer carries; markup, or "". */
281
+ export function factLines(m) {
282
+ const said = [];
283
+ if (m.journal) {
284
+ if (m.chapter) said.push("chapter " + m.chapter.n + " of " + m.chapter.of);
285
+ if (m.lastWritten) said.push("written until " + dateOr(m.lastWritten));
286
+ } else {
287
+ if (m.saidBy) said.push(SAID[m.saidBy] || m.saidBy);
288
+ if (m.status) said.push(m.status);
289
+ if (m.occurredOn && m.learned && m.learned !== m.occurredOn) said.push("learned " + dateOr(m.learned));
290
+ }
291
+ const parts = said.map(esc);
292
+ if (!m.current) {
293
+ parts.push(/^(mem|epi|sch)_/.test(m.now || "") ? "an earlier version — now " + withIdMarks(m.now) : "an earlier version — a later one holds now");
294
+ }
295
+ for (const s of m.standing || []) parts.push(withIdMarks(s));
296
+ if (m.corrected > 0) parts.push(esc(plural(m.corrected, "corrected version") + " hidden"));
297
+ const earlier = (m.earlier || []).map((e) =>
298
+ '<div class="mearlier">earlier: “' + esc(e.text) + "”" +
299
+ esc((e.learned ? " (learned " + dateOr(e.learned) + ")" : "") + (e.changed ? ", changed " + dateOr(e.changed) : "")) +
300
+ (e.id ? " " + withIdMarks(e.id) : "") + "</div>").join("") +
301
+ (m.earlierMore > 0 ? '<div class="mearlier">+' + m.earlierMore + " more earlier</div>" : "");
302
+ if (parts.length === 0 && !earlier) return "";
303
+ return '<div class="mfacts">' + (parts.length > 0 ? "<div>" + parts.join(" · ") + "</div>" : "") + earlier + "</div>";
304
+ }
305
+
306
+ /** One fact as a row: its date is when it happened, else when it was learned
307
+ * (a chapter: when it was written, in its title). */
308
+ export function factRow(m, words) {
309
+ return memRow({
310
+ id: m.id,
311
+ title: m.title,
312
+ text: m.journal ? withoutChapterHeading(m.body) : m.body,
313
+ kind: m.kind,
314
+ journal: m.journal,
315
+ date: m.journal ? m.learned : m.occurredOn || m.learned,
316
+ dateFrom: m.journal ? null : m.occurredOn ? "happened" : "learned",
317
+ confidential: false, core: false, feelings: [], archived: null,
318
+ }, { mark: words, under: factLines(m) });
319
+ }
320
+
321
+ /** A facts answer's rows: the page's results, then its faded ones. Markup. */
322
+ export function factsRows(r, q) {
323
+ const words = questionWords(q);
324
+ const rows = r.memories.map((m) => factRow(m, words)).join("");
325
+ const faded = r.faded.length === 0 ? "" :
326
+ '<div class="mclose-h">Faded <span>· ' + esc(plural(r.fadedTotal, "memory", "memories") + " not used for a long while") + "</span></div>" +
327
+ r.faded.map((f) => memRow({ id: f.id, title: f.line, text: "", date: f.date, dateFrom: "learned", feelings: [] }, { mark: words })).join("");
328
+ if (!rows && !faded) {
329
+ return '<div class="empty">Nothing I hold answers that. Try the words the memory itself would use, a person or a project it names, or a wider time.</div>';
330
+ }
331
+ return rows + faded;
332
+ }
333
+
334
+ /** A meaning answer's head: what it is about, how much holds it, then the quieter notes. Markup. */
335
+ export function meaningHead(r) {
336
+ if (r.lens === null) return esc("nothing came");
337
+ const c = r.counts;
338
+ const parts = [r.lens.name];
339
+ if (c.chapters > 0) parts.push(plural(c.chapters, "chapter"));
340
+ const chapterless = c.sessions - c.unplaced;
341
+ if (chapterless > 0) parts.push(plural(chapterless, "session") + " with no chapter");
342
+ if (c.unplaced > 0) parts.push(plural(c.unplaced, "session") + " with moments outside its chapters");
343
+ parts.push(plural(c.moments, "moment") + (c.faded > 0 ? " (+" + c.faded + " faded)" : ""));
344
+ const notes = [];
345
+ if (r.feeling) notes.push("feeling asked: " + (r.feeling.words.length > 0 ? r.feeling.words.join(", ") : "any") + " · " + (r.feeling.whose || "both of us"));
346
+ if (r.others.length > 0) {
347
+ notes.push("also named: " + r.others.map((o) => o.name + " (" + plural(o.memories, "memory", "memories") + ")").join(", ") + " — ask about one by name");
348
+ }
349
+ // Its own notes say what makes it thin — words alone, when no card or
350
+ // feeling found the moments, among them — so no channel line is added here.
351
+ for (const n of r.notes) notes.push(n);
352
+ return esc(parts.join(" · ")) + noteLine(notes);
353
+ }
354
+
355
+ /** What a mark on an arc entry says (`MeaningEntry.marks`). */
356
+ const MARK_WORDS = { start: "where it starts", end: "the latest", turn: "the feelings turn here" };
357
+
358
+ /** Whose feelings, side by side and never merged: "mine: proud · Mike's: worried". */
359
+ function feelingSides(f, whose) {
360
+ const side = (list, who) => (list && list.length > 0 ? who + ": " + list.map((x) => x.word).join(", ") : null);
361
+ return [side(f.self, whose.self), side(f.owner, whose.owner)].filter(Boolean).join(" · ");
362
+ }
363
+
364
+ /** One entry of the arc: a chapter (opens its journal), or a session's moments
365
+ * with no chapter (opens nothing). Its moments are links under it. */
366
+ export function arcRow(e, whose) {
367
+ const chapter = e.kind === "chapter";
368
+ const lines = [];
369
+ if (chapter && e.of > 1) lines.push("chapter " + e.chapter + " of " + e.of);
370
+ for (const mk of e.marks) lines.push(MARK_WORDS[mk] || mk);
371
+ const felt = feelingSides(e.feelings, whose);
372
+ if (felt) lines.push(felt);
373
+ const more = e.momentCount - e.moments.length;
374
+ const moments = e.moments.map((m) =>
375
+ '<button type="button" class="mmoment" data-open="' + esc(m.id) + '">' + withIdMarks(m.title, true) + "</button>").join("") +
376
+ (more > 0 ? '<span class="mmore">+' + more + " more of its moments</span>" : "");
377
+ const under = (lines.length > 0 ? '<div class="mfacts"><div>' + esc(lines.join(" · ")) + "</div></div>" : "") +
378
+ (moments ? '<div class="mmoments">' + moments + "</div>" : "");
379
+ return memRow(chapter
380
+ ? { id: e.episodeId, title: e.title, text: e.line, journal: true, date: e.date, feelings: [] }
381
+ : { id: null, title: e.unplaced ? "Moments outside that session's chapters" : "A session with no chapter written", text: "",
382
+ date: e.date, dateFrom: "recorded", feelings: [] },
383
+ { under });
384
+ }
385
+
386
+ /** A stretch of the arc this page does not show, as one quiet line. */
387
+ function foldRow(l, page) {
388
+ const what = page === 1 ? plural(l.count, "quieter entry", "quieter entries") : plural(l.count, "entry", "entries");
389
+ const when = l.from === null ? "" : l.to === null || l.to === l.from ? ", " + dateOr(l.from) : ", " + dateOr(l.from) + " – " + dateOr(l.to);
390
+ return '<div class="mfold">' + esc("· " + what + " not shown here" + when) + "</div>";
391
+ }
392
+
393
+ /** A titled part after the arc, or nothing when it is empty. */
394
+ function part(title, note, rows) {
395
+ return rows ? '<div class="mclose-h">' + esc(title) + (note ? " <span>· " + esc(note) + "</span>" : "") + "</div>" + rows : "";
396
+ }
397
+
398
+ /** A meaning answer's rows: the arc in time order, then the faded moments,
399
+ * what I made of it before, what is still open, and what recurs. Markup. */
400
+ export function meaningRows(r) {
401
+ if (r.lens === null) {
402
+ return '<div class="empty">Nothing came: the question names no one and nothing I keep a card for, asks about no feeling, and none of its words reach a memory. Try a person’s or a project’s name — or ask for the facts.</div>';
403
+ }
404
+ if (r.reason === "nothing-came") return '<div class="empty">Nothing I hold is about that yet. Try a person’s or a project’s name — or ask for the facts.</div>';
405
+ const plain = (x, under) => memRow({ id: x.id, title: x.title, text: x.excerpt || "", date: x.date, dateFrom: "recorded", feelings: [] },
406
+ under ? { under: '<div class="mfacts"><div>' + esc(under) + "</div></div>" } : {});
407
+ const p = r.patterns;
408
+ const recurring = [
409
+ p.subjects.length > 0 ? "with " + p.subjects.map((x) => x.label + " (" + x.entries + " of " + x.of + ")").join(", ") : "",
410
+ p.feelings.length > 0 ? "feelings: " + p.feelings.map((x) => x.label + " (" + x.entries + " of " + x.of + ")").join(", ") : "",
411
+ ].filter(Boolean);
412
+ return r.arc.map((l) => (l.fold ? foldRow(l, r.page) : arcRow(l.entry, r.whose))).join("") +
413
+ part("Faded", plural(r.counts.faded, "moment") + " not used for a long while", r.faded.map((m) => plain(m)).join("")) +
414
+ part("What I made of it before", "dreams and reflections", r.readings.map((g) => plain(g, g.by === "dreamed" ? "from a dream" : "from a reflection")).join("")) +
415
+ part("Still open", "", r.open.map((o) => plain(o, o.why === "dated" ? "a date still ahead" : "not settled yet")).join("")) +
416
+ part("Recurring", "across the entries of the arc", recurring.map((x) => '<div class="mfold">' + esc(x) + "</div>").join(""));
417
+ }
418
+
419
+ /** An answer's pages, as the list's pager looks: back, where, more. "" for one page. */
420
+ export function askPager(r) {
421
+ if (!(r.pages > 1)) return "";
422
+ const first = (r.page - 1) * FACTS_PAGE;
423
+ const range = r.mode === "facts" && r.memories.length > 0
424
+ ? '<span class="mpage">' + (first + 1) + "–" + (first + r.memories.length) + " of " + r.matched + "</span>" : "";
425
+ const button = (page, words, off) =>
426
+ '<button type="button" class="mbtn" data-ask-page="' + page + '"' + (off ? " disabled" : "") + ">" + words + "</button>";
427
+ return button(r.page - 1, "← back", r.page <= 1) + range +
428
+ '<span class="mpage mpage-n">page ' + r.page + " of " + r.pages + "</span>" + button(r.page + 1, "more →", r.page >= r.pages);
210
429
  }
@@ -10,7 +10,8 @@ export const filters = {
10
10
 
11
11
  /** The find box: while it holds words, its answers stand in the list's place
12
12
  * (round 4, 2026-09-28: results REPLACE the list). Any filter change ends it.
13
- * `mode`: the switch beside it, "word" or "meaning" (2026-09-30). */
13
+ * `mode`: the switch beside it, "word" or "meaning" (2026-09-30), or "facts"
14
+ * (2026-10-09). */
14
15
  export const find = { on: false, mode: "word" };
15
16
 
16
17
  const listeners = [];
@@ -84,7 +84,6 @@ import { DREAM_LIMIT, dreamsView } from "./views/dreams.js";
84
84
  import { resolveStatic } from "./static.js";
85
85
  import {
86
86
  activityView,
87
- chapterLinks,
88
87
  eventDetail,
89
88
  flowView,
90
89
  healthView,
@@ -279,10 +278,6 @@ export function router(
279
278
  if (path === "/api/search") {
280
279
  return json(searchView(src, url.searchParams.get("q") ?? "", intParam(url, "limit", 25)));
281
280
  }
282
- if (path === "/api/chapters") {
283
- const ids = (url.searchParams.get("ids") ?? "").split(",").map((s) => s.trim()).filter((s) => s.length > 0);
284
- return json(chapterLinks(src, ids));
285
- }
286
281
  if (path === "/api/mind") return json(mindView(src));
287
282
  if (path === "/api/dreams") return json(dreamsView(src, intParam(url, "limit", DREAM_LIMIT)));
288
283
  if (path === "/api/flow") return json(flowView(src, intParam(url, "limit", 24)));
@@ -13,3 +13,10 @@
13
13
  .mbadge.core{color:#e8dcff;border-color:rgba(179,136,255,.45)}
14
14
  .mbadge.lock{color:var(--amber);border-color:rgba(255,215,64,.35);padding:1px 5px}
15
15
  .mbadge.journal{color:var(--purple);border-color:rgba(179,136,255,.3)}
16
+ /* An id inside a memory's words, drawn as what it is ("memory ↗"), the id on
17
+ hover (`idMark`). Quiet: the same word, not a link. */
18
+ .idref{display:inline;padding:0;margin:0;background:none;border:none;border-radius:3px;font:inherit;font-size:.92em;
19
+ color:var(--cyan);cursor:pointer;white-space:nowrap}
20
+ .idref:hover,.idref:focus-visible{text-decoration:underline;outline:none}
21
+ .idref.quiet{color:var(--faint);cursor:inherit}
22
+ .idref.quiet:hover{text-decoration:none}
@@ -82,3 +82,36 @@ export function badges(r) {
82
82
 
83
83
  const LOCK = '<svg class="kic" viewBox="0 0 16 16" aria-label="protected"><rect x="3.5" y="7" width="9" height="7" rx="1.3"/>' +
84
84
  '<path d="M5.5 7V5a2.5 2.5 0 0 1 5 0v2"/></svg>';
85
+
86
+ /**
87
+ * A memory's own id written inside words — "(mem_cb6eea7a6b9f)", a dream's
88
+ * "replaces mem_…", a chapter's address "epi_…#2" (2026-10-09). The store's
89
+ * three families (`store/prose.ts#ID_PREFIX`), twelve hex digits from
90
+ * `randomBytes(6)` (sixteen allowed, as `recall/reference.ts#MEMORY_ID`).
91
+ */
92
+ export const ID_IN_WORDS = /\b(?:mem|epi|sch)_[0-9a-f]{12,16}(?:#\d+)?\b/;
93
+
94
+ /** What an id in the words is called, by its family, instead of its digits. */
95
+ const ID_WORDS = { mem: "memory", epi: "journal", sch: "card" };
96
+
97
+ /**
98
+ * An id inside words, drawn as what it is rather than its digits: a small
99
+ * link that opens it (`data-open`, which the memories list routes to
100
+ * `openMemory`, `row.js#wireRows`), the id itself on hover. A chapter's
101
+ * address opens its journal and says which chapter. `quiet` draws the same
102
+ * word with no link — for words already inside something clickable, where a
103
+ * link cannot nest. Display only: the memory keeps its words.
104
+ */
105
+ export function idMark(ref, quiet) {
106
+ const [id, chapter] = String(ref).split("#");
107
+ const word = (ID_WORDS[id.slice(0, 3)] || "memory") + (chapter ? " chapter " + chapter : "");
108
+ return quiet
109
+ ? '<span class="idref quiet" title="' + esc(ref) + '">' + esc(word) + "</span>"
110
+ : '<button type="button" class="idref" data-open="' + esc(id) + '" title="open ' + esc(ref) + '">' + esc(word) + " ↗</button>";
111
+ }
112
+
113
+ /** `text`, escaped, with every id in it drawn by `idMark`. */
114
+ export function withIdMarks(text, quiet) {
115
+ const parts = String(text || "").split(new RegExp("(" + ID_IN_WORDS.source + ")"));
116
+ return parts.map((p, i) => (i % 2 === 1 ? idMark(p, quiet) : esc(p))).join("");
117
+ }
@@ -13,7 +13,7 @@ import { emptyBox } from "./absence.js";
13
13
  import { esc } from "./dom.js";
14
14
  import { headline, n2, n3, said } from "./format.js";
15
15
  import { coreRoadLine, curveStart, versionRows } from "./memory-card-words.js";
16
- import { dateOr, stampWords } from "./dates.js";
16
+ import { dateOr, localIso, stampWords } from "./dates.js";
17
17
  import { FEELING_COLOURS, feelingName, feelingWord, kindMark, kindOf } from "./memory-marks.js";
18
18
  import { openModal } from "./modal.js";
19
19
  import { confirmTyped } from "./widgets/confirm.js";
@@ -48,9 +48,11 @@ export function memoryCard(d) {
48
48
  }
49
49
 
50
50
  /** The day it was written, once: "Written Sep 28th, 2026" — the moment it entered
51
- * the store (v7 `created_at`), else the calendar day it was recorded. */
51
+ * the store (v7 `created_at`) on this computer's calendar, else the calendar day
52
+ * it was recorded. It read the UTC day until 2026-10-09, which put a memory
53
+ * written on a Denver evening on the next day. */
52
54
  export function writtenOn(d) {
53
- if (typeof d.createdAt === "number" && d.createdAt > 0) return new Date(d.createdAt).toISOString().slice(0, 10);
55
+ if (typeof d.createdAt === "number" && d.createdAt > 0) return localIso(d.createdAt);
54
56
  return /^\d{4}-\d{2}-\d{2}$/.test(String(d.learnedOn || "")) ? d.learnedOn : null;
55
57
  }
56
58
 
@@ -278,7 +278,7 @@ const ADAPTER_EVENTS: readonly DurableEventName[] = [
278
278
 
279
279
  const ADAPTER_NOTE: Partial<Record<DurableEventName, string>> = {
280
280
  "adapter.wake.injected": "bytes handed to the host, never the text",
281
- "adapter.wake.delivered": "whether the briefing was actually seen the next turn",
281
+ "adapter.wake.delivered": "whether the briefing actually arrived, checked at the first prompt or the first Stop",
282
282
  "adapter.recall": "how long recall took, when the adapter recorded it",
283
283
  "adapter.ask": "asked, paced out, or capped for the day",
284
284
  "adapter.authorship.ask": "historical — nothing writes this now",
@@ -1,5 +1,7 @@
1
1
  /**
2
- * `/api/search`, and `/api/chapters` (the chapter an Ask answer came from).
2
+ * `/api/search`. (`/api/chapters`, the chapter an Ask answer came from, left
3
+ * with the "from chapter" link on 2026-10-09: facts mode folds a chapter and
4
+ * the memory drawn from it into one answer itself.)
3
5
  *
4
6
  * Split out of `web/views.ts`, which re-exports every public name from here;
5
7
  * the four rules in that file's header apply to every line below.
@@ -9,7 +11,7 @@ import { isJournal } from "../../../../core/sleep/index.js";
9
11
  import type { Band, Kind } from "../../../../core/types.js";
10
12
  import { NEVER, NONE } from "../../layout.js";
11
13
  import type { DashboardSource } from "../../source.js";
12
- import { reveal, revealHere } from "../reveal.js";
14
+ import { reveal } from "../reveal.js";
13
15
  import { feelingsShown, isChapterMemory, shownOf } from "./memory-words.js";
14
16
  import type { DateFrom, FeelingShown } from "./memory-words.js";
15
17
 
@@ -50,49 +52,6 @@ export interface Hit {
50
52
  feelings: FeelingShown[];
51
53
  }
52
54
 
53
- /** How many ids one `/api/chapters` call looks at — an Ask answer is a handful. */
54
- export const CHAPTER_LINKS_MAX = 50;
55
-
56
- /** A journal-chapter memory's chapter: the journal entry it was minted from. */
57
- export interface ChapterLink {
58
- readonly episodeId: string;
59
- /** The journal entry's title, or null when it has none (or is withheld). */
60
- readonly label: string | null;
61
- }
62
-
63
- /**
64
- * `/api/chapters?ids=…` — for each id that is a JOURNAL-CHAPTER MEMORY
65
- * (`isChapterMemory`: minted from a chapter, `meta.episodeId`), the journal
66
- * entry it came from. Ask (the console's `ask --json`) can return a chapter
67
- * and the memory drawn from it side by side with the same words; the page
68
- * folds the pair into one answer with a "from chapter …" link (2026-09-27).
69
- *
70
- * Read-only and quiet: `row()` only, never `read()` (a read is an event).
71
- * Ids that are not chapter memories, or whose journal entry is gone, are left
72
- * out.
73
- */
74
- export function chapterLinks(src: DashboardSource, ids: readonly string[]): { links: Record<string, ChapterLink> } {
75
- const store = src.store;
76
- const links: Record<string, ChapterLink> = {};
77
- for (const id of ids.slice(0, CHAPTER_LINKS_MAX)) {
78
- const row = store.row(id);
79
- if (row === undefined || !isChapterMemory(row)) continue;
80
- let episodeId: unknown;
81
- try {
82
- episodeId = (JSON.parse(row.meta) as Record<string, unknown>)["episodeId"];
83
- } catch {
84
- continue;
85
- }
86
- if (typeof episodeId !== "string" || episodeId === id) continue;
87
- const episode = store.row(episodeId);
88
- if (episode === undefined) continue;
89
- const r = revealHere(store, episodeId, 80);
90
- const title = episode.title?.trim() ?? "";
91
- links[id] = { episodeId, label: r.confidential || !r.present || title === "" ? null : title };
92
- }
93
- return { links };
94
- }
95
-
96
55
  export function searchView(src: DashboardSource, q: string, limit = 25): SearchView {
97
56
  const store = src.store;
98
57
  const day = store.livedDay();
@@ -44,8 +44,8 @@ export { LIST_MAX, memoriesView, memoryListView } from "./views/memories.js";
44
44
  export type { KindRow, ListRow, ListState, MemoriesView, MemoryListView } from "./views/memories.js";
45
45
  export { coreRoad, memoryDetail } from "./views/memory.js";
46
46
  export type { CoreRoad, MemoryDetail } from "./views/memory.js";
47
- export { CHAPTER_LINKS_MAX, chapterLinks, searchView } from "./views/search.js";
48
- export type { ChapterLink, SearchView } from "./views/search.js";
47
+ export { searchView } from "./views/search.js";
48
+ export type { SearchView } from "./views/search.js";
49
49
  export { mindView, wakeLanes } from "./views/mind.js";
50
50
  export type { MindView, StoryBeat, StoryView, WakeLane } from "./views/mind.js";
51
51
  export { activityView, eventDetail } from "./views/activity.js";