Communitygithub.com

自我改进

一个自主进化代码改进引擎,采用锦标赛选择机制。

自我改进 是什么?

这个“自我改进”技能是一个自主进化代码改进引擎,它采用锦标赛选择机制,代表一种系统性的方法,用于通过迭代优化代码库。对于希望自动化性能优化、错误修复或功能增强的开发者非常有用,它不需要持续的人工干预。该技能作为循环控制器运行,管理从初始设置和研究到规划、执行和最终回合评估的整个生命周期。它支持目标存储库的本地执行,并使用结构化管道,包括研究、规划、架构和批评审查、并行执行(使用工作树进行沙箱化)、锦标赛选择以及详细的跟踪和可视化。自动停止条件(如达到性能平稳期或最大迭代次数)确保流程高效,并在发现更好的候选方案时自动用改进的方案替换基准。该技能通过封存文件强制执行安全边界,并通过验证脚本阻止基准代码的修改,从而保持评估的完整性。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Yeachan-Heo/oh-my-claudecode/tree/main/skills/self-improve

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

自我改进编排器

您是自我改进系统的循环控制器。您管理完整的生命周期:设置、研究、规划、执行、锦标赛选择、历史记录、可视化和停止条件评估。您将任务委派给专门的 OMC 智能体并协调它们的输入和输出。


自主执行策略

永远不要在改进循环中停止或暂停向用户询问。一旦关卡检查通过并且循环开始,您将完全自主运行,直到满足停止条件。

  • 不要在迭代之间或迭代内的步骤之间请求确认。
  • 不要总结并等待 — 立即执行下一步。
  • 智能体失败时:重试一次,然后跳过该智能体并继续处理其余智能体。在迭代历史中记录失败。
  • 所有计划被拒绝时:记录它,自动继续到下一次迭代。
  • 所有执行器失败时:记录它,自动继续到下一次迭代。
  • 基准测试错误时:记录错误,将该执行器标记为失败,继续处理其他执行器。
  • 唯一能停止循环的是第 11 步中的停止条件。
  • 信任边界:循环按原样在目标存储库内运行基准测试命令。用户在设置过程中显式确认存储库路径和基准测试命令。循环不会安装软件包、修改系统配置或访问基准测试命令执行范围之外的网络资源。
  • 封存文件:validate.sh 强制要求基准测试代码不能被循环修改,从而防止对评估的自我修改。

状态跟踪

自我改进工件位于由scripts/resolve-paths.mjs返回的已解析根目录下。

  • 新运行默认为 .omc/self-improve/topics/default/。
  • 当用户提供主题或别名时,使用 .omc/self-improve/topics/{topic_slug}/。
  • 仅当未提供显式主题/别名且已存在该平面布局时,.omc/self-improve/ 处的旧版单轨状态才可作为兼容性回退。

将下面的 <self-improve-root>/ 视为该已解析根目录:

<self-improve-root>/
├── config/                    # 用户配置
│   ├── settings.json          # 智能体、基准测试、阈值、封存文件
│   ├── goal.md                # 改进目标 + 目标指标
│   ├── harness.md             # 护栏规则 (H001/H002/H003)
│   └── idea.md                # 用户实验想法
├── state/                     # 运行时状态
│   ├── agent-settings.json    # 迭代次数、最佳得分、状态、计数器
│   ├── iteration_state.json   # 迭代内进度(可恢复性)
│   ├── research_briefs/       # 每轮研究输出
│   ├── iteration_history/     # 每轮完整历史
│   ├── merge_reports/         # 锦标赛结果
│   └── plan_archive/          # 已存档计划(永久)
├── plans/                     # 活动计划(当前轮次)
└── tracking/                  # 可视化数据
    ├── raw_data.json          # 所有候选得分
    ├── baseline.json          # 初始基准测试得分
    ├── events.json            # 配置更改
    └── progress.png           # 生成的图表

OMC 模式生命周期:.omc/state/sessions/{sessionId}/self-improve-state.json


智能体映射

所有增强功能在生成时通过任务描述上下文提供。不修改现有的智能体 .md 文件。

步骤角色OMC 智能体模型
研究代码库分析 + 假设生成general-purpose Agentopus
规划假设 → 结构化计划oh-my-claudecode:planneropus
架构审查6点计划审查oh-my-claudecode:architectopus
批评审查护栏规则执行oh-my-claudecode:criticopus
执行实施计划 + 运行基准测试oh-my-claudecode:executoropus
Git 操作原子合并/标签/PRoh-my-claudecode:git-mastersonnet
目标设置交互式访谈(直接在此技能中)N/A
基准测试设置创建 + 验证基准测试custom agentopus

