agenteval-cli 0.8.1 → 0.8.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.
Files changed (2) hide show
  1. package/bin/agenteval +101 -26
  2. package/package.json +2 -7
package/bin/agenteval CHANGED
@@ -1,38 +1,113 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { execFileSync } = require("child_process");
3
+ const { execFileSync, execSync } = require("child_process");
4
+ const { existsSync, mkdirSync, chmodSync, renameSync, unlinkSync } = require("fs");
4
5
  const { join } = require("path");
6
+ const https = require("https");
5
7
 
6
- const PLATFORMS = {
7
- "linux-x64": "@agenteval/linux-x64",
8
- "darwin-arm64": "@agenteval/darwin-arm64",
9
- "darwin-x64": "@agenteval/darwin-x64",
10
- };
8
+ const REPO = "lukasmetzler/agenteval";
9
+ const CACHE_DIR = join(require("os").homedir(), ".agenteval", "bin");
10
+ const BIN_PATH = join(CACHE_DIR, "agenteval");
11
+ const VERSION_PATH = join(CACHE_DIR, ".version");
11
12
 
12
- const key = `${process.platform === "win32" ? "win32" : process.platform}-${process.arch}`;
13
- const pkg = PLATFORMS[key];
13
+ function getPlatformKey() {
14
+ const platform = process.platform;
15
+ const arch = process.arch;
16
+ if (platform === "darwin" && arch === "arm64") return "agenteval-darwin-arm64";
17
+ if (platform === "darwin" && arch === "x64") return "agenteval-darwin-x64";
18
+ if (platform === "linux" && arch === "x64") return "agenteval-linux-x64";
19
+ return null;
20
+ }
14
21
 
15
- if (!pkg) {
16
- console.error(`agenteval: unsupported platform ${process.platform}-${process.arch}`);
17
- console.error("Supported: linux-x64, darwin-arm64, darwin-x64");
18
- console.error("Install manually: https://github.com/lukasmetzler/agenteval/releases");
19
- process.exit(1);
22
+ function getPackageVersion() {
23
+ try {
24
+ return require("../package.json").version;
25
+ } catch {
26
+ return null;
27
+ }
20
28
  }
21
29
 
22
- let binPath;
23
- try {
24
- binPath = join(require.resolve(`${pkg}/package.json`), "..", "bin", "agenteval");
25
- } catch {
26
- console.error(`agenteval: platform package ${pkg} not installed.`);
27
- console.error("Try reinstalling: npm install -g agenteval-cli");
28
- process.exit(1);
30
+ function getCachedVersion() {
31
+ try {
32
+ return require("fs").readFileSync(VERSION_PATH, "utf8").trim();
33
+ } catch {
34
+ return null;
35
+ }
29
36
  }
30
37
 
31
- try {
32
- execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
33
- } catch (err) {
34
- if (err && typeof err === "object" && "status" in err) {
35
- process.exit(err.status);
38
+ function download(url) {
39
+ return new Promise((resolve, reject) => {
40
+ https.get(url, (res) => {
41
+ if (res.statusCode === 301 || res.statusCode === 302) {
42
+ return download(res.headers.location).then(resolve, reject);
43
+ }
44
+ if (res.statusCode !== 200) {
45
+ reject(new Error(`HTTP ${res.statusCode}`));
46
+ return;
47
+ }
48
+ const chunks = [];
49
+ res.on("data", (chunk) => chunks.push(chunk));
50
+ res.on("end", () => resolve(Buffer.concat(chunks)));
51
+ res.on("error", reject);
52
+ }).on("error", reject);
53
+ });
54
+ }
55
+
56
+ async function ensureBinary() {
57
+ const pkgVersion = getPackageVersion();
58
+ const cachedVersion = getCachedVersion();
59
+
60
+ // Binary exists and matches current package version
61
+ if (existsSync(BIN_PATH) && cachedVersion === pkgVersion) {
62
+ return BIN_PATH;
36
63
  }
37
- process.exit(1);
64
+
65
+ const binary = getPlatformKey();
66
+ if (!binary) {
67
+ console.error(`agenteval: unsupported platform ${process.platform}-${process.arch}`);
68
+ console.error("Supported: linux-x64, darwin-arm64, darwin-x64");
69
+ console.error("Install manually: https://github.com/lukasmetzler/agenteval/releases");
70
+ process.exit(1);
71
+ }
72
+
73
+ const version = pkgVersion ? `v${pkgVersion}` : "latest";
74
+ const url = `https://github.com/${REPO}/releases/download/${version}/${binary}`;
75
+
76
+ console.error(`Downloading agenteval ${version} (${binary})...`);
77
+
78
+ mkdirSync(CACHE_DIR, { recursive: true });
79
+
80
+ const tmpPath = `${BIN_PATH}.tmp.${Date.now()}`;
81
+ try {
82
+ const data = await download(url);
83
+ require("fs").writeFileSync(tmpPath, data);
84
+ chmodSync(tmpPath, 0o755);
85
+
86
+ // Atomic replace
87
+ if (existsSync(BIN_PATH)) {
88
+ try { unlinkSync(BIN_PATH); } catch {}
89
+ }
90
+ renameSync(tmpPath, BIN_PATH);
91
+ require("fs").writeFileSync(VERSION_PATH, pkgVersion || version);
92
+
93
+ console.error("Done.");
94
+ } catch (err) {
95
+ try { unlinkSync(tmpPath); } catch {}
96
+ console.error(`agenteval: download failed (${err.message})`);
97
+ console.error(`Install manually: https://github.com/${REPO}/releases`);
98
+ process.exit(1);
99
+ }
100
+
101
+ return BIN_PATH;
38
102
  }
103
+
104
+ ensureBinary().then((binPath) => {
105
+ try {
106
+ const result = execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
107
+ } catch (err) {
108
+ process.exit(err && typeof err === "object" && "status" in err ? err.status : 1);
109
+ }
110
+ }).catch((err) => {
111
+ console.error(`agenteval: ${err.message}`);
112
+ process.exit(1);
113
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agenteval-cli",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Lint, benchmark, and CI gate for AI coding instructions",
5
5
  "keywords": [
6
6
  "cli",
@@ -35,10 +35,5 @@
35
35
  "files": [
36
36
  "bin/",
37
37
  "README.md"
38
- ],
39
- "optionalDependencies": {
40
- "@agenteval/linux-x64": "0.8.1",
41
- "@agenteval/darwin-arm64": "0.8.1",
42
- "@agenteval/darwin-x64": "0.8.1"
43
- }
38
+ ]
44
39
  }