selflore 0.0.2 → 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 +80 -17
- package/dist/cli.js +87 -17
- package/dist/hooks/capture-worker.js +27 -0
- package/dist/hooks/io.js +6 -1
- package/dist/hooks/session-start.js +2 -8
- package/dist/hooks/stop.js +3 -21
- package/dist/hooks/user-prompt-submit.js +10 -0
- package/dist/init.js +84 -18
- package/dist/lib/background.js +173 -0
- package/dist/lib/capture-prompt.js +39 -0
- package/dist/lib/commands.js +321 -67
- package/dist/lib/config.js +84 -5
- package/dist/lib/entries.js +82 -3
- package/dist/lib/heat.js +141 -0
- package/dist/lib/hook-logic.js +107 -0
- package/dist/lib/index-cache.js +46 -0
- package/dist/lib/install.js +2 -3
- 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 -330
- package/dist/lib/notes-page-css.js +279 -0
- package/dist/lib/notes-page-js.js +959 -0
- package/dist/lib/notes.js +19 -6
- package/dist/lib/nudge.js +8 -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 +11 -1
- 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 +27 -1
- package/dist/lib/settings.js +5 -1
- package/dist/lib/signals.js +51 -0
- package/dist/lib/stats.js +72 -40
- package/dist/lib/struggle.js +120 -0
- package/dist/lib/surface.js +75 -0
- package/dist/lib/transcript.js +205 -37
- package/dist/lib/ui.js +127 -0
- package/dist/notes-server.js +39 -0
- package/dist/sl.js +33 -14
- package/dist/vendor/graph3d.js +5402 -0
- package/package.json +6 -3
- package/skill/SKILL.md +29 -14
- package/skill/references/capture.md +16 -12
- package/skill/references/log.md +2 -2
- package/skill/references/recall.md +44 -0
- package/skill/references/stats.md +5 -1
- package/skill/references/test.md +49 -31
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
|
|
|
@@ -10,18 +19,67 @@ selflore is a Claude Code skill. It captures the moments where Claude did real w
|
|
|
10
19
|
npx selflore init
|
|
11
20
|
```
|
|
12
21
|
|
|
13
|
-
|
|
22
|
+
A few questions:
|
|
23
|
+
- a self-rating from 1 to 10 (←/→ on a scale, starting at 5);
|
|
24
|
+
- what you want to keep sharp;
|
|
25
|
+
- **capture intensity** (light, normal or thorough);
|
|
26
|
+
- **focus**: details, design or mixed, plus a balance if you pick mixed;
|
|
27
|
+
- **how capture happens**: background, quiet or off;
|
|
28
|
+
- the model for background capture;
|
|
29
|
+
- whether you also want a weekly test (default: no);
|
|
30
|
+
- whether selflore may offer a 2-minute check (default: yes).
|
|
31
|
+
|
|
32
|
+
Re-run `init` at any time to change your answers. Your data is kept. Restart any open Claude Code sessions afterwards.
|
|
14
33
|
|
|
15
34
|
## Use
|
|
16
35
|
|
|
17
|
-
Work normally.
|
|
36
|
+
Work normally. selflore never interrupts a task.
|
|
37
|
+
|
|
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.
|
|
43
|
+
|
|
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.
|
|
51
|
+
|
|
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.
|
|
18
55
|
|
|
19
56
|
| Command | What it does |
|
|
20
57
|
|---|---|
|
|
21
|
-
|
|
|
22
|
-
| `/selflore
|
|
23
|
-
| `/selflore notes` | Opens
|
|
24
|
-
| `/selflore stats` |
|
|
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:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
selflore focus design # global
|
|
77
|
+
selflore focus details --project # just this repo (e.g. while learning a new language)
|
|
78
|
+
selflore focus mixed --balance design # mostly design
|
|
79
|
+
selflore focus --reset --project # back to the global setting
|
|
80
|
+
```
|
|
81
|
+
|
|
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.
|
|
25
83
|
|
|
26
84
|
## Remove
|
|
27
85
|
|
|
@@ -32,29 +90,34 @@ npx selflore remove --purge # remove everything
|
|
|
32
90
|
|
|
33
91
|
## How it works
|
|
34
92
|
|
|
35
|
-
- **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.
|
|
36
94
|
- **Hooks** are merged into `~/.claude/settings.json`; existing hooks are never touched, and a backup is written to `settings.json.selflore-bak`.
|
|
37
|
-
- `SessionStart` gives Claude the session id and
|
|
38
|
-
- `Stop`
|
|
39
|
-
-
|
|
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:
|
|
40
101
|
|
|
41
102
|
```
|
|
42
103
|
~/.selflore/
|
|
43
|
-
config.json rating, keep_sharp,
|
|
104
|
+
config.json rating, keep_sharp, capture_intensity, focus, projects, capture, capture_model, cadence, offers
|
|
44
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
|
|
45
107
|
results.jsonl one line per graded answer
|
|
46
|
-
queue.json
|
|
47
|
-
|
|
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
|
|
48
111
|
app/ the runtime the hooks call
|
|
49
112
|
```
|
|
50
113
|
|
|
51
|
-
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.
|
|
52
115
|
|
|
53
116
|
## Develop
|
|
54
117
|
|
|
55
118
|
```bash
|
|
56
119
|
npm install
|
|
57
|
-
npm run build
|
|
120
|
+
npm run build # tsc, then bundles the 3D graph into dist/vendor
|
|
58
121
|
npm test
|
|
59
122
|
SELFLORE_HOME=/tmp/sl CLAUDE_HOME=/tmp/cl node dist/cli.js init --yes # sandboxed install
|
|
60
123
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,41 +1,111 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import fs from "node:fs";
|
|
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
|
-
|
|
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
|
+
}
|
|
15
48
|
async function main() {
|
|
16
49
|
const [cmd, ...args] = process.argv.slice(2);
|
|
17
50
|
switch (cmd) {
|
|
18
51
|
case "init": {
|
|
19
52
|
// Imported lazily: the prompt library is only needed here, not in the hook runtime.
|
|
20
53
|
const { init } = await import("./init.js");
|
|
21
|
-
await init({ yes: args.includes("--yes") || args.includes("-y") });
|
|
54
|
+
await init({ yes: args.includes("--yes") || args.includes("-y"), version: version() });
|
|
22
55
|
return;
|
|
23
56
|
}
|
|
24
57
|
case "notes": {
|
|
25
58
|
const i = args.indexOf("--project");
|
|
26
|
-
|
|
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));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
case "focus": {
|
|
64
|
+
const r = focusCmd(focusArgs(args));
|
|
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);
|
|
85
|
+
process.exitCode = r.code;
|
|
27
86
|
return;
|
|
28
87
|
}
|
|
29
88
|
case "remove": {
|
|
30
89
|
const purge = args.includes("--purge");
|
|
31
90
|
removeFiles(purge);
|
|
32
|
-
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`);
|
|
33
93
|
return;
|
|
34
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;
|
|
35
105
|
default:
|
|
36
|
-
console.
|
|
37
|
-
|
|
38
|
-
|
|
106
|
+
console.error(`Unknown command: ${cmd}`);
|
|
107
|
+
console.log(help());
|
|
108
|
+
process.exitCode = 1;
|
|
39
109
|
}
|
|
40
110
|
}
|
|
41
111
|
main().catch((err) => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Detached background capture, started by the Stop hook: reads one transcript range,
|
|
3
|
+
// asks a headless Claude for lore entries, stores them, then releases the session lock.
|
|
4
|
+
import { logWorkerError, runCapture } from "../lib/background.js";
|
|
5
|
+
import { addAnnounce, updateSession } from "../lib/session.js";
|
|
6
|
+
import { buildExcerpt, lastModel, readTranscriptFrom } from "../lib/transcript.js";
|
|
7
|
+
const [session, transcript, from, to, cwd] = process.argv.slice(2);
|
|
8
|
+
try {
|
|
9
|
+
if (session && transcript) {
|
|
10
|
+
const { text } = readTranscriptFrom(transcript, Number(from) || 0, Number(to) || undefined);
|
|
11
|
+
const stored = runCapture({ session, cwd: cwd || process.cwd(), excerpt: buildExcerpt(text), sessionModel: lastModel(text) });
|
|
12
|
+
addAnnounce(stored);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
logWorkerError(err);
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
if (session) {
|
|
20
|
+
try {
|
|
21
|
+
updateSession(session, { capturing_since: null });
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// ignore
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/hooks/io.js
CHANGED
|
@@ -14,7 +14,12 @@ export async function readHookInput() {
|
|
|
14
14
|
return {};
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Hooks must never break the user's session: swallow everything and exit 0.
|
|
19
|
+
* Inside selflore's own background capture (SELFLORE_BG), hooks do nothing, so a capture can't trigger another.
|
|
20
|
+
*/
|
|
18
21
|
export function runHook(fn) {
|
|
22
|
+
if (process.env.SELFLORE_BG)
|
|
23
|
+
process.exit(0);
|
|
19
24
|
fn().catch(() => { }).finally(() => process.exit(0));
|
|
20
25
|
}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { listEntries } from "../lib/entries.js";
|
|
4
|
-
import { sessionStartContext } from "../lib/nudge.js";
|
|
2
|
+
import { handleSessionStart } from "../lib/hook-logic.js";
|
|
5
3
|
import { readHookInput, runHook } from "./io.js";
|
|
6
4
|
runHook(async () => {
|
|
7
|
-
const
|
|
8
|
-
if (!configExists())
|
|
9
|
-
return;
|
|
10
|
-
const oldest = listEntries()[0]?.date ?? null; // ids are date-prefixed, so sorted oldest first
|
|
11
|
-
const out = sessionStartContext(input.session_id, readConfig(), oldest, new Date());
|
|
5
|
+
const out = handleSessionStart(await readHookInput());
|
|
12
6
|
if (out)
|
|
13
7
|
process.stdout.write(out + "\n");
|
|
14
8
|
});
|
package/dist/hooks/stop.js
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { readSession, writeSession } from "../lib/session.js";
|
|
4
|
-
import { anyTrigger, describeTriggers, detectTriggers, readTranscript } from "../lib/transcript.js";
|
|
2
|
+
import { handleStop } from "../lib/hook-logic.js";
|
|
5
3
|
import { readHookInput, runHook } from "./io.js";
|
|
6
|
-
// Stop fires after every assistant turn.
|
|
4
|
+
// Stop fires after every assistant turn. It never blocks: capture happens in the background or via a later hint.
|
|
7
5
|
runHook(async () => {
|
|
8
|
-
|
|
9
|
-
if (input.stop_hook_active || !input.session_id || !configExists())
|
|
10
|
-
return;
|
|
11
|
-
const session = readSession(input.session_id);
|
|
12
|
-
if (session.nudged || session.entries.length > 0)
|
|
13
|
-
return;
|
|
14
|
-
const triggers = detectTriggers(readTranscript(input.transcript_path));
|
|
15
|
-
if (!anyTrigger(triggers))
|
|
16
|
-
return;
|
|
17
|
-
writeSession(input.session_id, { ...session, nudged: true });
|
|
18
|
-
const cap = readConfig().max_entries_per_session;
|
|
19
|
-
process.stdout.write(JSON.stringify({
|
|
20
|
-
decision: "block",
|
|
21
|
-
reason: `selflore: this session had ${describeTriggers(triggers)} but nothing was logged. ` +
|
|
22
|
-
`Use the selflore skill to log up to ${cap} lore entries (session_id=${input.session_id}), ` +
|
|
23
|
-
`or reply in one line that nothing here is lore-worthy. Do not continue other work.`,
|
|
24
|
-
}) + "\n");
|
|
6
|
+
handleStop(await readHookInput());
|
|
25
7
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { handlePromptSubmit } from "../lib/hook-logic.js";
|
|
3
|
+
import { readHookInput, runHook } from "./io.js";
|
|
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.
|
|
6
|
+
runHook(async () => {
|
|
7
|
+
const out = handlePromptSubmit(await readHookInput());
|
|
8
|
+
if (out)
|
|
9
|
+
process.stdout.write(out + "\n");
|
|
10
|
+
});
|
package/dist/init.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as p from "@clack/prompts";
|
|
2
|
-
import {
|
|
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) {
|
|
@@ -38,37 +39,100 @@ async function ask(existing, reinstall) {
|
|
|
38
39
|
}));
|
|
39
40
|
keep_sharp.push(...stack.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean));
|
|
40
41
|
}
|
|
41
|
-
const
|
|
42
|
-
message: "
|
|
43
|
-
options: [
|
|
44
|
-
|
|
42
|
+
const capture_intensity = bail(await p.select({
|
|
43
|
+
message: "Capture intensity: how much should count as worth capturing?",
|
|
44
|
+
options: [
|
|
45
|
+
{ value: "light", label: "Light", hint: "only the big moments: major bugs and design decisions" },
|
|
46
|
+
{ value: "normal", label: "Normal", hint: "every real unit of work: bugs, tradeoffs, new APIs, unread modules" },
|
|
47
|
+
{ value: "thorough", label: "Thorough", hint: "smaller gotchas and edge cases too" },
|
|
48
|
+
],
|
|
49
|
+
initialValue: existing.capture_intensity,
|
|
50
|
+
}));
|
|
51
|
+
const mode = bail(await p.select({
|
|
52
|
+
message: "What should selflore capture? (you can override this per project later)",
|
|
53
|
+
options: [
|
|
54
|
+
{ value: "details", label: "Details", hint: "language & library specifics, edge cases, gotchas" },
|
|
55
|
+
{ value: "design", label: "Design", hint: "architecture, tradeoffs, failure modes" },
|
|
56
|
+
{ value: "mixed", label: "Mixed", hint: "both; you choose the balance next" },
|
|
57
|
+
],
|
|
58
|
+
initialValue: existing.focus.mode,
|
|
59
|
+
}));
|
|
60
|
+
let balance = existing.focus.balance;
|
|
61
|
+
if (mode === "mixed") {
|
|
62
|
+
balance = bail(await p.select({
|
|
63
|
+
message: "Mixed: what balance?",
|
|
64
|
+
options: [
|
|
65
|
+
{ value: "design", label: "Mostly design", hint: "~70% design, 30% details" },
|
|
66
|
+
{ value: "balanced", label: "Balanced", hint: "50/50" },
|
|
67
|
+
{ value: "details", label: "Mostly details", hint: "~70% details, 30% design" },
|
|
68
|
+
],
|
|
69
|
+
initialValue: existing.focus.balance,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
const capture = bail(await p.select({
|
|
73
|
+
message: "How should capture happen?",
|
|
74
|
+
options: [
|
|
75
|
+
{ value: "background", label: "In the background", hint: "recommended; never interrupts, runs a separate Claude call" },
|
|
76
|
+
{ value: "quiet", label: "Quiet hint", hint: "Claude logs at a natural pause in your session; no extra calls" },
|
|
77
|
+
{ value: "off", label: "Off", hint: "only when you run /selflore log" },
|
|
78
|
+
],
|
|
79
|
+
initialValue: existing.capture,
|
|
80
|
+
}));
|
|
81
|
+
let capture_model = existing.capture_model;
|
|
82
|
+
if (capture === "background") {
|
|
83
|
+
capture_model = bail(await p.select({
|
|
84
|
+
message: "Which model should background capture use?",
|
|
85
|
+
options: [
|
|
86
|
+
{ value: "session", label: "Same as the session", hint: "default" },
|
|
87
|
+
{ value: "sonnet", label: "Sonnet", hint: "sharp questions, moderate cost" },
|
|
88
|
+
{ value: "haiku", label: "Haiku", hint: "cheapest and fastest" },
|
|
89
|
+
],
|
|
90
|
+
initialValue: existing.capture_model,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
const weekly = bail(await p.select({
|
|
94
|
+
message: "Do you also want a weekly test?",
|
|
95
|
+
options: [
|
|
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" },
|
|
99
|
+
],
|
|
100
|
+
initialValue: existing.cadence === "weekly" ? (existing.nudge ? "nudge" : "quiet") : "off",
|
|
45
101
|
}));
|
|
46
|
-
const
|
|
47
|
-
message: "
|
|
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?",
|
|
48
104
|
options: [
|
|
49
|
-
{ value:
|
|
50
|
-
{ value:
|
|
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" },
|
|
51
107
|
],
|
|
52
|
-
initialValue: existing.
|
|
108
|
+
initialValue: existing.offers,
|
|
53
109
|
}));
|
|
54
110
|
return {
|
|
55
111
|
...existing,
|
|
56
112
|
rating,
|
|
57
113
|
keep_sharp,
|
|
58
|
-
|
|
59
|
-
|
|
114
|
+
capture_intensity,
|
|
115
|
+
focus: { mode, balance },
|
|
116
|
+
capture,
|
|
117
|
+
capture_model,
|
|
118
|
+
cadence: weekly === "off" ? "off" : "weekly",
|
|
119
|
+
nudge: weekly === "nudge",
|
|
120
|
+
offers,
|
|
60
121
|
};
|
|
61
122
|
}
|
|
62
123
|
export async function init(opts) {
|
|
124
|
+
const ui = createUi();
|
|
63
125
|
const reinstall = configExists();
|
|
64
126
|
const existing = reinstall ? readConfig() : DEFAULT_CONFIG;
|
|
127
|
+
console.log(ui.banner(opts.version));
|
|
65
128
|
if (opts.yes || !process.stdin.isTTY) {
|
|
66
129
|
writeConfig(existing);
|
|
67
130
|
installFiles();
|
|
68
|
-
|
|
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`);
|
|
69
133
|
return;
|
|
70
134
|
}
|
|
71
|
-
p.intro("
|
|
135
|
+
p.intro(ui.bold(reinstall ? "Update your setup" : "Set up selflore"));
|
|
72
136
|
if (reinstall)
|
|
73
137
|
p.log.info("Existing config found; your previous answers are pre-filled. Data is kept.");
|
|
74
138
|
const config = await ask(existing, reinstall);
|
|
@@ -77,11 +141,13 @@ export async function init(opts) {
|
|
|
77
141
|
p.note([
|
|
78
142
|
`config ${paths.config()}`,
|
|
79
143
|
`skill ${paths.skill()}`,
|
|
80
|
-
`hooks SessionStart + Stop in ${paths.settings()}`,
|
|
144
|
+
`hooks SessionStart + Stop + UserPromptSubmit in ${paths.settings()}`,
|
|
81
145
|
"",
|
|
82
|
-
"Work normally.
|
|
83
|
-
"
|
|
146
|
+
"Work normally. selflore never interrupts; lore is captured as you go.",
|
|
147
|
+
"Per-project focus: run `selflore focus details --project` inside a repo.",
|
|
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.",
|
|
84
150
|
"Restart any open Claude Code sessions to pick up the skill and hooks.",
|
|
85
151
|
].join("\n"), "Installed");
|
|
86
|
-
p.outro("
|
|
152
|
+
p.outro("Your agent wrote it. selflore remembers why.");
|
|
87
153
|
}
|