recodex 0.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.
- package/bin/recodex.js +125 -0
- package/package.json +35 -0
package/bin/recodex.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// recodex — launcher for the recodex Rust binary.
|
|
3
|
+
//
|
|
4
|
+
// On first run it downloads the prebuilt binary for this platform from the
|
|
5
|
+
// recodex GitHub release, caches it under ~/.recodex/bin/, and execs it. On
|
|
6
|
+
// later runs it launches the cached binary directly. No optionalDependencies
|
|
7
|
+
// or platform sub-packages are required.
|
|
8
|
+
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import {
|
|
11
|
+
chmodSync,
|
|
12
|
+
existsSync,
|
|
13
|
+
mkdirSync,
|
|
14
|
+
renameSync,
|
|
15
|
+
} from "node:fs";
|
|
16
|
+
import { tmpdir } from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
const VERSION = "0.1.0";
|
|
20
|
+
const GITHUB = "Kartvya69/recodex";
|
|
21
|
+
|
|
22
|
+
// Map process.platform/process.arch -> the release asset triple.
|
|
23
|
+
// v0.1.0 ships Linux x86_64 (glibc). Other platforms will be added in later
|
|
24
|
+
// releases; until then we fail fast with a helpful message.
|
|
25
|
+
const ASSET_BY_PLATFORM = {
|
|
26
|
+
"linux-x64": "recodex-x86_64-unknown-linux-gnu.tar.gz",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function fail(msg, suggestion) {
|
|
30
|
+
console.error(`recodex: ${msg}`);
|
|
31
|
+
if (suggestion) console.error(suggestion);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function cacheDir() {
|
|
36
|
+
const home = process.env.HOME || process.env.USERPROFILE || tmpdir();
|
|
37
|
+
return path.join(home, ".recodex", "bin");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function ensureBinary() {
|
|
41
|
+
const key = `${process.platform}-${process.arch}`;
|
|
42
|
+
const asset = ASSET_BY_PLATFORM[key];
|
|
43
|
+
if (!asset) {
|
|
44
|
+
fail(
|
|
45
|
+
`no prebuilt binary for ${process.platform}/${process.arch} in v${VERSION}.`,
|
|
46
|
+
`Browse https://github.com/${GITHUB}/releases for available assets, or build from source.`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const dir = cacheDir();
|
|
51
|
+
const cached = path.join(dir, `recodex-${VERSION}`);
|
|
52
|
+
if (existsSync(cached)) return cached;
|
|
53
|
+
|
|
54
|
+
mkdirSync(dir, { recursive: true });
|
|
55
|
+
|
|
56
|
+
const url = `https://github.com/${GITHUB}/releases/download/v${VERSION}/${asset}`;
|
|
57
|
+
process.stderr.write(`recodex: downloading v${VERSION} (${key}) — one-time setup...\n`);
|
|
58
|
+
|
|
59
|
+
let res;
|
|
60
|
+
try {
|
|
61
|
+
res = await fetch(url, { redirect: "follow" });
|
|
62
|
+
} catch (err) {
|
|
63
|
+
fail(`network error fetching ${url}: ${err && err.message ? err.message : err}`);
|
|
64
|
+
}
|
|
65
|
+
if (!res.ok) fail(`download failed: HTTP ${res.status} for ${url}`);
|
|
66
|
+
|
|
67
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
68
|
+
const code = await new Promise((resolve) => {
|
|
69
|
+
const t = spawn("tar", ["-xz", "-C", dir, "recodex"], {
|
|
70
|
+
stdio: ["pipe", "inherit", "inherit"],
|
|
71
|
+
});
|
|
72
|
+
t.on("exit", resolve);
|
|
73
|
+
t.on("error", (err) => {
|
|
74
|
+
console.error(`recodex: tar extraction failed: ${err.message}`);
|
|
75
|
+
resolve(1);
|
|
76
|
+
});
|
|
77
|
+
t.stdin.end(buf);
|
|
78
|
+
});
|
|
79
|
+
if (code !== 0) fail("failed to extract the downloaded tarball");
|
|
80
|
+
|
|
81
|
+
const extracted = path.join(dir, "recodex");
|
|
82
|
+
if (!existsSync(extracted)) fail("extracted binary not found after untar");
|
|
83
|
+
renameSync(extracted, cached);
|
|
84
|
+
chmodSync(cached, 0o755);
|
|
85
|
+
return cached;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const binaryPath = await ensureBinary();
|
|
89
|
+
|
|
90
|
+
const env = {
|
|
91
|
+
...process.env,
|
|
92
|
+
CODEX_MANAGED_PACKAGE_ROOT: undefined,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit", env });
|
|
96
|
+
|
|
97
|
+
child.on("error", (err) => {
|
|
98
|
+
console.error(`recodex: failed to launch binary: ${err.message}`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const forwardSignal = (signal) => {
|
|
103
|
+
if (child.killed) return;
|
|
104
|
+
try {
|
|
105
|
+
child.kill(signal);
|
|
106
|
+
} catch {
|
|
107
|
+
/* ignore */
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) =>
|
|
111
|
+
process.on(sig, () => forwardSignal(sig)),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const result = await new Promise((resolve) => {
|
|
115
|
+
child.on("exit", (code, signal) => {
|
|
116
|
+
if (signal) resolve({ type: "signal", signal });
|
|
117
|
+
else resolve({ type: "code", exitCode: code ?? 1 });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (result.type === "signal") {
|
|
122
|
+
process.kill(process.pid, result.signal);
|
|
123
|
+
} else {
|
|
124
|
+
process.exit(result.exitCode);
|
|
125
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "recodex",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "recodex — a community fork of OpenAI Codex with a restored Chat Completions wire API and models.dev BYOK metadata enrichment.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "",
|
|
7
|
+
"homepage": "https://github.com/Kartvya69/recodex#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Kartvya69/recodex.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Kartvya69/recodex/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"codex",
|
|
17
|
+
"cli",
|
|
18
|
+
"agent",
|
|
19
|
+
"ai",
|
|
20
|
+
"byok",
|
|
21
|
+
"chat-completions",
|
|
22
|
+
"openai"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"bin": {
|
|
26
|
+
"recodex": "bin/recodex.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"bin/recodex.js"
|
|
30
|
+
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"engineStrict": true
|
|
35
|
+
}
|