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.
- package/CHANGELOG.md +72 -0
- package/package.json +1 -1
- package/src/adapters/claude-code/NOTES.md +12 -0
- package/src/adapters/claude-code/bin/hook.ts +85 -22
- package/src/adapters/claude-code/config.ts +7 -0
- package/src/adapters/claude-code/doctor.ts +20 -4
- package/src/adapters/claude-code/hooks.ts +157 -6
- package/src/adapters/claude-code/index.ts +3 -0
- package/src/adapters/cli/commands.ts +11 -0
- package/src/adapters/cli/mechanisms.ts +46 -21
- package/src/adapters/dashboard/registries.ts +4 -0
- package/src/adapters/dashboard/web/README.md +19 -11
- package/src/adapters/dashboard/web/flow.ts +2 -0
- package/src/adapters/dashboard/web/mechanisms/emotional/index.js +9 -5
- package/src/adapters/dashboard/web/mechanisms/prospective/index.js +6 -3
- package/src/adapters/dashboard/web/narrate.ts +8 -0
- package/src/adapters/dashboard/web/pages/health/sections/checks.js +17 -1
- package/src/adapters/dashboard/web/pages/self/index.js +55 -16
- package/src/adapters/dashboard/web/pages/self/sections/journal.js +75 -19
- package/src/adapters/dashboard/web/pages/self/sections/page.js +108 -65
- package/src/adapters/dashboard/web/pages/self/sections/settling.js +94 -99
- package/src/adapters/dashboard/web/pages/self/sections/wake.js +31 -15
- package/src/adapters/dashboard/web/pages/self/self.css +119 -59
- package/src/adapters/dashboard/web/pages/self/state.js +23 -0
- package/src/adapters/dashboard/web/pages/self/tips.js +50 -0
- package/src/adapters/dashboard/web/shared/memory-modal.js +9 -0
- package/src/adapters/dashboard/web/views/mechanisms.ts +85 -14
- package/src/adapters/dashboard/web/views/memory.ts +15 -1
- package/src/adapters/dashboard/web/views/mind.ts +130 -6
- package/src/adapters/feelings-line.ts +74 -0
- package/src/adapters/fired.ts +78 -18
- package/src/adapters/mcp/CONTRACT.md +8 -0
- package/src/adapters/mcp/NOTES.md +45 -0
- package/src/adapters/mcp/server.ts +165 -6
- package/src/adapters/mcp/tools.ts +51 -4
- package/src/core/bridge.ts +21 -16
- package/src/core/counterpart.ts +309 -6
- package/src/core/encode/CONTRACT.md +7 -1
- package/src/core/feelings-wheel.ts +171 -13
- package/src/core/mint.ts +9 -0
- package/src/core/physics/CONTRACT.md +43 -0
- package/src/core/physics/NOTES.md +94 -0
- package/src/core/physics/index.ts +98 -6
- package/src/core/prospective/CONTRACT.md +35 -6
- package/src/core/prospective/INTERFACE-GAPS.md +10 -5
- package/src/core/prospective/NOTES.md +175 -4
- package/src/core/prospective/derive.ts +32 -3
- package/src/core/prospective/index.ts +362 -39
- package/src/core/prospective/tunables.ts +18 -1
- package/src/core/prospective/windows.ts +104 -46
- package/src/core/recall/CONTRACT.md +28 -0
- package/src/core/recall/NOTES.md +39 -0
- package/src/core/recall/activate.ts +32 -5
- package/src/core/recall/gate.ts +7 -1
- package/src/core/recall/index.ts +19 -0
- package/src/core/recall/mood.ts +106 -0
- package/src/core/recall/tunables.ts +26 -0
- package/src/core/remember/index.ts +1 -0
- package/src/core/remember/proposals.ts +86 -3
- package/src/core/self/identity.ts +20 -1
- package/src/core/store/CONTRACT.md +9 -2
- package/src/core/store/NOTES.md +20 -0
- package/src/core/store/feelings.ts +23 -6
- package/src/core/store/index.ts +107 -10
- package/src/core/store/operational.ts +15 -1
- 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
|
-
//
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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-
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
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
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
|
3
|
-
|
|
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: "
|
|
13
|
-
built: [
|
|
14
|
-
|
|
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: "
|
|
13
|
-
built: [
|
|
14
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
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 {
|
|
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
|
-
<
|
|
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>${
|
|
30
|
+
<div>${journal.markup}
|
|
17
31
|
</div>
|
|
18
|
-
</div
|
|
32
|
+
</div>
|
|
19
33
|
`;
|
|
20
34
|
|
|
21
|
-
|
|
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) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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(
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
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 <
|
|
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
|
-
|
|
32
|
+
box.innerHTML = absenceLine(d.journalAbsent, "no chapter has been written yet");
|
|
16
33
|
return;
|
|
17
34
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
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
|
}
|