@magnitudedev/cli 0.0.1-alpha.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.
@@ -0,0 +1,109 @@
1
+ 'use strict';
2
+
3
+ const https = require('https');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const os = require('os');
7
+ const { execSync } = require('child_process');
8
+
9
+ const BINARY_DIR = path.join(os.homedir(), '.magnitude', 'bin');
10
+ const VERSION_FILE = path.join(BINARY_DIR, 'magnitude.version');
11
+ const REPO = 'magnitudedev/magnitude';
12
+
13
+ function getPlatformKey() {
14
+ const platform = process.platform;
15
+ const arch = process.arch;
16
+
17
+ const map = {
18
+ 'darwin-arm64': 'darwin-arm64',
19
+ 'darwin-x64': 'darwin-x64',
20
+ 'linux-x64': 'linux-x64',
21
+ 'linux-arm64': 'linux-arm64',
22
+ 'win32-x64': 'windows-x64',
23
+ };
24
+
25
+ const key = `${platform}-${arch}`;
26
+ if (!map[key]) {
27
+ throw new Error(`Unsupported platform: ${key}. Magnitude supports: ${Object.keys(map).join(', ')}`);
28
+ }
29
+ return map[key];
30
+ }
31
+
32
+ function getBinaryPath() {
33
+ const ext = process.platform === 'win32' ? '.exe' : '';
34
+ return path.join(BINARY_DIR, `magnitude${ext}`);
35
+ }
36
+
37
+ function versionMatches(version) {
38
+ try {
39
+ const cached = fs.readFileSync(VERSION_FILE, 'utf8').trim();
40
+ return cached === version;
41
+ } catch {
42
+ return false;
43
+ }
44
+ }
45
+
46
+ function download(url) {
47
+ return new Promise((resolve, reject) => {
48
+ https.get(url, (res) => {
49
+ if (res.statusCode === 302 || res.statusCode === 301) {
50
+ return download(res.headers.location).then(resolve, reject);
51
+ }
52
+ if (res.statusCode !== 200) {
53
+ return reject(new Error(`Download failed: HTTP ${res.statusCode}`));
54
+ }
55
+ const chunks = [];
56
+ res.on('data', (chunk) => chunks.push(chunk));
57
+ res.on('end', () => resolve(Buffer.concat(chunks)));
58
+ res.on('error', reject);
59
+ }).on('error', reject);
60
+ });
61
+ }
62
+
63
+ async function downloadAndInstall(version) {
64
+ const platformKey = getPlatformKey();
65
+ const fileName = `magnitude-${platformKey}.tar.gz`;
66
+ const url = `https://github.com/${REPO}/releases/download/%40magnitudedev%2Fcli%40${version}/${fileName}`;
67
+
68
+ fs.mkdirSync(BINARY_DIR, { recursive: true });
69
+
70
+ console.log(`Downloading Magnitude v${version} for ${platformKey}...`);
71
+
72
+ const data = await download(url);
73
+ const tmpFile = path.join(BINARY_DIR, fileName);
74
+ fs.writeFileSync(tmpFile, data);
75
+
76
+ try {
77
+ if (process.platform === 'win32') {
78
+ execSync(`tar -xf "${tmpFile}" -C "${BINARY_DIR}"`, { stdio: 'ignore' });
79
+ } else {
80
+ execSync(`tar -xzf "${tmpFile}" -C "${BINARY_DIR}"`, { stdio: 'ignore' });
81
+ }
82
+
83
+ const binPath = getBinaryPath();
84
+ if (!fs.existsSync(binPath)) {
85
+ throw new Error(`Binary not found after extraction at ${binPath}`);
86
+ }
87
+
88
+ if (process.platform !== 'win32') {
89
+ fs.chmodSync(binPath, 0o755);
90
+ }
91
+
92
+ fs.writeFileSync(VERSION_FILE, version, 'utf8');
93
+ return binPath;
94
+ } finally {
95
+ try { fs.unlinkSync(tmpFile); } catch {}
96
+ }
97
+ }
98
+
99
+ async function ensureBinary(version) {
100
+ const binPath = getBinaryPath();
101
+
102
+ if (fs.existsSync(binPath) && versionMatches(version)) {
103
+ return binPath;
104
+ }
105
+
106
+ return downloadAndInstall(version);
107
+ }
108
+
109
+ module.exports = { ensureBinary };
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ console.log('');
4
+ console.log(' Thanks for installing Magnitude!');
5
+ console.log(' Run `magnitude` to get started.');
6
+ console.log('');
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@magnitudedev/cli",
3
+ "version": "0.0.1-alpha.0",
4
+ "description": "Magnitude AI coding agent",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "magnitude": "bin/magnitude.js"
8
+ },
9
+ "files": [
10
+ "bin",
11
+ "lib"
12
+ ],
13
+ "scripts": {
14
+ "postinstall": "node lib/postinstall.js"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ }
19
+ }