mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 21:00:22 +08:00
Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
318b3e3db3 | ||
|
|
6a3f89da8d | ||
|
|
278eabbc07 | ||
|
|
4f1470d6e5 | ||
|
|
b3a23dba75 | ||
|
|
d3b3bc3551 | ||
|
|
014a225822 | ||
|
|
0fb12fc25e | ||
|
|
1a47bcd969 | ||
|
|
c743a64d13 | ||
|
|
fd631154f2 |
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.12-beta.1</strong></p>
|
||||
<p align="center"><strong>Version 1.1.14</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>
|
||||
@@ -246,13 +246,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.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>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz"><strong>🚀 Install in desktop client</strong></a>
|
||||
</p>
|
||||
|
||||
🔗 **Raw protocol URL:**
|
||||
|
||||
```
|
||||
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
|
||||
dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz
|
||||
```
|
||||
|
||||
**Web trigger example:**
|
||||
@@ -265,7 +265,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.10',
|
||||
version: '1.1.14',
|
||||
repo: 'YuJunZhiXue/dsh-purge',
|
||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||
@@ -284,7 +284,7 @@ export function installDshPurgeToDesktop() {
|
||||
**HTML link:**
|
||||
|
||||
```html
|
||||
<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 href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz">
|
||||
🚀 Install in desktop client
|
||||
</a>
|
||||
```
|
||||
@@ -295,7 +295,7 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | Plugin id |
|
||||
| name | `dsh-purge` | Display name |
|
||||
| version | `1.1.10` | Semver |
|
||||
| version | `1.1.14` | Semver |
|
||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub repo |
|
||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub source archive |
|
||||
@@ -753,18 +753,34 @@ If nothing is found, set `DSH_BASE` / `DSH_DESKTOP_INSTALL`. No files are change
|
||||
|
||||
## Changelog
|
||||
|
||||
### 1.1.12-beta.1
|
||||
### 1.1.14
|
||||
|
||||
- Skill import stays on beta: Settings and `/skills` write zip/folder into official `$DSH_HOME/skills`
|
||||
- Stable / Beta columns match official 1.1.11, so you can switch both ways
|
||||
- Same system-prompt fix as official 1.1.11: inject once per conversation, do not append another「系统提示词」on later steps
|
||||
- Rewind waits for `updateQueue` to finish. A queue item that is already gone no longer becomes an unhandled rejection that can take down the host.
|
||||
- The fallback rewind button records this rewind’s timestamp. The 1.2s poll does not open and refill the same rewind a second time.
|
||||
- When the text being restored belongs to a turn that is still open, the fork point is the last closed turn. The previous completed turn is no longer dropped. If that turn is still running and does not close within 8 seconds, rewind still fails instead of cutting an incomplete log.
|
||||
- The bash timeout patch is now one whole-line regular expression, and values that grew extra zeros are pulled back to 10 minutes. Startup no longer appends another zero (#22, #31).
|
||||
- Patch replacement accepts regular expressions, and `$1` expands. A finished bundle-layout clean matches `persona: ""`, so the panel does not stay on pending. #39 is optional. The skipped hint now says the patch is not needed for this version, or the component is not installed.
|
||||
- Beta versions already covered by the current stable release are hidden from the version list. When the commit does not match, 「当前」follows the local version number.
|
||||
- Phase-1 no longer clears runtime context or the message allowlist. 梁神 and official plugin messages stay as they are.
|
||||
|
||||
### 1.1.13
|
||||
|
||||
- In-plugin updates rewrite `github:` and `git+https` to the GitHub `master.tar.gz` archive, so a reinstall does not need a local git (#30).
|
||||
- A first install from the plugin hub still uses `git+https`. Without git, use the `master.tar.gz` URL above.
|
||||
|
||||
### 1.1.12
|
||||
|
||||
- **Beta is now the stable release.** Settings and `/skills` import a zip or folder into official `$DSH_HOME/skills`. DSH still owns match and load.
|
||||
- Includes the 1.1.11 system-prompt fix: do not pin the previous full prompt (#29). The version list marks「当前」by commit. Local routes reject cross-origin requests. Patch #41 no longer keeps `dsh-purge:committed`.
|
||||
|
||||
### 1.1.11
|
||||
|
||||
- Settings splits Stable / Beta into two columns, each with its own list, switch, and rollback. 1.1.10 can reach this by Check update.
|
||||
- **No Skill import.** Skill stays on beta 1.1.12.
|
||||
- **Inject the system prompt once per conversation.** The first turn writes the full `prompt-inject`; later steps pin that committed prompt and do not fold it again.
|
||||
- **Stop a new「系统提示词」card on every step.** With 0.1.5 in-history, a changed assemble appends another `system/message`, so the transcript repeats system prompt → think → tools. Refolding inject every step made later official sections look like a new prompt; emptying inject did the same. After the inject is already in history, this release pins that committed system prompt and does not append a second copy.
|
||||
- **No Skill import in this release.** Skill joins stable in 1.1.12.
|
||||
- **#29:** Stop pinning the previous full system prompt. That pin was meant to stop a new「系统提示词」card each step, but presets that append a section every assemble (梁神 `workspace-instructions`) turned it into “last full prompt + this step’s block”, so the prompt grew every step and prefix cache missed. Later turns only fold `prompt-inject` into persona, and do not fold a second copy when it is already there.
|
||||
- The version list marks「当前」by commit. An older tag with the same 1.1.11 version is no longer current next to `master`.
|
||||
- Local routes reject cross-origin requests, and updates only accept a known ref. Another webpage cannot apply, revert, uninstall, or switch.
|
||||
- Patch #41 no longer keeps the `dsh-purge:committed` shortcut. Hosts that already applied the old patch need one more Apply to remove it.
|
||||
|
||||
### 1.1.10
|
||||
|
||||
|
||||
+30
-13
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.12-beta.1</strong></p>
|
||||
<p align="center"><strong>Version 1.1.14</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件:在受控本机环境评测并加固宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||
@@ -243,13 +243,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.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>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz"><strong>🚀 唤起客户端一键安装</strong></a>
|
||||
</p>
|
||||
|
||||
🔗 **原生协议链接:**
|
||||
|
||||
```
|
||||
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
|
||||
dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz
|
||||
```
|
||||
|
||||
**网页端(前端)触发代码示例:**
|
||||
@@ -262,7 +262,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.10',
|
||||
version: '1.1.14',
|
||||
repo: 'YuJunZhiXue/dsh-purge',
|
||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||
@@ -281,7 +281,7 @@ export function installDshPurgeToDesktop() {
|
||||
**HTML 静态链接方式:**
|
||||
|
||||
```html
|
||||
<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 href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.14&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz">
|
||||
🚀 唤起客户端一键安装
|
||||
</a>
|
||||
```
|
||||
@@ -292,7 +292,7 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | 插件唯一标识符 |
|
||||
| name | `dsh-purge` | 插件展示名称 |
|
||||
| version | `1.1.10` | 语义化版本号 |
|
||||
| version | `1.1.14` | 语义化版本号 |
|
||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
|
||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
|
||||
@@ -740,17 +740,34 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
|
||||
|
||||
## 更新记录
|
||||
|
||||
### 1.1.12-beta.1
|
||||
### 1.1.14
|
||||
|
||||
- Skill 导入继续只在测试版:设置页和 `/skills` 可导入压缩包或文件夹到官方 `$DSH_HOME/skills`
|
||||
- 正式/测试分栏与 1.1.11 正式版同一套,可来回切换
|
||||
- 系统提示词修复与正式版 1.1.11 相同:每个会话只注入一次,后续步骤不再追加「系统提示词」
|
||||
- 回退清队列时会等 `updateQueue` 结束。条目已经不在时不再变成未处理的拒绝,避免把宿主带崩。
|
||||
- 兜底回退按钮成功后会记下这次的时间。1.2 秒后的轮询不会把同一次回退再打开、再回填一遍。
|
||||
- 回填的是还没结束的那一句时,切点改到最后一个已闭合回合。不再多丢上一整轮。回合还在进行、8 秒内等不到结束时,仍然直接失败,不会按不完整日志去切。
|
||||
- bash 超时补丁改成整行正则,并把已经多写出来的 0 收回到 10 分钟。每次启动不再给超时再补一个 0(#22,#31)。
|
||||
- 补丁替换支持正则,`$1` 会展开。bundle 布局清洗完成后能认出 `persona: ""`,面板不再一直显示待应用。#39 改为可选。跳过说明改为「当前版本不需要或组件未安装」。
|
||||
- 正式版已经追上的测试版不再出现在版本列表里。提交号对不上时,按本机版本号标「当前」。
|
||||
- phase-1 不再清空 runtime context,也不改消息白名单。梁神和官方插件的消息照旧保留。
|
||||
|
||||
### 1.1.13
|
||||
|
||||
- 插件自己更新时,`github:` 和 `git+https` 改走 GitHub `master.tar.gz`,没装 git 也能重装(#30)。
|
||||
- 第一次从插件市场安装仍会走 `git+https`。没装 git 时,直接用上面的 `master.tar.gz` 地址。
|
||||
|
||||
### 1.1.12
|
||||
|
||||
- **测试版转为正式版。** 设置页和 `/skills` 可把压缩包或文件夹导入官方 `$DSH_HOME/skills`。命中和加载仍由 DSH 负责。
|
||||
- 带上 1.1.11 的系统提示修复:不再钉上一轮全文(#29)。版本列表按提交号标「当前」。本机接口拒绝跨站请求。补丁 #41 不再保留 `dsh-purge:committed`。
|
||||
|
||||
### 1.1.11
|
||||
|
||||
- 设置页把正式版和测试版左右分开,各自选版本、各自切换和回退。
|
||||
- **系统提示词每个会话只注入一次。** 第一轮把 `prompt-inject` 完整写进系统提示;之后钉住已经提交的那一份,不再每步重折。
|
||||
- **修了聊天里每步都冒出「系统提示词」。** 0.1.5 in-history 只要本步组装结果和上一条不一样,就会再追加一条 `system/message`,时间线就会「思考 → 工具 → 系统提示词」循环。以前每步都把注入重新折进 persona,官方后半段稍有变化就会追加;把注入掏空也不行,渲染少了同样会被当成变化再追加。这一版历史里已经有完整注入后,就钉住那条已提交的系统提示,后续步骤不再追加第二份。
|
||||
- 设置页把正式版和测试版左右分开,各自选版本、各自切换和回退。还在 1.1.10 的点「检测更新」就能升到这一版。
|
||||
- **当时没有 Skill 导入。** Skill 从 1.1.12 起进入正式版。
|
||||
- **#29:** 去掉「钉住上一条系统提示全文」。起初为了避免每步追加「系统提示词」,把上一轮全文钉回去;和每轮追加 section 的预设(梁神的 `workspace-instructions`)叠在一起后,系统提示每步变长,前缀缓存整段失效。现在每轮只把 `prompt-inject` 折进 persona,已经折过就不再折第二份。
|
||||
- 版本列表按提交号标「当前」。同为 1.1.11 的旧标签不再和 `master` 一起显示当前。
|
||||
- 本机接口拒绝跨站请求,更新只接受已知版本。任意网页不能再调用应用、还原、卸载或切换。
|
||||
- 补丁 #41 去掉 `dsh-purge:committed` 短路。已经打过旧补丁的,再点一次「应用」才会从宿主文件里删掉。
|
||||
|
||||
### 1.1.10
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"status.applied": "已应用",
|
||||
"status.pending": "待应用",
|
||||
"status.skipped": "跳过",
|
||||
"apply.hint": "待应用=原文还在。跳过=没装或官方已改写,再点也不会变。",
|
||||
"apply.hint": "待应用=原文还在。跳过=当前版本不需要或组件未安装,再点也不会变。",
|
||||
"warn.noRoot": "未定位到当前宿主的 @deepseek-ai,清洗不会生效。请完全退出后再打开本宿主,在本页点「应用」。桌面端安装目录可以是任意盘符,不要用官方 dsh 去清桌面端。",
|
||||
"warn.noRoot.desktop": "未定位到当前桌面应用里的 @deepseek-ai。请退出托盘后重新打开 DSH Desktop.exe,再在桌面端设置页点「应用」。安装目录不限盘符。",
|
||||
"warn.noInject": "提示词优先;为空则注入当前启用的规则集。两边都空会提示必须添加。Skill 不顶替提示词。",
|
||||
@@ -363,7 +363,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"status.applied": "Applied",
|
||||
"status.pending": "Pending",
|
||||
"status.skipped": "Skipped",
|
||||
"apply.hint": "Pending = original text still present. Skipped = missing or already rewritten.",
|
||||
"apply.hint": "Pending = original text still present. Skipped = not needed for this version or component not installed.",
|
||||
"warn.noRoot": "Could not find this host’s @deepseek-ai tree, so Apply will not patch anything. Fully quit and reopen this host, then Apply here. Desktop may live on any drive; 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": "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. Skills do not replace the prompt.",
|
||||
@@ -879,12 +879,12 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
|
||||
const syncPicks = (d) => {
|
||||
const versions = (d && d.versions) || [];
|
||||
const ceiling = listedCeiling(versions, d && d.localVersion);
|
||||
const next = { stable: "", beta: "" };
|
||||
for (const id of ["stable", "beta"]) {
|
||||
const list = versions.filter((item) => item.channel === id && keepListedVersion(item));
|
||||
const cur = list.find((item) => item.current);
|
||||
const latest = list.find((item) => item.latest);
|
||||
next[id] = (cur || latest || {}).ref || "";
|
||||
const list = versions.filter((item) => item.channel === id && keepListedVersion(item, ceiling));
|
||||
const hit = preferListed(list, d && d.localVersion);
|
||||
next[id] = (hit && hit.ref) || "";
|
||||
}
|
||||
setPick(next);
|
||||
};
|
||||
@@ -1251,11 +1251,12 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const localVer = (s && s.plugin_version) || (updateInfo && updateInfo.localVersion) || "";
|
||||
const renderEdition = (id) => {
|
||||
const lane = (updateInfo && updateInfo.lanes && updateInfo.lanes[id]) || {};
|
||||
const list = versions.filter((item) => item.channel === id && keepListedVersion(item));
|
||||
const ceiling = listedCeiling(versions, localVer || (updateInfo && updateInfo.localVersion));
|
||||
const list = versions.filter((item) => item.channel === id && keepListedVersion(item, ceiling));
|
||||
const selectedRef = pick[id] || "";
|
||||
const hit = list.find((item) => item.ref === selectedRef) || list.find((item) => item.current) || list.find((item) => item.latest);
|
||||
const hit = list.find((item) => item.ref === selectedRef) || preferListed(list, localVer);
|
||||
const onLane = channelNow === id;
|
||||
const noBeta = id === "beta" && updateInfo && updateInfo.hasBeta === false && !list.length;
|
||||
const noBeta = id === "beta" && Array.isArray(updateInfo && updateInfo.versions) && !list.length;
|
||||
const pickedOther = Boolean(hit && selectedRef && !hit.current);
|
||||
const thisJob = updateJob && updateJob.id === id ? updateJob : null;
|
||||
let actionLabel = t("btn.checkUpdate");
|
||||
@@ -1293,7 +1294,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
),
|
||||
h("select", {
|
||||
className: "dshp-field dshp-ver",
|
||||
value: selectedRef || (hit && hit.ref) || "",
|
||||
value: list.length ? ((hit && hit.ref) || "") : "",
|
||||
disabled: updateBusy || !list.length,
|
||||
onChange: (e) => setPick((prev) => Object.assign({}, prev, { [id]: e.target.value })),
|
||||
"aria-label": t("update.pick"),
|
||||
@@ -1302,7 +1303,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
? list.map((item) => h("option", {
|
||||
key: item.ref + (item.sha || ""),
|
||||
value: item.ref,
|
||||
}, (item.version ? "v" + item.version : item.label) + (item.latest && !item.current ? " · " + t("update.tip") : "")))
|
||||
}, versionChoiceLabel(item, t)))
|
||||
: h("option", { value: "" }, noBeta ? t("update.noBeta") : t("update.pick")),
|
||||
),
|
||||
h(Btn, { tiny: true, kind: actionKind, disabled: actionDisabled, onClick: actionClick }, actionLabel),
|
||||
@@ -1620,7 +1621,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
}
|
||||
|
||||
function skillUiAllowed(d) {
|
||||
if (!d || d.channel === "stable") return false;
|
||||
if (!d) return false;
|
||||
const ver = String(d.plugin_version || d.localVersion || "").replace(/^v/i, "");
|
||||
if (/^1\.1\.11(?:-|$)/.test(ver)) return false;
|
||||
const parts = ver.match(/^(\d+)\.(\d+)\.(\d+)/);
|
||||
@@ -1630,8 +1631,63 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
return +parts[3] >= 12;
|
||||
}
|
||||
|
||||
function keepListedVersion(item) {
|
||||
return !/^1\.1\.11-beta/i.test(String((item && item.version) || "").replace(/^v/i, ""));
|
||||
function splitListedVersion(raw) {
|
||||
const text = String(raw || "").trim().replace(/^v/i, "");
|
||||
const cut = text.split("-");
|
||||
const core = String(cut[0] || "").split(".").map((n) => parseInt(n, 10) || 0);
|
||||
return { core: [core[0] || 0, core[1] || 0, core[2] || 0], pre: cut.slice(1).join("-") };
|
||||
}
|
||||
|
||||
function listedVersionNewer(remote, local) {
|
||||
if (!remote || !local || String(remote) === String(local)) return false;
|
||||
const a = splitListedVersion(remote);
|
||||
const b = splitListedVersion(local);
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
if (a.core[i] !== b.core[i]) return a.core[i] > b.core[i];
|
||||
}
|
||||
if (a.pre && !b.pre) return false;
|
||||
if (!a.pre && b.pre) return true;
|
||||
return a.pre > b.pre;
|
||||
}
|
||||
|
||||
function listedCeiling(versions, localVer) {
|
||||
let best = "";
|
||||
const rows = (versions || []).slice();
|
||||
const local = String(localVer || "").replace(/^v/i, "");
|
||||
if (local && !/(?:^|[-._])(beta|rc|pre|preview|test)(?:\d|$|[-._])/i.test(local)) {
|
||||
rows.push({ channel: "stable", version: local });
|
||||
}
|
||||
for (const item of rows) {
|
||||
if (!item || item.channel === "beta") continue;
|
||||
const ver = String(item.version || "").replace(/^v/i, "");
|
||||
if (!/^\d+\.\d+\.\d+/.test(ver) || /(?:^|[-._])(beta|rc|pre|preview|test)(?:\d|$|[-._])/i.test(ver)) continue;
|
||||
if (!best || listedVersionNewer(ver, best)) best = ver;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
function keepListedVersion(item, ceiling) {
|
||||
const ver = String((item && (item.version || item.ref)) || "").replace(/^v/i, "");
|
||||
if (/^1\.1\.11-beta/i.test(ver)) return false;
|
||||
if (item && item.channel === "beta" && ceiling && !listedVersionNewer(ver, ceiling)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function preferListed(list, localVer) {
|
||||
const ver = String(localVer || "").replace(/^v/i, "");
|
||||
return (list || []).find((item) => item.current)
|
||||
|| (list || []).find((item) => ver && String(item.version || "").replace(/^v/i, "") === ver)
|
||||
|| (list || []).find((item) => item.latest)
|
||||
|| (list || [])[0]
|
||||
|| null;
|
||||
}
|
||||
|
||||
function versionChoiceLabel(item, tr) {
|
||||
const ver = String((item && item.version) || "").replace(/^v/i, "");
|
||||
const base = ver ? ("v" + ver) : ((item && (item.label || item.ref)) || "—");
|
||||
if (item && item.current) return base + " · " + tr("update.current");
|
||||
if (item && item.latest) return base + " · " + tr("update.tip");
|
||||
return base;
|
||||
}
|
||||
|
||||
function SkillsSection() {
|
||||
@@ -2308,6 +2364,7 @@ body[data-ds-dark-theme] .dshp-rewind-item span{color:var(--dsw-alias-label-tert
|
||||
body: JSON.stringify({ sessionId, mode: "once" }),
|
||||
});
|
||||
if (data && data.ok && data.sessionId) {
|
||||
if (data.at) rewindSeenAt = data.at;
|
||||
const text = isPluginDraft(data.text) ? "" : (data.text || "");
|
||||
armComposerFill(data.sessionId, text);
|
||||
scheduleComposerFill(data.sessionId, text);
|
||||
|
||||
+70
-18
@@ -620,7 +620,7 @@ function listLiangshenCustomBashFiles(dshHome) {
|
||||
return out;
|
||||
}
|
||||
|
||||
// phase-1 只留 persona + dsh-purge*,不全量放行以免官方身份段漏回去。
|
||||
// phase-1 只留 persona + dsh-purge*。不改 contexts、不改消息白名单,梁神和官方插件照旧。
|
||||
export function silenceLiangshenPhase1Strip(dshHome = findDshHome()) {
|
||||
const marker = "[dsh-purge] phase-1 keep persona+inject sections";
|
||||
const keepAllMarker = "[dsh-purge] phase-1 keep full system-prompt sections";
|
||||
@@ -689,11 +689,32 @@ export function silenceLiangshenPhase1Strip(dshHome = findDshHome()) {
|
||||
" // " + marker + "\n",
|
||||
);
|
||||
|
||||
const contextMarker = "[dsh-purge] phase-1 keep runtime context";
|
||||
const keptContexts = " // " + contextMarker + "\n";
|
||||
if (next.includes(keptContexts)) {
|
||||
next = next.replace(keptContexts, " contexts: [],\n");
|
||||
}
|
||||
const allowNew =
|
||||
"function isAllowedMessage(message, allowedSources) {\n" +
|
||||
" const kind = message.source?.kind\n" +
|
||||
" // " + contextMarker + "\n" +
|
||||
' if (message?.source?.plugin === "@deepseek-ai/dsh-system-prompt") return true\n' +
|
||||
" return kind !== undefined && allowedSources.has(kind)\n" +
|
||||
"}";
|
||||
const allowOld =
|
||||
"function isAllowedMessage(message, allowedSources) {\n" +
|
||||
" const kind = message.source?.kind\n" +
|
||||
" return kind !== undefined && allowedSources.has(kind)\n" +
|
||||
"}";
|
||||
if (next.includes(allowNew)) next = next.replace(allowNew, allowOld);
|
||||
|
||||
const already =
|
||||
next.includes(marker) &&
|
||||
!next.includes(keepAllMarker) &&
|
||||
next.includes('startsWith("dsh-purge")') &&
|
||||
!next.includes(unfiltered);
|
||||
!next.includes(unfiltered) &&
|
||||
!next.includes(contextMarker) &&
|
||||
!next.includes('plugin === "@deepseek-ai/dsh-system-prompt"');
|
||||
if (already && next === text.replace(/\r\n/g, "\n")) {
|
||||
hit = "already";
|
||||
continue;
|
||||
@@ -1744,6 +1765,11 @@ const PATCHES = [
|
||||
'personaPrefix: ""',
|
||||
'prefix: ""',
|
||||
'text: ""',
|
||||
// bundle 布局 (0.1.5):web-app / headless 的 persona 是 `persona:` 键,
|
||||
// 上面三条都命中不了,会让已完成的清洗在 UI 上报待应用。见下方 markersAny。
|
||||
'persona: ""',
|
||||
// 1.3.x cordis preset:身份段删除后留下的 purge 注记同样是完成态。
|
||||
'[dsh-purge] identity stripped',
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -2237,21 +2263,16 @@ const NEW_TOOL_PATCHES = [
|
||||
rel: ["cordis.patch.yml"],
|
||||
replacements: [
|
||||
{
|
||||
pattern:
|
||||
' - id: bash-sandbox\n' +
|
||||
" name: '@deepseek-ai/dsh-bash-sandbox'\n" +
|
||||
" disabled: !!js process.platform === 'win32'\n" +
|
||||
' config:\n' +
|
||||
' timeoutMs: 60000',
|
||||
replace:
|
||||
' - id: bash-sandbox\n' +
|
||||
" name: '@deepseek-ai/dsh-bash-sandbox'\n" +
|
||||
" disabled: !!js process.platform === 'win32'\n" +
|
||||
' config:\n' +
|
||||
' timeoutMs: 600000',
|
||||
// 幂等性:原 pattern 以 `timeoutMs: 60000` 结尾,替换产物 `600000` 仍然
|
||||
// 包含它,于是每次 autoApplyOnStart 都会再拼一个 0(实测已涨到
|
||||
// 600000000000000)。
|
||||
// 现在的做法:锚在 bash-sandbox 行内,`[^\n]*` 必须吃到行尾 —— 这样上一次
|
||||
// 追加的注记会被整体重写而不是再叠一层,数值也不再有可再匹配的"前缀"。
|
||||
pattern: /(name: '@deepseek-ai\/dsh-bash-sandbox'[\s\S]*?\n {8}timeoutMs: )6[0-9]+[^\n]*/g,
|
||||
replace: "$1600000 // [dsh-purge] bash timeout raised",
|
||||
},
|
||||
],
|
||||
markers: ["timeoutMs: 600000"],
|
||||
markers: ["timeoutMs: 600000 // [dsh-purge] bash timeout raised"],
|
||||
},
|
||||
{
|
||||
id: 23, name: "READ_CAPS_RAISED", layer: "代码", layer_en: "Code",
|
||||
@@ -2439,6 +2460,9 @@ const NEW_TOOL_PATCHES = [
|
||||
markers: [
|
||||
"[dsh-purge] identity stripped",
|
||||
'prefix: ""',
|
||||
// bundle 布局:web-app / headless 的官方 persona 挂在 `persona:` 键上,
|
||||
// 清掉后是 `persona: ""` —— 既无 purge 注记也无 prefix 键。
|
||||
'persona: ""',
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -2956,6 +2980,7 @@ const NEW_TOOL_PATCHES = [
|
||||
id: 39, name: "PERSONA_TEXT_PREFIX_ALIAS", layer: "代码", layer_en: "Code",
|
||||
desc: "dsh-persona:兼容 0.1.2 text 字段,否则梁神会话起不来 / accept legacy text as prefix",
|
||||
file: "persona",
|
||||
optional: true, // 仅旧版 0.1.2 persona 使用;新版 prefix 结构无需改写
|
||||
replacements: [
|
||||
{
|
||||
pattern:
|
||||
@@ -3015,8 +3040,6 @@ 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 committed = sections.find((s) => s && s.name === \"dsh-purge:committed\");\n" +
|
||||
"\t\t\t\tif (committed && String(committed.text || \"\").trim()) return [{ ...complete, name: complete.name, text: committed.text }];\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" +
|
||||
@@ -3027,7 +3050,15 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
|
||||
"\t\t};",
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\t\t\tconst committed = sections.find((s) => s && s.name === \"dsh-purge:committed\");\n" +
|
||||
"\t\t\t\tif (committed && String(committed.text || \"\").trim()) return [{ ...complete, name: complete.name, text: committed.text }];\n",
|
||||
replace: "",
|
||||
},
|
||||
],
|
||||
// 已打过旧补丁的宿主里还有这行时,不能当成完成,要点一次应用删掉。
|
||||
forbid: ["dsh-purge:committed"],
|
||||
markers: ["[dsh-purge] complete prompt keeps inject"],
|
||||
},
|
||||
{
|
||||
@@ -3572,6 +3603,7 @@ export function sanitizeYamlPersonaScalars(text) {
|
||||
|
||||
function patchApplied(text, patch) {
|
||||
const hay = asLf(text);
|
||||
if (Array.isArray(patch.forbid) && patch.forbid.some((marker) => hay.includes(asLf(marker)))) return false;
|
||||
if (Array.isArray(patch.markers) && patch.markers.length > 0) {
|
||||
// markersAny:任一标记即可;默认要全部命中。
|
||||
const match = patch.markersAny ? "some" : "every";
|
||||
@@ -3584,6 +3616,15 @@ function patchApplied(text, patch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function matchesPattern(hay, pattern) {
|
||||
if (pattern instanceof RegExp) {
|
||||
const re = pattern.global ? pattern : new RegExp(pattern.source, pattern.flags);
|
||||
re.lastIndex = 0;
|
||||
return re.test(hay);
|
||||
}
|
||||
return hay.includes(asLf(pattern));
|
||||
}
|
||||
|
||||
function patchHasRemainingWork(text, patch, fp = "") {
|
||||
const hay = asLf(text);
|
||||
const yaml = isYamlPath(fp);
|
||||
@@ -3591,7 +3632,7 @@ function patchHasRemainingWork(text, patch, fp = "") {
|
||||
if (!pattern || typeof replace !== "string") continue;
|
||||
// 与 apply 一致:YAML 里无缩进 identity 不能 replaceAll,不算待做。
|
||||
if (yaml && isBareIdentityNeedle(pattern)) continue;
|
||||
if (hay.includes(asLf(pattern))) return true;
|
||||
if (matchesPattern(hay, pattern)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -3651,6 +3692,17 @@ function applyReplacementsToText(text, patch, fp = "") {
|
||||
if (!pattern || typeof replace !== "string") continue;
|
||||
// YAML 块标量行首有缩进;无缩进 identity+\n\n 会留下 6 空格,再和下一段拼成 12 空格。
|
||||
if (yaml && isBareIdentityNeedle(pattern)) continue;
|
||||
// 正则 pattern:用于自匹配型替换(产物包含原 pattern,如 timeoutMs 追加 0)。
|
||||
if (pattern instanceof RegExp) {
|
||||
const re = pattern.global ? pattern : new RegExp(pattern.source, pattern.flags + "g");
|
||||
if (!re.test(out)) continue;
|
||||
// 用字符串形态调用:保留 $1..$9 展开语义(回调形态会把 "$1" 当字面量写进文件)。
|
||||
const next = out.replace(re, asLf(replace));
|
||||
if (next === out) continue;
|
||||
out = next;
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
const needle = asLf(pattern);
|
||||
if (!out.includes(needle)) continue;
|
||||
out = out.split(needle).join(asLf(replace));
|
||||
|
||||
+4
-19
@@ -191,9 +191,8 @@ export function lastInjectedSystemPrompt(context, injectText) {
|
||||
export function shouldInjectPrompt(context, _injectOnce = true, injectText = "") {
|
||||
const inject = String(injectText || "").trim();
|
||||
if (!inject) return false;
|
||||
// 历史里已经有完整注入就不要再折一份。0.1.5 in-history 只要渲染结果和上一条
|
||||
// system/message 不同就会再追加,聊天里就会每步都冒出「系统提示词」。
|
||||
// 掏空注入也不行:渲染少了注入同样会被当成变化再追加,形成 A/B。
|
||||
// 只做历史探测。assemble 不要据此钉上一条 system/message 全文(#29):
|
||||
// 梁神等预设每轮还会追加 section,钉最近全文会变成「上一轮全文 + 本步新块」。
|
||||
return !lastInjectedSystemPrompt(context, inject);
|
||||
}
|
||||
|
||||
@@ -225,15 +224,6 @@ function normalizeRewriteOptions(fallbackInject, options) {
|
||||
};
|
||||
}
|
||||
|
||||
function pinCommittedSystemPrompt(sections, committed) {
|
||||
const names = sections.map((section) => String(section?.name || ""));
|
||||
const hasPrefix = names.some((name) => PERSONA_PREFIX_NAMES.has(name));
|
||||
const target = hasPrefix
|
||||
? names.find((name) => PERSONA_PREFIX_NAMES.has(name))
|
||||
: names.find((name) => PERSONA_LEGACY_NAMES.has(name));
|
||||
return [{ name: target || "dsh-purge:committed", text: committed }];
|
||||
}
|
||||
|
||||
// 0.1.5 优先写入 persona-prefix;无 prefix 时写入 legacy persona。
|
||||
function foldInjectIntoPersona(sections, injectText) {
|
||||
const inject = typeof injectText === "string" ? injectText : "";
|
||||
@@ -277,13 +267,8 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
}
|
||||
|
||||
const injectText = collectInjectText(purge, opts.fallbackInject);
|
||||
if (!shouldInjectPrompt(opts.context, true, injectText)) {
|
||||
const committed = lastInjectedSystemPrompt(opts.context, injectText);
|
||||
if (committed) {
|
||||
assembled.sections = pinCommittedSystemPrompt([...rest, ...purge], committed);
|
||||
return assembled;
|
||||
}
|
||||
}
|
||||
// #29: 不要把上一条 system/message 全文钉回 sections。
|
||||
// 「历史里已有完整注入就不再折一份」由 foldInjectIntoPersona 的 includes 幂等满足。
|
||||
const folded = foldInjectIntoPersona(rest, injectText);
|
||||
const extras = opts.dropPurgeAfterFold
|
||||
? purge.filter((section) => section.name !== "dsh-purge")
|
||||
|
||||
+72
-22
@@ -234,7 +234,7 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
context,
|
||||
});
|
||||
};
|
||||
// 只挂一次:挂多次会让同一轮 assemble 折两遍,UI 也会显示两次注入。
|
||||
// 只挂一次。不改 contexts,不改 pre-step 白名单,梁神 phase-1 和其它插件的消息原样保留。
|
||||
ctx.on("system-prompt/assemble", hook, { global: true, prepend: true });
|
||||
}
|
||||
|
||||
@@ -809,12 +809,62 @@ export function apply(ctx, config) {
|
||||
installWebServer(ctx, cfg);
|
||||
}
|
||||
|
||||
function headerOf(request, name) {
|
||||
const headers = request?.headers;
|
||||
if (!headers) return "";
|
||||
const value = headers[name] ?? headers[String(name).toLowerCase()];
|
||||
if (Array.isArray(value)) return String(value[0] || "");
|
||||
return String(value || "");
|
||||
}
|
||||
|
||||
function denyCrossOrigin(response) {
|
||||
response.writeHead(403, {
|
||||
"cache-control": "no-store",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
});
|
||||
response.end(JSON.stringify({ ok: false, error: "cross-origin blocked" }));
|
||||
}
|
||||
|
||||
function allowPluginRequest(request, response) {
|
||||
const site = headerOf(request, "sec-fetch-site").toLowerCase();
|
||||
if (site === "cross-site") {
|
||||
denyCrossOrigin(response);
|
||||
return false;
|
||||
}
|
||||
const origin = headerOf(request, "origin").trim();
|
||||
if (origin === "null") {
|
||||
denyCrossOrigin(response);
|
||||
return false;
|
||||
}
|
||||
if (!origin) return true;
|
||||
let originHost = "";
|
||||
try {
|
||||
originHost = new URL(origin).host;
|
||||
} catch {
|
||||
denyCrossOrigin(response);
|
||||
return false;
|
||||
}
|
||||
const host = headerOf(request, "host").trim();
|
||||
if (!host || originHost.toLowerCase() !== host.toLowerCase()) {
|
||||
denyCrossOrigin(response);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function installWebServer(ctx, cfg) {
|
||||
// 桌面端内嵌 @deepseek-ai/dsh-web-app,设置页同样走 webServer(常见 43120),不是只给官方 dsh web。
|
||||
watchWebTreeReady(ctx);
|
||||
ctx.inject(["webServer"], (host) => {
|
||||
host.effect(() => {
|
||||
host.webServer.register({
|
||||
const registerPluginRoute = (spec, label) => host.webServer.register({
|
||||
...spec,
|
||||
handler: async (request, response) => {
|
||||
if (!allowPluginRequest(request, response)) return;
|
||||
return spec.handler(request, response);
|
||||
},
|
||||
}, label);
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/status",
|
||||
handler: async (request, response) => {
|
||||
@@ -861,7 +911,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: status");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/last-user",
|
||||
handler: async (request, response) => {
|
||||
@@ -879,7 +929,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: last user");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/rewind/options",
|
||||
handler: async (request, response) => {
|
||||
@@ -897,7 +947,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: rewind options");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/rewind",
|
||||
handler: async (request, response) => {
|
||||
@@ -937,7 +987,7 @@ function installWebServer(ctx, cfg) {
|
||||
response.end();
|
||||
},
|
||||
}, "dsh-purge: rewind");
|
||||
// host.webServer.register({
|
||||
// registerPluginRoute({
|
||||
// kind: "exact",
|
||||
// path: "/dsh-purge/continue",
|
||||
// handler: async (request, response) => {
|
||||
@@ -975,7 +1025,7 @@ function installWebServer(ctx, cfg) {
|
||||
// response.end();
|
||||
// },
|
||||
// }, "dsh-purge: continue");
|
||||
// host.webServer.register({
|
||||
// registerPluginRoute({
|
||||
// kind: "exact",
|
||||
// path: "/dsh-purge/continue/settings",
|
||||
// handler: async (request, response) => {
|
||||
@@ -1004,7 +1054,7 @@ function installWebServer(ctx, cfg) {
|
||||
// response.end();
|
||||
// },
|
||||
// }, "dsh-purge: continue settings");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/update",
|
||||
handler: async (request, response) => {
|
||||
@@ -1029,7 +1079,7 @@ function installWebServer(ctx, cfg) {
|
||||
response.end();
|
||||
},
|
||||
}, "dsh-purge: update");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/apply",
|
||||
handler: async (request, response) => {
|
||||
@@ -1093,7 +1143,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: apply");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/revert",
|
||||
handler: async (request, response) => {
|
||||
@@ -1117,7 +1167,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: revert");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/uninstall",
|
||||
handler: async (request, response) => {
|
||||
@@ -1146,7 +1196,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: uninstall");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/override",
|
||||
handler: async (request, response) => {
|
||||
@@ -1191,7 +1241,7 @@ function installWebServer(ctx, cfg) {
|
||||
}, "dsh-purge: override");
|
||||
installRulesHttp(host.webServer);
|
||||
installSkillsHttp(host.webServer);
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/restart",
|
||||
handler: async (request, response) => {
|
||||
@@ -1414,29 +1464,29 @@ function installRulesHttp(webServer) {
|
||||
};
|
||||
}
|
||||
|
||||
const CORS_HEAD = {
|
||||
"access-control-allow-origin": "*",
|
||||
"access-control-allow-methods": "GET, POST, OPTIONS",
|
||||
"access-control-allow-headers": "content-type",
|
||||
};
|
||||
|
||||
function sendJson(response, status, payload) {
|
||||
response.writeHead(status, {
|
||||
"cache-control": "no-store",
|
||||
"content-type": "application/json; charset=utf-8",
|
||||
...CORS_HEAD,
|
||||
});
|
||||
response.end(JSON.stringify(payload));
|
||||
}
|
||||
|
||||
function sendOptions(response) {
|
||||
response.writeHead(204, { ...CORS_HEAD, "access-control-max-age": "86400" });
|
||||
response.writeHead(204, { "cache-control": "no-store" });
|
||||
response.end();
|
||||
}
|
||||
|
||||
function registerRoute(webServer, spec) {
|
||||
try {
|
||||
return webServer.register(spec);
|
||||
const handler = spec.handler;
|
||||
return webServer.register({
|
||||
...spec,
|
||||
handler: async (request, response) => {
|
||||
if (!allowPluginRequest(request, response)) return;
|
||||
return handler(request, response);
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn("[dsh-purge] route", spec?.path, String(e && e.message ? e.message : e));
|
||||
return () => {};
|
||||
|
||||
+16
-7
@@ -6,6 +6,10 @@ function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
function ignoreSettled(value) {
|
||||
Promise.resolve(value).catch(() => {});
|
||||
}
|
||||
|
||||
function errorText(err) {
|
||||
if (!err) return "回退失败";
|
||||
if (typeof err === "string") return err;
|
||||
@@ -149,11 +153,16 @@ export function planRewind(events) {
|
||||
return { ok: false, error: "没有可回退的上一句" };
|
||||
}
|
||||
const text = userTextFromEvent(lastUser);
|
||||
if (turnEnds.length >= 2) {
|
||||
const open = lastOpenTurn(list);
|
||||
const fromOpenTurn = Boolean(open && lastUser.seq >= open.seq);
|
||||
// 开放回合的那句还没进历史,切在最后一个已闭合 turn/end。
|
||||
// 已闭合的上一句要整轮拿掉,所以再往前一个 end。
|
||||
const cutIndex = fromOpenTurn ? turnEnds.length - 1 : turnEnds.length - 2;
|
||||
if (cutIndex >= 0) {
|
||||
return {
|
||||
ok: true,
|
||||
mode: "fork",
|
||||
atSeq: turnEnds[turnEnds.length - 2].seq,
|
||||
atSeq: turnEnds[cutIndex].seq,
|
||||
text,
|
||||
};
|
||||
}
|
||||
@@ -301,7 +310,7 @@ async function disarmRewoundSession(ctx, sessionId) {
|
||||
const disarmOnce = async () => {
|
||||
const agent = getAgent(ctx, sessionId);
|
||||
try { agent?.inbox?.clear?.(); } catch { /* ignore */ }
|
||||
try { agent?.cancel?.({ kind: "user" }, { keepInbox: false }); } catch { /* ignore */ }
|
||||
try { ignoreSettled(agent?.cancel?.({ kind: "user" }, { keepInbox: false })); } catch { /* ignore */ }
|
||||
|
||||
const ids = [];
|
||||
try {
|
||||
@@ -319,7 +328,7 @@ async function disarmRewoundSession(ctx, sessionId) {
|
||||
if (!id || seen.has(id)) continue;
|
||||
seen.add(id);
|
||||
try {
|
||||
controller?.updateQueue?.({
|
||||
await controller?.updateQueue?.({
|
||||
sessionId,
|
||||
itemId: id,
|
||||
action: { kind: "remove" },
|
||||
@@ -329,7 +338,7 @@ async function disarmRewoundSession(ctx, sessionId) {
|
||||
|
||||
try { agent?.inbox?.clear?.(); } catch { /* ignore */ }
|
||||
if (agent?.status === "running") {
|
||||
try { agent.cancel({ kind: "user" }, { keepInbox: false }); } catch { /* ignore */ }
|
||||
try { ignoreSettled(agent.cancel({ kind: "user" }, { keepInbox: false })); } catch { /* ignore */ }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -380,7 +389,7 @@ async function resolveMainSession(ctx, sessionId) {
|
||||
async function rewindOneSession(ctx, controller, sessionId) {
|
||||
let log = await readSessionLog(ctx, sessionId);
|
||||
if (lastOpenTurn(log.events)) {
|
||||
try { controller.cancel?.({ sessionId }); } catch { /* ignore */ }
|
||||
try { ignoreSettled(controller.cancel?.({ sessionId })); } catch { /* ignore */ }
|
||||
log = await waitTurnClosed(ctx, sessionId);
|
||||
}
|
||||
const plan = planRewind(log.events);
|
||||
@@ -438,7 +447,7 @@ export async function applyRewind(ctx, sessionId, mode) {
|
||||
if (action === "round") {
|
||||
const target = await resolveMainSession(ctx, sessionId);
|
||||
if (sessionId !== target.sessionId) {
|
||||
try { controller.cancel?.({ sessionId }); } catch { /* ignore */ }
|
||||
try { ignoreSettled(controller.cancel?.({ sessionId })); } catch { /* ignore */ }
|
||||
}
|
||||
const result = await rewindOneSession(ctx, controller, target.sessionId);
|
||||
if (!result.ok) return result;
|
||||
|
||||
+152
-52
@@ -96,6 +96,29 @@ export function versionIsNewer(remote, local) {
|
||||
return a.pre > b.pre;
|
||||
}
|
||||
|
||||
export function latestStableVersion(versions) {
|
||||
let best = "";
|
||||
for (const item of versions || []) {
|
||||
if (!item || item.channel === "beta") continue;
|
||||
const ver = String(item.version || "").replace(/^v/i, "");
|
||||
if (!/^\d+\.\d+\.\d+/.test(ver) || isBetaName(ver)) continue;
|
||||
if (!best || versionIsNewer(ver, best)) best = ver;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/** 正式版已经追上的测试版不再列出。1.1.11-beta 始终下线。 */
|
||||
export function hideListedVersion(item, stableVersion = "") {
|
||||
if (!item || withdrawnVersion(item)) return true;
|
||||
const beta = item.channel === "beta" || isBetaName(item.version) || isBetaName(item.ref) || isBetaName(item.id);
|
||||
if (!beta) return false;
|
||||
const ceiling = String(stableVersion || "").replace(/^v/i, "");
|
||||
if (!ceiling || isBetaName(ceiling)) return false;
|
||||
const ver = String(item.version || item.ref || item.id || "").replace(/^v/i, "");
|
||||
if (!/^\d+\.\d+/.test(ver)) return false;
|
||||
return !versionIsNewer(ver, ceiling);
|
||||
}
|
||||
|
||||
export function readChannelState() {
|
||||
const raw = readJson(channelStatePath()) || {};
|
||||
return {
|
||||
@@ -153,10 +176,6 @@ function archiveTarballUrl(ref) {
|
||||
return `https://github.com/${REPO}/archive/refs/heads/${encodeURIComponent(value)}.tar.gz`;
|
||||
}
|
||||
|
||||
function githubSpec(ref) {
|
||||
return `github:${REPO}#${ref || STABLE_REF}`;
|
||||
}
|
||||
|
||||
function readStamp() {
|
||||
try {
|
||||
return fs.readFileSync(stampPath(), "utf8").trim();
|
||||
@@ -313,8 +332,17 @@ export function runDshPlugin(profile, args) {
|
||||
|
||||
export function pluginAddSpec(spec, ref = currentChannelRef()) {
|
||||
const s = String(spec || "");
|
||||
if (/\.(zip|tgz|tar\.gz)(\b|$)/i.test(s) || /^https?:\/\//i.test(s)) return archiveTarballUrl(ref);
|
||||
if (/^github:/i.test(s) || /github\.com\/.+\.git/i.test(s)) return githubSpec(ref);
|
||||
// github: / git+https 会让 pnpm 跑 git ls-remote。没装 git 时就是 #30。
|
||||
// 公开仓库用 archive tar.gz,不依赖本机 git。
|
||||
if (
|
||||
/\.(zip|tgz|tar\.gz)(\b|$)/i.test(s) ||
|
||||
/^https?:\/\//i.test(s) ||
|
||||
/^git\+https?:\/\//i.test(s) ||
|
||||
/^github:/i.test(s) ||
|
||||
/github\.com\/.+\.git/i.test(s)
|
||||
) {
|
||||
return archiveTarballUrl(ref);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -475,17 +503,46 @@ function rememberVersion(item, seen) {
|
||||
return item;
|
||||
}
|
||||
|
||||
function markCurrent(versions, state, localVer, localSha) {
|
||||
return (versions || []).map((item) => ({
|
||||
...item,
|
||||
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
|
||||
current: Boolean(
|
||||
(localSha && item.sha && sameRev(localSha, item.sha))
|
||||
|| (state.pin && item.ref === state.pin)
|
||||
|| (!state.pin && item.latest && item.channel === state.channel && item.version && item.version === localVer)
|
||||
|| (!state.pin && item.version && item.version === localVer && item.channel === (isBetaName(localVer) ? "beta" : "stable")),
|
||||
),
|
||||
}));
|
||||
const UPDATE_REF_RE = /^(?:master|beta|v\d+\.\d+[\w.-]{0,48}|[0-9a-f]{7,40})$/i;
|
||||
|
||||
export function safeUpdateRef(ref) {
|
||||
const target = String(ref || "").trim();
|
||||
if (!UPDATE_REF_RE.test(target)) return "";
|
||||
return target;
|
||||
}
|
||||
|
||||
export function markCurrent(versions, state, localVer, localSha) {
|
||||
const pin = String(state?.pin || "");
|
||||
const rows = versions || [];
|
||||
const ver = String(localVer || "").replace(/^v/i, "");
|
||||
const shaMatched = rows.some((item) => localSha && item.sha && sameRev(localSha, item.sha));
|
||||
const versionOnLatest = rows.some((item) => (
|
||||
item.latest
|
||||
&& item.channel === state?.channel
|
||||
&& String(item.version || "").replace(/^v/i, "") === ver
|
||||
));
|
||||
const versionFallback = versionOnLatest ? null : rows.find((item) => (
|
||||
item.channel === state?.channel
|
||||
&& String(item.version || "").replace(/^v/i, "") === ver
|
||||
));
|
||||
return rows.map((item) => {
|
||||
const shaHit = Boolean(localSha && item.sha && sameRev(localSha, item.sha));
|
||||
const pinHit = Boolean(pin && item.ref === pin);
|
||||
// 提交号对不上时,只把本通道里和本机版本号相同的那一条标成当前。
|
||||
const headHit = Boolean(
|
||||
!pin
|
||||
&& !shaMatched
|
||||
&& ver
|
||||
&& (versionOnLatest
|
||||
? item.latest && item.channel === state?.channel && String(item.version || "").replace(/^v/i, "") === ver
|
||||
: versionFallback && item === versionFallback)
|
||||
);
|
||||
return {
|
||||
...item,
|
||||
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
|
||||
current: shaHit || pinHit || headHit,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function listGithubTags() {
|
||||
@@ -512,6 +569,25 @@ async function listGithubTags() {
|
||||
}
|
||||
}
|
||||
|
||||
function ensureRunningVersion(versions, state, localVer, localSha) {
|
||||
const ver = String(localVer || "").replace(/^v/i, "");
|
||||
if (!ver || isBetaName(ver) || state?.channel === "beta") return versions;
|
||||
if ((versions || []).some((item) => item.channel === "stable" && String(item.version || "").replace(/^v/i, "") === ver)) {
|
||||
return versions;
|
||||
}
|
||||
const ref = (versions || []).some((item) => item.ref === "master") ? `local-${ver}` : "master";
|
||||
return [{
|
||||
id: ref,
|
||||
ref,
|
||||
sha: localSha || "",
|
||||
version: ver,
|
||||
channel: "stable",
|
||||
label: versionLabel(ver, "stable", localSha),
|
||||
kind: "local",
|
||||
latest: !(versions || []).some((item) => item.channel === "stable" && item.latest),
|
||||
}, ...(versions || [])];
|
||||
}
|
||||
|
||||
async function listRemoteVersions() {
|
||||
const state = readChannelState();
|
||||
const seen = new Set();
|
||||
@@ -567,11 +643,18 @@ async function listRemoteVersions() {
|
||||
|
||||
const localVer = localVersion();
|
||||
const localSha = (gitOk() ? gitHead(PLUGIN_ROOT) : "") || readStamp();
|
||||
const withLocal = ensureRunningVersion(out, state, localVer, localSha);
|
||||
const ceiling = latestStableVersion([
|
||||
...withLocal,
|
||||
localVer && !isBetaName(localVer) ? { channel: "stable", version: localVer } : null,
|
||||
].filter(Boolean));
|
||||
const visible = withLocal.filter((item) => !hideListedVersion(item, ceiling));
|
||||
const betaOpen = visible.some((item) => item.channel === "beta");
|
||||
return {
|
||||
versions: markCurrent(out.filter((item) => !withdrawnVersion(item)), state, localVer, localSha),
|
||||
hasBeta: Boolean(betaSha || out.some((item) => item.channel === "beta" && item.kind === "tag")),
|
||||
versions: markCurrent(visible, state, localVer, localSha),
|
||||
hasBeta: betaOpen,
|
||||
stableSha,
|
||||
betaSha,
|
||||
betaSha: betaOpen ? betaSha : "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -597,8 +680,7 @@ function describeLane(id, listed, state, localVer, localRev) {
|
||||
const version = latest?.version || "";
|
||||
const onLane = state.channel === id;
|
||||
const matchesHead = Boolean(localRev && sha && sameRev(localRev, sha));
|
||||
const current = versions.some((item) => item.current) || matchesHead
|
||||
|| Boolean(onLane && version && localVer && version === localVer && !state.pin);
|
||||
const current = matchesHead || versions.some((item) => item.current && (item.latest || (state.pin && item.ref === state.pin)));
|
||||
let hasUpdate = false;
|
||||
if (onLane && state.pin) {
|
||||
hasUpdate = Boolean(sha && localRev && !sameRev(localRev, sha));
|
||||
@@ -716,7 +798,8 @@ function gitResetTo(dir, ref, { force = false } = {}) {
|
||||
if (!force && gitTrackedDirty(dir)) {
|
||||
throw new Error("本地插件文件有未提交改动,未覆盖");
|
||||
}
|
||||
const target = String(ref || STABLE_REF);
|
||||
const target = safeUpdateRef(ref || STABLE_REF);
|
||||
if (!target) throw new Error("未知版本");
|
||||
try {
|
||||
runGit(dir, ["fetch", "origin", "--tags"], 60000);
|
||||
} catch {
|
||||
@@ -798,7 +881,8 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) {
|
||||
jobs = planUpdates();
|
||||
}
|
||||
const state = readChannelState();
|
||||
const ref = String(options.ref || currentChannelRef(state) || STABLE_REF);
|
||||
const ref = safeUpdateRef(options.ref || currentChannelRef(state) || STABLE_REF);
|
||||
if (!ref) throw new Error("未知版本");
|
||||
const force = options.force !== false;
|
||||
const zipDirs = [];
|
||||
const vias = new Set();
|
||||
@@ -845,13 +929,7 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) {
|
||||
label: versionLabel(localVer, channel, sha),
|
||||
at: new Date().toISOString(),
|
||||
});
|
||||
const prev = lastUpdateResult() || {};
|
||||
const listed = {
|
||||
versions: Array.isArray(prev.versions) ? prev.versions : [],
|
||||
hasBeta: prev.hasBeta !== false,
|
||||
stableSha: prev.stableSha || "",
|
||||
betaSha: prev.betaSha || "",
|
||||
};
|
||||
const listed = await listRemoteVersions().catch(() => ({ versions: [], hasBeta: saved.channel === "beta" }));
|
||||
return rememberUpdate({
|
||||
ok: true,
|
||||
applied: true,
|
||||
@@ -874,21 +952,24 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) {
|
||||
export async function switchChannel(channel, { apply = true } = {}) {
|
||||
const next = normalizeChannel(channel);
|
||||
if (next === "beta") {
|
||||
const betaSha = await remoteHeadSha(BETA_REF);
|
||||
if (!betaSha) {
|
||||
const tags = await listGithubTags();
|
||||
const tag = tags.find((item) => item.channel === "beta");
|
||||
if (!tag) {
|
||||
return rememberUpdate({
|
||||
ok: false,
|
||||
error: "还没有测试版",
|
||||
hasBeta: false,
|
||||
...channelPublic(),
|
||||
versions: [],
|
||||
lanes: { stable: { id: "stable", hasRemote: true }, beta: { id: "beta", hasRemote: false } },
|
||||
});
|
||||
}
|
||||
if (apply) return applyUpdate(planUpdates(), { ref: tag.ref, channel: "beta", pin: false, force: true });
|
||||
const listed = await listRemoteVersions();
|
||||
if (!listed.hasBeta) {
|
||||
const state = readChannelState();
|
||||
const localVer = localVersion();
|
||||
const localRev = (gitOk() ? gitHead(PLUGIN_ROOT) : "") || readStamp();
|
||||
return rememberUpdate({
|
||||
ok: false,
|
||||
error: "还没有测试版",
|
||||
hasBeta: false,
|
||||
localVersion: localVer,
|
||||
versions: listed.versions,
|
||||
lanes: lanesOf(listed, state, localVer, localRev),
|
||||
...channelPublic(state),
|
||||
});
|
||||
}
|
||||
if (!listed.betaSha && apply) {
|
||||
const tag = listed.versions.find((item) => item.channel === "beta" && item.kind === "tag");
|
||||
if (tag) return applyUpdate(planUpdates(), { ref: tag.ref, channel: "beta", pin: false, force: true });
|
||||
}
|
||||
}
|
||||
if (!apply) {
|
||||
@@ -898,14 +979,27 @@ export async function switchChannel(channel, { apply = true } = {}) {
|
||||
return applyUpdate(planUpdates(), { ref: CHANNELS[next].ref, channel: next, pin: false, force: true });
|
||||
}
|
||||
|
||||
function listedUpdateRef(target, listed) {
|
||||
const safe = safeUpdateRef(target);
|
||||
if (!safe) return "";
|
||||
const hit = (listed?.versions || []).find((item) => (
|
||||
item.ref === safe
|
||||
|| item.id === safe
|
||||
|| item.sha === safe
|
||||
|| (item.sha && safe.length >= 7 && (item.sha.startsWith(safe) || safe.startsWith(item.sha)))
|
||||
));
|
||||
return safeUpdateRef(hit?.ref || "");
|
||||
}
|
||||
|
||||
export async function switchVersion(ref) {
|
||||
const target = String(ref || "").trim();
|
||||
const raw = String(ref || "").trim();
|
||||
if (withdrawnVersion({ ref: raw, version: raw })) throw new Error("该版本已下线");
|
||||
const target = safeUpdateRef(raw);
|
||||
if (!target) throw new Error("请选择要回退的版本");
|
||||
if (withdrawnVersion({ ref: target, version: target })) throw new Error("该版本已下线");
|
||||
const listed = await listRemoteVersions();
|
||||
const hit = listed.versions.find((item) => item.ref === target || item.id === target || item.version === target || item.sha === target);
|
||||
if (hit && withdrawnVersion(hit)) throw new Error("该版本已下线");
|
||||
const resolved = hit?.ref || target;
|
||||
const resolved = listedUpdateRef(target, listed);
|
||||
if (!resolved) throw new Error("未知版本");
|
||||
const hit = listed.versions.find((item) => item.ref === resolved);
|
||||
const channel = hit?.channel || readChannelState().channel;
|
||||
const pin = hit?.latest ? "" : resolved;
|
||||
return applyUpdate(planUpdates(), { ref: resolved, channel, pin, force: true });
|
||||
@@ -918,7 +1012,13 @@ export async function handleUpdateOp(body = {}) {
|
||||
if (op === "switch" || op === "rollback") return switchVersion(body.ref || body.version || body.id);
|
||||
if (op === "auto") return autoUpdateIfNeeded();
|
||||
const state = readChannelState();
|
||||
const ref = body.ref || currentChannelRef(state);
|
||||
const requested = body.ref || currentChannelRef(state);
|
||||
const ref = safeUpdateRef(requested);
|
||||
if (!ref) throw new Error("未知版本");
|
||||
if (ref !== STABLE_REF && ref !== BETA_REF) {
|
||||
const listed = await listRemoteVersions();
|
||||
if (!listedUpdateRef(ref, listed)) throw new Error("未知版本");
|
||||
}
|
||||
const channel = body.channel || (ref === BETA_REF ? "beta" : ref === STABLE_REF ? "stable" : state.channel);
|
||||
return applyUpdate(planUpdates(), { ref, channel, pin: false, force: true });
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.12-beta.1",
|
||||
"version": "1.1.14",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
@@ -27,7 +27,10 @@
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"embed-prompt": "node scripts/embed-default-prompt.mjs"
|
||||
"embed-prompt": "node scripts/embed-default-prompt.mjs",
|
||||
"test:identity": "node scripts/test-identity-assembly.mjs",
|
||||
"test:update": "node scripts/test-update-guards.mjs",
|
||||
"test:rewind": "node scripts/test-rewind-plan.mjs"
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { rewritePromptAssembly } from "../lib/identity.js";
|
||||
|
||||
const inject = [
|
||||
"WHO YOU ARE (highest priority operator inject)",
|
||||
"You are Little Code Sauce.",
|
||||
"Keep this block intact.",
|
||||
].join("\n");
|
||||
|
||||
const persona = "Working directory: {{cwd}}.\nFollow official harness tools.";
|
||||
|
||||
function render(assembled) {
|
||||
return (assembled.sections || [])
|
||||
.map((section) => String(section?.text || ""))
|
||||
.filter(Boolean)
|
||||
.join("\n\n");
|
||||
}
|
||||
|
||||
function historyContext(text) {
|
||||
return {
|
||||
session: {
|
||||
events: [
|
||||
{
|
||||
type: "system/message",
|
||||
data: { message: { role: "system", content: text } },
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function workspaceBlock(n) {
|
||||
return `workspace snapshot ${n}\n${"W".repeat(3000)}`;
|
||||
}
|
||||
|
||||
// 梁神一类:assemble 外层在我们折完之后再追加一条 workspace-instructions。
|
||||
function assembleWithOuterWorkspace(workspaceText, context) {
|
||||
const rewritten = rewritePromptAssembly(
|
||||
{
|
||||
sections: [
|
||||
{ name: "deployment:persona-prefix", text: persona },
|
||||
{ name: "dsh-purge", text: inject },
|
||||
],
|
||||
},
|
||||
{
|
||||
fallbackInject: inject,
|
||||
dropPurgeAfterFold: true,
|
||||
context,
|
||||
},
|
||||
);
|
||||
rewritten.sections = [
|
||||
...rewritten.sections,
|
||||
{ name: "workspace-instructions", text: workspaceText },
|
||||
];
|
||||
return rewritten;
|
||||
}
|
||||
|
||||
const turn1 = assembleWithOuterWorkspace(workspaceBlock(1), {});
|
||||
const r1 = render(turn1);
|
||||
assert.match(r1, /Little Code Sauce/);
|
||||
assert.match(r1, /workspace snapshot 1/);
|
||||
assert.equal((r1.match(/Little Code Sauce/g) || []).length, 1);
|
||||
|
||||
const turn2 = assembleWithOuterWorkspace(workspaceBlock(2), historyContext(r1));
|
||||
const r2 = render(turn2);
|
||||
|
||||
assert.equal(
|
||||
r2.startsWith(r1),
|
||||
false,
|
||||
"#29: later assemble must not be previous full system prompt + new block",
|
||||
);
|
||||
assert.equal(
|
||||
(r2.match(/workspace snapshot /g) || []).length,
|
||||
1,
|
||||
"#29: must not keep the previous workspace-instructions copy inside a pinned blob",
|
||||
);
|
||||
assert.match(r2, /workspace snapshot 2/);
|
||||
assert.doesNotMatch(r2, /workspace snapshot 1/);
|
||||
assert.match(r2, /Little Code Sauce/);
|
||||
assert.equal((r2.match(/Little Code Sauce/g) || []).length, 1);
|
||||
|
||||
let prev = r1;
|
||||
for (let n = 2; n <= 8; n++) {
|
||||
const turn = assembleWithOuterWorkspace(workspaceBlock(n), historyContext(prev));
|
||||
const next = render(turn);
|
||||
assert.equal(next.startsWith(prev), false, `turn ${n} must not prefix-grow`);
|
||||
assert.ok(
|
||||
Math.abs(next.length - r1.length) < 80,
|
||||
`turn ${n} length ${next.length} drifted from first ${r1.length}`,
|
||||
);
|
||||
prev = next;
|
||||
}
|
||||
|
||||
const again = rewritePromptAssembly(
|
||||
{
|
||||
sections: [
|
||||
{ name: "deployment:persona-prefix", text: `${inject}\n\n${persona}` },
|
||||
{ name: "dsh-purge", text: inject },
|
||||
],
|
||||
},
|
||||
{ fallbackInject: inject, dropPurgeAfterFold: true, context: historyContext(r2) },
|
||||
);
|
||||
assert.equal((render(again).match(/Little Code Sauce/g) || []).length, 1);
|
||||
|
||||
console.log("ok: #29 pin snowball is gone");
|
||||
@@ -0,0 +1,54 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { planRewind } from "../lib/rewind.js";
|
||||
|
||||
function user(seq, text) {
|
||||
return { seq, type: "user/message", data: { source: { kind: "user" }, content: text } };
|
||||
}
|
||||
function start(seq) {
|
||||
return { seq, type: "turn/start" };
|
||||
}
|
||||
function end(seq) {
|
||||
return { seq, type: "turn/end" };
|
||||
}
|
||||
|
||||
const closed = planRewind([
|
||||
start(1), user(2, "Q1"), end(3),
|
||||
start(4), user(5, "Q2"), end(6),
|
||||
]);
|
||||
assert.equal(closed.mode, "fork");
|
||||
assert.equal(closed.atSeq, 3);
|
||||
assert.equal(closed.text, "Q2");
|
||||
|
||||
const open = planRewind([
|
||||
start(1), user(2, "Q1"), end(3),
|
||||
start(4), user(5, "Q2"), end(6),
|
||||
start(7), user(8, "Q3"),
|
||||
]);
|
||||
assert.equal(open.mode, "fork");
|
||||
assert.equal(open.atSeq, 6);
|
||||
assert.equal(open.text, "Q3");
|
||||
|
||||
const openWithoutQuestion = planRewind([
|
||||
start(1), user(2, "Q1"), end(3),
|
||||
start(4), user(5, "Q2"), end(6),
|
||||
start(7),
|
||||
]);
|
||||
assert.equal(openWithoutQuestion.mode, "fork");
|
||||
assert.equal(openWithoutQuestion.atSeq, 3);
|
||||
assert.equal(openWithoutQuestion.text, "Q2");
|
||||
|
||||
const oneThenOpen = planRewind([
|
||||
start(1), user(2, "Q1"), end(3),
|
||||
start(4), user(5, "Q2"),
|
||||
]);
|
||||
assert.equal(oneThenOpen.mode, "fork");
|
||||
assert.equal(oneThenOpen.atSeq, 3);
|
||||
assert.equal(oneThenOpen.text, "Q2");
|
||||
|
||||
const onlyOne = planRewind([
|
||||
start(1), user(2, "Q1"), end(3),
|
||||
]);
|
||||
assert.equal(onlyOne.mode, "blank");
|
||||
assert.equal(onlyOne.text, "Q1");
|
||||
|
||||
console.log("ok: rewind plan");
|
||||
@@ -0,0 +1,56 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { hideListedVersion, latestStableVersion, markCurrent, pluginAddSpec, safeUpdateRef } from "../lib/update.js";
|
||||
|
||||
assert.equal(safeUpdateRef("master"), "master");
|
||||
assert.equal(safeUpdateRef("beta"), "beta");
|
||||
assert.equal(safeUpdateRef("v1.1.11"), "v1.1.11");
|
||||
assert.equal(safeUpdateRef("v1.1.12-beta.1"), "v1.1.12-beta.1");
|
||||
assert.equal(safeUpdateRef("9397203733562d6baeec9e38ac519698c619edcb"), "9397203733562d6baeec9e38ac519698c619edcb");
|
||||
assert.equal(safeUpdateRef("--hard"), "");
|
||||
assert.equal(safeUpdateRef("origin/master"), "");
|
||||
assert.equal(safeUpdateRef("../evil"), "");
|
||||
assert.equal(safeUpdateRef("master;rm"), "");
|
||||
|
||||
const masterTar = "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz";
|
||||
assert.equal(pluginAddSpec("git+https://github.com/yujunzhixue/dsh-purge.git", "master"), masterTar);
|
||||
assert.equal(pluginAddSpec("github:yujunzhixue/dsh-purge", "master"), masterTar);
|
||||
assert.equal(pluginAddSpec("https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip", "master"), masterTar);
|
||||
assert.equal(pluginAddSpec("dsh-purge", "master"), "");
|
||||
|
||||
const head = "9397203733562d6baeec9e38ac519698c619edcb";
|
||||
const tag = "5e6be24acc3e5aac981c701cc34ef710ce48c4c7";
|
||||
const versions = [
|
||||
{ id: "master", ref: "master", sha: head, version: "1.1.11", channel: "stable", latest: true },
|
||||
{ id: "v1.1.11", ref: "v1.1.11", sha: tag, version: "1.1.11", channel: "stable" },
|
||||
];
|
||||
const marked = markCurrent(versions, { channel: "stable", pin: "" }, "1.1.11", head);
|
||||
assert.equal(marked.find((item) => item.ref === "master").current, true);
|
||||
assert.equal(marked.find((item) => item.ref === "v1.1.11").current, false);
|
||||
|
||||
const onTag = markCurrent(versions, { channel: "stable", pin: "v1.1.11" }, "1.1.11", tag);
|
||||
assert.equal(onTag.find((item) => item.ref === "v1.1.11").current, true);
|
||||
assert.equal(onTag.find((item) => item.ref === "master").current, false);
|
||||
|
||||
const caughtUp = [
|
||||
{ ref: "master", version: "1.1.12", channel: "stable", latest: true },
|
||||
{ ref: "v1.1.12", version: "1.1.12", channel: "stable" },
|
||||
{ ref: "v1.1.12-beta.1", version: "1.1.12-beta.1", channel: "beta" },
|
||||
{ ref: "beta", version: "1.1.12-beta.1", channel: "beta", latest: true },
|
||||
{ ref: "v1.1.13-beta.1", version: "1.1.13-beta.1", channel: "beta" },
|
||||
];
|
||||
const ceiling = latestStableVersion(caughtUp);
|
||||
assert.equal(ceiling, "1.1.12");
|
||||
assert.equal(hideListedVersion(caughtUp[2], ceiling), true);
|
||||
assert.equal(hideListedVersion(caughtUp[3], ceiling), true);
|
||||
assert.equal(hideListedVersion(caughtUp[4], ceiling), false);
|
||||
assert.equal(hideListedVersion({ ref: "v1.1.11-beta.1", version: "1.1.11-beta.1", channel: "beta" }, ""), true);
|
||||
|
||||
const visible = caughtUp.filter((item) => !hideListedVersion(item, ceiling));
|
||||
assert.deepEqual(visible.map((item) => item.ref), ["master", "v1.1.12", "v1.1.13-beta.1"]);
|
||||
const staleSha = "423a91614baa747b56749003d054fedb8e725714";
|
||||
const shown = markCurrent(visible, { channel: "stable", pin: "" }, "1.1.12", staleSha);
|
||||
assert.equal(shown.find((item) => item.ref === "master").current, true);
|
||||
assert.equal(shown.find((item) => item.ref === "v1.1.12").current, false);
|
||||
assert.equal(shown.find((item) => item.ref === "v1.1.13-beta.1").current, false);
|
||||
|
||||
console.log("ok: update guards");
|
||||
Reference in new issue
Block a user