codexuse-cli 6.0.0 → 6.0.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.
package/dist/index.js CHANGED
@@ -5661,10 +5661,15 @@ function resolveProfileCodexHomeDir(profileHomeId) {
5661
5661
  const currentExists = (0, import_node_fs3.existsSync)(current);
5662
5662
  const legacyExists = (0, import_node_fs3.existsSync)(legacy);
5663
5663
  if (currentExists && legacyExists) {
5664
- throw new Error("profile-home-location-conflict");
5664
+ return current;
5665
5665
  }
5666
5666
  return legacyExists ? legacy : current;
5667
5667
  }
5668
+ function findProfileCodexHomeLocationConflict(profileHomeId) {
5669
+ const current = resolveCurrentProfileCodexHomeDir(profileHomeId);
5670
+ const legacy = import_node_path5.default.join(resolveLegacyProfileCodexHomesRoot(), profileHomeId);
5671
+ return (0, import_node_fs3.existsSync)(current) && (0, import_node_fs3.existsSync)(legacy) ? { current, legacy } : null;
5672
+ }
5668
5673
  function resolveProfileCodexHomesRoot() {
5669
5674
  return import_node_path5.default.join(resolveHomeDir(), ".codexuse", "p");
5670
5675
  }
@@ -5688,7 +5693,7 @@ async function migrateProfileCodexHomeDir(profileHomeId) {
5688
5693
  const currentExists = (0, import_node_fs3.existsSync)(current);
5689
5694
  const legacyExists = (0, import_node_fs3.existsSync)(legacy);
5690
5695
  if (currentExists && legacyExists) {
5691
- throw new Error("profile-home-location-conflict");
5696
+ return current;
5692
5697
  }
5693
5698
  if (currentExists || !legacyExists) {
5694
5699
  return current;
@@ -36330,6 +36335,7 @@ var ProfileManager = class {
36330
36335
  }
36331
36336
  async migrateCredentialsToProfileHomes() {
36332
36337
  const source = await this.readProfilesStateSource();
36338
+ await this.reconcileProfileHomeLocationConflicts(source);
36333
36339
  const homeIdsByProfileName = /* @__PURE__ */ new Map();
36334
36340
  const profileNamesByHomeId = /* @__PURE__ */ new Map();
36335
36341
  for (const [profileName, raw] of Object.entries(source)) {
@@ -36471,6 +36477,74 @@ var ProfileManager = class {
36471
36477
  );
36472
36478
  }
36473
36479
  }
36480
+ async reconcileProfileHomeLocationConflicts(source) {
36481
+ for (const [profileName, raw] of Object.entries(source)) {
36482
+ const record2 = this.fromStateRecord(profileName, raw);
36483
+ if (!record2) {
36484
+ continue;
36485
+ }
36486
+ const conflict = findProfileCodexHomeLocationConflict(record2.homeId);
36487
+ if (!conflict) {
36488
+ continue;
36489
+ }
36490
+ const currentAuthPath = (0, import_path2.join)(conflict.current, "auth.json");
36491
+ const legacyAuthPath = (0, import_path2.join)(conflict.legacy, "auth.json");
36492
+ try {
36493
+ await this.withProfileAuthFileLock(currentAuthPath, async (currentRaw) => {
36494
+ await this.withProfileAuthFileLock(legacyAuthPath, async (legacyRaw) => {
36495
+ if (!legacyRaw?.trim()) {
36496
+ return;
36497
+ }
36498
+ let legacyAuth;
36499
+ try {
36500
+ legacyAuth = JSON.parse(legacyRaw);
36501
+ } catch (error) {
36502
+ throw errorWithCause("Legacy profile auth is invalid.", error);
36503
+ }
36504
+ if (!this.activeAuthMatchesRecord(legacyAuth, record2)) {
36505
+ throw new Error("Legacy profile auth has a different identity.");
36506
+ }
36507
+ if (!currentRaw?.trim()) {
36508
+ await this.replaceProfileAuthPathIfCurrent(
36509
+ currentAuthPath,
36510
+ currentRaw,
36511
+ legacyRaw
36512
+ );
36513
+ return;
36514
+ }
36515
+ let currentAuth;
36516
+ try {
36517
+ currentAuth = JSON.parse(currentRaw);
36518
+ } catch (error) {
36519
+ throw errorWithCause("Current profile auth is invalid.", error);
36520
+ }
36521
+ if (!this.activeAuthMatchesRecord(currentAuth, record2)) {
36522
+ throw new Error("Current profile auth has a different identity.");
36523
+ }
36524
+ const currentRecency = this.getProfileTokenRecencyMs(
36525
+ this.normalizeProfileData(currentAuth)
36526
+ );
36527
+ const legacyRecency = this.getProfileTokenRecencyMs(
36528
+ this.normalizeProfileData(legacyAuth)
36529
+ );
36530
+ if (typeof legacyRecency !== "number" || typeof currentRecency === "number" && legacyRecency <= currentRecency) {
36531
+ return;
36532
+ }
36533
+ await this.replaceProfileAuthPathIfCurrent(
36534
+ currentAuthPath,
36535
+ currentRaw,
36536
+ legacyRaw
36537
+ );
36538
+ });
36539
+ });
36540
+ } catch (error) {
36541
+ logWarn(
36542
+ `Could not reconcile the upgrade profile home for '${profileName}':`,
36543
+ error
36544
+ );
36545
+ }
36546
+ }
36547
+ }
36474
36548
  enqueueAuthSwap(task) {
36475
36549
  const run2 = globalAuthSwapLock.then(task, task);
36476
36550
  globalAuthSwapLock = run2.then(
@@ -37107,7 +37181,13 @@ var ProfileManager = class {
37107
37181
  if (migrationError) {
37108
37182
  return { record: record2, cacheable: false };
37109
37183
  }
37110
- const authPath = import_path.default.join(this.getProfileHomePath(record2.homeId), "auth.json");
37184
+ let authPath;
37185
+ try {
37186
+ authPath = import_path.default.join(this.getProfileHomePath(record2.homeId), "auth.json");
37187
+ } catch (error) {
37188
+ logWarn(`Failed to resolve profile home for '${record2.name}':`, error);
37189
+ return { record: record2, cacheable: false };
37190
+ }
37111
37191
  let authRaw;
37112
37192
  try {
37113
37193
  const recovered = await this.readProfileAuthFile(authPath);
@@ -44640,7 +44720,7 @@ async function ensureCliStorageReady() {
44640
44720
  }
44641
44721
 
44642
44722
  // src/app/main.ts
44643
- var VERSION = true ? "6.0.0" : "0.0.0";
44723
+ var VERSION = true ? "6.0.1" : "0.0.0";
44644
44724
  async function runCli() {
44645
44725
  const args2 = process.argv.slice(2);
44646
44726
  if (args2.length === 0) {