opencode-acp 1.14.22-pr.323.38 → 1.14.22-pr.325.40

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 CHANGED
@@ -7192,7 +7192,9 @@ function refNum(ref) {
7192
7192
  function buildCompressibleRanges(messages, state, protectedTools = [], protectedFilePatterns = [], protectedZoneRefs) {
7193
7193
  const msgInfo = [];
7194
7194
  const protectedMsgInfo = [];
7195
- for (const msg of messages) {
7195
+ const lastUserRefIdx = [];
7196
+ for (let mi = 0; mi < messages.length; mi++) {
7197
+ const msg = messages[mi];
7196
7198
  if (isSyntheticMessage(msg)) continue;
7197
7199
  const ref = state.messageIds.byRawId.get(msg.info.id);
7198
7200
  if (!ref) continue;
@@ -7227,15 +7229,27 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7227
7229
  }
7228
7230
  let tokens = 0;
7229
7231
  let isTool = false;
7232
+ let hasMeaningfulPart = false;
7230
7233
  for (const part of msg.parts || []) {
7231
7234
  if (part.type === "text" && typeof part.text === "string") {
7232
7235
  tokens += Math.round(part.text.length / 4);
7236
+ if (part.text.trim().length > 0) hasMeaningfulPart = true;
7233
7237
  } else if (part.type !== "text" && part.type !== "reasoning") {
7234
7238
  tokens += Math.round(JSON.stringify(part).length / 4);
7235
7239
  isTool = true;
7240
+ hasMeaningfulPart = true;
7236
7241
  }
7237
7242
  }
7238
- msgInfo.push({ ref, refNum: rn, tokens, isTool, isUser: msg.info.role === "user" });
7243
+ if (msg.info.role === "user" && !isIgnoredUserMessage(msg)) {
7244
+ lastUserRefIdx.length = 0;
7245
+ lastUserRefIdx.push(msgInfo.length);
7246
+ }
7247
+ msgInfo.push({ ref, refNum: rn, tokens, effectiveTokens: 0, meaningful: hasMeaningfulPart, isTool, isUser: msg.info.role === "user" });
7248
+ }
7249
+ const lastUserIdx = lastUserRefIdx.length > 0 ? lastUserRefIdx[0] : -1;
7250
+ for (let i = 0; i < msgInfo.length; i++) {
7251
+ const info = msgInfo[i];
7252
+ info.effectiveTokens = i !== lastUserIdx && info.meaningful ? info.tokens : 0;
7239
7253
  }
7240
7254
  const groups = [];
7241
7255
  let cur = null;
@@ -7261,6 +7275,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7261
7275
  endRef: info.ref,
7262
7276
  count: 1,
7263
7277
  tokens: info.tokens,
7278
+ effectiveTokens: info.effectiveTokens,
7264
7279
  toolPct: info.isTool ? 100 : 0,
7265
7280
  textPct: info.isTool ? 0 : 100
7266
7281
  };
@@ -7268,6 +7283,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7268
7283
  cur.endRef = info.ref;
7269
7284
  cur.count++;
7270
7285
  cur.tokens += info.tokens;
7286
+ cur.effectiveTokens += info.effectiveTokens;
7271
7287
  if (info.isTool) {
7272
7288
  cur.toolPct = Math.round((cur.toolPct * (cur.count - 1) + 100) / cur.count);
7273
7289
  } else {
@@ -7310,6 +7326,11 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7310
7326
  protected: protectedGroups
7311
7327
  };
7312
7328
  }
