Add debug log toggle and silence diagnostic logs

This commit is contained in:
Youzini-afk
2026-04-06 11:26:37 +08:00
parent b6187d46e0
commit 8320e3e7f6
23 changed files with 226 additions and 96 deletions

View File

@@ -1,5 +1,7 @@
// ST-BME: 召回输入解析与注入控制器(纯函数)
import { debugLog, debugWarn } from "./debug-logging.js";
export function buildRecallRecentMessagesController(
chat,
limit,
@@ -174,7 +176,7 @@ export function applyRecallInjectionController(
if (injectionText) {
const tokens = runtime.estimateTokens(injectionText);
runtime.console.log(
debugLog(
`[ST-BME] 注入 ${tokens} 估算 tokens, Core=${result.stats.coreCount}, Recall=${result.stats.recallCount}`,
);
runtime.persistRecallInjectionRecord?.({
@@ -287,12 +289,12 @@ export function applyRecallInjectionController(
}
export async function runRecallController(runtime, options = {}) {
console.warn("[ST-BME:DIAG:RECALL] runRecallController entered");
debugWarn("[ST-BME:DIAG:RECALL] runRecallController entered");
if (runtime.getIsRecalling()) {
runtime.abortRecallStageWithReason("旧召回已取消,正在启动新的召回");
const settle = await runtime.waitForActiveRecallToSettle();
if (!settle.settled && runtime.getIsRecalling()) {
console.warn("[ST-BME:DIAG:RECALL] EXIT: 上一轮召回仍在清理");
debugWarn("[ST-BME:DIAG:RECALL] EXIT: 上一轮召回仍在清理");
runtime.setLastRecallStatus(
"召回忙",
"上一轮召回仍在清理,请稍后重试",
@@ -308,18 +310,18 @@ export async function runRecallController(runtime, options = {}) {
}
const hasGraph = !!runtime.getCurrentGraph();
console.warn("[ST-BME:DIAG:RECALL] hasGraph:", hasGraph);
debugWarn("[ST-BME:DIAG:RECALL] hasGraph:", hasGraph);
if (!hasGraph) {
console.warn("[ST-BME:DIAG:RECALL] EXIT: 当前无图谱");
debugWarn("[ST-BME:DIAG:RECALL] EXIT: 当前无图谱");
return runtime.createRecallRunResult("skipped", {
reason: "当前无图谱",
});
}
const settings = runtime.getSettings();
console.warn("[ST-BME:DIAG:RECALL] settings.enabled:", settings.enabled, "recallEnabled:", settings.recallEnabled);
debugWarn("[ST-BME:DIAG:RECALL] settings.enabled:", settings.enabled, "recallEnabled:", settings.recallEnabled);
if (!settings.enabled || !settings.recallEnabled) {
console.warn("[ST-BME:DIAG:RECALL] EXIT: 召回功能未启用");
debugWarn("[ST-BME:DIAG:RECALL] EXIT: 召回功能未启用");
return runtime.createRecallRunResult("skipped", {
reason: "召回功能未启用",
});
@@ -330,10 +332,10 @@ export async function runRecallController(runtime, options = {}) {
: runtime.isGraphReadable();
const chatId = typeof runtime.getCurrentChatId === "function" ? runtime.getCurrentChatId() : "(no fn)";
const loadState = runtime.getGraphPersistenceLoadState?.() || "(no fn)";
console.warn("[ST-BME:DIAG:RECALL] isReadableForRecall:", isReadableForRecall, "chatId:", chatId, "loadState:", loadState);
debugWarn("[ST-BME:DIAG:RECALL] isReadableForRecall:", isReadableForRecall, "chatId:", chatId, "loadState:", loadState);
if (!isReadableForRecall) {
const reason = runtime.getGraphMutationBlockReason("召回");
console.warn("[ST-BME:DIAG:RECALL] EXIT: 图谱不可读 -", reason);
debugWarn("[ST-BME:DIAG:RECALL] EXIT: 图谱不可读 -", reason);
runtime.setLastRecallStatus("等待图谱加载", reason, "warning", {
syncRuntime: true,
});
@@ -407,7 +409,7 @@ export async function runRecallController(runtime, options = {}) {
recallInput.deliveryMode =
String(options.deliveryMode || "immediate").trim() || "immediate";
runtime.console.log("[ST-BME] 开始召回", {
debugLog("[ST-BME] 开始召回", {
source: recallInput.source,
sourceLabel: recallInput.sourceLabel,
hookName: recallInput.hookName,