notesoup 0.52.4 → 0.52.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,15 +53,29 @@ pi -e npm:notesoup
53
53
 
54
54
  ## Configuration
55
55
 
56
- The reminder threshold is Pi's compaction reserve plus a margin, configured under the top-level `notesoup` key in `~/.pi/agent/settings.json` or `<cwd>/.pi/settings.json` (project values win per key):
56
+ Pi budget settings live under the top-level `notesoup` key in `~/.pi/agent/settings.json` or `<cwd>/.pi/settings.json`. Trusted project values win **per key**: a project override of `reserveTokens` still inherits a global `warningRunwayTokens`. Each value must be a positive safe integer (numeric strings are also accepted). An absent value uses its fallback; an invalid value emits a warning and uses that same fallback, not a lower-precedence global value.
57
+
58
+ | Setting | Meaning | Fallback |
59
+ | --- | --- | --- |
60
+ | `notesoup.reserveTokens` | Remaining tokens at the hard-reserve wipe. Also subtracted by `get_context_remaining`. | The active Pi compaction reserve, including provider/model overrides. |
61
+ | `notesoup.warningRunwayTokens` | Room between the final warning and the hard-reserve wipe. Warning fires at remaining tokens ≤ reserve + runway. | Shared default: `16384`. |
62
+ | `notesoup.reminderMarginTokens` | Early reminder margin above the resolved notesoup reserve. | `24576`. |
63
+
64
+ For example, explicitly configure an `8192` hard reserve and a `16384` warning runway:
57
65
 
58
66
  ```json
59
67
  {
60
- "compaction": { "reserveTokens": 16384 },
61
- "notesoup": { "reminderMarginTokens": 24576 }
68
+ "notesoup": {
69
+ "reserveTokens": 8192,
70
+ "warningRunwayTokens": 16384
71
+ }
62
72
  }
63
73
  ```
64
74
 
75
+ This warns at **24576 remaining tokens** and hard-wipes at **8192**; `get_context_remaining` reports `16384` at the warning line. These are example settings, not changed defaults. Without overrides, the reserve still inherits Pi's active compaction reserve, and the warning runway remains `16384`. The early reminder uses reserve + reminder margin; if usage crosses both reminder and warning, the final warning takes precedence.
76
+
77
+ These settings only change notesoup's budget thresholds. They do not modify Pi's native `compaction` settings or enable automatic resets when Pi's compaction is disabled (or notesoup is off). Other hosts retain their existing host-specific settings.
78
+
65
79
  Environment variables:
66
80
 
67
81
  - `NOTESOUP_DISABLED` — presence-style kill switch: any value but an explicit no (`0`, `false`, `no`, `off`) turns notesoup off. On Pi the extension registers nothing at all; on Claude the mod passes every event through and native compaction behaves as if the mod were absent.
@@ -1,7 +1,7 @@
1
1
  import { type ResolvedThresholds } from "../../src/budget/policy.js";
2
2
  import { SettingsManager, type ExtensionContext } from "@earendil-works/pi-coding-agent";
3
3
  /**
4
- * Read the active compaction reserve, enablement, and notesoup margin settings. This
4
+ * Read the active compaction reserve, enablement, and notesoup budget settings. This
5
5
  * function deliberately has no cache: the budget owner supplies the invocation-scoped
6
6
  * cache so two live notesoup instances cannot share mutable policy state.
7
7
  */
@@ -4,13 +4,11 @@ export type ResolvedThresholds = {
4
4
  warning: number;
5
5
  };
6
6
  /**
7
- * Pure derivation of the thresholds from the host's reserve: the reminder fires at reserve
8
- * plus the notesoup margin, the warning steer at reserve plus WARNING_RUNWAY_TOKENS.
9
- * An invalid margin degrades to the default and reports one warning. Automatic
10
- * threshold/overflow handling is represented by reset lifecycle boundary drafts;
11
- * no compaction summary is generated.
7
+ * Derive notesoup thresholds from the host reserve and optional notesoup overrides.
8
+ * Invalid settings fall back independently and report one warning per offending key.
9
+ * No host compaction settings are changed and no compaction summary is generated.
12
10
  */
