Files
dsh-purge/lib
叫我小杨同学 473cf80669 fix(inject): v4 加 turn-start 分支 — 中途发消息也强制 full
YG 实测反馈 v3 规则下中途发消息走了 anchor,不是预期的 full。

根因:cordis dsh-agent-loop step() 顺序是
  turn/start → prepare → assemble → user/message append → request
assemble 发生在 user/message append 之前,中途发消息的那次 assemble 时 session
末尾只有 turn/start,新的真实 user/message 还没进来。原 scanUserTurn 只找最后
一个真实 user/message,扫到的是 **旧 turn** 的,afterCount 积得很大 → 误判
tool-loop → anchor。

v4 修法:
- scanUserTurn 追踪 latestTurnStartSeq 和 hasAnyUserAfterLatestStart (真实或
  内部 kind=plugin/dsh-purge 都算)。
- 如果 "最新 turn/start 之后没有任何 user/message append" → newTurn=true →
  shouldInjectAssembly 返回 full lastRole=turn-start。
- 如果 continuation (agent.followup) 已经 append 了 kind=dsh-purge 的 user/message
  在 turn/start 之后 → hasAnyUserAfterLatestStart=true → 不触发 newTurn →
  走正常 afterCount,一般是 tool-loop 的 anchor,符合 "agent 自己继续不是 user 发话"。

现在的 lastRole 枚举:retry / turn-start / no-user / user / task-decl / tool-loop
前五个都是 full,只有 tool-loop 是 anchor。
2026-10-09 22:52:53 +08:00
..