@nothumanwork/cursor-agent-cli 1.0.0 → 1.1.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/install.js +69 -10
- package/package.json +3 -2
package/install.js
CHANGED
|
@@ -8,7 +8,7 @@ const path = require("path");
|
|
|
8
8
|
const { execFileSync } = require("child_process");
|
|
9
9
|
const os = require("os");
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const INSTALL_SCRIPT_URL = "https://cursor.com/install";
|
|
12
12
|
const BASE_URL = "https://downloads.cursor.com/lab";
|
|
13
13
|
|
|
14
14
|
function getPlatform() {
|
|
@@ -35,6 +35,41 @@ function getArch() {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
function fetchText(url) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const get = url.startsWith("https") ? https.get : http.get;
|
|
41
|
+
get(url, (res) => {
|
|
42
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
43
|
+
return fetchText(res.headers.location).then(resolve, reject);
|
|
44
|
+
}
|
|
45
|
+
if (res.statusCode !== 200) {
|
|
46
|
+
reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
47
|
+
res.resume();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let body = "";
|
|
51
|
+
res.on("data", (chunk) => (body += chunk));
|
|
52
|
+
res.on("end", () => resolve(body));
|
|
53
|
+
res.on("error", reject);
|
|
54
|
+
}).on("error", reject);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function getLatestVersion() {
|
|
59
|
+
const script = await fetchText(INSTALL_SCRIPT_URL);
|
|
60
|
+
return parseVersionFromScript(script);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parseVersionFromScript(script) {
|
|
64
|
+
// The install script contains a download URL like:
|
|
65
|
+
// https://downloads.cursor.com/lab/<VERSION>/linux/x64/agent-cli-package.tar.gz
|
|
66
|
+
const match = script.match(/downloads\.cursor\.com\/lab\/([^/]+)\//);
|
|
67
|
+
if (!match) {
|
|
68
|
+
throw new Error("Could not detect latest version from install script");
|
|
69
|
+
}
|
|
70
|
+
return match[1];
|
|
71
|
+
}
|
|
72
|
+
|
|
38
73
|
function fetch(url) {
|
|
39
74
|
return new Promise((resolve, reject) => {
|
|
40
75
|
const get = url.startsWith("https") ? https.get : http.get;
|
|
@@ -59,18 +94,27 @@ async function install() {
|
|
|
59
94
|
const vendorDir = path.join(packageDir, "vendor");
|
|
60
95
|
const binaryPath = path.join(vendorDir, "cursor-agent");
|
|
61
96
|
|
|
62
|
-
|
|
97
|
+
console.log("cursor-agent: fetching latest version...");
|
|
98
|
+
const version = await getLatestVersion();
|
|
99
|
+
console.log(`cursor-agent: latest version is ${version}`);
|
|
100
|
+
|
|
101
|
+
// Skip if already installed at this version
|
|
63
102
|
if (fs.existsSync(binaryPath)) {
|
|
64
103
|
try {
|
|
65
|
-
execFileSync(binaryPath, ["--version"], {
|
|
66
|
-
|
|
67
|
-
|
|
104
|
+
const installed = execFileSync(binaryPath, ["--version"], {
|
|
105
|
+
encoding: "utf-8",
|
|
106
|
+
}).trim();
|
|
107
|
+
if (installed === version) {
|
|
108
|
+
console.log("cursor-agent: already up to date, skipping download");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
console.log(`cursor-agent: upgrading from ${installed} to ${version}`);
|
|
68
112
|
} catch {
|
|
69
113
|
// Binary exists but doesn't work — re-download
|
|
70
114
|
}
|
|
71
115
|
}
|
|
72
116
|
|
|
73
|
-
const url = `${BASE_URL}/${
|
|
117
|
+
const url = `${BASE_URL}/${version}/${platform}/${arch}/agent-cli-package.tar.gz`;
|
|
74
118
|
|
|
75
119
|
console.log(`cursor-agent: downloading ${platform}/${arch} binary...`);
|
|
76
120
|
|
|
@@ -114,7 +158,22 @@ async function install() {
|
|
|
114
158
|
}
|
|
115
159
|
}
|
|
116
160
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
161
|
+
module.exports = {
|
|
162
|
+
getPlatform,
|
|
163
|
+
getArch,
|
|
164
|
+
fetchText,
|
|
165
|
+
getLatestVersion,
|
|
166
|
+
parseVersionFromScript,
|
|
167
|
+
fetch,
|
|
168
|
+
install,
|
|
169
|
+
INSTALL_SCRIPT_URL,
|
|
170
|
+
BASE_URL,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// Run install when executed directly
|
|
174
|
+
if (require.main === module) {
|
|
175
|
+
install().catch((err) => {
|
|
176
|
+
console.error(`cursor-agent: ${err.message}`);
|
|
177
|
+
process.exit(1);
|
|
178
|
+
});
|
|
179
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nothumanwork/cursor-agent-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Cursor Agent CLI — installs the official Cursor Agent binary via npm",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"cursor-agent": "bin/agent.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"postinstall": "node install.js"
|
|
11
|
+
"postinstall": "node install.js",
|
|
12
|
+
"test": "node --test ./test/install.test.js"
|
|
12
13
|
},
|
|
13
14
|
"os": [
|
|
14
15
|
"darwin",
|