mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 16:40:22 +08:00
fix: 1.1.45 第二轮发送不再因 undefined.length 直接死掉。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6f50df28f3
commit
11aa390cc3
5 files changed
+81
-62
No files matched your search
+6
-11
@@ -8,7 +8,6 @@ import * as reapply from "./reapply.js";
|
||||
import * as officialUpdate from "./official-update.js";
|
||||
import {
|
||||
GLOBAL_PROMPT_ORDER,
|
||||
clearPinnedSystemPrompt,
|
||||
isMnemonPluginMessage,
|
||||
isRedteamSession,
|
||||
rewritePromptAssembly,
|
||||
@@ -217,15 +216,17 @@ function readInjectFallback(context) {
|
||||
}
|
||||
|
||||
function installMnemonMessageStrip(ctx, config = {}) {
|
||||
if (config.stripMnemon === false) return;
|
||||
if (typeof ctx.on !== "function") return;
|
||||
if (ctx.__dshPurgeMnemonStrip) return;
|
||||
ctx.__dshPurgeMnemonStrip = true;
|
||||
const strip = config.stripMnemon !== false;
|
||||
const wrap = async (_payload, next) => {
|
||||
const decision = await next();
|
||||
if (!decision || !Array.isArray(decision.messages)) return decision;
|
||||
const messages = decision.messages.filter((message) => !isMnemonPluginMessage(message));
|
||||
if (messages.length === decision.messages.length) return decision;
|
||||
if (!decision) return decision;
|
||||
// agent-loop 会读 decision.messages.length;缺数组时第二轮直接 gateway/internal 炸掉。
|
||||
const incoming = Array.isArray(decision.messages) ? decision.messages : [];
|
||||
const messages = strip ? incoming.filter((message) => !isMnemonPluginMessage(message)) : incoming;
|
||||
if (messages.length === incoming.length && Array.isArray(decision.messages)) return decision;
|
||||
return { ...decision, messages };
|
||||
};
|
||||
const late = () => {
|
||||
@@ -329,12 +330,6 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
};
|
||||
// 只挂一次。不改 contexts,不改 pre-step 白名单,梁神 phase-1 和其它插件的消息原样保留。
|
||||
ctx.on("system-prompt/assemble", hook, { global: true, prepend: true });
|
||||
try {
|
||||
ctx.on("session/created", (session) => {
|
||||
const id = session?.id ?? session?.header?.id;
|
||||
if (id != null && id !== "") clearPinnedSystemPrompt(id);
|
||||
});
|
||||
} catch { /* ignore */ }
|
||||
// 0.1.5 起 complete:true 在 waterfall 之后用调用前的快照盖掉 sections。
|
||||
// 换宿主版本时文件补丁还没写上,或换插件版本时旧钩子把 dsh-purge 段删掉,注入都会丢。
|
||||
// 包住 assemble 的返回值,按 prompt-inject.md 再补回。
|
||||
|
||||
Reference in new issue
Block a user