feat: 发布 1.1.11-beta.2,正式/测试分栏并能切回去

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-20 16:43:26 +08:00
1 parent 24a3ff1b99
commit 2287ac4be7
5 files changed
+301 -144

No files matched your search

+5 -1
View File
@@ -654,7 +654,7 @@ dsh-purge --edit
purge_status purge_apply purge_revert
```
Patched packages load only after a restart. Apply does not restart by itself. Under the patch title you can switch **Stable / Beta** or roll back from the version list. A rollback is pinned; click **Update** to return to the channel tip.
Patched packages load only after a restart. Apply does not restart by itself. Under the patch title, **Stable** and **Beta** are separate: each has its own version list and switch action. A rollback is pinned; click **Update** to return to that channel's tip.
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.
@@ -751,6 +751,10 @@ If nothing is found, set `DSH_BASE` / `DSH_DESKTOP_INSTALL`. No files are change
## Changelog
### 1.1.11-beta.2
- Stable and Beta sit in two columns, each with its own list; switching a channel checks out that branch and can switch back after restart
### 1.1.11-beta.1
- Settings can import a zip or folder into official `$DSH_HOME/skills`; Stable / Beta can be switched and rolled back
+5 -1
View File
@@ -654,7 +654,7 @@ dsh-purge --edit
purge_status purge_apply purge_revert
```
设置页「应用」完成后需要重启才会加载已改的包文件。点「重启」才会重启,不会自动重启。补丁标题下可切换「正式版 / 测试版」,或从版本列表回退;回退后会固定在该版本,要回到通道最新再点「更新」。
设置页「应用」完成后需要重启才会加载已改的包文件。点「重启」才会重启,不会自动重启。补丁标题下正式版和测试版分开两栏:各自看版本、各自切换;回退后会固定在该版本,要回到该通道最新再点「更新」。
输入框旁的「回退」会丢掉最近一轮对话,并把上一句填回输入框;聊天里 `/rewind` 同样可用。
@@ -738,6 +738,10 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
## 更新记录
### 1.1.11-beta.2
- 正式版和测试版左右分栏,各自选版本、各自切换;切通道会落到对应分支,重启后也能切回去
### 1.1.11-beta.1
- 设置页可导入压缩包或文件夹到官方 `$DSH_HOME/skills`;正式版 / 测试版可切换并回退
+135 -83
View File
@@ -183,6 +183,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
"channel.title": "通道",
"channel.stable": "正式版",
"channel.beta": "测试版",
"channel.useStable": "切换到正式版",
"channel.useBeta": "切换到测试版",
"channel.now": "当前通道",
"channel.other": "可切换",
"update.checking": "正在检测更新…",
"update.applying": "正在更新…",
"update.switching": "正在切换版本…",
@@ -198,8 +202,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
"update.needRestart": "检测接口未加载,请先重启 dsh 再点检测更新",
"update.noBeta": "还没有测试版",
"update.switch": "切换到此版本",
"update.pick": "选择版本",
"update.tip": "最新",
"update.current": "当前",
"update.confirmSwitch": "切换到 {version}?之后可再选回正式版或其它版本。本地未提交的插件改动不会保留。",
"update.confirmSwitch": "切换到 {version}?之后可再切回另一通道或其它版本。本地未提交的插件改动不会保留。",
"update.confirmChannel": "切换到{version}?会按该通道重新安装插件,本地未提交的插件改动不会保留。",
"metric.version": "版本",
"action.apply": "应用",
"action.revert": "还原",
@@ -382,6 +389,10 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
"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…",
@@ -397,8 +408,11 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
"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",
@@ -594,7 +608,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{min-width:168px;max-width:260px;height:28px;padding:0 8px;font-size:12px}
.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}
@@ -836,11 +866,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 [selectedRef, setSelectedRef] = useState("");
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");
@@ -851,21 +892,17 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
const applyUpdateInfo = useCallback((d, tr, kind) => {
if (d.channel) setChannel(d.channel);
setUpdateInfo(d);
setCanApplyUpdate(Boolean(d.hasUpdate) && !d.error);
const versions = d.versions || [];
const current = versions.find((item) => item.current);
if (current && current.ref) setSelectedRef(current.ref);
else if (d.pin) setSelectedRef(d.pin);
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 || selectedRef || "—" });
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 });
}, [selectedRef]);
}, []);
const checkUpdate = useCallback(() => {
setUpdateBusy(true);
@@ -891,7 +928,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
})
.then((d) => {
if (!d || (d.ok === false && d.error)) throw new Error((d && d.error) || "update failed");
applyUpdateInfo(d, tr, kind === "channel" ? "done" : kind);
applyUpdateInfo(d, tr, kind === "channel" ? "switched" : kind);
if (d.applied || d.needRestart) setAskRestart(true);
return d;
})
@@ -902,24 +939,28 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
.finally(() => setUpdateBusy(false));
}, [applyUpdateInfo]);
const doUpdate = useCallback(() => {
postUpdate({ op: "apply" }, "done").catch(() => {});
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 || next === channel) return;
postUpdate({ op: "channel", channel: next }, "channel").catch(() => {});
}, [channel, postUpdate]);
const switchSelected = useCallback(() => {
if (!next) return;
const tr = tRef.current;
const versions = (updateInfo && updateInfo.versions) || [];
const hit = versions.find((item) => item.ref === selectedRef);
const label = (hit && (hit.label || hit.version)) || selectedRef;
if (!selectedRef) return;
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: selectedRef }, "switched").catch(() => {});
}, [postUpdate, selectedRef, updateInfo]);
postUpdate({ op: "switch", ref }, "switched").catch(() => {});
}, [pick, postUpdate, updateInfo]);
const loadAll = useCallback(() => {
const tr = tRef.current;
@@ -943,10 +984,7 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
if (!d) return;
if (d.channel) setChannel(d.channel);
setUpdateInfo(d);
setCanApplyUpdate(Boolean(d.hasUpdate) && !d.error);
const current = (d.versions || []).find((item) => item.current);
if (current && current.ref) setSelectedRef(current.ref);
else if (d.pin) setSelectedRef(d.pin);
syncPicks(d);
})
.catch(() => {});
apiJson("/dsh-purge/override")
@@ -1165,67 +1203,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 selected = versions.find((item) => item.ref === selectedRef);
const canSwitchVersion = Boolean(selectedRef && selected && !selected.current);
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)),
h("span", { className: "dshp-pill" + (channelNow === "beta" ? " is-wait" : "") }, t("channel." + (channelNow === "beta" ? "beta" : "stable"))),
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-row", style: { margin: "-4px 0 12px" } },
h("div", { className: "dshp-switch", role: "group", "aria-label": t("channel.title") },
h("button", {
type: "button",
className: channelNow === "stable" ? "is-on" : "",
disabled: updateBusy,
onClick: () => changeChannel("stable"),
}, t("channel.stable")),
h("button", {
type: "button",
className: channelNow === "beta" ? "is-on" : "",
disabled: updateBusy,
onClick: () => changeChannel("beta"),
}, t("channel.beta")),
h("div", { className: "dshp-rel" },
h("div", { className: "dshp-lanes" },
renderLane("stable"),
renderLane("beta"),
),
h("select", {
className: "dshp-field dshp-ver",
value: selectedRef,
disabled: updateBusy || versions.length === 0,
onChange: (e) => setSelectedRef(e.target.value),
"aria-label": t("update.switch"),
},
versions.length
? versions.map((item) => h("option", { key: item.ref + (item.sha || ""), value: item.ref }, item.label + (item.current ? " · " + t("update.current") : "")))
: h("option", { value: "" }, t("btn.checkUpdate")),
),
h(Btn, {
tiny: true,
disabled: updateBusy || !canSwitchVersion,
onClick: switchSelected,
}, t("update.switch")),
noticeNode(updateNotice),
),
s ? h("div", { className: "dshp-metrics" },
h("div", { className: "dshp-metric" },
+155 -58
View File
@@ -70,6 +70,27 @@ 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 {
@@ -448,6 +469,19 @@ function rememberVersion(item, seen) {
return item;
}
function markCurrent(versions, state, localVer, localSha) {
return (versions || []).map((item) => ({
...item,
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
current: Boolean(
(localSha && item.sha && sameRev(localSha, item.sha))
|| (state.pin && item.ref === state.pin)
|| (!state.pin && item.latest && item.channel === state.channel && item.version && item.version === localVer)
|| (!state.pin && item.version && item.version === localVer && item.channel === (isBetaName(localVer) ? "beta" : "stable")),
),
}));
}
async function listGithubTags() {
try {
const rows = await fetchJson(`https://api.github.com/repos/${REPO}/tags?per_page=50`);
@@ -526,70 +560,106 @@ async function listRemoteVersions() {
const localVer = localVersion();
const localSha = (gitOk() ? gitHead(PLUGIN_ROOT) : "") || readStamp();
return {
versions: out.map((item) => ({
...item,
shaShort: item.sha ? String(item.sha).slice(0, 7) : "",
current: Boolean(
(localSha && item.sha && sameRev(localSha, item.sha))
|| (state.pin && item.ref === state.pin)
|| (!state.pin && item.latest && item.channel === state.channel && item.version && item.version === localVer),
),
})),
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 = versions.some((item) => item.current) || matchesHead
|| Boolean(onLane && version && localVer && version === localVer && !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() {
const state = readChannelState();
let state = readChannelState();
const localVer = localVersion();
const listed = await listRemoteVersions();
const channelRef = currentChannelRef(state);
const remoteSha = state.channel === "beta" ? listed.betaSha : listed.stableSha;
const remoteVer = remoteSha ? await remotePackageVersion(remoteSha, channelRef) : "";
if (!remoteSha && !remoteVer) {
if (state.channel === "beta") {
return rememberUpdate({
ok: true,
hasUpdate: false,
hasBeta: false,
error: "还没有测试版",
localVersion: localVer,
remoteVersion: "",
localSha: ((gitOk() ? gitHead(PLUGIN_ROOT) : "") || readStamp()).slice(0, 7),
remoteSha: "",
via: detectVia(),
versions: listed.versions,
...channelPublic(state),
});
}
throw new Error("无法读取 GitHub master");
}
const gitSha = gitOk() ? gitHead(PLUGIN_ROOT) : "";
const stamp = readStamp();
const localRev = gitSha || stamp;
let hasUpdate = false;
if (state.pin) {
hasUpdate = Boolean(remoteSha && localRev && !sameRev(localRev, remoteSha));
} else if (remoteSha && localRev) {
hasUpdate = !sameRev(localRev, remoteSha);
} else if (remoteVer && localVer && remoteVer !== localVer) {
hasUpdate = true;
} else if (remoteSha && !localRev) {
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);
@@ -640,20 +710,25 @@ function gitResetTo(dir, ref, { force = false } = {}) {
}
const target = String(ref || STABLE_REF);
try {
if (target === STABLE_REF || target === BETA_REF) {
runGit(dir, ["pull", "--ff-only", "origin", target], 60000);
runGit(dir, ["fetch", "origin", "--tags"], 60000);
} catch {
runGit(dir, ["fetch", "origin", "--tags", target], 60000);
}
if (target === STABLE_REF || target === BETA_REF) {
try {
runGit(dir, ["checkout", "-B", target, `origin/${target}`]);
return;
} catch {
runGit(dir, ["reset", "--hard", `origin/${target}`]);
return;
}
} catch {
// 再走 fetch + reset。
}
try {
runGit(dir, ["fetch", "origin", "--tags", target], 60000);
} catch {
runGit(dir, ["fetch", "origin", "--tags"], 60000);
// 上面已经 fetch 过全部分支。
}
const remote = (target === STABLE_REF || target === BETA_REF) ? `origin/${target}` : target;
runGit(dir, ["reset", "--hard", remote], 60000);
runGit(dir, ["reset", "--hard", target]);
}
function extractZip(zip, dest) {
@@ -690,8 +765,16 @@ async function overlayFromZip(dests, ref = STABLE_REF) {
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 {
@@ -768,25 +851,25 @@ export async function applyUpdate(jobs = planUpdates(), options = {}) {
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);
writeChannelState({ channel: next, pin: "" });
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) {
const stable = writeChannelState({ channel: "stable", pin: "" });
return rememberUpdate({
ok: false,
error: "还没有测试版",
hasBeta: false,
...channelPublic(stable),
...channelPublic(),
versions: [],
lanes: { stable: { id: "stable", hasRemote: true }, beta: { id: "beta", hasRemote: false } },
});
}
if (!betaSha && apply) {
@@ -794,8 +877,11 @@ export async function switchChannel(channel, { apply = true } = {}) {
if (tag) return applyUpdate(planUpdates(), { ref: tag.ref, channel: "beta", pin: false, force: true });
}
}
if (!apply) return checkUpdate();
return applyUpdate(planUpdates(), { ref: currentChannelRef(), channel: next, 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 });
}
export async function switchVersion(ref) {
@@ -815,7 +901,10 @@ export async function handleUpdateOp(body = {}) {
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();
return applyUpdate(planUpdates(), { ref: body.ref || currentChannelRef(), pin: false, force: true });
const state = readChannelState();
const ref = body.ref || currentChannelRef(state);
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() {
@@ -823,6 +912,9 @@ export async function autoUpdateIfNeeded() {
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)));
@@ -834,7 +926,12 @@ export async function autoUpdateIfNeeded() {
error: "本地插件文件有未提交改动,未自动覆盖",
});
}
const applied = await applyUpdate(runnable, { ref: currentChannelRef(), pin: false, force: false });
const applied = await applyUpdate(runnable, {
ref: currentChannelRef(),
channel: readChannelState().channel,
pin: false,
force: false,
});
return rememberUpdate({ ...applied, auto: true });
} catch (e) {
return rememberUpdate({
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dsh-purge",
"version": "1.1.11-beta.1",
"version": "1.1.11-beta.2",
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
"type": "module",
"main": "lib/index.js",