@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
32 lines • 1.32 kB
JavaScript
import { shouldTriggerCompaction } from "./policy.js";
import { WARM_GENERATION_FLOOR_RATIO } from "./speculation-lead.js";
export const IDLE_COMPACTION_INSTRUCTIONS = "Proactively compact at idle before the next agent turn, while the user is not waiting.";
const PERSISTENT_MODES = new Set(["tui", "rpc"]);
function isIdleEligible(decision) {
if (decision.willRetry)
return false;
if (decision.aborted)
return false;
if (!PERSISTENT_MODES.has(decision.mode))
return false;
if (!decision.settings.enabled)
return false;
if (decision.settings.idleCompactionEnabled === false)
return false;
if (decision.breakerTripped)
return false;
if (!decision.usage)
return false;
return decision.usage.tokens !== null;
}
export function shouldRunIdleCompaction(decision) {
if (!isIdleEligible(decision) || !decision.usage)
return false;
return shouldTriggerCompaction(decision.usage, decision.contextWindow, decision.settings, decision.lastYield);
}
export function shouldWarmAtIdle(decision) {
if (!isIdleEligible(decision) || !decision.usage || decision.usage.tokens === null)
return false;
return decision.usage.tokens >= decision.contextWindow * WARM_GENERATION_FLOOR_RATIO;
}
//# sourceMappingURL=idle.js.map