selflore 0.0.2 → 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.
- package/README.md +36 -6
- package/dist/cli.js +10 -2
- package/dist/hooks/capture-worker.js +27 -0
- package/dist/hooks/io.js +6 -1
- package/dist/hooks/session-start.js +2 -8
- package/dist/hooks/stop.js +3 -21
- package/dist/hooks/user-prompt-submit.js +9 -0
- package/dist/init.js +58 -8
- package/dist/lib/background.js +154 -0
- package/dist/lib/capture-prompt.js +33 -0
- package/dist/lib/commands.js +134 -44
- package/dist/lib/config.js +63 -4
- package/dist/lib/entries.js +27 -0
- package/dist/lib/hook-logic.js +72 -0
- package/dist/lib/install.js +2 -3
- package/dist/lib/notes-html.js +19 -10
- package/dist/lib/notes.js +12 -5
- package/dist/lib/nudge.js +6 -0
- package/dist/lib/results.js +10 -1
- package/dist/lib/session.js +27 -1
- package/dist/lib/settings.js +5 -1
- package/dist/lib/stats.js +5 -0
- package/dist/lib/transcript.js +146 -24
- package/dist/sl.js +8 -14
- package/package.json +1 -1
- package/skill/SKILL.md +25 -11
- package/skill/references/capture.md +12 -9
- package/skill/references/log.md +2 -2
- package/skill/references/test.md +22 -9
package/dist/lib/commands.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { readConfig, writeConfig } from "./config.js";
|
|
4
|
-
import {
|
|
3
|
+
import { BALANCES, configExists, designShare, describeFocus, effectiveFocus, FOCUS_MODES, readConfig, writeConfig, } from "./config.js";
|
|
4
|
+
import { inferLevel, listEntries, MERGE_SIMILARITY, parseEntry, readEntry, similarity, uniqueId, validateEntry, writeEntry, } from "./entries.js";
|
|
5
5
|
import { applyGrade, dueItems, readQueue, writeQueue } from "./queue.js";
|
|
6
6
|
import { appendResult, QUESTION_TYPES, readResults, testedEntryIds } from "./results.js";
|
|
7
7
|
import { readSession, writeSession } from "./session.js";
|
|
8
8
|
import fs from "node:fs";
|
|
9
|
-
import { renderNotes } from "./notes.js";
|
|
9
|
+
import { renderNotes, staleBefore } from "./notes.js";
|
|
10
10
|
import { buildNotesData, renderNotesHtml } from "./notes-html.js";
|
|
11
11
|
import { openInBrowser } from "./open.js";
|
|
12
12
|
import { paths } from "./paths.js";
|
|
@@ -38,58 +38,86 @@ function today(now) {
|
|
|
38
38
|
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
39
39
|
}
|
|
40
40
|
function summarize(e) {
|
|
41
|
-
return `- ${e.id} [${e.kind}/${e.skill}] ${e.testable}`;
|
|
41
|
+
return `- ${e.id} [${e.kind}/${e.level}/${e.skill}] ${e.testable}`;
|
|
42
42
|
}
|
|
43
|
-
/**
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Find an untested entry this one should be merged into: same project, a shared path,
|
|
45
|
+
* and a similar question. Long sessions keep touching the same area; this keeps one
|
|
46
|
+
* entry per idea instead of a pile of near-duplicates.
|
|
47
|
+
*/
|
|
48
|
+
export function findMergeTarget(candidate, tested) {
|
|
49
|
+
const queue = readQueue();
|
|
50
|
+
let best = null;
|
|
51
|
+
let bestScore = 0;
|
|
52
|
+
for (const e of listEntries()) {
|
|
53
|
+
if (e.suppressed || e.project !== candidate.project || tested.has(e.id) || queue[e.id])
|
|
54
|
+
continue;
|
|
55
|
+
const sharesPath = e.paths.some((p) => candidate.paths.includes(p));
|
|
56
|
+
const score = similarity(e.testable, candidate.testable);
|
|
57
|
+
const threshold = sharesPath ? MERGE_SIMILARITY : 0.8; // without a shared file, only near-identical questions merge
|
|
58
|
+
if (score >= threshold && score > bestScore) {
|
|
59
|
+
best = e;
|
|
60
|
+
bestScore = score;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return best;
|
|
64
|
+
}
|
|
65
|
+
/** Enrich, merge-or-create and store a validated entry. Shared by `entry add` and the background worker. */
|
|
66
|
+
export function storeEntry(parsed, opts) {
|
|
45
67
|
const now = opts.now ?? new Date();
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
68
|
+
const info = projectInfo(opts.cwd);
|
|
69
|
+
const project = parsed.project ? String(parsed.project) : info.project;
|
|
70
|
+
const commit = parsed.commit ? String(parsed.commit) : info.commit;
|
|
71
|
+
const paths = Array.isArray(parsed.paths) ? parsed.paths.map(String) : [];
|
|
72
|
+
const testable = String(parsed.testable);
|
|
73
|
+
const level = parsed.level ?? inferLevel(parsed.kind);
|
|
51
74
|
const session = readSession(opts.session);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
const target = findMergeTarget({ project, paths, testable }, testedEntryIds(readResults()));
|
|
76
|
+
if (target) {
|
|
77
|
+
const merged = {
|
|
78
|
+
...target,
|
|
79
|
+
kind: parsed.kind,
|
|
80
|
+
level,
|
|
81
|
+
skill: String(parsed.skill),
|
|
82
|
+
paths: [...new Set([...target.paths, ...paths])],
|
|
83
|
+
testable,
|
|
84
|
+
commit: commit || target.commit,
|
|
85
|
+
body: parsed.body ?? target.body,
|
|
86
|
+
};
|
|
87
|
+
writeEntry(merged);
|
|
88
|
+
if (!session.entries.includes(merged.id))
|
|
89
|
+
writeSession(opts.session, { ...session, entries: [...session.entries, merged.id] });
|
|
90
|
+
return { action: "updated", entry: merged };
|
|
61
91
|
}
|
|
62
|
-
else if (sessionEntries.length >= config.max_entries_per_session) {
|
|
63
|
-
if (!opts.manual) {
|
|
64
|
-
const current = sessionEntries.map((id) => readEntry(id)).filter((e) => e !== null);
|
|
65
|
-
return fail([
|
|
66
|
-
`cap reached: ${sessionEntries.length}/${config.max_entries_per_session} entries this session.`,
|
|
67
|
-
`Keep the ones that best match keep_sharp (${config.keep_sharp.join(", ")}).`,
|
|
68
|
-
`If the new one is better, rerun with \`entry replace <id>\`; otherwise drop it.`,
|
|
69
|
-
...current.map(summarize),
|
|
70
|
-
].join("\n"), 2);
|
|
71
|
-
}
|
|
72
|
-
warning = `\nnote: over the session cap (${config.max_entries_per_session}); logged anyway because it was manual.`;
|
|
73
|
-
}
|
|
74
|
-
const { project, commit } = projectInfo(opts.cwd);
|
|
75
92
|
const date = typeof parsed.date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(parsed.date) ? parsed.date : today(now);
|
|
76
93
|
const entry = {
|
|
77
|
-
id: uniqueId(date,
|
|
94
|
+
id: uniqueId(date, testable),
|
|
78
95
|
date,
|
|
79
96
|
session: opts.session,
|
|
80
|
-
project
|
|
81
|
-
commit
|
|
97
|
+
project,
|
|
98
|
+
commit,
|
|
82
99
|
kind: parsed.kind,
|
|
100
|
+
level,
|
|
83
101
|
skill: String(parsed.skill),
|
|
84
|
-
paths
|
|
85
|
-
testable
|
|
102
|
+
paths,
|
|
103
|
+
testable,
|
|
86
104
|
suppressed: false,
|
|
87
105
|
body: parsed.body ?? "",
|
|
88
106
|
};
|
|
89
107
|
writeEntry(entry);
|
|
90
|
-
writeSession(opts.session, { ...session, entries: [...
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
writeSession(opts.session, { ...session, entries: [...session.entries, entry.id] });
|
|
109
|
+
return { action: "logged", entry };
|
|
110
|
+
}
|
|
111
|
+
/** Validate and store an entry from markdown. There is no per-session cap; near-duplicates are merged. */
|
|
112
|
+
export function addEntry(markdown, opts) {
|
|
113
|
+
const parsed = parseEntry(markdown);
|
|
114
|
+
const errors = validateEntry(parsed);
|
|
115
|
+
if (errors.length)
|
|
116
|
+
return fail(`entry rejected:\n${errors.map((e) => ` - ${e}`).join("\n")}`);
|
|
117
|
+
const { action, entry } = storeEntry(parsed, opts);
|
|
118
|
+
return ok(action === "updated"
|
|
119
|
+
? `updated ${entry.id} (merged with a similar untested entry) [${entry.level}]`
|
|
120
|
+
: `logged ${entry.id} [${entry.level}]`);
|
|
93
121
|
}
|
|
94
122
|
export function listCmd(session) {
|
|
95
123
|
let entries = listEntries();
|
|
@@ -100,6 +128,16 @@ export function listCmd(session) {
|
|
|
100
128
|
return ok(entries.length ? entries.map(summarize).join("\n") : "no entries");
|
|
101
129
|
}
|
|
102
130
|
export const QUIZ_SIZE = 10;
|
|
131
|
+
/** Split QUIZ_SIZE into design/detail counts from the candidates' effective focus (per project). */
|
|
132
|
+
export function targetSplit(entries, config = readConfig()) {
|
|
133
|
+
if (!entries.length) {
|
|
134
|
+
const design = Math.round(QUIZ_SIZE * designShare(effectiveFocus(config)));
|
|
135
|
+
return { design, detail: QUIZ_SIZE - design };
|
|
136
|
+
}
|
|
137
|
+
const share = entries.reduce((sum, e) => sum + designShare(effectiveFocus(config, e.project)), 0) / entries.length;
|
|
138
|
+
const design = Math.round(QUIZ_SIZE * share);
|
|
139
|
+
return { design, detail: QUIZ_SIZE - design };
|
|
140
|
+
}
|
|
103
141
|
/** Everything the skill needs to build this week's quiz, as JSON. */
|
|
104
142
|
export function quizInput(now = new Date()) {
|
|
105
143
|
const config = readConfig();
|
|
@@ -109,16 +147,22 @@ export function quizInput(now = new Date()) {
|
|
|
109
147
|
const due = dueItems(queue, now);
|
|
110
148
|
const dueIds = new Set(due.map((d) => d.entry_id));
|
|
111
149
|
const entries = listEntries().filter((e) => !e.suppressed);
|
|
150
|
+
const cutoff = staleBefore(now);
|
|
151
|
+
const withFocus = (e) => ({ ...e, focus: effectiveFocus(config, e.project).mode });
|
|
112
152
|
const retests = entries
|
|
113
153
|
.filter((e) => dueIds.has(e.id))
|
|
114
|
-
.map((e) => ({ ...e, retest: { streak: queue[e.id].streak, due: queue[e.id].due[0] } }));
|
|
115
|
-
const
|
|
154
|
+
.map((e) => ({ ...withFocus(e), retest: { streak: queue[e.id].streak, due: queue[e.id].due[0] } }));
|
|
155
|
+
const untested = entries.filter((e) => !tested.has(e.id) && !queue[e.id]);
|
|
156
|
+
// Untested for 3+ weeks: out of the quiz pool (still visible in notes), so a heavy week can't create an endless backlog.
|
|
157
|
+
const fresh = untested.filter((e) => e.date >= cutoff);
|
|
116
158
|
return ok(JSON.stringify({
|
|
117
159
|
now: now.toISOString(),
|
|
118
160
|
config: { rating: config.rating, keep_sharp: config.keep_sharp, last_test_at: config.last_test_at },
|
|
119
161
|
target_questions: QUIZ_SIZE,
|
|
162
|
+
target_split: targetSplit([...retests, ...fresh], config),
|
|
163
|
+
stale_count: untested.length - fresh.length,
|
|
120
164
|
retests,
|
|
121
|
-
fresh,
|
|
165
|
+
fresh: fresh.map(withFocus),
|
|
122
166
|
}, null, 2));
|
|
123
167
|
}
|
|
124
168
|
export function recordCmd(entryId, grade, type, now = new Date()) {
|
|
@@ -136,6 +180,7 @@ export function recordCmd(entryId, grade, type, now = new Date()) {
|
|
|
136
180
|
entry_id: entryId,
|
|
137
181
|
project: entry.project,
|
|
138
182
|
skill: entry.skill,
|
|
183
|
+
level: entry.level,
|
|
139
184
|
question_type: type,
|
|
140
185
|
grade: grade,
|
|
141
186
|
is_retest: isRetest,
|
|
@@ -195,3 +240,48 @@ export function notesCmd(opts = {}, now = new Date()) {
|
|
|
195
240
|
project: opts.project,
|
|
196
241
|
}));
|
|
197
242
|
}
|
|
243
|
+
/** Parse `focus` CLI args: [mode] [--balance x] [--project] [--reset]. Shared by `selflore` and `sl`. */
|
|
244
|
+
export function focusArgs(args, cwd = process.cwd()) {
|
|
245
|
+
const i = args.indexOf("--balance");
|
|
246
|
+
const mode = args.find((a, j) => !a.startsWith("--") && (i < 0 || j !== i + 1));
|
|
247
|
+
return {
|
|
248
|
+
mode,
|
|
249
|
+
balance: i >= 0 ? args[i + 1] : undefined,
|
|
250
|
+
project: args.includes("--project"),
|
|
251
|
+
reset: args.includes("--reset"),
|
|
252
|
+
cwd,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/** Show or change the capture focus, globally or for the current project (which then takes priority). */
|
|
256
|
+
export function focusCmd(opts) {
|
|
257
|
+
if (!configExists())
|
|
258
|
+
return fail("selflore is not set up yet; run `npx selflore init` first");
|
|
259
|
+
const config = readConfig();
|
|
260
|
+
const project = projectInfo(opts.cwd).project;
|
|
261
|
+
if (opts.mode && !FOCUS_MODES.includes(opts.mode))
|
|
262
|
+
return fail(`focus must be one of ${FOCUS_MODES.join(" | ")}`);
|
|
263
|
+
if (opts.balance && !BALANCES.includes(opts.balance))
|
|
264
|
+
return fail(`--balance must be one of ${BALANCES.join(" | ")}`);
|
|
265
|
+
if (opts.reset) {
|
|
266
|
+
if (!opts.project)
|
|
267
|
+
return fail("--reset only applies with --project (it removes this project's override)");
|
|
268
|
+
const { [project]: _removed, ...rest } = config.projects;
|
|
269
|
+
writeConfig({ ...config, projects: rest });
|
|
270
|
+
}
|
|
271
|
+
else if (opts.mode || opts.balance) {
|
|
272
|
+
const change = {
|
|
273
|
+
...(opts.mode ? { mode: opts.mode } : {}),
|
|
274
|
+
...(opts.balance ? { balance: opts.balance } : {}),
|
|
275
|
+
};
|
|
276
|
+
if (opts.project)
|
|
277
|
+
writeConfig({ ...config, projects: { ...config.projects, [project]: { ...config.projects[project], ...change } } });
|
|
278
|
+
else
|
|
279
|
+
writeConfig({ ...config, focus: { ...config.focus, ...change } });
|
|
280
|
+
}
|
|
281
|
+
const next = readConfig();
|
|
282
|
+
const eff = effectiveFocus(next, project);
|
|
283
|
+
return ok([
|
|
284
|
+
`global focus: ${describeFocus(next.focus)}`,
|
|
285
|
+
`${project}: ${describeFocus(eff)} (${eff.source === "project" ? "project override" : "from global"})`,
|
|
286
|
+
].join("\n"));
|
|
287
|
+
}
|
package/dist/lib/config.js
CHANGED
|
@@ -1,15 +1,54 @@
|
|
|
1
1
|
import { readJson, writeJson } from "./fsutil.js";
|
|
2
2
|
import { paths } from "./paths.js";
|
|
3
|
+
export const INTENSITIES = ["light", "normal", "thorough"];
|
|
4
|
+
export const FOCUS_MODES = ["details", "design", "mixed"];
|
|
5
|
+
export const BALANCES = ["design", "balanced", "details"];
|
|
6
|
+
export const CAPTURE_MODES = ["background", "quiet", "off"];
|
|
7
|
+
export const CAPTURE_MODELS = ["session", "sonnet", "haiku"];
|
|
3
8
|
export const DEFAULT_CONFIG = {
|
|
4
9
|
rating: 5,
|
|
5
10
|
keep_sharp: ["debugging"],
|
|
6
|
-
|
|
11
|
+
capture_intensity: "normal",
|
|
12
|
+
focus: { mode: "mixed", balance: "balanced" },
|
|
13
|
+
projects: {},
|
|
14
|
+
capture: "background",
|
|
15
|
+
capture_model: "session",
|
|
7
16
|
nudge: true,
|
|
8
17
|
cadence: "weekly",
|
|
9
18
|
last_test_at: null,
|
|
10
19
|
};
|
|
20
|
+
const pick = (v, allowed, fallback) => allowed.includes(v) ? v : fallback;
|
|
21
|
+
/** Fill in new fields and convert old ones (v0.2's max_entries_per_session → capture_intensity). */
|
|
22
|
+
export function migrateConfig(raw) {
|
|
23
|
+
const legacyCap = typeof raw.max_entries_per_session === "number" ? raw.max_entries_per_session : null;
|
|
24
|
+
const intensityFromCap = legacyCap === null ? null : legacyCap <= 3 ? "light" : legacyCap <= 5 ? "normal" : "thorough";
|
|
25
|
+
const focus = (raw.focus ?? {});
|
|
26
|
+
const projects = {};
|
|
27
|
+
for (const [name, f] of Object.entries((raw.projects ?? {}))) {
|
|
28
|
+
const o = {};
|
|
29
|
+
if (FOCUS_MODES.includes(f?.mode))
|
|
30
|
+
o.mode = f.mode;
|
|
31
|
+
if (BALANCES.includes(f?.balance))
|
|
32
|
+
o.balance = f.balance;
|
|
33
|
+
if (Object.keys(o).length)
|
|
34
|
+
projects[name] = o;
|
|
35
|
+
}
|
|
36
|
+
const { max_entries_per_session: _legacy, ...rest } = raw;
|
|
37
|
+
return {
|
|
38
|
+
...DEFAULT_CONFIG,
|
|
39
|
+
...rest,
|
|
40
|
+
capture_intensity: pick(raw.capture_intensity, INTENSITIES, intensityFromCap ?? DEFAULT_CONFIG.capture_intensity),
|
|
41
|
+
focus: {
|
|
42
|
+
mode: pick(focus.mode, FOCUS_MODES, DEFAULT_CONFIG.focus.mode),
|
|
43
|
+
balance: pick(focus.balance, BALANCES, DEFAULT_CONFIG.focus.balance),
|
|
44
|
+
},
|
|
45
|
+
projects,
|
|
46
|
+
capture: pick(raw.capture, CAPTURE_MODES, DEFAULT_CONFIG.capture),
|
|
47
|
+
capture_model: pick(raw.capture_model, CAPTURE_MODELS, DEFAULT_CONFIG.capture_model),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
11
50
|
export function readConfig() {
|
|
12
|
-
return
|
|
51
|
+
return migrateConfig(readJson(paths.config(), {}));
|
|
13
52
|
}
|
|
14
53
|
export function configExists() {
|
|
15
54
|
return readJson(paths.config(), null) !== null;
|
|
@@ -17,6 +56,26 @@ export function configExists() {
|
|
|
17
56
|
export function writeConfig(config) {
|
|
18
57
|
writeJson(paths.config(), config);
|
|
19
58
|
}
|
|
20
|
-
|
|
21
|
-
|
|
59
|
+
/** The focus that applies to a project: its override wins, field by field, over the global focus. */
|
|
60
|
+
export function effectiveFocus(config, project) {
|
|
61
|
+
const o = project ? config.projects[project] : undefined;
|
|
62
|
+
return {
|
|
63
|
+
mode: o?.mode ?? config.focus.mode,
|
|
64
|
+
balance: o?.balance ?? config.focus.balance,
|
|
65
|
+
source: o && (o.mode || o.balance) ? "project" : "global",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** How many of `total` quiz questions should be design-level for a focus. */
|
|
69
|
+
export function designShare(focus) {
|
|
70
|
+
if (focus.mode === "design")
|
|
71
|
+
return 1;
|
|
72
|
+
if (focus.mode === "details")
|
|
73
|
+
return 0;
|
|
74
|
+
return focus.balance === "design" ? 0.7 : focus.balance === "details" ? 0.3 : 0.5;
|
|
75
|
+
}
|
|
76
|
+
export function describeFocus(focus) {
|
|
77
|
+
if (focus.mode !== "mixed")
|
|
78
|
+
return focus.mode;
|
|
79
|
+
const b = { design: "mostly design", balanced: "balanced", details: "mostly details" }[focus.balance];
|
|
80
|
+
return `mixed (${b})`;
|
|
22
81
|
}
|
package/dist/lib/entries.js
CHANGED
|
@@ -2,6 +2,11 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { paths } from "./paths.js";
|
|
4
4
|
export const KINDS = ["bug", "decision", "concept", "pattern"];
|
|
5
|
+
export const LEVELS = ["detail", "design"];
|
|
6
|
+
/** Entries from before `level` existed: decisions are design-level, everything else detail. */
|
|
7
|
+
export function inferLevel(kind) {
|
|
8
|
+
return kind === "decision" ? "design" : "detail";
|
|
9
|
+
}
|
|
5
10
|
export const MAX_BODY_WORDS = 150; // PRD says ~120; small grace before rejecting
|
|
6
11
|
export const MAX_SNIPPET_LINES = 40;
|
|
7
12
|
const FIELD_ORDER = [
|
|
@@ -11,6 +16,7 @@ const FIELD_ORDER = [
|
|
|
11
16
|
"project",
|
|
12
17
|
"commit",
|
|
13
18
|
"kind",
|
|
19
|
+
"level",
|
|
14
20
|
"skill",
|
|
15
21
|
"paths",
|
|
16
22
|
"testable",
|
|
@@ -92,6 +98,8 @@ export function validateEntry(e) {
|
|
|
92
98
|
errors.push("missing `testable` — if you cannot write a test question, the moment is not worth logging");
|
|
93
99
|
if (!e.kind || !KINDS.includes(e.kind))
|
|
94
100
|
errors.push(`\`kind\` must be one of ${KINDS.join(" | ")}`);
|
|
101
|
+
if (e.level !== undefined && !LEVELS.includes(e.level))
|
|
102
|
+
errors.push(`\`level\` must be one of ${LEVELS.join(" | ")}`);
|
|
95
103
|
if (!e.skill || !String(e.skill).trim())
|
|
96
104
|
errors.push("missing `skill`");
|
|
97
105
|
const { prose, snippet } = splitBody(e.body ?? "");
|
|
@@ -166,6 +174,7 @@ function normalize(p, id) {
|
|
|
166
174
|
project: String(p.project ?? ""),
|
|
167
175
|
commit: String(p.commit ?? ""),
|
|
168
176
|
kind: (p.kind ?? "concept"),
|
|
177
|
+
level: LEVELS.includes(p.level) ? p.level : inferLevel(p.kind),
|
|
169
178
|
skill: String(p.skill ?? ""),
|
|
170
179
|
paths: Array.isArray(p.paths) ? p.paths.map(String) : p.paths ? [String(p.paths)] : [],
|
|
171
180
|
testable: String(p.testable ?? ""),
|
|
@@ -173,3 +182,21 @@ function normalize(p, id) {
|
|
|
173
182
|
body: p.body ?? "",
|
|
174
183
|
};
|
|
175
184
|
}
|
|
185
|
+
// Question scaffolding that says nothing about the topic ("why does … happen if …").
|
|
186
|
+
const STOPWORDS = new Set("the and for are was were why what when where which who how does did doesn don isn can could would should will this that these those with without from into than then there here have has had not but its it's you your our they them their about after before over under also just only use used using happen happens happened instead break breaks".split(" "));
|
|
187
|
+
function words(s) {
|
|
188
|
+
return new Set(s.toLowerCase().match(/[a-z0-9_]+/g)?.filter((w) => w.length > 2 && !STOPWORDS.has(w)) ?? []);
|
|
189
|
+
}
|
|
190
|
+
/** Jaccard similarity of the word sets of two strings (words of 3+ chars). */
|
|
191
|
+
export function similarity(a, b) {
|
|
192
|
+
const wa = words(a);
|
|
193
|
+
const wb = words(b);
|
|
194
|
+
if (!wa.size || !wb.size)
|
|
195
|
+
return 0;
|
|
196
|
+
let inter = 0;
|
|
197
|
+
for (const w of wa)
|
|
198
|
+
if (wb.has(w))
|
|
199
|
+
inter++;
|
|
200
|
+
return inter / (wa.size + wb.size - inter);
|
|
201
|
+
}
|
|
202
|
+
export const MERGE_SIMILARITY = 0.5;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { configExists, readConfig } from "./config.js";
|
|
2
|
+
import { keepWriteFor, spawnWorker } from "./background.js";
|
|
3
|
+
import { isCapturing, readSession, takeAnnounce, updateSession } from "./session.js";
|
|
4
|
+
import { anyTrigger, describeTriggers, detectTriggers, MIN_LINES, readTranscriptFrom } from "./transcript.js";
|
|
5
|
+
import { listEntries } from "./entries.js";
|
|
6
|
+
import { sessionStartContext } from "./nudge.js";
|
|
7
|
+
/**
|
|
8
|
+
* The Stop hook. It never blocks the turn: it only looks at work since the last capture and,
|
|
9
|
+
* if that work has triggers, either starts a detached background capture or (quiet mode)
|
|
10
|
+
* leaves a hint for the next prompt.
|
|
11
|
+
*/
|
|
12
|
+
export function handleStop(input, deps = {}) {
|
|
13
|
+
if (!input.session_id || !configExists())
|
|
14
|
+
return "none";
|
|
15
|
+
const config = readConfig();
|
|
16
|
+
if (config.capture === "off")
|
|
17
|
+
return "off";
|
|
18
|
+
const now = deps.now ?? new Date();
|
|
19
|
+
const session = readSession(input.session_id);
|
|
20
|
+
// Don't advance past work a running capture hasn't finished; it'll be picked up next turn.
|
|
21
|
+
if (config.capture === "background" && isCapturing(session, now))
|
|
22
|
+
return "locked";
|
|
23
|
+
const cwd = input.cwd ?? process.cwd();
|
|
24
|
+
const { text, start, end } = readTranscriptFrom(input.transcript_path, session.scanned_offset);
|
|
25
|
+
const triggers = detectTriggers(text, {
|
|
26
|
+
minLines: MIN_LINES[config.capture_intensity],
|
|
27
|
+
keepWrite: deps.keepWrite ?? keepWriteFor(cwd),
|
|
28
|
+
});
|
|
29
|
+
// No triggers: leave the offset where it is, so small steps across turns are judged together.
|
|
30
|
+
if (!anyTrigger(triggers))
|
|
31
|
+
return "none";
|
|
32
|
+
if (config.capture === "quiet") {
|
|
33
|
+
updateSession(input.session_id, { scanned_offset: end, pending: describeTriggers(triggers) });
|
|
34
|
+
return "pending";
|
|
35
|
+
}
|
|
36
|
+
const ok = (deps.spawn ?? spawnWorker)({
|
|
37
|
+
session: input.session_id,
|
|
38
|
+
transcript: input.transcript_path,
|
|
39
|
+
from: start,
|
|
40
|
+
to: end,
|
|
41
|
+
cwd,
|
|
42
|
+
});
|
|
43
|
+
if (!ok)
|
|
44
|
+
return "spawn-failed";
|
|
45
|
+
updateSession(input.session_id, { scanned_offset: end, capturing_since: now.toISOString() });
|
|
46
|
+
return "spawned";
|
|
47
|
+
}
|
|
48
|
+
/** UserPromptSubmit (quiet mode): one context line asking Claude to log at a natural pause. */
|
|
49
|
+
export function handlePromptSubmit(input) {
|
|
50
|
+
if (!input.session_id || !configExists())
|
|
51
|
+
return "";
|
|
52
|
+
if (readConfig().capture !== "quiet")
|
|
53
|
+
return "";
|
|
54
|
+
const session = readSession(input.session_id);
|
|
55
|
+
if (!session.pending)
|
|
56
|
+
return "";
|
|
57
|
+
updateSession(input.session_id, { pending: null });
|
|
58
|
+
return (`selflore: recent work had ${session.pending}. At a natural pause in this task (not mid-step, and never instead of answering the user), ` +
|
|
59
|
+
`use the selflore skill to log any lore-worthy moments (session_id=${input.session_id}). Don't mention this unless you log something.`);
|
|
60
|
+
}
|
|
61
|
+
export function handleSessionStart(input, now = new Date()) {
|
|
62
|
+
if (!configExists())
|
|
63
|
+
return "";
|
|
64
|
+
const config = readConfig();
|
|
65
|
+
const oldest = listEntries()[0]?.date ?? null; // ids are date-prefixed, so sorted oldest first
|
|
66
|
+
const lines = [sessionStartContext(input.session_id, config, oldest, now)];
|
|
67
|
+
const captured = takeAnnounce();
|
|
68
|
+
if (captured > 0)
|
|
69
|
+
lines.push(`selflore: captured ${captured} ${captured === 1 ? "entry" : "entries"} in the background since the last session. ` +
|
|
70
|
+
"Mention this once, in one short line, at the start of your first reply; then don't bring it up again.");
|
|
71
|
+
return lines.filter(Boolean).join("\n");
|
|
72
|
+
}
|
package/dist/lib/install.js
CHANGED
|
@@ -41,8 +41,7 @@ export function removeFiles(purge) {
|
|
|
41
41
|
fs.rmSync(paths.skill(), { recursive: true, force: true });
|
|
42
42
|
if (purge)
|
|
43
43
|
fs.rmSync(selfloreHome(), { recursive: true, force: true });
|
|
44
|
-
|
|
44
|
+
// Session state is data: keeping it means a remove + init doesn't re-trigger capture for old sessions.
|
|
45
|
+
else
|
|
45
46
|
fs.rmSync(paths.app(), { recursive: true, force: true });
|
|
46
|
-
fs.rmSync(paths.state(), { recursive: true, force: true });
|
|
47
|
-
}
|
|
48
47
|
}
|
package/dist/lib/notes-html.js
CHANGED
|
@@ -3,13 +3,14 @@ import { listEntries, splitBody } from "./entries.js";
|
|
|
3
3
|
import { entryStatus, weekStart } from "./notes.js";
|
|
4
4
|
import { readQueue } from "./queue.js";
|
|
5
5
|
import { readResults, testedEntryIds } from "./results.js";
|
|
6
|
-
export function toCard(e, tested, queue) {
|
|
6
|
+
export function toCard(e, tested, queue, now = new Date()) {
|
|
7
7
|
const { prose, snippet } = splitBody(e.body);
|
|
8
8
|
return {
|
|
9
9
|
id: e.id,
|
|
10
10
|
date: e.date,
|
|
11
11
|
project: e.project,
|
|
12
12
|
kind: e.kind,
|
|
13
|
+
level: e.level,
|
|
13
14
|
skill: e.skill,
|
|
14
15
|
paths: e.paths,
|
|
15
16
|
commit: e.commit,
|
|
@@ -17,7 +18,7 @@ export function toCard(e, tested, queue) {
|
|
|
17
18
|
prose,
|
|
18
19
|
snippet: snippet ? snippet.replace(/\s+$/, "") : null,
|
|
19
20
|
snippetLang: e.body.match(/```([\w+-]+)/)?.[1] ?? "",
|
|
20
|
-
...entryStatus(e, tested, queue),
|
|
21
|
+
...entryStatus(e, tested, queue, now),
|
|
21
22
|
};
|
|
22
23
|
}
|
|
23
24
|
export function buildNotesData(now = new Date()) {
|
|
@@ -29,7 +30,7 @@ export function buildNotesData(now = new Date()) {
|
|
|
29
30
|
week_start: weekStart(now),
|
|
30
31
|
rating: config.rating,
|
|
31
32
|
keep_sharp: config.keep_sharp,
|
|
32
|
-
entries: listEntries().map((e) => toCard(e, tested, queue)),
|
|
33
|
+
entries: listEntries().map((e) => toCard(e, tested, queue, now)),
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
/** JSON safe to embed in a <script> element: no "<" can close the tag early. */
|
|
@@ -96,6 +97,9 @@ header.top { display: flex; align-items: flex-end; justify-content: space-betwee
|
|
|
96
97
|
.badge { font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em; border-radius: 6px; padding: 2px 8px; }
|
|
97
98
|
.kind { color: var(--kind); background: color-mix(in srgb, var(--kind) 12%, transparent); text-transform: capitalize; }
|
|
98
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; }
|
|
99
103
|
.status { margin-left: auto; border: 1px solid var(--border); color: var(--muted); font-weight: 500; }
|
|
100
104
|
.status.tested { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
|
|
101
105
|
.status.retest { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
|
|
@@ -139,7 +143,8 @@ const JS = String.raw `
|
|
|
139
143
|
var DATA = JSON.parse(document.getElementById("selflore-data").textContent);
|
|
140
144
|
var NOW = new Date();
|
|
141
145
|
var KIND_VAR = { bug: "--bug", decision: "--decision", concept: "--concept", pattern: "--pattern" };
|
|
142
|
-
var STATUS_LABEL = { untested: "Untested", tested: "Tested", suppressed: "Suppressed" };
|
|
146
|
+
var STATUS_LABEL = { untested: "Untested", tested: "Tested", suppressed: "Suppressed", stale: "Stale" };
|
|
147
|
+
var LEVEL_LABEL = { detail: "Detail", design: "Design" };
|
|
143
148
|
|
|
144
149
|
function pad(n) { return (n < 10 ? "0" : "") + n; }
|
|
145
150
|
function parse(s) { var p = s.split("-"); return new Date(Date.UTC(+p[0], +p[1] - 1, +p[2])); }
|
|
@@ -149,12 +154,12 @@ const JS = String.raw `
|
|
|
149
154
|
function fmt(s, opts) { return parse(s).toLocaleDateString(undefined, Object.assign({ timeZone: "UTC" }, opts)); }
|
|
150
155
|
|
|
151
156
|
var init = DATA.initial || {};
|
|
152
|
-
var state = { week: DATA.week_start, all: !!init.all, project: init.project || null, skill: null, kind: null, status: null, q: "" };
|
|
157
|
+
var state = { week: DATA.week_start, all: !!init.all, project: init.project || null, level: null, skill: null, kind: null, status: null, q: "" };
|
|
153
158
|
(location.hash.slice(1) || "").split("&").forEach(function (kv) {
|
|
154
159
|
var p = kv.split("="); var k = decodeURIComponent(p[0] || ""); var v = p[1] ? decodeURIComponent(p[1]) : "";
|
|
155
160
|
if (k === "all") state.all = true;
|
|
156
161
|
else if (k === "week" && /^\d{4}-\d{2}-\d{2}$/.test(v)) state.week = monday(v);
|
|
157
|
-
else if (["project", "skill", "kind", "status"].indexOf(k) >= 0 && v) state[k] = v;
|
|
162
|
+
else if (["project", "level", "skill", "kind", "status"].indexOf(k) >= 0 && v) state[k] = v;
|
|
158
163
|
});
|
|
159
164
|
var earliest = DATA.entries.reduce(function (m, e) { var w = monday(e.date); return w < m ? w : m; }, DATA.week_start);
|
|
160
165
|
|
|
@@ -173,6 +178,7 @@ const JS = String.raw `
|
|
|
173
178
|
function inScope(e) { return state.all || monday(e.date) === state.week; }
|
|
174
179
|
function matches(e, skip) {
|
|
175
180
|
if (skip !== "project" && state.project && e.project !== state.project) return false;
|
|
181
|
+
if (skip !== "level" && state.level && e.level !== state.level) return false;
|
|
176
182
|
if (skip !== "skill" && state.skill && e.skill !== state.skill) return false;
|
|
177
183
|
if (skip !== "kind" && state.kind && e.kind !== state.kind) return false;
|
|
178
184
|
if (skip !== "status" && state.status && e.status !== state.status) return false;
|
|
@@ -229,7 +235,9 @@ const JS = String.raw `
|
|
|
229
235
|
|
|
230
236
|
function renderChips(scope) {
|
|
231
237
|
var el = document.getElementById("chips"); el.textContent = "";
|
|
232
|
-
[chipRow("project", "Project", scope),
|
|
238
|
+
[chipRow("project", "Project", scope),
|
|
239
|
+
chipRow("level", "Level", scope, function (v) { return LEVEL_LABEL[v] || v; }),
|
|
240
|
+
chipRow("skill", "Skill", scope),
|
|
233
241
|
chipRow("kind", "Kind", scope, function (v) { return v.charAt(0).toUpperCase() + v.slice(1); }),
|
|
234
242
|
chipRow("status", "Status", scope, function (v) { return v === "retest" ? "Retest" : STATUS_LABEL[v]; })]
|
|
235
243
|
.forEach(function (r) { if (r) el.appendChild(r); });
|
|
@@ -253,6 +261,7 @@ const JS = String.raw `
|
|
|
253
261
|
c.style.setProperty("--kind", "var(" + (KIND_VAR[e.kind] || "--border") + ")");
|
|
254
262
|
c.appendChild(h("div", { class: "row" },
|
|
255
263
|
h("span", { class: "badge kind", text: e.kind }),
|
|
264
|
+
h("span", { class: "badge level " + e.level, text: LEVEL_LABEL[e.level] || e.level }),
|
|
256
265
|
h("span", { class: "badge skill", text: e.skill }),
|
|
257
266
|
h("span", { class: "badge status " + e.status, text: statusText(e) })));
|
|
258
267
|
c.appendChild(h("div", { class: "q", text: e.testable }));
|
|
@@ -277,12 +286,12 @@ const JS = String.raw `
|
|
|
277
286
|
return;
|
|
278
287
|
}
|
|
279
288
|
if (shown.length === 0) {
|
|
280
|
-
var filtered = state.project || state.skill || state.kind || state.status || state.q;
|
|
289
|
+
var filtered = state.project || state.level || state.skill || state.kind || state.status || state.q;
|
|
281
290
|
list.appendChild(h("div", { class: "empty" },
|
|
282
291
|
h("strong", { text: filtered ? "No entries match these filters" : "Nothing captured this week" }),
|
|
283
292
|
filtered ? null : "Try another week or switch to All time.",
|
|
284
293
|
filtered ? h("button", { class: "chip", text: "Clear filters", onclick: function () {
|
|
285
|
-
state.project = state.skill = state.kind = state.status = null; state.q = ""; document.getElementById("search").value = ""; render();
|
|
294
|
+
state.project = state.level = state.skill = state.kind = state.status = null; state.q = ""; document.getElementById("search").value = ""; render();
|
|
286
295
|
} }) : null));
|
|
287
296
|
return;
|
|
288
297
|
}
|
|
@@ -298,7 +307,7 @@ const JS = String.raw `
|
|
|
298
307
|
function syncHash() {
|
|
299
308
|
var parts = [];
|
|
300
309
|
if (state.all) parts.push("all"); else if (state.week !== DATA.week_start) parts.push("week=" + state.week);
|
|
301
|
-
["project", "skill", "kind", "status"].forEach(function (k) { if (state[k]) parts.push(k + "=" + encodeURIComponent(state[k])); });
|
|
310
|
+
["project", "level", "skill", "kind", "status"].forEach(function (k) { if (state[k]) parts.push(k + "=" + encodeURIComponent(state[k])); });
|
|
302
311
|
history.replaceState(null, "", parts.length ? "#" + parts.join("&") : location.pathname);
|
|
303
312
|
}
|
|
304
313
|
|
package/dist/lib/notes.js
CHANGED
|
@@ -10,15 +10,22 @@ export function weekStart(now) {
|
|
|
10
10
|
d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
|
|
11
11
|
return localDate(d);
|
|
12
12
|
}
|
|
13
|
-
|
|
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()) {
|
|
14
19
|
if (e.suppressed)
|
|
15
20
|
return { status: "suppressed", retest_due: null };
|
|
16
21
|
if (queue[e.id])
|
|
17
22
|
return { status: "retest", retest_due: queue[e.id].due[0] ?? null };
|
|
18
|
-
|
|
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 };
|
|
19
26
|
}
|
|
20
|
-
function status(e, tested, queue) {
|
|
21
|
-
const s = entryStatus(e, tested, queue);
|
|
27
|
+
function status(e, tested, queue, now) {
|
|
28
|
+
const s = entryStatus(e, tested, queue, now);
|
|
22
29
|
return s.status === "retest" ? `retest ${s.retest_due?.slice(0, 10) ?? ""}`.trim() : s.status;
|
|
23
30
|
}
|
|
24
31
|
/** Plain-text list of captured entries, grouped by day. Defaults to the current week. */
|
|
@@ -41,7 +48,7 @@ export function renderNotes({ entries, tested, queue, now, all, project }) {
|
|
|
41
48
|
}
|
|
42
49
|
const { prose, snippet } = splitBody(e.body);
|
|
43
50
|
const where = [e.project, e.paths.join(", ")].filter(Boolean).join(" · ");
|
|
44
|
-
out.push(` • [${e.kind} · ${e.skill}] ${where} (${status(e, tested, queue)})`);
|
|
51
|
+
out.push(` • [${e.kind} · ${e.level} · ${e.skill}] ${where} (${status(e, tested, queue, now)})`);
|
|
45
52
|
out.push(` Q: ${e.testable}`);
|
|
46
53
|
for (const line of prose.split("\n"))
|
|
47
54
|
if (line.trim())
|
package/dist/lib/nudge.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
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
|
+
};
|
|
2
7
|
/** Overdue = there is material and a week has passed since the last test (or since the first entry, before any test). */
|
|
3
8
|
export function testOverdue(config, oldestEntryDate, now) {
|
|
4
9
|
if (!oldestEntryDate)
|
|
@@ -10,6 +15,7 @@ export function sessionStartContext(sessionId, config, oldestEntryDate, now) {
|
|
|
10
15
|
const lines = [];
|
|
11
16
|
if (sessionId)
|
|
12
17
|
lines.push(`selflore session_id=${sessionId}`);
|
|
18
|
+
lines.push(CAPTURE_LINE[config.capture]);
|
|
13
19
|
if (config.nudge && testOverdue(config, oldestEntryDate, now))
|
|
14
20
|
lines.push("selflore: weekly test overdue — mention once that the user can run /selflore test (~20 min).");
|
|
15
21
|
return lines.join("\n");
|