mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-06-14 02:40:45 +08:00
fix(recall): pass generation context to primary reroll path + trace gates
This commit is contained in:
@@ -585,12 +585,14 @@ export async function onGenerationAfterCommandsController(
|
|||||||
|
|
||||||
const context = runtime.getContext();
|
const context = runtime.getContext();
|
||||||
const chat = context?.chat;
|
const chat = context?.chat;
|
||||||
|
const generationContext = runtime.getGenerationContext?.() || null;
|
||||||
|
|
||||||
const recallOptions = runtime.buildGenerationAfterCommandsRecallInput(
|
const recallOptions = runtime.buildGenerationAfterCommandsRecallInput(
|
||||||
type,
|
generationContext?.type || type,
|
||||||
{
|
{
|
||||||
...params,
|
...params,
|
||||||
frozenInputSnapshot,
|
frozenInputSnapshot,
|
||||||
|
generationContext,
|
||||||
},
|
},
|
||||||
chat,
|
chat,
|
||||||
);
|
);
|
||||||
@@ -601,6 +603,26 @@ export async function onGenerationAfterCommandsController(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (globalThis.__stBmeDebugLoggingEnabled === true) {
|
||||||
|
const tail = Array.isArray(chat)
|
||||||
|
? chat.slice(-3).map((m, i) => ({
|
||||||
|
idx: chat.length - 3 + i,
|
||||||
|
is_user: Boolean(m?.is_user),
|
||||||
|
hasRecall: Boolean(m?.extra?.bme_recall),
|
||||||
|
mes: String(m?.mes || "").slice(0, 40),
|
||||||
|
}))
|
||||||
|
: null;
|
||||||
|
console.warn("[ST-BME][reroll-trace] AFTER_COMMANDS enter", {
|
||||||
|
type,
|
||||||
|
generationContextType: generationContext?.type || null,
|
||||||
|
generationContextKind: generationContext?.kind || null,
|
||||||
|
recallOptionsSource: recallOptions?.overrideSource || recallOptions?.source || null,
|
||||||
|
recallOptionsType: recallOptions?.generationType || null,
|
||||||
|
targetUserMessageIndex: recallOptions?.targetUserMessageIndex ?? null,
|
||||||
|
chatTail: tail,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const recallContext = runtime.createGenerationRecallContext({
|
const recallContext = runtime.createGenerationRecallContext({
|
||||||
hookName: "GENERATION_AFTER_COMMANDS",
|
hookName: "GENERATION_AFTER_COMMANDS",
|
||||||
generationType,
|
generationType,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// ST-BME: 召回输入解析与注入控制器(纯函数)
|
// ST-BME: 召回输入解析与注入控制器(纯函数)
|
||||||
|
|
||||||
import { debugLog } from "../runtime/debug-logging.js";
|
import { debugLog, debugWarn } from "../runtime/debug-logging.js";
|
||||||
import { isSystemMessageForExtraction } from "../maintenance/chat-history.js";
|
import { isSystemMessageForExtraction } from "../maintenance/chat-history.js";
|
||||||
|
|
||||||
export function buildRecallRecentMessagesController(
|
export function buildRecallRecentMessagesController(
|
||||||
@@ -161,13 +161,29 @@ function resolveReusablePersistedRecallRecord(chat, recallInput, runtime) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Number.isFinite(targetUserMessageIndex)) return null;
|
if (!Number.isFinite(targetUserMessageIndex)) {
|
||||||
|
debugWarn("[ST-BME][reroll-trace] no target user floor resolved", {
|
||||||
|
generationType,
|
||||||
|
recallSource,
|
||||||
|
currentRecallInputText: currentRecallInputText.slice(0, 60),
|
||||||
|
chatLength: Array.isArray(chat) ? chat.length : null,
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const targetMessage = Array.isArray(chat) ? chat[targetUserMessageIndex] : null;
|
const targetMessage = Array.isArray(chat) ? chat[targetUserMessageIndex] : null;
|
||||||
if (!targetMessage?.is_user) return null;
|
if (!targetMessage?.is_user) return null;
|
||||||
|
|
||||||
const record = readPersistedRecallFromUserMessage(chat, targetUserMessageIndex);
|
const record = readPersistedRecallFromUserMessage(chat, targetUserMessageIndex);
|
||||||
if (!record?.injectionText) return null;
|
if (!record?.injectionText) {
|
||||||
|
debugWarn("[ST-BME][reroll-trace] target floor has no persisted recall record", {
|
||||||
|
generationType,
|
||||||
|
recallSource,
|
||||||
|
targetUserMessageIndex,
|
||||||
|
targetUserFloorText: String(targetMessage?.mes || "").slice(0, 60),
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const currentUserFloorText = normalizeText(targetMessage?.mes || "");
|
const currentUserFloorText = normalizeText(targetMessage?.mes || "");
|
||||||
const recordRecallInput = normalizeText(record?.recallInput || "");
|
const recordRecallInput = normalizeText(record?.recallInput || "");
|
||||||
@@ -228,9 +244,34 @@ function resolveReusablePersistedRecallRecord(chat, recallInput, runtime) {
|
|||||||
!canReuseUnboundTargetRecord &&
|
!canReuseUnboundTargetRecord &&
|
||||||
!canTrustUserFloorRecord
|
!canTrustUserFloorRecord
|
||||||
) {
|
) {
|
||||||
|
debugWarn("[ST-BME][reroll-trace] reuse REJECTED", {
|
||||||
|
generationType,
|
||||||
|
recallSource,
|
||||||
|
targetUserMessageIndex,
|
||||||
|
isActiveInputSource,
|
||||||
|
isNoNewUserGeneration,
|
||||||
|
hasRecord: Boolean(record?.injectionText),
|
||||||
|
currentUserFloorText: currentUserFloorText.slice(0, 60),
|
||||||
|
currentRecallInputText: currentRecallInputText.slice(0, 60),
|
||||||
|
recordRecallInput: recordRecallInput.slice(0, 60),
|
||||||
|
boundUserFloorText: boundUserFloorText.slice(0, 60),
|
||||||
|
matchesPersistedRecord,
|
||||||
|
canReuseUnboundTargetRecord,
|
||||||
|
canTrustUserFloorRecord,
|
||||||
|
recordRecallInputMismatch,
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debugWarn("[ST-BME][reroll-trace] reuse ACCEPTED", {
|
||||||
|
generationType,
|
||||||
|
recallSource,
|
||||||
|
targetUserMessageIndex,
|
||||||
|
matchesPersistedRecord,
|
||||||
|
canReuseUnboundTargetRecord,
|
||||||
|
canTrustUserFloorRecord,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
record,
|
record,
|
||||||
targetUserMessageIndex,
|
targetUserMessageIndex,
|
||||||
|
|||||||
Reference in New Issue
Block a user