mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 15:50:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fedda6d338 | ||
|
|
6a6293524a | ||
|
|
0b55914487 | ||
|
|
5c5fff5c70 | ||
|
|
b2fb8e83c8 |
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.9</strong></p>
|
||||
<p align="center"><strong>Version 1.1.10</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>Local official DeepSeek Harness cybersecurity red-team plugin: evaluate and harden host safety policy in a controlled local install; swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐</em>
|
||||
@@ -35,11 +35,14 @@
|
||||
|
||||
## ☕ Sponsor
|
||||
|
||||
If dsh-purge helps you, a tip is welcome.
|
||||
If this project helps you, send it over — I'm out here asking~
|
||||
|
||||
<p align="center">
|
||||
<img src="docs/appreciate.png" alt="WeChat appreciate" width="360">
|
||||
</p>
|
||||
| Asset | Address |
|
||||
|---|---|
|
||||
| **USDT (TRC20)** | `TV5ajPkRD8RH623Dx9mqvYZVNN8nPGRKid` |
|
||||
| **Solana** | `6x16GhRgLVpKFFXaU1seKNdx2rypspSJTL4dbpt6Xpwk` |
|
||||
| **Ethereum** | `0xB68BD60C0e8c519513B7DF9bB147696815423B3E` |
|
||||
| **Bitcoin** | `bc1qu70yxkrtwnymt8ryluz9x8y8hqzune5340npht` |
|
||||
|
||||
<p align="center">
|
||||
<sub>Built by 小杨 · for DeepSeek Harness</sub>
|
||||
@@ -63,29 +66,29 @@ This is a **local official DeepSeek Harness cybersecurity red-team plugin**. It
|
||||
|
||||
<div>
|
||||
|
||||
### ⚠️ <font color="red">严正法律免责与合规使用声明(Strict Legal & Compliance Disclaimer)</font>
|
||||
### ⚠️ <font color="red">Strict legal and compliance disclaimer</font>
|
||||
|
||||
<font color="red">
|
||||
|
||||
**【零容忍严正申明】**:本项目坚决反对并严禁任何形式的违法犯罪行为!本项目开发者绝不支持、不鼓励、不协助任何未授权网络攻击、漏洞利用、数据窃取、非法侵入计算机信息系统或生成违法违禁内容的活动。**任何将本项目用于违法犯罪的行为,均与开发者无关,由行为人依法独立承担全部法律责任。**
|
||||
**Zero-tolerance statement:** This project opposes and forbids any illegal activity. The authors do not support, encourage, or assist unauthorized network attacks, exploit use, data theft, unlawful intrusion into computer information systems, or generation of illegal or prohibited content. **Anyone who uses this project for crime is solely responsible under the law. The authors have no liability.**
|
||||
|
||||
1. **本仓库不含违法内容**:`dsh-purge` 发布的代码、文档、补丁与默认提示词**不是**木马、后门、未授权渗透工具、勒索软件、撞库脚本,也**不是**针对公网或第三方系统的攻击载荷。项目本身不提供违法内容,也不教唆、组织、协助实施违法犯罪。
|
||||
2. **只作用于本机官方 Harness**:清洗、补丁、提示词注入全部发生在使用者**本机已安装的官方 DeepSeek Harness**(`@deepseek-ai` 包、本机 profile / `$DSH_HOME`)上。对象是使用者自己的官方本地软件,**不是**他人的网站、服务器、账号或信息系统。
|
||||
3. **清洗不对外网目标联网**:应用补丁、写入注入、回滚、卸载均在本机文件与本机进程内完成,**不对任何公网主机、未授权系统进行扫描、探测、入侵或攻击发包**。不得把本项目当作跳板去打外网。插件若开启「检测更新」,仅可能访问本插件自己的 GitHub 仓库以核对版本,**与对第三方系统的网络攻击无关**,也不能被解释为授权对外渗透。
|
||||
4. **合法受控范围限定**:本项目定位为使用者在**自己有权管理的本机官方 Harness**上,进行红队科研与鲁棒性评测的辅助工具。**严禁在未经所有者合法书面授权的目标、公网在线系统或生产业务上运行本项目**。一切测试必须限制在**本机已授权安装的官方 Harness、离线本地合成靶标(Local Synthetic Fixtures)、授权网络安全演练靶场及合规实验室受控环境**中进行。
|
||||
5. **严禁违法与违禁用途**:使用者严禁利用本项目直接或间接从事任何违反下列法律法规的行为(必须逐条遵守,不得以任何理由规避):
|
||||
- <font color="red"><strong>《中华人民共和国刑法》</strong></font>
|
||||
- <font color="red"><strong>《中华人民共和国网络安全法》</strong></font>
|
||||
- <font color="red"><strong>《中华人民共和国数据安全法》</strong></font>
|
||||
- <font color="red"><strong>《中华人民共和国个人信息保护法》</strong></font>
|
||||
- 以及其他现行有效的法律、行政法规与监管规定;
|
||||
- 同时严禁:
|
||||
- 未经授权渗透、攻击公私机构计算机信息系统,实施勒索、破坏、撞库或传播恶意载荷;
|
||||
- 诱导、生成或传播危害国家安全、恐怖主义、暴力血腥、涉黄涉赌、诈骗、侵犯公民隐私或知识产权等任何法律明令禁止的违法违禁内容;
|
||||
- 违反相关大模型提供商的《服务条款(Terms of Service)》与《滥用政策(Usage Policy)》。
|
||||
6. **使用者独立承担全部责任**:本项目依据 MIT 开源协议“按现状(AS-IS)”提供,开发者不对软件的完整性、安全性与适用性作任何明示或暗示的保证。**使用者应对自身的所有下载、部署、运行、修改、传播行为以及由此产生的全部输入与输出后果承担独立、完全的民事、行政及刑事法律责任**。项目作者与贡献团队绝不承担任何因使用者滥用导致的直接、间接或连带责任。
|
||||
7. **违约即终止授权**:任何将本项目用于非法攻击、恶意活动或违规行为的个人或实体,其开源软件使用许可将自违法违规行为发生之日起**自动且不可撤销地立即终止**。该主体须立即停止使用并永久销毁本项目的所有代码、脚本与衍生数据,并依法承担相应法律制裁。
|
||||
8. **第三方独立性声明**:本项目属于完全独立的开源安全评测研究项目,与 DeepSeek 官方或其关联主体无任何隶属、商业合作、授权或官方背书关系。文中「官方」仅指清洗对象为使用者本机安装的官方 DeepSeek Harness 软件包,**不代表** DeepSeek 官方开发、认可或担保本插件。
|
||||
1. **This repository contains no illegal material.** The published code, docs, patches, and default prompt are **not** malware, backdoors, unauthorized pentest kits, ransomware, credential-stuffing scripts, or attack payloads aimed at the public internet or third-party systems. The project does not supply illegal content and does not incite, organize, or assist crime.
|
||||
2. **Local official Harness only.** Security-eval patches and prompt injection run only on the **official DeepSeek Harness already installed on the user's machine** (`@deepseek-ai` packages, local profile / `$DSH_HOME`). The target is the user's own official local software, **not** someone else's website, server, account, or information system.
|
||||
3. **Eval patches do not attack the public internet.** Apply, inject, revert, and uninstall stay in local files and local processes. They **do not scan, probe, intrude, or send attack traffic to any public host or unauthorized system**. Do not use this project as a jump host against the public internet. If "check for updates" is on, the plugin may only contact this plugin's own GitHub repository to compare versions. That is **not** an attack on third-party systems and is **not** authorization to penetrate anything.
|
||||
4. **Lawful, controlled scope.** This project is an aid for red-team research and robustness evaluation on an **official Harness the user is entitled to administer**. **Do not run it against targets without the owner's lawful written authorization, public online systems, or production workloads.** Testing must stay on the **authorized local official Harness, offline local synthetic fixtures, authorized cybersecurity ranges, and compliant lab environments**.
|
||||
5. **Forbidden uses.** Users must not use this project, directly or indirectly, to violate the following (each must be followed; no excuse to evade):
|
||||
- <font color="red"><strong>Criminal Law of the People's Republic of China</strong></font>
|
||||
- <font color="red"><strong>Cybersecurity Law of the People's Republic of China</strong></font>
|
||||
- <font color="red"><strong>Data Security Law of the People's Republic of China</strong></font>
|
||||
- <font color="red"><strong>Personal Information Protection Law of the People's Republic of China</strong></font>
|
||||
- and other applicable laws, regulations, and supervisory rules;
|
||||
- Also forbidden:
|
||||
- Unauthorized intrusion or attacks on public or private computer information systems; extortion, sabotage, credential stuffing, or spreading malicious payloads;
|
||||
- Inducing, generating, or spreading any content the law forbids, including threats to national security, terrorism, violence, pornography, gambling, fraud, and privacy or intellectual-property infringement;
|
||||
- Violating the model provider's terms of service and acceptable-use policy.
|
||||
6. **The user bears all responsibility.** The project is provided under the MIT license as-is. The authors make no warranty of completeness, security, or fitness. **Users independently bear all civil, administrative, and criminal liability** for download, deploy, run, modify, distribute, and all resulting inputs and outputs. Authors and contributors bear no direct, indirect, or joint liability for abuse.
|
||||
7. **The license ends on breach.** Anyone who uses this project for illegal attacks, malicious activity, or other violations has their open-source license **automatically and irrevocably terminated** from the moment of the violation. They must stop using the project, permanently destroy all copies and derivatives, and accept legal sanctions.
|
||||
8. **No affiliation.** This is an independent open-source security-eval research project. It has no employment, commercial, authorization, or endorsement relationship with DeepSeek or its affiliates. "Official" here only means the eval target is the official DeepSeek Harness package on the user's machine. It does **not** mean DeepSeek developed, approved, or warrants this plugin.
|
||||
|
||||
</font>
|
||||
|
||||
@@ -111,9 +114,7 @@ After install:
|
||||
|
||||
Web **Apply / Restart / Uninstall** affect Web only. Desktop **Apply / Restart / Uninstall** affect the desktop app only — they do not launch `dsh web`.
|
||||
|
||||
> 🌐 **Plugin hub:** [DeepSeek Harness Hub](https://deepseek.stream/plugins/dsh-purge) (docs only — **do not** install via `deepseek.stream/api/plugins/download?...`; that URL is not a pnpm tarball and fails with `ERR_PNPM_TARBALL_EXTRACT`)
|
||||
>
|
||||
> `dsh plugin add <url>` hands the URL to pnpm as a **remote tarball**. Use GitHub `master.tar.gz`. A `.zip` archive is ZIP, not gzip, and fails with `ERR_PNPM_TARBALL_DECODE_GZIP` ([#26](https://github.com/YuJunZhiXue/dsh-purge/issues/26)).
|
||||
> 🌐 **Plugin hub:** [DeepSeek Harness Hub](https://deepseek.stream/plugins/dsh-purge) (docs only — **do not** install via `deepseek.stream/api/plugins/download?...`)
|
||||
|
||||
### Web (default)
|
||||
|
||||
@@ -243,13 +244,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.9&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.10&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.9&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.10&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
|
||||
```
|
||||
|
||||
**Web trigger example:**
|
||||
@@ -262,7 +263,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.9',
|
||||
version: '1.1.10',
|
||||
repo: 'YuJunZhiXue/dsh-purge',
|
||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||
@@ -281,7 +282,7 @@ export function installDshPurgeToDesktop() {
|
||||
**HTML link:**
|
||||
|
||||
```html
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.9&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.10&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>
|
||||
```
|
||||
@@ -292,58 +293,150 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | Plugin id |
|
||||
| name | `dsh-purge` | Display name |
|
||||
| version | `1.1.9` | Semver |
|
||||
| version | `1.1.10` | Semver |
|
||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub repo |
|
||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub tarball (not `.zip`) |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub source archive |
|
||||
|
||||
### Manual install
|
||||
|
||||
Use this when `dsh` is not on `PATH` or you do not want `dsh plugin add`. Edit the profile for that host. Do **not** delete existing bundles.
|
||||
Use this when `dsh` is not on `PATH`, official `dsh plugin add` fails, or you do not want a remote install. Edit **only the profile for the host you are using**. Do **not** delete existing bundles. Do not edit Web and Desktop in the same pass.
|
||||
|
||||
**1. Find the Harness home (`$DSH_HOME`)**
|
||||
**0. Pick one host, one profile**
|
||||
|
||||
| Layout | Typical path |
|
||||
|---|---|
|
||||
| Env | `DSH_HOME` if set (community Desktop host-commands also set this) |
|
||||
| Windows portable | `.dsh` next to `npm-global` |
|
||||
| User default | Windows `%USERPROFILE%\.dsh`; Linux / macOS `~/.dsh` |
|
||||
| What you actually run | Edit only this directory | Leave alone |
|
||||
|---|---|---|
|
||||
| Official `dsh web` | `$DSH_HOME/profiles/web` | `desktop`, `default` |
|
||||
| Community [DSH Desktop](https://github.com/anywhere-labs/dsh-desktop) | `$DSH_HOME/profiles/desktop` | `web`, `default` |
|
||||
| Official Harness desktop EXE | `$DSH_HOME/profiles/default` | `web`, `desktop` |
|
||||
|
||||
| Host | Profile directory |
|
||||
|---|---|
|
||||
| Official Web | `$DSH_HOME/profiles/web` |
|
||||
| Official desktop EXE | `$DSH_HOME/profiles/default` |
|
||||
| Community DSH Desktop | `$DSH_HOME/profiles/desktop` |
|
||||
If `profiles/<name>/package.json` is missing, start that host once so the official program creates the profile, then continue.
|
||||
|
||||
**2. Put this repo under plugins**
|
||||
**1. Find the `$DSH_HOME` this host actually uses**
|
||||
|
||||
A real home is named `.dsh` (official EXE sometimes uses `dsh-home`), contains `profiles`, and has at least one `profiles/<name>/package.json`.
|
||||
|
||||
Search in this order and use the first tree that matches the host you run:
|
||||
|
||||
| Order | Layout | Typical path |
|
||||
|---|---|---|
|
||||
| 1 | Environment | `DSH_HOME` if set |
|
||||
| 2 | Windows portable / install folder | `.dsh` next to `dsh.cmd` or `npm-global`, for example `<install root>\.dsh` |
|
||||
| 3 | User default | Windows `%USERPROFILE%\.dsh`; Linux / macOS `~/.dsh` |
|
||||
| 4 | Official desktop EXE | `%APPDATA%\DeepSeek Harness\dsh-home`, `%LOCALAPPDATA%\DeepSeek Harness\dsh-home` |
|
||||
|
||||
PowerShell can list candidates:
|
||||
|
||||
```powershell
|
||||
$cands = @()
|
||||
if ($env:DSH_HOME) { $cands += $env:DSH_HOME }
|
||||
$cands += "$env:USERPROFILE\.dsh"
|
||||
$dsh = Get-Command dsh -ErrorAction SilentlyContinue
|
||||
if ($dsh) {
|
||||
$dir = Split-Path $dsh.Source
|
||||
$cands += @(
|
||||
(Join-Path $dir ".dsh"),
|
||||
(Join-Path (Split-Path $dir) ".dsh"),
|
||||
(Join-Path (Split-Path (Split-Path $dir)) ".dsh")
|
||||
)
|
||||
}
|
||||
$cands += @(
|
||||
"$env:APPDATA\DeepSeek Harness\dsh-home",
|
||||
"$env:LOCALAPPDATA\DeepSeek Harness\dsh-home"
|
||||
)
|
||||
$cands | Select-Object -Unique | Where-Object { $_ -and (Test-Path (Join-Path $_ "profiles")) }
|
||||
```
|
||||
|
||||
How to confirm you found the right one:
|
||||
|
||||
- Web: `$DSH_HOME/profiles/web/package.json` has `"name": "dsh-profile-web"`
|
||||
- Community Desktop: `$DSH_HOME/profiles/desktop/package.json` has `"name": "dsh-profile-desktop"`
|
||||
- Official EXE: `$DSH_HOME/profiles/default/package.json` exists
|
||||
|
||||
Machines often have two homes (user folder and install folder). A portable / install-dir official `dsh` uses the `.dsh` next to the install root — not an empty `%USERPROFILE%\.dsh`. After the steps below, start the host that belongs to that home.
|
||||
|
||||
**2. Put the plugin at `$DSH_HOME/plugins/dsh-purge`**
|
||||
|
||||
The tree must look like this (do not rename the folder):
|
||||
|
||||
```
|
||||
$DSH_HOME/
|
||||
plugins/
|
||||
dsh-purge/ ← must be named dsh-purge
|
||||
package.json ← "name" must be "dsh-purge"
|
||||
client.js
|
||||
cordis.patch.yml
|
||||
lib/
|
||||
profiles/
|
||||
web/package.json ← or desktop / default
|
||||
```
|
||||
|
||||
With git:
|
||||
|
||||
```sh
|
||||
mkdir -p "$DSH_HOME/plugins"
|
||||
git clone https://github.com/YuJunZhiXue/dsh-purge.git "$DSH_HOME/plugins/dsh-purge"
|
||||
```
|
||||
|
||||
Or copy the tree to `$DSH_HOME/plugins/dsh-purge` (folder name must be `dsh-purge`). The `file:../../plugins/dsh-purge` relative path is enough. A junction is only needed if `plugin add` is given a local path that contains spaces.
|
||||
Without git, download [master.tar.gz](https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz), extract it, rename `dsh-purge-master` to `dsh-purge`, and place that folder under `plugins`. PowerShell example (set `$home` to the path from step 1):
|
||||
|
||||
**3. Edit that profile’s `package.json`**
|
||||
|
||||
- Web: `$DSH_HOME/profiles/web/package.json`
|
||||
- Official desktop EXE: `$DSH_HOME/profiles/default/package.json`
|
||||
- Community DSH Desktop: `$DSH_HOME/profiles/desktop/package.json`
|
||||
|
||||
Add to `dependencies` (keep other deps):
|
||||
|
||||
```json
|
||||
"dsh-purge": "file:../../plugins/dsh-purge"
|
||||
```powershell
|
||||
$home = "D:\DeepSeek Harness\.dsh"
|
||||
$plugins = Join-Path $home "plugins"
|
||||
New-Item -ItemType Directory -Force -Path $plugins | Out-Null
|
||||
$tmp = Join-Path $env:TEMP "dsh-purge-master.tar.gz"
|
||||
Invoke-WebRequest -Uri "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz" -OutFile $tmp
|
||||
tar -xzf $tmp -C $plugins
|
||||
$src = Join-Path $plugins "dsh-purge-master"
|
||||
$dst = Join-Path $plugins "dsh-purge"
|
||||
if (Test-Path $dst) { Remove-Item -Recurse -Force $dst }
|
||||
Rename-Item $src "dsh-purge"
|
||||
```
|
||||
|
||||
**Append** `"dsh-purge"` at the end of `dsh.profile.bundles`:
|
||||
If you already have a clone, copy the whole tree to `$DSH_HOME/plugins/dsh-purge`. Do not copy a few `.js` files by themselves.
|
||||
|
||||
- Web: **keep** `@deepseek-ai/dsh-web-app`, only append this plugin
|
||||
- Official / community Desktop: keep `@deepseek-ai/dsh-base` (and the rest), only append this plugin
|
||||
Check: `$DSH_HOME/plugins/dsh-purge/package.json` opens and `"name": "dsh-purge"`. Do not use the Hub `api/plugins/download` URL as the source.
|
||||
|
||||
Sketch (keep every other field from the file on disk):
|
||||
**3. Edit only that profile’s `package.json` — back it up first**
|
||||
|
||||
| Host | File to edit |
|
||||
|---|---|
|
||||
| Web | `$DSH_HOME/profiles/web/package.json` |
|
||||
| Community Desktop | `$DSH_HOME/profiles/desktop/package.json` |
|
||||
| Official desktop EXE | `$DSH_HOME/profiles/default/package.json` |
|
||||
|
||||
Copy `package.json.bak` first. Then **add only two things**. Keep every existing dependency, bundle, and other field:
|
||||
|
||||
1. In `dependencies`, add `"dsh-purge": "file:../../plugins/dsh-purge"`
|
||||
2. At the **end** of `dsh.profile.bundles`, append `"dsh-purge"` (skip if it is already there)
|
||||
|
||||
`file:../../plugins/dsh-purge` is the relative path from `profiles/web` (or `desktop` / `default`) to `$DSH_HOME/plugins/dsh-purge`. The same relative path works for all three. Do not switch it to an absolute path.
|
||||
|
||||
Before (official default often looks like this; your file may list more plugins — keep them):
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dsh-profile-web",
|
||||
"private": true,
|
||||
"dependencies": {},
|
||||
"dsh": {
|
||||
"profile": {
|
||||
"bundles": [
|
||||
"@deepseek-ai/dsh-base",
|
||||
"@deepseek-ai/dsh-web-app"
|
||||
],
|
||||
"patchReload": "live"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dsh-profile-web",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"dsh-purge": "file:../../plugins/dsh-purge"
|
||||
},
|
||||
@@ -353,43 +446,71 @@ Sketch (keep every other field from the file on disk):
|
||||
"@deepseek-ai/dsh-base",
|
||||
"@deepseek-ai/dsh-web-app",
|
||||
"dsh-purge"
|
||||
]
|
||||
],
|
||||
"patchReload": "live"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the desktop profile has no `dsh-web-app` row, do not add it; just make sure `"dsh-purge"` is in `bundles`.
|
||||
Notes:
|
||||
|
||||
**4. Install deps**
|
||||
- Web: **keep** `@deepseek-ai/dsh-web-app`; only append this plugin
|
||||
- Desktop: keep `@deepseek-ai/dsh-base` and the rest; if there is no `dsh-web-app` row, do not add one
|
||||
- JSON must stay valid: a comma before the new item, no trailing comma after the last item
|
||||
- Leave `patchReload`, other plugin names, and versions alone
|
||||
- Do not write `"dsh-purge"` twice
|
||||
|
||||
**4. Run `pnpm install` only in the profile you just edited**
|
||||
|
||||
`pnpm` must be available (official `dsh` usually ships it). `cd` into **that profile directory**, not the repo root and not `$DSH_HOME` itself.
|
||||
|
||||
```sh
|
||||
cd "$DSH_HOME/profiles/web"
|
||||
pnpm install
|
||||
|
||||
cd "$DSH_HOME/profiles/default"
|
||||
pnpm install
|
||||
|
||||
cd "$DSH_HOME/profiles/desktop"
|
||||
pnpm install
|
||||
```
|
||||
|
||||
PowerShell: use the real Harness home:
|
||||
|
||||
```powershell
|
||||
cd "$env:USERPROFILE\.dsh\profiles\web" # Web
|
||||
# cd "$env:USERPROFILE\.dsh\profiles\desktop" # community Desktop
|
||||
# cd "$env:USERPROFILE\.dsh\profiles\default" # official EXE
|
||||
# portable: <install root>\.dsh\profiles\<web|desktop|default>
|
||||
cd "$DSH_HOME/profiles/default"
|
||||
pnpm install
|
||||
```
|
||||
|
||||
**5. Restart, then apply patches**
|
||||
PowerShell (use the home from step 1):
|
||||
|
||||
1. Fully quit the current host (Web process, or official EXE / community Desktop tray) and start it again. Community Desktop opens `DSH Desktop.exe`, not `dsh web`.
|
||||
2. Settings should show **Rules**. Ctrl+F5 if cached.
|
||||
3. Click **Apply**, or `/purge apply`, or `dsh-purge --apply` from the plugin dir.
|
||||
4. Restart again when prompted so patched packages load in this process. Settings **Restart / Uninstall** relaunch the desktop app when you are on Desktop.
|
||||
```powershell
|
||||
cd "$env:USERPROFILE\.dsh\profiles\web"
|
||||
# cd "$env:USERPROFILE\.dsh\profiles\desktop"
|
||||
# cd "$env:USERPROFILE\.dsh\profiles\default"
|
||||
# portable example:
|
||||
# cd "D:\DeepSeek Harness\.dsh\profiles\web"
|
||||
pnpm install
|
||||
```
|
||||
|
||||
Success: `$DSH_HOME/profiles/<web|desktop|default>/node_modules/dsh-purge/package.json` exists.
|
||||
|
||||
Common failures:
|
||||
|
||||
- `pnpm` not found: install pnpm, or use the Node / pnpm that ships with official `dsh`
|
||||
- `Could not resolve` / missing local package: check that `plugins/dsh-purge/package.json` exists and `file:../../plugins/dsh-purge` is correct
|
||||
- JSON parse error: fix commas in `package.json` and retry; restore the backup if needed
|
||||
|
||||
**5. Fully quit that host, start it, then apply**
|
||||
|
||||
Writing `package.json` does **not** patch `@deepseek-ai` by itself. Restart, then click **Apply**.
|
||||
|
||||
1. Fully quit the host you just installed into: stop `dsh web`; quit the community Desktop tray and open `DSH Desktop.exe`; quit the official EXE tray as well
|
||||
2. Open **that host’s** Settings page. **Rules** should appear. Ctrl+F5 if cached
|
||||
3. Click **Apply** on this host only, or run `/purge apply` in chat. Do not Apply Web from Desktop or Desktop from Web
|
||||
4. Restart again when prompted so patched packages load in this process. Settings **Restart / Uninstall** relaunch the desktop app; they do not launch `dsh web`
|
||||
|
||||
**6. How to confirm it is installed**
|
||||
|
||||
- Settings shows the **Rules** card
|
||||
- `/purge status` prints `DSH_HOME` and the patch list; the path should match step 1
|
||||
- `profiles/<name>/node_modules/dsh-purge` points at `plugins/dsh-purge`
|
||||
|
||||
If the card is missing, you likely edited the other `.dsh`, or you edited `web` and then opened Desktop. Go back to step 1. Do not split the same install across two homes.
|
||||
|
||||
### Uninstall
|
||||
|
||||
@@ -476,7 +597,6 @@ dsh-purge/
|
||||
├── client.js
|
||||
├── cordis.patch.yml
|
||||
├── docs/
|
||||
│ ├── appreciate.png
|
||||
│ ├── banner.svg
|
||||
│ └── preview/
|
||||
│ ├── rules.png
|
||||
@@ -548,8 +668,6 @@ node --check lib/desktop.js
|
||||
node --check lib/host.js
|
||||
node --check lib/rewind.js
|
||||
node --check client.js
|
||||
node --test test/surface.test.js
|
||||
node --test test/update-spec.test.js
|
||||
```
|
||||
|
||||
---
|
||||
@@ -627,9 +745,14 @@ If nothing is found, set `DSH_BASE` / `DSH_DESKTOP_INSTALL`. No files are change
|
||||
|
||||
## Changelog
|
||||
|
||||
### 1.1.10
|
||||
|
||||
- Saving or applying with both the prompt and the rule set empty is blocked and shows a dialog
|
||||
- First-turn inject is complete; later turns no longer pin the previous full system prompt
|
||||
|
||||
### 1.1.9
|
||||
|
||||
- 将提示词从仓库中下线
|
||||
- Removed the default prompt from the repository
|
||||
|
||||
<details>
|
||||
<summary>Earlier versions</summary>
|
||||
|
||||
+190
-66
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.9</strong></p>
|
||||
<p align="center"><strong>Version 1.1.10</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件:在受控本机环境评测并加固宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||
@@ -26,25 +26,28 @@
|
||||
|
||||
> 对准 **dsh 0.1.5-rc.1**(Node.js **≥18**;Windows 无感路径依赖 **Node ≥22** 的 `registerHooks`,更低版本仍靠文件级 `windowsHide` 补丁)。其它版本原文对不上时会显示待应用 / 跳过,不会乱改文件。
|
||||
>
|
||||
> 兼容 0.1.2 社区预设的 `dsh-persona text` 字段,以及 `dsh-mnemon` 历史会话的 v0 `summary`。装完必须 **Apply + 重启**。
|
||||
> 兼容 0.1.2 社区预设的 `dsh-persona text` 字段,以及 `dsh-mnemon` 历史会话的 v0 `summary`。装完必须 **应用 + 重启**。
|
||||
|
||||
---
|
||||
|
||||
## ☕ 赞赏支持 / Sponsor
|
||||
## ☕ 赞赏支持
|
||||
|
||||
如果 dsh-purge 对你有帮助,欢迎打赏。
|
||||
如果这个项目对你有帮助,请给我转,我是讨口子~
|
||||
|
||||
| 币种 | 地址 |
|
||||
|---|---|
|
||||
| **USDT(TRC20)** | `TV5ajPkRD8RH623Dx9mqvYZVNN8nPGRKid` |
|
||||
| **Solana** | `6x16GhRgLVpKFFXaU1seKNdx2rypspSJTL4dbpt6Xpwk` |
|
||||
| **Ethereum** | `0xB68BD60C0e8c519513B7DF9bB147696815423B3E` |
|
||||
| **Bitcoin** | `bc1qu70yxkrtwnymt8ryluz9x8y8hqzune5340npht` |
|
||||
|
||||
<p align="center">
|
||||
<img src="docs/appreciate.png" alt="微信赞赏码" width="360">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<sub>Built by 小杨 · for DeepSeek Harness</sub>
|
||||
<sub>小杨制作 · 面向 DeepSeek Harness</sub>
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
## 🛡️ 网络安全红队基准评测的必要性(Why Red-Teaming Matters)
|
||||
## 🛡️ 网络安全红队基准评测的必要性
|
||||
|
||||
在生成式人工智能与大语言模型(LLM)向各行业深度融合的背景下,模型的鲁棒性、对抗防御能力与系统对齐安全性已成为网络空间安全的核心研究课题。本地 Agent / Harness 还会在运行时改写提示词、审批门、沙箱和会话迁移,只测「模型会不会答」不够,还要看宿主层有没有把合法安全评测请求拦截掉。
|
||||
|
||||
@@ -60,7 +63,7 @@
|
||||
|
||||
<div>
|
||||
|
||||
### ⚠️ <font color="red">严正法律免责与合规使用声明(Strict Legal & Compliance Disclaimer)</font>
|
||||
### ⚠️ <font color="red">严正法律免责与合规使用声明</font>
|
||||
|
||||
<font color="red">
|
||||
|
||||
@@ -69,7 +72,7 @@
|
||||
1. **本仓库不含违法内容**:`dsh-purge` 发布的代码、文档、补丁与默认提示词**不是**木马、后门、未授权渗透工具、勒索软件、撞库脚本,也**不是**针对公网或第三方系统的攻击载荷。项目本身不提供违法内容,也不教唆、组织、协助实施违法犯罪。
|
||||
2. **只作用于本机官方 Harness**:安全评测补丁、提示词注入全部发生在使用者**本机已安装的官方 DeepSeek Harness**(`@deepseek-ai` 包、本机 profile / `$DSH_HOME`)上。对象是使用者自己的官方本地软件,**不是**他人的网站、服务器、账号或信息系统。
|
||||
3. **评测补丁不对外网目标联网**:应用补丁、写入注入、回滚、卸载均在本机文件与本机进程内完成,**不对任何公网主机、未授权系统进行扫描、探测、入侵或攻击发包**。不得把本项目当作跳板去打外网。插件若开启「检测更新」,仅可能访问本插件自己的 GitHub 仓库以核对版本,**与对第三方系统的网络攻击无关**,也不能被解释为授权对外渗透。
|
||||
4. **合法受控范围限定**:本项目定位为使用者在**自己有权管理的本机官方 Harness**上,进行红队科研与鲁棒性评测的辅助工具。**严禁在未经所有者合法书面授权的目标、公网在线系统或生产业务上运行本项目**。一切测试必须限制在**本机已授权安装的官方 Harness、离线本地合成靶标(Local Synthetic Fixtures)、授权网络安全演练靶场及合规实验室受控环境**中进行。
|
||||
4. **合法受控范围限定**:本项目定位为使用者在**自己有权管理的本机官方 Harness**上,进行红队科研与鲁棒性评测的辅助工具。**严禁在未经所有者合法书面授权的目标、公网在线系统或生产业务上运行本项目**。一切测试必须限制在**本机已授权安装的官方 Harness、离线本地合成靶标、授权网络安全演练靶场及合规实验室受控环境**中进行。
|
||||
5. **严禁违法与违禁用途**:使用者严禁利用本项目直接或间接从事任何违反下列法律法规的行为(必须逐条遵守,不得以任何理由规避):
|
||||
- <font color="red"><strong>《中华人民共和国刑法》</strong></font>
|
||||
- <font color="red"><strong>《中华人民共和国网络安全法》</strong></font>
|
||||
@@ -79,8 +82,8 @@
|
||||
- 同时严禁:
|
||||
- 未经授权渗透、攻击公私机构计算机信息系统,实施勒索、破坏、撞库或传播恶意载荷;
|
||||
- 诱导、生成或传播危害国家安全、恐怖主义、暴力血腥、涉黄涉赌、诈骗、侵犯公民隐私或知识产权等任何法律明令禁止的违法违禁内容;
|
||||
- 违反相关大模型提供商的《服务条款(Terms of Service)》与《滥用政策(Usage Policy)》。
|
||||
6. **使用者独立承担全部责任**:本项目依据 MIT 开源协议“按现状(AS-IS)”提供,开发者不对软件的完整性、安全性与适用性作任何明示或暗示的保证。**使用者应对自身的所有下载、部署、运行、修改、传播行为以及由此产生的全部输入与输出后果承担独立、完全的民事、行政及刑事法律责任**。项目作者与贡献团队绝不承担任何因使用者滥用导致的直接、间接或连带责任。
|
||||
- 违反相关大模型提供商的《服务条款》与《滥用政策》。
|
||||
6. **使用者独立承担全部责任**:本项目依据 MIT 开源协议“按现状”提供,开发者不对软件的完整性、安全性与适用性作任何明示或暗示的保证。**使用者应对自身的所有下载、部署、运行、修改、传播行为以及由此产生的全部输入与输出后果承担独立、完全的民事、行政及刑事法律责任**。项目作者与贡献团队绝不承担任何因使用者滥用导致的直接、间接或连带责任。
|
||||
7. **违约即终止授权**:任何将本项目用于非法攻击、恶意活动或违规行为的个人或实体,其开源软件使用许可将自违法违规行为发生之日起**自动且不可撤销地立即终止**。该主体须立即停止使用并永久销毁本项目的所有代码、脚本与衍生数据,并依法承担相应法律制裁。
|
||||
8. **第三方独立性声明**:本项目属于完全独立的开源安全评测研究项目,与 DeepSeek 官方或其关联主体无任何隶属、商业合作、授权或官方背书关系。文中「官方」仅指评测对象为使用者本机安装的官方 DeepSeek Harness 软件包,**不代表** DeepSeek 官方开发、认可或担保本插件。
|
||||
|
||||
@@ -108,9 +111,7 @@ Web 端和桌面端**分开安装、分开做安全评测补丁**,互不影响
|
||||
|
||||
Web 的「应用 / 重启 / 卸载」只动 Web。桌面端的「应用 / 重启 / 卸载」只动桌面应用,不会去拉 `dsh web`。
|
||||
|
||||
> 🌐 **插件生态市场**:[DeepSeek Harness Hub](https://deepseek.stream/plugins/dsh-purge)(只看介绍;**不要**用 `deepseek.stream/api/plugins/download?...`,那个地址不是 pnpm 能解的 tar,会报 `ERR_PNPM_TARBALL_EXTRACT`)
|
||||
>
|
||||
> `dsh plugin add <url>` 会把地址交给 pnpm 当 **远程 tarball**。请用 GitHub 的 `master.tar.gz`。`.zip` 是 ZIP 不是 gzip,会报 `ERR_PNPM_TARBALL_DECODE_GZIP`([#26](https://github.com/YuJunZhiXue/dsh-purge/issues/26))。
|
||||
> 🌐 **插件生态市场**:[DeepSeek Harness Hub](https://deepseek.stream/plugins/dsh-purge)(只看介绍;**不要**用 `deepseek.stream/api/plugins/download?...` 安装)
|
||||
|
||||
### Web 端(默认)
|
||||
|
||||
@@ -240,13 +241,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.9&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.10&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.9&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.10&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
|
||||
```
|
||||
|
||||
**网页端(前端)触发代码示例:**
|
||||
@@ -259,7 +260,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.9',
|
||||
version: '1.1.10',
|
||||
repo: 'YuJunZhiXue/dsh-purge',
|
||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||
@@ -278,7 +279,7 @@ export function installDshPurgeToDesktop() {
|
||||
**HTML 静态链接方式:**
|
||||
|
||||
```html
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.9&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.10&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>
|
||||
```
|
||||
@@ -289,58 +290,150 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | 插件唯一标识符 |
|
||||
| name | `dsh-purge` | 插件展示名称 |
|
||||
| version | `1.1.9` | 语义化版本号 |
|
||||
| version | `1.1.10` | 语义化版本号 |
|
||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
|
||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub tarball(不要用 `.zip`) |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
|
||||
|
||||
### 手动配置安装
|
||||
|
||||
`dsh` 不在 PATH、或不想用 `dsh plugin add` 时,按宿主改对应 profile。不要删原有 bundle。
|
||||
`dsh` 不在 PATH、官方 `dsh plugin add` 失败、或不想走远程安装时,按下面手工写入。只改**正在用的那个宿主**对应的 profile,不要删原有 bundle,不要同时改 Web 和桌面端。
|
||||
|
||||
**1. 找到 Harness 主目录(下文称 `$DSH_HOME`)**
|
||||
**0. 先确认宿主,只动一个 profile**
|
||||
|
||||
| 安装形态 | 典型路径 |
|
||||
|---|---|
|
||||
| 环境变量 | `DSH_HOME`(已设置就用它) |
|
||||
| Windows 便携包 | 与 `npm-global` 同级的 `.dsh` |
|
||||
| 用户默认 | Windows `%USERPROFILE%\.dsh`;Linux / macOS `~/.dsh` |
|
||||
| 你实际在用的 | 只改这个目录 | 不要改 |
|
||||
|---|---|---|
|
||||
| 官方 `dsh web` | `$DSH_HOME/profiles/web` | `desktop`、`default` |
|
||||
| 社区 [DSH Desktop](https://github.com/anywhere-labs/dsh-desktop) | `$DSH_HOME/profiles/desktop` | `web`、`default` |
|
||||
| 官方 Harness 桌面 EXE | `$DSH_HOME/profiles/default` | `web`、`desktop` |
|
||||
|
||||
| 宿主 | profile 目录 |
|
||||
|---|---|
|
||||
| Web 端 | `$DSH_HOME/profiles/web` |
|
||||
| 社区桌面端 | `$DSH_HOME/profiles/desktop` |
|
||||
| 官方桌面 EXE | `$DSH_HOME/profiles/default` |
|
||||
对应 `profiles/<名>/package.json` 还不存在时,先正常启动一次该宿主,让官方程序自己建好 profile,再继续。
|
||||
|
||||
**2. 把本仓库放到 plugins 目录**
|
||||
**1. 找到真正在用的 `$DSH_HOME`**
|
||||
|
||||
认目录:名字是 `.dsh`(官方 EXE 偶见 `dsh-home`),里面有 `profiles`,并且至少有一个 `profiles/<名>/package.json`。
|
||||
|
||||
按这个顺序找,找到第一份能对上当前宿主的就用它:
|
||||
|
||||
| 顺序 | 安装形态 | 典型路径 |
|
||||
|---|---|---|
|
||||
| 1 | 环境变量 | `DSH_HOME`(已设置就用它) |
|
||||
| 2 | Windows 便携 / 安装目录 | `dsh.cmd` 或 `npm-global` 旁边的 `.dsh`,例如 `<安装根>\.dsh` |
|
||||
| 3 | 用户默认 | Windows `%USERPROFILE%\.dsh`;Linux / macOS `~/.dsh` |
|
||||
| 4 | 官方桌面 EXE | `%APPDATA%\DeepSeek Harness\dsh-home`、`%LOCALAPPDATA%\DeepSeek Harness\dsh-home` |
|
||||
|
||||
Windows PowerShell 可先列出本机有哪些候选:
|
||||
|
||||
```powershell
|
||||
$cands = @()
|
||||
if ($env:DSH_HOME) { $cands += $env:DSH_HOME }
|
||||
$cands += "$env:USERPROFILE\.dsh"
|
||||
$dsh = Get-Command dsh -ErrorAction SilentlyContinue
|
||||
if ($dsh) {
|
||||
$dir = Split-Path $dsh.Source
|
||||
$cands += @(
|
||||
(Join-Path $dir ".dsh"),
|
||||
(Join-Path (Split-Path $dir) ".dsh"),
|
||||
(Join-Path (Split-Path (Split-Path $dir)) ".dsh")
|
||||
)
|
||||
}
|
||||
$cands += @(
|
||||
"$env:APPDATA\DeepSeek Harness\dsh-home",
|
||||
"$env:LOCALAPPDATA\DeepSeek Harness\dsh-home"
|
||||
)
|
||||
$cands | Select-Object -Unique | Where-Object { $_ -and (Test-Path (Join-Path $_ "profiles")) }
|
||||
```
|
||||
|
||||
怎么确认找对了:
|
||||
|
||||
- Web:`$DSH_HOME/profiles/web/package.json` 里 `"name"` 是 `dsh-profile-web`
|
||||
- 社区桌面端:`$DSH_HOME/profiles/desktop/package.json` 里 `"name"` 是 `dsh-profile-desktop`
|
||||
- 官方 EXE:`$DSH_HOME/profiles/default/package.json` 存在
|
||||
|
||||
本机常有两份 `.dsh`(用户目录一份、安装目录一份)。便携包、安装目录里的官方 `dsh` **用安装根下那份**,不要改到空的 `%USERPROFILE%\.dsh`。改完下面步骤后,启动的必须是这份主目录对应的宿主。
|
||||
|
||||
**2. 把插件放到 `$DSH_HOME/plugins/dsh-purge`**
|
||||
|
||||
目标树必须长这样(目录名不能改):
|
||||
|
||||
```
|
||||
$DSH_HOME/
|
||||
plugins/
|
||||
dsh-purge/ ← 必须叫 dsh-purge
|
||||
package.json ← 里面 "name" 必须是 "dsh-purge"
|
||||
client.js
|
||||
cordis.patch.yml
|
||||
lib/
|
||||
profiles/
|
||||
web/package.json ← 或 desktop / default
|
||||
```
|
||||
|
||||
有 git 时:
|
||||
|
||||
```sh
|
||||
mkdir -p "$DSH_HOME/plugins"
|
||||
git clone https://github.com/YuJunZhiXue/dsh-purge.git "$DSH_HOME/plugins/dsh-purge"
|
||||
```
|
||||
|
||||
或把已有仓库复制为 `$DSH_HOME/plugins/dsh-purge`(目录名必须是 `dsh-purge`)。用 `file:../../plugins/dsh-purge` 相对路径即可。
|
||||
没有 git 时,下载 [master.tar.gz](https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz),解压后把里面的 `dsh-purge-master` **改名为** `dsh-purge`,再整夹放到 `plugins` 下。Windows PowerShell 示例(先把 `$home` 换成上一步找到的路径):
|
||||
|
||||
**3. 改对应 profile 的 `package.json`**
|
||||
|
||||
- Web:`$DSH_HOME/profiles/web/package.json`
|
||||
- 社区桌面端:`$DSH_HOME/profiles/desktop/package.json`
|
||||
- 官方桌面 EXE:`$DSH_HOME/profiles/default/package.json`
|
||||
|
||||
在 `dependencies` 里追加(不要删别的依赖):
|
||||
|
||||
```json
|
||||
"dsh-purge": "file:../../plugins/dsh-purge"
|
||||
```powershell
|
||||
$home = "D:\DeepSeek Harness\.dsh"
|
||||
$plugins = Join-Path $home "plugins"
|
||||
New-Item -ItemType Directory -Force -Path $plugins | Out-Null
|
||||
$tmp = Join-Path $env:TEMP "dsh-purge-master.tar.gz"
|
||||
Invoke-WebRequest -Uri "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz" -OutFile $tmp
|
||||
tar -xzf $tmp -C $plugins
|
||||
$src = Join-Path $plugins "dsh-purge-master"
|
||||
$dst = Join-Path $plugins "dsh-purge"
|
||||
if (Test-Path $dst) { Remove-Item -Recurse -Force $dst }
|
||||
Rename-Item $src "dsh-purge"
|
||||
```
|
||||
|
||||
在 `dsh.profile.bundles` 数组**末尾追加** `"dsh-purge"`:
|
||||
已有本仓库副本时,复制整个目录到 `$DSH_HOME/plugins/dsh-purge`,不要只拷几个 js。
|
||||
|
||||
- Web:**必须保留**原来的 `@deepseek-ai/dsh-web-app`,只追加本插件
|
||||
- 桌面端:保留原来的 `@deepseek-ai/dsh-base` 等,只追加本插件
|
||||
放好后检查:`$DSH_HOME/plugins/dsh-purge/package.json` 能打开,且 `"name": "dsh-purge"`。不要用插件市场的 `api/plugins/download` 地址当源。
|
||||
|
||||
完整示意(其它字段按原文件保留):
|
||||
**3. 只改对应 profile 的 `package.json`,先备份**
|
||||
|
||||
| 宿主 | 要改的文件 |
|
||||
|---|---|
|
||||
| Web | `$DSH_HOME/profiles/web/package.json` |
|
||||
| 社区桌面端 | `$DSH_HOME/profiles/desktop/package.json` |
|
||||
| 官方桌面 EXE | `$DSH_HOME/profiles/default/package.json` |
|
||||
|
||||
先复制一份 `package.json.bak`。然后**只追加两处**,原有依赖、原有 bundle、其它字段全部留着:
|
||||
|
||||
1. `dependencies` 增加一行:`"dsh-purge": "file:../../plugins/dsh-purge"`
|
||||
2. `dsh.profile.bundles` **末尾**追加 `"dsh-purge"`(已经有就不要再加)
|
||||
|
||||
`file:../../plugins/dsh-purge` 是从 `profiles/web`(或 `desktop` / `default`)走到 `$DSH_HOME/plugins/dsh-purge` 的相对路径,三层目录都一样,不要改成绝对路径。
|
||||
|
||||
改前(官方默认常见长这样,你机器上还会有其它插件,那些一行都不要删):
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dsh-profile-web",
|
||||
"private": true,
|
||||
"dependencies": {},
|
||||
"dsh": {
|
||||
"profile": {
|
||||
"bundles": [
|
||||
"@deepseek-ai/dsh-base",
|
||||
"@deepseek-ai/dsh-web-app"
|
||||
],
|
||||
"patchReload": "live"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
改后:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "dsh-profile-web",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"dsh-purge": "file:../../plugins/dsh-purge"
|
||||
},
|
||||
@@ -350,15 +443,24 @@ git clone https://github.com/YuJunZhiXue/dsh-purge.git "$DSH_HOME/plugins/dsh-pu
|
||||
"@deepseek-ai/dsh-base",
|
||||
"@deepseek-ai/dsh-web-app",
|
||||
"dsh-purge"
|
||||
]
|
||||
],
|
||||
"patchReload": "live"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
桌面 profile 若没有 `dsh-web-app` 这一行,不要硬加;只保证 `bundles` 里有 `"dsh-purge"`。
|
||||
注意:
|
||||
|
||||
**4. 安装依赖**
|
||||
- Web:**必须保留** `@deepseek-ai/dsh-web-app`,只在数组末尾追加本插件
|
||||
- 桌面端:保留原来的 `@deepseek-ai/dsh-base` 等;没有 `dsh-web-app` 就不要硬加
|
||||
- JSON 要合法:新增项前面要有逗号,最后一项后面不要多余逗号
|
||||
- `patchReload`、其它插件名、版本号都不要动
|
||||
- 已经写过 `"dsh-purge"` 就不要再写第二份
|
||||
|
||||
**4. 只在刚改的那个 profile 目录装依赖**
|
||||
|
||||
本机要有 `pnpm`(官方 dsh 一般自带)。进入**上一步改过的那个** profile 目录再执行,不要在仓库根目录、也不要在 `$DSH_HOME` 根目录执行。
|
||||
|
||||
```sh
|
||||
cd "$DSH_HOME/profiles/web" # Web
|
||||
@@ -371,22 +473,41 @@ cd "$DSH_HOME/profiles/default" # 官方 EXE
|
||||
pnpm install
|
||||
```
|
||||
|
||||
Windows PowerShell:
|
||||
Windows PowerShell(路径换成第 1 步找到的那份):
|
||||
|
||||
```powershell
|
||||
cd "$env:USERPROFILE\.dsh\profiles\web"
|
||||
# cd "$env:USERPROFILE\.dsh\profiles\desktop"
|
||||
# cd "$env:USERPROFILE\.dsh\profiles\default"
|
||||
# 便携包:<安装根>\.dsh\profiles\<web|desktop|default>
|
||||
# 便携包示例:
|
||||
# cd "D:\DeepSeek Harness\.dsh\profiles\web"
|
||||
pnpm install
|
||||
```
|
||||
|
||||
**5. 重启,再打补丁**
|
||||
成功标志:出现 `$DSH_HOME/profiles/<web|desktop|default>/node_modules/dsh-purge/package.json`。
|
||||
|
||||
1. 完全退出刚装的那个宿主(Web 关进程;桌面端退出托盘),再启动。
|
||||
2. 设置页应出现「规则设定」。有缓存就 Ctrl+F5。
|
||||
3. 在**这个宿主**点「应用」,或聊天 `/purge apply`。
|
||||
4. 按提示再重启一次。桌面端的「重启 / 卸载」会重启桌面应用。
|
||||
常见失败:
|
||||
|
||||
- 提示找不到 `pnpm`:先装 pnpm,或用官方 dsh 自带的 Node / pnpm
|
||||
- `Could not resolve` / 找不到本地包:检查 `plugins/dsh-purge/package.json` 是否存在,以及 `file:../../plugins/dsh-purge` 有没有写错
|
||||
- JSON 解析失败:把 `package.json` 用编辑器校验逗号后重试;不行就用备份还原再改一次
|
||||
|
||||
**5. 完全退出该宿主,再启动,再打补丁**
|
||||
|
||||
只写入 `package.json` **还不会**改 `@deepseek-ai` 包,必须重启后再点「应用」。
|
||||
|
||||
1. 完全退出刚装的那个宿主:Web 关掉 `dsh web`;社区桌面端退出托盘再开 `DSH Desktop.exe`;官方 EXE 也要退出托盘
|
||||
2. 打开**这个宿主**的设置页,应出现「规则设定」。有缓存就 Ctrl+F5
|
||||
3. 只在这个宿主点「应用」,或聊天 `/purge apply`。不要用 Web 去点桌面端的应用,也不要反过来
|
||||
4. 按提示再重启一次,补丁才会进当前进程。桌面端的「重启 / 卸载」会重启桌面应用,不会去拉 `dsh web`
|
||||
|
||||
**6. 怎么确认装上了**
|
||||
|
||||
- 设置页有「规则设定」卡片
|
||||
- 聊天 `/purge status` 能打出 `DSH_HOME` 和补丁列表,路径应等于第 1 步用的那份
|
||||
- `profiles/<名>/node_modules/dsh-purge` 指向 `plugins/dsh-purge`
|
||||
|
||||
还没有卡片时,多半是改错了另一份 `.dsh`,或改了 `web` 却在桌面端里等设置页。回到第 1 步核对路径,不要在两份主目录各改一半。
|
||||
|
||||
### 卸载
|
||||
|
||||
@@ -473,7 +594,6 @@ dsh-purge/
|
||||
├── client.js
|
||||
├── cordis.patch.yml
|
||||
├── docs/
|
||||
│ ├── appreciate.png
|
||||
│ ├── banner.svg
|
||||
│ └── preview/
|
||||
│ ├── rules.png
|
||||
@@ -544,7 +664,6 @@ node --check lib/index.js
|
||||
node --check lib/core.js
|
||||
node --check lib/rewind.js
|
||||
node --check client.js
|
||||
node --test test/update-spec.test.js
|
||||
```
|
||||
|
||||
---
|
||||
@@ -574,9 +693,9 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
|
||||
|
||||
**身份(1.3.6):** 插件不发明「操作员 / LCS」第二套人设。官方 Harness 身份句剥掉;`prompt-inject.md` 原文就是身份。0.1.5 把 inject 折进 `persona-prefix`,避免被梁神 phase-1 滤掉。
|
||||
|
||||
**Windows CMD 无感:** Node 24 上 `import { spawn } from "node:child_process"` 不是 live binding。`registerHooks` 把 `node:child_process` 指到带 `windowsHide` 的 facade,并直接给 `@deepseek-ai/dsh-subprocess-local` 加 `windowsHide: true`。doctor 重启走 `node + bin.js`,不写 noop `supervisor.cmd`。
|
||||
**Windows CMD 无感:** Node 24 上 `import { spawn } from "node:child_process"` 不是实时绑定。`registerHooks` 把 `node:child_process` 指到带 `windowsHide` 的封装层,并直接给 `@deepseek-ai/dsh-subprocess-local` 加 `windowsHide: true`。doctor 重启走 `node + bin.js`,不写空操作 `supervisor.cmd`。
|
||||
|
||||
**梁神 phase-1:** 默认预设会扒掉非 persona 的 system-prompt 段。Apply / 启动时保留 persona、persona-prefix、persona-suffix 与 inject(工具目录仍按梁神隔离)。
|
||||
**梁神 phase-1:** 默认预设会扒掉非 persona 的 system-prompt 段。应用 / 启动时保留 persona、persona-prefix、persona-suffix 与 inject(工具目录仍按梁神隔离)。
|
||||
|
||||
**DSH Desktop(anywhere-labs/dsh-desktop,issue #9):** `host-commands/<profile>/bin` 是密封目录,禁止 sibling 额外文件(含 `dsh.cmd.dshpurge.bak`)。本插件对密封目录只清理、不注入、不写 bak。
|
||||
|
||||
@@ -613,6 +732,11 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
|
||||
|
||||
## 更新记录
|
||||
|
||||
### 1.1.10
|
||||
|
||||
- 提示词和规则集都空时不能保存或应用,弹窗要求先添加提示词
|
||||
- 第一轮完整注入;不再钉上一轮整篇系统提示,避免来回追加
|
||||
|
||||
### 1.1.9
|
||||
|
||||
- 将提示词从仓库中下线
|
||||
@@ -627,7 +751,7 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
|
||||
### 1.1.7
|
||||
|
||||
- **#25:** 第一轮注入 `prompt-inject.md` 之后不再把上一轮整段系统提示钉回去;后续只保留本轮组装结果。
|
||||
- **#26:** `dsh plugin add` / 插件内更新改用 GitHub `master.tar.gz`。`.zip` 不是 pnpm tarball,会报 `ERR_PNPM_TARBALL_DECODE_GZIP`。本地覆盖安装仍下载 zip 给 `tar` / Expand-Archive。
|
||||
- **#26:** `dsh plugin add` / 插件内更新改用 GitHub `master.tar.gz`。`.zip` 不是 pnpm 能解的压缩包,会报 `ERR_PNPM_TARBALL_DECODE_GZIP`。本地覆盖安装仍下载 zip 给 `tar` / Expand-Archive。
|
||||
- 安装文档按 **Web 端 / 桌面端** 分开写默认命令:Web 用官方 `dsh --profile web`;桌面端默认在自带终端 `dsh plugin add <zip>`。
|
||||
- 桌面端安全评测补丁、重启、卸载只针对当前桌面进程的安装树,不碰官方 Web / npm-global。
|
||||
- 桌面端安装目录按运行中的 `DSH Desktop.exe` 定位,默认位置或自定义目录都可以。
|
||||
|
||||
@@ -73,6 +73,35 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
} finally { clearTimeout(timer); }
|
||||
}
|
||||
|
||||
function promptBoxEmpty(text) {
|
||||
return !String(text || "").trim();
|
||||
}
|
||||
|
||||
function responseNeedsPrompt(d) {
|
||||
return Boolean(d && (d.needPrompt || d.injectSource === "none"));
|
||||
}
|
||||
|
||||
function warnNeedPrompt(d, tr) {
|
||||
if (!responseNeedsPrompt(d)) return false;
|
||||
window.alert(tr("need.prompt"));
|
||||
return true;
|
||||
}
|
||||
|
||||
function activeRuleHasBody(st) {
|
||||
if (!st || !st.ok) return false;
|
||||
const active = st.rules && st.rules.find((r) => r.id === st.active);
|
||||
return Boolean(active && active.size > 0);
|
||||
}
|
||||
|
||||
async function bothInjectEmpty(overrideText) {
|
||||
if (!promptBoxEmpty(overrideText)) return false;
|
||||
try {
|
||||
return !activeRuleHasBody(await rulesApi("status"));
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function rulesApi(op, extra) {
|
||||
return apiJson("/dsh-purge/rules", {
|
||||
method: "POST",
|
||||
@@ -110,7 +139,8 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"apply.hint": "待应用=原文还在。跳过=没装或官方已改写,再点也不会变。",
|
||||
"warn.noRoot": "未定位到当前宿主的 @deepseek-ai,清洗不会生效。请完全退出后再打开本宿主,在本页点「应用」。桌面端安装目录可以是任意盘符,不要用官方 dsh 去清桌面端。",
|
||||
"warn.noRoot.desktop": "未定位到当前桌面应用里的 @deepseek-ai。请退出托盘后重新打开 DSH Desktop.exe,再在桌面端设置页点「应用」。安装目录不限盘符。",
|
||||
"warn.noInject": "未自行改过时始终使用插件内置默认提示词。保存不同内容后才会换成你的;恢复默认可改回去。",
|
||||
"warn.noInject": "提示词优先;为空则注入当前启用的规则集。两边都空会提示必须添加。",
|
||||
"need.prompt": "提示词和规则集都是空的,必须先添加提示词,或启用一条有内容的规则集。",
|
||||
"btn.restoreInject": "恢复默认",
|
||||
"saved.restoreInject": "已填入默认提示词,点保存写入",
|
||||
"skip": "跳过",
|
||||
@@ -280,7 +310,8 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"apply.hint": "Pending = original text still present. Skipped = missing or already rewritten.",
|
||||
"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; do not use official dsh to purge Desktop.",
|
||||
"warn.noRoot.desktop": "Could not find @deepseek-ai inside this desktop app. Quit the tray, reopen DSH Desktop.exe, then Apply on the desktop Settings page. The install folder can be on any drive.",
|
||||
"warn.noInject": "Until you save a different prompt, the plugin keeps its built-in default. Restore default to go back.",
|
||||
"warn.noInject": "The prompt box wins. If it is empty, the enabled rule set is injected. If both are empty you will be asked to add a prompt.",
|
||||
"need.prompt": "Both the prompt and the rule set are empty. Add a prompt, or enable a rule that has content.",
|
||||
"btn.restoreInject": "Reset default",
|
||||
"saved.restoreInject": "Default prompt loaded. Save to write.",
|
||||
"skip": "Skipped",
|
||||
@@ -732,6 +763,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const [updateNotice, setUpdateNotice] = useState({ kind: "idle", text: "" });
|
||||
const [updateInfo, setUpdateInfo] = useState(null);
|
||||
const [canApplyUpdate, setCanApplyUpdate] = useState(false);
|
||||
const actionTicket = useRef(0);
|
||||
|
||||
const updateErrorText = (tr, e) => {
|
||||
const msg = String((e && e.message) || e || "");
|
||||
@@ -797,8 +829,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
if (d && d.ok) {
|
||||
const packed = typeof d.defaultContent === "string" ? d.defaultContent : "";
|
||||
if (packed) setDefaultOverride(packed);
|
||||
const shown = String(d.content || packed || "").trim() ? (d.content || packed) : packed;
|
||||
setOverride(shown);
|
||||
setOverride(typeof d.content === "string" ? d.content : packed);
|
||||
setOverrideLoaded(true);
|
||||
}
|
||||
else setNotice({ kind: "error", text: tr("err.override", { error: (d && d.error) || "" }) });
|
||||
@@ -808,21 +839,41 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
|
||||
useEffect(() => { loadAll(); }, [loadAll]);
|
||||
|
||||
const doAction = useCallback((action, actionKey) => {
|
||||
setPatchBusy(true);
|
||||
const rejectNeedPrompt = useCallback((tr) => {
|
||||
setAskRestart(false);
|
||||
setNotice({ kind: "idle", text: "" });
|
||||
setNotice({ kind: "error", text: tr("need.prompt") });
|
||||
setTimeout(() => window.alert(tr("need.prompt")), 0);
|
||||
}, []);
|
||||
|
||||
const doAction = useCallback((action, actionKey) => {
|
||||
const tr = tRef.current;
|
||||
const label = tr(actionKey);
|
||||
fetch("/dsh-purge/" + action, { method: "POST", headers: { "content-type": "application/json" }, body: "{}" })
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (d.ok) {
|
||||
const ticket = ++actionTicket.current;
|
||||
const run = () => {
|
||||
setPatchBusy(true);
|
||||
setAskRestart(false);
|
||||
setNotice({ kind: "idle", text: "" });
|
||||
fetch("/dsh-purge/" + action, {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(action === "apply" ? { content: override } : {}),
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
const applyEmptyBlocked = action === "apply" && promptBoxEmpty(override) && (!d || d.injectSource !== "rule");
|
||||
if (responseNeedsPrompt(d) || applyEmptyBlocked) {
|
||||
rejectNeedPrompt(tr);
|
||||
return;
|
||||
}
|
||||
if (!d.ok) {
|
||||
setNotice({ kind: "error", text: tr("err.action", { action: label, error: d.error || "" }) });
|
||||
return;
|
||||
}
|
||||
if (action === "apply") {
|
||||
if (typeof d.defaultContent === "string") setDefaultOverride(d.defaultContent);
|
||||
const shown = d.override_content || d.defaultContent;
|
||||
if (typeof shown === "string" && shown) {
|
||||
setOverride(shown);
|
||||
if (typeof d.override_content === "string") {
|
||||
setOverride(d.override_content);
|
||||
setOverrideLoaded(true);
|
||||
}
|
||||
}
|
||||
@@ -858,32 +909,68 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
setNotice({ kind: "ok", text: tr("ok.done") });
|
||||
loadAll();
|
||||
if (action === "apply") setAskRestart(true);
|
||||
} else {
|
||||
setNotice({ kind: "error", text: tr("err.action", { action: label, error: d.error || "" }) });
|
||||
}
|
||||
})
|
||||
.catch((e) => setNotice({ kind: "error", text: tr("err.action", { action: label, error: e.message }) }))
|
||||
.finally(() => setPatchBusy(false));
|
||||
}, [loadAll]);
|
||||
})
|
||||
.catch((e) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
setNotice({ kind: "error", text: tr("err.action", { action: label, error: e.message }) });
|
||||
})
|
||||
.finally(() => {
|
||||
if (ticket === actionTicket.current) setPatchBusy(false);
|
||||
});
|
||||
};
|
||||
if (action !== "apply") {
|
||||
run();
|
||||
return;
|
||||
}
|
||||
bothInjectEmpty(override).then((empty) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
if (empty) {
|
||||
rejectNeedPrompt(tr);
|
||||
return;
|
||||
}
|
||||
run();
|
||||
});
|
||||
}, [loadAll, override, rejectNeedPrompt]);
|
||||
|
||||
const saveOverride = useCallback(() => {
|
||||
setPatchBusy(true);
|
||||
setNotice({ kind: "idle", text: "" });
|
||||
fetch("/dsh-purge/override", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ content: override }),
|
||||
})
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (d.ok && typeof d.content === "string") setOverride(d.content);
|
||||
setNotice(d.ok
|
||||
? { kind: "ok", text: t("saved.override") }
|
||||
: { kind: "error", text: t("err.save", { error: d.error || "" }) });
|
||||
const tr = t;
|
||||
const ticket = ++actionTicket.current;
|
||||
const go = () => {
|
||||
setPatchBusy(true);
|
||||
setAskRestart(false);
|
||||
setNotice({ kind: "idle", text: "" });
|
||||
fetch("/dsh-purge/override", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ content: override }),
|
||||
})
|
||||
.catch((e) => setNotice({ kind: "error", text: t("err.save", { error: e.message }) }))
|
||||
.finally(() => setPatchBusy(false));
|
||||
}, [override, t]);
|
||||
.then((r) => r.json())
|
||||
.then((d) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
if (!d.ok || responseNeedsPrompt(d) || (promptBoxEmpty(override) && d.injectSource !== "rule")) {
|
||||
rejectNeedPrompt(tr);
|
||||
return;
|
||||
}
|
||||
if (typeof d.content === "string") setOverride(d.content);
|
||||
setNotice({ kind: "ok", text: t("saved.override") });
|
||||
})
|
||||
.catch((e) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
setNotice({ kind: "error", text: t("err.save", { error: e.message }) });
|
||||
})
|
||||
.finally(() => {
|
||||
if (ticket === actionTicket.current) setPatchBusy(false);
|
||||
});
|
||||
};
|
||||
bothInjectEmpty(override).then((empty) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
if (empty) {
|
||||
rejectNeedPrompt(tr);
|
||||
return;
|
||||
}
|
||||
go();
|
||||
});
|
||||
}, [override, t, rejectNeedPrompt]);
|
||||
|
||||
const restoreOverride = useCallback(() => {
|
||||
if (!defaultOverride) return;
|
||||
@@ -1056,6 +1143,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
spellCheck: false,
|
||||
placeholder: "",
|
||||
}),
|
||||
promptBoxEmpty(override) ? h("p", {
|
||||
className: "dshp-hint",
|
||||
style: { margin: "8px 0 0", color: "var(--dshp-danger, #c44)", fontSize: 12 },
|
||||
}, t("need.prompt")) : null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1105,9 +1196,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
.then((d) => {
|
||||
if (d && d.ok) {
|
||||
setNotice({ kind: "ok", text: t("ok.done") });
|
||||
if (action === "save" || action === "activate") warnNeedPrompt(d, t);
|
||||
loadStatus();
|
||||
if (after) after();
|
||||
} else {
|
||||
warnNeedPrompt(d, t);
|
||||
setNotice({ kind: "error", text: t("err.action", { error: (d && d.error) || "" }) });
|
||||
}
|
||||
})
|
||||
@@ -1123,7 +1216,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
setEditId(id);
|
||||
setEditName(d.name || id);
|
||||
setEditTarget(d.target || "AGENTS.md");
|
||||
setContent(d.content || "");
|
||||
setContent(typeof d.content === "string" ? d.content : "");
|
||||
} else setNotice({ kind: "error", text: t("err.read", { error: d.error || "" }) });
|
||||
})
|
||||
.catch((e) => setNotice({ kind: "error", text: t("err.read", { error: e.message }) }))
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
autoApplyOnStart: true
|
||||
autoUpdateOnStart: true
|
||||
autoRevertOnMissing: false
|
||||
injectOnce: true
|
||||
injectOnce: false
|
||||
stripMnemon: true
|
||||
verbose: false
|
||||
postPrompt: ""
|
||||
|
||||
+35
-15
@@ -2975,11 +2975,11 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\t\t...transformed,\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, assembled) {\n" +
|
||||
"\t\t\t\tconst sections = assembled.sections || [];\n" +
|
||||
"\t\t\t\tconst inject = sections.filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\")).map((s) => String(s.text || \"\").trim()).filter(Boolean).join(\"\\n\\n\");\n" +
|
||||
"\t\t\t\tconst inject = sections.filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\")).map((s) => String(s.text || \"\")).filter((t) => t.length > 0).join(\"\\n\\n\");\n" +
|
||||
"\t\t\t\tconst folded = sections.find((s) => s && s.name === complete.name);\n" +
|
||||
"\t\t\t\tconst base = folded && typeof folded.text === \"string\" ? { ...complete, text: folded.text } : { ...complete };\n" +
|
||||
"\t\t\t\tif (!inject) return [base];\n" +
|
||||
"\t\t\t\tif (String(base.text || \"\").includes(inject.slice(0, Math.min(80, inject.length)))) 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 inject\n" +
|
||||
"\t\t\t})(completeSection, transformed),\n" +
|
||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
|
||||
@@ -4249,16 +4249,20 @@ export function overrideStatePath(dshHome) {
|
||||
return path.join(dshHome, "dsh-purge", "override-state.json");
|
||||
}
|
||||
|
||||
export async function readOverrideState(dshHome) {
|
||||
export function readOverrideStateSync(dshHome) {
|
||||
const fp = overrideStatePath(dshHome);
|
||||
try {
|
||||
const raw = JSON.parse(await fsp.readFile(fp, "utf8"));
|
||||
const raw = JSON.parse(fs.readFileSync(fp, "utf8"));
|
||||
return raw && typeof raw === "object" ? raw : {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export async function readOverrideState(dshHome) {
|
||||
return readOverrideStateSync(dshHome);
|
||||
}
|
||||
|
||||
export async function writeOverrideState(dshHome, state) {
|
||||
const fp = overrideStatePath(dshHome);
|
||||
await fsp.mkdir(path.dirname(fp), { recursive: true });
|
||||
@@ -4275,6 +4279,9 @@ export async function markOverrideCustomized(dshHome, customized, text) {
|
||||
}
|
||||
|
||||
export async function isUserCustomizedOverride(dshHome) {
|
||||
const state = await readOverrideState(dshHome);
|
||||
if (state.customized === true) return true;
|
||||
if (state.customized === false) return false;
|
||||
const fp = findOverrideFile(dshHome);
|
||||
let disk = "";
|
||||
if (fs.existsSync(fp)) {
|
||||
@@ -4286,9 +4293,6 @@ export async function isUserCustomizedOverride(dshHome) {
|
||||
}
|
||||
if (!normalizeOverride(disk)) return false;
|
||||
if (hashOverride(disk) === defaultOverrideHash()) return false;
|
||||
const state = await readOverrideState(dshHome);
|
||||
if (state.customized === false) return false;
|
||||
if (state.customized === true) return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4319,11 +4323,11 @@ export async function readOverrideForUi(dshHome) {
|
||||
}
|
||||
}
|
||||
const customized = await isUserCustomizedOverride(dshHome);
|
||||
const show = customized && normalizeOverride(disk) ? disk : defaultContent;
|
||||
const show = customized ? disk : defaultContent;
|
||||
return {
|
||||
path: fp,
|
||||
exists,
|
||||
empty: !normalizeOverride(disk),
|
||||
empty: !normalizeOverride(show),
|
||||
customized,
|
||||
usingDefault: !customized,
|
||||
content: show,
|
||||
@@ -4331,6 +4335,24 @@ export async function readOverrideForUi(dshHome) {
|
||||
};
|
||||
}
|
||||
|
||||
/** 插件加载时同步落下默认提示词,避免第一轮 assemble 读到空文件。 */
|
||||
export function seedOverrideSync(dshHome) {
|
||||
const fp = findOverrideFile(dshHome);
|
||||
fs.mkdirSync(dshHome, { recursive: true });
|
||||
if (readOverrideStateSync(dshHome).customized === true) return "exists";
|
||||
let disk = "";
|
||||
try {
|
||||
if (fs.existsSync(fp)) disk = fs.readFileSync(fp, "utf8");
|
||||
} catch {
|
||||
disk = "";
|
||||
}
|
||||
if (normalizeOverride(disk)) return "exists";
|
||||
const bundled = defaultOverrideText();
|
||||
if (!normalizeOverride(bundled)) return fs.existsSync(fp) ? "empty" : "missing";
|
||||
fs.writeFileSync(fp, bundled, "utf8");
|
||||
return "wrote";
|
||||
}
|
||||
|
||||
export async function installOverride(dshHome, force = false) {
|
||||
const fp = findOverrideFile(dshHome);
|
||||
await fsp.mkdir(dshHome, { recursive: true });
|
||||
@@ -4345,14 +4367,12 @@ export async function installOverride(dshHome, force = false) {
|
||||
export async function saveOverrideContent(dshHome, content) {
|
||||
const bundled = defaultOverrideText();
|
||||
const incoming = typeof content === "string" ? content : "";
|
||||
const customized = Boolean(normalizeOverride(incoming))
|
||||
&& normalizeOverride(incoming) !== normalizeOverride(bundled);
|
||||
const toWrite = customized ? incoming : bundled;
|
||||
const customized = normalizeOverride(incoming) !== normalizeOverride(bundled);
|
||||
const fp = findOverrideFile(dshHome);
|
||||
await fsp.mkdir(dshHome, { recursive: true });
|
||||
await fsp.writeFile(fp, toWrite, "utf8");
|
||||
await markOverrideCustomized(dshHome, customized, toWrite);
|
||||
return { path: fp, customized, content: toWrite };
|
||||
await fsp.writeFile(fp, incoming, "utf8");
|
||||
await markOverrideCustomized(dshHome, customized, incoming);
|
||||
return { path: fp, customized, content: incoming, defaultContent: bundled };
|
||||
}
|
||||
|
||||
export async function ensureOverrideContent(dshHome, force = false) {
|
||||
|
||||
+29
-20
@@ -90,10 +90,20 @@ function stripHarnessPersona(text) {
|
||||
}
|
||||
|
||||
function collectInjectText(purgeSections, fallbackText) {
|
||||
const fallback = typeof fallbackText === "string" ? fallbackText : "";
|
||||
if (fallback) return fallback;
|
||||
const main = purgeSections.find((section) => section.name === "dsh-purge");
|
||||
const fromMain = String(main?.text || "").trim();
|
||||
if (fromMain) return fromMain;
|
||||
return typeof fallbackText === "string" ? fallbackText.trim() : "";
|
||||
return String(main?.text || "");
|
||||
}
|
||||
|
||||
function assemblyHasExactInject(sections, inject) {
|
||||
if (!inject) return true;
|
||||
return sections.some((section) => String(section?.text || "").includes(inject));
|
||||
}
|
||||
|
||||
function ensureFullInject(sections, inject) {
|
||||
if (!inject || assemblyHasExactInject(sections, inject)) return sections;
|
||||
return [{ name: "dsh-purge", text: inject, order: -10000 }, ...sections];
|
||||
}
|
||||
|
||||
function stripIdentityPrefix(text) {
|
||||
@@ -135,13 +145,13 @@ function messageText(message) {
|
||||
|
||||
export function existingSystemPrompt(context) {
|
||||
const events = eventList(context?.agent?.session || context?.session);
|
||||
let latest = "";
|
||||
const texts = [];
|
||||
for (const event of events) {
|
||||
if (event?.type !== "system/message") continue;
|
||||
const text = messageText(event.data?.message || event.data).trim();
|
||||
if (text) latest = text;
|
||||
if (text) texts.push(text);
|
||||
}
|
||||
return latest;
|
||||
return texts.join("\n\n");
|
||||
}
|
||||
|
||||
export function isFirstConversationTurn(context) {
|
||||
@@ -162,13 +172,13 @@ export function isFirstConversationTurn(context) {
|
||||
export function promptAlreadyInjected(existing, injectText) {
|
||||
const inject = String(injectText || "").trim();
|
||||
if (!inject) return false;
|
||||
return String(existing || "").includes(inject.slice(0, Math.min(80, inject.length)));
|
||||
return String(existing || "").includes(inject);
|
||||
}
|
||||
|
||||
export function shouldInjectPrompt(context, injectOnce = true, injectText = "") {
|
||||
if (injectOnce === false) return true;
|
||||
if (isFirstConversationTurn(context)) return true;
|
||||
return !promptAlreadyInjected(existingSystemPrompt(context), injectText);
|
||||
export function shouldInjectPrompt(_context, _injectOnce = true, _injectText = "") {
|
||||
// 0.1.5 in-history:渲染少了注入就会再追加一条 system/message。
|
||||
// 用「最后一条是否含注入」决定本步掏空注入,会 A/B 死循环。每步都必须留下完整注入。
|
||||
return true;
|
||||
}
|
||||
|
||||
export function isMnemonPluginMessage(message) {
|
||||
@@ -199,7 +209,7 @@ function normalizeRewriteOptions(fallbackInject, options) {
|
||||
|
||||
// 0.1.5 优先写入 persona-prefix;无 prefix 时写入 legacy persona。
|
||||
function foldInjectIntoPersona(sections, injectText) {
|
||||
const inject = typeof injectText === "string" ? injectText.trim() : "";
|
||||
const inject = typeof injectText === "string" ? injectText : "";
|
||||
const names = sections.map((s) => String(s?.name || ""));
|
||||
const hasPrefix = names.some((n) => PERSONA_PREFIX_NAMES.has(n));
|
||||
let folded = false;
|
||||
@@ -207,16 +217,16 @@ function foldInjectIntoPersona(sections, injectText) {
|
||||
const name = String(section?.name || "");
|
||||
if (!isPersonaFoldTarget(name, hasPrefix)) return section;
|
||||
folded = true;
|
||||
const prior = stripIdentityPrefix(String(section.text || "").trim());
|
||||
const prior = stripIdentityPrefix(String(section.text || ""));
|
||||
if (!inject) return { ...section, text: prior };
|
||||
if (prior.includes(inject.slice(0, Math.min(80, inject.length)))) {
|
||||
return { ...section, text: prior };
|
||||
}
|
||||
if (prior.includes(inject)) return { ...section, text: prior };
|
||||
return { ...section, text: prior ? `${inject}\n\n${prior}` : inject };
|
||||
});
|
||||
if (folded) return out;
|
||||
if (!inject) return out;
|
||||
return [{ name: "deployment:persona-prefix", text: inject }, ...out];
|
||||
const orders = sections.map((s) => s?.order).filter((n) => Number.isFinite(n));
|
||||
const order = orders.length ? Math.min(0, ...orders) : 0;
|
||||
return [{ name: "deployment:persona-prefix", text: inject, order }, ...out];
|
||||
}
|
||||
|
||||
export function rewritePromptAssembly(assembled, fallbackInject = "", options = {}) {
|
||||
@@ -233,18 +243,17 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
next.text = stripHarnessPersona(next.text);
|
||||
}
|
||||
if (String(next.name).startsWith("dsh-purge")) {
|
||||
if (!opts.fallbackInject) continue;
|
||||
purge.push(next);
|
||||
} else {
|
||||
rest.push(next);
|
||||
}
|
||||
}
|
||||
|
||||
const injectText = opts.fallbackInject ? collectInjectText(purge, opts.fallbackInject) : "";
|
||||
const injectText = collectInjectText(purge, opts.fallbackInject);
|
||||
const folded = foldInjectIntoPersona(rest, injectText);
|
||||
const extras = opts.dropPurgeAfterFold
|
||||
? purge.filter((section) => section.name !== "dsh-purge")
|
||||
: purge;
|
||||
assembled.sections = [...folded, ...extras];
|
||||
assembled.sections = ensureFullInject([...folded, ...extras], injectText);
|
||||
return assembled;
|
||||
}
|
||||
+76
-67
@@ -1,6 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import { promises as fsp } from "node:fs";
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
import * as core from "./core.js";
|
||||
import * as hostctl from "./host.js";
|
||||
import * as rules from "./rules.js";
|
||||
@@ -9,7 +8,6 @@ import {
|
||||
GLOBAL_PROMPT_ORDER,
|
||||
isMnemonPluginMessage,
|
||||
rewritePromptAssembly,
|
||||
shouldInjectPrompt,
|
||||
} from "./identity.js";
|
||||
import * as rewind from "./rewind.js";
|
||||
import * as continueRetry from "./continue-retry.js";
|
||||
@@ -24,7 +22,7 @@ const DEFAULTS = {
|
||||
autoApplyOnStart: true,
|
||||
autoUpdateOnStart: true,
|
||||
autoRevertOnMissing: false,
|
||||
injectOnce: true,
|
||||
injectOnce: false,
|
||||
stripMnemon: true,
|
||||
postPrompt: "",
|
||||
postPromptOrder: 5100,
|
||||
@@ -138,43 +136,39 @@ function renderStatus(state) {
|
||||
return out.join("\n");
|
||||
}
|
||||
|
||||
function readInjectFile(injectFile) {
|
||||
try {
|
||||
if (!injectFile || !fs.existsSync(injectFile)) return "";
|
||||
return fs.readFileSync(injectFile, "utf8").trim();
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
const assembleState = new AsyncLocalStorage();
|
||||
|
||||
function injectAllowedNow(config) {
|
||||
if (config.enabled === false) return false;
|
||||
const state = assembleState.getStore();
|
||||
return !state || state.allow !== false;
|
||||
return config.enabled !== false;
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, injectFile) {
|
||||
function injectSnapshot(dshHome = core.findDshHome()) {
|
||||
const resolved = rules.resolveInjectText(dshHome);
|
||||
return {
|
||||
injectSource: resolved.source,
|
||||
injectRuleId: resolved.ruleId,
|
||||
needPrompt: resolved.source === "none",
|
||||
};
|
||||
}
|
||||
|
||||
/** 以设置页文本框为准;空框且没有启用中的规则集则必须补提示词。 */
|
||||
function injectSnapshotFromBox(dshHome, boxText) {
|
||||
if (typeof boxText !== "string") return injectSnapshot(dshHome);
|
||||
if (core.normalizeOverride(boxText)) {
|
||||
return { injectSource: "prompt", injectRuleId: null, needPrompt: false };
|
||||
}
|
||||
const ruleId = rules.activeRuleId(dshHome);
|
||||
if (core.normalizeOverride(rules.activeRuleText(dshHome))) {
|
||||
return { injectSource: "rule", injectRuleId: ruleId, needPrompt: false };
|
||||
}
|
||||
return { injectSource: "none", injectRuleId: ruleId, needPrompt: true };
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, _injectFile) {
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge",
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
text: () => {
|
||||
if (!injectAllowedNow(config)) return "";
|
||||
return readInjectFile(injectFile);
|
||||
},
|
||||
});
|
||||
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge:rules",
|
||||
order: GLOBAL_PROMPT_ORDER + 1,
|
||||
text: () => {
|
||||
if (!injectAllowedNow(config)) return "";
|
||||
try {
|
||||
return rules.activeRuleText(core.findDshHome());
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
return rules.resolveInjectText(core.findDshHome()).text;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -190,26 +184,8 @@ export function registerPromptSections(ctx, config, injectFile) {
|
||||
});
|
||||
}
|
||||
|
||||
const INJECT_FALLBACK_MAX_BYTES = 512 * 1024;
|
||||
|
||||
function readInjectFallback() {
|
||||
try {
|
||||
const fp = core.findOverrideFile(core.findDshHome());
|
||||
if (!fp || !fs.existsSync(fp)) return "";
|
||||
const st = fs.statSync(fp);
|
||||
if (!st.isFile() || st.size <= 0) return "";
|
||||
if (st.size <= INJECT_FALLBACK_MAX_BYTES) return fs.readFileSync(fp, "utf8");
|
||||
const fd = fs.openSync(fp, "r");
|
||||
try {
|
||||
const buf = Buffer.alloc(INJECT_FALLBACK_MAX_BYTES);
|
||||
const n = fs.readSync(fd, buf, 0, INJECT_FALLBACK_MAX_BYTES, 0);
|
||||
return buf.toString("utf8", 0, n);
|
||||
} finally {
|
||||
fs.closeSync(fd);
|
||||
}
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
return rules.resolveInjectText(core.findDshHome()).text;
|
||||
}
|
||||
|
||||
function installMnemonMessageStrip(ctx, config = {}) {
|
||||
@@ -238,16 +214,14 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
if (typeof ctx.on !== "function") return;
|
||||
if (ctx.__dshPurgeAssembleHook) return;
|
||||
ctx.__dshPurgeAssembleHook = true;
|
||||
const hook = async (_assembly, context, next) => {
|
||||
const inject = config.enabled === false ? "" : readInjectFallback();
|
||||
const allow = config.enabled !== false && shouldInjectPrompt(context, config.injectOnce !== false, inject);
|
||||
return assembleState.run({ allow }, async () => {
|
||||
const assembled = typeof next === "function" ? await next() : _assembly;
|
||||
return rewritePromptAssembly(assembled, {
|
||||
fallbackInject: allow ? inject : "",
|
||||
dropMnemon: config.stripMnemon !== false,
|
||||
dropPurgeAfterFold: true,
|
||||
});
|
||||
const hook = async (_assembly, _context, next) => {
|
||||
const assembled = typeof next === "function" ? await next() : _assembly;
|
||||
const enabled = config.enabled !== false;
|
||||
const inject = enabled ? readInjectFallback() : "";
|
||||
return rewritePromptAssembly(assembled, {
|
||||
fallbackInject: inject,
|
||||
dropMnemon: config.stripMnemon !== false,
|
||||
dropPurgeAfterFold: true,
|
||||
});
|
||||
};
|
||||
// 只挂一次:挂多次会让同一轮 assemble 折两遍,UI 也会显示两次注入。
|
||||
@@ -559,6 +533,11 @@ export function apply(ctx, config) {
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
core.seedOverrideSync(core.findDshHome());
|
||||
} catch (e) {
|
||||
console.warn("[dsh-purge] seed override error:", String(e));
|
||||
}
|
||||
installIdentityOverride(ctx, cfg);
|
||||
installMnemonMessageStrip(ctx, cfg);
|
||||
const injectFile = core.findOverrideFile(core.findDshHome());
|
||||
@@ -948,9 +927,24 @@ function installWebServer(ctx, cfg) {
|
||||
sendJson(response, 500, { ok: false, error: core.missingAiBaseMessage() });
|
||||
return;
|
||||
}
|
||||
const body = await readJsonBody(request);
|
||||
const ui = await core.readOverrideForUi(state.dsh_home);
|
||||
const boxText = typeof body?.content === "string" ? body.content : ui.content;
|
||||
const snap = injectSnapshotFromBox(state.dsh_home, boxText);
|
||||
if (snap.needPrompt) {
|
||||
sendJson(response, 400, {
|
||||
ok: false,
|
||||
needPrompt: true,
|
||||
error: "提示词和规则集都是空的,必须先添加提示词",
|
||||
override_content: boxText,
|
||||
defaultContent: ui.defaultContent,
|
||||
...snap,
|
||||
});
|
||||
return;
|
||||
}
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const override = await core.ensureOverrideContent(state.dsh_home, false);
|
||||
const override = await core.readOverrideForUi(state.dsh_home);
|
||||
const shim = await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
@@ -968,6 +962,8 @@ function installWebServer(ctx, cfg) {
|
||||
})),
|
||||
report: report.map((r) => ({ id: r.patch_id, name: r.name, status: r.status })),
|
||||
override_content: override.content,
|
||||
defaultContent: override.defaultContent,
|
||||
...injectSnapshot(state.dsh_home),
|
||||
override_path: override.path,
|
||||
override_installed: override.installed,
|
||||
shim,
|
||||
@@ -1038,8 +1034,9 @@ function installWebServer(ctx, cfg) {
|
||||
handler: async (request, response) => {
|
||||
if (request.method === "GET") {
|
||||
try {
|
||||
const ui = await core.ensureOverrideContent(core.findDshHome(), false);
|
||||
sendJson(response, 200, { ok: true, ...ui });
|
||||
const home = core.findDshHome();
|
||||
const ui = await core.readOverrideForUi(home);
|
||||
sendJson(response, 200, { ok: true, ...ui, ...injectSnapshot(home) });
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
@@ -1053,8 +1050,19 @@ function installWebServer(ctx, cfg) {
|
||||
sendJson(response, 400, { ok: false, error: "content must be a string" });
|
||||
return;
|
||||
}
|
||||
const saved = await core.saveOverrideContent(core.findDshHome(), content);
|
||||
sendJson(response, 200, { ok: true, ...saved });
|
||||
const home = core.findDshHome();
|
||||
const snap = injectSnapshotFromBox(home, content);
|
||||
if (snap.needPrompt) {
|
||||
sendJson(response, 400, {
|
||||
ok: false,
|
||||
error: "提示词和规则集都是空的,必须先添加提示词",
|
||||
content,
|
||||
...snap,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const saved = await core.saveOverrideContent(home, content);
|
||||
sendJson(response, 200, { ok: true, ...saved, ...injectSnapshot(home) });
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
@@ -1121,7 +1129,7 @@ async function handleRulesOp(op, body, queryId) {
|
||||
name: typeof body?.name === "string" ? body.name : undefined,
|
||||
target: typeof body?.target === "string" ? body.target : undefined,
|
||||
});
|
||||
return { ok: true, id };
|
||||
return { ok: true, id, ...injectSnapshot(dshHome) };
|
||||
}
|
||||
if (op === "activate") {
|
||||
if (!rules.validRuleId(id)) return { status: 400, ok: false, error: "invalid id" };
|
||||
@@ -1133,6 +1141,7 @@ async function handleRulesOp(op, body, queryId) {
|
||||
target: meta.target,
|
||||
agents_path: rules.targetPath(dshHome, meta.target),
|
||||
note: "已写入目标文件并注入 systemPrompt,新会话生效",
|
||||
...injectSnapshot(dshHome),
|
||||
};
|
||||
}
|
||||
if (op === "delete") {
|
||||
|
||||
+37
-19
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import { promises as fsp } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { findDshHome } from "./core.js";
|
||||
import { findDshHome, findOverrideFile, normalizeOverride } from "./core.js";
|
||||
|
||||
const RULE_ID_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
|
||||
const MAX_RULE_BYTES = 256 * 1024;
|
||||
@@ -151,17 +151,46 @@ export async function setActive(dshHome, id) {
|
||||
await fsp.writeFile(stateFile(dshHome), JSON.stringify({ active: id }, null, 2), "utf8");
|
||||
}
|
||||
|
||||
export function activeRuleText(dshHome) {
|
||||
export function activeRuleId(dshHome) {
|
||||
try {
|
||||
const parsed = JSON.parse(fs.readFileSync(stateFile(dshHome), "utf8"));
|
||||
const id = parsed?.active;
|
||||
if (!validRuleId(id)) return "";
|
||||
return fs.readFileSync(rulePath(dshHome, id), "utf8").trim();
|
||||
return validRuleId(id) ? id : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function activeRuleText(dshHome) {
|
||||
const id = activeRuleId(dshHome);
|
||||
if (!id) return "";
|
||||
try {
|
||||
return fs.readFileSync(rulePath(dshHome, id), "utf8");
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export function overrideFileText(dshHome) {
|
||||
const fp = findOverrideFile(dshHome);
|
||||
try {
|
||||
if (!fp || !fs.existsSync(fp)) return "";
|
||||
return fs.readFileSync(fp, "utf8");
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/** 提示词优先;为空则用当前启用的规则集。两边都空则不注入。 */
|
||||
export function resolveInjectText(dshHome) {
|
||||
const prompt = overrideFileText(dshHome);
|
||||
if (normalizeOverride(prompt)) return { text: prompt, source: "prompt", ruleId: null };
|
||||
const ruleId = activeRuleId(dshHome);
|
||||
const rule = activeRuleText(dshHome);
|
||||
if (normalizeOverride(rule)) return { text: rule, source: "rule", ruleId };
|
||||
return { text: "", source: "none", ruleId };
|
||||
}
|
||||
|
||||
export async function activateRule(dshHome, id) {
|
||||
const content = await readRule(dshHome, id);
|
||||
if (content === null) throw new Error(`rule not found: ${id}`);
|
||||
@@ -181,21 +210,7 @@ export async function ensureInitialState(dshHome) {
|
||||
}
|
||||
active = null;
|
||||
}
|
||||
if (active !== null) return { active };
|
||||
if (listed.length > 0) return { active: null };
|
||||
for (const target of RULE_TARGETS) {
|
||||
try {
|
||||
const content = await fsp.readFile(targetPath(dshHome, target), "utf8");
|
||||
if (content.trim().length > 0) {
|
||||
await saveRule(dshHome, "default", content, { name: "默认规则", target });
|
||||
await setActive(dshHome, "default");
|
||||
return { active: "default", imported: target };
|
||||
}
|
||||
} catch {
|
||||
// 当前 target 文件不存在,试下一个
|
||||
}
|
||||
}
|
||||
return { active: null };
|
||||
return { active };
|
||||
}
|
||||
|
||||
export async function resetToOriginal(dshHome) {
|
||||
@@ -243,9 +258,12 @@ export async function rulesStatus(dshHome) {
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
const inject = resolveInjectText(dshHome);
|
||||
return {
|
||||
rules: listed,
|
||||
active,
|
||||
injectSource: inject.source,
|
||||
injectRuleId: inject.ruleId,
|
||||
active_target,
|
||||
agents_exists,
|
||||
agents_synced,
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.9",
|
||||
"version": "1.1.10",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
|
||||
Reference in new issue
Block a user