@sayknow-cli/agent-core 0.7.16 → 0.7.19
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/CHANGELOG.md +7 -1
- package/package.json +4 -4
- package/src/compaction/compaction.ts +27 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
-
## [0.7.
|
|
5
|
+
## [0.7.19] - 2026-11-09
|
|
6
|
+
|
|
7
|
+
## [0.7.17] - 2026-11-05
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Compaction now scales the kept recent-history window to 30% of the threshold it actually triggers at (explicit, adaptive, or the 300K default ceiling) instead of 30% of the model window. With `thresholdTokens: 150000`, a 500K-window model such as grok-4.7 kept 75K tokens (half the trigger), so post-compaction context sat near the next compaction; a 1M-window model kept a single token and dropped every recent turn. Both now keep 45K.
|
|
6
12
|
|
|
7
13
|
## [0.7.12] - 2026-10-24
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sayknow-cli/agent-core",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.19",
|
|
5
5
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
6
6
|
"homepage": "https://sayknow-cli.com",
|
|
7
7
|
"author": "jaybeyond",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"fmt": "biome format --write ."
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@sayknow-cli/ai": "0.7.
|
|
39
|
-
"@sayknow-cli/natives": "0.7.
|
|
40
|
-
"@sayknow-cli/utils": "0.7.
|
|
38
|
+
"@sayknow-cli/ai": "0.7.19",
|
|
39
|
+
"@sayknow-cli/natives": "0.7.19",
|
|
40
|
+
"@sayknow-cli/utils": "0.7.19",
|
|
41
41
|
"@opentelemetry/api": "^1.9.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
@@ -1270,18 +1270,30 @@ export interface PrepareCompactionOptions {
|
|
|
1270
1270
|
|
|
1271
1271
|
/**
|
|
1272
1272
|
* Leave reserve headroom below the compaction trigger for the kept history.
|
|
1273
|
-
*
|
|
1274
|
-
*
|
|
1275
|
-
*
|
|
1276
|
-
*
|
|
1273
|
+
* The headroom is capped to half the trigger: the reserve scales with the model
|
|
1274
|
+
* window (15% of 1M is 150K), so a trigger at or below it — the 300K default
|
|
1275
|
+
* ceiling or an explicit/adaptive threshold — would otherwise reduce the safe
|
|
1276
|
+
* keep window to zero and drop every recent turn. The caller separately clamps
|
|
1277
|
+
* an oversized configured keep floor and corrected budget below the threshold
|
|
1278
|
+
* so they cannot prevent an actual compaction.
|
|
1277
1279
|
*/
|
|
1278
1280
|
function resolveThresholdSafeKeepRecentTokens(contextWindow: number, settings: CompactionSettings): number {
|
|
1279
1281
|
const thresholdTokens = resolveThresholdTokens(contextWindow, settings);
|
|
1280
1282
|
const reserveTokens = effectiveReserveTokens(contextWindow, settings, 0);
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1283
|
+
return Math.max(1, thresholdTokens - Math.min(reserveTokens, Math.floor(thresholdTokens * 0.5)));
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* The budget the 30% keep window scales against: the model window when
|
|
1288
|
+
* compaction triggers at its reserve-derived default, otherwise the lower
|
|
1289
|
+
* trigger itself (default ceiling, explicit, or adaptive threshold). Scaling a
|
|
1290
|
+
* 500K window against a 150K trigger kept half the trigger, so the
|
|
1291
|
+
* post-compaction prompt landed close to the next compaction.
|
|
1292
|
+
*/
|
|
1293
|
+
function resolveKeepScaleBudget(contextWindow: number, settings: CompactionSettings): number {
|
|
1294
|
+
const thresholdTokens = resolveThresholdTokens(contextWindow, settings);
|
|
1295
|
+
const reserveDerivedThreshold = contextWindow - effectiveReserveTokens(contextWindow, settings, 0);
|
|
1296
|
+
return thresholdTokens < reserveDerivedThreshold ? thresholdTokens : contextWindow;
|
|
1285
1297
|
}
|
|
1286
1298
|
|
|
1287
1299
|
export function prepareCompaction(
|
|
@@ -1320,11 +1332,15 @@ export function prepareCompaction(
|
|
|
1320
1332
|
: configuredKeepRecentTokens;
|
|
1321
1333
|
const keepRecentTokens = Math.min(configuredKeepRecentTokens, thresholdSafeKeepRecentTokens);
|
|
1322
1334
|
// Preserve the legacy fixed window for smaller models. At 66k and above,
|
|
1323
|
-
// retain up to 30% of the
|
|
1324
|
-
//
|
|
1335
|
+
// retain up to 30% of the budget compaction runs in (the model context, or a
|
|
1336
|
+
// lower trigger), but never enough to leave the post-compaction prompt
|
|
1337
|
+
// immediately above its configured threshold.
|
|
1325
1338
|
const scaledKeepRecentTokens =
|
|
1326
1339
|
contextWindow !== undefined && Number.isFinite(contextWindow) && contextWindow >= 66_000
|
|
1327
|
-
? Math.min(
|
|
1340
|
+
? Math.min(
|
|
1341
|
+
thresholdSafeKeepRecentTokens,
|
|
1342
|
+
Math.max(keepRecentTokens, Math.floor(resolveKeepScaleBudget(contextWindow, settings) * 0.3)),
|
|
1343
|
+
)
|
|
1328
1344
|
: keepRecentTokens;
|
|
1329
1345
|
const rawRatio = options.tokenCorrectionRatio;
|
|
1330
1346
|
const appliedRatio =
|