@wiggumdev/ralph-ai 0.0.2
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/bin/ralph +91 -0
- package/package.json +35 -0
- package/postinstall.mjs +125 -0
package/bin/ralph
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const childProcess = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const path = require("node:path");
|
|
6
|
+
const os = require("node:os");
|
|
7
|
+
|
|
8
|
+
function run(target) {
|
|
9
|
+
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
});
|
|
12
|
+
if (result.error) {
|
|
13
|
+
console.error(result.error.message);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const code = typeof result.status === "number" ? result.status : 0;
|
|
17
|
+
process.exit(code);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const envPath = process.env.OPENCODE_BIN_PATH;
|
|
21
|
+
if (envPath) {
|
|
22
|
+
run(envPath);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const scriptPath = fs.realpathSync(__filename);
|
|
26
|
+
const scriptDir = path.dirname(scriptPath);
|
|
27
|
+
|
|
28
|
+
const NPM_SCOPE = "@wiggumdev";
|
|
29
|
+
|
|
30
|
+
const platformMap = {
|
|
31
|
+
darwin: "darwin",
|
|
32
|
+
linux: "linux",
|
|
33
|
+
win32: "windows",
|
|
34
|
+
};
|
|
35
|
+
const archMap = {
|
|
36
|
+
x64: "x64",
|
|
37
|
+
arm64: "arm64",
|
|
38
|
+
arm: "arm",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let platform = platformMap[os.platform()];
|
|
42
|
+
if (!platform) {
|
|
43
|
+
platform = os.platform();
|
|
44
|
+
}
|
|
45
|
+
let arch = archMap[os.arch()];
|
|
46
|
+
if (!arch) {
|
|
47
|
+
arch = os.arch();
|
|
48
|
+
}
|
|
49
|
+
const base = `ralph-${platform}-${arch}`;
|
|
50
|
+
const scopedBase = `${NPM_SCOPE}/${base}`;
|
|
51
|
+
const binary = platform === "windows" ? "ralph.exe" : "ralph";
|
|
52
|
+
|
|
53
|
+
function findBinary(startDir) {
|
|
54
|
+
let current = startDir;
|
|
55
|
+
for (;;) {
|
|
56
|
+
const modules = path.join(current, "node_modules");
|
|
57
|
+
if (fs.existsSync(modules)) {
|
|
58
|
+
// Check for scoped package in @wiggumdev directory
|
|
59
|
+
const scopedDir = path.join(modules, NPM_SCOPE);
|
|
60
|
+
if (fs.existsSync(scopedDir)) {
|
|
61
|
+
const entries = fs.readdirSync(scopedDir);
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
if (!entry.startsWith(base)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const candidate = path.join(scopedDir, entry, "bin", binary);
|
|
67
|
+
if (fs.existsSync(candidate)) {
|
|
68
|
+
return candidate;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const parent = path.dirname(current);
|
|
74
|
+
if (parent === current) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
current = parent;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const resolved = findBinary(scriptDir);
|
|
82
|
+
if (!resolved) {
|
|
83
|
+
console.error(
|
|
84
|
+
'It seems that your package manager failed to install the right version of the ralph CLI for your platform. You can try manually installing the "' +
|
|
85
|
+
scopedBase +
|
|
86
|
+
'" package'
|
|
87
|
+
);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
run(resolved);
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wiggumdev/ralph-ai",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "AI-agnostic agentic loop CLI",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ralph": "./bin/ralph"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node ./postinstall.mjs"
|
|
10
|
+
},
|
|
11
|
+
"optionalDependencies": {
|
|
12
|
+
"@wiggumdev/ralph-linux-arm64": "0.0.2",
|
|
13
|
+
"@wiggumdev/ralph-linux-x64": "0.0.2",
|
|
14
|
+
"@wiggumdev/ralph-linux-x64-baseline": "0.0.2",
|
|
15
|
+
"@wiggumdev/ralph-linux-arm64-musl": "0.0.2",
|
|
16
|
+
"@wiggumdev/ralph-linux-x64-musl": "0.0.2",
|
|
17
|
+
"@wiggumdev/ralph-linux-x64-baseline-musl": "0.0.2",
|
|
18
|
+
"@wiggumdev/ralph-darwin-arm64": "0.0.2",
|
|
19
|
+
"@wiggumdev/ralph-darwin-x64": "0.0.2",
|
|
20
|
+
"@wiggumdev/ralph-darwin-x64-baseline": "0.0.2",
|
|
21
|
+
"@wiggumdev/ralph-windows-x64": "0.0.2",
|
|
22
|
+
"@wiggumdev/ralph-windows-x64-baseline": "0.0.2"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/wiggumdev/ralph.git"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
|
|
12
|
+
// npm scope for scoped package names
|
|
13
|
+
const NPM_SCOPE = "@wiggumdev";
|
|
14
|
+
|
|
15
|
+
function detectPlatformAndArch() {
|
|
16
|
+
// Map platform names
|
|
17
|
+
let platform;
|
|
18
|
+
switch (os.platform()) {
|
|
19
|
+
case "darwin":
|
|
20
|
+
platform = "darwin";
|
|
21
|
+
break;
|
|
22
|
+
case "linux":
|
|
23
|
+
platform = "linux";
|
|
24
|
+
break;
|
|
25
|
+
case "win32":
|
|
26
|
+
platform = "windows";
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
platform = os.platform();
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Map architecture names
|
|
34
|
+
let arch;
|
|
35
|
+
switch (os.arch()) {
|
|
36
|
+
case "x64":
|
|
37
|
+
arch = "x64";
|
|
38
|
+
break;
|
|
39
|
+
case "arm64":
|
|
40
|
+
arch = "arm64";
|
|
41
|
+
break;
|
|
42
|
+
case "arm":
|
|
43
|
+
arch = "arm";
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
arch = os.arch();
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { platform, arch };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function findBinary() {
|
|
54
|
+
const { platform, arch } = detectPlatformAndArch();
|
|
55
|
+
const packageName = `${NPM_SCOPE}/ralph-${platform}-${arch}`;
|
|
56
|
+
const binaryName = platform === "windows" ? "ralph.exe" : "ralph";
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
// Use require.resolve to find the package
|
|
60
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
61
|
+
const packageDir = path.dirname(packageJsonPath);
|
|
62
|
+
const binaryPath = path.join(packageDir, "bin", binaryName);
|
|
63
|
+
|
|
64
|
+
if (!fs.existsSync(binaryPath)) {
|
|
65
|
+
throw new Error(`Binary not found at ${binaryPath}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { binaryPath, binaryName };
|
|
69
|
+
} catch (error) {
|
|
70
|
+
throw new Error(`Could not find package ${packageName}: ${error.message}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function prepareBinDirectory(binaryName) {
|
|
75
|
+
const binDir = path.join(__dirname, "bin");
|
|
76
|
+
const targetPath = path.join(binDir, binaryName);
|
|
77
|
+
|
|
78
|
+
// Ensure bin directory exists
|
|
79
|
+
if (!fs.existsSync(binDir)) {
|
|
80
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Remove existing binary/symlink if it exists
|
|
84
|
+
if (fs.existsSync(targetPath)) {
|
|
85
|
+
fs.unlinkSync(targetPath);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return { binDir, targetPath };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function symlinkBinary(sourcePath, binaryName) {
|
|
92
|
+
const { targetPath } = prepareBinDirectory(binaryName);
|
|
93
|
+
|
|
94
|
+
fs.symlinkSync(sourcePath, targetPath);
|
|
95
|
+
console.log(`ralph binary symlinked: ${targetPath} -> ${sourcePath}`);
|
|
96
|
+
|
|
97
|
+
// Verify the file exists after operation
|
|
98
|
+
if (!fs.existsSync(targetPath)) {
|
|
99
|
+
throw new Error(`Failed to symlink binary to ${targetPath}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function main() {
|
|
104
|
+
try {
|
|
105
|
+
if (os.platform() === "win32") {
|
|
106
|
+
// On Windows, the .exe is already included in the package and bin field points to it
|
|
107
|
+
// No postinstall setup needed
|
|
108
|
+
console.log(
|
|
109
|
+
"Windows detected: binary setup not needed (using packaged .exe)"
|
|
110
|
+
);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const { binaryPath, binaryName } = findBinary();
|
|
115
|
+
symlinkBinary(binaryPath, binaryName);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error("Failed to setup ralph binary:", error.message);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
main().catch((error) => {
|
|
123
|
+
console.error("Postinstall script error:", error.message);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
});
|