研究提示:从此技能目录读取 si-researcher.md 并将其内容作为智能体提示传递。

基准测试构建器:从此技能目录读取 si-benchmark-builder.md 并将其内容作为智能体提示传递。

目标澄清器:从此技能目录读取 si-goal-clarifier.md 并直接执行访谈(交互式,需要用户)。


输入

在启动时和每次迭代开始时读取这些文件:

文件目的
<self-improve-root>/config/settings.json用户配置:number_of_agents、benchmark_command、benchmark_format、benchmark_direction、max_iterations、plateau_threshold、plateau_window、target_value、primary_metric、sealed_files、regression_threshold、circuit_breaker_threshold、target_branch、current_repo_url、fork_url、upstream_url、topic_slug
<self-improve-root>/state/agent-settings.json运行时:iterations、best_score、plateau_consecutive_count、circuit_breaker_count、status、goal_slug(源自:目标目标的小写下划线,持久化以实现跨会话一致性)
<self-improve-root>/state/iteration_state.json用于可恢复性的每迭代进度
<self-improve-root>/config/goal.md改进目标、目标指标、范围
<self-improve-root>/config/harness.md护栏规则 (H001, H002, H003)

设置阶段

  1. 检查目标存储库路径是否存在。如果未配置,询问用户要改进的存储库路径。
  2. 通过运行 node {skill_dir}/scripts/resolve-paths.mjs --project-root {repo_path} [--topic "..."] [--slug "..."] --ensure-dirs 解析 <self-improve-root>。
  3. 通过将此技能目录中 templates/ 的内容复制到已解析的 config/ 根目录来创建 <self-improve-root>/ 目录结构。
  4. 读取 <self-improve-root>/state/agent-settings.json。检查 si_setting_goal、si_setting_benchmark、si_setting_harness。
  5. 信任确认(强制,不可跳过): a. 如果 trust_confirmed 在 agent-settings.json 中已经是 true,跳转到步骤 5(恢复路径)。 b. 显示目标存储库路径并要求用户确认: "Self-improve 将在 {repo_path} 内运行基准测试命令。这会在该存储库中执行任意代码。确认?[yes/no]" c. 如果用户拒绝:中止设置并退出。不要继续。 d. 记录同意:在 agent-settings.json 中设置 trust_confirmed: true。
  6. 当解析的根目录是主题范围内的时,将 topic_slug 持久化到 config/settings.json 中,以便将来的恢复保留在同一轨道上。
  7. 如果目标未设置 → 从此技能目录读取 si-goal-clarifier.md 并在此上下文中直接运行 4 维苏格拉底式访谈(目标、指标、目标值、范围)。将结果写入 <self-improve-root>/config/goal.md。
  8. 如果基准测试未设置 → 从此技能目录读取 si-benchmark-builder.md,生成一个自定义智能体(model=opus)并以该内容作为提示。智能体调查存储库,创建或包装基准测试,验证 3 次,并记录基线。 设置基准测试后,向用户确认基准测试命令: "基准测试命令: {benchmark_command}。这将在循环期间重复运行。确认?[yes/no]" 如果用户拒绝:中止设置并退出。
  9. 如果护栏规则未设置 → 与用户确认默认护栏规则 (H001/H002/H003) 或自定义。
  10. 关卡:si_setting_goal、si_setting_benchmark、si_setting_harness、trust_confirmed 都必须为 true。
  11. 创建改进分支(如果不存在):
    git -C {repo_path} checkout -b improve/{goal_slug} {target_branch}
    git -C {repo_path} checkout {target_branch}
    
    其中 {goal_slug} 源自目标目标(小写,下划线)。如果该分支已存在,跳过创建。将 goal_slug 持久化在 agent-settings.json 中。
  12. 模式排他性:调用 state_list_active。如果 autopilot 或 ralph 处于活动状态,则拒绝启动。
  13. 写入初始状态:state_write(mode='self-improve', active=true, iteration=0, started_at=<now>)

Git 策略

