/** * Systematic debugging instructions for sub-agent prompts. * Matches supipowers' systematic-debugging skill depth. */ export function buildDebuggingInstructions(): string { return [ "## Systematic Debugging", "", "### Iron Law", "", "NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.", "Symptom fixes are failure. Find root cause before attempting any fix.", "", "### Phase 1: Root Cause Investigation", "", "Complete this phase before proposing fixes:", "", "1. **Read the error message carefully.** Don't skip it; it often contains the solution.", "2. **Reproduce consistently.** Exact steps, every time.", "3. **Check recent changes.** Run `git diff` to see what changed. Check new dependencies, config changes.", "4. **Gather evidence** in multi-component systems: add diagnostic instrumentation at each boundary.", "5. **Trace the data flow** backward through the call stack to find the original trigger.", "", "### Phase 2: Pattern Analysis", "", "1. Find a working example in the codebase that does something similar.", "2. Compare against the reference completely (don't skim).", "3. Identify differences between working and broken.", "4. Understand dependencies and assumptions.", "", "### Phase 3: Hypothesis and Testing", "", "1. Form a single, specific hypothesis (not vague).", "2. Test minimally: smallest possible change, one variable at a time.", "3. Verify before continuing. If wrong → form a NEW hypothesis, not more fixes.", "4. Admit uncertainty. Don't pretend to know.", "", "### Phase 4: Implementation", "", "1. Create a failing test case first (automated or manual).", "2. Implement a single fix that addresses the root cause only.", "3. Verify the fix: test passes, no other tests broken.", "4. **If the fix doesn't work:**", " - Fewer than 3 attempts → return to Phase 1 with new information", " - 3 or more attempts → STOP and question the architecture. Discuss with human partner.", "", "### Red Flags — STOP and Follow the Process", "", '- "Quick fix for now, investigate later"', '- "Just try changing X and see if it works"', '- "Skip the test, I\'ll manually verify"', '- "It\'s probably X, let me fix that"', '- "I don\'t fully understand but this might work"', '- "One more fix attempt" (when already tried 2+)', "- Each fix reveals a new problem in a different place", ].join("\n"); }