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.
- package/README.md +64 -31
- package/dist/cli.js +81 -19
- package/dist/hooks/user-prompt-submit.js +2 -1
- package/dist/init.js +26 -10
- package/dist/lib/background.js +23 -4
- package/dist/lib/capture-prompt.js +13 -7
- package/dist/lib/commands.js +199 -35
- package/dist/lib/config.js +24 -4
- package/dist/lib/entries.js +56 -4
- package/dist/lib/heat.js +141 -0
- package/dist/lib/hook-logic.js +44 -9
- package/dist/lib/index-cache.js +46 -0
- package/dist/lib/links.js +58 -0
- package/dist/lib/logo.js +6 -0
- package/dist/lib/notes-graph.js +585 -0
- package/dist/lib/notes-html.js +148 -339
- package/dist/lib/notes-page-css.js +279 -0
- package/dist/lib/notes-page-js.js +959 -0
- package/dist/lib/notes.js +19 -13
- package/dist/lib/nudge.js +2 -1
- package/dist/lib/paths.js +6 -0
- package/dist/lib/question.js +19 -0
- package/dist/lib/queue.js +6 -4
- package/dist/lib/recall.js +149 -0
- package/dist/lib/results.js +1 -0
- package/dist/lib/retag.js +150 -0
- package/dist/lib/server-launch.js +73 -0
- package/dist/lib/server.js +120 -0
- package/dist/lib/session.js +1 -1
- package/dist/lib/signals.js +51 -0
- package/dist/lib/stats.js +71 -44
- package/dist/lib/struggle.js +120 -0
- package/dist/lib/surface.js +75 -0
- package/dist/lib/transcript.js +61 -15
- package/dist/lib/ui.js +127 -0
- package/dist/notes-server.js +39 -0
- package/dist/sl.js +29 -4
- package/dist/vendor/graph3d.js +5402 -0
- package/package.json +6 -3
- package/skill/SKILL.md +6 -5
- package/skill/references/capture.md +6 -5
- package/skill/references/recall.md +44 -0
- package/skill/references/stats.md +5 -1
- package/skill/references/test.md +35 -30
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
|
-
**
|
|
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
|
-
|
|
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
|
|
29
|
+
- whether you also want a weekly test (default: no);
|
|
30
|
+
- whether selflore may offer a 2-minute check (default: yes).
|
|
21
31
|
|
|
22
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
67
|
-
- `Stop` never blocks. It looks
|
|
68
|
-
- `UserPromptSubmit`
|
|
69
|
-
- **
|
|
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,
|
|
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
|
|
77
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
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.
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
//
|
|
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
|
|
93
|
-
message: "
|
|
93
|
+
const weekly = bail(await p.select({
|
|
94
|
+
message: "Do you also want a weekly test?",
|
|
94
95
|
options: [
|
|
95
|
-
{ value:
|
|
96
|
-
{ value:
|
|
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
|
-
|
|
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
|
-
|
|
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("
|
|
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
|
-
"
|
|
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("
|
|
152
|
+
p.outro("Your agent wrote it. selflore remembers why.");
|
|
137
153
|
}
|
package/dist/lib/background.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
135
|
-
const
|
|
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
|
|
4
|
-
normal: "
|
|
5
|
-
thorough: "Anything the
|
|
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
|
-
|
|
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
|
|
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", "
|
|
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
|
}
|