@bman654/clodex 2.11.4 → 2.11.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/cli.js CHANGED
@@ -52,7 +52,7 @@ import {
52
52
  withProviderMutationLock,
53
53
  withRegistryWriteLock,
54
54
  withRegistryWriteLockSync
55
- } from "./chunk-J7WXOD2K.js";
55
+ } from "./chunk-ZM2KYLPH.js";
56
56
 
57
57
  // src/cli.ts
58
58
  import pc13 from "picocolors";
@@ -227,7 +227,7 @@ function printFavoritesOnlyPanel() {
227
227
 
228
228
  // src/cli.ts
229
229
  import * as p12 from "@clack/prompts";
230
- import { realpathSync as realpathSync2 } from "fs";
230
+ import { realpathSync as realpathSync3 } from "fs";
231
231
  import { fileURLToPath } from "url";
232
232
 
233
233
  // src/launch.ts
@@ -297,7 +297,7 @@ function buildClaudeArgs(model, extraArgs) {
297
297
  return model ? ["--model", model, ...extraArgs] : [...extraArgs];
298
298
  }
299
299
  function launchClaude(env, model, extraArgs) {
300
- return new Promise((resolve3) => {
300
+ return new Promise((resolve4) => {
301
301
  const claudePath = findClaudeBinary();
302
302
  const args = buildClaudeArgs(model, extraArgs);
303
303
  const debugFileIdx = extraArgs.indexOf("--debug-file");
@@ -366,11 +366,11 @@ function launchClaude(env, model, extraArgs) {
366
366
  process.once("SIGTERM", () => forward("SIGTERM"));
367
367
  child.on("exit", (code) => {
368
368
  restore();
369
- resolve3(code ?? 0);
369
+ resolve4(code ?? 0);
370
370
  });
371
371
  child.on("error", (err) => {
372
372
  restore();
373
- resolve3(1);
373
+ resolve4(1);
374
374
  });
375
375
  });
376
376
  }
@@ -382,7 +382,7 @@ import { join } from "path";
382
382
  // package.json
383
383
  var package_default = {
384
384
  name: "@bman654/clodex",
385
- version: "2.11.4",
385
+ version: "2.11.5",
386
386
  publishConfig: {
387
387
  access: "public"
388
388
  },
@@ -584,7 +584,7 @@ async function runCredentialHelper(operation, account, input, expectedHelperId)
584
584
  `${CREDENTIAL_HELPER_ENV} does not match the helper that owns this credential; restore the prior helper or reauthenticate`
585
585
  );
586
586
  }
587
- return new Promise((resolve3, reject) => {
587
+ return new Promise((resolve4, reject) => {
588
588
  const child = spawn2(
589
589
  helper.path,
590
590
  [operation, CREDENTIAL_HELPER_SERVICE, account],
@@ -625,7 +625,7 @@ async function runCredentialHelper(operation, account, input, expectedHelperId)
625
625
  if (settled) return;
626
626
  settled = true;
627
627
  clearTimeout(timer);
628
- resolve3({ code: code ?? 1, stdout: Buffer.concat(stdout).toString("utf8") });
628
+ resolve4({ code: code ?? 1, stdout: Buffer.concat(stdout).toString("utf8") });
629
629
  });
630
630
  if (input !== void 0) child.stdin.end(input);
631
631
  else child.stdin.end();
@@ -852,7 +852,7 @@ function positiveSecondsToMs(value, defaultMs) {
852
852
  return Number.isFinite(seconds) && seconds > 0 ? seconds * 1e3 : defaultMs;
853
853
  }
854
854
  async function sleepMs(ms) {
855
- await new Promise((resolve3) => setTimeout(resolve3, ms));
855
+ await new Promise((resolve4) => setTimeout(resolve4, ms));
856
856
  }
857
857
 
858
858
  // src/oauth/refresh-http.ts
@@ -979,9 +979,9 @@ async function startCallbackServer(options) {
979
979
  port: address.port,
980
980
  redirectUri: `http://${redirectHost}:${address.port}${path}`,
981
981
  waitForCallback(timeoutMs = 3e5) {
982
- return new Promise((resolve3, reject) => {
982
+ return new Promise((resolve4, reject) => {
983
983
  if (buffered) {
984
- resolve3(buffered);
984
+ resolve4(buffered);
985
985
  buffered = void 0;
986
986
  return;
987
987
  }
@@ -993,7 +993,7 @@ async function startCallbackServer(options) {
993
993
  );
994
994
  codeResolve = (params) => {
995
995
  clearTimeout(timer);
996
- resolve3(params);
996
+ resolve4(params);
997
997
  };
998
998
  codeReject = (err) => {
999
999
  clearTimeout(timer);
@@ -3888,18 +3888,18 @@ import {
3888
3888
  existsSync as existsSync5,
3889
3889
  mkdtempSync,
3890
3890
  mkdirSync as mkdirSync5,
3891
- readFileSync as readFileSync8,
3891
+ readFileSync as readFileSync9,
3892
3892
  renameSync as renameSync2,
3893
3893
  rmSync,
3894
- statSync as statSync6,
3894
+ statSync as statSync7,
3895
3895
  unlinkSync as unlinkSync3,
3896
3896
  writeFileSync as writeFileSync5,
3897
3897
  openSync as openSync6,
3898
3898
  closeSync as closeSync6,
3899
- realpathSync
3899
+ realpathSync as realpathSync2
3900
3900
  } from "fs";
3901
3901
  import { homedir as homedir3 } from "os";
3902
- import { basename, dirname as dirname3, join as join7 } from "path";
3902
+ import { basename, dirname as dirname4, join as join7 } from "path";
3903
3903
  import pc3 from "picocolors";
3904
3904
  import * as p2 from "@clack/prompts";
3905
3905
 
@@ -6874,8 +6874,108 @@ function materializeRegistry(registry, resolveCredential, opts) {
6874
6874
  return result;
6875
6875
  }
6876
6876
 
6877
+ // src/npm-shim.ts
6878
+ import { readFileSync as readFileSync7, realpathSync, statSync as statSync4 } from "fs";
6879
+ import { dirname as dirname3, resolve as resolve2 } from "path";
6880
+ var MAX_LAUNCHER_BYTES = 64 * 1024;
6881
+ var MAX_LAUNCHER_HOPS = 4;
6882
+ var COMMENT_LINE = {
6883
+ cmd: /^[\s@]*(?:rem\b|::)/i,
6884
+ powershell: /^\s*#/,
6885
+ sh: /^\s*#/
6886
+ };
6887
+ var TARGET_PATTERN = {
6888
+ cmd: /"%(?:~dp0|dp0%)\\([^"]+?)"\s+%\*/g,
6889
+ powershell: /"\$basedir\/([^"]+?)"\s+\$args/g,
6890
+ sh: /"\$basedir(?:_win)?\/([^"]+?)"\s+"\$@"/g
6891
+ };
6892
+ function launcherKind(shimPath) {
6893
+ const lower = shimPath.toLowerCase();
6894
+ if (lower.endsWith(".cmd")) return "cmd";
6895
+ if (lower.endsWith(".ps1")) return "powershell";
6896
+ return "sh";
6897
+ }
6898
+ function readLauncherText(path) {
6899
+ try {
6900
+ if (statSync4(path).size > MAX_LAUNCHER_BYTES) return null;
6901
+ return readFileSync7(path, "utf8");
6902
+ } catch {
6903
+ return null;
6904
+ }
6905
+ }
6906
+ function isLiteralPath(relativeTarget) {
6907
+ return relativeTarget.length > 0 && !/[%$]/.test(relativeTarget);
6908
+ }
6909
+ function collectTargets(contents, kind) {
6910
+ const comment = COMMENT_LINE[kind];
6911
+ const pattern = TARGET_PATTERN[kind];
6912
+ const targets = [];
6913
+ for (const line of contents.split(/\r?\n/)) {
6914
+ if (comment.test(line)) continue;
6915
+ for (const match of line.matchAll(pattern)) targets.push(match[1]);
6916
+ }
6917
+ return targets;
6918
+ }
6919
+ function readNpmShim(shimPath) {
6920
+ const kind = launcherKind(shimPath);
6921
+ const unreadable = kind === "sh" ? { kind: "not-a-shim" } : { kind: "unreadable-launcher" };
6922
+ const text5 = readLauncherText(shimPath);
6923
+ if (text5 === null) return unreadable;
6924
+ const rawTargets = collectTargets(text5, kind);
6925
+ if (rawTargets.length === 0) return unreadable;
6926
+ if (!rawTargets.every(isLiteralPath)) return unreadable;
6927
+ const absolute = rawTargets.map((target) => resolve2(
6928
+ dirname3(shimPath),
6929
+ kind === "cmd" ? target.replace(/\\/g, "/") : target
6930
+ ));
6931
+ const distinct = [...new Set(absolute)];
6932
+ if (distinct.length > 1) return { kind: "ambiguous-launcher", targets: distinct };
6933
+ return { kind: "target", target: distinct[0] };
6934
+ }
6935
+ function resolveThroughNpmShims(startPath) {
6936
+ let current = startPath;
6937
+ for (let hop = 0; hop <= MAX_LAUNCHER_HOPS; hop++) {
6938
+ const reading = readNpmShim(current);
6939
+ if (reading.kind === "not-a-shim") return { ok: true, path: current };
6940
+ if (reading.kind === "unreadable-launcher") {
6941
+ return {
6942
+ ok: false,
6943
+ shimPath: current,
6944
+ declaredTarget: null,
6945
+ detail: "it is a launcher script rather than the program itself, and clodex could not read which file it starts"
6946
+ };
6947
+ }
6948
+ if (reading.kind === "ambiguous-launcher") {
6949
+ return {
6950
+ ok: false,
6951
+ shimPath: current,
6952
+ declaredTarget: null,
6953
+ detail: `it names more than one program (${reading.targets.join(", ")}), so clodex cannot tell which one it starts`
6954
+ };
6955
+ }
6956
+ let hopped;
6957
+ try {
6958
+ hopped = realpathSync(reading.target);
6959
+ } catch {
6960
+ return {
6961
+ ok: false,
6962
+ shimPath: current,
6963
+ declaredTarget: reading.target,
6964
+ detail: `it starts ${reading.target}, which does not exist`
6965
+ };
6966
+ }
6967
+ current = hopped;
6968
+ }
6969
+ return {
6970
+ ok: false,
6971
+ shimPath: startPath,
6972
+ declaredTarget: null,
6973
+ detail: `it starts another launcher script, more than ${MAX_LAUNCHER_HOPS} deep`
6974
+ };
6975
+ }
6976
+
6877
6977
  // src/bun-entry-module.ts
6878
- import { closeSync as closeSync2, openSync as openSync2, readSync, statSync as statSync4, writeSync as writeSync2 } from "fs";
6978
+ import { closeSync as closeSync2, openSync as openSync2, readSync, statSync as statSync5, writeSync as writeSync2 } from "fs";
6879
6979
  import { execFileSync } from "child_process";
6880
6980
  var BUN_TRAILER = Buffer.from("\n---- Bun! ----\n");
6881
6981
  var BUN_OFFSETS_BYTES = 32;
@@ -7054,7 +7154,7 @@ function isMachO(fd) {
7054
7154
  function readBunModuleTable(path) {
7055
7155
  const fd = openSync2(path, "r");
7056
7156
  try {
7057
- return readBunModuleNames(fd, statSync4(path).size);
7157
+ return readBunModuleNames(fd, statSync5(path).size);
7058
7158
  } finally {
7059
7159
  closeSync2(fd);
7060
7160
  }
@@ -7062,7 +7162,7 @@ function readBunModuleTable(path) {
7062
7162
  function readBunJavaScriptModules(path) {
7063
7163
  const fd = openSync2(path, "r");
7064
7164
  try {
7065
- const parsed = readBunModuleNames(fd, statSync4(path).size);
7165
+ const parsed = readBunModuleNames(fd, statSync5(path).size);
7066
7166
  if (!parsed) return null;
7067
7167
  const modules = [];
7068
7168
  for (let index = 0; index < parsed.names.length; index++) {
@@ -7088,14 +7188,14 @@ function readBunJavaScriptModules(path) {
7088
7188
  function shimEntryModuleName(path) {
7089
7189
  const fd = openSync2(path, "r+");
7090
7190
  try {
7091
- const parsed = readBunModuleNames(fd, statSync4(path).size);
7191
+ const parsed = readBunModuleNames(fd, statSync5(path).size);
7092
7192
  if (!parsed) return null;
7093
7193
  if (parsed.names.some(tweakccRecognizesModuleName)) return null;
7094
7194
  const original = parsed.names[parsed.entryPointId];
7095
7195
  const offset = parsed.offsets[parsed.entryPointId];
7096
7196
  const marker = entryModuleShimName(Buffer.byteLength(original));
7097
7197
  if (marker === null) return null;
7098
- if (findStandIn(fd, statSync4(path).size, marker).some((offset2) => isModuleNameAt(fd, offset2, marker))) {
7198
+ if (findStandIn(fd, statSync5(path).size, marker).some((offset2) => isModuleNameAt(fd, offset2, marker))) {
7099
7199
  return null;
7100
7200
  }
7101
7201
  writeNameBytes(fd, marker, offset);
@@ -7108,7 +7208,7 @@ function restoreEntryModuleName(path, shim, { resign }) {
7108
7208
  const fd = openSync2(path, "r+");
7109
7209
  let machO;
7110
7210
  try {
7111
- const parsed = readBunModuleNames(fd, statSync4(path).size);
7211
+ const parsed = readBunModuleNames(fd, statSync5(path).size);
7112
7212
  const offset = parsed?.offsets[parsed.entryPointId];
7113
7213
  if (!parsed || offset === void 0 || parsed.names[parsed.entryPointId] !== shim.marker) {
7114
7214
  throw new Error(
@@ -7116,7 +7216,7 @@ function restoreEntryModuleName(path, shim, { resign }) {
7116
7216
  );
7117
7217
  }
7118
7218
  writeNameBytes(fd, shim.original, offset);
7119
- restoreEveryStandIn(fd, statSync4(path).size, shim);
7219
+ restoreEveryStandIn(fd, statSync5(path).size, shim);
7120
7220
  machO = resign;
7121
7221
  } finally {
7122
7222
  closeSync2(fd);
@@ -7577,7 +7677,7 @@ function writeAll(fd, bytes, position, path) {
7577
7677
 
7578
7678
  // src/patch-backup.ts
7579
7679
  import { createHash as createHash5 } from "crypto";
7580
- import { existsSync as existsSync4, readFileSync as readFileSync7, readdirSync, statSync as statSync5 } from "fs";
7680
+ import { existsSync as existsSync4, readFileSync as readFileSync8, readdirSync, statSync as statSync6 } from "fs";
7581
7681
  import { homedir as homedir2 } from "os";
7582
7682
  import { join as join6 } from "path";
7583
7683
  var BACKUP_SHA_PREFIX_LENGTH = 16;
@@ -7585,7 +7685,7 @@ function backupDir() {
7585
7685
  return process.env["TWEAKCC_CONFIG_DIR"]?.trim() || join6(homedir2(), ".tweakcc");
7586
7686
  }
7587
7687
  function sha256File(path) {
7588
- return createHash5("sha256").update(readFileSync7(path)).digest("hex");
7688
+ return createHash5("sha256").update(readFileSync8(path)).digest("hex");
7589
7689
  }
7590
7690
  function backupVersionTag(version) {
7591
7691
  const tag = version.trim().replace(/[^\w.-]+/g, "_");
@@ -7615,7 +7715,7 @@ function scanPristineBackups(version, dir = backupDir()) {
7615
7715
  const path = join6(dir, entry);
7616
7716
  let sha256;
7617
7717
  try {
7618
- if (!statSync5(path).isFile()) continue;
7718
+ if (!statSync6(path).isFile()) continue;
7619
7719
  sha256 = sha256File(path);
7620
7720
  } catch {
7621
7721
  corrupt.push(path);
@@ -8443,7 +8543,7 @@ var WsUpgradePacer = class {
8443
8543
  * catch that, because an untested guard is not a guarantee.
8444
8544
  */
8445
8545
  sleep(ms, signal) {
8446
- return new Promise((resolve3, reject) => {
8546
+ return new Promise((resolve4, reject) => {
8447
8547
  let settled = false;
8448
8548
  let cancelTimer;
8449
8549
  const onAbort = () => {
@@ -8456,7 +8556,7 @@ var WsUpgradePacer = class {
8456
8556
  if (settled) return;
8457
8557
  settled = true;
8458
8558
  signal?.removeEventListener("abort", onAbort);
8459
- resolve3();
8559
+ resolve4();
8460
8560
  };
8461
8561
  signal?.addEventListener("abort", onAbort, { once: true });
8462
8562
  cancelTimer = this.schedule(ms, fire);
@@ -11068,7 +11168,7 @@ function decodeRequestBody(raw, encoding) {
11068
11168
  }
11069
11169
  }
11070
11170
  function readBody(req) {
11071
- return new Promise((resolve3, reject) => {
11171
+ return new Promise((resolve4, reject) => {
11072
11172
  const chunks = [];
11073
11173
  let totalSize = 0;
11074
11174
  req.on("data", (c) => {
@@ -11082,7 +11182,7 @@ function readBody(req) {
11082
11182
  });
11083
11183
  req.on("end", () => {
11084
11184
  try {
11085
- resolve3(decodeRequestBody(Buffer.concat(chunks), req.headers["content-encoding"]));
11185
+ resolve4(decodeRequestBody(Buffer.concat(chunks), req.headers["content-encoding"]));
11086
11186
  } catch (err) {
11087
11187
  reject(err);
11088
11188
  }
@@ -11607,6 +11707,49 @@ function resolveUpstreamTools(tools, messages) {
11607
11707
  return upstream;
11608
11708
  }
11609
11709
 
11710
+ // src/tool-schema-sanitize.ts
11711
+ function isCompatiblePattern(pattern) {
11712
+ for (let i = 0; i < pattern.length; i++) {
11713
+ if (pattern[i] === "\\") {
11714
+ const next = pattern[i + 1];
11715
+ if ((next === "p" || next === "P") && pattern[i + 2] === "{") return false;
11716
+ if (next === "k" && pattern[i + 2] === "<") return false;
11717
+ i++;
11718
+ continue;
11719
+ }
11720
+ if (pattern[i] === "(" && pattern[i + 1] === "?" && pattern[i + 2] === "<" && pattern[i + 3] !== "=" && pattern[i + 3] !== "!") return false;
11721
+ }
11722
+ return true;
11723
+ }
11724
+ function sanitizeToolSchema(schema) {
11725
+ if (Array.isArray(schema)) {
11726
+ let changed2 = false;
11727
+ const out2 = schema.map((entry) => {
11728
+ const next = sanitizeToolSchema(entry);
11729
+ changed2 ||= next !== entry;
11730
+ return next;
11731
+ });
11732
+ return changed2 ? out2 : schema;
11733
+ }
11734
+ if (!schema || typeof schema !== "object") return schema;
11735
+ let changed = false;
11736
+ const out = {};
11737
+ for (const [key, value] of Object.entries(schema)) {
11738
+ if (key === "pattern" && typeof value === "string") {
11739
+ if (!isCompatiblePattern(value)) {
11740
+ changed = true;
11741
+ continue;
11742
+ }
11743
+ out[key] = value;
11744
+ continue;
11745
+ }
11746
+ const next = sanitizeToolSchema(value);
11747
+ changed ||= next !== value;
11748
+ out[key] = next;
11749
+ }
11750
+ return changed ? out : schema;
11751
+ }
11752
+
11610
11753
  // src/upstream-attempts.ts
11611
11754
  import { APICallError as APICallError2, RetryError as RetryError2, wrapLanguageModel as wrapLanguageModel2 } from "ai";
11612
11755
  function restoreSyntheticRetryAfterHeader(error) {
@@ -11992,12 +12135,13 @@ function toolRequiredProps(tools) {
11992
12135
  }
11993
12136
  function translateTools(anthropicTools, npm) {
11994
12137
  if (!anthropicTools?.length) return void 0;
12138
+ const anthropicFormat = npm === "@ai-sdk/anthropic" || npm === VERTEX_ANTHROPIC_NPM;
11995
12139
  const tools = {};
11996
12140
  for (const t of anthropicTools) {
11997
12141
  if (!t.name || !t.input_schema) continue;
11998
12142
  tools[t.name] = tool({
11999
12143
  description: t.description ?? "",
12000
- inputSchema: jsonSchema(t.input_schema),
12144
+ inputSchema: jsonSchema(anthropicFormat ? t.input_schema : sanitizeToolSchema(t.input_schema)),
12001
12145
  strict: npm === "@ai-sdk/openai" ? false : void 0
12002
12146
  });
12003
12147
  }
@@ -13401,7 +13545,7 @@ function getPatchLockPath() {
13401
13545
  }
13402
13546
  function readPatchManifest(path = getPatchManifestPath()) {
13403
13547
  try {
13404
- const parsed = JSON.parse(readFileSync8(path, "utf8"));
13548
+ const parsed = JSON.parse(readFileSync9(path, "utf8"));
13405
13549
  if (parsed && typeof parsed.binaryPath === "string" && typeof parsed.configHash === "string") {
13406
13550
  return parsed;
13407
13551
  }
@@ -13580,7 +13724,7 @@ function tryAcquirePatchLock(lockPath = getPatchLockPath(), opts = {}) {
13580
13724
  } catch {
13581
13725
  let stale = false;
13582
13726
  try {
13583
- const existing = JSON.parse(readFileSync8(lockPath, "utf8"));
13727
+ const existing = JSON.parse(readFileSync9(lockPath, "utf8"));
13584
13728
  stale = !existing.pid || !isAlive(existing.pid) || typeof existing.startedAt === "number" && now - existing.startedAt > PATCH_LOCK_STALE_MS;
13585
13729
  } catch {
13586
13730
  stale = true;
@@ -13601,12 +13745,24 @@ function resolveClaudeBinaryForPatch() {
13601
13745
  if (!source) return { ok: false, reason: "binary-not-found" };
13602
13746
  let resolved;
13603
13747
  try {
13604
- resolved = realpathSync(source);
13748
+ resolved = realpathSync2(source);
13605
13749
  } catch {
13606
13750
  return { ok: false, reason: "binary-not-found" };
13607
13751
  }
13752
+ const followed = resolveThroughNpmShims(resolved);
13753
+ if (!followed.ok) {
13754
+ return {
13755
+ ok: false,
13756
+ reason: "launcher-unresolved",
13757
+ binaryPath: followed.declaredTarget ?? followed.shimPath,
13758
+ shimPath: followed.shimPath,
13759
+ declaredTarget: followed.declaredTarget,
13760
+ detail: followed.detail
13761
+ };
13762
+ }
13763
+ resolved = followed.path;
13608
13764
  try {
13609
- if (!statSync6(resolved).isFile()) return { ok: false, reason: "binary-not-found" };
13765
+ if (!statSync7(resolved).isFile()) return { ok: false, reason: "binary-not-found" };
13610
13766
  } catch {
13611
13767
  return { ok: false, reason: "binary-not-found" };
13612
13768
  }
@@ -13615,6 +13771,9 @@ function resolveClaudeBinaryForPatch() {
13615
13771
  return { ok: true, binaryPath: resolved, version };
13616
13772
  }
13617
13773
  function describePatchTargetFailure(target) {
13774
+ if (target.reason === "launcher-unresolved") {
13775
+ return `${target.shimPath} starts Claude Code but is not Claude Code itself, and clodex could not follow it: ${target.detail}. clodex will not patch a launcher script \u2014 that fails with "Unable to detect installation type". Set CLODEX_CLAUDE_PATH to the Claude Code program itself (for an npm install on Windows that is node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe under the directory holding the launcher), then run the command again.`;
13776
+ }
13618
13777
  return target.reason === "binary-not-found" ? "claude binary not found. Install Claude Code or set TWEAKCC_CC_INSTALLATION_PATH." : `Could not determine the version of ${target.binaryPath} (\`claude --version\` failed). clodex will not patch a binary whose version it cannot read, because the version selects the pristine backup it patches from. If a previous patch left the install broken, \`clodex patch --restore\` still works \u2014 it reads the version from the patch manifest.`;
13619
13778
  }
13620
13779
  function summarizePatchResults(results) {
@@ -13711,7 +13870,7 @@ async function applyPatch(binaryPath, version, desired, configHash, opts) {
13711
13870
  try {
13712
13871
  mkdirSync5(backupDir(), { recursive: true });
13713
13872
  const { tryDetectInstallation, readContent, writeContent } = await import("tweakcc");
13714
- candidateDir = mkdtempSync(join7(dirname3(binaryPath), ".clodex-patch-"));
13873
+ candidateDir = mkdtempSync(join7(dirname4(binaryPath), ".clodex-patch-"));
13715
13874
  const candidatePath = join7(candidateDir, basename(binaryPath));
13716
13875
  const seedCandidate = async (from) => {
13717
13876
  copyFileSync(from, candidatePath);
@@ -13842,7 +14001,7 @@ async function applyPatch(binaryPath, version, desired, configHash, opts) {
13842
14001
  }
13843
14002
  if (writeShim) restoreEntryModuleName(candidatePath, writeShim, { resign: true });
13844
14003
  else if (publishedBlob) resignMachOBinary(candidatePath);
13845
- patchedSize = statSync6(candidatePath).size;
14004
+ patchedSize = statSync7(candidatePath).size;
13846
14005
  patchedSha256 = sha256File(candidatePath);
13847
14006
  renameSync2(candidatePath, binaryPath);
13848
14007
  } catch (err) {
@@ -13899,6 +14058,10 @@ function runRestoreCommand(target) {
13899
14058
  p2.log.error(describePatchTargetFailure(target));
13900
14059
  return 1;
13901
14060
  }
14061
+ if (!target.ok && target.reason === "launcher-unresolved" && target.declaredTarget === null) {
14062
+ p2.log.error(describePatchTargetFailure(target));
14063
+ return 1;
14064
+ }
13902
14065
  const binaryPath = target.binaryPath;
13903
14066
  const manifest = readPatchManifest();
13904
14067
  let version;
@@ -13967,7 +14130,7 @@ async function runPatchCommand(opts = {}) {
13967
14130
  binaryPath,
13968
14131
  claudeVersion: version,
13969
14132
  configHash,
13970
- binarySize: statSync6(binaryPath).size
14133
+ binarySize: statSync7(binaryPath).size
13971
14134
  });
13972
14135
  if (state === "current") {
13973
14136
  p2.log.success(`claude ${version} is already patched with the current model config \u2014 nothing to do.`);
@@ -14004,7 +14167,7 @@ async function runLaunchPatchCheck(opts = {}) {
14004
14167
  if (Object.keys(desired.config).length === 0) return;
14005
14168
  const target = resolveClaudeBinaryForPatch();
14006
14169
  if (!target.ok) {
14007
- if (target.reason === "version-unknown" && !opts.agentStdout) {
14170
+ if (target.reason !== "binary-not-found" && !opts.agentStdout) {
14008
14171
  console.error(pc3.dim(`clodex: ${describePatchTargetFailure(target)}`));
14009
14172
  }
14010
14173
  return;
@@ -14023,7 +14186,7 @@ async function runLaunchPatchCheck(opts = {}) {
14023
14186
  binaryPath: resolved.binaryPath,
14024
14187
  claudeVersion: resolved.version,
14025
14188
  configHash,
14026
- binarySize: statSync6(resolved.binaryPath).size
14189
+ binarySize: statSync7(resolved.binaryPath).size
14027
14190
  });
14028
14191
  if (state === "current") return;
14029
14192
  const interactive = !opts.dryRun && !opts.agentStdout && process.stdin.isTTY === true && process.stdout.isTTY === true;
@@ -14366,12 +14529,12 @@ import {
14366
14529
  lstatSync,
14367
14530
  mkdirSync as mkdirSync6,
14368
14531
  openSync as openSync7,
14369
- readFileSync as readFileSync9,
14532
+ readFileSync as readFileSync10,
14370
14533
  renameSync as renameSync3,
14371
14534
  unlinkSync as unlinkSync4,
14372
14535
  writeFileSync as writeFileSync6
14373
14536
  } from "fs";
14374
- import { dirname as dirname4 } from "path";
14537
+ import { dirname as dirname5 } from "path";
14375
14538
  var JOURNAL_SCHEMA_VERSION = 1;
14376
14539
  var DIR_MODE2 = 448;
14377
14540
  var FILE_MODE4 = 384;
@@ -14473,7 +14636,7 @@ function readJournalUnlocked(path) {
14473
14636
  if (opened.size > MAX_JOURNAL_BYTES) {
14474
14637
  throw new Error("Credential cleanup journal is too large.");
14475
14638
  }
14476
- return parseJournal(JSON.parse(readFileSync9(fd, "utf8")));
14639
+ return parseJournal(JSON.parse(readFileSync10(fd, "utf8")));
14477
14640
  } catch (error) {
14478
14641
  const message = error instanceof Error ? error.message : String(error);
14479
14642
  throw new Error(`Could not read credential cleanup journal: ${message}`);
@@ -14484,7 +14647,7 @@ function readJournalUnlocked(path) {
14484
14647
  function syncParentDirectory(path) {
14485
14648
  let fd;
14486
14649
  try {
14487
- fd = openSync7(dirname4(path), "r");
14650
+ fd = openSync7(dirname5(path), "r");
14488
14651
  fsyncSync2(fd);
14489
14652
  } catch (error) {
14490
14653
  const code = error.code;
@@ -14496,7 +14659,7 @@ function syncParentDirectory(path) {
14496
14659
  function writeJournalUnlocked(journal, path) {
14497
14660
  assertRegistryWriteOwnership(path);
14498
14661
  ensureSecureAppHome();
14499
- mkdirSync6(dirname4(path), { recursive: true, mode: DIR_MODE2 });
14662
+ mkdirSync6(dirname5(path), { recursive: true, mode: DIR_MODE2 });
14500
14663
  const tmp = `${path}.${process.pid}.${randomUUID4()}.tmp`;
14501
14664
  let fd;
14502
14665
  try {
@@ -17739,8 +17902,8 @@ async function startServer(options) {
17739
17902
  url: `http://${tcpListenerUrlHost(address.address)}:${address.port}`,
17740
17903
  server,
17741
17904
  inferenceLogPath: options.inferenceLogPath,
17742
- close: () => new Promise((resolve3, reject) => {
17743
- server.close((err) => err ? reject(err) : resolve3());
17905
+ close: () => new Promise((resolve4, reject) => {
17906
+ server.close((err) => err ? reject(err) : resolve4());
17744
17907
  })
17745
17908
  };
17746
17909
  }
@@ -18479,8 +18642,8 @@ import { createBrotliDecompress, createGunzip, createInflate } from "zlib";
18479
18642
 
18480
18643
  // src/http-proxy/ca.ts
18481
18644
  import { randomBytes as randomBytes2 } from "crypto";
18482
- import { chmodSync as chmodSync4, existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as readFileSync10, writeFileSync as writeFileSync7 } from "fs";
18483
- import { dirname as dirname5, join as join8, resolve as resolve2 } from "path";
18645
+ import { chmodSync as chmodSync4, existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync7 } from "fs";
18646
+ import { dirname as dirname6, join as join8, resolve as resolve3 } from "path";
18484
18647
  import forge from "node-forge";
18485
18648
  var CERT_DIR = "http-proxy";
18486
18649
  var CA_CERT_FILE = "clodex-ca.pem";
@@ -18555,8 +18718,8 @@ function generateCertificates(paths) {
18555
18718
  }
18556
18719
  function storedCertificatesAreCurrent(paths) {
18557
18720
  try {
18558
- const ca = forge.pki.certificateFromPem(readFileSync10(paths.caCert, "utf8"));
18559
- const server = forge.pki.certificateFromPem(readFileSync10(paths.serverCert, "utf8"));
18721
+ const ca = forge.pki.certificateFromPem(readFileSync11(paths.caCert, "utf8"));
18722
+ const server = forge.pki.certificateFromPem(readFileSync11(paths.serverCert, "utf8"));
18560
18723
  const now = Date.now();
18561
18724
  const renewalBuffer = 7 * 24 * 60 * 60 * 1e3;
18562
18725
  return ca.validity.notBefore.getTime() <= now && ca.validity.notAfter.getTime() > now + renewalBuffer && server.validity.notBefore.getTime() <= now && server.validity.notAfter.getTime() > now + renewalBuffer && ca.verify(ca) && ca.verify(server);
@@ -18567,13 +18730,13 @@ function storedCertificatesAreCurrent(paths) {
18567
18730
  function ensureHttpProxyCertificates() {
18568
18731
  const paths = certPaths();
18569
18732
  const required = [paths.caCert, paths.caKey, paths.serverCert, paths.serverKey, paths.version];
18570
- const current = required.every(existsSync7) && readFileSync10(paths.version, "utf8") === CERT_VERSION && storedCertificatesAreCurrent(paths);
18733
+ const current = required.every(existsSync7) && readFileSync11(paths.version, "utf8") === CERT_VERSION && storedCertificatesAreCurrent(paths);
18571
18734
  if (!current) generateCertificates(paths);
18572
18735
  return {
18573
18736
  caCertPath: paths.caCert,
18574
- caCert: readFileSync10(paths.caCert, "utf8"),
18575
- serverCert: readFileSync10(paths.serverCert, "utf8"),
18576
- serverKey: readFileSync10(paths.serverKey, "utf8")
18737
+ caCert: readFileSync11(paths.caCert, "utf8"),
18738
+ serverCert: readFileSync11(paths.serverCert, "utf8"),
18739
+ serverKey: readFileSync11(paths.serverKey, "utf8")
18577
18740
  };
18578
18741
  }
18579
18742
  function ensureHttpProxyCaBundle(relayCaCertPath, additionalCaCertPath, onWarning) {
@@ -18586,8 +18749,8 @@ function ensureHttpProxyCaBundle(relayCaCertPath, additionalCaCertPath, onWarnin
18586
18749
  };
18587
18750
  let additionalCa;
18588
18751
  try {
18589
- if (resolve2(additionalCaCertPath) === resolve2(relayCaCertPath)) return relayCaCertPath;
18590
- additionalCa = readFileSync10(additionalCaCertPath, "utf8").trim();
18752
+ if (resolve3(additionalCaCertPath) === resolve3(relayCaCertPath)) return relayCaCertPath;
18753
+ additionalCa = readFileSync11(additionalCaCertPath, "utf8").trim();
18591
18754
  } catch (err) {
18592
18755
  return warn(
18593
18756
  `NODE_EXTRA_CA_CERTS=${additionalCaCertPath} cannot be read (${err instanceof Error ? err.message : String(err)}), so it is not part of the proxy CA bundle. Where node reports this itself it says only "Ignoring extra certs ... load failed", without naming the variable. Clear or correct it.`
@@ -18597,15 +18760,15 @@ function ensureHttpProxyCaBundle(relayCaCertPath, additionalCaCertPath, onWarnin
18597
18760
  return warn(`NODE_EXTRA_CA_CERTS=${additionalCaCertPath} is empty, so it adds nothing.`);
18598
18761
  }
18599
18762
  try {
18600
- const relayCa = readFileSync10(relayCaCertPath, "utf8").trimEnd();
18601
- const combinedPath = join8(dirname5(relayCaCertPath), "combined-ca.pem");
18763
+ const relayCa = readFileSync11(relayCaCertPath, "utf8").trimEnd();
18764
+ const combinedPath = join8(dirname6(relayCaCertPath), "combined-ca.pem");
18602
18765
  writePublic(combinedPath, `${relayCa}
18603
18766
  ${additionalCa}
18604
18767
  `);
18605
18768
  return combinedPath;
18606
18769
  } catch (err) {
18607
18770
  return warn(
18608
- `clodex could not build the combined CA bundle in ${dirname5(relayCaCertPath)} (${err instanceof Error ? err.message : String(err)}), so the readable, non-empty NODE_EXTRA_CA_CERTS=${additionalCaCertPath} was left out of it. Fix the reported error and restart clodex.`
18771
+ `clodex could not build the combined CA bundle in ${dirname6(relayCaCertPath)} (${err instanceof Error ? err.message : String(err)}), so the readable, non-empty NODE_EXTRA_CA_CERTS=${additionalCaCertPath} was left out of it. Fix the reported error and restart clodex.`
18609
18772
  );
18610
18773
  }
18611
18774
  }
@@ -18708,7 +18871,7 @@ function shouldInterceptConnect(authority) {
18708
18871
  return Boolean(target && target.port === 443 && target.host.replace(/\.$/, "").toLowerCase() === ANTHROPIC_HOST);
18709
18872
  }
18710
18873
  function readRawBody(req) {
18711
- return new Promise((resolve3, reject) => {
18874
+ return new Promise((resolve4, reject) => {
18712
18875
  const chunks = [];
18713
18876
  let size = 0;
18714
18877
  req.on("data", (chunk) => {
@@ -18720,7 +18883,7 @@ function readRawBody(req) {
18720
18883
  }
18721
18884
  chunks.push(chunk);
18722
18885
  });
18723
- req.on("end", () => resolve3(Buffer.concat(chunks)));
18886
+ req.on("end", () => resolve4(Buffer.concat(chunks)));
18724
18887
  req.on("error", reject);
18725
18888
  });
18726
18889
  }
@@ -18771,7 +18934,7 @@ function requestHeadersWithoutProxyHeaders(req) {
18771
18934
  return headers;
18772
18935
  }
18773
18936
  function forwardRawAnthropicRequest(req, res, rawBody, origin, rejectUnauthorized, agent, onErrorResponse, onResponseUsage, lifecycle, isLocalShutdown = () => false) {
18774
- return new Promise((resolve3) => {
18937
+ return new Promise((resolve4) => {
18775
18938
  const startedAt = Date.now();
18776
18939
  const retryBudget = passthroughUpstreamRetries();
18777
18940
  let lastActivityAt = startedAt;
@@ -18820,7 +18983,7 @@ function forwardRawAnthropicRequest(req, res, rawBody, origin, rejectUnauthorize
18820
18983
  const done = () => {
18821
18984
  if (settled) return;
18822
18985
  settled = true;
18823
- resolve3();
18986
+ resolve4();
18824
18987
  };
18825
18988
  const errorType = (err) => err.code ?? err.name;
18826
18989
  let upstream;
@@ -18969,7 +19132,7 @@ function forwardRawAnthropicRequest(req, res, rawBody, origin, rejectUnauthorize
18969
19132
  });
18970
19133
  }
18971
19134
  function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.request, adapterAgent, lifecycle, isLocalShutdown = () => false) {
18972
- return new Promise((resolve3) => {
19135
+ return new Promise((resolve4) => {
18973
19136
  const startedAt = Date.now();
18974
19137
  let lastActivityAt = startedAt;
18975
19138
  let headersReceived = false;
@@ -19044,11 +19207,11 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
19044
19207
  });
19045
19208
  adapterResponse?.destroy(new Error("Client disconnected"));
19046
19209
  upstream?.destroy(new Error("Client disconnected"));
19047
- resolve3();
19210
+ resolve4();
19048
19211
  });
19049
19212
  const failAdapterRequest = (err, failureSource) => {
19050
19213
  if (clientDisconnected2) {
19051
- resolve3();
19214
+ resolve4();
19052
19215
  return;
19053
19216
  }
19054
19217
  if (headersReceived || failed) return;
@@ -19069,7 +19232,7 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
19069
19232
  });
19070
19233
  if (!res.headersSent) res.writeHead(502, { "Content-Type": "text/plain" });
19071
19234
  res.end(`Relay adapter unreachable: ${err.message}`);
19072
- resolve3();
19235
+ resolve4();
19073
19236
  };
19074
19237
  upstream = adapterRequest({
19075
19238
  hostname: "127.0.0.1",
@@ -19106,7 +19269,7 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
19106
19269
  copyResponse(upstreamRes, res, void 0, lifecycle ? (usage) => writeLifecycle("response_usage", usage) : void 0);
19107
19270
  const failAdapterResponse = (err, failureSource) => {
19108
19271
  if (clientDisconnected2) {
19109
- resolve3();
19272
+ resolve4();
19110
19273
  return;
19111
19274
  }
19112
19275
  if (adapterEnded || failed) return;
@@ -19127,12 +19290,12 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
19127
19290
  terminationSource: "upstream_failure"
19128
19291
  });
19129
19292
  if (!res.writableEnded) res.destroy(err);
19130
- resolve3();
19293
+ resolve4();
19131
19294
  };
19132
19295
  upstreamRes.once("end", () => {
19133
19296
  adapterEnded = true;
19134
19297
  lastActivityAt = Date.now();
19135
- resolve3();
19298
+ resolve4();
19136
19299
  });
19137
19300
  upstreamRes.once("error", (err) => failAdapterResponse(err, "adapter_response_error"));
19138
19301
  upstreamRes.once("aborted", () => failAdapterResponse(
@@ -19558,7 +19721,7 @@ async function startHttpProxy(options) {
19558
19721
  close: async () => {
19559
19722
  shuttingDown = true;
19560
19723
  for (const socket of sockets) socket.destroy();
19561
- await new Promise((resolve3) => proxyServer.close(() => resolve3()));
19724
+ await new Promise((resolve4) => proxyServer.close(() => resolve4()));
19562
19725
  mitmServer.close();
19563
19726
  anthropicAgent?.destroy();
19564
19727
  adapter?.close();
@@ -19689,11 +19852,11 @@ async function startConfiguredHttpProxy(port, debug = false, inferenceLogPath =
19689
19852
  return { handle, loaded, ...caWarning ? { caWarning } : {} };
19690
19853
  }
19691
19854
  function waitForShutdown() {
19692
- return new Promise((resolve3) => {
19855
+ return new Promise((resolve4) => {
19693
19856
  const done = () => {
19694
19857
  process.off("SIGINT", done);
19695
19858
  process.off("SIGTERM", done);
19696
- resolve3();
19859
+ resolve4();
19697
19860
  };
19698
19861
  process.once("SIGINT", done);
19699
19862
  process.once("SIGTERM", done);
@@ -19867,14 +20030,14 @@ function enrichServerModelReasoning(model) {
19867
20030
  return { ...model, defaultEffort: caps.defaultLevel };
19868
20031
  }
19869
20032
  function waitForShutdown2() {
19870
- return new Promise((resolve3) => {
20033
+ return new Promise((resolve4) => {
19871
20034
  const cleanup = () => {
19872
20035
  process.off("SIGINT", onSignal);
19873
20036
  process.off("SIGTERM", onSignal);
19874
20037
  };
19875
20038
  const onSignal = () => {
19876
20039
  cleanup();
19877
- resolve3();
20040
+ resolve4();
19878
20041
  };
19879
20042
  process.once("SIGINT", onSignal);
19880
20043
  process.once("SIGTERM", onSignal);
@@ -21853,7 +22016,7 @@ Error: ${resolved.error}
21853
22016
  function isCliEntryPoint() {
21854
22017
  if (!process.argv[1]) return false;
21855
22018
  try {
21856
- return realpathSync2(fileURLToPath(import.meta.url)) === realpathSync2(process.argv[1]);
22019
+ return realpathSync3(fileURLToPath(import.meta.url)) === realpathSync3(process.argv[1]);
21857
22020
  } catch {
21858
22021
  return false;
21859
22022
  }