skills/reflect/SKILL.md
Diagnose agent deviations and rule violations via root cause analysis. Triggers on "reflect", "diagnose deviation", "root cause", "why did you do X", "what went wrong", or "RCA". Must run in the session where the deviation occurred.
npx skillsauth add ddaanet/agent-core reflectInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Perform structured root cause analysis of agent behavior deviations within the current session context. Diagnoses why an agent violated rules, bypassed constraints, or rationalized exceptions.
First action: Emit session-break framing block to force cognitive reset from execution mode to diagnostic mode:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔍 REFLECT MODE — Deviation Diagnosis
Previous task suspended. Analyzing conversation for rule violations.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Why critical: Without explicit framing, the agent remains in execution mode and applies quick fixes instead of performing systematic diagnosis. The framing block forces diagnostic mindset.
Scan conversation context (no tool calls needed — context already loaded):
plugin/fragments/communication.md, "Stop on unexpected results")Output format:
**Deviation Identified:**
- Message: [turn number or timestamp if available]
- Observed: [what the agent actually did]
- Expected: [what the rule required]
- Violated rule: [rule name] (`[file path]`, section "[section name]")
- Rule text: "[quoted directive]"
Analyze why the deviation occurred:
Proximal cause: What directly caused the deviation?
Contributing factors: What made the deviation plausible?
Rule gap analysis:
Consult references: See references/patterns.md for common deviation patterns and diagnostic heuristics.
Based on RCA findings, classify the structural root cause:
| Classification | Meaning | Fix Approach | |---|---|---| | Directive conflict | Competing signals; agent follows the wrong one | Resolve the conflict — remove, reconcile, or separate competing signals | | Unanchored gate | Decision point lacks tool-call anchor | Add Read/Bash anchor per D+B hybrid (implementation-notes.md) | | Missing enforcement | Rule exists but nothing prevents violation | Environmental enforcement: hook, script, or structural constraint with guidance | | Insufficient context | Relevant decisions not loaded at decision point | Add recall loading or context embedding before the decision | | Input fix | Upstream document (design/plan) is incorrect | Handoff to fix upstream first | | Rule gap | Rule is genuinely missing or ambiguous | Create or clarify rule — only after ruling out structural fixes above | | Systemic | Pattern recurs across sessions | Combine structural fix with memory index entry |
Multiple classifications possible. Example: Well-specified brief.md creates execution pressure (directive conflict) at an unanchored triage gate (unanchored gate) where prior identical instance wasn't loaded (insufficient context). Address all layers.
Anti-pattern: Language strengthening. Adding "no exceptions," "MUST," or scenario-specific warnings to rules the agent already saw and rationalized past. If the rule was clear and the agent overrode it, clarity was not the problem — the environment allowed the override. Fix the environment, not the prose. Language strengthening is never the correct fix for behavioral deviation.
edify _recall resolve "when <trigger>" ... — resolve entries matching (a) the deviation's pattern class and (b) design patterns for the artifact type being modified. Read memory-index.md first if triggers not known from context.
Read the primary target file(s) identified for fixes — verify current state matches RCA assumptions. Read agents/learnings.md for line count.
Present diagnostic summary:
STOP. Do not proceed to Phase 5 without explicit user direction. The diagnostic is the deliverable of Phases 1-4; fixes are a separate decision.
User options:
/recall for broader coverageAfter user confirms at diagnostic checkpoint, choose exit path based on context budget and fix scope:
When:
Actions:
agents/learnings.md (anti-pattern / correct pattern / rationale format)When:
Actions:
plans/reflect-rca-<slug>/rca.md where slug describes deviation
orchestrator-dirty-tree, tool-misuse-grep)agents/learnings.mdagents/session.md in task format:
- [ ] **Task Name** — \command` | model | restart?`| restart)git rev-parse --git-dir (.git = main, otherwise worktree).RCA report template: See references/rca-template.md for structure
When:
Actions:
agents/learnings.md if pattern identifiedagents/session.md in task format:
| restart)- [ ] **Task Name** — \command` | model | restart?`git rev-parse --git-dir (.git = main, otherwise worktree).Always produced:
agents/learnings.md (anti-pattern / correct pattern / rationale)Produced when fixing in-session (Exit Path 1):
Produced when deferring fixes (Exit Path 2):
plans/reflect-rca-<slug>/rca.mdreflect-rca-orchestrator-dirty-tree)Never produced:
/codify (consolidates learnings), /hookify (creates enforcement hooks)references/patterns.md — Common deviation patterns, diagnostic heuristics, rationalization anti-patternsreferences/rca-template.md — Structured template for RCA reports (Exit Path 2)references/rca-design-decisions.md — Key design decisions (session-local, opus expected, framing mandatory, diagnostic-before-fixes, three exit paths)references/rca-examples.md — Worked examples for each exit path (unanchored gate, upstream input error, systemic pattern)development
Verify a Python function against its intended behavior by writing an icontract contract and checking it with `edify check` (CrossHair), repairing in a loop. Triggers on "formalize", "verify this function", "add a contract and check it", or after writing a function whose correctness matters. The in-context agent holds intent and asks the user when behavior is ambiguous; CrossHair owns the deduction.
tools
Manage git worktrees for parallel task execution. Triggers on "create a worktree", "set up parallel work", "merge a worktree", "branch off a task", or uses the `wt`, `wt merge`, or `wt-rm` shortcuts. Worktree lifecycle: creation, focused sessions, merge ceremony, cleanup, parallel task setup.
testing
Recall behavioral knowledge from project decisions. Triggers on "when to do X", situational patterns, or decision content for recognized situations. Invoke with "/when <trigger>".
tools
Sync edify fragments and portable justfile to match the current plugin version. Detects user-edited files and warns instead of overwriting. Use --force to overwrite conflicts.