Repository navigation
Expand file tree
/
Copy pathmetrics.html
More file actions
561 lines (517 loc) · 28.8 KB
/
Copy pathmetrics.html
File metadata and controls
561 lines (517 loc) · 28.8 KB
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RAR Metrics — Public Registry Dashboard</title>
<meta name="description" content="Public download, vote, and review metrics for the RAPP Agent Registry. Every number sourced from a public API.">
<meta property="og:title" content="RAR Metrics — Public Registry Dashboard">
<meta property="og:description" content="Total downloads, most downloaded agents, most upvoted, most reviewed. All public data.">
<meta property="og:type" content="website">
<meta property="og:url" content="https://kody-w.github.io/RAR/metrics.html">
<style>
:root {
--bg: #0d1117;
--surface: #161b22;
--surface2: #21262d;
--border: #30363d;
--border-hover: #484f58;
--text: #e6edf3;
--text-dim: #8b949e;
--text-muted: #656d76;
--accent: #58a6ff;
--purple: #bc8cff;
--green: #3fb950;
--orange: #d29922;
--red: #f85149;
--radius: 10px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace; }
header {
background: var(--surface); border-bottom: 1px solid var(--border);
padding: 14px 32px; display: flex; align-items: center; justify-content: space-between;
position: sticky; top: 0; z-index: 50; gap: 16px; flex-wrap: wrap;
}
.logo { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; font-weight: 700; }
.logo-mark {
background: linear-gradient(135deg, var(--accent), var(--purple));
color: #fff; width: 32px; height: 32px; border-radius: 8px;
display: flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 800;
}
.header-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-link {
background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim);
padding: 6px 14px; border-radius: 6px; font-size: .78rem; font-weight: 600;
cursor: pointer; transition: all .15s;
}
.nav-link:hover { border-color: var(--border-hover); color: var(--text); text-decoration: none; }
.nav-link.primary { background: linear-gradient(135deg, var(--accent), var(--purple)); color: #fff; border: none; }
.container { max-width: 1180px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { margin-bottom: 28px; }
.page-head h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.page-head p { color: var(--text-dim); margin-top: 6px; font-size: .95rem; max-width: 720px; }
.stamp { margin-top: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: .75rem; color: var(--text-muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi {
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
padding: 16px 18px; position: relative; overflow: hidden;
}
.kpi.hero { grid-column: span 2; background: linear-gradient(135deg, rgba(88,166,255,.10), rgba(188,140,255,.07)); border-color: #2c4a6e; }
.kpi .label { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--text-muted); font-weight: 700; }
.kpi .value { font-size: 2rem; font-weight: 800; letter-spacing: -.03em; margin-top: 4px; line-height: 1.1; }
.kpi.hero .value { font-size: 2.9rem; background: linear-gradient(135deg, var(--accent), var(--purple)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.kpi .sub { font-size: .74rem; color: var(--text-dim); margin-top: 4px; }
.section { margin-top: 34px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 1.1rem; font-weight: 700; }
.section-head .hint { font-size: .76rem; color: var(--text-muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } .kpi.hero { grid-column: span 2; } }
/* chart */
.chart { width: 100%; height: 190px; display: block; }
.legend { display: flex; gap: 16px; font-size: .74rem; color: var(--text-dim); margin-top: 10px; flex-wrap: wrap; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; margin-right: 5px; }
/* tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
padding: 7px 14px; border-radius: 20px; font-size: .78rem; font-weight: 600; cursor: pointer; transition: all .15s;
}
.tab:hover { border-color: var(--border-hover); color: var(--text); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #06121f; }
/* rank rows */
.rank-row {
display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center;
padding: 11px 4px; border-bottom: 1px solid var(--border);
}
.rank-row:last-child { border-bottom: none; }
.rank-n { font-size: .8rem; font-weight: 800; color: var(--text-muted); text-align: center; }
.rank-row:nth-child(1) .rank-n { color: var(--orange); }
.rank-name { font-weight: 650; font-size: .92rem; }
.rank-meta { font-size: .74rem; color: var(--text-muted); margin-top: 2px; }
.rank-meta .mono { color: var(--text-dim); }
.rank-val { font-size: 1.05rem; font-weight: 800; text-align: right; white-space: nowrap; }
.rank-val small { display: block; font-size: .66rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.pill {
display: inline-block; font-size: .64rem; font-weight: 700; padding: 1px 7px; border-radius: 20px;
border: 1px solid var(--border); color: var(--text-dim); margin-left: 6px; vertical-align: 1px;
}
.pill.official { border-color: #2ea043; color: var(--green); }
.pill.verified { border-color: #1f6feb; color: var(--accent); }
.pill.private { border-color: #6e7681; color: var(--text-muted); }
/* bars */
.bar-row { display: grid; grid-template-columns: 150px 1fr 54px; gap: 10px; align-items: center; padding: 5px 0; font-size: .82rem; }
.bar-track { background: var(--surface2); border-radius: 4px; height: 9px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: 4px; }
.bar-num { text-align: right; font-weight: 700; font-size: .8rem; color: var(--text-dim); }
.bar-label { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); font-weight: 700; }
td { padding: 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.src-item { display: grid; grid-template-columns: 190px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .8rem; }
.src-item:last-child { border-bottom: none; }
.src-item b { font-weight: 650; }
.src-item span { color: var(--text-dim); }
.note { font-size: .78rem; color: var(--text-muted); line-height: 1.65; }
.empty { color: var(--text-muted); font-size: .85rem; padding: 18px 4px; text-align: center; }
footer { border-top: 1px solid var(--border); margin-top: 46px; padding-top: 20px; font-size: .78rem; color: var(--text-muted); }
.spin { display: inline-block; width: 11px; height: 11px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: r .7s linear infinite; }
@keyframes r { to { transform: rotate(360deg); } }
</style>
<link rel="stylesheet" href="nav.css">
<script src="nav.js" defer></script>
</head>
<body>
<nav id="rar-nav" aria-label="Primary">
<a class="rar-brand" href="index.html"><span class="rar-brand-mark">R</span>RAPP Agent Repository</a>
<span class="rar-primary"><noscript><span class="rar-nav-fallback">
<a href="index.html">Browse</a><a href="distros.html">Distros</a><a href="skills.html">Skills</a><a href="install.html">Install</a><a href="front.html">Front page</a><a href="store.html">Advanced</a><a href="llms.txt">For AIs</a>
</span></noscript></span>
<details class="rar-more"><summary>More</summary><div class="rar-more-content">
<a href="rappterpedia/index.html">Rappterpedia</a>
<a href="https://github.com/kody-w/RAR" target="_blank" rel="noopener">GitHub</a>
</div></details>
</nav>
<header class="rar-page-header">
<div class="logo"><div class="logo-mark">RAR</div> Registry Metrics</div>
<div class="header-right">
<a class="nav-link" href="index.html">Browse</a>
<a class="nav-link" href="store.html">Store</a>
<a class="nav-link" href="rappterpedia/index.html">Rappterpedia</a>
<button class="nav-link" id="refresh">↻ Refresh live</button>
<a class="nav-link primary" href="https://github.com/kody-w/RAR" target="_blank" rel="noopener">GitHub</a>
</div>
</header>
<div class="container">
<div class="page-head">
<h1>Public registry metrics</h1>
<p>Every number below comes from a public, verifiable API — GitHub traffic and releases, the jsDelivr CDN, and the registry's own state files. No private analytics, no tracking pixel.</p>
<div class="stamp">
<span><span class="dot"></span> <span id="stamp-time">loading…</span></span>
<span>·</span><span id="stamp-window"></span>
<span>·</span><span id="stamp-src"></span>
<span>·</span><span id="stamp-mode"></span>
</div>
</div>
<div class="kpis" id="kpis"></div>
<div class="section">
<div class="section-head">
<h2>Traffic over time</h2>
<div class="hint">daily clones, page views and CDN hits — accumulated past GitHub's 14-day window</div>
</div>
<div class="card">
<svg class="chart" id="chart" preserveAspectRatio="none"></svg>
<div class="legend">
<span><i style="background:var(--accent)"></i>Clones (downloads)</span>
<span><i style="background:var(--purple)"></i>Page views</span>
<span><i style="background:var(--green)"></i>CDN hits</span>
</div>
<div id="annotations"></div>
</div>
</div>
<div class="section">
<div class="section-head">
<h2>Agent leaderboards</h2>
<div class="hint" id="board-hint">ranked across all registry agents</div>
</div>
<div class="tabs" id="tabs"></div>
<div class="card"><div id="board"></div></div>
</div>
<div class="section grid2">
<div>
<div class="section-head"><h2>Publishers</h2></div>
<div class="card" style="overflow-x:auto"><table id="pub-table"></table></div>
</div>
<div>
<div class="section-head"><h2>Categories</h2></div>
<div class="card" id="cat-bars"></div>
</div>
</div>
<div class="section grid3">
<div>
<div class="section-head"><h2>Quality tiers</h2></div>
<div class="card" id="tier-bars"></div>
</div>
<div>
<div class="section-head"><h2>Rating spread</h2><div class="hint">human reviews</div></div>
<div class="card" id="rating-bars"></div>
</div>
</div>
<div class="section grid2">
<div>
<div class="section-head"><h2>Most downloaded files</h2><div class="hint">jsDelivr CDN</div></div>
<div class="card" id="cdn-files"></div>
</div>
<div>
<div class="section-head"><h2>Most visited pages</h2><div class="hint">GitHub, 14-day window</div></div>
<div class="card" id="paths"></div>
</div>
</div>
<div class="section grid2">
<div>
<div class="section-head"><h2>Traffic sources</h2></div>
<div class="card" id="referrers"></div>
</div>
<div>
<div class="section-head"><h2>Releases</h2></div>
<div class="card" id="releases"></div>
</div>
</div>
<div class="section">
<div class="section-head"><h2>Where these numbers come from</h2></div>
<div class="card">
<div id="sources"></div>
<p class="note" style="margin-top:14px">
<b>Downloads</b> = git clones + jsDelivr CDN file hits + GitHub release asset downloads. A clone pulls the whole
registry; a CDN hit is a single agent file fetched by an installer or an agent. GitHub only exposes a rolling
14-day traffic window, so <code>scripts/build_metrics.py</code> snapshots it daily into
<code>state/metrics_history.json</code>, deduplicated by date — the all-time total grows from the first day of
tracking and never double-counts.
</p>
<p class="note" style="margin-top:10px">
<b>On downloads.</b> The headline figure adds repository clones, CDN file hits and release asset
downloads. Be aware that GitHub counts every <code>actions/checkout</code> as a clone, and this
repository runs a dozen scheduled and push-triggered workflows — so clones, the largest component,
are substantially self-generated. The estimated CI baseline is published as
<code>ci_clone_estimate</code> alongside <code>clones_excluding_ci_estimate</code> in the snapshot.
<b>Agent file fetches</b> is the narrowest and most trustworthy number on this page.
</p>
<p class="note" style="margin-top:10px">
<b>On reviews and votes.</b> Only real user reviews from <code>state/reviews.json</code> — submitted through the
GitHub issues API — are counted in the review total, the average rating, and the review leaderboards.
Votes are upvotes only: RAR stopped tracking downvotes and retired every automated review
(the model critic panel and the engine "curator notes") on 2026-08-18. Nothing on this page is a
machine's opinion of an agent.
</p>
<p class="note" style="margin-top:10px">
<b>On unique counts.</b> GitHub reports uniques per 14-day window, not per day, so daily unique figures cannot
be summed into a true all-time unique. The headline <b>unique cloners</b> figure is GitHub's own 14-day number;
the "daily-unique sum" beside it is an upper bound, since one machine cloning on three days counts three times.
Clone counts and CDN hits have no such caveat — they are plain event counts and do accumulate exactly.
</p>
</div>
</div>
<footer>
Generated by <code>scripts/build_metrics.py</code> · data in
<a href="state/metrics.json">state/metrics.json</a> ·
<a href="https://github.com/kody-w/RAR" target="_blank" rel="noopener">kody-w/RAR</a> ·
rebuilt daily by GitHub Actions.
</footer>
</div>
<script>
const SITE = 'https://kody-w.github.io/RAR/';
const OWNER = 'kody-w', REPO = 'RAR';
const $ = id => document.getElementById(id);
const num = n => (n === null || n === undefined || isNaN(n)) ? '—' : Number(n).toLocaleString();
const esc = s => String(s == null ? '' : s).replace(/[&<>"'`]/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":''','`':'`'}[c]));
const bytes = b => !b ? '—' : b > 1e9 ? (b/1e9).toFixed(1)+' GB' : b > 1e6 ? (b/1e6).toFixed(1)+' MB' : (b/1e3).toFixed(0)+' KB';
const short = s => String(s || '').replace(/^@[^/]+\//, '');
let M = null;
/* ---------------------------------------------------------------- loading */
async function getJSON(paths) {
for (const p of paths) {
try {
const r = await fetch(p, { cache: 'no-store' });
if (r.ok) return await r.json();
} catch (e) { /* try next */ }
}
return null;
}
async function load() {
M = await getJSON(['state/metrics.json', SITE + 'state/metrics.json']);
if (!M) {
$('kpis').innerHTML = '<div class="card" style="grid-column:1/-1">Could not load <code>state/metrics.json</code>. Run <code>python scripts/build_metrics.py</code>.</div>';
return;
}
render();
liveTopUp();
}
/* Client-side top-up: keeps CDN hits current between nightly snapshots.
jsDelivr only — stars/forks come from the committed snapshot; pages never
call the GitHub API (rate-limited per visitor; the snapshot is the truth). */
async function liveTopUp(force) {
$('stamp-mode').innerHTML = '<span class="spin"></span> checking live sources…';
const cdn = await getJSON([`https://data.jsdelivr.com/v1/stats/packages/gh/${OWNER}/${REPO}?period=year`]);
let live = [];
if (cdn && cdn.hits) {
const hits = cdn.hits.total || 0;
if (hits > M.totals.cdn_hits) {
M.totals.downloads += (hits - M.totals.cdn_hits);
M.totals.cdn_hits = hits;
}
live.push('jsDelivr');
}
renderKPIs();
$('stamp-mode').textContent = live.length
? 'live top-up: ' + live.join(' + ')
: 'snapshot only (CDN stats unreachable)';
}
/* ----------------------------------------------------------------- render */
function render() {
const t = M.totals;
$('stamp-time').textContent = 'snapshot ' + new Date(M.generated_at).toLocaleString();
const tr = M.traffic || {};
$('stamp-src').textContent = tr.live === false
? `traffic figures as of ${String(tr.as_of || '').slice(0, 10)} (last authorized read)`
: 'traffic read live';
$('stamp-window').textContent = t.tracking_since
? `tracking since ${t.tracking_since} (${t.days_tracked} days)`
: 'tracking started';
renderKPIs();
$('board-hint').textContent = `ranked across ${num(t.agents)} single-file agents`;
renderChart();
renderAnnotations();
renderBoards();
renderPublishers();
renderBars('cat-bars', (M.leaderboards.categories || []).slice(0, 12).map(c => ({ label: c.name.replace(/_/g,' '), value: c.agents, extra: `${c.reviews} reviews` })));
renderBars('tier-bars', Object.entries(M.leaderboards.tiers || {}).map(([k, v]) => ({ label: k, value: v })));
const usr = (M.reviews && M.reviews.user) || {};
renderBars('rating-bars', Object.entries(usr.distribution || {}).reverse().map(([k, v]) => ({ label: '★'.repeat(+k), value: v })));
renderCDNFiles();
renderPaths();
renderReferrers();
renderReleases();
renderSources();
}
function renderKPIs() {
const t = M.totals, r = M.repo || {};
const cards = [
{ hero: true, label: 'Total downloads', value: num(t.downloads), sub: `${num(t.clones)} repository clones (includes this repo's own CI) · ${num(t.cdn_hits)} CDN hits · ${num(t.release_downloads)} release assets` },
{ label: 'Agent file fetches', value: num(t.agent_file_downloads), sub: 'individual agent files pulled from the CDN — the cleanest signal here' },
{ label: 'Unique cloners', value: num(t.clone_uniques_14d), sub: `last 14 days · ${num(t.clone_uniques_daily_sum)} daily-unique sum since ${t.tracking_since || '—'}` },
{ label: 'Agents', value: num(t.agents), sub: `${num(t.publishers)} publishers · ${num(t.categories)} categories` },
{ label: 'Reviews', value: num(t.reviews), sub: t.reviews ? `${num(t.agents_reviewed)} agents · ★ ${t.avg_rating} avg` : 'no user reviews yet' },
{ label: 'Upvotes', value: num(t.upvotes), sub: 'distinct people · RAR tracks upvotes only' },
{ label: 'Page views', value: num(t.page_views), sub: `${num(t.view_uniques_14d)} unique visitors (14d)` },
{ label: 'Stars', value: num(r.stars), sub: `${num(r.forks)} forks · ${num(r.open_issues)} open issues` },
{ label: 'Registry size', value: num(t.total_lines), sub: `lines of Python · ${num(t.swarms)} swarms` }
];
$('kpis').innerHTML = cards.map(c =>
`<div class="kpi${c.hero ? ' hero' : ''}">
<div class="label">${esc(c.label)}</div>
<div class="value">${c.value}</div>
<div class="sub">${esc(c.sub)}</div>
</div>`).join('');
}
function renderChart() {
const data = (M.daily || []).slice(-60);
const svg = $('chart');
if (!data.length) { svg.innerHTML = '<text x="10" y="24" fill="#656d76" font-size="12">No traffic history yet</text>'; return; }
const W = 1000, H = 190, PAD = 26;
const max = Math.max(1, ...data.map(d => Math.max(d.clones, d.views, d.cdn)));
const bw = (W - PAD * 2) / data.length;
const y = v => H - PAD - (v / max) * (H - PAD * 2);
let out = '';
// gridlines
for (let i = 0; i <= 3; i++) {
const gy = PAD + i * (H - PAD * 2) / 3;
const val = Math.round(max - i * max / 3);
out += `<line x1="${PAD}" y1="${gy}" x2="${W - PAD}" y2="${gy}" stroke="#21262d" stroke-width="1"/>`;
out += `<text x="4" y="${gy + 3}" fill="#656d76" font-size="9">${val}</text>`;
}
data.forEach((d, i) => {
const x = PAD + i * bw;
const w = Math.max(1.5, bw * 0.26);
if (d.clones) out += `<rect x="${x}" y="${y(d.clones)}" width="${w}" height="${H - PAD - y(d.clones)}" fill="#58a6ff" rx="1"><title>${d.date}: ${d.clones} clones</title></rect>`;
if (d.views) out += `<rect x="${x + w + 1}" y="${y(d.views)}" width="${w}" height="${H - PAD - y(d.views)}" fill="#bc8cff" rx="1"><title>${d.date}: ${d.views} views</title></rect>`;
if (d.cdn) out += `<rect x="${x + (w + 1) * 2}" y="${y(d.cdn)}" width="${w}" height="${H - PAD - y(d.cdn)}" fill="#3fb950" rx="1"><title>${d.date}: ${d.cdn} CDN hits</title></rect>`;
});
const step = Math.ceil(data.length / 8);
data.forEach((d, i) => {
if (i % step) return;
out += `<text x="${PAD + i * bw}" y="${H - 6}" fill="#656d76" font-size="9">${d.date.slice(5)}</text>`;
});
svg.setAttribute('viewBox', `0 0 ${W} ${H}`);
svg.innerHTML = out;
}
const BOARDS = [
{ id: 'most_downloaded', label: 'Most downloaded', metric: 'downloads', unit: 'downloads' },
{ id: 'most_upvoted', label: 'Most upvoted', metric: 'score', unit: 'upvotes' },
{ id: 'most_reviewed', label: 'Most reviewed', metric: 'reviews', unit: 'reviews' },
{ id: 'highest_rated', label: 'Highest rated', metric: 'rating', unit: 'avg ★' },
{ id: 'newest', label: 'Newest', metric: 'added_at', unit: 'added' },
{ id: 'largest', label: 'Biggest', metric: 'lines', unit: 'lines' }
];
let activeBoard = 'most_downloaded';
function renderAnnotations() {
const el = $('annotations');
const rows = M.annotations || [];
if (!rows.length) { el.innerHTML = ''; return; }
el.innerHTML = rows.map(a =>
`<div class="hint" style="margin-top:8px">⚑ <strong>${a.date}</strong> — ${a.note}</div>`).join('');
}
function renderBoards() {
$('tabs').innerHTML = BOARDS.map(b =>
`<button class="tab${b.id === activeBoard ? ' active' : ''}" data-board="${b.id}">${b.label}</button>`).join('');
$('tabs').querySelectorAll('.tab').forEach(el => el.onclick = () => { activeBoard = el.dataset.board; renderBoards(); });
const cfg = BOARDS.find(b => b.id === activeBoard);
const rows = (M.leaderboards[activeBoard] || []);
if (!rows.length) {
const isRev = activeBoard === 'most_reviewed' || activeBoard === 'highest_rated';
$('board').innerHTML = isRev
? `<div class="empty">No <b>user</b> reviews yet.<br><br>
<a href="https://github.com/${OWNER}/${REPO}/issues/new?title=%5BRAR%5D%20review&body=%60%60%60json%0A%7B%22action%22%3A%22review%22%2C%22payload%22%3A%7B%22agent%22%3A%22%40pub%2Fslug%22%2C%22rating%22%3A5%2C%22text%22%3A%22Your%20review%22%7D%7D%0A%60%60%60" target="_blank" rel="noopener">Leave the first review →</a></div>`
: '<div class="empty">No data recorded yet for this metric.</div>';
return;
}
$('board').innerHTML = rows.map((r, i) => {
let val = r[cfg.metric];
if (cfg.metric === 'added_at') val = String(val).slice(0, 10);
else if (cfg.metric === 'rating') val = '★ ' + val;
else val = num(val);
const tier = r.tier && r.tier !== 'community' ? `<span class="pill ${esc(r.tier)}">${esc(r.tier)}</span>` : '';
const url = r.file ? `https://github.com/${OWNER}/${REPO}/blob/main/${encodeURI(r.file)}` : `https://github.com/${OWNER}/${REPO}`;
return `<div class="rank-row">
<div class="rank-n">${i + 1}</div>
<div>
<div class="rank-name"><a href="${url}" target="_blank" rel="noopener">${esc(r.display_name || short(r.name))}</a>${tier}</div>
<div class="rank-meta"><span class="mono">${esc(r.name)}</span> · ${esc(String(r.category).replace(/_/g,' '))}
${r.reviews ? ` · ${r.reviews} reviews` : ''}${r.rating ? ` · ★${r.rating}` : ''}${r.score ? ` · ${r.score} upvotes` : ''}</div>
</div>
<div class="rank-val">${val}<small>${esc(cfg.unit)}</small></div>
</div>`;
}).join('');
}
function renderPublishers() {
const rows = M.leaderboards.publishers || [];
$('pub-table').innerHTML =
`<thead><tr><th>Publisher</th><th class="num">Agents</th><th class="num">Downloads</th><th class="num">Reviews</th><th class="num">★</th><th class="num">Upvotes</th></tr></thead>
<tbody>${rows.map(p => `<tr>
<td><a href="https://github.com/${OWNER}/${REPO}/tree/main/agents/${encodeURIComponent(p.name)}" target="_blank" rel="noopener">${esc(p.name)}</a></td>
<td class="num">${num(p.agents)}</td><td class="num">${num(p.downloads)}</td>
<td class="num">${num(p.reviews)}</td><td class="num">${p.rating || '—'}</td>
<td class="num">${p.score || 0}</td></tr>`).join('')}</tbody>`;
}
function renderBars(target, rows) {
const el = $(target);
if (!rows.length) { el.innerHTML = '<div class="empty">No data</div>'; return; }
const max = Math.max(...rows.map(r => r.value), 1);
el.innerHTML = rows.map(r => `<div class="bar-row">
<div class="bar-label" title="${esc(r.label)}">${esc(r.label)}${r.extra ? ` <span style="color:var(--text-muted)">· ${esc(r.extra)}</span>` : ''}</div>
<div class="bar-track"><div class="bar-fill" style="width:${(r.value / max) * 100}%"></div></div>
<div class="bar-num">${num(r.value)}</div>
</div>`).join('');
}
function renderCDNFiles() {
const files = (M.cdn.files || []).slice(0, 12);
if (!files.length) { $('cdn-files').innerHTML = '<div class="empty">No CDN hits recorded yet</div>'; return; }
const max = Math.max(...files.map(f => f.hits), 1);
$('cdn-files').innerHTML = files.map(f => `<div class="bar-row">
<div class="bar-label" title="${esc(f.file)}">${esc(f.agent ? short(f.agent) : f.file.split('/').pop())}
<span style="color:var(--text-muted)">· ${esc(f.kind)}</span></div>
<div class="bar-track"><div class="bar-fill" style="width:${(f.hits / max) * 100}%"></div></div>
<div class="bar-num">${num(f.hits)}</div>
</div>`).join('') +
`<p class="note" style="margin-top:12px">Total CDN traffic: ${num(M.cdn.total_hits)} hits · ${bytes(M.cdn.bandwidth)} served${M.cdn.rank ? ` · jsDelivr rank #${num(M.cdn.rank)}` : ''}</p>`;
}
function renderPaths() {
const rows = M.traffic.paths || [];
if (!rows.length) { $('paths').innerHTML = '<div class="empty">Path data needs a token-authenticated snapshot</div>'; return; }
const max = Math.max(...rows.map(r => r.count), 1);
$('paths').innerHTML = rows.slice(0, 12).map(p => `<div class="bar-row">
<div class="bar-label" title="${esc(p.path)}"><a href="https://github.com${esc(p.path)}" target="_blank" rel="noopener">${esc(p.path.replace(`/${OWNER}/${REPO}`, '') || '/')}</a></div>
<div class="bar-track"><div class="bar-fill" style="width:${(p.count / max) * 100}%"></div></div>
<div class="bar-num">${num(p.count)}</div>
</div>`).join('');
}
function renderReferrers() {
const rows = M.traffic.referrers || [];
if (!rows.length) { $('referrers').innerHTML = '<div class="empty">No referrer data in this snapshot</div>'; return; }
const max = Math.max(...rows.map(r => r.count), 1);
$('referrers').innerHTML = rows.map(r => `<div class="bar-row">
<div class="bar-label">${esc(r.referrer)}</div>
<div class="bar-track"><div class="bar-fill" style="width:${(r.count / max) * 100}%"></div></div>
<div class="bar-num">${num(r.count)}</div>
</div>`).join('');
}
function renderReleases() {
const rel = M.releases || { releases: [] };
if (!rel.releases.length) { $('releases').innerHTML = '<div class="empty">No releases published</div>'; return; }
$('releases').innerHTML = rel.releases.map(r => `<div class="rank-row">
<div class="rank-n">▸</div>
<div><div class="rank-name"><a href="https://github.com/${OWNER}/${REPO}/releases/tag/${encodeURIComponent(r.tag)}" target="_blank" rel="noopener">${esc(r.tag)}</a></div>
<div class="rank-meta">${esc(r.name || '')} · ${String(r.published_at || '').slice(0, 10)} · ${r.assets.length} assets</div></div>
<div class="rank-val">${num(r.downloads)}<small>downloads</small></div>
</div>`).join('');
}
function renderSources() {
$('sources').innerHTML = (M.sources || []).map(s =>
`<div class="src-item"><b>${esc(s.name)}</b><span>${esc(s.metric)} — <a href="${esc(s.url)}" target="_blank" rel="noopener">${esc(s.url.replace('https://', ''))}</a></span></div>`).join('');
}
$('refresh').onclick = () => load();
load();
</script>
</body>
</html>