notesoup 0.41.0 → 0.43.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 (127) hide show
  1. package/dist/src/boot/render.js +11 -20
  2. package/dist/src/boot/snapshot.js +1 -6
  3. package/dist/src/boot/text.d.ts +12 -0
  4. package/dist/src/boot/text.js +15 -3
  5. package/dist/src/budget/parse.d.ts +14 -0
  6. package/dist/src/budget/parse.js +36 -0
  7. package/dist/src/budget/policy.js +2 -7
  8. package/dist/src/budget/text.d.ts +14 -0
  9. package/dist/src/budget/text.js +14 -0
  10. package/dist/src/claude/helper.js +24 -4
  11. package/dist/src/claude/thresholds.d.ts +39 -0
  12. package/dist/src/claude/thresholds.js +128 -0
  13. package/dist/src/dream/doctor.js +1 -1
  14. package/dist/src/dream/jail.js +10 -10
  15. package/dist/src/dream/lock.js +6 -13
  16. package/dist/src/dream/report.js +5 -15
  17. package/dist/src/history/history.js +5 -3
  18. package/dist/src/history/query.js +14 -26
  19. package/dist/src/notes/address.d.ts +1 -2
  20. package/dist/src/notes/address.js +14 -26
  21. package/dist/src/notes/errors.d.ts +2 -0
  22. package/dist/src/notes/errors.js +5 -0
  23. package/dist/src/notes/frontmatter.js +16 -2
  24. package/dist/src/notes/identity.js +0 -3
  25. package/dist/src/notes/paths.d.ts +11 -1
  26. package/dist/src/notes/paths.js +28 -7
  27. package/dist/src/notes/store.d.ts +1 -0
  28. package/dist/src/notes/store.js +54 -49
  29. package/dist/src/pi/boot.js +1 -5
  30. package/dist/src/pi/budget.d.ts +3 -3
  31. package/dist/src/pi/budget.js +11 -11
  32. package/dist/src/pi/dream/cli.js +43 -11
  33. package/dist/src/pi/estimate.d.ts +1 -5
  34. package/dist/src/pi/estimate.js +4 -4
  35. package/dist/src/pi/history.js +1 -4
  36. package/dist/src/pi/notes/adapter.d.ts +1 -1
  37. package/dist/src/pi/notes/adapter.js +2 -2
  38. package/dist/src/pi/reset/artifacts.d.ts +0 -2
  39. package/dist/src/pi/reset/artifacts.js +4 -4
  40. package/dist/src/pi/reset/committed.js +2 -2
  41. package/dist/src/pi/runtime.js +9 -6
  42. package/dist/src/pi/thresholds.js +5 -9
  43. package/dist/src/pi/tool-result.d.ts +1 -4
  44. package/dist/src/pi/tool-result.js +3 -3
  45. package/dist/src/pi/window.d.ts +5 -0
  46. package/dist/src/pi/window.js +7 -0
  47. package/dist/src/settings.d.ts +10 -0
  48. package/dist/src/settings.js +10 -4
  49. package/dist/src/tools/history.js +15 -18
  50. package/dist/src/tools/notes.d.ts +3 -7
  51. package/dist/src/tools/notes.js +18 -27
  52. package/dist/src/tools/output.d.ts +2 -3
  53. package/dist/src/tools/output.js +3 -9
  54. package/dist/src/tools/result.d.ts +1 -0
  55. package/dist/src/tools/result.js +15 -21
  56. package/dist/src/tools/schema.d.ts +0 -1
  57. package/dist/src/tools/schema.js +3 -4
  58. package/dist/test/agent-loop.test.js +1 -2
  59. package/dist/test/boot.integration.test.js +1 -1
  60. package/dist/test/claude-mod.test.js +425 -23
  61. package/dist/test/claude-validation.test.d.ts +1 -0
  62. package/dist/test/claude-validation.test.js +73 -0
  63. package/dist/test/dream-skill.test.js +2 -4
  64. package/dist/test/dream.test.js +17 -3
  65. package/dist/test/helpers/extension.js +1 -1
  66. package/dist/test/history.integration.test.js +9 -9
  67. package/dist/test/host-neutral.test.js +16 -1
  68. package/dist/test/notes-library.test.js +31 -2
  69. package/dist/test/notes.integration.test.js +11 -11
  70. package/dist/test/notes.test.js +40 -21
  71. package/dist/test/reset-lifecycle.test.js +1 -1
  72. package/docs/claude-code-mod.md +13 -3
  73. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  74. package/mods/notesoup/dist/claude/helper.js +285 -152
  75. package/mods/notesoup/hooks/register.ts +308 -51
  76. package/mods/notesoup/playbook.md +1 -1
  77. package/mods/notesoup/skills/dream/SKILL.md +1 -1
  78. package/mods/notesoup/skills/memory/SKILL.md +61 -0
  79. package/mods/pi-context/dist/claude/helper.js +9324 -0
  80. package/package.json +5 -3
  81. package/playbook.md +1 -1
  82. package/skills/dream/SKILL.md +1 -1
  83. package/skills/memory/SKILL.md +1 -1
  84. package/src/boot/render.ts +11 -21
  85. package/src/boot/snapshot.ts +2 -7
  86. package/src/boot/text.ts +21 -3
  87. package/src/budget/parse.ts +39 -0
  88. package/src/budget/policy.ts +2 -6
  89. package/src/budget/text.ts +20 -0
  90. package/src/claude/helper.ts +22 -5
  91. package/src/claude/thresholds.ts +153 -0
  92. package/src/dream/doctor.ts +1 -1
  93. package/src/dream/jail.ts +10 -10
  94. package/src/dream/lock.ts +3 -9
  95. package/src/dream/report.ts +5 -10
  96. package/src/history/history.ts +5 -3
  97. package/src/history/query.ts +14 -27
  98. package/src/notes/address.ts +13 -25
  99. package/src/notes/errors.ts +6 -0
  100. package/src/notes/frontmatter.ts +12 -2
  101. package/src/notes/identity.ts +0 -2
  102. package/src/notes/paths.ts +23 -5
  103. package/src/notes/store.ts +50 -48
  104. package/src/pi/boot.ts +1 -13
  105. package/src/pi/budget.ts +10 -11
  106. package/src/pi/dream/cli.ts +35 -10
  107. package/src/pi/estimate.ts +4 -4
  108. package/src/pi/history.ts +1 -5
  109. package/src/pi/notes/adapter.ts +2 -2
  110. package/src/pi/reset/artifacts.ts +4 -4
  111. package/src/pi/reset/committed.ts +2 -2
  112. package/src/pi/runtime.ts +8 -7
  113. package/src/pi/thresholds.ts +5 -11
  114. package/src/pi/tool-result.ts +3 -3
  115. package/src/pi/window.ts +8 -0
  116. package/src/settings.ts +22 -5
  117. package/src/tools/history.ts +15 -19
  118. package/src/tools/notes.ts +21 -32
  119. package/src/tools/output.ts +3 -12
  120. package/src/tools/result.ts +14 -19
  121. package/src/tools/schema.ts +3 -4
  122. package/dist/src/dream/playbook.d.ts +0 -1
  123. package/dist/src/dream/playbook.js +0 -2
  124. package/dist/src/pi/reset/text.d.ts +0 -5
  125. package/dist/src/pi/reset/text.js +0 -6
  126. package/src/dream/playbook.ts +0 -3
  127. package/src/pi/reset/text.ts +0 -10
