@rickgetz/codex 0.150.1-rick.4 → 0.153.0-rick.1

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/codex.js +53 -9
  2. package/package.json +2 -2
package/bin/codex.js CHANGED
@@ -25,6 +25,7 @@ const rootPackageJson = JSON.parse(
25
25
  readFileSync(path.join(__dirname, "..", "package.json"), "utf8"),
26
26
  );
27
27
  const rootPackageName = rootPackageJson.name || "@rickgetz/codex";
28
+ const rootPackagePath = rootPackageName.split("/");
28
29
 
29
30
  function packageAliasName(basePackageName, suffix) {
30
31
  if (basePackageName.startsWith("@")) {
@@ -114,7 +115,9 @@ function findCodexExecutable() {
114
115
  ? `bun install -g ${rootPackageName}@latest`
115
116
  : packageManager === "pnpm"
116
117
  ? `pnpm add -g ${rootPackageName}@latest`
117
- : `npm install -g ${rootPackageName}@latest`;
118
+ : packageManager === "vite-plus"
119
+ ? `vp install -g ${rootPackageName}@latest`
120
+ : `npm install -g ${rootPackageName}@latest`;
118
121
  throw new Error(
119
122
  `Missing optional dependency ${platformPackage}. Reinstall Codex: ${updateCommand}`,
120
123
  );
@@ -134,23 +137,58 @@ function isPnpmOwnedCodexInstall(nodeModulesDir) {
134
137
  }
135
138
 
136
139
  try {
137
- return (
138
- realpathSync(path.join(nodeModulesDir, "@openai", "codex")) ===
139
- codexPackageRoot
140
- );
140
+ return realpathSync(path.join(nodeModulesDir, ...rootPackagePath)) === codexPackageRoot;
141
141
  } catch {
142
142
  return false;
143
143
  }
144
144
  }
145
145
 
146
+ function isVitePlusOwnedCodexInstall(packagesDir) {
147
+ if (path.basename(packagesDir) !== "packages") {
148
+ return false;
149
+ }
150
+
151
+ try {
152
+ const metadata = JSON.parse(
153
+ readFileSync(path.join(packagesDir, `${rootPackageName}.json`), "utf8"),
154
+ );
155
+ if (metadata.name !== rootPackageName) {
156
+ return false;
157
+ }
158
+
159
+ // Vite+ records the active global installation in packages/<package-name>.json.
160
+ // Older installs have no ID or append a #-prefixed ID to the package name;
161
+ // newer installs put the ID in a subdirectory of the package prefix.
162
+ const installId = metadata.installId || "";
163
+ const installDir = installId.startsWith("#")
164
+ ? path.join(packagesDir, `${rootPackageName}${installId}`)
165
+ : path.join(packagesDir, rootPackageName, installId);
166
+ for (const nodeModulesDir of [
167
+ path.join(installDir, "lib", "node_modules"),
168
+ path.join(installDir, "node_modules"),
169
+ ]) {
170
+ const packageRoot = path.join(nodeModulesDir, ...rootPackagePath);
171
+ if (
172
+ existsSync(packageRoot) &&
173
+ realpathSync(packageRoot) === codexPackageRoot
174
+ ) {
175
+ return true;
176
+ }
177
+ }
178
+ } catch {
179
+ // Missing or unreadable ownership metadata must not prevent Codex starting.
180
+ }
181
+ return false;
182
+ }
183
+
146
184
  /**
147
185
  * Use heuristics to detect the package manager that was used to install Codex
148
186
  * in order to give the user a hint about how to update it.
149
187
  */
150
188
  function detectPackageManager() {
151
- // pnpm's owning node_modules directory can be several parents above the
152
- // package in isolated global layouts. Search ancestors of both the canonical
153
- // package root and lexical entrypoint because pnpm may link either path.
189
+ // Package-manager ownership metadata can be several parents above the package.
190
+ // Search ancestors of both the canonical package root and lexical entrypoint
191
+ // because the package manager may link either path.
154
192
  const entrypointDir = path.dirname(path.resolve(process.argv[1]));
155
193
  for (const startDir of new Set([codexPackageRoot, entrypointDir])) {
156
194
  const filesystemRoot = path.parse(startDir).root;
@@ -159,6 +197,9 @@ function detectPackageManager() {
159
197
  currentDir !== filesystemRoot;
160
198
  currentDir = path.dirname(currentDir)
161
199
  ) {
200
+ if (isVitePlusOwnedCodexInstall(currentDir)) {
201
+ return "vite-plus";
202
+ }
162
203
  if (isPnpmOwnedCodexInstall(path.join(currentDir, "node_modules"))) {
163
204
  return "pnpm";
164
205
  }
@@ -195,7 +236,9 @@ const packageManagerEnvVar =
195
236
  ? "CODEX_MANAGED_BY_BUN"
196
237
  : packageManager === "pnpm"
197
238
  ? "CODEX_MANAGED_BY_PNPM"
198
- : "CODEX_MANAGED_BY_NPM";
239
+ : packageManager === "vite-plus"
240
+ ? "CODEX_MANAGED_BY_VITE_PLUS"
241
+ : "CODEX_MANAGED_BY_NPM";
199
242
  const env = {
200
243
  ...process.env,
201
244
  CODEX_MANAGED_PACKAGE_ROOT: codexPackageRoot,
@@ -203,6 +246,7 @@ const env = {
203
246
  delete env.CODEX_MANAGED_BY_NPM;
204
247
  delete env.CODEX_MANAGED_BY_BUN;
205
248
  delete env.CODEX_MANAGED_BY_PNPM;
249
+ delete env.CODEX_MANAGED_BY_VITE_PLUS;
206
250
  env[packageManagerEnvVar] = "1";
207
251
 
208
252
  const child = spawn(binaryPath, process.argv.slice(2), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickgetz/codex",
3
- "version": "0.150.1-rick.4",
3
+ "version": "0.153.0-rick.1",
4
4
  "description": "Codex CLI is a coding agent from OpenAI that runs locally on your computer.",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -20,6 +20,6 @@
20
20
  },
21
21
  "packageManager": "pnpm@10.34.5+sha512.a4ee05f2f73658255bd6a89859c065a45c28a57daefae2c893a168ee2b73168c37b91e83e57ea67654ad03f03031746430e8bce38e362e042605fb8abc80192e",
22
22
  "optionalDependencies": {
23
- "@rickgetz/codex-darwin-arm64": "npm:@rickgetz/codex@0.150.1-rick.4-darwin-arm64"
23
+ "@rickgetz/codex-darwin-arm64": "npm:@rickgetz/codex@0.153.0-rick.1-darwin-arm64"
24
24
  }
25
25
  }