<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."4user-invocable: true5allowed-tools: Agent, Bash, Read, Write, Grep, Glob6kernel:7 kind: workflow8 version: 19 side_effects: none10 confirmation: none11---1213<skill id="diagnose">1415<purpose>16Diagnose before fixing. The debug skill holds the methodology; this workflow orchestrates it.17Mixing diagnosis with implementation means the surgeon starts cutting before the X-ray.18/kernel:diagnose is the X-ray.19</purpose>2021<on_start>22agentdb recall "<exact error> <subsystem> <test> <files/symbols>" --global23# Recall again after isolation reveals better symbols, when the hypothesis changes,24# or when a different failure appears.25</on_start>2627<skill_load>28Load: skills/debug/SKILL.md, skills/build/reference/testing.md, skills/architecture/SKILL.md29</skill_load>3031<modes>32 <mode id="bug" default="true">33 <trigger>error, failing test, stack trace, "not working", exception, crash</trigger>34 <steps>35 <step id="reproduce">36 Read error output, failing test, or stack trace.37 Run the failing command/test to confirm reproduction.38 If not reproducible, document conditions and ask for more info.39 </step>40 <step id="trace">41 Follow the call stack from error to origin.42 Check recent git changes: git log --oneline --since="3 days" -- {affected files}43 Identify when the behavior changed.44 </step>45 <step id="isolate">46 Run failing test in isolation (not full suite).47 If multiple tests fail, find the minimal reproduction.48 Binary search: comment out code blocks to narrow the cause.49 </step>50 <step id="hypothesize">51 Form 2-3 hypotheses for root cause.52 For each hypothesis: what evidence would confirm or reject it?53 Test each hypothesis with minimal code changes or debug output.5455 <ask_user>56 Use AskUserQuestion when: hypotheses formed and user may have domain knowledge57 Ask: "Top hypothesis: {hypothesis}. Does this match what you're seeing, or is there context I'm missing?"58 Options: investigate that, I have more context, try a different hypothesis59 </ask_user>60 </step>61 <step id="diagnose">62 Identify confirmed root cause.63 List affected files and blast radius.64 Recommend fix approach (don't implement yet).65 Determine tier based on blast radius.66 </step>67 <step id="handoff">68 Output structured diagnosis.69 Hand off to /kernel:ingest or /kernel:forge for implementation.70 If the user wants to fix immediately, transition to execute mode.71 </step>72 </steps>73 </mode>7475 <mode id="refactor">76 <trigger>refactor, restructure, "clean up", "simplify", coupling, dependency</trigger>77 <steps>78 <step id="map">79 Identify all files/modules touched by the refactor target.80 Use Grep/Glob to find all references.81 Build a dependency map of what imports/calls what.82 </step>83 <step id="trace_deps">84 For each file in the map: who calls this? who depends on it?85 What breaks if this changes?86 Identify the blast radius.87 </step>88 <step id="measure_coupling">89 How tangled is this code with the rest of the system?90 Count cross-module references.91 Identify circular dependencies.92 </step>93 <step id="risks">94 What are the edge cases in the current implementation?95 What tests exist? What's untested?96 What invariants must be preserved?97 </step>98 <step id="diagnose">99 Produce restructuring plan with safety constraints.100 List files that change, in what order.101 Identify tests that must pass before AND after.102 Determine tier by reversibility x blast radius (file count is only a weak hint).103 </step>104 <step id="handoff">105 Output structured diagnosis.106 Hand off to /kernel:ingest with pre-identified scope.107 </step>108 </steps>109 </mode>110</modes>111112<output_format>113## Diagnosis: {title}114115**Mode:** bug | refactor116**Root cause:** {one sentence}117**Confidence:** high | medium | low118119### Affected Files120| File | Role |121|------|------|122| {path} | origin — where the bug lives / refactor starts |123| {path} | downstream — affected by the change |124125### Blast Radius126{N} files affected. **Tier {1|2|3}.**127128### Hypotheses Tested (bug mode)1291. "{hypothesis}" → CONFIRMED | REJECTED ({evidence})130131### Dependency Map (refactor mode)132{what depends on what}133134### Recommended Approach135{what to do, not how — that's for ingest/forge}136137### Tests Required138- {test that must pass before the fix}139- {test that validates the fix}140141---142**Next:** /kernel:ingest or /kernel:forge to implement.143</output_format>144145<telemetry>146Record diagnosis event:147 agentdb emit command "diagnose" "" '{"mode":"bug|refactor","confidence":"high|medium|low","blast_radius":N,"tier":N}'148</telemetry>149150</skill>