@@ -0,0 +1,73 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ const plugin = join(process.cwd(), "mods/notesoup");
8
+ /** Only an absent executable may skip the real loader gate; other failures fail the suite. */
9
+ function validate(t, dir) {
10
+ const result = spawnSync("claude", ["plugin", "validate", dir, "--strict", "--json"], {
11
+ encoding: "utf8", timeout: 30_000,
12
+ });
13
+ if (result.error?.code === "ENOENT") {
14
+ t.skip("Claude mod validation skipped: claude is not installed (not found on PATH)");
15
+ return undefined;
16
+ }
17
+ assert.ifError(result.error);
18
+ assert.equal(result.signal, null, result.stderr);
19
+ const report = JSON.parse(result.stdout);
20
+ return { ...result, report };
21
+ }
22
+ test("Claude mod passes the installed engine's strict loader validation", (t) => {
23
+ const result = validate(t, plugin);
24
+ if (!result)
25
+ return;
26
+ assert.equal(result.status, 0, result.stdout + result.stderr);
27
+ assert.equal(result.report.success, true, result.stdout);
28
+ t.diagnostic("claude plugin validate mods/notesoup --strict: passed");
29
+ });
30
+ test("Claude mod typechecks against the vendored engine contract without Node globals", () => {
31
+ const result = spawnSync(process.execPath, ["node_modules/typescript/bin/tsc", "-p", "mods/notesoup/tsconfig.json"], {
32
+ encoding: "utf8", timeout: 30_000,
33
+ });
34
+ assert.ifError(result.error);
35
+ assert.equal(result.status, 0, result.stdout + result.stderr);
36
+ });
37
+ // Test each original ScanRefusal independently against the real scanner. A regression must
38
+ // fail the gate rather than silently transpile in our fake engine's lifecycle tests.
39
+ for (const mutation of [
40
+ {
41
+ name: "variable environment names",
42
+ from: 'return await $.env.get("CLAUDE_AUTOCOMPACT_PCT_OVERRIDE")',
43
+ to: 'const name = "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"; return await $.env.get(name)',
44
+ },
45
+ {
46
+ name: "bound session usage ops",
47
+ from: "const context = (await $.session.usage()).context",
48
+ to: "const read = $.session.usage; const context = (await read()).context",
49
+ },
50
+ {
51
+ name: "bound settings nouns",
52
+ from: "return await $.settings.read()",
53
+ to: "const settings = $.settings; return await settings.read()",
54
+ },
55
+ ]) {
56
+ test(`Claude loader gate rejects ${mutation.name}`, (t) => {
57
+ const fixture = mkdtempSync(join(tmpdir(), "claude-scanner-gate-"));
58
+ t.after(() => rmSync(fixture, { recursive: true, force: true }));
59
+ const dir = join(fixture, "notesoup");
60
+ cpSync(plugin, dir, { recursive: true });
61
+ const source = join(dir, "hooks/register.ts");
62
+ const text = readFileSync(source, "utf8");
63
+ assert.equal(text.split(mutation.from).length, 2, "one scanner-safe call site is mutated");
64
+ writeFileSync(source, text.replace(mutation.from, mutation.to));
65
+ const result = validate(t, dir);
66
+ if (!result)
67
+ return;
68
+ assert.notEqual(result.status, 0, "the strict gate must fail a loader refusal");
69
+ assert.equal(result.report.success, false);
70
+ // This build emits a null error code for ScanRefusal, so use the module error path.
71
+ assert.ok(result.report.contents.some((entry) => entry.errors.some((error) => error.path === "modules../register.ts")), result.stdout);
72
+ });
73
+ }
@@ -6,7 +6,6 @@ import { tmpdir } from "node:os";
6
6
  import { dirname, join, resolve } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { loadSkillsFromDir } from "@earendil-works/pi-coding-agent";
