opencode-statboard 2.10.15 → 2.10.17

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/fix-dup.py ADDED
@@ -0,0 +1,28 @@
1
+ c = open('tui-dashboard.js', encoding='utf-8').read()
2
+
3
+ # Find the two renderChart declarations
4
+ first = c.find(' const renderChart = (data, label, color, maxVal) => {')
5
+ second = c.find(' const renderChart = (data, label, color, maxVal) => {', first + 1)
6
+
7
+ # Show context around first
8
+ print("First renderChart at line:", c[:first].count('\n') + 1)
9
+ print("Second renderChart at line:", c[:second].count('\n') + 1)
10
+
11
+ # The first renderChart ends at the semicolon + blank line before "const maxInOut"
12
+ # Find the line after the first closing of renderChart function
13
+ # The pattern: " return lines.join('\\n');\n };" appears twice
14
+ marker = " return lines.join('\\n');\n };"
15
+ first_marker = c.find(marker, first)
16
+ second_marker = c.find(marker, first_marker + 1)
17
+
18
+ print("First marker at line:", c[:first_marker].count('\n') + 1)
19
+
20
+ # Remove everything from first renderChart to second renderChart (inclusive of first)
21
+ # We want to keep from first renderChart line to the line before second renderChart
22
+ old_block = c[first:first_marker + len(marker)]
23
+ print("Block to remove length:", len(old_block))
24
+ print("Block preview:", old_block[:200])
25
+
26
+ # Check what's between
27
+ between_preview = c[first_marker + len(marker):second][:200]
28
+ print("Between:", repr(between_preview))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-statboard",
3
- "version": "2.10.15",
3
+ "version": "2.10.17",
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
@@ -604,15 +604,34 @@ class TUIServer {
604
604
 
605
605
  const height = this.getContentHeight() - 4;
606
606
  const width = this.getContentWidth();
607
- const chartHeight = Math.max(1, Math.floor(height / 3) - 2);
607
+ const chartHeight = Math.max(1, Math.floor(height / 4) - 2);
608
+
609
+ let out = '{center}{bold}\u2501\u2501\u2501 ' + t('trend') + ' \u2501\u2501\u2501{/bold}{/center}\n\n';
610
+
611
+ const maxInOut = Math.max(...labels.map((_, i) => Math.max(input[i] || 0, output[i] || 0)), 1);
612
+ let inOutChart = [];
613
+ inOutChart.push('{bold}' + t('input') + ' (' + this.formatNumber(input[input.length - 1] || 0) + ') + ' + t('output') + ' (' + this.formatNumber(output[output.length - 1] || 0) + ') today, max: ' + this.formatNumber(maxInOut) + '{/bold}');
614
+ for (let row = chartHeight - 1; row >= 0; row--) {
615
+ let line = '';
616
+ const threshold = (row / chartHeight) * maxInOut;
617
+ for (let i = 0; i < width; i++) {
618
+ const idx = Math.floor(i * labels.length / width);
619
+ const inVal = input[idx] || 0;
620
+ const outVal = output[idx] || 0;
621
+ if (inVal >= threshold && outVal >= threshold) line += '{magenta-fg}\u2588{/}';
622
+ else if (inVal >= threshold) line += '{cyan-fg}\u2588{/}';
623
+ else if (outVal >= threshold) line += '{green-fg}\u2588{/}';
624
+ else line += ' ';
625
+ }
626
+ inOutChart.push(line);
627
+ }
628
+ out += inOutChart.join('\n') + '\n';
608
629
 
609
- // Helper: render one chart with its own max
610
630
  const renderChart = (data, label, color, maxVal) => {
611
631
  if (maxVal <= 0) return '{gray}(no data){/gray}\n';
612
632
  let lines = [];
613
- // Show current (today = last index) value next to label
614
633
  const todayVal = data[data.length - 1] || 0;
615
- lines.push('{bold}' + label + ': ' + this.formatNumber(todayVal) + ' (today){/bold}');
634
+ lines.push('{bold}' + label + ': ' + this.formatNumber(todayVal) + ' (today, max: ' + this.formatNumber(maxVal) + '){/bold}');
616
635
  for (let row = chartHeight - 1; row >= 0; row--) {
617
636
  let line = '';
618
637
  const threshold = (row / chartHeight) * maxVal;
@@ -627,17 +646,13 @@ class TUIServer {
627
646
  return lines.join('\n');
628
647
  };
629
648
 
630
- const maxIn = Math.max(...input, 1);
631
- const maxOut = Math.max(...output, 1);
649
+ const maxReasoning = Math.max(...reasoning, 1);
650
+ const maxCache = Math.max(...cache, 1);
632
651
  const maxCost = Math.max(...cost, 1);
652
+ out += renderChart(reasoning, t('reasoning') + ' (tool)', 'tool', maxReasoning) + '\n';
653
+ out += renderChart(cache, t('cacheRead') + ' (yellow)', 'yellow', maxCache) + '\n';
654
+ out += renderChart(cost, t('cost') + ' (red)', 'red', maxCost) + '\n';
633
655
 
634
- let out = '{center}{bold}\u2501\u2501\u2501 ' + t('trend') + ' \u2501\u2501\u2501{/bold}{/center}\n\n';
635
-
636
- out += renderChart(input, t('input') + ' (cyan)', 'cyan', maxIn) + '\n';
637
- out += renderChart(output, t('output') + ' (green)', 'green', maxOut) + '\n';
638
- out += renderChart(cost, t('cost') + ' (yellow)', 'yellow', maxCost) + '\n';
639
-
640
- // X-axis: show first date, middle date, last date
641
656
  let xAxis = '';
642
657
  const labelStep = Math.max(1, Math.ceil(width / 20));
643
658
  for (let i = 0; i < width; i++) {
@@ -650,17 +665,14 @@ class TUIServer {
650
665
  }
651
666
  out += '{gray}' + xAxis + '{/gray}\n';
652
667
 
653
- // Add date range info
654
668
  const firstDate = trend.dates ? trend.dates[0] : labels[0];
655
669
  const lastDate = trend.dates ? trend.dates[trend.dates.length - 1] : labels[labels.length - 1];
670
+ const totalToday = (input[input.length-1]||0) + (output[output.length-1]||0) + (reasoning[reasoning.length-1]||0) + (cache[cache.length-1]||0);
656
671
  out += '\n{gray}Range: ' + firstDate + ' \u2192 ' + lastDate + ' (' + labels.length + ' days){/gray}\n';
657
-
658
- const lastIdx = labels.length - 1;
659
- out += '\n{bold}' + t('today') + ':{/bold} Input: ' + this.formatNumber(input[lastIdx] || 0) + ' | Output: ' + this.formatNumber(output[lastIdx] || 0) + ' | Cost: ' + this.formatCost(cost[lastIdx] || 0);
672
+ out += '{bold}' + t('today') + ':{/bold} Input: ' + this.formatNumber(input[input.length - 1] || 0) + ' | Output: ' + this.formatNumber(output[output.length - 1] || 0) + ' | Reasoning: ' + this.formatNumber(reasoning[reasoning.length - 1] || 0) + ' | Cache: ' + this.formatNumber(cache[cache.length - 1] || 0) + ' | Total: ' + this.formatNumber(totalToday) + ' | Cost: ' + this.formatCost(cost[cost.length - 1] || 0);
660
673
 
661
674
  return out;
662
675
  }
663
-
664
676
  renderHeatmap() {
665
677
  const trend = this.data.trend;
666
678
  const t = this.t.bind(this);
package/fix-i18n.js DELETED
@@ -1,161 +0,0 @@
1
- const fs = require('fs');
2
- const c = fs.readFileSync('tui-dashboard.js', 'utf8');
3
-
4
- const zhOld = ` zh: {
5
- title: 'opencode-statboard v{version} TUI',
6
- keys: '[1]總覽 [2]專案 [3]模型 [4]趨勢 [5]熱力 [W]網頁 [R]重整 [Q]離開 [L]語言',
7
- footer: '上次更新: {time} | 視圖: {view} | W:網頁 R:重整 Q:離開',
8
- loading: '載入資料中...',
9
- error: '錯誤: {error}',
10
- overview: '總覽',
11
- projects: '專案',
12
- models: '模型',
13
- trend: '趨勢 (90 天)',
14
- heatmap: '熱力圖',
15
- noData: '無資料',
16
- sessions: '會話',
17
- main: '主',
18
- total: '總計',
19
- projectsLabel: '專案數',
20
- days: '天數',
21
- messages: '訊息',
22
- tokens: 'Token',
23
- input: '輸入',
24
- output: '輸出',
25
- reasoning: '推理',
26
- cacheRead: '快取讀取',
27
- cacheWrite: '快取寫入',
28
- total: '總計',
29
- cost: '成本',
30
- marketValue: '市場價值',
31
- saved: '節省',
32
- avgCostDay: '日均成本',
33
- avgTokensDay: '日均Token',
34
- projectHeader: '{專案:<45} {會話:>10} {Token:>18} {成本:>14}',
35
- modelHeader: '{模型:<40} {供應商:<14} {Token:>18} {成本:>12} {速度:>10}',
36
- unknown: '未知',
37
- today: '今天',
38
- version: '版本',
39
- sun: '日', mon: '一', tue: '二', wed: '三', thu: '四', fri: '五', sat: '六'
40
- }`;
41
-
42
- const zhNew = ` zh: {
43
- title: 'opencode-statboard v{version} TUI',
44
- keys: '[1]總覽 [2]專案 [3]模型 [4]趨勢 [5]熱力 [W]網頁 [R]重整 [Q]離開 [L]語言',
45
- footer: '上次更新: {time} | 視圖: {view} | W:網頁 R:重整 Q:離開',
46
- loading: '載入資料中...',
47
- error: '錯誤: {error}',
48
- overview: '總覽',
49
- projects: '專案',
50
- models: '模型',
51
- trend: '趨勢 (90 天)',
52
- heatmap: '熱力圖',
53
- noData: '無資料',
54
- sessions: '會話',
55
- main: '主',
56
- total: '總計',
57
- projectsLabel: '專案數',
58
- days: '天數',
59
- messages: '訊息',
60
- tokens: 'Token',
61
- input: '輸入',
62
- output: '輸出',
63
- reasoning: '推理',
64
- cacheRead: '快取讀取',
65
- cacheWrite: '快取寫入',
66
- total: '總計',
67
- cost: '成本',
68
- marketValue: '市場價值',
69
- saved: '節省',
70
- avgCostDay: '日均成本',
71
- avgTokensDay: '日均Token',
72
- projectHeader: '{專案:<45} {會話:>10} {Token:>18} {成本:>14}',
73
- modelHeader: '{模型:<40} {供應商:<14} {Token:>18} {成本:>12} {速度:>10}',
74
- unknown: '未知',
75
- today: '今天',
76
- version: '版本',
77
- sun: '日', mon: '一', tue: '二', wed: '三', thu: '四', fri: '五', sat: '六',
78
- day: '日', week: '周', month: '月', quarter: '季', all: '全',
79
- range: '範圍'
80
- }`;
81
-
82
- const enOld = ` en: {
83
- title: 'opencode-statboard v{version} TUI',
84
- keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit',
85
- footer: 'Last update: {time} | View: {view} | W:Web R:Refresh Q:Quit',
86
- loading: 'Loading data...',
87
- error: 'Error: {error}',
88
- overview: 'OVERVIEW',
89
- projects: 'PROJECTS',
90
- models: 'MODELS',
91
- trend: 'TREND (90 days)',
92
- heatmap: 'HEATMAP',
93
- noData: 'No data',
94
- sessions: 'Sessions',
95
- main: 'main',
96
- total: 'total',
97
- projectsLabel: 'Projects',
98
- days: 'Days',
99
- messages: 'Messages',
100
- tokens: 'Tokens',
101
- input: 'Input',
102
- output: 'Output',
103
- reasoning: 'Reasoning',
104
- cacheRead: 'Cache Read',
105
- cacheWrite: 'Cache Write',
106
- total: 'Total',
107
- cost: 'Cost',
108
- marketValue: 'Market Value',
109
- saved: 'Saved',
110
- avgCostDay: 'Avg Cost/Day',
111
- avgTokensDay: 'Avg Tokens/Day',
112
- projectHeader: '{Project:<45} {Sessions:>10} {Tokens:>18} {Cost:>14}',
113
- modelHeader: '{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}',
114
- unknown: 'unknown',
115
- today: 'Today',
116
- version: 'Version'
117
- }`;
118
-
119
- const enNew = ` en: {
120
- title: 'opencode-statboard v{version} TUI',
121
- keys: '[1]Overview [2]Projects [3]Models [4]Trend [5]Heatmap [W]Web [R]Refresh [Q]Quit [L]Lang',
122
- footer: 'Last update: {time} | View: {view} | W:Web R:Refresh Q:Quit',
123
- loading: 'Loading data...',
124
- error: 'Error: {error}',
125
- overview: 'OVERVIEW',
126
- projects: 'PROJECTS',
127
- models: 'MODELS',
128
- trend: 'TREND (90 days)',
129
- heatmap: 'HEATMAP',
130
- noData: 'No data',
131
- sessions: 'Sessions',
132
- main: 'main',
133
- total: 'total',
134
- projectsLabel: 'Projects',
135
- days: 'Days',
136
- messages: 'Messages',
137
- tokens: 'Tokens',
138
- input: 'Input',
139
- output: 'Output',
140
- reasoning: 'Reasoning',
141
- cacheRead: 'Cache Read',
142
- cacheWrite: 'Cache Write',
143
- total: 'Total',
144
- cost: 'Cost',
145
- marketValue: 'Market Value',
146
- saved: 'Saved',
147
- avgCostDay: 'Avg Cost/Day',
148
- avgTokensDay: 'Avg Tokens/Day',
149
- projectHeader: '{Project:<45} {Sessions:>10} {Tokens:>18} {Cost:>14}',
150
- modelHeader: '{Model:<40} {Provider:<14} {Tokens:>18} {Cost:>12} {Speed:>10}',
151
- unknown: 'unknown',
152
- today: 'Today',
153
- version: 'Version',
154
- day: 'Day', week: 'Week', month: 'Month', quarter: 'Quarter', all: 'All',
155
- range: 'Range'
156
- }`;
157
-
158
- let newContent = c.replace(zhOld, zhNew).replace(enOld, enNew);
159
-
160
- fs.writeFileSync('tui-dashboard.js', newContent);
161
- console.log('Done');
package/fix-port-final.js DELETED
@@ -1,86 +0,0 @@
1
- const fs = require('fs');
2
- const c = fs.readFileSync('server.js', 'utf8');
3
-
4
- // Find the tryListen function start
5
- const tryListenStart = c.indexOf('function tryListen(port, maxPort) {');
6
- if (tryListenStart === -1) {
7
- console.log('Could not find tryListen function');
8
- process.exit(1);
9
- }
10
-
11
- // Find the end of tryListen function
12
- let braceCount = 0;
13
- let tryListenEnd = -1;
14
- for (let i = tryListenStart; i < c.length; i++) {
15
- if (c[i] === '{') braceCount++;
16
- else if (c[i] === '}') {
17
- braceCount--;
18
- if (braceCount === 0) {
19
- tryListenEnd = i + 1; // Include the closing brace
20
- break;
21
- }
22
- }
23
-
24
- if (tryListenEnd === -1) {
25
- console.log('Could not find end of tryListen function');
26
- process.exit(1);
27
- }
28
-
29
- // Find the IIFE start
30
- const iifeStart = c.indexOf('(async () => {');
31
- if (iifeStart === -1) {
32
- console.log('Could not find IIFE start');
33
- process.exit(1);
34
- }
35
-
36
- // Find the end of the IIFE (the closing })();)
37
- let braceCount = 0;
38
- let iifeEnd = -1;
39
- for (let i = c.indexOf('(async () => {'); i < c.length; i++) {
40
- if (c[i] === '{') braceCount++;
41
- else if (c[i] === '}') {
42
- braceCount--;
43
- if (braceCount === 0) {
44
- // Check if next chars are })();
45
- const nextChars = c.substring(i, i + 10);
46
- if (nextChars.startsWith('})();')) {
47
- tryListenEnd = i + 5; // Include })();
48
- break;
49
- }
50
- }
51
- }
52
-
53
- if (tryListenEnd === -1) {
54
- console.log('Could not find end of IIFE');
55
- process.exit(1);
56
- }
57
-
58
- // Find the IIFE start (the async () => { part)
59
- const iifeStart = c.indexOf('(async () => {');
60
- if (iifeStart === -1) {
61
- console.log('Could not find IIFE start');
62
- process.exit(1);
63
- }
64
-
65
- // Build new content
66
- const beforeTryListen = c.substring(0, tryListenStart);
67
- const afterIifeStart = c.substring(iifeStart);
68
-
69
- const newContent = beforeTryListen + `
70
- async function startServer() {
71
- return new Promise((resolve, reject) => {
72
- server.listen(PORT, '127.0.0.1', () => {
73
- console.log('opencode stats dashboard: http://127.0.0.1:' + PORT);
74
- resolve(PORT);
75
- });
76
- server.once('error', (e) => {
77
- console.error('Server error:', e.message);
78
- process.exit(1);
79
- });
80
- });
81
- }
82
-
83
- ` + c.substring(iifeStart);
84
-
85
- fs.writeFileSync('server.js', newContent);
86
- console.log('Fixed server.js - replaced tryListen with fixed port listener');
@@ -1,79 +0,0 @@
1
- const fs = require('fs');
2
- const c = fs.readFileSync('server.js', 'utf8');
3
-
4
- // Find the tryListen function start
5
- const tryListenStart = c.indexOf('function tryListen(port, maxPort) {');
6
- if (tryListenStart === -1) {
7
- console.log('Could not find tryListen function');
8
- process.exit(1);
9
- }
10
-
11
- // Find the end of tryListen function
12
- let braceCount = 0;
13
- let tryListenEnd = -1;
14
- for (let i = tryListenStart; i < c.length; i++) {
15
- if (c[i] === '{') braceCount++;
16
- else if (c[i] === '}') {
17
- braceCount--;
18
- if (braceCount === 0) {
19
- tryListenEnd = i + 1; // Include the closing brace
20
- break;
21
- }
22
- }
23
-
24
- if (tryListenEnd === -1) {
25
- console.log('Could not find end of tryListen function');
26
- process.exit(1);
27
- }
28
-
29
- // Find the IIFE start
30
- const iifeStart = c.indexOf('(async () => {');
31
- if (iifeStart === -1) {
32
- console.log('Could not find IIFE start');
33
- process.exit(1);
34
- }
35
-
36
- // Find the end of the IIFE (the closing })();)
37
- let braceCount = 0;
38
- let iifeEnd = -1;
39
- for (let i = c.indexOf('(async () => {'); i < c.length; i++) {
40
- if (c[i] === '{') braceCount++;
41
- else if (c[i] === '}') {
42
- braceCount--;
43
- if (braceCount === 0) {
44
- // Check if next chars are })();
45
- const nextChars = c.substring(i, i + 10);
46
- if (nextChars.startsWith('})();')) {
47
- iifeEnd = i + 5; // Include })();
48
- break;
49
- }
50
- }
51
- }
52
-
53
- if (iifeEnd === -1) {
54
- console.log('Could not find end of IIFE');
55
- process.exit(1);
56
- }
57
-
58
- // Build new content
59
- const beforeTryListen = c.substring(0, tryListenStart);
60
- const afterIifeEnd = c.substring(iifeEnd);
61
-
62
- const newContent = c.substring(0, tryListenStart) + `
63
- async function startServer() {
64
- return new Promise((resolve, reject) => {
65
- server.listen(PORT, '127.0.0.1', () => {
66
- console.log('opencode stats dashboard: http://127.0.0.1:' + PORT);
67
- resolve(PORT);
68
- });
69
- server.once('error', (e) => {
70
- console.error('Server error:', e.message);
71
- process.exit(1);
72
- });
73
- });
74
- }
75
-
76
- ` + c.substring(iifeStart);
77
-
78
- fs.writeFileSync('server.js', newContent);
79
- console.log('Fixed server.js - replaced tryListen with fixed port listener');
@@ -1,79 +0,0 @@
1
- const fs = require('fs');
2
- const c = fs.readFileSync('server.js', 'utf8');
3
-
4
- // Find the tryListen function start
5
- const tryListenStart = c.indexOf('function tryListen(port, maxPort) {');
6
- if (tryListenStart === -1) {
7
- console.log('Could not find tryListen function');
8
- process.exit(1);
9
- }
10
-
11
- // Find the end of tryListen function
12
- let braceCount = 0;
13
- let tryListenEnd = -1;
14
- for (let i = tryListenStart; i < c.length; i++) {
15
- if (c[i] === '{') braceCount++;
16
- else if (c[i] === '}') {
17
- braceCount--;
18
- if (braceCount === 0) {
19
- tryListenEnd = i + 1; // Include the closing brace
20
- break;
21
- }
22
- }
23
-
24
- if (tryListenEnd === -1) {
25
- console.log('Could not find end of tryListen function');
26
- process.exit(1);
27
- }
28
-
29
- // Find the IIFE start
30
- const iifeStart = c.indexOf('(async () => {');
31
- if (iifeStart === -1) {
32
- console.log('Could not find IIFE start');
33
- process.exit(1);
34
- }
35
-
36
- // Find the end of the IIFE (the closing })();)
37
- let braceCount = 0;
38
- let iifeEnd = -1;
39
- for (let i = c.indexOf('(async () => {'); i < c.length; i++) {
40
- if (c[i] === '{') braceCount++;
41
- else if (c[i] === '}') {
42
- braceCount--;
43
- if (braceCount === 0) {
44
- // Check if next chars are })();
45
- const nextChars = c.substring(i, i + 10);
46
- if (nextChars.startsWith('})();')) {
47
- iifeEnd = i + 5; // Include })();
48
- break;
49
- }
50
- }
51
- }
52
-
53
- if (iifeEnd === -1) {
54
- console.log('Could not find end of IIFE');
55
- process.exit(1);
56
- }
57
-
58
- // Build new content
59
- const beforeTryListen = c.substring(0, tryListenStart);
60
- const afterIifeEnd = c.substring(iifeEnd);
61
-
62
- const newContent = c.substring(0, tryListenStart) + `
63
- async function startServer() {
64
- return new Promise((resolve, reject) => {
65
- server.listen(PORT, '127.0.0.1', () => {
66
- console.log('opencode stats dashboard: http://127.0.0.1:' + PORT);
67
- resolve(PORT);
68
- });
69
- server.once('error', (e) => {
70
- console.error('Server error:', e.message);
71
- process.exit(1);
72
- });
73
- });
74
- }
75
-
76
- ` + c.substring(iifeStart);
77
-
78
- fs.writeFileSync('server.js', newContent);
79
- console.log('Fixed server.js - replaced tryListen with fixed port listener');
@@ -1,79 +0,0 @@
1
- const fs = require('fs');
2
- const c = fs.readFileSync('server.js', 'utf8');
3
-
4
- // Find the tryListen function start
5
- const tryListenStart = c.indexOf('function tryListen(port, maxPort) {');
6
- if (tryListenStart === -1) {
7
- console.log('Could not find tryListen function');
8
- process.exit(1);
9
- }
10
-
11
- // Find the end of tryListen function
12
- let braceCount = 0;
13
- let tryListenEnd = -1;
14
- for (let i = tryListenStart; i < c.length; i++) {
15
- if (c[i] === '{') braceCount++;
16
- else if (c[i] === '}') {
17
- braceCount--;
18
- if (braceCount === 0) {
19
- tryListenEnd = i + 1; // Include the closing brace
20
- break;
21
- }
22
- }
23
-
24
- if (tryListenEnd === -1) {
25
- console.log('Could not find end of tryListen function');
26
- process.exit(1);
27
- }
28
-
29
- // Find the IIFE start
30
- const iifeStart = c.indexOf('(async () => {');
31
- if (iifeStart === -1) {
32
- console.log('Could not find IIFE start');
33
- process.exit(1);
34
- }
35
-
36
- // Find the end of the IIFE (the closing })();)
37
- let braceCount = 0;
38
- let iifeEnd = -1;
39
- for (let i = c.indexOf('(async () => {'); i < c.length; i++) {
40
- if (c[i] === '{') braceCount++;
41
- else if (c[i] === '}') {
42
- braceCount--;
43
- if (braceCount === 0) {
44
- // Check if next chars are })();
45
- const nextChars = c.substring(i, i + 10);
46
- if (nextChars.startsWith('})();')) {
47
- iifeEnd = i + 5; // Include })();
48
- break;
49
- }
50
- }
51
- }
52
-
53
- if (iifeEnd === -1) {
54
- console.log('Could not find end of IIFE');
55
- process.exit(1);
56
- }
57
-
58
- // Build new content
59
- const beforeTryListen = c.substring(0, tryListenStart);
60
- const afterIifeEnd = c.substring(iifeEnd);
61
-
62
- const newContent = c.substring(0, tryListenStart) + `
63
- async function startServer() {
64
- return new Promise((resolve, reject) => {
65
- server.listen(PORT, '127.0.0.1', () => {
66
- console.log('opencode stats dashboard: http://127.0.0.1:' + PORT);
67
- resolve(PORT);
68
- });
69
- server.once('error', (e) => {
70
- console.error('Server error:', e.message);
71
- process.exit(1);
72
- });
73
- });
74
- }
75
-
76
- ` + c.substring(iifeStart);
77
-
78
- fs.writeFileSync('server.js', newContent);
79
- console.log('Fixed server.js - replaced tryListen with fixed port listener');
@@ -1,79 +0,0 @@
1
- const fs = require('fs');
2
- const c = fs.readFileSync('server.js', 'utf8');
3
-
4
- // Find the tryListen function start
5
- const tryListenStart = c.indexOf('function tryListen(port, maxPort) {');
6
- if (tryListenStart === -1) {
7
- console.log('Could not find tryListen function');
8
- process.exit(1);
9
- }
10
-
11
- // Find the end of tryListen function
12
- let braceCount = 0;
13
- let tryListenEnd = -1;
14
- for (let i = tryListenStart; i < c.length; i++) {
15
- if (c[i] === '{') braceCount++;
16
- else if (c[i] === '}') {
17
- braceCount--;
18
- if (braceCount === 0) {
19
- tryListenEnd = i + 1; // Include the closing brace
20
- break;
21
- }
22
- }
23
-
24
- if (tryListenEnd === -1) {
25
- console.log('Could not find end of tryListen function');
26
- process.exit(1);
27
- }
28
-
29
- // Find the IIFE start
30
- const iifeStart = c.indexOf('(async () => {');
31
- if (iifeStart === -1) {
32
- console.log('Could not find IIFE start');
33
- process.exit(1);
34
- }
35
-
36
- // Find the end of the IIFE (the closing })();)
37
- let braceCount = 0;
38
- let iifeEnd = -1;
39
- for (let i = c.indexOf('(async () => {'); i < c.length; i++) {
40
- if (c[i] === '{') braceCount++;
41
- else if (c[i] === '}') {
42
- braceCount--;
43
- if (braceCount === 0) {
44
- // Check if next chars are })();
45
- const nextChars = c.substring(i, i + 10);
46
- if (nextChars.startsWith('})();')) {
47
- iifeEnd = i + 5; // Include })();
48
- break;
49
- }
50
- }
51
- }
52
-
53
- if (iifeEnd === -1) {
54
- console.log('Could not find end of IIFE');
55
- process.exit(1);
56
- }
57
-
58
- // Build new content
59
- const beforeTryListen = c.substring(0, tryListenStart);
60
- const afterIifeEnd = c.substring(iifeEnd);
61
-
62
- const newContent = c.substring(0, tryListenStart) + `
63
- async function startServer() {
64
- return new Promise((resolve, reject) => {
65
- server.listen(PORT, '127.0.0.1', () => {
66
- console.log('opencode stats dashboard: http://127.0.0.1:' + PORT);
67
- resolve(PORT);
68
- });
69
- server.once('error', (e) => {
70
- console.error('Server error:', e.message);
71
- process.exit(1);
72
- });
73
- });
74
- }
75
-
76
- ` + c.substring(iifeStart);
77
-
78
- fs.writeFileSync('server.js', newContent);
79
- console.log('Fixed server.js - replaced tryListen with fixed port listener');