mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 04:50:22 +08:00
fix: bash 超时注记改成 YAML 注释,避免启动校验失败 (#36)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d92d4dc2ca
commit
5d6cf35dac
4 files changed
+127
-5
No files matched your search
+40
-5
@@ -2230,11 +2230,13 @@ const NEW_TOOL_PATCHES = [
|
||||
// 现在的做法:锚在 bash-sandbox 行内,`[^\n]*` 必须吃到行尾 —— 这样上一次
|
||||
// 追加的注记会被整体重写而不是再叠一层,数值也不再有可再匹配的"前缀"。
|
||||
// 这条是带 g 的模块级正则,匹配和写入都要克隆后再用,否则 lastIndex 残留会导致永远 pending。
|
||||
// YAML 只认 #。写成 // 时从数字到行尾都是字符串,timeoutMs 校验失败,宿主起不来。
|
||||
// [^\n]* 会把已经写成 // 的那一行整段重写成下面的 # 版本。
|
||||
pattern: /(name: '@deepseek-ai\/dsh-bash-sandbox'[\s\S]*?\n {8}timeoutMs: )6[0-9]+[^\n]*/g,
|
||||
replace: "$1600000 // [dsh-purge] bash timeout raised",
|
||||
replace: "$1600000 # [dsh-purge] bash timeout raised",
|
||||
},
|
||||
],
|
||||
markers: ["timeoutMs: 600000 // [dsh-purge] bash timeout raised"],
|
||||
markers: ["timeoutMs: 600000 # [dsh-purge] bash timeout raised"],
|
||||
},
|
||||
{
|
||||
id: 22, name: "READ_CAPS_RAISED", layer: "代码", layer_en: "Code",
|
||||
@@ -3646,7 +3648,39 @@ function isBareIdentityNeedle(pattern) {
|
||||
return /^You are a coding agent powered by\b/.test(needle);
|
||||
}
|
||||
|
||||
function applyReplacementsToText(text, patch, fp = "") {
|
||||
// 行尾的 JS 注释写进 YAML 会变成字符串。!!js 行本身是表达式,引号里的 // 也不动。
|
||||
export function yamlJsCommentsToHash(text) {
|
||||
return asLf(text).split("\n").map((line) => {
|
||||
if (line.includes("!!js")) return line;
|
||||
let quote = "";
|
||||
for (let i = 0; i < line.length - 1; i += 1) {
|
||||
const ch = line[i];
|
||||
if (quote) {
|
||||
if (quote === "'" && ch === "'" && line[i + 1] === "'") {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (quote === '"' && ch === "\\") {
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
if (ch === quote) quote = "";
|
||||
continue;
|
||||
}
|
||||
if (ch === '"' || ch === "'") {
|
||||
quote = ch;
|
||||
continue;
|
||||
}
|
||||
if (ch === "#") return line;
|
||||
if (ch === "/" && line[i + 1] === "/" && (i === 0 || /\s/.test(line[i - 1]))) {
|
||||
return `${line.slice(0, i)}#${line.slice(i + 2)}`;
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}).join("\n");
|
||||
}
|
||||
|
||||
export function applyReplacementsToText(text, patch, fp = "") {
|
||||
// 插入型补丁锚点仍在,已有标记则不再 replaceAll。
|
||||
if (patch.skipIfMarked && patchApplied(text, patch)) {
|
||||
return { text, changed: false };
|
||||
@@ -3659,6 +3693,7 @@ function applyReplacementsToText(text, patch, fp = "") {
|
||||
if (!pattern || typeof replace !== "string") continue;
|
||||
// YAML 块标量行首有缩进;无缩进 identity+\n\n 会留下 6 空格,再和下一段拼成 12 空格。
|
||||
if (yaml && isBareIdentityNeedle(pattern)) continue;
|
||||
const written = yaml ? yamlJsCommentsToHash(asLf(replace)) : asLf(replace);
|
||||
// 正则 pattern:用于自匹配型替换(产物包含原 pattern,如 timeoutMs 追加 0)。
|
||||
if (pattern instanceof RegExp) {
|
||||
const re = cloneRegExp(pattern, true);
|
||||
@@ -3666,7 +3701,7 @@ function applyReplacementsToText(text, patch, fp = "") {
|
||||
if (!re.test(out)) continue;
|
||||
re.lastIndex = 0;
|
||||
// 用字符串形态调用:保留 $1..$9 展开语义(回调形态会把 "$1" 当字面量写进文件)。
|
||||
const next = out.replace(re, asLf(replace));
|
||||
const next = out.replace(re, written);
|
||||
if (next === out) continue;
|
||||
out = next;
|
||||
changed = true;
|
||||
@@ -3674,7 +3709,7 @@ function applyReplacementsToText(text, patch, fp = "") {
|
||||
}
|
||||
const needle = asLf(pattern);
|
||||
if (!out.includes(needle)) continue;
|
||||
out = out.split(needle).join(asLf(replace));
|
||||
out = out.split(needle).join(written);
|
||||
changed = true;
|
||||
}
|
||||
if (crlf) out = out.replace(/\n/g, "\r\n");
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"scripts": {
|
||||
"embed-prompt": "node scripts/embed-default-prompt.mjs",
|
||||
"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"
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
- 设置页点「应用」会把输入框里的提示词写入 `prompt-inject.md`。以前只检查有没有字,重启后读的还是旧文件,所以注入像没生效。
|
||||
- 带 `complete: true` 的预设在重启后不再丢掉 `dsh-purge` 注入段。点「应用」之后必须再点「重启」,宿主重新打开后新开一轮对话,注入才进入当前会话。
|
||||
- bash 超时补丁不再和状态检查共用同一条正则。点「应用」会把 60 秒写成 10 分钟,不会一直停在待应用(#35)。
|
||||
- bash 超时写进 `cordis.patch.yml` 时用 `#` 注释。`//` 会被 YAML 当成字符串,`timeoutMs` 校验失败,`dsh` 一启动就崩(#36)。已经起不来的,先把 `@deepseek-ai/dsh-base` 里那一行的 `//` 改成 `#`,或改回 `timeoutMs: 600000`,再更新插件。
|
||||
- 去掉点了也不变的「启用 fetch」补丁,后面的编号依次前移。没装 `dsh-web-fetch-http` 时不再占着一条待应用。
|
||||
- README 开头写明必须应用并重启。工作原理改成流程图,去掉 0.1.5 适配表和生效验证。
|
||||
|
||||
@@ -13,5 +14,6 @@
|
||||
- Apply on the settings page writes the prompt box into `prompt-inject.md`. It used to only check that the box was not empty, so after a restart the host still read the old file and the inject looked like it never happened.
|
||||
- Presets with `complete: true` no longer drop the `dsh-purge` inject section after a restart. After Apply you must click Restart. When the host is back, start a new chat; that is when the inject enters the session.
|
||||
- The bash timeout patch no longer shares one regular expression with the status check. Apply now writes 60 seconds as 10 minutes instead of staying on pending (#35).
|
||||
- The bash timeout note in `cordis.patch.yml` is a `#` comment. A `//` comment is a YAML string, so `timeoutMs` fails validation and `dsh` dies on startup (#36). If it already will not start, change that `//` to `#` in `@deepseek-ai/dsh-base`, or put the line back to `timeoutMs: 600000`, then update the plugin.
|
||||
- The fetch-enable patch that stayed pending is gone, and later patch numbers move up by one. A missing `dsh-web-fetch-http` package no longer occupies a pending row.
|
||||
- The README now says at the top that Apply must be followed by Restart. How it works is a flowchart. The 0.1.5 notes table and the verify list are removed.
|
||||
@@ -0,0 +1,84 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { ALL_PATCHES, applyReplacementsToText, yamlJsCommentsToHash } from "../lib/core.js";
|
||||
|
||||
const bash = ALL_PATCHES.find((patch) => patch.id === 21);
|
||||
assert.equal(bash.name, "BASH_TIMEOUT_RAISED");
|
||||
assert.equal(bash.replacements[0].replace.includes("//"), false);
|
||||
assert.match(bash.markers[0], /timeoutMs: 600000 # \[dsh-purge\]/);
|
||||
|
||||
const head =
|
||||
"- id: bash-sandbox\n" +
|
||||
" name: '@deepseek-ai/dsh-bash-sandbox'\n" +
|
||||
" config:\n";
|
||||
const indent = " ".repeat(8);
|
||||
|
||||
const fresh = applyReplacementsToText(
|
||||
`${head}${indent}timeoutMs: 60000\n`,
|
||||
bash,
|
||||
"cordis.patch.yml",
|
||||
);
|
||||
assert.equal(fresh.changed, true);
|
||||
assert.match(fresh.text, /timeoutMs: 600000 # \[dsh-purge\] bash timeout raised/);
|
||||
assert.equal(fresh.text.includes("//"), false);
|
||||
|
||||
const broken = applyReplacementsToText(
|
||||
`${head}${indent}timeoutMs: 600000 // [dsh-purge] bash timeout raised\n`,
|
||||
bash,
|
||||
"cordis.patch.yml",
|
||||
);
|
||||
assert.equal(broken.changed, true);
|
||||
assert.equal(broken.text, fresh.text);
|
||||
|
||||
const healed = applyReplacementsToText(fresh.text, bash, "cordis.patch.yml");
|
||||
assert.equal(healed.changed, false);
|
||||
assert.equal(healed.text, fresh.text);
|
||||
|
||||
const jsKept = applyReplacementsToText(
|
||||
'text: "You are an AI agent powered by DeepSeek Harness."\n',
|
||||
{
|
||||
replacements: [{
|
||||
pattern: 'text: "You are an AI agent powered by DeepSeek Harness."',
|
||||
replace: 'text: "" // [dsh-purge] identity stripped',
|
||||
}],
|
||||
},
|
||||
"lib/index.js",
|
||||
);
|
||||
assert.match(jsKept.text, /text: "" \/\/ \[dsh-purge\] identity stripped/);
|
||||
|
||||
const yamlFixed = applyReplacementsToText(
|
||||
'text: "You are an AI agent powered by DeepSeek Harness."\n',
|
||||
{
|
||||
replacements: [{
|
||||
pattern: 'text: "You are an AI agent powered by DeepSeek Harness."',
|
||||
replace: 'text: "" // [dsh-purge] identity stripped',
|
||||
}],
|
||||
},
|
||||
"agent.cordis.yml",
|
||||
);
|
||||
assert.match(yamlFixed.text, /text: "" # \[dsh-purge\] identity stripped/);
|
||||
assert.equal(yamlFixed.text.includes("//"), false);
|
||||
|
||||
assert.equal(
|
||||
yamlJsCommentsToHash("mode: !!js process.env.X ?? 'https://example.com' // keep"),
|
||||
"mode: !!js process.env.X ?? 'https://example.com' // keep",
|
||||
);
|
||||
assert.equal(yamlJsCommentsToHash("url: https://example.com"), "url: https://example.com");
|
||||
assert.equal(
|
||||
yamlJsCommentsToHash('note: "keep // inside"'),
|
||||
'note: "keep // inside"',
|
||||
);
|
||||
|
||||
const yamlPatches = ALL_PATCHES.filter((patch) => {
|
||||
const keys = Array.isArray(patch.file) ? patch.file : [patch.file];
|
||||
return keys.some((key) => /preset|web-app|headless|base$|agent-preset/.test(key));
|
||||
});
|
||||
for (const patch of yamlPatches) {
|
||||
const reps = patch.replacements || (patch.patterns || []).map((pattern) => ({ pattern, replace: patch.replace }));
|
||||
for (const rep of reps) {
|
||||
if (typeof rep.replace !== "string" || !rep.replace.includes("//")) continue;
|
||||
const safe = yamlJsCommentsToHash(rep.replace);
|
||||
assert.equal(safe.includes(" //"), false, `${patch.name} still writes a JS comment into YAML`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("ok: yaml comments");
|
||||
Reference in new issue
Block a user