codexuse-cli 5.2.4 → 5.2.5

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";
@@ -6175,6 +5986,24 @@ function resolveActivationModel(configuredModel) {
6175
5986
  return model;
6176
5987
  }
6177
5988
  var MAX_STDERR_CAPTURE_CHARS = 32768;
5989
+ function augmentActivationError(error, info) {
5990
+ const base = error instanceof Error ? error : new Error(String(error));
5991
+ const parts = [];
5992
+ if (info.exitCode !== null) {
5993
+ parts.push(`codex exited code=${info.exitCode}`);
5994
+ }
5995
+ if (info.exitSignal) {
5996
+ parts.push(`signal=${info.exitSignal}`);
5997
+ }
5998
+ const stderrTail = info.stderr.replace(/\s+/g, " ").trim().slice(-400);
5999
+ if (stderrTail) {
6000
+ parts.push(`stderr: ${stderrTail}`);
6001
+ }
6002
+ if (parts.length > 0) {
6003
+ base.message = `${base.message} (${parts.join("; ")})`;
6004
+ }
6005
+ return base;
6006
+ }
6178
6007
  var REFRESH_TOKEN_REDEEMED_SNIPPET = "refresh token was already used";
6179
6008
  var authFileCache = /* @__PURE__ */ new Map();
6180
6009
  function isRecord5(value) {
@@ -6733,28 +6562,20 @@ async function activateResetWindowViaRpc(envOverride, options = {}) {
6733
6562
  return { status: "skipped", reason: "auth-missing" };
6734
6563
  }
6735
6564
  let configuredModel = null;
6736
- let sourceConfigContent = null;
6737
6565
  try {
6738
6566
  const snapshot = await getCodexConfigSnapshot({
6739
6567
  codexHomePath: import_node_path8.default.dirname(sourceAuthPath)
6740
6568
  });
6741
6569
  configuredModel = snapshot.settings.model;
6742
- if (!snapshot.parseError) {
6743
- sourceConfigContent = snapshot.content;
6744
- }
6745
6570
  } catch {
6746
6571
  }
6747
6572
  const activationModel = resolveActivationModel(configuredModel);
6748
6573
  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,
6754
- `model = ${JSON.stringify(activationModel)}
6574
+ await import_node_fs3.promises.writeFile(
6575
+ tempConfigPath,
6576
+ `model = ${JSON.stringify(activationModel)}
6755
6577
  `,
6756
- "utf8"
6757
- )
6578
+ "utf8"
6758
6579
  ).catch(() => {
6759
6580
  });
6760
6581
  const childEnv = buildCodexChildEnv({
@@ -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();
@@ -10808,7 +10641,6 @@ var CODEXUSE_BRIDGE_BINDING_NAME = "__codexuseBridgeBinding";
10808
10641
  var CODEXUSE_BRIDGE_INSTALL_TTL_MS = 5e3;
10809
10642
  var CODEXUSE_BRIDGE_VERSION = "0.2.0";
10810
10643
  var CODEXUSE_STALE_LAUNCH_GRACE_MS = 45e3;
10811
- var CODEXUSE_STALE_BRIDGE_MISS_TTL_MS = 2 * 6e4;
10812
10644
  var officialCodexBridgeActionHandler = null;
10813
10645
  var bridgeActionListeners = /* @__PURE__ */ new Map();
10814
10646
  var handledBridgeActionIds = [];
@@ -15531,8 +15363,6 @@ async function hasRecoverableOfficialCodexBridge(cdpPort) {
15531
15363
  }
15532
15364
  async function reapStaleOfficialCodexManagedLaunchRows(candidate, rows) {
15533
15365
  const now = Date.now();
15534
- const reaped = [];
15535
- let currentRows = rows;
15536
15366
  const livePids = new Set(rows.map((row) => row.pid));
15537
15367
  for (const pid of staleOfficialCodexBridgeMissesByPid.keys()) {
15538
15368
  if (!livePids.has(pid)) {
@@ -15544,30 +15374,18 @@ async function reapStaleOfficialCodexManagedLaunchRows(candidate, rows) {
15544
15374
  if (!isMainProcessRow(row, candidate) || cdpPort === null || row.startedAt === null || now - row.startedAt < CODEXUSE_STALE_LAUNCH_GRACE_MS || !await isCodexUseLaunchedProcess(row.pid)) {
15545
15375
  continue;
15546
15376
  }
15547
- const appServerPid = findAppServerPid(currentRows, row.pid);
15377
+ const appServerPid = findAppServerPid(rows, row.pid);
15548
15378
  if (appServerPid !== null) {
15549
15379
  if (await hasRecoverableOfficialCodexBridge(cdpPort)) {
15550
15380
  staleOfficialCodexBridgeMissesByPid.delete(row.pid);
15551
15381
  continue;
15552
15382
  }
15553
- const previousMissAt = staleOfficialCodexBridgeMissesByPid.get(row.pid);
15554
15383
  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
- }
15384
+ continue;
15567
15385
  }
15568
- break;
15386
+ staleOfficialCodexBridgeMissesByPid.set(row.pid, now);
15569
15387
  }
15570
- return reaped;
15388
+ return [];
15571
15389
  }
15572
15390
  async function focusOfficialCodexApp(candidate) {
15573
15391
  const result = await runCommand3("/usr/bin/open", [candidate.appPath], 5e3);
@@ -15883,7 +15701,6 @@ async function signalPids(pids, signal) {
15883
15701
  return signaled;
15884
15702
  }
15885
15703
  var SHARED_CODEX_HOME = import_node_path13.default.join((0, import_node_os4.homedir)(), ".codex");
15886
- var sharedHomeCdpWindow = null;
15887
15704
  function toIso(value) {
15888
15705
  return typeof value === "number" && Number.isFinite(value) ? new Date(value).toISOString() : null;
15889
15706
  }
@@ -18411,7 +18228,7 @@ async function ensureCliStorageReady() {
18411
18228
  }
18412
18229
 
18413
18230
  // src/app/main.ts
18414
- var VERSION = true ? "5.2.4" : "0.0.0";
18231
+ var VERSION = true ? "5.2.5" : "0.0.0";
18415
18232
  async function runCli() {
18416
18233
  const args = process.argv.slice(2);
18417
18234
  if (args.length === 0) {