codexuse-cli 6.1.1 → 6.2.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/README.md CHANGED
@@ -4,6 +4,10 @@ Command-line control for CodexUse profiles: switch Codex accounts, run Codex und
4
4
  profile, and manage Account Pool, licenses, and manual cloud sync. Shares local state with
5
5
  the CodexUse desktop app on the same machine.
6
6
 
7
+ The CLI has a separate macOS, Windows, and Linux route. Codex App window control,
8
+ provider setup, and the desktop Account Pool runtime require the Apple Silicon
9
+ macOS desktop app. The CLI does not provide desktop feature parity.
10
+
7
11
  Install (npm):
8
12
  ```bash
9
13
  npm install -g codexuse-cli
package/dist/index.js CHANGED
@@ -2082,6 +2082,57 @@ var import_node_crypto2 = require("crypto");
2082
2082
  var import_node_path4 = __toESM(require("path"), 1);
2083
2083
  var import_node_os = __toESM(require("os"), 1);
2084
2084
 
2085
+ // ../../packages/contracts/src/license/offer-config.ts
2086
+ function getActiveOffer() {
2087
+ const basePriceUsd = 39;
2088
+ const discountPercent = 50;
2089
+ const salePriceUsd = basePriceUsd * (100 - discountPercent) / 100;
2090
+ return {
2091
+ basePriceUsd,
2092
+ basePriceDisplay: `$${basePriceUsd}`,
2093
+ couponCode: "SUMMER50",
2094
+ discountPercent,
2095
+ salePriceUsd,
2096
+ salePriceDisplay: `$${salePriceUsd.toFixed(2)}`,
2097
+ isActive: true,
2098
+ campaign: "summer-2026",
2099
+ productPermalink: "codex-use",
2100
+ checkoutBaseUrl: "https://hweihwang.gumroad.com/l/codex-use",
2101
+ trialEnabled: true,
2102
+ trialDays: 7
2103
+ };
2104
+ }
2105
+ function buildCheckoutUrl(offer2, options) {
2106
+ const base2 = offer2.checkoutBaseUrl;
2107
+ const withCoupon = offer2.isActive && offer2.couponCode ? `${base2}/${offer2.couponCode}` : base2;
2108
+ const url = new URL(withCoupon);
2109
+ if (options?.directCheckout) {
2110
+ url.searchParams.set("wanted", "true");
2111
+ }
2112
+ if (!options?.source || !options?.medium) {
2113
+ return url.toString();
2114
+ }
2115
+ url.searchParams.set("utm_source", options.source);
2116
+ url.searchParams.set("utm_medium", options.medium);
2117
+ if (options.campaign) {
2118
+ url.searchParams.set("utm_campaign", options.campaign);
2119
+ } else if (offer2.campaign) {
2120
+ url.searchParams.set("utm_campaign", offer2.campaign);
2121
+ }
2122
+ return url.toString();
2123
+ }
2124
+
2125
+ // ../../packages/contracts/src/license/activation-session.ts
2126
+ var ACTIVATION_RETENTION_MS = 24 * 60 * 60 * 1e3;
2127
+ var ACTIVATION_WATCH_MS = 20 * 60 * 1e3;
2128
+ var ACTIVATION_SESSION_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
2129
+ function normalizePendingCheckout(value3) {
2130
+ if (!value3 || typeof value3 !== "object" || Array.isArray(value3)) return null;
2131
+ const { sessionId, startedAt } = value3;
2132
+ if (typeof sessionId !== "string" || !ACTIVATION_SESSION_PATTERN.test(sessionId) || typeof startedAt !== "number" || !Number.isSafeInteger(startedAt) || startedAt <= 0) return null;
2133
+ return { sessionId, startedAt };
2134
+ }
2135
+
2085
2136
  // ../../packages/contracts/src/desktop/llm-compatibility.ts
2086
2137
  var DESKTOP_LLM_CAPABILITY_NAMES = [
2087
2138
  "streamingText",
@@ -3408,6 +3459,7 @@ function resolveStorageDbPath() {
3408
3459
  function createDefaultAppState() {
3409
3460
  return {
3410
3461
  schemaVersion: 1,
3462
+ trialExperience: { knownLicenseHolder: false, pendingInteractiveAt: null, trial: null },
3411
3463
  autoRoll: {
3412
3464
  enabled: false,
3413
3465
  rearmRemainingThreshold: 15,
@@ -3498,7 +3550,8 @@ function createDefaultAppState() {
3498
3550
  proUnlockedCelebrated: false
3499
3551
  },
3500
3552
  duplicateWarningDismissedKey: null,
3501
- pendingLicenseActivation: false
3553
+ pendingLicenseActivation: false,
3554
+ pendingCheckout: null
3502
3555
  },
3503
3556
  profileDashboard: {
3504
3557
  customGroupsByAccountKey: {}
@@ -4110,6 +4163,35 @@ function normalizeOfficialCodexPowerStatus(value3) {
4110
4163
  appliedAt: asString(value3.appliedAt)
4111
4164
  };
4112
4165
  }
4166
+ function normalizeTrialExperience(raw) {
4167
+ const value3 = isRecord2(raw) ? raw : {};
4168
+ const trial = isRecord2(value3.trial) ? value3.trial : {};
4169
+ const startedAt = asString(trial.startedAt);
4170
+ const expiresAt = asString(trial.expiresAt);
4171
+ const start = startedAt ? Date.parse(startedAt) : NaN;
4172
+ const end = expiresAt ? Date.parse(expiresAt) : NaN;
4173
+ const observedAt = asNumberOrNull(trial.observedAt);
4174
+ const valid = startedAt && expiresAt && Number.isFinite(start) && end > start && observedAt !== null && observedAt >= start;
4175
+ const first = isRecord2(trial.firstOutcome) ? trial.firstOutcome : {};
4176
+ const completedAt = asNumberOrNull(first.completedAt);
4177
+ const kind = first.kind;
4178
+ const validKind = kind === "shared_history_switch" || kind === "shared_history_window" || kind === "matched_window" || kind === "provider_window" || kind === "pool_request";
4179
+ const interactiveAt = asNumberOrNull(trial.interactiveAt);
4180
+ const pendingInteractiveAt = asNumberOrNull(value3.pendingInteractiveAt);
4181
+ return {
4182
+ knownLicenseHolder: value3.knownLicenseHolder === true,
4183
+ pendingInteractiveAt: pendingInteractiveAt !== null && pendingInteractiveAt > 0 ? pendingInteractiveAt : null,
4184
+ trial: valid ? {
4185
+ startedAt,
4186
+ expiresAt,
4187
+ observedAt,
4188
+ priorPayment: trial.priorPayment === "known_prior_license" ? "known_prior_license" : "unknown",
4189
+ interactiveAt: interactiveAt !== null && interactiveAt > 0 && interactiveAt < end ? interactiveAt : null,
4190
+ firstOutcome: validKind && completedAt !== null && completedAt >= start && completedAt < end ? { kind, completedAt } : null,
4191
+ entitlementObservedAt: asNumberOrNull(trial.entitlementObservedAt)
4192
+ } : null
4193
+ };
4194
+ }
4113
4195
  function normalizeAppState(raw) {
4114
4196
  const defaults = createDefaultAppState();
4115
4197
  if (!isRecord2(raw)) {
@@ -4120,6 +4202,7 @@ function normalizeAppState(raw) {
4120
4202
  const next = deepMerge(defaults, raw);
4121
4203
  const merged = next;
4122
4204
  merged.schemaVersion = 1;
4205
+ merged.trialExperience = normalizeTrialExperience(raw.trialExperience);
4123
4206
  merged.autoRoll = normalizeAutoRollSettings(rawAutoRoll);
4124
4207
  if (!isRecord2(merged.officialCodex)) {
4125
4208
  merged.officialCodex = clone2(defaults.officialCodex);
@@ -4562,6 +4645,7 @@ function normalizeAppState(raw) {
4562
4645
  if (typeof merged.ui.pendingLicenseActivation !== "boolean") {
4563
4646
  merged.ui.pendingLicenseActivation = false;
4564
4647
  }
4648
+ merged.ui.pendingCheckout = normalizePendingCheckout(merged.ui.pendingCheckout);
4565
4649
  {
4566
4650
  const allowedUiKeys = new Set(Object.keys(defaults.ui));
4567
4651
  for (const key of Object.keys(merged.ui)) {
@@ -5139,27 +5223,35 @@ async function getStoredLicense() {
5139
5223
  const state = await getAppState();
5140
5224
  return parseStoredLicense(state.license);
5141
5225
  }
5142
- async function persistLicense(license) {
5226
+ async function persistLicense(license, expected) {
5143
5227
  const parsed = parseStoredLicense(license);
5144
- await patchAppState({
5145
- license: parsed ? {
5146
- licenseKey: parsed.licenseKey ?? null,
5147
- purchaseEmail: parsed.purchaseEmail ?? null,
5148
- lastVerifiedAt: parsed.lastVerifiedAt ?? null,
5149
- nextCheckAt: parsed.nextCheckAt ?? null,
5150
- lastVerificationError: parsed.lastVerificationError ?? null,
5151
- status: parsed.status ?? "inactive",
5152
- signature: parsed.signature ?? null
5153
- } : {
5154
- licenseKey: null,
5155
- purchaseEmail: null,
5156
- lastVerifiedAt: null,
5157
- nextCheckAt: null,
5158
- lastVerificationError: null,
5159
- status: "inactive",
5160
- signature: null
5228
+ let persisted = false;
5229
+ await updateAppState((current) => {
5230
+ if (expected !== void 0 && JSON.stringify(parseStoredLicense(current.license)) !== JSON.stringify(parseStoredLicense(expected))) {
5231
+ return {};
5161
5232
  }
5233
+ persisted = true;
5234
+ return {
5235
+ license: parsed ? {
5236
+ licenseKey: parsed.licenseKey ?? null,
5237
+ purchaseEmail: parsed.purchaseEmail ?? null,
5238
+ lastVerifiedAt: parsed.lastVerifiedAt ?? null,
5239
+ nextCheckAt: parsed.nextCheckAt ?? null,
5240
+ lastVerificationError: parsed.lastVerificationError ?? null,
5241
+ status: parsed.status ?? "inactive",
5242
+ signature: parsed.signature ?? null
5243
+ } : {
5244
+ licenseKey: null,
5245
+ purchaseEmail: null,
5246
+ lastVerifiedAt: null,
5247
+ nextCheckAt: null,
5248
+ lastVerificationError: null,
5249
+ status: "inactive",
5250
+ signature: null
5251
+ }
5252
+ };
5162
5253
  });
5254
+ return persisted;
5163
5255
  }
5164
5256
  async function getStoredAutoRollSettings() {
5165
5257
  const state = await getAppState();
@@ -5254,46 +5346,6 @@ async function getLicenseSecret() {
5254
5346
  return persistLicenseSecret(dbPath, secret);
5255
5347
  }
5256
5348
 
5257
- // ../../packages/contracts/src/license/offer-config.ts
5258
- function getActiveOffer() {
5259
- const basePriceUsd = 39;
5260
- const discountPercent = 50;
5261
- const salePriceUsd = basePriceUsd * (100 - discountPercent) / 100;
5262
- return {
5263
- basePriceUsd,
5264
- basePriceDisplay: `$${basePriceUsd}`,
5265
- couponCode: "SUMMER50",
5266
- discountPercent,
5267
- salePriceUsd,
5268
- salePriceDisplay: `$${salePriceUsd.toFixed(2)}`,
5269
- isActive: true,
5270
- campaign: "summer-2026",
5271
- productPermalink: "codex-use",
5272
- checkoutBaseUrl: "https://hweihwang.gumroad.com/l/codex-use",
5273
- trialEnabled: true,
5274
- trialDays: 7
5275
- };
5276
- }
5277
- function buildCheckoutUrl(offer2, options) {
5278
- const base2 = offer2.checkoutBaseUrl;
5279
- const withCoupon = offer2.isActive && offer2.couponCode ? `${base2}/${offer2.couponCode}` : base2;
5280
- const url = new URL(withCoupon);
5281
- if (options?.directCheckout) {
5282
- url.searchParams.set("wanted", "true");
5283
- }
5284
- if (!options?.source || !options?.medium) {
5285
- return url.toString();
5286
- }
5287
- url.searchParams.set("utm_source", options.source);
5288
- url.searchParams.set("utm_medium", options.medium);
5289
- if (options.campaign) {
5290
- url.searchParams.set("utm_campaign", options.campaign);
5291
- } else if (offer2.campaign) {
5292
- url.searchParams.set("utm_campaign", offer2.campaign);
5293
- }
5294
- return url.toString();
5295
- }
5296
-
5297
5349
  // ../../packages/runtime-profiles/src/license/trial.ts
5298
5350
  var import_node_crypto6 = __toESM(require("crypto"), 1);
5299
5351
 
@@ -5562,6 +5614,7 @@ function buildTrialInfo(stored, now2) {
5562
5614
  const expired = stored?.serverExpired === true || expiresAtMs === null || expiresAtMs <= now2;
5563
5615
  const daysLeft = expired || expiresAtMs === null ? 0 : Math.max(0, Math.ceil((expiresAtMs - now2) / DAY_MS));
5564
5616
  return {
5617
+ startedAt: stored?.startedAt ?? null,
5565
5618
  active: !expired,
5566
5619
  expired,
5567
5620
  expiresAt: stored?.expiresAt ?? null,
@@ -5573,6 +5626,7 @@ function lockReasonFor(info) {
5573
5626
  }
5574
5627
  function buildLockedTrialInfo(stored) {
5575
5628
  return {
5629
+ startedAt: null,
5576
5630
  active: false,
5577
5631
  expired: true,
5578
5632
  expiresAt: stored?.expiresAt ?? null,
@@ -6078,6 +6132,7 @@ var LicenseService = class {
6078
6132
  constructor() {
6079
6133
  this.refreshPromise = null;
6080
6134
  this.verificationPromise = null;
6135
+ this.activationTail = Promise.resolve();
6081
6136
  }
6082
6137
  async getCachedStatus() {
6083
6138
  try {
@@ -6129,8 +6184,10 @@ var LicenseService = class {
6129
6184
  nextCheckAt: new Date(cappedNextCheckTs).toISOString()
6130
6185
  };
6131
6186
  const signed = withSignature(updated, secret);
6187
+ if (!await persistLicense(signed, workingStored)) {
6188
+ return this.getStatus({ allowStale: true });
6189
+ }
6132
6190
  workingStored = signed;
6133
- await persistLicense(signed);
6134
6191
  }
6135
6192
  const tampered = Boolean(workingStored.licenseKey) && !signatureValid;
6136
6193
  const cached2 = tampered ? toLicenseStatus(null, {
@@ -6161,7 +6218,9 @@ var LicenseService = class {
6161
6218
  lastVerificationError: null
6162
6219
  };
6163
6220
  const signed = withSignature(updated, secret);
6164
- await persistLicense(signed);
6221
+ if (!await persistLicense(signed, workingStored)) {
6222
+ return this.getStatus({ allowStale: true });
6223
+ }
6165
6224
  return finalize2(toLicenseStatus(signed));
6166
6225
  } catch (error) {
6167
6226
  const message = error instanceof Error ? error.message : "License verification failed.";
@@ -6175,7 +6234,9 @@ var LicenseService = class {
6175
6234
  },
6176
6235
  secret
6177
6236
  );
6178
- await persistLicense(fallbackStored2);
6237
+ if (!await persistLicense(fallbackStored2, workingStored)) {
6238
+ return this.getStatus({ allowStale: true });
6239
+ }
6179
6240
  const fallback = toLicenseStatus(fallbackStored2, {
6180
6241
  state: fallbackStored2.status ?? "grace",
6181
6242
  error: message
@@ -6190,7 +6251,9 @@ var LicenseService = class {
6190
6251
  status: "inactive",
6191
6252
  lastVerificationError: message
6192
6253
  }, secret);
6193
- await persistLicense(fallbackStored);
6254
+ if (!await persistLicense(fallbackStored, workingStored)) {
6255
+ return this.getStatus({ allowStale: true });
6256
+ }
6194
6257
  return finalize2(toLicenseStatus(fallbackStored, { error: message }));
6195
6258
  }
6196
6259
  };
@@ -6202,6 +6265,23 @@ var LicenseService = class {
6202
6265
  }
6203
6266
  }
6204
6267
  async activate(licenseKey) {
6268
+ return (await this.queueActivation(licenseKey, false)).license;
6269
+ }
6270
+ activateFromCheckout(licenseKey) {
6271
+ return this.queueActivation(licenseKey, true);
6272
+ }
6273
+ queueActivation(licenseKey, onlyIfUnlicensed) {
6274
+ const result2 = this.activationTail.then(async () => {
6275
+ if (onlyIfUnlicensed) {
6276
+ const current = await this.getCachedStatus();
6277
+ if (current.isPro) return { license: current, activated: false };
6278
+ }
6279
+ return { license: await this.performActivation(licenseKey), activated: true };
6280
+ });
6281
+ this.activationTail = result2.then(() => void 0, () => void 0);
6282
+ return result2;
6283
+ }
6284
+ async performActivation(licenseKey) {
6205
6285
  const trimmed = licenseKey.trim();
6206
6286
  if (!trimmed) {
6207
6287
  throw new Error("License key is required.");
@@ -23636,6 +23716,7 @@ var RPC_METHODS = {
23636
23716
  runtimeRefreshProviders: "runtime.refreshProviders",
23637
23717
  appStateGet: "appState.get",
23638
23718
  appStatePatch: "appState.patch",
23719
+ trialExperienceStart: "trialExperience.start",
23639
23720
  appSettingsGet: "appSettings.get",
23640
23721
  appSettingsUpdate: "appSettings.update",
23641
23722
  officialCodexSetAutoControl: "officialCodex.setAutoControl",
@@ -23819,6 +23900,7 @@ var DesktopRpcRequestBody = Schema_exports.Union([
23819
23900
  // Desktop dashboard/runtime methods
23820
23901
  tagRequestBody(RPC_METHODS.appStateGet, Schema_exports.Struct({})),
23821
23902
  tagRequestBody(RPC_METHODS.appStatePatch, Schema_exports.Struct({ patch: Schema_exports.Unknown })),
23903
+ tagRequestBody(RPC_METHODS.trialExperienceStart, Schema_exports.Struct({ interactiveAt: Schema_exports.Number })),
23822
23904
  tagRequestBody(RPC_METHODS.appSettingsGet, Schema_exports.Struct({})),
23823
23905
  tagRequestBody(
23824
23906
  RPC_METHODS.appSettingsUpdate,
@@ -46458,7 +46540,7 @@ async function ensureCliStorageReady() {
46458
46540
  }
46459
46541
 
46460
46542
  // src/app/main.ts
46461
- var VERSION = true ? "6.1.1" : "0.0.0";
46543
+ var VERSION = true ? "6.2.0" : "0.0.0";
46462
46544
  async function runCli() {
46463
46545
  const args2 = process.argv.slice(2);
46464
46546
  if (args2.length === 0) {