selflore 0.0.1 → 0.1.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.
@@ -0,0 +1,47 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { paths, selfloreHome } from "./paths.js";
5
+ import { installHooks, uninstallHooks } from "./settings.js";
6
+ /** Package root (contains dist/ and skill/), resolved from this compiled file at dist/lib/install.js. */
7
+ export function packageRoot() {
8
+ return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
9
+ }
10
+ function copyDir(src, dest, transform) {
11
+ fs.mkdirSync(dest, { recursive: true });
12
+ for (const name of fs.readdirSync(src)) {
13
+ const from = path.join(src, name);
14
+ const to = path.join(dest, name);
15
+ if (fs.statSync(from).isDirectory())
16
+ copyDir(from, to, transform);
17
+ else if (transform && name.endsWith(".md"))
18
+ fs.writeFileSync(to, transform(from, fs.readFileSync(from, "utf8")));
19
+ else
20
+ fs.copyFileSync(from, to);
21
+ }
22
+ }
23
+ export function slCommand() {
24
+ return `node "${path.join(paths.app(), "sl.js")}"`;
25
+ }
26
+ /** Copy the runtime and skill into place and merge hooks. Safe to re-run (upgrades in place). */
27
+ export function installFiles(root = packageRoot()) {
28
+ fs.mkdirSync(paths.entries(), { recursive: true });
29
+ fs.mkdirSync(paths.state(), { recursive: true });
30
+ // Runtime: a self-contained copy so hooks never depend on the npx cache.
31
+ fs.rmSync(paths.app(), { recursive: true, force: true });
32
+ copyDir(path.join(root, "dist"), paths.app());
33
+ fs.writeFileSync(path.join(paths.app(), "package.json"), JSON.stringify({ type: "module", private: true }) + "\n");
34
+ // Skill: templated with the real sl path so SELFLORE_HOME overrides keep working.
35
+ fs.rmSync(paths.skill(), { recursive: true, force: true });
36
+ copyDir(path.join(root, "skill"), paths.skill(), (_f, text) => text.replaceAll("{{SL}}", slCommand()));
37
+ installHooks();
38
+ }
39
+ export function removeFiles(purge) {
40
+ uninstallHooks();
41
+ fs.rmSync(paths.skill(), { recursive: true, force: true });
42
+ if (purge)
43
+ fs.rmSync(selfloreHome(), { recursive: true, force: true });
44
+ // Session state is data: keeping it means a remove + init doesn't re-trigger capture for old sessions.
45
+ else
46
+ fs.rmSync(paths.app(), { recursive: true, force: true });
47
+ }
@@ -0,0 +1,395 @@
1
+ import { readConfig } from "./config.js";
2
+ import { listEntries, splitBody } from "./entries.js";
3
+ import { entryStatus, weekStart } from "./notes.js";
4
+ import { readQueue } from "./queue.js";
5
+ import { readResults, testedEntryIds } from "./results.js";
6
+ export function toCard(e, tested, queue, now = new Date()) {
7
+ const { prose, snippet } = splitBody(e.body);
8
+ return {
9
+ id: e.id,
10
+ date: e.date,
11
+ project: e.project,
12
+ kind: e.kind,
13
+ level: e.level,
14
+ skill: e.skill,
15
+ paths: e.paths,
16
+ commit: e.commit,
17
+ testable: e.testable,
18
+ prose,
19
+ snippet: snippet ? snippet.replace(/\s+$/, "") : null,
20
+ snippetLang: e.body.match(/```([\w+-]+)/)?.[1] ?? "",
21
+ ...entryStatus(e, tested, queue, now),
22
+ };
23
+ }
24
+ export function buildNotesData(now = new Date()) {
25
+ const config = readConfig();
26
+ const tested = testedEntryIds(readResults());
27
+ const queue = readQueue();
28
+ return {
29
+ generated_at: now.toISOString(),
30
+ week_start: weekStart(now),
31
+ rating: config.rating,
32
+ keep_sharp: config.keep_sharp,
33
+ entries: listEntries().map((e) => toCard(e, tested, queue, now)),
34
+ };
35
+ }
36
+ /** JSON safe to embed in a <script> element: no "<" can close the tag early. */
37
+ export function embedJson(data) {
38
+ return JSON.stringify(data).replace(/</g, "\\u003c").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
39
+ }
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>');
354
+ export function renderNotesHtml(data) {
355
+ return `<!doctype html>
356
+ <html lang="en">
357
+ <head>
358
+ <meta charset="utf-8">
359
+ <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>
363
+ </head>
364
+ <body>
365
+ <div class="wrap">
366
+ <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>
370
+ </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>
377
+ </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>
383
+ </div>
384
+ <main id="list"></main>
385
+ <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>
388
+ </footer>
389
+ </div>
390
+ <script type="application/json" id="selflore-data">${embedJson(data)}</script>
391
+ <script>${JS}</script>
392
+ </body>
393
+ </html>
394
+ `;
395
+ }
@@ -0,0 +1,63 @@
1
+ import { splitBody } from "./entries.js";
2
+ const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
3
+ function localDate(d) {
4
+ const pad = (n) => String(n).padStart(2, "0");
5
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
6
+ }
7
+ /** Local Monday of the week containing `now`, as YYYY-MM-DD. */
8
+ export function weekStart(now) {
9
+ const d = new Date(now.getFullYear(), now.getMonth(), now.getDate());
10
+ d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
11
+ return localDate(d);
12
+ }
13
+ /** Untested entries older than this leave the quiz pool (they stay visible in notes as "stale"). */
14
+ export const STALE_AFTER_DAYS = 21;
15
+ export function staleBefore(now) {
16
+ return localDate(new Date(now.getTime() - STALE_AFTER_DAYS * 86_400_000));
17
+ }
18
+ export function entryStatus(e, tested, queue, now = new Date()) {
19
+ if (e.suppressed)
20
+ return { status: "suppressed", retest_due: null };
21
+ if (queue[e.id])
22
+ return { status: "retest", retest_due: queue[e.id].due[0] ?? null };
23
+ if (tested.has(e.id))
24
+ return { status: "tested", retest_due: null };
25
+ return { status: e.date < staleBefore(now) ? "stale" : "untested", retest_due: null };
26
+ }
27
+ function status(e, tested, queue, now) {
28
+ const s = entryStatus(e, tested, queue, now);
29
+ return s.status === "retest" ? `retest ${s.retest_due?.slice(0, 10) ?? ""}`.trim() : s.status;
30
+ }
31
+ /** Plain-text list of captured entries, grouped by day. Defaults to the current week. */
32
+ export function renderNotes({ entries, tested, queue, now, all, project }) {
33
+ const since = weekStart(now);
34
+ let list = entries;
35
+ if (!all)
36
+ list = list.filter((e) => e.date >= since);
37
+ if (project)
38
+ list = list.filter((e) => e.project === project);
39
+ const scope = `${all ? "all time" : `week of ${since}`}${project ? ` · ${project}` : ""}`;
40
+ if (list.length === 0)
41
+ return `selflore notes — ${scope}\n\nNothing captured yet. Work normally; entries appear as you go.`;
42
+ const out = [`selflore notes — ${scope} (${list.length} ${list.length === 1 ? "entry" : "entries"})`];
43
+ let day = "";
44
+ for (const e of [...list].sort((a, b) => a.id.localeCompare(b.id))) {
45
+ if (e.date !== day) {
46
+ day = e.date;
47
+ out.push("", `${DAYS[new Date(`${e.date}T12:00:00`).getDay()]} ${e.date}`);
48
+ }
49
+ const { prose, snippet } = splitBody(e.body);
50
+ const where = [e.project, e.paths.join(", ")].filter(Boolean).join(" · ");
51
+ out.push(` • [${e.kind} · ${e.level} · ${e.skill}] ${where} (${status(e, tested, queue, now)})`);
52
+ out.push(` Q: ${e.testable}`);
53
+ for (const line of prose.split("\n"))
54
+ if (line.trim())
55
+ out.push(` ${line.trim()}`);
56
+ if (snippet) {
57
+ const lines = snippet.trimEnd().split("\n").length;
58
+ out.push(` + ${lines}-line snippet${e.commit ? ` @ ${e.commit}` : ""}`);
59
+ }
60
+ out.push(` id: ${e.id}`);
61
+ }
62
+ return out.join("\n");
63
+ }
@@ -0,0 +1,22 @@
1
+ const WEEK = 7 * 24 * 60 * 60 * 1000;
2
+ const CAPTURE_LINE = {
3
+ background: "selflore capture=background: lore is captured automatically after turns. Do not log selflore entries yourself unless the user runs /selflore log.",
4
+ quiet: "selflore capture=quiet: you may get a selflore hint with a prompt; act on it only at a natural pause.",
5
+ off: "selflore capture=off: only log entries when the user runs /selflore log.",
6
+ };
7
+ /** Overdue = there is material and a week has passed since the last test (or since the first entry, before any test). */
8
+ export function testOverdue(config, oldestEntryDate, now) {
9
+ if (!oldestEntryDate)
10
+ return false;
11
+ const since = config.last_test_at ?? `${oldestEntryDate}T00:00:00`;
12
+ return now.getTime() - new Date(since).getTime() > WEEK;
13
+ }
14
+ export function sessionStartContext(sessionId, config, oldestEntryDate, now) {
15
+ const lines = [];
16
+ if (sessionId)
17
+ lines.push(`selflore session_id=${sessionId}`);
18
+ lines.push(CAPTURE_LINE[config.capture]);
19
+ if (config.nudge && testOverdue(config, oldestEntryDate, now))
20
+ lines.push("selflore: weekly test overdue — mention once that the user can run /selflore test (~20 min).");
21
+ return lines.join("\n");
22
+ }
@@ -0,0 +1,20 @@
1
+ import { spawn } from "node:child_process";
2
+ /** Open a file in the default browser. Returns false if skipped or the opener couldn't start. */
3
+ export function openInBrowser(file) {
4
+ if (process.env.SELFLORE_NO_OPEN)
5
+ return false;
6
+ const [cmd, args] = process.platform === "darwin"
7
+ ? ["open", [file]]
8
+ : process.platform === "win32"
9
+ ? ["cmd", ["/c", "start", "", file]]
10
+ : ["xdg-open", [file]];
11
+ try {
12
+ const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
13
+ child.on("error", () => { });
14
+ child.unref();
15
+ return true;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ // Resolved at call time so tests (and power users) can override via env.
4
+ export function selfloreHome() {
5
+ return process.env.SELFLORE_HOME ?? path.join(os.homedir(), ".selflore");
6
+ }
7
+ export function claudeHome() {
8
+ return process.env.CLAUDE_HOME ?? path.join(os.homedir(), ".claude");
9
+ }
10
+ export const paths = {
11
+ config: () => path.join(selfloreHome(), "config.json"),
12
+ entries: () => path.join(selfloreHome(), "entries"),
13
+ results: () => path.join(selfloreHome(), "results.jsonl"),
14
+ queue: () => path.join(selfloreHome(), "queue.json"),
15
+ state: () => path.join(selfloreHome(), "state"),
16
+ app: () => path.join(selfloreHome(), "app"),
17
+ notesHtml: () => path.join(selfloreHome(), "notes.html"),
18
+ skill: () => path.join(claudeHome(), "skills", "selflore"),
19
+ settings: () => path.join(claudeHome(), "settings.json"),
20
+ };
@@ -0,0 +1,48 @@
1
+ import { readJson, writeJson } from "./fsutil.js";
2
+ import { paths } from "./paths.js";
3
+ export const RETEST_OFFSETS_DAYS = [7, 21];
4
+ export const PASSES_TO_RETIRE = 2;
5
+ const DAY = 24 * 60 * 60 * 1000;
6
+ export function schedule(now) {
7
+ return RETEST_OFFSETS_DAYS.map((d) => new Date(now.getTime() + d * DAY).toISOString());
8
+ }
9
+ /**
10
+ * Apply one graded answer to the queue (pure).
11
+ * - miss/partial: (re)enter the queue with fresh +7d/+21d dates and streak 0.
12
+ * - pass on a queued item: streak++, consume the earliest due date; retire at 2 consecutive passes.
13
+ * - pass on an item not in the queue: nothing to do.
14
+ */
15
+ export function applyGrade(queue, entryId, grade, now) {
16
+ const next = { ...queue };
17
+ const item = next[entryId];
18
+ if (grade !== "got") {
19
+ next[entryId] = { entry_id: entryId, due: schedule(now), streak: 0, added_at: item?.added_at ?? now.toISOString() };
20
+ return next;
21
+ }
22
+ if (!item)
23
+ return next;
24
+ const streak = item.streak + 1;
25
+ if (streak >= PASSES_TO_RETIRE) {
26
+ delete next[entryId];
27
+ return next;
28
+ }
29
+ // Keep at least one future date so the item comes back for its second pass.
30
+ const remaining = item.due.slice(1);
31
+ next[entryId] = {
32
+ ...item,
33
+ streak,
34
+ due: remaining.length ? remaining : [new Date(now.getTime() + RETEST_OFFSETS_DAYS[0] * DAY).toISOString()],
35
+ };
36
+ return next;
37
+ }
38
+ export function dueItems(queue, now) {
39
+ return Object.values(queue)
40
+ .filter((q) => q.due.length > 0 && new Date(q.due[0]).getTime() <= now.getTime())
41
+ .sort((a, b) => a.due[0].localeCompare(b.due[0]));
42
+ }
43
+ export function readQueue() {
44
+ return readJson(paths.queue(), {});
45
+ }
46
+ export function writeQueue(q) {
47
+ writeJson(paths.queue(), q);
48
+ }