codexuse-cli 5.0.8 → 5.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/dist/index.js CHANGED
@@ -2023,7 +2023,7 @@ var require_toml = __commonJS({
2023
2023
 
2024
2024
  // src/commands/accountPool.ts
2025
2025
  var import_node_crypto4 = require("crypto");
2026
- var import_node_path6 = __toESM(require("path"));
2026
+ var import_node_path7 = __toESM(require("path"));
2027
2027
 
2028
2028
  // ../../packages/contracts/src/settings/types.ts
2029
2029
  var DEFAULT_ACCOUNT_POOL_EXPOSED_MODELS = [
@@ -4862,7 +4862,7 @@ function parseRateLimitSnapshotFromOAuthUsage(value) {
4862
4862
  }
4863
4863
  return {
4864
4864
  lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
4865
- source: "codex-oauth",
4865
+ source: "codex-oauth-estimate",
4866
4866
  ...primary ? { primary } : {},
4867
4867
  ...secondary ? { secondary } : {},
4868
4868
  ...extraWindows.length > 0 ? { extraWindows } : {}
@@ -5291,6 +5291,120 @@ async function activateResetWindowViaRpc(envOverride, options = {}) {
5291
5291
  }
5292
5292
  }
5293
5293
 
5294
+ // ../../packages/runtime-profiles/src/profiles/rate-limit-cache.ts
5295
+ var import_node_fs4 = require("fs");
5296
+ var import_node_path6 = __toESM(require("path"), 1);
5297
+ var memorySnapshots = /* @__PURE__ */ new Map();
5298
+ var persistedSnapshotWriteLock = Promise.resolve();
5299
+ var RATE_LIMIT_SNAPSHOT_CACHE_FILE = "rate-limit-snapshots.json";
5300
+ function cloneSnapshot(snapshot) {
5301
+ return JSON.parse(JSON.stringify(snapshot));
5302
+ }
5303
+ function snapshotCachePath() {
5304
+ return import_node_path6.default.join(getUserDataDir(), RATE_LIMIT_SNAPSHOT_CACHE_FILE);
5305
+ }
5306
+ async function loadPersistedSnapshots() {
5307
+ let raw;
5308
+ try {
5309
+ raw = (await import_node_fs4.promises.readFile(snapshotCachePath(), "utf8")).trim();
5310
+ } catch {
5311
+ return /* @__PURE__ */ new Map();
5312
+ }
5313
+ if (!raw) {
5314
+ return /* @__PURE__ */ new Map();
5315
+ }
5316
+ try {
5317
+ const parsed = JSON.parse(raw);
5318
+ if (!parsed || typeof parsed !== "object") {
5319
+ return /* @__PURE__ */ new Map();
5320
+ }
5321
+ return new Map(
5322
+ Object.entries(parsed).flatMap(
5323
+ ([key, value]) => {
5324
+ if (!key || !value || typeof value !== "object") {
5325
+ return [];
5326
+ }
5327
+ const snapshot = value;
5328
+ if (typeof snapshot.lastUpdated !== "string") {
5329
+ return [];
5330
+ }
5331
+ return [[key, cloneSnapshot(snapshot)]];
5332
+ }
5333
+ )
5334
+ );
5335
+ } catch {
5336
+ return /* @__PURE__ */ new Map();
5337
+ }
5338
+ }
5339
+ async function writePersistedSnapshots(snapshots) {
5340
+ const filePath = snapshotCachePath();
5341
+ const tmpPath = `${filePath}.tmp`;
5342
+ const payload = JSON.stringify(
5343
+ Object.fromEntries(
5344
+ Array.from(snapshots.entries()).map(([key, snapshot]) => [
5345
+ key,
5346
+ cloneSnapshot(snapshot)
5347
+ ])
5348
+ ),
5349
+ null,
5350
+ 2
5351
+ );
5352
+ try {
5353
+ await import_node_fs4.promises.mkdir(import_node_path6.default.dirname(filePath), { recursive: true });
5354
+ await import_node_fs4.promises.writeFile(tmpPath, `${payload}
5355
+ `, "utf8");
5356
+ await import_node_fs4.promises.rename(tmpPath, filePath);
5357
+ } catch {
5358
+ try {
5359
+ await import_node_fs4.promises.rm(tmpPath, { force: true });
5360
+ } catch {
5361
+ }
5362
+ }
5363
+ }
5364
+ async function mutatePersistedSnapshots(mutate) {
5365
+ persistedSnapshotWriteLock = persistedSnapshotWriteLock.then(async () => {
5366
+ const persistedSnapshots = await loadPersistedSnapshots();
5367
+ if (!mutate(persistedSnapshots)) {
5368
+ return;
5369
+ }
5370
+ await writePersistedSnapshots(persistedSnapshots);
5371
+ });
5372
+ await persistedSnapshotWriteLock;
5373
+ }
5374
+ async function deleteRateLimitSnapshots(keys) {
5375
+ const snapshotKeys = Array.from(new Set(keys.map((key) => key.trim()).filter(Boolean)));
5376
+ if (snapshotKeys.length === 0) {
5377
+ return;
5378
+ }
5379
+ for (const key of snapshotKeys) {
5380
+ memorySnapshots.delete(key);
5381
+ }
5382
+ await mutatePersistedSnapshots((persistedSnapshots) => {
5383
+ let changed = false;
5384
+ for (const key of snapshotKeys) {
5385
+ changed = persistedSnapshots.delete(key) || changed;
5386
+ }
5387
+ return changed;
5388
+ });
5389
+ }
5390
+ async function pruneRateLimitSnapshots(allowedKeys) {
5391
+ const allowed = new Set(allowedKeys.map((key) => key.trim()).filter(Boolean));
5392
+ for (const key of Array.from(memorySnapshots.keys())) {
5393
+ if (!allowed.has(key)) {
5394
+ memorySnapshots.delete(key);
5395
+ }
5396
+ }
5397
+ await mutatePersistedSnapshots((persistedSnapshots) => {
5398
+ let changed = false;
5399
+ for (const key of Array.from(persistedSnapshots.keys())) {
5400
+ if (!allowed.has(key)) {
5401
+ changed = persistedSnapshots.delete(key) || changed;
5402
+ }
5403
+ }
5404
+ return changed;
5405
+ });
5406
+ }
5407
+
5294
5408
  // ../../packages/runtime-profiles/src/profiles/profile-manager.ts
5295
5409
  var TOKEN_EXPIRING_SOON_WINDOW_MS = 15 * 60 * 1e3;
5296
5410
  var REFRESH_TOKEN_REDEEMED_SNIPPET2 = "refresh token was already used";
@@ -5449,6 +5563,20 @@ var ProfileManager = class {
5449
5563
  delete map[name];
5450
5564
  await this.writeProfilesStateMap(map);
5451
5565
  }
5566
+ rateLimitSnapshotKeysForRecord(record) {
5567
+ return Array.from(
5568
+ /* @__PURE__ */ new Set([
5569
+ this.resolveProfileIdentityFromRecord(record),
5570
+ resolveFallbackAccountKey(record.name)
5571
+ ])
5572
+ );
5573
+ }
5574
+ rateLimitSnapshotKeysForStateMap(map) {
5575
+ return Object.entries(map).flatMap(([name, raw]) => {
5576
+ const record = this.fromStateRecord(name, raw);
5577
+ return record ? this.rateLimitSnapshotKeysForRecord(record) : [];
5578
+ });
5579
+ }
5452
5580
  resolveAuthMethod(data) {
5453
5581
  const raw = typeof data?.auth_method === "string" ? data.auth_method.trim().toLowerCase() : "";
5454
5582
  return raw || "codex-cli";
@@ -6179,6 +6307,7 @@ var ProfileManager = class {
6179
6307
  }
6180
6308
  async deleteProfileRecordAndHome(record) {
6181
6309
  const profileName = this.normalizeProfileName(record.name);
6310
+ const snapshotKeys = this.rateLimitSnapshotKeysForRecord(record);
6182
6311
  if (!record.accountId) {
6183
6312
  const dashboardState = await this.readProfileDashboardState();
6184
6313
  delete dashboardState.customGroupsByAccountKey[resolveFallbackAccountKey(profileName)];
@@ -6192,6 +6321,7 @@ var ProfileManager = class {
6192
6321
  }
6193
6322
  }
6194
6323
  await this.deleteProfileRecord(profileName);
6324
+ await deleteRateLimitSnapshots(snapshotKeys);
6195
6325
  }
6196
6326
  buildProfileFromData(name, data, fallback) {
6197
6327
  const metadata = fallback?.metadata ?? this.extractProfileMetadata(data);
@@ -6918,6 +7048,25 @@ var ProfileManager = class {
6918
7048
  });
6919
7049
  }
6920
7050
  }
7051
+ async readConfirmedRateLimits(name, options = {}) {
7052
+ const profileName = this.normalizeProfileName(name);
7053
+ try {
7054
+ return await this.enqueueProfileOperation(
7055
+ profileName,
7056
+ () => this.runWithPreparedProfileHome(
7057
+ profileName,
7058
+ (env) => fetchRateLimitsViaRpc(env, { codexPath: options.codexPath }),
7059
+ { syncFromActiveAuthBeforeAction: false }
7060
+ )
7061
+ );
7062
+ } finally {
7063
+ await this.enqueueAuthSwap(async () => {
7064
+ await this.syncActiveAuthFromProfileIfCurrent(profileName);
7065
+ }).catch((error) => {
7066
+ logWarn(`Failed to sync active auth after rate-limit confirmation for '${profileName}':`, error);
7067
+ });
7068
+ }
7069
+ }
6921
7070
  async activateResetWindow(name, options = {}) {
6922
7071
  const profileName = this.normalizeProfileName(name);
6923
7072
  try {
@@ -7105,6 +7254,7 @@ var ProfileManager = class {
7105
7254
  }
7106
7255
  if (removed.length > 0) {
7107
7256
  await this.writeProfilesStateMap(nextMap);
7257
+ await pruneRateLimitSnapshots(this.rateLimitSnapshotKeysForStateMap(nextMap));
7108
7258
  }
7109
7259
  return removed;
7110
7260
  }
@@ -7247,6 +7397,7 @@ var ProfileManager = class {
7247
7397
  nextMap[record.name] = this.toStateRecord(record);
7248
7398
  }
7249
7399
  await this.writeProfilesStateMap(nextMap);
7400
+ await pruneRateLimitSnapshots(this.rateLimitSnapshotKeysForStateMap(nextMap));
7250
7401
  let removed = 0;
7251
7402
  for (const name of existingNames) {
7252
7403
  if (normalized.has(name)) {
@@ -7720,7 +7871,7 @@ function pruneStore(store) {
7720
7871
  return store;
7721
7872
  }
7722
7873
  function resolveAccountPoolDbPath(stateDir) {
7723
- return import_node_path6.default.join(stateDir, "state.sqlite");
7874
+ return import_node_path7.default.join(stateDir, "state.sqlite");
7724
7875
  }
7725
7876
  async function readStore(stateDir) {
7726
7877
  const dbPath = resolveAccountPoolDbPath(stateDir);
@@ -7823,9 +7974,9 @@ async function listSessions(stateDir) {
7823
7974
  }
7824
7975
  function resolveRuntimeStateDir(runtime, explicitStateDir) {
7825
7976
  if (explicitStateDir) {
7826
- return import_node_path6.default.resolve(explicitStateDir);
7977
+ return import_node_path7.default.resolve(explicitStateDir);
7827
7978
  }
7828
- return import_node_path6.default.join(getUserDataDir(), DESKTOP_RPC_STATE_DIR);
7979
+ return import_node_path7.default.join(getUserDataDir(), DESKTOP_RPC_STATE_DIR);
7829
7980
  }
7830
7981
  function resolveStateDir(flags) {
7831
7982
  const runtimeFlag = parseStringFlag(flags, "--runtime")?.trim().toLowerCase();
@@ -8282,8 +8433,7 @@ function maxUsedPercent(snapshot) {
8282
8433
  }
8283
8434
  const candidates = [
8284
8435
  snapshot.primary?.usedPercent,
8285
- snapshot.secondary?.usedPercent,
8286
- ...(snapshot.extraWindows ?? []).map((window) => window.usedPercent)
8436
+ snapshot.secondary?.usedPercent
8287
8437
  ].filter((value) => typeof value === "number" && Number.isFinite(value));
8288
8438
  if (candidates.length === 0) {
8289
8439
  return null;
@@ -8293,14 +8443,14 @@ function maxUsedPercent(snapshot) {
8293
8443
 
8294
8444
  // src/platform/codexCli.ts
8295
8445
  var import_node_child_process3 = require("child_process");
8296
- var import_node_fs4 = require("fs");
8297
- var import_node_path7 = __toESM(require("path"));
8446
+ var import_node_fs5 = require("fs");
8447
+ var import_node_path8 = __toESM(require("path"));
8298
8448
  var ENV_HINTS2 = ["CODEX_BINARY", "CODEX_CLI_PATH", "CODEX_PATH"];
8299
8449
  function fileExists2(candidate) {
8300
8450
  if (!candidate) return null;
8301
- const resolved = import_node_path7.default.resolve(candidate);
8451
+ const resolved = import_node_path8.default.resolve(candidate);
8302
8452
  try {
8303
- const stat2 = (0, import_node_fs4.statSync)(resolved);
8453
+ const stat2 = (0, import_node_fs5.statSync)(resolved);
8304
8454
  if (stat2.isFile()) return resolved;
8305
8455
  } catch {
8306
8456
  return null;
@@ -8318,9 +8468,9 @@ function resolveFromEnv() {
8318
8468
  }
8319
8469
  function resolveFromPath() {
8320
8470
  const pathValue = process.env.PATH ?? "";
8321
- const entries = pathValue.split(import_node_path7.default.delimiter).filter(Boolean);
8471
+ const entries = pathValue.split(import_node_path8.default.delimiter).filter(Boolean);
8322
8472
  for (const entry of entries) {
8323
- const candidate = fileExists2(import_node_path7.default.join(entry, "codex"));
8473
+ const candidate = fileExists2(import_node_path8.default.join(entry, "codex"));
8324
8474
  if (candidate) return candidate;
8325
8475
  }
8326
8476
  return null;
@@ -8412,8 +8562,7 @@ function formatUsagePercent(value) {
8412
8562
  function snapshotResetSeconds(snapshot) {
8413
8563
  const values = [
8414
8564
  snapshot?.primary?.resetsInSeconds,
8415
- snapshot?.secondary?.resetsInSeconds,
8416
- ...(snapshot?.extraWindows ?? []).map((window) => window.resetsInSeconds)
8565
+ snapshot?.secondary?.resetsInSeconds
8417
8566
  ].filter((value) => typeof value === "number" && Number.isFinite(value));
8418
8567
  return values.length > 0 ? Math.min(...values) : null;
8419
8568
  }
@@ -8698,14 +8847,14 @@ async function assertProfileCreationAllowed(profileManager) {
8698
8847
  // ../../packages/runtime-codex/src/codex/officialAppRestart.ts
8699
8848
  var import_node_child_process5 = require("child_process");
8700
8849
  var import_node_crypto5 = require("crypto");
8701
- var import_node_fs6 = require("fs");
8850
+ var import_node_fs7 = require("fs");
8702
8851
  var import_node_os3 = require("os");
8703
8852
  var import_node_net = __toESM(require("net"), 1);
8704
- var import_node_path9 = __toESM(require("path"), 1);
8853
+ var import_node_path10 = __toESM(require("path"), 1);
8705
8854
 
8706
8855
  // ../../packages/runtime-codex/src/codex/threadUsage.ts
8707
- var import_node_fs5 = require("fs");
8708
- var import_node_path8 = __toESM(require("path"), 1);
8856
+ var import_node_fs6 = require("fs");
8857
+ var import_node_path9 = __toESM(require("path"), 1);
8709
8858
  var ROLLOUT_DIRS = ["sessions", "archived_sessions"];
8710
8859
  function isRecord5(value) {
8711
8860
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
@@ -8715,7 +8864,7 @@ async function collectRolloutFiles(root) {
8715
8864
  async function visit(dir) {
8716
8865
  let entries;
8717
8866
  try {
8718
- entries = await import_node_fs5.promises.readdir(dir, {
8867
+ entries = await import_node_fs6.promises.readdir(dir, {
8719
8868
  withFileTypes: true,
8720
8869
  encoding: "utf8"
8721
8870
  });
@@ -8725,7 +8874,7 @@ async function collectRolloutFiles(root) {
8725
8874
  const childVisits = [];
8726
8875
  for (const entry of entries) {
8727
8876
  const entryName = String(entry.name);
8728
- const entryPath = import_node_path8.default.join(dir, entryName);
8877
+ const entryPath = import_node_path9.default.join(dir, entryName);
8729
8878
  if (entry.isDirectory()) {
8730
8879
  childVisits.push(visit(entryPath));
8731
8880
  continue;
@@ -8744,14 +8893,14 @@ async function findRolloutFileByScan(profileHome, threadId) {
8744
8893
  let best = null;
8745
8894
  const variants = threadIdVariants(threadId);
8746
8895
  for (const dirname of ROLLOUT_DIRS) {
8747
- const root = import_node_path8.default.join(profileHome, dirname);
8896
+ const root = import_node_path9.default.join(profileHome, dirname);
8748
8897
  const files = await collectRolloutFiles(root);
8749
8898
  for (const file of files) {
8750
- const basename = import_node_path8.default.basename(file);
8899
+ const basename = import_node_path9.default.basename(file);
8751
8900
  if (!variants.some((variant) => basename.includes(variant))) {
8752
8901
  continue;
8753
8902
  }
8754
- const stat2 = await import_node_fs5.promises.stat(file).catch(() => null);
8903
+ const stat2 = await import_node_fs6.promises.stat(file).catch(() => null);
8755
8904
  const updatedAtMs = stat2 && Number.isFinite(stat2.mtimeMs) ? stat2.mtimeMs : null;
8756
8905
  if (!best || (updatedAtMs ?? 0) > (best.updatedAtMs ?? 0) || (updatedAtMs ?? 0) === (best.updatedAtMs ?? 0) && file > best.path) {
8757
8906
  best = { path: file, updatedAtMs };
@@ -8823,12 +8972,12 @@ function resolveRolloutPath(profileHome, rolloutPath) {
8823
8972
  if (!rolloutPath) {
8824
8973
  return null;
8825
8974
  }
8826
- return import_node_path8.default.isAbsolute(rolloutPath) ? rolloutPath : import_node_path8.default.join(profileHome, rolloutPath);
8975
+ return import_node_path9.default.isAbsolute(rolloutPath) ? rolloutPath : import_node_path9.default.join(profileHome, rolloutPath);
8827
8976
  }
8828
8977
  async function readThreadRecordFromStateDb(profileHome, threadId) {
8829
- const dbPath = import_node_path8.default.join(profileHome, "state_5.sqlite");
8978
+ const dbPath = import_node_path9.default.join(profileHome, "state_5.sqlite");
8830
8979
  try {
8831
- await import_node_fs5.promises.access(dbPath);
8980
+ await import_node_fs6.promises.access(dbPath);
8832
8981
  } catch {
8833
8982
  return null;
8834
8983
  }
@@ -12935,18 +13084,18 @@ function startOfficialCodexBridgeActionListener(args) {
12935
13084
  if (!requestId || !rememberBridgeActionId(requestId)) {
12936
13085
  return;
12937
13086
  }
12938
- const path14 = typeof payload.path === "string" ? payload.path.trim().slice(0, 64) : "";
13087
+ const path15 = typeof payload.path === "string" ? payload.path.trim().slice(0, 64) : "";
12939
13088
  const requestHandler = officialCodexBridgeRequestHandler;
12940
13089
  void (async () => {
12941
13090
  let result;
12942
- if (!path14) {
13091
+ if (!path15) {
12943
13092
  result = { status: "failed", reason: "missing-path" };
12944
13093
  } else if (!requestHandler) {
12945
13094
  result = { status: "failed", reason: "no-request-handler" };
12946
13095
  } else {
12947
13096
  try {
12948
13097
  result = await requestHandler({
12949
- path: path14,
13098
+ path: path15,
12950
13099
  payload: payload.payload ?? null,
12951
13100
  sourceProfileName: profileName
12952
13101
  });
@@ -13364,7 +13513,7 @@ async function readProcessRows() {
13364
13513
  });
13365
13514
  }
13366
13515
  function getMainExecutablePath(candidate) {
13367
- return import_node_path9.default.join(candidate.appPath, "Contents", "MacOS", candidate.executableName);
13516
+ return import_node_path10.default.join(candidate.appPath, "Contents", "MacOS", candidate.executableName);
13368
13517
  }
13369
13518
  function isMainProcessRow(row, candidate) {
13370
13519
  return row.args.includes(getMainExecutablePath(candidate));
@@ -13586,15 +13735,15 @@ function classifyOpenCodexLaunchFailure(error) {
13586
13735
  }
13587
13736
  async function openCodexWithProfileHome(candidate, profileHome, profileName, cdpPort, previousPids, options = {}) {
13588
13737
  const executablePath = getMainExecutablePath(candidate);
13589
- if (!(0, import_node_fs6.existsSync)(executablePath)) {
13738
+ if (!(0, import_node_fs7.existsSync)(executablePath)) {
13590
13739
  return { opened: false, pid: null, reason: "app-executable-missing" };
13591
13740
  }
13592
13741
  const telemetryLabel = `codexuse-profile-${encodeURIComponent(profileName)}`;
13593
- const appUserDataDir = options.useDefaultUserData === false ? import_node_path9.default.join(profileHome, "codex-app-user-data") : null;
13742
+ const appUserDataDir = options.useDefaultUserData === false ? import_node_path10.default.join(profileHome, "codex-app-user-data") : null;
13594
13743
  let child;
13595
13744
  try {
13596
13745
  if (appUserDataDir) {
13597
- (0, import_node_fs6.mkdirSync)(appUserDataDir, { recursive: true });
13746
+ (0, import_node_fs7.mkdirSync)(appUserDataDir, { recursive: true });
13598
13747
  }
13599
13748
  child = (0, import_node_child_process5.spawn)(
13600
13749
  "/usr/bin/open",
@@ -13652,8 +13801,8 @@ async function openCodexWithProfileHome(candidate, profileHome, profileName, cdp
13652
13801
  };
13653
13802
  }
13654
13803
  async function readBundleString(appPath, key) {
13655
- const plistPath = import_node_path9.default.join(appPath, "Contents", "Info.plist");
13656
- if (!(0, import_node_fs6.existsSync)(plistPath)) {
13804
+ const plistPath = import_node_path10.default.join(appPath, "Contents", "Info.plist");
13805
+ if (!(0, import_node_fs7.existsSync)(plistPath)) {
13657
13806
  return null;
13658
13807
  }
13659
13808
  const result = await runCommand2("/usr/bin/plutil", [
@@ -13673,7 +13822,7 @@ async function readBundleString(appPath, key) {
13673
13822
  async function collectCodexAppCandidates(rawPaths) {
13674
13823
  const candidates = [];
13675
13824
  for (const appPath of rawPaths) {
13676
- if (!(0, import_node_fs6.existsSync)(appPath) || import_node_path9.default.basename(appPath) !== "Codex.app") {
13825
+ if (!(0, import_node_fs7.existsSync)(appPath) || import_node_path10.default.basename(appPath) !== "Codex.app") {
13677
13826
  continue;
13678
13827
  }
13679
13828
  const bundleId = await readBundleString(appPath, "CFBundleIdentifier");
@@ -13690,7 +13839,7 @@ async function collectCodexAppCandidates(rawPaths) {
13690
13839
  return candidates.sort((a, b) => a.appPath.localeCompare(b.appPath));
13691
13840
  }
13692
13841
  function addCodexAppPathsFromDirectory(rawPaths, rootPath, maxDepth = 2) {
13693
- if (!(0, import_node_fs6.existsSync)(rootPath)) {
13842
+ if (!(0, import_node_fs7.existsSync)(rootPath)) {
13694
13843
  return;
13695
13844
  }
13696
13845
  const pending = [{ directory: rootPath, depth: 0 }];
@@ -13698,7 +13847,7 @@ function addCodexAppPathsFromDirectory(rawPaths, rootPath, maxDepth = 2) {
13698
13847
  const current = pending.shift();
13699
13848
  let entries;
13700
13849
  try {
13701
- entries = (0, import_node_fs6.readdirSync)(current.directory, { withFileTypes: true });
13850
+ entries = (0, import_node_fs7.readdirSync)(current.directory, { withFileTypes: true });
13702
13851
  } catch {
13703
13852
  continue;
13704
13853
  }
@@ -13706,7 +13855,7 @@ function addCodexAppPathsFromDirectory(rawPaths, rootPath, maxDepth = 2) {
13706
13855
  if (!entry.isDirectory()) {
13707
13856
  continue;
13708
13857
  }
13709
- const childPath = import_node_path9.default.join(current.directory, entry.name);
13858
+ const childPath = import_node_path10.default.join(current.directory, entry.name);
13710
13859
  if (entry.name === "Codex.app") {
13711
13860
  rawPaths.add(childPath);
13712
13861
  continue;
@@ -13729,9 +13878,9 @@ async function discoverCodexAppCandidates() {
13729
13878
  rawPaths.add(envPath);
13730
13879
  }
13731
13880
  rawPaths.add("/Applications/Codex.app");
13732
- rawPaths.add(import_node_path9.default.join((0, import_node_os3.homedir)(), "Applications", "Codex.app"));
13881
+ rawPaths.add(import_node_path10.default.join((0, import_node_os3.homedir)(), "Applications", "Codex.app"));
13733
13882
  addCodexAppPathsFromDirectory(rawPaths, "/Applications");
13734
- addCodexAppPathsFromDirectory(rawPaths, import_node_path9.default.join((0, import_node_os3.homedir)(), "Applications"));
13883
+ addCodexAppPathsFromDirectory(rawPaths, import_node_path10.default.join((0, import_node_os3.homedir)(), "Applications"));
13735
13884
  const sorted = await collectCodexAppCandidates(rawPaths);
13736
13885
  appDiscoveryCache = {
13737
13886
  envPath,
@@ -13742,7 +13891,7 @@ async function discoverCodexAppCandidates() {
13742
13891
  }
13743
13892
  function getRunningCodexPidsFromRows(candidate, rows) {
13744
13893
  const pids = /* @__PURE__ */ new Set();
13745
- const appContentsRoot = `${import_node_path9.default.join(candidate.appPath, "Contents")}${import_node_path9.default.sep}`;
13894
+ const appContentsRoot = `${import_node_path10.default.join(candidate.appPath, "Contents")}${import_node_path10.default.sep}`;
13746
13895
  for (const row of rows) {
13747
13896
  if (row.args.includes(appContentsRoot)) {
13748
13897
  pids.add(row.pid);
@@ -13752,7 +13901,7 @@ function getRunningCodexPidsFromRows(candidate, rows) {
13752
13901
  }
13753
13902
  function getRunningCodexMainPidsFromRows(candidate, rows) {
13754
13903
  const pids = /* @__PURE__ */ new Set();
13755
- const executablePath = import_node_path9.default.join(
13904
+ const executablePath = import_node_path10.default.join(
13756
13905
  candidate.appPath,
13757
13906
  "Contents",
13758
13907
  "MacOS",
@@ -13783,7 +13932,7 @@ async function resolveCodexAppTarget() {
13783
13932
  const mainPids = getRunningCodexMainPidsFromRows(fallback, rows);
13784
13933
  return { candidate: fallback, runningPids, mainPids };
13785
13934
  }
13786
- var SHARED_CODEX_HOME = import_node_path9.default.join((0, import_node_os3.homedir)(), ".codex");
13935
+ var SHARED_CODEX_HOME = import_node_path10.default.join((0, import_node_os3.homedir)(), ".codex");
13787
13936
  function toIso(value) {
13788
13937
  return typeof value === "number" && Number.isFinite(value) ? new Date(value).toISOString() : null;
13789
13938
  }
@@ -15544,7 +15693,7 @@ var import_toml3 = __toESM(require_toml(), 1);
15544
15693
  // ../../packages/runtime-codex/src/codex/config-metadata.ts
15545
15694
  var import_node_child_process6 = require("child_process");
15546
15695
  var import_promises = require("fs/promises");
15547
- var import_node_path10 = __toESM(require("path"), 1);
15696
+ var import_node_path11 = __toESM(require("path"), 1);
15548
15697
  var CONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/openai/codex/main/codex-rs/core/config.schema.json";
15549
15698
  var METADATA_CACHE_TTL_MS = 6e4;
15550
15699
  var FALLBACK_SCHEMA_TOP_LEVEL_KEYS = [
@@ -15730,8 +15879,8 @@ function parseSchemaKeys(schemaRaw) {
15730
15879
  async function readSchemaFromLocal() {
15731
15880
  const candidates = [
15732
15881
  process.env.CODEX_CONFIG_SCHEMA_PATH,
15733
- import_node_path10.default.join(process.cwd(), "codex-rs", "core", "config.schema.json"),
15734
- import_node_path10.default.join(process.cwd(), "node_modules", "@openai", "codex", "codex-rs", "core", "config.schema.json")
15882
+ import_node_path11.default.join(process.cwd(), "codex-rs", "core", "config.schema.json"),
15883
+ import_node_path11.default.join(process.cwd(), "node_modules", "@openai", "codex", "codex-rs", "core", "config.schema.json")
15735
15884
  ].filter((candidate) => Boolean(candidate));
15736
15885
  for (const candidate of candidates) {
15737
15886
  try {
@@ -15836,11 +15985,11 @@ async function getCodexConfigMetadata(forceRefresh = false) {
15836
15985
 
15837
15986
  // ../../packages/runtime-codex/src/codex/config-io.ts
15838
15987
  var import_promises2 = require("fs/promises");
15839
- var import_node_path12 = __toESM(require("path"), 1);
15988
+ var import_node_path13 = __toESM(require("path"), 1);
15840
15989
 
15841
15990
  // ../../packages/runtime-codex/src/codex/home.ts
15842
15991
  var import_node_os4 = __toESM(require("os"), 1);
15843
- var import_node_path11 = __toESM(require("path"), 1);
15992
+ var import_node_path12 = __toESM(require("path"), 1);
15844
15993
  function resolveHomeDir() {
15845
15994
  return process.env.HOME || import_node_os4.default.homedir();
15846
15995
  }
@@ -15849,7 +15998,7 @@ function expandHomePrefix(input, homeDir) {
15849
15998
  return homeDir;
15850
15999
  }
15851
16000
  if (input.startsWith("~/") || input.startsWith("~\\")) {
15852
- return import_node_path11.default.join(homeDir, input.slice(2));
16001
+ return import_node_path12.default.join(homeDir, input.slice(2));
15853
16002
  }
15854
16003
  return input;
15855
16004
  }
@@ -15865,10 +16014,10 @@ function normalizeCodexHomePath(input) {
15865
16014
  if (!configured) {
15866
16015
  return null;
15867
16016
  }
15868
- return import_node_path11.default.resolve(expandHomePrefix(configured, resolveHomeDir()));
16017
+ return import_node_path12.default.resolve(expandHomePrefix(configured, resolveHomeDir()));
15869
16018
  }
15870
16019
  function resolveDefaultCodexHomeDir() {
15871
- return import_node_path11.default.join(resolveHomeDir(), ".codex");
16020
+ return import_node_path12.default.join(resolveHomeDir(), ".codex");
15872
16021
  }
15873
16022
  function resolveCodexHomeDir(options) {
15874
16023
  return normalizeCodexHomePath(options?.codexHomePath) ?? resolveDefaultCodexHomeDir();
@@ -15941,10 +16090,10 @@ var YOLO_PRESET = {
15941
16090
 
15942
16091
  // ../../packages/runtime-codex/src/codex/config-io.ts
15943
16092
  function getConfigPath(options) {
15944
- return import_node_path12.default.join(resolveCodexHomeDir(options), "config.toml");
16093
+ return import_node_path13.default.join(resolveCodexHomeDir(options), "config.toml");
15945
16094
  }
15946
16095
  async function ensureConfigDirExists(filePath) {
15947
- const dir = import_node_path12.default.dirname(filePath);
16096
+ const dir = import_node_path13.default.dirname(filePath);
15948
16097
  await (0, import_promises2.mkdir)(dir, { recursive: true });
15949
16098
  }
15950
16099
  function normalizeLineEndings(content) {
@@ -17103,7 +17252,7 @@ async function ensureCliStorageReady() {
17103
17252
  }
17104
17253
 
17105
17254
  // src/app/main.ts
17106
- var VERSION = true ? "5.0.8" : "0.0.0";
17255
+ var VERSION = true ? "5.1.0" : "0.0.0";
17107
17256
  async function runCli() {
17108
17257
  const args = process.argv.slice(2);
17109
17258
  if (args.length === 0) {