notesoup 0.42.0 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/boot/render.js +11 -20
- package/dist/src/boot/snapshot.js +1 -6
- package/dist/src/boot/text.js +1 -1
- package/dist/src/budget/parse.d.ts +14 -0
- package/dist/src/budget/parse.js +36 -0
- package/dist/src/budget/policy.js +2 -7
- package/dist/src/budget/text.d.ts +2 -0
- package/dist/src/budget/text.js +2 -0
- package/dist/src/claude/helper.js +1 -2
- package/dist/src/claude/thresholds.js +45 -66
- package/dist/src/dream/lock.js +6 -13
- package/dist/src/dream/report.js +5 -15
- package/dist/src/history/history.js +4 -2
- package/dist/src/history/query.js +10 -22
- package/dist/src/notes/address.d.ts +0 -1
- package/dist/src/notes/address.js +5 -17
- package/dist/src/notes/errors.d.ts +2 -0
- package/dist/src/notes/errors.js +5 -0
- package/dist/src/notes/frontmatter.js +16 -2
- package/dist/src/notes/identity.js +0 -3
- package/dist/src/notes/paths.d.ts +11 -1
- package/dist/src/notes/paths.js +28 -7
- package/dist/src/notes/store.d.ts +1 -0
- package/dist/src/notes/store.js +38 -37
- package/dist/src/pi/boot.js +1 -5
- package/dist/src/pi/budget.d.ts +3 -3
- package/dist/src/pi/budget.js +11 -11
- package/dist/src/pi/dream/cli.js +43 -11
- package/dist/src/pi/estimate.d.ts +1 -5
- package/dist/src/pi/estimate.js +4 -4
- package/dist/src/pi/history.js +1 -4
- package/dist/src/pi/notes/adapter.d.ts +1 -1
- package/dist/src/pi/notes/adapter.js +2 -2
- package/dist/src/pi/reset/artifacts.d.ts +0 -2
- package/dist/src/pi/reset/artifacts.js +4 -4
- package/dist/src/pi/reset/committed.js +2 -2
- package/dist/src/pi/runtime.js +8 -5
- package/dist/src/pi/thresholds.js +5 -9
- package/dist/src/pi/tool-result.d.ts +1 -4
- package/dist/src/pi/tool-result.js +1 -1
- package/dist/src/pi/window.d.ts +5 -0
- package/dist/src/pi/window.js +7 -0
- package/dist/src/settings.d.ts +2 -0
- package/dist/src/settings.js +4 -3
- package/dist/src/tools/history.js +4 -7
- package/dist/src/tools/notes.d.ts +0 -4
- package/dist/src/tools/notes.js +6 -16
- package/dist/src/tools/output.d.ts +0 -3
- package/dist/src/tools/output.js +1 -9
- package/dist/src/tools/result.d.ts +1 -0
- package/dist/src/tools/result.js +14 -20
- package/dist/src/tools/schema.d.ts +0 -1
- package/dist/src/tools/schema.js +0 -1
- package/dist/test/agent-loop.test.js +1 -2
- package/dist/test/boot.integration.test.js +1 -1
- package/dist/test/claude-mod.test.js +221 -9
- package/dist/test/claude-validation.test.d.ts +1 -0
- package/dist/test/claude-validation.test.js +73 -0
- package/dist/test/dream-skill.test.js +2 -4
- package/dist/test/dream.test.js +14 -0
- package/dist/test/helpers/extension.js +1 -1
- package/dist/test/history.integration.test.js +2 -1
- package/dist/test/host-neutral.test.js +15 -0
- package/dist/test/notes-library.test.js +30 -1
- package/dist/test/notes.integration.test.js +7 -7
- package/dist/test/notes.test.js +24 -5
- package/dist/test/reset-lifecycle.test.js +1 -1
- package/docs/claude-code-mod.md +5 -3
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +147 -173
- package/mods/notesoup/hooks/register.ts +158 -67
- package/mods/notesoup/playbook.md +1 -1
- package/mods/notesoup/skills/dream/SKILL.md +1 -1
- package/mods/notesoup/skills/memory/SKILL.md +61 -0
- package/package.json +5 -3
- package/playbook.md +1 -1
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/render.ts +11 -21
- package/src/boot/snapshot.ts +2 -7
- package/src/boot/text.ts +1 -1
- package/src/budget/parse.ts +39 -0
- package/src/budget/policy.ts +2 -6
- package/src/budget/text.ts +3 -0
- package/src/claude/helper.ts +2 -2
- package/src/claude/thresholds.ts +45 -62
- package/src/dream/lock.ts +3 -9
- package/src/dream/report.ts +5 -10
- package/src/history/history.ts +4 -2
- package/src/history/query.ts +10 -23
- package/src/notes/address.ts +4 -16
- package/src/notes/errors.ts +6 -0
- package/src/notes/frontmatter.ts +12 -2
- package/src/notes/identity.ts +0 -2
- package/src/notes/paths.ts +23 -5
- package/src/notes/store.ts +33 -36
- package/src/pi/boot.ts +1 -13
- package/src/pi/budget.ts +10 -11
- package/src/pi/dream/cli.ts +35 -10
- package/src/pi/estimate.ts +4 -4
- package/src/pi/history.ts +1 -5
- package/src/pi/notes/adapter.ts +2 -2
- package/src/pi/reset/artifacts.ts +4 -4
- package/src/pi/reset/committed.ts +2 -2
- package/src/pi/runtime.ts +7 -6
- package/src/pi/thresholds.ts +5 -11
- package/src/pi/tool-result.ts +1 -1
- package/src/pi/window.ts +8 -0
- package/src/settings.ts +4 -3
- package/src/tools/history.ts +4 -8
- package/src/tools/notes.ts +7 -20
- package/src/tools/output.ts +1 -12
- package/src/tools/result.ts +14 -19
- package/src/tools/schema.ts +0 -1
- package/dist/src/dream/playbook.d.ts +0 -1
- package/dist/src/dream/playbook.js +0 -2
- package/dist/src/pi/reset/text.d.ts +0 -4
- package/dist/src/pi/reset/text.js +0 -7
- package/src/dream/playbook.ts +0 -3
- package/src/pi/reset/text.ts +0 -9
|
@@ -5,7 +5,7 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/claude/helper.ts
|
|
8
|
-
import { realpathSync } from "node:fs";
|
|
8
|
+
import { realpathSync as realpathSync2 } from "node:fs";
|
|
9
9
|
import { pathToFileURL } from "node:url";
|
|
10
10
|
|
|
11
11
|
// node_modules/typebox/build/system/arguments/arguments.mjs
|
|
@@ -7933,10 +7933,17 @@ function parseNote(raw, now = Date.now()) {
|
|
|
7933
7933
|
function yamlScalar(value) {
|
|
7934
7934
|
if (typeof value === "string") {
|
|
7935
7935
|
const reserved = /* @__PURE__ */ new Set(["true", "false", "null", "yes", "no", "on", "off", "~"]);
|
|
7936
|
-
if (/^[A-Za-z0-9_.+\-:/]+$/.test(value) && !reserved.has(value.toLowerCase())) return value;
|
|
7936
|
+
if (/^[A-Za-z0-9_.+\-:/]+$/.test(value) && !reserved.has(value.toLowerCase()) && !parsesAsNonString(value)) return value;
|
|
7937
7937
|
}
|
|
7938
7938
|
return JSON.stringify(value);
|
|
7939
7939
|
}
|
|
7940
|
+
function parsesAsNonString(text) {
|
|
7941
|
+
try {
|
|
7942
|
+
return typeof JSON.parse(text) !== "string";
|
|
7943
|
+
} catch {
|
|
7944
|
+
return false;
|
|
7945
|
+
}
|
|
7946
|
+
}
|
|
7940
7947
|
function serializeNote(meta, body) {
|
|
7941
7948
|
const lines = [];
|
|
7942
7949
|
for (const key of KNOWN_KEYS) {
|
|
@@ -7996,16 +8003,32 @@ var NoteError = class extends Error {
|
|
|
7996
8003
|
this.editIndex = extra.editIndex;
|
|
7997
8004
|
}
|
|
7998
8005
|
};
|
|
8006
|
+
function shown(value) {
|
|
8007
|
+
const json = JSON.stringify(value);
|
|
8008
|
+
return json === void 0 ? String(value) : json;
|
|
8009
|
+
}
|
|
7999
8010
|
|
|
8000
8011
|
// src/notes/paths.ts
|
|
8001
8012
|
import { createHash } from "node:crypto";
|
|
8002
|
-
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
8013
|
+
import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
8003
8014
|
import { readdir } from "node:fs/promises";
|
|
8004
8015
|
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
8005
8016
|
var SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8017
|
+
function assertVirtualPath(value) {
|
|
8018
|
+
if (typeof value !== "string" || value.length === 0) throw new NoteError("invalid_address", "The address is empty; give the note a path.");
|
|
8019
|
+
if (value.includes("\0") || value.includes("\\") || value.startsWith("/")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't start with "/" or contain "\\" or NUL.`);
|
|
8020
|
+
const parts = value.split("/");
|
|
8021
|
+
if (parts.some((part) => part.length === 0 || part === "." || part === "..")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't have empty, ".", or ".." folder names.`);
|
|
8022
|
+
return value;
|
|
8023
|
+
}
|
|
8006
8024
|
function projectKey(cwd) {
|
|
8007
8025
|
const absolute = resolve(cwd);
|
|
8008
|
-
const
|
|
8026
|
+
const spelled = gitRoot(absolute) ?? absolute;
|
|
8027
|
+
let root = spelled;
|
|
8028
|
+
try {
|
|
8029
|
+
root = realpathSync(spelled);
|
|
8030
|
+
} catch {
|
|
8031
|
+
}
|
|
8009
8032
|
const digest = createHash("sha1").update(root).digest("hex").slice(0, 8);
|
|
8010
8033
|
return `${basename(root)}-${digest}`;
|
|
8011
8034
|
}
|
|
@@ -8064,24 +8087,11 @@ function noteFileName(vpath) {
|
|
|
8064
8087
|
return vpath.endsWith(".md") ? vpath : `${vpath}.md`;
|
|
8065
8088
|
}
|
|
8066
8089
|
function physicalPath(scope, vpath, identity2, who) {
|
|
8067
|
-
if (typeof vpath !== "string" || vpath.length === 0 || vpath.includes("\0") || vpath.includes("\\") || vpath.startsWith("/")) throw new TypeError("path must be a safe virtual relative path");
|
|
8068
|
-
if (vpath.split("/").some((part) => part.length === 0 || part === "." || part === "..")) throw new TypeError("path contains an unsupported component");
|
|
8069
8090
|
return join(scopeDir(scope, identity2, who), ...noteFileName(vpath).split("/"));
|
|
8070
8091
|
}
|
|
8071
8092
|
|
|
8072
8093
|
// src/notes/address.ts
|
|
8073
8094
|
var ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path.";
|
|
8074
|
-
function shown(value) {
|
|
8075
|
-
const json = JSON.stringify(value);
|
|
8076
|
-
return json === void 0 ? String(value) : json;
|
|
8077
|
-
}
|
|
8078
|
-
function assertVirtualPath(value) {
|
|
8079
|
-
if (typeof value !== "string" || value.length === 0) throw new NoteError("invalid_address", "The address is empty; give the note a path.");
|
|
8080
|
-
if (value.includes("\0") || value.includes("\\") || value.startsWith("/")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't start with "/" or contain "\\" or NUL.`);
|
|
8081
|
-
const parts = value.split("/");
|
|
8082
|
-
if (parts.some((part) => part.length === 0 || part === "." || part === "..")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't have empty, ".", or ".." folder names.`);
|
|
8083
|
-
return value;
|
|
8084
|
-
}
|
|
8085
8095
|
function globToRegExp(pattern) {
|
|
8086
8096
|
let source = "^";
|
|
8087
8097
|
for (let index = 0; index < pattern.length; index++) {
|
|
@@ -8094,6 +8104,8 @@ function globToRegExp(pattern) {
|
|
|
8094
8104
|
} else {
|
|
8095
8105
|
source += "[^/]*";
|
|
8096
8106
|
}
|
|
8107
|
+
} else if (char === "?") {
|
|
8108
|
+
source += "[^/]";
|
|
8097
8109
|
} else {
|
|
8098
8110
|
source += char.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
8099
8111
|
}
|
|
@@ -8163,8 +8175,6 @@ function assertDirectoryComponent(field, value) {
|
|
|
8163
8175
|
}
|
|
8164
8176
|
function snapshotNotesIdentity(value) {
|
|
8165
8177
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("notes context must be a plain object");
|
|
8166
|
-
const prototype = Object.getPrototypeOf(value);
|
|
8167
|
-
if (prototype !== Object.prototype && prototype !== null) throw new TypeError("notes context must be a plain object");
|
|
8168
8178
|
const homeValue = requireString("home", value.home);
|
|
8169
8179
|
const sessionId = requireString("sessionId", value.sessionId);
|
|
8170
8180
|
const projectKey2 = requireString("projectKey", value.projectKey);
|
|
@@ -8236,10 +8246,6 @@ async function walkMarkdown(dir, base = dir) {
|
|
|
8236
8246
|
}
|
|
8237
8247
|
return paths;
|
|
8238
8248
|
}
|
|
8239
|
-
function matcherFor(pattern) {
|
|
8240
|
-
const normalized = assertGlobPattern(pattern);
|
|
8241
|
-
return normalized === void 0 ? void 0 : globToRegExp(normalized);
|
|
8242
|
-
}
|
|
8243
8249
|
async function homesForPattern(pattern, identity2) {
|
|
8244
8250
|
if (!pattern || !pattern.startsWith("@")) return void 0;
|
|
8245
8251
|
const head = /^@([^/]+)\//.exec(pattern)?.[1];
|
|
@@ -8261,10 +8267,6 @@ function normalizePattern(pattern, identity2) {
|
|
|
8261
8267
|
if (pattern.startsWith("@model/")) return `@models/${identity2.model}/${pattern.slice("@model/".length)}`;
|
|
8262
8268
|
return pattern;
|
|
8263
8269
|
}
|
|
8264
|
-
function assertScope(value) {
|
|
8265
|
-
if (!isScope(value)) throw new NoteError("invalid_scope", `scope must be one of session, project, human, agent, model (got ${JSON.stringify(value)})`);
|
|
8266
|
-
return value;
|
|
8267
|
-
}
|
|
8268
8270
|
function assertOrigin(value) {
|
|
8269
8271
|
if (!isOrigin(value)) throw new NoteError("invalid_origin", `origin must be one of user, self, external (got ${JSON.stringify(value)})`);
|
|
8270
8272
|
return value;
|
|
@@ -8277,7 +8279,8 @@ function assertWho(value) {
|
|
|
8277
8279
|
}
|
|
8278
8280
|
async function homesFor(identity2, opts) {
|
|
8279
8281
|
if (opts.scope !== void 0) {
|
|
8280
|
-
|
|
8282
|
+
if (!isScope(opts.scope)) throw new NoteError("invalid_scope", `scope must be one of session, project, human, agent, model (got ${JSON.stringify(opts.scope)})`);
|
|
8283
|
+
const scope = opts.scope;
|
|
8281
8284
|
if (opts.who !== void 0) {
|
|
8282
8285
|
const who = assertWho(opts.who);
|
|
8283
8286
|
if (scope !== "agent" && scope !== "model") throw new NoteError("invalid_scope", "who is only valid with agent or model scope");
|
|
@@ -8345,12 +8348,6 @@ function assertWritableHome(scope, who, identity2) {
|
|
|
8345
8348
|
const home = scope === "agent" ? `@agents/${who}/` : `@models/${who}/`;
|
|
8346
8349
|
throw new NoteError("invalid_scope", `${home} is someone else's home; you can write to this session, @project/, @human/, @self/, or @model/.`);
|
|
8347
8350
|
}
|
|
8348
|
-
function accessedMeta(meta, scope, now) {
|
|
8349
|
-
const next = { ...meta, scope };
|
|
8350
|
-
next.lastAccessed = now;
|
|
8351
|
-
next.accessCount = (typeof next.accessCount === "number" ? next.accessCount : 0) + 1;
|
|
8352
|
-
return next;
|
|
8353
|
-
}
|
|
8354
8351
|
function createNotesStore(input) {
|
|
8355
8352
|
const identity2 = snapshotNotesIdentity(input);
|
|
8356
8353
|
async function write(address, content, options = {}) {
|
|
@@ -8359,7 +8356,7 @@ function createNotesStore(input) {
|
|
|
8359
8356
|
assertWritablePath(destination.path);
|
|
8360
8357
|
const scope = destination.scope;
|
|
8361
8358
|
assertWritableHome(scope, destination.who, identity2);
|
|
8362
|
-
const origin = assertOrigin(stableOptions.origin
|
|
8359
|
+
const origin = stableOptions.origin === void 0 ? void 0 : assertOrigin(stableOptions.origin);
|
|
8363
8360
|
const path = physicalPath(scope, destination.path, identity2, destination.who);
|
|
8364
8361
|
return withPathQueue(path, async () => {
|
|
8365
8362
|
const now = writeStamp();
|
|
@@ -8369,7 +8366,7 @@ function createNotesStore(input) {
|
|
|
8369
8366
|
const outcome = existing === void 0 ? "created" : existing.crumpledAt === void 0 ? "overwrote" : "uncrumpled";
|
|
8370
8367
|
const meta = existing ?? {
|
|
8371
8368
|
scope,
|
|
8372
|
-
origin,
|
|
8369
|
+
origin: origin ?? "self",
|
|
8373
8370
|
createdAt: now,
|
|
8374
8371
|
updatedAt: now,
|
|
8375
8372
|
lastAccessed: now,
|
|
@@ -8377,7 +8374,7 @@ function createNotesStore(input) {
|
|
|
8377
8374
|
...scope === "session" ? { project: identity2.projectKey } : {}
|
|
8378
8375
|
};
|
|
8379
8376
|
meta.scope = scope;
|
|
8380
|
-
meta.origin = origin;
|
|
8377
|
+
if (origin !== void 0) meta.origin = origin;
|
|
8381
8378
|
delete meta.crumpledAt;
|
|
8382
8379
|
meta.updatedAt = now;
|
|
8383
8380
|
const serialized = serializeNote(meta, cleanBody);
|
|
@@ -8395,7 +8392,7 @@ function createNotesStore(input) {
|
|
|
8395
8392
|
if (raw === void 0) return void 0;
|
|
8396
8393
|
const now = Date.now();
|
|
8397
8394
|
const parsed = parseNote(raw, now);
|
|
8398
|
-
const meta =
|
|
8395
|
+
const meta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
|
|
8399
8396
|
await atomicWrite(path, serializeNote(meta, parsed.body));
|
|
8400
8397
|
return { meta, body: parsed.body, resolvedScope: scope };
|
|
8401
8398
|
});
|
|
@@ -8486,7 +8483,9 @@ function createNotesStore(input) {
|
|
|
8486
8483
|
}));
|
|
8487
8484
|
}
|
|
8488
8485
|
async function* scan(options, status) {
|
|
8489
|
-
const
|
|
8486
|
+
const pattern = normalizePattern(options.glob, identity2);
|
|
8487
|
+
const normalized = assertGlobPattern(pattern);
|
|
8488
|
+
const matcher = normalized === void 0 ? void 0 : globToRegExp(normalized);
|
|
8490
8489
|
let homes;
|
|
8491
8490
|
try {
|
|
8492
8491
|
homes = await homesFor(identity2, options);
|
|
@@ -8498,24 +8497,31 @@ function createNotesStore(input) {
|
|
|
8498
8497
|
for (const home of homes) {
|
|
8499
8498
|
const scope = home.scope;
|
|
8500
8499
|
const root = scopeDir(scope, identity2, home.who);
|
|
8501
|
-
|
|
8500
|
+
let paths;
|
|
8502
8501
|
try {
|
|
8503
|
-
|
|
8504
|
-
if (matcher && !matcher.test(canonicalAddressFor(identity2, scope, path, home.who))) continue;
|
|
8505
|
-
const address = addressFor(identity2, scope, path, home.who);
|
|
8506
|
-
const fullPath = join2(root, path);
|
|
8507
|
-
const raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
|
|
8508
|
-
const { meta, body } = parseNote(raw);
|
|
8509
|
-
meta.scope = scope;
|
|
8510
|
-
if (meta.crumpledAt !== void 0 !== (options.crumpled === true)) continue;
|
|
8511
|
-
homeRows.push({ address, scope, path, meta, body });
|
|
8512
|
-
}
|
|
8502
|
+
paths = await walkMarkdown(root);
|
|
8513
8503
|
} catch (error) {
|
|
8514
8504
|
if (!status || !isFilesystemError(error)) throw error;
|
|
8515
8505
|
status.homesUnavailable.push(addressFor(identity2, scope, "", home.who).replace(/\/$/, "") || "session");
|
|
8516
8506
|
continue;
|
|
8517
8507
|
}
|
|
8518
|
-
for (const
|
|
8508
|
+
for (const path of paths) {
|
|
8509
|
+
if (matcher && !matcher.test(canonicalAddressFor(identity2, scope, path, home.who))) continue;
|
|
8510
|
+
const address = addressFor(identity2, scope, path, home.who);
|
|
8511
|
+
const fullPath = join2(root, path);
|
|
8512
|
+
let raw;
|
|
8513
|
+
try {
|
|
8514
|
+
raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
|
|
8515
|
+
} catch (error) {
|
|
8516
|
+
if (!status || !isFilesystemError(error)) throw error;
|
|
8517
|
+
status.homesUnavailable.push(address);
|
|
8518
|
+
continue;
|
|
8519
|
+
}
|
|
8520
|
+
const { meta, body } = parseNote(raw);
|
|
8521
|
+
meta.scope = scope;
|
|
8522
|
+
if (meta.crumpledAt !== void 0 !== (options.crumpled === true)) continue;
|
|
8523
|
+
yield { address, scope, path, meta, body };
|
|
8524
|
+
}
|
|
8519
8525
|
}
|
|
8520
8526
|
}
|
|
8521
8527
|
async function list(options = {}) {
|
|
@@ -8567,9 +8573,6 @@ var TOOL_OUTPUT_MAX_BYTES = 32 * 1024;
|
|
|
8567
8573
|
var TOOL_OUTPUT_LIMIT = `${TOOL_OUTPUT_MAX_BYTES / 1024} KB`;
|
|
8568
8574
|
var DEFAULT_READ_WINDOW_CHARS = 12e3;
|
|
8569
8575
|
var MAX_READ_WINDOW_CHARS = 5e4;
|
|
8570
|
-
function withinTextBudget(text, budget = TOOL_OUTPUT_MAX_BYTES) {
|
|
8571
|
-
return Buffer.byteLength(text, "utf8") <= budget;
|
|
8572
|
-
}
|
|
8573
8576
|
function prefixFit(text, fits) {
|
|
8574
8577
|
if (fits(text)) return text;
|
|
8575
8578
|
const chars = Array.from(text);
|
|
@@ -8592,12 +8595,10 @@ function success(data) {
|
|
|
8592
8595
|
return { ok: true, data };
|
|
8593
8596
|
}
|
|
8594
8597
|
var ERROR_MESSAGE_MAX_CHARS = 2e3;
|
|
8595
|
-
function boundedMessage(message) {
|
|
8596
|
-
const chars = Array.from(message);
|
|
8597
|
-
return chars.length <= ERROR_MESSAGE_MAX_CHARS ? message : `${chars.slice(0, ERROR_MESSAGE_MAX_CHARS).join("")}\u2026[truncated ${chars.length - ERROR_MESSAGE_MAX_CHARS} chars]`;
|
|
8598
|
-
}
|
|
8599
8598
|
function failure(code, message) {
|
|
8600
|
-
|
|
8599
|
+
const chars = Array.from(message);
|
|
8600
|
+
const bounded = chars.length <= ERROR_MESSAGE_MAX_CHARS ? message : `${chars.slice(0, ERROR_MESSAGE_MAX_CHARS).join("")}\u2026[truncated ${chars.length - ERROR_MESSAGE_MAX_CHARS} chars]`;
|
|
8601
|
+
return { ok: false, error: { code, message: bounded } };
|
|
8601
8602
|
}
|
|
8602
8603
|
var WireErrorSchema = typebox_exports.Object({ error: typebox_exports.String(), code: typebox_exports.String() }, { additionalProperties: false });
|
|
8603
8604
|
function wireResult(result) {
|
|
@@ -8615,7 +8616,7 @@ function structuredBytes(value) {
|
|
|
8615
8616
|
return Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
8616
8617
|
}
|
|
8617
8618
|
function fitsResult(result, render) {
|
|
8618
|
-
return
|
|
8619
|
+
return Buffer.byteLength(render(result), "utf8") <= TOOL_OUTPUT_MAX_BYTES && structuredBytes(wireResult(result)) <= TOOL_OUTPUT_MAX_BYTES;
|
|
8619
8620
|
}
|
|
8620
8621
|
var TextWindowSchema = typebox_exports.Object({
|
|
8621
8622
|
text: typebox_exports.String(),
|
|
@@ -8631,26 +8632,20 @@ function readTextWindow(text, offset, limit, makeData, render) {
|
|
|
8631
8632
|
const requested = offset ?? 0;
|
|
8632
8633
|
const start = requested < 0 ? Math.max(0, chars.length + requested) : requested;
|
|
8633
8634
|
const requestedChars = limit ?? DEFAULT_READ_WINDOW_CHARS;
|
|
8634
|
-
const range = Math.min(requestedChars, chars.length - start);
|
|
8635
|
-
const window = (
|
|
8636
|
-
const end = start +
|
|
8635
|
+
const range = Math.max(0, Math.min(requestedChars, chars.length - start));
|
|
8636
|
+
const window = (delivered2) => {
|
|
8637
|
+
const end = start + delivered2;
|
|
8637
8638
|
return {
|
|
8638
8639
|
text: chars.slice(start, end).join(""),
|
|
8639
8640
|
total_chars: chars.length,
|
|
8640
8641
|
next_offset_chars: end < chars.length ? end : null
|
|
8641
8642
|
};
|
|
8642
8643
|
};
|
|
8643
|
-
const fits = (
|
|
8644
|
+
const fits = (delivered2) => fitsResult(success(makeData(window(delivered2))), render);
|
|
8644
8645
|
if (fits(range)) return success(makeData(window(range)));
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
const mid = Math.ceil((low + high) / 2);
|
|
8649
|
-
if (fits(mid)) low = mid;
|
|
8650
|
-
else high = mid - 1;
|
|
8651
|
-
}
|
|
8652
|
-
if (low === 0) return failure("output_too_large", `Its header alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry; no room left for the text.`);
|
|
8653
|
-
return success(makeData(window(low)));
|
|
8646
|
+
const delivered = Array.from(prefixFit(window(range).text, (candidate) => fits(Array.from(candidate).length))).length;
|
|
8647
|
+
if (delivered === 0) return failure("output_too_large", `Its header alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry; no room left for the text.`);
|
|
8648
|
+
return success(makeData(window(delivered)));
|
|
8654
8649
|
}
|
|
8655
8650
|
function renderTextWindow(window) {
|
|
8656
8651
|
const next = window.next_offset_chars;
|
|
@@ -8717,25 +8712,16 @@ var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({
|
|
|
8717
8712
|
var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
|
|
8718
8713
|
var GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
|
|
8719
8714
|
var ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
8720
|
-
function projectKeyField(scope, projectKey2) {
|
|
8721
|
-
return scope === "project" ? { project_key: projectKey2 } : {};
|
|
8722
|
-
}
|
|
8723
8715
|
function failureOf(error) {
|
|
8724
8716
|
if (error instanceof NoteError) return failure(error.code, error.message);
|
|
8725
8717
|
if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
|
|
8726
8718
|
if (isFilesystemError(error)) return failure("io_error", "notes operation failed");
|
|
8727
8719
|
throw error;
|
|
8728
8720
|
}
|
|
8729
|
-
function byRecent(a, b) {
|
|
8730
|
-
return b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address);
|
|
8731
|
-
}
|
|
8732
8721
|
var NORMALIZED_META_KEYS = /* @__PURE__ */ new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project"]);
|
|
8733
8722
|
var MAX_METADATA_ENTRY_BYTES = 1024;
|
|
8734
8723
|
var MAX_METADATA_VERBATIM_BYTES = 2048;
|
|
8735
8724
|
var TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
|
|
8736
|
-
function extraEntryBytes(key, value) {
|
|
8737
|
-
return structuredBytes(key) + 1 + structuredBytes(value);
|
|
8738
|
-
}
|
|
8739
8725
|
var NoteMetadataSchema = typebox_exports.Object({
|
|
8740
8726
|
origin: typebox_exports.Union([...ORIGIN_VALUES]),
|
|
8741
8727
|
created_at: typebox_exports.String(),
|
|
@@ -8753,7 +8739,7 @@ function noteMetadata(meta) {
|
|
|
8753
8739
|
for (const [key, value] of Object.entries(meta)) {
|
|
8754
8740
|
if (NORMALIZED_META_KEYS.has(key) || value === void 0) continue;
|
|
8755
8741
|
if (structuredBytes(key) > MAX_METADATA_ENTRY_BYTES) continue;
|
|
8756
|
-
const entryBytes =
|
|
8742
|
+
const entryBytes = structuredBytes(key) + 1 + structuredBytes(value);
|
|
8757
8743
|
if (entryBytes > MAX_METADATA_ENTRY_BYTES || verbatimBytes + entryBytes > MAX_METADATA_VERBATIM_BYTES) {
|
|
8758
8744
|
put(key, TOO_LARGE_EXTRA_VALUE);
|
|
8759
8745
|
continue;
|
|
@@ -8851,7 +8837,7 @@ function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
8851
8837
|
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable homes is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer homes.`);
|
|
8852
8838
|
}
|
|
8853
8839
|
function listedFile(row, identity2) {
|
|
8854
|
-
return { address: row.address, ...
|
|
8840
|
+
return { address: row.address, ...row.scope === "project" ? { project_key: identity2.projectKey } : {}, updated_at: localIso(row.meta.updatedAt), ...row.meta.crumpledAt === void 0 ? {} : { crumpled_at: row.meta.crumpledAt } };
|
|
8855
8841
|
}
|
|
8856
8842
|
var notesWriteParameters = typebox_exports.Object({ address: typebox_exports.String(), content: typebox_exports.String(), origin: ORIGIN }, { additionalProperties: false });
|
|
8857
8843
|
function renderWriteData(data) {
|
|
@@ -9019,7 +9005,7 @@ var notesSearch = {
|
|
|
9019
9005
|
async execute(params, identity2) {
|
|
9020
9006
|
try {
|
|
9021
9007
|
const { rows, status } = await createNotesStore(identity2).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? void 0, crumpled: params.crumpled });
|
|
9022
|
-
const files = rows.sort(
|
|
9008
|
+
const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map((row) => ({
|
|
9023
9009
|
...listedFile(row, identity2),
|
|
9024
9010
|
matches: row.matches.slice(0, params.max_matches_per_file).map((match) => ({ line: match.line, text: match.text, offset_chars: match.offsetChars }))
|
|
9025
9011
|
}));
|
|
@@ -9039,13 +9025,9 @@ var NOTES_HOMES = [
|
|
|
9039
9025
|
{ scope: "agent", label: "@self" },
|
|
9040
9026
|
{ scope: "model", label: "@model" }
|
|
9041
9027
|
];
|
|
9042
|
-
function queryForScope(scope) {
|
|
9043
|
-
if (scope === "agent" || scope === "model") return { scope };
|
|
9044
|
-
return { scope };
|
|
9045
|
-
}
|
|
9046
9028
|
async function loadNotesSnapshot(identity2, openedAt, loadHome) {
|
|
9047
9029
|
const store = createNotesStore(identity2);
|
|
9048
|
-
const load = loadHome ?? ((scope) => store.list(
|
|
9030
|
+
const load = loadHome ?? ((scope) => store.list({ scope }));
|
|
9049
9031
|
const homes = /* @__PURE__ */ new Map();
|
|
9050
9032
|
const unavailable = [];
|
|
9051
9033
|
for (const home of NOTES_HOMES) {
|
|
@@ -9098,7 +9080,7 @@ Still a tie? *shrugs* You've got a brain. Use it.
|
|
|
9098
9080
|
|
|
9099
9081
|
Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like \`read\`, \`write\`, \`edit\`, or \`bash\`.
|
|
9100
9082
|
|
|
9101
|
-
\`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each
|
|
9083
|
+
\`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each may carry a short Cheatsheet of rules that always apply (about 5 lines); the rest is the note index, with addresses and gists for lookup. Keep each one current.
|
|
9102
9084
|
${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
|
|
9103
9085
|
function renderProtocolBlock(tools) {
|
|
9104
9086
|
const names = {
|
|
@@ -9112,17 +9094,6 @@ function renderProtocolBlock(tools) {
|
|
|
9112
9094
|
}
|
|
9113
9095
|
|
|
9114
9096
|
// src/boot/render.ts
|
|
9115
|
-
function identityBlock(agentName, modelName, firstWindowId, currentWindowId, previousWindowId) {
|
|
9116
|
-
const lines = [
|
|
9117
|
-
`Agent name: ${agentName} (brain: ${modelName})`,
|
|
9118
|
-
`First context window id: ${firstWindowId}`,
|
|
9119
|
-
`Current context window id: ${currentWindowId}`
|
|
9120
|
-
];
|
|
9121
|
-
if (previousWindowId) lines.push(`Previous context window id: ${previousWindowId}`);
|
|
9122
|
-
return `${CONTEXT_WINDOW_OPEN_TAG}
|
|
9123
|
-
${lines.join("\n")}
|
|
9124
|
-
${CONTEXT_WINDOW_CLOSE_TAG}`;
|
|
9125
|
-
}
|
|
9126
9097
|
function relativeTime(timestamp, now) {
|
|
9127
9098
|
const seconds = Math.trunc((timestamp - now) / 1e3);
|
|
9128
9099
|
if (seconds === 0) return "just now";
|
|
@@ -9130,9 +9101,6 @@ function relativeTime(timestamp, now) {
|
|
|
9130
9101
|
const amount = `${Math.abs(Math.trunc(seconds / size))}${unit}`;
|
|
9131
9102
|
return seconds > 0 ? `in ${amount}` : `${amount} ago`;
|
|
9132
9103
|
}
|
|
9133
|
-
function rowsFor(snapshot2, scope) {
|
|
9134
|
-
return snapshot2.homes.get(scope) ?? [];
|
|
9135
|
-
}
|
|
9136
9104
|
var FEED_TITLE_MAX_CHARS = 40;
|
|
9137
9105
|
function feedTitle(body) {
|
|
9138
9106
|
const lines = body.split("\n");
|
|
@@ -9165,7 +9133,7 @@ function notesIndex(snapshot2, tools) {
|
|
|
9165
9133
|
shelves.push(section(home.label, indent(`This drawer wouldn't open. Try \`${tools.notesList}\` again.`)));
|
|
9166
9134
|
continue;
|
|
9167
9135
|
}
|
|
9168
|
-
const rows =
|
|
9136
|
+
const rows = (snapshot2.homes.get(home.scope) ?? []).filter((row) => row.meta.crumpledAt === void 0);
|
|
9169
9137
|
const map = rows.find((row) => row.path === "MAP.md");
|
|
9170
9138
|
const fresh = rows.filter((row) => row.path !== "MAP.md").slice(0, SHELF_FRESH_LIMIT).map((row) => {
|
|
9171
9139
|
const locator = `${row.address} \xB7 ${relativeTime(row.meta.updatedAt, snapshot2.openedAt)}`;
|
|
@@ -9192,33 +9160,70 @@ function mapBodyForBoot(address, body) {
|
|
|
9192
9160
|
[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`${address}\`]`;
|
|
9193
9161
|
}
|
|
9194
9162
|
function renderBootBlock(data) {
|
|
9195
|
-
const
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9163
|
+
const lines = [
|
|
9164
|
+
`Agent name: ${data.agentName} (brain: ${data.modelName})`,
|
|
9165
|
+
`First context window id: ${data.firstWindowId}`,
|
|
9166
|
+
`Current context window id: ${data.currentWindowId}`,
|
|
9167
|
+
...data.previousWindowId ? [`Previous context window id: ${data.previousWindowId}`] : []
|
|
9168
|
+
];
|
|
9169
|
+
const identity2 = `${CONTEXT_WINDOW_OPEN_TAG}
|
|
9170
|
+
${lines.join("\n")}
|
|
9171
|
+
${CONTEXT_WINDOW_CLOSE_TAG}`;
|
|
9172
|
+
return [identity2, renderProtocolBlock(data.tools), notesIndex(data.notes, data.tools)].join("\n\n");
|
|
9200
9173
|
}
|
|
9201
9174
|
|
|
9202
9175
|
// src/budget/text.ts
|
|
9176
|
+
var GUIDANCE_OPEN_TAG = "<context_window_guidance>";
|
|
9177
|
+
var GUIDANCE_CLOSE_TAG = "</context_window_guidance>";
|
|
9203
9178
|
var CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
|
|
9204
9179
|
var WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
|
|
9205
9180
|
var WARNING_PROMPT = `${WARNING_BODY}
|
|
9206
9181
|
When the notes are ready, call \`clear_memory\` to reset now instead of being cut off mid-task.`;
|
|
9182
|
+
var WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}
|
|
9183
|
+
${WARNING_PROMPT}
|
|
9184
|
+
${GUIDANCE_CLOSE_TAG}`;
|
|
9207
9185
|
var CLAUDE_WARNING_PROMPT = `${WARNING_BODY}
|
|
9208
9186
|
When the notes are ready, end your turn; the reset runs after it.`;
|
|
9209
9187
|
|
|
9210
9188
|
// src/budget/constants.ts
|
|
9211
9189
|
var WARNING_RUNWAY_TOKENS = 16384;
|
|
9212
9190
|
|
|
9191
|
+
// src/budget/parse.ts
|
|
9192
|
+
function numberOf(value) {
|
|
9193
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
9194
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
9195
|
+
const parsed = Number(value);
|
|
9196
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
9197
|
+
}
|
|
9198
|
+
return void 0;
|
|
9199
|
+
}
|
|
9200
|
+
function positiveNumber(value) {
|
|
9201
|
+
const parsed = numberOf(value);
|
|
9202
|
+
return parsed !== void 0 && parsed > 0 ? parsed : void 0;
|
|
9203
|
+
}
|
|
9204
|
+
function positiveInteger(value) {
|
|
9205
|
+
const parsed = numberOf(value);
|
|
9206
|
+
return parsed !== void 0 && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
9207
|
+
}
|
|
9208
|
+
function percent(value) {
|
|
9209
|
+
const parsed = numberOf(value);
|
|
9210
|
+
return parsed !== void 0 && parsed > 0 && parsed <= 100 ? parsed : void 0;
|
|
9211
|
+
}
|
|
9212
|
+
function presenceFlag(value) {
|
|
9213
|
+
if (typeof value !== "string") return false;
|
|
9214
|
+
const text = value.trim().toLowerCase();
|
|
9215
|
+
return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off";
|
|
9216
|
+
}
|
|
9217
|
+
|
|
9213
9218
|
// src/settings.ts
|
|
9214
9219
|
var NOTESOUP_SETTINGS_KEY = "notesoup";
|
|
9215
|
-
function
|
|
9220
|
+
function isPlainObject(value) {
|
|
9216
9221
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9217
9222
|
}
|
|
9218
9223
|
function notesoupSettings(settings2) {
|
|
9219
|
-
if (!
|
|
9224
|
+
if (!isPlainObject(settings2)) return {};
|
|
9220
9225
|
const value = settings2[NOTESOUP_SETTINGS_KEY];
|
|
9221
|
-
return
|
|
9226
|
+
return isPlainObject(value) ? value : {};
|
|
9222
9227
|
}
|
|
9223
9228
|
function mergeNotesoupSettings(globalSettings, projectSettings) {
|
|
9224
9229
|
const merged = { ...notesoupSettings(globalSettings), ...notesoupSettings(projectSettings) };
|
|
@@ -9234,68 +9239,40 @@ function mergeNotesoupSettings(globalSettings, projectSettings) {
|
|
|
9234
9239
|
var CLAUDE_AUTOCOMPACT_BUFFER_TOKENS = 13e3;
|
|
9235
9240
|
var CLAUDE_OUTPUT_RESERVE_TOKENS = 2e4;
|
|
9236
9241
|
var DEFAULT_CLAUDE_RESET_MARGIN_TOKENS = 8192;
|
|
9242
|
+
var MIN_POINT_TOKENS = 1;
|
|
9243
|
+
var MIN_POINT_PERCENT = 0.1;
|
|
9237
9244
|
var ASSUMED_WINDOW_TOKENS = 2e5;
|
|
9238
|
-
function
|
|
9239
|
-
return typeof
|
|
9240
|
-
}
|
|
9241
|
-
function numberOf(value) {
|
|
9242
|
-
if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
|
|
9243
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
9244
|
-
const parsed = Number(value);
|
|
9245
|
-
return Number.isFinite(parsed) ? parsed : void 0;
|
|
9246
|
-
}
|
|
9247
|
-
return void 0;
|
|
9248
|
-
}
|
|
9249
|
-
function positiveNumberOf(value) {
|
|
9250
|
-
const parsed = numberOf(value);
|
|
9251
|
-
return parsed !== void 0 && parsed > 0 ? parsed : void 0;
|
|
9252
|
-
}
|
|
9253
|
-
function positiveIntegerOf(value) {
|
|
9254
|
-
const parsed = numberOf(value);
|
|
9255
|
-
return parsed !== void 0 && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
9256
|
-
}
|
|
9257
|
-
function percentOf(value) {
|
|
9258
|
-
const parsed = numberOf(value);
|
|
9259
|
-
return parsed !== void 0 && parsed > 0 && parsed <= 100 ? parsed : void 0;
|
|
9260
|
-
}
|
|
9261
|
-
function flagOn(value) {
|
|
9262
|
-
if (typeof value !== "string") return false;
|
|
9263
|
-
const text = value.trim().toLowerCase();
|
|
9264
|
-
return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off";
|
|
9265
|
-
}
|
|
9266
|
-
function settingFlag(settings2, key) {
|
|
9267
|
-
if (!isObject(settings2)) return void 0;
|
|
9268
|
-
const value = settings2[key];
|
|
9269
|
-
return typeof value === "boolean" ? value : void 0;
|
|
9245
|
+
function settingFlag(settings2) {
|
|
9246
|
+
return isPlainObject(settings2) && typeof settings2.autoCompactEnabled === "boolean" ? settings2.autoCompactEnabled : void 0;
|
|
9270
9247
|
}
|
|
9271
9248
|
function configuredWindow(settings2, env, model) {
|
|
9272
9249
|
const windows = [];
|
|
9273
|
-
const fromEnv =
|
|
9250
|
+
const fromEnv = positiveNumber(env.autoCompactWindow);
|
|
9274
9251
|
if (fromEnv !== void 0) windows.push(fromEnv);
|
|
9275
|
-
if (typeof model === "string" && model.length > 0 &&
|
|
9276
|
-
const modelSettings =
|
|
9252
|
+
if (typeof model === "string" && model.length > 0 && isPlainObject(settings2)) {
|
|
9253
|
+
const modelSettings = isPlainObject(settings2.modelSettings) ? settings2.modelSettings : {};
|
|
9277
9254
|
const perModel = modelSettings[model];
|
|
9278
|
-
if (
|
|
9279
|
-
const value =
|
|
9255
|
+
if (isPlainObject(perModel)) {
|
|
9256
|
+
const value = positiveNumber(perModel.autoCompactWindow);
|
|
9280
9257
|
if (value !== void 0) windows.push(value);
|
|
9281
9258
|
}
|
|
9282
9259
|
}
|
|
9283
|
-
if (
|
|
9284
|
-
const value =
|
|
9260
|
+
if (isPlainObject(settings2)) {
|
|
9261
|
+
const value = positiveNumber(settings2.autoCompactWindow);
|
|
9285
9262
|
if (value !== void 0) windows.push(value);
|
|
9286
9263
|
}
|
|
9287
9264
|
return windows.length === 0 ? void 0 : Math.min(...windows);
|
|
9288
9265
|
}
|
|
9289
9266
|
function tokenLimits(source, autoCompact, native, resetMargin, warningRunway) {
|
|
9290
9267
|
const tokens = Math.max(0, Math.floor(native));
|
|
9291
|
-
const reset = Math.max(
|
|
9268
|
+
const reset = Math.max(MIN_POINT_TOKENS, tokens - resetMargin);
|
|
9292
9269
|
return {
|
|
9293
9270
|
source,
|
|
9294
9271
|
autoCompact,
|
|
9295
9272
|
unit: "tokens",
|
|
9296
9273
|
native: tokens,
|
|
9297
9274
|
reset,
|
|
9298
|
-
warn: Math.max(
|
|
9275
|
+
warn: Math.max(MIN_POINT_TOKENS, reset - warningRunway),
|
|
9299
9276
|
resetMargin,
|
|
9300
9277
|
warningRunway
|
|
9301
9278
|
};
|
|
@@ -9303,40 +9280,40 @@ function tokenLimits(source, autoCompact, native, resetMargin, warningRunway) {
|
|
|
9303
9280
|
function percentLimits(autoCompact, pct, resetMargin, warningRunway) {
|
|
9304
9281
|
const base = 100 * (1 - (CLAUDE_OUTPUT_RESERVE_TOKENS + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) / ASSUMED_WINDOW_TOKENS);
|
|
9305
9282
|
const native = pct === void 0 ? base : Math.min(pct, base);
|
|
9306
|
-
const reset = Math.max(
|
|
9283
|
+
const reset = Math.max(MIN_POINT_PERCENT, native - resetMargin / ASSUMED_WINDOW_TOKENS * 100);
|
|
9307
9284
|
return {
|
|
9308
9285
|
source: "percent",
|
|
9309
9286
|
autoCompact,
|
|
9310
9287
|
unit: "percent",
|
|
9311
9288
|
native,
|
|
9312
9289
|
reset,
|
|
9313
|
-
warn: Math.max(
|
|
9290
|
+
warn: Math.max(MIN_POINT_PERCENT, reset - warningRunway / ASSUMED_WINDOW_TOKENS * 100),
|
|
9314
9291
|
resetMargin,
|
|
9315
9292
|
warningRunway
|
|
9316
9293
|
};
|
|
9317
9294
|
}
|
|
9318
9295
|
function resolveClaudeLimits(facts) {
|
|
9319
|
-
const root =
|
|
9320
|
-
const usage =
|
|
9321
|
-
const breakdown =
|
|
9322
|
-
const env =
|
|
9296
|
+
const root = isPlainObject(facts) ? facts : {};
|
|
9297
|
+
const usage = isPlainObject(root.usage) ? root.usage : {};
|
|
9298
|
+
const breakdown = isPlainObject(root.breakdown) ? root.breakdown : {};
|
|
9299
|
+
const env = isPlainObject(root.env) ? root.env : {};
|
|
9323
9300
|
const settings2 = root.settings;
|
|
9324
9301
|
const margins = mergeNotesoupSettings(settings2, void 0);
|
|
9325
|
-
const resetMargin =
|
|
9326
|
-
const warningRunway =
|
|
9327
|
-
const autoCompact = settingFlag(settings2
|
|
9328
|
-
const pct =
|
|
9329
|
-
const threshold =
|
|
9302
|
+
const resetMargin = positiveInteger(margins.resetMarginTokens) ?? DEFAULT_CLAUDE_RESET_MARGIN_TOKENS;
|
|
9303
|
+
const warningRunway = positiveInteger(margins.warningRunwayTokens) ?? WARNING_RUNWAY_TOKENS;
|
|
9304
|
+
const autoCompact = settingFlag(settings2) !== false && !presenceFlag(env.disableAutoCompact) && breakdown.isAutoCompactEnabled !== false;
|
|
9305
|
+
const pct = percent(env.pctOverride);
|
|
9306
|
+
const threshold = positiveNumber(breakdown.autoCompactThreshold);
|
|
9330
9307
|
if (autoCompact && threshold !== void 0) {
|
|
9331
9308
|
const native = pct === void 0 ? threshold : Math.min(Math.floor((threshold + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) * (pct / 100)), threshold);
|
|
9332
9309
|
if (native > 0) return tokenLimits("auto-compact", true, native, resetMargin, warningRunway);
|
|
9333
9310
|
}
|
|
9334
|
-
const window =
|
|
9311
|
+
const window = positiveNumber(usage.window);
|
|
9335
9312
|
if (window !== void 0) {
|
|
9336
9313
|
const configured = configuredWindow(settings2, env, breakdown.model);
|
|
9337
9314
|
const effective = Math.min(configured ?? window, window);
|
|
9338
9315
|
const native = autoCompact ? effective - CLAUDE_OUTPUT_RESERVE_TOKENS - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS : effective - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
9339
|
-
|
|
9316
|
+
return tokenLimits("window", autoCompact, native, resetMargin, warningRunway);
|
|
9340
9317
|
}
|
|
9341
9318
|
return percentLimits(autoCompact, pct, resetMargin, warningRunway);
|
|
9342
9319
|
}
|
|
@@ -9356,9 +9333,6 @@ function paramProblem(schema, params) {
|
|
|
9356
9333
|
const field = first.instancePath.replace(/^\//, "").replaceAll("/", ".");
|
|
9357
9334
|
return `${field ? `${field} ` : ""}${first.message}${extra}`;
|
|
9358
9335
|
}
|
|
9359
|
-
function jsonValue(value) {
|
|
9360
|
-
return JSON.parse(JSON.stringify(value));
|
|
9361
|
-
}
|
|
9362
9336
|
function boundOperation(operation, ...rest) {
|
|
9363
9337
|
return {
|
|
9364
9338
|
description: operation.description,
|
|
@@ -9383,7 +9357,7 @@ var OPERATIONS = {
|
|
|
9383
9357
|
async function dispatch(request) {
|
|
9384
9358
|
if (!request || typeof request !== "object" || Array.isArray(request)) throw new Error("malformed request");
|
|
9385
9359
|
const value = request;
|
|
9386
|
-
if (value.op === "schemas") return TOOL_NAMES.map((name) => ({ name, description: OPERATIONS[name].description, inputSchema:
|
|
9360
|
+
if (value.op === "schemas") return TOOL_NAMES.map((name) => ({ name, description: OPERATIONS[name].description, inputSchema: JSON.parse(JSON.stringify(OPERATIONS[name].parameters)) }));
|
|
9387
9361
|
if (value.op === "texts") return { warning: CLAUDE_WARNING_PROMPT, continuation: CONTINUATION, wipeSentence: CLAUDE_WIPE_SENTENCE };
|
|
9388
9362
|
if (value.op === "limits") return resolveClaudeLimits(value.facts);
|
|
9389
9363
|
if (value.op === "tool") {
|
|
@@ -9415,7 +9389,7 @@ async function handleLine(line) {
|
|
|
9415
9389
|
return JSON.stringify({ ok: false, error: safeError(error) });
|
|
9416
9390
|
}
|
|
9417
9391
|
}
|
|
9418
|
-
if (process.argv[1] && pathToFileURL(
|
|
9392
|
+
if (process.argv[1] && pathToFileURL(realpathSync2(process.argv[1])).href === import.meta.url) {
|
|
9419
9393
|
process.stdin.setEncoding("utf8");
|
|
9420
9394
|
let input = "";
|
|
9421
9395
|
process.stdin.on("data", (chunk) => {
|