--- description: Debug issues with parallel agents on competing hypotheses output-dir: dist/commands --- @import { knowledge_writeback } from "./_partials/_knowledge.mds" @import { decisions_load } from "./_partials/_decisions.mds" @import { issue_ref_grammar, issue_capture_contract } from "./_partials/_tracker.mds" @import "./_partials/_settings.mds" as settings @import "./_partials/_compliance.mds" as compliance # Debug Command ## Usage ``` /debug "description of bug or issue" /debug "function returns undefined when called with empty array" /debug #42 (investigate bug from issue reference) ``` ## Input What follows `/debug` is bound once, here. Every later step names it `COMMAND_INPUT` and never restates it: $ARGUMENTS An empty `COMMAND_INPUT` means: use the conversation context. ## Phases ### Phase 1: Load Decisions Index (Orchestrator-Local) ### Phase 1: Resolve Settings **Produces:** DECISIONS_CONTEXT {{settings.settings_resolve()}} From the same line: {{compliance.compliance_frameworks()}} {{compliance.compliance_inject()}} Phase 7 passes `COMPLIANCE_DIRECTIVE` to the Code agent that implements the fix, on a line of its own. {{decisions_load()}} The orchestrator uses `DECISIONS_CONTEXT` locally when generating hypotheses (Phase 2) — prior pitfalls and decisions can suggest specific root causes to investigate. Follow `devflow:apply-decisions` to Read full entry bodies on demand. **Do NOT pass `DECISIONS_CONTEXT` to Explore investigators** — decisions context stays in the orchestrator; investigators examine code directly. **No up-front feature knowledge load** — debug investigation workers read code directly to avoid confirmation bias. Write back only if the investigation found durable, cross-cutting knowledge. ### Phase 2: Context Gathering **Produces:** HYPOTHESES, BUG_CONTEXT **Requires:** DECISIONS_CONTEXT If `COMMAND_INPUT` opens with a candidate issue reference, fetch the issue: {{issue_ref_grammar()}} ``` Agent(subagent_type="Git"): "OPERATION: fetch-issue ISSUE_INPUT: {issue reference} Return issue title, body, labels, and any linked error logs." ``` {{issue_capture_contract()}} If the Git agent returns only a TRACEABILITY: DEGRADED line and no issue content, report that line verbatim to the user and use AskUserQuestion to request the bug description before generating any hypotheses — do not fabricate a description from the raw candidate token alone. Analyze the bug description (from arguments or issue) and identify 3-5 plausible hypotheses. Each hypothesis must be: - **Specific**: Points to a concrete mechanism (not "something is wrong") - **Testable**: Can be confirmed or disproved by reading code/logs - **Distinct**: Does not overlap significantly with other hypotheses ### Phase 3: Investigate (Parallel) **Produces:** INVESTIGATION_RESULTS **Requires:** HYPOTHESES Spawn one Explore agent per hypothesis in a **single message** (parallel execution): ``` Agent(subagent_type="Explore"): "Investigate this bug: {bug_description} Hypothesis: {hypothesis A description} Focus area: {specific code area, mechanism, or condition} Steps: 1. Read relevant code files in your focus area 2. Trace data flow related to this hypothesis 3. Collect evidence FOR this hypothesis (with file:line references) 4. Collect evidence AGAINST this hypothesis (with file:line references) Return a structured report: - Hypothesis: {restate} - Status: CONFIRMED / DISPROVED / PARTIAL - Evidence FOR: [list with file:line refs] - Evidence AGAINST: [list with file:line refs] - Key finding: {one-sentence summary} Keep the whole report to at most about 1,500 tokens." Agent(subagent_type="Explore"): "Investigate this bug: {bug_description} Hypothesis: {hypothesis B description} Focus area: {specific code area, mechanism, or condition} [same steps and return format; the whole report at most about 1,500 tokens]" Agent(subagent_type="Explore"): "Investigate this bug: {bug_description} Hypothesis: {hypothesis C description} Focus area: {specific code area, mechanism, or condition} [same steps and return format; the whole report at most about 1,500 tokens]" (Add more investigators if bug complexity warrants 4-5 hypotheses) ``` ### Phase 4: Converge **Produces:** CONVERGENCE_DECISION **Requires:** INVESTIGATION_RESULTS Evaluate investigation verdicts before synthesis: - **One CONFIRMED**: Spawn 1-2 additional `Agent(subagent_type="Explore")` agents to validate from different angles (prevent confirmation bias), each reporting at most about 1,500 tokens - **Multiple PARTIAL**: Look for a unifying root cause that explains all partial evidence - **All DISPROVED**: Report honestly — "No root cause identified from initial hypotheses." Generate 2-3 second-round hypotheses if conversation context suggests avenues not yet explored. Loop back to Phase 3. ### Phase 5: Synthesize **Produces:** ROOT_CAUSE_SYNTHESIS **Requires:** INVESTIGATION_RESULTS, CONVERGENCE_DECISION Once all investigators return, spawn a Synthesize agent to aggregate findings: ``` Agent(subagent_type="Synthesize"): "You are a root cause analyst. Synthesize these investigation reports: {paste all investigator reports} Instructions: 1. Compare evidence across all hypotheses 2. Identify which hypothesis has the strongest evidence 3. Note contradictions between investigators 4. Determine overall root cause (may combine partial findings) 5. Assess confidence level based on evidence strength" ``` ### Phase 6: Report **Requires:** ROOT_CAUSE_SYNTHESIS Produce the final report: ```markdown ## Root Cause Analysis: {bug description} ### Root Cause {Description of the root cause supported by evidence} {Key evidence with file:line references} ### Investigation Summary | Hypothesis | Status | Key Evidence | |-----------|--------|-------------| | A: {description} | CONFIRMED/DISPROVED/PARTIAL | {file:line + summary} | | B: {description} | CONFIRMED/DISPROVED/PARTIAL | {file:line + summary} | | C: {description} | CONFIRMED/DISPROVED/PARTIAL | {file:line + summary} | ### Key Findings {2-3 most important discoveries across all investigators} ### Recommended Fix {Concrete action items with file references} ### Confidence Level {HIGH/MEDIUM/LOW based on evidence strength and investigator agreement} ``` ### Phase 7: Offer Fix **Requires:** ROOT_CAUSE_SYNTHESIS Ask user via AskUserQuestion: "Want me to implement this fix?" - **YES** → implement the fix through the Code agent, never in this thread, then spawn `Agent(subagent_type="Polish")` on the changed files. /debug loads no feature knowledge, so the fix gets none: ``` Agent(subagent_type="Code"): "OPERATION: implement TASK_ID: debug-{YYYY-MM-DD_HHMM} TASK_DESCRIPTION: Implement the fix for this root cause: {bug description} EXECUTION_PLAN: {Root Cause, Key Findings and Recommended Fix from Phase 6, with their file:line references} PUSH: false DECISIONS_CONTEXT: {decisions_context} FEATURE_KNOWLEDGE: (none) {COMPLIANCE_DIRECTIVE}" ``` - **NO** → Done. Report stands as documentation. {{knowledge_writeback()}} ## Principles 1. **Competing hypotheses** - Never investigate a single theory; always have alternatives 2. **Evidence-based** - Every claim requires file:line references 3. **Honest uncertainty** - If no hypothesis survives, report that clearly ## Error Handling - If fewer than 3 hypotheses can be generated: proceed with 2, note limited scope - If all hypotheses are disproved: report "No root cause identified" with investigation summary - If an investigator errors: continue with remaining results, note the gap - If convergence validation contradicts the original confirmation: downgrade confidence and report contradicting evidence