/** * Token / agent budget tracking for a workflow run. * * Bounds the cost of a fan-out so a runaway script (parallel × retries × N * sprints) can't spend without limit. Mirrors the intent of Claude Code's * per-run budget: a hard ceiling on agents and an optional token ceiling. * * The {@link Scheduler} owns the live agent-count runaway guard for a single * fan-out; `Budget` is the run-level accountant the interpreter (Sprint 3) * charges as agents complete, surfacing `spent`/`remaining` for dynamic * loops (`while (budget.remainingTokens() > 50_000) { ... }`). */ export interface TokenUsage { inputTokens: number; outputTokens: number; } export interface BudgetOptions { /** Max total (input+output) tokens. `null`/omitted = unlimited. */ maxTokens?: number | null; /** Max agent executions charged to this budget. `null`/omitted = unlimited. */ maxAgents?: number | null; /** Max total USD cost charged to this budget. `null`/omitted = unlimited. */ maxUsd?: number | null; } /** Raised by {@link Budget.assertWithinBudget} when a ceiling is exceeded. */ export declare class BudgetExceededError extends Error { /** Which ceiling was hit. */ readonly kind: "tokens" | "agents" | "usd"; constructor(message: string, /** Which ceiling was hit. */ kind: "tokens" | "agents" | "usd"); } export declare class Budget { private readonly opts; private inputTokens; private outputTokens; private agents; private usd; constructor(opts?: BudgetOptions); /** Record an agent's token usage. */ chargeTokens(usage: TokenUsage): void; /** Record `n` agent executions (default 1). */ chargeAgents(n?: number): void; /** * Record a USD charge. Non-finite (`NaN`, `Infinity`, `-Infinity`) or * negative values are treated as 0 (no-op) rather than corrupting the * running total — a malformed/absent `costUsd` must never crash or * silently under/over-charge the budget. */ chargeUsd(usd: number): void; /** Total tokens spent (input + output). */ get tokensSpent(): number; /** Agent executions charged so far. */ get agentsSpent(): number; /** Total USD charged so far. */ get usdSpent(): number; /** Remaining token headroom, or `Infinity` when uncapped. */ remainingTokens(): number; /** Remaining agent headroom, or `Infinity` when uncapped. */ remainingAgents(): number; /** Remaining USD headroom, or `Infinity` when uncapped. */ remainingUsd(): number; /** True once any configured ceiling has been reached or passed. */ exceeded(): boolean; /** * Throw {@link BudgetExceededError} if a ceiling has been reached. Call before * dispatching the next agent to fail fast on the offending dimension. */ assertWithinBudget(): void; } /** * Construct a USD-only {@link Budget} from a role section's `budget.maxUsd` * config value, or `undefined` when unset (Sprint 3 — agent-loop capability * port). Shared helper so role entry points (generator, and future * curator/evaluator/planner wiring) can adopt the same absent-means-no-budget * convention without duplicating the `!= null` check. */ export declare function budgetFromMaxUsd(maxUsd: number | null | undefined): Budget | undefined; //# sourceMappingURL=budget.d.ts.map