notesoup 0.40.0 → 0.42.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 (93) hide show
  1. package/dist/src/boot/render.js +1 -1
  2. package/dist/src/boot/text.d.ts +12 -0
  3. package/dist/src/boot/text.js +25 -5
  4. package/dist/src/budget/policy.js +1 -1
  5. package/dist/src/budget/text.d.ts +12 -0
  6. package/dist/src/budget/text.js +13 -1
  7. package/dist/src/claude/helper.js +23 -2
  8. package/dist/src/claude/thresholds.d.ts +39 -0
  9. package/dist/src/claude/thresholds.js +149 -0
  10. package/dist/src/dream/doctor.js +3 -2
  11. package/dist/src/dream/git.js +2 -1
  12. package/dist/src/dream/jail.js +10 -10
  13. package/dist/src/dream/report.js +3 -2
  14. package/dist/src/error-message.d.ts +2 -0
  15. package/dist/src/error-message.js +4 -0
  16. package/dist/src/history/history.js +1 -1
  17. package/dist/src/history/query.js +6 -6
  18. package/dist/src/notes/address.d.ts +1 -1
  19. package/dist/src/notes/address.js +12 -12
  20. package/dist/src/notes/store.js +16 -12
  21. package/dist/src/pi/anchored.d.ts +16 -0
  22. package/dist/src/pi/anchored.js +55 -0
  23. package/dist/src/pi/budget.d.ts +1 -1
  24. package/dist/src/pi/budget.js +33 -28
  25. package/dist/src/pi/dream/cli.js +3 -2
  26. package/dist/src/pi/dream/runner.js +2 -1
  27. package/dist/src/pi/reset/lifecycle.d.ts +1 -1
  28. package/dist/src/pi/reset/lifecycle.js +4 -3
  29. package/dist/src/pi/reset/text.d.ts +3 -4
  30. package/dist/src/pi/reset/text.js +5 -4
  31. package/dist/src/pi/runtime.js +13 -16
  32. package/dist/src/pi/thresholds.js +2 -1
  33. package/dist/src/pi/tool-result.js +2 -2
  34. package/dist/src/settings.d.ts +8 -0
  35. package/dist/src/settings.js +6 -1
  36. package/dist/src/tools/history.js +12 -12
  37. package/dist/src/tools/notes.d.ts +3 -3
  38. package/dist/src/tools/notes.js +12 -11
  39. package/dist/src/tools/output.d.ts +2 -0
  40. package/dist/src/tools/output.js +2 -0
  41. package/dist/src/tools/result.js +2 -2
  42. package/dist/src/tools/schema.js +3 -3
  43. package/dist/test/agent-loop.test.js +78 -28
  44. package/dist/test/boot.integration.test.js +5 -5
  45. package/dist/test/budget-settings.integration.test.js +9 -8
  46. package/dist/test/claude-mod.test.js +213 -23
  47. package/dist/test/dream.test.js +3 -3
  48. package/dist/test/history.integration.test.js +7 -8
  49. package/dist/test/host-neutral.test.js +2 -2
  50. package/dist/test/notes-library.test.js +1 -1
  51. package/dist/test/notes.integration.test.js +5 -5
  52. package/dist/test/notes.test.js +16 -16
  53. package/dist/test/reset-lifecycle.test.js +2 -2
  54. package/docs/claude-code-mod.md +10 -2
  55. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  56. package/mods/notesoup/dist/claude/helper.js +212 -45
  57. package/mods/notesoup/hooks/register.ts +209 -48
  58. package/mods/notesoup/playbook.md +10 -10
  59. package/mods/notesoup/skills/dream/SKILL.md +1 -1
  60. package/package.json +1 -1
  61. package/playbook.md +10 -10
  62. package/skills/dream/SKILL.md +1 -1
  63. package/skills/memory/SKILL.md +5 -3
  64. package/src/boot/render.ts +1 -1
  65. package/src/boot/text.ts +31 -5
  66. package/src/budget/policy.ts +1 -1
  67. package/src/budget/text.ts +18 -1
  68. package/src/claude/helper.ts +20 -3
  69. package/src/claude/thresholds.ts +170 -0
  70. package/src/dream/doctor.ts +3 -2
  71. package/src/dream/git.ts +2 -1
  72. package/src/dream/jail.ts +10 -10
  73. package/src/dream/report.ts +3 -2
  74. package/src/error-message.ts +4 -0
  75. package/src/history/history.ts +1 -1
  76. package/src/history/query.ts +6 -6
  77. package/src/notes/address.ts +12 -12
  78. package/src/notes/store.ts +17 -12
  79. package/src/pi/anchored.ts +62 -0
  80. package/src/pi/budget.ts +27 -26
  81. package/src/pi/dream/cli.ts +3 -2
  82. package/src/pi/dream/runner.ts +2 -1
  83. package/src/pi/reset/lifecycle.ts +5 -4
  84. package/src/pi/reset/text.ts +6 -7
  85. package/src/pi/runtime.ts +13 -16
  86. package/src/pi/thresholds.ts +2 -1
  87. package/src/pi/tool-result.ts +2 -2
  88. package/src/settings.ts +18 -2
  89. package/src/tools/history.ts +12 -12
  90. package/src/tools/notes.ts +14 -12
  91. package/src/tools/output.ts +2 -0
  92. package/src/tools/result.ts +2 -2
  93. package/src/tools/schema.ts +3 -3
