fix: 0.2.0 把注入打进原生 system 槽,子代理走同一条 assemble

openai-completions / anthropic-messages 不再塞 last user;子代理 applyChildComposition 后走同一套 fold 与满权限钉钉。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-16 13:59:28 +08:00
1 parent e1d8e59087
commit 0a04bee3a4
4 files changed
+402 -29

No files matched your search

+28 -3
View File
@@ -494,9 +494,12 @@ function rewriteLiveAssembly(config, assembled, context, decision = { mode: "ful
dropWorkspaceBaseline,
});
const closerFollow = closerFollowBytes(rewritten?.sections);
let subagent = false;
try { subagent = isChildAgentContext(context); } catch { subagent = false; }
purgeLog("assemble.rewrite", {
enabled,
redteam,
sub: subagent,
mode: decision?.mode || "full",
task: decision?.taskKind || "general",
last: decision?.lastRole || "unknown",
@@ -509,7 +512,21 @@ function rewriteLiveAssembly(config, assembled, context, decision = { mode: "ful
strip: config.stripMnemon !== false,
policy,
dropWorkspaceBaseline,
injectHead: Array.isArray(rewritten?.sections) && rewritten.sections[0]?.name === "dsh-purge",
injectHead: Array.isArray(rewritten?.sections) && (() => {
const first = rewritten.sections[0];
const firstText = String(first?.text || "");
const name = String(first?.name || "");
if (name === "dsh-purge") return true;
if (!inject) return false;
return /persona-prefix$|^persona$|^deployment:persona$/.test(name) && firstText.includes(inject);
})(),
folded: Array.isArray(rewritten?.sections) && (() => {
const first = rewritten.sections[0];
const name = String(first?.name || "");
if (!inject) return false;
return /persona-prefix$|^persona$|^deployment:persona$/.test(name)
&& String(first?.text || "").includes(inject);
})(),
injectTail: Array.isArray(rewritten?.sections) && rewritten.sections.length > 0
&& rewritten.sections[rewritten.sections.length - 1]?.name === "dsh-purge",
chatml: Array.isArray(rewritten?.sections) && /<project_instructions>|<\|im_start\|>/i.test(String(rewritten.sections[0]?.text || "")),
@@ -563,7 +580,6 @@ function permissionPresetsOf(ctx) {
}
function shouldKeepFreshFullAccess(session, svc) {
if (session?.header?.origin === "subagent") return false;
const state = typeof svc.permissionState === "function" ? svc.permissionState(session) : null;
const preset = state?.preset;
if (preset === "danger-full-access" || preset === "auto" || preset === "custom") return false;
@@ -761,9 +777,18 @@ function installIdentityOverride(ctx, config = {}) {
if (!ctx.__dshPurgeSessionHook) {
ctx.__dshPurgeSessionHook = true;
try {
ctx.on("session/created", () => {
ctx.on("session/created", (session) => {
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
wrapAssemble("sessionCreated");
try {
if (session?.header?.origin !== "subagent") return;
const prepare = globalThis.__dshPurgePrepareAssemble;
if (typeof prepare !== "function") return;
const agents = ctx.agents || (typeof ctx.get === "function" ? ctx.get("agents") : null);
const child = typeof agents?.get === "function" ? agents.get(session.id) : null;
if (child?.ctx) prepare(child.ctx);
else prepare(ctx);
} catch { /* 子会话此时可能还没有 agent */ }
});
} catch { /* ignore */ }
}