--- description: Mine business logic from legacy code into testable, human-readable rule specifications argument-hint: [module-pattern] --- Extract the **business rules** embedded in `legacy/$1` into a structured, testable specification — the institutional knowledge that's currently locked in code and in the heads of engineers who are about to retire. Scope: if a module pattern was given (`$2`), focus there; otherwise cover the entire system. Either way, prioritize calculation, validation, eligibility, and state-transition logic over plumbing. ## Method Spawn **three business-rules-extractor subagents in parallel**, each assigned a different lens. If `$2` is non-empty, include "focusing on files matching $2" in each prompt. 1. **Calculations** — "Find every formula, rate, threshold, and computed value in legacy/$1. For each: what does it compute, what are the inputs, what is the exact formula/algorithm, where is it implemented (file:line), and what edge cases does the code handle?" 2. **Validations & eligibility** — "Find every business validation, eligibility check, and guard condition in legacy/$1. For each: what is being checked, what happens on pass/fail, where is it (file:line)?" 3. **State & lifecycle** — "Find every status field, state machine, and lifecycle transition in legacy/$1. For each entity: what states exist, what triggers transitions, what side-effects fire?" ## Synthesize Merge the three result sets. Deduplicate. For each distinct rule, write a **Rule Card** in this exact format: ``` ### RULE-NNN: **Category:** Calculation | Validation | Lifecycle | Policy **Priority:** P0 | P1 | P2 **Source:** `path/to/file.ext:line-line` **Plain English:** One sentence a business analyst would recognize. **Specification:** Given When Then [And ] **Parameters:** **Edge cases handled:** **Suspected defect:** **Confidence:** High | Medium | Low — ``` Priority heuristic — default to **P1**. Assign **P0** if the rule moves money, enforces a regulatory/compliance requirement, or guards data integrity (and flag P0 rules at