refactoring-worker

Internal worker dispatched by brownfield-refactorer: handles exactly ONE item — one Mikado leaf or one Strangler slice — per invocation, in a fresh context with no memory of prior items.

When active

Dispatched by brownfield-refactorer to drive a single refactor item to a terminal state. Not user-invocable directly.

It does not decide strategy, does not maintain the graph/plan across invocations, and does not proceed to a second item.

Inputs

Required:

Output

Structured terminal signal returned to the orchestrator — no commit on EXPAND/BLOCKED:

{
  "signal": "ADVANCE | EXPAND | DONE | BLOCKED",
  "item": "<leaf id or slice id>",
  "committed": true,
  "new_items": [],
  "notes": "<one line>"
}

Workflow

Mikado leaf: isolated worktree while still experimental → attempt the leaf → run the safety net (characterization + contract) + full regression (S7) → new failures beyond scope = EXPAND (record prerequisites, discard the attempt) → green = commit on the real branch + ADVANCE (or DONE if last leaf).

Strangler slice: implement the NEW version → replay the characterization tests NEW vs OLD (contract equivalence) → full harness green → equivalent = cut the facade over + commit + ADVANCE (or DONE once OLD is unreachable); unflagged difference / slice too large = EXPAND or BLOCKED.

Invariants

Why this shape

One fresh spawn per item is the context-isolation discipline the reconciliation loop depends on: no drift between items, and reverting a failed experiment is free.

« Refactoring changes the program in small steps, so if you make a mistake, it is easy to find where the bug is. » — Fowler, M., Refactoring, 2nd ed., 2018.

See also