7329
+ var EFFECTIVE_MIN_COMPRESSIBLE_TOKENS = 1250;
7330
+ function resolveEffectiveFloor(config) {
7331
+ const minChars = config.compress?.minCompressRange ?? 5e3;
7332
+ return minChars > 0 ? Math.floor(minChars / 4) : 0;
7333
+ }
7313
7334
  function filterRecommendedRanges(compressible, _protectedRanges, options) {
7314
7335
  const { logger } = options;
7315
7336
  const log = logger?.debug.bind(logger);
@@ -7317,12 +7338,22 @@ function filterRecommendedRanges(compressible, _protectedRanges, options) {
7317
7338
  log?.("filterRecommendedRanges: no compressible ranges, returning empty");
7318
7339
  return [];
7319
7340
  }
7320
- const result = compressible.map(
7321
- (r, i) => i === compressible.length - 1 ? { ...r, dangerous: true } : r
7341
+ const floor = options.minEffectiveTokens ?? EFFECTIVE_MIN_COMPRESSIBLE_TOKENS;
7342
+ const kept = compressible.filter((r) => {
7343
+ const effective = r.effectiveTokens ?? r.tokens;
7344
+ return effective > 0 && effective >= floor;
7345
+ });
7346
+ const result = kept.map(
7347
+ (r, i) => i === kept.length - 1 ? { ...r, dangerous: true } : r
7322
7348
  );
7323
- log?.("filterRecommendedRanges: passthrough (last segment marked dangerous)", {
7349
+ log?.("filterRecommendedRanges: effective-token floor applied", {
7324
7350
  inputRanges: compressible.length,
7325
- outputRanges: result.length
7351
+ outputRanges: result.length,
7352
+ floor,
7353
+ dropped: compressible.filter((r) => {
7354
+ const effective = r.effectiveTokens ?? r.tokens;
7355
+ return effective <= 0 || effective < floor;
7356
+ }).map((r) => `${r.startRef}\u2013${r.endRef} (${r.effectiveTokens ?? r.tokens} eff tokens)`)
7326
7357
  });
7327
7358
  return result;
7328
7359
  }
@@ -7331,8 +7362,10 @@ function formatCompressibleRanges(ranges, protectedRanges) {
7331
7362
  if (!protectedRanges || protectedRanges.length === 0) {
7332
7363
  if (ranges.length === 0) return "";
7333
7364
  const lines2 = ranges.map((r) => {
7365
+ const eff = r.effectiveTokens ?? r.tokens;
7366
+ const size = eff < r.tokens ? `${fmt(eff)} effective of ${fmt(r.tokens)}` : fmt(r.tokens);
7334
7367
  const suffix = r.dangerous ? " \u26A0\uFE0F NOT recommended unless you are certain. If you MUST compress this, pass `dangerous: true`." : "";
7335
- return ` ${r.startRef}\u2013${r.endRef} ${r.count} msgs ${fmt(r.tokens)} [tool ${r.toolPct}% | text ${r.textPct}%]${suffix}`;
7368
+ return ` ${r.startRef}\u2013${r.endRef} ${r.count} msgs ${size} [tool ${r.toolPct}% | text ${r.textPct}%]${suffix}`;
7336
7369
  });
7337
7370
  return `Compressible ranges (oldest first):
7338
7371
  ${lines2.join("\n")}`;
@@ -7348,7 +7381,7 @@ ${lines2.join("\n")}`;
7348
7381
  tokens: r.tokens,
7349
7382
  toolPct: r.toolPct,
7350
7383
  textPct: r.textPct,
7351
- compressibleTokens: r.tokens,
7384
+ compressibleTokens: r.effectiveTokens ?? r.tokens,
7352
7385
  compressibleCount: r.count,
7353
7386
  protectedTokens: 0,
7354
7387
  protectedCount: 0,
@@ -7637,12 +7670,13 @@ var injectCompressNudges = (state, config, logger, messages, prompts, compressio
7637
7670
  const recommendedRanges = filterRecommendedRanges(
7638
7671
  unprotectedCompressible,
7639
7672
  contextRanges.protected,
7640
- { logger }
7673
+ { logger, minEffectiveTokens: resolveEffectiveFloor(config) }
7641
7674
  );
7642
7675
  const hasRecommendations = recommendedRanges.length > 0;
7643
7676
  const allProtected = contextRanges.compressible.length === 0 && contextRanges.protected.length > 0;
7644
7677
  const allInProtectedZone = protectedRefs.size > 0 && unprotectedCompressible.length === 0;
7645
- const nothingToCompress = allProtected || allInProtectedZone;
7678
+ const allBelowMin = contextRanges.compressible.length > 0 && recommendedRanges.length === 0;
7679
+ const nothingToCompress = allProtected || allInProtectedZone || allBelowMin;
7646
7680
  const shouldInjectNudge = nudgeAllowed && (!nothingToCompress || emergencyOverride);
7647
7681
  let shouldInject = shouldInjectNudge;
7648
7682
  if (shouldInjectNudge) {
@@ -9032,7 +9066,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
9032
9066
  import { join as join3 } from "path";
9033
9067
  import { existsSync as existsSync3 } from "fs";
9034
9068
  import { homedir as homedir3 } from "os";
9035
- var LOG_VERSION = true ? "1.14.22-pr.323.38" : "dev";
9069
+ var LOG_VERSION = true ? "1.14.22-pr.325.40" : "dev";
9036
9070
  var Logger = class {
9037
9071
  logDir;
9038
9072
  enabled;