ai-factory.evolve

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Evolve - Skill Self-Improvement

Evolve - 技能自我提升

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
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
.ai-factory/DESCRIPTION.md
to understand:
  • Tech stack
  • Architecture
  • Conventions
读取
.ai-factory/DESCRIPTION.md
以了解:
  • 技术栈
  • 架构
  • 约定规范

Step 1: Collect Intelligence

步骤1:收集情报

1.1: Read all patches
Glob: .ai-factory/patches/*.md
Read 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
    ,
    ruff.toml
    , etc.)
  • 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
    $ARGUMENTS
    contains a specific skill name → evolve only that skill
  • If
    $ARGUMENTS
    is "all" or empty → evolve all installed skills
Read each target skill's SKILL.md:
Glob: {{skills_dir}}/*/SKILL.md
If skills are not installed yet (no
{{skills_dir}}/
), read from source:
Glob: skills/*/SKILL.md
确定要进化的技能:
  • 如果
    $ARGUMENTS
    包含特定技能名称 → 仅进化该技能
  • 如果
    $ARGUMENTS
    为 "all" 或为空 → 进化所有已安装的技能
读取每个目标技能的SKILL.md:
Glob: {{skills_dir}}/*/SKILL.md
如果技能尚未安装(无
{{skills_dir}}/
),则从源目录读取:
Glob: skills/*/SKILL.md

Step 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
    /ai-factory.fix
    mention the most common error categories from patches? If not → add them
  • Does
    /ai-factory.implement
    warn about the pitfalls found in patches? If not → add guards
  • Does
    /ai-factory.task
    include logging/validation requirements for problem areas? If not → enhance
  • Does
    /ai-factory.review
    check for the patterns that caused bugs? If not → add checklist items
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:补丁驱动的差距
对比补丁模式与技能说明:
  • /ai-factory.fix
    是否提及补丁中最常见的错误类别?如果没有 → 添加相关内容
  • /ai-factory.implement
    是否针对补丁中发现的陷阱发出警告?如果没有 → 添加防护规则
  • /ai-factory.task
    是否包含针对问题领域的日志/验证要求?如果没有 → 增强相关内容
  • /ai-factory.review
    是否检查导致bug的模式?如果没有 → 添加检查清单项
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
undefined

Improvement: [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
undefined
5.1:向用户展示改进方案
undefined

Skill Evolution Report

技能进化报告

Based on:
  • X patches analyzed
  • Y recurring patterns found
  • Z tech-stack specific insights
基于:
  • 分析了X个补丁
  • 发现Y个重复模式
  • Z个技术栈特定洞察

Proposed Improvements

拟议改进

/ai-factory.fix

/ai-factory.fix

  1. Add null-check guard — 5 patches involved null references → Add to Step 2: "Check for optional/nullable fields before accessing nested properties"
  2. Add async/await pattern — 3 patches involved unhandled promises → Add to Important Rules: "Always use try/catch with async/await"
  1. 添加空值检查防护 — 5个补丁涉及空引用 → 添加到步骤2:"在访问嵌套属性前检查可选/可空字段"
  2. 添加async/await模式 — 3个补丁涉及未处理的Promise → 添加到重要规则:"始终将async/await与try/catch配合使用"

/ai-factory.implement

/ai-factory.implement

  1. Add Prisma-specific warning — 2 patches from incorrect Prisma queries → Add to Logging: "Log all Prisma queries in DEBUG mode"
  1. 添加Prisma特定警告 — 2个补丁来自不正确的Prisma查询 → 添加到日志记录:"在DEBUG模式下记录所有Prisma查询"

/ai-factory.review

/ai-factory.review

  1. 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/evolutions
markdown
undefined
  1. 添加检查清单项 — 未检查可选链 → 添加到正确性检查:"可空关联的可选链使用"
是否应用这些改进?
  • 是,全部应用
  • 让我选择要应用的项
  • 否,仅保存报告

**5.2:应用已批准的改进**

针对每个已批准的改进:
1. 读取目标SKILL.md
2. 使用`Edit`应用修改
3. 保持修改最小化且精准

**5.3:保存进化日志**

创建 `.ai-factory/evolutions/YYYY-MM-DD-HH.mm.md`:

```bash
mkdir -p .ai-factory/evolutions
markdown
undefined

Evolution: 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
  • [模式]:出现[频次]次
  • [模式]:出现[频次]次
undefined

Step 6: Suggest Next Actions

步骤6:建议后续操作

undefined
undefined

Evolution Complete

进化完成

Skills improved: X Improvements applied: Y
已改进技能数量:X 已应用改进数量:Y

Recommendations

建议

  1. Run
    /ai-factory.review
    on recent code to verify improvements
  2. Next evolution — run
    /ai-factory.evolve
    again after 5-10 more fixes
  3. Consider new skill — if pattern X keeps recurring, create a dedicated skill:
    /ai-factory.skill-generator <skill-name>
undefined
  1. 运行
    /ai-factory.review
    检查近期代码,验证改进效果
  2. 下次进化 — 在完成5-10次更多修复后,再次运行
    /ai-factory.evolve
  3. 考虑新增技能 — 如果模式X持续出现,创建专用技能:
    /ai-factory.skill-generator <skill-name>
undefined

Context 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
读取所有补丁和技能后,上下文占用较大。所有改进已保存 — 建议释放空间:
AskUserQuestion: 在继续之前释放上下文空间?

选项:
1. /clear — 完全重置(推荐)
2. /compact — 压缩历史记录
3. 保持当前状态继续

What Each Skill Can Learn

各技能可学习内容

SkillLearns FromExample Enhancement
/ai-factory.fix
Patches → common errors"Check for X before accessing Y"
/ai-factory.implement
Patches → prevention rules"When creating models, always validate Z"
/ai-factory.task
Patches → logging gaps"Add validation task for nullable fields"
/ai-factory.review
Patches → missed issues"Check: are all optional relations null-safe?"
/ai-factory.commit
Codebase → conventions"Use project's commit prefix format"
/ai-factory.feature
Codebase → patterns"Default branch prefix based on project convention"
技能学习来源示例改进
/ai-factory.fix
补丁 → 常见错误"在访问Y之前检查X"
/ai-factory.implement
补丁 → 预防规则"创建模型时,始终验证Z"
/ai-factory.task
补丁 → 日志缺口"添加可空字段的验证任务"
/ai-factory.review
补丁 → 遗漏问题"检查:所有可选关联是否都做了空值安全处理?"
/ai-factory.commit
代码库 → 约定规范"使用项目的提交前缀格式"
/ai-factory.feature
代码库 → 模式"基于项目约定的默认分支前缀"

Important Rules

重要规则

  1. Traceable — every improvement must link to a patch, convention, or tech fact
  2. Minimal — add rules, don't rewrite skills
  3. Reversible — user approves before changes are applied
  4. Cumulative — each evolution builds on previous ones
  5. No hallucination — only suggest improvements backed by evidence
  6. Preserve structure — don't change skill workflow, only enrich it
  1. 可追溯 — 每项改进必须关联到补丁、约定规范或技术事实
  2. 最小化 — 添加规则,不要重写技能
  3. 可逆 — 在应用修改前需获得用户批准
  4. 累积性 — 每次进化都基于之前的成果
  5. 无幻觉 — 仅建议有证据支持的改进
  6. 保留结构 — 不要改变技能工作流程,仅丰富内容

Examples

示例

Example 1: After 10 fixes with null-reference patterns

示例1:在10次修复后,空引用模式频繁出现

/ai-factory.evolve fix

→ Found 6/10 patches tagged #null-check
→ Improvement: Add to /ai-factory.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 /ai-factory.review checklist:
  "- [ ] All nullable DB fields have null checks in UI/API layer"
/ai-factory.evolve fix

→ 发现10个补丁中有6个标记为#null-check
→ 改进:添加到/ai-factory.fix步骤2:
  "优先级检查:在访问嵌套属性前,检查可选/可空字段。这是本项目中排名第一的bug来源。"
→ 改进:添加到/ai-factory.review检查清单:
  "- [ ] 所有可空数据库字段在UI/API层都有空值检查"

Example 2: Laravel project with N+1 issues

示例2:存在N+1问题的Laravel项目

/ai-factory.evolve all

→ Stack: Laravel + Eloquent (from DESCRIPTION.md)
→ Found 3 patches tagged #n-plus-one #database
→ Improvement: Add to /ai-factory.implement logging:
  "Enable query logging: DB::enableQueryLog() in DEBUG mode"
→ Improvement: Add to /ai-factory.review checklist:
  "- [ ] Eager loading used for related models (no N+1)"
→ Improvement: Add to /ai-factory.task descriptions:
  "Include 'use ->with() for relations' in DB-related tasks"
/ai-factory.evolve all

→ 技术栈:Laravel + Eloquent(来自DESCRIPTION.md)
→ 发现3个补丁标记为#n-plus-one #database
→ 改进:添加到/ai-factory.implement日志记录:
  "启用查询日志:在DEBUG模式下使用DB::enableQueryLog()"
→ 改进:添加到/ai-factory.review检查清单:
  "- [ ] 关联模型使用了预加载(无N+1问题)"
→ 改进:添加到/ai-factory.task描述:
  "在数据库相关任务中包含'使用->with()处理关联'"

Example 3: First run with no patches

示例3:首次运行,无补丁

/ai-factory.evolve

→ No patches found (first run)
→ Analyzing project context only...
→ Stack: Next.js 14 + Prisma + TypeScript
→ Improvement: Add to /ai-factory.implement:
  "Use server actions for mutations, API routes for external APIs"
→ Improvement: Add to /ai-factory.fix:
  "For Prisma errors, check schema.prisma for field types first"
→ Improvement: Add to /ai-factory.review:
  "- [ ] Server components don't use client-only hooks"
/ai-factory.evolve

→ 未找到补丁(首次运行)
→ 仅分析项目上下文...
→ 技术栈:Next.js 14 + Prisma + TypeScript
→ 改进:添加到/ai-factory.implement:
  "使用Server Actions处理突变,API路由处理外部API"
→ 改进:添加到/ai-factory.fix:
  "对于Prisma错误,首先检查schema.prisma中的字段类型"
→ 改进:添加到/ai-factory.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
    /ai-factory.skill-generator
    instead)
  • Do not apply changes without user approval
  • Do not evolve skills not installed in the project
  • 不要重写整个技能
  • 不要删除现有规则
  • 不要添加通用建议(如"编写整洁代码")
  • 不要创建新技能(建议使用
    /ai-factory.skill-generator
    替代)
  • 不要在未获得用户批准的情况下应用修改
  • 不要进化项目中未安装的技能