<ask_user>
Use AskUserQuestion when: hypotheses formed and user may have domain knowledge
Ask: "Top hypothesis: {hypothesis}. Does this match what you're seeing, or is there context I'm missing?"
Options: investigate that, I have more context, try a different hypothesis
</ask_user>
</step>
<step id="diagnose">
Identify confirmed root cause.
List affected files and blast radius.
Recommend fix approach (don't implement yet).
Determine tier based on blast radius.
</step>
<step id="handoff">
Output structured diagnosis.
Hand off to /kernel:ingest or /kernel:forge for implementation.
If the user wants to fix immediately, transition to execute mode.
</step>
</steps>
Mode: bug | refactor
Root cause: {one sentence}
Confidence: high | medium | low
Affected Files
| File |
Role |
| {path} |
origin — where the bug lives / refactor starts |
| {path} |
downstream — affected by the change |
Blast Radius
{N} files affected. Tier {1|2|3}.
Hypotheses Tested (bug mode)
- "{hypothesis}" → CONFIRMED | REJECTED ({evidence})
Dependency Map (refactor mode)
{what depends on what}
Recommended Approach
{what to do, not how — that's for ingest/forge}
Tests Required
- {test that must pass before the fix}
- {test that validates the fix}
Next: /kernel:ingest or /kernel:forge to implement.
1---2name: diagnose3description: Systematic debugging and refactor analysis. Diagnosis before prescription. Bug mode: reproduce, trace, isolate, hypothesize, diagnose. Refactor mode: map, trace deps, measure coupling, risks, diagnose.4---56<skill id="diagnose">78<purpose>9Diagnose before fixing. The debug skill holds the methodology; this workflow orchestrates it.10Mixing diagnosis with implementation means the surgeon starts cutting before the X-ray.11/kernel:diagnose is the X-ray.12</purpose>1314<on_start>15agentdb recall "<exact error> <subsystem> <test> <files/symbols>" --global16# Recall again after isolation reveals better symbols, when the hypothesis changes,17# or when a different failure appears.18</on_start>1920<skill_load>21Load: skills/debug/SKILL.md, skills/build/reference/testing.md, skills/architecture/SKILL.md22</skill_load>2324<modes>25 <mode id="bug" default="true">26 <trigger>error, failing test, stack trace, "not working", exception, crash</trigger>27 <steps>28 <step id="reproduce">29 Read error output, failing test, or stack trace.30 Run the failing command/test to confirm reproduction.31 If not reproducible, document conditions and ask for more info.32 </step>33 <step id="trace">34 Follow the call stack from error to origin.35 Check recent git changes: git log --oneline --since="3 days" -- {affected files}36 Identify when the behavior changed.37 </step>38 <step id="isolate">39 Run failing test in isolation (not full suite).40 If multiple tests fail, find the minimal reproduction.41 Binary search: comment out code blocks to narrow the cause.42 </step>43 <step id="hypothesize">44 Form 2-3 hypotheses for root cause.45 For each hypothesis: what evidence would confirm or reject it?46 Test each hypothesis with minimal code changes or debug output.4748 <ask_user>49 Use AskUserQuestion when: hypotheses formed and user may have domain knowledge50 Ask: "Top hypothesis: {hypothesis}. Does this match what you're seeing, or is there context I'm missing?"51 Options: investigate that, I have more context, try a different hypothesis52 </ask_user>53 </step>54 <step id="diagnose">55 Identify confirmed root cause.56 List affected files and blast radius.57 Recommend fix approach (don't implement yet).58 Determine tier based on blast radius.59 </step>60 <step id="handoff">61 Output structured diagnosis.62 Hand off to /kernel:ingest or /kernel:forge for implementation.63 If the user wants to fix immediately, transition to execute mode.64 </step>65 </steps>66 </mode>6768 <mode id="refactor">69 <trigger>refactor, restructure, "clean up", "simplify", coupling, dependency</trigger>70 <steps>71 <step id="map">72 Identify all files/modules touched by the refactor target.73 Use Grep/Glob to find all references.74 Build a dependency map of what imports/calls what.75 </step>76 <step id="trace_deps">77 For each file in the map: who calls this? who depends on it?78 What breaks if this changes?79 Identify the blast radius.80 </step>81 <step id="measure_coupling">82 How tangled is this code with the rest of the system?83 Count cross-module references.84 Identify circular dependencies.85 </step>86 <step id="risks">87 What are the edge cases in the current implementation?88 What tests exist? What's untested?89 What invariants must be preserved?90 </step>91 <step id="diagnose">92 Produce restructuring plan with safety constraints.93 List files that change, in what order.94 Identify tests that must pass before AND after.95 Determine tier by reversibility x blast radius (file count is only a weak hint).96 </step>97 <step id="handoff">98 Output structured diagnosis.99 Hand off to /kernel:ingest with pre-identified scope.100 </step>101 </steps>102 </mode>103</modes>104105<output_format>106## Diagnosis: {title}107108**Mode:** bug | refactor109**Root cause:** {one sentence}110**Confidence:** high | medium | low111112### Affected Files113| File | Role |114|------|------|115| {path} | origin — where the bug lives / refactor starts |116| {path} | downstream — affected by the change |117118### Blast Radius119{N} files affected. **Tier {1|2|3}.**120121### Hypotheses Tested (bug mode)1221. "{hypothesis}" → CONFIRMED | REJECTED ({evidence})123124### Dependency Map (refactor mode)125{what depends on what}126127### Recommended Approach128{what to do, not how — that's for ingest/forge}129130### Tests Required131- {test that must pass before the fix}132- {test that validates the fix}133134---135**Next:** /kernel:ingest or /kernel:forge to implement.136</output_format>137138<telemetry>139Record diagnosis event:140 agentdb emit command "diagnose" "" '{"mode":"bug|refactor","confidence":"high|medium|low","blast_radius":N,"tier":N}'141</telemetry>142143</skill>