notesoup 0.57.4 → 0.58.1
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 +15 -1
- package/dist/plugins/claude/src/helper.js +2 -11
- package/dist/plugins/claude/src/thresholds.js +23 -43
- package/dist/plugins/codex/src/mcp.js +3 -11
- package/dist/plugins/codex/src/state.d.ts +1 -1
- package/dist/plugins/codex/src/state.js +1 -1
- package/dist/plugins/dsh/tools.js +1 -1
- package/dist/plugins/pi/boot.d.ts +1 -1
- package/dist/plugins/pi/boot.js +2 -3
- package/dist/plugins/pi/budget.d.ts +1 -1
- package/dist/plugins/pi/budget.js +1 -1
- package/dist/plugins/pi/render.d.ts +1 -1
- package/dist/plugins/pi/render.js +20 -11
- package/dist/plugins/pi/runtime.js +6 -2
- package/dist/plugins/pi/tool-result.d.ts +2 -1
- package/dist/plugins/pi/window.js +24 -1
- package/dist/src/boot/render.d.ts +3 -4
- package/dist/src/boot/render.js +23 -21
- package/dist/src/boot/text.d.ts +2 -5
- package/dist/src/boot/text.js +12 -9
- package/dist/src/budget/text.d.ts +1 -1
- package/dist/src/budget/text.js +1 -1
- package/dist/src/history/corpus.d.ts +1 -1
- package/dist/src/history/corpus.js +1 -1
- package/dist/src/history/history.d.ts +2 -2
- package/dist/src/history/history.js +5 -8
- package/dist/src/history/query.d.ts +11 -3
- package/dist/src/history/query.js +7 -11
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.js +1 -1
- package/dist/src/notes/constants.d.ts +1 -1
- package/dist/src/notes/constants.js +1 -1
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.d.ts +2 -1
- package/dist/src/notes/frontmatter.js +3 -1
- package/dist/src/notes/index.d.ts +1 -0
- package/dist/src/notes/index.js +1 -0
- package/dist/src/notes/policy.d.ts +16 -0
- package/dist/src/notes/policy.js +43 -0
- package/dist/src/notes/store.d.ts +7 -2
- package/dist/src/notes/store.js +61 -19
- package/dist/src/result.d.ts +21 -0
- package/dist/src/result.js +18 -0
- package/dist/src/text-match.d.ts +8 -0
- package/dist/src/text-match.js +34 -0
- package/dist/src/tools/dream.d.ts +9 -1
- package/dist/src/tools/dream.js +2 -1
- package/dist/src/tools/history.js +14 -5
- package/dist/src/tools/notes.d.ts +75 -13
- package/dist/src/tools/notes.js +58 -19
- package/dist/src/tools/output.d.ts +1 -3
- package/dist/src/tools/output.js +1 -19
- package/dist/src/tools/result.d.ts +2 -20
- package/dist/src/tools/result.js +4 -18
- package/dist/src/tools/schema.d.ts +3 -7
- package/dist/src/tools/schema.js +10 -16
- package/dist/test/agent-loop.test.js +78 -6
- package/dist/test/boot.integration.test.js +30 -3
- package/dist/test/claude-mod.test.js +101 -16
- package/dist/test/codex-history.test.js +2 -2
- package/dist/test/codex-plugin.test.js +2 -0
- package/dist/test/dependencies.test.js +38 -3
- package/dist/test/dsh.test.js +1 -1
- package/dist/test/helpers/dependency-graph.js +12 -6
- package/dist/test/helpers/extension.d.ts +2 -1
- package/dist/test/history.integration.test.js +47 -1
- package/dist/test/host-neutral.test.js +4 -3
- package/dist/test/model-facing-text.test.js +20 -16
- package/dist/test/note-policy.test.d.ts +1 -0
- package/dist/test/note-policy.test.js +227 -0
- package/dist/test/notes.integration.test.js +9 -9
- package/dist/test/notes.test.js +4 -4
- package/dist/test/pi-render.test.js +28 -1
- package/dist/test/project-namespace.test.js +1 -1
- package/docs/architecture.md +10 -7
- package/docs/claude-code-mod.md +3 -3
- package/docs/dsh.md +1 -1
- package/docs/notes-library.md +19 -6
- package/docs/reset-lifecycle.md +2 -2
- package/docs/tool-results.md +3 -1
- package/package.json +12 -12
- package/playbook.md +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +535 -439
- package/plugins/claude/hooks/register.ts +26 -36
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/memory/SKILL.md +1 -1
- package/plugins/claude/src/helper.ts +2 -11
- package/plugins/claude/src/thresholds.ts +22 -42
- package/plugins/codex/dist/codex/notesoup.js +519 -403
- package/plugins/codex/src/mcp.ts +5 -12
- package/plugins/codex/src/state.ts +1 -1
- package/plugins/dsh/tools.ts +2 -1
- package/plugins/pi/boot.ts +3 -4
- package/plugins/pi/budget.ts +1 -1
- package/plugins/pi/render.ts +20 -8
- package/plugins/pi/runtime.ts +6 -2
- package/plugins/pi/tool-result.ts +2 -1
- package/plugins/pi/window.ts +20 -1
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/render.ts +24 -21
- package/src/boot/text.ts +12 -9
- package/src/budget/text.ts +1 -1
- package/src/history/corpus.ts +1 -1
- package/src/history/history.ts +5 -6
- package/src/history/query.ts +11 -14
- package/src/index.ts +5 -2
- package/src/notes/constants.ts +1 -1
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +4 -2
- package/src/notes/index.ts +1 -0
- package/src/notes/policy.ts +49 -0
- package/src/notes/store.ts +63 -24
- package/src/result.ts +26 -0
- package/src/text-match.ts +32 -0
- package/src/tools/dream.ts +2 -1
- package/src/tools/history.ts +15 -6
- package/src/tools/notes.ts +60 -20
- package/src/tools/output.ts +1 -17
- package/src/tools/result.ts +4 -26
- package/src/tools/schema.ts +11 -17
- package/dist/plugins/codex/src/history.d.ts +0 -3
- package/dist/plugins/codex/src/history.js +0 -2
- package/dist/plugins/codex/src/transcript.d.ts +0 -3
- package/dist/plugins/codex/src/transcript.js +0 -2
- package/plugins/codex/src/history.ts +0 -3
- package/plugins/codex/src/transcript.ts +0 -3
|
@@ -22,7 +22,7 @@ type ResetState = {
|
|
|
22
22
|
manualPending: boolean; headless: boolean; usageFailureLogged: boolean; preparedBoot?: string; retainedBoot?: string
|
|
23
23
|
toolResetRequested?: boolean; lastWord?: string; manualCompacting?: boolean
|
|
24
24
|
continuation?: string; continuationWindow?: number
|
|
25
|
-
compactDisabled: boolean; limitsFailureLogged: boolean; limitsAttempts: number;
|
|
25
|
+
compactDisabled: boolean; limitsFailureLogged: boolean; limitsAttempts: number; limitsKey?: string
|
|
26
26
|
limits?: ClaudeLimits; warnedWindow?: number; warningPending?: number; texts?: SharedTexts; settingsFailureLogged: boolean
|
|
27
27
|
}
|
|
28
28
|
const COMPACT_DISABLED = "Brain can't be emptied with DISABLE_COMPACT"
|
|
@@ -95,15 +95,6 @@ async function envAutoCompactWindow($: Engine) {
|
|
|
95
95
|
async function envDisableAutoCompact($: Engine) {
|
|
96
96
|
try { return await $.env.get("DISABLE_AUTO_COMPACT") } catch { return undefined }
|
|
97
97
|
}
|
|
98
|
-
/** Presence-style environment flags: any value but an explicit no counts as on. */
|
|
99
|
-
async function compactDisabled($: Engine): Promise<boolean> {
|
|
100
|
-
let value: string | undefined
|
|
101
|
-
try { value = await $.env.get("DISABLE_COMPACT") } catch { return false }
|
|
102
|
-
if (value === undefined) return false
|
|
103
|
-
const text = value.trim().toLowerCase()
|
|
104
|
-
// The same presence convention as the helper's flag parsing: "off"/"no" mean not disabled.
|
|
105
|
-
return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off"
|
|
106
|
-
}
|
|
107
98
|
/** Presence-style env switch; the same convention as DISABLE_COMPACT. The loader requires literal env names. */
|
|
108
99
|
function envFlag(value: string | undefined): boolean {
|
|
109
100
|
const text = value?.trim().toLowerCase() ?? ""
|
|
@@ -140,11 +131,12 @@ async function breakdownContext($: Engine): Promise<Record<string, unknown> | un
|
|
|
140
131
|
return typeof breakdown === "object" && breakdown !== null ? breakdown as unknown as Record<string, unknown> : undefined
|
|
141
132
|
} catch { return undefined }
|
|
142
133
|
}
|
|
143
|
-
/**
|
|
134
|
+
/** Threshold inputs only: changing fill must not invalidate the resolved points. */
|
|
144
135
|
async function limitFacts($: Engine, state: ResetState, usage: ContextUsage): Promise<Record<string, unknown>> {
|
|
136
|
+
const breakdown = await breakdownContext($)
|
|
145
137
|
return {
|
|
146
|
-
usage,
|
|
147
|
-
breakdown:
|
|
138
|
+
usage: { window: usage.window },
|
|
139
|
+
breakdown: { model: breakdown?.model, autoCompactThreshold: breakdown?.autoCompactThreshold, isAutoCompactEnabled: breakdown?.isAutoCompactEnabled },
|
|
148
140
|
settings: await readSettings($, state),
|
|
149
141
|
env: {
|
|
150
142
|
pctOverride: await envPctOverride($),
|
|
@@ -153,35 +145,26 @@ async function limitFacts($: Engine, state: ResetState, usage: ContextUsage): Pr
|
|
|
153
145
|
},
|
|
154
146
|
}
|
|
155
147
|
}
|
|
156
|
-
/**
|
|
157
|
-
* The points the current window is measured against, resolved by the helper's shared
|
|
158
|
-
* derivation. One resolved result per reported window value: an unknown window resolves the
|
|
159
|
-
* percent fallback, and a later real window re-resolves against it. A failed round trip is
|
|
160
|
-
* retried a bounded number of times instead of disabling thresholds for the whole window.
|
|
161
|
-
*/
|
|
148
|
+
/** Reuse points only while their inputs match; bound retries per configuration, not capacity. */
|
|
162
149
|
async function limitsOf($: Engine, state: ResetState, usage: ContextUsage): Promise<ClaudeLimits | undefined> {
|
|
163
|
-
const window = usage.window !== undefined && usage.window > 0 ? usage.window : 0
|
|
164
|
-
const sameWindow = state.limitsWindow === window
|
|
165
|
-
if (sameWindow && state.limits !== undefined) return state.limits
|
|
166
|
-
if (sameWindow && state.limitsAttempts >= MAX_LIMITS_ATTEMPTS) return undefined
|
|
167
150
|
const generation = state.generation
|
|
168
151
|
const facts = await limitFacts($, state, usage)
|
|
169
152
|
if (generation !== state.generation) return undefined
|
|
153
|
+
const key = JSON.stringify([state.identity?.model, facts])
|
|
154
|
+
const sameFacts = state.limitsKey === key
|
|
155
|
+
if (sameFacts && state.limits !== undefined) return state.limits
|
|
156
|
+
if (sameFacts && state.limitsAttempts >= MAX_LIMITS_ATTEMPTS) return undefined
|
|
170
157
|
const response = await run($, { op: "limits", facts })
|
|
171
158
|
if (generation !== state.generation) return undefined
|
|
172
159
|
const limits = response.ok ? limitsShape(response.result) : undefined
|
|
173
|
-
state.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return limits
|
|
178
|
-
}
|
|
179
|
-
state.limitsAttempts = sameWindow ? state.limitsAttempts + 1 : 1
|
|
180
|
-
if (!state.limitsFailureLogged) {
|
|
160
|
+
state.limitsKey = key
|
|
161
|
+
state.limits = limits
|
|
162
|
+
state.limitsAttempts = limits ? 0 : sameFacts ? state.limitsAttempts + 1 : 1
|
|
163
|
+
if (!limits && !state.limitsFailureLogged) {
|
|
181
164
|
state.limitsFailureLogged = true
|
|
182
165
|
log($, THRESHOLDS_UNAVAILABLE)
|
|
183
166
|
}
|
|
184
|
-
return
|
|
167
|
+
return limits
|
|
185
168
|
}
|
|
186
169
|
/** The measured value the points are expressed in; tokens win, percent × window stands in. */
|
|
187
170
|
function measuredValue(limits: ClaudeLimits, usage: ContextUsage): number | undefined {
|
|
@@ -264,7 +247,8 @@ function forgetSession(state: ResetState) {
|
|
|
264
247
|
state.texts = state.limits = undefined
|
|
265
248
|
state.continuation = undefined
|
|
266
249
|
state.continuationWindow = undefined
|
|
267
|
-
state.limitsAttempts =
|
|
250
|
+
state.limitsAttempts = 0
|
|
251
|
+
state.limitsKey = undefined
|
|
268
252
|
state.settingsFailureLogged = state.limitsFailureLogged = false
|
|
269
253
|
state.warnedWindow = state.warningPending = undefined
|
|
270
254
|
}
|
|
@@ -316,7 +300,7 @@ async function syncHistoryWindow($: Engine, state: ResetState) {
|
|
|
316
300
|
|
|
317
301
|
export function register(on: On) {
|
|
318
302
|
const manualSignal: { wake?: () => void } = {}
|
|
319
|
-
const state: ResetState = { generation: 0, window: 0, disabled: false, turnRunning: false, resetting: false, manualPending: false, headless: false, usageFailureLogged: false, compactDisabled: false, limitsFailureLogged: false, limitsAttempts: 0,
|
|
303
|
+
const state: ResetState = { generation: 0, window: 0, disabled: false, turnRunning: false, resetting: false, manualPending: false, headless: false, usageFailureLogged: false, compactDisabled: false, limitsFailureLogged: false, limitsAttempts: 0, settingsFailureLogged: false }
|
|
320
304
|
const registered = new Set<string>()
|
|
321
305
|
let keepMemory = false
|
|
322
306
|
// Classic SessionStart precedes typed session.start and startup appends. Keep this binding
|
|
@@ -349,7 +333,7 @@ export function register(on: On) {
|
|
|
349
333
|
await refreshIdentity($, state)
|
|
350
334
|
state.headless = !e.isInteractive
|
|
351
335
|
// Compaction is the capability explicit resets and budget warnings depend on.
|
|
352
|
-
state.compactDisabled = await
|
|
336
|
+
state.compactDisabled = envFlag(await $.env.get("DISABLE_COMPACT").catch(() => undefined))
|
|
353
337
|
if (state.compactDisabled) log($, COMPACT_DISABLED)
|
|
354
338
|
registered.clear()
|
|
355
339
|
await loadTexts($, state)
|
|
@@ -602,13 +586,19 @@ async function finishManual($: Engine, state: ResetState, signal: { wake?: () =>
|
|
|
602
586
|
const texts = await loadTexts($, state)
|
|
603
587
|
if (generation !== state.generation) return
|
|
604
588
|
if (texts?.warning === undefined) {
|
|
589
|
+
clearManualRequest(state)
|
|
605
590
|
log($, "Brain still full: the close-out prompt didn't load")
|
|
606
591
|
return
|
|
607
592
|
}
|
|
608
|
-
await $.prompt.submit({ text: texts.warning })
|
|
593
|
+
const result = await $.prompt.submit({ text: texts.warning })
|
|
594
|
+
if (generation === state.generation && result.drop !== undefined) {
|
|
595
|
+
clearManualRequest(state)
|
|
596
|
+
log($, "Brain still full: the close-out turn didn't start")
|
|
597
|
+
}
|
|
609
598
|
}
|
|
610
599
|
} catch {
|
|
611
600
|
if (generation === state.generation) {
|
|
601
|
+
clearManualRequest(state)
|
|
612
602
|
log($, "Brain still full: the close-out turn didn't start")
|
|
613
603
|
}
|
|
614
604
|
} finally { armManual($, state, signal) }
|
|
@@ -27,7 +27,7 @@ Durable notes hold decisions, constraints, and lessons that stay true after the
|
|
|
27
27
|
5. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper notebook, move it there, preserving its metadata, and update both notebooks' maps. Do it, don't propose it. Propose only when the destination notebook itself is unclear.
|
|
28
28
|
6. **Preserve meaning and provenance.** Keep facts, conditions, exceptions, uncertainty, authorship, and sources. When promoting a finding, cite its source. Do not relabel agent-authored material as human-authored. If its destination or authority is unclear, propose the promotion instead.
|
|
29
29
|
7. **Keep notes manageable.** Aim below about 200 lines / 8KB per note. Split oversized notes by topic with one-line cross-links.
|
|
30
|
-
8. **Keep wake-up pages useful.** Each writable notebook's `CHEATSHEET.md` holds standing reminders, kept to five lines. Its `MAP.md` holds only the note index: durable notes' addresses and short gists. Both load every window when
|
|
30
|
+
8. **Keep wake-up pages useful.** Each writable notebook's `CHEATSHEET.md` holds standing reminders, kept to five lines. Its `MAP.md` holds only the note index: durable notes' addresses and short gists. Both default to pinned and load every window when live unless explicitly unpinned; do not create empty pages. Each notebook allows five live pins. Every page defaults to a 2048-code-point advisory budget, adjustable per note; overflow warns without truncating a pinned body. Preserve standing rules, add promoted notes to the map, and drop entries that no longer hold. Maps follow the same size budget.
|
|
31
31
|
|
|
32
32
|
## Deleting
|
|
33
33
|
|
|
@@ -5,7 +5,7 @@ description: Review and consolidate durable notes using notesoup's shared dream
|
|
|
5
5
|
|
|
6
6
|
# Dream
|
|
7
7
|
|
|
8
|
-
Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate `CHEATSHEET.md` (five lines); `MAP.md` holds only the note index. Both load every window when
|
|
8
|
+
Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate `CHEATSHEET.md` (five lines); `MAP.md` holds only the note index. Both default to pinned and load every window when live unless explicitly unpinned. Every note defaults to a 2048-code-point advisory budget, adjustable per note; pinned bodies load whole with overflow warnings. Respect soft readonly locks; explicitly unlock with `readonly:false` before changing a locked note.
|
|
9
9
|
|
|
10
10
|
Dream in this agent's current session. Do not start another agent or model unless the human asks.
|
|
11
11
|
|
|
@@ -32,7 +32,7 @@ Any other `@` prefix is refused. A path is relative and `/`-separated, with no e
|
|
|
32
32
|
|
|
33
33
|
`@` addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`. That creates a stray directory instead of a note.
|
|
34
34
|
|
|
35
|
-
`CHEATSHEET.md` and `MAP.md` at
|
|
35
|
+
`CHEATSHEET.md` and `MAP.md` at each notebook's root are separate default-pinned pages you wake up with; absent or crumpled pages are skipped. Set `pinned`, `budget`, and `readonly` through `notes_write`/`notes_update` or frontmatter. Explicit `pinned:false` unpins even a default page. Each notebook allows five live pins; every page defaults to a 2048-code-point advisory budget, adjustable per note. Overflow warns but saves, and pinned bodies load whole. `readonly:true` is a soft lock, not security; explicitly set `readonly:false` to unlock, alone or alongside your changes. Keep standing reminders in `CHEATSHEET.md`, to five lines. `MAP.md` holds only the note index: each durable note's address and gist, for lookup. Update it whenever you add, move or crumple a durable note. Do not create empty pages.
|
|
36
36
|
|
|
37
37
|
Keep notes focused on what is true now; if a piece of past context still matters (such as why an approach was ruled out), keep only a brief summary rather than a blow-by-blow log. Crumple notes that are no longer true; a stale note is worse than none.
|
|
38
38
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
3
|
import type { Static, TSchema } from "typebox";
|
|
4
|
-
import { Check
|
|
4
|
+
import { Check } from "typebox/value";
|
|
5
|
+
import { paramProblem } from "../../../src/tools/schema.js";
|
|
5
6
|
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../../../src/tools/notes.js";
|
|
6
7
|
import { historyList, historyRead, type HistoryTextWrapper } from "../../../src/tools/history.js";
|
|
7
8
|
import { localHistoryCorpus, type LocalHistoryOptions } from "../../../src/history/local.js";
|
|
@@ -32,16 +33,6 @@ function identity(input: ClaudeIdentityInput): NotesIdentity {
|
|
|
32
33
|
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: projectKey(input.cwd, input.home), agent: input.agent, model: input.model });
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
/** The first schema violation, named by parameter so the model can fix that one field. */
|
|
36
|
-
function paramProblem(schema: TSchema, params: unknown): string {
|
|
37
|
-
// A false subschema reports "schema is false"; its parent's additionalProperties error names the field instead.
|
|
38
|
-
const first = Errors(schema, params).find((error) => error.keyword !== "boolean");
|
|
39
|
-
if (!first) return "unrecognized shape";
|
|
40
|
-
const extra = first.keyword === "additionalProperties" ? `: ${(first.params as { additionalProperties: string[] }).additionalProperties.join(", ")}` : "";
|
|
41
|
-
const field = first.instancePath.replace(/^\//, "").replaceAll("/", ".");
|
|
42
|
-
return `${field ? `${field} ` : ""}${first.message}${extra}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
36
|
/** Bind shared execution/rendering to a host context; dispatch validates parameters before calling. */
|
|
46
37
|
function boundOperation<TParams extends TSchema, TData, TContext extends readonly unknown[]>(
|
|
47
38
|
operation: Operation<TParams, TData, TContext>,
|
|
@@ -64,21 +64,11 @@ function settingFlag(settings: unknown): boolean | undefined {
|
|
|
64
64
|
* smallest present value keeps notesoup's reset ahead of whichever one Claude would use.
|
|
65
65
|
*/
|
|
66
66
|
function configuredWindow(settings: unknown, env: Record<string, unknown>, model: unknown): number | undefined {
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const perModel = modelSettings[model];
|
|
73
|
-
if (isPlainObject(perModel)) {
|
|
74
|
-
const value = positiveNumber(perModel.autoCompactWindow);
|
|
75
|
-
if (value !== undefined) windows.push(value);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (isPlainObject(settings)) {
|
|
79
|
-
const value = positiveNumber(settings.autoCompactWindow);
|
|
80
|
-
if (value !== undefined) windows.push(value);
|
|
81
|
-
}
|
|
67
|
+
const root = isPlainObject(settings) ? settings : {};
|
|
68
|
+
const models = isPlainObject(root.modelSettings) ? root.modelSettings : {};
|
|
69
|
+
const perModel = typeof model === "string" && model.length > 0 ? models[model] : undefined;
|
|
70
|
+
const windows = [env.autoCompactWindow, isPlainObject(perModel) ? perModel.autoCompactWindow : undefined, root.autoCompactWindow]
|
|
71
|
+
.map(positiveNumber).filter((value): value is number => value !== undefined);
|
|
82
72
|
return windows.length === 0 ? undefined : Math.min(...windows);
|
|
83
73
|
}
|
|
84
74
|
|
|
@@ -91,17 +81,6 @@ function tokenLimits(source: ClaudeLimitSource, autoCompact: boolean, native: nu
|
|
|
91
81
|
};
|
|
92
82
|
}
|
|
93
83
|
|
|
94
|
-
/** The percent fallback: the same reserves expressed as points of ASSUMED_WINDOW_TOKENS. */
|
|
95
|
-
function percentLimits(autoCompact: boolean, pct: number | undefined, resetMargin: number, warningRunway: number): ClaudeLimits {
|
|
96
|
-
const base = 100 * (1 - (CLAUDE_OUTPUT_RESERVE_TOKENS + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) / ASSUMED_WINDOW_TOKENS);
|
|
97
|
-
const native = pct === undefined ? base : Math.min(pct, base);
|
|
98
|
-
const reset = Math.max(MIN_POINT_PERCENT, native - (resetMargin / ASSUMED_WINDOW_TOKENS) * 100);
|
|
99
|
-
return {
|
|
100
|
-
source: "percent", autoCompact, unit: "percent",
|
|
101
|
-
native, reset, warn: Math.max(MIN_POINT_PERCENT, reset - (warningRunway / ASSUMED_WINDOW_TOKENS) * 100), resetMargin, warningRunway,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
84
|
/**
|
|
106
85
|
* Resolve the points from whatever the host could read. Every field is undocumented-adjacent,
|
|
107
86
|
* so a missing or malformed one degrades to the next source and finally to the percent
|
|
@@ -135,21 +114,22 @@ export function resolveClaudeLimits(facts: unknown): ClaudeLimits {
|
|
|
135
114
|
if (native > 0) return tokenLimits("auto-compact", true, native, resetMargin, warningRunway);
|
|
136
115
|
}
|
|
137
116
|
|
|
138
|
-
// (b)
|
|
139
|
-
// window always answers here: falling through to the percent fallback would express the
|
|
140
|
-
// points on an assumed 200K window, which is later than the window notesoup can see.
|
|
117
|
+
// (b/c) Compute once, using the classic 200K capacity only when the host reports none.
|
|
141
118
|
const window = positiveNumber(usage.window);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
119
|
+
const capacity = window ?? ASSUMED_WINDOW_TOKENS;
|
|
120
|
+
const configured = configuredWindow(settings, env, breakdown.model);
|
|
121
|
+
const effective = Math.min(configured ?? capacity, capacity);
|
|
122
|
+
const available = effective - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
123
|
+
const thresholdFromWindow = available - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS;
|
|
124
|
+
const native = autoCompact
|
|
125
|
+
? pct === undefined ? thresholdFromWindow : Math.min(Math.floor(available * (pct / 100)), thresholdFromWindow)
|
|
126
|
+
: available;
|
|
127
|
+
const limits = tokenLimits(window === undefined ? "percent" : "window", autoCompact, native, resetMargin, warningRunway);
|
|
128
|
+
if (window !== undefined) return limits;
|
|
129
|
+
return {
|
|
130
|
+
...limits, unit: "percent",
|
|
131
|
+
native: limits.native / capacity * 100,
|
|
132
|
+
reset: Math.max(MIN_POINT_PERCENT, limits.reset / capacity * 100),
|
|
133
|
+
warn: Math.max(MIN_POINT_PERCENT, limits.warn / capacity * 100),
|
|
134
|
+
};
|
|
155
135
|
}
|