revert(inject): v6 回到 v3 规则 — v4 turn-start / v5 全 full 都失败,v3 中途发送前正常

This commit is contained in:
叫我小杨同学 committed 2026-10-09 23:05:21 +08:00
1 parent 884acca937
commit e6ce8dd056
1 file changed
+29 -24
+29 -24
View File
@@ -222,12 +222,18 @@ function installHungPromptGlobal() {
return fn;
}
// [dsh-purge-fix 2026-10-09 方案2 v5] anchor 分支取消 — 工具链里 500 字符身份锚挡不住 Claude
// 本尊拉回,导致任务被拒绝 (v4 实测失效:task-decl full 一次后进 tool-loop/anchor,下一步 LLM
// 就滑回 Claude 身份拒绝 YG)。回到 "全部 full" 策略 — 不省 token,保证不拒绝。
// retry pending 仍走 full (本来就 full),.hung-disabled 存在时唯一决策是:无条件 full。
// [dsh-purge-fix 2026-10-09 方案2 v6 = v3 回退] 回到 v3 规则 (中途发送之前正常的版本)。
// v4 的 turn-start 分支改坏了,去掉。保留 v3 的三段式。
//
// 规则 (.hung-disabled 存在时):
// 1. retry pending → full lastRole=retry
// 2. 没找到真实 user/message → full lastRole=no-user
// 3. 最近真实 user/message 之后 asst+tool 条数:
// 0 → full lastRole=user (激活身份)
// 1 → full lastRole=task-decl (任务目标声明)
// ≥2 → anchor lastRole=tool-loop (工具回环,省 token)
function shouldInjectAssembly(context, home) {
const decision = { mode: "full", taskKind: "general", lastRole: "always-full", isSubagent: false };
const decision = { mode: "full", taskKind: "general", lastRole: "unknown", isSubagent: false };
const session = context?.agent?.session;
try {
decision.isSubagent = session?.header?.origin === "subagent";
@@ -241,6 +247,22 @@ function shouldInjectAssembly(context, home) {
decision.lastRole = "retry";
return decision;
}
const events = readSessionEvents(session);
if (!Array.isArray(events) || events.length === 0) { decision.lastRole = "no-events"; return decision; }
const scan = scanUserTurn(events);
if (!scan.foundUser) { decision.lastRole = "no-user"; return decision; }
if (scan.afterCount === 0) {
decision.lastRole = "user";
return decision;
}
if (scan.afterCount === 1) {
decision.lastRole = "task-decl";
decision.taskKind = detectTaskKindFromEvents(events);
return decision;
}
decision.lastRole = "tool-loop";
decision.mode = "anchor";
decision.taskKind = detectTaskKindFromEvents(events);
return decision;
}
@@ -258,36 +280,19 @@ function readSessionEvents(session) {
// 从末尾向前扫,返回:
// foundUser: 是否找到真实 user/message (kind !== plugin/dsh-purge)
// afterCount: 该 user/message 之后 assistant/message + tool/result 的条数
// newTurn: 最新 turn/start 之后还没有任何 user/message append (真实或内部都没)
// → 新 user turn 刚启动,user 消息即将 append,强制走 full
// continuation 场景 (agent.followup) 会 append kind=dsh-purge user/message → 不触发 newTurn → 正常 afterCount。
function scanUserTurn(events) {
let afterCount = 0;
let latestTurnStartSeq = -1;
let hasAnyUserAfterLatestStart = false;
for (let i = events.length - 1; i >= 0; i--) {
const e = events[i];
if (!e || typeof e.type !== "string") continue;
const seq = typeof e.seq === "number" ? e.seq : i;
if (e.type === "turn/start") {
if (latestTurnStartSeq < 0) latestTurnStartSeq = seq;
continue;
}
if (e.type === "user/message") {
if (latestTurnStartSeq >= 0 && seq > latestTurnStartSeq) hasAnyUserAfterLatestStart = true;
const kind = e.data?.source?.kind;
if (kind === "plugin" || kind === "dsh-purge") continue;
if (latestTurnStartSeq >= 0 && seq < latestTurnStartSeq && !hasAnyUserAfterLatestStart) {
return { foundUser: true, afterCount: 0, newTurn: true };
}
return { foundUser: true, afterCount, newTurn: false };
return { foundUser: true, afterCount };
}
if (e.type === "assistant/message" || e.type === "tool/result") afterCount += 1;
}
if (latestTurnStartSeq >= 0 && !hasAnyUserAfterLatestStart) {
return { foundUser: true, afterCount: 0, newTurn: true };
}
return { foundUser: false, afterCount, newTurn: false };
return { foundUser: false, afterCount };
}
// [方案2] 简化版 inject (anchor + 任务块)。工具回环时替代全量 inject 塞进 fallbackInject。