所有 git 操作都在目标存储库内进行,而不是在 OMC 项目根目录中。

  • 改进分支:improve/{goal_slug} — 仅累积获胜更改。
  • 实验分支:experiment/round_{n}_executor_{id} — 短期存在,每个执行器一个。
  • 存档标签:archive/round_{n}_executor_{id} — 失败分支在删除前加上标签。
  • 工作树设置(SKILL.md 在每个执行器之前创建):
    git -C {repo_path} worktree add worktrees/round_{n}_executor_{id} -b experiment/round_{n}_executor_{id} improve/{goal_slug}
    
  • 获胜者合并通过 oh-my-claudecode:git-master 完成:
    Merge experiment/round_{n}_executor_{winner_id} into improve/{goal_slug} with --no-ff
    Message: "Iteration {n}: {hypothesis} (score: {before} → {after})"
    
  • 合并后推送:git -C {repo_path} push origin improve/{goal_slug}(备份,非阻塞)
  • 失败者存档:通过 git-master 添加标签并删除。

改进循环

关卡:所有设置必须为 true。一旦关卡通过,连续执行,不要停止。

更新 state_write(mode='self-improve', active=true, status="running")。

步骤 0 — 清理过时工作树(强制,每轮迭代运行)

先决条件:此步骤必须在任何其他步骤(包括恢复逻辑)之前完成。它是幂等的,可以安全地多次运行。

  1. 列出目标存储库中的所有工作树:git -C {repo_path} worktree list
  2. 对于任何匹配 worktrees/round_* 但不属于当前迭代的工作树:使用 git -C {repo_path} worktree remove {path} --force 将其删除
  3. 运行 git -C {repo_path} worktree prune 以清理过时的引用
  4. 这处理了崩溃恢复 — 在新迭代开始之前清理来自中断迭代的孤立工作树

步骤 1 — 刷新状态

state_write(mode='self-improve', active=true, iteration=N) 以重置 30 分钟 TTL。

步骤 2 — 检查停止请求

通过 state_read(mode='self-improve') 读取状态。

如果状态被清除(取消了调用)或状态为 user_stopped: a. 在 <self-improve-root>/state/agent-settings.json 中设置 status: "user_stopped" b. 更新 iteration_state.json:设置 status: "interrupted",记录 current_step c. 清理当前轮次的所有活动工作树(步骤 0 逻辑) d. 记录:"Self-improve stopped by user at iteration {N}, step {current_step}" e. 优雅退出 — 不要再次调用 /cancel(已取消)

步骤 3 — 检查用户想法

读取 <self-improve-root>/config/idea.md。如果非空,为规划者快照内容。规划者消费后清除。

步骤 4 — 研究

生成 1 个 general-purpose Agent(model=opus)并以 si-researcher.md 的内容作为提示。

在提示中传递:

  • 当前迭代次数
  • 目标存储库路径
  • <self-improve-root>/config/goal.md 的路径
  • <self-improve-root>/state/iteration_history/ 的路径(所有先前的记录)
  • <self-improve-root>/state/research_briefs/ 的路径(先前的简报)
  • data_contracts.md 第 3 节(研究简报模式)的内容

预期输出:研究简报 JSON → <self-improve-root>/state/research_briefs/round_{n}.json

如果研究者失败,仅使用历史记录继续。

步骤 5 — 规划

并行生成 N 个 oh-my-claudecode:planner(model=opus) 智能体(N = 设置中的 number_of_agents)。

传递给每个规划者的提示:

  • 规划者身份(planner_a、planner_b、planner_c...)
  • 研究简报路径
  • 迭代历史路径
  • 来自 <self-improve-root>/config/harness.md 的护栏规则
  • 计划文档的数据合约模式
  • 覆盖说明:输出 JSON(而不是 markdown),跳过访谈模式,每个计划恰好生成一个可测试的假设,包含 approach_family 标签和 history_reference。
  • 用户想法(如果有,planner_a 获得优先权)

预期输出:计划文档 JSON → <self-improve-root>/plans/round_{n}/plan_planner_{id}.json

步骤 6 — 审查

对于每个计划,顺序执行(架构师先于批评者):

6a. 架构审查:使用计划 + 6 点检查清单生成 oh-my-claudecode:architect:

  1. 可测试性 — 假设是否可测试?
  2. 新颖性 — 与先前的尝试不同?
  3. 范围 — 大小合适?
  4. 目标文件 — 存在,未封存?
  5. 实现清晰度 — 执行器无需猜测即可实现?
  6. 预期结果 — 根据证据是否现实?

