diff --git a/README.md b/README.md index abb04d3..1fa23f4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

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

-

Version 1.1.14

+

Version 1.1.15

Local official DeepSeek Harness cybersecurity red-team plugin. Evaluate and adjust host safety policy on a controlled local install; swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐ @@ -25,6 +25,8 @@ English | 中文

+> **After Apply, you must click Restart or the inject does not take effect.** Apply only writes the prompt and patches to disk. This process is still the old one. When the host has restarted, start a new chat — that is when the inject enters the session. Apply alone looks like nothing was injected. + > Aligned with **dsh 0.1.5-rc.2** (Node.js **≥18**; Windows no-flash import hooks need **Node ≥22** `registerHooks`, older Node still gets file-level `windowsHide` patches). On other versions, unmatched originals stay pending or skipped. Nothing is rewritten blindly. Also accepts the 0.1.2 community `dsh-persona text` field and `dsh-mnemon` v0 session `summary`. After install you still need **Apply + restart**. > > Hub page is for reading only: [DeepSeek Harness Hub](https://deepseek.stream/plugins/dsh-purge). Do not install via `deepseek.stream/api/plugins/download?...`. @@ -208,13 +210,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv

🌐 Open Hub page  ·  - 🚀 Install in desktop client + 🚀 Install in desktop client

🔗 **Raw protocol URL:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.15&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz ```
@@ -230,7 +232,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.1.14', + version: '1.1.15', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz', @@ -249,7 +251,7 @@ export function installDshPurgeToDesktop() { **HTML link:** ```html - + 🚀 Install in desktop client ``` @@ -260,7 +262,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | Plugin id | | name | `dsh-purge` | Display name | -| version | `1.1.14` | Semver | +| version | `1.1.15` | Semver | | repo | `YuJunZhiXue/dsh-purge` | GitHub repo | | permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub source archive | diff --git a/README.zh-CN.md b/README.zh-CN.md index 47c7040..20db43f 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@

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

-

Version 1.1.14

+

Version 1.1.15

本机官方 DeepSeek Harness 网络安全红队评测插件。在受控本机里评测并调整宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -25,6 +25,8 @@ English | 中文

+> **点「应用」之后,必须再点「重启」,注入才会生效。** 「应用」只把提示词和补丁写进文件,当前这个进程还是旧的。重启完成、宿主重新打开后,新开一轮对话,注入才进当前会话。只点应用、不重启,看起来就像没注入。 + > 对准 **dsh 0.1.5-rc.2**(Node.js **≥18**;Windows 无闪窗需要 **Node ≥22** 的 `registerHooks`,更低版本仍用文件级 `windowsHide`)。其它版本对不上的原文会显示待应用或跳过,不会乱改文件。兼容 0.1.2 社区预设的 `text` 字段,以及 `dsh-mnemon` 旧会话的 v0 `summary`。装完必须 **应用 + 重启**。 > > 插件市场只看介绍:[DeepSeek Harness Hub](https://deepseek.stream/plugins/dsh-purge)。不要用 `deepseek.stream/api/plugins/download?...` 安装。 @@ -208,13 +210,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv

🌐 打开插件市场页  ·  - 🚀 唤起客户端一键安装 + 🚀 唤起客户端一键安装

🔗 **原生协议链接:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.15&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz ```
@@ -230,7 +232,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.1.14', + version: '1.1.15', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz', @@ -249,7 +251,7 @@ export function installDshPurgeToDesktop() { **HTML 静态链接方式:** ```html - + 🚀 唤起客户端一键安装 ``` @@ -260,7 +262,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | 插件唯一标识符 | | name | `dsh-purge` | 插件展示名称 | -| version | `1.1.14` | 语义化版本号 | +| version | `1.1.15` | 语义化版本号 | | repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 | | permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 | diff --git a/lib/core.js b/lib/core.js index 7e239a8..367ae55 100644 --- a/lib/core.js +++ b/lib/core.js @@ -3577,11 +3577,16 @@ function patchApplied(text, patch) { return false; } +function cloneRegExp(pattern, global) { + let flags = String(pattern.flags || "").replace("g", ""); + if (global) flags += "g"; + return new RegExp(pattern.source, flags); +} + function matchesPattern(hay, pattern) { if (pattern instanceof RegExp) { - const re = pattern.global ? pattern : new RegExp(pattern.source, pattern.flags); - re.lastIndex = 0; - return re.test(hay); + // 不复用带 g 的模块级正则。test() 会留下 lastIndex,下一次替换从中间开始,等于没匹配到。 + return cloneRegExp(pattern, false).test(hay); } return hay.includes(asLf(pattern)); } @@ -3655,8 +3660,10 @@ function applyReplacementsToText(text, patch, fp = "") { if (yaml && isBareIdentityNeedle(pattern)) continue; // 正则 pattern:用于自匹配型替换(产物包含原 pattern,如 timeoutMs 追加 0)。 if (pattern instanceof RegExp) { - const re = pattern.global ? pattern : new RegExp(pattern.source, pattern.flags + "g"); + const re = cloneRegExp(pattern, true); + re.lastIndex = 0; if (!re.test(out)) continue; + re.lastIndex = 0; // 用字符串形态调用:保留 $1..$9 展开语义(回调形态会把 "$1" 当字面量写进文件)。 const next = out.replace(re, asLf(replace)); if (next === out) continue; diff --git a/lib/identity.js b/lib/identity.js index 13a0afc..b663225 100644 --- a/lib/identity.js +++ b/lib/identity.js @@ -268,8 +268,9 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options = const injectText = collectInjectText(purge, opts.fallbackInject); // #29: 不要把上一条 system/message 全文钉回 sections。 - // 「历史里已有完整注入就不再折一份」由 foldInjectIntoPersona 的 includes 幂等满足。 - const folded = foldInjectIntoPersona(rest, injectText); + // 默认留下 dsh-purge 段。0.1.5 在 waterfall 之后若 complete:true,只认这段把注入抄进最终提示词; + // 提前折进 persona 再删掉本段,重启加载该逻辑后注入会丢。 + const folded = opts.dropPurgeAfterFold ? foldInjectIntoPersona(rest, injectText) : rest; const extras = opts.dropPurgeAfterFold ? purge.filter((section) => section.name !== "dsh-purge") : purge; diff --git a/lib/index.js b/lib/index.js index d42a4c8..3ecb448 100644 --- a/lib/index.js +++ b/lib/index.js @@ -230,7 +230,7 @@ function installIdentityOverride(ctx, config = {}) { return rewritePromptAssembly(assembled, { fallbackInject: inject, dropMnemon: config.stripMnemon !== false, - dropPurgeAfterFold: true, + dropPurgeAfterFold: false, context, }); }; @@ -1110,6 +1110,9 @@ function installWebServer(ctx, cfg) { }); return; } + if (typeof body?.content === "string") { + await core.saveOverrideContent(state.dsh_home, body.content); + } await core.backupAll(state.ai_base); const report = await core.applyPatches(state.ai_base); const override = await core.readOverrideForUi(state.dsh_home); diff --git a/package.json b/package.json index c66bcd8..c28da18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-purge", - "version": "1.1.14", + "version": "1.1.15", "description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐", "type": "module", "main": "lib/index.js", diff --git a/release-notes.md b/release-notes.md index 63bab70..c3b1883 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,21 +1,17 @@ -# 1.1.14 +# 1.1.15 ## 中文 -- 回退清队列时会等 `updateQueue` 结束。条目已经不在时不再变成未处理的拒绝,避免把宿主带崩(#32)。 -- 兜底回退按钮成功后会记下这次的时间。1.2 秒后的轮询不会把同一次回退再打开、再回填一遍(#33)。 -- 回填的是还没结束的那一句时,切点改到最后一个已闭合回合。不再多丢上一整轮。回合还在进行、8 秒内等不到结束时,仍然直接失败,不会按不完整日志去切(#34)。 -- bash 超时补丁改成整行正则,并把已经多写出来的 0 收回到 10 分钟。每次启动不再给超时再补一个 0(#22,#31)。 -- 补丁替换支持正则,`$1` 会展开。bundle 布局清洗完成后能认出 `persona: ""`,面板不再一直显示待应用。#39 改为可选。跳过说明改为「当前版本不需要或组件未安装」。 -- 正式版已经追上的测试版不再出现在版本列表里。提交号对不上时,按本机版本号标「当前」。 -- phase-1 不再清空 runtime context,也不改消息白名单。梁神和官方插件的消息照旧保留。 +- 设置页点「应用」会把输入框里的提示词写入 `prompt-inject.md`。以前只检查有没有字,重启后读的还是旧文件,所以注入像没生效。 +- 带 `complete: true` 的预设在重启后不再丢掉 `dsh-purge` 注入段。点「应用」之后必须再点「重启」,宿主重新打开后新开一轮对话,注入才进入当前会话。 +- bash 超时补丁不再和状态检查共用同一条正则。点「应用」会把 60 秒写成 10 分钟,不会一直停在待应用(#35)。 +- 去掉点了也不变的「启用 fetch」补丁,后面的编号依次前移。没装 `dsh-web-fetch-http` 时不再占着一条待应用。 +- README 开头写明必须应用并重启。工作原理改成流程图,去掉 0.1.5 适配表和生效验证。 ## English -- Rewind waits for `updateQueue` to finish. A queue item that is already gone no longer becomes an unhandled rejection that can take down the host (#32). -- The fallback rewind button records this rewind’s timestamp. The 1.2s poll does not open and refill the same rewind a second time (#33). -- When the text being restored belongs to a turn that is still open, the fork point is the last closed turn. The previous completed turn is no longer dropped. If that turn is still running and does not close within 8 seconds, rewind still fails instead of cutting an incomplete log (#34). -- The bash timeout patch is now one whole-line regular expression, and values that grew extra zeros are pulled back to 10 minutes. Startup no longer appends another zero (#22, #31). -- Patch replacement accepts regular expressions, and `$1` expands. A finished bundle-layout clean matches `persona: ""`, so the panel does not stay on pending. #39 is optional. The skipped hint now says the patch is not needed for this version, or the component is not installed. -- Beta versions already covered by the current stable release are hidden from the version list. When the commit does not match, 「当前」follows the local version number. -- Phase-1 no longer clears runtime context or the message allowlist. 梁神 and official plugin messages stay as they are. +- Apply on the settings page writes the prompt box into `prompt-inject.md`. It used to only check that the box was not empty, so after a restart the host still read the old file and the inject looked like it never happened. +- Presets with `complete: true` no longer drop the `dsh-purge` inject section after a restart. After Apply you must click Restart. When the host is back, start a new chat; that is when the inject enters the session. +- The bash timeout patch no longer shares one regular expression with the status check. Apply now writes 60 seconds as 10 minutes instead of staying on pending (#35). +- The fetch-enable patch that stayed pending is gone, and later patch numbers move up by one. A missing `dsh-web-fetch-http` package no longer occupies a pending row. +- The README now says at the top that Apply must be followed by Restart. How it works is a flowchart. The 0.1.5 notes table and the verify list are removed. diff --git a/scripts/test-identity-assembly.mjs b/scripts/test-identity-assembly.mjs index cece8d0..8dc6b01 100644 --- a/scripts/test-identity-assembly.mjs +++ b/scripts/test-identity-assembly.mjs @@ -102,4 +102,17 @@ const again = rewritePromptAssembly( ); assert.equal((render(again).match(/Little Code Sauce/g) || []).length, 1); +const kept = rewritePromptAssembly( + { + sections: [ + { name: "deployment:persona-prefix", text: persona }, + ], + }, + { fallbackInject: inject, dropPurgeAfterFold: false }, +); +const purge = (kept.sections || []).filter((section) => section.name === "dsh-purge"); +assert.equal(purge.length, 1); +assert.match(purge[0].text, /Little Code Sauce/); +assert.equal((render(kept).match(/Little Code Sauce/g) || []).length, 1); + console.log("ok: #29 pin snowball is gone");