opencode-acp 1.14.27-pr.376.109 → 1.14.27-pr.377.112
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 +9 -0
- package/README.zh-CN.md +8 -0
- package/dist/index.js +145 -222
- package/dist/index.js.map +1 -1
- package/dist/lib/config-validation.d.ts.map +1 -1
- package/dist/lib/config.d.ts +44 -3
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/messages/index.d.ts +1 -1
- package/dist/lib/messages/index.d.ts.map +1 -1
- package/dist/lib/messages/inject/utils.d.ts.map +1 -1
- package/dist/lib/messages/reasoning-strip.d.ts +24 -0
- package/dist/lib/messages/reasoning-strip.d.ts.map +1 -1
- package/dist/lib/state/state.d.ts.map +1 -1
- package/dist/lib/state/utils.d.ts +0 -1
- package/dist/lib/state/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/lib/state/fork-transfer.d.ts +0 -42
- package/dist/lib/state/fork-transfer.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -381,6 +381,15 @@ Each level overrides the previous, so project settings take priority over global
|
|
|
381
381
|
// Preserve your messages during compression.
|
|
382
382
|
// Warning: large copy-pasted prompts will never be compressed away
|
|
383
383
|
"protectUserMessages": false,
|
|
384
|
+
// [#368] Drop oversized reasoning (thinking) from historical compress
|
|
385
|
+
// tool calls at request time. compress calls are hard-exempt from
|
|
386
|
+
// compression, so their thinking rides along every request as an
|
|
387
|
+
// unreclaimable floor. Closed turns only; the active round is never
|
|
388
|
+
// touched. Small thinkings under the threshold are kept.
|
|
389
|
+
"reasoning": {
|
|
390
|
+
"drop": true,
|
|
391
|
+
"threshold": 2048
|
|
392
|
+
},
|
|
384
393
|
},
|
|
385
394
|
// Garbage collection — hardcoded 100% fallback only
|
|
386
395
|
"gc": {
|
package/README.zh-CN.md
CHANGED
|
@@ -334,6 +334,14 @@ ACP 使用自己的配置文件,按以下顺序搜索:
|
|
|
334
334
|
// Preserve your messages during compression.
|
|
335
335
|
// Warning: large copy-pasted prompts will never be compressed away
|
|
336
336
|
"protectUserMessages": false,
|
|
337
|
+
// [#368] 请求时丢弃历史 compress 工具调用中超大的 reasoning(思考)。
|
|
338
|
+
// compress 调用被硬排除在压缩之外,其思考内容会随每次请求原样重发,
|
|
339
|
+
// 形成无法回收的上下文底座。仅作用于已关闭的轮次,活跃轮永不触碰;
|
|
340
|
+
// 低于阈值的小思考保留。
|
|
341
|
+
"reasoning": {
|
|
342
|
+
"drop": true,
|
|
343
|
+
"threshold": 2048
|
|
344
|
+
},
|
|
337
345
|
},
|
|
338
346
|
// 垃圾回收与批量清理
|
|
339
347
|
"gc": {
|
package/dist/index.js
CHANGED
|
@@ -909,6 +909,9 @@ var VALID_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
909
909
|
"compress.preserveRecentMessages",
|
|
910
910
|
"compress.preserveRecentTokens",
|
|
911
911
|
"compress.preserveLastUserMessage",
|
|
912
|
+
"compress.reasoning",
|
|
913
|
+
"compress.reasoning.drop",
|
|
914
|
+
"compress.reasoning.threshold",
|
|
912
915
|
"gc",
|
|
913
916
|
"gc.algorithm",
|
|
914
917
|
"gc.promotionThreshold",
|
|
@@ -1262,6 +1265,30 @@ function validateConfigTypes(config) {
|
|
|
1262
1265
|
actual: typeof compress.preserveLastUserMessage
|
|
1263
1266
|
});
|
|
1264
1267
|
}
|
|
1268
|
+
if (compress.reasoning !== void 0) {
|
|
1269
|
+
if (typeof compress.reasoning !== "object" || compress.reasoning === null || Array.isArray(compress.reasoning)) {
|
|
1270
|
+
errors.push({
|
|
1271
|
+
key: "compress.reasoning",
|
|
1272
|
+
expected: "object { drop?: boolean; threshold?: integer (>= 0) }",
|
|
1273
|
+
actual: JSON.stringify(compress.reasoning)
|
|
1274
|
+
});
|
|
1275
|
+
} else {
|
|
1276
|
+
if (compress.reasoning.drop !== void 0 && typeof compress.reasoning.drop !== "boolean") {
|
|
1277
|
+
errors.push({
|
|
1278
|
+
key: "compress.reasoning.drop",
|
|
1279
|
+
expected: "boolean",
|
|
1280
|
+
actual: typeof compress.reasoning.drop
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
if (compress.reasoning.threshold !== void 0 && (typeof compress.reasoning.threshold !== "number" || !Number.isInteger(compress.reasoning.threshold) || compress.reasoning.threshold < 0)) {
|
|
1284
|
+
errors.push({
|
|
1285
|
+
key: "compress.reasoning.threshold",
|
|
1286
|
+
expected: "integer (>= 0)",
|
|
1287
|
+
actual: JSON.stringify(compress.reasoning.threshold)
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1265
1292
|
if (typeof compress.iterationNudgeThreshold === "number" && compress.iterationNudgeThreshold < 1) {
|
|
1266
1293
|
errors.push({
|
|
1267
1294
|
key: "compress.iterationNudgeThreshold",
|
|
@@ -1347,7 +1374,8 @@ function validateConfigTypes(config) {
|
|
|
1347
1374
|
maxVisibleSegments: "positiveNumber",
|
|
1348
1375
|
keepEmbedMaxChars: "nonNegativeNumber",
|
|
1349
1376
|
preserveRecentMessages: "nonNegativeNumber",
|
|
1350
|
-
preserveRecentTokens: "nonNegativeNumber"
|
|
1377
|
+
preserveRecentTokens: "nonNegativeNumber",
|
|
1378
|
+
reasoning: "reasoningConfig"
|
|
1351
1379
|
};
|
|
1352
1380
|
const validateOverrideField = (key, type, value) => {
|
|
1353
1381
|
if (value === void 0) {
|
|
@@ -1387,6 +1415,31 @@ function validateConfigTypes(config) {
|
|
|
1387
1415
|
errors.push({ key, expected: "string[]", actual: JSON.stringify(value) });
|
|
1388
1416
|
}
|
|
1389
1417
|
break;
|
|
1418
|
+
case "reasoningConfig":
|
|
1419
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1420
|
+
errors.push({
|
|
1421
|
+
key,
|
|
1422
|
+
expected: "object { drop?: boolean; threshold?: integer (>= 0) }",
|
|
1423
|
+
actual: JSON.stringify(value)
|
|
1424
|
+
});
|
|
1425
|
+
break;
|
|
1426
|
+
}
|
|
1427
|
+
const reasoning = value;
|
|
1428
|
+
if (reasoning.drop !== void 0 && typeof reasoning.drop !== "boolean") {
|
|
1429
|
+
errors.push({
|
|
1430
|
+
key: `${key}.drop`,
|
|
1431
|
+
expected: "boolean",
|
|
1432
|
+
actual: typeof reasoning.drop
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
if (reasoning.threshold !== void 0 && (typeof reasoning.threshold !== "number" || !Number.isInteger(reasoning.threshold) || reasoning.threshold < 0)) {
|
|
1436
|
+
errors.push({
|
|
1437
|
+
key: `${key}.threshold`,
|
|
1438
|
+
expected: "integer (>= 0)",
|
|
1439
|
+
actual: JSON.stringify(reasoning.threshold)
|
|
1440
|
+
});
|
|
1441
|
+
}
|
|
1442
|
+
break;
|
|
1390
1443
|
}
|
|
1391
1444
|
};
|
|
1392
1445
|
const validateOverrideObject = (prefix, overrides) => {
|
|
@@ -1565,6 +1618,10 @@ function validateConfigTypes(config) {
|
|
|
1565
1618
|
}
|
|
1566
1619
|
|
|
1567
1620
|
// lib/config.ts
|
|
1621
|
+
var DEFAULT_COMPRESS_REASONING = {
|
|
1622
|
+
drop: true,
|
|
1623
|
+
threshold: 2048
|
|
1624
|
+
};
|
|
1568
1625
|
var DEFAULT_PROTECTED_TOOLS = [
|
|
1569
1626
|
"task",
|
|
1570
1627
|
"skill",
|
|
@@ -1659,7 +1716,8 @@ var defaultConfig = {
|
|
|
1659
1716
|
lastSegmentSoftBlock: true,
|
|
1660
1717
|
preserveRecentMessages: 5,
|
|
1661
1718
|
preserveRecentTokens: 5e3,
|
|
1662
|
-
preserveLastUserMessage: true
|
|
1719
|
+
preserveLastUserMessage: true,
|
|
1720
|
+
reasoning: { ...DEFAULT_COMPRESS_REASONING }
|
|
1663
1721
|
},
|
|
1664
1722
|
gc: {
|
|
1665
1723
|
algorithm: "truncate",
|
|
@@ -1829,7 +1887,11 @@ function mergeCompress(base, override) {
|
|
|
1829
1887
|
lastSegmentSoftBlock: override.lastSegmentSoftBlock ?? base.lastSegmentSoftBlock,
|
|
1830
1888
|
preserveRecentMessages: override.preserveRecentMessages ?? base.preserveRecentMessages,
|
|
1831
1889
|
preserveRecentTokens: override.preserveRecentTokens ?? base.preserveRecentTokens,
|
|
1832
|
-
preserveLastUserMessage: override.preserveLastUserMessage ?? base.preserveLastUserMessage
|
|
1890
|
+
preserveLastUserMessage: override.preserveLastUserMessage ?? base.preserveLastUserMessage,
|
|
1891
|
+
reasoning: {
|
|
1892
|
+
drop: override.reasoning?.drop ?? base.reasoning?.drop ?? DEFAULT_COMPRESS_REASONING.drop,
|
|
1893
|
+
threshold: override.reasoning?.threshold ?? base.reasoning?.threshold ?? DEFAULT_COMPRESS_REASONING.threshold
|
|
1894
|
+
}
|
|
1833
1895
|
};
|
|
1834
1896
|
}
|
|
1835
1897
|
function mergeCommands(base, override) {
|
|
@@ -2323,12 +2385,12 @@ function serializePruneMessagesState(messagesState) {
|
|
|
2323
2385
|
markedForCleanup: Array.from(messagesState.markedForCleanup)
|
|
2324
2386
|
};
|
|
2325
2387
|
}
|
|
2326
|
-
async function
|
|
2388
|
+
async function isSubAgentSession(client, sessionID) {
|
|
2327
2389
|
try {
|
|
2328
2390
|
const result = await client.session.get({ path: { id: sessionID } });
|
|
2329
|
-
return result.data?.parentID
|
|
2391
|
+
return !!result.data?.parentID;
|
|
2330
2392
|
} catch (error) {
|
|
2331
|
-
return
|
|
2393
|
+
return false;
|
|
2332
2394
|
}
|
|
2333
2395
|
}
|
|
2334
2396
|
function findLastCompactionTimestamp(messages) {
|
|
@@ -4365,205 +4427,6 @@ function rebuildCompressionState(state, messages, config, logger) {
|
|
|
4365
4427
|
return rebuilt;
|
|
4366
4428
|
}
|
|
4367
4429
|
|
|
4368
|
-
// lib/state/fork-transfer.ts
|
|
4369
|
-
function extractIdentity(message) {
|
|
4370
|
-
const id = message?.info?.id;
|
|
4371
|
-
if (typeof id !== "string" || id.length === 0) {
|
|
4372
|
-
return null;
|
|
4373
|
-
}
|
|
4374
|
-
if (isSyntheticMessage(message)) {
|
|
4375
|
-
return null;
|
|
4376
|
-
}
|
|
4377
|
-
const role = message.info.role;
|
|
4378
|
-
const created = message.info.time?.created;
|
|
4379
|
-
if (typeof created !== "number") {
|
|
4380
|
-
return null;
|
|
4381
|
-
}
|
|
4382
|
-
return { id, role, created };
|
|
4383
|
-
}
|
|
4384
|
-
function buildSharedPrefixMapping(parentMessages, forkMessages) {
|
|
4385
|
-
const parentIds = parentMessages.map(extractIdentity).filter((x) => x !== null);
|
|
4386
|
-
const forkIds = forkMessages.map(extractIdentity).filter((x) => x !== null);
|
|
4387
|
-
const mapping = /* @__PURE__ */ new Map();
|
|
4388
|
-
const limit = Math.min(parentIds.length, forkIds.length);
|
|
4389
|
-
for (let i = 0; i < limit; i++) {
|
|
4390
|
-
const p = parentIds[i];
|
|
4391
|
-
const f = forkIds[i];
|
|
4392
|
-
if (p.created === f.created && p.role === f.role) {
|
|
4393
|
-
mapping.set(p.id, f.id);
|
|
4394
|
-
} else {
|
|
4395
|
-
break;
|
|
4396
|
-
}
|
|
4397
|
-
}
|
|
4398
|
-
return mapping;
|
|
4399
|
-
}
|
|
4400
|
-
function remapBoundaryRef(ref, mapping, forkByRawId, parentByRef) {
|
|
4401
|
-
const parsed = parseBoundaryId(ref);
|
|
4402
|
-
if (!parsed) {
|
|
4403
|
-
return ref;
|
|
4404
|
-
}
|
|
4405
|
-
if (parsed.kind === "compressed-block") {
|
|
4406
|
-
return parsed.ref;
|
|
4407
|
-
}
|
|
4408
|
-
const parentRawId = parentByRef.get(parsed.ref);
|
|
4409
|
-
if (!parentRawId) {
|
|
4410
|
-
return ref;
|
|
4411
|
-
}
|
|
4412
|
-
const forkRawId = mapping.get(parentRawId);
|
|
4413
|
-
if (!forkRawId) {
|
|
4414
|
-
return ref;
|
|
4415
|
-
}
|
|
4416
|
-
const forkRef = forkByRawId.get(forkRawId);
|
|
4417
|
-
return forkRef ?? ref;
|
|
4418
|
-
}
|
|
4419
|
-
function translateBlock(block, mapping, forkByRawId, parentByRef) {
|
|
4420
|
-
const anchorForkId = mapping.get(block.anchorMessageId);
|
|
4421
|
-
if (!anchorForkId) {
|
|
4422
|
-
return null;
|
|
4423
|
-
}
|
|
4424
|
-
const compressForkId = mapping.get(block.compressMessageId);
|
|
4425
|
-
if (!compressForkId) {
|
|
4426
|
-
return null;
|
|
4427
|
-
}
|
|
4428
|
-
const translateList = (ids) => ids.map((id) => mapping.get(id)).filter((id) => id !== void 0);
|
|
4429
|
-
const preserveList = (ids) => [...new Set(ids)];
|
|
4430
|
-
return {
|
|
4431
|
-
...block,
|
|
4432
|
-
anchorMessageId: anchorForkId,
|
|
4433
|
-
compressMessageId: compressForkId,
|
|
4434
|
-
directMessageIds: translateList(block.directMessageIds),
|
|
4435
|
-
effectiveMessageIds: translateList(block.effectiveMessageIds),
|
|
4436
|
-
directToolIds: preserveList(block.directToolIds),
|
|
4437
|
-
effectiveToolIds: preserveList(block.effectiveToolIds),
|
|
4438
|
-
startId: remapBoundaryRef(block.startId, mapping, forkByRawId, parentByRef),
|
|
4439
|
-
endId: remapBoundaryRef(block.endId, mapping, forkByRawId, parentByRef)
|
|
4440
|
-
};
|
|
4441
|
-
}
|
|
4442
|
-
function translateByMessageId(parentByMessageId, mapping, translatedBlockIds) {
|
|
4443
|
-
const result = /* @__PURE__ */ new Map();
|
|
4444
|
-
for (const [parentMsgId, entry] of Object.entries(parentByMessageId)) {
|
|
4445
|
-
if (!entry || typeof entry !== "object") {
|
|
4446
|
-
continue;
|
|
4447
|
-
}
|
|
4448
|
-
const forkMsgId = mapping.get(parentMsgId);
|
|
4449
|
-
if (!forkMsgId) {
|
|
4450
|
-
continue;
|
|
4451
|
-
}
|
|
4452
|
-
const allBlockIds = (entry.allBlockIds ?? []).filter((id) => translatedBlockIds.has(id));
|
|
4453
|
-
const activeBlockIds = (entry.activeBlockIds ?? []).filter(
|
|
4454
|
-
(id) => translatedBlockIds.has(id)
|
|
4455
|
-
);
|
|
4456
|
-
result.set(forkMsgId, {
|
|
4457
|
-
tokenCount: typeof entry.tokenCount === "number" ? entry.tokenCount : 0,
|
|
4458
|
-
allBlockIds,
|
|
4459
|
-
activeBlockIds
|
|
4460
|
-
});
|
|
4461
|
-
}
|
|
4462
|
-
return result;
|
|
4463
|
-
}
|
|
4464
|
-
async function recoverFromParentState(client, state, forkMessages, parentId, logger) {
|
|
4465
|
-
const parentState = await loadSessionState(parentId, logger);
|
|
4466
|
-
if (!parentState) {
|
|
4467
|
-
logger.info("fork-transfer: no parent state found, falling back to replay", {
|
|
4468
|
-
parentId
|
|
4469
|
-
});
|
|
4470
|
-
return 0;
|
|
4471
|
-
}
|
|
4472
|
-
const parentMessagesState = parentState.prune?.messages;
|
|
4473
|
-
const parentBlocks = parentMessagesState?.blocksById;
|
|
4474
|
-
if (!parentBlocks) {
|
|
4475
|
-
logger.info("fork-transfer: parent state has no blocks, falling back to replay", {
|
|
4476
|
-
parentId
|
|
4477
|
-
});
|
|
4478
|
-
return 0;
|
|
4479
|
-
}
|
|
4480
|
-
const parentBlockEntries = Object.entries(parentBlocks).filter(
|
|
4481
|
-
([id, block]) => Number.isInteger(Number.parseInt(id, 10)) && Number.parseInt(id, 10) >= 1 && !!block
|
|
4482
|
-
);
|
|
4483
|
-
if (parentBlockEntries.length === 0) {
|
|
4484
|
-
logger.info("fork-transfer: parent state has no blocks, falling back to replay", {
|
|
4485
|
-
parentId
|
|
4486
|
-
});
|
|
4487
|
-
return 0;
|
|
4488
|
-
}
|
|
4489
|
-
let parentMessages;
|
|
4490
|
-
try {
|
|
4491
|
-
const response = await client.session.messages({ path: { id: parentId } });
|
|
4492
|
-
parentMessages = filterMessages(response?.data || response);
|
|
4493
|
-
} catch (error) {
|
|
4494
|
-
logger.warn("fork-transfer: failed to fetch parent messages, falling back to replay", {
|
|
4495
|
-
parentId,
|
|
4496
|
-
error: error?.message || String(error)
|
|
4497
|
-
});
|
|
4498
|
-
return 0;
|
|
4499
|
-
}
|
|
4500
|
-
const mapping = buildSharedPrefixMapping(parentMessages, forkMessages);
|
|
4501
|
-
if (mapping.size === 0) {
|
|
4502
|
-
logger.info("fork-transfer: no shared prefix detected, falling back to replay", {
|
|
4503
|
-
parentId
|
|
4504
|
-
});
|
|
4505
|
-
return 0;
|
|
4506
|
-
}
|
|
4507
|
-
assignMessageRefs(state, forkMessages);
|
|
4508
|
-
const forkByRawId = state.messageIds.byRawId;
|
|
4509
|
-
const parentByRef = new Map(Object.entries(parentState.messageIds?.byRef ?? {}));
|
|
4510
|
-
const translatedBlocks = /* @__PURE__ */ new Map();
|
|
4511
|
-
let skipped = 0;
|
|
4512
|
-
for (const [blockIdStr, block] of parentBlockEntries) {
|
|
4513
|
-
const blockId = Number.parseInt(blockIdStr, 10);
|
|
4514
|
-
const translated = translateBlock(block, mapping, forkByRawId, parentByRef);
|
|
4515
|
-
if (translated) {
|
|
4516
|
-
translatedBlocks.set(blockId, translated);
|
|
4517
|
-
} else {
|
|
4518
|
-
skipped++;
|
|
4519
|
-
}
|
|
4520
|
-
}
|
|
4521
|
-
if (translatedBlocks.size === 0) {
|
|
4522
|
-
logger.info("fork-transfer: no blocks translatable, falling back to replay", {
|
|
4523
|
-
parentId,
|
|
4524
|
-
parentBlockCount: parentBlockEntries.length,
|
|
4525
|
-
mappingSize: mapping.size
|
|
4526
|
-
});
|
|
4527
|
-
return 0;
|
|
4528
|
-
}
|
|
4529
|
-
const activeCount = Array.from(translatedBlocks.values()).filter((b) => b.active).length;
|
|
4530
|
-
if (activeCount === 0) {
|
|
4531
|
-
logger.info("fork-transfer: no active blocks translatable, falling back to replay", {
|
|
4532
|
-
parentId,
|
|
4533
|
-
recoveredBlocks: translatedBlocks.size,
|
|
4534
|
-
skippedBlocks: skipped,
|
|
4535
|
-
mappingSize: mapping.size
|
|
4536
|
-
});
|
|
4537
|
-
return 0;
|
|
4538
|
-
}
|
|
4539
|
-
const translatedByMessageId = translateByMessageId(
|
|
4540
|
-
parentMessagesState.byMessageId ?? {},
|
|
4541
|
-
mapping,
|
|
4542
|
-
new Set(translatedBlocks.keys())
|
|
4543
|
-
);
|
|
4544
|
-
state.prune.messages = loadPruneMessagesState({
|
|
4545
|
-
byMessageId: Object.fromEntries(translatedByMessageId),
|
|
4546
|
-
blocksById: Object.fromEntries(
|
|
4547
|
-
Array.from(translatedBlocks.entries()).map(
|
|
4548
|
-
([id, block]) => [String(id), block]
|
|
4549
|
-
)
|
|
4550
|
-
),
|
|
4551
|
-
activeBlockIds: [],
|
|
4552
|
-
activeByAnchorMessageId: {},
|
|
4553
|
-
nextBlockId: 1,
|
|
4554
|
-
nextRunId: 1,
|
|
4555
|
-
markedForCleanup: []
|
|
4556
|
-
});
|
|
4557
|
-
logger.info("fork-transfer: recovered compression state from parent", {
|
|
4558
|
-
parentId,
|
|
4559
|
-
recoveredBlocks: translatedBlocks.size,
|
|
4560
|
-
activeBlocks: activeCount,
|
|
4561
|
-
skippedBlocks: skipped,
|
|
4562
|
-
mappingSize: mapping.size
|
|
4563
|
-
});
|
|
4564
|
-
return activeCount;
|
|
4565
|
-
}
|
|
4566
|
-
|
|
4567
4430
|
// lib/state/state.ts
|
|
4568
4431
|
async function updatePerTurnState(state, logger, messages) {
|
|
4569
4432
|
const lastCompactionTimestamp = findLastCompactionTimestamp(messages);
|
|
@@ -4752,22 +4615,16 @@ async function ensureSessionInitialized(client, state, sessionId, logger, messag
|
|
|
4752
4615
|
}
|
|
4753
4616
|
resetSessionState(state);
|
|
4754
4617
|
state.sessionId = sessionId;
|
|
4755
|
-
const
|
|
4756
|
-
state.isSubAgent =
|
|
4618
|
+
const isSubAgent = await isSubAgentSession(client, sessionId);
|
|
4619
|
+
state.isSubAgent = isSubAgent;
|
|
4757
4620
|
state.lastCompaction = findLastCompactionTimestamp(messages);
|
|
4758
4621
|
state.currentTurn = countTurns(state, messages);
|
|
4759
4622
|
state.nudges.turnNudgeAnchors = collectTurnNudgeAnchors(messages);
|
|
4760
4623
|
const persisted = await loadSessionState(sessionId, logger);
|
|
4761
4624
|
if (persisted === null) {
|
|
4762
4625
|
if (config) {
|
|
4763
|
-
|
|
4764
|
-
if (
|
|
4765
|
-
recovered = await recoverFromParentState(client, state, messages, parentId, logger);
|
|
4766
|
-
}
|
|
4767
|
-
if (recovered === 0) {
|
|
4768
|
-
recovered = rebuildCompressionState(state, messages, config, logger);
|
|
4769
|
-
}
|
|
4770
|
-
if (recovered > 0) {
|
|
4626
|
+
const rebuilt = rebuildCompressionState(state, messages, config, logger);
|
|
4627
|
+
if (rebuilt > 0) {
|
|
4771
4628
|
await saveSessionState(state, logger);
|
|
4772
4629
|
}
|
|
4773
4630
|
}
|
|
@@ -6852,10 +6709,11 @@ function resolveCompressOverrides(config, providerId, modelId) {
|
|
|
6852
6709
|
}
|
|
6853
6710
|
const { models: _models, ...providerFields } = providerEntry;
|
|
6854
6711
|
const modelEntry = modelId !== void 0 ? providerEntry.models?.[modelId] : void 0;
|
|
6855
|
-
|
|
6856
|
-
|
|
6712
|
+
const merged = modelEntry ? { ...providerFields, ...modelEntry } : providerFields;
|
|
6713
|
+
if (providerFields.reasoning !== void 0 || modelEntry?.reasoning !== void 0) {
|
|
6714
|
+
merged.reasoning = { ...providerFields.reasoning, ...modelEntry?.reasoning };
|
|
6857
6715
|
}
|
|
6858
|
-
return
|
|
6716
|
+
return merged;
|
|
6859
6717
|
}
|
|
6860
6718
|
function resolveMinNudgeContextPercent(config, providerId, modelId) {
|
|
6861
6719
|
const overrides = resolveCompressOverrides(config, providerId, modelId);
|
|
@@ -6872,19 +6730,26 @@ function resolveMinNudgeFloorTokens(config, modelContextLimit, providerId, model
|
|
|
6872
6730
|
const clamped = Math.min(100, Math.max(0, percent));
|
|
6873
6731
|
return Math.round(clamped / 100 * modelContextLimit);
|
|
6874
6732
|
}
|
|
6875
|
-
var OVERRIDE_BLANKET_APPLY_EXCLUDE = /* @__PURE__ */ new Set([
|
|
6733
|
+
var OVERRIDE_BLANKET_APPLY_EXCLUDE = /* @__PURE__ */ new Set([
|
|
6734
|
+
"maxContextLimit",
|
|
6735
|
+
"reasoning"
|
|
6736
|
+
]);
|
|
6876
6737
|
function applyCompressOverrides(config, providerId, modelId) {
|
|
6877
6738
|
const overrides = resolveCompressOverrides(config, providerId, modelId);
|
|
6878
6739
|
const applied = Object.keys(overrides).filter(
|
|
6879
6740
|
(key) => !OVERRIDE_BLANKET_APPLY_EXCLUDE.has(key)
|
|
6880
6741
|
);
|
|
6881
|
-
|
|
6742
|
+
const reasoningOverride = overrides.reasoning;
|
|
6743
|
+
if (applied.length === 0 && reasoningOverride === void 0 || !config.compress) {
|
|
6882
6744
|
return config;
|
|
6883
6745
|
}
|
|
6884
6746
|
const effectiveCompress = { ...config.compress };
|
|
6885
6747
|
for (const key of applied) {
|
|
6886
6748
|
effectiveCompress[key] = overrides[key];
|
|
6887
6749
|
}
|
|
6750
|
+
if (reasoningOverride !== void 0) {
|
|
6751
|
+
effectiveCompress.reasoning = { ...config.compress.reasoning, ...reasoningOverride };
|
|
6752
|
+
}
|
|
6888
6753
|
return { ...config, compress: effectiveCompress };
|
|
6889
6754
|
}
|
|
6890
6755
|
function addAnchor(anchorMessageIds, anchorMessageId, anchorMessageIndex, messages, interval) {
|
|
@@ -8467,6 +8332,46 @@ function stripStaleMetadata(messages) {
|
|
|
8467
8332
|
});
|
|
8468
8333
|
});
|
|
8469
8334
|
}
|
|
8335
|
+
function dropCompressReasoning(messages, threshold) {
|
|
8336
|
+
const lastUserMessage = getLastUserMessage(messages);
|
|
8337
|
+
if (!lastUserMessage || lastUserMessage.info.role !== "user") {
|
|
8338
|
+
return 0;
|
|
8339
|
+
}
|
|
8340
|
+
const lastUserIndex = messages.lastIndexOf(lastUserMessage);
|
|
8341
|
+
if (lastUserIndex <= 0) {
|
|
8342
|
+
return 0;
|
|
8343
|
+
}
|
|
8344
|
+
let removed = 0;
|
|
8345
|
+
for (let i = 0; i < lastUserIndex; i++) {
|
|
8346
|
+
const message = messages[i];
|
|
8347
|
+
if (!message || message.info.role !== "assistant") {
|
|
8348
|
+
continue;
|
|
8349
|
+
}
|
|
8350
|
+
const parts = Array.isArray(message.parts) ? message.parts : [];
|
|
8351
|
+
let hasCompressTool = false;
|
|
8352
|
+
let reasoningLength = 0;
|
|
8353
|
+
for (const part of parts) {
|
|
8354
|
+
if (part.type === "tool" && part.tool === "compress") {
|
|
8355
|
+
hasCompressTool = true;
|
|
8356
|
+
} else if (part.type === "reasoning") {
|
|
8357
|
+
reasoningLength += part.text.length;
|
|
8358
|
+
}
|
|
8359
|
+
}
|
|
8360
|
+
if (!hasCompressTool) {
|
|
8361
|
+
continue;
|
|
8362
|
+
}
|
|
8363
|
+
if (reasoningLength <= threshold) {
|
|
8364
|
+
continue;
|
|
8365
|
+
}
|
|
8366
|
+
const filtered = parts.filter((part) => part.type !== "reasoning");
|
|
8367
|
+
if (filtered.length === parts.length) {
|
|
8368
|
+
continue;
|
|
8369
|
+
}
|
|
8370
|
+
message.parts = filtered;
|
|
8371
|
+
removed += parts.length - filtered.length;
|
|
8372
|
+
}
|
|
8373
|
+
return removed;
|
|
8374
|
+
}
|
|
8470
8375
|
|
|
8471
8376
|
// lib/messages/priority.ts
|
|
8472
8377
|
function buildPriorityMap(_config, _state, _messages) {
|
|
@@ -9583,7 +9488,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
|
9583
9488
|
import { join as join3 } from "path";
|
|
9584
9489
|
import { existsSync as existsSync3 } from "fs";
|
|
9585
9490
|
import { homedir as homedir3 } from "os";
|
|
9586
|
-
var LOG_VERSION = true ? "1.14.27-pr.
|
|
9491
|
+
var LOG_VERSION = true ? "1.14.27-pr.377.112" : "dev";
|
|
9587
9492
|
var LEVEL_RANK = {
|
|
9588
9493
|
debug: 10,
|
|
9589
9494
|
info: 20,
|
|
@@ -11575,6 +11480,24 @@ function createChatMessageTransformHandler(client, registry4, logger, config, pr
|
|
|
11575
11480
|
return;
|
|
11576
11481
|
}
|
|
11577
11482
|
stripHallucinations(output.messages);
|
|
11483
|
+
const dropReasoningModel = lastUserMessage?.info?.model;
|
|
11484
|
+
const reasoningConfig = applyCompressOverrides(
|
|
11485
|
+
config,
|
|
11486
|
+
dropReasoningModel?.providerID ?? state.modelProviderID,
|
|
11487
|
+
dropReasoningModel?.modelID ?? state.modelID
|
|
11488
|
+
).compress.reasoning;
|
|
11489
|
+
if (reasoningConfig?.drop !== false) {
|
|
11490
|
+
const droppedReasoning = dropCompressReasoning(
|
|
11491
|
+
output.messages,
|
|
11492
|
+
reasoningConfig?.threshold ?? DEFAULT_COMPRESS_REASONING.threshold
|
|
11493
|
+
);
|
|
11494
|
+
if (droppedReasoning > 0) {
|
|
11495
|
+
logger.debug("compress.reasoning: dropped oversized reasoning parts", {
|
|
11496
|
+
dropped: droppedReasoning,
|
|
11497
|
+
threshold: reasoningConfig?.threshold ?? DEFAULT_COMPRESS_REASONING.threshold
|
|
11498
|
+
});
|
|
11499
|
+
}
|
|
11500
|
+
}
|
|
11578
11501
|
ensureBuiltinFiltersRegistered();
|
|
11579
11502
|
applyMessageFilters(output.messages, config.messageFilters, logger, {
|
|
11580
11503
|
sessionId: state.sessionId ?? "",
|
|
@@ -12056,7 +11979,7 @@ var server = (async (ctx) => {
|
|
|
12056
11979
|
}
|
|
12057
11980
|
const logger = new Logger(config.debug, config.debug ? "debug" : config.logLevel);
|
|
12058
11981
|
logger.info("ACP plugin initialized", {
|
|
12059
|
-
version: true ? "1.14.27-pr.
|
|
11982
|
+
version: true ? "1.14.27-pr.377.112" : "dev",
|
|
12060
11983
|
workspace: ctx.directory,
|
|
12061
11984
|
logLevel: logger.level,
|
|
12062
11985
|
debug: config.debug,
|