opencode-statboard 2.10.12 → 2.10.14

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 +33 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-statboard",
3
- "version": "2.10.12",
3
+ "version": "2.10.14",
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
@@ -6,6 +6,7 @@
6
6
 
7
7
  const blessed = require('blessed');
8
8
  const http = require('http');
9
+ const zlib = require('zlib');
9
10
  const { spawn } = require('child_process');
10
11
  const path = require('path');
11
12
  const pkg = require('./package.json');
@@ -148,7 +149,16 @@ class TUIServer {
148
149
 
149
150
  async start() {
150
151
  this.startServer();
151
- await this.sleep(1500);
152
+ await this.sleep(3000);
153
+ // Health check: wait for server to be ready
154
+ for (let i = 0; i < 10; i++) {
155
+ try {
156
+ await this.fetchData('/api/stats?days=7');
157
+ break;
158
+ } catch {
159
+ await this.sleep(500);
160
+ }
161
+ }
152
162
  this.initTUI();
153
163
  this.startPolling();
154
164
  process.on('SIGINT', () => this.shutdown());
@@ -179,10 +189,15 @@ class TUIServer {
179
189
 
180
190
  async fetchData(endpoint) {
181
191
  return new Promise((resolve, reject) => {
182
- http.get('http://' + this.host + ':' + this.port + endpoint, (res) => {
192
+ const req = http.get('http://' + this.host + ':' + this.port + endpoint, (res) => {
193
+ const encoding = res.headers['content-encoding'];
194
+ let stream = res;
195
+ if (encoding && encoding.includes('gzip')) {
196
+ stream = res.pipe(zlib.createGunzip());
197
+ }
183
198
  let data = '';
184
- res.on('data', chunk => data += chunk);
185
- res.on('end', () => {
199
+ stream.on('data', chunk => data += chunk);
200
+ stream.on('end', () => {
186
201
  try {
187
202
  const raw = res.headers['content-type']?.includes('utf-16')
188
203
  ? Buffer.from(data, 'utf16le').toString('utf8')
@@ -192,7 +207,10 @@ class TUIServer {
192
207
  reject(e);
193
208
  }
194
209
  });
195
- }).on('error', reject);
210
+ stream.on('error', reject);
211
+ });
212
+ req.on('error', reject);
213
+ req.setTimeout(10000, () => req.destroy(new Error('Request timeout')));
196
214
  });
197
215
  }
198
216
 
@@ -555,13 +573,15 @@ class TUIServer {
555
573
 
556
574
  const height = this.getContentHeight() - 4;
557
575
  const width = this.getContentWidth();
558
- const chartHeight = Math.max(1, Math.floor(height / 3) - 2); // 3 charts, each ~1/3 height
576
+ const chartHeight = Math.max(1, Math.floor(height / 3) - 2);
559
577
 
560
578
  // Helper: render one chart with its own max
561
579
  const renderChart = (data, label, color, maxVal) => {
562
580
  if (maxVal <= 0) return '{gray}(no data){/gray}\n';
563
581
  let lines = [];
564
- lines.push('{bold}' + label + ':{/bold}');
582
+ // Show current (today = last index) value next to label
583
+ const todayVal = data[data.length - 1] || 0;
584
+ lines.push('{bold}' + label + ': ' + this.formatNumber(todayVal) + ' (today){/bold}');
565
585
  for (let row = chartHeight - 1; row >= 0; row--) {
566
586
  let line = '';
567
587
  const threshold = (row / chartHeight) * maxVal;
@@ -586,6 +606,7 @@ class TUIServer {
586
606
  out += renderChart(output, t('output') + ' (green)', 'green', maxOut) + '\n';
587
607
  out += renderChart(cost, t('cost') + ' (yellow)', 'yellow', maxCost) + '\n';
588
608
 
609
+ // X-axis: show first date, middle date, last date
589
610
  let xAxis = '';
590
611
  const labelStep = Math.max(1, Math.ceil(width / 20));
591
612
  for (let i = 0; i < width; i++) {
@@ -598,6 +619,11 @@ class TUIServer {
598
619
  }
599
620
  out += '{gray}' + xAxis + '{/gray}\n';
600
621
 
622
+ // Add date range info
623
+ const firstDate = trend.dates ? trend.dates[0] : labels[0];
624
+ const lastDate = trend.dates ? trend.dates[trend.dates.length - 1] : labels[labels.length - 1];
625
+ out += '\n{gray}Range: ' + firstDate + ' \u2192 ' + lastDate + ' (' + labels.length + ' days){/gray}\n';
626
+
601
627
  const lastIdx = labels.length - 1;
602
628
  out += '\n{bold}' + t('today') + ':{/bold} Input: ' + this.formatNumber(input[lastIdx] || 0) + ' | Output: ' + this.formatNumber(output[lastIdx] || 0) + ' | Cost: ' + this.formatCost(cost[lastIdx] || 0);
603
629