| name | evolve-apply |
| description | Manage evolution suggestion lifecycle: list, apply, skip, and rollback suggestions generated by /evolve. Trigger: /evolve-apply, evolve-apply, 应用建议, /evolve-rollback, evolve rollback. |
Evolve-Apply — Suggestion Lifecycle Manager
Purpose
View, apply, skip, or rollback evolution suggestions from pending.json.
When Triggered
User says "/evolve-apply", "evolve-apply", "应用建议", "/evolve-rollback",
"evolve rollback", or wants to manage evolution suggestions.
Data Paths
- Pending:
~/.pi/agent/evolution-data/suggestions/pending.json
- History:
~/.pi/agent/evolution-data/history.jsonl
- Backups:
~/.pi/agent/evolution-data/backups/
Procedure
Parse Command
- No args or "list" → LIST mode
- "apply N" → APPLY mode (0-indexed)
- "skip N" → SKIP mode (0-indexed)
- "rollback" → ROLLBACK mode
LIST Mode
- Read
pending.json using the read tool
- If file doesn't exist or suggestions array is empty:
"No pending suggestions. Run /evolve first to generate suggestions."
- Display each suggestion:
[#0] [HIGH] Clean up dormant skills (confidence: 0.85)
Target: ~/.pi/agent/CLAUDE.md
Status: pending
Summary: <first 2 lines of description>
APPLY Mode
- Read
pending.json, validate index N exists and status is "pending"
- Get suggestion at index N
- Backup: Use
bash tool to run:
mkdir -p ~/.pi/agent/evolution-data/backups
cp "<targetPath>" "~/.pi/agent/evolution-data/backups/<timestamp>-<filename>"
Use ISO timestamp with colons replaced by dashes for the backup filename.
If cp fails → ABORT, tell user "Backup failed, cannot apply. Reason: ..."
- Modify file: Use
edit or write tool to apply the suggestion's
instruction to targetPath. Follow the instruction precisely.
If edit fails → clean up backup file (rm "<backupPath>"), ABORT,
tell user reason, keep status as "pending",
do NOT update pending.json or append to history.jsonl.
- Git commit: Use
bash tool:
cd "$(dirname '<targetPath>')" && git add '<filename>' && git commit -m "evolve: <title>"
If commit fails → CONTINUE (commitSha will be empty)
- Update pending.json: Change suggestion status to "applied". Use
write
tool to overwrite the entire file.
- Append to history.jsonl: Use
bash tool with python to ensure
valid single-line JSON (avoids heredoc issues with multi-line instruction):
python3 -c "import json; print(json.dumps({'timestamp':'<ISO>','action':'apply','suggestionId':'<id>','targetPath':'<path>','backupPath':'<backup>','instruction':'<instruction text>','title':'<title>','commitSha':'<sha>'}, ensure_ascii=False))" >> ~/.pi/agent/evolution-data/history.jsonl
Escape single quotes in values before passing to python -c.
- Confirm to user: "Applied suggestion #N: . Backup at <backupPath>."
SKIP Mode
- Read
pending.json, validate index N exists and status is "pending"
- Update suggestion status to "rejected"
- Write back
pending.json using write tool
- Confirm: "Skipped suggestion #N: ."
ROLLBACK Mode
- Read
history.jsonl (last line = most recent action)
- Find the most recent "apply" action that hasn't been rolled back
- Check if
backupPath file exists
- If backup exists: Use
bash tool to restore:
cp "<backupPath>" "<targetPath>"
Verify cp succeeded (exit code 0). If cp fails → ABORT, tell user.
If cp succeeded → commit:
cd "$(dirname '<targetPath>')" && git add '<filename>' && git commit -m "evolve: rollback <title>"
- If backup missing: Tell user "Cannot auto-restore: backup file not found
at . You may need to manually check git history." STOP HERE.
Do NOT proceed to steps 6-8. Do NOT update pending.json or history.jsonl.
- Update pending.json (only if step 4 succeeded): Find the suggestion
matching the suggestionId and change its status back to "pending".
Use
write tool to overwrite.
- Append rollback to history.jsonl (only if step 4 succeeded):
python3 -c "import json; print(json.dumps({'timestamp':'<ISO>','action':'rollback','suggestionId':'<id>','targetPath':'<path>','backupPath':'<backup>','instruction':'','title':'<title>','commitSha':'<sha>'}, ensure_ascii=False))" >> ~/.pi/agent/evolution-data/history.jsonl
- Confirm (only if step 4 succeeded): "Rolled back: . File restored from backup."