@bman654/clodex 2.11.3 → 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-
|
|
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
|
|
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((
|
|
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
|
-
|
|
369
|
+
resolve4(code ?? 0);
|
|
370
370
|
});
|
|
371
371
|
child.on("error", (err) => {
|
|
372
372
|
restore();
|
|
373
|
-
|
|
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.
|
|
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((
|
|
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
|
-
|
|
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((
|
|
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((
|
|
982
|
+
return new Promise((resolve4, reject) => {
|
|
983
983
|
if (buffered) {
|
|
984
|
-
|
|
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
|
-
|
|
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
|
|
3891
|
+
readFileSync as readFileSync9,
|
|
3892
3892
|
renameSync as renameSync2,
|
|
3893
3893
|
rmSync,
|
|
3894
|
-
statSync as
|
|
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
|
|
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
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
|
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(
|
|
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 (!
|
|
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((
|
|
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
|
-
|
|
8559
|
+
resolve4();
|
|
8460
8560
|
};
|
|
8461
8561
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
8462
8562
|
cancelTimer = this.schedule(ms, fire);
|
|
@@ -8663,6 +8763,7 @@ function normalizeToolCallJson(value) {
|
|
|
8663
8763
|
}
|
|
8664
8764
|
}
|
|
8665
8765
|
if (record.type === "reasoning") {
|
|
8766
|
+
delete out.id;
|
|
8666
8767
|
if (Array.isArray(record.content) && record.content.length === 0) delete out.content;
|
|
8667
8768
|
if (typeof record.encrypted_content === "string" && record.encrypted_content) delete out.summary;
|
|
8668
8769
|
}
|
|
@@ -11067,7 +11168,7 @@ function decodeRequestBody(raw, encoding) {
|
|
|
11067
11168
|
}
|
|
11068
11169
|
}
|
|
11069
11170
|
function readBody(req) {
|
|
11070
|
-
return new Promise((
|
|
11171
|
+
return new Promise((resolve4, reject) => {
|
|
11071
11172
|
const chunks = [];
|
|
11072
11173
|
let totalSize = 0;
|
|
11073
11174
|
req.on("data", (c) => {
|
|
@@ -11081,7 +11182,7 @@ function readBody(req) {
|
|
|
11081
11182
|
});
|
|
11082
11183
|
req.on("end", () => {
|
|
11083
11184
|
try {
|
|
11084
|
-
|
|
11185
|
+
resolve4(decodeRequestBody(Buffer.concat(chunks), req.headers["content-encoding"]));
|
|
11085
11186
|
} catch (err) {
|
|
11086
11187
|
reject(err);
|
|
11087
11188
|
}
|
|
@@ -11606,6 +11707,49 @@ function resolveUpstreamTools(tools, messages) {
|
|
|
11606
11707
|
return upstream;
|
|
11607
11708
|
}
|
|
11608
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
|
+
|
|
11609
11753
|
// src/upstream-attempts.ts
|
|
11610
11754
|
import { APICallError as APICallError2, RetryError as RetryError2, wrapLanguageModel as wrapLanguageModel2 } from "ai";
|
|
11611
11755
|
function restoreSyntheticRetryAfterHeader(error) {
|
|
@@ -11672,6 +11816,71 @@ var CLAUDE_CODE_COMPACT_PROMPT_MARKERS = Object.freeze({
|
|
|
11672
11816
|
end: "REMINDER: Do NOT call any tools. Respond with plain text only"
|
|
11673
11817
|
});
|
|
11674
11818
|
|
|
11819
|
+
// src/openai-thinking.ts
|
|
11820
|
+
var SIGNATURE_PREFIX = "clodex:openai-thinking:";
|
|
11821
|
+
var SIGNATURE_V1 = `${SIGNATURE_PREFIX}v1:`;
|
|
11822
|
+
function openAiReasoningItemId(part) {
|
|
11823
|
+
const id = part.providerMetadata?.openai?.itemId;
|
|
11824
|
+
return typeof id === "string" && id.length > 0 ? id : void 0;
|
|
11825
|
+
}
|
|
11826
|
+
var OpenAiThinkingBlock = class {
|
|
11827
|
+
parts = /* @__PURE__ */ new Map();
|
|
11828
|
+
hasText = false;
|
|
11829
|
+
start(part) {
|
|
11830
|
+
const itemId = openAiReasoningItemId(part);
|
|
11831
|
+
if (!itemId || !part.id) throw new Error("OpenAI reasoning part has no identity");
|
|
11832
|
+
if (!this.parts.has(part.id)) this.parts.set(part.id, { itemId, text: "" });
|
|
11833
|
+
this.end(part);
|
|
11834
|
+
}
|
|
11835
|
+
append(part) {
|
|
11836
|
+
const entry = this.parts.get(part.id ?? "");
|
|
11837
|
+
if (!entry) throw new Error("OpenAI reasoning delta has no matching start");
|
|
11838
|
+
const text5 = part.text ?? "";
|
|
11839
|
+
if (!text5) return "";
|
|
11840
|
+
const separator = entry.text.length === 0 && this.hasText ? "\n\n" : "";
|
|
11841
|
+
entry.text += text5;
|
|
11842
|
+
this.hasText = true;
|
|
11843
|
+
return separator + text5;
|
|
11844
|
+
}
|
|
11845
|
+
end(part) {
|
|
11846
|
+
const entry = this.parts.get(part.id ?? "");
|
|
11847
|
+
const encrypted = part.providerMetadata?.openai?.reasoningEncryptedContent;
|
|
11848
|
+
if (entry && typeof encrypted === "string" && encrypted) entry.encryptedContent = encrypted;
|
|
11849
|
+
}
|
|
11850
|
+
signature() {
|
|
11851
|
+
return SIGNATURE_V1 + JSON.stringify({ parts: [...this.parts.values()] });
|
|
11852
|
+
}
|
|
11853
|
+
};
|
|
11854
|
+
function isRecord(value) {
|
|
11855
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
11856
|
+
}
|
|
11857
|
+
function restoreOpenAiThinking(text5, signature, npm) {
|
|
11858
|
+
if (!signature?.startsWith(SIGNATURE_PREFIX)) return void 0;
|
|
11859
|
+
if (!signature.startsWith(SIGNATURE_V1)) return [];
|
|
11860
|
+
try {
|
|
11861
|
+
const envelope = JSON.parse(signature.slice(SIGNATURE_V1.length));
|
|
11862
|
+
if (!isRecord(envelope) || !Array.isArray(envelope.parts) || envelope.parts.length === 0) return [];
|
|
11863
|
+
const parts = [];
|
|
11864
|
+
for (const part of envelope.parts) {
|
|
11865
|
+
if (!isRecord(part) || typeof part.itemId !== "string" || !part.itemId || typeof part.text !== "string" || part.encryptedContent !== void 0 && typeof part.encryptedContent !== "string") return [];
|
|
11866
|
+
parts.push(part);
|
|
11867
|
+
}
|
|
11868
|
+
if (npm !== "@ai-sdk/openai") return text5 ? [{ type: "reasoning", text: text5 }] : [];
|
|
11869
|
+
return parts.map((part) => ({
|
|
11870
|
+
type: "reasoning",
|
|
11871
|
+
text: part.text,
|
|
11872
|
+
providerOptions: {
|
|
11873
|
+
openai: {
|
|
11874
|
+
itemId: part.itemId,
|
|
11875
|
+
...part.encryptedContent ? { reasoningEncryptedContent: part.encryptedContent } : {}
|
|
11876
|
+
}
|
|
11877
|
+
}
|
|
11878
|
+
}));
|
|
11879
|
+
} catch {
|
|
11880
|
+
return [];
|
|
11881
|
+
}
|
|
11882
|
+
}
|
|
11883
|
+
|
|
11675
11884
|
// src/sdk-adapter.ts
|
|
11676
11885
|
function sdkTranslationErrorSignature(error) {
|
|
11677
11886
|
const message = error instanceof Error ? error.message : typeof error === "string" ? error : void 0;
|
|
@@ -11876,8 +12085,12 @@ function translateMessages(messages, npm, openAiPromptCacheBreakpoints = false)
|
|
|
11876
12085
|
if (b.type === "text") {
|
|
11877
12086
|
parts.push({ type: "text", text: b.text ?? "" });
|
|
11878
12087
|
} else if (b.type === "thinking") {
|
|
11879
|
-
const
|
|
11880
|
-
if (
|
|
12088
|
+
const restored = restoreOpenAiThinking(b.thinking ?? "", b.signature, npm);
|
|
12089
|
+
if (restored) parts.push(...restored);
|
|
12090
|
+
else {
|
|
12091
|
+
const part = thinkingToSdkPart(b, npm);
|
|
12092
|
+
if (part) parts.push(part);
|
|
12093
|
+
}
|
|
11881
12094
|
} else if (b.type === "tool_use" && b.id) {
|
|
11882
12095
|
const { rawId, thoughtSignature } = splitToolUseId(b.id);
|
|
11883
12096
|
const part = {
|
|
@@ -11922,12 +12135,13 @@ function toolRequiredProps(tools) {
|
|
|
11922
12135
|
}
|
|
11923
12136
|
function translateTools(anthropicTools, npm) {
|
|
11924
12137
|
if (!anthropicTools?.length) return void 0;
|
|
12138
|
+
const anthropicFormat = npm === "@ai-sdk/anthropic" || npm === VERTEX_ANTHROPIC_NPM;
|
|
11925
12139
|
const tools = {};
|
|
11926
12140
|
for (const t of anthropicTools) {
|
|
11927
12141
|
if (!t.name || !t.input_schema) continue;
|
|
11928
12142
|
tools[t.name] = tool({
|
|
11929
12143
|
description: t.description ?? "",
|
|
11930
|
-
inputSchema: jsonSchema(t.input_schema),
|
|
12144
|
+
inputSchema: jsonSchema(anthropicFormat ? t.input_schema : sanitizeToolSchema(t.input_schema)),
|
|
11931
12145
|
strict: npm === "@ai-sdk/openai" ? false : void 0
|
|
11932
12146
|
});
|
|
11933
12147
|
}
|
|
@@ -12119,6 +12333,7 @@ async function writeAnthropicStream(stream, modelId, write, log12, observer, too
|
|
|
12119
12333
|
let started = false;
|
|
12120
12334
|
let openType = null;
|
|
12121
12335
|
let pendingThinkingSig;
|
|
12336
|
+
let openAiThinking;
|
|
12122
12337
|
const idToBlock = /* @__PURE__ */ new Map();
|
|
12123
12338
|
const toolJsonBuffer = /* @__PURE__ */ new Map();
|
|
12124
12339
|
const flushedTools = /* @__PURE__ */ new Set();
|
|
@@ -12158,9 +12373,10 @@ async function writeAnthropicStream(stream, modelId, write, log12, observer, too
|
|
|
12158
12373
|
emit("content_block_delta", {
|
|
12159
12374
|
type: "content_block_delta",
|
|
12160
12375
|
index: blockIndex,
|
|
12161
|
-
delta: { type: "signature_delta", signature: pendingThinkingSig ?? "" }
|
|
12376
|
+
delta: { type: "signature_delta", signature: openAiThinking?.signature() ?? pendingThinkingSig ?? "" }
|
|
12162
12377
|
});
|
|
12163
12378
|
pendingThinkingSig = void 0;
|
|
12379
|
+
openAiThinking = void 0;
|
|
12164
12380
|
}
|
|
12165
12381
|
if (openType === "tool" && openToolId !== null && !flushedTools.has(openToolId)) {
|
|
12166
12382
|
const buffered = toolJsonBuffer.get(openToolId);
|
|
@@ -12200,19 +12416,30 @@ async function writeAnthropicStream(stream, modelId, write, log12, observer, too
|
|
|
12200
12416
|
case "abort":
|
|
12201
12417
|
throw streamAbortError(observer?.abortSignal);
|
|
12202
12418
|
case "reasoning-start":
|
|
12203
|
-
|
|
12419
|
+
if (openAiReasoningItemId(part) && part.id) {
|
|
12420
|
+
if (!openAiThinking) {
|
|
12421
|
+
openBlock("thinking", { type: "thinking", thinking: "", signature: "" });
|
|
12422
|
+
openAiThinking = new OpenAiThinkingBlock();
|
|
12423
|
+
}
|
|
12424
|
+
openAiThinking.start(part);
|
|
12425
|
+
} else {
|
|
12426
|
+
openBlock("thinking", { type: "thinking", thinking: "", signature: "" });
|
|
12427
|
+
}
|
|
12204
12428
|
break;
|
|
12205
12429
|
case "reasoning-delta":
|
|
12206
12430
|
if (openType !== "thinking") openBlock("thinking", { type: "thinking", thinking: "", signature: "" });
|
|
12207
12431
|
emit("content_block_delta", {
|
|
12208
12432
|
type: "content_block_delta",
|
|
12209
12433
|
index: blockIndex,
|
|
12210
|
-
delta: { type: "thinking_delta", thinking: part.text ?? "" }
|
|
12434
|
+
delta: { type: "thinking_delta", thinking: openAiThinking ? openAiThinking.append(part) : part.text ?? "" }
|
|
12211
12435
|
});
|
|
12212
12436
|
break;
|
|
12213
12437
|
case "reasoning-end": {
|
|
12214
|
-
|
|
12215
|
-
|
|
12438
|
+
if (openAiThinking) openAiThinking.end(part);
|
|
12439
|
+
else {
|
|
12440
|
+
const sig = grabRoundTripSignature(part);
|
|
12441
|
+
if (sig) pendingThinkingSig = sig;
|
|
12442
|
+
}
|
|
12216
12443
|
break;
|
|
12217
12444
|
}
|
|
12218
12445
|
case "text-start":
|
|
@@ -13318,7 +13545,7 @@ function getPatchLockPath() {
|
|
|
13318
13545
|
}
|
|
13319
13546
|
function readPatchManifest(path = getPatchManifestPath()) {
|
|
13320
13547
|
try {
|
|
13321
|
-
const parsed = JSON.parse(
|
|
13548
|
+
const parsed = JSON.parse(readFileSync9(path, "utf8"));
|
|
13322
13549
|
if (parsed && typeof parsed.binaryPath === "string" && typeof parsed.configHash === "string") {
|
|
13323
13550
|
return parsed;
|
|
13324
13551
|
}
|
|
@@ -13497,7 +13724,7 @@ function tryAcquirePatchLock(lockPath = getPatchLockPath(), opts = {}) {
|
|
|
13497
13724
|
} catch {
|
|
13498
13725
|
let stale = false;
|
|
13499
13726
|
try {
|
|
13500
|
-
const existing = JSON.parse(
|
|
13727
|
+
const existing = JSON.parse(readFileSync9(lockPath, "utf8"));
|
|
13501
13728
|
stale = !existing.pid || !isAlive(existing.pid) || typeof existing.startedAt === "number" && now - existing.startedAt > PATCH_LOCK_STALE_MS;
|
|
13502
13729
|
} catch {
|
|
13503
13730
|
stale = true;
|
|
@@ -13518,12 +13745,24 @@ function resolveClaudeBinaryForPatch() {
|
|
|
13518
13745
|
if (!source) return { ok: false, reason: "binary-not-found" };
|
|
13519
13746
|
let resolved;
|
|
13520
13747
|
try {
|
|
13521
|
-
resolved =
|
|
13748
|
+
resolved = realpathSync2(source);
|
|
13522
13749
|
} catch {
|
|
13523
13750
|
return { ok: false, reason: "binary-not-found" };
|
|
13524
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;
|
|
13525
13764
|
try {
|
|
13526
|
-
if (!
|
|
13765
|
+
if (!statSync7(resolved).isFile()) return { ok: false, reason: "binary-not-found" };
|
|
13527
13766
|
} catch {
|
|
13528
13767
|
return { ok: false, reason: "binary-not-found" };
|
|
13529
13768
|
}
|
|
@@ -13532,6 +13771,9 @@ function resolveClaudeBinaryForPatch() {
|
|
|
13532
13771
|
return { ok: true, binaryPath: resolved, version };
|
|
13533
13772
|
}
|
|
13534
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
|
+
}
|
|
13535
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.`;
|
|
13536
13778
|
}
|
|
13537
13779
|
function summarizePatchResults(results) {
|
|
@@ -13628,7 +13870,7 @@ async function applyPatch(binaryPath, version, desired, configHash, opts) {
|
|
|
13628
13870
|
try {
|
|
13629
13871
|
mkdirSync5(backupDir(), { recursive: true });
|
|
13630
13872
|
const { tryDetectInstallation, readContent, writeContent } = await import("tweakcc");
|
|
13631
|
-
candidateDir = mkdtempSync(join7(
|
|
13873
|
+
candidateDir = mkdtempSync(join7(dirname4(binaryPath), ".clodex-patch-"));
|
|
13632
13874
|
const candidatePath = join7(candidateDir, basename(binaryPath));
|
|
13633
13875
|
const seedCandidate = async (from) => {
|
|
13634
13876
|
copyFileSync(from, candidatePath);
|
|
@@ -13759,7 +14001,7 @@ async function applyPatch(binaryPath, version, desired, configHash, opts) {
|
|
|
13759
14001
|
}
|
|
13760
14002
|
if (writeShim) restoreEntryModuleName(candidatePath, writeShim, { resign: true });
|
|
13761
14003
|
else if (publishedBlob) resignMachOBinary(candidatePath);
|
|
13762
|
-
patchedSize =
|
|
14004
|
+
patchedSize = statSync7(candidatePath).size;
|
|
13763
14005
|
patchedSha256 = sha256File(candidatePath);
|
|
13764
14006
|
renameSync2(candidatePath, binaryPath);
|
|
13765
14007
|
} catch (err) {
|
|
@@ -13816,6 +14058,10 @@ function runRestoreCommand(target) {
|
|
|
13816
14058
|
p2.log.error(describePatchTargetFailure(target));
|
|
13817
14059
|
return 1;
|
|
13818
14060
|
}
|
|
14061
|
+
if (!target.ok && target.reason === "launcher-unresolved" && target.declaredTarget === null) {
|
|
14062
|
+
p2.log.error(describePatchTargetFailure(target));
|
|
14063
|
+
return 1;
|
|
14064
|
+
}
|
|
13819
14065
|
const binaryPath = target.binaryPath;
|
|
13820
14066
|
const manifest = readPatchManifest();
|
|
13821
14067
|
let version;
|
|
@@ -13884,7 +14130,7 @@ async function runPatchCommand(opts = {}) {
|
|
|
13884
14130
|
binaryPath,
|
|
13885
14131
|
claudeVersion: version,
|
|
13886
14132
|
configHash,
|
|
13887
|
-
binarySize:
|
|
14133
|
+
binarySize: statSync7(binaryPath).size
|
|
13888
14134
|
});
|
|
13889
14135
|
if (state === "current") {
|
|
13890
14136
|
p2.log.success(`claude ${version} is already patched with the current model config \u2014 nothing to do.`);
|
|
@@ -13921,7 +14167,7 @@ async function runLaunchPatchCheck(opts = {}) {
|
|
|
13921
14167
|
if (Object.keys(desired.config).length === 0) return;
|
|
13922
14168
|
const target = resolveClaudeBinaryForPatch();
|
|
13923
14169
|
if (!target.ok) {
|
|
13924
|
-
if (target.reason
|
|
14170
|
+
if (target.reason !== "binary-not-found" && !opts.agentStdout) {
|
|
13925
14171
|
console.error(pc3.dim(`clodex: ${describePatchTargetFailure(target)}`));
|
|
13926
14172
|
}
|
|
13927
14173
|
return;
|
|
@@ -13940,7 +14186,7 @@ async function runLaunchPatchCheck(opts = {}) {
|
|
|
13940
14186
|
binaryPath: resolved.binaryPath,
|
|
13941
14187
|
claudeVersion: resolved.version,
|
|
13942
14188
|
configHash,
|
|
13943
|
-
binarySize:
|
|
14189
|
+
binarySize: statSync7(resolved.binaryPath).size
|
|
13944
14190
|
});
|
|
13945
14191
|
if (state === "current") return;
|
|
13946
14192
|
const interactive = !opts.dryRun && !opts.agentStdout && process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
@@ -14283,12 +14529,12 @@ import {
|
|
|
14283
14529
|
lstatSync,
|
|
14284
14530
|
mkdirSync as mkdirSync6,
|
|
14285
14531
|
openSync as openSync7,
|
|
14286
|
-
readFileSync as
|
|
14532
|
+
readFileSync as readFileSync10,
|
|
14287
14533
|
renameSync as renameSync3,
|
|
14288
14534
|
unlinkSync as unlinkSync4,
|
|
14289
14535
|
writeFileSync as writeFileSync6
|
|
14290
14536
|
} from "fs";
|
|
14291
|
-
import { dirname as
|
|
14537
|
+
import { dirname as dirname5 } from "path";
|
|
14292
14538
|
var JOURNAL_SCHEMA_VERSION = 1;
|
|
14293
14539
|
var DIR_MODE2 = 448;
|
|
14294
14540
|
var FILE_MODE4 = 384;
|
|
@@ -14390,7 +14636,7 @@ function readJournalUnlocked(path) {
|
|
|
14390
14636
|
if (opened.size > MAX_JOURNAL_BYTES) {
|
|
14391
14637
|
throw new Error("Credential cleanup journal is too large.");
|
|
14392
14638
|
}
|
|
14393
|
-
return parseJournal(JSON.parse(
|
|
14639
|
+
return parseJournal(JSON.parse(readFileSync10(fd, "utf8")));
|
|
14394
14640
|
} catch (error) {
|
|
14395
14641
|
const message = error instanceof Error ? error.message : String(error);
|
|
14396
14642
|
throw new Error(`Could not read credential cleanup journal: ${message}`);
|
|
@@ -14401,7 +14647,7 @@ function readJournalUnlocked(path) {
|
|
|
14401
14647
|
function syncParentDirectory(path) {
|
|
14402
14648
|
let fd;
|
|
14403
14649
|
try {
|
|
14404
|
-
fd = openSync7(
|
|
14650
|
+
fd = openSync7(dirname5(path), "r");
|
|
14405
14651
|
fsyncSync2(fd);
|
|
14406
14652
|
} catch (error) {
|
|
14407
14653
|
const code = error.code;
|
|
@@ -14413,7 +14659,7 @@ function syncParentDirectory(path) {
|
|
|
14413
14659
|
function writeJournalUnlocked(journal, path) {
|
|
14414
14660
|
assertRegistryWriteOwnership(path);
|
|
14415
14661
|
ensureSecureAppHome();
|
|
14416
|
-
mkdirSync6(
|
|
14662
|
+
mkdirSync6(dirname5(path), { recursive: true, mode: DIR_MODE2 });
|
|
14417
14663
|
const tmp = `${path}.${process.pid}.${randomUUID4()}.tmp`;
|
|
14418
14664
|
let fd;
|
|
14419
14665
|
try {
|
|
@@ -17656,8 +17902,8 @@ async function startServer(options) {
|
|
|
17656
17902
|
url: `http://${tcpListenerUrlHost(address.address)}:${address.port}`,
|
|
17657
17903
|
server,
|
|
17658
17904
|
inferenceLogPath: options.inferenceLogPath,
|
|
17659
|
-
close: () => new Promise((
|
|
17660
|
-
server.close((err) => err ? reject(err) :
|
|
17905
|
+
close: () => new Promise((resolve4, reject) => {
|
|
17906
|
+
server.close((err) => err ? reject(err) : resolve4());
|
|
17661
17907
|
})
|
|
17662
17908
|
};
|
|
17663
17909
|
}
|
|
@@ -18396,8 +18642,8 @@ import { createBrotliDecompress, createGunzip, createInflate } from "zlib";
|
|
|
18396
18642
|
|
|
18397
18643
|
// src/http-proxy/ca.ts
|
|
18398
18644
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
18399
|
-
import { chmodSync as chmodSync4, existsSync as existsSync7, mkdirSync as mkdirSync7, readFileSync as
|
|
18400
|
-
import { dirname as
|
|
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";
|
|
18401
18647
|
import forge from "node-forge";
|
|
18402
18648
|
var CERT_DIR = "http-proxy";
|
|
18403
18649
|
var CA_CERT_FILE = "clodex-ca.pem";
|
|
@@ -18472,8 +18718,8 @@ function generateCertificates(paths) {
|
|
|
18472
18718
|
}
|
|
18473
18719
|
function storedCertificatesAreCurrent(paths) {
|
|
18474
18720
|
try {
|
|
18475
|
-
const ca = forge.pki.certificateFromPem(
|
|
18476
|
-
const server = forge.pki.certificateFromPem(
|
|
18721
|
+
const ca = forge.pki.certificateFromPem(readFileSync11(paths.caCert, "utf8"));
|
|
18722
|
+
const server = forge.pki.certificateFromPem(readFileSync11(paths.serverCert, "utf8"));
|
|
18477
18723
|
const now = Date.now();
|
|
18478
18724
|
const renewalBuffer = 7 * 24 * 60 * 60 * 1e3;
|
|
18479
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);
|
|
@@ -18484,13 +18730,13 @@ function storedCertificatesAreCurrent(paths) {
|
|
|
18484
18730
|
function ensureHttpProxyCertificates() {
|
|
18485
18731
|
const paths = certPaths();
|
|
18486
18732
|
const required = [paths.caCert, paths.caKey, paths.serverCert, paths.serverKey, paths.version];
|
|
18487
|
-
const current = required.every(existsSync7) &&
|
|
18733
|
+
const current = required.every(existsSync7) && readFileSync11(paths.version, "utf8") === CERT_VERSION && storedCertificatesAreCurrent(paths);
|
|
18488
18734
|
if (!current) generateCertificates(paths);
|
|
18489
18735
|
return {
|
|
18490
18736
|
caCertPath: paths.caCert,
|
|
18491
|
-
caCert:
|
|
18492
|
-
serverCert:
|
|
18493
|
-
serverKey:
|
|
18737
|
+
caCert: readFileSync11(paths.caCert, "utf8"),
|
|
18738
|
+
serverCert: readFileSync11(paths.serverCert, "utf8"),
|
|
18739
|
+
serverKey: readFileSync11(paths.serverKey, "utf8")
|
|
18494
18740
|
};
|
|
18495
18741
|
}
|
|
18496
18742
|
function ensureHttpProxyCaBundle(relayCaCertPath, additionalCaCertPath, onWarning) {
|
|
@@ -18503,8 +18749,8 @@ function ensureHttpProxyCaBundle(relayCaCertPath, additionalCaCertPath, onWarnin
|
|
|
18503
18749
|
};
|
|
18504
18750
|
let additionalCa;
|
|
18505
18751
|
try {
|
|
18506
|
-
if (
|
|
18507
|
-
additionalCa =
|
|
18752
|
+
if (resolve3(additionalCaCertPath) === resolve3(relayCaCertPath)) return relayCaCertPath;
|
|
18753
|
+
additionalCa = readFileSync11(additionalCaCertPath, "utf8").trim();
|
|
18508
18754
|
} catch (err) {
|
|
18509
18755
|
return warn(
|
|
18510
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.`
|
|
@@ -18514,15 +18760,15 @@ function ensureHttpProxyCaBundle(relayCaCertPath, additionalCaCertPath, onWarnin
|
|
|
18514
18760
|
return warn(`NODE_EXTRA_CA_CERTS=${additionalCaCertPath} is empty, so it adds nothing.`);
|
|
18515
18761
|
}
|
|
18516
18762
|
try {
|
|
18517
|
-
const relayCa =
|
|
18518
|
-
const combinedPath = join8(
|
|
18763
|
+
const relayCa = readFileSync11(relayCaCertPath, "utf8").trimEnd();
|
|
18764
|
+
const combinedPath = join8(dirname6(relayCaCertPath), "combined-ca.pem");
|
|
18519
18765
|
writePublic(combinedPath, `${relayCa}
|
|
18520
18766
|
${additionalCa}
|
|
18521
18767
|
`);
|
|
18522
18768
|
return combinedPath;
|
|
18523
18769
|
} catch (err) {
|
|
18524
18770
|
return warn(
|
|
18525
|
-
`clodex could not build the combined CA bundle in ${
|
|
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.`
|
|
18526
18772
|
);
|
|
18527
18773
|
}
|
|
18528
18774
|
}
|
|
@@ -18625,7 +18871,7 @@ function shouldInterceptConnect(authority) {
|
|
|
18625
18871
|
return Boolean(target && target.port === 443 && target.host.replace(/\.$/, "").toLowerCase() === ANTHROPIC_HOST);
|
|
18626
18872
|
}
|
|
18627
18873
|
function readRawBody(req) {
|
|
18628
|
-
return new Promise((
|
|
18874
|
+
return new Promise((resolve4, reject) => {
|
|
18629
18875
|
const chunks = [];
|
|
18630
18876
|
let size = 0;
|
|
18631
18877
|
req.on("data", (chunk) => {
|
|
@@ -18637,7 +18883,7 @@ function readRawBody(req) {
|
|
|
18637
18883
|
}
|
|
18638
18884
|
chunks.push(chunk);
|
|
18639
18885
|
});
|
|
18640
|
-
req.on("end", () =>
|
|
18886
|
+
req.on("end", () => resolve4(Buffer.concat(chunks)));
|
|
18641
18887
|
req.on("error", reject);
|
|
18642
18888
|
});
|
|
18643
18889
|
}
|
|
@@ -18688,7 +18934,7 @@ function requestHeadersWithoutProxyHeaders(req) {
|
|
|
18688
18934
|
return headers;
|
|
18689
18935
|
}
|
|
18690
18936
|
function forwardRawAnthropicRequest(req, res, rawBody, origin, rejectUnauthorized, agent, onErrorResponse, onResponseUsage, lifecycle, isLocalShutdown = () => false) {
|
|
18691
|
-
return new Promise((
|
|
18937
|
+
return new Promise((resolve4) => {
|
|
18692
18938
|
const startedAt = Date.now();
|
|
18693
18939
|
const retryBudget = passthroughUpstreamRetries();
|
|
18694
18940
|
let lastActivityAt = startedAt;
|
|
@@ -18737,7 +18983,7 @@ function forwardRawAnthropicRequest(req, res, rawBody, origin, rejectUnauthorize
|
|
|
18737
18983
|
const done = () => {
|
|
18738
18984
|
if (settled) return;
|
|
18739
18985
|
settled = true;
|
|
18740
|
-
|
|
18986
|
+
resolve4();
|
|
18741
18987
|
};
|
|
18742
18988
|
const errorType = (err) => err.code ?? err.name;
|
|
18743
18989
|
let upstream;
|
|
@@ -18886,7 +19132,7 @@ function forwardRawAnthropicRequest(req, res, rawBody, origin, rejectUnauthorize
|
|
|
18886
19132
|
});
|
|
18887
19133
|
}
|
|
18888
19134
|
function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.request, adapterAgent, lifecycle, isLocalShutdown = () => false) {
|
|
18889
|
-
return new Promise((
|
|
19135
|
+
return new Promise((resolve4) => {
|
|
18890
19136
|
const startedAt = Date.now();
|
|
18891
19137
|
let lastActivityAt = startedAt;
|
|
18892
19138
|
let headersReceived = false;
|
|
@@ -18961,11 +19207,11 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
|
|
|
18961
19207
|
});
|
|
18962
19208
|
adapterResponse?.destroy(new Error("Client disconnected"));
|
|
18963
19209
|
upstream?.destroy(new Error("Client disconnected"));
|
|
18964
|
-
|
|
19210
|
+
resolve4();
|
|
18965
19211
|
});
|
|
18966
19212
|
const failAdapterRequest = (err, failureSource) => {
|
|
18967
19213
|
if (clientDisconnected2) {
|
|
18968
|
-
|
|
19214
|
+
resolve4();
|
|
18969
19215
|
return;
|
|
18970
19216
|
}
|
|
18971
19217
|
if (headersReceived || failed) return;
|
|
@@ -18986,7 +19232,7 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
|
|
|
18986
19232
|
});
|
|
18987
19233
|
if (!res.headersSent) res.writeHead(502, { "Content-Type": "text/plain" });
|
|
18988
19234
|
res.end(`Relay adapter unreachable: ${err.message}`);
|
|
18989
|
-
|
|
19235
|
+
resolve4();
|
|
18990
19236
|
};
|
|
18991
19237
|
upstream = adapterRequest({
|
|
18992
19238
|
hostname: "127.0.0.1",
|
|
@@ -19023,7 +19269,7 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
|
|
|
19023
19269
|
copyResponse(upstreamRes, res, void 0, lifecycle ? (usage) => writeLifecycle("response_usage", usage) : void 0);
|
|
19024
19270
|
const failAdapterResponse = (err, failureSource) => {
|
|
19025
19271
|
if (clientDisconnected2) {
|
|
19026
|
-
|
|
19272
|
+
resolve4();
|
|
19027
19273
|
return;
|
|
19028
19274
|
}
|
|
19029
19275
|
if (adapterEnded || failed) return;
|
|
@@ -19044,12 +19290,12 @@ function forwardToAdapter(req, res, rawBody, adapter, adapterRequest = http2.req
|
|
|
19044
19290
|
terminationSource: "upstream_failure"
|
|
19045
19291
|
});
|
|
19046
19292
|
if (!res.writableEnded) res.destroy(err);
|
|
19047
|
-
|
|
19293
|
+
resolve4();
|
|
19048
19294
|
};
|
|
19049
19295
|
upstreamRes.once("end", () => {
|
|
19050
19296
|
adapterEnded = true;
|
|
19051
19297
|
lastActivityAt = Date.now();
|
|
19052
|
-
|
|
19298
|
+
resolve4();
|
|
19053
19299
|
});
|
|
19054
19300
|
upstreamRes.once("error", (err) => failAdapterResponse(err, "adapter_response_error"));
|
|
19055
19301
|
upstreamRes.once("aborted", () => failAdapterResponse(
|
|
@@ -19475,7 +19721,7 @@ async function startHttpProxy(options) {
|
|
|
19475
19721
|
close: async () => {
|
|
19476
19722
|
shuttingDown = true;
|
|
19477
19723
|
for (const socket of sockets) socket.destroy();
|
|
19478
|
-
await new Promise((
|
|
19724
|
+
await new Promise((resolve4) => proxyServer.close(() => resolve4()));
|
|
19479
19725
|
mitmServer.close();
|
|
19480
19726
|
anthropicAgent?.destroy();
|
|
19481
19727
|
adapter?.close();
|
|
@@ -19606,11 +19852,11 @@ async function startConfiguredHttpProxy(port, debug = false, inferenceLogPath =
|
|
|
19606
19852
|
return { handle, loaded, ...caWarning ? { caWarning } : {} };
|
|
19607
19853
|
}
|
|
19608
19854
|
function waitForShutdown() {
|
|
19609
|
-
return new Promise((
|
|
19855
|
+
return new Promise((resolve4) => {
|
|
19610
19856
|
const done = () => {
|
|
19611
19857
|
process.off("SIGINT", done);
|
|
19612
19858
|
process.off("SIGTERM", done);
|
|
19613
|
-
|
|
19859
|
+
resolve4();
|
|
19614
19860
|
};
|
|
19615
19861
|
process.once("SIGINT", done);
|
|
19616
19862
|
process.once("SIGTERM", done);
|
|
@@ -19784,14 +20030,14 @@ function enrichServerModelReasoning(model) {
|
|
|
19784
20030
|
return { ...model, defaultEffort: caps.defaultLevel };
|
|
19785
20031
|
}
|
|
19786
20032
|
function waitForShutdown2() {
|
|
19787
|
-
return new Promise((
|
|
20033
|
+
return new Promise((resolve4) => {
|
|
19788
20034
|
const cleanup = () => {
|
|
19789
20035
|
process.off("SIGINT", onSignal);
|
|
19790
20036
|
process.off("SIGTERM", onSignal);
|
|
19791
20037
|
};
|
|
19792
20038
|
const onSignal = () => {
|
|
19793
20039
|
cleanup();
|
|
19794
|
-
|
|
20040
|
+
resolve4();
|
|
19795
20041
|
};
|
|
19796
20042
|
process.once("SIGINT", onSignal);
|
|
19797
20043
|
process.once("SIGTERM", onSignal);
|
|
@@ -21770,7 +22016,7 @@ Error: ${resolved.error}
|
|
|
21770
22016
|
function isCliEntryPoint() {
|
|
21771
22017
|
if (!process.argv[1]) return false;
|
|
21772
22018
|
try {
|
|
21773
|
-
return
|
|
22019
|
+
return realpathSync3(fileURLToPath(import.meta.url)) === realpathSync3(process.argv[1]);
|
|
21774
22020
|
} catch {
|
|
21775
22021
|
return false;
|
|
21776
22022
|
}
|