recover
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/recover — Context Recovery After Compaction
/recover — 压缩后的上下文恢复
Purpose: Help you get back up to speed after Claude Code context compaction. Automatically detects in-progress work (RPI runs, evolve cycles), loads relevant knowledge, and summarizes what you were doing and what's next.
YOU MUST EXECUTE THIS WORKFLOW. Do not just describe it.
CLI dependencies: gt, ao, bd — all optional. Shows what's available, skips what isn't.
用途: 帮助您在Claude Code上下文压缩后快速恢复工作状态。自动检测进行中的工作(RPI运行、evolve周期),加载相关知识,并总结您之前正在做的工作以及下一步计划。
您必须执行此工作流,而不只是描述它。
CLI依赖: gt、ao、bd — 均为可选工具。会显示可用的工具,跳过不可用的。
Quick Start
快速开始
bash
/recover # Full recovery dashboard
/recover --json # Machine-readable JSON outputbash
/recover # 完整恢复仪表盘
/recover --json # 机器可读的JSON输出Execution Steps
执行步骤
Step 1: Detect In-Progress Sessions (Parallel)
步骤1:检测进行中的会话(并行执行)
Run ALL of the following in parallel bash calls:
Call 1 — RPI Phased State:
bash
if [ -f .agents/rpi/phased-state.json ]; then
echo "=== RPI_STATE ==="
cat .agents/rpi/phased-state.json
else
echo "RPI_STATE=NONE"
fiCall 2 — Evolve Cycle History:
bash
if [ -f .agents/evolve/cycle-history.jsonl ]; then
echo "=== EVOLVE_STATE ==="
tail -3 .agents/evolve/cycle-history.jsonl
else
echo "EVOLVE_STATE=NONE"
fiCall 3 — Git Recent Changes:
bash
echo "=== GIT_STATUS ==="
git status --short
echo "=== GIT_LOG ==="
git log --oneline -5
echo "=== GIT_BRANCH ==="
git branch --show-currentCall 4 — Work Queue State:
bash
if command -v bd &>/dev/null; then
echo "=== IN_PROGRESS ==="
bd list --status in_progress 2>/dev/null | head -3
echo "=== READY ==="
bd ready 2>/dev/null | head -3
else
echo "BD_UNAVAILABLE"
fiCall 5 — Knowledge and Messages:
bash
undefined并行运行以下所有bash命令:
调用1 — RPI阶段状态:
bash
if [ -f .agents/rpi/phased-state.json ]; then
echo "=== RPI_STATE ==="
cat .agents/rpi/phased-state.json
else
echo "RPI_STATE=NONE"
fi调用2 — Evolve周期历史:
bash
if [ -f .agents/evolve/cycle-history.jsonl ]; then
echo "=== EVOLVE_STATE ==="
tail -3 .agents/evolve/cycle-history.jsonl
else
echo "EVOLVE_STATE=NONE"
fi调用3 — Git近期变更:
bash
echo "=== GIT_STATUS ==="
git status --short
echo "=== GIT_LOG ==="
git log --oneline -5
echo "=== GIT_BRANCH ==="
git branch --show-current调用4 — 工作队列状态:
bash
if command -v bd &>/dev/null; then
echo "=== IN_PROGRESS ==="
bd list --status in_progress 2>/dev/null | head -3
echo "=== READY ==="
bd ready 2>/dev/null | head -3
else
echo "BD_UNAVAILABLE"
fi调用5 — 知识与消息:
bash
undefinedKnowledge artifacts
知识工件
echo "=== KNOWLEDGE_COUNT ==="
echo "Learnings=$(ls .agents/learnings/ 2>/dev/null | wc -l | tr -d ' ')"
echo "Patterns=$(ls .agents/patterns/ 2>/dev/null | wc -l | tr -d ' ')"
echo "=== KNOWLEDGE_COUNT ==="
echo "Learnings=$(ls .agents/learnings/ 2>/dev/null | wc -l | tr -d ' ')"
echo "Patterns=$(ls .agents/patterns/ 2>/dev/null | wc -l | tr -d ' ')"
Inbox if gt available
若gt可用则显示收件箱
if command -v gt &>/dev/null; then
echo "=== MESSAGES ==="
gt mail inbox 2>/dev/null | head -3
else
echo "GT_UNAVAILABLE"
fi
undefinedif command -v gt &>/dev/null; then
echo "=== MESSAGES ==="
gt mail inbox 2>/dev/null | head -3
else
echo "GT_UNAVAILABLE"
fi
undefinedStep 2: Load Context from Knowledge Base
步骤2:从知识库加载上下文
If RPI state detected, run:
bash
if command -v ao &>/dev/null; then
ao inject --apply-decay --format markdown --max-tokens 2000
fi若检测到RPI状态,运行:
bash
if command -v ao &>/dev/null; then
ao inject --apply-decay --format markdown --max-tokens 2000
fiStep 3: Parse and Summarize Session State
步骤3:解析并总结会话状态
Extract from collected data:
-
RPI Detection: Ifexists:
.agents/rpi/phased-state.json- Extract ,
goal,epic_id,phase,cyclestarted_at - Map phase number to phase name (1=research, 2=plan, 3=implement, 4=validate)
- Show elapsed time since started_at
- Extract
-
Evolve Detection: Ifexists:
.agents/evolve/cycle-history.jsonl- Read last entry for most recent cycle
- Extract ,
goals_fixed,resulttimestamp - Show latest cycle summary
-
Recent Work: From git log:
- Last 3 commits (extracted in Call 3)
- Uncommitted changes count
-
Pending Work: From beads:
- In-progress issues (up to 3)
- Ready issues count
-
Knowledge State:
- Total learnings and patterns available
- Unread messages count if gt available
从收集的数据中提取信息:
-
RPI检测: 若存在:
.agents/rpi/phased-state.json- 提取、
goal、epic_id、phase、cyclestarted_at - 将阶段编号映射为阶段名称(1=研究,2=规划,3=实现,4=验证)
- 显示自以来的耗时
started_at
- 提取
-
Evolve检测: 若存在:
.agents/evolve/cycle-history.jsonl- 读取最后一条记录以获取最新周期
- 提取、
goals_fixed、resulttimestamp - 显示最新周期摘要
-
近期工作: 来自git日志:
- 最近3次提交(在调用3中提取)
- 未提交变更的数量
-
待办工作: 来自beads:
- 进行中的问题(最多3个)
- 就绪问题的数量
-
知识状态:
- 可用的学习内容和模式总数
- 若gt可用则显示未读消息数量
Step 4: Render Recovery Dashboard
步骤4:渲染恢复仪表盘
Assemble gathered data into this format:
══════════════════════════════════════════════════════════════
Context Recovery Dashboard
══════════════════════════════════════════════════════════════
IN-PROGRESS RPI RUN
Epic: <epic_id>
Goal: <first 80 chars of goal>
Phase: <phase name: research | plan | implement | validate>
Cycle: <cycle #>
Started: <time ago (e.g., "2 hours ago")>
Status: <PHASE_START | IN_PROGRESS | READY_FOR_GATE | ...>
─ Next Step: <state-aware suggestion from Step 5>
OR
RECENT EVOLVE CYCLE (IF NO RPI)
Cycle: <cycle #>
Latest Goal: <goal_id or summary>
Result: <result>
Items Completed: <count or "—">
Timestamp: <time ago>
─ Next Step: <state-aware suggestion from Step 5>
OR
[NO ACTIVE SESSION]
No RPI run or evolve cycle in progress.
Last activity: <time of last commit or "unknown">
IN-PROGRESS WORK
<list up to 3 in-progress issues with IDs>
<or "No in-progress work">
READY TO WORK
<count of ready issues>
<or "No ready issues">
RECENT COMMITS
<last 3 commits>
PENDING CHANGES
<uncommitted file count or "clean">
KNOWLEDGE AVAILABLE
Learnings: <count> Patterns: <count>
INBOX
<message count or "No messages" or "gt not installed">
──────────────────────────────────────────────────────────────
SUGGESTED NEXT ACTION
<state-aware command from Step 5>
──────────────────────────────────────────────────────────────
QUICK COMMANDS
/status Current workflow dashboard
/research Deep codebase exploration
/plan Decompose work into issues
/implement Execute a single issue
/crank Autonomous epic execution
/vibe Validate code quality
══════════════════════════════════════════════════════════════将收集到的数据组装为以下格式:
══════════════════════════════════════════════════════════════
上下文恢复仪表盘
══════════════════════════════════════════════════════════════
进行中的RPI运行
史诗ID: <epic_id>
目标: <目标的前80个字符>
阶段: <阶段名称:research | plan | implement | validate>
周期: <周期编号>
开始时间: <多久之前(例如:"2小时前")>
状态: <PHASE_START | IN_PROGRESS | READY_FOR_GATE | ...>
─ 下一步:<来自步骤5的状态感知建议>
或
近期Evolve周期(若无RPI)
周期: <周期编号>
最新目标: <goal_id或摘要>
结果: <result>
已完成项: <数量或"—">
时间戳: <多久之前>
─ 下一步:<来自步骤5的状态感知建议>
或
[无活动会话]
无进行中的RPI运行或evolve周期。
最后活动: <最后一次提交的时间或"未知">
进行中的工作
<最多列出3个带ID的进行中问题>
<或"无进行中工作">
就绪工作
<就绪问题的数量>
<或"无就绪问题">
近期提交
<最近3次提交>
待提交变更
<未提交文件数量或"干净">
可用知识
学习内容: <数量> 模式: <数量>
收件箱
<消息数量或"无消息"或"gt未安装">
──────────────────────────────────────────────────────────────
建议的下一步操作
<来自步骤5的状态感知命令>
──────────────────────────────────────────────────────────────
快捷命令
/status 当前工作流仪表盘
/research 深度代码库探索
/plan 将工作分解为问题
/implement 执行单个问题
/crank 自主史诗执行
/vibe 验证代码质量
══════════════════════════════════════════════════════════════Step 5: Suggest Next Action (State-Aware)
步骤5:状态感知的下一步建议
Evaluate context top-to-bottom. Use the FIRST matching condition:
| Priority | Condition | Suggestion |
|---|---|---|
| 1 | Unread messages in inbox | "Check messages: |
| 2 | RPI run in-progress + phase=research | "Continue research: |
| 3 | RPI run in-progress + phase=plan | "Review plan: |
| 4 | RPI run in-progress + phase=implement | "Resume implementation: |
| 5 | RPI run in-progress + phase=validate | "Complete cycle: |
| 6 | Evolve cycle in-progress | "Continue autonomous improvements: |
| 7 | In-progress issues exist | "Continue work: |
| 8 | Ready issues available | "Pick next issue: |
| 9 | Uncommitted changes | "Review changes: |
| 10 | Clean state, nothing pending | "Session recovered. Start with |
自上而下评估上下文,使用第一个匹配的条件:
| 优先级 | 条件 | 建议 |
|---|---|---|
| 1 | 收件箱中有未读消息 | "查看消息: |
| 2 | 进行中的RPI运行 + 阶段=research | "继续研究: |
| 3 | 进行中的RPI运行 + 阶段=plan | "审查规划: |
| 4 | 进行中的RPI运行 + 阶段=implement | "恢复实现: |
| 5 | 进行中的RPI运行 + 阶段=validate | "完成周期: |
| 6 | 进行中的Evolve周期 | "继续自主改进: |
| 7 | 存在进行中的问题 | "继续工作: |
| 8 | 存在就绪问题 | "选择下一个问题: |
| 9 | 存在未提交变更 | "审查变更: |
| 10 | 状态干净,无待办事项 | "会话已恢复。使用 |
Step 6: JSON Output (--json flag)
步骤6:JSON输出(--json参数)
If the user passed , output all recovery data as structured JSON:
--jsonjson
{
"session_type": "rpi|evolve|none",
"rpi": {
"epic_id": "ag-l2pu",
"goal": "Implement...",
"phase": 2,
"phase_name": "plan",
"cycle": 1,
"started_at": "2026-02-15T14:33:36-05:00",
"elapsed_minutes": 120
},
"evolve": {
"cycle": 3,
"result": "improved",
"goals_fixed": ["goal1", "goal2"],
"timestamp": "2026-02-15T22:00:00-05:00"
},
"work_state": {
"in_progress_count": 3,
"in_progress_issues": ["ag-042.1", "ag-042.2"],
"ready_count": 5,
"uncommitted_changes": 2
},
"git": {
"branch": "main",
"recent_commits": [
"7de51c8 feat: wave 2 — structural assertions",
"25004f8 fix: replace per-wave vibe gate"
]
},
"knowledge": {
"learnings_count": 12,
"patterns_count": 5
},
"inbox": {
"unread_count": 0
},
"suggestion": {
"priority": 4,
"message": "Resume implementation: /implement ag-042.1"
}
}Render this with a single code block. No visual dashboard when is active.
--json若用户传递了,则以结构化JSON格式输出所有恢复数据:
--jsonjson
{
"session_type": "rpi|evolve|none",
"rpi": {
"epic_id": "ag-l2pu",
"goal": "Implement...",
"phase": 2,
"phase_name": "plan",
"cycle": 1,
"started_at": "2026-02-15T14:33:36-05:00",
"elapsed_minutes": 120
},
"evolve": {
"cycle": 3,
"result": "improved",
"goals_fixed": ["goal1", "goal2"],
"timestamp": "2026-02-15T22:00:00-05:00"
},
"work_state": {
"in_progress_count": 3,
"in_progress_issues": ["ag-042.1", "ag-042.2"],
"ready_count": 5,
"uncommitted_changes": 2
},
"git": {
"branch": "main",
"recent_commits": [
"7de51c8 feat: wave 2 — structural assertions",
"25004f8 fix: replace per-wave vibe gate"
]
},
"knowledge": {
"learnings_count": 12,
"patterns_count": 5
},
"inbox": {
"unread_count": 0
},
"suggestion": {
"priority": 4,
"message": "Resume implementation: /implement ag-042.1"
}
}使用单个代码块渲染此内容。当激活时,不显示可视化仪表盘。
--jsonExamples
示例
Recovery After Compaction Mid-RPI
压缩期间RPI运行中的恢复
User says:
/recoverWhat happens:
- Agent runs 5 parallel bash calls to gather state
- Agent detects RPI run in phased-state.json (phase=2, epic ag-l2pu)
- Agent runs to load relevant knowledge
ao inject - Agent shows goal, current phase (plan), cycle 1, started 2 hours ago
- Agent lists 2 in-progress issues and 3 ready issues
- Agent shows clean git state, recent commit
- Agent suggests: "Review plan: to validate before coding"
/pre-mortem
Result: Dashboard confirms in-progress RPI session, loads context, suggests next step.
用户输入:
/recover执行过程:
- Agent运行5个并行bash调用以收集状态
- Agent在phased-state.json中检测到RPI运行(阶段=2,史诗ag-l2pu)
- Agent运行以加载相关知识
ao inject - Agent显示目标、当前阶段(规划)、周期1、2小时前开始
- Agent列出2个进行中的问题和3个就绪问题
- Agent显示干净的git状态和近期提交
- Agent建议:"审查规划:以在编码前验证"
/pre-mortem
结果: 仪表盘确认进行中的RPI会话,加载上下文,建议下一步操作。
Recovery After Compaction With Evolve Cycle
压缩期间Evolve周期中的恢复
User says:
/recoverWhat happens:
- Agent gathers state in parallel
- Agent finds no RPI run
- Agent detects evolve cycle (most recent: cycle 3, result "improved", goals_fixed=["goal1", "goal2"])
- Agent shows timestamp (1 hour ago), items_completed (8)
- Agent loads knowledge with
ao inject - Agent suggests: "Continue autonomous improvements: "
/evolve --resume
Result: Dashboard confirms evolve cycle, shows progress, offers resume command.
用户输入:
/recover执行过程:
- Agent并行收集状态
- Agent未找到RPI运行
- Agent检测到evolve周期(最新:周期3,结果"improved",goals_fixed=["goal1", "goal2"])
- Agent显示时间戳(1小时前)、已完成项(8个)
- Agent使用加载知识
ao inject - Agent建议:"继续自主改进:"
/evolve --resume
结果: 仪表盘确认evolve周期,显示进度,提供恢复命令。
Recovery in Clean State (No Active Session)
干净状态下的恢复(无活动会话)
User says:
/recoverWhat happens:
- Agent gathers state in parallel
- Agent finds no RPI run, no evolve cycle
- Agent shows last 3 commits only
- Agent finds no in-progress work, no ready issues
- Agent shows 12 learnings available from knowledge base
- Agent suggests: "Session recovered. Start with to plan next work"
/status
Result: Dashboard confirms clean state, points user to entry points.
用户输入:
/recover执行过程:
- Agent并行收集状态
- Agent未找到RPI运行或evolve周期
- Agent仅显示最近3次提交
- Agent未找到进行中工作或就绪问题
- Agent显示知识库中有12个学习内容可用
- Agent建议:"会话已恢复。使用规划下一步工作"
/status
结果: 仪表盘确认干净状态,为用户提供入口点指引。
Troubleshooting
故障排除
| Problem | Cause | Solution |
|---|---|---|
| Shows "BD_UNAVAILABLE" or "GT_UNAVAILABLE" | CLI tools not installed or not in PATH | Install missing tools: |
| RPI state shows wrong phase | Stale phased-state.json not updated | Check timestamp of |
| Evolve history shows wrong cycle | Old cycle-history.jsonl entries not pruned | Tail -3 shows most recent entries. Check all entries with |
| Knowledge injection fails silently | ao CLI not installed or no knowledge artifacts | Ensure ao installed: |
| Suggested action doesn't match context | State-aware rules didn't capture edge case | Use |
| JSON output malformed | Parallel bash calls returned unexpected format | Check each bash call individually. Ensure jq parsing works on actual data. Validate JSON structure before returning to user. |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 显示"BD_UNAVAILABLE"或"GT_UNAVAILABLE" | CLI工具未安装或不在PATH中 | 安装缺失的工具: |
| RPI状态显示错误阶段 | 过时的phased-state.json未更新 | 检查 |
| Evolve历史显示错误周期 | 旧的cycle-history.jsonl条目未被修剪 | |
| 知识注入静默失败 | ao CLI未安装或无知识工件 | 确保已安装ao: |
| 建议的操作与上下文不匹配 | 状态感知规则未捕获边缘情况 | 使用 |
| JSON输出格式错误 | 并行bash调用返回了意外格式 | 单独检查每个bash调用。确保jq解析可处理实际数据。返回给用户前验证JSON结构。 |