acp-kernel 0.0.21 → 0.0.22
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/boundaries.d.ts +13 -0
- package/dist/boundaries.d.ts.map +1 -1
- package/dist/compress.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +152 -49
- package/dist/index.js.map +1 -1
- package/dist/nudge-text.d.ts +2 -1
- package/dist/nudge-text.d.ts.map +1 -1
- package/dist/prompts.d.ts +48 -0
- package/dist/prompts.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/boundaries.d.ts
CHANGED
|
@@ -6,6 +6,19 @@ export interface ParsedBoundary {
|
|
|
6
6
|
raw: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function parseBoundary(ref: string): ParsedBoundary | null;
|
|
9
|
+
/**
|
|
10
|
+
* Thrown when a boundary ref parses but cannot be anchored in the visible
|
|
11
|
+
* context. `kind` distinguishes a ref that never existed ("unknown", e.g. a
|
|
12
|
+
* typo or a ref from another session) from one that was consumed by an
|
|
13
|
+
* existing block ("consumed", messages hidden by prune). `endpoint` names the
|
|
14
|
+
* failing side of the range so callers can attribute the error precisely.
|
|
15
|
+
*/
|
|
16
|
+
export declare class BoundaryNotFoundError extends Error {
|
|
17
|
+
readonly code = "BOUNDARY_NOT_FOUND";
|
|
18
|
+
readonly kind: "unknown" | "consumed";
|
|
19
|
+
readonly endpoint: "start" | "end";
|
|
20
|
+
constructor(kind: "unknown" | "consumed", endpoint: "start" | "end", message: string);
|
|
21
|
+
}
|
|
9
22
|
export interface ResolveBoundariesInput {
|
|
10
23
|
startRef: string;
|
|
11
24
|
endRef: string;
|
package/dist/boundaries.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundaries.d.ts","sourceRoot":"","sources":["../src/boundaries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,WA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AI,wBAAwB;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,KAAK,CAAC;gBAGjC,IAAI,EAAE,SAAS,GAAG,UAAU,EAC5B,QAAQ,EAAE,OAAO,GAAG,KAAK,EACzB,OAAO,EAAE,MAAM;CAQlB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,sBAAsB,GAC5B,aAAa,CAoDf;AA6DD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EAAE,EACb,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,MAAM,GAAG,IAAI,CASf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,gBAAgB,CAMzE"}
|
package/dist/compress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,kBAAkB,EACnB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAapB,OAAO,KAAK,EAAE,cAAc,EAA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,MAAM,CAAC;KAC1B,EAAE,CAAC;IACJ,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACnC;AAsBD,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAwQ7D;AA8sBD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,12 +6,14 @@ export { defaultConfig, validateConfig } from "./config.js";
|
|
|
6
6
|
export { assignRefs, highestUsedIndex, emptyRefMap, indexToRef, refToIndex, refForRaw, rawForRef, BLOCKED_REF, } from "./refs.js";
|
|
7
7
|
export { prune, SUMMARY_HEADER } from "./prune.js";
|
|
8
8
|
export { syncBlocks } from "./sync.js";
|
|
9
|
-
export { resolveBoundaries, parseBoundary } from "./boundaries.js";
|
|
9
|
+
export { resolveBoundaries, parseBoundary, BoundaryNotFoundError } from "./boundaries.js";
|
|
10
10
|
export { defaultCountTokens, estimateTokensFast, createBpeTokenizer } from "./tokenize.js";
|
|
11
11
|
export type { TokenCountFn } from "./tokenize.js";
|
|
12
12
|
export { renderNudgeText, formatRanges } from "./nudge-text.js";
|
|
13
13
|
export type { NudgeVoice, RenderedNudge } from "./nudge-text.js";
|
|
14
14
|
export { COMPRESS_PHILOSOPHY, HOW_TO_COMPRESS_RULES, TIER2_DISTILL_RULES, TIER3_CONDENSE_RULES } from "./compression-rules.js";
|
|
15
|
+
export { defaultPrompts, resolvePrompts } from "./prompts.js";
|
|
16
|
+
export type { Prompts, ResolvePromptsOptions } from "./prompts.js";
|
|
15
17
|
export { truncateLargeToolOutputs } from "./truncate-tools.js";
|
|
16
18
|
export type { TruncateOptions, TruncateResult } from "./truncate-tools.js";
|
|
17
19
|
export { parseBlockIdArg, findBlocksOverlappingMessages, findActiveAncestor, deactivateBlock, buildRestoredContentPreview, collectBlockContent, } from "./decompress.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EACV,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,SAAS,EACT,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,O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E,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC3F,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtF,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzM,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzI,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EACL,WAAW,EACX,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -382,6 +382,18 @@ function parseBoundary(ref) {
|
|
|
382
382
|
}
|
|
383
383
|
return null;
|
|
384
384
|
}
|
|
385
|
+
var BoundaryNotFoundError = class extends Error {
|
|
386
|
+
code = "BOUNDARY_NOT_FOUND";
|
|
387
|
+
kind;
|
|
388
|
+
endpoint;
|
|
389
|
+
constructor(kind, endpoint, message) {
|
|
390
|
+
super(message);
|
|
391
|
+
this.name = "BoundaryNotFoundError";
|
|
392
|
+
this.code = "BOUNDARY_NOT_FOUND";
|
|
393
|
+
this.kind = kind;
|
|
394
|
+
this.endpoint = endpoint;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
385
397
|
function resolveBoundaries(input) {
|
|
386
398
|
const start = parseBoundary(input.startRef);
|
|
387
399
|
const end = parseBoundary(input.endRef);
|
|
@@ -394,13 +406,8 @@ function resolveBoundaries(input) {
|
|
|
394
406
|
input.messages.forEach(
|
|
395
407
|
(message, index) => indexByRawId.set(message.id, index)
|
|
396
408
|
);
|
|
397
|
-
let startIndex = resolveAnchorIndex(start, input.state, indexByRawId);
|
|
398
|
-
let endIndex = resolveAnchorIndex(end, input.state, indexByRawId);
|
|
399
|
-
if (startIndex === null || endIndex === null) {
|
|
400
|
-
throw new Error(
|
|
401
|
-
`Boundary not found in visible context (likely consumed by an existing block). startId="${input.startRef}", endId="${input.endRef}".`
|
|
402
|
-
);
|
|
403
|
-
}
|
|
409
|
+
let startIndex = resolveAnchorIndex(start, input.state, indexByRawId, "start");
|
|
410
|
+
let endIndex = resolveAnchorIndex(end, input.state, indexByRawId, "end");
|
|
404
411
|
if (startIndex > endIndex) {
|
|
405
412
|
[startIndex, endIndex] = [endIndex, startIndex];
|
|
406
413
|
}
|
|
@@ -431,16 +438,51 @@ function resolveBoundaries(input) {
|
|
|
431
438
|
protectedGaps
|
|
432
439
|
};
|
|
433
440
|
}
|
|
434
|
-
function resolveAnchorIndex(boundary, state, indexByRawId) {
|
|
441
|
+
function resolveAnchorIndex(boundary, state, indexByRawId, endpoint) {
|
|
442
|
+
const label = endpoint === "start" ? "startId" : "endId";
|
|
435
443
|
if (boundary.kind === "message") {
|
|
436
444
|
const rawId = state.messageRefs.byRef[boundary.raw] ?? state.messageRefs.byRef[formatPaddedRef(boundary.numericId)];
|
|
437
|
-
if (!rawId)
|
|
445
|
+
if (!rawId) {
|
|
446
|
+
throw new BoundaryNotFoundError(
|
|
447
|
+
"unknown",
|
|
448
|
+
endpoint,
|
|
449
|
+
`${label}="${boundary.raw}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
438
452
|
const index = indexByRawId.get(rawId);
|
|
439
|
-
|
|
453
|
+
if (index === void 0) {
|
|
454
|
+
throw new BoundaryNotFoundError(
|
|
455
|
+
"consumed",
|
|
456
|
+
endpoint,
|
|
457
|
+
`${label}="${boundary.raw}" not found in visible context (likely consumed by an existing block).`
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
return index;
|
|
440
461
|
}
|
|
441
462
|
const block = blockById(state, `b${boundary.numericId}`);
|
|
442
|
-
if (!block
|
|
443
|
-
|
|
463
|
+
if (!block) {
|
|
464
|
+
throw new BoundaryNotFoundError(
|
|
465
|
+
"unknown",
|
|
466
|
+
endpoint,
|
|
467
|
+
`${label}="b${boundary.numericId}" does not exist in this session (typo or wrong session) \u2014 run acp_status for current refs.`
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
if (!block.active) {
|
|
471
|
+
throw new BoundaryNotFoundError(
|
|
472
|
+
"consumed",
|
|
473
|
+
endpoint,
|
|
474
|
+
`${label}="b${boundary.numericId}" not found in visible context (block distilled/consumed by a higher-tier block).`
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
const anchor = earliestIndexOfIds(block.effectiveMessageIds, indexByRawId);
|
|
478
|
+
if (anchor === null) {
|
|
479
|
+
throw new BoundaryNotFoundError(
|
|
480
|
+
"consumed",
|
|
481
|
+
endpoint,
|
|
482
|
+
`${label}="b${boundary.numericId}" not found in visible context (block messages consumed by a higher-tier block).`
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
return anchor;
|
|
444
486
|
}
|
|
445
487
|
function formatPaddedRef(index) {
|
|
446
488
|
return `m${String(index).padStart(5, "0")}`;
|
|
@@ -1009,6 +1051,9 @@ function runPipeline(nodes, initial, ctx) {
|
|
|
1009
1051
|
}
|
|
1010
1052
|
|
|
1011
1053
|
// src/compress.ts
|
|
1054
|
+
function rangeError(spec, message) {
|
|
1055
|
+
return `range ${spec.startRef}..${spec.endRef}: ${message}`;
|
|
1056
|
+
}
|
|
1012
1057
|
function createCore(ports = {}) {
|
|
1013
1058
|
const countTokens = ports.countTokens ?? defaultCountTokens;
|
|
1014
1059
|
function applyCompression(input) {
|
|
@@ -1020,20 +1065,44 @@ function createCore(ports = {}) {
|
|
|
1020
1065
|
const warnings = [];
|
|
1021
1066
|
const protectedMessageIds = input.protectedMessageIds ?? computeProtectedRefs(input.messages, input.state, input.config, countTokens);
|
|
1022
1067
|
const preExistingCoverage = collectCoverage(state);
|
|
1023
|
-
const
|
|
1068
|
+
const classifications = /* @__PURE__ */ new Map();
|
|
1069
|
+
const classificationErrors = [];
|
|
1070
|
+
const consumedRanges = [];
|
|
1024
1071
|
for (const spec of input.ranges) {
|
|
1025
|
-
let resolved;
|
|
1026
1072
|
try {
|
|
1027
|
-
resolved = resolveBoundaries({
|
|
1073
|
+
const resolved = resolveBoundaries({
|
|
1028
1074
|
startRef: spec.startRef,
|
|
1029
1075
|
endRef: spec.endRef,
|
|
1030
1076
|
messages: input.messages,
|
|
1031
1077
|
state
|
|
1032
1078
|
});
|
|
1033
|
-
|
|
1034
|
-
|
|
1079
|
+
classifications.set(spec, { status: "ok", resolved });
|
|
1080
|
+
} catch (error) {
|
|
1081
|
+
if (error instanceof BoundaryNotFoundError) {
|
|
1082
|
+
classifications.set(
|
|
1083
|
+
spec,
|
|
1084
|
+
error.kind === "unknown" ? { status: "unknown", error } : { status: "consumed", error }
|
|
1085
|
+
);
|
|
1086
|
+
if (error.kind === "consumed") {
|
|
1087
|
+
consumedRanges.push(spec);
|
|
1088
|
+
} else {
|
|
1089
|
+
classificationErrors.push(rangeError(spec, error.message));
|
|
1090
|
+
}
|
|
1091
|
+
} else {
|
|
1092
|
+
classifications.set(spec, {
|
|
1093
|
+
status: "invalid",
|
|
1094
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
1095
|
+
});
|
|
1096
|
+
classificationErrors.push(
|
|
1097
|
+
rangeError(spec, error instanceof Error ? error.message : String(error))
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1035
1100
|
}
|
|
1036
|
-
|
|
1101
|
+
}
|
|
1102
|
+
const rangeIndexSets = [];
|
|
1103
|
+
for (const [spec, resolution] of classifications) {
|
|
1104
|
+
if (resolution.status !== "ok") continue;
|
|
1105
|
+
const indices = resolution.resolved.messageIds.map(
|
|
1037
1106
|
(id) => input.messages.findIndex((m) => m.id === id)
|
|
1038
1107
|
).filter((i) => i >= 0);
|
|
1039
1108
|
rangeIndexSets.push({ spec, indices });
|
|
@@ -1060,37 +1129,27 @@ function createCore(ports = {}) {
|
|
|
1060
1129
|
if (input.config.compress.minCompressRange > 0 && input.ranges.length > 0) {
|
|
1061
1130
|
let totalRangeChars = 0;
|
|
1062
1131
|
let hasBlockBoundaryRange = false;
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
resolved = resolveBoundaries({
|
|
1068
|
-
startRef: spec.startRef,
|
|
1069
|
-
endRef: spec.endRef,
|
|
1070
|
-
messages: input.messages,
|
|
1071
|
-
state
|
|
1072
|
-
});
|
|
1073
|
-
} catch {
|
|
1074
|
-
continue;
|
|
1075
|
-
}
|
|
1076
|
-
if (resolved.boundaryKind === "block") {
|
|
1132
|
+
let countedRanges = 0;
|
|
1133
|
+
for (const [spec, resolution] of classifications) {
|
|
1134
|
+
if (resolution.status !== "ok" || skipSpecs.has(spec)) continue;
|
|
1135
|
+
if (resolution.resolved.boundaryKind === "block") {
|
|
1077
1136
|
hasBlockBoundaryRange = true;
|
|
1078
1137
|
continue;
|
|
1079
1138
|
}
|
|
1080
|
-
|
|
1139
|
+
countedRanges++;
|
|
1140
|
+
for (const id of resolution.resolved.messageIds) {
|
|
1081
1141
|
const msg = input.messages.find((m) => m.id === id);
|
|
1082
1142
|
totalRangeChars += msg?.text?.length ?? 0;
|
|
1083
1143
|
}
|
|
1084
1144
|
}
|
|
1085
1145
|
if (!hasBlockBoundaryRange && totalRangeChars < input.config.compress.minCompressRange) {
|
|
1146
|
+
const gateMessage = consumedRanges.length > 0 ? `Requested range(s) already compressed (e.g. ${consumedRanges[0].startRef}..${consumedRanges[0].endRef}); remaining compressible content ${totalRangeChars} chars < min ${input.config.compress.minCompressRange}. Nothing to do \u2014 run acp_status to see current compressible ranges.` : `Total compressible content too small (${totalRangeChars} chars across ${countedRanges} range(s), min ${input.config.compress.minCompressRange}). Combine more messages into your range(s) to meet the threshold.`;
|
|
1086
1147
|
return {
|
|
1087
1148
|
state: input.state,
|
|
1088
1149
|
result: {
|
|
1089
1150
|
blocksCreated: 0,
|
|
1090
1151
|
tokensCompressed: 0,
|
|
1091
|
-
errors: [
|
|
1092
|
-
`Total compressible content too small (${totalRangeChars} chars across ${input.ranges.length} range(s), min ${input.config.compress.minCompressRange}). Combine more messages into your range(s) to meet the threshold.`
|
|
1093
|
-
],
|
|
1152
|
+
errors: [gateMessage, ...classificationErrors],
|
|
1094
1153
|
warnings: []
|
|
1095
1154
|
}
|
|
1096
1155
|
};
|
|
@@ -1098,6 +1157,18 @@ function createCore(ports = {}) {
|
|
|
1098
1157
|
}
|
|
1099
1158
|
for (const spec of input.ranges) {
|
|
1100
1159
|
if (skipSpecs.has(spec)) continue;
|
|
1160
|
+
const resolution = classifications.get(spec);
|
|
1161
|
+
if (resolution === void 0) continue;
|
|
1162
|
+
if (resolution.status === "consumed") {
|
|
1163
|
+
warnings.push(
|
|
1164
|
+
`Skipped range (${spec.startRef}..${spec.endRef}) \u2014 already compressed (messages consumed by existing block(s)); nothing to compress.`
|
|
1165
|
+
);
|
|
1166
|
+
continue;
|
|
1167
|
+
}
|
|
1168
|
+
if (resolution.status === "unknown" || resolution.status === "invalid") {
|
|
1169
|
+
errors.push(rangeError(spec, resolution.error.message));
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1101
1172
|
try {
|
|
1102
1173
|
const outcome = applySingleRange({
|
|
1103
1174
|
spec,
|
|
@@ -1113,7 +1184,7 @@ function createCore(ports = {}) {
|
|
|
1113
1184
|
tokensCompressed += outcome.tokens;
|
|
1114
1185
|
warnings.push(...outcome.warnings);
|
|
1115
1186
|
} catch (error) {
|
|
1116
|
-
errors.push(error instanceof Error ? error.message : String(error));
|
|
1187
|
+
errors.push(rangeError(spec, error instanceof Error ? error.message : String(error)));
|
|
1117
1188
|
}
|
|
1118
1189
|
}
|
|
1119
1190
|
state.stats.compressionCount += blocksCreated;
|
|
@@ -1807,13 +1878,42 @@ DROP:
|
|
|
1807
1878
|
|
|
1808
1879
|
SIZE TARGET: 30-60 tokens per source block (including header). For a batch of N source blocks, total output \u2248 N \xD7 40 tokens. If a source block has only one trivial fact, output just the header + one line.`;
|
|
1809
1880
|
|
|
1881
|
+
// src/prompts.ts
|
|
1882
|
+
var defaultPrompts = Object.freeze({
|
|
1883
|
+
compressPhilosophy: COMPRESS_PHILOSOPHY,
|
|
1884
|
+
howToCompressRules: HOW_TO_COMPRESS_RULES,
|
|
1885
|
+
tier2DistillRules: TIER2_DISTILL_RULES,
|
|
1886
|
+
tier3CondenseRules: TIER3_CONDENSE_RULES
|
|
1887
|
+
});
|
|
1888
|
+
function resolvePrompts(overrides, options = {}) {
|
|
1889
|
+
const clean = {};
|
|
1890
|
+
if (overrides) {
|
|
1891
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
1892
|
+
if (typeof value === "string") {
|
|
1893
|
+
clean[key] = value;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
const keys = Object.keys(clean);
|
|
1898
|
+
if (keys.length > 0 && !options.acknowledgeRisk) {
|
|
1899
|
+
throw new Error(
|
|
1900
|
+
`resolvePrompts: overriding compression rules requires { acknowledgeRisk: true }. Overridden keys: ${keys.join(", ")}. These rules are quality-critical (tuned over months of production use); changing them can degrade summary quality and break retrieval (summaries may lose paths, signatures, decisions).`
|
|
1901
|
+
);
|
|
1902
|
+
}
|
|
1903
|
+
return { ...defaultPrompts, ...clean };
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1810
1906
|
// src/nudge-text.ts
|
|
1811
|
-
|
|
1907
|
+
function efficiencyNote(prompts) {
|
|
1908
|
+
return `This is an efficiency nudge to compress early and keep context lean \u2014 not an overflow warning. A separate, stronger alert will appear if the context is actually full.
|
|
1812
1909
|
|
|
1813
|
-
${
|
|
1814
|
-
|
|
1910
|
+
${prompts.compressPhilosophy}`;
|
|
1911
|
+
}
|
|
1912
|
+
function emergencyHeader(prompts) {
|
|
1913
|
+
return `\u26A0\uFE0F Context limit reached \u2014 compress now. Prioritize consumed tool outputs.
|
|
1815
1914
|
|
|
1816
|
-
${
|
|
1915
|
+
${prompts.compressPhilosophy}`;
|
|
1916
|
+
}
|
|
1817
1917
|
function formatK(n) {
|
|
1818
1918
|
if (n >= 1e3) return `${(n / 1e3).toFixed(1)}K`;
|
|
1819
1919
|
return `${n}`;
|
|
@@ -1921,7 +2021,7 @@ function formatRanges(compressible, protectedRanges) {
|
|
|
1921
2021
|
return `Compressible ranges (${merged.length}, oldest first):
|
|
1922
2022
|
${lines.join("\n")}`;
|
|
1923
2023
|
}
|
|
1924
|
-
function renderNudgeText(decision) {
|
|
2024
|
+
function renderNudgeText(decision, prompts = defaultPrompts) {
|
|
1925
2025
|
const breakdownStr = formatBreakdown(decision.contextBreakdown);
|
|
1926
2026
|
const rangesStr = formatRanges(decision.compressibleRanges, decision.protectedRanges ?? []);
|
|
1927
2027
|
if (decision.tier !== null && decision.tier >= 2) {
|
|
@@ -1933,7 +2033,7 @@ function renderNudgeText(decision) {
|
|
|
1933
2033
|
return {
|
|
1934
2034
|
voice: "gentle",
|
|
1935
2035
|
text: [
|
|
1936
|
-
|
|
2036
|
+
efficiencyNote(prompts),
|
|
1937
2037
|
"",
|
|
1938
2038
|
breakdownStr,
|
|
1939
2039
|
"",
|
|
@@ -1942,9 +2042,9 @@ function renderNudgeText(decision) {
|
|
|
1942
2042
|
blockList,
|
|
1943
2043
|
`Example: compress({ content: [{ startId: "${startId}", endId: "${endId}", summary: "..." }] })`,
|
|
1944
2044
|
"",
|
|
1945
|
-
|
|
2045
|
+
prompts.howToCompressRules,
|
|
1946
2046
|
"",
|
|
1947
|
-
isT2 ?
|
|
2047
|
+
isT2 ? prompts.tier2DistillRules : prompts.tier3CondenseRules
|
|
1948
2048
|
].join("\n")
|
|
1949
2049
|
};
|
|
1950
2050
|
}
|
|
@@ -1953,11 +2053,11 @@ function renderNudgeText(decision) {
|
|
|
1953
2053
|
return {
|
|
1954
2054
|
voice: "emergency",
|
|
1955
2055
|
text: [
|
|
1956
|
-
|
|
2056
|
+
emergencyHeader(prompts),
|
|
1957
2057
|
"",
|
|
1958
2058
|
breakdownStr,
|
|
1959
2059
|
"",
|
|
1960
|
-
|
|
2060
|
+
prompts.howToCompressRules,
|
|
1961
2061
|
"",
|
|
1962
2062
|
`{ "topic": "...", "content": [{ "startId": "<ID>", "endId": "<ID>", "summary": "..." }] }`,
|
|
1963
2063
|
"Only use IDs from visible messages above. Compress older work first.",
|
|
@@ -1969,11 +2069,11 @@ function renderNudgeText(decision) {
|
|
|
1969
2069
|
return {
|
|
1970
2070
|
voice: "gentle",
|
|
1971
2071
|
text: [
|
|
1972
|
-
|
|
2072
|
+
efficiencyNote(prompts),
|
|
1973
2073
|
"",
|
|
1974
2074
|
breakdownStr,
|
|
1975
2075
|
"",
|
|
1976
|
-
|
|
2076
|
+
prompts.howToCompressRules,
|
|
1977
2077
|
"",
|
|
1978
2078
|
rangesStr,
|
|
1979
2079
|
"",
|
|
@@ -2706,6 +2806,7 @@ function makePreview(text, query, len) {
|
|
|
2706
2806
|
}
|
|
2707
2807
|
export {
|
|
2708
2808
|
BLOCKED_REF,
|
|
2809
|
+
BoundaryNotFoundError,
|
|
2709
2810
|
COMPRESS_PHILOSOPHY,
|
|
2710
2811
|
DEFAULT_ALGORITHM,
|
|
2711
2812
|
DEFAULT_ROLE_WEIGHTS,
|
|
@@ -2734,6 +2835,7 @@ export {
|
|
|
2734
2835
|
deactivateBlock,
|
|
2735
2836
|
defaultConfig,
|
|
2736
2837
|
defaultCountTokens,
|
|
2838
|
+
defaultPrompts,
|
|
2737
2839
|
emptyRefMap,
|
|
2738
2840
|
estimateTokensFast,
|
|
2739
2841
|
findActiveAncestor,
|
|
@@ -2764,6 +2866,7 @@ export {
|
|
|
2764
2866
|
renderRefsNode,
|
|
2765
2867
|
renderVisibleRefs,
|
|
2766
2868
|
resolveBoundaries,
|
|
2869
|
+
resolvePrompts,
|
|
2767
2870
|
runPipeline,
|
|
2768
2871
|
searchBlocks,
|
|
2769
2872
|
searchBlocksAsync,
|