codexuse-cli 6.2.2 → 6.2.3

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
@@ -2026,7 +2026,7 @@ var require_toml = __commonJS({
2026
2026
  });
2027
2027
 
2028
2028
  // src/commands/accountPool.ts
2029
- var import_node_crypto15 = require("crypto");
2029
+ var import_node_crypto16 = require("crypto");
2030
2030
  var import_node_path15 = __toESM(require("path"));
2031
2031
 
2032
2032
  // ../../packages/contracts/src/settings/types.ts
@@ -3347,25 +3347,6 @@ async function updateDocument(input) {
3347
3347
  await finalizeDocumentRecovery(updated.stagedRecovery);
3348
3348
  return updated.value;
3349
3349
  }
3350
- async function deleteDocument(dbPath, namespace) {
3351
- await withWriteQueue(
3352
- dbPath,
3353
- async () => withDatabase(dbPath, (db) => {
3354
- beginImmediate(db);
3355
- try {
3356
- withStatement(
3357
- db,
3358
- `DELETE FROM ${APP_STORAGE_TABLE} WHERE namespace = ?`,
3359
- (statement) => statement.run(namespace)
3360
- );
3361
- commit(db);
3362
- } catch (error) {
3363
- rollback(db);
3364
- throw error;
3365
- }
3366
- })
3367
- );
3368
- }
3369
3350
 
3370
3351
  // ../../packages/runtime-app-state/src/storage/cloudSyncTransaction.ts
3371
3352
  var import_node_async_hooks = require("async_hooks");
@@ -3440,7 +3421,8 @@ async function withCloudSyncTransaction(userDataDir, mode, operation) {
3440
3421
  }
3441
3422
 
3442
3423
  // ../../packages/runtime-app-state/src/app/state.ts
3443
- var APP_STATE_DOCUMENT = "desktop.app-state";
3424
+ var APP_STATE_DOCUMENT = "desktop.app-state.v2";
3425
+ var LEGACY_APP_STATE_DOCUMENT = "desktop.app-state";
3444
3426
  var APP_NAME = "codexuse-desktop";
3445
3427
  var PERSISTENCE_RETRY_COOLDOWN_MS = 5e3;
3446
3428
  var PERSISTENCE_READ_DEADLINE_MS = 8e3;
@@ -3450,6 +3432,7 @@ var appStateCache = null;
3450
3432
  var ephemeralAppState = null;
3451
3433
  var persistenceFailure = null;
3452
3434
  var pendingRendererUiPatch = null;
3435
+ var legacyAppStateNeedsMigration = false;
3453
3436
  var nextPersistenceRetryAt = 0;
3454
3437
  var writeLock = Promise.resolve();
3455
3438
  var writeLockContext = new import_node_async_hooks2.AsyncLocalStorage();
@@ -3477,6 +3460,10 @@ function freezeDeep(value3, seen = /* @__PURE__ */ new WeakSet()) {
3477
3460
  return Object.freeze(value3);
3478
3461
  }
