@bd7pil/opencode-deep-memory 0.4.3 → 0.4.4
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 +24 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15219,19 +15219,21 @@ function createCompactingHandler(args) {
|
|
|
15219
15219
|
}
|
|
15220
15220
|
|
|
15221
15221
|
// src/compress/pressure.ts
|
|
15222
|
-
var
|
|
15222
|
+
var FALLBACK_MAX_CONTEXT = 128e3;
|
|
15223
|
+
var OPENCODE_COMPACTION_RATIO = 0.75;
|
|
15223
15224
|
var THRESHOLDS = {
|
|
15224
15225
|
medium: 0.3,
|
|
15225
15226
|
high: 0.5
|
|
15226
15227
|
};
|
|
15227
|
-
var
|
|
15228
|
-
|
|
15229
|
-
|
|
15230
|
-
|
|
15231
|
-
|
|
15232
|
-
|
|
15233
|
-
|
|
15234
|
-
|
|
15228
|
+
var calibratedMaxContext = 0;
|
|
15229
|
+
function calibrateFromCompaction(lastInputTokens) {
|
|
15230
|
+
if (lastInputTokens <= 0) return;
|
|
15231
|
+
const derived = Math.round(lastInputTokens / OPENCODE_COMPACTION_RATIO);
|
|
15232
|
+
calibratedMaxContext = derived;
|
|
15233
|
+
}
|
|
15234
|
+
function getCalibratedMaxContext() {
|
|
15235
|
+
return calibratedMaxContext;
|
|
15236
|
+
}
|
|
15235
15237
|
function estimateTokens2(text) {
|
|
15236
15238
|
let cjk = 0;
|
|
15237
15239
|
let other = 0;
|
|
@@ -15285,8 +15287,8 @@ function extractInputTokensFromMessages(messages) {
|
|
|
15285
15287
|
}
|
|
15286
15288
|
return 0;
|
|
15287
15289
|
}
|
|
15288
|
-
function detectPressure(messages
|
|
15289
|
-
const maxContext =
|
|
15290
|
+
function detectPressure(messages) {
|
|
15291
|
+
const maxContext = calibratedMaxContext || FALLBACK_MAX_CONTEXT;
|
|
15290
15292
|
const inputTokens = extractInputTokensFromMessages(messages);
|
|
15291
15293
|
const estimated = inputTokens > 0 ? inputTokens : extractTokensFromMessages(messages);
|
|
15292
15294
|
const ratio = Math.min(estimated / maxContext, 1);
|
|
@@ -15294,7 +15296,7 @@ function detectPressure(messages, modelId) {
|
|
|
15294
15296
|
if (ratio >= THRESHOLDS.high) level = "high";
|
|
15295
15297
|
else if (ratio >= THRESHOLDS.medium) level = "medium";
|
|
15296
15298
|
else level = "low";
|
|
15297
|
-
return { level, ratio, estimatedTokens: estimated };
|
|
15299
|
+
return { level, ratio, estimatedTokens: estimated, maxContext };
|
|
15298
15300
|
}
|
|
15299
15301
|
|
|
15300
15302
|
// src/compress/dedup.ts
|
|
@@ -15700,7 +15702,7 @@ function detectContentType(content) {
|
|
|
15700
15702
|
// src/compress/index.ts
|
|
15701
15703
|
function runCompressionPipeline(ctx) {
|
|
15702
15704
|
const { messages, state, logger } = ctx;
|
|
15703
|
-
const pressure = detectPressure(messages
|
|
15705
|
+
const pressure = detectPressure(messages);
|
|
15704
15706
|
state.recordInputTokens(pressure.estimatedTokens);
|
|
15705
15707
|
const stats = {
|
|
15706
15708
|
toolDedup: 0,
|
|
@@ -16557,6 +16559,15 @@ var deepMemoryPlugin = async (input) => {
|
|
|
16557
16559
|
if (event.type === "session.compacted") {
|
|
16558
16560
|
const compactedSessionID = event.properties.sessionID;
|
|
16559
16561
|
logger.info("event session.compacted", { sessionID: compactedSessionID });
|
|
16562
|
+
const lastTokens = state.lastInputTokens();
|
|
16563
|
+
if (lastTokens > 0) {
|
|
16564
|
+
calibrateFromCompaction(lastTokens);
|
|
16565
|
+
logger.info("pressure calibrated", {
|
|
16566
|
+
trigger: "compaction",
|
|
16567
|
+
lastInputTokens: lastTokens,
|
|
16568
|
+
derivedMaxContext: getCalibratedMaxContext()
|
|
16569
|
+
});
|
|
16570
|
+
}
|
|
16560
16571
|
try {
|
|
16561
16572
|
const auditLogDir = projectMemoryDir(projectPath);
|
|
16562
16573
|
await mkdir4(auditLogDir, { recursive: true });
|