evolve
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/evolve — Goal-Driven Compounding Loop
/evolve — 目标驱动的复利式改进循环
Purpose: Measure what's wrong. Fix the worst thing. Measure again. Compound.
Thin fitness-scored loop over . The knowledge flywheel provides compounding — each cycle loads learnings from all prior cycles.
/rpiDormancy is success. When all goals pass and no harvested work remains, the system enters dormancy — a valid, healthy state. The system does not manufacture work to justify its existence. Nothing to do means everything is working.
用途: 找出问题所在,修复最严重的问题,再次测量,实现复利式提升。
基于 的轻量 fitness 评分循环。知识飞轮实现复利式增长——每个循环都会吸收所有先前循环的经验。
/rpi休眠即成功。 当所有目标都达成且没有待处理的任务时,系统会进入休眠状态——这是一种有效且健康的状态。系统不会为了证明自身存在而凭空制造任务。无事可做意味着一切正常运转。
Quick Start
快速开始
bash
/evolve # Run forever until kill switch or stagnation
/evolve --max-cycles=5 # Cap at 5 improvement cycles
/evolve --dry-run # Measure fitness, show what would be worked on, don't executebash
/evolve # 持续运行直到触发终止开关或进入停滞状态
/evolve --max-cycles=5 # 最多运行5个改进循环
/evolve --dry-run # 测量fitness,展示待处理任务,但不执行实际操作Execution Steps
执行步骤
YOU MUST EXECUTE THIS WORKFLOW. Do not just describe it.
你必须执行此工作流,不能仅停留在描述层面。
Step 0: Setup
步骤0:设置
bash
mkdir -p .agents/evolveLoad accumulated learnings (COMPOUNDING):
bash
ao inject 2>/dev/null || trueParse flags:
- (default: unlimited) — optional hard cap. Without this flag, the loop runs forever until kill switch or stagnation.
--max-cycles=N - — measure and report only, no execution
--dry-run - — skip the Step 0.5 baseline sweep
--skip-baseline
Capture session-start SHA (for multi-commit revert):
bash
SESSION_START_SHA=$(git rev-parse HEAD)Initialize state:
evolve_state = {
cycle: 0,
max_cycles: <from flag, or Infinity if not set>,
dry_run: <from flag, default false>,
test_first: <from flag, default false>,
session_start_sha: $SESSION_START_SHA,
idle_streak: 0, # consecutive cycles with nothing to do
max_idle_streak: 3, # stop after this many consecutive idle cycles
history: []
}bash
mkdir -p .agents/evolve加载累积的经验(复利式增长):
bash
ao inject 2>/dev/null || true解析参数:
- (默认:无限制)——可选的循环次数上限。如果不设置此参数,循环会持续运行直到触发终止开关或进入停滞状态。
--max-cycles=N - ——仅测量并报告,不执行实际操作
--dry-run - ——跳过步骤0.5的基准扫描
--skip-baseline
记录会话启动时的SHA(用于多提交回滚):
bash
SESSION_START_SHA=$(git rev-parse HEAD)初始化状态:
evolve_state = {
cycle: 0,
max_cycles: <来自参数,未设置则为Infinity>,
dry_run: <来自参数,默认false>,
test_first: <来自参数,默认false>,
session_start_sha: $SESSION_START_SHA,
idle_streak: 0, # 连续无任务的循环次数
max_idle_streak: 3, # 连续无任务达到此次数后停止
history: []
}Step 0.5: Cycle-0 Baseline Sweep
步骤0.5:循环0基准扫描
Capture a baseline fitness snapshot before the first cycle so every later cycle
has a comparison anchor. Skipped on resume (idempotent).
if [ "$SKIP_BASELINE" = "true" ]; then
log "Skipping baseline sweep (--skip-baseline flag set)"
exit 0
fi
if ! [ -f .agents/evolve/fitness-0-baseline.json ]; then
baseline = MEASURE_FITNESS() # run every GOALS.yaml goal
baseline.cycle = 0
write ".agents/evolve/fitness-0-baseline.json" baseline
# Baseline report
failing = [g for g in baseline.goals if g.result == "fail"]
failing.sort(by=weight, descending)
cat > .agents/evolve/cycle-0-report.md << EOF
# Cycle-0 Baseline
**Total goals:** ${len(baseline.goals)}
**Passing:** ${len(baseline.goals) - len(failing)}
**Failing:** ${len(failing)}
$(for g in failing: "- [weight ${g.weight}] ${g.id}: ${g.result}")
EOF
log "Baseline captured: ${len(failing)}/${len(baseline.goals)} goals failing"
fi在第一个循环前捕获基准fitness快照,以便后续每个循环都有对比基准。恢复运行时会跳过此步骤(幂等操作)。
if [ "$SKIP_BASELINE" = "true" ]; then
log "跳过基准扫描(已设置 --skip-baseline 参数)"
exit 0
fi
if ! [ -f .agents/evolve/fitness-0-baseline.json ]; then
baseline = MEASURE_FITNESS() # 运行GOALS.yaml中的所有目标
baseline.cycle = 0
write ".agents/evolve/fitness-0-baseline.json" baseline
# 基准报告
failing = [g for g in baseline.goals if g.result == "fail"]
failing.sort(by=weight, descending)
cat > .agents/evolve/cycle-0-report.md << EOF
# 循环0基准
**总目标数:** ${len(baseline.goals)}
**已通过:** ${len(baseline.goals) - len(failing)}
**未通过:** ${len(failing)}
$(for g in failing: "- [权重 ${g.weight}] ${g.id}: ${g.result}")
EOF
log "已捕获基准:${len(failing)}/${len(baseline.goals)}个目标未通过"
fiStep 1: Kill Switch Check
步骤1:终止开关检查
Check at the TOP of every cycle iteration:
bash
undefined在每个循环迭代开始时检查:
bash
undefinedExternal kill (outside repo — can't be accidentally deleted by agents)
外部终止开关(仓库外——不会被Agent意外删除)
if [ -f ~/.config/evolve/KILL ]; then
echo "KILL SWITCH ACTIVE: $(cat ~/.config/evolve/KILL)"
Write acknowledgment
echo "{"killed_at": "$(date -Iseconds)", "cycle": $CYCLE}" > .agents/evolve/KILLED.json
exit 0
fi
if [ -f ~/.config/evolve/KILL ]; then
echo "终止开关已激活:$(cat ~/.config/evolve/KILL)"
写入确认信息
echo "{"killed_at": "$(date -Iseconds)", "cycle": $CYCLE}" > .agents/evolve/KILLED.json
exit 0
fi
Local convenience stop
本地临时终止开关
if [ -f .agents/evolve/STOP ]; then
echo "STOP file detected: $(cat .agents/evolve/STOP 2>/dev/null)"
exit 0
fi
If either file exists, log reason and **stop immediately**. Do not proceed to measurement.if [ -f .agents/evolve/STOP ]; then
echo "检测到STOP文件:$(cat .agents/evolve/STOP 2>/dev/null)"
exit 0
fi
如果任一文件存在,记录原因并**立即停止**,不要进入测量步骤。Step 2: Measure Fitness (MEASURE_FITNESS)
步骤2:测量Fitness(MEASURE_FITNESS)
Read from repo root. For each goal:
GOALS.yamlbash
undefined读取仓库根目录下的,针对每个目标:
GOALS.yamlbash
undefinedRun the check command
运行检查命令
if eval "$goal_check" > /dev/null 2>&1; then
Exit code 0 = PASS
result = "pass"
else
Non-zero = FAIL
result = "fail"
fi
Record results with **continuous values** (not just pass/fail):
```bashif eval "$goal_check" > /dev/null 2>&1; then
退出码0 = 通过
result = "pass"
else
非零 = 未通过
result = "fail"
fi
记录包含**连续数值**的结果(不只是通过/未通过):
```bashWrite fitness snapshot
写入fitness快照
cat > .agents/evolve/fitness-${CYCLE}.json << EOF
{
"cycle": $CYCLE,
"timestamp": "$(date -Iseconds)",
"cycle_start_sha": "$(git rev-parse HEAD)",
"goals": [
{"id": "$goal_id", "result": "$result", "weight": $weight, "value": $metric_value, "threshold": $threshold},
...
]
}
EOF
For goals with measurable metrics, extract the continuous value:
- `go-coverage-floor`: parse `go test -cover` output → `"value": 85.7, "threshold": 80`
- `doc-coverage`: count skills with references/ → `"value": 20, "threshold": 16`
- `shellcheck-clean`: count of warnings → `"value": 0, "threshold": 0`
- Other goals: `"value": null` (binary pass/fail only)
**Snapshot enforcement (HARD GATE):** After writing the snapshot, validate it:
```bash
if ! jq empty ".agents/evolve/fitness-${CYCLE}.json" 2>/dev/null; then
echo "ERROR: Fitness snapshot write failed or invalid JSON. Refusing to proceed."
exit 1
fiDo NOT proceed to Step 3 without a valid fitness snapshot.
Bootstrap mode: If a check command fails to execute (command not found, permission denied), mark that goal as with a warning. Do NOT block the entire loop because one check is broken.
"result": "skip"cat > .agents/evolve/fitness-${CYCLE}.json << EOF
{
"cycle": $CYCLE,
"timestamp": "$(date -Iseconds)",
"cycle_start_sha": "$(git rev-parse HEAD)",
"goals": [
{"id": "$goal_id", "result": "$result", "weight": $weight, "value": $metric_value, "threshold": $threshold},
...
]
}
EOF
对于可测量的目标,提取连续数值:
- `go-coverage-floor`:解析`go test -cover`输出 → `"value": 85.7, "threshold": 80`
- `doc-coverage`:统计带引用的技能数量 → `"value": 20, "threshold": 16`
- `shellcheck-clean`:统计警告数量 → `"value": 0, "threshold": 0`
- 其他目标:`"value": null`(仅支持二元通过/未通过)
**快照强制校验(硬性要求):** 写入快照后,验证其有效性:
```bash
if ! jq empty ".agents/evolve/fitness-${CYCLE}.json" 2>/dev/null; then
echo "错误:Fitness快照写入失败或JSON无效。拒绝继续执行。"
exit 1
fi没有有效fitness快照的情况下,不要进入步骤3。
引导模式: 如果检查命令执行失败(命令不存在、权限不足),将该目标标记为并发出警告。不要因为单个检查失败而阻塞整个循环。
"result": "skip"Step 3: Select Work
步骤3:选择任务
failing_goals = [g for g in goals if g.result == "fail"]
if not failing_goals:
# Cycle-0 Comprehensive Sweep (optional full-repo scan)
# Before consuming harvested work, optionally discover items the harvest missed.
# This is because manual sweeps have found issues automated harvests didn't catch.
if ! [ -f .agents/evolve/last-sweep-date ] || \
[ $(date +%s) -gt $(( $(stat -f %m .agents/evolve/last-sweep-date) + 604800 )) ]; then
# Sweep is stale (> 7 days) or missing — run lightweight scan
log "Running cycle-0 comprehensive sweep (stale/missing: .agents/evolve/last-sweep-date)"
# Lightweight sweep: shellcheck, go vet, known anti-patterns
shellcheck hooks/*.sh 2>&1 | grep -v "^$" | while read line; do
add_to_next_work("shellcheck finding: $line", severity="medium", type="bug")
done
go vet ./cli/... 2>&1 | grep -v "^$" | while read line; do
add_to_next_work("go vet finding: $line", severity="medium", type="bug")
done
# grep for known anti-patterns (e.g., hardcoded secrets, TODO markers)
grep -r "TODO|FIXME|XXX" --include="*.go" --include="*.sh" . 2>/dev/null | while read line; do
add_to_next_work("code marker: $line", severity="low", type="tech-debt")
done
# Mark sweep complete
touch .agents/evolve/last-sweep-date
log "Cycle-0 sweep complete. New findings added to next-work.jsonl"
fi
# All goals pass — check harvested work from prior /rpi cycles
if [ -f .agents/rpi/next-work.jsonl ]; then
# Detect current repo for filtering
CURRENT_REPO=$(bd config --get prefix 2>/dev/null \
|| basename "$(git remote get-url origin 2>/dev/null)" .git 2>/dev/null \
|| basename "$(pwd)")
all_items = read_unconsumed(next-work.jsonl) # entries with consumed: false
# Filter by target_repo: include items where target_repo matches
# CURRENT_REPO, target_repo is "*" (cross-repo), or field is absent (backward compat).
# Skip items whose target_repo names a different repo.
items = [i for i in all_items
if i.target_repo in (CURRENT_REPO, "*", None)]
if items:
evolve_state.idle_streak = 0 # reset — we found work
selected_item = max(items, by=severity) # highest severity first
log "All goals met. Picking harvested work: {selected_item.title}"
# Execute as an /rpi cycle (Step 4), then mark consumed
/rpi "{selected_item.title}" --auto --max-cycles=1 --test-first # if --test-first set
/rpi "{selected_item.title}" --auto --max-cycles=1 # otherwise
mark_consumed(selected_item) # set consumed: true, consumed_by, consumed_at
# Skip Steps 4-5 (already executed above), go to Step 6 (log cycle)
log_cycle(cycle, goal_id="next-work:{selected_item.title}", result="harvested")
continue loop # → Step 1 (kill switch check)
# Nothing to do THIS cycle — but don't quit yet
evolve_state.idle_streak += 1
log "All goals met, no harvested work. Idle streak: {idle_streak}/{max_idle_streak}"
if evolve_state.idle_streak >= evolve_state.max_idle_streak:
log "Stagnation: {max_idle_streak} consecutive idle cycles. Nothing left to improve."
STOP → go to Teardown
# NOT stagnant yet — re-measure next cycle (external changes, new harvested work)
log "Re-measuring next cycle in case conditions changed..."
continue loop # → Step 1 (kill switch check)failing_goals = [g for g in goals if g.result == "fail"]
if not failing_goals:
# 循环0全面扫描(可选的全仓库扫描)
# 在处理待处理任务前,可选发现自动扫描遗漏的问题。
# 这是因为手动扫描曾发现过自动扫描遗漏的问题。
if ! [ -f .agents/evolve/last-sweep-date ] || \
[ $(date +%s) -gt $(( $(stat -f %m .agents/evolve/last-sweep-date) + 604800 )) ]; then
# 扫描已过期(超过7天)或未执行过——运行轻量扫描
log "执行循环0全面扫描(扫描过期/未执行:.agents/evolve/last-sweep-date)"
# 轻量扫描:shellcheck、go vet、已知反模式
shellcheck hooks/*.sh 2>&1 | grep -v "^$" | while read line; do
add_to_next_work("shellcheck发现:$line", severity="medium", type="bug")
done
go vet ./cli/... 2>&1 | grep -v "^$" | while read line; do
add_to_next_work("go vet发现:$line", severity="medium", type="bug")
done
# 查找已知反模式(如硬编码密钥、TODO标记)
grep -r "TODO|FIXME|XXX" --include="*.go" --include="*.sh" . 2>/dev/null | while read line; do
add_to_next_work("代码标记:$line", severity="low", type="tech-debt")
done
# 标记扫描完成
touch .agents/evolve/last-sweep-date
log "循环0扫描完成。新发现的问题已添加至next-work.jsonl"
fi
# 所有目标都已达成——检查之前/rpi循环留下的待处理任务
if [ -f .agents/rpi/next-work.jsonl ]; then
# 检测当前仓库用于过滤
CURRENT_REPO=$(bd config --get prefix 2>/dev/null \
|| basename "$(git remote get-url origin 2>/dev/null)" .git 2>/dev/null \
|| basename "$(pwd)")
all_items = read_unconsumed(next-work.jsonl) # 未标记为已处理的条目
# 按目标仓库过滤:包含目标仓库匹配当前仓库、目标仓库为"*"(跨仓库)或无目标仓库字段(向后兼容)的条目。
# 跳过目标仓库与当前仓库不同的条目。
items = [i for i in all_items
if i.target_repo in (CURRENT_REPO, "*", None)]
if items:
evolve_state.idle_streak = 0 # 重置——找到任务
selected_item = max(items, by=severity) # 优先处理最高严重级别的任务
log "所有目标已达成。选择待处理任务:{selected_item.title}"
# 执行一个/rpi循环(步骤4),然后标记为已处理
/rpi "{selected_item.title}" --auto --max-cycles=1 --test-first # 如果已设置--test-first
/rpi "{selected_item.title}" --auto --max-cycles=1 # 否则
mark_consumed(selected_item) # 设置consumed: true,记录consumed_by和consumed_at
# 跳过步骤4-5(已在上面执行),进入步骤6(记录循环)
log_cycle(cycle, goal_id="next-work:{selected_item.title}", result="harvested")
continue loop # → 步骤1(终止开关检查)
# 本次循环无任务可做——但暂时不退出
evolve_state.idle_streak += 1
log "所有目标已达成,无待处理任务。连续无任务次数:{idle_streak}/{max_idle_streak}"
if evolve_state.idle_streak >= evolve_state.max_idle_streak:
log "已停滞:连续{max_idle_streak}次循环无任务。无更多可改进内容。"
STOP → 进入清理步骤
# 尚未完全停滞——下次循环重新测量(可能有外部变化或新的待处理任务)
log "下次循环将重新测量,以防情况变化..."
continue loop # → 步骤1(终止开关检查)We have failing goals — reset idle streak
存在未通过的目标——重置连续无任务次数
evolve_state.idle_streak = 0
evolve_state.idle_streak = 0
Sort by weight (highest priority first)
按权重排序(优先级从高到低)
failing_goals.sort(by=weight, descending)
failing_goals.sort(by=weight, descending)
Simple strike check: skip goals that failed the last 3 consecutive cycles
简单排除检查:跳过连续3次循环未通过的目标
for goal in failing_goals:
recent = last_3_cycles_for(goal.id)
if all(r.result == "regressed" for r in recent):
log "Skipping {goal.id}: regressed 3 consecutive cycles. Needs human attention."
continue
selected = goal
break
if no goal selected:
log "All failing goals have regressed 3+ times. Human intervention needed."
STOP → go to Teardown
undefinedfor goal in failing_goals:
recent = last_3_cycles_for(goal.id)
if all(r.result == "regressed" for r in recent):
log "跳过{goal.id}:连续3次循环未通过。需要人工介入。"
continue
selected = goal
break
if no goal selected:
log "所有未通过目标均连续3次以上未改进。需要人工介入。"
STOP → 进入清理步骤
undefinedStep 4: Execute
步骤4:执行任务
If : Report the selected goal (or harvested item) and stop.
--dry-runlog "Dry run: would work on '{selected.id}' (weight: {selected.weight})"
log "Description: {selected.description}"
log "Check command: {selected.check}"如果是模式: 报告选中的目标(或待处理任务)并停止。
--dry-runlog "Dry Run模式:将处理'{selected.id}'(权重:{selected.weight})"
log "描述:{selected.description}"
log "检查命令:{selected.check}"Also show queued harvested work (filtered to current repo)
同时显示队列中的待处理任务(已过滤当前仓库)
if [ -f .agents/rpi/next-work.jsonl ]; then
all_items = read_unconsumed(next-work.jsonl)
items = [i for i in all_items
if i.target_repo in (CURRENT_REPO, "*", None)]
if items:
log "Harvested work queue ({len(items)} items):"
for item in items:
log " - [{item.severity}] {item.title} ({item.type})"
STOP → go to Teardown
**Otherwise:** Run a full /rpi cycle on the selected goal.
/rpi "Improve {selected.id}: {selected.description}" --auto --max-cycles=1 --test-first # if --test-first set
/rpi "Improve {selected.id}: {selected.description}" --auto --max-cycles=1 # otherwise
This internally runs the full lifecycle:
- `/research` — understand the problem
- `/plan` — decompose into issues
- `/pre-mortem` — validate the plan
- `/crank` — implement (spawns workers)
- `/vibe` — validate the code
- `/post-mortem` — extract learnings + `ao forge` (COMPOUNDING)
**Wait for /rpi to complete before proceeding.**if [ -f .agents/rpi/next-work.jsonl ]; then
all_items = read_unconsumed(next-work.jsonl)
items = [i for i in all_items
if i.target_repo in (CURRENT_REPO, "*", None)]
if items:
log "待处理任务队列({len(items)}个任务):"
for item in items:
log " - [{item.severity}] {item.title} ({item.type})"
STOP → 进入清理步骤
**否则:** 对选中的目标运行完整的/rpi循环。
/rpi "改进{selected.id}:{selected.description}" --auto --max-cycles=1 --test-first # 如果已设置--test-first
/rpi "改进{selected.id}:{selected.description}" --auto --max-cycles=1 # 否则
此命令内部会运行完整生命周期:
- `/research` — 理解问题
- `/plan` — 将问题分解为任务
- `/pre-mortem` — 验证计划
- `/crank` — 实现(生成工作进程)
- `/vibe` — 验证代码
- `/post-mortem` — 提取经验 + `ao forge`(复利式增长)
**等待/rpi完成后再继续执行。**Step 5: Full-Fitness Regression Gate
步骤5:全Fitness回归校验
CRITICAL: Re-run ALL goals, not just the target.
After /rpi completes, re-run MEASURE_FITNESS on every goal (same as Step 2). Write result to .
fitness-{CYCLE}-post.jsonCompare the pre-cycle snapshot () against the post-cycle snapshot () for ALL goals:
fitness-{CYCLE}.jsonfitness-{CYCLE}-post.jsonundefined关键:重新运行所有目标,而不仅仅是目标目标。
/rpi完成后,重新对所有目标运行MEASURE_FITNESS(与步骤2相同)。将结果写入。
fitness-{CYCLE}-post.json对比循环前快照()与循环后快照()的所有目标:
fitness-{CYCLE}.jsonfitness-{CYCLE}-post.jsonundefinedLoad pre-cycle results
加载循环前结果
pre_results = load("fitness-{CYCLE}.json")
pre_results = load("fitness-{CYCLE}.json")
Re-measure ALL goals (writes fitness-{CYCLE}-post.json)
重新测量所有目标(写入fitness-{CYCLE}-post.json)
post_results = MEASURE_FITNESS()
post_results = MEASURE_FITNESS()
Check the target goal
检查目标目标
if selected_goal.post_result == "pass":
outcome = "improved"
else:
outcome = "unchanged"
if selected_goal.post_result == "pass":
outcome = "improved"
else:
outcome = "unchanged"
FULL REGRESSION CHECK: compare ALL goals, not just the target
全回归检查:对比所有目标,而不仅仅是目标目标
newly_failing = []
for goal in post_results.goals:
pre = pre_results.find(goal.id)
if pre.result == "pass" and goal.result == "fail":
newly_failing.append(goal.id)
if newly_failing:
outcome = "regressed"
log "REGRESSION: {newly_failing} started failing after fixing {selected.id}"
Multi-commit revert using cycle start SHA
cycle_start_sha = pre_results.cycle_start_sha
commit_count = $(git rev-list --count ${cycle_start_sha}..HEAD)
if commit_count == 0:
log "No commits to revert"
elif commit_count == 1:
git revert HEAD --no-edit
else:
git revert --no-commit ${cycle_start_sha}..HEAD
git commit -m "revert: evolve cycle ${CYCLE} regression in {newly_failing}"
log "Reverted ${commit_count} commits. Moving to next goal."
**Snapshot enforcement:** Validate `fitness-{CYCLE}-post.json` was written and is valid JSON before proceeding.newly_failing = []
for goal in post_results.goals:
pre = pre_results.find(goal.id)
if pre.result == "pass" and goal.result == "fail":
newly_failing.append(goal.id)
if newly_failing:
outcome = "regressed"
log "回归:修复{selected.id}后,{newly_failing}开始未通过"
使用循环开始时的SHA进行多提交回滚
cycle_start_sha = pre_results.cycle_start_sha
commit_count = $(git rev-list --count ${cycle_start_sha}..HEAD)
if commit_count == 0:
log "无提交可回滚"
elif commit_count == 1:
git revert HEAD --no-edit
else:
git revert --no-commit ${cycle_start_sha}..HEAD
git commit -m "revert: evolve循环${CYCLE}中{newly_failing}出现回归"
log "已回滚${commit_count}个提交。将处理下一个目标。"
**快照强制校验:** 在继续执行前,验证`fitness-{CYCLE}-post.json`已写入且为有效JSON。Step 6: Log Cycle
步骤6:记录循环
Append to :
.agents/evolve/cycle-history.jsonljsonl
{"cycle": 1, "goal_id": "test-pass-rate", "result": "improved", "commit_sha": "abc1234", "timestamp": "2026-02-11T21:00:00Z"}
{"cycle": 2, "goal_id": "doc-coverage", "result": "regressed", "commit_sha": "def5678", "reverted_to": "abc1234", "timestamp": "2026-02-11T21:30:00Z"}将内容追加至:
.agents/evolve/cycle-history.jsonljsonl
{"cycle": 1, "goal_id": "test-pass-rate", "result": "improved", "commit_sha": "abc1234", "timestamp": "2026-02-11T21:00:00Z"}
{"cycle": 2, "goal_id": "doc-coverage", "result": "regressed", "commit_sha": "def5678", "reverted_to": "abc1234", "timestamp": "2026-02-11T21:30:00Z"}Step 7: Loop or Stop
步骤7:循环或停止
evolve_state.cycle += 1evolve_state.cycle += 1Only stop for max-cycles if the user explicitly set one
仅当用户明确设置时,才会因达到最大循环次数而停止
if evolve_state.max_cycles != Infinity and evolve_state.cycle >= evolve_state.max_cycles:
log "Max cycles ({max_cycles}) reached."
STOP → go to Teardown
if evolve_state.max_cycles != Infinity and evolve_state.cycle >= evolve_state.max_cycles:
log "已达到最大循环次数({max_cycles})。"
STOP → 进入清理步骤
Otherwise: loop back to Step 1 (kill switch check) — run forever
否则:回到步骤1(终止开关检查)——持续运行
undefinedundefinedTeardown
清理步骤
Auto-run /post-mortem on the full evolution session:
/post-mortem "evolve session: $CYCLE cycles, goals improved: X, harvested: Y"This captures learnings from the ENTIRE evolution run (all cycles, all /rpi invocations) in one council review. The post-mortem harvests follow-up items into , feeding the next session.
next-work.jsonl/evolveCompute session fitness trajectory:
bash
undefined自动对整个进化会话运行/post-mortem:
/post-mortem "evolve会话:$CYCLE个循环,已改进目标:X,已处理待办任务:Y"此命令会在一次评审中捕获整个进化运行(所有循环、所有/rpi调用)的经验。事后分析会将后续任务存入,为下一次会话提供任务。
next-work.jsonl/evolve计算会话fitness变化轨迹:
bash
undefinedCheck if both baseline and final snapshot exist
检查基准和最终快照是否都存在
if [ -f .agents/evolve/fitness-0-baseline.json ] && [ -f .agents/evolve/fitness-${CYCLE}.json ]; then
baseline = load(".agents/evolve/fitness-0-baseline.json")
final = load(".agents/evolve/fitness-${CYCLE}.json")
Compute delta — goals that flipped between baseline and final
improved_count = 0
regressed_count = 0
unchanged_count = 0
delta_rows = []
for final_goal in final.goals:
baseline_goal = baseline.goals.find(g => g.id == final_goal.id)
baseline_result = baseline_goal ? baseline_goal.result : "unknown"
final_result = final_goal.result
if baseline_result == "fail" and final_result == "pass":
delta = "improved"
improved_count += 1
elif baseline_result == "pass" and final_result == "fail":
delta = "regressed"
regressed_count += 1
else:
delta = "unchanged"
unchanged_count += 1
delta_rows.append({goal_id: final_goal.id, baseline_result, final_result, delta})Write session-fitness-delta.md with trajectory table
cat > .agents/evolve/session-fitness-delta.md << EOF
Session Fitness Trajectory
| goal_id | baseline_result | final_result | delta |
|---|---|---|---|
| $(for row in delta_rows: " | ${row.goal_id} | ${row.baseline_result} | ${row.final_result} |
Summary: ${improved_count} improved, ${regressed_count} regressed, ${unchanged_count} unchanged
EOF
Include delta summary in user-facing teardown report
log "Fitness trajectory: ${improved_count} improved, ${regressed_count} regressed, ${unchanged_count} unchanged"
fi
**Then write session summary:**
```bash
cat > .agents/evolve/session-summary.md << EOFif [ -f .agents/evolve/fitness-0-baseline.json ] && [ -f .agents/evolve/fitness-${CYCLE}.json ]; then
baseline = load(".agents/evolve/fitness-0-baseline.json")
final = load(".agents/evolve/fitness-${CYCLE}.json")
计算变化量——基准与最终状态之间发生变化的目标
improved_count = 0
regressed_count = 0
unchanged_count = 0
delta_rows = []
for final_goal in final.goals:
baseline_goal = baseline.goals.find(g => g.id == final_goal.id)
baseline_result = baseline_goal ? baseline_goal.result : "unknown"
final_result = final_goal.result
if baseline_result == "fail" and final_result == "pass":
delta = "improved"
improved_count += 1
elif baseline_result == "pass" and final_result == "fail":
delta = "regressed"
regressed_count += 1
else:
delta = "unchanged"
unchanged_count += 1
delta_rows.append({goal_id: final_goal.id, baseline_result, final_result, delta})将变化轨迹表格写入session-fitness-delta.md
cat > .agents/evolve/session-fitness-delta.md << EOF
会话Fitness变化轨迹
| goal_id | baseline_result | final_result | delta |
|---|---|---|---|
| $(for row in delta_rows: " | ${row.goal_id} | ${row.baseline_result} | ${row.final_result} |
总结: ${improved_count}个目标改进,${regressed_count}个目标退化,${unchanged_count}个目标无变化
EOF
在面向用户的清理报告中包含变化量总结
log "Fitness变化轨迹:${improved_count}个目标改进,${regressed_count}个目标退化,${unchanged_count}个目标无变化"
fi
**然后写入会话总结:**
```bash
cat > .agents/evolve/session-summary.md << EOF/evolve Session Summary
/evolve会话总结
Date: $(date -Iseconds)
Cycles: $CYCLE of $MAX_CYCLES
Goals measured: $(wc -l < GOALS.yaml goals)
日期: $(date -Iseconds)
循环次数: $CYCLE / $MAX_CYCLES
测量目标数: $(wc -l < GOALS.yaml goals)
Cycle History
循环历史
$(cat .agents/evolve/cycle-history.jsonl)
$(cat .agents/evolve/cycle-history.jsonl)
Final Fitness
最终Fitness
$(cat .agents/evolve/fitness-${CYCLE}.json)
$(cat .agents/evolve/fitness-${CYCLE}.json)
Post-Mortem
事后分析
<path to post-mortem report from above>
<上述事后分析报告的路径>
Next Steps
后续步骤
- Run `/evolve` again to continue improving
- Run `/evolve --dry-run` to check current fitness without executing
- Create `~/.config/evolve/KILL` to prevent future runs
- Create `.agents/evolve/STOP` for a one-time local stop EOF
Report to user:- 再次运行`/evolve`继续改进
- 运行`/evolve --dry-run`检查当前fitness而不执行操作
- 创建`~/.config/evolve/KILL`以阻止未来运行
- 创建`.agents/evolve/STOP`实现单次本地停止 EOF
向用户报告:/evolve Complete
/evolve已完成
Cycles: N of M
Goals improved: X
Goals regressed: Y (reverted)
Goals unchanged: Z
Post-mortem: <verdict> (see <report-path>)
Run again to continue improving.
/evolve
---
Read `references/compounding.md` for details on how the knowledge flywheel and work harvesting compound across cycles.
---循环次数:N / M
已改进目标数:X
已退化目标数:Y(已回滚)
无变化目标数:Z
事后分析:<结论>(查看<报告路径>)
再次运行继续改进。
/evolve
---
阅读`references/compounding.md`了解知识飞轮和任务收割如何在循环间实现复利式增长的详细信息。
---Kill Switch
终止开关
Two paths, checked at every cycle boundary:
| File | Purpose | Who Creates It |
|---|---|---|
| Permanent stop (outside repo) | Human |
| One-time local stop | Human or automation |
To stop /evolve:
bash
echo "Taking a break" > ~/.config/evolve/KILL # Permanent
echo "done for today" > .agents/evolve/STOP # Local, one-timeTo re-enable:
bash
rm ~/.config/evolve/KILL
rm .agents/evolve/STOP两种方式,在每个循环边界检查:
| 文件 | 用途 | 创建者 |
|---|---|---|
| 永久停止(仓库外) | 人工 |
| 单次本地停止 | 人工或自动化 |
停止/evolve:
bash
echo "休息一下" > ~/.config/evolve/KILL # 永久停止
echo "今日任务完成" > .agents/evolve/STOP # 本地单次停止重新启用:
bash
rm ~/.config/evolve/KILL
rm .agents/evolve/STOPFlags
参数
| Flag | Default | Description |
|---|---|---|
| unlimited | Optional hard cap. Without this, loop runs forever. |
| off | Pass |
| off | Measure fitness and show plan, don't execute |
| off | Skip cycle-0 baseline sweep |
Read for the GOALS.yaml format.
references/goals-schema.md| 参数 | 默认值 | 描述 |
|---|---|---|
| 无限制 | 可选的循环次数上限。不设置此参数则持续运行。 |
| 关闭 | 将 |
| 关闭 | 测量fitness并展示计划,不执行实际操作 |
| 关闭 | 跳过循环0基准扫描 |
阅读了解GOALS.yaml的格式。
references/goals-schema.mdArtifacts
生成产物
See for the full list of generated files and their purposes.
references/artifacts.md阅读了解所有生成文件及其用途的完整列表。
references/artifacts.mdExamples
示例
See for detailed examples including infinite improvement, dry-run mode, and regression with revert.
references/examples.md阅读了解详细示例,包括无限改进、dry-run模式和带回滚的回归案例。
references/examples.mdTroubleshooting
故障排除
| Problem | Cause | Solution |
|---|---|---|
| Kill switch file exists | Remove |
| "No goals to measure" error | GOALS.yaml missing or empty | Create GOALS.yaml in repo root with fitness goals (see references/goals-schema.md) |
| Cycle completes but fitness unchanged | Goal check command is always passing or always failing | Verify check command logic in GOALS.yaml produces exit code 0 (pass) or non-zero (fail) |
| Regression revert fails | Multiple commits in cycle or uncommitted changes | Check cycle-start SHA in fitness snapshot, commit or stash changes before retrying |
| Harvested work never consumed | All goals passing but | Check file exists and has |
| Loop stops after N cycles | | Omit |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 终止开关文件存在 | 删除 |
| "无目标可测量"错误 | GOALS.yaml缺失或为空 | 在仓库根目录创建包含fitness目标的GOALS.yaml(查看references/goals-schema.md) |
| 循环完成但fitness无变化 | 目标检查命令始终通过或始终失败 | 验证GOALS.yaml中的检查命令逻辑是否能返回0(通过)或非0(未通过)的退出码 |
| 回归回滚失败 | 循环中有多个提交或未提交的更改 | 检查fitness快照中的循环启动SHA,在重试前提交或暂存更改 |
| 待处理任务从未被处理 | 所有目标已通过但未读取next-work.jsonl | 检查文件是否存在且包含 |
| 循环运行N次后停止 | 已设置 | 省略 |
See Also
相关链接
- — Full lifecycle orchestrator (called per cycle)
skills/rpi/SKILL.md - — Code validation (called by /rpi)
skills/vibe/SKILL.md - — Multi-model judgment (called by /rpi)
skills/council/SKILL.md - — Fitness goals for this repo
GOALS.yaml
- — 全生命周期编排器(每个循环调用一次)
skills/rpi/SKILL.md - — 代码验证(由/rpi调用)
skills/vibe/SKILL.md - — 多模型评审(由/rpi调用)
skills/council/SKILL.md - — 本仓库的fitness目标
GOALS.yaml