agent-shim 11.84.0 → 11.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1050 -1010
- package/dist/index.cjs +506 -466
- package/dist/index.mjs +494 -454
- package/dist/types/index.d.ts +48 -28
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1043,6 +1043,8 @@ var init_schema = __esm({
|
|
|
1043
1043
|
thinking: z3.boolean().optional()
|
|
1044
1044
|
});
|
|
1045
1045
|
ModelsConfigSchema = z3.strictObject({
|
|
1046
|
+
/** Whether picker labels put spaces around the provider/model slash. */
|
|
1047
|
+
pickerLabelSpaces: z3.boolean().optional(),
|
|
1046
1048
|
/** Virtual models, by name. */
|
|
1047
1049
|
virtual: z3.record(z3.string().min(1), VirtualModelSchema).optional(),
|
|
1048
1050
|
/** Which model ref each Claude tier (`fable`, `opus`, `sonnet`, `haiku`) points at: a concrete target, an account model, a virtual model, or a family. */
|
|
@@ -1066,6 +1068,7 @@ var init_schema = __esm({
|
|
|
1066
1068
|
families: z3.record(z3.string().min(1), FamilySettingsSchema).optional()
|
|
1067
1069
|
});
|
|
1068
1070
|
ModelsLayerSchema = z3.strictObject({
|
|
1071
|
+
pickerLabelSpaces: z3.boolean().optional(),
|
|
1069
1072
|
virtual: z3.record(z3.string().min(1), z3.union([VirtualModelSchema, z3.null()])).optional(),
|
|
1070
1073
|
tiers: z3.strictObject({
|
|
1071
1074
|
fable: z3.union([z3.string().min(1), z3.null()]).optional(),
|
|
@@ -1278,7 +1281,7 @@ function parseIgnoringUnrecognisedKeys(schema, raw) {
|
|
|
1278
1281
|
return second.success ? { success: true, data: second.data, ignored } : { success: false, issues: second.error.issues };
|
|
1279
1282
|
}
|
|
1280
1283
|
function describeIgnoredKeys(filePath, ignored) {
|
|
1281
|
-
const places = ignored.map(({ path:
|
|
1284
|
+
const places = ignored.map(({ path: path49, keys }) => `${path49.length === 0 ? "" : `${path49.map(String).join(".")}.`}${keys.join(", ")}`);
|
|
1282
1285
|
return `${filePath} has settings this version of agent-shim does not know and ignores: ${places.join("; ")}. A newer release may read them.`;
|
|
1283
1286
|
}
|
|
1284
1287
|
function noteIgnoredKeys(filePath, ignored) {
|
|
@@ -1300,9 +1303,9 @@ function restoreIgnoredKeys(filePath, value) {
|
|
|
1300
1303
|
return value;
|
|
1301
1304
|
}
|
|
1302
1305
|
const restored = structuredClone(value);
|
|
1303
|
-
for (const { path:
|
|
1306
|
+
for (const { path: path49, values } of ignored) {
|
|
1304
1307
|
let holder = restored;
|
|
1305
|
-
for (const step of
|
|
1308
|
+
for (const step of path49) {
|
|
1306
1309
|
holder = isRecord(holder) ? holder[step] : void 0;
|
|
1307
1310
|
}
|
|
1308
1311
|
if (isRecord(holder)) {
|
|
@@ -2160,6 +2163,7 @@ function matchingRules(flattened, relPath) {
|
|
|
2160
2163
|
}
|
|
2161
2164
|
function mergeModels(current, layer) {
|
|
2162
2165
|
const pieces = { ...current ?? {} };
|
|
2166
|
+
if (layer.pickerLabelSpaces !== void 0) pieces.pickerLabelSpaces = layer.pickerLabelSpaces;
|
|
2163
2167
|
if (layer.virtual !== void 0) {
|
|
2164
2168
|
const virtual = {};
|
|
2165
2169
|
for (const [name, definition] of Object.entries(current?.virtual ?? {})) {
|
|
@@ -2232,6 +2236,7 @@ function mergeModels(current, layer) {
|
|
|
2232
2236
|
}
|
|
2233
2237
|
function modelsOf(pieces) {
|
|
2234
2238
|
return {
|
|
2239
|
+
...pieces.pickerLabelSpaces === void 0 ? {} : { pickerLabelSpaces: pieces.pickerLabelSpaces },
|
|
2235
2240
|
...pieces.virtual === void 0 || Object.keys(pieces.virtual).length === 0 ? {} : { virtual: pieces.virtual },
|
|
2236
2241
|
...pieces.tiers === void 0 || Object.keys(pieces.tiers).length === 0 ? {} : { tiers: pieces.tiers },
|
|
2237
2242
|
...pieces.prices === void 0 || Object.keys(pieces.prices).length === 0 ? {} : { prices: pieces.prices },
|
|
@@ -3022,8 +3027,8 @@ var init_lock = __esm({
|
|
|
3022
3027
|
// src/launcher/farm.ts
|
|
3023
3028
|
import path8 from "node:path";
|
|
3024
3029
|
import { z as z4 } from "zod";
|
|
3025
|
-
function readFarmManifest(
|
|
3026
|
-
const raw =
|
|
3030
|
+
function readFarmManifest(fs16, farmRoot) {
|
|
3031
|
+
const raw = fs16.readFileUtf8(path8.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs16.readFileUtf8(path8.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
|
|
3027
3032
|
if (raw === void 0) {
|
|
3028
3033
|
return void 0;
|
|
3029
3034
|
}
|
|
@@ -3081,9 +3086,9 @@ function buildEntryFacts(params) {
|
|
|
3081
3086
|
entries
|
|
3082
3087
|
};
|
|
3083
3088
|
}
|
|
3084
|
-
function listSubtree(
|
|
3089
|
+
function listSubtree(fs16, root, rel) {
|
|
3085
3090
|
const absolute = path8.join(root, rel);
|
|
3086
|
-
const stat =
|
|
3091
|
+
const stat = fs16.lstat(absolute);
|
|
3087
3092
|
if (stat === void 0) {
|
|
3088
3093
|
return [];
|
|
3089
3094
|
}
|
|
@@ -3091,10 +3096,10 @@ function listSubtree(fs15, root, rel) {
|
|
|
3091
3096
|
return [{ rel, kind: "symlink" }];
|
|
3092
3097
|
}
|
|
3093
3098
|
if (stat.kind === "dir") {
|
|
3094
|
-
const children = [...
|
|
3099
|
+
const children = [...fs16.readdir(absolute)].sort().flatMap((name) => listSubtree(fs16, root, `${rel}/${name}`));
|
|
3095
3100
|
return [{ rel, kind: "dir" }, ...children];
|
|
3096
3101
|
}
|
|
3097
|
-
const contentHash =
|
|
3102
|
+
const contentHash = fs16.hashFile(absolute);
|
|
3098
3103
|
return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
|
|
3099
3104
|
}
|
|
3100
3105
|
function topLevelScopeRoots(roots) {
|
|
@@ -3108,25 +3113,25 @@ function topLevelScopeRoots(roots) {
|
|
|
3108
3113
|
}
|
|
3109
3114
|
return kept;
|
|
3110
3115
|
}
|
|
3111
|
-
function reconciliationScope(
|
|
3116
|
+
function reconciliationScope(fs16, farmRoot, manifest) {
|
|
3112
3117
|
if (manifest !== void 0) {
|
|
3113
3118
|
return topLevelScopeRoots(manifest.materialised);
|
|
3114
3119
|
}
|
|
3115
|
-
return [...
|
|
3120
|
+
return [...fs16.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs16.lstat(path8.join(farmRoot, name))?.kind === "dir").sort();
|
|
3116
3121
|
}
|
|
3117
|
-
function collectFarmListing(
|
|
3118
|
-
return scopeRoots.flatMap((root) => listSubtree(
|
|
3122
|
+
function collectFarmListing(fs16, farmRoot, scopeRoots) {
|
|
3123
|
+
return scopeRoots.flatMap((root) => listSubtree(fs16, farmRoot, root));
|
|
3119
3124
|
}
|
|
3120
|
-
function collectCanonicalCounterparts(
|
|
3125
|
+
function collectCanonicalCounterparts(fs16, claudeHome, farmListing) {
|
|
3121
3126
|
const out = [];
|
|
3122
3127
|
for (const entry of farmListing) {
|
|
3123
3128
|
const absolute = path8.join(claudeHome, entry.rel);
|
|
3124
|
-
const stat =
|
|
3129
|
+
const stat = fs16.lstat(absolute);
|
|
3125
3130
|
if (stat === void 0) {
|
|
3126
3131
|
continue;
|
|
3127
3132
|
}
|
|
3128
3133
|
if (stat.kind === "file") {
|
|
3129
|
-
const contentHash =
|
|
3134
|
+
const contentHash = fs16.hashFile(absolute);
|
|
3130
3135
|
out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
|
|
3131
3136
|
continue;
|
|
3132
3137
|
}
|
|
@@ -3964,9 +3969,9 @@ var init_providerCatalogue = __esm({
|
|
|
3964
3969
|
// src/frontdoor/state.ts
|
|
3965
3970
|
import path10 from "node:path";
|
|
3966
3971
|
import { z as z6 } from "zod";
|
|
3967
|
-
function readCatalogueStatus(
|
|
3972
|
+
function readCatalogueStatus(fs16, paths, pid, generation, name) {
|
|
3968
3973
|
const file = path10.join(path10.dirname(catalogueCachePath(paths, name, pid, generation)), `${name}.status.json`);
|
|
3969
|
-
const raw =
|
|
3974
|
+
const raw = fs16.readFileUtf8(file);
|
|
3970
3975
|
if (raw === void 0) return void 0;
|
|
3971
3976
|
try {
|
|
3972
3977
|
const value = z6.strictObject({ status: z6.enum(["running", "ready", "failed"]), fingerprint: z6.string().min(1).optional(), recordedAt: z6.number().optional() }).safeParse(JSON.parse(raw));
|
|
@@ -3975,14 +3980,14 @@ function readCatalogueStatus(fs15, paths, pid, generation, name) {
|
|
|
3975
3980
|
return void 0;
|
|
3976
3981
|
}
|
|
3977
3982
|
}
|
|
3978
|
-
function writeFrontDoorCodexHome(
|
|
3983
|
+
function writeFrontDoorCodexHome(fs16, frontdoorDir, pid, codexHome, generation) {
|
|
3979
3984
|
const directory = path10.join(frontdoorDir, "codex-homes");
|
|
3980
|
-
|
|
3981
|
-
|
|
3985
|
+
fs16.mkdirp(directory);
|
|
3986
|
+
fs16.writeFilePrivate(path10.join(directory, `${String(pid)}.json`), `${JSON.stringify({ codexHome, generation })}
|
|
3982
3987
|
`);
|
|
3983
3988
|
}
|
|
3984
|
-
function readFrontDoorCodexRecord(
|
|
3985
|
-
const raw =
|
|
3989
|
+
function readFrontDoorCodexRecord(fs16, frontdoorDir, pid) {
|
|
3990
|
+
const raw = fs16.readFileUtf8(path10.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
3986
3991
|
if (raw === void 0) return void 0;
|
|
3987
3992
|
try {
|
|
3988
3993
|
const parsed = z6.strictObject({ codexHome: z6.string().min(1), generation: z6.uuid() }).safeParse(JSON.parse(raw));
|
|
@@ -3991,13 +3996,13 @@ function readFrontDoorCodexRecord(fs15, frontdoorDir, pid) {
|
|
|
3991
3996
|
return void 0;
|
|
3992
3997
|
}
|
|
3993
3998
|
}
|
|
3994
|
-
function removeFrontDoorCodexHome(
|
|
3995
|
-
|
|
3999
|
+
function removeFrontDoorCodexHome(fs16, frontdoorDir, pid) {
|
|
4000
|
+
fs16.removeRecursive(path10.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
3996
4001
|
}
|
|
3997
|
-
function readFrontDoorState(
|
|
4002
|
+
function readFrontDoorState(fs16, stateFile) {
|
|
3998
4003
|
let raw;
|
|
3999
4004
|
try {
|
|
4000
|
-
raw =
|
|
4005
|
+
raw = fs16.readFileUtf8(stateFile);
|
|
4001
4006
|
} catch {
|
|
4002
4007
|
return void 0;
|
|
4003
4008
|
}
|
|
@@ -4011,9 +4016,9 @@ function readFrontDoorState(fs15, stateFile) {
|
|
|
4011
4016
|
return void 0;
|
|
4012
4017
|
}
|
|
4013
4018
|
}
|
|
4014
|
-
function writeFrontDoorState(
|
|
4015
|
-
|
|
4016
|
-
|
|
4019
|
+
function writeFrontDoorState(fs16, stateFile, state) {
|
|
4020
|
+
fs16.mkdirp(path10.dirname(stateFile));
|
|
4021
|
+
fs16.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
4017
4022
|
`);
|
|
4018
4023
|
}
|
|
4019
4024
|
function directOrigin(port) {
|
|
@@ -4023,37 +4028,37 @@ function frontDoorOrigin(state) {
|
|
|
4023
4028
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
4024
4029
|
return port === void 0 ? void 0 : directOrigin(port);
|
|
4025
4030
|
}
|
|
4026
|
-
function writeFrontDoorDirectRecord(
|
|
4027
|
-
|
|
4028
|
-
|
|
4031
|
+
function writeFrontDoorDirectRecord(fs16, recordsDir, record) {
|
|
4032
|
+
fs16.mkdirp(recordsDir);
|
|
4033
|
+
fs16.writeFilePrivate(path10.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
|
|
4029
4034
|
`);
|
|
4030
4035
|
}
|
|
4031
|
-
function removeFrontDoorDirectRecord(
|
|
4032
|
-
|
|
4036
|
+
function removeFrontDoorDirectRecord(fs16, recordsDir, pid) {
|
|
4037
|
+
fs16.removeRecursive(path10.join(recordsDir, `${String(pid)}.json`));
|
|
4033
4038
|
}
|
|
4034
|
-
function markFrontDoorDraining(
|
|
4035
|
-
|
|
4036
|
-
|
|
4039
|
+
function markFrontDoorDraining(fs16, markersDir, pid) {
|
|
4040
|
+
fs16.mkdirp(markersDir);
|
|
4041
|
+
fs16.writeFilePrivate(path10.join(markersDir, String(pid)), "\n");
|
|
4037
4042
|
}
|
|
4038
|
-
function unmarkFrontDoorDraining(
|
|
4039
|
-
|
|
4043
|
+
function unmarkFrontDoorDraining(fs16, markersDir, pid) {
|
|
4044
|
+
fs16.removeRecursive(path10.join(markersDir, String(pid)));
|
|
4040
4045
|
}
|
|
4041
|
-
function listDrainingFrontDoors(
|
|
4042
|
-
return
|
|
4046
|
+
function listDrainingFrontDoors(fs16, markersDir, isRunning) {
|
|
4047
|
+
return fs16.readdir(markersDir).flatMap((file) => /^[1-9]\d*$/.test(file) && Number.isSafeInteger(Number(file)) ? [Number(file)] : []).filter(isRunning).sort((a, b) => a - b);
|
|
4043
4048
|
}
|
|
4044
4049
|
function recordPid(file) {
|
|
4045
4050
|
const pidText = /^([1-9]\d*)\.json$/.exec(file)?.[1];
|
|
4046
4051
|
const pid = pidText === void 0 ? void 0 : Number(pidText);
|
|
4047
4052
|
return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
|
|
4048
4053
|
}
|
|
4049
|
-
function readDirectRecordEntry(
|
|
4054
|
+
function readDirectRecordEntry(fs16, recordsDir, file) {
|
|
4050
4055
|
const pid = recordPid(file);
|
|
4051
4056
|
if (pid === void 0) {
|
|
4052
4057
|
return void 0;
|
|
4053
4058
|
}
|
|
4054
4059
|
let raw;
|
|
4055
4060
|
try {
|
|
4056
|
-
raw =
|
|
4061
|
+
raw = fs16.readFileUtf8(path10.join(recordsDir, file));
|
|
4057
4062
|
} catch {
|
|
4058
4063
|
return void 0;
|
|
4059
4064
|
}
|
|
@@ -4067,37 +4072,37 @@ function readDirectRecordEntry(fs15, recordsDir, file) {
|
|
|
4067
4072
|
return { malformed: true };
|
|
4068
4073
|
}
|
|
4069
4074
|
}
|
|
4070
|
-
function listFrontDoorDirectRecords(
|
|
4071
|
-
return
|
|
4072
|
-
const entry = readDirectRecordEntry(
|
|
4075
|
+
function listFrontDoorDirectRecords(fs16, recordsDir) {
|
|
4076
|
+
return fs16.readdir(recordsDir).flatMap((file) => {
|
|
4077
|
+
const entry = readDirectRecordEntry(fs16, recordsDir, file);
|
|
4073
4078
|
return entry?.record === void 0 ? [] : [entry.record];
|
|
4074
4079
|
}).sort((a, b) => a.pid - b.pid);
|
|
4075
4080
|
}
|
|
4076
|
-
function pruneMalformedFrontDoorDirectFiles(
|
|
4077
|
-
for (const file of
|
|
4081
|
+
function pruneMalformedFrontDoorDirectFiles(fs16, recordsDir, isRunning) {
|
|
4082
|
+
for (const file of fs16.readdir(recordsDir)) {
|
|
4078
4083
|
const writer = RECORD_TEMPORARY_FILE.exec(file)?.[1];
|
|
4079
4084
|
const stale = writer !== void 0 && !isRunning(Number(writer));
|
|
4080
|
-
if (stale || readDirectRecordEntry(
|
|
4081
|
-
|
|
4085
|
+
if (stale || readDirectRecordEntry(fs16, recordsDir, file)?.malformed === true) {
|
|
4086
|
+
fs16.removeRecursive(path10.join(recordsDir, file));
|
|
4082
4087
|
}
|
|
4083
4088
|
}
|
|
4084
4089
|
}
|
|
4085
4090
|
function liveFrontDoorDirectRecords(records, liveness) {
|
|
4086
4091
|
return records.filter((record) => liveness.doors.has(record.pid) || liveness.unknown.has(record.pid));
|
|
4087
4092
|
}
|
|
4088
|
-
function pruneDeadFrontDoorDirectRecords(
|
|
4093
|
+
function pruneDeadFrontDoorDirectRecords(fs16, recordsDir, records, liveness) {
|
|
4089
4094
|
for (const record of records) {
|
|
4090
4095
|
if (!liveness.doors.has(record.pid) && !liveness.unknown.has(record.pid)) {
|
|
4091
|
-
removeFrontDoorDirectRecord(
|
|
4096
|
+
removeFrontDoorDirectRecord(fs16, recordsDir, record.pid);
|
|
4092
4097
|
}
|
|
4093
4098
|
}
|
|
4094
4099
|
}
|
|
4095
4100
|
function recordOf(details) {
|
|
4096
4101
|
return details === void 0 ? {} : { sessionId: details.sessionId, ...details.models === void 0 ? {} : { models: details.models } };
|
|
4097
4102
|
}
|
|
4098
|
-
function writeFrontDoorSession(
|
|
4099
|
-
|
|
4100
|
-
|
|
4103
|
+
function writeFrontDoorSession(fs16, sessionsDir, session) {
|
|
4104
|
+
fs16.mkdirPrivate(sessionsDir);
|
|
4105
|
+
fs16.writeFilePrivate(path10.join(sessionsDir, sessionRecordName(session.pid)), `${JSON.stringify(session, null, 2)}
|
|
4101
4106
|
`);
|
|
4102
4107
|
}
|
|
4103
4108
|
function sessionRecordName(pid) {
|
|
@@ -4109,32 +4114,32 @@ function isSessionRecordName(name) {
|
|
|
4109
4114
|
function summaryOf(session) {
|
|
4110
4115
|
return { pid: session.pid, startedAt: session.startedAt, ...session.supervisorPid === void 0 ? {} : { supervisorPid: session.supervisorPid } };
|
|
4111
4116
|
}
|
|
4112
|
-
function readFrontDoorSessionRecord(
|
|
4117
|
+
function readFrontDoorSessionRecord(fs16, sessionsDir, name) {
|
|
4113
4118
|
try {
|
|
4114
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
4119
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs16.readFileUtf8(path10.join(sessionsDir, name)) ?? ""));
|
|
4115
4120
|
return parsed.success ? parsed.data : void 0;
|
|
4116
4121
|
} catch {
|
|
4117
4122
|
return void 0;
|
|
4118
4123
|
}
|
|
4119
4124
|
}
|
|
4120
|
-
function listFrontDoorSessions(
|
|
4125
|
+
function listFrontDoorSessions(fs16, sessionsDir) {
|
|
4121
4126
|
const sessions = [];
|
|
4122
|
-
for (const name of
|
|
4123
|
-
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(
|
|
4127
|
+
for (const name of fs16.readdir(sessionsDir)) {
|
|
4128
|
+
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(fs16, sessionsDir, name) : void 0;
|
|
4124
4129
|
if (record !== void 0) {
|
|
4125
4130
|
sessions.push(summaryOf(record));
|
|
4126
4131
|
}
|
|
4127
4132
|
}
|
|
4128
4133
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
4129
4134
|
}
|
|
4130
|
-
function removeFrontDoorSession(
|
|
4131
|
-
|
|
4135
|
+
function removeFrontDoorSession(fs16, sessionsDir, pid) {
|
|
4136
|
+
fs16.removeRecursive(path10.join(sessionsDir, sessionRecordName(pid)));
|
|
4132
4137
|
}
|
|
4133
|
-
function pruneDeadFrontDoorSessions(
|
|
4138
|
+
function pruneDeadFrontDoorSessions(fs16, sessionsDir, listed, isRunning) {
|
|
4134
4139
|
const removed = [];
|
|
4135
4140
|
for (const session of listed) {
|
|
4136
4141
|
if (!isRunning(session.pid)) {
|
|
4137
|
-
removeFrontDoorSession(
|
|
4142
|
+
removeFrontDoorSession(fs16, sessionsDir, session.pid);
|
|
4138
4143
|
removed.push(session.pid);
|
|
4139
4144
|
}
|
|
4140
4145
|
}
|
|
@@ -4217,19 +4222,19 @@ var init_processRole = __esm({
|
|
|
4217
4222
|
// src/frontdoor/catalogueCleanup.ts
|
|
4218
4223
|
import path11 from "node:path";
|
|
4219
4224
|
import { z as z7 } from "zod";
|
|
4220
|
-
async function pruneAbandonedCatalogueGenerations(
|
|
4225
|
+
async function pruneAbandonedCatalogueGenerations(fs16, paths, ownPid, generation, runningAmong) {
|
|
4221
4226
|
const root = path11.join(paths.catalogueDir, "supervisors");
|
|
4222
|
-
const owners =
|
|
4227
|
+
const owners = fs16.readdir(root).flatMap((entry) => {
|
|
4223
4228
|
const pid = Number(entry);
|
|
4224
|
-
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry &&
|
|
4229
|
+
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry && fs16.lstat(path11.join(root, entry))?.kind === "dir" ? [pid] : [];
|
|
4225
4230
|
});
|
|
4226
4231
|
const running = await runningAmong(owners);
|
|
4227
4232
|
for (const pid of owners) {
|
|
4228
4233
|
if (pid !== ownPid && running.has(pid)) continue;
|
|
4229
4234
|
const directory = path11.join(root, String(pid));
|
|
4230
|
-
for (const entry of
|
|
4235
|
+
for (const entry of fs16.readdir(directory)) {
|
|
4231
4236
|
const candidate = path11.join(directory, entry);
|
|
4232
|
-
if (z7.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) &&
|
|
4237
|
+
if (z7.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) && fs16.lstat(candidate)?.kind === "dir") fs16.removeRecursive(candidate);
|
|
4233
4238
|
}
|
|
4234
4239
|
}
|
|
4235
4240
|
}
|
|
@@ -4258,9 +4263,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
4258
4263
|
}
|
|
4259
4264
|
}
|
|
4260
4265
|
async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
4261
|
-
const { fs:
|
|
4266
|
+
const { fs: fs16, paths } = ports;
|
|
4262
4267
|
const servingBinary = ports.statOwnExecutable();
|
|
4263
|
-
const previous = readFrontDoorState(
|
|
4268
|
+
const previous = readFrontDoorState(fs16, paths.frontdoorStateFile);
|
|
4264
4269
|
let lastPort = previous?.lastPort;
|
|
4265
4270
|
let lastConnectPort = previous?.lastConnectPort;
|
|
4266
4271
|
let lastDirectPort = previous?.lastDirectPort;
|
|
@@ -4274,8 +4279,8 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4274
4279
|
const fail = async (message) => {
|
|
4275
4280
|
ports.closeRcStreamHub();
|
|
4276
4281
|
if (predecessor === void 0) {
|
|
4277
|
-
writeFrontDoorState(
|
|
4278
|
-
|
|
4282
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { lastError: message, ...sticky() });
|
|
4283
|
+
fs16.removeRecursive(paths.frontdoorLockFile);
|
|
4279
4284
|
}
|
|
4280
4285
|
ports.log(`agent-shim frontdoor supervisor: ${message}`);
|
|
4281
4286
|
const chain = ports.respawnChain;
|
|
@@ -4286,7 +4291,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4286
4291
|
return 1;
|
|
4287
4292
|
};
|
|
4288
4293
|
if (predecessor === void 0) {
|
|
4289
|
-
writeFrontDoorState(
|
|
4294
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
|
|
4290
4295
|
}
|
|
4291
4296
|
const previousSticky = lastPort;
|
|
4292
4297
|
let http3;
|
|
@@ -4327,14 +4332,14 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4327
4332
|
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)`);
|
|
4328
4333
|
}
|
|
4329
4334
|
lastDirectPort = direct.port;
|
|
4330
|
-
writeFrontDoorDirectRecord(
|
|
4331
|
-
writeFrontDoorCodexHome(
|
|
4332
|
-
writeFrontDoorState(
|
|
4333
|
-
await pruneAbandonedCatalogueGenerations(
|
|
4335
|
+
writeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
|
|
4336
|
+
writeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid, ports.codexHome, ports.catalogueGeneration);
|
|
4337
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http3.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
|
|
4338
|
+
await pruneAbandonedCatalogueGenerations(fs16, paths, ports.ownPid, ports.catalogueGeneration, ports.runningAmong);
|
|
4334
4339
|
ports.onServing();
|
|
4335
4340
|
ports.doorHealth.generation({ providerPort: http3.port, connectPort: connect3.port, directPort: direct.port });
|
|
4336
4341
|
if (predecessor === void 0) {
|
|
4337
|
-
|
|
4342
|
+
fs16.removeRecursive(paths.frontdoorLockFile);
|
|
4338
4343
|
} else {
|
|
4339
4344
|
predecessor.serving();
|
|
4340
4345
|
}
|
|
@@ -4343,7 +4348,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4343
4348
|
let idleSince;
|
|
4344
4349
|
let ticks = 0;
|
|
4345
4350
|
const supersedingOwner = async () => {
|
|
4346
|
-
const owner = readFrontDoorState(
|
|
4351
|
+
const owner = readFrontDoorState(fs16, paths.frontdoorStateFile)?.supervisorPid;
|
|
4347
4352
|
return owner !== void 0 && owner !== ports.ownPid && (await ports.runningAmong([owner])).has(owner) ? owner : void 0;
|
|
4348
4353
|
};
|
|
4349
4354
|
let supersededBy;
|
|
@@ -4372,15 +4377,15 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4372
4377
|
ports.stopBackgroundWork?.();
|
|
4373
4378
|
const drained = [direct.drain(), connect3.drain(), http3.drain()];
|
|
4374
4379
|
if (await supersedingOwner() === void 0) {
|
|
4375
|
-
writeFrontDoorState(
|
|
4380
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, sticky());
|
|
4376
4381
|
}
|
|
4377
|
-
markFrontDoorDraining(
|
|
4382
|
+
markFrontDoorDraining(fs16, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4378
4383
|
ports.closeRcStreamHub();
|
|
4379
4384
|
await Promise.all(drained);
|
|
4380
|
-
unmarkFrontDoorDraining(
|
|
4381
|
-
removeFrontDoorDirectRecord(
|
|
4382
|
-
removeFrontDoorCodexHome(
|
|
4383
|
-
|
|
4385
|
+
unmarkFrontDoorDraining(fs16, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4386
|
+
removeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4387
|
+
removeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid);
|
|
4388
|
+
fs16.removeRecursive(catalogueGenerationDir(paths, ports.ownPid, ports.catalogueGeneration));
|
|
4384
4389
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: the connections this door carried have ended; exiting`);
|
|
4385
4390
|
return 0;
|
|
4386
4391
|
};
|
|
@@ -4401,14 +4406,14 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4401
4406
|
await connect3.close();
|
|
4402
4407
|
await http3.close();
|
|
4403
4408
|
ports.closeRcStreamHub();
|
|
4404
|
-
removeFrontDoorDirectRecord(
|
|
4405
|
-
removeFrontDoorCodexHome(
|
|
4406
|
-
|
|
4409
|
+
removeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4410
|
+
removeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid);
|
|
4411
|
+
fs16.removeRecursive(catalogueGenerationDir(paths, ports.ownPid, ports.catalogueGeneration));
|
|
4407
4412
|
};
|
|
4408
4413
|
const shutdown = async () => {
|
|
4409
4414
|
await closeServing();
|
|
4410
4415
|
if (await supersedingOwner() === void 0) {
|
|
4411
|
-
writeFrontDoorState(
|
|
4416
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, sticky());
|
|
4412
4417
|
}
|
|
4413
4418
|
return 0;
|
|
4414
4419
|
};
|
|
@@ -4427,7 +4432,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4427
4432
|
ticks += 1;
|
|
4428
4433
|
const listed = ports.registry.rescan();
|
|
4429
4434
|
const running = await ports.runningAmong(listed.map((session) => session.pid));
|
|
4430
|
-
const pruned = pruneDeadFrontDoorSessions(
|
|
4435
|
+
const pruned = pruneDeadFrontDoorSessions(fs16, paths.frontdoorSessionsDir, listed, (pid) => running.has(pid));
|
|
4431
4436
|
ports.registry.forget(pruned);
|
|
4432
4437
|
ports.observeLaunchRegistry(listed, pruned);
|
|
4433
4438
|
ports.checkQuotaExpiry();
|
|
@@ -4504,8 +4509,8 @@ function parseConnectTarget(authority) {
|
|
|
4504
4509
|
function isInterceptedHost(host, interceptHosts) {
|
|
4505
4510
|
return interceptHosts.includes(host);
|
|
4506
4511
|
}
|
|
4507
|
-
function servedByPipeline(
|
|
4508
|
-
return
|
|
4512
|
+
function servedByPipeline(path49) {
|
|
4513
|
+
return path49?.startsWith(ROUTED_PATH_PREFIX) === true;
|
|
4509
4514
|
}
|
|
4510
4515
|
function forwardableHeaders(headers) {
|
|
4511
4516
|
const connectionTokens = new Set(
|
|
@@ -4949,7 +4954,7 @@ var init_package = __esm({
|
|
|
4949
4954
|
"package.json"() {
|
|
4950
4955
|
package_default = {
|
|
4951
4956
|
name: "agent-shim",
|
|
4952
|
-
version: "11.
|
|
4957
|
+
version: "11.85.0",
|
|
4953
4958
|
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.",
|
|
4954
4959
|
license: "MIT",
|
|
4955
4960
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -5175,43 +5180,43 @@ function parseJson(raw, schema) {
|
|
|
5175
5180
|
const parsed = schema.safeParse(JSON.parse(raw));
|
|
5176
5181
|
return parsed.success ? parsed.data : void 0;
|
|
5177
5182
|
}
|
|
5178
|
-
function readHeadroomState(
|
|
5183
|
+
function readHeadroomState(fs16, stateFile) {
|
|
5179
5184
|
try {
|
|
5180
|
-
return parseJson(
|
|
5185
|
+
return parseJson(fs16.readFileUtf8(stateFile), HeadroomStateSchema);
|
|
5181
5186
|
} catch {
|
|
5182
5187
|
return void 0;
|
|
5183
5188
|
}
|
|
5184
5189
|
}
|
|
5185
|
-
function writeHeadroomState(
|
|
5186
|
-
|
|
5187
|
-
|
|
5190
|
+
function writeHeadroomState(fs16, stateFile, state) {
|
|
5191
|
+
fs16.mkdirp(path14.dirname(stateFile));
|
|
5192
|
+
fs16.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
5188
5193
|
`);
|
|
5189
5194
|
}
|
|
5190
|
-
function resolveServingHeadroomState(
|
|
5191
|
-
const current = readHeadroomState(
|
|
5195
|
+
function resolveServingHeadroomState(fs16, files, isRunning) {
|
|
5196
|
+
const current = readHeadroomState(fs16, files.stateFile);
|
|
5192
5197
|
if (current !== void 0) {
|
|
5193
5198
|
return { path: files.stateFile, state: current };
|
|
5194
5199
|
}
|
|
5195
|
-
const legacy = readHeadroomState(
|
|
5200
|
+
const legacy = readHeadroomState(fs16, files.legacyStateFile);
|
|
5196
5201
|
if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
|
|
5197
5202
|
return { path: files.legacyStateFile, state: legacy };
|
|
5198
5203
|
}
|
|
5199
5204
|
return void 0;
|
|
5200
5205
|
}
|
|
5201
|
-
function migrateHeadroomState(
|
|
5202
|
-
const legacy = readHeadroomState(
|
|
5206
|
+
function migrateHeadroomState(fs16, files, isRunning) {
|
|
5207
|
+
const legacy = readHeadroomState(fs16, files.legacyStateFile);
|
|
5203
5208
|
const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
|
|
5204
|
-
const current = readHeadroomState(
|
|
5209
|
+
const current = readHeadroomState(fs16, files.stateFile);
|
|
5205
5210
|
if (current !== void 0 || legacyLive) {
|
|
5206
|
-
if (!legacyLive &&
|
|
5207
|
-
|
|
5211
|
+
if (!legacyLive && fs16.readFileUtf8(files.legacyStateFile) !== void 0) {
|
|
5212
|
+
fs16.removeRecursive(files.legacyStateFile);
|
|
5208
5213
|
}
|
|
5209
5214
|
return;
|
|
5210
5215
|
}
|
|
5211
5216
|
if (legacy !== void 0) {
|
|
5212
|
-
writeHeadroomState(
|
|
5217
|
+
writeHeadroomState(fs16, files.stateFile, legacy);
|
|
5213
5218
|
}
|
|
5214
|
-
|
|
5219
|
+
fs16.removeRecursive(files.legacyStateFile);
|
|
5215
5220
|
}
|
|
5216
5221
|
function hashAllowlist(allowlist) {
|
|
5217
5222
|
return createHash3("sha256").update(allowlist.join("\n")).digest("hex");
|
|
@@ -5244,27 +5249,27 @@ function isAdmissibleUrl(entry) {
|
|
|
5244
5249
|
function parseAllowlistFile(content) {
|
|
5245
5250
|
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)));
|
|
5246
5251
|
}
|
|
5247
|
-
function writeAllowlistFile(
|
|
5248
|
-
|
|
5249
|
-
|
|
5252
|
+
function writeAllowlistFile(fs16, allowlistFile, allowlist) {
|
|
5253
|
+
fs16.mkdirPrivate(path14.dirname(allowlistFile));
|
|
5254
|
+
fs16.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
|
|
5250
5255
|
}
|
|
5251
|
-
function pruneStaleAllowlistTemporaries(
|
|
5256
|
+
function pruneStaleAllowlistTemporaries(fs16, allowlistFile, isRunning) {
|
|
5252
5257
|
const prefix = `${path14.basename(allowlistFile)}.`;
|
|
5253
|
-
for (const name of
|
|
5258
|
+
for (const name of fs16.readdir(path14.dirname(allowlistFile))) {
|
|
5254
5259
|
const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
|
|
5255
5260
|
if (writer !== void 0 && !isRunning(Number(writer))) {
|
|
5256
|
-
|
|
5261
|
+
fs16.removeRecursive(path14.join(path14.dirname(allowlistFile), name));
|
|
5257
5262
|
}
|
|
5258
5263
|
}
|
|
5259
5264
|
}
|
|
5260
|
-
function readAllProviders(
|
|
5265
|
+
function readAllProviders(fs16, providersDir) {
|
|
5261
5266
|
const result = [];
|
|
5262
|
-
for (const name of
|
|
5267
|
+
for (const name of fs16.readdir(providersDir)) {
|
|
5263
5268
|
if (!name.endsWith(".json")) {
|
|
5264
5269
|
continue;
|
|
5265
5270
|
}
|
|
5266
5271
|
try {
|
|
5267
|
-
const parsed = parseJson(
|
|
5272
|
+
const parsed = parseJson(fs16.readFileUtf8(path14.join(providersDir, name)), ProviderSchema);
|
|
5268
5273
|
if (parsed !== void 0) {
|
|
5269
5274
|
result.push({ name: name.slice(0, -".json".length), provider: parsed });
|
|
5270
5275
|
}
|
|
@@ -5274,22 +5279,22 @@ function readAllProviders(fs15, providersDir) {
|
|
|
5274
5279
|
}
|
|
5275
5280
|
return result;
|
|
5276
5281
|
}
|
|
5277
|
-
function writeSession(
|
|
5278
|
-
|
|
5279
|
-
|
|
5282
|
+
function writeSession(fs16, sessionsDir, session) {
|
|
5283
|
+
fs16.mkdirp(sessionsDir);
|
|
5284
|
+
fs16.writeFileUtf8(path14.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
5280
5285
|
`);
|
|
5281
5286
|
}
|
|
5282
|
-
function removeSession(
|
|
5283
|
-
|
|
5287
|
+
function removeSession(fs16, sessionsDir, pid) {
|
|
5288
|
+
fs16.removeRecursive(path14.join(sessionsDir, `${String(pid)}.json`));
|
|
5284
5289
|
}
|
|
5285
|
-
function listSessions(
|
|
5290
|
+
function listSessions(fs16, sessionsDir) {
|
|
5286
5291
|
const sessions = [];
|
|
5287
|
-
for (const name of
|
|
5292
|
+
for (const name of fs16.readdir(sessionsDir)) {
|
|
5288
5293
|
if (!name.endsWith(".json")) {
|
|
5289
5294
|
continue;
|
|
5290
5295
|
}
|
|
5291
5296
|
try {
|
|
5292
|
-
const parsed = parseJson(
|
|
5297
|
+
const parsed = parseJson(fs16.readFileUtf8(path14.join(sessionsDir, name)), HeadroomSessionSchema);
|
|
5293
5298
|
if (parsed !== void 0) {
|
|
5294
5299
|
sessions.push(parsed);
|
|
5295
5300
|
}
|
|
@@ -5299,22 +5304,22 @@ function listSessions(fs15, sessionsDir) {
|
|
|
5299
5304
|
}
|
|
5300
5305
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
5301
5306
|
}
|
|
5302
|
-
function sessionsForSupervisor(
|
|
5303
|
-
return listSessions(
|
|
5307
|
+
function sessionsForSupervisor(fs16, sessionsDir, supervisorPid) {
|
|
5308
|
+
return listSessions(fs16, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
|
|
5304
5309
|
}
|
|
5305
|
-
function pruneDeadSessions(
|
|
5310
|
+
function pruneDeadSessions(fs16, sessionsDir, isRunning) {
|
|
5306
5311
|
const removed = [];
|
|
5307
|
-
for (const session of listSessions(
|
|
5312
|
+
for (const session of listSessions(fs16, sessionsDir)) {
|
|
5308
5313
|
if (!isRunning(session.pid)) {
|
|
5309
|
-
removeSession(
|
|
5314
|
+
removeSession(fs16, sessionsDir, session.pid);
|
|
5310
5315
|
removed.push(session.pid);
|
|
5311
5316
|
}
|
|
5312
5317
|
}
|
|
5313
5318
|
return removed;
|
|
5314
5319
|
}
|
|
5315
|
-
function readStartLock(
|
|
5320
|
+
function readStartLock(fs16, lockFile) {
|
|
5316
5321
|
try {
|
|
5317
|
-
return parseJson(
|
|
5322
|
+
return parseJson(fs16.readFileUtf8(lockFile), HeadroomLockSchema);
|
|
5318
5323
|
} catch {
|
|
5319
5324
|
return void 0;
|
|
5320
5325
|
}
|
|
@@ -5404,12 +5409,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
|
|
|
5404
5409
|
}
|
|
5405
5410
|
return hashAllowlist([...entries].sort());
|
|
5406
5411
|
}
|
|
5407
|
-
function earlierReleaseDaemon(
|
|
5412
|
+
function earlierReleaseDaemon(fs16, paths, daemon) {
|
|
5408
5413
|
if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
|
|
5409
5414
|
return void 0;
|
|
5410
5415
|
}
|
|
5411
|
-
const providers = readAllProviders(
|
|
5412
|
-
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(
|
|
5416
|
+
const providers = readAllProviders(fs16, paths.providersDir).map((entry) => entry.provider);
|
|
5417
|
+
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile)));
|
|
5413
5418
|
return { admitsServingDoor: daemon.recordedHash === expected };
|
|
5414
5419
|
}
|
|
5415
5420
|
var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
|
|
@@ -5434,8 +5439,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
|
|
|
5434
5439
|
}
|
|
5435
5440
|
return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
|
|
5436
5441
|
}
|
|
5437
|
-
function daemonAdmits(
|
|
5438
|
-
const content =
|
|
5442
|
+
function daemonAdmits(fs16, allowlistFile, recordedHash, required) {
|
|
5443
|
+
const content = fs16.readFileUtf8(allowlistFile);
|
|
5439
5444
|
if (content === void 0 || recordedHash === void 0) {
|
|
5440
5445
|
return false;
|
|
5441
5446
|
}
|
|
@@ -5704,7 +5709,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
|
|
|
5704
5709
|
const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
|
|
5705
5710
|
return { message: refusal2, repairable: replaceable };
|
|
5706
5711
|
}
|
|
5707
|
-
function prepareHeadroomSocket(
|
|
5712
|
+
function prepareHeadroomSocket(fs16, ports, paths, supervisorPid) {
|
|
5708
5713
|
const unsupported = platformRefusal(ports.platform);
|
|
5709
5714
|
if (unsupported !== void 0) {
|
|
5710
5715
|
return { refused: unsupported };
|
|
@@ -5719,18 +5724,18 @@ function prepareHeadroomSocket(fs15, ports, paths, supervisorPid) {
|
|
|
5719
5724
|
if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
|
|
5720
5725
|
return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
|
|
5721
5726
|
}
|
|
5722
|
-
|
|
5727
|
+
fs16.mkdirPrivate(paths.headroomSocketDir);
|
|
5723
5728
|
const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
|
|
5724
5729
|
return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
|
|
5725
5730
|
}
|
|
5726
|
-
function pruneStaleHeadroomSockets(
|
|
5731
|
+
function pruneStaleHeadroomSockets(fs16, paths, isRunning) {
|
|
5727
5732
|
const removed = [];
|
|
5728
|
-
for (const name of
|
|
5733
|
+
for (const name of fs16.readdir(paths.headroomSocketDir)) {
|
|
5729
5734
|
const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
|
|
5730
5735
|
if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
|
|
5731
5736
|
continue;
|
|
5732
5737
|
}
|
|
5733
|
-
|
|
5738
|
+
fs16.removeRecursive(path15.join(paths.headroomSocketDir, name));
|
|
5734
5739
|
removed.push(name);
|
|
5735
5740
|
}
|
|
5736
5741
|
return removed;
|
|
@@ -5842,37 +5847,37 @@ function compareVersions2(a, b) {
|
|
|
5842
5847
|
return 0;
|
|
5843
5848
|
}
|
|
5844
5849
|
async function runSupervisor(initialConfig, ports, options = {}) {
|
|
5845
|
-
const { fs:
|
|
5850
|
+
const { fs: fs16, paths } = ports;
|
|
5846
5851
|
let config = initialConfig;
|
|
5847
|
-
migrateHeadroomState(
|
|
5848
|
-
const previousState = resolveServingHeadroomState(
|
|
5852
|
+
migrateHeadroomState(fs16, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
|
|
5853
|
+
const previousState = resolveServingHeadroomState(fs16, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
|
|
5849
5854
|
if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
|
|
5850
5855
|
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
|
|
5851
5856
|
return 0;
|
|
5852
5857
|
}
|
|
5853
5858
|
let installedSource = previousState?.installedSource;
|
|
5854
5859
|
const ownsState = () => {
|
|
5855
|
-
const owner = readHeadroomState(
|
|
5860
|
+
const owner = readHeadroomState(fs16, paths.headroomStateFile)?.supervisorPid;
|
|
5856
5861
|
return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
|
|
5857
5862
|
};
|
|
5858
5863
|
const writeOwnState = (state) => {
|
|
5859
5864
|
if (!ownsState()) {
|
|
5860
5865
|
return false;
|
|
5861
5866
|
}
|
|
5862
|
-
writeHeadroomState(
|
|
5867
|
+
writeHeadroomState(fs16, paths.headroomStateFile, state);
|
|
5863
5868
|
return true;
|
|
5864
5869
|
};
|
|
5865
5870
|
const fail = (message) => {
|
|
5866
5871
|
if (writeOwnState({ lastError: message })) {
|
|
5867
|
-
|
|
5872
|
+
fs16.removeRecursive(paths.headroomLockFile);
|
|
5868
5873
|
}
|
|
5869
5874
|
ports.log(`agent-shim headroom supervisor: ${message}`);
|
|
5870
5875
|
return 1;
|
|
5871
5876
|
};
|
|
5872
5877
|
const syncAllowlistFile = (allowlist) => {
|
|
5873
5878
|
try {
|
|
5874
|
-
if (
|
|
5875
|
-
writeAllowlistFile(
|
|
5879
|
+
if (fs16.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
|
|
5880
|
+
writeAllowlistFile(fs16, paths.headroomAllowlistFile, allowlist);
|
|
5876
5881
|
ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
|
|
5877
5882
|
}
|
|
5878
5883
|
return void 0;
|
|
@@ -5890,9 +5895,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5890
5895
|
}
|
|
5891
5896
|
ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
|
|
5892
5897
|
try {
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
writeAllowlistFile(
|
|
5898
|
+
fs16.mkdirPrivate(paths.headroomDir);
|
|
5899
|
+
fs16.mkdirPrivate(path16.dirname(paths.headroomAllowlistFile));
|
|
5900
|
+
writeAllowlistFile(fs16, paths.headroomAllowlistFile, allowlist);
|
|
5896
5901
|
} catch (error) {
|
|
5897
5902
|
return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error instanceof Error ? error.message : String(error)}`;
|
|
5898
5903
|
}
|
|
@@ -5917,20 +5922,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5917
5922
|
installedSource = config.source;
|
|
5918
5923
|
return void 0;
|
|
5919
5924
|
};
|
|
5920
|
-
const socket = prepareHeadroomSocket(
|
|
5925
|
+
const socket = prepareHeadroomSocket(fs16, ports.socketTrust, paths, ports.ownPid);
|
|
5921
5926
|
if (socket.refused !== void 0) {
|
|
5922
5927
|
return fail(socket.refused);
|
|
5923
5928
|
}
|
|
5924
5929
|
const { socketPath } = socket;
|
|
5925
|
-
pruneStaleHeadroomSockets(
|
|
5926
|
-
pruneStaleAllowlistTemporaries(
|
|
5930
|
+
pruneStaleHeadroomSockets(fs16, paths, ports.isRunning);
|
|
5931
|
+
pruneStaleAllowlistTemporaries(fs16, paths.headroomAllowlistFile, ports.isRunning);
|
|
5927
5932
|
const installFailure = ensureInstalled();
|
|
5928
5933
|
if (installFailure !== void 0) {
|
|
5929
5934
|
return fail(installFailure);
|
|
5930
5935
|
}
|
|
5931
5936
|
const version = ports.headroomVersion() ?? "unknown";
|
|
5932
5937
|
writeOwnState({ supervisorPid: ports.ownPid, version, installedSource });
|
|
5933
|
-
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(
|
|
5938
|
+
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs16, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
|
|
5934
5939
|
const orphanPid = previousState?.headroomPid;
|
|
5935
5940
|
const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
|
|
5936
5941
|
const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
|
|
@@ -5968,12 +5973,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5968
5973
|
}
|
|
5969
5974
|
config = ports.readConfig();
|
|
5970
5975
|
const settingsHash = hashSettings(config.settings);
|
|
5971
|
-
const inputs = currentHeadroomAllowlistInputs(
|
|
5972
|
-
pruneDeadFrontDoorDirectRecords(
|
|
5973
|
-
pruneMalformedFrontDoorDirectFiles(
|
|
5976
|
+
const inputs = currentHeadroomAllowlistInputs(fs16, paths, ports.frontDoorLiveness);
|
|
5977
|
+
pruneDeadFrontDoorDirectRecords(fs16, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
|
|
5978
|
+
pruneMalformedFrontDoorDirectFiles(fs16, paths.frontdoorDirectRecordsDir, ports.isRunning);
|
|
5974
5979
|
const allowlist = inputs.frontDoorOrigins;
|
|
5975
5980
|
const allowlistHash = hashAllowlist(allowlist);
|
|
5976
|
-
pruneDeadSessions(
|
|
5981
|
+
pruneDeadSessions(fs16, paths.headroomSessionsDir, ports.isRunning);
|
|
5977
5982
|
const ownsNow = ownsState();
|
|
5978
5983
|
if (!ownsNow && !superseded) {
|
|
5979
5984
|
ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
|
|
@@ -6020,7 +6025,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6020
6025
|
runningSettingsHash = settingsHash;
|
|
6021
6026
|
const recorded = writeOwnState(servingState(pid));
|
|
6022
6027
|
if (recorded) {
|
|
6023
|
-
|
|
6028
|
+
fs16.removeRecursive(paths.headroomLockFile);
|
|
6024
6029
|
}
|
|
6025
6030
|
idleSince = void 0;
|
|
6026
6031
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
|
|
@@ -6048,7 +6053,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6048
6053
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
|
|
6049
6054
|
}
|
|
6050
6055
|
if (runningSettingsHash !== settingsHash || installedSource !== config.source) {
|
|
6051
|
-
if (sessionsForSupervisor(
|
|
6056
|
+
if (sessionsForSupervisor(fs16, paths.headroomSessionsDir, ports.ownPid).length === 0) {
|
|
6052
6057
|
ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
|
|
6053
6058
|
ports.stopProcess(headroomPid);
|
|
6054
6059
|
headroomPid = void 0;
|
|
@@ -6057,7 +6062,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6057
6062
|
continue;
|
|
6058
6063
|
}
|
|
6059
6064
|
}
|
|
6060
|
-
const sessions = sessionsForSupervisor(
|
|
6065
|
+
const sessions = sessionsForSupervisor(fs16, paths.headroomSessionsDir, ports.ownPid);
|
|
6061
6066
|
if (sessions.length === 0) {
|
|
6062
6067
|
idleSince ??= ports.now();
|
|
6063
6068
|
const idleMs = ports.now() - idleSince;
|
|
@@ -6082,9 +6087,9 @@ function undeterminedFrontDoors(inputs) {
|
|
|
6082
6087
|
return reason === void 0 ? [] : [{ pid: record.pid, origin: directOrigin(record.directPort), reason }];
|
|
6083
6088
|
});
|
|
6084
6089
|
}
|
|
6085
|
-
function currentHeadroomAllowlistInputs(
|
|
6086
|
-
const named = frontDoorOrigin(readFrontDoorState(
|
|
6087
|
-
const records = listFrontDoorDirectRecords(
|
|
6090
|
+
function currentHeadroomAllowlistInputs(fs16, paths, frontDoorLiveness) {
|
|
6091
|
+
const named = frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile));
|
|
6092
|
+
const records = listFrontDoorDirectRecords(fs16, paths.frontdoorDirectRecordsDir);
|
|
6088
6093
|
const liveness = frontDoorLiveness(records.map((record) => record.pid));
|
|
6089
6094
|
const live = liveFrontDoorDirectRecords(records, liveness).map((record) => directOrigin(record.directPort));
|
|
6090
6095
|
return {
|
|
@@ -6093,8 +6098,8 @@ function currentHeadroomAllowlistInputs(fs15, paths, frontDoorLiveness) {
|
|
|
6093
6098
|
frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
|
|
6094
6099
|
};
|
|
6095
6100
|
}
|
|
6096
|
-
function launchRequiredUpstreams(
|
|
6097
|
-
const door = frontDoorOrigin(readFrontDoorState(
|
|
6101
|
+
function launchRequiredUpstreams(fs16, paths) {
|
|
6102
|
+
const door = frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile));
|
|
6098
6103
|
return door === void 0 ? [] : [door];
|
|
6099
6104
|
}
|
|
6100
6105
|
async function waitUntilReady(ports, socketPath, pid) {
|
|
@@ -6884,8 +6889,8 @@ import path20 from "node:path";
|
|
|
6884
6889
|
function poolNameOf(selector) {
|
|
6885
6890
|
return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
|
|
6886
6891
|
}
|
|
6887
|
-
function readActiveIdentity(
|
|
6888
|
-
const trimmed =
|
|
6892
|
+
function readActiveIdentity(fs16, activeIdentityFile) {
|
|
6893
|
+
const trimmed = fs16.readFileUtf8(activeIdentityFile)?.trim();
|
|
6889
6894
|
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
6890
6895
|
}
|
|
6891
6896
|
function isNonEmpty(value) {
|
|
@@ -6935,11 +6940,11 @@ function decideConfigProfile(params) {
|
|
|
6935
6940
|
}
|
|
6936
6941
|
return { source: "none" };
|
|
6937
6942
|
}
|
|
6938
|
-
function loadIdentity(identitiesDir, name,
|
|
6943
|
+
function loadIdentity(identitiesDir, name, fs16) {
|
|
6939
6944
|
if (!isFileName(name)) {
|
|
6940
6945
|
throw new UnsafeNameError(name, "identity", FILE_NAME_RULE);
|
|
6941
6946
|
}
|
|
6942
|
-
return loadConfigFile(path20.join(identitiesDir, name, "identity.json"), IdentitySchema,
|
|
6947
|
+
return loadConfigFile(path20.join(identitiesDir, name, "identity.json"), IdentitySchema, fs16.readConfigFile);
|
|
6943
6948
|
}
|
|
6944
6949
|
var IDENTITY_DECISION_SOURCES, IDENTITY_SOURCE_LABELS, CONFIG_PROFILE_DECISION_SOURCES;
|
|
6945
6950
|
var init_identity = __esm({
|
|
@@ -7193,14 +7198,14 @@ function isIdentityName(name) {
|
|
|
7193
7198
|
function claudeJsonPath(identitiesDir, identity) {
|
|
7194
7199
|
return path21.join(identitiesDir, identity, CLAUDE_JSON);
|
|
7195
7200
|
}
|
|
7196
|
-
function readAccountMetadata(
|
|
7201
|
+
function readAccountMetadata(fs16, identitiesDir, identity) {
|
|
7197
7202
|
if (!isIdentityName(identity)) {
|
|
7198
7203
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
7199
7204
|
}
|
|
7200
|
-
return readAccountMetadataFile(
|
|
7205
|
+
return readAccountMetadataFile(fs16, claudeJsonPath(identitiesDir, identity));
|
|
7201
7206
|
}
|
|
7202
|
-
function readAccountMetadataFile(
|
|
7203
|
-
const raw =
|
|
7207
|
+
function readAccountMetadataFile(fs16, file) {
|
|
7208
|
+
const raw = fs16.readFileUtf8(file);
|
|
7204
7209
|
if (raw === void 0) {
|
|
7205
7210
|
return void 0;
|
|
7206
7211
|
}
|
|
@@ -7230,19 +7235,19 @@ function readAccountMetadataFile(fs15, file) {
|
|
|
7230
7235
|
}
|
|
7231
7236
|
return account.data;
|
|
7232
7237
|
}
|
|
7233
|
-
function createAccountReader(
|
|
7238
|
+
function createAccountReader(fs16, identitiesDir) {
|
|
7234
7239
|
const cache = /* @__PURE__ */ new Map();
|
|
7235
7240
|
return (identity) => {
|
|
7236
7241
|
if (!isIdentityName(identity)) {
|
|
7237
7242
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
7238
7243
|
}
|
|
7239
|
-
const stat =
|
|
7244
|
+
const stat = fs16.lstat(claudeJsonPath(identitiesDir, identity));
|
|
7240
7245
|
const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
|
|
7241
7246
|
const cached = cache.get(identity);
|
|
7242
7247
|
if (cached?.stamp === stamp) {
|
|
7243
7248
|
return cached.account;
|
|
7244
7249
|
}
|
|
7245
|
-
const account = readAccountMetadata(
|
|
7250
|
+
const account = readAccountMetadata(fs16, identitiesDir, identity);
|
|
7246
7251
|
cache.set(identity, { stamp, account });
|
|
7247
7252
|
return account;
|
|
7248
7253
|
};
|
|
@@ -7278,9 +7283,9 @@ var init_accountDescription = __esm({
|
|
|
7278
7283
|
});
|
|
7279
7284
|
|
|
7280
7285
|
// src/identityAccounts.ts
|
|
7281
|
-
function readIdentityAccount(
|
|
7286
|
+
function readIdentityAccount(fs16, identitiesDir, identity) {
|
|
7282
7287
|
try {
|
|
7283
|
-
const account = readAccountMetadata(
|
|
7288
|
+
const account = readAccountMetadata(fs16, identitiesDir, identity);
|
|
7284
7289
|
return account === void 0 ? void 0 : { account };
|
|
7285
7290
|
} catch (error) {
|
|
7286
7291
|
if (error instanceof AccountMetadataError) {
|
|
@@ -7919,8 +7924,8 @@ function segmentDay(epochMs) {
|
|
|
7919
7924
|
function segmentName(day, pid) {
|
|
7920
7925
|
return `${day}.${String(pid)}.jsonl`;
|
|
7921
7926
|
}
|
|
7922
|
-
function listLogSegments(
|
|
7923
|
-
return
|
|
7927
|
+
function listLogSegments(fs16, logDir) {
|
|
7928
|
+
return fs16.readdir(logDir).flatMap((name) => {
|
|
7924
7929
|
const match = SEGMENT_RE.exec(name);
|
|
7925
7930
|
const day = match?.[1];
|
|
7926
7931
|
if (day === void 0) {
|
|
@@ -7929,15 +7934,15 @@ function listLogSegments(fs15, logDir) {
|
|
|
7929
7934
|
return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
|
|
7930
7935
|
}).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
|
|
7931
7936
|
}
|
|
7932
|
-
function readUsageLog(
|
|
7937
|
+
function readUsageLog(fs16, logDir, options = {}) {
|
|
7933
7938
|
const { sinceMs } = options;
|
|
7934
7939
|
const records = [];
|
|
7935
7940
|
let invalidLines = 0;
|
|
7936
|
-
for (const segment of listLogSegments(
|
|
7941
|
+
for (const segment of listLogSegments(fs16, logDir)) {
|
|
7937
7942
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
7938
7943
|
continue;
|
|
7939
7944
|
}
|
|
7940
|
-
const read = readSegment(
|
|
7945
|
+
const read = readSegment(fs16, logDir, segment);
|
|
7941
7946
|
if (read === void 0) {
|
|
7942
7947
|
continue;
|
|
7943
7948
|
}
|
|
@@ -7951,8 +7956,8 @@ function readUsageLog(fs15, logDir, options = {}) {
|
|
|
7951
7956
|
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
7952
7957
|
return { records, invalidLines };
|
|
7953
7958
|
}
|
|
7954
|
-
function readSegment(
|
|
7955
|
-
const contents =
|
|
7959
|
+
function readSegment(fs16, logDir, segment) {
|
|
7960
|
+
const contents = fs16.readFileUtf8(path22.join(logDir, segment.name));
|
|
7956
7961
|
if (contents === void 0) {
|
|
7957
7962
|
return void 0;
|
|
7958
7963
|
}
|
|
@@ -7986,9 +7991,9 @@ function snapshotPath(snapshotsDir, identity) {
|
|
|
7986
7991
|
}
|
|
7987
7992
|
return path22.join(snapshotsDir, `${identity}.json`);
|
|
7988
7993
|
}
|
|
7989
|
-
function readUsageSnapshot(
|
|
7994
|
+
function readUsageSnapshot(fs16, snapshotsDir, identity) {
|
|
7990
7995
|
const file = snapshotPath(snapshotsDir, identity);
|
|
7991
|
-
const raw =
|
|
7996
|
+
const raw = fs16.readFileUtf8(file);
|
|
7992
7997
|
if (raw === void 0) {
|
|
7993
7998
|
return void 0;
|
|
7994
7999
|
}
|
|
@@ -8004,8 +8009,8 @@ function readUsageSnapshot(fs15, snapshotsDir, identity) {
|
|
|
8004
8009
|
}
|
|
8005
8010
|
return snapshot.data;
|
|
8006
8011
|
}
|
|
8007
|
-
function listUsageSnapshots(
|
|
8008
|
-
return
|
|
8012
|
+
function listUsageSnapshots(fs16, snapshotsDir) {
|
|
8013
|
+
return fs16.readdir(snapshotsDir).flatMap((name) => {
|
|
8009
8014
|
if (!name.endsWith(".json")) {
|
|
8010
8015
|
return [];
|
|
8011
8016
|
}
|
|
@@ -8013,7 +8018,7 @@ function listUsageSnapshots(fs15, snapshotsDir) {
|
|
|
8013
8018
|
if (!isIdentityName(identity)) {
|
|
8014
8019
|
return [];
|
|
8015
8020
|
}
|
|
8016
|
-
const snapshot = readUsageSnapshot(
|
|
8021
|
+
const snapshot = readUsageSnapshot(fs16, snapshotsDir, identity);
|
|
8017
8022
|
return snapshot === void 0 ? [] : [snapshot];
|
|
8018
8023
|
}).sort((left, right) => left.identity.localeCompare(right.identity));
|
|
8019
8024
|
}
|
|
@@ -8038,11 +8043,11 @@ var init_read = __esm({
|
|
|
8038
8043
|
|
|
8039
8044
|
// src/usage/store.ts
|
|
8040
8045
|
import path23 from "node:path";
|
|
8041
|
-
function pruneUsageLog(
|
|
8046
|
+
function pruneUsageLog(fs16, logDir, nowMs) {
|
|
8042
8047
|
const cutoff = nowMs - USAGE_RETENTION_MS;
|
|
8043
|
-
for (const segment of listLogSegments(
|
|
8048
|
+
for (const segment of listLogSegments(fs16, logDir)) {
|
|
8044
8049
|
if (segment.endsAt <= cutoff) {
|
|
8045
|
-
|
|
8050
|
+
fs16.removeRecursive(path23.join(logDir, segment.name));
|
|
8046
8051
|
}
|
|
8047
8052
|
}
|
|
8048
8053
|
}
|
|
@@ -8071,7 +8076,7 @@ function foldProviderState(current, record) {
|
|
|
8071
8076
|
};
|
|
8072
8077
|
}
|
|
8073
8078
|
function createUsageStore(deps) {
|
|
8074
|
-
const { fs:
|
|
8079
|
+
const { fs: fs16, paths } = deps;
|
|
8075
8080
|
let prunedDay;
|
|
8076
8081
|
const rewriteSnapshot = (identity, fold) => {
|
|
8077
8082
|
if (!isIdentityName(identity)) {
|
|
@@ -8080,7 +8085,7 @@ function createUsageStore(deps) {
|
|
|
8080
8085
|
}
|
|
8081
8086
|
let current;
|
|
8082
8087
|
try {
|
|
8083
|
-
current = readUsageSnapshot(
|
|
8088
|
+
current = readUsageSnapshot(fs16, paths.usageSnapshotsDir, identity);
|
|
8084
8089
|
} catch (error) {
|
|
8085
8090
|
if (!(error instanceof UsageSnapshotError)) {
|
|
8086
8091
|
throw error;
|
|
@@ -8107,8 +8112,8 @@ function createUsageStore(deps) {
|
|
|
8107
8112
|
...account === void 0 ? {} : { account },
|
|
8108
8113
|
providers
|
|
8109
8114
|
});
|
|
8110
|
-
|
|
8111
|
-
|
|
8115
|
+
fs16.mkdirPrivate(paths.usageSnapshotsDir);
|
|
8116
|
+
fs16.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
|
|
8112
8117
|
`);
|
|
8113
8118
|
deps.publish?.(snapshot);
|
|
8114
8119
|
return true;
|
|
@@ -8117,14 +8122,14 @@ function createUsageStore(deps) {
|
|
|
8117
8122
|
record: (input) => {
|
|
8118
8123
|
const record = UsageRecordSchema.parse(input);
|
|
8119
8124
|
const nowMs = deps.now();
|
|
8120
|
-
|
|
8121
|
-
|
|
8125
|
+
fs16.mkdirPrivate(paths.usageDir);
|
|
8126
|
+
fs16.mkdirPrivate(paths.usageLogDir);
|
|
8122
8127
|
const day = segmentDay(nowMs);
|
|
8123
8128
|
if (prunedDay !== day) {
|
|
8124
|
-
pruneUsageLog(
|
|
8129
|
+
pruneUsageLog(fs16, paths.usageLogDir, nowMs);
|
|
8125
8130
|
prunedDay = day;
|
|
8126
8131
|
}
|
|
8127
|
-
|
|
8132
|
+
fs16.appendFilePrivate(path23.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
|
|
8128
8133
|
`);
|
|
8129
8134
|
deps.onRecord?.(record);
|
|
8130
8135
|
if (record.identity !== void 0) {
|
|
@@ -8168,14 +8173,14 @@ import { z as z17 } from "zod";
|
|
|
8168
8173
|
function errorMessage(error) {
|
|
8169
8174
|
return error instanceof Error ? error.message : String(error);
|
|
8170
8175
|
}
|
|
8171
|
-
function loadPoolMembers(
|
|
8176
|
+
function loadPoolMembers(fs16, paths, identities, nowMs) {
|
|
8172
8177
|
const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
|
|
8173
|
-
const log = readUsageLog(
|
|
8178
|
+
const log = readUsageLog(fs16, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
8174
8179
|
return identities.map((identity) => {
|
|
8175
8180
|
const records = log.records.filter((record) => record.identity === identity && record.provider === ANTHROPIC_PROVIDER && Date.parse(record.at) >= windowStartMs);
|
|
8176
8181
|
try {
|
|
8177
|
-
const snapshot = readUsageSnapshot(
|
|
8178
|
-
const account = readAccountMetadata(
|
|
8182
|
+
const snapshot = readUsageSnapshot(fs16, paths.usageSnapshotsDir, identity);
|
|
8183
|
+
const account = readAccountMetadata(fs16, paths.identitiesDir, identity) ?? snapshot?.account;
|
|
8179
8184
|
return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
|
|
8180
8185
|
} catch (error) {
|
|
8181
8186
|
if (error instanceof UsageSnapshotError || error instanceof AccountMetadataError) {
|
|
@@ -8294,9 +8299,9 @@ function collectPoolIdentities(pools, poolName, stack, found) {
|
|
|
8294
8299
|
collectPoolIdentities(pools, nestedName, childStack, found);
|
|
8295
8300
|
}
|
|
8296
8301
|
}
|
|
8297
|
-
function readPicksFile(
|
|
8302
|
+
function readPicksFile(fs16, file) {
|
|
8298
8303
|
const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
|
|
8299
|
-
const raw =
|
|
8304
|
+
const raw = fs16.readFileUtf8(file);
|
|
8300
8305
|
if (raw === void 0) {
|
|
8301
8306
|
return { file: empty };
|
|
8302
8307
|
}
|
|
@@ -8309,17 +8314,17 @@ function readPicksFile(fs15, file) {
|
|
|
8309
8314
|
const result = PicksFileSchema.safeParse(parsed);
|
|
8310
8315
|
return result.success ? { file: result.data } : { file: empty, problem: `${file} is not a picks file this agent-shim can read` };
|
|
8311
8316
|
}
|
|
8312
|
-
function readStickyPick(
|
|
8313
|
-
const read = readPicksFile(
|
|
8317
|
+
function readStickyPick(fs16, picksFile, directory) {
|
|
8318
|
+
const read = readPicksFile(fs16, picksFile);
|
|
8314
8319
|
const entry = read.file.picks[directory];
|
|
8315
8320
|
return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
|
|
8316
8321
|
}
|
|
8317
|
-
function recordStickyPick(
|
|
8318
|
-
const current = readPicksFile(
|
|
8322
|
+
function recordStickyPick(fs16, picksFile, directory, identity, nowMs) {
|
|
8323
|
+
const current = readPicksFile(fs16, picksFile).file.picks;
|
|
8319
8324
|
const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
|
|
8320
8325
|
const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
|
|
8321
|
-
|
|
8322
|
-
|
|
8326
|
+
fs16.mkdirPrivate(path24.dirname(picksFile));
|
|
8327
|
+
fs16.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
8323
8328
|
`);
|
|
8324
8329
|
}
|
|
8325
8330
|
var PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
@@ -8352,9 +8357,9 @@ var init_poolPick = __esm({
|
|
|
8352
8357
|
|
|
8353
8358
|
// src/statusline/keys.ts
|
|
8354
8359
|
import { z as z18 } from "zod";
|
|
8355
|
-
function valueAt(source,
|
|
8360
|
+
function valueAt(source, path49) {
|
|
8356
8361
|
let current = source;
|
|
8357
|
-
for (const part of
|
|
8362
|
+
for (const part of path49) {
|
|
8358
8363
|
if (!isPlainObject(current)) {
|
|
8359
8364
|
return void 0;
|
|
8360
8365
|
}
|
|
@@ -8362,14 +8367,14 @@ function valueAt(source, path48) {
|
|
|
8362
8367
|
}
|
|
8363
8368
|
return current;
|
|
8364
8369
|
}
|
|
8365
|
-
function acceptsNull(
|
|
8366
|
-
const layer =
|
|
8370
|
+
function acceptsNull(path49) {
|
|
8371
|
+
const layer = path49.reduceRight((inner, part) => ({ [part]: inner }), null);
|
|
8367
8372
|
return StatuslineSchema.safeParse(layer).success;
|
|
8368
8373
|
}
|
|
8369
|
-
function keyOf(
|
|
8374
|
+
function keyOf(path49, declared) {
|
|
8370
8375
|
const optional = declared instanceof z18.ZodOptional;
|
|
8371
8376
|
const leaf = optional ? declared.unwrap() : declared;
|
|
8372
|
-
const common = { path:
|
|
8377
|
+
const common = { path: path49.join("."), description: declared.description ?? "", defaultValue: valueAt(STATUSLINE_DEFAULTS, path49), optional, unsettable: acceptsNull(path49) };
|
|
8373
8378
|
if (leaf instanceof z18.ZodNumber) {
|
|
8374
8379
|
return { ...common, kind: "integer", choices: [] };
|
|
8375
8380
|
}
|
|
@@ -8394,7 +8399,7 @@ function keyOf(path48, declared) {
|
|
|
8394
8399
|
if (leaf instanceof z18.ZodArray && leaf.element instanceof z18.ZodString) {
|
|
8395
8400
|
return { ...common, kind: "textList", choices: [] };
|
|
8396
8401
|
}
|
|
8397
|
-
throw new TypeError(`statusline setting ${
|
|
8402
|
+
throw new TypeError(`statusline setting ${path49.join(".")} has a kind the key listing does not describe`);
|
|
8398
8403
|
}
|
|
8399
8404
|
function walk(shape, prefix) {
|
|
8400
8405
|
return Object.entries(shape).flatMap(([name, schema]) => schema instanceof z18.ZodObject ? walk(schema.shape, [...prefix, name]) : [keyOf([...prefix, name], schema)]);
|
|
@@ -8410,15 +8415,15 @@ var init_keys = __esm({
|
|
|
8410
8415
|
});
|
|
8411
8416
|
|
|
8412
8417
|
// src/statusline/change.ts
|
|
8413
|
-
function keyNamed(
|
|
8414
|
-
const found = statuslineKeys().find((key) => key.path ===
|
|
8418
|
+
function keyNamed(path49) {
|
|
8419
|
+
const found = statuslineKeys().find((key) => key.path === path49);
|
|
8415
8420
|
if (found === void 0) {
|
|
8416
|
-
throw new UsageError(`"${
|
|
8421
|
+
throw new UsageError(`"${path49}" is not a statusline setting; \`agent-shim statusline keys\` lists them.`);
|
|
8417
8422
|
}
|
|
8418
8423
|
return found;
|
|
8419
8424
|
}
|
|
8420
|
-
function setAt(target,
|
|
8421
|
-
const [head, ...rest] =
|
|
8425
|
+
function setAt(target, path49, value) {
|
|
8426
|
+
const [head, ...rest] = path49;
|
|
8422
8427
|
if (head === void 0) {
|
|
8423
8428
|
return;
|
|
8424
8429
|
}
|
|
@@ -8431,8 +8436,8 @@ function setAt(target, path48, value) {
|
|
|
8431
8436
|
target[head] = next;
|
|
8432
8437
|
setAt(next, rest, value);
|
|
8433
8438
|
}
|
|
8434
|
-
function removeAt(target,
|
|
8435
|
-
const [head, ...rest] =
|
|
8439
|
+
function removeAt(target, path49) {
|
|
8440
|
+
const [head, ...rest] = path49;
|
|
8436
8441
|
if (head === void 0) {
|
|
8437
8442
|
return;
|
|
8438
8443
|
}
|
|
@@ -8450,13 +8455,13 @@ function removeAt(target, path48) {
|
|
|
8450
8455
|
}
|
|
8451
8456
|
function applyStatuslineChange(existing, change) {
|
|
8452
8457
|
const draft = structuredClone(existing ?? {});
|
|
8453
|
-
for (const [
|
|
8454
|
-
keyNamed(
|
|
8455
|
-
setAt(draft,
|
|
8458
|
+
for (const [path49, value] of Object.entries(change.set ?? {})) {
|
|
8459
|
+
keyNamed(path49);
|
|
8460
|
+
setAt(draft, path49.split("."), value);
|
|
8456
8461
|
}
|
|
8457
|
-
for (const
|
|
8458
|
-
keyNamed(
|
|
8459
|
-
removeAt(draft,
|
|
8462
|
+
for (const path49 of change.unset ?? []) {
|
|
8463
|
+
keyNamed(path49);
|
|
8464
|
+
removeAt(draft, path49.split("."));
|
|
8460
8465
|
}
|
|
8461
8466
|
const result = StatuslineSchema.safeParse(draft);
|
|
8462
8467
|
if (!result.success) {
|
|
@@ -9835,13 +9840,13 @@ function decideSignIn(facts) {
|
|
|
9835
9840
|
function credentialsFilePath(farmRoot) {
|
|
9836
9841
|
return path27.join(farmRoot, CREDENTIALS_FILE);
|
|
9837
9842
|
}
|
|
9838
|
-
function identitySignIn(
|
|
9843
|
+
function identitySignIn(fs16, probe, identity) {
|
|
9839
9844
|
const probing = !identity.hasCredentialBlock && identity.provider === void 0;
|
|
9840
9845
|
return decideSignIn({
|
|
9841
9846
|
hasCredentialBlock: identity.hasCredentialBlock,
|
|
9842
9847
|
provider: identity.provider,
|
|
9843
9848
|
keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
|
|
9844
|
-
credentialsFile: probing &&
|
|
9849
|
+
credentialsFile: probing && fs16.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
|
|
9845
9850
|
platform: probe.platform
|
|
9846
9851
|
});
|
|
9847
9852
|
}
|
|
@@ -10270,7 +10275,7 @@ var init_modelsStore = __esm({
|
|
|
10270
10275
|
|
|
10271
10276
|
// src/codex/catalogueCredential.ts
|
|
10272
10277
|
import { createHash as createHash7 } from "node:crypto";
|
|
10273
|
-
import
|
|
10278
|
+
import path34 from "node:path";
|
|
10274
10279
|
import { z as z30 } from "zod";
|
|
10275
10280
|
function parseCatalogueBinding(raw) {
|
|
10276
10281
|
if (raw === void 0) return void 0;
|
|
@@ -10304,8 +10309,8 @@ function signInCatalogueFingerprint(raw, filePath) {
|
|
|
10304
10309
|
function savedCatalogueFingerprint(provider, paths, env, home, read) {
|
|
10305
10310
|
if (provider.codex?.login === "chatgpt-sign-in") return signInCatalogueFingerprint(read(paths.chatgptSignInFile), paths.chatgptSignInFile);
|
|
10306
10311
|
const configuredHome = env.CODEX_HOME;
|
|
10307
|
-
const codexHome = configuredHome === void 0 || configuredHome === "" ?
|
|
10308
|
-
return cliCatalogueFingerprint(read(
|
|
10312
|
+
const codexHome = configuredHome === void 0 || configuredHome === "" ? path34.join(home, ".codex") : configuredHome;
|
|
10313
|
+
return cliCatalogueFingerprint(read(path34.join(codexHome, "auth.json")));
|
|
10309
10314
|
}
|
|
10310
10315
|
var CatalogueBindingSchema;
|
|
10311
10316
|
var init_catalogueCredential = __esm({
|
|
@@ -10590,7 +10595,8 @@ function routedModelRows(models, providers) {
|
|
|
10590
10595
|
const hidden = new Set(models.hide ?? []);
|
|
10591
10596
|
const shown = models.show === void 0 ? void 0 : new Set(models.show);
|
|
10592
10597
|
const visible = (model) => shown === void 0 ? !hidden.has(model) : shown.has(model);
|
|
10593
|
-
const
|
|
10598
|
+
const separator = models.pickerLabelSpaces === false ? "/" : " / ";
|
|
10599
|
+
const concrete = providers.flatMap(([name, provider, catalogue]) => providerModelRows(provider, catalogue).map((row) => ({ ...row, model: `${name}/${row.model}`, label: `${name}${separator}${row.label}`, description: `${name}: ${row.description}` })));
|
|
10594
10600
|
const concreteByRef = new Map(concrete.map((row) => [row.model, row]));
|
|
10595
10601
|
const families = buildFamilies([...concrete.map((row) => row.model), ...accountRefsOf(models)], models);
|
|
10596
10602
|
const handlingOf = (refs) => refs.map((ref) => concreteByRef.get(ref)?.behavesAs).find((behavesAs) => behavesAs !== void 0) ?? TIER_BEHAVES_AS.sonnet;
|
|
@@ -11412,16 +11418,16 @@ var init_cliOverride = __esm({
|
|
|
11412
11418
|
});
|
|
11413
11419
|
|
|
11414
11420
|
// src/launcher/launchRecords.ts
|
|
11415
|
-
import
|
|
11421
|
+
import path42 from "node:path";
|
|
11416
11422
|
import { z as z39 } from "zod";
|
|
11417
11423
|
function recordFile(directory, pid, identity) {
|
|
11418
|
-
return
|
|
11424
|
+
return path42.join(directory, `${String(pid)}.${identity}${RECORD_SUFFIX}`);
|
|
11419
11425
|
}
|
|
11420
|
-
function readRecord(
|
|
11426
|
+
function readRecord(fs16, directory, name) {
|
|
11421
11427
|
if (!name.endsWith(RECORD_SUFFIX)) {
|
|
11422
11428
|
return void 0;
|
|
11423
11429
|
}
|
|
11424
|
-
const raw =
|
|
11430
|
+
const raw = fs16.readFileUtf8(path42.join(directory, name));
|
|
11425
11431
|
if (raw === void 0) {
|
|
11426
11432
|
return void 0;
|
|
11427
11433
|
}
|
|
@@ -11434,20 +11440,20 @@ function readRecord(fs15, directory, name) {
|
|
|
11434
11440
|
const result = LaunchRecordSchema.safeParse(parsed);
|
|
11435
11441
|
return result.success ? result.data : void 0;
|
|
11436
11442
|
}
|
|
11437
|
-
function registerLaunch(
|
|
11438
|
-
|
|
11439
|
-
for (const name of
|
|
11440
|
-
const record2 = readRecord(
|
|
11443
|
+
function registerLaunch(fs16, directory, owner, isRunning) {
|
|
11444
|
+
fs16.mkdirPrivate(directory);
|
|
11445
|
+
for (const name of fs16.readdir(directory)) {
|
|
11446
|
+
const record2 = readRecord(fs16, directory, name);
|
|
11441
11447
|
if (record2 !== void 0 && !isRunning(record2.pid)) {
|
|
11442
|
-
|
|
11448
|
+
fs16.removeRecursive(path42.join(directory, name));
|
|
11443
11449
|
}
|
|
11444
11450
|
}
|
|
11445
11451
|
const file = recordFile(directory, owner.pid, owner.identity);
|
|
11446
11452
|
const record = { pid: owner.pid, identity: owner.identity, startedAt: new Date(owner.startedAtMs).toISOString() };
|
|
11447
|
-
|
|
11453
|
+
fs16.writeFilePrivate(file, `${JSON.stringify(record)}
|
|
11448
11454
|
`);
|
|
11449
11455
|
return () => {
|
|
11450
|
-
|
|
11456
|
+
fs16.removeRecursive(file);
|
|
11451
11457
|
};
|
|
11452
11458
|
}
|
|
11453
11459
|
var LaunchRecordSchema, RECORD_SUFFIX;
|
|
@@ -11532,7 +11538,7 @@ var init_settings2 = __esm({
|
|
|
11532
11538
|
});
|
|
11533
11539
|
|
|
11534
11540
|
// src/launcher/flags.ts
|
|
11535
|
-
import
|
|
11541
|
+
import path43 from "node:path";
|
|
11536
11542
|
function resolveLaunchFlags(params) {
|
|
11537
11543
|
const statusline = resolveStatuslineSettings(params);
|
|
11538
11544
|
return {
|
|
@@ -11588,7 +11594,7 @@ function buildEnv(params) {
|
|
|
11588
11594
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
11589
11595
|
let providerCustomHeaders;
|
|
11590
11596
|
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
11591
|
-
env.CLAUDE_CONFIG_DIR =
|
|
11597
|
+
env.CLAUDE_CONFIG_DIR = path43.join(params.identitiesDir, params.resolvedIdentityName);
|
|
11592
11598
|
}
|
|
11593
11599
|
if (params.provider !== void 0) {
|
|
11594
11600
|
const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
|
|
@@ -11680,7 +11686,7 @@ var init_extraFlags = __esm({
|
|
|
11680
11686
|
});
|
|
11681
11687
|
|
|
11682
11688
|
// src/usage/resumeContext.ts
|
|
11683
|
-
import
|
|
11689
|
+
import path44 from "node:path";
|
|
11684
11690
|
function projectDirNameOf(cwd) {
|
|
11685
11691
|
return cwd.replace(/[^A-Za-z0-9]/g, "-");
|
|
11686
11692
|
}
|
|
@@ -11731,15 +11737,15 @@ function contextTokensOfTranscript(text) {
|
|
|
11731
11737
|
}
|
|
11732
11738
|
return void 0;
|
|
11733
11739
|
}
|
|
11734
|
-
function newestTranscript(
|
|
11740
|
+
function newestTranscript(fs16, projectDir) {
|
|
11735
11741
|
let newest;
|
|
11736
11742
|
let newestMs = -Infinity;
|
|
11737
|
-
for (const name of
|
|
11743
|
+
for (const name of fs16.readdir(projectDir)) {
|
|
11738
11744
|
if (!name.endsWith(".jsonl")) {
|
|
11739
11745
|
continue;
|
|
11740
11746
|
}
|
|
11741
|
-
const candidate =
|
|
11742
|
-
const stat =
|
|
11747
|
+
const candidate = path44.join(projectDir, name);
|
|
11748
|
+
const stat = fs16.lstat(candidate);
|
|
11743
11749
|
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
11744
11750
|
newestMs = stat.mtimeMs;
|
|
11745
11751
|
newest = candidate;
|
|
@@ -11747,14 +11753,14 @@ function newestTranscript(fs15, projectDir) {
|
|
|
11747
11753
|
}
|
|
11748
11754
|
return newest;
|
|
11749
11755
|
}
|
|
11750
|
-
function resumedContextTokens(
|
|
11756
|
+
function resumedContextTokens(fs16, params) {
|
|
11751
11757
|
const target = resumeTargetOf(params.passthrough);
|
|
11752
11758
|
if (target === void 0) {
|
|
11753
11759
|
return void 0;
|
|
11754
11760
|
}
|
|
11755
|
-
const projectDir =
|
|
11756
|
-
const file = target.kind === "id" ?
|
|
11757
|
-
const text = file === void 0 ? void 0 :
|
|
11761
|
+
const projectDir = path44.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
11762
|
+
const file = target.kind === "id" ? path44.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs16, projectDir);
|
|
11763
|
+
const text = file === void 0 ? void 0 : fs16.readFileUtf8(file);
|
|
11758
11764
|
return text === void 0 ? void 0 : contextTokensOfTranscript(text);
|
|
11759
11765
|
}
|
|
11760
11766
|
var init_resumeContext = __esm({
|
|
@@ -12351,7 +12357,7 @@ var init_launchHook = __esm({
|
|
|
12351
12357
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
12352
12358
|
import os9 from "node:os";
|
|
12353
12359
|
import { isDeepStrictEqual } from "node:util";
|
|
12354
|
-
import
|
|
12360
|
+
import path45 from "node:path";
|
|
12355
12361
|
function resolveIdentityCredential(identity, credential, env, port) {
|
|
12356
12362
|
if (port === void 0) {
|
|
12357
12363
|
return { ok: false, status: 1, message: `agent-shim: identity ${identity} needs its credential resolved, but this launcher has no credential port wired` };
|
|
@@ -12360,7 +12366,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
|
|
|
12360
12366
|
return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
|
|
12361
12367
|
}
|
|
12362
12368
|
function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
12363
|
-
const { paths, fs:
|
|
12369
|
+
const { paths, fs: fs16, proc, log } = params;
|
|
12364
12370
|
if (decided.pool === void 0) {
|
|
12365
12371
|
return { identityDecision: decided };
|
|
12366
12372
|
}
|
|
@@ -12379,7 +12385,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
12379
12385
|
selectedVia: decided.source,
|
|
12380
12386
|
pools: params.pools,
|
|
12381
12387
|
paths,
|
|
12382
|
-
fs:
|
|
12388
|
+
fs: fs16,
|
|
12383
12389
|
usageFs: farmRuntime.fs,
|
|
12384
12390
|
cwd: farmRuntime.cwd,
|
|
12385
12391
|
now: farmRuntime.now,
|
|
@@ -12403,7 +12409,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
12403
12409
|
};
|
|
12404
12410
|
}
|
|
12405
12411
|
function decideLaunch(params, readOnly) {
|
|
12406
|
-
const { paths, fs:
|
|
12412
|
+
const { paths, fs: fs16, proc, log } = params;
|
|
12407
12413
|
const { env, argv } = proc;
|
|
12408
12414
|
const parsedArgv = parseLauncherArgv(argv);
|
|
12409
12415
|
const cliOverride = buildCliOverride({
|
|
@@ -12418,7 +12424,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12418
12424
|
argv0Identity: params.pickedIdentity ?? parsedArgv.identity,
|
|
12419
12425
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
12420
12426
|
readActiveIdentityFile: () => {
|
|
12421
|
-
const raw =
|
|
12427
|
+
const raw = fs16.readFileUtf8(paths.activeIdentityFile);
|
|
12422
12428
|
if (raw === void 0) {
|
|
12423
12429
|
return void 0;
|
|
12424
12430
|
}
|
|
@@ -12453,7 +12459,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12453
12459
|
}
|
|
12454
12460
|
let loadedIdentity;
|
|
12455
12461
|
if (identityDecision.name !== void 0) {
|
|
12456
|
-
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name,
|
|
12462
|
+
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs16);
|
|
12457
12463
|
if (loadedIdentity === void 0) {
|
|
12458
12464
|
log.error(
|
|
12459
12465
|
`agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
|
|
@@ -12468,7 +12474,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12468
12474
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
12469
12475
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
12470
12476
|
});
|
|
12471
|
-
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true &&
|
|
12477
|
+
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs16.readConfigFile(profileFilePath(paths.configProfilesDir, configProfileDecision.name, `the configuration profile selected via ${configProfileDecision.source}`)) === void 0) {
|
|
12472
12478
|
log.error(
|
|
12473
12479
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
12474
12480
|
);
|
|
@@ -12477,7 +12483,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12477
12483
|
const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
|
|
12478
12484
|
const providerParams = {
|
|
12479
12485
|
paths,
|
|
12480
|
-
port:
|
|
12486
|
+
port: fs16,
|
|
12481
12487
|
...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
|
|
12482
12488
|
...farmContext === void 0 ? {} : { cascade: farmContext.cascade },
|
|
12483
12489
|
...loadedIdentity?.config.provider === void 0 ? {} : { identityProvider: loadedIdentity.config.provider }
|
|
@@ -12598,9 +12604,9 @@ function decideLaunch(params, readOnly) {
|
|
|
12598
12604
|
const doorRecord = doorPid === void 0 ? void 0 : readFrontDoorCodexRecord(params.fs, paths.frontdoorDir, doorPid);
|
|
12599
12605
|
const doorHome = doorRecord?.codexHome;
|
|
12600
12606
|
const catalogueEnv = doorHome === void 0 ? proc.env : { ...proc.env, CODEX_HOME: doorHome };
|
|
12601
|
-
const listedProviders = listProviderNames(
|
|
12607
|
+
const listedProviders = listProviderNames(fs16.readdir, paths.providersDir).flatMap((name) => {
|
|
12602
12608
|
try {
|
|
12603
|
-
const definition = loadProvider(paths.providersDir, name,
|
|
12609
|
+
const definition = loadProvider(paths.providersDir, name, fs16);
|
|
12604
12610
|
if (definition === void 0) return [];
|
|
12605
12611
|
const catalogueOwner = definition.kind === "codex" ? doorPid : void 0;
|
|
12606
12612
|
const generation = definition.kind === "codex" ? doorRecord?.generation : void 0;
|
|
@@ -12610,8 +12616,8 @@ function decideLaunch(params, readOnly) {
|
|
|
12610
12616
|
if (definition.kind === "codex" && readOnly && cache !== void 0) {
|
|
12611
12617
|
const binding = parseCatalogueBinding(params.fs.readFileUtf8(catalogueBindingPath(paths, name, catalogueOwner, generation)));
|
|
12612
12618
|
const configuredHome = catalogueEnv.CODEX_HOME;
|
|
12613
|
-
const home = configuredHome === void 0 || configuredHome === "" ?
|
|
12614
|
-
const source = definition.codex?.login === "chatgpt-sign-in" ? paths.chatgptSignInFile :
|
|
12619
|
+
const home = configuredHome === void 0 || configuredHome === "" ? path45.join(os9.homedir(), ".codex") : configuredHome;
|
|
12620
|
+
const source = definition.codex?.login === "chatgpt-sign-in" ? paths.chatgptSignInFile : path45.resolve(home, "auth.json");
|
|
12615
12621
|
const revision = params.fs.fileRevision?.(source);
|
|
12616
12622
|
if (binding === void 0 || binding.fingerprint !== cache.credentialFingerprint || binding.source !== source || revision === void 0 || revision !== binding.revision) return [];
|
|
12617
12623
|
}
|
|
@@ -12632,7 +12638,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12632
12638
|
return { args: args2, pickerSuppressed: startsSession && pickerSettings !== void 0 && callerSettings };
|
|
12633
12639
|
};
|
|
12634
12640
|
const args = argsForSupervisor().args;
|
|
12635
|
-
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR :
|
|
12641
|
+
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : path45.join(paths.identitiesDir, identityDecision.name);
|
|
12636
12642
|
const decision = {
|
|
12637
12643
|
identitySource: identityDecision.source,
|
|
12638
12644
|
configDirEscapeHatch: identityDecision.configDirEscapeHatch,
|
|
@@ -12707,7 +12713,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
|
|
|
12707
12713
|
let unregisterLaunch;
|
|
12708
12714
|
const updateCheck = runLaunchUpdateCheck({
|
|
12709
12715
|
mode: params.updateMode ?? "off",
|
|
12710
|
-
checkPath:
|
|
12716
|
+
checkPath: path45.join(paths.root, "update.check"),
|
|
12711
12717
|
currentVersion: package_default.version,
|
|
12712
12718
|
port: params.update
|
|
12713
12719
|
});
|
|
@@ -12918,12 +12924,12 @@ var init_launcher = __esm({
|
|
|
12918
12924
|
});
|
|
12919
12925
|
|
|
12920
12926
|
// src/ownCli.ts
|
|
12921
|
-
import
|
|
12927
|
+
import path46 from "node:path";
|
|
12922
12928
|
function agentShimCliPath(distDir = typeof __AGENT_SHIM_DIST_DIR__ === "string" ? __AGENT_SHIM_DIST_DIR__ : void 0) {
|
|
12923
12929
|
if (distDir === void 0) {
|
|
12924
12930
|
throw new OwnCliPathUnknownError();
|
|
12925
12931
|
}
|
|
12926
|
-
return
|
|
12932
|
+
return path46.join(distDir, OWN_CLI_FILE_NAME);
|
|
12927
12933
|
}
|
|
12928
12934
|
var OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
|
|
12929
12935
|
var init_ownCli = __esm({
|
|
@@ -12951,10 +12957,10 @@ var init_childRun = __esm({
|
|
|
12951
12957
|
});
|
|
12952
12958
|
|
|
12953
12959
|
// src/frontdoor/doorLog.ts
|
|
12954
|
-
import
|
|
12960
|
+
import fs14 from "node:fs";
|
|
12955
12961
|
function appendDoorLog(paths, line) {
|
|
12956
|
-
|
|
12957
|
-
|
|
12962
|
+
fs14.mkdirSync(paths.logsDir, { recursive: true });
|
|
12963
|
+
fs14.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
12958
12964
|
`);
|
|
12959
12965
|
}
|
|
12960
12966
|
var init_doorLog = __esm({
|
|
@@ -12979,16 +12985,16 @@ var init_selfIdentity = __esm({
|
|
|
12979
12985
|
|
|
12980
12986
|
// src/frontdoor/trust.ts
|
|
12981
12987
|
import { createHash as createHash8 } from "node:crypto";
|
|
12982
|
-
import
|
|
12988
|
+
import path47 from "node:path";
|
|
12983
12989
|
function resolveTrustBundle(params) {
|
|
12984
|
-
const { caCertFile, bundlesDir, variable, inherited, fs:
|
|
12985
|
-
if (inherited === void 0 || inherited === "" ||
|
|
12990
|
+
const { caCertFile, bundlesDir, variable, inherited, fs: fs16 } = params;
|
|
12991
|
+
if (inherited === void 0 || inherited === "" || path47.resolve(inherited) === path47.resolve(caCertFile)) {
|
|
12986
12992
|
return { path: caCertFile };
|
|
12987
12993
|
}
|
|
12988
|
-
const caPem =
|
|
12994
|
+
const caPem = fs16.readFileUtf8(caCertFile);
|
|
12989
12995
|
let inheritedPem;
|
|
12990
12996
|
try {
|
|
12991
|
-
inheritedPem =
|
|
12997
|
+
inheritedPem = fs16.readFileUtf8(inherited);
|
|
12992
12998
|
} catch (error) {
|
|
12993
12999
|
return {
|
|
12994
13000
|
path: caCertFile,
|
|
@@ -13000,10 +13006,10 @@ function resolveTrustBundle(params) {
|
|
|
13000
13006
|
}
|
|
13001
13007
|
const combined = `${inheritedPem.trimEnd()}
|
|
13002
13008
|
${caPem}`;
|
|
13003
|
-
const bundle =
|
|
13004
|
-
if (!
|
|
13005
|
-
|
|
13006
|
-
|
|
13009
|
+
const bundle = path47.join(bundlesDir, `${createHash8("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
13010
|
+
if (!fs16.exists(bundle)) {
|
|
13011
|
+
fs16.mkdirp(bundlesDir);
|
|
13012
|
+
fs16.writeFileAtomic(bundle, combined);
|
|
13007
13013
|
}
|
|
13008
13014
|
return { path: bundle };
|
|
13009
13015
|
}
|
|
@@ -13016,7 +13022,7 @@ var init_trust = __esm({
|
|
|
13016
13022
|
});
|
|
13017
13023
|
|
|
13018
13024
|
// src/frontdoor/realFrontDoorPort.ts
|
|
13019
|
-
import
|
|
13025
|
+
import fs15 from "node:fs";
|
|
13020
13026
|
import os10 from "node:os";
|
|
13021
13027
|
function realEnsurePorts(paths, spawnDaemon) {
|
|
13022
13028
|
return {
|
|
@@ -13043,7 +13049,7 @@ function realEnsurePorts(paths, spawnDaemon) {
|
|
|
13043
13049
|
}
|
|
13044
13050
|
},
|
|
13045
13051
|
// 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.
|
|
13046
|
-
verifyListener: (port) => probeFrontDoorSync(port,
|
|
13052
|
+
verifyListener: (port) => probeFrontDoorSync(port, fs15.readFileSync(paths.frontdoorCaCertFile, "utf8"))
|
|
13047
13053
|
};
|
|
13048
13054
|
}
|
|
13049
13055
|
function realFrontDoorPort(paths, spawnDaemon) {
|
|
@@ -13130,10 +13136,10 @@ var init_realFrontDoorPort = __esm({
|
|
|
13130
13136
|
init_selfIdentity();
|
|
13131
13137
|
init_trust();
|
|
13132
13138
|
realTrustBundleFs = {
|
|
13133
|
-
readFileUtf8: (file) =>
|
|
13134
|
-
exists: (file) =>
|
|
13139
|
+
readFileUtf8: (file) => fs15.readFileSync(file, "utf8"),
|
|
13140
|
+
exists: (file) => fs15.existsSync(file),
|
|
13135
13141
|
mkdirp: (dir) => {
|
|
13136
|
-
|
|
13142
|
+
fs15.mkdirSync(dir, { recursive: true });
|
|
13137
13143
|
},
|
|
13138
13144
|
writeFileAtomic: (file, contents) => {
|
|
13139
13145
|
realFarmFs.writeFilePrivate(file, contents);
|
|
@@ -13144,7 +13150,7 @@ var init_realFrontDoorPort = __esm({
|
|
|
13144
13150
|
|
|
13145
13151
|
// src/launchWiring.ts
|
|
13146
13152
|
import os11 from "node:os";
|
|
13147
|
-
import
|
|
13153
|
+
import path48 from "node:path";
|
|
13148
13154
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
13149
13155
|
function buildFarmRuntime(paths, cwd, run = realRunPort) {
|
|
13150
13156
|
const home = os11.homedir();
|
|
@@ -13199,7 +13205,7 @@ function realPrepareLaunchParams(paths, options) {
|
|
|
13199
13205
|
frontdoor: realFrontDoorPort(paths, options.spawnDaemon),
|
|
13200
13206
|
credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
|
|
13201
13207
|
hold: realHoldPort,
|
|
13202
|
-
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot:
|
|
13208
|
+
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: path48.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
|
|
13203
13209
|
...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
|
|
13204
13210
|
...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
|
|
13205
13211
|
...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },
|
|
@@ -13935,8 +13941,8 @@ function pathnameOf(url) {
|
|
|
13935
13941
|
return new URL(url ?? "/", "http://127.0.0.1").pathname;
|
|
13936
13942
|
}
|
|
13937
13943
|
function isRcSessionExchange(url) {
|
|
13938
|
-
const
|
|
13939
|
-
return
|
|
13944
|
+
const path49 = pathnameOf(url);
|
|
13945
|
+
return path49 === RC_SESSIONS_PATH_PREFIX || path49.startsWith(`${RC_SESSIONS_PATH_PREFIX}/`);
|
|
13940
13946
|
}
|
|
13941
13947
|
var RC_SESSION_ID_PREFIX = "cse_";
|
|
13942
13948
|
var RC_IDLE_EXPIRY_MS = 45e3;
|
|
@@ -14495,8 +14501,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
|
|
|
14495
14501
|
function isRcReadFileEncoding(value) {
|
|
14496
14502
|
return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value);
|
|
14497
14503
|
}
|
|
14498
|
-
function buildRcReadFilePayload(requestId,
|
|
14499
|
-
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path:
|
|
14504
|
+
function buildRcReadFilePayload(requestId, path49, options) {
|
|
14505
|
+
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path49, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
|
|
14500
14506
|
}
|
|
14501
14507
|
function buildRcFileSuggestionsPayload(requestId, query) {
|
|
14502
14508
|
return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
|
|
@@ -14598,15 +14604,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
|
|
|
14598
14604
|
const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
|
|
14599
14605
|
return result.ok ? { ...result, requestId } : result;
|
|
14600
14606
|
}
|
|
14601
|
-
async function readRcSessionFile(deps, sessionId,
|
|
14602
|
-
if (
|
|
14607
|
+
async function readRcSessionFile(deps, sessionId, path49, options) {
|
|
14608
|
+
if (path49 === "") {
|
|
14603
14609
|
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" };
|
|
14604
14610
|
}
|
|
14605
14611
|
if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
|
|
14606
14612
|
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" };
|
|
14607
14613
|
}
|
|
14608
14614
|
const requestId = deps.newUuid();
|
|
14609
|
-
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId,
|
|
14615
|
+
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path49, options), `read ${path49} from session ${sessionId}`);
|
|
14610
14616
|
return result.ok ? { ...result, requestId } : result;
|
|
14611
14617
|
}
|
|
14612
14618
|
async function suggestRcSessionFiles(deps, sessionId, query) {
|
|
@@ -14775,11 +14781,11 @@ function createRcControlHandler(deps) {
|
|
|
14775
14781
|
path: "read-file",
|
|
14776
14782
|
read: (body) => {
|
|
14777
14783
|
const session = bodyString(body, "session");
|
|
14778
|
-
const
|
|
14784
|
+
const path49 = bodyString(body, "path");
|
|
14779
14785
|
const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
|
|
14780
14786
|
const encoding = "encoding" in body && isRcReadFileEncoding(body.encoding) ? body.encoding : void 0;
|
|
14781
|
-
const refused2 = session === void 0 ||
|
|
14782
|
-
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,
|
|
14787
|
+
const refused2 = session === void 0 || path49 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
|
|
14788
|
+
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, path49, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
|
|
14783
14789
|
}
|
|
14784
14790
|
},
|
|
14785
14791
|
{
|
|
@@ -15089,9 +15095,9 @@ function requestIdOfBody(body) {
|
|
|
15089
15095
|
}
|
|
15090
15096
|
function frontDoorRcControl(transport, token) {
|
|
15091
15097
|
const headers = { authorization: `Bearer ${token}` };
|
|
15092
|
-
const listAnswerOf = async (
|
|
15098
|
+
const listAnswerOf = async (path49, what) => {
|
|
15093
15099
|
try {
|
|
15094
|
-
return await transport.request({ method: "GET", path:
|
|
15100
|
+
return await transport.request({ method: "GET", path: path49, headers });
|
|
15095
15101
|
} catch (error) {
|
|
15096
15102
|
throw new Error(`${what}: could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
15097
15103
|
}
|
|
@@ -15163,10 +15169,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15163
15169
|
}
|
|
15164
15170
|
return pending;
|
|
15165
15171
|
};
|
|
15166
|
-
const writeOf = async (
|
|
15172
|
+
const writeOf = async (path49, body, describeFailure2) => {
|
|
15167
15173
|
let answer;
|
|
15168
15174
|
try {
|
|
15169
|
-
answer = await transport.request({ method: "POST", path:
|
|
15175
|
+
answer = await transport.request({ method: "POST", path: path49, headers: { ...headers, "content-type": "application/json" }, body });
|
|
15170
15176
|
} catch (error) {
|
|
15171
15177
|
return { ok: false, message: `could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}` };
|
|
15172
15178
|
}
|
|
@@ -15197,10 +15203,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15197
15203
|
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}`),
|
|
15198
15204
|
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}`),
|
|
15199
15205
|
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}`),
|
|
15200
|
-
readFile: async (sessionId,
|
|
15206
|
+
readFile: async (sessionId, path49, options) => await writeOf(
|
|
15201
15207
|
`${CONTROL_PATH_PREFIX}/read-file`,
|
|
15202
|
-
JSON.stringify({ session: sessionId, path:
|
|
15203
|
-
(status, message) => `reading ${
|
|
15208
|
+
JSON.stringify({ session: sessionId, path: path49, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
|
|
15209
|
+
(status, message) => `reading ${path49} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
15204
15210
|
),
|
|
15205
15211
|
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}`),
|
|
15206
15212
|
keepAlive: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/keep-alive`, JSON.stringify({ session: sessionId }), (status, message) => `keeping ${sessionId} alive failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -15359,12 +15365,12 @@ function tlsFacts(options) {
|
|
|
15359
15365
|
}
|
|
15360
15366
|
function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15361
15367
|
const agent = new ExemptTlsAgent();
|
|
15362
|
-
const post = async (
|
|
15368
|
+
const post = async (path49, headers, body) => await new Promise((resolve, reject) => {
|
|
15363
15369
|
const options = {
|
|
15364
15370
|
host: target.host,
|
|
15365
15371
|
port: target.port,
|
|
15366
15372
|
method: "POST",
|
|
15367
|
-
path:
|
|
15373
|
+
path: path49,
|
|
15368
15374
|
// 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.
|
|
15369
15375
|
headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
|
|
15370
15376
|
agent
|
|
@@ -15429,12 +15435,12 @@ function lateRcStreamDial(resolve) {
|
|
|
15429
15435
|
}
|
|
15430
15436
|
function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15431
15437
|
const agent = new ExemptTlsAgent();
|
|
15432
|
-
const request4 = async (method,
|
|
15438
|
+
const request4 = async (method, path49, headers, body, signal) => await new Promise((resolve, reject) => {
|
|
15433
15439
|
const options = {
|
|
15434
15440
|
host: target.host,
|
|
15435
15441
|
port: target.port,
|
|
15436
15442
|
method,
|
|
15437
|
-
path:
|
|
15443
|
+
path: path49,
|
|
15438
15444
|
// 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.
|
|
15439
15445
|
headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
|
|
15440
15446
|
agent,
|
|
@@ -15476,9 +15482,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
|
|
|
15476
15482
|
return { status, body: await readAll(response) };
|
|
15477
15483
|
},
|
|
15478
15484
|
openStream: async (sessionId, headers, resume, signal) => {
|
|
15479
|
-
const
|
|
15485
|
+
const path49 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
|
|
15480
15486
|
const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
|
|
15481
|
-
const { status, response } = await request4("GET",
|
|
15487
|
+
const { status, response } = await request4("GET", path49, streamHeaders, void 0, signal);
|
|
15482
15488
|
if (!isSuccessful2(status)) {
|
|
15483
15489
|
await readAll(response);
|
|
15484
15490
|
return { status, chunks: NO_CHUNKS };
|
|
@@ -15728,11 +15734,11 @@ function credentialOfJson(parsed) {
|
|
|
15728
15734
|
function sequenceNumOfJson(value) {
|
|
15729
15735
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
15730
15736
|
}
|
|
15731
|
-
function createRcCredentialStore(
|
|
15732
|
-
|
|
15737
|
+
function createRcCredentialStore(fs16, dir) {
|
|
15738
|
+
fs16.mkdirPrivate(dir);
|
|
15733
15739
|
const fileFor = (sessionId) => path13.join(dir, `${sessionId}.json`);
|
|
15734
15740
|
const readParsed = (sessionId) => {
|
|
15735
|
-
const raw =
|
|
15741
|
+
const raw = fs16.readFileUtf8(fileFor(sessionId));
|
|
15736
15742
|
if (raw === void 0) {
|
|
15737
15743
|
return void 0;
|
|
15738
15744
|
}
|
|
@@ -15757,7 +15763,7 @@ function createRcCredentialStore(fs15, dir) {
|
|
|
15757
15763
|
}
|
|
15758
15764
|
const cursor = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
|
|
15759
15765
|
const record = { ...credential, ...cursor === void 0 ? {} : { highestSequenceNum: cursor } };
|
|
15760
|
-
|
|
15766
|
+
fs16.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
15761
15767
|
`);
|
|
15762
15768
|
},
|
|
15763
15769
|
readCursor: (sessionId) => {
|
|
@@ -15772,14 +15778,14 @@ function createRcCredentialStore(fs15, dir) {
|
|
|
15772
15778
|
}
|
|
15773
15779
|
const credential = credentialOfJson(readParsed(sessionId));
|
|
15774
15780
|
const record = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
|
|
15775
|
-
|
|
15781
|
+
fs16.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
15776
15782
|
`);
|
|
15777
15783
|
},
|
|
15778
15784
|
remove: (sessionId) => {
|
|
15779
15785
|
if (!isSafeSessionId(sessionId)) {
|
|
15780
15786
|
return;
|
|
15781
15787
|
}
|
|
15782
|
-
|
|
15788
|
+
fs16.removeRecursive(fileFor(sessionId));
|
|
15783
15789
|
}
|
|
15784
15790
|
};
|
|
15785
15791
|
}
|
|
@@ -16471,19 +16477,19 @@ function writePools(paths, pools) {
|
|
|
16471
16477
|
applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
|
|
16472
16478
|
}
|
|
16473
16479
|
function poolCycleOf(pools, name) {
|
|
16474
|
-
const walk2 = (current,
|
|
16480
|
+
const walk2 = (current, path49) => {
|
|
16475
16481
|
for (const entry of pools[current]?.identities ?? []) {
|
|
16476
16482
|
const nested = poolNameOf(poolMemberIdentity(entry));
|
|
16477
16483
|
if (nested === void 0) {
|
|
16478
16484
|
continue;
|
|
16479
16485
|
}
|
|
16480
16486
|
if (nested === name) {
|
|
16481
|
-
return [...
|
|
16487
|
+
return [...path49, nested];
|
|
16482
16488
|
}
|
|
16483
|
-
if (
|
|
16489
|
+
if (path49.includes(nested)) {
|
|
16484
16490
|
continue;
|
|
16485
16491
|
}
|
|
16486
|
-
const found = walk2(nested, [...
|
|
16492
|
+
const found = walk2(nested, [...path49, nested]);
|
|
16487
16493
|
if (found !== void 0) {
|
|
16488
16494
|
return found;
|
|
16489
16495
|
}
|
|
@@ -17195,7 +17201,7 @@ var ResetRowSchema = z24.strictObject({
|
|
|
17195
17201
|
var ResetScheduleSchema = z24.strictObject({ resets: z24.readonly(z24.array(ResetRowSchema)) });
|
|
17196
17202
|
|
|
17197
17203
|
// src/frontdoor/controlSchemas.ts
|
|
17198
|
-
import
|
|
17204
|
+
import path36 from "node:path";
|
|
17199
17205
|
import { z as z32 } from "zod";
|
|
17200
17206
|
|
|
17201
17207
|
// src/doctorReport.ts
|
|
@@ -17244,8 +17250,8 @@ var RenameJournalUnreadableError = class extends CliError {
|
|
|
17244
17250
|
}
|
|
17245
17251
|
detail;
|
|
17246
17252
|
};
|
|
17247
|
-
function readRenameJournal(
|
|
17248
|
-
const raw =
|
|
17253
|
+
function readRenameJournal(fs16, file) {
|
|
17254
|
+
const raw = fs16.readFileUtf8(file);
|
|
17249
17255
|
if (raw === void 0) {
|
|
17250
17256
|
return void 0;
|
|
17251
17257
|
}
|
|
@@ -17261,16 +17267,16 @@ function readRenameJournal(fs15, file) {
|
|
|
17261
17267
|
}
|
|
17262
17268
|
return result.data;
|
|
17263
17269
|
}
|
|
17264
|
-
function listRenameJournals(
|
|
17270
|
+
function listRenameJournals(fs16, directory) {
|
|
17265
17271
|
const journals = [];
|
|
17266
17272
|
const unreadable = [];
|
|
17267
|
-
for (const name of [...
|
|
17273
|
+
for (const name of [...fs16.readdir(directory)].sort()) {
|
|
17268
17274
|
if (!name.endsWith(JOURNAL_SUFFIX)) {
|
|
17269
17275
|
continue;
|
|
17270
17276
|
}
|
|
17271
17277
|
const file = path30.join(directory, name);
|
|
17272
17278
|
try {
|
|
17273
|
-
const journal = readRenameJournal(
|
|
17279
|
+
const journal = readRenameJournal(fs16, file);
|
|
17274
17280
|
if (journal !== void 0) {
|
|
17275
17281
|
journals.push(journal);
|
|
17276
17282
|
}
|
|
@@ -17313,8 +17319,8 @@ var NameHeldByUnfinishedRenameError = class extends CliError {
|
|
|
17313
17319
|
this.name = "NameHeldByUnfinishedRenameError";
|
|
17314
17320
|
}
|
|
17315
17321
|
};
|
|
17316
|
-
function requireNameFreeOfUnfinishedRename(
|
|
17317
|
-
const held = listRenameJournals(
|
|
17322
|
+
function requireNameFreeOfUnfinishedRename(fs16, directory, name, action, sameName, exists) {
|
|
17323
|
+
const held = listRenameJournals(fs16, directory).journals.find((journal) => [journal.from, journal.to].some((heldName) => heldName === name || sameName(name, heldName)));
|
|
17318
17324
|
if (held !== void 0) {
|
|
17319
17325
|
throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
|
|
17320
17326
|
}
|
|
@@ -17664,8 +17670,46 @@ function removeIdentity(paths, name) {
|
|
|
17664
17670
|
|
|
17665
17671
|
// src/doctorReport.ts
|
|
17666
17672
|
init_realPorts();
|
|
17667
|
-
import
|
|
17668
|
-
|
|
17673
|
+
import fs13 from "node:fs";
|
|
17674
|
+
|
|
17675
|
+
// src/doctorPath.ts
|
|
17676
|
+
init_blockingSpawn();
|
|
17677
|
+
init_realPorts();
|
|
17678
|
+
import fs11 from "node:fs";
|
|
17679
|
+
import path33 from "node:path";
|
|
17680
|
+
function realpathOrSelf(target) {
|
|
17681
|
+
try {
|
|
17682
|
+
return fs11.realpathSync(target);
|
|
17683
|
+
} catch {
|
|
17684
|
+
return target;
|
|
17685
|
+
}
|
|
17686
|
+
}
|
|
17687
|
+
var MAX_FORWARDING_SCRIPT_BYTES = 8192;
|
|
17688
|
+
function resolveMiseDispatcher(target, pathDirs, env, trustedExecutable) {
|
|
17689
|
+
const executable = realpathOrSelf(target);
|
|
17690
|
+
const trustedMise = path33.join(path33.dirname(trustedExecutable), "mise");
|
|
17691
|
+
if (path33.basename(executable) !== "mise" || realpathOrSelf(trustedMise) !== executable) return void 0;
|
|
17692
|
+
const result = spawnSyncBlocking("a mise shim lookup", executable, ["which", path33.basename(target)], { encoding: "utf8", env });
|
|
17693
|
+
if (result.error !== void 0) return void 0;
|
|
17694
|
+
if (result.status === 0 && result.stdout.trim() !== "") return result.stdout.trim();
|
|
17695
|
+
if (!result.stderr.includes("not currently active")) return void 0;
|
|
17696
|
+
for (const dir of pathDirs) {
|
|
17697
|
+
const candidate = findExecutableInDir(dir, path33.basename(target));
|
|
17698
|
+
if (candidate !== void 0 && realpathOrSelf(candidate) !== executable) {
|
|
17699
|
+
try {
|
|
17700
|
+
const script = fs11.statSync(candidate).size <= MAX_FORWARDING_SCRIPT_BYTES ? realFsPort.readFileUtf8(candidate) : void 0;
|
|
17701
|
+
const forwarded = script === void 0 ? void 0 : /^#!\/bin\/sh\r?\nexec (\/[A-Za-z0-9_./+-]+) "\$@"\r?\n?$/.exec(script)?.[1];
|
|
17702
|
+
return forwarded ?? candidate;
|
|
17703
|
+
} catch {
|
|
17704
|
+
return candidate;
|
|
17705
|
+
}
|
|
17706
|
+
}
|
|
17707
|
+
}
|
|
17708
|
+
return void 0;
|
|
17709
|
+
}
|
|
17710
|
+
|
|
17711
|
+
// src/doctorReport.ts
|
|
17712
|
+
import path35 from "node:path";
|
|
17669
17713
|
init_signIn();
|
|
17670
17714
|
init_identityAccounts();
|
|
17671
17715
|
init_read();
|
|
@@ -17912,7 +17956,7 @@ function pushFrontDoorListeners(push, readings) {
|
|
|
17912
17956
|
|
|
17913
17957
|
// src/frontdoor/listenerReadings.ts
|
|
17914
17958
|
init_probe();
|
|
17915
|
-
import
|
|
17959
|
+
import fs12 from "node:fs";
|
|
17916
17960
|
function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
17917
17961
|
if (!supervisorAlive) {
|
|
17918
17962
|
return [];
|
|
@@ -17932,7 +17976,7 @@ function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
|
17932
17976
|
}
|
|
17933
17977
|
function realFrontDoorListenerProbes(paths) {
|
|
17934
17978
|
return {
|
|
17935
|
-
authenticateProvider: (port) => probeFrontDoorSync(port,
|
|
17979
|
+
authenticateProvider: (port) => probeFrontDoorSync(port, fs12.readFileSync(paths.frontdoorCaCertFile, "utf8")),
|
|
17936
17980
|
connect: probeListenerAcceptSync,
|
|
17937
17981
|
now: () => performance.now()
|
|
17938
17982
|
};
|
|
@@ -18064,11 +18108,12 @@ var DOCTOR_SECTIONS = [
|
|
|
18064
18108
|
"frontdoor",
|
|
18065
18109
|
"models"
|
|
18066
18110
|
];
|
|
18067
|
-
function refinePathShadow(status, ownExecutablePath, realpath) {
|
|
18111
|
+
function refinePathShadow(status, ownExecutablePath, realpath, resolveDispatcher) {
|
|
18068
18112
|
if (status.status !== "shadowed") {
|
|
18069
18113
|
return status;
|
|
18070
18114
|
}
|
|
18071
|
-
|
|
18115
|
+
const resolved = resolveDispatcher?.(status.by) ?? status.by;
|
|
18116
|
+
return realpath(resolved) === realpath(ownExecutablePath) ? { status: "ok" } : status;
|
|
18072
18117
|
}
|
|
18073
18118
|
function validateJson(schema, input) {
|
|
18074
18119
|
if (input.raw === void 0) {
|
|
@@ -18097,7 +18142,7 @@ function tcpPortEraRecord(raw) {
|
|
|
18097
18142
|
return (has("port") || has("lastPort")) && !has("socketPath");
|
|
18098
18143
|
}
|
|
18099
18144
|
function pushPathResolution(push, resolution) {
|
|
18100
|
-
const ownDir =
|
|
18145
|
+
const ownDir = path35.dirname(resolution.ownExecutablePath);
|
|
18101
18146
|
switch (resolution.agentShim.status) {
|
|
18102
18147
|
case "ok":
|
|
18103
18148
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -18217,14 +18262,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
18217
18262
|
}
|
|
18218
18263
|
function pushLegacyName(push, params) {
|
|
18219
18264
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
18220
|
-
if (legacyVariables.length === 0 &&
|
|
18265
|
+
if (legacyVariables.length === 0 && path35.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
18221
18266
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
18222
18267
|
return;
|
|
18223
18268
|
}
|
|
18224
18269
|
for (const name of legacyVariables) {
|
|
18225
18270
|
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);
|
|
18226
18271
|
}
|
|
18227
|
-
if (
|
|
18272
|
+
if (path35.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
18228
18273
|
push(
|
|
18229
18274
|
"legacy-name",
|
|
18230
18275
|
"warn",
|
|
@@ -18318,7 +18363,7 @@ function runDoctor(params) {
|
|
|
18318
18363
|
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);
|
|
18319
18364
|
}
|
|
18320
18365
|
for (const { file, detail } of params.renameJournals?.unreadable ?? []) {
|
|
18321
|
-
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.`,
|
|
18366
|
+
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.`, path35.basename(file));
|
|
18322
18367
|
}
|
|
18323
18368
|
const validIdentityNames = /* @__PURE__ */ new Set();
|
|
18324
18369
|
const signedInAccounts = [];
|
|
@@ -18668,13 +18713,6 @@ function formatDoctorReport(report) {
|
|
|
18668
18713
|
lines.push("", report.ok ? "All checks passed." : `${String(failCount)} check(s) failed.`);
|
|
18669
18714
|
return lines;
|
|
18670
18715
|
}
|
|
18671
|
-
function realpathOrSelf(target) {
|
|
18672
|
-
try {
|
|
18673
|
-
return fs12.realpathSync(target);
|
|
18674
|
-
} catch {
|
|
18675
|
-
return target;
|
|
18676
|
-
}
|
|
18677
|
-
}
|
|
18678
18716
|
function servingDoorListeners(paths) {
|
|
18679
18717
|
const state = readFrontDoorState(realFarmFs, paths.frontdoorStateFile) ?? {};
|
|
18680
18718
|
const alive = state.supervisorPid !== void 0 && realIsProcessRunning(state.supervisorPid);
|
|
@@ -18684,9 +18722,9 @@ function collectDoctorReport(params) {
|
|
|
18684
18722
|
const { paths } = params;
|
|
18685
18723
|
const { names: identityNames, unreachable: unreachableIdentities } = listIdentityDirectories(paths);
|
|
18686
18724
|
const identities = identityNames.map((name) => {
|
|
18687
|
-
const farmRoot =
|
|
18688
|
-
const identityPath =
|
|
18689
|
-
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent:
|
|
18725
|
+
const farmRoot = path35.join(paths.identitiesDir, name);
|
|
18726
|
+
const identityPath = path35.join(farmRoot, "identity.json");
|
|
18727
|
+
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: fs13.existsSync(credentialsFilePath(farmRoot)), account: readIdentityAccount(realFsPort, paths.identitiesDir, name)?.account };
|
|
18690
18728
|
});
|
|
18691
18729
|
const usageSnapshots = {};
|
|
18692
18730
|
for (const name of identityNames) {
|
|
@@ -18701,14 +18739,14 @@ function collectDoctorReport(params) {
|
|
|
18701
18739
|
}
|
|
18702
18740
|
}
|
|
18703
18741
|
}
|
|
18704
|
-
const profileNames =
|
|
18742
|
+
const profileNames = fs13.existsSync(paths.configProfilesDir) ? fs13.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
18705
18743
|
const configProfiles = profileNames.map((name) => {
|
|
18706
|
-
const profilePath =
|
|
18744
|
+
const profilePath = path35.join(paths.configProfilesDir, `${name}.json`);
|
|
18707
18745
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
18708
18746
|
});
|
|
18709
|
-
const providerNames =
|
|
18747
|
+
const providerNames = fs13.existsSync(paths.providersDir) ? fs13.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
18710
18748
|
const providers = providerNames.map((name) => {
|
|
18711
|
-
const providerPath =
|
|
18749
|
+
const providerPath = path35.join(paths.providersDir, `${name}.json`);
|
|
18712
18750
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
18713
18751
|
});
|
|
18714
18752
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -18720,16 +18758,17 @@ function collectDoctorReport(params) {
|
|
|
18720
18758
|
binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
18721
18759
|
}
|
|
18722
18760
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
18723
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
18761
|
+
const pathDirs = (params.env.PATH ?? "").split(path35.delimiter).filter((dir) => dir !== "");
|
|
18724
18762
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
18725
18763
|
findPathShadow({
|
|
18726
18764
|
pathDirs,
|
|
18727
|
-
targetDir:
|
|
18728
|
-
targetFilename:
|
|
18765
|
+
targetDir: path35.dirname(shimState.targetPath),
|
|
18766
|
+
targetFilename: path35.basename(shimState.targetPath),
|
|
18729
18767
|
findExecutableInDir
|
|
18730
18768
|
}),
|
|
18731
18769
|
shimState.targetPath,
|
|
18732
|
-
realpathOrSelf
|
|
18770
|
+
realpathOrSelf,
|
|
18771
|
+
(target) => resolveMiseDispatcher(target, pathDirs, params.env, shimState.targetPath)
|
|
18733
18772
|
);
|
|
18734
18773
|
const uid = process.getuid?.();
|
|
18735
18774
|
const allowlistContent = realFarmFs.readFileUtf8(paths.headroomAllowlistFile);
|
|
@@ -18757,19 +18796,20 @@ function collectDoctorReport(params) {
|
|
|
18757
18796
|
categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
|
|
18758
18797
|
activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
|
|
18759
18798
|
binaryDiscovery,
|
|
18760
|
-
claudeShim: { state: shimState, targetExists: shimState !== void 0 &&
|
|
18799
|
+
claudeShim: { state: shimState, targetExists: shimState !== void 0 && fs13.existsSync(shimState.targetPath) },
|
|
18761
18800
|
rootPath: paths.root,
|
|
18762
18801
|
pathResolution: {
|
|
18763
18802
|
ownExecutablePath,
|
|
18764
18803
|
agentShim: refinePathShadow(
|
|
18765
18804
|
findPathShadow({
|
|
18766
18805
|
pathDirs,
|
|
18767
|
-
targetDir:
|
|
18806
|
+
targetDir: path35.dirname(ownExecutablePath),
|
|
18768
18807
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
18769
18808
|
findExecutableInDir
|
|
18770
18809
|
}),
|
|
18771
18810
|
ownExecutablePath,
|
|
18772
|
-
realpathOrSelf
|
|
18811
|
+
realpathOrSelf,
|
|
18812
|
+
(target) => resolveMiseDispatcher(target, pathDirs, params.env, ownExecutablePath)
|
|
18773
18813
|
),
|
|
18774
18814
|
...claudeShimShadow === void 0 ? {} : { claude: claudeShimShadow }
|
|
18775
18815
|
},
|
|
@@ -18854,11 +18894,11 @@ var FrontDoorSessionsOutputSchema = z32.strictObject({ sessions: z32.readonly(z3
|
|
|
18854
18894
|
var CheckRunInputSchema = z32.strictObject({
|
|
18855
18895
|
path: z32.string().min(1),
|
|
18856
18896
|
identity: z32.string().min(1).optional()
|
|
18857
|
-
}).refine((input) =>
|
|
18897
|
+
}).refine((input) => path36.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
18858
18898
|
var PoolPickInputSchema = z32.strictObject({
|
|
18859
18899
|
pool: z32.string().min(1),
|
|
18860
18900
|
path: z32.string().min(1)
|
|
18861
|
-
}).refine((input) =>
|
|
18901
|
+
}).refine((input) => path36.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
18862
18902
|
var DoctorFindingSchema = z32.strictObject({
|
|
18863
18903
|
section: z32.enum(DOCTOR_SECTIONS),
|
|
18864
18904
|
subject: z32.string().optional(),
|
|
@@ -19282,7 +19322,7 @@ function profileValue(name, paths) {
|
|
|
19282
19322
|
function createConfigApiRouter(deps) {
|
|
19283
19323
|
const authed = doorApiAuth(deps.expectedToken);
|
|
19284
19324
|
const { paths } = deps;
|
|
19285
|
-
const route = (
|
|
19325
|
+
const route = (path49, summary) => authed.meta(openapi3({ method: "POST", path: path49, summary, tags: [CONFIG_API_TAG] }));
|
|
19286
19326
|
return {
|
|
19287
19327
|
config: {
|
|
19288
19328
|
identity: {
|
|
@@ -19669,7 +19709,7 @@ import { ORPCError as ORPCError5 } from "@orpc/client";
|
|
|
19669
19709
|
import { openapi as openapi6 } from "@orpc/openapi";
|
|
19670
19710
|
|
|
19671
19711
|
// src/frontdoor/launchSchemas.ts
|
|
19672
|
-
import
|
|
19712
|
+
import path37 from "node:path";
|
|
19673
19713
|
import { z as z36 } from "zod";
|
|
19674
19714
|
init_statusline();
|
|
19675
19715
|
init_claudeVersion();
|
|
@@ -19680,7 +19720,7 @@ var LaunchResolveInputSchema = z36.strictObject({
|
|
|
19680
19720
|
argv: z36.readonly(z36.array(z36.string())).optional(),
|
|
19681
19721
|
/** 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. */
|
|
19682
19722
|
env: z36.record(z36.string(), z36.string()).optional()
|
|
19683
|
-
}).refine((input) =>
|
|
19723
|
+
}).refine((input) => path37.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
19684
19724
|
var LaunchPoolDecisionSchema = z36.strictObject({
|
|
19685
19725
|
name: z36.string(),
|
|
19686
19726
|
reasons: z36.readonly(z36.array(z36.string())),
|
|
@@ -21861,7 +21901,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
21861
21901
|
|
|
21862
21902
|
// src/frontdoor/rcSelfHostMint.ts
|
|
21863
21903
|
init_account();
|
|
21864
|
-
import
|
|
21904
|
+
import path38 from "node:path";
|
|
21865
21905
|
var CREDENTIALS_FILE2 = ".credentials.json";
|
|
21866
21906
|
var CLAUDE_JSON2 = ".claude.json";
|
|
21867
21907
|
var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
@@ -21871,8 +21911,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
|
21871
21911
|
function isRecord14(value) {
|
|
21872
21912
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21873
21913
|
}
|
|
21874
|
-
function readJsonObject(
|
|
21875
|
-
const raw =
|
|
21914
|
+
function readJsonObject(fs16, file) {
|
|
21915
|
+
const raw = fs16.readFileUtf8(file);
|
|
21876
21916
|
if (raw === void 0) {
|
|
21877
21917
|
return void 0;
|
|
21878
21918
|
}
|
|
@@ -21884,8 +21924,8 @@ function readJsonObject(fs15, file) {
|
|
|
21884
21924
|
}
|
|
21885
21925
|
return isRecord14(parsed) ? parsed : void 0;
|
|
21886
21926
|
}
|
|
21887
|
-
function readRcSelfHostRecord(
|
|
21888
|
-
const parsed = readJsonObject(
|
|
21927
|
+
function readRcSelfHostRecord(fs16, frontdoorDir) {
|
|
21928
|
+
const parsed = readJsonObject(fs16, path38.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
21889
21929
|
if (parsed === void 0) {
|
|
21890
21930
|
return void 0;
|
|
21891
21931
|
}
|
|
@@ -21899,11 +21939,11 @@ function mintRcSelfHostCredential(deps) {
|
|
|
21899
21939
|
if (!isIdentityName(deps.identity)) {
|
|
21900
21940
|
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
21901
21941
|
}
|
|
21902
|
-
const identityDir =
|
|
21903
|
-
const credentialsFile =
|
|
21904
|
-
const claudeJsonFile =
|
|
21905
|
-
const recordDir =
|
|
21906
|
-
const recordFile2 =
|
|
21942
|
+
const identityDir = path38.join(deps.identitiesDir, deps.identity);
|
|
21943
|
+
const credentialsFile = path38.join(identityDir, CREDENTIALS_FILE2);
|
|
21944
|
+
const claudeJsonFile = path38.join(identityDir, CLAUDE_JSON2);
|
|
21945
|
+
const recordDir = path38.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
21946
|
+
const recordFile2 = path38.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
21907
21947
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
21908
21948
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
21909
21949
|
const existingOauth = isRecord14(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
@@ -21919,7 +21959,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
21919
21959
|
const organizationUuid = deps.newUuid();
|
|
21920
21960
|
const accountUuid = deps.newUuid();
|
|
21921
21961
|
const mintedAt = new Date(deps.now()).toISOString();
|
|
21922
|
-
deps.fs.mkdirPrivate(
|
|
21962
|
+
deps.fs.mkdirPrivate(path38.dirname(credentialsFile));
|
|
21923
21963
|
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)}
|
|
21924
21964
|
`);
|
|
21925
21965
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
@@ -21957,25 +21997,25 @@ init_ensure2();
|
|
|
21957
21997
|
// src/frontdoor/liveSessionRegistry.ts
|
|
21958
21998
|
init_capability();
|
|
21959
21999
|
init_state();
|
|
21960
|
-
import
|
|
22000
|
+
import path39 from "node:path";
|
|
21961
22001
|
function sameStat(recorded, current) {
|
|
21962
22002
|
return recorded?.mtimeMs === current.mtimeMs && recorded.sizeBytes === current.sizeBytes;
|
|
21963
22003
|
}
|
|
21964
22004
|
function createLiveSessionRegistry(ports) {
|
|
21965
|
-
const { fs:
|
|
22005
|
+
const { fs: fs16, sessionsDir } = ports;
|
|
21966
22006
|
const known = /* @__PURE__ */ new Map();
|
|
21967
22007
|
let tokens = /* @__PURE__ */ new Set();
|
|
21968
22008
|
let bySessionId = /* @__PURE__ */ new Map();
|
|
21969
|
-
const recordNames = () =>
|
|
22009
|
+
const recordNames = () => fs16.readdir(sessionsDir).filter(isSessionRecordName);
|
|
21970
22010
|
const rebuildIndexes = () => {
|
|
21971
22011
|
const records = [...known.values()].flatMap(({ record }) => record === void 0 ? [] : [record]);
|
|
21972
22012
|
tokens = new Set(records.map((record) => record.token));
|
|
21973
22013
|
bySessionId = new Map(records.flatMap((record) => record.sessionId === void 0 ? [] : [[record.sessionId, record]]));
|
|
21974
22014
|
};
|
|
21975
22015
|
const load = (name, stat) => {
|
|
21976
|
-
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(
|
|
22016
|
+
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(fs16, sessionsDir, name) });
|
|
21977
22017
|
};
|
|
21978
|
-
const statOf = (name) =>
|
|
22018
|
+
const statOf = (name) => fs16.lstat(path39.join(sessionsDir, name));
|
|
21979
22019
|
const reconcile = () => {
|
|
21980
22020
|
const names = new Set(recordNames());
|
|
21981
22021
|
let changed = false;
|
|
@@ -22042,7 +22082,7 @@ init_plan2();
|
|
|
22042
22082
|
init_poolPick();
|
|
22043
22083
|
|
|
22044
22084
|
// src/agents/read.ts
|
|
22045
|
-
import
|
|
22085
|
+
import path40 from "node:path";
|
|
22046
22086
|
import { z as z38 } from "zod";
|
|
22047
22087
|
var PROJECTS_DIR = "projects";
|
|
22048
22088
|
var TASKS_DIR = "tasks";
|
|
@@ -22066,17 +22106,17 @@ function parseEntry2(project, entry) {
|
|
|
22066
22106
|
const base = match?.[1];
|
|
22067
22107
|
return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
|
|
22068
22108
|
}
|
|
22069
|
-
function listSessions2(
|
|
22109
|
+
function listSessions2(fs16, configDir) {
|
|
22070
22110
|
const found = [];
|
|
22071
|
-
for (const project of
|
|
22072
|
-
const projectDir =
|
|
22111
|
+
for (const project of fs16.readdir(path40.join(configDir, PROJECTS_DIR))) {
|
|
22112
|
+
const projectDir = path40.join(configDir, PROJECTS_DIR, project);
|
|
22073
22113
|
const entries = /* @__PURE__ */ new Set();
|
|
22074
|
-
for (const name of
|
|
22114
|
+
for (const name of fs16.readdir(projectDir)) {
|
|
22075
22115
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
22076
22116
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
22077
22117
|
continue;
|
|
22078
22118
|
}
|
|
22079
|
-
const children =
|
|
22119
|
+
const children = fs16.readdir(path40.join(projectDir, name));
|
|
22080
22120
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
22081
22121
|
entries.add(name);
|
|
22082
22122
|
}
|
|
@@ -22087,17 +22127,17 @@ function listSessions2(fs15, configDir) {
|
|
|
22087
22127
|
}
|
|
22088
22128
|
return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
|
|
22089
22129
|
}
|
|
22090
|
-
function locateAgents(
|
|
22130
|
+
function locateAgents(fs16, configDir, relativeDir, workflowRunId, report) {
|
|
22091
22131
|
const located = [];
|
|
22092
|
-
for (const name of listDirOrReport(
|
|
22132
|
+
for (const name of listDirOrReport(fs16, configDir, relativeDir, report)) {
|
|
22093
22133
|
if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
|
|
22094
22134
|
continue;
|
|
22095
22135
|
}
|
|
22096
22136
|
const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
|
|
22097
22137
|
located.push({
|
|
22098
22138
|
id,
|
|
22099
|
-
metaPath:
|
|
22100
|
-
transcriptPath:
|
|
22139
|
+
metaPath: path40.join(relativeDir, name),
|
|
22140
|
+
transcriptPath: path40.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
|
|
22101
22141
|
workflowRunId
|
|
22102
22142
|
});
|
|
22103
22143
|
}
|
|
@@ -22138,17 +22178,17 @@ function toNode(read, children) {
|
|
|
22138
22178
|
function describeFailure(error) {
|
|
22139
22179
|
return error instanceof Error ? error.message : String(error);
|
|
22140
22180
|
}
|
|
22141
|
-
function readFileOrReport(
|
|
22181
|
+
function readFileOrReport(fs16, configDir, relative, report) {
|
|
22142
22182
|
try {
|
|
22143
|
-
return
|
|
22183
|
+
return fs16.readFileUtf8(path40.join(configDir, relative));
|
|
22144
22184
|
} catch (error) {
|
|
22145
22185
|
report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
|
|
22146
22186
|
return void 0;
|
|
22147
22187
|
}
|
|
22148
22188
|
}
|
|
22149
|
-
function listDirOrReport(
|
|
22189
|
+
function listDirOrReport(fs16, configDir, relative, report) {
|
|
22150
22190
|
try {
|
|
22151
|
-
return
|
|
22191
|
+
return fs16.readdir(path40.join(configDir, relative));
|
|
22152
22192
|
} catch (error) {
|
|
22153
22193
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
|
|
22154
22194
|
return [];
|
|
@@ -22171,38 +22211,38 @@ var WorkflowRunFileSchema = z38.object({
|
|
|
22171
22211
|
phases: z38.array(z38.object({ title: z38.string() })).default([]),
|
|
22172
22212
|
summary: z38.string().optional()
|
|
22173
22213
|
});
|
|
22174
|
-
function summariseSession(
|
|
22175
|
-
const sessionRelative =
|
|
22176
|
-
const subagentsRelative =
|
|
22177
|
-
const workflowsUnderSubagents =
|
|
22214
|
+
function summariseSession(fs16, configDir, ref) {
|
|
22215
|
+
const sessionRelative = path40.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22216
|
+
const subagentsRelative = path40.join(sessionRelative, SUBAGENTS_DIR);
|
|
22217
|
+
const workflowsUnderSubagents = path40.join(subagentsRelative, WORKFLOWS_DIR);
|
|
22178
22218
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
22179
|
-
let agentCount =
|
|
22180
|
-
for (const runDir of
|
|
22219
|
+
let agentCount = fs16.readdir(path40.join(configDir, subagentsRelative)).filter(isMeta).length;
|
|
22220
|
+
for (const runDir of fs16.readdir(path40.join(configDir, workflowsUnderSubagents))) {
|
|
22181
22221
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
22182
|
-
agentCount +=
|
|
22222
|
+
agentCount += fs16.readdir(path40.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
22183
22223
|
}
|
|
22184
22224
|
}
|
|
22185
|
-
const workflowRunCount =
|
|
22186
|
-
const transcript =
|
|
22225
|
+
const workflowRunCount = fs16.readdir(path40.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
|
|
22226
|
+
const transcript = fs16.lstat(path40.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
|
|
22187
22227
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
22188
22228
|
}
|
|
22189
|
-
function readSessionAgentTree(
|
|
22229
|
+
function readSessionAgentTree(fs16, configDir, ref, options = {}) {
|
|
22190
22230
|
const problems = [];
|
|
22191
22231
|
const report = (problem) => {
|
|
22192
22232
|
problems.push(problem);
|
|
22193
22233
|
};
|
|
22194
|
-
const sessionRelative =
|
|
22195
|
-
const subagentsRelative =
|
|
22196
|
-
const workflowsUnderSubagents =
|
|
22197
|
-
const located = locateAgents(
|
|
22198
|
-
for (const runDir of listDirOrReport(
|
|
22234
|
+
const sessionRelative = path40.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22235
|
+
const subagentsRelative = path40.join(sessionRelative, SUBAGENTS_DIR);
|
|
22236
|
+
const workflowsUnderSubagents = path40.join(subagentsRelative, WORKFLOWS_DIR);
|
|
22237
|
+
const located = locateAgents(fs16, configDir, subagentsRelative, void 0, report);
|
|
22238
|
+
for (const runDir of listDirOrReport(fs16, configDir, workflowsUnderSubagents, report)) {
|
|
22199
22239
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
22200
|
-
located.push(...locateAgents(
|
|
22240
|
+
located.push(...locateAgents(fs16, configDir, path40.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
22201
22241
|
}
|
|
22202
22242
|
}
|
|
22203
22243
|
const agents = /* @__PURE__ */ new Map();
|
|
22204
22244
|
for (const candidate of located) {
|
|
22205
|
-
const text = readFileOrReport(
|
|
22245
|
+
const text = readFileOrReport(fs16, configDir, candidate.metaPath, report);
|
|
22206
22246
|
if (text === void 0) {
|
|
22207
22247
|
continue;
|
|
22208
22248
|
}
|
|
@@ -22214,7 +22254,7 @@ function readSessionAgentTree(fs15, configDir, ref, options = {}) {
|
|
|
22214
22254
|
agents.set(candidate.id, { located: candidate, meta: parsed.data });
|
|
22215
22255
|
}
|
|
22216
22256
|
const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
|
|
22217
|
-
const parentOf3 = resolveParents(
|
|
22257
|
+
const parentOf3 = resolveParents(fs16, configDir, agents, report);
|
|
22218
22258
|
const childrenOf = /* @__PURE__ */ new Map();
|
|
22219
22259
|
const roots = [];
|
|
22220
22260
|
for (const id of agents.keys()) {
|
|
@@ -22237,12 +22277,12 @@ function readSessionAgentTree(fs15, configDir, ref, options = {}) {
|
|
|
22237
22277
|
sessionId: ref.sessionId,
|
|
22238
22278
|
superseded: ref.superseded,
|
|
22239
22279
|
agents: roots.sort().map(build),
|
|
22240
|
-
tasks: readTasks(
|
|
22241
|
-
workflowRuns: readWorkflowRuns(
|
|
22280
|
+
tasks: readTasks(fs16, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
|
|
22281
|
+
workflowRuns: readWorkflowRuns(fs16, configDir, path40.join(sessionRelative, WORKFLOWS_DIR), report),
|
|
22242
22282
|
problems
|
|
22243
22283
|
};
|
|
22244
22284
|
}
|
|
22245
|
-
function resolveParents(
|
|
22285
|
+
function resolveParents(fs16, configDir, agents, report) {
|
|
22246
22286
|
const parentOf3 = /* @__PURE__ */ new Map();
|
|
22247
22287
|
const transcriptCache = /* @__PURE__ */ new Map();
|
|
22248
22288
|
const transcriptOf = (agent) => {
|
|
@@ -22250,7 +22290,7 @@ function resolveParents(fs15, configDir, agents, report) {
|
|
|
22250
22290
|
if (cached !== void 0) {
|
|
22251
22291
|
return cached;
|
|
22252
22292
|
}
|
|
22253
|
-
const text = readFileOrReport(
|
|
22293
|
+
const text = readFileOrReport(fs16, configDir, agent.located.transcriptPath, report) ?? "";
|
|
22254
22294
|
transcriptCache.set(agent.located.id, text);
|
|
22255
22295
|
return text;
|
|
22256
22296
|
};
|
|
@@ -22300,16 +22340,16 @@ function resolveParents(fs15, configDir, agents, report) {
|
|
|
22300
22340
|
function ownTaskLists(sessionId) {
|
|
22301
22341
|
return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
|
|
22302
22342
|
}
|
|
22303
|
-
function readTasks(
|
|
22343
|
+
function readTasks(fs16, configDir, ownLists, sharedLists, report) {
|
|
22304
22344
|
const tasks = [];
|
|
22305
22345
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
22306
|
-
const relativeDir =
|
|
22307
|
-
for (const name of [...listDirOrReport(
|
|
22346
|
+
const relativeDir = path40.join(TASKS_DIR, scope);
|
|
22347
|
+
for (const name of [...listDirOrReport(fs16, configDir, relativeDir, report)].sort()) {
|
|
22308
22348
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
22309
22349
|
continue;
|
|
22310
22350
|
}
|
|
22311
|
-
const relative =
|
|
22312
|
-
const text = readFileOrReport(
|
|
22351
|
+
const relative = path40.join(relativeDir, name);
|
|
22352
|
+
const text = readFileOrReport(fs16, configDir, relative, report);
|
|
22313
22353
|
const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
22314
22354
|
if (parsed.success) {
|
|
22315
22355
|
tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
|
|
@@ -22320,14 +22360,14 @@ function readTasks(fs15, configDir, ownLists, sharedLists, report) {
|
|
|
22320
22360
|
});
|
|
22321
22361
|
return tasks;
|
|
22322
22362
|
}
|
|
22323
|
-
function readWorkflowRuns(
|
|
22363
|
+
function readWorkflowRuns(fs16, configDir, relativeDir, report) {
|
|
22324
22364
|
const runs = [];
|
|
22325
|
-
for (const name of [...listDirOrReport(
|
|
22365
|
+
for (const name of [...listDirOrReport(fs16, configDir, relativeDir, report)].sort()) {
|
|
22326
22366
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
22327
22367
|
continue;
|
|
22328
22368
|
}
|
|
22329
|
-
const relative =
|
|
22330
|
-
const text = readFileOrReport(
|
|
22369
|
+
const relative = path40.join(relativeDir, name);
|
|
22370
|
+
const text = readFileOrReport(fs16, configDir, relative, report);
|
|
22331
22371
|
const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
22332
22372
|
if (!parsed.success) {
|
|
22333
22373
|
if (text !== void 0) {
|
|
@@ -22343,7 +22383,7 @@ function readWorkflowRuns(fs15, configDir, relativeDir, report) {
|
|
|
22343
22383
|
|
|
22344
22384
|
// src/agents/sessions.ts
|
|
22345
22385
|
init_cliError();
|
|
22346
|
-
import
|
|
22386
|
+
import path41 from "node:path";
|
|
22347
22387
|
var SessionLookupError = class extends CliError {
|
|
22348
22388
|
constructor(message) {
|
|
22349
22389
|
super(message);
|
|
@@ -22351,13 +22391,13 @@ var SessionLookupError = class extends CliError {
|
|
|
22351
22391
|
}
|
|
22352
22392
|
};
|
|
22353
22393
|
function identityConfigDir(identitiesDir, identity) {
|
|
22354
|
-
return
|
|
22394
|
+
return path41.join(identitiesDir, identity);
|
|
22355
22395
|
}
|
|
22356
|
-
function historyStores(
|
|
22396
|
+
function historyStores(fs16, identitiesDir, identities) {
|
|
22357
22397
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
22358
22398
|
for (const identity of identities) {
|
|
22359
22399
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
22360
|
-
const real =
|
|
22400
|
+
const real = fs16.realpath(path41.join(configDir, "projects"));
|
|
22361
22401
|
if (real === void 0) {
|
|
22362
22402
|
continue;
|
|
22363
22403
|
}
|
|
@@ -22370,15 +22410,15 @@ function historyStores(fs15, identitiesDir, identities) {
|
|
|
22370
22410
|
}
|
|
22371
22411
|
return [...byRealPath.values()];
|
|
22372
22412
|
}
|
|
22373
|
-
function collectSessionList(
|
|
22413
|
+
function collectSessionList(fs16, identitiesDir, identities, filters) {
|
|
22374
22414
|
const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
|
|
22375
22415
|
if (filters.identity !== void 0 && names.length === 0) {
|
|
22376
22416
|
throw new SessionLookupError(`no identity named "${filters.identity}"`);
|
|
22377
22417
|
}
|
|
22378
22418
|
const sessions = [];
|
|
22379
|
-
for (const store of historyStores(
|
|
22380
|
-
for (const ref of listSessions2(
|
|
22381
|
-
const summary = summariseSession(
|
|
22419
|
+
for (const store of historyStores(fs16, identitiesDir, names)) {
|
|
22420
|
+
for (const ref of listSessions2(fs16, store.configDir)) {
|
|
22421
|
+
const summary = summariseSession(fs16, store.configDir, ref);
|
|
22382
22422
|
if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
|
|
22383
22423
|
sessions.push({ ...summary, identities: store.identities });
|
|
22384
22424
|
}
|
|
@@ -22386,14 +22426,14 @@ function collectSessionList(fs15, identitiesDir, identities, filters) {
|
|
|
22386
22426
|
}
|
|
22387
22427
|
return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
|
|
22388
22428
|
}
|
|
22389
|
-
function locateSession(
|
|
22429
|
+
function locateSession(fs16, identitiesDir, identities, query, onlyIdentity) {
|
|
22390
22430
|
const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
|
|
22391
22431
|
if (onlyIdentity !== void 0 && names.length === 0) {
|
|
22392
22432
|
throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
|
|
22393
22433
|
}
|
|
22394
22434
|
const matches = [];
|
|
22395
|
-
for (const store of historyStores(
|
|
22396
|
-
for (const ref of listSessions2(
|
|
22435
|
+
for (const store of historyStores(fs16, identitiesDir, names)) {
|
|
22436
|
+
for (const ref of listSessions2(fs16, store.configDir)) {
|
|
22397
22437
|
if (ref.sessionId.startsWith(query)) {
|
|
22398
22438
|
matches.push({ identities: store.identities, configDir: store.configDir, ref });
|
|
22399
22439
|
}
|
|
@@ -22410,9 +22450,9 @@ function locateSession(fs15, identitiesDir, identities, query, onlyIdentity) {
|
|
|
22410
22450
|
}
|
|
22411
22451
|
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`);
|
|
22412
22452
|
}
|
|
22413
|
-
function showSession(
|
|
22414
|
-
const located = locateSession(
|
|
22415
|
-
return { identities: located.identities, tree: readSessionAgentTree(
|
|
22453
|
+
function showSession(fs16, identitiesDir, identities, query, onlyIdentity) {
|
|
22454
|
+
const located = locateSession(fs16, identitiesDir, identities, query, onlyIdentity);
|
|
22455
|
+
return { identities: located.identities, tree: readSessionAgentTree(fs16, located.configDir, located.ref) };
|
|
22416
22456
|
}
|
|
22417
22457
|
|
|
22418
22458
|
// src/agents/realFs.ts
|