opencode-acp 1.18.4-pr.484.217 → 1.18.4-pr.488.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/README.md CHANGED
@@ -431,15 +431,9 @@ Each level overrides the previous, so project settings take priority over global
431
431
  // compression, so their thinking rides along every request as an
432
432
  // unreclaimable floor. Closed turns only; the active round is never
433
433
  // touched. Small thinkings under the threshold are kept.
434
- // [#482] Pin the wire form of historical thinking: fold each assistant
435
- // message's reasoning parts into one <thinking>-marked text part at
436
- // request time, so serialized bytes stay deterministic across host
437
- // metadata-table refreshes. On by default; set normalize:false for
438
- // direct providers needing structured thinking replay.
439
434
  "reasoning": {
440
435
  "drop": true,
441
436
  "threshold": 2048,
442
- "normalize": true
443
437
  },
444
438
  // [#478] Image archive: spill data-URL images to disk when they enter
445
439
  // the session so folded ranges keep re-readable pointers instead of
package/README.zh-CN.md CHANGED
@@ -376,14 +376,9 @@ ACP 使用自己的配置文件,按以下顺序搜索:
376
376
  // compress 调用被硬排除在压缩之外,其思考内容会随每次请求原样重发,
377
377
  // 形成无法回收的上下文底座。仅作用于已关闭的轮次,活跃轮永不触碰;
378
378
  // 低于阈值的小思考保留。
379
- // [#482] 钉死历史思考的 wire 形态:请求时把每个 assistant 消息的
380
- // reasoning 部分折叠为一个带 <thinking> 标记的 text 部分,使序列化字节
381
- // 在宿主元数据表刷新后保持确定。默认开启;直连需要结构化 thinking
382
- // 回放的 provider 设 normalize:false。
383
379
  "reasoning": {
384
380
  "drop": true,
385
381
  "threshold": 2048,
386
- "normalize": true
387
382
  },
388
383
  // [#478] 图片归档:图片(data-URL)进入会话时即落盘,折叠后摘要里保留
389
384
  // 可重读的路径指针,而不是把像素悄悄丢掉。文件落在
package/dist/index.js CHANGED
@@ -916,12 +916,12 @@ var VALID_CONFIG_KEYS = /* @__PURE__ */ new Set([
916
916
  "compress.reasoning",
917
917
  "compress.reasoning.drop",
918
918
  "compress.reasoning.threshold",
919
- "compress.reasoning.normalize",
920
919
  "compress.images",
921
920
  "compress.images.enabled",
922
921
  "compress.images.minBytes",
923
922
  "compress.images.ttlDays",
924
923
  "compress.completionReserveTokens",
924
+ "compress.emergencyTruncation",
925
925
  "gc",
926
926
  "gc.algorithm",
927
927
  "gc.promotionThreshold",
@@ -1293,7 +1293,7 @@ function validateConfigTypes(config) {
1293
1293
  if (typeof compress.reasoning !== "object" || compress.reasoning === null || Array.isArray(compress.reasoning)) {
1294
1294
  errors.push({
1295
1295
  key: "compress.reasoning",
1296
- expected: "object { drop?: boolean; threshold?: integer (>= 0); normalize?: boolean }",
1296
+ expected: "object { drop?: boolean; threshold?: integer (>= 0) }",
1297
1297
  actual: JSON.stringify(compress.reasoning)
1298
1298
  });
1299
1299
  } else {
@@ -1311,13 +1311,6 @@ function validateConfigTypes(config) {
1311
1311
  actual: JSON.stringify(compress.reasoning.threshold)
1312
1312
  });
1313
1313
  }
1314
- if (compress.reasoning.normalize !== void 0 && typeof compress.reasoning.normalize !== "boolean") {
1315
- errors.push({
1316
- key: "compress.reasoning.normalize",
1317
- expected: "boolean",
1318
- actual: typeof compress.reasoning.normalize
1319
- });
1320
- }
1321
1314
  }
1322
1315
  }
1323
1316
  if (compress.images !== void 0) {
@@ -1358,6 +1351,13 @@ function validateConfigTypes(config) {
1358
1351
  actual: typeof compress.completionReserveTokens
1359
1352
  });
1360
1353
  }
