mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 16:20:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ad39ad832 | ||
|
|
c032942e5f | ||
|
|
71defcc3da | ||
|
|
4655d06723 | ||
|
|
79714102a5 |
No files matched your search
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.57</strong></p>
|
||||
<p align="center"><strong>Version 1.1.59</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>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 ⭐</em>
|
||||
@@ -126,7 +126,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.57**. 1.1.45 is skipped; it has bugs.
|
||||
The plugin version is **1.1.59**. 1.1.45 is skipped; it has bugs.
|
||||
|
||||
---
|
||||
|
||||
@@ -190,13 +190,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv
|
||||
<p align="center">
|
||||
<a href="https://deepseek.stream/plugins/dsh-purge"><strong>🌐 Open Hub page</strong></a>
|
||||
·
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.57&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"><strong>🚀 Install in desktop client</strong></a>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.59&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"><strong>🚀 Install in desktop client</strong></a>
|
||||
</p>
|
||||
|
||||
🔗 **Raw protocol URL:**
|
||||
|
||||
```
|
||||
dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.57&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.59&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
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -212,7 +212,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.57',
|
||||
version: '1.1.59',
|
||||
repo: 'YuJunZhiXue/dsh-purge',
|
||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||
@@ -231,7 +231,7 @@ export function installDshPurgeToDesktop() {
|
||||
**HTML link:**
|
||||
|
||||
```html
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.57&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">
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.59&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">
|
||||
🚀 Install in desktop client
|
||||
</a>
|
||||
```
|
||||
@@ -242,7 +242,7 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | Plugin id |
|
||||
| name | `dsh-purge` | Display name |
|
||||
| version | `1.1.57` | Semver |
|
||||
| version | `1.1.59` | 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 |
|
||||
|
||||
+7
-7
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.57</strong></p>
|
||||
<p align="center"><strong>Version 1.1.59</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||
@@ -126,7 +126,7 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审
|
||||
| 官方 Harness 0.1.x | 不支持 |
|
||||
| 其它未列出版本 | 对不上的补丁会显示待应用或跳过,不要指望能用 |
|
||||
|
||||
插件版本是 **1.1.57**。1.1.45 有问题,略过。
|
||||
插件版本是 **1.1.59**。1.1.45 有问题,略过。
|
||||
|
||||
---
|
||||
|
||||
@@ -190,13 +190,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv
|
||||
<p align="center">
|
||||
<a href="https://deepseek.stream/plugins/dsh-purge"><strong>🌐 打开插件市场页</strong></a>
|
||||
·
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.57&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"><strong>🚀 唤起客户端一键安装</strong></a>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.59&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"><strong>🚀 唤起客户端一键安装</strong></a>
|
||||
</p>
|
||||
|
||||
🔗 **原生协议链接:**
|
||||
|
||||
```
|
||||
dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.57&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.59&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
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -212,7 +212,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.57',
|
||||
version: '1.1.59',
|
||||
repo: 'YuJunZhiXue/dsh-purge',
|
||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||
@@ -231,7 +231,7 @@ export function installDshPurgeToDesktop() {
|
||||
**HTML 静态链接方式:**
|
||||
|
||||
```html
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.57&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">
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.59&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">
|
||||
🚀 唤起客户端一键安装
|
||||
</a>
|
||||
```
|
||||
@@ -242,7 +242,7 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | 插件唯一标识符 |
|
||||
| name | `dsh-purge` | 插件展示名称 |
|
||||
| version | `1.1.57` | 语义化版本号 |
|
||||
| version | `1.1.59` | 语义化版本号 |
|
||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
|
||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ async function main() {
|
||||
const { made, errors } = await core.backupAll(state.ai_base);
|
||||
for (const b of made) console.log(` ✓ 备份 / backup → ${b}`);
|
||||
for (const [p, e] of errors) console.log(` ⚠ 备份失败 ${p}: ${e}`);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
for (const r of report) {
|
||||
const m = r.status === "applied" ? "✓ 已清洗" : r.status === "already" ? "- 已是最新" : r.status === "missing_file" ? "⚠ 文件缺失" : `✗ ${r.status}`;
|
||||
console.log(` ${m} patch #${String(r.patch_id).padEnd(2)} ${r.name}`);
|
||||
|
||||
@@ -129,14 +129,6 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
}
|
||||
|
||||
const TARGETS = ["AGENTS.md", "CLAUDE.md"];
|
||||
const PATCH_GROUPS = [
|
||||
{ key: "prompt", ids: [1, 2, 3, 4, 5, 25, 26, 28, 32, 43, 50, 53, 54, 61, 63] },
|
||||
{ key: "code", ids: [6, 7, 8, 42, 45, 46, 51, 52, 55, 56, 57, 58, 59, 62, 63, 64, 65] },
|
||||
{ key: "engine", ids: [9, 10, 11, 12, 13, 14, 15, 16, 35] },
|
||||
{ key: "tools", ids: [17, 18, 19, 21, 22, 23, 24, 29, 30, 31, 33, 34, 36, 37, 48, 60, 62, 64, 65] },
|
||||
{ key: "compat", ids: [38, 39, 40] },
|
||||
{ key: "dsh20", ids: [47, 49] },
|
||||
];
|
||||
|
||||
const zh = {
|
||||
nav: "规则设定",
|
||||
@@ -192,8 +184,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"own.save": "保存名单",
|
||||
"saved.own": "已保存自己的服务器",
|
||||
"saved.own.dropped": "已保存。有 {n} 行不是单个 IP 或主机名,已丢掉",
|
||||
"metric.purged": "已就绪",
|
||||
"metric.purged.skip": "已就绪,其中 {n} 项本机不需要",
|
||||
"metric.purged": "已写入",
|
||||
"metric.purged.skip": "已写入。跳过 {n} 项,本机没有这些文件",
|
||||
"metric.pendingShort": "待处理 {n}",
|
||||
"metric.unmatchedShort": "没对上 {n}",
|
||||
"metric.skipShort": "跳过 {n}",
|
||||
"metric.unlocated.count": "—",
|
||||
"metric.shim": "shim",
|
||||
"metric.shim.na": "本端不需要",
|
||||
@@ -204,6 +199,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"table.status": "状态",
|
||||
"status.applied": "已应用",
|
||||
"status.pending": "待应用",
|
||||
"status.unmatched": "没对上",
|
||||
"status.skipped": "跳过",
|
||||
"apply.hint": "点应用会把提示词框里的全文写入并打补丁,不必再点保存。待应用=原文还在。跳过=当前版本不需要或组件未安装。",
|
||||
"warn.noRoot": "未定位到当前宿主的 @deepseek-ai,清洗不会生效。请完全退出后再打开本宿主,在本页点「应用」。桌面端安装目录可以是任意盘符;目录名带 DeepseekHarness / DeepSeek Harness 均可。",
|
||||
@@ -323,8 +319,14 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"restarting.desktop": "正在重启桌面应用…",
|
||||
"restart.timeout": "超时,请刷新",
|
||||
"restart.fail": "失败: {error}",
|
||||
"restart.notStarted": "重启没有开始,客户端还在。不会自动再试。",
|
||||
"restart.already": "这一次重启已经开始,不会再重启一次。",
|
||||
"restart.confirm": "清洗已完成,重启后生效。",
|
||||
"restart.confirm.desktop": "清洗已完成,重启桌面应用后生效。",
|
||||
"restart.ask.title": "要现在重启吗",
|
||||
"restart.ask.body": "已经写入。重启后才会在当前客户端里生效。",
|
||||
"restart.now": "现在重启",
|
||||
"restart.notNow": "稍后",
|
||||
"restart.asarSwap": "补丁已写入磁盘。正在结束桌面进程并挪开 app.asar,完成后会自动重新打开;若仍无效,请先完全退出 Harness(托盘也关),再点一次应用。",
|
||||
"surface.web": "Web",
|
||||
"surface.desktop": "桌面端",
|
||||
@@ -403,6 +405,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"patch.63": "计划模式不再软拦执行",
|
||||
"patch.64": "Stop hook 不再注入假用户话",
|
||||
"patch.65": "UserPromptSubmit deny 不再整轮 reject",
|
||||
"patch.66": "空的系统段不再把这一轮打成内部错误",
|
||||
"patch.67": "缺 messages 时这一轮不中断",
|
||||
"patch.68": "回退后缺 content 不中断",
|
||||
"patch.69": "deepseek-flash 保持官方 in-history",
|
||||
"patch.72": "Messages 的 system 用当前系统提示",
|
||||
"status.unlocated": "未定位",
|
||||
"status.na": "本端不需要",
|
||||
"metric.unlocated": "还没定位到本机 Harness",
|
||||
@@ -489,8 +496,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"own.save": "Save list",
|
||||
"saved.own": "Own servers saved",
|
||||
"saved.own.dropped": "Saved. {n} lines were not a single IP or hostname and were dropped",
|
||||
"metric.purged": "Ready",
|
||||
"metric.purged.skip": "Ready, {n} not needed here",
|
||||
"metric.purged": "Written",
|
||||
"metric.purged.skip": "Written. Skipped {n}; those files are not on this install",
|
||||
"metric.pendingShort": "Pending {n}",
|
||||
"metric.unmatchedShort": "No match {n}",
|
||||
"metric.skipShort": "Skipped {n}",
|
||||
"metric.unlocated.count": "—",
|
||||
"metric.shim": "shim",
|
||||
"metric.shim.na": "Not needed here",
|
||||
@@ -501,6 +511,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"table.status": "Status",
|
||||
"status.applied": "Applied",
|
||||
"status.pending": "Pending",
|
||||
"status.unmatched": "No match",
|
||||
"status.skipped": "Skipped",
|
||||
"apply.hint": "Apply writes the prompt in the box and the patches. A separate save is unnecessary. Pending = original text still present. Skipped = not needed for this version or the component is not installed.",
|
||||
"warn.noRoot": "Could not find this host’s @deepseek-ai tree, so Apply will not patch anything. Fully quit and reopen this host, then Apply here. Desktop may live on any drive; folder names like DeepseekHarnessDesktop or DeepSeek Harness are fine.",
|
||||
@@ -620,8 +631,14 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"restarting.desktop": "Restarting the desktop app…",
|
||||
"restart.timeout": "Timed out; refresh",
|
||||
"restart.fail": "Failed: {error}",
|
||||
"restart.notStarted": "Restart did not start. This client is still open, and it will not try again by itself.",
|
||||
"restart.already": "This restart already started. It will not restart again.",
|
||||
"restart.confirm": "Apply finished. Restart to take effect.",
|
||||
"restart.confirm.desktop": "Apply finished. Restart the desktop app to take effect.",
|
||||
"restart.ask.title": "Restart now?",
|
||||
"restart.ask.body": "It is written. It takes effect in this client after a restart.",
|
||||
"restart.now": "Restart now",
|
||||
"restart.notNow": "Later",
|
||||
"restart.asarSwap": "Patches are on disk. Quitting the desktop app and moving app.asar aside; it will reopen when done. If behavior is unchanged, fully quit Harness (including tray) and Apply again.",
|
||||
"surface.web": "Web",
|
||||
"surface.desktop": "Desktop",
|
||||
@@ -700,6 +717,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"patch.63": "Plan mode no longer soft-blocks execution",
|
||||
"patch.64": "Stop hook no longer steers fake user text",
|
||||
"patch.65": "UserPromptSubmit deny no longer rejects turn",
|
||||
"patch.66": "Empty system section no longer ends the turn as an internal error",
|
||||
"patch.67": "A missing messages list no longer ends the turn",
|
||||
"patch.68": "Missing content after rewind no longer ends the turn",
|
||||
"patch.69": "deepseek-flash keeps the official in-history flag",
|
||||
"patch.72": "Messages system field uses the current system prompt",
|
||||
"status.na": "Not for this host",
|
||||
"metric.sealed": "Official client found. Apply to unpack",
|
||||
"metric.sealed.count": "Sealed",
|
||||
@@ -814,6 +836,16 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
.dshp-modal h4{margin:0 0 8px;font-family:var(--dshp-display);font-size:18px;font-weight:500}
|
||||
.dshp-modal p{margin:0 0 16px;font-size:13.5px;line-height:1.55}
|
||||
.dshp-modal-ops{display:flex;justify-content:flex-end;gap:8px}
|
||||
.dshp-restart-mask{position:fixed;inset:0;z-index:12000;display:flex;align-items:center;justify-content:center;padding:24px;background:rgba(0,0,0,.62);font-family:"Yu Gothic UI","Hiragino Sans GB","Source Han Sans SC","Microsoft YaHei UI",system-ui,sans-serif}
|
||||
.dshp-restart-card{width:min(420px,100%);box-sizing:border-box;padding:22px 22px 18px;border-radius:14px;background:var(--dsw-alias-bg-layer-1,#fffcf7);color:var(--dsw-alias-label-primary,#16140f);border:1px solid var(--dsw-alias-border-l1,#c9c3b6);box-shadow:0 18px 50px rgba(0,0,0,.35)}
|
||||
.dshp-restart-card h4{margin:0 0 10px;font-family:inherit;font-size:20px;font-weight:650;line-height:1.35;color:inherit}
|
||||
.dshp-restart-card p{margin:0 0 18px;font-size:16px;font-weight:500;line-height:1.65;color:inherit}
|
||||
.dshp-restart-card .dshp-modal-ops{display:flex;justify-content:flex-end;gap:10px}
|
||||
.dshp-restart-card .dshp-btn{min-height:38px;padding:0 16px;font-size:15px;font-weight:650;color:var(--dsw-alias-label-primary,#16140f);background:var(--dsw-alias-bg-layer-2,#fff);border:1px solid var(--dsw-alias-border-l1,#c9c3b6)}
|
||||
.dshp-restart-card .dshp-btn-primary,.dshp-restart-card .dshp-btn-primary:hover:not(:disabled){color:#fff;background:#2f6b4f;border-color:#2f6b4f}
|
||||
body[data-ds-dark-theme] .dshp-restart-card,.dshp-restart-mask[data-theme="dusk"] .dshp-restart-card{background:#1c1e24;color:#f4f1ea;border-color:#5a5e68}
|
||||
body[data-ds-dark-theme] .dshp-restart-card .dshp-btn,.dshp-restart-mask[data-theme="dusk"] .dshp-restart-card .dshp-btn{color:#f4f1ea;background:#2a2d34;border-color:#5a5e68}
|
||||
body[data-ds-dark-theme] .dshp-restart-card .dshp-btn-primary,body[data-ds-dark-theme] .dshp-restart-card .dshp-btn-primary:hover:not(:disabled),.dshp-restart-mask[data-theme="dusk"] .dshp-restart-card .dshp-btn-primary,.dshp-restart-mask[data-theme="dusk"] .dshp-restart-card .dshp-btn-primary:hover:not(:disabled){color:#fff;background:#3d8f68;border-color:#3d8f68}
|
||||
.dshp-notice{font-size:12.5px;line-height:1.4}
|
||||
.dshp-notice.is-ok{color:var(--dshp-ok)}
|
||||
.dshp-notice.is-bad{color:var(--dshp-bad)}
|
||||
@@ -949,6 +981,7 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
function statusKind(st) {
|
||||
if (st === "applied" || st === "already") return "ok";
|
||||
if (st === "pending") return "wait";
|
||||
if (st === "unmatched") return "bad";
|
||||
if (st === "na") return "ok";
|
||||
if (st === "missing_file" || st === "skipped" || st === "unlocated") return "miss";
|
||||
return "bad";
|
||||
@@ -957,6 +990,7 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
function statusLabel(st, t) {
|
||||
if (st === "applied" || st === "already") return t("status.applied");
|
||||
if (st === "pending") return t("status.pending");
|
||||
if (st === "unmatched") return t("status.unmatched");
|
||||
if (st === "skipped") return t("status.skipped");
|
||||
if (st === "missing_file") return t("skip");
|
||||
if (st === "unlocated") return t("status.unlocated");
|
||||
@@ -964,11 +998,6 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
return st || t("unknown");
|
||||
}
|
||||
|
||||
function statusApplied(st) {
|
||||
// 与后端 soft-ok 对齐:跳过 / 缺文件也算就绪,避免 48/63 这种假未完成。
|
||||
return st === "applied" || st === "already" || st === "skipped" || st === "missing_file";
|
||||
}
|
||||
|
||||
function shimKind(v) {
|
||||
if (v === "patched" || v === "n/a") return "ok";
|
||||
if (v === "original") return "wait";
|
||||
@@ -992,31 +1021,74 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
return h("span", { className: "dshp-pill is-" + statusKind(value) }, label || statusLabel(value, t));
|
||||
}
|
||||
|
||||
const LAYER_GROUP = {
|
||||
"提示词": "prompt",
|
||||
"代码": "code",
|
||||
"工具": "tools",
|
||||
"0.1.5 兼容": "compat",
|
||||
"0.2.0 兼容": "dsh20",
|
||||
};
|
||||
const GROUP_ORDER = ["prompt", "code", "tools", "compat", "dsh20"];
|
||||
|
||||
function patchRowsOf(state) {
|
||||
if (!state || !state.ai_base) return [];
|
||||
const fromList = Array.isArray(state.patches) ? state.patches : null;
|
||||
const rows = fromList
|
||||
? fromList.map((p) => ({
|
||||
id: Number(p.id),
|
||||
st: p.status || "missing_file",
|
||||
layer: p.layer || "",
|
||||
}))
|
||||
: Object.keys(state.patch_status || {}).map((id) => ({
|
||||
id: Number(id),
|
||||
st: state.patch_status[id],
|
||||
layer: "",
|
||||
}));
|
||||
return rows.filter((r) => r.st && r.st !== "na" && Number.isFinite(r.id));
|
||||
}
|
||||
|
||||
function tallyPatches(rows) {
|
||||
const out = { applied: 0, pending: 0, unmatched: 0, skipped: 0, total: 0 };
|
||||
for (const row of rows || []) {
|
||||
out.total += 1;
|
||||
if (row.st === "applied" || row.st === "already") out.applied += 1;
|
||||
else if (row.st === "pending") out.pending += 1;
|
||||
else if (row.st === "unmatched") out.unmatched += 1;
|
||||
else out.skipped += 1;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function PatchGroups({ state }) {
|
||||
const t = useT();
|
||||
const [open, setOpen] = useState({});
|
||||
if (!state || !state.patch_status) return h("div", { className: "dshp-skel", style: { height: 120 } });
|
||||
const located = !!state.ai_base;
|
||||
if (!located) return null;
|
||||
return PATCH_GROUPS.map((group) => {
|
||||
const rows = group.ids.map((id) => {
|
||||
const raw = located
|
||||
? (state.patch_status[id] || state.patch_status[String(id)] || "missing_file")
|
||||
: "unlocated";
|
||||
return { id, st: raw, label: t("patch." + id) };
|
||||
}).filter((r) => r.st !== "na");
|
||||
const grouped = new Map();
|
||||
for (const row of patchRowsOf(state)) {
|
||||
const key = LAYER_GROUP[row.layer] || "code";
|
||||
if (!grouped.has(key)) grouped.set(key, []);
|
||||
grouped.get(key).push(row);
|
||||
}
|
||||
return GROUP_ORDER.filter((key) => grouped.has(key)).map((key) => {
|
||||
const rows = grouped.get(key).slice().sort((a, b) => a.id - b.id);
|
||||
if (!rows.length) return null;
|
||||
const done = rows.filter((r) => statusApplied(r.st)).length;
|
||||
const expanded = !!open[group.key];
|
||||
return h("div", { key: group.key, className: "dshp-group" },
|
||||
const tally = tallyPatches(rows);
|
||||
const notes = [];
|
||||
if (tally.pending) notes.push(t("metric.pendingShort", { n: tally.pending }));
|
||||
if (tally.unmatched) notes.push(t("metric.unmatchedShort", { n: tally.unmatched }));
|
||||
if (tally.skipped) notes.push(t("metric.skipShort", { n: tally.skipped }));
|
||||
const expanded = !!open[key];
|
||||
return h("div", { key: key, className: "dshp-group" },
|
||||
h("button", {
|
||||
type: "button",
|
||||
className: "dshp-group-h",
|
||||
"aria-expanded": expanded ? "true" : "false",
|
||||
onClick: () => setOpen((prev) => Object.assign({}, prev, { [group.key]: !prev[group.key] })),
|
||||
onClick: () => setOpen((prev) => Object.assign({}, prev, { [key]: !prev[key] })),
|
||||
},
|
||||
h("strong", null, t("group." + group.key)),
|
||||
h("span", { className: "dshp-count" }, done + "/" + rows.length),
|
||||
h("strong", null, t("group." + key)),
|
||||
h("span", { className: "dshp-count" }, tally.applied + "/" + tally.total + (notes.length ? " · " + notes.join(" · ") : "")),
|
||||
),
|
||||
expanded ? h("table", { className: "dshp-table" },
|
||||
h("thead", null, h("tr", null,
|
||||
@@ -1026,7 +1098,7 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
)),
|
||||
h("tbody", null, rows.map((r) => h("tr", { key: r.id },
|
||||
h("td", { className: "dshp-id" }, "#" + r.id),
|
||||
h("td", null, r.label),
|
||||
h("td", null, t("patch." + r.id)),
|
||||
h("td", null, h(Pill, { value: r.st })),
|
||||
))),
|
||||
) : null,
|
||||
@@ -1136,6 +1208,33 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
);
|
||||
}
|
||||
|
||||
function RestartAsk(props) {
|
||||
const node = h("div", {
|
||||
className: "dshp-restart-mask",
|
||||
"data-theme": props.theme === "dusk" ? "dusk" : "white",
|
||||
role: "dialog",
|
||||
"aria-modal": "true",
|
||||
"aria-labelledby": "dshp-restart-title",
|
||||
onClick: (e) => { if (e.target === e.currentTarget && props.onLater) props.onLater(); },
|
||||
},
|
||||
h("div", { className: "dshp-restart-card" },
|
||||
h("h4", { id: "dshp-restart-title" }, props.t("restart.ask.title")),
|
||||
h("p", null, props.t("restart.ask.body")),
|
||||
h("div", { className: "dshp-modal-ops" },
|
||||
h(Btn, { onClick: props.onLater }, props.t("restart.notNow")),
|
||||
h(Btn, { kind: "primary", onClick: props.onRestart }, props.t("restart.now")),
|
||||
),
|
||||
),
|
||||
);
|
||||
try {
|
||||
const rd = require("react-dom");
|
||||
if (rd && typeof rd.createPortal === "function" && typeof document !== "undefined" && document.body) {
|
||||
return rd.createPortal(node, document.body);
|
||||
}
|
||||
} catch { /* host 可能没暴露 react-dom */ }
|
||||
return node;
|
||||
}
|
||||
|
||||
function PurgifySection() {
|
||||
const t = useT();
|
||||
const tRef = useRef(t);
|
||||
@@ -1357,7 +1456,11 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => { loadAll(); }, [loadAll]);
|
||||
useEffect(() => {
|
||||
loadAll();
|
||||
const timer = setTimeout(() => { loadAll(); }, 5000);
|
||||
return () => clearTimeout(timer);
|
||||
}, [loadAll]);
|
||||
|
||||
const rejectNeedPrompt = useCallback((tr) => {
|
||||
setAskRestart(false);
|
||||
@@ -1424,29 +1527,13 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
text: tr("restart.incomplete", { detail: parts.join(";") }),
|
||||
});
|
||||
loadAll();
|
||||
setAskRestart(true);
|
||||
return;
|
||||
}
|
||||
if (action === "apply" && d.asar_swap_started) {
|
||||
setNotice({ kind: "ok", text: tr("restart.asarSwap") });
|
||||
loadAll();
|
||||
return;
|
||||
}
|
||||
if (action === "apply" && (d.restart_after_apply || d.restarting)) {
|
||||
setNotice({
|
||||
kind: "ok",
|
||||
text: d.asar_still_sealed ? tr("restart.asarSwap") : tr("update.restarting"),
|
||||
});
|
||||
loadAll();
|
||||
const surf = hostSurfaceOf(state) || clientGuessSurface() || "web";
|
||||
restartDsh(setNotice, setPatchBusy, tr, surf);
|
||||
return;
|
||||
}
|
||||
if (action === "apply" && (d.needs_full_quit || d.unpacked_asar)) {
|
||||
setNotice({
|
||||
kind: "ok",
|
||||
text: d.asar_still_sealed ? tr("restart.asarSwap") : tr("ok.done"),
|
||||
});
|
||||
if (action === "apply") {
|
||||
setNotice({ kind: "ok", text: tr("ok.done") });
|
||||
loadAll();
|
||||
setAskRestart(true);
|
||||
return;
|
||||
}
|
||||
setNotice({ kind: "ok", text: tr("ok.done") });
|
||||
@@ -1461,7 +1548,7 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
});
|
||||
};
|
||||
run();
|
||||
}, [loadAll, rejectNeedPrompt]);
|
||||
}, [loadAll, rejectNeedPrompt, state]);
|
||||
|
||||
const saveOverride = useCallback(() => {
|
||||
const tr = t;
|
||||
@@ -1571,13 +1658,14 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
const desktopLikely = hostSurface === "desktop" || clientGuessSurface() === "desktop";
|
||||
const sealedReady = !located && desktopLikely && !!(s && (s.asar_still_sealed || s.desktop_exe || s.desktop_install));
|
||||
const patchesLost = !located && !!(s && s.patches_lost);
|
||||
const total = s && s.patches_total ? s.patches_total : 0;
|
||||
const ready = s && typeof s.patches_ready === "number"
|
||||
? s.patches_ready
|
||||
: (s && typeof s.patches_applied === "number" ? s.patches_applied : 0);
|
||||
const applied = ready;
|
||||
const skipped = located && s && typeof s.patches_skipped === "number" ? s.patches_skipped : 0;
|
||||
const pct = located && total ? Math.round((ready / total) * 100) : 0;
|
||||
const tally = located ? tallyPatches(patchRowsOf(s)) : { applied: 0, pending: 0, unmatched: 0, skipped: 0, total: 0 };
|
||||
const total = tally.total;
|
||||
const applied = tally.applied;
|
||||
const pct = located && total ? Math.round((applied / total) * 100) : 0;
|
||||
const metricNotes = [];
|
||||
if (tally.pending) metricNotes.push(t("metric.pendingShort", { n: tally.pending }));
|
||||
if (tally.unmatched) metricNotes.push(t("metric.unmatchedShort", { n: tally.unmatched }));
|
||||
if (tally.skipped) metricNotes.push(t("metric.skipShort", { n: tally.skipped }));
|
||||
|
||||
const versions = (updateInfo && updateInfo.versions) || [];
|
||||
const channelNow = (updateInfo && updateInfo.channel) || channel || "stable";
|
||||
@@ -1660,8 +1748,8 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
),
|
||||
s ? h("div", { className: "dshp-metrics" },
|
||||
h("div", { className: "dshp-metric" },
|
||||
h("b", null, located ? (ready + " / " + total) : (patchesLost ? t("metric.lost.count") : (sealedReady ? t("metric.sealed.count") : t("metric.unlocated.count")))),
|
||||
h("span", null, !located ? (patchesLost ? t("metric.lost") : (sealedReady ? t("metric.sealed") : t("metric.unlocated"))) : (skipped > 0 ? t("metric.purged.skip", { n: skipped }) : t("metric.purged"))),
|
||||
h("b", null, located ? (applied + " / " + total) : (patchesLost ? t("metric.lost.count") : (sealedReady ? t("metric.sealed.count") : t("metric.unlocated.count")))),
|
||||
h("span", null, !located ? (patchesLost ? t("metric.lost") : (sealedReady ? t("metric.sealed") : t("metric.unlocated"))) : (metricNotes.length ? metricNotes.join(" · ") : t("metric.purged"))),
|
||||
),
|
||||
h("div", { className: "dshp-metric" },
|
||||
h("b", { style: { fontSize: 13, fontFamily: "var(--dshp-mono)", fontWeight: 500 } },
|
||||
@@ -1729,18 +1817,15 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
h("p", { className: "dshp-hint", style: { margin: "8px 0 0", color: "var(--dshp-mute)", fontSize: 12 } }, t("apply.hint")),
|
||||
s && !s.ai_base ? h("p", { className: "dshp-hint", style: { margin: "8px 0 0", color: "var(--dshp-danger, #c44)", fontSize: 12 } }, hostText(t, "warn.noRoot", hostSurface)) : null,
|
||||
s && s.ai_base && s.override_status === "missing" ? h("p", { className: "dshp-hint", style: { margin: "8px 0 0", color: "var(--dshp-mute)", fontSize: 12 } }, t("warn.noInject")) : null,
|
||||
askRestart ? h("div", { className: "dshp-ask" },
|
||||
h("span", null, hostText(t, "restart.confirm", hostSurface)),
|
||||
h(Btn, { tiny: true, onClick: () => setAskRestart(false) }, t("restart.later")),
|
||||
h(Btn, {
|
||||
tiny: true,
|
||||
kind: "primary",
|
||||
onClick: () => {
|
||||
setAskRestart(false);
|
||||
restartDsh(setNotice, function () {}, t, hostSurface);
|
||||
},
|
||||
}, t("btn.restart")),
|
||||
) : null,
|
||||
askRestart ? h(RestartAsk, {
|
||||
t: t,
|
||||
theme: detectHostTheme(),
|
||||
onLater: () => setAskRestart(false),
|
||||
onRestart: () => {
|
||||
setAskRestart(false);
|
||||
restartDsh(setNotice, function () {}, t, hostSurface);
|
||||
},
|
||||
}) : null,
|
||||
// h(ContinueRetrySection, null),
|
||||
h("div", { className: "dshp-sub" },
|
||||
h("h4", null, t("override.title")),
|
||||
@@ -2070,8 +2155,13 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
const pinned = pin ? (list || []).find((item) => item.ref === pin) : null;
|
||||
if (pinned) return pinned;
|
||||
const ver = String(localVer || "").replace(/^v/i, "");
|
||||
const same = (list || []).filter((item) => ver && String(item.version || "").replace(/^v/i, "") === ver);
|
||||
if (same.length) {
|
||||
return same.find((item) => item.current)
|
||||
|| same.find((item) => item.latest)
|
||||
|| same[0];
|
||||
}
|
||||
return (list || []).find((item) => item.current)
|
||||
|| (list || []).find((item) => ver && String(item.version || "").replace(/^v/i, "") === ver)
|
||||
|| (list || []).find((item) => item.latest)
|
||||
|| (list || [])[0]
|
||||
|| null;
|
||||
@@ -2410,33 +2500,59 @@ body:not([data-ds-dark-theme]) .dshp-auth-ops button.primary{background:var(--ds
|
||||
setTimeout(ping, 800);
|
||||
}
|
||||
|
||||
let restartOnce = false;
|
||||
|
||||
function restartDsh(setNotice, setBusy, t, surface) {
|
||||
const surf = surface || clientGuessSurface() || "web";
|
||||
if (restartOnce) return;
|
||||
const surf = surface || clientGuessSurface() || "desktop";
|
||||
const desktop = surf === "desktop" || clientGuessSurface() === "desktop";
|
||||
restartOnce = true;
|
||||
setBusy(true);
|
||||
setNotice({ kind: "ok", text: hostText(t, "restarting", surf) });
|
||||
const stop = (error) => {
|
||||
restartOnce = false;
|
||||
setNotice({ kind: "error", text: error ? t("restart.fail", { error }) : t("restart.notStarted") });
|
||||
setBusy(false);
|
||||
};
|
||||
let sawDrop = false;
|
||||
const watch = setTimeout(() => {
|
||||
if (sawDrop) return;
|
||||
stop("");
|
||||
}, 25000);
|
||||
fetch("/dsh-purge/restart", { method: "POST", headers: { "content-type": "application/json" }, body: "{}" })
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (!d.ok) throw new Error(d.error || "restart failed");
|
||||
const next = (d && d.surface) || surf;
|
||||
if ((next === "desktop" || d.fullApp) && d.restarting === false) {
|
||||
setNotice({ kind: "error", text: t("restart.fail", { error: d.error || "not started" }) });
|
||||
const full = next === "desktop" || (d && d.fullApp) || desktop;
|
||||
if (full && d.already) {
|
||||
clearTimeout(watch);
|
||||
restartOnce = false;
|
||||
setNotice({ kind: "ok", text: t("restart.already") });
|
||||
setBusy(false);
|
||||
return;
|
||||
}
|
||||
if (full && d.restarting === false) {
|
||||
clearTimeout(watch);
|
||||
stop(d.error || "not started");
|
||||
return;
|
||||
}
|
||||
setNotice({ kind: "ok", text: hostText(t, "restarting", next) });
|
||||
// 桌面端整应用会退出重开。先刷新内嵌 web 会单独重启 Host。
|
||||
if (next === "desktop" || (d && d.fullApp) || clientGuessSurface() === "desktop") return;
|
||||
if (full) return;
|
||||
clearTimeout(watch);
|
||||
restartOnce = false;
|
||||
waitForRestart(setNotice, setBusy, t);
|
||||
})
|
||||
.catch((e) => {
|
||||
if (surf === "desktop" || clientGuessSurface() === "desktop") return;
|
||||
if (String(e.message || e).includes("Failed to fetch") || e.name === "TypeError") {
|
||||
waitForRestart(setNotice, setBusy, t);
|
||||
const msg = String((e && e.message) || e || "");
|
||||
const dropped = /failed to fetch|networkerror|load failed/i.test(msg) || e.name === "TypeError";
|
||||
if (dropped && desktop) {
|
||||
sawDrop = true;
|
||||
clearTimeout(watch);
|
||||
return;
|
||||
}
|
||||
setNotice({ kind: "error", text: t("restart.fail", { error: e.message }) });
|
||||
setBusy(false);
|
||||
clearTimeout(watch);
|
||||
stop(msg || "restart failed");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3156,7 +3272,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
这里放占位符,由 bundle 的 build.mjs 在生成 lib/client.js 时替换成正文。 */
|
||||
const CSS = `
|
||||
:root{--rt-dock-w:620px}
|
||||
/* 右侧栏收起时给 frame 加内边距,中栏主动收窄。属性名跨 DSH 版本兼容:\n 旧版 details 栏 data-details-collapsed,新版 rightbar 栏 data-rightbar-collapsed。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-details-collapsed],\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-rightbar-collapsed]{padding-right:var(--rt-dock-w)}
|
||||
/* 右侧栏收起时给 frame 加内边距,中栏主动收窄。属性名跨 DSH 版本兼容:\n 旧版 details 栏 data-details-collapsed,新版 rightbar 栏 data-rightbar-collapsed。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-details-collapsed],\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-rightbar-collapsed]{padding-right:var(--rt-dock-w)}
|
||||
.rt-dock{position:absolute;top:0;right:0;bottom:0;z-index:20;display:flex;flex-direction:column;
|
||||
background:color-mix(in srgb,var(--dsw-alias-bg-layer-1,#1c1c1c) 52%,transparent);
|
||||
backdrop-filter:blur(20px) saturate(1.3);-webkit-backdrop-filter:blur(20px) saturate(1.3);
|
||||
@@ -3164,7 +3280,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
box-shadow:-12px 0 32px color-mix(in srgb,#000 22%,transparent);pointer-events:auto;color:var(--dsw-alias-label-primary);
|
||||
font-size:13px;line-height:1.5;transition:transform .18s ease,opacity .18s ease}
|
||||
.rt-dock.rt-embedded{position:relative;background:transparent!important;border:0;box-shadow:none;backdrop-filter:none;-webkit-backdrop-filter:none}
|
||||
/* 右侧栏打开(或新版全屏)时让位:滑出隐藏。必须同时否定两个属性名——\n 旧写法只用 :not([data-details-collapsed]),在新 shell 里该属性不存在会导致条件恒真、面板永远打不开。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]):not([data-details-collapsed]):not([data-rightbar-collapsed]) .rt-dock,\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-rightbar-fullscreen] .rt-dock{
|
||||
/* 右侧栏打开(或新版全屏)时让位:滑出隐藏。必须同时否定两个属性名——\n 旧写法只用 :not([data-details-collapsed]),在新 shell 里该属性不存在会导致条件恒真、面板永远打不开。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded)):not([data-details-collapsed]):not([data-rightbar-collapsed]) .rt-dock,\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-rightbar-fullscreen] .rt-dock{
|
||||
transform:translateX(100%);opacity:0;pointer-events:none}
|
||||
.rt-grip{position:absolute;left:-3px;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:2}
|
||||
.rt-head{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--dsw-alias-border-l1)}
|
||||
@@ -7277,23 +7393,24 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
}
|
||||
syncDrillGrant();
|
||||
|
||||
const DOCK_GEOM_KEY = "dsh-purge-dock-geom-v2";
|
||||
const DOCK_GEOM_KEY = "dsh-purge-dock-geom-v4";
|
||||
/* 默认停在右上,底边留在输入框上面。拖动之后停在用户松开的位置,只保证不拖出窗口。 */
|
||||
const DOCK_COMPOSER_CLEAR = 172;
|
||||
function defaultDockGeom() {
|
||||
/* 默认贴右侧,像侧边栏:靠右、顶边留标题栏、高度铺满可视区 */
|
||||
const w = 620;
|
||||
const vw = typeof window !== "undefined" ? window.innerWidth : 1280;
|
||||
const vh = typeof window !== "undefined" ? window.innerHeight : 800;
|
||||
const w = Math.min(620, Math.max(380, vw - 16));
|
||||
const y = 48;
|
||||
const h = Math.max(360, vh - y - 12);
|
||||
const h = Math.max(240, Math.min(640, vh - y - DOCK_COMPOSER_CLEAR));
|
||||
return { x: Math.max(8, vw - w - 8), y: y, w: w, h: h };
|
||||
}
|
||||
function clampDockGeom(g) {
|
||||
const vw = typeof window !== "undefined" ? window.innerWidth : 1280;
|
||||
const vh = typeof window !== "undefined" ? window.innerHeight : 800;
|
||||
const w = Math.min(Math.max(380, Number(g && g.w) || 620), Math.max(380, vw - 16));
|
||||
const h = Math.min(Math.max(320, Number(g && g.h) || 520), Math.max(320, vh - 16));
|
||||
const x = Math.min(Math.max(8, Number(g && g.x) || 8), Math.max(8, vw - 64));
|
||||
const y = Math.min(Math.max(8, Number(g && g.y) || 8), Math.max(8, vh - 64));
|
||||
const h = Math.min(Math.max(240, Number(g && g.h) || 520), Math.max(240, vh - 16));
|
||||
const x = Math.min(Math.max(8, Number(g && g.x) || 8), Math.max(8, vw - w - 8));
|
||||
const y = Math.min(Math.max(8, Number(g && g.y) || 8), Math.max(8, vh - Math.min(h, vh - 16) - 8));
|
||||
return { x: x, y: y, w: w, h: h };
|
||||
}
|
||||
function loadDockGeom() {
|
||||
@@ -7797,21 +7914,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
try { if (__dshPurgeDrill && __dshPurgeDrill.setDockWidth) __dshPurgeDrill.setDockWidth(geom.w); } catch { /* ignore */ }
|
||||
}, [geom]);
|
||||
useEffect(() => {
|
||||
const onResize = () => setGeom((g) => {
|
||||
const vw = window.innerWidth;
|
||||
const vh = window.innerHeight;
|
||||
const nearRight = (g.x + g.w) >= (vw - 28);
|
||||
const tall = g.y <= 64 && g.h >= Math.min(vh * 0.55, vh - 80);
|
||||
let next = { x: g.x, y: g.y, w: g.w, h: g.h };
|
||||
if (nearRight) next.x = Math.max(8, vw - g.w - 8);
|
||||
if (tall) {
|
||||
next.y = 48;
|
||||
next.h = Math.max(360, vh - next.y - 12);
|
||||
} else if ((g.y + g.h) > vh - 8) {
|
||||
next.h = Math.max(320, vh - g.y - 12);
|
||||
}
|
||||
return clampDockGeom(next);
|
||||
});
|
||||
const onResize = () => setGeom((g) => clampDockGeom(g));
|
||||
window.addEventListener("resize", onResize);
|
||||
return () => window.removeEventListener("resize", onResize);
|
||||
}, []);
|
||||
|
||||
+255
-42
@@ -25,6 +25,7 @@ import {
|
||||
restoreExtractedDir,
|
||||
} from "./extract-asar.js";
|
||||
import { adapterFor, detectSurface } from "./surface.js";
|
||||
import { hostPromptKeepsInject } from "./host-clean.js";
|
||||
import { openSlot } from "./table-read.js";
|
||||
|
||||
// 无归档时用 node:fs;app.asar 还在时改写真实的 resources/app,避免新建文件 ENOENT。
|
||||
@@ -1451,6 +1452,13 @@ export function isDshHomeDir(dir) {
|
||||
return base === ".dsh" || base === "dsh-home";
|
||||
}
|
||||
|
||||
function homeHasHarnessData(dir) {
|
||||
if (!dir || !isDir(dir)) return false;
|
||||
return isFile(path.join(dir, "prompt-inject.md"))
|
||||
|| isDir(path.join(dir, "profiles"))
|
||||
|| isFile(path.join(dir, "cordis.patch.yml"));
|
||||
}
|
||||
|
||||
function desktopHomeCandidates() {
|
||||
const out = [];
|
||||
const push = (dir) => {
|
||||
@@ -1517,9 +1525,15 @@ export function findDshHome(options = {}) {
|
||||
if (fromEnv && String(fromEnv).trim()) return path.normalize(fromEnv.trim());
|
||||
const desktopHost = adapterFor(detectSurface(options)) === "desktop";
|
||||
if (desktopHost) {
|
||||
const found = [];
|
||||
for (const cand of desktopHomeCandidates()) {
|
||||
if (isDshHomeDir(cand)) return path.normalize(cand);
|
||||
if (isDshHomeDir(cand)) found.push(path.normalize(cand));
|
||||
}
|
||||
const unix = path.normalize(path.join(os.homedir(), ".dsh"));
|
||||
const usable = found.find((cand) => homeHasHarnessData(cand));
|
||||
if (usable) return usable;
|
||||
if (isDir(unix) && homeHasHarnessData(unix)) return unix;
|
||||
if (found.length) return found[0];
|
||||
}
|
||||
const shimDir = options.shimDir !== undefined ? options.shimDir : findShimDir();
|
||||
const prefix = options.prefix !== undefined ? options.prefix : findNpmPrefix();
|
||||
@@ -1604,12 +1618,31 @@ export function listShimDirsForPatch() {
|
||||
.filter((dir) => !isDesktopCommandRuntimeDir(dir));
|
||||
}
|
||||
|
||||
function pathIsUnder(child, root) {
|
||||
const c = path.normalize(String(child || "")).replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
|
||||
const r = path.normalize(String(root || "")).replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
|
||||
if (!c || !r || /^[a-z]:$/.test(r)) return false;
|
||||
return c === r || c.startsWith(`${r}/`);
|
||||
}
|
||||
|
||||
function findAiBaseDesktop() {
|
||||
const env = process.env.DSH_BASE;
|
||||
if (env && env.trim()) {
|
||||
const p = path.normalize(env.trim());
|
||||
if (isAiBase(p) && desktop.isInsideDesktopInstall(p)) return p;
|
||||
const exe = desktop.findDesktopAppExecutable();
|
||||
const owned = exe
|
||||
? desktop.resolveDesktopAiBase({
|
||||
execPath: exe,
|
||||
resourcesPath: path.join(path.dirname(exe), "resources"),
|
||||
argv: [],
|
||||
env: {},
|
||||
})
|
||||
: "";
|
||||
const envBase = String(process.env.DSH_BASE || "").trim();
|
||||
if (envBase) {
|
||||
const p = path.normalize(envBase);
|
||||
const underOwned = Boolean(owned && exe && pathIsUnder(p, path.dirname(exe)));
|
||||
if (isAiBase(p) && underOwned) return p;
|
||||
if (isAiBase(p) && !owned && desktop.isInsideDesktopInstall(p)) return p;
|
||||
}
|
||||
if (owned) return owned;
|
||||
const resolved = desktop.resolveDesktopAiBase();
|
||||
if (resolved) return resolved;
|
||||
const starts = [];
|
||||
@@ -1842,18 +1875,16 @@ export function scheduleSealedDesktopRestart(handoff) {
|
||||
return { renamed: false, pending: true, ...pending };
|
||||
}
|
||||
|
||||
const HOST_CLEAN_MARKERS = ["[dsh-purge] identity stripped", "[dsh-purge] complete prompt keeps inject"];
|
||||
export { hostPromptKeepsInject };
|
||||
|
||||
export function hostCleanMarkersPresent(aiBase) {
|
||||
if (!aiBase) return false;
|
||||
const fp = path.join(aiBase, "dsh-system-prompt", "lib", "index.js");
|
||||
let text = "";
|
||||
try {
|
||||
text = fs.readFileSync(fp, "utf8");
|
||||
return hostPromptKeepsInject(fs.readFileSync(fp, "utf8"));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return HOST_CLEAN_MARKERS.every((mark) => text.includes(mark));
|
||||
}
|
||||
|
||||
/** 重启前把清洗写进当前宿主。没写完就返回失败,调用方不得打开进程。 */
|
||||
@@ -1879,17 +1910,18 @@ export async function ensureHostClean() {
|
||||
let flash = silenceCmdFlash(aiBase);
|
||||
if (pending.length || flash.ok !== true) {
|
||||
await backupAll(aiBase);
|
||||
const report = await applyPatches(aiBase);
|
||||
const report = await applyPatches(aiBase, ALL_PATCHES, { preserveClientBundles: true });
|
||||
await patchAllShims();
|
||||
flash = silenceCmdFlash(aiBase);
|
||||
const summary = summarizeApplyReport(report);
|
||||
pending = await pendingIds();
|
||||
if (pending.length || summary.failed.length || flash.ok !== true) {
|
||||
const blocking = summary.failed.filter((row) => row.status !== "pattern_not_found");
|
||||
if (pending.length || blocking.length || flash.ok !== true) {
|
||||
return {
|
||||
ok: false,
|
||||
error: "清洗没有完成,已取消重启",
|
||||
pending,
|
||||
failed: summary.failed.length,
|
||||
failed: blocking.length,
|
||||
aiBase,
|
||||
};
|
||||
}
|
||||
@@ -2060,16 +2092,15 @@ function quotedConst(name, body) {
|
||||
|
||||
const COMPLETE_PROMPT_WATERFALL_INJECT =
|
||||
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
|
||||
"\t\tconst dshPurgeInject = (transformed.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\tif (completeSection === void 0 && !runtimeContextSuppressed) return transformed;\n" +
|
||||
"\t\tconst dshPurgeSections = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\") && String(s.text || \"\").length > 0);\n" +
|
||||
"\t\tconst dshPurgeRest = (transformed.sections || []).filter((s) => !String(s && s.name || \"\").startsWith(\"dsh-purge\"));\n" +
|
||||
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return { ...transformed, sections: [...dshPurgeSections, ...dshPurgeRest] }; // [dsh-purge] every mode keeps system inject\n" +
|
||||
"\t\treturn {\n" +
|
||||
"\t\t\t...transformed,\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, inject) {\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? [...dshPurgeSections, ...dshPurgeRest] : (function (complete, purge) {\n" +
|
||||
"\t\t\t\tconst base = { ...complete };\n" +
|
||||
"\t\t\t\tif (!inject) return [base];\n" +
|
||||
"\t\t\t\tif (String(base.text || \"\").includes(inject)) return [base];\n" +
|
||||
"\t\t\t\treturn [{ ...base, text: inject + \"\\n\\n\" + base.text }]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
|
||||
"\t\t\t})(completeSection, dshPurgeInject),\n" +
|
||||
"\t\t\t\treturn [...purge, base]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
|
||||
"\t\t\t})(completeSection, dshPurgeSections),\n" +
|
||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
|
||||
"\t\t};";
|
||||
|
||||
@@ -2267,6 +2298,21 @@ const PATCHES = [
|
||||
],
|
||||
markers: ["[dsh-purge] preset shell network"],
|
||||
},
|
||||
{
|
||||
id: 73,
|
||||
name: "PRESET_BASH_MIRROR_LINE",
|
||||
layer: "提示词",
|
||||
layer_en: "Prompt",
|
||||
desc: "极简 bash 去掉误留的镜像说明 / drop the extra mirror sentence",
|
||||
file: ["preset-minimal", "preset-sdk-minimal"],
|
||||
optional: true,
|
||||
replacements: [
|
||||
{
|
||||
pattern: /\n[ \t]*\* Network access depends on the task environment\. Prefer configured mirrors\/proxies when they are available\.\n/,
|
||||
replace: "\n",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 71,
|
||||
name: "LIANGSHEN_IDENTITY_LINE",
|
||||
@@ -2859,6 +2905,14 @@ const NEW_TOOL_PATCHES = [
|
||||
replace:
|
||||
"personaPrefix: !!js process.env.DSH_SYSTEM_PROMPT ?? ''",
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
" prefix: \"\"\n" +
|
||||
" complete: true",
|
||||
replace:
|
||||
" prefix: \"\"\n" +
|
||||
" complete: false # [dsh-purge] minimal keeps operator once",
|
||||
},
|
||||
],
|
||||
markers: [
|
||||
"personaPrefix: !!js process.env.DSH_SYSTEM_PROMPT ?? ''",
|
||||
@@ -3249,14 +3303,8 @@ const NEW_TOOL_PATCHES = [
|
||||
file: ["system-prompt", "system-prompt-nested"],
|
||||
replacements: [
|
||||
{
|
||||
pattern:
|
||||
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
|
||||
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return transformed;\n" +
|
||||
"\t\treturn {\n" +
|
||||
"\t\t\t...transformed,\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? transformed.sections : [completeSection],\n" +
|
||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
|
||||
"\t\t};",
|
||||
// 缩进不固定。0.2 有的构建用 tab,有的用空格;只认 tab 时匹配为 0,重启校验会说没写进宿主。
|
||||
pattern: /[ \t]*const transformed = await this\.ctx\.waterfall\(scopeTarget\(this, scope\), "system-prompt\/assemble", assembly, context, \(\) => Promise\.resolve\(assembly\)\);\n[ \t]*if \(completeSection === void 0 && !runtimeContextSuppressed\) return transformed;\n[ \t]*return \{\n[ \t]*\.\.\.transformed,\n[ \t]*sections: completeSection === void 0 \? transformed\.sections : \[completeSection\],\n[ \t]*contexts: runtimeContextSuppressed \? \[\] : transformed\.contexts\n[ \t]*\};/,
|
||||
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
|
||||
},
|
||||
{
|
||||
@@ -3276,6 +3324,21 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\t};",
|
||||
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
|
||||
"\t\tconst dshPurgeSections = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\") && String(s.text || \"\").length > 0);\n" +
|
||||
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return transformed;\n" +
|
||||
"\t\treturn {\n" +
|
||||
"\t\t\t...transformed,\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, purge) {\n" +
|
||||
"\t\t\t\tconst base = { ...complete };\n" +
|
||||
"\t\t\t\treturn [...purge, base]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
|
||||
"\t\t\t})(completeSection, dshPurgeSections),\n" +
|
||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
|
||||
"\t\t};",
|
||||
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
|
||||
},
|
||||
],
|
||||
forbid: ["dsh-purge:committed"],
|
||||
markers: ["complete prompt keeps waterfall inject"],
|
||||
@@ -3853,6 +3916,30 @@ const NEW_TOOL_PATCHES = [
|
||||
],
|
||||
markers: ["[dsh-purge] system prompt replaces the first node"],
|
||||
},
|
||||
{
|
||||
id: 74,
|
||||
name: "ASSEMBLE_BEFORE_PRESTEP",
|
||||
layer: "代码",
|
||||
layer_en: "Code",
|
||||
desc: "每个模式的第一次发送前先挂上默认提示词 / hang the default prompt before the first assemble",
|
||||
file: ["agent-loop"],
|
||||
skipIfMarked: true,
|
||||
replacements: [
|
||||
{
|
||||
pattern:
|
||||
"\t\tconst claimed = this.inbox.claim(target, position.turn);\n" +
|
||||
"\t\tconst assembly = await this.loopCtx.systemPrompt.assemble(assembleContextFor(this, signal));",
|
||||
replace:
|
||||
"\t\tconst claimed = this.inbox.claim(target, position.turn);\n" +
|
||||
"\t\tconst dshPurgePrepare = globalThis.__dshPurgePrepareAssemble;\n" +
|
||||
"\t\tif (typeof dshPurgePrepare === \"function\") {\n" +
|
||||
"\t\t\ttry { dshPurgePrepare(this.loopCtx); } catch { /* [dsh-purge] prepare assemble before this step */ }\n" +
|
||||
"\t\t}\n" +
|
||||
"\t\tconst assembly = await this.loopCtx.systemPrompt.assemble(assembleContextFor(this, signal));",
|
||||
},
|
||||
],
|
||||
markers: ["[dsh-purge] prepare assemble before this step"],
|
||||
},
|
||||
{
|
||||
id: 66,
|
||||
name: "SYSTEM_PROMPT_RENDER_GUARD",
|
||||
@@ -4118,7 +4205,50 @@ const NEW_TOOL_PATCHES = [
|
||||
desc: "回退只藏被撤掉的那一轮 / rewind hides only the cut range",
|
||||
file: ["conversation-client"],
|
||||
optional: true,
|
||||
// 锚点还在时也别再 replaceAll。这个文件是前端模块,重复写会改 mtime。
|
||||
skipIfMarked: true,
|
||||
replacements: [
|
||||
{
|
||||
// 上一版只藏 surface 序号。界面气泡和「用时」挂在回合事件上,序号对不上就还留在聊天里。
|
||||
pattern:
|
||||
"\t\t\t\thidden.add(event.seq);\n" +
|
||||
"\t\t\t\tif (Array.isArray(event.sourceEventSeqs)) {\n" +
|
||||
"\t\t\t\t\tfor (const seq of event.sourceEventSeqs) hidden.add(seq);\n" +
|
||||
"\t\t\t\t}\n",
|
||||
replace:
|
||||
"\t\t\t\thidden.add(event.seq); // [dsh-purge] rewind hides the cut turn\n" +
|
||||
"\t\t\t\tconst op = event.surfaceOp;\n" +
|
||||
"\t\t\t\tif (op && typeof op.startSeq === \"number\" && typeof op.endSeq === \"number\" && op.endSeq >= op.startSeq && op.endSeq - op.startSeq < 100000) {\n" +
|
||||
"\t\t\t\t\tfor (let seq = op.startSeq; seq <= op.endSeq; seq += 1) hidden.add(seq);\n" +
|
||||
"\t\t\t\t}\n" +
|
||||
"\t\t\t\tconst raw = event.sourceEventSeqs;\n" +
|
||||
"\t\t\t\tif (Array.isArray(raw)) {\n" +
|
||||
"\t\t\t\t\tfor (const row of raw) {\n" +
|
||||
"\t\t\t\t\t\tif (typeof row === \"number\") hidden.add(row);\n" +
|
||||
"\t\t\t\t\t\telse if (Array.isArray(row) && row.length === 2 && typeof row[0] === \"number\" && typeof row[1] === \"number\" && row[1] >= row[0] && row[1] - row[0] < 100000) {\n" +
|
||||
"\t\t\t\t\t\t\tfor (let seq = row[0]; seq <= row[1]; seq += 1) hidden.add(seq);\n" +
|
||||
"\t\t\t\t\t\t}\n" +
|
||||
"\t\t\t\t\t}\n" +
|
||||
"\t\t\t\t}\n" +
|
||||
"\t\t\t\tconst cutEnd = op && typeof op.endSeq === \"number\" ? op.endSeq : event.seq;\n" +
|
||||
"\t\t\t\tlet turnStart = null;\n" +
|
||||
"\t\t\t\tlet turnEnd = null;\n" +
|
||||
"\t\t\t\tfor (const row of list) {\n" +
|
||||
"\t\t\t\t\tconst ev = row && row.event;\n" +
|
||||
"\t\t\t\t\tif (!ev || ev.seq >= event.seq) continue;\n" +
|
||||
"\t\t\t\t\tif (ev.type === \"turn/start\") turnStart = ev.seq;\n" +
|
||||
"\t\t\t\t\tif (ev.type === \"turn/end\" && ev.seq >= cutEnd && turnEnd === null) turnEnd = ev.seq;\n" +
|
||||
"\t\t\t\t}\n" +
|
||||
"\t\t\t\tif (turnStart !== null) {\n" +
|
||||
"\t\t\t\t\tconst last = turnEnd === null ? event.seq : turnEnd;\n" +
|
||||
"\t\t\t\t\tfor (const row of list) {\n" +
|
||||
"\t\t\t\t\t\tconst ev = row && row.event;\n" +
|
||||
"\t\t\t\t\t\tif (!ev || ev.seq < turnStart || ev.seq > last) continue;\n" +
|
||||
"\t\t\t\t\t\tif (ev.type === \"system/message\") continue;\n" +
|
||||
"\t\t\t\t\t\thidden.add(ev.seq);\n" +
|
||||
"\t\t\t\t\t}\n" +
|
||||
"\t\t\t\t}\n",
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\tfunction rewindVisibleEntries(entries) {\n" +
|
||||
@@ -4187,7 +4317,7 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\t\t\tconst event = entry && entry.event;\n" +
|
||||
"\t\t\t\treturn !!event && !hidden.has(event.seq);\n" +
|
||||
"\t\t\t});\n" +
|
||||
"\t\t} // [dsh-purge] rewind hides only the cut range",
|
||||
"\t\t} // [dsh-purge] rewind hides the cut turn",
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
@@ -4252,7 +4382,7 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\t\t\tconst event = entry && entry.event;\n" +
|
||||
"\t\t\t\treturn !!event && !hidden.has(event.seq);\n" +
|
||||
"\t\t\t});\n" +
|
||||
"\t\t} // [dsh-purge] rewind hides only the cut range\n" +
|
||||
"\t\t} // [dsh-purge] rewind hides the cut turn\n" +
|
||||
"\t\tvar ConversationNodeAssembler = class {",
|
||||
},
|
||||
{
|
||||
@@ -4265,7 +4395,7 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\t\t\tthis.contexts.clear();",
|
||||
},
|
||||
],
|
||||
markers: ["[dsh-purge] rewind hides only the cut range"],
|
||||
markers: ["[dsh-purge] rewind hides the cut turn"],
|
||||
},
|
||||
{
|
||||
id: 57,
|
||||
@@ -4614,6 +4744,21 @@ function flattenTargetPaths(files) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* client-hmr 按 mtime/ctime/size 轮询 exports["./client"](官方 UI 包是 lib/client.js)。
|
||||
* 页面已经按旧 rev 要脚本时,再写这个文件会让缓存里的地址 404,输入框整串掉光(#63)。
|
||||
*/
|
||||
export function isWatchedClientBundle(fp) {
|
||||
const norm = String(fp || "").replace(/\\/g, "/");
|
||||
return /\/node_modules\/@[^/]+\/[^/]+\/lib\/client\.js$/.test(norm);
|
||||
}
|
||||
|
||||
export function clientBundlePackageName(fp) {
|
||||
const norm = String(fp || "").replace(/\\/g, "/");
|
||||
const matched = norm.match(/\/node_modules\/(@[^/]+\/[^/]+)\/lib\/client\.js$/);
|
||||
return matched ? matched[1] : "";
|
||||
}
|
||||
|
||||
/** 用户配置层:官方允许在 profiles/<name>/cordis.patch.yml 手写 insert,绝不能进 bak/回滚(#43)。 */
|
||||
export function isUserProfilePatchFile(fp) {
|
||||
const n = String(fp || "").replace(/\\/g, "/").toLowerCase();
|
||||
@@ -4671,14 +4816,29 @@ export async function backupAll(aiBase) {
|
||||
return { made, errors, skippedUser, dropped };
|
||||
}
|
||||
|
||||
export async function revertAll(aiBase) {
|
||||
async function sameFileBytes(left, right) {
|
||||
try {
|
||||
const [a, b] = await Promise.all([fsp.readFile(left), fsp.readFile(right)]);
|
||||
return a.equals(b);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function revertAll(aiBase, options = {}) {
|
||||
const files = targetFiles(aiBase);
|
||||
const reverted = [];
|
||||
const skipped = [];
|
||||
const preservedUser = [];
|
||||
const errors = [];
|
||||
const preserveClientBundles = options.preserveClientBundles === true;
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
// 启动自愈不能把前端 client.js 盖回去:copyFile 即使字节相同也会改 mtime(#63)。
|
||||
if (preserveClientBundles && isWatchedClientBundle(fp)) {
|
||||
skipped.push(fp);
|
||||
continue;
|
||||
}
|
||||
// 用户 patch 层:有 bak 也只丢掉 bak,绝不 copy 回去(#43)。
|
||||
if (isUserProfilePatchFile(fp)) {
|
||||
if (fs.existsSync(bak)) {
|
||||
@@ -4693,6 +4853,10 @@ export async function revertAll(aiBase) {
|
||||
}
|
||||
if (fs.existsSync(bak)) {
|
||||
try {
|
||||
if (fs.existsSync(fp) && await sameFileBytes(fp, bak)) {
|
||||
skipped.push(fp);
|
||||
continue;
|
||||
}
|
||||
await fsp.copyFile(bak, fp);
|
||||
await fsp.unlink(bak);
|
||||
reverted.push(fp);
|
||||
@@ -5387,7 +5551,15 @@ async function loadText(p) {
|
||||
}
|
||||
|
||||
async function saveText(p, text) {
|
||||
await fsp.writeFile(p, text, "utf8");
|
||||
const next = Buffer.from(text, "utf8");
|
||||
try {
|
||||
const current = await fsp.readFile(p);
|
||||
if (current.equals(next)) return false;
|
||||
} catch (e) {
|
||||
if (!e || e.code !== "ENOENT") throw e;
|
||||
}
|
||||
await fsp.writeFile(p, next);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function repairPluginCordisYaml() {
|
||||
@@ -5398,9 +5570,10 @@ async function repairPluginCordisYaml() {
|
||||
if (cleaned !== text) await saveText(fp, cleaned);
|
||||
}
|
||||
|
||||
export async function applyPatches(aiBase, patches = ALL_PATCHES) {
|
||||
export async function applyPatches(aiBase, patches = ALL_PATCHES, options = {}) {
|
||||
const files = targetFiles(aiBase);
|
||||
const report = [];
|
||||
const preserveClientBundles = options.preserveClientBundles === true;
|
||||
await repairPluginCordisYaml();
|
||||
for (const p of patches) {
|
||||
if (!patchAppliesHere(p)) {
|
||||
@@ -5437,6 +5610,11 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
|
||||
lastError = "read_error";
|
||||
continue;
|
||||
}
|
||||
if (preserveClientBundles && isWatchedClientBundle(fp)) {
|
||||
if (filePatchSettled(text, p, fp)) already += 1;
|
||||
else if (patchHasRemainingWork(text, p, fp) || p.strictFiles) notFound += 1;
|
||||
continue;
|
||||
}
|
||||
const appliedText = applyReplacementsToText(text, p, fp);
|
||||
let textOut = appliedText.text;
|
||||
let changed = appliedText.changed;
|
||||
@@ -5449,8 +5627,9 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
|
||||
}
|
||||
if (changed) {
|
||||
try {
|
||||
await saveText(fp, textOut);
|
||||
applied += 1;
|
||||
const wrote = await saveText(fp, textOut);
|
||||
if (wrote) applied += 1;
|
||||
else already += 1;
|
||||
} catch (e) {
|
||||
lastError = `write_error:${e}`;
|
||||
}
|
||||
@@ -5481,6 +5660,37 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
|
||||
return report;
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面加载前同步写入前端 client.js。只在字节真的变化时写盘。
|
||||
* 启动 4 秒后的 settle 不得再写这些文件,否则 client-hmr 会把旧 rev 从缓存里拿掉(#63)。
|
||||
* @returns 实际写过的包名
|
||||
*/
|
||||
export function patchWatchedClientBundlesSync(aiBase = findAiBase()) {
|
||||
if (!aiBase) return [];
|
||||
const files = targetFiles(aiBase);
|
||||
const written = [];
|
||||
for (const p of ALL_PATCHES) {
|
||||
if (!patchAppliesHere(p)) continue;
|
||||
for (const key of fileKeysOf(p)) {
|
||||
for (const fp of pathsOf(files, key)) {
|
||||
if (!isWatchedClientBundle(fp)) continue;
|
||||
const text = fs.readFileSync(fp, "utf8");
|
||||
const appliedText = applyReplacementsToText(text, p, fp);
|
||||
if (!appliedText.changed) continue;
|
||||
const next = Buffer.from(appliedText.text, "utf8");
|
||||
const current = fs.readFileSync(fp);
|
||||
if (current.equals(next)) continue;
|
||||
const bak = `${fp}.dshpurge.bak`;
|
||||
if (!fs.existsSync(bak)) fs.copyFileSync(fp, bak);
|
||||
fs.writeFileSync(fp, next);
|
||||
const packageName = clientBundlePackageName(fp);
|
||||
if (packageName && !written.includes(packageName)) written.push(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
export async function patchStatus(aiBase, patches = ALL_PATCHES) {
|
||||
const files = targetFiles(aiBase);
|
||||
const status = {};
|
||||
@@ -5493,6 +5703,7 @@ export async function patchStatus(aiBase, patches = ALL_PATCHES) {
|
||||
let applied = 0;
|
||||
let pending = 0;
|
||||
let skipped = 0;
|
||||
let unmatched = 0;
|
||||
let missing = 0;
|
||||
for (const key of keys) {
|
||||
const fps = pathsOf(files, key);
|
||||
@@ -5510,12 +5721,14 @@ export async function patchStatus(aiBase, patches = ALL_PATCHES) {
|
||||
}
|
||||
const outcome = filePatchOutcome(text, p, fp);
|
||||
if (outcome === "applied") applied += 1;
|
||||
else if (outcome === "pending" || (p.strictFiles && outcome === "skipped")) pending += 1;
|
||||
else if (outcome === "pending") pending += 1;
|
||||
else if (p.strictFiles) unmatched += 1;
|
||||
else skipped += 1;
|
||||
}
|
||||
}
|
||||
if (pending > 0) status[p.id] = "pending";
|
||||
else if (applied > 0) status[p.id] = "applied";
|
||||
else if (unmatched > 0) status[p.id] = "unmatched";
|
||||
else if (skipped > 0) status[p.id] = "skipped";
|
||||
else status[p.id] = p.optional ? "na" : "missing_file";
|
||||
}
|
||||
@@ -6190,15 +6403,15 @@ export async function gatherState() {
|
||||
let shim_cmd = "missing";
|
||||
let shim_ps1 = "missing";
|
||||
let shim_bin = "missing";
|
||||
if (shimDir) {
|
||||
shim_cmd = shimFileStatus(path.join(shimDir, "dsh.cmd"));
|
||||
shim_ps1 = shimFileStatus(path.join(shimDir, "dsh.ps1"));
|
||||
shim_bin = shimFileStatus(path.join(shimDir, "dsh"));
|
||||
} else if (adapterFor(detectSurface()) === "desktop") {
|
||||
// 桌面宿主不 patch CLI shim;缺目录不是失败。
|
||||
if (adapterFor(detectSurface()) === "desktop") {
|
||||
// 桌面宿主不改 CLI shim。PATH 上就算有网页端的 dsh,也不算进这一页。
|
||||
shim_cmd = "n/a";
|
||||
shim_ps1 = "n/a";
|
||||
shim_bin = "n/a";
|
||||
} else if (shimDir) {
|
||||
shim_cmd = shimFileStatus(path.join(shimDir, "dsh.cmd"));
|
||||
shim_ps1 = shimFileStatus(path.join(shimDir, "dsh.ps1"));
|
||||
shim_bin = shimFileStatus(path.join(shimDir, "dsh"));
|
||||
}
|
||||
return {
|
||||
surface: detectSurface(),
|
||||
|
||||
+102
-20
@@ -4,6 +4,7 @@ import { execFileSync, spawn } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { isWshAscii, wshLiteral } from "./official-update.js";
|
||||
import { asarArchiveIsFile, hostFs } from "./extract-asar.js";
|
||||
import { hostPromptKeepsInject } from "./host-clean.js";
|
||||
|
||||
// 无归档时用 node:fs。app.asar 还在时不能把映射出来的 resources/app 当成已经解开。
|
||||
const fs = hostFs;
|
||||
@@ -771,7 +772,9 @@ function helperEnv(payload) {
|
||||
|
||||
function spawnHelper(helper, payload, opts = {}) {
|
||||
const plan = restartPlan();
|
||||
if (!plan.execPath) throw new Error(plan.error || "未找到 DSH Desktop.exe,无法重启桌面应用");
|
||||
const hinted = payload && payload.execPath ? payload.execPath : "";
|
||||
const execPath = hinted || plan.execPath;
|
||||
if (!execPath) throw new Error(plan.error || "未找到 DSH Desktop.exe,无法重启桌面应用");
|
||||
const child = spawn(process.execPath, [helper], {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
@@ -779,9 +782,9 @@ function spawnHelper(helper, payload, opts = {}) {
|
||||
shell: false,
|
||||
env: helperEnv({
|
||||
kind: "desktop",
|
||||
execPath: plan.execPath,
|
||||
execPath,
|
||||
argv: plan.argv,
|
||||
cwd: plan.cwd,
|
||||
cwd: plan.cwd || path.dirname(execPath),
|
||||
pid: process.pid,
|
||||
...payload,
|
||||
}),
|
||||
@@ -988,16 +991,22 @@ export function scheduleAsarRenameWhenIdle({ exe, asar } = {}) {
|
||||
return { pending: true };
|
||||
}
|
||||
|
||||
/** 等当前桌面进程退出后把 app.asar 挪走,再启动 exe。解开后的 resources\\app 才会被加载。 */
|
||||
/** 等当前桌面进程退出后把 app.asar 挪走,再启动 exe。解开后的 resources/app 才会被加载。 */
|
||||
export function scheduleAsarSwapRestart({ exe, asar, waitPid = process.pid, exit = false } = {}) {
|
||||
if (!exe || !asar) throw new Error("缺少桌面 exe 或 app.asar,无法重启");
|
||||
if (process.platform === "darwin") {
|
||||
if (sealedSwapKind() === "helper") {
|
||||
const helper = fileURLToPath(new URL("./restart-desktop.js", import.meta.url));
|
||||
spawnHelper(helper, { respawn: true, killApp: true, asar, waitPid }, { exit: false });
|
||||
spawnHelper(helper, {
|
||||
respawn: true,
|
||||
killApp: true,
|
||||
asar,
|
||||
execPath: exe,
|
||||
cwd: path.dirname(exe),
|
||||
waitPid,
|
||||
}, { exit: false });
|
||||
if (exit !== false) setTimeout(() => process.exit(0), 800);
|
||||
return { scheduled: true };
|
||||
}
|
||||
if (process.platform !== "win32") return scheduleAsarRenameWhenIdle({ exe, asar });
|
||||
const script = path.join(os.tmpdir(), `dsh-purge-asar-swap-${process.pid}.ps1`);
|
||||
fs.writeFileSync(script, ASAR_SWAP_PS1, "utf8");
|
||||
const child = spawn(
|
||||
@@ -1022,8 +1031,30 @@ export function scheduleAsarSwapRestart({ exe, asar, waitPid = process.pid, exit
|
||||
return { scheduled: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* 点「应用」之后走哪条重启。#64:宿主 requestRestart 在桌面端会空返回,进程不动。
|
||||
* Windows 官方包用 wscript 结束再打开。Linux / macOS 能定位到 exe 就走 restart-desktop.js。
|
||||
*/
|
||||
export function desktopRestartChoice(input = {}) {
|
||||
const platform = input.platform || process.platform;
|
||||
const exe = input.exe || "";
|
||||
const desktopExe = Boolean(exe && isDesktopExecutable(exe));
|
||||
const official = Boolean(exe && isOfficialHarnessExecutable(exe));
|
||||
if (input.openBrowser === false) return "skip";
|
||||
if (platform === "win32" && official) return "windows-official";
|
||||
if (desktopExe && input.asarSealed === true) return "asar-swap";
|
||||
if (desktopExe) return "helper";
|
||||
if (input.hasRuntime) return "request-restart";
|
||||
return "helper";
|
||||
}
|
||||
|
||||
/** 密封 asar 要先退出进程才能挪走文件。Windows 用 PowerShell;Linux / macOS 用同一份重启脚本。 */
|
||||
export function sealedSwapKind(platform = process.platform) {
|
||||
return platform === "win32" ? "powershell" : "helper";
|
||||
}
|
||||
|
||||
function officialExeFromProcess() {
|
||||
// macOS / Linux 的重启走宿主 requestRestart。这里的 wscript 只服务 Windows 官方包。
|
||||
// Windows 官方包用 wscript。macOS 解开后的重启走 restart-desktop.js,不靠 requestRestart。
|
||||
if (process.platform !== "win32") return "";
|
||||
if (isOfficialHarnessExecutable(process.execPath)) return path.normalize(process.execPath);
|
||||
const resources = process.resourcesPath;
|
||||
@@ -1045,7 +1076,9 @@ function dshHomeForRelaunch() {
|
||||
return current;
|
||||
}
|
||||
|
||||
export function scheduleRestart(request, ctx, _options = {}) {
|
||||
export function scheduleRestart(request, ctx, options = {}) {
|
||||
// 启动自检会带 openBrowser:false。桌面进程不再因此杀掉自己。
|
||||
if (options.openBrowser === false) return { restarting: false, skipped: true };
|
||||
const exe =
|
||||
officialExeFromProcess() ||
|
||||
findDesktopAppExecutable() ||
|
||||
@@ -1059,6 +1092,28 @@ export function scheduleRestart(request, ctx, _options = {}) {
|
||||
return { restarting: true, asarSwap: true };
|
||||
}
|
||||
const runtime = desktopRuntimeOf(ctx);
|
||||
const choice = desktopRestartChoice({
|
||||
exe,
|
||||
asarSealed: false,
|
||||
hasRuntime: Boolean(runtime),
|
||||
});
|
||||
if (choice === "helper" && exe && isDesktopExecutable(exe)) {
|
||||
const helper = fileURLToPath(new URL("./restart-desktop.js", import.meta.url));
|
||||
try {
|
||||
spawnHelper(helper, {
|
||||
respawn: true,
|
||||
killApp: true,
|
||||
execPath: exe,
|
||||
cwd: path.dirname(exe),
|
||||
}, { exit: false });
|
||||
} catch (error) {
|
||||
return {
|
||||
restarting: false,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
};
|
||||
}
|
||||
return { restarting: true };
|
||||
}
|
||||
if (runtime) {
|
||||
// 只走桌面整应用 relaunch,不要 exit Host(那会先把内嵌 web 单独拉起来)。
|
||||
Promise.resolve(runtime.requestRestart()).catch((err) => {
|
||||
@@ -1093,8 +1148,13 @@ function officialRestartScript(exe, asar, dshHome) {
|
||||
"function pids() { var out = []; var root = String(installRoot() || '').replace(/\\//g, '\\\\').toLowerCase(); var e = new Enumerator(wmi.ExecQuery(\"SELECT ProcessId, ExecutablePath FROM Win32_Process WHERE Name = 'DeepSeek Harness.exe'\")); for (; !e.atEnd(); e.moveNext()) { var p = e.item(); var ep = String(p.ExecutablePath || '').replace(/\\//g, '\\\\').toLowerCase(); if (samePath(p.ExecutablePath, exe) || (root && ep.indexOf(root) === 0)) out.push(p.ProcessId); } return out; }",
|
||||
"log('begin');",
|
||||
"var promptFile = asar.replace(/app\\.asar$/i, 'app') + '\\\\dsh\\\\node_modules\\\\@deepseek-ai\\\\dsh-system-prompt\\\\lib\\\\index.js';",
|
||||
"var altFile = asar.replace(/app\\.asar$/i, 'app') + '\\\\node_modules\\\\@deepseek-ai\\\\dsh-system-prompt\\\\lib\\\\index.js';",
|
||||
"function readBody(file) { if (!fso.FileExists(file)) return ''; var tf = fso.OpenTextFile(file, 1); var body = tf.ReadAll(); tf.Close(); return body; }",
|
||||
"function hostClean(body) { if (!body) return null; var ident = body.indexOf('[dsh-purge] identity stripped') >= 0; var kept = body.indexOf('[dsh-purge] complete prompt keeps waterfall inject') >= 0 || body.indexOf('[dsh-purge] complete prompt keeps inject') >= 0; if (ident && kept) return true; if (body.indexOf('system-prompt/assemble') < 0) return false; var identityLeft = body.indexOf('You are an AI agent powered by DeepSeek Harness.') >= 0; var drops = body.indexOf('transformed.sections : [completeSection]') >= 0; return !identityLeft && !drops; }",
|
||||
"var clean = false;",
|
||||
"if (fso.FileExists(promptFile)) { var tf = fso.OpenTextFile(promptFile, 1); var body = tf.ReadAll(); tf.Close(); clean = body.indexOf('[dsh-purge] identity stripped') >= 0 && body.indexOf('[dsh-purge] complete prompt keeps inject') >= 0; }",
|
||||
"var primary = hostClean(readBody(promptFile));",
|
||||
"var alt = hostClean(readBody(altFile));",
|
||||
"clean = (primary == true || alt == true) && primary != false && alt != false;",
|
||||
"if (!clean) log('clean markers missing; not starting');",
|
||||
"if (clean) {",
|
||||
"log('clean markers ok');",
|
||||
@@ -1118,26 +1178,39 @@ function officialRestartScript(exe, asar, dshHome) {
|
||||
"if (!renamed) { log('rename failed; not starting'); }",
|
||||
"if (renamed) {",
|
||||
"try { sh.Environment('PROCESS').Remove('ELECTRON_RUN_AS_NODE'); } catch (ignore) {}",
|
||||
"try { sh.Environment('PROCESS').Remove('DSH_BASE'); } catch (ignoreBase) {}",
|
||||
"if (home) { try { sh.Environment('PROCESS').Item('DSH_HOME') = home; } catch (ignore2) {} }",
|
||||
"sh.Run('\"' + exe + '\"', 1, false);",
|
||||
"log('started');",
|
||||
"}",
|
||||
"}",
|
||||
"WScript.Sleep(180000);",
|
||||
"try { if (fso.FileExists(" + jsString(path.join(os.tmpdir(), "dsh-purge-official-restarting")) + ")) fso.DeleteFile(" + jsString(path.join(os.tmpdir(), "dsh-purge-official-restarting")) + ", true); } catch (ignoreFlag) {}",
|
||||
"",
|
||||
].join("\r\n");
|
||||
}
|
||||
|
||||
function unpackedHostIsClean(exe) {
|
||||
function systemPromptFiles(exe) {
|
||||
const appDir = appDirForExecutable(exe);
|
||||
if (!appDir) return false;
|
||||
const fp = path.join(appDir, "dsh", "node_modules", "@deepseek-ai", "dsh-system-prompt", "lib", "index.js");
|
||||
try {
|
||||
const text = fs.readFileSync(fp, "utf8");
|
||||
return text.includes("[dsh-purge] identity stripped")
|
||||
&& text.includes("[dsh-purge] complete prompt keeps inject");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
if (!appDir) return [];
|
||||
return [
|
||||
path.join(appDir, "dsh", "node_modules", "@deepseek-ai", "dsh-system-prompt", "lib", "index.js"),
|
||||
path.join(appDir, "node_modules", "@deepseek-ai", "dsh-system-prompt", "lib", "index.js"),
|
||||
].filter((fp) => {
|
||||
try { return fs.existsSync(fp); } catch { return false; }
|
||||
});
|
||||
}
|
||||
|
||||
function unpackedHostIsClean(exe) {
|
||||
const files = systemPromptFiles(exe);
|
||||
if (files.length === 0) return false;
|
||||
return files.every((fp) => {
|
||||
try {
|
||||
return hostPromptKeepsInject(fs.readFileSync(fp, "utf8"));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 点「重启」后结束当前官方客户端,挪开被占用的 app.asar,再自己打开。 */
|
||||
@@ -1167,6 +1240,15 @@ export function restartOfficialHarness(options = {}) {
|
||||
if (options.requireClean !== false && !unpackedHostIsClean(exe)) {
|
||||
return { restarting: false, clean: false };
|
||||
}
|
||||
const inflight = path.join(os.tmpdir(), "dsh-purge-official-restarting");
|
||||
try {
|
||||
const age = Date.now() - fs.statSync(inflight).mtimeMs;
|
||||
// 同一次换进程里不再开第二轮,避免杀掉刚拉起来的客户端。
|
||||
if (age >= 0 && age < 180000) return { restarting: true, already: true };
|
||||
} catch {
|
||||
// 没有进行中的重启。
|
||||
}
|
||||
try { fs.writeFileSync(inflight, `${Date.now()}\n`, "utf8"); } catch { /* 标记写失败仍继续这一次 */ }
|
||||
const asar = options.asar || appAsarPath(exe);
|
||||
const asarPresent = Boolean(asar && asarArchiveIsFile(asar));
|
||||
const swapLock = asar ? `${asar}.swap-lock` : "";
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/** 重启前看系统提示词文件:标记写上了,或者当前原文里已经没有那两处旧拦截。 */
|
||||
export function hostPromptKeepsInject(text) {
|
||||
const body = String(text || "");
|
||||
const identityMarked = body.includes("[dsh-purge] identity stripped");
|
||||
const injectMarked = body.includes("[dsh-purge] complete prompt keeps waterfall inject")
|
||||
|| body.includes("[dsh-purge] complete prompt keeps inject");
|
||||
if (identityMarked && injectMarked) return true;
|
||||
// 空文件或不是这份模块,不能当成已经洗过。
|
||||
if (!body.includes("system-prompt/assemble")) return false;
|
||||
const identityLeft = body.includes("You are an AI agent powered by DeepSeek Harness.");
|
||||
const dropsInject = body.includes("transformed.sections : [completeSection]");
|
||||
return !identityLeft && !dropsInject;
|
||||
}
|
||||
+160
-48
@@ -176,9 +176,13 @@ function injectAllowedNow(config) {
|
||||
return config.enabled !== false;
|
||||
}
|
||||
|
||||
/** 有默认提示词用默认,没有才用当前规则集。两边都空则段上不挂正文。 */
|
||||
/** 有磁盘提示词用磁盘,没有才用规则集,再没有就用内置默认。打开就能挂上。 */
|
||||
function refreshHungOperator(dshHome = core.findDshHome()) {
|
||||
const resolved = rules.resolveInjectText(dshHome);
|
||||
const home = dshHome || core.findDshHome();
|
||||
if (home) {
|
||||
try { core.seedOverrideSync(home); } catch { /* 默认写不进去时,组装仍会用内存里的内置正文 */ }
|
||||
}
|
||||
const resolved = rules.resolveInjectText(home);
|
||||
core.hangOperatorPrompt(resolved.text);
|
||||
return resolved;
|
||||
}
|
||||
@@ -192,7 +196,7 @@ function injectSnapshot(dshHome = core.findDshHome()) {
|
||||
};
|
||||
}
|
||||
|
||||
/** 框里有字用框;空框才看规则集;都没有则要求先写提示词。不看内置默认。 */
|
||||
/** 框里有字用框;空框才看规则集;都没有就用内置默认,不要求先点保存。 */
|
||||
function injectSnapshotFromBox(dshHome, boxText) {
|
||||
const ruleId = rules.activeRuleId(dshHome);
|
||||
if (typeof boxText === "string" && core.normalizeOverride(boxText)) {
|
||||
@@ -201,6 +205,9 @@ function injectSnapshotFromBox(dshHome, boxText) {
|
||||
if (core.normalizeOverride(rules.activeRuleText(dshHome))) {
|
||||
return { injectSource: "rule", injectRuleId: ruleId, needPrompt: false };
|
||||
}
|
||||
if (core.normalizeOverride(core.defaultOverrideText())) {
|
||||
return { injectSource: "default", injectRuleId: null, needPrompt: false };
|
||||
}
|
||||
if (typeof boxText !== "string") return injectSnapshot(dshHome);
|
||||
return { injectSource: "none", injectRuleId: ruleId, needPrompt: true };
|
||||
}
|
||||
@@ -223,8 +230,31 @@ async function ensureRestartReady() {
|
||||
return clean;
|
||||
}
|
||||
|
||||
/** 提示词服务自己的 ctx 多半没有 scope,段会进全局层。插件若挂在某个 scope 上,预设代理的父链看不到那一层。 */
|
||||
function addPromptSection(ctx, section) {
|
||||
const hosts = [];
|
||||
const push = (host) => {
|
||||
if (host && !hosts.includes(host)) hosts.push(host);
|
||||
};
|
||||
try { push(ctx?.systemPrompt?.ctx); } catch { /* 代理未注入时点属性会抛 */ }
|
||||
push(ctx);
|
||||
let registered = false;
|
||||
let lastError = null;
|
||||
for (const host of hosts) {
|
||||
try {
|
||||
host.systemPrompt.section(section);
|
||||
registered = true;
|
||||
} catch (error) {
|
||||
const msg = String(error && error.message || error);
|
||||
if (msg.includes("already registered")) registered = true;
|
||||
else lastError = error;
|
||||
}
|
||||
}
|
||||
if (!registered && lastError) throw lastError;
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, _injectFile) {
|
||||
ctx.systemPrompt.section({
|
||||
addPromptSection(ctx, {
|
||||
name: "dsh-purge",
|
||||
order: GLOBAL_PROMPT_ORDER + 1,
|
||||
interpolate: false,
|
||||
@@ -235,7 +265,7 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
});
|
||||
|
||||
if (config.capabilityProtocol !== false) {
|
||||
ctx.systemPrompt.section({
|
||||
addPromptSection(ctx, {
|
||||
name: CAPABILITY_SECTION,
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
interpolate: false,
|
||||
@@ -264,9 +294,13 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
}
|
||||
|
||||
function readInjectFallback(context) {
|
||||
const raw = core.hungOperatorPrompt();
|
||||
if (!String(raw || "").trim()) return "";
|
||||
return modePromptText(raw, isRedteamSession(context));
|
||||
let home = "";
|
||||
try { home = core.findDshHome(); } catch { home = ""; }
|
||||
const raw = rules.ensureOperatorBody(home);
|
||||
if (!raw) return "";
|
||||
let redteam = false;
|
||||
try { redteam = isRedteamSession(context); } catch { redteam = false; }
|
||||
return modePromptText(raw, redteam);
|
||||
}
|
||||
|
||||
function installMnemonMessageStrip(ctx, config = {}) {
|
||||
@@ -307,6 +341,21 @@ function rewriteLiveAssembly(config, assembled, context) {
|
||||
});
|
||||
}
|
||||
|
||||
/** 注册表若已经按旧文件算过 rev,立刻 rebuilt,让页面拿到的地址和缓存一致(#63)。 */
|
||||
function publishClientBundleRevs(ctx, packageNames) {
|
||||
if (!Array.isArray(packageNames) || packageNames.length === 0) return;
|
||||
let mods = null;
|
||||
try {
|
||||
mods = ctx?.get?.("clientModules", false);
|
||||
} catch {
|
||||
mods = null;
|
||||
}
|
||||
if (!mods || typeof mods.rebuilt !== "function") return;
|
||||
for (const id of packageNames) {
|
||||
try { mods.rebuilt(id); } catch { /* 这一包还没进注册表,下次快照会读到新文件 */ }
|
||||
}
|
||||
}
|
||||
|
||||
/** Cordis 的 ctx 是 Proxy:未声明 inject 时点属性会抛 "cannot get property ... without inject",所以两段都要包 try。 */
|
||||
function permissionPresetsOf(ctx) {
|
||||
try {
|
||||
@@ -393,6 +442,21 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
return rewriteLiveAssembly(config, assembled, context);
|
||||
}, { global: true, prepend: true });
|
||||
}
|
||||
// 切换预设会换掉 assemble。pre-step 瀑布在 assemble 之后才跑,第一次发送包不上。
|
||||
// 宿主在 assemble 之前调用这个函数,用的就是当前模式自己的 systemPrompt。
|
||||
const prepareAssemble = (loopCtx) => {
|
||||
try { rules.ensureOperatorBody(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
|
||||
const prompt = loopCtx && loopCtx.systemPrompt;
|
||||
if (prompt) {
|
||||
try {
|
||||
installAssembleGuard(prompt, (assembled, context) => (
|
||||
rewriteLiveAssembly(config, assembled, context)
|
||||
));
|
||||
} catch { /* 这一层代理包不上时,下面再包插件自己的 */ }
|
||||
}
|
||||
wrapAssemble();
|
||||
};
|
||||
globalThis.__dshPurgePrepareAssemble = prepareAssemble;
|
||||
// complete:true 会在 waterfall 之后盖掉 sections;包住 assemble 返回值,每轮都补回注入。
|
||||
wrapAssemble();
|
||||
const started = Date.now();
|
||||
@@ -403,6 +467,12 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
if (typeof timer.unref === "function") timer.unref();
|
||||
try { ctx.effect(() => () => clearInterval(timer)); } catch { /* 无 effect 时靠 unref */ }
|
||||
try { ctx.on("session/created", wrapAssemble); } catch { /* ignore */ }
|
||||
try {
|
||||
ctx.on("agent-preset/selected", () => {
|
||||
try { rules.ensureOperatorBody(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
|
||||
wrapAssemble();
|
||||
}, { global: true });
|
||||
} catch { /* ignore */ }
|
||||
try {
|
||||
ctx.on("agent/pre-step", (payload, next) => {
|
||||
wrapAssemble();
|
||||
@@ -446,6 +516,11 @@ async function settleInstalledPatches(config, ctx, life) {
|
||||
log(config, "sealed desktop: skip startup reapply (wait for Apply)");
|
||||
return "skip:sealed-wait-apply";
|
||||
}
|
||||
if (await reapply.hostCleanEnoughToKeep()) {
|
||||
reapply.markPatchesApplied();
|
||||
log(config, "host already clean; kept patches and refreshed stamp");
|
||||
return "already-clean";
|
||||
}
|
||||
if (officialUpdate.upgradeMarkerExists(process.execPath)) {
|
||||
const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, upgrade: true });
|
||||
if (life && !life.alive) return "skip:inactive";
|
||||
@@ -561,7 +636,7 @@ async function autoApply(config) {
|
||||
return "disabled";
|
||||
}
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const applied = report.filter((r) => r.status === "applied").length;
|
||||
@@ -573,6 +648,25 @@ async function autoApply(config) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 应用之后的那一次重启。密封包退出再打开,不再干等用户自己退出。 */
|
||||
function scheduleApplyRestart(shouldRestart) {
|
||||
if (!shouldRestart) return { restarting: false };
|
||||
if (core.desktopAsarStillSealed()) {
|
||||
const planned = core.restartSealedDesktopIfNeeded();
|
||||
return {
|
||||
...(planned || {}),
|
||||
restarting: Boolean(planned && (planned.restarting || planned.asarSwap)),
|
||||
};
|
||||
}
|
||||
try {
|
||||
const planned = hostctl.scheduleRestart(null, null);
|
||||
if (planned && (planned.restarting === false || planned.clean === false)) return planned;
|
||||
return planned || { restarting: true };
|
||||
} catch (error) {
|
||||
return { restarting: false, error: String(error && error.message ? error.message : error) };
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePurgeCommand(rawInput, config) {
|
||||
const args = (rawInput || "").trim().split(/\s+/).filter(Boolean);
|
||||
const sub = (args[0] || "status").toLowerCase();
|
||||
@@ -591,19 +685,15 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
const state = await core.gatherState();
|
||||
if (home) state.dsh_home = home;
|
||||
let handoff = null;
|
||||
if (!state.ai_base) {
|
||||
const opened = await core.openSealedDesktopHost();
|
||||
if (!opened.aiBase) return { kind: "error", text: core.missingAiBaseMessage() };
|
||||
state.ai_base = opened.aiBase;
|
||||
if (opened.swapAsar) handoff = opened;
|
||||
} else {
|
||||
handoff = core.sealedAsarHandoff();
|
||||
}
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||
if (blocked) return { kind: "error", text: blocked.error };
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
const shimResult = await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const lines = report.map((r) => {
|
||||
@@ -619,13 +709,26 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
lines.push("", "Desktop in-bin .bak scrub:");
|
||||
for (const row of scrubbed) lines.push(` ✓ ${row.dir} → ${row.cleaned.join(", ")}`);
|
||||
}
|
||||
lines.push("", "全部完成 / All done。重启 dsh 生效 / Restart dsh to take effect.");
|
||||
lines.push("Desktop: host-commands 密封目录只清理不注入;bak 禁止写进 bin(issue #9)。");
|
||||
if (handoff) {
|
||||
const swapped = core.scheduleSealedDesktopRestart(handoff);
|
||||
if (swapped?.renamed || swapped?.pending) {
|
||||
lines.push("", "补丁已写入。请在设置页点「重启」,客户端会自己重新打开。");
|
||||
}
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true;
|
||||
const shouldRestart = applyShouldRestart({
|
||||
complete,
|
||||
sealed: core.desktopAsarStillSealed(),
|
||||
appliedCount: summary.applied,
|
||||
});
|
||||
if (shouldRestart) reapply.markSettleRestart();
|
||||
const planned = scheduleApplyRestart(shouldRestart);
|
||||
if (planned && planned.clean === false) {
|
||||
lines.push("", "清洗没有写进当前宿主,已取消重启。");
|
||||
} else if (planned && planned.restarting === false && planned.error) {
|
||||
lines.push("", String(planned.error));
|
||||
} else if (shouldRestart && planned && planned.restarting !== false) {
|
||||
lines.push("", "正在重启。");
|
||||
} else if (!complete) {
|
||||
lines.push("", "清洗没有完成,没有重启。");
|
||||
} else {
|
||||
lines.push("", "补丁已经在宿主里,不再重启。");
|
||||
}
|
||||
return { kind: "success", text: lines.join("\n") };
|
||||
}
|
||||
@@ -928,7 +1031,18 @@ export function apply(ctx, config) {
|
||||
console.warn("[dsh-purge] hide-console error:", String(e));
|
||||
}
|
||||
core.applyRuntimeEnv();
|
||||
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词时段上留空 */ }
|
||||
// 页面打开前写前端 client.js。settle 在数秒之后,那时再写会让已发出的 rev 404(#63)。
|
||||
try {
|
||||
const written = core.patchWatchedClientBundlesSync();
|
||||
publishClientBundleRevs(ctx, written);
|
||||
if (written.length) log(cfg, "client bundles patched before page:", written.join(","));
|
||||
} catch (e) {
|
||||
console.warn("[dsh-purge] client bundle boot patch:", String(e && e.message ? e.message : e));
|
||||
}
|
||||
try {
|
||||
const home = core.pinDshHome() || core.findDshHome();
|
||||
refreshHungOperator(home);
|
||||
} catch { /* 主目录还没有提示词时,组装会再挂内置默认 */ }
|
||||
try {
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
if (scrubbed.length) log(cfg, "desktop runtime scrub on load:", JSON.stringify(scrubbed));
|
||||
@@ -1107,7 +1221,7 @@ function applyHostHooks(ctx, cfg) {
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||
if (blocked) return { text: "ERROR: " + blocked.error };
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const applied = report.filter((r) => r.status === "applied").length;
|
||||
@@ -1238,6 +1352,11 @@ function installWebServer(ctx, cfg) {
|
||||
patches_total: state.ai_base ? (state.patches_total || 0) : 0,
|
||||
patches_lost: reapply.patchesLostAfterHostReset(),
|
||||
patch_status: state.patch_status,
|
||||
patches: core.ALL_PATCHES.map((p) => ({
|
||||
id: p.id,
|
||||
layer: p.layer || "",
|
||||
status: state.patch_status[p.id] || (state.ai_base ? "missing_file" : "unlocated"),
|
||||
})).filter((p) => p.status !== "na"),
|
||||
patch_names,
|
||||
shim_cmd: state.shim_cmd,
|
||||
shim_ps1: state.shim_ps1,
|
||||
@@ -1474,10 +1593,12 @@ function installWebServer(ctx, cfg) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (incoming !== null) await core.saveOverrideContent(state.dsh_home, incoming);
|
||||
if (incoming !== null && core.normalizeOverride(incoming)) {
|
||||
await core.saveOverrideContent(state.dsh_home, incoming);
|
||||
}
|
||||
refreshHungOperator(state.dsh_home);
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
const override = await core.readOverrideForUi(state.dsh_home);
|
||||
const shim = await core.patchAllShims();
|
||||
let cliRepair = null;
|
||||
@@ -1489,20 +1610,16 @@ function installWebServer(ctx, cfg) {
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true;
|
||||
let renamed = false;
|
||||
let pendingQuit = false;
|
||||
if (handoff) {
|
||||
if (core.desktopAsarStillSealed()) {
|
||||
// 仍在读 app.asar:不要先挂 idle-rename(易留下 rename-pending 且与 wscript 重启抢锁)。
|
||||
pendingQuit = true;
|
||||
} else {
|
||||
const swapped = core.scheduleSealedDesktopRestart(handoff);
|
||||
renamed = Boolean(swapped?.renamed);
|
||||
pendingQuit = Boolean(swapped?.pending);
|
||||
}
|
||||
if (handoff && core.desktopAsarStillSealed()) {
|
||||
// 仍在读 app.asar:等这次响应发出后由重启接口退出再打开,不要先挂 idle-rename。
|
||||
pendingQuit = true;
|
||||
}
|
||||
const leaveTray = pendingQuit;
|
||||
const onlyUnmatched = summary.failed.every((item) => item.status === "pattern_not_found");
|
||||
if (flash.ok === true && onlyUnmatched && core.hostCleanMarkersPresent(state.ai_base)) {
|
||||
reapply.markPatchesApplied();
|
||||
}
|
||||
const leaveTray = renamed || pendingQuit;
|
||||
if (complete) reapply.markPatchesApplied();
|
||||
if (leaveTray) bootFullQuit = true;
|
||||
const sealedNow = core.desktopAsarStillSealed();
|
||||
const shouldRestart = applyShouldRestart({
|
||||
@@ -1539,15 +1656,6 @@ function installWebServer(ctx, cfg) {
|
||||
cli_repair: cliRepair,
|
||||
cmd_flash: flash,
|
||||
});
|
||||
if (shouldRestart && handoff && sealedNow) {
|
||||
setImmediate(() => {
|
||||
try {
|
||||
core.restartSealedDesktopIfNeeded();
|
||||
} catch (e) {
|
||||
console.warn("[dsh-purge] asar swap after apply failed:", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
@@ -1734,14 +1842,18 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
// 用户已点重启:清掉粘性标记,避免同进程误刷新/再进面板又弹一次。
|
||||
bootFullQuit = false;
|
||||
const restarting = Boolean(planned && (planned.restarting || planned.asarSwap));
|
||||
const restartError = planned && planned.error ? String(planned.error) : "";
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
ok: restarting || !restartError,
|
||||
surface,
|
||||
fullApp: surface === "desktop",
|
||||
restarting: Boolean(planned && (planned.restarting || planned.asarSwap)),
|
||||
restarting,
|
||||
already: Boolean(planned && planned.already),
|
||||
needsFullQuit: Boolean(planned && planned.asarSwap),
|
||||
asar_still_sealed: core.desktopAsarStillSealed(),
|
||||
note: "正在重启。",
|
||||
error: restartError || undefined,
|
||||
note: restarting ? "正在重启。" : restartError,
|
||||
});
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
|
||||
+19
-2
@@ -128,6 +128,22 @@ export function patchesMatchInstall() {
|
||||
return hostStillHasAppliedPatches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 宿主上的清洗还在,只是版本戳旧了。启动时不能因此 revertAll,
|
||||
* 否则用户点应用并重启后,页面会回到「要重新清洗」。
|
||||
*/
|
||||
export async function hostCleanEnoughToKeep() {
|
||||
let aiBase = "";
|
||||
try {
|
||||
aiBase = core.findAiBase() || "";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
if (!aiBase || !core.hostCleanMarkersPresent(aiBase)) return false;
|
||||
const status = await core.patchStatus(aiBase);
|
||||
return !Object.values(status).some((row) => row === "pending");
|
||||
}
|
||||
|
||||
/** 有 applied 戳但宿主已回到密封 asar / 清洗标记没了:面板提示「补丁已丢失」(#57)。找不到根不算丢失。 */
|
||||
export function patchesLostAfterHostReset() {
|
||||
const stamp = readAppliedStamp();
|
||||
@@ -251,10 +267,11 @@ export async function reapplyInstalled(options = {}) {
|
||||
}
|
||||
if (!aiBase) return { ok: false, error: core.missingAiBaseMessage() };
|
||||
// 刚解开的是官方原件。已经在用的目录仍先还原再按这一版重打。
|
||||
const reverted = freshExtract ? { reverted: [] } : await core.revertAll(aiBase);
|
||||
const preserveClientBundles = options.preserveClientBundles !== false;
|
||||
const reverted = freshExtract ? { reverted: [] } : await core.revertAll(aiBase, { preserveClientBundles });
|
||||
if (!freshExtract) await core.revertAllShims();
|
||||
await core.backupAll(aiBase);
|
||||
const report = await core.applyPatches(aiBase);
|
||||
const report = await core.applyPatches(aiBase, core.ALL_PATCHES, { preserveClientBundles });
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(aiBase);
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
|
||||
@@ -28,7 +28,7 @@ window.__ModuleLoader__.load({
|
||||
这里放占位符,由 bundle 的 build.mjs 在生成 lib/client.js 时替换成正文。 */
|
||||
const CSS = `
|
||||
:root{--rt-dock-w:620px}
|
||||
/* 右侧栏收起时给 frame 加内边距,中栏主动收窄。属性名跨 DSH 版本兼容:\n 旧版 details 栏 data-details-collapsed,新版 rightbar 栏 data-rightbar-collapsed。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-details-collapsed],\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-rightbar-collapsed]{padding-right:var(--rt-dock-w)}
|
||||
/* 右侧栏收起时给 frame 加内边距,中栏主动收窄。属性名跨 DSH 版本兼容:\n 旧版 details 栏 data-details-collapsed,新版 rightbar 栏 data-rightbar-collapsed。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-details-collapsed],\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-rightbar-collapsed]{padding-right:var(--rt-dock-w)}
|
||||
.rt-dock{position:absolute;top:0;right:0;bottom:0;z-index:20;display:flex;flex-direction:column;
|
||||
background:color-mix(in srgb,var(--dsw-alias-bg-layer-1,#1c1c1c) 52%,transparent);
|
||||
backdrop-filter:blur(20px) saturate(1.3);-webkit-backdrop-filter:blur(20px) saturate(1.3);
|
||||
@@ -36,7 +36,7 @@ window.__ModuleLoader__.load({
|
||||
box-shadow:-12px 0 32px color-mix(in srgb,#000 22%,transparent);pointer-events:auto;color:var(--dsw-alias-label-primary);
|
||||
font-size:13px;line-height:1.5;transition:transform .18s ease,opacity .18s ease}
|
||||
.rt-dock.rt-embedded{position:relative;background:transparent!important;border:0;box-shadow:none;backdrop-filter:none;-webkit-backdrop-filter:none}
|
||||
/* 右侧栏打开(或新版全屏)时让位:滑出隐藏。必须同时否定两个属性名——\n 旧写法只用 :not([data-details-collapsed]),在新 shell 里该属性不存在会导致条件恒真、面板永远打不开。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]):not([data-details-collapsed]):not([data-rightbar-collapsed]) .rt-dock,\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-rightbar-fullscreen] .rt-dock{
|
||||
/* 右侧栏打开(或新版全屏)时让位:滑出隐藏。必须同时否定两个属性名——\n 旧写法只用 :not([data-details-collapsed]),在新 shell 里该属性不存在会导致条件恒真、面板永远打不开。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded)):not([data-details-collapsed]):not([data-rightbar-collapsed]) .rt-dock,\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-rightbar-fullscreen] .rt-dock{
|
||||
transform:translateX(100%);opacity:0;pointer-events:none}
|
||||
.rt-grip{position:absolute;left:-3px;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:2}
|
||||
.rt-head{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--dsw-alias-border-l1)}
|
||||
|
||||
+47
-2
@@ -145,9 +145,40 @@ function listDarwinPids(exe) {
|
||||
return [...new Set(pids)];
|
||||
}
|
||||
|
||||
function commandMatchesExe(cmd, exe) {
|
||||
if (!cmd || !exe) return false;
|
||||
if (cmd.includes("/dsh-desktop-host/lib/cli.js")) return false;
|
||||
return cmd === exe || cmd.startsWith(`${exe} `) || cmd.startsWith(`${exe}\t`);
|
||||
}
|
||||
|
||||
function listPosixPids(exe) {
|
||||
if (!exe) return [];
|
||||
let out = "";
|
||||
try {
|
||||
out = execFileSync("ps", ["-Ao", "pid=,command="], {
|
||||
encoding: "utf8",
|
||||
timeout: 8000,
|
||||
});
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
const pids = [];
|
||||
for (const line of String(out || "").split(/\n/)) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
const sp = trimmed.search(/\s/);
|
||||
if (sp < 0) continue;
|
||||
const pid = Number(trimmed.slice(0, sp).trim());
|
||||
const cmd = trimmed.slice(sp + 1).trim();
|
||||
if (!pid || !commandMatchesExe(cmd, exe)) continue;
|
||||
pids.push(pid);
|
||||
}
|
||||
return [...new Set(pids)];
|
||||
}
|
||||
|
||||
function listDesktopPids(exe = info.execPath) {
|
||||
if (process.platform === "darwin") return listDarwinPids(exe);
|
||||
if (process.platform !== "win32") return [];
|
||||
if (process.platform !== "win32") return listPosixPids(exe);
|
||||
const images = ["DeepSeek Harness.exe", "DSH Desktop.exe"];
|
||||
const pids = [];
|
||||
for (const image of images) {
|
||||
@@ -181,6 +212,18 @@ async function waitDesktopGone(exe, timeoutMs = 8000) {
|
||||
return listDesktopPids(exe).filter((pid) => pid !== process.pid).length === 0;
|
||||
}
|
||||
|
||||
async function quitPosixDesktop(exe) {
|
||||
signalPids(listDesktopPids(exe), "SIGTERM");
|
||||
if (await waitDesktopGone(exe, 8000)) {
|
||||
log("quit by SIGTERM");
|
||||
return "SIGTERM";
|
||||
}
|
||||
signalPids(listDesktopPids(exe), "SIGKILL");
|
||||
await waitDesktopGone(exe, 2000);
|
||||
log("quit by SIGKILL");
|
||||
return "SIGKILL";
|
||||
}
|
||||
|
||||
async function quitDarwinDesktop(exe) {
|
||||
const bundle = darwinBundleOf(exe);
|
||||
const name = darwinBundleName(bundle);
|
||||
@@ -293,9 +336,11 @@ if (info.killApp) {
|
||||
}
|
||||
if (process.platform === "darwin") {
|
||||
await quitDarwinDesktop(info.execPath);
|
||||
} else {
|
||||
} else if (process.platform === "win32") {
|
||||
killOtherDesktopProcesses(process.pid);
|
||||
await sleep(500);
|
||||
} else {
|
||||
await quitPosixDesktop(info.execPath);
|
||||
}
|
||||
if (info.asar) await moveAsarAsideAsync(info.asar);
|
||||
} else {
|
||||
|
||||
+23
-3
@@ -1,7 +1,15 @@
|
||||
import fs from "node:fs";
|
||||
import { promises as fsp } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { findDshHome, findOverrideFile, normalizeOverride, peekCommittedOverride } from "./core.js";
|
||||
import {
|
||||
findDshHome,
|
||||
findOverrideFile,
|
||||
defaultOverrideText,
|
||||
hangOperatorPrompt,
|
||||
hungOperatorPrompt,
|
||||
normalizeOverride,
|
||||
peekCommittedOverride,
|
||||
} from "./core.js";
|
||||
import { modePromptText } from "./identity.js";
|
||||
|
||||
const RULE_ID_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
|
||||
@@ -184,20 +192,32 @@ export function overrideFileText(dshHome) {
|
||||
|
||||
function diskPrompt(dshHome) {
|
||||
const pinned = peekCommittedOverride(dshHome);
|
||||
if (typeof pinned === "string") return normalizeOverride(pinned);
|
||||
if (typeof pinned === "string" && normalizeOverride(pinned)) return normalizeOverride(pinned);
|
||||
return normalizeOverride(overrideFileText(dshHome));
|
||||
}
|
||||
|
||||
/** 磁盘上的提示词优先;没有则用当前规则集;两边都没有则不注入。不回落内置默认。 */
|
||||
/** 磁盘上的提示词优先;没有则用当前规则集;两边都没有就用内置默认。不需要先点保存。 */
|
||||
export function resolveInjectText(dshHome) {
|
||||
const prompt = diskPrompt(dshHome);
|
||||
if (prompt) return { text: prompt, source: "prompt", ruleId: null };
|
||||
const ruleId = activeRuleId(dshHome);
|
||||
const rule = normalizeOverride(activeRuleText(dshHome));
|
||||
if (rule) return { text: rule, source: "rule", ruleId };
|
||||
const bundled = normalizeOverride(defaultOverrideText());
|
||||
if (bundled) return { text: bundled, source: "default", ruleId: null };
|
||||
return { text: "", source: "none", ruleId };
|
||||
}
|
||||
|
||||
/**
|
||||
* 每次组装都按当前主目录重读。重启后的空内存不能挡住磁盘或内置默认。
|
||||
* 磁盘和规则集都没有时挂内置默认,打开、应用、重启都不用再点保存。
|
||||
*/
|
||||
export function ensureOperatorBody(dshHome) {
|
||||
const resolved = resolveInjectText(dshHome);
|
||||
if (resolved.text) hangOperatorPrompt(resolved.text);
|
||||
return resolved.text || normalizeOverride(hungOperatorPrompt()) || "";
|
||||
}
|
||||
|
||||
/** 官方和红队同一顺序。红队再去掉 CTF。没有正文时不注入操作者段。 */
|
||||
export function resolveModeInject(dshHome, redteam) {
|
||||
const resolved = resolveInjectText(dshHome);
|
||||
|
||||
+20
-28
@@ -633,34 +633,26 @@ export function markCurrent(versions, state, localVer, localSha) {
|
||||
const pin = String(state?.pin || "");
|
||||
const rows = versions || [];
|
||||
const ver = String(localVer || "").replace(/^v/i, "");
|
||||
const shaMatched = rows.some((item) => localSha && item.sha && sameRev(localSha, item.sha));
|
||||
const versionOnLatest = rows.some((item) => (
|
||||
item.latest
|
||||
&& item.channel === state?.channel
|
||||
&& String(item.version || "").replace(/^v/i, "") === ver
|
||||
));
|
||||
const versionFallback = versionOnLatest ? null : rows.find((item) => (
|
||||
item.channel === state?.channel
|
||||
&& String(item.version || "").replace(/^v/i, "") === ver
|
||||
));
|
||||
return rows.map((item) => {
|
||||
const shaHit = Boolean(!pin && localSha && item.sha && sameRev(localSha, item.sha));
|
||||
const pinHit = Boolean(pin && item.ref === pin);
|
||||
// 提交号对不上时,只把本通道里和本机版本号相同的那一条标成当前。
|
||||
const headHit = Boolean(
|
||||
!pin
|
||||
&& !shaMatched
|
||||
&& ver
|
||||
&& (versionOnLatest
|
||||
? item.latest && item.channel === state?.channel && String(item.version || "").replace(/^v/i, "") === ver
|
||||
: versionFallback && item === versionFallback)
|
||||
);
|
||||
return {
|
||||
...item,
|
||||
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
|
||||
current: pinHit || shaHit || headHit,
|
||||
};
|
||||
});
|
||||
const channel = state?.channel || "stable";
|
||||
const sameVersion = (item) => ver && String(item?.version || "").replace(/^v/i, "") === ver && item.channel === channel;
|
||||
const sameSha = (item) => Boolean(localSha && item?.sha && sameRev(localSha, item.sha));
|
||||
let chosen = null;
|
||||
if (pin) {
|
||||
chosen = rows.find((item) => item.ref === pin) || null;
|
||||
} else {
|
||||
const pool = rows.filter(sameVersion);
|
||||
// 安装记录里的旧提交号不能把较低版本标成当前。只认和正在跑的 package.json 相同的版本。
|
||||
chosen = pool.find((item) => sameSha(item) && (item.latest || item.ref === "master" || item.kind === "head"))
|
||||
|| pool.find((item) => item.latest || item.ref === "master" || item.kind === "head")
|
||||
|| pool.find((item) => sameSha(item))
|
||||
|| pool[0]
|
||||
|| null;
|
||||
}
|
||||
return rows.map((item) => ({
|
||||
...item,
|
||||
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
|
||||
current: Boolean(chosen && item === chosen),
|
||||
}));
|
||||
}
|
||||
|
||||
async function listGithubTags() {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.57",
|
||||
"version": "1.1.59",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
|
||||
@@ -1,3 +1,35 @@
|
||||
# 1.1.59
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本升级到 1.1.59。
|
||||
- 点应用后不再因为宿主路径或旧标记对不上,就报「清洗没有写进当前宿主」(#65)。
|
||||
- `resources\app\node_modules` 和 `resources\app\dsh\node_modules` 都认。原文里已经没有官方身份句、也没有丢掉注入的写法时,不再要求那两条标记。
|
||||
- complete 段补丁同时认 tab 和空格。
|
||||
|
||||
## English
|
||||
|
||||
- Version 1.1.59.
|
||||
- Apply no longer reports that the clean missed the current host just because the package path or the old markers do not match (#65).
|
||||
- Both `resources/app/node_modules` and `resources/app/dsh/node_modules` count. If the official identity sentence and the inject-dropping return are already gone, those two markers are not required.
|
||||
- The complete-prompt patch matches both tab and space indentation.
|
||||
|
||||
# 1.1.58
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本升级到 1.1.58。
|
||||
- 打开、应用、重启都会挂上提示词。磁盘上有正文就用磁盘,没有就用规则集,再没有就用内置默认,不用再点保存。
|
||||
- 启动不再在页面发出之后改写前端 client.js,避免输入框因模块版本号对不上而消失(#63)。
|
||||
- macOS / Linux 已解包桌面端点应用后会退出并重新打开;清洗标记两种写法都认(#64)。
|
||||
|
||||
## English
|
||||
|
||||
- Version 1.1.58.
|
||||
- Open, Apply, and restart all hang the prompt. A saved file wins, then the active rule set, then the built-in default. Save is not required.
|
||||
- Startup no longer rewrites frontend client.js after the page has taken a module revision, so the composer does not disappear (#63).
|
||||
- Unpacked macOS and Linux desktop builds quit and relaunch after Apply. Both inject markers count as clean (#64).
|
||||
|
||||
# 1.1.57
|
||||
|
||||
## 中文
|
||||
|
||||
Reference in new issue
Block a user