From d2578b79c3ffa17370d7f751aefdaf54cd299fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= Date: Mon, 21 Sep 2026 10:35:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=8B=E8=AF=95=E7=89=88=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=B3=BB=E7=BB=9F=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=8F=AA?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E4=B8=80=E6=AC=A1=EF=BC=8C=E5=B9=B6=E5=86=99?= =?UTF-8?q?=E6=B8=85=201.1.11=20=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- README.md | 10 +++++++++- README.zh-CN.md | 10 +++++++++- lib/core.js | 2 ++ lib/identity.js | 42 ++++++++++++++++++++++++++++++++++++++---- lib/index.js | 3 ++- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a589229..81d3910 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)

-

Version 1.1.10

+

Version 1.1.12-beta.1

Local official DeepSeek Harness cybersecurity red-team plugin: evaluate and harden host safety policy in a controlled local install; swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐ @@ -755,6 +755,14 @@ If nothing is found, set `DSH_BASE` / `DSH_DESKTOP_INSTALL`. No files are change - Skill import stays on beta: Settings and `/skills` write zip/folder into official `$DSH_HOME/skills` - Stable / Beta columns match official 1.1.11, so you can switch both ways +- Same system-prompt fix as official 1.1.11: inject once per conversation, do not append another「系统提示词」on later steps + +### 1.1.11 + +- Settings splits Stable / Beta into two columns, each with its own list, switch, and rollback. 1.1.10 can reach this by Check update. +- **No Skill import.** Skill stays on beta 1.1.12. +- **Inject the system prompt once per conversation.** The first turn writes the full `prompt-inject`; later steps pin that committed prompt and do not fold it again. +- **Stop a new「系统提示词」card on every step.** With 0.1.5 in-history, a changed assemble appends another `system/message`, so the transcript repeats system prompt → think → tools. Refolding inject every step made later official sections look like a new prompt; emptying inject did the same. After the inject is already in history, this release pins that committed system prompt and does not append a second copy. ### 1.1.11-beta.2 diff --git a/README.zh-CN.md b/README.zh-CN.md index b624b88..ddeacfb 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@

⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)

-

Version 1.1.10

+

Version 1.1.12-beta.1

