From 8316594fe27fd1093581d129b5c1221b8c1a1e48 Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Mon, 6 Apr 2026 19:26:12 +0800 Subject: [PATCH 1/5] =?UTF-8?q?debug:=20Recall=20Card=20=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=BB=9F=E4=B8=80=E5=89=8D=E7=BC=80=20ST-BME?= =?UTF-8?q?|DBG|recall-card-ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 87849ce..2a63c94 100644 --- a/index.js +++ b/index.js @@ -584,6 +584,8 @@ const PERSISTED_RECALL_UI_REFRESH_RETRY_DELAYS_MS = [ 3000, 4200, ]; +/** Ingest / NDJSON:搜索此固定串可只看 Recall Card UI 调试行 */ +const BME_DEBUG_RECALL_CARD_UI = "ST-BME|DBG|recall-card-ui"; const PERSISTED_RECALL_UI_DIAGNOSTIC_THROTTLE_MS = 1500; const persistedRecallUiDiagnosticTimestamps = new Map(); const persistedRecallPersistDiagnosticTimestamps = new Map(); @@ -1792,7 +1794,7 @@ function ensurePersistedRecallRecordForGeneration({ ); // #region agent log - {fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:ensurePersistedRecallRecordForGeneration',message:'target resolved',data:{targetUserMessageIndex,chatLen:chat.length,isUser:chat[targetUserMessageIndex]?.is_user,generationType,hookName:String(hookName||''),injectionTextLen:injectionText?.length||0},timestamp:Date.now()})}).catch(()=>{});} + {fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:ensurePersistedRecallRecordForGeneration',message:`${BME_DEBUG_RECALL_CARD_UI} target resolved`,data:{targetUserMessageIndex,chatLen:chat.length,isUser:chat[targetUserMessageIndex]?.is_user,generationType,hookName:String(hookName||''),injectionTextLen:injectionText?.length||0},timestamp:Date.now()})}).catch(()=>{});} // #endregion if ( !Number.isFinite(targetUserMessageIndex) || @@ -2551,7 +2553,7 @@ function refreshPersistedRecallMessageUi() { }; // #region agent log - {const _latestUserIdx=chat.reduce((a,m,i)=>m?.is_user?i:a,-1);const _domKeys=[...messageElementMap.keys()];const _hasRecord=_latestUserIdx>=0&&!!readPersistedRecallFromUserMessage(chat,_latestUserIdx);const _hasDom=_latestUserIdx>=0&&messageElementMap.has(_latestUserIdx);fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:loop-start',message:'refresh loop entry',data:{chatLen:chat.length,domElementCount:_domKeys.length,domKeys:_domKeys.slice(-6),latestUserIdx:_latestUserIdx,hasRecordForLatest:_hasRecord,hasDomForLatest:_hasDom},timestamp:Date.now()})}).catch(()=>{});} + {const _latestUserIdx=chat.reduce((a,m,i)=>m?.is_user?i:a,-1);const _domKeys=[...messageElementMap.keys()];const _hasRecord=_latestUserIdx>=0&&!!readPersistedRecallFromUserMessage(chat,_latestUserIdx);const _hasDom=_latestUserIdx>=0&&messageElementMap.has(_latestUserIdx);fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:loop-start',message:`${BME_DEBUG_RECALL_CARD_UI} refresh loop entry`,data:{chatLen:chat.length,domElementCount:_domKeys.length,domKeys:_domKeys.slice(-6),latestUserIdx:_latestUserIdx,hasRecordForLatest:_hasRecord,hasDomForLatest:_hasDom},timestamp:Date.now()})}).catch(()=>{});} // #endregion for (let messageIndex = 0; messageIndex < chat.length; messageIndex++) { const message = chat[messageIndex]; @@ -2585,7 +2587,7 @@ function refreshPersistedRecallMessageUi() { const record = readPersistedRecallFromUserMessage(chat, messageIndex); // #region agent log - if(message?.is_user){const _isLatestUser=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:latest-user-check',message:'latest user msg detail',data:{messageIndex,hasRecord:!!record?.injectionText,hasDom:!!messageElement,hasExistingCard:!!existingCard,domMesid:messageElement?.getAttribute?.('mesid'),domDataMesid:messageElement?.getAttribute?.('data-mesid'),domClasses:messageElement?.className?.slice(0,80)||''},timestamp:Date.now()})}).catch(()=>{});}} + if(message?.is_user){const _isLatestUser=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:latest-user-check',message:`${BME_DEBUG_RECALL_CARD_UI} latest user msg detail`,data:{messageIndex,hasRecord:!!record?.injectionText,hasDom:!!messageElement,hasExistingCard:!!existingCard,domMesid:messageElement?.getAttribute?.('mesid'),domDataMesid:messageElement?.getAttribute?.('data-mesid'),domClasses:messageElement?.className?.slice(0,80)||''},timestamp:Date.now()})}).catch(()=>{});}} // #endregion if (!record?.injectionText) { if (messageElement) { @@ -2655,7 +2657,7 @@ function refreshPersistedRecallMessageUi() { ); summary.renderedCount += 1; // #region agent log - {const _isLatestUser2=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser2){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:card-mounted',message:'card mounted for latest user',data:{messageIndex,hadExistingCard:!!currentCard,cardInDom:!!messageElement.querySelector('.bme-recall-card')},timestamp:Date.now()})}).catch(()=>{});}} + {const _isLatestUser2=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser2){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:card-mounted',message:`${BME_DEBUG_RECALL_CARD_UI} card mounted for latest user`,data:{messageIndex,hadExistingCard:!!currentCard,cardInDom:!!messageElement.querySelector('.bme-recall-card')},timestamp:Date.now()})}).catch(()=>{});}} // #endregion } @@ -2674,7 +2676,7 @@ function refreshPersistedRecallMessageUi() { ); } // #region agent log - fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:summary',message:'refresh complete',data:{status:summary.status,renderedCount:summary.renderedCount,persistedRecordCount:summary.persistedRecordCount,waitingDom:summary.waitingMessageIndices,anchorFail:summary.anchorFailureIndices},timestamp:Date.now()})}).catch(()=>{}); + fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:summary',message:`${BME_DEBUG_RECALL_CARD_UI} refresh complete`,data:{status:summary.status,renderedCount:summary.renderedCount,persistedRecordCount:summary.persistedRecordCount,waitingDom:summary.waitingMessageIndices,anchorFail:summary.anchorFailureIndices},timestamp:Date.now()})}).catch(()=>{}); // #endregion return summary; } @@ -2768,7 +2770,7 @@ function armPersistedRecallMessageUiObserver(sessionId, runAttempt) { function schedulePersistedRecallMessageUiRefresh(delayMs = 0) { // #region agent log - {const _prevSession=persistedRecallUiRefreshSession;const _caller=new Error().stack?.split('\n')?.[2]?.trim()?.slice(0,120)||'';fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({sessionId:'b6ba57',location:'index.js:schedulePersistedRecallMessageUiRefresh',message:'schedule called',data:{delayMs,prevSession:_prevSession,nextSession:_prevSession+1,caller:_caller},timestamp:Date.now()})}).catch(()=>{});} + {const _prevSession=persistedRecallUiRefreshSession;const _caller=new Error().stack?.split('\n')?.[2]?.trim()?.slice(0,120)||'';fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:schedulePersistedRecallMessageUiRefresh',message:`${BME_DEBUG_RECALL_CARD_UI} schedule refresh called`,data:{delayMs,prevSession:_prevSession,nextSession:_prevSession+1,caller:_caller},timestamp:Date.now()})}).catch(()=>{});} // #endregion clearTimeout(persistedRecallUiRefreshTimer); clearPersistedRecallMessageUiObserver(); From f1cf0fa652de54e52a3bb694d13289a2c32a94db Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Mon, 6 Apr 2026 19:31:55 +0800 Subject: [PATCH 2/5] =?UTF-8?q?debug:=20Recall=20Card=20=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E5=90=8C=E6=97=B6=20console.info=EF=BC=8C=E4=BE=BF=E4=BA=8E?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=8F=B0=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- index.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 2a63c94..2690127 100644 --- a/index.js +++ b/index.js @@ -586,6 +586,29 @@ const PERSISTED_RECALL_UI_REFRESH_RETRY_DELAYS_MS = [ ]; /** Ingest / NDJSON:搜索此固定串可只看 Recall Card UI 调试行 */ const BME_DEBUG_RECALL_CARD_UI = "ST-BME|DBG|recall-card-ui"; +const BME_DEBUG_RECALL_CARD_UI_INGEST = + "http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85"; +function bmePostRecallCardUiDebug(partial) { + const payload = { + bmeDbgTag: BME_DEBUG_RECALL_CARD_UI, + sessionId: "b6ba57", + ...partial, + timestamp: Date.now(), + }; + try { + if (typeof console?.info === "function") { + console.info(BME_DEBUG_RECALL_CARD_UI, payload.message, payload); + } + } catch (_) {} + fetch(BME_DEBUG_RECALL_CARD_UI_INGEST, { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-Debug-Session-Id": "b6ba57", + }, + body: JSON.stringify(payload), + }).catch(() => {}); +} const PERSISTED_RECALL_UI_DIAGNOSTIC_THROTTLE_MS = 1500; const persistedRecallUiDiagnosticTimestamps = new Map(); const persistedRecallPersistDiagnosticTimestamps = new Map(); @@ -1794,7 +1817,7 @@ function ensurePersistedRecallRecordForGeneration({ ); // #region agent log - {fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:ensurePersistedRecallRecordForGeneration',message:`${BME_DEBUG_RECALL_CARD_UI} target resolved`,data:{targetUserMessageIndex,chatLen:chat.length,isUser:chat[targetUserMessageIndex]?.is_user,generationType,hookName:String(hookName||''),injectionTextLen:injectionText?.length||0},timestamp:Date.now()})}).catch(()=>{});} + {bmePostRecallCardUiDebug({location:'index.js:ensurePersistedRecallRecordForGeneration',message:`${BME_DEBUG_RECALL_CARD_UI} target resolved`,data:{targetUserMessageIndex,chatLen:chat.length,isUser:chat[targetUserMessageIndex]?.is_user,generationType,hookName:String(hookName||''),injectionTextLen:injectionText?.length||0}});} // #endregion if ( !Number.isFinite(targetUserMessageIndex) || @@ -2553,7 +2576,7 @@ function refreshPersistedRecallMessageUi() { }; // #region agent log - {const _latestUserIdx=chat.reduce((a,m,i)=>m?.is_user?i:a,-1);const _domKeys=[...messageElementMap.keys()];const _hasRecord=_latestUserIdx>=0&&!!readPersistedRecallFromUserMessage(chat,_latestUserIdx);const _hasDom=_latestUserIdx>=0&&messageElementMap.has(_latestUserIdx);fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:loop-start',message:`${BME_DEBUG_RECALL_CARD_UI} refresh loop entry`,data:{chatLen:chat.length,domElementCount:_domKeys.length,domKeys:_domKeys.slice(-6),latestUserIdx:_latestUserIdx,hasRecordForLatest:_hasRecord,hasDomForLatest:_hasDom},timestamp:Date.now()})}).catch(()=>{});} + {const _latestUserIdx=chat.reduce((a,m,i)=>m?.is_user?i:a,-1);const _domKeys=[...messageElementMap.keys()];const _hasRecord=_latestUserIdx>=0&&!!readPersistedRecallFromUserMessage(chat,_latestUserIdx);const _hasDom=_latestUserIdx>=0&&messageElementMap.has(_latestUserIdx);bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:loop-start',message:`${BME_DEBUG_RECALL_CARD_UI} refresh loop entry`,data:{chatLen:chat.length,domElementCount:_domKeys.length,domKeys:_domKeys.slice(-6),latestUserIdx:_latestUserIdx,hasRecordForLatest:_hasRecord,hasDomForLatest:_hasDom}});} // #endregion for (let messageIndex = 0; messageIndex < chat.length; messageIndex++) { const message = chat[messageIndex]; @@ -2587,7 +2610,7 @@ function refreshPersistedRecallMessageUi() { const record = readPersistedRecallFromUserMessage(chat, messageIndex); // #region agent log - if(message?.is_user){const _isLatestUser=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:latest-user-check',message:`${BME_DEBUG_RECALL_CARD_UI} latest user msg detail`,data:{messageIndex,hasRecord:!!record?.injectionText,hasDom:!!messageElement,hasExistingCard:!!existingCard,domMesid:messageElement?.getAttribute?.('mesid'),domDataMesid:messageElement?.getAttribute?.('data-mesid'),domClasses:messageElement?.className?.slice(0,80)||''},timestamp:Date.now()})}).catch(()=>{});}} + if(message?.is_user){const _isLatestUser=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser){bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:latest-user-check',message:`${BME_DEBUG_RECALL_CARD_UI} latest user msg detail`,data:{messageIndex,hasRecord:!!record?.injectionText,hasDom:!!messageElement,hasExistingCard:!!existingCard,domMesid:messageElement?.getAttribute?.('mesid'),domDataMesid:messageElement?.getAttribute?.('data-mesid'),domClasses:messageElement?.className?.slice(0,80)||''}});}} // #endregion if (!record?.injectionText) { if (messageElement) { @@ -2657,7 +2680,7 @@ function refreshPersistedRecallMessageUi() { ); summary.renderedCount += 1; // #region agent log - {const _isLatestUser2=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser2){fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:card-mounted',message:`${BME_DEBUG_RECALL_CARD_UI} card mounted for latest user`,data:{messageIndex,hadExistingCard:!!currentCard,cardInDom:!!messageElement.querySelector('.bme-recall-card')},timestamp:Date.now()})}).catch(()=>{});}} + {const _isLatestUser2=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser2){bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:card-mounted',message:`${BME_DEBUG_RECALL_CARD_UI} card mounted for latest user`,data:{messageIndex,hadExistingCard:!!currentCard,cardInDom:!!messageElement.querySelector('.bme-recall-card')}});}} // #endregion } @@ -2676,7 +2699,7 @@ function refreshPersistedRecallMessageUi() { ); } // #region agent log - fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:refreshPersistedRecallMessageUi:summary',message:`${BME_DEBUG_RECALL_CARD_UI} refresh complete`,data:{status:summary.status,renderedCount:summary.renderedCount,persistedRecordCount:summary.persistedRecordCount,waitingDom:summary.waitingMessageIndices,anchorFail:summary.anchorFailureIndices},timestamp:Date.now()})}).catch(()=>{}); + bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:summary',message:`${BME_DEBUG_RECALL_CARD_UI} refresh complete`,data:{status:summary.status,renderedCount:summary.renderedCount,persistedRecordCount:summary.persistedRecordCount,waitingDom:summary.waitingMessageIndices,anchorFail:summary.anchorFailureIndices}}); // #endregion return summary; } @@ -2770,7 +2793,7 @@ function armPersistedRecallMessageUiObserver(sessionId, runAttempt) { function schedulePersistedRecallMessageUiRefresh(delayMs = 0) { // #region agent log - {const _prevSession=persistedRecallUiRefreshSession;const _caller=new Error().stack?.split('\n')?.[2]?.trim()?.slice(0,120)||'';fetch('http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85',{method:'POST',headers:{'Content-Type':'application/json','X-Debug-Session-Id':'b6ba57'},body:JSON.stringify({bmeDbgTag:BME_DEBUG_RECALL_CARD_UI,sessionId:'b6ba57',location:'index.js:schedulePersistedRecallMessageUiRefresh',message:`${BME_DEBUG_RECALL_CARD_UI} schedule refresh called`,data:{delayMs,prevSession:_prevSession,nextSession:_prevSession+1,caller:_caller},timestamp:Date.now()})}).catch(()=>{});} + {const _prevSession=persistedRecallUiRefreshSession;const _caller=new Error().stack?.split('\n')?.[2]?.trim()?.slice(0,120)||'';bmePostRecallCardUiDebug({location:'index.js:schedulePersistedRecallMessageUiRefresh',message:`${BME_DEBUG_RECALL_CARD_UI} schedule refresh called`,data:{delayMs,prevSession:_prevSession,nextSession:_prevSession+1,caller:_caller}});} // #endregion clearTimeout(persistedRecallUiRefreshTimer); clearPersistedRecallMessageUiObserver(); From 665c547ee370be198c6739743333009066193e98 Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Mon, 6 Apr 2026 19:37:27 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20Recall=20Card=20=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E5=9F=8B=E7=82=B9=E5=8F=97=E9=9D=A2=E6=9D=BF=E3=80=8C=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E3=80=8D=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=EF=BC=9B=E6=8E=A7=E5=88=B6=E5=8F=B0=E8=8A=82=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- index.js | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2690127..589cd5d 100644 --- a/index.js +++ b/index.js @@ -75,6 +75,7 @@ import { import { debugDebug, debugLog, + isDebugLoggingEnabled, } from "./debug-logging.js"; import { extractMemories, @@ -588,18 +589,19 @@ const PERSISTED_RECALL_UI_REFRESH_RETRY_DELAYS_MS = [ const BME_DEBUG_RECALL_CARD_UI = "ST-BME|DBG|recall-card-ui"; const BME_DEBUG_RECALL_CARD_UI_INGEST = "http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85"; +const BME_DEBUG_RECALL_CARD_UI_CONSOLE_THROTTLE_MS = 2500; +let bmeRecallCardUiConsolePending = 0; +let bmeRecallCardUiConsoleLastFlush = 0; function bmePostRecallCardUiDebug(partial) { + if (!isDebugLoggingEnabled(getSettings())) { + return; + } const payload = { bmeDbgTag: BME_DEBUG_RECALL_CARD_UI, sessionId: "b6ba57", ...partial, timestamp: Date.now(), }; - try { - if (typeof console?.info === "function") { - console.info(BME_DEBUG_RECALL_CARD_UI, payload.message, payload); - } - } catch (_) {} fetch(BME_DEBUG_RECALL_CARD_UI_INGEST, { method: "POST", headers: { @@ -608,6 +610,35 @@ function bmePostRecallCardUiDebug(partial) { }, body: JSON.stringify(payload), }).catch(() => {}); + + try { + if (typeof console?.info !== "function") return; + const verbose = + typeof globalThis !== "undefined" && + globalThis.__ST_BME_RECALL_CARD_UI_VERBOSE_CONSOLE === true; + if (verbose) { + console.info(BME_DEBUG_RECALL_CARD_UI, payload.message, payload); + return; + } + bmeRecallCardUiConsolePending += 1; + const now = Date.now(); + if ( + now - bmeRecallCardUiConsoleLastFlush < + BME_DEBUG_RECALL_CARD_UI_CONSOLE_THROTTLE_MS + ) { + return; + } + const batched = bmeRecallCardUiConsolePending; + bmeRecallCardUiConsolePending = 0; + bmeRecallCardUiConsoleLastFlush = now; + console.info( + BME_DEBUG_RECALL_CARD_UI, + partial.message, + partial.location, + partial.data, + batched > 1 ? `(×${batched})` : "", + ); + } catch (_) {} } const PERSISTED_RECALL_UI_DIAGNOSTIC_THROTTLE_MS = 1500; const persistedRecallUiDiagnosticTimestamps = new Map(); From f42295fe80928bab54c1ac16298e686bb237bdb9 Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Mon, 6 Apr 2026 19:43:32 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20normal=20=E6=A8=A1=E5=BC=8F=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=A7=A3=E6=9E=90=E6=9C=80=E6=96=B0=20user=20?= =?UTF-8?q?=E6=A5=BC=E5=B1=82=E4=BB=A5=E6=8C=81=E4=B9=85=E5=8C=96=20Recall?= =?UTF-8?q?=20Card=EF=BC=9B=E5=85=B3=E9=97=AD=E6=B8=B2=E6=9F=93=E5=90=8E?= =?UTF-8?q?=20MutationObserver=20=E9=A3=8E=E6=9A=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- index.js | 5 +++-- recall-persistence.js | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 589cd5d..44bc789 100644 --- a/index.js +++ b/index.js @@ -2848,8 +2848,9 @@ function schedulePersistedRecallMessageUiRefresh(delayMs = 0) { summary.status === "missing_message_anchor") && attemptIndex < retryDelays.length - 1; - const shouldWatchForRepaint = - summary.status === "rendered" && summary.renderedCount > 0; + // 勿在「已成功渲染」时长期挂 MutationObserver:#chat 上 class/流式更新会疯狂触发 + // runAttempt,造成满屏刷新与日志;显式事件(USER_MESSAGE_RENDERED 等)仍会 schedule 刷新。 + const shouldWatchForRepaint = false; if (!shouldRetryForPending && !shouldWatchForRepaint) { clearPersistedRecallMessageUiObserver(); diff --git a/recall-persistence.js b/recall-persistence.js index 1eaf898..b418474 100644 --- a/recall-persistence.js +++ b/recall-persistence.js @@ -134,11 +134,13 @@ export function resolveGenerationTargetUserMessageIndex( const normalizedType = String(generationType || "normal").trim() || "normal"; + // normal:取「最后一条非系统用户楼层」。若直接 return 末条非 user(常见为刚追加的助手回合), + // 会得到 null,导致持久化无法回绑到本轮 user,`hasRecordForLatest` 长期为 false。 if (normalizedType === "normal") { for (let index = chat.length - 1; index >= 0; index--) { const message = chat[index]; if (message?.is_system) continue; - return message?.is_user ? index : null; + if (message?.is_user) return index; } return null; } From a0c706e41066f6fddff7ea55d4901571ae89dd5e Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Mon, 6 Apr 2026 19:46:22 +0800 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=20Recall=20Card?= =?UTF-8?q?=20=E6=9C=AC=E5=9C=B0=20ingest=20=E7=AB=AF=E5=8F=A3=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E5=9F=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- index.js | 74 -------------------------------------------------------- 1 file changed, 74 deletions(-) diff --git a/index.js b/index.js index 44bc789..b1a29a0 100644 --- a/index.js +++ b/index.js @@ -75,7 +75,6 @@ import { import { debugDebug, debugLog, - isDebugLoggingEnabled, } from "./debug-logging.js"; import { extractMemories, @@ -585,61 +584,6 @@ const PERSISTED_RECALL_UI_REFRESH_RETRY_DELAYS_MS = [ 3000, 4200, ]; -/** Ingest / NDJSON:搜索此固定串可只看 Recall Card UI 调试行 */ -const BME_DEBUG_RECALL_CARD_UI = "ST-BME|DBG|recall-card-ui"; -const BME_DEBUG_RECALL_CARD_UI_INGEST = - "http://127.0.0.1:7433/ingest/799bfe5d-077f-41ac-bcda-da9f93fe5a85"; -const BME_DEBUG_RECALL_CARD_UI_CONSOLE_THROTTLE_MS = 2500; -let bmeRecallCardUiConsolePending = 0; -let bmeRecallCardUiConsoleLastFlush = 0; -function bmePostRecallCardUiDebug(partial) { - if (!isDebugLoggingEnabled(getSettings())) { - return; - } - const payload = { - bmeDbgTag: BME_DEBUG_RECALL_CARD_UI, - sessionId: "b6ba57", - ...partial, - timestamp: Date.now(), - }; - fetch(BME_DEBUG_RECALL_CARD_UI_INGEST, { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-Debug-Session-Id": "b6ba57", - }, - body: JSON.stringify(payload), - }).catch(() => {}); - - try { - if (typeof console?.info !== "function") return; - const verbose = - typeof globalThis !== "undefined" && - globalThis.__ST_BME_RECALL_CARD_UI_VERBOSE_CONSOLE === true; - if (verbose) { - console.info(BME_DEBUG_RECALL_CARD_UI, payload.message, payload); - return; - } - bmeRecallCardUiConsolePending += 1; - const now = Date.now(); - if ( - now - bmeRecallCardUiConsoleLastFlush < - BME_DEBUG_RECALL_CARD_UI_CONSOLE_THROTTLE_MS - ) { - return; - } - const batched = bmeRecallCardUiConsolePending; - bmeRecallCardUiConsolePending = 0; - bmeRecallCardUiConsoleLastFlush = now; - console.info( - BME_DEBUG_RECALL_CARD_UI, - partial.message, - partial.location, - partial.data, - batched > 1 ? `(×${batched})` : "", - ); - } catch (_) {} -} const PERSISTED_RECALL_UI_DIAGNOSTIC_THROTTLE_MS = 1500; const persistedRecallUiDiagnosticTimestamps = new Map(); const persistedRecallPersistDiagnosticTimestamps = new Map(); @@ -1847,9 +1791,6 @@ function ensurePersistedRecallRecordForGeneration({ }, ); - // #region agent log - {bmePostRecallCardUiDebug({location:'index.js:ensurePersistedRecallRecordForGeneration',message:`${BME_DEBUG_RECALL_CARD_UI} target resolved`,data:{targetUserMessageIndex,chatLen:chat.length,isUser:chat[targetUserMessageIndex]?.is_user,generationType,hookName:String(hookName||''),injectionTextLen:injectionText?.length||0}});} - // #endregion if ( !Number.isFinite(targetUserMessageIndex) || !chat[targetUserMessageIndex]?.is_user @@ -2606,9 +2547,6 @@ function refreshPersistedRecallMessageUi() { skippedNonUserIndices: [], }; - // #region agent log - {const _latestUserIdx=chat.reduce((a,m,i)=>m?.is_user?i:a,-1);const _domKeys=[...messageElementMap.keys()];const _hasRecord=_latestUserIdx>=0&&!!readPersistedRecallFromUserMessage(chat,_latestUserIdx);const _hasDom=_latestUserIdx>=0&&messageElementMap.has(_latestUserIdx);bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:loop-start',message:`${BME_DEBUG_RECALL_CARD_UI} refresh loop entry`,data:{chatLen:chat.length,domElementCount:_domKeys.length,domKeys:_domKeys.slice(-6),latestUserIdx:_latestUserIdx,hasRecordForLatest:_hasRecord,hasDomForLatest:_hasDom}});} - // #endregion for (let messageIndex = 0; messageIndex < chat.length; messageIndex++) { const message = chat[messageIndex]; const messageElement = messageElementMap.get(messageIndex) || null; @@ -2640,9 +2578,6 @@ function refreshPersistedRecallMessageUi() { } const record = readPersistedRecallFromUserMessage(chat, messageIndex); - // #region agent log - if(message?.is_user){const _isLatestUser=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser){bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:latest-user-check',message:`${BME_DEBUG_RECALL_CARD_UI} latest user msg detail`,data:{messageIndex,hasRecord:!!record?.injectionText,hasDom:!!messageElement,hasExistingCard:!!existingCard,domMesid:messageElement?.getAttribute?.('mesid'),domDataMesid:messageElement?.getAttribute?.('data-mesid'),domClasses:messageElement?.className?.slice(0,80)||''}});}} - // #endregion if (!record?.injectionText) { if (messageElement) { restoreRecallCardUserInputDisplay(messageElement); @@ -2710,9 +2645,6 @@ function refreshPersistedRecallMessageUi() { recallCardUserInputDisplayMode, ); summary.renderedCount += 1; - // #region agent log - {const _isLatestUser2=messageIndex===chat.reduce((a,m,i)=>m?.is_user?i:a,-1);if(_isLatestUser2){bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:card-mounted',message:`${BME_DEBUG_RECALL_CARD_UI} card mounted for latest user`,data:{messageIndex,hadExistingCard:!!currentCard,cardInDom:!!messageElement.querySelector('.bme-recall-card')}});}} - // #endregion } summary.status = summarizePersistedRecallRefreshStatus(summary); @@ -2729,9 +2661,6 @@ function refreshPersistedRecallMessageUi() { `rendered:${summary.renderedCount}`, ); } - // #region agent log - bmePostRecallCardUiDebug({location:'index.js:refreshPersistedRecallMessageUi:summary',message:`${BME_DEBUG_RECALL_CARD_UI} refresh complete`,data:{status:summary.status,renderedCount:summary.renderedCount,persistedRecordCount:summary.persistedRecordCount,waitingDom:summary.waitingMessageIndices,anchorFail:summary.anchorFailureIndices}}); - // #endregion return summary; } @@ -2823,9 +2752,6 @@ function armPersistedRecallMessageUiObserver(sessionId, runAttempt) { } function schedulePersistedRecallMessageUiRefresh(delayMs = 0) { - // #region agent log - {const _prevSession=persistedRecallUiRefreshSession;const _caller=new Error().stack?.split('\n')?.[2]?.trim()?.slice(0,120)||'';bmePostRecallCardUiDebug({location:'index.js:schedulePersistedRecallMessageUiRefresh',message:`${BME_DEBUG_RECALL_CARD_UI} schedule refresh called`,data:{delayMs,prevSession:_prevSession,nextSession:_prevSession+1,caller:_caller}});} - // #endregion clearTimeout(persistedRecallUiRefreshTimer); clearPersistedRecallMessageUiObserver();