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
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ // Local notes server, started detached by `selflore notes`: serves the notes page and records
3
+ // answers from the in-page test. Prints its port once, then exits after a while with no requests.
4
+ import { randomBytes } from "node:crypto";
5
+ import fs from "node:fs";
6
+ import { writeJson } from "./lib/fsutil.js";
7
+ import { paths } from "./lib/paths.js";
8
+ import { createNotesServer } from "./lib/server.js";
9
+ const IDLE_MS = Number(process.env.SELFLORE_SERVER_IDLE_MS) || 30 * 60 * 1000;
10
+ const token = randomBytes(16).toString("hex");
11
+ let timer;
12
+ function shutdown() {
13
+ try {
14
+ const state = JSON.parse(fs.readFileSync(paths.serverState(), "utf8"));
15
+ if (state.pid === process.pid)
16
+ fs.rmSync(paths.serverState(), { force: true });
17
+ }
18
+ catch {
19
+ // no state file to clean up
20
+ }
21
+ process.exit(0);
22
+ }
23
+ function touch() {
24
+ if (timer)
25
+ clearTimeout(timer);
26
+ timer = setTimeout(shutdown, IDLE_MS);
27
+ }
28
+ const server = createNotesServer({ token, onRequest: touch });
29
+ server.on("error", () => process.exit(1));
30
+ server.listen(0, "127.0.0.1", () => {
31
+ const address = server.address();
32
+ const port = address && typeof address === "object" ? address.port : 0;
33
+ writeJson(paths.serverState(), { port, pid: process.pid, token });
34
+ touch();
35
+ // The parent reads this line, then stops listening; nothing is written to stdout after it.
36
+ process.stdout.write(`${port}\n`);
37
+ });
38
+ process.on("SIGTERM", shutdown);
39
+ process.on("SIGINT", shutdown);
package/dist/sl.js CHANGED
@@ -1,16 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
  // Data CLI the selflore skill calls for bookkeeping that must be exact.
3
3
  import { readStdin } from "./hooks/io.js";
4
- import { addEntry, finishTest, focusArgs, focusCmd, listCmd, notesCmd, quizInput, recordCmd, statsCmd, suppressCmd, } from "./lib/commands.js";
4
+ import { addEntry, finishTest, heatCmd, recallCmd, showCmd, focusArgs, focusCmd, listCmd, notesCmd, quizInput, recordCmd, statsCmd, suppressCmd, } from "./lib/commands.js";
5
5
  const USAGE = `usage: sl <command>
6
6
  entry add --session <id> read entry markdown from stdin and store it (merges near-duplicates)
7
7
  entry list [--session <id>]
8
- quiz-input JSON of fresh entries + due retests
8
+ recall "<question>" [--project <name> | --all] [--limit n] [--json]
9
+ the notes that best answer a question (this project unless told otherwise)
10
+ show <id> [--session <id>] one note in full, and whether its files changed since it was captured;
11
+ with a session id, records that the note was used to answer the user
12
+ quiz-input [--project <name>] [--topic <name>] [--query "<anything>"]
13
+ JSON of what was missed last time + untested entries; with a scope, that cluster only;
14
+ with --query, the notes that best match those words (at most 5 questions)
9
15
  record --entry <id> --grade got|partial|missed --type <question-type>
10
16
  suppress <id> flag an entry as unfair; never test it again
11
17
  finish-test
12
18
  stats [--project <name>]
13
- notes [--all] [--project <name>] [--text] open the notes page (or print text)
19
+ heat [--project <name>] [--json] where the user gets stuck: the hottest project + topic areas, and why
20
+ notes [--all] [--project <name>] [--text] open the notes page, with an in-page test (or print text)
14
21
  focus [details|design|mixed] [--balance design|balanced|details] [--project] [--reset]`;
15
22
  function flag(args, name) {
16
23
  const i = args.indexOf(`--${name}`);
@@ -30,8 +37,24 @@ async function main(argv) {
30
37
  return { code: 1, out: "missing --session <id> (it is in the session context as selflore session_id=…)" };
31
38
  return addEntry(await readStdin(), { session, cwd: process.cwd() });
32
39
  }
40
+ case "recall": {
41
+ const flags = new Set(["--project", "--limit"]);
42
+ const text = args.filter((a, i) => !a.startsWith("--") && !flags.has(args[i - 1] ?? "")).join(" ");
43
+ const limit = Number(flag(args, "limit"));
44
+ return recallCmd(text, {
45
+ cwd: process.cwd(),
46
+ project: flag(args, "project"),
47
+ all: args.includes("--all"),
48
+ limit: Number.isFinite(limit) && limit > 0 ? limit : undefined,
49
+ json: args.includes("--json"),
50
+ });
51
+ }
52
+ case "show":
53
+ if (!sub)
54
+ break;
55
+ return showCmd(sub, { cwd: process.cwd(), session: flag(args, "session") });
33
56
  case "quiz-input":
34
- return quizInput();
57
+ return quizInput(new Date(), { project: flag(args, "project"), topic: flag(args, "topic") ?? flag(args, "skill"), query: flag(args, "query") });
35
58
  case "record": {
36
59
  const entry = flag(args, "entry");
37
60
  const grade = flag(args, "grade");
@@ -46,6 +69,8 @@ async function main(argv) {
46
69
  return suppressCmd(sub);
47
70
  case "finish-test":
48
71
  return finishTest();
72
+ case "heat":
73
+ return heatCmd({ project: flag(args, "project"), json: args.includes("--json") });
49
74
  case "stats":
50
75
  return statsCmd(flag(args, "project"));
51
76
  case "focus":