3479
3462
  function resolveDefaultUserDataDir() {
3463
+ const configured = process.env.CODEXUSE_DESKTOP_USER_DATA_DIR?.trim();
3464
+ if (configured && import_node_path4.default.isAbsolute(configured)) {
3465
+ return import_node_path4.default.resolve(configured);
3466
+ }
3480
3467
  const home = process.env.HOME || import_node_os.default.homedir();
3481
3468
  if (!home) {
3482
3469
  throw new Error("Unable to resolve home directory for app state.");
@@ -3962,6 +3949,55 @@ function desktopLlmReasoningEffortsMatchStyle(adapter, style, values2) {
3962
3949
  }
3963
3950
  return style !== "openrouter" || !values2.includes("max") && !values2.includes("ultra");
3964
3951
  }
3952
+ function recoverDowngradedChatGptWebProfile(input) {
3953
+ const expectedProviderId = `chatgpt-web-provider-${input.id.slice(-36)}`;
3954
+ const provider = input.providers.find(
3955
+ (candidate) => candidate.id === input.providerId
3956
+ );
3957
+ const selectedRoutes = input.modelRoutePublicSlugs.flatMap((publicSlug) => {
3958
+ const route = input.routes.find(
3959
+ (candidate) => candidate.publicSlug === publicSlug
3960
+ );
3961
+ return route ? [route] : [];
3962
+ });
3963
+ if (!/^chatgpt-web-[A-Za-z0-9_-]{36}$/.test(input.id) || !/^chatgpt-web-[A-Za-z0-9_-]{36}$/.test(input.profileHomeId) || input.providerId !== expectedProviderId || input.capabilityRef !== `CODEXUSE_LLM_PROFILE_${input.id}` || provider?.displayName !== "ChatGPT Web" || provider.baseUrl !== "http://127.0.0.1:1" || provider.authMode !== "bearer" || provider.credentialRef !== `CODEXUSE_CHATGPT_WEB_RUNTIME_${input.id}` || provider.transportPolicy.allowInsecureLocal !== true || selectedRoutes.length !== input.modelRoutePublicSlugs.length || selectedRoutes.some(
3964
+ (route) => route.providerId !== input.providerId || route.adapter !== "openai-responses" || route.path !== "/v1/responses" || !chatGptWebRouteEffort(route.upstreamModelId) || route.publicSlug !== chatGptWebPublicSlug(input.id, route.upstreamModelId)
3965
+ )) {
3966
+ return null;
3967
+ }
3968
+ const supported = (capability) => capability.nativeSupport.state === "supported";
3969
+ return {
3970
+ id: input.id,
3971
+ profileHomeId: input.profileHomeId,
3972
+ runtimeId: `chatgpt-web:${input.id}`,
3973
+ browserSessionId: `chatgpt-web:${input.id}`,
3974
+ linkedIdentityVerified: false,
3975
+ interactionMode: "automatic",
3976
+ setupState: "failed",
3977
+ runtimeState: "stopped",
3978
+ availability: "degraded",
3979
+ observedModelRoutes: selectedRoutes.map((route) => ({
3980
+ publicSlug: route.publicSlug,
3981
+ upstreamModelId: route.upstreamModelId,
3982
+ displayName: route.displayName,
3983
+ reasoningEfforts: [chatGptWebRouteEffort(route.upstreamModelId)],
3984
+ contextWindow: route.catalogMetadata.contextWindow,
3985
+ autoCompactTokenLimit: route.catalogMetadata.autoCompactTokenLimit,
3986
+ effectiveContextWindowPercent: route.catalogMetadata.effectiveContextWindowPercent,
3987
+ supportsImages: supported(route.capabilities.inputImage),
3988
+ supportsFunctionTools: false,
3989
+ supportsParallelTools: false,
3990
+ supportsCompaction: route.catalogMetadata.autoCompactTokenLimit !== null,
3991
+ fullHarnessVerified: false
3992
+ })),
3993
+ fullModeConfigured: false,
3994
+ fullCodexHarnessVerified: false,
3995
+ helperProtocolVersion: 0,
3996
+ helperVersion: "unknown",
3997
+ lastRuntimeError: "chatgpt-web-full-setup-required",
3998
+ restartRequired: true
3999
+ };
4000
+ }
3965
4001
  function normalizeDesktopLlmRegistry(value3, profiles) {
3966
4002
  if (!isRecord2(value3) || value3.version !== 1 && value3.version !== 2 && value3.version !== 3 && value3.version !== 4) {
3967
4003
  return migrateDesktopLlmRegistry(profiles);
@@ -4124,8 +4160,17 @@ function normalizeDesktopLlmRegistry(value3, profiles) {
4124
4160
  if (!id2 || !name || !profileHomeId || !providerId || modelRoutePublicSlugs.length === 0 || !defaultModelRoutePublicSlug || !capabilityRef || !createdAt || !updatedAt) {
4125
4161
  return [];
4126
4162
  }
4127
- const kind = entry.kind === "chatgpt-web" ? "chatgpt-web" : "custom";
4128
- const rawWeb = kind === "chatgpt-web" && isRecord2(entry.chatgptWeb) ? entry.chatgptWeb : null;
4163
+ const recoveredWeb = entry.kind !== "chatgpt-web" ? recoverDowngradedChatGptWebProfile({
4164
+ id: id2,
4165
+ profileHomeId,
4166
+ providerId,
4167
+ capabilityRef,
4168
+ modelRoutePublicSlugs,
4169
+ providers,
4170
+ routes
4171
+ }) : null;
4172
+ const kind = entry.kind === "chatgpt-web" || recoveredWeb ? "chatgpt-web" : "custom";
4173
+ const rawWeb = kind === "chatgpt-web" ? isRecord2(entry.chatgptWeb) ? entry.chatgptWeb : recoveredWeb : null;
4129
4174
  const interactionMode = "automatic";
4130
4175
  const setupState = rawWeb?.setupState === "provisional" || rawWeb?.setupState === "signing-in" || rawWeb?.setupState === "verifying" || rawWeb?.setupState === "ready" || rawWeb?.setupState === "failed" ? rawWeb.setupState : "failed";
4131
4176
  const runtimeState = rawWeb?.runtimeState === "starting" || rawWeb?.runtimeState === "ready" || rawWeb?.runtimeState === "draining" || rawWeb?.runtimeState === "failed" ? rawWeb.runtimeState : "stopped";
@@ -4230,8 +4275,13 @@ function normalizeDesktopLlmRegistry(value3, profiles) {
4230
4275
  (profile) => profile.kind === "chatgpt-web" && profile.chatgptWeb ? [[profile.providerId, profile.chatgptWeb]] : []
4231
4276
  )
4232
4277
  );
4278
+ const canonicalProviders = providers.map(
4279
+ (provider) => webProfilesByProvider.has(provider.id) ? { ...provider, systemManaged: "chatgpt-web" } : provider
4280
+ );
4233
4281
  const canonicalRoutes = routes.map((route) => {
4234
- const provider = providers.find((candidate) => candidate.id === route.providerId);
4282
+ const provider = canonicalProviders.find(
4283
+ (candidate) => candidate.id === route.providerId
4284
+ );
4235
4285
  if (provider?.systemManaged !== "chatgpt-web") return route;
4236
4286
  const web = webProfilesByProvider.get(route.providerId);
4237
4287
  const observed = web?.observedModelRoutes.find(
@@ -4256,11 +4306,29 @@ function normalizeDesktopLlmRegistry(value3, profiles) {
4256
4306
  standaloneWebSearch: capability(false),
4257
4307
  imageGeneration: capability(false)
4258
4308
  };
4259
- return { ...route, capabilities };
4309
+ const observedEffort = observed?.reasoningEfforts[0];
4310
+ const reasoningEffort = isDesktopLlmReasoningEffort(observedEffort) ? observedEffort : null;
4311
+ return {
4312
+ ...route,
4313
+ capabilities,
4314
+ requestProfile: {
4315
+ ...route.requestProfile,
4316
+ reasoningStyle: "default",
4317
+ supportsReasoningEffort: Boolean(reasoningEffort)
4318
+ },
4319
+ reasoningEffort: reasoningEffort ? {
4320
+ mode: "selectable",
4321
+ values: [reasoningEffort],
4322
+ defaultValue: reasoningEffort,
4323
+ source: "provider",
4324
+ fetchedAt: route.reasoningEffort.fetchedAt
4325
+ } : route.reasoningEffort,
4326
+ published: observed?.fullHarnessVerified === true && observed.supportsFunctionTools && observed.supportsParallelTools
4327
+ };
4260
4328
  });
4261
4329
  const revision = (0, import_node_crypto2.createHash)("sha256").update(
4262
4330
  JSON.stringify({
4263
- providers: providers.map((provider) => ({
4331
+ providers: canonicalProviders.map((provider) => ({
4264
4332
  id: provider.id,
4265
4333
  displayName: provider.displayName,
4266
4334
  enabled: provider.enabled,
@@ -4309,7 +4377,7 @@ function normalizeDesktopLlmRegistry(value3, profiles) {
4309
4377
  return {
4310
4378
  version: 4,
4311
4379
  revision,
4312
- providers,
4380
+ providers: canonicalProviders,
4313
4381
  routes: canonicalRoutes,
4314
4382
  externalProfiles: uniqueExternalProfiles
4315
4383
  };
@@ -4946,11 +5014,22 @@ function deepMerge(base, patch) {
4946
5014
  return next;
4947
5015
  }
4948
5016
  async function readAppStateFromStorage() {
4949
- return readDocumentStrict(
5017
+ const current = await readDocumentStrict(
4950
5018
  resolveStorageDbPath(),
4951
5019
  APP_STATE_DOCUMENT,
4952
5020
  normalizeAppState
4953
5021
  );
5022
+ if (current) {
5023
+ legacyAppStateNeedsMigration = false;
5024
+ return current;
5025
+ }
5026
+ const legacy = await readDocumentStrict(
5027
+ resolveStorageDbPath(),
5028
+ LEGACY_APP_STATE_DOCUMENT,
5029
+ normalizeAppState
5030
+ );
5031
+ legacyAppStateNeedsMigration = legacy !== null;
5032
+ return legacy;
4954
5033
  }
4955
5034
  async function readStoredAppStateOrNull() {
4956
5035
  try {
@@ -4966,7 +5045,7 @@ async function readStoredAppStateOrNull() {
4966
5045
  }
4967
5046
  async function readStoredAppStateForInit() {
4968
5047
  const stored = await readAppStateFromStorage();
4969
- if (stored && !pendingRendererUiPatch) {
5048
+ if (stored && !pendingRendererUiPatch && !legacyAppStateNeedsMigration) {
4970
5049
  return stored;
4971
5050
  }
4972
5051
  const pendingUiPatch = pendingRendererUiPatch;
@@ -4974,7 +5053,7 @@ async function readStoredAppStateForInit() {
4974
5053
  dbPath: resolveStorageDbPath(),
4975
5054
  namespace: APP_STATE_DOCUMENT,
4976
5055
  normalize: normalizeAppState,
4977
- fallback: () => normalizeAppState(null),
5056
+ fallback: () => stored ?? normalizeAppState(null),
4978
5057
  transform: (current) => pendingUiPatch ? deepMerge(current, { ui: pendingUiPatch }) : current,
4979
5058
  cloneBeforeTransform: false,
4980
5059
  cloneResult: false,
@@ -4983,6 +5062,7 @@ async function readStoredAppStateForInit() {
4983
5062
  if (pendingRendererUiPatch === pendingUiPatch) {
4984
5063
  pendingRendererUiPatch = null;
4985
5064
  }
5065
+ legacyAppStateNeedsMigration = false;
4986
5066
  return initialized;
4987
5067
  }
4988
5068
  function degradeToMemory(kind, message) {
@@ -5061,6 +5141,7 @@ async function initializeAppState(userDataDir) {
5061
5141
  ephemeralAppState = null;
5062
5142
  persistenceFailure = null;
5063
5143
  pendingRendererUiPatch = null;
5144
+ legacyAppStateNeedsMigration = false;
5064
5145
  nextPersistenceRetryAt = 0;
5065
5146
  }
5066
5147
  const state = await ensureInitialized();
@@ -5249,7 +5330,7 @@ async function updateAppSettings(transform3, onUpdated) {
5249
5330
  }
5250
5331
 
5251
5332
  // ../../packages/runtime-profiles/src/license/service.ts
5252
- var import_node_crypto7 = __toESM(require("crypto"), 1);
5333
+ var import_node_crypto8 = __toESM(require("crypto"), 1);
5253
5334
 
5254
5335
  // ../../packages/runtime-codex/src/codex/settings.ts
5255
5336
  function asString2(value3) {
@@ -5505,8 +5586,8 @@ async function persistLicenseSecret(dbPath, secret) {
5505
5586
  await writeDocument(dbPath, LICENSE_SECRET_DOCUMENT, secret);
5506
5587
  return secret;
5507
5588
  }
5508
- async function getLicenseSecret() {
5509
- const dbPath = resolveAppStorageDbPath(getUserDataDir());
5589
+ async function getLicenseSecret(userDataDir = getUserDataDir()) {
5590
+ const dbPath = resolveAppStorageDbPath(userDataDir);
5510
5591
  const existing = await readDocument(dbPath, LICENSE_SECRET_DOCUMENT, normalizeSecret);
5511
5592
  const normalizedExisting = normalizeSecret(existing);
5512
5593
  if (normalizedExisting.length > 0) {
@@ -5517,7 +5598,7 @@ async function getLicenseSecret() {
5517
5598
  }
5518
5599
 
5519
5600
  // ../../packages/runtime-profiles/src/license/trial.ts
5520
- var import_node_crypto6 = __toESM(require("crypto"), 1);
5601
+ var import_node_crypto7 = __toESM(require("crypto"), 1);
5521
5602
 
5522
5603
  // ../../packages/runtime-profiles/src/license/device-id.ts
5523
5604
  var import_node_crypto4 = __toESM(require("crypto"), 1);
@@ -5650,95 +5731,106 @@ async function registerTrialWithServer(input) {
5650
5731
  }
5651
5732
 
5652
5733
  // ../../packages/runtime-profiles/src/license/trial-token-store.ts
5734
+ var import_node_crypto6 = require("crypto");
5735
+
5736
+ // ../../packages/runtime-profiles/src/secrets/local-secret-store.ts
5653
5737
  var import_node_crypto5 = require("crypto");
5654
- var import_node_child_process2 = require("child_process");
5655
- var KEYCHAIN_SERVICE = "CODEXUSE_TRIAL_TOKEN";
5656
- var KEYCHAIN_ACCOUNT_PREFIX = "device-sha256:";
5657
- var FALLBACK_DOCUMENT_PREFIX = "desktop.trial-token.";
5658
- function keychainAccountForDevice(deviceId) {
5659
- const digest = (0, import_node_crypto5.createHash)("sha256").update(deviceId).digest("hex");
5660
- return KEYCHAIN_ACCOUNT_PREFIX + digest;
5738
+ var SECRET_NAME = /^[A-Za-z0-9_.:-]{1,220}$/;
5739
+ var DOCUMENT_PREFIX = "desktop.local-secret.";
5740
+ var ENCRYPTION_CONTEXT = "codexuse-local-secret-v1";
5741
+ var SECRET_LIMIT_BYTES = 64 * 1024;
5742
+ function validateName(name) {
5743
+ if (!SECRET_NAME.test(name)) {
5744
+ throw new Error("local-secret-name-invalid");
5745
+ }
5661
5746
  }
5662
- function fallbackDocumentForDevice(deviceId) {
5663
- const digest = (0, import_node_crypto5.createHash)("sha256").update(deviceId).digest("hex");
5664
- return FALLBACK_DOCUMENT_PREFIX + digest;
5747
+ function documentName(name) {
5748
+ return DOCUMENT_PREFIX + (0, import_node_crypto5.createHash)("sha256").update(name).digest("hex");
5749
+ }
5750
+ function normalizeEnvelope(value3) {
5751
+ if (!value3 || typeof value3 !== "object" || Array.isArray(value3)) {
5752
+ throw new Error("local-secret-envelope-invalid");
5753
+ }
5754
+ const envelope = value3;
5755
+ if (envelope.version !== 1 || typeof envelope.iv !== "string" || typeof envelope.tag !== "string" || typeof envelope.ciphertext !== "string") {
5756
+ throw new Error("local-secret-envelope-invalid");
5757
+ }
5758
+ return envelope;
5759
+ }
5760
+ async function encryptionKey(userDataDir) {
5761
+ const deviceSecret = await getLicenseSecret(userDataDir);
5762
+ return (0, import_node_crypto5.createHash)("sha256").update(ENCRYPTION_CONTEXT).update("\0").update(deviceSecret).digest();
5763
+ }
5764
+ async function writeLocalSecret(name, secret, userDataDir = getUserDataDir()) {
5765
+ validateName(name);
5766
+ if (secret.length === 0 || Buffer.byteLength(secret) > SECRET_LIMIT_BYTES) {
5767
+ throw new Error("local-secret-value-invalid");
5768
+ }
5769
+ const iv = (0, import_node_crypto5.randomBytes)(12);
5770
+ const cipher = (0, import_node_crypto5.createCipheriv)("aes-256-gcm", await encryptionKey(userDataDir), iv);
5771
+ cipher.setAAD(Buffer.from(name, "utf8"));
5772
+ const ciphertext = Buffer.concat([
5773
+ cipher.update(secret, "utf8"),
5774
+ cipher.final()
5775
+ ]);
5776
+ const envelope = {
5777
+ version: 1,
5778
+ iv: iv.toString("base64"),
5779
+ tag: cipher.getAuthTag().toString("base64"),
5780
+ ciphertext: ciphertext.toString("base64")
5781
+ };
5782
+ await writeDocument(
5783
+ resolveAppStorageDbPath(userDataDir),
5784
+ documentName(name),
5785
+ envelope
5786
+ );
5787
+ }
5788
+ async function readLocalSecret(name, userDataDir = getUserDataDir()) {
5789
+ validateName(name);
5790
+ const envelope = await readDocument(
5791
+ resolveAppStorageDbPath(userDataDir),
5792
+ documentName(name),
5793
+ normalizeEnvelope
5794
+ );
5795
+ if (!envelope) return null;
5796
+ try {
5797
+ const decipher = (0, import_node_crypto5.createDecipheriv)(
5798
+ "aes-256-gcm",
5799
+ await encryptionKey(userDataDir),
5800
+ Buffer.from(envelope.iv, "base64")
5801
+ );
5802
+ decipher.setAAD(Buffer.from(name, "utf8"));
5803
+ decipher.setAuthTag(Buffer.from(envelope.tag, "base64"));
5804
+ return Buffer.concat([
5805
+ decipher.update(Buffer.from(envelope.ciphertext, "base64")),
5806
+ decipher.final()
5807
+ ]).toString("utf8") || null;
5808
+ } catch (error) {
5809
+ throw new Error("local-secret-read-failed", { cause: error });
5810
+ }
5811
+ }
5812
+
5813
+ // ../../packages/runtime-profiles/src/license/trial-token-store.ts
5814
+ var SECRET_PREFIX = "trial-token:";
5815
+ function secretNameForDevice(deviceId) {
5816
+ const digest = (0, import_node_crypto6.createHash)("sha256").update(deviceId).digest("hex");
5817
+ return SECRET_PREFIX + digest;
5665
5818
  }
5666
5819
  function normalizeToken(value3) {
5667
5820
  const trimmed = typeof value3 === "string" ? value3.trim() : "";
5668
5821
  return trimmed.length > 0 ? trimmed : null;
5669
5822
  }
5670
- function runSecurityCommand(args2) {
5671
- return new Promise((resolve2, reject) => {
5672
- const child = (0, import_node_child_process2.spawn)("security", args2, { stdio: ["ignore", "pipe", "ignore"] });
5673
- let stdout = "";
5674
- child.stdout?.on("data", (chunk) => {
5675
- stdout += String(chunk);
5676
- });
5677
- child.on("error", () => {
5678
- reject(new Error("keychain-command-failed"));
5679
- });
5680
- child.on("close", (code) => {
5681
- resolve2({ code, stdout });
5682
- });
5683
- });
5684
- }
5685
5823
  async function readStoredTrialToken(deviceId) {
5686
- if (process.platform !== "darwin") {
5687
- const dbPath = resolveAppStorageDbPath(getUserDataDir());
5688
- return readDocument(
5689
- dbPath,
5690
- fallbackDocumentForDevice(deviceId),
5691
- normalizeToken
5692
- );
5693
- }
5694
- const result2 = await runSecurityCommand([
5695
- "find-generic-password",
5696
- "-a",
5697
- keychainAccountForDevice(deviceId),
5698
- "-s",
5699
- KEYCHAIN_SERVICE,
5700
- "-w"
5701
- ]).catch(() => null);
5702
- await deleteDocument(
5703
- resolveAppStorageDbPath(getUserDataDir()),
5704
- fallbackDocumentForDevice(deviceId)
5705
- ).catch(() => void 0);
5706
- if (!result2 || result2.code !== 0) {
5707
- return null;
5708
- }
5709
- return result2.stdout.length > 0 ? result2.stdout.replace(/\n$/, "") : null;
5824
+ return normalizeToken(
5825
+ await readLocalSecret(secretNameForDevice(deviceId)).catch(() => null)
5826
+ );
5710
5827
  }
5711
5828
  async function writeStoredTrialToken(deviceId, token) {
5712
5829
  const value3 = typeof token === "string" ? token.trim() : "";
5713
5830
  if (!value3) {
5714
5831
  return;
5715
5832
  }
5716
- if (process.platform !== "darwin") {
5717
- const dbPath = resolveAppStorageDbPath(getUserDataDir());
5718
- await writeDocument(
5719
- dbPath,
5720
- fallbackDocumentForDevice(deviceId),
5721
- value3
5722
- );
5723
- return;
5724
- }
5725
- const result2 = await runSecurityCommand([
5726
- "add-generic-password",
5727
- "-U",
5728
- "-a",
5729
- keychainAccountForDevice(deviceId),
5730
- "-s",
5731
- KEYCHAIN_SERVICE,
5732
- "-w",
5733
- value3
5734
- ]).catch(() => null);
5735
- await deleteDocument(
5736
- resolveAppStorageDbPath(getUserDataDir()),
5737
- fallbackDocumentForDevice(deviceId)
5738
- ).catch(() => void 0);
5739
- if (!result2 || result2.code !== 0) {
5740
- throw new Error("trial-token-keychain-write-failed");
5741
- }
5833
+ await writeLocalSecret(secretNameForDevice(deviceId), value3);
5742
5834
  }
5743
5835
 
5744
5836
  // ../../packages/runtime-profiles/src/license/trial.ts
@@ -5764,7 +5856,7 @@ function trialSignaturePayload(trial) {
5764
5856
  });
5765
5857
  }
5766
5858
  function signTrial(trial, secret) {
5767
- return import_node_crypto6.default.createHmac("sha256", secret).update(trialSignaturePayload(trial)).digest("hex");
5859
+ return import_node_crypto7.default.createHmac("sha256", secret).update(trialSignaturePayload(trial)).digest("hex");
5768
5860
  }
5769
5861
  function withTrialSignature(trial, secret) {
5770
5862
  return { ...trial, signature: signTrial(trial, secret) };
@@ -6096,7 +6188,7 @@ function licenseSignaturePayload(license) {
6096
6188
  return JSON.stringify(payload);
6097
6189
  }
6098
6190
  function signLicense(license, secret) {
6099
- return import_node_crypto7.default.createHmac("sha256", secret).update(licenseSignaturePayload(license)).digest("hex");
6191
+ return import_node_crypto8.default.createHmac("sha256", secret).update(licenseSignaturePayload(license)).digest("hex");
6100
6192
  }
6101
6193
  function withSignature(license, secret) {
6102
6194
  return {
@@ -6457,7 +6549,7 @@ var LicenseService = class {
6457
6549
  throw new Error("License key is required.");
6458
6550
  }
6459
6551
  const secret = await getLicenseSecret();
6460
- const digest = import_node_crypto7.default.createHash("sha256").update(trimmed).digest("hex");
6552
+ const digest = import_node_crypto8.default.createHash("sha256").update(trimmed).digest("hex");
6461
6553
  const normalized = await requestDeviceActivation(trimmed);
6462
6554
  const stored = {
6463
6555
  licenseKey: trimmed,
@@ -6518,7 +6610,7 @@ function shouldEnforceProfileLimit(status) {
6518
6610
  }
6519
6611
 
6520
6612
  // ../../packages/runtime-profiles/src/profiles/profile-manager.ts
6521
- var import_node_crypto14 = require("crypto");
6613
+ var import_node_crypto15 = require("crypto");
6522
6614
  var import_fs = require("fs");
6523
6615
  var import_node_os5 = __toESM(require("os"), 1);
6524
6616
  var import_path = __toESM(require("path"), 1);
@@ -6576,15 +6668,15 @@ function resolveProfileIdentityKeyFromProfile(profile) {
6576
6668
  }
6577
6669
 
6578
6670
  // ../../packages/runtime-codex/src/codex/rpc.ts
6579
- var import_node_child_process6 = require("child_process");
6580
- var import_node_crypto10 = require("crypto");
6671
+ var import_node_child_process5 = require("child_process");
6672
+ var import_node_crypto11 = require("crypto");
6581
6673
  var import_node_readline = __toESM(require("readline"), 1);
6582
6674
  var import_node_fs6 = require("fs");
6583
6675
  var import_node_os3 = __toESM(require("os"), 1);
6584
6676
  var import_node_path10 = __toESM(require("path"), 1);
6585
6677
 
6586
6678
  // ../../packages/runtime-codex/src/codex/cli.ts
6587
- var import_node_child_process3 = require("child_process");
6679
+ var import_node_child_process2 = require("child_process");
6588
6680
  var import_node_fs4 = require("fs");
6589
6681
  var import_node_path5 = __toESM(require("path"), 1);
6590
6682
  var STABLE_CHANNEL = "stable";
@@ -6692,7 +6784,7 @@ function evaluateCodexCliStatus() {
6692
6784
  function runVersionPreflight(cliPath) {
6693
6785
  return new Promise((resolve2) => {
6694
6786
  const useNode = /\.(?:c|m)?js$/i.test(cliPath);
6695
- const child = (0, import_node_child_process3.spawn)(
6787
+ const child = (0, import_node_child_process2.spawn)(
6696
6788
  useNode ? process.execPath : cliPath,
6697
6789
  useNode ? [cliPath, "--version"] : ["--version"],
6698
6790
  {
@@ -6761,7 +6853,7 @@ async function requireCodexCli() {
6761
6853
  }
6762
6854
 
6763
6855
  // ../../packages/runtime-codex/src/codex/command.ts
6764
- var import_node_child_process4 = require("child_process");
6856
+ var import_node_child_process3 = require("child_process");
6765
6857
  var import_node_path6 = __toESM(require("path"), 1);
6766
6858
  var cachedNodeRuntime = null;
6767
6859
  function isJavaScriptEntrypoint(binaryPath) {
@@ -6804,7 +6896,7 @@ function resolveNodeRuntime(env) {
6804
6896
  )
6805
6897
  );
6806
6898
  for (const candidate of candidates) {
6807
- const probe = (0, import_node_child_process4.spawnSync)(candidate, ["-v"], { env: runtimeEnv, stdio: "ignore" });
6899
+ const probe = (0, import_node_child_process3.spawnSync)(candidate, ["-v"], { env: runtimeEnv, stdio: "ignore" });
6808
6900
  if (!probe.error && probe.status === 0) {
6809
6901
  cachedNodeRuntime = candidate;
6810
6902
  return candidate;
@@ -6829,7 +6921,7 @@ function buildCodexCommand(binaryPath, args2, env) {
6829
6921
  }
6830
6922
 
6831
6923
  // ../../packages/runtime-codex/src/codex/home.ts
6832
- var import_node_crypto8 = require("crypto");
6924
+ var import_node_crypto9 = require("crypto");
6833
6925
  var import_node_fs5 = require("fs");
6834
6926
  var import_promises2 = require("fs/promises");
6835
6927
  var import_node_os2 = __toESM(require("os"), 1);
@@ -6869,7 +6961,7 @@ function resolveCodexSqliteHomeDir(codexHomePath) {
6869
6961
  function resolveCurrentProfileCodexHomeDir(profileHomeId) {
6870
6962
  return import_node_path7.default.join(
6871
6963
  resolveProfileCodexHomesRoot(),
6872
- (0, import_node_crypto8.createHash)("sha256").update(profileHomeId).digest("hex").slice(0, 20)
6964
+ (0, import_node_crypto9.createHash)("sha256").update(profileHomeId).digest("hex").slice(0, 20)
6873
6965
  );
6874
6966
  }
6875
6967
  function resolveProfileCodexHomeDir(profileHomeId) {
@@ -6982,7 +7074,7 @@ function buildCodexChildEnv(overrides = {}) {
6982
7074
  var import_toml = __toESM(require_toml(), 1);
6983
7075
 
6984
7076
  // ../../packages/runtime-codex/src/codex/config-metadata.ts
6985
- var import_node_child_process5 = require("child_process");
7077
+ var import_node_child_process4 = require("child_process");
6986
7078
  var import_promises3 = require("fs/promises");
6987
7079
  var import_node_path8 = __toESM(require("path"), 1);
6988
7080
  var CONFIG_SCHEMA_URL = "https://raw.githubusercontent.com/openai/codex/main/codex-rs/core/config.schema.json";
@@ -7094,7 +7186,7 @@ function uniqueSorted(values2) {
7094
7186
  }
7095
7187
  async function runCommand(command, args2, timeoutMs = 3e3) {
7096
7188
  return new Promise((resolve2, reject) => {
7097
- const child = (0, import_node_child_process5.spawn)(command, args2, {
7189
+ const child = (0, import_node_child_process4.spawn)(command, args2, {
7098
7190
  stdio: ["ignore", "pipe", "pipe"],
7099
7191
  env: buildCodexChildEnv()
7100
7192
  });
@@ -7275,7 +7367,7 @@ async function getCodexConfigMetadata(forceRefresh = false) {
7275
7367
  }
7276
7368
 
7277
7369
  // ../../packages/runtime-codex/src/codex/config-io.ts
7278
- var import_node_crypto9 = require("crypto");
7370
+ var import_node_crypto10 = require("crypto");
7279
7371
  var import_promises4 = require("fs/promises");
7280
7372
  var import_node_path9 = __toESM(require("path"), 1);
7281
7373
 
@@ -7405,7 +7497,7 @@ async function writeConfigContent(content, options) {
7405
7497
  await removeStaleConfigStagingFiles(targetPath);
7406
7498
  const mode = await resolveConfigWriteMode(targetPath);
7407
7499
  const normalized = ensureTrailingNewline(normalizeLineEndings(content));
7408
- const stagingPath = `${targetPath}.tmp-${process.pid}-${(0, import_node_crypto9.randomUUID)()}`;
7500
+ const stagingPath = `${targetPath}.tmp-${process.pid}-${(0, import_node_crypto10.randomUUID)()}`;
7409
7501
  try {
7410
7502
  const handle = await (0, import_promises4.open)(stagingPath, "wx", mode);
7411
7503
  try {
@@ -24398,9 +24490,9 @@ var ChatGptWebCreateInput = Schema_exports.Struct({
24398
24490
  newOpenAiProfileName: ChatGptWebOptionalName,
24399
24491
  setupId: ChatGptWebOptionalSetupId,
24400
24492
  interactionMode: Schema_exports.optional(Schema_exports.Literal("automatic")),
24401
- // A passkey cannot complete in the private browser, so that sign-in is
24402
- // handed to a throwaway Chrome profile instead. The choice is made before
24403
- // anything opens, because the two paths open different windows.
24493
+ // Google and passkeys cannot complete in the private browser, so this path
24494
+ // uses a throwaway Chrome profile. The choice is made before anything opens,
24495
+ // because the two paths open different windows.
24404
24496
  signInMethod: Schema_exports.optional(
24405
24497
  Schema_exports.Union([Schema_exports.Literal("password"), Schema_exports.Literal("passkey")])
24406
24498
  ),
@@ -25390,7 +25482,7 @@ function authWritebackPaths(filePath) {
25390
25482
  };
25391
25483
  }
25392
25484
  function fingerprintAuth(content) {
25393
- return (0, import_node_crypto10.createHash)("sha256").update(content).digest("hex");
25485
+ return (0, import_node_crypto11.createHash)("sha256").update(content).digest("hex");
25394
25486
  }
25395
25487
  async function readOptionalFile(filePath) {
25396
25488
  try {
@@ -25405,7 +25497,7 @@ async function writeAtomicPath(filePath, content) {
25405
25497
  const dir = import_node_path10.default.dirname(filePath);
25406
25498
  const tempPath = import_node_path10.default.join(
25407
25499
  dir,
25408
- `.${import_node_path10.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto10.randomUUID)()}.tmp`
25500
+ `.${import_node_path10.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto11.randomUUID)()}.tmp`
25409
25501
  );
25410
25502
  const handle = await import_node_fs6.promises.open(tempPath, "wx", 384);
25411
25503
  try {
@@ -25432,7 +25524,7 @@ async function installAuthFileIfAbsent(filePath, content) {
25432
25524
  const dir = import_node_path10.default.dirname(filePath);
25433
25525
  const tempPath = import_node_path10.default.join(
25434
25526
  dir,
25435
- `.${import_node_path10.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto10.randomUUID)()}.install`
25527
+ `.${import_node_path10.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto11.randomUUID)()}.install`
25436
25528
  );
25437
25529
  const handle = await import_node_fs6.promises.open(tempPath, "wx", 384);
25438
25530
  try {
@@ -25503,7 +25595,7 @@ async function hasExternalOpenFileHandle(filePath) {
25503
25595
  }
25504
25596
  const lsofCommand = process.platform === "darwin" ? "/usr/sbin/lsof" : "lsof";
25505
25597
  return new Promise((resolve2) => {
25506
- const child = (0, import_node_child_process6.spawn)(lsofCommand, ["-F", "p", "--", filePath], {
25598
+ const child = (0, import_node_child_process5.spawn)(lsofCommand, ["-F", "p", "--", filePath], {
25507
25599
  stdio: ["ignore", "pipe", "ignore"]
25508
25600
  });
25509
25601
  let output = "";
@@ -25903,7 +25995,7 @@ async function fetchRateLimitsViaRpc(envOverride, options = {}) {
25903
25995
  ["-s", "read-only", "-a", "never", "app-server"],
25904
25996
  childEnv
25905
25997
  );
25906
- const child = (0, import_node_child_process6.spawn)(command.command, command.args, {
25998
+ const child = (0, import_node_child_process5.spawn)(command.command, command.args, {
25907
25999
  stdio: ["pipe", "pipe", "pipe"],
25908
26000
  env: childEnv,
25909
26001
  shell: command.shell
@@ -26055,7 +26147,7 @@ async function activateResetWindowViaRpcIsolated(envOverride, options, sourceAut
26055
26147
  ["-s", "read-only", "-a", "never", "app-server"],
26056
26148
  childEnv
26057
26149
  );
26058
- const child = (0, import_node_child_process6.spawn)(command.command, command.args, {
26150
+ const child = (0, import_node_child_process5.spawn)(command.command, command.args, {
26059
26151
  stdio: ["pipe", "pipe", "pipe"],
26060
26152
  env: childEnv,
26061
26153
  shell: command.shell
@@ -26230,8 +26322,8 @@ async function activateResetWindowViaRpcIsolated(envOverride, options, sourceAut
26230
26322
  }
26231
26323
 
26232
26324
  // ../../packages/runtime-codex/src/codex/officialAppRestart.ts
26233
- var import_node_child_process7 = require("child_process");
26234
- var import_node_crypto12 = require("crypto");
26325
+ var import_node_child_process6 = require("child_process");
26326
+ var import_node_crypto13 = require("crypto");
26235
26327
  var import_node_fs9 = require("fs");
26236
26328
  var import_node_os4 = require("os");
26237
26329
  var import_node_path13 = __toESM(require("path"), 1);
@@ -26565,7 +26657,7 @@ async function findOfficialCodexThreadRecord(profileHome, threadId, options = {}
26565
26657
  }
26566
26658
 
26567
26659
  // ../../packages/runtime-codex/src/codex/sharedHistory.ts
26568
- var import_node_crypto11 = require("crypto");
26660
+ var import_node_crypto12 = require("crypto");
26569
26661
  var import_node_fs8 = require("fs");
26570
26662
  var import_promises5 = require("fs/promises");
26571
26663
  var import_node_path12 = __toESM(require("path"), 1);
@@ -27002,7 +27094,7 @@ function hashProfileKey(profileKey) {
27002
27094
  if (!profileKey) {
27003
27095
  return null;
27004
27096
  }
27005
- return (0, import_node_crypto12.createHash)("sha256").update(profileKey).digest("hex").slice(0, 12);
27097
+ return (0, import_node_crypto13.createHash)("sha256").update(profileKey).digest("hex").slice(0, 12);
27006
27098
  }
27007
27099
  function sanitizeOfficialCodexOverlayActionTargetsForRenderer(targets) {
27008
27100
  const sanitized = [];
@@ -30340,7 +30432,7 @@ async function runCdpCommandSequence(debuggerUrl, commands, timeoutMs = CODEX_CD
30340
30432
  });
30341
30433
  }
30342
30434
  async function verifyCdpBindingRoundTrip(debuggerUrl) {
30343
- const nonce = (0, import_node_crypto12.randomUUID)();
30435
+ const nonce = (0, import_node_crypto13.randomUUID)();
30344
30436
  const expression = `(() => {
30345
30437
  const binding = window[${JSON.stringify(CODEXUSE_BRIDGE_BINDING_NAME)}];
30346
30438
  if (typeof binding !== "function") return false;
@@ -30763,7 +30855,7 @@ async function startOfficialCodexBridgeActionListenerOnce(args2) {
30763
30855
  let closeNotified = false;
30764
30856
  let echoReceived = false;
30765
30857
  const requiredCommandIds = /* @__PURE__ */ new Set();
30766
- const echoId = (0, import_node_crypto12.randomUUID)();
30858
+ const echoId = (0, import_node_crypto13.randomUUID)();
30767
30859
  const readyTimeout = setTimeout(() => {
30768
30860
  settleReady(false);
30769
30861
  try {
@@ -30837,7 +30929,7 @@ async function startOfficialCodexBridgeActionListenerOnce(args2) {
30837
30929
  }
30838
30930
  };
30839
30931
  bridgeActionListenerVerifiers.set(args2.debuggerUrl, async () => {
30840
- const id2 = (0, import_node_crypto12.randomUUID)();
30932
+ const id2 = (0, import_node_crypto13.randomUUID)();
30841
30933
  return await new Promise((resolve2) => {
30842
30934
  const waiters = bridgeActionListenerHealthWaiters.get(args2.debuggerUrl) ?? /* @__PURE__ */ new Map();
30843
30935
  bridgeActionListenerHealthWaiters.set(args2.debuggerUrl, waiters);
@@ -31393,7 +31485,7 @@ async function recordOfficialCodexActivity(input) {
31393
31485
  };
31394
31486
  const finite2 = (value3, min4, max4) => typeof value3 === "number" && Number.isFinite(value3) ? Math.max(min4, Math.min(max4, value3)) : null;
31395
31487
  const entry = {
31396
- id: (0, import_node_crypto12.randomUUID)(),
31488
+ id: (0, import_node_crypto13.randomUUID)(),
31397
31489
  at: now2.toISOString(),
31398
31490
  kind: input.kind,
31399
31491
  status: bounded(input.status, 80) ?? "unknown",
@@ -31463,7 +31555,7 @@ async function recordOfficialCodexActivity(input) {
31463
31555
  }
31464
31556
  function runCommand2(command, args2, timeoutMs = COMMAND_TIMEOUT_MS) {
31465
31557
  return new Promise((resolve2) => {
31466
- const child = (0, import_node_child_process7.spawn)(command, args2, {
31558
+ const child = (0, import_node_child_process6.spawn)(command, args2, {
31467
31559
  stdio: ["ignore", "pipe", "pipe"]
31468
31560
  });
31469
31561
  let stdout = "";
@@ -31514,7 +31606,7 @@ var LAUNCH_LOCK_NAME = ".codexuse-launch.lock";
31514
31606
  var LAUNCH_LOCK_WAIT_MS = 6e4;
31515
31607
  async function withProfileLaunchFileLock(profileHome, work, options) {
31516
31608
  const accountKey = options.profileKey?.trim();
31517
- const lockPath = accountKey ? import_node_path13.default.join(resolveProfileCodexHomesRoot(), ".launch-locks", (0, import_node_crypto12.createHash)("sha256").update(accountKey).digest("hex")) : import_node_path13.default.join(profileHome, LAUNCH_LOCK_NAME);
31609
+ const lockPath = accountKey ? import_node_path13.default.join(resolveProfileCodexHomesRoot(), ".launch-locks", (0, import_node_crypto13.createHash)("sha256").update(accountKey).digest("hex")) : import_node_path13.default.join(profileHome, LAUNCH_LOCK_NAME);
31518
31610
  const deadline = Date.now() + (options.waitMs ?? LAUNCH_LOCK_WAIT_MS);
31519
31611
  for (; ; ) {
31520
31612
  const release = await acquireCrossProcessFileLock(lockPath, { busyTimeoutMs: 0 });
@@ -32363,7 +32455,7 @@ async function openCodexWithProfileHome(candidate, profileHome, profileName, pre
32363
32455
  if (appUserDataDir) {
32364
32456
  (0, import_node_fs9.mkdirSync)(appUserDataDir, { recursive: true });
32365
32457
  }
32366
- child = (0, import_node_child_process7.spawn)(
32458
+ child = (0, import_node_child_process6.spawn)(
32367
32459
  "/usr/bin/open",
32368
32460
  [
32369
32461
  "-n",
@@ -32671,7 +32763,7 @@ function sharedCodexLaunchOptions(useDefaultUserData, profileIdentity) {
32671
32763
  const userDataDir = !useDefaultUserData && profileIdentity ? import_node_path13.default.join(
32672
32764
  SHARED_CODEX_HOME,
32673
32765
  "codex-app-user-data",
32674
- (0, import_node_crypto12.createHash)("sha256").update(profileIdentity).digest("hex").slice(0, 16)
32766
+ (0, import_node_crypto13.createHash)("sha256").update(profileIdentity).digest("hex").slice(0, 16)
32675
32767
  ) : void 0;
32676
32768
  return {
32677
32769
  useDefaultUserData,
@@ -35035,7 +35127,7 @@ async function attemptOfficialCodexManagedLiveLogin(args2) {
35035
35127
  }
35036
35128
  }
35037
35129
  async function applyOfficialCodexLiveAccountSwitchOnce(options = {}, takeoverTrace = {
35038
- operationId: (0, import_node_crypto12.randomUUID)(),
35130
+ operationId: (0, import_node_crypto13.randomUUID)(),
35039
35131
  attempt: 1
35040
35132
  }) {
35041
35133
  let expectedWindowPreflight = options.expectedWindowPreflight;
@@ -36104,7 +36196,7 @@ async function applyOfficialCodexLiveAccountSwitchOnce(options = {}, takeoverTra
36104
36196
  }
36105
36197
  function applyOfficialCodexLiveAccountSwitch(options = {}) {
36106
36198
  return enqueueProfileAction("shared-window", () => withProfileLaunchFileLock(resolveDefaultCodexHomeDir(), async () => {
36107
- const operationId = (0, import_node_crypto12.randomUUID)();
36199
+ const operationId = (0, import_node_crypto13.randomUUID)();
36108
36200
  let result2 = await applyOfficialCodexLiveAccountSwitchOnce(options, {
36109
36201
  operationId,
36110
36202
  attempt: 1
@@ -36784,16 +36876,16 @@ async function launchOfficialCodexProfileInstanceOnce(options) {
36784
36876
  }
36785
36877
 
36786
36878
  // ../../packages/runtime-app-state/src/app/profileHomeMutationCoordinator.ts
36787
- var import_node_crypto13 = require("crypto");
36879
+ var import_node_crypto14 = require("crypto");
36788
36880
 
36789
36881
  // ../../packages/runtime-app-state/src/app/processOwner.ts
36790
- var import_node_child_process8 = require("child_process");
36882
+ var import_node_child_process7 = require("child_process");
36791
36883
  function readProcessStartedAt(pid) {
36792
36884
  if (!Number.isSafeInteger(pid) || pid <= 0) {
36793
36885
  return null;
36794
36886
  }
36795
36887
  try {
36796
- const output = (0, import_node_child_process8.execFileSync)("/bin/ps", ["-p", String(pid), "-o", "lstart="], {
36888
+ const output = (0, import_node_child_process7.execFileSync)("/bin/ps", ["-p", String(pid), "-o", "lstart="], {
36797
36889
  encoding: "utf8",
36798
36890
  timeout: 2e3
36799
36891
  }).trim();
@@ -36822,12 +36914,12 @@ function isProcessEpochAlive(pid, expectedStartedAt) {
36822
36914
  // ../../packages/runtime-app-state/src/app/profileHomeMutationCoordinator.ts
36823
36915
  var PROFILE_HOME_MUTATION_TTL_MS = 10 * 60 * 1e3;
36824
36916
  var PROFILE_HOME_MUTATION_RENEW_MS = 30 * 1e3;
36825
- var PROCESS_OWNER_ID = (0, import_node_crypto13.randomUUID)();
36917
+ var PROCESS_OWNER_ID = (0, import_node_crypto14.randomUUID)();
36826
36918
  var PROCESS_STARTED_AT = readProcessStartedAt(process.pid);
36827
36919
  var activeRenewals = /* @__PURE__ */ new Map();
36828
36920
  async function acquireProfileHomeMutationIntent(input) {
36829
36921
  const now2 = Date.now();
36830
- const operationId = (0, import_node_crypto13.randomUUID)();
36922
+ const operationId = (0, import_node_crypto14.randomUUID)();
36831
36923
  const renewal = {
36832
36924
  timer: void 0,
36833
36925
  pending: Promise.resolve(),
@@ -37049,7 +37141,7 @@ var AUTH_MUTATION_MANIFEST_NAME = ".codexuse-auth-transaction.json";
37049
37141
  var AUTH_MUTATION_BACKUP_NAME = ".codexuse-auth-transaction.backup";
37050
37142
  var AUTH_MUTATION_REPLACED_NAME = ".codexuse-auth-transaction.replaced";
37051
37143
  var PROFILE_HOME_MUTATION_MARKER_TTL_MS = 10 * 60 * 1e3;
37052
- var PROCESS_OWNER_ID2 = (0, import_node_crypto14.randomUUID)();
37144
+ var PROCESS_OWNER_ID2 = (0, import_node_crypto15.randomUUID)();
37053
37145
  var PROCESS_STARTED_AT2 = readProcessStartedAt(process.pid);
37054
37146
  var globalAuthSwapLock = Promise.resolve();
37055
37147
  var profileOperationLocks = /* @__PURE__ */ new Map();
@@ -37902,7 +37994,7 @@ var ProfileManager = class {
37902
37994
  let attempt = 0;
37903
37995
  let homeId;
37904
37996
  do {
37905
- homeId = `legacy-${(0, import_node_crypto14.createHash)("sha256").update(profileName).update("\0").update(String(attempt)).digest("hex").slice(0, 32)}`;
37997
+ homeId = `legacy-${(0, import_node_crypto15.createHash)("sha256").update(profileName).update("\0").update(String(attempt)).digest("hex").slice(0, 32)}`;
37906
37998
  attempt += 1;
37907
37999
  } while (profileNamesByHomeId.has(homeId.toLowerCase()));
37908
38000
  homeIdsByProfileName.set(profileName, homeId);
@@ -38112,7 +38204,7 @@ var ProfileManager = class {
38112
38204
  const dir = import_path.default.dirname(filePath);
38113
38205
  const tempPath = import_path.default.join(
38114
38206
  dir,
38115
- `.${import_path.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto14.randomUUID)()}.tmp`
38207
+ `.${import_path.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto15.randomUUID)()}.tmp`
38116
38208
  );
38117
38209
  await import_fs.promises.mkdir(dir, { recursive: true, mode: 448 });
38118
38210
  if (process.platform !== "win32") {
@@ -38399,7 +38491,7 @@ var ProfileManager = class {
38399
38491
  if (content === null) {
38400
38492
  return null;
38401
38493
  }
38402
- return (0, import_node_crypto14.createHash)("sha256").update(content).digest("hex");
38494
+ return (0, import_node_crypto15.createHash)("sha256").update(content).digest("hex");
38403
38495
  }
38404
38496
  async readOptionalFile(filePath) {
38405
38497
  try {
@@ -38457,7 +38549,7 @@ var ProfileManager = class {
38457
38549
  const dir = import_path.default.dirname(filePath);
38458
38550
  const tempPath = import_path.default.join(
38459
38551
  dir,
38460
- `.${import_path.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto14.randomUUID)()}.install`
38552
+ `.${import_path.default.basename(filePath)}.${process.pid}.${(0, import_node_crypto15.randomUUID)()}.install`
38461
38553
  );
38462
38554
  const handle = await import_fs.promises.open(tempPath, "wx", 384);
38463
38555
  try {
@@ -38577,7 +38669,7 @@ var ProfileManager = class {
38577
38669
  });
38578
38670
  const manifest = {
38579
38671
  version: 1,
38580
- id: (0, import_node_crypto14.randomUUID)(),
38672
+ id: (0, import_node_crypto15.randomUUID)(),
38581
38673
  operation,
38582
38674
  phase: "prepared",
38583
38675
  sourceFingerprint: this.fingerprintAuthContent(sourceRaw),
@@ -39319,7 +39411,7 @@ var ProfileManager = class {
39319
39411
  const displayName = typeof options?.displayName === "string" && options.displayName.trim().length > 0 ? options.displayName.trim() : existingRecord?.displayName ?? resolvedName;
39320
39412
  const record2 = {
39321
39413
  name: resolvedName,
39322
- homeId: existingRecord?.homeId ?? (options?.homeId ? this.normalizeProfileHomeId(options.homeId, resolvedName) : (0, import_node_crypto14.randomUUID)()),
39414
+ homeId: existingRecord?.homeId ?? (options?.homeId ? this.normalizeProfileHomeId(options.homeId, resolvedName) : (0, import_node_crypto15.randomUUID)()),
39323
39415
  cloudHomeId: existingRecord?.cloudHomeId ?? null,
39324
39416
  displayName,
39325
39417
  data,
@@ -39424,7 +39516,7 @@ var ProfileManager = class {
39424
39516
  const safeName = record2.name.replace(/[^A-Za-z0-9._-]+/g, "-").slice(0, 48) || "profile";
39425
39517
  const destination = import_path.default.join(
39426
39518
  trashRoot,
39427
- `CodexUse-${safeName}-${(0, import_node_crypto14.randomUUID)()}`
39519
+ `CodexUse-${safeName}-${(0, import_node_crypto15.randomUUID)()}`
39428
39520
  );
39429
39521
  await import_fs.promises.rename(profileHome, destination);
39430
39522
  return destination;
@@ -39852,7 +39944,7 @@ var ProfileManager = class {
39852
39944
  async acquireProfileRuntimeLease(record2) {
39853
39945
  const leaseDir = this.getProfileRuntimeLeaseDir(record2.homeId);
39854
39946
  const deletingPath = (0, import_path2.join)(leaseDir, ".deleting");
39855
- const leaseId = (0, import_node_crypto14.randomUUID)();
39947
+ const leaseId = (0, import_node_crypto15.randomUUID)();
39856
39948
  const leasePath = (0, import_path2.join)(leaseDir, `${leaseId}.json`);
39857
39949
  const backupPath = (0, import_path2.join)(leaseDir, `${leaseId}.auth.backup`);
39858
39950
  const releaseIntent = await this.acquireProfileHomeWriteIntent(record2);
@@ -40063,7 +40155,7 @@ var ProfileManager = class {
40063
40155
  async acquireProfileHomeMutationGuard(record2) {
40064
40156
  const leaseDir = this.getProfileRuntimeLeaseDir(record2.homeId);
40065
40157
  const deletingPath = (0, import_path2.join)(leaseDir, ".deleting");
40066
- const mutationId = (0, import_node_crypto14.randomUUID)();
40158
+ const mutationId = (0, import_node_crypto15.randomUUID)();
40067
40159
  const mutationIntent = await acquireProfileHomeMutationIntent({
40068
40160
  homeId: record2.homeId,
40069
40161
  profileName: record2.name
@@ -41442,8 +41534,8 @@ var ProfileManager = class {
41442
41534
  if (mappedHomeId !== void 0 && !isSafeProfileHomePathSegment(mappedHomeId)) {
41443
41535
  throw new Error(`Cloud Sync restore contains an invalid profile home id.`);
41444
41536
  }
41445
- const homeId = mappedHomeId ?? (0, import_node_crypto14.randomUUID)();
41446
- const cloudHomeId = remoteHomeId || existing?.cloudHomeId || existing?.homeId || renamedExisting?.cloudHomeId || renamedExisting?.homeId || (0, import_node_crypto14.randomUUID)();
41537
+ const homeId = mappedHomeId ?? (0, import_node_crypto15.randomUUID)();
41538
+ const cloudHomeId = remoteHomeId || existing?.cloudHomeId || existing?.homeId || renamedExisting?.cloudHomeId || renamedExisting?.homeId || (0, import_node_crypto15.randomUUID)();
41447
41539
  const sourceRecord = renamedExisting ?? existing;
41448
41540
  if (sourceRecord) {
41449
41541
  sourceHomeIdByTargetHomeId.set(homeId, sourceRecord.homeId);
@@ -42408,13 +42500,13 @@ async function listApiKeys(stateDir) {
42408
42500
  return Object.values(store.apiKeysById).filter((key) => key.revokedAt === null).sort((left, right) => right.createdAt.localeCompare(left.createdAt)).map(accountPoolApiKeyView);
42409
42501
  }
42410
42502
  function hashToken(token) {
42411
- return (0, import_node_crypto15.createHash)("sha256").update(token).digest("hex");
42503
+ return (0, import_node_crypto16.createHash)("sha256").update(token).digest("hex");
42412
42504
  }
42413
42505
  async function createApiKey(stateDir) {
42414
- const plaintextToken = `cux_pool_${(0, import_node_crypto15.randomBytes)(24).toString("hex")}`;
42506
+ const plaintextToken = `cux_pool_${(0, import_node_crypto16.randomBytes)(24).toString("hex")}`;
42415
42507
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
42416
42508
  const keyRecord = {
42417
- id: (0, import_node_crypto15.randomUUID)(),
42509
+ id: (0, import_node_crypto16.randomUUID)(),
42418
42510
  tokenHash: hashToken(plaintextToken),
42419
42511
  tokenPreview: `${plaintextToken.slice(0, 8)}...${plaintextToken.slice(-6)}`,
42420
42512
  createdAt: now2,
@@ -42919,7 +43011,7 @@ async function handleAccountPoolCommand(args2, version) {
42919
43011
  }
42920
43012
 
42921
43013
  // src/commands/codex.ts
42922
- var import_node_child_process10 = require("child_process");
43014
+ var import_node_child_process9 = require("child_process");
42923
43015
  var import_node_os6 = __toESM(require("os"));
42924
43016
 
42925
43017
  // ../../packages/runtime-profiles/src/profiles/rate-limit-notifier.ts
@@ -43130,7 +43222,7 @@ async function resolveWorkspaceProfileBinding(requestedPath) {
43130
43222
  }
43131
43223
 
43132
43224
  // src/platform/codexCli.ts
43133
- var import_node_child_process9 = require("child_process");
43225
+ var import_node_child_process8 = require("child_process");
43134
43226
  var import_node_fs12 = require("fs");
43135
43227
  var import_node_path17 = __toESM(require("path"));
43136
43228
  var ENV_HINTS2 = ["CODEX_BINARY", "CODEX_CLI_PATH", "CODEX_PATH"];
@@ -43202,7 +43294,7 @@ async function runCodexLogin(mode, envOverrides = {}) {
43202
43294
  const resolvedMode = resolveLoginMode(mode ?? null);
43203
43295
  const loginArgs = resolvedMode === "device" ? ["login", "--device-auth"] : ["login"];
43204
43296
  const { command, args: args2, shell } = buildCodexCommand2(codexPath, loginArgs);
43205
- const child = (0, import_node_child_process9.spawn)(command, args2, {
43297
+ const child = (0, import_node_child_process8.spawn)(command, args2, {
43206
43298
  stdio: "inherit",
43207
43299
  env: { ...process.env, ...envOverrides },
43208
43300
  shell
@@ -43271,7 +43363,7 @@ function compareCandidates(left, right) {
43271
43363
  async function runCommand3(codexPath, args2, timeoutMs) {
43272
43364
  const command = buildCodexCommand2(codexPath, args2);
43273
43365
  return new Promise((resolve2) => {
43274
- const child = (0, import_node_child_process10.spawn)(command.command, command.args, {
43366
+ const child = (0, import_node_child_process9.spawn)(command.command, command.args, {
43275
43367
  env: process.env,
43276
43368
  shell: command.shell,
43277
43369
  stdio: ["ignore", "pipe", "pipe"]
@@ -43360,7 +43452,7 @@ async function runCodexWithProfile(manager, profileName, codexArgs) {
43360
43452
  });
43361
43453
  const command = buildCodexCommand2(codexPath, codexArgs);
43362
43454
  try {
43363
- const child = (0, import_node_child_process10.spawn)(command.command, command.args, {
43455
+ const child = (0, import_node_child_process9.spawn)(command.command, command.args, {
43364
43456
  env: runtime.env,
43365
43457
  shell: command.shell,
43366
43458
  stdio: "inherit"
@@ -43611,12 +43703,12 @@ var import_node_os7 = __toESM(require("os"));
43611
43703
  var import_node_path19 = __toESM(require("path"));
43612
43704
 
43613
43705
  // ../../packages/runtime-app-state/src/app/officialCodexSwitchCoordinator.ts
43614
- var import_node_crypto16 = require("crypto");
43706
+ var import_node_crypto17 = require("crypto");
43615
43707
  var import_node_fs13 = require("fs");
43616
43708
  var import_node_path18 = __toESM(require("path"), 1);
43617
43709
  var DEFAULT_SWITCH_INTENT_TTL_MS = 10 * 60 * 1e3;
43618
43710
  var SWITCH_INTENT_RENEW_MS = 30 * 1e3;
43619
- var PROCESS_OWNER_ID3 = (0, import_node_crypto16.randomUUID)();
43711
+ var PROCESS_OWNER_ID3 = (0, import_node_crypto17.randomUUID)();
43620
43712
  var PROCESS_STARTED_AT3 = readProcessStartedAt(process.pid);
43621
43713
  var localIntentDepth = /* @__PURE__ */ new Map();
43622
43714
  var pendingLocalIntentAcquisitions = /* @__PURE__ */ new Map();
@@ -43626,7 +43718,7 @@ function nextSwitchIntentGeneration(current) {
43626
43718
  }
43627
43719
  async function acquireOfficialCodexSwitchIntent(input) {
43628
43720
  const now2 = Date.now();
43629
- const operationId = input.operationId?.trim() || (0, import_node_crypto16.randomUUID)();
43721
+ const operationId = input.operationId?.trim() || (0, import_node_crypto17.randomUUID)();
43630
43722
  const targetProfileName = input.targetProfileName.trim();
43631
43723
  if (!targetProfileName) {
43632
43724
  throw new Error("Profile name is required");
@@ -45945,7 +46037,7 @@ async function pushRemoteSnapshot(access, snapshot2, options) {
45945
46037
 
45946
46038
  // ../../packages/runtime-profiles/src/cloud-sync/journal.ts
45947
46039
  var import_node_fs15 = require("fs");
45948
- var import_node_crypto17 = require("crypto");
46040
+ var import_node_crypto18 = require("crypto");
45949
46041
  var import_node_path20 = __toESM(require("path"), 1);
45950
46042
  var JOURNAL_FILENAME = "cloud-sync-pull.journal.json";
45951
46043
  function getCloudSyncJournalPath() {
@@ -45964,7 +46056,7 @@ async function writeCloudSyncJournal(journal) {
45964
46056
  const dir = import_node_path20.default.dirname(target);
45965
46057
  await import_node_fs15.promises.mkdir(dir, { recursive: true, mode: 448 });
45966
46058
  await import_node_fs15.promises.chmod(dir, 448);
45967
- const staging = `${target}.tmp-${process.pid}-${(0, import_node_crypto17.randomUUID)()}`;
46059
+ const staging = `${target}.tmp-${process.pid}-${(0, import_node_crypto18.randomUUID)()}`;
45968
46060
  await import_node_fs15.promises.writeFile(staging, JSON.stringify(journal), {
45969
46061
  encoding: "utf8",
45970
46062
  flag: "wx",
@@ -45988,10 +46080,8 @@ async function clearCloudSyncJournal() {
45988
46080
  }
45989
46081
 
45990
46082
  // ../../packages/runtime-profiles/src/cloud-sync/encryption.ts
45991
- var import_node_child_process11 = require("child_process");
45992
- var import_node_crypto18 = require("crypto");
45993
- var KEYCHAIN_SERVICE2 = "CODEXUSE_CLOUD_SYNC_PASSPHRASE";
45994
- var KEYCHAIN_ACCOUNT_PREFIX2 = "license-sha256:";
46083
+ var import_node_crypto19 = require("crypto");
46084
+ var REMEMBERED_PASSPHRASE_PREFIX = "cloud-sync-passphrase:";
45995
46085
  var ENCRYPTION_AAD = Buffer.from("codexuse-cloud-sync-v2", "utf8");
45996
46086
  var SCRYPT_PARAMS = {
45997
46087
  N: 32768,
@@ -46014,7 +46104,7 @@ function requireCloudSyncPassphrase(value3) {
46014
46104
  }
46015
46105
  async function deriveKey(passphrase, salt, params = SCRYPT_PARAMS) {
46016
46106
  return new Promise((resolve2, reject) => {
46017
- (0, import_node_crypto18.scrypt)(passphrase, salt, params.keyLength, {
46107
+ (0, import_node_crypto19.scrypt)(passphrase, salt, params.keyLength, {
46018
46108
  N: params.N,
46019
46109
  r: params.r,
46020
46110
  p: params.p,
@@ -46051,10 +46141,10 @@ function normalizeDecryptedSnapshot(value3) {
46051
46141
  };
46052
46142
  }
46053
46143
  async function encryptCloudSyncSnapshot(snapshot2, passphrase) {
46054
- const salt = (0, import_node_crypto18.randomBytes)(16);
46055
- const iv = (0, import_node_crypto18.randomBytes)(12);
46144
+ const salt = (0, import_node_crypto19.randomBytes)(16);
46145
+ const iv = (0, import_node_crypto19.randomBytes)(12);
46056
46146
  const key = await deriveKey(requireCloudSyncPassphrase(passphrase), salt);
46057
- const cipher = (0, import_node_crypto18.createCipheriv)("aes-256-gcm", key, iv);
46147
+ const cipher = (0, import_node_crypto19.createCipheriv)("aes-256-gcm", key, iv);
46058
46148
  cipher.setAAD(ENCRYPTION_AAD);
46059
46149
  const plaintext = Buffer.from(JSON.stringify(snapshot2), "utf8");
46060
46150
  const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
@@ -46081,7 +46171,7 @@ async function decryptCloudSyncSnapshot(snapshot2, passphrase) {
46081
46171
  const tag2 = fromBase64(snapshot2.encryption.tag);
46082
46172
  const ciphertext = fromBase64(snapshot2.encryption.ciphertext);
46083
46173
  const key = await deriveKey(requireCloudSyncPassphrase(passphrase), salt, snapshot2.encryption.kdfParams);
46084
- const decipher = (0, import_node_crypto18.createDecipheriv)("aes-256-gcm", key, iv);
46174
+ const decipher = (0, import_node_crypto19.createDecipheriv)("aes-256-gcm", key, iv);
46085
46175
  decipher.setAAD(ENCRYPTION_AAD);
46086
46176
  decipher.setAuthTag(tag2);
46087
46177
  const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
@@ -46095,60 +46185,16 @@ async function decryptCloudSyncSnapshot(snapshot2, passphrase) {
46095
46185
  throw wrapped;
46096
46186
  }
46097
46187
  }
46098
- function keychainAccountForLicense(licenseKey) {
46099
- const digest = (0, import_node_crypto18.createHash)("sha256").update(licenseKey).digest("hex");
46100
- return KEYCHAIN_ACCOUNT_PREFIX2 + digest;
46101
- }
46102
- function runSecurityCommand2(args2) {
46103
- return new Promise((resolve2, reject) => {
46104
- const child = (0, import_node_child_process11.spawn)("security", args2, { stdio: ["ignore", "pipe", "ignore"] });
46105
- let stdout = "";
46106
- child.stdout?.on("data", (chunk) => {
46107
- stdout += String(chunk);
46108
- });
46109
- child.on("error", () => {
46110
- reject(new Error("keychain-command-failed"));
46111
- });
46112
- child.on("close", (code) => {
46113
- resolve2({ code, stdout });
46114
- });
46115
- });
46188
+ function rememberedPassphraseName(licenseKey) {
46189
+ const digest = (0, import_node_crypto19.createHash)("sha256").update(licenseKey).digest("hex");
46190
+ return REMEMBERED_PASSPHRASE_PREFIX + digest;
46116
46191
  }
46117
46192
  async function readRememberedCloudSyncPassphrase(licenseKey) {
46118
- if (process.platform !== "darwin") {
46119
- return null;
46120
- }
46121
- const result2 = await runSecurityCommand2([
46122
- "find-generic-password",
46123
- "-a",
46124
- keychainAccountForLicense(licenseKey),
46125
- "-s",
46126
- KEYCHAIN_SERVICE2,
46127
- "-w"
46128
- ]);
46129
- if (result2.code !== 0) {
46130
- return null;
46131
- }
46132
- return result2.stdout.length > 0 ? result2.stdout.replace(/\n$/, "") : null;
46193
+ return readLocalSecret(rememberedPassphraseName(licenseKey));
46133
46194
  }
46134
46195
  async function writeRememberedCloudSyncPassphrase(licenseKey, passphrase) {
46135
- if (process.platform !== "darwin") {
46136
- throw new Error("keychain-unsupported");
46137
- }
46138
46196
  const value3 = requireCloudSyncPassphrase(passphrase);
46139
- const result2 = await runSecurityCommand2([
46140
- "add-generic-password",
46141
- "-U",
46142
- "-a",
46143
- keychainAccountForLicense(licenseKey),
46144
- "-s",
46145
- KEYCHAIN_SERVICE2,
46146
- "-w",
46147
- value3
46148
- ]);
46149
- if (result2.code !== 0) {
46150
- throw new Error("keychain-write-failed");
46151
- }
46197
+ await writeLocalSecret(rememberedPassphraseName(licenseKey), value3);
46152
46198
  }
46153
46199
 
46154
46200
  // ../../packages/runtime-profiles/src/cloud-sync/service.ts
@@ -46539,7 +46585,7 @@ async function resolvePassphrase(licenseKey, options) {
46539
46585
  }
46540
46586
  const remembered = await readRememberedCloudSyncPassphrase(licenseKey);
46541
46587
  if (remembered) {
46542
- return { value: remembered, source: "keychain" };
46588
+ return { value: remembered, source: "local" };
46543
46589
  }
46544
46590
  throw new Error("Cloud Sync passphrase is required.");
46545
46591
  }
@@ -46550,7 +46596,7 @@ async function rememberPassphraseIfRequested(licenseKey, options, passphrase) {
46550
46596
  try {
46551
46597
  await writeRememberedCloudSyncPassphrase(licenseKey, passphrase.value);
46552
46598
  } catch (error) {
46553
- logWarn("[cloud-sync] failed to remember passphrase in keychain", {
46599
+ logWarn("[cloud-sync] failed to remember passphrase locally", {
46554
46600
  error: error instanceof Error ? error.message : String(error)
46555
46601
  });
46556
46602
  }
@@ -46921,7 +46967,7 @@ async function ensureCliStorageReady() {
46921
46967
  }
46922
46968
 
46923
46969
  // src/app/main.ts
46924
- var VERSION = true ? "6.2.2" : "0.0.0";
46970
+ var VERSION = true ? "6.2.3" : "0.0.0";
46925
46971
  async function runCli() {
46926
46972
  const args2 = process.argv.slice(2);
46927
46973
  if (args2.length === 0) {