@@ -235,12 +235,12 @@ test("edit is body-scoped with named failures and a replace_all escape hatch", a
235
235
  const ctx = context(session);
236
236
  await call(captured, "notes_write", { address: "edit.md", content: "alpha\nbeta\nbeta\ngamma" }, ctx);
237
237
  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/);
238
+ assert.match(ambiguous.message, /2 times/);
239
239
  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");
240
+ 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
241
  const missing = resultError(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "absent", newText: "x" }] }, ctx));
242
242
  assert.equal(missing.code, "no_match");
243
- assert.match(missing.message, /^edit 0:/, "a zero-match anchor names the failing edit index");
243
+ assert.match(missing.message, /edits\[0\]/, "a zero-match anchor names the failing edit index");
244
244
  const all = resultData(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "beta", newText: "B" }], replace_all: true }, ctx));
245
245
  assert.equal(all.address, "edit.md");
246
246
  assertReceiptIdentity(all, "edit.md", "session", ctx);
@@ -248,7 +248,7 @@ test("edit is body-scoped with named failures and a replace_all escape hatch", a
248
248
  assert.equal(resultRead(await call(captured, "notes_read", { address: "edit.md" }, ctx)).content, "alpha\nB\nB\ngamma", "replace_all replaces every occurrence");
249
249
  // An anchor that occurs only in frontmatter is not matched: edits are body-only.
250
250
  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");
251
+ assert.match(frontmatterOnly.message, /edits\[0\]/, "a frontmatter-only anchor is not a body match");
252
252
  });
