mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 12:00:22 +08:00
release: 1.3.5 适配 dsh 0.1.2-rc.1 / Node 24 Windows 无感与首轮注入
修复 Node 24 ESM spawn 补丁无效导致的 CMD 闪窗;梁神 phase-1 保留完整 system-prompt;README 写明适配版本与变更说明。
This commit is contained in:
1 parent
905383165b
commit
9d139bf474
10 files changed
+1097
-171
No files matched your search
+32
-4
@@ -121,14 +121,43 @@ export function registerPromptSections(ctx, config, injectFile) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Cap fallback inject read so a huge/corrupt prompt-inject.md cannot blow memory each assemble. */
|
||||
const INJECT_FALLBACK_MAX_BYTES = 512 * 1024;
|
||||
|
||||
function readInjectFallback() {
|
||||
try {
|
||||
const fp = core.findOverrideFile(core.findDshHome());
|
||||
if (!fp || !fs.existsSync(fp)) return "";
|
||||
const st = fs.statSync(fp);
|
||||
if (!st.isFile() || st.size <= 0) return "";
|
||||
if (st.size <= INJECT_FALLBACK_MAX_BYTES) return fs.readFileSync(fp, "utf8");
|
||||
const fd = fs.openSync(fp, "r");
|
||||
try {
|
||||
const buf = Buffer.alloc(INJECT_FALLBACK_MAX_BYTES);
|
||||
const n = fs.readSync(fd, buf, 0, INJECT_FALLBACK_MAX_BYTES, 0);
|
||||
return buf.toString("utf8", 0, n);
|
||||
} finally {
|
||||
fs.closeSync(fd);
|
||||
}
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function installIdentityOverride(ctx) {
|
||||
if (typeof ctx.on !== "function") return;
|
||||
const hook = async (_assembly, _context, next) => {
|
||||
const assembled = typeof next === "function" ? await next() : _assembly;
|
||||
return rewritePromptAssembly(assembled);
|
||||
// Fallback file read covers Liangshen phase-1 races where purge sections
|
||||
// were filtered before this hook ran — first turn must still get inject.
|
||||
return rewritePromptAssembly(assembled, readInjectFallback());
|
||||
};
|
||||
// Register early (inside Liangshen filter) and again late as outermost so
|
||||
// phase-1 persona-only filtering cannot drop prompt-inject.md.
|
||||
// Inner (no prepend): fold inject into persona BEFORE Liangshen phase-1 filter.
|
||||
try {
|
||||
ctx.on("system-prompt/assemble", hook, { global: true, prepend: false });
|
||||
} catch {}
|
||||
// Outer (prepend): if filter already ran, re-fold from file. Re-register once
|
||||
// after plugins settle so we stay outermost without stacking three listeners.
|
||||
ctx.on("system-prompt/assemble", hook, { global: true, prepend: true });
|
||||
const late = () => {
|
||||
try {
|
||||
@@ -136,7 +165,6 @@ function installIdentityOverride(ctx) {
|
||||
} catch {}
|
||||
};
|
||||
queueMicrotask(late);
|
||||
setTimeout(late, 0);
|
||||
setTimeout(late, 1500);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user