claude-use 11.87.5 → 11.88.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cli.cjs +1033 -439
- package/dist/index.cjs +1245 -731
- package/dist/index.mjs +1213 -712
- package/dist/types/index.d.ts +396 -7
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -31830,6 +31830,53 @@ var init_supervisor = __esm({
|
|
|
31830
31830
|
}
|
|
31831
31831
|
});
|
|
31832
31832
|
|
|
31833
|
+
// src/sameDirectory.ts
|
|
31834
|
+
function systemErrorCode(error63) {
|
|
31835
|
+
return typeof error63 === "object" && error63 !== null && "code" in error63 && typeof error63.code === "string" ? error63.code : void 0;
|
|
31836
|
+
}
|
|
31837
|
+
function reachableStat(target) {
|
|
31838
|
+
try {
|
|
31839
|
+
return import_node_fs3.default.statSync(target, { throwIfNoEntry: false });
|
|
31840
|
+
} catch (error63) {
|
|
31841
|
+
const code = systemErrorCode(error63);
|
|
31842
|
+
if (code !== void 0 && UNREACHABLE_CODES.has(code)) {
|
|
31843
|
+
return void 0;
|
|
31844
|
+
}
|
|
31845
|
+
throw error63;
|
|
31846
|
+
}
|
|
31847
|
+
}
|
|
31848
|
+
function sameDirectory(first, second) {
|
|
31849
|
+
const a10 = reachableStat(first);
|
|
31850
|
+
const b = reachableStat(second);
|
|
31851
|
+
if (a10 === void 0 || b === void 0) {
|
|
31852
|
+
return false;
|
|
31853
|
+
}
|
|
31854
|
+
return a10.dev === b.dev && a10.ino === b.ino;
|
|
31855
|
+
}
|
|
31856
|
+
function caseSwapped(name) {
|
|
31857
|
+
return name.replace(/[A-Za-z]/gu, (letter) => letter === letter.toLowerCase() ? letter.toUpperCase() : letter.toLowerCase());
|
|
31858
|
+
}
|
|
31859
|
+
function ignoresCase(directory) {
|
|
31860
|
+
if (!import_node_fs3.default.existsSync(directory)) {
|
|
31861
|
+
return false;
|
|
31862
|
+
}
|
|
31863
|
+
const probe = import_node_fs3.default.mkdtempSync(import_node_path11.default.join(directory, ".case-probe-"));
|
|
31864
|
+
try {
|
|
31865
|
+
return sameDirectory(probe, import_node_path11.default.join(directory, caseSwapped(import_node_path11.default.basename(probe))));
|
|
31866
|
+
} finally {
|
|
31867
|
+
import_node_fs3.default.rmSync(probe, { recursive: true, force: true });
|
|
31868
|
+
}
|
|
31869
|
+
}
|
|
31870
|
+
var import_node_fs3, import_node_path11, UNREACHABLE_CODES;
|
|
31871
|
+
var init_sameDirectory = __esm({
|
|
31872
|
+
"src/sameDirectory.ts"() {
|
|
31873
|
+
"use strict";
|
|
31874
|
+
import_node_fs3 = __toESM(require("node:fs"), 1);
|
|
31875
|
+
import_node_path11 = __toESM(require("node:path"), 1);
|
|
31876
|
+
UNREACHABLE_CODES = /* @__PURE__ */ new Set(["ELOOP", "EACCES", "ENOTDIR"]);
|
|
31877
|
+
}
|
|
31878
|
+
});
|
|
31879
|
+
|
|
31833
31880
|
// src/launcher/report.ts
|
|
31834
31881
|
function renderReport(rows, style) {
|
|
31835
31882
|
if (rows.length === 0) {
|
|
@@ -31910,26 +31957,26 @@ function isErrorWithCode(error63, code) {
|
|
|
31910
31957
|
return typeof error63 === "object" && error63 !== null && "code" in error63 && error63.code === code;
|
|
31911
31958
|
}
|
|
31912
31959
|
function writeFileFlushed(file2, contents) {
|
|
31913
|
-
const descriptor =
|
|
31960
|
+
const descriptor = import_node_fs4.default.openSync(file2, "w", OWNER_ONLY_FILE_MODE);
|
|
31914
31961
|
try {
|
|
31915
|
-
|
|
31916
|
-
|
|
31917
|
-
|
|
31962
|
+
import_node_fs4.default.writeFileSync(descriptor, contents, "utf8");
|
|
31963
|
+
import_node_fs4.default.fchmodSync(descriptor, OWNER_ONLY_FILE_MODE);
|
|
31964
|
+
import_node_fs4.default.fsyncSync(descriptor);
|
|
31918
31965
|
} finally {
|
|
31919
|
-
|
|
31966
|
+
import_node_fs4.default.closeSync(descriptor);
|
|
31920
31967
|
}
|
|
31921
31968
|
}
|
|
31922
31969
|
function flushDirectory(directory) {
|
|
31923
|
-
const descriptor =
|
|
31970
|
+
const descriptor = import_node_fs4.default.openSync(directory, "r");
|
|
31924
31971
|
try {
|
|
31925
|
-
|
|
31972
|
+
import_node_fs4.default.fsyncSync(descriptor);
|
|
31926
31973
|
} catch (error63) {
|
|
31927
31974
|
const code = typeof error63 === "object" && error63 !== null && "code" in error63 && typeof error63.code === "string" ? error63.code : void 0;
|
|
31928
31975
|
if (code === void 0 || !DIRECTORY_FLUSH_UNSUPPORTED_CODES.has(code)) {
|
|
31929
31976
|
throw error63;
|
|
31930
31977
|
}
|
|
31931
31978
|
} finally {
|
|
31932
|
-
|
|
31979
|
+
import_node_fs4.default.closeSync(descriptor);
|
|
31933
31980
|
}
|
|
31934
31981
|
}
|
|
31935
31982
|
function realSleepSync(ms) {
|
|
@@ -31964,7 +32011,7 @@ function leadingContinuationBytes(bytes) {
|
|
|
31964
32011
|
}
|
|
31965
32012
|
function realFileSize(filePath) {
|
|
31966
32013
|
try {
|
|
31967
|
-
return
|
|
32014
|
+
return import_node_fs4.default.statSync(filePath).size;
|
|
31968
32015
|
} catch (error63) {
|
|
31969
32016
|
if (isEnoent2(error63)) {
|
|
31970
32017
|
return 0;
|
|
@@ -31979,11 +32026,11 @@ function realReadFileTail(filePath, fromByte, maxBytes) {
|
|
|
31979
32026
|
return "";
|
|
31980
32027
|
}
|
|
31981
32028
|
const buffer2 = Buffer.alloc(size - start);
|
|
31982
|
-
const descriptor =
|
|
32029
|
+
const descriptor = import_node_fs4.default.openSync(filePath, "r");
|
|
31983
32030
|
try {
|
|
31984
32031
|
let read = 0;
|
|
31985
32032
|
while (read < buffer2.length) {
|
|
31986
|
-
const got =
|
|
32033
|
+
const got = import_node_fs4.default.readSync(descriptor, buffer2, read, buffer2.length - read, start + read);
|
|
31987
32034
|
if (got === 0) {
|
|
31988
32035
|
break;
|
|
31989
32036
|
}
|
|
@@ -31996,7 +32043,7 @@ function realReadFileTail(filePath, fromByte, maxBytes) {
|
|
|
31996
32043
|
const lineBreak = bytes.indexOf(LINE_FEED);
|
|
31997
32044
|
return bytes.subarray(lineBreak === -1 ? leadingContinuationBytes(bytes) : lineBreak + 1).toString("utf8");
|
|
31998
32045
|
} finally {
|
|
31999
|
-
|
|
32046
|
+
import_node_fs4.default.closeSync(descriptor);
|
|
32000
32047
|
}
|
|
32001
32048
|
}
|
|
32002
32049
|
function realProcessCommandLine(pid) {
|
|
@@ -32039,7 +32086,7 @@ function realRunAsyncWithin(timeoutMs) {
|
|
|
32039
32086
|
});
|
|
32040
32087
|
}
|
|
32041
32088
|
function expandHome(filePath) {
|
|
32042
|
-
return filePath.startsWith("~/") ?
|
|
32089
|
+
return filePath.startsWith("~/") ? import_node_path12.default.join(import_node_os2.default.homedir(), filePath.slice(1)) : filePath;
|
|
32043
32090
|
}
|
|
32044
32091
|
function hasDesktopSession() {
|
|
32045
32092
|
if (process.platform === "darwin") {
|
|
@@ -32142,8 +32189,8 @@ function spawnDaemonThroughScript(script) {
|
|
|
32142
32189
|
return (paths, subcommand, logPath) => spawnDetachedDaemon({ command: process.execPath, args: [script, subcommand] }, paths, subcommand, logPath);
|
|
32143
32190
|
}
|
|
32144
32191
|
function spawnDetachedDaemon(invocation, paths, subcommand, logPath) {
|
|
32145
|
-
|
|
32146
|
-
const logFd =
|
|
32192
|
+
import_node_fs4.default.mkdirSync(import_node_path12.default.dirname(logPath), { recursive: true });
|
|
32193
|
+
const logFd = import_node_fs4.default.openSync(logPath, "a");
|
|
32147
32194
|
try {
|
|
32148
32195
|
const child = (0, import_node_child_process3.spawn)(invocation.command, invocation.args, detachedDaemonSpawnOptions(logFd, { ...process.env, AGENT_SHIM_HOME: paths.root }));
|
|
32149
32196
|
child.unref();
|
|
@@ -32152,7 +32199,7 @@ function spawnDetachedDaemon(invocation, paths, subcommand, logPath) {
|
|
|
32152
32199
|
}
|
|
32153
32200
|
return child.pid;
|
|
32154
32201
|
} finally {
|
|
32155
|
-
|
|
32202
|
+
import_node_fs4.default.closeSync(logFd);
|
|
32156
32203
|
}
|
|
32157
32204
|
}
|
|
32158
32205
|
function spawnHeadroomSupervisor(paths, spawnDaemon) {
|
|
@@ -32188,7 +32235,7 @@ function realHeadroomPort(paths, options) {
|
|
|
32188
32235
|
function listVersionsDir(dir) {
|
|
32189
32236
|
let entries;
|
|
32190
32237
|
try {
|
|
32191
|
-
entries =
|
|
32238
|
+
entries = import_node_fs4.default.readdirSync(dir, { withFileTypes: true });
|
|
32192
32239
|
} catch (error63) {
|
|
32193
32240
|
if (isEnoent2(error63)) {
|
|
32194
32241
|
return [];
|
|
@@ -32196,8 +32243,8 @@ function listVersionsDir(dir) {
|
|
|
32196
32243
|
throw error63;
|
|
32197
32244
|
}
|
|
32198
32245
|
return entries.filter((entry) => entry.isFile()).map((entry) => {
|
|
32199
|
-
const fullPath =
|
|
32200
|
-
const stat =
|
|
32246
|
+
const fullPath = import_node_path12.default.join(dir, entry.name);
|
|
32247
|
+
const stat = import_node_fs4.default.statSync(fullPath);
|
|
32201
32248
|
return {
|
|
32202
32249
|
name: entry.name,
|
|
32203
32250
|
isFile: true,
|
|
@@ -32210,7 +32257,7 @@ function windowsPathExtensions(pathext) {
|
|
|
32210
32257
|
return (pathext ?? WINDOWS_DEFAULT_PATHEXT).split(";").map((ext) => ext.trim()).filter((ext) => ext.length > 0);
|
|
32211
32258
|
}
|
|
32212
32259
|
function resolveExecutableCandidate(dir, name, env) {
|
|
32213
|
-
const candidate =
|
|
32260
|
+
const candidate = import_node_path12.default.join(dir, name);
|
|
32214
32261
|
if (env.platform === "win32") {
|
|
32215
32262
|
const extensions = windowsPathExtensions(env.pathext);
|
|
32216
32263
|
const alreadyHasRecognisedExtension = extensions.some((ext) => candidate.toLowerCase().endsWith(ext.toLowerCase()));
|
|
@@ -32230,7 +32277,7 @@ function resolveExecutableCandidate(dir, name, env) {
|
|
|
32230
32277
|
}
|
|
32231
32278
|
function realStatFileMode(candidate) {
|
|
32232
32279
|
try {
|
|
32233
|
-
const stat =
|
|
32280
|
+
const stat = import_node_fs4.default.statSync(candidate);
|
|
32234
32281
|
return stat.isFile() ? stat.mode : void 0;
|
|
32235
32282
|
} catch (error63) {
|
|
32236
32283
|
if (isEnoent2(error63)) {
|
|
@@ -32259,13 +32306,13 @@ function resolveOwnExecutablePath(env) {
|
|
|
32259
32306
|
if (env.argv1 !== void 0 && !env.argv1.includes("/") && !env.argv1.includes("\\")) {
|
|
32260
32307
|
return searchPathForExecutable(env.pathDirs, env.argv1, env.findExecutableInDir) ?? env.execPath;
|
|
32261
32308
|
}
|
|
32262
|
-
const candidate = env.argv1 === void 0 ? env.execPath :
|
|
32263
|
-
const candidateDir =
|
|
32264
|
-
const candidateDirOnPath = env.pathDirs.some((dir) =>
|
|
32309
|
+
const candidate = env.argv1 === void 0 ? env.execPath : import_node_path12.default.resolve(env.cwd, env.argv1);
|
|
32310
|
+
const candidateDir = import_node_path12.default.dirname(candidate);
|
|
32311
|
+
const candidateDirOnPath = env.pathDirs.some((dir) => import_node_path12.default.resolve(dir) === candidateDir);
|
|
32265
32312
|
if (candidateDirOnPath) {
|
|
32266
32313
|
return candidate;
|
|
32267
32314
|
}
|
|
32268
|
-
const viaPath = searchPathForExecutable(env.pathDirs,
|
|
32315
|
+
const viaPath = searchPathForExecutable(env.pathDirs, import_node_path12.default.basename(candidate), env.findExecutableInDir);
|
|
32269
32316
|
return viaPath ?? candidate;
|
|
32270
32317
|
}
|
|
32271
32318
|
function realOwnExecutablePath() {
|
|
@@ -32273,7 +32320,7 @@ function realOwnExecutablePath() {
|
|
|
32273
32320
|
argv1: process.argv[1],
|
|
32274
32321
|
execPath: process.execPath,
|
|
32275
32322
|
cwd: process.cwd(),
|
|
32276
|
-
pathDirs: (process.env.PATH ?? "").split(
|
|
32323
|
+
pathDirs: (process.env.PATH ?? "").split(import_node_path12.default.delimiter).filter((dir) => dir !== ""),
|
|
32277
32324
|
findExecutableInDir
|
|
32278
32325
|
});
|
|
32279
32326
|
}
|
|
@@ -32286,7 +32333,7 @@ function realContentSourcePath() {
|
|
|
32286
32333
|
function realResolveClaudeBinary(isOwnBinary) {
|
|
32287
32334
|
return (request7) => discoverClaudeBinary({
|
|
32288
32335
|
listVersionsDir,
|
|
32289
|
-
pathDirs: (process.env.PATH ?? "").split(
|
|
32336
|
+
pathDirs: (process.env.PATH ?? "").split(import_node_path12.default.delimiter).filter((dir) => dir !== ""),
|
|
32290
32337
|
findExecutableInDir,
|
|
32291
32338
|
isOwnBinary,
|
|
32292
32339
|
...request7?.version === void 0 ? {} : { version: request7.version }
|
|
@@ -32295,7 +32342,7 @@ function realResolveClaudeBinary(isOwnBinary) {
|
|
|
32295
32342
|
function realInstalledClaudeVersions() {
|
|
32296
32343
|
return installedVersions(listVersionsDir(defaultVersionsDir()));
|
|
32297
32344
|
}
|
|
32298
|
-
var import_node_child_process3, import_node_crypto4,
|
|
32345
|
+
var import_node_child_process3, import_node_crypto4, import_node_fs4, import_node_os2, import_node_path12, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS, DIRECTORY_FLUSH_UNSUPPORTED_CODES, realFarmFs, INT32_BYTE_LENGTH, KEY_POLL_MS, CTRL_C_BYTE, realHoldPort, LINE_FEED, UTF8_CONTINUATION_MASK, UTF8_CONTINUATION_BITS, PS_TIMEOUT_MS, RUN_OUTPUT_LIMIT_MIB, BYTES_PER_MIB2, RUN_OUTPUT_LIMIT_BYTES, realRunPort, ASYNC_RUN_TIMEOUT_MS, realRunAsync, MACOS_GUI_SESSION_MANAGER, realCredentialPort, realAsyncCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, realLogPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
|
|
32299
32346
|
var init_realPorts = __esm({
|
|
32300
32347
|
"src/realPorts.ts"() {
|
|
32301
32348
|
"use strict";
|
|
@@ -32303,9 +32350,9 @@ var init_realPorts = __esm({
|
|
|
32303
32350
|
init_processRole();
|
|
32304
32351
|
import_node_child_process3 = require("node:child_process");
|
|
32305
32352
|
import_node_crypto4 = require("node:crypto");
|
|
32306
|
-
|
|
32353
|
+
import_node_fs4 = __toESM(require("node:fs"), 1);
|
|
32307
32354
|
import_node_os2 = __toESM(require("node:os"), 1);
|
|
32308
|
-
|
|
32355
|
+
import_node_path12 = __toESM(require("node:path"), 1);
|
|
32309
32356
|
import_node_sea = require("node:sea");
|
|
32310
32357
|
init_load();
|
|
32311
32358
|
init_versionDiscovery();
|
|
@@ -32313,11 +32360,13 @@ var init_realPorts = __esm({
|
|
|
32313
32360
|
init_ensure();
|
|
32314
32361
|
init_supervisor();
|
|
32315
32362
|
init_state2();
|
|
32363
|
+
init_sameDirectory();
|
|
32316
32364
|
init_logStyle();
|
|
32317
32365
|
realFsPort = {
|
|
32366
|
+
sameDirectory,
|
|
32318
32367
|
fileRevision(filePath) {
|
|
32319
32368
|
try {
|
|
32320
|
-
const stat =
|
|
32369
|
+
const stat = import_node_fs4.default.statSync(filePath, { bigint: true });
|
|
32321
32370
|
return [stat.dev, stat.ino, stat.size, stat.mtimeNs, stat.ctimeNs].map(String).join(":");
|
|
32322
32371
|
} catch (error63) {
|
|
32323
32372
|
if (isEnoent2(error63)) return void 0;
|
|
@@ -32326,7 +32375,7 @@ var init_realPorts = __esm({
|
|
|
32326
32375
|
},
|
|
32327
32376
|
readFileUtf8(filePath) {
|
|
32328
32377
|
try {
|
|
32329
|
-
return
|
|
32378
|
+
return import_node_fs4.default.readFileSync(filePath, "utf8");
|
|
32330
32379
|
} catch (error63) {
|
|
32331
32380
|
if (isEnoent2(error63)) {
|
|
32332
32381
|
return void 0;
|
|
@@ -32337,7 +32386,7 @@ var init_realPorts = __esm({
|
|
|
32337
32386
|
readConfigFile: cosmiconfigReader(),
|
|
32338
32387
|
readdir(dirPath) {
|
|
32339
32388
|
try {
|
|
32340
|
-
return
|
|
32389
|
+
return import_node_fs4.default.readdirSync(dirPath);
|
|
32341
32390
|
} catch (error63) {
|
|
32342
32391
|
if (isEnoent2(error63)) {
|
|
32343
32392
|
return [];
|
|
@@ -32354,7 +32403,7 @@ var init_realPorts = __esm({
|
|
|
32354
32403
|
lstat(filePath) {
|
|
32355
32404
|
let stat;
|
|
32356
32405
|
try {
|
|
32357
|
-
stat =
|
|
32406
|
+
stat = import_node_fs4.default.lstatSync(filePath);
|
|
32358
32407
|
} catch (error63) {
|
|
32359
32408
|
if (isEnoent2(error63)) {
|
|
32360
32409
|
return void 0;
|
|
@@ -32366,7 +32415,7 @@ var init_realPorts = __esm({
|
|
|
32366
32415
|
},
|
|
32367
32416
|
readdir(dirPath) {
|
|
32368
32417
|
try {
|
|
32369
|
-
return
|
|
32418
|
+
return import_node_fs4.default.readdirSync(dirPath);
|
|
32370
32419
|
} catch (error63) {
|
|
32371
32420
|
if (isEnoent2(error63) || isErrorWithCode(error63, "ENOTDIR")) {
|
|
32372
32421
|
return [];
|
|
@@ -32375,23 +32424,23 @@ var init_realPorts = __esm({
|
|
|
32375
32424
|
}
|
|
32376
32425
|
},
|
|
32377
32426
|
mkdirp(dirPath) {
|
|
32378
|
-
|
|
32427
|
+
import_node_fs4.default.mkdirSync(dirPath, { recursive: true });
|
|
32379
32428
|
},
|
|
32380
32429
|
symlink(target, linkPath) {
|
|
32381
|
-
|
|
32430
|
+
import_node_fs4.default.symlinkSync(target, linkPath);
|
|
32382
32431
|
},
|
|
32383
32432
|
rename(from, to2) {
|
|
32384
|
-
|
|
32433
|
+
import_node_fs4.default.renameSync(from, to2);
|
|
32385
32434
|
},
|
|
32386
32435
|
removeRecursive(targetPath) {
|
|
32387
|
-
|
|
32436
|
+
import_node_fs4.default.rmSync(targetPath, { recursive: true, force: true });
|
|
32388
32437
|
},
|
|
32389
32438
|
copyRecursive(from, to2) {
|
|
32390
|
-
|
|
32439
|
+
import_node_fs4.default.cpSync(from, to2, { recursive: true, force: true, verbatimSymlinks: true });
|
|
32391
32440
|
},
|
|
32392
32441
|
readFileUtf8(filePath) {
|
|
32393
32442
|
try {
|
|
32394
|
-
return
|
|
32443
|
+
return import_node_fs4.default.readFileSync(filePath, "utf8");
|
|
32395
32444
|
} catch (error63) {
|
|
32396
32445
|
if (isEnoent2(error63)) {
|
|
32397
32446
|
return void 0;
|
|
@@ -32400,47 +32449,47 @@ var init_realPorts = __esm({
|
|
|
32400
32449
|
}
|
|
32401
32450
|
},
|
|
32402
32451
|
writeFileUtf8(filePath, contents) {
|
|
32403
|
-
|
|
32452
|
+
import_node_fs4.default.writeFileSync(filePath, contents, "utf8");
|
|
32404
32453
|
},
|
|
32405
32454
|
mkdirPrivate(dirPath) {
|
|
32406
|
-
|
|
32407
|
-
|
|
32455
|
+
import_node_fs4.default.mkdirSync(dirPath, { recursive: true, mode: OWNER_ONLY_DIR_MODE });
|
|
32456
|
+
import_node_fs4.default.chmodSync(dirPath, OWNER_ONLY_DIR_MODE);
|
|
32408
32457
|
},
|
|
32409
32458
|
writeFilePrivate(filePath, contents, options) {
|
|
32410
32459
|
const temp = `${filePath}.${String(process.pid)}.tmp`;
|
|
32411
32460
|
try {
|
|
32412
32461
|
if (options?.durable === true) {
|
|
32413
32462
|
writeFileFlushed(temp, contents);
|
|
32414
|
-
|
|
32415
|
-
flushDirectory(
|
|
32463
|
+
import_node_fs4.default.renameSync(temp, filePath);
|
|
32464
|
+
flushDirectory(import_node_path12.default.dirname(filePath));
|
|
32416
32465
|
} else {
|
|
32417
|
-
|
|
32418
|
-
|
|
32419
|
-
|
|
32466
|
+
import_node_fs4.default.writeFileSync(temp, contents, { encoding: "utf8", mode: OWNER_ONLY_FILE_MODE });
|
|
32467
|
+
import_node_fs4.default.chmodSync(temp, OWNER_ONLY_FILE_MODE);
|
|
32468
|
+
import_node_fs4.default.renameSync(temp, filePath);
|
|
32420
32469
|
}
|
|
32421
32470
|
} catch (error63) {
|
|
32422
|
-
|
|
32471
|
+
import_node_fs4.default.rmSync(temp, { force: true });
|
|
32423
32472
|
throw error63;
|
|
32424
32473
|
}
|
|
32425
32474
|
},
|
|
32426
32475
|
appendFilePrivate(filePath, contents) {
|
|
32427
|
-
const descriptor =
|
|
32476
|
+
const descriptor = import_node_fs4.default.openSync(filePath, "a", OWNER_ONLY_FILE_MODE);
|
|
32428
32477
|
try {
|
|
32429
|
-
if ((
|
|
32430
|
-
|
|
32478
|
+
if ((import_node_fs4.default.fstatSync(descriptor).mode & PERMISSION_BITS) !== OWNER_ONLY_FILE_MODE) {
|
|
32479
|
+
import_node_fs4.default.fchmodSync(descriptor, OWNER_ONLY_FILE_MODE);
|
|
32431
32480
|
}
|
|
32432
32481
|
const bytes = Buffer.from(contents, "utf8");
|
|
32433
32482
|
let written = 0;
|
|
32434
32483
|
while (written < bytes.length) {
|
|
32435
|
-
written +=
|
|
32484
|
+
written += import_node_fs4.default.writeSync(descriptor, bytes, written, bytes.length - written);
|
|
32436
32485
|
}
|
|
32437
32486
|
} finally {
|
|
32438
|
-
|
|
32487
|
+
import_node_fs4.default.closeSync(descriptor);
|
|
32439
32488
|
}
|
|
32440
32489
|
},
|
|
32441
32490
|
writeFileExclusive(filePath, contents) {
|
|
32442
32491
|
try {
|
|
32443
|
-
|
|
32492
|
+
import_node_fs4.default.writeFileSync(filePath, contents, { encoding: "utf8", flag: "wx" });
|
|
32444
32493
|
return true;
|
|
32445
32494
|
} catch (error63) {
|
|
32446
32495
|
if (isErrorWithCode(error63, "EEXIST")) {
|
|
@@ -32451,7 +32500,7 @@ var init_realPorts = __esm({
|
|
|
32451
32500
|
},
|
|
32452
32501
|
hashFile(filePath) {
|
|
32453
32502
|
try {
|
|
32454
|
-
return (0, import_node_crypto4.createHash)("sha256").update(
|
|
32503
|
+
return (0, import_node_crypto4.createHash)("sha256").update(import_node_fs4.default.readFileSync(filePath)).digest("hex");
|
|
32455
32504
|
} catch (error63) {
|
|
32456
32505
|
if (isEnoent2(error63) || isErrorWithCode(error63, "EISDIR")) {
|
|
32457
32506
|
return void 0;
|
|
@@ -32472,7 +32521,7 @@ var init_realPorts = __esm({
|
|
|
32472
32521
|
const buffer2 = Buffer.alloc(1);
|
|
32473
32522
|
for (; ; ) {
|
|
32474
32523
|
try {
|
|
32475
|
-
const read =
|
|
32524
|
+
const read = import_node_fs4.default.readSync(process.stdin.fd, buffer2, 0, buffer2.length, null);
|
|
32476
32525
|
return read > 0 && buffer2[0] === CTRL_C_BYTE ? "interrupt" : "key";
|
|
32477
32526
|
} catch (error63) {
|
|
32478
32527
|
if (!(error63 instanceof Error && "code" in error63 && error63.code === "EAGAIN")) {
|
|
@@ -32508,8 +32557,8 @@ var init_realPorts = __esm({
|
|
|
32508
32557
|
let content;
|
|
32509
32558
|
let stat;
|
|
32510
32559
|
try {
|
|
32511
|
-
stat =
|
|
32512
|
-
content =
|
|
32560
|
+
stat = import_node_fs4.default.statSync(resolved);
|
|
32561
|
+
content = import_node_fs4.default.readFileSync(resolved, "utf8");
|
|
32513
32562
|
} catch (error63) {
|
|
32514
32563
|
if (isEnoent2(error63)) {
|
|
32515
32564
|
return { found: false };
|
|
@@ -32550,7 +32599,7 @@ var init_realPorts = __esm({
|
|
|
32550
32599
|
lstat: (target) => {
|
|
32551
32600
|
let stat;
|
|
32552
32601
|
try {
|
|
32553
|
-
stat =
|
|
32602
|
+
stat = import_node_fs4.default.lstatSync(target);
|
|
32554
32603
|
} catch (error63) {
|
|
32555
32604
|
if (isEnoent2(error63)) {
|
|
32556
32605
|
return void 0;
|
|
@@ -32560,7 +32609,7 @@ var init_realPorts = __esm({
|
|
|
32560
32609
|
const kind = stat.isSymbolicLink() ? "symlink" : stat.isDirectory() ? "dir" : stat.isFile() ? "file" : stat.isSocket() ? "socket" : "other";
|
|
32561
32610
|
return { kind, uid: stat.uid, mode: stat.mode & SOCKET_PERMISSION_BITS };
|
|
32562
32611
|
},
|
|
32563
|
-
readlink: (target) =>
|
|
32612
|
+
readlink: (target) => import_node_fs4.default.readlinkSync(target, "utf8")
|
|
32564
32613
|
};
|
|
32565
32614
|
realSpawnPort = {
|
|
32566
32615
|
spawnSync(command, args, options) {
|
|
@@ -32601,10 +32650,10 @@ function isInvokedAsClaude(invokedName) {
|
|
|
32601
32650
|
}
|
|
32602
32651
|
function resolveOwnBinaryCheck(paths, contentSourcePath) {
|
|
32603
32652
|
const state = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
32604
|
-
const recordedTarget = state === void 0 ? void 0 :
|
|
32653
|
+
const recordedTarget = state === void 0 ? void 0 : import_node_path13.default.resolve(state.targetPath);
|
|
32605
32654
|
let ownStat;
|
|
32606
32655
|
return (candidate) => {
|
|
32607
|
-
if (recordedTarget !== void 0 &&
|
|
32656
|
+
if (recordedTarget !== void 0 && import_node_path13.default.resolve(candidate) === recordedTarget) {
|
|
32608
32657
|
return true;
|
|
32609
32658
|
}
|
|
32610
32659
|
ownStat ??= statOrUndefined(contentSourcePath);
|
|
@@ -32614,7 +32663,7 @@ function resolveOwnBinaryCheck(paths, contentSourcePath) {
|
|
|
32614
32663
|
};
|
|
32615
32664
|
}
|
|
32616
32665
|
function resolveClaudeTargetPath(ownExecutablePath, dir) {
|
|
32617
|
-
return
|
|
32666
|
+
return import_node_path13.default.join(dir ?? import_node_path13.default.dirname(ownExecutablePath), claudeTargetFilename(ownExecutablePath));
|
|
32618
32667
|
}
|
|
32619
32668
|
function isEnoent3(error63) {
|
|
32620
32669
|
return typeof error63 === "object" && error63 !== null && "code" in error63 && error63.code === "ENOENT";
|
|
@@ -32624,7 +32673,7 @@ function isCrossDeviceError(error63) {
|
|
|
32624
32673
|
}
|
|
32625
32674
|
function lstatOrUndefined(target) {
|
|
32626
32675
|
try {
|
|
32627
|
-
return
|
|
32676
|
+
return import_node_fs5.default.lstatSync(target);
|
|
32628
32677
|
} catch (error63) {
|
|
32629
32678
|
if (isEnoent3(error63)) {
|
|
32630
32679
|
return void 0;
|
|
@@ -32634,7 +32683,7 @@ function lstatOrUndefined(target) {
|
|
|
32634
32683
|
}
|
|
32635
32684
|
function statOrUndefined(target) {
|
|
32636
32685
|
try {
|
|
32637
|
-
return
|
|
32686
|
+
return import_node_fs5.default.statSync(target);
|
|
32638
32687
|
} catch (error63) {
|
|
32639
32688
|
if (isEnoent3(error63)) {
|
|
32640
32689
|
return void 0;
|
|
@@ -32643,22 +32692,22 @@ function statOrUndefined(target) {
|
|
|
32643
32692
|
}
|
|
32644
32693
|
}
|
|
32645
32694
|
function enableClaudeShim(params, linkFs = nodeLinkFs) {
|
|
32646
|
-
const realContentPath =
|
|
32695
|
+
const realContentPath = import_node_fs5.default.realpathSync(params.contentSourcePath);
|
|
32647
32696
|
if (params.platform === "win32" && !realContentPath.toLowerCase().endsWith(".exe")) {
|
|
32648
32697
|
throw new UnsupportedShimSourceError(realContentPath);
|
|
32649
32698
|
}
|
|
32650
32699
|
const targetPath = resolveClaudeTargetPath(params.ownExecutablePath, params.dir);
|
|
32651
|
-
|
|
32700
|
+
import_node_fs5.default.mkdirSync(import_node_path13.default.dirname(targetPath), { recursive: true });
|
|
32652
32701
|
const existing = lstatOrUndefined(targetPath);
|
|
32653
32702
|
if (existing !== void 0) {
|
|
32654
|
-
const ownStat =
|
|
32703
|
+
const ownStat = import_node_fs5.default.statSync(realContentPath);
|
|
32655
32704
|
const state = readJson(params.paths.claudeShimFile, ClaudeShimStateSchema);
|
|
32656
32705
|
const sameInode = existing.dev === ownStat.dev && existing.ino === ownStat.ino;
|
|
32657
|
-
const markerMatches = state !== void 0 &&
|
|
32706
|
+
const markerMatches = state !== void 0 && import_node_path13.default.resolve(state.targetPath) === targetPath;
|
|
32658
32707
|
if (!sameInode && !markerMatches && !params.force) {
|
|
32659
32708
|
throw new ForeignClaudeEntryError(targetPath, "enable");
|
|
32660
32709
|
}
|
|
32661
|
-
|
|
32710
|
+
import_node_fs5.default.rmSync(targetPath, { recursive: true, force: true });
|
|
32662
32711
|
}
|
|
32663
32712
|
let method;
|
|
32664
32713
|
try {
|
|
@@ -32677,36 +32726,36 @@ function enableClaudeShim(params, linkFs = nodeLinkFs) {
|
|
|
32677
32726
|
return { action: existing === void 0 ? "enabled" : "reenabled", targetPath, method };
|
|
32678
32727
|
}
|
|
32679
32728
|
function disableClaudeShim(params) {
|
|
32680
|
-
const realContentPath =
|
|
32729
|
+
const realContentPath = import_node_fs5.default.realpathSync(params.contentSourcePath);
|
|
32681
32730
|
const state = readJson(params.paths.claudeShimFile, ClaudeShimStateSchema);
|
|
32682
|
-
const targetPath = params.dir !== void 0 ?
|
|
32731
|
+
const targetPath = params.dir !== void 0 ? import_node_path13.default.join(params.dir, claudeTargetFilename(params.ownExecutablePath)) : state?.targetPath ?? resolveClaudeTargetPath(params.ownExecutablePath);
|
|
32683
32732
|
const existing = lstatOrUndefined(targetPath);
|
|
32684
32733
|
if (existing === void 0) {
|
|
32685
32734
|
if (state !== void 0) {
|
|
32686
|
-
|
|
32735
|
+
import_node_fs5.default.rmSync(params.paths.claudeShimFile, { force: true });
|
|
32687
32736
|
}
|
|
32688
32737
|
return { action: "not-enabled", targetPath };
|
|
32689
32738
|
}
|
|
32690
|
-
const ownStat =
|
|
32739
|
+
const ownStat = import_node_fs5.default.statSync(realContentPath);
|
|
32691
32740
|
const sameInode = existing.dev === ownStat.dev && existing.ino === ownStat.ino;
|
|
32692
|
-
const markerMatches = state !== void 0 &&
|
|
32741
|
+
const markerMatches = state !== void 0 && import_node_path13.default.resolve(state.targetPath) === targetPath;
|
|
32693
32742
|
if (!sameInode && !markerMatches && !params.force) {
|
|
32694
32743
|
throw new ForeignClaudeEntryError(targetPath, "disable");
|
|
32695
32744
|
}
|
|
32696
|
-
|
|
32697
|
-
|
|
32745
|
+
import_node_fs5.default.rmSync(targetPath, { recursive: true, force: true });
|
|
32746
|
+
import_node_fs5.default.rmSync(params.paths.claudeShimFile, { force: true });
|
|
32698
32747
|
return { action: "disabled", targetPath };
|
|
32699
32748
|
}
|
|
32700
32749
|
function findPathShadow(params) {
|
|
32701
|
-
const resolvedTargetDir =
|
|
32750
|
+
const resolvedTargetDir = import_node_path13.default.resolve(params.targetDir);
|
|
32702
32751
|
for (const dir of params.pathDirs) {
|
|
32703
32752
|
const found = params.findExecutableInDir(dir, params.targetFilename);
|
|
32704
32753
|
if (found === void 0) {
|
|
32705
32754
|
continue;
|
|
32706
32755
|
}
|
|
32707
|
-
return
|
|
32756
|
+
return import_node_path13.default.resolve(dir) === resolvedTargetDir ? { status: "ok" } : { status: "shadowed", by: found };
|
|
32708
32757
|
}
|
|
32709
|
-
return params.pathDirs.some((dir) =>
|
|
32758
|
+
return params.pathDirs.some((dir) => import_node_path13.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
|
|
32710
32759
|
}
|
|
32711
32760
|
function registerShimCommand(program2, deps) {
|
|
32712
32761
|
const { paths } = deps;
|
|
@@ -32724,21 +32773,21 @@ function registerShimCommand(program2, deps) {
|
|
|
32724
32773
|
ownExecutablePath,
|
|
32725
32774
|
contentSourcePath,
|
|
32726
32775
|
platform: process.platform,
|
|
32727
|
-
...options.dir === void 0 ? {} : { dir:
|
|
32776
|
+
...options.dir === void 0 ? {} : { dir: import_node_path13.default.resolve(options.dir) },
|
|
32728
32777
|
force: options.force ?? false
|
|
32729
32778
|
});
|
|
32730
32779
|
console.log(`${result.action === "enabled" ? "Installed" : "Reinstalled"} \`claude\` at ${result.targetPath} (${result.method}).`);
|
|
32731
32780
|
const shadow = findPathShadow({
|
|
32732
|
-
pathDirs: (process.env.PATH ?? "").split(
|
|
32733
|
-
targetDir:
|
|
32734
|
-
targetFilename:
|
|
32781
|
+
pathDirs: (process.env.PATH ?? "").split(import_node_path13.default.delimiter).filter((dir) => dir !== ""),
|
|
32782
|
+
targetDir: import_node_path13.default.dirname(result.targetPath),
|
|
32783
|
+
targetFilename: import_node_path13.default.basename(result.targetPath),
|
|
32735
32784
|
findExecutableInDir
|
|
32736
32785
|
});
|
|
32737
32786
|
if (shadow.status === "not-on-path") {
|
|
32738
|
-
console.warn(`warning: ${
|
|
32787
|
+
console.warn(`warning: ${import_node_path13.default.dirname(result.targetPath)} is not on PATH \u2014 add it, or use \`agent-shim run\` instead.`);
|
|
32739
32788
|
} else if (shadow.status === "shadowed") {
|
|
32740
32789
|
console.warn(
|
|
32741
|
-
`warning: 'claude' on PATH currently resolves to ${shadow.by}, not ${result.targetPath}. Put ${
|
|
32790
|
+
`warning: 'claude' on PATH currently resolves to ${shadow.by}, not ${result.targetPath}. Put ${import_node_path13.default.dirname(result.targetPath)} ahead of it on PATH.`
|
|
32742
32791
|
);
|
|
32743
32792
|
}
|
|
32744
32793
|
});
|
|
@@ -32750,7 +32799,7 @@ function registerShimCommand(program2, deps) {
|
|
|
32750
32799
|
paths,
|
|
32751
32800
|
ownExecutablePath,
|
|
32752
32801
|
contentSourcePath,
|
|
32753
|
-
...options.dir === void 0 ? {} : { dir:
|
|
32802
|
+
...options.dir === void 0 ? {} : { dir: import_node_path13.default.resolve(options.dir) },
|
|
32754
32803
|
force: options.force ?? false
|
|
32755
32804
|
});
|
|
32756
32805
|
console.log(
|
|
@@ -32759,12 +32808,12 @@ function registerShimCommand(program2, deps) {
|
|
|
32759
32808
|
});
|
|
32760
32809
|
withExamples(disable, ["agent-shim shim disable"]);
|
|
32761
32810
|
}
|
|
32762
|
-
var
|
|
32811
|
+
var import_node_fs5, import_node_path13, EXECUTABLE_FILE_MODE, ClaudeShimStateSchema, ForeignClaudeEntryError, UnsupportedShimSourceError, nodeLinkFs;
|
|
32763
32812
|
var init_claudeShim = __esm({
|
|
32764
32813
|
"src/claudeShim.ts"() {
|
|
32765
32814
|
"use strict";
|
|
32766
|
-
|
|
32767
|
-
|
|
32815
|
+
import_node_fs5 = __toESM(require("node:fs"), 1);
|
|
32816
|
+
import_node_path13 = __toESM(require("node:path"), 1);
|
|
32768
32817
|
init_zod();
|
|
32769
32818
|
init_commandDeps();
|
|
32770
32819
|
init_store();
|
|
@@ -32798,7 +32847,7 @@ var init_claudeShim = __esm({
|
|
|
32798
32847
|
}
|
|
32799
32848
|
contentSourcePath;
|
|
32800
32849
|
};
|
|
32801
|
-
nodeLinkFs = { link:
|
|
32850
|
+
nodeLinkFs = { link: import_node_fs5.default.linkSync, copyFile: import_node_fs5.default.copyFileSync, chmod: import_node_fs5.default.chmodSync };
|
|
32802
32851
|
}
|
|
32803
32852
|
});
|
|
32804
32853
|
|
|
@@ -33077,53 +33126,6 @@ var init_classify = __esm({
|
|
|
33077
33126
|
}
|
|
33078
33127
|
});
|
|
33079
33128
|
|
|
33080
|
-
// src/sameDirectory.ts
|
|
33081
|
-
function systemErrorCode(error63) {
|
|
33082
|
-
return typeof error63 === "object" && error63 !== null && "code" in error63 && typeof error63.code === "string" ? error63.code : void 0;
|
|
33083
|
-
}
|
|
33084
|
-
function reachableStat(target) {
|
|
33085
|
-
try {
|
|
33086
|
-
return import_node_fs5.default.statSync(target, { throwIfNoEntry: false });
|
|
33087
|
-
} catch (error63) {
|
|
33088
|
-
const code = systemErrorCode(error63);
|
|
33089
|
-
if (code !== void 0 && UNREACHABLE_CODES.has(code)) {
|
|
33090
|
-
return void 0;
|
|
33091
|
-
}
|
|
33092
|
-
throw error63;
|
|
33093
|
-
}
|
|
33094
|
-
}
|
|
33095
|
-
function sameDirectory(first, second) {
|
|
33096
|
-
const a10 = reachableStat(first);
|
|
33097
|
-
const b = reachableStat(second);
|
|
33098
|
-
if (a10 === void 0 || b === void 0) {
|
|
33099
|
-
return false;
|
|
33100
|
-
}
|
|
33101
|
-
return a10.dev === b.dev && a10.ino === b.ino;
|
|
33102
|
-
}
|
|
33103
|
-
function caseSwapped(name) {
|
|
33104
|
-
return name.replace(/[A-Za-z]/gu, (letter) => letter === letter.toLowerCase() ? letter.toUpperCase() : letter.toLowerCase());
|
|
33105
|
-
}
|
|
33106
|
-
function ignoresCase(directory) {
|
|
33107
|
-
if (!import_node_fs5.default.existsSync(directory)) {
|
|
33108
|
-
return false;
|
|
33109
|
-
}
|
|
33110
|
-
const probe = import_node_fs5.default.mkdtempSync(import_node_path13.default.join(directory, ".case-probe-"));
|
|
33111
|
-
try {
|
|
33112
|
-
return sameDirectory(probe, import_node_path13.default.join(directory, caseSwapped(import_node_path13.default.basename(probe))));
|
|
33113
|
-
} finally {
|
|
33114
|
-
import_node_fs5.default.rmSync(probe, { recursive: true, force: true });
|
|
33115
|
-
}
|
|
33116
|
-
}
|
|
33117
|
-
var import_node_fs5, import_node_path13, UNREACHABLE_CODES;
|
|
33118
|
-
var init_sameDirectory = __esm({
|
|
33119
|
-
"src/sameDirectory.ts"() {
|
|
33120
|
-
"use strict";
|
|
33121
|
-
import_node_fs5 = __toESM(require("node:fs"), 1);
|
|
33122
|
-
import_node_path13 = __toESM(require("node:path"), 1);
|
|
33123
|
-
UNREACHABLE_CODES = /* @__PURE__ */ new Set(["ELOOP", "EACCES", "ENOTDIR"]);
|
|
33124
|
-
}
|
|
33125
|
-
});
|
|
33126
|
-
|
|
33127
33129
|
// src/identityRecords.ts
|
|
33128
33130
|
function isSymlinkEntry(entry) {
|
|
33129
33131
|
return import_node_fs6.default.lstatSync(entry, { throwIfNoEntry: false })?.isSymbolicLink() ?? false;
|
|
@@ -33273,19 +33275,21 @@ function readActiveIdentity(fs36, activeIdentityFile) {
|
|
|
33273
33275
|
function isNonEmpty(value3) {
|
|
33274
33276
|
return value3 !== void 0 && value3 !== "";
|
|
33275
33277
|
}
|
|
33276
|
-
function selected(selector, source) {
|
|
33278
|
+
function selected(selector, source, supersededConfigDir) {
|
|
33277
33279
|
if (!IdentitySelectorSchema.safeParse(selector).success) {
|
|
33278
33280
|
throw new UnsafeNameError(selector, "identity", `${FILE_NAME_RULE}, or be pool:<name> for a pool`, IDENTITY_SOURCE_LABELS[source]);
|
|
33279
33281
|
}
|
|
33280
33282
|
const pool = poolNameOf(selector);
|
|
33281
|
-
|
|
33283
|
+
const superseded = supersededConfigDir === void 0 ? {} : { supersededConfigDir };
|
|
33284
|
+
return pool === void 0 ? { name: selector, source, configDirEscapeHatch: false, ...superseded } : { pool, source, configDirEscapeHatch: false, ...superseded };
|
|
33282
33285
|
}
|
|
33283
33286
|
function decideIdentity(params) {
|
|
33284
|
-
|
|
33285
|
-
return { source: "config-dir-escape-hatch", configDirEscapeHatch: true };
|
|
33286
|
-
}
|
|
33287
|
+
const inheritedConfigDir = isNonEmpty(params.env.CLAUDE_CONFIG_DIR) ? params.env.CLAUDE_CONFIG_DIR : void 0;
|
|
33287
33288
|
if (isNonEmpty(params.argv0Identity)) {
|
|
33288
|
-
return selected(params.argv0Identity, "argv");
|
|
33289
|
+
return selected(params.argv0Identity, "argv", inheritedConfigDir);
|
|
33290
|
+
}
|
|
33291
|
+
if (inheritedConfigDir !== void 0) {
|
|
33292
|
+
return { source: "config-dir-escape-hatch", configDirEscapeHatch: true };
|
|
33289
33293
|
}
|
|
33290
33294
|
if (isNonEmpty(params.env.AGENT_SHIM_IDENTITY)) {
|
|
33291
33295
|
return selected(params.env.AGENT_SHIM_IDENTITY, "env");
|
|
@@ -33364,7 +33368,7 @@ var init_identity = __esm({
|
|
|
33364
33368
|
init_identityRecords();
|
|
33365
33369
|
init_sameDirectory();
|
|
33366
33370
|
IDENTITY_DECISION_SOURCES = [
|
|
33367
|
-
/** `CLAUDE_CONFIG_DIR` was already set: identity resolution is skipped entirely and the real binary uses whatever it already points to. */
|
|
33371
|
+
/** `CLAUDE_CONFIG_DIR` was already set and nothing on the command line names an identity: identity resolution is skipped entirely and the real binary uses whatever it already points to. */
|
|
33368
33372
|
"config-dir-escape-hatch",
|
|
33369
33373
|
/** A leading `@name` argv[0] positional, or its explicit form `--identity <name>`. */
|
|
33370
33374
|
"argv",
|
|
@@ -41224,10 +41228,9 @@ function checkedProxyBypass(entries, source) {
|
|
|
41224
41228
|
}
|
|
41225
41229
|
return kept;
|
|
41226
41230
|
}
|
|
41227
|
-
function
|
|
41228
|
-
const
|
|
41229
|
-
|
|
41230
|
-
const added = hosts.filter((host) => {
|
|
41231
|
+
function appendedBypassHosts(existing, hosts) {
|
|
41232
|
+
const have = new Set((existing ?? "").split(",").map((entry) => entry.trim().toLowerCase()).filter((entry) => entry !== ""));
|
|
41233
|
+
return hosts.filter((host) => {
|
|
41231
41234
|
const key = host.toLowerCase();
|
|
41232
41235
|
if (have.has(key)) {
|
|
41233
41236
|
return false;
|
|
@@ -41235,7 +41238,10 @@ function withBypassHosts(existing, hosts) {
|
|
|
41235
41238
|
have.add(key);
|
|
41236
41239
|
return true;
|
|
41237
41240
|
});
|
|
41238
|
-
|
|
41241
|
+
}
|
|
41242
|
+
function withBypassHosts(existing, hosts) {
|
|
41243
|
+
const listed = (existing ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
41244
|
+
return [...listed, ...appendedBypassHosts(existing, hosts)].join(",");
|
|
41239
41245
|
}
|
|
41240
41246
|
var init_proxyBypass2 = __esm({
|
|
41241
41247
|
"src/launcher/proxyBypass.ts"() {
|
|
@@ -41980,7 +41986,7 @@ var init_package = __esm({
|
|
|
41980
41986
|
"package.json"() {
|
|
41981
41987
|
package_default = {
|
|
41982
41988
|
name: "claude-use",
|
|
41983
|
-
version: "11.
|
|
41989
|
+
version: "11.88.1",
|
|
41984
41990
|
description: "A profile manager and launcher for Claude Code that lets one person run multiple logins from one machine while controlling what gets shared between them.",
|
|
41985
41991
|
license: "MIT",
|
|
41986
41992
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -42153,6 +42159,156 @@ var init_claudeVersion = __esm({
|
|
|
42153
42159
|
}
|
|
42154
42160
|
});
|
|
42155
42161
|
|
|
42162
|
+
// src/headroom/headers.ts
|
|
42163
|
+
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
42164
|
+
const merged = /* @__PURE__ */ new Map();
|
|
42165
|
+
for (const block2 of existing) {
|
|
42166
|
+
if (block2 === void 0) {
|
|
42167
|
+
continue;
|
|
42168
|
+
}
|
|
42169
|
+
for (const line of block2.split("\n")) {
|
|
42170
|
+
const entry = parseCustomHeaderLine(line);
|
|
42171
|
+
if (entry === void 0) {
|
|
42172
|
+
continue;
|
|
42173
|
+
}
|
|
42174
|
+
merged.set(entry.name, entry.value);
|
|
42175
|
+
}
|
|
42176
|
+
}
|
|
42177
|
+
for (const entry of additions) {
|
|
42178
|
+
merged.set(entry.name, entry.value);
|
|
42179
|
+
}
|
|
42180
|
+
return [...merged].map(([name, value3]) => `${name}: ${value3}`).join("\n");
|
|
42181
|
+
}
|
|
42182
|
+
function parseAnthropicCustomHeaders(block2) {
|
|
42183
|
+
return block2.split("\n").flatMap((line) => {
|
|
42184
|
+
const entry = parseCustomHeaderLine(line);
|
|
42185
|
+
return entry === void 0 ? [] : [entry];
|
|
42186
|
+
});
|
|
42187
|
+
}
|
|
42188
|
+
function withoutAnthropicCustomHeaders(block2, remove) {
|
|
42189
|
+
const lines = block2.split("\n");
|
|
42190
|
+
const kept = lines.filter((line) => {
|
|
42191
|
+
const entry = parseCustomHeaderLine(line);
|
|
42192
|
+
return entry === void 0 || !remove(entry);
|
|
42193
|
+
});
|
|
42194
|
+
return kept.length === lines.length ? block2 : kept.join("\n");
|
|
42195
|
+
}
|
|
42196
|
+
function parseCustomHeaderLine(line) {
|
|
42197
|
+
const trimmed = line.trim();
|
|
42198
|
+
if (trimmed === "") {
|
|
42199
|
+
return void 0;
|
|
42200
|
+
}
|
|
42201
|
+
const colon = trimmed.indexOf(":");
|
|
42202
|
+
if (colon <= 0) {
|
|
42203
|
+
return void 0;
|
|
42204
|
+
}
|
|
42205
|
+
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
42206
|
+
}
|
|
42207
|
+
var init_headers = __esm({
|
|
42208
|
+
"src/headroom/headers.ts"() {
|
|
42209
|
+
"use strict";
|
|
42210
|
+
}
|
|
42211
|
+
});
|
|
42212
|
+
|
|
42213
|
+
// src/launcher/injected.ts
|
|
42214
|
+
function listKey(list2) {
|
|
42215
|
+
return `${list2},appended`;
|
|
42216
|
+
}
|
|
42217
|
+
function digest2(value3) {
|
|
42218
|
+
return (0, import_node_crypto13.createHash)("sha256").update(value3).digest("hex");
|
|
42219
|
+
}
|
|
42220
|
+
function recordedDigests(env) {
|
|
42221
|
+
const raw = env[INJECTED_ENV];
|
|
42222
|
+
if (raw === void 0 || raw === "") {
|
|
42223
|
+
return {};
|
|
42224
|
+
}
|
|
42225
|
+
let parsed;
|
|
42226
|
+
try {
|
|
42227
|
+
parsed = JSON.parse(raw);
|
|
42228
|
+
} catch {
|
|
42229
|
+
return {};
|
|
42230
|
+
}
|
|
42231
|
+
const result = InjectedSchema.safeParse(parsed);
|
|
42232
|
+
return result.success ? result.data : {};
|
|
42233
|
+
}
|
|
42234
|
+
function recordInjections(base) {
|
|
42235
|
+
const env = { ...base };
|
|
42236
|
+
const digests = new Map(Object.entries(recordedDigests(env)));
|
|
42237
|
+
return {
|
|
42238
|
+
env,
|
|
42239
|
+
set: (name, value3) => {
|
|
42240
|
+
env[name] = value3;
|
|
42241
|
+
digests.set(name, digest2(value3));
|
|
42242
|
+
},
|
|
42243
|
+
unset: (name) => {
|
|
42244
|
+
env[name] = void 0;
|
|
42245
|
+
digests.delete(name);
|
|
42246
|
+
},
|
|
42247
|
+
recordHeaders: (names) => {
|
|
42248
|
+
const block2 = env[CUSTOM_HEADERS_ENV];
|
|
42249
|
+
for (const entry of block2 === void 0 ? [] : parseAnthropicCustomHeaders(block2)) {
|
|
42250
|
+
if (names.includes(entry.name)) {
|
|
42251
|
+
digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
|
|
42252
|
+
}
|
|
42253
|
+
}
|
|
42254
|
+
},
|
|
42255
|
+
recordBypassHosts: (list2, hosts) => {
|
|
42256
|
+
const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list2))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
|
|
42257
|
+
if (recordedHosts.length > 0) {
|
|
42258
|
+
digests.set(listKey(list2), recordedHosts.join(","));
|
|
42259
|
+
}
|
|
42260
|
+
},
|
|
42261
|
+
finish: () => {
|
|
42262
|
+
if (digests.size > 0) {
|
|
42263
|
+
env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
|
|
42264
|
+
}
|
|
42265
|
+
}
|
|
42266
|
+
};
|
|
42267
|
+
}
|
|
42268
|
+
function withoutRecordedHosts(list2, value3, digests) {
|
|
42269
|
+
const recordedHosts = new Set(digests[listKey(list2)]?.split(","));
|
|
42270
|
+
const entries = value3.split(",");
|
|
42271
|
+
const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
|
|
42272
|
+
return kept.length === entries.length ? value3 : kept.join(",");
|
|
42273
|
+
}
|
|
42274
|
+
function launchEnvironment(env, configDirEscapeHatch) {
|
|
42275
|
+
return configDirEscapeHatch ? env : withoutInjected(env);
|
|
42276
|
+
}
|
|
42277
|
+
function withoutInjected(env) {
|
|
42278
|
+
const digests = recordedDigests(env);
|
|
42279
|
+
const entries = Object.entries(env).flatMap(([name, value3]) => {
|
|
42280
|
+
if (name === INJECTED_ENV) {
|
|
42281
|
+
return [];
|
|
42282
|
+
}
|
|
42283
|
+
if (value3 === void 0) {
|
|
42284
|
+
return [[name, value3]];
|
|
42285
|
+
}
|
|
42286
|
+
if (name === CUSTOM_HEADERS_ENV) {
|
|
42287
|
+
const remaining = withoutAnthropicCustomHeaders(value3, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
|
|
42288
|
+
return remaining !== value3 && remaining.trim() === "" ? [] : [[name, remaining]];
|
|
42289
|
+
}
|
|
42290
|
+
if (name === "NO_PROXY" || name === "no_proxy") {
|
|
42291
|
+
const remaining = withoutRecordedHosts(name, value3, digests);
|
|
42292
|
+
return remaining !== value3 && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
|
|
42293
|
+
}
|
|
42294
|
+
return digests[name] === digest2(value3) ? [] : [[name, value3]];
|
|
42295
|
+
});
|
|
42296
|
+
return Object.fromEntries(entries);
|
|
42297
|
+
}
|
|
42298
|
+
var import_node_crypto13, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
|
|
42299
|
+
var init_injected = __esm({
|
|
42300
|
+
"src/launcher/injected.ts"() {
|
|
42301
|
+
"use strict";
|
|
42302
|
+
import_node_crypto13 = require("node:crypto");
|
|
42303
|
+
init_zod();
|
|
42304
|
+
init_headers();
|
|
42305
|
+
INJECTED_ENV = "AGENT_SHIM_INJECTED";
|
|
42306
|
+
CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
|
|
42307
|
+
HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
|
|
42308
|
+
InjectedSchema = external_exports.record(external_exports.string(), external_exports.string());
|
|
42309
|
+
}
|
|
42310
|
+
});
|
|
42311
|
+
|
|
42156
42312
|
// src/launcher/guard.ts
|
|
42157
42313
|
function detectAmbientCredential(env, injected) {
|
|
42158
42314
|
for (const variable of AMBIENT_CREDENTIAL_VARS) {
|
|
@@ -42191,10 +42347,22 @@ function evaluateAmbientCredentialGuard(params) {
|
|
|
42191
42347
|
message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
|
|
42192
42348
|
};
|
|
42193
42349
|
}
|
|
42350
|
+
function ambientCredentialFinding(env) {
|
|
42351
|
+
const named = detectAmbientCredential(launchEnvironment(env, false));
|
|
42352
|
+
if (named !== void 0) {
|
|
42353
|
+
return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
|
|
42354
|
+
}
|
|
42355
|
+
const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
|
|
42356
|
+
if (bare !== void 0) {
|
|
42357
|
+
return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
|
|
42358
|
+
}
|
|
42359
|
+
return { severity: "pass", message: "No ambient-credential environment variable is set." };
|
|
42360
|
+
}
|
|
42194
42361
|
var AMBIENT_CREDENTIAL_VARS;
|
|
42195
42362
|
var init_guard = __esm({
|
|
42196
42363
|
"src/launcher/guard.ts"() {
|
|
42197
42364
|
"use strict";
|
|
42365
|
+
init_injected();
|
|
42198
42366
|
AMBIENT_CREDENTIAL_VARS = [
|
|
42199
42367
|
"ANTHROPIC_API_KEY",
|
|
42200
42368
|
"ANTHROPIC_AUTH_TOKEN",
|
|
@@ -66029,8 +66197,8 @@ var require_connection = __commonJS({
|
|
|
66029
66197
|
return;
|
|
66030
66198
|
}
|
|
66031
66199
|
const secWSAccept = response.headersList.get("Sec-WebSocket-Accept");
|
|
66032
|
-
const
|
|
66033
|
-
if (secWSAccept !==
|
|
66200
|
+
const digest3 = crypto.hash("sha1", keyValue + uid, "base64");
|
|
66201
|
+
if (secWSAccept !== digest3) {
|
|
66034
66202
|
failHandshake(handler, response, 1002, "Incorrect hash received in Sec-WebSocket-Accept header.");
|
|
66035
66203
|
return;
|
|
66036
66204
|
}
|
|
@@ -68609,7 +68777,7 @@ function base64Url(bytes) {
|
|
|
68609
68777
|
}
|
|
68610
68778
|
function newPkce(randomBytes5) {
|
|
68611
68779
|
const verifier = base64Url(randomBytes5(SIWC_RANDOM_BYTES));
|
|
68612
|
-
return { verifier, challenge: (0,
|
|
68780
|
+
return { verifier, challenge: (0, import_node_crypto14.createHash)("sha256").update(verifier).digest("base64url") };
|
|
68613
68781
|
}
|
|
68614
68782
|
function newOpaqueValue(randomBytes5) {
|
|
68615
68783
|
return base64Url(randomBytes5(SIWC_RANDOM_BYTES));
|
|
@@ -68718,7 +68886,7 @@ async function verifyIdToken(ports, idToken, expected) {
|
|
|
68718
68886
|
throw new SiwcError("the issuer's key set has no key for the ID token's signature");
|
|
68719
68887
|
}
|
|
68720
68888
|
const signed = Buffer.from(`${headerSegment}.${payloadSegment}`);
|
|
68721
|
-
if (!(0,
|
|
68889
|
+
if (!(0, import_node_crypto14.verify)("sha256", signed, (0, import_node_crypto14.createPublicKey)({ key: jwk, format: "jwk" }), Buffer.from(signatureSegment, "base64url"))) {
|
|
68722
68890
|
throw new SiwcError("the ID token's signature did not verify");
|
|
68723
68891
|
}
|
|
68724
68892
|
const claims = IdTokenClaimsSchema.parse(decodeSegment(payloadSegment));
|
|
@@ -68736,11 +68904,11 @@ async function verifyIdToken(ports, idToken, expected) {
|
|
|
68736
68904
|
}
|
|
68737
68905
|
return { sub: claims.sub, email: claims.email };
|
|
68738
68906
|
}
|
|
68739
|
-
var
|
|
68907
|
+
var import_node_crypto14, SIWC_AUTHORIZE_URL, SIWC_TOKEN_URL, SIWC_REVOKE_URL, SIWC_ISSUER, SIWC_JWKS_URL, SIWC_DYNAMIC_CLIENT_ID, SIWC_RESOURCE, SIWC_RESPONSES_URL, SIWC_SCOPES, SIWC_PLAN_SCOPE, SIWC_CALLBACK_PORT, SIWC_CALLBACK_PATH, SIWC_RANDOM_BYTES, MS_PER_SECOND7, ID_TOKEN_ALGORITHM, SiwcError, SiwcInvalidGrantError, TokenResponseSchema, ERROR_BODY_CHARS, TOKEN_CALL_TIMEOUT_MS, JwtHeaderSchema, IdTokenClaimsSchema, JwksSchema;
|
|
68740
68908
|
var init_siwc = __esm({
|
|
68741
68909
|
"src/codex/siwc.ts"() {
|
|
68742
68910
|
"use strict";
|
|
68743
|
-
|
|
68911
|
+
import_node_crypto14 = require("node:crypto");
|
|
68744
68912
|
init_zod();
|
|
68745
68913
|
SIWC_AUTHORIZE_URL = "https://auth.openai.com/api/accounts/authorize";
|
|
68746
68914
|
SIWC_TOKEN_URL = "https://auth.openai.com/api/accounts/oauth/token";
|
|
@@ -68910,7 +69078,7 @@ function parseCatalogueBinding(raw) {
|
|
|
68910
69078
|
}
|
|
68911
69079
|
}
|
|
68912
69080
|
function catalogueCredentialFingerprint(cli, token, accountId) {
|
|
68913
|
-
return (0,
|
|
69081
|
+
return (0, import_node_crypto18.createHash)("sha256").update(JSON.stringify([cli, token, accountId])).digest("hex");
|
|
68914
69082
|
}
|
|
68915
69083
|
function cliCatalogueFingerprint(raw) {
|
|
68916
69084
|
if (raw === void 0) return void 0;
|
|
@@ -68935,11 +69103,11 @@ function savedCatalogueFingerprint(provider, paths, env, home, read) {
|
|
|
68935
69103
|
const codexHome2 = configuredHome === void 0 || configuredHome === "" ? import_node_path48.default.join(home, ".codex") : configuredHome;
|
|
68936
69104
|
return cliCatalogueFingerprint(read(import_node_path48.default.join(codexHome2, "auth.json")));
|
|
68937
69105
|
}
|
|
68938
|
-
var
|
|
69106
|
+
var import_node_crypto18, import_node_path48, CatalogueBindingSchema;
|
|
68939
69107
|
var init_catalogueCredential = __esm({
|
|
68940
69108
|
"src/codex/catalogueCredential.ts"() {
|
|
68941
69109
|
"use strict";
|
|
68942
|
-
|
|
69110
|
+
import_node_crypto18 = require("node:crypto");
|
|
68943
69111
|
import_node_path48 = __toESM(require("node:path"), 1);
|
|
68944
69112
|
init_zod();
|
|
68945
69113
|
init_siwcStore();
|
|
@@ -69117,7 +69285,7 @@ function ensureFrontDoor(params) {
|
|
|
69117
69285
|
if (supervisorPid !== void 0 && !distrusted.has(supervisorPid) && ports.isRunning(supervisorPid)) {
|
|
69118
69286
|
if (state?.port !== void 0 && state.connectPort !== void 0) {
|
|
69119
69287
|
if (supervisorPid === params.launcherPid && params.replace === void 0 && ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
69120
|
-
const token = (0,
|
|
69288
|
+
const token = (0, import_node_crypto19.randomUUID)();
|
|
69121
69289
|
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
69122
69290
|
return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
|
|
69123
69291
|
}
|
|
@@ -69138,7 +69306,7 @@ function ensureFrontDoor(params) {
|
|
|
69138
69306
|
continue;
|
|
69139
69307
|
}
|
|
69140
69308
|
if (verdict.ok) {
|
|
69141
|
-
const token = (0,
|
|
69309
|
+
const token = (0, import_node_crypto19.randomUUID)();
|
|
69142
69310
|
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
69143
69311
|
return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
|
|
69144
69312
|
}
|
|
@@ -69208,11 +69376,11 @@ function restartFrontDoor(params) {
|
|
|
69208
69376
|
}
|
|
69209
69377
|
return { action: "restarted", previousPid, pid };
|
|
69210
69378
|
}
|
|
69211
|
-
var
|
|
69379
|
+
var import_node_crypto19, FRONTDOOR_START_TIMEOUT_MS, FRONTDOOR_LAUNCHER_POLL_MS, FRONTDOOR_PROBE_ATTEMPTS, FRONTDOOR_EXIT_GRACE_MS, FrontDoorStartError;
|
|
69212
69380
|
var init_ensure2 = __esm({
|
|
69213
69381
|
"src/frontdoor/ensure.ts"() {
|
|
69214
69382
|
"use strict";
|
|
69215
|
-
|
|
69383
|
+
import_node_crypto19 = require("node:crypto");
|
|
69216
69384
|
init_cliError();
|
|
69217
69385
|
init_state2();
|
|
69218
69386
|
init_replacement();
|
|
@@ -69397,18 +69565,18 @@ function resolveTrustBundle(params) {
|
|
|
69397
69565
|
}
|
|
69398
69566
|
const combined = `${inheritedPem.trimEnd()}
|
|
69399
69567
|
${caPem}`;
|
|
69400
|
-
const bundle = import_node_path52.default.join(bundlesDir, `${(0,
|
|
69568
|
+
const bundle = import_node_path52.default.join(bundlesDir, `${(0, import_node_crypto20.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
69401
69569
|
if (!fs36.exists(bundle)) {
|
|
69402
69570
|
fs36.mkdirp(bundlesDir);
|
|
69403
69571
|
fs36.writeFileAtomic(bundle, combined);
|
|
69404
69572
|
}
|
|
69405
69573
|
return { path: bundle };
|
|
69406
69574
|
}
|
|
69407
|
-
var
|
|
69575
|
+
var import_node_crypto20, import_node_path52, BUNDLE_NAME_HEX_DIGITS;
|
|
69408
69576
|
var init_trust = __esm({
|
|
69409
69577
|
"src/frontdoor/trust.ts"() {
|
|
69410
69578
|
"use strict";
|
|
69411
|
-
|
|
69579
|
+
import_node_crypto20 = require("node:crypto");
|
|
69412
69580
|
import_node_path52 = __toESM(require("node:path"), 1);
|
|
69413
69581
|
BUNDLE_NAME_HEX_DIGITS = 16;
|
|
69414
69582
|
}
|
|
@@ -69681,11 +69849,11 @@ async function downloadAndInstall(ports, asset, target) {
|
|
|
69681
69849
|
throw new UpdateDownloadError(`the downloaded files for ${asset} are missing from ${tempDir}`);
|
|
69682
69850
|
}
|
|
69683
69851
|
const expected = expectedSha256(sidecar);
|
|
69684
|
-
const actual = (0,
|
|
69852
|
+
const actual = (0, import_node_crypto21.createHash)("sha256").update(downloaded).digest("hex");
|
|
69685
69853
|
if (expected === void 0 || expected !== actual) {
|
|
69686
69854
|
throw new UpdateDownloadError(`checksum mismatch for ${asset} (expected ${expected ?? "(none)"}, got ${actual})`);
|
|
69687
69855
|
}
|
|
69688
|
-
const tempBinary = import_node_path53.default.join(import_node_path53.default.dirname(target), `.${import_node_path53.default.basename(target)}.${String(process.pid)}.${(0,
|
|
69856
|
+
const tempBinary = import_node_path53.default.join(import_node_path53.default.dirname(target), `.${import_node_path53.default.basename(target)}.${String(process.pid)}.${(0, import_node_crypto21.randomUUID)()}.tmp`);
|
|
69689
69857
|
ports.fs.writeFileBytes(tempBinary, downloaded);
|
|
69690
69858
|
try {
|
|
69691
69859
|
ports.fs.chmod(tempBinary, EXECUTABLE_MODE);
|
|
@@ -69732,11 +69900,11 @@ async function runSelfUpdate(ports, options) {
|
|
|
69732
69900
|
}
|
|
69733
69901
|
return { current: options.currentVersion, latest, action: "updated" };
|
|
69734
69902
|
}
|
|
69735
|
-
var
|
|
69903
|
+
var import_node_crypto21, import_node_path53, LATEST_RELEASE_URL, DOWNLOAD_BASE_URL, MACOS_X64_NOTE, BREW_PREFIXES, EXECUTABLE_MODE, UpdateChannelError, UpdateConflictError, UpdateDownloadError;
|
|
69736
69904
|
var init_update = __esm({
|
|
69737
69905
|
"src/update/update.ts"() {
|
|
69738
69906
|
"use strict";
|
|
69739
|
-
|
|
69907
|
+
import_node_crypto21 = require("node:crypto");
|
|
69740
69908
|
import_node_path53 = __toESM(require("node:path"), 1);
|
|
69741
69909
|
init_cliError();
|
|
69742
69910
|
LATEST_RELEASE_URL = "https://github.com/ExaDev/agent-shim/releases/latest";
|
|
@@ -70177,43 +70345,6 @@ var init_cliOverride = __esm({
|
|
|
70177
70345
|
}
|
|
70178
70346
|
});
|
|
70179
70347
|
|
|
70180
|
-
// src/headroom/headers.ts
|
|
70181
|
-
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
70182
|
-
const merged = /* @__PURE__ */ new Map();
|
|
70183
|
-
for (const block2 of existing) {
|
|
70184
|
-
if (block2 === void 0) {
|
|
70185
|
-
continue;
|
|
70186
|
-
}
|
|
70187
|
-
for (const line of block2.split("\n")) {
|
|
70188
|
-
const entry = parseCustomHeaderLine(line);
|
|
70189
|
-
if (entry === void 0) {
|
|
70190
|
-
continue;
|
|
70191
|
-
}
|
|
70192
|
-
merged.set(entry.name, entry.value);
|
|
70193
|
-
}
|
|
70194
|
-
}
|
|
70195
|
-
for (const entry of additions) {
|
|
70196
|
-
merged.set(entry.name, entry.value);
|
|
70197
|
-
}
|
|
70198
|
-
return [...merged].map(([name, value3]) => `${name}: ${value3}`).join("\n");
|
|
70199
|
-
}
|
|
70200
|
-
function parseCustomHeaderLine(line) {
|
|
70201
|
-
const trimmed = line.trim();
|
|
70202
|
-
if (trimmed === "") {
|
|
70203
|
-
return void 0;
|
|
70204
|
-
}
|
|
70205
|
-
const colon = trimmed.indexOf(":");
|
|
70206
|
-
if (colon <= 0) {
|
|
70207
|
-
return void 0;
|
|
70208
|
-
}
|
|
70209
|
-
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
70210
|
-
}
|
|
70211
|
-
var init_headers = __esm({
|
|
70212
|
-
"src/headroom/headers.ts"() {
|
|
70213
|
-
"use strict";
|
|
70214
|
-
}
|
|
70215
|
-
});
|
|
70216
|
-
|
|
70217
70348
|
// src/statusline/settings.ts
|
|
70218
70349
|
function checkedStatusline(settings2, source) {
|
|
70219
70350
|
try {
|
|
@@ -70296,7 +70427,10 @@ function buildArgv(params) {
|
|
|
70296
70427
|
return [...params.toolFlags, ...params.extraFlags, ...params.passthrough];
|
|
70297
70428
|
}
|
|
70298
70429
|
function buildEnv(params) {
|
|
70299
|
-
const
|
|
70430
|
+
const injections = recordInjections(params.baseEnv);
|
|
70431
|
+
const { env } = injections;
|
|
70432
|
+
const inject = injections.set;
|
|
70433
|
+
const injectedHeaderNames = [];
|
|
70300
70434
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
70301
70435
|
let providerCustomHeaders;
|
|
70302
70436
|
if (!params.configDirEscapeHatch && params.identityId !== void 0) {
|
|
@@ -70305,53 +70439,75 @@ function buildEnv(params) {
|
|
|
70305
70439
|
if (params.provider !== void 0) {
|
|
70306
70440
|
const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
|
|
70307
70441
|
providerCustomHeaders = providerEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
70308
|
-
|
|
70309
|
-
|
|
70442
|
+
injections.unset("ANTHROPIC_BASE_URL");
|
|
70443
|
+
inject("AGENT_SHIM_PROVIDER", params.provider.definition.displayName);
|
|
70310
70444
|
for (const [key, value3] of Object.entries(providerEnv)) {
|
|
70311
|
-
|
|
70445
|
+
if (key === CUSTOM_HEADERS_ENV) {
|
|
70446
|
+
env[key] = value3;
|
|
70447
|
+
injectedHeaderNames.push(...parseAnthropicCustomHeaders(value3).map(({ name }) => name));
|
|
70448
|
+
} else if (key === "NO_PROXY" || key === "no_proxy") {
|
|
70449
|
+
env[key] = value3;
|
|
70450
|
+
injections.recordBypassHosts(key, value3.split(","));
|
|
70451
|
+
} else {
|
|
70452
|
+
inject(key, value3);
|
|
70453
|
+
}
|
|
70312
70454
|
}
|
|
70313
70455
|
}
|
|
70314
70456
|
for (const tier of CLAUDE_TIERS) {
|
|
70315
70457
|
const ref = params.tierModels?.[tier];
|
|
70316
70458
|
if (ref !== void 0) {
|
|
70317
|
-
|
|
70459
|
+
inject(`ANTHROPIC_DEFAULT_${tier.toUpperCase()}_MODEL`, ref);
|
|
70318
70460
|
}
|
|
70319
70461
|
}
|
|
70320
70462
|
if (params.provider !== void 0) {
|
|
70321
|
-
|
|
70322
|
-
|
|
70323
|
-
|
|
70463
|
+
if (params.remoteControl) {
|
|
70464
|
+
injections.unset("ANTHROPIC_AUTH_TOKEN");
|
|
70465
|
+
} else {
|
|
70466
|
+
inject("ANTHROPIC_AUTH_TOKEN", PROVIDER_SESSION_PLACEHOLDER);
|
|
70467
|
+
}
|
|
70468
|
+
injections.unset("ANTHROPIC_API_KEY");
|
|
70469
|
+
injections.unset("CLAUDE_CODE_OAUTH_TOKEN");
|
|
70324
70470
|
} else if (params.identityCredential !== void 0) {
|
|
70325
70471
|
for (const [variable, value3] of Object.entries(credentialVariables(params.identityCredential.target, params.identityCredential.token))) {
|
|
70326
|
-
|
|
70472
|
+
if (value3 === void 0) {
|
|
70473
|
+
injections.unset(variable);
|
|
70474
|
+
} else {
|
|
70475
|
+
inject(variable, value3);
|
|
70476
|
+
}
|
|
70327
70477
|
}
|
|
70328
70478
|
}
|
|
70329
70479
|
if (params.frontdoor !== void 0) {
|
|
70480
|
+
const launcherHeaders = [
|
|
70481
|
+
...params.identityId === void 0 ? [] : [{ name: IDENTITY_HEADER, value: params.identityId }],
|
|
70482
|
+
{ name: SESSION_HEADER, value: params.sessionId },
|
|
70483
|
+
{ name: AUTH_HEADER, value: params.frontdoor.sessionToken },
|
|
70484
|
+
...params.provider === void 0 ? [] : [{ name: PROVIDER_HEADER, value: params.provider.name }],
|
|
70485
|
+
...params.headroom === void 0 ? [] : [
|
|
70486
|
+
{ name: HEADROOM_FLAG_HEADER, value: "1" },
|
|
70487
|
+
{ name: PROJECT_ID_HEADER, value: params.headroom.projectId }
|
|
70488
|
+
]
|
|
70489
|
+
];
|
|
70490
|
+
injectedHeaderNames.push(...launcherHeaders.map(({ name }) => name));
|
|
70330
70491
|
env.ANTHROPIC_CUSTOM_HEADERS = mergeAnthropicCustomHeaders(
|
|
70331
70492
|
[
|
|
70332
70493
|
...parentCustomHeaders === void 0 ? [] : [parentCustomHeaders],
|
|
70333
70494
|
...providerCustomHeaders === void 0 ? [] : [providerCustomHeaders]
|
|
70334
70495
|
],
|
|
70335
|
-
|
|
70336
|
-
...params.identityId === void 0 ? [] : [{ name: IDENTITY_HEADER, value: params.identityId }],
|
|
70337
|
-
{ name: SESSION_HEADER, value: params.sessionId },
|
|
70338
|
-
{ name: AUTH_HEADER, value: params.frontdoor.sessionToken },
|
|
70339
|
-
...params.provider === void 0 ? [] : [{ name: PROVIDER_HEADER, value: params.provider.name }],
|
|
70340
|
-
...params.headroom === void 0 ? [] : [
|
|
70341
|
-
{ name: HEADROOM_FLAG_HEADER, value: "1" },
|
|
70342
|
-
{ name: PROJECT_ID_HEADER, value: params.headroom.projectId }
|
|
70343
|
-
]
|
|
70344
|
-
]
|
|
70496
|
+
launcherHeaders
|
|
70345
70497
|
);
|
|
70346
|
-
|
|
70347
|
-
|
|
70498
|
+
inject("NODE_EXTRA_CA_CERTS", params.frontdoor.trustBundlePath);
|
|
70499
|
+
inject("HTTPS_PROXY", connectProxyUrl(params.frontdoor.connectPort, params.frontdoor.sessionToken));
|
|
70348
70500
|
const bypassed = [...LOOPBACK_HOSTS, ...params.proxyBypass ?? []];
|
|
70349
|
-
|
|
70350
|
-
|
|
70501
|
+
for (const list2 of ["NO_PROXY", "no_proxy"]) {
|
|
70502
|
+
injections.recordBypassHosts(list2, appendedBypassHosts(env[list2], bypassed));
|
|
70503
|
+
env[list2] = withBypassHosts(env[list2], bypassed);
|
|
70504
|
+
}
|
|
70351
70505
|
}
|
|
70352
70506
|
if (params.statusline !== void 0) {
|
|
70353
|
-
|
|
70507
|
+
inject(STATUSLINE_ENV, JSON.stringify(params.statusline));
|
|
70354
70508
|
}
|
|
70509
|
+
injections.recordHeaders(injectedHeaderNames);
|
|
70510
|
+
injections.finish();
|
|
70355
70511
|
return env;
|
|
70356
70512
|
}
|
|
70357
70513
|
var import_node_path56, LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
|
|
@@ -70365,6 +70521,7 @@ var init_flags = __esm({
|
|
|
70365
70521
|
init_schema();
|
|
70366
70522
|
init_credential();
|
|
70367
70523
|
init_headers();
|
|
70524
|
+
init_injected();
|
|
70368
70525
|
init_capability();
|
|
70369
70526
|
init_route();
|
|
70370
70527
|
init_statusline();
|
|
@@ -71309,7 +71466,7 @@ function buildCloudRequestBody(params) {
|
|
|
71309
71466
|
if (isCcpaEndpoint(base)) {
|
|
71310
71467
|
return JSON.stringify({
|
|
71311
71468
|
project: params.config.cloud.projectId ?? CCPA_DEFAULT_PROJECT_ID,
|
|
71312
|
-
requestId: `agent/${(0,
|
|
71469
|
+
requestId: `agent/${(0, import_node_crypto22.randomUUID)()}/${String(Date.now())}/1`,
|
|
71313
71470
|
request: params.request,
|
|
71314
71471
|
model: params.model,
|
|
71315
71472
|
userAgent: "antigravity"
|
|
@@ -71377,11 +71534,11 @@ function* chunksOfLine(line) {
|
|
|
71377
71534
|
}
|
|
71378
71535
|
}
|
|
71379
71536
|
}
|
|
71380
|
-
var
|
|
71537
|
+
var import_node_crypto22, CCPA_ENDPOINT, CCPA_DEFAULT_PROJECT_ID, CCPA_USER_AGENT, AntigravityUpstreamError, SSE_DATA_PREFIX;
|
|
71381
71538
|
var init_cloudUpstream = __esm({
|
|
71382
71539
|
"src/antigravity/cloudUpstream.ts"() {
|
|
71383
71540
|
"use strict";
|
|
71384
|
-
|
|
71541
|
+
import_node_crypto22 = require("node:crypto");
|
|
71385
71542
|
CCPA_ENDPOINT = "https://daily-cloudcode-pa.googleapis.com";
|
|
71386
71543
|
CCPA_DEFAULT_PROJECT_ID = "aicode-consumers";
|
|
71387
71544
|
CCPA_USER_AGENT = "antigravity/cli/1.3.5 (aidev_client; os_type=darwin; arch=arm64; cl=998863838; auth_method=consumer)";
|
|
@@ -71921,7 +72078,7 @@ function shortToolName(name, names) {
|
|
|
71921
72078
|
if (sanitized.length <= ANTIGRAVITY_TOOL_NAME_LIMIT) {
|
|
71922
72079
|
result = sanitized;
|
|
71923
72080
|
} else {
|
|
71924
|
-
const hash2 = (0,
|
|
72081
|
+
const hash2 = (0, import_node_crypto23.createHash)("sha256").update(name).digest("hex").slice(0, TOOL_NAME_HASH_CHARS);
|
|
71925
72082
|
const prefix = sanitized.slice(0, ANTIGRAVITY_TOOL_NAME_LIMIT - TOOL_NAME_HASH_CHARS - 1);
|
|
71926
72083
|
result = `${prefix}_${hash2}`;
|
|
71927
72084
|
}
|
|
@@ -72090,11 +72247,11 @@ function translateRequest(request7, config2, routing) {
|
|
|
72090
72247
|
toolNames
|
|
72091
72248
|
};
|
|
72092
72249
|
}
|
|
72093
|
-
var
|
|
72250
|
+
var import_node_crypto23, SECONDS_PER_HOUR3, NEUTRAL_PRESSURE, AUTO_ALIAS, BACKEND_FAMILY_PREFIXES, BACKEND_CLAUDE_NAME, EFFORT_TO_BUDGET, BILLING_HEADER_LINE, ANTIGRAVITY_TOOL_NAME_LIMIT, TOOL_NAME_HASH_CHARS, NON_TEXT_TOOL_RESULT, EMPTY_SCHEMA, EFFORT_SUFFIXES;
|
|
72094
72251
|
var init_translate = __esm({
|
|
72095
72252
|
"src/antigravity/translate.ts"() {
|
|
72096
72253
|
"use strict";
|
|
72097
|
-
|
|
72254
|
+
import_node_crypto23 = require("node:crypto");
|
|
72098
72255
|
init_identity2();
|
|
72099
72256
|
init_engine();
|
|
72100
72257
|
init_quota();
|
|
@@ -72164,7 +72321,7 @@ function shortToolName2(name, names) {
|
|
|
72164
72321
|
if (name.length <= CODEX_TOOL_NAME_LIMIT) {
|
|
72165
72322
|
return name;
|
|
72166
72323
|
}
|
|
72167
|
-
const hash2 = (0,
|
|
72324
|
+
const hash2 = (0, import_node_crypto24.createHash)("sha256").update(name).digest("hex").slice(0, TOOL_NAME_HASH_CHARS2);
|
|
72168
72325
|
const shortened = `${name.slice(0, CODEX_TOOL_NAME_LIMIT - TOOL_NAME_HASH_CHARS2 - 1)}_${hash2}`;
|
|
72169
72326
|
names.set(shortened, name);
|
|
72170
72327
|
return shortened;
|
|
@@ -72287,11 +72444,11 @@ function translateRequest2(body, config2) {
|
|
|
72287
72444
|
};
|
|
72288
72445
|
return { request: request7, toolNames: names };
|
|
72289
72446
|
}
|
|
72290
|
-
var
|
|
72447
|
+
var import_node_crypto24, REQUESTABLE_EFFORTS, BILLING_HEADER_LINE2, CODEX_TOOL_NAME_LIMIT, TOOL_NAME_HASH_CHARS2, NON_TEXT_TOOL_RESULT2, EMPTY_PARAMETERS;
|
|
72291
72448
|
var init_translate2 = __esm({
|
|
72292
72449
|
"src/codex/translate.ts"() {
|
|
72293
72450
|
"use strict";
|
|
72294
|
-
|
|
72451
|
+
import_node_crypto24 = require("node:crypto");
|
|
72295
72452
|
init_schema();
|
|
72296
72453
|
init_anthropic();
|
|
72297
72454
|
REQUESTABLE_EFFORTS = ["low", "medium", "high"];
|
|
@@ -72884,19 +73041,18 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
72884
73041
|
...resolution.lastRanAs === void 0 ? {} : { lastRanAs: { identity: resolution.lastRanAs.identity, agoMs: farmRuntime.now() - Date.parse(resolution.lastRanAs.at) } }
|
|
72885
73042
|
};
|
|
72886
73043
|
}
|
|
73044
|
+
function warnOfSupersededConfigDir(warn, fs36, superseded, identity, identityDir) {
|
|
73045
|
+
if (superseded === void 0 || superseded === identityDir || fs36.sameDirectory(superseded, identityDir)) {
|
|
73046
|
+
return;
|
|
73047
|
+
}
|
|
73048
|
+
warn(`agent-shim: the identity named on the command line outranks the inherited CLAUDE_CONFIG_DIR ${superseded}; running as ${identity} in ${identityDir}`);
|
|
73049
|
+
}
|
|
72887
73050
|
function decideLaunch(params, readOnly, onRecorded) {
|
|
72888
73051
|
const { paths, fs: fs36, proc, log } = params;
|
|
72889
|
-
const {
|
|
73052
|
+
const { argv } = proc;
|
|
72890
73053
|
const parsedArgv = parseLauncherArgv(argv);
|
|
72891
|
-
const cliOverride = buildCliOverride({
|
|
72892
|
-
env,
|
|
72893
|
-
categoryFlags: parsedArgv.categoryFlags,
|
|
72894
|
-
shareFlags: parsedArgv.shareFlags,
|
|
72895
|
-
hideFlags: parsedArgv.hideFlags
|
|
72896
|
-
});
|
|
72897
|
-
const configDirEscapeHatchApplies = env.CLAUDE_CONFIG_DIR !== void 0 && env.CLAUDE_CONFIG_DIR !== "";
|
|
72898
73054
|
const decidedIdentity = decideIdentity({
|
|
72899
|
-
env,
|
|
73055
|
+
env: proc.env,
|
|
72900
73056
|
argv0Identity: params.pickedIdentity ?? parsedArgv.identity,
|
|
72901
73057
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
72902
73058
|
readActiveIdentityFile: () => {
|
|
@@ -72908,6 +73064,14 @@ function decideLaunch(params, readOnly, onRecorded) {
|
|
|
72908
73064
|
return trimmed === "" ? void 0 : trimmed;
|
|
72909
73065
|
}
|
|
72910
73066
|
});
|
|
73067
|
+
const configDirEscapeHatchApplies = decidedIdentity.configDirEscapeHatch;
|
|
73068
|
+
const env = launchEnvironment(proc.env, configDirEscapeHatchApplies);
|
|
73069
|
+
const cliOverride = buildCliOverride({
|
|
73070
|
+
env,
|
|
73071
|
+
categoryFlags: parsedArgv.categoryFlags,
|
|
73072
|
+
shareFlags: parsedArgv.shareFlags,
|
|
73073
|
+
hideFlags: parsedArgv.hideFlags
|
|
73074
|
+
});
|
|
72911
73075
|
const { identityDecision, poolPick, poolRanking, lastRanAs } = pickFromPool(decidedIdentity, params, parsedArgv, readOnly);
|
|
72912
73076
|
const lockFarm = !readOnly && !configDirEscapeHatchApplies && identityDecision.name !== void 0 ? params.farm : void 0;
|
|
72913
73077
|
const lockPorts = params.namesLock ?? (lockFarm === void 0 ? realIdentityNamesLockPorts : { fs: lockFarm.fs, nowMs: lockFarm.now, ...lockFarm.lock });
|
|
@@ -72915,6 +73079,9 @@ function decideLaunch(params, readOnly, onRecorded) {
|
|
|
72915
73079
|
try {
|
|
72916
73080
|
const farmIdentity = configDirEscapeHatchApplies || identityDecision.name === void 0 ? void 0 : resolveIdentityId(paths.identitiesDir, identityDecision.name, fs36);
|
|
72917
73081
|
const farm = farmIdentity === void 0 ? void 0 : params.farm;
|
|
73082
|
+
if (!readOnly && params.supervised?.member === void 0 && farmIdentity !== void 0 && identityDecision.name !== void 0) {
|
|
73083
|
+
warnOfSupersededConfigDir(log.warn, fs36, identityDecision.supersededConfigDir, identityDecision.name, import_node_path58.default.join(paths.identitiesDir, farmIdentity));
|
|
73084
|
+
}
|
|
72918
73085
|
if (!readOnly && farm !== void 0 && farmIdentity !== void 0) {
|
|
72919
73086
|
try {
|
|
72920
73087
|
recoverFarmWarning(
|
|
@@ -73081,7 +73248,7 @@ function decideLaunch(params, readOnly, onRecorded) {
|
|
|
73081
73248
|
const doorPid = supervisorPid ?? (recordedPid !== void 0 && proc.isProcessAlive(recordedPid) ? recordedPid : void 0);
|
|
73082
73249
|
const doorRecord = doorPid === void 0 ? void 0 : readFrontDoorCodexRecord(params.fs, paths.frontdoorDir, doorPid);
|
|
73083
73250
|
const doorHome = doorRecord?.codexHome;
|
|
73084
|
-
const catalogueEnv = doorHome === void 0 ?
|
|
73251
|
+
const catalogueEnv = doorHome === void 0 ? env : { ...env, CODEX_HOME: doorHome };
|
|
73085
73252
|
const listedProviders = listProviderNames(fs36.readdir, paths.providersDir).flatMap((name) => {
|
|
73086
73253
|
try {
|
|
73087
73254
|
const definition = loadProvider(paths.providersDir, name, fs36);
|
|
@@ -73143,6 +73310,7 @@ function decideLaunch(params, readOnly, onRecorded) {
|
|
|
73143
73310
|
billing,
|
|
73144
73311
|
notes,
|
|
73145
73312
|
configDirEscapeHatch: configDirEscapeHatchApplies,
|
|
73313
|
+
env,
|
|
73146
73314
|
farmIdentity,
|
|
73147
73315
|
farmContext,
|
|
73148
73316
|
configProfileDecision,
|
|
@@ -73178,12 +73346,12 @@ function prepareLaunch(params) {
|
|
|
73178
73346
|
}
|
|
73179
73347
|
function prepareRegisteredLaunch(params, onRecorded) {
|
|
73180
73348
|
const { paths, proc, log } = params;
|
|
73181
|
-
const { env } = proc;
|
|
73182
73349
|
let unregisterLaunch;
|
|
73183
73350
|
const decided = decideLaunch(params, false, (remove) => {
|
|
73184
73351
|
unregisterLaunch = remove;
|
|
73185
73352
|
onRecorded(remove);
|
|
73186
73353
|
});
|
|
73354
|
+
const { env } = decided;
|
|
73187
73355
|
const { identityDecision, configProfileDecision, resolvedProvider, identityCredential, poolPick, poolRanking, lastRanAs, billing, notes, flags: resolvedFlags, configDirEscapeHatch: configDirEscapeHatchApplies, decision } = decided;
|
|
73188
73356
|
const rows = [
|
|
73189
73357
|
...decisionRows({
|
|
@@ -73258,7 +73426,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
|
|
|
73258
73426
|
log.error("agent-shim: this launch routes through the front-door daemon, but this launcher has no front-door port wired; refusing to launch without it.");
|
|
73259
73427
|
proc.exit(1);
|
|
73260
73428
|
}
|
|
73261
|
-
const sessionId = params.supervised?.sessionId ?? (0,
|
|
73429
|
+
const sessionId = params.supervised?.sessionId ?? (0, import_node_crypto25.randomUUID)();
|
|
73262
73430
|
const resolvedModels = decided.models ?? (decided.globalModels === void 0 ? void 0 : {});
|
|
73263
73431
|
const sessionModels = (0, import_node_util6.isDeepStrictEqual)(resolvedModels, decided.globalModels) ? void 0 : resolvedModels;
|
|
73264
73432
|
const session = { sessionId, ...sessionModels === void 0 ? {} : { models: sessionModels } };
|
|
@@ -73319,7 +73487,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
|
|
|
73319
73487
|
}
|
|
73320
73488
|
function resolveLaunch(params) {
|
|
73321
73489
|
const decided = decideLaunch(params, true);
|
|
73322
|
-
const { env } =
|
|
73490
|
+
const { env } = decided;
|
|
73323
73491
|
const frontDoor = decided.provider !== void 0 || decided.flags.headroom || decided.flags.trackUsage;
|
|
73324
73492
|
const built = buildEnv({
|
|
73325
73493
|
baseEnv: env,
|
|
@@ -73335,7 +73503,7 @@ function resolveLaunch(params) {
|
|
|
73335
73503
|
...decided.flags.statusline === void 0 ? {} : { statusline: decided.flags.statusline }
|
|
73336
73504
|
});
|
|
73337
73505
|
const credentialNames = decided.identityCredentialBlock === void 0 ? [] : Object.keys(credentialVariables(decided.identityCredentialBlock.target ?? "bearer", ""));
|
|
73338
|
-
const environment = [.../* @__PURE__ */ new Set([...Object.keys(built).filter((name) => built[name] !== env[name]), ...credentialNames])].sort();
|
|
73506
|
+
const environment = [.../* @__PURE__ */ new Set([...Object.keys(built).filter((name) => name !== INJECTED_ENV && built[name] !== env[name]), ...credentialNames])].sort();
|
|
73339
73507
|
const credential = decided.provider !== void 0 ? isRouterProvider(decided.provider.definition) ? void 0 : { subject: "provider", name: decided.provider.name, summary: summariseCredential(decided.provider.definition.credential) } : decided.identityCredentialBlock !== void 0 && decided.farmIdentity !== void 0 && decided.identityDecision.name !== void 0 ? { subject: "identity", name: decided.identityDecision.name, summary: summariseCredential(decided.identityCredentialBlock) } : void 0;
|
|
73340
73508
|
return {
|
|
73341
73509
|
decision: decided.decision,
|
|
@@ -73366,11 +73534,11 @@ function runLaunchPlan(plan, spawn10) {
|
|
|
73366
73534
|
function runLauncher(params) {
|
|
73367
73535
|
params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
|
|
73368
73536
|
}
|
|
73369
|
-
var
|
|
73537
|
+
var import_node_crypto25, import_node_os13, import_node_util6, import_node_path58;
|
|
73370
73538
|
var init_launcher = __esm({
|
|
73371
73539
|
"src/launcher.ts"() {
|
|
73372
73540
|
"use strict";
|
|
73373
|
-
|
|
73541
|
+
import_node_crypto25 = require("node:crypto");
|
|
73374
73542
|
import_node_os13 = __toESM(require("node:os"), 1);
|
|
73375
73543
|
init_catalogueCredential();
|
|
73376
73544
|
import_node_util6 = require("node:util");
|
|
@@ -73416,6 +73584,7 @@ var init_launcher = __esm({
|
|
|
73416
73584
|
init_launchHook();
|
|
73417
73585
|
init_targets();
|
|
73418
73586
|
init_names();
|
|
73587
|
+
init_injected();
|
|
73419
73588
|
}
|
|
73420
73589
|
});
|
|
73421
73590
|
|
|
@@ -73500,7 +73669,7 @@ function buildFarmRuntime(paths, cwd, run = realRunPort) {
|
|
|
73500
73669
|
...cliOverride === void 0 ? {} : { cliOverride }
|
|
73501
73670
|
}).input,
|
|
73502
73671
|
now: () => Date.now(),
|
|
73503
|
-
uniqueSuffix: `${String(process.pid)}.${(0,
|
|
73672
|
+
uniqueSuffix: `${String(process.pid)}.${(0, import_node_crypto26.randomUUID)()}`,
|
|
73504
73673
|
// Zombie-aware on purpose: a previous launcher that crashed out of a resync without releasing the lock may sit unreaped, still answering signal 0 as alive, and must read as a dead holder so this launch takes the lock over instead of timing out.
|
|
73505
73674
|
lock: { pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync }
|
|
73506
73675
|
},
|
|
@@ -73569,13 +73738,13 @@ function resolveClaudeLaunch(options, run = realRunPort) {
|
|
|
73569
73738
|
async function resolveClaudeLaunchAsync(options, runAsync2 = realRunAsync) {
|
|
73570
73739
|
return await resolveWithAsyncRuns((run) => resolveClaudeLaunch(options, run), runAsync2);
|
|
73571
73740
|
}
|
|
73572
|
-
var import_node_os14, import_node_path59,
|
|
73741
|
+
var import_node_os14, import_node_path59, import_node_crypto26, LaunchRefusedError;
|
|
73573
73742
|
var init_launchWiring = __esm({
|
|
73574
73743
|
"src/launchWiring.ts"() {
|
|
73575
73744
|
"use strict";
|
|
73576
73745
|
import_node_os14 = __toESM(require("node:os"), 1);
|
|
73577
73746
|
import_node_path59 = __toESM(require("node:path"), 1);
|
|
73578
|
-
|
|
73747
|
+
import_node_crypto26 = require("node:crypto");
|
|
73579
73748
|
init_cliError();
|
|
73580
73749
|
init_claudeShim();
|
|
73581
73750
|
init_classify();
|
|
@@ -73610,7 +73779,7 @@ function identityLaunchArgv(identity, flags) {
|
|
|
73610
73779
|
}
|
|
73611
73780
|
async function withIdentityClaude(params, identity, flags, use2) {
|
|
73612
73781
|
const refusals = [];
|
|
73613
|
-
const env =
|
|
73782
|
+
const env = { ...process.env };
|
|
73614
73783
|
const argv = [...identityLaunchArgv(identity, flags)];
|
|
73615
73784
|
const run = await recordRuns((replay) => resolveClaudeLaunch({ argv, cwd: params.cwd, env: definedEnvironment(env), paths: params.paths }, replay), params.runAsync ?? realRunAsync);
|
|
73616
73785
|
const farm = buildFarmRuntime(params.paths, params.cwd, run);
|
|
@@ -73648,7 +73817,7 @@ async function withIdentityClaude(params, identity, flags, use2) {
|
|
|
73648
73817
|
plan.release();
|
|
73649
73818
|
}
|
|
73650
73819
|
}
|
|
73651
|
-
var
|
|
73820
|
+
var IDENTITY_ONLY_FLAG;
|
|
73652
73821
|
var init_identityClaude = __esm({
|
|
73653
73822
|
"src/usage/identityClaude.ts"() {
|
|
73654
73823
|
"use strict";
|
|
@@ -73657,7 +73826,6 @@ var init_identityClaude = __esm({
|
|
|
73657
73826
|
init_realPorts();
|
|
73658
73827
|
init_replayRun();
|
|
73659
73828
|
init_identityNamesLock();
|
|
73660
|
-
CONFIG_DIR_VARIABLE2 = "CLAUDE_CONFIG_DIR";
|
|
73661
73829
|
IDENTITY_ONLY_FLAG = "--no-provider";
|
|
73662
73830
|
}
|
|
73663
73831
|
});
|
|
@@ -124492,6 +124660,7 @@ init_farm();
|
|
|
124492
124660
|
init_guard();
|
|
124493
124661
|
init_providersStore();
|
|
124494
124662
|
init_projects();
|
|
124663
|
+
init_injected();
|
|
124495
124664
|
init_pipeline();
|
|
124496
124665
|
var HISTORY_PROJECTS_KEY_PREFIX = "history/projects/";
|
|
124497
124666
|
function projectFragmentOf(rawKey) {
|
|
@@ -124664,10 +124833,11 @@ function runCheck(params) {
|
|
|
124664
124833
|
const resolved = resolveDecisions({ facts, cascade: params.cascade, classification: params.classification });
|
|
124665
124834
|
const decisionLines = [...resolved.decisions.values()].slice().sort((a10, b) => a10.relPath < b.relPath ? -1 : a10.relPath > b.relPath ? 1 : 0).map(formatDecision);
|
|
124666
124835
|
const projectEncodingAmbiguities = flagAmbiguousEncodings(resolved.flattened, facts);
|
|
124836
|
+
const guardEnv = launchEnvironment(params.env, params.configDirEscapeHatch);
|
|
124667
124837
|
const ambientCredential = isCodex ? codexCredentialGuard(params.env, params.identity?.allowAmbientCredential ?? false) : evaluateAmbientCredentialGuard({
|
|
124668
|
-
env:
|
|
124838
|
+
env: guardEnv,
|
|
124669
124839
|
allowAmbientCredential: params.identity?.allowAmbientCredential ?? false,
|
|
124670
|
-
allowAmbientCredentialOverride: parseEnvBool("AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL",
|
|
124840
|
+
allowAmbientCredentialOverride: parseEnvBool("AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL", guardEnv.AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL) === true,
|
|
124671
124841
|
...params.identityName === void 0 ? {} : { identityName: params.identityName }
|
|
124672
124842
|
});
|
|
124673
124843
|
const settingsShared = resolved.flattened.categories.get("settings") ?? SHIPPED_CATEGORY_DEFAULTS.settings;
|
|
@@ -124837,6 +125007,7 @@ function collectCheckReport(params) {
|
|
|
124837
125007
|
home,
|
|
124838
125008
|
claudeHome,
|
|
124839
125009
|
env: params.env,
|
|
125010
|
+
configDirEscapeHatch: identityDecision.configDirEscapeHatch,
|
|
124840
125011
|
...git.branch === void 0 ? {} : { branch: git.branch },
|
|
124841
125012
|
...git.branchDetached === void 0 ? {} : { branchDetached: git.branchDetached },
|
|
124842
125013
|
nowMs: Date.now(),
|
|
@@ -124884,7 +125055,7 @@ function registerCheckCommand(program2, deps) {
|
|
|
124884
125055
|
}
|
|
124885
125056
|
|
|
124886
125057
|
// src/codex/commands.ts
|
|
124887
|
-
var
|
|
125058
|
+
var import_node_crypto17 = require("node:crypto");
|
|
124888
125059
|
var import_node_fs17 = __toESM(require("node:fs"), 1);
|
|
124889
125060
|
var import_node_os8 = __toESM(require("node:os"), 1);
|
|
124890
125061
|
var import_node_path47 = __toESM(require("node:path"), 1);
|
|
@@ -125007,7 +125178,7 @@ async function runSiwcLogout(ports) {
|
|
|
125007
125178
|
|
|
125008
125179
|
// src/codex/siwcPorts.ts
|
|
125009
125180
|
var import_node_child_process5 = require("node:child_process");
|
|
125010
|
-
var
|
|
125181
|
+
var import_node_crypto15 = require("node:crypto");
|
|
125011
125182
|
var import_node_http = __toESM(require("node:http"), 1);
|
|
125012
125183
|
|
|
125013
125184
|
// src/codex/http.ts
|
|
@@ -125030,7 +125201,7 @@ var HTTP_STATUS = {
|
|
|
125030
125201
|
// src/codex/siwcPorts.ts
|
|
125031
125202
|
init_siwc();
|
|
125032
125203
|
function realSiwcPorts(fetch3) {
|
|
125033
|
-
return { fetch: fetch3, randomBytes: (size) => (0,
|
|
125204
|
+
return { fetch: fetch3, randomBytes: (size) => (0, import_node_crypto15.randomBytes)(size), now: () => /* @__PURE__ */ new Date() };
|
|
125034
125205
|
}
|
|
125035
125206
|
var CALLBACK_PAGE = "<!doctype html><meta charset=utf-8><title>Signed in</title><p>You can close this tab and return to the terminal.</p>";
|
|
125036
125207
|
async function listenForCallback(port, state) {
|
|
@@ -125080,7 +125251,7 @@ function openInBrowser(url2) {
|
|
|
125080
125251
|
init_siwcStore();
|
|
125081
125252
|
|
|
125082
125253
|
// src/codex/upstream.ts
|
|
125083
|
-
var
|
|
125254
|
+
var import_node_crypto16 = require("node:crypto");
|
|
125084
125255
|
init_siwc();
|
|
125085
125256
|
var CODEX_RESPONSES_URL = "https://chatgpt.com/backend-api/codex/responses";
|
|
125086
125257
|
var CODEX_UPSTREAM_TIMEOUT_MS = 3e5;
|
|
@@ -125117,7 +125288,7 @@ function sessionIdFor(userId, randomId) {
|
|
|
125117
125288
|
if (userId === void 0 || userId === "") {
|
|
125118
125289
|
return randomId();
|
|
125119
125290
|
}
|
|
125120
|
-
const hex3 = (0,
|
|
125291
|
+
const hex3 = (0, import_node_crypto16.createHash)("sha256").update(`agent-shim codex session
|
|
125121
125292
|
${userId}`).digest("hex");
|
|
125122
125293
|
let next = 0;
|
|
125123
125294
|
return UUID_TEMPLATE.replace(/x/g, () => hex3.charAt(next++));
|
|
@@ -125202,7 +125373,7 @@ function writeUsageSnapshot(log, snapshot) {
|
|
|
125202
125373
|
function createCodexRoutePorts(log, signInFile, options) {
|
|
125203
125374
|
const agent = createUpstreamAgent();
|
|
125204
125375
|
const upstreamFetch = createUpstreamFetch(agent);
|
|
125205
|
-
const tempSuffix = `${String(process.pid)}.${(0,
|
|
125376
|
+
const tempSuffix = `${String(process.pid)}.${(0, import_node_crypto17.randomUUID)()}`;
|
|
125206
125377
|
const auth = createCodexAuthStore(import_node_path47.default.join(codexHome(options?.env ?? process.env, import_node_os8.default.homedir()), "auth.json"), {
|
|
125207
125378
|
fs: realCodexAuthFs,
|
|
125208
125379
|
fetch: upstreamFetch,
|
|
@@ -125212,8 +125383,8 @@ function createCodexRoutePorts(log, signInFile, options) {
|
|
|
125212
125383
|
const signIn = createSiwcStore(signInFile, { fs: realCodexAuthFs, siwc: realSiwcPorts(upstreamFetch), tempSuffix });
|
|
125213
125384
|
return {
|
|
125214
125385
|
upstreams: {
|
|
125215
|
-
"codex-cli": { fetch: upstreamFetch, auth, timers: realTimers, randomId:
|
|
125216
|
-
"chatgpt-sign-in": { fetch: upstreamFetch, auth: signIn.auth, timers: realTimers, randomId:
|
|
125386
|
+
"codex-cli": { fetch: upstreamFetch, auth, timers: realTimers, randomId: import_node_crypto17.randomUUID },
|
|
125387
|
+
"chatgpt-sign-in": { fetch: upstreamFetch, auth: signIn.auth, timers: realTimers, randomId: import_node_crypto17.randomUUID, target: RESPONSES_API_TARGET }
|
|
125217
125388
|
},
|
|
125218
125389
|
...options?.enableUsageSnapshot === true ? {
|
|
125219
125390
|
writeUsageSnapshot: (snapshot) => {
|
|
@@ -125292,7 +125463,7 @@ async function runCodexLogout(paths) {
|
|
|
125292
125463
|
}
|
|
125293
125464
|
function realSiwcLoginPorts(paths) {
|
|
125294
125465
|
const siwc = realSiwcPorts(createUpstreamFetch(createUpstreamAgent()));
|
|
125295
|
-
const store = createSiwcStore(paths.chatgptSignInFile, { fs: realCodexAuthFs, siwc, tempSuffix: `${String(process.pid)}.${(0,
|
|
125466
|
+
const store = createSiwcStore(paths.chatgptSignInFile, { fs: realCodexAuthFs, siwc, tempSuffix: `${String(process.pid)}.${(0, import_node_crypto17.randomUUID)()}` });
|
|
125296
125467
|
return {
|
|
125297
125468
|
store,
|
|
125298
125469
|
siwc,
|
|
@@ -125350,7 +125521,7 @@ function registerCodexCommand(program2, deps) {
|
|
|
125350
125521
|
}
|
|
125351
125522
|
|
|
125352
125523
|
// src/frontdoor/commands.ts
|
|
125353
|
-
var
|
|
125524
|
+
var import_node_crypto30 = require("node:crypto");
|
|
125354
125525
|
var import_node_os18 = __toESM(require("node:os"), 1);
|
|
125355
125526
|
init_catalogueCredential();
|
|
125356
125527
|
var import_node_path70 = __toESM(require("node:path"), 1);
|
|
@@ -127199,30 +127370,60 @@ function parseRcRequestBody(kind, body) {
|
|
|
127199
127370
|
}
|
|
127200
127371
|
function createRcSessionTracker(deps) {
|
|
127201
127372
|
const entries = /* @__PURE__ */ new Map();
|
|
127202
|
-
const
|
|
127373
|
+
const retirePending = (entry, requestId, reason) => {
|
|
127374
|
+
if (entry.pending.delete(requestId)) {
|
|
127375
|
+
entry.retired.set(requestId, deps.now());
|
|
127376
|
+
deps.onTransition?.({ kind: "pending-retired", session: entry.id, requestId, reason, at: deps.now() });
|
|
127377
|
+
}
|
|
127378
|
+
};
|
|
127379
|
+
const addPending = (entry, pending) => {
|
|
127380
|
+
if (entry.retired.has(pending.requestId)) {
|
|
127381
|
+
return;
|
|
127382
|
+
}
|
|
127383
|
+
const born = !entry.pending.has(pending.requestId);
|
|
127384
|
+
entry.pending.set(pending.requestId, pending);
|
|
127385
|
+
if (born) {
|
|
127386
|
+
deps.onTransition?.({ kind: "pending-born", session: entry.id, requestId: pending.requestId, type: pending.type, summary: pending.summary, at: pending.observedAt });
|
|
127387
|
+
}
|
|
127388
|
+
};
|
|
127389
|
+
const expire = (id2, reason) => {
|
|
127390
|
+
const entry = entries.get(id2);
|
|
127391
|
+
if (entry === void 0) {
|
|
127392
|
+
return;
|
|
127393
|
+
}
|
|
127394
|
+
for (const requestId of [...entry.pending.keys()]) {
|
|
127395
|
+
retirePending(entry, requestId, "session-ended");
|
|
127396
|
+
}
|
|
127203
127397
|
entries.delete(id2);
|
|
127398
|
+
deps.onTransition?.({ kind: "session-ended", session: id2, reason, at: deps.now() });
|
|
127204
127399
|
};
|
|
127205
127400
|
const expirePendings = (entry, now) => {
|
|
127206
127401
|
for (const [requestId, pending] of entry.pending) {
|
|
127207
127402
|
if (now - pending.observedAt >= RC_PENDING_DEADLINE_MS) {
|
|
127208
|
-
entry
|
|
127403
|
+
retirePending(entry, requestId, "expired");
|
|
127404
|
+
}
|
|
127405
|
+
}
|
|
127406
|
+
for (const [requestId, retiredAt] of entry.retired) {
|
|
127407
|
+
if (now - retiredAt >= RC_PENDING_DEADLINE_MS) {
|
|
127408
|
+
entry.retired.delete(requestId);
|
|
127209
127409
|
}
|
|
127210
127410
|
}
|
|
127211
127411
|
};
|
|
127212
127412
|
const sweep = () => {
|
|
127213
127413
|
for (const [id2, entry] of entries) {
|
|
127214
127414
|
if (deps.now() - entry.lastSeenAt >= deps.idleMs) {
|
|
127215
|
-
expire(id2);
|
|
127415
|
+
expire(id2, "expired");
|
|
127216
127416
|
continue;
|
|
127217
127417
|
}
|
|
127218
127418
|
expirePendings(entry, deps.now());
|
|
127219
127419
|
}
|
|
127220
127420
|
};
|
|
127221
|
-
const timer = setInterval(sweep, deps.idleMs);
|
|
127421
|
+
const timer = setInterval(sweep, Math.min(deps.idleMs, RC_PENDING_DEADLINE_MS));
|
|
127222
127422
|
timer.unref();
|
|
127223
127423
|
const birth = (id2, facts) => {
|
|
127224
|
-
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), workerState: void 0, workerIdleSeconds: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map() };
|
|
127424
|
+
const record3 = { id: id2, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new Map(), workerState: void 0, workerIdleSeconds: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map() };
|
|
127225
127425
|
entries.set(id2, record3);
|
|
127426
|
+
deps.onTransition?.({ kind: "session-appeared", session: id2, at: record3.createdAt });
|
|
127226
127427
|
return record3;
|
|
127227
127428
|
};
|
|
127228
127429
|
const persistCredential = (entry) => {
|
|
@@ -127230,6 +127431,13 @@ function createRcSessionTracker(deps) {
|
|
|
127230
127431
|
deps.credentialStore?.write(entry.id, { authorization: entry.oauthAuthorization, anthropicVersion: entry.anthropicVersion, anthropicClientPlatform: entry.anthropicClientPlatform });
|
|
127231
127432
|
}
|
|
127232
127433
|
};
|
|
127434
|
+
const refresh = (entry, facts) => {
|
|
127435
|
+
entry.lastSeenAt = deps.now();
|
|
127436
|
+
entry.oauthAuthorization = facts.oauthAuthorization ?? entry.oauthAuthorization;
|
|
127437
|
+
entry.anthropicVersion = facts.anthropicVersion ?? entry.anthropicVersion;
|
|
127438
|
+
entry.anthropicClientPlatform = facts.anthropicClientPlatform ?? entry.anthropicClientPlatform;
|
|
127439
|
+
persistCredential(entry);
|
|
127440
|
+
};
|
|
127233
127441
|
const observeExchange = (request7) => {
|
|
127234
127442
|
const method = (request7.method ?? "").toUpperCase();
|
|
127235
127443
|
if (!isRcSessionExchange(request7.url)) {
|
|
@@ -127268,7 +127476,12 @@ function createRcSessionTracker(deps) {
|
|
|
127268
127476
|
if (id3 === void 0) {
|
|
127269
127477
|
return;
|
|
127270
127478
|
}
|
|
127271
|
-
|
|
127479
|
+
const existing = entries.get(id3);
|
|
127480
|
+
if (existing === void 0) {
|
|
127481
|
+
persistCredential(birth(id3, facts));
|
|
127482
|
+
return;
|
|
127483
|
+
}
|
|
127484
|
+
refresh(existing, facts);
|
|
127272
127485
|
}
|
|
127273
127486
|
};
|
|
127274
127487
|
}
|
|
@@ -127277,12 +127490,10 @@ function createRcSessionTracker(deps) {
|
|
|
127277
127490
|
if (id2?.startsWith(RC_SESSION_ID_PREFIX) !== true) {
|
|
127278
127491
|
return void 0;
|
|
127279
127492
|
}
|
|
127280
|
-
const
|
|
127281
|
-
|
|
127282
|
-
|
|
127283
|
-
|
|
127284
|
-
entry.anthropicClientPlatform = facts.anthropicClientPlatform ?? entry.anthropicClientPlatform;
|
|
127285
|
-
persistCredential(entry);
|
|
127493
|
+
const tracked = entries.get(id2);
|
|
127494
|
+
if (tracked !== void 0) {
|
|
127495
|
+
refresh(tracked, facts);
|
|
127496
|
+
}
|
|
127286
127497
|
const bodyKind = method === "POST" && rest === `${id2}/worker/events` ? "worker-events" : method === "POST" && rest === `${id2}/events` ? "client-events" : method === "POST" && rest === `${id2}/worker/heartbeat` ? "heartbeat" : method === "PUT" && rest === `${id2}/worker` ? "worker-registration" : void 0;
|
|
127287
127498
|
let chunks = [];
|
|
127288
127499
|
let buffered = 0;
|
|
@@ -127303,10 +127514,10 @@ function createRcSessionTracker(deps) {
|
|
|
127303
127514
|
}
|
|
127304
127515
|
const now = deps.now();
|
|
127305
127516
|
for (const controlRequest of factsOfBody.controlRequests) {
|
|
127306
|
-
entryNow
|
|
127517
|
+
addPending(entryNow, { sessionId: id2, ...controlRequest, observedAt: now });
|
|
127307
127518
|
}
|
|
127308
127519
|
for (const requestId of factsOfBody.answeredRequestIds) {
|
|
127309
|
-
entryNow
|
|
127520
|
+
retirePending(entryNow, requestId, "answered");
|
|
127310
127521
|
}
|
|
127311
127522
|
for (const payload of factsOfBody.payloads) {
|
|
127312
127523
|
entryNow.liveTasks = applyAgentTaskEvent(entryNow.liveTasks, id2, payload, now);
|
|
@@ -127315,7 +127526,11 @@ function createRcSessionTracker(deps) {
|
|
|
127315
127526
|
entryNow.workerIdleSeconds = { value: factsOfBody.idleSeconds, observedAt: now };
|
|
127316
127527
|
}
|
|
127317
127528
|
if (factsOfBody.workerStatus !== void 0) {
|
|
127529
|
+
const previous = entryNow.workerState?.value;
|
|
127318
127530
|
entryNow.workerState = { value: factsOfBody.workerStatus, observedAt: now };
|
|
127531
|
+
if (previous !== factsOfBody.workerStatus) {
|
|
127532
|
+
deps.onTransition?.({ kind: "worker-state", session: id2, state: factsOfBody.workerStatus, ...previous === void 0 ? {} : { previous }, at: now });
|
|
127533
|
+
}
|
|
127319
127534
|
}
|
|
127320
127535
|
};
|
|
127321
127536
|
const archiving = method === "POST" && rest === `${id2}/archive`;
|
|
@@ -127340,10 +127555,13 @@ function createRcSessionTracker(deps) {
|
|
|
127340
127555
|
onResponse: (status, headers) => {
|
|
127341
127556
|
if (singleHeader(headers, CONFLICT_REASON_HEADER) !== void 0 || archiving && isSuccessful(status)) {
|
|
127342
127557
|
deps.credentialStore?.remove(id2);
|
|
127343
|
-
expire(id2);
|
|
127558
|
+
expire(id2, singleHeader(headers, CONFLICT_REASON_HEADER) === void 0 ? "archived" : "conflict");
|
|
127344
127559
|
return;
|
|
127345
127560
|
}
|
|
127346
127561
|
accepted = isSuccessful(status);
|
|
127562
|
+
if (accepted && !entries.has(id2)) {
|
|
127563
|
+
persistCredential(birth(id2, facts));
|
|
127564
|
+
}
|
|
127347
127565
|
file2();
|
|
127348
127566
|
},
|
|
127349
127567
|
onBodyChunk: () => {
|
|
@@ -127408,12 +127626,12 @@ function createRcSessionTracker(deps) {
|
|
|
127408
127626
|
const pending = pendingOfControlRequestPayload(event.payload);
|
|
127409
127627
|
if (pending !== void 0) {
|
|
127410
127628
|
if (event.source === RC_STREAM_WORKER_SOURCE) {
|
|
127411
|
-
entry
|
|
127629
|
+
addPending(entry, { sessionId, ...pending, observedAt: deps.now() });
|
|
127412
127630
|
}
|
|
127413
127631
|
return;
|
|
127414
127632
|
}
|
|
127415
127633
|
for (const requestId of answeredRequestIdsOfControlResponsePayload(event.payload)) {
|
|
127416
|
-
entry
|
|
127634
|
+
retirePending(entry, requestId, "answered");
|
|
127417
127635
|
}
|
|
127418
127636
|
},
|
|
127419
127637
|
liveTasksOf: (sessionId) => {
|
|
@@ -127421,10 +127639,14 @@ function createRcSessionTracker(deps) {
|
|
|
127421
127639
|
return sortedEntries().filter((entry) => sessionId === void 0 || entry.id === sessionId).flatMap((entry) => [...entry.liveTasks.values()].sort((left, right) => left.observedAt - right.observedAt || (left.taskId < right.taskId ? -1 : 1)));
|
|
127422
127640
|
},
|
|
127423
127641
|
completePending: (sessionId, requestId) => {
|
|
127424
|
-
entries.get(sessionId)
|
|
127642
|
+
const entry = entries.get(sessionId);
|
|
127643
|
+
if (entry !== void 0) {
|
|
127644
|
+
retirePending(entry, requestId, "answered");
|
|
127645
|
+
}
|
|
127425
127646
|
},
|
|
127426
127647
|
close: () => {
|
|
127427
127648
|
clearInterval(timer);
|
|
127649
|
+
deps.onClose?.();
|
|
127428
127650
|
}
|
|
127429
127651
|
};
|
|
127430
127652
|
}
|
|
@@ -129745,12 +129967,8 @@ function runDoctor(params) {
|
|
|
129745
129967
|
}
|
|
129746
129968
|
push(section, "warn", `${where} pins Claude Code ${version2}, which is not installed (installed: ${installed.length === 0 ? "none" : installed.join(", ")}); a launch that resolves to it fails.`, subject);
|
|
129747
129969
|
};
|
|
129748
|
-
const ambient =
|
|
129749
|
-
|
|
129750
|
-
push("ambient-credential", "pass", "No ambient-credential environment variable is set.");
|
|
129751
|
-
} else {
|
|
129752
|
-
push("ambient-credential", "warn", formatAmbientCredentialGuardMessage(ambient.variable));
|
|
129753
|
-
}
|
|
129970
|
+
const ambient = ambientCredentialFinding(params.env);
|
|
129971
|
+
push("ambient-credential", ambient.severity, ambient.message);
|
|
129754
129972
|
if (params.binaryDiscovery.ok) {
|
|
129755
129973
|
const { binary } = params.binaryDiscovery;
|
|
129756
129974
|
const versionNote = binary.version === void 0 ? "" : `, version ${binary.version}`;
|
|
@@ -141531,6 +141749,7 @@ var LaunchDecisionSchema = external_exports.strictObject({
|
|
|
141531
141749
|
identityId: external_exports.string().optional(),
|
|
141532
141750
|
identitySource: external_exports.enum(IDENTITY_DECISION_SOURCES),
|
|
141533
141751
|
pool: LaunchPoolDecisionSchema.optional(),
|
|
141752
|
+
/** True when `CLAUDE_CONFIG_DIR` was already set and nothing on the command line named an identity; an identity named there outranks the variable and leaves it false. */
|
|
141534
141753
|
configDirEscapeHatch: external_exports.boolean(),
|
|
141535
141754
|
configDir: external_exports.string().optional(),
|
|
141536
141755
|
configProfile: external_exports.string().optional(),
|
|
@@ -141660,104 +141879,8 @@ function createAgentTreesApiRouter(deps) {
|
|
|
141660
141879
|
};
|
|
141661
141880
|
}
|
|
141662
141881
|
|
|
141663
|
-
// src/frontdoor/
|
|
141664
|
-
|
|
141665
|
-
var FRONTDOOR_API_TAG2 = "frontdoor";
|
|
141666
|
-
var CHECK_API_TAG = "check";
|
|
141667
|
-
var DOCTOR_API_TAG = "doctor";
|
|
141668
|
-
var POOL_API_TAG = "pool";
|
|
141669
|
-
function createControlApiRouter(deps) {
|
|
141670
|
-
const authed = doorApiAuth(deps.expectedToken);
|
|
141671
|
-
return {
|
|
141672
|
-
usage: {
|
|
141673
|
-
list: authed.meta(openapi({ method: "GET", path: "/rest/usage/snapshots", summary: "List every identity's usage snapshot", tags: [USAGE_API_TAG] })).output(UsageListOutputSchema).handler(() => ({ snapshots: deps.usageSnapshots() })),
|
|
141674
|
-
resets: authed.meta(openapi({ method: "GET", path: "/rest/usage/resets", summary: "List every recorded quota window with when it resets", tags: [USAGE_API_TAG] })).output(ResetScheduleSchema).handler(() => collectResets(deps.usageSnapshots(), deps.now())),
|
|
141675
|
-
effectiveWindow: authed.meta(openapi({ method: "GET", path: "/rest/usage/windows", summary: "Read one identity's effective quota windows", tags: [USAGE_API_TAG] })).input(UsageWindowsInputSchema).output(UsageWindowsOutputSchema).handler(({ input: input2 }) => {
|
|
141676
|
-
const snapshot = deps.usageSnapshotOf(input2.identity);
|
|
141677
|
-
if (snapshot === void 0) {
|
|
141678
|
-
throw new ORPCError("NOT_FOUND", { message: `identity ${input2.identity} has no usage snapshot yet, so no quota window has been observed for it` });
|
|
141679
|
-
}
|
|
141680
|
-
const provider = input2.provider ?? ANTHROPIC_PROVIDER;
|
|
141681
|
-
const rateLimit = snapshot.providers[provider]?.rateLimit;
|
|
141682
|
-
const unified = rateLimit?.unified;
|
|
141683
|
-
const now = deps.now();
|
|
141684
|
-
return {
|
|
141685
|
-
identity: snapshot.identity,
|
|
141686
|
-
provider,
|
|
141687
|
-
...rateLimit === void 0 ? {} : { observedAt: rateLimit.observedAt },
|
|
141688
|
-
...unified?.fiveHour === void 0 ? {} : { fiveHour: effectiveWindow(unified.fiveHour, now) },
|
|
141689
|
-
...unified?.sevenDay === void 0 ? {} : { sevenDay: effectiveWindow(unified.sevenDay, now) }
|
|
141690
|
-
};
|
|
141691
|
-
}),
|
|
141692
|
-
live: authed.meta(openapi({ method: "GET", path: "/rest/usage/live", summary: "Read the live rate-limit observations the event backbone files", tags: [USAGE_API_TAG] })).input(RcSessionQuerySchema).output(UsageLiveOutputSchema).handler(({ input: input2 }) => {
|
|
141693
|
-
const sessions = deps.liveRateLimits(input2.session);
|
|
141694
|
-
if (input2.session !== void 0 && sessions.length === 0) {
|
|
141695
|
-
if (deps.list().some((session) => session.id === input2.session)) {
|
|
141696
|
-
throw new ORPCError("NOT_FOUND", { message: `session ${input2.session} has filed no rate_limit_event on its stream yet: the worker emits one only once a turn has completed, so retry after this session's next turn` });
|
|
141697
|
-
}
|
|
141698
|
-
throw new ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input2.session) });
|
|
141699
|
-
}
|
|
141700
|
-
return { latest: deps.latestRateLimit(), sessions };
|
|
141701
|
-
})
|
|
141702
|
-
},
|
|
141703
|
-
frontdoor: {
|
|
141704
|
-
status: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/status", summary: "Read the front door's status", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorStatusOutputSchema).handler(() => deps.frontDoorStatus()),
|
|
141705
|
-
sessions: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/sessions", summary: "Read the front door's session registry", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorSessionsOutputSchema).handler(() => ({ sessions: deps.frontDoorStatus().sessions }))
|
|
141706
|
-
},
|
|
141707
|
-
check: {
|
|
141708
|
-
// The report's own JSON shape is the contract (the same one `check --json` prints and `checkReportSchema.ts` defines), so the procedure returns exactly that conversion.
|
|
141709
|
-
run: authed.meta(openapi({ method: "GET", path: "/rest/check", summary: "Run the check report for one directory", tags: [CHECK_API_TAG] })).input(CheckRunInputSchema).output(CheckReportJsonSchema).handler(({ input: input2 }) => checkReportToJson(deps.checkReport(input2.path, input2.identity)))
|
|
141710
|
-
},
|
|
141711
|
-
doctor: {
|
|
141712
|
-
run: authed.meta(openapi({ method: "GET", path: "/rest/doctor", summary: "Run the doctor report", tags: [DOCTOR_API_TAG] })).output(DoctorRunOutputSchema).handler(() => deps.doctorReport())
|
|
141713
|
-
},
|
|
141714
|
-
pool: {
|
|
141715
|
-
pick: authed.meta(openapi({ method: "GET", path: "/rest/pool/pick", summary: "Rank one pool exactly as a launch from a directory would right now", tags: [POOL_API_TAG] })).input(PoolPickInputSchema).output(PoolPickReportSchema).handler(({ input: input2 }) => {
|
|
141716
|
-
const report = deps.poolPick(input2.pool, input2.path);
|
|
141717
|
-
if (report === void 0) {
|
|
141718
|
-
const live = deps.poolNames();
|
|
141719
|
-
throw new ORPCError("NOT_FOUND", {
|
|
141720
|
-
message: live.length === 0 ? `no pools are configured, so none is named ${input2.pool}` : `no pool is named ${input2.pool}; the live pools are ${live.map((name) => `"${name}"`).join(", ")}`
|
|
141721
|
-
});
|
|
141722
|
-
}
|
|
141723
|
-
return report;
|
|
141724
|
-
})
|
|
141725
|
-
}
|
|
141726
|
-
};
|
|
141727
|
-
}
|
|
141728
|
-
function createDoorApiRouter(deps) {
|
|
141729
|
-
const control = createControlApiRouter(deps);
|
|
141730
|
-
const lifecycle = createLifecycleApiRouter(deps);
|
|
141731
|
-
return { ...createRcApiRouter(deps), ...control, ...lifecycle, ...createConfigApiRouter(deps), ...createCodexApiRouter(deps), ...createLaunchApiRouter(deps), ...createAgentTreesApiRouter(deps), ...createEventsApiRouter(deps), frontdoor: { ...control.frontdoor, ...lifecycle.frontdoor } };
|
|
141732
|
-
}
|
|
141733
|
-
function createDoorApiNodeHandler(deps) {
|
|
141734
|
-
return doorApiNodeHandlerOf(createDoorApiRouter(deps), deps.expectedToken);
|
|
141735
|
-
}
|
|
141736
|
-
|
|
141737
|
-
// src/frontdoor/doorHealthEvents.ts
|
|
141738
|
-
function createDoorHealthPublisher(hub, now, pid) {
|
|
141739
|
-
const publisher = hub.publisher(DOOR_HEALTH_EVENT_SOURCE);
|
|
141740
|
-
return {
|
|
141741
|
-
generation: (ports) => {
|
|
141742
|
-
publisher.publish({ kind: "generation", pid, providerPort: ports.providerPort, connectPort: ports.connectPort, directPort: ports.directPort, observedAt: now() });
|
|
141743
|
-
},
|
|
141744
|
-
listenerFailed: (listener, message) => {
|
|
141745
|
-
publisher.publish({ kind: "listenerFailed", pid, listener, message, observedAt: now() });
|
|
141746
|
-
},
|
|
141747
|
-
idleShutdown: () => {
|
|
141748
|
-
publisher.publish({ kind: "idleShutdown", pid, observedAt: now() });
|
|
141749
|
-
},
|
|
141750
|
-
binaryTurnover: () => {
|
|
141751
|
-
publisher.publish({ kind: "binaryTurnover", pid, observedAt: now() });
|
|
141752
|
-
},
|
|
141753
|
-
superseded: (ownerPid) => {
|
|
141754
|
-
publisher.publish({ kind: "superseded", pid, ownerPid, observedAt: now() });
|
|
141755
|
-
},
|
|
141756
|
-
drained: () => {
|
|
141757
|
-
publisher.publish({ kind: "drained", pid, observedAt: now() });
|
|
141758
|
-
}
|
|
141759
|
-
};
|
|
141760
|
-
}
|
|
141882
|
+
// src/frontdoor/rcEventLog.ts
|
|
141883
|
+
init_zod();
|
|
141761
141884
|
|
|
141762
141885
|
// src/frontdoor/eventHub.ts
|
|
141763
141886
|
var DOOR_EVENT_BUFFER_EVENTS = 100;
|
|
@@ -141865,6 +141988,369 @@ function rcFanoutOnDoorHub(fanout, hub) {
|
|
|
141865
141988
|
};
|
|
141866
141989
|
}
|
|
141867
141990
|
|
|
141991
|
+
// src/frontdoor/rcEventLog.ts
|
|
141992
|
+
var RC_SESSION_EVENT_TOKEN_MAX_CHARS = 255;
|
|
141993
|
+
var HIGH_SURROGATE_FIRST = 55296;
|
|
141994
|
+
var HIGH_SURROGATE_LAST = 56319;
|
|
141995
|
+
var LOW_SURROGATE_FIRST = 56320;
|
|
141996
|
+
var LOW_SURROGATE_LAST = 57343;
|
|
141997
|
+
var CUT_MARKER = "...";
|
|
141998
|
+
var RC_SESSION_EVENT_SUMMARY_MAX_CHARS = RC_SESSION_EVENT_TOKEN_MAX_CHARS + " ".length + RC_PENDING_SUMMARY_EXCERPT_CHARS + CUT_MARKER.length;
|
|
141999
|
+
var RC_SESSION_EVENT_GENERATION_MAX_CHARS = "00000000-0000-4000-8000-000000000000".length;
|
|
142000
|
+
var SEQUENCE_MAX_DIGITS = String(Number.MAX_SAFE_INTEGER).length;
|
|
142001
|
+
var NUMBER_BYTES = Float64Array.BYTES_PER_ELEMENT;
|
|
142002
|
+
var NUMBER_FIELDS = ["at", "sequence"].length;
|
|
142003
|
+
var BYTES_PER_CODE_UNIT = Uint16Array.BYTES_PER_ELEMENT;
|
|
142004
|
+
var RC_SESSION_END_REASONS = ["expired", "archived", "conflict"];
|
|
142005
|
+
var RC_PENDING_RETIRE_REASONS = ["answered", "expired", "session-ended"];
|
|
142006
|
+
var transitionBase = { session: external_exports.string(), at: external_exports.number() };
|
|
142007
|
+
var cursorFields = { cursor: external_exports.string(), sequence: external_exports.int().positive() };
|
|
142008
|
+
var sessionAppearedShape = { kind: external_exports.literal("session-appeared"), ...transitionBase };
|
|
142009
|
+
var sessionEndedShape = { kind: external_exports.literal("session-ended"), reason: external_exports.enum(RC_SESSION_END_REASONS), ...transitionBase };
|
|
142010
|
+
var workerStateShape = { kind: external_exports.literal("worker-state"), state: external_exports.string(), previous: external_exports.string().optional(), ...transitionBase };
|
|
142011
|
+
var pendingBornShape = { kind: external_exports.literal("pending-born"), requestId: external_exports.string(), type: external_exports.string(), summary: external_exports.string(), ...transitionBase };
|
|
142012
|
+
var pendingRetiredShape = { kind: external_exports.literal("pending-retired"), requestId: external_exports.string(), reason: external_exports.enum(RC_PENDING_RETIRE_REASONS), ...transitionBase };
|
|
142013
|
+
var RcSessionTransitionSchema = external_exports.discriminatedUnion("kind", [
|
|
142014
|
+
external_exports.strictObject(sessionAppearedShape),
|
|
142015
|
+
external_exports.strictObject(sessionEndedShape),
|
|
142016
|
+
external_exports.strictObject(workerStateShape),
|
|
142017
|
+
external_exports.strictObject(pendingBornShape),
|
|
142018
|
+
external_exports.strictObject(pendingRetiredShape)
|
|
142019
|
+
]);
|
|
142020
|
+
var KIND_MAX_CHARS = Math.max(...RcSessionTransitionSchema.options.map((option) => option.shape.kind.value.length));
|
|
142021
|
+
var RC_SESSION_EVENT_MAX_BYTES = (RC_SESSION_EVENT_GENERATION_MAX_CHARS + ".".length + SEQUENCE_MAX_DIGITS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + KIND_MAX_CHARS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + RC_SESSION_EVENT_SUMMARY_MAX_CHARS) * BYTES_PER_CODE_UNIT + NUMBER_FIELDS * NUMBER_BYTES;
|
|
142022
|
+
var RC_SESSION_EVENT_LOG_CAPACITY = Math.floor(CONTROL_BODY_CAP_BYTES / RC_SESSION_EVENT_MAX_BYTES);
|
|
142023
|
+
var RcSessionEventSchema = external_exports.discriminatedUnion("kind", [
|
|
142024
|
+
external_exports.strictObject({ ...cursorFields, ...sessionAppearedShape }),
|
|
142025
|
+
external_exports.strictObject({ ...cursorFields, ...sessionEndedShape }),
|
|
142026
|
+
external_exports.strictObject({ ...cursorFields, ...workerStateShape }),
|
|
142027
|
+
external_exports.strictObject({ ...cursorFields, ...pendingBornShape }),
|
|
142028
|
+
external_exports.strictObject({ ...cursorFields, ...pendingRetiredShape })
|
|
142029
|
+
]);
|
|
142030
|
+
var RcSessionEventsReadInputSchema = external_exports.strictObject({
|
|
142031
|
+
/** The cursor of the last event the caller saw; every retained event when omitted. */
|
|
142032
|
+
since: external_exports.string().min(1).optional(),
|
|
142033
|
+
/** One `cse_` session id; every session when omitted. */
|
|
142034
|
+
session: external_exports.string().min(1).optional(),
|
|
142035
|
+
/** The most events one answer carries; every event after `since` when omitted. */
|
|
142036
|
+
limit: external_exports.int().positive().optional()
|
|
142037
|
+
});
|
|
142038
|
+
var RcSessionEventsPageInputSchema = RcSessionEventsReadInputSchema.extend({
|
|
142039
|
+
/** The most events this page carries: by default and at most, the bound the door's event backbone already holds per slow consumer (`DOOR_EVENT_BUFFER_EVENTS`, oRPC's own documented default for that case). A page lands whole in its reader, so a reader receives at most one consumer buffer's worth at a time (at worst `DOOR_EVENT_BUFFER_EVENTS` times `RC_SESSION_EVENT_MAX_BYTES`) and pages on with the cursor for more; a maximum of the whole window would let one page carry the log's entire memory budget into an agent's context. */
|
|
142040
|
+
limit: external_exports.int().positive().max(DOOR_EVENT_BUFFER_EVENTS).default(DOOR_EVENT_BUFFER_EVENTS)
|
|
142041
|
+
});
|
|
142042
|
+
var RcSessionEventsStreamInputSchema = RcSessionEventsReadInputSchema.omit({ limit: true });
|
|
142043
|
+
var RcSessionEventsReadOutputSchema = external_exports.discriminatedUnion("status", [
|
|
142044
|
+
external_exports.strictObject({ status: external_exports.literal("ok"), events: external_exports.readonly(external_exports.array(RcSessionEventSchema)), cursor: external_exports.string(), more: external_exports.boolean(), head: external_exports.string() }),
|
|
142045
|
+
external_exports.strictObject({ status: external_exports.literal("expired"), message: external_exports.string(), head: external_exports.string() })
|
|
142046
|
+
]);
|
|
142047
|
+
var CURSOR_SEPARATOR = ".";
|
|
142048
|
+
var RESYNC_ADVICE = "cursor expired, resync from status: read `rc status` for every session's present state, then resume after the head this answer names";
|
|
142049
|
+
function cursorOf(generation, sequence2) {
|
|
142050
|
+
return `${generation}${CURSOR_SEPARATOR}${String(sequence2)}`;
|
|
142051
|
+
}
|
|
142052
|
+
function parseCursor(cursor3) {
|
|
142053
|
+
const at2 = cursor3.lastIndexOf(CURSOR_SEPARATOR);
|
|
142054
|
+
if (at2 <= 0) {
|
|
142055
|
+
return void 0;
|
|
142056
|
+
}
|
|
142057
|
+
const digits = cursor3.slice(at2 + 1);
|
|
142058
|
+
if (!/^[0-9]+$/.test(digits)) {
|
|
142059
|
+
return void 0;
|
|
142060
|
+
}
|
|
142061
|
+
return { generation: cursor3.slice(0, at2), sequence: Number(digits) };
|
|
142062
|
+
}
|
|
142063
|
+
function codePointBoundary(text5, at2) {
|
|
142064
|
+
const before = text5.charCodeAt(at2 - 1);
|
|
142065
|
+
const after = text5.charCodeAt(at2);
|
|
142066
|
+
const isHigh = before >= HIGH_SURROGATE_FIRST && before <= HIGH_SURROGATE_LAST;
|
|
142067
|
+
const isLow = after >= LOW_SURROGATE_FIRST && after <= LOW_SURROGATE_LAST;
|
|
142068
|
+
return isHigh && isLow ? at2 - 1 : at2;
|
|
142069
|
+
}
|
|
142070
|
+
function bounded2(text5, maxChars) {
|
|
142071
|
+
const kept = text5.length <= maxChars ? text5 : `${text5.slice(0, codePointBoundary(text5, maxChars - CUT_MARKER.length))}${CUT_MARKER}`;
|
|
142072
|
+
return Buffer.from(kept, "utf16le").toString("utf16le");
|
|
142073
|
+
}
|
|
142074
|
+
function boundedTransition(transition) {
|
|
142075
|
+
const session = bounded2(transition.session, RC_SESSION_EVENT_TOKEN_MAX_CHARS);
|
|
142076
|
+
if (transition.kind === "worker-state") {
|
|
142077
|
+
return { ...transition, session, state: bounded2(transition.state, RC_SESSION_EVENT_TOKEN_MAX_CHARS), ...transition.previous === void 0 ? {} : { previous: bounded2(transition.previous, RC_SESSION_EVENT_TOKEN_MAX_CHARS) } };
|
|
142078
|
+
}
|
|
142079
|
+
if (transition.kind === "pending-born") {
|
|
142080
|
+
return { ...transition, session, requestId: bounded2(transition.requestId, RC_SESSION_EVENT_TOKEN_MAX_CHARS), type: bounded2(transition.type, RC_SESSION_EVENT_TOKEN_MAX_CHARS), summary: bounded2(transition.summary, RC_SESSION_EVENT_SUMMARY_MAX_CHARS) };
|
|
142081
|
+
}
|
|
142082
|
+
if (transition.kind === "pending-retired") {
|
|
142083
|
+
return { ...transition, session, requestId: bounded2(transition.requestId, RC_SESSION_EVENT_TOKEN_MAX_CHARS) };
|
|
142084
|
+
}
|
|
142085
|
+
return { ...transition, session };
|
|
142086
|
+
}
|
|
142087
|
+
function createRcSessionEventLog(deps) {
|
|
142088
|
+
if (deps.generation.includes(CURSOR_SEPARATOR)) {
|
|
142089
|
+
throw new Error(`a door generation id must not contain "${CURSOR_SEPARATOR}", which separates a cursor's generation from its sequence`);
|
|
142090
|
+
}
|
|
142091
|
+
if (deps.generation.length > RC_SESSION_EVENT_GENERATION_MAX_CHARS) {
|
|
142092
|
+
throw new Error(`a door generation id must be at most ${String(RC_SESSION_EVENT_GENERATION_MAX_CHARS)} characters, a UUID's length`);
|
|
142093
|
+
}
|
|
142094
|
+
const events = [];
|
|
142095
|
+
let lastSequence = 0;
|
|
142096
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
142097
|
+
let isClosed = false;
|
|
142098
|
+
const expired = (reason) => ({ status: "expired", message: `${reason}; ${RESYNC_ADVICE}`, head: cursorOf(deps.generation, lastSequence) });
|
|
142099
|
+
return {
|
|
142100
|
+
append: (transition) => {
|
|
142101
|
+
lastSequence += 1;
|
|
142102
|
+
events.push({ ...boundedTransition(transition), cursor: cursorOf(deps.generation, lastSequence), sequence: lastSequence });
|
|
142103
|
+
if (events.length > deps.capacity) {
|
|
142104
|
+
events.splice(0, events.length - deps.capacity);
|
|
142105
|
+
}
|
|
142106
|
+
for (const listener of listeners) {
|
|
142107
|
+
listener();
|
|
142108
|
+
}
|
|
142109
|
+
},
|
|
142110
|
+
head: () => cursorOf(deps.generation, lastSequence),
|
|
142111
|
+
read: ({ since, session, limit }) => {
|
|
142112
|
+
let after = 0;
|
|
142113
|
+
if (since !== void 0) {
|
|
142114
|
+
const parsed = parseCursor(since);
|
|
142115
|
+
if (parsed === void 0) {
|
|
142116
|
+
return expired(`"${since}" is not a cursor this door issues`);
|
|
142117
|
+
}
|
|
142118
|
+
if (parsed.generation !== deps.generation) {
|
|
142119
|
+
return expired(`the cursor "${since}" was issued by another generation of the front door, whose events this one never held`);
|
|
142120
|
+
}
|
|
142121
|
+
if (parsed.sequence > lastSequence) {
|
|
142122
|
+
return expired(`the cursor "${since}" names an event past this door's newest`);
|
|
142123
|
+
}
|
|
142124
|
+
const oldest = events[0]?.sequence ?? lastSequence + 1;
|
|
142125
|
+
if (parsed.sequence < oldest - 1) {
|
|
142126
|
+
return expired(`the events after "${since}" have been evicted (the log retains the newest ${String(deps.capacity)} and the oldest it still holds is "${cursorOf(deps.generation, oldest)}")`);
|
|
142127
|
+
}
|
|
142128
|
+
after = parsed.sequence;
|
|
142129
|
+
}
|
|
142130
|
+
const selected2 = [];
|
|
142131
|
+
let cursor3 = cursorOf(deps.generation, lastSequence);
|
|
142132
|
+
let more = false;
|
|
142133
|
+
for (const event of events) {
|
|
142134
|
+
if (event.sequence <= after || session !== void 0 && event.session !== session) {
|
|
142135
|
+
continue;
|
|
142136
|
+
}
|
|
142137
|
+
if (limit !== void 0 && selected2.length === limit) {
|
|
142138
|
+
more = true;
|
|
142139
|
+
cursor3 = selected2.at(-1)?.cursor ?? cursor3;
|
|
142140
|
+
break;
|
|
142141
|
+
}
|
|
142142
|
+
selected2.push(event);
|
|
142143
|
+
}
|
|
142144
|
+
return { status: "ok", events: selected2, cursor: cursor3, more, head: cursorOf(deps.generation, lastSequence) };
|
|
142145
|
+
},
|
|
142146
|
+
onAppend: (listener) => {
|
|
142147
|
+
listeners.add(listener);
|
|
142148
|
+
return () => {
|
|
142149
|
+
listeners.delete(listener);
|
|
142150
|
+
};
|
|
142151
|
+
},
|
|
142152
|
+
close: () => {
|
|
142153
|
+
if (isClosed) {
|
|
142154
|
+
return;
|
|
142155
|
+
}
|
|
142156
|
+
isClosed = true;
|
|
142157
|
+
for (const listener of listeners) {
|
|
142158
|
+
listener();
|
|
142159
|
+
}
|
|
142160
|
+
},
|
|
142161
|
+
closed: () => isClosed
|
|
142162
|
+
};
|
|
142163
|
+
}
|
|
142164
|
+
var RcSessionEventCursorExpiredError = class extends Error {
|
|
142165
|
+
/** The cursor naming the log's newest event at the moment of the refusal: where to resume after once the status read has restated the present. */
|
|
142166
|
+
head;
|
|
142167
|
+
constructor(message, head) {
|
|
142168
|
+
super(message);
|
|
142169
|
+
this.name = "RcSessionEventCursorExpiredError";
|
|
142170
|
+
this.head = head;
|
|
142171
|
+
}
|
|
142172
|
+
};
|
|
142173
|
+
function followRcSessionEvents(log, input2, signal) {
|
|
142174
|
+
return followAfter(log, input2.since ?? log.head(), input2.session, signal);
|
|
142175
|
+
}
|
|
142176
|
+
async function* followAfter(log, since, session, signal) {
|
|
142177
|
+
let cursor3 = since;
|
|
142178
|
+
let onAbort = () => void 0;
|
|
142179
|
+
const aborted2 = new Promise((resolve3) => {
|
|
142180
|
+
onAbort = resolve3;
|
|
142181
|
+
});
|
|
142182
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
142183
|
+
try {
|
|
142184
|
+
for (; ; ) {
|
|
142185
|
+
signal?.throwIfAborted();
|
|
142186
|
+
const closedBeforeRead = log.closed();
|
|
142187
|
+
let detach = () => void 0;
|
|
142188
|
+
const woken = new Promise((resolve3) => {
|
|
142189
|
+
detach = log.onAppend(resolve3);
|
|
142190
|
+
});
|
|
142191
|
+
try {
|
|
142192
|
+
const read = log.read({ since: cursor3, ...session === void 0 ? {} : { session } });
|
|
142193
|
+
if (read.status === "expired") {
|
|
142194
|
+
throw new RcSessionEventCursorExpiredError(read.message, read.head);
|
|
142195
|
+
}
|
|
142196
|
+
if (read.events.length === 0) {
|
|
142197
|
+
cursor3 = read.cursor;
|
|
142198
|
+
if (closedBeforeRead) {
|
|
142199
|
+
return;
|
|
142200
|
+
}
|
|
142201
|
+
await Promise.race([woken, aborted2]);
|
|
142202
|
+
continue;
|
|
142203
|
+
}
|
|
142204
|
+
for (const event of read.events) {
|
|
142205
|
+
yield event;
|
|
142206
|
+
cursor3 = event.cursor;
|
|
142207
|
+
}
|
|
142208
|
+
cursor3 = read.cursor;
|
|
142209
|
+
} finally {
|
|
142210
|
+
detach();
|
|
142211
|
+
}
|
|
142212
|
+
}
|
|
142213
|
+
} finally {
|
|
142214
|
+
signal?.removeEventListener("abort", onAbort);
|
|
142215
|
+
}
|
|
142216
|
+
}
|
|
142217
|
+
|
|
142218
|
+
// src/frontdoor/rcEventLogApi.ts
|
|
142219
|
+
var RC_API_TAG2 = "remote-control";
|
|
142220
|
+
var CURSOR_EXPIRED_CODE = "GONE";
|
|
142221
|
+
async function* sseOf(follower) {
|
|
142222
|
+
try {
|
|
142223
|
+
for await (const event of follower) {
|
|
142224
|
+
yield withEventMeta2(event, { id: event.cursor });
|
|
142225
|
+
}
|
|
142226
|
+
} catch (error63) {
|
|
142227
|
+
if (error63 instanceof RcSessionEventCursorExpiredError) {
|
|
142228
|
+
throw new ORPCError(CURSOR_EXPIRED_CODE, { message: error63.message, data: { head: error63.head } });
|
|
142229
|
+
}
|
|
142230
|
+
throw error63;
|
|
142231
|
+
}
|
|
142232
|
+
}
|
|
142233
|
+
function createRcSessionEventsApiRouter(deps) {
|
|
142234
|
+
const authed = doorApiAuth(deps.expectedToken);
|
|
142235
|
+
return {
|
|
142236
|
+
rcSessions: {
|
|
142237
|
+
events: authed.meta(openapi({ method: "GET", path: "/rest/rc/session-events", summary: "Stream every observed session's state transitions, pending requests and endings (SSE), resumable by cursor", tags: [RC_API_TAG2] })).input(RcSessionEventsStreamInputSchema).output(asyncIteratorObject(RcSessionEventSchema)).handler(({ input: input2, signal, lastEventId }) => sseOf(followRcSessionEvents(deps.sessionEvents, { since: lastEventId ?? input2.since, session: input2.session }, signal))),
|
|
142238
|
+
eventsPage: authed.meta(
|
|
142239
|
+
openapi({
|
|
142240
|
+
method: "POST",
|
|
142241
|
+
path: "/rest/rc/session-events/page",
|
|
142242
|
+
summary: "Read every observed session's state transitions, pending requests and endings after a cursor, one page at a time",
|
|
142243
|
+
tags: [RC_API_TAG2],
|
|
142244
|
+
// A POST because the page size is a number a query string cannot type, but the answer changes nothing.
|
|
142245
|
+
spec: (current) => ({ ...current, [READ_ONLY_OPERATION_EXTENSION]: true })
|
|
142246
|
+
})
|
|
142247
|
+
).input(RcSessionEventsPageInputSchema).output(RcSessionEventsReadOutputSchema).handler(({ input: input2 }) => deps.sessionEvents.read(input2))
|
|
142248
|
+
}
|
|
142249
|
+
};
|
|
142250
|
+
}
|
|
142251
|
+
|
|
142252
|
+
// src/frontdoor/controlApi.ts
|
|
142253
|
+
var USAGE_API_TAG = "usage";
|
|
142254
|
+
var FRONTDOOR_API_TAG2 = "frontdoor";
|
|
142255
|
+
var CHECK_API_TAG = "check";
|
|
142256
|
+
var DOCTOR_API_TAG = "doctor";
|
|
142257
|
+
var POOL_API_TAG = "pool";
|
|
142258
|
+
function createControlApiRouter(deps) {
|
|
142259
|
+
const authed = doorApiAuth(deps.expectedToken);
|
|
142260
|
+
return {
|
|
142261
|
+
usage: {
|
|
142262
|
+
list: authed.meta(openapi({ method: "GET", path: "/rest/usage/snapshots", summary: "List every identity's usage snapshot", tags: [USAGE_API_TAG] })).output(UsageListOutputSchema).handler(() => ({ snapshots: deps.usageSnapshots() })),
|
|
142263
|
+
resets: authed.meta(openapi({ method: "GET", path: "/rest/usage/resets", summary: "List every recorded quota window with when it resets", tags: [USAGE_API_TAG] })).output(ResetScheduleSchema).handler(() => collectResets(deps.usageSnapshots(), deps.now())),
|
|
142264
|
+
effectiveWindow: authed.meta(openapi({ method: "GET", path: "/rest/usage/windows", summary: "Read one identity's effective quota windows", tags: [USAGE_API_TAG] })).input(UsageWindowsInputSchema).output(UsageWindowsOutputSchema).handler(({ input: input2 }) => {
|
|
142265
|
+
const snapshot = deps.usageSnapshotOf(input2.identity);
|
|
142266
|
+
if (snapshot === void 0) {
|
|
142267
|
+
throw new ORPCError("NOT_FOUND", { message: `identity ${input2.identity} has no usage snapshot yet, so no quota window has been observed for it` });
|
|
142268
|
+
}
|
|
142269
|
+
const provider = input2.provider ?? ANTHROPIC_PROVIDER;
|
|
142270
|
+
const rateLimit = snapshot.providers[provider]?.rateLimit;
|
|
142271
|
+
const unified = rateLimit?.unified;
|
|
142272
|
+
const now = deps.now();
|
|
142273
|
+
return {
|
|
142274
|
+
identity: snapshot.identity,
|
|
142275
|
+
provider,
|
|
142276
|
+
...rateLimit === void 0 ? {} : { observedAt: rateLimit.observedAt },
|
|
142277
|
+
...unified?.fiveHour === void 0 ? {} : { fiveHour: effectiveWindow(unified.fiveHour, now) },
|
|
142278
|
+
...unified?.sevenDay === void 0 ? {} : { sevenDay: effectiveWindow(unified.sevenDay, now) }
|
|
142279
|
+
};
|
|
142280
|
+
}),
|
|
142281
|
+
live: authed.meta(openapi({ method: "GET", path: "/rest/usage/live", summary: "Read the live rate-limit observations the event backbone files", tags: [USAGE_API_TAG] })).input(RcSessionQuerySchema).output(UsageLiveOutputSchema).handler(({ input: input2 }) => {
|
|
142282
|
+
const sessions = deps.liveRateLimits(input2.session);
|
|
142283
|
+
if (input2.session !== void 0 && sessions.length === 0) {
|
|
142284
|
+
if (deps.list().some((session) => session.id === input2.session)) {
|
|
142285
|
+
throw new ORPCError("NOT_FOUND", { message: `session ${input2.session} has filed no rate_limit_event on its stream yet: the worker emits one only once a turn has completed, so retry after this session's next turn` });
|
|
142286
|
+
}
|
|
142287
|
+
throw new ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input2.session) });
|
|
142288
|
+
}
|
|
142289
|
+
return { latest: deps.latestRateLimit(), sessions };
|
|
142290
|
+
})
|
|
142291
|
+
},
|
|
142292
|
+
frontdoor: {
|
|
142293
|
+
status: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/status", summary: "Read the front door's status", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorStatusOutputSchema).handler(() => deps.frontDoorStatus()),
|
|
142294
|
+
sessions: authed.meta(openapi({ method: "GET", path: "/rest/frontdoor/sessions", summary: "Read the front door's session registry", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorSessionsOutputSchema).handler(() => ({ sessions: deps.frontDoorStatus().sessions }))
|
|
142295
|
+
},
|
|
142296
|
+
check: {
|
|
142297
|
+
// The report's own JSON shape is the contract (the same one `check --json` prints and `checkReportSchema.ts` defines), so the procedure returns exactly that conversion.
|
|
142298
|
+
run: authed.meta(openapi({ method: "GET", path: "/rest/check", summary: "Run the check report for one directory", tags: [CHECK_API_TAG] })).input(CheckRunInputSchema).output(CheckReportJsonSchema).handler(({ input: input2 }) => checkReportToJson(deps.checkReport(input2.path, input2.identity)))
|
|
142299
|
+
},
|
|
142300
|
+
doctor: {
|
|
142301
|
+
run: authed.meta(openapi({ method: "GET", path: "/rest/doctor", summary: "Run the doctor report", tags: [DOCTOR_API_TAG] })).output(DoctorRunOutputSchema).handler(() => deps.doctorReport())
|
|
142302
|
+
},
|
|
142303
|
+
pool: {
|
|
142304
|
+
pick: authed.meta(openapi({ method: "GET", path: "/rest/pool/pick", summary: "Rank one pool exactly as a launch from a directory would right now", tags: [POOL_API_TAG] })).input(PoolPickInputSchema).output(PoolPickReportSchema).handler(({ input: input2 }) => {
|
|
142305
|
+
const report = deps.poolPick(input2.pool, input2.path);
|
|
142306
|
+
if (report === void 0) {
|
|
142307
|
+
const live = deps.poolNames();
|
|
142308
|
+
throw new ORPCError("NOT_FOUND", {
|
|
142309
|
+
message: live.length === 0 ? `no pools are configured, so none is named ${input2.pool}` : `no pool is named ${input2.pool}; the live pools are ${live.map((name) => `"${name}"`).join(", ")}`
|
|
142310
|
+
});
|
|
142311
|
+
}
|
|
142312
|
+
return report;
|
|
142313
|
+
})
|
|
142314
|
+
}
|
|
142315
|
+
};
|
|
142316
|
+
}
|
|
142317
|
+
function createDoorApiRouter(deps) {
|
|
142318
|
+
const control = createControlApiRouter(deps);
|
|
142319
|
+
const lifecycle = createLifecycleApiRouter(deps);
|
|
142320
|
+
return { ...createRcApiRouter(deps), ...createRcSessionEventsApiRouter(deps), ...control, ...lifecycle, ...createConfigApiRouter(deps), ...createCodexApiRouter(deps), ...createLaunchApiRouter(deps), ...createAgentTreesApiRouter(deps), ...createEventsApiRouter(deps), frontdoor: { ...control.frontdoor, ...lifecycle.frontdoor } };
|
|
142321
|
+
}
|
|
142322
|
+
function createDoorApiNodeHandler(deps) {
|
|
142323
|
+
return doorApiNodeHandlerOf(createDoorApiRouter(deps), deps.expectedToken);
|
|
142324
|
+
}
|
|
142325
|
+
function frontDoorApiClient(port, ca2, token) {
|
|
142326
|
+
return createORPCClient(frontDoorApiLink(port, ca2, token));
|
|
142327
|
+
}
|
|
142328
|
+
|
|
142329
|
+
// src/frontdoor/doorHealthEvents.ts
|
|
142330
|
+
function createDoorHealthPublisher(hub, now, pid) {
|
|
142331
|
+
const publisher = hub.publisher(DOOR_HEALTH_EVENT_SOURCE);
|
|
142332
|
+
return {
|
|
142333
|
+
generation: (ports) => {
|
|
142334
|
+
publisher.publish({ kind: "generation", pid, providerPort: ports.providerPort, connectPort: ports.connectPort, directPort: ports.directPort, observedAt: now() });
|
|
142335
|
+
},
|
|
142336
|
+
listenerFailed: (listener, message) => {
|
|
142337
|
+
publisher.publish({ kind: "listenerFailed", pid, listener, message, observedAt: now() });
|
|
142338
|
+
},
|
|
142339
|
+
idleShutdown: () => {
|
|
142340
|
+
publisher.publish({ kind: "idleShutdown", pid, observedAt: now() });
|
|
142341
|
+
},
|
|
142342
|
+
binaryTurnover: () => {
|
|
142343
|
+
publisher.publish({ kind: "binaryTurnover", pid, observedAt: now() });
|
|
142344
|
+
},
|
|
142345
|
+
superseded: (ownerPid) => {
|
|
142346
|
+
publisher.publish({ kind: "superseded", pid, ownerPid, observedAt: now() });
|
|
142347
|
+
},
|
|
142348
|
+
drained: () => {
|
|
142349
|
+
publisher.publish({ kind: "drained", pid, observedAt: now() });
|
|
142350
|
+
}
|
|
142351
|
+
};
|
|
142352
|
+
}
|
|
142353
|
+
|
|
141868
142354
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
141869
142355
|
init_pick();
|
|
141870
142356
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
@@ -142043,7 +142529,7 @@ init_connect();
|
|
|
142043
142529
|
init_route();
|
|
142044
142530
|
|
|
142045
142531
|
// src/frontdoor/lineage.ts
|
|
142046
|
-
var
|
|
142532
|
+
var import_node_crypto27 = require("node:crypto");
|
|
142047
142533
|
var CACHE_MARKER_KEY = '"cache_control"';
|
|
142048
142534
|
var THREAD_MEMBER_KEYS = /* @__PURE__ */ new Set(['"model"', '"system"', '"tools"']);
|
|
142049
142535
|
var MESSAGES_KEY = '"messages"';
|
|
@@ -142120,8 +142606,8 @@ function nextToken(body, from) {
|
|
|
142120
142606
|
return SCALAR;
|
|
142121
142607
|
}
|
|
142122
142608
|
function walk2(body, hashing, parentAfter) {
|
|
142123
|
-
const thread = (0,
|
|
142124
|
-
const messages = (0,
|
|
142609
|
+
const thread = (0, import_node_crypto27.createHash)("sha256");
|
|
142610
|
+
const messages = (0, import_node_crypto27.createHash)("sha256");
|
|
142125
142611
|
let parentDigest;
|
|
142126
142612
|
let elements = 0;
|
|
142127
142613
|
let depth = 0;
|
|
@@ -142242,7 +142728,7 @@ function lineageOf(body) {
|
|
|
142242
142728
|
}
|
|
142243
142729
|
const parentAfter = counted3.elements > MESSAGES_PER_TURN ? counted3.elements - MESSAGES_PER_TURN : void 0;
|
|
142244
142730
|
const hashed = walk2(body, true, parentAfter);
|
|
142245
|
-
const combine = (messagesDigest) => (0,
|
|
142731
|
+
const combine = (messagesDigest) => (0, import_node_crypto27.createHash)("sha256").update(hashed.threadDigest).update(messagesDigest).digest("hex");
|
|
142246
142732
|
return { ownKey: combine(hashed.messagesDigest), parentKey: hashed.parentDigest === void 0 ? void 0 : combine(hashed.parentDigest) };
|
|
142247
142733
|
}
|
|
142248
142734
|
|
|
@@ -143360,7 +143846,7 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
|
|
|
143360
143846
|
}
|
|
143361
143847
|
|
|
143362
143848
|
// src/antigravity/route.ts
|
|
143363
|
-
var
|
|
143849
|
+
var import_node_crypto28 = require("node:crypto");
|
|
143364
143850
|
init_route();
|
|
143365
143851
|
init_anthropic();
|
|
143366
143852
|
|
|
@@ -143824,7 +144310,7 @@ function exhaustedMessage(exhaustion) {
|
|
|
143824
144310
|
return `Antigravity ${window} limit reached; it resets at ${new Date(exhaustion.resetSec * MS_PER_SECOND13).toISOString()}.`;
|
|
143825
144311
|
}
|
|
143826
144312
|
function createAntigravityRoute(ports) {
|
|
143827
|
-
const fallbackId = ports.fallbackId ?? (() => (0,
|
|
144313
|
+
const fallbackId = ports.fallbackId ?? (() => (0, import_node_crypto28.randomUUID)());
|
|
143828
144314
|
const lastRouted = ports.lastRouted ?? /* @__PURE__ */ new Map();
|
|
143829
144315
|
const exhaustedModels = ports.exhaustedModels ?? /* @__PURE__ */ new Map();
|
|
143830
144316
|
const liveQuota = (nowMs) => {
|
|
@@ -144952,7 +145438,7 @@ function predecessorOfThisProcess() {
|
|
|
144952
145438
|
init_realFrontDoorPort();
|
|
144953
145439
|
|
|
144954
145440
|
// src/frontdoor/rcCommands.ts
|
|
144955
|
-
var
|
|
145441
|
+
var import_node_crypto29 = require("node:crypto");
|
|
144956
145442
|
init_commandDeps();
|
|
144957
145443
|
init_cliError();
|
|
144958
145444
|
init_realPorts();
|
|
@@ -144988,6 +145474,107 @@ function readFrontDoorControlMaterial(fsPort, paths, purpose) {
|
|
|
144988
145474
|
}
|
|
144989
145475
|
return { port: state.port, ca: ca2, token };
|
|
144990
145476
|
}
|
|
145477
|
+
function frontDoorApiFromState(paths, fsPort = realFarmFs) {
|
|
145478
|
+
const { port, ca: ca2, token } = readFrontDoorControlMaterial(fsPort, paths, "its typed API");
|
|
145479
|
+
return frontDoorApiClient(port, ca2, token);
|
|
145480
|
+
}
|
|
145481
|
+
|
|
145482
|
+
// src/frontdoor/rcEventsCommand.ts
|
|
145483
|
+
init_commandDeps();
|
|
145484
|
+
init_cliError();
|
|
145485
|
+
function detailOf(event) {
|
|
145486
|
+
if (event.kind === "session-ended") {
|
|
145487
|
+
return event.reason;
|
|
145488
|
+
}
|
|
145489
|
+
if (event.kind === "worker-state") {
|
|
145490
|
+
return event.previous === void 0 ? event.state : `${event.previous} -> ${event.state}`;
|
|
145491
|
+
}
|
|
145492
|
+
if (event.kind === "pending-born") {
|
|
145493
|
+
return `${event.requestId} ${event.type}${event.summary === "" ? "" : ` ${event.summary}`}`;
|
|
145494
|
+
}
|
|
145495
|
+
if (event.kind === "pending-retired") {
|
|
145496
|
+
return `${event.requestId} ${event.reason}`;
|
|
145497
|
+
}
|
|
145498
|
+
return "";
|
|
145499
|
+
}
|
|
145500
|
+
function formatRcSessionEvent(event) {
|
|
145501
|
+
const detail = detailOf(event);
|
|
145502
|
+
return `${event.cursor} ${new Date(event.at).toISOString()} ${event.session} ${event.kind}${detail === "" ? "" : ` ${detail}`}`;
|
|
145503
|
+
}
|
|
145504
|
+
function expiredHeadOf(error63) {
|
|
145505
|
+
if (!(error63 instanceof ORPCError) || error63.code !== "GONE") {
|
|
145506
|
+
return void 0;
|
|
145507
|
+
}
|
|
145508
|
+
const data = error63.data;
|
|
145509
|
+
return typeof data === "object" && data !== null && "head" in data && typeof data.head === "string" ? data.head : void 0;
|
|
145510
|
+
}
|
|
145511
|
+
var RcSessionEventsStreamEndedError = class extends Error {
|
|
145512
|
+
lastCursor;
|
|
145513
|
+
constructor(cause, lastCursor) {
|
|
145514
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
145515
|
+
this.name = "RcSessionEventsStreamEndedError";
|
|
145516
|
+
this.lastCursor = lastCursor;
|
|
145517
|
+
}
|
|
145518
|
+
};
|
|
145519
|
+
async function printRcSessionEvents(events, options, write) {
|
|
145520
|
+
let last = options.since;
|
|
145521
|
+
try {
|
|
145522
|
+
for await (const event of events) {
|
|
145523
|
+
write(options.json ? JSON.stringify(event) : formatRcSessionEvent(event));
|
|
145524
|
+
last = event.cursor;
|
|
145525
|
+
}
|
|
145526
|
+
} catch (error63) {
|
|
145527
|
+
throw new RcSessionEventsStreamEndedError(error63, last);
|
|
145528
|
+
}
|
|
145529
|
+
return last;
|
|
145530
|
+
}
|
|
145531
|
+
function lastCursorOf(error63, since) {
|
|
145532
|
+
return error63 instanceof RcSessionEventsStreamEndedError ? error63.lastCursor : since;
|
|
145533
|
+
}
|
|
145534
|
+
function resumeHint(lastCursor) {
|
|
145535
|
+
return lastCursor === void 0 ? "no event was printed; follow afresh, or resume after the head `frontdoor rc events` names" : `resume with --since ${lastCursor}`;
|
|
145536
|
+
}
|
|
145537
|
+
function registerRcEventsCommand(rc, paths) {
|
|
145538
|
+
withExamples(
|
|
145539
|
+
rc.command("events").description(
|
|
145540
|
+
"Follow every observed Remote Control session at once: each session appearing or ending, each worker state change (idle, running, requires_action), and each pending control request's birth and retirement, every line tagged with its session and the cursor a later --since resumes after. A cursor the door no longer holds (evicted, or from a previous door) fails naming the head to resume after once `frontdoor rc status` has restated the present. It does not reconnect: when the stream ends or fails (a door restart above all, whose new generation would refuse the cursor anyway), or Ctrl-C leaves it, it names the last cursor printed. Read-only, until Ctrl-C leaves."
|
|
145541
|
+
).argument("[session]", "One cse_ session id, to follow that session alone; every observed session when omitted.").option("--all", "Follow every observed session: the explicit spelling of omitting the session.").option("--since <cursor>", "Resume after this cursor, replaying what was missed; only what happens next when omitted.").option("--json", "Print each event as one JSON line as it arrives.").action(async (session, options) => {
|
|
145542
|
+
if (options.all === true && session !== void 0) {
|
|
145543
|
+
throw new UsageError("name one session or pass --all, not both");
|
|
145544
|
+
}
|
|
145545
|
+
const client = frontDoorApiFromState(paths);
|
|
145546
|
+
const leave = new AbortController();
|
|
145547
|
+
const onInterrupt = () => {
|
|
145548
|
+
leave.abort();
|
|
145549
|
+
};
|
|
145550
|
+
process.once("SIGINT", onInterrupt);
|
|
145551
|
+
try {
|
|
145552
|
+
const stream = await client.rcSessions.events({ ...session === void 0 ? {} : { session }, ...options.since === void 0 ? {} : { since: options.since } }, { signal: leave.signal });
|
|
145553
|
+
const last = await printRcSessionEvents(stream, { json: options.json === true, since: options.since }, (line) => {
|
|
145554
|
+
console.log(line);
|
|
145555
|
+
});
|
|
145556
|
+
console.error(`agent-shim: the event stream ended; ${resumeHint(last)}`);
|
|
145557
|
+
} catch (error63) {
|
|
145558
|
+
if (leave.signal.aborted) {
|
|
145559
|
+
console.error(`agent-shim: left the event stream; ${resumeHint(lastCursorOf(error63, options.since))}`);
|
|
145560
|
+
return;
|
|
145561
|
+
}
|
|
145562
|
+
const cause = error63 instanceof RcSessionEventsStreamEndedError ? error63.cause : error63;
|
|
145563
|
+
const head = expiredHeadOf(cause);
|
|
145564
|
+
if (head !== void 0 && cause instanceof Error) {
|
|
145565
|
+
throw new Error(`${cause.message} (resume with --since ${head})`, { cause: error63 });
|
|
145566
|
+
}
|
|
145567
|
+
if (error63 instanceof RcSessionEventsStreamEndedError) {
|
|
145568
|
+
throw new Error(`${error63.message}; ${resumeHint(error63.lastCursor)}`, { cause: error63 });
|
|
145569
|
+
}
|
|
145570
|
+
throw error63;
|
|
145571
|
+
} finally {
|
|
145572
|
+
process.off("SIGINT", onInterrupt);
|
|
145573
|
+
}
|
|
145574
|
+
}),
|
|
145575
|
+
["agent-shim frontdoor rc events --all", "agent-shim frontdoor rc events --all --since 00000000-0000-4000-8000-000000000000.42 --json"]
|
|
145576
|
+
);
|
|
145577
|
+
}
|
|
144991
145578
|
|
|
144992
145579
|
// src/frontdoor/rcLiveUsage.ts
|
|
144993
145580
|
var RC_RATE_LIMIT_EVENT_TYPE = "rate_limit_event";
|
|
@@ -145553,6 +146140,7 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
145553
146140
|
}),
|
|
145554
146141
|
["agent-shim frontdoor rc watch", "agent-shim frontdoor rc watch cse_00000000-0000-4000-8000-000000000000 --json"]
|
|
145555
146142
|
);
|
|
146143
|
+
registerRcEventsCommand(rc, paths);
|
|
145556
146144
|
const selfhost = withExamples(
|
|
145557
146145
|
rc.command("selfhost").description("Mint the local credential behind the door's self-hosted Remote Control surface: the opt-in mode (AGENT_SHIM_FRONTDOOR_RC_SELF_HOST=1 in the door's environment) where the door serves the CCR surface itself and a session activates Remote Control with no Anthropic credential anywhere."),
|
|
145558
146146
|
["agent-shim frontdoor rc selfhost mint rig"]
|
|
@@ -145564,8 +146152,8 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
145564
146152
|
identitiesDir: paths.identitiesDir,
|
|
145565
146153
|
frontdoorDir: paths.frontdoorDir,
|
|
145566
146154
|
identity,
|
|
145567
|
-
newUuid:
|
|
145568
|
-
randomToken: () => (0,
|
|
146155
|
+
newUuid: import_node_crypto29.randomUUID,
|
|
146156
|
+
randomToken: () => (0, import_node_crypto29.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
145569
146157
|
force: options.force === true,
|
|
145570
146158
|
now: () => Date.now()
|
|
145571
146159
|
});
|
|
@@ -148139,7 +148727,7 @@ function inheritedControlToken(paths) {
|
|
|
148139
148727
|
return token;
|
|
148140
148728
|
}
|
|
148141
148729
|
function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, trackTunnels) {
|
|
148142
|
-
const catalogueGeneration = (0,
|
|
148730
|
+
const catalogueGeneration = (0, import_node_crypto30.randomUUID)();
|
|
148143
148731
|
const log = (line) => {
|
|
148144
148732
|
appendDoorLog(paths, `frontdoor ${String(process.pid)}: ${line}`);
|
|
148145
148733
|
};
|
|
@@ -148172,14 +148760,15 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148172
148760
|
};
|
|
148173
148761
|
const rcSelfHostSurface = rcSelfHost ? createRcSelfHostSurface({
|
|
148174
148762
|
now: () => Date.now(),
|
|
148175
|
-
newUuid:
|
|
148176
|
-
randomToken: () => (0,
|
|
148763
|
+
newUuid: import_node_crypto30.randomUUID,
|
|
148764
|
+
randomToken: () => (0, import_node_crypto30.randomBytes)(MINTED_TOKEN_RANDOM_BYTES).toString("base64url"),
|
|
148177
148765
|
credentialRecord: () => readRcSelfHostRecord(realFarmFs, paths.frontdoorDir),
|
|
148178
148766
|
webFetch: realRcWebFetch({ allowPrivate: rcWebFetchAllowsPrivateFromEnv(process.env) }),
|
|
148179
148767
|
log
|
|
148180
148768
|
}) : void 0;
|
|
148181
148769
|
const rcCredentialStore = createRcCredentialStore(realFarmFs, paths.frontdoorRcCredentialsDir);
|
|
148182
|
-
const
|
|
148770
|
+
const rcSessionEvents = createRcSessionEventLog({ generation: (0, import_node_crypto30.randomUUID)(), capacity: RC_SESSION_EVENT_LOG_CAPACITY });
|
|
148771
|
+
const rcTracker = createRcSessionTracker({ now: () => Date.now(), idleMs: RC_IDLE_EXPIRY_MS, credentialStore: rcCredentialStore, onTransition: rcSessionEvents.append, onClose: rcSessionEvents.close });
|
|
148183
148772
|
const doorEvents = createDoorEventHub();
|
|
148184
148773
|
const usagePublisher = doorEvents.publisher(USAGE_EVENT_SOURCE);
|
|
148185
148774
|
const usageEventNames = createIdentityNameReader(paths);
|
|
@@ -148200,7 +148789,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148200
148789
|
saveSequenceNum: rcCredentialStore.writeCursor,
|
|
148201
148790
|
dial: rcSelfHost ? lateRcStreamDial(rcSelfHostDialTarget) : realRcStreamDial(),
|
|
148202
148791
|
fanout: rcFanout,
|
|
148203
|
-
newClientId:
|
|
148792
|
+
newClientId: import_node_crypto30.randomUUID,
|
|
148204
148793
|
backoffMs: RC_STREAM_BACKOFF_MS,
|
|
148205
148794
|
sleep: async (ms) => {
|
|
148206
148795
|
await new Promise((resolve3) => {
|
|
@@ -148213,7 +148802,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148213
148802
|
});
|
|
148214
148803
|
const observations = createTargetObservationStore(realFarmFs, paths);
|
|
148215
148804
|
const routingSnapshots = /* @__PURE__ */ new Map();
|
|
148216
|
-
const rcControlToken = lifecycle.predecessor === void 0 ? (0,
|
|
148805
|
+
const rcControlToken = lifecycle.predecessor === void 0 ? (0, import_node_crypto30.randomUUID)() : inheritedControlToken(paths);
|
|
148217
148806
|
const sessionRegistry = createLiveSessionRegistry({ fs: realFarmFs, sessionsDir: paths.frontdoorSessionsDir });
|
|
148218
148807
|
const resolveRoute = rcObservingResolver(
|
|
148219
148808
|
createProviderRouteResolver({
|
|
@@ -148390,9 +148979,9 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148390
148979
|
now: () => Date.now(),
|
|
148391
148980
|
headroomSocket: () => headroomSocketTarget(realFarmFs, realHeadroomSocketTrust, paths),
|
|
148392
148981
|
// The per-generation capability the direct listener demands: held only in this process's memory, so a loopback process that discovers the direct port still cannot use it.
|
|
148393
|
-
hopSecret: (0,
|
|
148982
|
+
hopSecret: (0, import_node_crypto30.randomUUID)(),
|
|
148394
148983
|
headroomDecision,
|
|
148395
|
-
custody: createCredentialCustody(() => (0,
|
|
148984
|
+
custody: createCredentialCustody(() => (0, import_node_crypto30.randomUUID)()),
|
|
148396
148985
|
log
|
|
148397
148986
|
});
|
|
148398
148987
|
const onListenerError = (name) => (error63) => {
|
|
@@ -148419,9 +149008,9 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148419
149008
|
startProviderListener: async (source) => {
|
|
148420
149009
|
const authority = loadCa();
|
|
148421
149010
|
const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
|
|
148422
|
-
const rcInject = async (sessionId, text5) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid:
|
|
149011
|
+
const rcInject = async (sessionId, text5) => await injectRcUserMessage({ credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto30.randomUUID }, sessionId, text5);
|
|
148423
149012
|
const rcAnswer = async (sessionId, requestId, decision) => await answerRcControlRequest({ credentialOf: rcTracker.credentialOf, pendingOf: (id2) => rcTracker.pendingOf(id2), completePending: rcTracker.completePending, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial }, sessionId, requestId, decision);
|
|
148424
|
-
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid:
|
|
149013
|
+
const rcControlRequestDeps = { credentialOf: rcTracker.credentialOf, noteSequenceNums: rcTracker.noteSequenceNums, dial: rcDial, newUuid: import_node_crypto30.randomUUID };
|
|
148425
149014
|
const rcInterrupt = async (sessionId) => await interruptRcSession(rcControlRequestDeps, sessionId);
|
|
148426
149015
|
const rcSetModel = async (sessionId, model) => await setRcSessionModel(rcControlRequestDeps, sessionId, model);
|
|
148427
149016
|
const rcSetPermissionMode = async (sessionId, mode) => await setRcSessionPermissionMode(rcControlRequestDeps, sessionId, mode);
|
|
@@ -148509,6 +149098,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148509
149098
|
mcpOAuthCallbackUrl: rcMcpOAuthCallbackUrl,
|
|
148510
149099
|
teleport: rcTeleport,
|
|
148511
149100
|
fanout: rcFanout,
|
|
149101
|
+
sessionEvents: rcSessionEvents,
|
|
148512
149102
|
...controlDeps,
|
|
148513
149103
|
...lifecycleAndCodexDeps,
|
|
148514
149104
|
keychain: doorKeychainProbe(process.platform),
|
|
@@ -148532,7 +149122,7 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148532
149122
|
},
|
|
148533
149123
|
startConnectListener: async (source) => {
|
|
148534
149124
|
const wantedTransparentPort = process.env.AGENT_SHIM_TRANSPARENT_SURFACE === void 0 ? void 0 : Number(process.env.AGENT_SHIM_TRANSPARENT_SURFACE);
|
|
148535
|
-
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0,
|
|
149125
|
+
const transparentCapability = wantedTransparentPort === void 0 || Number.isNaN(wantedTransparentPort) ? void 0 : (0, import_node_crypto30.randomUUID)();
|
|
148536
149126
|
if (transparentCapability !== void 0) {
|
|
148537
149127
|
writeFrontDoorSession(realFarmFs, paths.frontdoorSessionsDir, { pid: process.pid, startedAt: Date.now(), token: transparentCapability });
|
|
148538
149128
|
}
|
|
@@ -148614,7 +149204,11 @@ function realFrontDoorSupervisorPorts(paths, respawnGeneration, lifecycle, track
|
|
|
148614
149204
|
});
|
|
148615
149205
|
return { port: handle.port, listening: server, close: handle.close, drain: handle.drain };
|
|
148616
149206
|
},
|
|
148617
|
-
|
|
149207
|
+
// The tracker closes with the hub: its close ends every session-events follower, so a supervisor's open stream ends with the door instead of holding a retiring door's drain open for as long as the subscriber stays connected.
|
|
149208
|
+
closeRcStreamHub: () => {
|
|
149209
|
+
rcHub.close();
|
|
149210
|
+
rcTracker.close();
|
|
149211
|
+
},
|
|
148618
149212
|
respawnChain: {
|
|
148619
149213
|
generation: respawnGeneration,
|
|
148620
149214
|
startNext: async () => {
|
|
@@ -150120,14 +150714,14 @@ init_zod();
|
|
|
150120
150714
|
init_schema2();
|
|
150121
150715
|
|
|
150122
150716
|
// src/statusline/cacheFile.ts
|
|
150123
|
-
var
|
|
150717
|
+
var import_node_crypto31 = require("node:crypto");
|
|
150124
150718
|
var import_node_path73 = __toESM(require("node:path"), 1);
|
|
150125
150719
|
var SESSION_CACHE_DIRECTORY = "session";
|
|
150126
150720
|
function cacheDirectory(ports) {
|
|
150127
150721
|
return import_node_path73.default.join(ports.stateDirectory, SESSION_CACHE_DIRECTORY);
|
|
150128
150722
|
}
|
|
150129
150723
|
function cacheFileFor(ports, kind, transcriptPath) {
|
|
150130
|
-
return import_node_path73.default.join(cacheDirectory(ports), `${kind}-${(0,
|
|
150724
|
+
return import_node_path73.default.join(cacheDirectory(ports), `${kind}-${(0, import_node_crypto31.createHash)("sha256").update(transcriptPath).digest("hex")}.json`);
|
|
150131
150725
|
}
|
|
150132
150726
|
function transcriptKeyOf(ports, transcriptPath) {
|
|
150133
150727
|
const trimmed = transcriptPath.trim();
|
|
@@ -152427,11 +153021,11 @@ function compactUnits(rows, barCells) {
|
|
|
152427
153021
|
}
|
|
152428
153022
|
|
|
152429
153023
|
// src/statusline/transcript/reader.ts
|
|
152430
|
-
var
|
|
153024
|
+
var import_node_crypto33 = require("node:crypto");
|
|
152431
153025
|
init_zod();
|
|
152432
153026
|
|
|
152433
153027
|
// src/statusline/transcript/activity.ts
|
|
152434
|
-
var
|
|
153028
|
+
var import_node_crypto32 = require("node:crypto");
|
|
152435
153029
|
init_zod();
|
|
152436
153030
|
init_graphemes();
|
|
152437
153031
|
|
|
@@ -152751,7 +153345,7 @@ function foldTodoCall(state, call2) {
|
|
|
152751
153345
|
return { ...state, todos: state.todos.map((item, at2) => at2 === index ? updated : item), todosEdited: true };
|
|
152752
153346
|
}
|
|
152753
153347
|
function digestOf(id2) {
|
|
152754
|
-
return (0,
|
|
153348
|
+
return (0, import_node_crypto32.createHash)("sha256").update(id2).digest("base64url").slice(0, CALL_DIGEST_CHARS);
|
|
152755
153349
|
}
|
|
152756
153350
|
function timeKeyOf(atMs) {
|
|
152757
153351
|
const key = atMs === void 0 || atMs < 0 ? "" : atMs.toString(CALL_TIME_RADIX);
|
|
@@ -152762,8 +153356,8 @@ function isRemembered(state, id2, atMs) {
|
|
|
152762
153356
|
if (atMs !== void 0 && state.forgottenUpToMs !== void 0 && atMs <= state.forgottenUpToMs) {
|
|
152763
153357
|
return true;
|
|
152764
153358
|
}
|
|
152765
|
-
const
|
|
152766
|
-
return state.rememberedCalls.some((entry) => entry.startsWith(
|
|
153359
|
+
const digest3 = digestOf(id2);
|
|
153360
|
+
return state.rememberedCalls.some((entry) => entry.startsWith(digest3)) || state.skippedCalls.some((entry) => entry.startsWith(digest3));
|
|
152767
153361
|
}
|
|
152768
153362
|
function beyondFloor(entries, floorMs) {
|
|
152769
153363
|
return entries.filter((entry) => floorMs === void 0 || Number.parseInt(timeKeyOfEntry(entry), CALL_TIME_RADIX) > floorMs);
|
|
@@ -152916,14 +153510,14 @@ function withName(set3, name) {
|
|
|
152916
153510
|
if (set3.others.length === 0 && set3.names.reduce((total, kept) => total + nameBytes(kept), nameBytes(name)) <= NAME_MEMORY_BYTES) {
|
|
152917
153511
|
return { ...set3, names: [...set3.names, name] };
|
|
152918
153512
|
}
|
|
152919
|
-
const
|
|
152920
|
-
if (set3.others.includes(
|
|
153513
|
+
const digest3 = digestOf(name);
|
|
153514
|
+
if (set3.others.includes(digest3)) {
|
|
152921
153515
|
return set3;
|
|
152922
153516
|
}
|
|
152923
153517
|
if (set3.others.length >= MAX_COUNTED_NAMES) {
|
|
152924
153518
|
return set3.overflowed === true ? set3 : { ...set3, overflowed: true };
|
|
152925
153519
|
}
|
|
152926
|
-
return { ...set3, others: [...set3.others,
|
|
153520
|
+
return { ...set3, others: [...set3.others, digest3] };
|
|
152927
153521
|
}
|
|
152928
153522
|
function foldActivityCumulative(state, record3) {
|
|
152929
153523
|
const content = record3.message?.content;
|
|
@@ -153158,7 +153752,7 @@ function foldLines(state, bytes) {
|
|
|
153158
153752
|
}
|
|
153159
153753
|
function fingerprintOf(head) {
|
|
153160
153754
|
const newline = head.subarray(0, FINGERPRINT_BYTES).indexOf(NEWLINE2);
|
|
153161
|
-
return (0,
|
|
153755
|
+
return (0, import_node_crypto33.createHash)("sha256").update(head.subarray(0, newline === -1 ? FINGERPRINT_BYTES : newline + 1)).digest("hex");
|
|
153162
153756
|
}
|
|
153163
153757
|
function factsOf(size, cache, reachedEnd, nowMs, env) {
|
|
153164
153758
|
return { bytes: size, complete: cache.complete && reachedEnd, session: sessionFactsOf(cache.session, cache.newer?.state), tokens: cache.tokens.totals, activity: activityFactsOf(cache.activity, nowMs, { bashMs: bashLiveLimitMs(env) }, cache.newer?.activity) };
|
|
@@ -165902,7 +166496,7 @@ function registerRuleCommand(program2, deps) {
|
|
|
165902
166496
|
}
|
|
165903
166497
|
|
|
165904
166498
|
// src/codex/launch.ts
|
|
165905
|
-
var
|
|
166499
|
+
var import_node_crypto34 = require("node:crypto");
|
|
165906
166500
|
var import_node_fs37 = __toESM(require("node:fs"), 1);
|
|
165907
166501
|
var import_node_os23 = __toESM(require("node:os"), 1);
|
|
165908
166502
|
var import_node_path90 = __toESM(require("node:path"), 1);
|
|
@@ -166106,7 +166700,7 @@ async function runCodex(paths, argv) {
|
|
|
166106
166700
|
}
|
|
166107
166701
|
throw new UsageError("No real Codex CLI found on PATH. Install Codex or set AGENT_SHIM_CODEX_BIN to its executable.");
|
|
166108
166702
|
};
|
|
166109
|
-
const plan = prepareCodexLaunch({ paths, argv, env: process.env, cwd: import_node_fs37.default.realpathSync(process.cwd()), home: import_node_os23.default.homedir(), fs: realFarmFs, read: cosmiconfigReader(), resolveBinary, now: Date.now, pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync, uniqueSuffix: `${String(process.pid)}.${(0,
|
|
166703
|
+
const plan = prepareCodexLaunch({ paths, argv, env: process.env, cwd: import_node_fs37.default.realpathSync(process.cwd()), home: import_node_os23.default.homedir(), fs: realFarmFs, read: cosmiconfigReader(), resolveBinary, now: Date.now, pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync, uniqueSuffix: `${String(process.pid)}.${(0, import_node_crypto34.randomUUID)()}`, warn: (message) => {
|
|
166110
166704
|
console.error(`agent-shim: ${message}`);
|
|
166111
166705
|
}, ...resolveGitBranch(realRunPort, process.cwd()) });
|
|
166112
166706
|
import_node_fs37.default.chmodSync(plan.env.CODEX_HOME ?? "", PRIVATE_DIRECTORY_MODE);
|
|
@@ -166854,7 +167448,7 @@ async function realRefresher(params) {
|
|
|
166854
167448
|
}
|
|
166855
167449
|
|
|
166856
167450
|
// src/supervise/launch.ts
|
|
166857
|
-
var
|
|
167451
|
+
var import_node_crypto36 = require("node:crypto");
|
|
166858
167452
|
var import_node_fs40 = require("node:fs");
|
|
166859
167453
|
var import_node_path97 = __toESM(require("node:path"), 1);
|
|
166860
167454
|
var import_promises21 = require("node:stream/promises");
|
|
@@ -167089,7 +167683,7 @@ function createLifecycleRecorder(params) {
|
|
|
167089
167683
|
}
|
|
167090
167684
|
|
|
167091
167685
|
// src/supervise/nativeCompact.ts
|
|
167092
|
-
var
|
|
167686
|
+
var import_node_crypto35 = require("node:crypto");
|
|
167093
167687
|
var import_node_fs38 = require("node:fs");
|
|
167094
167688
|
var import_promises20 = require("node:timers/promises");
|
|
167095
167689
|
var RESULT_POLL_MS = 250;
|
|
@@ -167099,7 +167693,7 @@ function nativeCompactionReady(plugin) {
|
|
|
167099
167693
|
async function compactInSession(plugin, conversationId, signal) {
|
|
167100
167694
|
if (!nativeCompactionReady(plugin)) throw new Error("the in-process compaction plugin did not load");
|
|
167101
167695
|
signal.throwIfAborted();
|
|
167102
|
-
const id2 = (0,
|
|
167696
|
+
const id2 = (0, import_node_crypto35.randomUUID)();
|
|
167103
167697
|
const temporary = `${plugin.request}.${id2}`;
|
|
167104
167698
|
(0, import_node_fs38.writeFileSync)(temporary, JSON.stringify({ id: id2, conversationId }), { mode: 384 });
|
|
167105
167699
|
(0, import_node_fs38.renameSync)(temporary, plugin.request);
|
|
@@ -167760,21 +168354,21 @@ async function runSupervised(params) {
|
|
|
167760
168354
|
log.warn(`agent-shim: pool "${pool}" cannot supervise a launch whose extra flags end option parsing`);
|
|
167761
168355
|
return void 0;
|
|
167762
168356
|
}
|
|
167763
|
-
const first = initialConversationOf(params.passthrough, { newId:
|
|
168357
|
+
const first = initialConversationOf(params.passthrough, { newId: import_node_crypto36.randomUUID, latestId: () => latestConversationId(farm.fs, { claudeHome: farm.claudeHome, cwd: farm.cwd }) });
|
|
167764
168358
|
if ("reason" in first) {
|
|
167765
168359
|
log.warn(`agent-shim: pool "${pool}" resumes on a spent quota, but this launch runs unsupervised: ${first.reason}`);
|
|
167766
168360
|
return void 0;
|
|
167767
168361
|
}
|
|
167768
168362
|
let entrypointSha256AtStart;
|
|
167769
168363
|
try {
|
|
167770
|
-
const hash2 = (0,
|
|
168364
|
+
const hash2 = (0, import_node_crypto36.createHash)("sha256");
|
|
167771
168365
|
await (0, import_promises21.pipeline)((0, import_node_fs40.createReadStream)(realContentSourcePath()), hash2);
|
|
167772
168366
|
entrypointSha256AtStart = hash2.digest("hex");
|
|
167773
168367
|
} catch {
|
|
167774
168368
|
entrypointSha256AtStart = null;
|
|
167775
168369
|
log.warn("agent-shim: could not fingerprint the supervisor entrypoint");
|
|
167776
168370
|
}
|
|
167777
|
-
const lifecycle = createLifecycleRecorder({ fs: realFarmFs, logsDir: paths.logsDir, fileId: (0,
|
|
168371
|
+
const lifecycle = createLifecycleRecorder({ fs: realFarmFs, logsDir: paths.logsDir, fileId: (0, import_node_crypto36.randomUUID)(), sessionId: first.sessionId, supervisorPid: farm.lock.pid, supervisorVersion: package_default.version, entrypointSha256AtStart, now: farm.now, log });
|
|
167778
168372
|
let compaction;
|
|
167779
168373
|
const policy = params.pools[pool];
|
|
167780
168374
|
const markSettings = markHooksSettings(selfInvocation([]), paths.root, pool, first.sessionId);
|