counterparts 0.3.2 → 0.3.3

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 (66) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/package.json +1 -1
  3. package/src/adapters/claude-code/NOTES.md +12 -0
  4. package/src/adapters/claude-code/bin/hook.ts +85 -22
  5. package/src/adapters/claude-code/config.ts +7 -0
  6. package/src/adapters/claude-code/doctor.ts +20 -4
  7. package/src/adapters/claude-code/hooks.ts +157 -6
  8. package/src/adapters/claude-code/index.ts +3 -0
  9. package/src/adapters/cli/commands.ts +11 -0
  10. package/src/adapters/cli/mechanisms.ts +46 -21
  11. package/src/adapters/dashboard/registries.ts +4 -0
  12. package/src/adapters/dashboard/web/README.md +19 -11
  13. package/src/adapters/dashboard/web/flow.ts +2 -0
  14. package/src/adapters/dashboard/web/mechanisms/emotional/index.js +9 -5
  15. package/src/adapters/dashboard/web/mechanisms/prospective/index.js +6 -3
  16. package/src/adapters/dashboard/web/narrate.ts +8 -0
  17. package/src/adapters/dashboard/web/pages/health/sections/checks.js +17 -1
  18. package/src/adapters/dashboard/web/pages/self/index.js +55 -16
  19. package/src/adapters/dashboard/web/pages/self/sections/journal.js +75 -19
  20. package/src/adapters/dashboard/web/pages/self/sections/page.js +108 -65
  21. package/src/adapters/dashboard/web/pages/self/sections/settling.js +94 -99
  22. package/src/adapters/dashboard/web/pages/self/sections/wake.js +31 -15
  23. package/src/adapters/dashboard/web/pages/self/self.css +119 -59
  24. package/src/adapters/dashboard/web/pages/self/state.js +23 -0
  25. package/src/adapters/dashboard/web/pages/self/tips.js +50 -0
  26. package/src/adapters/dashboard/web/shared/memory-modal.js +9 -0
  27. package/src/adapters/dashboard/web/views/mechanisms.ts +85 -14
  28. package/src/adapters/dashboard/web/views/memory.ts +15 -1
  29. package/src/adapters/dashboard/web/views/mind.ts +130 -6
  30. package/src/adapters/feelings-line.ts +74 -0
  31. package/src/adapters/fired.ts +78 -18
  32. package/src/adapters/mcp/CONTRACT.md +8 -0
  33. package/src/adapters/mcp/NOTES.md +45 -0
  34. package/src/adapters/mcp/server.ts +165 -6
  35. package/src/adapters/mcp/tools.ts +51 -4
  36. package/src/core/bridge.ts +21 -16
  37. package/src/core/counterpart.ts +309 -6
  38. package/src/core/encode/CONTRACT.md +7 -1
  39. package/src/core/feelings-wheel.ts +171 -13
  40. package/src/core/mint.ts +9 -0
  41. package/src/core/physics/CONTRACT.md +43 -0
  42. package/src/core/physics/NOTES.md +94 -0
  43. package/src/core/physics/index.ts +98 -6
  44. package/src/core/prospective/CONTRACT.md +35 -6
  45. package/src/core/prospective/INTERFACE-GAPS.md +10 -5
  46. package/src/core/prospective/NOTES.md +175 -4
  47. package/src/core/prospective/derive.ts +32 -3
  48. package/src/core/prospective/index.ts +362 -39
  49. package/src/core/prospective/tunables.ts +18 -1
  50. package/src/core/prospective/windows.ts +104 -46
  51. package/src/core/recall/CONTRACT.md +28 -0
  52. package/src/core/recall/NOTES.md +39 -0
  53. package/src/core/recall/activate.ts +32 -5
  54. package/src/core/recall/gate.ts +7 -1
  55. package/src/core/recall/index.ts +19 -0
  56. package/src/core/recall/mood.ts +106 -0
  57. package/src/core/recall/tunables.ts +26 -0
  58. package/src/core/remember/index.ts +1 -0
  59. package/src/core/remember/proposals.ts +86 -3
  60. package/src/core/self/identity.ts +20 -1
  61. package/src/core/store/CONTRACT.md +9 -2
  62. package/src/core/store/NOTES.md +20 -0
  63. package/src/core/store/feelings.ts +23 -6
  64. package/src/core/store/index.ts +107 -10
  65. package/src/core/store/operational.ts +15 -1
  66. package/src/core/types.ts +9 -0
