diff --git a/lib/index.js b/lib/index.js index 9c81a5e..ce6894b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -493,11 +493,11 @@ function installIdentityOverride(ctx, config = {}) { installHungPromptGlobal(); // complete:true 会在 waterfall 之后盖掉 sections;包住 assemble 返回值,每轮都补回注入。 wrapAssemble(); - const started = Date.now(); - const timer = setInterval(() => { - wrapAssemble(); - if (Date.now() - started > 20000) clearInterval(timer); - }, 400); + // guard 需要在每次 cordis 换 systemPrompt 代理时重挂(session 内切预设、subagent fork、 + // live-mount)。原本 20 秒后 clearInterval,之后换代理就包不上 → 第二轮 inject 走原生 + // assemble → 宿主按 token 预算裁剪 → 用户看到"只截取了部分"。installAssembleGuard 幂等 + // (只做对象 identity 校验 + Map get),400ms 持续跑到 ctx dispose 的 CPU 代价可忽略。 + const timer = setInterval(wrapAssemble, 400); if (typeof timer.unref === "function") timer.unref(); try { ctx.on("session/created", wrapAssemble); } catch { /* ignore */ } try {