selflore 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +64 -31
  2. package/dist/cli.js +81 -19
  3. package/dist/hooks/user-prompt-submit.js +2 -1
  4. package/dist/init.js +26 -10
  5. package/dist/lib/background.js +23 -4
  6. package/dist/lib/capture-prompt.js +13 -7
  7. package/dist/lib/commands.js +199 -35
  8. package/dist/lib/config.js +24 -4
  9. package/dist/lib/entries.js +56 -4
  10. package/dist/lib/heat.js +141 -0
  11. package/dist/lib/hook-logic.js +44 -9
  12. package/dist/lib/index-cache.js +46 -0
  13. package/dist/lib/links.js +58 -0
  14. package/dist/lib/logo.js +6 -0
  15. package/dist/lib/notes-graph.js +585 -0
  16. package/dist/lib/notes-html.js +148 -339
  17. package/dist/lib/notes-page-css.js +279 -0
  18. package/dist/lib/notes-page-js.js +959 -0
  19. package/dist/lib/notes.js +19 -13
  20. package/dist/lib/nudge.js +2 -1
  21. package/dist/lib/paths.js +6 -0
  22. package/dist/lib/question.js +19 -0
  23. package/dist/lib/queue.js +6 -4
  24. package/dist/lib/recall.js +149 -0
  25. package/dist/lib/results.js +1 -0
  26. package/dist/lib/retag.js +150 -0
  27. package/dist/lib/server-launch.js +73 -0
  28. package/dist/lib/server.js +120 -0
  29. package/dist/lib/session.js +1 -1
  30. package/dist/lib/signals.js +51 -0
  31. package/dist/lib/stats.js +71 -44
  32. package/dist/lib/struggle.js +120 -0
  33. package/dist/lib/surface.js +75 -0
  34. package/dist/lib/transcript.js +61 -15
  35. package/dist/lib/ui.js +127 -0
  36. package/dist/notes-server.js +39 -0
  37. package/dist/sl.js +29 -4
  38. package/dist/vendor/graph3d.js +5402 -0
  39. package/package.json +6 -3
  40. package/skill/SKILL.md +6 -5
  41. package/skill/references/capture.md +6 -5
  42. package/skill/references/recall.md +44 -0
  43. package/skill/references/stats.md +5 -1
  44. package/skill/references/test.md +35 -30
package/README.md CHANGED
@@ -1,8 +1,17 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="public/selflore-mark.png">
4
+ <img src="public/selflore-mark-dark.png" alt="The selflore logo: an S above the pages of an open book" width="128">
5
+ </picture>
6
+ </p>
7
+
1
8
  # selflore
2
9
 
3
- **Own what your agent builds.**
10
+ **Your agent wrote it. selflore remembers why.**
11
+
12
+ selflore is a Claude Code skill. While you work, it keeps dated notes on what Claude built for you and why: the bug that was root-caused, the tradeoff that was made, the thing you asked to have explained. Later, when you ask "why does this retry twice?", Claude answers from your own notes, with the date, checked against today's code.
4
13
 
5
- selflore is a Claude Code skill. It captures the moments where Claude did real work *for* you (a bug root-caused, a tradeoff made, a 40-line module you never read), then tests you on them once a week. Misses come back at +7 and +21 days until they stick. Getting it wrong is the feature.
14
+ Nothing is ever due. There is no weekly test unless you ask for one. selflore reads what you understand from what you do: asking about the same thing again, or the same code breaking on you again, marks it as a place you get stuck. You test yourself only on what you pick.
6
15
 
7
16
  ## Install
8
17
 
@@ -17,25 +26,51 @@ A few questions:
17
26
  - **focus**: details, design or mixed, plus a balance if you pick mixed;
18
27
  - **how capture happens**: background, quiet or off;
19
28
  - the model for background capture;
20
- - whether you want a nudge when a test is overdue.
29
+ - whether you also want a weekly test (default: no);
30
+ - whether selflore may offer a 2-minute check (default: yes).
21
31
 
22
- Re-run `init` at any time to change your answers. Your data is kept. Restart any open Claude Code sessions afterwards.
32
+ Re-run `init` at any time to change your answers. Your data is kept. Restart any open Claude Code sessions afterwards.
23
33
 
24
34
  ## Use
25
35
 
