diff options
| author | Agando <roduccomm@gmail.com> | 2026-06-17 06:01:20 +0200 |
|---|---|---|
| committer | Agando <roduccomm@gmail.com> | 2026-06-17 06:01:20 +0200 |
| commit | cebacc27a48168e666679018f8e27156d12d4527 (patch) | |
| tree | b306d33b67b9d8c84bd9b9c16b1e91ee217628a6 /modules/core/module-world-model.js | |
| parent | 6aa24b976952a698c673d350977721b27193183d (diff) | |
auto: 2026-06-17_06:01 changes
Diffstat (limited to 'modules/core/module-world-model.js')
| -rw-r--r-- | modules/core/module-world-model.js | 83 |
1 files changed, 66 insertions, 17 deletions
diff --git a/modules/core/module-world-model.js b/modules/core/module-world-model.js index e8e3405..6f0c4e5 100644 --- a/modules/core/module-world-model.js +++ b/modules/core/module-world-model.js @@ -96,7 +96,22 @@ class WorldModelModule { _deriveVersion(mInfo) { // Single source of truth: the constant set at bootstrap if (window.NEWOS4_VERSION) return window.NEWOS4_VERSION; - // No fallback version string — if the constant is missing, report unknown + // Fallback: try to extract from script tag ?v= query param or LATEST_VER constant + try { + const scripts = document.querySelectorAll('script[src*="module-loader"]'); + for (const s of scripts) { + const match = s.src.match(/[?&]v=([^&]+)/); + if (match) return match[1]; + } + // Try to find LATEST_VER in any inline script + const allScripts = document.querySelectorAll('script:not([src])'); + for (const s of allScripts) { + const match = s.textContent.match(/LATEST_VER\s*=\s*['"]([^'"]+)['"]/); + if (match) return match[1]; + } + } catch (e) { + console.warn('[WorldModel] Version extraction error:', e.message); + } return 'v?'; } @@ -106,14 +121,20 @@ class WorldModelModule { if (!mm) return 0; // Count registry entries (all known modules) vs loaded const registry = mm.moduleRegistry || []; - return registry.length || Object.keys(mm.modules || {}).length + 5; // +5 for expected unloaded + return registry.length || Object.keys(mm.modules || {}).length; } catch (e) { + console.warn('[WorldModel] Total modules gather error:', e.message); return Object.keys(this.terminal?.moduleManager?.modules || {}).length || 0; } } _gatherSystemInfo(fs, moduleCount, version) { - const healthData = fs.fsReadJSON('/system/metrics/health.json'); + // Get real health data from ServerMonitorModule's _latencyLog and AI assistant's _errorLog + const sm = this.terminal?.moduleManager?.modules?.['ServerMonitorModule']; + const ai = this.terminal?.moduleManager?.modules?.['WebX11AIAssistantModule']; + const errorCount = ai?._errorLog?.length || 0; + const latencyErrors = sm?._latencyLog ? Object.values(sm._latencyLog).filter(e => e.status === 'error').length : 0; + const totalErrors = errorCount + latencyErrors; return { version: `newOS4 ${version}`, modules: moduleCount || Object.keys(this.terminal?.moduleManager?.modules || {}).length || 0, @@ -122,8 +143,8 @@ class WorldModelModule { memory: typeof performance !== 'undefined' && performance.memory ? `${(performance.memory.usedJSHeapSize / 1048576).toFixed(1)}MB` : 'N/A', - health: healthData?.status || 'OK', - lastHealthCheck: healthData?.timestamp || null + health: totalErrors > 0 ? `⚠️ ${totalErrors} errors` : 'OK', + lastHealthCheck: new Date().toISOString() }; } @@ -175,6 +196,7 @@ class WorldModelModule { const count = idx ? Object.keys(idx).length : 0; return { count, skills: idx ? Object.keys(idx) : [] }; } catch (e) { + console.warn('[WorldModel] Skill info gather error:', e.message); return { count: 0, skills: [] }; } } @@ -184,20 +206,21 @@ class WorldModelModule { if (mg && mg._nodes) { const nodes = Object.keys(mg._nodes).length; const edges = (mg._edges || []).length; - return { nodes, edges, active: true }; + return { nodes, edges, active: true, fallback: false }; } // Fallback: count memory files try { const memIndex = this.terminal.fs?.fsReadJSON('/memory/index.json'); - return { nodes: memIndex ? Object.keys(memIndex).length : 0, edges: 0, active: false }; + return { nodes: memIndex ? Object.keys(memIndex).length : 0, edges: 0, active: false, fallback: true }; } catch (e) { - return { nodes: 0, edges: 0, active: false }; + console.warn('[WorldModel] Memory info gather error:', e.message); + return { nodes: 0, edges: 0, active: false, fallback: true }; } } _gatherAgentInfo() { const orch = this.terminal?.moduleManager?.modules?.['OrchestratorModule']; - if (!orch || !orch._agents) return { agents: 0, active: 0 }; + if (!orch || !orch._agents) return { agents: -1, active: -1, error: 'Orchestrator not loaded' }; const agents = Object.keys(orch._agents).length; const active = Object.values(orch._agents).filter(a => a.status === 'busy').length; return { agents, active, totalLeases: Object.keys(orch._a2aMessages || {}).length }; @@ -205,13 +228,17 @@ class WorldModelModule { _gatherTelemetry(fs) { try { - const latency = fs.fsReadJSON('/system/metrics/tool-latency.json'); - const errors = fs.fsReadJSON('/system/metrics/error-log.json'); + // Get real latency data from ServerMonitorModule and errors from AI assistant + const sm = this.terminal?.moduleManager?.modules?.['ServerMonitorModule']; + const ai = this.terminal?.moduleManager?.modules?.['WebX11AIAssistantModule']; + const latencyDataPoints = sm?._latencyLog ? Object.keys(sm._latencyLog).length : 0; + const recentErrors = ai?._errorLog?.length || 0; return { - toolLatencyDataPoints: latency ? Object.keys(latency).length : 0, - recentErrors: errors ? (Array.isArray(errors) ? errors.length : Object.keys(errors).length) : 0, + toolLatencyDataPoints: latencyDataPoints, + recentErrors: recentErrors, }; } catch (e) { + console.warn('[WorldModel] Telemetry gather error:', e.message); return { toolLatencyDataPoints: 0, recentErrors: 0 }; } } @@ -224,19 +251,20 @@ class WorldModelModule { const tasks = Object.values(mg._nodes).filter(n => n.type === 'task'); const recentFiles = Object.values(mg._nodes) .filter(n => n.type === 'file') - .sort((a, b) => b.access_count - a.access_count) + .sort((a, b) => (b.access_count || 0) - (a.access_count || 0)) .slice(0, this._MAX_PROJECTS); return { totalTasks: tasks.length, activeProjects: recentFiles.slice(0, 5).map(f => ({ name: f.label, - accesses: f.access_count, + accesses: f.access_count || 0, lastModified: f.updated })) }; } return { totalTasks: 0, activeProjects: [] }; } catch (e) { + console.warn('[WorldModel] Projects gather error:', e.message); return { totalTasks: 0, activeProjects: [] }; } } @@ -258,7 +286,25 @@ class WorldModelModule { if (skills && skills.length > 0) { recent.push(`Skills directory: ${skills.filter(s => s.type === 'file').length} files`); } - } catch (e) {} + // Check memory directory for recent changes + const memDir = fs.readDir('/memory/'); + if (memDir && memDir.length > 0) { + const memFiles = memDir.filter(s => s.type === 'file'); + if (memFiles.length > 0) { + recent.push(`Memory: ${memFiles.length} files in /memory/`); + } + } + // Check system config changes + const sysDir = fs.readDir('/system/'); + if (sysDir && sysDir.length > 0) { + const configFiles = sysDir.filter(s => s.type === 'file' && s.name.endsWith('.json')); + if (configFiles.length > 0) { + recent.push(`System config: ${configFiles.length} config files`); + } + } + } catch (e) { + console.warn('[WorldModel] Recent gather error:', e.message); + } return recent; } @@ -380,7 +426,10 @@ class WorldModelModule { getContextForPrompt() { if (!this._model) return ''; const m = this._model; - return `[World Model Context]\\nSystem: newOS4 ${m.version} · ${m.modules.loaded} modules · ${m.skills.count} skills · ${m.files.total} files · ${m.agents.agents} agents${m.telemetry.recentErrors > 0 ? ` · ⚠️ ${m.telemetry.recentErrors} errors` : ' · ✅ OK'}${m.modules.modifiedCount > 0 ? `\\nModified modules: ${m.modules.modified.slice(0, 3).join(', ')}${m.modules.modifiedCount > 3 ? ` (+${m.modules.modifiedCount - 3} more)` : ''}` : ''}`; + const agentStr = m.agents.error + ? 'agents: N/A' + : `${m.agents.agents} agents`; + return `[World Model Context]\\nSystem: newOS4 ${m.version} · ${m.modules.loaded} modules · ${m.skills.count} skills · ${m.files.total} files · ${agentStr}${m.telemetry.recentErrors > 0 ? ` · ⚠️ ${m.telemetry.recentErrors} errors` : ' · ✅ OK'}${m.modules.modifiedCount > 0 ? `\\nModified modules: ${m.modules.modified.slice(0, 3).join(', ')}${m.modules.modifiedCount > 3 ? ` (+${m.modules.modifiedCount - 3} more)` : ''}` : ''}`; } // ─── Persistence ─── |