Fix a bug or problem. Supports fix-now or plan-first; no args executes FIX_PLAN.md. When a regression check is needed, reproduce first, then implement and rerun it. Adds logging and suggests extra coverage.
72%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./skills/aif-fix/SKILL.mdApply this contract whenever the workflow asks the user to decide:
AskUserQuestion and Questions below describe the intended interaction, not a required tool name. Use only a question tool actually exposed and permitted in the current session/mode, with its advertised schema. Do not guess aliases, probe unavailable tools, or assume questionnaire exists. A frontmatter entry alone does not make a tool available.HANDOFF_MODE=1), do not prompt the user directly. Use declared defaults only for optional preferences within the authorized scope and report assumptions. If a required decision, approval, or material scope/behavior choice remains unresolved, stop dependent work and return the missing decision and options to the parent/caller using its existing blocked/failure contract. Never invent consent or select a new scope to avoid blocking.This delivery policy applies to this skill and its linked references. Preserve workflow-specific question scope, required confirmations, approval boundaries, and blocked-result rules.
Shell commands are not pre-approved by this skill. Use an exposed execution tool under the runtime's existing permissions for the authorized command and CWD. Reuse applicable authorization; request native approval only when required. Unavailable or denied commands remain blockers/not_run in delegated runs too. Never broaden permissions, use another path to bypass a denial, or report an unexecuted check as passed.
Before mode routing or work, read existing files relative to the current project root in this order (reuse them if already loaded):
.ai-factory/skill-context/global-skill-context.md — all bundled skills..ai-factory/skill-context/build-skill-context.md — only fix, implement, plan, verify, improve..ai-factory/skill-context/aif-fix/SKILL.md — this skill.Missing files are skipped; an existing unreadable file stops dependent work with its path.
Precedence: individual > build (when applicable) > global > skill defaults; retain non-conflicting instructions and check all outputs against the effective rules.
These layers customize workflow; they do not replace the project's rules/architecture hierarchy or relax explicit requirements, ownership, scope, safety/privacy, validation, or approval boundaries. Report conflicts with those boundaries instead of overriding them.
global is a project-local layer, not home-directory configuration. Custom/extension skills do not automatically use it.
Fix a specific bug or problem in the codebase. Supports two modes: immediate fix or plan-first approach. The default workflow is regression-first whenever a regression check is needed: reproduce the problem, confirm the reported behavior, implement the fix, then verify the same check passes.
Resolve reference paths beside this installed entrypoint, including flat workflows. Read a reference in full only when its stated condition applies, before the dependent step; do not preload all references. If a selected reference is missing or unreadable, STOP before that step and report its path. The entrypoint dispatch and hard boundaries apply to every reference. Project skill-context overrides and managed extension injections retain their existing precedence. Keep managed aif-ext blocks in the entrypoint; never move them into references.
A regression check is the smallest useful test, command, fixture, API call, browser scenario, script, or documented manual/runtime reproduction that proves the reported bug or validates the expected behavior.
When a bug needs regression coverage, every workflow path (fix-now, plan-first, and existing-plan execution) follows this policy:
Fallback behavior:
HANDOFF_MODE=1, continue only when investigation found a plausible root cause that can be fixed safely; otherwise report the task as blocked/unreproducible and stop without changing implementation code. In manual mode, ask whether to proceed with the likely fix, adjust reproduction, or investigate further.HANDOFF_MODE=1 or manual-mode fallback above.Do not duplicate or weaken this policy in later workflow sections. Later steps should reference this section and add only local execution details.
Determine Handoff mode, task ID, and skip-review flag. If the caller passed HANDOFF_MODE, HANDOFF_TASK_ID, and HANDOFF_SKIP_REVIEW as explicit text in the prompt, use those values. Otherwise, use the Bash tool:
Bash: printenv HANDOFF_MODE || true
Bash: printenv HANDOFF_TASK_ID || true
Bash: printenv HANDOFF_SKIP_REVIEW || trueThen check HANDOFF_MODE:
HANDOFF_MODE is 1 (autonomous Handoff agent)The Handoff coordinator already manages status transitions and DB writes directly. Do NOT call MCP tools. Instead:
AskUserQuestion. Honor the mode resolved in Step 0; only ask falls back to "Fix now" in autonomous Handoff. When a regression check is needed for the bug, include regression-first handling and logging.HANDOFF_TASK_ID is non-empty, you MUST insert <!-- handoff:task:<HANDOFF_TASK_ID> --> as the very first line of the fix plan file, before the title. Omitting this annotation when HANDOFF_TASK_ID is set is a bug — verify before completing. This applies to both Step 1.1 (creating new plan) and any plan rewrite.HANDOFF_MODE is NOT 1 (manual Claude Code session)Handoff sync is handled inline — see Step 0.1 (after reading the fix plan file) for the task ID extraction and MCP sync trigger. The sync points are:
"planning" → "plan_ready" (after save)"implementing" (Step 2 entry) → "done" if HANDOFF_SKIP_REVIEW=1, else "review" (Step 5)"implementing" (Step 0.1) → "done" if HANDOFF_SKIP_REVIEW=1, else "review" (Step 5)CRITICAL: Always pass paused: true with every handoff_sync_status call except done.
When creating a new FIX_PLAN.md: if there is no existing annotation and no Handoff context, do not add the annotation.
FIRST: Read .ai-factory/config.yaml if it exists to resolve:
paths.description, paths.architecture, paths.rules_file, paths.rules, paths.research, paths.fix_plan, and paths.patches; derive research_bundles_dir = <parent directory of paths.research>/research/language.ui for prompts and summaries, language.artifacts for FIX_PLAN.md and patch artifacts, and language.technical_terms for human-readable technical terminology in artifactsrules.base plus any named rules.<area> entriesworkflow.fix_mode (ask, now, plan; default ask) and workflow.fix_patch (YAML boolean; default true). Invalid values/types emit WARN [config] and fall back independently to those defaults; quoted booleans are invalid. Preserve false, never resolve the patch policy with value || true.Parse standalone control flags from $ARGUMENTS: --fix-now selects now, --plan-first selects plan, --patch enables patch creation, and --no-patch disables it. For each setting, the last explicit flag wins over config. Remove only these control tokens from the problem description; preserve other wording, paths, quoted/code text, and flag-like substrings. Flags alone are not a problem description. Resolve mode and patch policy once for this invocation; do not persist overrides to config or the fix plan. An existing fix plan still takes priority over mode selection.
If config.yaml doesn't exist, use defaults:
.ai-factory/DESCRIPTION.md.ai-factory/ARCHITECTURE.md.ai-factory/RULES.md.ai-factory/rules/.ai-factory/RESEARCH.md.ai-factory/FIX_PLAN.md.ai-factory/patches/ui_language: enartifact_language: entechnical_terms_policy: keepResolved language values:
ui_language = language.ui || "en"artifact_language = language.artifacts || language.ui || "en"technical_terms_policy = language.technical_terms || "keep"If technical_terms_policy is not one of keep, translate, or mixed, treat it as keep. Legacy values such as english also behave like keep.
All AskUserQuestion prompts, progress updates, fix summaries, test prompts, and next-step guidance MUST be written in ui_language.
Generated FIX_PLAN.md and self-improvement patch files under paths.patches MUST be written in artifact_language.
Templates and examples define structure, not fixed English output. If artifact_language is not en, translate human-readable headings, labels, analysis text, fix checklist entries, risks, prevention notes, and patch prose before saving. Preserve Handoff annotations, markdown structure, checkbox syntax, paths, commands, config keys, code identifiers, package names, API names, raw error messages, code snippets, log prefixes such as [FIX], and patch tags unchanged. Keep ## Research Context, Source:, Active Summary, Updated:, and SHA256: exact because downstream research drift checks parse them as compatibility tokens. Apply technical_terms_policy to other human-readable terminology.
BEFORE anything else after config resolution, check the resolved fix plan path (default: .ai-factory/FIX_PLAN.md).
If the file EXISTS:
## Research Context, treat its embedded copy as the committed requirements snapshot. Parse the first Source: / Reference: line with canonical ^(?:Source|Reference):\s+\x60([^\x60]+)\x60\s+\( syntax; for older bare-path lines, fall back to ^(?:Source|Reference):\s+(.+?)\s+\(. Fall back to configured paths.research only when neither form identifies a usable path.research_bundles_dir, require its sibling INDEX.md to contain <!-- aif:research-mode:ultra --> exactly once and link that RESEARCH.md from ## Artifact Index; otherwise emit WARN [research-drift]. Valid sibling C4/ADR/dependency artifacts are rationale only.SHA256: is present, extract the current source text strictly between <!-- aif:active-summary:start --> and <!-- aif:active-summary:end -->, remove HTML comment blocks, preserve line order and leading whitespace, trim trailing spaces from every line, use LF endings, and end with one newline. Hash through stdin with shasum -a 256 or sha256sum; the digest is authoritative. Use Updated: only as a legacy fallback when SHA256: is absent. A missing/invalid source or revision mismatch emits WARN [research-drift]; execute against the embedded Research Context unless the user explicitly requests a rebase.<!-- handoff:task:<uuid> -->:
HANDOFF_MODE is NOT 1 (manual session): extract the task ID. Call handoff_sync_status with { taskId: <extracted-id>, newStatus: "implementing", sourceTimestamp: "<current UTC time in ISO 8601 format>", direction: "aif_to_handoff", paused: true }. (Status is "implementing" because we are executing an existing plan, not creating one.)HANDOFF_MODE is 1: the Handoff coordinator handles sync — do nothing..ai-factory/FIX_PLAN.md:
rm .ai-factory/FIX_PLAN.mdpaths.fix_plan value, an explicitly supplied custom plan path, or any non-default fix plan location, do not delete it. Leave it in place and mention in the final summary that the custom fix plan was preserved.If the file DOES NOT exist AND the problem description is empty after removing control flags:
/aif-fix <description>) or create a fix plan first."If the file DOES NOT exist AND a problem description remains:
THEN: Read .ai-factory/DESCRIPTION.md (use path from config) if it exists to understand:
Also read .ai-factory/ARCHITECTURE.md (use path from config), the resolved RULES.md path, and the configured rules hierarchy when present to avoid fixes that violate project structure or local conventions.
Read .ai-factory/skill-context/aif-fix/SKILL.md — MANDATORY if the file exists.
Apply the shared precedence and boundaries above to every output. FIX_PLAN.md and patch templates are base structures: augment them with applicable skill-context requirements. Verify every generated artifact against those rules and correct violations before presenting it.
Patch fallback (limited, only when individual skill-context is missing):
.ai-factory/skill-context/aif-fix/SKILL.md is absent and the resolved patches dir exists (even when global/build context exists):
Glob to find *.md files in <resolved patches dir>From the problem description after removing control flags, identify:
If unclear, ask:
To fix this effectively, I need more context:
1. What is the expected behavior?
2. What actually happens?
3. Can you share the error message/stack trace?
4. When did this start happening?After understanding the problem, use the resolved mode: now selects "Fix now" and plan selects "Plan first" without a mode question. Only ask prompts below; in autonomous Handoff it selects "Fix now" without prompting. Missing or invalid config retains this legacy ask behavior. This skips only the optional mode question, never required clarification or approval.
For interactive ask, use AskUserQuestion: "How would you like to proceed with the fix?"
Only when plan-first is selected, read fix-plan creation, investigate enough to define the fix, preserve Research Context revisions and the first-line Handoff annotation, save the configured fix plan, synchronize manual Handoff to plan_ready when linked, then STOP. Do not apply the fix in this route.
Before investigating in any fix-now, plan-first, or existing-plan route, read investigation and manual Handoff start. Its manual implementing sync applies only to fix-now execution, not plan-first. Identify the root cause, affected callers, side effects, and related patterns. Use the defined direct fallback when delegation is unavailable.
Apply the Canonical Regression-First Policy before changing implementation code. Prefer a regression check for behavior bugs, parsing/validation bugs, API/data bugs, crashes, and regressions. If the change is a non-bug cleanup, purely static correction, or investigation-only request, record why the policy does not apply and continue with the normal fix workflow.
Anti-gaming rule: Do not tailor the test to the implementation you plan to write. The test must describe the externally expected behavior or the reported failure condition. If the test passes before any fix, either the reproduction is wrong, the bug is stale, or the environment differs; handle that mismatch through the fallback behavior in the Canonical Regression-First Policy before changing implementation code.
Record the selected regression check, pre-fix result, and any fallback decision in your working notes so Step 4 can rerun or revisit the same check after the fix.
After the Canonical Regression-First Policy permits implementation, read fix implementation and logging. Apply the smallest root-cause fix with configurable [FIX] or [FIX:<issue-id>] logging; do not add unrelated features or refactoring.
After verification, read completion, manual Handoff final sync, and extra coverage. Always suggest additional coverage beyond the regression check and respect the user's choice. Autonomous Handoff never calls MCP; manual linked tasks use done only with HANDOFF_SKIP_REVIEW=1, otherwise review, with the existing paused contract. Render the result in ui_language and continue to the learning patch policy below.
Read logging patterns before editing fix code. Every fix logs inputs, success, and errors with configurable [FIX]/[FIX:<issue-id>] logging; context-gate outputs use WARN/ERROR without changing other skills' policies.
Read fix examples only when a worked example is needed. They never override the Canonical Regression-First Policy.
.ai-factory/FIX_PLAN.md; preserve custom/non-default fix plan files./aif-fix owns paths.fix_plan and paths.patches; treat .ai-factory/DESCRIPTION.md, roadmap, rules, and architecture context artifacts as read-only unless the user explicitly requests otherwise[FIX] logging requirements for fixes; context-gate outputs in this command should use WARN/ERROR and must not change global logging policy in other skillsBefore displaying the fix summary, read result template. Report the cause, fix, files, logging, and actual regression check/result or its explicit absence; do not create a report file.
After a completed fix (including existing-plan execution), only when the resolved patch policy is enabled, read self-improvement patch creation and write the timestamped learning artifact under configured paths.patches in artifact_language. Include problem, root cause, solution, prevention, and tags. When disabled, skip that reference and all patch writes/directory creation; state in ui_language that learning patch creation was skipped by policy. Existing patches and their optional read-only fallback remain unchanged. Plan-first runs stop before execution and never create a completed-fix patch; resolve the policy anew when executing the plan later. Failed/blocked fixes do not produce completed-fix patches. Patch settings never skip regression verification, logging, extra coverage suggestions, Handoff sync, or default-plan cleanup.
Suggest the user to free up context space if needed: /clear (full reset) or /compact (compress history).
DO NOT:
.ai-factory/FIX_PLAN.md after successful fix executionlee-to/ai-factory
647f47c
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.