13
- export declare function deriveThresholds(reserveTokens: number, margins: Record<string, unknown>): {
11
+ export declare function deriveThresholds(reserveTokens: number, settings: Record<string, unknown>): {
14
12
  thresholds: ResolvedThresholds;
15
13
  warnings: string[];
16
14
  };
@@ -2,28 +2,25 @@ import { DEFAULT_REMINDER_MARGIN_TOKENS, WARNING_RUNWAY_TOKENS } from "./constan
2
2
  import { positiveInteger } from "./parse.js";
3
3
  import { NOTESOUP_SETTINGS_KEY } from "../settings.js";
4
4
  /**
5
- * Pure derivation of the thresholds from the host's reserve: the reminder fires at reserve
6
- * plus the notesoup margin, the warning steer at reserve plus WARNING_RUNWAY_TOKENS.
7
- * An invalid margin degrades to the default and reports one warning. Automatic
8
- * threshold/overflow handling is represented by reset lifecycle boundary drafts;
9
- * no compaction summary is generated.
5
+ * Derive notesoup thresholds from the host reserve and optional notesoup overrides.
6
+ * Invalid settings fall back independently and report one warning per offending key.
7
+ * No host compaction settings are changed and no compaction summary is generated.
10
8
  */
11
- export function deriveThresholds(reserveTokens, margins) {
9
+ export function deriveThresholds(reserveTokens, settings) {
12
10
  const warnings = [];
13
- const reminderKey = `${NOTESOUP_SETTINGS_KEY}.reminderMarginTokens`;
14
- let reminderMargin;
15
- if (margins.reminderMarginTokens === undefined)
16
- reminderMargin = DEFAULT_REMINDER_MARGIN_TOKENS;
17
- else {
18
- const parsed = positiveInteger(margins.reminderMarginTokens);
19
- if (parsed === undefined) {
20
- warnings.push(`🥣 ${reminderKey} must be a positive integer · using the default`);
21
- reminderMargin = DEFAULT_REMINDER_MARGIN_TOKENS;
22
- }
23
- else
24
- reminderMargin = parsed;
25
- }
26
- return { thresholds: { reminder: reserveTokens + reminderMargin, reserve: reserveTokens, warning: reserveTokens + WARNING_RUNWAY_TOKENS }, warnings };
11
+ const resolve = (key, fallback) => {
12
+ if (settings[key] === undefined)
13
+ return fallback;
14
+ const parsed = positiveInteger(settings[key]);
15
+ if (parsed !== undefined)
16
+ return parsed;
17
+ warnings.push(`🥣 ${NOTESOUP_SETTINGS_KEY}.${key} must be a positive integer · using the default`);
18
+ return fallback;
19
+ };
20
+ const reserve = resolve("reserveTokens", reserveTokens);
21
+ const reminderMargin = resolve("reminderMarginTokens", DEFAULT_REMINDER_MARGIN_TOKENS);
22
+ const warningRunway = resolve("warningRunwayTokens", WARNING_RUNWAY_TOKENS);
23
+ return { thresholds: { reminder: reserve + reminderMargin, reserve, warning: reserve + warningRunway }, warnings };
27
24
  }
28
25
  /** Room before the hard-reserve wipe; unknown usage stays unknown. */
29
26
  export function remainingBudget(remaining, reserve) {
@@ -1,11 +1,81 @@
1
1
  import assert from "node:assert/strict";
2
+ import { join } from "node:path";
2
3
  import test from "node:test";
4
+ import { SettingsManager } from "@earendil-works/pi-coding-agent";
3
5
  import { DEFAULT_REMINDER_MARGIN_TOKENS, DEFAULT_RESERVE_TOKENS } from "../src/budget/constants.js";
4
- import { GUIDANCE_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
6
+ import { GUIDANCE_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
7
+ import { deriveThresholds } from "../src/budget/policy.js";
8
+ import { readThresholdSettings } from "../plugins/pi/thresholds.js";
5
9
  import { NOTESOUP_SETTINGS_KEY } from "../src/settings.js";
6
- import { appendText, call, commitTurnEndBoundary, context, makeExtension, manager, noticesOf, resultJson, runContextHook, runHandlers, sentOf, settingsFixture, } from "./helpers/extension.js";
10
+ import { appendText, call, commitTurnEndBoundary, context, makeExtension, manager, noticesOf, resultJson, runContextHook, runHandlers, sentOf, settingsFixture, writeJson, } from "./helpers/extension.js";
7
11
  import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
8
12
  const testEnvironment = installExtensionTestHooks("notesoup-integration");
13
+ test("budget derivation preserves defaults and validates overrides independently", () => {
14
+ assert.deepEqual(deriveThresholds(32_768, {}), {
15
+ thresholds: { reserve: 32_768, reminder: 57_344, warning: 49_152 }, warnings: [],
16
+ });
17
+ assert.deepEqual(deriveThresholds(32_768, { reserveTokens: 8192, warningRunwayTokens: "16384" }), {
18
+ thresholds: { reserve: 8192, reminder: 32_768, warning: 24_576 }, warnings: [],
19
+ });
20
+ const invalid = deriveThresholds(32_768, { reserveTokens: 0, warningRunwayTokens: 1.5, reminderMarginTokens: -1 });
21
+ assert.deepEqual(invalid.thresholds, deriveThresholds(32_768, {}).thresholds);
22
+ assert.equal(invalid.warnings.length, 3);
23
+ for (const key of ["reserveTokens", "warningRunwayTokens", "reminderMarginTokens"]) {
24
+ assert.equal(invalid.warnings.filter((warning) => warning.includes(`notesoup.${key} must be a positive integer · using the default`)).length, 1);
25
+ }
26
+ assert.deepEqual(deriveThresholds(32_768, { reserveTokens: 8192, warningRunwayTokens: null }).thresholds, { reserve: 8192, reminder: 32_768, warning: 24_576 }, "an invalid runway does not discard a valid reserve");
27
+ });
28
+ test("Pi budget settings merge per key without changing native compaction settings or enablement", async () => {
29
+ const fixture = settingsFixture({
30
+ reserveTokens: 32_768,
31
+ global: { notesoup: { reserveTokens: 12_000, warningRunwayTokens: 20_000 } },
32
+ project: { notesoup: { reserveTokens: 8192 } },
33
+ });
34
+ const sm = manager();
35
+ const ctx = context(sm, undefined, undefined, true, fixture.cwd);
36
+ const sdk = SettingsManager.create(fixture.cwd, fixture.agentDir, { projectTrusted: true });
37
+ const native = sdk.getCompactionSettings();
38
+ assert.deepEqual(readThresholdSettings(ctx, sdk), {
39
+ thresholds: { reserve: 8192, reminder: 32_768, warning: 28_192 }, automatic: true, warnings: [],
40
+ });
41
+ assert.deepEqual(sdk.getCompactionSettings(), native, "notesoup reserve does not mutate Pi's reserve or other compaction settings");
42
+ writeJson(join(fixture.cwd, ".pi", "settings.json"), { notesoup: { warningRunwayTokens: 4096, reserveTokens: 0 } });
43
+ const reloaded = SettingsManager.create(fixture.cwd, fixture.agentDir, { projectTrusted: true });
44
+ const invalid = readThresholdSettings(ctx, reloaded);
45
+ assert.deepEqual(invalid.thresholds, { reserve: 32_768, reminder: 57_344, warning: 36_864 }, "invalid project reserve falls back to native, not the global notesoup reserve; project runway wins");
46
+ assert.equal(invalid.warnings.length, 1);
47
+ assert.match(invalid.warnings[0], /notesoup.reserveTokens/);
48
+ const disabledSettings = { compaction: { enabled: false, reserveTokens: 32_768 }, notesoup: { reserveTokens: 8192, warningRunwayTokens: 16_384 } };
49
+ const disabled = SettingsManager.inMemory(disabledSettings);
50
+ const captured = makeExtension(sm, disabled);
51
+ const full = context(sm, undefined, { tokens: 199_999, percent: 99.9, contextWindow: 200_000 });
52
+ assert.equal(readThresholdSettings(full, disabled).automatic, false);
53
+ assert.equal(await runContextHook(captured, full), undefined, "new knobs do not enable warning injection when native compaction is off");
54
+ const boundary = await commitTurnEndBoundary(captured, sm, full);
55
+ assert.equal(boundary.entries.some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE), false, "new knobs do not enable a hard wipe when native compaction is off");
56
+ assert.equal(disabled.getCompactionSettings().enabled, false);
57
+ });
58
+ test("Pi warning, reported room, and hard wipe use the notesoup reserve override", async () => {
59
+ const fixture = settingsFixture({ reserveTokens: 32_768, global: { notesoup: { reserveTokens: 8192, warningRunwayTokens: 16_384 } } });
60
+ const sm = manager();
61
+ appendText(sm, "user", "ongoing work");
62
+ const captured = makeExtension(sm);
63
+ await runHandlers(captured, "session_tree", {}, context(sm, undefined, undefined, true, fixture.cwd));
64
+ const at = (remaining) => context(sm, undefined, { tokens: 200_000 - remaining, percent: 0, contextWindow: 200_000 }, true, fixture.cwd);
65
+ const early = await runContextHook(captured, at(24_577));
66
+ assert.equal(early?.messages[0]?.customType, GUIDANCE_TYPE, "no warning above reserve + runway");
67
+ assert.match(String(early?.messages[0]?.content), /About 16385 tokens of room left\./, "guidance subtracts the overridden reserve");
68
+ const warning = await runContextHook(captured, at(24_576));
69
+ assert.equal(warning?.messages[0]?.customType, WARNING_TYPE, "warn at 8192 + 16384, not native reserve + runway");
70
+ const room = async (remaining) => resultJson(await call(captured, "get_context_remaining", {}, at(remaining))).remaining_tokens;
71
+ assert.equal(await room(24_576), 16_384);
72
+ assert.equal(await room(8193), 1);
73
+ const before = await commitTurnEndBoundary(captured, sm, at(8193));
74
+ assert.equal(before.entries.some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE), false, "no wipe above the overridden reserve, even below Pi's reserve");
75
+ assert.equal(await room(8192), 0);
76
+ const hard = await commitTurnEndBoundary(captured, sm, at(8192));
77
+ assert.equal(hard.entries.filter((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE).length, 1, "hard wipe at the overridden reserve");
78
+ });
9
79
  test("low-budget guidance and warning persist at turn_end, once per active window", async () => {
10
80
  const sessionManager = manager();
11
81
  const captured = makeExtension(sessionManager);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.52.4",
3
+ "version": "0.52.5",
4
4
  "type": "module",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notesoup",
3
- "version": "0.52.4",
3
+ "version": "0.52.5",
4
4
  "description": "Durable notes and a host-scoped notes boot section for Claude Code.",
5
5
  "author": {
6
6
  "name": "AstroSheep"
@@ -5,7 +5,7 @@ import { mergeNotesoupSettings } from "../../src/settings.js";
5
5
  import { errorMessage } from "../../src/error-message.js";
6
6
 
7
7
  /**
8
- * Read the active compaction reserve, enablement, and notesoup margin settings. This
8
+ * Read the active compaction reserve, enablement, and notesoup budget settings. This
9
9
  * function deliberately has no cache: the budget owner supplies the invocation-scoped
10
10
  * cache so two live notesoup instances cannot share mutable policy state.
11
11
  */
@@ -5,25 +5,23 @@ import { NOTESOUP_SETTINGS_KEY } from "../settings.js";
5
5
  export type ResolvedThresholds = { reminder: number; reserve: number; warning: number };
6
6
 
7
7
  /**
8
- * Pure derivation of the thresholds from the host's reserve: the reminder fires at reserve
9
- * plus the notesoup margin, the warning steer at reserve plus WARNING_RUNWAY_TOKENS.
10
- * An invalid margin degrades to the default and reports one warning. Automatic
11
- * threshold/overflow handling is represented by reset lifecycle boundary drafts;
12
- * no compaction summary is generated.
8
+ * Derive notesoup thresholds from the host reserve and optional notesoup overrides.
9
+ * Invalid settings fall back independently and report one warning per offending key.
10
+ * No host compaction settings are changed and no compaction summary is generated.
13
11
  */
14
- export function deriveThresholds(reserveTokens: number, margins: Record<string, unknown>): { thresholds: ResolvedThresholds; warnings: string[] } {
12
+ export function deriveThresholds(reserveTokens: number, settings: Record<string, unknown>): { thresholds: ResolvedThresholds; warnings: string[] } {
15
13
  const warnings: string[] = [];
16
- const reminderKey = `${NOTESOUP_SETTINGS_KEY}.reminderMarginTokens`;
17
- let reminderMargin: number;
18
- if (margins.reminderMarginTokens === undefined) reminderMargin = DEFAULT_REMINDER_MARGIN_TOKENS;
19
- else {
20
- const parsed = positiveInteger(margins.reminderMarginTokens);
21
- if (parsed === undefined) {
22
- warnings.push(`🥣 ${reminderKey} must be a positive integer · using the default`);
23
- reminderMargin = DEFAULT_REMINDER_MARGIN_TOKENS;
24
- } else reminderMargin = parsed;
25
- }
26
- return { thresholds: { reminder: reserveTokens + reminderMargin, reserve: reserveTokens, warning: reserveTokens + WARNING_RUNWAY_TOKENS }, warnings };
14
+ const resolve = (key: string, fallback: number): number => {
15
+ if (settings[key] === undefined) return fallback;
16
+ const parsed = positiveInteger(settings[key]);
17
+ if (parsed !== undefined) return parsed;
18
+ warnings.push(`🥣 ${NOTESOUP_SETTINGS_KEY}.${key} must be a positive integer · using the default`);
19
+ return fallback;
20
+ };
21
+ const reserve = resolve("reserveTokens", reserveTokens);
22
+ const reminderMargin = resolve("reminderMarginTokens", DEFAULT_REMINDER_MARGIN_TOKENS);
23
+ const warningRunway = resolve("warningRunwayTokens", WARNING_RUNWAY_TOKENS);
24
+ return { thresholds: { reminder: reserve + reminderMargin, reserve, warning: reserve + warningRunway }, warnings };
27
25
  }
28
26
 
29
27
  /** Room before the hard-reserve wipe; unknown usage stays unknown. */