opencode-acp 1.14.21 → 1.14.22-pr.325.39

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
@@ -4523,6 +4523,9 @@ function formatProgressBar(messageIds, prunedMessages, recentMessageIds, width =
4523
4523
  return `\u2502${bar.join("")}\u2502`;
4524
4524
  }
4525
4525
  function cacheSystemPromptTokens(state, messages) {
4526
+ if (state.systemPromptTokens !== void 0 && state.systemPromptTokens > 0) {
4527
+ return;
4528
+ }
4526
4529
  let firstInputTokens = 0;
4527
4530
  for (const msg of messages) {
4528
4531
  if (msg.info.role !== "assistant") {
@@ -7165,7 +7168,7 @@ function estimateContextComposition(messages, state, protectedTools = [], protec
7165
7168
  perCode.sort((a, b) => b.tokens - a.tokens);
7166
7169
  perText.sort((a, b) => b.tokens - a.tokens);
7167
7170
  const toolTypeBreakdown = Array.from(toolTypeMap.entries()).map(([tool6, tokens]) => ({ tool: tool6, tokens })).sort((a, b) => b.tokens - a.tokens);
7168
- const systemTokens = estimateSystemPromptTokens(messages);
7171
+ const systemTokens = state?.systemPromptTokens !== void 0 && state.systemPromptTokens > 0 ? state.systemPromptTokens : estimateSystemPromptTokens(messages);
7169
7172
  return {
7170
7173
  toolTokens,
7171
7174
  codeTokens,
@@ -7189,7 +7192,9 @@ function refNum(ref) {
7189
7192
  function buildCompressibleRanges(messages, state, protectedTools = [], protectedFilePatterns = [], protectedZoneRefs) {
7190
7193
  const msgInfo = [];
7191
7194
  const protectedMsgInfo = [];
7192
- for (const msg of messages) {
7195
+ const lastUserRefIdx = [];
7196
+ for (let mi = 0; mi < messages.length; mi++) {
7197
+ const msg = messages[mi];
7193
7198
  if (isSyntheticMessage(msg)) continue;
7194
7199
  const ref = state.messageIds.byRawId.get(msg.info.id);
7195
7200
  if (!ref) continue;
@@ -7224,15 +7229,27 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7224
7229
  }
7225
7230
  let tokens = 0;
7226
7231
  let isTool = false;
7232
+ let hasMeaningfulPart = false;
7227
7233
  for (const part of msg.parts || []) {
7228
7234
  if (part.type === "text" && typeof part.text === "string") {
7229
7235
  tokens += Math.round(part.text.length / 4);
7236
+ if (part.text.trim().length > 0) hasMeaningfulPart = true;
7230
7237
  } else if (part.type !== "text" && part.type !== "reasoning") {
7231
7238
  tokens += Math.round(JSON.stringify(part).length / 4);
7232
7239
  isTool = true;
7240
+ hasMeaningfulPart = true;
7233
7241
  }
7234
7242
  }
7235
- 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;
7236
7253
  }
7237
7254
  const groups = [];
7238
7255
  let cur = null;
@@ -7258,6 +7275,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7258
7275
  endRef: info.ref,
7259
7276
  count: 1,
7260
7277
  tokens: info.tokens,
7278
+ effectiveTokens: info.effectiveTokens,
7261
7279
  toolPct: info.isTool ? 100 : 0,
7262
7280
  textPct: info.isTool ? 0 : 100
7263
7281
  };
@@ -7265,6 +7283,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7265
7283
  cur.endRef = info.ref;
7266
7284
  cur.count++;
7267
7285
  cur.tokens += info.tokens;
7286
+ cur.effectiveTokens += info.effectiveTokens;
7268
7287
  if (info.isTool) {
7269
7288
  cur.toolPct = Math.round((cur.toolPct * (cur.count - 1) + 100) / cur.count);
7270
7289
  } else {
@@ -7307,6 +7326,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
7307
7326
  protected: protectedGroups
7308
7327
  };
7309
7328
  }
7329
+ var EFFECTIVE_MIN_COMPRESSIBLE_TOKENS = 1250;
7310
7330
  function filterRecommendedRanges(compressible, _protectedRanges, options) {
7311
7331
  const { logger } = options;
7312
7332
  const log = logger?.debug.bind(logger);
@@ -7314,12 +7334,17 @@ function filterRecommendedRanges(compressible, _protectedRanges, options) {
7314
7334
  log?.("filterRecommendedRanges: no compressible ranges, returning empty");
7315
7335
  return [];
7316
7336
  }
7317
- const result = compressible.map(
7318
- (r, i) => i === compressible.length - 1 ? { ...r, dangerous: true } : r
7337
+ const kept = compressible.filter((r) => {
7338
+ const effective = r.effectiveTokens ?? r.tokens;
7339
+ return effective >= EFFECTIVE_MIN_COMPRESSIBLE_TOKENS;
7340
+ });
7341
+ const result = kept.map(
7342
+ (r, i) => i === kept.length - 1 ? { ...r, dangerous: true } : r
7319
7343
  );
7320
- log?.("filterRecommendedRanges: passthrough (last segment marked dangerous)", {
7344
+ log?.("filterRecommendedRanges: effective-token floor applied", {
7321
7345
  inputRanges: compressible.length,
7322
- outputRanges: result.length
7346
+ outputRanges: result.length,
7347
+ dropped: compressible.filter((r) => (r.effectiveTokens ?? r.tokens) < EFFECTIVE_MIN_COMPRESSIBLE_TOKENS).map((r) => `${r.startRef}\u2013${r.endRef} (${r.effectiveTokens ?? r.tokens} eff tokens)`)
7323
7348
  });
7324
7349
  return result;
7325
7350
  }
@@ -7328,8 +7353,10 @@ function formatCompressibleRanges(ranges, protectedRanges) {
7328
7353
  if (!protectedRanges || protectedRanges.length === 0) {
7329
7354
  if (ranges.length === 0) return "";
7330
7355
  const lines2 = ranges.map((r) => {
7356
+ const eff = r.effectiveTokens ?? r.tokens;
7357
+ const size = eff < r.tokens ? `${fmt(eff)} effective of ${fmt(r.tokens)}` : fmt(r.tokens);
7331
7358
  const suffix = r.dangerous ? " \u26A0\uFE0F NOT recommended unless you are certain. If you MUST compress this, pass `dangerous: true`." : "";
7332
- return ` ${r.startRef}\u2013${r.endRef} ${r.count} msgs ${fmt(r.tokens)} [tool ${r.toolPct}% | text ${r.textPct}%]${suffix}`;
7359
+ return ` ${r.startRef}\u2013${r.endRef} ${r.count} msgs ${size} [tool ${r.toolPct}% | text ${r.textPct}%]${suffix}`;
7333
7360
  });
7334
7361
  return `Compressible ranges (oldest first):
7335
7362
  ${lines2.join("\n")}`;
@@ -7345,7 +7372,7 @@ ${lines2.join("\n")}`;
7345
7372
  tokens: r.tokens,
7346
7373
  toolPct: r.toolPct,
7347
7374
  textPct: r.textPct,
7348
- compressibleTokens: r.tokens,
7375
+ compressibleTokens: r.effectiveTokens ?? r.tokens,
7349
7376
  compressibleCount: r.count,
7350
7377
  protectedTokens: 0,
7351
7378
  protectedCount: 0,
@@ -7639,7 +7666,8 @@ var injectCompressNudges = (state, config, logger, messages, prompts, compressio
7639
7666
  const hasRecommendations = recommendedRanges.length > 0;
7640
7667
  const allProtected = contextRanges.compressible.length === 0 && contextRanges.protected.length > 0;
7641
7668
  const allInProtectedZone = protectedRefs.size > 0 && unprotectedCompressible.length === 0;
7642
- const nothingToCompress = allProtected || allInProtectedZone;
7669
+ const allBelowMin = contextRanges.compressible.length > 0 && recommendedRanges.length === 0;
7670
+ const nothingToCompress = allProtected || allInProtectedZone || allBelowMin;
7643
7671
  const shouldInjectNudge = nudgeAllowed && (!nothingToCompress || emergencyOverride);
7644
7672
  let shouldInject = shouldInjectNudge;
7645
7673
  if (shouldInjectNudge) {
@@ -8609,7 +8637,11 @@ function collectVisibleMessages(rawMessages, ctx) {
8609
8637
  result.push({ ref, tokens, tool: toolName || "text", index: idx });
8610
8638
  }
8611
8639
  });
8612
- return { messages: result, summaryTokens, systemTokens: estimateSystemPromptTokens(rawMessages) };
8640
+ return {
8641
+ messages: result,
8642
+ summaryTokens,
8643
+ systemTokens: ctx.state.systemPromptTokens !== void 0 && ctx.state.systemPromptTokens > 0 ? ctx.state.systemPromptTokens : estimateSystemPromptTokens(rawMessages)
8644
+ };
8613
8645
  }
8614
8646
  function renderOverview(visibleMessages, summaryTokens, systemTokens, blocks, fetchFailed, rawMessages, ctx) {
8615
8647
  const lines = [];
@@ -9025,7 +9057,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
9025
9057
  import { join as join3 } from "path";
9026
9058
  import { existsSync as existsSync3 } from "fs";
9027
9059
  import { homedir as homedir3 } from "os";
9028
- var LOG_VERSION = true ? "1.14.21" : "dev";
9060
+ var LOG_VERSION = true ? "1.14.22-pr.325.39" : "dev";
9029
9061
  var Logger = class {
9030
9062
  logDir;
9031
9063
  enabled;