1.1.80: 修复 bug,修复稳定性(#168 #169 #170 #172 #176)

This commit is contained in:
叫我小杨同学 committed 2026-10-27 23:34:55 +08:00
1 parent 533f4605c6
commit 093acefdfb
10 files changed
+178 -40

No files matched your search

+1 -1
View File
@@ -2530,7 +2530,7 @@ const COMPLETE_PROMPT_WATERFALL_INJECT =
"\t\t\t\treturn [...purge, ...tail, base]; // [dsh-purge] complete prompt keeps inject + agent-instructions\n" +
"\t\t\t})(completeSection, dshPurgeSections, dshPurgeRest),\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};";
"\t\t};";
function clearShellNetworkBan(pattern) {
return pattern
+87 -13
View File
@@ -105,24 +105,98 @@ export function ensureProfileBundles(profileDir) {
return { ok: true, wrote: true, path: fp };
}
function readPurgeTarball() {
try {
const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
return String(pkg?.dsh?.install?.tarball || "").trim();
} catch {
return "https://codeload.github.com/YuJunZhiXue/dsh-purge/tar.gz/refs/heads/master";
}
}
/** pnpm 12 会给 tarball 单独写一行 `dsh-purge@https://...: set this to true or false`。只写包名不够。 */
export function purgePnpmBuildSpecs() {
const specs = ["dsh-purge"];
const tarball = readPurgeTarball();
if (tarball) specs.push(`${PURGE_NAME}@${tarball}`);
return specs;
}
function isPurgeAllowBuildKey(key) {
const name = String(key || "").replace(/^['"]|['"]$/g, "");
return name === PURGE_NAME || name.startsWith(`${PURGE_NAME}@`);
}
function parseAllowBuildLine(line) {
const m = String(line || "").match(/^[ \t]+(?:"([^"]+)"|'([^']+)'|(\S+?))[ \t]*:[ \t]*(.*?)\s*$/);
if (!m) return null;
return { key: m[1] || m[2] || m[3], value: String(m[4] || "").trim() };
}
function formatAllowBuildLine(key) {
return ` ${key}: true`;
}
/** 把 dsh-purge 以及 `dsh-purge@tarball` 都写成 true,避免装别的插件还报 ERR_PNPM_IGNORED_BUILDS(#168)。 */
export function rewritePnpmAllowBuilds(raw) {
const wanted = purgePnpmBuildSpecs();
const text = String(raw || "").replace(/\r\n/g, "\n");
if (!text.trim()) {
return `allowBuilds:\n${wanted.map(formatAllowBuildLine).join("\n")}\n`;
}
const lines = text.split(/\r?\n/);
let start = -1;
for (let i = 0; i < lines.length; i += 1) {
if (/^allowBuilds[ \t]*:/.test(lines[i])) {
start = i;
break;
}
}
if (start < 0) {
const prefix = text.endsWith("\n") ? "" : "\n";
return `${text}${prefix}\nallowBuilds:\n${wanted.map(formatAllowBuildLine).join("\n")}\n`;
}
let end = lines.length;
const kept = [];
const seen = new Set();
for (let i = start + 1; i < lines.length; i += 1) {
const line = lines[i];
if (!line.trim()) {
end = i;
break;
}
if (/^\S/.test(line)) {
end = i;
break;
}
const parsed = parseAllowBuildLine(line);
if (!parsed) {
kept.push(line);
continue;
}
if (isPurgeAllowBuildKey(parsed.key)) {
kept.push(formatAllowBuildLine(parsed.key));
seen.add(parsed.key);
continue;
}
kept.push(line);
}
for (const key of wanted) {
if (!seen.has(key)) kept.push(formatAllowBuildLine(key));
}
const next = [...lines.slice(0, start + 1), ...kept, ...lines.slice(end)].join("\n");
return next.endsWith("\n") ? next : `${next}\n`;
}
/** pnpm 11/12 默认拦 postinstall(ERR_PNPM_IGNORED_BUILDS)。写进 profile 的 allowBuilds,下次 add 能跑脚本。 */
export function ensurePnpmAllowBuild(profileDir) {
const fp = path.join(profileDir, "pnpm-workspace.yaml");
let text = "";
try { text = fs.readFileSync(fp, "utf8"); } catch { text = ""; }
if (/(^|\n)[ \t]*dsh-purge[ \t]*:[ \t]*true\b/.test(text)) return { ok: true, wrote: false, path: fp };
if (!String(text).trim()) {
fs.writeFileSync(fp, "allowBuilds:\n dsh-purge: true\n", "utf8");
return { ok: true, wrote: true, path: fp };
}
if (/(^|\n)allowBuilds[ \t]*:/.test(text)) {
const next = text.replace(/(^|\n)(allowBuilds[ \t]*:[ \t]*\n)/, "$1$2 dsh-purge: true\n");
if (next === text) return { ok: true, wrote: false, path: fp };
fs.writeFileSync(fp, next, "utf8");
return { ok: true, wrote: true, path: fp };
}
const prefix = text.endsWith("\n") ? "" : "\n";
fs.writeFileSync(fp, `${text}${prefix}\nallowBuilds:\n dsh-purge: true\n`, "utf8");
const current = String(text || "").replace(/\r\n/g, "\n");
const next = rewritePnpmAllowBuilds(current);
if (next === current) return { ok: true, wrote: false, path: fp };
fs.writeFileSync(fp, next, "utf8");
return { ok: true, wrote: true, path: fp };
}
+2 -2
View File
@@ -51,9 +51,9 @@ window.__ModuleLoader__.load({
.rt-dot{width:8px;height:8px;border-radius:50%;background:var(--dsw-alias-brand-primary)}
.rt-spacer{flex:1}
.rt-btn{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:inherit;
border-radius:6px;padding:3px 9px;font-size:12px;cursor:pointer;font-family:inherit;white-space:nowrap}
border-radius:6px;padding:3px 9px;font-size:12px;cursor:pointer;font-family:system-ui,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif;white-space:nowrap;-webkit-text-fill-color:currentColor;overflow:visible}
.rt-btn:hover{border-color:var(--dsw-alias-border-l2)}
.rt-btn-primary{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:#fff}
.rt-btn-primary{background:var(--dsw-alias-brand-primary);border-color:var(--dsw-alias-brand-primary);color:#fff;-webkit-text-fill-color:#fff}
.rt-btn-primary:hover{opacity:.9}
.rt-btn:disabled{opacity:.5;cursor:default}
.rt-tabs{display:flex;flex-wrap:wrap;gap:2px;padding:6px 12px 0;border-bottom:1px solid var(--dsw-alias-border-l1)}
+1 -1
View File
@@ -1,4 +1,4 @@
import { promises as fsp } from "node:fs";
import fs, { promises as fsp } from "node:fs";
import { spawnSync } from "node:child_process";
import os from "node:os";
import path from "node:path";
+11 -3
View File
@@ -73,12 +73,23 @@ function localDataOffset(buf, localOffset) {
return localOffset + 30 + nameLen + extraLen;
}
function isZipDirectoryEntry(name) {
return /[/\\]$/.test(String(name || ""));
}
export function extractZipBuffer(buf, dest) {
fs.mkdirSync(dest, { recursive: true });
const root = path.resolve(dest);
const prefix = root.endsWith(path.sep) ? root : root + path.sep;
for (const entry of readZipEntries(buf)) {
const rel = safeZipName(entry.name);
if (!rel) continue;
const out = path.resolve(root, rel);
if (out !== root && !out.startsWith(prefix)) throw new Error("Invalid zip path");
if (isZipDirectoryEntry(entry.name)) {
fs.mkdirSync(out, { recursive: true });
continue;
}
if (entry.compSize === 0xffffffff || entry.localOffset === 0xffffffff) {
throw new Error("zip64 is not supported");
}
@@ -90,9 +101,6 @@ export function extractZipBuffer(buf, dest) {
if (end > buf.length) throw new Error("Truncated zip data");
const compressed = buf.subarray(start, end);
const body = entry.method === 0 ? compressed : zlib.inflateRawSync(compressed);
const out = path.resolve(root, rel);
const prefix = root.endsWith(path.sep) ? root : root + path.sep;
if (out !== root && !out.startsWith(prefix)) throw new Error("Invalid zip path");
fs.mkdirSync(path.dirname(out), { recursive: true });
fs.writeFileSync(out, body);
}