feat: 发布 1.1.0,自动更新并修复 #14 #15 #16

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-17 22:36:04 +08:00
1 parent 4dce6689a8
commit e8567a8d34
8 files changed
+564 -114

No files matched your search

+115 -19
View File
@@ -1164,7 +1164,31 @@ export function findDshHome(options = {}) {
const prefix = options.prefix !== undefined ? options.prefix : findNpmPrefix();
const portable = portableHomeFromLauncher(shimDir, prefix);
if (portable) return portable;
return path.join(os.homedir(), ".dsh");
const unix = path.join(os.homedir(), ".dsh");
if (isDir(unix)) return unix;
const wslWin = findWslWindowsDshHome(env);
if (wslWin) return wslWin;
return unix;
}
function findWslWindowsDshHome(env = process.env) {
if (process.platform !== "linux") return "";
const rel = env.WSL_DISTRO_NAME || env.WSLENV;
if (!rel && !isDir("/mnt/c/Users")) return "";
const users = "/mnt/c/Users";
if (!isDir(users)) return "";
let names = [];
try {
names = fs.readdirSync(users);
} catch {
return "";
}
for (const name of names) {
if (name === "Public" || name === "Default" || name === "Default User" || name === "All Users") continue;
const cand = path.join(users, name, ".dsh");
if (isDir(cand)) return path.normalize(cand);
}
return "";
}
export function findNpmPrefix() {
@@ -2095,14 +2119,12 @@ const NEW_TOOL_PATCHES = [
replace: 'prefix: ""',
},
{
// 1.3.6 把无缩进 identity+\n\n 抽掉后,行首 6 空格和下一段拼成 12 空格。
// 0.1.5 cordis:连同行首 6 空格删身份段,plane 说明缩进保持 6。
pattern:
" prefix: |-\n You can read and modify the harness you run on.",
replace:
" prefix: |-\n You can read and modify the harness you run on.",
" You are a coding agent powered by the {{model}} model, running on the DeepSeek Harness. Your working directory is {{cwd}}.\n\n",
replace: IDENTITY_STRIP,
},
{
// 0.1.5 cordis:连同行首 6 空格删身份段,plane 说明缩进保持 6。
pattern:
" You are a coding agent powered by the {{model}} model, running on the DeepSeek Harness.\n\n",
replace: IDENTITY_STRIP,
@@ -2158,6 +2180,13 @@ const NEW_TOOL_PATCHES = [
pattern: "Start every reply with the deliverable. - id: agent-instructions",
replace: "Start every reply with the deliverable.\n\n- id: agent-instructions",
},
{
// 1.3.6 无缩进 identity+\n\n 留下的 12 空格首行;sanitize 也会修。
pattern:
" prefix: |-\n You can read and modify the harness you run on.",
replace:
" prefix: |-\n You can read and modify the harness you run on.",
},
],
markersAny: true,
markers: [
@@ -2721,6 +2750,37 @@ const NEW_TOOL_PATCHES = [
],
markers: ["[dsh-purge] mnemon summary off-notice"],
},
{
// 0.1.5 assemble 在 waterfall 之后若有 complete:true,会丢掉全部 section,提示词写了也进不去。
id: 41, name: "COMPLETE_PROMPT_KEEP_INJECT", layer: "0.1.5 兼容", layer_en: "0.1.5",
desc: "complete 预设仍保留 dsh-purge 注入 / keep inject after complete prompt",
file: ["system-prompt", "system-prompt-nested"],
replacements: [
{
pattern:
"\t\treturn {\n" +
"\t\t\t...transformed,\n" +
"\t\t\tsections: completeSection === void 0 ? transformed.sections : [completeSection],\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};",
replace:
"\t\treturn {\n" +
"\t\t\t...transformed,\n" +
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, assembled) {\n" +
"\t\t\t\tconst sections = assembled.sections || [];\n" +
"\t\t\t\tconst inject = sections.filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\")).map((s) => String(s.text || \"\").trim()).filter(Boolean).join(\"\\n\\n\");\n" +
"\t\t\t\tconst folded = sections.find((s) => s && s.name === complete.name);\n" +
"\t\t\t\tconst base = folded && typeof folded.text === \"string\" ? { ...complete, text: folded.text } : { ...complete };\n" +
"\t\t\t\tif (!inject) return [base];\n" +
"\t\t\t\tif (String(base.text || \"\").includes(inject.slice(0, Math.min(80, inject.length)))) return [base];\n" +
"\t\t\t\treturn [{ ...base, text: inject + \"\\n\\n\" + base.text }]; // [dsh-purge] complete prompt keeps inject\n" +
"\t\t\t})(completeSection, transformed),\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};",
},
],
markers: ["[dsh-purge] complete prompt keeps inject"],
},
];
export const ALL_PATCHES = [...PATCHES, ...CODE_PATCHES, ...ENGINE_PATCHES, ...NEW_TOOL_PATCHES];
@@ -3101,22 +3161,50 @@ function isDisposableYamlFoldParagraph(para) {
return false;
}
function yamlDropPaddingOnlyLines(bodyLines) {
return bodyLines.filter((line) => String(line).trim() !== "" || line === "");
}
function yamlMinContentIndent(bodyLines, keyIndent) {
let min = Infinity;
for (const line of bodyLines) {
if (!String(line).trim()) continue;
const n = yamlIndentOf(line);
if (n > keyIndent && n < min) min = n;
}
return Number.isFinite(min) ? min : keyIndent + 2;
}
function yamlReindentBody(bodyLines, indent) {
const pad = " ".repeat(Math.max(0, indent));
const out = [];
for (const line of bodyLines) {
if (!String(line).trim()) {
out.push("");
continue;
}
out.push(pad + String(line).replace(/^[ \t]+/, ""));
}
return out;
}
function yamlStripDisposableFoldParas(bodyLines) {
const raw = yamlFoldBodyText(bodyLines);
if (!raw) return [];
const kept = raw.split(/\n\s*\n/).filter((para) => !isDisposableYamlFoldParagraph(para));
if (kept.length === 0) return [];
const indent = (bodyLines.find((line) => String(line).trim()) || " ").match(/^[ \t]*/)[0] || " ";
const indent = yamlMinContentIndent(bodyLines, 0);
const pad = " ".repeat(indent || 6);
const out = [];
for (let i = 0; i < kept.length; i += 1) {
if (i > 0) out.push("");
for (const line of kept[i].split("\n")) out.push(indent + line);
for (const line of kept[i].split("\n")) out.push(pad + line);
}
return out;
}
function emptyDisposableFoldedYaml(text) {
const headerRe = /^(\s*)(personaPrefix|prefix|persona):\s*[>|][-+]?\s*$/;
const headerRe = /^(\s*)(personaPrefix|prefix|persona|text|suffix):\s*[>|][-+]?\s*$/;
const lines = String(text).split("\n");
const out = [];
for (let i = 0; i < lines.length; i += 1) {
@@ -3127,14 +3215,13 @@ function emptyDisposableFoldedYaml(text) {
}
const keyIndent = m[1].length;
const end = yamlConsumeFoldBody(lines, i, keyIndent);
const body = lines.slice(i + 1, end);
let body = yamlDropPaddingOnlyLines(lines.slice(i + 1, end));
const kept = yamlStripDisposableFoldParas(body);
if (kept.length === 0) out.push(`${m[1]}${m[2]}: ""`);
else if (kept.length === body.length && kept.every((line, idx) => line === body[idx])) {
out.push(lines[i], ...body);
} else {
else {
const indent = yamlMinContentIndent(kept, keyIndent);
out.push(`${m[1]}${m[2]}: |-`);
out.push(...kept);
out.push(...yamlReindentBody(kept, indent));
}
i = end - 1;
}
@@ -3142,7 +3229,7 @@ function emptyDisposableFoldedYaml(text) {
}
function stripOrphanYamlAfterEmptyScalars(text) {
const headerRe = /^(\s*)(personaPrefix|prefix|persona):\s*(""|'')\s*$/;
const headerRe = /^(\s*)(personaPrefix|prefix|persona|text|suffix):\s*(""|'')\s*$/;
const lines = String(text).split("\n");
const out = [];
for (let i = 0; i < lines.length; i += 1) {
@@ -3215,16 +3302,26 @@ function patchReplacements(p) {
return (p.patterns ?? []).map((pat) => ({ pattern: pat, replace: p.replace }));
}
function applyReplacementsToText(text, patch) {
function isBareIdentityNeedle(pattern) {
const needle = asLf(pattern);
if (!needle) return false;
if (/^[ \t]/.test(needle)) return false;
return /^You are a coding agent powered by\b/.test(needle);
}
function applyReplacementsToText(text, patch, fp = "") {
// 插入型补丁锚点仍在,已有标记则不再 replaceAll。
if (patch.skipIfMarked && patchApplied(text, patch)) {
return { text, changed: false };
}
const crlf = typeof text === "string" && text.includes("\r\n");
const yaml = isYamlPath(fp);
let out = asLf(text);
let changed = false;
for (const { pattern, replace } of patchReplacements(patch)) {
if (!pattern || typeof replace !== "string") continue;
// YAML 块标量行首有缩进;无缩进 identity+\n\n 会留下 6 空格,再和下一段拼成 12 空格。
if (yaml && isBareIdentityNeedle(pattern)) continue;
const needle = asLf(pattern);
if (!out.includes(needle)) continue;
out = out.split(needle).join(asLf(replace));
@@ -3321,7 +3418,7 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
lastError = "read_error";
continue;
}
const appliedText = applyReplacementsToText(text, p);
const appliedText = applyReplacementsToText(text, p, fp);
let textOut = appliedText.text;
let changed = appliedText.changed;
if (isYamlPath(fp)) {
@@ -3849,10 +3946,9 @@ export async function installOverride(dshHome, force = false) {
await fsp.mkdir(dshHome, { recursive: true });
if (fs.existsSync(fp) && !force) {
const existing = await loadText(fp);
// 非空保留用户内容;空文件视为故意清空。
// 空文件就是空:不注入、不改写。
return existing.trim().length > 0 ? "exists" : "empty";
}
// 文件不存在或 force 时写入默认稿。
await fsp.writeFile(fp, defaultOverrideText(), "utf8");
return "wrote";
}