mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 03:00:22 +08:00
feat(inject): .hung-disabled 启用方案2 — assemble 按 user turn 去重 + retry 例外
- shouldInjectAssembly(context, home): 开关存在时,只在 last message role===user 或 __dshPurgeRetryPending 为真时放行,tool-call 回环返原 assembled - rewriteFn(installAssembleGuard 路径) + system-prompt/assemble 回调两条路径同判断 - installHungPromptGlobal: hung 永久返空,把 patch #81 的 "system 不含 inject 时 补塞" 补救逻辑废掉,让 inject 完全由 cordis 层决策,避免绕过规则 - continue-retry.js: tracker.takeRetry 成功后设 __dshPurgeRetryPending=true, 下次 assemble 消费后清零 — 救场链路保留
This commit is contained in:
1 parent
661eebac15
commit
3cc691c66c
2 files changed
+46
-5
No files matched your search
@@ -323,6 +323,10 @@ export function installContinueRetry(ctx, options = {}) {
|
||||
const id = sessionIdOf(payload?.agent);
|
||||
const key = `${payload?.turn || 0}:${payload?.step || 0}:${payload?.failure?.code || ""}`;
|
||||
if (!tracker.takeRetry(id, key, cfg.retryMax)) return downstream;
|
||||
// [方案2] 标记 retry pending,让下次 system-prompt/assemble 强制塞 inject
|
||||
// (消费一次后由 shouldInjectAssembly 清掉)。user 发消息自然塞,不需要;
|
||||
// retry 不是 user 触发,messages 结构没变,必须靠这个 flag 让 assemble 吃到。
|
||||
globalThis.__dshPurgeRetryPending = true;
|
||||
return { kind: "retry" };
|
||||
});
|
||||
|
||||
|
||||
+42
-5
@@ -201,10 +201,11 @@ function installHungPromptGlobal() {
|
||||
const fn = () => {
|
||||
try {
|
||||
const home = core.findDshHome();
|
||||
// [dsh-purge-fix 2026-10-09 方案A] 开关文件 DSH_HOME/.hung-disabled 存在时,
|
||||
// hung 返空串 → 每步 model.step 不再追加 prompt-inject.md 全文 (省 ~9000 token/步)。
|
||||
// system 层由 patch #67/#68/#74 保证不被 rewind/compaction 洗掉,够兜底。
|
||||
// 想关掉开关恢复全量 inject: 删掉 .hung-disabled 文件 + 重启 DSH。
|
||||
// [dsh-purge-fix 2026-10-09 方案2] 开关文件 DSH_HOME/.hung-disabled 存在时,
|
||||
// hung 永久返空 — 把 patch #81 的 "system 不含 inject 时补塞" 补救逻辑废掉,
|
||||
// 让 inject 完全由 cordis 的 system-prompt/assemble 回调 (按 user turn + retry
|
||||
// 条件) 决策,避免 hung 补塞绕过规则。
|
||||
// rm .hung-disabled + 重启 → 回到旧行为 (全量 inject 每步都塞)。
|
||||
if (home) {
|
||||
try {
|
||||
if (fs.existsSync(`${home}/.hung-disabled`)) return "";
|
||||
@@ -219,6 +220,36 @@ function installHungPromptGlobal() {
|
||||
return fn;
|
||||
}
|
||||
|
||||
// [dsh-purge-fix 2026-10-09 方案2] 按 user turn 去重 + 自动重试例外。
|
||||
// 规则:
|
||||
// - .hung-disabled 开关不存在 → 原行为 (每次 assemble 都塞 inject)
|
||||
// - .hung-disabled 开关存在 → 只在以下场景塞 inject:
|
||||
// 1. messages 最后一条 role === "user" (user 刚发消息,新 turn 的首次 model.step)
|
||||
// 2. globalThis.__dshPurgeRetryPending === true (continue-retry 刚触发)
|
||||
// tool-call 回环 (last role === "tool" / "assistant") → 不塞
|
||||
// 命中后清掉 retry flag,保证单次消费。
|
||||
function shouldInjectAssembly(context, home) {
|
||||
if (!home) return true;
|
||||
try {
|
||||
if (!fs.existsSync(`${home}/.hung-disabled`)) return true; // 开关没开 → 原行为
|
||||
} catch { return true; }
|
||||
if (globalThis.__dshPurgeRetryPending) {
|
||||
globalThis.__dshPurgeRetryPending = false;
|
||||
return true;
|
||||
}
|
||||
// 从 context 多个可能路径找 messages (cordis 版本间字段名有差异,保守多试)。
|
||||
const msgs =
|
||||
context?.session?.messages ||
|
||||
context?.messages ||
|
||||
context?.conversation?.messages ||
|
||||
context?.history ||
|
||||
null;
|
||||
if (!Array.isArray(msgs) || msgs.length === 0) return true; // 拿不到 → 保守塞
|
||||
const last = msgs[msgs.length - 1];
|
||||
if (!last) return true;
|
||||
return last.role === "user";
|
||||
}
|
||||
|
||||
function injectSnapshot(dshHome = core.findDshHome()) {
|
||||
const resolved = rules.resolveInjectText(dshHome);
|
||||
return {
|
||||
@@ -498,7 +529,11 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
wrapDisposers.add(d);
|
||||
return d;
|
||||
};
|
||||
const rewriteFn = (assembled, context) => rewriteLiveAssembly(config, assembled, context);
|
||||
const rewriteFn = (assembled, context) => {
|
||||
// [方案2] installAssembleGuard 走的也是这条路径,同样按 user turn / retry 条件决策。
|
||||
if (!shouldInjectAssembly(context, core.findDshHome())) return assembled;
|
||||
return rewriteLiveAssembly(config, assembled, context);
|
||||
};
|
||||
const wrapAssemble = () => {
|
||||
try {
|
||||
const prompt = ctx.systemPrompt;
|
||||
@@ -526,6 +561,8 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
// [方案2] 工具回环/非 user turn 不塞 inject,直接返原生 assembled。
|
||||
if (!shouldInjectAssembly(context, core.findDshHome())) return assembled;
|
||||
return rewriteLiveAssembly(config, assembled, context);
|
||||
} catch (err) {
|
||||
try { console.warn("[dsh-purge] rewriteLiveAssembly failed:", err?.message || err); } catch {}
|
||||
|
||||
Reference in new issue
Block a user