rai-cli 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.
Files changed (3) hide show
  1. package/bin/rai +22 -0
  2. package/install.js +97 -0
  3. package/package.json +37 -0
package/bin/rai ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const path = require("path");
5
+ const { execFileSync } = require("child_process");
6
+
7
+ const ext = process.platform === "win32" ? ".exe" : "";
8
+ const bin = path.join(__dirname, `rai${ext}`);
9
+
10
+ try {
11
+ const result = execFileSync(bin, process.argv.slice(2), {
12
+ stdio: "inherit",
13
+ env: process.env,
14
+ });
15
+ } catch (err) {
16
+ if (err.status !== null) {
17
+ process.exit(err.status);
18
+ }
19
+ console.error(`Failed to run rai: ${err.message}`);
20
+ console.error("Try reinstalling: npm install rai-cli");
21
+ process.exit(1);
22
+ }
package/install.js ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ const os = require("os");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const https = require("https");
8
+ const { execSync } = require("child_process");
9
+
10
+ const VERSION = require("./package.json").version;
11
+ const REPO = "appmakes/Rai";
12
+ const BIN_DIR = path.join(__dirname, "bin");
13
+
14
+ const PLATFORM_MAP = {
15
+ "darwin-x64": { artifact: "rai-x86_64-apple-darwin.tar.gz", binary: "rai" },
16
+ "darwin-arm64": { artifact: "rai-aarch64-apple-darwin.tar.gz", binary: "rai" },
17
+ "linux-x64": { artifact: "rai-x86_64-linux-gnu.tar.gz", binary: "rai" },
18
+ "linux-arm64": { artifact: "rai-aarch64-linux-gnu.tar.gz", binary: "rai" },
19
+ "win32-x64": { artifact: "rai-x86_64-pc-windows-msvc.zip", binary: "rai.exe" },
20
+ };
21
+
22
+ function getPlatformKey() {
23
+ const platform = os.platform();
24
+ const arch = os.arch();
25
+ return `${platform}-${arch}`;
26
+ }
27
+
28
+ function fetch(url) {
29
+ return new Promise((resolve, reject) => {
30
+ https.get(url, { headers: { "User-Agent": "rai-cli-npm" } }, (res) => {
31
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
32
+ return fetch(res.headers.location).then(resolve, reject);
33
+ }
34
+ if (res.statusCode !== 200) {
35
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
36
+ }
37
+ const chunks = [];
38
+ res.on("data", (chunk) => chunks.push(chunk));
39
+ res.on("end", () => resolve(Buffer.concat(chunks)));
40
+ res.on("error", reject);
41
+ }).on("error", reject);
42
+ });
43
+ }
44
+
45
+ async function extract(buffer, artifact, binaryName) {
46
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "rai-"));
47
+ const archivePath = path.join(tmpDir, artifact);
48
+ fs.writeFileSync(archivePath, buffer);
49
+
50
+ if (artifact.endsWith(".tar.gz")) {
51
+ execSync(`tar xzf "${archivePath}" -C "${tmpDir}"`);
52
+ } else if (artifact.endsWith(".zip")) {
53
+ if (os.platform() === "win32") {
54
+ execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`, { stdio: "ignore" });
55
+ } else {
56
+ execSync(`unzip -o "${archivePath}" -d "${tmpDir}"`, { stdio: "ignore" });
57
+ }
58
+ }
59
+
60
+ const src = path.join(tmpDir, binaryName);
61
+ const dest = path.join(BIN_DIR, binaryName);
62
+
63
+ if (!fs.existsSync(src)) {
64
+ throw new Error(`Expected binary not found: ${src}`);
65
+ }
66
+
67
+ fs.mkdirSync(BIN_DIR, { recursive: true });
68
+ fs.copyFileSync(src, dest);
69
+ fs.chmodSync(dest, 0o755);
70
+
71
+ fs.rmSync(tmpDir, { recursive: true, force: true });
72
+ }
73
+
74
+ async function main() {
75
+ const key = getPlatformKey();
76
+ const target = PLATFORM_MAP[key];
77
+
78
+ if (!target) {
79
+ console.error(`Unsupported platform: ${key}`);
80
+ console.error(`Supported: ${Object.keys(PLATFORM_MAP).join(", ")}`);
81
+ process.exit(1);
82
+ }
83
+
84
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${target.artifact}`;
85
+ console.log(`Downloading rai v${VERSION} for ${key}...`);
86
+
87
+ try {
88
+ const buffer = await fetch(url);
89
+ await extract(buffer, target.artifact, target.binary);
90
+ console.log(`rai v${VERSION} installed successfully.`);
91
+ } catch (err) {
92
+ console.error(`Failed to install rai: ${err.message}`);
93
+ process.exit(1);
94
+ }
95
+ }
96
+
97
+ main();
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "rai-cli",
3
+ "version": "1.1.0",
4
+ "description": "Run AI instructions directly from your terminal, scripts, and CI/CD pipelines",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/appmakes/Rai"
9
+ },
10
+ "homepage": "https://appmakes.github.io/Rai/",
11
+ "keywords": [
12
+ "ai",
13
+ "cli",
14
+ "terminal",
15
+ "llm",
16
+ "automation"
17
+ ],
18
+ "bin": {
19
+ "rai": "bin/rai"
20
+ },
21
+ "scripts": {
22
+ "postinstall": "node install.js"
23
+ },
24
+ "os": [
25
+ "darwin",
26
+ "linux",
27
+ "win32"
28
+ ],
29
+ "cpu": [
30
+ "x64",
31
+ "arm64"
32
+ ],
33
+ "files": [
34
+ "install.js",
35
+ "bin/"
36
+ ]
37
+ }