9
- import { loadPlaybook } from "../src/dream/playbook.js";
10
9
  function packageRoot() {
11
10
  let dir = dirname(fileURLToPath(import.meta.url));
12
11
  while (!existsSync(join(dir, "package.json"))) {
@@ -38,7 +37,7 @@ test("dream skill is publicly discoverable and resolves the CLI's shared playboo
38
37
  const packagePlaybook = resolve(root, "playbook.md");
39
38
  assert.equal(skillPlaybook, packagePlaybook);
40
39
  const playbook = readFileSync(packagePlaybook, "utf8");
41
- assert.equal(loadPlaybook(skillPlaybook), playbook);
40
+ assert.equal(readFileSync(skillPlaybook, "utf8"), playbook);
42
41
  });
43
42
  test("npm tarball keeps the skill's relative playbook path portable after extraction", () => {
44
43
  const root = packageRoot();
@@ -63,8 +62,7 @@ test("npm tarball keeps the skill's relative playbook path portable after extrac
63
62
  const installedSkill = discoverSkill(join(installedRoot, "skills"), "dream");
64
63
  const referencedPlaybook = resolve(installedSkill.baseDir, "../../playbook.md");
65
64
  assert.equal(referencedPlaybook, resolve(installedRoot, "playbook.md"));
66
- assert.equal(loadPlaybook(referencedPlaybook), readFileSync(referencedPlaybook, "utf8"));
67
- assert.equal(loadPlaybook(referencedPlaybook), readFileSync(join(root, "playbook.md"), "utf8"));
65
+ assert.equal(readFileSync(referencedPlaybook, "utf8"), readFileSync(join(root, "playbook.md"), "utf8"));
68
66
  }
69
67
  finally {
70
68
  rmSync(fixture, { recursive: true, force: true });
@@ -84,11 +84,11 @@ test("dreamer delete is jailed to the notes home and refuses live notes", async
84
84
  const ctx = { cwd: home };
85
85
  await del.execute("d1", { path: "global/dead.md" }, undefined, undefined, ctx);
86
86
  assert.equal(existsSync(join(home, "global/dead.md")), false);
87
- await assert.rejects(() => del.execute("d2", { path: "global/live.md" }, undefined, undefined, ctx), /not a crumpled note/);
87
+ await assert.rejects(() => del.execute("d2", { path: "global/live.md" }, undefined, undefined, ctx), /global\/live\.md/);
88
88
  assert.equal(existsSync(join(home, "global/live.md")), true);
89
- await assert.rejects(() => del.execute("d3", { path: join("..", basename(outside), "keep.md") }, undefined, undefined, ctx), /write jail/);
89
+ await assert.rejects(() => del.execute("d3", { path: join("..", basename(outside), "keep.md") }, undefined, undefined, ctx), /outside the notes home/);
90
90
  symlinkSync(join(outside, "keep.md"), join(home, "link.md"));
91
- await assert.rejects(() => del.execute("d4", { path: "link.md" }, undefined, undefined, ctx), /write jail/);
91
+ await assert.rejects(() => del.execute("d4", { path: "link.md" }, undefined, undefined, ctx), /outside the notes home/);
92
92
  assert.equal(existsSync(join(outside, "keep.md")), true);
93
93
  });
94
94
  test("CLI lists dreamer deletions in the report", async () => {
@@ -134,3 +134,17 @@ test("CLI commits partial writes when report writing fails", async () => {
134
134
  assert.match(execFileSync("git", ["log", "--format=%s"], { cwd: home, encoding: "utf8" }).trim(), /\(failed\)/);
135
135
  assert.equal(execFileSync("git", ["show", "HEAD:global/partial.md"], { cwd: home, encoding: "utf8" }), "half");
136
136
  });
137
+ test("CLI refuses a malformed flag value before creating anything", async () => {
138
+ const numberHome = join(fixture(), "notes");
139
+ const badNumber = await captureErrors(() => main(["--notes-home", numberHome, "--min-hours", "abc"], { dreamerSettings: () => ({ warnings: [] }) }));
140
+ assert.equal(badNumber.code, 1);
141
+ assert.ok(badNumber.errors.some((line) => /--min-hours needs a positive whole number/.test(line)), badNumber.errors.join("\n"));
142
+ assert.equal(existsSync(numberHome), false, "a bad number is refused before the home is created");
143
+ for (const value of ["", "--force"]) {
144
+ const home = join(fixture(), "notes");
145
+ const badHome = await captureErrors(() => main(["--notes-home", value], { dreamerSettings: () => ({ warnings: [] }) }));
146
+ assert.equal(badHome.code, 1, `--notes-home ${JSON.stringify(value)} is refused`);
147
+ assert.ok(badHome.errors.some((line) => /--notes-home needs a directory path/.test(line)), badHome.errors.join("\n"));
148
+ assert.equal(existsSync(home), false, "a flag-looking path never becomes the home");
149
+ }
150
+ });
@@ -136,7 +136,7 @@ export function makeExtension(sessionManager, settingsManager) {
136
136
  export async function explicitBoot(ctx, currentWindowId, previousWindowId) {
137
137
  return renderBootBlock({
138
138
  tools: PI_TOOL_NAMES,
139
- agentName: agentSlug(ctx),
139
+ agentName: agentSlug(),
140
140
  modelName: modelSlug(ctx),
141
141
  firstWindowId: rootWindowId(ctx.sessionManager.getSessionId()),
142
142
  currentWindowId,
@@ -1,7 +1,8 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { Check } from "typebox/value";
4
- import { earliestMatchOffsetChars, TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
4
+ import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
5
+ import { earliestMatchOffsetChars } from "../src/text-match.js";
5
6
  import { historyList, historyRead, historyWindows } from "../src/tools/history.js";
6
7
  import { historyDocument, projectHistory } from "../src/history/history.js";
7
8
  import { selectPage } from "../src/history/query.js";
@@ -107,11 +108,10 @@ test("seq is stable across branch changes, abandoned entries stay unreadable, an
107
108
  assert.equal(branchId !== abandonedId, true);
108
109
  const offBranch = resultError(await call(captured, "history_read", { seq: 2 }, ctx));
109
110
  assert.equal(offBranch.code, "not_on_branch");
110
- assert.match(offBranch.message, /another branch/);
111
111
  assert.equal(JSON.stringify(offBranch).includes("abandoned"), false, "the refusal does not leak the abandoned entry's text");
112
112
  const unknown = resultError(await call(captured, "history_read", { seq: 4 }, ctx));
113
113
  assert.equal(unknown.code, "unknown_seq");
114
- assert.match(unknown.message, /run 1\.\.3/);
114
+ assert.match(unknown.message, /\b4\b.*\b3\b/);
115
115
  });
116
116
  test("a result address consumed by a pairing names its call instead of serving a second read", async () => {
117
117
  const session = manager();
@@ -123,7 +123,7 @@ test("a result address consumed by a pairing names its call instead of serving a
123
123
  assert.deepEqual(seqs(await call(captured, "history_list", { roles: ["tool"] }, ctx)), [2], "the pairing is one event at the call's address");
124
124
  const consumed = resultError(await call(captured, "history_read", { seq: 3 }, ctx));
125
125
  assert.equal(consumed.code, "not_an_event");
126
- assert.match(consumed.message, /already shown inside the call at seq 2/);
126
+ assert.match(consumed.message, /seq 2\b/);
127
127
  const callSeq = resultRead(await call(captured, "history_read", { seq: 2 }, ctx));
128
128
  assert.equal(callSeq.seq, 2);
129
129
  assert.equal(callSeq.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
@@ -445,7 +445,7 @@ test("list renders paging and fold recipes, read renders a neighborhood call, an
445
445
  const noPrevious = resultError(await call(soloCaptured, "history_list", { window_id: "@previous" }, context(solo)));
446
446
  assert.equal(noPrevious.code, "unknown_window_id");
447
447
  assert.match(noPrevious.message, /@previous/);
448
- assert.match(noPrevious.message, new RegExp(`; known: ${soloWindows.windows[0].window_id}$`), "the refusal names the window the session does have");
448
+ assert.match(noPrevious.message, new RegExp(`${soloWindows.windows[0].window_id}\\.$`), "the refusal names the window the session does have");
449
449
  });
450
450
  test("compaction summary becomes context and is folded in the default list", async () => {
451
451
  const session = manager();
@@ -482,7 +482,7 @@ test("a query covers every role, carries match offsets and refuses an empty lite
482
482
  assert.deepEqual(next.items.map((item) => item.seq), [3]);
483
483
  const absent = await call(captured, "history_list", { query: "absent" }, ctx);
484
484
  assert.deepEqual(page(absent).items, []);
485
- assert.equal(rendered(absent), "no events match this selection", "an empty page says so instead of rendering nothing");
485
+ assert.notEqual(rendered(absent).trim(), "", "an empty page says so instead of rendering nothing");
486
486
  assert.deepEqual(resultError(await call(captured, "history_list", { query: "" }, ctx)).code, "invalid_query");
487
487
  });
488
488
  test("page_older and page_newer round-trip a session with no duplicates and no gaps", async () => {
@@ -574,7 +574,7 @@ test("history_read paginates one document with an accurate limit and a bounded b
574
574
  assert.equal(tail.next_offset_chars, null, "the true end has no continuation");
575
575
  const past = resultError(await call(captured, "history_read", { seq, offset_chars: content.length + 1 }, ctx));
576
576
  assert.equal(past.code, "invalid_offset");
577
- assert.match(past.message, new RegExp(`${content.length} chars`), "the refusal names the real length");
577
+ assert.match(past.message, new RegExp(`\\b${content.length}\\b`), "the refusal names the real length");
578
578
  });
579
579
  test("history windows expose stable ranges and session identity", async () => {
580
580
  const session = manager();
@@ -617,11 +617,11 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
617
617
  const offBranch = await historyRead.execute({ seq: 12 }, projection);
618
618
  assert.equal(offBranch.ok, false);
619
619
  if (!offBranch.ok)
620
- assert.match(offBranch.error.message, /another branch/);
620
+ assert.equal(offBranch.error.code, "not_on_branch");
621
621
  const unknown = await historyRead.execute({ seq: 13 }, projection);
622
622
  assert.equal(unknown.ok, false);
623
623
  if (!unknown.ok)
624
- assert.match(unknown.error.message, /unknown seq/);
624
+ assert.match(unknown.error.message, /\b13\b.*\b12\b/);
625
625
  const listed = await historyList.execute({}, projection);
626
626
  assert.equal(listed.ok, true);
627
627
  if (listed.ok)
@@ -254,7 +254,7 @@ test("an unknown window_id names at most five known windows in its message", asy
254
254
  assert.equal(outcome.ok, false);
255
255
  if (!outcome.ok) {
256
256
  assert.equal(outcome.error.code, "unknown_window_id");
257
- assert.match(outcome.error.message, /unknown window_id "pcw:absent"; known: pcw:w0, pcw:w1, pcw:w2, pcw:w3, pcw:w4/, "the message names the known windows itself");
257
+ assert.match(outcome.error.message, /"pcw:absent".*pcw:w0, pcw:w1, pcw:w2, pcw:w3, pcw:w4\.$/, "the message names the known windows itself");
258
258
  assert.equal(outcome.error.message.includes("pcw:w5"), false, "at most five known windows are named");
259
259
  }
260
260
  });
@@ -272,3 +272,18 @@ test("one role schema declares the four public roles for the page item, the read
272
272
  assert.equal(Check(HistoryRoleSchema, "developer"), false, "a role outside the four is refused");
273
273
  assert.equal(Check(historyRead.outputSchema, read("developer")), false, "history_read refuses a role outside the four");
274
274
  });
275
+ test("history paging bounds are the schema's, and a zero limit still pages one event", async () => {
276
+ const items = Array.from({ length: 3 }, (_, index) => ({ seq: index + 1, windowId: "root", role: "user", text: `message-${index}` }));
277
+ const projection = projectHistory([{ windowId: "root", items }], 3, new Set([1, 2, 3]));
278
+ assert.equal(Check(historyList.parameters, { limit: 0 }), false, "the schema refuses a zero limit");
279
+ assert.equal(Check(historyList.parameters, { limit: 501 }), false, "the schema refuses a limit past its maximum");
280
+ assert.equal(Check(historyList.parameters, { max_chars_per_item: 0 }), false, "the schema refuses a zero preview budget");
281
+ const zero = data(await historyList.execute({ limit: 0, from: "oldest", roles: ["user"] }, projection));
282
+ assert.equal(zero.items.length, 1, "an unvalidated zero limit still returns one row instead of none");
283
+ const negative = data(await historyList.execute({ max_chars_per_item: -5, roles: ["user"] }, projection));
284
+ const row = negative.items[0];
285
+ if ("folded" in row)
286
+ assert.fail("a role filter returns event rows only");
287
+ assert.equal(row.content, "", "a negative budget delivers nothing instead of cutting the tail");
288
+ assert.equal(row.truncated, true, "the empty preview says it was truncated");
289
+ });
@@ -1,5 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import test from "node:test";
@@ -206,9 +206,38 @@ test("a massively ambiguous edit still reports every match line to a library cal
206
206
  assert.equal(error.lineNumbers?.length, 2000, "the domain keeps every match line rather than a sample");
207
207
  assert.deepEqual(error.lineNumbers?.slice(0, 3), [1, 2, 3]);
208
208
  assert.equal(error.lineNumbers?.[1999], 2000);
209
- assert.match(error.message, /occurs 2000 times \(lines 1, 2, 3, 4, 5, 6, 7, 8, and 1992 more\)/, "the message names the exact total and a bounded sample");
209
+ assert.match(error.message, /2000 times \(lines 1, 2, 3, 4, 5, 6, 7, 8, and 1992 more\)/, "the message names the exact total and a bounded sample");
210
210
  assert.ok(Buffer.byteLength(error.message, "utf8") < 300, "the message stays small however many lines matched");
211
211
  return true;
212
212
  });
213
213
  assert.equal((await notes.read("many"))?.body.startsWith("beta\nbeta"), true, "the refused edit left the body alone");
214
214
  });
215
+ test("one unreadable note is named without hiding its readable siblings", async (t) => {
216
+ if (process.getuid?.() === 0 || process.platform === "win32")
217
+ return t.skip("chmod 000 is not a read refusal for this user");
218
+ const { home, notes } = fixture(t);
219
+ await notes.write("@project/bad.md", "bad body");
220
+ await notes.write("@project/good.md", "good body");
221
+ chmodSync(join(home, "project", "project-12345678", "bad.md"), 0o000);
222
+ const result = await notes.listWithStatus({ scope: "project" });
223
+ assert.deepEqual(result.rows.map((row) => row.address), ["@project/good.md"], "the readable sibling still lists");
224
+ assert.deepEqual(result.status.homesUnavailable, ["@project/bad.md"], "the unreadable note is named on its own");
225
+ await assert.rejects(() => notes.list({ scope: "project" }), (error) => error.code === "EACCES", "a caller that asked for no status still sees the failure");
226
+ });
227
+ test("a hand-written quoted numeric extra survives a rewrite as a string", async (t) => {
228
+ const { home, notes } = fixture(t);
229
+ await notes.write("typed", "body");
230
+ const path = join(home, "pi/session/session-a/typed.md");
231
+ writeFileSync(path, readFileSync(path, "utf8").replace("\n---\n\n", "\ncount: \"1\"\n---\n\n"));
232
+ assert.equal((await notes.read("typed"))?.meta.count, "1", "a quoted scalar is read as text");
233
+ const raw = readFileSync(path, "utf8");
234
+ assert.match(raw, /^count: "1"$/m, "a bare 1 would read back as a number");
235
+ assert.match(raw, /^origin: self$/m, "an ordinary string still stays bare");
236
+ });
237
+ test("writing keeps an existing note's origin unless the caller names one", async (t) => {
238
+ const { notes } = fixture(t);
239
+ await notes.write("owned", "first", { origin: "user" });
240
+ assert.equal((await notes.write("owned", "second")).meta.origin, "user", "a rewrite does not re-attribute the note");
241
+ assert.equal((await notes.write("owned", "third", { origin: "external" })).meta.origin, "external", "an explicit origin still wins");
242
+ assert.equal((await notes.write("fresh", "new")).meta.origin, "self", "a new note still defaults to self");
243
+ });
@@ -136,7 +136,7 @@ test("crumple lifecycle: metadata-only edits close and smooth a note without tou
136
136
  assert.equal((await listNotes(ctx, { scope: "session" }))[0]?.meta.crumpledAt, undefined, "writing always produces an uncrumpled note");
137
137
  // metadata-only on a missing path is the typed not-found arm
138
138
  const missing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
139
- assert.equal(missing.message, "note not found");
139
+ assert.equal(missing.code, "not_found");
140
140
  });
141
141
  test("the filesystem notes loader treats an absent home as empty but surfaces a real directory read failure", async () => {
142
142
  const sm = manager();
@@ -272,18 +272,18 @@ test("the boot block gives awake agents the notes-home file layout", async () =>
272
272
  assert.equal(rendered.includes(process.env.PI_NOTES_HOME ?? ""), false, "the absolute notes home is never exposed");
273
273
  assert.match(rendered, /`<path>`, no @[\s\S]*`@project\/<path>`[\s\S]*`@human\/<path>`/);
274
274
  });
275
- test("the boot protocol carries the approved copy and cuts an over-cap MAP with the approved notice", async () => {
275
+ test("the boot binds its tools and bounds an over-cap MAP with a lookup pointer", async () => {
276
276
  const session = manager();
277
277
  const captured = makeExtension(session);
278
278
  const ctx = context(session);
279
279
  await call(captured, "notes_write", { address: "MAP.md", content: "M".repeat(MAP_BOOT_MAX_CHARS + 10) }, ctx);
280
280
  const rendered = await explicitBoot(ctx, "pcw:test:root", undefined);
281
- assert.ok(rendered.includes("History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice."), "the History paragraph is the approved copy");
282
- assert.ok(rendered.includes("- `@project/<path>` — this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Commit hashes, test counts, dates, the story of how you got here: git and history already have them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say."), "the @project bullet is the approved copy");
283
- assert.ok(rendered.includes("- `<path>`, no @") && rendered.includes("- `@human/<path>`") && rendered.includes("- `@self/<path>`") && rendered.includes("- `@model/<path>`"), "every address bullet is backticked");
284
- assert.ok(rendered.includes("Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`."), "the fake-address paragraph is the approved copy");
285
- assert.ok(rendered.includes(`[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`MAP.md\`]`), "an over-cap MAP is cut with the approved notice");
286
- assert.equal(rendered.includes("MAP cut at"), false, "the retired cut notice is gone");
281
+ for (const tool of ["notes_*", "history_*", "get_context_remaining", "clear_memory"]) {
282
+ assert.ok(rendered.includes(`\`${tool}\``), `${tool} is bound in the protocol`);
283
+ }
284
+ assert.ok(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS)), "the existing MAP cap keeps a bounded prefix");
285
+ assert.equal(rendered.includes("M".repeat(MAP_BOOT_MAX_CHARS + 1)), false, "the over-cap suffix is not inlined");
286
+ assert.ok(rendered.includes("`MAP.md`"), "the full MAP remains available by address");
287
287
  for (const retired of ["history_windows", "history_list", "history_read"]) {
288
288
  assert.equal(rendered.includes(retired), false, `${retired} no longer appears in the boot block`);
289
289
  }
@@ -339,7 +339,7 @@ test("an over-budget note is delivered as a bounded prefix and resumed by next_o
339
339
  assert.equal(JSON.stringify(missingResult).includes(root), false, "failure receipts never expose the absolute home");
340
340
  const missing = resultError(missingResult);
341
341
  assert.deepEqual(Object.keys(missing).sort(), ["code", "message"], "the refusal carries a precise code and message");
342
- assert.equal(missing.message, "note not found");
342
+ assert.equal(missing.code, "not_found");
343
343
  assert.equal(missing.code, "not_found");
344
344
  });
345
345
  test("an over-budget note search match is a marked prefix with an honest line address", async () => {
@@ -506,8 +506,8 @@ test("a body that repeats one anchor thousands of times refuses with bounded, co
506
506
  assertWithinBudget(raw, "refusal with thousands of match lines");
507
507
  const refusal = resultError(raw);
508
508
  assert.equal(refusal.code, "ambiguous_edit");
509
- assert.match(refusal.message, /edit 0:/, "the message names the failing edit index");
510
- assert.match(refusal.message, /occurs 5000 times \(lines 1, 2, 3, 4, 5, 6, 7, 8, and 4992 more\)/, "the message names a bounded sample and the exact total");
509
+ assert.match(refusal.message, /edits\[0\]/, "the message names the failing edit index");
510
+ assert.match(refusal.message, /5000 times \(lines 1, 2, 3, 4, 5, 6, 7, 8, and 4992 more\)/, "the message names a bounded sample and the exact total");
511
511
  assert.equal(resultRead(await call(captured, "notes_read", { address: "many.md", max_chars: 15 }, ctx)).content, "beta\n".repeat(3), "the refused edit changed nothing");
512
512
  const replaced = resultData(await call(captured, "notes_update", { address: "many.md", edits: [{ oldText: "beta", newText: "B" }], replace_all: true }, ctx));
513
513
  assertWithinBudget(await call(captured, "notes_read", { address: "many.md" }, ctx), "read after replace_all");
@@ -8,12 +8,14 @@
8
8
  */
9
9
  import assert from "node:assert/strict";
10
10
  import { execFileSync } from "node:child_process";
11
- import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
12
- import { join } from "node:path";
11
+ import { createHash } from "node:crypto";
12
+ import { existsSync, mkdirSync, readFileSync, realpathSync, symlinkSync, writeFileSync } from "node:fs";
13
+ import { basename, join } from "node:path";
13
14
  import test from "node:test";
14
15
  import { Check } from "typebox/value";
15
16
  import { parseNote } from "../src/notes/frontmatter.js";
16
17
  import { projectKey } from "../src/notes/paths.js";
18
+ import { globToRegExp } from "../src/notes/address.js";
17
19
  import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
18
20
  import { call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead } from "./helpers/extension.js";
19
21
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
@@ -164,9 +166,8 @@ test("session-note project ownership is per note, persistent across sessions, an
164
166
  });
165
167
  test("linked git worktrees share the main checkout's project key", () => {
166
168
  freshRoot();
167
- // realpath keeps the fixture's gitdir pointer and the asserted paths on one spelling
168
- // (macOS temp roots live under the /var -> /private/var symlink).
169
- const root = realpathSync(testEnvironment.cwd);
169
+ // The fixture root is used as spelled: a symlinked temp root must still hash to one key.
170
+ const root = testEnvironment.cwd;
170
171
  const main = join(root, "repo");
171
172
  mkdirSync(main, { recursive: true });
172
173
  const git = (args) => {
@@ -235,12 +236,12 @@ test("edit is body-scoped with named failures and a replace_all escape hatch", a
235
236
  const ctx = context(session);
236
237
  await call(captured, "notes_write", { address: "edit.md", content: "alpha\nbeta\nbeta\ngamma" }, ctx);
237
238
  const ambiguous = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "beta", newText: "B" }] }, ctx));
238
- assert.match(ambiguous.message, /occurs 2 times/);
239
+ assert.match(ambiguous.message, /2 times/);
239
240
  assert.equal(ambiguous.code, "ambiguous_edit");
240
- assert.match(ambiguous.message, /edit 0: oldText occurs 2 times \(lines 2, 3\)/, "the message names the failing edit index and every match line");
241
+ assert.match(ambiguous.message, /edits\[0\]\.oldText appears 2 times \(lines 2, 3\)/, "the message names the failing edit index and every match line");
241
242
  const missing = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "absent", newText: "x" }] }, ctx));
242
243
  assert.equal(missing.code, "no_match");
243
- assert.match(missing.message, /^edit 0:/, "a zero-match anchor names the failing edit index");
244
+ assert.match(missing.message, /edits\[0\]/, "a zero-match anchor names the failing edit index");
244
245
  const all = resultData(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "beta", newText: "B" }], replace_all: true }, ctx));
245
246
  assert.equal(all.address, "edit.md");
246
247
  assertReceiptIdentity(all, "edit.md", "session", ctx);
@@ -248,7 +249,7 @@ test("edit is body-scoped with named failures and a replace_all escape hatch", a
248
249
  assert.equal(resultRead(await call(captured, "notes_read", { address: "edit.md" }, ctx)).content, "alpha\nB\nB\ngamma", "replace_all replaces every occurrence");
249
250
  // An anchor that occurs only in frontmatter is not matched: edits are body-only.
250
251
  const frontmatterOnly = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "origin", newText: "x" }] }, ctx));
