diff --git a/README.md b/README.md index cf5301c..ca088ab 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ example: true - AI_REPO_STOP(): emergency stop - AI_REPO.clearHistory: clear dedupe history -- window.AI_REPO_COMMANDER: monitor, config, tests, history +- window.AI_REPO: monitor, config, tests, history ## Security Model - Bridge key stored locally and masked, never logged diff --git a/src/logger.js b/src/logger.js index 8ac2642..e0c6c91 100644 --- a/src/logger.js +++ b/src/logger.js @@ -31,6 +31,27 @@ this.info(`${icon} ${action} [${status}]`, extra); } + /** + * Special logger for preventing log spam from aggressive loops or frequently repeated operations. + * + * Use this when logging inside tight loops, mutation observers, or frequently-fired events + * to avoid polluting the logs and making it hard to find other information. + * + * Features: + * - Limits each unique message to max 10 occurrences + * - Only logs within the watch window (default 120s from logger start) + * - Shows occurrence count (e.g., "Processing message (3x)") + * - WARN messages bypass the time window restriction + * + * @param {string} kind - Log level: 'ERROR', 'WARN', or 'INFO' + * @param {string} msg - The message to log + * + * @example + * // Inside a mutation observer that fires rapidly: + * observer.observe(() => { + * log.logLoop('INFO', 'Processing DOM mutation'); // Won't spam after 10 times + * }); + */ logLoop(kind, msg) { const k = `${kind}:${msg}`; const cur = this.loopCounts.get(k) || 0; diff --git a/src/paste-submit.js b/src/paste-submit.js index eea8af8..f9d8a73 100644 --- a/src/paste-submit.js +++ b/src/paste-submit.js @@ -6,7 +6,7 @@ const log = () => window.AI_REPO_LOGGER; function findComposer() { - const sels = [ + const selectors = [ '#prompt-textarea', '.ProseMirror#prompt-textarea', '.ProseMirror[role="textbox"][contenteditable="true"]', @@ -17,7 +17,7 @@ 'textarea', '[contenteditable="true"]' ]; - for (const s of sels) { + for (const s of selectors) { const el = document.querySelector(s); if (!el) continue; const st = window.getComputedStyle(el);