A function that mixes two clearly different concerns — pricing AND rendering, parsing AND validating, fetching AND transforming — interleaved through shared locals.
The agent finds a function that conflates two concerns in interleaved code; reasoning about either concern requires tracing through the other.
Each phase reads and writes its own well-defined inputs and outputs; the seam between them is data, not control flow.
Each phase reads and writes its own well-defined inputs and outputs; the agent reasons about phases independently with the intermediate shape as the contract.
Before the refactoring
function priceAndRender(input) {let total = 0;for (const item of input.items) total += item.qty * item.price;if (input.member) total *= 0.95;return `<p>Total: ${(total / 100).toFixed(2)} for ${input.items.length} items</p>`;}
After the refactoring
function pricing(input) {let total = 0;for (const item of input.items) total += item.qty * item.price;if (input.member) total *= 0.95;return { items: input.items, totalCents: total };}function render({ items, totalCents }) {return `<p>Total: ${(totalCents / 100).toFixed(2)} for ${items.length} items</p>`;}
Each concern can't be tested or evolved independently; changes to one concern risk breaking the other; the function's intent gets buried under coordination work.
The agent must trace interleaved concerns through one function body; testing or modifying either requires reasoning about both.
An intermediate data structure between the phases is overhead — earn it by separating two clearly different concerns.
The intermediate data structure is overhead; for functions where the two phases are tightly coupled (shared mutable locals, observer effects), splitting adds a seam without buying isolation.
Phases evolve independently; tests target each phase in isolation; the intermediate shape becomes a documented contract.
Each phase becomes the agent's unit of reasoning; the intermediate shape documents the contract; testing and modification isolate to one phase at a time.
Splitting phases that genuinely belong together — work where the second phase needs to mutate state the first phase set up in subtle ways — fragments coherent logic across an artificial seam.
Splitting tightly-coupled phases creates an artificial seam the agent must coordinate across — the intermediate shape leaks one phase's implementation into the next.