aiellie

Search

Find a component, template or page

GitHub
Components

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

Stops at the cap. Finished work is kept.
Open full screen
fig. 01 · open it full screen from the corner

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

  1. Drive it from the run

    The component holds no run of its own. Pass the state and the spend as they change.

    components/budget.tsx
    import { 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}
        />
      )
    }
  2. Handle the stop

    Once state is stopped, pass what was kept and the two ways on. onRaise gets the new cap, double the old one unless you set raiseTo.

    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

$5.12 / $5
$0.12 past the cap38 turns · 3:34

Kept

Pages translated
41 of 60
Glossary terms
128

Ended at the cap. Finished work is kept.

API reference

RunBudget

PropTypeDefaultDescription
state"setting" | "running" | "stopped" | "done"required
limitnumberrequiredThe cap, in currency.
spentnumber0It can pass limit.
optionsnumber[][1, 5, 20]The caps offered.
onLimitChange(limit: number) => void
onStart() => voidAdds Start run while setting.
turnsnumber
elapsedSecondsnumber
warnAtnumber0.8The share of the cap at which it warns.
raiseTonumberdouble limitThe cap offered.
onRaise(limit: number) => void
onKeep() => void
kept{ label: string; value: string }[][]What the run finished before it stopped.
currencystring"USD"

All other div props are forwarded.