selflore 0.1.0 → 0.3.0

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -32
  3. package/dist/cli.js +81 -19
  4. package/dist/hooks/user-prompt-submit.js +2 -1
  5. package/dist/init.js +29 -11
  6. package/dist/lib/background.js +23 -4
  7. package/dist/lib/capture-prompt.js +13 -7
  8. package/dist/lib/commands.js +199 -35
  9. package/dist/lib/config.js +23 -3
  10. package/dist/lib/entries.js +56 -4
  11. package/dist/lib/heat.js +141 -0
  12. package/dist/lib/hook-logic.js +44 -9
  13. package/dist/lib/index-cache.js +46 -0
  14. package/dist/lib/links.js +58 -0
  15. package/dist/lib/logo.js +6 -0
  16. package/dist/lib/notes-graph.js +585 -0
  17. package/dist/lib/notes-html.js +149 -340
  18. package/dist/lib/notes-page-css.js +279 -0
  19. package/dist/lib/notes-page-js.js +959 -0
  20. package/dist/lib/notes.js +19 -13
  21. package/dist/lib/nudge.js +2 -1
  22. package/dist/lib/paths.js +6 -0
  23. package/dist/lib/question.js +19 -0
  24. package/dist/lib/queue.js +6 -4
  25. package/dist/lib/recall.js +149 -0
  26. package/dist/lib/results.js +1 -0
  27. package/dist/lib/retag.js +150 -0
  28. package/dist/lib/server-launch.js +73 -0
  29. package/dist/lib/server.js +120 -0
  30. package/dist/lib/session.js +1 -1
  31. package/dist/lib/signals.js +51 -0
  32. package/dist/lib/stats.js +71 -44
  33. package/dist/lib/struggle.js +120 -0
  34. package/dist/lib/surface.js +75 -0
  35. package/dist/lib/transcript.js +61 -15
  36. package/dist/lib/ui.js +127 -0
  37. package/dist/notes-server.js +39 -0
  38. package/dist/sl.js +29 -4
  39. package/dist/vendor/graph3d.js +5402 -0
  40. package/package.json +11 -4
  41. package/skill/SKILL.md +6 -5
  42. package/skill/references/capture.md +6 -5
  43. package/skill/references/recall.md +44 -0
  44. package/skill/references/stats.md +5 -1
  45. package/skill/references/test.md +35 -30
@@ -1,9 +1,25 @@
1
1
  import { readConfig } from "./config.js";
2
2
  import { listEntries, splitBody } from "./entries.js";
3
- import { entryStatus, weekStart } from "./notes.js";
3
+ import { computeHeat, hotAreas } from "./heat.js";
4
+ import { computeLinks } from "./links.js";
5
+ import { DAY_MS, readSignals, REASK_AFTER_DAYS } from "./signals.js";
6
+ import { GRAPH_CSS, GRAPH_JS } from "./notes-graph.js";
7
+ import { FAVICON, LOGO_MASK, LOGO_MASK_RATIO } from "./logo.js";
8
+ import { PAGE_CSS } from "./notes-page-css.js";
9
+ import { PAGE_JS } from "./notes-page-js.js";
10
+ import { entryStatus, weekOfDate, weekStart } from "./notes.js";
4
11
  import { readQueue } from "./queue.js";
5
12
  import { readResults, testedEntryIds } from "./results.js";
