@dreb/coding-agent 2.59.1 → 2.59.2
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.
|
@@ -20,7 +20,7 @@ import { getDocsPath } from "../config.js";
|
|
|
20
20
|
import { theme } from "../modes/interactive/theme/theme.js";
|
|
21
21
|
import { sleep } from "../utils/sleep.js";
|
|
22
22
|
import { executeBash as executeBashCommand, executeBashWithOperations } from "./bash-executor.js";
|
|
23
|
-
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
23
|
+
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
24
24
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
25
25
|
import { DispatchArbiter } from "./dispatch-arbiter.js";
|
|
26
26
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
@@ -3346,11 +3346,12 @@ export class AgentSession {
|
|
|
3346
3346
|
return undefined;
|
|
3347
3347
|
// After compaction, the last assistant usage reflects pre-compaction context size.
|
|
3348
3348
|
// We can only trust usage from an assistant that responded after the latest compaction.
|
|
3349
|
-
//
|
|
3349
|
+
// Until then, estimate every rebuilt message independently so the stale kept
|
|
3350
|
+
// assistant usage cannot leak into the current context value.
|
|
3350
3351
|
const branchEntries = this.sessionManager.getBranch();
|
|
3351
3352
|
const latestCompaction = getLatestCompactionEntry(branchEntries);
|
|
3352
3353
|
if (latestCompaction) {
|
|
3353
|
-
// Check if there's a valid assistant usage after the compaction boundary
|
|
3354
|
+
// Check if there's a valid assistant usage after the compaction boundary.
|
|
3354
3355
|
const compactionIndex = branchEntries.lastIndexOf(latestCompaction);
|
|
3355
3356
|
let hasPostCompactionUsage = false;
|
|
3356
3357
|
for (let i = branchEntries.length - 1; i > compactionIndex; i--) {
|
|
@@ -3359,23 +3360,22 @@ export class AgentSession {
|
|
|
3359
3360
|
const assistant = entry.message;
|
|
3360
3361
|
if (assistant.stopReason !== "aborted" && assistant.stopReason !== "error") {
|
|
3361
3362
|
const contextTokens = calculateContextTokens(assistant.usage);
|
|
3362
|
-
if (contextTokens > 0)
|
|
3363
|
+
if (contextTokens > 0)
|
|
3363
3364
|
hasPostCompactionUsage = true;
|
|
3364
|
-
}
|
|
3365
3365
|
break;
|
|
3366
3366
|
}
|
|
3367
3367
|
}
|
|
3368
3368
|
}
|
|
3369
3369
|
if (!hasPostCompactionUsage) {
|
|
3370
|
-
|
|
3370
|
+
const tokens = this.messages.reduce((total, message) => total + estimateTokens(message), 0);
|
|
3371
|
+
return { tokens, contextWindow, percent: (tokens / contextWindow) * 100 };
|
|
3371
3372
|
}
|
|
3372
3373
|
}
|
|
3373
3374
|
const estimate = estimateContextTokens(this.messages);
|
|
3374
|
-
const percent = (estimate.tokens / contextWindow) * 100;
|
|
3375
3375
|
return {
|
|
3376
3376
|
tokens: estimate.tokens,
|
|
3377
3377
|
contextWindow,
|
|
3378
|
-
percent,
|
|
3378
|
+
percent: (estimate.tokens / contextWindow) * 100,
|
|
3379
3379
|
};
|
|
3380
3380
|
}
|
|
3381
3381
|
/**
|