mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 17:40:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6075a782bf | ||
|
|
a576e9b817 | ||
|
|
e360fa6b70 | ||
|
|
4321b3a039 | ||
|
|
38e3bdce70 | ||
|
|
3d49ccb501 | ||
|
|
d31894a931 | ||
|
|
16fb3ff634 | ||
|
|
be6ea4bbdd | ||
|
|
fd661ec593 |
No files matched your search
@@ -1031,7 +1031,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
setState(d);
|
||||
if (d.channel) setChannel(d.channel);
|
||||
if (d.update && d.update.ok && !d.update.error) setUpdateInfo(d.update);
|
||||
if (d.boot_full_quit) setAskOfficialRestart(true);
|
||||
setAskOfficialRestart(Boolean(d.boot_full_quit));
|
||||
} 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" }) });
|
||||
@@ -1714,8 +1714,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
function keepListedVersion(item, ceiling) {
|
||||
const ver = String((item && (item.version || item.ref)) || "").replace(/^v/i, "");
|
||||
if (/^1\.1\.11-beta/i.test(ver)) return false;
|
||||
if (item && item.channel === "beta" && ceiling && !listedVersionNewer(ver, ceiling)) return false;
|
||||
return true;
|
||||
if (!item || item.channel !== "beta") return true;
|
||||
// 与 lib/update.hideListedVersion 一致:测试 tip / beta 分支始终可见(并行通道)。
|
||||
if (item.ref === "beta" || item.kind === "head" || item.latest) return true;
|
||||
if (!ceiling) return true;
|
||||
return listedVersionNewer(ver, ceiling);
|
||||
}
|
||||
|
||||
function preferListed(list, localVer) {
|
||||
@@ -2031,14 +2034,23 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
|
||||
function waitForRestart(setNotice, setBusy, t) {
|
||||
const started = Date.now();
|
||||
// 必须先看到旧进程掉线,再等新进程就绪;否则同进程立刻 200 会被当成「重启成功」又弹重启。
|
||||
let sawDown = false;
|
||||
const ping = () => {
|
||||
fetch("/dsh-purge/status", { cache: "no-store", credentials: "same-origin" })
|
||||
.then((r) => (r.ok ? r.json() : Promise.reject()))
|
||||
.then((d) => {
|
||||
if (!sawDown) {
|
||||
retry();
|
||||
return;
|
||||
}
|
||||
if (d && d.ok && d.ready !== false) reopenAfterRestart();
|
||||
else retry();
|
||||
})
|
||||
.catch(retry);
|
||||
.catch(() => {
|
||||
sawDown = true;
|
||||
retry();
|
||||
});
|
||||
};
|
||||
const retry = () => {
|
||||
if (Date.now() - started > 90000) {
|
||||
|
||||
+112
-51
@@ -313,12 +313,13 @@ export function silenceCmdFlash(aiBase = findAiBase()) {
|
||||
const customBash = silenceLiangshenCustomBashFlash();
|
||||
const phase1 = silenceLiangshenPhase1Strip();
|
||||
const mnemon = silenceMnemonGitFlash();
|
||||
// bin.js 写失败(missing_bin / ACL)不阻断 Apply。
|
||||
// bin.js 写失败(missing_bin / ACL)不阻断 Apply。源码 cli 跳过注入也算成功(#41)。
|
||||
const ok =
|
||||
process.platform !== "win32" ||
|
||||
hide.entry === "injected" ||
|
||||
hide.entry === "already_injected" ||
|
||||
hide.entry === "skipped_not_win32" ||
|
||||
hide.entry === "skipped_source_cli" ||
|
||||
hide.entry === "missing_bin" ||
|
||||
hide.entry === "sealed_asar" ||
|
||||
(typeof hide.entry === "string" && hide.entry.startsWith("error:"));
|
||||
@@ -1715,6 +1716,10 @@ const PATCHES = [
|
||||
id: 1, name: "WORKSPACE_CONTEXT_INTRO", layer: "提示词", layer_en: "Prompt",
|
||||
desc: "全局免责声明 / global disclaimer",
|
||||
file: "agent-instructions",
|
||||
// 这些补丁的替换链含"新版以旧版为前缀"的自匹配 pattern(STRONG_*_V2 是 STRONG_* 的前缀),
|
||||
// 而 markers 默认只用于报状态、不参与防重复应用 → 每次 apply 都会再叠一层(实测 +841 字符/次,永不收敛)。
|
||||
// 与 #41/#42/#45 一致,用 skipIfMarked 让 markers 真正生效。
|
||||
skipIfMarked: true,
|
||||
rel: ["lib", "index.js"],
|
||||
replacements: [
|
||||
{
|
||||
@@ -1784,6 +1789,10 @@ const PATCHES = [
|
||||
id: 2, name: "REPLACEMENT_WORKSPACE_CONTEXT_INTRO", layer: "提示词", layer_en: "Prompt",
|
||||
desc: "替换式免责 / replacement disclaimer",
|
||||
file: "agent-instructions",
|
||||
// 这些补丁的替换链含"新版以旧版为前缀"的自匹配 pattern(STRONG_*_V2 是 STRONG_* 的前缀),
|
||||
// 而 markers 默认只用于报状态、不参与防重复应用 → 每次 apply 都会再叠一层(实测 +841 字符/次,永不收敛)。
|
||||
// 与 #41/#42/#45 一致,用 skipIfMarked 让 markers 真正生效。
|
||||
skipIfMarked: true,
|
||||
rel: ["lib", "index.js"],
|
||||
replacements: [
|
||||
{
|
||||
@@ -1866,6 +1875,10 @@ const PATCHES = [
|
||||
id: 3, name: "SCOPE_INTRO", layer: "提示词", layer_en: "Prompt",
|
||||
desc: "作用域免责 / scope disclaimer",
|
||||
file: "agent-instructions",
|
||||
// 这些补丁的替换链含"新版以旧版为前缀"的自匹配 pattern(STRONG_*_V2 是 STRONG_* 的前缀),
|
||||
// 而 markers 默认只用于报状态、不参与防重复应用 → 每次 apply 都会再叠一层(实测 +841 字符/次,永不收敛)。
|
||||
// 与 #41/#42/#45 一致,用 skipIfMarked 让 markers 真正生效。
|
||||
skipIfMarked: true,
|
||||
rel: ["lib", "index.js"],
|
||||
replacements: [
|
||||
{
|
||||
@@ -3244,6 +3257,100 @@ function flattenTargetPaths(files) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 用户配置层:官方允许在 profiles/<name>/cordis.patch.yml 手写 insert,绝不能进 bak/回滚(#43)。 */
|
||||
export function isUserProfilePatchFile(fp) {
|
||||
const n = String(fp || "").replace(/\\/g, "/").toLowerCase();
|
||||
return /\/profiles\/[^/]+\/cordis\.patch\.yml$/i.test(n);
|
||||
}
|
||||
|
||||
/** 丢掉历史误建的 profile cordis.bak,不还原(保留用户当前文件)。 */
|
||||
export async function dropStaleUserProfilePatchBackups(dshHome = findDshHome()) {
|
||||
const dropped = [];
|
||||
const profilesRoot = path.join(dshHome, "profiles");
|
||||
if (!isDir(profilesRoot)) return dropped;
|
||||
let names = [];
|
||||
try {
|
||||
names = fs.readdirSync(profilesRoot, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
||||
} catch {
|
||||
return dropped;
|
||||
}
|
||||
for (const name of names) {
|
||||
const fp = path.join(profilesRoot, name, "cordis.patch.yml");
|
||||
const bak = `${fp}.dshpurge.bak`;
|
||||
if (!fs.existsSync(bak)) continue;
|
||||
try {
|
||||
await fsp.unlink(bak);
|
||||
dropped.push(bak);
|
||||
} catch {
|
||||
/* 下次再试 */
|
||||
}
|
||||
}
|
||||
return dropped;
|
||||
}
|
||||
|
||||
export async function backupAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const made = [];
|
||||
const errors = [];
|
||||
const skippedUser = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
if (!fs.existsSync(fp)) continue;
|
||||
// 用户 patch 层永不建 bak(#43)。
|
||||
if (isUserProfilePatchFile(fp)) {
|
||||
skippedUser.push(fp);
|
||||
continue;
|
||||
}
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
if (!fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(fp, bak);
|
||||
made.push(bak);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
const dropped = await dropStaleUserProfilePatchBackups();
|
||||
return { made, errors, skippedUser, dropped };
|
||||
}
|
||||
|
||||
export async function revertAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const reverted = [];
|
||||
const skipped = [];
|
||||
const preservedUser = [];
|
||||
const errors = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
// 用户 patch 层:有 bak 也只丢掉 bak,绝不 copy 回去(#43)。
|
||||
if (isUserProfilePatchFile(fp)) {
|
||||
if (fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.unlink(bak);
|
||||
preservedUser.push(fp);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(bak, fp);
|
||||
await fsp.unlink(bak);
|
||||
reverted.push(fp);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// 没有 bak 时绝不删除目标。源码部署的构建产物缺备份时,删了无法自愈(#41)。
|
||||
if (fs.existsSync(fp)) skipped.push(fp);
|
||||
}
|
||||
const dropped = await dropStaleUserProfilePatchBackups();
|
||||
return { reverted, skipped, preservedUser, dropped, errors };
|
||||
}
|
||||
|
||||
function nestedPkg(aiBase, pkg, ...rel) {
|
||||
return [
|
||||
path.join(aiBase, pkg, ...rel),
|
||||
@@ -3279,7 +3386,6 @@ function filterTargetFiles(files) {
|
||||
|
||||
export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
const root = packageRootFromAiBase(aiBase);
|
||||
const desktopHost = adapterFor(detectSurface()) === "desktop";
|
||||
const files = {
|
||||
"agent-instructions": firstExisting([
|
||||
path.join(aiBase, "dsh-agent-instructions", "lib", "index.js"),
|
||||
@@ -3300,17 +3406,9 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
...(root ? [path.join(root, "packages", "bundle", "headless", "cordis.patch.yml")] : []),
|
||||
]),
|
||||
"desktop-shell": officialShellMain(),
|
||||
"profile-web": firstExisting(desktopHost
|
||||
? [
|
||||
path.join(dshHome, "profiles", "desktop", "cordis.patch.yml"),
|
||||
path.join(aiBase, "dsh-web-app", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "web-app", "cordis.patch.yml")] : []),
|
||||
]
|
||||
: [
|
||||
path.join(dshHome, "profiles", "web", "cordis.patch.yml"),
|
||||
path.join(aiBase, "dsh-web-app", "cordis.patch.yml"),
|
||||
...(root ? [path.join(root, "packages", "bundle", "web-app", "cordis.patch.yml")] : []),
|
||||
]),
|
||||
// 注意:不要把 profiles/<name>/cordis.patch.yml 放进 targetFiles。
|
||||
// 那是官方文档支持的「用户 patch 层」,本插件没有任何补丁写入它;
|
||||
// 一旦进 backupAll/revertAll,版本升级自愈会把用户后来追加的 insert 盖掉(#43)。
|
||||
"agent-preset": firstExisting([
|
||||
...userPresetYml(dshHome, "unrestricted"),
|
||||
...shippedPresetYml(root, "standard", aiBase),
|
||||
@@ -3986,47 +4084,10 @@ export async function patchStatus(aiBase, patches = ALL_PATCHES) {
|
||||
return status;
|
||||
}
|
||||
|
||||
export async function backupAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const made = [];
|
||||
const errors = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
if (!fs.existsSync(fp)) continue;
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
if (!fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(fp, bak);
|
||||
made.push(bak);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { made, errors };
|
||||
}
|
||||
|
||||
export async function revertAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const reverted = [];
|
||||
const errors = [];
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
const bak = fp + ".dshpurge.bak";
|
||||
if (fs.existsSync(bak)) {
|
||||
try {
|
||||
await fsp.copyFile(bak, fp);
|
||||
await fsp.unlink(bak);
|
||||
reverted.push(fp);
|
||||
} catch (e) {
|
||||
errors.push([fp, String(e)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { reverted, errors };
|
||||
}
|
||||
|
||||
export async function hasBackup(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
for (const fp of flattenTargetPaths(files)) {
|
||||
if (isUserProfilePatchFile(fp)) continue;
|
||||
if (fs.existsSync(fp + ".dshpurge.bak")) return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
+35
-1
@@ -176,6 +176,26 @@ function ioFor(explicit, targetPath) {
|
||||
return explicit ?? fsFor(targetPath);
|
||||
}
|
||||
|
||||
/** 源码 monorepo 的 apps/cli(tsdown 构建产物)。往这里注入/还原会动构建输出,缺 bak 时无法自愈(#41)。 */
|
||||
export function looksLikeSourceCliRoot(root, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
if (!root) return false;
|
||||
const n = String(root).replace(/\\/g, "/").toLowerCase();
|
||||
if (/\/apps\/cli\/?$/.test(n)) return true;
|
||||
if (/\/node_modules\//.test(n)) return false;
|
||||
try {
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const libDir = p.join(root, "lib");
|
||||
if (nodeFs.existsSync(p.join(libDir, "tsconfig.tsbuildinfo"))) return true;
|
||||
if (nodeFs.existsSync(p.join(root, "tsdown.config.ts")) || nodeFs.existsSync(p.join(root, "tsdown.config.mjs"))) {
|
||||
return true;
|
||||
}
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
const tries = [];
|
||||
@@ -196,6 +216,16 @@ export function resolveDshBinRoot(hint, { fs, path: nodePath } = {}) {
|
||||
if (typeof process.argv[1] === "string" && /[\\/]bin\.js$/i.test(process.argv[1])) {
|
||||
push(p.dirname(p.dirname(process.argv[1])));
|
||||
}
|
||||
for (const root of tries) {
|
||||
try {
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
if (isAsarSealedPath(root) || isAsarSealedPath(binJs)) continue;
|
||||
// 源码树只作探测候选的最后手段;优先 node_modules 包,避免改写 apps/cli/lib(#41)。
|
||||
if (looksLikeSourceCliRoot(root, { fs, path: p })) continue;
|
||||
if (ioFor(fs, binJs).existsSync(binJs)) return p.normalize(root);
|
||||
} catch {}
|
||||
}
|
||||
// 没有包装配路径时,才回退到 argv 指向的源码 cli(仍禁止注入,见 installHideConsoleIntoBin)。
|
||||
for (const root of tries) {
|
||||
try {
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
@@ -213,6 +243,8 @@ export function installHideConsoleIntoBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
const root = resolveDshBinRoot(aiBase, { fs, path: p });
|
||||
if (!root) return "missing_bin";
|
||||
// 源码部署的 apps/cli/lib 是 tsdown 产物:只准读、不准写 sidecar / 改 bin.js(#41)。
|
||||
if (looksLikeSourceCliRoot(root, { fs, path: p })) return "skipped_source_cli";
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
const side = p.join(root, "lib", `${IMPORT_MARK}.js`);
|
||||
@@ -248,12 +280,14 @@ export function revertHideConsoleFromBin(aiBase, { fs, path: nodePath } = {}) {
|
||||
const p = nodePath ?? requirePath();
|
||||
const root = resolveDshBinRoot(aiBase, { fs, path: p });
|
||||
if (!root) return "missing_bin";
|
||||
// 源码 cli:只清理本插件留下的 sidecar,绝不改/删 bin.js 或其它构建产物(#41)。
|
||||
const sourceCli = looksLikeSourceCliRoot(root, { fs, path: p });
|
||||
const nodeFs = ioFor(fs, root);
|
||||
const binJs = p.join(root, "lib", "bin.js");
|
||||
const side = p.join(root, "lib", `${IMPORT_MARK}.js`);
|
||||
const facadeSide = p.join(root, "lib", "dsh-purge-child-process-hide.mjs");
|
||||
let changed = false;
|
||||
if (nodeFs.existsSync(binJs)) {
|
||||
if (!sourceCli && nodeFs.existsSync(binJs)) {
|
||||
try {
|
||||
const text = nodeFs.readFileSync(binJs, "utf8");
|
||||
const next = text.replace(/^import "\.\/dsh-purge-hide-console\.js";.*\r?\n/gm, "");
|
||||
|
||||
@@ -1232,6 +1232,8 @@ function installWebServer(ctx, cfg) {
|
||||
pendingQuit = Boolean(swapped?.pending);
|
||||
}
|
||||
const leaveTray = renamed || pendingQuit;
|
||||
if (complete) reapply.markPatchesApplied();
|
||||
if (leaveTray) bootFullQuit = true;
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
complete,
|
||||
@@ -1371,6 +1373,8 @@ function installWebServer(ctx, cfg) {
|
||||
try {
|
||||
const surface = hostctl.currentSurface();
|
||||
const planned = hostctl.scheduleRestart(request, ctx);
|
||||
// 用户已点重启:清掉粘性标记,避免同进程误刷新/再进面板又弹一次。
|
||||
bootFullQuit = false;
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
surface,
|
||||
|
||||
+7
-1
@@ -64,6 +64,11 @@ function writeAppliedStamp(sha) {
|
||||
}, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
/** 手动「应用」成功后也要打戳,否则重启后 settle 会以为补丁未对齐再要求重启。 */
|
||||
export function markPatchesApplied(sha) {
|
||||
writeAppliedStamp(sha == null ? installedRev() : sha);
|
||||
}
|
||||
|
||||
/**
|
||||
* 先把宿主文件从备份还原,再按当前这份插件的补丁重写。
|
||||
* 低版本带着自己的补丁列表,高版本带着自己的;回退到哪一版就打哪一版。
|
||||
@@ -103,6 +108,7 @@ export async function reapplyInstalled(options = {}) {
|
||||
}
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
writeAppliedStamp(installedRev());
|
||||
const pending = Boolean(handoff?.asar && !renamed && options.scheduleSwap !== false);
|
||||
return {
|
||||
ok: true,
|
||||
version: pluginVersion(),
|
||||
@@ -110,7 +116,7 @@ export async function reapplyInstalled(options = {}) {
|
||||
applied: summary.applied || 0,
|
||||
failed: summary.failed.length,
|
||||
renamed,
|
||||
needsFullQuit: renamed || core.officialHostMustStayUp(),
|
||||
needsFullQuit: renamed || pending || core.officialHostMustStayUp(),
|
||||
cmdFlashOk: flash.ok === true,
|
||||
};
|
||||
}
|
||||
+6
-3
@@ -18,15 +18,18 @@ function exeName(execPath) {
|
||||
export function pathLooksDesktop(p) {
|
||||
const n = slash(p);
|
||||
if (!n) return false;
|
||||
// 安装目录可能叫 "DeepSeek Harness" / "deepseek-harness",但源码仓库(monorepo)也叫这个名字 ——
|
||||
// 所以只凭目录名不算,还必须带桌面安装形态(resources/、exe、.app/)。与 desktop.looksLikeDesktopName 对齐。
|
||||
const harnessDir = n.includes("/deepseek harness/") || n.includes("/deepseek-harness/");
|
||||
return (
|
||||
n.includes("/dsh desktop/") ||
|
||||
n.includes("/dsh desktop.app/") ||
|
||||
n.includes("dsh-desktop") ||
|
||||
n.includes("dsh-plugin-desktop") ||
|
||||
n.includes("/deepseek harness/") ||
|
||||
n.includes("deepseek-harness") ||
|
||||
n.includes("/deepseek harness.app/") ||
|
||||
(harnessDir && (n.includes("/resources/") || n.includes("/contents/resources/") || n.endsWith("/resources"))) ||
|
||||
/\/dsh desktop\.exe$/i.test(n) ||
|
||||
/\/deepseek harness\.exe$/i.test(n) ||
|
||||
/\/deepseek[- ]harness\.exe$/i.test(n) ||
|
||||
n.endsWith("/host-process-entry.js") ||
|
||||
n.endsWith("/desktop-cli.js")
|
||||
);
|
||||
|
||||
+46
-16
@@ -11,7 +11,7 @@ import { cliInvocation } from "./desktop.js";
|
||||
const REPO = "YuJunZhiXue/dsh-purge";
|
||||
const STABLE_REF = "master";
|
||||
const BETA_REF = "beta";
|
||||
export const TARBALL_URL = `https://github.com/${REPO}/archive/refs/heads/${STABLE_REF}.tar.gz`;
|
||||
export const TARBALL_URL = `https://codeload.github.com/${REPO}/tar.gz/refs/heads/${STABLE_REF}`;
|
||||
const PLUGIN_ROOT = path.resolve(fileURLToPath(new URL(".", import.meta.url)), "..");
|
||||
const CHANNELS = {
|
||||
stable: { id: "stable", ref: STABLE_REF, label: "正式版" },
|
||||
@@ -107,11 +107,14 @@ export function latestStableVersion(versions) {
|
||||
return best;
|
||||
}
|
||||
|
||||
/** 正式版已经追上的测试版不再列出。1.1.11-beta 始终下线。 */
|
||||
/** 正式版已经追上的旧测试版标签不再列出。1.1.11-beta 始终下线。
|
||||
* 正式/测试是并行通道(测试带红队等),beta 分支 tip 始终保留,避免 1.1.25 正式把 1.1.25-beta 整通道藏掉。 */
|
||||
export function hideListedVersion(item, stableVersion = "") {
|
||||
if (!item || withdrawnVersion(item)) return true;
|
||||
const beta = item.channel === "beta" || isBetaName(item.version) || isBetaName(item.ref) || isBetaName(item.id);
|
||||
if (!beta) return false;
|
||||
// 并行测试通道 tip:始终可见。
|
||||
if (item.ref === BETA_REF || item.kind === "head") return false;
|
||||
const ceiling = String(stableVersion || "").replace(/^v/i, "");
|
||||
if (!ceiling || isBetaName(ceiling)) return false;
|
||||
const ver = String(item.version || item.ref || item.id || "").replace(/^v/i, "");
|
||||
@@ -162,18 +165,19 @@ function pushHistory(entry) {
|
||||
fs.writeFileSync(historyPath(), `${JSON.stringify(next, null, 2)}\n`, "utf8");
|
||||
}
|
||||
|
||||
/** 直连 codeload,避免 github.com/archive → 302 在 Electron/部分 Node 下变成 http 302 / fetch failed。 */
|
||||
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`;
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://codeload.github.com/${REPO}/zip/${value}`;
|
||||
if (/^v?\d/.test(value)) return `https://codeload.github.com/${REPO}/zip/refs/tags/${encodeURIComponent(value)}`;
|
||||
return `https://codeload.github.com/${REPO}/zip/refs/heads/${encodeURIComponent(value)}`;
|
||||
}
|
||||
|
||||
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`;
|
||||
if (/^[0-9a-f]{40}$/i.test(value)) return `https://codeload.github.com/${REPO}/tar.gz/${value}`;
|
||||
if (/^v?\d/.test(value)) return `https://codeload.github.com/${REPO}/tar.gz/refs/tags/${encodeURIComponent(value)}`;
|
||||
return `https://codeload.github.com/${REPO}/tar.gz/refs/heads/${encodeURIComponent(value)}`;
|
||||
}
|
||||
|
||||
function readStamp() {
|
||||
@@ -417,14 +421,25 @@ async function fetchRes(url, ms = 20000, headers = {}) {
|
||||
}
|
||||
}, ms);
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
headers: { "user-agent": "dsh-purge-update", accept: "*/*", ...headers },
|
||||
redirect: "follow",
|
||||
cache: "no-store",
|
||||
signal: ctrl.signal,
|
||||
});
|
||||
if (!res.ok) throw new Error(`http ${res.status}`);
|
||||
return res;
|
||||
let current = String(url || "");
|
||||
for (let hop = 0; hop < 6; hop += 1) {
|
||||
const res = await fetch(current, {
|
||||
headers: { "user-agent": "dsh-purge-update", accept: "*/*", ...headers },
|
||||
// 手动跟跳转:部分宿主对 github.com → codeload 跨域 302 不会自动 follow,会直接抛 http 302。
|
||||
redirect: "manual",
|
||||
cache: "no-store",
|
||||
signal: ctrl.signal,
|
||||
});
|
||||
if ([301, 302, 303, 307, 308].includes(res.status)) {
|
||||
const loc = res.headers.get("location");
|
||||
if (!loc) throw new Error(`http ${res.status}`);
|
||||
current = new URL(loc, current).href;
|
||||
continue;
|
||||
}
|
||||
if (!res.ok) throw new Error(`http ${res.status}`);
|
||||
return res;
|
||||
}
|
||||
throw new Error("http redirect loop");
|
||||
} catch (e) {
|
||||
if (isAbortError(e)) throw new Error("GitHub 超时");
|
||||
throw e;
|
||||
@@ -628,6 +643,21 @@ async function listRemoteVersions() {
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
} else {
|
||||
// API/atom 拿不到 tip 时,仍用 raw/jsDelivr 探一下 beta 分支,避免测试通道整栏空白。
|
||||
const version = await remotePackageVersion("", BETA_REF).catch(() => "");
|
||||
if (version) {
|
||||
add({
|
||||
id: BETA_REF,
|
||||
ref: BETA_REF,
|
||||
sha: "",
|
||||
version,
|
||||
channel: "beta",
|
||||
label: `${versionLabel(version, "beta")} · 最新`,
|
||||
kind: "head",
|
||||
latest: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const tag of tags) {
|
||||
if (!withdrawnVersion(tag)) add(tag);
|
||||
|
||||
+5
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.22",
|
||||
"version": "1.1.28",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
@@ -31,7 +31,10 @@
|
||||
"test:identity": "node scripts/test-identity-assembly.mjs",
|
||||
"test:yaml": "node scripts/test-yaml-comment.mjs",
|
||||
"test:update": "node scripts/test-update-guards.mjs",
|
||||
"test:rewind": "node scripts/test-rewind-plan.mjs"
|
||||
"test:rewind": "node scripts/test-rewind-plan.mjs",
|
||||
"test:idempotence": "node scripts/test-patch-idempotence.mjs",
|
||||
"test:surface": "node scripts/test-surface-desktop.mjs",
|
||||
"test:profile-patch": "node scripts/test-user-profile-patch.mjs"
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
|
||||
@@ -1,3 +1,82 @@
|
||||
# 1.1.28
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复更新失败 `http 302`**:下载改为直连 `codeload.github.com`,并手动跟随跳转,避免 Electron/部分 Node 对 github.com → codeload 的 302 处理失败。
|
||||
- **修复测试版列表空白**:前端 `keepListedVersion` 与后端一致,正式版已发布时仍保留 beta tip / `beta` 分支;tip SHA 拉不到时回退 raw/jsDelivr 探测。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix update failure `http 302`**: download via `codeload.github.com` and follow redirects manually so Electron/some Node builds no longer stall on github.com → codeload 302.
|
||||
- **Fix empty beta list**: client `keepListedVersion` matches the server — keep the beta tip / `beta` branch after stable ships; fall back to raw/jsDelivr when tip SHA cannot be fetched.
|
||||
|
||||
# 1.1.27
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复应用重启后进规则设定仍弹「需要重启」**:手动「应用」成功后写入 `applied` 戳,重启后 settle 不再误判补丁未对齐。
|
||||
- 点「重启」清掉 `boot_full_quit` 粘性标记;status 按布尔值同步弹窗。
|
||||
- web `waitForRestart` 必须先看到旧进程掉线再判定成功,避免同进程误刷新又弹窗。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix restart prompt still showing after Apply + successful restart**: write the `applied` stamp on successful manual Apply so settle does not think patches are out of date.
|
||||
- Clear sticky `boot_full_quit` when Restart is clicked; status syncs the modal from the boolean.
|
||||
- Web `waitForRestart` requires the old process to go down before treating restart as success, avoiding same-process false refresh.
|
||||
|
||||
# 1.1.26
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复测试通道被正式版同号藏掉**:`1.1.25` 正式发布后,`1.1.25-beta.*` 因「正式已追上」逻辑整通道不可见;现 **beta 分支 tip 始终列出**(正式/测试并行,测试带红队)。
|
||||
- 已追上的旧 beta **标签**仍会隐藏;`1.1.11-beta` 仍下线。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix beta lane hidden by same-number stable**: after `1.1.25` stable, `1.1.25-beta.*` vanished via the “stable caught up” filter; the **beta branch tip always stays listed** (parallel channels; beta carries red-team).
|
||||
- Older caught-up beta **tags** still hide; `1.1.11-beta` stays withdrawn.
|
||||
# 1.1.25
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复 [#43](https://github.com/YuJunZhiXue/dsh-purge/issues/43)**:不再把 `profiles/*/cordis.patch.yml`(用户 patch 层)纳入 `backupAll`/`revertAll`;升级自愈时不会用旧 bak 覆盖用户后来追加的 `insert`。
|
||||
- 启动/还原时主动丢掉历史上误建的 `cordis.patch.yml.dshpurge.bak`,保留当前用户文件。
|
||||
- 新增 `npm run test:profile-patch`。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix [#43](https://github.com/YuJunZhiXue/dsh-purge/issues/43)**: stop including `profiles/*/cordis.patch.yml` (user patch layer) in `backupAll`/`revertAll`, so upgrade reapply no longer restores an old bak over later user `insert`s.
|
||||
- Drop stale `cordis.patch.yml.dshpurge.bak` without restoring; keep the live user file.
|
||||
- Add `npm run test:profile-patch`.
|
||||
# 1.1.24
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复 [#40](https://github.com/YuJunZhiXue/dsh-purge/issues/40)**:`pathLooksDesktop` 不再仅凭路径里的 `deepseek-harness` 子串把源码版判成桌面端;需带 `resources/` / `.exe` / `.app` 等安装形态。
|
||||
- **修复 [#41](https://github.com/YuJunZhiXue/dsh-purge/issues/41)**:源码部署的 `apps/cli`(tsdown 构建产物)禁止 hide-console 注入;`revertAll` 在无 `.dshpurge.bak` 时只跳过、绝不删除目标文件。
|
||||
- 新增 `npm run test:surface` 回归。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix [#40](https://github.com/YuJunZhiXue/dsh-purge/issues/40)**: `pathLooksDesktop` no longer treats source trees as desktop just because the path contains `deepseek-harness`; require install shapes (`resources/`, `.exe`, `.app`).
|
||||
- **Fix [#41](https://github.com/YuJunZhiXue/dsh-purge/issues/41)**: skip hide-console injection into source `apps/cli` build output; `revertAll` never deletes targets when `.dshpurge.bak` is missing.
|
||||
- Add `npm run test:surface`.
|
||||
# 1.1.23
|
||||
|
||||
## 中文
|
||||
|
||||
- **修复 [#38](https://github.com/YuJunZhiXue/dsh-purge/issues/38)**:`#1`/`#2`/`#3` 提示词补丁每次 `apply` 叠加约 +841 字符、永不收敛。
|
||||
- **原因**:替换产物仍以前一版文本为前缀,且未设 `skipIfMarked`,`autoApplyOnStart` 每轮都会再写一层。
|
||||
- **修复**:为 `#1`/`#2`/`#3` 补 `skipIfMarked: true`([#42](https://github.com/YuJunZhiXue/dsh-purge/pull/42)),并加 `npm run test:idempotence` 回归。
|
||||
- 已膨胀的宿主文件不会自动缩回,需还原 `.dshpurge.bak` 或重装 dsh 后再 apply。
|
||||
|
||||
## English
|
||||
|
||||
- **Fix [#38](https://github.com/YuJunZhiXue/dsh-purge/issues/38)**: prompt patches `#1`/`#2`/`#3` grew by ~+841 chars on every `apply` and never converged.
|
||||
- **Cause**: replacement text still starts with the previous pattern, and `skipIfMarked` was missing, so `autoApplyOnStart` rewrote every boot.
|
||||
- **Fix**: set `skipIfMarked: true` on `#1`/`#2`/`#3` ([#42](https://github.com/YuJunZhiXue/dsh-purge/pull/42)); add `npm run test:idempotence`.
|
||||
- Already-bloated host files are not auto-shrunk — restore `.dshpurge.bak` or reinstall dsh, then apply again.
|
||||
|
||||
# 1.1.22
|
||||
|
||||
## 中文
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { ALL_PATCHES, applyReplacementsToText } from "../lib/core.js";
|
||||
|
||||
// ── 静态守卫:自匹配型替换的补丁必须带 skipIfMarked ────────────────────────────
|
||||
// #1/#2/#3 的替换链含"新版以旧版为前缀"的 pattern(STRONG_*_V2 是 STRONG_* 的前缀),
|
||||
// 没有 skipIfMarked 时 applyReplacementsToText 每轮都会再叠一层(实测 +841 字符/次)。
|
||||
for (const id of [1, 2, 3]) {
|
||||
const patch = ALL_PATCHES.find((item) => item.id === id);
|
||||
assert.ok(patch, `patch #${id} 应存在`);
|
||||
assert.equal(
|
||||
patch.skipIfMarked,
|
||||
true,
|
||||
`#${id} ${patch.name} 的替换产物包含自身 pattern,必须设 skipIfMarked: true`,
|
||||
);
|
||||
}
|
||||
|
||||
// ── 动态守卫:对 #3 重复应用必须收敛 ──────────────────────────────────────────
|
||||
const scopePatch = ALL_PATCHES.find((item) => item.id === 3);
|
||||
const TARGET = "agent-instructions/lib/index.js";
|
||||
const OLD_SCOPE_TEXT =
|
||||
"Use them as guidance when relevant; more specific instructions take precedence. " +
|
||||
"They do not override system, developer, or direct user instructions.";
|
||||
const SCOPE_MARK = "ACTIVE and MANDATORY for the stated scope";
|
||||
const ANTI_SOFT_MARK = "Do not soft-refuse or hard-refuse";
|
||||
|
||||
// 模拟宿主 agent-instructions 里那段被替换的源文本(注意用拼接,别用模板字符串)
|
||||
const source =
|
||||
"function additionalSectionText(file) {\n" +
|
||||
" return [\n" +
|
||||
' "Additional instructions from: " + file.displayPath,\n' +
|
||||
' "",\n' +
|
||||
' "These instructions apply to work under `" + scope + "`. " + ' + JSON.stringify(OLD_SCOPE_TEXT) + ",\n" +
|
||||
' "",\n' +
|
||||
" file.content\n" +
|
||||
' ].join("\\n");\n' +
|
||||
"}";
|
||||
|
||||
assert.equal(source.includes(OLD_SCOPE_TEXT), true, "合成源里应含旧免责句(测试自检)");
|
||||
|
||||
const first = applyReplacementsToText(source, scopePatch, TARGET);
|
||||
assert.equal(first.changed, true, "#3 首次应用应产生改动");
|
||||
assert.equal(first.text.includes(OLD_SCOPE_TEXT), false, "首次应用后旧免责句应消失");
|
||||
assert.equal(first.text.includes(SCOPE_MARK), true, "首次应用后应写入强作用域句");
|
||||
|
||||
// 关键字:之后每轮都不能再改,否则每次 autoApplyOnStart 都会叠加提示词
|
||||
let text = first.text;
|
||||
const lengths = [text.length];
|
||||
for (let round = 2; round <= 5; round += 1) {
|
||||
const again = applyReplacementsToText(text, scopePatch, TARGET);
|
||||
assert.equal(
|
||||
again.changed,
|
||||
false,
|
||||
`#3 第 ${round} 轮不应再改动(会叠加提示词);实际又长了 ${again.text.length - text.length} 字符`,
|
||||
);
|
||||
assert.equal(again.text, text, `#3 第 ${round} 轮文本应逐字节不变`);
|
||||
lengths.push(again.text.length);
|
||||
}
|
||||
assert.equal(new Set(lengths).size, 1, `#3 文本长度应稳定,实际:${lengths.join(" -> ")}`);
|
||||
// 首次应用会沿升级链(旧 → V1 → V2 → 最新)合法地补上尾巴,因此只断言"之后不再增长":
|
||||
assert.equal(
|
||||
lengths[0],
|
||||
lengths[lengths.length - 1],
|
||||
"收敛后长度必须与首轮一致(增长即为叠加回归)",
|
||||
);
|
||||
|
||||
// ── 对照:摘掉 skipIfMarked 时应能复现叠加,证明本测试确实覆盖到该回归 ──────────
|
||||
const unguarded = { ...scopePatch, skipIfMarked: undefined, markers: undefined, markersAny: undefined };
|
||||
let probe = first.text;
|
||||
let grew = 0;
|
||||
for (let round = 1; round <= 3; round += 1) {
|
||||
const r = applyReplacementsToText(probe, unguarded, TARGET);
|
||||
if (!r.changed) break;
|
||||
grew += r.text.length - probe.length;
|
||||
probe = r.text;
|
||||
}
|
||||
assert.ok(grew > 0, "对照:无 skipIfMarked 时应复现叠加");
|
||||
|
||||
console.log("ok: patch idempotence (skipIfMarked)");
|
||||
console.log(` #3 收敛长度=${lengths[0]} 无守卫时 3 轮累计增长=${grew} 字符`);
|
||||
@@ -0,0 +1,77 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { pathLooksDesktop, detectSurface } from "../lib/surface.js";
|
||||
import { looksLikeSourceCliRoot, installHideConsoleIntoBin } from "../lib/hide-console.js";
|
||||
|
||||
// #40:源码仓库路径不能仅因目录名 deepseek-harness 被判成桌面端
|
||||
assert.equal(
|
||||
pathLooksDesktop("/home/me/deepseek-harness/apps/cli/lib/bin.js"),
|
||||
false,
|
||||
"源码 cli 路径不应命中 pathLooksDesktop",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("/home/me/deepseek-harness/node_modules/@deepseek-ai/dsh/lib/bin.js"),
|
||||
false,
|
||||
"源码树里的 node_modules 也不应仅凭目录名判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
detectSurface({
|
||||
argv: ["/usr/bin/node", "/home/me/deepseek-harness/apps/cli/lib/bin.js"],
|
||||
execPath: "/usr/bin/node",
|
||||
env: {},
|
||||
}),
|
||||
"web",
|
||||
"源码版 argv 应判为 web",
|
||||
);
|
||||
|
||||
// 官方桌面安装形态仍应命中
|
||||
assert.equal(
|
||||
pathLooksDesktop("C:/DeepSeek Harness/resources/app.asar/node_modules/@deepseek-ai/dsh"),
|
||||
true,
|
||||
"官方 Win resources 路径应判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("/Applications/DeepSeek Harness.app/Contents/Resources/app"),
|
||||
true,
|
||||
"官方 macOS .app Resources 应判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("C:/deepseek-harness/deepseek-harness.exe"),
|
||||
true,
|
||||
"官方 exe 路径应判桌面",
|
||||
);
|
||||
assert.equal(
|
||||
pathLooksDesktop("C:/dsh-desktop/DSH Desktop.exe"),
|
||||
true,
|
||||
"第三方 DSH Desktop 应判桌面",
|
||||
);
|
||||
|
||||
// #41:源码 apps/cli 识别 + 禁止注入
|
||||
assert.equal(looksLikeSourceCliRoot("E:/DSH/apps/cli"), true);
|
||||
assert.equal(looksLikeSourceCliRoot("/home/me/deepseek-harness/apps/cli"), true);
|
||||
assert.equal(
|
||||
looksLikeSourceCliRoot("/home/me/deepseek-harness/node_modules/@deepseek-ai/dsh"),
|
||||
false,
|
||||
);
|
||||
|
||||
const prev = process.platform;
|
||||
Object.defineProperty(process, "platform", { value: "win32" });
|
||||
try {
|
||||
const status = installHideConsoleIntoBin("E:/DSH/apps/cli", {
|
||||
fs: {
|
||||
existsSync: () => true,
|
||||
readFileSync: () => 'import "./x.js";\n',
|
||||
writeFileSync: () => {
|
||||
throw new Error("source cli must not be written");
|
||||
},
|
||||
unlinkSync: () => {
|
||||
throw new Error("source cli must not be unlinked");
|
||||
},
|
||||
},
|
||||
path: await import("node:path").then((m) => m.default),
|
||||
});
|
||||
assert.equal(status, "skipped_source_cli", "源码 cli 应跳过 hide-console 注入");
|
||||
} finally {
|
||||
Object.defineProperty(process, "platform", { value: prev });
|
||||
}
|
||||
|
||||
console.log("ok: surface desktop + source cli guards (#40/#41)");
|
||||
@@ -11,10 +11,10 @@ assert.equal(safeUpdateRef("origin/master"), "");
|
||||
assert.equal(safeUpdateRef("../evil"), "");
|
||||
assert.equal(safeUpdateRef("master;rm"), "");
|
||||
|
||||
const masterTar = "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz";
|
||||
const masterTar = "https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master";
|
||||
assert.equal(pluginAddSpec("git+https://github.com/yujunzhixue/dsh-purge.git", "master"), masterTar);
|
||||
assert.equal(pluginAddSpec("github:yujunzhixue/dsh-purge", "master"), masterTar);
|
||||
assert.equal(pluginAddSpec("https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip", "master"), masterTar);
|
||||
assert.equal(pluginAddSpec("https://codeload.github.com/YuJunZhiXue/dsh-purge/zip/refs/heads/master", "master"), masterTar);
|
||||
assert.equal(pluginAddSpec("dsh-purge", "master"), "");
|
||||
|
||||
const head = "9397203733562d6baeec9e38ac519698c619edcb";
|
||||
@@ -40,17 +40,18 @@ const caughtUp = [
|
||||
];
|
||||
const ceiling = latestStableVersion(caughtUp);
|
||||
assert.equal(ceiling, "1.1.12");
|
||||
assert.equal(hideListedVersion(caughtUp[2], ceiling), true);
|
||||
assert.equal(hideListedVersion(caughtUp[3], ceiling), true);
|
||||
assert.equal(hideListedVersion(caughtUp[2], ceiling), true); // 已追上的旧 beta 标签仍隐藏
|
||||
assert.equal(hideListedVersion(caughtUp[3], ceiling), false); // beta 分支 tip 始终保留(并行通道)
|
||||
assert.equal(hideListedVersion(caughtUp[4], ceiling), false);
|
||||
assert.equal(hideListedVersion({ ref: "v1.1.11-beta.1", version: "1.1.11-beta.1", channel: "beta" }, ""), true);
|
||||
|
||||
const visible = caughtUp.filter((item) => !hideListedVersion(item, ceiling));
|
||||
assert.deepEqual(visible.map((item) => item.ref), ["master", "v1.1.12", "v1.1.13-beta.1"]);
|
||||
assert.deepEqual(visible.map((item) => item.ref), ["master", "v1.1.12", "beta", "v1.1.13-beta.1"]);
|
||||
const staleSha = "423a91614baa747b56749003d054fedb8e725714";
|
||||
const shown = markCurrent(visible, { channel: "stable", pin: "" }, "1.1.12", staleSha);
|
||||
assert.equal(shown.find((item) => item.ref === "master").current, true);
|
||||
assert.equal(shown.find((item) => item.ref === "v1.1.12").current, false);
|
||||
assert.equal(shown.find((item) => item.ref === "beta").current, false);
|
||||
assert.equal(shown.find((item) => item.ref === "v1.1.13-beta.1").current, false);
|
||||
|
||||
console.log("ok: update guards");
|
||||
@@ -0,0 +1,52 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import {
|
||||
isUserProfilePatchFile,
|
||||
dropStaleUserProfilePatchBackups,
|
||||
targetFiles,
|
||||
} from "../lib/core.js";
|
||||
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("D:/DeepSeek Harness/.dsh/profiles/web/cordis.patch.yml"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("C:/Users/x/.dsh/profiles/desktop/cordis.patch.yml"),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("/home/me/.dsh/profiles/web/node_modules/dsh-purge/cordis.patch.yml"),
|
||||
false,
|
||||
"插件自己的 cordis.patch.yml 不是用户 profile 层",
|
||||
);
|
||||
assert.equal(
|
||||
isUserProfilePatchFile("/x/node_modules/@deepseek-ai/dsh-web-app/cordis.patch.yml"),
|
||||
false,
|
||||
);
|
||||
|
||||
// targetFiles 不得再收录 profiles/*/cordis.patch.yml(#43)
|
||||
const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-purge-43-"));
|
||||
const profilePatch = path.join(tmpHome, "profiles", "web", "cordis.patch.yml");
|
||||
fs.mkdirSync(path.dirname(profilePatch), { recursive: true });
|
||||
fs.writeFileSync(profilePatch, "patches:\n - insert: user-mcp\n", "utf8");
|
||||
const bak = `${profilePatch}.dshpurge.bak`;
|
||||
fs.writeFileSync(bak, "patches: []\n", "utf8");
|
||||
|
||||
const files = targetFiles(path.join(tmpHome, "missing-ai-base"), tmpHome);
|
||||
const flat = Object.values(files).flatMap((v) => (Array.isArray(v) ? v : [v])).filter(Boolean);
|
||||
assert.equal(
|
||||
flat.some((fp) => isUserProfilePatchFile(fp)),
|
||||
false,
|
||||
"targetFiles 不应包含用户 profile cordis.patch.yml",
|
||||
);
|
||||
|
||||
const before = fs.readFileSync(profilePatch, "utf8");
|
||||
const dropped = await dropStaleUserProfilePatchBackups(tmpHome);
|
||||
assert.equal(dropped.length, 1, "应丢掉误建 bak");
|
||||
assert.equal(fs.existsSync(bak), false, "bak 应已删除");
|
||||
assert.equal(fs.readFileSync(profilePatch, "utf8"), before, "用户当前内容必须保留");
|
||||
|
||||
fs.rmSync(tmpHome, { recursive: true, force: true });
|
||||
console.log("ok: user profile cordis.patch.yml not reverted (#43)");
|
||||
Reference in new issue
Block a user