Expand logging for WI and scan states

413f6a03793c83fa1f80d1f46e7e27738766f457

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +23 -5Ignore whitespace
public/scripts/world-info.js+23 -5
@@ -3728,6 +3728,9 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
37283728 )].sort((a, b) => a - b);
37293729 // Already preset with the first level
37303730 let currentRecursionDelayLevel = availableRecursionDelayLevels.shift() ?? 0;
3731+ if (currentRecursionDelayLevel > 0 && availableRecursionDelayLevels.length) {
3732+ console.debug('[WI] Preparing first delayed recursion level', currentRecursionDelayLevel, '. Still delayed:', availableRecursionDelayLevels);
3733+ }
37313734
37323735 console.debug(`[WI] --- SEARCHING ENTRIES (on ${sortedEntries.length} entries) ---`);
37333736
@@ -3741,7 +3744,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
37413744 // Track how many times the loop has run. May be useful for debugging.
37423745 count++;
37433746
37443747 console.debug(`[WI] Loop--- LOOP #${count}. SearchSTART state---`, Object.entries(scan_state).find(x => x[1] === scanState));
3748+ console.debug(`[WI] Scan state`, Object.entries(scan_state).find(x => x[1] === scanState));
37453749
37463750 // Until decided otherwise, we set the loop to stop scanning after this
37473751 let nextScanState = scan_state.NONE;
@@ -3821,7 +3825,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
38213825 }
38223826
38233827 if (scanState === scan_state.RECURSION && entry.delayUntilRecursion && entry.delayUntilRecursion > currentRecursionDelayLevel && !isSticky) {
38243828 log('suppressed by delay until recursion and having alevel', higherentry.delayUntilRecursion, recursion'. levelCurrently', currentRecursionDelayLevel);
38253829 continue;
38263830 }
38273831
@@ -3963,6 +3967,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
39633967 filterByInclusionGroups(newEntries, allActivatedEntries, buffer, scanState, timedEffects);
39643968
39653969 console.debug('[WI] --- PROBABILITY CHECKS ---');
3970+ !newEntries.length && console.debug('[WI] No probability checks to do');
3971+
39663972 for (const entry of newEntries) {
39673973 function verifyProbability() {
39683974 // If we don't need to roll, it's always true
@@ -3998,6 +4004,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
39984004 newContent += `${entry.content}\n`;
39994005
40004006 if ((textToScanTokens + (await getTokenCountAsync(newContent))) >= budget) {
4007+ console.debug('[WI] --- BUDGET OVERFLOW CHECK ---');
40014008 if (world_info_overflow_alert) {
40024009 console.warn(`[WI] budget of ${budget} reached, stopping after ${allActivatedEntries.size} entries`);
40034010 toastr.warning(`World info budget reached after ${allActivatedEntries.size} entries.`, 'World Info');
@@ -4015,23 +4022,31 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
40154022 const successfulNewEntries = newEntries.filter(x => !failedProbabilityChecks.has(x));
40164023 const successfulNewEntriesForRecursion = successfulNewEntries.filter(x => !x.preventRecursion);
40174024
4025+ console.debug(`[WI] --- LOOP #${count} RESULT ---`);
40184026 if (!newEntries.length) {
40194027 console.debug('[WI] No new entries activated, stopping.');
40204028 } else if (!successfulNewEntries.length) {
40214029 console.debug('[WI] Probability checks failed for all activated entries,. stoppingNo new entries activated.');
40224030 } else {
40234031 console.debug(`[WI] Successfully activated ${successfulNewEntries.length} new entries to prompt. ${allActivatedEntries.size} total entries activated.`, successfulNewEntries);
40244032 }
40254033
4034+ function logNextState(...args) {
4035+ args.length && console.debug(args.shift(), ...args);
4036+ console.debug('[WI] Setting scan state', Object.entries(scan_state).find(x => x[1] === scanState));
4037+ }
4038+
40264039 // After processing and rolling entries is done, see if we should continue with normal recursion
40274040 if (world_info_recursive && !token_budget_overflowed && successfulNewEntriesForRecursion.length) {
40284041 nextScanState = scan_state.RECURSION;
4042+ logNextState('[WI] Found', successfulNewEntriesForRecursion.length, 'new entries for recursion');
40294043 }
40304044
40314045 // If we are inside min activations scan, and we have recursive buffer, we should do a recursive scan before increasing the buffer again
40324046 // There might be recurse-trigger-able entries that match the buffer, so we need to check that
40334047 if (world_info_recursive && !token_budget_overflowed && scanState === scan_state.MIN_ACTIVATIONS && buffer.hasRecurse()) {
40344048 nextScanState = scan_state.RECURSION;
4049+ logNextState('[WI] Min Activations run done, whill will always be followed by a recursive scan');
40354050 }
40364051
40374052 // If scanning is planned to stop, but min activations is set and not satisfied, check if we should continue
@@ -4045,8 +4060,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
40454060 ) || (buffer.getDepth() > chat.length);
40464061
40474062 if (!over_max) {
4048- console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), advancing depth to ${buffer.getDepth() + 1} and checking again`);
40494063 nextScanState = scan_state.MIN_ACTIVATIONS; // loop
4064+ logNextState(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), advancing depth to ${buffer.getDepth() + 1}, starting another scan`);
40504065 buffer.advanceScan();
40514066 } else {
40524067 console.debug(`[WI] Min activations not reached (${allActivatedEntries.size}/${world_info_min_activations}), but reached on of depth. Stopping`);
@@ -4057,6 +4072,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
40574072 if (nextScanState === scan_state.NONE && availableRecursionDelayLevels.length) {
40584073 nextScanState = scan_state.RECURSION;
40594074 currentRecursionDelayLevel = availableRecursionDelayLevels.shift();
4075+ logNextState('[WI] Open delayed recursion levels left. Preparing next delayed recursion level', currentRecursionDelayLevel, '. Still delayed:', availableRecursionDelayLevels);
40604076 }
40614077
40624078 // Final check if we should really continue scan, and extend the current WI recurse buffer
@@ -4066,6 +4082,8 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
40664082 .map(x => x.content).join('\n');
40674083 buffer.addRecurse(text);
40684084 allActivatedText = (text + '\n' + allActivatedText);
4085+ } else {
4086+ logNextState('[WI] Scan done. No new entries to prompt. Stopping.');
40694087 }
40704088 }
40714089