Fix min activations not checking recursion

5e89dc35e38e53c41365b8d3a108a49ed5912077

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +15 -1Ignore whitespace
public/scripts/world-info.js+15 -1
@@ -300,6 +300,14 @@ class WorldInfoBuffer {
300300 }
301301
302302 /**
303+ * Checks if the recursion buffer is not empty.
304+ * @returns {boolean} Returns true if the recursion buffer is not empty, otherwise false
305+ */
306+ hasRecurse() {
307+ return this.#recurseBuffer.length > 0;
308+ }
309+
310+ /**
303311 * Increments skew and sets startDepth to previous depth.
304312 */
305313 advanceScanPosition() {
@@ -3847,11 +3855,17 @@ async function checkWorldInfo(chat, maxContext, isDryRun) {
38473855 console.debug(`[WI] Sucessfully activated ${successfulNewEntries.length} new entries to prompt. ${allActivatedEntries.size} total entries activated.`, successfulNewEntries);
38483856 }
38493857
38503858 // After processing and rolling entries is done, see if we should continue with normal recursion
38513859 if (world_info_recursive && !token_budget_overflowed && successfulNewEntriesForRecursion.length) {
38523860 nextScanState = scan_state.RECURSION;
38533861 }
38543862
3863+ // If we are inside min activations scan, and we have recursive buffer, we should do a recursive scan before increasing the buffer again
3864+ // There might be recurse-trigger-able entries that match the buffer, so we need to check that
3865+ if (world_info_recursive && !token_budget_overflowed && scanState === scan_state.MIN_ACTIVATIONS && buffer.hasRecurse()) {
3866+ nextScanState = scan_state.RECURSION;
3867+ }
3868+
38553869 // If scanning is planned to stop, but min activations is set and not satisfied, check if we should continue
38563870 const minActivationsNotSatisfied = world_info_min_activations > 0 && (allActivatedEntries.size < world_info_min_activations);
38573871 if (!nextScanState && !token_budget_overflowed && minActivationsNotSatisfied) {