acp-kernel 0.0.82-pr.345.220 → 0.0.82-pr.347.221
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/{chunk-5TQA7ZQM.js → chunk-BDAKCQHT.js} +2 -1
- package/dist/chunk-BDAKCQHT.js.map +1 -0
- package/dist/compress.d.ts.map +1 -1
- package/dist/index.js +11 -79
- package/dist/index.js.map +1 -1
- package/dist/persist/index.js +3 -2
- package/dist/persist/index.js.map +1 -1
- package/dist/persist/state-merge.d.ts.map +1 -1
- package/dist/recommend.d.ts +11 -12
- package/dist/recommend.d.ts.map +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5TQA7ZQM.js.map +0 -1
|
@@ -15,6 +15,7 @@ function createInitialState() {
|
|
|
15
15
|
absorbed: [],
|
|
16
16
|
rules: [],
|
|
17
17
|
nextRuleId: 1,
|
|
18
|
+
lastConfigWarnings: [],
|
|
18
19
|
nextBlockId: 1,
|
|
19
20
|
nextRunId: 1
|
|
20
21
|
};
|
|
@@ -70,4 +71,4 @@ export {
|
|
|
70
71
|
highestActiveTier,
|
|
71
72
|
advanceSurvival
|
|
72
73
|
};
|
|
73
|
-
//# sourceMappingURL=chunk-
|
|
74
|
+
//# sourceMappingURL=chunk-BDAKCQHT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/state.ts"],"sourcesContent":["import type { CompressionBlock, CompressionState } from \"./types.js\";\n\nexport function createInitialState(): CompressionState {\n return {\n blocks: [],\n messageRefs: { byRaw: {}, byRef: {} },\n tokenSnapshot: {},\n nudge: {\n lastPerMessageNudgeTokens: 0,\n lastNudgeShownTokens: 0,\n baselineTokens: 0,\n anchors: {},\n lastShownByTier: {},\n },\n stats: { tokensCompressed: 0, compressionCount: 0, absorbedTokens: 0 },\n absorbed: [],\n rules: [],\n nextRuleId: 1,\n lastConfigWarnings: [],\n nextBlockId: 1,\n nextRunId: 1,\n };\n}\n\nexport function allocateBlockId(state: CompressionState): string {\n const id = state.nextBlockId;\n state.nextBlockId = Math.max(1, id) + 1;\n return `b${id}`;\n}\n\nexport function allocateRunId(state: CompressionState): string {\n const id = state.nextRunId;\n state.nextRunId = Math.max(1, id) + 1;\n return `r${id}`;\n}\n\nexport function blockById(\n state: CompressionState,\n blockId: string,\n): CompressionBlock | undefined {\n return state.blocks.find((block) => block.blockId === blockId);\n}\n\nexport function activeBlocks(state: CompressionState): CompressionBlock[] {\n return state.blocks.filter((block) => block.active);\n}\n\nexport function coveredMessageIds(state: CompressionState): Set<string> {\n const covered = new Set<string>();\n for (const block of state.blocks) {\n if (!block.active) continue;\n for (const id of block.effectiveMessageIds) covered.add(id);\n }\n return covered;\n}\n\nexport function highestActiveTier(state: CompressionState): 0 | 1 | 2 | 3 {\n let highest: 0 | 1 | 2 | 3 = 0;\n for (const block of state.blocks) {\n if (block.active && block.tier > highest) highest = block.tier;\n }\n return highest;\n}\n\nexport function advanceSurvival(\n state: CompressionState,\n promotionThreshold: number,\n): void {\n for (const block of state.blocks) {\n if (!block.active) continue;\n block.survivedCount += 1;\n if (block.survivedCount >= promotionThreshold) {\n block.generation = \"old\";\n }\n }\n}\n"],"mappings":";AAEO,SAAS,qBAAuC;AACrD,SAAO;AAAA,IACL,QAAQ,CAAC;AAAA,IACT,aAAa,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE;AAAA,IACpC,eAAe,CAAC;AAAA,IAChB,OAAO;AAAA,MACL,2BAA2B;AAAA,MAC3B,sBAAsB;AAAA,MACtB,gBAAgB;AAAA,MAChB,SAAS,CAAC;AAAA,MACV,iBAAiB,CAAC;AAAA,IACpB;AAAA,IACA,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,EAAE;AAAA,IACrE,UAAU,CAAC;AAAA,IACX,OAAO,CAAC;AAAA,IACR,YAAY;AAAA,IACZ,oBAAoB,CAAC;AAAA,IACrB,aAAa;AAAA,IACb,WAAW;AAAA,EACb;AACF;AAEO,SAAS,gBAAgB,OAAiC;AAC/D,QAAM,KAAK,MAAM;AACjB,QAAM,cAAc,KAAK,IAAI,GAAG,EAAE,IAAI;AACtC,SAAO,IAAI,EAAE;AACf;AAEO,SAAS,cAAc,OAAiC;AAC7D,QAAM,KAAK,MAAM;AACjB,QAAM,YAAY,KAAK,IAAI,GAAG,EAAE,IAAI;AACpC,SAAO,IAAI,EAAE;AACf;AAEO,SAAS,UACd,OACA,SAC8B;AAC9B,SAAO,MAAM,OAAO,KAAK,CAAC,UAAU,MAAM,YAAY,OAAO;AAC/D;AAEO,SAAS,aAAa,OAA6C;AACxE,SAAO,MAAM,OAAO,OAAO,CAAC,UAAU,MAAM,MAAM;AACpD;AAEO,SAAS,kBAAkB,OAAsC;AACtE,QAAM,UAAU,oBAAI,IAAY;AAChC,aAAW,SAAS,MAAM,QAAQ;AAChC,QAAI,CAAC,MAAM,OAAQ;AACnB,eAAW,MAAM,MAAM,oBAAqB,SAAQ,IAAI,EAAE;AAAA,EAC5D;AACA,SAAO;AACT;AAEO,SAAS,kBAAkB,OAAwC;AACxE,MAAI,UAAyB;AAC7B,aAAW,SAAS,MAAM,QAAQ;AAChC,QAAI,MAAM,UAAU,MAAM,OAAO,QAAS,WAAU,MAAM;AAAA,EAC5D;AACA,SAAO;AACT;AAEO,SAAS,gBACd,OACA,oBACM;AACN,aAAW,SAAS,MAAM,QAAQ;AAChC,QAAI,CAAC,MAAM,OAAQ;AACnB,UAAM,iBAAiB;AACvB,QAAI,MAAM,iBAAiB,oBAAoB;AAC7C,YAAM,aAAa;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
package/dist/compress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"names":[],"mappings":"AAIA,OA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M,EAClB,MAAM,EAAE,MAAM,GACb,YAAY,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,eAAe,CAAC,EAAE,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;AA2GD,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAuV7D;AA+mCD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
coveredMessageIds,
|
|
27
27
|
createInitialState,
|
|
28
28
|
highestActiveTier
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-BDAKCQHT.js";
|
|
30
30
|
|
|
31
31
|
// src/refs.ts
|
|
32
32
|
var REF_WIDTH = 5;
|
|
@@ -301,6 +301,7 @@ function syncBlocks(messages, state) {
|
|
|
301
301
|
rules: (state.rules ?? []).map((rule) => ({ ...rule })),
|
|
302
302
|
nextRuleId: state.nextRuleId,
|
|
303
303
|
terminalStreak: state.terminalStreak,
|
|
304
|
+
lastConfigWarnings: [...state.lastConfigWarnings ?? []],
|
|
304
305
|
nextBlockId: state.nextBlockId,
|
|
305
306
|
nextRunId: state.nextRunId
|
|
306
307
|
};
|
|
@@ -2233,27 +2234,6 @@ function computeProtectedRefs(messages, state, config, countTokens = estimateTex
|
|
|
2233
2234
|
}
|
|
2234
2235
|
return result;
|
|
2235
2236
|
}
|
|
2236
|
-
function computeOpenTurnMemberIds(messages) {
|
|
2237
|
-
const resultCallIds = /* @__PURE__ */ new Set();
|
|
2238
|
-
for (const msg of messages) {
|
|
2239
|
-
if (msg.contentType === "tool-result" && typeof msg.toolCallId === "string") {
|
|
2240
|
-
resultCallIds.add(msg.toolCallId);
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
const openCallIds = /* @__PURE__ */ new Set();
|
|
2244
|
-
for (const msg of messages) {
|
|
2245
|
-
if (msg.id && msg.role === "assistant" && msg.contentType === "tool-call" && typeof msg.toolCallId === "string" && !resultCallIds.has(msg.toolCallId)) {
|
|
2246
|
-
openCallIds.add(msg.id);
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
if (openCallIds.size === 0) return /* @__PURE__ */ new Set();
|
|
2250
|
-
const excluded = /* @__PURE__ */ new Set();
|
|
2251
|
-
for (const group of computeTurnGroups(messages)) {
|
|
2252
|
-
if (!group.some((id) => openCallIds.has(id))) continue;
|
|
2253
|
-
for (const id of group) excluded.add(id);
|
|
2254
|
-
}
|
|
2255
|
-
return excluded;
|
|
2256
|
-
}
|
|
2257
2237
|
function buildCompressibleRanges(messages, state, config, protectedZoneRefs, countTokens = estimateTextTokens) {
|
|
2258
2238
|
let compressibleMsgs = [];
|
|
2259
2239
|
const protectedMsgs = [];
|
|
@@ -2302,20 +2282,6 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
2302
2282
|
skipSinceCompressible = false;
|
|
2303
2283
|
skipSinceProtected = true;
|
|
2304
2284
|
}
|
|
2305
|
-
const openTurnIds = computeOpenTurnMemberIds(messages);
|
|
2306
|
-
if (openTurnIds.size > 0) {
|
|
2307
|
-
let gapPending = false;
|
|
2308
|
-
const kept = [];
|
|
2309
|
-
for (const info of compressibleMsgs) {
|
|
2310
|
-
if (openTurnIds.has(info.id)) {
|
|
2311
|
-
gapPending = true;
|
|
2312
|
-
continue;
|
|
2313
|
-
}
|
|
2314
|
-
kept.push(gapPending ? { ...info, gapBefore: true } : info);
|
|
2315
|
-
gapPending = false;
|
|
2316
|
-
}
|
|
2317
|
-
compressibleMsgs = kept;
|
|
2318
|
-
}
|
|
2319
2285
|
const unfoldedIds = computeIntegrityWithdrawals(
|
|
2320
2286
|
messages,
|
|
2321
2287
|
new Set(compressibleMsgs.map((info) => info.id))
|
|
@@ -2333,13 +2299,6 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
2333
2299
|
}
|
|
2334
2300
|
compressibleMsgs = kept;
|
|
2335
2301
|
}
|
|
2336
|
-
const gapCount = compressibleMsgs.reduce(
|
|
2337
|
-
(s, info) => s + (info.gapBefore ? 1 : 0),
|
|
2338
|
-
0
|
|
2339
|
-
);
|
|
2340
|
-
if (gapCount > 0) {
|
|
2341
|
-
compressibleMsgs = refineSegmentsForFoldability(messages, compressibleMsgs);
|
|
2342
|
-
}
|
|
2343
2302
|
const compressible = [];
|
|
2344
2303
|
let cur = null;
|
|
2345
2304
|
for (const info of compressibleMsgs) {
|
|
@@ -2409,41 +2368,6 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
2409
2368
|
protected: protectedRanges
|
|
2410
2369
|
};
|
|
2411
2370
|
}
|
|
2412
|
-
var MAX_REFINEMENT_PASSES = 8;
|
|
2413
|
-
function refineSegmentsForFoldability(messages, infos) {
|
|
2414
|
-
let current = infos;
|
|
2415
|
-
for (let pass = 0; pass < MAX_REFINEMENT_PASSES; pass++) {
|
|
2416
|
-
const segments = [];
|
|
2417
|
-
for (const info of current) {
|
|
2418
|
-
const seg = segments[segments.length - 1];
|
|
2419
|
-
if (seg === void 0 || info.gapBefore) segments.push([info]);
|
|
2420
|
-
else seg.push(info);
|
|
2421
|
-
}
|
|
2422
|
-
const removed = /* @__PURE__ */ new Set();
|
|
2423
|
-
for (const seg of segments) {
|
|
2424
|
-
const withdrawn = computeIntegrityWithdrawals(
|
|
2425
|
-
messages,
|
|
2426
|
-
new Set(seg.map((info) => info.id))
|
|
2427
|
-
).withdrawn;
|
|
2428
|
-
for (const info of seg) {
|
|
2429
|
-
if (withdrawn.has(info.id)) removed.add(info.id);
|
|
2430
|
-
}
|
|
2431
|
-
}
|
|
2432
|
-
if (removed.size === 0) break;
|
|
2433
|
-
let gapPending = false;
|
|
2434
|
-
const kept = [];
|
|
2435
|
-
for (const info of current) {
|
|
2436
|
-
if (removed.has(info.id)) {
|
|
2437
|
-
gapPending = true;
|
|
2438
|
-
continue;
|
|
2439
|
-
}
|
|
2440
|
-
kept.push(gapPending ? { ...info, gapBefore: true } : info);
|
|
2441
|
-
gapPending = false;
|
|
2442
|
-
}
|
|
2443
|
-
current = kept;
|
|
2444
|
-
}
|
|
2445
|
-
return current;
|
|
2446
|
-
}
|
|
2447
2371
|
function mergeBatch(batch) {
|
|
2448
2372
|
const first = batch[0];
|
|
2449
2373
|
const last = batch[batch.length - 1];
|
|
@@ -2744,11 +2668,12 @@ function createCore(ports = {}) {
|
|
|
2744
2668
|
}
|
|
2745
2669
|
function processTurn(input) {
|
|
2746
2670
|
const configErrors = validateConfig(input.config);
|
|
2747
|
-
if (configErrors.length > 0) {
|
|
2671
|
+
if (configErrors.length > 0 && !sameWarningSet(input.state.lastConfigWarnings, configErrors)) {
|
|
2748
2672
|
console.warn(
|
|
2749
2673
|
`[acp-kernel] Config validation warnings: ${configErrors.join("; ")}. Thresholds may not fire correctly.`
|
|
2750
2674
|
);
|
|
2751
2675
|
}
|
|
2676
|
+
input.state.lastConfigWarnings = configErrors.length > 0 ? [...configErrors] : [];
|
|
2752
2677
|
const ctx = {
|
|
2753
2678
|
config: input.config,
|
|
2754
2679
|
tokenCount: input.tokenCount,
|
|
@@ -3316,6 +3241,12 @@ function pendingByTier(state, recommendation, countTokens, minCompressRange) {
|
|
|
3316
3241
|
};
|
|
3317
3242
|
return out;
|
|
3318
3243
|
}
|
|
3244
|
+
function sameWarningSet(a, b) {
|
|
3245
|
+
if (!a || a.length !== b.length) return false;
|
|
3246
|
+
const sa = [...a].sort();
|
|
3247
|
+
const sb = [...b].sort();
|
|
3248
|
+
return sa.every((v, i) => v === sb[i]);
|
|
3249
|
+
}
|
|
3319
3250
|
function decideNudge(input) {
|
|
3320
3251
|
const { config, state, tokenCount, recommendation, countTokens } = input;
|
|
3321
3252
|
const limit = config.modelContextLimit;
|
|
@@ -3511,6 +3442,7 @@ function cloneState(state) {
|
|
|
3511
3442
|
rules: (state.rules ?? []).map((rule) => ({ ...rule })),
|
|
3512
3443
|
nextRuleId: state.nextRuleId,
|
|
3513
3444
|
terminalStreak: state.terminalStreak,
|
|
3445
|
+
lastConfigWarnings: [...state.lastConfigWarnings ?? []],
|
|
3514
3446
|
nextBlockId: state.nextBlockId,
|
|
3515
3447
|
nextRunId: state.nextRunId
|
|
3516
3448
|
};
|