selflore 0.0.1 → 0.0.2
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 +59 -2
- package/dist/cli.js +44 -0
- package/dist/hooks/io.js +20 -0
- package/dist/hooks/session-start.js +14 -0
- package/dist/hooks/stop.js +25 -0
- package/dist/init.js +87 -0
- package/dist/lib/commands.js +197 -0
- package/dist/lib/config.js +22 -0
- package/dist/lib/entries.js +175 -0
- package/dist/lib/fsutil.js +17 -0
- package/dist/lib/install.js +48 -0
- package/dist/lib/notes-html.js +386 -0
- package/dist/lib/notes.js +56 -0
- package/dist/lib/nudge.js +16 -0
- package/dist/lib/open.js +20 -0
- package/dist/lib/paths.js +20 -0
- package/dist/lib/queue.js +48 -0
- package/dist/lib/results.js +32 -0
- package/dist/lib/session.js +12 -0
- package/dist/lib/settings.js +60 -0
- package/dist/lib/stats.js +67 -0
- package/dist/lib/transcript.js +128 -0
- package/dist/rating-prompt.js +49 -0
- package/dist/sl.js +70 -0
- package/package.json +22 -11
- package/skill/SKILL.md +37 -0
- package/skill/references/capture.md +60 -0
- package/skill/references/log.md +13 -0
- package/skill/references/stats.md +8 -0
- package/skill/references/test.md +74 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readJson, writeJson } from "./fsutil.js";
|
|
4
|
+
import { paths } from "./paths.js";
|
|
5
|
+
export const HOOK_SCRIPTS = { SessionStart: "session-start.js", Stop: "stop.js" };
|
|
6
|
+
export function hookCommand(appDir, script) {
|
|
7
|
+
return `node "${path.join(appDir, "hooks", script)}"`;
|
|
8
|
+
}
|
|
9
|
+
function isOurs(cmd, appDir) {
|
|
10
|
+
const c = cmd.command ?? "";
|
|
11
|
+
return c.includes(path.join(appDir, "hooks")) || /[\\/]\.selflore[\\/]app[\\/]hooks[\\/]/.test(c);
|
|
12
|
+
}
|
|
13
|
+
/** Remove selflore hook commands, dropping groups/events that end up empty. Other hooks are untouched. */
|
|
14
|
+
export function stripHooks(settings, appDir) {
|
|
15
|
+
if (!settings.hooks)
|
|
16
|
+
return settings;
|
|
17
|
+
const hooks = {};
|
|
18
|
+
for (const [event, groups] of Object.entries(settings.hooks)) {
|
|
19
|
+
const kept = groups
|
|
20
|
+
.map((g) => (Array.isArray(g.hooks) ? { ...g, hooks: g.hooks.filter((h) => !isOurs(h, appDir)) } : g))
|
|
21
|
+
.filter((g) => !Array.isArray(g.hooks) || g.hooks.length > 0);
|
|
22
|
+
if (kept.length)
|
|
23
|
+
hooks[event] = kept;
|
|
24
|
+
}
|
|
25
|
+
const { hooks: _old, ...rest } = settings;
|
|
26
|
+
return Object.keys(hooks).length ? { ...rest, hooks } : rest;
|
|
27
|
+
}
|
|
28
|
+
/** Idempotently add selflore's hooks (strip then append). */
|
|
29
|
+
export function mergeHooks(settings, appDir) {
|
|
30
|
+
const base = stripHooks(settings, appDir);
|
|
31
|
+
const hooks = { ...(base.hooks ?? {}) };
|
|
32
|
+
for (const [event, script] of Object.entries(HOOK_SCRIPTS)) {
|
|
33
|
+
hooks[event] = [...(hooks[event] ?? []), { hooks: [{ type: "command", command: hookCommand(appDir, script) }] }];
|
|
34
|
+
}
|
|
35
|
+
return { ...base, hooks };
|
|
36
|
+
}
|
|
37
|
+
function loadSettings() {
|
|
38
|
+
const file = paths.settings();
|
|
39
|
+
if (!fs.existsSync(file))
|
|
40
|
+
return {};
|
|
41
|
+
const parsed = readJson(file, null);
|
|
42
|
+
if (parsed === null)
|
|
43
|
+
throw new Error(`${file} is not valid JSON; fix it before running selflore`);
|
|
44
|
+
return parsed;
|
|
45
|
+
}
|
|
46
|
+
export function installHooks() {
|
|
47
|
+
const file = paths.settings();
|
|
48
|
+
const settings = loadSettings();
|
|
49
|
+
if (fs.existsSync(file))
|
|
50
|
+
fs.copyFileSync(file, `${file}.selflore-bak`);
|
|
51
|
+
writeJson(file, mergeHooks(settings, paths.app()));
|
|
52
|
+
}
|
|
53
|
+
export function uninstallHooks() {
|
|
54
|
+
const file = paths.settings();
|
|
55
|
+
if (!fs.existsSync(file))
|
|
56
|
+
return;
|
|
57
|
+
const settings = loadSettings();
|
|
58
|
+
fs.copyFileSync(file, `${file}.selflore-bak`);
|
|
59
|
+
writeJson(file, stripHooks(settings, paths.app()));
|
|
60
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Monday (UTC) of the week containing `d`, as YYYY-MM-DD. */
|
|
2
|
+
export function weekOf(d) {
|
|
3
|
+
const date = new Date(typeof d === "string" && d.length === 10 ? `${d}T00:00:00Z` : d);
|
|
4
|
+
const day = (date.getUTCDay() + 6) % 7; // Mon=0
|
|
5
|
+
const monday = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() - day));
|
|
6
|
+
return monday.toISOString().slice(0, 10);
|
|
7
|
+
}
|
|
8
|
+
function pct(pass, total) {
|
|
9
|
+
return total === 0 ? "–" : `${Math.round((pass / total) * 100)}%`;
|
|
10
|
+
}
|
|
11
|
+
function table(header, rows) {
|
|
12
|
+
const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
|
|
13
|
+
const fmt = (r) => r.map((c, i) => (c ?? "").padEnd(widths[i])).join(" ").trimEnd();
|
|
14
|
+
return [fmt(header), widths.map((w) => "-".repeat(w)).join(" "), ...rows.map(fmt)].join("\n");
|
|
15
|
+
}
|
|
16
|
+
export function renderStats({ entries, results, queue, rating, project }) {
|
|
17
|
+
if (project) {
|
|
18
|
+
entries = entries.filter((e) => e.project === project);
|
|
19
|
+
results = results.filter((r) => r.project === project);
|
|
20
|
+
const ids = new Set(entries.map((e) => e.id));
|
|
21
|
+
queue = Object.fromEntries(Object.entries(queue).filter(([id]) => ids.has(id)));
|
|
22
|
+
}
|
|
23
|
+
if (entries.length === 0 && results.length === 0) {
|
|
24
|
+
return project ? `No selflore data for project "${project}" yet.` : "No selflore data yet. Work normally; entries appear as you go.";
|
|
25
|
+
}
|
|
26
|
+
const skills = [...new Set([...entries.map((e) => e.skill), ...results.map((r) => r.skill)])].filter(Boolean).sort();
|
|
27
|
+
const weeks = [...new Set([...entries.map((e) => weekOf(e.date)), ...results.map((r) => weekOf(r.ts))])].sort();
|
|
28
|
+
const rows = weeks.map((w) => {
|
|
29
|
+
const wr = results.filter((r) => weekOf(r.ts) === w);
|
|
30
|
+
const pass = (rs) => rs.filter((r) => r.grade === "got").length;
|
|
31
|
+
return [
|
|
32
|
+
w,
|
|
33
|
+
String(entries.filter((e) => weekOf(e.date) === w).length),
|
|
34
|
+
String(wr.length),
|
|
35
|
+
pct(pass(wr), wr.length),
|
|
36
|
+
...skills.map((s) => {
|
|
37
|
+
const sr = wr.filter((r) => r.skill === s);
|
|
38
|
+
return pct(pass(sr), sr.length);
|
|
39
|
+
}),
|
|
40
|
+
];
|
|
41
|
+
});
|
|
42
|
+
const passes = results.filter((r) => r.grade === "got").length;
|
|
43
|
+
const first = results.filter((r) => !r.is_retest);
|
|
44
|
+
const retest = results.filter((r) => r.is_retest);
|
|
45
|
+
const passCount = (rs) => rs.filter((r) => r.grade === "got").length;
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
const backlog = Object.values(queue);
|
|
48
|
+
const overdue = backlog.filter((q) => q.due[0] && new Date(q.due[0]).getTime() <= now).length;
|
|
49
|
+
const observed = results.length ? passes / results.length : null;
|
|
50
|
+
const lines = [
|
|
51
|
+
`selflore stats${project ? ` — ${project}` : ""}`,
|
|
52
|
+
"",
|
|
53
|
+
table(["week of", "entries", "questions", "pass", ...skills.map((s) => `pass:${s}`)], rows),
|
|
54
|
+
"",
|
|
55
|
+
`overall pass rate ${pct(passes, results.length)} (${passes}/${results.length})`,
|
|
56
|
+
`first-attempt pass ${pct(passCount(first), first.length)}`,
|
|
57
|
+
`retest pass ${pct(passCount(retest), retest.length)}`,
|
|
58
|
+
`retest backlog ${backlog.length} queued, ${overdue} due now`,
|
|
59
|
+
`self-rating ${rating}/10 (≈${rating * 10}%) vs observed ${observed === null ? "–" : `${Math.round(observed * 100)}%`}`,
|
|
60
|
+
];
|
|
61
|
+
if (observed !== null && results.length >= 10) {
|
|
62
|
+
const gap = Math.round(observed * 100) - rating * 10;
|
|
63
|
+
if (Math.abs(gap) >= 20)
|
|
64
|
+
lines.push(` tests ${gap > 0 ? "rate you higher" : "rate you lower"} than you do; re-rate with \`npx selflore init\` if it holds`);
|
|
65
|
+
}
|
|
66
|
+
return lines.join("\n");
|
|
67
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Cheap heuristics over a Claude Code transcript (JSONL) for the Stop-hook safety net.
|
|
5
|
+
* Only the mechanically observable PRD triggers are detected here; tradeoffs and
|
|
6
|
+
* corrections are left to the skill itself.
|
|
7
|
+
*/
|
|
8
|
+
export const LARGE_WRITE_LINES = 30;
|
|
9
|
+
const DEP_FILES = new Set([
|
|
10
|
+
"package.json",
|
|
11
|
+
"requirements.txt",
|
|
12
|
+
"pyproject.toml",
|
|
13
|
+
"Pipfile",
|
|
14
|
+
"go.mod",
|
|
15
|
+
"Cargo.toml",
|
|
16
|
+
"Gemfile",
|
|
17
|
+
"composer.json",
|
|
18
|
+
"build.gradle",
|
|
19
|
+
"build.gradle.kts",
|
|
20
|
+
"pom.xml",
|
|
21
|
+
]);
|
|
22
|
+
const TEST_CMD = /\b(test|tests|jest|vitest|pytest|mocha|rspec|cargo test|go test|phpunit|tsc)\b/;
|
|
23
|
+
const FAIL_TEXT = /\b(FAIL|FAILED|failed|Error:|error TS\d+|Traceback|panic:)\b/;
|
|
24
|
+
function lineCount(s) {
|
|
25
|
+
return typeof s === "string" && s.length ? s.split("\n").length : 0;
|
|
26
|
+
}
|
|
27
|
+
function contentText(c) {
|
|
28
|
+
if (typeof c === "string")
|
|
29
|
+
return c;
|
|
30
|
+
if (Array.isArray(c))
|
|
31
|
+
return c.map((p) => (typeof p === "string" ? p : p?.text ?? "")).join("\n");
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
export function detectTriggers(jsonl) {
|
|
35
|
+
const largeWrites = new Set();
|
|
36
|
+
const depChanges = new Set();
|
|
37
|
+
const testCmds = new Map(); // tool_use id -> is a test command
|
|
38
|
+
// Sequence of events: "fail" | "pass" | "edit"
|
|
39
|
+
const seq = [];
|
|
40
|
+
for (const raw of jsonl.split("\n")) {
|
|
41
|
+
if (!raw.trim())
|
|
42
|
+
continue;
|
|
43
|
+
let line;
|
|
44
|
+
try {
|
|
45
|
+
line = JSON.parse(raw);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const content = line.message?.content;
|
|
51
|
+
if (!Array.isArray(content))
|
|
52
|
+
continue;
|
|
53
|
+
for (const block of content) {
|
|
54
|
+
if (block.type === "tool_use") {
|
|
55
|
+
const tu = block;
|
|
56
|
+
const input = tu.input ?? {};
|
|
57
|
+
const file = typeof input.file_path === "string" ? input.file_path : "";
|
|
58
|
+
if (file.includes(`${path.sep}.selflore${path.sep}`))
|
|
59
|
+
continue;
|
|
60
|
+
let added = 0;
|
|
61
|
+
if (tu.name === "Write")
|
|
62
|
+
added = lineCount(input.content);
|
|
63
|
+
else if (tu.name === "Edit")
|
|
64
|
+
added = lineCount(input.new_string) - lineCount(input.old_string);
|
|
65
|
+
else if (tu.name === "MultiEdit" && Array.isArray(input.edits))
|
|
66
|
+
added = input.edits.reduce((n, e) => n + lineCount(e.new_string) - lineCount(e.old_string), 0);
|
|
67
|
+
if (["Write", "Edit", "MultiEdit"].includes(tu.name)) {
|
|
68
|
+
if (added >= LARGE_WRITE_LINES)
|
|
69
|
+
largeWrites.add(file);
|
|
70
|
+
if (DEP_FILES.has(path.basename(file)))
|
|
71
|
+
depChanges.add(file);
|
|
72
|
+
seq.push("edit");
|
|
73
|
+
}
|
|
74
|
+
else if (tu.name === "Bash" && typeof input.command === "string") {
|
|
75
|
+
testCmds.set(tu.id, TEST_CMD.test(input.command));
|
|
76
|
+
if (/\b(npm|pnpm|yarn|bun) (add|install|i) \S|\bpip install \S|\bcargo add\b|\bgo get\b/.test(input.command))
|
|
77
|
+
depChanges.add(input.command.slice(0, 80));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (block.type === "tool_result") {
|
|
81
|
+
const id = String(block.tool_use_id ?? "");
|
|
82
|
+
if (!testCmds.get(id))
|
|
83
|
+
continue;
|
|
84
|
+
const failed = block.is_error === true || FAIL_TEXT.test(contentText(block.content));
|
|
85
|
+
seq.push(failed ? "fail" : "pass");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// fail → (edit)+ → pass
|
|
90
|
+
let bugFixLoop = false;
|
|
91
|
+
let state = "idle";
|
|
92
|
+
for (const ev of seq) {
|
|
93
|
+
if (ev === "fail")
|
|
94
|
+
state = "failed";
|
|
95
|
+
else if (ev === "edit" && state !== "idle")
|
|
96
|
+
state = "edited";
|
|
97
|
+
else if (ev === "pass" && state === "edited") {
|
|
98
|
+
bugFixLoop = true;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
else if (ev === "pass")
|
|
102
|
+
state = "idle";
|
|
103
|
+
}
|
|
104
|
+
return { largeWrites: [...largeWrites], depChanges: [...depChanges], bugFixLoop };
|
|
105
|
+
}
|
|
106
|
+
export function anyTrigger(t) {
|
|
107
|
+
return t.largeWrites.length > 0 || t.depChanges.length > 0 || t.bugFixLoop;
|
|
108
|
+
}
|
|
109
|
+
export function describeTriggers(t) {
|
|
110
|
+
const parts = [];
|
|
111
|
+
if (t.largeWrites.length)
|
|
112
|
+
parts.push(`large writes (${t.largeWrites.map((f) => path.basename(f)).join(", ")})`);
|
|
113
|
+
if (t.depChanges.length)
|
|
114
|
+
parts.push("new dependencies");
|
|
115
|
+
if (t.bugFixLoop)
|
|
116
|
+
parts.push("a fail → fix → pass loop");
|
|
117
|
+
return parts.join("; ");
|
|
118
|
+
}
|
|
119
|
+
export function readTranscript(file) {
|
|
120
|
+
if (!file)
|
|
121
|
+
return "";
|
|
122
|
+
try {
|
|
123
|
+
return fs.readFileSync(file, "utf8");
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return "";
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Prompt } from "@clack/core";
|
|
2
|
+
import { S_BAR, S_BAR_END, symbol } from "@clack/prompts";
|
|
3
|
+
import { styleText } from "node:util";
|
|
4
|
+
const MIN = 1;
|
|
5
|
+
const MAX = 10;
|
|
6
|
+
/** Horizontal 1–10 scale: ←/→ to move, digits jump (0 = 10), enter to confirm. */
|
|
7
|
+
class RatingPrompt extends Prompt {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
super(opts, false);
|
|
10
|
+
this.value = opts.initialValue ?? 5;
|
|
11
|
+
this.on("cursor", (action) => {
|
|
12
|
+
const v = this.value ?? 5;
|
|
13
|
+
if (action === "left" || action === "down")
|
|
14
|
+
this.value = Math.max(MIN, v - 1);
|
|
15
|
+
if (action === "right" || action === "up")
|
|
16
|
+
this.value = Math.min(MAX, v + 1);
|
|
17
|
+
});
|
|
18
|
+
this.on("key", (ch) => {
|
|
19
|
+
if (ch && /^[0-9]$/.test(ch))
|
|
20
|
+
this.value = ch === "0" ? 10 : Number(ch);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function renderScale(value) {
|
|
25
|
+
return Array.from({ length: MAX - MIN + 1 }, (_, i) => i + MIN)
|
|
26
|
+
.map((n) => (n === value ? styleText(["green", "bold", "inverse"], ` ${n} `) : styleText("dim", ` ${n} `)))
|
|
27
|
+
.join(" ");
|
|
28
|
+
}
|
|
29
|
+
export async function ratingPrompt(message, initialValue = 5) {
|
|
30
|
+
return (await new RatingPrompt({
|
|
31
|
+
initialValue,
|
|
32
|
+
render() {
|
|
33
|
+
const title = `${styleText("gray", S_BAR)}\n${symbol(this.state)} ${message}\n`;
|
|
34
|
+
const value = this.value ?? initialValue;
|
|
35
|
+
switch (this.state) {
|
|
36
|
+
case "submit":
|
|
37
|
+
return `${title}${styleText("gray", S_BAR)} ${styleText("dim", `${value}/10`)}`;
|
|
38
|
+
case "cancel":
|
|
39
|
+
return `${title}${styleText("gray", S_BAR)} ${styleText(["strikethrough", "dim"], `${value}/10`)}\n${styleText("gray", S_BAR)}`;
|
|
40
|
+
default:
|
|
41
|
+
return [
|
|
42
|
+
`${title}${styleText("cyan", S_BAR)} ${renderScale(value)}`,
|
|
43
|
+
`${styleText("cyan", S_BAR)} ${styleText("dim", "← → to change · enter to confirm")}`,
|
|
44
|
+
`${styleText("cyan", S_BAR_END)}\n`,
|
|
45
|
+
].join("\n");
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
}).prompt());
|
|
49
|
+
}
|
package/dist/sl.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Data CLI the selflore skill calls for bookkeeping that must be exact.
|
|
3
|
+
import { readStdin } from "./hooks/io.js";
|
|
4
|
+
import { addEntry, finishTest, listCmd, notesCmd, quizInput, recordCmd, statsCmd, suppressCmd, } from "./lib/commands.js";
|
|
5
|
+
const USAGE = `usage: sl <command>
|
|
6
|
+
entry add --session <id> [--manual] read entry markdown from stdin and store it
|
|
7
|
+
entry replace <id> --session <id> swap a weaker entry from this session for the one on stdin
|
|
8
|
+
entry list [--session <id>]
|
|
9
|
+
quiz-input JSON of fresh entries + due retests
|
|
10
|
+
record --entry <id> --grade got|partial|missed --type <question-type>
|
|
11
|
+
suppress <id> flag an entry as unfair; never test it again
|
|
12
|
+
finish-test
|
|
13
|
+
stats [--project <name>]
|
|
14
|
+
notes [--all] [--project <name>] [--text] open the notes page (or print text)`;
|
|
15
|
+
function flag(args, name) {
|
|
16
|
+
const i = args.indexOf(`--${name}`);
|
|
17
|
+
return i >= 0 ? args[i + 1] : undefined;
|
|
18
|
+
}
|
|
19
|
+
async function main(argv) {
|
|
20
|
+
const [cmd, sub, ...rest] = argv;
|
|
21
|
+
const args = [sub, ...rest].filter((a) => a !== undefined);
|
|
22
|
+
switch (cmd) {
|
|
23
|
+
case "entry": {
|
|
24
|
+
const session = flag(args, "session");
|
|
25
|
+
if (sub === "list")
|
|
26
|
+
return listCmd(session);
|
|
27
|
+
if (sub !== "add" && sub !== "replace")
|
|
28
|
+
break;
|
|
29
|
+
if (!session)
|
|
30
|
+
return { code: 1, out: "missing --session <id> (it is in the session context as selflore session_id=…)" };
|
|
31
|
+
const replace = sub === "replace" ? rest[0] : undefined;
|
|
32
|
+
if (sub === "replace" && (!replace || replace.startsWith("--")))
|
|
33
|
+
return { code: 1, out: "usage: entry replace <id> --session <id>" };
|
|
34
|
+
return addEntry(await readStdin(), {
|
|
35
|
+
session,
|
|
36
|
+
cwd: process.cwd(),
|
|
37
|
+
manual: args.includes("--manual"),
|
|
38
|
+
replace,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
case "quiz-input":
|
|
42
|
+
return quizInput();
|
|
43
|
+
case "record": {
|
|
44
|
+
const entry = flag(args, "entry");
|
|
45
|
+
const grade = flag(args, "grade");
|
|
46
|
+
const type = flag(args, "type");
|
|
47
|
+
if (!entry || !grade || !type)
|
|
48
|
+
break;
|
|
49
|
+
return recordCmd(entry, grade, type);
|
|
50
|
+
}
|
|
51
|
+
case "suppress":
|
|
52
|
+
if (!sub)
|
|
53
|
+
break;
|
|
54
|
+
return suppressCmd(sub);
|
|
55
|
+
case "finish-test":
|
|
56
|
+
return finishTest();
|
|
57
|
+
case "stats":
|
|
58
|
+
return statsCmd(flag(args, "project"));
|
|
59
|
+
case "notes":
|
|
60
|
+
return notesCmd({ all: args.includes("--all"), project: flag(args, "project"), text: args.includes("--text") });
|
|
61
|
+
}
|
|
62
|
+
return { code: 1, out: USAGE };
|
|
63
|
+
}
|
|
64
|
+
main(process.argv.slice(2)).then((r) => {
|
|
65
|
+
(r.code === 0 ? process.stdout : process.stderr).write(r.out + "\n");
|
|
66
|
+
process.exit(r.code);
|
|
67
|
+
}, (err) => {
|
|
68
|
+
process.stderr.write(`sl: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "selflore",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Own what your agent builds. A Claude Code skill that captures what your agent did for you and tests you on it weekly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude",
|
|
7
7
|
"claude-skill",
|
|
@@ -10,17 +10,18 @@
|
|
|
10
10
|
],
|
|
11
11
|
"author": "lak7-manadon",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/lak7/selflore.git"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/lak7/selflore#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/lak7/selflore/issues"
|
|
21
20
|
},
|
|
21
|
+
"type": "module",
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
24
|
+
"skill",
|
|
24
25
|
"README.md"
|
|
25
26
|
],
|
|
26
27
|
"engines": {
|
|
@@ -28,9 +29,19 @@
|
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
31
|
"build": "tsc",
|
|
32
|
+
"test": "vitest run",
|
|
31
33
|
"prepublishOnly": "npm run build"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
|
-
"
|
|
36
|
+
"@types/node": "^26.6.3",
|
|
37
|
+
"typescript": "^7.0.2",
|
|
38
|
+
"vitest": "^5.0.3"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@clack/core": "^1.5.1",
|
|
42
|
+
"@clack/prompts": "^1.8.1"
|
|
43
|
+
},
|
|
44
|
+
"bin": {
|
|
45
|
+
"selflore": "dist/cli.js"
|
|
35
46
|
}
|
|
36
47
|
}
|
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: selflore
|
|
3
|
+
description: Captures "lore-worthy" moments from Claude Code sessions and runs a weekly comprehension test on them so the developer keeps understanding code the agent wrote. Use it proactively, without being asked, right after any of these happen in a session - you wrote a function or module of ~30+ lines the user did not read or edit; a non-obvious tradeoff was made and a reason stated; a bug was root-caused and fixed; a new library, API or pattern entered the codebase; the user corrected you or you talked the user out of an approach. Also handles /selflore test, /selflore log, /selflore notes and /selflore stats, and the selflore Stop-hook nudge.
|
|
4
|
+
argument-hint: "test | log | notes | stats"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# selflore
|
|
8
|
+
|
|
9
|
+
selflore captures what you (the agent) did *for* the user, then tests them on it weekly. Getting it wrong is the feature: a miss followed by an immediate explanation is the strongest learning moment.
|
|
10
|
+
|
|
11
|
+
All bookkeeping goes through the data CLI. Never edit `~/.selflore/` files by hand.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
SL = {{SL}}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Routing
|
|
18
|
+
|
|
19
|
+
Look at the arguments the skill was invoked with:
|
|
20
|
+
|
|
21
|
+
| Argument | Do this |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `test` | Read [references/test.md](references/test.md) and run the weekly test. |
|
|
24
|
+
| `log` | Read [references/log.md](references/log.md) and write a manual entry. |
|
|
25
|
+
| `notes` | Run `{{SL}} notes` (add `--all` or `--project <name>` if the user asks). It opens the notes page in the browser. Reply with one line: that it opened, or the `file://` path if it couldn't open. Don't repeat the entries in chat. |
|
|
26
|
+
| `stats` | Run `{{SL}} stats` (add `--project <name>` if the user names one) and show the output verbatim in a code block. Add at most two sentences of interpretation. |
|
|
27
|
+
| none, or invoked by a capture trigger / Stop-hook nudge | Capture: follow the rules below and [references/capture.md](references/capture.md). |
|
|
28
|
+
|
|
29
|
+
## Capture rules (summary)
|
|
30
|
+
|
|
31
|
+
- **Triggers:** only the five in the description. Routine edits, renames, config tweaks and anything the user wrote themselves are not lore.
|
|
32
|
+
- **The `testable` line is the gate.** If you cannot write one sharp question that tests *understanding* (why / what breaks / what happens if), don't log it.
|
|
33
|
+
- **Cap:** at most `max_entries_per_session` per session (3–7, enforced by `entry add`). When the cap is hit, keep the entries that best match the user's `keep_sharp` areas, and replace a weaker one only if the new moment is clearly better.
|
|
34
|
+
- **Session id:** this comes from the session context line `selflore session_id=<id>`. If it is missing, use `manual-<YYYY-MM-DD>`.
|
|
35
|
+
- **Cost to the user:** near zero. Log quietly in one short tool call, then say a single line like `selflore: logged 1 entry (webhook idempotency)`. Never interrupt the user's task to discuss logging, and never ask permission to log.
|
|
36
|
+
- **Timing:** log when a unit of work wraps up (the bug is fixed, the module is written). Do not log mid-debugging.
|
|
37
|
+
- **Stop-hook nudge:** if a `selflore:` Stop-hook message says nothing was logged, either log up to the cap or reply with one line saying nothing was lore-worthy. Then stop.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Capturing an entry
|
|
2
|
+
|
|
3
|
+
## Format
|
|
4
|
+
|
|
5
|
+
Write one markdown entry with frontmatter and pipe it to `entry add`. `id`, `date`, `session`, `project` and `commit` are filled in automatically.
|
|
6
|
+
|
|
7
|
+
~~~bash
|
|
8
|
+
{{SL}} entry add --session <session_id> <<'LORE'
|
|
9
|
+
---
|
|
10
|
+
kind: bug # bug | decision | concept | pattern
|
|
11
|
+
skill: debugging # debugging | architecture | fundamentals | <a keep_sharp stack name>
|
|
12
|
+
paths: ["src/payments/webhook.ts"]
|
|
13
|
+
testable: "Why must the Stripe webhook handler be idempotent, and what fails without it?"
|
|
14
|
+
---
|
|
15
|
+
Retries caused double refunds. In-memory dedupe fails across pods;
|
|
16
|
+
moved to a processed_events table keyed on event id.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
export async function handleWebhook(evt: Stripe.Event) {
|
|
20
|
+
const inserted = await db.processedEvents.insertIgnore({ id: evt.id });
|
|
21
|
+
if (!inserted) return; // already handled
|
|
22
|
+
await applyRefund(evt);
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
LORE
|
|
26
|
+
~~~
|
|
27
|
+
|
|
28
|
+
Run it from the project's working directory so `project` and `commit` are detected.
|
|
29
|
+
|
|
30
|
+
## Field rules
|
|
31
|
+
|
|
32
|
+
- **kind**
|
|
33
|
+
- `bug`: something was root-caused and fixed.
|
|
34
|
+
- `decision`: a tradeoff was made, either by you or after the user corrected you.
|
|
35
|
+
- `concept`: an idea the user needs, such as how an API or library actually behaves.
|
|
36
|
+
- `pattern`: a reusable structure that entered the codebase.
|
|
37
|
+
- **skill:** use the user's `keep_sharp` area that fits best. Use the stack name, such as `postgres`, when the lore is stack-specific.
|
|
38
|
+
- **paths:** the files involved, relative to the repo root.
|
|
39
|
+
- **testable:** a single question written *now*, while context is fresh. It should test understanding, not trivia:
|
|
40
|
+
- Good: "Why X over Y?", "What breaks if…?", "What happens when the input is…?", "Where would this fail under concurrency?"
|
|
41
|
+
- Bad: "What is the name of the function that…?", "Which file contains…?"
|
|
42
|
+
- **Body:** at most ~120 words of prose saying *what* happened and *why*, including the reason a tradeoff was made or what the root cause was. This is the answer key the grader uses later, so include the facts a correct answer must contain.
|
|
43
|
+
- **Snippet (strongly recommended):** one fenced code block of at most 40 lines with the essential code *as it is now*. The weekly test uses it for predict-behavior and find-the-bug questions, even after the file changes. For a `bug` entry, include the **fixed** code and name the original bug in the prose.
|
|
44
|
+
|
|
45
|
+
## Responses from `entry add`
|
|
46
|
+
|
|
47
|
+
- `logged <id> (n/cap this session)`: done. Tell the user in one line.
|
|
48
|
+
- `entry rejected: …`: fix the listed problems and retry once. If there is no good `testable` line, drop the entry.
|
|
49
|
+
- `cap reached` (exit code 2): compare the new moment against the listed entries using the user's `keep_sharp` areas. If the new one is clearly better, run:
|
|
50
|
+
`{{SL}} entry replace <weaker-id> --session <session_id> <<'LORE' … LORE`
|
|
51
|
+
Otherwise drop it silently.
|
|
52
|
+
|
|
53
|
+
## Choosing what to log when several triggers fired
|
|
54
|
+
|
|
55
|
+
Rank the candidates and keep the top ones up to the cap:
|
|
56
|
+
1. A match with the user's `keep_sharp` areas.
|
|
57
|
+
2. Bugs and corrected decisions. These are the moments the user is most likely to have missed.
|
|
58
|
+
3. Anything the user did not visibly read.
|
|
59
|
+
|
|
60
|
+
Prefer one deep entry over two shallow ones.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# /selflore log — manual entry
|
|
2
|
+
|
|
3
|
+
The user said "this was important". It is also the escape hatch for work done outside Claude Code.
|
|
4
|
+
|
|
5
|
+
1. Work out what they mean from the current conversation. If the conversation has no such context (for example, the work happened in Cursor or Codex), ask for a 2–3 sentence description and any code worth keeping.
|
|
6
|
+
2. Write the entry exactly as described in [capture.md](capture.md). The same quality bar applies: a real `testable` line and a body that works as an answer key.
|
|
7
|
+
3. Store it with the `--manual` flag. Manual entries may exceed the session cap; the CLI warns instead of refusing:
|
|
8
|
+
```bash
|
|
9
|
+
{{SL}} entry add --session <session_id> --manual <<'LORE'
|
|
10
|
+
…
|
|
11
|
+
LORE
|
|
12
|
+
```
|
|
13
|
+
4. Show the user the `testable` question you wrote, in one line, so they can ask you to sharpen it.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# /selflore stats
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
{{SL}} stats # all projects
|
|
5
|
+
{{SL}} stats --project <name> # one project
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
Show the output verbatim in a code block. Afterwards, add at most two sentences, only if the data supports them. For example: the weakest skill area, whether retest pass rate is above first-attempt pass rate (which means the correction step is working), or a large gap between the self-rating and the observed pass rate.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# /selflore test — the weekly test
|
|
2
|
+
|
|
3
|
+
Target: about 10 questions in about 20 minutes. Tests are meant to measure **understanding**, not recall.
|
|
4
|
+
|
|
5
|
+
## 1. Load the material
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
{{SL}} quiz-input
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This returns JSON with `config` (`rating`, `keep_sharp`), `target_questions`, `retests` (due misses from earlier weeks) and `fresh` (entries never tested). Each entry has `testable`, a `body` (the answer key, usually with a code snippet), `kind`, `skill`, `paths` and `commit`.
|
|
12
|
+
|
|
13
|
+
- If both lists are empty, say there is nothing to test yet and stop.
|
|
14
|
+
- **Include every due retest.** Then fill the rest up to `target_questions` with `fresh` entries, weighted toward the `keep_sharp` areas. If there are fewer than 10 entries in total, ask fewer questions. Never pad.
|
|
15
|
+
- Fresh entries you skip stay untested and roll into next week.
|
|
16
|
+
|
|
17
|
+
## 2. Build the questions (before asking the first one)
|
|
18
|
+
|
|
19
|
+
There is one question per entry. Pick the best type for each, in this priority order:
|
|
20
|
+
|
|
21
|
+
1. **explain-why** (from `decision` entries, and others where it fits): "Why did we choose X over Y? What breaks if we hadn't?" The entry's `testable` line is the starting point; you can sharpen it.
|
|
22
|
+
2. **predict-behavior:** show the snippet (or a trimmed piece of it) and ask what happens for a specific, concrete input or condition.
|
|
23
|
+
3. **find-the-bug:** take the snippet, reintroduce the logged bug from a `bug` entry, and ask the user to locate it and explain the failure. Don't mark the bug in any way, and don't let the change stand out visually.
|
|
24
|
+
4. **rewrite-from-spec:** "Without looking, write the signature and core logic of…". **At most one per test.**
|
|
25
|
+
5. **recall:** only when nothing better fits.
|
|
26
|
+
|
|
27
|
+
Calibrate to `config.rating`:
|
|
28
|
+
|
|
29
|
+
| Rating | Questions | Hints | What the grader expects |
|
|
30
|
+
|---|---|---|---|
|
|
31
|
+
| 1–3 | Fundamentals-heavy: what the code does and why it's needed | A short hint is offered up front with each question | The core idea plus the *why* |
|
|
32
|
+
| 4–7 | Balanced: why plus one consequence | A hint only if the user asks | The *why* plus at least one concrete consequence |
|
|
33
|
+
| 8–10 | Tradeoffs, failure modes, scale and concurrency edges | None | The *why*, the alternative rejected and when it would break |
|
|
34
|
+
|
|
35
|
+
Don't quote the answer key in the question. If a question needs file context beyond the stored snippet, use the snippet. Don't read the live files to build questions; they may have changed.
|
|
36
|
+
|
|
37
|
+
## 3. Ask one question at a time
|
|
38
|
+
|
|
39
|
+
Open with: `selflore test — N questions (R retests). Answer in your own words; "skip", "hint", or "unfair" are fine.`
|
|
40
|
+
|
|
41
|
+
For each question:
|
|
42
|
+
|
|
43
|
+
1. Show `Q<i>/<N> [<type> · <skill>]` followed by the question and any code. Retests are marked `(retest)`.
|
|
44
|
+
2. **Wait for the user's answer.** Never answer for them, and never move on without their answer.
|
|
45
|
+
3. Grade strictly against the entry body:
|
|
46
|
+
- **got:** the core *why* is correct and nothing important is wrong. Describing *what* the code does without the *why* is not `got`.
|
|
47
|
+
- **partial:** the right direction, but missing the key reason or consequence, or containing a significant error.
|
|
48
|
+
- **missed:** wrong, empty, "I don't know" or "skip".
|
|
49
|
+
Don't be generous. The user installed this to find gaps, and over-grading defeats it. When in doubt between two levels, choose the lower one.
|
|
50
|
+
4. **Explain immediately**, before the next question. Give the verdict, then the correct explanation in 2–5 sentences: what they got right, the gap and the real answer. For a miss, add the single sentence they should remember.
|
|
51
|
+
5. Record it:
|
|
52
|
+
```bash
|
|
53
|
+
{{SL}} record --entry <id> --grade got|partial|missed --type explain-why|predict-behavior|find-the-bug|rewrite-from-spec|recall
|
|
54
|
+
```
|
|
55
|
+
The CLI decides whether this was a retest and schedules misses and partials for +7 and +21 days. Retests retire after two consecutive passes.
|
|
56
|
+
|
|
57
|
+
Special replies:
|
|
58
|
+
- **"hint":** give one hint that does not reveal the answer, then wait. A correct answer after a hint can still be `got` for ratings of 7 or below. For ratings of 8 and above, it is at most `partial`.
|
|
59
|
+
- **"unfair"** (or the user says the question is wrong or irrelevant): don't argue. Run `{{SL}} suppress <id>`, don't record a grade and move on. If the question was flawed but the entry is fine, say so in one line.
|
|
60
|
+
- **"stop" / "later":** end the quiz early (step 4). Answers recorded so far still count.
|
|
61
|
+
|
|
62
|
+
## 4. Finish
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
{{SL}} finish-test
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Then give a summary of at most 6 lines:
|
|
69
|
+
- The score (got / partial / missed) and how many retests were passed.
|
|
70
|
+
- The one or two misses most worth re-reading, by entry topic.
|
|
71
|
+
- When the next retest is due (from the `record` outputs).
|
|
72
|
+
- A pointer to `/selflore stats` for the trend.
|
|
73
|
+
|
|
74
|
+
No pep talk.
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|