feat: 发布 1.1.10,空提示词拦截并修首轮注入

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-20 11:00:02 +08:00
1 parent 56ba72a035
commit 51a9d271dd
9 files changed
+334 -175

No files matched your search

+37 -19
View File
@@ -1,7 +1,7 @@
import fs from "node:fs";
import { promises as fsp } from "node:fs";
import path from "node:path";
import { findDshHome } from "./core.js";
import { findDshHome, findOverrideFile, normalizeOverride } from "./core.js";
const RULE_ID_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}$/;
const MAX_RULE_BYTES = 256 * 1024;
@@ -151,17 +151,46 @@ export async function setActive(dshHome, id) {
await fsp.writeFile(stateFile(dshHome), JSON.stringify({ active: id }, null, 2), "utf8");
}
export function activeRuleText(dshHome) {
export function activeRuleId(dshHome) {
try {
const parsed = JSON.parse(fs.readFileSync(stateFile(dshHome), "utf8"));
const id = parsed?.active;
if (!validRuleId(id)) return "";
return fs.readFileSync(rulePath(dshHome, id), "utf8").trim();
return validRuleId(id) ? id : null;
} catch {
return null;
}
}
export function activeRuleText(dshHome) {
const id = activeRuleId(dshHome);
if (!id) return "";
try {
return fs.readFileSync(rulePath(dshHome, id), "utf8");
} catch {
return "";
}
}
export function overrideFileText(dshHome) {
const fp = findOverrideFile(dshHome);
try {
if (!fp || !fs.existsSync(fp)) return "";
return fs.readFileSync(fp, "utf8");
} catch {
return "";
}
}
/** 提示词优先;为空则用当前启用的规则集。两边都空则不注入。 */
export function resolveInjectText(dshHome) {
const prompt = overrideFileText(dshHome);
if (normalizeOverride(prompt)) return { text: prompt, source: "prompt", ruleId: null };
const ruleId = activeRuleId(dshHome);
const rule = activeRuleText(dshHome);
if (normalizeOverride(rule)) return { text: rule, source: "rule", ruleId };
return { text: "", source: "none", ruleId };
}
export async function activateRule(dshHome, id) {
const content = await readRule(dshHome, id);
if (content === null) throw new Error(`rule not found: ${id}`);
@@ -181,21 +210,7 @@ export async function ensureInitialState(dshHome) {
}
active = null;
}
if (active !== null) return { active };
if (listed.length > 0) return { active: null };
for (const target of RULE_TARGETS) {
try {
const content = await fsp.readFile(targetPath(dshHome, target), "utf8");
if (content.trim().length > 0) {
await saveRule(dshHome, "default", content, { name: "默认规则", target });
await setActive(dshHome, "default");
return { active: "default", imported: target };
}
} catch {
// 当前 target 文件不存在,试下一个
}
}
return { active: null };
return { active };
}
export async function resetToOriginal(dshHome) {
@@ -243,9 +258,12 @@ export async function rulesStatus(dshHome) {
} catch {
}
}
const inject = resolveInjectText(dshHome);
return {
rules: listed,
active,
injectSource: inject.source,
injectRuleId: inject.ruleId,
active_target,
agents_exists,
agents_synced,