mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 19:20:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
014a225822 | ||
|
|
0fb12fc25e | ||
|
|
1a47bcd969 | ||
|
|
c743a64d13 | ||
|
|
fd631154f2 | ||
|
|
ed08f0c431 |
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.10</strong></p>
|
||||
<p align="center"><strong>Version 1.1.11</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>
|
||||
@@ -70,6 +70,8 @@ This is a **local official DeepSeek Harness cybersecurity red-team plugin**. It
|
||||
|
||||
<font color="red">
|
||||
|
||||
**Disclaimer:** This is a non-profit open-source project. It follows applicable laws and the rules of the platforms it uses, and is intended only for learning and research. Do not use it for any illegal or non-compliant purpose; the user bears any resulting consequences.
|
||||
|
||||
**Zero-tolerance statement:** This project opposes and forbids any illegal activity. The authors do not support, encourage, or assist unauthorized network attacks, exploit use, data theft, unlawful intrusion into computer information systems, or generation of illegal or prohibited content. **Anyone who uses this project for crime is solely responsible under the law. The authors have no liability.**
|
||||
|
||||
1. **This repository contains no illegal material.** The published code, docs, patches, and default prompt are **not** malware, backdoors, unauthorized pentest kits, ransomware, credential-stuffing scripts, or attack payloads aimed at the public internet or third-party systems. The project does not supply illegal content and does not incite, organize, or assist crime.
|
||||
@@ -244,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.11&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.11&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:**
|
||||
@@ -263,7 +265,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.10',
|
||||
version: '1.1.11',
|
||||
repo: 'YuJunZhiXue/dsh-purge',
|
||||
permissions: '系统提示词注入, 本机补丁, 设置页',
|
||||
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
|
||||
@@ -282,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.11&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>
|
||||
```
|
||||
@@ -293,7 +295,7 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | Plugin id |
|
||||
| name | `dsh-purge` | Display name |
|
||||
| version | `1.1.10` | Semver |
|
||||
| version | `1.1.11` | 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 |
|
||||
@@ -651,7 +653,7 @@ dsh-purge --edit
|
||||
purge_status purge_apply purge_revert
|
||||
```
|
||||
|
||||
Patched packages load only after a restart. Apply does not restart by itself.
|
||||
Patched packages load only after a restart. Apply does not restart by itself. Under the patch title, **Stable** and **Beta** sit in two columns, each with its own version list.
|
||||
|
||||
The composer **Undo** button drops the last turn and puts the last user sentence back in the input. On the main agent you can rewind once or the whole last round (including subagents). After rewind, send only what is in the box now. `/rewind` does the same.
|
||||
|
||||
@@ -745,6 +747,15 @@ If nothing is found, set `DSH_BASE` / `DSH_DESKTOP_INSTALL`. No files are change
|
||||
|
||||
## Changelog
|
||||
|
||||
### 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.
|
||||
- **#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
|
||||
|
||||
- Saving or applying with both the prompt and the rule set empty is blocked and shows a dialog
|
||||
|
||||
+17
-6
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.10</strong></p>
|
||||
<p align="center"><strong>Version 1.1.11</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件:在受控本机环境评测并加固宿主安全策略,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||
@@ -67,6 +67,8 @@
|
||||
|
||||
<font color="red">
|
||||
|
||||
**免责声明:** 本项目为非营利开源项目,遵守国家法律法规及所在平台的相关规范,仅供学习与研究使用。不得将本项目用于任何违法违规用途;由此产生的后果由使用者自行承担。
|
||||
|
||||
**【零容忍严正申明】**:本项目坚决反对并严禁任何形式的违法犯罪行为!本项目开发者绝不支持、不鼓励、不协助任何未授权网络攻击、漏洞利用、数据窃取、非法侵入计算机信息系统或生成违法违禁内容的活动。**任何将本项目用于违法犯罪的行为,均与开发者无关,由行为人依法独立承担全部法律责任。**
|
||||
|
||||
1. **本仓库不含违法内容**:`dsh-purge` 发布的代码、文档、补丁与默认提示词**不是**木马、后门、未授权渗透工具、勒索软件、撞库脚本,也**不是**针对公网或第三方系统的攻击载荷。项目本身不提供违法内容,也不教唆、组织、协助实施违法犯罪。
|
||||
@@ -241,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.11&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.11&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
|
||||
```
|
||||
|
||||
**网页端(前端)触发代码示例:**
|
||||
@@ -279,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.11&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>
|
||||
```
|
||||
@@ -290,7 +292,7 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | 插件唯一标识符 |
|
||||
| name | `dsh-purge` | 插件展示名称 |
|
||||
| version | `1.1.10` | 语义化版本号 |
|
||||
| version | `1.1.11` | 语义化版本号 |
|
||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
|
||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
|
||||
@@ -651,7 +653,7 @@ dsh-purge --edit
|
||||
purge_status purge_apply purge_revert
|
||||
```
|
||||
|
||||
设置页「应用」完成后需要重启才会加载已改的包文件。点「重启」才会重启,不会自动重启。
|
||||
设置页「应用」完成后需要重启才会加载已改的包文件。点「重启」才会重启,不会自动重启。补丁标题下正式版和测试版左右分栏,各自选版本、各自切换。
|
||||
|
||||
输入框旁的「回退」会丢掉最近一轮对话,并把上一句填回输入框;聊天里 `/rewind` 同样可用。
|
||||
|
||||
@@ -732,6 +734,15 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
|
||||
|
||||
## 更新记录
|
||||
|
||||
### 1.1.11
|
||||
|
||||
- 设置页把正式版和测试版左右分开,各自选版本、各自切换和回退。还在 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
|
||||
|
||||
- 提示词和规则集都空时不能保存或应用,弹窗要求先添加提示词
|
||||
|
||||
@@ -163,16 +163,33 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"btn.checkUpdate.busy": "检测中…",
|
||||
"btn.doUpdate": "更新",
|
||||
"btn.doUpdate.busy": "更新中…",
|
||||
"channel.title": "通道",
|
||||
"channel.stable": "正式版",
|
||||
"channel.beta": "测试版",
|
||||
"channel.useStable": "切换到正式版",
|
||||
"channel.useBeta": "切换到测试版",
|
||||
"channel.now": "当前通道",
|
||||
"channel.other": "可切换",
|
||||
"update.checking": "正在检测更新…",
|
||||
"update.applying": "正在更新…",
|
||||
"update.switching": "正在切换版本…",
|
||||
"update.latest": "已是最新({version})",
|
||||
"update.available": "有新版本 {remote},当前 {local}",
|
||||
"update.pinned": "已固定在 {version},通道最新是 {remote}",
|
||||
"update.done": "已更新到 {version},请重启",
|
||||
"update.switched": "已切换到 {version},请重启",
|
||||
"update.autoDone": "已自动更新到 {version},请重启",
|
||||
"update.dirty": "有新版本,本地有改动未自动覆盖",
|
||||
"update.fail": "更新失败: {error}",
|
||||
"update.timeout": "检测超时,请再点一次检测更新",
|
||||
"update.needRestart": "检测接口未加载,请先重启 dsh 再点检测更新",
|
||||
"update.noBeta": "还没有测试版",
|
||||
"update.switch": "切换到此版本",
|
||||
"update.pick": "选择版本",
|
||||
"update.tip": "最新",
|
||||
"update.current": "当前",
|
||||
"update.confirmSwitch": "切换到 {version}?之后可再切回另一通道或其它版本。本地未提交的插件改动不会保留。",
|
||||
"update.confirmChannel": "切换到{version}?会按该通道重新安装插件,本地未提交的插件改动不会保留。",
|
||||
"metric.version": "版本",
|
||||
"action.apply": "应用",
|
||||
"action.revert": "还原",
|
||||
@@ -334,16 +351,33 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
"btn.checkUpdate.busy": "Checking…",
|
||||
"btn.doUpdate": "Update",
|
||||
"btn.doUpdate.busy": "Updating…",
|
||||
"channel.title": "Channel",
|
||||
"channel.stable": "Stable",
|
||||
"channel.beta": "Beta",
|
||||
"channel.useStable": "Switch to stable",
|
||||
"channel.useBeta": "Switch to beta",
|
||||
"channel.now": "Current channel",
|
||||
"channel.other": "Available",
|
||||
"update.checking": "Checking for updates…",
|
||||
"update.applying": "Updating…",
|
||||
"update.switching": "Switching version…",
|
||||
"update.latest": "Up to date ({version})",
|
||||
"update.available": "Update {remote} available (now {local})",
|
||||
"update.pinned": "Pinned at {version}; channel latest is {remote}",
|
||||
"update.done": "Updated to {version}. Restart to apply.",
|
||||
"update.switched": "Switched to {version}. Restart to apply.",
|
||||
"update.autoDone": "Auto-updated to {version}. Restart to apply.",
|
||||
"update.dirty": "Update available; local edits were not overwritten.",
|
||||
"update.fail": "Update failed: {error}",
|
||||
"update.timeout": "Check timed out. Click Check update again.",
|
||||
"update.needRestart": "Update API is not loaded. Restart dsh, then check again.",
|
||||
"update.noBeta": "No beta build yet",
|
||||
"update.switch": "Switch to this version",
|
||||
"update.pick": "Select version",
|
||||
"update.tip": "latest",
|
||||
"update.current": "current",
|
||||
"update.confirmSwitch": "Switch to {version}? You can switch back later. Uncommitted plugin edits will not be kept.",
|
||||
"update.confirmChannel": "Switch to {version}? The plugin will be reinstalled from that channel. Uncommitted plugin edits will not be kept.",
|
||||
"metric.version": "Version",
|
||||
"action.apply": "Apply",
|
||||
"action.revert": "Restore",
|
||||
@@ -521,6 +555,23 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
.dshp-cr-row label{display:inline-flex;align-items:center;gap:6px;color:var(--dshp-ink)}
|
||||
.dshp-cr-num{width:64px;min-width:64px;height:28px;padding:0 8px}
|
||||
.dshp-cr-text{width:120px;min-width:88px;height:28px;padding:0 8px}
|
||||
.dshp-ver{width:100%;min-width:0;max-width:none;height:34px;padding:0 10px;font-size:12px}
|
||||
.dshp-lanes{display:grid;grid-template-columns:1fr 1fr;gap:1px;margin:0 0 16px;background:var(--dshp-line);border:1px solid var(--dshp-line);border-radius:8px;overflow:hidden}
|
||||
.dshp-lane{display:flex;flex-direction:column;gap:0;min-width:0;padding:14px 14px 12px;background:var(--dshp-paper);transition:background .2s var(--dshp-ease)}
|
||||
.dshp-lane.is-on{background:var(--dshp-bg)}
|
||||
.dshp-lane-kicker{margin:0 0 4px;font-family:var(--dshp-mono);font-size:10px;letter-spacing:.16em;text-transform:uppercase;color:var(--dshp-mute)}
|
||||
.dshp-lane.is-on .dshp-lane-kicker{color:var(--dshp-accent)}
|
||||
.dshp-lane.is-beta .dshp-lane-kicker{color:var(--dshp-warn)}
|
||||
.dshp-lane.is-on.is-beta .dshp-lane-kicker{color:var(--dshp-warn)}
|
||||
.dshp-lane-h{display:flex;align-items:baseline;gap:10px;margin:0 0 12px;padding-bottom:10px;border-bottom:1px solid var(--dshp-line)}
|
||||
.dshp-lane-h strong{font-family:var(--dshp-display);font-size:18px;font-weight:500;letter-spacing:.02em}
|
||||
.dshp-lane-ver{margin-left:auto;font-family:var(--dshp-mono);font-size:12px;color:var(--dshp-mute);white-space:nowrap}
|
||||
.dshp-lane-ops{display:flex;flex-direction:column;gap:8px}
|
||||
.dshp-lane-ops .dshp-btn{width:100%}
|
||||
.dshp-rel{margin:0 0 14px}
|
||||
.dshp-rel .dshp-notice{display:block;margin-top:8px;min-height:16px}
|
||||
@media (max-width:640px){.dshp-lanes{grid-template-columns:1fr}}
|
||||
@media (prefers-reduced-motion:reduce){.dshp-lane{transition:none}}
|
||||
.dshp-area{min-height:220px;resize:vertical}
|
||||
.dshp-field:focus,.dshp-area:focus{outline:none;border-color:var(--dshp-accent);box-shadow:0 0 0 3px var(--dshp-accent-soft)}
|
||||
.dshp-field:disabled,.dshp-area:disabled{opacity:.5}
|
||||
@@ -609,7 +660,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
|
||||
function PatchGroups({ state }) {
|
||||
const t = useT();
|
||||
const [open, setOpen] = useState({ prompt: true, code: true, engine: true, tools: false, compat: true });
|
||||
const [open, setOpen] = useState({});
|
||||
if (!state || !state.patch_status) return h("div", { className: "dshp-skel", style: { height: 120 } });
|
||||
return PATCH_GROUPS.map((group) => {
|
||||
const rows = group.ids.map((id) => {
|
||||
@@ -762,9 +813,22 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const [notice, setNotice] = useState({ kind: "idle", text: "" });
|
||||
const [updateNotice, setUpdateNotice] = useState({ kind: "idle", text: "" });
|
||||
const [updateInfo, setUpdateInfo] = useState(null);
|
||||
const [canApplyUpdate, setCanApplyUpdate] = useState(false);
|
||||
const [channel, setChannel] = useState("stable");
|
||||
const [pick, setPick] = useState({ stable: "", beta: "" });
|
||||
const actionTicket = useRef(0);
|
||||
|
||||
const syncPicks = (d) => {
|
||||
const versions = (d && d.versions) || [];
|
||||
const next = { stable: "", beta: "" };
|
||||
for (const id of ["stable", "beta"]) {
|
||||
const list = versions.filter((item) => item.channel === id);
|
||||
const cur = list.find((item) => item.current);
|
||||
const latest = list.find((item) => item.latest);
|
||||
next[id] = (cur || latest || {}).ref || "";
|
||||
}
|
||||
setPick(next);
|
||||
};
|
||||
|
||||
const updateErrorText = (tr, e) => {
|
||||
const msg = String((e && e.message) || e || "");
|
||||
if (msg === "timeout" || /aborted|abort|超时/i.test(msg)) return tr("update.timeout");
|
||||
@@ -772,41 +836,78 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
return tr("update.fail", { error: msg });
|
||||
};
|
||||
|
||||
const applyUpdateInfo = useCallback((d, tr, kind) => {
|
||||
if (d.channel) setChannel(d.channel);
|
||||
setUpdateInfo(d);
|
||||
syncPicks(d);
|
||||
const version = d.localVersion || d.localSha || "—";
|
||||
const remote = d.remoteVersion || d.remoteSha || "—";
|
||||
let text = tr("update.latest", { version });
|
||||
if (d.hasUpdate) text = tr("update.available", { remote, local: version });
|
||||
if (d.pinned && d.hasUpdate) text = tr("update.pinned", { version, remote });
|
||||
if (kind === "switched") text = tr("update.switched", { version: d.localVersion || d.remoteVersion || "—" });
|
||||
if (kind === "done") text = tr("update.done", { version: d.localVersion || d.remoteVersion || "—" });
|
||||
if (d.error) text = d.error;
|
||||
setUpdateNotice({ kind: d.ok === false || d.error ? "error" : "ok", text });
|
||||
}, []);
|
||||
|
||||
const checkUpdate = useCallback(() => {
|
||||
setUpdateBusy(true);
|
||||
const tr = tRef.current;
|
||||
setUpdateNotice({ kind: "ok", text: tr("update.checking") });
|
||||
apiJson("/dsh-purge/update")
|
||||
.then((d) => {
|
||||
if (!d || !d.ok) throw new Error((d && d.error) || "check failed");
|
||||
setUpdateInfo(d);
|
||||
setCanApplyUpdate(Boolean(d.hasUpdate));
|
||||
setUpdateNotice({
|
||||
kind: "ok",
|
||||
text: d.hasUpdate
|
||||
? tr("update.available", { remote: d.remoteVersion || d.remoteSha, local: d.localVersion || d.localSha })
|
||||
: tr("update.latest", { version: d.localVersion || d.localSha || "—" }),
|
||||
});
|
||||
if (!d || (!d.ok && !d.channel)) throw new Error((d && d.error) || "check failed");
|
||||
applyUpdateInfo(d, tr);
|
||||
})
|
||||
.catch((e) => setUpdateNotice({ kind: "error", text: updateErrorText(tr, e) }))
|
||||
.finally(() => setUpdateBusy(false));
|
||||
}, []);
|
||||
}, [applyUpdateInfo]);
|
||||
|
||||
const doUpdate = useCallback(() => {
|
||||
const postUpdate = useCallback((body, kind) => {
|
||||
setUpdateBusy(true);
|
||||
const tr = tRef.current;
|
||||
setUpdateNotice({ kind: "ok", text: tr("update.applying") });
|
||||
apiJson("/dsh-purge/update", { method: "POST", headers: { "content-type": "application/json" }, body: "{}" })
|
||||
setUpdateNotice({ kind: "ok", text: kind === "switched" || kind === "channel" ? tr("update.switching") : tr("update.applying") });
|
||||
return apiJson("/dsh-purge/update", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify(body || {}),
|
||||
})
|
||||
.then((d) => {
|
||||
if (!d || !d.ok) throw new Error((d && d.error) || "update failed");
|
||||
setUpdateInfo(d);
|
||||
setCanApplyUpdate(false);
|
||||
setUpdateNotice({ kind: "ok", text: tr("update.done", { version: d.localVersion || d.remoteVersion || "—" }) });
|
||||
if (!d || (d.ok === false && d.error)) throw new Error((d && d.error) || "update failed");
|
||||
applyUpdateInfo(d, tr, kind === "channel" ? "switched" : kind);
|
||||
if (d.applied || d.needRestart) setAskRestart(true);
|
||||
return d;
|
||||
})
|
||||
.catch((e) => {
|
||||
setUpdateNotice({ kind: "error", text: updateErrorText(tr, e) });
|
||||
throw e;
|
||||
})
|
||||
.catch((e) => setUpdateNotice({ kind: "error", text: updateErrorText(tr, e) }))
|
||||
.finally(() => setUpdateBusy(false));
|
||||
}, []);
|
||||
}, [applyUpdateInfo]);
|
||||
|
||||
const doUpdate = useCallback((id) => {
|
||||
const lane = id === "beta" ? "beta" : "stable";
|
||||
postUpdate({ op: "apply", ref: lane === "beta" ? "beta" : "master", channel: lane }, "done").catch(() => {});
|
||||
}, [postUpdate]);
|
||||
|
||||
const changeChannel = useCallback((next) => {
|
||||
if (!next) return;
|
||||
const tr = tRef.current;
|
||||
if (!window.confirm(tr("update.confirmChannel", { version: tr("channel." + next) }))) return;
|
||||
postUpdate({ op: "channel", channel: next }, "channel").catch(() => {});
|
||||
}, [postUpdate]);
|
||||
|
||||
const switchSelected = useCallback((id) => {
|
||||
const tr = tRef.current;
|
||||
const ref = pick[id];
|
||||
const versions = ((updateInfo && updateInfo.versions) || []).filter((item) => item.channel === id);
|
||||
const hit = versions.find((item) => item.ref === ref);
|
||||
const label = (hit && (hit.label || hit.version)) || ref;
|
||||
if (!ref) return;
|
||||
if (!window.confirm(tr("update.confirmSwitch", { version: label }))) return;
|
||||
postUpdate({ op: "switch", ref }, "switched").catch(() => {});
|
||||
}, [pick, postUpdate, updateInfo]);
|
||||
|
||||
const loadAll = useCallback(() => {
|
||||
const tr = tRef.current;
|
||||
@@ -814,7 +915,8 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
.then((d) => {
|
||||
if (d && d.ok) {
|
||||
setState(d);
|
||||
if (d.update && d.update.ok && !d.update.error && !d.update.hasUpdate) setUpdateInfo(d.update);
|
||||
if (d.channel) setChannel(d.channel);
|
||||
if (d.update && d.update.ok && !d.update.error) setUpdateInfo(d.update);
|
||||
} else {
|
||||
setState({ ok: false, patches_total: 0, patches_applied: 0, patch_status: {}, shim_cmd: "n/a", shim_ps1: "n/a", shim_bin: "n/a", has_backup: false });
|
||||
setNotice({ kind: "error", text: tr("err.status", { error: (d && d.error) || "bad response" }) });
|
||||
@@ -824,6 +926,14 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
setState({ ok: false, patches_total: 0, patches_applied: 0, patch_status: {}, shim_cmd: "n/a", shim_ps1: "n/a", shim_bin: "n/a", has_backup: false });
|
||||
setNotice({ kind: "error", text: tr("err.status", { error: e.message }) });
|
||||
});
|
||||
apiJson("/dsh-purge/update")
|
||||
.then((d) => {
|
||||
if (!d) return;
|
||||
if (d.channel) setChannel(d.channel);
|
||||
setUpdateInfo(d);
|
||||
syncPicks(d);
|
||||
})
|
||||
.catch(() => {});
|
||||
apiJson("/dsh-purge/override")
|
||||
.then((d) => {
|
||||
if (d && d.ok) {
|
||||
@@ -1040,30 +1150,81 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
const pct = total ? Math.round((settled / total) * 100) : 0;
|
||||
|
||||
const hostSurface = hostSurfaceOf(s);
|
||||
const localVer = (s && s.plugin_version) || (updateInfo && updateInfo.localVersion) || "";
|
||||
const remoteVer = updateInfo && (updateInfo.remoteVersion || updateInfo.remoteSha) || "";
|
||||
const remoteSha = updateInfo && updateInfo.remoteSha || "";
|
||||
const sameVer = remoteVer && localVer && remoteVer === localVer;
|
||||
const versionText = canApplyUpdate && remoteVer
|
||||
? (sameVer && remoteSha ? "v" + remoteVer + " · " + remoteSha : "v" + remoteVer)
|
||||
: (localVer ? "v" + localVer : "");
|
||||
const updateBtnLabel = updateBusy
|
||||
? (canApplyUpdate ? t("btn.doUpdate.busy") : t("btn.checkUpdate.busy"))
|
||||
: (canApplyUpdate ? t("btn.doUpdate") : t("btn.checkUpdate"));
|
||||
const versions = (updateInfo && updateInfo.versions) || [];
|
||||
const channelNow = (updateInfo && updateInfo.channel) || channel || "stable";
|
||||
const renderLane = (id) => {
|
||||
const lane = (updateInfo && updateInfo.lanes && updateInfo.lanes[id]) || {};
|
||||
const list = versions.filter((item) => item.channel === id);
|
||||
const selectedRef = pick[id] || "";
|
||||
const hit = list.find((item) => item.ref === selectedRef) || list.find((item) => item.current) || list.find((item) => item.latest);
|
||||
const onLane = channelNow === id;
|
||||
const noBeta = id === "beta" && updateInfo && updateInfo.hasBeta === false && !list.length;
|
||||
const pickedOther = Boolean(hit && selectedRef && !hit.current);
|
||||
let actionLabel = t("btn.checkUpdate");
|
||||
let actionKind;
|
||||
let actionClick = checkUpdate;
|
||||
let actionDisabled = updateBusy || Boolean(noBeta);
|
||||
if (noBeta) {
|
||||
actionLabel = t("update.noBeta");
|
||||
actionClick = () => {};
|
||||
} else if (pickedOther) {
|
||||
actionLabel = t("update.switch");
|
||||
actionKind = "primary";
|
||||
actionClick = () => switchSelected(id);
|
||||
} else if (!onLane) {
|
||||
actionLabel = id === "beta" ? t("channel.useBeta") : t("channel.useStable");
|
||||
actionKind = "primary";
|
||||
actionClick = () => changeChannel(id);
|
||||
} else if (lane.hasUpdate) {
|
||||
actionLabel = t("btn.doUpdate");
|
||||
actionKind = "primary";
|
||||
actionClick = () => doUpdate(id);
|
||||
}
|
||||
if (updateBusy) {
|
||||
if (pickedOther || !onLane) actionLabel = t("update.switching");
|
||||
else if (lane.hasUpdate && onLane) actionLabel = t("btn.doUpdate.busy");
|
||||
else actionLabel = t("btn.checkUpdate.busy");
|
||||
}
|
||||
const verText = lane.version ? "v" + lane.version : (hit && hit.version ? "v" + hit.version : "—");
|
||||
return h("div", {
|
||||
className: "dshp-lane" + (onLane ? " is-on" : "") + (id === "beta" ? " is-beta" : ""),
|
||||
"aria-label": t("channel." + id),
|
||||
},
|
||||
h("p", { className: "dshp-lane-kicker" }, onLane ? t("channel.now") : t("channel.other")),
|
||||
h("div", { className: "dshp-lane-h" },
|
||||
h("strong", null, t("channel." + id)),
|
||||
h("span", { className: "dshp-lane-ver" }, verText),
|
||||
),
|
||||
h("div", { className: "dshp-lane-ops" },
|
||||
h("select", {
|
||||
className: "dshp-field dshp-ver",
|
||||
value: selectedRef || (hit && hit.ref) || "",
|
||||
disabled: updateBusy || !list.length,
|
||||
onChange: (e) => setPick((prev) => Object.assign({}, prev, { [id]: e.target.value })),
|
||||
"aria-label": t("update.pick"),
|
||||
},
|
||||
list.length
|
||||
? list.map((item) => h("option", {
|
||||
key: item.ref + (item.sha || ""),
|
||||
value: item.ref,
|
||||
}, (item.version ? "v" + item.version : item.label) + (item.current ? " · " + t("update.current") : item.latest ? " · " + t("update.tip") : "")))
|
||||
: h("option", { value: "" }, noBeta ? t("update.noBeta") : t("update.pick")),
|
||||
),
|
||||
h(Btn, { kind: actionKind, disabled: actionDisabled, onClick: actionClick }, actionLabel),
|
||||
),
|
||||
);
|
||||
};
|
||||
return h("section", { className: "dshp-panel", "aria-label": t("purge.title") },
|
||||
h("div", { className: "dshp-head" },
|
||||
h("h3", { className: "dshp-title" }, t("purge.title")),
|
||||
h("div", { className: "dshp-row", style: { margin: 0, flex: 1, justifyContent: "flex-end" } },
|
||||
h("span", { className: "dshp-pill" }, t("surface." + hostSurface)),
|
||||
versionText ? h("span", { className: "dshp-pill" + (canApplyUpdate ? " is-wait" : "") }, versionText) : null,
|
||||
h(Btn, {
|
||||
tiny: true,
|
||||
kind: canApplyUpdate ? "primary" : undefined,
|
||||
disabled: updateBusy,
|
||||
onClick: canApplyUpdate ? doUpdate : checkUpdate,
|
||||
}, updateBtnLabel),
|
||||
noticeNode(updateNotice),
|
||||
h("span", { className: "dshp-pill" }, t("surface." + hostSurface)),
|
||||
),
|
||||
h("div", { className: "dshp-rel" },
|
||||
h("div", { className: "dshp-lanes" },
|
||||
renderLane("stable"),
|
||||
renderLane("beta"),
|
||||
),
|
||||
noticeNode(updateNotice),
|
||||
),
|
||||
s ? h("div", { className: "dshp-metrics" },
|
||||
h("div", { className: "dshp-metric" },
|
||||
|
||||
+11
-1
@@ -734,7 +734,8 @@ export function pathZone(fp) {
|
||||
export function allowTargetPath(fp, surface = detectSurface()) {
|
||||
const zone = pathZone(fp);
|
||||
if (adapterFor(surface) === "desktop") {
|
||||
return zone === "desktop-install" || zone === "desktop-profile";
|
||||
// 桌面只动本机桌面树 + 共享的 $DSH_HOME/.agent-presets,不碰 Web / npm-global。
|
||||
return zone === "desktop-install" || zone === "desktop-profile" || zone === "shared";
|
||||
}
|
||||
return zone !== "desktop-install" && zone !== "desktop-profile";
|
||||
}
|
||||
@@ -2985,7 +2986,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"],
|
||||
},
|
||||
{
|
||||
@@ -3530,6 +3539,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";
|
||||
|
||||
+23
-4
@@ -175,10 +175,25 @@ export function promptAlreadyInjected(existing, injectText) {
|
||||
return String(existing || "").includes(inject);
|
||||
}
|
||||
|
||||
export function shouldInjectPrompt(_context, _injectOnce = true, _injectText = "") {
|
||||
// 0.1.5 in-history:渲染少了注入就会再追加一条 system/message。
|
||||
// 用「最后一条是否含注入」决定本步掏空注入,会 A/B 死循环。每步都必须留下完整注入。
|
||||
return true;
|
||||
export function lastInjectedSystemPrompt(context, injectText) {
|
||||
const inject = String(injectText || "").trim();
|
||||
if (!inject) return "";
|
||||
const events = eventList(context?.agent?.session || context?.session);
|
||||
let last = "";
|
||||
for (const event of events) {
|
||||
if (event?.type !== "system/message") continue;
|
||||
const text = messageText(event.data?.message || event.data).trim();
|
||||
if (text && promptAlreadyInjected(text, inject)) last = text;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
export function shouldInjectPrompt(context, _injectOnce = true, injectText = "") {
|
||||
const inject = String(injectText || "").trim();
|
||||
if (!inject) return false;
|
||||
// 只做历史探测。assemble 不要据此钉上一条 system/message 全文(#29):
|
||||
// 梁神等预设每轮还会追加 section,钉最近全文会变成「上一轮全文 + 本步新块」。
|
||||
return !lastInjectedSystemPrompt(context, inject);
|
||||
}
|
||||
|
||||
export function isMnemonPluginMessage(message) {
|
||||
@@ -198,12 +213,14 @@ function normalizeRewriteOptions(fallbackInject, options) {
|
||||
fallbackInject: typeof fallbackInject.fallbackInject === "string" ? fallbackInject.fallbackInject : "",
|
||||
dropMnemon: fallbackInject.dropMnemon !== false,
|
||||
dropPurgeAfterFold: fallbackInject.dropPurgeAfterFold !== false,
|
||||
context: fallbackInject.context,
|
||||
};
|
||||
}
|
||||
return {
|
||||
fallbackInject: typeof fallbackInject === "string" ? fallbackInject : "",
|
||||
dropMnemon: options?.dropMnemon !== false,
|
||||
dropPurgeAfterFold: options?.dropPurgeAfterFold !== false,
|
||||
context: options?.context,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -250,6 +267,8 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
}
|
||||
|
||||
const injectText = collectInjectText(purge, opts.fallbackInject);
|
||||
// #29: 不要把上一条 system/message 全文钉回 sections。
|
||||
// 「历史里已有完整注入就不再折一份」由 foldInjectIntoPersona 的 includes 幂等满足。
|
||||
const folded = foldInjectIntoPersona(rest, injectText);
|
||||
const extras = opts.dropPurgeAfterFold
|
||||
? purge.filter((section) => section.name !== "dsh-purge")
|
||||
|
||||
+94
-36
@@ -162,6 +162,14 @@ function injectSnapshotFromBox(dshHome, boxText) {
|
||||
return { injectSource: "none", injectRuleId: ruleId, needPrompt: true };
|
||||
}
|
||||
|
||||
const NEED_PROMPT_ERROR = "提示词和规则集都是空的,必须先添加提示词";
|
||||
|
||||
function rejectIfNeedPrompt(dshHome, boxText) {
|
||||
const snap = injectSnapshotFromBox(dshHome, boxText);
|
||||
if (!snap.needPrompt) return null;
|
||||
return { ...snap, error: NEED_PROMPT_ERROR };
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, _injectFile) {
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge",
|
||||
@@ -214,7 +222,7 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
if (typeof ctx.on !== "function") return;
|
||||
if (ctx.__dshPurgeAssembleHook) return;
|
||||
ctx.__dshPurgeAssembleHook = true;
|
||||
const hook = async (_assembly, _context, next) => {
|
||||
const hook = async (_assembly, context, next) => {
|
||||
const assembled = typeof next === "function" ? await next() : _assembly;
|
||||
const enabled = config.enabled !== false;
|
||||
const inject = enabled ? readInjectFallback() : "";
|
||||
@@ -222,6 +230,7 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
fallbackInject: inject,
|
||||
dropMnemon: config.stripMnemon !== false,
|
||||
dropPurgeAfterFold: true,
|
||||
context,
|
||||
});
|
||||
};
|
||||
// 只挂一次:挂多次会让同一轮 assemble 折两遍,UI 也会显示两次注入。
|
||||
@@ -302,9 +311,10 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
if (!state.ai_base) {
|
||||
return { kind: "error", text: core.missingAiBaseMessage() };
|
||||
}
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||
if (blocked) return { kind: "error", text: blocked.error };
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
await core.installOverride(state.dsh_home, false);
|
||||
const shimResult = await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const lines = report.map((r) => {
|
||||
@@ -646,9 +656,10 @@ export function apply(ctx, config) {
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
const state = await core.gatherState();
|
||||
if (!state.ai_base) return { text: "ERROR: " + core.missingAiBaseMessage() };
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||
if (blocked) return { text: "ERROR: " + blocked.error };
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
await core.installOverride(state.dsh_home, false);
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const applied = report.filter((r) => r.status === "applied").length;
|
||||
@@ -690,11 +701,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) => {
|
||||
@@ -733,13 +795,14 @@ function installWebServer(ctx, cfg) {
|
||||
dsh_home: state.dsh_home,
|
||||
plugin_version: updater.localVersion(),
|
||||
update: updater.lastUpdateResult(),
|
||||
...updater.channelPublic(),
|
||||
});
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: status");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/last-user",
|
||||
handler: async (request, response) => {
|
||||
@@ -757,7 +820,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: last user");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/rewind/options",
|
||||
handler: async (request, response) => {
|
||||
@@ -775,7 +838,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: rewind options");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/rewind",
|
||||
handler: async (request, response) => {
|
||||
@@ -815,7 +878,7 @@ function installWebServer(ctx, cfg) {
|
||||
response.end();
|
||||
},
|
||||
}, "dsh-purge: rewind");
|
||||
// host.webServer.register({
|
||||
// registerPluginRoute({
|
||||
// kind: "exact",
|
||||
// path: "/dsh-purge/continue",
|
||||
// handler: async (request, response) => {
|
||||
@@ -853,7 +916,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) => {
|
||||
@@ -882,7 +945,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) => {
|
||||
@@ -897,10 +960,7 @@ function installWebServer(ctx, cfg) {
|
||||
if (request.method === "POST") {
|
||||
try {
|
||||
const body = await readJsonBody(request);
|
||||
const result = body && body.auto
|
||||
? await updater.autoUpdateIfNeeded()
|
||||
: await updater.applyUpdate();
|
||||
sendJson(response, 200, result);
|
||||
sendJson(response, 200, await updater.handleUpdateOp(body || {}));
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
@@ -910,7 +970,7 @@ function installWebServer(ctx, cfg) {
|
||||
response.end();
|
||||
},
|
||||
}, "dsh-purge: update");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/apply",
|
||||
handler: async (request, response) => {
|
||||
@@ -930,15 +990,14 @@ function installWebServer(ctx, cfg) {
|
||||
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) {
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home, boxText);
|
||||
if (blocked) {
|
||||
sendJson(response, 400, {
|
||||
ok: false,
|
||||
needPrompt: true,
|
||||
error: "提示词和规则集都是空的,必须先添加提示词",
|
||||
override_content: boxText,
|
||||
defaultContent: ui.defaultContent,
|
||||
...snap,
|
||||
...blocked,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -975,7 +1034,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: apply");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/revert",
|
||||
handler: async (request, response) => {
|
||||
@@ -999,7 +1058,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: revert");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/uninstall",
|
||||
handler: async (request, response) => {
|
||||
@@ -1028,7 +1087,7 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: uninstall");
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/override",
|
||||
handler: async (request, response) => {
|
||||
@@ -1051,13 +1110,12 @@ function installWebServer(ctx, cfg) {
|
||||
return;
|
||||
}
|
||||
const home = core.findDshHome();
|
||||
const snap = injectSnapshotFromBox(home, content);
|
||||
if (snap.needPrompt) {
|
||||
const blocked = rejectIfNeedPrompt(home, content);
|
||||
if (blocked) {
|
||||
sendJson(response, 400, {
|
||||
ok: false,
|
||||
error: "提示词和规则集都是空的,必须先添加提示词",
|
||||
content,
|
||||
...snap,
|
||||
...blocked,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -1073,7 +1131,7 @@ function installWebServer(ctx, cfg) {
|
||||
},
|
||||
}, "dsh-purge: override");
|
||||
installRulesHttp(host.webServer);
|
||||
host.webServer.register({
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/restart",
|
||||
handler: async (request, response) => {
|
||||
@@ -1203,29 +1261,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 () => {};
|
||||
|
||||
+477
-53
@@ -9,11 +9,14 @@ import { adapterFor, detectSurface } from "./surface.js";
|
||||
import { cliInvocation } from "./desktop.js";
|
||||
|
||||
const REPO = "YuJunZhiXue/dsh-purge";
|
||||
const BRANCH = "master";
|
||||
const ZIP_URL = `https://github.com/${REPO}/archive/refs/heads/${BRANCH}.zip`;
|
||||
export const TARBALL_URL = `https://github.com/${REPO}/archive/refs/heads/${BRANCH}.tar.gz`;
|
||||
const GITHUB_SPEC = `github:${REPO}#${BRANCH}`;
|
||||
const STABLE_REF = "master";
|
||||
const BETA_REF = "beta";
|
||||
export const TARBALL_URL = `https://github.com/${REPO}/archive/refs/heads/${STABLE_REF}.tar.gz`;
|
||||
const PLUGIN_ROOT = path.resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
|
||||
const CHANNELS = {
|
||||
stable: { id: "stable", ref: STABLE_REF, label: "正式版" },
|
||||
beta: { id: "beta", ref: BETA_REF, label: "测试版" },
|
||||
};
|
||||
const COPY_NAMES = [
|
||||
"lib",
|
||||
"bin",
|
||||
@@ -47,10 +50,107 @@ export function localVersion() {
|
||||
}
|
||||
}
|
||||
|
||||
function channelStatePath() {
|
||||
return path.join(findDshHome(), "dsh-purge", "channel.json");
|
||||
}
|
||||
|
||||
function historyPath() {
|
||||
return path.join(findDshHome(), "dsh-purge", "version-history.json");
|
||||
}
|
||||
|
||||
function stampPath() {
|
||||
return path.join(findDshHome(), "dsh-purge", "installed-rev");
|
||||
}
|
||||
|
||||
export function normalizeChannel(value) {
|
||||
return String(value || "").toLowerCase() === "beta" ? "beta" : "stable";
|
||||
}
|
||||
|
||||
function isBetaName(name) {
|
||||
return /(?:^|[-._])(beta|rc|pre|preview|test)(?:\d|$|[-._])/i.test(String(name || ""));
|
||||
}
|
||||
|
||||
function splitVersion(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("-") };
|
||||
}
|
||||
|
||||
export function versionIsNewer(remote, local) {
|
||||
if (!remote) return false;
|
||||
if (!local) return true;
|
||||
if (String(remote) === String(local)) return false;
|
||||
const a = splitVersion(remote);
|
||||
const b = splitVersion(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;
|
||||
}
|
||||
|
||||
export function readChannelState() {
|
||||
const raw = readJson(channelStatePath()) || {};
|
||||
return {
|
||||
channel: normalizeChannel(raw.channel),
|
||||
pin: typeof raw.pin === "string" ? raw.pin.trim() : "",
|
||||
};
|
||||
}
|
||||
|
||||
function writeChannelState(next) {
|
||||
const state = {
|
||||
channel: normalizeChannel(next?.channel),
|
||||
pin: typeof next?.pin === "string" ? next.pin.trim() : "",
|
||||
};
|
||||
fs.mkdirSync(path.dirname(channelStatePath()), { recursive: true });
|
||||
fs.writeFileSync(channelStatePath(), `${JSON.stringify(state, null, 2)}\n`, "utf8");
|
||||
return state;
|
||||
}
|
||||
|
||||
export function channelPublic(state = readChannelState()) {
|
||||
const meta = CHANNELS[state.channel] || CHANNELS.stable;
|
||||
return {
|
||||
channel: meta.id,
|
||||
channelLabel: meta.label,
|
||||
pin: state.pin || "",
|
||||
};
|
||||
}
|
||||
|
||||
function currentChannelRef(state = readChannelState()) {
|
||||
return (CHANNELS[state.channel] || CHANNELS.stable).ref;
|
||||
}
|
||||
|
||||
function readHistory() {
|
||||
const raw = readJson(historyPath());
|
||||
return Array.isArray(raw) ? raw : [];
|
||||
}
|
||||
|
||||
function pushHistory(entry) {
|
||||
const next = [entry, ...readHistory().filter((item) => item && item.ref !== entry.ref)].slice(0, 20);
|
||||
fs.mkdirSync(path.dirname(historyPath()), { recursive: true });
|
||||
fs.writeFileSync(historyPath(), `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
function archiveZipUrl(ref) {
|
||||
const value = String(ref || STABLE_REF);
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://github.com/${REPO}/archive/${value}.zip`;
|
||||
if (/^v?\d/.test(value)) return `https://github.com/${REPO}/archive/refs/tags/${encodeURIComponent(value)}.zip`;
|
||||
return `https://github.com/${REPO}/archive/refs/heads/${encodeURIComponent(value)}.zip`;
|
||||
}
|
||||
|
||||
function archiveTarballUrl(ref) {
|
||||
const value = String(ref || STABLE_REF);
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://github.com/${REPO}/archive/${value}.tar.gz`;
|
||||
if (/^v?\d/.test(value)) return `https://github.com/${REPO}/archive/refs/tags/${encodeURIComponent(value)}.tar.gz`;
|
||||
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();
|
||||
@@ -205,15 +305,15 @@ export function runDshPlugin(profile, args) {
|
||||
});
|
||||
}
|
||||
|
||||
export function pluginAddSpec(spec) {
|
||||
export function pluginAddSpec(spec, ref = currentChannelRef()) {
|
||||
const s = String(spec || "");
|
||||
if (/\.(zip|tgz|tar\.gz)(\b|$)/i.test(s) || /^https?:\/\//i.test(s)) return TARBALL_URL;
|
||||
if (/^github:/i.test(s) || /github\.com\/.+\.git/i.test(s)) return GITHUB_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);
|
||||
return "";
|
||||
}
|
||||
|
||||
function dshReinstall(profile, spec) {
|
||||
const addSpec = pluginAddSpec(spec);
|
||||
function dshReinstall(profile, spec, ref = currentChannelRef()) {
|
||||
const addSpec = pluginAddSpec(spec, ref);
|
||||
if (addSpec) {
|
||||
runDshPlugin(profile, ["add", "--force", addSpec]);
|
||||
return;
|
||||
@@ -221,7 +321,7 @@ function dshReinstall(profile, spec) {
|
||||
try {
|
||||
runDshPlugin(profile, ["update", "dsh-purge"]);
|
||||
} catch {
|
||||
runDshPlugin(profile, ["add", "--force", TARBALL_URL]);
|
||||
runDshPlugin(profile, ["add", "--force", archiveTarballUrl(ref)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,8 +412,8 @@ function versionFromPackageText(text) {
|
||||
return pkg && pkg.version ? String(pkg.version) : "";
|
||||
}
|
||||
|
||||
async function remotePackageVersion(sha = "") {
|
||||
const ref = sha || BRANCH;
|
||||
async function remotePackageVersion(sha = "", fallbackRef = STABLE_REF) {
|
||||
const ref = sha || fallbackRef;
|
||||
const urls = [
|
||||
sha ? `https://cdn.jsdelivr.net/gh/${REPO}@${sha}/package.json` : "",
|
||||
`https://raw.githubusercontent.com/${REPO}/${ref}/package.json`,
|
||||
@@ -340,11 +440,12 @@ async function remotePackageVersion(sha = "") {
|
||||
return "";
|
||||
}
|
||||
|
||||
async function remoteHeadSha() {
|
||||
const fromApi = fetchJson(`https://api.github.com/repos/${REPO}/commits/${BRANCH}`)
|
||||
async function remoteHeadSha(ref = STABLE_REF) {
|
||||
const target = encodeURIComponent(ref || STABLE_REF);
|
||||
const fromApi = fetchJson(`https://api.github.com/repos/${REPO}/commits/${target}`)
|
||||
.then((data) => (data?.sha ? String(data.sha) : ""))
|
||||
.catch(() => "");
|
||||
const fromAtom = fetchText(`https://github.com/${REPO}/commits/${BRANCH}.atom`)
|
||||
const fromAtom = fetchText(`https://github.com/${REPO}/commits/${ref}.atom`)
|
||||
.then((atom) => {
|
||||
const hit = atom.match(/<id>tag:github\.com,2008:Grit::Commit\/([0-9a-f]{40})<\/id>/);
|
||||
return hit ? hit[1] : "";
|
||||
@@ -354,31 +455,228 @@ async function remoteHeadSha() {
|
||||
return apiSha || atomSha || "";
|
||||
}
|
||||
|
||||
export async function checkUpdate() {
|
||||
function versionLabel(version, channel, sha = "") {
|
||||
const ver = String(version || "").replace(/^v/, "") || (sha ? String(sha).slice(0, 7) : "");
|
||||
const mark = channel === "beta" ? "测试" : "正式";
|
||||
return ver ? `${ver}(${mark})` : mark;
|
||||
}
|
||||
|
||||
function rememberVersion(item, seen) {
|
||||
if (!item || !item.ref) return null;
|
||||
const key = `${item.sha || ""}|${item.ref}`.toLowerCase();
|
||||
if (seen.has(key)) return null;
|
||||
seen.add(key);
|
||||
return item;
|
||||
}
|
||||
|
||||
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 || "");
|
||||
return (versions || []).map((item) => {
|
||||
const shaHit = Boolean(localSha && item.sha && sameRev(localSha, item.sha));
|
||||
const pinHit = Boolean(pin && item.ref === pin);
|
||||
// 没有本地提交号时,只把本通道「最新」标成当前。同版本号的旧标签不能再标。
|
||||
const headHit = Boolean(
|
||||
!pin
|
||||
&& !localSha
|
||||
&& item.latest
|
||||
&& item.channel === state?.channel
|
||||
&& item.version
|
||||
&& item.version === localVer
|
||||
);
|
||||
return {
|
||||
...item,
|
||||
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
|
||||
current: shaHit || pinHit || headHit,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function listGithubTags() {
|
||||
try {
|
||||
const rows = await fetchJson(`https://api.github.com/repos/${REPO}/tags?per_page=50`);
|
||||
if (!Array.isArray(rows)) return [];
|
||||
return rows.map((row) => {
|
||||
const name = String(row?.name || "").trim();
|
||||
if (!name || !/^v?\d+\.\d+/.test(name)) return null;
|
||||
const sha = row?.commit?.sha ? String(row.commit.sha) : "";
|
||||
const channel = isBetaName(name) ? "beta" : "stable";
|
||||
return {
|
||||
id: name,
|
||||
ref: name,
|
||||
sha,
|
||||
version: name.replace(/^v/, ""),
|
||||
channel,
|
||||
label: versionLabel(name, channel, sha),
|
||||
kind: "tag",
|
||||
};
|
||||
}).filter(Boolean);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function listRemoteVersions() {
|
||||
const state = readChannelState();
|
||||
const seen = new Set();
|
||||
const out = [];
|
||||
const add = (item) => {
|
||||
const next = rememberVersion(item, seen);
|
||||
if (next) out.push(next);
|
||||
};
|
||||
|
||||
const [stableSha, betaSha, tags] = await Promise.all([
|
||||
remoteHeadSha(STABLE_REF),
|
||||
remoteHeadSha(BETA_REF),
|
||||
listGithubTags(),
|
||||
]);
|
||||
|
||||
if (stableSha) {
|
||||
const version = await remotePackageVersion(stableSha, STABLE_REF).catch(() => "");
|
||||
add({
|
||||
id: STABLE_REF,
|
||||
ref: STABLE_REF,
|
||||
sha: stableSha,
|
||||
version: version || "",
|
||||
channel: "stable",
|
||||
label: `${versionLabel(version, "stable", stableSha)} · 最新`,
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
}
|
||||
if (betaSha) {
|
||||
const version = await remotePackageVersion(betaSha, BETA_REF).catch(() => "");
|
||||
add({
|
||||
id: BETA_REF,
|
||||
ref: BETA_REF,
|
||||
sha: betaSha,
|
||||
version: version || "",
|
||||
channel: "beta",
|
||||
label: `${versionLabel(version, "beta", betaSha)} · 最新`,
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
}
|
||||
for (const tag of tags) add(tag);
|
||||
for (const item of readHistory()) {
|
||||
if (!item || !item.ref) continue;
|
||||
add({
|
||||
...item,
|
||||
label: item.label || versionLabel(item.version, item.channel, item.sha),
|
||||
kind: item.kind || "history",
|
||||
});
|
||||
}
|
||||
|
||||
const localVer = localVersion();
|
||||
const remoteSha = await remoteHeadSha();
|
||||
const remoteVer = await remotePackageVersion(remoteSha);
|
||||
if (!remoteSha && !remoteVer) throw new Error("无法读取 GitHub master");
|
||||
const localSha = (gitOk() ? gitHead(PLUGIN_ROOT) : "") || readStamp();
|
||||
return {
|
||||
versions: markCurrent(out, state, localVer, localSha),
|
||||
hasBeta: Boolean(betaSha || out.some((item) => item.channel === "beta" && item.kind === "tag")),
|
||||
stableSha,
|
||||
betaSha,
|
||||
};
|
||||
}
|
||||
|
||||
function alignChannelState(state, listed, localRev, localVer) {
|
||||
if (state.pin) return state;
|
||||
if (listed.betaSha && localRev && sameRev(localRev, listed.betaSha) && state.channel !== "beta") {
|
||||
return writeChannelState({ channel: "beta", pin: "" });
|
||||
}
|
||||
if (listed.stableSha && localRev && sameRev(localRev, listed.stableSha) && state.channel !== "stable") {
|
||||
return writeChannelState({ channel: "stable", pin: "" });
|
||||
}
|
||||
if (!localRev && localVer) {
|
||||
const inferred = isBetaName(localVer) ? "beta" : "stable";
|
||||
if (inferred !== state.channel) return writeChannelState({ channel: inferred, pin: "" });
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
function describeLane(id, listed, state, localVer, localRev) {
|
||||
const sha = id === "beta" ? listed.betaSha : listed.stableSha;
|
||||
const versions = listed.versions.filter((item) => item.channel === id);
|
||||
const latest = versions.find((item) => item.latest);
|
||||
const version = latest?.version || "";
|
||||
const onLane = state.channel === id;
|
||||
const matchesHead = Boolean(localRev && sha && sameRev(localRev, sha));
|
||||
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));
|
||||
} else if (onLane && sha && localRev) {
|
||||
hasUpdate = !sameRev(localRev, sha) || versionIsNewer(version, localVer);
|
||||
} else if (onLane && versionIsNewer(version, localVer)) {
|
||||
hasUpdate = true;
|
||||
}
|
||||
return {
|
||||
id,
|
||||
ref: CHANNELS[id].ref,
|
||||
version,
|
||||
sha: sha ? String(sha).slice(0, 7) : "",
|
||||
current,
|
||||
hasUpdate,
|
||||
hasRemote: Boolean(sha || versions.length),
|
||||
};
|
||||
}
|
||||
|
||||
function lanesOf(listed, state, localVer, localRev) {
|
||||
return {
|
||||
stable: describeLane("stable", listed, state, localVer, localRev),
|
||||
beta: describeLane("beta", listed, state, localVer, localRev),
|
||||
};
|
||||
}
|
||||
|
||||
export async function checkUpdate() {
|
||||
let state = readChannelState();
|
||||
const localVer = localVersion();
|
||||
const listed = await listRemoteVersions();
|
||||
const gitSha = gitOk() ? gitHead(PLUGIN_ROOT) : "";
|
||||
const stamp = readStamp();
|
||||
const localRev = gitSha || stamp;
|
||||
let hasUpdate = false;
|
||||
if (remoteSha && localRev) {
|
||||
hasUpdate = !sameRev(localRev, remoteSha);
|
||||
} else if (remoteVer && localVer && remoteVer !== localVer) {
|
||||
hasUpdate = true;
|
||||
} else if (remoteSha && !localRev) {
|
||||
// zip / dsh 安装没有 stamp,按有更新处理,拉一次与 master 对齐。
|
||||
hasUpdate = true;
|
||||
state = alignChannelState(state, listed, localRev, localVer);
|
||||
listed.versions = markCurrent(listed.versions, state, localVer, localRev);
|
||||
const channelRef = currentChannelRef(state);
|
||||
const lanes = lanesOf(listed, state, localVer, localRev);
|
||||
const lane = lanes[state.channel] || lanes.stable;
|
||||
if (!lane.hasRemote && state.channel === "beta") {
|
||||
return rememberUpdate({
|
||||
ok: true,
|
||||
hasUpdate: false,
|
||||
hasBeta: false,
|
||||
error: "还没有测试版",
|
||||
localVersion: localVer,
|
||||
remoteVersion: "",
|
||||
localSha: localRev ? localRev.slice(0, 7) : "",
|
||||
remoteSha: "",
|
||||
updateTarget: channelRef,
|
||||
via: detectVia(),
|
||||
versions: listed.versions,
|
||||
lanes,
|
||||
...channelPublic(state),
|
||||
});
|
||||
}
|
||||
if (!lanes.stable.hasRemote) throw new Error("无法读取 GitHub master");
|
||||
const result = {
|
||||
ok: true,
|
||||
hasUpdate,
|
||||
hasUpdate: Boolean(lane.hasUpdate),
|
||||
hasBeta: listed.hasBeta,
|
||||
updateTarget: channelRef,
|
||||
pinned: Boolean(state.pin),
|
||||
localVersion: localVer,
|
||||
remoteVersion: remoteVer || (remoteSha ? remoteSha.slice(0, 7) : ""),
|
||||
remoteVersion: lane.version || lane.sha,
|
||||
localSha: localRev ? localRev.slice(0, 7) : "",
|
||||
remoteSha: remoteSha ? remoteSha.slice(0, 7) : "",
|
||||
remoteSha: lane.sha,
|
||||
via: detectVia(),
|
||||
versions: listed.versions,
|
||||
lanes,
|
||||
...channelPublic(state),
|
||||
};
|
||||
rememberUpdate(result);
|
||||
return result;
|
||||
@@ -422,21 +720,32 @@ function runGit(dir, args, timeout = 20000) {
|
||||
}
|
||||
}
|
||||
|
||||
function gitPull(dir) {
|
||||
function gitResetTo(dir, ref, { force = false } = {}) {
|
||||
if (!force && gitTrackedDirty(dir)) {
|
||||
throw new Error("本地插件文件有未提交改动,未覆盖");
|
||||
}
|
||||
const target = safeUpdateRef(ref || STABLE_REF);
|
||||
if (!target) throw new Error("未知版本");
|
||||
try {
|
||||
runGit(dir, ["pull", "--ff-only", "origin", BRANCH], 60000);
|
||||
return;
|
||||
} catch (pullErr) {
|
||||
runGit(dir, ["fetch", "origin", "--tags"], 60000);
|
||||
} catch {
|
||||
runGit(dir, ["fetch", "origin", "--tags", target], 60000);
|
||||
}
|
||||
if (target === STABLE_REF || target === BETA_REF) {
|
||||
try {
|
||||
runGit(dir, ["fetch", "origin", BRANCH], 60000);
|
||||
runGit(dir, ["reset", "--hard", `origin/${BRANCH}`], 60000);
|
||||
runGit(dir, ["checkout", "-B", target, `origin/${target}`]);
|
||||
return;
|
||||
} catch {
|
||||
runGit(dir, ["reset", "--hard", `origin/${target}`]);
|
||||
return;
|
||||
} catch (resetErr) {
|
||||
throw new Error(
|
||||
`git 更新失败(${dir}):${String(resetErr.message || resetErr).slice(0, 240)};${String(pullErr.message || pullErr).slice(0, 160)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
try {
|
||||
runGit(dir, ["fetch", "origin", "--tags", target], 60000);
|
||||
} catch {
|
||||
// 上面已经 fetch 过全部分支。
|
||||
}
|
||||
runGit(dir, ["reset", "--hard", target]);
|
||||
}
|
||||
|
||||
function extractZip(zip, dest) {
|
||||
@@ -457,12 +766,12 @@ function extractZip(zip, dest) {
|
||||
);
|
||||
}
|
||||
|
||||
async function overlayFromZip(dests) {
|
||||
async function overlayFromZip(dests, ref = STABLE_REF) {
|
||||
const unique = [...new Set(dests.filter(Boolean).map((d) => realPath(d)))];
|
||||
if (!unique.length) return;
|
||||
const tmp = await fsp.mkdtemp(path.join(os.tmpdir(), "dsh-purge-upd-"));
|
||||
const zip = path.join(tmp, "master.zip");
|
||||
const res = await fetchRes(ZIP_URL, 45000);
|
||||
const zip = path.join(tmp, "plugin.zip");
|
||||
const res = await fetchRes(archiveZipUrl(ref), 45000);
|
||||
await fsp.writeFile(zip, Buffer.from(await res.arrayBuffer()));
|
||||
extractZip(zip, tmp);
|
||||
const names = await fsp.readdir(tmp);
|
||||
@@ -473,8 +782,16 @@ async function overlayFromZip(dests) {
|
||||
for (const dest of unique) {
|
||||
for (const name of COPY_NAMES) {
|
||||
const from = path.join(unpacked, name);
|
||||
const to = path.join(dest, name);
|
||||
if (!fs.existsSync(from)) continue;
|
||||
await fsp.cp(from, path.join(dest, name), { recursive: true, force: true });
|
||||
if (name === "lib" || name === "docs" || name === "bin") {
|
||||
try {
|
||||
await fsp.rm(to, { recursive: true, force: true });
|
||||
} catch {
|
||||
// 目录被占用时改为覆盖写入。
|
||||
}
|
||||
}
|
||||
await fsp.cp(from, to, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
try {
|
||||
@@ -484,23 +801,32 @@ async function overlayFromZip(dests) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function applyUpdate(jobs = planUpdates()) {
|
||||
export async function applyUpdate(jobs = planUpdates(), options = {}) {
|
||||
if (!Array.isArray(jobs)) {
|
||||
options = jobs && typeof jobs === "object" ? jobs : {};
|
||||
jobs = planUpdates();
|
||||
}
|
||||
const state = readChannelState();
|
||||
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();
|
||||
for (const job of jobs) {
|
||||
if (job.kind === "git") {
|
||||
try {
|
||||
gitPull(job.dir);
|
||||
gitResetTo(job.dir, ref, { force });
|
||||
vias.add("git");
|
||||
continue;
|
||||
} catch {
|
||||
} catch (e) {
|
||||
if (!force && /未提交改动/.test(String(e && e.message))) throw e;
|
||||
zipDirs.push(job.dir);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (job.kind === "dsh") {
|
||||
try {
|
||||
dshReinstall(job.profile, job.spec);
|
||||
dshReinstall(job.profile, job.spec, ref);
|
||||
vias.add("dsh");
|
||||
continue;
|
||||
} catch {
|
||||
@@ -511,29 +837,121 @@ export async function applyUpdate(jobs = planUpdates()) {
|
||||
}
|
||||
}
|
||||
if (zipDirs.length) {
|
||||
await overlayFromZip(zipDirs);
|
||||
await overlayFromZip(zipDirs, ref);
|
||||
vias.add("zip");
|
||||
}
|
||||
const sha = (await remoteHeadSha()) || (gitOk() ? gitHead(PLUGIN_ROOT) : "");
|
||||
const sha = (await remoteHeadSha(ref)) || (gitOk() ? gitHead(PLUGIN_ROOT) : "");
|
||||
if (sha) writeStamp(sha);
|
||||
const via = vias.size > 1 ? "mixed" : [...vias][0] || detectVia();
|
||||
const pin = options.pin === false ? "" : (options.pin || state.pin || "");
|
||||
const channel = normalizeChannel(options.channel || state.channel);
|
||||
const saved = writeChannelState({ channel, pin });
|
||||
const localVer = localVersion();
|
||||
pushHistory({
|
||||
ref,
|
||||
sha: sha || "",
|
||||
version: localVer,
|
||||
channel,
|
||||
label: versionLabel(localVer, channel, sha),
|
||||
at: new Date().toISOString(),
|
||||
});
|
||||
const listed = await listRemoteVersions().catch(() => ({ versions: [], hasBeta: saved.channel === "beta" }));
|
||||
return rememberUpdate({
|
||||
ok: true,
|
||||
applied: true,
|
||||
hasUpdate: false,
|
||||
localVersion: localVersion(),
|
||||
remoteVersion: localVersion(),
|
||||
hasBeta: listed.hasBeta,
|
||||
pinned: Boolean(saved.pin),
|
||||
localVersion: localVer,
|
||||
remoteVersion: localVer,
|
||||
localSha: sha ? String(sha).slice(0, 7) : "",
|
||||
remoteSha: sha ? String(sha).slice(0, 7) : "",
|
||||
needRestart: true,
|
||||
via,
|
||||
versions: listed.versions,
|
||||
lanes: lanesOf(listed, saved, localVer, sha),
|
||||
...channelPublic(saved),
|
||||
});
|
||||
}
|
||||
|
||||
export async function switchChannel(channel, { apply = true } = {}) {
|
||||
const next = normalizeChannel(channel);
|
||||
if (next === "beta") {
|
||||
const betaSha = await remoteHeadSha(BETA_REF);
|
||||
const tags = await listGithubTags();
|
||||
const hasBeta = Boolean(betaSha || tags.some((item) => item.channel === "beta"));
|
||||
if (!hasBeta) {
|
||||
return rememberUpdate({
|
||||
ok: false,
|
||||
error: "还没有测试版",
|
||||
hasBeta: false,
|
||||
...channelPublic(),
|
||||
versions: [],
|
||||
lanes: { stable: { id: "stable", hasRemote: true }, beta: { id: "beta", hasRemote: false } },
|
||||
});
|
||||
}
|
||||
if (!betaSha && apply) {
|
||||
const tag = tags.find((item) => item.channel === "beta");
|
||||
if (tag) return applyUpdate(planUpdates(), { ref: tag.ref, channel: "beta", pin: false, force: true });
|
||||
}
|
||||
}
|
||||
if (!apply) {
|
||||
writeChannelState({ channel: next, pin: "" });
|
||||
return checkUpdate();
|
||||
}
|
||||
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 = safeUpdateRef(ref);
|
||||
if (!target) throw new Error("请选择要回退的版本");
|
||||
const listed = await listRemoteVersions();
|
||||
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 });
|
||||
}
|
||||
|
||||
export async function handleUpdateOp(body = {}) {
|
||||
const op = String(body.op || (body.auto ? "auto" : "apply")).toLowerCase();
|
||||
if (op === "check" || op === "status" || op === "versions") return checkUpdate();
|
||||
if (op === "channel") return switchChannel(body.channel, { apply: body.apply !== false });
|
||||
if (op === "switch" || op === "rollback") return switchVersion(body.ref || body.version || body.id);
|
||||
if (op === "auto") return autoUpdateIfNeeded();
|
||||
const state = readChannelState();
|
||||
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 });
|
||||
}
|
||||
|
||||
export async function autoUpdateIfNeeded() {
|
||||
try {
|
||||
const check = await checkUpdate();
|
||||
if (check.pinned) return rememberUpdate({ ...check, auto: true, skipped: "pinned" });
|
||||
if (!check.hasUpdate) return rememberUpdate({ ...check, auto: true, skipped: "latest" });
|
||||
if (check.updateTarget === BETA_REF && readChannelState().channel !== "beta") {
|
||||
return rememberUpdate({ ...check, auto: true, skipped: "beta" });
|
||||
}
|
||||
const jobs = planUpdates();
|
||||
const dirtyGit = jobs.filter((j) => j.kind === "git" && gitTrackedDirty(j.dir));
|
||||
const runnable = jobs.filter((j) => !(j.kind === "git" && gitTrackedDirty(j.dir)));
|
||||
@@ -545,7 +963,12 @@ export async function autoUpdateIfNeeded() {
|
||||
error: "本地插件文件有未提交改动,未自动覆盖",
|
||||
});
|
||||
}
|
||||
const applied = await applyUpdate(runnable);
|
||||
const applied = await applyUpdate(runnable, {
|
||||
ref: currentChannelRef(),
|
||||
channel: readChannelState().channel,
|
||||
pin: false,
|
||||
force: false,
|
||||
});
|
||||
return rememberUpdate({ ...applied, auto: true });
|
||||
} catch (e) {
|
||||
return rememberUpdate({
|
||||
@@ -553,6 +976,7 @@ export async function autoUpdateIfNeeded() {
|
||||
auto: true,
|
||||
hasUpdate: false,
|
||||
error: String(e && e.message ? e.message : e),
|
||||
...channelPublic(),
|
||||
});
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.10",
|
||||
"version": "1.1.11",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
@@ -27,7 +27,9 @@
|
||||
"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"
|
||||
},
|
||||
"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,28 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { markCurrent, 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 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);
|
||||
|
||||
console.log("ok: update guards");
|
||||
Reference in new issue
Block a user