本机官方 DeepSeek Harness 网络安全红队评测插件:在受控本机环境评测并加固宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -742,6 +742,14 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt - Skill 导入继续只在测试版:设置页和 `/skills` 可导入压缩包或文件夹到官方 `$DSH_HOME/skills` - 正式/测试分栏与 1.1.11 正式版同一套,可来回切换 +- 系统提示词修复与正式版 1.1.11 相同:每个会话只注入一次,后续步骤不再追加「系统提示词」 + +### 1.1.11 + +- 设置页把正式版和测试版左右分开,各自选版本、各自切换和回退。还在 1.1.10 的点「检测更新」就能升到这一版。 +- **没有 Skill 导入。** Skill 只在测试版 1.1.12。 +- **系统提示词每个会话只注入一次。** 第一轮把 `prompt-inject` 完整写进系统提示;之后钉住已经提交的那一份,不再每步重折。 +- **修了聊天里每步都冒出「系统提示词」。** 0.1.5 in-history 只要本步组装结果和上一条不一样,就会再追加一条 `system/message`,时间线就会「思考 → 工具 → 系统提示词」循环。以前每步都把注入重新折进 persona,官方后半段稍有变化就会追加;把注入掏空也不行,渲染少了同样会被当成变化再追加。这一版历史里已经有完整注入后,就钉住那条已提交的系统提示,后续步骤不再追加第二份。 ### 1.1.11-beta.2 diff --git a/lib/core.js b/lib/core.js index 7a51fc6..140bdbe 100644 --- a/lib/core.js +++ b/lib/core.js @@ -3015,6 +3015,8 @@ const NEW_TOOL_PATCHES = [ "\t\t\t...transformed,\n" + "\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, assembled) {\n" + "\t\t\t\tconst sections = assembled.sections || [];\n" + + "\t\t\t\tconst committed = sections.find((s) => s && s.name === \"dsh-purge:committed\");\n" + + "\t\t\t\tif (committed && String(committed.text || \"\").trim()) return [{ ...complete, name: complete.name, text: committed.text }];\n" + "\t\t\t\tconst inject = sections.filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\")).map((s) => String(s.text || \"\")).filter((t) => t.length > 0).join(\"\\n\\n\");\n" + "\t\t\t\tconst folded = sections.find((s) => s && s.name === complete.name);\n" + "\t\t\t\tconst base = folded && typeof folded.text === \"string\" ? { ...complete, text: folded.text } : { ...complete };\n" + diff --git a/lib/identity.js b/lib/identity.js index c7ed2d6..81fae39 100644 --- a/lib/identity.js +++ b/lib/identity.js @@ -175,10 +175,26 @@ export function promptAlreadyInjected(existing, injectText) { return String(existing || "").includes(inject); } -export function shouldInjectPrompt(_context, _injectOnce = true, _injectText = "") { - // 0.1.5 in-history:渲染少了注入就会再追加一条 system/message。 - // 用「最后一条是否含注入」决定本步掏空注入,会 A/B 死循环。每步都必须留下完整注入。 - return true; +export function lastInjectedSystemPrompt(context, injectText) { + const inject = String(injectText || "").trim(); + if (!inject) return ""; + const events = eventList(context?.agent?.session || context?.session); + let last = ""; + for (const event of events) { + if (event?.type !== "system/message") continue; + const text = messageText(event.data?.message || event.data).trim(); + if (text && promptAlreadyInjected(text, inject)) last = text; + } + return last; +} + +export function shouldInjectPrompt(context, _injectOnce = true, injectText = "") { + const inject = String(injectText || "").trim(); + if (!inject) return false; + // 历史里已经有完整注入就不要再折一份。0.1.5 in-history 只要渲染结果和上一条 + // system/message 不同就会再追加,聊天里就会每步都冒出「系统提示词」。 + // 掏空注入也不行:渲染少了注入同样会被当成变化再追加,形成 A/B。 + return !lastInjectedSystemPrompt(context, inject); } export function isMnemonPluginMessage(message) { @@ -198,15 +214,26 @@ function normalizeRewriteOptions(fallbackInject, options) { fallbackInject: typeof fallbackInject.fallbackInject === "string" ? fallbackInject.fallbackInject : "", dropMnemon: fallbackInject.dropMnemon !== false, dropPurgeAfterFold: fallbackInject.dropPurgeAfterFold !== false, + context: fallbackInject.context, }; } return { fallbackInject: typeof fallbackInject === "string" ? fallbackInject : "", dropMnemon: options?.dropMnemon !== false, dropPurgeAfterFold: options?.dropPurgeAfterFold !== false, + context: options?.context, }; } +function pinCommittedSystemPrompt(sections, committed) { + const names = sections.map((section) => String(section?.name || "")); + const hasPrefix = names.some((name) => PERSONA_PREFIX_NAMES.has(name)); + const target = hasPrefix + ? names.find((name) => PERSONA_PREFIX_NAMES.has(name)) + : names.find((name) => PERSONA_LEGACY_NAMES.has(name)); + return [{ name: target || "dsh-purge:committed", text: committed }]; +} + // 0.1.5 优先写入 persona-prefix;无 prefix 时写入 legacy persona。 function foldInjectIntoPersona(sections, injectText) { const inject = typeof injectText === "string" ? injectText : ""; @@ -250,6 +277,13 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options = } const injectText = collectInjectText(purge, opts.fallbackInject); + if (!shouldInjectPrompt(opts.context, true, injectText)) { + const committed = lastInjectedSystemPrompt(opts.context, injectText); + if (committed) { + assembled.sections = pinCommittedSystemPrompt([...rest, ...purge], committed); + return assembled; + } + } const folded = foldInjectIntoPersona(rest, injectText); const extras = opts.dropPurgeAfterFold ? purge.filter((section) => section.name !== "dsh-purge") diff --git a/lib/index.js b/lib/index.js index ce1528b..95ce792 100644 --- a/lib/index.js +++ b/lib/index.js @@ -223,7 +223,7 @@ function installIdentityOverride(ctx, config = {}) { if (typeof ctx.on !== "function") return; if (ctx.__dshPurgeAssembleHook) return; ctx.__dshPurgeAssembleHook = true; - const hook = async (_assembly, _context, next) => { + const hook = async (_assembly, context, next) => { const assembled = typeof next === "function" ? await next() : _assembly; const enabled = config.enabled !== false; const inject = enabled ? readInjectFallback() : ""; @@ -231,6 +231,7 @@ function installIdentityOverride(ctx, config = {}) { fallbackInject: inject, dropMnemon: config.stripMnemon !== false, dropPurgeAfterFold: true, + context, }); }; // 只挂一次:挂多次会让同一轮 assemble 折两遍,UI 也会显示两次注入。