recodex 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/bin/recodex.js +54 -29
  2. package/package.json +1 -1
package/bin/recodex.js CHANGED
@@ -12,18 +12,25 @@ import {
12
12
  existsSync,
13
13
  mkdirSync,
14
14
  renameSync,
15
+ unlinkSync,
16
+ writeFileSync,
15
17
  } from "node:fs";
16
18
  import { tmpdir } from "node:os";
17
19
  import path from "node:path";
18
20
 
19
- const VERSION = "0.1.0";
21
+ const VERSION = "0.1.2";
20
22
  const GITHUB = "Kartvya69/recodex";
21
23
 
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",
24
+ // process.platform/process.arch -> release asset + entry binary name.
25
+ const PLATFORM = {
26
+ "linux-x64": {
27
+ asset: "recodex-x86_64-unknown-linux-gnu.tar.gz",
28
+ entry: "recodex",
29
+ },
30
+ "win32-x64": {
31
+ asset: "recodex-x86_64-pc-windows-msvc.zip",
32
+ entry: "recodex.exe",
33
+ },
27
34
  };
28
35
 
29
36
  function fail(msg, suggestion) {
@@ -39,8 +46,8 @@ function cacheDir() {
39
46
 
40
47
  async function ensureBinary() {
41
48
  const key = `${process.platform}-${process.arch}`;
42
- const asset = ASSET_BY_PLATFORM[key];
43
- if (!asset) {
49
+ const p = PLATFORM[key];
50
+ if (!p) {
44
51
  fail(
45
52
  `no prebuilt binary for ${process.platform}/${process.arch} in v${VERSION}.`,
46
53
  `Browse https://github.com/${GITHUB}/releases for available assets, or build from source.`,
@@ -48,12 +55,12 @@ async function ensureBinary() {
48
55
  }
49
56
 
50
57
  const dir = cacheDir();
51
- const cached = path.join(dir, `recodex-${VERSION}`);
58
+ const cached = path.join(dir, `recodex-${VERSION}-${p.entry}`);
52
59
  if (existsSync(cached)) return cached;
53
60
 
54
61
  mkdirSync(dir, { recursive: true });
55
62
 
56
- const url = `https://github.com/${GITHUB}/releases/download/v${VERSION}/${asset}`;
63
+ const url = `https://github.com/${GITHUB}/releases/download/v${VERSION}/${p.asset}`;
57
64
  process.stderr.write(`recodex: downloading v${VERSION} (${key}) — one-time setup...\n`);
58
65
 
59
66
  let res;
@@ -65,34 +72,52 @@ async function ensureBinary() {
65
72
  if (!res.ok) fail(`download failed: HTTP ${res.status} for ${url}`);
66
73
 
67
74
  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"],
75
+
76
+ if (process.platform === "win32") {
77
+ // Windows: write the zip to a temp file and Expand-Archive it (always
78
+ // available on Windows; avoids depending on a system `tar`).
79
+ const tmpZip = path.join(dir, `__recodex-${VERSION}-${process.pid}.zip`);
80
+ writeFileSync(tmpZip, buf);
81
+ const code = await new Promise((resolve) => {
82
+ const t = spawn(
83
+ "powershell",
84
+ ["-NoProfile", "-Command", `Expand-Archive -Path '${tmpZip}' -DestinationPath '${dir}' -Force`],
85
+ { stdio: "inherit" },
86
+ );
87
+ t.on("exit", resolve);
88
+ t.on("error", (err) => {
89
+ console.error(`recodex: Expand-Archive failed: ${err.message}`);
90
+ resolve(1);
91
+ });
71
92
  });
72
- t.on("exit", resolve);
73
- t.on("error", (err) => {
74
- console.error(`recodex: tar extraction failed: ${err.message}`);
75
- resolve(1);
93
+ try { unlinkSync(tmpZip); } catch { /* ignore */ }
94
+ if (code !== 0) fail("failed to extract the downloaded zip (Expand-Archive)");
95
+ } else {
96
+ // POSIX: stream the gzip tarball into tar.
97
+ const code = await new Promise((resolve) => {
98
+ const t = spawn("tar", ["-xz", "-C", dir, p.entry], {
99
+ stdio: ["pipe", "inherit", "inherit"],
100
+ });
101
+ t.on("exit", resolve);
102
+ t.on("error", (err) => {
103
+ console.error(`recodex: tar extraction failed: ${err.message}`);
104
+ resolve(1);
105
+ });
106
+ t.stdin.end(buf);
76
107
  });
77
- t.stdin.end(buf);
78
- });
79
- if (code !== 0) fail("failed to extract the downloaded tarball");
108
+ if (code !== 0) fail("failed to extract the downloaded tarball");
109
+ }
80
110
 
81
- const extracted = path.join(dir, "recodex");
82
- if (!existsSync(extracted)) fail("extracted binary not found after untar");
111
+ const extracted = path.join(dir, p.entry);
112
+ if (!existsSync(extracted)) fail("extracted binary not found after extraction");
83
113
  renameSync(extracted, cached);
84
- chmodSync(cached, 0o755);
114
+ try { chmodSync(cached, 0o755); } catch { /* Windows: chmod is a no-op */ }
85
115
  return cached;
86
116
  }
87
117
 
88
118
  const binaryPath = await ensureBinary();
89
119
 
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 });
120
+ const child = spawn(binaryPath, process.argv.slice(2), { stdio: "inherit" });
96
121
 
97
122
  child.on("error", (err) => {
98
123
  console.error(`recodex: failed to launch binary: ${err.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "recodex",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "recodex — a community fork of OpenAI Codex with a restored Chat Completions wire API and models.dev BYOK metadata enrichment.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "",