diff --git a/README.md b/README.md index 9364916..356a996 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
Version 1.1.46
+Version 1.1.47
Local official DeepSeek Harness cybersecurity red-team plugin. Clean host policy, and ship a built-in drill console. Swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐ @@ -118,7 +118,7 @@ This release supports **DeepSeek Harness 0.2** only (official desktop **0.2.0-rc | Official Harness 0.1.x | Not supported | | Any other version | Unmatched patches stay pending or skipped; do not expect them to work | -The plugin version is **1.1.46**. 1.1.45 is skipped; it has bugs. +The plugin version is **1.1.47**. 1.1.45 is skipped; it has bugs. --- @@ -218,13 +218,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.46&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.47&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 ```Version 1.1.46
+Version 1.1.47
本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -118,7 +118,7 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审 | 官方 Harness 0.1.x | 不支持 | | 其它未列出版本 | 对不上的补丁会显示待应用或跳过,不要指望能用 | -插件版本是 **1.1.46**。1.1.45 有问题,略过。 +插件版本是 **1.1.47**。1.1.45 有问题,略过。 --- @@ -218,13 +218,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.46&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.47&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 ```本声明在进入演练台前必须全文阅读。本项目是非营利开源项目,遵守国家法律法规及所在平台的规范,仅供学习与研究、技术参考。严禁任何主体把本项目用于商业售卖、付费倒卖或黑灰产牟利。
\r\n开发者坚决反对并严禁任何形式的违法犯罪,绝不支持、不鼓励、不协助未授权网络攻击、漏洞利用、数据窃取、非法侵入计算机信息系统,或生成违法违禁内容。任何将本项目用于违法犯罪的行为,均与开发者无关,由行为人依法独立承担全部法律责任。不得以科研、教学、测试、演示或内部学习为由规避下列条款。
\r\ndsh-purge 发布的代码、文档、补丁与默认提示词不是木马、后门、未授权渗透工具、勒索软件、撞库脚本,也不是针对公网或第三方系统的攻击载荷。项目不提供违法内容,也不教唆、组织、协助实施违法犯罪。
\r\n应用补丁、写入、回滚、卸载,都在本机文件和本机进程内完成。这些操作不对任何公网主机或未授权系统进行扫描、探测、入侵或攻击发包,也不得把本机当作跳板。
\r\n插件若开启检测更新,仅可能访问本插件自己的 GitHub 仓库以核对版本。该访问与对第三方系统的网络攻击无关,不能被解释为对外渗透的授权。
\r\n只允许用在你能证明有权处理的环境:本人有权管理的本机官方 Harness;离线的本地合成靶标;所有者已经出具合法书面授权的网络安全演练靶场;合规实验室里的受控环境。书面授权要能对应具体目标、时间和范围。只填写一个单位名称,或只有口头说法,不构成授权。
\r\n未经所有者合法书面授权的目标、公网在线系统、生产业务,以及能源、交通、水利、金融、公共服务、电子政务等关键信息基础设施,都不得作为演练对象。
\r\n《中华人民共和国刑法》第二百八十五条第一款:禁止违反国家规定,侵入国家事务、国防建设、尖端科学技术领域的计算机信息系统。
\r\n同条第二款:禁止侵入前款规定以外的计算机信息系统,或者用其他技术手段,获取该系统中存储、处理或者传输的数据,或者对该系统实施非法控制。
\r\n同条第三款:禁止提供专门用于侵入、非法控制计算机信息系统的程序、工具;明知他人实施侵入、非法控制而为其提供程序、工具,同样禁止。
\r\n第二百八十六条第一款:禁止对计算机信息系统功能进行删除、修改、增加、干扰,造成系统不能正常运行。
\r\n同条第二款:禁止对系统中存储、处理或者传输的数据和应用程序进行删除、修改、增加。
\r\n同条第三款:禁止故意制作、传播计算机病毒等破坏性程序,影响计算机系统正常运行。
\r\n第二百八十七条:禁止利用计算机实施金融诈骗、盗窃、贪污、挪用公款、窃取国家秘密或者其他犯罪。
\r\n第二百八十七条之一第一款第(一)项:禁止设立用于实施诈骗、传授犯罪方法、制作或者销售违禁物品、管制物品等违法犯罪活动的网站、通讯群组。
\r\n同款第(二)项:禁止发布有关制作或者销售毒品、枪支、淫秽物品等违禁物品、管制物品或者其他违法犯罪的信息。
\r\n同款第(三)项:禁止为实施诈骗等违法犯罪活动发布信息。
\r\n第二百八十七条之二:禁止明知他人利用信息网络实施犯罪,仍为其提供技术支持,或者提供广告推广、支付结算等帮助。
\r\n第二百五十三条之一第一款、第三款:禁止向他人出售或者提供公民个人信息;禁止窃取或者以其他方法非法获取公民个人信息。
\r\n《中华人民共和国网络安全法》第十三条第二款:使用网络不得危害网络安全,不得利用网络从事危害国家安全、荣誉和利益,煽动颠覆国家政权、推翻社会主义制度,煽动分裂国家、破坏国家统一,宣扬恐怖主义、极端主义,宣扬民族仇恨、民族歧视,传播暴力、淫秽色情信息,编造、传播虚假信息扰乱经济秩序和社会秩序,以及侵害他人名誉、隐私、知识产权和其他合法权益等活动。
\r\n第十四条:禁止利用网络从事危害未成年人身心健康的活动。
\r\n第二十九条:禁止非法侵入他人网络、干扰他人网络正常功能、窃取网络数据;禁止提供专门用于侵入网络、干扰网络正常功能及防护措施、窃取网络数据的程序、工具;明知他人从事危害网络安全的活动,禁止为其提供技术支持、广告推广、支付结算等帮助。
\r\n第三十三条:公共通信和信息服务、能源、交通、水利、金融、公共服务、电子政务等关键信息基础设施实行重点保护。未获合法授权,不得侵入、干扰或破坏。
\r\n第四十六条:禁止窃取或者以其他非法方式获取个人信息,禁止非法出售或者非法向他人提供个人信息。
\r\n第四十八条:禁止设立用于实施诈骗,传授犯罪方法,制作或者销售违禁物品、管制物品等违法犯罪活动的网站、通讯群组;禁止利用网络发布涉及上述违法犯罪活动的信息。
\r\n第五十条:发送的电子信息、提供的应用软件不得设置恶意程序,不得含有法律、行政法规禁止发布或者传输的信息。
\r\n《中华人民共和国数据安全法》第八条:开展数据处理活动,不得危害国家安全、公共利益,不得损害个人、组织的合法权益。
\r\n第三十二条第一款:收集数据应当采取合法、正当的方式,不得窃取或者以其他非法方式获取数据。
\r\n同条第二款:法律、行政法规对收集、使用数据的目的和范围有规定的,只能在该目的和范围内收集、使用。
\r\n第五十一条:窃取或者以其他非法方式获取数据,或者因此损害个人、组织合法权益的,依照有关法律、行政法规处罚。
\r\n《中华人民共和国个人信息保护法》第五条:处理个人信息应当合法、正当、必要、诚信,不得通过误导、欺诈、胁迫等方式处理。
\r\n第六条第一款、第二款:处理个人信息应当具有明确、合理的目的,并与该目的直接相关,采取对个人权益影响最小的方式;收集限于实现处理目的的最小范围,不得过度收集。
\r\n第十条:禁止非法收集、使用、加工、传输他人个人信息,禁止非法买卖、提供或者公开他人个人信息;禁止从事危害国家安全、公共利益的个人信息处理活动。
\r\n第十三条:没有取得个人同意,也不属于订立履行合同所必需、履行法定职责、应对突发、公共利益新闻舆论、处理本人已经合法公开的信息,以及法律行政法规规定的其他情形之一的,不得处理个人信息。
\r\n第二十八条、第二十九条:生物识别、医疗健康、金融账户、行踪轨迹,以及不满十四周岁未成年人的个人信息,属于敏感个人信息。没有特定目的、充分必要性和严格保护措施,并且没有取得个人单独同意的,不得处理。
\r\n此外还须遵守其他现行有效的法律、行政法规、监管规定,以及所使用模型的服务条款与滥用政策。
\r\n未授权进入。禁止把没有书面授权的单位、域名、地址、公网系统、生产业务或关键信息基础设施登记为靶标,禁止对其扫描、探测、侵入、控制或发包。对应刑法第二百八十五条第一款、第二款,网络安全法第二十九条、第三十三条。
\r\n破坏与恶意程序。禁止删除、修改、增加、干扰他人系统功能或其中的数据、应用程序;禁止制作、传播病毒、勒索程序或其他破坏性程序;禁止在信息或软件中设置恶意程序。对应刑法第二百八十六条第一款至第三款,网络安全法第五十条。
\r\n工具与帮助。禁止把本项目或本机提供给他人,用于侵入、非法控制或窃取数据;禁止明知对方在实施网络犯罪,仍提供程序、工具、技术支持、广告推广或支付结算。对应刑法第二百八十五条第三款、第二百八十七条之二,网络安全法第二十九条。
\r\n数据。禁止窃取、非法收集、超范围使用、泄露、出售或向他人提供业务数据、账号、口令和其他受保护数据。对应数据安全法第八条、第三十二条、第五十一条。
\r\n个人信息。禁止非法收集、使用、加工、传输、买卖、提供或公开他人个人信息;禁止过度收集;禁止以误导、欺诈、胁迫方式处理;禁止擅自处理生物识别、医疗健康、金融账户、行踪轨迹和儿童个人信息。对应刑法第二百五十三条之一第一款、第三款,网络安全法第四十六条,个人信息保护法第五条、第六条、第十条、第十三条、第二十八条、第二十九条。
\r\n诈骗与违法信息。禁止设立或利用网站、群组实施诈骗、传授犯罪方法、制作或销售违禁物品、管制物品;禁止发布此类信息;禁止利用计算机实施诈骗、盗窃、贪污、挪用公款、窃取国家秘密。对应刑法第二百八十七条、第二百八十七条之一第一款第(一)项至第(三)项,网络安全法第四十八条。
\r\n内容。禁止生成或传播危害国家安全、荣誉和利益的内容,禁止煽动颠覆、分裂,禁止恐怖主义、极端主义、民族仇恨,禁止暴力、淫秽色情、赌博,禁止编造虚假信息扰乱经济秩序和社会秩序,禁止侵害名誉、隐私、知识产权,禁止危害未成年人身心健康的内容。对应网络安全法第十三条第二款、第十四条。
\r\n结果扩散。演练中形成的记录、资产信息和文件,只留在书面授权写明的目标和期限里,不得交给无权获知的人,也不得改作授权以外的用途。
\r\n本项目依据 MIT 协议按现状提供。开发者不就完整性、安全性与适用性作保证。使用者对自己的下载、部署、运行、修改、传播,以及全部输入与输出,承担独立、完全的民事、行政及刑事法律责任。作者与贡献者不承担因滥用产生的直接、间接或连带责任。
\r\n勾选确认的是操作者本人,不能代替没有阅读本声明的人,也不能把别人的系统说成已经授权。
\r\n一旦用于非法攻击、恶意活动或上述任一禁止方向,使用许可自该行为发生之日起自动终止,且不可撤销。必须立即停止使用,并销毁本项目的代码、脚本与衍生数据,依法承担责任。授权终止后,演练台不得继续打开或继续使用。
\r\n本项目是独立的开源项目,与 DeepSeek 官方或其关联主体没有隶属、商业合作、授权或官方背书。文中的「官方」只表示评测对象是使用者本机安装的官方 DeepSeek Harness 软件包,不代表 DeepSeek 官方开发、认可或担保本插件。
\r\n文末。倒计时结束、滚到这里并勾选全部三项,才表示你以本人身份认可本声明,并完成本次演练台授权。
"; + function readWelcomeAck() { + try { return window.localStorage.getItem(WELCOME_KEY) === "1"; } catch { return false; } + } + function writeWelcomeAck() { + try { window.localStorage.setItem(WELCOME_KEY, "1"); } catch { /* ignore */ } + } + function readDrillAuth() { try { return window.localStorage.getItem(AUTH_KEY) === "1"; } catch { return false; } } @@ -7288,6 +7325,65 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert try { window.localStorage.setItem(DOCK_GEOM_KEY, JSON.stringify(clampDockGeom(g))); } catch { /* ignore */ } } + function WelcomeNotice() { + const t = useT(); + const [open, setOpen] = useState(() => !readWelcomeAck()); + const [checked, setChecked] = useState(false); + if (!open) return null; + const repo = t("welcome.repo"); + const node = h("div", { className: "dshp-auth-mask", role: "dialog", "aria-modal": "true" }, + h("div", { className: "dshp-auth-modal", style: { width: "min(560px,100%)" } }, + h("h2", null, t("welcome.title")), + h("div", { className: "muted", style: { color: "var(--dsw-alias-label-secondary,#999)", fontSize: 12 } }, t("welcome.lead")), + h("div", { className: "dshp-auth-warn" }, t("welcome.warn")), + h("div", { className: "dshp-auth-legal", style: { height: "auto", maxHeight: 280 } }, + h("p", null, t("welcome.body")), + h("p", null, + h("a", { + href: repo, + target: "_blank", + rel: "noopener noreferrer", + style: { color: "var(--dsw-alias-label-brand, #8fbf9a)", wordBreak: "break-all" }, + }, repo), + ), + h("h3", null, t("welcome.bans")), + h("p", null, t("welcome.ban1")), + h("p", null, t("welcome.ban2")), + h("p", null, t("welcome.ban3")), + ), + h("div", { className: "dshp-auth-checks" }, + h("label", null, + h("input", { + type: "checkbox", + checked: checked, + onChange: (e) => setChecked(!!(e && e.target && e.target.checked)), + }), + h("span", null, t("welcome.check")), + ), + ), + h("div", { className: "dshp-auth-ops" }, + h("button", { + type: "button", + className: "primary", + disabled: !checked, + onClick: () => { + if (!checked) return; + writeWelcomeAck(); + setOpen(false); + }, + }, t("welcome.ok")), + ), + ), + ); + try { + const rd = require("react-dom"); + if (rd && typeof rd.createPortal === "function" && typeof document !== "undefined" && document.body) { + return rd.createPortal(node, document.body); + } + } catch { /* ignore */ } + return node; + } + function AuthGate(props) { const t = useT(); const [left, setLeft] = useState(10); @@ -8021,7 +8117,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert name: "shell.overlay", id: "dsh-purge-dock", order: 50, - }, () => h(react.Fragment, null, h(PurgeDock), h(HeroNewSessionMount), h(TabRowPurgeMount), h(EnvAdaptSendGate)))); + }, () => h(react.Fragment, null, h(WelcomeNotice), h(PurgeDock), h(HeroNewSessionMount), h(TabRowPurgeMount), h(EnvAdaptSendGate)))); try { if (typeof ctx.inject === "function") { ctx.inject(["sessions", "uiWorkspace", "workspaces", "conversation"], (host) => installRewindUi(host)); diff --git a/lib/core.js b/lib/core.js index 37deebf..dec2e9d 100644 --- a/lib/core.js +++ b/lib/core.js @@ -118,6 +118,11 @@ export function resetPathMemo() { for (const slot of Object.keys(memo)) memo[slot] = { ready: false, value: null }; } +export function clearDesktopLocateCache() { + try { desktop.clearDesktopLocateCache(); } catch { /* ignore */ } + resetPathMemo(); +} + function isFile(fp) { try { if (desktop.isAsarSealedPath(fp)) return false; @@ -1630,12 +1635,30 @@ export function sealedAsarHandoff(input = {}) { const surface = input.surface ?? detectSurface(input); if (adapterFor(surface) !== "desktop") return null; const hinted = input.execPath; - const exe = hinted && desktop.isDesktopExecutable(hinted) + let exe = hinted && desktop.isDesktopExecutable(hinted) ? path.normalize(hinted) : desktop.findDesktopAppExecutable(input); - if (!exe || !desktop.isOfficialHarnessExecutable(exe)) return null; - const asar = desktop.appAsarPath(exe); - if (!asarArchiveIsFile(asar)) return null; + const resourcesPath = input.resourcesPath ?? process.resourcesPath; + let asar = exe ? desktop.appAsarPath(exe) : ""; + if (!asarArchiveIsFile(asar) && resourcesPath) { + const candidate = path.join(path.normalize(resourcesPath), "app.asar"); + if (asarArchiveIsFile(candidate)) { + asar = candidate; + if (!exe) { + exe = desktop.findDesktopAppExecutable({ ...input, resourcesPath }) + || (desktop.isDesktopExecutable(process.execPath) ? path.normalize(process.execPath) : "") + || path.normalize(process.execPath); + } + } + } + if (!exe || !asarArchiveIsFile(asar)) return null; + // 官方密封包:已知 exe 名,或当前进程 resources 里就有 app.asar。 + if ( + !desktop.isOfficialHarnessExecutable(exe) + && !(resourcesPath && asarArchiveIsFile(path.join(path.normalize(resourcesPath), "app.asar"))) + ) { + return null; + } return { exe, asar, swapAsar: true }; } @@ -3706,6 +3729,144 @@ const NEW_TOOL_PATCHES = [ ], markers: ["[dsh-purge] guard undefined content"], }, + { + id: 69, + name: "MODEL_STREAM_RELEASE", + layer: "代码", + layer_en: "Code", + desc: "deepseek-flash 恢复官方 in-history,并撤掉会打成 TRANSPORT 的独立连接补丁 / restore official in-history and remove the transport-breaking socket patch", + file: ["llm-deepseek"], + optional: true, + skipIfMarked: true, + forbid: [ + "[dsh-purge] one connection per model request", + "[dsh-purge] release model socket", + "[dsh-purge] drop the model socket", + ], + replacements: [ + { + pattern: + "\t\t\t\tsignal.throwIfAborted();\n" + + "\t\t\t\tconst betas = [...fileIds !== void 0 && fileIds.size > 0 ? [MESSAGES_FILES_BETA] : [], ...body.messages.some((message) => message.content.some((block) => block.type === \"tool_addition\" || block.type === \"tool_removal\")) ? [MESSAGES_TOOL_CHANGES_BETA] : []];\n" + + "\t\t\t\tlet streamAgent; // [dsh-purge] one connection per model request\n" + + "\t\t\t\ttry {\n" + + "\t\t\t\t\tconst undici = await import(\"undici\");\n" + + "\t\t\t\t\tif (typeof undici.Agent === \"function\") streamAgent = new undici.Agent({\n" + + "\t\t\t\t\t\tconnections: 1,\n" + + "\t\t\t\t\t\tpipelining: 0,\n" + + "\t\t\t\t\t\tkeepAliveTimeout: 1,\n" + + "\t\t\t\t\t\tkeepAliveMaxTimeout: 1,\n" + + "\t\t\t\t\t\tallowH2: true\n" + + "\t\t\t\t\t});\n" + + "\t\t\t\t} catch (_noUndici) {}\n" + + "\t\t\t\ttry {\n" + + "\t\t\t\t\tconst response = await fetch(`${messagesApiRoot(connection.baseURL)}/messages`, {\n" + + "\t\t\t\t\t\tmethod: \"POST\",\n" + + "\t\t\t\t\t\tsignal,\n" + + "\t\t\t\t\t\tbody: extensions.payload,\n" + + "\t\t\t\t\t\tredirect: \"error\",\n" + + "\t\t\t\t\t\t...streamAgent ? { dispatcher: streamAgent } : {},\n" + + "\t\t\t\t\t\theaders: {\n" + + "\t\t\t\t\t\t\t...attributionHeaders(),\n" + + "\t\t\t\t\t\t\t\"content-type\": \"application/json\",\n" + + "\t\t\t\t\t\t\t\"accept\": \"text/event-stream\",\n" + + "\t\t\t\t\t\t\t...auth.headers,\n" + + "\t\t\t\t\t\t\t\"anthropic-version\": \"2023-06-01\",\n" + + "\t\t\t\t\t\t\t...betas.length === 0 ? {} : { \"anthropic-beta\": betas.join(\",\") },\n" + + "\t\t\t\t\t\t\t\"x-deepseek-harness-user-id\": this.dependencies.resolveUserId(),\n" + + "\t\t\t\t\t\t\t...options.sessionId === void 0 ? {} : { \"x-deepseek-harness-session-id\": String(options.sessionId) },\n" + + "\t\t\t\t\t\t\t...options.purpose === \"compaction\" ? { \"x-deepseek-harness-compact\": \"1\" } : {}\n" + + "\t\t\t\t\t\t}\n" + + "\t\t\t\t\t});\n" + + "\t\t\t\t\tif (!response.ok) {\n" + + "\t\t\t\t\t\tconst text = await response.text();\n" + + "\t\t\t\t\t\tlet raw;\n" + + "\t\t\t\t\t\ttry {\n" + + "\t\t\t\t\t\t\traw = JSON.parse(text);\n" + + "\t\t\t\t\t\t} catch (_nonJsonGatewayError) {}\n" + + "\t\t\t\t\t\tconst detail = providerErrorDetail(raw);\n" + + "\t\t\t\t\t\tif (await files.retry(detail)) continue;\n" + + "\t\t\t\t\t\tconst failure = providerError(raw, response.status, response.headers);\n" + + "\t\t\t\t\t\tthrow new LlmError(files.errorMessage(response.status, failure.message, detail), failure.code, {\n" + + "\t\t\t\t\t\t\t...failure.failure,\n" + + "\t\t\t\t\t\t\tcause: new Error(text)\n" + + "\t\t\t\t\t\t});\n" + + "\t\t\t\t\t}\n" + + "\t\t\t\t\tawait extensions.accept();\n" + + "\t\t\t\t\tif (response.body === null) throw new LlmError(\"DeepSeek Messages returned no response body\", \"EMPTY_RESPONSE\");\n" + + "\t\t\t\t\tyield* translate(parseSse(response.body, activity), options.model);\n" + + "\t\t\t\t\treturn;\n" + + "\t\t\t\t} finally {\n" + + "\t\t\t\t\ttry {\n" + + "\t\t\t\t\t\tconst closed = streamAgent?.destroy();\n" + + "\t\t\t\t\t\tif (closed && typeof closed.catch === \"function\") closed.catch(() => {});\n" + + "\t\t\t\t\t} catch { /* [dsh-purge] release model socket */ }\n" + + "\t\t\t\t}", + replace: + "\t\t\t\tsignal.throwIfAborted();\n" + + "\t\t\t\tconst betas = [...fileIds !== void 0 && fileIds.size > 0 ? [MESSAGES_FILES_BETA] : [], ...body.messages.some((message) => message.content.some((block) => block.type === \"tool_addition\" || block.type === \"tool_removal\")) ? [MESSAGES_TOOL_CHANGES_BETA] : []];\n" + + "\t\t\t\tconst response = await fetch(`${messagesApiRoot(connection.baseURL)}/messages`, {\n" + + "\t\t\t\t\tmethod: \"POST\",\n" + + "\t\t\t\t\tsignal,\n" + + "\t\t\t\t\tbody: extensions.payload,\n" + + "\t\t\t\t\tredirect: \"error\",\n" + + "\t\t\t\t\theaders: {\n" + + "\t\t\t\t\t\t...attributionHeaders(),\n" + + "\t\t\t\t\t\t\"content-type\": \"application/json\",\n" + + "\t\t\t\t\t\t\"accept\": \"text/event-stream\",\n" + + "\t\t\t\t\t\t...auth.headers,\n" + + "\t\t\t\t\t\t\"anthropic-version\": \"2023-06-01\",\n" + + "\t\t\t\t\t\t...betas.length === 0 ? {} : { \"anthropic-beta\": betas.join(\",\") },\n" + + "\t\t\t\t\t\t\"x-deepseek-harness-user-id\": this.dependencies.resolveUserId(),\n" + + "\t\t\t\t\t\t...options.sessionId === void 0 ? {} : { \"x-deepseek-harness-session-id\": String(options.sessionId) },\n" + + "\t\t\t\t\t\t...options.purpose === \"compaction\" ? { \"x-deepseek-harness-compact\": \"1\" } : {}\n" + + "\t\t\t\t\t}\n" + + "\t\t\t\t});\n" + + "\t\t\t\tif (!response.ok) {\n" + + "\t\t\t\t\tconst text = await response.text();\n" + + "\t\t\t\t\tlet raw;\n" + + "\t\t\t\t\ttry {\n" + + "\t\t\t\t\t\traw = JSON.parse(text);\n" + + "\t\t\t\t\t} catch (_nonJsonGatewayError) {}\n" + + "\t\t\t\t\tconst detail = providerErrorDetail(raw);\n" + + "\t\t\t\t\tif (await files.retry(detail)) continue;\n" + + "\t\t\t\t\tconst failure = providerError(raw, response.status, response.headers);\n" + + "\t\t\t\t\tthrow new LlmError(files.errorMessage(response.status, failure.message, detail), failure.code, {\n" + + "\t\t\t\t\t\t...failure.failure,\n" + + "\t\t\t\t\t\tcause: new Error(text)\n" + + "\t\t\t\t\t});\n" + + "\t\t\t\t}\n" + + "\t\t\t\tawait extensions.accept();\n" + + "\t\t\t\tif (response.body === null) throw new LlmError(\"DeepSeek Messages returned no response body\", \"EMPTY_RESPONSE\");\n" + + "\t\t\t\tyield* translate(parseSse(response.body, activity), options.model);\n" + + "\t\t\t\treturn;", + }, + { + pattern: + "\tid: \"deepseek-flash\",\n" + + "\tname: \"DeepSeek-V41-Flash\",\n" + + "\tcontextWindow: DEFAULT_CONTEXT_WINDOW,\n" + + "\tinputModalities: [\"text\", \"image\"],\n" + + "\ttoolUpdate: \"addition-only\"", + replace: + "\tid: \"deepseek-flash\",\n" + + "\tname: \"DeepSeek-V41-Flash\",\n" + + "\tcontextWindow: DEFAULT_CONTEXT_WINDOW,\n" + + "\tinputModalities: [\"text\", \"image\"],\n" + + "\tsystemPromptUpdate: \"in-history\", // [dsh-purge] deepseek-flash keeps in-history\n" + + "\ttoolUpdate: \"addition-only\"", + }, + { + pattern: + "\tsystemPromptUpdate: \"in-history\",\n" + + "\ttoolUpdate: \"addition-only\"", + replace: + "\tsystemPromptUpdate: \"in-history\", // [dsh-purge] deepseek-flash keeps in-history\n" + + "\ttoolUpdate: \"addition-only\"", + }, + ], + markers: ["[dsh-purge] deepseek-flash keeps in-history"], + }, { id: 56, name: "REWIND_HIDE_CUT_ONLY", @@ -4523,6 +4684,9 @@ export function targetFiles(aiBase, dshHome = findDshHome()) { "deliverables-prompt": allExisting([ ...nestedPkg(aiBase, "dsh-client-ui-deliverables", "lib", "index.js"), ]), + "llm-deepseek": allExisting([ + ...nestedPkg(aiBase, "dsh-llm-deepseek", "lib", "index.js"), + ]), "session": allExisting([ ...nestedPkg(aiBase, "dsh-session", "lib", "index.js"), ]), diff --git a/lib/desktop.js b/lib/desktop.js index c94d333..1a88f36 100644 --- a/lib/desktop.js +++ b/lib/desktop.js @@ -80,11 +80,14 @@ export function looksLikeDesktopName(p) { n.endsWith("/dsh desktop") || n.endsWith("/dsh desktop.app") || n.includes("dsh-desktop") || + n.includes("/deepseek harness/") || + n.includes("/deepseek-harness/") || + n.includes("/deepseekharness") || + /\/deepseek[\s._-]*harness(\/|$)/.test(n) || n.includes("/deepseek harness.app/") || n.endsWith("/deepseek harness.app") || /\/dsh desktop\.exe$/i.test(n) || - /\/deepseek harness\.exe$/i.test(n) || - /\/deepseek-harness\.exe$/i.test(n) + /\/deepseek[\s._-]*harness\.exe$/i.test(n) ); } @@ -101,12 +104,16 @@ function sameBase(name, expected) { export function isDesktopExecutable(fp) { const base = path.basename(String(fp || "")).toLowerCase(); - return base === "dsh desktop.exe" || base === "dsh desktop" || OFFICIAL_HARNESS_BASES.has(base); + if (base === "dsh desktop.exe" || base === "dsh desktop") return true; + if (OFFICIAL_HARNESS_BASES.has(base)) return true; + return /^deepseek[\s._-]*harness(\.exe)?$/.test(base); } /** 只有官方 DeepSeek Harness 会把宿主封进 app.asar 并在「应用」时解开。第三方 DSH Desktop 不走这条。 */ export function isOfficialHarnessExecutable(fp) { - return OFFICIAL_HARNESS_BASES.has(path.basename(String(fp || "")).toLowerCase()); + const base = path.basename(String(fp || "")).toLowerCase(); + if (OFFICIAL_HARNESS_BASES.has(base)) return true; + return /^deepseek[\s._-]*harness(\.exe)?$/.test(base); } /** 某个安装目录下可能的 resources 文件夹(mac 大小写敏感盘要 Resources 和 resources 都试)。 */ @@ -267,7 +274,7 @@ function exeDirFromRegistryValue(value) { let cachedRegistryDirs; /** 从卸载登记读安装目录。盘符跟着用户安装位置,不写死。 */ export function registryInstallDirs() { - if (cachedRegistryDirs) return cachedRegistryDirs; + if (cachedRegistryDirs !== undefined) return cachedRegistryDirs; if (process.platform !== "win32") { cachedRegistryDirs = []; return cachedRegistryDirs; @@ -280,15 +287,14 @@ export function registryInstallDirs() { timeout: 15000, }); } catch { - cachedRegistryDirs = []; - return cachedRegistryDirs; + return []; } let rows = []; try { const parsed = JSON.parse(String(text || "").replace(/^\uFEFF/, "").trim() || "[]"); rows = Array.isArray(parsed) ? parsed : parsed ? [parsed] : []; } catch { - rows = []; + return []; } const found = []; for (const row of rows) { @@ -371,7 +377,7 @@ if ($paths) { @($paths) | ConvertTo-Json -Compress } let cachedRunningExes; function runningOfficialExecutables() { - if (cachedRunningExes) return cachedRunningExes; + if (cachedRunningExes !== undefined) return cachedRunningExes; if (process.platform !== "win32") { cachedRunningExes = []; return cachedRunningExes; @@ -384,15 +390,15 @@ function runningOfficialExecutables() { timeout: 15000, }); } catch { - cachedRunningExes = []; - return cachedRunningExes; + // 探测失败不缓存空结果,否则整次进程都找不到正在跑的客户端。 + return []; } let rows = []; try { const parsed = JSON.parse(String(text || "").replace(/^\uFEFF/, "").trim() || "[]"); rows = Array.isArray(parsed) ? parsed : parsed ? [parsed] : []; } catch { - rows = []; + return []; } cachedRunningExes = uniquePaths(rows.map((item) => String(item || "").trim()).filter((fp) => isDesktopExecutable(fp) && isFile(fp))); return cachedRunningExes; @@ -426,7 +432,7 @@ if ($out.Count) { @($out) | ConvertTo-Json -Compress } let cachedShortcutExes; function shortcutOfficialExecutables() { - if (cachedShortcutExes) return cachedShortcutExes; + if (cachedShortcutExes !== undefined) return cachedShortcutExes; if (process.platform !== "win32") { cachedShortcutExes = []; return cachedShortcutExes; @@ -439,20 +445,26 @@ function shortcutOfficialExecutables() { timeout: 15000, }); } catch { - cachedShortcutExes = []; - return cachedShortcutExes; + return []; } let rows = []; try { const parsed = JSON.parse(String(text || "").replace(/^\uFEFF/, "").trim() || "[]"); rows = Array.isArray(parsed) ? parsed : parsed ? [parsed] : []; } catch { - rows = []; + return []; } cachedShortcutExes = uniquePaths(rows.map((item) => String(item || "").trim()).filter((fp) => isDesktopExecutable(fp) && isFile(fp))); return cachedShortcutExes; } +/** 点「应用」前清掉失败的空缓存,重新找本机 exe。 */ +export function clearDesktopLocateCache() { + cachedRunningExes = undefined; + cachedShortcutExes = undefined; + cachedRegistryDirs = undefined; +} + function extraDiscoveredInstallDirs(env = process.env) { return uniquePaths([ ...homeSiblingInstalls(env), diff --git a/lib/index.js b/lib/index.js index 72991a0..9749711 100644 --- a/lib/index.js +++ b/lib/index.js @@ -468,6 +468,7 @@ async function handlePurgeCommand(rawInput, config) { case "apply": case "a": { core.applyRuntimeEnv(); + core.clearDesktopLocateCache(); const scrubbed = core.sanitizeDesktopCommandRuntimes(); const state = await core.gatherState(); let handoff = null; @@ -1288,6 +1289,7 @@ function installWebServer(ctx, cfg) { } try { core.applyRuntimeEnv(); + core.clearDesktopLocateCache(); const scrubbed = core.sanitizeDesktopCommandRuntimes(); const state = await core.gatherState(); let handoff = null; diff --git a/lib/redteam/client.js b/lib/redteam/client.js index 441b2c5..b345ec2 100644 --- a/lib/redteam/client.js +++ b/lib/redteam/client.js @@ -2462,6 +2462,11 @@ window.__ModuleLoader__.load({ /* 老 host 还没有知识库接口:讲清怎么恢复,别让人对着 "engagement required" 发懵 */ ? '知识库接口由 host 侧提供,当前宿主还是旧进程 —— 请完全退出后重新打开(官方 exe / 社区版 / dsh web 任一),再刷新页面。' : err) : null, + !err && data && data.dbPath + ? h('div', { className: 'rt-foot', style: { marginBottom: 6, fontSize: 11 } }, + '知识库:' + data.dbPath + + (data.root ? '(根目录 ' + data.root + ')' : '')) + : null, h('div', { className: 'rt-table' }, (() => { if (!grouped) return items.map(card) @@ -2526,6 +2531,7 @@ window.__ModuleLoader__.load({ : '知识库还是空的。本机也还没有 nuclei 模板库 —— 在演练机上跑 setup.sh 或 `nuclei -update-templates`,装好后这里会出现「本机模板 N」。'))), h('div', { style: { marginTop: 6, fontSize: 12 } }, '打 Nday/1day 的标准顺序:① redteam_poc_search 先查这里(顺带搜本机 nuclei 模板库)→ ② 都没有就互联网搜索(web_search / GitHub / ExploitDB / 厂商公告)或自己手搓 → ③ 在真实目标上验证有效后 redteam_poc_add 回填,后面的靶标直接就能用。'), + data.dbPath ? h('div', { style: { marginTop: 6, fontSize: 11 }, className: 'rt-mono' }, '知识库文件:' + data.dbPath) : null, tpl.dir ? h('div', { style: { marginTop: 6, fontSize: 11 }, className: 'rt-mono' }, '模板目录:' + tpl.dir) : null) : null), h('div', { className: 'rt-foot' }, diff --git a/lib/redteam/store-core.js b/lib/redteam/store-core.js index 263c7af..f7f0f3f 100644 --- a/lib/redteam/store-core.js +++ b/lib/redteam/store-core.js @@ -45,6 +45,9 @@ import { /* 内部辅助:原本就是 core.js 里的模块级函数,拆分后由 score-rules.js 提供 */ normalizePort, targetAuthority, systemKeyOf, pickBestHit, legacyCapGroup, targetHasIpv6Host, } from './score-rules.js' +import { + platformSummary, savePlatformConfig, assignToolkitFolder, loadPlatformConfig, nucleiTemplatesDirOf, +} from './platform-config.js' /* 再导出:core.js 的对外导出面与拆分前完全一致(调用方零改动) */ export { @@ -739,9 +742,9 @@ export function dispatch(store, req = {}) { const templates = q ? store.searchTemplates(q, Math.min(Number(req.templateLimit) || 20, 100)) : { dir: store.nucleiTemplatesDir() || null, total: store.templateStats().total, items: [] } - return { ok: true, items, stats: store.pocStats(), templates } + return { ok: true, items, stats: store.pocStats(), templates, dbPath: store.knowledgePath(), root: store.root } } - if (op === 'pocList') return { ok: true, items: store.searchPocs(req), stats: store.pocStats() } + if (op === 'pocList') return { ok: true, items: store.searchPocs(req), stats: store.pocStats(), dbPath: store.knowledgePath(), root: store.root } if (op === 'templateSearch') return Object.assign({ ok: true }, store.searchTemplates(req.q, Math.min(Number(req.limit) || 40, 200))) if (op === 'templateStats') return { ok: true, stats: store.templateStats() } if (op === 'pocGet') return Object.assign({ ok: true }, store.getPoc(req.id !== undefined ? req.id : req.code)) @@ -750,6 +753,13 @@ export function dispatch(store, req = {}) { if (op === 'pocDelete') return Object.assign({ ok: true }, store.deletePoc(req.id !== undefined ? req.id : req.code)) if (op === 'pocUse') return Object.assign({ ok: true }, store.markPocUsed(req.id !== undefined ? req.id : req.code, req.used_on)) if (op === 'pocStats') return { ok: true, stats: store.pocStats() } + /* 环境适配:全局,不依赖靶标;面板 / CLI / 工具共用 */ + if (op === 'platformConfigGet') return platformSummary(store.root) + if (op === 'platformConfigSave') { + savePlatformConfig(req.config || {}, store.root) + return platformSummary(store.root) + } + if (op === 'platformAssignToolkit') return assignToolkitFolder(req.dir, store.root) /* 没选靶标时:提示词回内置默认;只读查询回空结果。不要抛英文 engagement required。 */ let id = typeof req.engagement === 'string' ? req.engagement.trim() : '' if (!id && typeof store.activeEngagementId === 'function') id = store.activeEngagementId() || '' @@ -3649,6 +3659,11 @@ export class RedteamStore { /** 找本机 nuclei 模板目录(装了模板才有;找不到返回 undefined)。 */ nucleiTemplatesDir() { + /* 环境适配里手填/自动分配的路径优先(Windows 尤其依赖这一条) */ + try { + const configured = nucleiTemplatesDirOf(loadPlatformConfig(this.root), this.root) + if (configured) return configured + } catch { /* 忽略配置读失败,继续默认探测 */ } const candidates = [ join(this.root, 'toolkit', 'nuclei-templates'), join(homedir(), '.local', 'nuclei-templates'), diff --git a/lib/redteam/ui.js b/lib/redteam/ui.js index b09b0bd..cf45caf 100644 --- a/lib/redteam/ui.js +++ b/lib/redteam/ui.js @@ -15,12 +15,22 @@ import { fileURLToPath } from 'node:url' import { resolve, join } from 'node:path' import { existsSync, readFileSync, writeFileSync, mkdirSync, readdirSync, realpathSync } from 'node:fs' +import { homedir } from 'node:os' import { spawn } from 'node:child_process' import { dispatch, dispatchAsync } from './store-core.js' /* 技能可用性判定与 redteam_preflight 共用同一份实现(环境变量 / 本机路径 / 占位符) */ import { checkSkill, summarizeSkills } from './skill-availability.js' import { maxAgentsOf, maxAgentsSourceOf, saveMaxAgents, DEFAULT_MAX_AGENTS, MAX_AGENTS_LIMIT } from './settings.js' -import { loadPlatformConfig, mergeConfigEnv, redteamRoot, envAdaptStatus } from './platform-config.js' +import { + loadPlatformConfig, mergeConfigEnv, redteamRoot, envAdaptStatus, + platformSummary, savePlatformConfig, assignToolkitFolder, +} from './platform-config.js' + +/** DSH_HOME:显式环境变量优先;Windows 上 HOME 常空,回退 homedir()。 */ +function dshHomeOf() { + if (process.env.DSH_HOME) return process.env.DSH_HOME + return join(homedir(), '.dsh') +} /** * 本包自带技能目录候选。 @@ -29,7 +39,7 @@ import { loadPlatformConfig, mergeConfigEnv, redteamRoot, envAdaptStatus } from * 不从 index.js 引 packagePaths,避免与 cordis 插件入口互相拖拽。 */ function resolvePluginSkillsDir() { - const home = process.env.DSH_HOME || '' + const home = dshHomeOf() const candidates = [] try { const root = fileURLToPath(new URL('../..', import.meta.url)) @@ -38,12 +48,12 @@ function resolvePluginSkillsDir() { try { candidates.push(resolve(fileURLToPath(new URL('../../skills/redteam/', import.meta.url)))) } catch { /* ignore */ } - if (home) { - for (const profile of ['desktop', 'web', 'headless']) { - candidates.push(join(home, 'profiles', profile, 'node_modules', 'dsh-purge', 'skills', 'redteam')) - } - /* 不扫官方 $DSH_HOME/skills:技能只认本包 skills/redteam(与上游插件包内分发一致)。 */ + /* installBundledSkills 落盘位置:包内路径失效时仍能列出技能 */ + candidates.push(join(home, 'redteam', 'skills')) + for (const profile of ['desktop', 'web', 'headless']) { + candidates.push(join(home, 'profiles', profile, 'node_modules', 'dsh-purge', 'skills', 'redteam')) } + /* 不扫官方 $DSH_HOME/skills:技能只认本包 / 同步副本(与上游插件包内分发一致)。 */ for (const raw of candidates) { if (!raw) continue try { @@ -136,8 +146,25 @@ function profileDirOf(ctx) { try { if (typeof ctx.baseUrl === 'string' && ctx.baseUrl.length > 0) return ctx.baseUrl } catch { /* 忽略 */ } - const home = process.env.DSH_HOME || join(process.env.HOME || '', '.dsh') - return join(home, 'profiles', 'web') + return join(dshHomeOf(), 'profiles', 'web') +} + +/** + * 环境适配 op:面板 EnvTab 读写 `$DSH_HOME/redteam/config.json`。 + * @returns JSON 结果,或 undefined 表示不是这个 op。 + */ +function handlePlatformOp(store, request) { + const op = request && request.op + if (op !== 'platformConfigGet' && op !== 'platformConfigSave' && op !== 'platformAssignToolkit') { + return undefined + } + const root = (store && store.root) || redteamRoot() + if (op === 'platformConfigGet') return platformSummary(root) + if (op === 'platformConfigSave') { + savePlatformConfig(request.config || {}, root) + return platformSummary(root) + } + return assignToolkitFolder(request.dir, root) } /** 读 profile 的 package.json(依赖声明 + dsh.profile.bundles)。 */ @@ -847,6 +874,11 @@ export function apply(ctx) { try { const raw = await readBody(req) const request = raw.trim() ? JSON.parse(raw) : {} + const platformResult = handlePlatformOp(store, request) + if (platformResult !== undefined) { + sendJson(res, 200, platformResult) + return + } const agentsResult = await handleAgentsOp(ctx, request) if (agentsResult !== undefined) { sendJson(res, 200, agentsResult) diff --git a/lib/rewind.js b/lib/rewind.js index c63bae4..0e14cd0 100644 --- a/lib/rewind.js +++ b/lib/rewind.js @@ -340,13 +340,8 @@ export function wrapSessionDeriveMessages(session) { if (!session || typeof session.deriveMessages !== "function" || session.__dshPurgeRewindDerive) return session; const orig = session.deriveMessages.bind(session); session.deriveMessages = function deriveMessagesWithoutRewind() { - let messages; - try { - messages = orig(); - } catch { - // 回退后偶发 event.data.message.content 为空,官方 derive 读 .length 会直接炸掉。 - return []; - } + // 抛错不能改成空数组。空历史仍会发出请求,界面停在进行中,模型没有可答的内容。 + const messages = orig(); if (!Array.isArray(messages)) return []; return messages.filter((message) => !isRewindDerivedMessage(message)); }; @@ -357,51 +352,36 @@ export function wrapSessionDeriveMessages(session) { async function disarmRewoundSession(ctx, sessionId) { if (!sessionId) return; const controller = service(ctx, "sessionController"); - const disarmOnce = async () => { - const agent = getAgent(ctx, sessionId); - try { agent?.inbox?.clear?.(); } catch { /* ignore */ } - try { ignoreSettled(agent?.cancel?.({ kind: "user" }, { keepInbox: false })); } catch { /* ignore */ } + const agent = getAgent(ctx, sessionId); + // 只停回退开始时还在跑的那一轮。延迟再 cancel 会把用户刚发出的下一句一起掐掉,界面停在进行中,请求发不出去。 + const runningAbort = agent?.phase?.kind && agent.phase.kind !== "idle" ? agent.phase.abort : null; + if (runningAbort) { + try { ignoreSettled(agent.cancel({ kind: "user" }, { keepInbox: true })); } catch { /* ignore */ } + } - const ids = []; - try { - const log = await readSessionLog(ctx, sessionId); - ids.push(...pendingInboxInserts(log.events)); - } catch { /* ignore */ } - try { - for (const message of [...(agent?.inbox?.nextTurn || []), ...(agent?.inbox?.nextStep || [])]) { - if (message?.id) ids.push(message.id); - } - } catch { /* ignore */ } - - const seen = new Set(); - for (const id of ids) { - if (!id || seen.has(id)) continue; - seen.add(id); - try { - await controller?.updateQueue?.({ - sessionId, - itemId: id, - action: { kind: "remove" }, - }); - } catch { /* ignore */ } - } - - try { agent?.inbox?.clear?.(); } catch { /* ignore */ } - if (agent?.status === "running") { - try { ignoreSettled(agent.cancel({ kind: "user" }, { keepInbox: false })); } catch { /* ignore */ } - } - }; - - await disarmOnce(); - await sleep(20); - await disarmOnce(); + const ids = []; try { - const idle = getAgent(ctx, sessionId)?.whenIdle?.(); - if (idle && typeof idle.then === "function") { - await Promise.race([idle, sleep(800)]); + const log = await readSessionLog(ctx, sessionId); + ids.push(...pendingInboxInserts(log.events)); + } catch { /* ignore */ } + try { + for (const message of [...(agent?.inbox?.nextTurn || []), ...(agent?.inbox?.nextStep || [])]) { + if (message?.id) ids.push(message.id); } } catch { /* ignore */ } - await disarmOnce(); + + const seen = new Set(); + for (const id of ids) { + if (!id || seen.has(id)) continue; + seen.add(id); + try { + await controller?.updateQueue?.({ + sessionId, + itemId: id, + action: { kind: "remove" }, + }); + } catch { /* ignore */ } + } } export function invocationSessionId(invocation) { diff --git a/lib/surface.js b/lib/surface.js index 583087b..0459b0a 100644 --- a/lib/surface.js +++ b/lib/surface.js @@ -1,4 +1,5 @@ import path from "node:path"; +import fs from "node:fs"; /** 当前已接线的宿主面。gui / tui 先能识别,适配仍回退 web。 */ export const SURFACES = Object.freeze(["web", "desktop", "gui", "tui"]); @@ -18,9 +19,13 @@ function exeName(execPath) { export function pathLooksDesktop(p) { const n = slash(p); if (!n) return false; - // 安装目录可能叫 "DeepSeek Harness" / "deepseek-harness",但源码仓库(monorepo)也叫这个名字 —— - // 所以只凭目录名不算,还必须带桌面安装形态(resources/、exe、.app/)。与 desktop.looksLikeDesktopName 对齐。 - const harnessDir = n.includes("/deepseek harness/") || n.includes("/deepseek-harness/"); + // 安装目录可能叫 "DeepSeek Harness" / "deepseek-harness" / "DeepseekHarnessDesktop"。 + // 源码仓库也常带 deepseek-harness 名字,所以还要带 resources/、exe、.app/ 才算桌面安装。 + const harnessDir = + n.includes("/deepseek harness/") || + n.includes("/deepseek-harness/") || + n.includes("/deepseekharness") || + /\/deepseek[\s._-]*harness/.test(n); return ( n.includes("/dsh desktop/") || n.includes("/dsh desktop.app/") || @@ -29,12 +34,28 @@ export function pathLooksDesktop(p) { n.includes("/deepseek harness.app/") || (harnessDir && (n.includes("/resources/") || n.includes("/contents/resources/") || n.endsWith("/resources"))) || /\/dsh desktop\.exe$/i.test(n) || - /\/deepseek[- ]harness\.exe$/i.test(n) || + /\/deepseek[\s._-]*harness\.exe$/i.test(n) || n.endsWith("/host-process-entry.js") || n.endsWith("/desktop-cli.js") ); } +function resourcesLookLikeDesktopInstall(resourcesPath) { + if (!resourcesPath) return false; + if (pathLooksDesktop(resourcesPath)) return true; + const n = slash(resourcesPath); + if (!(n.endsWith("/resources") || n.includes("/contents/resources"))) return false; + try { + const asar = path.join(resourcesPath, "app.asar"); + if (fs.existsSync(asar) && fs.statSync(asar).isFile()) return true; + if (fs.existsSync(path.join(resourcesPath, "app", "dsh"))) return true; + if (fs.existsSync(path.join(resourcesPath, "app.asar.unpacked", "dsh"))) return true; + } catch { + /* ignore */ + } + return false; +} + export function isDesktopSurface(input = {}) { const env = input.env ?? process.env; const forced = norm(env.DSH_SURFACE); @@ -49,20 +70,21 @@ export function isDesktopSurface(input = {}) { name === "deepseek harness.exe" || name === "deepseek-harness.exe" || name === "deepseek harness" || - name === "deepseek-harness" + name === "deepseek-harness" || + /^deepseek[\s._-]*harness(\.exe)?$/.test(name) ) return true; if (pathLooksDesktop(execPath)) return true; const resourcesPath = input.resourcesPath ?? process.resourcesPath; - if (pathLooksDesktop(resourcesPath)) return true; + if (resourcesLookLikeDesktopInstall(resourcesPath)) return true; const argv = input.argv ?? process.argv; if ((Array.isArray(argv) ? argv : []).some((arg) => pathLooksDesktop(arg))) return true; const parentPort = input.parentPort !== undefined ? input.parentPort : process.parentPort; - if (parentPort && (pathLooksDesktop(execPath) || pathLooksDesktop(resourcesPath))) return true; + if (parentPort && (pathLooksDesktop(execPath) || resourcesLookLikeDesktopInstall(resourcesPath))) return true; - if (env.ELECTRON_RUN_AS_NODE && pathLooksDesktop(execPath)) return true; + if (env.ELECTRON_RUN_AS_NODE && (pathLooksDesktop(execPath) || resourcesLookLikeDesktopInstall(resourcesPath))) return true; return false; } diff --git a/package.json b/package.json index dc89c1d..addf858 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-purge", - "version": "1.1.46", + "version": "1.1.47", "description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐", "type": "module", "main": "lib/index.js", diff --git a/release-notes.md b/release-notes.md index ccd8d24..4fbdb9c 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,22 +1,32 @@ -# 1.1.46 +# 1.1.47 ## 中文 -- 版本升级到 1.1.46。1.1.45 有问题,略过,不要安装。 -- 默认提示词按 `default-prompt-inject.md` 重新加密写入。 -- 修复注入不稳定:第二轮或任务做到一半人设失效、被当成 `project_instructions` 拆掉的问题。 -- 工作区替换稿和作用域说明改回 0.1.7 的优先级:不能压过 system、developer 和用户原话。主 intro 的反软拒绝句保持不变。已经叠上的作用域强句整段收成这一句。 -- 进模型前剥掉外层 ChatML / `