agent-shim 11.82.0 → 11.83.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 +3 -2
- package/dist/cli.cjs +7671 -4330
- package/dist/index.cjs +1357 -862
- package/dist/index.mjs +1343 -849
- package/dist/types/index.d.ts +166 -97
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1300,7 +1300,7 @@ function parseIgnoringUnrecognisedKeys(schema, raw) {
|
|
|
1300
1300
|
return second.success ? { success: true, data: second.data, ignored } : { success: false, issues: second.error.issues };
|
|
1301
1301
|
}
|
|
1302
1302
|
function describeIgnoredKeys(filePath, ignored) {
|
|
1303
|
-
const places = ignored.map(({ path:
|
|
1303
|
+
const places = ignored.map(({ path: path45, keys }) => `${path45.length === 0 ? "" : `${path45.map(String).join(".")}.`}${keys.join(", ")}`);
|
|
1304
1304
|
return `${filePath} has settings this version of agent-shim does not know and ignores: ${places.join("; ")}. A newer release may read them.`;
|
|
1305
1305
|
}
|
|
1306
1306
|
function noteIgnoredKeys(filePath, ignored) {
|
|
@@ -1322,9 +1322,9 @@ function restoreIgnoredKeys(filePath, value) {
|
|
|
1322
1322
|
return value;
|
|
1323
1323
|
}
|
|
1324
1324
|
const restored = structuredClone(value);
|
|
1325
|
-
for (const { path:
|
|
1325
|
+
for (const { path: path45, values } of ignored) {
|
|
1326
1326
|
let holder = restored;
|
|
1327
|
-
for (const step of
|
|
1327
|
+
for (const step of path45) {
|
|
1328
1328
|
holder = isRecord(holder) ? holder[step] : void 0;
|
|
1329
1329
|
}
|
|
1330
1330
|
if (isRecord(holder)) {
|
|
@@ -1371,6 +1371,12 @@ function captureRuleEntryOrders(value) {
|
|
|
1371
1371
|
}
|
|
1372
1372
|
return rules.map((rule) => captureEntryOrder(rule));
|
|
1373
1373
|
}
|
|
1374
|
+
function unparseableFile(error, filepath) {
|
|
1375
|
+
if (error instanceof SyntaxError) {
|
|
1376
|
+
return new ConfigFileNotJsonError(filepath);
|
|
1377
|
+
}
|
|
1378
|
+
return error instanceof Error && error.name === "YAMLException" ? new ConfigFileNotJsonError(filepath, "YAML") : void 0;
|
|
1379
|
+
}
|
|
1374
1380
|
function cosmiconfigReader(explorer = createExplorer()) {
|
|
1375
1381
|
return (filepath) => {
|
|
1376
1382
|
let result;
|
|
@@ -1381,7 +1387,7 @@ function cosmiconfigReader(explorer = createExplorer()) {
|
|
|
1381
1387
|
if (code === "ENOENT") {
|
|
1382
1388
|
return void 0;
|
|
1383
1389
|
}
|
|
1384
|
-
throw error;
|
|
1390
|
+
throw unparseableFile(error, filepath) ?? error;
|
|
1385
1391
|
}
|
|
1386
1392
|
if (result === null || result.isEmpty === true) {
|
|
1387
1393
|
return void 0;
|
|
@@ -1406,7 +1412,7 @@ function loadConfigFile(filepath, schema, read = cosmiconfigReader()) {
|
|
|
1406
1412
|
ruleEntryOrders: captureRuleEntryOrders(raw)
|
|
1407
1413
|
};
|
|
1408
1414
|
}
|
|
1409
|
-
var import_cosmiconfig, ConfigValidationError;
|
|
1415
|
+
var import_cosmiconfig, ConfigValidationError, ConfigFileNotJsonError;
|
|
1410
1416
|
var init_load = __esm({
|
|
1411
1417
|
"src/config/load.ts"() {
|
|
1412
1418
|
"use strict";
|
|
@@ -1425,6 +1431,16 @@ ${detail}`);
|
|
|
1425
1431
|
filepath;
|
|
1426
1432
|
issues;
|
|
1427
1433
|
};
|
|
1434
|
+
ConfigFileNotJsonError = class extends CliError {
|
|
1435
|
+
constructor(filepath, format = "JSON") {
|
|
1436
|
+
super(`${filepath} is not valid ${format}.`);
|
|
1437
|
+
this.filepath = filepath;
|
|
1438
|
+
this.format = format;
|
|
1439
|
+
this.name = "ConfigFileNotJsonError";
|
|
1440
|
+
}
|
|
1441
|
+
filepath;
|
|
1442
|
+
format;
|
|
1443
|
+
};
|
|
1428
1444
|
}
|
|
1429
1445
|
});
|
|
1430
1446
|
|
|
@@ -1437,7 +1453,12 @@ function readJson(filePath, schema, storeFs = nodeStoreFs) {
|
|
|
1437
1453
|
if (raw === void 0) {
|
|
1438
1454
|
return void 0;
|
|
1439
1455
|
}
|
|
1440
|
-
|
|
1456
|
+
let parsed;
|
|
1457
|
+
try {
|
|
1458
|
+
parsed = JSON.parse(raw);
|
|
1459
|
+
} catch (error) {
|
|
1460
|
+
throw error instanceof SyntaxError ? new ConfigFileNotJsonError(filePath) : error;
|
|
1461
|
+
}
|
|
1441
1462
|
const result = parseIgnoringUnrecognisedKeys(schema, parsed);
|
|
1442
1463
|
if (!result.success) {
|
|
1443
1464
|
throw new ConfigValidationError(filePath, result.issues);
|
|
@@ -2943,6 +2964,14 @@ function acquireIdentityLock(params) {
|
|
|
2943
2964
|
return {
|
|
2944
2965
|
path: lockPath,
|
|
2945
2966
|
token,
|
|
2967
|
+
refresh: () => {
|
|
2968
|
+
const current = parseLockRecord(params.fs.readFileUtf8(lockPath));
|
|
2969
|
+
if (current?.token !== token) {
|
|
2970
|
+
throw new IdentityLockLostError(params.identity);
|
|
2971
|
+
}
|
|
2972
|
+
params.fs.writeFilePrivate(lockPath, `${JSON.stringify({ ...current, acquiredAtMs: params.nowMs() })}
|
|
2973
|
+
`);
|
|
2974
|
+
},
|
|
2946
2975
|
release: () => {
|
|
2947
2976
|
const current = parseLockRecord(params.fs.readFileUtf8(lockPath));
|
|
2948
2977
|
if (current !== void 0 && current.token !== token) {
|
|
@@ -2952,7 +2981,19 @@ function acquireIdentityLock(params) {
|
|
|
2952
2981
|
}
|
|
2953
2982
|
};
|
|
2954
2983
|
}
|
|
2955
|
-
const
|
|
2984
|
+
const raw = params.fs.readFileUtf8(lockPath);
|
|
2985
|
+
if (raw === void 0) {
|
|
2986
|
+
continue;
|
|
2987
|
+
}
|
|
2988
|
+
let existing = parseLockRecord(raw);
|
|
2989
|
+
if (existing === void 0) {
|
|
2990
|
+
params.sleep(retryDelayMs);
|
|
2991
|
+
const again = params.fs.readFileUtf8(lockPath);
|
|
2992
|
+
if (again === void 0) {
|
|
2993
|
+
continue;
|
|
2994
|
+
}
|
|
2995
|
+
existing = parseLockRecord(again);
|
|
2996
|
+
}
|
|
2956
2997
|
if (existing === void 0) {
|
|
2957
2998
|
params.fs.removeRecursive(lockPath);
|
|
2958
2999
|
continue;
|
|
@@ -2967,7 +3008,7 @@ function acquireIdentityLock(params) {
|
|
|
2967
3008
|
}
|
|
2968
3009
|
throw new IdentityLockBusyError(params.identity, lockPath, lastHolderPid);
|
|
2969
3010
|
}
|
|
2970
|
-
var import_node_crypto2, import_node_path7, DEFAULT_STALE_AFTER_MS, DEFAULT_RETRY_DELAY_MS, DEFAULT_MAX_ATTEMPTS, IdentityLockBusyError;
|
|
3011
|
+
var import_node_crypto2, import_node_path7, DEFAULT_STALE_AFTER_MS, DEFAULT_RETRY_DELAY_MS, DEFAULT_MAX_ATTEMPTS, IdentityLockLostError, IdentityLockBusyError;
|
|
2971
3012
|
var init_lock = __esm({
|
|
2972
3013
|
"src/launcher/lock.ts"() {
|
|
2973
3014
|
"use strict";
|
|
@@ -2977,6 +3018,14 @@ var init_lock = __esm({
|
|
|
2977
3018
|
DEFAULT_STALE_AFTER_MS = 12e4;
|
|
2978
3019
|
DEFAULT_RETRY_DELAY_MS = 50;
|
|
2979
3020
|
DEFAULT_MAX_ATTEMPTS = 200;
|
|
3021
|
+
IdentityLockLostError = class extends CliError {
|
|
3022
|
+
constructor(identity) {
|
|
3023
|
+
super(`The lock on identity "${identity}" was taken over by another process while it was held, so nothing it guards can be assumed unchanged.`);
|
|
3024
|
+
this.identity = identity;
|
|
3025
|
+
this.name = "IdentityLockLostError";
|
|
3026
|
+
}
|
|
3027
|
+
identity;
|
|
3028
|
+
};
|
|
2980
3029
|
IdentityLockBusyError = class extends CliError {
|
|
2981
3030
|
constructor(identity, lockPath, holderPid) {
|
|
2982
3031
|
super(
|
|
@@ -2995,8 +3044,8 @@ var init_lock = __esm({
|
|
|
2995
3044
|
});
|
|
2996
3045
|
|
|
2997
3046
|
// src/launcher/farm.ts
|
|
2998
|
-
function readFarmManifest(
|
|
2999
|
-
const raw =
|
|
3047
|
+
function readFarmManifest(fs15, farmRoot) {
|
|
3048
|
+
const raw = fs15.readFileUtf8(import_node_path8.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs15.readFileUtf8(import_node_path8.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
|
|
3000
3049
|
if (raw === void 0) {
|
|
3001
3050
|
return void 0;
|
|
3002
3051
|
}
|
|
@@ -3054,9 +3103,9 @@ function buildEntryFacts(params) {
|
|
|
3054
3103
|
entries
|
|
3055
3104
|
};
|
|
3056
3105
|
}
|
|
3057
|
-
function listSubtree(
|
|
3106
|
+
function listSubtree(fs15, root, rel) {
|
|
3058
3107
|
const absolute = import_node_path8.default.join(root, rel);
|
|
3059
|
-
const stat =
|
|
3108
|
+
const stat = fs15.lstat(absolute);
|
|
3060
3109
|
if (stat === void 0) {
|
|
3061
3110
|
return [];
|
|
3062
3111
|
}
|
|
@@ -3064,10 +3113,10 @@ function listSubtree(fs14, root, rel) {
|
|
|
3064
3113
|
return [{ rel, kind: "symlink" }];
|
|
3065
3114
|
}
|
|
3066
3115
|
if (stat.kind === "dir") {
|
|
3067
|
-
const children = [...
|
|
3116
|
+
const children = [...fs15.readdir(absolute)].sort().flatMap((name) => listSubtree(fs15, root, `${rel}/${name}`));
|
|
3068
3117
|
return [{ rel, kind: "dir" }, ...children];
|
|
3069
3118
|
}
|
|
3070
|
-
const contentHash =
|
|
3119
|
+
const contentHash = fs15.hashFile(absolute);
|
|
3071
3120
|
return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
|
|
3072
3121
|
}
|
|
3073
3122
|
function topLevelScopeRoots(roots) {
|
|
@@ -3081,25 +3130,25 @@ function topLevelScopeRoots(roots) {
|
|
|
3081
3130
|
}
|
|
3082
3131
|
return kept;
|
|
3083
3132
|
}
|
|
3084
|
-
function reconciliationScope(
|
|
3133
|
+
function reconciliationScope(fs15, farmRoot, manifest) {
|
|
3085
3134
|
if (manifest !== void 0) {
|
|
3086
3135
|
return topLevelScopeRoots(manifest.materialised);
|
|
3087
3136
|
}
|
|
3088
|
-
return [...
|
|
3137
|
+
return [...fs15.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs15.lstat(import_node_path8.default.join(farmRoot, name))?.kind === "dir").sort();
|
|
3089
3138
|
}
|
|
3090
|
-
function collectFarmListing(
|
|
3091
|
-
return scopeRoots.flatMap((root) => listSubtree(
|
|
3139
|
+
function collectFarmListing(fs15, farmRoot, scopeRoots) {
|
|
3140
|
+
return scopeRoots.flatMap((root) => listSubtree(fs15, farmRoot, root));
|
|
3092
3141
|
}
|
|
3093
|
-
function collectCanonicalCounterparts(
|
|
3142
|
+
function collectCanonicalCounterparts(fs15, claudeHome, farmListing) {
|
|
3094
3143
|
const out = [];
|
|
3095
3144
|
for (const entry of farmListing) {
|
|
3096
3145
|
const absolute = import_node_path8.default.join(claudeHome, entry.rel);
|
|
3097
|
-
const stat =
|
|
3146
|
+
const stat = fs15.lstat(absolute);
|
|
3098
3147
|
if (stat === void 0) {
|
|
3099
3148
|
continue;
|
|
3100
3149
|
}
|
|
3101
3150
|
if (stat.kind === "file") {
|
|
3102
|
-
const contentHash =
|
|
3151
|
+
const contentHash = fs15.hashFile(absolute);
|
|
3103
3152
|
out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
|
|
3104
3153
|
continue;
|
|
3105
3154
|
}
|
|
@@ -3341,6 +3390,9 @@ function resyncFarm(params) {
|
|
|
3341
3390
|
farmRoot,
|
|
3342
3391
|
classification: params.classification
|
|
3343
3392
|
});
|
|
3393
|
+
if (params.identityExists?.() === false) {
|
|
3394
|
+
throw new IdentityGoneError(params.identity);
|
|
3395
|
+
}
|
|
3344
3396
|
const previousManifest = readFarmManifest(params.fs, farmRoot);
|
|
3345
3397
|
const scope = reconciliationScope(params.fs, farmRoot, previousManifest);
|
|
3346
3398
|
const farmListing = collectFarmListing(params.fs, farmRoot, scope);
|
|
@@ -3456,7 +3508,7 @@ function recoveryDiagnostics(recovery, identity) {
|
|
|
3456
3508
|
}
|
|
3457
3509
|
];
|
|
3458
3510
|
}
|
|
3459
|
-
var import_node_path8, import_zod4, FARM_MANIFEST_FILENAME, FarmManifestSchema;
|
|
3511
|
+
var import_node_path8, import_zod4, FARM_MANIFEST_FILENAME, FarmManifestSchema, IdentityGoneError;
|
|
3460
3512
|
var init_farm = __esm({
|
|
3461
3513
|
"src/launcher/farm.ts"() {
|
|
3462
3514
|
"use strict";
|
|
@@ -3465,6 +3517,7 @@ var init_farm = __esm({
|
|
|
3465
3517
|
init_classify();
|
|
3466
3518
|
init_reconcile();
|
|
3467
3519
|
init_pipeline();
|
|
3520
|
+
init_cliError();
|
|
3468
3521
|
init_legacy();
|
|
3469
3522
|
init_lock();
|
|
3470
3523
|
FARM_MANIFEST_FILENAME = ".agent-shim-farm.json";
|
|
@@ -3478,6 +3531,14 @@ var init_farm = __esm({
|
|
|
3478
3531
|
materialised: import_zod4.z.array(import_zod4.z.string()),
|
|
3479
3532
|
links: import_zod4.z.array(import_zod4.z.strictObject({ rel: import_zod4.z.string(), target: import_zod4.z.string() }))
|
|
3480
3533
|
});
|
|
3534
|
+
IdentityGoneError = class extends CliError {
|
|
3535
|
+
constructor(identity) {
|
|
3536
|
+
super(`Identity "${identity}" no longer exists: it was renamed or removed while this launch waited for it. Launch it under its current name.`);
|
|
3537
|
+
this.identity = identity;
|
|
3538
|
+
this.name = "IdentityGoneError";
|
|
3539
|
+
}
|
|
3540
|
+
identity;
|
|
3541
|
+
};
|
|
3481
3542
|
}
|
|
3482
3543
|
});
|
|
3483
3544
|
|
|
@@ -3870,10 +3931,10 @@ var init_route = __esm({
|
|
|
3870
3931
|
});
|
|
3871
3932
|
|
|
3872
3933
|
// src/frontdoor/state.ts
|
|
3873
|
-
function readFrontDoorState(
|
|
3934
|
+
function readFrontDoorState(fs15, stateFile) {
|
|
3874
3935
|
let raw;
|
|
3875
3936
|
try {
|
|
3876
|
-
raw =
|
|
3937
|
+
raw = fs15.readFileUtf8(stateFile);
|
|
3877
3938
|
} catch {
|
|
3878
3939
|
return void 0;
|
|
3879
3940
|
}
|
|
@@ -3887,9 +3948,9 @@ function readFrontDoorState(fs14, stateFile) {
|
|
|
3887
3948
|
return void 0;
|
|
3888
3949
|
}
|
|
3889
3950
|
}
|
|
3890
|
-
function writeFrontDoorState(
|
|
3891
|
-
|
|
3892
|
-
|
|
3951
|
+
function writeFrontDoorState(fs15, stateFile, state) {
|
|
3952
|
+
fs15.mkdirp(import_node_path9.default.dirname(stateFile));
|
|
3953
|
+
fs15.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
3893
3954
|
`);
|
|
3894
3955
|
}
|
|
3895
3956
|
function directOrigin(port) {
|
|
@@ -3899,37 +3960,37 @@ function frontDoorOrigin(state) {
|
|
|
3899
3960
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
3900
3961
|
return port === void 0 ? void 0 : directOrigin(port);
|
|
3901
3962
|
}
|
|
3902
|
-
function writeFrontDoorDirectRecord(
|
|
3903
|
-
|
|
3904
|
-
|
|
3963
|
+
function writeFrontDoorDirectRecord(fs15, recordsDir, record) {
|
|
3964
|
+
fs15.mkdirp(recordsDir);
|
|
3965
|
+
fs15.writeFilePrivate(import_node_path9.default.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
|
|
3905
3966
|
`);
|
|
3906
3967
|
}
|
|
3907
|
-
function removeFrontDoorDirectRecord(
|
|
3908
|
-
|
|
3968
|
+
function removeFrontDoorDirectRecord(fs15, recordsDir, pid) {
|
|
3969
|
+
fs15.removeRecursive(import_node_path9.default.join(recordsDir, `${String(pid)}.json`));
|
|
3909
3970
|
}
|
|
3910
|
-
function markFrontDoorDraining(
|
|
3911
|
-
|
|
3912
|
-
|
|
3971
|
+
function markFrontDoorDraining(fs15, markersDir, pid) {
|
|
3972
|
+
fs15.mkdirp(markersDir);
|
|
3973
|
+
fs15.writeFilePrivate(import_node_path9.default.join(markersDir, String(pid)), "\n");
|
|
3913
3974
|
}
|
|
3914
|
-
function unmarkFrontDoorDraining(
|
|
3915
|
-
|
|
3975
|
+
function unmarkFrontDoorDraining(fs15, markersDir, pid) {
|
|
3976
|
+
fs15.removeRecursive(import_node_path9.default.join(markersDir, String(pid)));
|
|
3916
3977
|
}
|
|
3917
|
-
function listDrainingFrontDoors(
|
|
3918
|
-
return
|
|
3978
|
+
function listDrainingFrontDoors(fs15, markersDir, isRunning) {
|
|
3979
|
+
return fs15.readdir(markersDir).flatMap((file) => /^[1-9]\d*$/.test(file) && Number.isSafeInteger(Number(file)) ? [Number(file)] : []).filter(isRunning).sort((a, b) => a - b);
|
|
3919
3980
|
}
|
|
3920
3981
|
function recordPid(file) {
|
|
3921
3982
|
const pidText = /^([1-9]\d*)\.json$/.exec(file)?.[1];
|
|
3922
3983
|
const pid = pidText === void 0 ? void 0 : Number(pidText);
|
|
3923
3984
|
return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
|
|
3924
3985
|
}
|
|
3925
|
-
function readDirectRecordEntry(
|
|
3986
|
+
function readDirectRecordEntry(fs15, recordsDir, file) {
|
|
3926
3987
|
const pid = recordPid(file);
|
|
3927
3988
|
if (pid === void 0) {
|
|
3928
3989
|
return void 0;
|
|
3929
3990
|
}
|
|
3930
3991
|
let raw;
|
|
3931
3992
|
try {
|
|
3932
|
-
raw =
|
|
3993
|
+
raw = fs15.readFileUtf8(import_node_path9.default.join(recordsDir, file));
|
|
3933
3994
|
} catch {
|
|
3934
3995
|
return void 0;
|
|
3935
3996
|
}
|
|
@@ -3943,37 +4004,37 @@ function readDirectRecordEntry(fs14, recordsDir, file) {
|
|
|
3943
4004
|
return { malformed: true };
|
|
3944
4005
|
}
|
|
3945
4006
|
}
|
|
3946
|
-
function listFrontDoorDirectRecords(
|
|
3947
|
-
return
|
|
3948
|
-
const entry = readDirectRecordEntry(
|
|
4007
|
+
function listFrontDoorDirectRecords(fs15, recordsDir) {
|
|
4008
|
+
return fs15.readdir(recordsDir).flatMap((file) => {
|
|
4009
|
+
const entry = readDirectRecordEntry(fs15, recordsDir, file);
|
|
3949
4010
|
return entry?.record === void 0 ? [] : [entry.record];
|
|
3950
4011
|
}).sort((a, b) => a.pid - b.pid);
|
|
3951
4012
|
}
|
|
3952
|
-
function pruneMalformedFrontDoorDirectFiles(
|
|
3953
|
-
for (const file of
|
|
4013
|
+
function pruneMalformedFrontDoorDirectFiles(fs15, recordsDir, isRunning) {
|
|
4014
|
+
for (const file of fs15.readdir(recordsDir)) {
|
|
3954
4015
|
const writer = RECORD_TEMPORARY_FILE.exec(file)?.[1];
|
|
3955
4016
|
const stale = writer !== void 0 && !isRunning(Number(writer));
|
|
3956
|
-
if (stale || readDirectRecordEntry(
|
|
3957
|
-
|
|
4017
|
+
if (stale || readDirectRecordEntry(fs15, recordsDir, file)?.malformed === true) {
|
|
4018
|
+
fs15.removeRecursive(import_node_path9.default.join(recordsDir, file));
|
|
3958
4019
|
}
|
|
3959
4020
|
}
|
|
3960
4021
|
}
|
|
3961
4022
|
function liveFrontDoorDirectRecords(records, liveness) {
|
|
3962
4023
|
return records.filter((record) => liveness.doors.has(record.pid) || liveness.unknown.has(record.pid));
|
|
3963
4024
|
}
|
|
3964
|
-
function pruneDeadFrontDoorDirectRecords(
|
|
4025
|
+
function pruneDeadFrontDoorDirectRecords(fs15, recordsDir, records, liveness) {
|
|
3965
4026
|
for (const record of records) {
|
|
3966
4027
|
if (!liveness.doors.has(record.pid) && !liveness.unknown.has(record.pid)) {
|
|
3967
|
-
removeFrontDoorDirectRecord(
|
|
4028
|
+
removeFrontDoorDirectRecord(fs15, recordsDir, record.pid);
|
|
3968
4029
|
}
|
|
3969
4030
|
}
|
|
3970
4031
|
}
|
|
3971
4032
|
function recordOf(details) {
|
|
3972
4033
|
return details === void 0 ? {} : { sessionId: details.sessionId, ...details.models === void 0 ? {} : { models: details.models } };
|
|
3973
4034
|
}
|
|
3974
|
-
function writeFrontDoorSession(
|
|
3975
|
-
|
|
3976
|
-
|
|
4035
|
+
function writeFrontDoorSession(fs15, sessionsDir, session) {
|
|
4036
|
+
fs15.mkdirPrivate(sessionsDir);
|
|
4037
|
+
fs15.writeFilePrivate(import_node_path9.default.join(sessionsDir, sessionRecordName(session.pid)), `${JSON.stringify(session, null, 2)}
|
|
3977
4038
|
`);
|
|
3978
4039
|
}
|
|
3979
4040
|
function sessionRecordName(pid) {
|
|
@@ -3985,32 +4046,32 @@ function isSessionRecordName(name) {
|
|
|
3985
4046
|
function summaryOf(session) {
|
|
3986
4047
|
return { pid: session.pid, startedAt: session.startedAt, ...session.supervisorPid === void 0 ? {} : { supervisorPid: session.supervisorPid } };
|
|
3987
4048
|
}
|
|
3988
|
-
function readFrontDoorSessionRecord(
|
|
4049
|
+
function readFrontDoorSessionRecord(fs15, sessionsDir, name) {
|
|
3989
4050
|
try {
|
|
3990
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
4051
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs15.readFileUtf8(import_node_path9.default.join(sessionsDir, name)) ?? ""));
|
|
3991
4052
|
return parsed.success ? parsed.data : void 0;
|
|
3992
4053
|
} catch {
|
|
3993
4054
|
return void 0;
|
|
3994
4055
|
}
|
|
3995
4056
|
}
|
|
3996
|
-
function listFrontDoorSessions(
|
|
4057
|
+
function listFrontDoorSessions(fs15, sessionsDir) {
|
|
3997
4058
|
const sessions = [];
|
|
3998
|
-
for (const name of
|
|
3999
|
-
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(
|
|
4059
|
+
for (const name of fs15.readdir(sessionsDir)) {
|
|
4060
|
+
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(fs15, sessionsDir, name) : void 0;
|
|
4000
4061
|
if (record !== void 0) {
|
|
4001
4062
|
sessions.push(summaryOf(record));
|
|
4002
4063
|
}
|
|
4003
4064
|
}
|
|
4004
4065
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
4005
4066
|
}
|
|
4006
|
-
function removeFrontDoorSession(
|
|
4007
|
-
|
|
4067
|
+
function removeFrontDoorSession(fs15, sessionsDir, pid) {
|
|
4068
|
+
fs15.removeRecursive(import_node_path9.default.join(sessionsDir, sessionRecordName(pid)));
|
|
4008
4069
|
}
|
|
4009
|
-
function pruneDeadFrontDoorSessions(
|
|
4070
|
+
function pruneDeadFrontDoorSessions(fs15, sessionsDir, listed, isRunning) {
|
|
4010
4071
|
const removed = [];
|
|
4011
4072
|
for (const session of listed) {
|
|
4012
4073
|
if (!isRunning(session.pid)) {
|
|
4013
|
-
removeFrontDoorSession(
|
|
4074
|
+
removeFrontDoorSession(fs15, sessionsDir, session.pid);
|
|
4014
4075
|
removed.push(session.pid);
|
|
4015
4076
|
}
|
|
4016
4077
|
}
|
|
@@ -4109,9 +4170,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
4109
4170
|
}
|
|
4110
4171
|
}
|
|
4111
4172
|
async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
4112
|
-
const { fs:
|
|
4173
|
+
const { fs: fs15, paths } = ports;
|
|
4113
4174
|
const servingBinary = ports.statOwnExecutable();
|
|
4114
|
-
const previous = readFrontDoorState(
|
|
4175
|
+
const previous = readFrontDoorState(fs15, paths.frontdoorStateFile);
|
|
4115
4176
|
let lastPort = previous?.lastPort;
|
|
4116
4177
|
let lastConnectPort = previous?.lastConnectPort;
|
|
4117
4178
|
let lastDirectPort = previous?.lastDirectPort;
|
|
@@ -4125,14 +4186,14 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4125
4186
|
const fail = (message) => {
|
|
4126
4187
|
ports.closeRcStreamHub();
|
|
4127
4188
|
if (predecessor === void 0) {
|
|
4128
|
-
writeFrontDoorState(
|
|
4129
|
-
|
|
4189
|
+
writeFrontDoorState(fs15, paths.frontdoorStateFile, { lastError: message, ...sticky() });
|
|
4190
|
+
fs15.removeRecursive(paths.frontdoorLockFile);
|
|
4130
4191
|
}
|
|
4131
4192
|
ports.log(`agent-shim frontdoor supervisor: ${message}`);
|
|
4132
4193
|
return 1;
|
|
4133
4194
|
};
|
|
4134
4195
|
if (predecessor === void 0) {
|
|
4135
|
-
writeFrontDoorState(
|
|
4196
|
+
writeFrontDoorState(fs15, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
|
|
4136
4197
|
}
|
|
4137
4198
|
const previousSticky = lastPort;
|
|
4138
4199
|
let http3;
|
|
@@ -4173,11 +4234,11 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4173
4234
|
ports.log(`agent-shim frontdoor supervisor: sticky direct port ${String(previousStickyDirect)} was occupied; moving to ${String(direct.port)} (headroom admits the new address once its supervisor rewrites the allowlist file)`);
|
|
4174
4235
|
}
|
|
4175
4236
|
lastDirectPort = direct.port;
|
|
4176
|
-
writeFrontDoorDirectRecord(
|
|
4177
|
-
writeFrontDoorState(
|
|
4237
|
+
writeFrontDoorDirectRecord(fs15, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
|
|
4238
|
+
writeFrontDoorState(fs15, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http3.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
|
|
4178
4239
|
ports.doorHealth.generation({ providerPort: http3.port, connectPort: connect3.port, directPort: direct.port });
|
|
4179
4240
|
if (predecessor === void 0) {
|
|
4180
|
-
|
|
4241
|
+
fs15.removeRecursive(paths.frontdoorLockFile);
|
|
4181
4242
|
} else {
|
|
4182
4243
|
predecessor.serving();
|
|
4183
4244
|
}
|
|
@@ -4186,7 +4247,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4186
4247
|
let idleSince;
|
|
4187
4248
|
let ticks = 0;
|
|
4188
4249
|
const supersedingOwner = async () => {
|
|
4189
|
-
const owner = readFrontDoorState(
|
|
4250
|
+
const owner = readFrontDoorState(fs15, paths.frontdoorStateFile)?.supervisorPid;
|
|
4190
4251
|
return owner !== void 0 && owner !== ports.ownPid && (await ports.runningAmong([owner])).has(owner) ? owner : void 0;
|
|
4191
4252
|
};
|
|
4192
4253
|
let supersededBy;
|
|
@@ -4215,13 +4276,13 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4215
4276
|
ports.stopBackgroundWork?.();
|
|
4216
4277
|
const drained = [direct.drain(), connect3.drain(), http3.drain()];
|
|
4217
4278
|
if (await supersedingOwner() === void 0) {
|
|
4218
|
-
writeFrontDoorState(
|
|
4279
|
+
writeFrontDoorState(fs15, paths.frontdoorStateFile, sticky());
|
|
4219
4280
|
}
|
|
4220
|
-
markFrontDoorDraining(
|
|
4281
|
+
markFrontDoorDraining(fs15, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4221
4282
|
ports.closeRcStreamHub();
|
|
4222
4283
|
await Promise.all(drained);
|
|
4223
|
-
unmarkFrontDoorDraining(
|
|
4224
|
-
removeFrontDoorDirectRecord(
|
|
4284
|
+
unmarkFrontDoorDraining(fs15, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4285
|
+
removeFrontDoorDirectRecord(fs15, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4225
4286
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: the connections this door carried have ended; exiting`);
|
|
4226
4287
|
return 0;
|
|
4227
4288
|
};
|
|
@@ -4242,12 +4303,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4242
4303
|
await connect3.close();
|
|
4243
4304
|
await http3.close();
|
|
4244
4305
|
ports.closeRcStreamHub();
|
|
4245
|
-
removeFrontDoorDirectRecord(
|
|
4306
|
+
removeFrontDoorDirectRecord(fs15, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4246
4307
|
};
|
|
4247
4308
|
const shutdown = async () => {
|
|
4248
4309
|
await closeServing();
|
|
4249
4310
|
if (await supersedingOwner() === void 0) {
|
|
4250
|
-
writeFrontDoorState(
|
|
4311
|
+
writeFrontDoorState(fs15, paths.frontdoorStateFile, sticky());
|
|
4251
4312
|
}
|
|
4252
4313
|
return 0;
|
|
4253
4314
|
};
|
|
@@ -4266,7 +4327,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4266
4327
|
ticks += 1;
|
|
4267
4328
|
const listed = ports.registry.rescan();
|
|
4268
4329
|
const running = await ports.runningAmong(listed.map((session) => session.pid));
|
|
4269
|
-
const pruned = pruneDeadFrontDoorSessions(
|
|
4330
|
+
const pruned = pruneDeadFrontDoorSessions(fs15, paths.frontdoorSessionsDir, listed, (pid) => running.has(pid));
|
|
4270
4331
|
ports.registry.forget(pruned);
|
|
4271
4332
|
ports.observeLaunchRegistry(listed, pruned);
|
|
4272
4333
|
ports.checkQuotaExpiry();
|
|
@@ -4340,8 +4401,8 @@ function parseConnectTarget(authority) {
|
|
|
4340
4401
|
function isInterceptedHost(host, interceptHosts) {
|
|
4341
4402
|
return interceptHosts.includes(host);
|
|
4342
4403
|
}
|
|
4343
|
-
function servedByPipeline(
|
|
4344
|
-
return
|
|
4404
|
+
function servedByPipeline(path45) {
|
|
4405
|
+
return path45?.startsWith(ROUTED_PATH_PREFIX) === true;
|
|
4345
4406
|
}
|
|
4346
4407
|
function forwardableHeaders(headers) {
|
|
4347
4408
|
const connectionTokens = new Set(
|
|
@@ -4787,7 +4848,7 @@ var init_package = __esm({
|
|
|
4787
4848
|
"package.json"() {
|
|
4788
4849
|
package_default = {
|
|
4789
4850
|
name: "agent-shim",
|
|
4790
|
-
version: "11.
|
|
4851
|
+
version: "11.83.1",
|
|
4791
4852
|
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.",
|
|
4792
4853
|
license: "MIT",
|
|
4793
4854
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -4839,7 +4900,7 @@ var init_package = __esm({
|
|
|
4839
4900
|
"@anthropic-ai/claude-agent-sdk": "0.3.292",
|
|
4840
4901
|
"@clack/prompts": "^1.8.0",
|
|
4841
4902
|
"@modelcontextprotocol/sdk": "1.32.0",
|
|
4842
|
-
"@orpc/client": "2.0.0-beta.
|
|
4903
|
+
"@orpc/client": "2.0.0-beta.46",
|
|
4843
4904
|
"@orpc/openapi": "2.0.0-beta.43",
|
|
4844
4905
|
"@orpc/server": "2.0.0-beta.43",
|
|
4845
4906
|
commander: "^15.0.0",
|
|
@@ -5009,43 +5070,43 @@ function parseJson(raw, schema) {
|
|
|
5009
5070
|
const parsed = schema.safeParse(JSON.parse(raw));
|
|
5010
5071
|
return parsed.success ? parsed.data : void 0;
|
|
5011
5072
|
}
|
|
5012
|
-
function readHeadroomState(
|
|
5073
|
+
function readHeadroomState(fs15, stateFile) {
|
|
5013
5074
|
try {
|
|
5014
|
-
return parseJson(
|
|
5075
|
+
return parseJson(fs15.readFileUtf8(stateFile), HeadroomStateSchema);
|
|
5015
5076
|
} catch {
|
|
5016
5077
|
return void 0;
|
|
5017
5078
|
}
|
|
5018
5079
|
}
|
|
5019
|
-
function writeHeadroomState(
|
|
5020
|
-
|
|
5021
|
-
|
|
5080
|
+
function writeHeadroomState(fs15, stateFile, state) {
|
|
5081
|
+
fs15.mkdirp(import_node_path12.default.dirname(stateFile));
|
|
5082
|
+
fs15.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
5022
5083
|
`);
|
|
5023
5084
|
}
|
|
5024
|
-
function resolveServingHeadroomState(
|
|
5025
|
-
const current = readHeadroomState(
|
|
5085
|
+
function resolveServingHeadroomState(fs15, files, isRunning) {
|
|
5086
|
+
const current = readHeadroomState(fs15, files.stateFile);
|
|
5026
5087
|
if (current !== void 0) {
|
|
5027
5088
|
return { path: files.stateFile, state: current };
|
|
5028
5089
|
}
|
|
5029
|
-
const legacy = readHeadroomState(
|
|
5090
|
+
const legacy = readHeadroomState(fs15, files.legacyStateFile);
|
|
5030
5091
|
if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
|
|
5031
5092
|
return { path: files.legacyStateFile, state: legacy };
|
|
5032
5093
|
}
|
|
5033
5094
|
return void 0;
|
|
5034
5095
|
}
|
|
5035
|
-
function migrateHeadroomState(
|
|
5036
|
-
const legacy = readHeadroomState(
|
|
5096
|
+
function migrateHeadroomState(fs15, files, isRunning) {
|
|
5097
|
+
const legacy = readHeadroomState(fs15, files.legacyStateFile);
|
|
5037
5098
|
const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
|
|
5038
|
-
const current = readHeadroomState(
|
|
5099
|
+
const current = readHeadroomState(fs15, files.stateFile);
|
|
5039
5100
|
if (current !== void 0 || legacyLive) {
|
|
5040
|
-
if (!legacyLive &&
|
|
5041
|
-
|
|
5101
|
+
if (!legacyLive && fs15.readFileUtf8(files.legacyStateFile) !== void 0) {
|
|
5102
|
+
fs15.removeRecursive(files.legacyStateFile);
|
|
5042
5103
|
}
|
|
5043
5104
|
return;
|
|
5044
5105
|
}
|
|
5045
5106
|
if (legacy !== void 0) {
|
|
5046
|
-
writeHeadroomState(
|
|
5107
|
+
writeHeadroomState(fs15, files.stateFile, legacy);
|
|
5047
5108
|
}
|
|
5048
|
-
|
|
5109
|
+
fs15.removeRecursive(files.legacyStateFile);
|
|
5049
5110
|
}
|
|
5050
5111
|
function hashAllowlist(allowlist) {
|
|
5051
5112
|
return (0, import_node_crypto6.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
@@ -5078,27 +5139,27 @@ function isAdmissibleUrl(entry) {
|
|
|
5078
5139
|
function parseAllowlistFile(content) {
|
|
5079
5140
|
return content.replace(/^\uFEFF/, "").replace(ALLOWLIST_FILE_COMMENT, "").split(ALLOWLIST_FILE_SEPARATORS).map((entry) => entry.replace(ALLOWLIST_SURROUNDING_WHITESPACE, "")).filter((entry) => entry !== "" && !ALLOWLIST_ENTRY_WHITESPACE.test(entry) && (entry.includes("://") ? isAdmissibleUrl(entry) : isBareHost(entry)));
|
|
5080
5141
|
}
|
|
5081
|
-
function writeAllowlistFile(
|
|
5082
|
-
|
|
5083
|
-
|
|
5142
|
+
function writeAllowlistFile(fs15, allowlistFile, allowlist) {
|
|
5143
|
+
fs15.mkdirPrivate(import_node_path12.default.dirname(allowlistFile));
|
|
5144
|
+
fs15.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
|
|
5084
5145
|
}
|
|
5085
|
-
function pruneStaleAllowlistTemporaries(
|
|
5146
|
+
function pruneStaleAllowlistTemporaries(fs15, allowlistFile, isRunning) {
|
|
5086
5147
|
const prefix = `${import_node_path12.default.basename(allowlistFile)}.`;
|
|
5087
|
-
for (const name of
|
|
5148
|
+
for (const name of fs15.readdir(import_node_path12.default.dirname(allowlistFile))) {
|
|
5088
5149
|
const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
|
|
5089
5150
|
if (writer !== void 0 && !isRunning(Number(writer))) {
|
|
5090
|
-
|
|
5151
|
+
fs15.removeRecursive(import_node_path12.default.join(import_node_path12.default.dirname(allowlistFile), name));
|
|
5091
5152
|
}
|
|
5092
5153
|
}
|
|
5093
5154
|
}
|
|
5094
|
-
function readAllProviders(
|
|
5155
|
+
function readAllProviders(fs15, providersDir) {
|
|
5095
5156
|
const result = [];
|
|
5096
|
-
for (const name of
|
|
5157
|
+
for (const name of fs15.readdir(providersDir)) {
|
|
5097
5158
|
if (!name.endsWith(".json")) {
|
|
5098
5159
|
continue;
|
|
5099
5160
|
}
|
|
5100
5161
|
try {
|
|
5101
|
-
const parsed = parseJson(
|
|
5162
|
+
const parsed = parseJson(fs15.readFileUtf8(import_node_path12.default.join(providersDir, name)), ProviderSchema);
|
|
5102
5163
|
if (parsed !== void 0) {
|
|
5103
5164
|
result.push({ name: name.slice(0, -".json".length), provider: parsed });
|
|
5104
5165
|
}
|
|
@@ -5108,22 +5169,22 @@ function readAllProviders(fs14, providersDir) {
|
|
|
5108
5169
|
}
|
|
5109
5170
|
return result;
|
|
5110
5171
|
}
|
|
5111
|
-
function writeSession(
|
|
5112
|
-
|
|
5113
|
-
|
|
5172
|
+
function writeSession(fs15, sessionsDir, session) {
|
|
5173
|
+
fs15.mkdirp(sessionsDir);
|
|
5174
|
+
fs15.writeFileUtf8(import_node_path12.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
5114
5175
|
`);
|
|
5115
5176
|
}
|
|
5116
|
-
function removeSession(
|
|
5117
|
-
|
|
5177
|
+
function removeSession(fs15, sessionsDir, pid) {
|
|
5178
|
+
fs15.removeRecursive(import_node_path12.default.join(sessionsDir, `${String(pid)}.json`));
|
|
5118
5179
|
}
|
|
5119
|
-
function listSessions(
|
|
5180
|
+
function listSessions(fs15, sessionsDir) {
|
|
5120
5181
|
const sessions = [];
|
|
5121
|
-
for (const name of
|
|
5182
|
+
for (const name of fs15.readdir(sessionsDir)) {
|
|
5122
5183
|
if (!name.endsWith(".json")) {
|
|
5123
5184
|
continue;
|
|
5124
5185
|
}
|
|
5125
5186
|
try {
|
|
5126
|
-
const parsed = parseJson(
|
|
5187
|
+
const parsed = parseJson(fs15.readFileUtf8(import_node_path12.default.join(sessionsDir, name)), HeadroomSessionSchema);
|
|
5127
5188
|
if (parsed !== void 0) {
|
|
5128
5189
|
sessions.push(parsed);
|
|
5129
5190
|
}
|
|
@@ -5133,22 +5194,22 @@ function listSessions(fs14, sessionsDir) {
|
|
|
5133
5194
|
}
|
|
5134
5195
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
5135
5196
|
}
|
|
5136
|
-
function sessionsForSupervisor(
|
|
5137
|
-
return listSessions(
|
|
5197
|
+
function sessionsForSupervisor(fs15, sessionsDir, supervisorPid) {
|
|
5198
|
+
return listSessions(fs15, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
|
|
5138
5199
|
}
|
|
5139
|
-
function pruneDeadSessions(
|
|
5200
|
+
function pruneDeadSessions(fs15, sessionsDir, isRunning) {
|
|
5140
5201
|
const removed = [];
|
|
5141
|
-
for (const session of listSessions(
|
|
5202
|
+
for (const session of listSessions(fs15, sessionsDir)) {
|
|
5142
5203
|
if (!isRunning(session.pid)) {
|
|
5143
|
-
removeSession(
|
|
5204
|
+
removeSession(fs15, sessionsDir, session.pid);
|
|
5144
5205
|
removed.push(session.pid);
|
|
5145
5206
|
}
|
|
5146
5207
|
}
|
|
5147
5208
|
return removed;
|
|
5148
5209
|
}
|
|
5149
|
-
function readStartLock(
|
|
5210
|
+
function readStartLock(fs15, lockFile) {
|
|
5150
5211
|
try {
|
|
5151
|
-
return parseJson(
|
|
5212
|
+
return parseJson(fs15.readFileUtf8(lockFile), HeadroomLockSchema);
|
|
5152
5213
|
} catch {
|
|
5153
5214
|
return void 0;
|
|
5154
5215
|
}
|
|
@@ -5241,12 +5302,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
|
|
|
5241
5302
|
}
|
|
5242
5303
|
return hashAllowlist([...entries].sort());
|
|
5243
5304
|
}
|
|
5244
|
-
function earlierReleaseDaemon(
|
|
5305
|
+
function earlierReleaseDaemon(fs15, paths, daemon) {
|
|
5245
5306
|
if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
|
|
5246
5307
|
return void 0;
|
|
5247
5308
|
}
|
|
5248
|
-
const providers = readAllProviders(
|
|
5249
|
-
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(
|
|
5309
|
+
const providers = readAllProviders(fs15, paths.providersDir).map((entry) => entry.provider);
|
|
5310
|
+
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs15, paths.frontdoorStateFile)));
|
|
5250
5311
|
return { admitsServingDoor: daemon.recordedHash === expected };
|
|
5251
5312
|
}
|
|
5252
5313
|
var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
|
|
@@ -5271,8 +5332,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
|
|
|
5271
5332
|
}
|
|
5272
5333
|
return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
|
|
5273
5334
|
}
|
|
5274
|
-
function daemonAdmits(
|
|
5275
|
-
const content =
|
|
5335
|
+
function daemonAdmits(fs15, allowlistFile, recordedHash, required) {
|
|
5336
|
+
const content = fs15.readFileUtf8(allowlistFile);
|
|
5276
5337
|
if (content === void 0 || recordedHash === void 0) {
|
|
5277
5338
|
return false;
|
|
5278
5339
|
}
|
|
@@ -5541,7 +5602,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
|
|
|
5541
5602
|
const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
|
|
5542
5603
|
return { message: refusal2, repairable: replaceable };
|
|
5543
5604
|
}
|
|
5544
|
-
function prepareHeadroomSocket(
|
|
5605
|
+
function prepareHeadroomSocket(fs15, ports, paths, supervisorPid) {
|
|
5545
5606
|
const unsupported = platformRefusal(ports.platform);
|
|
5546
5607
|
if (unsupported !== void 0) {
|
|
5547
5608
|
return { refused: unsupported };
|
|
@@ -5556,18 +5617,18 @@ function prepareHeadroomSocket(fs14, ports, paths, supervisorPid) {
|
|
|
5556
5617
|
if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
|
|
5557
5618
|
return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
|
|
5558
5619
|
}
|
|
5559
|
-
|
|
5620
|
+
fs15.mkdirPrivate(paths.headroomSocketDir);
|
|
5560
5621
|
const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
|
|
5561
5622
|
return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
|
|
5562
5623
|
}
|
|
5563
|
-
function pruneStaleHeadroomSockets(
|
|
5624
|
+
function pruneStaleHeadroomSockets(fs15, paths, isRunning) {
|
|
5564
5625
|
const removed = [];
|
|
5565
|
-
for (const name of
|
|
5626
|
+
for (const name of fs15.readdir(paths.headroomSocketDir)) {
|
|
5566
5627
|
const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
|
|
5567
5628
|
if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
|
|
5568
5629
|
continue;
|
|
5569
5630
|
}
|
|
5570
|
-
|
|
5631
|
+
fs15.removeRecursive(import_node_path13.default.join(paths.headroomSocketDir, name));
|
|
5571
5632
|
removed.push(name);
|
|
5572
5633
|
}
|
|
5573
5634
|
return removed;
|
|
@@ -5679,37 +5740,37 @@ function compareVersions2(a, b) {
|
|
|
5679
5740
|
return 0;
|
|
5680
5741
|
}
|
|
5681
5742
|
async function runSupervisor(initialConfig, ports, options = {}) {
|
|
5682
|
-
const { fs:
|
|
5743
|
+
const { fs: fs15, paths } = ports;
|
|
5683
5744
|
let config = initialConfig;
|
|
5684
|
-
migrateHeadroomState(
|
|
5685
|
-
const previousState = resolveServingHeadroomState(
|
|
5745
|
+
migrateHeadroomState(fs15, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
|
|
5746
|
+
const previousState = resolveServingHeadroomState(fs15, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
|
|
5686
5747
|
if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
|
|
5687
5748
|
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
|
|
5688
5749
|
return 0;
|
|
5689
5750
|
}
|
|
5690
5751
|
let installedSource = previousState?.installedSource;
|
|
5691
5752
|
const ownsState = () => {
|
|
5692
|
-
const owner = readHeadroomState(
|
|
5753
|
+
const owner = readHeadroomState(fs15, paths.headroomStateFile)?.supervisorPid;
|
|
5693
5754
|
return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
|
|
5694
5755
|
};
|
|
5695
5756
|
const writeOwnState = (state) => {
|
|
5696
5757
|
if (!ownsState()) {
|
|
5697
5758
|
return false;
|
|
5698
5759
|
}
|
|
5699
|
-
writeHeadroomState(
|
|
5760
|
+
writeHeadroomState(fs15, paths.headroomStateFile, state);
|
|
5700
5761
|
return true;
|
|
5701
5762
|
};
|
|
5702
5763
|
const fail = (message) => {
|
|
5703
5764
|
if (writeOwnState({ lastError: message })) {
|
|
5704
|
-
|
|
5765
|
+
fs15.removeRecursive(paths.headroomLockFile);
|
|
5705
5766
|
}
|
|
5706
5767
|
ports.log(`agent-shim headroom supervisor: ${message}`);
|
|
5707
5768
|
return 1;
|
|
5708
5769
|
};
|
|
5709
5770
|
const syncAllowlistFile = (allowlist) => {
|
|
5710
5771
|
try {
|
|
5711
|
-
if (
|
|
5712
|
-
writeAllowlistFile(
|
|
5772
|
+
if (fs15.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
|
|
5773
|
+
writeAllowlistFile(fs15, paths.headroomAllowlistFile, allowlist);
|
|
5713
5774
|
ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
|
|
5714
5775
|
}
|
|
5715
5776
|
return void 0;
|
|
@@ -5727,9 +5788,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5727
5788
|
}
|
|
5728
5789
|
ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
|
|
5729
5790
|
try {
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
writeAllowlistFile(
|
|
5791
|
+
fs15.mkdirPrivate(paths.headroomDir);
|
|
5792
|
+
fs15.mkdirPrivate(import_node_path14.default.dirname(paths.headroomAllowlistFile));
|
|
5793
|
+
writeAllowlistFile(fs15, paths.headroomAllowlistFile, allowlist);
|
|
5733
5794
|
} catch (error) {
|
|
5734
5795
|
return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error instanceof Error ? error.message : String(error)}`;
|
|
5735
5796
|
}
|
|
@@ -5754,20 +5815,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5754
5815
|
installedSource = config.source;
|
|
5755
5816
|
return void 0;
|
|
5756
5817
|
};
|
|
5757
|
-
const socket = prepareHeadroomSocket(
|
|
5818
|
+
const socket = prepareHeadroomSocket(fs15, ports.socketTrust, paths, ports.ownPid);
|
|
5758
5819
|
if (socket.refused !== void 0) {
|
|
5759
5820
|
return fail(socket.refused);
|
|
5760
5821
|
}
|
|
5761
5822
|
const { socketPath } = socket;
|
|
5762
|
-
pruneStaleHeadroomSockets(
|
|
5763
|
-
pruneStaleAllowlistTemporaries(
|
|
5823
|
+
pruneStaleHeadroomSockets(fs15, paths, ports.isRunning);
|
|
5824
|
+
pruneStaleAllowlistTemporaries(fs15, paths.headroomAllowlistFile, ports.isRunning);
|
|
5764
5825
|
const installFailure = ensureInstalled();
|
|
5765
5826
|
if (installFailure !== void 0) {
|
|
5766
5827
|
return fail(installFailure);
|
|
5767
5828
|
}
|
|
5768
5829
|
const version = ports.headroomVersion() ?? "unknown";
|
|
5769
5830
|
writeOwnState({ supervisorPid: ports.ownPid, version, installedSource });
|
|
5770
|
-
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(
|
|
5831
|
+
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs15, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
|
|
5771
5832
|
const orphanPid = previousState?.headroomPid;
|
|
5772
5833
|
const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
|
|
5773
5834
|
const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
|
|
@@ -5805,12 +5866,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5805
5866
|
}
|
|
5806
5867
|
config = ports.readConfig();
|
|
5807
5868
|
const settingsHash = hashSettings(config.settings);
|
|
5808
|
-
const inputs = currentHeadroomAllowlistInputs(
|
|
5809
|
-
pruneDeadFrontDoorDirectRecords(
|
|
5810
|
-
pruneMalformedFrontDoorDirectFiles(
|
|
5869
|
+
const inputs = currentHeadroomAllowlistInputs(fs15, paths, ports.frontDoorLiveness);
|
|
5870
|
+
pruneDeadFrontDoorDirectRecords(fs15, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
|
|
5871
|
+
pruneMalformedFrontDoorDirectFiles(fs15, paths.frontdoorDirectRecordsDir, ports.isRunning);
|
|
5811
5872
|
const allowlist = inputs.frontDoorOrigins;
|
|
5812
5873
|
const allowlistHash = hashAllowlist(allowlist);
|
|
5813
|
-
pruneDeadSessions(
|
|
5874
|
+
pruneDeadSessions(fs15, paths.headroomSessionsDir, ports.isRunning);
|
|
5814
5875
|
const ownsNow = ownsState();
|
|
5815
5876
|
if (!ownsNow && !superseded) {
|
|
5816
5877
|
ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
|
|
@@ -5857,7 +5918,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5857
5918
|
runningSettingsHash = settingsHash;
|
|
5858
5919
|
const recorded = writeOwnState(servingState(pid));
|
|
5859
5920
|
if (recorded) {
|
|
5860
|
-
|
|
5921
|
+
fs15.removeRecursive(paths.headroomLockFile);
|
|
5861
5922
|
}
|
|
5862
5923
|
idleSince = void 0;
|
|
5863
5924
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
|
|
@@ -5885,7 +5946,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5885
5946
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
|
|
5886
5947
|
}
|
|
5887
5948
|
if (runningSettingsHash !== settingsHash || installedSource !== config.source) {
|
|
5888
|
-
if (sessionsForSupervisor(
|
|
5949
|
+
if (sessionsForSupervisor(fs15, paths.headroomSessionsDir, ports.ownPid).length === 0) {
|
|
5889
5950
|
ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
|
|
5890
5951
|
ports.stopProcess(headroomPid);
|
|
5891
5952
|
headroomPid = void 0;
|
|
@@ -5894,7 +5955,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5894
5955
|
continue;
|
|
5895
5956
|
}
|
|
5896
5957
|
}
|
|
5897
|
-
const sessions = sessionsForSupervisor(
|
|
5958
|
+
const sessions = sessionsForSupervisor(fs15, paths.headroomSessionsDir, ports.ownPid);
|
|
5898
5959
|
if (sessions.length === 0) {
|
|
5899
5960
|
idleSince ??= ports.now();
|
|
5900
5961
|
const idleMs = ports.now() - idleSince;
|
|
@@ -5919,9 +5980,9 @@ function undeterminedFrontDoors(inputs) {
|
|
|
5919
5980
|
return reason === void 0 ? [] : [{ pid: record.pid, origin: directOrigin(record.directPort), reason }];
|
|
5920
5981
|
});
|
|
5921
5982
|
}
|
|
5922
|
-
function currentHeadroomAllowlistInputs(
|
|
5923
|
-
const named = frontDoorOrigin(readFrontDoorState(
|
|
5924
|
-
const records = listFrontDoorDirectRecords(
|
|
5983
|
+
function currentHeadroomAllowlistInputs(fs15, paths, frontDoorLiveness) {
|
|
5984
|
+
const named = frontDoorOrigin(readFrontDoorState(fs15, paths.frontdoorStateFile));
|
|
5985
|
+
const records = listFrontDoorDirectRecords(fs15, paths.frontdoorDirectRecordsDir);
|
|
5925
5986
|
const liveness = frontDoorLiveness(records.map((record) => record.pid));
|
|
5926
5987
|
const live = liveFrontDoorDirectRecords(records, liveness).map((record) => directOrigin(record.directPort));
|
|
5927
5988
|
return {
|
|
@@ -5930,8 +5991,8 @@ function currentHeadroomAllowlistInputs(fs14, paths, frontDoorLiveness) {
|
|
|
5930
5991
|
frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
|
|
5931
5992
|
};
|
|
5932
5993
|
}
|
|
5933
|
-
function launchRequiredUpstreams(
|
|
5934
|
-
const door = frontDoorOrigin(readFrontDoorState(
|
|
5994
|
+
function launchRequiredUpstreams(fs15, paths) {
|
|
5995
|
+
const door = frontDoorOrigin(readFrontDoorState(fs15, paths.frontdoorStateFile));
|
|
5935
5996
|
return door === void 0 ? [] : [door];
|
|
5936
5997
|
}
|
|
5937
5998
|
async function waitUntilReady(ports, socketPath, pid) {
|
|
@@ -6063,6 +6124,29 @@ function isEnoent3(error) {
|
|
|
6063
6124
|
function isErrorWithCode(error, code) {
|
|
6064
6125
|
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
6065
6126
|
}
|
|
6127
|
+
function writeFileFlushed(file, contents) {
|
|
6128
|
+
const descriptor = import_node_fs2.default.openSync(file, "w", OWNER_ONLY_FILE_MODE);
|
|
6129
|
+
try {
|
|
6130
|
+
import_node_fs2.default.writeFileSync(descriptor, contents, "utf8");
|
|
6131
|
+
import_node_fs2.default.fchmodSync(descriptor, OWNER_ONLY_FILE_MODE);
|
|
6132
|
+
import_node_fs2.default.fsyncSync(descriptor);
|
|
6133
|
+
} finally {
|
|
6134
|
+
import_node_fs2.default.closeSync(descriptor);
|
|
6135
|
+
}
|
|
6136
|
+
}
|
|
6137
|
+
function flushDirectory(directory) {
|
|
6138
|
+
const descriptor = import_node_fs2.default.openSync(directory, "r");
|
|
6139
|
+
try {
|
|
6140
|
+
import_node_fs2.default.fsyncSync(descriptor);
|
|
6141
|
+
} catch (error) {
|
|
6142
|
+
const code = typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
6143
|
+
if (code === void 0 || !DIRECTORY_FLUSH_UNSUPPORTED_CODES.has(code)) {
|
|
6144
|
+
throw error;
|
|
6145
|
+
}
|
|
6146
|
+
} finally {
|
|
6147
|
+
import_node_fs2.default.closeSync(descriptor);
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6066
6150
|
function realSleepSync(ms) {
|
|
6067
6151
|
refuseToBlockInRole("a synchronous sleep");
|
|
6068
6152
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(INT32_BYTE_LENGTH)), 0, 0, ms);
|
|
@@ -6096,9 +6180,9 @@ function realFrontDoorLiveness(pids) {
|
|
|
6096
6180
|
return { status: result.status, stdout: result.stdout, stderr: result.stderr, ...result.error === void 0 ? {} : { error: result.error } };
|
|
6097
6181
|
});
|
|
6098
6182
|
}
|
|
6099
|
-
|
|
6100
|
-
return await new Promise((resolve) => {
|
|
6101
|
-
(0, import_node_child_process3.execFile)(command, [...args], { encoding: "utf8", timeout:
|
|
6183
|
+
function realRunAsyncWithin(timeoutMs) {
|
|
6184
|
+
return async (command, args) => await new Promise((resolve) => {
|
|
6185
|
+
(0, import_node_child_process3.execFile)(command, [...args], { encoding: "utf8", timeout: timeoutMs }, (error, stdout, stderr) => {
|
|
6102
6186
|
resolve({ status: error === null ? 0 : typeof error.code === "number" ? error.code : null, stdout, stderr });
|
|
6103
6187
|
});
|
|
6104
6188
|
});
|
|
@@ -6304,7 +6388,7 @@ function realResolveClaudeBinary(isOwnBinary) {
|
|
|
6304
6388
|
function realInstalledClaudeVersions() {
|
|
6305
6389
|
return installedVersions(listVersionsDir(defaultVersionsDir()));
|
|
6306
6390
|
}
|
|
6307
|
-
var import_node_child_process3, import_node_crypto8, import_node_fs2, import_node_os2, import_node_path15, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS, realFarmFs, INT32_BYTE_LENGTH, KEY_POLL_MS, CTRL_C_BYTE, realHoldPort, PS_TIMEOUT_MS, realRunPort, MACOS_GUI_SESSION_MANAGER, realCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, realLogPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
|
|
6391
|
+
var import_node_child_process3, import_node_crypto8, import_node_fs2, import_node_os2, import_node_path15, 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, 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, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, realLogPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
|
|
6308
6392
|
var init_realPorts = __esm({
|
|
6309
6393
|
"src/realPorts.ts"() {
|
|
6310
6394
|
"use strict";
|
|
@@ -6349,6 +6433,7 @@ var init_realPorts = __esm({
|
|
|
6349
6433
|
OWNER_ONLY_DIR_MODE = 448;
|
|
6350
6434
|
OWNER_ONLY_FILE_MODE = 384;
|
|
6351
6435
|
PERMISSION_BITS = 511;
|
|
6436
|
+
DIRECTORY_FLUSH_UNSUPPORTED_CODES = /* @__PURE__ */ new Set(["EINVAL", "ENOTSUP", "EOPNOTSUPP"]);
|
|
6352
6437
|
realFarmFs = {
|
|
6353
6438
|
lstat(filePath) {
|
|
6354
6439
|
let stat;
|
|
@@ -6405,12 +6490,18 @@ var init_realPorts = __esm({
|
|
|
6405
6490
|
import_node_fs2.default.mkdirSync(dirPath, { recursive: true, mode: OWNER_ONLY_DIR_MODE });
|
|
6406
6491
|
import_node_fs2.default.chmodSync(dirPath, OWNER_ONLY_DIR_MODE);
|
|
6407
6492
|
},
|
|
6408
|
-
writeFilePrivate(filePath, contents) {
|
|
6493
|
+
writeFilePrivate(filePath, contents, options) {
|
|
6409
6494
|
const temp = `${filePath}.${String(process.pid)}.tmp`;
|
|
6410
6495
|
try {
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6496
|
+
if (options?.durable === true) {
|
|
6497
|
+
writeFileFlushed(temp, contents);
|
|
6498
|
+
import_node_fs2.default.renameSync(temp, filePath);
|
|
6499
|
+
flushDirectory(import_node_path15.default.dirname(filePath));
|
|
6500
|
+
} else {
|
|
6501
|
+
import_node_fs2.default.writeFileSync(temp, contents, { encoding: "utf8", mode: OWNER_ONLY_FILE_MODE });
|
|
6502
|
+
import_node_fs2.default.chmodSync(temp, OWNER_ONLY_FILE_MODE);
|
|
6503
|
+
import_node_fs2.default.renameSync(temp, filePath);
|
|
6504
|
+
}
|
|
6414
6505
|
} catch (error) {
|
|
6415
6506
|
import_node_fs2.default.rmSync(temp, { force: true });
|
|
6416
6507
|
throw error;
|
|
@@ -6480,12 +6571,17 @@ var init_realPorts = __esm({
|
|
|
6480
6571
|
}
|
|
6481
6572
|
};
|
|
6482
6573
|
PS_TIMEOUT_MS = 2e3;
|
|
6574
|
+
RUN_OUTPUT_LIMIT_MIB = 256;
|
|
6575
|
+
BYTES_PER_MIB2 = 1048576;
|
|
6576
|
+
RUN_OUTPUT_LIMIT_BYTES = RUN_OUTPUT_LIMIT_MIB * BYTES_PER_MIB2;
|
|
6483
6577
|
realRunPort = {
|
|
6484
|
-
run(command, args) {
|
|
6485
|
-
const result = spawnSyncBlocking("an external command", command, args, { encoding: "utf8" });
|
|
6578
|
+
run(command, args, input) {
|
|
6579
|
+
const result = spawnSyncBlocking("an external command", command, args, { encoding: "utf8", maxBuffer: RUN_OUTPUT_LIMIT_BYTES, ...input === void 0 ? {} : { input } });
|
|
6486
6580
|
return { status: result.status, stdout: result.stdout, stderr: result.stderr };
|
|
6487
6581
|
}
|
|
6488
6582
|
};
|
|
6583
|
+
ASYNC_RUN_TIMEOUT_MS = 2e3;
|
|
6584
|
+
realRunAsync = realRunAsyncWithin(ASYNC_RUN_TIMEOUT_MS);
|
|
6489
6585
|
MACOS_GUI_SESSION_MANAGER = "Aqua";
|
|
6490
6586
|
realCredentialPort = {
|
|
6491
6587
|
readSecretFile(filePath) {
|
|
@@ -6677,8 +6773,8 @@ var init_cascade = __esm({
|
|
|
6677
6773
|
function poolNameOf(selector) {
|
|
6678
6774
|
return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
|
|
6679
6775
|
}
|
|
6680
|
-
function readActiveIdentity(
|
|
6681
|
-
const trimmed =
|
|
6776
|
+
function readActiveIdentity(fs15, activeIdentityFile) {
|
|
6777
|
+
const trimmed = fs15.readFileUtf8(activeIdentityFile)?.trim();
|
|
6682
6778
|
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
6683
6779
|
}
|
|
6684
6780
|
function isNonEmpty(value) {
|
|
@@ -6728,11 +6824,11 @@ function decideConfigProfile(params) {
|
|
|
6728
6824
|
}
|
|
6729
6825
|
return { source: "none" };
|
|
6730
6826
|
}
|
|
6731
|
-
function loadIdentity(identitiesDir, name,
|
|
6827
|
+
function loadIdentity(identitiesDir, name, fs15) {
|
|
6732
6828
|
if (!isFileName(name)) {
|
|
6733
6829
|
throw new UnsafeNameError(name, "identity", FILE_NAME_RULE);
|
|
6734
6830
|
}
|
|
6735
|
-
return loadConfigFile(import_node_path18.default.join(identitiesDir, name, "identity.json"), IdentitySchema,
|
|
6831
|
+
return loadConfigFile(import_node_path18.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs15.readConfigFile);
|
|
6736
6832
|
}
|
|
6737
6833
|
var import_node_path18, IDENTITY_DECISION_SOURCES, IDENTITY_SOURCE_LABELS, CONFIG_PROFILE_DECISION_SOURCES;
|
|
6738
6834
|
var init_identity = __esm({
|
|
@@ -6986,14 +7082,14 @@ function isIdentityName(name) {
|
|
|
6986
7082
|
function claudeJsonPath(identitiesDir, identity) {
|
|
6987
7083
|
return import_node_path19.default.join(identitiesDir, identity, CLAUDE_JSON);
|
|
6988
7084
|
}
|
|
6989
|
-
function readAccountMetadata(
|
|
7085
|
+
function readAccountMetadata(fs15, identitiesDir, identity) {
|
|
6990
7086
|
if (!isIdentityName(identity)) {
|
|
6991
7087
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
6992
7088
|
}
|
|
6993
|
-
return readAccountMetadataFile(
|
|
7089
|
+
return readAccountMetadataFile(fs15, claudeJsonPath(identitiesDir, identity));
|
|
6994
7090
|
}
|
|
6995
|
-
function readAccountMetadataFile(
|
|
6996
|
-
const raw =
|
|
7091
|
+
function readAccountMetadataFile(fs15, file) {
|
|
7092
|
+
const raw = fs15.readFileUtf8(file);
|
|
6997
7093
|
if (raw === void 0) {
|
|
6998
7094
|
return void 0;
|
|
6999
7095
|
}
|
|
@@ -7023,19 +7119,19 @@ function readAccountMetadataFile(fs14, file) {
|
|
|
7023
7119
|
}
|
|
7024
7120
|
return account.data;
|
|
7025
7121
|
}
|
|
7026
|
-
function createAccountReader(
|
|
7122
|
+
function createAccountReader(fs15, identitiesDir) {
|
|
7027
7123
|
const cache = /* @__PURE__ */ new Map();
|
|
7028
7124
|
return (identity) => {
|
|
7029
7125
|
if (!isIdentityName(identity)) {
|
|
7030
7126
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
7031
7127
|
}
|
|
7032
|
-
const stat =
|
|
7128
|
+
const stat = fs15.lstat(claudeJsonPath(identitiesDir, identity));
|
|
7033
7129
|
const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
|
|
7034
7130
|
const cached = cache.get(identity);
|
|
7035
7131
|
if (cached?.stamp === stamp) {
|
|
7036
7132
|
return cached.account;
|
|
7037
7133
|
}
|
|
7038
|
-
const account = readAccountMetadata(
|
|
7134
|
+
const account = readAccountMetadata(fs15, identitiesDir, identity);
|
|
7039
7135
|
cache.set(identity, { stamp, account });
|
|
7040
7136
|
return account;
|
|
7041
7137
|
};
|
|
@@ -7072,9 +7168,9 @@ var init_accountDescription = __esm({
|
|
|
7072
7168
|
});
|
|
7073
7169
|
|
|
7074
7170
|
// src/identityAccounts.ts
|
|
7075
|
-
function readIdentityAccount(
|
|
7171
|
+
function readIdentityAccount(fs15, identitiesDir, identity) {
|
|
7076
7172
|
try {
|
|
7077
|
-
const account = readAccountMetadata(
|
|
7173
|
+
const account = readAccountMetadata(fs15, identitiesDir, identity);
|
|
7078
7174
|
return account === void 0 ? void 0 : { account };
|
|
7079
7175
|
} catch (error) {
|
|
7080
7176
|
if (error instanceof AccountMetadataError) {
|
|
@@ -7712,8 +7808,8 @@ function segmentDay(epochMs) {
|
|
|
7712
7808
|
function segmentName(day, pid) {
|
|
7713
7809
|
return `${day}.${String(pid)}.jsonl`;
|
|
7714
7810
|
}
|
|
7715
|
-
function listLogSegments(
|
|
7716
|
-
return
|
|
7811
|
+
function listLogSegments(fs15, logDir) {
|
|
7812
|
+
return fs15.readdir(logDir).flatMap((name) => {
|
|
7717
7813
|
const match = SEGMENT_RE.exec(name);
|
|
7718
7814
|
const day = match?.[1];
|
|
7719
7815
|
if (day === void 0) {
|
|
@@ -7722,15 +7818,15 @@ function listLogSegments(fs14, logDir) {
|
|
|
7722
7818
|
return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
|
|
7723
7819
|
}).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
|
|
7724
7820
|
}
|
|
7725
|
-
function readUsageLog(
|
|
7821
|
+
function readUsageLog(fs15, logDir, options = {}) {
|
|
7726
7822
|
const { sinceMs } = options;
|
|
7727
7823
|
const records = [];
|
|
7728
7824
|
let invalidLines = 0;
|
|
7729
|
-
for (const segment of listLogSegments(
|
|
7825
|
+
for (const segment of listLogSegments(fs15, logDir)) {
|
|
7730
7826
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
7731
7827
|
continue;
|
|
7732
7828
|
}
|
|
7733
|
-
const read = readSegment(
|
|
7829
|
+
const read = readSegment(fs15, logDir, segment);
|
|
7734
7830
|
if (read === void 0) {
|
|
7735
7831
|
continue;
|
|
7736
7832
|
}
|
|
@@ -7744,8 +7840,8 @@ function readUsageLog(fs14, logDir, options = {}) {
|
|
|
7744
7840
|
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
7745
7841
|
return { records, invalidLines };
|
|
7746
7842
|
}
|
|
7747
|
-
function readSegment(
|
|
7748
|
-
const contents =
|
|
7843
|
+
function readSegment(fs15, logDir, segment) {
|
|
7844
|
+
const contents = fs15.readFileUtf8(import_node_path20.default.join(logDir, segment.name));
|
|
7749
7845
|
if (contents === void 0) {
|
|
7750
7846
|
return void 0;
|
|
7751
7847
|
}
|
|
@@ -7779,9 +7875,9 @@ function snapshotPath(snapshotsDir, identity) {
|
|
|
7779
7875
|
}
|
|
7780
7876
|
return import_node_path20.default.join(snapshotsDir, `${identity}.json`);
|
|
7781
7877
|
}
|
|
7782
|
-
function readUsageSnapshot(
|
|
7878
|
+
function readUsageSnapshot(fs15, snapshotsDir, identity) {
|
|
7783
7879
|
const file = snapshotPath(snapshotsDir, identity);
|
|
7784
|
-
const raw =
|
|
7880
|
+
const raw = fs15.readFileUtf8(file);
|
|
7785
7881
|
if (raw === void 0) {
|
|
7786
7882
|
return void 0;
|
|
7787
7883
|
}
|
|
@@ -7797,8 +7893,8 @@ function readUsageSnapshot(fs14, snapshotsDir, identity) {
|
|
|
7797
7893
|
}
|
|
7798
7894
|
return snapshot.data;
|
|
7799
7895
|
}
|
|
7800
|
-
function listUsageSnapshots(
|
|
7801
|
-
return
|
|
7896
|
+
function listUsageSnapshots(fs15, snapshotsDir) {
|
|
7897
|
+
return fs15.readdir(snapshotsDir).flatMap((name) => {
|
|
7802
7898
|
if (!name.endsWith(".json")) {
|
|
7803
7899
|
return [];
|
|
7804
7900
|
}
|
|
@@ -7806,7 +7902,7 @@ function listUsageSnapshots(fs14, snapshotsDir) {
|
|
|
7806
7902
|
if (!isIdentityName(identity)) {
|
|
7807
7903
|
return [];
|
|
7808
7904
|
}
|
|
7809
|
-
const snapshot = readUsageSnapshot(
|
|
7905
|
+
const snapshot = readUsageSnapshot(fs15, snapshotsDir, identity);
|
|
7810
7906
|
return snapshot === void 0 ? [] : [snapshot];
|
|
7811
7907
|
}).sort((left, right) => left.identity.localeCompare(right.identity));
|
|
7812
7908
|
}
|
|
@@ -7831,11 +7927,11 @@ var init_read = __esm({
|
|
|
7831
7927
|
});
|
|
7832
7928
|
|
|
7833
7929
|
// src/usage/store.ts
|
|
7834
|
-
function pruneUsageLog(
|
|
7930
|
+
function pruneUsageLog(fs15, logDir, nowMs) {
|
|
7835
7931
|
const cutoff = nowMs - USAGE_RETENTION_MS;
|
|
7836
|
-
for (const segment of listLogSegments(
|
|
7932
|
+
for (const segment of listLogSegments(fs15, logDir)) {
|
|
7837
7933
|
if (segment.endsAt <= cutoff) {
|
|
7838
|
-
|
|
7934
|
+
fs15.removeRecursive(import_node_path21.default.join(logDir, segment.name));
|
|
7839
7935
|
}
|
|
7840
7936
|
}
|
|
7841
7937
|
}
|
|
@@ -7864,7 +7960,7 @@ function foldProviderState(current, record) {
|
|
|
7864
7960
|
};
|
|
7865
7961
|
}
|
|
7866
7962
|
function createUsageStore(deps) {
|
|
7867
|
-
const { fs:
|
|
7963
|
+
const { fs: fs15, paths } = deps;
|
|
7868
7964
|
let prunedDay;
|
|
7869
7965
|
const rewriteSnapshot = (identity, fold) => {
|
|
7870
7966
|
if (!isIdentityName(identity)) {
|
|
@@ -7873,7 +7969,7 @@ function createUsageStore(deps) {
|
|
|
7873
7969
|
}
|
|
7874
7970
|
let current;
|
|
7875
7971
|
try {
|
|
7876
|
-
current = readUsageSnapshot(
|
|
7972
|
+
current = readUsageSnapshot(fs15, paths.usageSnapshotsDir, identity);
|
|
7877
7973
|
} catch (error) {
|
|
7878
7974
|
if (!(error instanceof UsageSnapshotError)) {
|
|
7879
7975
|
throw error;
|
|
@@ -7900,8 +7996,8 @@ function createUsageStore(deps) {
|
|
|
7900
7996
|
...account === void 0 ? {} : { account },
|
|
7901
7997
|
providers
|
|
7902
7998
|
});
|
|
7903
|
-
|
|
7904
|
-
|
|
7999
|
+
fs15.mkdirPrivate(paths.usageSnapshotsDir);
|
|
8000
|
+
fs15.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
|
|
7905
8001
|
`);
|
|
7906
8002
|
deps.publish?.(snapshot);
|
|
7907
8003
|
return true;
|
|
@@ -7910,14 +8006,14 @@ function createUsageStore(deps) {
|
|
|
7910
8006
|
record: (input) => {
|
|
7911
8007
|
const record = UsageRecordSchema.parse(input);
|
|
7912
8008
|
const nowMs = deps.now();
|
|
7913
|
-
|
|
7914
|
-
|
|
8009
|
+
fs15.mkdirPrivate(paths.usageDir);
|
|
8010
|
+
fs15.mkdirPrivate(paths.usageLogDir);
|
|
7915
8011
|
const day = segmentDay(nowMs);
|
|
7916
8012
|
if (prunedDay !== day) {
|
|
7917
|
-
pruneUsageLog(
|
|
8013
|
+
pruneUsageLog(fs15, paths.usageLogDir, nowMs);
|
|
7918
8014
|
prunedDay = day;
|
|
7919
8015
|
}
|
|
7920
|
-
|
|
8016
|
+
fs15.appendFilePrivate(import_node_path21.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
|
|
7921
8017
|
`);
|
|
7922
8018
|
deps.onRecord?.(record);
|
|
7923
8019
|
if (record.identity !== void 0) {
|
|
@@ -7960,14 +8056,14 @@ var init_store2 = __esm({
|
|
|
7960
8056
|
function errorMessage(error) {
|
|
7961
8057
|
return error instanceof Error ? error.message : String(error);
|
|
7962
8058
|
}
|
|
7963
|
-
function loadPoolMembers(
|
|
8059
|
+
function loadPoolMembers(fs15, paths, identities, nowMs) {
|
|
7964
8060
|
const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
|
|
7965
|
-
const log = readUsageLog(
|
|
8061
|
+
const log = readUsageLog(fs15, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
7966
8062
|
return identities.map((identity) => {
|
|
7967
8063
|
const records = log.records.filter((record) => record.identity === identity && record.provider === ANTHROPIC_PROVIDER && Date.parse(record.at) >= windowStartMs);
|
|
7968
8064
|
try {
|
|
7969
|
-
const snapshot = readUsageSnapshot(
|
|
7970
|
-
const account = readAccountMetadata(
|
|
8065
|
+
const snapshot = readUsageSnapshot(fs15, paths.usageSnapshotsDir, identity);
|
|
8066
|
+
const account = readAccountMetadata(fs15, paths.identitiesDir, identity) ?? snapshot?.account;
|
|
7971
8067
|
return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
|
|
7972
8068
|
} catch (error) {
|
|
7973
8069
|
if (error instanceof UsageSnapshotError || error instanceof AccountMetadataError) {
|
|
@@ -8086,9 +8182,9 @@ function collectPoolIdentities(pools, poolName, stack, found) {
|
|
|
8086
8182
|
collectPoolIdentities(pools, nestedName, childStack, found);
|
|
8087
8183
|
}
|
|
8088
8184
|
}
|
|
8089
|
-
function readPicksFile(
|
|
8185
|
+
function readPicksFile(fs15, file) {
|
|
8090
8186
|
const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
|
|
8091
|
-
const raw =
|
|
8187
|
+
const raw = fs15.readFileUtf8(file);
|
|
8092
8188
|
if (raw === void 0) {
|
|
8093
8189
|
return { file: empty };
|
|
8094
8190
|
}
|
|
@@ -8101,17 +8197,17 @@ function readPicksFile(fs14, file) {
|
|
|
8101
8197
|
const result = PicksFileSchema.safeParse(parsed);
|
|
8102
8198
|
return result.success ? { file: result.data } : { file: empty, problem: `${file} is not a picks file this agent-shim can read` };
|
|
8103
8199
|
}
|
|
8104
|
-
function readStickyPick(
|
|
8105
|
-
const read = readPicksFile(
|
|
8200
|
+
function readStickyPick(fs15, picksFile, directory) {
|
|
8201
|
+
const read = readPicksFile(fs15, picksFile);
|
|
8106
8202
|
const entry = read.file.picks[directory];
|
|
8107
8203
|
return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
|
|
8108
8204
|
}
|
|
8109
|
-
function recordStickyPick(
|
|
8110
|
-
const current = readPicksFile(
|
|
8205
|
+
function recordStickyPick(fs15, picksFile, directory, identity, nowMs) {
|
|
8206
|
+
const current = readPicksFile(fs15, picksFile).file.picks;
|
|
8111
8207
|
const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
|
|
8112
8208
|
const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
|
|
8113
|
-
|
|
8114
|
-
|
|
8209
|
+
fs15.mkdirPrivate(import_node_path22.default.dirname(picksFile));
|
|
8210
|
+
fs15.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
8115
8211
|
`);
|
|
8116
8212
|
}
|
|
8117
8213
|
var import_node_path22, import_zod15, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
@@ -8145,9 +8241,9 @@ var init_poolPick = __esm({
|
|
|
8145
8241
|
});
|
|
8146
8242
|
|
|
8147
8243
|
// src/statusline/keys.ts
|
|
8148
|
-
function valueAt(source,
|
|
8244
|
+
function valueAt(source, path45) {
|
|
8149
8245
|
let current = source;
|
|
8150
|
-
for (const part of
|
|
8246
|
+
for (const part of path45) {
|
|
8151
8247
|
if (!isPlainObject(current)) {
|
|
8152
8248
|
return void 0;
|
|
8153
8249
|
}
|
|
@@ -8155,14 +8251,14 @@ function valueAt(source, path42) {
|
|
|
8155
8251
|
}
|
|
8156
8252
|
return current;
|
|
8157
8253
|
}
|
|
8158
|
-
function acceptsNull(
|
|
8159
|
-
const layer =
|
|
8254
|
+
function acceptsNull(path45) {
|
|
8255
|
+
const layer = path45.reduceRight((inner, part) => ({ [part]: inner }), null);
|
|
8160
8256
|
return StatuslineSchema.safeParse(layer).success;
|
|
8161
8257
|
}
|
|
8162
|
-
function keyOf(
|
|
8258
|
+
function keyOf(path45, declared) {
|
|
8163
8259
|
const optional = declared instanceof import_zod16.z.ZodOptional;
|
|
8164
8260
|
const leaf = optional ? declared.unwrap() : declared;
|
|
8165
|
-
const common = { path:
|
|
8261
|
+
const common = { path: path45.join("."), description: declared.description ?? "", defaultValue: valueAt(STATUSLINE_DEFAULTS, path45), optional, unsettable: acceptsNull(path45) };
|
|
8166
8262
|
if (leaf instanceof import_zod16.z.ZodNumber) {
|
|
8167
8263
|
return { ...common, kind: "integer", choices: [] };
|
|
8168
8264
|
}
|
|
@@ -8187,7 +8283,7 @@ function keyOf(path42, declared) {
|
|
|
8187
8283
|
if (leaf instanceof import_zod16.z.ZodArray && leaf.element instanceof import_zod16.z.ZodString) {
|
|
8188
8284
|
return { ...common, kind: "textList", choices: [] };
|
|
8189
8285
|
}
|
|
8190
|
-
throw new TypeError(`statusline setting ${
|
|
8286
|
+
throw new TypeError(`statusline setting ${path45.join(".")} has a kind the key listing does not describe`);
|
|
8191
8287
|
}
|
|
8192
8288
|
function walk(shape, prefix) {
|
|
8193
8289
|
return Object.entries(shape).flatMap(([name, schema]) => schema instanceof import_zod16.z.ZodObject ? walk(schema.shape, [...prefix, name]) : [keyOf([...prefix, name], schema)]);
|
|
@@ -8205,15 +8301,15 @@ var init_keys = __esm({
|
|
|
8205
8301
|
});
|
|
8206
8302
|
|
|
8207
8303
|
// src/statusline/change.ts
|
|
8208
|
-
function keyNamed(
|
|
8209
|
-
const found = statuslineKeys().find((key) => key.path ===
|
|
8304
|
+
function keyNamed(path45) {
|
|
8305
|
+
const found = statuslineKeys().find((key) => key.path === path45);
|
|
8210
8306
|
if (found === void 0) {
|
|
8211
|
-
throw new UsageError(`"${
|
|
8307
|
+
throw new UsageError(`"${path45}" is not a statusline setting; \`agent-shim statusline keys\` lists them.`);
|
|
8212
8308
|
}
|
|
8213
8309
|
return found;
|
|
8214
8310
|
}
|
|
8215
|
-
function setAt(target,
|
|
8216
|
-
const [head, ...rest] =
|
|
8311
|
+
function setAt(target, path45, value) {
|
|
8312
|
+
const [head, ...rest] = path45;
|
|
8217
8313
|
if (head === void 0) {
|
|
8218
8314
|
return;
|
|
8219
8315
|
}
|
|
@@ -8226,8 +8322,8 @@ function setAt(target, path42, value) {
|
|
|
8226
8322
|
target[head] = next;
|
|
8227
8323
|
setAt(next, rest, value);
|
|
8228
8324
|
}
|
|
8229
|
-
function removeAt(target,
|
|
8230
|
-
const [head, ...rest] =
|
|
8325
|
+
function removeAt(target, path45) {
|
|
8326
|
+
const [head, ...rest] = path45;
|
|
8231
8327
|
if (head === void 0) {
|
|
8232
8328
|
return;
|
|
8233
8329
|
}
|
|
@@ -8245,13 +8341,13 @@ function removeAt(target, path42) {
|
|
|
8245
8341
|
}
|
|
8246
8342
|
function applyStatuslineChange(existing, change) {
|
|
8247
8343
|
const draft = structuredClone(existing ?? {});
|
|
8248
|
-
for (const [
|
|
8249
|
-
keyNamed(
|
|
8250
|
-
setAt(draft,
|
|
8344
|
+
for (const [path45, value] of Object.entries(change.set ?? {})) {
|
|
8345
|
+
keyNamed(path45);
|
|
8346
|
+
setAt(draft, path45.split("."), value);
|
|
8251
8347
|
}
|
|
8252
|
-
for (const
|
|
8253
|
-
keyNamed(
|
|
8254
|
-
removeAt(draft,
|
|
8348
|
+
for (const path45 of change.unset ?? []) {
|
|
8349
|
+
keyNamed(path45);
|
|
8350
|
+
removeAt(draft, path45.split("."));
|
|
8255
8351
|
}
|
|
8256
8352
|
const result = StatuslineSchema.safeParse(draft);
|
|
8257
8353
|
if (!result.success) {
|
|
@@ -8537,6 +8633,8 @@ function buildLayoutPaths(root) {
|
|
|
8537
8633
|
usageAnchorsFile: import_node_path23.default.join(root, "usage", "anchors.json"),
|
|
8538
8634
|
usageJobsFile: import_node_path23.default.join(root, "usage", "jobs.json"),
|
|
8539
8635
|
jobLogsDir: import_node_path23.default.join(root, "logs", "jobs"),
|
|
8636
|
+
identityRenamesDir: import_node_path23.default.join(root, "identity-renames"),
|
|
8637
|
+
launchesDir: import_node_path23.default.join(root, "launches"),
|
|
8540
8638
|
superviseDir: import_node_path23.default.join(root, "supervise"),
|
|
8541
8639
|
modelMovesDir: import_node_path23.default.join(root, "model-moves"),
|
|
8542
8640
|
mcpPermissionsFile: import_node_path23.default.join(root, "mcp", "permissions.json")
|
|
@@ -9255,7 +9353,12 @@ function readProvider(paths, name) {
|
|
|
9255
9353
|
if (!import_node_fs6.default.existsSync(filePath)) {
|
|
9256
9354
|
return void 0;
|
|
9257
9355
|
}
|
|
9258
|
-
|
|
9356
|
+
let raw;
|
|
9357
|
+
try {
|
|
9358
|
+
raw = JSON.parse(import_node_fs6.default.readFileSync(filePath, "utf8"));
|
|
9359
|
+
} catch (error) {
|
|
9360
|
+
throw error instanceof SyntaxError ? new ConfigFileNotJsonError(filePath) : error;
|
|
9361
|
+
}
|
|
9259
9362
|
return parseProviderFile(filePath, raw);
|
|
9260
9363
|
}
|
|
9261
9364
|
function loadProvider(providersDir, name, port) {
|
|
@@ -9277,7 +9380,7 @@ function listProviders(paths, onInvalid = reportInvalidProvider) {
|
|
|
9277
9380
|
try {
|
|
9278
9381
|
provider = readProvider(paths, name);
|
|
9279
9382
|
} catch (error) {
|
|
9280
|
-
if (!(error instanceof ConfigValidationError || error instanceof LegacyProviderFileError || error instanceof UnsafeNameError)) {
|
|
9383
|
+
if (!(error instanceof ConfigValidationError || error instanceof LegacyProviderFileError || error instanceof ConfigFileNotJsonError || error instanceof UnsafeNameError)) {
|
|
9281
9384
|
throw error;
|
|
9282
9385
|
}
|
|
9283
9386
|
onInvalid(name, error.message);
|
|
@@ -9622,13 +9725,13 @@ function decideSignIn(facts) {
|
|
|
9622
9725
|
function credentialsFilePath(farmRoot) {
|
|
9623
9726
|
return import_node_path25.default.join(farmRoot, CREDENTIALS_FILE);
|
|
9624
9727
|
}
|
|
9625
|
-
function identitySignIn(
|
|
9728
|
+
function identitySignIn(fs15, probe, identity) {
|
|
9626
9729
|
const probing = !identity.hasCredentialBlock && identity.provider === void 0;
|
|
9627
9730
|
return decideSignIn({
|
|
9628
9731
|
hasCredentialBlock: identity.hasCredentialBlock,
|
|
9629
9732
|
provider: identity.provider,
|
|
9630
9733
|
keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
|
|
9631
|
-
credentialsFile: probing &&
|
|
9734
|
+
credentialsFile: probing && fs15.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
|
|
9632
9735
|
platform: probe.platform
|
|
9633
9736
|
});
|
|
9634
9737
|
}
|
|
@@ -10009,62 +10112,62 @@ var init_signatures = __esm({
|
|
|
10009
10112
|
});
|
|
10010
10113
|
|
|
10011
10114
|
// src/codex/anthropic.ts
|
|
10012
|
-
var
|
|
10115
|
+
var import_zod28, TextBlockSchema, Base64ImageSourceSchema, UrlImageSourceSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultContentBlockSchema, ToolResultBlockSchema, OtherBlockSchema, ContentBlockSchema, MessageSchema, ToolSchema, ToolChoiceSchema, SystemSchema, MessagesRequestSchema, CountTokensRequestSchema;
|
|
10013
10116
|
var init_anthropic = __esm({
|
|
10014
10117
|
"src/codex/anthropic.ts"() {
|
|
10015
10118
|
"use strict";
|
|
10016
|
-
|
|
10017
|
-
TextBlockSchema =
|
|
10018
|
-
Base64ImageSourceSchema =
|
|
10019
|
-
UrlImageSourceSchema =
|
|
10020
|
-
ImageBlockSchema =
|
|
10021
|
-
type:
|
|
10022
|
-
source:
|
|
10119
|
+
import_zod28 = require("zod");
|
|
10120
|
+
TextBlockSchema = import_zod28.z.looseObject({ type: import_zod28.z.literal("text"), text: import_zod28.z.string() });
|
|
10121
|
+
Base64ImageSourceSchema = import_zod28.z.looseObject({ type: import_zod28.z.literal("base64"), media_type: import_zod28.z.string().min(1), data: import_zod28.z.string() });
|
|
10122
|
+
UrlImageSourceSchema = import_zod28.z.looseObject({ type: import_zod28.z.literal("url"), url: import_zod28.z.string().min(1) });
|
|
10123
|
+
ImageBlockSchema = import_zod28.z.looseObject({
|
|
10124
|
+
type: import_zod28.z.literal("image"),
|
|
10125
|
+
source: import_zod28.z.union([Base64ImageSourceSchema, UrlImageSourceSchema])
|
|
10023
10126
|
});
|
|
10024
|
-
ToolUseBlockSchema =
|
|
10025
|
-
type:
|
|
10026
|
-
id:
|
|
10027
|
-
name:
|
|
10028
|
-
input:
|
|
10127
|
+
ToolUseBlockSchema = import_zod28.z.looseObject({
|
|
10128
|
+
type: import_zod28.z.literal("tool_use"),
|
|
10129
|
+
id: import_zod28.z.string().min(1),
|
|
10130
|
+
name: import_zod28.z.string().min(1),
|
|
10131
|
+
input: import_zod28.z.unknown()
|
|
10029
10132
|
});
|
|
10030
|
-
ToolResultContentBlockSchema =
|
|
10031
|
-
ToolResultBlockSchema =
|
|
10032
|
-
type:
|
|
10033
|
-
tool_use_id:
|
|
10034
|
-
content:
|
|
10133
|
+
ToolResultContentBlockSchema = import_zod28.z.union([TextBlockSchema, import_zod28.z.looseObject({ type: import_zod28.z.string() })]);
|
|
10134
|
+
ToolResultBlockSchema = import_zod28.z.looseObject({
|
|
10135
|
+
type: import_zod28.z.literal("tool_result"),
|
|
10136
|
+
tool_use_id: import_zod28.z.string().min(1),
|
|
10137
|
+
content: import_zod28.z.union([import_zod28.z.string(), import_zod28.z.array(ToolResultContentBlockSchema)]).optional()
|
|
10035
10138
|
});
|
|
10036
|
-
OtherBlockSchema =
|
|
10037
|
-
ContentBlockSchema =
|
|
10038
|
-
MessageSchema =
|
|
10039
|
-
role:
|
|
10040
|
-
content:
|
|
10139
|
+
OtherBlockSchema = import_zod28.z.looseObject({ type: import_zod28.z.string() });
|
|
10140
|
+
ContentBlockSchema = import_zod28.z.union([TextBlockSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultBlockSchema, OtherBlockSchema]);
|
|
10141
|
+
MessageSchema = import_zod28.z.looseObject({
|
|
10142
|
+
role: import_zod28.z.enum(["user", "assistant", "system"]),
|
|
10143
|
+
content: import_zod28.z.union([import_zod28.z.string(), import_zod28.z.array(ContentBlockSchema)])
|
|
10041
10144
|
});
|
|
10042
|
-
ToolSchema =
|
|
10043
|
-
name:
|
|
10044
|
-
description:
|
|
10045
|
-
input_schema:
|
|
10145
|
+
ToolSchema = import_zod28.z.looseObject({
|
|
10146
|
+
name: import_zod28.z.string().min(1),
|
|
10147
|
+
description: import_zod28.z.string().optional(),
|
|
10148
|
+
input_schema: import_zod28.z.record(import_zod28.z.string(), import_zod28.z.unknown()).optional()
|
|
10046
10149
|
});
|
|
10047
|
-
ToolChoiceSchema =
|
|
10048
|
-
|
|
10049
|
-
|
|
10150
|
+
ToolChoiceSchema = import_zod28.z.union([
|
|
10151
|
+
import_zod28.z.looseObject({ type: import_zod28.z.enum(["auto", "none", "any"]) }),
|
|
10152
|
+
import_zod28.z.looseObject({ type: import_zod28.z.literal("tool"), name: import_zod28.z.string().min(1) })
|
|
10050
10153
|
]);
|
|
10051
|
-
SystemSchema =
|
|
10052
|
-
MessagesRequestSchema =
|
|
10053
|
-
model:
|
|
10154
|
+
SystemSchema = import_zod28.z.union([import_zod28.z.string(), import_zod28.z.array(import_zod28.z.union([TextBlockSchema, OtherBlockSchema]))]);
|
|
10155
|
+
MessagesRequestSchema = import_zod28.z.looseObject({
|
|
10156
|
+
model: import_zod28.z.string().optional(),
|
|
10054
10157
|
system: SystemSchema.optional(),
|
|
10055
|
-
messages:
|
|
10056
|
-
tools:
|
|
10158
|
+
messages: import_zod28.z.array(MessageSchema),
|
|
10159
|
+
tools: import_zod28.z.array(ToolSchema).optional(),
|
|
10057
10160
|
tool_choice: ToolChoiceSchema.optional(),
|
|
10058
|
-
stream:
|
|
10161
|
+
stream: import_zod28.z.boolean().optional(),
|
|
10059
10162
|
/** `user_id` is stable for one Claude Code session and differs between sessions, which is what makes it the right key for both the backend's prompt cache and its session header. */
|
|
10060
|
-
metadata:
|
|
10163
|
+
metadata: import_zod28.z.looseObject({ user_id: import_zod28.z.string().optional() }).optional(),
|
|
10061
10164
|
/** Claude Code's effort setting. Any string is accepted; the translator honours only the levels the backend understands. */
|
|
10062
|
-
output_config:
|
|
10165
|
+
output_config: import_zod28.z.looseObject({ effort: import_zod28.z.string().optional() }).optional()
|
|
10063
10166
|
});
|
|
10064
|
-
CountTokensRequestSchema =
|
|
10065
|
-
system:
|
|
10066
|
-
messages:
|
|
10067
|
-
tools:
|
|
10167
|
+
CountTokensRequestSchema = import_zod28.z.looseObject({
|
|
10168
|
+
system: import_zod28.z.unknown().optional(),
|
|
10169
|
+
messages: import_zod28.z.unknown().optional(),
|
|
10170
|
+
tools: import_zod28.z.unknown().optional()
|
|
10068
10171
|
});
|
|
10069
10172
|
}
|
|
10070
10173
|
});
|
|
@@ -10166,12 +10269,12 @@ function filterCatalogue(models, catalogue) {
|
|
|
10166
10269
|
const excluded = catalogue.exclude === void 0 ? void 0 : (0, import_picomatch4.default)(catalogue.exclude, { dot: true });
|
|
10167
10270
|
return models.filter((model) => included?.(model.id) !== false && excluded?.(model.id) !== true);
|
|
10168
10271
|
}
|
|
10169
|
-
var import_picomatch4,
|
|
10272
|
+
var import_picomatch4, import_zod29, DEFAULT_CANDIDATE_URLS, MS_PER_SECOND5, SECONDS_PER_HOUR2, HOURS_PER_DAY5, MS_PER_HOUR4, HOURS_BETWEEN_RETRIES, CATALOGUE_MAX_AGE_MS, CATALOGUE_RETRY_MS, CATALOGUE_REQUEST_SECONDS, CATALOGUE_REQUEST_TIMEOUT_MS, CATALOGUE_REFRESH_TIMEOUT_MS, CatalogueModelSchema, CatalogueCacheSchema;
|
|
10170
10273
|
var init_providerCatalogue = __esm({
|
|
10171
10274
|
"src/providerCatalogue.ts"() {
|
|
10172
10275
|
"use strict";
|
|
10173
10276
|
import_picomatch4 = __toESM(require("picomatch"), 1);
|
|
10174
|
-
|
|
10277
|
+
import_zod29 = require("zod");
|
|
10175
10278
|
init_names();
|
|
10176
10279
|
DEFAULT_CANDIDATE_URLS = 2;
|
|
10177
10280
|
MS_PER_SECOND5 = 1e3;
|
|
@@ -10184,8 +10287,8 @@ var init_providerCatalogue = __esm({
|
|
|
10184
10287
|
CATALOGUE_REQUEST_SECONDS = 10;
|
|
10185
10288
|
CATALOGUE_REQUEST_TIMEOUT_MS = CATALOGUE_REQUEST_SECONDS * MS_PER_SECOND5;
|
|
10186
10289
|
CATALOGUE_REFRESH_TIMEOUT_MS = DEFAULT_CANDIDATE_URLS * CATALOGUE_REQUEST_TIMEOUT_MS;
|
|
10187
|
-
CatalogueModelSchema =
|
|
10188
|
-
CatalogueCacheSchema =
|
|
10290
|
+
CatalogueModelSchema = import_zod29.z.strictObject({ id: import_zod29.z.string().min(1), name: import_zod29.z.string().min(1).optional() });
|
|
10291
|
+
CatalogueCacheSchema = import_zod29.z.strictObject({ fetchedAt: import_zod29.z.number(), url: import_zod29.z.string().min(1), models: import_zod29.z.array(CatalogueModelSchema) });
|
|
10189
10292
|
}
|
|
10190
10293
|
});
|
|
10191
10294
|
|
|
@@ -10492,6 +10595,60 @@ var init_proxyBypass2 = __esm({
|
|
|
10492
10595
|
}
|
|
10493
10596
|
});
|
|
10494
10597
|
|
|
10598
|
+
// src/replayRun.ts
|
|
10599
|
+
function keyOf2(command, args) {
|
|
10600
|
+
return JSON.stringify([command, args]);
|
|
10601
|
+
}
|
|
10602
|
+
async function recordRuns(decide, runAsync) {
|
|
10603
|
+
const answers = /* @__PURE__ */ new Map();
|
|
10604
|
+
const replay = {
|
|
10605
|
+
run: (command, args) => {
|
|
10606
|
+
const answer = answers.get(keyOf2(command, args));
|
|
10607
|
+
if (answer === void 0) {
|
|
10608
|
+
throw new RunNeededError(command, args);
|
|
10609
|
+
}
|
|
10610
|
+
return answer;
|
|
10611
|
+
}
|
|
10612
|
+
};
|
|
10613
|
+
for (; ; ) {
|
|
10614
|
+
try {
|
|
10615
|
+
decide(replay);
|
|
10616
|
+
return replay;
|
|
10617
|
+
} catch (error) {
|
|
10618
|
+
if (!(error instanceof RunNeededError)) {
|
|
10619
|
+
throw error;
|
|
10620
|
+
}
|
|
10621
|
+
answers.set(keyOf2(error.command, error.args), await runAsync(error.command, error.args));
|
|
10622
|
+
}
|
|
10623
|
+
}
|
|
10624
|
+
}
|
|
10625
|
+
async function resolveWithAsyncRuns(decide, runAsync) {
|
|
10626
|
+
let result;
|
|
10627
|
+
await recordRuns((run) => {
|
|
10628
|
+
result = { value: decide(run) };
|
|
10629
|
+
}, runAsync);
|
|
10630
|
+
if (result === void 0) {
|
|
10631
|
+
throw new Error("the decision finished without a result");
|
|
10632
|
+
}
|
|
10633
|
+
return result.value;
|
|
10634
|
+
}
|
|
10635
|
+
var RunNeededError;
|
|
10636
|
+
var init_replayRun = __esm({
|
|
10637
|
+
"src/replayRun.ts"() {
|
|
10638
|
+
"use strict";
|
|
10639
|
+
RunNeededError = class extends Error {
|
|
10640
|
+
constructor(command, args) {
|
|
10641
|
+
super(`no recorded answer for ${command} ${args.join(" ")}`);
|
|
10642
|
+
this.command = command;
|
|
10643
|
+
this.args = args;
|
|
10644
|
+
this.name = "RunNeededError";
|
|
10645
|
+
}
|
|
10646
|
+
command;
|
|
10647
|
+
args;
|
|
10648
|
+
};
|
|
10649
|
+
}
|
|
10650
|
+
});
|
|
10651
|
+
|
|
10495
10652
|
// src/update/update.ts
|
|
10496
10653
|
function compareVersions3(left, right) {
|
|
10497
10654
|
const parse = (version) => {
|
|
@@ -10998,6 +11155,59 @@ var init_cliOverride = __esm({
|
|
|
10998
11155
|
}
|
|
10999
11156
|
});
|
|
11000
11157
|
|
|
11158
|
+
// src/launcher/launchRecords.ts
|
|
11159
|
+
function recordFile(directory, pid, identity) {
|
|
11160
|
+
return import_node_path38.default.join(directory, `${String(pid)}.${identity}${RECORD_SUFFIX}`);
|
|
11161
|
+
}
|
|
11162
|
+
function readRecord(fs15, directory, name) {
|
|
11163
|
+
if (!name.endsWith(RECORD_SUFFIX)) {
|
|
11164
|
+
return void 0;
|
|
11165
|
+
}
|
|
11166
|
+
const raw = fs15.readFileUtf8(import_node_path38.default.join(directory, name));
|
|
11167
|
+
if (raw === void 0) {
|
|
11168
|
+
return void 0;
|
|
11169
|
+
}
|
|
11170
|
+
let parsed;
|
|
11171
|
+
try {
|
|
11172
|
+
parsed = JSON.parse(raw);
|
|
11173
|
+
} catch {
|
|
11174
|
+
return void 0;
|
|
11175
|
+
}
|
|
11176
|
+
const result = LaunchRecordSchema.safeParse(parsed);
|
|
11177
|
+
return result.success ? result.data : void 0;
|
|
11178
|
+
}
|
|
11179
|
+
function registerLaunch(fs15, directory, owner, isRunning) {
|
|
11180
|
+
fs15.mkdirPrivate(directory);
|
|
11181
|
+
for (const name of fs15.readdir(directory)) {
|
|
11182
|
+
const record2 = readRecord(fs15, directory, name);
|
|
11183
|
+
if (record2 !== void 0 && !isRunning(record2.pid)) {
|
|
11184
|
+
fs15.removeRecursive(import_node_path38.default.join(directory, name));
|
|
11185
|
+
}
|
|
11186
|
+
}
|
|
11187
|
+
const file = recordFile(directory, owner.pid, owner.identity);
|
|
11188
|
+
const record = { pid: owner.pid, identity: owner.identity, startedAt: new Date(owner.startedAtMs).toISOString() };
|
|
11189
|
+
fs15.writeFilePrivate(file, `${JSON.stringify(record)}
|
|
11190
|
+
`);
|
|
11191
|
+
return () => {
|
|
11192
|
+
fs15.removeRecursive(file);
|
|
11193
|
+
};
|
|
11194
|
+
}
|
|
11195
|
+
var import_node_path38, import_zod36, LaunchRecordSchema, RECORD_SUFFIX;
|
|
11196
|
+
var init_launchRecords = __esm({
|
|
11197
|
+
"src/launcher/launchRecords.ts"() {
|
|
11198
|
+
"use strict";
|
|
11199
|
+
import_node_path38 = __toESM(require("node:path"), 1);
|
|
11200
|
+
import_zod36 = require("zod");
|
|
11201
|
+
LaunchRecordSchema = import_zod36.z.strictObject({
|
|
11202
|
+
/** The launcher's process id, which is what tells a launch in progress from a record a crashed launcher left behind. */
|
|
11203
|
+
pid: import_zod36.z.number().int().positive(),
|
|
11204
|
+
identity: import_zod36.z.string().min(1),
|
|
11205
|
+
startedAt: import_zod36.z.iso.datetime()
|
|
11206
|
+
});
|
|
11207
|
+
RECORD_SUFFIX = ".json";
|
|
11208
|
+
}
|
|
11209
|
+
});
|
|
11210
|
+
|
|
11001
11211
|
// src/headroom/headers.ts
|
|
11002
11212
|
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
11003
11213
|
const merged = /* @__PURE__ */ new Map();
|
|
@@ -11121,7 +11331,7 @@ function buildEnv(params) {
|
|
|
11121
11331
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
11122
11332
|
let providerCustomHeaders;
|
|
11123
11333
|
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
11124
|
-
env.CLAUDE_CONFIG_DIR =
|
|
11334
|
+
env.CLAUDE_CONFIG_DIR = import_node_path39.default.join(params.identitiesDir, params.resolvedIdentityName);
|
|
11125
11335
|
}
|
|
11126
11336
|
if (params.provider !== void 0) {
|
|
11127
11337
|
const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
|
|
@@ -11175,11 +11385,11 @@ function buildEnv(params) {
|
|
|
11175
11385
|
}
|
|
11176
11386
|
return env;
|
|
11177
11387
|
}
|
|
11178
|
-
var
|
|
11388
|
+
var import_node_path39, LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
|
|
11179
11389
|
var init_flags = __esm({
|
|
11180
11390
|
"src/launcher/flags.ts"() {
|
|
11181
11391
|
"use strict";
|
|
11182
|
-
|
|
11392
|
+
import_node_path39 = __toESM(require("node:path"), 1);
|
|
11183
11393
|
init_envBool();
|
|
11184
11394
|
init_cliError();
|
|
11185
11395
|
init_conditions();
|
|
@@ -11264,15 +11474,15 @@ function contextTokensOfTranscript(text) {
|
|
|
11264
11474
|
}
|
|
11265
11475
|
return void 0;
|
|
11266
11476
|
}
|
|
11267
|
-
function newestTranscript(
|
|
11477
|
+
function newestTranscript(fs15, projectDir) {
|
|
11268
11478
|
let newest;
|
|
11269
11479
|
let newestMs = -Infinity;
|
|
11270
|
-
for (const name of
|
|
11480
|
+
for (const name of fs15.readdir(projectDir)) {
|
|
11271
11481
|
if (!name.endsWith(".jsonl")) {
|
|
11272
11482
|
continue;
|
|
11273
11483
|
}
|
|
11274
|
-
const candidate =
|
|
11275
|
-
const stat =
|
|
11484
|
+
const candidate = import_node_path40.default.join(projectDir, name);
|
|
11485
|
+
const stat = fs15.lstat(candidate);
|
|
11276
11486
|
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
11277
11487
|
newestMs = stat.mtimeMs;
|
|
11278
11488
|
newest = candidate;
|
|
@@ -11280,21 +11490,21 @@ function newestTranscript(fs14, projectDir) {
|
|
|
11280
11490
|
}
|
|
11281
11491
|
return newest;
|
|
11282
11492
|
}
|
|
11283
|
-
function resumedContextTokens(
|
|
11493
|
+
function resumedContextTokens(fs15, params) {
|
|
11284
11494
|
const target = resumeTargetOf(params.passthrough);
|
|
11285
11495
|
if (target === void 0) {
|
|
11286
11496
|
return void 0;
|
|
11287
11497
|
}
|
|
11288
|
-
const projectDir =
|
|
11289
|
-
const file = target.kind === "id" ?
|
|
11290
|
-
const text = file === void 0 ? void 0 :
|
|
11498
|
+
const projectDir = import_node_path40.default.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
11499
|
+
const file = target.kind === "id" ? import_node_path40.default.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs15, projectDir);
|
|
11500
|
+
const text = file === void 0 ? void 0 : fs15.readFileUtf8(file);
|
|
11291
11501
|
return text === void 0 ? void 0 : contextTokensOfTranscript(text);
|
|
11292
11502
|
}
|
|
11293
|
-
var
|
|
11503
|
+
var import_node_path40;
|
|
11294
11504
|
var init_resumeContext = __esm({
|
|
11295
11505
|
"src/usage/resumeContext.ts"() {
|
|
11296
11506
|
"use strict";
|
|
11297
|
-
|
|
11507
|
+
import_node_path40 = __toESM(require("node:path"), 1);
|
|
11298
11508
|
}
|
|
11299
11509
|
});
|
|
11300
11510
|
|
|
@@ -11891,7 +12101,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
|
|
|
11891
12101
|
return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
|
|
11892
12102
|
}
|
|
11893
12103
|
function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
11894
|
-
const { paths, fs:
|
|
12104
|
+
const { paths, fs: fs15, proc, log } = params;
|
|
11895
12105
|
if (decided.pool === void 0) {
|
|
11896
12106
|
return { identityDecision: decided };
|
|
11897
12107
|
}
|
|
@@ -11910,7 +12120,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
11910
12120
|
selectedVia: decided.source,
|
|
11911
12121
|
pools: params.pools,
|
|
11912
12122
|
paths,
|
|
11913
|
-
fs:
|
|
12123
|
+
fs: fs15,
|
|
11914
12124
|
usageFs: farmRuntime.fs,
|
|
11915
12125
|
cwd: farmRuntime.cwd,
|
|
11916
12126
|
now: farmRuntime.now,
|
|
@@ -11934,7 +12144,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
11934
12144
|
};
|
|
11935
12145
|
}
|
|
11936
12146
|
function decideLaunch(params, readOnly) {
|
|
11937
|
-
const { paths, fs:
|
|
12147
|
+
const { paths, fs: fs15, proc, log } = params;
|
|
11938
12148
|
const { env, argv } = proc;
|
|
11939
12149
|
const parsedArgv = parseLauncherArgv(argv);
|
|
11940
12150
|
const cliOverride = buildCliOverride({
|
|
@@ -11949,7 +12159,7 @@ function decideLaunch(params, readOnly) {
|
|
|
11949
12159
|
argv0Identity: params.pickedIdentity ?? parsedArgv.identity,
|
|
11950
12160
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
11951
12161
|
readActiveIdentityFile: () => {
|
|
11952
|
-
const raw =
|
|
12162
|
+
const raw = fs15.readFileUtf8(paths.activeIdentityFile);
|
|
11953
12163
|
if (raw === void 0) {
|
|
11954
12164
|
return void 0;
|
|
11955
12165
|
}
|
|
@@ -11984,7 +12194,7 @@ function decideLaunch(params, readOnly) {
|
|
|
11984
12194
|
}
|
|
11985
12195
|
let loadedIdentity;
|
|
11986
12196
|
if (identityDecision.name !== void 0) {
|
|
11987
|
-
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name,
|
|
12197
|
+
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs15);
|
|
11988
12198
|
if (loadedIdentity === void 0) {
|
|
11989
12199
|
log.error(
|
|
11990
12200
|
`agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
|
|
@@ -11999,7 +12209,7 @@ function decideLaunch(params, readOnly) {
|
|
|
11999
12209
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
12000
12210
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
12001
12211
|
});
|
|
12002
|
-
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true &&
|
|
12212
|
+
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs15.readConfigFile(profileFilePath(paths.configProfilesDir, configProfileDecision.name, `the configuration profile selected via ${configProfileDecision.source}`)) === void 0) {
|
|
12003
12213
|
log.error(
|
|
12004
12214
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
12005
12215
|
);
|
|
@@ -12008,7 +12218,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12008
12218
|
const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
|
|
12009
12219
|
const providerParams = {
|
|
12010
12220
|
paths,
|
|
12011
|
-
port:
|
|
12221
|
+
port: fs15,
|
|
12012
12222
|
...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
|
|
12013
12223
|
...farmContext === void 0 ? {} : { cascade: farmContext.cascade },
|
|
12014
12224
|
...loadedIdentity?.config.provider === void 0 ? {} : { identityProvider: loadedIdentity.config.provider }
|
|
@@ -12120,9 +12330,9 @@ function decideLaunch(params, readOnly) {
|
|
|
12120
12330
|
const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
|
|
12121
12331
|
const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
|
|
12122
12332
|
const models = launchCascade !== void 0 && params.farm !== void 0 ? cascadeModels : globalModels;
|
|
12123
|
-
const listedProviders = listProviderNames(
|
|
12333
|
+
const listedProviders = listProviderNames(fs15.readdir, paths.providersDir).flatMap((name) => {
|
|
12124
12334
|
try {
|
|
12125
|
-
const definition = loadProvider(paths.providersDir, name,
|
|
12335
|
+
const definition = loadProvider(paths.providersDir, name, fs15);
|
|
12126
12336
|
return definition === void 0 ? [] : [[name, definition, parseCatalogueCache(params.fs.readFileUtf8(catalogueCachePath(paths, name)))?.models ?? []]];
|
|
12127
12337
|
} catch {
|
|
12128
12338
|
return [];
|
|
@@ -12140,7 +12350,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12140
12350
|
extraFlags: splitExtraFlags(env.CLAUDE_EXTRA_FLAGS),
|
|
12141
12351
|
passthrough: withLauncherSettings(params.supervised === void 0 ? parsedArgv.rest : withSupervision(parsedArgv.rest, params.supervised), launcherSettings)
|
|
12142
12352
|
}) : [...parsedArgv.rest];
|
|
12143
|
-
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR :
|
|
12353
|
+
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : import_node_path41.default.join(paths.identitiesDir, identityDecision.name);
|
|
12144
12354
|
const decision = {
|
|
12145
12355
|
identitySource: identityDecision.source,
|
|
12146
12356
|
configDirEscapeHatch: identityDecision.configDirEscapeHatch,
|
|
@@ -12178,6 +12388,19 @@ function decideLaunch(params, readOnly) {
|
|
|
12178
12388
|
};
|
|
12179
12389
|
}
|
|
12180
12390
|
function prepareLaunch(params) {
|
|
12391
|
+
const removers = [];
|
|
12392
|
+
try {
|
|
12393
|
+
return prepareRegisteredLaunch(params, (remove) => {
|
|
12394
|
+
removers.push(remove);
|
|
12395
|
+
});
|
|
12396
|
+
} catch (error) {
|
|
12397
|
+
for (const remove of removers) {
|
|
12398
|
+
remove();
|
|
12399
|
+
}
|
|
12400
|
+
throw error;
|
|
12401
|
+
}
|
|
12402
|
+
}
|
|
12403
|
+
function prepareRegisteredLaunch(params, onRecorded) {
|
|
12181
12404
|
const { paths, proc, log } = params;
|
|
12182
12405
|
const { env } = proc;
|
|
12183
12406
|
const decided = decideLaunch(params, false);
|
|
@@ -12198,14 +12421,17 @@ function prepareLaunch(params) {
|
|
|
12198
12421
|
})
|
|
12199
12422
|
];
|
|
12200
12423
|
let warnings = [];
|
|
12424
|
+
let unregisterLaunch;
|
|
12201
12425
|
const updateCheck = runLaunchUpdateCheck({
|
|
12202
12426
|
mode: params.updateMode ?? "off",
|
|
12203
|
-
checkPath:
|
|
12427
|
+
checkPath: import_node_path41.default.join(paths.root, "update.check"),
|
|
12204
12428
|
currentVersion: package_default.version,
|
|
12205
12429
|
port: params.update
|
|
12206
12430
|
});
|
|
12207
12431
|
if (decided.farmContext !== void 0) {
|
|
12208
12432
|
const { farm: resyncFarmRuntime, identity: resyncIdentity, cascade } = decided.farmContext;
|
|
12433
|
+
unregisterLaunch = registerLaunch(resyncFarmRuntime.fs, paths.launchesDir, { pid: resyncFarmRuntime.lock.pid, identity: resyncIdentity, startedAtMs: resyncFarmRuntime.now() }, resyncFarmRuntime.lock.isRunning);
|
|
12434
|
+
onRecorded(unregisterLaunch);
|
|
12209
12435
|
let result;
|
|
12210
12436
|
try {
|
|
12211
12437
|
result = resyncFarm({
|
|
@@ -12223,10 +12449,11 @@ function prepareLaunch(params) {
|
|
|
12223
12449
|
classification: resyncFarmRuntime.classification,
|
|
12224
12450
|
now: resyncFarmRuntime.now,
|
|
12225
12451
|
uniqueSuffix: resyncFarmRuntime.uniqueSuffix,
|
|
12452
|
+
identityExists: () => loadIdentity(paths.identitiesDir, resyncIdentity, params.fs) !== void 0,
|
|
12226
12453
|
lock: resyncFarmRuntime.lock
|
|
12227
12454
|
});
|
|
12228
12455
|
} catch (error) {
|
|
12229
|
-
if (error instanceof IdentityLockBusyError) {
|
|
12456
|
+
if (error instanceof IdentityLockBusyError || error instanceof IdentityGoneError) {
|
|
12230
12457
|
log.error(error.message);
|
|
12231
12458
|
proc.exit(1);
|
|
12232
12459
|
}
|
|
@@ -12286,7 +12513,7 @@ function prepareLaunch(params) {
|
|
|
12286
12513
|
proxyBypass: resolvedFlags.proxyBypass,
|
|
12287
12514
|
...resolvedFlags.statusline === void 0 ? {} : { statusline: resolvedFlags.statusline }
|
|
12288
12515
|
});
|
|
12289
|
-
const releases = [...headroom === void 0 || headroomPort === void 0 ? [] : [headroomPort.release], ...frontDoorRelease === void 0 ? [] : [frontDoorRelease]];
|
|
12516
|
+
const releases = [...unregisterLaunch === void 0 ? [] : [unregisterLaunch], ...headroom === void 0 || headroomPort === void 0 ? [] : [headroomPort.release], ...frontDoorRelease === void 0 ? [] : [frontDoorRelease]];
|
|
12290
12517
|
const release = () => {
|
|
12291
12518
|
for (const registered of releases) {
|
|
12292
12519
|
registered();
|
|
@@ -12347,18 +12574,19 @@ function runLaunchPlan(plan, spawn3) {
|
|
|
12347
12574
|
function runLauncher(params) {
|
|
12348
12575
|
params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
|
|
12349
12576
|
}
|
|
12350
|
-
var import_node_crypto11, import_node_util2,
|
|
12577
|
+
var import_node_crypto11, import_node_util2, import_node_path41;
|
|
12351
12578
|
var init_launcher = __esm({
|
|
12352
12579
|
"src/launcher.ts"() {
|
|
12353
12580
|
"use strict";
|
|
12354
12581
|
import_node_crypto11 = require("node:crypto");
|
|
12355
12582
|
import_node_util2 = require("node:util");
|
|
12356
|
-
|
|
12583
|
+
import_node_path41 = __toESM(require("node:path"), 1);
|
|
12357
12584
|
init_package();
|
|
12358
12585
|
init_envBool();
|
|
12359
12586
|
init_argv();
|
|
12360
12587
|
init_cliOverride();
|
|
12361
12588
|
init_farm();
|
|
12589
|
+
init_launchRecords();
|
|
12362
12590
|
init_guard();
|
|
12363
12591
|
init_identity();
|
|
12364
12592
|
init_flags();
|
|
@@ -12398,13 +12626,13 @@ function agentShimCliPath(distDir = typeof __AGENT_SHIM_DIST_DIR__ === "string"
|
|
|
12398
12626
|
if (distDir === void 0) {
|
|
12399
12627
|
throw new OwnCliPathUnknownError();
|
|
12400
12628
|
}
|
|
12401
|
-
return
|
|
12629
|
+
return import_node_path42.default.join(distDir, OWN_CLI_FILE_NAME);
|
|
12402
12630
|
}
|
|
12403
|
-
var
|
|
12631
|
+
var import_node_path42, OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
|
|
12404
12632
|
var init_ownCli = __esm({
|
|
12405
12633
|
"src/ownCli.ts"() {
|
|
12406
12634
|
"use strict";
|
|
12407
|
-
|
|
12635
|
+
import_node_path42 = __toESM(require("node:path"), 1);
|
|
12408
12636
|
init_cliError();
|
|
12409
12637
|
OWN_CLI_FILE_NAME = "cli.cjs";
|
|
12410
12638
|
OwnCliPathUnknownError = class extends CliError {
|
|
@@ -12418,15 +12646,15 @@ var init_ownCli = __esm({
|
|
|
12418
12646
|
|
|
12419
12647
|
// src/frontdoor/doorLog.ts
|
|
12420
12648
|
function appendDoorLog(paths, line) {
|
|
12421
|
-
|
|
12422
|
-
|
|
12649
|
+
import_node_fs13.default.mkdirSync(paths.logsDir, { recursive: true });
|
|
12650
|
+
import_node_fs13.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
12423
12651
|
`);
|
|
12424
12652
|
}
|
|
12425
|
-
var
|
|
12653
|
+
var import_node_fs13;
|
|
12426
12654
|
var init_doorLog = __esm({
|
|
12427
12655
|
"src/frontdoor/doorLog.ts"() {
|
|
12428
12656
|
"use strict";
|
|
12429
|
-
|
|
12657
|
+
import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
12430
12658
|
}
|
|
12431
12659
|
});
|
|
12432
12660
|
|
|
@@ -12446,14 +12674,14 @@ var init_selfIdentity = __esm({
|
|
|
12446
12674
|
|
|
12447
12675
|
// src/frontdoor/trust.ts
|
|
12448
12676
|
function resolveTrustBundle(params) {
|
|
12449
|
-
const { caCertFile, bundlesDir, variable, inherited, fs:
|
|
12450
|
-
if (inherited === void 0 || inherited === "" ||
|
|
12677
|
+
const { caCertFile, bundlesDir, variable, inherited, fs: fs15 } = params;
|
|
12678
|
+
if (inherited === void 0 || inherited === "" || import_node_path43.default.resolve(inherited) === import_node_path43.default.resolve(caCertFile)) {
|
|
12451
12679
|
return { path: caCertFile };
|
|
12452
12680
|
}
|
|
12453
|
-
const caPem =
|
|
12681
|
+
const caPem = fs15.readFileUtf8(caCertFile);
|
|
12454
12682
|
let inheritedPem;
|
|
12455
12683
|
try {
|
|
12456
|
-
inheritedPem =
|
|
12684
|
+
inheritedPem = fs15.readFileUtf8(inherited);
|
|
12457
12685
|
} catch (error) {
|
|
12458
12686
|
return {
|
|
12459
12687
|
path: caCertFile,
|
|
@@ -12465,19 +12693,19 @@ function resolveTrustBundle(params) {
|
|
|
12465
12693
|
}
|
|
12466
12694
|
const combined = `${inheritedPem.trimEnd()}
|
|
12467
12695
|
${caPem}`;
|
|
12468
|
-
const bundle =
|
|
12469
|
-
if (!
|
|
12470
|
-
|
|
12471
|
-
|
|
12696
|
+
const bundle = import_node_path43.default.join(bundlesDir, `${(0, import_node_crypto12.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
12697
|
+
if (!fs15.exists(bundle)) {
|
|
12698
|
+
fs15.mkdirp(bundlesDir);
|
|
12699
|
+
fs15.writeFileAtomic(bundle, combined);
|
|
12472
12700
|
}
|
|
12473
12701
|
return { path: bundle };
|
|
12474
12702
|
}
|
|
12475
|
-
var import_node_crypto12,
|
|
12703
|
+
var import_node_crypto12, import_node_path43, BUNDLE_NAME_HEX_DIGITS;
|
|
12476
12704
|
var init_trust = __esm({
|
|
12477
12705
|
"src/frontdoor/trust.ts"() {
|
|
12478
12706
|
"use strict";
|
|
12479
12707
|
import_node_crypto12 = require("node:crypto");
|
|
12480
|
-
|
|
12708
|
+
import_node_path43 = __toESM(require("node:path"), 1);
|
|
12481
12709
|
BUNDLE_NAME_HEX_DIGITS = 16;
|
|
12482
12710
|
}
|
|
12483
12711
|
});
|
|
@@ -12508,7 +12736,7 @@ function realEnsurePorts(paths, spawnDaemon) {
|
|
|
12508
12736
|
}
|
|
12509
12737
|
},
|
|
12510
12738
|
// Read fresh for each probe: a replacement supervisor may have regenerated an unparseable CA, and the probe must trust exactly what the serving door's leaf chains to.
|
|
12511
|
-
verifyListener: (port) => probeFrontDoorSync(port,
|
|
12739
|
+
verifyListener: (port) => probeFrontDoorSync(port, import_node_fs14.default.readFileSync(paths.frontdoorCaCertFile, "utf8"))
|
|
12512
12740
|
};
|
|
12513
12741
|
}
|
|
12514
12742
|
function realFrontDoorPort(paths, spawnDaemon) {
|
|
@@ -12529,11 +12757,11 @@ function realFrontDoorPort(paths, spawnDaemon) {
|
|
|
12529
12757
|
}
|
|
12530
12758
|
};
|
|
12531
12759
|
}
|
|
12532
|
-
var
|
|
12760
|
+
var import_node_fs14, realTrustBundleFs;
|
|
12533
12761
|
var init_realFrontDoorPort = __esm({
|
|
12534
12762
|
"src/frontdoor/realFrontDoorPort.ts"() {
|
|
12535
12763
|
"use strict";
|
|
12536
|
-
|
|
12764
|
+
import_node_fs14 = __toESM(require("node:fs"), 1);
|
|
12537
12765
|
init_realPorts();
|
|
12538
12766
|
init_doorLog();
|
|
12539
12767
|
init_ensure2();
|
|
@@ -12542,10 +12770,10 @@ var init_realFrontDoorPort = __esm({
|
|
|
12542
12770
|
init_selfIdentity();
|
|
12543
12771
|
init_trust();
|
|
12544
12772
|
realTrustBundleFs = {
|
|
12545
|
-
readFileUtf8: (file) =>
|
|
12546
|
-
exists: (file) =>
|
|
12773
|
+
readFileUtf8: (file) => import_node_fs14.default.readFileSync(file, "utf8"),
|
|
12774
|
+
exists: (file) => import_node_fs14.default.existsSync(file),
|
|
12547
12775
|
mkdirp: (dir) => {
|
|
12548
|
-
|
|
12776
|
+
import_node_fs14.default.mkdirSync(dir, { recursive: true });
|
|
12549
12777
|
},
|
|
12550
12778
|
writeFileAtomic: (file, contents) => {
|
|
12551
12779
|
realFarmFs.writeFilePrivate(file, contents);
|
|
@@ -12554,50 +12782,6 @@ var init_realFrontDoorPort = __esm({
|
|
|
12554
12782
|
}
|
|
12555
12783
|
});
|
|
12556
12784
|
|
|
12557
|
-
// src/replayRun.ts
|
|
12558
|
-
function keyOf2(command, args) {
|
|
12559
|
-
return JSON.stringify([command, args]);
|
|
12560
|
-
}
|
|
12561
|
-
async function recordRuns(decide, runAsync) {
|
|
12562
|
-
const answers = /* @__PURE__ */ new Map();
|
|
12563
|
-
const replay = {
|
|
12564
|
-
run: (command, args) => {
|
|
12565
|
-
const answer = answers.get(keyOf2(command, args));
|
|
12566
|
-
if (answer === void 0) {
|
|
12567
|
-
throw new RunNeededError(command, args);
|
|
12568
|
-
}
|
|
12569
|
-
return answer;
|
|
12570
|
-
}
|
|
12571
|
-
};
|
|
12572
|
-
for (; ; ) {
|
|
12573
|
-
try {
|
|
12574
|
-
decide(replay);
|
|
12575
|
-
return replay;
|
|
12576
|
-
} catch (error) {
|
|
12577
|
-
if (!(error instanceof RunNeededError)) {
|
|
12578
|
-
throw error;
|
|
12579
|
-
}
|
|
12580
|
-
answers.set(keyOf2(error.command, error.args), await runAsync(error.command, error.args));
|
|
12581
|
-
}
|
|
12582
|
-
}
|
|
12583
|
-
}
|
|
12584
|
-
var RunNeededError;
|
|
12585
|
-
var init_replayRun = __esm({
|
|
12586
|
-
"src/replayRun.ts"() {
|
|
12587
|
-
"use strict";
|
|
12588
|
-
RunNeededError = class extends Error {
|
|
12589
|
-
constructor(command, args) {
|
|
12590
|
-
super(`no recorded answer for ${command} ${args.join(" ")}`);
|
|
12591
|
-
this.command = command;
|
|
12592
|
-
this.args = args;
|
|
12593
|
-
this.name = "RunNeededError";
|
|
12594
|
-
}
|
|
12595
|
-
command;
|
|
12596
|
-
args;
|
|
12597
|
-
};
|
|
12598
|
-
}
|
|
12599
|
-
});
|
|
12600
|
-
|
|
12601
12785
|
// src/launchWiring.ts
|
|
12602
12786
|
function buildFarmRuntime(paths, cwd, run = realRunPort) {
|
|
12603
12787
|
const home = import_node_os7.default.homedir();
|
|
@@ -12652,7 +12836,7 @@ function realPrepareLaunchParams(paths, options) {
|
|
|
12652
12836
|
frontdoor: realFrontDoorPort(paths, options.spawnDaemon),
|
|
12653
12837
|
credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
|
|
12654
12838
|
hold: realHoldPort,
|
|
12655
|
-
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot:
|
|
12839
|
+
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: import_node_path44.default.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
|
|
12656
12840
|
...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
|
|
12657
12841
|
...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
|
|
12658
12842
|
...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },
|
|
@@ -12711,12 +12895,12 @@ function resolveClaudeLaunch(options, run = realRunPort) {
|
|
|
12711
12895
|
};
|
|
12712
12896
|
return { resolution: resolveLaunch(realPrepareLaunchParams(paths, { proc, log, spawnDaemon, run, farm: buildFarmRuntime(paths, options.cwd, run) })), warnings };
|
|
12713
12897
|
}
|
|
12714
|
-
var import_node_os7,
|
|
12898
|
+
var import_node_os7, import_node_path44, import_node_crypto13, LaunchRefusedError;
|
|
12715
12899
|
var init_launchWiring = __esm({
|
|
12716
12900
|
"src/launchWiring.ts"() {
|
|
12717
12901
|
"use strict";
|
|
12718
12902
|
import_node_os7 = __toESM(require("node:os"), 1);
|
|
12719
|
-
|
|
12903
|
+
import_node_path44 = __toESM(require("node:path"), 1);
|
|
12720
12904
|
import_node_crypto13 = require("node:crypto");
|
|
12721
12905
|
init_cliError();
|
|
12722
12906
|
init_claudeShim();
|
|
@@ -12940,11 +13124,11 @@ var init_identityClaude = __esm({
|
|
|
12940
13124
|
});
|
|
12941
13125
|
|
|
12942
13126
|
// src/usage/providerQuota.ts
|
|
12943
|
-
var
|
|
13127
|
+
var import_zod37, MS_PER_SECOND9, SECONDS_PER_HOUR3, HOURS_PER_DAY6, DAYS_PER_MONTH, ZAI_HOST, ZAI_QUOTA_URL, ZAI_UNIT_HOURS, ZAI_UNIT_MONTHS, ZAI_UNIT_MS, ZaiLimitSchema, ZaiResponseSchema, OPENROUTER_HOST, OPENROUTER_KEY_URL, OPENROUTER_CREDITS_URL, MS_PER_DAY2, OpenRouterKeySchema, OpenRouterCreditsSchema, ANTIGRAVITY_HOST, ANTIGRAVITY_QUOTA_URL, ANTIGRAVITY_USER_URL, FIVE_HOURS2, DAYS_PER_WEEK2, FIVE_HOURS_MS, WEEK_MS, AntigravityBucketSchema, AntigravitySummarySchema, GoogleTokenInfoSchema, AntigravityUserSchema;
|
|
12944
13128
|
var init_providerQuota = __esm({
|
|
12945
13129
|
"src/usage/providerQuota.ts"() {
|
|
12946
13130
|
"use strict";
|
|
12947
|
-
|
|
13131
|
+
import_zod37 = require("zod");
|
|
12948
13132
|
init_cloudUpstream();
|
|
12949
13133
|
init_schema2();
|
|
12950
13134
|
MS_PER_SECOND9 = 1e3;
|
|
@@ -12959,35 +13143,35 @@ var init_providerQuota = __esm({
|
|
|
12959
13143
|
[ZAI_UNIT_HOURS, SECONDS_PER_HOUR3 * MS_PER_SECOND9],
|
|
12960
13144
|
[ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY6 * SECONDS_PER_HOUR3 * MS_PER_SECOND9]
|
|
12961
13145
|
]);
|
|
12962
|
-
ZaiLimitSchema =
|
|
12963
|
-
type:
|
|
12964
|
-
unit:
|
|
12965
|
-
number:
|
|
12966
|
-
percentage:
|
|
12967
|
-
nextResetTime:
|
|
12968
|
-
usage:
|
|
12969
|
-
currentValue:
|
|
12970
|
-
remaining:
|
|
13146
|
+
ZaiLimitSchema = import_zod37.z.object({
|
|
13147
|
+
type: import_zod37.z.string(),
|
|
13148
|
+
unit: import_zod37.z.number().int(),
|
|
13149
|
+
number: import_zod37.z.number().int().positive(),
|
|
13150
|
+
percentage: import_zod37.z.number().nonnegative(),
|
|
13151
|
+
nextResetTime: import_zod37.z.number().positive().optional(),
|
|
13152
|
+
usage: import_zod37.z.number().nonnegative().optional(),
|
|
13153
|
+
currentValue: import_zod37.z.number().nonnegative().optional(),
|
|
13154
|
+
remaining: import_zod37.z.number().nonnegative().optional()
|
|
12971
13155
|
});
|
|
12972
|
-
ZaiResponseSchema =
|
|
12973
|
-
success:
|
|
12974
|
-
msg:
|
|
12975
|
-
data:
|
|
13156
|
+
ZaiResponseSchema = import_zod37.z.object({
|
|
13157
|
+
success: import_zod37.z.boolean(),
|
|
13158
|
+
msg: import_zod37.z.string().optional(),
|
|
13159
|
+
data: import_zod37.z.object({ level: import_zod37.z.string().optional(), limits: import_zod37.z.array(ZaiLimitSchema) })
|
|
12976
13160
|
});
|
|
12977
13161
|
OPENROUTER_HOST = "openrouter.ai";
|
|
12978
13162
|
OPENROUTER_KEY_URL = `https://${OPENROUTER_HOST}/api/v1/key`;
|
|
12979
13163
|
OPENROUTER_CREDITS_URL = `https://${OPENROUTER_HOST}/api/v1/credits`;
|
|
12980
13164
|
MS_PER_DAY2 = HOURS_PER_DAY6 * SECONDS_PER_HOUR3 * MS_PER_SECOND9;
|
|
12981
|
-
OpenRouterKeySchema =
|
|
12982
|
-
data:
|
|
12983
|
-
limit:
|
|
12984
|
-
limit_remaining:
|
|
12985
|
-
limit_reset:
|
|
12986
|
-
is_free_tier:
|
|
12987
|
-
free_model_daily_requests:
|
|
13165
|
+
OpenRouterKeySchema = import_zod37.z.object({
|
|
13166
|
+
data: import_zod37.z.object({
|
|
13167
|
+
limit: import_zod37.z.number().nonnegative().nullable(),
|
|
13168
|
+
limit_remaining: import_zod37.z.number().nullable(),
|
|
13169
|
+
limit_reset: import_zod37.z.string().nullable(),
|
|
13170
|
+
is_free_tier: import_zod37.z.boolean().optional(),
|
|
13171
|
+
free_model_daily_requests: import_zod37.z.object({ used: import_zod37.z.number().nonnegative(), limit: import_zod37.z.number().nonnegative(), remaining: import_zod37.z.number() }).optional()
|
|
12988
13172
|
})
|
|
12989
13173
|
});
|
|
12990
|
-
OpenRouterCreditsSchema =
|
|
13174
|
+
OpenRouterCreditsSchema = import_zod37.z.object({ data: import_zod37.z.object({ total_credits: import_zod37.z.number().nonnegative(), total_usage: import_zod37.z.number().nonnegative() }) });
|
|
12991
13175
|
ANTIGRAVITY_HOST = "daily-cloudcode-pa.googleapis.com";
|
|
12992
13176
|
ANTIGRAVITY_QUOTA_URL = `https://${ANTIGRAVITY_HOST}/v1internal:retrieveUserQuotaSummary`;
|
|
12993
13177
|
ANTIGRAVITY_USER_URL = `https://${ANTIGRAVITY_HOST}/v1internal:loadCodeAssist`;
|
|
@@ -12995,21 +13179,21 @@ var init_providerQuota = __esm({
|
|
|
12995
13179
|
DAYS_PER_WEEK2 = 7;
|
|
12996
13180
|
FIVE_HOURS_MS = FIVE_HOURS2 * SECONDS_PER_HOUR3 * MS_PER_SECOND9;
|
|
12997
13181
|
WEEK_MS = DAYS_PER_WEEK2 * HOURS_PER_DAY6 * SECONDS_PER_HOUR3 * MS_PER_SECOND9;
|
|
12998
|
-
AntigravityBucketSchema =
|
|
12999
|
-
bucketId:
|
|
13000
|
-
remainingFraction:
|
|
13001
|
-
resetTime:
|
|
13182
|
+
AntigravityBucketSchema = import_zod37.z.object({
|
|
13183
|
+
bucketId: import_zod37.z.string(),
|
|
13184
|
+
remainingFraction: import_zod37.z.number().optional(),
|
|
13185
|
+
resetTime: import_zod37.z.string().optional()
|
|
13002
13186
|
});
|
|
13003
|
-
AntigravitySummarySchema =
|
|
13004
|
-
GoogleTokenInfoSchema =
|
|
13005
|
-
email:
|
|
13006
|
-
sub:
|
|
13187
|
+
AntigravitySummarySchema = import_zod37.z.object({ groups: import_zod37.z.array(import_zod37.z.object({ buckets: import_zod37.z.array(AntigravityBucketSchema) })) });
|
|
13188
|
+
GoogleTokenInfoSchema = import_zod37.z.object({
|
|
13189
|
+
email: import_zod37.z.string().optional(),
|
|
13190
|
+
sub: import_zod37.z.string().optional()
|
|
13007
13191
|
});
|
|
13008
|
-
AntigravityUserSchema =
|
|
13192
|
+
AntigravityUserSchema = import_zod37.z.object({
|
|
13009
13193
|
/** The code-assist tier context, which defaults to the free tier for every account. */
|
|
13010
|
-
currentTier:
|
|
13194
|
+
currentTier: import_zod37.z.object({ name: import_zod37.z.string().optional(), id: import_zod37.z.string().optional() }).optional(),
|
|
13011
13195
|
/** The account's paid subscription; absent when the account has none. */
|
|
13012
|
-
paidTier:
|
|
13196
|
+
paidTier: import_zod37.z.object({ name: import_zod37.z.string().optional(), id: import_zod37.z.string().optional() }).optional()
|
|
13013
13197
|
});
|
|
13014
13198
|
}
|
|
13015
13199
|
});
|
|
@@ -13124,6 +13308,7 @@ __export(index_exports, {
|
|
|
13124
13308
|
CodexRateLimitsReadSchema: () => CodexRateLimitsReadSchema,
|
|
13125
13309
|
CodexSignInSchema: () => CodexSignInSchema,
|
|
13126
13310
|
CodexStatusOutputSchema: () => CodexStatusOutputSchema,
|
|
13311
|
+
ConfigIdentityAddInputSchema: () => ConfigIdentityAddInputSchema,
|
|
13127
13312
|
ConfigIdentityAddOutputSchema: () => ConfigIdentityAddOutputSchema,
|
|
13128
13313
|
ConfigIdentityRemoveInputSchema: () => ConfigIdentityRemoveInputSchema,
|
|
13129
13314
|
ConfigIdentityRemoveOutputSchema: () => ConfigIdentityRemoveOutputSchema,
|
|
@@ -13773,8 +13958,8 @@ function pathnameOf(url) {
|
|
|
13773
13958
|
return new URL(url ?? "/", "http://127.0.0.1").pathname;
|
|
13774
13959
|
}
|
|
13775
13960
|
function isRcSessionExchange(url) {
|
|
13776
|
-
const
|
|
13777
|
-
return
|
|
13961
|
+
const path45 = pathnameOf(url);
|
|
13962
|
+
return path45 === RC_SESSIONS_PATH_PREFIX || path45.startsWith(`${RC_SESSIONS_PATH_PREFIX}/`);
|
|
13778
13963
|
}
|
|
13779
13964
|
var RC_SESSION_ID_PREFIX = "cse_";
|
|
13780
13965
|
var RC_IDLE_EXPIRY_MS = 45e3;
|
|
@@ -14333,8 +14518,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
|
|
|
14333
14518
|
function isRcReadFileEncoding(value) {
|
|
14334
14519
|
return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value);
|
|
14335
14520
|
}
|
|
14336
|
-
function buildRcReadFilePayload(requestId,
|
|
14337
|
-
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path:
|
|
14521
|
+
function buildRcReadFilePayload(requestId, path45, options) {
|
|
14522
|
+
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path45, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
|
|
14338
14523
|
}
|
|
14339
14524
|
function buildRcFileSuggestionsPayload(requestId, query) {
|
|
14340
14525
|
return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
|
|
@@ -14436,15 +14621,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
|
|
|
14436
14621
|
const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
|
|
14437
14622
|
return result.ok ? { ...result, requestId } : result;
|
|
14438
14623
|
}
|
|
14439
|
-
async function readRcSessionFile(deps, sessionId,
|
|
14440
|
-
if (
|
|
14624
|
+
async function readRcSessionFile(deps, sessionId, path45, options) {
|
|
14625
|
+
if (path45 === "") {
|
|
14441
14626
|
return { ok: false, message: "a read-file write needs a non-empty path: the SDK's own field names the file the worker resolves against the session's cwd, and an empty string names none" };
|
|
14442
14627
|
}
|
|
14443
14628
|
if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
|
|
14444
14629
|
return { ok: false, message: "a read-file write's max-bytes is a positive whole number of bytes: the SDK's own field caps the read, and a zero or negative cap reads nothing" };
|
|
14445
14630
|
}
|
|
14446
14631
|
const requestId = deps.newUuid();
|
|
14447
|
-
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId,
|
|
14632
|
+
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path45, options), `read ${path45} from session ${sessionId}`);
|
|
14448
14633
|
return result.ok ? { ...result, requestId } : result;
|
|
14449
14634
|
}
|
|
14450
14635
|
async function suggestRcSessionFiles(deps, sessionId, query) {
|
|
@@ -14613,11 +14798,11 @@ function createRcControlHandler(deps) {
|
|
|
14613
14798
|
path: "read-file",
|
|
14614
14799
|
read: (body) => {
|
|
14615
14800
|
const session = bodyString(body, "session");
|
|
14616
|
-
const
|
|
14801
|
+
const path45 = bodyString(body, "path");
|
|
14617
14802
|
const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
|
|
14618
14803
|
const encoding = "encoding" in body && isRcReadFileEncoding(body.encoding) ? body.encoding : void 0;
|
|
14619
|
-
const refused2 = session === void 0 ||
|
|
14620
|
-
return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session,
|
|
14804
|
+
const refused2 = session === void 0 || path45 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
|
|
14805
|
+
return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session, path45, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
|
|
14621
14806
|
}
|
|
14622
14807
|
},
|
|
14623
14808
|
{
|
|
@@ -14927,9 +15112,9 @@ function requestIdOfBody(body) {
|
|
|
14927
15112
|
}
|
|
14928
15113
|
function frontDoorRcControl(transport, token) {
|
|
14929
15114
|
const headers = { authorization: `Bearer ${token}` };
|
|
14930
|
-
const listAnswerOf = async (
|
|
15115
|
+
const listAnswerOf = async (path45, what) => {
|
|
14931
15116
|
try {
|
|
14932
|
-
return await transport.request({ method: "GET", path:
|
|
15117
|
+
return await transport.request({ method: "GET", path: path45, headers });
|
|
14933
15118
|
} catch (error) {
|
|
14934
15119
|
throw new Error(`${what}: could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
14935
15120
|
}
|
|
@@ -15001,10 +15186,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15001
15186
|
}
|
|
15002
15187
|
return pending;
|
|
15003
15188
|
};
|
|
15004
|
-
const writeOf = async (
|
|
15189
|
+
const writeOf = async (path45, body, describeFailure2) => {
|
|
15005
15190
|
let answer;
|
|
15006
15191
|
try {
|
|
15007
|
-
answer = await transport.request({ method: "POST", path:
|
|
15192
|
+
answer = await transport.request({ method: "POST", path: path45, headers: { ...headers, "content-type": "application/json" }, body });
|
|
15008
15193
|
} catch (error) {
|
|
15009
15194
|
return { ok: false, message: `could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}` };
|
|
15010
15195
|
}
|
|
@@ -15035,10 +15220,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15035
15220
|
endSession: async (sessionId, reason) => await writeOf(`${CONTROL_PATH_PREFIX}/end-session`, JSON.stringify({ session: sessionId, ...reason === void 0 ? {} : { reason } }), (status, message) => `ending ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
15036
15221
|
getUsage: async (sessionId, skipBehaviors) => await writeOf(`${CONTROL_PATH_PREFIX}/get-usage`, JSON.stringify({ session: sessionId, ...skipBehaviors === void 0 ? {} : { skipBehaviors } }), (status, message) => `requesting the usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
15037
15222
|
getContextUsage: async (sessionId, detail) => await writeOf(`${CONTROL_PATH_PREFIX}/get-context-usage`, JSON.stringify({ session: sessionId, ...detail === void 0 ? {} : { detail } }), (status, message) => `requesting the context usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
15038
|
-
readFile: async (sessionId,
|
|
15223
|
+
readFile: async (sessionId, path45, options) => await writeOf(
|
|
15039
15224
|
`${CONTROL_PATH_PREFIX}/read-file`,
|
|
15040
|
-
JSON.stringify({ session: sessionId, path:
|
|
15041
|
-
(status, message) => `reading ${
|
|
15225
|
+
JSON.stringify({ session: sessionId, path: path45, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
|
|
15226
|
+
(status, message) => `reading ${path45} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
15042
15227
|
),
|
|
15043
15228
|
fileSuggestions: async (sessionId, query) => await writeOf(`${CONTROL_PATH_PREFIX}/file-suggestions`, JSON.stringify({ session: sessionId, query }), (status, message) => `requesting file suggestions from ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
15044
15229
|
keepAlive: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/keep-alive`, JSON.stringify({ session: sessionId }), (status, message) => `keeping ${sessionId} alive failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -15197,12 +15382,12 @@ function tlsFacts(options) {
|
|
|
15197
15382
|
}
|
|
15198
15383
|
function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15199
15384
|
const agent = new ExemptTlsAgent();
|
|
15200
|
-
const post = async (
|
|
15385
|
+
const post = async (path45, headers, body) => await new Promise((resolve, reject) => {
|
|
15201
15386
|
const options = {
|
|
15202
15387
|
host: target.host,
|
|
15203
15388
|
port: target.port,
|
|
15204
15389
|
method: "POST",
|
|
15205
|
-
path:
|
|
15390
|
+
path: path45,
|
|
15206
15391
|
// The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
|
|
15207
15392
|
headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
|
|
15208
15393
|
agent
|
|
@@ -15267,12 +15452,12 @@ function lateRcStreamDial(resolve) {
|
|
|
15267
15452
|
}
|
|
15268
15453
|
function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15269
15454
|
const agent = new ExemptTlsAgent();
|
|
15270
|
-
const request4 = async (method,
|
|
15455
|
+
const request4 = async (method, path45, headers, body, signal) => await new Promise((resolve, reject) => {
|
|
15271
15456
|
const options = {
|
|
15272
15457
|
host: target.host,
|
|
15273
15458
|
port: target.port,
|
|
15274
15459
|
method,
|
|
15275
|
-
path:
|
|
15460
|
+
path: path45,
|
|
15276
15461
|
// The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
|
|
15277
15462
|
headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
|
|
15278
15463
|
agent,
|
|
@@ -15314,9 +15499,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
|
|
|
15314
15499
|
return { status, body: await readAll(response) };
|
|
15315
15500
|
},
|
|
15316
15501
|
openStream: async (sessionId, headers, resume, signal) => {
|
|
15317
|
-
const
|
|
15502
|
+
const path45 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
|
|
15318
15503
|
const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
|
|
15319
|
-
const { status, response } = await request4("GET",
|
|
15504
|
+
const { status, response } = await request4("GET", path45, streamHeaders, void 0, signal);
|
|
15320
15505
|
if (!isSuccessful2(status)) {
|
|
15321
15506
|
await readAll(response);
|
|
15322
15507
|
return { status, chunks: NO_CHUNKS };
|
|
@@ -15566,11 +15751,11 @@ function credentialOfJson(parsed) {
|
|
|
15566
15751
|
function sequenceNumOfJson(value) {
|
|
15567
15752
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
15568
15753
|
}
|
|
15569
|
-
function createRcCredentialStore(
|
|
15570
|
-
|
|
15754
|
+
function createRcCredentialStore(fs15, dir) {
|
|
15755
|
+
fs15.mkdirPrivate(dir);
|
|
15571
15756
|
const fileFor = (sessionId) => import_node_path11.default.join(dir, `${sessionId}.json`);
|
|
15572
15757
|
const readParsed = (sessionId) => {
|
|
15573
|
-
const raw =
|
|
15758
|
+
const raw = fs15.readFileUtf8(fileFor(sessionId));
|
|
15574
15759
|
if (raw === void 0) {
|
|
15575
15760
|
return void 0;
|
|
15576
15761
|
}
|
|
@@ -15595,7 +15780,7 @@ function createRcCredentialStore(fs14, dir) {
|
|
|
15595
15780
|
}
|
|
15596
15781
|
const cursor = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
|
|
15597
15782
|
const record = { ...credential, ...cursor === void 0 ? {} : { highestSequenceNum: cursor } };
|
|
15598
|
-
|
|
15783
|
+
fs15.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
15599
15784
|
`);
|
|
15600
15785
|
},
|
|
15601
15786
|
readCursor: (sessionId) => {
|
|
@@ -15610,14 +15795,14 @@ function createRcCredentialStore(fs14, dir) {
|
|
|
15610
15795
|
}
|
|
15611
15796
|
const credential = credentialOfJson(readParsed(sessionId));
|
|
15612
15797
|
const record = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
|
|
15613
|
-
|
|
15798
|
+
fs15.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
15614
15799
|
`);
|
|
15615
15800
|
},
|
|
15616
15801
|
remove: (sessionId) => {
|
|
15617
15802
|
if (!isSafeSessionId(sessionId)) {
|
|
15618
15803
|
return;
|
|
15619
15804
|
}
|
|
15620
|
-
|
|
15805
|
+
fs15.removeRecursive(fileFor(sessionId));
|
|
15621
15806
|
}
|
|
15622
15807
|
};
|
|
15623
15808
|
}
|
|
@@ -16309,19 +16494,19 @@ function writePools(paths, pools) {
|
|
|
16309
16494
|
applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
|
|
16310
16495
|
}
|
|
16311
16496
|
function poolCycleOf(pools, name) {
|
|
16312
|
-
const walk2 = (current,
|
|
16497
|
+
const walk2 = (current, path45) => {
|
|
16313
16498
|
for (const entry of pools[current]?.identities ?? []) {
|
|
16314
16499
|
const nested = poolNameOf(poolMemberIdentity(entry));
|
|
16315
16500
|
if (nested === void 0) {
|
|
16316
16501
|
continue;
|
|
16317
16502
|
}
|
|
16318
16503
|
if (nested === name) {
|
|
16319
|
-
return [...
|
|
16504
|
+
return [...path45, nested];
|
|
16320
16505
|
}
|
|
16321
|
-
if (
|
|
16506
|
+
if (path45.includes(nested)) {
|
|
16322
16507
|
continue;
|
|
16323
16508
|
}
|
|
16324
|
-
const found = walk2(nested, [...
|
|
16509
|
+
const found = walk2(nested, [...path45, nested]);
|
|
16325
16510
|
if (found !== void 0) {
|
|
16326
16511
|
return found;
|
|
16327
16512
|
}
|
|
@@ -16761,7 +16946,7 @@ function loadCheckProvider(paths, name) {
|
|
|
16761
16946
|
try {
|
|
16762
16947
|
definition = readProvider(paths, name);
|
|
16763
16948
|
} catch (error) {
|
|
16764
|
-
if (error instanceof ConfigValidationError || error instanceof LegacyProviderFileError) {
|
|
16949
|
+
if (error instanceof ConfigValidationError || error instanceof LegacyProviderFileError || error instanceof ConfigFileNotJsonError) {
|
|
16765
16950
|
return { name, problem: error.message };
|
|
16766
16951
|
}
|
|
16767
16952
|
throw error;
|
|
@@ -17033,8 +17218,8 @@ var ResetRowSchema = import_zod22.z.strictObject({
|
|
|
17033
17218
|
var ResetScheduleSchema = import_zod22.z.strictObject({ resets: import_zod22.z.readonly(import_zod22.z.array(ResetRowSchema)) });
|
|
17034
17219
|
|
|
17035
17220
|
// src/frontdoor/controlSchemas.ts
|
|
17036
|
-
var
|
|
17037
|
-
var
|
|
17221
|
+
var import_node_path32 = __toESM(require("node:path"), 1);
|
|
17222
|
+
var import_zod30 = require("zod");
|
|
17038
17223
|
|
|
17039
17224
|
// src/doctorReport.ts
|
|
17040
17225
|
init_claudeShim();
|
|
@@ -17042,14 +17227,212 @@ init_names();
|
|
|
17042
17227
|
init_store();
|
|
17043
17228
|
|
|
17044
17229
|
// src/identityStore.ts
|
|
17045
|
-
var
|
|
17046
|
-
var
|
|
17230
|
+
var import_node_fs9 = __toESM(require("node:fs"), 1);
|
|
17231
|
+
var import_node_path30 = __toESM(require("node:path"), 1);
|
|
17047
17232
|
init_load();
|
|
17233
|
+
init_names();
|
|
17048
17234
|
init_store();
|
|
17049
17235
|
init_schema();
|
|
17050
17236
|
init_cliError();
|
|
17051
17237
|
init_identity();
|
|
17052
17238
|
init_lock();
|
|
17239
|
+
|
|
17240
|
+
// src/identityRenameJournal.ts
|
|
17241
|
+
var import_node_path28 = __toESM(require("node:path"), 1);
|
|
17242
|
+
var import_zod24 = require("zod");
|
|
17243
|
+
init_cliError();
|
|
17244
|
+
var RenameJournalSchema = import_zod24.z.strictObject({
|
|
17245
|
+
version: import_zod24.z.literal(1),
|
|
17246
|
+
from: import_zod24.z.string().min(1),
|
|
17247
|
+
to: import_zod24.z.string().min(1),
|
|
17248
|
+
startedAt: import_zod24.z.iso.datetime(),
|
|
17249
|
+
/** The process that began the rename, for a person reading the file. Whether it is still running is told by the locks, not by this. */
|
|
17250
|
+
pid: import_zod24.z.number().int().positive(),
|
|
17251
|
+
steps: import_zod24.z.array(
|
|
17252
|
+
import_zod24.z.strictObject({
|
|
17253
|
+
description: import_zod24.z.string().min(1),
|
|
17254
|
+
/** Whether the step has been applied and marked so. */
|
|
17255
|
+
done: import_zod24.z.boolean(),
|
|
17256
|
+
/** Whether the step was begun: written ahead of the step, before it runs, so a process that dies after the step took effect and before `done` was written still leaves a record that it may have. */
|
|
17257
|
+
started: import_zod24.z.boolean()
|
|
17258
|
+
})
|
|
17259
|
+
)
|
|
17260
|
+
});
|
|
17261
|
+
var JOURNAL_SUFFIX = ".json";
|
|
17262
|
+
var RenameJournalUnreadableError = class extends CliError {
|
|
17263
|
+
constructor(file, detail) {
|
|
17264
|
+
super(`${file} is not a rename journal this agent-shim can read (${detail}). If no rename was left unfinished, remove it; otherwise look at what it names before renaming anything.`);
|
|
17265
|
+
this.detail = detail;
|
|
17266
|
+
this.name = "RenameJournalUnreadableError";
|
|
17267
|
+
}
|
|
17268
|
+
detail;
|
|
17269
|
+
};
|
|
17270
|
+
function readRenameJournal(fs15, file) {
|
|
17271
|
+
const raw = fs15.readFileUtf8(file);
|
|
17272
|
+
if (raw === void 0) {
|
|
17273
|
+
return void 0;
|
|
17274
|
+
}
|
|
17275
|
+
let parsed;
|
|
17276
|
+
try {
|
|
17277
|
+
parsed = JSON.parse(raw);
|
|
17278
|
+
} catch {
|
|
17279
|
+
throw new RenameJournalUnreadableError(file, "not valid JSON");
|
|
17280
|
+
}
|
|
17281
|
+
const result = RenameJournalSchema.safeParse(parsed);
|
|
17282
|
+
if (!result.success) {
|
|
17283
|
+
throw new RenameJournalUnreadableError(file, result.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; "));
|
|
17284
|
+
}
|
|
17285
|
+
return result.data;
|
|
17286
|
+
}
|
|
17287
|
+
function listRenameJournals(fs15, directory) {
|
|
17288
|
+
const journals = [];
|
|
17289
|
+
const unreadable = [];
|
|
17290
|
+
for (const name of [...fs15.readdir(directory)].sort()) {
|
|
17291
|
+
if (!name.endsWith(JOURNAL_SUFFIX)) {
|
|
17292
|
+
continue;
|
|
17293
|
+
}
|
|
17294
|
+
const file = import_node_path28.default.join(directory, name);
|
|
17295
|
+
try {
|
|
17296
|
+
const journal = readRenameJournal(fs15, file);
|
|
17297
|
+
if (journal !== void 0) {
|
|
17298
|
+
journals.push(journal);
|
|
17299
|
+
}
|
|
17300
|
+
} catch (error) {
|
|
17301
|
+
if (!(error instanceof RenameJournalUnreadableError)) {
|
|
17302
|
+
throw error;
|
|
17303
|
+
}
|
|
17304
|
+
unreadable.push({ file, detail: error.detail });
|
|
17305
|
+
}
|
|
17306
|
+
}
|
|
17307
|
+
return { journals, unreadable };
|
|
17308
|
+
}
|
|
17309
|
+
function stepMayBeApplied(step) {
|
|
17310
|
+
return step.done || step.started;
|
|
17311
|
+
}
|
|
17312
|
+
function recordsNothingApplied(journal) {
|
|
17313
|
+
return !journal.steps.some(stepMayBeApplied);
|
|
17314
|
+
}
|
|
17315
|
+
function describeUnfinishable(bothExist) {
|
|
17316
|
+
return bothExist ? "both names are identities" : "there is no identity under either name";
|
|
17317
|
+
}
|
|
17318
|
+
function finishabilityOf(journal, exists) {
|
|
17319
|
+
const underFrom = exists(journal.from);
|
|
17320
|
+
if (underFrom === exists(journal.to)) {
|
|
17321
|
+
return { finishable: false, reason: describeUnfinishable(underFrom) };
|
|
17322
|
+
}
|
|
17323
|
+
return underFrom && recordsNothingApplied(journal) ? { finishable: true, discardable: true } : { finishable: true };
|
|
17324
|
+
}
|
|
17325
|
+
function discardJournalCommand(journal) {
|
|
17326
|
+
return `agent-shim identity rename ${journal.from} ${journal.to} --discard-journal`;
|
|
17327
|
+
}
|
|
17328
|
+
function describeUnfinishedRename(journal, finishability) {
|
|
17329
|
+
const applied = journal.steps.filter(stepMayBeApplied).length;
|
|
17330
|
+
const progress = `an unfinished rename of identity "${journal.from}" to "${journal.to}" (${String(applied)} of ${String(journal.steps.length)} steps recorded as begun or done)`;
|
|
17331
|
+
return finishability.finishable ? `${progress}. Finish it with \`agent-shim identity rename ${journal.from} ${journal.to}\`; to put the name back afterwards, run \`agent-shim identity rename ${journal.to} ${journal.from}\`.${finishability.discardable === true ? ` No step is recorded as begun or done and the identity is still under "${journal.from}", so its record can be discarded with \`${discardJournalCommand(journal)}\`; that removes only the record.` : ""}` : `${progress} that cannot be finished: ${finishability.reason}. If nothing is left of it to keep, discard its record with \`${discardJournalCommand(journal)}\`; that removes only the record and changes no identity.`;
|
|
17332
|
+
}
|
|
17333
|
+
var NameHeldByUnfinishedRenameError = class extends CliError {
|
|
17334
|
+
constructor(action, name, journal, finishability) {
|
|
17335
|
+
super(`Cannot ${action} identity "${name}": there is ${describeUnfinishedRename(journal, finishability)}`);
|
|
17336
|
+
this.name = "NameHeldByUnfinishedRenameError";
|
|
17337
|
+
}
|
|
17338
|
+
};
|
|
17339
|
+
function requireNameFreeOfUnfinishedRename(fs15, directory, name, action, sameName, exists) {
|
|
17340
|
+
const held = listRenameJournals(fs15, directory).journals.find((journal) => [journal.from, journal.to].some((heldName) => heldName === name || sameName(name, heldName)));
|
|
17341
|
+
if (held !== void 0) {
|
|
17342
|
+
throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
|
|
17343
|
+
}
|
|
17344
|
+
}
|
|
17345
|
+
|
|
17346
|
+
// src/keychainLogin.ts
|
|
17347
|
+
init_cliError();
|
|
17348
|
+
init_signIn();
|
|
17349
|
+
var ITEM_NOT_FOUND_STATUS = 44;
|
|
17350
|
+
var MAX_DETAIL_CHARS = 200;
|
|
17351
|
+
var CONTROL_CHARACTER = new RegExp("\\p{Cc}", "u");
|
|
17352
|
+
var KeychainLoginError = class extends CliError {
|
|
17353
|
+
constructor(message) {
|
|
17354
|
+
super(message);
|
|
17355
|
+
this.name = "KeychainLoginError";
|
|
17356
|
+
}
|
|
17357
|
+
};
|
|
17358
|
+
var KeychainLookupError = class extends KeychainLoginError {
|
|
17359
|
+
constructor(message) {
|
|
17360
|
+
super(message);
|
|
17361
|
+
this.name = "KeychainLookupError";
|
|
17362
|
+
}
|
|
17363
|
+
};
|
|
17364
|
+
function statusPhrase(status) {
|
|
17365
|
+
return status === null ? "without a status" : String(status);
|
|
17366
|
+
}
|
|
17367
|
+
function describe(stderr) {
|
|
17368
|
+
const [first] = stderr.trim().split("\n");
|
|
17369
|
+
return first === void 0 || first === "" ? "" : ` (${first.slice(0, MAX_DETAIL_CHARS)})`;
|
|
17370
|
+
}
|
|
17371
|
+
function lookup(run, service) {
|
|
17372
|
+
const result = run.run("security", ["find-generic-password", "-s", service]);
|
|
17373
|
+
if (result.status === 0) {
|
|
17374
|
+
return { found: true, attributes: result.stdout };
|
|
17375
|
+
}
|
|
17376
|
+
if (result.status === ITEM_NOT_FOUND_STATUS) {
|
|
17377
|
+
return { found: false };
|
|
17378
|
+
}
|
|
17379
|
+
throw new KeychainLookupError(`Could not look up the Keychain item ${service}: security exited ${statusPhrase(result.status)}${describe(result.stderr)}.`);
|
|
17380
|
+
}
|
|
17381
|
+
function plainAccountOf(attributes) {
|
|
17382
|
+
const line = attributes.split("\n").find((candidate) => candidate.includes('"acct"<blob>='));
|
|
17383
|
+
const value = line?.slice(line.indexOf("=") + 1).trim();
|
|
17384
|
+
const name = value === void 0 ? void 0 : /^"([^"\\]*)"$/u.exec(value)?.[1];
|
|
17385
|
+
return name === void 0 || name === "" || CONTROL_CHARACTER.test(name) ? void 0 : name;
|
|
17386
|
+
}
|
|
17387
|
+
function keychainDeleteCommand(service, account) {
|
|
17388
|
+
return `security delete-generic-password -s ${shellQuoted(service)}${account === void 0 ? "" : ` -a ${shellQuoted(account)}`}`;
|
|
17389
|
+
}
|
|
17390
|
+
function shellQuoted(value) {
|
|
17391
|
+
return `'${value.replace(/'/gu, "'\\''")}'`;
|
|
17392
|
+
}
|
|
17393
|
+
var KEEP_KEYCHAIN_LOGIN_DESCRIPTION = "Create the identity even though the macOS Keychain already holds a Claude Code login filed for its directory (left by an identity of that name that was renamed or removed); the identity starts signed in as that account. If another identity holds that login, the two share it. Without it that login is refused and the command that deletes it is printed.";
|
|
17394
|
+
function requireNoLeftoverKeychainLogin(keychain, configDir, name, keepLogin) {
|
|
17395
|
+
if (keepLogin || keychain.platform !== "darwin") {
|
|
17396
|
+
return;
|
|
17397
|
+
}
|
|
17398
|
+
const service = claudeCodeKeychainService(configDir);
|
|
17399
|
+
const found = lookup(keychain.run, service);
|
|
17400
|
+
if (!found.found) {
|
|
17401
|
+
return;
|
|
17402
|
+
}
|
|
17403
|
+
const account = plainAccountOf(found.attributes);
|
|
17404
|
+
throw new KeychainLoginError(
|
|
17405
|
+
`Cannot create identity "${name}": the Keychain already holds a Claude Code login filed for ${configDir} (service ${service}${account === void 0 ? "" : `, account ${account}`}), left behind by an identity of that name that was renamed or removed. A new identity there would start signed in as that account. If you do not need it, delete it with \`${keychainDeleteCommand(service, account)}\` and run the command again. To create the identity signed in as that account on purpose, run \`agent-shim identity add ${name} --keep-keychain-login\`. If another identity holds a copy of that login, as a renamed identity does when its old item could not be deleted, keeping it makes the two share one login.`
|
|
17406
|
+
);
|
|
17407
|
+
}
|
|
17408
|
+
|
|
17409
|
+
// src/sameDirectory.ts
|
|
17410
|
+
var import_node_fs8 = __toESM(require("node:fs"), 1);
|
|
17411
|
+
var import_node_path29 = __toESM(require("node:path"), 1);
|
|
17412
|
+
function sameDirectory(first, second) {
|
|
17413
|
+
const a = import_node_fs8.default.statSync(first, { throwIfNoEntry: false });
|
|
17414
|
+
const b = import_node_fs8.default.statSync(second, { throwIfNoEntry: false });
|
|
17415
|
+
if (a === void 0 || b === void 0) {
|
|
17416
|
+
return false;
|
|
17417
|
+
}
|
|
17418
|
+
return a.dev === b.dev && a.ino === b.ino;
|
|
17419
|
+
}
|
|
17420
|
+
function caseSwapped(name) {
|
|
17421
|
+
return name.replace(/[A-Za-z]/gu, (letter) => letter === letter.toLowerCase() ? letter.toUpperCase() : letter.toLowerCase());
|
|
17422
|
+
}
|
|
17423
|
+
function ignoresCase(directory) {
|
|
17424
|
+
if (!import_node_fs8.default.existsSync(directory)) {
|
|
17425
|
+
return false;
|
|
17426
|
+
}
|
|
17427
|
+
const probe = import_node_fs8.default.mkdtempSync(import_node_path29.default.join(directory, ".case-probe-"));
|
|
17428
|
+
try {
|
|
17429
|
+
return sameDirectory(probe, import_node_path29.default.join(directory, caseSwapped(import_node_path29.default.basename(probe))));
|
|
17430
|
+
} finally {
|
|
17431
|
+
import_node_fs8.default.rmSync(probe, { recursive: true, force: true });
|
|
17432
|
+
}
|
|
17433
|
+
}
|
|
17434
|
+
|
|
17435
|
+
// src/identityStore.ts
|
|
17053
17436
|
var IdentityNotFoundError = class extends CliError {
|
|
17054
17437
|
constructor(name) {
|
|
17055
17438
|
super(`No identity named "${name}". Run \`agent-shim identity add ${name}\` first.`);
|
|
@@ -17077,7 +17460,7 @@ var InvalidIdentityNameError = class extends CliError {
|
|
|
17077
17460
|
attemptedName;
|
|
17078
17461
|
};
|
|
17079
17462
|
function identityJsonPath(paths, name) {
|
|
17080
|
-
return
|
|
17463
|
+
return import_node_path30.default.join(paths.identitiesDir, name, "identity.json");
|
|
17081
17464
|
}
|
|
17082
17465
|
function requireIdentityNames(paths, names) {
|
|
17083
17466
|
const existing = new Set(listIdentities(paths).map((entry) => entry.name));
|
|
@@ -17088,21 +17471,23 @@ function requireIdentityNames(paths, names) {
|
|
|
17088
17471
|
}
|
|
17089
17472
|
}
|
|
17090
17473
|
function identityExists(paths, name) {
|
|
17091
|
-
return
|
|
17474
|
+
return import_node_fs9.default.existsSync(identityJsonPath(paths, name));
|
|
17092
17475
|
}
|
|
17093
17476
|
function readIdentity(paths, name) {
|
|
17094
17477
|
return readJson(identityJsonPath(paths, name), IdentitySchema);
|
|
17095
17478
|
}
|
|
17096
|
-
function
|
|
17479
|
+
function requireIdentityCreatable(paths, name) {
|
|
17480
|
+
requireNoUnfinishedRenameNaming(paths, name, "add");
|
|
17097
17481
|
if (identityExists(paths, name)) {
|
|
17098
17482
|
throw new IdentityAlreadyExistsError(name);
|
|
17099
17483
|
}
|
|
17100
|
-
|
|
17101
|
-
|
|
17102
|
-
|
|
17103
|
-
|
|
17104
|
-
|
|
17105
|
-
|
|
17484
|
+
requireNewIdentityName(name);
|
|
17485
|
+
}
|
|
17486
|
+
function addIdentity(paths, name) {
|
|
17487
|
+
requireIdentityCreatable(paths, name);
|
|
17488
|
+
const identity = IdentitySchema.parse({ name, allowAmbientCredential: false });
|
|
17489
|
+
writeJsonAtomic(identityJsonPath(paths, name), identity);
|
|
17490
|
+
return identity;
|
|
17106
17491
|
}
|
|
17107
17492
|
function useIdentity(paths, name) {
|
|
17108
17493
|
const pool = poolNameOf(name);
|
|
@@ -17115,33 +17500,89 @@ function useIdentity(paths, name) {
|
|
|
17115
17500
|
`);
|
|
17116
17501
|
}
|
|
17117
17502
|
function readActiveIdentity2(paths) {
|
|
17118
|
-
if (!
|
|
17503
|
+
if (!import_node_fs9.default.existsSync(paths.activeIdentityFile)) {
|
|
17119
17504
|
return void 0;
|
|
17120
17505
|
}
|
|
17121
|
-
const raw =
|
|
17506
|
+
const raw = import_node_fs9.default.readFileSync(paths.activeIdentityFile, "utf8").trim();
|
|
17122
17507
|
return raw === "" ? void 0 : raw;
|
|
17123
17508
|
}
|
|
17124
17509
|
function isIdentityDirectoryName(name) {
|
|
17125
17510
|
return !name.startsWith(".");
|
|
17126
17511
|
}
|
|
17512
|
+
var UNREACHABLE_CODES = /* @__PURE__ */ new Set(["ELOOP", "EACCES", "ENOTDIR"]);
|
|
17513
|
+
function systemErrorCode(error) {
|
|
17514
|
+
return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
17515
|
+
}
|
|
17516
|
+
function unreachableCodeOf(error) {
|
|
17517
|
+
const code = systemErrorCode(error);
|
|
17518
|
+
if (code === "ENOENT") {
|
|
17519
|
+
return void 0;
|
|
17520
|
+
}
|
|
17521
|
+
if (code !== void 0 && UNREACHABLE_CODES.has(code)) {
|
|
17522
|
+
return code;
|
|
17523
|
+
}
|
|
17524
|
+
throw error;
|
|
17525
|
+
}
|
|
17526
|
+
function followedLink(link) {
|
|
17527
|
+
try {
|
|
17528
|
+
return import_node_fs9.default.statSync(link).isDirectory() ? "directory" : "other";
|
|
17529
|
+
} catch (error) {
|
|
17530
|
+
const code = unreachableCodeOf(error);
|
|
17531
|
+
return code === void 0 ? "other" : { code };
|
|
17532
|
+
}
|
|
17533
|
+
}
|
|
17534
|
+
function entryRefusal(directory) {
|
|
17535
|
+
try {
|
|
17536
|
+
import_node_fs9.default.accessSync(directory, import_node_fs9.default.constants.X_OK);
|
|
17537
|
+
return void 0;
|
|
17538
|
+
} catch (error) {
|
|
17539
|
+
return unreachableCodeOf(error);
|
|
17540
|
+
}
|
|
17541
|
+
}
|
|
17542
|
+
function listIdentityDirectories(paths) {
|
|
17543
|
+
const names = [];
|
|
17544
|
+
const unreachable = [];
|
|
17545
|
+
if (import_node_fs9.default.existsSync(paths.identitiesDir)) {
|
|
17546
|
+
for (const entry of import_node_fs9.default.readdirSync(paths.identitiesDir, { withFileTypes: true })) {
|
|
17547
|
+
if (!isIdentityDirectoryName(entry.name)) {
|
|
17548
|
+
continue;
|
|
17549
|
+
}
|
|
17550
|
+
const entryPath = import_node_path30.default.join(paths.identitiesDir, entry.name);
|
|
17551
|
+
const followed = entry.isDirectory() ? "directory" : entry.isSymbolicLink() ? followedLink(entryPath) : "other";
|
|
17552
|
+
if (followed === "other") {
|
|
17553
|
+
continue;
|
|
17554
|
+
}
|
|
17555
|
+
const code = followed === "directory" ? entryRefusal(entryPath) : followed.code;
|
|
17556
|
+
if (code === void 0) {
|
|
17557
|
+
names.push(entry.name);
|
|
17558
|
+
} else {
|
|
17559
|
+
unreachable.push({ name: entry.name, code });
|
|
17560
|
+
}
|
|
17561
|
+
}
|
|
17562
|
+
}
|
|
17563
|
+
return { names: names.sort(), unreachable: unreachable.sort((a, b) => a.name.localeCompare(b.name)) };
|
|
17564
|
+
}
|
|
17565
|
+
var NOT_JSON_PROBLEM = "is not valid JSON";
|
|
17127
17566
|
function readIdentityForListing(paths, name) {
|
|
17128
17567
|
try {
|
|
17129
17568
|
return readIdentity(paths, name);
|
|
17130
17569
|
} catch (error) {
|
|
17131
|
-
if (error instanceof
|
|
17570
|
+
if (error instanceof ConfigFileNotJsonError) {
|
|
17571
|
+
return { problem: NOT_JSON_PROBLEM };
|
|
17572
|
+
}
|
|
17573
|
+
if (error instanceof ConfigValidationError) {
|
|
17132
17574
|
return { problem: error.message.replace(/\s*\n\s*/g, " ") };
|
|
17133
17575
|
}
|
|
17134
17576
|
throw error;
|
|
17135
17577
|
}
|
|
17136
17578
|
}
|
|
17137
17579
|
function listIdentities(paths) {
|
|
17138
|
-
if (!
|
|
17580
|
+
if (!import_node_fs9.default.existsSync(paths.identitiesDir)) {
|
|
17139
17581
|
return [];
|
|
17140
17582
|
}
|
|
17141
17583
|
const active = readActiveIdentity2(paths);
|
|
17142
|
-
const names = import_node_fs8.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort();
|
|
17143
17584
|
const result = [];
|
|
17144
|
-
for (const name of names) {
|
|
17585
|
+
for (const name of listIdentityDirectories(paths).names) {
|
|
17145
17586
|
const read = readIdentityForListing(paths, name);
|
|
17146
17587
|
if (read === void 0) {
|
|
17147
17588
|
continue;
|
|
@@ -17151,6 +17592,10 @@ function listIdentities(paths) {
|
|
|
17151
17592
|
}
|
|
17152
17593
|
return result;
|
|
17153
17594
|
}
|
|
17595
|
+
function requireIdentityAddable(paths, name, keychain, keepKeychainLogin) {
|
|
17596
|
+
requireIdentityCreatable(paths, name);
|
|
17597
|
+
requireNoLeftoverKeychainLogin(keychain, import_node_path30.default.join(paths.identitiesDir, name), name, keepKeychainLogin);
|
|
17598
|
+
}
|
|
17154
17599
|
function setIdentityAnchors(paths, identityName, anchors) {
|
|
17155
17600
|
if (!identityExists(paths, identityName)) {
|
|
17156
17601
|
throw new IdentityNotFoundError(identityName);
|
|
@@ -17203,50 +17648,70 @@ function setIdentityCredential(paths, identityName, change) {
|
|
|
17203
17648
|
credential: { sources: [...sources], ...target === void 0 ? {} : { target }, ...cache === void 0 ? {} : { cache } }
|
|
17204
17649
|
});
|
|
17205
17650
|
}
|
|
17651
|
+
var UUID_PATTERN = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
17652
|
+
var FARM_SUFFIX_PATTERN = `\\.(?:scratch|previous)\\.\\d+\\.${UUID_PATTERN}`;
|
|
17653
|
+
function escapedForPattern(text) {
|
|
17654
|
+
return text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
17655
|
+
}
|
|
17656
|
+
function isFarmEntry(entry, name) {
|
|
17657
|
+
return entry === name || new RegExp(`^\\.${escapedForPattern(name)}${FARM_SUFFIX_PATTERN}$`, "u").test(entry);
|
|
17658
|
+
}
|
|
17206
17659
|
function belongsToIdentity(entry, name) {
|
|
17207
|
-
return entry
|
|
17660
|
+
return isFarmEntry(entry, name) || entry === import_node_path30.default.basename(identityLockPath("", name));
|
|
17661
|
+
}
|
|
17662
|
+
function requireNewIdentityName(name) {
|
|
17663
|
+
if (!FileNameSchema.safeParse(name).success) {
|
|
17664
|
+
throw new InvalidIdentityNameError(name);
|
|
17665
|
+
}
|
|
17666
|
+
}
|
|
17667
|
+
function sameIdentityName(paths, first, second) {
|
|
17668
|
+
return sameDirectory(import_node_path30.default.join(paths.identitiesDir, first), import_node_path30.default.join(paths.identitiesDir, second)) || first.toLowerCase() === second.toLowerCase() && ignoresCase(paths.identitiesDir);
|
|
17669
|
+
}
|
|
17670
|
+
function requireNoUnfinishedRenameNaming(paths, name, action) {
|
|
17671
|
+
requireNameFreeOfUnfinishedRename({ readFileUtf8: nodeStoreFs.readFileUtf8, readdir: (directory) => import_node_fs9.default.existsSync(directory) ? import_node_fs9.default.readdirSync(directory) : [] }, paths.identityRenamesDir, name, action, (first, second) => sameIdentityName(paths, first, second), (identity) => identityExists(paths, identity));
|
|
17208
17672
|
}
|
|
17209
17673
|
function removeIdentity(paths, name) {
|
|
17674
|
+
requireNoUnfinishedRenameNaming(paths, name, "remove");
|
|
17210
17675
|
if (!identityExists(paths, name)) {
|
|
17211
17676
|
throw new IdentityNotFoundError(name);
|
|
17212
17677
|
}
|
|
17213
|
-
for (const entry of
|
|
17678
|
+
for (const entry of import_node_fs9.default.readdirSync(paths.identitiesDir)) {
|
|
17214
17679
|
if (belongsToIdentity(entry, name)) {
|
|
17215
|
-
|
|
17680
|
+
import_node_fs9.default.rmSync(import_node_path30.default.join(paths.identitiesDir, entry), { recursive: true, force: true });
|
|
17216
17681
|
}
|
|
17217
17682
|
}
|
|
17218
17683
|
if (readActiveIdentity2(paths) === name) {
|
|
17219
|
-
|
|
17684
|
+
import_node_fs9.default.rmSync(paths.activeIdentityFile);
|
|
17220
17685
|
}
|
|
17221
17686
|
}
|
|
17222
17687
|
|
|
17223
17688
|
// src/doctorReport.ts
|
|
17224
17689
|
init_realPorts();
|
|
17225
|
-
var
|
|
17226
|
-
var
|
|
17690
|
+
var import_node_fs11 = __toESM(require("node:fs"), 1);
|
|
17691
|
+
var import_node_path31 = __toESM(require("node:path"), 1);
|
|
17227
17692
|
init_signIn();
|
|
17228
17693
|
init_identityAccounts();
|
|
17229
17694
|
init_read();
|
|
17230
17695
|
|
|
17231
17696
|
// src/codex/siwcStore.ts
|
|
17232
|
-
var
|
|
17697
|
+
var import_zod27 = require("zod");
|
|
17233
17698
|
|
|
17234
17699
|
// src/codex/auth.ts
|
|
17235
|
-
var
|
|
17236
|
-
var AuthFileSchema =
|
|
17237
|
-
tokens:
|
|
17238
|
-
access_token:
|
|
17239
|
-
refresh_token:
|
|
17240
|
-
id_token:
|
|
17241
|
-
account_id:
|
|
17700
|
+
var import_zod25 = require("zod");
|
|
17701
|
+
var AuthFileSchema = import_zod25.z.looseObject({
|
|
17702
|
+
tokens: import_zod25.z.looseObject({
|
|
17703
|
+
access_token: import_zod25.z.string().optional(),
|
|
17704
|
+
refresh_token: import_zod25.z.string().optional(),
|
|
17705
|
+
id_token: import_zod25.z.string().optional(),
|
|
17706
|
+
account_id: import_zod25.z.string().optional()
|
|
17242
17707
|
}).nullish(),
|
|
17243
|
-
last_refresh:
|
|
17708
|
+
last_refresh: import_zod25.z.string().optional()
|
|
17244
17709
|
});
|
|
17245
|
-
var TokenGrantSchema =
|
|
17246
|
-
access_token:
|
|
17247
|
-
refresh_token:
|
|
17248
|
-
id_token:
|
|
17249
|
-
account_id:
|
|
17710
|
+
var TokenGrantSchema = import_zod25.z.looseObject({
|
|
17711
|
+
access_token: import_zod25.z.string().min(1).optional(),
|
|
17712
|
+
refresh_token: import_zod25.z.string().min(1).optional(),
|
|
17713
|
+
id_token: import_zod25.z.string().min(1).optional(),
|
|
17714
|
+
account_id: import_zod25.z.string().min(1).optional()
|
|
17250
17715
|
});
|
|
17251
17716
|
var CodexAuthError = class extends Error {
|
|
17252
17717
|
constructor(message) {
|
|
@@ -17256,41 +17721,41 @@ var CodexAuthError = class extends Error {
|
|
|
17256
17721
|
};
|
|
17257
17722
|
|
|
17258
17723
|
// src/codex/siwc.ts
|
|
17259
|
-
var
|
|
17724
|
+
var import_zod26 = require("zod");
|
|
17260
17725
|
var SIWC_RESOURCE = "https://api.openai.com/v1";
|
|
17261
17726
|
var SIWC_RESPONSES_URL = `${SIWC_RESOURCE}/responses`;
|
|
17262
17727
|
var SIWC_PLAN_SCOPE = "chatgpt.tokens.use.direct";
|
|
17263
|
-
var TokenResponseSchema =
|
|
17264
|
-
access_token:
|
|
17265
|
-
refresh_token:
|
|
17266
|
-
id_token:
|
|
17267
|
-
expires_in:
|
|
17268
|
-
scope:
|
|
17728
|
+
var TokenResponseSchema = import_zod26.z.looseObject({
|
|
17729
|
+
access_token: import_zod26.z.string().min(1),
|
|
17730
|
+
refresh_token: import_zod26.z.string().min(1).optional(),
|
|
17731
|
+
id_token: import_zod26.z.string().min(1).optional(),
|
|
17732
|
+
expires_in: import_zod26.z.number().positive(),
|
|
17733
|
+
scope: import_zod26.z.string().optional()
|
|
17269
17734
|
});
|
|
17270
|
-
var JwtHeaderSchema =
|
|
17271
|
-
var IdTokenClaimsSchema =
|
|
17272
|
-
iss:
|
|
17273
|
-
sub:
|
|
17274
|
-
aud:
|
|
17275
|
-
exp:
|
|
17276
|
-
nonce:
|
|
17277
|
-
email:
|
|
17735
|
+
var JwtHeaderSchema = import_zod26.z.looseObject({ alg: import_zod26.z.string(), kid: import_zod26.z.string().optional() });
|
|
17736
|
+
var IdTokenClaimsSchema = import_zod26.z.looseObject({
|
|
17737
|
+
iss: import_zod26.z.string(),
|
|
17738
|
+
sub: import_zod26.z.string().min(1),
|
|
17739
|
+
aud: import_zod26.z.union([import_zod26.z.string(), import_zod26.z.array(import_zod26.z.string())]),
|
|
17740
|
+
exp: import_zod26.z.number(),
|
|
17741
|
+
nonce: import_zod26.z.string().optional(),
|
|
17742
|
+
email: import_zod26.z.string().optional()
|
|
17278
17743
|
});
|
|
17279
|
-
var JwksSchema =
|
|
17744
|
+
var JwksSchema = import_zod26.z.object({ keys: import_zod26.z.array(import_zod26.z.looseObject({ kid: import_zod26.z.string().optional(), kty: import_zod26.z.string() })) });
|
|
17280
17745
|
|
|
17281
17746
|
// src/codex/siwcStore.ts
|
|
17282
|
-
var SiwcGrantSchema =
|
|
17283
|
-
clientId:
|
|
17284
|
-
sub:
|
|
17285
|
-
email:
|
|
17286
|
-
idToken:
|
|
17287
|
-
accessToken:
|
|
17288
|
-
refreshToken:
|
|
17289
|
-
scopes:
|
|
17747
|
+
var SiwcGrantSchema = import_zod27.z.strictObject({
|
|
17748
|
+
clientId: import_zod27.z.string().min(1),
|
|
17749
|
+
sub: import_zod27.z.string().min(1),
|
|
17750
|
+
email: import_zod27.z.string().optional(),
|
|
17751
|
+
idToken: import_zod27.z.string().min(1),
|
|
17752
|
+
accessToken: import_zod27.z.string().min(1),
|
|
17753
|
+
refreshToken: import_zod27.z.string().min(1),
|
|
17754
|
+
scopes: import_zod27.z.array(import_zod27.z.string()).readonly(),
|
|
17290
17755
|
/** When the access token stops working, in milliseconds since the epoch. */
|
|
17291
|
-
expiresAt:
|
|
17756
|
+
expiresAt: import_zod27.z.number()
|
|
17292
17757
|
});
|
|
17293
|
-
var SiwcFileSchema =
|
|
17758
|
+
var SiwcFileSchema = import_zod27.z.strictObject({ registeredClientId: import_zod27.z.string().min(1).optional(), grant: SiwcGrantSchema.optional() });
|
|
17294
17759
|
function parseSiwcFile(raw, filePath) {
|
|
17295
17760
|
let json;
|
|
17296
17761
|
try {
|
|
@@ -17546,7 +18011,7 @@ function pushFrontDoorListeners(push, readings) {
|
|
|
17546
18011
|
}
|
|
17547
18012
|
|
|
17548
18013
|
// src/frontdoor/listenerReadings.ts
|
|
17549
|
-
var
|
|
18014
|
+
var import_node_fs10 = __toESM(require("node:fs"), 1);
|
|
17550
18015
|
init_probe();
|
|
17551
18016
|
function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
17552
18017
|
if (!supervisorAlive) {
|
|
@@ -17567,7 +18032,7 @@ function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
|
17567
18032
|
}
|
|
17568
18033
|
function realFrontDoorListenerProbes(paths) {
|
|
17569
18034
|
return {
|
|
17570
|
-
authenticateProvider: (port) => probeFrontDoorSync(port,
|
|
18035
|
+
authenticateProvider: (port) => probeFrontDoorSync(port, import_node_fs10.default.readFileSync(paths.frontdoorCaCertFile, "utf8")),
|
|
17571
18036
|
connect: probeListenerAcceptSync,
|
|
17572
18037
|
now: () => performance.now()
|
|
17573
18038
|
};
|
|
@@ -17712,8 +18177,8 @@ function validateJson(schema, input) {
|
|
|
17712
18177
|
let parsed;
|
|
17713
18178
|
try {
|
|
17714
18179
|
parsed = JSON.parse(input.raw);
|
|
17715
|
-
} catch
|
|
17716
|
-
return { ok: false, message: `${input.path} is not valid JSON
|
|
18180
|
+
} catch {
|
|
18181
|
+
return { ok: false, message: `${input.path} is not valid JSON.` };
|
|
17717
18182
|
}
|
|
17718
18183
|
const result = parseIgnoringUnrecognisedKeys(schema, parsed);
|
|
17719
18184
|
if (!result.success) {
|
|
@@ -17732,7 +18197,7 @@ function tcpPortEraRecord(raw) {
|
|
|
17732
18197
|
return (has("port") || has("lastPort")) && !has("socketPath");
|
|
17733
18198
|
}
|
|
17734
18199
|
function pushPathResolution(push, resolution) {
|
|
17735
|
-
const ownDir =
|
|
18200
|
+
const ownDir = import_node_path31.default.dirname(resolution.ownExecutablePath);
|
|
17736
18201
|
switch (resolution.agentShim.status) {
|
|
17737
18202
|
case "ok":
|
|
17738
18203
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -17819,8 +18284,8 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
17819
18284
|
let parsed;
|
|
17820
18285
|
try {
|
|
17821
18286
|
parsed = JSON.parse(entry.raw);
|
|
17822
|
-
} catch
|
|
17823
|
-
push("provider", "fail", `${entry.path} is not valid JSON
|
|
18287
|
+
} catch {
|
|
18288
|
+
push("provider", "fail", `${entry.path} is not valid JSON.`, entry.name);
|
|
17824
18289
|
return;
|
|
17825
18290
|
}
|
|
17826
18291
|
const conversion = legacyProviderConversion(parsed);
|
|
@@ -17852,14 +18317,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
17852
18317
|
}
|
|
17853
18318
|
function pushLegacyName(push, params) {
|
|
17854
18319
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
17855
|
-
if (legacyVariables.length === 0 &&
|
|
18320
|
+
if (legacyVariables.length === 0 && import_node_path31.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
17856
18321
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
17857
18322
|
return;
|
|
17858
18323
|
}
|
|
17859
18324
|
for (const name of legacyVariables) {
|
|
17860
18325
|
push("legacy-name", "warn", `${name} is the former name of ${name.replace(LEGACY_ENV_PREFIX, ENV_PREFIX)}. Rename it; the old name still works but is only a fallback.`, name);
|
|
17861
18326
|
}
|
|
17862
|
-
if (
|
|
18327
|
+
if (import_node_path31.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
17863
18328
|
push(
|
|
17864
18329
|
"legacy-name",
|
|
17865
18330
|
"warn",
|
|
@@ -17945,6 +18410,16 @@ function runDoctor(params) {
|
|
|
17945
18410
|
}
|
|
17946
18411
|
const validProfileNames = new Set(profileSources.keys());
|
|
17947
18412
|
const validProviderNames = /* @__PURE__ */ new Set([...params.providers.map((entry) => entry.name), ...Object.keys(params.providerAliases ?? {})]);
|
|
18413
|
+
const identityNames = new Set(params.identities.filter((entry) => entry.raw !== void 0).map((entry) => entry.name));
|
|
18414
|
+
for (const journal of params.renameJournals?.journals ?? []) {
|
|
18415
|
+
push("identity", "fail", `There is ${describeUnfinishedRename(journal, finishabilityOf(journal, (name) => identityNames.has(name)))}`, journal.from);
|
|
18416
|
+
}
|
|
18417
|
+
for (const { name, code } of params.unreachableIdentities ?? []) {
|
|
18418
|
+
push("identity", "warn", `identities/${name} cannot be reached (${code}), so it is not counted as an identity. Repair the permissions of the directory or of what a symlink points through, or remove the entry.`, name);
|
|
18419
|
+
}
|
|
18420
|
+
for (const { file, detail } of params.renameJournals?.unreadable ?? []) {
|
|
18421
|
+
push("identity", "fail", `${file} is not a rename journal this agent-shim can read (${detail}), so no identity can be renamed until it is fixed or removed, and it may be the trace of a rename that was left unfinished.`, import_node_path31.default.basename(file));
|
|
18422
|
+
}
|
|
17948
18423
|
const validIdentityNames = /* @__PURE__ */ new Set();
|
|
17949
18424
|
const signedInAccounts = [];
|
|
17950
18425
|
for (const entry of params.identities) {
|
|
@@ -18295,7 +18770,7 @@ function formatDoctorReport(report) {
|
|
|
18295
18770
|
}
|
|
18296
18771
|
function realpathOrSelf(target) {
|
|
18297
18772
|
try {
|
|
18298
|
-
return
|
|
18773
|
+
return import_node_fs11.default.realpathSync(target);
|
|
18299
18774
|
} catch {
|
|
18300
18775
|
return target;
|
|
18301
18776
|
}
|
|
@@ -18307,11 +18782,11 @@ function servingDoorListeners(paths) {
|
|
|
18307
18782
|
}
|
|
18308
18783
|
function collectDoctorReport(params) {
|
|
18309
18784
|
const { paths } = params;
|
|
18310
|
-
const
|
|
18785
|
+
const { names: identityNames, unreachable: unreachableIdentities } = listIdentityDirectories(paths);
|
|
18311
18786
|
const identities = identityNames.map((name) => {
|
|
18312
|
-
const farmRoot =
|
|
18313
|
-
const identityPath =
|
|
18314
|
-
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent:
|
|
18787
|
+
const farmRoot = import_node_path31.default.join(paths.identitiesDir, name);
|
|
18788
|
+
const identityPath = import_node_path31.default.join(farmRoot, "identity.json");
|
|
18789
|
+
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs11.default.existsSync(credentialsFilePath(farmRoot)), account: readIdentityAccount(realFsPort, paths.identitiesDir, name)?.account };
|
|
18315
18790
|
});
|
|
18316
18791
|
const usageSnapshots = {};
|
|
18317
18792
|
for (const name of identityNames) {
|
|
@@ -18326,14 +18801,14 @@ function collectDoctorReport(params) {
|
|
|
18326
18801
|
}
|
|
18327
18802
|
}
|
|
18328
18803
|
}
|
|
18329
|
-
const profileNames =
|
|
18804
|
+
const profileNames = import_node_fs11.default.existsSync(paths.configProfilesDir) ? import_node_fs11.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
18330
18805
|
const configProfiles = profileNames.map((name) => {
|
|
18331
|
-
const profilePath =
|
|
18806
|
+
const profilePath = import_node_path31.default.join(paths.configProfilesDir, `${name}.json`);
|
|
18332
18807
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
18333
18808
|
});
|
|
18334
|
-
const providerNames =
|
|
18809
|
+
const providerNames = import_node_fs11.default.existsSync(paths.providersDir) ? import_node_fs11.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
18335
18810
|
const providers = providerNames.map((name) => {
|
|
18336
|
-
const providerPath =
|
|
18811
|
+
const providerPath = import_node_path31.default.join(paths.providersDir, `${name}.json`);
|
|
18337
18812
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
18338
18813
|
});
|
|
18339
18814
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -18345,12 +18820,12 @@ function collectDoctorReport(params) {
|
|
|
18345
18820
|
binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
18346
18821
|
}
|
|
18347
18822
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
18348
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
18823
|
+
const pathDirs = (params.env.PATH ?? "").split(import_node_path31.default.delimiter).filter((dir) => dir !== "");
|
|
18349
18824
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
18350
18825
|
findPathShadow({
|
|
18351
18826
|
pathDirs,
|
|
18352
|
-
targetDir:
|
|
18353
|
-
targetFilename:
|
|
18827
|
+
targetDir: import_node_path31.default.dirname(shimState.targetPath),
|
|
18828
|
+
targetFilename: import_node_path31.default.basename(shimState.targetPath),
|
|
18354
18829
|
findExecutableInDir
|
|
18355
18830
|
}),
|
|
18356
18831
|
shimState.targetPath,
|
|
@@ -18373,6 +18848,8 @@ function collectDoctorReport(params) {
|
|
|
18373
18848
|
configProfiles,
|
|
18374
18849
|
providers,
|
|
18375
18850
|
providerAliases: readProviderAliases(paths),
|
|
18851
|
+
renameJournals: listRenameJournals(realFarmFs, paths.identityRenamesDir),
|
|
18852
|
+
unreachableIdentities,
|
|
18376
18853
|
directoryRules: { path: paths.directoryRulesFile, raw: realFsPort.readFileUtf8(paths.directoryRulesFile) },
|
|
18377
18854
|
globalConfig: { path: paths.globalConfigFile, raw: realFsPort.readFileUtf8(paths.globalConfigFile) },
|
|
18378
18855
|
models: parsedModelsOf(paths),
|
|
@@ -18380,14 +18857,14 @@ function collectDoctorReport(params) {
|
|
|
18380
18857
|
categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
|
|
18381
18858
|
activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
|
|
18382
18859
|
binaryDiscovery,
|
|
18383
|
-
claudeShim: { state: shimState, targetExists: shimState !== void 0 &&
|
|
18860
|
+
claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs11.default.existsSync(shimState.targetPath) },
|
|
18384
18861
|
rootPath: paths.root,
|
|
18385
18862
|
pathResolution: {
|
|
18386
18863
|
ownExecutablePath,
|
|
18387
18864
|
agentShim: refinePathShadow(
|
|
18388
18865
|
findPathShadow({
|
|
18389
18866
|
pathDirs,
|
|
18390
|
-
targetDir:
|
|
18867
|
+
targetDir: import_node_path31.default.dirname(ownExecutablePath),
|
|
18391
18868
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
18392
18869
|
findExecutableInDir
|
|
18393
18870
|
}),
|
|
@@ -18428,92 +18905,92 @@ function collectDoctorReport(params) {
|
|
|
18428
18905
|
// src/frontdoor/controlSchemas.ts
|
|
18429
18906
|
init_schema2();
|
|
18430
18907
|
init_state();
|
|
18431
|
-
var UsageListOutputSchema =
|
|
18432
|
-
var UsageWindowsInputSchema =
|
|
18433
|
-
identity:
|
|
18434
|
-
provider:
|
|
18908
|
+
var UsageListOutputSchema = import_zod30.z.strictObject({ snapshots: import_zod30.z.readonly(import_zod30.z.array(UsageSnapshotSchema)) });
|
|
18909
|
+
var UsageWindowsInputSchema = import_zod30.z.strictObject({
|
|
18910
|
+
identity: import_zod30.z.string().min(1),
|
|
18911
|
+
provider: import_zod30.z.string().min(1).optional()
|
|
18435
18912
|
});
|
|
18436
|
-
var EffectiveWindowSchema =
|
|
18913
|
+
var EffectiveWindowSchema = import_zod30.z.strictObject({
|
|
18437
18914
|
/** True when the window's reset time has passed, so the recorded observation describes a window that no longer exists. */
|
|
18438
|
-
reset:
|
|
18915
|
+
reset: import_zod30.z.boolean(),
|
|
18439
18916
|
/** The fraction used: 0 for a reset window, otherwise what was last observed, absent when none was reported. */
|
|
18440
|
-
utilization:
|
|
18917
|
+
utilization: import_zod30.z.number().optional(),
|
|
18441
18918
|
/** The reset instant, for a window that has not reset yet and reported one. */
|
|
18442
|
-
resetsAtMs:
|
|
18919
|
+
resetsAtMs: import_zod30.z.number().optional(),
|
|
18443
18920
|
/** The window's own status, for a window that has not reset yet. */
|
|
18444
|
-
status:
|
|
18921
|
+
status: import_zod30.z.string().optional()
|
|
18445
18922
|
});
|
|
18446
|
-
var UsageWindowsOutputSchema =
|
|
18447
|
-
identity:
|
|
18448
|
-
provider:
|
|
18923
|
+
var UsageWindowsOutputSchema = import_zod30.z.strictObject({
|
|
18924
|
+
identity: import_zod30.z.string(),
|
|
18925
|
+
provider: import_zod30.z.string(),
|
|
18449
18926
|
/** When the rate-limit state the windows come from was observed. */
|
|
18450
|
-
observedAt:
|
|
18927
|
+
observedAt: import_zod30.z.iso.datetime().optional(),
|
|
18451
18928
|
fiveHour: EffectiveWindowSchema.optional(),
|
|
18452
18929
|
sevenDay: EffectiveWindowSchema.optional()
|
|
18453
18930
|
});
|
|
18454
|
-
var UsageLiveOutputSchema =
|
|
18931
|
+
var UsageLiveOutputSchema = import_zod30.z.strictObject({
|
|
18455
18932
|
/** The freshest observation the door holds, never narrowed by the read's session filter because it is the door's single latest statement of the account's quota; absent while no rate_limit_event has been filed at all. */
|
|
18456
18933
|
latest: RcLiveRateLimitSchema.optional(),
|
|
18457
18934
|
/** One observation per session whose stream has filed a rate_limit_event this door generation. */
|
|
18458
|
-
sessions:
|
|
18935
|
+
sessions: import_zod30.z.readonly(import_zod30.z.array(RcLiveRateLimitSchema))
|
|
18459
18936
|
});
|
|
18460
|
-
var FrontDoorSessionStatusSchema =
|
|
18461
|
-
pid:
|
|
18462
|
-
startedAt:
|
|
18463
|
-
alive:
|
|
18937
|
+
var FrontDoorSessionStatusSchema = import_zod30.z.strictObject({
|
|
18938
|
+
pid: import_zod30.z.int().positive(),
|
|
18939
|
+
startedAt: import_zod30.z.number(),
|
|
18940
|
+
alive: import_zod30.z.boolean()
|
|
18464
18941
|
});
|
|
18465
|
-
var HeadroomSocketTargetSchema =
|
|
18466
|
-
var FrontDoorStatusOutputSchema =
|
|
18942
|
+
var HeadroomSocketTargetSchema = import_zod30.z.union([import_zod30.z.strictObject({ socketPath: import_zod30.z.string() }), import_zod30.z.strictObject({ refused: import_zod30.z.string() })]);
|
|
18943
|
+
var FrontDoorStatusOutputSchema = import_zod30.z.strictObject({
|
|
18467
18944
|
state: FrontDoorStateSchema,
|
|
18468
|
-
supervisorAlive:
|
|
18945
|
+
supervisorAlive: import_zod30.z.boolean(),
|
|
18469
18946
|
/** The pids of earlier doors that released their addresses and are finishing the connections they carried: running, but not serving anything new. */
|
|
18470
|
-
draining:
|
|
18471
|
-
sessions:
|
|
18947
|
+
draining: import_zod30.z.readonly(import_zod30.z.array(import_zod30.z.number().int().positive())),
|
|
18948
|
+
sessions: import_zod30.z.readonly(import_zod30.z.array(FrontDoorSessionStatusSchema)),
|
|
18472
18949
|
headroomSocket: HeadroomSocketTargetSchema.optional(),
|
|
18473
|
-
logPath:
|
|
18474
|
-
logExists:
|
|
18950
|
+
logPath: import_zod30.z.string(),
|
|
18951
|
+
logExists: import_zod30.z.boolean()
|
|
18475
18952
|
});
|
|
18476
|
-
var FrontDoorSessionsOutputSchema =
|
|
18477
|
-
var CheckRunInputSchema =
|
|
18478
|
-
path:
|
|
18479
|
-
identity:
|
|
18480
|
-
}).refine((input) =>
|
|
18481
|
-
var PoolPickInputSchema =
|
|
18482
|
-
pool:
|
|
18483
|
-
path:
|
|
18484
|
-
}).refine((input) =>
|
|
18485
|
-
var DoctorFindingSchema =
|
|
18486
|
-
section:
|
|
18487
|
-
subject:
|
|
18488
|
-
severity:
|
|
18489
|
-
message:
|
|
18953
|
+
var FrontDoorSessionsOutputSchema = import_zod30.z.strictObject({ sessions: import_zod30.z.readonly(import_zod30.z.array(FrontDoorSessionStatusSchema)) });
|
|
18954
|
+
var CheckRunInputSchema = import_zod30.z.strictObject({
|
|
18955
|
+
path: import_zod30.z.string().min(1),
|
|
18956
|
+
identity: import_zod30.z.string().min(1).optional()
|
|
18957
|
+
}).refine((input) => import_node_path32.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
18958
|
+
var PoolPickInputSchema = import_zod30.z.strictObject({
|
|
18959
|
+
pool: import_zod30.z.string().min(1),
|
|
18960
|
+
path: import_zod30.z.string().min(1)
|
|
18961
|
+
}).refine((input) => import_node_path32.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
18962
|
+
var DoctorFindingSchema = import_zod30.z.strictObject({
|
|
18963
|
+
section: import_zod30.z.enum(DOCTOR_SECTIONS),
|
|
18964
|
+
subject: import_zod30.z.string().optional(),
|
|
18965
|
+
severity: import_zod30.z.enum(DOCTOR_SEVERITIES),
|
|
18966
|
+
message: import_zod30.z.string()
|
|
18490
18967
|
});
|
|
18491
|
-
var DoctorRunOutputSchema =
|
|
18968
|
+
var DoctorRunOutputSchema = import_zod30.z.strictObject({
|
|
18492
18969
|
/** False exactly when any finding is a `fail`; a `warn` never fails the report on its own. */
|
|
18493
|
-
ok:
|
|
18494
|
-
findings:
|
|
18970
|
+
ok: import_zod30.z.boolean(),
|
|
18971
|
+
findings: import_zod30.z.readonly(import_zod30.z.array(DoctorFindingSchema))
|
|
18495
18972
|
});
|
|
18496
|
-
var FrontDoorRestartOutputSchema =
|
|
18497
|
-
action:
|
|
18498
|
-
previousPid:
|
|
18973
|
+
var FrontDoorRestartOutputSchema = import_zod30.z.strictObject({
|
|
18974
|
+
action: import_zod30.z.literal("restarting"),
|
|
18975
|
+
previousPid: import_zod30.z.int().positive()
|
|
18499
18976
|
});
|
|
18500
|
-
var UpdateCheckOutputSchema =
|
|
18501
|
-
current:
|
|
18502
|
-
latest:
|
|
18503
|
-
action:
|
|
18977
|
+
var UpdateCheckOutputSchema = import_zod30.z.strictObject({
|
|
18978
|
+
current: import_zod30.z.string(),
|
|
18979
|
+
latest: import_zod30.z.string(),
|
|
18980
|
+
action: import_zod30.z.enum(["current", "available", "updated"])
|
|
18504
18981
|
});
|
|
18505
|
-
var CodexSignInSchema =
|
|
18506
|
-
|
|
18507
|
-
|
|
18508
|
-
|
|
18982
|
+
var CodexSignInSchema = import_zod30.z.discriminatedUnion("state", [
|
|
18983
|
+
import_zod30.z.strictObject({ state: import_zod30.z.literal("none") }),
|
|
18984
|
+
import_zod30.z.strictObject({ state: import_zod30.z.literal("signed-in"), email: import_zod30.z.string().optional(), planScope: import_zod30.z.boolean(), accessTokenExpiresAt: import_zod30.z.number() }),
|
|
18985
|
+
import_zod30.z.strictObject({ state: import_zod30.z.literal("unreadable"), message: import_zod30.z.string() })
|
|
18509
18986
|
]);
|
|
18510
|
-
var CodexStatusOutputSchema =
|
|
18987
|
+
var CodexStatusOutputSchema = import_zod30.z.strictObject({
|
|
18511
18988
|
signIn: CodexSignInSchema,
|
|
18512
|
-
codexProviders:
|
|
18989
|
+
codexProviders: import_zod30.z.readonly(import_zod30.z.array(import_zod30.z.string()))
|
|
18513
18990
|
});
|
|
18514
|
-
var CodexLogoutOutputSchema =
|
|
18515
|
-
hadGrant:
|
|
18516
|
-
revoked:
|
|
18991
|
+
var CodexLogoutOutputSchema = import_zod30.z.strictObject({
|
|
18992
|
+
hadGrant: import_zod30.z.boolean(),
|
|
18993
|
+
revoked: import_zod30.z.boolean()
|
|
18517
18994
|
});
|
|
18518
18995
|
|
|
18519
18996
|
// src/frontdoor/codexApi.ts
|
|
@@ -18668,72 +19145,74 @@ function requireRuleSelector(paths, selector) {
|
|
|
18668
19145
|
|
|
18669
19146
|
// src/frontdoor/configApi.ts
|
|
18670
19147
|
init_identity();
|
|
19148
|
+
init_replayRun();
|
|
18671
19149
|
init_providersStore();
|
|
18672
19150
|
|
|
18673
19151
|
// src/frontdoor/configSchemas.ts
|
|
18674
|
-
var
|
|
19152
|
+
var import_zod31 = require("zod");
|
|
18675
19153
|
init_schema();
|
|
18676
19154
|
init_names();
|
|
18677
19155
|
init_statusline();
|
|
18678
|
-
var RemovalConfirmationSchema =
|
|
18679
|
-
var CredentialWriteSchema = (targets) =>
|
|
18680
|
-
sources:
|
|
18681
|
-
target:
|
|
18682
|
-
cache:
|
|
19156
|
+
var RemovalConfirmationSchema = import_zod31.z.boolean();
|
|
19157
|
+
var CredentialWriteSchema = (targets) => import_zod31.z.strictObject({
|
|
19158
|
+
sources: import_zod31.z.array(RemoteCredentialSourceSchema).min(1).optional(),
|
|
19159
|
+
target: import_zod31.z.enum(targets).optional(),
|
|
19160
|
+
cache: import_zod31.z.union([import_zod31.z.literal(false), CredentialCacheSchema]).optional()
|
|
18683
19161
|
});
|
|
18684
|
-
var CredentialSummarySchema2 =
|
|
18685
|
-
target:
|
|
18686
|
-
sources:
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
18692
|
-
|
|
18693
|
-
|
|
19162
|
+
var CredentialSummarySchema2 = import_zod31.z.strictObject({
|
|
19163
|
+
target: import_zod31.z.enum(CREDENTIAL_TARGETS),
|
|
19164
|
+
sources: import_zod31.z.readonly(import_zod31.z.array(
|
|
19165
|
+
import_zod31.z.discriminatedUnion("kind", [
|
|
19166
|
+
import_zod31.z.strictObject({ kind: import_zod31.z.literal("env"), variable: import_zod31.z.string() }),
|
|
19167
|
+
import_zod31.z.strictObject({ kind: import_zod31.z.literal("file"), path: import_zod31.z.string() }),
|
|
19168
|
+
import_zod31.z.strictObject({ kind: import_zod31.z.literal("command"), program: import_zod31.z.string() }),
|
|
19169
|
+
import_zod31.z.strictObject({ kind: import_zod31.z.literal("op"), reference: import_zod31.z.string() }),
|
|
19170
|
+
import_zod31.z.strictObject({ kind: import_zod31.z.literal("keychain"), service: import_zod31.z.string(), account: import_zod31.z.string().optional() }),
|
|
19171
|
+
import_zod31.z.strictObject({ kind: import_zod31.z.literal("literal") })
|
|
18694
19172
|
])
|
|
18695
19173
|
)),
|
|
18696
19174
|
cache: CredentialCacheSchema.optional()
|
|
18697
19175
|
});
|
|
18698
|
-
var mutationOutput = (kind, action) =>
|
|
18699
|
-
var storedMutationOutput = (kind, action, value) =>
|
|
18700
|
-
var IdentityValueSchema =
|
|
18701
|
-
name:
|
|
18702
|
-
label:
|
|
18703
|
-
defaultConfigProfile:
|
|
18704
|
-
provider:
|
|
18705
|
-
allowAmbientCredential:
|
|
19176
|
+
var mutationOutput = (kind, action) => import_zod31.z.strictObject({ action: import_zod31.z.literal(action), kind: import_zod31.z.literal(kind), name: import_zod31.z.string() });
|
|
19177
|
+
var storedMutationOutput = (kind, action, value) => import_zod31.z.strictObject({ action: import_zod31.z.literal(action), kind: import_zod31.z.literal(kind), name: import_zod31.z.string(), value });
|
|
19178
|
+
var IdentityValueSchema = import_zod31.z.strictObject({
|
|
19179
|
+
name: import_zod31.z.string(),
|
|
19180
|
+
label: import_zod31.z.string().optional(),
|
|
19181
|
+
defaultConfigProfile: import_zod31.z.string().optional(),
|
|
19182
|
+
provider: import_zod31.z.string().optional(),
|
|
19183
|
+
allowAmbientCredential: import_zod31.z.boolean(),
|
|
18706
19184
|
credential: CredentialSummarySchema2.optional(),
|
|
18707
|
-
anchors:
|
|
19185
|
+
anchors: import_zod31.z.array(AnchorSchema).optional()
|
|
18708
19186
|
});
|
|
18709
19187
|
var ProfileValueSchema = ConfigProfileSchema.omit({ $schema: true });
|
|
18710
|
-
var ProviderValueSchema =
|
|
18711
|
-
name:
|
|
18712
|
-
kind:
|
|
18713
|
-
displayName:
|
|
18714
|
-
baseUrl:
|
|
19188
|
+
var ProviderValueSchema = import_zod31.z.strictObject({
|
|
19189
|
+
name: import_zod31.z.string(),
|
|
19190
|
+
kind: import_zod31.z.enum(PROVIDER_KINDS),
|
|
19191
|
+
displayName: import_zod31.z.string(),
|
|
19192
|
+
baseUrl: import_zod31.z.string().optional(),
|
|
18715
19193
|
codex: CodexProviderConfigSchema.optional(),
|
|
18716
19194
|
credential: CredentialSummarySchema2.optional(),
|
|
18717
|
-
env:
|
|
19195
|
+
env: import_zod31.z.record(import_zod31.z.string(), import_zod31.z.string()).optional()
|
|
18718
19196
|
});
|
|
18719
|
-
var ConfigNameInputSchema =
|
|
19197
|
+
var ConfigNameInputSchema = import_zod31.z.strictObject({ name: import_zod31.z.string().min(1) });
|
|
19198
|
+
var ConfigIdentityAddInputSchema = import_zod31.z.strictObject({ name: import_zod31.z.string().min(1), keepKeychainLogin: import_zod31.z.boolean().optional().describe(KEEP_KEYCHAIN_LOGIN_DESCRIPTION) });
|
|
18720
19199
|
var ConfigIdentityAddOutputSchema = storedMutationOutput("identity", "created", IdentityValueSchema);
|
|
18721
|
-
var ConfigIdentitySetInputSchema =
|
|
18722
|
-
name:
|
|
19200
|
+
var ConfigIdentitySetInputSchema = import_zod31.z.strictObject({
|
|
19201
|
+
name: import_zod31.z.string().min(1),
|
|
18723
19202
|
/** The identity's display label; `false` clears it. */
|
|
18724
|
-
label:
|
|
18725
|
-
defaultConfigProfile:
|
|
19203
|
+
label: import_zod31.z.union([IdentityLabelSchema, import_zod31.z.literal(false)]).optional(),
|
|
19204
|
+
defaultConfigProfile: import_zod31.z.union([import_zod31.z.string().min(1), import_zod31.z.literal(false)]).optional(),
|
|
18726
19205
|
/** The provider the identity exists for; `false` clears it. */
|
|
18727
|
-
provider:
|
|
18728
|
-
allowAmbientCredential:
|
|
18729
|
-
credential:
|
|
19206
|
+
provider: import_zod31.z.union([import_zod31.z.string().min(1), import_zod31.z.literal(false)]).optional(),
|
|
19207
|
+
allowAmbientCredential: import_zod31.z.boolean().optional(),
|
|
19208
|
+
credential: import_zod31.z.union([import_zod31.z.literal(false), CredentialWriteSchema(CREDENTIAL_TARGETS)]).optional(),
|
|
18730
19209
|
/** `false` removes the anchors; a list replaces them. */
|
|
18731
|
-
anchors:
|
|
19210
|
+
anchors: import_zod31.z.union([import_zod31.z.literal(false), import_zod31.z.array(AnchorSchema).min(1)]).optional()
|
|
18732
19211
|
});
|
|
18733
19212
|
var ConfigIdentitySetOutputSchema = storedMutationOutput("identity", "updated", IdentityValueSchema);
|
|
18734
|
-
var ConfigIdentityRemoveInputSchema =
|
|
19213
|
+
var ConfigIdentityRemoveInputSchema = import_zod31.z.strictObject({ name: import_zod31.z.string().min(1), confirm: RemovalConfirmationSchema });
|
|
18735
19214
|
var ConfigIdentityRemoveOutputSchema = mutationOutput("identity", "removed");
|
|
18736
|
-
var ConfigStatuslineSetSchema =
|
|
19215
|
+
var ConfigStatuslineSetSchema = import_zod31.z.record(import_zod31.z.string(), import_zod31.z.unknown()).superRefine((settings, context) => {
|
|
18737
19216
|
for (const key of Object.keys(settings)) {
|
|
18738
19217
|
if (key === STATUSLINE_EXTRA_GROUP || key.startsWith(`${STATUSLINE_EXTRA_GROUP}.`)) {
|
|
18739
19218
|
context.addIssue({ code: "custom", path: [key], message: `a config write through the API cannot set "${key}": the extra segment's command runs a program, so only your own configuration (the global config, a profile you edit yourself, a directory rule or a command-line assignment) may set it` });
|
|
@@ -18741,102 +19220,105 @@ var ConfigStatuslineSetSchema = import_zod30.z.record(import_zod30.z.string(), i
|
|
|
18741
19220
|
}
|
|
18742
19221
|
});
|
|
18743
19222
|
var ConfigIdentityUseOutputSchema = mutationOutput("identity", "selected");
|
|
18744
|
-
var ConfigProfileAddInputSchema =
|
|
18745
|
-
name:
|
|
18746
|
-
extends:
|
|
18747
|
-
description:
|
|
19223
|
+
var ConfigProfileAddInputSchema = import_zod31.z.strictObject({
|
|
19224
|
+
name: import_zod31.z.string().min(1),
|
|
19225
|
+
extends: import_zod31.z.array(import_zod31.z.string().min(1)).optional(),
|
|
19226
|
+
description: import_zod31.z.string().optional()
|
|
18748
19227
|
});
|
|
18749
19228
|
var ConfigProfileAddOutputSchema = storedMutationOutput("profile", "created", ProfileValueSchema);
|
|
18750
|
-
var ConfigProfileSetInputSchema =
|
|
18751
|
-
name:
|
|
18752
|
-
category:
|
|
18753
|
-
entry:
|
|
18754
|
-
extends:
|
|
18755
|
-
description:
|
|
18756
|
-
launch:
|
|
18757
|
-
skipPermissions:
|
|
18758
|
-
remoteControl:
|
|
18759
|
-
headroom:
|
|
18760
|
-
trackUsage:
|
|
18761
|
-
provider:
|
|
18762
|
-
claudeVersion:
|
|
18763
|
-
delay:
|
|
18764
|
-
pause:
|
|
18765
|
-
explain:
|
|
18766
|
-
proxyBypass:
|
|
18767
|
-
statusline:
|
|
19229
|
+
var ConfigProfileSetInputSchema = import_zod31.z.strictObject({
|
|
19230
|
+
name: import_zod31.z.string().min(1),
|
|
19231
|
+
category: import_zod31.z.record(import_zod31.z.string(), import_zod31.z.boolean()).optional(),
|
|
19232
|
+
entry: import_zod31.z.record(import_zod31.z.string(), import_zod31.z.boolean()).optional(),
|
|
19233
|
+
extends: import_zod31.z.union([import_zod31.z.array(import_zod31.z.string().min(1)), import_zod31.z.literal(false)]).optional(),
|
|
19234
|
+
description: import_zod31.z.union([import_zod31.z.string(), import_zod31.z.literal(false)]).optional(),
|
|
19235
|
+
launch: import_zod31.z.strictObject({
|
|
19236
|
+
skipPermissions: import_zod31.z.boolean().optional(),
|
|
19237
|
+
remoteControl: import_zod31.z.boolean().optional(),
|
|
19238
|
+
headroom: import_zod31.z.boolean().optional(),
|
|
19239
|
+
trackUsage: import_zod31.z.boolean().optional(),
|
|
19240
|
+
provider: import_zod31.z.union([import_zod31.z.string().min(1), import_zod31.z.literal(false)]).optional(),
|
|
19241
|
+
claudeVersion: import_zod31.z.union([import_zod31.z.string().min(1), import_zod31.z.literal(false)]).optional(),
|
|
19242
|
+
delay: import_zod31.z.union([import_zod31.z.string().regex(DURATION_RE), import_zod31.z.literal(false)]).optional(),
|
|
19243
|
+
pause: import_zod31.z.boolean().optional(),
|
|
19244
|
+
explain: import_zod31.z.boolean().optional(),
|
|
19245
|
+
proxyBypass: import_zod31.z.union([import_zod31.z.array(import_zod31.z.string().min(1)), import_zod31.z.literal(false)]).optional(),
|
|
19246
|
+
statusline: import_zod31.z.strictObject({
|
|
18768
19247
|
set: ConfigStatuslineSetSchema.optional(),
|
|
18769
|
-
unset:
|
|
19248
|
+
unset: import_zod31.z.array(import_zod31.z.string()).optional()
|
|
18770
19249
|
}).optional()
|
|
18771
19250
|
}).optional()
|
|
18772
19251
|
});
|
|
18773
19252
|
var ConfigProfileSetOutputSchema = storedMutationOutput("profile", "updated", ProfileValueSchema);
|
|
18774
|
-
var ConfigProfileRemoveInputSchema =
|
|
19253
|
+
var ConfigProfileRemoveInputSchema = import_zod31.z.strictObject({ name: import_zod31.z.string().min(1), confirm: RemovalConfirmationSchema });
|
|
18775
19254
|
var ConfigProfileRemoveOutputSchema = mutationOutput("profile", "removed");
|
|
18776
19255
|
var ConfigProfileUseOutputSchema = mutationOutput("profile", "selected");
|
|
18777
|
-
var PoolMembersInputSchema =
|
|
18778
|
-
var ConfigPoolAddInputSchema =
|
|
18779
|
-
name:
|
|
19256
|
+
var PoolMembersInputSchema = import_zod31.z.array(import_zod31.z.string().min(1)).min(1);
|
|
19257
|
+
var ConfigPoolAddInputSchema = import_zod31.z.strictObject({
|
|
19258
|
+
name: import_zod31.z.string().min(1),
|
|
18780
19259
|
identities: PoolMembersInputSchema,
|
|
18781
|
-
preference:
|
|
18782
|
-
resumeOnLimit:
|
|
18783
|
-
compactBeforeLimit:
|
|
19260
|
+
preference: import_zod31.z.enum(POOL_PREFERENCES).optional(),
|
|
19261
|
+
resumeOnLimit: import_zod31.z.boolean().optional(),
|
|
19262
|
+
compactBeforeLimit: import_zod31.z.boolean().optional(),
|
|
18784
19263
|
compactAtUtilisation: CompactAtUtilisationSchema.optional()
|
|
18785
19264
|
});
|
|
18786
19265
|
var ConfigPoolAddOutputSchema = storedMutationOutput("pool", "created", PoolSchema);
|
|
18787
|
-
var ConfigPoolSetInputSchema =
|
|
18788
|
-
name:
|
|
19266
|
+
var ConfigPoolSetInputSchema = import_zod31.z.strictObject({
|
|
19267
|
+
name: import_zod31.z.string().min(1),
|
|
18789
19268
|
identities: PoolMembersInputSchema.optional(),
|
|
18790
|
-
preference:
|
|
18791
|
-
resumeOnLimit:
|
|
18792
|
-
compactBeforeLimit:
|
|
18793
|
-
compactAtUtilisation:
|
|
19269
|
+
preference: import_zod31.z.union([import_zod31.z.enum(POOL_PREFERENCES), import_zod31.z.literal(false)]).optional(),
|
|
19270
|
+
resumeOnLimit: import_zod31.z.boolean().optional(),
|
|
19271
|
+
compactBeforeLimit: import_zod31.z.boolean().optional(),
|
|
19272
|
+
compactAtUtilisation: import_zod31.z.union([CompactAtUtilisationSchema, import_zod31.z.literal(false)]).optional()
|
|
18794
19273
|
});
|
|
18795
19274
|
var ConfigPoolSetOutputSchema = storedMutationOutput("pool", "updated", PoolSchema);
|
|
18796
|
-
var ConfigPoolRemoveInputSchema =
|
|
19275
|
+
var ConfigPoolRemoveInputSchema = import_zod31.z.strictObject({ name: import_zod31.z.string().min(1), confirm: RemovalConfirmationSchema });
|
|
18797
19276
|
var ConfigPoolRemoveOutputSchema = mutationOutput("pool", "removed");
|
|
18798
19277
|
var ConfigPoolUseOutputSchema = mutationOutput("pool", "selected");
|
|
18799
|
-
var ConfigProviderAddInputSchema =
|
|
18800
|
-
name:
|
|
18801
|
-
kind:
|
|
18802
|
-
displayName:
|
|
18803
|
-
baseUrl:
|
|
19278
|
+
var ConfigProviderAddInputSchema = import_zod31.z.strictObject({
|
|
19279
|
+
name: import_zod31.z.string().min(1),
|
|
19280
|
+
kind: import_zod31.z.enum(PROVIDER_KINDS).optional(),
|
|
19281
|
+
displayName: import_zod31.z.string().min(1),
|
|
19282
|
+
baseUrl: import_zod31.z.string().min(1).optional(),
|
|
18804
19283
|
credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).required({ sources: true }),
|
|
18805
19284
|
codex: CodexProviderConfigSchema.optional()
|
|
18806
19285
|
});
|
|
18807
19286
|
var ConfigProviderAddOutputSchema = storedMutationOutput("provider", "created", ProviderValueSchema);
|
|
18808
|
-
var ConfigProviderSetInputSchema =
|
|
18809
|
-
name:
|
|
18810
|
-
displayName:
|
|
18811
|
-
baseUrl:
|
|
19287
|
+
var ConfigProviderSetInputSchema = import_zod31.z.strictObject({
|
|
19288
|
+
name: import_zod31.z.string().min(1),
|
|
19289
|
+
displayName: import_zod31.z.string().min(1).optional(),
|
|
19290
|
+
baseUrl: import_zod31.z.string().min(1).optional(),
|
|
18812
19291
|
credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).optional(),
|
|
18813
19292
|
codex: CodexProviderConfigSchema.optional()
|
|
18814
19293
|
});
|
|
18815
19294
|
var ConfigProviderSetOutputSchema = storedMutationOutput("provider", "updated", ProviderValueSchema);
|
|
18816
|
-
var ConfigProviderRemoveInputSchema =
|
|
19295
|
+
var ConfigProviderRemoveInputSchema = import_zod31.z.strictObject({ name: import_zod31.z.string().min(1), confirm: RemovalConfirmationSchema });
|
|
18817
19296
|
var ConfigProviderRemoveOutputSchema = mutationOutput("provider", "removed");
|
|
18818
|
-
var ConfigRuleAddInputSchema =
|
|
18819
|
-
path:
|
|
18820
|
-
configProfile:
|
|
18821
|
-
identity:
|
|
19297
|
+
var ConfigRuleAddInputSchema = import_zod31.z.strictObject({
|
|
19298
|
+
path: import_zod31.z.string().min(1),
|
|
19299
|
+
configProfile: import_zod31.z.string().min(1).optional(),
|
|
19300
|
+
identity: import_zod31.z.string().min(1).optional()
|
|
18822
19301
|
});
|
|
18823
19302
|
var ConfigRuleAddOutputSchema = storedMutationOutput("rule", "created", DirectoryRuleSchema);
|
|
18824
|
-
var ConfigRuleSetInputSchema =
|
|
18825
|
-
path:
|
|
18826
|
-
configProfile:
|
|
18827
|
-
identity:
|
|
19303
|
+
var ConfigRuleSetInputSchema = import_zod31.z.strictObject({
|
|
19304
|
+
path: import_zod31.z.string().min(1),
|
|
19305
|
+
configProfile: import_zod31.z.union([import_zod31.z.string().min(1), import_zod31.z.literal(false)]).optional(),
|
|
19306
|
+
identity: import_zod31.z.union([import_zod31.z.string().min(1), import_zod31.z.literal(false)]).optional()
|
|
18828
19307
|
});
|
|
18829
19308
|
var ConfigRuleSetOutputSchema = storedMutationOutput("rule", "updated", DirectoryRuleSchema);
|
|
18830
|
-
var ConfigRuleRemoveInputSchema =
|
|
19309
|
+
var ConfigRuleRemoveInputSchema = import_zod31.z.strictObject({ path: import_zod31.z.string().min(1), confirm: RemovalConfirmationSchema });
|
|
18831
19310
|
var ConfigRuleRemoveOutputSchema = mutationOutput("rule", "removed");
|
|
18832
19311
|
|
|
18833
19312
|
// src/frontdoor/configApi.ts
|
|
18834
19313
|
var CONFIG_API_TAG = "config";
|
|
18835
19314
|
function refusal(error) {
|
|
19315
|
+
if (error instanceof KeychainLookupError) {
|
|
19316
|
+
throw new import_client2.ORPCError("SERVICE_UNAVAILABLE", { message: error.message });
|
|
19317
|
+
}
|
|
18836
19318
|
if (error instanceof IdentityNotFoundError || error instanceof ProfileNotFoundError || error instanceof PoolNotFoundError || error instanceof ProviderNotFoundError || error instanceof DirectoryRuleNotFoundError) {
|
|
18837
19319
|
throw new import_client2.ORPCError("NOT_FOUND", { message: error.message });
|
|
18838
19320
|
}
|
|
18839
|
-
if (error instanceof IdentityAlreadyExistsError || error instanceof ProfileAlreadyExistsError || error instanceof PoolAlreadyExistsError || error instanceof ProviderAlreadyExistsError || error instanceof DirectoryRuleAlreadyExistsError) {
|
|
19321
|
+
if (error instanceof IdentityAlreadyExistsError || error instanceof ProfileAlreadyExistsError || error instanceof PoolAlreadyExistsError || error instanceof ProviderAlreadyExistsError || error instanceof DirectoryRuleAlreadyExistsError || error instanceof KeychainLoginError) {
|
|
18840
19322
|
throw new import_client2.ORPCError("CONFLICT", { message: error.message });
|
|
18841
19323
|
}
|
|
18842
19324
|
if (error instanceof CliError) {
|
|
@@ -18844,6 +19326,13 @@ function refusal(error) {
|
|
|
18844
19326
|
}
|
|
18845
19327
|
throw error;
|
|
18846
19328
|
}
|
|
19329
|
+
async function guardedAsync(write) {
|
|
19330
|
+
try {
|
|
19331
|
+
await write();
|
|
19332
|
+
} catch (error) {
|
|
19333
|
+
refusal(error);
|
|
19334
|
+
}
|
|
19335
|
+
}
|
|
18847
19336
|
function guarded(write) {
|
|
18848
19337
|
try {
|
|
18849
19338
|
return write();
|
|
@@ -18893,16 +19382,21 @@ function profileValue(name, paths) {
|
|
|
18893
19382
|
function createConfigApiRouter(deps) {
|
|
18894
19383
|
const authed = doorApiAuth(deps.expectedToken);
|
|
18895
19384
|
const { paths } = deps;
|
|
18896
|
-
const route = (
|
|
19385
|
+
const route = (path45, summary) => authed.meta((0, import_openapi3.openapi)({ method: "POST", path: path45, summary, tags: [CONFIG_API_TAG] }));
|
|
18897
19386
|
return {
|
|
18898
19387
|
config: {
|
|
18899
19388
|
identity: {
|
|
18900
|
-
add: route("/rest/config/identity/add", "Create an identity").input(
|
|
18901
|
-
(
|
|
19389
|
+
add: route("/rest/config/identity/add", "Create an identity").input(ConfigIdentityAddInputSchema).output(ConfigIdentityAddOutputSchema).handler(async ({ input }) => {
|
|
19390
|
+
await guardedAsync(async () => {
|
|
19391
|
+
await resolveWithAsyncRuns((run) => {
|
|
19392
|
+
requireIdentityAddable(paths, input.name, { run, platform: deps.keychain.platform }, input.keepKeychainLogin === true);
|
|
19393
|
+
}, deps.keychain.runAsync);
|
|
19394
|
+
});
|
|
19395
|
+
return guarded(() => {
|
|
18902
19396
|
addIdentity(paths, input.name);
|
|
18903
19397
|
return { action: "created", kind: "identity", name: input.name, value: identityValue(input.name, paths) };
|
|
18904
|
-
})
|
|
18905
|
-
),
|
|
19398
|
+
});
|
|
19399
|
+
}),
|
|
18906
19400
|
set: route("/rest/config/identity/set", "Update an identity's label, default profile, provider, ambient-credential setting, credential or anchors").input(ConfigIdentitySetInputSchema).output(ConfigIdentitySetOutputSchema).handler(
|
|
18907
19401
|
({ input }) => guarded(() => {
|
|
18908
19402
|
requireChange(input.label !== void 0 || input.defaultConfigProfile !== void 0 || input.provider !== void 0 || input.allowAmbientCredential !== void 0 || input.credential !== void 0 || input.anchors !== void 0, "label, defaultConfigProfile, provider, allowAmbientCredential, credential or anchors");
|
|
@@ -19151,43 +19645,43 @@ var import_openapi4 = require("@orpc/openapi");
|
|
|
19151
19645
|
var import_server3 = require("@orpc/server");
|
|
19152
19646
|
|
|
19153
19647
|
// src/frontdoor/eventSchemas.ts
|
|
19154
|
-
var
|
|
19648
|
+
var import_zod32 = require("zod");
|
|
19155
19649
|
var DOOR_EVENT_SOURCE_RC = "rc";
|
|
19156
19650
|
var LAUNCH_EVENT_SOURCE = "launch";
|
|
19157
19651
|
var USAGE_EVENT_SOURCE = "usage";
|
|
19158
19652
|
var DOOR_HEALTH_EVENT_SOURCE = "door";
|
|
19159
19653
|
var QUOTA_EXPIRING_EVENT_SOURCE = "quota-expiring";
|
|
19160
|
-
var DoorEventSchema =
|
|
19161
|
-
source:
|
|
19654
|
+
var DoorEventSchema = import_zod32.z.strictObject({
|
|
19655
|
+
source: import_zod32.z.string().min(1),
|
|
19162
19656
|
/** A positive integer because the backbone's counters start at one and only ever increase. */
|
|
19163
|
-
sequence:
|
|
19164
|
-
payload:
|
|
19657
|
+
sequence: import_zod32.z.number().int().positive(),
|
|
19658
|
+
payload: import_zod32.z.unknown()
|
|
19165
19659
|
});
|
|
19166
|
-
var DoorEventSourceQuerySchema =
|
|
19167
|
-
sources:
|
|
19660
|
+
var DoorEventSourceQuerySchema = import_zod32.z.strictObject({
|
|
19661
|
+
sources: import_zod32.z.array(import_zod32.z.string().min(1)).min(1).optional()
|
|
19168
19662
|
});
|
|
19169
|
-
var LaunchLifecycleEventSchema =
|
|
19170
|
-
kind:
|
|
19171
|
-
pid:
|
|
19172
|
-
startedAt:
|
|
19173
|
-
observedAt:
|
|
19663
|
+
var LaunchLifecycleEventSchema = import_zod32.z.strictObject({
|
|
19664
|
+
kind: import_zod32.z.enum(["registered", "pruned", "ended"]),
|
|
19665
|
+
pid: import_zod32.z.number().int().positive(),
|
|
19666
|
+
startedAt: import_zod32.z.number(),
|
|
19667
|
+
observedAt: import_zod32.z.number()
|
|
19174
19668
|
});
|
|
19175
|
-
var DoorHealthEventSchema =
|
|
19176
|
-
|
|
19177
|
-
|
|
19178
|
-
|
|
19179
|
-
|
|
19180
|
-
|
|
19181
|
-
|
|
19669
|
+
var DoorHealthEventSchema = import_zod32.z.discriminatedUnion("kind", [
|
|
19670
|
+
import_zod32.z.strictObject({ kind: import_zod32.z.literal("generation"), pid: import_zod32.z.number().int().positive(), providerPort: import_zod32.z.number().int().positive(), connectPort: import_zod32.z.number().int().positive(), directPort: import_zod32.z.number().int().positive(), observedAt: import_zod32.z.number() }),
|
|
19671
|
+
import_zod32.z.strictObject({ kind: import_zod32.z.literal("listenerFailed"), pid: import_zod32.z.number().int().positive(), listener: import_zod32.z.enum(["provider", "connect", "direct"]), message: import_zod32.z.string(), observedAt: import_zod32.z.number() }),
|
|
19672
|
+
import_zod32.z.strictObject({ kind: import_zod32.z.literal("binaryTurnover"), pid: import_zod32.z.number().int().positive(), observedAt: import_zod32.z.number() }),
|
|
19673
|
+
import_zod32.z.strictObject({ kind: import_zod32.z.literal("idleShutdown"), pid: import_zod32.z.number().int().positive(), observedAt: import_zod32.z.number() }),
|
|
19674
|
+
import_zod32.z.strictObject({ kind: import_zod32.z.literal("superseded"), pid: import_zod32.z.number().int().positive(), ownerPid: import_zod32.z.number().int().positive(), observedAt: import_zod32.z.number() }),
|
|
19675
|
+
import_zod32.z.strictObject({ kind: import_zod32.z.literal("drained"), pid: import_zod32.z.number().int().positive(), observedAt: import_zod32.z.number() })
|
|
19182
19676
|
]);
|
|
19183
|
-
var QuotaExpiringEventSchema =
|
|
19184
|
-
identity:
|
|
19185
|
-
provider:
|
|
19186
|
-
window:
|
|
19677
|
+
var QuotaExpiringEventSchema = import_zod32.z.strictObject({
|
|
19678
|
+
identity: import_zod32.z.string().min(1),
|
|
19679
|
+
provider: import_zod32.z.string().min(1),
|
|
19680
|
+
window: import_zod32.z.enum(["fiveHour", "sevenDay"]),
|
|
19187
19681
|
/** The fraction of the window already used when it was seen expiring, always below one because a fully used window has nothing left to spend. */
|
|
19188
|
-
utilization:
|
|
19189
|
-
resetsAt:
|
|
19190
|
-
observedAt:
|
|
19682
|
+
utilization: import_zod32.z.number().min(0).max(1),
|
|
19683
|
+
resetsAt: import_zod32.z.iso.datetime(),
|
|
19684
|
+
observedAt: import_zod32.z.number()
|
|
19191
19685
|
});
|
|
19192
19686
|
|
|
19193
19687
|
// src/frontdoor/eventsApi.ts
|
|
@@ -19270,61 +19764,61 @@ var import_openapi6 = require("@orpc/openapi");
|
|
|
19270
19764
|
init_cliError();
|
|
19271
19765
|
|
|
19272
19766
|
// src/frontdoor/launchSchemas.ts
|
|
19273
|
-
var
|
|
19274
|
-
var
|
|
19767
|
+
var import_node_path33 = __toESM(require("node:path"), 1);
|
|
19768
|
+
var import_zod33 = require("zod");
|
|
19275
19769
|
init_statusline();
|
|
19276
19770
|
init_claudeVersion();
|
|
19277
19771
|
init_identity();
|
|
19278
|
-
var LaunchResolveInputSchema =
|
|
19279
|
-
path:
|
|
19772
|
+
var LaunchResolveInputSchema = import_zod33.z.strictObject({
|
|
19773
|
+
path: import_zod33.z.string().min(1),
|
|
19280
19774
|
/** `@name`, launch flags, then the arguments for `claude`; empty for a bare launch. */
|
|
19281
|
-
argv:
|
|
19775
|
+
argv: import_zod33.z.readonly(import_zod33.z.array(import_zod33.z.string())).optional(),
|
|
19282
19776
|
/** The launch's inherited environment. Absent means an empty one: the door's own environment is never a substitute for the caller's, so a caller that wants `AGENT_SHIM_*` switches or a `CLAUDE_CONFIG_DIR` considered names them here. Values are read, never reported. */
|
|
19283
|
-
env:
|
|
19284
|
-
}).refine((input) =>
|
|
19285
|
-
var LaunchPoolDecisionSchema =
|
|
19286
|
-
name:
|
|
19287
|
-
reasons:
|
|
19288
|
-
movedOff:
|
|
19777
|
+
env: import_zod33.z.record(import_zod33.z.string(), import_zod33.z.string()).optional()
|
|
19778
|
+
}).refine((input) => import_node_path33.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
19779
|
+
var LaunchPoolDecisionSchema = import_zod33.z.strictObject({
|
|
19780
|
+
name: import_zod33.z.string(),
|
|
19781
|
+
reasons: import_zod33.z.readonly(import_zod33.z.array(import_zod33.z.string())),
|
|
19782
|
+
movedOff: import_zod33.z.strictObject({ identity: import_zod33.z.string(), reason: import_zod33.z.string() }).optional()
|
|
19289
19783
|
});
|
|
19290
|
-
var LaunchDecisionSchema =
|
|
19291
|
-
identity:
|
|
19292
|
-
identitySource:
|
|
19784
|
+
var LaunchDecisionSchema = import_zod33.z.strictObject({
|
|
19785
|
+
identity: import_zod33.z.string().optional(),
|
|
19786
|
+
identitySource: import_zod33.z.enum(IDENTITY_DECISION_SOURCES),
|
|
19293
19787
|
pool: LaunchPoolDecisionSchema.optional(),
|
|
19294
|
-
configDirEscapeHatch:
|
|
19295
|
-
configDir:
|
|
19296
|
-
configProfile:
|
|
19297
|
-
configProfileSource:
|
|
19298
|
-
provider:
|
|
19788
|
+
configDirEscapeHatch: import_zod33.z.boolean(),
|
|
19789
|
+
configDir: import_zod33.z.string().optional(),
|
|
19790
|
+
configProfile: import_zod33.z.string().optional(),
|
|
19791
|
+
configProfileSource: import_zod33.z.enum(CONFIG_PROFILE_DECISION_SOURCES),
|
|
19792
|
+
provider: import_zod33.z.string().optional()
|
|
19299
19793
|
});
|
|
19300
|
-
var LaunchFlagsSchema =
|
|
19301
|
-
skipPermissions:
|
|
19302
|
-
remoteControl:
|
|
19303
|
-
headroom:
|
|
19304
|
-
trackUsage:
|
|
19305
|
-
pause:
|
|
19306
|
-
explain:
|
|
19794
|
+
var LaunchFlagsSchema = import_zod33.z.strictObject({
|
|
19795
|
+
skipPermissions: import_zod33.z.boolean(),
|
|
19796
|
+
remoteControl: import_zod33.z.boolean(),
|
|
19797
|
+
headroom: import_zod33.z.boolean(),
|
|
19798
|
+
trackUsage: import_zod33.z.boolean(),
|
|
19799
|
+
pause: import_zod33.z.boolean(),
|
|
19800
|
+
explain: import_zod33.z.boolean(),
|
|
19307
19801
|
/** How long the launch waits after its own output before it starts claude, in milliseconds. */
|
|
19308
|
-
delayMs:
|
|
19802
|
+
delayMs: import_zod33.z.number(),
|
|
19309
19803
|
/** The hosts the launch keeps off the front door by adding them to the child's `NO_PROXY`. */
|
|
19310
|
-
proxyBypass:
|
|
19804
|
+
proxyBypass: import_zod33.z.array(import_zod33.z.string()).readonly(),
|
|
19311
19805
|
/** How the session's built-in statusline looks, when the launch configures any of it. */
|
|
19312
19806
|
statusline: StatuslineSchema.optional()
|
|
19313
19807
|
});
|
|
19314
|
-
var LaunchResolveOutputSchema =
|
|
19808
|
+
var LaunchResolveOutputSchema = import_zod33.z.strictObject({
|
|
19315
19809
|
decision: LaunchDecisionSchema,
|
|
19316
19810
|
flags: LaunchFlagsSchema,
|
|
19317
|
-
claudeVersion:
|
|
19811
|
+
claudeVersion: import_zod33.z.strictObject({ version: import_zod33.z.string(), source: import_zod33.z.enum(CLAUDE_VERSION_SOURCES) }).optional(),
|
|
19318
19812
|
/** The real `claude` binary the launch would spawn, on the door's host. */
|
|
19319
|
-
bin:
|
|
19813
|
+
bin: import_zod33.z.string(),
|
|
19320
19814
|
/** The arguments the launch would pass it: the tool's own flags, then `CLAUDE_EXTRA_FLAGS`, then the caller's own. */
|
|
19321
|
-
args:
|
|
19815
|
+
args: import_zod33.z.readonly(import_zod33.z.array(import_zod33.z.string())),
|
|
19322
19816
|
/** The credential the launch would authenticate with, by target and source kinds. Absent when none applies. */
|
|
19323
|
-
credential:
|
|
19324
|
-
routing:
|
|
19817
|
+
credential: import_zod33.z.strictObject({ subject: import_zod33.z.enum(["provider", "identity"]), name: import_zod33.z.string(), summary: CredentialSummarySchema }).optional(),
|
|
19818
|
+
routing: import_zod33.z.strictObject({ frontDoor: import_zod33.z.boolean(), headroom: import_zod33.z.boolean() }),
|
|
19325
19819
|
/** The names of the environment variables the launch would set or unset, sorted. Values are not reported. */
|
|
19326
|
-
environment:
|
|
19327
|
-
warnings:
|
|
19820
|
+
environment: import_zod33.z.readonly(import_zod33.z.array(import_zod33.z.string())),
|
|
19821
|
+
warnings: import_zod33.z.readonly(import_zod33.z.array(import_zod33.z.string()))
|
|
19328
19822
|
});
|
|
19329
19823
|
|
|
19330
19824
|
// src/frontdoor/launchApi.ts
|
|
@@ -19360,22 +19854,22 @@ function createLaunchApiRouter(deps) {
|
|
|
19360
19854
|
// src/frontdoor/agentTreesApi.ts
|
|
19361
19855
|
var import_client6 = require("@orpc/client");
|
|
19362
19856
|
var import_openapi7 = require("@orpc/openapi");
|
|
19363
|
-
var
|
|
19857
|
+
var import_zod34 = require("zod");
|
|
19364
19858
|
init_cliError();
|
|
19365
|
-
var AgentTreesListInputSchema =
|
|
19859
|
+
var AgentTreesListInputSchema = import_zod34.z.strictObject({
|
|
19366
19860
|
/** Only this identity's sessions. */
|
|
19367
|
-
identity:
|
|
19861
|
+
identity: import_zod34.z.string().optional(),
|
|
19368
19862
|
/** Include sessions that spawned no agent and ran no workflow. */
|
|
19369
|
-
all:
|
|
19863
|
+
all: import_zod34.z.boolean().optional()
|
|
19370
19864
|
});
|
|
19371
|
-
var AgentTreesListOutputSchema =
|
|
19372
|
-
var AgentTreesShowInputSchema =
|
|
19865
|
+
var AgentTreesListOutputSchema = import_zod34.z.array(SessionSummarySchema);
|
|
19866
|
+
var AgentTreesShowInputSchema = import_zod34.z.strictObject({
|
|
19373
19867
|
/** A session id, or an unambiguous prefix of one. */
|
|
19374
|
-
session:
|
|
19868
|
+
session: import_zod34.z.string().min(1),
|
|
19375
19869
|
/** Look only in this identity. */
|
|
19376
|
-
identity:
|
|
19870
|
+
identity: import_zod34.z.string().optional()
|
|
19377
19871
|
});
|
|
19378
|
-
var AgentTreesShowOutputSchema =
|
|
19872
|
+
var AgentTreesShowOutputSchema = import_zod34.z.strictObject({ identities: import_zod34.z.array(import_zod34.z.string()), ...MergedAgentTreeSchema.shape });
|
|
19379
19873
|
function asBadRequest(error) {
|
|
19380
19874
|
if (error instanceof CliError) {
|
|
19381
19875
|
throw new import_client6.ORPCError("BAD_REQUEST", { message: error.message });
|
|
@@ -21461,7 +21955,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
21461
21955
|
}
|
|
21462
21956
|
|
|
21463
21957
|
// src/frontdoor/rcSelfHostMint.ts
|
|
21464
|
-
var
|
|
21958
|
+
var import_node_path34 = __toESM(require("node:path"), 1);
|
|
21465
21959
|
init_account();
|
|
21466
21960
|
var CREDENTIALS_FILE2 = ".credentials.json";
|
|
21467
21961
|
var CLAUDE_JSON2 = ".claude.json";
|
|
@@ -21472,8 +21966,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
|
21472
21966
|
function isRecord14(value) {
|
|
21473
21967
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21474
21968
|
}
|
|
21475
|
-
function readJsonObject(
|
|
21476
|
-
const raw =
|
|
21969
|
+
function readJsonObject(fs15, file) {
|
|
21970
|
+
const raw = fs15.readFileUtf8(file);
|
|
21477
21971
|
if (raw === void 0) {
|
|
21478
21972
|
return void 0;
|
|
21479
21973
|
}
|
|
@@ -21485,8 +21979,8 @@ function readJsonObject(fs14, file) {
|
|
|
21485
21979
|
}
|
|
21486
21980
|
return isRecord14(parsed) ? parsed : void 0;
|
|
21487
21981
|
}
|
|
21488
|
-
function readRcSelfHostRecord(
|
|
21489
|
-
const parsed = readJsonObject(
|
|
21982
|
+
function readRcSelfHostRecord(fs15, frontdoorDir) {
|
|
21983
|
+
const parsed = readJsonObject(fs15, import_node_path34.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
21490
21984
|
if (parsed === void 0) {
|
|
21491
21985
|
return void 0;
|
|
21492
21986
|
}
|
|
@@ -21500,11 +21994,11 @@ function mintRcSelfHostCredential(deps) {
|
|
|
21500
21994
|
if (!isIdentityName(deps.identity)) {
|
|
21501
21995
|
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
21502
21996
|
}
|
|
21503
|
-
const identityDir =
|
|
21504
|
-
const credentialsFile =
|
|
21505
|
-
const claudeJsonFile =
|
|
21506
|
-
const recordDir =
|
|
21507
|
-
const
|
|
21997
|
+
const identityDir = import_node_path34.default.join(deps.identitiesDir, deps.identity);
|
|
21998
|
+
const credentialsFile = import_node_path34.default.join(identityDir, CREDENTIALS_FILE2);
|
|
21999
|
+
const claudeJsonFile = import_node_path34.default.join(identityDir, CLAUDE_JSON2);
|
|
22000
|
+
const recordDir = import_node_path34.default.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
22001
|
+
const recordFile2 = import_node_path34.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
21508
22002
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
21509
22003
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
21510
22004
|
const existingOauth = isRecord14(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
@@ -21520,7 +22014,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
21520
22014
|
const organizationUuid = deps.newUuid();
|
|
21521
22015
|
const accountUuid = deps.newUuid();
|
|
21522
22016
|
const mintedAt = new Date(deps.now()).toISOString();
|
|
21523
|
-
deps.fs.mkdirPrivate(
|
|
22017
|
+
deps.fs.mkdirPrivate(import_node_path34.default.dirname(credentialsFile));
|
|
21524
22018
|
deps.fs.writeFilePrivate(credentialsFile, `${JSON.stringify({ ...existingCredentials, claudeAiOauth: { accessToken, refreshToken, expiresAt: null, scopes: [...RC_SELF_HOST_SCOPE_LIST], subscriptionType: SELF_HOST_SUBSCRIPTION_TYPE, rateLimitTier: null } }, null, 2)}
|
|
21525
22019
|
`);
|
|
21526
22020
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
@@ -21547,36 +22041,36 @@ function mintRcSelfHostCredential(deps) {
|
|
|
21547
22041
|
}, null, 2)}
|
|
21548
22042
|
`);
|
|
21549
22043
|
deps.fs.mkdirPrivate(recordDir);
|
|
21550
|
-
deps.fs.writeFilePrivate(
|
|
22044
|
+
deps.fs.writeFilePrivate(recordFile2, `${JSON.stringify({ accessToken, refreshToken, organizationUuid, accountUuid }, null, 2)}
|
|
21551
22045
|
`);
|
|
21552
|
-
return { identity: deps.identity, organizationUuid, credentialsFile, claudeJsonFile, recordFile, replaced: existingIsOwn };
|
|
22046
|
+
return { identity: deps.identity, organizationUuid, credentialsFile, claudeJsonFile, recordFile: recordFile2, replaced: existingIsOwn };
|
|
21553
22047
|
}
|
|
21554
22048
|
|
|
21555
22049
|
// src/index.ts
|
|
21556
22050
|
init_ensure2();
|
|
21557
22051
|
|
|
21558
22052
|
// src/frontdoor/liveSessionRegistry.ts
|
|
21559
|
-
var
|
|
22053
|
+
var import_node_path35 = __toESM(require("node:path"), 1);
|
|
21560
22054
|
init_capability();
|
|
21561
22055
|
init_state();
|
|
21562
22056
|
function sameStat(recorded, current) {
|
|
21563
22057
|
return recorded?.mtimeMs === current.mtimeMs && recorded.sizeBytes === current.sizeBytes;
|
|
21564
22058
|
}
|
|
21565
22059
|
function createLiveSessionRegistry(ports) {
|
|
21566
|
-
const { fs:
|
|
22060
|
+
const { fs: fs15, sessionsDir } = ports;
|
|
21567
22061
|
const known = /* @__PURE__ */ new Map();
|
|
21568
22062
|
let tokens = /* @__PURE__ */ new Set();
|
|
21569
22063
|
let bySessionId = /* @__PURE__ */ new Map();
|
|
21570
|
-
const recordNames = () =>
|
|
22064
|
+
const recordNames = () => fs15.readdir(sessionsDir).filter(isSessionRecordName);
|
|
21571
22065
|
const rebuildIndexes = () => {
|
|
21572
22066
|
const records = [...known.values()].flatMap(({ record }) => record === void 0 ? [] : [record]);
|
|
21573
22067
|
tokens = new Set(records.map((record) => record.token));
|
|
21574
22068
|
bySessionId = new Map(records.flatMap((record) => record.sessionId === void 0 ? [] : [[record.sessionId, record]]));
|
|
21575
22069
|
};
|
|
21576
22070
|
const load = (name, stat) => {
|
|
21577
|
-
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(
|
|
22071
|
+
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(fs15, sessionsDir, name) });
|
|
21578
22072
|
};
|
|
21579
|
-
const statOf = (name) =>
|
|
22073
|
+
const statOf = (name) => fs15.lstat(import_node_path35.default.join(sessionsDir, name));
|
|
21580
22074
|
const reconcile = () => {
|
|
21581
22075
|
const names = new Set(recordNames());
|
|
21582
22076
|
let changed = false;
|
|
@@ -21643,8 +22137,8 @@ init_plan2();
|
|
|
21643
22137
|
init_poolPick();
|
|
21644
22138
|
|
|
21645
22139
|
// src/agents/read.ts
|
|
21646
|
-
var
|
|
21647
|
-
var
|
|
22140
|
+
var import_node_path36 = __toESM(require("node:path"), 1);
|
|
22141
|
+
var import_zod35 = require("zod");
|
|
21648
22142
|
var PROJECTS_DIR = "projects";
|
|
21649
22143
|
var TASKS_DIR = "tasks";
|
|
21650
22144
|
var SUBAGENTS_DIR = "subagents";
|
|
@@ -21667,17 +22161,17 @@ function parseEntry2(project, entry) {
|
|
|
21667
22161
|
const base = match?.[1];
|
|
21668
22162
|
return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
|
|
21669
22163
|
}
|
|
21670
|
-
function listSessions2(
|
|
22164
|
+
function listSessions2(fs15, configDir) {
|
|
21671
22165
|
const found = [];
|
|
21672
|
-
for (const project of
|
|
21673
|
-
const projectDir =
|
|
22166
|
+
for (const project of fs15.readdir(import_node_path36.default.join(configDir, PROJECTS_DIR))) {
|
|
22167
|
+
const projectDir = import_node_path36.default.join(configDir, PROJECTS_DIR, project);
|
|
21674
22168
|
const entries = /* @__PURE__ */ new Set();
|
|
21675
|
-
for (const name of
|
|
22169
|
+
for (const name of fs15.readdir(projectDir)) {
|
|
21676
22170
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
21677
22171
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
21678
22172
|
continue;
|
|
21679
22173
|
}
|
|
21680
|
-
const children =
|
|
22174
|
+
const children = fs15.readdir(import_node_path36.default.join(projectDir, name));
|
|
21681
22175
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
21682
22176
|
entries.add(name);
|
|
21683
22177
|
}
|
|
@@ -21688,17 +22182,17 @@ function listSessions2(fs14, configDir) {
|
|
|
21688
22182
|
}
|
|
21689
22183
|
return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
|
|
21690
22184
|
}
|
|
21691
|
-
function locateAgents(
|
|
22185
|
+
function locateAgents(fs15, configDir, relativeDir, workflowRunId, report) {
|
|
21692
22186
|
const located = [];
|
|
21693
|
-
for (const name of listDirOrReport(
|
|
22187
|
+
for (const name of listDirOrReport(fs15, configDir, relativeDir, report)) {
|
|
21694
22188
|
if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
|
|
21695
22189
|
continue;
|
|
21696
22190
|
}
|
|
21697
22191
|
const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
|
|
21698
22192
|
located.push({
|
|
21699
22193
|
id,
|
|
21700
|
-
metaPath:
|
|
21701
|
-
transcriptPath:
|
|
22194
|
+
metaPath: import_node_path36.default.join(relativeDir, name),
|
|
22195
|
+
transcriptPath: import_node_path36.default.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
|
|
21702
22196
|
workflowRunId
|
|
21703
22197
|
});
|
|
21704
22198
|
}
|
|
@@ -21739,17 +22233,17 @@ function toNode(read, children) {
|
|
|
21739
22233
|
function describeFailure(error) {
|
|
21740
22234
|
return error instanceof Error ? error.message : String(error);
|
|
21741
22235
|
}
|
|
21742
|
-
function readFileOrReport(
|
|
22236
|
+
function readFileOrReport(fs15, configDir, relative, report) {
|
|
21743
22237
|
try {
|
|
21744
|
-
return
|
|
22238
|
+
return fs15.readFileUtf8(import_node_path36.default.join(configDir, relative));
|
|
21745
22239
|
} catch (error) {
|
|
21746
22240
|
report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
|
|
21747
22241
|
return void 0;
|
|
21748
22242
|
}
|
|
21749
22243
|
}
|
|
21750
|
-
function listDirOrReport(
|
|
22244
|
+
function listDirOrReport(fs15, configDir, relative, report) {
|
|
21751
22245
|
try {
|
|
21752
|
-
return
|
|
22246
|
+
return fs15.readdir(import_node_path36.default.join(configDir, relative));
|
|
21753
22247
|
} catch (error) {
|
|
21754
22248
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
|
|
21755
22249
|
return [];
|
|
@@ -21763,47 +22257,47 @@ function parseJson2(text) {
|
|
|
21763
22257
|
return void 0;
|
|
21764
22258
|
}
|
|
21765
22259
|
}
|
|
21766
|
-
var TaskFileSchema =
|
|
21767
|
-
var WorkflowRunFileSchema =
|
|
21768
|
-
runId:
|
|
21769
|
-
workflowName:
|
|
21770
|
-
status:
|
|
21771
|
-
startTime:
|
|
21772
|
-
phases:
|
|
21773
|
-
summary:
|
|
22260
|
+
var TaskFileSchema = import_zod35.z.object({ ...TaskItemSchema.omit({ taskList: true }).shape, blocks: import_zod35.z.array(import_zod35.z.string()).default([]), blockedBy: import_zod35.z.array(import_zod35.z.string()).default([]) });
|
|
22261
|
+
var WorkflowRunFileSchema = import_zod35.z.object({
|
|
22262
|
+
runId: import_zod35.z.string(),
|
|
22263
|
+
workflowName: import_zod35.z.string().optional(),
|
|
22264
|
+
status: import_zod35.z.string().optional(),
|
|
22265
|
+
startTime: import_zod35.z.number().optional(),
|
|
22266
|
+
phases: import_zod35.z.array(import_zod35.z.object({ title: import_zod35.z.string() })).default([]),
|
|
22267
|
+
summary: import_zod35.z.string().optional()
|
|
21774
22268
|
});
|
|
21775
|
-
function summariseSession(
|
|
21776
|
-
const sessionRelative =
|
|
21777
|
-
const subagentsRelative =
|
|
21778
|
-
const workflowsUnderSubagents =
|
|
22269
|
+
function summariseSession(fs15, configDir, ref) {
|
|
22270
|
+
const sessionRelative = import_node_path36.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22271
|
+
const subagentsRelative = import_node_path36.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
22272
|
+
const workflowsUnderSubagents = import_node_path36.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
21779
22273
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
21780
|
-
let agentCount =
|
|
21781
|
-
for (const runDir of
|
|
22274
|
+
let agentCount = fs15.readdir(import_node_path36.default.join(configDir, subagentsRelative)).filter(isMeta).length;
|
|
22275
|
+
for (const runDir of fs15.readdir(import_node_path36.default.join(configDir, workflowsUnderSubagents))) {
|
|
21782
22276
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
21783
|
-
agentCount +=
|
|
22277
|
+
agentCount += fs15.readdir(import_node_path36.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
21784
22278
|
}
|
|
21785
22279
|
}
|
|
21786
|
-
const workflowRunCount =
|
|
21787
|
-
const transcript =
|
|
22280
|
+
const workflowRunCount = fs15.readdir(import_node_path36.default.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
|
|
22281
|
+
const transcript = fs15.lstat(import_node_path36.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
|
|
21788
22282
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
21789
22283
|
}
|
|
21790
|
-
function readSessionAgentTree(
|
|
22284
|
+
function readSessionAgentTree(fs15, configDir, ref, options = {}) {
|
|
21791
22285
|
const problems = [];
|
|
21792
22286
|
const report = (problem) => {
|
|
21793
22287
|
problems.push(problem);
|
|
21794
22288
|
};
|
|
21795
|
-
const sessionRelative =
|
|
21796
|
-
const subagentsRelative =
|
|
21797
|
-
const workflowsUnderSubagents =
|
|
21798
|
-
const located = locateAgents(
|
|
21799
|
-
for (const runDir of listDirOrReport(
|
|
22289
|
+
const sessionRelative = import_node_path36.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22290
|
+
const subagentsRelative = import_node_path36.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
22291
|
+
const workflowsUnderSubagents = import_node_path36.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
22292
|
+
const located = locateAgents(fs15, configDir, subagentsRelative, void 0, report);
|
|
22293
|
+
for (const runDir of listDirOrReport(fs15, configDir, workflowsUnderSubagents, report)) {
|
|
21800
22294
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
21801
|
-
located.push(...locateAgents(
|
|
22295
|
+
located.push(...locateAgents(fs15, configDir, import_node_path36.default.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
21802
22296
|
}
|
|
21803
22297
|
}
|
|
21804
22298
|
const agents = /* @__PURE__ */ new Map();
|
|
21805
22299
|
for (const candidate of located) {
|
|
21806
|
-
const text = readFileOrReport(
|
|
22300
|
+
const text = readFileOrReport(fs15, configDir, candidate.metaPath, report);
|
|
21807
22301
|
if (text === void 0) {
|
|
21808
22302
|
continue;
|
|
21809
22303
|
}
|
|
@@ -21815,7 +22309,7 @@ function readSessionAgentTree(fs14, configDir, ref, options = {}) {
|
|
|
21815
22309
|
agents.set(candidate.id, { located: candidate, meta: parsed.data });
|
|
21816
22310
|
}
|
|
21817
22311
|
const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
|
|
21818
|
-
const parentOf3 = resolveParents(
|
|
22312
|
+
const parentOf3 = resolveParents(fs15, configDir, agents, report);
|
|
21819
22313
|
const childrenOf = /* @__PURE__ */ new Map();
|
|
21820
22314
|
const roots = [];
|
|
21821
22315
|
for (const id of agents.keys()) {
|
|
@@ -21838,12 +22332,12 @@ function readSessionAgentTree(fs14, configDir, ref, options = {}) {
|
|
|
21838
22332
|
sessionId: ref.sessionId,
|
|
21839
22333
|
superseded: ref.superseded,
|
|
21840
22334
|
agents: roots.sort().map(build),
|
|
21841
|
-
tasks: readTasks(
|
|
21842
|
-
workflowRuns: readWorkflowRuns(
|
|
22335
|
+
tasks: readTasks(fs15, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
|
|
22336
|
+
workflowRuns: readWorkflowRuns(fs15, configDir, import_node_path36.default.join(sessionRelative, WORKFLOWS_DIR), report),
|
|
21843
22337
|
problems
|
|
21844
22338
|
};
|
|
21845
22339
|
}
|
|
21846
|
-
function resolveParents(
|
|
22340
|
+
function resolveParents(fs15, configDir, agents, report) {
|
|
21847
22341
|
const parentOf3 = /* @__PURE__ */ new Map();
|
|
21848
22342
|
const transcriptCache = /* @__PURE__ */ new Map();
|
|
21849
22343
|
const transcriptOf = (agent) => {
|
|
@@ -21851,7 +22345,7 @@ function resolveParents(fs14, configDir, agents, report) {
|
|
|
21851
22345
|
if (cached !== void 0) {
|
|
21852
22346
|
return cached;
|
|
21853
22347
|
}
|
|
21854
|
-
const text = readFileOrReport(
|
|
22348
|
+
const text = readFileOrReport(fs15, configDir, agent.located.transcriptPath, report) ?? "";
|
|
21855
22349
|
transcriptCache.set(agent.located.id, text);
|
|
21856
22350
|
return text;
|
|
21857
22351
|
};
|
|
@@ -21901,16 +22395,16 @@ function resolveParents(fs14, configDir, agents, report) {
|
|
|
21901
22395
|
function ownTaskLists(sessionId) {
|
|
21902
22396
|
return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
|
|
21903
22397
|
}
|
|
21904
|
-
function readTasks(
|
|
22398
|
+
function readTasks(fs15, configDir, ownLists, sharedLists, report) {
|
|
21905
22399
|
const tasks = [];
|
|
21906
22400
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
21907
|
-
const relativeDir =
|
|
21908
|
-
for (const name of [...listDirOrReport(
|
|
22401
|
+
const relativeDir = import_node_path36.default.join(TASKS_DIR, scope);
|
|
22402
|
+
for (const name of [...listDirOrReport(fs15, configDir, relativeDir, report)].sort()) {
|
|
21909
22403
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
21910
22404
|
continue;
|
|
21911
22405
|
}
|
|
21912
|
-
const relative =
|
|
21913
|
-
const text = readFileOrReport(
|
|
22406
|
+
const relative = import_node_path36.default.join(relativeDir, name);
|
|
22407
|
+
const text = readFileOrReport(fs15, configDir, relative, report);
|
|
21914
22408
|
const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
21915
22409
|
if (parsed.success) {
|
|
21916
22410
|
tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
|
|
@@ -21921,14 +22415,14 @@ function readTasks(fs14, configDir, ownLists, sharedLists, report) {
|
|
|
21921
22415
|
});
|
|
21922
22416
|
return tasks;
|
|
21923
22417
|
}
|
|
21924
|
-
function readWorkflowRuns(
|
|
22418
|
+
function readWorkflowRuns(fs15, configDir, relativeDir, report) {
|
|
21925
22419
|
const runs = [];
|
|
21926
|
-
for (const name of [...listDirOrReport(
|
|
22420
|
+
for (const name of [...listDirOrReport(fs15, configDir, relativeDir, report)].sort()) {
|
|
21927
22421
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
21928
22422
|
continue;
|
|
21929
22423
|
}
|
|
21930
|
-
const relative =
|
|
21931
|
-
const text = readFileOrReport(
|
|
22424
|
+
const relative = import_node_path36.default.join(relativeDir, name);
|
|
22425
|
+
const text = readFileOrReport(fs15, configDir, relative, report);
|
|
21932
22426
|
const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
21933
22427
|
if (!parsed.success) {
|
|
21934
22428
|
if (text !== void 0) {
|
|
@@ -21943,7 +22437,7 @@ function readWorkflowRuns(fs14, configDir, relativeDir, report) {
|
|
|
21943
22437
|
}
|
|
21944
22438
|
|
|
21945
22439
|
// src/agents/sessions.ts
|
|
21946
|
-
var
|
|
22440
|
+
var import_node_path37 = __toESM(require("node:path"), 1);
|
|
21947
22441
|
init_cliError();
|
|
21948
22442
|
var SessionLookupError = class extends CliError {
|
|
21949
22443
|
constructor(message) {
|
|
@@ -21952,13 +22446,13 @@ var SessionLookupError = class extends CliError {
|
|
|
21952
22446
|
}
|
|
21953
22447
|
};
|
|
21954
22448
|
function identityConfigDir(identitiesDir, identity) {
|
|
21955
|
-
return
|
|
22449
|
+
return import_node_path37.default.join(identitiesDir, identity);
|
|
21956
22450
|
}
|
|
21957
|
-
function historyStores(
|
|
22451
|
+
function historyStores(fs15, identitiesDir, identities) {
|
|
21958
22452
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
21959
22453
|
for (const identity of identities) {
|
|
21960
22454
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
21961
|
-
const real =
|
|
22455
|
+
const real = fs15.realpath(import_node_path37.default.join(configDir, "projects"));
|
|
21962
22456
|
if (real === void 0) {
|
|
21963
22457
|
continue;
|
|
21964
22458
|
}
|
|
@@ -21971,15 +22465,15 @@ function historyStores(fs14, identitiesDir, identities) {
|
|
|
21971
22465
|
}
|
|
21972
22466
|
return [...byRealPath.values()];
|
|
21973
22467
|
}
|
|
21974
|
-
function collectSessionList(
|
|
22468
|
+
function collectSessionList(fs15, identitiesDir, identities, filters) {
|
|
21975
22469
|
const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
|
|
21976
22470
|
if (filters.identity !== void 0 && names.length === 0) {
|
|
21977
22471
|
throw new SessionLookupError(`no identity named "${filters.identity}"`);
|
|
21978
22472
|
}
|
|
21979
22473
|
const sessions = [];
|
|
21980
|
-
for (const store of historyStores(
|
|
21981
|
-
for (const ref of listSessions2(
|
|
21982
|
-
const summary = summariseSession(
|
|
22474
|
+
for (const store of historyStores(fs15, identitiesDir, names)) {
|
|
22475
|
+
for (const ref of listSessions2(fs15, store.configDir)) {
|
|
22476
|
+
const summary = summariseSession(fs15, store.configDir, ref);
|
|
21983
22477
|
if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
|
|
21984
22478
|
sessions.push({ ...summary, identities: store.identities });
|
|
21985
22479
|
}
|
|
@@ -21987,14 +22481,14 @@ function collectSessionList(fs14, identitiesDir, identities, filters) {
|
|
|
21987
22481
|
}
|
|
21988
22482
|
return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
|
|
21989
22483
|
}
|
|
21990
|
-
function locateSession(
|
|
22484
|
+
function locateSession(fs15, identitiesDir, identities, query, onlyIdentity) {
|
|
21991
22485
|
const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
|
|
21992
22486
|
if (onlyIdentity !== void 0 && names.length === 0) {
|
|
21993
22487
|
throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
|
|
21994
22488
|
}
|
|
21995
22489
|
const matches = [];
|
|
21996
|
-
for (const store of historyStores(
|
|
21997
|
-
for (const ref of listSessions2(
|
|
22490
|
+
for (const store of historyStores(fs15, identitiesDir, names)) {
|
|
22491
|
+
for (const ref of listSessions2(fs15, store.configDir)) {
|
|
21998
22492
|
if (ref.sessionId.startsWith(query)) {
|
|
21999
22493
|
matches.push({ identities: store.identities, configDir: store.configDir, ref });
|
|
22000
22494
|
}
|
|
@@ -22011,19 +22505,19 @@ function locateSession(fs14, identitiesDir, identities, query, onlyIdentity) {
|
|
|
22011
22505
|
}
|
|
22012
22506
|
throw new SessionLookupError(`"${query}" matches ${String(candidates.length)} sessions: ${candidates.map((match) => `${match.ref.sessionId} (${match.identities.join(", ")})`).join("; ")}; give more of the id or pass --identity`);
|
|
22013
22507
|
}
|
|
22014
|
-
function showSession(
|
|
22015
|
-
const located = locateSession(
|
|
22016
|
-
return { identities: located.identities, tree: readSessionAgentTree(
|
|
22508
|
+
function showSession(fs15, identitiesDir, identities, query, onlyIdentity) {
|
|
22509
|
+
const located = locateSession(fs15, identitiesDir, identities, query, onlyIdentity);
|
|
22510
|
+
return { identities: located.identities, tree: readSessionAgentTree(fs15, located.configDir, located.ref) };
|
|
22017
22511
|
}
|
|
22018
22512
|
|
|
22019
22513
|
// src/agents/realFs.ts
|
|
22020
|
-
var
|
|
22514
|
+
var import_node_fs12 = __toESM(require("node:fs"), 1);
|
|
22021
22515
|
init_realPorts();
|
|
22022
22516
|
var realSessionFs = {
|
|
22023
22517
|
...realFarmFs,
|
|
22024
22518
|
realpath: (candidate) => {
|
|
22025
22519
|
try {
|
|
22026
|
-
return
|
|
22520
|
+
return import_node_fs12.default.realpathSync(candidate);
|
|
22027
22521
|
} catch {
|
|
22028
22522
|
return void 0;
|
|
22029
22523
|
}
|
|
@@ -22169,6 +22663,7 @@ init_ownCli();
|
|
|
22169
22663
|
CodexRateLimitsReadSchema,
|
|
22170
22664
|
CodexSignInSchema,
|
|
22171
22665
|
CodexStatusOutputSchema,
|
|
22666
|
+
ConfigIdentityAddInputSchema,
|
|
22172
22667
|
ConfigIdentityAddOutputSchema,
|
|
22173
22668
|
ConfigIdentityRemoveInputSchema,
|
|
22174
22669
|
ConfigIdentityRemoveOutputSchema,
|