@@ -79,16 +79,31 @@ export const MEMORY_MECHANISMS: readonly MemoryMechanism[] = [
79
79
  {
80
80
  name: "Emotion",
81
81
  group: "Encoding",
82
- evidence: ["emotion"],
83
- // The audit's verdict: a feeling is recorded as a label and carries no
84
- // weight, and the classifier ships off. Idle whatever the counts say.
85
- read: (rows) => ({
86
- light: LIGHT.idle,
87
- says:
88
- rows("emotion")?.state === "disabled"
89
- ? "built, held back: the feeling classifier is off, so feelings carry no weight yet"
90
- : "built, not firing yet: feelings are recorded but carry no weight yet",
91
- }),
82
+ evidence: ["feelings", "emotion-weight", "mood-match"],
83
+ // Emotion part A (2026-09-26): a memory's strongest feeling lifts it and
84
+ // slows its fading, and a recorded mood lifts matching memories in recall.
85
+ // Working when a memory carrying feeling was written this week or a mood
86
+ // lifted a memory that came to mind; the totals ride along either way.
87
+ read: (rows) => {
88
+ const weighted = rows("emotion-weight")?.total ?? 0;
89
+ const withFeelings = rows("feelings")?.total ?? 0;
90
+ const newWeighted = week(rows, "emotion-weight");
91
+ const matched = week(rows, "mood-match");
92
+ const held = `${plural(weighted, "memory", "memories")} held higher and fading slower (${String(withFeelings)} with recorded feelings)`;
93
+ if (newWeighted + matched > 0) {
94
+ const parts: string[] = [];
95
+ if (newWeighted > 0) parts.push(`${plural(newWeighted, "new memory", "new memories")} carrying feeling`);
96
+ if (matched > 0) parts.push(`${plural(matched, "turn")} where a mood brought matching memories closer`);
97
+ return { light: LIGHT.working, says: `${parts.join("; ")}; ${held}` };
98
+ }
99
+ return {
100
+ light: LIGHT.idle,
101
+ says:
102
+ weighted > 0
103
+ ? `built, not firing yet this week: ${held}`
104
+ : "built, not firing yet: no memory carries a feeling",
105
+ };
106
+ },
92
107
  },
93
108
  // ── Storage ──
94
109
  {
@@ -171,18 +186,28 @@ export const MEMORY_MECHANISMS: readonly MemoryMechanism[] = [
171
186
  {
172
187
  name: "Prospective",
173
188
  group: "Retrieval",
174
- evidence: ["prospective-armed", "prospective-fired"],
175
- // Nothing in live use can put a date on a memory yet (audit: DRAFT_FIELDS),
176
- // and nothing spends a fire. A store that holds dated intentions anyway has
177
- // the half that is built; one that holds none has nothing of it.
189
+ evidence: ["prospective-dated", "prospective-fired", "prospective-plain"],
190
+ // Built end to end since 2026-09-26: `note` and `session_end` take a date,
191
+ // a quiet one comes back as a footnote cue (`prospective.fire`), a plain
192
+ // one is said on its day (`prospective.plain`). Grey only when nothing is
193
+ // dated at all — then there is truly nothing for it to do.
178
194
  read: (rows) => {
179
- const armed = rows("prospective-armed")?.total ?? 0;
180
- return armed > 0
181
- ? {
182
- light: LIGHT.idle,
183
- says: `built, not firing yet: ${plural(armed, "dated reminder")} held, and nothing brings one back yet`,
184
- }
185
- : { light: LIGHT.notBuilt, says: "not built yet: nothing can put a date on a memory" };
195
+ const dated = rows("prospective-dated")?.total ?? 0;
196
+ const quiet = week(rows, "prospective-fired");
197
+ const plain = week(rows, "prospective-plain");
198
+ const held = `${plural(dated, "dated memory", "dated memories")} held`;
199
+ if (quiet + plain > 0) {
200
+ const parts: string[] = [];
201
+ if (plain > 0) parts.push(`${String(plain)} said plainly`);
202
+ if (quiet > 0) parts.push(`${String(quiet)} as quiet footnotes`);
203
+ return {
204
+ light: LIGHT.working,
205
+ says: `${plural(quiet + plain, "reminder")} came back (${parts.join(", ")}); ${held}`,
206
+ };
207
+ }
208
+ return dated > 0
209
+ ? { light: LIGHT.idle, says: `built, nothing due this week: ${held}` }
210
+ : { light: LIGHT.notBuilt, says: "nothing dated yet: a note with a date comes back around that day" };
186
211
  },
187
212
  },
188
213
  // ── Transformation ──
@@ -64,8 +64,10 @@ import { BAND_TRANSITION_EVENT } from "../../core/sleep/index.js";
64
64
  // Prospective memory's two (2026-09-20, E2). The module had no durable row at
65
65
  // all: `fires` is a column, so the store could say a window had ever fired and
66
66
  // never when, or why one did not.
67
+ // And a third (2026-09-26): a PLAIN item told to the person on its day.
67
68
  import {
68
69
  PROSPECTIVE_FIRE_EVENT,
70
+ PROSPECTIVE_PLAIN_EVENT,
69
71
  PROSPECTIVE_REFUSED_EVENT,
70
72
  } from "../../core/prospective/index.js";
71
73
  // The self page's two, from `self/` itself (2026-09-18, S1): a written page is
@@ -176,6 +178,7 @@ export type DurableEventName =
176
178
  | typeof SNAPSHOT_ROTATED_EVENT
177
179
  | typeof PROSPECTIVE_FIRE_EVENT
178
180
  | typeof PROSPECTIVE_REFUSED_EVENT
181
+ | typeof PROSPECTIVE_PLAIN_EVENT
179
182
  | typeof JOURNAL_COPY_WRITTEN_EVENT
180
183
  | typeof JOURNAL_COPY_FAILED_EVENT
181
184
  | typeof STORE_EXPORT_EVENT
@@ -265,6 +268,7 @@ export const DURABLE_EVENTS = {
265
268
  // counted as a firing.
266
269
  "prospective.fire": "a future date arrived and the reminder was offered into the turn (which window, and how much of its budget is left)",
267
270
  "prospective.fire.refused": "a reminder was NOT offered (which brake held — one row per window per reason per lived day)",
271
+ "prospective.plain": "a reminder its author marked plain was told to the person on its day (which window, which beat — its day, a month or range opening, or its last day — and the date)",
268
272
  // The journal's markdown copy and the hand export (2026-09-20, F6 and F7):
269
273
  // the two places the constitution's "prose the owner can view" is kept now
270
274
  // that every body is a column.
@@ -108,17 +108,25 @@ filter), `list.js` (every memory, newest first, paged on the server by
108
108
  `/api/memories/list` in `views/memories.ts`, whose archive reasons are put into
109
109
  plain words by `archiveWords` from `views/archive-words.ts`).
110
110
 
111
- `pages/self/`: the self tab. `sections/page.js` is the self page (rendered by
112
- `markdown.js`, which escapes first) and its history as a timeline; clicking a
113
- dot diffs that version against the one before with `diff.js` (line comparison,
114
- then words, no deps). `sections/settling.js` covers the core, protected and
115
- contested memories, plus the closest candidates for the core; the view computes
116
- them with `physics#promotionEligibility` and counts memories that can't get
117
- there by use separately. `sections/wake.js` is the wake folded to one line and
118
- a stacked bar of its parts (`wakeParts` in `views/mind.ts`, cut at the lane
119
- headings from `self/`), plus the rebrief button. `sections/journal.js` shows
120
- chapters by day with their model. `sections/stories.js` is only `storyCard`,
121
- opened in the overlay. The view is still `views/mind.ts` / `/api/mind`.
111
+ `pages/self/`: the self tab (reworked 2026-09-26 as an experiment). The top is
112
+ two columns: the self page on the left (rendered by `markdown.js`, which escapes
113
+ first), and a side column with when it was rewritten and by whom, the page
114
+ writer's newest night in words (`writer` in `views/mind.ts`, read through
115
+ `self/`'s `pageWriterStatus`), the history as a line of dots, and the wake.
116
+ `sections/page.js` draws the page, the side column's facts and the dots;
117
+ clicking a dot opens that version above the page and diffs it against the one
118
+ before with `diff.js` (line comparison, then words, no deps); nothing is open
119
+ by default. `sections/settling.js` is one line of counts (core, protected,
120
+ argued with; each opens its list) over a compact chart of the closest
121
+ candidates for the core; the view computes them with
122
+ `physics#promotionEligibility`. `sections/wake.js` is the wake as one line and
123
+ a stacked bar of its parts (`wakeParts`, cut at the lane headings from `self/`),
124
+ with the rebrief button shown disabled ("coming soon", back with the sleep
125
+ work). `sections/journal.js` is a strip of days; a day lists its chapters, a
126
+ chapter opens in place. `tips.js` is the `?` that holds each explaining line;
127
+ `state.js` holds what is open, so the pulse's `refresh()` (which redraws only
128
+ the panels whose data moved) keeps it open. `sections/stories.js` is only
129
+ `storyCard`, opened in the overlay. The view is still `views/mind.ts` / `/api/mind`.
122
130
 
123
131
  The health tab answers "is it working?": `pages/health/sections/checks.js` runs
124
132
  `counterparts doctor --json` through the actions seam (a read; a dashboard
@@ -422,6 +422,8 @@ export const EVENT_NODE = {
422
422
  // not a command), so both rows land on the prospective node.
423
423
  "prospective.fire": "prospective",
424
424
  "prospective.fire.refused": "prospective",
425
+ // A plain item told on its day (2026-09-26) is the same node's, by request.
426
+ "prospective.plain": "prospective",
425
427
  // Which checkout was live at a session start. It belongs to the SESSION node:
426
428
  // it is a fact about the process the host started, recorded on the way in,
427
429
  // before anything was read or written.
@@ -1,6 +1,6 @@
1
1
  /* Emotional modulation. `explainer` is what Counterparts actually does, checked against
2
- docs/research/mechanism-audit-2026-09-24.md; `built` / `inDevelopment` are the
3
- audit plus #215/#218/#220, in plain words; `tagline` and `inDev` are the
2
+ docs/research/mechanism-audit-2026-09-24.md and emotion part A (2026-09-26);
3
+ `built` / `inDevelopment` are in plain words; `tagline` and `inDev` are the
4
4
  site's (regions.ts). Its light comes from `/api/mechanisms`. */
5
5
  export default {
6
6
  id: "emotional",
@@ -9,7 +9,11 @@ export default {
9
9
  short: "Emotion",
10
10
  tagline: "The moments that mattered are the ones you keep. Feeling is the encoder’s thumb on the scale.",
11
11
  inDev: true,
12
- explainer: "A memory its author scored as emotional comes back more easily while you are expressing a feeling. The quoted feeling itself is kept as a label and does not add weight yet.",
13
- built: ["A memory its author scored as emotional comes back more easily while you are expressing a feeling."],
14
- inDevelopment: ["A quoted feeling is kept as a label only; it adds no weight.", "The score is dropped unless all three salience parts are given, and the feeling classifier is switched off."],
12
+ explainer: "The strongest feeling on a memory, yours or Claude’s, holds it higher and makes it fade more slowly. Memories that felt the way one of you feels now come to mind a little more easily.",
13
+ built: [
14
+ "A memory’s strongest recorded feeling, or its emotional score, lifts it and slows its fading.",
15
+ "A recorded feeling softens faster than the memory itself.",
16
+ "Memories that carried the feeling someone has now come up more easily — more for the same person, a little for the other.",
17
+ ],
18
+ inDevelopment: ["Nothing reads feeling from the words themselves: the feeling classifier stays off, so only recorded feelings count."],
15
19
  };
@@ -9,7 +9,10 @@ export default {
9
9
  short: "Prospective",
10
10
  tagline: "Remembering to do something later — the memory that fires itself at the right moment.",
11
11
  inDev: true,
12
- explainer: "Not built yet. A memory can carry a date, like a launch next Tuesday, but nothing brings it back on the day.",
13
- built: ["Dated reminders can be stored and have their own records."],
14
- inDevelopment: ["Nothing live can put a date on a memory yet, and nothing brings one back on the day."],
12
+ explainer: "A memory can carry a date — a day, a month or a range like late October — and it comes back around then. Most come back quietly, as a footnote; one marked plain is said outright on its day.",
13
+ built: [
14
+ "A note or a session's memories can be given a date, and quiet ones come back as footnotes at most twice per date.",
15
+ "A reminder marked plain is said to you on its day, once.",
16
+ ],
17
+ inDevelopment: ["Nothing yet notices when you have already dealt with a reminder, so a quiet one can still come back a second time."],
15
18
  };
@@ -773,6 +773,13 @@ export const NARRATORS = {
773
773
  calm(
774
774
  `I held back a reminder about ${subject(t)} (${s(t, "reason") ?? "no reason recorded"}). Holding debts and losing deadlines is the whole of the tact rule; this is it working.`,
775
775
  ),
776
+ // A plain reminder (2026-09-26): the one kind that is SAID, because its
777
+ // author asked for exactly that.
778
+ "prospective.plain": (t) => {
779
+ const beat = s(t, "beat");
780
+ const when = beat === "last-day" ? "on its last day" : beat === "opens" ? "as its dates opened" : "on the day";
781
+ return notable(`I told you plainly about ${subject(t)} ${when}, as it was asked to be.`);
782
+ },
776
783
 
777
784
  // ── the worker that did start ──────────────────────────────────────────────
778
785
  //
@@ -945,6 +952,7 @@ export const REF_KIND = {
945
952
  // key is a derived address on that row, not an entity of its own.
946
953
  "prospective.fire": "memory",
947
954
  "prospective.fire.refused": "memory",
955
+ "prospective.plain": "memory",
948
956
  "adapter.checkout": "none",
949
957
  "adapter.wake.delivered": "none",
950
958
  "adapter.wake.injected": "none",
@@ -67,6 +67,22 @@ function plain(detail) {
67
67
  return String(detail || "").replace(/^\/\S+ — /, "").replace(/^\/\S+ /, "");
68
68
  }
69
69
 
70
+ /** A line doctor's facts can say in plain words, by key; null keeps the detail. */
71
+ export const PLAIN = {
72
+ // The self page: how long since its last rewrite, and — once that passes
73
+ // doctor's own limit, which is what turns the row amber — that it has.
74
+ "self-page": (d) => {
75
+ if (!d || d.present !== true || typeof d.daysSince !== "number") return null;
76
+ const n = d.daysSince;
77
+ if (d.stale) {
78
+ return "not rewritten in " + n + (n === 1 ? " day" : " days") +
79
+ (typeof d.staleAfter === "number" ? "; this turns amber after " + d.staleAfter : "");
80
+ }
81
+ return "rewritten " + (n <= 0 ? "today" : n === 1 ? "yesterday" : n + " days ago") +
82
+ (typeof d.version === "number" ? " · version " + d.version : "");
83
+ },
84
+ };
85
+
70
86
  function gradeOf(f) {
71
87
  if (f.key === "config" && f.data && f.data.reason === "not-read") return "grey";
72
88
  if (f.optional) return "off";
@@ -100,7 +116,7 @@ function paintFindings(report, when) {
100
116
  const name = NAMES[f.key] || f.title;
101
117
  const line = grade === "grey"
102
118
  ? "not checked — this dashboard was opened on a store, not through its settings file"
103
- : plain(f.detail);
119
+ : (PLAIN[f.key] && PLAIN[f.key](f.data)) || plain(f.detail);
104
120
  details.push(f);
105
121
  rows.push({ grade, name, line, f, order: HEADLINE.indexOf(f.key) });
106
122
  }
@@ -1,40 +1,79 @@
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";
6
13
  import * as journal from "./sections/journal.js";
7
14
  import * as page from "./sections/page.js";
8
15
  import * as settling from "./sections/settling.js";
9
16
  import * as wake from "./sections/wake.js";
17
+ import { q, wireTips } from "./tips.js";
10
18
 
11
19
  const markup = `
12
- <p class="lede" id="mind-opening"></p>${page.markup}
20
+ <h2 class="sp-title" id="mind-opening"></h2>
21
+ <div class="self-top">
22
+ <div class="self-main">${page.mainMarkup}
23
+ </div>
24
+ <aside class="self-side">${page.sideMarkup}${wake.markup}
25
+ </aside>
26
+ </div>
13
27
  <div class="cols self-cols">
14
28
  <div>${settling.markup}
15
29
  </div>
16
- <div>${wake.markup}
30
+ <div>${journal.markup}
17
31
  </div>
18
- </div>${journal.markup}
32
+ </div>
19
33
  `;
20
34
 
21
- async function render() {
35
+ /** Each panel, the slice of the view it draws from, and how it draws. */
36
+ const PANELS = [
37
+ { name: "opening", slice: (d) => [d.opening], paint: paintOpening },
38
+ { name: "page", slice: (d) => [d.page, d.pageAbsent], paint: page.paintPage },
39
+ { name: "meta", slice: (d) => [d.page, d.writer], paint: page.paintMeta },
40
+ { name: "history", slice: (d) => [d.pageHistory], paint: page.paintHistory },
41
+ { name: "wake", slice: (d) => [d.wake, d.wakeParts, d.wakeBudget], paint: wake.paint },
42
+ { name: "settling", slice: (d) => [d.settling, d.stories], paint: settling.paint },
43
+ { name: "journal", slice: (d) => [d.journal, d.journalAbsent, d.journalMore], paint: journal.paint },
44
+ ];
45
+
46
+ /** What each panel was last drawn from. */
47
+ const drawn = {};
48
+
49
+ function paintOpening(d) {
50
+ $("mind-opening").innerHTML = esc(d.opening) + " " +
51
+ 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.");
52
+ wireTips($("mind-opening"));
53
+ }
54
+
55
+ /** Draw every panel whose data moved (all of them when `force`). */
56
+ async function draw(force) {
22
57
  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);
58
+ try { d = await api("/api/mind"); } catch (e) { if (force) fail("The self page", e); return; }
59
+ const x = scrollX, y = scrollY;
60
+ for (const p of PANELS) {
61
+ const key = JSON.stringify(p.slice(d));
62
+ if (!force && drawn[p.name] === key) continue;
63
+ p.paint(d);
64
+ drawn[p.name] = key;
65
+ }
66
+ if (scrollX !== x || scrollY !== y) scrollTo(x, y);
29
67
  }
30
68
 
31
69
  export default {
32
70
  name: "self",
33
71
  mount(section) {
34
72
  section.innerHTML = markup;
35
- wake.mount(render);
73
+ wake.mount(() => draw(false));
36
74
  },
37
- render,
75
+ render: () => draw(true),
76
+ refresh: () => draw(false),
38
77
  /** `#self/settling`, `#self/journal`: open the tab at that section. */
39
78
  route({ anchor }) {
40
79
  const h = anchor && $("self-" + anchor + "-h");
@@ -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 "../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
  }