opencode-statboard 2.10.4 → 2.10.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/tui-dashboard.js +175 -50
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-statboard",
3
- "version": "2.10.4",
3
+ "version": "2.10.5",
4
4
  "description": "Real-time dashboard for opencode token usage and cost statistics",
5
5
  "main": "server.js",
6
6
  "bin": {
package/tui-dashboard.js CHANGED
@@ -10,6 +10,119 @@ const { spawn } = require('child_process');
10
10
  const path = require('path');
11
11
  const pkg = require('./package.json');
12
12
 
13
+ const I18N = {
14
+ en: {
15
+ title: 'opencode-statboard v{version} TUI',
16
+ keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit',
17
+ footer: 'Last update: {time} | View: {view} | W:Web R:Refresh Q:Quit',
18
+ loading: 'Loading data...',
19
+ error: 'Error: {error}',
20
+ overview: 'OVERVIEW',
21
+ projects: 'PROJECTS',
22
+ models: 'MODELS',
23
+ trend: 'TREND (90 days)',
24
+ heatmap: 'HEATMAP',
25
+ noData: 'No data',
26
+ sessions: 'Sessions',
27
+ main: 'main',
28
+ total: 'total',
29
+ projectsLabel: 'Projects',
30
+ days: 'Days',
31
+ messages: 'Messages',
32
+ tokens: 'Tokens',
33
+ input: 'Input',
34
+ output: 'Output',
35
+ reasoning: 'Reasoning',
36
+ cacheRead: 'Cache Read',
37
+ cacheWrite: 'Cache Write',
38
+ total: 'Total',
39
+ cost: 'Cost',
40
+ marketValue: 'Market Value',
41
+ saved: 'Saved',
42
+ avgCostDay: 'Avg Cost/Day',
43
+ avgTokensDay: 'Avg Tokens/Day',
44
+ projectHeader: '{Project:<45} {Sessions:>10} {Tokens:>18} {Cost:>14}',
45
+ modelHeader: '{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}',
46
+ unknown: 'unknown',
47
+ today: 'Today',
48
+ version: 'Version'
49
+ },
50
+ zh: {
51
+ title: 'opencode-statboard v{version} TUI',
52
+ keys: '[1]總覽 [2]專案 [3]模型 [4]趨勢 [5]熱力 [W]網頁 [R]重整 [Q]離開 [L]語言',
53
+ footer: '上次更新: {time} | 視圖: {view} | W:網頁 R:重整 Q:離開',
54
+ loading: '載入資料中...',
55
+ error: '錯誤: {error}',
56
+ overview: '總覽',
57
+ projects: '專案',
58
+ models: '模型',
59
+ trend: '趨勢 (90 天)',
60
+ heatmap: '熱力圖',
61
+ noData: '無資料',
62
+ sessions: '會話',
63
+ main: '主',
64
+ total: '總計',
65
+ projectsLabel: '專案數',
66
+ days: '天數',
67
+ messages: '訊息',
68
+ tokens: 'Token',
69
+ input: '輸入',
70
+ output: '輸出',
71
+ reasoning: '推理',
72
+ cacheRead: '快取讀取',
73
+ cacheWrite: '快取寫入',
74
+ total: '總計',
75
+ cost: '成本',
76
+ marketValue: '市場價值',
77
+ saved: '節省',
78
+ avgCostDay: '日均成本',
79
+ avgTokensDay: '日均Token',
80
+ projectHeader: '{專案:<45} {會話:>10} {Token:>18} {成本:>14}',
81
+ modelHeader: '{模型:<40} {供應商:<14} {Token:>18} {成本:>12} {速度:>10}',
82
+ unknown: '未知',
83
+ today: '今天',
84
+ version: '版本',
85
+ sun: '日', mon: '一', tue: '二', wed: '三', thu: '四', fri: '五', sat: '六'
86
+ },
87
+ en: {
88
+ title: 'opencode-statboard v{version} TUI',
89
+ keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit [L]Lang',
90
+ footer: 'Last update: {time} | View: {view} | W:Web R:Refresh Q:Quit',
91
+ loading: 'Loading data...',
92
+ error: 'Error: {error}',
93
+ overview: 'OVERVIEW',
94
+ projects: 'PROJECTS',
95
+ models: 'MODELS',
96
+ trend: 'TREND (90 days)',
97
+ heatmap: 'HEATMAP',
98
+ noData: 'No data',
99
+ sessions: 'Sessions',
100
+ main: 'main',
101
+ total: 'total',
102
+ projectsLabel: 'Projects',
103
+ days: 'Days',
104
+ messages: 'Messages',
105
+ tokens: 'Tokens',
106
+ input: 'Input',
107
+ output: 'Output',
108
+ reasoning: 'Reasoning',
109
+ cacheRead: 'Cache Read',
110
+ cacheWrite: 'Cache Write',
111
+ total: 'Total',
112
+ cost: 'Cost',
113
+ marketValue: 'Market Value',
114
+ saved: 'Saved',
115
+ avgCostDay: 'Avg Cost/Day',
116
+ avgTokensDay: 'Avg Tokens/Day',
117
+ projectHeader: '{Project:<45} {Sessions:>10} {Tokens:>18} {Cost:>14}',
118
+ modelHeader: '{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}',
119
+ unknown: 'unknown',
120
+ today: 'Today',
121
+ version: 'Version',
122
+ sun: 'Sun', mon: 'Mon', tue: 'Tue', wed: 'Wed', thu: 'Thu', fri: 'Fri', sat: 'Sat'
123
+ }
124
+ };
125
+
13
126
  class TUIServer {
14
127
  constructor(options = {}) {
15
128
  this.port = options.port || 4868;
@@ -30,6 +143,7 @@ class TUIServer {
30
143
  this.pollInterval = null;
31
144
  this.lastUpdate = null;
32
145
  this._earlyLogs = [];
146
+ this.lang = 'zh'; // Default to Chinese
33
147
  }
34
148
 
35
149
  async start() {
@@ -183,12 +297,30 @@ class TUIServer {
183
297
  this.screen.key(['S-tab'], () => this.prevView());
184
298
  this.screen.key(['r'], () => this.pollData());
185
299
  this.screen.key(['w'], () => this.openWeb());
300
+ this.screen.key(['l'], () => this.toggleLang());
301
+
302
+ this.createLayout();
303
+ this.render();
304
+ }
186
305
 
306
+ toggleLang() {
307
+ this.lang = this.lang === 'zh' ? 'en' : 'zh';
187
308
  this.createLayout();
188
309
  this.render();
189
310
  }
190
311
 
312
+ t(key) {
313
+ return I18N[this.lang][key] || key;
314
+ }
315
+
191
316
  createLayout() {
317
+ // Remove old layout if exists
318
+ if (this.layout.header) this.screen.remove(this.layout.header);
319
+ if (this.layout.main) this.screen.remove(this.layout.main);
320
+ if (this.layout.footer) this.screen.remove(this.layout.footer);
321
+
322
+ const t = this.t.bind(this);
323
+
192
324
  this.layout.header = blessed.box({
193
325
  top: 0,
194
326
  left: 0,
@@ -197,7 +329,7 @@ class TUIServer {
197
329
  tags: true,
198
330
  border: { type: 'line' },
199
331
  style: { border: { fg: 'cyan' } },
200
- content: '{center}{bold}opencode-statboard v' + pkg.version + '{/bold} TUI | [1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit{/center}'
332
+ content: '{center}{bold}' + t('title').replace('{version}', pkg.version) + '{/bold} | ' + t('keys') + ' [L]Lang{/center}'
201
333
  });
202
334
 
203
335
  this.layout.main = blessed.box({
@@ -205,7 +337,6 @@ class TUIServer {
205
337
  bottom: 2,
206
338
  left: 0,
207
339
  width: '100%',
208
- height: '100%-4',
209
340
  tags: true,
210
341
  border: { type: 'line' },
211
342
  style: { border: { fg: 'blue' } },
@@ -224,14 +355,12 @@ class TUIServer {
224
355
  tags: true,
225
356
  border: { type: 'line' },
226
357
  style: { border: { fg: 'green' } },
227
- content: '{center}Last update: {bold}never{/bold} | View: {bold}overview{/bold} | W:Web R:Refresh Q:Quit{/center}'
358
+ content: '{center}' + t('footer').replace('{time}', this.lastUpdate ? this.lastUpdate.toLocaleTimeString() : 'never').replace('{view}', t(this.currentView)) + '{/center}'
228
359
  });
229
360
 
230
361
  this.screen.append(this.layout.header);
231
362
  this.screen.append(this.layout.main);
232
363
  this.screen.append(this.layout.footer);
233
-
234
- this.render();
235
364
  }
236
365
 
237
366
  switchView(view) {
@@ -260,16 +389,10 @@ class TUIServer {
260
389
  }
261
390
 
262
391
  updateFooter() {
392
+ const t = this.t.bind(this);
263
393
  const time = this.lastUpdate ? this.lastUpdate.toLocaleTimeString() : 'never';
264
- const viewLabels = {
265
- overview: 'Overview',
266
- projects: 'Projects',
267
- models: 'Models',
268
- trend: 'Trend',
269
- heatmap: 'Heatmap'
270
- };
271
394
  this.layout.footer.setContent(
272
- '{center}Last update: {bold}' + time + '{/bold} | View: {bold}' + (viewLabels[this.currentView] || this.currentView) + '{/bold} | W:Web R:Refresh Q:Quit{/center}'
395
+ '{center}' + t('footer').replace('{time}', time).replace('{view}', t(this.currentView)) + '{/center}'
273
396
  );
274
397
  }
275
398
 
@@ -286,7 +409,8 @@ class TUIServer {
286
409
 
287
410
  getContentHeight() {
288
411
  const mainHeight = this.layout.main.height;
289
- return typeof mainHeight === 'number' ? mainHeight - 2 : this.screen.height - 6;
412
+ if (typeof mainHeight === 'number') return mainHeight - 2;
413
+ return this.screen.height - 6; // header(2) + footer(2) + borders(2)
290
414
  }
291
415
 
292
416
  render() {
@@ -314,43 +438,45 @@ class TUIServer {
314
438
 
315
439
  renderOverview() {
316
440
  const ov = this.data;
317
- if (!ov || ov.loading) return '{center}{bold}Loading data...{/bold}{/center}';
441
+ const t = this.t.bind(this);
442
+ if (!ov || ov.loading) return '{center}{bold}' + t('loading') + '{/bold}{/center}';
318
443
 
319
444
  const tokens = ov.tokens || {};
320
445
  const cost = ov.cost || {};
321
446
 
322
447
  const lines = [
323
- '{center}{bold}\u2501\u2501\u2501 OVERVIEW \u2501\u2501\u2501{/bold}{/center}',
448
+ '{center}{bold}\u2501\u2501\u2501 ' + t('overview') + ' \u2501\u2501\u2501{/bold}{/center}',
324
449
  '',
325
- '{bold}Sessions:{/bold} ' + (ov.overview?.sessions?.main || 0) + ' main / ' + (ov.overview?.sessions?.total || 0) + ' total',
326
- '{bold}Projects:{/bold} ' + (ov.overview?.projects || 0),
327
- '{bold}Days:{/bold} ' + (ov.overview?.days || 0),
328
- '{bold}Messages:{/bold} ' + (ov.overview?.messages || 0),
450
+ '{bold}' + t('sessions') + ':{/bold} ' + (ov.overview?.sessions?.main || 0) + ' ' + t('main') + ' / ' + (ov.overview?.sessions?.total || 0) + ' ' + t('total'),
451
+ '{bold}' + t('projectsLabel') + ':{/bold} ' + (ov.overview?.projects || 0),
452
+ '{bold}' + t('days') + ':{/bold} ' + (ov.overview?.days || 0),
453
+ '{bold}' + t('messages') + ':{/bold} ' + (ov.overview?.messages || 0),
329
454
  '',
330
- '{bold}Tokens:{/bold}',
331
- ' Input: ' + this.formatNumber(tokens.input || 0),
332
- ' Output: ' + this.formatNumber(tokens.output || 0),
333
- ' Reasoning: ' + this.formatNumber(tokens.reasoning || 0),
334
- ' Cache Read: ' + this.formatNumber(tokens.cacheRead || 0),
335
- ' Cache Write: ' + this.formatNumber(tokens.cacheWrite || 0),
336
- ' {bold}Total: ' + this.formatNumber(tokens.total || 0) + '{/bold}',
455
+ '{bold}' + t('tokens') + ':{/bold}',
456
+ ' ' + t('input') + ': ' + this.formatNumber(tokens.input || 0),
457
+ ' ' + t('output') + ': ' + this.formatNumber(tokens.output || 0),
458
+ ' ' + t('reasoning') + ': ' + this.formatNumber(tokens.reasoning || 0),
459
+ ' ' + t('cacheRead') + ': ' + this.formatNumber(tokens.cacheRead || 0),
460
+ ' ' + t('cacheWrite') + ': ' + this.formatNumber(tokens.cacheWrite || 0),
461
+ ' {bold}' + t('total') + ': ' + this.formatNumber(tokens.total || 0) + '{/bold}',
337
462
  '',
338
- '{bold}Cost:{/bold} ' + this.formatCost(cost.total || 0),
339
- '{bold}Market Value:{/bold} ' + this.formatCost(cost.marketValue || 0),
340
- '{bold}Saved:{/bold} ' + this.formatCost(cost.saved || 0) + (cost.savedPct ? ' (' + cost.savedPct + '%)' : ''),
463
+ '{bold}' + t('cost') + ':{/bold} ' + this.formatCost(cost.total || 0),
464
+ '{bold}' + t('marketValue') + ':{/bold} ' + this.formatCost(cost.marketValue || 0),
465
+ '{bold}' + t('saved') + ':{/bold} ' + this.formatCost(cost.saved || 0) + (cost.savedPct ? ' (' + cost.savedPct + '%)' : ''),
341
466
  '',
342
- '{bold}Avg Cost/Day:{/bold} ' + this.formatCost(cost.avgCostPerDay || 0),
343
- '{bold}Avg Tokens/Day:{/bold} ' + this.formatNumber(cost.avgTokensPerDay || 0)
467
+ '{bold}' + t('avgCostDay') + ':{/bold} ' + this.formatCost(cost.avgCostPerDay || 0),
468
+ '{bold}' + t('avgTokensDay') + ':{/bold} ' + this.formatNumber(cost.avgTokensPerDay || 0)
344
469
  ];
345
470
  return lines.join('\n');
346
471
  }
347
472
 
348
473
  renderProjects() {
349
474
  const projects = this.data.projects || [];
350
- if (projects.length === 0) return '{center}No projects{/center}';
475
+ const t = this.t.bind(this);
476
+ if (projects.length === 0) return '{center}' + t('noData') + '{/center}';
351
477
 
352
- const lines = ['{center}{bold}\u2501\u2501\u2501 PROJECTS \u2501\u2501\u2501{/bold}{/center}', ''];
353
- lines.push('{bold}{Project:<45} {Sessions:>10} {Tokens:>18} {Cost:>14}{/bold}');
478
+ const lines = ['{center}{bold}\u2501\u2501\u2501 ' + t('projects') + ' \u2501\u2501\u2501{/bold}{/center}', ''];
479
+ lines.push('{bold}' + t('projectHeader') + '{/bold}');
354
480
  lines.push('{gray}\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500{/gray}');
355
481
 
356
482
  for (const p of projects.slice(0, 50)) {
@@ -367,7 +493,7 @@ class TUIServer {
367
493
 
368
494
  if (projects.length > 50) {
369
495
  lines.push('');
370
- lines.push('{gray}... and ' + (projects.length - 50) + ' more projects{/gray}');
496
+ lines.push('{gray}... ' + t('noData') + ' ' + (projects.length - 50) + ' ' + t('projects') + '{/gray}');
371
497
  }
372
498
 
373
499
  return lines.join('\n');
@@ -375,10 +501,11 @@ class TUIServer {
375
501
 
376
502
  renderModels() {
377
503
  const models = this.data.models || [];
378
- if (models.length === 0) return '{center}No models{/center}';
504
+ const t = this.t.bind(this);
505
+ if (models.length === 0) return '{center}' + t('noData') + '{/center}';
379
506
 
380
- const lines = ['{center}{bold}\u2501\u2501\u2501 MODELS \u2501\u2501\u2501{/bold}{/center}', ''];
381
- lines.push('{bold}{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}{/bold}');
507
+ const lines = ['{center}{bold}\u2501\u2501\u2501 ' + t('models') + ' \u2501\u2501\u2501{/bold}{/center}', ''];
508
+ lines.push('{bold}' + t('modelHeader') + '{/bold}');
382
509
  lines.push('{gray}\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500{/gray}');
383
510
 
384
511
  for (const m of models.slice(0, 30)) {
@@ -400,8 +527,9 @@ class TUIServer {
400
527
 
401
528
  renderTrend() {
402
529
  const trend = this.data.trend;
530
+ const t = this.t.bind(this);
403
531
  if (!trend || !trend.labels || !trend.labels.length) {
404
- return '{center}No trend data{/center}';
532
+ return '{center}' + t('noData') + '{/center}';
405
533
  }
406
534
 
407
535
  const labels = trend.labels;
@@ -413,7 +541,7 @@ class TUIServer {
413
541
  const height = this.getContentHeight() - 4;
414
542
  const width = this.getContentWidth();
415
543
 
416
- let out = '{center}{bold}\u2501\u2501\u2501 TREND (90 days) \u2501\u2501\u2501{/bold}{/center}\n\n';
544
+ let out = '{center}{bold}\u2501\u2501\u2501 ' + t('trend') + ' \u2501\u2501\u2501{/bold}{/center}\n\n';
417
545
  out += '{bold}Input (cyan) / Output (green) / Cost (yellow){/bold}\n\n';
418
546
 
419
547
  for (let row = height - 1; row >= 0; row--) {
@@ -444,15 +572,16 @@ class TUIServer {
444
572
  out += '\n{gray}' + xAxis + '{/gray}\n';
445
573
 
446
574
  const lastIdx = labels.length - 1;
447
- out += '\n{bold}Today:{/bold} Input: ' + this.formatNumber(input[lastIdx] || 0) + ' | Output: ' + this.formatNumber(output[lastIdx] || 0) + ' | Cost: ' + this.formatCost(cost[lastIdx] || 0);
575
+ out += '\n{bold}' + t('today') + ':{/bold} Input: ' + this.formatNumber(input[lastIdx] || 0) + ' | Output: ' + this.formatNumber(output[lastIdx] || 0) + ' | Cost: ' + this.formatCost(cost[lastIdx] || 0);
448
576
 
449
577
  return out;
450
578
  }
451
579
 
452
580
  renderHeatmap() {
453
581
  const trend = this.data.trend;
582
+ const t = this.t.bind(this);
454
583
  if (!trend || !trend.dates || !trend.dates.length) {
455
- return '{center}No heatmap data{/center}';
584
+ return '{center}' + t('noData') + '{/center}';
456
585
  }
457
586
 
458
587
  const dates = trend.dates;
@@ -472,7 +601,7 @@ class TUIServer {
472
601
 
473
602
  const monthNames = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
474
603
 
475
- let out = '{center}{bold}\u2501\u2501\u2501 HEATMAP (90 days) \u2501\u2501\u2501{/bold}{/center}\n\n';
604
+ let out = '{center}{bold}\u2501\u2501\u2501 ' + t('heatmap') + ' \u2501\u2501\u2501{/bold}{/center}\n\n';
476
605
 
477
606
  let monthHeader = ' ';
478
607
  let lastMonth = -1;
@@ -492,7 +621,7 @@ class TUIServer {
492
621
  }
493
622
  out = '{gray}' + monthHeader + '{/gray}\n';
494
623
 
495
- const dow = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
624
+ const dow = [t('sun') || 'Sun', t('mon') || 'Mon', t('tue') || 'Tue', t('wed') || 'Wed', t('thu') || 'Thu', t('fri') || 'Fri', t('sat') || 'Sat'];
496
625
  for (let d = 0; d < 7; d++) {
497
626
  let line = '{bold}' + dow[d].padEnd(4) + '{/bold} ';
498
627
  for (let w = 0; w < weeks.length; w++) {
@@ -511,6 +640,7 @@ class TUIServer {
511
640
 
512
641
  out += '\n{gray}Less \u2591\u2591\u2592\u2592\u2593\u2593\u2588\u2588 More (max: ' + this.formatNumber(max) + '){/gray}';
513
642
  return out;
643
+ return out;
514
644
  }
515
645
 
516
646
  getHeatLevel(value, max) {
@@ -577,11 +707,6 @@ class TUIServer {
577
707
  return typeof mainWidth === 'number' ? mainWidth - 2 : this.screen.width - 4;
578
708
  }
579
709
 
580
- getContentHeight() {
581
- const mainHeight = this.layout.main.height;
582
- return typeof mainHeight === 'number' ? mainHeight - 2 : this.screen.height - 6;
583
- }
584
-
585
710
  sleep(ms) {
586
711
  return new Promise(resolve => setTimeout(resolve, ms));
587
712
  }