@wacry/codeks 0.0.0-stage → 0.162.1-codeks.4

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/README.md +80 -2
  2. package/bin/codex.js +295 -0
  3. package/package.json +30 -4
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ <p align="center"><strong>Codex CLI</strong> is a coding agent from OpenAI that runs locally on your computer.
2
+ <p align="center">
3
+ <img src="https://github.com/openai/codex/blob/main/.github/codex-cli-splash.png" alt="Codex CLI splash" width="80%" />
4
+ </p>
5
+ </br>
6
+ If you want Codex in your code editor (VS Code, Cursor, Windsurf), <a href="https://developers.openai.com/codex/ide">install in your IDE.</a>
7
+ </br>If you want the desktop app experience, run <code>codex app</code> or visit <a href="https://chatgpt.com/codex?app-landing-page=true">the Codex App page</a>.
8
+ </br>If you are looking for the <em>cloud-based agent</em> from OpenAI, <strong>Codex Web</strong>, go to <a href="https://chatgpt.com/codex">chatgpt.com/codex</a>.</p>
2
9
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
10
+ ---
11
+
12
+ ## Quickstart
13
+
14
+ ### Installing and running Codex CLI
15
+
16
+ Run the following on Mac or Linux to install Codex CLI:
17
+
18
+ ```shell
19
+ curl -fsSL https://chatgpt.com/codex/install.sh | sh
20
+ ```
21
+
22
+ Run the following on Windows to install Codex CLI:
23
+
24
+ ```shell
25
+ powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"
26
+ ```
27
+
28
+ The standalone installers download from `https://releases.openai.com/codex` by default and fall back to GitHub Releases if a metadata or asset download is unavailable. To force GitHub Releases, set `CODEX_INSTALLER_USE_RELEASES_OPENAI_COM` to `false` (`0` and `no` are also accepted):
29
+
30
+ ```shell
31
+ curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_INSTALLER_USE_RELEASES_OPENAI_COM=false sh
32
+ ```
33
+
34
+ ```powershell
35
+ $env:CODEX_INSTALLER_USE_RELEASES_OPENAI_COM='false'; irm https://chatgpt.com/codex/install.ps1 | iex
36
+ ```
37
+
38
+ Codex CLI can also be installed via the following package managers:
39
+
40
+ ```shell
41
+ # Install using npm
42
+ npm install -g @openai/codex
43
+ ```
44
+
45
+ ```shell
46
+ # Install using Homebrew
47
+ brew install --cask codex
48
+ ```
49
+
50
+ Then simply run `codex` to get started.
51
+
52
+ <details>
53
+ <summary>You can also go to the <a href="https://github.com/openai/codex/releases/latest">latest GitHub Release</a> and download the appropriate binary for your platform.</summary>
54
+
55
+ Each GitHub Release contains many executables, but in practice, you likely want one of these:
56
+
57
+ - macOS
58
+ - Apple Silicon/arm64: `codex-aarch64-apple-darwin.tar.gz`
59
+ - x86_64 (older Mac hardware): `codex-x86_64-apple-darwin.tar.gz`
60
+ - Linux
61
+ - x86_64: `codex-x86_64-unknown-linux-musl.tar.gz`
62
+ - arm64: `codex-aarch64-unknown-linux-musl.tar.gz`
63
+
64
+ Each archive contains a single entry with the platform baked into the name (e.g., `codex-x86_64-unknown-linux-musl`), so you likely want to rename it to `codex` after extracting it.
65
+
66
+ </details>
67
+
68
+ ### Using Codex with your ChatGPT plan
69
+
70
+ Run `codex` and select **Sign in with ChatGPT**. We recommend signing into your ChatGPT account to use Codex as part of your Plus, Pro, Business, Edu, or Enterprise plan. [Learn more about what's included in your ChatGPT plan](https://help.openai.com/en/articles/11369540-codex-in-chatgpt).
71
+
72
+ You can also use Codex with an API key, but this requires [additional setup](https://developers.openai.com/codex/auth#sign-in-with-an-api-key).
73
+
74
+ ## Docs
75
+
76
+ - [**Codex Documentation**](https://developers.openai.com/codex)
77
+ - [**Contributing**](./docs/contributing.md)
78
+ - [**Installing & building**](./docs/install.md)
79
+ - [**Open source fund**](./docs/open-source-fund.md)
80
+
81
+ This repository is licensed under the [Apache-2.0 License](LICENSE).
package/bin/codex.js ADDED
@@ -0,0 +1,295 @@
1
+ #!/usr/bin/env node
2
+ // Unified entry point for the Codex CLI.
3
+
4
+ import { spawn } from "node:child_process";
5
+ import { existsSync, readFileSync, realpathSync } from "fs";
6
+ import { createRequire } from "node:module";
7
+ import path from "path";
8
+ import { fileURLToPath } from "url";
9
+
10
+ // __dirname equivalent in ESM
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+ const require = createRequire(import.meta.url);
14
+ const codexPackageRoot = realpathSync(path.join(__dirname, ".."));
15
+
16
+ const PLATFORM_PACKAGE_BY_TARGET = {
17
+ "x86_64-unknown-linux-musl": "@openai/codex-linux-x64",
18
+ "aarch64-unknown-linux-musl": "@openai/codex-linux-arm64",
19
+ "x86_64-apple-darwin": "@openai/codex-darwin-x64",
20
+ "aarch64-apple-darwin": "@openai/codex-darwin-arm64",
21
+ "x86_64-pc-windows-msvc": "@openai/codex-win32-x64",
22
+ "aarch64-pc-windows-msvc": "@openai/codex-win32-arm64",
23
+ };
24
+
25
+ const { platform, arch } = process;
26
+
27
+ let targetTriple = null;
28
+ switch (platform) {
29
+ case "linux":
30
+ case "android":
31
+ switch (arch) {
32
+ case "x64":
33
+ targetTriple = "x86_64-unknown-linux-musl";
34
+ break;
35
+ case "arm64":
36
+ targetTriple = "aarch64-unknown-linux-musl";
37
+ break;
38
+ default:
39
+ break;
40
+ }
41
+ break;
42
+ case "darwin":
43
+ switch (arch) {
44
+ case "x64":
45
+ targetTriple = "x86_64-apple-darwin";
46
+ break;
47
+ case "arm64":
48
+ targetTriple = "aarch64-apple-darwin";
49
+ break;
50
+ default:
51
+ break;
52
+ }
53
+ break;
54
+ case "win32":
55
+ switch (arch) {
56
+ case "x64":
57
+ targetTriple = "x86_64-pc-windows-msvc";
58
+ break;
59
+ case "arm64":
60
+ targetTriple = "aarch64-pc-windows-msvc";
61
+ break;
62
+ default:
63
+ break;
64
+ }
65
+ break;
66
+ default:
67
+ break;
68
+ }
69
+
70
+ if (!targetTriple) {
71
+ throw new Error(`Unsupported platform: ${platform} (${arch})`);
72
+ }
73
+
74
+ const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
75
+ if (!platformPackage) {
76
+ throw new Error(`Unsupported target triple: ${targetTriple}`);
77
+ }
78
+
79
+ function findCodexExecutable() {
80
+ let vendorRoot;
81
+ try {
82
+ const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
83
+ vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
84
+ } catch {
85
+ vendorRoot = path.join(__dirname, "..", "vendor");
86
+ }
87
+
88
+ const codexExecutable = path.join(
89
+ vendorRoot,
90
+ targetTriple,
91
+ "bin",
92
+ process.platform === "win32" ? "codex.exe" : "codex",
93
+ );
94
+ if (existsSync(codexExecutable)) {
95
+ return codexExecutable;
96
+ }
97
+
98
+ const packageManager = detectPackageManager();
99
+ const updateCommand =
100
+ packageManager === "bun"
101
+ ? "bun install -g @openai/codex@latest"
102
+ : packageManager === "pnpm"
103
+ ? "pnpm add -g @openai/codex@latest"
104
+ : packageManager === "vite-plus"
105
+ ? "vp install -g @openai/codex@latest"
106
+ : "npm install -g @openai/codex@latest";
107
+ throw new Error(
108
+ `Missing optional dependency ${platformPackage}. Reinstall Codex: ${updateCommand}`,
109
+ );
110
+ }
111
+
112
+ const binaryPath = findCodexExecutable();
113
+
114
+ // Use an asynchronous spawn instead of spawnSync so that Node is able to
115
+ // respond to signals (e.g. Ctrl-C / SIGINT) while the native binary is
116
+ // executing. This allows us to forward those signals to the child process
117
+ // and guarantees that when either the child terminates or the parent
118
+ // receives a fatal signal, both processes exit in a predictable manner.
119
+
120
+ function isPnpmOwnedCodexInstall(nodeModulesDir) {
121
+ if (!existsSync(path.join(nodeModulesDir, ".modules.yaml"))) {
122
+ return false;
123
+ }
124
+
125
+ try {
126
+ return (
127
+ realpathSync(path.join(nodeModulesDir, "@openai", "codex")) ===
128
+ codexPackageRoot
129
+ );
130
+ } catch {
131
+ return false;
132
+ }
133
+ }
134
+
135
+ function isVitePlusOwnedCodexInstall(packagesDir) {
136
+ if (path.basename(packagesDir) !== "packages") {
137
+ return false;
138
+ }
139
+
140
+ try {
141
+ const metadata = JSON.parse(
142
+ readFileSync(path.join(packagesDir, "@openai", "codex.json"), "utf8"),
143
+ );
144
+ if (metadata.name !== "@openai/codex") {
145
+ return false;
146
+ }
147
+
148
+ // Vite+ records the active global installation in packages/@openai/codex.json.
149
+ // Older installs have no ID or append a #-prefixed ID to the package name;
150
+ // newer installs put the ID in a subdirectory of the package prefix.
151
+ const installId = metadata.installId || "";
152
+ const installDir = installId.startsWith("#")
153
+ ? path.join(packagesDir, `@openai/codex${installId}`)
154
+ : path.join(packagesDir, "@openai/codex", installId);
155
+ for (const nodeModulesDir of [
156
+ path.join(installDir, "lib", "node_modules"),
157
+ path.join(installDir, "node_modules"),
158
+ ]) {
159
+ const packageRoot = path.join(nodeModulesDir, "@openai", "codex");
160
+ if (
161
+ existsSync(packageRoot) &&
162
+ realpathSync(packageRoot) === codexPackageRoot
163
+ ) {
164
+ return true;
165
+ }
166
+ }
167
+ } catch {
168
+ // Missing or unreadable ownership metadata must not prevent Codex starting.
169
+ }
170
+ return false;
171
+ }
172
+
173
+ /**
174
+ * Use heuristics to detect the package manager that was used to install Codex
175
+ * in order to give the user a hint about how to update it.
176
+ */
177
+ function detectPackageManager() {
178
+ // Package-manager ownership metadata can be several parents above the package.
179
+ // Search ancestors of both the canonical package root and lexical entrypoint
180
+ // because the package manager may link either path.
181
+ const entrypointDir = path.dirname(path.resolve(process.argv[1]));
182
+ for (const startDir of new Set([codexPackageRoot, entrypointDir])) {
183
+ const filesystemRoot = path.parse(startDir).root;
184
+ for (
185
+ let currentDir = startDir;
186
+ currentDir !== filesystemRoot;
187
+ currentDir = path.dirname(currentDir)
188
+ ) {
189
+ if (isVitePlusOwnedCodexInstall(currentDir)) {
190
+ return "vite-plus";
191
+ }
192
+ if (isPnpmOwnedCodexInstall(path.join(currentDir, "node_modules"))) {
193
+ return "pnpm";
194
+ }
195
+ }
196
+
197
+ if (isPnpmOwnedCodexInstall(path.join(filesystemRoot, "node_modules"))) {
198
+ return "pnpm";
199
+ }
200
+ }
201
+
202
+ const userAgent = process.env.npm_config_user_agent || "";
203
+ if (/\bbun\//.test(userAgent)) {
204
+ return "bun";
205
+ }
206
+
207
+ const execPath = process.env.npm_execpath || "";
208
+ if (execPath.includes("bun")) {
209
+ return "bun";
210
+ }
211
+
212
+ if (
213
+ __dirname.includes(".bun/install/global") ||
214
+ __dirname.includes(".bun\\install\\global")
215
+ ) {
216
+ return "bun";
217
+ }
218
+
219
+ return userAgent ? "npm" : null;
220
+ }
221
+
222
+ const packageManager = detectPackageManager();
223
+ const packageManagerEnvVar =
224
+ packageManager === "bun"
225
+ ? "CODEX_MANAGED_BY_BUN"
226
+ : packageManager === "pnpm"
227
+ ? "CODEX_MANAGED_BY_PNPM"
228
+ : packageManager === "vite-plus"
229
+ ? "CODEX_MANAGED_BY_VITE_PLUS"
230
+ : "CODEX_MANAGED_BY_NPM";
231
+ const env = {
232
+ ...process.env,
233
+ CODEX_MANAGED_PACKAGE_ROOT: codexPackageRoot,
234
+ };
235
+ delete env.CODEX_MANAGED_BY_NPM;
236
+ delete env.CODEX_MANAGED_BY_BUN;
237
+ delete env.CODEX_MANAGED_BY_PNPM;
238
+ delete env.CODEX_MANAGED_BY_VITE_PLUS;
239
+ env[packageManagerEnvVar] = "1";
240
+
241
+ const child = spawn(binaryPath, process.argv.slice(2), {
242
+ stdio: "inherit",
243
+ env,
244
+ });
245
+
246
+ child.on("error", (err) => {
247
+ // Typically triggered when the binary is missing or not executable.
248
+ // Re-throwing here will terminate the parent with a non-zero exit code
249
+ // while still printing a helpful stack trace.
250
+ // eslint-disable-next-line no-console
251
+ console.error(err);
252
+ process.exit(1);
253
+ });
254
+
255
+ // Forward common termination signals to the child so that it shuts down
256
+ // gracefully. In the handler we temporarily disable the default behavior of
257
+ // exiting immediately; once the child has been signaled we simply wait for
258
+ // its exit event which will in turn terminate the parent (see below).
259
+ const forwardSignal = (signal) => {
260
+ if (child.killed) {
261
+ return;
262
+ }
263
+ try {
264
+ child.kill(signal);
265
+ } catch {
266
+ /* ignore */
267
+ }
268
+ };
269
+
270
+ ["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
271
+ process.on(sig, () => forwardSignal(sig));
272
+ });
273
+
274
+ // When the child exits, mirror its termination reason in the parent so that
275
+ // shell scripts and other tooling observe the correct exit status.
276
+ // Wrap the lifetime of the child process in a Promise so that we can await
277
+ // its termination in a structured way. The Promise resolves with an object
278
+ // describing how the child exited: either via exit code or due to a signal.
279
+ const childResult = await new Promise((resolve) => {
280
+ child.on("exit", (code, signal) => {
281
+ if (signal) {
282
+ resolve({ type: "signal", signal });
283
+ } else {
284
+ resolve({ type: "code", exitCode: code ?? 1 });
285
+ }
286
+ });
287
+ });
288
+
289
+ if (childResult.type === "signal") {
290
+ // Re-emit the same signal so that the parent terminates with the expected
291
+ // semantics (this also sets the correct exit code of 128 + n).
292
+ process.kill(process.pid, childResult.signal);
293
+ } else {
294
+ process.exit(childResult.exitCode);
295
+ }
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@wacry/codeks",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.162.1-codeks.4",
4
+ "description": "Personal build of the Codex CLI from the codeks fork (WAcry/codeks). Not an official OpenAI package.",
5
+ "license": "Apache-2.0",
6
+ "bin": {
7
+ "codex": "bin/codex.js"
8
+ },
9
+ "type": "module",
10
+ "engines": {
11
+ "node": ">=16"
12
+ },
13
+ "files": [
14
+ "bin/codex.js"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/WAcry/codeks.git",
19
+ "directory": "codex-cli"
20
+ },
21
+ "packageManager": "pnpm@10.34.5+sha512.a4ee05f2f73658255bd6a89859c065a45c28a57daefae2c893a168ee2b73168c37b91e83e57ea67654ad03f03031746430e8bce38e362e042605fb8abc80192e",
22
+ "optionalDependencies": {
23
+ "@openai/codex-linux-x64": "npm:@wacry/codeks@0.162.1-codeks.4-linux-x64"
24
+ },
25
+ "codeks": {
26
+ "tag": "codeks/rust-v0.162.1/4",
27
+ "commit": "c9932e65fa3f98d9be884b38f5aab9b1dbe20fc2",
28
+ "upstreamVersion": "0.162.1",
29
+ "upstreamTag": "rust-v0.162.1",
30
+ "upstreamCommit": "092d3acd6bec3e3a14bdc7e7a2810ab628ab759d"
31
+ }
32
+ }