253
253
  test("nothing-to-do, not-found, atomic batches, and replace_all zero-match are named", async () => {
254
254
  freshRoot();
@@ -256,26 +256,26 @@ test("nothing-to-do, not-found, atomic batches, and replace_all zero-match are n
256
256
  const captured = makeExtension(session);
257
257
  const ctx = context(session);
258
258
  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");
259
+ assert.equal(nameOnly.code, "nothing_to_do", "neither edits nor setters is a named error");
260
260
  await call(captured, "notes_write", { address: "edit.md", content: "alpha\nbeta" }, ctx);
261
261
  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");
262
+ assert.equal(empty.code, "nothing_to_do", "an empty edits list with no setters is also nothing to do");
263
263
  const editMissing = resultError(await call(captured, "notes_update", { address: "missing.md", crumpled: true }, ctx));
264
- assert.equal(editMissing.message, "note not found");
264
+ assert.equal(editMissing.code, "not_found");
265
265
  const readMissing = resultError(await call(captured, "notes_read", { address: "missing.md" }, ctx));
266
- assert.equal(readMissing.message, "note not found");
266
+ assert.equal(readMissing.code, "not_found");
267
267
  assert.equal(readMissing.code, "not_found");
268
268
  assert.deepEqual(Object.keys(readMissing).sort(), ["code", "message"], "a plain refusal carries only a code and message");
269
269
  const file = physicalPath("session", "edit.md", ctx);
270
270
  const before = readFileSync(file, "utf8");
271
271
  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");
272
+ assert.match(failed.message, /edits\[1\]/, "the failing edit is named");
273
273
  assert.equal(readFileSync(file, "utf8"), before, "a failing batch leaves the file byte-identical, frontmatter included");
274
274
  const applied = resultData(await call(captured, "notes_update", { address: "edit.md", edits: [{ oldText: "alpha", newText: "A" }, { oldText: "beta", newText: "B" }] }, ctx));
275
275
  assert.equal(applied.change_kind, "body");
276
276
  assert.equal(resultRead(await call(captured, "notes_read", { address: "edit.md" }, ctx)).content, "A\nB");
277
277
  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");
278
+ assert.match(zero.message, /edits\[0\]/, "replace_all with zero matches is the same zero-match error, not a silent no-op");
279
279
  });
280
280
  test("notes_update rename_to moves a note and refuses combinations and live targets", async () => {
281
281
  freshRoot();
@@ -287,14 +287,14 @@ test("notes_update rename_to moves a note and refuses combinations and live targ
287
287
  assert.match(combined.message, /rename_to is used alone/, "rename_to rejects being combined with edits");
288
288
  await call(captured, "notes_write", { address: "occupied.md", content: "live target" }, ctx);
289
289
  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");
290
+ assert.match(conflict.message, /occupied\.md/, "a live target refuses the move");
291
291
  const renamed = resultData(await call(captured, "notes_update", { address: "move-me.md", rename_to: "moved.md" }, ctx));
292
292
  assertReceiptIdentity(renamed, "moved.md", "session", ctx);
293
293
  assert.equal(renamed.rename_from, "move-me.md");
294
294
  assert.equal(renamed.change_kind, "moved");
295
295
  assert.equal(renamed.address, "moved.md");
296
296
  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");
297
+ assert.equal(gone.code, "not_found", "the old address is gone");
298
298
  assert.equal(resultRead(await call(captured, "notes_read", { address: "moved.md" }, ctx)).content, "body");
299
299
  // Empty filler values are not a combination: a model passing every parameter still gets its crumple.
300
300
  const crumpled = resultData(await call(captured, "notes_update", { address: "moved.md", crumpled: true, edits: [], origin: "self", rename_to: "", replace_all: false }, ctx));
@@ -469,8 +469,8 @@ test("@ addresses select one home, reject illegal sigils, and never fall back",
469
469
  assert.ok(existsSync(physicalPath("project", "same.md", ctx)), "@project writes to the current project home");
470
470
  assert.ok(existsSync(physicalPath("human", "same.md", ctx)), "@human writes to the human home");
471
471
  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\//);
472
+ assert.equal(resultError(await call(captured, "notes_read", { address: "@project/missing.md" }, ctx)).code, "not_found");
473
+ assert.match(resultError(await call(captured, "notes_read", { address: "@glboal/same.md" }, ctx)).message, /isn't a note address.*@project\/.*@human\//);
474
474
  assert.equal(resultError(await call(captured, "notes_write", { address: "bad@name.md", content: "no" }, ctx)).code, "invalid_address");
475
475
  assert.equal(existsSync(join(root, "human", "bad@name.md")), false, "a bad sigil creates nothing anywhere");
476
476
  });
@@ -497,7 +497,7 @@ test("Pi adapter resolves agent and switched model identity on each notes call a
497
497
  await call(captured, "notes_write", { address: "@self/private.md", content: "agent note" }, ctx);
498
498
  await call(captured, "notes_write", { address: "@model/private.md", content: "first model note" }, ctx);
499
499
  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");
500
+ 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
501
  await call(captured, "notes_write", { address: "@model/private.md", content: "second model note" }, ctx);
502
502
  const listed = resultData(await call(captured, "notes_list", {}, ctx));
503
503
  assert.deepEqual(listed.files.map((row) => row.address).sort(), ["@model/private.md", "@self/private.md"]);
@@ -506,7 +506,7 @@ test("Pi adapter resolves agent and switched model identity on each notes call a
506
506
  assert.equal(boot.includes("@models/first-model/private.md"), false);
507
507
  assert.match(resultRead(await call(captured, "notes_read", { address: "@models/first-model/private.md" }, ctx)).content, /first model note$/);
508
508
  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/);
509
+ assert.match(refused.message, /someone else's home/);
510
510
  assert.match(readFileSync(join(root, "models/first-model/private.md"), "utf8"), /first model note$/);
511
511
  });
512
512
  });
@@ -271,8 +271,8 @@ test("reset construction failure preserves incoming and budget drafts without co
271
271
  assert.deepEqual(result.entries, [incoming, budgetDraft], "already-built drafts survive reset construction failure");
272
272
  assert.equal(result.continue, false, "a failed reset does not request continuation");
273
273
  assert.equal(notices.at(-1)?.type, "warning");
274
- assert.match(notices.at(-1)?.message ?? "", /could not build reset/);
275
- assert.match(notices.at(-1)?.message ?? "", /follow-up prompt was not executed/);
274
+ assert.match(notices.at(-1)?.message ?? "", /Couldn't clear memory/);
275
+ assert.match(notices.at(-1)?.message ?? "", /your prompt was not sent/);
276
276
  });
277
277
  test("a stale async reset is discarded after a lifecycle switch without staging a notice", async () => {
278
278
  const sessionManager = Manager.inMemory("/private/tmp/notesoup-stale-reset-test");
@@ -2,8 +2,16 @@
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:true}).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.
10
+
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.
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.
8
16
 
9
17
  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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.40.0",
3
+ "version": "0.42.0",
4
4
  "description": "Durable notes and a host-scoped notes boot section for Claude Code.",
5
5
  "author": {
6
6
  "name": "AstroSheep"