@rivocode-cli/cli 2.0.2 → 3.0.1

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/rivo.js +25 -267
  2. package/package.json +10 -4
package/bin/rivo.js CHANGED
@@ -1,274 +1,32 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { spawn, execSync } from 'node:child_process';
4
- import {
5
- existsSync,
6
- mkdirSync,
7
- createWriteStream,
8
- chmodSync,
9
- unlinkSync,
10
- readFileSync,
11
- renameSync,
12
- readdirSync,
13
- } from 'node:fs';
14
- import { homedir, platform, arch } from 'node:os';
15
- import { join, dirname } from 'node:path';
16
- import { fileURLToPath } from 'node:url';
17
- import https from 'node:https';
18
- import http from 'node:http';
19
-
20
- const __filename = fileURLToPath(import.meta.url);
21
- const __dirname = dirname(__filename);
22
-
23
- // Read package.json version
24
- function getPackageVersion() {
25
- try {
26
- const pkgPath = join(__dirname, '..', 'package.json');
27
- const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
28
- return pkg.version || '2.0.0';
29
- } catch {
30
- return '2.0.0';
31
- }
32
- }
33
-
34
- const GITHUB_REPO = 'sanketpadhyal/RivoCode-Cli';
35
- const VERSION = getPackageVersion();
36
-
37
- function getTargetInfo() {
38
- const osType = platform();
39
- const archType = arch();
40
-
41
- if (osType === 'darwin') {
42
- if (archType === 'arm64') {
43
- return {
44
- target: 'darwin-arm64',
45
- binaryName: 'rivo-darwin-arm64',
46
- archiveName: 'rivo-darwin-arm64.tar.gz',
47
- isZip: false,
48
- isWindows: false,
49
- };
50
- }
51
- if (archType === 'x64') {
52
- return {
53
- target: 'darwin-x64',
54
- binaryName: 'rivo-darwin-x64',
55
- archiveName: 'rivo-darwin-x64.tar.gz',
56
- isZip: false,
57
- isWindows: false,
58
- };
59
- }
60
- } else if (osType === 'linux' || osType === 'android') {
61
- if (archType === 'x64') {
62
- return {
63
- target: 'linux-x64',
64
- binaryName: 'rivo-linux-x64',
65
- archiveName: 'rivo-linux-x64.tar.gz',
66
- isZip: false,
67
- isWindows: false,
68
- };
69
- }
70
- if (archType === 'arm64' || archType === 'arm') {
71
- return {
72
- target: 'linux-arm64',
73
- binaryName: 'rivo-linux-arm64',
74
- archiveName: 'rivo-linux-arm64.tar.gz',
75
- isZip: false,
76
- isWindows: false,
77
- };
78
- }
79
- } else if (osType === 'win32') {
80
- if (archType === 'x64') {
81
- return {
82
- target: 'win32-x64',
83
- binaryName: 'rivo-windows-x64.exe',
84
- archiveName: 'rivo-windows-x64.exe.zip',
85
- isZip: true,
86
- isWindows: true,
87
- };
88
- }
89
- }
90
-
91
- throw new Error(
92
- `Unsupported platform: ${osType} (${archType}).\n` +
93
- `RivoCode supports macOS (arm64, x64), Linux (x64, arm64), and Windows (x64).`
94
- );
95
- }
96
-
97
- function safeUnlink(filePath) {
98
- if (existsSync(filePath)) {
99
- try {
100
- unlinkSync(filePath);
101
- } catch {}
102
- }
103
- }
104
-
105
- function downloadFile(url, dest, maxRedirects = 5) {
106
- return new Promise((resolve, reject) => {
107
- if (maxRedirects < 0) {
108
- return reject(new Error('Too many redirects when downloading binary.'));
109
- }
110
-
111
- const client = url.startsWith('https:') ? https : http;
112
-
113
- client
114
- .get(url, { headers: { 'User-Agent': 'rivocode-installer' } }, (res) => {
115
- if (
116
- res.statusCode &&
117
- res.statusCode >= 300 &&
118
- res.statusCode < 400 &&
119
- res.headers.location
120
- ) {
121
- return resolve(
122
- downloadFile(res.headers.location, dest, maxRedirects - 1)
123
- );
124
- }
125
-
126
- if (res.statusCode !== 200) {
127
- return reject(
128
- new Error(
129
- `Failed to download binary: HTTP ${res.statusCode} ${res.statusMessage}`
130
- )
131
- );
132
- }
133
-
134
- const fileStream = createWriteStream(dest);
135
- res.pipe(fileStream);
136
-
137
- fileStream.on('finish', () => {
138
- fileStream.close(() => resolve());
139
- });
140
-
141
- fileStream.on('error', (err) => {
142
- safeUnlink(dest);
143
- reject(err);
144
- });
145
- })
146
- .on('error', (err) => {
147
- safeUnlink(dest);
148
- reject(err);
149
- });
150
- });
151
- }
152
-
153
- function extractArchive(archivePath, destDir, isZip) {
154
- if (isZip) {
155
- // Windows ZIP extraction
156
- try {
157
- execSync(`tar -xf "${archivePath}" -C "${destDir}"`, { stdio: 'ignore' });
158
- } catch {
159
- execSync(
160
- `powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force"`,
161
- { stdio: 'ignore' }
162
- );
163
- }
164
- } else {
165
- // Unix tar.gz extraction
166
- execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: 'inherit' });
167
- }
3
+ const os = require('os');
4
+ const { spawnSync } = require('child_process');
5
+ const path = require('path');
6
+
7
+ const platform = os.platform();
8
+ const architecture = os.arch();
9
+
10
+ const platformPackage = `@rivocode-cli/cli-${platform}-${architecture}`;
11
+
12
+ let binaryPath;
13
+ try {
14
+ const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
15
+ const packageDir = path.dirname(packageJsonPath);
16
+ const binaryName = platform === 'win32' ? 'rivo.exe' : 'rivo';
17
+ binaryPath = path.join(packageDir, 'bin', binaryName);
18
+ } catch (error) {
19
+ console.error(`Error: Unsupported platform or architecture: ${platform}-${architecture}`);
20
+ console.error(`Please ensure the optional dependency ${platformPackage} was installed.`);
21
+ process.exit(1);
168
22
  }
