@agi-cli/install 0.1.30 → 0.1.31
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 +99 -15
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { promisify } from 'util';
|
|
5
|
-
import { existsSync } from 'fs';
|
|
3
|
+
import { existsSync, createWriteStream, chmodSync, mkdirSync } from 'fs';
|
|
6
4
|
import { resolve, dirname } from 'path';
|
|
7
5
|
import { fileURLToPath } from 'url';
|
|
6
|
+
import { get } from 'https';
|
|
7
|
+
import { homedir, platform, arch } from 'os';
|
|
8
|
+
import { spawnSync } from 'child_process';
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
+
const REPO = 'nitishxyz/agi';
|
|
11
|
+
const BIN_NAME = 'agi';
|
|
10
12
|
|
|
11
13
|
// Skip if running in a workspace (local development)
|
|
12
14
|
function isInWorkspace() {
|
|
13
15
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
// Check if we're in a monorepo workspace by looking for workspace root indicators
|
|
15
16
|
const workspaceRoot = resolve(__dirname, '../../');
|
|
16
17
|
return (
|
|
17
18
|
existsSync(resolve(workspaceRoot, 'apps')) &&
|
|
@@ -19,23 +20,106 @@ function isInWorkspace() {
|
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
function getPlatformInfo() {
|
|
24
|
+
const platformMap = {
|
|
25
|
+
darwin: 'darwin',
|
|
26
|
+
linux: 'linux',
|
|
27
|
+
win32: 'windows',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const archMap = {
|
|
31
|
+
x64: 'x64',
|
|
32
|
+
arm64: 'arm64',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const os = platformMap[platform()];
|
|
36
|
+
const architecture = archMap[arch()];
|
|
37
|
+
const ext = platform() === 'win32' ? '.exe' : '';
|
|
38
|
+
|
|
39
|
+
if (!os || !architecture) {
|
|
40
|
+
throw new Error(`Unsupported platform: ${platform()}-${arch()}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { os, arch: architecture, ext };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function download(url, dest) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const file = createWriteStream(dest);
|
|
49
|
+
|
|
50
|
+
function handleRedirect(response) {
|
|
51
|
+
if (
|
|
52
|
+
response.statusCode >= 300 &&
|
|
53
|
+
response.statusCode < 400 &&
|
|
54
|
+
response.headers.location
|
|
55
|
+
) {
|
|
56
|
+
get(response.headers.location, handleRedirect);
|
|
57
|
+
} else if (response.statusCode === 200) {
|
|
58
|
+
response.pipe(file);
|
|
59
|
+
file.on('finish', () => {
|
|
60
|
+
file.close();
|
|
61
|
+
resolve();
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
reject(new Error(`Download failed: ${response.statusCode}`));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get(url, handleRedirect).on('error', (err) => {
|
|
69
|
+
file.close();
|
|
70
|
+
reject(err);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
22
75
|
async function install() {
|
|
23
76
|
if (isInWorkspace()) {
|
|
24
77
|
console.log('Detected workspace environment, skipping install script.');
|
|
25
78
|
return;
|
|
26
79
|
}
|
|
27
80
|
|
|
28
|
-
console.log('Installing agi CLI...');
|
|
29
|
-
console.log('Running: curl -fsSL https://install.agi.nitish.sh | sh');
|
|
30
|
-
|
|
31
81
|
try {
|
|
32
|
-
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
82
|
+
const { os, arch: architecture, ext } = getPlatformInfo();
|
|
83
|
+
const asset = `${BIN_NAME}-${os}-${architecture}${ext}`;
|
|
84
|
+
const url = `https://github.com/${REPO}/releases/latest/download/${asset}`;
|
|
85
|
+
|
|
86
|
+
console.log(`Installing ${BIN_NAME} (${os}/${architecture})...`);
|
|
87
|
+
|
|
88
|
+
// Determine install directory
|
|
89
|
+
const userBin = resolve(homedir(), '.local', 'bin');
|
|
90
|
+
mkdirSync(userBin, { recursive: true });
|
|
91
|
+
const binPath = resolve(userBin, `${BIN_NAME}${ext}`);
|
|
92
|
+
|
|
93
|
+
// Download
|
|
94
|
+
console.log(`Downloading from ${url}...`);
|
|
95
|
+
await download(url, binPath);
|
|
96
|
+
|
|
97
|
+
// Make executable
|
|
98
|
+
chmodSync(binPath, 0o755);
|
|
99
|
+
|
|
100
|
+
// Verify
|
|
101
|
+
const result = spawnSync(binPath, ['--version'], { encoding: 'utf8' });
|
|
102
|
+
if (result.status === 0) {
|
|
103
|
+
console.log(`\n✓ ${BIN_NAME} installed successfully!`);
|
|
104
|
+
console.log(`Version: ${result.stdout.trim()}`);
|
|
105
|
+
console.log(`Location: ${binPath}`);
|
|
106
|
+
|
|
107
|
+
// Check if in PATH
|
|
108
|
+
const pathDirs = (process.env.PATH || '').split(':');
|
|
109
|
+
if (!pathDirs.includes(userBin)) {
|
|
110
|
+
console.log(`\n⚠️ Add ${userBin} to your PATH:`);
|
|
111
|
+
console.log(
|
|
112
|
+
` echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc`,
|
|
113
|
+
);
|
|
114
|
+
console.log(
|
|
115
|
+
` Or for zsh: echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
console.log(`\n✓ Installed to ${binPath}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log(`\nRun: ${BIN_NAME} --help`);
|
|
39
123
|
} catch (error) {
|
|
40
124
|
console.error('Failed to install agi CLI:', error.message);
|
|
41
125
|
console.error('\nPlease try installing manually:');
|