@agi-cli/install 0.1.34 → 0.1.35
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/package.json +1 -1
- package/start.js +134 -1
package/package.json
CHANGED
package/start.js
CHANGED
|
@@ -49,6 +49,91 @@ function findBinaryInPath() {
|
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
function getVersion(binaryPath) {
|
|
53
|
+
try {
|
|
54
|
+
const result = spawnSync(binaryPath, ['--version'], { encoding: 'utf8' });
|
|
55
|
+
if (result.status === 0 && result.stdout) {
|
|
56
|
+
// Extract version number from output (e.g., "agi 1.2.3" -> "1.2.3")
|
|
57
|
+
const match = result.stdout.trim().match(/[\d.]+/);
|
|
58
|
+
return match ? match[0] : null;
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
// If we can't get version, return null
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getLatestVersion() {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const url = `https://api.github.com/repos/${REPO}/releases/latest`;
|
|
69
|
+
|
|
70
|
+
get(
|
|
71
|
+
url,
|
|
72
|
+
{
|
|
73
|
+
headers: {
|
|
74
|
+
'User-Agent': 'agi-installer',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
(response) => {
|
|
78
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
79
|
+
// Follow redirect
|
|
80
|
+
get(
|
|
81
|
+
response.headers.location,
|
|
82
|
+
{
|
|
83
|
+
headers: {
|
|
84
|
+
'User-Agent': 'agi-installer',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
handleResponse,
|
|
88
|
+
);
|
|
89
|
+
} else {
|
|
90
|
+
handleResponse(response);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function handleResponse(res) {
|
|
94
|
+
let data = '';
|
|
95
|
+
|
|
96
|
+
res.on('data', (chunk) => {
|
|
97
|
+
data += chunk;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
res.on('end', () => {
|
|
101
|
+
try {
|
|
102
|
+
const json = JSON.parse(data);
|
|
103
|
+
if (json.tag_name) {
|
|
104
|
+
// Remove 'v' prefix if present (e.g., "v1.2.3" -> "1.2.3")
|
|
105
|
+
const version = json.tag_name.replace(/^v/, '');
|
|
106
|
+
resolve(version);
|
|
107
|
+
} else {
|
|
108
|
+
reject(new Error('No tag_name in response'));
|
|
109
|
+
}
|
|
110
|
+
} catch (err) {
|
|
111
|
+
reject(err);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
).on('error', reject);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function compareVersions(v1, v2) {
|
|
121
|
+
if (!v1 || !v2) return null;
|
|
122
|
+
|
|
123
|
+
const parts1 = v1.split('.').map(Number);
|
|
124
|
+
const parts2 = v2.split('.').map(Number);
|
|
125
|
+
|
|
126
|
+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
127
|
+
const part1 = parts1[i] || 0;
|
|
128
|
+
const part2 = parts2[i] || 0;
|
|
129
|
+
|
|
130
|
+
if (part1 > part2) return 1;
|
|
131
|
+
if (part1 < part2) return -1;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return 0; // Equal
|
|
135
|
+
}
|
|
136
|
+
|
|
52
137
|
function getPlatformInfo() {
|
|
53
138
|
const platformMap = {
|
|
54
139
|
darwin: 'darwin',
|
|
@@ -213,15 +298,62 @@ async function install() {
|
|
|
213
298
|
}
|
|
214
299
|
}
|
|
215
300
|
|
|
301
|
+
async function checkAndUpdateVersion(binaryPath) {
|
|
302
|
+
try {
|
|
303
|
+
const currentVersion = getVersion(binaryPath);
|
|
304
|
+
|
|
305
|
+
if (!currentVersion) {
|
|
306
|
+
console.log('⚠️ Could not determine current version');
|
|
307
|
+
return { needsUpdate: false, binaryPath };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
console.log(`Current version: ${currentVersion}`);
|
|
311
|
+
console.log('Checking for updates...');
|
|
312
|
+
|
|
313
|
+
const latestVersion = await getLatestVersion();
|
|
314
|
+
console.log(`Latest version: ${latestVersion}`);
|
|
315
|
+
|
|
316
|
+
const comparison = compareVersions(currentVersion, latestVersion);
|
|
317
|
+
|
|
318
|
+
if (comparison < 0) {
|
|
319
|
+
// Current version is older
|
|
320
|
+
console.log(
|
|
321
|
+
`\n🔄 New version available: ${currentVersion} → ${latestVersion}`,
|
|
322
|
+
);
|
|
323
|
+
console.log('Updating...\n');
|
|
324
|
+
const newBinaryPath = await install();
|
|
325
|
+
return { needsUpdate: true, binaryPath: newBinaryPath };
|
|
326
|
+
} else if (comparison > 0) {
|
|
327
|
+
// Current version is newer (dev version?)
|
|
328
|
+
console.log(
|
|
329
|
+
`✓ You have a newer version (${currentVersion}) than the latest release`,
|
|
330
|
+
);
|
|
331
|
+
return { needsUpdate: false, binaryPath };
|
|
332
|
+
} else {
|
|
333
|
+
// Versions match
|
|
334
|
+
console.log('✓ You have the latest version');
|
|
335
|
+
return { needsUpdate: false, binaryPath };
|
|
336
|
+
}
|
|
337
|
+
} catch (error) {
|
|
338
|
+
console.log(`⚠️ Could not check for updates: ${error.message}`);
|
|
339
|
+
return { needsUpdate: false, binaryPath };
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
216
343
|
async function main() {
|
|
217
344
|
if (isInWorkspace()) {
|
|
218
345
|
console.log('Detected workspace environment, skipping install script.');
|
|
219
346
|
return;
|
|
220
347
|
}
|
|
221
348
|
|
|
222
|
-
|
|
349
|
+
let binaryPath = findBinaryInPath();
|
|
223
350
|
|
|
224
351
|
if (binaryPath) {
|
|
352
|
+
// Binary exists, check version
|
|
353
|
+
const { needsUpdate, binaryPath: updatedPath } =
|
|
354
|
+
await checkAndUpdateVersion(binaryPath);
|
|
355
|
+
binaryPath = updatedPath;
|
|
356
|
+
|
|
225
357
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
|
226
358
|
stdio: 'inherit',
|
|
227
359
|
});
|
|
@@ -230,6 +362,7 @@ async function main() {
|
|
|
230
362
|
process.exit(code || 0);
|
|
231
363
|
});
|
|
232
364
|
} else {
|
|
365
|
+
// No binary found, install fresh
|
|
233
366
|
const installedPath = await install();
|
|
234
367
|
|
|
235
368
|
if (process.argv.length > 2) {
|