import type { CostModel } from "../util/cost.js"; /** * v0.5 §5.6 — Author loop budget envelope. * * Cumulative USD spent on author-loop LLM calls per org. Persisted to * `//memory/author-costs.jsonl` as append-only JSONL so the * file can be tail-read for diagnostics without a parse pass over the entire * history. Caps come from `workspace.yaml` `author.budget` (read by the * caller — `checkBudget` is pure on its `opts`). * * Daily/weekly windows use UTC boundaries (avoids subtle DST drift when a * solo-founder workspace migrates timezones). The week is rolling — last 7 * UTC days, not "current ISO week" — because solo-founder usage is * continuous, not aligned to a Mon-Sun cycle. * * `on_cap_action: warn` always allows; `pause` refuses. `checkBudget` * surfaces both so the caller can either short-circuit (pause) or just log * a warning (warn). */ export type OnCapAction = "pause" | "warn"; export interface AuthorCostRow { ts: string; skill_draft_id: string; step: string; usd: number; model: CostModel; } export interface RecordAuthorCostInput { workspace: string; orgSlug: string; skillDraftId: string; step: string; usd: number; model: CostModel; } export interface CheckBudgetOpts { workspace: string; orgSlug: string; /** Optional cap on a single upcoming call. */ perCallUsd?: number; dailyUsd?: number; weeklyUsd?: number; onCapAction?: OnCapAction; } export interface CheckBudgetResult { allowed: boolean; reason?: string; /** Remaining headroom for diagnostics — never negative. */ remaining: { today: number; week: number; }; /** True when the call would breach a cap regardless of action policy. */ exceeded: boolean; } export declare function authorCostsPath(workspace: string, orgSlug: string): string; export declare function recordAuthorCost(input: RecordAuthorCostInput): void; export declare function readAuthorCosts(workspace: string, orgSlug: string): AuthorCostRow[]; export declare function checkBudget(opts: CheckBudgetOpts): CheckBudgetResult;