@loongphy/codext 0.111.0-ad42b61

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 (4) hide show
  1. package/README.md +81 -0
  2. package/bin/codex.js +226 -0
  3. package/bin/rg +79 -0
  4. package/package.json +26 -0
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Codext
2
+
3
+ An opinionated Codex CLI. This is strictly a personal hobby project, forked from openai/codex.
4
+
5
+ ![Codex build](https://img.shields.io/static/v1?label=codex%20build&message=rust-v0.111.0-36ab73925&color=2ea043)
6
+
7
+ ![TUI](
8
+ https://github.com/user-attachments/assets/127abbc2-cb30-4d6e-8a81-ce707260c045)
9
+
10
+ ## Quick Start
11
+
12
+ ```shell
13
+ cd codex-rs
14
+ cargo run --bin codex
15
+ ```
16
+
17
+ ## Project Goals
18
+
19
+ We will never merge code from the upstream repo; instead, we re-implement our changes on top of the latest upstream code.
20
+
21
+ Iteration flow (aligned with `.agents/skills/codex-upstream-reapply`):
22
+
23
+ ```mermaid
24
+ flowchart TD
25
+ A[Freeze old branch: commit changes + intent docs] --> B[Fetch upstream tags]
26
+ B --> C[Pick tag + create new branch from tag]
27
+ C --> D[Generate reimplementation bundle]
28
+ D --> E[Read old branch + bundle for intent]
29
+ E --> F[Re-implement changes on new branch]
30
+ F --> G[Sanity check diffs vs tag]
31
+ G --> H[Force-push to fork main]
32
+ ```
33
+
34
+ > [!IMPORTANT]
35
+ > **DO NOT USE IN PRODUCTION.**
36
+ > To keep upstream sync easy, we do not write test code for what we changed. This project is for experimental use only.
37
+
38
+ * **DX Focused:** Focus strictly on optimizing developer experience, **without adding new features**.
39
+ * **Upstream Sync:** We sync with the upstream repository regularly.
40
+
41
+ ## What Changed
42
+
43
+ * Added a TUI status header with model/effort, cwd, git summary, and rate-limit status.
44
+ * Collaboration mode presets now accept per-mode overrides and default to the active `/model` settings.
45
+ * TUI watches `auth.json` for external login changes and reloads auth automatically (with a warning on account switch).
46
+ * AGENTS.md/project-doc instructions are refreshed on each new user turn, and Codex shows an explicit warning when a refresh is applied.
47
+ * Full change log: see [CHANGED.md](./CHANGED.md).
48
+
49
+ ## AGENT Local development check
50
+
51
+ 1. DO NOT update any test codes
52
+ 2. After making code changes, verify the CLI still launches:
53
+
54
+ ```shell
55
+ cd ./codex-rs
56
+ cargo run --bin codex
57
+ ```
58
+
59
+ ```toml
60
+ # config.toml
61
+ [collaboration_modes.plan]
62
+ model = "gpt-5.2-codex"
63
+ reasoning_effort = "xhigh"
64
+
65
+ [collaboration_modes.code]
66
+ model = "gpt-5.2-codex"
67
+ ```
68
+
69
+ ## Skills
70
+
71
+ When syncing to the latest upstream codex version, use `.agents/skills/codex-upstream-reapply` to re-implement our custom requirements on top of the newest code, avoiding merge conflicts from the old branch history.
72
+
73
+ Example:
74
+
75
+ ```
76
+ $codex-upstream-reapply old_branch feat/rust-v0.94.0, new origin tag: rust-v0.98.0
77
+ ```
78
+
79
+ ## Credits
80
+
81
+ Status bar design reference: <https://linux.do/t/topic/1481797>
package/bin/codex.js ADDED
@@ -0,0 +1,226 @@
1
+ #!/usr/bin/env node
2
+ // Unified entry point for the Codex CLI.
3
+
4
+ import { spawn } from "node:child_process";
5
+ import { existsSync } 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
+
15
+ const PLATFORM_PACKAGE_BY_TARGET = {
16
+ "x86_64-unknown-linux-musl": "@openai/codex-linux-x64",
17
+ "aarch64-apple-darwin": "@openai/codex-darwin-arm64",
18
+ "x86_64-pc-windows-msvc": "@openai/codex-win32-x64",
19
+ };
20
+
21
+ const { platform, arch } = process;
22
+
23
+ let targetTriple = null;
24
+ switch (platform) {
25
+ case "linux":
26
+ case "android":
27
+ switch (arch) {
28
+ case "x64":
29
+ targetTriple = "x86_64-unknown-linux-musl";
30
+ break;
31
+ case "arm64":
32
+ targetTriple = "aarch64-unknown-linux-musl";
33
+ break;
34
+ default:
35
+ break;
36
+ }
37
+ break;
38
+ case "darwin":
39
+ switch (arch) {
40
+ case "x64":
41
+ targetTriple = "x86_64-apple-darwin";
42
+ break;
43
+ case "arm64":
44
+ targetTriple = "aarch64-apple-darwin";
45
+ break;
46
+ default:
47
+ break;
48
+ }
49
+ break;
50
+ case "win32":
51
+ switch (arch) {
52
+ case "x64":
53
+ targetTriple = "x86_64-pc-windows-msvc";
54
+ break;
55
+ case "arm64":
56
+ targetTriple = "aarch64-pc-windows-msvc";
57
+ break;
58
+ default:
59
+ break;
60
+ }
61
+ break;
62
+ default:
63
+ break;
64
+ }
65
+
66
+ if (!targetTriple) {
67
+ throw new Error(`Unsupported platform: ${platform} (${arch})`);
68
+ }
69
+
70
+ const platformPackage = PLATFORM_PACKAGE_BY_TARGET[targetTriple];
71
+ if (!platformPackage) {
72
+ throw new Error(`Unsupported target triple: ${targetTriple}`);
73
+ }
74
+
75
+ const codexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
76
+ const localVendorRoot = path.join(__dirname, "..", "vendor");
77
+ const localBinaryPath = path.join(
78
+ localVendorRoot,
79
+ targetTriple,
80
+ "codex",
81
+ codexBinaryName,
82
+ );
83
+
84
+ let vendorRoot;
85
+ try {
86
+ const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
87
+ vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
88
+ } catch {
89
+ if (existsSync(localBinaryPath)) {
90
+ vendorRoot = localVendorRoot;
91
+ } else {
92
+ const packageManager = detectPackageManager();
93
+ const updateCommand =
94
+ packageManager === "bun"
95
+ ? "bun install -g @loongphy/codext@latest"
96
+ : "npm install -g @loongphy/codext@latest";
97
+ throw new Error(
98
+ `Missing optional dependency ${platformPackage}. Reinstall Codex: ${updateCommand}`,
99
+ );
100
+ }
101
+ }
102
+
103
+ if (!vendorRoot) {
104
+ const packageManager = detectPackageManager();
105
+ const updateCommand =
106
+ packageManager === "bun"
107
+ ? "bun install -g @loongphy/codext@latest"
108
+ : "npm install -g @loongphy/codext@latest";
109
+ throw new Error(
110
+ `Missing optional dependency ${platformPackage}. Reinstall Codex: ${updateCommand}`,
111
+ );
112
+ }
113
+
114
+ const archRoot = path.join(vendorRoot, targetTriple);
115
+ const binaryPath = path.join(archRoot, "codex", codexBinaryName);
116
+
117
+ // Use an asynchronous spawn instead of spawnSync so that Node is able to
118
+ // respond to signals (e.g. Ctrl-C / SIGINT) while the native binary is
119
+ // executing. This allows us to forward those signals to the child process
120
+ // and guarantees that when either the child terminates or the parent
121
+ // receives a fatal signal, both processes exit in a predictable manner.
122
+
123
+ function getUpdatedPath(newDirs) {
124
+ const pathSep = process.platform === "win32" ? ";" : ":";
125
+ const existingPath = process.env.PATH || "";
126
+ const updatedPath = [
127
+ ...newDirs,
128
+ ...existingPath.split(pathSep).filter(Boolean),
129
+ ].join(pathSep);
130
+ return updatedPath;
131
+ }
132
+
133
+ /**
134
+ * Use heuristics to detect the package manager that was used to install Codex
135
+ * in order to give the user a hint about how to update it.
136
+ */
137
+ function detectPackageManager() {
138
+ const userAgent = process.env.npm_config_user_agent || "";
139
+ if (/\bbun\//.test(userAgent)) {
140
+ return "bun";
141
+ }
142
+
143
+ const execPath = process.env.npm_execpath || "";
144
+ if (execPath.includes("bun")) {
145
+ return "bun";
146
+ }
147
+
148
+ if (
149
+ __dirname.includes(".bun/install/global") ||
150
+ __dirname.includes(".bun\\install\\global")
151
+ ) {
152
+ return "bun";
153
+ }
154
+
155
+ return userAgent ? "npm" : null;
156
+ }
157
+
158
+ const additionalDirs = [];
159
+ const pathDir = path.join(archRoot, "path");
160
+ if (existsSync(pathDir)) {
161
+ additionalDirs.push(pathDir);
162
+ }
163
+ const updatedPath = getUpdatedPath(additionalDirs);
164
+
165
+ const env = { ...process.env, PATH: updatedPath };
166
+ const packageManagerEnvVar =
167
+ detectPackageManager() === "bun"
168
+ ? "CODEX_MANAGED_BY_BUN"
169
+ : "CODEX_MANAGED_BY_NPM";
170
+ env[packageManagerEnvVar] = "1";
171
+
172
+ const child = spawn(binaryPath, process.argv.slice(2), {
173
+ stdio: "inherit",
174
+ env,
175
+ });
176
+
177
+ child.on("error", (err) => {
178
+ // Typically triggered when the binary is missing or not executable.
179
+ // Re-throwing here will terminate the parent with a non-zero exit code
180
+ // while still printing a helpful stack trace.
181
+ // eslint-disable-next-line no-console
182
+ console.error(err);
183
+ process.exit(1);
184
+ });
185
+
186
+ // Forward common termination signals to the child so that it shuts down
187
+ // gracefully. In the handler we temporarily disable the default behavior of
188
+ // exiting immediately; once the child has been signaled we simply wait for
189
+ // its exit event which will in turn terminate the parent (see below).
190
+ const forwardSignal = (signal) => {
191
+ if (child.killed) {
192
+ return;
193
+ }
194
+ try {
195
+ child.kill(signal);
196
+ } catch {
197
+ /* ignore */
198
+ }
199
+ };
200
+
201
+ ["SIGINT", "SIGTERM", "SIGHUP"].forEach((sig) => {
202
+ process.on(sig, () => forwardSignal(sig));
203
+ });
204
+
205
+ // When the child exits, mirror its termination reason in the parent so that
206
+ // shell scripts and other tooling observe the correct exit status.
207
+ // Wrap the lifetime of the child process in a Promise so that we can await
208
+ // its termination in a structured way. The Promise resolves with an object
209
+ // describing how the child exited: either via exit code or due to a signal.
210
+ const childResult = await new Promise((resolve) => {
211
+ child.on("exit", (code, signal) => {
212
+ if (signal) {
213
+ resolve({ type: "signal", signal });
214
+ } else {
215
+ resolve({ type: "code", exitCode: code ?? 1 });
216
+ }
217
+ });
218
+ });
219
+
220
+ if (childResult.type === "signal") {
221
+ // Re-emit the same signal so that the parent terminates with the expected
222
+ // semantics (this also sets the correct exit code of 128 + n).
223
+ process.kill(process.pid, childResult.signal);
224
+ } else {
225
+ process.exit(childResult.exitCode);
226
+ }
package/bin/rg ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env dotslash
2
+
3
+ {
4
+ "name": "rg",
5
+ "platforms": {
6
+ "macos-aarch64": {
7
+ "size": 1777930,
8
+ "hash": "sha256",
9
+ "digest": "378e973289176ca0c6054054ee7f631a065874a352bf43f0fa60ef079b6ba715",
10
+ "format": "tar.gz",
11
+ "path": "ripgrep-15.1.0-aarch64-apple-darwin/rg",
12
+ "providers": [
13
+ {
14
+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.1.0/ripgrep-15.1.0-aarch64-apple-darwin.tar.gz"
15
+ }
16
+ ]
17
+ },
18
+ "linux-aarch64": {
19
+ "size": 1869959,
20
+ "hash": "sha256",
21
+ "digest": "2b661c6ef508e902f388e9098d9c4c5aca72c87b55922d94abdba830b4dc885e",
22
+ "format": "tar.gz",
23
+ "path": "ripgrep-15.1.0-aarch64-unknown-linux-gnu/rg",
24
+ "providers": [
25
+ {
26
+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.1.0/ripgrep-15.1.0-aarch64-unknown-linux-gnu.tar.gz"
27
+ }
28
+ ]
29
+ },
30
+ "macos-x86_64": {
31
+ "size": 1894127,
32
+ "hash": "sha256",
33
+ "digest": "64811cb24e77cac3057d6c40b63ac9becf9082eedd54ca411b475b755d334882",
34
+ "format": "tar.gz",
35
+ "path": "ripgrep-15.1.0-x86_64-apple-darwin/rg",
36
+ "providers": [
37
+ {
38
+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.1.0/ripgrep-15.1.0-x86_64-apple-darwin.tar.gz"
39
+ }
40
+ ]
41
+ },
42
+ "linux-x86_64": {
43
+ "size": 2263077,
44
+ "hash": "sha256",
45
+ "digest": "1c9297be4a084eea7ecaedf93eb03d058d6faae29bbc57ecdaf5063921491599",
46
+ "format": "tar.gz",
47
+ "path": "ripgrep-15.1.0-x86_64-unknown-linux-musl/rg",
48
+ "providers": [
49
+ {
50
+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.1.0/ripgrep-15.1.0-x86_64-unknown-linux-musl.tar.gz"
51
+ }
52
+ ]
53
+ },
54
+ "windows-x86_64": {
55
+ "size": 1810687,
56
+ "hash": "sha256",
57
+ "digest": "124510b94b6baa3380d051fdf4650eaa80a302c876d611e9dba0b2e18d87493a",
58
+ "format": "zip",
59
+ "path": "ripgrep-15.1.0-x86_64-pc-windows-msvc/rg.exe",
60
+ "providers": [
61
+ {
62
+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.1.0/ripgrep-15.1.0-x86_64-pc-windows-msvc.zip"
63
+ }
64
+ ]
65
+ },
66
+ "windows-aarch64": {
67
+ "size": 1675460,
68
+ "hash": "sha256",
69
+ "digest": "00d931fb5237c9696ca49308818edb76d8eb6fc132761cb2a1bd616b2df02f8e",
70
+ "format": "zip",
71
+ "path": "ripgrep-15.1.0-aarch64-pc-windows-msvc/rg.exe",
72
+ "providers": [
73
+ {
74
+ "url": "https://github.com/BurntSushi/ripgrep/releases/download/15.1.0/ripgrep-15.1.0-aarch64-pc-windows-msvc.zip"
75
+ }
76
+ ]
77
+ }
78
+ }
79
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@loongphy/codext",
3
+ "version": "0.111.0-ad42b61",
4
+ "license": "Apache-2.0",
5
+ "bin": {
6
+ "codext": "bin/codex.js"
7
+ },
8
+ "type": "module",
9
+ "engines": {
10
+ "node": ">=16"
11
+ },
12
+ "files": [
13
+ "bin"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Loongphy/codext.git",
18
+ "directory": "codex-cli"
19
+ },
20
+ "packageManager": "pnpm@10.29.3+sha512.498e1fb4cca5aa06c1dcf2611e6fafc50972ffe7189998c409e90de74566444298ffe43e6cd2acdc775ba1aa7cc5e092a8b7054c811ba8c5770f84693d33d2dc",
21
+ "optionalDependencies": {
22
+ "@openai/codex-linux-x64": "npm:@loongphy/codext@0.111.0-ad42b61-linux-x64",
23
+ "@openai/codex-darwin-arm64": "npm:@loongphy/codext@0.111.0-ad42b61-darwin-arm64",
24
+ "@openai/codex-win32-x64": "npm:@loongphy/codext@0.111.0-ad42b61-win32-x64"
25
+ }
26
+ }