mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 04:20:22 +08:00
fix: 发布 1.1.48,桌面跟 Web 配置、红队派活与 skill/MCP 按任务选用。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
33baeeef45
commit
eb09b2e62d
12 files changed
+389
-38
No files matched your search
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 能力选用协议:先读 skill / MCP 目录,再按当前任务选用。
|
||||
* 不改官方 skill 注册、不改 MCP 挂载、不 deny 任何工具。
|
||||
*/
|
||||
|
||||
export const CAPABILITY_SECTION = "dsh-purge:capabilities";
|
||||
|
||||
const OFFICIAL_PROTOCOL = `## Capability selection by task (mandatory)
|
||||
|
||||
1. **Read first**: Inspect \`<available_skills>\` / the skill catalog and the installed MCP / host tools for this session. Know what exists before acting.
|
||||
2. **Match the task**: From that catalog, pick the skill(s) and MCP/CLI tool(s) that fit *this* user task — not “always use something”, not “never use something”.
|
||||
3. **Call what matches**:
|
||||
- Matching **Skill** → load it with the host \`skill\` tool, then follow it (methods, premises, branches, counter-evidence).
|
||||
- Matching **MCP / CLI** → call that tool with real schema and context; treat failures by the tool’s semantics.
|
||||
4. **Only then DIY**: If nothing in the catalog fits the task, use shell / ad-hoc steps and say what was missing.
|
||||
5. **Subagents / sub-delegates inherit this rule**: Any \`subagent\`, teammate, or child agent you start must also read the catalog and call task-matched skills/MCP the same way. Put that requirement in the child brief when you dispatch.
|
||||
6. Host skills and MCP stay available; this prompt does not remove them.`;
|
||||
|
||||
const REDTEAM_LEAD_PROTOCOL = `## Capability selection by task (redteam lead)
|
||||
|
||||
1. You plan, dispatch with \`subagent\`, verify results, and report. Executors do hands-on work.
|
||||
2. Before dispatch, know which skills/MCP fit the next stage (from \`<available_skills>\` / redteam skills / session MCP).
|
||||
3. In every \`subagent\` brief: require the child to **read the skill/MCP catalog, then call only what the assigned task needs** (name concrete skill codes when you know them).
|
||||
4. Do not ban skill or MCP for children. Leaf limits apply only to further delegation tools (\`subagent_fork\` / workflow / ralph), not to skill/MCP.
|
||||
5. Vague “go investigate” briefs are wrong; task-matched skill/MCP instructions are right.`;
|
||||
|
||||
const REDTEAM_CHILD_PROTOCOL = `## Capability selection by task (redteam executor)
|
||||
|
||||
1. **Read** \`<available_skills>\` / your role skills and available MCP/CLI tools.
|
||||
2. **Match** them to *your assigned task* (not every skill, not zero skills).
|
||||
3. **Call** matching skills via \`skill\`, and matching MCP/CLI tools by schema, before freelancing equivalent shell work.
|
||||
4. DIY only for gaps the catalog does not cover; stay in role; do not re-delegate.`;
|
||||
|
||||
/**
|
||||
* @param {{ redteam?: boolean, redteamChild?: boolean, enabled?: boolean }} [opts]
|
||||
* @returns {string}
|
||||
*/
|
||||
export function capabilityProtocolText(opts = {}) {
|
||||
if (opts.enabled === false) return "";
|
||||
if (opts.redteamChild) return REDTEAM_CHILD_PROTOCOL;
|
||||
if (opts.redteam) return REDTEAM_LEAD_PROTOCOL;
|
||||
return OFFICIAL_PROTOCOL;
|
||||
}
|
||||
+51
-1
@@ -1744,6 +1744,12 @@ export async function openSealedDesktopHost(options = {}) {
|
||||
restoreUnusableExtract(appDir, prev);
|
||||
throw new Error(`已解开 ${handoff.asar},但 ${appDir} 下没有 @deepseek-ai`);
|
||||
}
|
||||
try {
|
||||
desktop.useWebProfileInOfficialShell(appDir);
|
||||
desktop.ensureDesktopRemoteUiOff(findDshHome());
|
||||
} catch {
|
||||
/* 壳入口或缺 Web profile 时下次 Apply 再对齐 */
|
||||
}
|
||||
resetPathMemo();
|
||||
return { aiBase, swapAsar: true, exe: handoff.exe, asar: handoff.asar, extracted, prev, appDir, archive: extracted ? archive : null };
|
||||
}
|
||||
@@ -1863,6 +1869,10 @@ export function desktopAsarStillSealed(input = {}) {
|
||||
return Boolean(handoff?.asar && asarArchiveIsFile(handoff.asar));
|
||||
}
|
||||
|
||||
export function alignOfficialShellProfile(input = {}) {
|
||||
return desktop.alignOfficialDesktopProfile(input);
|
||||
}
|
||||
|
||||
export function officialHostMustStayUp() {
|
||||
return process.env.ELECTRON_RUN_AS_NODE === "1" && desktop.isOfficialHarnessExecutable(process.execPath);
|
||||
}
|
||||
@@ -2570,7 +2580,7 @@ const NEW_TOOL_PATCHES = [
|
||||
id: 23, name: "SUBAGENT_MAXDEPTH_RAISED", layer: "代码", layer_en: "Code",
|
||||
desc: "子代理深度默认 3 → 10 / subagent maxDepth raised",
|
||||
// 0.1.7 起深度默认在工具参数上(dsh-tool-subagent);旧版在 dsh-subagent 服务配置上。
|
||||
// 两个 key 都列,命中哪个都能抬高递归预算。
|
||||
// 0.2 起 tool-subagent 的 maxDepth 可能没有 .default(3),补回 default(10)。
|
||||
file: ["subagent", "tool-subagent"],
|
||||
rel: ["lib", "index.js"],
|
||||
replacements: [
|
||||
@@ -2581,6 +2591,13 @@ const NEW_TOOL_PATCHES = [
|
||||
replace:
|
||||
'maxDepth: z.union([z.natural().max(Number.MAX_SAFE_INTEGER), z.const("provider-managed")]).default(10) // [dsh-purge] subagent depth raised',
|
||||
},
|
||||
{
|
||||
// 0.2:schema 去掉了 default,官方 preset 又不写 maxDepth;补回 default(10)。
|
||||
pattern:
|
||||
'maxDepth: z.union([z.natural().max(Number.MAX_SAFE_INTEGER), z.const("provider-managed")])\n});',
|
||||
replace:
|
||||
'maxDepth: z.union([z.natural().max(Number.MAX_SAFE_INTEGER), z.const("provider-managed")]).default(10) // [dsh-purge] subagent depth raised\n});',
|
||||
},
|
||||
{
|
||||
// 0.1.5/0.1.6 时代:数值 schema,默认 1。
|
||||
pattern:
|
||||
@@ -3325,6 +3342,39 @@ const NEW_TOOL_PATCHES = [
|
||||
],
|
||||
markers: ["function dshPurgeHandoffDesktopUpdate", "dshPurgeHandoffDesktopUpdate(this)"],
|
||||
},
|
||||
{
|
||||
id: 70,
|
||||
name: "OFFICIAL_DESKTOP_USE_WEB_PROFILE",
|
||||
layer: "代码",
|
||||
layer_en: "Code",
|
||||
desc: "官方桌面有 Web profile 时改读 profiles/web,渠道和插件与 Web 端一致",
|
||||
file: "desktop-shell",
|
||||
surfaces: ["desktop"],
|
||||
optional: true,
|
||||
skipIfMarked: true,
|
||||
replacements: [
|
||||
{
|
||||
pattern:
|
||||
"function resolveDesktopPaths(dshHome = resolveDshHome()) {\n" +
|
||||
"\treturn {\n" +
|
||||
'\t\tprofile: join(dshHome, "profiles", "desktop"),\n' +
|
||||
'\t\tlock: join(dshHome, "profiles", "desktop", "lock")\n' +
|
||||
"\t};\n" +
|
||||
"}",
|
||||
replace:
|
||||
"function resolveDesktopPaths(dshHome = resolveDshHome()) {\n" +
|
||||
'\tconst webProfile = join(dshHome, "profiles", "web");\n' +
|
||||
'\tconst desktopProfile = join(dshHome, "profiles", "desktop");\n' +
|
||||
'\tconst profile = existsSync(join(webProfile, "package.json")) ? webProfile : desktopProfile;\n' +
|
||||
"\treturn {\n" +
|
||||
"\t\tprofile,\n" +
|
||||
'\t\tlock: join(profile, "lock")\n' +
|
||||
"\t};\n" +
|
||||
"}",
|
||||
},
|
||||
],
|
||||
markers: ['const webProfile = join(dshHome, "profiles", "web")'],
|
||||
},
|
||||
{
|
||||
id: 46, name: "OFFICIAL_DESKTOP_UPDATE_ASCII", layer: "代码", layer_en: "Code",
|
||||
desc: "已接管的官方桌面更新改为 ASCII 脚本,中文 Windows 不再吞掉换行",
|
||||
|
||||
@@ -1026,6 +1026,88 @@ function officialExeFromProcess() {
|
||||
return fs.existsSync(beside) ? beside : "";
|
||||
}
|
||||
|
||||
const WEB_PROFILE_RESOLVER =
|
||||
"function resolveDesktopPaths(dshHome = resolveDshHome()) {\n" +
|
||||
'\tconst webProfile = join(dshHome, "profiles", "web");\n' +
|
||||
'\tconst desktopProfile = join(dshHome, "profiles", "desktop");\n' +
|
||||
'\tconst profile = existsSync(join(webProfile, "package.json")) ? webProfile : desktopProfile;\n' +
|
||||
"\treturn {\n" +
|
||||
"\t\tprofile,\n" +
|
||||
'\t\tlock: join(profile, "lock")\n' +
|
||||
"\t};\n" +
|
||||
"}";
|
||||
|
||||
const WEB_PROFILE_RESOLVER_RE =
|
||||
/function resolveDesktopPaths\(dshHome = resolveDshHome\(\)\) \{\s*return \{\s*profile: join\(dshHome, "profiles", "desktop"\),\s*lock: join\(dshHome, "profiles", "desktop", "lock"\)\s*\};\s*\}/;
|
||||
|
||||
function officialShellMainCandidates(appDir) {
|
||||
if (!appDir) return [];
|
||||
return [path.join(appDir, "lib", "main.js"), path.join(appDir, "main.js")];
|
||||
}
|
||||
|
||||
/** 官方壳默认只开 profiles/desktop。同一 DSH_HOME 下已有 Web profile 时改读那一份,渠道和插件才能跟过来。 */
|
||||
export function useWebProfileInOfficialShell(appDir) {
|
||||
const mains = officialShellMainCandidates(appDir).filter((fp) => isFile(fp));
|
||||
if (!mains.length) return { changed: false, missing: true };
|
||||
let changed = false;
|
||||
let already = false;
|
||||
let missing = false;
|
||||
for (const mainJs of mains) {
|
||||
const text = fs.readFileSync(mainJs, "utf8");
|
||||
if (text.includes('const webProfile = join(dshHome, "profiles", "web")')) {
|
||||
already = true;
|
||||
continue;
|
||||
}
|
||||
if (!WEB_PROFILE_RESOLVER_RE.test(text)) {
|
||||
missing = true;
|
||||
continue;
|
||||
}
|
||||
fs.writeFileSync(mainJs, text.replace(WEB_PROFILE_RESOLVER_RE, WEB_PROFILE_RESOLVER), "utf8");
|
||||
changed = true;
|
||||
}
|
||||
return { changed, already: already && !changed, missing: missing && !changed && !already };
|
||||
}
|
||||
|
||||
/** Electron 桌面读 Web profile 时关掉远程配对页,避免一启动卡在 pairing。 */
|
||||
export function ensureDesktopRemoteUiOff(dshHome) {
|
||||
const home = dshHome || process.env.DSH_HOME || "";
|
||||
if (!home) return { changed: false };
|
||||
const patchFile = path.join(home, "profiles", "web", "cordis.patch.yml");
|
||||
if (!isFile(patchFile)) return { changed: false, missing: true };
|
||||
const text = fs.readFileSync(patchFile, "utf8");
|
||||
if (/^\s*-\s*id:\s*web-ui-remote-web-ui\b/m.test(text)) {
|
||||
if (/-\s*id:\s*web-ui-remote-web-ui[\s\S]*?disabled:\s*true/.test(text)) {
|
||||
return { changed: false, already: true };
|
||||
}
|
||||
}
|
||||
const block =
|
||||
"\n# [dsh-purge] official desktop shares this profile; keep remote pairing off in the exe window\n" +
|
||||
"- id: web-ui-remote-web-ui\n" +
|
||||
" disabled: true\n";
|
||||
if (text.includes("web-ui-remote-web-ui")) return { changed: false, already: true };
|
||||
fs.writeFileSync(patchFile, text.replace(/\s*$/, "\n") + block, "utf8");
|
||||
return { changed: true };
|
||||
}
|
||||
|
||||
export function alignOfficialDesktopProfile(input = {}) {
|
||||
const exe =
|
||||
input.exe ||
|
||||
officialExeFromProcess() ||
|
||||
findDesktopAppExecutable() ||
|
||||
"";
|
||||
if (!exe || !isOfficialHarnessExecutable(exe)) return { changed: false };
|
||||
const appDir = input.appDir || appDirForExecutable(exe);
|
||||
const shell = useWebProfileInOfficialShell(appDir);
|
||||
const remote = ensureDesktopRemoteUiOff(input.dshHome || process.env.DSH_HOME || "");
|
||||
return {
|
||||
changed: Boolean(shell.changed || remote.changed),
|
||||
shell,
|
||||
remote,
|
||||
appDir,
|
||||
exe,
|
||||
};
|
||||
}
|
||||
|
||||
function dshHomeForRelaunch() {
|
||||
const current = String(process.env.DSH_HOME || "").replace(/[\\/]+$/, "");
|
||||
if (!current) return "";
|
||||
|
||||
+46
-17
@@ -1,6 +1,8 @@
|
||||
import { ownServerNote } from "./net-scope.js";
|
||||
import { CAPABILITY_SECTION, capabilityProtocolText } from "./capability-protocol.js";
|
||||
|
||||
export const GLOBAL_PROMPT_ORDER = -100000;
|
||||
export { CAPABILITY_SECTION, capabilityProtocolText };
|
||||
export const IDENTITY_CARD_PREFIX = "WHO YOU ARE (highest priority";
|
||||
|
||||
const PERSONA_PREFIX_NAMES = new Set([
|
||||
@@ -173,13 +175,13 @@ function injectNeedles(inject) {
|
||||
}
|
||||
|
||||
/** 每次组装都把提示词放到最前。后面段落里的同一份正文拆掉,避免再拼一份。 */
|
||||
function leadWithInject(sections, inject) {
|
||||
function leadWithInject(sections, inject, protocol = "") {
|
||||
const text = String(inject || "").trim();
|
||||
if (!text) return sections;
|
||||
const proto = String(protocol || "").trim();
|
||||
const needles = injectNeedles(text);
|
||||
const rest = [];
|
||||
for (const section of sections) {
|
||||
if (!section || section.name === "dsh-purge") continue;
|
||||
if (!section || section.name === "dsh-purge" || section.name === CAPABILITY_SECTION) continue;
|
||||
const body = typeof section.text === "string" ? section.text : "";
|
||||
if (!needles.some((needle) => body.includes(needle))) {
|
||||
rest.push(section);
|
||||
@@ -191,12 +193,31 @@ function leadWithInject(sections, inject) {
|
||||
if (!next) continue;
|
||||
rest.push({ ...section, text: next });
|
||||
}
|
||||
return [{ name: "dsh-purge", text, order: GLOBAL_PROMPT_ORDER, interpolate: false }, ...rest];
|
||||
const head = [];
|
||||
if (proto) {
|
||||
head.push({
|
||||
name: CAPABILITY_SECTION,
|
||||
text: proto,
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
interpolate: false,
|
||||
});
|
||||
}
|
||||
if (text) {
|
||||
head.push({
|
||||
name: "dsh-purge",
|
||||
text,
|
||||
order: GLOBAL_PROMPT_ORDER + (proto ? 1 : 0),
|
||||
interpolate: false,
|
||||
});
|
||||
}
|
||||
return [...head, ...rest];
|
||||
}
|
||||
|
||||
/** 红队预设里要留下来的操作说明起点。这句前面的「你是红队指挥」身份句丢掉。 */
|
||||
/** 红队预设里要留下来的操作说明起点。 */
|
||||
const REDTEAM_OPS_MARK = "## 运行环境前提";
|
||||
/** 旧标题;现为「指挥职责」。历史预设仍可能用旧名。 */
|
||||
const REDTEAM_LEAD_IDENTITY = "## 你是谁、你不做什么";
|
||||
const REDTEAM_LEAD_DUTY = "## 指挥职责";
|
||||
const REDTEAM_OPS_NOTE = "身份和规则以上面的提示词为准。下面只补充红队调度步骤,不改写上面的身份。";
|
||||
|
||||
function redteamOpsBody(text) {
|
||||
@@ -206,21 +227,23 @@ function redteamOpsBody(text) {
|
||||
return raw.slice(at).trim();
|
||||
}
|
||||
|
||||
/** 红队操作稿里的「你是谁」会盖住用户提示词,模型会把提示词当成用户消息里的注入。 */
|
||||
/**
|
||||
* 以前整段删掉「你是谁、你不做什么」,会把「只派活 / 自己不动手」指挥硬约束一起删掉,
|
||||
* 模型就自己动手、不再派 subagent——比原版红队差、也像“新版本不会派子代理”。
|
||||
* 身份冲突已由 inject 置顶处理;这里只保留操作稿,不再砍指挥职责。
|
||||
*/
|
||||
export function withoutRedteamLeadIdentity(text) {
|
||||
const raw = String(text || "");
|
||||
const start = raw.indexOf(REDTEAM_LEAD_IDENTITY);
|
||||
if (start < 0) return raw.trim();
|
||||
const rest = raw.slice(start + REDTEAM_LEAD_IDENTITY.length);
|
||||
const next = rest.search(/\n## /);
|
||||
const end = next < 0 ? raw.length : start + REDTEAM_LEAD_IDENTITY.length + next;
|
||||
return (raw.slice(0, start) + raw.slice(end)).replace(/\n{3,}/g, "\n\n").trim();
|
||||
return String(text || "").trim();
|
||||
}
|
||||
|
||||
function redteamProcedure(text) {
|
||||
const ops = redteamOpsBody(text);
|
||||
if (ops == null) return null;
|
||||
const body = withoutRedteamLeadIdentity(ops);
|
||||
let body = withoutRedteamLeadIdentity(ops);
|
||||
// 旧预设标题改成指挥职责,避免以后再被当成「身份句」误删。
|
||||
if (body.includes(REDTEAM_LEAD_IDENTITY) && !body.includes(REDTEAM_LEAD_DUTY)) {
|
||||
body = body.split(REDTEAM_LEAD_IDENTITY).join(`${REDTEAM_LEAD_DUTY}(硬约束)`);
|
||||
}
|
||||
if (!body) return REDTEAM_OPS_NOTE;
|
||||
if (body.includes(REDTEAM_OPS_NOTE)) return body;
|
||||
return `${REDTEAM_OPS_NOTE}\n\n${body}`;
|
||||
@@ -531,6 +554,7 @@ function normalizeRewriteOptions(fallbackInject, options) {
|
||||
fallbackInject: typeof fallbackInject.fallbackInject === "string" ? fallbackInject.fallbackInject : "",
|
||||
dropMnemon: fallbackInject.dropMnemon !== false,
|
||||
dropPurgeAfterFold: fallbackInject.dropPurgeAfterFold !== false,
|
||||
capabilityProtocol: fallbackInject.capabilityProtocol !== false,
|
||||
context: fallbackInject.context,
|
||||
roleText: typeof fallbackInject.roleText === "string" ? fallbackInject.roleText : "",
|
||||
cardText: typeof fallbackInject.cardText === "string" ? fallbackInject.cardText : "",
|
||||
@@ -540,6 +564,7 @@ function normalizeRewriteOptions(fallbackInject, options) {
|
||||
fallbackInject: typeof fallbackInject === "string" ? fallbackInject : "",
|
||||
dropMnemon: options?.dropMnemon !== false,
|
||||
dropPurgeAfterFold: options?.dropPurgeAfterFold !== false,
|
||||
capabilityProtocol: options?.capabilityProtocol !== false,
|
||||
context: options?.context,
|
||||
roleText: typeof options?.roleText === "string" ? options.roleText : "",
|
||||
cardText: typeof options?.cardText === "string" ? options.cardText : "",
|
||||
@@ -621,15 +646,19 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
}
|
||||
|
||||
const redteam = isRedteamSession(opts.context);
|
||||
const redteamChild = redteam && isRedteamSubagent(opts.context);
|
||||
const rawInject = modePromptText(collectInjectText(purge, opts.fallbackInject), redteam);
|
||||
const injectText = withOwnServers(rawInject);
|
||||
const protocol = opts.capabilityProtocol === false
|
||||
? ""
|
||||
: capabilityProtocolText({ redteam, redteamChild, enabled: true });
|
||||
// #29: 不要把上一条 system/message 全文钉回 sections。
|
||||
// 默认留下 dsh-purge 段。0.1.5 在 waterfall 之后若 complete:true,只认这段把注入抄进最终提示词;
|
||||
// 提前折进 persona 再删掉本段,重启加载该逻辑后注入会丢。
|
||||
const folded = opts.dropPurgeAfterFold ? foldInjectIntoPersona(rest, injectText) : rest;
|
||||
const extras = withoutHardcodedExec(opts.dropPurgeAfterFold
|
||||
? purge.filter((section) => section.name !== "dsh-purge")
|
||||
: purge);
|
||||
? purge.filter((section) => section.name !== "dsh-purge" && section.name !== CAPABILITY_SECTION)
|
||||
: purge.filter((section) => section.name !== CAPABILITY_SECTION));
|
||||
let sections = [...folded, ...extras].map((section) => {
|
||||
if (!section || typeof section.text !== "string") return section;
|
||||
const cut = modePromptText(section.text, redteam);
|
||||
@@ -642,7 +671,7 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
? insertRoleSection(insertCardSection(sections, opts.cardText), opts.roleText)
|
||||
: withOps;
|
||||
}
|
||||
assembled.sections = sanitizeAssemblySections(leadWithInject(sections, injectText));
|
||||
assembled.sections = sanitizeAssemblySections(leadWithInject(sections, injectText, protocol));
|
||||
if (!Array.isArray(assembled.contexts)) assembled.contexts = [];
|
||||
if (!Array.isArray(assembled.tools)) assembled.tools = [];
|
||||
return assembled;
|
||||
|
||||
+54
-1
@@ -12,6 +12,7 @@ import {
|
||||
isRedteamSession,
|
||||
rewritePromptAssembly,
|
||||
} from "./identity.js";
|
||||
import { capabilityProtocolText, CAPABILITY_SECTION } from "./capability-protocol.js";
|
||||
import { installSubagentRoleCapture, resolveSubagentRoleText } from "./redteam/role-section.js";
|
||||
import * as rewind from "./rewind.js";
|
||||
import * as continueRetry from "./continue-retry.js";
|
||||
@@ -43,6 +44,8 @@ const DEFAULTS = {
|
||||
refusalRecover: true,
|
||||
refusalRecoverMax: 2,
|
||||
refusalRecoverText: "",
|
||||
// Codex 风格:教模型主动发现 skill / MCP;不改官方注册与工具面。
|
||||
capabilityProtocol: true,
|
||||
};
|
||||
|
||||
const log = (config, ...args) => {
|
||||
@@ -191,7 +194,7 @@ async function ensureRestartReady() {
|
||||
export function registerPromptSections(ctx, config, _injectFile) {
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge",
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
order: GLOBAL_PROMPT_ORDER + 1,
|
||||
interpolate: false,
|
||||
text: (context) => {
|
||||
if (!injectAllowedNow(config)) return "";
|
||||
@@ -199,6 +202,23 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
},
|
||||
});
|
||||
|
||||
if (config.capabilityProtocol !== false) {
|
||||
ctx.systemPrompt.section({
|
||||
name: CAPABILITY_SECTION,
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
interpolate: false,
|
||||
text: (context) => {
|
||||
if (!injectAllowedNow(config)) return "";
|
||||
const redteam = isRedteamSession(context);
|
||||
return capabilityProtocolText({
|
||||
redteam,
|
||||
redteamChild: redteam && context?.agent?.session?.header?.origin === "subagent",
|
||||
enabled: true,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const postPrompt = typeof config.postPrompt === "string" ? config.postPrompt.trim() : "";
|
||||
if (!postPrompt) return;
|
||||
if (!Number.isFinite(config.postPromptOrder) || config.postPromptOrder <= GLOBAL_PROMPT_ORDER) {
|
||||
@@ -247,6 +267,7 @@ function rewriteLiveAssembly(config, assembled, context) {
|
||||
fallbackInject: inject,
|
||||
dropMnemon: config.stripMnemon !== false,
|
||||
dropPurgeAfterFold: false,
|
||||
capabilityProtocol: config.capabilityProtocol !== false,
|
||||
context,
|
||||
roleText: redteam ? resolveSubagentRoleText(context) : "",
|
||||
});
|
||||
@@ -354,6 +375,22 @@ function shimNeedsPatch(state) {
|
||||
|
||||
async function settleInstalledPatches(config, ctx) {
|
||||
try { core.rememberUnpackedArchive(); } catch { /* 没有官方安装目录时不必记归档 */ }
|
||||
try {
|
||||
const shell = core.alignOfficialShellProfile({ dshHome: process.env.DSH_HOME || "" });
|
||||
if (shell.changed) {
|
||||
bootFullQuit = true;
|
||||
log(config, "official desktop now follows the web profile");
|
||||
try {
|
||||
hostctl.scheduleRestart(null, ctx);
|
||||
} catch (e) {
|
||||
log(config, "restart after web profile switch failed:", String(e && e.message ? e.message : e));
|
||||
return "restart-failed";
|
||||
}
|
||||
return "full-quit";
|
||||
}
|
||||
} catch (e) {
|
||||
log(config, "align web profile skipped:", String(e && e.message ? e.message : e));
|
||||
}
|
||||
if (officialUpdate.upgradeMarkerExists(process.execPath)) {
|
||||
const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, upgrade: true });
|
||||
if (!upgraded.ok) {
|
||||
@@ -486,6 +523,11 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
if (blocked) return { kind: "error", text: blocked.error };
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const shell = core.alignOfficialShellProfile({
|
||||
dshHome: state.dsh_home || process.env.DSH_HOME || "",
|
||||
exe: handoff?.exe,
|
||||
appDir: handoff?.appDir,
|
||||
});
|
||||
const shimResult = await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const lines = report.map((r) => {
|
||||
@@ -497,6 +539,14 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
lines.push(` · ${dir} → ${typeof st === "object" ? JSON.stringify(st) : st}`);
|
||||
}
|
||||
lines.push(` cmd-flash=${flash.entry} phase-1=${flash.phase1} ok=${flash.ok}`);
|
||||
if (shell.changed || shell.shell?.already || shell.shell?.changed) {
|
||||
lines.push(
|
||||
"",
|
||||
shell.changed
|
||||
? "官方桌面已改为读取 profiles/web(与 Web 端同一套渠道/插件配置)。"
|
||||
: "官方桌面已对齐 profiles/web。",
|
||||
);
|
||||
}
|
||||
if (scrubbed.length) {
|
||||
lines.push("", "Desktop in-bin .bak scrub:");
|
||||
for (const row of scrubbed) lines.push(` ✓ ${row.dir} → ${row.cleaned.join(", ")}`);
|
||||
@@ -508,6 +558,9 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
if (swapped?.renamed || swapped?.pending) {
|
||||
lines.push("", "补丁已写入。请在设置页点「重启」,客户端会自己重新打开。");
|
||||
}
|
||||
} else if (shell.changed) {
|
||||
lines.push("", "已切换到 profiles/web。请在设置页点「重启」,客户端会自己重新打开。");
|
||||
try { hostctl.scheduleRestart(null, null); } catch { /* 设置页再点重启即可 */ }
|
||||
}
|
||||
return { kind: "success", text: lines.join("\n") };
|
||||
}
|
||||
|
||||
+71
-3
@@ -177,6 +177,69 @@ function renderToolsPackage(text) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自愈:指挥职责标题 + 在 Agent Teams profile 下强制重新启用 classic subagent。
|
||||
* 不整份覆盖用户预设,只改会让派活失败的几处。
|
||||
*/
|
||||
function repairDelegation(text) {
|
||||
let next = String(text || "")
|
||||
let changed = false
|
||||
if (next.includes("## 你是谁、你不做什么")) {
|
||||
next = next.split("## 你是谁、你不做什么").join("## 指挥职责(硬约束)")
|
||||
changed = true
|
||||
}
|
||||
const mark = "**必须用原生 `subagent` 工具派活**"
|
||||
if (next.includes("## 指挥职责") && !next.includes(mark)) {
|
||||
const needle = "`redteam_session_info`。"
|
||||
const at = next.indexOf(needle)
|
||||
if (at >= 0) {
|
||||
next =
|
||||
next.slice(0, at + needle.length) +
|
||||
"\n " + mark +
|
||||
";不要改用 Agent Teams 的 `spawn_teammate`(红队角色稿 / 并发闸门 / 叶子约束都挂在 `subagent` 路径上)。" +
|
||||
next.slice(at + needle.length)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
for (const id of [
|
||||
"tool-subagent-control",
|
||||
"tool-subagent-list-agents",
|
||||
"tool-subagent",
|
||||
"tool-subagent-fork",
|
||||
]) {
|
||||
const idLine = `- id: ${id}`
|
||||
let from = 0
|
||||
while (from < next.length) {
|
||||
const at = next.indexOf(idLine, from)
|
||||
if (at < 0) break
|
||||
const endId = at + idLine.length
|
||||
const ch = next[endId] || "\n"
|
||||
// 避免 tool-subagent 误匹配 tool-subagent-control / fork / codex
|
||||
if (ch !== "\n" && ch !== "\r" && ch !== " " && ch !== "\t") {
|
||||
from = endId
|
||||
continue
|
||||
}
|
||||
const after = endId
|
||||
const rest = next.slice(after)
|
||||
const endRel = rest.search(/\n[ \t]*- id: /)
|
||||
const block = endRel < 0 ? rest : rest.slice(0, endRel)
|
||||
if (/disabled:\s*false/.test(block)) break
|
||||
if (/disabled:\s*true/.test(block)) {
|
||||
const patched = block.replace(/disabled:\s*true/, "disabled: false")
|
||||
next = next.slice(0, after) + patched + next.slice(after + block.length)
|
||||
changed = true
|
||||
break
|
||||
}
|
||||
const indentMatch = /\n([ \t]+)name:/.exec(block)
|
||||
const indent = indentMatch ? indentMatch[1] : " "
|
||||
next = next.slice(0, after) + `\n${indent}disabled: false` + next.slice(after)
|
||||
changed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return { text: next, changed }
|
||||
}
|
||||
|
||||
/** 包内锚点门相对预设模板的标记,用来给已有用户预设补一行,不整份覆盖。 */
|
||||
const ANCHOR_ROW_MARK = '- id: anchor-gate'
|
||||
|
||||
@@ -254,8 +317,9 @@ export function installPreset(options = {}) {
|
||||
}
|
||||
const rendered = renderSkillsDir(text)
|
||||
const tools = renderToolsPackage(rendered.text)
|
||||
const next = tools.text
|
||||
if (rendered.changed || tools.changed) {
|
||||
const delegation = repairDelegation(tools.text)
|
||||
const next = delegation.text
|
||||
if (rendered.changed || tools.changed || delegation.changed) {
|
||||
writeFileSync(presetFile, next.replace(/\r\n/g, '\n').replace(/\r/g, '\n'), 'utf8')
|
||||
log(
|
||||
(rendered.changed
|
||||
@@ -264,7 +328,10 @@ export function installPreset(options = {}) {
|
||||
: '预设里的技能目录写成了本机绝对路径')
|
||||
+ ',已改为 dshHomePath(\'redteam/skills\')'
|
||||
: '')
|
||||
+ (tools.changed ? (rendered.changed ? ';' : '') + '工具包名已改为 dsh-purge/redteam/tools' : ''),
|
||||
+ (tools.changed ? (rendered.changed ? ';' : '') + '工具包名已改为 dsh-purge/redteam/tools' : '')
|
||||
+ (delegation.changed
|
||||
? ((rendered.changed || tools.changed) ? ';' : '') + '已修复指挥派活约束 / 重新启用 subagent'
|
||||
: ''),
|
||||
)
|
||||
}
|
||||
const anchor = syncAnchorGate(target)
|
||||
@@ -273,6 +340,7 @@ export function installPreset(options = {}) {
|
||||
const repaired = [
|
||||
rendered.changed ? rendered.reason : null,
|
||||
tools.changed ? 'tools-package' : null,
|
||||
delegation.changed ? 'delegation' : null,
|
||||
anchor === 'inserted' ? 'anchor-gate' : null,
|
||||
anchor === 'updated' ? 'anchor-script' : null,
|
||||
].filter(Boolean)
|
||||
|
||||
Reference in new issue
Block a user