mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 11:50:23 +08:00
1 parent
d4a0bb572f
commit
111427b198
8 files changed
+59
-35
No files matched your search
+11
-4
@@ -3577,11 +3577,16 @@ function patchApplied(text, patch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function cloneRegExp(pattern, global) {
|
||||
let flags = String(pattern.flags || "").replace("g", "");
|
||||
if (global) flags += "g";
|
||||
return new RegExp(pattern.source, flags);
|
||||
}
|
||||
|
||||
function matchesPattern(hay, pattern) {
|
||||
if (pattern instanceof RegExp) {
|
||||
const re = pattern.global ? pattern : new RegExp(pattern.source, pattern.flags);
|
||||
re.lastIndex = 0;
|
||||
return re.test(hay);
|
||||
// 不复用带 g 的模块级正则。test() 会留下 lastIndex,下一次替换从中间开始,等于没匹配到。
|
||||
return cloneRegExp(pattern, false).test(hay);
|
||||
}
|
||||
return hay.includes(asLf(pattern));
|
||||
}
|
||||
@@ -3655,8 +3660,10 @@ function applyReplacementsToText(text, patch, fp = "") {
|
||||
if (yaml && isBareIdentityNeedle(pattern)) continue;
|
||||
// 正则 pattern:用于自匹配型替换(产物包含原 pattern,如 timeoutMs 追加 0)。
|
||||
if (pattern instanceof RegExp) {
|
||||
const re = pattern.global ? pattern : new RegExp(pattern.source, pattern.flags + "g");
|
||||
const re = cloneRegExp(pattern, true);
|
||||
re.lastIndex = 0;
|
||||
if (!re.test(out)) continue;
|
||||
re.lastIndex = 0;
|
||||
// 用字符串形态调用:保留 $1..$9 展开语义(回调形态会把 "$1" 当字面量写进文件)。
|
||||
const next = out.replace(re, asLf(replace));
|
||||
if (next === out) continue;
|
||||
|
||||
+3
-2
@@ -268,8 +268,9 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
|
||||
|
||||
const injectText = collectInjectText(purge, opts.fallbackInject);
|
||||
// #29: 不要把上一条 system/message 全文钉回 sections。
|
||||
// 「历史里已有完整注入就不再折一份」由 foldInjectIntoPersona 的 includes 幂等满足。
|
||||
const folded = foldInjectIntoPersona(rest, injectText);
|
||||
// 默认留下 dsh-purge 段。0.1.5 在 waterfall 之后若 complete:true,只认这段把注入抄进最终提示词;
|
||||
// 提前折进 persona 再删掉本段,重启加载该逻辑后注入会丢。
|
||||
const folded = opts.dropPurgeAfterFold ? foldInjectIntoPersona(rest, injectText) : rest;
|
||||
const extras = opts.dropPurgeAfterFold
|
||||
? purge.filter((section) => section.name !== "dsh-purge")
|
||||
: purge;
|
||||
|
||||
+4
-1
@@ -230,7 +230,7 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
return rewritePromptAssembly(assembled, {
|
||||
fallbackInject: inject,
|
||||
dropMnemon: config.stripMnemon !== false,
|
||||
dropPurgeAfterFold: true,
|
||||
dropPurgeAfterFold: false,
|
||||
context,
|
||||
});
|
||||
};
|
||||
@@ -1110,6 +1110,9 @@ function installWebServer(ctx, cfg) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (typeof body?.content === "string") {
|
||||
await core.saveOverrideContent(state.dsh_home, body.content);
|
||||
}
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const override = await core.readOverrideForUi(state.dsh_home);
|
||||
|
||||
Reference in new issue
Block a user