// engine/session-budget.ts — In-memory token budget tracker for SPEC-220.
// Resets on every process restart. No persistence.
// ---------------------------------------------------------------------------
// Session start time (module-level constant, set at import)
// ---------------------------------------------------------------------------
const SESSION_START = Date.now();
/** Average estimated tokens per tool call. */
const TOKENS_PER_CALL = 500;
/** Percentage threshold (as call count fraction) that triggers a warning. */
const WARNING_FRACTION = 0.7;
// ---------------------------------------------------------------------------
// Public API
// ---------------------------------------------------------------------------
/** Returns milliseconds elapsed since this process started. */
export function getSessionElapsedMs() {
    return Date.now() - SESSION_START;
}
/**
 * Estimate total tokens used based on the number of tool calls made.
 * Uses a flat 500-token average per call.
 */
export function estimateTokensUsed(callCount) {
    return callCount * TOKENS_PER_CALL;
}
/**
 * Returns a warning string if callCount > 70% of budgetLimit, null if OK.
 * budgetLimit represents the estimated maximum tool calls before context limit.
 */
export function getBudgetWarning(callCount, budgetLimit = 50) {
    const threshold = Math.floor(budgetLimit * WARNING_FRACTION);
    if (callCount <= threshold) {
        return null;
    }
    const remaining = Math.max(0, budgetLimit - callCount);
    const percent = Math.round((callCount / budgetLimit) * 100);
    return (`Budget warning: ${String(percent)}% of estimated session capacity used ` +
        `(${String(callCount)}/${String(budgetLimit)} calls). ` +
        `~${String(remaining)} calls remaining — consider checkpointing soon.`);
}
//# sourceMappingURL=session-budget.js.map