1354
+ if (compress.emergencyTruncation !== void 0 && typeof compress.emergencyTruncation !== "boolean") {
1355
+ errors.push({
1356
+ key: "compress.emergencyTruncation",
1357
+ expected: "boolean",
1358
+ actual: typeof compress.emergencyTruncation
1359
+ });
1360
+ }
1361
1361
  if (typeof compress.completionReserveTokens === "number" && compress.completionReserveTokens < 0) {
1362
1362
  errors.push({
1363
1363
  key: "compress.completionReserveTokens",
@@ -1430,6 +1430,7 @@ function validateConfigTypes(config) {
1430
1430
  const OVERRIDE_FIELD_TYPES = {
1431
1431
  showCompression: "boolean",
1432
1432
  summaryBuffer: "boolean",
1433
+ emergencyTruncation: "boolean",
1433
1434
  protectTags: "boolean",
1434
1435
  protectUserMessages: "boolean",
1435
1436
  lastSegmentSoftBlock: "boolean",
@@ -1504,7 +1505,7 @@ function validateConfigTypes(config) {
1504
1505
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
1505
1506
  errors.push({
1506
1507
  key,
1507
- expected: "object { drop?: boolean; threshold?: integer (>= 0); normalize?: boolean }",
1508
+ expected: "object { drop?: boolean; threshold?: integer (>= 0) }",
1508
1509
  actual: JSON.stringify(value)
1509
1510
  });
1510
1511
  break;
@@ -1524,13 +1525,6 @@ function validateConfigTypes(config) {
1524
1525
  actual: JSON.stringify(reasoning.threshold)
1525
1526
  });
1526
1527
  }
1527
- if (reasoning.normalize !== void 0 && typeof reasoning.normalize !== "boolean") {
1528
- errors.push({
1529
- key: `${key}.normalize`,
1530
- expected: "boolean",
1531
- actual: typeof reasoning.normalize
1532
- });
1533
- }
1534
1528
  break;
1535
1529
  }
1536
1530
  };
@@ -1824,6 +1818,7 @@ var defaultConfig = {
1824
1818
  permission: "allow",
1825
1819
  showCompression: true,
1826
1820
  summaryBuffer: true,
1821
+ emergencyTruncation: false,
1827
1822
  candidates: false,
1828
1823
  maxContextLimit: "80%",
1829
1824
  minContextLimit: "80%",
@@ -1991,7 +1986,6 @@ function mergeCompress(base, override) {
1991
1986
  if (!override) {
1992
1987
  return base;
1993
1988
  }
1994
- const normalizeResolved = override.reasoning?.normalize ?? base.reasoning?.normalize;
1995
1989
  return {
1996
1990
  permission: override.permission ?? base.permission,
1997
1991
  showCompression: override.showCompression ?? base.showCompression,
@@ -2026,15 +2020,15 @@ function mergeCompress(base, override) {
2026
2020
  preserveLastUserMessage: override.preserveLastUserMessage ?? base.preserveLastUserMessage,
2027
2021
  reasoning: {
2028
2022
  drop: override.reasoning?.drop ?? base.reasoning?.drop ?? DEFAULT_COMPRESS_REASONING.drop,
2029
- threshold: override.reasoning?.threshold ?? base.reasoning?.threshold ?? DEFAULT_COMPRESS_REASONING.threshold,
2030
- ...normalizeResolved !== void 0 ? { normalize: normalizeResolved } : {}
2023
+ threshold: override.reasoning?.threshold ?? base.reasoning?.threshold ?? DEFAULT_COMPRESS_REASONING.threshold
2031
2024
  },
2032
2025
  images: {
2033
2026
  enabled: override.images?.enabled ?? base.images?.enabled ?? DEFAULT_COMPRESS_IMAGES.enabled,
2034
2027
  minBytes: override.images?.minBytes ?? base.images?.minBytes ?? DEFAULT_COMPRESS_IMAGES.minBytes,
2035
2028
  ttlDays: override.images?.ttlDays ?? base.images?.ttlDays ?? DEFAULT_COMPRESS_IMAGES.ttlDays
2036
2029
  },
2037
- completionReserveTokens: override.completionReserveTokens ?? base.completionReserveTokens
2030
+ completionReserveTokens: override.completionReserveTokens ?? base.completionReserveTokens,
2031
+ emergencyTruncation: override.emergencyTruncation ?? base.emergencyTruncation
2038
2032
  };
2039
2033
  }
2040
2034
  function mergeCommands(base, override) {
@@ -2972,7 +2966,8 @@ function saveSessionState(sessionState, logger, sessionName) {
2972
2966
  modelContextLimit: sessionState.modelContextLimit,
2973
2967
  modelProviderID: sessionState.modelProviderID,
2974
2968
  modelID: sessionState.modelID,
2975
- imageArchive: sessionState.imageArchive
2969
+ imageArchive: sessionState.imageArchive,
2970
+ stickyTruncations: sessionState.stickyTruncations
2976
2971
  };
2977
2972
  const key = saveQueueKey(sessionState.sessionId, sessionState.storageDir);
2978
2973
  let queue = saveQueues.get(key);
@@ -5141,7 +5136,8 @@ function createSessionState() {
5141
5136
  qualityGateRetryPending: false,
5142
5137
  noContextLimitWarned: false,
5143
5138
  imageArchive: {},
5144
- imagePruneDone: false
5139
+ imagePruneDone: false,
5140
+ stickyTruncations: {}
5145
5141
  };
5146
5142
  }
5147
5143
  function resetSessionState(state) {
@@ -5187,6 +5183,7 @@ function resetSessionState(state) {
5187
5183
  state.noContextLimitWarned = false;
5188
5184
  state.imageArchive = {};
5189
5185
  state.imagePruneDone = false;
5186
+ state.stickyTruncations = {};
5190
5187
  }
5191
5188
  async function ensureSessionInitialized(client, state, sessionId, logger, messages, config, projectDir) {
5192
5189
  if (state.sessionId === sessionId) {
@@ -5215,6 +5212,13 @@ async function ensureSessionInitialized(client, state, sessionId, logger, messag
5215
5212
  if (parentSessionId) {
5216
5213
  try {
5217
5214
  const parent = await loadSessionState(parentSessionId, logger);
5215
+ if (parent?.stickyTruncations) {
5216
+ for (const [callID, output] of Object.entries(parent.stickyTruncations)) {
5217
+ if (typeof output === "string") {
5218
+ state.stickyTruncations[callID] = output;
5219
+ }
5220
+ }
5221
+ }
5218
5222
  const response = parent ? await client.session.messages({ path: { id: parentSessionId } }) : void 0;
5219
5223
  const parentMessages = Array.isArray(response?.data) ? response.data : Array.isArray(response) ? response : [];
5220
5224
  if (parent && parentMessages.length > 0) {
@@ -5280,6 +5284,14 @@ async function ensureSessionInitialized(client, state, sessionId, logger, messag
5280
5284
  }
5281
5285
  }
5282
5286
  }
5287
+ const persistedSticky = persisted.stickyTruncations;
5288
+ if (persistedSticky && typeof persistedSticky === "object") {
5289
+ for (const [callID, output] of Object.entries(persistedSticky)) {
5290
+ if (typeof output === "string") {
5291
+ state.stickyTruncations[callID] = output;
5292
+ }
5293
+ }
5294
+ }
5283
5295
  const persistedAny = persisted;
5284
5296
  if (persistedAny._persistedMessageIds) {
5285
5297
  state.messageIds = {
@@ -9901,8 +9913,6 @@ var injectMessageIds = (state, config, messages, compressionPriorities) => {
9901
9913
  };
9902
9914
 
9903
9915
  // lib/messages/reasoning-strip.ts
9904
- var isReasoningWithText = (part) => part.type === "reasoning" && typeof part.text === "string";
9905
- var isTextWithText = (part) => part.type === "text" && typeof part.text === "string";
9906
9916
  function stripStaleMetadata(messages) {
9907
9917
  const lastUserMessage = getLastUserMessage(messages);
9908
9918
  if (lastUserMessage?.info.role !== "user") {
@@ -9971,61 +9981,6 @@ function dropCompressReasoning(messages, threshold) {
9971
9981
  }
9972
9982
  return removed;
9973
9983
  }
9974
- function normalizeThinkingForm(messages) {
9975
- let normalized = 0;
9976
- for (const message of messages) {
9977
- if (!message || message.info.role !== "assistant") {
9978
- continue;
9979
- }
9980
- const parts = Array.isArray(message.parts) ? message.parts : [];
9981
- const reasoningParts = parts.filter(isReasoningWithText);
9982
- if (reasoningParts.length === 0) {
9983
- continue;
9984
- }
9985
- const R = reasoningParts.map((part) => part.text).join("");
9986
- const textParts = parts.filter(isTextWithText);
9987
- const T = textParts.map((part) => part.text).join("");
9988
- const mergedText = `<thinking>
9989
- ${R}
9990
- </thinking>` + (T.length > 0 ? `
9991
- ${T}` : "");
9992
- const donor = textParts[0];
9993
- const newParts = [];
9994
- let inserted = false;
9995
- for (const part of parts) {
9996
- if (part.type === "reasoning" || part.type === "text") {
9997
- if (!inserted) {
9998
- if (donor) {
9999
- newParts.push({ ...donor, text: mergedText });
10000
- } else {
10001
- newParts.push({
10002
- id: `${message.info.id}-acp-think`,
10003
- sessionID: message.info.sessionID,
10004
- messageID: message.info.id,
10005
- type: "text",
10006
- text: mergedText
10007
- });
10008
- }
10009
- inserted = true;
10010
- }
10011
- continue;
10012
- }
10013
- newParts.push(part);
10014
- }
10015
- if (!inserted) {
10016
- newParts.unshift({
10017
- id: `${message.info.id}-acp-think`,
10018
- sessionID: message.info.sessionID,
10019
- messageID: message.info.id,
10020
- type: "text",
10021
- text: mergedText
10022
- });
10023
- }
10024
- message.parts = newParts;
10025
- normalized++;
10026
- }
10027
- return normalized;
10028
- }
10029
9984
 
10030
9985
  // lib/messages/priority.ts
10031
9986
  function buildPriorityMap(_config, _state, _messages) {
@@ -11403,7 +11358,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
11403
11358
  import { join as join5 } from "path";
11404
11359
  import { existsSync as existsSync5 } from "fs";
11405
11360
  import { homedir as homedir3 } from "os";
11406
- var LOG_VERSION = true ? "1.18.4-pr.484.217" : "dev";
11361
+ var LOG_VERSION = true ? "1.18.4-pr.488.221" : "dev";
11407
11362
  var LEVEL_RANK = {
11408
11363
  debug: 10,
11409
11364
  info: 20,
@@ -12258,6 +12213,7 @@ function truncateLargeToolOutputs(state, config, logger, messages) {
12258
12213
  const part = parts[pi];
12259
12214
  if (part?.type !== "tool") continue;
12260
12215
  if (part.state?.status !== "completed") continue;
12216
+ if (part.tool === "compress") continue;
12261
12217
  const content = extractCompletedToolOutput(part);
12262
12218
  if (content === void 0) continue;
12263
12219
  if (content === "[Old tool result content cleared]") continue;
@@ -12298,6 +12254,74 @@ function truncateLargeToolOutputs(state, config, logger, messages) {
12298
12254
  }
12299
12255
  }
12300
12256
 
12257
+ // lib/messages/sticky-truncation.ts
12258
+ function collectToolParts(messages) {
12259
+ const parts = [];
12260
+ for (const message of messages) {
12261
+ const messageParts = Array.isArray(message.parts) ? message.parts : [];
12262
+ for (const part of messageParts) {
12263
+ if (part?.type === "tool") {
12264
+ parts.push(part);
12265
+ }
12266
+ }
12267
+ }
12268
+ return parts;
12269
+ }
12270
+ function applyStickyTruncations(state, messages, logger) {
12271
+ const frozen = state.stickyTruncations;
12272
+ if (Object.keys(frozen).length === 0) return;
12273
+ let replayed = 0;
12274
+ const seen = /* @__PURE__ */ new Set();
12275
+ for (const part of collectToolParts(messages)) {
12276
+ const callID = typeof part.callID === "string" ? part.callID : void 0;
12277
+ if (!callID) continue;
12278
+ seen.add(callID);
12279
+ const recorded = frozen[callID];
12280
+ if (recorded === void 0) continue;
12281
+ if (!part.state) continue;
12282
+ if (part.state.output === recorded) continue;
12283
+ part.state.output = recorded;
12284
+ replayed++;
12285
+ }
12286
+ for (const callID of Object.keys(frozen)) {
12287
+ if (!seen.has(callID)) delete frozen[callID];
12288
+ }
12289
+ if (replayed > 0) {
12290
+ logger.debug("Sticky truncation: replayed frozen tool outputs", {
12291
+ replayed,
12292
+ frozen: Object.keys(frozen).length
12293
+ });
12294
+ }
12295
+ }
12296
+ function snapshotToolOutputs(messages) {
12297
+ const snapshot = /* @__PURE__ */ new Map();
12298
+ for (const part of collectToolParts(messages)) {
12299
+ const callID = typeof part.callID === "string" ? part.callID : void 0;
12300
+ if (!callID) continue;
12301
+ const content = extractCompletedToolOutput(part);
12302
+ if (content === void 0) continue;
12303
+ snapshot.set(callID, content);
12304
+ }
12305
+ return snapshot;
12306
+ }
12307
+ function recordStickyTruncations(state, messages, before, logger) {
12308
+ let recorded = 0;
12309
+ for (const part of collectToolParts(messages)) {
12310
+ const callID = typeof part.callID === "string" ? part.callID : void 0;
12311
+ if (!callID) continue;
12312
+ if (typeof part.state?.output !== "string") continue;
12313
+ const prior = before.get(callID);
12314
+ if (prior === void 0 || prior === part.state.output) continue;
12315
+ if (state.stickyTruncations[callID] === part.state.output) continue;
12316
+ state.stickyTruncations[callID] = part.state.output;
12317
+ recorded++;
12318
+ }
12319
+ if (recorded > 0) {
12320
+ logger.info("Sticky truncation: froze truncated tool outputs", { recorded });
12321
+ }
12322
+ return recorded;
12323
+ }
12324
+
12301
12325
  // lib/messages/enforce-budget.ts
12302
12326
  var DEFAULT_COMPLETION_RESERVE_TOKENS = 32768;
12303
12327
  var TRUNCATION_MARKER2 = "[truncated for context space";
@@ -13602,14 +13626,6 @@ function createChatMessageTransformHandler(client, registry4, logger, config, pr
13602
13626
  });
13603
13627
  }
13604
13628
  }
13605
- if (reasoningConfig?.normalize !== false) {
13606
- const normalizedThinking = normalizeThinkingForm(output.messages);
13607
- if (normalizedThinking > 0) {
13608
- logger.debug("compress.reasoning: pinned thinking wire form", {
13609
- normalizedMessages: normalizedThinking
13610
- });
13611
- }
13612
- }
13613
13629
  ensureBuiltinFiltersRegistered();
13614
13630
  const effectiveLimit = resolveEffectiveContextLimit(state, config);
13615
13631
  applyMessageFilters(output.messages, config.messageFilters, logger, {
@@ -13676,13 +13692,32 @@ ${text}`);
13676
13692
  prePruneTokens,
13677
13693
  candidateMessages
13678
13694
  );
13679
- truncateLargeToolOutputs(
13680
- state,
13695
+ const emergencyTruncationEnabled = applyCompressOverrides(
13681
13696
  config,
13682
- logger,
13683
- output.messages.filter((message) => !isSyntheticMessage(message))
13684
- );
13685
- enforceContextBudget(state, config, logger, output.messages);
13697
+ dropReasoningModel?.providerID ?? state.modelProviderID,
13698
+ dropReasoningModel?.modelID ?? state.modelID
13699
+ ).compress.emergencyTruncation;
13700
+ if (emergencyTruncationEnabled === true) {
13701
+ applyStickyTruncations(state, output.messages, logger);
13702
+ const toolOutputsBefore = snapshotToolOutputs(output.messages);
13703
+ truncateLargeToolOutputs(
13704
+ state,
13705
+ config,
13706
+ logger,
13707
+ output.messages.filter((message) => !isSyntheticMessage(message))
13708
+ );
13709
+ enforceContextBudget(state, config, logger, output.messages);
13710
+ const frozenCount = recordStickyTruncations(
13711
+ state,
13712
+ output.messages,
13713
+ toolOutputsBefore,
13714
+ logger
13715
+ );
13716
+ if (frozenCount > 0) {
13717
+ saveSessionState(state, logger).catch(() => {
13718
+ });
13719
+ }
13720
+ }
13686
13721
  injectMessageIds(state, config, output.messages, compressionPriorities);
13687
13722
  hideFailedCompressCalls(output.messages);
13688
13723
  stripStaleMetadata(output.messages);
@@ -14121,7 +14156,7 @@ var server = (async (ctx) => {
14121
14156
  }
14122
14157
  const logger = new Logger(config.debug, config.debug ? "debug" : config.logLevel);
14123
14158
  logger.info("ACP plugin initialized", {
14124
- version: true ? "1.18.4-pr.484.217" : "dev",
14159
+ version: true ? "1.18.4-pr.488.221" : "dev",
14125
14160
  workspace: ctx.directory,
14126
14161
  logLevel: logger.level,
14127
14162
  debug: config.debug,