1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
<?php
require_once __DIR__ . '/config.php';
header('Content-Type: text/html; charset=utf-8');
$errors = load_json(ERRORS_FILE);
$sessions = load_json(SESSIONS_FILE);
$uniqueErrors = count($errors);
$totalOccurrences = array_sum(array_map(fn($e) => (int)($e['count'] ?? 1), $errors));
$lastIngest = $errors ? max(array_column($errors, 'ingested_at')) : null;
$totalSessions = count($sessions);
$byType = [];
$bySeverity = [];
$byCategory = [];
$byModule = [];
$byDay = [];
$topErrors = [];
foreach ($errors as $e) {
$t = $e['type'] ?? 'unknown';
$byType[$t] = ($byType[$t] ?? 0) + ($e['count'] ?? 1);
$s = $e['severity'] ?? 'error';
$bySeverity[$s] = ($bySeverity[$s] ?? 0) + ($e['count'] ?? 1);
$m = $e['module'] ?? 'unknown';
$byModule[$m] = ($byModule[$m] ?? 0) + ($e['count'] ?? 1);
$c = $e['category'] ?? 'runtime';
$byCategory[$c] = ($byCategory[$c] ?? 0) + ($e['count'] ?? 1);
$day = substr($e['ingested_at'] ?? $e['last_seen'], 0, 10);
$byDay[$day] = ($byDay[$day] ?? 0) + ($e['count'] ?? 1);
$hash = $e['hash'] ?? '';
if ($hash) {
if (!isset($topErrors[$hash])) {
$topErrors[$hash] = ['hash' => $hash, 'message' => $e['message'] ?? '', 'count' => 0, 'type' => $t,
'frame' => $e['frame'] ?? null];
}
$topErrors[$hash]['count'] += $e['count'] ?? 1;
}
}
usort($topErrors, fn($a, $b) => $b['count'] - $a['count']);
$topErrors = array_slice($topErrors, 0, 10);
ksort($byDay);
$recentSessions = array_slice($sessions, -10, 10, true);
// --- Maintenance layer -------------------------------------------------------
// Both files are written by the Hermes maintenance job. Read them defensively: a partially
// written JSON must render as "unavailable", never as zero (a zero here would read as
// "nothing is wrong", which is the exact failure this dashboard exists to catch).
$DOCROOT = dirname(__DIR__, 4);
$triageFile = $DOCROOT . '/admin/docs/newos4-triage-latest.json';
$repliesFile = __DIR__ . '/../../data/maintenance/replies.json';
$triage = null; $triageState = 'missing';
if (is_file($triageFile)) {
$raw = @file_get_contents($triageFile);
$parsed = $raw === false ? null : json_decode($raw, true);
if (is_array($parsed)) { $triage = $parsed; $triageState = 'ok'; }
else { $triageState = 'unreadable'; }
}
$replies = []; $repliesState = 'missing';
if (is_file($repliesFile)) {
$raw = @file_get_contents($repliesFile);
$parsed = $raw === false ? null : json_decode($raw, true);
if (is_array($parsed)) { $replies = array_slice($parsed, -5); $repliesState = 'ok'; }
else { $repliesState = 'unreadable'; }
}
// In-app feedback (kind=maintenance) — the other half of the thread.
$feedback = [];
foreach (glob(__DIR__ . '/../../data/reports/RPT-*.json') ?: [] as $rf) {
$r = json_decode((string)@file_get_contents($rf), true);
if (is_array($r) && ($r['kind'] ?? '') === 'maintenance') {
$feedback[] = $r;
}
}
usort($feedback, fn($a, $b) => strcmp($b['created_at'] ?? '', $a['created_at'] ?? ''));
$feedback = array_slice($feedback, 0, 5);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>newOS4 Debug Dashboard</title>
<style>
:root { --bg: #0d0d12; --surface: #16161e; --border: #1e1e2a; --text: #e8e8f0; --muted: #888; --accent: #00e5c8; --error: #ff5555; --warn: #ffaa00; --info: #00aaff; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: 'Courier New', monospace; padding: 20px; }
h1 { color: var(--accent); font-size: 1.4em; margin-bottom: 4px; }
.subtitle { color: var(--muted); font-size: 0.85em; margin-bottom: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.card h3 { font-size: 0.8em; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-size: 2em; font-weight: bold; }
.stat-value.error { color: var(--error); }
.stat-value.warn { color: var(--warn); }
.stat-value.ok { color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
th { text-align: left; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 0.8em; text-transform: uppercase; }
td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); margin-right: 6px; vertical-align: middle; }
.bar.error { background: var(--error); }
.bar.warn { background: var(--warn); }
.tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 0.75em; background: var(--border); }
.tag.error { background: #3a1010; color: var(--error); }
.tag.warn { background: #3a2a00; color: var(--warn); }
.tag.ok { background: #002a20; color: var(--accent); }
.refresh { color: var(--muted); font-size: 0.8em; margin-top: 20px; text-align: center; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.max-w-300 { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread { font-size: 0.85em; line-height: 1.45; }
.thread .msg { border-left: 3px solid var(--border); padding: 4px 0 4px 10px; margin-bottom: 10px; }
.thread .msg.hermes { border-left-color: var(--accent); }
.thread .msg.app { border-left-color: var(--info); }
.thread .who { color: var(--muted); font-size: 0.8em; }
.thread .body { white-space: pre-wrap; word-break: break-word; }
.status-pill { display:inline-block; padding:1px 8px; border-radius:10px; font-size:.75em; }
.status-pill.ok { background:#002a20; color:var(--accent); }
.status-pill.stale { background:#3a2a00; color:var(--warn); }
.status-pill.degraded { background:#3a1010; color:var(--error); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Phones: one column, no horizontal page overflow, smaller type. */
@media (max-width: 640px) {
body { padding: 10px; font-size: 14px; }
h1 { font-size: 1.1em; }
.subtitle { font-size: 0.75em; line-height: 1.5; }
.grid { grid-template-columns: 1fr; gap: 8px; }
.card { padding: 10px; border-radius: 6px; }
.stat-value { font-size: 1.5em; }
table { font-size: 0.78em; }
th, td { padding: 4px 5px; }
.max-w-300 { max-width: 42vw; }
.hide-sm { display: none; }
}</style>
</head>
<body>
<h1>🔍 newOS4 Debug Dashboard</h1>
<div class="subtitle">Server-side error aggregation · <?= date('Y-m-d H:i:s') ?> · <a href="stats.php">JSON Stats</a> · <a href="clusters.php">Clusters</a> · <a href="errors.php">Raw Errors</a> · <a href="health.php">Health</a></div>
<?php
// Use the newest ingest across all signatures, not the last array element: after the 2026-10-23
// prune the array order is not chronological, and `end()` showed a 3-day-old timestamp while the
// triage card showed a fresh one — two numbers disagreeing on the same screen.
if ($lastIngest): ?>
<div style="color:var(--muted);font-size:0.8em;margin-bottom:16px;">Last ingest: <?= htmlspecialchars(substr($lastIngest, 0, 19)) ?> UTC · signatures sorted by occurrence count</div>
<?php endif; ?>
<div class="grid">
<div class="card">
<h3>Total Occurrences</h3>
<div class="stat-value <?= $totalOccurrences > 0 ? 'error' : 'ok' ?>"><?= $totalOccurrences ?></div>
<div class="muted" style="font-size:.75em;color:var(--muted)"><?= $uniqueErrors ?> unique signatures</div>
<div class="muted" style="font-size:.75em;color:var(--muted)">last ingest: <?= $lastIngest ? htmlspecialchars($lastIngest) : '—' ?></div>
</div>
<div class="card">
<h3>Sessions</h3>
<div class="stat-value"><?= $totalSessions ?></div>
</div>
<div class="card">
<h3>Error Types</h3>
<div class="stat-value"><?= count($byType) ?></div>
</div>
<div class="card">
<h3>Modules Affected</h3>
<div class="stat-value"><?= count($byModule) ?></div>
</div>
</div>
<?php
// Triage freshness: the digest is only useful if it is recent. Never present a stale digest as
// current — that is how a status page keeps claiming "all clear" days after the job died.
$triClass = 'degraded'; $triLabel = $triageState;
if ($triageState === 'ok') {
$triAgeH = (time() - (strtotime($triage['generated_at'] ?? '') ?: 0)) / 3600;
if ($triAgeH <= 26) { $triClass = 'ok'; $triLabel = 'fresh (' . round($triAgeH, 1) . 'h)'; }
else { $triClass = 'stale'; $triLabel = 'stale (' . round($triAgeH, 1) . 'h)'; }
}
$tri = $triage['counts'] ?? [];
// `checks` is {exit, findings[]}, not a list of strings (shape verified against the digest on
// 2026-10-23). Accept both so a future collector change cannot fatal the whole page.
$triChecks = [];
$rawChecks = $triage['checks'] ?? [];
if (is_array($rawChecks)) {
$list = $rawChecks['findings'] ?? $rawChecks;
foreach ((array)$list as $c) {
if (is_array($c)) {
$line = trim(($c['status'] ?? $c['level'] ?? '') . ' ' . ($c['name'] ?? $c['check'] ?? '') . ' ' . ($c['detail'] ?? $c['message'] ?? ''));
} else {
$line = (string)$c;
}
if (stripos($line, 'FAIL') !== false || stripos($line, 'WARN') !== false) $triChecks[] = $line;
}
}
?>
<div class="card" style="margin-bottom:20px;">
<h3>Maintenance triage <span class="status-pill <?= $triClass ?>"><?= htmlspecialchars($triLabel) ?></span></h3>
<?php if ($triageState !== 'ok'): ?>
<div style="color:var(--warn);font-size:.85em;">Triage digest <?= htmlspecialchars($triageState) ?> — run <code>python3 scripts/newos4-triage.py</code> or check the newos4-maintenance cron.</div>
<?php else: ?>
<div class="table-scroll">
<table>
<tr><th>Signatures</th><th>Clusters</th><th>Active <24h</th><th>Stale >7d</th><th>Occurrences</th><th>Regressed</th><th>Generated</th></tr>
<tr>
<td><?= (int)($tri['records'] ?? 0) ?></td>
<td><?= (int)($tri['clusters'] ?? 0) ?></td>
<td><?= (int)($tri['active_records'] ?? 0) ?></td>
<td><?= (int)($tri['stale_records'] ?? 0) ?></td>
<td><?= (int)($tri['occurrences'] ?? 0) ?></td>
<td><?php $rg = (int)($tri['fixes_regressed'] ?? 0); ?>
<?php if ($rg > 0): ?><span class="status-pill degraded"><?= $rg ?> regressed</span><?php else: ?><span class="status-pill ok">none</span><?php endif; ?></td>
<td><?= htmlspecialchars(substr($triage['generated_at'] ?? '', 5, 11)) ?>Z</td>
</tr>
</table>
</div>
<?php if (!empty($triage['top_real'])): ?>
<div style="margin-top:10px;font-size:.82em;color:var(--muted);">Top real signatures</div>
<?php foreach (array_slice($triage['top_real'], 0, 3) as $t): ?>
<div class="thread"><div class="body" style="font-size:.82em;"><?= (int)($t['count'] ?? 0) ?>× <span class="tag"><?= htmlspecialchars($t['type'] ?? '?') ?></span> <?= htmlspecialchars(mb_substr($t['message'] ?? '', 0, 110)) ?></div></div>
<?php endforeach; ?>
<?php endif; ?>
<?php foreach (($triage['fixes']['regressed'] ?? []) as $fx): ?>
<div style="color:var(--error);font-size:.85em;margin-top:8px;">
<b>REGRESSED</b> <?= htmlspecialchars((string)($fx['commit'] ?? '?')) ?> —
<?= htmlspecialchars(substr((string)($fx['message'] ?? ''), 0, 90)) ?>
<span style="color:var(--muted)">(<?= htmlspecialchars((string)($fx['detail'] ?? '')) ?>)</span>
</div>
<?php endforeach; ?>
<?php if ($triChecks): ?>
<div style="margin-top:10px;font-size:.82em;color:var(--warn);">
<?php foreach (array_slice($triChecks, 0, 4) as $c): ?><div class="body"><?= htmlspecialchars($c) ?></div><?php endforeach; ?>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php
// Merge both halves of the thread into one chronological view.
$thread = [];
foreach ($feedback as $f) {
$thread[] = ['at' => $f['created_at'] ?? '', 'who' => 'app', 'body' => ($f['title'] ?? '') . (($f['body'] ?? '') !== ($f['title'] ?? '') ? "\n" . ($f['body'] ?? '') : '')];
}
foreach ($replies as $r) {
$thread[] = ['at' => $r['created_at'] ?? '', 'who' => ($r['author'] ?? 'hermes'), 'body' => $r['body'] ?? ''];
}
usort($thread, fn($a, $b) => strcmp($a['at'], $b['at']));
$thread = array_slice($thread, -6);
?>
<div class="card" style="margin-bottom:20px;">
<h3>Maintenance thread <?php if ($repliesState !== 'ok'): ?><span class="status-pill degraded"><?= htmlspecialchars($repliesState) ?></span><?php endif; ?></h3>
<?php if (!$thread): ?>
<div style="color:var(--muted);font-size:.85em;">No messages yet. In the app: <code>feedback <message></code>; agent replies appear here.</div>
<?php endif; ?>
<div class="thread">
<?php foreach ($thread as $m): ?>
<div class="msg <?= $m['who'] === 'app' ? 'app' : 'hermes' ?>">
<div class="who"><?= $m['who'] === 'app' ? 'app (feedback)' : 'maintenance agent' ?> · <?= htmlspecialchars(substr($m['at'], 0, 19)) ?></div>
<div class="body"><?= htmlspecialchars(mb_substr($m['body'], 0, 600)) ?></div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="grid">
<div class="card">
<h3>By Severity</h3>
<table>
<?php foreach (['fatal' => 'error', 'error' => 'error', 'warning' => 'warn'] as $sev => $cls): ?>
<tr><td><span class="tag <?= $cls ?>"><?= $sev ?></span></td><td><?= $bySeverity[$sev] ?? 0 ?></td></tr>
<?php endforeach; ?>
</table>
</div>
<div class="card">
<h3>By Category</h3>
<table>
<?php foreach (['network', 'module', 'runtime', 'vfs', 'security', 'tool'] as $cat): ?>
<?php if (($byCategory[$cat] ?? 0) > 0): ?>
<tr><td><?= $cat ?></td><td><?= $byCategory[$cat] ?? 0 ?></td></tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
</div>
<div class="card">
<h3>By Module</h3>
<table>
<?php
arsort($byModule);
$i = 0;
foreach (array_slice($byModule, 0, 8) as $mod => $count):
if ($i++ > 5) break;
?>
<tr><td class="max-w-300"><?= htmlspecialchars($mod) ?></td><td><?= $count ?></td></tr>
<?php endforeach; ?>
</table>
</div>
</div>
<div class="card" style="margin-bottom:20px;">
<h3>Top Errors</h3>
<div class="table-scroll">
<table>
<tr><th>#</th><th>Message</th><th class="hide-sm">Type</th><th>Count</th></tr>
<?php $i = 1; foreach ($topErrors as $e): ?>
<tr>
<td><?= $i++ ?></td>
<td class="max-w-300"><a href="error.php?hash=<?= urlencode($e['hash'] ?? '') ?>" style="color:var(--text);text-decoration:none;" title="View details"><?= htmlspecialchars(substr($e['message'] ?? '', 0, 80)) ?></a>
<?php if (!empty($e['frame'])): ?><div class="hide-sm" style="font-size:.72em;color:var(--muted)"><?= htmlspecialchars($e['frame']) ?></div><?php endif; ?>
</td>
<td class="hide-sm"><span class="tag"><?= htmlspecialchars($e['type'] ?? '?') ?></span></td>
<td><?= (int)($e['count'] ?? 0) ?></td>
</tr>
<?php endforeach; ?>
<?php if (empty($topErrors)): ?>
<tr><td colspan="4" style="color:var(--muted);text-align:center;">No errors recorded</td></tr>
<?php endif; ?>
</table>
</div>
</div>
<div class="card" style="margin-bottom:20px;">
<h3>Daily Trend (last 14 days)</h3>
<table>
<tr><th>Day</th><th>Errors</th><th></th></tr>
<?php
$maxDay = max($byDay) ?: 1;
$days = array_slice($byDay, -14, 14, true);
foreach ($days as $day => $count):
$pct = round($count / $maxDay * 100, 0);
?>
<tr>
<td><?= $day ?></td>
<td><?= $count ?></td>
<td><div class="bar" style="width:<?= $pct ?>%;"></div></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="card">
<h3>Recent Sessions</h3>
<table>
<tr><th>Session</th><th>Version</th><th>Errors</th><th>Last Seen</th></tr>
<?php foreach ($recentSessions as $sid => $s): ?>
<tr>
<td class="max-w-300"><a href="errors.php?session=<?= urlencode($sid) ?>" style="color:var(--text);text-decoration:none;" title="View this session's errors"><?= htmlspecialchars($sid) ?></a></td>
<td><?= htmlspecialchars($s['version'] ?? '?') ?></td>
<td><?= $s['error_count'] ?? 0 ?></td>
<td><?= htmlspecialchars(substr($s['last_seen'] ?? '', 0, 16)) ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="refresh">Auto-refresh every 30s (paused while the tab is hidden)</div>
<script>
// Only reload when the tab is actually visible: the old unconditional timer could abort a
// half-read table on a phone that had been backgrounded for minutes.
setInterval(() => {
if (document.visibilityState === 'visible') location.reload();
}, 30000);
</script>
</body>
</html>
|