acp-kernel 0.0.58 → 0.0.59-pr.222.74
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/index.js +122 -21
- package/dist/index.js.map +1 -1
- package/dist/parse-compress-input.d.ts +2 -0
- package/dist/parse-compress-input.d.ts.map +1 -1
- package/dist/recommend.d.ts.map +1 -1
- package/dist/report.d.ts.map +1 -1
- package/dist/wire/anthropic.d.ts.map +1 -1
- package/dist/wire/index.js +27 -5
- package/dist/wire/index.js.map +1 -1
- package/dist/wire/openai.d.ts.map +1 -1
- package/dist/wire/responses.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1652,10 +1652,6 @@ function adjustBoundariesForReasoningPairs(startIndex, endIndex, messages) {
|
|
|
1652
1652
|
}
|
|
1653
1653
|
|
|
1654
1654
|
// src/recommend.ts
|
|
1655
|
-
function refNum(ref) {
|
|
1656
|
-
const n = parseInt(ref.slice(1), 10);
|
|
1657
|
-
return Number.isNaN(n) ? -1 : n;
|
|
1658
|
-
}
|
|
1659
1655
|
function estimateTextTokens(text) {
|
|
1660
1656
|
return Math.ceil(text.length / 4);
|
|
1661
1657
|
}
|
|
@@ -1708,42 +1704,50 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
1708
1704
|
const compressibleMsgs = [];
|
|
1709
1705
|
const protectedMsgs = [];
|
|
1710
1706
|
const protectedCallIds = collectProtectedToolCallIds(messages, config);
|
|
1707
|
+
let skipSinceCompressible = false;
|
|
1708
|
+
let skipSinceProtected = false;
|
|
1711
1709
|
for (const msg of messages) {
|
|
1712
|
-
if (isSyntheticOrPruned(msg, state)) continue;
|
|
1713
1710
|
const ref = state.messageRefs.byRaw[msg.id];
|
|
1714
1711
|
if (!ref || ref === "BLOCKED") continue;
|
|
1715
|
-
|
|
1712
|
+
if (isSyntheticOrPruned(msg, state)) {
|
|
1713
|
+
skipSinceCompressible = true;
|
|
1714
|
+
skipSinceProtected = true;
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1716
1717
|
if (isMessageProtectedWithPairing(msg, config, protectedCallIds)) {
|
|
1717
1718
|
protectedMsgs.push({
|
|
1718
1719
|
ref,
|
|
1719
|
-
|
|
1720
|
+
gapBefore: skipSinceProtected,
|
|
1720
1721
|
tokens: countTokens(msg.text ?? ""),
|
|
1721
1722
|
tools: msg.toolName ? [msg.toolName] : []
|
|
1722
1723
|
});
|
|
1724
|
+
skipSinceProtected = false;
|
|
1725
|
+
skipSinceCompressible = true;
|
|
1723
1726
|
continue;
|
|
1724
1727
|
}
|
|
1725
1728
|
if (protectedZoneRefs?.has(ref)) {
|
|
1729
|
+
skipSinceCompressible = true;
|
|
1730
|
+
skipSinceProtected = true;
|
|
1726
1731
|
continue;
|
|
1727
1732
|
}
|
|
1728
1733
|
compressibleMsgs.push({
|
|
1729
1734
|
ref,
|
|
1730
|
-
|
|
1735
|
+
gapBefore: skipSinceCompressible,
|
|
1731
1736
|
tokens: countTokens(msg.text ?? ""),
|
|
1732
1737
|
chars: (msg.text ?? "").length,
|
|
1733
1738
|
isTool: isToolMessage(msg),
|
|
1734
1739
|
isUser: msg.role === "user"
|
|
1735
1740
|
});
|
|
1741
|
+
skipSinceCompressible = false;
|
|
1742
|
+
skipSinceProtected = true;
|
|
1736
1743
|
}
|
|
1737
1744
|
const compressible = [];
|
|
1738
1745
|
let cur = null;
|
|
1739
|
-
let prevRefNum = -2;
|
|
1740
1746
|
for (const info of compressibleMsgs) {
|
|
1741
|
-
|
|
1742
|
-
if (cur && (info.isUser && cur.count >= 3 || hasGap)) {
|
|
1747
|
+
if (cur && (info.isUser && cur.count >= 3 || info.gapBefore)) {
|
|
1743
1748
|
compressible.push(cur);
|
|
1744
1749
|
cur = null;
|
|
1745
1750
|
}
|
|
1746
|
-
prevRefNum = info.refNum;
|
|
1747
1751
|
if (!cur) {
|
|
1748
1752
|
cur = {
|
|
1749
1753
|
startRef: info.ref,
|
|
@@ -1770,14 +1774,11 @@ function buildCompressibleRanges(messages, state, config, protectedZoneRefs, cou
|
|
|
1770
1774
|
if (cur) compressible.push(cur);
|
|
1771
1775
|
const protectedRanges = [];
|
|
1772
1776
|
let pcur = null;
|
|
1773
|
-
let pPrevRefNum = -2;
|
|
1774
1777
|
for (const info of protectedMsgs) {
|
|
1775
|
-
|
|
1776
|
-
if (pcur && hasGap) {
|
|
1778
|
+
if (pcur && info.gapBefore) {
|
|
1777
1779
|
protectedRanges.push(pcur);
|
|
1778
1780
|
pcur = null;
|
|
1779
1781
|
}
|
|
1780
|
-
pPrevRefNum = info.refNum;
|
|
1781
1782
|
if (!pcur) {
|
|
1782
1783
|
pcur = {
|
|
1783
1784
|
startRef: info.ref,
|
|
@@ -2930,14 +2931,16 @@ function tierLabel(block) {
|
|
|
2930
2931
|
}
|
|
2931
2932
|
function tierBreakdown(blocks, countTokens) {
|
|
2932
2933
|
const tierTokens = {};
|
|
2934
|
+
const tierCounts = {};
|
|
2933
2935
|
for (const block of blocks) {
|
|
2934
2936
|
tierTokens[block.tier] = (tierTokens[block.tier] ?? 0) + summaryTokensOf(block, countTokens);
|
|
2937
|
+
tierCounts[block.tier] = (tierCounts[block.tier] ?? 0) + 1;
|
|
2935
2938
|
}
|
|
2936
2939
|
const tiers = Object.keys(tierTokens).map(Number);
|
|
2937
2940
|
if (tiers.length <= 1) return null;
|
|
2938
2941
|
const parts = [];
|
|
2939
2942
|
for (const tier of [1, 2, 3]) {
|
|
2940
|
-
if (tierTokens[tier]) parts.push(`T${tier}: ${formatTokens2(tierTokens[tier])}`);
|
|
2943
|
+
if (tierTokens[tier]) parts.push(`T${tier}: ${formatTokens2(tierTokens[tier])} (${tierCounts[tier]} blocks)`);
|
|
2941
2944
|
}
|
|
2942
2945
|
return parts.join(" | ");
|
|
2943
2946
|
}
|
|
@@ -3031,6 +3034,11 @@ function renderOverview(visible, summaryTokens, blocks, state, countTokens, limi
|
|
|
3031
3034
|
` ${block.blockId} (${tierLabel(block)}) ${formatTokens2(eff)}\u2192${formatTokens2(summaryTokensOf(block, countTokens))} ${block.effectiveMessageIds.length} msgs "${topic}"`
|
|
3032
3035
|
);
|
|
3033
3036
|
}
|
|
3037
|
+
if (blocks.length > limit) {
|
|
3038
|
+
lines.push(
|
|
3039
|
+
` ... and ${blocks.length - limit} more blocks not shown (scope:"compressed", limit:${blocks.length} for full list)`
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3034
3042
|
}
|
|
3035
3043
|
lines.push("");
|
|
3036
3044
|
lines.push(
|
|
@@ -3047,7 +3055,7 @@ function renderUncompressedRanges(visible) {
|
|
|
3047
3055
|
lines.push(" (no uncompressed messages)");
|
|
3048
3056
|
return lines.join("\n");
|
|
3049
3057
|
}
|
|
3050
|
-
const
|
|
3058
|
+
const refNum = (ref) => {
|
|
3051
3059
|
const m = ref.match(/\d+/);
|
|
3052
3060
|
return m ? parseInt(m[0], 10) : 0;
|
|
3053
3061
|
};
|
|
@@ -3064,7 +3072,7 @@ function renderUncompressedRanges(visible) {
|
|
|
3064
3072
|
};
|
|
3065
3073
|
const merged = [];
|
|
3066
3074
|
for (const m of visible) {
|
|
3067
|
-
const num =
|
|
3075
|
+
const num = refNum(m.ref);
|
|
3068
3076
|
const last = merged[merged.length - 1];
|
|
3069
3077
|
if (last && num === last.startNum + last.count) {
|
|
3070
3078
|
last.endRef = m.ref;
|
|
@@ -3262,6 +3270,23 @@ function parseStringInput(raw, callId, diag) {
|
|
|
3262
3270
|
diag.rawPrefix = raw.slice(0, 800);
|
|
3263
3271
|
diag.length = raw.length;
|
|
3264
3272
|
const cleaned = stripFence(raw.trim());
|
|
3273
|
+
const first = parseStringCore(cleaned, callId, diag);
|
|
3274
|
+
if (first.ranges.length === 0 || first.diagnostics.invalidItems > 0) {
|
|
3275
|
+
const normalized = normalizeSingleQuotes(cleaned);
|
|
3276
|
+
if (normalized !== void 0) {
|
|
3277
|
+
const retryDiag = { ok: false, kind: "ok", invalidItems: 0 };
|
|
3278
|
+
retryDiag.rawPrefix = diag.rawPrefix;
|
|
3279
|
+
retryDiag.length = diag.length;
|
|
3280
|
+
const retry = parseStringCore(normalized, callId, retryDiag);
|
|
3281
|
+
if (retry.ranges.length > first.ranges.length) {
|
|
3282
|
+
retryDiag.quoteSalvage = true;
|
|
3283
|
+
return retry;
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
return first;
|
|
3288
|
+
}
|
|
3289
|
+
function parseStringCore(cleaned, callId, diag) {
|
|
3265
3290
|
if (cleaned === "") {
|
|
3266
3291
|
diag.kind = "empty-input";
|
|
3267
3292
|
return finish([], diag);
|
|
@@ -3305,6 +3330,7 @@ function parseObjectValue(value, callId, diag) {
|
|
|
3305
3330
|
}
|
|
3306
3331
|
entries = parsed.entries;
|
|
3307
3332
|
salvaged = parsed.salvaged;
|
|
3333
|
+
if (parsed.quoteRepaired) diag.quoteSalvage = true;
|
|
3308
3334
|
} else {
|
|
3309
3335
|
diag.kind = "content-not-array";
|
|
3310
3336
|
return finish([], diag);
|
|
@@ -3326,7 +3352,17 @@ function parseObjectValue(value, callId, diag) {
|
|
|
3326
3352
|
}
|
|
3327
3353
|
function parseContentArray(s) {
|
|
3328
3354
|
const cleaned = stripFence(s.trim());
|
|
3329
|
-
|
|
3355
|
+
const direct = parseContentArrayCore(cleaned);
|
|
3356
|
+
if (direct !== null && direct.entries.length > 0) return direct;
|
|
3357
|
+
const normalized = normalizeSingleQuotes(cleaned);
|
|
3358
|
+
if (normalized !== void 0) {
|
|
3359
|
+
const retry = parseContentArrayCore(normalized);
|
|
3360
|
+
if (retry !== null && retry.entries.length > 0) return { ...retry, quoteRepaired: true };
|
|
3361
|
+
}
|
|
3362
|
+
return direct;
|
|
3363
|
+
}
|
|
3364
|
+
function parseContentArrayCore(s) {
|
|
3365
|
+
let value = s === "" ? void 0 : tryParseLenient(s);
|
|
3330
3366
|
if (typeof value === "string") {
|
|
3331
3367
|
value = tryParseLenient(stripFence(value));
|
|
3332
3368
|
}
|
|
@@ -3334,7 +3370,7 @@ function parseContentArray(s) {
|
|
|
3334
3370
|
return { entries: value, salvaged: false };
|
|
3335
3371
|
}
|
|
3336
3372
|
if (value === void 0) {
|
|
3337
|
-
const entries = salvageContentEntries('{"content": ' +
|
|
3373
|
+
const entries = salvageContentEntries('{"content": ' + s);
|
|
3338
3374
|
return { entries, salvaged: entries.length > 0 };
|
|
3339
3375
|
}
|
|
3340
3376
|
return null;
|
|
@@ -3407,6 +3443,71 @@ function tryParseLenient(s) {
|
|
|
3407
3443
|
}
|
|
3408
3444
|
return void 0;
|
|
3409
3445
|
}
|
|
3446
|
+
function normalizeSingleQuotes(raw) {
|
|
3447
|
+
if (!raw.includes("'") || !raw.includes("{") && !raw.includes("[")) return void 0;
|
|
3448
|
+
let out = "";
|
|
3449
|
+
let changed = false;
|
|
3450
|
+
let inDouble = false;
|
|
3451
|
+
let inSingle = false;
|
|
3452
|
+
for (let i = 0; i < raw.length; i++) {
|
|
3453
|
+
const ch = raw.charAt(i);
|
|
3454
|
+
if (inDouble) {
|
|
3455
|
+
out += ch;
|
|
3456
|
+
if (ch === "\\" && i + 1 < raw.length) {
|
|
3457
|
+
out += raw.charAt(i + 1);
|
|
3458
|
+
i++;
|
|
3459
|
+
} else if (ch === '"') {
|
|
3460
|
+
inDouble = false;
|
|
3461
|
+
}
|
|
3462
|
+
continue;
|
|
3463
|
+
}
|
|
3464
|
+
if (inSingle) {
|
|
3465
|
+
if (ch === "\\" && i + 1 < raw.length) {
|
|
3466
|
+
const next = raw.charAt(i + 1);
|
|
3467
|
+
out += next === "'" ? "'" : "\\" + next;
|
|
3468
|
+
i++;
|
|
3469
|
+
continue;
|
|
3470
|
+
}
|
|
3471
|
+
if (ch === "'") {
|
|
3472
|
+
out += '"';
|
|
3473
|
+
inSingle = false;
|
|
3474
|
+
changed = true;
|
|
3475
|
+
continue;
|
|
3476
|
+
}
|
|
3477
|
+
if (ch === '"') {
|
|
3478
|
+
out += '\\"';
|
|
3479
|
+
continue;
|
|
3480
|
+
}
|
|
3481
|
+
if (ch === "\n") {
|
|
3482
|
+
out += "\\n";
|
|
3483
|
+
continue;
|
|
3484
|
+
}
|
|
3485
|
+
if (ch === "\r") {
|
|
3486
|
+
out += "\\r";
|
|
3487
|
+
continue;
|
|
3488
|
+
}
|
|
3489
|
+
if (ch === " ") {
|
|
3490
|
+
out += "\\t";
|
|
3491
|
+
continue;
|
|
3492
|
+
}
|
|
3493
|
+
out += ch;
|
|
3494
|
+
continue;
|
|
3495
|
+
}
|
|
3496
|
+
if (ch === '"') {
|
|
3497
|
+
inDouble = true;
|
|
3498
|
+
out += ch;
|
|
3499
|
+
continue;
|
|
3500
|
+
}
|
|
3501
|
+
if (ch === "'") {
|
|
3502
|
+
inSingle = true;
|
|
3503
|
+
out += '"';
|
|
3504
|
+
changed = true;
|
|
3505
|
+
continue;
|
|
3506
|
+
}
|
|
3507
|
+
out += ch;
|
|
3508
|
+
}
|
|
3509
|
+
return changed ? out : void 0;
|
|
3510
|
+
}
|
|
3410
3511
|
function stripFence(s) {
|
|
3411
3512
|
if (!s.startsWith("```")) return s;
|
|
3412
3513
|
const firstNewline = s.indexOf("\n");
|