idlebench 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 IdleBench
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # idlebench
2
+
3
+ **The verification CLI for idle compute.**
4
+
5
+ Run one command to benchmark your machine and publish a verified score to IdleBench — the trust layer for IDLE Protocol compute providers.
6
+
7
+ ## Install & run
8
+
9
+ ```bash
10
+ npx idlebench run
11
+ ```
12
+
13
+ No installation required. Node.js 18+ needed.
14
+
15
+ ## Commands
16
+
17
+ ```bash
18
+ npx idlebench run # Run full benchmark and upload report
19
+ npx idlebench doctor # Check local environment readiness
20
+ npx idlebench upload <path> # Upload a saved report JSON
21
+ npx idlebench version # Show version
22
+ ```
23
+
24
+ ## What it checks
25
+
26
+ | Check | Description |
27
+ |-------|-------------|
28
+ | GPU detection | Model, VRAM via nvidia-smi or systeminformation |
29
+ | CUDA | Availability and version |
30
+ | NVIDIA driver | Driver version |
31
+ | Docker | Installation and daemon status |
32
+ | Docker GPU runtime | Tests docker --gpus all |
33
+ | CPU benchmark | Hash workload + matrix calculation |
34
+ | Network latency | Round-trip to IdleBench API |
35
+
36
+ ## Security
37
+
38
+ IdleBench **never asks for private keys or seed phrases**. Only your public wallet address is used to identify your provider profile.
39
+
40
+ All checks run locally. Only the structured benchmark report is uploaded.
41
+
42
+ ## Environment variables
43
+
44
+ ```bash
45
+ IDLEBENCH_API_URL=https://idlebench.com # Override API URL
46
+ ```
47
+
48
+ ## Publish to npm
49
+
50
+ ```bash
51
+ cd idlebench-cli
52
+ npm install
53
+ npm run build
54
+ npm publish --access public
55
+ ```
56
+
57
+ ## Local development
58
+
59
+ ```bash
60
+ npm install
61
+ npm run build
62
+ npm link
63
+ idlebench doctor
64
+ idlebench run
65
+ ```
66
+
67
+ ## License
68
+
69
+ MIT
@@ -0,0 +1,4 @@
1
+ export declare function runDoctor(options: {
2
+ apiUrl?: string;
3
+ }): Promise<void>;
4
+ //# sourceMappingURL=doctor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/commands/doctor.ts"],"names":[],"mappings":"AAiBA,wBAAsB,SAAS,CAAC,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,iBAkG3D"}
@@ -0,0 +1,107 @@
1
+ import chalk from 'chalk';
2
+ import ora from 'ora';
3
+ import { getSystemInfo } from '../lib/system.js';
4
+ import { getGpuInfo } from '../lib/gpu.js';
5
+ import { getDockerInfo } from '../lib/docker.js';
6
+ import { measureLatency } from '../lib/network.js';
7
+ const CHECK = chalk.green('✓');
8
+ const WARN = chalk.yellow('!');
9
+ const FAIL = chalk.red('✗');
10
+ function row(label, value, ok) {
11
+ const icon = ok === true ? CHECK : ok === false ? FAIL : WARN;
12
+ const icon2 = ok === undefined ? '' : ` ${icon}`;
13
+ console.log(` ${chalk.dim(label.padEnd(24))} ${chalk.white(value)}${icon2}`);
14
+ }
15
+ export async function runDoctor(options) {
16
+ const apiUrl = options.apiUrl ?? 'https://idlebench.com';
17
+ console.log();
18
+ console.log(chalk.bold(' IdleBench Doctor'));
19
+ console.log(chalk.dim(` Checking your environment for benchmark readiness`));
20
+ console.log();
21
+ // Node version
22
+ const nodeVersion = process.version;
23
+ const nodeOk = parseInt(nodeVersion.slice(1)) >= 18;
24
+ row('Node.js', nodeVersion, nodeOk);
25
+ if (!nodeOk) {
26
+ console.log(chalk.yellow(' → Node.js 18+ is required'));
27
+ }
28
+ // System info
29
+ const spinner = ora({ text: 'Reading system info...', color: 'green' }).start();
30
+ let system;
31
+ try {
32
+ system = await getSystemInfo();
33
+ spinner.stop();
34
+ row('OS', system.os);
35
+ row('Architecture', system.arch);
36
+ row('CPU', `${system.cpuModel} (${system.cpuCores} cores)`);
37
+ row('RAM', `${system.ramGb} GB`);
38
+ }
39
+ catch (err) {
40
+ spinner.fail('Failed to read system info');
41
+ }
42
+ console.log();
43
+ // GPU detection
44
+ const gpuSpinner = ora({ text: 'Detecting GPU...', color: 'green' }).start();
45
+ try {
46
+ const gpu = await getGpuInfo();
47
+ gpuSpinner.stop();
48
+ if (gpu.name) {
49
+ row('GPU', gpu.name, true);
50
+ if (gpu.vramGb)
51
+ row('VRAM', `${gpu.vramGb} GB`);
52
+ row('CUDA', gpu.cudaAvailable ? `Available (${gpu.cudaVersion ?? 'unknown version'})` : 'Not detected', gpu.cudaAvailable);
53
+ if (gpu.driverVersion)
54
+ row('NVIDIA Driver', gpu.driverVersion, true);
55
+ if (gpu.detectionMethod)
56
+ console.log(chalk.dim(` (detected via ${gpu.detectionMethod})`));
57
+ }
58
+ else {
59
+ gpuSpinner.stop();
60
+ row('GPU', 'Not detected', null);
61
+ console.log(chalk.dim(' → No NVIDIA GPU found. CPU-only resources are still valid.'));
62
+ }
63
+ }
64
+ catch {
65
+ gpuSpinner.fail('GPU detection failed');
66
+ }
67
+ console.log();
68
+ // Docker
69
+ const dockerSpinner = ora({ text: 'Checking Docker...', color: 'green' }).start();
70
+ try {
71
+ const docker = await getDockerInfo();
72
+ dockerSpinner.stop();
73
+ row('Docker', docker.available ? `Installed (v${docker.version})` : 'Not found', docker.available);
74
+ if (docker.available) {
75
+ row('Docker GPU Runtime', docker.gpuRuntime ? 'Available' : 'Not available', docker.gpuRuntime);
76
+ if (!docker.gpuRuntime && docker.gpuRuntimeError) {
77
+ console.log(chalk.dim(` → ${docker.gpuRuntimeError}`));
78
+ }
79
+ }
80
+ }
81
+ catch {
82
+ dockerSpinner.fail('Docker check failed');
83
+ }
84
+ console.log();
85
+ // Network
86
+ const netSpinner = ora({ text: 'Testing network...', color: 'green' }).start();
87
+ try {
88
+ const latency = await measureLatency(apiUrl);
89
+ netSpinner.stop();
90
+ if (latency !== null) {
91
+ const latencyOk = latency < 500;
92
+ row('Network', `${latency}ms latency to IdleBench`, latencyOk);
93
+ }
94
+ else {
95
+ row('Network', 'Could not reach IdleBench API', false);
96
+ console.log(chalk.dim(` → Tried: ${apiUrl}/api/health/check`));
97
+ }
98
+ }
99
+ catch {
100
+ netSpinner.fail('Network check failed');
101
+ }
102
+ console.log();
103
+ console.log(chalk.dim(' ─────────────────────────────────────────'));
104
+ console.log();
105
+ console.log(chalk.bold(' Ready to benchmark?'), chalk.dim('Run'), chalk.white('npx idlebench run'), chalk.dim('to start.'));
106
+ console.log();
107
+ }
@@ -0,0 +1,2 @@
1
+ export declare function runBenchmarkCommand(): Promise<void>;
2
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/commands/run.ts"],"names":[],"mappings":"AAmIA,wBAAsB,mBAAmB,kBAgNxC"}
@@ -0,0 +1,302 @@
1
+ import chalk from 'chalk';
2
+ import ora from 'ora';
3
+ import inquirer from 'inquirer';
4
+ import { fetch } from 'undici';
5
+ import { getSystemInfo } from '../lib/system.js';
6
+ import { getGpuInfo } from '../lib/gpu.js';
7
+ import { getDockerInfo } from '../lib/docker.js';
8
+ import { getNetworkInfo } from '../lib/network.js';
9
+ import { runBenchmark } from '../lib/benchmark.js';
10
+ import { calculateGpuScore, calculateRuntimeScore, calculateNetworkScore, calculateInferenceScore, calculateStabilityScore, calculateFinalScore, getGrade, } from '../lib/scoring.js';
11
+ import { buildReport, saveReportLocally } from '../lib/report.js';
12
+ const CLI_VERSION = '1.0.0';
13
+ const DEFAULT_API_URL = 'https://idlebench.com';
14
+ function line() {
15
+ console.log(chalk.dim(' ─────────────────────────────────────────'));
16
+ }
17
+ function header() {
18
+ console.log();
19
+ console.log(chalk.bold.white(' IdleBench'));
20
+ console.log(chalk.dim(' The verification layer for idle compute.'));
21
+ console.log();
22
+ console.log(chalk.bgYellow.black(' SECURITY NOTICE ') + chalk.yellow(' IdleBench never asks for private keys or seed phrases.'));
23
+ console.log();
24
+ line();
25
+ console.log();
26
+ }
27
+ function checkRow(label, value, ok) {
28
+ const icon = ok === true ? chalk.green('✓') : ok === false ? chalk.red('✗') : chalk.yellow('—');
29
+ console.log(` ${icon} ${chalk.dim(label.padEnd(26))} ${chalk.white(value)}`);
30
+ }
31
+ function scoreBar(label, score, width = 20) {
32
+ const filled = Math.round((score / 100) * width);
33
+ const bar = '█'.repeat(filled) + '░'.repeat(width - filled);
34
+ const color = score >= 85 ? chalk.green : score >= 70 ? chalk.yellow : chalk.red;
35
+ console.log(` ${chalk.dim(label.padEnd(28))} ${color(bar)} ${chalk.bold(score)}`);
36
+ }
37
+ async function promptSetup() {
38
+ console.log(chalk.dim(' Answer a few questions to configure your benchmark.\n'));
39
+ const answers = await inquirer.prompt([
40
+ {
41
+ type: 'input',
42
+ name: 'providerWallet',
43
+ message: 'Solana wallet address (public key):',
44
+ validate: (input) => {
45
+ if (!input.trim())
46
+ return 'Wallet address is required';
47
+ if (input.trim().length < 32 || input.trim().length > 44) {
48
+ return 'Wallet address must be 32-44 characters';
49
+ }
50
+ return true;
51
+ },
52
+ },
53
+ {
54
+ type: 'input',
55
+ name: 'resourceName',
56
+ message: 'Resource name:',
57
+ default: 'My Compute Node',
58
+ validate: (input) => input.trim().length > 0 || 'Name is required',
59
+ },
60
+ {
61
+ type: 'list',
62
+ name: 'resourceType',
63
+ message: 'Resource type:',
64
+ choices: [
65
+ { name: 'GPU — Graphics card or GPU compute node', value: 'GPU' },
66
+ { name: 'CPU — CPU-only workstation or server', value: 'CPU' },
67
+ { name: 'API — API endpoint or inference service', value: 'API' },
68
+ { name: 'Agent — AI agent or automation endpoint', value: 'AGENT' },
69
+ { name: 'PC — General personal computer', value: 'PC' },
70
+ { name: 'Other', value: 'OTHER' },
71
+ ],
72
+ default: 'GPU',
73
+ },
74
+ {
75
+ type: 'input',
76
+ name: 'idleGatewayUrl',
77
+ message: 'IDLE gateway URL (optional, press Enter to skip):',
78
+ default: '',
79
+ validate: (input) => {
80
+ if (!input.trim())
81
+ return true;
82
+ try {
83
+ new URL(input.trim());
84
+ return true;
85
+ }
86
+ catch {
87
+ return 'Enter a valid URL or leave blank';
88
+ }
89
+ },
90
+ },
91
+ {
92
+ type: 'input',
93
+ name: 'apiUrl',
94
+ message: `IdleBench API URL:`,
95
+ default: DEFAULT_API_URL,
96
+ validate: (input) => {
97
+ try {
98
+ new URL(input.trim());
99
+ return true;
100
+ }
101
+ catch {
102
+ return 'Enter a valid URL';
103
+ }
104
+ },
105
+ },
106
+ ]);
107
+ return {
108
+ providerWallet: answers.providerWallet.trim(),
109
+ resourceName: answers.resourceName.trim(),
110
+ resourceType: answers.resourceType,
111
+ idleGatewayUrl: answers.idleGatewayUrl.trim() || null,
112
+ apiUrl: answers.apiUrl.trim(),
113
+ };
114
+ }
115
+ export async function runBenchmarkCommand() {
116
+ header();
117
+ const setup = await promptSetup();
118
+ const { providerWallet, resourceName, resourceType, idleGatewayUrl, apiUrl } = setup;
119
+ console.log();
120
+ line();
121
+ console.log();
122
+ console.log(chalk.bold(' Running checks...'));
123
+ console.log();
124
+ // System info
125
+ let system;
126
+ {
127
+ const spinner = ora({ text: 'Reading system info', color: 'green' }).start();
128
+ try {
129
+ system = await getSystemInfo();
130
+ spinner.succeed(chalk.dim('System info'));
131
+ checkRow('OS', system.os);
132
+ checkRow('CPU', `${system.cpuModel} (${system.cpuCores} cores)`);
133
+ checkRow('RAM', `${system.ramGb} GB`);
134
+ checkRow('Architecture', system.arch);
135
+ }
136
+ catch (err) {
137
+ spinner.fail('Failed to read system info');
138
+ throw err;
139
+ }
140
+ }
141
+ console.log();
142
+ // GPU
143
+ let gpu;
144
+ {
145
+ const spinner = ora({ text: 'Detecting GPU', color: 'green' }).start();
146
+ gpu = await getGpuInfo();
147
+ spinner.succeed(chalk.dim('GPU detection'));
148
+ if (gpu.name) {
149
+ checkRow('GPU Model', gpu.name, true);
150
+ if (gpu.vramGb)
151
+ checkRow('VRAM', `${gpu.vramGb} GB`);
152
+ checkRow('CUDA', gpu.cudaAvailable ? `${gpu.cudaVersion ?? 'Available'}` : 'Not available', gpu.cudaAvailable);
153
+ if (gpu.driverVersion)
154
+ checkRow('NVIDIA Driver', gpu.driverVersion, true);
155
+ }
156
+ else {
157
+ checkRow('GPU', 'Not detected', null);
158
+ console.log(chalk.dim(' No GPU detected — running CPU-only checks'));
159
+ }
160
+ }
161
+ console.log();
162
+ // Docker
163
+ let docker;
164
+ {
165
+ const spinner = ora({ text: 'Checking Docker', color: 'green' }).start();
166
+ docker = await getDockerInfo();
167
+ spinner.succeed(chalk.dim('Docker check'));
168
+ checkRow('Docker', docker.available ? `v${docker.version}` : 'Not installed', docker.available);
169
+ if (docker.available) {
170
+ if (docker.gpuRuntime) {
171
+ checkRow('Docker GPU Runtime', 'Available', true);
172
+ }
173
+ else {
174
+ checkRow('Docker GPU Runtime', docker.gpuRuntimeError ?? 'Not available', false);
175
+ }
176
+ }
177
+ }
178
+ console.log();
179
+ // Benchmark
180
+ let benchmarkResult;
181
+ {
182
+ const spinner = ora({ text: 'Running benchmark', color: 'green' }).start();
183
+ benchmarkResult = await runBenchmark();
184
+ spinner.succeed(chalk.dim('Benchmark complete'));
185
+ checkRow('CPU hash workload', `${benchmarkResult.cpuHashMs}ms`);
186
+ checkRow('Matrix calculation', `${benchmarkResult.matrixMs}ms`);
187
+ }
188
+ console.log();
189
+ // Network
190
+ let network;
191
+ {
192
+ const spinner = ora({ text: 'Testing network', color: 'green' }).start();
193
+ network = await getNetworkInfo(apiUrl);
194
+ spinner.succeed(chalk.dim('Network check'));
195
+ checkRow('Latency', network.latencyMs !== null ? `${network.latencyMs}ms` : 'Could not measure', network.latencyMs !== null);
196
+ if (network.downloadMbps !== null) {
197
+ checkRow('Download estimate', `${network.downloadMbps} Mbps`);
198
+ }
199
+ }
200
+ console.log();
201
+ line();
202
+ console.log();
203
+ // Calculate scores
204
+ const gpuScore = calculateGpuScore({
205
+ gpuName: gpu.name,
206
+ vramGb: gpu.vramGb,
207
+ cpuCores: system.cpuCores,
208
+ ramGb: system.ramGb,
209
+ cudaAvailable: gpu.cudaAvailable,
210
+ dockerAvailable: docker.available,
211
+ dockerGpuRuntime: docker.gpuRuntime,
212
+ });
213
+ const runtimeScore = calculateRuntimeScore({
214
+ gpuName: gpu.name,
215
+ vramGb: gpu.vramGb,
216
+ cpuCores: system.cpuCores,
217
+ ramGb: system.ramGb,
218
+ cudaAvailable: gpu.cudaAvailable,
219
+ dockerAvailable: docker.available,
220
+ dockerGpuRuntime: docker.gpuRuntime,
221
+ });
222
+ const networkScore = calculateNetworkScore(network.latencyMs);
223
+ const inferenceScore = calculateInferenceScore(system.cpuCores, system.ramGb, benchmarkResult.totalMs, gpu.name);
224
+ const stabilityScore = calculateStabilityScore(system.cpuCores, system.ramGb);
225
+ const finalScore = calculateFinalScore({
226
+ gpuScore,
227
+ runtimeScore,
228
+ networkScore,
229
+ inferenceScore,
230
+ stabilityScore,
231
+ });
232
+ const grade = getGrade(finalScore);
233
+ console.log(chalk.bold(' Score breakdown'));
234
+ console.log();
235
+ scoreBar('GPU Capability (30%)', gpuScore);
236
+ scoreBar('Runtime Readiness (20%)', runtimeScore);
237
+ scoreBar('Performance (20%)', inferenceScore);
238
+ scoreBar('Network (15%)', networkScore);
239
+ scoreBar('Stability (15%)', stabilityScore);
240
+ console.log();
241
+ const gradeColor = finalScore >= 85 ? chalk.green : finalScore >= 70 ? chalk.yellow : chalk.red;
242
+ console.log(` ${chalk.dim('Final Score')} ${gradeColor.bold(`${finalScore}/100`)} ${gradeColor(`[${grade}]`)}`);
243
+ console.log();
244
+ line();
245
+ console.log();
246
+ // Build report
247
+ const report = buildReport({
248
+ reportVersion: '1.0.0',
249
+ providerWallet,
250
+ resourceName,
251
+ resourceType,
252
+ idleGatewayUrl,
253
+ system,
254
+ gpu,
255
+ docker,
256
+ network,
257
+ scores: { gpuScore, runtimeScore, networkScore, inferenceScore, stabilityScore, finalScore, grade },
258
+ benchmarkMs: benchmarkResult.totalMs,
259
+ cliVersion: CLI_VERSION,
260
+ });
261
+ // Save locally
262
+ const localPath = saveReportLocally(report);
263
+ console.log(chalk.dim(` Report saved locally: ${localPath}`));
264
+ console.log();
265
+ // Upload
266
+ const uploadSpinner = ora({ text: `Uploading to ${apiUrl}`, color: 'green' }).start();
267
+ try {
268
+ const res = await fetch(`${apiUrl}/api/reports/upload`, {
269
+ method: 'POST',
270
+ headers: { 'Content-Type': 'application/json' },
271
+ body: JSON.stringify(report),
272
+ signal: AbortSignal.timeout(30000),
273
+ });
274
+ const json = await res.json();
275
+ if (!res.ok) {
276
+ uploadSpinner.fail('Upload failed');
277
+ console.error(chalk.red(` ✗ Server error: ${JSON.stringify(json)}`));
278
+ console.log(chalk.dim(` Your report was saved locally: ${localPath}`));
279
+ console.log(chalk.dim(` You can upload it later with: idlebench upload ${localPath}`));
280
+ return;
281
+ }
282
+ uploadSpinner.succeed('Report uploaded');
283
+ console.log();
284
+ console.log(chalk.bold(' Benchmark complete.'));
285
+ console.log();
286
+ console.log(chalk.dim(' Score: '), chalk.white.bold(`${finalScore}/100`));
287
+ console.log(chalk.dim(' Grade: '), gradeColor.bold(grade));
288
+ console.log(chalk.dim(' Public URL: '), chalk.cyan(String(json.publicUrl)));
289
+ console.log(chalk.dim(' Local report: '), chalk.dim(localPath));
290
+ console.log();
291
+ console.log(chalk.dim(' Attach the badge to your IDLE listing or GitHub README:'));
292
+ console.log(chalk.dim(` Badge URL: ${apiUrl}/api/badge/${json.resourceId}`));
293
+ console.log();
294
+ }
295
+ catch (err) {
296
+ uploadSpinner.fail('Upload failed — network error');
297
+ console.error(chalk.red(` ✗ ${err instanceof Error ? err.message : err}`));
298
+ console.log();
299
+ console.log(chalk.dim(` Your report was saved locally: ${localPath}`));
300
+ console.log(chalk.dim(` Upload later with: idlebench upload ${localPath}`));
301
+ }
302
+ }
@@ -0,0 +1,4 @@
1
+ export declare function runUpload(filePath: string, options: {
2
+ apiUrl?: string;
3
+ }): Promise<void>;
4
+ //# sourceMappingURL=upload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/commands/upload.ts"],"names":[],"mappings":"AAqCA,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,iBA2D7E"}
@@ -0,0 +1,88 @@
1
+ import { readFileSync } from 'fs';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+ import { fetch } from 'undici';
5
+ import { z } from 'zod';
6
+ const ReportSchema = z.object({
7
+ reportVersion: z.string(),
8
+ providerWallet: z.string(),
9
+ resourceName: z.string(),
10
+ resourceType: z.string(),
11
+ system: z.object({
12
+ os: z.string(),
13
+ arch: z.string(),
14
+ cpuModel: z.string(),
15
+ cpuCores: z.number(),
16
+ ramGb: z.number(),
17
+ }),
18
+ gpu: z.object({
19
+ cudaAvailable: z.boolean(),
20
+ }).passthrough(),
21
+ runtime: z.object({
22
+ dockerAvailable: z.boolean(),
23
+ dockerGpuRuntime: z.boolean(),
24
+ }).passthrough(),
25
+ network: z.object({}).passthrough(),
26
+ scores: z.object({
27
+ finalScore: z.number(),
28
+ grade: z.string(),
29
+ }).passthrough(),
30
+ metadata: z.object({
31
+ createdAt: z.string(),
32
+ cliVersion: z.string(),
33
+ }),
34
+ reportHash: z.string(),
35
+ });
36
+ export async function runUpload(filePath, options) {
37
+ const apiUrl = (options.apiUrl ?? 'https://idlebench.com').replace(/\/$/, '');
38
+ console.log();
39
+ console.log(chalk.bold(' IdleBench Upload'));
40
+ console.log(chalk.dim(` Uploading: ${filePath}`));
41
+ console.log();
42
+ let rawJson;
43
+ let reportData;
44
+ try {
45
+ rawJson = readFileSync(filePath, 'utf-8');
46
+ reportData = JSON.parse(rawJson);
47
+ }
48
+ catch (err) {
49
+ console.error(chalk.red(' ✗ Could not read report file:'), filePath);
50
+ if (err instanceof Error)
51
+ console.error(chalk.dim(` ${err.message}`));
52
+ process.exit(1);
53
+ }
54
+ const parsed = ReportSchema.safeParse(reportData);
55
+ if (!parsed.success) {
56
+ console.error(chalk.red(' ✗ Invalid report format:'));
57
+ console.error(chalk.dim(JSON.stringify(parsed.error.flatten(), null, 2)));
58
+ process.exit(1);
59
+ }
60
+ const spinner = ora({ text: 'Uploading to IdleBench...', color: 'green' }).start();
61
+ try {
62
+ const res = await fetch(`${apiUrl}/api/reports/upload`, {
63
+ method: 'POST',
64
+ headers: { 'Content-Type': 'application/json' },
65
+ body: rawJson,
66
+ signal: AbortSignal.timeout(30000),
67
+ });
68
+ const json = await res.json();
69
+ if (!res.ok) {
70
+ spinner.fail('Upload failed');
71
+ console.error(chalk.red(` ✗ ${JSON.stringify(json)}`));
72
+ process.exit(1);
73
+ }
74
+ spinner.succeed('Report uploaded');
75
+ console.log();
76
+ console.log(chalk.bold(' Upload complete'));
77
+ console.log();
78
+ console.log(chalk.dim(' Score: '), chalk.white(`${json.score}/100`));
79
+ console.log(chalk.dim(' Grade: '), chalk.white(String(json.grade)));
80
+ console.log(chalk.dim(' Public URL: '), chalk.cyan(String(json.publicUrl)));
81
+ console.log();
82
+ }
83
+ catch (err) {
84
+ spinner.fail('Upload failed');
85
+ console.error(chalk.red(' ✗ Network error:'), err instanceof Error ? err.message : err);
86
+ process.exit(1);
87
+ }
88
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}