opencode-acp 1.14.22-pr.323.38 → 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
|
@@ -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
|
-
|
|
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
|
-
|
|
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,7 @@ function buildCompressibleRanges(messages, state, protectedTools = [], protected
|
|
|
7310
7326
|
protected: protectedGroups
|
|
7311
7327
|
};
|
|
7312
7328
|
}
|
|
7329
|
+
var EFFECTIVE_MIN_COMPRESSIBLE_TOKENS = 1250;
|
|
7313
7330
|
function filterRecommendedRanges(compressible, _protectedRanges, options) {
|
|
7314
7331
|
const { logger } = options;
|
|
7315
7332
|
const log = logger?.debug.bind(logger);
|
|
@@ -7317,12 +7334,17 @@ function filterRecommendedRanges(compressible, _protectedRanges, options) {
|
|
|
7317
7334
|
log?.("filterRecommendedRanges: no compressible ranges, returning empty");
|
|
7318
7335
|
return [];
|
|
7319
7336
|
}
|
|
7320
|
-
const
|
|
7321
|
-
|
|
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
|
|
7322
7343
|
);
|
|
7323
|
-
log?.("filterRecommendedRanges:
|
|
7344
|
+
log?.("filterRecommendedRanges: effective-token floor applied", {
|
|
7324
7345
|
inputRanges: compressible.length,
|
|
7325
|
-
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)`)
|
|
7326
7348
|
});
|
|
7327
7349
|
return result;
|
|
7328
7350
|
}
|
|
@@ -7331,8 +7353,10 @@ function formatCompressibleRanges(ranges, protectedRanges) {
|
|
|
7331
7353
|
if (!protectedRanges || protectedRanges.length === 0) {
|
|
7332
7354
|
if (ranges.length === 0) return "";
|
|
7333
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);
|
|
7334
7358
|
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 ${
|
|
7359
|
+
return ` ${r.startRef}\u2013${r.endRef} ${r.count} msgs ${size} [tool ${r.toolPct}% | text ${r.textPct}%]${suffix}`;
|
|
7336
7360
|
});
|
|
7337
7361
|
return `Compressible ranges (oldest first):
|
|
7338
7362
|
${lines2.join("\n")}`;
|
|
@@ -7348,7 +7372,7 @@ ${lines2.join("\n")}`;
|
|
|
7348
7372
|
tokens: r.tokens,
|
|
7349
7373
|
toolPct: r.toolPct,
|
|
7350
7374
|
textPct: r.textPct,
|
|
7351
|
-
compressibleTokens: r.tokens,
|
|
7375
|
+
compressibleTokens: r.effectiveTokens ?? r.tokens,
|
|
7352
7376
|
compressibleCount: r.count,
|
|
7353
7377
|
protectedTokens: 0,
|
|
7354
7378
|
protectedCount: 0,
|
|
@@ -7642,7 +7666,8 @@ var injectCompressNudges = (state, config, logger, messages, prompts, compressio
|
|
|
7642
7666
|
const hasRecommendations = recommendedRanges.length > 0;
|
|
7643
7667
|
const allProtected = contextRanges.compressible.length === 0 && contextRanges.protected.length > 0;
|
|
7644
7668
|
const allInProtectedZone = protectedRefs.size > 0 && unprotectedCompressible.length === 0;
|
|
7645
|
-
const
|
|
7669
|
+
const allBelowMin = contextRanges.compressible.length > 0 && recommendedRanges.length === 0;
|
|
7670
|
+
const nothingToCompress = allProtected || allInProtectedZone || allBelowMin;
|
|
7646
7671
|
const shouldInjectNudge = nudgeAllowed && (!nothingToCompress || emergencyOverride);
|
|
7647
7672
|
let shouldInject = shouldInjectNudge;
|
|
7648
7673
|
if (shouldInjectNudge) {
|
|
@@ -9032,7 +9057,7 @@ import { writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
|
|
|
9032
9057
|
import { join as join3 } from "path";
|
|
9033
9058
|
import { existsSync as existsSync3 } from "fs";
|
|
9034
9059
|
import { homedir as homedir3 } from "os";
|
|
9035
|
-
var LOG_VERSION = true ? "1.14.22-pr.
|
|
9060
|
+
var LOG_VERSION = true ? "1.14.22-pr.325.39" : "dev";
|
|
9036
9061
|
var Logger = class {
|
|
9037
9062
|
logDir;
|
|
9038
9063
|
enabled;
|