fix: bash 超时注记改成 YAML 注释,避免启动校验失败 (#36)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-24 12:22:07 +08:00
1 parent d92d4dc2ca
commit 5d6cf35dac
4 files changed
+127 -5

No files matched your search

+40 -5
View File
@@ -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");