claude-raid 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +345 -0
  3. package/bin/cli.js +34 -0
  4. package/package.json +37 -0
  5. package/src/detect-project.js +112 -0
  6. package/src/doctor.js +201 -0
  7. package/src/init.js +138 -0
  8. package/src/merge-settings.js +119 -0
  9. package/src/remove.js +92 -0
  10. package/src/update.js +110 -0
  11. package/template/.claude/agents/archer.md +115 -0
  12. package/template/.claude/agents/rogue.md +116 -0
  13. package/template/.claude/agents/warrior.md +114 -0
  14. package/template/.claude/agents/wizard.md +206 -0
  15. package/template/.claude/hooks/validate-commit-message.sh +78 -0
  16. package/template/.claude/hooks/validate-file-naming.sh +73 -0
  17. package/template/.claude/hooks/validate-no-placeholders.sh +67 -0
  18. package/template/.claude/hooks/validate-phase-gate.sh +60 -0
  19. package/template/.claude/hooks/validate-tests-pass.sh +43 -0
  20. package/template/.claude/hooks/validate-verification.sh +70 -0
  21. package/template/.claude/raid-rules.md +21 -0
  22. package/template/.claude/skills/raid-debugging/SKILL.md +159 -0
  23. package/template/.claude/skills/raid-design/SKILL.md +208 -0
  24. package/template/.claude/skills/raid-finishing/SKILL.md +123 -0
  25. package/template/.claude/skills/raid-git-worktrees/SKILL.md +96 -0
  26. package/template/.claude/skills/raid-implementation/SKILL.md +155 -0
  27. package/template/.claude/skills/raid-implementation-plan/SKILL.md +173 -0
  28. package/template/.claude/skills/raid-protocol/SKILL.md +288 -0
  29. package/template/.claude/skills/raid-review/SKILL.md +133 -0
  30. package/template/.claude/skills/raid-tdd/SKILL.md +147 -0
  31. package/template/.claude/skills/raid-verification/SKILL.md +113 -0
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env bash
2
+ # Raid quality gate: validates file naming conventions
3
+ # PostToolUse hook for Write and Edit operations
4
+ # Reads conventions from .claude/raid.json
5
+ set -euo pipefail
6
+
7
+ INPUT=$(cat)
8
+ FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // empty')
9
+
10
+ if [ -z "$FILE_PATH" ]; then
11
+ exit 0
12
+ fi
13
+
14
+ RAID_CONFIG=".claude/raid.json"
15
+ ISSUES=""
16
+
17
+ # Read naming convention from config (default: none)
18
+ NAMING="none"
19
+ if [ -f "$RAID_CONFIG" ]; then
20
+ NAMING=$(jq -r '.conventions.fileNaming // "none"' "$RAID_CONFIG")
21
+ fi
22
+
23
+ BASENAME=$(basename "$FILE_PATH")
24
+
25
+ # Check 1: No spaces in filenames (always enforced)
26
+ if echo "$BASENAME" | grep -qE '[[:space:]]'; then
27
+ ISSUES="${ISSUES}NAMING: File '$BASENAME' contains spaces. Use hyphens or underscores.\n"
28
+ fi
29
+
30
+ # Check 2: Naming convention (if configured)
31
+ if [ "$NAMING" != "none" ]; then
32
+ # Strip extension for naming check
33
+ NAME_PART=$(echo "$BASENAME" | sed 's/\.[^.]*$//')
34
+
35
+ case "$NAMING" in
36
+ kebab-case)
37
+ if ! echo "$NAME_PART" | grep -qE '^[a-z0-9]+(-[a-z0-9]+)*$'; then
38
+ ISSUES="${ISSUES}NAMING: File '$BASENAME' does not follow kebab-case convention.\n"
39
+ fi
40
+ ;;
41
+ snake_case)
42
+ if ! echo "$NAME_PART" | grep -qE '^[a-z0-9]+(_[a-z0-9]+)*$'; then
43
+ ISSUES="${ISSUES}NAMING: File '$BASENAME' does not follow snake_case convention.\n"
44
+ fi
45
+ ;;
46
+ camelCase)
47
+ if ! echo "$NAME_PART" | grep -qE '^[a-z][a-zA-Z0-9]*$'; then
48
+ ISSUES="${ISSUES}NAMING: File '$BASENAME' does not follow camelCase convention.\n"
49
+ fi
50
+ ;;
51
+ esac
52
+ fi
53
+
54
+ # Check 3: Directory depth (default max 8)
55
+ MAX_DEPTH=8
56
+ if [ -f "$RAID_CONFIG" ]; then
57
+ CONFIGURED_DEPTH=$(jq -r '.conventions.maxDepth // empty' "$RAID_CONFIG")
58
+ if [ -n "$CONFIGURED_DEPTH" ]; then
59
+ MAX_DEPTH="$CONFIGURED_DEPTH"
60
+ fi
61
+ fi
62
+
63
+ DEPTH=$(echo "$FILE_PATH" | awk -F'/' '{print NF}')
64
+ if [ "$DEPTH" -gt "$MAX_DEPTH" ]; then
65
+ ISSUES="${ISSUES}STRUCTURE: File at depth $DEPTH ($FILE_PATH). Maximum is $MAX_DEPTH.\n"
66
+ fi
67
+
68
+ if [ -n "$ISSUES" ]; then
69
+ printf "Raid Quality Check:\n%b" "$ISSUES" >&2
70
+ exit 2
71
+ fi
72
+
73
+ exit 0
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env bash
2
+ # Raid quality gate: blocks placeholder text in specs and plans
3
+ # PostToolUse hook for Write and Edit operations
4
+ # Only checks files within configured specs/plans paths
5
+ set -euo pipefail
6
+
7
+ INPUT=$(cat)
8
+ FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // empty')
9
+
10
+ if [ -z "$FILE_PATH" ]; then
11
+ exit 0
12
+ fi
13
+
14
+ RAID_CONFIG=".claude/raid.json"
15
+
16
+ # Read paths from config (defaults)
17
+ SPECS_PATH="docs/raid/specs"
18
+ PLANS_PATH="docs/raid/plans"
19
+ if [ -f "$RAID_CONFIG" ]; then
20
+ CONFIGURED_SPECS=$(jq -r '.paths.specs // empty' "$RAID_CONFIG")
21
+ CONFIGURED_PLANS=$(jq -r '.paths.plans // empty' "$RAID_CONFIG")
22
+ [ -n "$CONFIGURED_SPECS" ] && SPECS_PATH="$CONFIGURED_SPECS"
23
+ [ -n "$CONFIGURED_PLANS" ] && PLANS_PATH="$CONFIGURED_PLANS"
24
+ fi
25
+
26
+ # Only check files in specs or plans directories
27
+ IS_RAID_DOC=false
28
+ case "$FILE_PATH" in
29
+ "$SPECS_PATH"/*|"$PLANS_PATH"/*) IS_RAID_DOC=true ;;
30
+ esac
31
+
32
+ if [ "$IS_RAID_DOC" = false ]; then
33
+ exit 0
34
+ fi
35
+
36
+ # Read the actual file content (tool_output is the tool's response message, not file content)
37
+ CONTENT=""
38
+ if [ -f "$FILE_PATH" ]; then
39
+ CONTENT=$(cat "$FILE_PATH")
40
+ fi
41
+
42
+ if [ -z "$CONTENT" ]; then
43
+ exit 0
44
+ fi
45
+
46
+ ISSUES=""
47
+ LINE_NUM=0
48
+
49
+ # Scan for placeholder patterns (case-insensitive)
50
+ while IFS= read -r line; do
51
+ LINE_NUM=$((LINE_NUM + 1))
52
+ LOWER_LINE=$(echo "$line" | tr '[:upper:]' '[:lower:]')
53
+
54
+ for PATTERN in "tbd" "todo" "fixme" "implement later" "add appropriate" "similar to task" "handle edge cases" "fill in"; do
55
+ if echo "$LOWER_LINE" | grep -qi "$PATTERN"; then
56
+ ISSUES="${ISSUES}Line ${LINE_NUM}: Found '${PATTERN}' — ${line}\n"
57
+ break
58
+ fi
59
+ done
60
+ done <<< "$CONTENT"
61
+
62
+ if [ -n "$ISSUES" ]; then
63
+ printf "Raid Placeholder Check:\nBLOCKED: Placeholders found in %s:\n%b\nRemove all placeholders before proceeding.\n" "$FILE_PATH" "$ISSUES" >&2
64
+ exit 2
65
+ fi
66
+
67
+ exit 0
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+ # Raid quality gate: blocks implementation without a design doc
3
+ # PreToolUse hook for Write operations
4
+ # Reads mode and paths from .claude/raid.json
5
+ set -euo pipefail
6
+
7
+ INPUT=$(cat)
8
+ FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // empty')
9
+
10
+ if [ -z "$FILE_PATH" ]; then
11
+ exit 0
12
+ fi
13
+
14
+ RAID_CONFIG=".claude/raid.json"
15
+
16
+ # Skip if no config (Raid not initialized)
17
+ if [ ! -f "$RAID_CONFIG" ]; then
18
+ exit 0
19
+ fi
20
+
21
+ # Skip if no active Raid session — don't block normal work
22
+ # The Wizard creates .claude/raid-session when a Raid starts
23
+ if [ ! -f ".claude/raid-session" ]; then
24
+ exit 0
25
+ fi
26
+
27
+ # Read mode and specs path
28
+ MODE=$(jq -r '.raid.defaultMode // "full"' "$RAID_CONFIG")
29
+ SPECS_PATH=$(jq -r '.paths.specs // "docs/raid/specs"' "$RAID_CONFIG")
30
+
31
+ # Scout mode: no phase gate
32
+ if [ "$MODE" = "scout" ]; then
33
+ exit 0
34
+ fi
35
+
36
+ # Skip checks for non-implementation files
37
+ # Allow: docs, tests, config files, raid files, markdown
38
+ case "$FILE_PATH" in
39
+ docs/*|test/*|tests/*|*.test.*|*.spec.*|*_test.*|*_spec.*) exit 0 ;;
40
+ .claude/*|*.json|*.yml|*.yaml|*.toml|*.md|*.lock) exit 0 ;;
41
+ *.config.*|*.rc|.gitignore|Makefile|Dockerfile) exit 0 ;;
42
+ esac
43
+
44
+ # Check if any design doc exists in specs path
45
+ if [ -d "$SPECS_PATH" ]; then
46
+ DOC_COUNT=$(find "$SPECS_PATH" -name "*.md" -type f 2>/dev/null | head -1)
47
+ if [ -n "$DOC_COUNT" ]; then
48
+ exit 0
49
+ fi
50
+ fi
51
+
52
+ # No design doc found
53
+ if [ "$MODE" = "full" ]; then
54
+ printf "Raid Phase Gate:\nBLOCKED: No design doc found in %s.\nCreate a design doc before writing implementation code.\nUse 'raid-design' skill or set mode to 'scout' in .claude/raid.json.\n" "$SPECS_PATH" >&2
55
+ exit 2
56
+ fi
57
+
58
+ # Skirmish mode: warn only
59
+ printf "Raid Phase Gate:\nWARNING: No design doc found in %s. Consider creating one.\n" "$SPECS_PATH" >&2
60
+ exit 0
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env bash
2
+ # Raid quality gate: runs tests before allowing commits
3
+ # PreToolUse hook for Bash commands containing 'git commit'
4
+ # Reads test command from .claude/raid.json
5
+ set -euo pipefail
6
+
7
+ INPUT=$(cat)
8
+ COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
9
+
10
+ # Only check git commit commands
11
+ if ! echo "$COMMAND" | grep -qE 'git commit'; then
12
+ exit 0
13
+ fi
14
+
15
+ RAID_CONFIG=".claude/raid.json"
16
+
17
+ # Skip if no active Raid session
18
+ if [ ! -f ".claude/raid-session" ]; then
19
+ exit 0
20
+ fi
21
+
22
+ # Read test command from config
23
+ TEST_CMD=""
24
+ if [ -f "$RAID_CONFIG" ]; then
25
+ TEST_CMD=$(jq -r '.project.testCommand // empty' "$RAID_CONFIG")
26
+ fi
27
+
28
+ # No test command configured — warn but allow
29
+ if [ -z "$TEST_CMD" ]; then
30
+ exit 0
31
+ fi
32
+
33
+ # Run tests
34
+ if ! eval "$TEST_CMD" > /dev/null 2>&1; then
35
+ printf "Raid Quality Check:\nTESTS: Tests failed. Fix before committing.\nCommand: %s\n" "$TEST_CMD" >&2
36
+ exit 2
37
+ fi
38
+
39
+ # Write timestamp for verification hook
40
+ mkdir -p .claude
41
+ date +%s > .claude/raid-last-test-run
42
+
43
+ exit 0
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env bash
2
+ # Raid quality gate: blocks completion claims without recent test evidence
3
+ # PreToolUse hook for Bash commands containing 'git commit'
4
+ # Checks for .claude/raid-last-test-run timestamp (written by validate-tests-pass.sh)
5
+ set -euo pipefail
6
+
7
+ INPUT=$(cat)
8
+ COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
9
+
10
+ # Only check git commit commands
11
+ if ! echo "$COMMAND" | grep -qE 'git commit'; then
12
+ exit 0
13
+ fi
14
+
15
+ # Skip if no active Raid session
16
+ if [ ! -f ".claude/raid-session" ]; then
17
+ exit 0
18
+ fi
19
+
20
+ # Extract commit message
21
+ MSG=""
22
+ if echo "$COMMAND" | grep -qE -- '-m '; then
23
+ MSG=$(echo "$COMMAND" | sed -n 's/.*-m "\([^"]*\)".*/\1/p' | head -1)
24
+ if [ -z "$MSG" ]; then
25
+ MSG=$(echo "$COMMAND" | sed -n "s/.*-m '\\([^']*\\)'.*/\\1/p" | head -1)
26
+ fi
27
+ fi
28
+
29
+ # Try heredoc
30
+ if [ -z "$MSG" ]; then
31
+ MSG=$(echo "$COMMAND" | sed -n 's/.*cat <<.*//;n;s/^ *//;p' | head -1)
32
+ fi
33
+
34
+ if [ -z "$MSG" ]; then
35
+ exit 0
36
+ fi
37
+
38
+ # Check if message claims completion
39
+ LOWER_MSG=$(echo "$MSG" | tr '[:upper:]' '[:lower:]')
40
+ HAS_COMPLETION=false
41
+ for WORD in "complete" "done" "finish" "final"; do
42
+ if echo "$LOWER_MSG" | grep -qiw "$WORD"; then
43
+ HAS_COMPLETION=true
44
+ break
45
+ fi
46
+ done
47
+
48
+ if [ "$HAS_COMPLETION" = false ]; then
49
+ exit 0
50
+ fi
51
+
52
+ # Check for recent test run
53
+ TIMESTAMP_FILE=".claude/raid-last-test-run"
54
+ MAX_AGE=600 # 10 minutes in seconds
55
+
56
+ if [ ! -f "$TIMESTAMP_FILE" ]; then
57
+ printf "Raid Verification Check:\nBLOCKED: Commit claims completion but no test run evidence found.\nRun tests before claiming work is complete.\n" >&2
58
+ exit 2
59
+ fi
60
+
61
+ LAST_RUN=$(cat "$TIMESTAMP_FILE")
62
+ NOW=$(date +%s)
63
+ AGE=$((NOW - LAST_RUN))
64
+
65
+ if [ "$AGE" -gt "$MAX_AGE" ]; then
66
+ printf "Raid Verification Check:\nBLOCKED: Last test run was %d minutes ago. Run tests again before claiming completion.\n" "$((AGE / 60))" >&2
67
+ exit 2
68
+ fi
69
+
70
+ exit 0
@@ -0,0 +1,21 @@
1
+ # Raid Team Rules
2
+
3
+ These are non-negotiable. Every agent follows them at all times.
4
+
5
+ 1. **No subagents.** This team uses agent teams only. Never delegate to subagents.
6
+ 2. **No laziness.** Every review is genuine. Every challenge carries new evidence or a new angle. No rubber-stamping.
7
+ 3. **No trust without verification.** Verify independently. Reports lie — read actual code.
8
+ 4. **Learn from mistakes.** When proven wrong, absorb the lesson. When another agent errs, learn from that too. Don't repeat errors.
9
+ 5. **Make every move count.** Limited moves, like a board game. No endless disputes. No circular arguments. Every interaction must carry the work forward. If you've made your point and been heard, move on.
10
+ 6. **Share knowledge.** Competitors but also a team. Discoveries are shared. The goal is maximum quality, not personal victory.
11
+ 7. **No ego.** Defend ideas with evidence. If you don't have evidence, don't defend. If proven wrong, concede instantly. Don't be stubborn. Don't hallucinate. Hesitate if uncertain.
12
+ 8. **Stay active.** All assigned agents participate at every step. No sitting idle while others work.
13
+ 9. **Wizard is the human interface.** Agents ask the Wizard for clarification. Only the Wizard asks the human important questions. Agents may ask the human only if the Wizard explicitly permits it.
14
+ 10. **Wizard is impartial.** No preference for any agent. Judge by evidence, not by source.
15
+ 11. **Wizard observes 90%, acts 10%.** The Wizard analyzes, judges, and maintains order. Speaks only when 90% confident or when the team is misaligned.
16
+ 12. **Maximum effort. Always.** Every agent runs at full capability on every task.
17
+ 13. **No hallucination.** If you don't know something, say so. Never fabricate evidence, certainty, or findings.
18
+ 14. **Dungeon discipline.** Only pin verified findings with `📌 DUNGEON:`. Don't spam. If challenged on a pin, defend with evidence or remove it. The Dungeon is a scoreboard, not a chat log.
19
+ 15. **Direct engagement.** Address agents by name with `@Name`. Build on each other's work explicitly with `🔗 BUILDING ON @Name:`. No broadcasting into void. No waiting for the Wizard to relay.
20
+ 16. **Escalate wisely.** Pull the Wizard with `🆘 WIZARD:` when genuinely stuck, split on fundamentals, or uncertain about project-level context. If you can resolve it by reading code or talking to another agent, do that first. Lazy escalation wastes the Wizard's attention.
21
+ 17. **Roast with evidence.** Every `🔥 ROAST:` carries proof — file paths, line numbers, concrete scenarios. "This is wrong" without showing why is laziness, not challenge.
@@ -0,0 +1,159 @@
1
+ ---
2
+ name: raid-debugging
3
+ description: "Use when encountering any bug, test failure, or unexpected behavior. Agents investigate competing hypotheses in parallel. No fixes without root cause. No subagents."
4
+ ---
5
+
6
+ # Raid Debugging — Adversarial Root Cause Analysis
7
+
8
+ Three investigators, three hypotheses, one truth.
9
+
10
+ **Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
11
+
12
+ **Violating the letter of this process is violating the spirit of debugging.**
13
+
14
+ ## The Iron Law
15
+
16
+ ```
17
+ NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
18
+ ```
19
+
20
+ If you haven't completed Phase 1, you cannot propose fixes.
21
+
22
+ ## Mode Behavior
23
+
24
+ - **Full Raid**: 3 agents investigate competing hypotheses in parallel.
25
+ - **Skirmish**: 2 agents with different hypotheses.
26
+ - **Scout**: 1 agent investigates + Wizard challenges the hypothesis.
27
+
28
+ ## Process Flow
29
+
30
+ ```dot
31
+ digraph debugging {
32
+ "Bug encountered" -> "Phase 1: Root Cause Investigation";
33
+ "Phase 1: Root Cause Investigation" -> "Reproduce consistently?";
34
+ "Reproduce consistently?" -> "Gather more data" [label="no"];
35
+ "Gather more data" -> "Reproduce consistently?";
36
+ "Reproduce consistently?" -> "Dispatch competing hypotheses" [label="yes"];
37
+ "Dispatch competing hypotheses" -> "Agents investigate independently";
38
+ "Agents investigate independently" -> "Phase 2: Pattern Analysis";
39
+ "Phase 2: Pattern Analysis" -> "Phase 3: Hypothesis Testing";
40
+ "Phase 3: Hypothesis Testing" -> "Hypothesis confirmed?" [shape=diamond];
41
+ "Hypothesis confirmed?" -> "New hypothesis" [label="no"];
42
+ "New hypothesis" -> "Phase 3: Hypothesis Testing";
43
+ "Hypothesis confirmed?" -> "Wizard ruling: root cause identified" [label="yes"];
44
+ "Wizard ruling: root cause identified" -> "Phase 4: Fix (TDD)";
45
+ "Phase 4: Fix (TDD)" -> "Fix works?" [shape=diamond];
46
+ "Fix works?" -> "3+ failed fixes?" [label="no"];
47
+ "3+ failed fixes?" -> "Question architecture" [label="yes"];
48
+ "3+ failed fixes?" -> "New hypothesis" [label="no"];
49
+ "Fix works?" -> "Cross-test fix + verify" [label="yes"];
50
+ "Cross-test fix + verify" -> "Done" [shape=doublecircle];
51
+ }
52
+ ```
53
+
54
+ ## The Four Phases
55
+
56
+ ### Phase 1: Root Cause Investigation
57
+
58
+ **BEFORE attempting ANY fix:**
59
+
60
+ 1. **Read error messages carefully** — stack traces, line numbers, error codes. Don't skip past them. The answer is often in the first error.
61
+ 2. **Reproduce consistently** — exact steps, every time. If not reproducible, gather more data — don't guess. An unreproducible bug is not understood.
62
+ 3. **Check recent changes** — `git diff`, recent commits, new dependencies, config changes. What changed since it last worked?
63
+ 4. **Gather evidence at boundaries** — in multi-component systems, log what enters and exits each component boundary. Run once to see WHERE it breaks. THEN investigate that component.
64
+ 5. **Trace data flow** — where does the bad value originate? Keep tracing upstream until you find the source. Fix at source, not at symptom.
65
+
66
+ ### Phase 2: Pattern Analysis
67
+
68
+ 1. **Find working examples** of similar code in the same codebase
69
+ 2. **Read reference implementations COMPLETELY** — don't skim. The difference between working and broken is often subtle.
70
+ 3. **List every difference** between working and broken, however small
71
+ 4. **Understand dependency assumptions** — what does this code expect from its environment?
72
+
73
+ ### Phase 3: Hypothesis and Testing
74
+
75
+ 1. **Form a single, specific hypothesis:** "X is the root cause because Y"
76
+ 2. **Make the SMALLEST possible change** to test it. One variable at a time.
77
+ 3. **Did it work?** -> Phase 4. **Didn't work?** -> NEW hypothesis. Don't pile fixes on top of failed fixes.
78
+
79
+ ### Phase 4: Fix Implementation
80
+
81
+ 1. **Write a failing test** that reproduces the bug (use `raid-tdd`)
82
+ 2. **Implement single fix** addressing root cause
83
+ 3. **Verify** — test passes, no regressions (run test command from `.claude/raid.json`)
84
+ 4. **Cross-testing** by challengers — does the fix introduce new issues?
85
+
86
+ ## Raid-Specific: Competing Hypotheses
87
+
88
+ The Wizard dispatches all agents with different hypotheses. After dispatch, agents debate directly:
89
+
90
+ **📡 DISPATCH:**
91
+ > **@Warrior**: Investigate [structural/data cause]. Reproduce. Trace data flow. Gather evidence at boundaries.
92
+ > **@Archer**: Investigate [integration/contract cause]. Check interfaces, type mismatches, implicit contracts, dependency versions.
93
+ > **@Rogue**: Investigate [timing/state/adversarial cause]. Race conditions, stale state, environment assumptions, concurrent access.
94
+ >
95
+ > **All**: Investigate independently, then debate directly. Challenge each other's hypotheses with evidence. Build on each other's findings. Pin verified evidence to the Dungeon. The hypothesis that survives cross-testing wins. Escalate to me with `🆘 WIZARD:` only if stuck.
96
+
97
+ **How agents debate root cause:**
98
+ - `⚔️ CHALLENGE: @Rogue, your race condition hypothesis doesn't explain why it fails on single-threaded test runs — evidence: [test output]`
99
+ - `🔗 BUILDING ON @Warrior: Your data flow trace reveals the value originates from the config loader, not the API call — here's the upstream path: ...`
100
+ - `📌 DUNGEON: Root cause evidence — config loader at config.js:47 returns stale cache when called concurrently [verified by @Archer and @Warrior]`
101
+
102
+ The hypothesis that survives direct cross-testing gets the Wizard's ruling:
103
+
104
+ ⚡ WIZARD RULING: Root cause is [X] because [evidence from Dungeon].
105
+
106
+ ## Root Cause Tracing
107
+
108
+ When tracing a bad value upstream:
109
+
110
+ ```
111
+ 1. Start at the symptom (where the bug manifests)
112
+ 2. Find where the bad value is used
113
+ 3. Find where it was set
114
+ 4. Is THIS the source? Or was it passed from somewhere else?
115
+ 5. If passed: go to the caller. Repeat from step 2.
116
+ 6. When you find where the value ORIGINATES incorrectly: that's the root cause.
117
+ 7. Fix at the source. Add validation at boundaries for defense-in-depth.
118
+ ```
119
+
120
+ ## 3+ Fixes Failed? Question Architecture
121
+
122
+ If 3 or more fix attempts fail, **STOP fixing and question architecture:**
123
+
124
+ - Each fix revealing a new problem in a different place = architectural issue, not implementation bug
125
+ - All three agents discuss fundamentals
126
+ - Wizard decides: fix architecture or escalate to human with evidence
127
+
128
+ This is not failure — it's the system working. Detecting architectural problems before sinking more time into symptom fixes.
129
+
130
+ ## Defense in Depth
131
+
132
+ After finding and fixing the root cause, add validation at multiple layers:
133
+
134
+ 1. **Entry point** — validate at the boundary where bad data enters
135
+ 2. **Business logic** — assert preconditions at the function that broke
136
+ 3. **Environment guards** — check assumptions about dependencies/state
137
+ 4. **Debug instrumentation** — add logging at key boundaries for future diagnosis
138
+
139
+ ## Red Flags — STOP and Follow Process
140
+
141
+ | Thought | Reality |
142
+ |---------|---------|
143
+ | "Quick fix for now" | NO. Find root cause. Quick fixes become permanent. |
144
+ | "Just try changing X" | NO. Hypothesize first. Random changes = random results. |
145
+ | "I'm confident it's Y" | Confidence ≠ evidence. Verify before acting. |
146
+ | "One more fix attempt" (after 2 failures) | STOP. Question architecture. |
147
+ | "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. Trace it. |
148
+ | "The issue is simple, don't need process" | Simple issues have root causes too. Process is fast. |
149
+ | "Emergency, no time" | Systematic debugging is FASTER than thrashing. Always. |
150
+ | "Just try this first" | The first fix sets the pattern. Do it right. |
151
+
152
+ ## Escalation
153
+
154
+ | Situation | Action |
155
+ |-----------|--------|
156
+ | Can't reproduce | Gather more data. Instrument boundaries. Don't guess. |
157
+ | Root cause identified but fix is risky | Present to human with evidence and risk assessment. |
158
+ | 3+ fixes failed | Architectural discussion. Don't force through. |
159
+ | Bug is in a dependency | Document, workaround, and report upstream. |