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.
- package/LICENSE +21 -0
- package/README.md +90 -32
- package/dist/cli.js +81 -19
- package/dist/hooks/user-prompt-submit.js +2 -1
- package/dist/init.js +29 -11
- package/dist/lib/background.js +23 -4
- package/dist/lib/capture-prompt.js +13 -7
- package/dist/lib/commands.js +199 -35
- package/dist/lib/config.js +23 -3
- package/dist/lib/entries.js +56 -4
- package/dist/lib/heat.js +141 -0
- package/dist/lib/hook-logic.js +44 -9
- package/dist/lib/index-cache.js +46 -0
- package/dist/lib/links.js +58 -0
- package/dist/lib/logo.js +6 -0
- package/dist/lib/notes-graph.js +585 -0
- package/dist/lib/notes-html.js +149 -340
- package/dist/lib/notes-page-css.js +279 -0
- package/dist/lib/notes-page-js.js +959 -0
- package/dist/lib/notes.js +19 -13
- package/dist/lib/nudge.js +2 -1
- package/dist/lib/paths.js +6 -0
- package/dist/lib/question.js +19 -0
- package/dist/lib/queue.js +6 -4
- package/dist/lib/recall.js +149 -0
- package/dist/lib/results.js +1 -0
- package/dist/lib/retag.js +150 -0
- package/dist/lib/server-launch.js +73 -0
- package/dist/lib/server.js +120 -0
- package/dist/lib/session.js +1 -1
- package/dist/lib/signals.js +51 -0
- package/dist/lib/stats.js +71 -44
- package/dist/lib/struggle.js +120 -0
- package/dist/lib/surface.js +75 -0
- package/dist/lib/transcript.js +61 -15
- package/dist/lib/ui.js +127 -0
- package/dist/notes-server.js +39 -0
- package/dist/sl.js +29 -4
- package/dist/vendor/graph3d.js +5402 -0
- package/package.json +11 -4
- package/skill/SKILL.md +6 -5
- package/skill/references/capture.md +6 -5
- package/skill/references/recall.md +44 -0
- package/skill/references/stats.md +5 -1
- package/skill/references/test.md +35 -30
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
// The notes page's script. Plain ES2017 with no template literals, so it embeds cleanly in the
|
|
2
|
+
// page. All note text reaches the DOM through textContent. It runs after GRAPH_JS, which defines
|
|
3
|
+
// selfloreHeat, selfloreGraphPanel and selfloreGraph.
|
|
4
|
+
export const PAGE_JS = String.raw `
|
|
5
|
+
(function () {
|
|
6
|
+
var DATA = JSON.parse(document.getElementById("selflore-data").textContent);
|
|
7
|
+
var NOW = new Date();
|
|
8
|
+
var HEAT = selfloreHeat;
|
|
9
|
+
var STATUS_LABEL = { untested: "Untested", tested: "Tested", suppressed: "Suppressed", retest: "To revisit" };
|
|
10
|
+
var LEVEL_LABEL = { detail: "Detail", design: "Design" };
|
|
11
|
+
var KIND_LABEL = { bug: "Bug", decision: "Decision", concept: "Concept", pattern: "Pattern" };
|
|
12
|
+
var GRADE_LABEL = { got: "Got it", partial: "Partial", missed: "Missed" };
|
|
13
|
+
var VIEWS = ["graph", "list", "stats"];
|
|
14
|
+
var GROUPS = ["project", "skill", "kind"];
|
|
15
|
+
var FILTER_KEYS = ["project", "level", "skill", "kind", "status"];
|
|
16
|
+
var TICK = String.fromCharCode(96);
|
|
17
|
+
var ICONS = {
|
|
18
|
+
x: "M4 4l8 8M12 4l-8 8", left: "M10 3L5 8l5 5", right: "M6 3l5 5-5 5", down: "M3.5 6l4.5 4.5L12.5 6",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function $(id) { return document.getElementById(id); }
|
|
22
|
+
function each(sel, fn) { Array.prototype.forEach.call(document.querySelectorAll(sel), fn); }
|
|
23
|
+
function pad(n) { return (n < 10 ? "0" : "") + n; }
|
|
24
|
+
function parse(s) { var p = s.split("-"); return new Date(Date.UTC(+p[0], +p[1] - 1, +p[2])); }
|
|
25
|
+
function iso(d) { return d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1) + "-" + pad(d.getUTCDate()); }
|
|
26
|
+
function monday(s) { var d = parse(s); d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 6) % 7)); return iso(d); }
|
|
27
|
+
function addDays(s, n) { var d = parse(s); d.setUTCDate(d.getUTCDate() + n); return iso(d); }
|
|
28
|
+
function fmt(s, opts) { return parse(s).toLocaleDateString(undefined, Object.assign({ timeZone: "UTC" }, opts)); }
|
|
29
|
+
function shortDate(s) { return fmt(s, { month: "short", day: "numeric" }); }
|
|
30
|
+
function plural(n, one, many) { return n + " " + (n === 1 ? one : many); }
|
|
31
|
+
|
|
32
|
+
function h(tag, attrs) {
|
|
33
|
+
var el = document.createElement(tag);
|
|
34
|
+
if (attrs) for (var k in attrs) {
|
|
35
|
+
if (k === "text") el.textContent = attrs[k];
|
|
36
|
+
else if (k === "class") el.className = attrs[k];
|
|
37
|
+
else if (k.slice(0, 2) === "on") el.addEventListener(k.slice(2), attrs[k]);
|
|
38
|
+
else if (attrs[k] != null) el.setAttribute(k, attrs[k]);
|
|
39
|
+
}
|
|
40
|
+
for (var i = 2; i < arguments.length; i++) { var c = arguments[i]; if (c != null) el.appendChild(typeof c === "string" ? document.createTextNode(c) : c); }
|
|
41
|
+
return el;
|
|
42
|
+
}
|
|
43
|
+
// Icons are fixed strings from the table above, never note text, so parsing them as markup is safe.
|
|
44
|
+
function icon(name) {
|
|
45
|
+
var t = document.createElement("template");
|
|
46
|
+
t.innerHTML = '<svg class="ic" viewBox="0 0 16 16" aria-hidden="true"><path d="' + ICONS[name] + '"/></svg>';
|
|
47
|
+
return t.content.firstChild;
|
|
48
|
+
}
|
|
49
|
+
/** Fill an element with text, turning backtick-quoted parts into inline code. Text nodes only. */
|
|
50
|
+
function rich(el, text) {
|
|
51
|
+
String(text).split(TICK).forEach(function (part, i) {
|
|
52
|
+
if (!part) return;
|
|
53
|
+
el.appendChild(i % 2 ? h("code", { text: part }) : document.createTextNode(part));
|
|
54
|
+
});
|
|
55
|
+
return el;
|
|
56
|
+
}
|
|
57
|
+
function facts(el, parts) {
|
|
58
|
+
el.textContent = "";
|
|
59
|
+
parts.filter(Boolean).forEach(function (p, i) {
|
|
60
|
+
if (i) el.appendChild(document.createTextNode(" · "));
|
|
61
|
+
el.appendChild(h("b", { text: String(p[0]) }));
|
|
62
|
+
el.appendChild(document.createTextNode(" " + p[1]));
|
|
63
|
+
});
|
|
64
|
+
return el;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ---- state: what is shown, kept in the URL so a reload or a shared link lands in the same place ----
|
|
68
|
+
var init = DATA.initial || {};
|
|
69
|
+
var state = { week: DATA.week_start, all: true, project: null, level: null, skill: null, kind: null, status: null, q: "", view: "graph", group: "project", filters: false, sort: "new" };
|
|
70
|
+
function readHash(first) {
|
|
71
|
+
state.all = true; state.week = DATA.week_start; state.view = "graph"; state.group = "project";
|
|
72
|
+
FILTER_KEYS.forEach(function (k) { state[k] = null; });
|
|
73
|
+
if (first && init.project) state.project = init.project;
|
|
74
|
+
(location.hash.slice(1) || "").split("&").forEach(function (kv) {
|
|
75
|
+
var i = kv.indexOf("="), k, v;
|
|
76
|
+
try { k = decodeURIComponent(i < 0 ? kv : kv.slice(0, i)); v = i < 0 ? "" : decodeURIComponent(kv.slice(i + 1)); } catch (e) { return; }
|
|
77
|
+
if (k === "week" && /^\d{4}-\d{2}-\d{2}$/.test(v)) { state.week = monday(v); state.all = false; }
|
|
78
|
+
else if (k === "view" && VIEWS.indexOf(v) >= 0) state.view = v;
|
|
79
|
+
else if (k === "group" && GROUPS.indexOf(v) >= 0) state.group = v;
|
|
80
|
+
else if (FILTER_KEYS.indexOf(k) >= 0 && v) state[k] = v;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function syncHash() {
|
|
84
|
+
var parts = [];
|
|
85
|
+
if (!state.all) parts.push("week=" + state.week);
|
|
86
|
+
if (state.view !== "graph") parts.push("view=" + state.view);
|
|
87
|
+
if (state.view === "graph" && state.group !== "project") parts.push("group=" + state.group);
|
|
88
|
+
FILTER_KEYS.forEach(function (k) { if (state[k]) parts.push(k + "=" + encodeURIComponent(state[k])); });
|
|
89
|
+
// Keep the query string: it carries the token the in-page test needs after a reload.
|
|
90
|
+
history.replaceState(null, "", location.pathname + location.search + (parts.length ? "#" + parts.join("&") : ""));
|
|
91
|
+
}
|
|
92
|
+
readHash(true);
|
|
93
|
+
var earliest = DATA.entries.reduce(function (m, e) { var w = monday(e.date); return w < m ? w : m; }, DATA.week_start);
|
|
94
|
+
|
|
95
|
+
function inScope(e) { return state.all || monday(e.date) === state.week; }
|
|
96
|
+
// "skill" is the filter key for a topic; a note matches on any of its topics.
|
|
97
|
+
function topicsOf(e) { return e.topics && e.topics.length ? e.topics : (e.skill ? [e.skill] : []); }
|
|
98
|
+
function valuesOf(e, key) { return key === "skill" ? topicsOf(e) : (e[key] ? [e[key]] : []); }
|
|
99
|
+
function matches(e, skip) {
|
|
100
|
+
if (skip !== "project" && state.project && e.project !== state.project) return false;
|
|
101
|
+
if (skip !== "level" && state.level && e.level !== state.level) return false;
|
|
102
|
+
if (skip !== "skill" && state.skill && topicsOf(e).indexOf(state.skill) < 0) return false;
|
|
103
|
+
if (skip !== "kind" && state.kind && e.kind !== state.kind) return false;
|
|
104
|
+
if (skip !== "status" && state.status && e.status !== state.status) return false;
|
|
105
|
+
if (state.q && !hasText(e, state.q)) return false;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
function hasText(e, q) {
|
|
109
|
+
return (e.testable + " " + e.paths.join(" ") + " " + e.project + " " + topicsOf(e).join(" ")).toLowerCase().indexOf(q.toLowerCase()) >= 0;
|
|
110
|
+
}
|
|
111
|
+
function valueLabel(key, v) {
|
|
112
|
+
return key === "level" ? LEVEL_LABEL[v] || v : key === "kind" ? KIND_LABEL[v] || v : key === "status" ? STATUS_LABEL[v] || v : v;
|
|
113
|
+
}
|
|
114
|
+
function isStuck(e) { return e.status !== "suppressed" && e.heat != null && e.heat >= HEAT.HOT; }
|
|
115
|
+
|
|
116
|
+
// ---- header: the facts, the active filters, the range ----
|
|
117
|
+
function renderHead(scope, shown) {
|
|
118
|
+
each("#viewseg button", function (b) { b.setAttribute("aria-pressed", String(b.getAttribute("data-view") === state.view)); });
|
|
119
|
+
var el = $("facts");
|
|
120
|
+
if (!scope.length) el.textContent = DATA.entries.length ? "No notes in this week" : "No notes yet";
|
|
121
|
+
else facts(el, [
|
|
122
|
+
[shown.length === scope.length ? scope.length : shown.length + " of " + scope.length, scope.length === 1 ? "note" : "notes"],
|
|
123
|
+
shown.some(isStuck) ? [shown.filter(isStuck).length, "where you get stuck"] : null,
|
|
124
|
+
shown.some(function (e) { return e.status === "retest"; }) ? [shown.filter(function (e) { return e.status === "retest"; }).length, "to revisit"] : null,
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
var act = $("active"); act.textContent = "";
|
|
128
|
+
function removable(text, off) {
|
|
129
|
+
act.appendChild(h("button", { class: "chip", title: "Remove this filter", "aria-label": "Remove filter: " + text, onclick: off }, text, icon("x")));
|
|
130
|
+
}
|
|
131
|
+
FILTER_KEYS.forEach(function (k) { if (state[k]) removable(valueLabel(k, state[k]), function () { state[k] = null; render(); }); });
|
|
132
|
+
if (state.q) removable("“" + state.q + "”", function () { state.q = ""; search.value = ""; render(); });
|
|
133
|
+
|
|
134
|
+
each("#rangeseg button", function (b) { b.setAttribute("aria-pressed", String((b.getAttribute("data-range") === "all") === state.all)); });
|
|
135
|
+
$("prev").hidden = $("next").hidden = $("weeklabel").hidden = state.all;
|
|
136
|
+
$("weeklabel").textContent = state.week === DATA.week_start ? "This week" : "Week of " + shortDate(state.week);
|
|
137
|
+
$("prev").disabled = state.week <= earliest;
|
|
138
|
+
$("next").disabled = state.week >= DATA.week_start;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ---- Notes: filters ----
|
|
142
|
+
function counts(key, scope) {
|
|
143
|
+
var values = {};
|
|
144
|
+
scope.filter(function (e) { return matches(e, key); }).forEach(function (e) { valuesOf(e, key).forEach(function (v) { values[v] = (values[v] || 0) + 1; }); });
|
|
145
|
+
if (state[key] && !values[state[key]]) values[state[key]] = 0;
|
|
146
|
+
return values;
|
|
147
|
+
}
|
|
148
|
+
function chip(key, v, n) {
|
|
149
|
+
return h("button", { class: "chip", "aria-pressed": String(state[key] === v), onclick: function () { state[key] = state[key] === v ? null : v; render(); } },
|
|
150
|
+
valueLabel(key, v), h("span", { class: "n", text: String(n) }));
|
|
151
|
+
}
|
|
152
|
+
var topicInput = h("input", { class: "search", type: "search", placeholder: "Find a topic", "aria-label": "Find a topic", autocomplete: "off" });
|
|
153
|
+
var topicVals = h("span", { class: "vals" });
|
|
154
|
+
var topicCounts = {};
|
|
155
|
+
// Topics are open-ended: show the most used, and let typing find the rest.
|
|
156
|
+
function renderTopics() {
|
|
157
|
+
topicVals.textContent = "";
|
|
158
|
+
var q = topicInput.value.trim().toLowerCase();
|
|
159
|
+
var keys = Object.keys(topicCounts).sort(function (a, b) { return topicCounts[b] - topicCounts[a] || (a < b ? -1 : 1); });
|
|
160
|
+
var pick = q ? keys.filter(function (k) { return k.toLowerCase().indexOf(q) >= 0; }).slice(0, 12) : keys.slice(0, 8);
|
|
161
|
+
if (state.skill && pick.indexOf(state.skill) < 0) pick.unshift(state.skill);
|
|
162
|
+
pick.forEach(function (k) { topicVals.appendChild(chip("skill", k, topicCounts[k])); });
|
|
163
|
+
if (!pick.length) topicVals.appendChild(h("span", { class: "k", text: "No topic matches." }));
|
|
164
|
+
else if (!q && keys.length > pick.length) topicVals.appendChild(h("span", { class: "k", text: (keys.length - pick.length) + " more" }));
|
|
165
|
+
}
|
|
166
|
+
topicInput.addEventListener("input", renderTopics);
|
|
167
|
+
function renderFilters(scope) {
|
|
168
|
+
var active = FILTER_KEYS.filter(function (k) { return state[k]; }).length;
|
|
169
|
+
var fb = $("filterbtn");
|
|
170
|
+
fb.textContent = "Filters" + (active ? " · " + active : "");
|
|
171
|
+
fb.setAttribute("aria-expanded", String(state.filters));
|
|
172
|
+
each("#sortseg button", function (b) { b.setAttribute("aria-pressed", String(b.getAttribute("data-sort") === state.sort)); });
|
|
173
|
+
var el = $("filters"); el.hidden = !state.filters; el.textContent = "";
|
|
174
|
+
if (state.filters) {
|
|
175
|
+
[["project", "Project"], ["skill", "Topic"], ["kind", "Kind"], ["status", "Status"], ["level", "Level"]].forEach(function (row) {
|
|
176
|
+
var key = row[0], values = counts(key, scope), keys = Object.keys(values).sort();
|
|
177
|
+
if (keys.length < 2 && !state[key]) return;
|
|
178
|
+
el.appendChild(h("span", { class: "k", text: row[1] }));
|
|
179
|
+
if (key === "skill") {
|
|
180
|
+
topicCounts = values;
|
|
181
|
+
renderTopics();
|
|
182
|
+
el.appendChild(h("div", { class: "vals" }, topicInput, topicVals));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
var vals = h("div", { class: "vals" });
|
|
186
|
+
keys.forEach(function (v) { vals.appendChild(chip(key, v, values[v])); });
|
|
187
|
+
el.appendChild(vals);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
// A project, a topic or a search is a selection: offer a short test on just that.
|
|
191
|
+
var sel = $("selrow"); sel.textContent = "";
|
|
192
|
+
var cluster = clusterScope();
|
|
193
|
+
if (cluster && DATA.server) {
|
|
194
|
+
var n = clusterCount(cluster);
|
|
195
|
+
sel.appendChild(h("div", { class: "selrow" },
|
|
196
|
+
n ? h("button", { class: "btn primary", text: "Test me · " + plural(n, "question", "questions"), onclick: function () { startTest(cluster); } }) : null,
|
|
197
|
+
h("span", { text: n ? "A short test on " + scopeText(cluster) + ": what you missed last time first, then " + (cluster.q ? "the notes this search shows." : "what you haven't been asked.")
|
|
198
|
+
: "Nothing to test in " + scopeText(cluster) + " right now." })));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// What "Test these notes" covers: a project, a topic, a search of 3+ characters, or any mix.
|
|
203
|
+
function clusterScope() {
|
|
204
|
+
var q = state.q.trim();
|
|
205
|
+
if (!state.project && !state.skill && q.length < 3) return null;
|
|
206
|
+
var s = {};
|
|
207
|
+
if (state.project) s.project = state.project;
|
|
208
|
+
if (state.skill) s.skill = state.skill;
|
|
209
|
+
if (q.length >= 3) s.q = q;
|
|
210
|
+
return s;
|
|
211
|
+
}
|
|
212
|
+
function scopeText(s) { return [s.project, s.skill, s.q ? "“" + s.q + "”" : null].filter(Boolean).join(" · "); }
|
|
213
|
+
// The notes a scope would test, hottest first. A search tests what it shows, even notes already passed.
|
|
214
|
+
function scopeEntries(s) {
|
|
215
|
+
return DATA.entries.filter(function (e) {
|
|
216
|
+
if (e.status === "suppressed") return false;
|
|
217
|
+
if (s.project && e.project !== s.project) return false;
|
|
218
|
+
if (s.skill && topicsOf(e).indexOf(s.skill) < 0) return false;
|
|
219
|
+
if (s.q) return hasText(e, s.q);
|
|
220
|
+
return e.status === "untested" || e.status === "retest";
|
|
221
|
+
}).sort(function (a, b) { return (b.heat == null ? 0.5 : b.heat) - (a.heat == null ? 0.5 : a.heat); });
|
|
222
|
+
}
|
|
223
|
+
// Mirrors the server's cluster pool: untested plus anything to revisit, capped at a test's length.
|
|
224
|
+
function clusterCount(s) {
|
|
225
|
+
return Math.min(s.q ? 5 : 10, scopeEntries(s).length);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ---- Notes: one row per note, opened in place ----
|
|
229
|
+
function codeBlock(e) {
|
|
230
|
+
var pre = h("pre");
|
|
231
|
+
e.snippet.split("\n").forEach(function (line) { pre.appendChild(h("span", { class: "ln", text: line || " " })); });
|
|
232
|
+
var copy = h("button", { class: "copy", text: "Copy", onclick: function () {
|
|
233
|
+
(navigator.clipboard ? navigator.clipboard.writeText(e.snippet) : Promise.reject()).then(
|
|
234
|
+
function () { copy.textContent = "Copied"; setTimeout(function () { copy.textContent = "Copy"; }, 1200); },
|
|
235
|
+
function () { copy.textContent = "Select and copy"; });
|
|
236
|
+
} });
|
|
237
|
+
var lines = e.snippet.split("\n").length;
|
|
238
|
+
var info = [e.snippetLang, plural(lines, "line", "lines"), e.commit ? "@ " + e.commit : ""].filter(Boolean).join(" · ");
|
|
239
|
+
return h("div", { class: "code" }, h("div", { class: "codebar" }, h("span", { text: info }), copy), pre);
|
|
240
|
+
}
|
|
241
|
+
function paras(box, text) {
|
|
242
|
+
text.split(/\n\s*\n/).forEach(function (p) { if (p.trim()) box.appendChild(rich(h("p"), p.replace(/\s*\n\s*/g, " ").trim())); });
|
|
243
|
+
return box;
|
|
244
|
+
}
|
|
245
|
+
// What is worth saying about a note in one line. Heat is in the dot; the words only name the ends.
|
|
246
|
+
function metaText(e) {
|
|
247
|
+
var band = HEAT.band(e.heat);
|
|
248
|
+
return [
|
|
249
|
+
e.project, topicsOf(e).join(", "), shortDate(e.date),
|
|
250
|
+
band === "stuck" ? "Stuck here" : band === "warm" ? "Warm" : null,
|
|
251
|
+
e.status === "retest" ? "To revisit" : e.status === "tested" ? "Tested" : e.status === "suppressed" ? "Hidden from tests" : null,
|
|
252
|
+
].filter(Boolean).join(" · ");
|
|
253
|
+
}
|
|
254
|
+
function noteRow(e, opt) {
|
|
255
|
+
opt = opt || {};
|
|
256
|
+
var d = h("details", { class: "note" + (e.status === "suppressed" ? " suppressed" : ""), id: opt.bare ? null : e.id });
|
|
257
|
+
if (opt.open) d.open = true;
|
|
258
|
+
d.appendChild(h("summary", null,
|
|
259
|
+
HEAT.dot(h, e.status === "suppressed" ? null : e.heat),
|
|
260
|
+
rich(h("span", { class: "q" }), e.testable),
|
|
261
|
+
h("span", { class: "side" }, h("span", { class: "p", text: e.project }), h("span", { class: "d", text: shortDate(e.date) })),
|
|
262
|
+
h("span", { class: "chev" }, icon("down")),
|
|
263
|
+
h("span", { class: "meta", text: metaText(e) })));
|
|
264
|
+
var body = paras(h("div", { class: "body" }), e.prose);
|
|
265
|
+
if (e.snippet) body.appendChild(codeBlock(e));
|
|
266
|
+
var files = h("div", { class: "files" }, h("span", { text: [KIND_LABEL[e.kind] || e.kind, LEVEL_LABEL[e.level] || e.level].join(" · ") }));
|
|
267
|
+
e.paths.forEach(function (p) { files.appendChild(h("code", { text: p })); });
|
|
268
|
+
if (e.last_grade) files.appendChild(h("span", { text: "Last answer: " + GRADE_LABEL[e.last_grade] + (e.attempts > 1 ? " (" + e.attempts + " answers)" : "") }));
|
|
269
|
+
body.appendChild(files);
|
|
270
|
+
// Why the dot is the colour it is, in plain words.
|
|
271
|
+
var why = h("ul", { class: "why" });
|
|
272
|
+
if (e.heat == null) why.appendChild(h("li", null, HEAT.dot(h, null), "No signal yet: nothing here has been asked about, tested or fought with."));
|
|
273
|
+
else (e.heat_why || []).forEach(function (w) { why.appendChild(h("li", null, HEAT.dot(h, e.heat), w.charAt(0).toUpperCase() + w.slice(1))); });
|
|
274
|
+
if (why.firstChild) body.appendChild(why);
|
|
275
|
+
d.appendChild(body);
|
|
276
|
+
return d;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
var OPEN_ROWS = 8, GROUP_ROWS = 15, OPEN_ALL = 60;
|
|
280
|
+
var groupOpen = {}, groupAll = {}, wanted = null;
|
|
281
|
+
function renderList(shown) {
|
|
282
|
+
var list = $("list"); list.textContent = "";
|
|
283
|
+
if (DATA.entries.length === 0) {
|
|
284
|
+
list.appendChild(h("div", { class: "empty" }, h("strong", { text: "Nothing captured yet" }), "Work normally in Claude Code. Notes land here as the work happens."));
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (shown.length === 0) {
|
|
288
|
+
var filtered = FILTER_KEYS.some(function (k) { return state[k]; }) || state.q;
|
|
289
|
+
list.appendChild(h("div", { class: "empty" },
|
|
290
|
+
h("strong", { text: filtered ? "No notes match these filters" : "Nothing captured this week" }),
|
|
291
|
+
filtered ? "Remove a filter, or clear them all." : "Try another week, or switch to All time.",
|
|
292
|
+
h("div", null, filtered
|
|
293
|
+
? h("button", { class: "chip", text: "Clear filters", onclick: function () { FILTER_KEYS.forEach(function (k) { state[k] = null; }); state.q = ""; search.value = ""; render(); } })
|
|
294
|
+
: h("button", { class: "chip", text: "Show all time", onclick: function () { state.all = true; render(); } }))));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
var groups = {}, order = [];
|
|
298
|
+
function add(key, label, e) { if (!groups[key]) { groups[key] = { label: label, items: [] }; order.push(key); } groups[key].items.push(e); }
|
|
299
|
+
if (state.sort === "stuck") {
|
|
300
|
+
// Grouped by how stuck: the same bands as the map.
|
|
301
|
+
var rank = {}; HEAT.BANDS.forEach(function (b, i) { rank[b[0]] = i; });
|
|
302
|
+
shown.slice().sort(function (a, b) {
|
|
303
|
+
var ba = rank[HEAT.band(a.heat)], bb = rank[HEAT.band(b.heat)];
|
|
304
|
+
return ba - bb || (b.heat || 0) - (a.heat || 0) || (a.date < b.date ? 1 : a.date > b.date ? -1 : 0) || (a.id < b.id ? -1 : 1);
|
|
305
|
+
}).forEach(function (e) { var b = HEAT.BANDS[rank[HEAT.band(e.heat)]]; add(b[0], b[1], e); });
|
|
306
|
+
} else {
|
|
307
|
+
shown.slice().sort(function (a, b) { return a.date < b.date ? 1 : a.date > b.date ? -1 : (a.id < b.id ? -1 : 1); }).forEach(function (e) {
|
|
308
|
+
var w = monday(e.date);
|
|
309
|
+
add(w, w === DATA.week_start ? "This week" : w === addDays(DATA.week_start, -7) ? "Last week" : "Week of " + shortDate(w), e);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
// A few hundred notes is a long page, so groups fold. The first ones start open (enough to fill
|
|
313
|
+
// a screen), a search or a short result opens everything, and a long group shows its first rows.
|
|
314
|
+
var narrowed = state.q || ((!state.all || FILTER_KEYS.some(function (k) { return state[k]; })) && shown.length <= OPEN_ALL);
|
|
315
|
+
var seen = 0;
|
|
316
|
+
order.forEach(function (key) {
|
|
317
|
+
var g = groups[key], id = state.sort + ":" + key;
|
|
318
|
+
if (wanted && g.items.some(function (e) { return e.id === wanted; })) groupOpen[id] = groupAll[id] = true;
|
|
319
|
+
var open = id in groupOpen ? groupOpen[id] : narrowed || seen < OPEN_ROWS;
|
|
320
|
+
seen += g.items.length;
|
|
321
|
+
var head = h("summary", null, h("span", { class: "chev" }, icon("down")), h("h2", { text: g.label }), h("span", { class: "c", text: String(g.items.length) }));
|
|
322
|
+
var sec = h("details", { class: "group" }, head);
|
|
323
|
+
var built = false;
|
|
324
|
+
function build() {
|
|
325
|
+
if (built) return;
|
|
326
|
+
built = true;
|
|
327
|
+
var limit = groupAll[id] || g.items.length <= GROUP_ROWS + 3 ? g.items.length : GROUP_ROWS;
|
|
328
|
+
g.items.slice(0, limit).forEach(function (e) { sec.appendChild(noteRow(e)); });
|
|
329
|
+
if (limit === g.items.length) return;
|
|
330
|
+
var rest = h("div", { class: "rest" }, h("button", { class: "more", text: "Show " + (g.items.length - limit) + " more", onclick: function () {
|
|
331
|
+
groupAll[id] = true;
|
|
332
|
+
g.items.slice(limit).forEach(function (e) { sec.insertBefore(noteRow(e), rest); });
|
|
333
|
+
sec.removeChild(rest);
|
|
334
|
+
} }));
|
|
335
|
+
sec.appendChild(rest);
|
|
336
|
+
}
|
|
337
|
+
if (open) { sec.open = true; build(); }
|
|
338
|
+
// The click comes before the browser flips "open": remember what the user chose, and fill on first open.
|
|
339
|
+
head.addEventListener("click", function () { groupOpen[id] = !sec.open; if (!sec.open) build(); });
|
|
340
|
+
list.appendChild(sec);
|
|
341
|
+
});
|
|
342
|
+
wanted = null;
|
|
343
|
+
}
|
|
344
|
+
// Jump to one note in the list, unfolding whatever hides it.
|
|
345
|
+
function showNote(id) {
|
|
346
|
+
wanted = id; state.view = "list"; render();
|
|
347
|
+
var c = $(id);
|
|
348
|
+
if (c) { c.open = true; c.scrollIntoView({ block: "center" }); }
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// ---- "Where you get stuck": read from what you did, not from tests you were made to take ----
|
|
352
|
+
function areaRow(a, onclick) {
|
|
353
|
+
var name = h("span", { class: "aname" }, a.topic, h("span", { text: " · " + a.project }));
|
|
354
|
+
return h("button", { class: "area", onclick: onclick },
|
|
355
|
+
HEAT.dot(h, a.heat), name,
|
|
356
|
+
h("span", { class: "awhy", text: a.hot_notes + " of " + plural(a.notes, "note", "notes") + ": " + a.why.join("; ") }));
|
|
357
|
+
}
|
|
358
|
+
function showArea(a) { state.project = a.project; state.skill = a.topic; state.q = ""; search.value = ""; state.all = true; state.view = "list"; render(); window.scrollTo(0, 0); }
|
|
359
|
+
// The areas are worked out over all time; the project and topic filters narrow them.
|
|
360
|
+
function hotAreas() { return (DATA.hot || []).filter(function (a) { return (!state.project || a.project === state.project) && (!state.skill || a.topic === state.skill); }); }
|
|
361
|
+
function hottestNote(a) {
|
|
362
|
+
return DATA.entries.filter(function (e) { return e.project === a.project && e.skill === a.topic && e.status !== "suppressed" && e.heat != null; })
|
|
363
|
+
.sort(function (x, y) { return y.heat - x.heat || (x.id < y.id ? -1 : 1); })[0];
|
|
364
|
+
}
|
|
365
|
+
var NOTHING_STUCK = "Nothing stands out yet. An area shows up here when you ask about it again, a test keeps failing in its files, or you miss a question on it.";
|
|
366
|
+
function renderRail() {
|
|
367
|
+
var el = $("rail"); el.textContent = "";
|
|
368
|
+
var hot = hotAreas();
|
|
369
|
+
el.appendChild(h("h2", { text: "Where you get stuck" }));
|
|
370
|
+
if (!hot.length) { el.appendChild(h("p", { class: "quietnote", text: NOTHING_STUCK })); return; }
|
|
371
|
+
el.appendChild(h("p", { class: "sub", text: (state.all ? "" : "Over all time. ") + "Read from what you did: asking again, tests that kept failing, missed answers." }));
|
|
372
|
+
hot.slice(0, 5).forEach(function (a) {
|
|
373
|
+
el.appendChild(areaRow(a, function () {
|
|
374
|
+
// Fly to the hottest note of the area; if it isn't on the map right now, show the area's notes instead.
|
|
375
|
+
var top = hottestNote(a), g = activeGraph();
|
|
376
|
+
if (!top || !g || !g.focus(top.id)) showArea(a);
|
|
377
|
+
}));
|
|
378
|
+
});
|
|
379
|
+
if (hot.length > 5) el.appendChild(h("button", { class: "more", text: "All " + hot.length + " areas", onclick: function () { state.view = "stats"; render(); window.scrollTo(0, 0); } }));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// ---- Stats: what was captured, how well it is known, and what was done with it ----
|
|
383
|
+
// A percentage needs a few answers behind it before it means anything.
|
|
384
|
+
var MIN_ANSWERS = 5, MIN_ROW = 3, WEEKS = 12, TOP = 6, PLOT = 104;
|
|
385
|
+
function pctText(pass, total) { return total ? Math.round((pass / total) * 100) + "%" : "–"; }
|
|
386
|
+
function passed(list) { return list.filter(function (r) { return r.grade === "got"; }).length; }
|
|
387
|
+
|
|
388
|
+
// One small tooltip for every mark on the page that has more to say than fits on it.
|
|
389
|
+
var tipEl = h("div", { class: "tip", role: "tooltip" });
|
|
390
|
+
tipEl.hidden = true;
|
|
391
|
+
document.body.appendChild(tipEl);
|
|
392
|
+
function tip(el, text, anchor) {
|
|
393
|
+
function show() {
|
|
394
|
+
var r = (anchor || el).getBoundingClientRect();
|
|
395
|
+
tipEl.textContent = text; tipEl.hidden = false;
|
|
396
|
+
var half = tipEl.offsetWidth / 2;
|
|
397
|
+
var x = Math.max(half + 8, Math.min(document.documentElement.clientWidth - half - 8, r.left + r.width / 2));
|
|
398
|
+
tipEl.style.left = (x + window.pageXOffset) + "px";
|
|
399
|
+
tipEl.style.top = (r.top + window.pageYOffset - 6) + "px";
|
|
400
|
+
}
|
|
401
|
+
function hide() { tipEl.hidden = true; }
|
|
402
|
+
el.addEventListener("mouseenter", show); el.addEventListener("focus", show);
|
|
403
|
+
el.addEventListener("mouseleave", hide); el.addEventListener("blur", hide);
|
|
404
|
+
return el;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// One column per week. items: { label, value, part, cap, text, on, onclick }.
|
|
408
|
+
// "part" is the share of the column drawn solid (right answers); the rest is an outline.
|
|
409
|
+
function columns(items, name) {
|
|
410
|
+
var max = items.reduce(function (m, it) { return Math.max(m, it.value); }, 1);
|
|
411
|
+
var step = items.length > 8 ? 2 : 1;
|
|
412
|
+
var box = h("div", { class: "cols", role: "group", "aria-label": name });
|
|
413
|
+
items.forEach(function (it, i) {
|
|
414
|
+
var bar = null;
|
|
415
|
+
if (it.value) {
|
|
416
|
+
if (it.part == null) bar = h("span", { class: "b" });
|
|
417
|
+
else {
|
|
418
|
+
bar = h("span", { class: "b stack" });
|
|
419
|
+
if (it.part < it.value) { var rest = h("i", { class: "rest" }); rest.style.flexGrow = String(it.value - it.part); bar.appendChild(rest); }
|
|
420
|
+
if (it.part) { var got = h("i"); got.style.flexGrow = String(it.part); bar.appendChild(got); }
|
|
421
|
+
}
|
|
422
|
+
bar.style.height = Math.max(4, Math.round((it.value / max) * PLOT)) + "px";
|
|
423
|
+
}
|
|
424
|
+
var attrs = { class: "c", "aria-label": it.text };
|
|
425
|
+
if (it.on) attrs["aria-current"] = "true";
|
|
426
|
+
if (it.onclick) attrs.onclick = it.onclick; else attrs.tabindex = "0";
|
|
427
|
+
var cap = it.value ? h("span", { class: "v", text: it.cap || String(it.value) }) : null;
|
|
428
|
+
var c = h(it.onclick ? "button" : "div", attrs, cap, bar,
|
|
429
|
+
(items.length - 1 - i) % step === 0 ? h("span", { class: "x", text: it.label }) : null);
|
|
430
|
+
box.appendChild(tip(c, it.text, cap));
|
|
431
|
+
});
|
|
432
|
+
return box;
|
|
433
|
+
}
|
|
434
|
+
function weekName(w) { return w === DATA.week_start ? "This week" : "Week of " + shortDate(w); }
|
|
435
|
+
function lastWeeks(from) {
|
|
436
|
+
var out = [], w = DATA.week_start;
|
|
437
|
+
while (out.length < WEEKS && w >= from) { out.unshift(w); w = addDays(w, -7); }
|
|
438
|
+
return out;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// How many notes carry each value, most first. Each row opens those notes.
|
|
442
|
+
function countBy(list, values) {
|
|
443
|
+
var g = {};
|
|
444
|
+
list.forEach(function (e) { values(e).forEach(function (v) { if (v) g[v] = (g[v] || 0) + 1; }); });
|
|
445
|
+
return Object.keys(g).map(function (k) { return { name: k, n: g[k] }; }).sort(function (a, b) { return b.n - a.n || (a.name < b.name ? -1 : 1); });
|
|
446
|
+
}
|
|
447
|
+
function rankList(title, rows, onpick) {
|
|
448
|
+
var box = h("div", null, h("h3", { class: "label", text: title }));
|
|
449
|
+
var max = rows.length ? rows[0].n : 1;
|
|
450
|
+
rows.slice(0, TOP).forEach(function (r) {
|
|
451
|
+
var bar = h("i");
|
|
452
|
+
bar.style.width = "calc((100% - 44px) * " + (r.n / max).toFixed(3) + ")";
|
|
453
|
+
box.appendChild(h("button", { class: "rank", title: "Show these notes", onclick: function () { onpick(r.name); } },
|
|
454
|
+
h("span", { class: "name", text: r.name }), h("span", { class: "m" }, bar, h("b", { text: String(r.n) }))));
|
|
455
|
+
});
|
|
456
|
+
if (rows.length > TOP) box.appendChild(h("p", { class: "quietnote", text: "and " + (rows.length - TOP) + " more" }));
|
|
457
|
+
return box;
|
|
458
|
+
}
|
|
459
|
+
function pick(key, value) { state[key] = value; state.q = ""; search.value = ""; state.view = "list"; render(); window.scrollTo(0, 0); }
|
|
460
|
+
|
|
461
|
+
// Project + topic groups with at least one warm note, warmest first. The Map's list only has
|
|
462
|
+
// the stuck ones; this one also says where things are merely warm.
|
|
463
|
+
function warmAreas(list) {
|
|
464
|
+
var g = {};
|
|
465
|
+
list.forEach(function (e) { var k = e.project + "\n" + (e.skill || ""); (g[k] = g[k] || []).push(e); });
|
|
466
|
+
return Object.keys(g).map(function (k) {
|
|
467
|
+
var items = g[k], warm = items.filter(function (e) { return e.heat != null && e.heat >= HEAT.WARM; });
|
|
468
|
+
if (!warm.length) return null;
|
|
469
|
+
var kinds = {};
|
|
470
|
+
warm.forEach(function (e) { (e.heat_why || []).forEach(function (w) { w = w.replace(/ \([^)]*\)$/, ""); kinds[w] = (kinds[w] || 0) + 1; }); });
|
|
471
|
+
var why = Object.keys(kinds).sort(function (a, b) { return kinds[b] - kinds[a] || (a < b ? -1 : 1); }).slice(0, 3)
|
|
472
|
+
.map(function (w) { return kinds[w] > 1 ? w + " ×" + kinds[w] : w; });
|
|
473
|
+
return { project: items[0].project, topic: items[0].skill || "", heat: HEAT.group(items.map(function (e) { return e.heat; })), notes: items.length, hot_notes: warm.length, why: why };
|
|
474
|
+
}).filter(Boolean).sort(function (a, b) { return b.heat - a.heat || b.hot_notes - a.hot_notes || (a.topic < b.topic ? -1 : 1); });
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// Right answers per row, weakest first. Rows with too few answers are left out and counted.
|
|
478
|
+
function gradeRows(rs, key) {
|
|
479
|
+
var g = {};
|
|
480
|
+
rs.forEach(function (r) { var k = key(r); if (!k) return; g[k] = g[k] || { name: k, pass: 0, total: 0 }; g[k].total++; if (r.grade === "got") g[k].pass++; });
|
|
481
|
+
var all = Object.keys(g).map(function (k) { return g[k]; });
|
|
482
|
+
return { all: all, rows: all.filter(function (r) { return r.total >= MIN_ROW; })
|
|
483
|
+
.sort(function (a, b) { return a.pass / a.total - b.pass / b.total || b.total - a.total || (a.name < b.name ? -1 : 1); }) };
|
|
484
|
+
}
|
|
485
|
+
function weakest(rs, key) {
|
|
486
|
+
var row = gradeRows(rs, key).rows.filter(function (r) { return r.pass < r.total; })[0];
|
|
487
|
+
return row ? row.name : null;
|
|
488
|
+
}
|
|
489
|
+
function meterList(title, rs, key) {
|
|
490
|
+
var graded = gradeRows(rs, key), all = graded.all, rows = graded.rows;
|
|
491
|
+
var box = h("div", null, h("h3", { class: "label", text: title }));
|
|
492
|
+
rows.slice(0, TOP).forEach(function (r) {
|
|
493
|
+
var fill = h("span", { class: "fill" }); fill.style.width = (r.pass / r.total) * 100 + "%";
|
|
494
|
+
box.appendChild(h("div", { class: "bar" },
|
|
495
|
+
h("span", { class: "name", text: r.name }),
|
|
496
|
+
h("span", { class: "track" }, fill),
|
|
497
|
+
h("span", { class: "val" }, h("b", { text: pctText(r.pass, r.total) }), " · " + r.pass + " of " + r.total)));
|
|
498
|
+
});
|
|
499
|
+
var left = all.length - Math.min(rows.length, TOP);
|
|
500
|
+
if (!rows.length) box.appendChild(h("p", { class: "quietnote", text: "None has " + MIN_ROW + " answers yet." }));
|
|
501
|
+
else if (left) box.appendChild(h("p", { class: "quietnote", text: left + " more, most with fewer than " + MIN_ROW + " answers" }));
|
|
502
|
+
return box;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function renderStats(shown) {
|
|
506
|
+
var el = $("statsview"); el.textContent = "";
|
|
507
|
+
tipEl.hidden = true;
|
|
508
|
+
if (!shown.length) {
|
|
509
|
+
el.appendChild(h("div", { class: "empty wide" },
|
|
510
|
+
h("strong", { text: DATA.entries.length ? "No notes in view" : "Nothing captured yet" }),
|
|
511
|
+
DATA.entries.length ? "Try another week, All time, or remove a filter." : "Work normally in Claude Code. Notes land here as the work happens."));
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
var byId = {};
|
|
515
|
+
shown.forEach(function (e) { byId[e.id] = e; });
|
|
516
|
+
var rs = (DATA.results || []).filter(function (r) { return byId[r.entry_id]; });
|
|
517
|
+
var live = shown.filter(function (e) { return e.status !== "suppressed"; });
|
|
518
|
+
|
|
519
|
+
// 1. What you captured: works from the first note, before anything has been asked or tested.
|
|
520
|
+
var cap = h("section", { class: "sec" }, h("h2", { text: "What you captured" }));
|
|
521
|
+
var projects = countBy(shown, function (e) { return [e.project]; }), topics = countBy(shown, topicsOf);
|
|
522
|
+
var first = shown.reduce(function (m, e) { return e.date < m ? e.date : m; }, shown[0].date);
|
|
523
|
+
cap.appendChild(facts(h("p", { class: "figs" }), [
|
|
524
|
+
[shown.length, shown.length === 1 ? "note" : "notes"],
|
|
525
|
+
[projects.length, (projects.length === 1 ? "project" : "projects") + (state.all ? ", since " + shortDate(first) : ", " + (state.week === DATA.week_start ? "this week" : "week of " + shortDate(state.week)))],
|
|
526
|
+
]));
|
|
527
|
+
// The weeks show every note the filters allow, whatever the range, so a single week has its context.
|
|
528
|
+
var perWeek = {};
|
|
529
|
+
DATA.entries.forEach(function (e) { if (matches(e)) { var w = monday(e.date); perWeek[w] = (perWeek[w] || 0) + 1; } });
|
|
530
|
+
var weeks = lastWeeks(earliest);
|
|
531
|
+
cap.appendChild(h("h3", { class: "label", text: "Notes per week" + (earliest < weeks[0] ? ", last " + WEEKS + " weeks" : "") }));
|
|
532
|
+
cap.appendChild(columns(weeks.map(function (w) {
|
|
533
|
+
var n = perWeek[w] || 0;
|
|
534
|
+
return { label: shortDate(w), value: n, on: !state.all && w === state.week, text: weekName(w) + ": " + plural(n, "note", "notes"),
|
|
535
|
+
onclick: n ? function () { state.week = w; state.all = false; state.view = "list"; render(); window.scrollTo(0, 0); } : null };
|
|
536
|
+
}), "Notes per week"));
|
|
537
|
+
cap.appendChild(h("div", { class: "pair" },
|
|
538
|
+
rankList("Projects", projects, function (v) { pick("project", v); }),
|
|
539
|
+
rankList("Topics", topics, function (v) { pick("skill", v); })));
|
|
540
|
+
el.appendChild(cap);
|
|
541
|
+
|
|
542
|
+
// 2. How well you know it: the same heat as the map, as one bar.
|
|
543
|
+
var know = h("section", { class: "sec" }, h("h2", { text: "How well you know it" }));
|
|
544
|
+
var counts = {};
|
|
545
|
+
HEAT.BANDS.forEach(function (b) { counts[b[0]] = 0; });
|
|
546
|
+
live.forEach(function (e) { counts[HEAT.band(e.heat)]++; });
|
|
547
|
+
var split = h("div", { class: "split", role: "img", "aria-label": HEAT.BANDS.map(function (b) { return b[1] + ": " + counts[b[0]]; }).join(", ") });
|
|
548
|
+
var bands = h("div", { class: "bands" });
|
|
549
|
+
HEAT.BANDS.forEach(function (b) {
|
|
550
|
+
var n = counts[b[0]], share = live.length ? (n / live.length) * 100 : 0;
|
|
551
|
+
var pct = !n ? "" : share < 1 ? "<1%" : Math.round(share) + "%";
|
|
552
|
+
if (n) {
|
|
553
|
+
var s = h("i", { class: b[2] == null ? "none" : "" });
|
|
554
|
+
s.style.flexGrow = String(n);
|
|
555
|
+
if (b[2] != null) { s.style.setProperty("--hd", HEAT.color(b[2])); s.style.setProperty("--hl", HEAT.color(b[2], null, true)); }
|
|
556
|
+
split.appendChild(tip(s, b[1] + ": " + plural(n, "note", "notes") + " (" + pct + ")"));
|
|
557
|
+
}
|
|
558
|
+
bands.appendChild(HEAT.dot(h, b[2]));
|
|
559
|
+
bands.appendChild(h("span", { class: n ? "" : "zero", text: b[1] }));
|
|
560
|
+
bands.appendChild(h("b", { class: n ? "" : "zero", text: String(n) }));
|
|
561
|
+
bands.appendChild(h("span", { class: "p", text: pct }));
|
|
562
|
+
});
|
|
563
|
+
know.appendChild(split);
|
|
564
|
+
know.appendChild(bands);
|
|
565
|
+
var areas = warmAreas(live);
|
|
566
|
+
if (areas.length) {
|
|
567
|
+
know.appendChild(h("h3", { class: "label", text: "Warmest areas" }));
|
|
568
|
+
areas.slice(0, 5).forEach(function (a) {
|
|
569
|
+
know.appendChild(areaRow({ project: a.project, topic: a.topic || "No topic", heat: a.heat, notes: a.notes, hot_notes: a.hot_notes, why: a.why },
|
|
570
|
+
function () { showArea(a); }));
|
|
571
|
+
});
|
|
572
|
+
know.appendChild(h("button", { class: "more", text: "Show the warmest notes first", onclick: function () { state.sort = "stuck"; state.view = "list"; render(); window.scrollTo(0, 0); } }));
|
|
573
|
+
}
|
|
574
|
+
know.appendChild(h("p", { class: "quietnote", text: "Heat is read from what you did: asking for an explanation, asking about it again, a fix that took several tries, a missed answer. No signal yet means none of that has happened around the note." }));
|
|
575
|
+
el.appendChild(know);
|
|
576
|
+
|
|
577
|
+
// 3. Tests you chose to take. No percentages until there are enough answers to mean something.
|
|
578
|
+
var tests = h("section", { class: "sec" }, h("h2", { text: "Tests you took" }));
|
|
579
|
+
var testBtn = DATA.server ? h("button", { class: "btn", text: $("testbtn").textContent, onclick: function () { startTest(null); } }) : null;
|
|
580
|
+
if (!rs.length) {
|
|
581
|
+
tests.appendChild(h("p", { class: "figs", text: "None yet on these notes. A test is something you ask for: a few questions, and you grade yourself." }));
|
|
582
|
+
if (testBtn) tests.appendChild(testBtn);
|
|
583
|
+
} else if (rs.length < MIN_ANSWERS) {
|
|
584
|
+
tests.appendChild(facts(h("p", { class: "figs" }), [[rs.length, (rs.length === 1 ? "answer" : "answers") + " so far"], [passed(rs), "right"]]));
|
|
585
|
+
tests.appendChild(h("p", { class: "quietnote", text: "Percentages show up after " + MIN_ANSWERS + " answers, so a single answer can't read as 100%." }));
|
|
586
|
+
if (testBtn) tests.appendChild(testBtn);
|
|
587
|
+
} else {
|
|
588
|
+
var once = rs.filter(function (r) { return !r.is_retest; }), again = rs.filter(function (r) { return r.is_retest; });
|
|
589
|
+
tests.appendChild(facts(h("p", { class: "figs" }), [
|
|
590
|
+
[rs.length, "answers"],
|
|
591
|
+
[pctText(passed(rs), rs.length), "right"],
|
|
592
|
+
once.length >= MIN_ROW ? [pctText(passed(once), once.length), "right the first time"] : null,
|
|
593
|
+
again.length >= MIN_ROW ? [pctText(passed(again), again.length), "right the second time"] : null,
|
|
594
|
+
]));
|
|
595
|
+
var byWeek = {};
|
|
596
|
+
rs.forEach(function (r) { var w = byWeek[r.week] = byWeek[r.week] || { pass: 0, total: 0 }; w.total++; if (r.grade === "got") w.pass++; });
|
|
597
|
+
var tested = Object.keys(byWeek).sort();
|
|
598
|
+
if (tested.length > 1) {
|
|
599
|
+
tests.appendChild(h("h3", { class: "label" }, "Answers per week",
|
|
600
|
+
h("span", { class: "key" }, h("i", { class: "sw" }), "right", h("i", { class: "sw rest" }), "not right")));
|
|
601
|
+
tests.appendChild(columns(lastWeeks(tested[0]).map(function (w) {
|
|
602
|
+
var x = byWeek[w] || { pass: 0, total: 0 };
|
|
603
|
+
return { label: shortDate(w), value: x.total, part: x.pass, cap: x.pass + "/" + x.total, text: weekName(w) + ": " + x.pass + " of " + plural(x.total, "answer", "answers") + " right" };
|
|
604
|
+
}), "Answers per week"));
|
|
605
|
+
}
|
|
606
|
+
tests.appendChild(h("div", { class: "pair" },
|
|
607
|
+
meterList("Weakest topics", rs, function (r) { return byId[r.entry_id].skill; }),
|
|
608
|
+
meterList("Weakest projects", rs, function (r) { return byId[r.entry_id].project; })));
|
|
609
|
+
// The one thing to do about it: a short test on the weakest topic that still has something to ask.
|
|
610
|
+
var weak = weakest(rs, function (r) { return byId[r.entry_id].skill; });
|
|
611
|
+
var wn = weak && DATA.server ? clusterCount({ skill: weak }) : 0;
|
|
612
|
+
if (wn) tests.appendChild(h("button", { class: "btn", text: "Test me on " + weak + " · " + plural(wn, "question", "questions"), onclick: function () { startTest({ skill: weak }); } }));
|
|
613
|
+
}
|
|
614
|
+
el.appendChild(tests);
|
|
615
|
+
|
|
616
|
+
// 4. Where the user still leaned on Claude: questions about their own code, re-asks, fixes that looped.
|
|
617
|
+
var act = DATA.activity || { days: 30, asks: 0, reasks: 0, loops: 0, asked: [] };
|
|
618
|
+
var all = {}; DATA.entries.forEach(function (e) { all[e.id] = e; });
|
|
619
|
+
var recall = h("section", { class: "sec" }, h("h2", { text: "Where you leaned on Claude, last " + act.days + " days" }));
|
|
620
|
+
if (!act.asks && !act.reasks && !act.loops) {
|
|
621
|
+
recall.appendChild(h("p", { class: "figs", text: "Nothing yet. This fills in when you ask Claude about your own code, or a fix takes several tries." }));
|
|
622
|
+
} else {
|
|
623
|
+
recall.appendChild(facts(h("p", { class: "figs" }), [
|
|
624
|
+
[act.asks, act.asks === 1 ? "question about your own code" : "questions about your own code"],
|
|
625
|
+
act.reasks ? [act.reasks, "asked again"] : null,
|
|
626
|
+
act.loops ? [act.loops, act.loops === 1 ? "fix that took several tries" : "fixes that took several tries"] : null,
|
|
627
|
+
]));
|
|
628
|
+
}
|
|
629
|
+
var asked = (act.asked || []).filter(function (a) { return all[a.id]; });
|
|
630
|
+
if (asked.length) {
|
|
631
|
+
recall.appendChild(h("h3", { class: "label", text: "What you keep asking about" }));
|
|
632
|
+
asked.forEach(function (a) {
|
|
633
|
+
recall.appendChild(h("button", { class: "asked", title: "Show this note", onclick: function () {
|
|
634
|
+
state.q = ""; search.value = ""; state.all = true; FILTER_KEYS.forEach(function (k) { state[k] = null; }); state.project = all[a.id].project; showNote(a.id);
|
|
635
|
+
} }, h("span", { class: "n", text: a.n + "×" }), rich(h("span", { class: "t" }), all[a.id].testable)));
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
el.appendChild(recall);
|
|
639
|
+
|
|
640
|
+
var closing = [];
|
|
641
|
+
if (rs.length >= MIN_ANSWERS) closing.push("You rated yourself " + DATA.rating + "/10; " + pctText(passed(rs), rs.length) + " of your answers here were right.");
|
|
642
|
+
if (DATA.keep_sharp.length) closing.push("Keeping sharp: " + DATA.keep_sharp.join(", ") + ".");
|
|
643
|
+
if (closing.length) el.appendChild(h("p", { class: "quietnote wide", text: closing.join(" ") }));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// ---- Map: a 3D heat map by default, with the flat one a click away ----
|
|
647
|
+
var heatbar = $("heatbar");
|
|
648
|
+
heatbar.style.setProperty("--gd", HEAT.gradient());
|
|
649
|
+
heatbar.style.setProperty("--gl", HEAT.gradient(true));
|
|
650
|
+
var graph = null, graph3d = null;
|
|
651
|
+
// 3D needs the bundle the notes server ships and a browser with WebGL. Without either, the page is flat.
|
|
652
|
+
var can3d = !!DATA.server && (function () {
|
|
653
|
+
try { var c = document.createElement("canvas"); return !!(c.getContext("webgl2") || c.getContext("webgl")); } catch (e) { return false; }
|
|
654
|
+
})();
|
|
655
|
+
var bundle = "none"; // none | loading | ready | failed
|
|
656
|
+
function pref(key, fallback) { try { return localStorage.getItem(key) || fallback; } catch (e) { return fallback; } }
|
|
657
|
+
function setPref(key, v) { try { localStorage.setItem(key, v); } catch (e) {} }
|
|
658
|
+
state.dim = can3d && pref("selflore-graph-dim", "3d") !== "2d" ? "3d" : "2d";
|
|
659
|
+
state.labels = pref("selflore-graph-labels", "on") !== "off";
|
|
660
|
+
function graphOpts() {
|
|
661
|
+
return {
|
|
662
|
+
h: h, icon: icon, rich: rich, card: function (e) { return noteRow(e, { open: true, bare: true }); }, now: NOW, links: DATA.links || [],
|
|
663
|
+
wrap: $("gwrap"), canvas: $("gcanvas"), panel: $("gpanel"), empty: $("gempty"),
|
|
664
|
+
canTest: !!DATA.server, clusterCount: clusterCount,
|
|
665
|
+
onTest: function (scope) { startTest(scope); },
|
|
666
|
+
onFilter: function (key, value) { state[key] = value === "(none)" ? null : value; state.view = "list"; render(); window.scrollTo(0, 0); },
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function activeGraph() { return state.dim === "3d" && graph3d ? graph3d : graph; }
|
|
670
|
+
function loadBundle() {
|
|
671
|
+
bundle = "loading";
|
|
672
|
+
var s = document.createElement("script");
|
|
673
|
+
s.src = "/vendor/graph3d.js";
|
|
674
|
+
s.onload = function () { bundle = window.selfloreGraph3d ? "ready" : "failed"; if (bundle === "failed") state.dim = "2d"; render(); };
|
|
675
|
+
s.onerror = function () { bundle = "failed"; state.dim = "2d"; render(); };
|
|
676
|
+
document.head.appendChild(s);
|
|
677
|
+
}
|
|
678
|
+
function renderGraph(shown) {
|
|
679
|
+
var live = shown.filter(function (e) { return e.status !== "suppressed"; });
|
|
680
|
+
var wrapEl = $("gwrap"), canvasEl = $("gcanvas"), holder = $("g3d");
|
|
681
|
+
var hint = $("ghint"); hint.textContent = "";
|
|
682
|
+
if (state.dim === "3d" && bundle === "none") loadBundle();
|
|
683
|
+
var three = state.dim === "3d" && bundle === "ready";
|
|
684
|
+
if (!state.all && live.length < 8 && DATA.entries.length > live.length) {
|
|
685
|
+
hint.appendChild(h("span", { text: plural(live.length, "note", "notes") + " in this week." }));
|
|
686
|
+
hint.appendChild(h("button", { class: "chip", text: "Show all time", onclick: function () { state.all = true; render(); } }));
|
|
687
|
+
}
|
|
688
|
+
each("#groupseg button", function (b) { b.setAttribute("aria-pressed", String(b.getAttribute("data-group") === state.group)); });
|
|
689
|
+
each("#dimseg button", function (b) { b.setAttribute("aria-pressed", String(b.getAttribute("data-dim") === state.dim)); });
|
|
690
|
+
$("dimseg").hidden = !can3d || bundle === "failed";
|
|
691
|
+
$("glabels").setAttribute("aria-pressed", String(state.labels));
|
|
692
|
+
// The stage is dark from the moment 3D is chosen, so the box doesn't flash while the bundle loads.
|
|
693
|
+
wrapEl.classList.toggle("three", state.dim === "3d");
|
|
694
|
+
holder.hidden = !three; canvasEl.hidden = state.dim === "3d";
|
|
695
|
+
|
|
696
|
+
// The caption and the legend name what the rings are in this grouping.
|
|
697
|
+
var GROUP_WORD = { project: ["project", "projects"], skill: ["topic", "topics"], kind: ["kind", "kinds"] }[state.group];
|
|
698
|
+
var groups = {};
|
|
699
|
+
live.forEach(function (e) { groups[e[state.group] || "(none)"] = true; });
|
|
700
|
+
$("lgroup").textContent = "A " + GROUP_WORD[0];
|
|
701
|
+
var cap = $("gcap"); cap.textContent = "";
|
|
702
|
+
cap.appendChild(h("b", { text: "selflore" }));
|
|
703
|
+
cap.appendChild(document.createTextNode(" · " + [plural(live.length, "note", "notes"), plural(Object.keys(groups).length, GROUP_WORD[0], GROUP_WORD[1]),
|
|
704
|
+
live.some(isStuck) ? live.filter(isStuck).length + " where you get stuck" : null].filter(Boolean).join(" · ")));
|
|
705
|
+
|
|
706
|
+
if (state.dim === "3d") {
|
|
707
|
+
if (graph && graph.hasPanel()) graph.closePanel();
|
|
708
|
+
if (!three) return; // the bundle is on its way; render() runs again when it lands
|
|
709
|
+
if (!graph3d) {
|
|
710
|
+
var o = graphOpts(); o.wrap = holder;
|
|
711
|
+
try { graph3d = window.selfloreGraph3d(o); }
|
|
712
|
+
catch (e) { bundle = "failed"; state.dim = "2d"; render(); return; }
|
|
713
|
+
}
|
|
714
|
+
graph3d.setLabels(state.labels);
|
|
715
|
+
graph3d.resize();
|
|
716
|
+
graph3d.setData(live, state.group);
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (graph3d) { if (graph3d.hasPanel()) graph3d.closePanel(); graph3d.pause(); }
|
|
720
|
+
if (!graph) graph = selfloreGraph(graphOpts());
|
|
721
|
+
graph.setLabels(state.labels);
|
|
722
|
+
graph.resize();
|
|
723
|
+
graph.setData(live, state.group);
|
|
724
|
+
}
|
|
725
|
+
$("gzoomin").onclick = function () { var g = activeGraph(); if (g) g.zoom(1.3); };
|
|
726
|
+
$("gzoomout").onclick = function () { var g = activeGraph(); if (g) g.zoom(1 / 1.3); };
|
|
727
|
+
$("gzoomfit").onclick = function () { var g = activeGraph(); if (g) g.fit(); };
|
|
728
|
+
each("#dimseg button", function (b) {
|
|
729
|
+
b.onclick = function () { state.dim = b.getAttribute("data-dim"); setPref("selflore-graph-dim", state.dim); render(); };
|
|
730
|
+
});
|
|
731
|
+
$("glabels").onclick = function () { state.labels = !state.labels; setPref("selflore-graph-labels", state.labels ? "on" : "off"); render(); };
|
|
732
|
+
|
|
733
|
+
function render() {
|
|
734
|
+
var scope = DATA.entries.filter(inScope);
|
|
735
|
+
var shown = scope.filter(function (e) { return matches(e); });
|
|
736
|
+
renderHead(scope, shown);
|
|
737
|
+
$("graphview").hidden = state.view !== "graph";
|
|
738
|
+
$("listview").hidden = state.view !== "list";
|
|
739
|
+
$("statsview").hidden = state.view !== "stats";
|
|
740
|
+
if (state.view !== "graph" && graph3d) graph3d.pause(); // no rendering while it is out of sight
|
|
741
|
+
if (state.view === "graph") { renderGraph(shown); renderRail(); }
|
|
742
|
+
else if (state.view === "stats") renderStats(shown);
|
|
743
|
+
else { renderFilters(scope); renderList(shown); }
|
|
744
|
+
syncHash();
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
each("#viewseg button", function (b) { b.onclick = function () { state.view = b.getAttribute("data-view"); render(); }; });
|
|
748
|
+
each("#groupseg button", function (b) { b.onclick = function () { state.group = b.getAttribute("data-group"); render(); }; });
|
|
749
|
+
each("#sortseg button", function (b) { b.onclick = function () { state.sort = b.getAttribute("data-sort"); render(); }; });
|
|
750
|
+
each("#rangeseg button", function (b) { b.onclick = function () { state.all = b.getAttribute("data-range") === "all"; render(); }; });
|
|
751
|
+
$("filterbtn").onclick = function () { state.filters = !state.filters; render(); };
|
|
752
|
+
$("prev").onclick = function () { state.week = addDays(state.week, -7); render(); };
|
|
753
|
+
$("next").onclick = function () { state.week = addDays(state.week, 7); render(); };
|
|
754
|
+
var search = $("search");
|
|
755
|
+
search.addEventListener("input", function () { state.q = search.value.trim(); render(); });
|
|
756
|
+
window.addEventListener("hashchange", function () { readHash(false); render(); });
|
|
757
|
+
$("generated").textContent = "Generated " + new Date(DATA.generated_at).toLocaleString();
|
|
758
|
+
|
|
759
|
+
// ---- In-page test (only when served by the local notes server) ----
|
|
760
|
+
var TOKEN = new URLSearchParams(location.search).get("t") || "";
|
|
761
|
+
var test = null; // { questions, i, revealed, results: [{q, grade, message}], skipped, unfair }
|
|
762
|
+
|
|
763
|
+
function api(method, url, body) {
|
|
764
|
+
return fetch(url, {
|
|
765
|
+
method: method,
|
|
766
|
+
headers: { "content-type": "application/json", "x-selflore-token": TOKEN },
|
|
767
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
768
|
+
}).then(function (r) {
|
|
769
|
+
return r.json().catch(function () { return {}; }).then(function (j) {
|
|
770
|
+
if (!r.ok) throw new Error(j.error || ("HTTP " + r.status + (r.status === 403 ? " (reopen with npx selflore notes)" : "")));
|
|
771
|
+
return j;
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
function draftKey(id) { return "selflore-draft:" + id; }
|
|
776
|
+
function getDraft(id) { try { return localStorage.getItem(draftKey(id)) || ""; } catch (e) { return ""; } }
|
|
777
|
+
function setDraft(id, v) { try { if (v) localStorage.setItem(draftKey(id), v); else localStorage.removeItem(draftKey(id)); } catch (e) {} }
|
|
778
|
+
|
|
779
|
+
function showTest(on) {
|
|
780
|
+
$("notesview").hidden = on;
|
|
781
|
+
$("testview").hidden = !on;
|
|
782
|
+
$("viewseg").hidden = on;
|
|
783
|
+
$("testbtn").hidden = on || !DATA.server;
|
|
784
|
+
if (on && graph3d) graph3d.pause();
|
|
785
|
+
window.scrollTo(0, 0);
|
|
786
|
+
if (!on) render();
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function quizUrl(scope) {
|
|
790
|
+
var q = [];
|
|
791
|
+
if (scope && scope.project) q.push("project=" + encodeURIComponent(scope.project));
|
|
792
|
+
if (scope && scope.skill) q.push("skill=" + encodeURIComponent(scope.skill));
|
|
793
|
+
// A search sends the notes it shows, so the test is on exactly what the user is looking at.
|
|
794
|
+
if (scope && scope.q) q.push("ids=" + encodeURIComponent(scopeEntries(scope).slice(0, 12).map(function (e) { return e.id; }).join(",")));
|
|
795
|
+
return "/api/quiz" + (q.length ? "?" + q.join("&") : "");
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// scope = { project, skill, q } tests a selection; no scope is a general test across everything recent.
|
|
799
|
+
function startTest(scope) {
|
|
800
|
+
var btn = $("testbtn");
|
|
801
|
+
btn.disabled = true;
|
|
802
|
+
api("GET", quizUrl(scope)).then(function (j) {
|
|
803
|
+
btn.disabled = false;
|
|
804
|
+
test = { questions: j.questions || [], i: 0, revealed: false, results: [], skipped: 0, unfair: 0, error: "", scope: scope || null };
|
|
805
|
+
showTest(true);
|
|
806
|
+
if (!test.questions.length) renderSummary(); else renderQuestion();
|
|
807
|
+
}, function (err) { btn.disabled = false; btn.textContent = "Test unavailable: " + err.message; });
|
|
808
|
+
}
|
|
809
|
+
// Leaving a test nobody answered goes straight back; otherwise the summary says what was saved.
|
|
810
|
+
function endTest() { if (test.results.length || test.unfair) renderSummary(); else showTest(false); }
|
|
811
|
+
|
|
812
|
+
function renderQuestion() {
|
|
813
|
+
var q = test.questions[test.i];
|
|
814
|
+
var n = test.questions.length;
|
|
815
|
+
var view = $("testview"); view.textContent = "";
|
|
816
|
+
|
|
817
|
+
var c = h("article", { class: "qcard" });
|
|
818
|
+
c.appendChild(h("div", { class: "meta", text: [q.project, topicsOf(q).join(", "), KIND_LABEL[q.kind] || q.kind, LEVEL_LABEL[q.level] || q.level, q.retest ? "You missed this before" : null].filter(Boolean).join(" · ") }));
|
|
819
|
+
c.appendChild(rich(h("div", { class: "q" }), q.testable));
|
|
820
|
+
var files = h("div", { class: "files" });
|
|
821
|
+
q.paths.forEach(function (p) { files.appendChild(h("code", { text: p })); });
|
|
822
|
+
if (q.paths.length) c.appendChild(files);
|
|
823
|
+
// Detail questions are often about the code itself, so it can be shown before answering.
|
|
824
|
+
var codeFirst = q.snippet && q.level === "detail";
|
|
825
|
+
if (codeFirst) c.appendChild(h("details", { class: "reveal" },
|
|
826
|
+
h("summary", null, h("span", { class: "show", text: "Show code" }), h("span", { class: "hide", text: "Hide code" })),
|
|
827
|
+
codeBlock(q)));
|
|
828
|
+
|
|
829
|
+
var reply = h("textarea", { class: "reply", "aria-label": "Your answer", placeholder: "Your answer: the why, and what would break. ⌘/Ctrl + Enter to reveal" });
|
|
830
|
+
reply.value = getDraft(q.id);
|
|
831
|
+
reply.addEventListener("input", function () { setDraft(q.id, reply.value); });
|
|
832
|
+
c.appendChild(reply);
|
|
833
|
+
|
|
834
|
+
var err = h("div", { class: "err" });
|
|
835
|
+
var actions = h("div", { class: "actions" });
|
|
836
|
+
var unfairBtn = h("button", { class: "btn quiet", text: "Unfair question", title: "Never ask this again", onclick: unfair });
|
|
837
|
+
function lock(on) { Array.prototype.forEach.call(actions.querySelectorAll("button"), function (b) { b.disabled = on; }); unfairBtn.disabled = on; }
|
|
838
|
+
function next() { test.i++; test.revealed = false; if (test.i >= test.questions.length) renderSummary(); else renderQuestion(); }
|
|
839
|
+
function grade(g) {
|
|
840
|
+
lock(true); err.textContent = "";
|
|
841
|
+
api("POST", "/api/answer", { entry_id: q.id, grade: g, answer: reply.value, scoped: !!test.scope }).then(function (j) {
|
|
842
|
+
test.results.push({ q: q, grade: g, message: j.message || "" });
|
|
843
|
+
setDraft(q.id, "");
|
|
844
|
+
next();
|
|
845
|
+
}, function (e) { lock(false); err.textContent = "Couldn't save: " + e.message; });
|
|
846
|
+
}
|
|
847
|
+
function unfair() {
|
|
848
|
+
lock(true); err.textContent = "";
|
|
849
|
+
api("POST", "/api/suppress", { entry_id: q.id }).then(function () { test.unfair++; setDraft(q.id, ""); next(); },
|
|
850
|
+
function (e) { lock(false); err.textContent = "Couldn't save: " + e.message; });
|
|
851
|
+
}
|
|
852
|
+
function reveal() {
|
|
853
|
+
test.revealed = true;
|
|
854
|
+
var ans = h("div", { class: "answer" });
|
|
855
|
+
if (reply.value.trim()) { ans.appendChild(h("div", { class: "label", text: "Your answer" })); ans.appendChild(h("div", { class: "yours", text: reply.value.trim() })); }
|
|
856
|
+
ans.appendChild(h("div", { class: "label", text: "From your notes" }));
|
|
857
|
+
paras(ans, q.prose);
|
|
858
|
+
if (q.snippet && !codeFirst) ans.appendChild(codeBlock(q));
|
|
859
|
+
c.insertBefore(ans, actions);
|
|
860
|
+
actions.textContent = "";
|
|
861
|
+
actions.appendChild(h("button", { class: "btn", onclick: function () { grade("got"); } }, "Got it", h("kbd", { text: "1" })));
|
|
862
|
+
actions.appendChild(h("button", { class: "btn", onclick: function () { grade("partial"); } }, "Partial", h("kbd", { text: "2" })));
|
|
863
|
+
actions.appendChild(h("button", { class: "btn", onclick: function () { grade("missed"); } }, "Missed", h("kbd", { text: "3" })));
|
|
864
|
+
// The answer is now shown read-only above the notes; drop the box so 1/2/3 grade instead of typing.
|
|
865
|
+
reply.remove();
|
|
866
|
+
actions.firstChild.focus({ preventScroll: true });
|
|
867
|
+
actions.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
868
|
+
}
|
|
869
|
+
test.grade = grade; test.reveal = reveal;
|
|
870
|
+
reply.addEventListener("keydown", function (ev) { if (ev.key === "Enter" && (ev.metaKey || ev.ctrlKey) && !test.revealed) { ev.preventDefault(); reveal(); } });
|
|
871
|
+
|
|
872
|
+
view.appendChild(h("div", { class: "testhead" },
|
|
873
|
+
h("span", { text: "Question " + (test.i + 1) + " of " + n + (test.scope ? " on " + scopeText(test.scope) : "") + ". Answer in your own words, then grade yourself honestly." }),
|
|
874
|
+
h("span", { class: "spacer" }), unfairBtn,
|
|
875
|
+
h("button", { class: "btn quiet", text: "End test", onclick: endTest })));
|
|
876
|
+
var bar = h("div", { class: "progress", role: "progressbar", "aria-valuemin": "0", "aria-valuemax": String(n), "aria-valuenow": String(test.i) }, h("span"));
|
|
877
|
+
bar.firstChild.style.width = Math.round((test.i / n) * 100) + "%";
|
|
878
|
+
view.appendChild(bar);
|
|
879
|
+
|
|
880
|
+
actions.appendChild(h("button", { class: "btn primary", text: "Reveal answer", onclick: reveal }));
|
|
881
|
+
actions.appendChild(h("button", { class: "btn", text: "Skip", title: "Not recorded; it stays for a later test", onclick: function () { test.skipped++; next(); } }));
|
|
882
|
+
c.appendChild(actions);
|
|
883
|
+
c.appendChild(err);
|
|
884
|
+
view.appendChild(c);
|
|
885
|
+
reply.focus();
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
function renderSummary() {
|
|
889
|
+
var view = $("testview"); view.textContent = "";
|
|
890
|
+
var r = test.results;
|
|
891
|
+
var count = function (g) { return r.filter(function (x) { return x.grade === g; }).length; };
|
|
892
|
+
var left = Math.max(0, test.questions.length - test.i);
|
|
893
|
+
var box = h("div", { class: "qcard summary" });
|
|
894
|
+
if (!test.questions.length) {
|
|
895
|
+
box.appendChild(h("div", { class: "q", text: "Nothing to test right now" }));
|
|
896
|
+
box.appendChild(h("p", { text: test.scope ? "Nothing in " + scopeText(test.scope) + " is waiting to be tested." : "Everything has been asked and nothing is waiting to be revisited. Keep working; new notes show up here." }));
|
|
897
|
+
} else {
|
|
898
|
+
box.appendChild(h("div", { class: "q", text: left ? "Stopped after " + plural(test.i, "question", "questions") : "Test done" }));
|
|
899
|
+
box.appendChild(facts(h("p", { class: "figs" }), [[count("got"), "got it"], [count("partial"), "partial"], [count("missed"), "missed"]]));
|
|
900
|
+
var notes = [];
|
|
901
|
+
var retestPass = r.filter(function (x) { return x.q.retest && x.grade === "got"; }).length;
|
|
902
|
+
if (retestPass) notes.push(retestPass + " you had missed before, now right.");
|
|
903
|
+
if (r.length) notes.push("Every answer is already saved.");
|
|
904
|
+
if (left) notes.push(plural(left, "question", "questions") + " not answered; " + (left === 1 ? "it stays" : "they stay") + " in the pool for next time.");
|
|
905
|
+
if (test.skipped) notes.push(test.skipped + " skipped (not recorded).");
|
|
906
|
+
if (test.unfair) notes.push(test.unfair + " marked unfair and removed from future tests.");
|
|
907
|
+
var dues = r.filter(function (x) { return x.grade !== "got"; }).map(function (x) { return x.q.testable; });
|
|
908
|
+
paras(box, notes.join(" "));
|
|
909
|
+
if (dues.length) {
|
|
910
|
+
box.appendChild(h("div", { class: "label", text: "Asked first next time you test this area" }));
|
|
911
|
+
var ul = h("ul"); dues.forEach(function (d) { ul.appendChild(rich(h("li"), d)); }); box.appendChild(ul);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
var actions = h("div", { class: "actions" });
|
|
915
|
+
if (left && test.questions.length) actions.appendChild(h("button", { class: "btn primary", text: "Resume", onclick: function () { renderQuestion(); } }));
|
|
916
|
+
// A reload picks up the new grades; the URL keeps the view and filters the test was started from.
|
|
917
|
+
actions.appendChild(h("button", { class: "btn", text: "Back to notes", onclick: function () { location.reload(); } }));
|
|
918
|
+
box.appendChild(actions);
|
|
919
|
+
view.appendChild(box);
|
|
920
|
+
test.grade = test.reveal = null;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (DATA.server) {
|
|
924
|
+
var tb = $("testbtn");
|
|
925
|
+
tb.hidden = false;
|
|
926
|
+
tb.onclick = function () { startTest(null); };
|
|
927
|
+
api("GET", "/api/quiz").then(function (j) {
|
|
928
|
+
var n = (j.questions || []).length;
|
|
929
|
+
tb.textContent = n ? "Test me · " + n : "Test me";
|
|
930
|
+
}, function () {});
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
document.addEventListener("keydown", function (ev) {
|
|
934
|
+
if (test && !$("testview").hidden) {
|
|
935
|
+
if (ev.metaKey || ev.ctrlKey || ev.altKey || (ev.target && ev.target.tagName === "TEXTAREA")) return;
|
|
936
|
+
if (test.grade && test.revealed && ["1", "2", "3"].indexOf(ev.key) >= 0) { ev.preventDefault(); test.grade(["got", "partial", "missed"][+ev.key - 1]); }
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
if (ev.target && (ev.target.tagName === "INPUT" || ev.target.tagName === "TEXTAREA")) {
|
|
940
|
+
if (ev.key === "Escape") ev.target.blur();
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
if (ev.metaKey || ev.ctrlKey || ev.altKey) return;
|
|
944
|
+
if (ev.key === "Escape" && activeGraph() && activeGraph().hasPanel()) activeGraph().closePanel();
|
|
945
|
+
else if (ev.key === "/") { ev.preventDefault(); if (state.view !== "list") { state.view = "list"; render(); } search.focus(); }
|
|
946
|
+
else if (ev.key === "g") { state.view = state.view === "graph" ? "list" : "graph"; render(); }
|
|
947
|
+
else if (ev.key === "a" && state.view === "list") {
|
|
948
|
+
var all = Array.prototype.slice.call(document.querySelectorAll("#list details.note"));
|
|
949
|
+
var open = all.some(function (d) { return !d.open; });
|
|
950
|
+
all.forEach(function (d) { d.open = open; });
|
|
951
|
+
}
|
|
952
|
+
else if (ev.key === "ArrowLeft" && !state.all && !$("prev").disabled) $("prev").click();
|
|
953
|
+
else if (ev.key === "ArrowRight" && !state.all && !$("next").disabled) $("next").click();
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
if (DATA.server) $("testhint").textContent = "take a test here (you grade yourself), or run /selflore test in Claude Code for graded questions";
|
|
957
|
+
render();
|
|
958
|
+
})();
|
|
959
|
+
`;
|