AI CodeOps

Monorepo: cost-capped multi-agent refactor

Refactor one package of a monorepo with Plan, Build, Review & Test, under a workspace budget and a per-workflow cap, with tests scoped to the package changed.

Use this template

Refactors in a monorepo go wrong in two ways: the change sprawls across packages, and the bill sprawls with it. This template points the default workflow at one package and puts a ceiling on both.

Which agents run

Plan, Build, Review & Test is the default workflow:

  1. Plan, by the Architect: the files to change, the order, and the risks, such as callers that depend on today's retry timing.
  2. Build, by the Builder: the exact edits, file by file.
  3. Review, by the Reviewer: edge cases and behavior changes in the proposed edits.
  4. Test, by the Tester: the cases that prove behavior didn't move.

Then the code pass writes the diff, your tests run against it, and the AI findings review reads it. Open high or critical findings and failing tests block the pull request, and a second person approves it.

Scope it to one package

Agents read a selected snapshot of the repository, not the whole tree, and one change can touch at most 25 files. Name the package and its boundary in the task. On the project, set the test command so the verify step runs the suite that matters:

Project fieldExample value
Test commandpnpm --filter @acme/billing test
Default branchmain

The command runs in an isolated sandbox, cut off the network after dependencies install, with a two-minute limit per command. If it can't run, the step records a skip with the reason, never a pass.

Cap the spend

Under Configure → Billing, choose Configure budget, save it, then choose Edit limits:

FieldExample value
PeriodMonthly
Soft limit (USD)150
Hard limit (USD)200
Per-workflow caps (USD)Plan, Build, Review & Test: 40

The soft limit is only a marker on the spend bar. The hard limit and the per-workflow cap stop sessions. The cap counts all sessions of that workflow in the period, not one session, so size it for the refactors you expect this month.

Split big refactors

If the plan names more than 25 files, merge the first slice, then start a follow-up for the next package. A follow-up gets the parent's task and summary as context. The full-stack feature template covers the opposite case: one feature across layers.

Frequently asked questions

What happens when the cap is reached mid-session?

The budget is checked before every model call. The session stops with Stopped over budget and shows Blocked by budget.

Can I cap each agent separately?

No. Budgets are per workspace and per workflow. The session page shows each step's cost, so you can see where the money went.