mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 17:50:22 +08:00
fix: 极简等模式不用再点保存也能挂上提示词
组装时若内存里还没挂正文,就从磁盘提示词或当前规则集补上。空的已保存标记不再挡住磁盘文件。提示词段同时挂到全局层,切换官方预设也能看见。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
79714102a5
commit
4655d06723
3 files changed
+74
-8
No files matched your search
+38
-5
@@ -223,8 +223,31 @@ async function ensureRestartReady() {
|
||||
return clean;
|
||||
}
|
||||
|
||||
/** 提示词服务自己的 ctx 多半没有 scope,段会进全局层。插件若挂在某个 scope 上,预设代理的父链看不到那一层。 */
|
||||
function addPromptSection(ctx, section) {
|
||||
const hosts = [];
|
||||
const push = (host) => {
|
||||
if (host && !hosts.includes(host)) hosts.push(host);
|
||||
};
|
||||
try { push(ctx?.systemPrompt?.ctx); } catch { /* 代理未注入时点属性会抛 */ }
|
||||
push(ctx);
|
||||
let registered = false;
|
||||
let lastError = null;
|
||||
for (const host of hosts) {
|
||||
try {
|
||||
host.systemPrompt.section(section);
|
||||
registered = true;
|
||||
} catch (error) {
|
||||
const msg = String(error && error.message || error);
|
||||
if (msg.includes("already registered")) registered = true;
|
||||
else lastError = error;
|
||||
}
|
||||
}
|
||||
if (!registered && lastError) throw lastError;
|
||||
}
|
||||
|
||||
export function registerPromptSections(ctx, config, _injectFile) {
|
||||
ctx.systemPrompt.section({
|
||||
addPromptSection(ctx, {
|
||||
name: "dsh-purge",
|
||||
order: GLOBAL_PROMPT_ORDER + 1,
|
||||
interpolate: false,
|
||||
@@ -235,7 +258,7 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
});
|
||||
|
||||
if (config.capabilityProtocol !== false) {
|
||||
ctx.systemPrompt.section({
|
||||
addPromptSection(ctx, {
|
||||
name: CAPABILITY_SECTION,
|
||||
order: GLOBAL_PROMPT_ORDER,
|
||||
interpolate: false,
|
||||
@@ -264,9 +287,13 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
}
|
||||
|
||||
function readInjectFallback(context) {
|
||||
const raw = core.hungOperatorPrompt();
|
||||
if (!String(raw || "").trim()) return "";
|
||||
return modePromptText(raw, isRedteamSession(context));
|
||||
let home = "";
|
||||
try { home = core.findDshHome(); } catch { home = ""; }
|
||||
const raw = rules.ensureOperatorBody(home);
|
||||
if (!raw) return "";
|
||||
let redteam = false;
|
||||
try { redteam = isRedteamSession(context); } catch { redteam = false; }
|
||||
return modePromptText(raw, redteam);
|
||||
}
|
||||
|
||||
function installMnemonMessageStrip(ctx, config = {}) {
|
||||
@@ -418,6 +445,12 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
if (typeof timer.unref === "function") timer.unref();
|
||||
try { ctx.effect(() => () => clearInterval(timer)); } catch { /* 无 effect 时靠 unref */ }
|
||||
try { ctx.on("session/created", wrapAssemble); } catch { /* ignore */ }
|
||||
try {
|
||||
ctx.on("agent-preset/selected", () => {
|
||||
try { rules.ensureOperatorBody(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
|
||||
wrapAssemble();
|
||||
}, { global: true });
|
||||
} catch { /* ignore */ }
|
||||
try {
|
||||
ctx.on("agent/pre-step", (payload, next) => {
|
||||
wrapAssemble();
|
||||
|
||||
Reference in new issue
Block a user