251
- assert.match(frontmatterOnly.message, /^edit 0:/, "a frontmatter-only anchor is not a body match");
252
+ assert.match(frontmatterOnly.message, /edits\[0\]/, "a frontmatter-only anchor is not a body match");
252
253
  });
253
254
  test("nothing-to-do, not-found, atomic batches, and replace_all zero-match are named", async () => {
254
255
  freshRoot();
@@ -256,26 +257,26 @@ test("nothing-to-do, not-found, atomic batches, and replace_all zero-match are n
256
257
  const captured = makeExtension(session);
257
258
  const ctx = context(session);
258
259
  const nameOnly = resultError(await call(captured, "notes_update", { address: "edit.md" }, ctx));
259
- assert.match(nameOnly.message, /nothing to do/, "neither edits nor setters is a named error");
260
+ assert.equal(nameOnly.code, "nothing_to_do", "neither edits nor setters is a named error");
260
261
  await call(captured, "notes_write", { address: "edit.md", content: "alpha\nbeta" }, ctx);
261
262
  const empty = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [] }, ctx));
262
- assert.match(empty.message, /nothing to do/, "an empty edits list with no setters is also nothing to do");
263
+ assert.equal(empty.code, "nothing_to_do", "an empty edits list with no setters is also nothing to do");
263
264
  const editMissing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
