Skip to content

Commit eb80e89

Browse files
committed
create cli
1 parent 50cea91 commit eb80e89

16 files changed

+635
-531
lines changed

dashboard/server.ts

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import http from "http";
2-
import fs from "fs";
3-
import path from "path";
1+
import fs from 'fs';
2+
import http from 'http';
3+
import path from 'path';
44

55
const PORT = 3001;
66

@@ -9,82 +9,70 @@ interface MimeTypes {
99
}
1010

1111
const MIME_TYPES: MimeTypes = {
12-
".html": "text/html",
13-
".js": "text/javascript",
14-
".css": "text/css",
15-
".json": "application/json",
16-
".png": "image/png",
17-
".jpg": "image/jpg",
18-
".gif": "image/gif",
19-
".svg": "image/svg+xml",
20-
".ico": "image/x-icon",
12+
'.html': 'text/html',
13+
'.js': 'text/javascript',
14+
'.css': 'text/css',
15+
'.json': 'application/json',
16+
'.png': 'image/png',
17+
'.jpg': 'image/jpg',
18+
'.gif': 'image/gif',
19+
'.svg': 'image/svg+xml',
20+
'.ico': 'image/x-icon',
2121
};
2222

2323
const server = http.createServer((req, res) => {
24-
console.log(`${req.method} ${req.url}`);
25-
2624
if (!req.url) {
2725
res.writeHead(400);
28-
res.end("Bad request: URL missing");
26+
res.end('Bad request: URL missing');
2927
return;
3028
}
3129

32-
// Handle the root path
3330
let filePath: string;
34-
if (req.url === "/") {
35-
filePath = path.join(__dirname, "../public/dashboard.html");
36-
} else if (req.url === "/index.js") {
37-
// Serve the main JS file from public folder
38-
filePath = path.join(__dirname, "../public/index.js");
39-
} else if (req.url === "/index.css") {
40-
// Serve the main CSS file from public folder
41-
filePath = path.join(__dirname, "../public/index.css");
42-
} else if (req.url.startsWith("/metrics/")) {
43-
// Serve metrics files from the metrics directory
31+
if (req.url === '/') {
32+
filePath = path.join(__dirname, '../public/dashboard.html');
33+
} else if (req.url === '/index.js') {
34+
filePath = path.join(__dirname, '../public/index.js');
35+
} else if (req.url === '/index.css') {
36+
filePath = path.join(__dirname, '../public/index.css');
37+
} else if (req.url.startsWith('/metrics/')) {
4438
const metricsPath =
45-
req.url === "/metrics/summary.json"
46-
? path.join(__dirname, "../metrics", req.url.replace("/metrics/", ""))
39+
req.url === '/metrics/summary.json'
40+
? path.join(__dirname, '../metrics', req.url.replace('/metrics/', ''))
4741
: path.join(
4842
__dirname,
49-
"../metrics/tasks",
50-
req.url.replace("/metrics/", ""),
43+
'../metrics/tasks',
44+
req.url.replace('/metrics/', ''),
5145
);
5246
filePath = metricsPath;
53-
} else if (req.url.startsWith("/docs/")) {
54-
// Serve docs assets
55-
filePath = path.join(__dirname, "../public", req.url);
47+
} else if (req.url.startsWith('/docs/')) {
48+
filePath = path.join(__dirname, '../public', req.url);
5649
} else {
57-
// Serve other static files from the public directory
58-
filePath = path.join(__dirname, "../public", req.url);
50+
filePath = path.join(__dirname, '../public', req.url);
5951
}
6052

6153
// Get the file extension
6254
const extname = path.extname(filePath);
63-
const contentType = MIME_TYPES[extname] || "application/octet-stream";
55+
const contentType = MIME_TYPES[extname] || 'application/octet-stream';
6456

6557
// Read the file
6658
fs.readFile(filePath, (err, content) => {
6759
if (err) {
68-
if (err.code === "ENOENT") {
69-
// Page not found
70-
console.error(`File not found: ${filePath}`);
60+
if (err.code === 'ENOENT') {
7161
res.writeHead(404);
72-
res.end("404 Not Found");
62+
res.end('404 Not Found');
7363
} else {
74-
// Server error
75-
console.error(`Server error: ${err.code}`);
7664
res.writeHead(500);
7765
res.end(`Server Error: ${err.code}`);
7866
}
7967
} else {
8068
// Success
81-
res.writeHead(200, { "Content-Type": contentType });
82-
res.end(content, "utf-8");
69+
res.writeHead(200, { 'Content-Type': contentType });
70+
res.end(content, 'utf-8');
8371
}
8472
});
8573
});
8674

8775
server.listen(PORT, () => {
8876
console.log(`Server running at http://localhost:${PORT}/`);
89-
console.log("Press Ctrl+C to stop the server");
77+
console.log('Press Ctrl+C to stop the server');
9078
});

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
"type": "module",
88
"main": "dist/server/dashboard-server.js",
99
"bin": {
10-
"mcp-te-benchmark": "./dist/cli/extract-chat-metrics.js"
10+
"mcp-te-benchmark": "./dist/cli.js"
1111
},
1212
"files": [
13-
"src/",
14-
"dist/",
15-
"scripts/regenerate-summary.sh"
13+
"public/",
14+
"server/",
15+
"dist/"
1616
],
1717
"scripts": {
18-
"build": "tsc",
18+
"build": "tsc -p tsconfig.build.json && chmod +x dist/cli.js",
19+
"cli:extract-metrics": "node --import tsx/esm src/cli.ts extract-metrics",
20+
"cli:generate-summary": "node --import tsx/esm src/cli.ts generate-summary",
1921
"dashboard": "node --watch --import tsx/esm dashboard/server.ts",
20-
"extract-metrics": "node --import tsx/esm src/extract-chat-metrics.ts",
21-
"generate-summary": "node --import tsx/esm src/generate-summary.ts",
22-
"prepare": "husky",
2322
"lint": "eslint src/**/*.ts dashboard/**/*.ts",
24-
"lint:fix": "eslint src/**/*.ts dashboard/**/*.ts --fix"
23+
"lint:fix": "eslint src/**/*.ts dashboard/**/*.ts --fix",
24+
"prepare": "husky"
2525
},
2626
"lint-staged": {
2727
"src/**/*.ts": [

scripts/extract-metrics.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

scripts/regenerate-summary.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/cli.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { hideBin } from 'yargs/helpers';
2+
import yargs from 'yargs/yargs';
3+
4+
import ExtractMetrics from './extract-metrics';
5+
import GenerateSummary from './generate-summary';
6+
import logger from './utils/logger';
7+
8+
// Define the main CLI command structure
9+
yargs(hideBin(process.argv))
10+
.scriptName('mcp-benchmark')
11+
.usage('$0 <cmd> [args]')
12+
.command(
13+
'extract-metrics',
14+
'Extract metrics from Claude chat logs',
15+
() => {},
16+
async () => {
17+
try {
18+
const subArgs = process.argv.slice(0, 2).concat(process.argv.slice(3));
19+
const result = await ExtractMetrics.extract(subArgs);
20+
21+
if (result.success) {
22+
logger.info(`Extraction completed successfully: ${result.message}`);
23+
} else {
24+
logger.error(`Extraction completed with errors: ${result.message}`);
25+
if (result.errors.length > 0) {
26+
logger.error(
27+
`Encountered ${result.errors.length} errors during extraction`,
28+
);
29+
}
30+
process.exit(1);
31+
}
32+
} catch (error) {
33+
logger.error('Unexpected error during extraction:', error);
34+
process.exit(1);
35+
}
36+
},
37+
)
38+
.command(
39+
'generate-summary',
40+
'Generate summary.json from existing metric files',
41+
() => {},
42+
async () => {
43+
try {
44+
const subArgs = process.argv.slice(0, 2).concat(process.argv.slice(3));
45+
const result = await GenerateSummary.generate(subArgs);
46+
47+
if (!result.success) {
48+
process.exit(1);
49+
}
50+
} catch (error) {
51+
logger.error('Unexpected error during summary generation:', error);
52+
process.exit(1);
53+
}
54+
},
55+
)
56+
.demandCommand(1, 'You must specify a command to run')
57+
.help()
58+
.alias('help', 'h')
59+
.epilog(
60+
'For more information, visit https://github.com/anthropic/mcp-te-benchmark',
61+
)
62+
.parse();

0 commit comments

Comments
 (0)