mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 07:20:22 +08:00
fix: 新对话把提示词放到系统提示最前,面板改为白墨玻璃。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e8b745e29e
commit
7c3eb548c0
3 files changed
+68
-64
No files matched your search
+22
-19
@@ -1,4 +1,4 @@
|
||||
export const GLOBAL_PROMPT_ORDER = 5000;
|
||||
export const GLOBAL_PROMPT_ORDER = -100000;
|
||||
export const IDENTITY_CARD_PREFIX = "WHO YOU ARE (highest priority";
|
||||
|
||||
const PERSONA_PREFIX_NAMES = new Set([
|
||||
@@ -138,14 +138,23 @@ function withoutRedteamPreset(sections) {
|
||||
});
|
||||
}
|
||||
|
||||
function assemblyHasExactInject(sections, inject) {
|
||||
if (!inject) return true;
|
||||
return sections.some((section) => String(section?.text || "").includes(inject));
|
||||
}
|
||||
|
||||
function ensureFullInject(sections, inject) {
|
||||
if (!inject || assemblyHasExactInject(sections, inject)) return sections;
|
||||
return [{ name: "dsh-purge", text: inject, order: -10000 }, ...sections];
|
||||
/** 每次组装都把提示词放到最前。已经嵌在后面的同一份正文拆出来,避免宿主段落挡在前面。 */
|
||||
function leadWithInject(sections, inject) {
|
||||
const text = String(inject || "").trim();
|
||||
if (!text) return sections;
|
||||
const rest = [];
|
||||
for (const section of sections) {
|
||||
if (!section || section.name === "dsh-purge") continue;
|
||||
const body = typeof section.text === "string" ? section.text : "";
|
||||
if (!body.includes(text)) {
|
||||
rest.push(section);
|
||||
continue;
|
||||
}
|
||||
const next = body.split(text).join("").replace(/\n{3,}/g, "\n\n").trim();
|
||||
if (!next) continue;
|
||||
rest.push({ ...section, text: next });
|
||||
}
|
||||
return [{ name: "dsh-purge", text, order: GLOBAL_PROMPT_ORDER, interpolate: false }, ...rest];
|
||||
}
|
||||
|
||||
/** 红队预设里要留下来的操作说明起点。这句前面的「你是红队指挥」身份句丢掉。 */
|
||||
@@ -199,7 +208,7 @@ function writePurgeSection(sections, inject) {
|
||||
return [{ name: "dsh-purge", text, order: -10000 }, ...next];
|
||||
}
|
||||
|
||||
/** 注册顺序在 5000,原文已经包含注入时不会再往前插,第二轮就继续用宿主开头的那条系统消息。 */
|
||||
/** 宿主按 order 升序拼接。提示词必须排在身份、Agent Teams、工作目录之前。 */
|
||||
function hoistOperatorPrompt(sections) {
|
||||
const index = sections.findIndex((section) => section?.name === "dsh-purge");
|
||||
if (index < 0) return sections;
|
||||
@@ -437,14 +446,8 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
? purge.filter((section) => section.name !== "dsh-purge")
|
||||
: purge);
|
||||
let sections = [...folded, ...extras];
|
||||
if (!redteam) {
|
||||
sections = writePurgeSection(withoutRedteamPreset(sections), injectText);
|
||||
assembled.sections = ensureFullInject(sections, injectText);
|
||||
return assembled;
|
||||
}
|
||||
assembled.sections = ensureFullInject(
|
||||
attachInjectToRedteamPersona(sections, injectText),
|
||||
injectText,
|
||||
);
|
||||
if (!redteam) sections = withoutRedteamPreset(sections);
|
||||
else sections = attachInjectToRedteamPersona(sections, injectText);
|
||||
assembled.sections = leadWithInject(sections, injectText);
|
||||
return assembled;
|
||||
}
|
||||
@@ -187,6 +187,7 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
ctx.systemPrompt.section({
|
||||
name: "dsh-purge",
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
interpolate: false,
|
||||
text: () => {
|
||||
if (!injectAllowedNow(config)) return "";
|
||||
return rules.resolveInjectText(core.findDshHome()).text;
|
||||
|
||||
Reference in new issue
Block a user