264
- assert.equal(editMissing.message, "note not found");
265
+ assert.equal(editMissing.code, "not_found");
265
266
  const readMissing = resultError(await call(captured, "notes_read", { address: "missing.md" }, ctx));
266
- assert.equal(readMissing.message, "note not found");
267
+ assert.equal(readMissing.code, "not_found");
267
268
  assert.equal(readMissing.code, "not_found");
268
269
  assert.deepEqual(Object.keys(readMissing).sort(), ["code", "message"], "a plain refusal carries only a code and message");
269
270
  const file = physicalPath("session", "edit.md", ctx);
270
271
  const before = readFileSync(file, "utf8");
271
272
  const failed = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "absent", newText: "x" }] }, ctx));
272
- assert.match(failed.message, /^edit 1:/, "the failing edit is named");
273
+ assert.match(failed.message, /edits\[1\]/, "the failing edit is named");
273
274
  assert.equal(readFileSync(file, "utf8"), before, "a failing batch leaves the file byte-identical, frontmatter included");
274
275
  const applied = resultData(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "beta", newText: "B" }] }, ctx));
275
276
  assert.equal(applied.change_kind, "body");
276
277
  assert.equal(resultRead(await call(captured, "notes_read", { address: "edit.md" }, ctx)).content, "A\nB");