169
23
 
170
- async function ensureBinary() {
171
- const targetInfo = getTargetInfo();
172
-
173
- // If local binary exists in development tree, prefer it
174
- const localDevBinary = join(
175
- __dirname,
176
- '..',
177
- 'cli',
178
- 'bin',
179
- targetInfo.isWindows ? 'rivo.exe' : 'rivo'
180
- );
181
- if (process.env.RIVO_LOCAL === '1' && existsSync(localDevBinary)) {
182
- return localDevBinary;
183
- }
184
-
185
- const cacheBase = join(homedir(), '.rivocode', 'bin', `v${VERSION}`);
186
- const finalBinaryName = targetInfo.isWindows ? 'rivo.exe' : 'rivo';
187
- const finalBinaryPath = join(cacheBase, finalBinaryName);
188
-
189
- if (existsSync(finalBinaryPath)) {
190
- return finalBinaryPath;
191
- }
192
-
193
- // Create directory
194
- mkdirSync(cacheBase, { recursive: true });
195
-
196
- const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/v${VERSION}/${targetInfo.archiveName}`;
197
- const tempArchive = join(cacheBase, targetInfo.archiveName);
198
-
199
- console.log(`\x1b[36m⚡ Downloading RivoCode v${VERSION} (${targetInfo.target})...\x1b[0m`);
200
-
201
- try {
202
- await downloadFile(downloadUrl, tempArchive);
203
- console.log(`\x1b[32m✔ Download complete. Installing...\x1b[0m`);
204
-
205
- extractArchive(tempArchive, cacheBase, targetInfo.isZip);
206
-
207
- // If the extracted binary was named target-specific (e.g. rivo-darwin-arm64), rename to rivo
208
- const rawBinaryPath = join(cacheBase, targetInfo.binaryName);
209
- if (existsSync(rawBinaryPath) && rawBinaryPath !== finalBinaryPath) {
210
- renameSync(rawBinaryPath, finalBinaryPath);
211
- }
212
-
213
- // Fallback search if target binary was not found directly at finalBinaryPath
214
- if (!existsSync(finalBinaryPath)) {
215
- const files = readdirSync(cacheBase);
216
- const matched = files.find(
217
- (f) => f.startsWith('rivo') && !f.endsWith('.tar.gz') && !f.endsWith('.zip')
218
- );
219
- if (matched) {
220
- renameSync(join(cacheBase, matched), finalBinaryPath);
221
- }
222
- }
223
-
224
- if (!existsSync(finalBinaryPath)) {
225
- throw new Error(`Extracted binary was not found at ${finalBinaryPath}`);
226
- }
227
-
228
- if (!targetInfo.isWindows && existsSync(finalBinaryPath)) {
229
- chmodSync(finalBinaryPath, 0o755);
230
- }
231
-
232
- // Clean up archive
233
- safeUnlink(tempArchive);
234
-
235
- return finalBinaryPath;
236
- } catch (err) {
237
- // Clean up on failure
238
- safeUnlink(tempArchive);
239
- throw new Error(
240
- `Failed to install RivoCode v${VERSION}:\n${err.message}\n` +
241
- `You can manually download the binary from: https://github.com/${GITHUB_REPO}/releases/tag/v${VERSION}`
242
- );
243
- }
244
- }
245
-
246
- async function main() {
247
- try {
248
- const binaryPath = await ensureBinary();
249
- const args = process.argv.slice(2);
250
-
251
- const child = spawn(binaryPath, args, {
252
- stdio: 'inherit',
253
- env: process.env,
254
- });
255
-
256
- child.on('exit', (code, signal) => {
257
- if (signal) {
258
- process.kill(process.pid, signal);
259
- } else {
260
- process.exit(code ?? 0);
261
- }
262
- });
24
+ const args = process.argv.slice(2);
25
+ const result = spawnSync(binaryPath, args, { stdio: 'inherit' });
263
26
 
264
- child.on('error', (err) => {
265
- console.error('\x1b[31mFailed to start RivoCode:\x1b[0m', err.message);
266
- process.exit(1);
267
- });
268
- } catch (err) {
269
- console.error('\x1b[31mError:\x1b[0m', err.message);
270
- process.exit(1);
271
- }
27
+ if (result.error) {
28
+ console.error(`Failed to execute binary: ${result.error.message}`);
29
+ process.exit(1);
272
30
  }
273
31
 
274
- main();
32
+ process.exit(result.status || 0);
package/package.json CHANGED
@@ -1,20 +1,26 @@
1
1
  {
2
2
  "name": "@rivocode-cli/cli",
3
- "version": "2.0.2",
3
+ "version": "3.0.1",
4
4
  "description": "RivoCode — AI-powered terminal coding assistant",
5
5
  "author": "Sanket Padhyal <mrsanketpadhyal@gmail.com>",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "bin": {
9
9
  "rivo": "bin/rivo.js",
10
- "rivocode": "bin/rivo.js",
11
- "cli": "bin/rivo.js"
10
+ "rivocode": "bin/rivo.js"
12
11
  },
13
12
  "files": [
14
- "bin",
13
+ "bin/rivo.js",
15
14
  "README.md",
16
15
  "LICENSE"
17
16
  ],
17
+ "optionalDependencies": {
18
+ "@rivocode-cli/cli-linux-x64": "3.0.1",
19
+ "@rivocode-cli/cli-linux-arm64": "3.0.1",
20
+ "@rivocode-cli/cli-darwin-x64": "3.0.1",
21
+ "@rivocode-cli/cli-darwin-arm64": "3.0.1",
22
+ "@rivocode-cli/cli-win32-x64": "3.0.1"
23
+ },
18
24
  "repository": {
19
25
  "type": "git",
20
26
  "url": "git+https://github.com/sanketpadhyal/RivoCode-Cli.git"