opencode-statboard 2.0.9 → 2.0.10
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 +2 -2
- package/package.json +1 -1
- package/public/index.html +2 -1
- package/server.js +14 -11
package/AGENTS.md
CHANGED
|
@@ -115,8 +115,8 @@ npm install -g opencode-statboard # after the Actions run is green
|
|
|
115
115
|
## Known Constraints
|
|
116
116
|
|
|
117
117
|
- `better-sqlite3` is a native addon; must match Node.js ABI
|
|
118
|
-
- `attributeUsage` does a full DB scan (~
|
|
119
|
-
- Trend
|
|
118
|
+
- `attributeUsage` does a full DB scan (~35k messages); cached 300s via `getAttrAll()`
|
|
119
|
+
- Trend buckets are sliced from the same `getAttrAll()` attribution the report uses — never a separate windowed call (windowed calls inflate in-window days via residual growth; fixed 2026-09-29 after measuring +0.25–1.7M input/day). Remaining panel differences are cache ages only (trend ≤60s, report ≤10min, both timestamps shown)
|
|
120
120
|
- V2 tool counts use `json_each` over `session_message` content (~1.2s full scan) and run on every 15s refresh; legacy V1 DBs scan `part` instead (~0.8s)
|
|
121
121
|
- OpenCode V2 writes `cost = 0` for free/subscription providers, so $ totals only reflect paid (per-token billed) usage — same field, not a schema issue
|
|
122
122
|
- `gzip` compression on all `/api/` responses (>512B, level 1 for speed)
|
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -338,12 +338,13 @@ function renderTrend(data) {
|
|
|
338
338
|
const maxAll = Math.max(...data.input, ...data.output, ...(data.reasoning || []), ...data.cacheRead);
|
|
339
339
|
const hasCost = data.cost.some((v) => v >= 0.0001);
|
|
340
340
|
|
|
341
|
+
const trendTime = data.generatedAt ? new Date(data.generatedAt).toLocaleTimeString(lang === 'zh-TW' ? 'zh-TW' : 'en', { hour12: false }) : '?';
|
|
341
342
|
$('trend-tokens').innerHTML = data.labels.map((l, i) => {
|
|
342
343
|
const hi = maxAll > 0 ? (data.input[i] / maxAll) * 100 : 0;
|
|
343
344
|
const ho = maxAll > 0 ? (data.output[i] / maxAll) * 100 : 0;
|
|
344
345
|
const hr = maxAll > 0 && data.reasoning ? (data.reasoning[i] / maxAll) * 100 : 0;
|
|
345
346
|
const hc = maxAll > 0 ? (data.cacheRead[i] / maxAll) * 100 : 0;
|
|
346
|
-
const tip = l + ': In ' + fmt(data.input[i]) + ' · Out ' + fmt(data.output[i]) + ' · Reas ' + fmt(data.reasoning ? data.reasoning[i] : 0) + ' · Cache ' + fmt(data.cacheRead[i]);
|
|
347
|
+
const tip = l + ': In ' + fmt(data.input[i]) + ' · Out ' + fmt(data.output[i]) + ' · Reas ' + fmt(data.reasoning ? data.reasoning[i] : 0) + ' · Cache ' + fmt(data.cacheRead[i]) + ' · ' + trendTime;
|
|
347
348
|
return `<div class="col" title="${tip}">
|
|
348
349
|
<div style="display:flex;gap:2px;align-items:flex-end;width:100%;height:170px;justify-content:center">
|
|
349
350
|
<div style="position:relative;width:100%;height:100%">
|
package/server.js
CHANGED
|
@@ -207,12 +207,16 @@ function cleanExpiredCache(cache, ttl) {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
async function generateTrend(days) {
|
|
210
|
-
const now = Date.now();
|
|
211
|
-
|
|
212
210
|
// Buckets: local midnights, today -> (days-1) days ago.
|
|
213
|
-
// Values
|
|
214
|
-
//
|
|
215
|
-
//
|
|
211
|
+
// Values are sliced from the SHARED all-time attribution (getAttrAll(),
|
|
212
|
+
// the same object the usage report uses) — never a separate windowed
|
|
213
|
+
// attributeUsage call. Windowed attribution inflates in-window days:
|
|
214
|
+
// messages before the window are excluded from msgTok, so the session
|
|
215
|
+
// residual grows and lands entirely on windowed days (measured
|
|
216
|
+
// +0.25–1.7M input/day on 2026-09-29). One shared attribution makes
|
|
217
|
+
// trend buckets and report periods structurally identical; any remaining
|
|
218
|
+
// panel difference is only cache age (trend ≤60s, report ≤10min, both
|
|
219
|
+
// timestamps shown in the UI).
|
|
216
220
|
const buckets = [];
|
|
217
221
|
const today = new Date();
|
|
218
222
|
for (let i = 0; i < days; i++) {
|
|
@@ -221,7 +225,7 @@ async function generateTrend(days) {
|
|
|
221
225
|
d.setHours(0, 0, 0, 0);
|
|
222
226
|
buckets.push(d);
|
|
223
227
|
}
|
|
224
|
-
const a =
|
|
228
|
+
const a = getAttrAll();
|
|
225
229
|
const at = (b, f) => {
|
|
226
230
|
const D = a.perDay[localDayKey(b)];
|
|
227
231
|
return D ? D[f] : 0;
|
|
@@ -232,7 +236,7 @@ async function generateTrend(days) {
|
|
|
232
236
|
};
|
|
233
237
|
|
|
234
238
|
return {
|
|
235
|
-
generatedAt:
|
|
239
|
+
generatedAt: attrAllCache.at, // attribution build time, not response time
|
|
236
240
|
step: 1,
|
|
237
241
|
labels: buckets.map((b) => (b.getMonth() + 1) + '/' + b.getDate()),
|
|
238
242
|
sessions: buckets.map(sess),
|
|
@@ -324,10 +328,9 @@ function attributeUsage(startMs, endMs) {
|
|
|
324
328
|
// 2. sessions intersecting the period: spread residual
|
|
325
329
|
const srows = dbQuery(`SELECT id, agent, COALESCE(json_extract(model, '$.providerID'), 'unknown') AS provider, COALESCE(json_extract(model, '$.id'), 'unknown') AS model, time_created AS tc, time_updated AS tu, tokens_input AS si, tokens_output AS so, tokens_reasoning AS sr, tokens_cache_read AS scr, tokens_cache_write AS scw, cost AS sc FROM ${schema.session} WHERE time_updated >= ${startMs} AND time_created < ${endMs};`) || [];
|
|
326
330
|
for (const s of srows) {
|
|
327
|
-
// Use the session's FULL span for residual distribution
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
// consistent regardless of the caller's time window.
|
|
331
|
+
// Use the session's FULL span for residual distribution. All consumers
|
|
332
|
+
// share one all-time attribution (getAttrAll), so per-day values are
|
|
333
|
+
// identical whichever period slices them.
|
|
331
334
|
const d0 = new Date(new Date(s.tc).setHours(0, 0, 0, 0));
|
|
332
335
|
const d1 = new Date(new Date(s.tu).setHours(0, 0, 0, 0));
|
|
333
336
|
const spanKeys = [];
|