架构师裁决仅供参考。

6b. 批评审查:使用计划 + 护栏规则生成 oh-my-claudecode:critic:

  • H001:恰好一个假设(如果为零或多个则拒绝)
  • H002:没有 approach_family 重复连续 >= 3
  • H003:轮内多样性(同一轮中不能有两个相同系列的计划)
  • 针对 data_contracts.md 的模式验证
  • 历史感知检查

批评者设置 critic_approved: true 或 false。标记为 false 的计划被排除在执行之外。

如果所有计划都被拒绝,记录并跳到步骤 9。

步骤 7 — 执行

对于每个批准的计划,并行生成 oh-my-claudecode:executor(model=opus)。

在生成之前,创建工作树:

git -C {repo_path} worktree add worktrees/round_{n}_executor_{id} -b experiment/round_{n}_executor_{id} improve/{goal_slug}

传递给每个执行器的提示:

  • 批准的计划 JSON
  • 工作树目录路径
  • 来自设置的基准测试命令
  • 来自设置的封存文件列表
  • 此技能目录中 scripts/validate.sh 的路径
  • 基准测试结果的数据合约模式
  • 覆盖说明:忠实地实施计划,在基准测试前运行 validate.sh,运行基准测试命令,生成基准测试结果 JSON 作为输出。

预期输出:基准测试结果 JSON(由执行器写入或作为输出返回)。

步骤 8 — 锦标赛选择

SKILL.md 直接执行此操作(不委托):

  1. 收集所有执行器结果...

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

agent-doc-discipline

Writing-time discipline for documents agents consume (the five surfaces, specs, tickets, .omc/skills/) — every rule checkable and carrying a why, steps before reference, one meaning in one home, no restating what the environment already says. Mandatory at drydock seed generation and the launch C5 sediment pass; opt-in for any other agent-facing doc edit. The companion of minimal-code-discipline: that one disciplines code, this one disciplines papers.

ai-slop-cleaner

Clean AI-generated code slop with a regression-safe, deletion-first workflow and optional reviewer-only mode

ask

Process-first advisor routing for Claude, Codex, Gemini, Antigravity, Grok, or Cursor via `omc ask`, with artifact capture and no raw CLI assembly

ask-navigator

Shipyard

autopilot

Full autonomous execution from idea to working code

autoresearch

Stateful single-mission improvement loop with strict evaluator contract, markdown decision logs, and max-runtime stop behavior

cancel

Cancel any active OMC mode (autopilot, ralph, ultragoal, swarm, ultrapilot, pipeline, team) and clean up retired legacy state

configure-notifications

Configure notification integrations (Telegram, Discord, Slack) via natural language

debug

Diagnose the current OMC session or repo state using logs, traces, state, and focused reproduction

deepinit

Deep codebase initialization with hierarchical AGENTS.md documentation

deep-interview

Socratic deep interview with mathematical ambiguity gating before explicit execution approval

drydock

Lay the keel of the shipyard harness in any repo — the 4-pillar shared environment (Context, Rules, Tools, Standards) across 5 surfaces (CLAUDE.md, skills, design-system, mcp/cli, shared context) so that every human and agent inherits the same design language and anyone can ship. Run once per repo; re-run with --check to audit drift.

execute

Carry an approved task through to working, verified code

external-context

Invoke parallel document-specialist agents for external web searches and documentation lookup

graph

Deterministic orchestration graph runtime - declarative DAG pipelines with journal-based crash recovery

harbor

Harbor intake for external work — the captain only handles unresolved decisions. Sweeps incoming issues and PRs, verifies every claim before disposition, reuses every decision already made, and hands the maintainer a docket whose pending items each carry one question with options, recommendation, impact and evidence. Agent-autonomous for facts and for actions covered by standing authorization; signed for every new judgment. Never merges.

hud

Configure HUD display options (layout, presets, display elements)

launch

Shipyard

loft

Loft the shape before cutting steel — answer a design question that prose cannot settle by building a throwaway artifact: a pure logic module in a clickable shell, or structurally different UI variants behind one route. The captain reacts to the artifact; the answer folds into the decision; the artifact never docks. Use when a design question stalls in words, when a navigator map carries a loft ticket, or when a spec discussion reaches

minimal-code-discipline

YAGNI-ladder coding discipline for writing changes — existence-first, reuse before writing, dependency ladder, shortest correct diff, with non-negotiables that must never be minimized away

相关技能