notesoup 0.58.3 → 0.59.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 +1 -0
- package/dist/plugins/claude/src/helper.js +13 -0
- package/dist/plugins/claude/src/thresholds.js +17 -12
- package/dist/plugins/dsh/tools.js +0 -3
- package/dist/plugins/pi/budget.d.ts +3 -0
- package/dist/plugins/pi/budget.js +22 -11
- package/dist/plugins/pi/runtime.js +22 -6
- package/dist/src/boot/text.d.ts +1 -1
- package/dist/src/boot/text.js +6 -10
- package/dist/src/budget/cap.d.ts +2 -0
- package/dist/src/budget/cap.js +11 -0
- package/dist/src/notes/address.d.ts +1 -1
- package/dist/src/notes/address.js +1 -1
- package/dist/src/notes/policy.js +1 -1
- package/dist/src/tools/dream.d.ts +3 -3
- package/dist/src/tools/dream.js +5 -5
- package/dist/src/tools/history.js +12 -13
- package/dist/src/tools/notes.d.ts +7 -5
- package/dist/src/tools/notes.js +35 -34
- package/dist/src/tools/result.js +2 -2
- package/dist/src/tools/schema.js +2 -2
- package/dist/test/budget-settings.integration.test.js +45 -1
- package/dist/test/claude-mod.test.js +80 -21
- package/dist/test/dsh.test.js +13 -1
- package/dist/test/note-policy.test.js +6 -1
- package/dist/test/notes.integration.test.js +28 -0
- package/docs/claude-code-mod.md +5 -3
- package/docs/reset-lifecycle.md +3 -1
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +96 -70
- package/plugins/claude/hooks/register.ts +57 -9
- package/plugins/claude/src/helper.ts +11 -0
- package/plugins/claude/src/thresholds.ts +18 -11
- package/plugins/codex/dist/codex/notesoup.js +59 -61
- package/plugins/dsh/tools.ts +0 -2
- package/plugins/pi/budget.ts +21 -11
- package/plugins/pi/runtime.ts +18 -6
- package/src/boot/text.ts +6 -10
- package/src/budget/cap.ts +9 -0
- package/src/notes/address.ts +1 -1
- package/src/notes/policy.ts +1 -1
- package/src/tools/dream.ts +5 -5
- package/src/tools/history.ts +12 -14
- package/src/tools/notes.ts +35 -33
- package/src/tools/result.ts +2 -2
- package/src/tools/schema.ts +2 -2
|
@@ -13,6 +13,7 @@ import type { BootToolNames } from "../../../src/boot/text.js";
|
|
|
13
13
|
import { selectContinuation } from "../../../src/budget/text.js";
|
|
14
14
|
import { claudeHistoryGapNotice, claudeHistoryUnconfirmedSeq, CLAUDE_HISTORY_UNKNOWN_WINDOW, CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
|
|
15
15
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
16
|
+
import { parseContextCap } from "../../../src/budget/cap.js";
|
|
16
17
|
import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../../../src/notes/index.js";
|
|
17
18
|
import type { Operation } from "../../../src/tools/result.js";
|
|
18
19
|
import { notesToolContext, type NotesToolContext } from "../../../src/tools/notes-context.js";
|
|
@@ -70,6 +71,16 @@ function historySource(value: unknown, sessionId: string): ClaudeHistorySource {
|
|
|
70
71
|
export async function dispatch(request: unknown, historyOptions: Pick<LocalHistoryOptions, "roots" | "home" | "env"> = {}): Promise<unknown> {
|
|
71
72
|
if (!request || typeof request !== "object" || Array.isArray(request)) throw new Error("malformed request");
|
|
72
73
|
const value = request as Record<string, unknown>;
|
|
74
|
+
if (value.op === "cap") {
|
|
75
|
+
const cap = typeof value.value === "string" ? parseContextCap(value.value) : undefined;
|
|
76
|
+
if (cap === undefined) throw new Error("Usage: /notesoup cap [100k|1m|tokens|off]");
|
|
77
|
+
if (cap !== null) {
|
|
78
|
+
const facts = value.facts && typeof value.facts === "object" ? value.facts as Record<string, unknown> : {};
|
|
79
|
+
const limits = resolveClaudeLimits({ ...facts, capTokens: undefined, usage: { window: cap }, breakdown: {} });
|
|
80
|
+
if (limits.reset <= 1) throw new Error("Cap is too small for Claude's output, compaction and reset reserves");
|
|
81
|
+
}
|
|
82
|
+
return { cap };
|
|
83
|
+
}
|
|
73
84
|
if (value.op === "schemas") return [...Object.entries(OPERATIONS), ...Object.entries(HISTORY_OPERATIONS)].map(([name, operation]) => ({ name, description: operation.description, inputSchema: JSON.parse(JSON.stringify(operation.parameters)) }));
|
|
74
85
|
// The shared reset prose lives here, not in the sandboxed hooks module, so Pi and Claude
|
|
75
86
|
// cannot drift apart. The hooks module caches one copy per session.
|
|
@@ -81,6 +81,12 @@ function tokenLimits(source: ClaudeLimitSource, autoCompact: boolean, native: nu
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
function windowPoint(window: number, autoCompact: boolean, pct: number | undefined): number {
|
|
85
|
+
const available = window - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
86
|
+
const threshold = available - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS;
|
|
87
|
+
return autoCompact ? pct === undefined ? threshold : Math.min(Math.floor(available * (pct / 100)), threshold) : available;
|
|
88
|
+
}
|
|
89
|
+
|
|
84
90
|
/**
|
|
85
91
|
* Resolve the points from whatever the host could read. Every field is undocumented-adjacent,
|
|
86
92
|
* so a missing or malformed one degrades to the next source and finally to the percent
|
|
@@ -103,6 +109,13 @@ export function resolveClaudeLimits(facts: unknown): ClaudeLimits {
|
|
|
103
109
|
&& !presenceFlag(env.disableAutoCompact)
|
|
104
110
|
&& breakdown.isAutoCompactEnabled !== false;
|
|
105
111
|
const pct = percent(env.pctOverride);
|
|
112
|
+
const window = positiveNumber(usage.window);
|
|
113
|
+
const capacity = window ?? ASSUMED_WINDOW_TOKENS;
|
|
114
|
+
const configured = configuredWindow(settings, env, breakdown.model);
|
|
115
|
+
const effective = Math.min(configured ?? capacity, capacity);
|
|
116
|
+
const cap = positiveInteger(root.capTokens);
|
|
117
|
+
const capped = cap !== undefined && cap < effective;
|
|
118
|
+
const nativeFromWindow = windowPoint(Math.min(effective, cap ?? Infinity), autoCompact, pct);
|
|
106
119
|
|
|
107
120
|
// (a) Claude's own point. It already includes the window, model settings and CLI flag; only
|
|
108
121
|
// the percent override is applied separately, on the window-after-output-reserve it is
|
|
@@ -111,20 +124,14 @@ export function resolveClaudeLimits(facts: unknown): ClaudeLimits {
|
|
|
111
124
|
const threshold = positiveNumber(breakdown.autoCompactThreshold);
|
|
112
125
|
if (autoCompact && threshold !== undefined) {
|
|
113
126
|
const native = pct === undefined ? threshold : Math.min(Math.floor((threshold + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) * (pct / 100)), threshold);
|
|
114
|
-
if (native > 0)
|
|
127
|
+
if (native > 0) {
|
|
128
|
+
const point = capped ? Math.min(native, nativeFromWindow) : native;
|
|
129
|
+
return tokenLimits(point < native ? "window" : "auto-compact", true, point, resetMargin, warningRunway);
|
|
130
|
+
}
|
|
115
131
|
}
|
|
116
132
|
|
|
117
133
|
// (b/c) Compute once, using the classic 200K capacity only when the host reports none.
|
|
118
|
-
const
|
|
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);
|
|
134
|
+
const limits = tokenLimits(window === undefined ? "percent" : "window", autoCompact, nativeFromWindow, resetMargin, warningRunway);
|
|
128
135
|
if (window !== undefined) return limits;
|
|
129
136
|
return {
|
|
130
137
|
...limits, unit: "percent",
|
|
@@ -24990,7 +24990,7 @@ function filteredItems(projection, params) {
|
|
|
24990
24990
|
|
|
24991
24991
|
// src/tools/schema.ts
|
|
24992
24992
|
var nullableString = (description) => typebox_exports.Optional(typebox_exports.Union([typebox_exports.String(), typebox_exports.Null()], description === void 0 ? {} : { description }));
|
|
24993
|
-
var historyRoles = () => typebox_exports.Optional(typebox_exports.Array(HistoryRoleSchema, { minItems: 1, description: "
|
|
24993
|
+
var historyRoles = () => typebox_exports.Optional(typebox_exports.Array(HistoryRoleSchema, { minItems: 1, description: "Only these voices: user, assistant, tool, context. Without roles or query, tool and context runs fold into one line." }));
|
|
24994
24994
|
function paramProblem(schema, params) {
|
|
24995
24995
|
const first = Errors2(schema, params).find((error2) => error2.keyword !== "boolean");
|
|
24996
24996
|
if (!first) return "unrecognized shape";
|
|
@@ -24998,7 +24998,7 @@ function paramProblem(schema, params) {
|
|
|
24998
24998
|
const field = first.instancePath.replace(/^\//, "").replaceAll("/", ".");
|
|
24999
24999
|
return `${field ? `${field} ` : ""}${first.message}${extra}`;
|
|
25000
25000
|
}
|
|
25001
|
-
var searchQuery = (description = "
|
|
25001
|
+
var searchQuery = (description = "Text to look for, or a list (any match). Leave it out to just list the pages.") => typebox_exports.Union([typebox_exports.String(), typebox_exports.Array(typebox_exports.String())], { description });
|
|
25002
25002
|
|
|
25003
25003
|
// src/notes/errors.ts
|
|
25004
25004
|
var NoteError = class extends Error {
|
|
@@ -25065,7 +25065,7 @@ function physicalPath(scope, vpath, identity, who) {
|
|
|
25065
25065
|
}
|
|
25066
25066
|
|
|
25067
25067
|
// src/notes/address.ts
|
|
25068
|
-
var ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path
|
|
25068
|
+
var ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path>, @sessions/<id>/<path>, @agents/<name>/<path>, and @models/<name>/<path> read named notebooks.";
|
|
25069
25069
|
var NAMESPACE_HEADS = /* @__PURE__ */ new Map([
|
|
25070
25070
|
["project", { scope: "project" }],
|
|
25071
25071
|
["human", { scope: "human" }],
|
|
@@ -25166,7 +25166,7 @@ function pinnedPageOrder(path) {
|
|
|
25166
25166
|
}
|
|
25167
25167
|
function noteBudgetWarnings(body, policy) {
|
|
25168
25168
|
const count = Array.from(body).length;
|
|
25169
|
-
return count > policy.budget ? [`Warning: note body is ${count} Unicode code points, over budget ${policy.budget}
|
|
25169
|
+
return count > policy.budget ? [`Warning: note body is ${count} Unicode code points, over budget ${policy.budget} \u2014 boil it down.`] : [];
|
|
25170
25170
|
}
|
|
25171
25171
|
function assertNoteUnlocked(fields, unlock) {
|
|
25172
25172
|
if (fields.readonly === true && unlock !== false) throw new NoteError("readonly", "This note has a soft readonly lock; explicitly set readonly:false to unlock before changing it (or in the same call).");
|
|
@@ -26083,8 +26083,8 @@ var TextWindowSchema = typebox_exports.Object({
|
|
|
26083
26083
|
next_offset_chars: typebox_exports.Union([typebox_exports.Integer({ minimum: 0 }), typebox_exports.Null()], { description: "Pass as `offset_chars` to continue; null at the end." })
|
|
26084
26084
|
}, { additionalProperties: false });
|
|
26085
26085
|
var TextWindowRequestSchema = {
|
|
26086
|
-
offset_chars: typebox_exports.Optional(typebox_exports.Integer({ description: "
|
|
26087
|
-
max_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description:
|
|
26086
|
+
offset_chars: typebox_exports.Optional(typebox_exports.Integer({ description: "Where on the page to start reading; negative counts from the end." })),
|
|
26087
|
+
max_chars: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much to read at once." }))
|
|
26088
26088
|
};
|
|
26089
26089
|
function readTextWindow(text2, offset, limit, makeData, render) {
|
|
26090
26090
|
const chars = Array.from(text2);
|
|
@@ -26138,12 +26138,12 @@ function notesIdentityForCall(context2, cwd) {
|
|
|
26138
26138
|
// src/tools/notes.ts
|
|
26139
26139
|
var ORIGIN_VALUES = [typebox_exports.Literal("user"), typebox_exports.Literal("self"), typebox_exports.Literal("external")];
|
|
26140
26140
|
var ORIGIN = typebox_exports.Optional(typebox_exports.Union([...ORIGIN_VALUES], {
|
|
26141
|
-
description: "
|
|
26141
|
+
description: "Whose handwriting: user, self, or external. Leave it out to keep what's there."
|
|
26142
26142
|
}));
|
|
26143
26143
|
var POLICY_PARAMETERS = {
|
|
26144
|
-
pinned: typebox_exports.Optional(typebox_exports.Boolean({ description: "
|
|
26145
|
-
budget: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "
|
|
26146
|
-
readonly: typebox_exports.Optional(typebox_exports.Boolean({ description: "
|
|
26144
|
+
pinned: typebox_exports.Optional(typebox_exports.Boolean({ description: "Tape the page inside the cover: read whole at every wake-up. Five per notebook, CHEATSHEET and MAP included." })),
|
|
26145
|
+
budget: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "How much paper the page gets. Writing past it still saves, with a warning. A page over budget gets boiled down: stale lines out, repeats merged, the rest said shorter. More paper is for a page already boiled down that still needs the room." })),
|
|
26146
|
+
readonly: typebox_exports.Optional(typebox_exports.Boolean({ description: "A paperclip that keeps your own hands off. `false` takes it off \u2014 same call is fine." }))
|
|
26147
26147
|
};
|
|
26148
26148
|
var PolicySchema = {
|
|
26149
26149
|
pinned: typebox_exports.Boolean(),
|
|
@@ -26160,13 +26160,12 @@ function renderPolicy(policy) {
|
|
|
26160
26160
|
function withWarnings(text2, data) {
|
|
26161
26161
|
return [text2, ...data.warnings].join("\n");
|
|
26162
26162
|
}
|
|
26163
|
-
var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "
|
|
26164
|
-
var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "
|
|
26165
|
-
var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "
|
|
26166
|
-
var GLOB_PARAMETER = nullableString("
|
|
26167
|
-
var CWD_PARAMETER = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "
|
|
26168
|
-
var
|
|
26169
|
-
var ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
26163
|
+
var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "`true` balls the page up: gone from list and search, still readable. `false` smooths it flat again." }));
|
|
26164
|
+
var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "Only the crumpled balls." }));
|
|
26165
|
+
var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many pages at most." }));
|
|
26166
|
+
var GLOB_PARAMETER = nullableString("Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf \xB7 `MAP.md` that page in every notebook \xB7 `**` everything \xB7 `@sessions/*/**` every session.");
|
|
26167
|
+
var CWD_PARAMETER = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
|
|
26168
|
+
var ADDRESS_PARAMETER = typebox_exports.String({ description: "Which drawer the page sits in. `plan.md` \u2014 this session's desk, cleared when it ends. `@project/` this project's shelf \xB7 `@human/` your human's file \xB7 `@self/` your own notebook \xB7 `@model/` your brain's. `@projects/<name>/`, `@sessions/<id>/`, `@agents/<name>/`, `@models/<name>/` \u2014 someone else's shelf: read only. Paper, not files: hand one to read/write/edit/bash and a real `@project` folder is born." });
|
|
26170
26169
|
function failureOf(error2) {
|
|
26171
26170
|
if (error2 instanceof NoteError) return failure2(error2.code, error2.message);
|
|
26172
26171
|
if (error2 instanceof InvalidQueryError) return failure2("invalid_query", error2.message);
|
|
@@ -26256,7 +26255,8 @@ var MatchSchema = typebox_exports.Object({
|
|
|
26256
26255
|
}, { additionalProperties: false });
|
|
26257
26256
|
var SearchedFileSchema = typebox_exports.Object({
|
|
26258
26257
|
...ListedFileSchema.properties,
|
|
26259
|
-
matches: typebox_exports.Array(MatchSchema)
|
|
26258
|
+
matches: typebox_exports.Array(MatchSchema),
|
|
26259
|
+
more_matches: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1 }))
|
|
26260
26260
|
}, { additionalProperties: false });
|
|
26261
26261
|
var SnapshotSchema = {
|
|
26262
26262
|
more: typebox_exports.Integer({ description: "How many more were left out." }),
|
|
@@ -26313,14 +26313,14 @@ function listedFile(row, identity) {
|
|
|
26313
26313
|
const policy = policyAt(row.meta, row.address);
|
|
26314
26314
|
return { ...noteIdentity(identity, row.address), ...policy, warnings: row.warnings ?? (row.body === void 0 ? [] : noteBudgetWarnings(row.body, policy)), updated_at: localIso(row.meta.updatedAt), ...row.meta.crumpledAt === void 0 ? {} : { crumpled_at: row.meta.crumpledAt } };
|
|
26315
26315
|
}
|
|
26316
|
-
var notesWriteParameters = typebox_exports.Object({ address:
|
|
26316
|
+
var notesWriteParameters = typebox_exports.Object({ address: ADDRESS_PARAMETER, content: typebox_exports.String({ description: "The whole page." }), origin: ORIGIN, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
26317
26317
|
function renderWriteData(data) {
|
|
26318
26318
|
return withWarnings(`${data.outcome} ${renderIdentity(data)} | ${renderPolicy(data)}`, data);
|
|
26319
26319
|
}
|
|
26320
26320
|
var notesWrite = {
|
|
26321
26321
|
name: "notes_write",
|
|
26322
26322
|
label: "Notes write",
|
|
26323
|
-
description:
|
|
26323
|
+
description: "Take a fresh page and write it \u2014 or rip out the old one and write it again. Title it for what's inside and when you'll reach for it.",
|
|
26324
26324
|
parameters: notesWriteParameters,
|
|
26325
26325
|
outputSchema: resultSchema(NotesWriteDataSchema),
|
|
26326
26326
|
executionMode: "sequential",
|
|
@@ -26336,13 +26336,13 @@ var notesWrite = {
|
|
|
26336
26336
|
render: (result) => renderOutcome(result, renderWriteData)
|
|
26337
26337
|
};
|
|
26338
26338
|
var notesUpdateParameters = typebox_exports.Object({
|
|
26339
|
-
address:
|
|
26340
|
-
edits: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({ oldText: typebox_exports.String(), newText: typebox_exports.String() }, { additionalProperties: false }))),
|
|
26339
|
+
address: ADDRESS_PARAMETER,
|
|
26340
|
+
edits: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({ oldText: typebox_exports.String({ description: "The passage as it stands on the page." }), newText: typebox_exports.String({ description: "What goes in its place." }) }, { additionalProperties: false }), { description: "Pen strokes, in order. Each `oldText` is the exact passage \u2014 same case, found once \u2014 and `newText` is what goes in its place." })),
|
|
26341
26341
|
origin: ORIGIN,
|
|
26342
26342
|
...POLICY_PARAMETERS,
|
|
26343
26343
|
crumpled: CRUMPLED_PARAMETER,
|
|
26344
|
-
replace_all: typebox_exports.Optional(typebox_exports.Boolean({ description: "
|
|
26345
|
-
rename_to: typebox_exports.Optional(typebox_exports.String({ description: "
|
|
26344
|
+
replace_all: typebox_exports.Optional(typebox_exports.Boolean({ description: "Strike every copy of `oldText`, not just one." })),
|
|
26345
|
+
rename_to: typebox_exports.Optional(typebox_exports.String({ description: "Move the page to another address. Never lands on top of a live page; nothing pointing at it follows." })),
|
|
26346
26346
|
cwd: CWD_PARAMETER
|
|
26347
26347
|
}, { additionalProperties: false });
|
|
26348
26348
|
function renderUpdateData(data) {
|
|
@@ -26352,7 +26352,7 @@ function renderUpdateData(data) {
|
|
|
26352
26352
|
var notesUpdate = {
|
|
26353
26353
|
name: "notes_update",
|
|
26354
26354
|
label: "Notes update",
|
|
26355
|
-
description:
|
|
26355
|
+
description: "Work on a page you already have: cross out and rewrite lines, move it, pin it, lock it, give it more paper, crumple it. Keep every page true to now: wrong, stale, or no-longer-mattering lines get rewritten or struck where they stand. The page stays one page.",
|
|
26356
26356
|
parameters: notesUpdateParameters,
|
|
26357
26357
|
outputSchema: resultSchema(NotesUpdateDataSchema),
|
|
26358
26358
|
executionMode: "sequential",
|
|
@@ -26372,7 +26372,7 @@ var notesUpdate = {
|
|
|
26372
26372
|
},
|
|
26373
26373
|
render: (result) => renderOutcome(result, renderUpdateData)
|
|
26374
26374
|
};
|
|
26375
|
-
var notesReadParameters = typebox_exports.Object({ address:
|
|
26375
|
+
var notesReadParameters = typebox_exports.Object({ address: ADDRESS_PARAMETER, ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
26376
26376
|
function renderReadData(data) {
|
|
26377
26377
|
return withWarnings(`${renderIdentity(data)}
|
|
26378
26378
|
${renderMetadata(data.metadata)}`, data) + `
|
|
@@ -26382,7 +26382,7 @@ ${renderTextWindow(data)}`;
|
|
|
26382
26382
|
var notesRead = {
|
|
26383
26383
|
name: "notes_read",
|
|
26384
26384
|
label: "Notes read",
|
|
26385
|
-
description:
|
|
26385
|
+
description: "Read a page. Long ones come a stretch at a time; follow `next_offset_chars`.",
|
|
26386
26386
|
parameters: notesReadParameters,
|
|
26387
26387
|
outputSchema: resultSchema(NotesReadDataSchema),
|
|
26388
26388
|
async execute(params, context2) {
|
|
@@ -26416,7 +26416,7 @@ function renderListData(data) {
|
|
|
26416
26416
|
var notesList = {
|
|
26417
26417
|
name: "notes_list",
|
|
26418
26418
|
label: "Notes list",
|
|
26419
|
-
description:
|
|
26419
|
+
description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile \u2014 narrow `glob`.",
|
|
26420
26420
|
parameters: notesListParameters,
|
|
26421
26421
|
outputSchema: resultSchema(NotesListDataSchema),
|
|
26422
26422
|
async execute(params, context2) {
|
|
@@ -26430,11 +26430,11 @@ var notesList = {
|
|
|
26430
26430
|
},
|
|
26431
26431
|
render: (result) => renderOutcome(result, renderListData)
|
|
26432
26432
|
};
|
|
26433
|
-
var notesSearchParameters = typebox_exports.Object({ query: typebox_exports.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "
|
|
26433
|
+
var notesSearchParameters = typebox_exports.Object({ query: typebox_exports.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "How many hit lines per page at most." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
26434
26434
|
function renderSearchData(data) {
|
|
26435
26435
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
26436
26436
|
for (const file of data.files) {
|
|
26437
|
-
lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}`);
|
|
26437
|
+
lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
|
|
26438
26438
|
lines.push(...file.warnings.map((warning) => ` ${warning}`));
|
|
26439
26439
|
for (const match of file.matches) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
26440
26440
|
}
|
|
@@ -26442,35 +26442,38 @@ function renderSearchData(data) {
|
|
|
26442
26442
|
for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
|
|
26443
26443
|
return lines.join("\n");
|
|
26444
26444
|
}
|
|
26445
|
+
function keepMatches(file, count = file.matches.length) {
|
|
26446
|
+
const more = (file.more_matches ?? 0) + Math.max(0, file.matches.length - count);
|
|
26447
|
+
return { ...file, matches: file.matches.slice(0, count), ...more ? { more_matches: more } : {} };
|
|
26448
|
+
}
|
|
26445
26449
|
var MATCH_SHORTENED_MARKER = " [truncated]";
|
|
26446
26450
|
function fitSearchFile(file, fits) {
|
|
26447
26451
|
let low = 0;
|
|
26448
26452
|
let high = file.matches.length;
|
|
26449
26453
|
while (low < high) {
|
|
26450
26454
|
const mid = Math.ceil((low + high) / 2);
|
|
26451
|
-
if (fits(
|
|
26455
|
+
if (fits(keepMatches(file, mid))) low = mid;
|
|
26452
26456
|
else high = mid - 1;
|
|
26453
26457
|
}
|
|
26454
|
-
if (low > 0
|
|
26458
|
+
if (low > 0 || file.matches.length === 0) return keepMatches(file, low);
|
|
26455
26459
|
const first = file.matches[0];
|
|
26456
|
-
|
|
26457
|
-
const withText = (text2) => ({ ...file, matches: [{ ...first, text: `${text2}${MATCH_SHORTENED_MARKER}` }] });
|
|
26460
|
+
const withText = (text2) => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text2}${MATCH_SHORTENED_MARKER}` }] });
|
|
26458
26461
|
return withText(prefixFit(first.text, (text2) => fits(withText(text2))));
|
|
26459
26462
|
}
|
|
26460
26463
|
var notesSearch = {
|
|
26461
26464
|
name: "notes_search",
|
|
26462
26465
|
label: "Notes search",
|
|
26463
|
-
description:
|
|
26466
|
+
description: "Run a finger down every page for some text, case doesn't matter. Returns the lines it hits and where they sit; no query just lists the pages. One pass; `more` counts pages left on the pile \u2014 narrow `glob`.",
|
|
26464
26467
|
parameters: notesSearchParameters,
|
|
26465
26468
|
outputSchema: resultSchema(NotesSearchDataSchema),
|
|
26466
26469
|
async execute(params, context2) {
|
|
26467
26470
|
try {
|
|
26468
26471
|
const identity = notesIdentityForCall(context2, params.cwd);
|
|
26469
26472
|
const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? void 0, crumpled: params.crumpled });
|
|
26470
|
-
const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map((row) => ({
|
|
26473
|
+
const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map((row) => keepMatches({
|
|
26471
26474
|
...listedFile(row, identity),
|
|
26472
|
-
matches: row.matches.
|
|
26473
|
-
}));
|
|
26475
|
+
matches: row.matches.map((match) => ({ line: match.line, text: match.text, offset_chars: match.offsetChars }))
|
|
26476
|
+
}, params.max_matches_per_file));
|
|
26474
26477
|
return snapshot(files, params.limit, status, renderSearchData, fitSearchFile);
|
|
26475
26478
|
} catch (error2) {
|
|
26476
26479
|
return failureOf(error2);
|
|
@@ -26805,23 +26808,22 @@ function pageOutcome(result) {
|
|
|
26805
26808
|
const narrow = multi ? "narrow the session pattern, query, roles or `since`/`until`, or read one session/seq with `history_read`" : "narrow with `before_seq`/`after_seq` or `since`/`until`, pass `roles` to skip folding, or `history_read` one seq";
|
|
26806
26809
|
return failure2("page_too_large", `Even trimmed to their shortest, these ${count} rows${multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
|
|
26807
26810
|
}
|
|
26808
|
-
var sessionParameter = typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions with query or lists recent sessions without it; history_read needs one session." }));
|
|
26809
26811
|
var historyListParameters = typebox_exports.Object({
|
|
26810
|
-
session:
|
|
26811
|
-
query: typebox_exports.Optional(searchQuery("
|
|
26812
|
+
session: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Whose record: a session ID or prefix (pi:, claude:, codex:, dsh: allowed). Leave it out for this one. `*` means every recent session." })),
|
|
26813
|
+
query: typebox_exports.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
26812
26814
|
roles: historyRoles(),
|
|
26813
|
-
before_seq: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "
|
|
26814
|
-
after_seq: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, description: "
|
|
26815
|
-
since: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "
|
|
26816
|
-
until: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "
|
|
26817
|
-
from: typebox_exports.Optional(typebox_exports.Union([typebox_exports.Literal("newest"), typebox_exports.Literal("oldest")], { description: "
|
|
26818
|
-
limit: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 500, description: "
|
|
26819
|
-
max_chars_per_item: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description:
|
|
26815
|
+
before_seq: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "Only entries before this seq." })),
|
|
26816
|
+
after_seq: typebox_exports.Optional(typebox_exports.Integer({ minimum: 0, description: "Only entries after this seq; 0 starts from the first page." })),
|
|
26817
|
+
since: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Only entries at or after this time (ISO 8601; UTC without an offset)." })),
|
|
26818
|
+
until: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Only entries before this time (ISO 8601; UTC without an offset)." })),
|
|
26819
|
+
from: typebox_exports.Optional(typebox_exports.Union([typebox_exports.Literal("newest"), typebox_exports.Literal("oldest")], { description: "Which end `limit` counts from: newest or oldest. Entries still read oldest first." })),
|
|
26820
|
+
limit: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: 500, description: "How many entries per page; folded runs don't count." })),
|
|
26821
|
+
max_chars_per_item: typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." }))
|
|
26820
26822
|
}, { additionalProperties: false });
|
|
26821
26823
|
var historyList = {
|
|
26822
26824
|
name: "history_list",
|
|
26823
26825
|
label: "History list items",
|
|
26824
|
-
description: "
|
|
26826
|
+
description: "Flip back through the record, a page at a time. Another session: its ID. `*` pulls every recent session off the shelf; add `query` to search them.",
|
|
26825
26827
|
parameters: historyListParameters,
|
|
26826
26828
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
26827
26829
|
async execute(params, context2, wrapText = plainText) {
|
|
@@ -26869,11 +26871,11 @@ var historyList = {
|
|
|
26869
26871
|
},
|
|
26870
26872
|
render: (result) => renderOutcome(result, renderPage)
|
|
26871
26873
|
};
|
|
26872
|
-
var historyReadParameters = typebox_exports.Object({ session:
|
|
26874
|
+
var historyReadParameters = typebox_exports.Object({ session: typebox_exports.Optional(typebox_exports.String({ minLength: 1, description: "Whose record: a session ID or prefix. Leave it out for this one." })), seq: typebox_exports.Integer({ minimum: 1, description: "Which entry, by its seq from `history_list`; bring its session along if it had one." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
26873
26875
|
var historyRead = {
|
|
26874
26876
|
name: "history_read",
|
|
26875
26877
|
label: "History read item",
|
|
26876
|
-
description: "
|
|
26878
|
+
description: "Open one entry: what was called, what came back, the calls nested inside. Long entries come in slices; follow `next_offset_chars`.",
|
|
26877
26879
|
parameters: historyReadParameters,
|
|
26878
26880
|
outputSchema: resultSchema(HistoryReadDataSchema),
|
|
26879
26881
|
async execute(params, context2, wrapText = plainText) {
|
|
@@ -28258,7 +28260,7 @@ While you're doing that... thing you're doing, don't make the poor future you gu
|
|
|
28258
28260
|
|
|
28259
28261
|
Notes are for what's true NOW. Not a diary of every dumb thing you did on the way here.
|
|
28260
28262
|
*flips a page* "First I tried this, then that broke, then\u2014" Nobody reads that!
|
|
28261
|
-
|
|
28263
|
+
When a line goes wrong, stale, or beside the point \u2014 cross it out! Write what's true now, and never pile updates onto the bottom!
|
|
28262
28264
|
*rolls eyes* ...Ugh, fine. If a piece of history *actually* matters \u2014 like why Plan A blew up so tomorrow's you doesn't try it again \u2014 I'll let it slide. Keep the short version! A few lines, max! *squints at you* Turn it into a blow-by-blow log and you're dead.
|
|
28263
28265
|
|
|
28264
28266
|
\`get_context_remaining\` tells you how much room is left. Check it before you do something ambitious. When it reaches zero, your brain gets reset immediately, taking every unwritten brilliant idea with it. ${PROTOCOL_WIPE_SENTENCE}
|
|
@@ -28270,8 +28272,7 @@ An address decides who the note belongs to \u2014 and how long it is meant to la
|
|
|
28270
28272
|
- \`@human/<path>\` \u2014 the long-term manual for your troublesome human, and only what stays true in EVERY project: how to deal with them, which lines not to cross, and what will make them accept the result. "The human said it" is not enough \u2014 if it stops being true the moment you switch projects, it was never theirs; it belongs to that project's notes. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
28271
28273
|
${PROTOCOL_SELF_NAMELESS}
|
|
28272
28274
|
- \`@model/<path>\` \u2014 different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
|
|
28273
|
-
- \`@projects/<name>/<path>\` \u2014
|
|
28274
|
-
- \`@sessions/<id>/<path>\` \u2014 read-only notes from a named session; find them with glob \`@sessions/*/**\`.
|
|
28275
|
+
- \`@projects/<name>/<path>\`, \`@sessions/<id>/<path>\`, \`@agents/<name>/<path>\`, \`@models/<name>/<path>\` \u2014 someone else's shelf, by name. Look, don't touch; \`notes_list\` with a glob like \`@projects/*/**\` shows what's there.
|
|
28275
28276
|
|
|
28276
28277
|
Notes fighting?! HAH! Let them brawl!
|
|
28277
28278
|
Whichever one is actually about what you're doing wins.
|
|
@@ -28284,12 +28285,9 @@ Every notebook's root has two default pins: \`CHEATSHEET.md\` and \`MAP.md\`.
|
|
|
28284
28285
|
Pinned pages get jammed straight into your brain the moment you wake up. Whoever wakes up next
|
|
28285
28286
|
reads them, and next is you. So keep them short, and keep them true.
|
|
28286
28287
|
|
|
28287
|
-
|
|
28288
|
-
|
|
28289
|
-
|
|
28290
|
-
change one. Going over warns but saves, and pinned bodies arrive whole, not cut short.
|
|
28291
|
-
\`readonly:true\` is a soft lock, not security; explicitly set \`readonly:false\` to unlock,
|
|
28292
|
-
on its own or with your changes.
|
|
28288
|
+
Up to five pages per notebook can be taped inside the cover, these two included. Every page gets
|
|
28289
|
+
a paper budget; when a page outgrows it, boil it down \u2014 stale lines out, repeats merged, the rest
|
|
28290
|
+
said shorter \u2014 instead of giving it more paper.
|
|
28293
28291
|
|
|
28294
28292
|
- **\`CHEATSHEET.md\`** holds what you'll want next time \u2014 a rule, a warning, a grudge, a name,
|
|
28295
28293
|
a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
|
|
@@ -28300,7 +28298,7 @@ on its own or with your changes.
|
|
|
28300
28298
|
|
|
28301
28299
|
Each notebook keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
|
|
28302
28300
|
no need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet
|
|
28303
|
-
line. And when a line
|
|
28301
|
+
line. And when a line goes wrong, stale, or useless, kill it \u2014 tomorrow's you reads that page as fact.
|
|
28304
28302
|
</notesoup:maps>`;
|
|
28305
28303
|
var DEFAULT_BOOT_TOOL_NAMES = {
|
|
28306
28304
|
notes: "notes_*",
|
package/plugins/dsh/tools.ts
CHANGED
|
@@ -19,8 +19,6 @@ function hostSchema(schema: TSchema): JsonSchemaNode {
|
|
|
19
19
|
const value = JSON.parse(JSON.stringify(schema)) as Record<string, unknown>;
|
|
20
20
|
const result: Record<string, unknown> = {};
|
|
21
21
|
for (const key of ["type", "required", "additionalProperties", "enum", "const", "description", "title", "default", "examples"]) if (value[key] !== undefined) result[key] = value[key];
|
|
22
|
-
const bounds = ["minimum", "maximum", "minLength", "maxLength", "minItems", "maxItems"].filter((key) => value[key] !== undefined).map((key) => `${key}=${value[key]}`);
|
|
23
|
-
if (bounds.length) result.description = [value.description, bounds.join(", ")].filter(Boolean).join("; ");
|
|
24
22
|
if (Array.isArray(value.anyOf)) result.oneOf = value.anyOf.map((branch) => hostSchema(branch as TSchema));
|
|
25
23
|
if (value.properties) result.properties = Object.fromEntries(Object.entries(value.properties as Record<string, TSchema>).map(([key, child]) => [key, hostSchema(child)]));
|
|
26
24
|
if (value.items) result.items = hostSchema(value.items as TSchema);
|
package/plugins/pi/budget.ts
CHANGED
|
@@ -17,9 +17,9 @@ export const ContextRemainingOutputSchema = Type.Object({
|
|
|
17
17
|
}, { additionalProperties: false });
|
|
18
18
|
|
|
19
19
|
/** Remaining tokens in the provider's active window, or null without a usable estimate. */
|
|
20
|
-
function remainingTokens(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model"
|
|
20
|
+
function remainingTokens(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model">, cap?: number): number | null {
|
|
21
21
|
const usage = windowUsage(ctx);
|
|
22
|
-
return !usage || usage.tokens === null ? null : Math.max(0, usage.contextWindow - usage.tokens);
|
|
22
|
+
return !usage || usage.tokens === null ? null : Math.max(0, Math.min(usage.contextWindow, cap ?? Infinity) - usage.tokens);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function registerBudget(
|
|
@@ -27,6 +27,7 @@ export function registerBudget(
|
|
|
27
27
|
isEnabled: () => boolean,
|
|
28
28
|
settingsManager?: SettingsManager,
|
|
29
29
|
) {
|
|
30
|
+
let cap: number | undefined;
|
|
30
31
|
let cachedPolicy: { thresholds: ResolvedThresholds; automatic: boolean } | undefined;
|
|
31
32
|
const notifiedWarnings = new Set<string>();
|
|
32
33
|
const resolvePolicy = (ctx: ExtensionContext): ThresholdSettingsResolution => {
|
|
@@ -45,15 +46,16 @@ export function registerBudget(
|
|
|
45
46
|
const hardReserveDue = (ctx: ExtensionContext, preSendMessages?: AgentMessage[]): boolean => {
|
|
46
47
|
if (!automaticResetEnabled(ctx)) return false;
|
|
47
48
|
if (preSendMessages) {
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
49
|
+
const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
|
|
50
|
+
if (!nativeWindow || nativeWindow <= 0) return false;
|
|
51
|
+
const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
|
|
50
52
|
const { reserve } = thresholdsFor(ctx);
|
|
51
53
|
const estimate = estimateContextTokens(convertToLlm(preSendMessages));
|
|
52
54
|
if (estimate.lastUsageIndex !== null && contextWindow - estimate.usageTokens <= reserve) return false;
|
|
53
55
|
return contextWindow - estimate.tokens <= reserve;
|
|
54
56
|
}
|
|
55
|
-
const
|
|
56
|
-
return
|
|
57
|
+
const remaining = remainingTokens(ctx, cap);
|
|
58
|
+
return remaining !== null && remaining <= thresholdsFor(ctx).reserve;
|
|
57
59
|
};
|
|
58
60
|
let pendingGuidance: { windowId: string; content: string } | undefined;
|
|
59
61
|
let pendingWarning: { windowId: string; content: string } | undefined;
|
|
@@ -87,10 +89,10 @@ export function registerBudget(
|
|
|
87
89
|
}));
|
|
88
90
|
};
|
|
89
91
|
|
|
90
|
-
pi.on("session_start", (_event, ctx) => { resetForTransition(); thresholdsFor(ctx); });
|
|
92
|
+
pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); thresholdsFor(ctx); });
|
|
91
93
|
pi.on("session_tree", resetForTransition);
|
|
92
94
|
pi.on("model_select", resetForTransition);
|
|
93
|
-
pi.on("session_shutdown", resetForTransition);
|
|
95
|
+
pi.on("session_shutdown", () => { cap = undefined; resetForTransition(); });
|
|
94
96
|
pi.on("agent_settled", clearStaged);
|
|
95
97
|
pi.on("context", (event, ctx) => {
|
|
96
98
|
if (!isEnabled()) return undefined;
|
|
@@ -104,7 +106,7 @@ export function registerBudget(
|
|
|
104
106
|
// measured for that request, and persists the same text at its successful turn_end.
|
|
105
107
|
// Without automatic reset nothing gets cleared, so there is nothing to remind about.
|
|
106
108
|
if (!automaticResetEnabled(ctx)) return result();
|
|
107
|
-
const remaining = remainingTokens(ctx);
|
|
109
|
+
const remaining = remainingTokens(ctx, cap);
|
|
108
110
|
if (remaining === null) return result();
|
|
109
111
|
const windowId = currentWindowId(ctx);
|
|
110
112
|
const { reminder, warning, reserve } = thresholdsFor(ctx);
|
|
@@ -139,7 +141,7 @@ export function registerBudget(
|
|
|
139
141
|
outputSchema: ContextRemainingOutputSchema,
|
|
140
142
|
async execute(_id, _params, _signal, _update, ctx) {
|
|
141
143
|
// Report room to the hard-reserve wipe, including the warning runway.
|
|
142
|
-
const remaining = remainingTokens(ctx);
|
|
144
|
+
const remaining = remainingTokens(ctx, cap);
|
|
143
145
|
const value = { remaining_tokens: remainingBudget(remaining, thresholdsFor(ctx as ExtensionContext).reserve) };
|
|
144
146
|
return { ...output(value), structuredContent: value };
|
|
145
147
|
},
|
|
@@ -150,7 +152,15 @@ export function registerBudget(
|
|
|
150
152
|
hardReserveDue,
|
|
151
153
|
consumeTurnEnd,
|
|
152
154
|
/** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
|
|
153
|
-
statusFor: (ctx: ExtensionContext)
|
|
155
|
+
statusFor: (ctx: ExtensionContext) => ({ remaining: remainingBudget(remainingTokens(ctx, cap), thresholdsFor(ctx).reserve), cap }),
|
|
156
|
+
/** Runtime-only cap; reserve and all warning margins keep their existing meanings. */
|
|
157
|
+
setCap: (value: number | undefined, ctx: ExtensionContext): string | undefined => {
|
|
158
|
+
const reserve = thresholdsFor(ctx).reserve;
|
|
159
|
+
if (value !== undefined && value <= reserve) return `Cap must exceed the ${reserve.toLocaleString("en-US")}-token reset reserve`;
|
|
160
|
+
cap = value;
|
|
161
|
+
clearStaged();
|
|
162
|
+
return undefined;
|
|
163
|
+
},
|
|
154
164
|
clear: () => { clearStaged(); notifiedWindows.clear(); },
|
|
155
165
|
};
|
|
156
166
|
}
|
package/plugins/pi/runtime.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot
|
|
|
17
17
|
import { maybeSendMarker } from "./marker.js";
|
|
18
18
|
import { nextHistorySeq } from "./history.js";
|
|
19
19
|
import { errorMessage } from "../../src/error-message.js";
|
|
20
|
+
import { parseContextCap } from "../../src/budget/cap.js";
|
|
20
21
|
|
|
21
22
|
function readPackageVersion(): string {
|
|
22
23
|
for (const up of ["../../package.json", "../../../package.json"]) {
|
|
@@ -152,12 +153,23 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
pi.registerCommand("notesoup", {
|
|
155
|
-
description: "Show
|
|
156
|
+
description: "Show notesoup status, toggle context windows, or cap their capacity",
|
|
156
157
|
getArgumentCompletions: (prefix) =>
|
|
157
|
-
["on", "off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
158
|
+
["on", "off", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
158
159
|
handler: async (args, cmdCtx) => {
|
|
159
160
|
const arg = args.trim().toLowerCase();
|
|
160
|
-
|
|
161
|
+
const parts = arg.split(/\s+/);
|
|
162
|
+
if (parts[0] === "cap") {
|
|
163
|
+
if (parts.length > 1) {
|
|
164
|
+
const value = parts.length === 2 ? parseContextCap(parts[1]!) : undefined;
|
|
165
|
+
if (value === undefined) {
|
|
166
|
+
cmdCtx.ui.notify("Usage: /notesoup cap [100k|1m|tokens|off]", "error");
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const error = budget.setCap(value ?? undefined, cmdCtx);
|
|
170
|
+
if (error) { cmdCtx.ui.notify(`🥣 ${error}`, "error"); return; }
|
|
171
|
+
}
|
|
172
|
+
} else if (arg === "on") {
|
|
161
173
|
enabled = true;
|
|
162
174
|
const generation = ++lifecycleGeneration;
|
|
163
175
|
await ensureBoot(pi, cmdCtx, notifyIncompleteNotes, () => generation === lifecycleGeneration && enabled);
|
|
@@ -170,11 +182,11 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
170
182
|
budget.clear();
|
|
171
183
|
resets.clear();
|
|
172
184
|
} else if (arg !== "") {
|
|
173
|
-
cmdCtx.ui.notify("Usage: /notesoup [on|off]", "error");
|
|
185
|
+
cmdCtx.ui.notify("Usage: /notesoup [on|off|cap [100k|1m|tokens|off]]", "error");
|
|
174
186
|
return;
|
|
175
187
|
}
|
|
176
|
-
const remaining = budget.statusFor(cmdCtx)
|
|
177
|
-
cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
|
|
188
|
+
const { remaining, cap } = budget.statusFor(cmdCtx);
|
|
189
|
+
cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION} · cap ${cap === undefined ? "off" : cap.toLocaleString("en-US")}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
|
|
178
190
|
},
|
|
179
191
|
});
|
|
180
192
|
|