import type { CostModel } from "../util/cost.js"; import type { OnCapAction } from "./author-budget.js"; import { type AgentProfileMerged } from "../util/agent-profile.js"; /** * v0.6 §2.2 P0 #1 — Agent spawn budget envelope. * * Generalization of the v0.5 author-loop envelope (`src/bot/author-budget.ts`) * to PM-mediated specialist spawns. The two budgets are intentionally kept in * *separate JSONL files* (`agent-costs.jsonl` vs `author-costs.jsonl`) so the * v0.5 author cap is not silently consumed by spawn traffic — a single ledger * would force solo-founders to size one cap to dominate both flows. * * File: `//memory/agent-costs.jsonl` — append-only JSONL, * one row per spawn (or per spawn step when broken down). * * Windows + boundary semantics mirror v0.5: UTC day, rolling 7-day window. */ export interface AgentCostRow { ts: string; agent_name: string; step: string; usd: number; model?: CostModel; } export interface RecordAgentCostInput { workspace: string; orgSlug: string; agentName: string; step: string; usd: number; model?: CostModel; } export interface CheckAgentBudgetInput { workspace: string; orgSlug: string; agentName: string; /** * Pre-loaded merged profile; pass-through if the caller already has it. * Otherwise `loadAgentProfile` is called internally. */ agentProfile?: AgentProfileMerged; } export interface CheckAgentBudgetResult { allowed: boolean; reason?: string; /** Remaining headroom — never negative. Infinity when no cap is set. */ remaining: { today: number; week: number; }; exceeded: boolean; action: OnCapAction; } export declare function agentCostsPath(workspace: string, orgSlug: string): string; export declare function recordAgentCost(input: RecordAgentCostInput): void; export declare function readAgentCosts(workspace: string, orgSlug: string): AgentCostRow[]; /** * Resolve the effective cap + remaining headroom for a single agent. * * The merged profile already encodes the 3-tier inheritance (workspace * bundle → user global → org agent-profile) and the "agent budget may only * tighten parent" invariant — this function only needs to look up the * resolved row and compare against cumulative spend. */ export declare function checkAgentBudget(input: CheckAgentBudgetInput): CheckAgentBudgetResult;