mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-12-03 12:00:22 +08:00
feat: 发布 1.1.10,空提示词拦截并修首轮注入
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
56ba72a035
commit
51a9d271dd
9 files changed
+334
-175
No files matched your search
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<h1 align="center">⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)</h1>
|
<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">
|
<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>
|
<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>
|
||||||
@@ -39,7 +39,7 @@ If this project helps you, send it over — I'm out here asking~
|
|||||||
|
|
||||||
| Asset | Address |
|
| Asset | Address |
|
||||||
|---|---|
|
|---|---|
|
||||||
| **USDT (TRC20)** | `TScRVxQsUhCRh5jApLVxwFdWcJ1S2hKWRf` |
|
| **USDT (TRC20)** | `TV5ajPkRD8RH623Dx9mqvYZVNN8nPGRKid` |
|
||||||
| **Solana** | `6x16GhRgLVpKFFXaU1seKNdx2rypspSJTL4dbpt6Xpwk` |
|
| **Solana** | `6x16GhRgLVpKFFXaU1seKNdx2rypspSJTL4dbpt6Xpwk` |
|
||||||
| **Ethereum** | `0xB68BD60C0e8c519513B7DF9bB147696815423B3E` |
|
| **Ethereum** | `0xB68BD60C0e8c519513B7DF9bB147696815423B3E` |
|
||||||
| **Bitcoin** | `bc1qu70yxkrtwnymt8ryluz9x8y8hqzune5340npht` |
|
| **Bitcoin** | `bc1qu70yxkrtwnymt8ryluz9x8y8hqzune5340npht` |
|
||||||
@@ -244,13 +244,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://deepseek.stream/plugins/dsh-purge"><strong>🌐 Open Hub page</strong></a>
|
<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>
|
</p>
|
||||||
|
|
||||||
🔗 **Raw protocol URL:**
|
🔗 **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:**
|
**Web trigger example:**
|
||||||
@@ -263,7 +263,7 @@ export function installDshPurgeToDesktop() {
|
|||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
id: 'dsh-purge',
|
id: 'dsh-purge',
|
||||||
name: 'dsh-purge',
|
name: 'dsh-purge',
|
||||||
version: '1.1.9',
|
version: '1.1.10',
|
||||||
repo: 'YuJunZhiXue/dsh-purge',
|
repo: 'YuJunZhiXue/dsh-purge',
|
||||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||||
@@ -282,7 +282,7 @@ export function installDshPurgeToDesktop() {
|
|||||||
**HTML link:**
|
**HTML link:**
|
||||||
|
|
||||||
```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">
|
||||||
🚀 Install in desktop client
|
🚀 Install in desktop client
|
||||||
</a>
|
</a>
|
||||||
```
|
```
|
||||||
@@ -293,7 +293,7 @@ export function installDshPurgeToDesktop() {
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| id | `dsh-purge` | Plugin id |
|
| id | `dsh-purge` | Plugin id |
|
||||||
| name | `dsh-purge` | Display name |
|
| name | `dsh-purge` | Display name |
|
||||||
| version | `1.1.9` | Semver |
|
| version | `1.1.10` | Semver |
|
||||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub repo |
|
| repo | `YuJunZhiXue/dsh-purge` | GitHub repo |
|
||||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions |
|
| permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions |
|
||||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub source archive |
|
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub source archive |
|
||||||
@@ -745,6 +745,11 @@ If nothing is found, set `DSH_BASE` / `DSH_DESKTOP_INSTALL`. No files are change
|
|||||||
|
|
||||||
## Changelog
|
## 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
|
### 1.1.9
|
||||||
|
|
||||||
- Removed the default prompt from the repository
|
- Removed the default prompt from the repository
|
||||||
|
|||||||
+12
-7
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
<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">
|
<p align="center">
|
||||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件:在受控本机环境评测并加固宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
<em>本机官方 DeepSeek Harness 网络安全红队评测插件:在受控本机环境评测并加固宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
|
|
||||||
| 币种 | 地址 |
|
| 币种 | 地址 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| **USDT(TRC20)** | `TScRVxQsUhCRh5jApLVxwFdWcJ1S2hKWRf` |
|
| **USDT(TRC20)** | `TV5ajPkRD8RH623Dx9mqvYZVNN8nPGRKid` |
|
||||||
| **Solana** | `6x16GhRgLVpKFFXaU1seKNdx2rypspSJTL4dbpt6Xpwk` |
|
| **Solana** | `6x16GhRgLVpKFFXaU1seKNdx2rypspSJTL4dbpt6Xpwk` |
|
||||||
| **Ethereum** | `0xB68BD60C0e8c519513B7DF9bB147696815423B3E` |
|
| **Ethereum** | `0xB68BD60C0e8c519513B7DF9bB147696815423B3E` |
|
||||||
| **Bitcoin** | `bc1qu70yxkrtwnymt8ryluz9x8y8hqzune5340npht` |
|
| **Bitcoin** | `bc1qu70yxkrtwnymt8ryluz9x8y8hqzune5340npht` |
|
||||||
@@ -241,13 +241,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://deepseek.stream/plugins/dsh-purge"><strong>🌐 打开插件市场页</strong></a>
|
<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>
|
</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
|
||||||
```
|
```
|
||||||
|
|
||||||
**网页端(前端)触发代码示例:**
|
**网页端(前端)触发代码示例:**
|
||||||
@@ -260,7 +260,7 @@ export function installDshPurgeToDesktop() {
|
|||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
id: 'dsh-purge',
|
id: 'dsh-purge',
|
||||||
name: 'dsh-purge',
|
name: 'dsh-purge',
|
||||||
version: '1.1.9',
|
version: '1.1.10',
|
||||||
repo: 'YuJunZhiXue/dsh-purge',
|
repo: 'YuJunZhiXue/dsh-purge',
|
||||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||||
@@ -279,7 +279,7 @@ export function installDshPurgeToDesktop() {
|
|||||||
**HTML 静态链接方式:**
|
**HTML 静态链接方式:**
|
||||||
|
|
||||||
```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>
|
</a>
|
||||||
```
|
```
|
||||||
@@ -290,7 +290,7 @@ export function installDshPurgeToDesktop() {
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| id | `dsh-purge` | 插件唯一标识符 |
|
| id | `dsh-purge` | 插件唯一标识符 |
|
||||||
| name | `dsh-purge` | 插件展示名称 |
|
| name | `dsh-purge` | 插件展示名称 |
|
||||||
| version | `1.1.9` | 语义化版本号 |
|
| version | `1.1.10` | 语义化版本号 |
|
||||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
|
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
|
||||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
|
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
|
||||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
|
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
|
||||||
@@ -732,6 +732,11 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
|
|||||||
|
|
||||||
## 更新记录
|
## 更新记录
|
||||||
|
|
||||||
|
### 1.1.10
|
||||||
|
|
||||||
|
- 提示词和规则集都空时不能保存或应用,弹窗要求先添加提示词
|
||||||
|
- 第一轮完整注入;不再钉上一轮整篇系统提示,避免来回追加
|
||||||
|
|
||||||
### 1.1.9
|
### 1.1.9
|
||||||
|
|
||||||
- 将提示词从仓库中下线
|
- 将提示词从仓库中下线
|
||||||
|
|||||||
@@ -73,6 +73,35 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
|||||||
} finally { clearTimeout(timer); }
|
} 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) {
|
function rulesApi(op, extra) {
|
||||||
return apiJson("/dsh-purge/rules", {
|
return apiJson("/dsh-purge/rules", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -110,7 +139,8 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
|||||||
"apply.hint": "待应用=原文还在。跳过=没装或官方已改写,再点也不会变。",
|
"apply.hint": "待应用=原文还在。跳过=没装或官方已改写,再点也不会变。",
|
||||||
"warn.noRoot": "未定位到当前宿主的 @deepseek-ai,清洗不会生效。请完全退出后再打开本宿主,在本页点「应用」。桌面端安装目录可以是任意盘符,不要用官方 dsh 去清桌面端。",
|
"warn.noRoot": "未定位到当前宿主的 @deepseek-ai,清洗不会生效。请完全退出后再打开本宿主,在本页点「应用」。桌面端安装目录可以是任意盘符,不要用官方 dsh 去清桌面端。",
|
||||||
"warn.noRoot.desktop": "未定位到当前桌面应用里的 @deepseek-ai。请退出托盘后重新打开 DSH Desktop.exe,再在桌面端设置页点「应用」。安装目录不限盘符。",
|
"warn.noRoot.desktop": "未定位到当前桌面应用里的 @deepseek-ai。请退出托盘后重新打开 DSH Desktop.exe,再在桌面端设置页点「应用」。安装目录不限盘符。",
|
||||||
"warn.noInject": "未自行改过时始终使用插件内置默认提示词。保存不同内容后才会换成你的;恢复默认可改回去。",
|
"warn.noInject": "提示词优先;为空则注入当前启用的规则集。两边都空会提示必须添加。",
|
||||||
|
"need.prompt": "提示词和规则集都是空的,必须先添加提示词,或启用一条有内容的规则集。",
|
||||||
"btn.restoreInject": "恢复默认",
|
"btn.restoreInject": "恢复默认",
|
||||||
"saved.restoreInject": "已填入默认提示词,点保存写入",
|
"saved.restoreInject": "已填入默认提示词,点保存写入",
|
||||||
"skip": "跳过",
|
"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.",
|
"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": "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.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",
|
"btn.restoreInject": "Reset default",
|
||||||
"saved.restoreInject": "Default prompt loaded. Save to write.",
|
"saved.restoreInject": "Default prompt loaded. Save to write.",
|
||||||
"skip": "Skipped",
|
"skip": "Skipped",
|
||||||
@@ -732,6 +763,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
|||||||
const [updateNotice, setUpdateNotice] = useState({ kind: "idle", text: "" });
|
const [updateNotice, setUpdateNotice] = useState({ kind: "idle", text: "" });
|
||||||
const [updateInfo, setUpdateInfo] = useState(null);
|
const [updateInfo, setUpdateInfo] = useState(null);
|
||||||
const [canApplyUpdate, setCanApplyUpdate] = useState(false);
|
const [canApplyUpdate, setCanApplyUpdate] = useState(false);
|
||||||
|
const actionTicket = useRef(0);
|
||||||
|
|
||||||
const updateErrorText = (tr, e) => {
|
const updateErrorText = (tr, e) => {
|
||||||
const msg = String((e && e.message) || e || "");
|
const msg = String((e && e.message) || e || "");
|
||||||
@@ -797,8 +829,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
|||||||
if (d && d.ok) {
|
if (d && d.ok) {
|
||||||
const packed = typeof d.defaultContent === "string" ? d.defaultContent : "";
|
const packed = typeof d.defaultContent === "string" ? d.defaultContent : "";
|
||||||
if (packed) setDefaultOverride(packed);
|
if (packed) setDefaultOverride(packed);
|
||||||
const shown = String(d.content || packed || "").trim() ? (d.content || packed) : packed;
|
setOverride(typeof d.content === "string" ? d.content : packed);
|
||||||
setOverride(shown);
|
|
||||||
setOverrideLoaded(true);
|
setOverrideLoaded(true);
|
||||||
}
|
}
|
||||||
else setNotice({ kind: "error", text: tr("err.override", { error: (d && d.error) || "" }) });
|
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]);
|
useEffect(() => { loadAll(); }, [loadAll]);
|
||||||
|
|
||||||
const doAction = useCallback((action, actionKey) => {
|
const rejectNeedPrompt = useCallback((tr) => {
|
||||||
setPatchBusy(true);
|
|
||||||
setAskRestart(false);
|
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 tr = tRef.current;
|
||||||
const label = tr(actionKey);
|
const label = tr(actionKey);
|
||||||
fetch("/dsh-purge/" + action, { method: "POST", headers: { "content-type": "application/json" }, body: "{}" })
|
const ticket = ++actionTicket.current;
|
||||||
.then((r) => r.json())
|
const run = () => {
|
||||||
.then((d) => {
|
setPatchBusy(true);
|
||||||
if (d.ok) {
|
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 (action === "apply") {
|
||||||
if (typeof d.defaultContent === "string") setDefaultOverride(d.defaultContent);
|
if (typeof d.defaultContent === "string") setDefaultOverride(d.defaultContent);
|
||||||
const shown = d.override_content || d.defaultContent;
|
if (typeof d.override_content === "string") {
|
||||||
if (typeof shown === "string" && shown) {
|
setOverride(d.override_content);
|
||||||
setOverride(shown);
|
|
||||||
setOverrideLoaded(true);
|
setOverrideLoaded(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -858,32 +909,68 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
|||||||
setNotice({ kind: "ok", text: tr("ok.done") });
|
setNotice({ kind: "ok", text: tr("ok.done") });
|
||||||
loadAll();
|
loadAll();
|
||||||
if (action === "apply") setAskRestart(true);
|
if (action === "apply") setAskRestart(true);
|
||||||
} else {
|
})
|
||||||
setNotice({ kind: "error", text: tr("err.action", { action: label, error: d.error || "" }) });
|
.catch((e) => {
|
||||||
}
|
if (ticket !== actionTicket.current) return;
|
||||||
})
|
setNotice({ kind: "error", text: tr("err.action", { action: label, error: e.message }) });
|
||||||
.catch((e) => setNotice({ kind: "error", text: tr("err.action", { action: label, error: e.message }) }))
|
})
|
||||||
.finally(() => setPatchBusy(false));
|
.finally(() => {
|
||||||
}, [loadAll]);
|
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(() => {
|
const saveOverride = useCallback(() => {
|
||||||
setPatchBusy(true);
|
const tr = t;
|
||||||
setNotice({ kind: "idle", text: "" });
|
const ticket = ++actionTicket.current;
|
||||||
fetch("/dsh-purge/override", {
|
const go = () => {
|
||||||
method: "POST",
|
setPatchBusy(true);
|
||||||
headers: { "content-type": "application/json" },
|
setAskRestart(false);
|
||||||
body: JSON.stringify({ content: override }),
|
setNotice({ kind: "idle", text: "" });
|
||||||
})
|
fetch("/dsh-purge/override", {
|
||||||
.then((r) => r.json())
|
method: "POST",
|
||||||
.then((d) => {
|
headers: { "content-type": "application/json" },
|
||||||
if (d.ok && typeof d.content === "string") setOverride(d.content);
|
body: JSON.stringify({ content: override }),
|
||||||
setNotice(d.ok
|
|
||||||
? { kind: "ok", text: t("saved.override") }
|
|
||||||
: { kind: "error", text: t("err.save", { error: d.error || "" }) });
|
|
||||||
})
|
})
|
||||||
.catch((e) => setNotice({ kind: "error", text: t("err.save", { error: e.message }) }))
|
.then((r) => r.json())
|
||||||
.finally(() => setPatchBusy(false));
|
.then((d) => {
|
||||||
}, [override, t]);
|
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(() => {
|
const restoreOverride = useCallback(() => {
|
||||||
if (!defaultOverride) return;
|
if (!defaultOverride) return;
|
||||||
@@ -1056,6 +1143,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
|||||||
spellCheck: false,
|
spellCheck: false,
|
||||||
placeholder: "",
|
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) => {
|
.then((d) => {
|
||||||
if (d && d.ok) {
|
if (d && d.ok) {
|
||||||
setNotice({ kind: "ok", text: t("ok.done") });
|
setNotice({ kind: "ok", text: t("ok.done") });
|
||||||
|
if (action === "save" || action === "activate") warnNeedPrompt(d, t);
|
||||||
loadStatus();
|
loadStatus();
|
||||||
if (after) after();
|
if (after) after();
|
||||||
} else {
|
} else {
|
||||||
|
warnNeedPrompt(d, t);
|
||||||
setNotice({ kind: "error", text: t("err.action", { error: (d && d.error) || "" }) });
|
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);
|
setEditId(id);
|
||||||
setEditName(d.name || id);
|
setEditName(d.name || id);
|
||||||
setEditTarget(d.target || "AGENTS.md");
|
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 || "" }) });
|
} else setNotice({ kind: "error", text: t("err.read", { error: d.error || "" }) });
|
||||||
})
|
})
|
||||||
.catch((e) => setNotice({ kind: "error", text: t("err.read", { error: e.message }) }))
|
.catch((e) => setNotice({ kind: "error", text: t("err.read", { error: e.message }) }))
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@
|
|||||||
autoApplyOnStart: true
|
autoApplyOnStart: true
|
||||||
autoUpdateOnStart: true
|
autoUpdateOnStart: true
|
||||||
autoRevertOnMissing: false
|
autoRevertOnMissing: false
|
||||||
injectOnce: true
|
injectOnce: false
|
||||||
stripMnemon: true
|
stripMnemon: true
|
||||||
verbose: false
|
verbose: false
|
||||||
postPrompt: ""
|
postPrompt: ""
|
||||||
|
|||||||
+35
-15
@@ -2975,11 +2975,11 @@ const NEW_TOOL_PATCHES = [
|
|||||||
"\t\t\t...transformed,\n" +
|
"\t\t\t...transformed,\n" +
|
||||||
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, assembled) {\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 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 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\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 (!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\treturn [{ ...base, text: inject + \"\\n\\n\" + base.text }]; // [dsh-purge] complete prompt keeps inject\n" +
|
||||||
"\t\t\t})(completeSection, transformed),\n" +
|
"\t\t\t})(completeSection, transformed),\n" +
|
||||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\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");
|
return path.join(dshHome, "dsh-purge", "override-state.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function readOverrideState(dshHome) {
|
export function readOverrideStateSync(dshHome) {
|
||||||
const fp = overrideStatePath(dshHome);
|
const fp = overrideStatePath(dshHome);
|
||||||
try {
|
try {
|
||||||
const raw = JSON.parse(await fsp.readFile(fp, "utf8"));
|
const raw = JSON.parse(fs.readFileSync(fp, "utf8"));
|
||||||
return raw && typeof raw === "object" ? raw : {};
|
return raw && typeof raw === "object" ? raw : {};
|
||||||
} catch {
|
} catch {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function readOverrideState(dshHome) {
|
||||||
|
return readOverrideStateSync(dshHome);
|
||||||
|
}
|
||||||
|
|
||||||
export async function writeOverrideState(dshHome, state) {
|
export async function writeOverrideState(dshHome, state) {
|
||||||
const fp = overrideStatePath(dshHome);
|
const fp = overrideStatePath(dshHome);
|
||||||
await fsp.mkdir(path.dirname(fp), { recursive: true });
|
await fsp.mkdir(path.dirname(fp), { recursive: true });
|
||||||
@@ -4275,6 +4279,9 @@ export async function markOverrideCustomized(dshHome, customized, text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function isUserCustomizedOverride(dshHome) {
|
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);
|
const fp = findOverrideFile(dshHome);
|
||||||
let disk = "";
|
let disk = "";
|
||||||
if (fs.existsSync(fp)) {
|
if (fs.existsSync(fp)) {
|
||||||
@@ -4286,9 +4293,6 @@ export async function isUserCustomizedOverride(dshHome) {
|
|||||||
}
|
}
|
||||||
if (!normalizeOverride(disk)) return false;
|
if (!normalizeOverride(disk)) return false;
|
||||||
if (hashOverride(disk) === defaultOverrideHash()) 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4319,11 +4323,11 @@ export async function readOverrideForUi(dshHome) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const customized = await isUserCustomizedOverride(dshHome);
|
const customized = await isUserCustomizedOverride(dshHome);
|
||||||
const show = customized && normalizeOverride(disk) ? disk : defaultContent;
|
const show = customized ? disk : defaultContent;
|
||||||
return {
|
return {
|
||||||
path: fp,
|
path: fp,
|
||||||
exists,
|
exists,
|
||||||
empty: !normalizeOverride(disk),
|
empty: !normalizeOverride(show),
|
||||||
customized,
|
customized,
|
||||||
usingDefault: !customized,
|
usingDefault: !customized,
|
||||||
content: show,
|
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) {
|
export async function installOverride(dshHome, force = false) {
|
||||||
const fp = findOverrideFile(dshHome);
|
const fp = findOverrideFile(dshHome);
|
||||||
await fsp.mkdir(dshHome, { recursive: true });
|
await fsp.mkdir(dshHome, { recursive: true });
|
||||||
@@ -4345,14 +4367,12 @@ export async function installOverride(dshHome, force = false) {
|
|||||||
export async function saveOverrideContent(dshHome, content) {
|
export async function saveOverrideContent(dshHome, content) {
|
||||||
const bundled = defaultOverrideText();
|
const bundled = defaultOverrideText();
|
||||||
const incoming = typeof content === "string" ? content : "";
|
const incoming = typeof content === "string" ? content : "";
|
||||||
const customized = Boolean(normalizeOverride(incoming))
|
const customized = normalizeOverride(incoming) !== normalizeOverride(bundled);
|
||||||
&& normalizeOverride(incoming) !== normalizeOverride(bundled);
|
|
||||||
const toWrite = customized ? incoming : bundled;
|
|
||||||
const fp = findOverrideFile(dshHome);
|
const fp = findOverrideFile(dshHome);
|
||||||
await fsp.mkdir(dshHome, { recursive: true });
|
await fsp.mkdir(dshHome, { recursive: true });
|
||||||
await fsp.writeFile(fp, toWrite, "utf8");
|
await fsp.writeFile(fp, incoming, "utf8");
|
||||||
await markOverrideCustomized(dshHome, customized, toWrite);
|
await markOverrideCustomized(dshHome, customized, incoming);
|
||||||
return { path: fp, customized, content: toWrite };
|
return { path: fp, customized, content: incoming, defaultContent: bundled };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ensureOverrideContent(dshHome, force = false) {
|
export async function ensureOverrideContent(dshHome, force = false) {
|
||||||
|
|||||||
+29
-20
@@ -90,10 +90,20 @@ function stripHarnessPersona(text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function collectInjectText(purgeSections, fallbackText) {
|
function collectInjectText(purgeSections, fallbackText) {
|
||||||
|
const fallback = typeof fallbackText === "string" ? fallbackText : "";
|
||||||
|
if (fallback) return fallback;
|
||||||
const main = purgeSections.find((section) => section.name === "dsh-purge");
|
const main = purgeSections.find((section) => section.name === "dsh-purge");
|
||||||
const fromMain = String(main?.text || "").trim();
|
return String(main?.text || "");
|
||||||
if (fromMain) return fromMain;
|
}
|
||||||
return typeof fallbackText === "string" ? fallbackText.trim() : "";
|
|
||||||
|
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) {
|
function stripIdentityPrefix(text) {
|
||||||
@@ -135,13 +145,13 @@ function messageText(message) {
|
|||||||
|
|
||||||
export function existingSystemPrompt(context) {
|
export function existingSystemPrompt(context) {
|
||||||
const events = eventList(context?.agent?.session || context?.session);
|
const events = eventList(context?.agent?.session || context?.session);
|
||||||
let latest = "";
|
const texts = [];
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
if (event?.type !== "system/message") continue;
|
if (event?.type !== "system/message") continue;
|
||||||
const text = messageText(event.data?.message || event.data).trim();
|
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) {
|
export function isFirstConversationTurn(context) {
|
||||||
@@ -162,13 +172,13 @@ export function isFirstConversationTurn(context) {
|
|||||||
export function promptAlreadyInjected(existing, injectText) {
|
export function promptAlreadyInjected(existing, injectText) {
|
||||||
const inject = String(injectText || "").trim();
|
const inject = String(injectText || "").trim();
|
||||||
if (!inject) return false;
|
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 = "") {
|
export function shouldInjectPrompt(_context, _injectOnce = true, _injectText = "") {
|
||||||
if (injectOnce === false) return true;
|
// 0.1.5 in-history:渲染少了注入就会再追加一条 system/message。
|
||||||
if (isFirstConversationTurn(context)) return true;
|
// 用「最后一条是否含注入」决定本步掏空注入,会 A/B 死循环。每步都必须留下完整注入。
|
||||||
return !promptAlreadyInjected(existingSystemPrompt(context), injectText);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isMnemonPluginMessage(message) {
|
export function isMnemonPluginMessage(message) {
|
||||||
@@ -199,7 +209,7 @@ function normalizeRewriteOptions(fallbackInject, options) {
|
|||||||
|
|
||||||
// 0.1.5 优先写入 persona-prefix;无 prefix 时写入 legacy persona。
|
// 0.1.5 优先写入 persona-prefix;无 prefix 时写入 legacy persona。
|
||||||
function foldInjectIntoPersona(sections, injectText) {
|
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 names = sections.map((s) => String(s?.name || ""));
|
||||||
const hasPrefix = names.some((n) => PERSONA_PREFIX_NAMES.has(n));
|
const hasPrefix = names.some((n) => PERSONA_PREFIX_NAMES.has(n));
|
||||||
let folded = false;
|
let folded = false;
|
||||||
@@ -207,16 +217,16 @@ function foldInjectIntoPersona(sections, injectText) {
|
|||||||
const name = String(section?.name || "");
|
const name = String(section?.name || "");
|
||||||
if (!isPersonaFoldTarget(name, hasPrefix)) return section;
|
if (!isPersonaFoldTarget(name, hasPrefix)) return section;
|
||||||
folded = true;
|
folded = true;
|
||||||
const prior = stripIdentityPrefix(String(section.text || "").trim());
|
const prior = stripIdentityPrefix(String(section.text || ""));
|
||||||
if (!inject) return { ...section, text: prior };
|
if (!inject) return { ...section, text: prior };
|
||||||
if (prior.includes(inject.slice(0, Math.min(80, inject.length)))) {
|
if (prior.includes(inject)) return { ...section, text: prior };
|
||||||
return { ...section, text: prior };
|
|
||||||
}
|
|
||||||
return { ...section, text: prior ? `${inject}\n\n${prior}` : inject };
|
return { ...section, text: prior ? `${inject}\n\n${prior}` : inject };
|
||||||
});
|
});
|
||||||
if (folded) return out;
|
if (folded) return out;
|
||||||
if (!inject) 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 = {}) {
|
export function rewritePromptAssembly(assembled, fallbackInject = "", options = {}) {
|
||||||
@@ -233,18 +243,17 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
|||||||
next.text = stripHarnessPersona(next.text);
|
next.text = stripHarnessPersona(next.text);
|
||||||
}
|
}
|
||||||
if (String(next.name).startsWith("dsh-purge")) {
|
if (String(next.name).startsWith("dsh-purge")) {
|
||||||
if (!opts.fallbackInject) continue;
|
|
||||||
purge.push(next);
|
purge.push(next);
|
||||||
} else {
|
} else {
|
||||||
rest.push(next);
|
rest.push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const injectText = opts.fallbackInject ? collectInjectText(purge, opts.fallbackInject) : "";
|
const injectText = collectInjectText(purge, opts.fallbackInject);
|
||||||
const folded = foldInjectIntoPersona(rest, injectText);
|
const folded = foldInjectIntoPersona(rest, injectText);
|
||||||
const extras = opts.dropPurgeAfterFold
|
const extras = opts.dropPurgeAfterFold
|
||||||
? purge.filter((section) => section.name !== "dsh-purge")
|
? purge.filter((section) => section.name !== "dsh-purge")
|
||||||
: purge;
|
: purge;
|
||||||
assembled.sections = [...folded, ...extras];
|
assembled.sections = ensureFullInject([...folded, ...extras], injectText);
|
||||||
return assembled;
|
return assembled;
|
||||||
}
|
}
|
||||||
+76
-67
@@ -1,6 +1,5 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { promises as fsp } from "node:fs";
|
import { promises as fsp } from "node:fs";
|
||||||
import { AsyncLocalStorage } from "node:async_hooks";
|
|
||||||
import * as core from "./core.js";
|
import * as core from "./core.js";
|
||||||
import * as hostctl from "./host.js";
|
import * as hostctl from "./host.js";
|
||||||
import * as rules from "./rules.js";
|
import * as rules from "./rules.js";
|
||||||
@@ -9,7 +8,6 @@ import {
|
|||||||
GLOBAL_PROMPT_ORDER,
|
GLOBAL_PROMPT_ORDER,
|
||||||
isMnemonPluginMessage,
|
isMnemonPluginMessage,
|
||||||
rewritePromptAssembly,
|
rewritePromptAssembly,
|
||||||
shouldInjectPrompt,
|
|
||||||
} from "./identity.js";
|
} from "./identity.js";
|
||||||
import * as rewind from "./rewind.js";
|
import * as rewind from "./rewind.js";
|
||||||
import * as continueRetry from "./continue-retry.js";
|
import * as continueRetry from "./continue-retry.js";
|
||||||
@@ -24,7 +22,7 @@ const DEFAULTS = {
|
|||||||
autoApplyOnStart: true,
|
autoApplyOnStart: true,
|
||||||
autoUpdateOnStart: true,
|
autoUpdateOnStart: true,
|
||||||
autoRevertOnMissing: false,
|
autoRevertOnMissing: false,
|
||||||
injectOnce: true,
|
injectOnce: false,
|
||||||
stripMnemon: true,
|
stripMnemon: true,
|
||||||
postPrompt: "",
|
postPrompt: "",
|
||||||
postPromptOrder: 5100,
|
postPromptOrder: 5100,
|
||||||
@@ -138,43 +136,39 @@ function renderStatus(state) {
|
|||||||
return out.join("\n");
|
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) {
|
function injectAllowedNow(config) {
|
||||||
if (config.enabled === false) return false;
|
return config.enabled !== false;
|
||||||
const state = assembleState.getStore();
|
|
||||||
return !state || state.allow !== 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({
|
ctx.systemPrompt.section({
|
||||||
name: "dsh-purge",
|
name: "dsh-purge",
|
||||||
order: GLOBAL_PROMPT_ORDER,
|
order: GLOBAL_PROMPT_ORDER,
|
||||||
text: () => {
|
text: () => {
|
||||||
if (!injectAllowedNow(config)) return "";
|
if (!injectAllowedNow(config)) return "";
|
||||||
return readInjectFile(injectFile);
|
return rules.resolveInjectText(core.findDshHome()).text;
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -190,26 +184,8 @@ export function registerPromptSections(ctx, config, injectFile) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const INJECT_FALLBACK_MAX_BYTES = 512 * 1024;
|
|
||||||
|
|
||||||
function readInjectFallback() {
|
function readInjectFallback() {
|
||||||
try {
|
return rules.resolveInjectText(core.findDshHome()).text;
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function installMnemonMessageStrip(ctx, config = {}) {
|
function installMnemonMessageStrip(ctx, config = {}) {
|
||||||
@@ -238,16 +214,14 @@ function installIdentityOverride(ctx, config = {}) {
|
|||||||
if (typeof ctx.on !== "function") return;
|
if (typeof ctx.on !== "function") return;
|
||||||
if (ctx.__dshPurgeAssembleHook) return;
|
if (ctx.__dshPurgeAssembleHook) return;
|
||||||
ctx.__dshPurgeAssembleHook = true;
|
ctx.__dshPurgeAssembleHook = true;
|
||||||
const hook = async (_assembly, context, next) => {
|
const hook = async (_assembly, _context, next) => {
|
||||||
const inject = config.enabled === false ? "" : readInjectFallback();
|
const assembled = typeof next === "function" ? await next() : _assembly;
|
||||||
const allow = config.enabled !== false && shouldInjectPrompt(context, config.injectOnce !== false, inject);
|
const enabled = config.enabled !== false;
|
||||||
return assembleState.run({ allow }, async () => {
|
const inject = enabled ? readInjectFallback() : "";
|
||||||
const assembled = typeof next === "function" ? await next() : _assembly;
|
return rewritePromptAssembly(assembled, {
|
||||||
return rewritePromptAssembly(assembled, {
|
fallbackInject: inject,
|
||||||
fallbackInject: allow ? inject : "",
|
dropMnemon: config.stripMnemon !== false,
|
||||||
dropMnemon: config.stripMnemon !== false,
|
dropPurgeAfterFold: true,
|
||||||
dropPurgeAfterFold: true,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 只挂一次:挂多次会让同一轮 assemble 折两遍,UI 也会显示两次注入。
|
// 只挂一次:挂多次会让同一轮 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);
|
installIdentityOverride(ctx, cfg);
|
||||||
installMnemonMessageStrip(ctx, cfg);
|
installMnemonMessageStrip(ctx, cfg);
|
||||||
const injectFile = core.findOverrideFile(core.findDshHome());
|
const injectFile = core.findOverrideFile(core.findDshHome());
|
||||||
@@ -948,9 +927,24 @@ function installWebServer(ctx, cfg) {
|
|||||||
sendJson(response, 500, { ok: false, error: core.missingAiBaseMessage() });
|
sendJson(response, 500, { ok: false, error: core.missingAiBaseMessage() });
|
||||||
return;
|
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);
|
await core.backupAll(state.ai_base);
|
||||||
const report = await core.applyPatches(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 shim = await core.patchAllShims();
|
||||||
const flash = core.silenceCmdFlash(state.ai_base);
|
const flash = core.silenceCmdFlash(state.ai_base);
|
||||||
const summary = core.summarizeApplyReport(report);
|
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 })),
|
report: report.map((r) => ({ id: r.patch_id, name: r.name, status: r.status })),
|
||||||
override_content: override.content,
|
override_content: override.content,
|
||||||
|
defaultContent: override.defaultContent,
|
||||||
|
...injectSnapshot(state.dsh_home),
|
||||||
override_path: override.path,
|
override_path: override.path,
|
||||||
override_installed: override.installed,
|
override_installed: override.installed,
|
||||||
shim,
|
shim,
|
||||||
@@ -1038,8 +1034,9 @@ function installWebServer(ctx, cfg) {
|
|||||||
handler: async (request, response) => {
|
handler: async (request, response) => {
|
||||||
if (request.method === "GET") {
|
if (request.method === "GET") {
|
||||||
try {
|
try {
|
||||||
const ui = await core.ensureOverrideContent(core.findDshHome(), false);
|
const home = core.findDshHome();
|
||||||
sendJson(response, 200, { ok: true, ...ui });
|
const ui = await core.readOverrideForUi(home);
|
||||||
|
sendJson(response, 200, { ok: true, ...ui, ...injectSnapshot(home) });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sendJson(response, 500, { ok: false, error: String(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" });
|
sendJson(response, 400, { ok: false, error: "content must be a string" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const saved = await core.saveOverrideContent(core.findDshHome(), content);
|
const home = core.findDshHome();
|
||||||
sendJson(response, 200, { ok: true, ...saved });
|
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) {
|
} catch (e) {
|
||||||
sendJson(response, 500, { ok: false, error: String(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,
|
name: typeof body?.name === "string" ? body.name : undefined,
|
||||||
target: typeof body?.target === "string" ? body.target : undefined,
|
target: typeof body?.target === "string" ? body.target : undefined,
|
||||||
});
|
});
|
||||||
return { ok: true, id };
|
return { ok: true, id, ...injectSnapshot(dshHome) };
|
||||||
}
|
}
|
||||||
if (op === "activate") {
|
if (op === "activate") {
|
||||||
if (!rules.validRuleId(id)) return { status: 400, ok: false, error: "invalid id" };
|
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,
|
target: meta.target,
|
||||||
agents_path: rules.targetPath(dshHome, meta.target),
|
agents_path: rules.targetPath(dshHome, meta.target),
|
||||||
note: "已写入目标文件并注入 systemPrompt,新会话生效",
|
note: "已写入目标文件并注入 systemPrompt,新会话生效",
|
||||||
|
...injectSnapshot(dshHome),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (op === "delete") {
|
if (op === "delete") {
|
||||||
|
|||||||
+37
-19
@@ -1,7 +1,7 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import { promises as fsp } from "node:fs";
|
import { promises as fsp } from "node:fs";
|
||||||
import path from "node:path";
|
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 RULE_ID_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
|
||||||
const MAX_RULE_BYTES = 256 * 1024;
|
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");
|
await fsp.writeFile(stateFile(dshHome), JSON.stringify({ active: id }, null, 2), "utf8");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function activeRuleText(dshHome) {
|
export function activeRuleId(dshHome) {
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(fs.readFileSync(stateFile(dshHome), "utf8"));
|
const parsed = JSON.parse(fs.readFileSync(stateFile(dshHome), "utf8"));
|
||||||
const id = parsed?.active;
|
const id = parsed?.active;
|
||||||
if (!validRuleId(id)) return "";
|
return validRuleId(id) ? id : null;
|
||||||
return fs.readFileSync(rulePath(dshHome, id), "utf8").trim();
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function activeRuleText(dshHome) {
|
||||||
|
const id = activeRuleId(dshHome);
|
||||||
|
if (!id) return "";
|
||||||
|
try {
|
||||||
|
return fs.readFileSync(rulePath(dshHome, id), "utf8");
|
||||||
} catch {
|
} catch {
|
||||||
return "";
|
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) {
|
export async function activateRule(dshHome, id) {
|
||||||
const content = await readRule(dshHome, id);
|
const content = await readRule(dshHome, id);
|
||||||
if (content === null) throw new Error(`rule not found: ${id}`);
|
if (content === null) throw new Error(`rule not found: ${id}`);
|
||||||
@@ -181,21 +210,7 @@ export async function ensureInitialState(dshHome) {
|
|||||||
}
|
}
|
||||||
active = null;
|
active = null;
|
||||||
}
|
}
|
||||||
if (active !== null) return { active };
|
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 };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resetToOriginal(dshHome) {
|
export async function resetToOriginal(dshHome) {
|
||||||
@@ -243,9 +258,12 @@ export async function rulesStatus(dshHome) {
|
|||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const inject = resolveInjectText(dshHome);
|
||||||
return {
|
return {
|
||||||
rules: listed,
|
rules: listed,
|
||||||
active,
|
active,
|
||||||
|
injectSource: inject.source,
|
||||||
|
injectRuleId: inject.ruleId,
|
||||||
active_target,
|
active_target,
|
||||||
agents_exists,
|
agents_exists,
|
||||||
agents_synced,
|
agents_synced,
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dsh-purge",
|
"name": "dsh-purge",
|
||||||
"version": "1.1.9",
|
"version": "1.1.10",
|
||||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
|
|||||||
Reference in new issue
Block a user