codexuse-cli 5.2.4 → 5.2.6

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
@@ -5932,188 +5932,6 @@ async function buildSnapshot(content, exists, options) {
5932
5932
  diagnostics
5933
5933
  };
5934
5934
  }
5935
- function sanitizeString(value) {
5936
- if (value === null || value === void 0) {
5937
- return null;
5938
- }
5939
- const trimmed = value.trim();
5940
- return trimmed.length > 0 ? trimmed : null;
5941
- }
5942
- function sanitizeNumber(value) {
5943
- if (value === void 0 || value === null) {
5944
- return null;
5945
- }
5946
- if (!Number.isFinite(value)) {
5947
- throw new Error("Numeric value must be finite.");
5948
- }
5949
- return value;
5950
- }
5951
- function normalizeStringRecordInput(record) {
5952
- if (!record) {
5953
- return null;
5954
- }
5955
- const normalized = {};
5956
- for (const [key, value] of Object.entries(record)) {
5957
- const normalizedKey = sanitizeString(key);
5958
- const normalizedValue = sanitizeString(value);
5959
- if (normalizedKey && normalizedValue) {
5960
- normalized[normalizedKey] = normalizedValue;
5961
- }
5962
- }
5963
- return Object.keys(normalized).length > 0 ? normalized : null;
5964
- }
5965
- function applySuggestedFixes(current, fixIds) {
5966
- if (!fixIds || fixIds.length === 0) {
5967
- return current;
5968
- }
5969
- let next = { ...current };
5970
- for (const fixId of fixIds) {
5971
- if (!fixId.startsWith("remove-feature:")) {
5972
- continue;
5973
- }
5974
- const featureKey = fixId.slice("remove-feature:".length).trim();
5975
- if (!featureKey) {
5976
- continue;
5977
- }
5978
- const rawFeatures = typeof next["features"] === "object" && next["features"] !== null && !Array.isArray(next["features"]) ? { ...next["features"] } : {};
5979
- if (!Object.prototype.hasOwnProperty.call(rawFeatures, featureKey)) {
5980
- continue;
5981
- }
5982
- delete rawFeatures[featureKey];
5983
- if (Object.keys(rawFeatures).length === 0) {
5984
- delete next["features"];
5985
- } else {
5986
- next["features"] = rawFeatures;
5987
- }
5988
- }
5989
- return next;
5990
- }
5991
- function applyUpdatesToConfig(current, updates) {
5992
- const next = { ...current };
5993
- const applyStringField = (key, candidate) => {
5994
- if (candidate === void 0) {
5995
- return;
5996
- }
5997
- const normalized = sanitizeString(candidate);
5998
- if (!normalized) {
5999
- delete next[key];
6000
- } else {
6001
- next[key] = normalized;
6002
- }
6003
- };
6004
- const applyNumberField = (key, candidate) => {
6005
- if (candidate === void 0) {
6006
- return;
6007
- }
6008
- const normalized = sanitizeNumber(candidate);
6009
- if (normalized === null) {
6010
- delete next[key];
6011
- } else {
6012
- next[key] = normalized;
6013
- }
6014
- };
6015
- applyStringField("model", updates.model);
6016
- applyStringField("review_model", updates.reviewModel);
6017
- applyStringField("model_reasoning_effort", updates.modelReasoningEffort);
6018
- applyStringField("model_reasoning_summary", updates.modelReasoningSummary);
6019
- applyStringField("model_verbosity", updates.modelVerbosity);
6020
- applyStringField("approval_policy", updates.approvalPolicy);
6021
- applyStringField("sandbox_mode", updates.sandboxMode);
6022
- applyStringField("web_search", updates.webSearch);
6023
- applyStringField("personality", updates.personality);
6024
- applyNumberField("tool_output_token_limit", updates.toolOutputTokenLimit);
6025
- applyNumberField("model_auto_compact_token_limit", updates.modelAutoCompactTokenLimit);
6026
- applyNumberField("model_context_window", updates.modelContextWindow);
6027
- if (updates.features) {
6028
- const rawFeatures = typeof next["features"] === "object" && next["features"] !== null && !Array.isArray(next["features"]) ? { ...next["features"] } : {};
6029
- const applyFeatureField = (key, candidate) => {
6030
- if (candidate === void 0) {
6031
- return;
6032
- }
6033
- if (candidate === null) {
6034
- delete rawFeatures[key];
6035
- return;
6036
- }
6037
- rawFeatures[key] = candidate;
6038
- };
6039
- for (const [rawKey, candidate] of Object.entries(updates.features)) {
6040
- const key = rawKey === "unifiedExec" ? "unified_exec" : rawKey === "shellSnapshot" ? "shell_snapshot" : rawKey;
6041
- applyFeatureField(key, candidate);
6042
- }
6043
- if (Object.keys(rawFeatures).length === 0) {
6044
- delete next["features"];
6045
- } else {
6046
- next["features"] = rawFeatures;
6047
- }
6048
- }
6049
- if (updates.tools) {
6050
- const rawTools = typeof next["tools"] === "object" && next["tools"] !== null && !Array.isArray(next["tools"]) ? { ...next["tools"] } : {};
6051
- const applyToolField = (key, candidate) => {
6052
- if (candidate === void 0) {
6053
- return;
6054
- }
6055
- if (candidate === null) {
6056
- delete rawTools[key];
6057
- } else {
6058
- rawTools[key] = candidate;
6059
- }
6060
- };
6061
- applyToolField("web_search", updates.tools.webSearch);
6062
- applyToolField("view_image", updates.tools.viewImage);
6063
- if (Object.keys(rawTools).length === 0) {
6064
- delete next["tools"];
6065
- } else {
6066
- next["tools"] = rawTools;
6067
- }
6068
- }
6069
- if (updates.notice) {
6070
- const rawNotice = next["notice"];
6071
- const currentNotice = rawNotice && typeof rawNotice === "object" && rawNotice !== null ? { ...rawNotice } : {};
6072
- const applyBooleanField = (key, candidate) => {
6073
- if (candidate === void 0) {
6074
- return;
6075
- }
6076
- if (candidate === null) {
6077
- delete currentNotice[key];
6078
- } else {
6079
- currentNotice[key] = candidate;
6080
- }
6081
- };
6082
- const applyRecordField = (key, candidate) => {
6083
- if (candidate === void 0) {
6084
- return;
6085
- }
6086
- const normalized = normalizeStringRecordInput(candidate);
6087
- if (!normalized) {
6088
- delete currentNotice[key];
6089
- } else {
6090
- currentNotice[key] = normalized;
6091
- }
6092
- };
6093
- applyBooleanField("hide_full_access_warning", updates.notice.hideFullAccessWarning);
6094
- applyBooleanField("hide_gpt5_1_migration_prompt", updates.notice.hideGpt51MigrationPrompt);
6095
- applyBooleanField(
6096
- "hide_gpt-5.1-codex-max_migration_prompt",
6097
- updates.notice.hideLegacyGpt51CodexMaxMigrationPrompt
6098
- );
6099
- applyBooleanField("hide_rate_limit_model_nudge", updates.notice.hideRateLimitModelNudge);
6100
- applyRecordField("model_migrations", updates.notice.modelMigrations);
6101
- if (Object.keys(currentNotice).length === 0) {
6102
- delete next["notice"];
6103
- } else {
6104
- next["notice"] = currentNotice;
6105
- }
6106
- }
6107
- return applySuggestedFixes(next, updates.applyFixes);
6108
- }
6109
- async function readParsedConfigOrThrow(options) {
6110
- const { content } = await readConfigContent(options);
6111
- const parsed = tryParseToml(content);
6112
- if (!parsed.data) {
6113
- throw new Error(parsed.error ?? "config.toml contains invalid TOML syntax.");
6114
- }
6115
- return parsed.data;
6116
- }
6117
5935
  async function getCodexConfigSnapshot(options) {
6118
5936
  const { content, exists } = await readConfigContent(options);
6119
5937
  return buildSnapshot(content, exists, options);
@@ -6127,13 +5945,6 @@ async function saveCodexConfigContent(content, options) {
6127
5945
  await writeConfigContent(normalized, options);
6128
5946
  return buildSnapshot(normalized, true, options);
6129
5947
  }
6130
- async function updateCodexConfigValues(updates, options) {
6131
- const parsed = await readParsedConfigOrThrow(options);
6132
- const updated = applyUpdatesToConfig(parsed, updates);
6133
- const serialized = ensureTrailingNewline((0, import_toml.stringify)(updated));
6134
- await writeConfigContent(serialized, options);
6135
- return buildSnapshot(serialized, true, options);
6136
- }
6137
5948
 
6138
5949
  // ../../packages/shared/src/core/logger.ts
6139
5950
  var isTestEnv = process.env.NODE_ENV === "test" || process.env.VITEST === "true" || process.env.VITEST === "1";
@@ -6163,18 +5974,35 @@ function logInfo(...args) {
6163
5974
  var RPC_TIMEOUT_MS = 1e4;
6164
5975
  var ACTIVATION_TURN_TIMEOUT_MS = 9e4;
6165
5976
  var ACTIVATION_PROMPT = "Reply with exactly: ok.";
6166
- var FALLBACK_ACTIVATION_MODEL = "gpt-5.5";
6167
5977
  function resolveActivationModel(configuredModel) {
6168
5978
  const model = configuredModel?.trim();
6169
5979
  if (!model) {
6170
- return FALLBACK_ACTIVATION_MODEL;
5980
+ return null;
6171
5981
  }
6172
5982
  if (/-codex$/.test(model) || /-codex-mini$/.test(model)) {
6173
- return FALLBACK_ACTIVATION_MODEL;
5983
+ return null;
6174
5984
  }
6175
5985
  return model;
6176
5986
  }
6177
5987
  var MAX_STDERR_CAPTURE_CHARS = 32768;
5988
+ function augmentActivationError(error, info) {
5989
+ const base = error instanceof Error ? error : new Error(String(error));
5990
+ const parts = [];
5991
+ if (info.exitCode !== null) {
5992
+ parts.push(`codex exited code=${info.exitCode}`);
5993
+ }
5994
+ if (info.exitSignal) {
5995
+ parts.push(`signal=${info.exitSignal}`);
5996
+ }
5997
+ const stderrTail = info.stderr.replace(/\s+/g, " ").trim().slice(-400);
5998
+ if (stderrTail) {
5999
+ parts.push(`stderr: ${stderrTail}`);
6000
+ }
6001
+ if (parts.length > 0) {
6002
+ base.message = `${base.message} (${parts.join("; ")})`;
6003
+ }
6004
+ return base;
6005
+ }
6178
6006
  var REFRESH_TOKEN_REDEEMED_SNIPPET = "refresh token was already used";
6179
6007
  var authFileCache = /* @__PURE__ */ new Map();
6180
6008
  function isRecord5(value) {
@@ -6733,30 +6561,23 @@ async function activateResetWindowViaRpc(envOverride, options = {}) {
6733
6561
  return { status: "skipped", reason: "auth-missing" };
6734
6562
  }
6735
6563
  let configuredModel = null;
6736
- let sourceConfigContent = null;
6737
6564
  try {
6738
6565
  const snapshot = await getCodexConfigSnapshot({
6739
6566
  codexHomePath: import_node_path8.default.dirname(sourceAuthPath)
6740
6567
  });
6741
6568
  configuredModel = snapshot.settings.model;
6742
- if (!snapshot.parseError) {
6743
- sourceConfigContent = snapshot.content;
6744
- }
6745
6569
  } catch {
6746
6570
  }
6747
6571
  const activationModel = resolveActivationModel(configuredModel);
6748
- const tempConfigPath = import_node_path8.default.join(tempHome, "config.toml");
6749
- await import_node_fs3.promises.writeFile(tempConfigPath, sourceConfigContent ?? "", "utf8").catch(() => {
6750
- });
6751
- await updateCodexConfigValues({ model: activationModel }, { codexHomePath: tempHome }).catch(
6752
- () => import_node_fs3.promises.writeFile(
6753
- tempConfigPath,
6572
+ if (activationModel) {
6573
+ await import_node_fs3.promises.writeFile(
6574
+ import_node_path8.default.join(tempHome, "config.toml"),
6754
6575
  `model = ${JSON.stringify(activationModel)}
6755
6576
  `,
6756
6577
  "utf8"
6757
- )
6758
- ).catch(() => {
6759
- });
6578
+ ).catch(() => {
6579
+ });
6580
+ }
6760
6581
  const childEnv = buildCodexChildEnv({
6761
6582
  ...envOverride ?? {},
6762
6583
  HOME: tempHome,
@@ -6789,6 +6610,12 @@ async function activateResetWindowViaRpc(envOverride, options = {}) {
6789
6610
  stderrOutput += text.slice(0, Math.max(0, remaining));
6790
6611
  };
6791
6612
  child.stderr?.on("data", onStderrData);
6613
+ let exitCode = null;
6614
+ let exitSignal = null;
6615
+ child.on("exit", (code, signal) => {
6616
+ exitCode = code;
6617
+ exitSignal = signal;
6618
+ });
6792
6619
  try {
6793
6620
  await sendPayload(child, {
6794
6621
  id: 1,
@@ -6860,6 +6687,12 @@ async function activateResetWindowViaRpc(envOverride, options = {}) {
6860
6687
  };
6861
6688
  }
6862
6689
  return { status: "completed", reason: null, threadId, turnId };
6690
+ } catch (error) {
6691
+ throw augmentActivationError(error, {
6692
+ stderr: stderrOutput,
6693
+ exitCode,
6694
+ exitSignal
6695
+ });
6863
6696
  } finally {
6864
6697
  child.stderr?.off("data", onStderrData);
6865
6698
  child.kill();
@@ -10794,7 +10627,6 @@ async function findOfficialCodexThreadRecord(profileHome, threadId) {
10794
10627
  // ../../packages/runtime-codex/src/codex/officialAppRestart.ts
10795
10628
  var COMMAND_TIMEOUT_MS = 3e3;
10796
10629
  var EXIT_WAIT_MS = 1e4;
10797
- var LAUNCH_WAIT_MS = 15e3;
10798
10630
  var POLL_INTERVAL_MS = 250;
10799
10631
  var PROCESS_EXIT_GRACE_MS = 15e3;
10800
10632
  var APP_DISCOVERY_CACHE_TTL_MS = 6e4;
@@ -10808,7 +10640,6 @@ var CODEXUSE_BRIDGE_BINDING_NAME = "__codexuseBridgeBinding";
10808
10640
  var CODEXUSE_BRIDGE_INSTALL_TTL_MS = 5e3;
10809
10641
  var CODEXUSE_BRIDGE_VERSION = "0.2.0";
10810
10642
  var CODEXUSE_STALE_LAUNCH_GRACE_MS = 45e3;
10811
- var CODEXUSE_STALE_BRIDGE_MISS_TTL_MS = 2 * 6e4;
10812
10643
  var officialCodexBridgeActionHandler = null;
10813
10644
  var bridgeActionListeners = /* @__PURE__ */ new Map();
10814
10645
  var handledBridgeActionIds = [];
@@ -15439,7 +15270,7 @@ function getDescendantPids(rootPid, rows) {
15439
15270
  return descendants;
15440
15271
  }
15441
15272
  async function waitForNewMainPid(candidate, previousPids) {
15442
- const deadline = Date.now() + LAUNCH_WAIT_MS;
15273
+ const deadline = Date.now() + CODEX_BRIDGE_LAUNCH_WAIT_MS;
15443
15274
  while (Date.now() < deadline) {
15444
15275
  const rows = await readProcessRows();
15445
15276
  const pid = rows.find((row) => isMainProcessRow(row, candidate) && !previousPids.has(row.pid))?.pid ?? null;
@@ -15451,7 +15282,7 @@ async function waitForNewMainPid(candidate, previousPids) {
15451
15282
  return null;
15452
15283
  }
15453
15284
  async function waitForAppServerPid(mainPid, profileHome) {
15454
- const deadline = Date.now() + LAUNCH_WAIT_MS;
15285
+ const deadline = Date.now() + CODEX_BRIDGE_LAUNCH_WAIT_MS;
15455
15286
  while (Date.now() < deadline) {
15456
15287
  const pid = await findAppServerPidForProfile(
15457
15288
  await readProcessRows(),
@@ -15531,8 +15362,6 @@ async function hasRecoverableOfficialCodexBridge(cdpPort) {
15531
15362
  }
15532
15363
  async function reapStaleOfficialCodexManagedLaunchRows(candidate, rows) {
15533
15364
  const now = Date.now();
15534
- const reaped = [];
15535
- let currentRows = rows;
15536
15365
  const livePids = new Set(rows.map((row) => row.pid));
15537
15366
  for (const pid of staleOfficialCodexBridgeMissesByPid.keys()) {
15538
15367
  if (!livePids.has(pid)) {
@@ -15544,30 +15373,18 @@ async function reapStaleOfficialCodexManagedLaunchRows(candidate, rows) {
15544
15373
  if (!isMainProcessRow(row, candidate) || cdpPort === null || row.startedAt === null || now - row.startedAt < CODEXUSE_STALE_LAUNCH_GRACE_MS || !await isCodexUseLaunchedProcess(row.pid)) {
15545
15374
  continue;
15546
15375
  }
15547
- const appServerPid = findAppServerPid(currentRows, row.pid);
15376
+ const appServerPid = findAppServerPid(rows, row.pid);
15548
15377
  if (appServerPid !== null) {
15549
15378
  if (await hasRecoverableOfficialCodexBridge(cdpPort)) {
15550
15379
  staleOfficialCodexBridgeMissesByPid.delete(row.pid);
15551
15380
  continue;
15552
15381
  }
15553
- const previousMissAt = staleOfficialCodexBridgeMissesByPid.get(row.pid);
15554
15382
  staleOfficialCodexBridgeMissesByPid.set(row.pid, now);
15555
- if (previousMissAt === void 0 || now - previousMissAt > CODEXUSE_STALE_BRIDGE_MISS_TTL_MS) {
15556
- continue;
15557
- }
15558
- }
15559
- await stopProcessTree(row.pid, currentRows);
15560
- currentRows = await readProcessRows();
15561
- if (!currentRows.some((entry) => entry.pid === row.pid)) {
15562
- staleOfficialCodexBridgeMissesByPid.delete(row.pid);
15563
- reaped.push(row.pid);
15564
- if (sharedHomeCdpWindow?.pid === row.pid) {
15565
- sharedHomeCdpWindow = null;
15566
- }
15383
+ continue;
15567
15384
  }
15568
- break;
15385
+ staleOfficialCodexBridgeMissesByPid.set(row.pid, now);
15569
15386
  }
15570
- return reaped;
15387
+ return [];
15571
15388
  }
15572
15389
  async function focusOfficialCodexApp(candidate) {
15573
15390
  const result = await runCommand3("/usr/bin/open", [candidate.appPath], 5e3);
@@ -15883,7 +15700,6 @@ async function signalPids(pids, signal) {
15883
15700
  return signaled;
15884
15701
  }
15885
15702
  var SHARED_CODEX_HOME = import_node_path13.default.join((0, import_node_os4.homedir)(), ".codex");
15886
- var sharedHomeCdpWindow = null;
15887
15703
  function toIso(value) {
15888
15704
  return typeof value === "number" && Number.isFinite(value) ? new Date(value).toISOString() : null;
15889
15705
  }
@@ -18411,7 +18227,7 @@ async function ensureCliStorageReady() {
18411
18227
  }
18412
18228
 
18413
18229
  // src/app/main.ts
18414
- var VERSION = true ? "5.2.4" : "0.0.0";
18230
+ var VERSION = true ? "5.2.6" : "0.0.0";
18415
18231
  async function runCli() {
18416
18232
  const args = process.argv.slice(2);
18417
18233
  if (args.length === 0) {