skills/aif-evolve/SKILL.md
Self-improve AI Factory skills based on project context, accumulated patches, and codebase patterns. Analyzes what went wrong, what works, and enhances skills to prevent future issues. Use when you want to make AI smarter for your project.
npx skillsauth add lee-to/ai-factory aif-evolveInstall 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.
Analyze project context, patches, and codebase to improve existing skills. Makes AI Factory smarter with every run.
patches (past mistakes) + project context + codebase patterns
↓
analyze recurring problems, tech-specific pitfalls, project conventions
↓
enhance skills with project-specific rules, guards, and patterns
Use a two-layer learning model:
paths.patches, default: .ai-factory/patches/*.md) are the source material..ai-factory/skill-context/*) are the compact, reusable output.Policy across workflow skills:
/aif-evolve is the primary raw-patch analyzer. It processes patches incrementally using a cursor./aif-implement, /aif-fix, and /aif-improve should prefer skill-context first; raw patches are fallback context only.NEVER modify any files inside built-in aif-* skill directories (skills/aif-*/).
All files in these directories are owned by ai-factory and will be overwritten on update — any direct edits will be lost.
ALWAYS write project-specific rules to skill-context:
.ai-factory/skill-context/<skill-name>/SKILL.md
This is the ONLY correct target for built-in skill improvements. No exceptions.
Normalize skill name from $ARGUMENTS:
| User input | Resolved skill name |
|--------------------|---------------------|
| plan | aif-plan |
| aif-plan | aif-plan |
| /aif-plan | aif-plan |
| my-custom-skill | my-custom-skill |
Rule: first, strip any leading / from the argument. Then: if the argument does not start with aif- AND a skill named aif-<argument> exists — use aif-<argument>. Otherwise use as-is.
After resolving the skill name: verify that the resolved skill actually exists
(check {{skills_dir}}/<resolved-name>/SKILL.md or skills/<resolved-name>/SKILL.md).
If the skill is not found → report an error to the user and stop:
"Skill '<resolved-name>' not found. Use /aif-evolve without arguments to evolve
all skills, or specify a valid skill name."
Determine which skills to evolve from $ARGUMENTS:
$ARGUMENTS contains a specific skill name → evolve only that skill$ARGUMENTS is "all" or empty → evolve all installed skillsFIRST: Read .ai-factory/config.yaml if it exists to resolve:
paths.description, paths.architecture, paths.rules_file, paths.rules, paths.patches, and paths.evolutionslanguage.ui for prompts and language.artifacts for generated reportsrules.base plus any named rules.<area> entriesIf config.yaml doesn't exist, use defaults:
.ai-factory/DESCRIPTION.md.ai-factory/ARCHITECTURE.md.ai-factory/RULES.md.ai-factory/rules/.ai-factory/patches/.ai-factory/evolutions/en (English)Note: .ai-factory/skill-context/ remains a fixed internal AI Factory path in the current schema. Patch and evolution-log locations are configurable via paths.patches and paths.evolutions.
THEN: Read .ai-factory/DESCRIPTION.md (use path from config) to understand:
Also read .ai-factory/ARCHITECTURE.md (use path from config) and the configured rules hierarchy when present. This context informs convention analysis and gap detection but does not change artifact ownership.
Read skill-context files for target skills:
/aif-evolve plan) → read only:
.ai-factory/skill-context/aif-plan/SKILL.md (target skill's context).ai-factory/skill-context/aif-evolve/SKILL.md (evolve's own context, if exists
and target skill is not aif-evolve itself)/aif-evolve or /aif-evolve all) → read all context files:
Glob: .ai-factory/skill-context/*/SKILL.md (this already includes evolve's own context — do NOT read it separately)These contain previously accumulated project-specific rules for built-in skills. Keep them in memory — they affect gap analysis in Step 5.
Skill-context rules are project-level overrides — when they conflict with the base SKILL.md of the target skill, skill-context wins (same principle as nested CLAUDE.md files).
How to apply evolve's own skill-context rules (aif-evolve):
Enforcement: After generating any output artifact, verify it against all skill-context rules. If any rule is violated — fix the output before presenting it to the user.
1.1: Read patches incrementally (cursor-based)
Glob: <resolved patches dir>/*.md
Cursor file:
<resolved evolutions dir>/patch-cursor.json
Recommended shape:
{
"last_processed_patch": "YYYY-MM-DD-HH.mm.md",
"updated_at": "YYYY-MM-DD HH:mm"
}
Processing rules:
> last_processed_patch.WARN [evolve] and do a full rescan.WARN [evolve] for historical drift only when a reliable baseline exists and drift is actually detected.<resolved evolutions dir>/patch-cursor.json, then run /aif-evolve again.Overlap window (anti-miss guard):
LLMs may miss prevention points on a single pass. To reduce the chance of "permanently skipping" a patch when running incrementally:
> last_processed_patchRead every patch. For each one, extract:
Build a Prevention Point Registry — a flat list of ALL extracted prevention points across the processed patch set in this run. This registry is the primary input for Step 5 gap analysis.
| # | Patch | Prevention Point (specific action) | Target Skill(s) |
|---|-------|------------------------------------|-----------------|
| 1 | <patch-file> | <concrete action to enforce> | <skill-1> |
| 2 | <patch-file> | <different action from same patch> | <skill-1>, <skill-2> |
| 3 | <other-patch> | <action> | <skill-3> |
CRITICAL: A patch with 5 prevention points produces 5 rows, not 1. If a prevention point targets 2 skills, it appears once but with both skills listed — and EACH skill must be checked independently in Step 5.
When the run is incremental, this registry reflects the processed patch set for this run (new + overlap). Use full rescan when you need full historical backfill.
1.2: Aggregate patterns
Group patches by tags and categories. Identify:
1.3: Read codebase conventions
Scan the project for patterns:
.eslintrc, phpstan.neon, ruff.toml, etc.)When evolving a specific skill, focus convention scanning on areas relevant to that skill
(e.g., for /aif-plan — focus on file structure and naming; for /aif-fix — error handling and testing).
Read ONLY the base SKILL.md files for target skills — not all skills.
/aif-evolve plan) → read only that one:
Read: {{skills_dir}}/aif-plan/SKILL.md (or skills/aif-plan/SKILL.md if not installed)/aif-evolve or /aif-evolve all) → read all:
Glob: {{skills_dir}}/*/SKILL.md (or Glob: skills/*/SKILL.md if not installed)Keep loaded SKILL.md content in memory — Step 3 needs it for comparison (do NOT re-read).
When: Run this step for every target aif-* skill that has a skill-context file.
For each rule in .ai-factory/skill-context/<skill-name>/SKILL.md:
Scope constraint: Step 3 can ONLY modify or remove skill-context files.
It must NEVER propose editing, deleting, or reverting base skills/aif-*/ files.
Even if the base file contains errors or incomplete rules — that is outside evolve's scope.
Use the base SKILL.md already loaded in Step 2 (do NOT re-read the file).
Compare each skill-context rule against the base SKILL.md content:
Case A — Base fully covers skill-context rule (equivalent or superset): The base SKILL.md now contains a rule that is equivalent to or MORE complete than the skill-context rule. This includes:
Case B — Contradicting rule found in base SKILL.md: The base skill now has a rule that directly contradicts the skill-context rule. → Do NOT auto-remove. Do NOT ask the user yet. → Collect this conflict for the report in Step 4 — include both rules and mark as "Conflict — user decision required".
Case C — Partial overlap (in either direction): The base SKILL.md and skill-context rule overlap, but NEITHER fully covers the other. This includes:
Case D — No overlap: The rule is still unique to the project context. → Keep as-is, no action needed.
Skip this step if no Case A/B/C rules were found in Step 3.
Present all stale rule findings using the stale rules report format (Case A/B/C sections with base vs skill-context comparison).
IMPORTANT: All decisions here affect ONLY skill-context files.
Never propose editing, deleting, or reverting base skills/aif-*/ files —
they are outside of evolve's scope.
For each stale rule, present:
Use AskUserQuestion to collect stale rule decisions. Process in batches
of up to 3 decisions per AskUserQuestion call:
AskUserQuestionAskUserQuestionDo NOT proceed to Step 5 until all stale rule decisions are collected and applied. This determines the actual skill-context state for gap analysis.
Before analyzing gaps: re-read skill-context files for target skills that were modified in Step 4 (stale rule removals/rewrites). Do NOT use the version loaded in Step 0.2 — it is outdated after Step 4 changes.
For each skill, consider the base SKILL.md AND its current skill-context file (after stale rule decisions from Step 4 have been applied). A gap only exists if NEITHER source covers it.
For each skill, identify what's missing based on collected intelligence:
5.1: Patch-driven gaps (prevention-point-exhaustive)
CRITICAL: Check each prevention point × each target skill independently.
Iterate over the Prevention Point Registry built in Step 1.1. For each row:
Common trap — Source reference ≠ full coverage:
Finding Source: <patch-filename> in a skill-context rule means ONE rule was derived
from that patch. It does NOT mean ALL prevention points from that patch are covered.
A patch with 5 prevention points may have only 1 covered. Always verify the content
of the existing rule against each prevention point individually.
Verification: After completing the registry scan, count: total prevention points, covered, uncovered. If uncovered > 0 — these are gaps for Step 6.
Note: in incremental mode, counts represent this run's processed patch set. For full historical recount, run a full rescan.
5.2: Tech-stack gaps
Compare project tech stack against skill instructions:
5.3: Convention gaps
Compare project conventions against skill instructions:
For each gap found, create a concrete improvement:
Quality rules for improvements:
7.1: Present improvements to user
Each improvement MUST explicitly state the target file path. Use the following target labels:
skill-context → .ai-factory/skill-context/<skill-name>/SKILL.mdSKILL.md → direct edit of the skill's own SKILL.md (only for custom/non-aif skills)templates/, checklists/),
specify the exact relative path within the skill directoryFormat:
## Skill Evolution Report
Based on:
- X patches analyzed
- Y recurring patterns found
- Z tech-stack specific insights
### Proposed Improvements
#### /aif-fix (N rules)
**Target:** `.ai-factory/skill-context/aif-fix/SKILL.md`
1. **Add null-check guard**
- **Source:** patch-2026-02-10.md, patch-2026-02-12.md (5 patches involved null references)
- **Why:** Recurring null-reference errors on optional DB relations
- **Rule:** "Check for optional/nullable fields before accessing nested properties"
2. **Add async/await pattern**
- **Source:** patch-2026-02-11.md (3 patches involved unhandled promises)
- **Why:** Unhandled promise rejections in API layer
- **Rule:** "Always use try/catch with async/await"
#### /aif-implement (N rules)
**Target:** `.ai-factory/skill-context/aif-implement/SKILL.md`
1. **Add Prisma-specific warning**
- **Source:** patch-2026-02-13.md (2 patches from incorrect Prisma queries)
- **Why:** Silent data loss from wrong Prisma query methods
- **Rule:** "Log all Prisma queries in DEBUG mode"
#### /my-custom-skill (N rules)
**Target:** `skills/my-custom-skill/SKILL.md` (direct edit — custom skill)
1. **Add pattern**
- **Source:** codebase convention
- **Why:** Missing guard in Step 2
- **Rule:** "..."
After presenting the full report, use AskUserQuestion to collect decisions:
For improvements — ask:
Based on choice:
AskUserQuestion call (same approach as Step 4 stale rules). For each
improvement, options: Apply / Skip. Continue until all improvements are resolved.
Then proceed to 7.2 with only approved improvements.Do NOT apply any changes until the user answers.
7.2: Apply approved improvements
For each approved improvement, determine the target:
If the skill is a built-in aif-* skill (its SKILL.md is inside the package skills/ directory):
.ai-factory/skill-context/<skill-name>/SKILL.md doesn't exist — create it with the header template> Last updated: and > Based on: lines in the headerskills/aif-*/ directory — all files there are owned by ai-factory and WILL be overwritten on update. All improvements go to skill-context only.rm .ai-factory/skill-context/<skill-name>/SKILL.md
rmdir .ai-factory/skill-context/<skill-name> (only if empty)> Based on: count and > Last updated: in skill-context files that were
only affected by stale rule removals (Step 4) but did NOT receive new improvements
(those were already updated in item 4).If the skill is a custom/project skill (not aif-*):
SKILL.md directly (existing behavior, unchanged)Context file template:
IMPORTANT: All skill-context files MUST be written in English, regardless of the user's language or the language used in patches/RULES.md. Skill-context rules are consumed by AI agents — English ensures consistent interpretation across all skills and sessions.
# Project Rules for /<skill-name>
> Auto-generated by `/aif-evolve`. Do not edit manually.
> Last updated: YYYY-MM-DD HH:mm
> Based on: N analyzed patches
## Rules
### [Rule Name]
**Source**: [patch filenames or "codebase convention"]
**Rule**: [Specific, actionable instruction in English]
7.3: Save evolution log
Create <resolved evolutions dir>/YYYY-MM-DD-HH.mm.md:
mkdir -p <resolved evolutions dir>
After saving the evolution log, update cursor state:
Definitions:
> last_processed_patch.
Cursor update rules:
# Evolution: YYYY-MM-DD HH:mm
## Intelligence Summary
- Patches analyzed: X
- Recurring patterns: [list]
- Tech stack: [from DESCRIPTION.md]
## Improvements Applied
### [skill-name] → skill-context
- [change description] ← driven by patches: [patch filenames]
**File:** `.ai-factory/skill-context/[skill-name]/SKILL.md`
### [skill-name] → SKILL.md (custom skill)
- [change description] ← driven by: [tech stack / convention]
**File:** `skills/[skill-name]/SKILL.md`
## Patterns Identified
- [pattern]: [frequency] occurrences
- [pattern]: [frequency] occurrences
## Evolution Complete
Skills improved: X
Improvements applied: Y
### Recommendations
1. **Run `/aif-review`** on recent code to verify improvements
2. **Next evolution** — run `/aif-evolve` again after 5-10 more fixes
3. **Consider new skill** — if pattern X keeps recurring, create a dedicated skill:
`/aif-skill-generator <skill-name>`
.ai-factory/skill-context/*, <resolved evolutions dir>/*.md, and <resolved evolutions dir>/patch-cursor.json.config.yaml resolves description, rules, patches, and evolution-log paths, but skill-context remains a fixed AI Factory internal path.After completing evolution, suggest /clear or /compact — context is heavy after patch analysis and skill processing.
aif-* skills go to .ai-factory/skill-context/, never to skills/aif-*/. NEVER edit any files inside skills/aif-*/ — they are overwritten on update. No exceptions./aif-skill-generator instead<resolved evolutions dir>/*.md, <resolved evolutions dir>/patch-cursor.json, and .ai-factory/skill-context/*; treat roadmap/rules/research/plan artifacts as read-only context unless explicitly asked/aif-evolve fix
→ Found 6/10 patches tagged #null-check
→ Improvement for /aif-fix (2 rules):
Target: .ai-factory/skill-context/aif-fix/SKILL.md
1. "PRIORITY CHECK: Look for optional/nullable fields accessed
without null guards. This is the #1 source of bugs in this project."
2. "When fixing nullable relation errors, check ALL usages of that
relation in the same file — same bug often repeats nearby."
data-ai
Archive completed plans and roadmap milestones. Moves finished plans to the archive directory and optionally trims closed milestones from ROADMAP.md. Use when user says "archive plans", "clean up plans", "archive completed", or "trim roadmap".
tools
Set up agent context for a project. Analyzes tech stack, installs relevant skills from skills.sh, generates custom skills, and configures MCP servers. Use when starting new project, setting up AI context, or asking "set up project", "configure AI", "what skills do I need".
development
Verify completed implementation against the plan. Checks that all tasks were fully implemented, nothing was forgotten, code compiles, tests pass, and quality standards are met. Use after "/aif-implement" completes, or when user says "verify", "check work", "did we miss anything".
data-ai
Plan implementation for a feature or task. Two modes — fast (single quick plan) or full (richer plan with optional git branch/worktree flow). Use when user says "plan", "new feature", "start feature", "create tasks".