Fix garbled text checks and L0 LLM handling

This commit is contained in:
2026-02-06 15:08:20 +08:00
parent 44ca06f9b9
commit 56e30bfe02
9 changed files with 163 additions and 48 deletions

View File

@@ -1627,7 +1627,7 @@ function rollbackToPreviousOf(messageId) {
const prevId = id - 1;
if (prevId < 0) return;
// ???? 1.0 ???????
// 1.0: restore from snapshot if available
const snap = getSnapshot(prevId);
if (snap) {
const normalized = normalizeSnapshotRecord(snap);
@@ -1645,7 +1645,7 @@ async function rollbackToPreviousOfAsync(messageId) {
const id = Number(messageId);
if (Number.isNaN(id)) return;
// ???????? floor>=id ? L0
// Notify L0 rollback hook for floor >= id
if (typeof globalThis.LWB_StateRollbackHook === 'function') {
try {
await globalThis.LWB_StateRollbackHook(id);
@@ -1660,7 +1660,7 @@ async function rollbackToPreviousOfAsync(messageId) {
if (mode === '2.0') {
try {
const mod = await import('./state2/index.js');
await mod.restoreStateV2ToFloor(prevId); // prevId<0 ???
await mod.restoreStateV2ToFloor(prevId); // prevId < 0 handled by implementation
} catch (e) {
console.error('[variablesCore][2.0] restoreStateV2ToFloor failed:', e);
}
@@ -1682,7 +1682,7 @@ async function rebuildVariablesFromScratch() {
await mod.restoreStateV2ToFloor(lastId);
return;
}
// 1.0 旧逻辑
// 1.0 legacy logic
setVarDict({});
const chat = getContext()?.chat || [];
for (let i = 0; i < chat.length; i++) {
@@ -1876,7 +1876,7 @@ async function applyVariablesForMessage(messageId) {
} catch (e) {
parseErrors++;
if (debugOn) {
try { xbLog.error(MODULE_ID, `plot-log 解析失败:楼<EFBFBD>?${messageId} <EFBFBD>?${idx + 1} 预览=${preview(b)}`, e); } catch {}
try { xbLog.error(MODULE_ID, `plot-log 解析失败:楼${messageId} ${idx + 1} 预览=${preview(b)}`, e); } catch {}
}
return;
}
@@ -1907,7 +1907,7 @@ async function applyVariablesForMessage(messageId) {
try {
xbLog.warn(
MODULE_ID,
`plot-log 未产生可执行指令:楼<EFBFBD>?${messageId} 块数=${blocks.length} 解析条目=${parsedPartsTotal} 解析失败=${parseErrors} 预览=${preview(blocks[0])}`
`plot-log 未产生可执行指令:楼${messageId} 块数=${blocks.length} 解析条目=${parsedPartsTotal} 解析失败=${parseErrors} 预览=${preview(blocks[0])}`
);
} catch {}
}
@@ -2183,7 +2183,7 @@ async function applyVariablesForMessage(messageId) {
const denied = guardDenied ? `,被规则拦截=${guardDenied}` : '';
xbLog.warn(
MODULE_ID,
`plot-log 指令执行后无变化:楼<EFBFBD>?${messageId} 指令<EFBFBD>?${ops.length}${denied} 示例=${preview(JSON.stringify(guardDeniedSamples))}`
`plot-log 指令执行后无变化:楼${messageId} 指令${ops.length}${denied} 示例=${preview(JSON.stringify(guardDeniedSamples))}`
);
} catch {}
}
@@ -2321,7 +2321,7 @@ function bindEvents() {
if (getVariablesMode() !== '2.0') clearAppliedFor(id);
// ? ?? await????? apply ????????????
// Roll back first so re-apply uses the edited message
await rollbackToPreviousOfAsync(id);
setTimeout(async () => {
@@ -2358,7 +2358,7 @@ function bindEvents() {
lastSwipedId = id;
if (getVariablesMode() !== '2.0') clearAppliedFor(id);
// ? ?? await???????????????
// Roll back first so swipe applies cleanly
await rollbackToPreviousOfAsync(id);
const tId = setTimeout(async () => {
@@ -2377,10 +2377,10 @@ function bindEvents() {
const id = getMsgIdStrict(data);
if (typeof id !== 'number') return;
// ? ????????await ???????
// Roll back first before delete handling
await rollbackToPreviousOfAsync(id);
// 2.0:物理删除消息 => 同步清理 WAL/ckpt避免膨胀
// 2.0: physical delete -> trim WAL/ckpt to avoid bloat
if (getVariablesMode() === '2.0') {
try {
const mod = await import('./state2/index.js');