diff --git a/README.md b/README.md index 6eb8ebc..36ca620 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
Version 1.3.6
+Version 1.0.0
DeepSeek Harness jailbreak (破甲): every model can jailbreak; swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐ @@ -166,13 +166,13 @@ If the official DeepSeek Harness desktop client (EXE) is installed, the button b
🌐 Open Hub page · - 🚀 Install in desktop client + 🚀 Install in desktop client
🔗 **Raw protocol URL:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.3.6&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.zip +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.0.0&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.zip ``` **Web trigger example:** @@ -185,7 +185,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.3.6', + version: '1.0.0', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip', @@ -204,7 +204,7 @@ export function installDshPurgeToDesktop() { **HTML link:** ```html - + 🚀 Install in desktop client ``` @@ -215,7 +215,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | Plugin id | | name | `dsh-purge` | Display name | -| version | `1.3.6` | Semver | +| version | `1.0.0` | Semver | | repo | `YuJunZhiXue/dsh-purge` | GitHub repo | | permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip` | Zip URL | @@ -531,6 +531,11 @@ If nothing is found, set `DSH_BASE`. No files are changed. ## Changelog +### 1.0.0 + +- Version numbering reset. +- Settings: **Check update** reads GitHub `master`. After a push, others can install that commit (git pull, or zip overlay). Restart to load. + ### 1.3.6 (dsh 0.1.5-rc.1) - **persona schema:** 0.1.5 requires `prefix`; `#39` aliases community `text` so picking a workspace / opening a chat no longer wipes empty. diff --git a/README.zh-CN.md b/README.zh-CN.md index f391cbc..2599620 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@Version 1.3.6
+Version 1.0.0
DeepSeek Harness 破甲:让所有模型都能破甲,不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -163,13 +163,13 @@ dsh plugin --profile default remove dsh-purge
🌐 打开插件市场页 · - 🚀 唤起客户端一键安装 + 🚀 唤起客户端一键安装
🔗 **原生协议链接:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.3.6&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.zip +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.0.0&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.zip ``` **网页端(前端)触发代码示例:** @@ -182,7 +182,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.3.6', + version: '1.0.0', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip', @@ -201,7 +201,7 @@ export function installDshPurgeToDesktop() { **HTML 静态链接方式:** ```html - + 🚀 唤起客户端一键安装 ``` @@ -212,7 +212,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | 插件唯一标识符 | | name | `dsh-purge` | 插件展示名称 | -| version | `1.3.6` | 语义化版本号 | +| version | `1.0.0` | 语义化版本号 | | repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 | | permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip` | zip 下载直链 | @@ -535,6 +535,11 @@ npm 嵌套布局下,审批在 `dsh-user-approval/lib/index.js`,升级逻辑 ## 更新记录 +### 1.0.0 + +- 版本号从头计数。 +- 设置页增加 **检测更新**:对照 GitHub `master`。你推送到云端后,别人点更新即可装上该提交(git 目录走 pull,zip 安装覆盖文件),然后重启。 + ### 1.3.6(适配 dsh 0.1.5-rc.1) - **persona schema**:0.1.5 只要 `prefix`;`#39` 把社区预设的 `text` 收成别名,选工作区 / 开新对话不再被清空。 diff --git a/client.js b/client.js index 62f811d..66f295c 100644 --- a/client.js +++ b/client.js @@ -63,6 +63,15 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "btn.apply": "应用", "btn.apply.busy": "处理中…", "btn.revert": "还原", + "btn.checkUpdate": "检测更新", + "btn.checkUpdate.busy": "检测中…", + "btn.doUpdate": "更新", + "btn.doUpdate.busy": "更新中…", + "update.latest": "已是最新({version})", + "update.available": "有新版本 {remote},当前 {local}", + "update.done": "已更新到 {version},请重启", + "update.fail": "更新失败: {error}", + "metric.version": "版本", "action.apply": "应用", "action.revert": "还原", "ok.done": "已完成", @@ -170,6 +179,15 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { "btn.apply": "Apply", "btn.apply.busy": "Working…", "btn.revert": "Restore", + "btn.checkUpdate": "Check update", + "btn.checkUpdate.busy": "Checking…", + "btn.doUpdate": "Update", + "btn.doUpdate.busy": "Updating…", + "update.latest": "Up to date ({version})", + "update.available": "Update {remote} available (now {local})", + "update.done": "Updated to {version}. Restart to apply.", + "update.fail": "Update failed: {error}", + "metric.version": "Version", "action.apply": "Apply", "action.revert": "Restore", "ok.done": "Done", @@ -269,7 +287,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { .dshp-panel{border:1px solid var(--dshp-line);background:var(--dshp-paper);border-radius:10px;padding:18px 18px 16px} .dshp-kicker{font-family:var(--dshp-mono);font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--dshp-mute);margin:0 0 4px} .dshp-title{font-family:var(--dshp-display);font-size:20px;font-weight:500;letter-spacing:.02em;line-height:1.3;margin:0;color:var(--dshp-ink)} -.dshp-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px} +.dshp-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:14px;flex-wrap:wrap} .dshp-sub{display:flex;align-items:center;justify-content:space-between;gap:8px;margin:20px 0 10px} .dshp-sub h4{margin:0;font-family:var(--dshp-display);font-size:15px;font-weight:500} .dshp-metrics{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin-bottom:14px} @@ -434,6 +452,43 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { const [busy, setBusy] = useState(false); const [askRestart, setAskRestart] = useState(false); const [notice, setNotice] = useState({ kind: "idle", text: "" }); + const [updateInfo, setUpdateInfo] = useState(null); + + const checkUpdate = useCallback(() => { + setBusy(true); + setNotice({ kind: "idle", text: "" }); + const tr = tRef.current; + fetch("/dsh-purge/update", { cache: "no-store", credentials: "same-origin" }) + .then((r) => r.json()) + .then((d) => { + if (!d.ok) throw new Error(d.error || "check failed"); + setUpdateInfo(d); + setNotice({ + kind: "ok", + text: d.hasUpdate + ? tr("update.available", { remote: d.remoteVersion || d.remoteSha, local: d.localVersion || d.localSha }) + : tr("update.latest", { version: d.localVersion || "—" }), + }); + }) + .catch((e) => setNotice({ kind: "error", text: tr("update.fail", { error: e.message }) })) + .finally(() => setBusy(false)); + }, []); + + const doUpdate = useCallback(() => { + setBusy(true); + setNotice({ kind: "idle", text: "" }); + const tr = tRef.current; + fetch("/dsh-purge/update", { method: "POST", headers: { "content-type": "application/json" }, body: "{}", credentials: "same-origin" }) + .then((r) => r.json()) + .then((d) => { + if (!d.ok) throw new Error(d.error || "update failed"); + setUpdateInfo(d); + setNotice({ kind: "ok", text: tr("update.done", { version: d.localVersion || d.remoteVersion || "—" }) }); + if (d.applied || d.needRestart) setAskRestart(true); + }) + .catch((e) => setNotice({ kind: "error", text: tr("update.fail", { error: e.message }) })) + .finally(() => setBusy(false)); + }, []); const loadAll = useCallback(() => { const tr = tRef.current; @@ -536,8 +591,18 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => { const applied = s && typeof s.patches_applied === "number" ? s.patches_applied : 0; const pct = total ? Math.round((applied / total) * 100) : 0; + const version = (s && s.plugin_version) || (updateInfo && updateInfo.localVersion) || ""; return h("section", { className: "dshp-panel", "aria-label": t("purge.title") }, - h("h3", { className: "dshp-title", style: { marginBottom: 14 } }, t("purge.title")), + h("div", { className: "dshp-head" }, + h("h3", { className: "dshp-title" }, t("purge.title")), + h("div", { className: "dshp-row", style: { margin: 0 } }, + version ? h("span", { className: "dshp-pill" }, "v" + version) : null, + h(Btn, { tiny: true, disabled: busy, onClick: checkUpdate }, busy ? t("btn.checkUpdate.busy") : t("btn.checkUpdate")), + updateInfo && updateInfo.hasUpdate + ? h(Btn, { tiny: true, kind: "primary", disabled: busy, onClick: doUpdate }, busy ? t("btn.doUpdate.busy") : t("btn.doUpdate")) + : null, + ), + ), s ? h("div", { className: "dshp-metrics" }, h("div", { className: "dshp-metric" }, h("b", null, applied + " / " + total), diff --git a/lib/index.js b/lib/index.js index 3af5e36..08785a2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,6 +5,7 @@ import { spawn } from "node:child_process"; import { fileURLToPath } from "node:url"; import * as core from "./core.js"; import * as rules from "./rules.js"; +import * as updater from "./update.js"; import { GLOBAL_PROMPT_ORDER, rewritePromptAssembly, @@ -684,6 +685,7 @@ function installWebServer(ctx, cfg) { override_status: state.override_status, override_path: state.override_path, dsh_home: state.dsh_home, + plugin_version: updater.localVersion(), }); } catch (e) { sendJson(response, 500, { ok: false, error: String(e) }); @@ -818,6 +820,30 @@ function installWebServer(ctx, cfg) { } }, }, "dsh-purge: restart"); + host.webServer.register({ + kind: "exact", + path: "/dsh-purge/update", + handler: async (request, response) => { + if (request.method === "GET") { + try { + sendJson(response, 200, await updater.checkUpdate()); + } catch (e) { + sendJson(response, 500, { ok: false, error: String(e) }); + } + return; + } + if (request.method === "POST") { + try { + sendJson(response, 200, await updater.applyUpdate()); + } catch (e) { + sendJson(response, 500, { ok: false, error: String(e) }); + } + return; + } + response.writeHead(405, { allow: "GET, POST" }); + response.end(); + }, + }, "dsh-purge: update"); }, "dsh-purge: http routes"); }); } diff --git a/lib/update.js b/lib/update.js new file mode 100644 index 0000000..563e0bf --- /dev/null +++ b/lib/update.js @@ -0,0 +1,196 @@ +import { execFileSync } from "node:child_process"; +import fs from "node:fs"; +import { promises as fsp } from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { findDshHome } from "./core.js"; + +const REPO = "YuJunZhiXue/dsh-purge"; +const BRANCH = "master"; +const PLUGIN_ROOT = path.resolve(fileURLToPath(new URL(".", import.meta.url)), ".."); +const COPY_NAMES = [ + "lib", + "bin", + "docs", + "client.js", + "cordis.patch.yml", + "package.json", + "README.md", + "README.zh-CN.md", + "LICENSE", +]; + +const HIDDEN = { + encoding: "utf8", + stdio: ["ignore", "pipe", "ignore"], + windowsHide: true, + timeout: 20000, +}; + +export function pluginRoot() { + return PLUGIN_ROOT; +} + +export function localVersion() { + try { + const pkg = JSON.parse(fs.readFileSync(path.join(PLUGIN_ROOT, "package.json"), "utf8")); + return String(pkg.version || ""); + } catch { + return ""; + } +} + +function stampPath() { + return path.join(findDshHome(), "dsh-purge", "installed-rev"); +} + +function readStamp() { + try { + return fs.readFileSync(stampPath(), "utf8").trim(); + } catch { + return ""; + } +} + +function writeStamp(value) { + if (!value) return; + const fp = stampPath(); + fs.mkdirSync(path.dirname(fp), { recursive: true }); + fs.writeFileSync(fp, `${value}\n`, "utf8"); +} + +function sameRev(a, b) { + if (!a || !b) return false; + return a === b || a.startsWith(b) || b.startsWith(a); +} + +function isGitCheckout(dir) { + return fs.existsSync(path.join(dir, ".git")); +} + +function gitHead(dir) { + try { + return execFileSync("git", ["-C", dir, "rev-parse", "HEAD"], HIDDEN).trim(); + } catch { + return ""; + } +} + +async function fetchText(url) { + const res = await fetch(url, { + headers: { "user-agent": "dsh-purge-update", accept: "*/*" }, + redirect: "follow", + }); + if (!res.ok) throw new Error(`http ${res.status}`); + return res.text(); +} + +async function fetchJson(url) { + return JSON.parse(await fetchText(url)); +} + +async function remotePackageVersion() { + try { + const pkg = await fetchJson(`https://raw.githubusercontent.com/${REPO}/${BRANCH}/package.json`); + return String(pkg.version || ""); + } catch { + return ""; + } +} + +async function remoteHeadSha() { + try { + const data = await fetchJson(`https://api.github.com/repos/${REPO}/commits/${BRANCH}`); + if (data?.sha) return String(data.sha); + } catch { + // GitHub API 失败时改走 atom。 + } + try { + const atom = await fetchText(`https://github.com/${REPO}/commits/${BRANCH}.atom`); + const hit = atom.match(/