opencode-statboard 2.0.0 → 2.0.2

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/README.md CHANGED
@@ -1,31 +1,48 @@
1
1
  # opencode-statboard
2
2
 
3
- Real-time dashboard for your [opencode](https://opencode.ai) token usage and cost statistics, built with zero dependencies (pure Node.js + vanilla HTML/CSS/JS).
3
+ Real-time dashboard for your [opencode](https://opencode.ai) token usage and cost statistics.
4
4
 
5
5
  ## Features
6
6
 
7
7
  - Live-updating overview: sessions, messages, total cost, tokens per session
8
- - Token statistics: Input / Output / Cache Read / Cache Write
8
+ - Token statistics: Input / Output / Reasoning / Cache Read / Cache Write
9
9
  - Tool usage breakdown with percentage bars (collapsible)
10
10
  - Per-model usage with cache read stats
11
- - Daily trend chart (7D / 30D / 90D, 90D uses downsampling for speed)
11
+ - Daily trend chart (7D / 30D / 90D)
12
+ - Usage reports: Daily / Weekly / Monthly / All time
12
13
  - i18n: English + Traditional Chinese, auto-detects browser language
14
+ - Gzip compressed API responses
15
+ - Auto port fallback if 4868 is in use
13
16
 
14
17
  ## Requirements
15
18
 
16
19
  - Node.js (tested on v24)
17
20
  - [opencode](https://opencode.ai) CLI installed globally via npm
18
- - No npm packages required
19
21
 
20
22
  ## Install
21
23
 
22
24
  ```bash
23
25
  npm install -g opencode-statboard
26
+ ```
27
+
28
+ ## Start
29
+
30
+ ```bash
24
31
  opencode-dashboard
25
32
  ```
26
33
 
27
34
  Then open http://127.0.0.1:4868
28
35
 
36
+ ## Update
37
+
38
+ ```bash
39
+ npm update -g opencode-statboard
40
+ ```
41
+
42
+ ## Options
43
+
44
+ - `OC_PORT` — change the listening port (default: 4868, auto-fallbacks to next available)
45
+
29
46
  ## License
30
47
 
31
48
  MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-statboard",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Real-time dashboard for opencode token usage and cost statistics",
5
5
  "main": "server.js",
6
6
  "bin": {
package/public/index.html CHANGED
@@ -298,7 +298,7 @@ function render(d, models, trend) {
298
298
  $('tool-bars').innerHTML = d.tools.map((tool) => barRow(tool.name, tool.count, d.tools[0].count, 'var(--tool)')).join('');
299
299
  }
300
300
 
301
- const modelList = (models && models.length ? models : (d.models || []));
301
+ const modelList = (models && models.length ? models : (d.models || [])).slice().sort((a, b) => b.cost - a.cost || b.messages - a.messages);
302
302
  if (modelList.length) {
303
303
  const total = modelList.reduce((s, m) => s + m.input, 0);
304
304
  $('model-rows').innerHTML = modelList.map((m) => {
package/server.js CHANGED
@@ -11,7 +11,7 @@ const pipelineAsync = promisify(pipeline);
11
11
  let Database;
12
12
  try { Database = require('better-sqlite3'); } catch (_) { Database = null; }
13
13
 
14
- const PORT = 4868;
14
+ const PORT = parseInt(process.env.OC_PORT || '4868', 10);
15
15
  const REFRESH_MS = 15000;
16
16
  const TREND_MS = 60 * 1000;
17
17
  const REPORT_TTL = 10 * 60 * 1000;
@@ -740,10 +740,32 @@ setInterval(() => {
740
740
  autoBackupIfDue();
741
741
  }, CACHE_CLEANUP_MS);
742
742
 
743
- (async () => {
744
- server.listen(PORT, '127.0.0.1', () => {
745
- console.log(`opencode stats dashboard: http://127.0.0.1:${PORT}`);
743
+ function tryListen(port, maxPort) {
744
+ return new Promise((resolve) => {
745
+ server.once('error', (e) => {
746
+ if (e.code === 'EADDRINUSE') {
747
+ console.log(`port ${port} in use, trying ${port + 1}...`);
748
+ server.removeAllListeners();
749
+ if (port < (maxPort || port + 5)) {
750
+ resolve(tryListen(port + 1, maxPort));
751
+ } else {
752
+ console.error(`all ports ${PORT}-${maxPort || PORT + 5} in use`);
753
+ process.exit(1);
754
+ }
755
+ } else {
756
+ console.error(e);
757
+ process.exit(1);
758
+ }
759
+ });
760
+ server.listen(port, '127.0.0.1', () => {
761
+ console.log(`opencode stats dashboard: http://127.0.0.1:${port}`);
762
+ resolve(port);
763
+ });
746
764
  });
765
+ }
766
+
767
+ (async () => {
768
+ const actualPort = await tryListen(PORT, PORT + 5);
747
769
  setInterval(refresh, REFRESH_MS);
748
770
  setInterval(refreshModels, 60000);
749
771
  await refresh();