notesoup 0.51.9 → 0.52.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +3 -10
  2. package/dist/plugins/claude/src/history.js +9 -12
  3. package/dist/plugins/pi/notes/tools.d.ts +1 -1
  4. package/dist/plugins/pi/notes/tools.js +26 -7
  5. package/dist/plugins/pi/tool-result.d.ts +3 -2
  6. package/dist/plugins/pi/tool-result.js +3 -1
  7. package/dist/src/dream/git.d.ts +2 -3
  8. package/dist/src/dream/git.js +3 -8
  9. package/dist/src/dream/lock.d.ts +10 -27
  10. package/dist/src/dream/lock.js +16 -79
  11. package/dist/src/history/query.js +2 -1
  12. package/dist/src/notes/errors.d.ts +1 -1
  13. package/dist/src/notes/identity.d.ts +2 -0
  14. package/dist/src/notes/identity.js +3 -1
  15. package/dist/src/notes/store.d.ts +2 -0
  16. package/dist/src/notes/store.js +40 -4
  17. package/dist/src/tools/dream.d.ts +113 -0
  18. package/dist/src/tools/dream.js +112 -0
  19. package/dist/src/tools/history.js +1 -1
  20. package/dist/src/tools/notes.d.ts +15 -1
  21. package/dist/src/tools/notes.js +4 -4
  22. package/dist/test/claude-history.test.js +49 -2
  23. package/dist/test/claude-mod.test.js +136 -30
  24. package/dist/test/dependencies.test.js +3 -6
  25. package/dist/test/dream-skill.test.js +2 -3
  26. package/dist/test/dream-tools.test.js +67 -0
  27. package/docs/claude-code-mod.md +2 -2
  28. package/docs/notes-library.md +1 -1
  29. package/docs/skills.md +12 -15
  30. package/package.json +2 -5
  31. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  32. package/plugins/claude/dist/claude/helper.js +36 -29
  33. package/plugins/claude/hooks/register.ts +71 -47
  34. package/plugins/claude/src/history.ts +9 -11
  35. package/plugins/pi/notes/tools.ts +25 -8
  36. package/plugins/pi/tool-result.ts +4 -1
  37. package/src/dream/git.ts +3 -8
  38. package/src/dream/lock.ts +18 -66
  39. package/src/history/query.ts +2 -1
  40. package/src/notes/errors.ts +1 -1
  41. package/src/notes/identity.ts +4 -1
  42. package/src/notes/store.ts +37 -4
  43. package/src/tools/dream.ts +112 -0
  44. package/src/tools/history.ts +1 -1
  45. package/src/tools/notes.ts +4 -4
  46. package/dist/plugins/pi/dream/cli.d.ts +0 -10
  47. package/dist/plugins/pi/dream/cli.js +0 -173
  48. package/dist/plugins/pi/dream/runner.d.ts +0 -27
  49. package/dist/plugins/pi/dream/runner.js +0 -91
  50. package/dist/plugins/pi/dream/settings.d.ts +0 -7
  51. package/dist/plugins/pi/dream/settings.js +0 -17
  52. package/dist/src/dream/doctor.d.ts +0 -2
  53. package/dist/src/dream/doctor.js +0 -161
  54. package/dist/src/dream/gates.d.ts +0 -10
  55. package/dist/src/dream/gates.js +0 -26
  56. package/dist/src/dream/jail.d.ts +0 -11
  57. package/dist/src/dream/jail.js +0 -71
  58. package/dist/src/dream/report.d.ts +0 -7
  59. package/dist/src/dream/report.js +0 -34
  60. package/dist/src/dream/result.d.ts +0 -9
  61. package/dist/src/dream/settings.d.ts +0 -9
  62. package/dist/src/dream/settings.js +0 -16
  63. package/dist/test/doctor.test.d.ts +0 -1
  64. package/dist/test/doctor.test.js +0 -37
  65. package/dist/test/dream.test.d.ts +0 -1
  66. package/dist/test/dream.test.js +0 -150
  67. package/plugins/pi/dream/cli.ts +0 -118
  68. package/plugins/pi/dream/runner.ts +0 -92
  69. package/plugins/pi/dream/settings.ts +0 -17
  70. package/src/dream/doctor.ts +0 -118
  71. package/src/dream/gates.ts +0 -26
  72. package/src/dream/jail.ts +0 -62
  73. package/src/dream/report.ts +0 -32
  74. package/src/dream/result.ts +0 -2
  75. package/src/dream/settings.ts +0 -19
  76. /package/dist/{src/dream/result.js → test/dream-tools.test.d.ts} +0 -0
