notesoup 0.58.0 → 0.58.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugins/claude/src/thresholds.js +18 -25
- package/dist/test/claude-mod.test.js +486 -80
- package/docs/claude-code-mod.md +17 -5
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +17 -26
- package/plugins/claude/hooks/register.ts +215 -148
- package/plugins/claude/src/thresholds.ts +17 -27
package/docs/claude-code-mod.md
CHANGED
|
@@ -6,15 +6,23 @@ There is no independent proactive automatic clear line: crossing a measured thre
|
|
|
6
6
|
|
|
7
7
|
1. `$.session.usage({breakdown:"summary"}).context.breakdown.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
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; `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` lowers this fallback point by the same formula. With auto-compaction off, the percent override is ignored;
|
|
9
|
-
3. otherwise the percent fallback, which
|
|
9
|
+
3. otherwise the percent fallback, which assumes a classic 200K capacity, applies the same configured-window caps and token derivation, then converts the points to percentages.
|
|
10
10
|
|
|
11
|
-
The warning remains `resetMarginTokens` (default 8192) plus `warningRunwayTokens` (default `WARNING_RUNWAY_TOKENS`, 16384) below that point. The internal reset-derived intermediate is only warning math, not a clear trigger. 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 budget warning. `DISABLE_COMPACT=1` is detected at `session.start`, logs once, suppresses budget warnings and explicit resets, and makes `/fresh-window` 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. Setting `NOTESOUP_DISABLED` (presence-style, the same convention as `DISABLE_COMPACT`) turns the whole mod off: `session.start` registers no tools or commands and logs once, every event passes through untouched, and native compaction behaves as if the mod were absent.
|
|
11
|
+
The warning remains `resetMarginTokens` (default 8192) plus `warningRunwayTokens` (default `WARNING_RUNWAY_TOKENS`, 16384) below that point. Resolved points are reused only while the current model, threshold inputs and settings match; changing context fill alone does not invalidate them. The internal reset-derived intermediate is only warning math, not a clear trigger. 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 budget warning. `DISABLE_COMPACT=1` is detected at `session.start`, logs once, suppresses budget warnings and explicit resets, and makes `/fresh-window` 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. Setting `NOTESOUP_DISABLED` (presence-style, the same convention as `DISABLE_COMPACT`) turns the whole mod off: `session.start` registers no tools or commands and logs once, every event passes through untouched, and native compaction behaves as if the mod were absent.
|
|
12
12
|
|
|
13
13
|
Once per window, when the measured context crosses the warning point, main-agent tool results or prompt submission carry exactly the same budget warning as Pi, ending with `empty_brain` and the countdown. Delivery is consumed only when the downstream chain accepts the warning. The warned flag resets with the window ordinal. Its own `session.compact` hook answers native compaction in the main conversation instead of letting it summarize: an automatic compaction (threshold or prompt-too-long) becomes the freshly built notes boot followed by one randomly selected handoff paragraph (normal only when the model called `empty_brain`, otherwise forced), selected once for the new window and reused on retry — the same boot-then-handoff order as Pi — while user `/compact` and precompute are vetoed with a one-line notice. `prompt.context` still recomputes but does not duplicate that retained boot. The boot's protocol block binds the shared reset sentence to `mcp__notesoup__empty_brain`; 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`. A failed boot build falls back to Claude's own summary, which invalidates a removed retained boot; vetoes, subagent compaction and precompute leave it alone.
|
|
14
14
|
|
|
15
|
-
The
|
|
15
|
+
The reset flow has three separate lifetimes. `ResetFlow.request` lasts until successful reset or cancellation; it owns the first valid tool call's sticky note and continuation policy. `ResetState.commit` lasts for one native command attempt and tracks proof that Claude kept the boot. The per-turn cutoff can outlive the request when native auto compaction consumes it before the next step. Successful explicit reset and automatic reset share the same window/boot bookkeeping. A failed compaction retains the request for retry; an aborted, failed, or refused main turn cancels it. Session changes discard the flow and invalidate asynchronous work by generation.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
`empty_brain` accepts optional `last_word` and boolean `terminate` (default `false`). Non-boolean `terminate` is refused before recording a request. The first valid tool call owns both arguments for that pending reset; duplicates can re-arm the cutoff but cannot replace them. Every tool in the response's batch finishes, including parallel siblings. At the requesting main turn's next `turn.step`, the cutoff yields a synthetic `end_turn` without another model request or aborting tools. Subagent steps pass through, and subagents cannot reset the main brain. After successful main `turn.complete`, the non-held reset worker compacts; a confirmed commit permits one plugin-origin continuation unless `terminate: true`, manual STOP, or natural input has taken over. The handoff and sticky are already retained alongside the boot and are not repeated by that prompt.
|
|
18
|
+
|
|
19
|
+
Accepted natural input owns its continuation. Input received within the running turn, including input accepted before the first tool latch, releases the cutoff at the next step for the whole subsequent tool workflow. Input not yet delivered to a model request prevents reset work from starting. A separately queued natural turn also runs normally. No input is replayed. Native auto compaction consumes a pending request without resetting twice, while preserving its armed cutoff until turn completion or natural-input delivery; further auto compaction does not disarm it. Once that reset has completed and natural input releases its cutoff, a new `empty_brain` owns its own sticky and `terminate` policy. A consumed request's STOP does not carry into the new request.
|
|
20
|
+
|
|
21
|
+
`/empty` and `/fresh-window` request STOP for the same pending or in-flight reset, including one first requested by a tool. While idle they start one hidden normal-model close-out using the shared budget warning, so the model can save notes; while busy they use the current turn. A close-out tool call may select the normal handoff pool and sticky but cannot undo manual STOP. If the warning cannot load, submission fails, or another hook drops it, the request is cancelled so the command can retry. STOP controls automatic continuation; handoff selection still follows actual tool origin (normal) or no tool origin (forced). `DISABLE_COMPACT` refuses explicit requests and suppresses warnings.
|
|
22
|
+
|
|
23
|
+
Both interactive and headless (`-p` / SDK) resets use `$.command.run({command:"compact",args:...})`. A waiter armed in `session.start` runs this work outside held hooks and re-arms before submitting a close-out, avoiding prompt deadlock and lost completion signals. The command carries a unique instruction marker stored in its commit attempt; only matching manual compaction is admitted, while user `/compact` stays vetoed. Direct `$.session.compact` skips the calling mod's hook interactively and is unavailable headlessly. The command is enqueued before `turn.complete` returns, supporting single-prompt `-p` runs and open SDK streams.
|
|
24
|
+
|
|
25
|
+
A command receipt and prepared boot are not commit evidence. On Claude Code 2.1.319, interactive completion exposes the installed boot through `$.session.messages()`. Headless completion still exposes the old request snapshot and precedes appends, so the worker waits for successful main `session.append` results: a kept compact boundary followed by the unchanged boot with its UUID. A missing or rewritten boot, veto, or rejected command cannot start continuation. Boot acquisition failure vetoes an explicit reset without advancing the window. After commit, a dropped or failed continuation is reported without compacting again. Native command/output rows remain alongside the fresh boot; no compaction model request is made. A Claude dream backend is not implemented, and budget reporting (`get_context_remaining`) remains Pi-only.
|
|
18
26
|
|
|
19
27
|
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.
|
|
20
28
|
|
|
@@ -36,4 +44,8 @@ Without a path back to a root or retained boot, window ordinals are unknown. Tho
|
|
|
36
44
|
|
|
37
45
|
## Validation
|
|
38
46
|
|
|
39
|
-
`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 plugins/claude --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.
|
|
47
|
+
`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 plugins/claude --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. Unit regressions drain the `turn.step` generator (including its final return value), distinguish a command receipt from deferred kept rows, and cover optional/default/explicit `terminate`, first-request-wins arguments, invalid booleans, manual STOP, STOP consumed by native automatic compaction, accepted natural input, failed commits, submission failures, and session changes.
|
|
48
|
+
|
|
49
|
+
The reset sequence was also verified with the installed Claude Code 2.1.319 main loop, using a scripted Anthropic service bound to loopback, isolated homes/settings/working directories, fake credentials, and a sandbox blocking external network access and reads of the real home. Single-prompt `-p`, open `stream-json`, and an interactive PTY all produced one clean request after a committed tool reset. The probe also checked parallel fast/slow `Read` siblings, `terminate:true` (one original API request, one commit, no kickoff) and explicit `terminate:false` (one commit followed by one fresh-window API request), manual close-out STOP even when it calls the tool, compaction vetoes, continuation drops, interruption, and natural input delivered within the running turn. These are host integration observations, separate from the unit harness. A skip returned after `next()` has already compacted is rejected by 2.1.319; that compaction stands. Valid vetoes return before calling `next`.
|
|
50
|
+
|
|
51
|
+
From a built checkout, check the real load with `claude --plugin-dir plugins/claude -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.
|
package/package.json
CHANGED
|
@@ -11476,21 +11476,6 @@ function tokenLimits(source, autoCompact, native, resetMargin, warningRunway) {
|
|
|
11476
11476
|
warningRunway
|
|
11477
11477
|
};
|
|
11478
11478
|
}
|
|
11479
|
-
function percentLimits(autoCompact, pct, resetMargin, warningRunway) {
|
|
11480
|
-
const base = 100 * (1 - (CLAUDE_OUTPUT_RESERVE_TOKENS + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) / ASSUMED_WINDOW_TOKENS);
|
|
11481
|
-
const native = pct === void 0 ? base : Math.min(pct, base);
|
|
11482
|
-
const reset = Math.max(MIN_POINT_PERCENT, native - resetMargin / ASSUMED_WINDOW_TOKENS * 100);
|
|
11483
|
-
return {
|
|
11484
|
-
source: "percent",
|
|
11485
|
-
autoCompact,
|
|
11486
|
-
unit: "percent",
|
|
11487
|
-
native,
|
|
11488
|
-
reset,
|
|
11489
|
-
warn: Math.max(MIN_POINT_PERCENT, reset - warningRunway / ASSUMED_WINDOW_TOKENS * 100),
|
|
11490
|
-
resetMargin,
|
|
11491
|
-
warningRunway
|
|
11492
|
-
};
|
|
11493
|
-
}
|
|
11494
11479
|
function resolveClaudeLimits(facts) {
|
|
11495
11480
|
const root = isPlainObject(facts) ? facts : {};
|
|
11496
11481
|
const usage = isPlainObject(root.usage) ? root.usage : {};
|
|
@@ -11504,19 +11489,25 @@ function resolveClaudeLimits(facts) {
|
|
|
11504
11489
|
const pct = percent(env.pctOverride);
|
|
11505
11490
|
const threshold = positiveNumber(breakdown.autoCompactThreshold);
|
|
11506
11491
|
if (autoCompact && threshold !== void 0) {
|
|
11507
|
-
const
|
|
11508
|
-
if (
|
|
11492
|
+
const native2 = pct === void 0 ? threshold : Math.min(Math.floor((threshold + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) * (pct / 100)), threshold);
|
|
11493
|
+
if (native2 > 0) return tokenLimits("auto-compact", true, native2, resetMargin, warningRunway);
|
|
11509
11494
|
}
|
|
11510
11495
|
const window = positiveNumber(usage.window);
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
return
|
|
11496
|
+
const capacity = window ?? ASSUMED_WINDOW_TOKENS;
|
|
11497
|
+
const configured = configuredWindow(settings2, env, breakdown.model);
|
|
11498
|
+
const effective = Math.min(configured ?? capacity, capacity);
|
|
11499
|
+
const available = effective - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
11500
|
+
const thresholdFromWindow = available - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS;
|
|
11501
|
+
const native = autoCompact ? pct === void 0 ? thresholdFromWindow : Math.min(Math.floor(available * (pct / 100)), thresholdFromWindow) : available;
|
|
11502
|
+
const limits = tokenLimits(window === void 0 ? "percent" : "window", autoCompact, native, resetMargin, warningRunway);
|
|
11503
|
+
if (window !== void 0) return limits;
|
|
11504
|
+
return {
|
|
11505
|
+
...limits,
|
|
11506
|
+
unit: "percent",
|
|
11507
|
+
native: limits.native / capacity * 100,
|
|
11508
|
+
reset: Math.max(MIN_POINT_PERCENT, limits.reset / capacity * 100),
|
|
11509
|
+
warn: Math.max(MIN_POINT_PERCENT, limits.warn / capacity * 100)
|
|
11510
|
+
};
|
|
11520
11511
|
}
|
|
11521
11512
|
|
|
11522
11513
|
// plugins/claude/src/helper.ts
|