26
- Work normally. selflore never interrupts you:
27
- - **background** (default): after turns with real code work, a separate headless Claude reads the new part of the session and writes entries. Your next session starts with a one-line "captured N entries" mention.
28
- - **quiet**: Claude gets a one-line hint with your next message and logs at a natural pause.
29
- - **off**: only `/selflore log`.
36
+ Work normally. selflore never interrupts a task.
30
37
 
31
- There's no cap. Near-duplicates are merged into the existing entry. Entries untested for 3 weeks drop out of the quiz but stay in notes.
38
+ **It captures.** After turns with real work, a separate headless Claude reads the new part of the session and writes notes. What counts:
39
+ - something you asked to have explained (the strongest signal: you just said what you didn't know);
40
+ - a bug root-caused and fixed (a test failed, was fixed, passed);
41
+ - a new dependency;
42
+ - a large piece of code with a real decision in it.
32
43
 
33
- **Focus** sets what gets captured:
34
- - `details`: language and library specifics;
35
- - `design`: architecture and tradeoffs;
36
- - `mixed`: both, with a balance you choose.
44
+ Each note has 1–3 topics (`stripe`, `idempotency`), the files it is about, a question, and a short body that leads with the why. Near-duplicates are merged. Capture modes: **background** (default), **quiet** (Claude logs at a natural pause, no extra call) or **off** (only `/selflore log`).
45
+
46
+ **It answers.** Ask how or why something in your code works. If your notes cover it, Claude answers from them: "From your notes, Oct 12: you moved dedupe to a table because retries were causing double refunds." If the files changed since the note was written, Claude reads them and tells you what is different. If nothing matches, selflore says nothing.
47
+
48
+ **It notices.** Two things mark an area as a place you get stuck:
49
+ - you ask about something a note already answered, a week or more later;
50
+ - a test fails, gets fixed and passes again in the same file or folder, in three different sessions within 60 days.
37
51
 
38
- It's set globally and can be overridden per project; the project setting wins:
52
+ When that happens, selflore says so once ("Third time `src/auth/token.ts` has bitten you. Want the 2-minute version?"). At most one offer per session, never twice about the same thing in a month, and you can turn offers off.
53
+
54
+ **It tests you when you ask.** `/selflore test auth flow in nebula`, or a project, or a topic. Three to five questions, graded straight away, each miss explained. A question you miss comes back first the next time you test that area. A bare `/selflore test` suggests the areas where you get stuck and lets you pick.
55
+
56
+ | Command | What it does |
57
+ |---|---|
58
+ | ask in plain words, or `/selflore recall <question>` | Answers from your notes, with the date, checked against the current code. |
59
+ | `/selflore test [anything]` | A short test on a project (`nebula/v0`), a topic (`react`) or anything in your own words. Say `unfair` to drop a question for good. |
60
+ | `/selflore notes` | Opens your notes in the browser: **Map**, **Notes** and **Stats**. In the terminal: `npx selflore notes` (`--project <name>`, or `--text` for plain text, with `--all` for every week). |
61
+ | `/selflore stats` | Where you get stuck and why, then the results of the tests you chose to take. |
62
+ | `/selflore log` | Write a note by hand. Also covers work done outside Claude Code. |
63
+ | `/selflore focus` | What gets captured: `details`, `design` or `mixed`, globally or per project. |
64
+
65
+ **The map.** The page opens on a 3D heat map of all your notes: you → projects (or topics) → notes, with a short "Where you get stuck" list beside it. Colour and size are heat: dim slate where things are settled, through amber, to red where you get stuck, and only a stuck note glows. A small hollow dot has no signal yet. It turns slowly and holds still while your pointer is over it. Drag to rotate, pinch or ⌘ + scroll to zoom, click a dot to see why it is the colour it is. **Flat** switches to a 2D view that is easier to read; **Labels** off gives you a picture with no project text in it. The 3D renderer ships with selflore; the page loads nothing from the internet.
66
+
67
+ **Notes** is the same notes as text: search, filters, newest or stuck first. Each note is one line and opens in place with its answer, code, files and the reasons for its heat. Notes are grouped by week (or by how stuck); the newest groups start open, older ones are folded to a heading with a count, and a long group shows its first 15.
68
+
69
+ **Stats** starts with what you have: notes per week, and your biggest projects and topics. Beside it, one bar splits your notes by heat, with the warmest areas under it. Test results come last, and show percentages only after 5 answers (3 per topic or project), so one right answer never reads as 100%. Click a week, a project, a topic or an area to see those notes.
70
+
71
+ **Testing from the browser.** **Test me** runs a self-graded test: write your answer, reveal the note, grade yourself. Filter to a project or topic, or search, and the button tests just that. Every grade is saved the moment you click.
72
+
73
+ **Focus** sets what gets captured:
39
74
 
40
75
  ```bash
41
76
  selflore focus design # global
@@ -44,13 +79,7 @@ selflore focus mixed --balance design # mostly design
44
79
  selflore focus --reset --project # back to the global setting
45
80
  ```
46
81
 
47
- | Command | What it does |
48
- |---|---|
49
- | `/selflore test` | Weekly quiz, about 10 questions and about 20 minutes. Each answer is graded immediately as got it, partial or missed, with an explanation. Say `unfair` to drop a question for good. |
50
- | `/selflore log` | Log the current thing manually. Also covers work done outside Claude Code. |
51
- | `/selflore notes` | Opens a page in your browser with everything captured this week, grouped by day, with answers hidden until you click. You can browse weeks and filter. In the terminal, run `npx selflore notes` (`--all`, `--project <name>`, or `--text` for plain text). |
52
- | `/selflore focus` | Same as `selflore focus` above, from inside Claude Code. |
53
- | `/selflore stats` | Weekly table: entries, questions, pass rate overall and by skill, retest backlog, and self-rating vs. observed pass rate. |
82
+ **Upgrading from 0.1.** Run `npx selflore init`. Your notes are kept. Notes from before topics existed are tagged `architecture` or `debugging`; `npx selflore retag` proposes real topics for them (it changes nothing), and `npx selflore retag --apply` writes them after backing the notes up. The weekly test is switched off unless you had actually been taking it.
54
83
 
55
84
  ## Remove
56
85
 
@@ -61,30 +90,34 @@ npx selflore remove --purge # remove everything
61
90
 
62
91
  ## How it works
63
92
 
64
- - **Skill** at `~/.claude/skills/selflore/`. Claude writes entries, builds quizzes and grades answers.
93
+ - **Skill** at `~/.claude/skills/selflore/`. Claude answers from notes, writes entries, builds and grades tests.
65
94
  - **Hooks** are merged into `~/.claude/settings.json`; existing hooks are never touched, and a backup is written to `settings.json.selflore-bak`.
66
- - `SessionStart` gives Claude the session id and capture mode, mentions background captures, and (if enabled) reminds you when a test is overdue.
67
- - `Stop` never blocks. It looks only at work since the last capture: real code changes (not docs, reports or one-off scripts), new dependencies, and fail → fix → pass loops. It then starts a background capture or, in quiet mode, leaves a hint.
68
- - `UserPromptSubmit` delivers that hint in quiet mode.
69
- - **Data** lives globally in `~/.selflore/`, because learning spans projects:
95
+ - `SessionStart` gives Claude the session id and capture mode, and mentions background captures.
96
+ - `Stop` never blocks. It looks at the work since the last capture, starts a background capture when there is something worth keeping, and logs fail → fix → pass loops and trouble-free edits.
97
+ - `UserPromptSubmit` checks whether your prompt is a question your notes may answer, and hands Claude up to three candidates. No model call, no network; it adds nothing when there is no match.
98
+ - **Heat** is one number per note, from settled to stuck, or none when there is no signal. Re-asks, loops and missed answers heat a note; passed answers and trouble-free edits cool it; everything fades with a 30-day half-life.
99
+ - **Notes server:** `selflore notes` starts a small local server (127.0.0.1 only, with a random token in the URL) so the in-page test can save answers. It stops by itself after 30 minutes with no use.
100
+ - **Data** lives globally in `~/.selflore/`, because understanding spans projects:
70
101
 
71
102
  ```
72
103
  ~/.selflore/
73
- config.json rating, keep_sharp, capture_intensity, focus, projects, capture, capture_model, nudge, last_test_at
104
+ config.json rating, keep_sharp, capture_intensity, focus, projects, capture, capture_model, cadence, offers
74
105
  entries/ YYYY-MM-DD-slug.md (frontmatter + ≤120 words + an optional code snippet)
106
+ signals.jsonl asks, loops, trouble-free edits and offers: what heat is read from
75
107
  results.jsonl one line per graded answer
76
- queue.json retest due dates
77
- state/ per-session capture progress, background-capture log
108
+ queue.json questions to ask first next time
109
+ backups/ copies of entries/ made by `retag --apply`
110
+ state/ per-session capture progress, recall index, background-capture log
78
111
  app/ the runtime the hooks call
79
112
  ```
80
113
 
81
- Each entry stores the `testable` question written at capture time, while context is fresh. It also stores a code snippet and the commit SHA, so quiz questions still work after the code moves on.
114
+ Each note stores its question, a code snippet, the commit and a fingerprint of its files, so selflore can tell whether the code has moved on.
82
115
 
83
116
  ## Develop
84
117
 
85
118
  ```bash
86
119
  npm install
87
- npm run build
120
+ npm run build # tsc, then bundles the 3D graph into dist/vendor
88
121
  npm test
89
122
  SELFLORE_HOME=/tmp/sl CLAUDE_HOME=/tmp/cl node dist/cli.js init --yes # sandboxed install
90
123
  ```
package/dist/cli.js CHANGED
@@ -1,49 +1,111 @@
1
1
  #!/usr/bin/env node
2
+ import fs from "node:fs";
2
3
  import { focusArgs, focusCmd, notesCmd } from "./lib/commands.js";
3
4
  import { removeFiles } from "./lib/install.js";
4
5
  import { selfloreHome } from "./lib/paths.js";
5
- const USAGE = `selflore — own what your agent builds
6
-
7
- usage:
8
- npx selflore init install skill + hooks, run onboarding (re-run to change answers)
9
- npx selflore init --yes non-interactive; keep existing config or use defaults
10
- npx selflore notes open this week's notes in your browser (--all, --project <name>, --text)
11
- npx selflore focus [mode] show or set what gets captured: details | design | mixed
12
- --balance design|balanced|details (mixed), --project (this repo only), --reset
13
- npx selflore remove remove skill + hooks, keep your data
14
- npx selflore remove --purge remove everything, including ${selfloreHome()}
15
-
16
- inside Claude Code: /selflore test /selflore log /selflore notes /selflore stats /selflore focus`;
6
+ import { createUi } from "./lib/ui.js";
7
+ const ui = createUi();
8
+ /** The package version, when this runs from the package (the copy under the selflore home has none). */
9
+ function version() {
10
+ try {
11
+ const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
12
+ return pkg.name === "selflore" ? pkg.version : undefined;
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ }
18
+ function help() {
19
+ const { bold, dim, accent, row, symbols } = ui;
20
+ const more = (text) => row("", text);
21
+ const slash = (names) => names.map((c) => accent(`/selflore ${c}`)).join(" ");
22
+ return [
23
+ ui.banner(version()),
24
+ ` ${bold("Usage")}`,
25
+ row("npx selflore init", "Install the skill and hooks and set up (re-run to change answers)"),
26
+ row("npx selflore init --yes", "No questions: keep your config, or use the defaults"),
27
+ row("npx selflore notes", "Open your notes in the browser: 3D heat map, notes, stats"),
28
+ more("--project <name>; --text [--all] for plain text"),
29
+ row("npx selflore focus [mode]", "Show or set what gets captured: details | design | mixed"),
30
+ more("--balance design|balanced|details for mixed"),
31
+ more("--project for this repo only, --reset"),
32
+ row("npx selflore retag", 'Propose real topics for entries tagged "architecture"/"debugging"'),
33
+ more("Changes nothing until --apply (entries are backed up first)"),
34
+ more("--all re-tags every entry"),
35
+ row("npx selflore remove", "Remove the skill and hooks, keep your data"),
36
+ row("npx selflore remove --purge", `Remove everything, including ${selfloreHome()}`),
37
+ row("npx selflore --version", "Print the version"),
38
+ "",
39
+ ` ${bold("Inside Claude Code")}`,
40
+ ` ${dim("Ask how or why something in your code works, or run")}`,
41
+ ` ${slash(["recall <question>", "test [anything]", "notes"])}`,
42
+ ` ${slash(["stats", "log", "focus"])}`,
43
+ "",
44
+ ` ${symbols.spark} ${dim("https://github.com/lak7/selflore")}`,
45
+ "",
46
+ ].join("\n");
47
+ }
17
48
  async function main() {
18
49
  const [cmd, ...args] = process.argv.slice(2);
19
50
  switch (cmd) {
20
51
  case "init": {
21
52
  // Imported lazily: the prompt library is only needed here, not in the hook runtime.
22
53
  const { init } = await import("./init.js");
23
- await init({ yes: args.includes("--yes") || args.includes("-y") });
54
+ await init({ yes: args.includes("--yes") || args.includes("-y"), version: version() });
24
55
  return;
25
56
  }
26
57
  case "notes": {
27
58
  const i = args.indexOf("--project");
28
- console.log(notesCmd({ all: args.includes("--all"), project: i >= 0 ? args[i + 1] : undefined, text: args.includes("--text") }).out);
59
+ const r = await notesCmd({ all: args.includes("--all"), project: i >= 0 ? args[i + 1] : undefined, text: args.includes("--text") });
60
+ console.log(ui.frame("notes", r.out));
29
61
  return;
30
62
  }
31
63
  case "focus": {
32
64
  const r = focusCmd(focusArgs(args));
33
- (r.code === 0 ? console.log : console.error)(r.out);
65
+ if (r.code === 0)
66
+ console.log(ui.frame("focus", r.out));
67
+ else
68
+ console.error(r.out);
69
+ process.exitCode = r.code;
70
+ return;
71
+ }
72
+ case "retag": {
73
+ const { retagCmd } = await import("./lib/retag.js");
74
+ const i = args.indexOf("--project");
75
+ const r = retagCmd({
76
+ apply: args.includes("--apply"),
77
+ all: args.includes("--all"),
78
+ project: i >= 0 ? args[i + 1] : undefined,
79
+ onBatch: (done, total) => process.stderr.write(` ${done}/${total}\n`),
80
+ });
81
+ if (r.code === 0)
82
+ console.log(ui.frame("retag", r.out));
83
+ else
84
+ console.error(r.out);
34
85
  process.exitCode = r.code;
35
86
  return;
36
87
  }
37
88
  case "remove": {
38
89
  const purge = args.includes("--purge");
39
90
  removeFiles(purge);
40
- console.log(purge ? `selflore removed, including ${selfloreHome()}` : `selflore removed; data kept in ${selfloreHome()}`);
91
+ console.log(ui.banner(version()));
92
+ console.log(` ${ui.symbols.ok} ${ui.bold("selflore removed")} ${ui.symbols.dot} ${ui.dim(purge ? `including ${selfloreHome()}` : `data kept in ${selfloreHome()}`)}\n`);
41
93
  return;
42
94
  }
95
+ case "-v":
96
+ case "--version":
97
+ console.log(version() ?? "unknown");
98
+ return;
99
+ case undefined:
100
+ case "help":
101
+ case "-h":
102
+ case "--help":
103
+ console.log(help());
104
+ return;
43
105
  default:
44
- console.log(USAGE);
45
- if (cmd && cmd !== "help" && cmd !== "--help" && cmd !== "-h")
46
- process.exitCode = 1;
106
+ console.error(`Unknown command: ${cmd}`);
107
+ console.log(help());
108
+ process.exitCode = 1;
47
109
  }
48
110
  }
49
111
  main().catch((err) => {
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { handlePromptSubmit } from "../lib/hook-logic.js";
3
3
  import { readHookInput, runHook } from "./io.js";
4
- // Quiet capture mode: turns a pending trigger into one line of context for the next turn. Never blocks.
4
+ // Adds context for the next turn and never blocks: the notes that may answer a question the user
5
+ // just asked, and (quiet capture mode) a pending capture hint.
5
6
  runHook(async () => {
6
7
  const out = handlePromptSubmit(await readHookInput());
7
8
  if (out)
package/dist/init.js CHANGED
@@ -2,6 +2,7 @@ import * as p from "@clack/prompts";
2
2
  import { configExists, DEFAULT_CONFIG, readConfig, writeConfig, } from "./lib/config.js";
3
3
  import { installFiles } from "./lib/install.js";
4
4
  import { paths } from "./lib/paths.js";
5
+ import { createUi } from "./lib/ui.js";
5
6
  import { ratingPrompt } from "./rating-prompt.js";
6
7
  const BUILTIN_SHARP = ["debugging", "architecture", "fundamentals"];
7
8
  function bail(v) {
@@ -89,13 +90,22 @@ async function ask(existing, reinstall) {
89
90
  initialValue: existing.capture_model,
90
91
  }));
91
92
  }
92
- const nudge = bail(await p.select({
93
- message: "How pushy should selflore be?",
93
+ const weekly = bail(await p.select({
94
+ message: "Do you also want a weekly test?",
94
95
  options: [
95
- { value: false, label: "Quiz only" },
96
- { value: true, label: "Quiz + a nudge when a test is overdue" },
96
+ { value: "off", label: "No", hint: "recommended; selflore answers from your notes, and you test yourself only when you ask" },
97
+ { value: "quiet", label: "Yes", hint: "about 10 questions once a week, when you run /selflore test" },
98
+ { value: "nudge", label: "Yes, and remind me", hint: "also a one-line reminder when the week's test is overdue" },
97
99
  ],
98
- initialValue: existing.nudge,
100
+ initialValue: existing.cadence === "weekly" ? (existing.nudge ? "nudge" : "quiet") : "off",
101
+ }));
102
+ const offers = bail(await p.select({
103
+ message: "May selflore offer a 2-minute check when you ask about the same thing twice, or the same code keeps breaking?",
104
+ options: [
105
+ { value: true, label: "Yes", hint: "at most one offer per session, and never twice about the same area in a month" },
106
+ { value: false, label: "No", hint: "never offer anything; just answer from my notes" },
107
+ ],
108
+ initialValue: existing.offers,
99
109
  }));
100
110
  return {
101
111
  ...existing,
@@ -105,19 +115,24 @@ async function ask(existing, reinstall) {
105
115
  focus: { mode, balance },
106
116
  capture,
107
117
  capture_model,
108
- nudge,
118
+ cadence: weekly === "off" ? "off" : "weekly",
119
+ nudge: weekly === "nudge",
120
+ offers,
109
121
  };
110
122
  }
111
123
  export async function init(opts) {
124
+ const ui = createUi();
112
125
  const reinstall = configExists();
113
126
  const existing = reinstall ? readConfig() : DEFAULT_CONFIG;
127
+ console.log(ui.banner(opts.version));
114
128
  if (opts.yes || !process.stdin.isTTY) {
115
129
  writeConfig(existing);
116
130
  installFiles();
117
- console.log(`selflore installed (${reinstall ? "kept existing config" : "default config"}) → ${paths.config()}`);
131
+ const kept = reinstall ? "kept existing config" : "default config";
132
+ console.log(` ${ui.symbols.ok} ${ui.bold("selflore installed")} ${ui.symbols.dot} ${ui.dim(`${kept} → ${paths.config()}`)}\n`);
118
133
  return;
119
134
  }
120
- p.intro("selflore — own what your agent builds");
135
+ p.intro(ui.bold(reinstall ? "Update your setup" : "Set up selflore"));
121
136
  if (reinstall)
122
137
  p.log.info("Existing config found; your previous answers are pre-filled. Data is kept.");
123
138
  const config = await ask(existing, reinstall);
@@ -130,8 +145,9 @@ export async function init(opts) {
130
145
  "",
131
146
  "Work normally. selflore never interrupts; lore is captured as you go.",
132
147
  "Per-project focus: run `selflore focus details --project` inside a repo.",
133
- "Once a week, run /selflore test (~20 min). /selflore stats shows the trend.",
148
+ "Ask Claude how or why something in your code works: it answers from your notes.",
149
+ "Nothing is ever due. /selflore test <anything> quizzes you on a topic when you want it.",
134
150
  "Restart any open Claude Code sessions to pick up the skill and hooks.",
135
151
  ].join("\n"), "Installed");
136
- p.outro("Getting it wrong is the feature.");
152
+ p.outro("Your agent wrote it. selflore remembers why.");
137
153
  }
@@ -3,7 +3,7 @@ import fs from "node:fs";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
5
  import { effectiveFocus, readConfig } from "./config.js";
6
- import { validateEntry } from "./entries.js";
6
+ import { GENERIC_TOPICS, listEntries, normalizeTopics, ORIGINS, validateEntry } from "./entries.js";
7
7
  import { capturePrompt } from "./capture-prompt.js";
8
8
  import { projectInfo, storeEntry } from "./commands.js";
9
9
  import { paths } from "./paths.js";
@@ -90,7 +90,8 @@ export function toDraft(raw, focusMode) {
90
90
  const draft = {
91
91
  kind: r.kind,
92
92
  level: r.level,
93
- skill: typeof r.skill === "string" ? r.skill : "",
93
+ topics: normalizeTopics(r.topics, r.skill),
94
+ ...(ORIGINS.includes(r.origin) ? { origin: r.origin } : {}), // anything else: inferred from the kind
94
95
  paths: Array.isArray(r.paths) ? r.paths.filter((p) => typeof p === "string") : [],
95
96
  testable: typeof r.testable === "string" ? r.testable.trim() : "",
96
97
  body: `${typeof r.body === "string" ? r.body.trim() : ""}${snippet ? `\n\n\`\`\`${lang}\n${snippet}\n\`\`\`` : ""}`,
@@ -126,13 +127,31 @@ export function askClaude(systemPrompt, input, model) {
126
127
  return out;
127
128
  }
128
129
  }
130
+ /**
131
+ * Topics worth reusing, so one subject keeps one name: what this project's entries already use
132
+ * (most used first), then what other projects use. Generic words are never offered.
133
+ */
134
+ export function knownTopics(project, entries = listEntries(), limit = 30) {
135
+ const mine = new Map();
136
+ const others = new Map();
137
+ for (const e of entries)
138
+ for (const t of e.topics) {
139
+ if (GENERIC_TOPICS.has(t))
140
+ continue;
141
+ const counts = e.project === project ? mine : others;
142
+ counts.set(t, (counts.get(t) ?? 0) + 1);
143
+ }
144
+ const byUse = (m) => [...m.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([t]) => t);
145
+ return [...new Set([...byUse(mine), ...byUse(others)])].slice(0, limit);
146
+ }
129
147
  /** Ask the capture model for entries from an excerpt and store them. Returns how many were stored. */
130
148
  export function runCapture(opts) {
131
149
  if (!opts.excerpt.trim())
132
150
  return 0;
133
151
  const config = readConfig();
134
- const focus = effectiveFocus(config, projectInfo(opts.cwd).project);
135
- const reply = (opts.ask ?? askClaude)(capturePrompt(config, focus), `Session excerpt (most recent work):\n\n${opts.excerpt}`, captureModel(config, opts.sessionModel));
152
+ const project = projectInfo(opts.cwd).project;
153
+ const focus = effectiveFocus(config, project);
154
+ const reply = (opts.ask ?? askClaude)(capturePrompt(config, focus, knownTopics(project)), `Session excerpt (most recent work):\n\n${opts.excerpt}`, captureModel(config, opts.sessionModel));
136
155
  let stored = 0;
137
156
  for (const raw of parseCaptureReply(reply)) {
138
157
  const draft = toDraft(raw, focus.mode);
@@ -1,8 +1,8 @@
1
1
  import { describeFocus } from "./config.js";
2
2
  const INTENSITY_BAR = {
3
- light: "Only the biggest moments: a significant bug root-caused, a major design decision, or a substantial module the user clearly did not read. Most chunks yield 0 entries.",
4
- normal: "Real units of work: a bug root-caused and fixed, a non-obvious tradeoff with a stated reason, a new library/API/pattern, a ~30+ line module the user did not read, or the user correcting the agent. Routine edits yield 0 entries.",
5
- thorough: "Anything the user would benefit from understanding, including smaller gotchas, edge cases and API behaviour discovered along the way. Still skip renames, formatting and config tweaks.",
3
+ light: "Only the biggest moments: a significant bug root-caused, a major design decision, or something the developer asked to have explained at length. Most chunks yield 0 entries.",
4
+ normal: "Something the developer asked to have explained, a bug root-caused and fixed, a non-obvious tradeoff with a stated reason, a new library/API/pattern, or the developer correcting the agent. A module the agent wrote counts only when there is a real decision in it. Routine edits yield 0 entries, and most chunks yield 0 or 1.",
5
+ thorough: "Anything the developer would benefit from understanding, including smaller gotchas, edge cases and API behaviour discovered along the way. Still skip renames, formatting and config tweaks.",
6
6
  };
7
7
  function focusRule(focus) {
8
8
  if (focus.mode === "details")
@@ -13,8 +13,11 @@ function focusRule(focus) {
13
13
  return `Capture both levels, tagging each honestly ("detail" = language/library specifics; "design" = architecture and tradeoffs). ${lean}`;
14
14
  }
15
15
  /** System prompt for the headless background capture call. Output: a JSON array, nothing else. */
16
- export function capturePrompt(config, focus) {
17
- return `You are selflore's capture step. You read an excerpt of a Claude Code session in which an AI agent did work for a developer, and you extract "lore": moments the developer should understand but probably doesn't, because the agent did the work. Each entry becomes a quiz question in the developer's weekly test.
16
+ export function capturePrompt(config, focus, knownTopics = []) {
17
+ const reuse = knownTopics.length
18
+ ? ` Reuse these when they fit, spelled exactly: ${knownTopics.join(", ")}. Only add a new one when none does.`
19
+ : "";
20
+ return `You are selflore's capture step. You read an excerpt of a Claude Code session in which an AI agent did work for a developer, and you extract "lore": moments the developer should understand but probably doesn't, because the agent did the work. Each entry is a dated note the developer will ask about later ("why does this retry twice?"), and a question they can be tested on.
18
21
 
19
22
  Bar for logging (intensity: ${config.capture_intensity}): ${INTENSITY_BAR[config.capture_intensity]}
20
23
  Focus (${describeFocus(focus)}): ${focusRule(focus)}
@@ -23,11 +26,14 @@ Self-rating ${config.rating}/10: ${config.rating <= 3 ? "favour fundamentals" :
23
26
 
24
27
  Rules:
25
28
  - The "testable" question is the gate. It must test understanding (why / what breaks / what happens if / what does this print and why), never trivia like names or file locations. If you cannot write one sharp question, skip the moment.
29
+ - The strongest signal is the developer asking how or why something works and the agent explaining it: they have just said what they didn't know. Capture it, with origin "asked". But skip a question whose answer is a one-line fact (what a flag does, where a file lives, what a command is called).
26
30
  - Prefer one deep entry over several shallow ones. Do not log the same idea twice.
27
31
  - Skip anything the developer wrote themselves, reports/docs the agent wrote for them to read, and throwaway one-off scripts.
28
- - "body" is the answer key: at most ~120 words with the facts a correct answer must contain (the why, the root cause, the alternative rejected).
32
+ - "body" is the note itself and the answer key, at most ~120 words. Lead with what the code alone can't tell anyone: why it was done this way, what was rejected, which bug or constraint forced it. What the code does comes second, and only as much as the why needs.
33
+ - "origin": "asked" (the developer asked for the explanation), "bugfix" (something failed and was root-caused and fixed), "dependency" (a library or API was added or changed), or "write" (anything else the agent built).
29
34
  - "snippet" (optional, max 40 lines): the essential code as it is now. For a bug, the fixed code; name the original bug in the body.
35
+ - "topics": 1 to 3, lowercase. The first is the group the moment sits in: the technology, framework, service or subsystem ("fastapi", "postgres", "stripe", "notes server"). Entries are grouped by it, so keep it broad and reuse an existing one wherever possible. Then the concept ("retry logic", "idempotency", "race condition"). Never a kind of work: not "architecture", "debugging", "fundamentals", "design" or "bug".${reuse}
30
36
 
31
37
  Output ONLY a JSON array (possibly empty, []), no prose, no code fences. Each element:
32
- {"kind": "bug"|"decision"|"concept"|"pattern", "level": "detail"|"design", "skill": "<one of the keep-sharp areas or a stack name>", "paths": ["relative/path"], "testable": "<question>", "body": "<answer key>", "snippet": "<code or omit>", "snippet_lang": "<ts|py|…|omit>"}`;
38
+ {"kind": "bug"|"decision"|"concept"|"pattern", "level": "detail"|"design", "origin": "asked"|"bugfix"|"dependency"|"write", "topics": ["<technology>", "<concept>"], "paths": ["relative/path"], "testable": "<question>", "body": "<answer key>", "snippet": "<code or omit>", "snippet_lang": "<ts|py|…|omit>"}`;
33
39
  }