package/src/dream/jail.ts DELETED
@@ -1,62 +0,0 @@
1
- import { lstat, mkdir, readFile, realpath, unlink } from "node:fs/promises";
2
- import { dirname, isAbsolute, relative, resolve } from "node:path";
3
- import { parseNote } from "../notes/frontmatter.js";
4
-
5
- function isOutside(notesHome: string, target: string): boolean {
6
- const fromHome = relative(notesHome, target);
7
- return fromHome === ".." || fromHome.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) || isAbsolute(fromHome);
8
- }
9
-
10
- export async function jailWritePath(notesHome: string, path: string, options: { createParent?: boolean } = {}): Promise<string> {
11
- let realNotesHome: string;
12
- try {
13
- realNotesHome = await realpath(notesHome);
14
- } catch {
15
- throw new Error(`Can't open the notes home ${notesHome}.`);
16
- }
17
- const target = resolve(realNotesHome, path);
18
- const targetParent = dirname(target);
19
- if (isOutside(realNotesHome, targetParent)) throw new Error(`${path} is outside the notes home ${notesHome}; dreams only write inside it.`);
20
- // write creates parent directories itself. Create only after the lexical check, then
21
- // canonicalize the parent so a symlink cannot lead the underlying tool out of home.
22
- // delete passes createParent:false: the parent must already exist for there to be anything to remove.
23
- if (options.createParent !== false) await mkdir(targetParent, { recursive: true });
24
- let realTargetParent: string;
25
- try {
26
- realTargetParent = await realpath(targetParent);
27
- } catch {
28
- throw new Error(`Can't open the folder of ${path} in the notes home.`);
29
- }
30
- if (isOutside(realNotesHome, realTargetParent)) throw new Error(`${path} is outside the notes home ${notesHome}; dreams only write inside it.`);
31
- let targetStats;
32
- try {
33
- targetStats = await lstat(target);
34
- } catch (error: any) {
35
- if (error.code !== "ENOENT") throw new Error(`Can't check ${path} in the notes home.`);
36
- }
37
- if (targetStats?.isSymbolicLink()) {
38
- let realTarget: string;
39
- try {
40
- realTarget = await realpath(target);
41
- } catch {
42
- throw new Error(`Can't follow the link at ${path} in the notes home.`);
43
- }
44
- if (isOutside(realNotesHome, realTarget)) throw new Error(`${path} is outside the notes home ${notesHome}; dreams only write inside it.`);
45
- }
46
- if (targetStats && targetStats.nlink > 1) throw new Error(`${path} has other hard links, which may reach outside the notes home; leave it alone.`);
47
- return target;
48
- }
49
-
50
- /** Physical deletion refuses live notes even before playbook policy is consulted. */
51
- export async function deleteCrumpledNote(notesHome: string, path: string) {
52
- const target = await jailWritePath(notesHome, path, { createParent: false });
53
- let raw: string;
54
- try {
55
- raw = await readFile(target, "utf8");
56
- } catch (error: any) {
57
- throw new Error(`Can't read ${path} in the notes home: ${error.message}`);
58
- }
59
- if (parseNote(raw).meta.crumpledAt === undefined) throw new Error(`${path} isn't crumpled; only crumpled notes can be deleted.`);
60
- await unlink(target);
61
- return { content: [{ type: "text" as const, text: `deleted ${path}` }], details: undefined };
62
- }
@@ -1,32 +0,0 @@
1
- import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { dirname } from "node:path";
3
- import { gitCommit } from "./git.js";
4
- import type { DreamWrite } from "./result.js";
5
- import { errorMessage } from "../error-message.js";
6
-
7
- function writeList(writes: DreamWrite[]): string {
8
- return writes.length ? writes.map((w) => `- ${w.tool}: ${w.path}`).join("\n") : "- no changes";
9
- }
10
-
11
- /** Best-effort filesystem step; returns the failure message instead of throwing. */
12
- function attempt(action: () => void): string | undefined {
13
- try { action(); return undefined; }
14
- catch (error) { return errorMessage(error); }
15
- }
16
-
17
- /**
18
- * Close one dream: record the report, then run the final audit commit. The audit always
19
- * runs even when the report cannot be written, and a failed audit is appended to the
20
- * report (when it exists) as well as named on stderr, so neither failure hides the other.
21
- */
22
- export function finishDream(home: string, stamp: string, reportPath: string, failed: boolean, body: string, writes: DreamWrite[]): number {
23
- const header = failed ? `# Dream ${stamp} (failed)` : `# Dream ${stamp}`;
24
- let reportError = attempt(() => { mkdirSync(dirname(reportPath), { recursive: true }); writeFileSync(reportPath, `${header}\n\n${body}\n\n${writeList(writes)}\n`); });
25
- const audit = gitCommit(home, `dream ${stamp}${failed ? " (failed)" : ""}`);
26
- if (!audit.ok) {
27
- console.error(`dream: final audit failed: ${audit.error}`);
28
- reportError ??= attempt(() => appendFileSync(reportPath, `\n## Final audit failed\n\n${audit.error}\n`));
29
- }
30
- if (reportError) console.error(`dream: could not write report at ${reportPath}: ${reportError}`);
31
- return failed || !audit.ok || reportError !== undefined ? 1 : 0;
32
- }
@@ -1,2 +0,0 @@
1
- export type DreamWrite = { tool: "write" | "edit" | "delete"; path: string };
2
- export type DreamResult = { report: string; writes: DreamWrite[]; error?: string };
@@ -1,19 +0,0 @@
1
- import { NOTESOUP_SETTINGS_KEY } from "../settings.js";
2
-
3
- /** Nested under the "notesoup" settings key; the dream CLI is the only reader. */
4
- const NOTESOUP_DREAMER_KEY = "dreamer";
5
-
6
- export type DreamerSetting = { pattern?: string; warnings: string[] };
7
-
8
- /**
9
- * `notesoup.dreamer` is a non-empty model pattern. Anything else present is ignored
10
- * with one warning; absent means no configured pattern, so the automatic model applies.
11
- */
12
- export function deriveDreamer(settings: Record<string, unknown>): DreamerSetting {
13
- const raw = settings[NOTESOUP_DREAMER_KEY];
14
- if (raw === undefined) return { warnings: [] };
15
- if (typeof raw !== "string" || raw.trim().length === 0) {
16
- return { warnings: [`notesoup: ${NOTESOUP_SETTINGS_KEY}.${NOTESOUP_DREAMER_KEY} must be a non-empty string; ignoring it.`] };
17
- }
18
- return { pattern: raw.trim(), warnings: [] };
19
- }