diff options
Diffstat (limited to 'main.html')
| -rw-r--r-- | main.html | 112 |
1 files changed, 107 insertions, 5 deletions
@@ -1342,13 +1342,13 @@ </script> <!-- v4.5.63: A2A scratchpad fixes + agent-register arg fix --> -<script src="modules/core/core-bundle.js?v=2026-06-30-v4.5.83"></script> +<script src="modules/core/core-bundle.js?v=v4.6.10"></script> <!-- Async dependency-ordered module loader now only initializes terminal and loads optional ext modules --> -<script src="modules/core/module-loader.js?v=2026-06-30-v4.5.83"></script> +<script src="modules/core/module-loader.js?v=v4.6.10"></script> <!-- Critical ext bundle loads AFTER webx11 exists so registerModule calls work --> -<script src="modules/ext/critical-ext-bundle.js?v=2026-06-30-v4.5.83"></script> +<script src="modules/ext/critical-ext-bundle.js?v=v4.6.10"></script> <script> // ═══ ONE TRUE VERSION SOURCE ═══ @@ -1357,8 +1357,8 @@ var version = 'v4.0'; // fallback var scripts = document.getElementsByTagName('script'); for (var i = 0; i < scripts.length; i++) { - var m = scripts[i].src && scripts[i].src.match(/module-loader\.js\?.*-v([\d.]+)/); - if (m) { version = 'v' + m[1]; break; } + var m = scripts[i].src && scripts[i].src.match(/module-loader\.js\?v=([v\d\.]+)/); + if (m) { version = m[1]; break; } } window.NEWOS4_VERSION = version; var el = document.getElementById('splash-version'); @@ -1371,5 +1371,107 @@ })(); </script> +<!-- Phase 6: Boot Watchdog — auto-revert if recent commit broke the system --> +<script> +(function() { + // Wait for modules to load, then check health + var watchdogTimer = null; + var watchdogStarted = false; + + function checkBoot() { + if (watchdogStarted) return; + watchdogStarted = true; + + // Check if core modules loaded + if (typeof webx11 === 'undefined' || !webx11.moduleManager) { + // Critical: webx11 object doesn't exist — system is broken + handleBootFailure('webx11 object not found'); + return; + } + + var mm = webx11.moduleManager; + var loadedModules = Object.keys(mm.modules).length; + + // If less than 50% of expected modules loaded, boot failed + // Expected: ~19 modules at full load + if (loadedModules < 10) { + handleBootFailure('Only ' + loadedModules + ' modules loaded (expected ≥10)'); + return; + } + + // Boot OK — save current state as last-good + try { + var lastGood = { + version: window.NEWOS4_VERSION || 'unknown', + moduleCount: loadedModules, + timestamp: Date.now() + }; + localStorage.setItem('newos4_last_good_boot', JSON.stringify(lastGood)); + } catch (e) {} + } + + function handleBootFailure(reason) { + console.error('[Boot Watchdog] Boot failure detected: ' + reason); + + // Check if there was a recent commit (within last 30 min) + var commitLog = null; + try { + // Check localStorage for recent commit info + var lastCommit = localStorage.getItem('newos4_last_commit'); + if (lastCommit) { + var commit = JSON.parse(lastCommit); + if (commit && commit.timestamp && (Date.now() - commit.timestamp < 1800000)) { + console.warn('[Boot Watchdog] Recent commit detected (version ' + commit.version + '), attempting auto-revert...'); + attemptRevert(commit); + return; + } + } + } catch (e) {} + + // No recent commit or no revert info — just alert + console.error('[Boot Watchdog] No recent commit to revert. System may need manual intervention.'); + var banner = document.createElement('div'); + banner.style.cssText = 'position:fixed;top:0;left:0;right:0;background:#ff4444;color:#fff;padding:10px;font-family:monospace;font-size:12px;z-index:99999;text-align:center;'; + banner.textContent = '⚠️ Boot Watchdog: System failed to load (' + reason + '). Try hard refresh or clear localStorage.'; + document.body.insertBefore(banner, document.body.firstChild); + } + + function attemptRevert(commit) { + // Try to restore the previous version by setting the version back + if (commit.previousVersion) { + console.warn('[Boot Watchdog] Reverting to version ' + commit.previousVersion); + // Replace all ?v= in script tags with previous version + var scripts = document.getElementsByTagName('script'); + var reverted = 0; + for (var i = 0; i < scripts.length; i++) { + var src = scripts[i].src || ''; + if (src.indexOf('?v=') !== -1) { + scripts[i].src = src.replace(/\?v=[^&"']*/, '?v=' + commit.previousVersion); + reverted++; + } + } + console.log('[Boot Watchdog] Reverted ' + reverted + ' script tags to ' + commit.previousVersion); + + // Show warning banner + var banner = document.createElement('div'); + banner.style.cssText = 'position:fixed;top:0;left:0;right:0;background:#ffaa00;color:#000;padding:10px;font-family:monospace;font-size:12px;z-index:99999;text-align:center;'; + banner.textContent = '⚠️ Boot Watchdog: Auto-reverted from ' + commit.version + ' to ' + commit.previousVersion + '. Refresh page to load reverted version.'; + document.body.insertBefore(banner, document.body.firstChild); + + // Force reload after 3 seconds + setTimeout(function() { + // Update URL with previous version to force cache bypass + window.location.href = window.location.pathname + '?v=' + commit.previousVersion + '&watchdog=1'; + }, 3000); + } else { + console.error('[Boot Watchdog] No previous version stored. Manual intervention required.'); + } + } + + // Start watchdog after a delay to allow modules to load + watchdogTimer = setTimeout(checkBoot, 8000); +})(); +</script> + </body> </html> |