Run Budget
A spend cap for an agent run: pick it, watch the meter fill and warn near the cap, then keep what's done or raise the cap when it stops.
Run budget
Pick a cap for this run
Installation
npx shadcn@latest add "@aiellie/run-budget"shadcn needs the @aiellie registry in components.json first. npx aiellie add run-budget adds it on its first run, then installs the same way.
Run Budget puts a spend cap on an agent run. Before it starts, you pick the cap. While it runs, a meter fills in the live colour, then turns to the warning colour with "May finish over budget" once it passes warnAt. A notch on the meter marks that point.
When the run stops at the cap, it lists what got done and offers two ways on: keep that work, or raise the cap and carry on. The step that crosses the cap still finishes, so spend can go past it, and the card says by how much.
Getting started
Drive it from the run
The component holds no run of its own. Pass the state and the spend as they change.
components/budget.tsximport { RunBudget } from "@/components/aiellie/run-budget" export function Budget({ run }: { run: Run }) { return ( <RunBudget state={run.state} limit={run.limit} spent={run.spent} turns={run.turns} elapsedSeconds={run.seconds} onLimitChange={run.setLimit} onStart={run.start} /> ) }Handle the stop
Once
stateisstopped, pass what was kept and the two ways on.onRaisegets the new cap, double the old one unless you setraiseTo.components/budget.tsx<RunBudget state="stopped" limit={run.limit} spent={run.spent} kept={[{ label: "Files changed", value: "4" }]} onKeep={run.finish} onRaise={(limit) => run.resume(limit)} />
Anatomy
<div data-slot="run-budget" data-state="running" data-warning role="group">
<div data-slot="run-budget-header" />
<div role="radiogroup" /> {/* while setting */}
<div data-slot="run-budget-meter" role="meter" />
{/* left, unused or past the cap; then the share or the warning */}
</div>The caps are a radio group: the arrow keys move between them. The warning is read out once a run, not on every tick, and stopping and finishing are each read out as they happen.
formatMoney is exported too. Spend always shows cents, and a whole cap doesn't: $5, $4.18.
Examples
Stopped, with nothing to decide
Leave out onKeep and onRaise, and a stopped run says the finished work is kept.
Run budget
Stopped at the cap
Kept
- Pages translated
- 41 of 60
- Glossary terms
- 128
Ended at the cap. Finished work is kept.
API reference
RunBudget
| Prop | Type | Default | Description |
|---|---|---|---|
state | "setting" | "running" | "stopped" | "done" | required | |
limit | number | required | The cap, in currency. |
spent | number | 0 | It can pass limit. |
options | number[] | [1, 5, 20] | The caps offered. |
onLimitChange | (limit: number) => void | ||
onStart | () => void | Adds Start run while setting. | |
turns | number | ||
elapsedSeconds | number | ||
warnAt | number | 0.8 | The share of the cap at which it warns. |
raiseTo | number | double limit | The cap offered. |
onRaise | (limit: number) => void | ||
onKeep | () => void | ||
kept | { label: string; value: string }[] | [] | What the run finished before it stopped. |
currency | string | "USD" |
All other div props are forwarded.