feat: pm 关 resume 降本 — noResume 配置 + 全新会话注入完整最近历史 - #273
Conversation
新增 AgentConfig.noResume:开启后该 agent 每条消息都用全新 SDK 会话 (不 resume 上一轮),配合注入的最近 N 条聊天历史提供上下文,避免高频 闲聊型 agent(如 pm)长会话逐轮累积把上下文推到数十万 token、成本失控。 - types.ts: AgentConfig 加 noResume?: boolean - config-schema.ts: input + defaults schema 加 noResume - config-loader.ts: mergeAgentConfig 透传(agent 级覆盖 defaults) - agents.example.json: pm 示例开启 noResume=true Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
抽出纯函数 canResumeSession 统一 resume 判定(无会话 / cwd 变更 / agent noResume → 全新会话),并在 executeClaudeTask、executeDirectTask 两条路径接入。 关键修正:历史增量去重(afterMsgId)与历史文件附件跳过原本以 activeConversationId 为准,导致不 resume(noResume 或 cwd 变更)时 只注入增量历史、SDK 端却无对话记忆 → 失忆。改为以 canResume 为准: 只有真正 resume 时才做增量,否则注入完整最近 N 条。 配套上调默认预算,让 fresh 会话装得下足够上下文: - CHAT_HISTORY_MAX_COUNT 10 → 20 - CHAT_HISTORY_MAX_CHARS 8000 → 16000 - SELF_BOT_MSG_MAX 150 → 1500 (noResume 下历史是唯一自我记忆来源, 需保留较完整的自身回复;字符硬顶仍防爆) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- event-handler.test.ts: 新增 canResumeSession describe(无会话/cwd 变更/ noResume/正常 resume 各分支) - config-loader.test.ts: 新增 noResume 透传/继承/覆盖/缺省 4 例 - history-truncation.test.ts: 常量与断言同步到 SELF_BOT_MSG_MAX=1500、 TOTAL_BUDGET=16000,新增'<1500 不截断'回归例 - structured-chat-context.test.ts: 放大输入以在 16000 预算下重新触发 父群消息裁剪/省略提示 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @lishuceo's task in 2m 58s —— View job PR Review: pm 关 resume 降本Verdict: ✅ Approved — clean, well-tested, no blocking issues. One trivial doc-drift nit below.
What I checked
The amnesia fix is real and correct. Previously Optional-chaining consistency — Merge precedence — Budget hard-cap holds — Tests — 🟡 Minor nit (confidence 85, non-blocking)
Notes
|
review 反馈:注释还写 CHAT_HISTORY_MAX_CHARS 默认 8000 / 自身 bot 150 字符, 本 PR 已改成 16000 / 1500,同步注释消除 doc-drift。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Fixed — 已把 |
|
Claude finished @lishuceo's task in 1m 4s —— View job Re-review after doc-comment fix
Verdict: ✅ Approved — the fix in The 🟡 One more stale comment of the same kind (confidence 90, non-blocking)
but this PR bumped that default to Everything else in the PR holds up — no blocking issues. |
背景
pm bot(土豆儿)在高频私聊场景整天 resume 累积,基线上下文从 60K 一路涨到 600K+,长循环里每轮重读把成本推高,频繁撞 $15 budget 上限、无法使用。根因不是单句话贵,而是长会话逐轮累积。
方案
让 pm 不 resume(每条消息全新 SDK 会话),用"注入最近 N 条聊天历史"替代 SDK session 记忆。配套上调历史预算,让 fresh 会话装得下足够上下文。
改动
1. per-agent
noResume配置字段AgentConfig.noResume:开启后该 agent 每条消息全新会话agents.example.json的 pm 示例开启2. 统一 resume 判定
canResumeSession(纯函数,可测)executeClaudeTask、executeDirectTask两条路径afterMsgId)与历史文件附件跳过原本以activeConversationId为准,导致不 resume 时只注入增量、SDK 端却无记忆 → 失忆。改为以canResume为准,只有真正 resume 才做增量,否则注入完整最近 N 条(cwd 变更场景一并受益)3. 上调默认历史预算
CHAT_HISTORY_MAX_COUNT10 → 20CHAT_HISTORY_MAX_CHARS8000 → 16000SELF_BOT_MSG_MAX150 → 1500(noResume 下历史是唯一自我记忆来源,需保留较完整自身回复;字符硬顶仍防爆)测试
canResumeSession单测(4 分支)+noResume配置透传单测(4 例)history-truncation/structured-chat-context测试适配新预算npx vitest run:1757 passed,唯一失败memory/quality.test.ts > 当前工作重点在 main 上同样失败(依赖 embedding API 的环境问题,与本 PR 无关)部署注意
noResume能力;要对 pm 生效,需在部署目录的config/agents.json给 pm 加"noResume": true(该文件不在 git 中)src/config.ts默认值改动,合并后部署目录需 build + 重启生效🤖 Generated with Claude Code