别着急,坐和放宽
使用社交账号登录
用户离开终端 5 分钟后,Claude Code 自动用小模型对最近 30 条消息生成 1-3 句摘要,重新聚焦时展示在 REPL 顶部——告诉你"你不在时/刚才在做什么,下一步是什么"。最新版本也支持 /recap 命令手动触发。
※ recap: 我们在给 bb-browser 构建企业级 s... adapter,刚验证了 powerbi/snapshot 能...
※(REFERENCE_MARK,komejirushi)是专用标记符,标识这是 away summary 消息。
代码:src/hooks/useAwaySummary.ts
触发条件(全部满足才生成):
AWAY_SUMMARY feature flag 开启tengu_sedge_lantern = true(默认 false,需后端下发)BLUR_DELAY_MS = 5 * 60_000)isLoading = false)终端 blur
↓
等 5 分钟
↓ (若 isLoading)
↓ pending → 等模型结束后触发
↓ (若 !isLoading)
↓
生成 away summary
↓
append 到 messages(type: 'system', subtype: 'away_summary')
终端重新 focus → 取消倒计时 + abort 进行中的生成。
terminal focus tracking 依赖 DECSET 1004(终端 focus/blur 事件),不支持此特性的终端(state = 'unknown')不触发。
/recap slash command(最新版本新增)— 直接调用 generateAwaySummary,复用同一套逻辑,绕过 5 分钟等待。
代码:src/services/awaySummary.ts
输入:最近 30 条消息(RECENT_MESSAGE_WINDOW = 30)+ session memory
模型:小模型(getSmallFastModel()),不带 streaming,skipCacheWrite: true
Prompt:
[如有 session memory]
Session memory (broader context):
<memory 内容>
The user stepped away and is coming back. Write exactly 1-3 short sentences.
Start by stating the high-level task — what they are building or debugging, not implementation details.
Next: the concrete next step.
Skip status reports and commit recaps.
关键约束:
API 调用结构(源码:buildAwaySummaryPrompt + generateAwaySummary):
messages: [
...messages.slice(-30), // 原始 messages 数组最后 30 条,原样传入
{
role: "user",
content: [{
type: "text",
text: "Session memory (broader context):\n<memory>\n\n<prompt template>"
}]
} // createUserMessage() 追加的最后一条
]
systemPrompt: [] // 空,不注入 system prompt
tools: []
model: getSmallFastModel()
skipCacheWrite: true
关键点:
user message 的 text block 追加{
type: 'system',
subtype: 'away_summary',
content: "生成的摘要文本",
timestamp: "...",
uuid: "...",
isMeta: false // ← 用户可见
}
isMeta: false——这条消息对用户可见,会正常显示在 transcript 里。
| Away Summary(Recap) | Task Summary | |
|---|---|---|
| 触发 | 终端失焦 5 分钟 / /recap | 每轮 queryLoop 结束 |
| 目的 | 告诉用户"你不在时做了什么" | 供 claude ps 实时显示 |
| 消费方 | 重新聚焦的用户本人 | 其他终端/进程 |
| feature flag | AWAY_SUMMARY | BG_SESSIONS |
| 实现 | 真实实现(可读源码) | 闭源(stub) |