aif-evolve
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEvolve - Skill Self-Improvement
演进 - 技能自我提升
Analyze project context, patches, and codebase to improve existing skills. Makes AI Factory smarter with every run.
分析项目上下文、补丁和代码库以改进现有技能。每次运行都能让AI Factory变得更智能。
Core Idea
核心思路
patches (past mistakes) + project context + codebase patterns
↓
analyze recurring problems, tech-specific pitfalls, project conventions
↓
enhance skills with project-specific rules, guards, and patterns补丁(过往错误) + 项目上下文 + 代码库模式
↓
分析重复出现的问题、技术特定陷阱、项目约定
↓
通过项目特定规则、防护机制和模式强化技能Workflow
工作流程
Step 0: Load Context
步骤0:加载上下文
Read to understand:
.ai-factory/DESCRIPTION.md- Tech stack
- Architecture
- Conventions
读取文件以了解:
.ai-factory/DESCRIPTION.md- 技术栈
- 架构
- 约定
Step 1: Collect Intelligence
步骤1:收集情报
1.1: Read all patches
Glob: .ai-factory/patches/*.mdRead every patch. For each one, extract:
- Problem category (null-check, async, validation, types, API, DB, etc.)
- Root cause pattern (what class of mistake was made)
- Prevention rule (what should be done differently)
- Tags
1.2: Aggregate patterns
Group patches by tags and categories. Identify:
- Recurring problems — same tag appears 3+ times? This is a systemic issue
- Tech-specific pitfalls — problems tied to the stack (e.g., React re-renders, Laravel N+1)
- Missing guards — what checks/patterns could have prevented these bugs
1.3: Read codebase conventions
Scan the project for patterns:
- Linter configs (,
.eslintrc,phpstan.neon, etc.)ruff.toml - Existing test patterns (test file structure, assertions used)
- Error handling patterns (try/catch style, error types)
- Logging patterns (logger used, format, levels)
- Import conventions, file structure
1.1:读取所有补丁
Glob: .ai-factory/patches/*.md读取每个补丁,并为每个补丁提取:
- 问题类别(空值检查、异步处理、验证、类型、API、数据库等)
- 根因模式(属于哪类错误)
- 预防规则(应该如何改进)
- 标签
1.2:聚合模式
按标签和类别对补丁进行分组,识别:
- 重复出现的问题——同一标签出现3次以上?这是系统性问题
- 技术特定陷阱——与技术栈相关的问题(例如React重渲染、Laravel N+1查询)
- 缺失的防护机制——哪些检查/模式本可以预防这些bug
1.3:读取代码库约定
扫描项目以识别模式:
- 代码检查器配置(、
.eslintrc、phpstan.neon等)ruff.toml - 现有测试模式(测试文件结构、使用的断言方式)
- 错误处理模式(try/catch风格、错误类型)
- 日志记录模式(使用的日志工具、格式、级别)
- 导入约定、文件结构
Step 2: Read Current Skills
步骤2:读取当前技能
Determine which skills to evolve:
- If contains a specific skill name → evolve only that skill
$ARGUMENTS - If is "all" or empty → evolve all installed skills
$ARGUMENTS
Read each target skill's SKILL.md:
Glob: {{skills_dir}}/*/SKILL.mdIf skills are not installed yet (no ), read from source:
{{skills_dir}}/Glob: skills/*/SKILL.md确定要演进的技能:
- 如果包含特定技能名称 → 仅演进该技能
$ARGUMENTS - 如果为"all"或为空 → 演进所有已安装技能
$ARGUMENTS
读取每个目标技能的SKILL.md文件:
Glob: {{skills_dir}}/*/SKILL.md如果技能尚未安装(无目录),则从源目录读取:
{{skills_dir}}/Glob: skills/*/SKILL.mdStep 3: Analyze Gaps
步骤3:分析差距
For each skill, identify what's missing based on collected intelligence:
3.1: Patch-driven gaps
Compare patch patterns against skill instructions:
- Does mention the most common error categories from patches? If not → add them
/aif-fix - Does warn about the pitfalls found in patches? If not → add guards
/aif-implement - Does include logging/validation requirements for problem areas? If not → enhance
/aif-plan - Does check for the patterns that caused bugs? If not → add checklist items
/aif-review
3.2: Tech-stack gaps
Compare project tech stack against skill instructions:
- Skills reference generic patterns but project uses specific framework? → Add framework-specific guidance
- Project uses TypeScript but skills show JS examples? → Update examples
- Project uses specific ORM (Prisma, Eloquent)? → Add ORM-specific patterns
3.3: Convention gaps
Compare project conventions against skill instructions:
- Project has specific error handling pattern? → Skills should enforce it
- Project uses specific logger? → Skills should reference it
- Project has specific file structure? → Skills should follow it
针对每个技能,基于收集到的情报识别缺失内容:
3.1:补丁驱动的差距
将补丁模式与技能说明进行对比:
- 是否提及补丁中最常见的错误类别?如果没有 → 添加
/aif-fix - 是否对补丁中发现的陷阱发出警告?如果没有 → 添加防护机制
/aif-implement - 是否包含问题领域的日志/验证要求?如果没有 → 强化
/aif-plan - 是否检查导致bug的模式?如果没有 → 添加检查清单项
/aif-review
3.2:技术栈差距
将项目技术栈与技能说明进行对比:
- 技能引用通用模式但项目使用特定框架? → 添加框架特定指导
- 项目使用TypeScript但技能示例为JS? → 更新示例
- 项目使用特定ORM(Prisma、Eloquent)? → 添加ORM特定模式
3.3:约定差距
将项目约定与技能说明进行对比:
- 项目有特定错误处理模式? → 技能应强制执行该模式
- 项目使用特定日志工具? → 技能应引用该工具
- 项目有特定文件结构? → 技能应遵循该结构
Step 4: Generate Improvements
步骤4:生成改进方案
For each gap found, create a concrete improvement:
markdown
undefined针对每个发现的差距,创建具体的改进方案:
markdown
undefinedImprovement: [skill-name]
改进方案:[技能名称]
What
内容
[Specific change to make]
[具体修改内容]
Why
原因
[Which patches/patterns drove this change]
[驱动此修改的补丁/模式]
Where
位置
[Exact section in SKILL.md to modify]
[SKILL.md中要修改的具体章节]
Change
修改
[The actual text to add/modify]
**Quality rules for improvements:**
- Each improvement must be traceable to a patch, convention, or tech-stack fact
- No generic advice — only project-specific enhancements
- Improvements must be minimal and focused — don't rewrite entire skills
- Preserve existing skill structure — add, don't replace[要添加/修改的实际文本]
**改进方案的质量规则:**
- 每个改进方案必须可追溯到补丁、约定或技术栈事实
- 不提供通用建议——仅针对项目的特定增强
- 改进方案必须最小化且聚焦——不要重写整个技能
- 保留现有技能结构——仅添加内容,不替换Step 5: Present & Apply
步骤5:展示并应用改进
5.1: Present improvements to user
undefined5.1:向用户展示改进方案
undefinedSkill Evolution Report
技能演进报告
Based on:
- X patches analyzed
- Y recurring patterns found
- Z tech-stack specific insights
基于以下内容生成:
- 分析了X个补丁
- 发现Y个重复模式
- Z个技术栈特定见解
Proposed Improvements
拟议改进方案
/aif-fix
/aif-fix
-
Add null-check guard — 5 patches involved null references → Add to Step 2: "Check for optional/nullable fields before accessing nested properties"
-
Add async/await pattern — 3 patches involved unhandled promises → Add to Important Rules: "Always use try/catch with async/await"
-
添加空值检查防护 —— 6个补丁涉及空引用问题 → 添加至步骤2:"在访问嵌套属性前检查可选/可为空字段"
-
添加async/await模式 —— 3个补丁涉及未处理的Promise → 添加至重要规则:"始终对async/await使用try/catch"
/aif-implement
/aif-implement
- Add Prisma-specific warning — 2 patches from incorrect Prisma queries → Add to Logging: "Log all Prisma queries in DEBUG mode"
- 添加Prisma特定警告 —— 2个补丁来自错误的Prisma查询 → 添加至日志记录:"在DEBUG模式下记录所有Prisma查询"
/aif-review
/aif-review
- Add checklist item — optional chaining not checked → Add to Correctness: "Optional chaining for nullable relations"
Apply these improvements?
- Yes, apply all
- Let me pick which ones
- No, just save the report
**5.2: Apply approved improvements**
For each approved improvement:
1. Read the target SKILL.md
2. Apply the change using `Edit`
3. Keep changes minimal and surgical
**5.3: Save evolution log**
Create `.ai-factory/evolutions/YYYY-MM-DD-HH.mm.md`:
```bash
mkdir -p .ai-factory/evolutionsmarkdown
undefined- 添加检查清单项 —— 未检查可选链式调用 → 添加至正确性检查:"可为空关联的可选链式调用"
是否应用这些改进?
- 是,全部应用
- 让我选择要应用的项
- 否,仅保存报告
**5.2:应用已批准的改进方案**
针对每个已批准的改进方案:
1. 读取目标SKILL.md文件
2. 使用`Edit`功能应用修改
3. 保持修改最小化且精准
**5.3:保存演进日志**
创建`.ai-factory/evolutions/YYYY-MM-DD-HH.mm.md`文件:
```bash
mkdir -p .ai-factory/evolutionsmarkdown
undefinedEvolution: YYYY-MM-DD HH:mm
演进记录:YYYY-MM-DD HH:mm
Intelligence Summary
情报摘要
- Patches analyzed: X
- Recurring patterns: [list]
- Tech stack: [from DESCRIPTION.md]
- 分析的补丁数量:X
- 重复模式:[列表]
- 技术栈:[来自DESCRIPTION.md]
Improvements Applied
已应用的改进方案
[skill-name]
[技能名称]
- [change description] ← driven by patches: [patch filenames]
- [修改描述] ← 驱动来源:[补丁文件名]
[skill-name]
[技能名称]
- [change description] ← driven by: [tech stack / convention]
- [修改描述] ← 驱动来源:[技术栈 / 约定]
Patterns Identified
识别的模式
- [pattern]: [frequency] occurrences
- [pattern]: [frequency] occurrences
undefined- [模式]:出现[频次]次
- [模式]:出现[频次]次
undefinedStep 6: Suggest Next Actions
步骤6:建议后续操作
undefinedundefinedEvolution Complete
演进完成
Skills improved: X
Improvements applied: Y
已改进技能数量:X
已应用改进方案数量:Y
Recommendations
建议
- Run on recent code to verify improvements
/aif-review - Next evolution — run again after 5-10 more fixes
/aif-evolve - Consider new skill — if pattern X keeps recurring, create a dedicated skill:
/aif-skill-generator <skill-name>
undefined- **运行**检查近期代码以验证改进效果
/aif-review - 下一次演进 —— 在完成5-10次修复后再次运行
/aif-evolve - 考虑新增技能 —— 如果模式X持续出现,创建专用技能:
/aif-skill-generator <技能名称>
undefinedContext Cleanup
上下文清理
Context is heavy after reading all patches and skills. All improvements are saved — suggest freeing space:
AskUserQuestion: Free up context before continuing?
Options:
1. /clear — Full reset (recommended)
2. /compact — Compress history
3. Continue as is读取所有补丁和技能后上下文会占用较多资源。所有改进方案已保存——建议释放空间:
向用户提问:继续之前是否释放上下文?
选项:
1. /clear —— 完全重置(推荐)
2. /compact —— 压缩历史记录
3. 保持当前状态继续What Each Skill Can Learn
各技能可学习的内容
| Skill | Learns From | Example Enhancement |
|---|---|---|
| Patches → common errors | "Check for X before accessing Y" |
| Patches → prevention rules | "When creating models, always validate Z" |
| Patches → logging gaps | "Add validation task for nullable fields" |
| Patches → missed issues | "Check: are all optional relations null-safe?" |
| Codebase → conventions | "Use project's commit prefix format" |
| 技能 | 学习来源 | 示例改进 |
|---|---|---|
| 补丁 → 常见错误 | "在访问Y之前检查X" |
| 补丁 → 预防规则 | "创建模型时,始终验证Z" |
| 补丁 → 日志缺口 | "添加可为空字段的验证任务" |
| 补丁 → 遗漏问题 | "检查:所有可选关联是否都做了空值安全处理?" |
| 代码库 → 约定 | "使用项目的提交前缀格式" |
Important Rules
重要规则
- Traceable — every improvement must link to a patch, convention, or tech fact
- Minimal — add rules, don't rewrite skills
- Reversible — user approves before changes are applied
- Cumulative — each evolution builds on previous ones
- No hallucination — only suggest improvements backed by evidence
- Preserve structure — don't change skill workflow, only enrich it
- 可追溯 —— 每个改进方案必须关联到补丁、约定或技术事实
- 最小化 —— 添加规则,不要重写技能
- 可撤销 —— 应用修改前需获得用户批准
- 累积性 —— 每次演进都基于之前的成果
- 无幻觉 —— 仅建议有证据支持的改进
- 保留结构 —— 不要更改技能工作流程,仅丰富内容
Examples
示例
Example 1: After 10 fixes with null-reference patterns
示例1:10次修复后出现空引用模式
/aif-evolve fix
→ Found 6/10 patches tagged #null-check
→ Improvement: Add to /aif-fix Step 2:
"PRIORITY CHECK: Look for optional/nullable fields accessed
without null guards. This is the #1 source of bugs in this project."
→ Improvement: Add to /aif-review checklist:
"- [ ] All nullable DB fields have null checks in UI/API layer"/aif-evolve fix
→ 发现10个补丁中有6个标记为#null-check
→ 改进方案:添加至/aif-fix步骤2:
"优先级检查:查找未做空值防护的可选/可为空字段访问
这是本项目中排名第一的bug来源。"
→ 改进方案:添加至/aif-review检查清单:
"- [ ] 所有可为空的数据库字段在UI/API层都做了空值检查"Example 2: Laravel project with N+1 issues
示例2:存在N+1问题的Laravel项目
/aif-evolve all
→ Stack: Laravel + Eloquent (from DESCRIPTION.md)
→ Found 3 patches tagged #n-plus-one #database
→ Improvement: Add to /aif-implement logging:
"Enable query logging: DB::enableQueryLog() in DEBUG mode"
→ Improvement: Add to /aif-review checklist:
"- [ ] Eager loading used for related models (no N+1)"
→ Improvement: Add to /aif-plan descriptions:
"Include 'use ->with() for relations' in DB-related tasks"/aif-evolve all
→ 技术栈:Laravel + Eloquent(来自DESCRIPTION.md)
→ 发现3个补丁标记为#n-plus-one #database
→ 改进方案:添加至/aif-implement日志记录:
"启用查询日志:在DEBUG模式下使用DB::enableQueryLog()"
→ 改进方案:添加至/aif-review检查清单:
"- [ ] 关联模型使用了预加载(无N+1问题)"
→ 改进方案:添加至/aif-plan描述:
"在数据库相关任务中包含'对关联使用->with()'"Example 3: First run with no patches
示例3:首次运行无补丁
/aif-evolve
→ No patches found (first run)
→ Analyzing project context only...
→ Stack: Next.js 14 + Prisma + TypeScript
→ Improvement: Add to /aif-implement:
"Use server actions for mutations, API routes for external APIs"
→ Improvement: Add to /aif-fix:
"For Prisma errors, check schema.prisma for field types first"
→ Improvement: Add to /aif-review:
"- [ ] Server components don't use client-only hooks"/aif-evolve
→ 未找到补丁(首次运行)
→ 仅分析项目上下文...
→ 技术栈:Next.js 14 + Prisma + TypeScript
→ 改进方案:添加至/aif-implement:
"对突变操作使用服务器动作,对外部API使用API路由"
→ 改进方案:添加至/aif-fix:
"对于Prisma错误,首先检查schema.prisma中的字段类型"
→ 改进方案:添加至/aif-review:
"- [ ] 服务器组件未使用仅客户端钩子"DO NOT:
禁止操作:
- Do not rewrite entire skills
- Do not remove existing rules
- Do not add generic advice ("write clean code")
- Do not create new skills (suggest using instead)
/aif-skill-generator - Do not apply changes without user approval
- Do not evolve skills not installed in the project
- 不要重写整个技能
- 不要删除现有规则
- 不要添加通用建议(如"编写整洁代码")
- 不要创建新技能(建议使用替代)
/aif-skill-generator - 不要在未获得用户批准的情况下应用修改
- 不要演进项目中未安装的技能