277
278
  const zero = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "zzz", newText: "y" }], replace_all: true }, ctx));
278
- assert.match(zero.message, /^edit 0:/, "replace_all with zero matches is the same zero-match error, not a silent no-op");
279
+ assert.match(zero.message, /edits\[0\]/, "replace_all with zero matches is the same zero-match error, not a silent no-op");
279
280
  });
280
281
  test("notes_update rename_to moves a note and refuses combinations and live targets", async () => {
281
282
  freshRoot();
@@ -287,14 +288,14 @@ test("notes_update rename_to moves a note and refuses combinations and live targ
287
288
  assert.match(combined.message, /rename_to is used alone/, "rename_to rejects being combined with edits");
288
289
  await call(captured, "notes_write", { address: "occupied.md", content: "live target" }, ctx);
289
290
  const conflict = resultError(await call(captured, "notes_update", { address: "move-me.md", rename_to: "occupied.md" }, ctx));
290
- assert.match(conflict.message, /live note/, "a live target refuses the move");
291
+ assert.match(conflict.message, /occupied\.md/, "a live target refuses the move");
291
292
  const renamed = resultData(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md" }, ctx));
292
293
  assertReceiptIdentity(renamed, "moved.md", "session", ctx);
293
294
  assert.equal(renamed.rename_from, "move-me.md");
294
295
  assert.equal(renamed.change_kind, "moved");
295
296
  assert.equal(renamed.address, "moved.md");
296
297
  const gone = resultError(await call(captured, "notes_read", { address: "move-me.md" }, ctx));
297
- assert.equal(gone.message, "note not found", "the old address is gone");
298
+ assert.equal(gone.code, "not_found", "the old address is gone");
298
299
  assert.equal(resultRead(await call(captured, "notes_read", { address: "moved.md" }, ctx)).content, "body");
299
300
  // Empty filler values are not a combination: a model passing every parameter still gets its crumple.
300
301
  const crumpled = resultData(await call(captured, "notes_update", { address: "moved.md", crumpled: true, edits: [], origin: "self", rename_to: "", replace_all: false }, ctx));
@@ -469,8 +470,8 @@ test("@ addresses select one home, reject illegal sigils, and never fall back",
469
470
  assert.ok(existsSync(physicalPath("project", "same.md", ctx)), "@project writes to the current project home");
470
471
  assert.ok(existsSync(physicalPath("human", "same.md", ctx)), "@human writes to the human home");
471
472
  assert.match(resultRead(await call(captured, "notes_read", { address: "same.md" }, ctx)).content, /session$/);
472
- assert.equal(resultError(await call(captured, "notes_read", { address: "@project/missing.md" }, ctx)).message, "note not found");
473
- assert.match(resultError(await call(captured, "notes_read", { address: "@glboal/same.md" }, ctx)).message, /no @ for this session.*@project\/.*@human\//);
473
+ assert.equal(resultError(await call(captured, "notes_read", { address: "@project/missing.md" }, ctx)).code, "not_found");
474
+ assert.match(resultError(await call(captured, "notes_read", { address: "@glboal/same.md" }, ctx)).message, /isn't a note address.*@project\/.*@human\//);
474
475
  assert.equal(resultError(await call(captured, "notes_write", { address: "bad@name.md", content: "no" }, ctx)).code, "invalid_address");
475
476
  assert.equal(existsSync(join(root, "human", "bad@name.md")), false, "a bad sigil creates nothing anywhere");
476
477
  });
@@ -497,7 +498,7 @@ test("Pi adapter resolves agent and switched model identity on each notes call a
497
498
  await call(captured, "notes_write", { address: "@self/private.md", content: "agent note" }, ctx);
498
499
  await call(captured, "notes_write", { address: "@model/private.md", content: "first model note" }, ctx);
499
500
  ctx.model = context(session, undefined, undefined, true, testEnvironment.cwd, true, "other/Second.Model").model;
500
- assert.equal(resultError(await call(captured, "notes_read", { address: "@model/private.md" }, ctx)).message, "note not found", "switched model does not fall back to previous home");
501
+ assert.equal(resultError(await call(captured, "notes_read", { address: "@model/private.md" }, ctx)).code, "not_found", "switched model does not fall back to previous home");
501
502
  await call(captured, "notes_write", { address: "@model/private.md", content: "second model note" }, ctx);
502
503
  const listed = resultData(await call(captured, "notes_list", {}, ctx));
503
504
  assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@model/private.md", "@self/private.md"]);
@@ -506,7 +507,7 @@ test("Pi adapter resolves agent and switched model identity on each notes call a
506
507
  assert.equal(boot.includes("@models/first-model/private.md"), false);
507
508
  assert.match(resultRead(await call(captured, "notes_read", { address: "@models/first-model/private.md" }, ctx)).content, /first model note$/);
508
509
  const refused = resultError(await call(captured, "notes_update", { address: "@models/first-model/private.md", crumpled: true }, ctx));
509
- assert.match(refused.message, /not your home/);
510
+ assert.match(refused.message, /someone else's home/);
510
511
  assert.match(readFileSync(join(root, "models/first-model/private.md"), "utf8"), /first model note$/);
511
512
  });
512
513
  });
@@ -528,3 +529,21 @@ async function withAgent(name, run) {
528
529
  process.env.PI_NOTES_AGENT = previous;
529
530
  }
530
531
  }
532
+ test("a symlinked checkout hashes the canonical root, so one checkout has one project home", () => {
533
+ const root = realpathSync(testEnvironment.cwd);
534
+ const real = join(root, "real-repo");
535
+ mkdirSync(join(real, ".git"), { recursive: true });
536
+ const linked = join(root, "linked-repo");
537
+ symlinkSync(real, linked);
538
+ // The formula the key is documented to be: basename plus sha1 of the canonical root.
539
+ const canonicalKey = `${basename(real)}-${createHash("sha1").update(real).digest("hex").slice(0, 8)}`;
540
+ assert.equal(projectKey(linked), canonicalKey, "the symlinked spelling hashes the canonical root");
541
+ assert.equal(projectKey(real), canonicalKey, "the canonical spelling hashes the same root");
542
+ assert.notEqual(`${basename(linked)}-${createHash("sha1").update(linked).digest("hex").slice(0, 8)}`, canonicalKey, "a path-spelled key would differ");
543
+ });
544
+ test("a glob ? matches exactly one non-slash character", () => {
545
+ const pattern = globToRegExp("a?.md");
546
+ assert.equal(pattern.test("ab.md"), true, "? matches one ordinary character");
547
+ assert.equal(pattern.test("a.md"), false, "? is not optional");
548
+ assert.equal(pattern.test("a/b.md"), false, "? never matches a path separator");
549
+ });
@@ -8,7 +8,7 @@ import notesoup from "../src/pi/extension.js";
8
8
  import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_MARKER_TYPE } from "../src/pi/entries.js";
9
9
  import { MANUAL_WIPE_TYPE } from "../src/pi/entries.js";
10
10
  import { toolContext } from "./helpers/extension.js";
11
- import { WARNING_CONTENT } from "../src/pi/reset/text.js";
11
+ import { WARNING_CONTENT } from "../src/budget/text.js";
12
12
  import { initialResetControl, reduceResetControl, registerResetLifecycle, } from "../src/pi/reset/lifecycle.js";
13
13
  const previousNotesHome = process.env.PI_NOTES_HOME;
14
14
  const testNotesHome = mkdtempSync(join(tmpdir(), "notesoup-lifecycle-notes-"));
@@ -2,8 +2,18 @@
2
2
 
3
3
  The package also ships `mods/notesoup`, an early-access Claude Code Mod that registers the five notes tools as `mcp__notesoup__notes_*` tools and attaches one host-scoped notes boot block through Claude's conversation-scoped `prompt.context` event; Claude persists it across resume and reload. The sandboxed hooks module delegates filesystem and shared-domain work to the plugin-local `mods/notesoup/dist/claude/helper.js` through Claude's bounded `$.process.run` capability.
4
4
 
5
- In interactive sessions it resets automatically when `$.session.usage().context.percent >= 85`, checking after `session.measure` and `turn.complete` and waiting for a running turn to complete. Missing percentages do not trigger a reset. Its own `session.compact` hook replaces the conversation with exactly one freshly built notes boot, not a generated summary. `prompt.context` still recomputes but does not duplicate that retained boot. Boot window IDs end in the ordinal `:0`, `:1`, etc.; retained boots restore the ordinal on resume/reload. Original transcript rows remain on disk.
5
+ In interactive sessions it resets automatically when the measured context reaches notesoup's reset point, checking after `session.measure` and `turn.complete` and waiting for a running turn to complete. That point is derived from Claude's own auto-compact threshold instead of a fixed percent, in `src/claude/thresholds.ts`, and reaches the sandboxed hooks module through the helper's `limits` operation:
6
6
 
7
- `/clear-memory` requests the same reset. While idle it submits one hidden normal-model close-out turn to let the model save notes, then resets at `turn.complete`; while busy it waits for the current turn instead. This is necessary in Claude Code 2.1.295: `command.run` holds a turn, and calling compact from a detached timer skips the plugin's own compact hook. The timer only schedules the close-out prompt, never compaction. The headless (`-p` / SDK) compact capability is unsupported: automatic attempts are caught and logged once, and the manual command skips without submitting a model turn. Boot acquisition failure vetoes reset, leaving the current window intact. These behaviors add no settings. Claude history tools, Pi-style warning/runway budgeting, and a Claude dream backend are not implemented.
7
+ 1. `$.session.usage({breakdown:"summary"}).context.autoCompactThreshold` when it is a positive number, with `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` applied the way Claude applies it (it can only lower the point);
8
+ 2. otherwise computed from `$.session.usage().context.window` plus `CLAUDE_CODE_AUTO_COMPACT_WINDOW`, `modelSettings.<model>.autoCompactWindow` and `autoCompactWindow` (the smallest configured window wins, capped at the model window), with Claude's 20000-token output reserve and 13000-token summary buffer;
9
+ 3. otherwise the percent fallback, which expresses the same reserves on the classic 200K window.
8
10
 
9
- The plugin also exposes the shared `skills/dream/SKILL.md` and its referenced `playbook.md`; the build synchronizes both projections from the canonical repository files. Validate it from a built checkout with `claude plugin validate mods/notesoup --strict`; the package build and `npm pack --dry-run` include the manifests, hooks module, helper, skill, and playbook.
11
+ Notesoup resets one `resetMarginTokens` (default 8192) below that point, and warns one `warningRunwayTokens` (default `WARNING_RUNWAY_TOKENS`, 16384) below the reset. With automatic compaction off (`autoCompactEnabled: false` in the merged settings, or `DISABLE_AUTO_COMPACT=1`) the point becomes the effective window minus the output reserve, so the same margins still apply. Every undocumented field is type-guarded and degrades to the next source; an unresolvable point, or missing usage, logs once and skips the automatic reset. `DISABLE_COMPACT=1` is detected at `session.start`, logs once, disables the automatic reset, and makes `/clear-memory` report that it cannot run. The margins are read from the `notesoup` object of Claude's merged `$.settings.read()` (`resetMarginTokens`, `warningRunwayTokens`); any other value is ignored.
12
+
13
+ Once per window, when the measured context crosses the warning point, `prompt.context` adds a `notesoup:warning` block carrying the shared warning text with Claude's closing instruction ("end your turn; the reset runs after it"). The warned flag resets with the window ordinal. Its own `session.compact` hook replaces the conversation with the freshly built notes boot followed by the shared continuation message — the same order and the same words as Pi — not a generated summary. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block tells the model to end its turn and ask the human to run `/clear-memory`, replacing that one sentence through `BootToolNames.wipeSentence`; Pi's boot text is unchanged. Boot window IDs end in the ordinal `:0`, `:1`, etc.; retained boots restore the ordinal on resume/reload. Original transcript rows remain on disk. `session.end` forgets the old window, and identity is refreshed lazily from `$.session.id()`, `$.session.cwd()` and the documented `$.session.model()` (slugified, with `claude` only as a fallback). `/clear`, `/resume` and `/branch` therefore acquire a boot again without needing another `session.start`. Successful native main-session compaction invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
14
+
15
+ `/clear-memory` requests the same reset. While idle it submits one hidden normal-model close-out turn to let the model save notes, then resets at `turn.complete`; while busy it waits for the current turn instead. The close-out prompt is the same shared warning text the automatic path shows. This is necessary in Claude Code 2.1.295: `command.run` holds a turn, and calling compact from a detached timer skips the plugin's own compact hook. The timer only schedules the close-out prompt, never compaction. The headless (`-p` / SDK) compact capability is unsupported: automatic attempts are caught and logged once, and the manual command skips without submitting a model turn. Boot acquisition failure vetoes reset, leaving the current window intact. Claude history tools and a Claude dream backend are not implemented; budget reporting (`get_context_remaining`) remains Pi-only, while the reset points and the one warning per window now follow Claude's own configuration.
16
+
17
+ The notes tools also serve subagent calls, using the same session identity and shared operations. The plugin exposes the shared memory and dream skills and the dream playbook; the build keeps these copies byte-identical to the canonical files.
18
+
19
+ `npm run typecheck` includes the mod against the vendored Claude Code 2.1.295 contract. `npm test` also typechecks it and runs `claude plugin validate mods/notesoup --strict`, skipping validation with a clear message only if `claude` is not installed. Scanner regression tests deliberately reintroduce each of the three forbidden call shapes and require the gate to fail. From a built checkout, check the real load with `claude --plugin-dir mods/notesoup -p "ok"`; a model/API failure after load is separate from a hooks-module refusal. The package build and `npm pack --dry-run` include the manifests, hooks module, helper, skills, and playbook.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.41.0",
3
+ "version": "0.43.0",
4
4
  "description": "Durable notes and a host-scoped notes boot section for Claude Code.",
5
5
  "author": {
6
6
  "name": "AstroSheep"