6
- export function toCard(e, tested, queue, now = new Date()) {
13
+ /** Last grade and number of answers per entry (results are in the order they were recorded). */
14
+ export function gradeHistory(results) {
15
+ const out = new Map();
16
+ for (const r of results)
17
+ out.set(r.entry_id, { last: r.grade, attempts: (out.get(r.entry_id)?.attempts ?? 0) + 1 });
18
+ return out;
19
+ }
20
+ export function toCard(e, tested, queue, history, heat) {
21
+ const h = history?.get(e.id);
22
+ const ht = heat?.get(e.id);
7
23
  const { prose, snippet } = splitBody(e.body);
8
24
  return {
9
25
  id: e.id,
@@ -12,383 +28,176 @@ export function toCard(e, tested, queue, now = new Date()) {
12
28
  kind: e.kind,
13
29
  level: e.level,
14
30
  skill: e.skill,
31
+ topics: e.topics,
32
+ origin: e.origin,
15
33
  paths: e.paths,
16
34
  commit: e.commit,
17
35
  testable: e.testable,
18
36
  prose,
19
37
  snippet: snippet ? snippet.replace(/\s+$/, "") : null,
20
38
  snippetLang: e.body.match(/```([\w+-]+)/)?.[1] ?? "",
21
- ...entryStatus(e, tested, queue, now),
39
+ ...entryStatus(e, tested, queue),
40
+ last_grade: h?.last ?? null,
41
+ attempts: h?.attempts ?? 0,
42
+ heat: ht?.heat ?? null,
43
+ heat_why: ht?.why ?? [],
44
+ };
45
+ }
46
+ export function recentActivity(signals, now, days = 30) {
47
+ const since = now.getTime() - days * DAY_MS;
48
+ const recent = signals.filter((s) => new Date(s.ts).getTime() >= since);
49
+ const firstAsk = new Map();
50
+ const count = new Map();
51
+ let reasks = 0;
52
+ for (const s of [...signals].sort((a, b) => a.ts.localeCompare(b.ts))) {
53
+ if (s.type !== "ask")
54
+ continue;
55
+ const ts = new Date(s.ts).getTime();
56
+ count.set(s.entry_id, (count.get(s.entry_id) ?? 0) + 1);
57
+ if (!firstAsk.has(s.entry_id))
58
+ firstAsk.set(s.entry_id, ts);
59
+ else if (ts >= since && ts - firstAsk.get(s.entry_id) >= REASK_AFTER_DAYS * DAY_MS)
60
+ reasks++;
61
+ }
62
+ return {
63
+ days,
64
+ asks: recent.filter((s) => s.type === "ask").length,
65
+ reasks,
66
+ loops: recent.filter((s) => s.type === "loop").length,
67
+ asked: [...count.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, 5).map(([id, n]) => ({ id, n })),
22
68
  };
23
69
  }
24
70
  export function buildNotesData(now = new Date()) {
25
71
  const config = readConfig();
26
- const tested = testedEntryIds(readResults());
72
+ const results = readResults();
73
+ const tested = testedEntryIds(results);
74
+ const history = gradeHistory(results);
27
75
  const queue = readQueue();
76
+ const entries = listEntries();
77
+ const signals = readSignals();
78
+ const heat = computeHeat({ entries, results, signals, now });
28
79
  return {
29
80
  generated_at: now.toISOString(),
30
81
  week_start: weekStart(now),
31
82
  rating: config.rating,
32
83
  keep_sharp: config.keep_sharp,
33
- entries: listEntries().map((e) => toCard(e, tested, queue, now)),
84
+ entries: entries.map((e) => toCard(e, tested, queue, history, heat)),
85
+ hot: hotAreas(entries, heat, { limit: 8 }),
86
+ activity: recentActivity(signals, now),
87
+ links: computeLinks(entries),
88
+ results: results.map((r) => ({ entry_id: r.entry_id, week: weekOfDate(r.ts), grade: r.grade, is_retest: r.is_retest })),
34
89
  };
35
90
  }
36
91
  /** JSON safe to embed in a <script> element: no "<" can close the tag early. */
37
92
  export function embedJson(data) {
38
93
  return JSON.stringify(data).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
39
94
  }
40
- const CSS = String.raw `
41
- :root {
42
- --bg: #f7f6f3; --surface: #ffffff; --surface-2: #f1efea; --text: #1c1a17; --muted: #6f6a62; --faint: #a39e95;
43
- --border: #e5e2db; --accent: #4f46e5; --accent-soft: #eef0ff; --code-bg: #f6f5f1;
44
- --bug: #c2410c; --decision: #6d28d9; --concept: #0f766e; --pattern: #a16207;
45
- --ok: #15803d; --warn: #b45309;
46
- color-scheme: light;
47
- }
48
- @media (prefers-color-scheme: dark) {
49
- :root:not([data-theme="light"]) {
50
- --bg: #0f0f10; --surface: #18181b; --surface-2: #1f1f23; --text: #f2f1ee; --muted: #a3a09a; --faint: #6b6862;
51
- --border: #2a2a2f; --accent: #a5b4fc; --accent-soft: #1e1f3a; --code-bg: #121214;
52
- --bug: #fb923c; --decision: #c4b5fd; --concept: #5eead4; --pattern: #fcd34d;
53
- --ok: #4ade80; --warn: #fbbf24;
54
- color-scheme: dark;
55
- }
56
- }
57
- * { box-sizing: border-box; }
58
- html, body { margin: 0; }
59
- body {
60
- background: var(--bg); color: var(--text);
61
- font: 15px/1.55 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
62
- -webkit-font-smoothing: antialiased;
63
- }
64
- .wrap { max-width: 880px; margin: 0 auto; padding: 40px 16px 80px; }
65
- header.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
66
- .brand { display: flex; align-items: center; gap: 12px; }
67
- .mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; color: var(--surface); font-weight: 700; font-size: 18px; }
68
- .brand h1 { font-size: 22px; letter-spacing: -0.02em; margin: 0; line-height: 1.1; }
69
- .brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
70
- .weeknav { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
71
- .weeknav button { border: 0; background: transparent; color: var(--text); font: inherit; padding: 6px 10px; border-radius: 8px; cursor: pointer; }
72
- .weeknav button:hover:not(:disabled) { background: var(--surface-2); }
73
- .weeknav button:disabled { color: var(--faint); cursor: default; }
74
- .weeknav .label { min-width: 150px; text-align: center; font-weight: 600; font-size: 14px; }
75
- .weeknav .alltime[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
76
- .tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
77
- .tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
78
- .tile .n { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
79
- .tile .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
80
- .sharp { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; color: var(--muted); font-size: 12.5px; margin-bottom: 26px; }
81
- .pill { border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; background: var(--surface); color: var(--text); font-size: 12.5px; }
82
- .filters { padding: 0 0 14px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
83
- .search { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; outline: none; }
84
- .search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
85
- .chiprows { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
86
- .chiprow { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
87
- .chiprow .k { color: var(--faint); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; width: 62px; flex-shrink: 0; }
88
- .chip { font: inherit; font-size: 12.5px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
89
- .chip:hover { border-color: var(--faint); }
90
- .chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
91
- .day { margin-top: 30px; }
92
- .day h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin: 0 0 10px; display: flex; gap: 8px; align-items: baseline; }
93
- .day h2 .c { color: var(--faint); font-weight: 500; }
94
- .card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px; margin-bottom: 12px; border-left: 4px solid var(--kind, var(--border)); }
95
- .card.suppressed { opacity: 0.6; }
96
- .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
97
- .badge { font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em; border-radius: 6px; padding: 2px 8px; }
98
- .kind { color: var(--kind); background: color-mix(in srgb, var(--kind) 12%, transparent); text-transform: capitalize; }
99
- .skill { color: var(--muted); background: var(--surface-2); font-weight: 500; }
100
- .level { color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); font-weight: 500; }
101
- .level.design { color: var(--decision); border-color: color-mix(in srgb, var(--decision) 35%, transparent); }
102
- .status.stale { color: var(--faint); font-style: italic; }
103
- .status { margin-left: auto; border: 1px solid var(--border); color: var(--muted); font-weight: 500; }
104
- .status.tested { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
105
- .status.retest { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
106
- .status.suppressed { text-decoration: line-through; }
107
- .q { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.4; margin: 12px 0 8px; }
108
- .meta { color: var(--muted); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
109
- .meta code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; color: var(--text); }
110
- details { margin-top: 14px; }
111
- summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent); padding: 6px 12px; border-radius: 8px; background: var(--accent-soft); user-select: none; }
112
- summary::-webkit-details-marker { display: none; }
113
- summary::before { content: "▸"; transition: transform 0.15s; }
114
- details[open] summary::before { transform: rotate(90deg); }
115
- details[open] summary .show { display: none; }
116
- details:not([open]) summary .hide { display: none; }
117
- .answer { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
118
- .answer p { margin: 0 0 10px; }
119
- .code { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin-top: 6px; background: var(--code-bg); }
120
- .codebar { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; border-bottom: 1px solid var(--border); font-size: 11.5px; color: var(--muted); }
121
- .copy { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 2px 8px; border-radius: 6px; cursor: pointer; }
122
- pre { margin: 0; padding: 12px 0; overflow-x: auto; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; counter-reset: ln; }
123
- pre .ln { display: block; padding: 0 14px 0 0; white-space: pre; }
124
- pre .ln::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 3em; padding-right: 1em; text-align: right; color: var(--faint); user-select: none; }
125
- .empty { text-align: center; color: var(--muted); padding: 60px 16px; border: 1px dashed var(--border); border-radius: 16px; margin-top: 24px; background: var(--surface); }
126
- .empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
127
- .empty button { margin-top: 12px; }
128
- footer { margin-top: 48px; color: var(--faint); font-size: 12px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
129
- kbd { font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); background: var(--surface); }
130
- @media (max-width: 640px) {
131
- .wrap { padding-top: 24px; }
132
- .tiles { grid-template-columns: repeat(2, 1fr); }
133
- .weeknav { width: 100%; justify-content: space-between; }
134
- .weeknav .label { min-width: 0; }
135
- .q { font-size: 16.5px; }
136
- .card { padding: 16px; }
137
- .chiprow .k { width: 100%; }
138
- }
139
- `;
140
- // Client script. Plain ES2017, no template literals, so it embeds cleanly. All entry text goes through textContent.
141
- const JS = String.raw `
142
- (function () {
143
- var DATA = JSON.parse(document.getElementById("selflore-data").textContent);
144
- var NOW = new Date();
145
- var KIND_VAR = { bug: "--bug", decision: "--decision", concept: "--concept", pattern: "--pattern" };
146
- var STATUS_LABEL = { untested: "Untested", tested: "Tested", suppressed: "Suppressed", stale: "Stale" };
147
- var LEVEL_LABEL = { detail: "Detail", design: "Design" };
148
-
149
- function pad(n) { return (n < 10 ? "0" : "") + n; }
150
- function parse(s) { var p = s.split("-"); return new Date(Date.UTC(+p[0], +p[1] - 1, +p[2])); }
151
- function iso(d) { return d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1) + "-" + pad(d.getUTCDate()); }
152
- function monday(s) { var d = parse(s); d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 6) % 7)); return iso(d); }
153
- function addDays(s, n) { var d = parse(s); d.setUTCDate(d.getUTCDate() + n); return iso(d); }
154
- function fmt(s, opts) { return parse(s).toLocaleDateString(undefined, Object.assign({ timeZone: "UTC" }, opts)); }
155
-
156
- var init = DATA.initial || {};
157
- var state = { week: DATA.week_start, all: !!init.all, project: init.project || null, level: null, skill: null, kind: null, status: null, q: "" };
158
- (location.hash.slice(1) || "").split("&").forEach(function (kv) {
159
- var p = kv.split("="); var k = decodeURIComponent(p[0] || ""); var v = p[1] ? decodeURIComponent(p[1]) : "";
160
- if (k === "all") state.all = true;
161
- else if (k === "week" && /^\d{4}-\d{2}-\d{2}$/.test(v)) state.week = monday(v);
162
- else if (["project", "level", "skill", "kind", "status"].indexOf(k) >= 0 && v) state[k] = v;
163
- });
164
- var earliest = DATA.entries.reduce(function (m, e) { var w = monday(e.date); return w < m ? w : m; }, DATA.week_start);
165
-
166
- function h(tag, attrs) {
167
- var el = document.createElement(tag);
168
- if (attrs) for (var k in attrs) {
169
- if (k === "text") el.textContent = attrs[k];
170
- else if (k === "class") el.className = attrs[k];
171
- else if (k.slice(0, 2) === "on") el.addEventListener(k.slice(2), attrs[k]);
172
- else if (attrs[k] != null) el.setAttribute(k, attrs[k]);
173
- }
174
- for (var i = 2; i < arguments.length; i++) { var c = arguments[i]; if (c != null) el.appendChild(typeof c === "string" ? document.createTextNode(c) : c); }
175
- return el;
176
- }
177
-
178
- function inScope(e) { return state.all || monday(e.date) === state.week; }
179
- function matches(e, skip) {
180
- if (skip !== "project" && state.project && e.project !== state.project) return false;
181
- if (skip !== "level" && state.level && e.level !== state.level) return false;
182
- if (skip !== "skill" && state.skill && e.skill !== state.skill) return false;
183
- if (skip !== "kind" && state.kind && e.kind !== state.kind) return false;
184
- if (skip !== "status" && state.status && e.status !== state.status) return false;
185
- if (state.q) {
186
- var hay = (e.testable + " " + e.paths.join(" ") + " " + e.project + " " + e.skill).toLowerCase();
187
- if (hay.indexOf(state.q.toLowerCase()) < 0) return false;
188
- }
189
- return true;
190
- }
191
-
192
- function statusText(e) {
193
- if (e.status !== "retest") return STATUS_LABEL[e.status];
194
- if (e.retest_due && new Date(e.retest_due) <= NOW) return "Retest due";
195
- return "Retest " + (e.retest_due ? new Date(e.retest_due).toLocaleDateString(undefined, { month: "short", day: "numeric" }) : "");
196
- }
197
-
198
- function renderNav() {
199
- var label = document.getElementById("weeklabel");
200
- label.textContent = state.all ? "Since " + fmt(earliest, { month: "short", day: "numeric" }) : (state.week === DATA.week_start ? "This week · " : "Week of ") + fmt(state.week, { month: "short", day: "numeric" });
201
- document.getElementById("prev").disabled = state.all || state.week <= earliest;
202
- document.getElementById("next").disabled = state.all || state.week >= DATA.week_start;
203
- document.getElementById("alltime").setAttribute("aria-pressed", String(state.all));
204
- }
205
-
206
- function renderTiles(scope) {
207
- var due = scope.filter(function (e) { return e.status === "retest" && e.retest_due && new Date(e.retest_due) <= NOW; }).length;
208
- var tiles = [
209
- [scope.length, state.all ? "Entries captured" : "Captured this week"],
210
- [scope.filter(function (e) { return e.status === "untested"; }).length, "Untested"],
211
- [scope.filter(function (e) { return e.status === "retest"; }).length, due ? "In retest queue · " + due + " due" : "In retest queue"],
212
- [scope.filter(function (e) { return e.status === "tested"; }).length, "Tested & solid"],
213
- ];
214
- var el = document.getElementById("tiles"); el.textContent = "";
215
- tiles.forEach(function (t) { el.appendChild(h("div", { class: "tile" }, h("div", { class: "n", text: String(t[0]) }), h("div", { class: "l", text: t[1] }))); });
216
- }
217
-
218
- function chipRow(key, label, scope, labeler) {
219
- var values = {};
220
- scope.filter(function (e) { return matches(e, key); }).forEach(function (e) { var v = e[key]; if (v) values[v] = (values[v] || 0) + 1; });
221
- if (state[key] && !values[state[key]]) values[state[key]] = 0;
222
- var keys = Object.keys(values).sort();
223
- if (keys.length < 2 && !state[key]) return null;
224
- var row = h("div", { class: "chiprow" }, h("span", { class: "k", text: label }));
225
- row.appendChild(h("button", { class: "chip", "aria-pressed": String(!state[key]), onclick: function () { state[key] = null; render(); }, text: "All" }));
226
- keys.forEach(function (v) {
227
- row.appendChild(h("button", {
228
- class: "chip", "aria-pressed": String(state[key] === v),
229
- onclick: function () { state[key] = state[key] === v ? null : v; render(); },
230
- text: (labeler ? labeler(v) : v) + " · " + values[v],
231
- }));
232
- });
233
- return row;
234
- }
235
-
236
- function renderChips(scope) {
237
- var el = document.getElementById("chips"); el.textContent = "";
238
- [chipRow("project", "Project", scope),
239
- chipRow("level", "Level", scope, function (v) { return LEVEL_LABEL[v] || v; }),
240
- chipRow("skill", "Skill", scope),
241
- chipRow("kind", "Kind", scope, function (v) { return v.charAt(0).toUpperCase() + v.slice(1); }),
242
- chipRow("status", "Status", scope, function (v) { return v === "retest" ? "Retest" : STATUS_LABEL[v]; })]
243
- .forEach(function (r) { if (r) el.appendChild(r); });
244
- }
245
-
246
- function codeBlock(e) {
247
- var pre = h("pre");
248
- e.snippet.split("\n").forEach(function (line) { pre.appendChild(h("span", { class: "ln", text: line || " " })); });
249
- var copy = h("button", { class: "copy", text: "Copy", onclick: function () {
250
- (navigator.clipboard ? navigator.clipboard.writeText(e.snippet) : Promise.reject()).then(
251
- function () { copy.textContent = "Copied"; setTimeout(function () { copy.textContent = "Copy"; }, 1200); },
252
- function () { copy.textContent = "Select & copy"; });
253
- } });
254
- var lines = e.snippet.split("\n").length;
255
- var info = [e.snippetLang, lines + (lines === 1 ? " line" : " lines"), e.commit ? "@ " + e.commit : ""].filter(Boolean).join(" · ");
256
- return h("div", { class: "code" }, h("div", { class: "codebar" }, h("span", { text: info }), copy), pre);
257
- }
258
-
259
- function card(e) {
260
- var c = h("article", { class: "card" + (e.status === "suppressed" ? " suppressed" : ""), id: e.id });
261
- c.style.setProperty("--kind", "var(" + (KIND_VAR[e.kind] || "--border") + ")");
262
- c.appendChild(h("div", { class: "row" },
263
- h("span", { class: "badge kind", text: e.kind }),
264
- h("span", { class: "badge level " + e.level, text: LEVEL_LABEL[e.level] || e.level }),
265
- h("span", { class: "badge skill", text: e.skill }),
266
- h("span", { class: "badge status " + e.status, text: statusText(e) })));
267
- c.appendChild(h("div", { class: "q", text: e.testable }));
268
- var meta = h("div", { class: "meta" });
269
- if (e.project) meta.appendChild(h("span", { text: e.project }));
270
- e.paths.forEach(function (p) { meta.appendChild(h("code", { text: p })); });
271
- c.appendChild(meta);
272
- var answer = h("div", { class: "answer" });
273
- e.prose.split(/\n\s*\n/).forEach(function (para) { if (para.trim()) answer.appendChild(h("p", { text: para.replace(/\s*\n\s*/g, " ").trim() })); });
274
- if (e.snippet) answer.appendChild(codeBlock(e));
275
- c.appendChild(h("details", null,
276
- h("summary", null, h("span", { class: "show", text: "Show answer" }), h("span", { class: "hide", text: "Hide answer" })),
277
- answer));
278
- return c;
279
- }
280
-
281
- function renderList(scope) {
282
- var list = document.getElementById("list"); list.textContent = "";
283
- var shown = scope.filter(function (e) { return matches(e); });
284
- if (DATA.entries.length === 0) {
285
- list.appendChild(h("div", { class: "empty" }, h("strong", { text: "Nothing captured yet" }), "Work normally in Claude Code. Lore-worthy moments land here as they happen."));
286
- return;
287
- }
288
- if (shown.length === 0) {
289
- var filtered = state.project || state.level || state.skill || state.kind || state.status || state.q;
290
- list.appendChild(h("div", { class: "empty" },
291
- h("strong", { text: filtered ? "No entries match these filters" : "Nothing captured this week" }),
292
- filtered ? null : "Try another week or switch to All time.",
293
- filtered ? h("button", { class: "chip", text: "Clear filters", onclick: function () {
294
- state.project = state.level = state.skill = state.kind = state.status = null; state.q = ""; document.getElementById("search").value = ""; render();
295
- } }) : null));
296
- return;
297
- }
298
- var days = {};
299
- shown.forEach(function (e) { (days[e.date] = days[e.date] || []).push(e); });
300
- Object.keys(days).sort().reverse().forEach(function (d) {
301
- var sec = h("section", { class: "day" }, h("h2", null, fmt(d, { weekday: "long", month: "short", day: "numeric" }), h("span", { class: "c", text: String(days[d].length) })));
302
- days[d].sort(function (a, b) { return a.id < b.id ? -1 : 1; }).forEach(function (e) { sec.appendChild(card(e)); });
303
- list.appendChild(sec);
304
- });
305
- }
306
-
307
- function syncHash() {
308
- var parts = [];
309
- if (state.all) parts.push("all"); else if (state.week !== DATA.week_start) parts.push("week=" + state.week);
310
- ["project", "level", "skill", "kind", "status"].forEach(function (k) { if (state[k]) parts.push(k + "=" + encodeURIComponent(state[k])); });
311
- history.replaceState(null, "", parts.length ? "#" + parts.join("&") : location.pathname);
312
- }
313
-
314
- function render() {
315
- var scope = DATA.entries.filter(inScope);
316
- renderNav(); renderTiles(scope); renderChips(scope); renderList(scope); syncHash();
317
- }
318
-
319
- document.getElementById("prev").onclick = function () { state.week = addDays(state.week, -7); render(); };
320
- document.getElementById("next").onclick = function () { state.week = addDays(state.week, 7); render(); };
321
- document.getElementById("alltime").onclick = function () { state.all = !state.all; render(); };
322
- var search = document.getElementById("search");
323
- search.addEventListener("input", function () { state.q = search.value.trim(); render(); });
324
-
325
- var sharp = document.getElementById("sharp");
326
- if (DATA.keep_sharp.length) {
327
- sharp.appendChild(document.createTextNode("Keeping sharp:"));
328
- DATA.keep_sharp.forEach(function (k) { sharp.appendChild(h("span", { class: "pill", text: k })); });
329
- sharp.appendChild(document.createTextNode("· self-rating " + DATA.rating + "/10"));
330
- }
331
- document.getElementById("generated").textContent = "Generated " + new Date(DATA.generated_at).toLocaleString();
332
-
333
- document.addEventListener("keydown", function (ev) {
334
- if (ev.target && (ev.target.tagName === "INPUT" || ev.target.tagName === "TEXTAREA") ) {
335
- if (ev.key === "Escape") ev.target.blur();
336
- return;
337
- }
338
- if (ev.metaKey || ev.ctrlKey || ev.altKey) return;
339
- if (ev.key === "/") { ev.preventDefault(); search.focus(); }
340
- else if (ev.key === "a") {
341
- var all = Array.prototype.slice.call(document.querySelectorAll("#list details"));
342
- var open = all.some(function (d) { return !d.open; });
343
- all.forEach(function (d) { d.open = open; });
344
- }
345
- else if (ev.key === "ArrowLeft" && !document.getElementById("prev").disabled) document.getElementById("prev").click();
346
- else if (ev.key === "ArrowRight" && !document.getElementById("next").disabled) document.getElementById("next").click();
347
- });
348
-
349
- render();
350
- })();
351
- `;
352
- const FAVICON = "data:image/svg+xml," +
353
- encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="8" fill="#4f46e5"/><text x="16" y="22" font-family="system-ui,sans-serif" font-size="18" font-weight="700" text-anchor="middle" fill="#fff">s</text></svg>');
95
+ // Icons are drawn, one stroke weight, and inherit the text colour.
96
+ const svg = (d) => `<svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><path d="${d}"/></svg>`;
97
+ const ICON = {
98
+ left: svg("M10 3L5 8l5 5"),
99
+ right: svg("M6 3l5 5-5 5"),
100
+ plus: svg("M8 3v10M3 8h10"),
101
+ minus: svg("M3 8h10"),
102
+ fit: svg("M3 6V3h3M10 3h3v3M13 10v3h-3M6 13H3v-3"),
103
+ };
354
104
  export function renderNotesHtml(data) {
355
105
  return `<!doctype html>
356
106
  <html lang="en">
357
107
  <head>
358
108
  <meta charset="utf-8">
359
109
  <meta name="viewport" content="width=device-width, initial-scale=1">
360
- <title>selflore notes</title>
361
- <link rel="icon" href="${FAVICON}">
362
- <style>${CSS}</style>
110
+ <title>selflore</title>
111
+ <link rel="icon" type="image/png" href="${FAVICON}">
112
+ <style>:root { --logo: url("${LOGO_MASK}"); --logo-ratio: ${LOGO_MASK_RATIO}; }
113
+ ${PAGE_CSS}${GRAPH_CSS}</style>
363
114
  </head>
364
115
  <body>
365
116
  <div class="wrap">
366
117
  <header class="top">
367
- <div class="brand">
368
- <div class="mark" aria-hidden="true">s</div>
369
- <div><h1>selflore</h1><p>What your agent built for you, and what you should own.</p></div>
118
+ <div class="brand"><span class="mark" aria-hidden="true"></span><h1>selflore</h1></div>
119
+ <div class="seg" id="viewseg" role="group" aria-label="View">
120
+ <button data-view="graph" aria-pressed="true">Map</button>
121
+ <button data-view="list" aria-pressed="false">Notes</button>
122
+ <button data-view="stats" aria-pressed="false">Stats</button>
370
123
  </div>
371
- <nav class="weeknav" aria-label="Week">
372
- <button id="prev" aria-label="Previous week">‹</button>
373
- <span class="label" id="weeklabel"></span>
374
- <button id="next" aria-label="Next week">›</button>
375
- <button id="alltime" class="alltime" aria-pressed="false">All time</button>
376
- </nav>
124
+ <span class="spacer"></span>
125
+ <button id="testbtn" class="btn primary" hidden title="Up to 10 questions: what you missed last time, then the notes where you get stuck">Test me</button>
377
126
  </header>
378
- <section class="tiles" id="tiles" aria-label="Summary"></section>
379
- <div class="sharp" id="sharp"></div>
380
- <div class="filters">
381
- <input id="search" class="search" type="search" placeholder="Search questions, files, projects… ( / )" autocomplete="off">
382
- <div class="chiprows" id="chips"></div>
127
+ <div id="notesview">
128
+ <div class="statline">
129
+ <span id="facts"></span>
130
+ <span class="active" id="active"></span>
131
+ <div class="range">
132
+ <button id="prev" class="btn quiet icon" aria-label="Previous week" hidden>${ICON.left}</button>
133
+ <span class="wk" id="weeklabel" hidden></span>
134
+ <button id="next" class="btn quiet icon" aria-label="Next week" hidden>${ICON.right}</button>
135
+ <div class="seg" id="rangeseg" role="group" aria-label="Time range">
136
+ <button data-range="all" aria-pressed="true">All time</button>
137
+ <button data-range="week" aria-pressed="false">By week</button>
138
+ </div>
139
+ </div>
140
+ </div>
141
+ <section id="graphview" class="map" aria-label="Map of your notes">
142
+ <div class="gwrap" id="gwrap">
143
+ <canvas id="gcanvas" role="img" aria-label="Your notes as a heat map, grouped into clusters. Dots run from dim slate where things are settled, through amber, to red where you get stuck; a hollow grey dot has no signal yet. The Notes tab has the same notes as text."></canvas>
144
+ <div class="g3d" id="g3d" hidden></div>
145
+ <div class="gctl tl">
146
+ <div class="seg" id="groupseg" role="group" aria-label="Group by">
147
+ <button data-group="project" aria-pressed="true" title="Group by project">Project</button>
148
+ <button data-group="skill" aria-pressed="false" title="Group by topic">Topic</button>
149
+ <button data-group="kind" aria-pressed="false" title="Group by kind of note">Kind</button>
150
+ </div>
151
+ </div>
152
+ <div class="gctl tr">
153
+ <div class="seg" id="dimseg" role="group" aria-label="Graph view" hidden>
154
+ <button data-dim="3d" aria-pressed="true" title="Drag to rotate, pinch or ⌘ + scroll to zoom, click a dot to open it">3D</button>
155
+ <button data-dim="2d" aria-pressed="false" title="The flat view: easier for reading names and picking out one note">Flat</button>
156
+ </div>
157
+ <button class="chip" id="glabels" aria-pressed="true" title="Hide the names to get a picture with no project text in it">Labels</button>
158
+ </div>
159
+ <div class="ghint" id="ghint"></div>
160
+ <div class="gempty" id="gempty" hidden>No notes match. Remove a filter or switch to All time.</div>
161
+ <div class="gctl bl">
162
+ <div class="legend" aria-label="Dot colour is heat">
163
+ <span>Settled</span><span class="heatbar" id="heatbar" aria-hidden="true"></span><span>Stuck</span>
164
+ <span><i class="hdot none" aria-hidden="true"></i>No signal yet</span>
165
+ <span><i class="hring" aria-hidden="true"></i><span id="lgroup">A project</span></span>
166
+ </div>
167
+ <div class="gcap" id="gcap"></div>
168
+ </div>
169
+ <div class="gctl br">
170
+ <button id="gzoomin" class="btn icon" aria-label="Zoom in" title="Zoom in (or pinch, or ⌘ + scroll)">${ICON.plus}</button>
171
+ <button id="gzoomout" class="btn icon" aria-label="Zoom out" title="Zoom out">${ICON.minus}</button>
172
+ <button id="gzoomfit" class="btn icon" aria-label="Fit to view" title="Fit to view">${ICON.fit}</button>
173
+ </div>
174
+ <aside class="gpanel" id="gpanel" hidden></aside>
175
+ </div>
176
+ <aside class="rail" id="rail" aria-label="Where you get stuck"></aside>
177
+ </section>
178
+ <section id="listview" class="col" hidden aria-label="Notes">
179
+ <div class="toolbar">
180
+ <input id="search" class="search" type="search" placeholder="Search questions, files, projects" aria-label="Search notes" autocomplete="off">
181
+ <button id="filterbtn" class="btn" aria-expanded="false" aria-controls="filters">Filters</button>
182
+ <div class="seg" id="sortseg" role="group" aria-label="Order">
183
+ <button data-sort="new" aria-pressed="true">Newest</button>
184
+ <button data-sort="stuck" aria-pressed="false">Stuck first</button>
185
+ </div>
186
+ </div>
187
+ <div class="fpanel" id="filters" hidden></div>
188
+ <div id="selrow"></div>
189
+ <main id="list"></main>
190
+ </section>
191
+ <section id="statsview" class="stats" hidden aria-label="Stats"></section>
383
192
  </div>
384
- <main id="list"></main>
193
+ <div id="testview" class="col" hidden></div>
385
194
  <footer>
386
- <span id="generated"></span>
387
- <span><kbd>a</kbd> reveal all · <kbd>←</kbd><kbd>→</kbd> weeks · <kbd>/</kbd> search · run <code>/selflore test</code> in Claude Code to be quizzed</span>
195
+ <span>What your agent built for you, and what you should own. <span id="generated"></span></span>
196
+ <span><kbd>g</kbd> map or notes · <kbd>/</kbd> search · <kbd>a</kbd> open all · <span id="testhint">run <code>/selflore test</code> in Claude Code to be quizzed</span></span>
388
197
  </footer>
389
198
  </div>
390
199
  <script type="application/json" id="selflore-data">${embedJson(data)}</script>
391
- <script>${JS}</script>
200
+ <script>${GRAPH_JS}${PAGE_JS}</script>
392
201
  </body>
393
202
  </html>
394
203
  `;