opencode-statboard 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.md +1 -0
- package/package.json +2 -2
- package/public/index.html +65 -3
package/AGENTS.md
CHANGED
|
@@ -13,7 +13,7 @@ opencode-dashboard
|
|
|
13
13
|
## Architecture
|
|
14
14
|
|
|
15
15
|
- `server.js` — Node.js HTTP server (zero frameworks, pure `http` module)
|
|
16
|
-
- `public/index.html` — Single-file frontend (vanilla JS/CSS/HTML, no build step)
|
|
16
|
+
- `public/index.html` — Single-file frontend (vanilla JS/CSS/HTML, no build step). Report charts (`#speed-bars`, `#agent-bars`, `#session-bars`) render from `/api/report` data via `renderReportCharts`; `check-frontend-smoke.js` executes the page's real script against live API data with a stub DOM.
|
|
17
17
|
- `backups/` — Gzipped DB backups (auto-rotated, `OPENCODE_BACKUP_RETENTION`)
|
|
18
18
|
|
|
19
19
|
## Key Patterns
|
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@ Real-time dashboard for your [opencode](https://opencode.ai) token usage and cos
|
|
|
9
9
|
- Tool usage breakdown with percentage bars (collapsible)
|
|
10
10
|
- Per-model usage with cache read stats and generation speed (output tok/s)
|
|
11
11
|
- Usage reports: per-agent speed, wall/active time, and top-20 sessions by duration
|
|
12
|
+
- Visual charts for model speed, agent wall/active time, and longest sessions
|
|
12
13
|
- Daily trend chart (7D / 30D / 90D)
|
|
13
14
|
- Usage reports: Daily / Weekly / Monthly / All time
|
|
14
15
|
- i18n: English + Traditional Chinese, auto-detects browser language
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-statboard",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Real-time dashboard for opencode token usage and cost statistics",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node server.js",
|
|
11
|
-
"test": "node --check server.js && node --check check-lib.js && node --check check-stats-verify.js && node --check check-trend-verify.js && node --check check-report-verify.js"
|
|
11
|
+
"test": "node --check server.js && node --check check-lib.js && node --check check-stats-verify.js && node --check check-trend-verify.js && node --check check-report-verify.js && node --check check-frontend-smoke.js"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"opencode",
|
package/public/index.html
CHANGED
|
@@ -173,6 +173,29 @@
|
|
|
173
173
|
<div id="reportContent" style="font-family:monospace;font-size:13px;line-height:1.6;white-space:pre;overflow-x:auto;color:var(--text)">Loading…</div>
|
|
174
174
|
</section>
|
|
175
175
|
|
|
176
|
+
<section>
|
|
177
|
+
<h2 data-i18n="modelSpeed">MODEL SPEED</h2>
|
|
178
|
+
<div id="speed-bars"></div>
|
|
179
|
+
</section>
|
|
180
|
+
|
|
181
|
+
<section>
|
|
182
|
+
<h2 data-i18n="agentTime">AGENT TIME</h2>
|
|
183
|
+
<div class="legend">
|
|
184
|
+
<span><i class="sw" style="background:var(--cache)"></i>wall</span>
|
|
185
|
+
<span><i class="sw" style="background:var(--out)"></i>active</span>
|
|
186
|
+
</div>
|
|
187
|
+
<div id="agent-bars"></div>
|
|
188
|
+
</section>
|
|
189
|
+
|
|
190
|
+
<section>
|
|
191
|
+
<h2 data-i18n="topSessions">TOP SESSIONS</h2>
|
|
192
|
+
<div class="legend">
|
|
193
|
+
<span><i class="sw" style="background:var(--cache)"></i>wall</span>
|
|
194
|
+
<span><i class="sw" style="background:var(--out)"></i>active</span>
|
|
195
|
+
</div>
|
|
196
|
+
<div id="session-bars"></div>
|
|
197
|
+
</section>
|
|
198
|
+
|
|
176
199
|
<script>
|
|
177
200
|
const STRINGS = {
|
|
178
201
|
en: {
|
|
@@ -185,7 +208,7 @@ const STRINGS = {
|
|
|
185
208
|
thModel: 'Model', thMsgs: 'Messages', thSpeed: 'Speed', thUsage: 'Usage', thCost: 'Cost',
|
|
186
209
|
dailyTrend: 'DAILY TREND ({days} DAYS)',
|
|
187
210
|
inputDay: 'Input / Day', outputDay: 'Output / Day', cacheReadDay: 'Cache Read / Day', costDay: 'Cost / Day',
|
|
188
|
-
report: 'USAGE REPORT', all: 'All', daily: 'Daily', weekly: 'Weekly', monthly: 'Monthly',
|
|
211
|
+
report: 'USAGE REPORT', all: 'All', daily: 'Daily', weekly: 'Weekly', monthly: 'Monthly', modelSpeed: 'MODEL SPEED', agentTime: 'AGENT TIME', topSessions: 'TOP SESSIONS',
|
|
189
212
|
updating: 'updating…', generating: 'Generating trend data…', cachedAt: 'cached at', allFree: 'All models free — no cost recorded',
|
|
190
213
|
live: 'Live', loading: 'Loading…', lastUpdated: 'Last updated', dataAgo: 'data generated',
|
|
191
214
|
statsFail: 'Failed to read opencode stats', connFail: 'Connection failed',
|
|
@@ -202,7 +225,7 @@ const STRINGS = {
|
|
|
202
225
|
thModel: '模型', thMsgs: '訊息', thSpeed: '速度', thUsage: '用量', thCost: '費用',
|
|
203
226
|
dailyTrend: '近 {days} 天趨勢',
|
|
204
227
|
inputDay: 'Input / 天', outputDay: 'Output / 天', cacheReadDay: 'Cache Read / 天', costDay: '費用 / 天',
|
|
205
|
-
report: '用量報告', all: '全部', daily: '每日', weekly: '每週', monthly: '每月',
|
|
228
|
+
report: '用量報告', all: '全部', daily: '每日', weekly: '每週', monthly: '每月', modelSpeed: '模型速度', agentTime: '代理時間', topSessions: '最長場次',
|
|
206
229
|
updating: '更新中…', generating: '趨勢資料產生中…', cachedAt: '快取於', allFree: '全部使用免費模型,無費用紀錄',
|
|
207
230
|
live: '即時更新', loading: '載入中…', lastUpdated: '更新於', dataAgo: '數據產生於',
|
|
208
231
|
statsFail: 'opencode stats 讀取失敗', connFail: '連線失敗',
|
|
@@ -265,6 +288,8 @@ const fmt = (n) => {
|
|
|
265
288
|
return String(Math.round(n));
|
|
266
289
|
};
|
|
267
290
|
const fmtCost = (n) => (n == null || isNaN(n)) ? '—' : '$' + n.toFixed(2);
|
|
291
|
+
const fmtDur = (ms) => { const v = Math.round((ms || 0) / 1000); if (!isFinite(v) || v < 0) return '—'; const d = Math.floor(v / 86400), h = Math.floor(v % 86400 / 3600), m = Math.floor(v % 3600 / 60), s = v % 60; if (d > 0) return d + 'd' + h + 'h'; if (h > 0) return h + 'h' + String(m).padStart(2, '0') + 'm'; if (m > 0) return m + 'm' + String(s).padStart(2, '0') + 's'; return s + 's'; };
|
|
292
|
+
const esc = (s) => String(s == null ? '' : s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
268
293
|
const fmtSpeed = (n) => (n == null || isNaN(n) || !isFinite(n)) ? '—' : ((n >= 100 ? Math.round(n) : Math.round(n * 10) / 10) + ' tok/s');
|
|
269
294
|
|
|
270
295
|
function barRow(name, value, max, color) {
|
|
@@ -446,12 +471,48 @@ let reportLoading = false;
|
|
|
446
471
|
let reportRetry = 0;
|
|
447
472
|
const MAX_REPORT_RETRIES = 12;
|
|
448
473
|
|
|
474
|
+
function twoBars(name, wallMs, activeMs, maxWall, valText, sub) {
|
|
475
|
+
const w = maxWall > 0 ? Math.max(0.5, (wallMs / maxWall) * 100) : 0;
|
|
476
|
+
const a = maxWall > 0 ? Math.max(0.5, (activeMs / maxWall) * 100) : 0;
|
|
477
|
+
return `<div class="bar-row"><div class="name" title="${esc(sub || '')}">${esc(name)}</div>
|
|
478
|
+
<div><div class="track" style="height:8px;margin-bottom:3px"><div class="fill" style="width:${w}%;background:var(--cache)"></div></div>
|
|
479
|
+
<div class="track" style="height:8px"><div class="fill" style="width:${a}%;background:var(--out)"></div></div></div>
|
|
480
|
+
<div class="val">${valText}</div></div>`;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function renderReportCharts(r) {
|
|
484
|
+
if (!r) return;
|
|
485
|
+
const spd = (r.providers || []).slice().sort((a, b) => (b.speed == null ? -1 : b.speed) - (a.speed == null ? -1 : a.speed));
|
|
486
|
+
const smax = Math.max(0, ...spd.map((p) => p.speed || 0));
|
|
487
|
+
const fullName = (p) => p.provider + '/' + p.model;
|
|
488
|
+
$('speed-bars').innerHTML = spd.length ? spd.map((p) => {
|
|
489
|
+
const pct = smax > 0 && p.speed != null ? Math.max(0.5, (p.speed / smax) * 100) : 0;
|
|
490
|
+
return `<div class="bar-row"><div class="name" title="${esc(fullName(p))}">${esc(fullName(p))}</div>
|
|
491
|
+
<div class="track"><div class="fill" style="width:${pct}%;background:var(--in)"></div></div>
|
|
492
|
+
<div class="val">${fmtSpeed(p.speed)}</div></div>`;
|
|
493
|
+
}).join('') : '<div class="val">—</div>';
|
|
494
|
+
|
|
495
|
+
const agents = r.agents || [];
|
|
496
|
+
const amax = Math.max(0, ...agents.map((a) => a.wallMs || 0));
|
|
497
|
+
$('agent-bars').innerHTML = agents.length ? agents.map((a) =>
|
|
498
|
+
twoBars(a.agent, a.wallMs || 0, a.activeMs || 0, amax,
|
|
499
|
+
fmtDur(a.wallMs) + ' / ' + fmtDur(a.activeMs), (a.sessions || 0) + ' sessions')
|
|
500
|
+
).join('') : '<div class="val">—</div>';
|
|
501
|
+
|
|
502
|
+
const sess = r.sessions || [];
|
|
503
|
+
const xmax = Math.max(0, ...sess.map((s) => s.wallMs || 0));
|
|
504
|
+
$('session-bars').innerHTML = sess.length ? sess.map((s) =>
|
|
505
|
+
twoBars(String(s.id).slice(0, 12), s.wallMs || 0, s.activeMs || 0, xmax,
|
|
506
|
+
fmtDur(s.wallMs) + ' · ' + fmtSpeed(s.speed),
|
|
507
|
+
(s.title || '') + ' · ' + s.agent + ' · ' + s.provider + '/' + s.model + ' · ' + (s.messages || 0) + ' msgs')
|
|
508
|
+
).join('') : '<div class="val">—</div>';
|
|
509
|
+
}
|
|
510
|
+
|
|
449
511
|
function formatReport(jr) {
|
|
450
512
|
const genTime = jr.generatedAt ? new Date(jr.generatedAt).toLocaleTimeString(lang === 'zh-TW' ? 'zh-TW' : 'en', { hour12: false }) : '?';
|
|
451
513
|
const cachedNote = jr.stale ? ' [⟳ ' + t('updating') + ']' : ' [' + t('cachedAt') + ' ' + genTime + ']';
|
|
452
514
|
const fmtCost = (n) => { const v = parseFloat(n); if (isNaN(v)) return '—'; return v === 0 ? '$0.00' : '$' + v.toFixed(4); };
|
|
453
515
|
const fmtT = (n) => { const v = parseInt(n, 10); if (isNaN(v)) return '—'; if (v >= 1e9) return (v/1e9).toFixed(2)+'B'; if (v >= 1e6) return (v/1e6).toFixed(1)+'M'; if (v >= 1e3) return (v/1e3).toFixed(1)+'K'; return String(v); };
|
|
454
|
-
const fmtDur = (ms) => { const v = Math.round((ms || 0) / 1000); if (!isFinite(v) || v < 0) return '—'; const d = Math.floor(v / 86400), h = Math.floor(v % 86400 / 3600), m = Math.floor(v % 3600 / 60), s = v % 60; if (d > 0) return d + 'd' + h + 'h'; if (h > 0) return h + 'h' + String(m).padStart(2, '0') + 'm'; if (m > 0) return m + 'm' + String(s).padStart(2, '0') + 's'; return s + 's'; };
|
|
455
516
|
const pad = (s, w) => { s = String(s); return s.length >= w ? s : s + ' '.repeat(w - s.length); };
|
|
456
517
|
const rpad = (s, w) => { s = String(s); return s.length >= w ? s : ' '.repeat(w - s.length) + s; };
|
|
457
518
|
let out = '';
|
|
@@ -517,6 +578,7 @@ async function loadReport(days) {
|
|
|
517
578
|
}
|
|
518
579
|
reportRetry = 0;
|
|
519
580
|
$('reportContent').textContent = formatReport(j.report);
|
|
581
|
+
renderReportCharts(j.report);
|
|
520
582
|
} catch (e) {
|
|
521
583
|
$('reportContent').textContent = t('connFail') + ': ' + e.message;
|
|
522
584
|
}
|