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.cjs
CHANGED
|
@@ -1065,6 +1065,8 @@ var init_schema = __esm({
|
|
|
1065
1065
|
thinking: import_zod3.z.boolean().optional()
|
|
1066
1066
|
});
|
|
1067
1067
|
ModelsConfigSchema = import_zod3.z.strictObject({
|
|
1068
|
+
/** Whether picker labels put spaces around the provider/model slash. */
|
|
1069
|
+
pickerLabelSpaces: import_zod3.z.boolean().optional(),
|
|
1068
1070
|
/** Virtual models, by name. */
|
|
1069
1071
|
virtual: import_zod3.z.record(import_zod3.z.string().min(1), VirtualModelSchema).optional(),
|
|
1070
1072
|
/** Which model ref each Claude tier (`fable`, `opus`, `sonnet`, `haiku`) points at: a concrete target, an account model, a virtual model, or a family. */
|
|
@@ -1088,6 +1090,7 @@ var init_schema = __esm({
|
|
|
1088
1090
|
families: import_zod3.z.record(import_zod3.z.string().min(1), FamilySettingsSchema).optional()
|
|
1089
1091
|
});
|
|
1090
1092
|
ModelsLayerSchema = import_zod3.z.strictObject({
|
|
1093
|
+
pickerLabelSpaces: import_zod3.z.boolean().optional(),
|
|
1091
1094
|
virtual: import_zod3.z.record(import_zod3.z.string().min(1), import_zod3.z.union([VirtualModelSchema, import_zod3.z.null()])).optional(),
|
|
1092
1095
|
tiers: import_zod3.z.strictObject({
|
|
1093
1096
|
fable: import_zod3.z.union([import_zod3.z.string().min(1), import_zod3.z.null()]).optional(),
|
|
@@ -1300,7 +1303,7 @@ function parseIgnoringUnrecognisedKeys(schema, raw) {
|
|
|
1300
1303
|
return second.success ? { success: true, data: second.data, ignored } : { success: false, issues: second.error.issues };
|
|
1301
1304
|
}
|
|
1302
1305
|
function describeIgnoredKeys(filePath, ignored) {
|
|
1303
|
-
const places = ignored.map(({ path:
|
|
1306
|
+
const places = ignored.map(({ path: path49, keys }) => `${path49.length === 0 ? "" : `${path49.map(String).join(".")}.`}${keys.join(", ")}`);
|
|
1304
1307
|
return `${filePath} has settings this version of agent-shim does not know and ignores: ${places.join("; ")}. A newer release may read them.`;
|
|
1305
1308
|
}
|
|
1306
1309
|
function noteIgnoredKeys(filePath, ignored) {
|
|
@@ -1322,9 +1325,9 @@ function restoreIgnoredKeys(filePath, value) {
|
|
|
1322
1325
|
return value;
|
|
1323
1326
|
}
|
|
1324
1327
|
const restored = structuredClone(value);
|
|
1325
|
-
for (const { path:
|
|
1328
|
+
for (const { path: path49, values } of ignored) {
|
|
1326
1329
|
let holder = restored;
|
|
1327
|
-
for (const step of
|
|
1330
|
+
for (const step of path49) {
|
|
1328
1331
|
holder = isRecord(holder) ? holder[step] : void 0;
|
|
1329
1332
|
}
|
|
1330
1333
|
if (isRecord(holder)) {
|
|
@@ -2182,6 +2185,7 @@ function matchingRules(flattened, relPath) {
|
|
|
2182
2185
|
}
|
|
2183
2186
|
function mergeModels(current, layer) {
|
|
2184
2187
|
const pieces = { ...current ?? {} };
|
|
2188
|
+
if (layer.pickerLabelSpaces !== void 0) pieces.pickerLabelSpaces = layer.pickerLabelSpaces;
|
|
2185
2189
|
if (layer.virtual !== void 0) {
|
|
2186
2190
|
const virtual = {};
|
|
2187
2191
|
for (const [name, definition] of Object.entries(current?.virtual ?? {})) {
|
|
@@ -2254,6 +2258,7 @@ function mergeModels(current, layer) {
|
|
|
2254
2258
|
}
|
|
2255
2259
|
function modelsOf(pieces) {
|
|
2256
2260
|
return {
|
|
2261
|
+
...pieces.pickerLabelSpaces === void 0 ? {} : { pickerLabelSpaces: pieces.pickerLabelSpaces },
|
|
2257
2262
|
...pieces.virtual === void 0 || Object.keys(pieces.virtual).length === 0 ? {} : { virtual: pieces.virtual },
|
|
2258
2263
|
...pieces.tiers === void 0 || Object.keys(pieces.tiers).length === 0 ? {} : { tiers: pieces.tiers },
|
|
2259
2264
|
...pieces.prices === void 0 || Object.keys(pieces.prices).length === 0 ? {} : { prices: pieces.prices },
|
|
@@ -3044,8 +3049,8 @@ var init_lock = __esm({
|
|
|
3044
3049
|
});
|
|
3045
3050
|
|
|
3046
3051
|
// src/launcher/farm.ts
|
|
3047
|
-
function readFarmManifest(
|
|
3048
|
-
const raw =
|
|
3052
|
+
function readFarmManifest(fs16, farmRoot) {
|
|
3053
|
+
const raw = fs16.readFileUtf8(import_node_path8.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs16.readFileUtf8(import_node_path8.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
|
|
3049
3054
|
if (raw === void 0) {
|
|
3050
3055
|
return void 0;
|
|
3051
3056
|
}
|
|
@@ -3103,9 +3108,9 @@ function buildEntryFacts(params) {
|
|
|
3103
3108
|
entries
|
|
3104
3109
|
};
|
|
3105
3110
|
}
|
|
3106
|
-
function listSubtree(
|
|
3111
|
+
function listSubtree(fs16, root, rel) {
|
|
3107
3112
|
const absolute = import_node_path8.default.join(root, rel);
|
|
3108
|
-
const stat =
|
|
3113
|
+
const stat = fs16.lstat(absolute);
|
|
3109
3114
|
if (stat === void 0) {
|
|
3110
3115
|
return [];
|
|
3111
3116
|
}
|
|
@@ -3113,10 +3118,10 @@ function listSubtree(fs15, root, rel) {
|
|
|
3113
3118
|
return [{ rel, kind: "symlink" }];
|
|
3114
3119
|
}
|
|
3115
3120
|
if (stat.kind === "dir") {
|
|
3116
|
-
const children = [...
|
|
3121
|
+
const children = [...fs16.readdir(absolute)].sort().flatMap((name) => listSubtree(fs16, root, `${rel}/${name}`));
|
|
3117
3122
|
return [{ rel, kind: "dir" }, ...children];
|
|
3118
3123
|
}
|
|
3119
|
-
const contentHash =
|
|
3124
|
+
const contentHash = fs16.hashFile(absolute);
|
|
3120
3125
|
return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
|
|
3121
3126
|
}
|
|
3122
3127
|
function topLevelScopeRoots(roots) {
|
|
@@ -3130,25 +3135,25 @@ function topLevelScopeRoots(roots) {
|
|
|
3130
3135
|
}
|
|
3131
3136
|
return kept;
|
|
3132
3137
|
}
|
|
3133
|
-
function reconciliationScope(
|
|
3138
|
+
function reconciliationScope(fs16, farmRoot, manifest) {
|
|
3134
3139
|
if (manifest !== void 0) {
|
|
3135
3140
|
return topLevelScopeRoots(manifest.materialised);
|
|
3136
3141
|
}
|
|
3137
|
-
return [...
|
|
3142
|
+
return [...fs16.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs16.lstat(import_node_path8.default.join(farmRoot, name))?.kind === "dir").sort();
|
|
3138
3143
|
}
|
|
3139
|
-
function collectFarmListing(
|
|
3140
|
-
return scopeRoots.flatMap((root) => listSubtree(
|
|
3144
|
+
function collectFarmListing(fs16, farmRoot, scopeRoots) {
|
|
3145
|
+
return scopeRoots.flatMap((root) => listSubtree(fs16, farmRoot, root));
|
|
3141
3146
|
}
|
|
3142
|
-
function collectCanonicalCounterparts(
|
|
3147
|
+
function collectCanonicalCounterparts(fs16, claudeHome, farmListing) {
|
|
3143
3148
|
const out = [];
|
|
3144
3149
|
for (const entry of farmListing) {
|
|
3145
3150
|
const absolute = import_node_path8.default.join(claudeHome, entry.rel);
|
|
3146
|
-
const stat =
|
|
3151
|
+
const stat = fs16.lstat(absolute);
|
|
3147
3152
|
if (stat === void 0) {
|
|
3148
3153
|
continue;
|
|
3149
3154
|
}
|
|
3150
3155
|
if (stat.kind === "file") {
|
|
3151
|
-
const contentHash =
|
|
3156
|
+
const contentHash = fs16.hashFile(absolute);
|
|
3152
3157
|
out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
|
|
3153
3158
|
continue;
|
|
3154
3159
|
}
|
|
@@ -3986,9 +3991,9 @@ var init_providerCatalogue = __esm({
|
|
|
3986
3991
|
});
|
|
3987
3992
|
|
|
3988
3993
|
// src/frontdoor/state.ts
|
|
3989
|
-
function readCatalogueStatus(
|
|
3994
|
+
function readCatalogueStatus(fs16, paths, pid, generation, name) {
|
|
3990
3995
|
const file = import_node_path10.default.join(import_node_path10.default.dirname(catalogueCachePath(paths, name, pid, generation)), `${name}.status.json`);
|
|
3991
|
-
const raw =
|
|
3996
|
+
const raw = fs16.readFileUtf8(file);
|
|
3992
3997
|
if (raw === void 0) return void 0;
|
|
3993
3998
|
try {
|
|
3994
3999
|
const value = import_zod6.z.strictObject({ status: import_zod6.z.enum(["running", "ready", "failed"]), fingerprint: import_zod6.z.string().min(1).optional(), recordedAt: import_zod6.z.number().optional() }).safeParse(JSON.parse(raw));
|
|
@@ -3997,14 +4002,14 @@ function readCatalogueStatus(fs15, paths, pid, generation, name) {
|
|
|
3997
4002
|
return void 0;
|
|
3998
4003
|
}
|
|
3999
4004
|
}
|
|
4000
|
-
function writeFrontDoorCodexHome(
|
|
4005
|
+
function writeFrontDoorCodexHome(fs16, frontdoorDir, pid, codexHome, generation) {
|
|
4001
4006
|
const directory = import_node_path10.default.join(frontdoorDir, "codex-homes");
|
|
4002
|
-
|
|
4003
|
-
|
|
4007
|
+
fs16.mkdirp(directory);
|
|
4008
|
+
fs16.writeFilePrivate(import_node_path10.default.join(directory, `${String(pid)}.json`), `${JSON.stringify({ codexHome, generation })}
|
|
4004
4009
|
`);
|
|
4005
4010
|
}
|
|
4006
|
-
function readFrontDoorCodexRecord(
|
|
4007
|
-
const raw =
|
|
4011
|
+
function readFrontDoorCodexRecord(fs16, frontdoorDir, pid) {
|
|
4012
|
+
const raw = fs16.readFileUtf8(import_node_path10.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
4008
4013
|
if (raw === void 0) return void 0;
|
|
4009
4014
|
try {
|
|
4010
4015
|
const parsed = import_zod6.z.strictObject({ codexHome: import_zod6.z.string().min(1), generation: import_zod6.z.uuid() }).safeParse(JSON.parse(raw));
|
|
@@ -4013,13 +4018,13 @@ function readFrontDoorCodexRecord(fs15, frontdoorDir, pid) {
|
|
|
4013
4018
|
return void 0;
|
|
4014
4019
|
}
|
|
4015
4020
|
}
|
|
4016
|
-
function removeFrontDoorCodexHome(
|
|
4017
|
-
|
|
4021
|
+
function removeFrontDoorCodexHome(fs16, frontdoorDir, pid) {
|
|
4022
|
+
fs16.removeRecursive(import_node_path10.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
4018
4023
|
}
|
|
4019
|
-
function readFrontDoorState(
|
|
4024
|
+
function readFrontDoorState(fs16, stateFile) {
|
|
4020
4025
|
let raw;
|
|
4021
4026
|
try {
|
|
4022
|
-
raw =
|
|
4027
|
+
raw = fs16.readFileUtf8(stateFile);
|
|
4023
4028
|
} catch {
|
|
4024
4029
|
return void 0;
|
|
4025
4030
|
}
|
|
@@ -4033,9 +4038,9 @@ function readFrontDoorState(fs15, stateFile) {
|
|
|
4033
4038
|
return void 0;
|
|
4034
4039
|
}
|
|
4035
4040
|
}
|
|
4036
|
-
function writeFrontDoorState(
|
|
4037
|
-
|
|
4038
|
-
|
|
4041
|
+
function writeFrontDoorState(fs16, stateFile, state) {
|
|
4042
|
+
fs16.mkdirp(import_node_path10.default.dirname(stateFile));
|
|
4043
|
+
fs16.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
4039
4044
|
`);
|
|
4040
4045
|
}
|
|
4041
4046
|
function directOrigin(port) {
|
|
@@ -4045,37 +4050,37 @@ function frontDoorOrigin(state) {
|
|
|
4045
4050
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
4046
4051
|
return port === void 0 ? void 0 : directOrigin(port);
|
|
4047
4052
|
}
|
|
4048
|
-
function writeFrontDoorDirectRecord(
|
|
4049
|
-
|
|
4050
|
-
|
|
4053
|
+
function writeFrontDoorDirectRecord(fs16, recordsDir, record) {
|
|
4054
|
+
fs16.mkdirp(recordsDir);
|
|
4055
|
+
fs16.writeFilePrivate(import_node_path10.default.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
|
|
4051
4056
|
`);
|
|
4052
4057
|
}
|
|
4053
|
-
function removeFrontDoorDirectRecord(
|
|
4054
|
-
|
|
4058
|
+
function removeFrontDoorDirectRecord(fs16, recordsDir, pid) {
|
|
4059
|
+
fs16.removeRecursive(import_node_path10.default.join(recordsDir, `${String(pid)}.json`));
|
|
4055
4060
|
}
|
|
4056
|
-
function markFrontDoorDraining(
|
|
4057
|
-
|
|
4058
|
-
|
|
4061
|
+
function markFrontDoorDraining(fs16, markersDir, pid) {
|
|
4062
|
+
fs16.mkdirp(markersDir);
|
|
4063
|
+
fs16.writeFilePrivate(import_node_path10.default.join(markersDir, String(pid)), "\n");
|
|
4059
4064
|
}
|
|
4060
|
-
function unmarkFrontDoorDraining(
|
|
4061
|
-
|
|
4065
|
+
function unmarkFrontDoorDraining(fs16, markersDir, pid) {
|
|
4066
|
+
fs16.removeRecursive(import_node_path10.default.join(markersDir, String(pid)));
|
|
4062
4067
|
}
|
|
4063
|
-
function listDrainingFrontDoors(
|
|
4064
|
-
return
|
|
4068
|
+
function listDrainingFrontDoors(fs16, markersDir, isRunning) {
|
|
4069
|
+
return fs16.readdir(markersDir).flatMap((file) => /^[1-9]\d*$/.test(file) && Number.isSafeInteger(Number(file)) ? [Number(file)] : []).filter(isRunning).sort((a, b) => a - b);
|
|
4065
4070
|
}
|
|
4066
4071
|
function recordPid(file) {
|
|
4067
4072
|
const pidText = /^([1-9]\d*)\.json$/.exec(file)?.[1];
|
|
4068
4073
|
const pid = pidText === void 0 ? void 0 : Number(pidText);
|
|
4069
4074
|
return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
|
|
4070
4075
|
}
|
|
4071
|
-
function readDirectRecordEntry(
|
|
4076
|
+
function readDirectRecordEntry(fs16, recordsDir, file) {
|
|
4072
4077
|
const pid = recordPid(file);
|
|
4073
4078
|
if (pid === void 0) {
|
|
4074
4079
|
return void 0;
|
|
4075
4080
|
}
|
|
4076
4081
|
let raw;
|
|
4077
4082
|
try {
|
|
4078
|
-
raw =
|
|
4083
|
+
raw = fs16.readFileUtf8(import_node_path10.default.join(recordsDir, file));
|
|
4079
4084
|
} catch {
|
|
4080
4085
|
return void 0;
|
|
4081
4086
|
}
|
|
@@ -4089,37 +4094,37 @@ function readDirectRecordEntry(fs15, recordsDir, file) {
|
|
|
4089
4094
|
return { malformed: true };
|
|
4090
4095
|
}
|
|
4091
4096
|
}
|
|
4092
|
-
function listFrontDoorDirectRecords(
|
|
4093
|
-
return
|
|
4094
|
-
const entry = readDirectRecordEntry(
|
|
4097
|
+
function listFrontDoorDirectRecords(fs16, recordsDir) {
|
|
4098
|
+
return fs16.readdir(recordsDir).flatMap((file) => {
|
|
4099
|
+
const entry = readDirectRecordEntry(fs16, recordsDir, file);
|
|
4095
4100
|
return entry?.record === void 0 ? [] : [entry.record];
|
|
4096
4101
|
}).sort((a, b) => a.pid - b.pid);
|
|
4097
4102
|
}
|
|
4098
|
-
function pruneMalformedFrontDoorDirectFiles(
|
|
4099
|
-
for (const file of
|
|
4103
|
+
function pruneMalformedFrontDoorDirectFiles(fs16, recordsDir, isRunning) {
|
|
4104
|
+
for (const file of fs16.readdir(recordsDir)) {
|
|
4100
4105
|
const writer = RECORD_TEMPORARY_FILE.exec(file)?.[1];
|
|
4101
4106
|
const stale = writer !== void 0 && !isRunning(Number(writer));
|
|
4102
|
-
if (stale || readDirectRecordEntry(
|
|
4103
|
-
|
|
4107
|
+
if (stale || readDirectRecordEntry(fs16, recordsDir, file)?.malformed === true) {
|
|
4108
|
+
fs16.removeRecursive(import_node_path10.default.join(recordsDir, file));
|
|
4104
4109
|
}
|
|
4105
4110
|
}
|
|
4106
4111
|
}
|
|
4107
4112
|
function liveFrontDoorDirectRecords(records, liveness) {
|
|
4108
4113
|
return records.filter((record) => liveness.doors.has(record.pid) || liveness.unknown.has(record.pid));
|
|
4109
4114
|
}
|
|
4110
|
-
function pruneDeadFrontDoorDirectRecords(
|
|
4115
|
+
function pruneDeadFrontDoorDirectRecords(fs16, recordsDir, records, liveness) {
|
|
4111
4116
|
for (const record of records) {
|
|
4112
4117
|
if (!liveness.doors.has(record.pid) && !liveness.unknown.has(record.pid)) {
|
|
4113
|
-
removeFrontDoorDirectRecord(
|
|
4118
|
+
removeFrontDoorDirectRecord(fs16, recordsDir, record.pid);
|
|
4114
4119
|
}
|
|
4115
4120
|
}
|
|
4116
4121
|
}
|
|
4117
4122
|
function recordOf(details) {
|
|
4118
4123
|
return details === void 0 ? {} : { sessionId: details.sessionId, ...details.models === void 0 ? {} : { models: details.models } };
|
|
4119
4124
|
}
|
|
4120
|
-
function writeFrontDoorSession(
|
|
4121
|
-
|
|
4122
|
-
|
|
4125
|
+
function writeFrontDoorSession(fs16, sessionsDir, session) {
|
|
4126
|
+
fs16.mkdirPrivate(sessionsDir);
|
|
4127
|
+
fs16.writeFilePrivate(import_node_path10.default.join(sessionsDir, sessionRecordName(session.pid)), `${JSON.stringify(session, null, 2)}
|
|
4123
4128
|
`);
|
|
4124
4129
|
}
|
|
4125
4130
|
function sessionRecordName(pid) {
|
|
@@ -4131,32 +4136,32 @@ function isSessionRecordName(name) {
|
|
|
4131
4136
|
function summaryOf(session) {
|
|
4132
4137
|
return { pid: session.pid, startedAt: session.startedAt, ...session.supervisorPid === void 0 ? {} : { supervisorPid: session.supervisorPid } };
|
|
4133
4138
|
}
|
|
4134
|
-
function readFrontDoorSessionRecord(
|
|
4139
|
+
function readFrontDoorSessionRecord(fs16, sessionsDir, name) {
|
|
4135
4140
|
try {
|
|
4136
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
4141
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs16.readFileUtf8(import_node_path10.default.join(sessionsDir, name)) ?? ""));
|
|
4137
4142
|
return parsed.success ? parsed.data : void 0;
|
|
4138
4143
|
} catch {
|
|
4139
4144
|
return void 0;
|
|
4140
4145
|
}
|
|
4141
4146
|
}
|
|
4142
|
-
function listFrontDoorSessions(
|
|
4147
|
+
function listFrontDoorSessions(fs16, sessionsDir) {
|
|
4143
4148
|
const sessions = [];
|
|
4144
|
-
for (const name of
|
|
4145
|
-
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(
|
|
4149
|
+
for (const name of fs16.readdir(sessionsDir)) {
|
|
4150
|
+
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(fs16, sessionsDir, name) : void 0;
|
|
4146
4151
|
if (record !== void 0) {
|
|
4147
4152
|
sessions.push(summaryOf(record));
|
|
4148
4153
|
}
|
|
4149
4154
|
}
|
|
4150
4155
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
4151
4156
|
}
|
|
4152
|
-
function removeFrontDoorSession(
|
|
4153
|
-
|
|
4157
|
+
function removeFrontDoorSession(fs16, sessionsDir, pid) {
|
|
4158
|
+
fs16.removeRecursive(import_node_path10.default.join(sessionsDir, sessionRecordName(pid)));
|
|
4154
4159
|
}
|
|
4155
|
-
function pruneDeadFrontDoorSessions(
|
|
4160
|
+
function pruneDeadFrontDoorSessions(fs16, sessionsDir, listed, isRunning) {
|
|
4156
4161
|
const removed = [];
|
|
4157
4162
|
for (const session of listed) {
|
|
4158
4163
|
if (!isRunning(session.pid)) {
|
|
4159
|
-
removeFrontDoorSession(
|
|
4164
|
+
removeFrontDoorSession(fs16, sessionsDir, session.pid);
|
|
4160
4165
|
removed.push(session.pid);
|
|
4161
4166
|
}
|
|
4162
4167
|
}
|
|
@@ -4239,19 +4244,19 @@ var init_processRole = __esm({
|
|
|
4239
4244
|
});
|
|
4240
4245
|
|
|
4241
4246
|
// src/frontdoor/catalogueCleanup.ts
|
|
4242
|
-
async function pruneAbandonedCatalogueGenerations(
|
|
4247
|
+
async function pruneAbandonedCatalogueGenerations(fs16, paths, ownPid, generation, runningAmong) {
|
|
4243
4248
|
const root = import_node_path11.default.join(paths.catalogueDir, "supervisors");
|
|
4244
|
-
const owners =
|
|
4249
|
+
const owners = fs16.readdir(root).flatMap((entry) => {
|
|
4245
4250
|
const pid = Number(entry);
|
|
4246
|
-
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry &&
|
|
4251
|
+
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry && fs16.lstat(import_node_path11.default.join(root, entry))?.kind === "dir" ? [pid] : [];
|
|
4247
4252
|
});
|
|
4248
4253
|
const running = await runningAmong(owners);
|
|
4249
4254
|
for (const pid of owners) {
|
|
4250
4255
|
if (pid !== ownPid && running.has(pid)) continue;
|
|
4251
4256
|
const directory = import_node_path11.default.join(root, String(pid));
|
|
4252
|
-
for (const entry of
|
|
4257
|
+
for (const entry of fs16.readdir(directory)) {
|
|
4253
4258
|
const candidate = import_node_path11.default.join(directory, entry);
|
|
4254
|
-
if (import_zod7.z.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) &&
|
|
4259
|
+
if (import_zod7.z.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) && fs16.lstat(candidate)?.kind === "dir") fs16.removeRecursive(candidate);
|
|
4255
4260
|
}
|
|
4256
4261
|
}
|
|
4257
4262
|
}
|
|
@@ -4282,9 +4287,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
4282
4287
|
}
|
|
4283
4288
|
}
|
|
4284
4289
|
async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
4285
|
-
const { fs:
|
|
4290
|
+
const { fs: fs16, paths } = ports;
|
|
4286
4291
|
const servingBinary = ports.statOwnExecutable();
|
|
4287
|
-
const previous = readFrontDoorState(
|
|
4292
|
+
const previous = readFrontDoorState(fs16, paths.frontdoorStateFile);
|
|
4288
4293
|
let lastPort = previous?.lastPort;
|
|
4289
4294
|
let lastConnectPort = previous?.lastConnectPort;
|
|
4290
4295
|
let lastDirectPort = previous?.lastDirectPort;
|
|
@@ -4298,8 +4303,8 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4298
4303
|
const fail = async (message) => {
|
|
4299
4304
|
ports.closeRcStreamHub();
|
|
4300
4305
|
if (predecessor === void 0) {
|
|
4301
|
-
writeFrontDoorState(
|
|
4302
|
-
|
|
4306
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { lastError: message, ...sticky() });
|
|
4307
|
+
fs16.removeRecursive(paths.frontdoorLockFile);
|
|
4303
4308
|
}
|
|
4304
4309
|
ports.log(`agent-shim frontdoor supervisor: ${message}`);
|
|
4305
4310
|
const chain = ports.respawnChain;
|
|
@@ -4310,7 +4315,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4310
4315
|
return 1;
|
|
4311
4316
|
};
|
|
4312
4317
|
if (predecessor === void 0) {
|
|
4313
|
-
writeFrontDoorState(
|
|
4318
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
|
|
4314
4319
|
}
|
|
4315
4320
|
const previousSticky = lastPort;
|
|
4316
4321
|
let http3;
|
|
@@ -4351,14 +4356,14 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4351
4356
|
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)`);
|
|
4352
4357
|
}
|
|
4353
4358
|
lastDirectPort = direct.port;
|
|
4354
|
-
writeFrontDoorDirectRecord(
|
|
4355
|
-
writeFrontDoorCodexHome(
|
|
4356
|
-
writeFrontDoorState(
|
|
4357
|
-
await pruneAbandonedCatalogueGenerations(
|
|
4359
|
+
writeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
|
|
4360
|
+
writeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid, ports.codexHome, ports.catalogueGeneration);
|
|
4361
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http3.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
|
|
4362
|
+
await pruneAbandonedCatalogueGenerations(fs16, paths, ports.ownPid, ports.catalogueGeneration, ports.runningAmong);
|
|
4358
4363
|
ports.onServing();
|
|
4359
4364
|
ports.doorHealth.generation({ providerPort: http3.port, connectPort: connect3.port, directPort: direct.port });
|
|
4360
4365
|
if (predecessor === void 0) {
|
|
4361
|
-
|
|
4366
|
+
fs16.removeRecursive(paths.frontdoorLockFile);
|
|
4362
4367
|
} else {
|
|
4363
4368
|
predecessor.serving();
|
|
4364
4369
|
}
|
|
@@ -4367,7 +4372,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4367
4372
|
let idleSince;
|
|
4368
4373
|
let ticks = 0;
|
|
4369
4374
|
const supersedingOwner = async () => {
|
|
4370
|
-
const owner = readFrontDoorState(
|
|
4375
|
+
const owner = readFrontDoorState(fs16, paths.frontdoorStateFile)?.supervisorPid;
|
|
4371
4376
|
return owner !== void 0 && owner !== ports.ownPid && (await ports.runningAmong([owner])).has(owner) ? owner : void 0;
|
|
4372
4377
|
};
|
|
4373
4378
|
let supersededBy;
|
|
@@ -4396,15 +4401,15 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4396
4401
|
ports.stopBackgroundWork?.();
|
|
4397
4402
|
const drained = [direct.drain(), connect3.drain(), http3.drain()];
|
|
4398
4403
|
if (await supersedingOwner() === void 0) {
|
|
4399
|
-
writeFrontDoorState(
|
|
4404
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, sticky());
|
|
4400
4405
|
}
|
|
4401
|
-
markFrontDoorDraining(
|
|
4406
|
+
markFrontDoorDraining(fs16, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4402
4407
|
ports.closeRcStreamHub();
|
|
4403
4408
|
await Promise.all(drained);
|
|
4404
|
-
unmarkFrontDoorDraining(
|
|
4405
|
-
removeFrontDoorDirectRecord(
|
|
4406
|
-
removeFrontDoorCodexHome(
|
|
4407
|
-
|
|
4409
|
+
unmarkFrontDoorDraining(fs16, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4410
|
+
removeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4411
|
+
removeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid);
|
|
4412
|
+
fs16.removeRecursive(catalogueGenerationDir(paths, ports.ownPid, ports.catalogueGeneration));
|
|
4408
4413
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: the connections this door carried have ended; exiting`);
|
|
4409
4414
|
return 0;
|
|
4410
4415
|
};
|
|
@@ -4425,14 +4430,14 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4425
4430
|
await connect3.close();
|
|
4426
4431
|
await http3.close();
|
|
4427
4432
|
ports.closeRcStreamHub();
|
|
4428
|
-
removeFrontDoorDirectRecord(
|
|
4429
|
-
removeFrontDoorCodexHome(
|
|
4430
|
-
|
|
4433
|
+
removeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4434
|
+
removeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid);
|
|
4435
|
+
fs16.removeRecursive(catalogueGenerationDir(paths, ports.ownPid, ports.catalogueGeneration));
|
|
4431
4436
|
};
|
|
4432
4437
|
const shutdown = async () => {
|
|
4433
4438
|
await closeServing();
|
|
4434
4439
|
if (await supersedingOwner() === void 0) {
|
|
4435
|
-
writeFrontDoorState(
|
|
4440
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, sticky());
|
|
4436
4441
|
}
|
|
4437
4442
|
return 0;
|
|
4438
4443
|
};
|
|
@@ -4451,7 +4456,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4451
4456
|
ticks += 1;
|
|
4452
4457
|
const listed = ports.registry.rescan();
|
|
4453
4458
|
const running = await ports.runningAmong(listed.map((session) => session.pid));
|
|
4454
|
-
const pruned = pruneDeadFrontDoorSessions(
|
|
4459
|
+
const pruned = pruneDeadFrontDoorSessions(fs16, paths.frontdoorSessionsDir, listed, (pid) => running.has(pid));
|
|
4455
4460
|
ports.registry.forget(pruned);
|
|
4456
4461
|
ports.observeLaunchRegistry(listed, pruned);
|
|
4457
4462
|
ports.checkQuotaExpiry();
|
|
@@ -4527,8 +4532,8 @@ function parseConnectTarget(authority) {
|
|
|
4527
4532
|
function isInterceptedHost(host, interceptHosts) {
|
|
4528
4533
|
return interceptHosts.includes(host);
|
|
4529
4534
|
}
|
|
4530
|
-
function servedByPipeline(
|
|
4531
|
-
return
|
|
4535
|
+
function servedByPipeline(path49) {
|
|
4536
|
+
return path49?.startsWith(ROUTED_PATH_PREFIX) === true;
|
|
4532
4537
|
}
|
|
4533
4538
|
function forwardableHeaders(headers) {
|
|
4534
4539
|
const connectionTokens = new Set(
|
|
@@ -4974,7 +4979,7 @@ var init_package = __esm({
|
|
|
4974
4979
|
"package.json"() {
|
|
4975
4980
|
package_default = {
|
|
4976
4981
|
name: "agent-shim",
|
|
4977
|
-
version: "11.
|
|
4982
|
+
version: "11.85.0",
|
|
4978
4983
|
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.",
|
|
4979
4984
|
license: "MIT",
|
|
4980
4985
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -5196,43 +5201,43 @@ function parseJson(raw, schema) {
|
|
|
5196
5201
|
const parsed = schema.safeParse(JSON.parse(raw));
|
|
5197
5202
|
return parsed.success ? parsed.data : void 0;
|
|
5198
5203
|
}
|
|
5199
|
-
function readHeadroomState(
|
|
5204
|
+
function readHeadroomState(fs16, stateFile) {
|
|
5200
5205
|
try {
|
|
5201
|
-
return parseJson(
|
|
5206
|
+
return parseJson(fs16.readFileUtf8(stateFile), HeadroomStateSchema);
|
|
5202
5207
|
} catch {
|
|
5203
5208
|
return void 0;
|
|
5204
5209
|
}
|
|
5205
5210
|
}
|
|
5206
|
-
function writeHeadroomState(
|
|
5207
|
-
|
|
5208
|
-
|
|
5211
|
+
function writeHeadroomState(fs16, stateFile, state) {
|
|
5212
|
+
fs16.mkdirp(import_node_path14.default.dirname(stateFile));
|
|
5213
|
+
fs16.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
5209
5214
|
`);
|
|
5210
5215
|
}
|
|
5211
|
-
function resolveServingHeadroomState(
|
|
5212
|
-
const current = readHeadroomState(
|
|
5216
|
+
function resolveServingHeadroomState(fs16, files, isRunning) {
|
|
5217
|
+
const current = readHeadroomState(fs16, files.stateFile);
|
|
5213
5218
|
if (current !== void 0) {
|
|
5214
5219
|
return { path: files.stateFile, state: current };
|
|
5215
5220
|
}
|
|
5216
|
-
const legacy = readHeadroomState(
|
|
5221
|
+
const legacy = readHeadroomState(fs16, files.legacyStateFile);
|
|
5217
5222
|
if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
|
|
5218
5223
|
return { path: files.legacyStateFile, state: legacy };
|
|
5219
5224
|
}
|
|
5220
5225
|
return void 0;
|
|
5221
5226
|
}
|
|
5222
|
-
function migrateHeadroomState(
|
|
5223
|
-
const legacy = readHeadroomState(
|
|
5227
|
+
function migrateHeadroomState(fs16, files, isRunning) {
|
|
5228
|
+
const legacy = readHeadroomState(fs16, files.legacyStateFile);
|
|
5224
5229
|
const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
|
|
5225
|
-
const current = readHeadroomState(
|
|
5230
|
+
const current = readHeadroomState(fs16, files.stateFile);
|
|
5226
5231
|
if (current !== void 0 || legacyLive) {
|
|
5227
|
-
if (!legacyLive &&
|
|
5228
|
-
|
|
5232
|
+
if (!legacyLive && fs16.readFileUtf8(files.legacyStateFile) !== void 0) {
|
|
5233
|
+
fs16.removeRecursive(files.legacyStateFile);
|
|
5229
5234
|
}
|
|
5230
5235
|
return;
|
|
5231
5236
|
}
|
|
5232
5237
|
if (legacy !== void 0) {
|
|
5233
|
-
writeHeadroomState(
|
|
5238
|
+
writeHeadroomState(fs16, files.stateFile, legacy);
|
|
5234
5239
|
}
|
|
5235
|
-
|
|
5240
|
+
fs16.removeRecursive(files.legacyStateFile);
|
|
5236
5241
|
}
|
|
5237
5242
|
function hashAllowlist(allowlist) {
|
|
5238
5243
|
return (0, import_node_crypto6.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
@@ -5265,27 +5270,27 @@ function isAdmissibleUrl(entry) {
|
|
|
5265
5270
|
function parseAllowlistFile(content) {
|
|
5266
5271
|
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)));
|
|
5267
5272
|
}
|
|
5268
|
-
function writeAllowlistFile(
|
|
5269
|
-
|
|
5270
|
-
|
|
5273
|
+
function writeAllowlistFile(fs16, allowlistFile, allowlist) {
|
|
5274
|
+
fs16.mkdirPrivate(import_node_path14.default.dirname(allowlistFile));
|
|
5275
|
+
fs16.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
|
|
5271
5276
|
}
|
|
5272
|
-
function pruneStaleAllowlistTemporaries(
|
|
5277
|
+
function pruneStaleAllowlistTemporaries(fs16, allowlistFile, isRunning) {
|
|
5273
5278
|
const prefix = `${import_node_path14.default.basename(allowlistFile)}.`;
|
|
5274
|
-
for (const name of
|
|
5279
|
+
for (const name of fs16.readdir(import_node_path14.default.dirname(allowlistFile))) {
|
|
5275
5280
|
const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
|
|
5276
5281
|
if (writer !== void 0 && !isRunning(Number(writer))) {
|
|
5277
|
-
|
|
5282
|
+
fs16.removeRecursive(import_node_path14.default.join(import_node_path14.default.dirname(allowlistFile), name));
|
|
5278
5283
|
}
|
|
5279
5284
|
}
|
|
5280
5285
|
}
|
|
5281
|
-
function readAllProviders(
|
|
5286
|
+
function readAllProviders(fs16, providersDir) {
|
|
5282
5287
|
const result = [];
|
|
5283
|
-
for (const name of
|
|
5288
|
+
for (const name of fs16.readdir(providersDir)) {
|
|
5284
5289
|
if (!name.endsWith(".json")) {
|
|
5285
5290
|
continue;
|
|
5286
5291
|
}
|
|
5287
5292
|
try {
|
|
5288
|
-
const parsed = parseJson(
|
|
5293
|
+
const parsed = parseJson(fs16.readFileUtf8(import_node_path14.default.join(providersDir, name)), ProviderSchema);
|
|
5289
5294
|
if (parsed !== void 0) {
|
|
5290
5295
|
result.push({ name: name.slice(0, -".json".length), provider: parsed });
|
|
5291
5296
|
}
|
|
@@ -5295,22 +5300,22 @@ function readAllProviders(fs15, providersDir) {
|
|
|
5295
5300
|
}
|
|
5296
5301
|
return result;
|
|
5297
5302
|
}
|
|
5298
|
-
function writeSession(
|
|
5299
|
-
|
|
5300
|
-
|
|
5303
|
+
function writeSession(fs16, sessionsDir, session) {
|
|
5304
|
+
fs16.mkdirp(sessionsDir);
|
|
5305
|
+
fs16.writeFileUtf8(import_node_path14.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
5301
5306
|
`);
|
|
5302
5307
|
}
|
|
5303
|
-
function removeSession(
|
|
5304
|
-
|
|
5308
|
+
function removeSession(fs16, sessionsDir, pid) {
|
|
5309
|
+
fs16.removeRecursive(import_node_path14.default.join(sessionsDir, `${String(pid)}.json`));
|
|
5305
5310
|
}
|
|
5306
|
-
function listSessions(
|
|
5311
|
+
function listSessions(fs16, sessionsDir) {
|
|
5307
5312
|
const sessions = [];
|
|
5308
|
-
for (const name of
|
|
5313
|
+
for (const name of fs16.readdir(sessionsDir)) {
|
|
5309
5314
|
if (!name.endsWith(".json")) {
|
|
5310
5315
|
continue;
|
|
5311
5316
|
}
|
|
5312
5317
|
try {
|
|
5313
|
-
const parsed = parseJson(
|
|
5318
|
+
const parsed = parseJson(fs16.readFileUtf8(import_node_path14.default.join(sessionsDir, name)), HeadroomSessionSchema);
|
|
5314
5319
|
if (parsed !== void 0) {
|
|
5315
5320
|
sessions.push(parsed);
|
|
5316
5321
|
}
|
|
@@ -5320,22 +5325,22 @@ function listSessions(fs15, sessionsDir) {
|
|
|
5320
5325
|
}
|
|
5321
5326
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
5322
5327
|
}
|
|
5323
|
-
function sessionsForSupervisor(
|
|
5324
|
-
return listSessions(
|
|
5328
|
+
function sessionsForSupervisor(fs16, sessionsDir, supervisorPid) {
|
|
5329
|
+
return listSessions(fs16, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
|
|
5325
5330
|
}
|
|
5326
|
-
function pruneDeadSessions(
|
|
5331
|
+
function pruneDeadSessions(fs16, sessionsDir, isRunning) {
|
|
5327
5332
|
const removed = [];
|
|
5328
|
-
for (const session of listSessions(
|
|
5333
|
+
for (const session of listSessions(fs16, sessionsDir)) {
|
|
5329
5334
|
if (!isRunning(session.pid)) {
|
|
5330
|
-
removeSession(
|
|
5335
|
+
removeSession(fs16, sessionsDir, session.pid);
|
|
5331
5336
|
removed.push(session.pid);
|
|
5332
5337
|
}
|
|
5333
5338
|
}
|
|
5334
5339
|
return removed;
|
|
5335
5340
|
}
|
|
5336
|
-
function readStartLock(
|
|
5341
|
+
function readStartLock(fs16, lockFile) {
|
|
5337
5342
|
try {
|
|
5338
|
-
return parseJson(
|
|
5343
|
+
return parseJson(fs16.readFileUtf8(lockFile), HeadroomLockSchema);
|
|
5339
5344
|
} catch {
|
|
5340
5345
|
return void 0;
|
|
5341
5346
|
}
|
|
@@ -5428,12 +5433,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
|
|
|
5428
5433
|
}
|
|
5429
5434
|
return hashAllowlist([...entries].sort());
|
|
5430
5435
|
}
|
|
5431
|
-
function earlierReleaseDaemon(
|
|
5436
|
+
function earlierReleaseDaemon(fs16, paths, daemon) {
|
|
5432
5437
|
if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
|
|
5433
5438
|
return void 0;
|
|
5434
5439
|
}
|
|
5435
|
-
const providers = readAllProviders(
|
|
5436
|
-
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(
|
|
5440
|
+
const providers = readAllProviders(fs16, paths.providersDir).map((entry) => entry.provider);
|
|
5441
|
+
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile)));
|
|
5437
5442
|
return { admitsServingDoor: daemon.recordedHash === expected };
|
|
5438
5443
|
}
|
|
5439
5444
|
var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
|
|
@@ -5458,8 +5463,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
|
|
|
5458
5463
|
}
|
|
5459
5464
|
return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
|
|
5460
5465
|
}
|
|
5461
|
-
function daemonAdmits(
|
|
5462
|
-
const content =
|
|
5466
|
+
function daemonAdmits(fs16, allowlistFile, recordedHash, required) {
|
|
5467
|
+
const content = fs16.readFileUtf8(allowlistFile);
|
|
5463
5468
|
if (content === void 0 || recordedHash === void 0) {
|
|
5464
5469
|
return false;
|
|
5465
5470
|
}
|
|
@@ -5728,7 +5733,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
|
|
|
5728
5733
|
const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
|
|
5729
5734
|
return { message: refusal2, repairable: replaceable };
|
|
5730
5735
|
}
|
|
5731
|
-
function prepareHeadroomSocket(
|
|
5736
|
+
function prepareHeadroomSocket(fs16, ports, paths, supervisorPid) {
|
|
5732
5737
|
const unsupported = platformRefusal(ports.platform);
|
|
5733
5738
|
if (unsupported !== void 0) {
|
|
5734
5739
|
return { refused: unsupported };
|
|
@@ -5743,18 +5748,18 @@ function prepareHeadroomSocket(fs15, ports, paths, supervisorPid) {
|
|
|
5743
5748
|
if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
|
|
5744
5749
|
return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
|
|
5745
5750
|
}
|
|
5746
|
-
|
|
5751
|
+
fs16.mkdirPrivate(paths.headroomSocketDir);
|
|
5747
5752
|
const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
|
|
5748
5753
|
return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
|
|
5749
5754
|
}
|
|
5750
|
-
function pruneStaleHeadroomSockets(
|
|
5755
|
+
function pruneStaleHeadroomSockets(fs16, paths, isRunning) {
|
|
5751
5756
|
const removed = [];
|
|
5752
|
-
for (const name of
|
|
5757
|
+
for (const name of fs16.readdir(paths.headroomSocketDir)) {
|
|
5753
5758
|
const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
|
|
5754
5759
|
if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
|
|
5755
5760
|
continue;
|
|
5756
5761
|
}
|
|
5757
|
-
|
|
5762
|
+
fs16.removeRecursive(import_node_path15.default.join(paths.headroomSocketDir, name));
|
|
5758
5763
|
removed.push(name);
|
|
5759
5764
|
}
|
|
5760
5765
|
return removed;
|
|
@@ -5866,37 +5871,37 @@ function compareVersions2(a, b) {
|
|
|
5866
5871
|
return 0;
|
|
5867
5872
|
}
|
|
5868
5873
|
async function runSupervisor(initialConfig, ports, options = {}) {
|
|
5869
|
-
const { fs:
|
|
5874
|
+
const { fs: fs16, paths } = ports;
|
|
5870
5875
|
let config = initialConfig;
|
|
5871
|
-
migrateHeadroomState(
|
|
5872
|
-
const previousState = resolveServingHeadroomState(
|
|
5876
|
+
migrateHeadroomState(fs16, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
|
|
5877
|
+
const previousState = resolveServingHeadroomState(fs16, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
|
|
5873
5878
|
if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
|
|
5874
5879
|
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
|
|
5875
5880
|
return 0;
|
|
5876
5881
|
}
|
|
5877
5882
|
let installedSource = previousState?.installedSource;
|
|
5878
5883
|
const ownsState = () => {
|
|
5879
|
-
const owner = readHeadroomState(
|
|
5884
|
+
const owner = readHeadroomState(fs16, paths.headroomStateFile)?.supervisorPid;
|
|
5880
5885
|
return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
|
|
5881
5886
|
};
|
|
5882
5887
|
const writeOwnState = (state) => {
|
|
5883
5888
|
if (!ownsState()) {
|
|
5884
5889
|
return false;
|
|
5885
5890
|
}
|
|
5886
|
-
writeHeadroomState(
|
|
5891
|
+
writeHeadroomState(fs16, paths.headroomStateFile, state);
|
|
5887
5892
|
return true;
|
|
5888
5893
|
};
|
|
5889
5894
|
const fail = (message) => {
|
|
5890
5895
|
if (writeOwnState({ lastError: message })) {
|
|
5891
|
-
|
|
5896
|
+
fs16.removeRecursive(paths.headroomLockFile);
|
|
5892
5897
|
}
|
|
5893
5898
|
ports.log(`agent-shim headroom supervisor: ${message}`);
|
|
5894
5899
|
return 1;
|
|
5895
5900
|
};
|
|
5896
5901
|
const syncAllowlistFile = (allowlist) => {
|
|
5897
5902
|
try {
|
|
5898
|
-
if (
|
|
5899
|
-
writeAllowlistFile(
|
|
5903
|
+
if (fs16.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
|
|
5904
|
+
writeAllowlistFile(fs16, paths.headroomAllowlistFile, allowlist);
|
|
5900
5905
|
ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
|
|
5901
5906
|
}
|
|
5902
5907
|
return void 0;
|
|
@@ -5914,9 +5919,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5914
5919
|
}
|
|
5915
5920
|
ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
|
|
5916
5921
|
try {
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
writeAllowlistFile(
|
|
5922
|
+
fs16.mkdirPrivate(paths.headroomDir);
|
|
5923
|
+
fs16.mkdirPrivate(import_node_path16.default.dirname(paths.headroomAllowlistFile));
|
|
5924
|
+
writeAllowlistFile(fs16, paths.headroomAllowlistFile, allowlist);
|
|
5920
5925
|
} catch (error) {
|
|
5921
5926
|
return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error instanceof Error ? error.message : String(error)}`;
|
|
5922
5927
|
}
|
|
@@ -5941,20 +5946,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5941
5946
|
installedSource = config.source;
|
|
5942
5947
|
return void 0;
|
|
5943
5948
|
};
|
|
5944
|
-
const socket = prepareHeadroomSocket(
|
|
5949
|
+
const socket = prepareHeadroomSocket(fs16, ports.socketTrust, paths, ports.ownPid);
|
|
5945
5950
|
if (socket.refused !== void 0) {
|
|
5946
5951
|
return fail(socket.refused);
|
|
5947
5952
|
}
|
|
5948
5953
|
const { socketPath } = socket;
|
|
5949
|
-
pruneStaleHeadroomSockets(
|
|
5950
|
-
pruneStaleAllowlistTemporaries(
|
|
5954
|
+
pruneStaleHeadroomSockets(fs16, paths, ports.isRunning);
|
|
5955
|
+
pruneStaleAllowlistTemporaries(fs16, paths.headroomAllowlistFile, ports.isRunning);
|
|
5951
5956
|
const installFailure = ensureInstalled();
|
|
5952
5957
|
if (installFailure !== void 0) {
|
|
5953
5958
|
return fail(installFailure);
|
|
5954
5959
|
}
|
|
5955
5960
|
const version = ports.headroomVersion() ?? "unknown";
|
|
5956
5961
|
writeOwnState({ supervisorPid: ports.ownPid, version, installedSource });
|
|
5957
|
-
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(
|
|
5962
|
+
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs16, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
|
|
5958
5963
|
const orphanPid = previousState?.headroomPid;
|
|
5959
5964
|
const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
|
|
5960
5965
|
const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
|
|
@@ -5992,12 +5997,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5992
5997
|
}
|
|
5993
5998
|
config = ports.readConfig();
|
|
5994
5999
|
const settingsHash = hashSettings(config.settings);
|
|
5995
|
-
const inputs = currentHeadroomAllowlistInputs(
|
|
5996
|
-
pruneDeadFrontDoorDirectRecords(
|
|
5997
|
-
pruneMalformedFrontDoorDirectFiles(
|
|
6000
|
+
const inputs = currentHeadroomAllowlistInputs(fs16, paths, ports.frontDoorLiveness);
|
|
6001
|
+
pruneDeadFrontDoorDirectRecords(fs16, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
|
|
6002
|
+
pruneMalformedFrontDoorDirectFiles(fs16, paths.frontdoorDirectRecordsDir, ports.isRunning);
|
|
5998
6003
|
const allowlist = inputs.frontDoorOrigins;
|
|
5999
6004
|
const allowlistHash = hashAllowlist(allowlist);
|
|
6000
|
-
pruneDeadSessions(
|
|
6005
|
+
pruneDeadSessions(fs16, paths.headroomSessionsDir, ports.isRunning);
|
|
6001
6006
|
const ownsNow = ownsState();
|
|
6002
6007
|
if (!ownsNow && !superseded) {
|
|
6003
6008
|
ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
|
|
@@ -6044,7 +6049,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6044
6049
|
runningSettingsHash = settingsHash;
|
|
6045
6050
|
const recorded = writeOwnState(servingState(pid));
|
|
6046
6051
|
if (recorded) {
|
|
6047
|
-
|
|
6052
|
+
fs16.removeRecursive(paths.headroomLockFile);
|
|
6048
6053
|
}
|
|
6049
6054
|
idleSince = void 0;
|
|
6050
6055
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
|
|
@@ -6072,7 +6077,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6072
6077
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
|
|
6073
6078
|
}
|
|
6074
6079
|
if (runningSettingsHash !== settingsHash || installedSource !== config.source) {
|
|
6075
|
-
if (sessionsForSupervisor(
|
|
6080
|
+
if (sessionsForSupervisor(fs16, paths.headroomSessionsDir, ports.ownPid).length === 0) {
|
|
6076
6081
|
ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
|
|
6077
6082
|
ports.stopProcess(headroomPid);
|
|
6078
6083
|
headroomPid = void 0;
|
|
@@ -6081,7 +6086,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6081
6086
|
continue;
|
|
6082
6087
|
}
|
|
6083
6088
|
}
|
|
6084
|
-
const sessions = sessionsForSupervisor(
|
|
6089
|
+
const sessions = sessionsForSupervisor(fs16, paths.headroomSessionsDir, ports.ownPid);
|
|
6085
6090
|
if (sessions.length === 0) {
|
|
6086
6091
|
idleSince ??= ports.now();
|
|
6087
6092
|
const idleMs = ports.now() - idleSince;
|
|
@@ -6106,9 +6111,9 @@ function undeterminedFrontDoors(inputs) {
|
|
|
6106
6111
|
return reason === void 0 ? [] : [{ pid: record.pid, origin: directOrigin(record.directPort), reason }];
|
|
6107
6112
|
});
|
|
6108
6113
|
}
|
|
6109
|
-
function currentHeadroomAllowlistInputs(
|
|
6110
|
-
const named = frontDoorOrigin(readFrontDoorState(
|
|
6111
|
-
const records = listFrontDoorDirectRecords(
|
|
6114
|
+
function currentHeadroomAllowlistInputs(fs16, paths, frontDoorLiveness) {
|
|
6115
|
+
const named = frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile));
|
|
6116
|
+
const records = listFrontDoorDirectRecords(fs16, paths.frontdoorDirectRecordsDir);
|
|
6112
6117
|
const liveness = frontDoorLiveness(records.map((record) => record.pid));
|
|
6113
6118
|
const live = liveFrontDoorDirectRecords(records, liveness).map((record) => directOrigin(record.directPort));
|
|
6114
6119
|
return {
|
|
@@ -6117,8 +6122,8 @@ function currentHeadroomAllowlistInputs(fs15, paths, frontDoorLiveness) {
|
|
|
6117
6122
|
frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
|
|
6118
6123
|
};
|
|
6119
6124
|
}
|
|
6120
|
-
function launchRequiredUpstreams(
|
|
6121
|
-
const door = frontDoorOrigin(readFrontDoorState(
|
|
6125
|
+
function launchRequiredUpstreams(fs16, paths) {
|
|
6126
|
+
const door = frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile));
|
|
6122
6127
|
return door === void 0 ? [] : [door];
|
|
6123
6128
|
}
|
|
6124
6129
|
async function waitUntilReady(ports, socketPath, pid) {
|
|
@@ -6909,8 +6914,8 @@ var init_cascade = __esm({
|
|
|
6909
6914
|
function poolNameOf(selector) {
|
|
6910
6915
|
return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
|
|
6911
6916
|
}
|
|
6912
|
-
function readActiveIdentity(
|
|
6913
|
-
const trimmed =
|
|
6917
|
+
function readActiveIdentity(fs16, activeIdentityFile) {
|
|
6918
|
+
const trimmed = fs16.readFileUtf8(activeIdentityFile)?.trim();
|
|
6914
6919
|
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
6915
6920
|
}
|
|
6916
6921
|
function isNonEmpty(value) {
|
|
@@ -6960,11 +6965,11 @@ function decideConfigProfile(params) {
|
|
|
6960
6965
|
}
|
|
6961
6966
|
return { source: "none" };
|
|
6962
6967
|
}
|
|
6963
|
-
function loadIdentity(identitiesDir, name,
|
|
6968
|
+
function loadIdentity(identitiesDir, name, fs16) {
|
|
6964
6969
|
if (!isFileName(name)) {
|
|
6965
6970
|
throw new UnsafeNameError(name, "identity", FILE_NAME_RULE);
|
|
6966
6971
|
}
|
|
6967
|
-
return loadConfigFile(import_node_path20.default.join(identitiesDir, name, "identity.json"), IdentitySchema,
|
|
6972
|
+
return loadConfigFile(import_node_path20.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs16.readConfigFile);
|
|
6968
6973
|
}
|
|
6969
6974
|
var import_node_path20, IDENTITY_DECISION_SOURCES, IDENTITY_SOURCE_LABELS, CONFIG_PROFILE_DECISION_SOURCES;
|
|
6970
6975
|
var init_identity = __esm({
|
|
@@ -7218,14 +7223,14 @@ function isIdentityName(name) {
|
|
|
7218
7223
|
function claudeJsonPath(identitiesDir, identity) {
|
|
7219
7224
|
return import_node_path21.default.join(identitiesDir, identity, CLAUDE_JSON);
|
|
7220
7225
|
}
|
|
7221
|
-
function readAccountMetadata(
|
|
7226
|
+
function readAccountMetadata(fs16, identitiesDir, identity) {
|
|
7222
7227
|
if (!isIdentityName(identity)) {
|
|
7223
7228
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
7224
7229
|
}
|
|
7225
|
-
return readAccountMetadataFile(
|
|
7230
|
+
return readAccountMetadataFile(fs16, claudeJsonPath(identitiesDir, identity));
|
|
7226
7231
|
}
|
|
7227
|
-
function readAccountMetadataFile(
|
|
7228
|
-
const raw =
|
|
7232
|
+
function readAccountMetadataFile(fs16, file) {
|
|
7233
|
+
const raw = fs16.readFileUtf8(file);
|
|
7229
7234
|
if (raw === void 0) {
|
|
7230
7235
|
return void 0;
|
|
7231
7236
|
}
|
|
@@ -7255,19 +7260,19 @@ function readAccountMetadataFile(fs15, file) {
|
|
|
7255
7260
|
}
|
|
7256
7261
|
return account.data;
|
|
7257
7262
|
}
|
|
7258
|
-
function createAccountReader(
|
|
7263
|
+
function createAccountReader(fs16, identitiesDir) {
|
|
7259
7264
|
const cache = /* @__PURE__ */ new Map();
|
|
7260
7265
|
return (identity) => {
|
|
7261
7266
|
if (!isIdentityName(identity)) {
|
|
7262
7267
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
7263
7268
|
}
|
|
7264
|
-
const stat =
|
|
7269
|
+
const stat = fs16.lstat(claudeJsonPath(identitiesDir, identity));
|
|
7265
7270
|
const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
|
|
7266
7271
|
const cached = cache.get(identity);
|
|
7267
7272
|
if (cached?.stamp === stamp) {
|
|
7268
7273
|
return cached.account;
|
|
7269
7274
|
}
|
|
7270
|
-
const account = readAccountMetadata(
|
|
7275
|
+
const account = readAccountMetadata(fs16, identitiesDir, identity);
|
|
7271
7276
|
cache.set(identity, { stamp, account });
|
|
7272
7277
|
return account;
|
|
7273
7278
|
};
|
|
@@ -7304,9 +7309,9 @@ var init_accountDescription = __esm({
|
|
|
7304
7309
|
});
|
|
7305
7310
|
|
|
7306
7311
|
// src/identityAccounts.ts
|
|
7307
|
-
function readIdentityAccount(
|
|
7312
|
+
function readIdentityAccount(fs16, identitiesDir, identity) {
|
|
7308
7313
|
try {
|
|
7309
|
-
const account = readAccountMetadata(
|
|
7314
|
+
const account = readAccountMetadata(fs16, identitiesDir, identity);
|
|
7310
7315
|
return account === void 0 ? void 0 : { account };
|
|
7311
7316
|
} catch (error) {
|
|
7312
7317
|
if (error instanceof AccountMetadataError) {
|
|
@@ -7944,8 +7949,8 @@ function segmentDay(epochMs) {
|
|
|
7944
7949
|
function segmentName(day, pid) {
|
|
7945
7950
|
return `${day}.${String(pid)}.jsonl`;
|
|
7946
7951
|
}
|
|
7947
|
-
function listLogSegments(
|
|
7948
|
-
return
|
|
7952
|
+
function listLogSegments(fs16, logDir) {
|
|
7953
|
+
return fs16.readdir(logDir).flatMap((name) => {
|
|
7949
7954
|
const match = SEGMENT_RE.exec(name);
|
|
7950
7955
|
const day = match?.[1];
|
|
7951
7956
|
if (day === void 0) {
|
|
@@ -7954,15 +7959,15 @@ function listLogSegments(fs15, logDir) {
|
|
|
7954
7959
|
return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
|
|
7955
7960
|
}).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
|
|
7956
7961
|
}
|
|
7957
|
-
function readUsageLog(
|
|
7962
|
+
function readUsageLog(fs16, logDir, options = {}) {
|
|
7958
7963
|
const { sinceMs } = options;
|
|
7959
7964
|
const records = [];
|
|
7960
7965
|
let invalidLines = 0;
|
|
7961
|
-
for (const segment of listLogSegments(
|
|
7966
|
+
for (const segment of listLogSegments(fs16, logDir)) {
|
|
7962
7967
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
7963
7968
|
continue;
|
|
7964
7969
|
}
|
|
7965
|
-
const read = readSegment(
|
|
7970
|
+
const read = readSegment(fs16, logDir, segment);
|
|
7966
7971
|
if (read === void 0) {
|
|
7967
7972
|
continue;
|
|
7968
7973
|
}
|
|
@@ -7976,8 +7981,8 @@ function readUsageLog(fs15, logDir, options = {}) {
|
|
|
7976
7981
|
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
7977
7982
|
return { records, invalidLines };
|
|
7978
7983
|
}
|
|
7979
|
-
function readSegment(
|
|
7980
|
-
const contents =
|
|
7984
|
+
function readSegment(fs16, logDir, segment) {
|
|
7985
|
+
const contents = fs16.readFileUtf8(import_node_path22.default.join(logDir, segment.name));
|
|
7981
7986
|
if (contents === void 0) {
|
|
7982
7987
|
return void 0;
|
|
7983
7988
|
}
|
|
@@ -8011,9 +8016,9 @@ function snapshotPath(snapshotsDir, identity) {
|
|
|
8011
8016
|
}
|
|
8012
8017
|
return import_node_path22.default.join(snapshotsDir, `${identity}.json`);
|
|
8013
8018
|
}
|
|
8014
|
-
function readUsageSnapshot(
|
|
8019
|
+
function readUsageSnapshot(fs16, snapshotsDir, identity) {
|
|
8015
8020
|
const file = snapshotPath(snapshotsDir, identity);
|
|
8016
|
-
const raw =
|
|
8021
|
+
const raw = fs16.readFileUtf8(file);
|
|
8017
8022
|
if (raw === void 0) {
|
|
8018
8023
|
return void 0;
|
|
8019
8024
|
}
|
|
@@ -8029,8 +8034,8 @@ function readUsageSnapshot(fs15, snapshotsDir, identity) {
|
|
|
8029
8034
|
}
|
|
8030
8035
|
return snapshot.data;
|
|
8031
8036
|
}
|
|
8032
|
-
function listUsageSnapshots(
|
|
8033
|
-
return
|
|
8037
|
+
function listUsageSnapshots(fs16, snapshotsDir) {
|
|
8038
|
+
return fs16.readdir(snapshotsDir).flatMap((name) => {
|
|
8034
8039
|
if (!name.endsWith(".json")) {
|
|
8035
8040
|
return [];
|
|
8036
8041
|
}
|
|
@@ -8038,7 +8043,7 @@ function listUsageSnapshots(fs15, snapshotsDir) {
|
|
|
8038
8043
|
if (!isIdentityName(identity)) {
|
|
8039
8044
|
return [];
|
|
8040
8045
|
}
|
|
8041
|
-
const snapshot = readUsageSnapshot(
|
|
8046
|
+
const snapshot = readUsageSnapshot(fs16, snapshotsDir, identity);
|
|
8042
8047
|
return snapshot === void 0 ? [] : [snapshot];
|
|
8043
8048
|
}).sort((left, right) => left.identity.localeCompare(right.identity));
|
|
8044
8049
|
}
|
|
@@ -8063,11 +8068,11 @@ var init_read = __esm({
|
|
|
8063
8068
|
});
|
|
8064
8069
|
|
|
8065
8070
|
// src/usage/store.ts
|
|
8066
|
-
function pruneUsageLog(
|
|
8071
|
+
function pruneUsageLog(fs16, logDir, nowMs) {
|
|
8067
8072
|
const cutoff = nowMs - USAGE_RETENTION_MS;
|
|
8068
|
-
for (const segment of listLogSegments(
|
|
8073
|
+
for (const segment of listLogSegments(fs16, logDir)) {
|
|
8069
8074
|
if (segment.endsAt <= cutoff) {
|
|
8070
|
-
|
|
8075
|
+
fs16.removeRecursive(import_node_path23.default.join(logDir, segment.name));
|
|
8071
8076
|
}
|
|
8072
8077
|
}
|
|
8073
8078
|
}
|
|
@@ -8096,7 +8101,7 @@ function foldProviderState(current, record) {
|
|
|
8096
8101
|
};
|
|
8097
8102
|
}
|
|
8098
8103
|
function createUsageStore(deps) {
|
|
8099
|
-
const { fs:
|
|
8104
|
+
const { fs: fs16, paths } = deps;
|
|
8100
8105
|
let prunedDay;
|
|
8101
8106
|
const rewriteSnapshot = (identity, fold) => {
|
|
8102
8107
|
if (!isIdentityName(identity)) {
|
|
@@ -8105,7 +8110,7 @@ function createUsageStore(deps) {
|
|
|
8105
8110
|
}
|
|
8106
8111
|
let current;
|
|
8107
8112
|
try {
|
|
8108
|
-
current = readUsageSnapshot(
|
|
8113
|
+
current = readUsageSnapshot(fs16, paths.usageSnapshotsDir, identity);
|
|
8109
8114
|
} catch (error) {
|
|
8110
8115
|
if (!(error instanceof UsageSnapshotError)) {
|
|
8111
8116
|
throw error;
|
|
@@ -8132,8 +8137,8 @@ function createUsageStore(deps) {
|
|
|
8132
8137
|
...account === void 0 ? {} : { account },
|
|
8133
8138
|
providers
|
|
8134
8139
|
});
|
|
8135
|
-
|
|
8136
|
-
|
|
8140
|
+
fs16.mkdirPrivate(paths.usageSnapshotsDir);
|
|
8141
|
+
fs16.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
|
|
8137
8142
|
`);
|
|
8138
8143
|
deps.publish?.(snapshot);
|
|
8139
8144
|
return true;
|
|
@@ -8142,14 +8147,14 @@ function createUsageStore(deps) {
|
|
|
8142
8147
|
record: (input) => {
|
|
8143
8148
|
const record = UsageRecordSchema.parse(input);
|
|
8144
8149
|
const nowMs = deps.now();
|
|
8145
|
-
|
|
8146
|
-
|
|
8150
|
+
fs16.mkdirPrivate(paths.usageDir);
|
|
8151
|
+
fs16.mkdirPrivate(paths.usageLogDir);
|
|
8147
8152
|
const day = segmentDay(nowMs);
|
|
8148
8153
|
if (prunedDay !== day) {
|
|
8149
|
-
pruneUsageLog(
|
|
8154
|
+
pruneUsageLog(fs16, paths.usageLogDir, nowMs);
|
|
8150
8155
|
prunedDay = day;
|
|
8151
8156
|
}
|
|
8152
|
-
|
|
8157
|
+
fs16.appendFilePrivate(import_node_path23.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
|
|
8153
8158
|
`);
|
|
8154
8159
|
deps.onRecord?.(record);
|
|
8155
8160
|
if (record.identity !== void 0) {
|
|
@@ -8192,14 +8197,14 @@ var init_store2 = __esm({
|
|
|
8192
8197
|
function errorMessage(error) {
|
|
8193
8198
|
return error instanceof Error ? error.message : String(error);
|
|
8194
8199
|
}
|
|
8195
|
-
function loadPoolMembers(
|
|
8200
|
+
function loadPoolMembers(fs16, paths, identities, nowMs) {
|
|
8196
8201
|
const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
|
|
8197
|
-
const log = readUsageLog(
|
|
8202
|
+
const log = readUsageLog(fs16, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
8198
8203
|
return identities.map((identity) => {
|
|
8199
8204
|
const records = log.records.filter((record) => record.identity === identity && record.provider === ANTHROPIC_PROVIDER && Date.parse(record.at) >= windowStartMs);
|
|
8200
8205
|
try {
|
|
8201
|
-
const snapshot = readUsageSnapshot(
|
|
8202
|
-
const account = readAccountMetadata(
|
|
8206
|
+
const snapshot = readUsageSnapshot(fs16, paths.usageSnapshotsDir, identity);
|
|
8207
|
+
const account = readAccountMetadata(fs16, paths.identitiesDir, identity) ?? snapshot?.account;
|
|
8203
8208
|
return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
|
|
8204
8209
|
} catch (error) {
|
|
8205
8210
|
if (error instanceof UsageSnapshotError || error instanceof AccountMetadataError) {
|
|
@@ -8318,9 +8323,9 @@ function collectPoolIdentities(pools, poolName, stack, found) {
|
|
|
8318
8323
|
collectPoolIdentities(pools, nestedName, childStack, found);
|
|
8319
8324
|
}
|
|
8320
8325
|
}
|
|
8321
|
-
function readPicksFile(
|
|
8326
|
+
function readPicksFile(fs16, file) {
|
|
8322
8327
|
const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
|
|
8323
|
-
const raw =
|
|
8328
|
+
const raw = fs16.readFileUtf8(file);
|
|
8324
8329
|
if (raw === void 0) {
|
|
8325
8330
|
return { file: empty };
|
|
8326
8331
|
}
|
|
@@ -8333,17 +8338,17 @@ function readPicksFile(fs15, file) {
|
|
|
8333
8338
|
const result = PicksFileSchema.safeParse(parsed);
|
|
8334
8339
|
return result.success ? { file: result.data } : { file: empty, problem: `${file} is not a picks file this agent-shim can read` };
|
|
8335
8340
|
}
|
|
8336
|
-
function readStickyPick(
|
|
8337
|
-
const read = readPicksFile(
|
|
8341
|
+
function readStickyPick(fs16, picksFile, directory) {
|
|
8342
|
+
const read = readPicksFile(fs16, picksFile);
|
|
8338
8343
|
const entry = read.file.picks[directory];
|
|
8339
8344
|
return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
|
|
8340
8345
|
}
|
|
8341
|
-
function recordStickyPick(
|
|
8342
|
-
const current = readPicksFile(
|
|
8346
|
+
function recordStickyPick(fs16, picksFile, directory, identity, nowMs) {
|
|
8347
|
+
const current = readPicksFile(fs16, picksFile).file.picks;
|
|
8343
8348
|
const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
|
|
8344
8349
|
const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
|
|
8345
|
-
|
|
8346
|
-
|
|
8350
|
+
fs16.mkdirPrivate(import_node_path24.default.dirname(picksFile));
|
|
8351
|
+
fs16.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
8347
8352
|
`);
|
|
8348
8353
|
}
|
|
8349
8354
|
var import_node_path24, import_zod17, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
@@ -8377,9 +8382,9 @@ var init_poolPick = __esm({
|
|
|
8377
8382
|
});
|
|
8378
8383
|
|
|
8379
8384
|
// src/statusline/keys.ts
|
|
8380
|
-
function valueAt(source,
|
|
8385
|
+
function valueAt(source, path49) {
|
|
8381
8386
|
let current = source;
|
|
8382
|
-
for (const part of
|
|
8387
|
+
for (const part of path49) {
|
|
8383
8388
|
if (!isPlainObject(current)) {
|
|
8384
8389
|
return void 0;
|
|
8385
8390
|
}
|
|
@@ -8387,14 +8392,14 @@ function valueAt(source, path48) {
|
|
|
8387
8392
|
}
|
|
8388
8393
|
return current;
|
|
8389
8394
|
}
|
|
8390
|
-
function acceptsNull(
|
|
8391
|
-
const layer =
|
|
8395
|
+
function acceptsNull(path49) {
|
|
8396
|
+
const layer = path49.reduceRight((inner, part) => ({ [part]: inner }), null);
|
|
8392
8397
|
return StatuslineSchema.safeParse(layer).success;
|
|
8393
8398
|
}
|
|
8394
|
-
function keyOf(
|
|
8399
|
+
function keyOf(path49, declared) {
|
|
8395
8400
|
const optional = declared instanceof import_zod18.z.ZodOptional;
|
|
8396
8401
|
const leaf = optional ? declared.unwrap() : declared;
|
|
8397
|
-
const common = { path:
|
|
8402
|
+
const common = { path: path49.join("."), description: declared.description ?? "", defaultValue: valueAt(STATUSLINE_DEFAULTS, path49), optional, unsettable: acceptsNull(path49) };
|
|
8398
8403
|
if (leaf instanceof import_zod18.z.ZodNumber) {
|
|
8399
8404
|
return { ...common, kind: "integer", choices: [] };
|
|
8400
8405
|
}
|
|
@@ -8419,7 +8424,7 @@ function keyOf(path48, declared) {
|
|
|
8419
8424
|
if (leaf instanceof import_zod18.z.ZodArray && leaf.element instanceof import_zod18.z.ZodString) {
|
|
8420
8425
|
return { ...common, kind: "textList", choices: [] };
|
|
8421
8426
|
}
|
|
8422
|
-
throw new TypeError(`statusline setting ${
|
|
8427
|
+
throw new TypeError(`statusline setting ${path49.join(".")} has a kind the key listing does not describe`);
|
|
8423
8428
|
}
|
|
8424
8429
|
function walk(shape, prefix) {
|
|
8425
8430
|
return Object.entries(shape).flatMap(([name, schema]) => schema instanceof import_zod18.z.ZodObject ? walk(schema.shape, [...prefix, name]) : [keyOf([...prefix, name], schema)]);
|
|
@@ -8437,15 +8442,15 @@ var init_keys = __esm({
|
|
|
8437
8442
|
});
|
|
8438
8443
|
|
|
8439
8444
|
// src/statusline/change.ts
|
|
8440
|
-
function keyNamed(
|
|
8441
|
-
const found = statuslineKeys().find((key) => key.path ===
|
|
8445
|
+
function keyNamed(path49) {
|
|
8446
|
+
const found = statuslineKeys().find((key) => key.path === path49);
|
|
8442
8447
|
if (found === void 0) {
|
|
8443
|
-
throw new UsageError(`"${
|
|
8448
|
+
throw new UsageError(`"${path49}" is not a statusline setting; \`agent-shim statusline keys\` lists them.`);
|
|
8444
8449
|
}
|
|
8445
8450
|
return found;
|
|
8446
8451
|
}
|
|
8447
|
-
function setAt(target,
|
|
8448
|
-
const [head, ...rest] =
|
|
8452
|
+
function setAt(target, path49, value) {
|
|
8453
|
+
const [head, ...rest] = path49;
|
|
8449
8454
|
if (head === void 0) {
|
|
8450
8455
|
return;
|
|
8451
8456
|
}
|
|
@@ -8458,8 +8463,8 @@ function setAt(target, path48, value) {
|
|
|
8458
8463
|
target[head] = next;
|
|
8459
8464
|
setAt(next, rest, value);
|
|
8460
8465
|
}
|
|
8461
|
-
function removeAt(target,
|
|
8462
|
-
const [head, ...rest] =
|
|
8466
|
+
function removeAt(target, path49) {
|
|
8467
|
+
const [head, ...rest] = path49;
|
|
8463
8468
|
if (head === void 0) {
|
|
8464
8469
|
return;
|
|
8465
8470
|
}
|
|
@@ -8477,13 +8482,13 @@ function removeAt(target, path48) {
|
|
|
8477
8482
|
}
|
|
8478
8483
|
function applyStatuslineChange(existing, change) {
|
|
8479
8484
|
const draft = structuredClone(existing ?? {});
|
|
8480
|
-
for (const [
|
|
8481
|
-
keyNamed(
|
|
8482
|
-
setAt(draft,
|
|
8485
|
+
for (const [path49, value] of Object.entries(change.set ?? {})) {
|
|
8486
|
+
keyNamed(path49);
|
|
8487
|
+
setAt(draft, path49.split("."), value);
|
|
8483
8488
|
}
|
|
8484
|
-
for (const
|
|
8485
|
-
keyNamed(
|
|
8486
|
-
removeAt(draft,
|
|
8489
|
+
for (const path49 of change.unset ?? []) {
|
|
8490
|
+
keyNamed(path49);
|
|
8491
|
+
removeAt(draft, path49.split("."));
|
|
8487
8492
|
}
|
|
8488
8493
|
const result = StatuslineSchema.safeParse(draft);
|
|
8489
8494
|
if (!result.success) {
|
|
@@ -9861,13 +9866,13 @@ function decideSignIn(facts) {
|
|
|
9861
9866
|
function credentialsFilePath(farmRoot) {
|
|
9862
9867
|
return import_node_path27.default.join(farmRoot, CREDENTIALS_FILE);
|
|
9863
9868
|
}
|
|
9864
|
-
function identitySignIn(
|
|
9869
|
+
function identitySignIn(fs16, probe, identity) {
|
|
9865
9870
|
const probing = !identity.hasCredentialBlock && identity.provider === void 0;
|
|
9866
9871
|
return decideSignIn({
|
|
9867
9872
|
hasCredentialBlock: identity.hasCredentialBlock,
|
|
9868
9873
|
provider: identity.provider,
|
|
9869
9874
|
keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
|
|
9870
|
-
credentialsFile: probing &&
|
|
9875
|
+
credentialsFile: probing && fs16.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
|
|
9871
9876
|
platform: probe.platform
|
|
9872
9877
|
});
|
|
9873
9878
|
}
|
|
@@ -10329,15 +10334,15 @@ function signInCatalogueFingerprint(raw, filePath) {
|
|
|
10329
10334
|
function savedCatalogueFingerprint(provider, paths, env, home, read) {
|
|
10330
10335
|
if (provider.codex?.login === "chatgpt-sign-in") return signInCatalogueFingerprint(read(paths.chatgptSignInFile), paths.chatgptSignInFile);
|
|
10331
10336
|
const configuredHome = env.CODEX_HOME;
|
|
10332
|
-
const codexHome = configuredHome === void 0 || configuredHome === "" ?
|
|
10333
|
-
return cliCatalogueFingerprint(read(
|
|
10337
|
+
const codexHome = configuredHome === void 0 || configuredHome === "" ? import_node_path34.default.join(home, ".codex") : configuredHome;
|
|
10338
|
+
return cliCatalogueFingerprint(read(import_node_path34.default.join(codexHome, "auth.json")));
|
|
10334
10339
|
}
|
|
10335
|
-
var import_node_crypto10,
|
|
10340
|
+
var import_node_crypto10, import_node_path34, import_zod30, CatalogueBindingSchema;
|
|
10336
10341
|
var init_catalogueCredential = __esm({
|
|
10337
10342
|
"src/codex/catalogueCredential.ts"() {
|
|
10338
10343
|
"use strict";
|
|
10339
10344
|
import_node_crypto10 = require("node:crypto");
|
|
10340
|
-
|
|
10345
|
+
import_node_path34 = __toESM(require("node:path"), 1);
|
|
10341
10346
|
import_zod30 = require("zod");
|
|
10342
10347
|
init_siwcStore();
|
|
10343
10348
|
CatalogueBindingSchema = import_zod30.z.strictObject({ fingerprint: import_zod30.z.string().min(1), source: import_zod30.z.string().min(1), revision: import_zod30.z.string().min(1) });
|
|
@@ -10618,7 +10623,8 @@ function routedModelRows(models, providers) {
|
|
|
10618
10623
|
const hidden = new Set(models.hide ?? []);
|
|
10619
10624
|
const shown = models.show === void 0 ? void 0 : new Set(models.show);
|
|
10620
10625
|
const visible = (model) => shown === void 0 ? !hidden.has(model) : shown.has(model);
|
|
10621
|
-
const
|
|
10626
|
+
const separator = models.pickerLabelSpaces === false ? "/" : " / ";
|
|
10627
|
+
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}` })));
|
|
10622
10628
|
const concreteByRef = new Map(concrete.map((row) => [row.model, row]));
|
|
10623
10629
|
const families = buildFamilies([...concrete.map((row) => row.model), ...accountRefsOf(models)], models);
|
|
10624
10630
|
const handlingOf = (refs) => refs.map((ref) => concreteByRef.get(ref)?.behavesAs).find((behavesAs) => behavesAs !== void 0) ?? TIER_BEHAVES_AS.sonnet;
|
|
@@ -11442,13 +11448,13 @@ var init_cliOverride = __esm({
|
|
|
11442
11448
|
|
|
11443
11449
|
// src/launcher/launchRecords.ts
|
|
11444
11450
|
function recordFile(directory, pid, identity) {
|
|
11445
|
-
return
|
|
11451
|
+
return import_node_path42.default.join(directory, `${String(pid)}.${identity}${RECORD_SUFFIX}`);
|
|
11446
11452
|
}
|
|
11447
|
-
function readRecord(
|
|
11453
|
+
function readRecord(fs16, directory, name) {
|
|
11448
11454
|
if (!name.endsWith(RECORD_SUFFIX)) {
|
|
11449
11455
|
return void 0;
|
|
11450
11456
|
}
|
|
11451
|
-
const raw =
|
|
11457
|
+
const raw = fs16.readFileUtf8(import_node_path42.default.join(directory, name));
|
|
11452
11458
|
if (raw === void 0) {
|
|
11453
11459
|
return void 0;
|
|
11454
11460
|
}
|
|
@@ -11461,27 +11467,27 @@ function readRecord(fs15, directory, name) {
|
|
|
11461
11467
|
const result = LaunchRecordSchema.safeParse(parsed);
|
|
11462
11468
|
return result.success ? result.data : void 0;
|
|
11463
11469
|
}
|
|
11464
|
-
function registerLaunch(
|
|
11465
|
-
|
|
11466
|
-
for (const name of
|
|
11467
|
-
const record2 = readRecord(
|
|
11470
|
+
function registerLaunch(fs16, directory, owner, isRunning) {
|
|
11471
|
+
fs16.mkdirPrivate(directory);
|
|
11472
|
+
for (const name of fs16.readdir(directory)) {
|
|
11473
|
+
const record2 = readRecord(fs16, directory, name);
|
|
11468
11474
|
if (record2 !== void 0 && !isRunning(record2.pid)) {
|
|
11469
|
-
|
|
11475
|
+
fs16.removeRecursive(import_node_path42.default.join(directory, name));
|
|
11470
11476
|
}
|
|
11471
11477
|
}
|
|
11472
11478
|
const file = recordFile(directory, owner.pid, owner.identity);
|
|
11473
11479
|
const record = { pid: owner.pid, identity: owner.identity, startedAt: new Date(owner.startedAtMs).toISOString() };
|
|
11474
|
-
|
|
11480
|
+
fs16.writeFilePrivate(file, `${JSON.stringify(record)}
|
|
11475
11481
|
`);
|
|
11476
11482
|
return () => {
|
|
11477
|
-
|
|
11483
|
+
fs16.removeRecursive(file);
|
|
11478
11484
|
};
|
|
11479
11485
|
}
|
|
11480
|
-
var
|
|
11486
|
+
var import_node_path42, import_zod39, LaunchRecordSchema, RECORD_SUFFIX;
|
|
11481
11487
|
var init_launchRecords = __esm({
|
|
11482
11488
|
"src/launcher/launchRecords.ts"() {
|
|
11483
11489
|
"use strict";
|
|
11484
|
-
|
|
11490
|
+
import_node_path42 = __toESM(require("node:path"), 1);
|
|
11485
11491
|
import_zod39 = require("zod");
|
|
11486
11492
|
LaunchRecordSchema = import_zod39.z.strictObject({
|
|
11487
11493
|
/** The launcher's process id, which is what tells a launch in progress from a record a crashed launcher left behind. */
|
|
@@ -11616,7 +11622,7 @@ function buildEnv(params) {
|
|
|
11616
11622
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
11617
11623
|
let providerCustomHeaders;
|
|
11618
11624
|
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
11619
|
-
env.CLAUDE_CONFIG_DIR =
|
|
11625
|
+
env.CLAUDE_CONFIG_DIR = import_node_path43.default.join(params.identitiesDir, params.resolvedIdentityName);
|
|
11620
11626
|
}
|
|
11621
11627
|
if (params.provider !== void 0) {
|
|
11622
11628
|
const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
|
|
@@ -11670,11 +11676,11 @@ function buildEnv(params) {
|
|
|
11670
11676
|
}
|
|
11671
11677
|
return env;
|
|
11672
11678
|
}
|
|
11673
|
-
var
|
|
11679
|
+
var import_node_path43, LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
|
|
11674
11680
|
var init_flags = __esm({
|
|
11675
11681
|
"src/launcher/flags.ts"() {
|
|
11676
11682
|
"use strict";
|
|
11677
|
-
|
|
11683
|
+
import_node_path43 = __toESM(require("node:path"), 1);
|
|
11678
11684
|
init_envBool();
|
|
11679
11685
|
init_cliError();
|
|
11680
11686
|
init_conditions();
|
|
@@ -11759,15 +11765,15 @@ function contextTokensOfTranscript(text) {
|
|
|
11759
11765
|
}
|
|
11760
11766
|
return void 0;
|
|
11761
11767
|
}
|
|
11762
|
-
function newestTranscript(
|
|
11768
|
+
function newestTranscript(fs16, projectDir) {
|
|
11763
11769
|
let newest;
|
|
11764
11770
|
let newestMs = -Infinity;
|
|
11765
|
-
for (const name of
|
|
11771
|
+
for (const name of fs16.readdir(projectDir)) {
|
|
11766
11772
|
if (!name.endsWith(".jsonl")) {
|
|
11767
11773
|
continue;
|
|
11768
11774
|
}
|
|
11769
|
-
const candidate =
|
|
11770
|
-
const stat =
|
|
11775
|
+
const candidate = import_node_path44.default.join(projectDir, name);
|
|
11776
|
+
const stat = fs16.lstat(candidate);
|
|
11771
11777
|
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
11772
11778
|
newestMs = stat.mtimeMs;
|
|
11773
11779
|
newest = candidate;
|
|
@@ -11775,21 +11781,21 @@ function newestTranscript(fs15, projectDir) {
|
|
|
11775
11781
|
}
|
|
11776
11782
|
return newest;
|
|
11777
11783
|
}
|
|
11778
|
-
function resumedContextTokens(
|
|
11784
|
+
function resumedContextTokens(fs16, params) {
|
|
11779
11785
|
const target = resumeTargetOf(params.passthrough);
|
|
11780
11786
|
if (target === void 0) {
|
|
11781
11787
|
return void 0;
|
|
11782
11788
|
}
|
|
11783
|
-
const projectDir =
|
|
11784
|
-
const file = target.kind === "id" ?
|
|
11785
|
-
const text = file === void 0 ? void 0 :
|
|
11789
|
+
const projectDir = import_node_path44.default.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
11790
|
+
const file = target.kind === "id" ? import_node_path44.default.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs16, projectDir);
|
|
11791
|
+
const text = file === void 0 ? void 0 : fs16.readFileUtf8(file);
|
|
11786
11792
|
return text === void 0 ? void 0 : contextTokensOfTranscript(text);
|
|
11787
11793
|
}
|
|
11788
|
-
var
|
|
11794
|
+
var import_node_path44;
|
|
11789
11795
|
var init_resumeContext = __esm({
|
|
11790
11796
|
"src/usage/resumeContext.ts"() {
|
|
11791
11797
|
"use strict";
|
|
11792
|
-
|
|
11798
|
+
import_node_path44 = __toESM(require("node:path"), 1);
|
|
11793
11799
|
}
|
|
11794
11800
|
});
|
|
11795
11801
|
|
|
@@ -12386,7 +12392,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
|
|
|
12386
12392
|
return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
|
|
12387
12393
|
}
|
|
12388
12394
|
function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
12389
|
-
const { paths, fs:
|
|
12395
|
+
const { paths, fs: fs16, proc, log } = params;
|
|
12390
12396
|
if (decided.pool === void 0) {
|
|
12391
12397
|
return { identityDecision: decided };
|
|
12392
12398
|
}
|
|
@@ -12405,7 +12411,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
12405
12411
|
selectedVia: decided.source,
|
|
12406
12412
|
pools: params.pools,
|
|
12407
12413
|
paths,
|
|
12408
|
-
fs:
|
|
12414
|
+
fs: fs16,
|
|
12409
12415
|
usageFs: farmRuntime.fs,
|
|
12410
12416
|
cwd: farmRuntime.cwd,
|
|
12411
12417
|
now: farmRuntime.now,
|
|
@@ -12429,7 +12435,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
12429
12435
|
};
|
|
12430
12436
|
}
|
|
12431
12437
|
function decideLaunch(params, readOnly) {
|
|
12432
|
-
const { paths, fs:
|
|
12438
|
+
const { paths, fs: fs16, proc, log } = params;
|
|
12433
12439
|
const { env, argv } = proc;
|
|
12434
12440
|
const parsedArgv = parseLauncherArgv(argv);
|
|
12435
12441
|
const cliOverride = buildCliOverride({
|
|
@@ -12444,7 +12450,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12444
12450
|
argv0Identity: params.pickedIdentity ?? parsedArgv.identity,
|
|
12445
12451
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
12446
12452
|
readActiveIdentityFile: () => {
|
|
12447
|
-
const raw =
|
|
12453
|
+
const raw = fs16.readFileUtf8(paths.activeIdentityFile);
|
|
12448
12454
|
if (raw === void 0) {
|
|
12449
12455
|
return void 0;
|
|
12450
12456
|
}
|
|
@@ -12479,7 +12485,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12479
12485
|
}
|
|
12480
12486
|
let loadedIdentity;
|
|
12481
12487
|
if (identityDecision.name !== void 0) {
|
|
12482
|
-
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name,
|
|
12488
|
+
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs16);
|
|
12483
12489
|
if (loadedIdentity === void 0) {
|
|
12484
12490
|
log.error(
|
|
12485
12491
|
`agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
|
|
@@ -12494,7 +12500,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12494
12500
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
12495
12501
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
12496
12502
|
});
|
|
12497
|
-
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true &&
|
|
12503
|
+
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs16.readConfigFile(profileFilePath(paths.configProfilesDir, configProfileDecision.name, `the configuration profile selected via ${configProfileDecision.source}`)) === void 0) {
|
|
12498
12504
|
log.error(
|
|
12499
12505
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
12500
12506
|
);
|
|
@@ -12503,7 +12509,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12503
12509
|
const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
|
|
12504
12510
|
const providerParams = {
|
|
12505
12511
|
paths,
|
|
12506
|
-
port:
|
|
12512
|
+
port: fs16,
|
|
12507
12513
|
...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
|
|
12508
12514
|
...farmContext === void 0 ? {} : { cascade: farmContext.cascade },
|
|
12509
12515
|
...loadedIdentity?.config.provider === void 0 ? {} : { identityProvider: loadedIdentity.config.provider }
|
|
@@ -12624,9 +12630,9 @@ function decideLaunch(params, readOnly) {
|
|
|
12624
12630
|
const doorRecord = doorPid === void 0 ? void 0 : readFrontDoorCodexRecord(params.fs, paths.frontdoorDir, doorPid);
|
|
12625
12631
|
const doorHome = doorRecord?.codexHome;
|
|
12626
12632
|
const catalogueEnv = doorHome === void 0 ? proc.env : { ...proc.env, CODEX_HOME: doorHome };
|
|
12627
|
-
const listedProviders = listProviderNames(
|
|
12633
|
+
const listedProviders = listProviderNames(fs16.readdir, paths.providersDir).flatMap((name) => {
|
|
12628
12634
|
try {
|
|
12629
|
-
const definition = loadProvider(paths.providersDir, name,
|
|
12635
|
+
const definition = loadProvider(paths.providersDir, name, fs16);
|
|
12630
12636
|
if (definition === void 0) return [];
|
|
12631
12637
|
const catalogueOwner = definition.kind === "codex" ? doorPid : void 0;
|
|
12632
12638
|
const generation = definition.kind === "codex" ? doorRecord?.generation : void 0;
|
|
@@ -12636,8 +12642,8 @@ function decideLaunch(params, readOnly) {
|
|
|
12636
12642
|
if (definition.kind === "codex" && readOnly && cache !== void 0) {
|
|
12637
12643
|
const binding = parseCatalogueBinding(params.fs.readFileUtf8(catalogueBindingPath(paths, name, catalogueOwner, generation)));
|
|
12638
12644
|
const configuredHome = catalogueEnv.CODEX_HOME;
|
|
12639
|
-
const home = configuredHome === void 0 || configuredHome === "" ?
|
|
12640
|
-
const source = definition.codex?.login === "chatgpt-sign-in" ? paths.chatgptSignInFile :
|
|
12645
|
+
const home = configuredHome === void 0 || configuredHome === "" ? import_node_path45.default.join(import_node_os8.default.homedir(), ".codex") : configuredHome;
|
|
12646
|
+
const source = definition.codex?.login === "chatgpt-sign-in" ? paths.chatgptSignInFile : import_node_path45.default.resolve(home, "auth.json");
|
|
12641
12647
|
const revision = params.fs.fileRevision?.(source);
|
|
12642
12648
|
if (binding === void 0 || binding.fingerprint !== cache.credentialFingerprint || binding.source !== source || revision === void 0 || revision !== binding.revision) return [];
|
|
12643
12649
|
}
|
|
@@ -12658,7 +12664,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12658
12664
|
return { args: args2, pickerSuppressed: startsSession && pickerSettings !== void 0 && callerSettings };
|
|
12659
12665
|
};
|
|
12660
12666
|
const args = argsForSupervisor().args;
|
|
12661
|
-
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR :
|
|
12667
|
+
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : import_node_path45.default.join(paths.identitiesDir, identityDecision.name);
|
|
12662
12668
|
const decision = {
|
|
12663
12669
|
identitySource: identityDecision.source,
|
|
12664
12670
|
configDirEscapeHatch: identityDecision.configDirEscapeHatch,
|
|
@@ -12733,7 +12739,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
|
|
|
12733
12739
|
let unregisterLaunch;
|
|
12734
12740
|
const updateCheck = runLaunchUpdateCheck({
|
|
12735
12741
|
mode: params.updateMode ?? "off",
|
|
12736
|
-
checkPath:
|
|
12742
|
+
checkPath: import_node_path45.default.join(paths.root, "update.check"),
|
|
12737
12743
|
currentVersion: package_default.version,
|
|
12738
12744
|
port: params.update
|
|
12739
12745
|
});
|
|
@@ -12898,7 +12904,7 @@ function runLaunchPlan(plan, spawn3) {
|
|
|
12898
12904
|
function runLauncher(params) {
|
|
12899
12905
|
params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
|
|
12900
12906
|
}
|
|
12901
|
-
var import_node_crypto12, import_node_os8, import_node_util2,
|
|
12907
|
+
var import_node_crypto12, import_node_os8, import_node_util2, import_node_path45;
|
|
12902
12908
|
var init_launcher = __esm({
|
|
12903
12909
|
"src/launcher.ts"() {
|
|
12904
12910
|
"use strict";
|
|
@@ -12906,7 +12912,7 @@ var init_launcher = __esm({
|
|
|
12906
12912
|
import_node_os8 = __toESM(require("node:os"), 1);
|
|
12907
12913
|
init_catalogueCredential();
|
|
12908
12914
|
import_node_util2 = require("node:util");
|
|
12909
|
-
|
|
12915
|
+
import_node_path45 = __toESM(require("node:path"), 1);
|
|
12910
12916
|
init_package();
|
|
12911
12917
|
init_envBool();
|
|
12912
12918
|
init_argv();
|
|
@@ -12953,13 +12959,13 @@ function agentShimCliPath(distDir = typeof __AGENT_SHIM_DIST_DIR__ === "string"
|
|
|
12953
12959
|
if (distDir === void 0) {
|
|
12954
12960
|
throw new OwnCliPathUnknownError();
|
|
12955
12961
|
}
|
|
12956
|
-
return
|
|
12962
|
+
return import_node_path46.default.join(distDir, OWN_CLI_FILE_NAME);
|
|
12957
12963
|
}
|
|
12958
|
-
var
|
|
12964
|
+
var import_node_path46, OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
|
|
12959
12965
|
var init_ownCli = __esm({
|
|
12960
12966
|
"src/ownCli.ts"() {
|
|
12961
12967
|
"use strict";
|
|
12962
|
-
|
|
12968
|
+
import_node_path46 = __toESM(require("node:path"), 1);
|
|
12963
12969
|
init_cliError();
|
|
12964
12970
|
OWN_CLI_FILE_NAME = "cli.cjs";
|
|
12965
12971
|
OwnCliPathUnknownError = class extends CliError {
|
|
@@ -12983,15 +12989,15 @@ var init_childRun = __esm({
|
|
|
12983
12989
|
|
|
12984
12990
|
// src/frontdoor/doorLog.ts
|
|
12985
12991
|
function appendDoorLog(paths, line) {
|
|
12986
|
-
|
|
12987
|
-
|
|
12992
|
+
import_node_fs14.default.mkdirSync(paths.logsDir, { recursive: true });
|
|
12993
|
+
import_node_fs14.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
12988
12994
|
`);
|
|
12989
12995
|
}
|
|
12990
|
-
var
|
|
12996
|
+
var import_node_fs14;
|
|
12991
12997
|
var init_doorLog = __esm({
|
|
12992
12998
|
"src/frontdoor/doorLog.ts"() {
|
|
12993
12999
|
"use strict";
|
|
12994
|
-
|
|
13000
|
+
import_node_fs14 = __toESM(require("node:fs"), 1);
|
|
12995
13001
|
}
|
|
12996
13002
|
});
|
|
12997
13003
|
|
|
@@ -13011,14 +13017,14 @@ var init_selfIdentity = __esm({
|
|
|
13011
13017
|
|
|
13012
13018
|
// src/frontdoor/trust.ts
|
|
13013
13019
|
function resolveTrustBundle(params) {
|
|
13014
|
-
const { caCertFile, bundlesDir, variable, inherited, fs:
|
|
13015
|
-
if (inherited === void 0 || inherited === "" ||
|
|
13020
|
+
const { caCertFile, bundlesDir, variable, inherited, fs: fs16 } = params;
|
|
13021
|
+
if (inherited === void 0 || inherited === "" || import_node_path47.default.resolve(inherited) === import_node_path47.default.resolve(caCertFile)) {
|
|
13016
13022
|
return { path: caCertFile };
|
|
13017
13023
|
}
|
|
13018
|
-
const caPem =
|
|
13024
|
+
const caPem = fs16.readFileUtf8(caCertFile);
|
|
13019
13025
|
let inheritedPem;
|
|
13020
13026
|
try {
|
|
13021
|
-
inheritedPem =
|
|
13027
|
+
inheritedPem = fs16.readFileUtf8(inherited);
|
|
13022
13028
|
} catch (error) {
|
|
13023
13029
|
return {
|
|
13024
13030
|
path: caCertFile,
|
|
@@ -13030,19 +13036,19 @@ function resolveTrustBundle(params) {
|
|
|
13030
13036
|
}
|
|
13031
13037
|
const combined = `${inheritedPem.trimEnd()}
|
|
13032
13038
|
${caPem}`;
|
|
13033
|
-
const bundle =
|
|
13034
|
-
if (!
|
|
13035
|
-
|
|
13036
|
-
|
|
13039
|
+
const bundle = import_node_path47.default.join(bundlesDir, `${(0, import_node_crypto13.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
13040
|
+
if (!fs16.exists(bundle)) {
|
|
13041
|
+
fs16.mkdirp(bundlesDir);
|
|
13042
|
+
fs16.writeFileAtomic(bundle, combined);
|
|
13037
13043
|
}
|
|
13038
13044
|
return { path: bundle };
|
|
13039
13045
|
}
|
|
13040
|
-
var import_node_crypto13,
|
|
13046
|
+
var import_node_crypto13, import_node_path47, BUNDLE_NAME_HEX_DIGITS;
|
|
13041
13047
|
var init_trust = __esm({
|
|
13042
13048
|
"src/frontdoor/trust.ts"() {
|
|
13043
13049
|
"use strict";
|
|
13044
13050
|
import_node_crypto13 = require("node:crypto");
|
|
13045
|
-
|
|
13051
|
+
import_node_path47 = __toESM(require("node:path"), 1);
|
|
13046
13052
|
BUNDLE_NAME_HEX_DIGITS = 16;
|
|
13047
13053
|
}
|
|
13048
13054
|
});
|
|
@@ -13073,7 +13079,7 @@ function realEnsurePorts(paths, spawnDaemon) {
|
|
|
13073
13079
|
}
|
|
13074
13080
|
},
|
|
13075
13081
|
// 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.
|
|
13076
|
-
verifyListener: (port) => probeFrontDoorSync(port,
|
|
13082
|
+
verifyListener: (port) => probeFrontDoorSync(port, import_node_fs15.default.readFileSync(paths.frontdoorCaCertFile, "utf8"))
|
|
13077
13083
|
};
|
|
13078
13084
|
}
|
|
13079
13085
|
function realFrontDoorPort(paths, spawnDaemon) {
|
|
@@ -13144,11 +13150,11 @@ function realFrontDoorPort(paths, spawnDaemon) {
|
|
|
13144
13150
|
}
|
|
13145
13151
|
};
|
|
13146
13152
|
}
|
|
13147
|
-
var
|
|
13153
|
+
var import_node_fs15, import_node_os9, realTrustBundleFs;
|
|
13148
13154
|
var init_realFrontDoorPort = __esm({
|
|
13149
13155
|
"src/frontdoor/realFrontDoorPort.ts"() {
|
|
13150
13156
|
"use strict";
|
|
13151
|
-
|
|
13157
|
+
import_node_fs15 = __toESM(require("node:fs"), 1);
|
|
13152
13158
|
import_node_os9 = __toESM(require("node:os"), 1);
|
|
13153
13159
|
init_providersStore();
|
|
13154
13160
|
init_providerCatalogue();
|
|
@@ -13162,10 +13168,10 @@ var init_realFrontDoorPort = __esm({
|
|
|
13162
13168
|
init_selfIdentity();
|
|
13163
13169
|
init_trust();
|
|
13164
13170
|
realTrustBundleFs = {
|
|
13165
|
-
readFileUtf8: (file) =>
|
|
13166
|
-
exists: (file) =>
|
|
13171
|
+
readFileUtf8: (file) => import_node_fs15.default.readFileSync(file, "utf8"),
|
|
13172
|
+
exists: (file) => import_node_fs15.default.existsSync(file),
|
|
13167
13173
|
mkdirp: (dir) => {
|
|
13168
|
-
|
|
13174
|
+
import_node_fs15.default.mkdirSync(dir, { recursive: true });
|
|
13169
13175
|
},
|
|
13170
13176
|
writeFileAtomic: (file, contents) => {
|
|
13171
13177
|
realFarmFs.writeFilePrivate(file, contents);
|
|
@@ -13228,7 +13234,7 @@ function realPrepareLaunchParams(paths, options) {
|
|
|
13228
13234
|
frontdoor: realFrontDoorPort(paths, options.spawnDaemon),
|
|
13229
13235
|
credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
|
|
13230
13236
|
hold: realHoldPort,
|
|
13231
|
-
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot:
|
|
13237
|
+
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot: import_node_path48.default.join(paths.identitiesDir, identity), hasCredentialBlock: false, provider: void 0 }).state !== "signed-out",
|
|
13232
13238
|
...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
|
|
13233
13239
|
...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
|
|
13234
13240
|
...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },
|
|
@@ -13289,12 +13295,12 @@ function resolveClaudeLaunch(options, run = realRunPort) {
|
|
|
13289
13295
|
};
|
|
13290
13296
|
return { resolution: resolveLaunch(realPrepareLaunchParams(paths, { proc, log, spawnDaemon, run, farm: buildFarmRuntime(paths, options.cwd, run) })), warnings };
|
|
13291
13297
|
}
|
|
13292
|
-
var import_node_os10,
|
|
13298
|
+
var import_node_os10, import_node_path48, import_node_crypto14, LaunchRefusedError;
|
|
13293
13299
|
var init_launchWiring = __esm({
|
|
13294
13300
|
"src/launchWiring.ts"() {
|
|
13295
13301
|
"use strict";
|
|
13296
13302
|
import_node_os10 = __toESM(require("node:os"), 1);
|
|
13297
|
-
|
|
13303
|
+
import_node_path48 = __toESM(require("node:path"), 1);
|
|
13298
13304
|
import_node_crypto14 = require("node:crypto");
|
|
13299
13305
|
init_cliError();
|
|
13300
13306
|
init_claudeShim();
|
|
@@ -14353,8 +14359,8 @@ function pathnameOf(url) {
|
|
|
14353
14359
|
return new URL(url ?? "/", "http://127.0.0.1").pathname;
|
|
14354
14360
|
}
|
|
14355
14361
|
function isRcSessionExchange(url) {
|
|
14356
|
-
const
|
|
14357
|
-
return
|
|
14362
|
+
const path49 = pathnameOf(url);
|
|
14363
|
+
return path49 === RC_SESSIONS_PATH_PREFIX || path49.startsWith(`${RC_SESSIONS_PATH_PREFIX}/`);
|
|
14358
14364
|
}
|
|
14359
14365
|
var RC_SESSION_ID_PREFIX = "cse_";
|
|
14360
14366
|
var RC_IDLE_EXPIRY_MS = 45e3;
|
|
@@ -14913,8 +14919,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
|
|
|
14913
14919
|
function isRcReadFileEncoding(value) {
|
|
14914
14920
|
return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value);
|
|
14915
14921
|
}
|
|
14916
|
-
function buildRcReadFilePayload(requestId,
|
|
14917
|
-
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path:
|
|
14922
|
+
function buildRcReadFilePayload(requestId, path49, options) {
|
|
14923
|
+
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path49, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
|
|
14918
14924
|
}
|
|
14919
14925
|
function buildRcFileSuggestionsPayload(requestId, query) {
|
|
14920
14926
|
return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
|
|
@@ -15016,15 +15022,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
|
|
|
15016
15022
|
const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
|
|
15017
15023
|
return result.ok ? { ...result, requestId } : result;
|
|
15018
15024
|
}
|
|
15019
|
-
async function readRcSessionFile(deps, sessionId,
|
|
15020
|
-
if (
|
|
15025
|
+
async function readRcSessionFile(deps, sessionId, path49, options) {
|
|
15026
|
+
if (path49 === "") {
|
|
15021
15027
|
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" };
|
|
15022
15028
|
}
|
|
15023
15029
|
if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
|
|
15024
15030
|
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" };
|
|
15025
15031
|
}
|
|
15026
15032
|
const requestId = deps.newUuid();
|
|
15027
|
-
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId,
|
|
15033
|
+
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path49, options), `read ${path49} from session ${sessionId}`);
|
|
15028
15034
|
return result.ok ? { ...result, requestId } : result;
|
|
15029
15035
|
}
|
|
15030
15036
|
async function suggestRcSessionFiles(deps, sessionId, query) {
|
|
@@ -15193,11 +15199,11 @@ function createRcControlHandler(deps) {
|
|
|
15193
15199
|
path: "read-file",
|
|
15194
15200
|
read: (body) => {
|
|
15195
15201
|
const session = bodyString(body, "session");
|
|
15196
|
-
const
|
|
15202
|
+
const path49 = bodyString(body, "path");
|
|
15197
15203
|
const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
|
|
15198
15204
|
const encoding = "encoding" in body && isRcReadFileEncoding(body.encoding) ? body.encoding : void 0;
|
|
15199
|
-
const refused2 = session === void 0 ||
|
|
15200
|
-
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,
|
|
15205
|
+
const refused2 = session === void 0 || path49 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
|
|
15206
|
+
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 } }) };
|
|
15201
15207
|
}
|
|
15202
15208
|
},
|
|
15203
15209
|
{
|
|
@@ -15507,9 +15513,9 @@ function requestIdOfBody(body) {
|
|
|
15507
15513
|
}
|
|
15508
15514
|
function frontDoorRcControl(transport, token) {
|
|
15509
15515
|
const headers = { authorization: `Bearer ${token}` };
|
|
15510
|
-
const listAnswerOf = async (
|
|
15516
|
+
const listAnswerOf = async (path49, what) => {
|
|
15511
15517
|
try {
|
|
15512
|
-
return await transport.request({ method: "GET", path:
|
|
15518
|
+
return await transport.request({ method: "GET", path: path49, headers });
|
|
15513
15519
|
} catch (error) {
|
|
15514
15520
|
throw new Error(`${what}: could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
15515
15521
|
}
|
|
@@ -15581,10 +15587,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15581
15587
|
}
|
|
15582
15588
|
return pending;
|
|
15583
15589
|
};
|
|
15584
|
-
const writeOf = async (
|
|
15590
|
+
const writeOf = async (path49, body, describeFailure2) => {
|
|
15585
15591
|
let answer;
|
|
15586
15592
|
try {
|
|
15587
|
-
answer = await transport.request({ method: "POST", path:
|
|
15593
|
+
answer = await transport.request({ method: "POST", path: path49, headers: { ...headers, "content-type": "application/json" }, body });
|
|
15588
15594
|
} catch (error) {
|
|
15589
15595
|
return { ok: false, message: `could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}` };
|
|
15590
15596
|
}
|
|
@@ -15615,10 +15621,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15615
15621
|
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}`),
|
|
15616
15622
|
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}`),
|
|
15617
15623
|
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}`),
|
|
15618
|
-
readFile: async (sessionId,
|
|
15624
|
+
readFile: async (sessionId, path49, options) => await writeOf(
|
|
15619
15625
|
`${CONTROL_PATH_PREFIX}/read-file`,
|
|
15620
|
-
JSON.stringify({ session: sessionId, path:
|
|
15621
|
-
(status, message) => `reading ${
|
|
15626
|
+
JSON.stringify({ session: sessionId, path: path49, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
|
|
15627
|
+
(status, message) => `reading ${path49} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
15622
15628
|
),
|
|
15623
15629
|
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}`),
|
|
15624
15630
|
keepAlive: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/keep-alive`, JSON.stringify({ session: sessionId }), (status, message) => `keeping ${sessionId} alive failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -15777,12 +15783,12 @@ function tlsFacts(options) {
|
|
|
15777
15783
|
}
|
|
15778
15784
|
function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15779
15785
|
const agent = new ExemptTlsAgent();
|
|
15780
|
-
const post = async (
|
|
15786
|
+
const post = async (path49, headers, body) => await new Promise((resolve, reject) => {
|
|
15781
15787
|
const options = {
|
|
15782
15788
|
host: target.host,
|
|
15783
15789
|
port: target.port,
|
|
15784
15790
|
method: "POST",
|
|
15785
|
-
path:
|
|
15791
|
+
path: path49,
|
|
15786
15792
|
// 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.
|
|
15787
15793
|
headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
|
|
15788
15794
|
agent
|
|
@@ -15847,12 +15853,12 @@ function lateRcStreamDial(resolve) {
|
|
|
15847
15853
|
}
|
|
15848
15854
|
function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15849
15855
|
const agent = new ExemptTlsAgent();
|
|
15850
|
-
const request4 = async (method,
|
|
15856
|
+
const request4 = async (method, path49, headers, body, signal) => await new Promise((resolve, reject) => {
|
|
15851
15857
|
const options = {
|
|
15852
15858
|
host: target.host,
|
|
15853
15859
|
port: target.port,
|
|
15854
15860
|
method,
|
|
15855
|
-
path:
|
|
15861
|
+
path: path49,
|
|
15856
15862
|
// 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.
|
|
15857
15863
|
headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
|
|
15858
15864
|
agent,
|
|
@@ -15894,9 +15900,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
|
|
|
15894
15900
|
return { status, body: await readAll(response) };
|
|
15895
15901
|
},
|
|
15896
15902
|
openStream: async (sessionId, headers, resume, signal) => {
|
|
15897
|
-
const
|
|
15903
|
+
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)}`;
|
|
15898
15904
|
const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
|
|
15899
|
-
const { status, response } = await request4("GET",
|
|
15905
|
+
const { status, response } = await request4("GET", path49, streamHeaders, void 0, signal);
|
|
15900
15906
|
if (!isSuccessful2(status)) {
|
|
15901
15907
|
await readAll(response);
|
|
15902
15908
|
return { status, chunks: NO_CHUNKS };
|
|
@@ -16146,11 +16152,11 @@ function credentialOfJson(parsed) {
|
|
|
16146
16152
|
function sequenceNumOfJson(value) {
|
|
16147
16153
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
16148
16154
|
}
|
|
16149
|
-
function createRcCredentialStore(
|
|
16150
|
-
|
|
16155
|
+
function createRcCredentialStore(fs16, dir) {
|
|
16156
|
+
fs16.mkdirPrivate(dir);
|
|
16151
16157
|
const fileFor = (sessionId) => import_node_path13.default.join(dir, `${sessionId}.json`);
|
|
16152
16158
|
const readParsed = (sessionId) => {
|
|
16153
|
-
const raw =
|
|
16159
|
+
const raw = fs16.readFileUtf8(fileFor(sessionId));
|
|
16154
16160
|
if (raw === void 0) {
|
|
16155
16161
|
return void 0;
|
|
16156
16162
|
}
|
|
@@ -16175,7 +16181,7 @@ function createRcCredentialStore(fs15, dir) {
|
|
|
16175
16181
|
}
|
|
16176
16182
|
const cursor = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
|
|
16177
16183
|
const record = { ...credential, ...cursor === void 0 ? {} : { highestSequenceNum: cursor } };
|
|
16178
|
-
|
|
16184
|
+
fs16.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
16179
16185
|
`);
|
|
16180
16186
|
},
|
|
16181
16187
|
readCursor: (sessionId) => {
|
|
@@ -16190,14 +16196,14 @@ function createRcCredentialStore(fs15, dir) {
|
|
|
16190
16196
|
}
|
|
16191
16197
|
const credential = credentialOfJson(readParsed(sessionId));
|
|
16192
16198
|
const record = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
|
|
16193
|
-
|
|
16199
|
+
fs16.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
16194
16200
|
`);
|
|
16195
16201
|
},
|
|
16196
16202
|
remove: (sessionId) => {
|
|
16197
16203
|
if (!isSafeSessionId(sessionId)) {
|
|
16198
16204
|
return;
|
|
16199
16205
|
}
|
|
16200
|
-
|
|
16206
|
+
fs16.removeRecursive(fileFor(sessionId));
|
|
16201
16207
|
}
|
|
16202
16208
|
};
|
|
16203
16209
|
}
|
|
@@ -16889,19 +16895,19 @@ function writePools(paths, pools) {
|
|
|
16889
16895
|
applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
|
|
16890
16896
|
}
|
|
16891
16897
|
function poolCycleOf(pools, name) {
|
|
16892
|
-
const walk2 = (current,
|
|
16898
|
+
const walk2 = (current, path49) => {
|
|
16893
16899
|
for (const entry of pools[current]?.identities ?? []) {
|
|
16894
16900
|
const nested = poolNameOf(poolMemberIdentity(entry));
|
|
16895
16901
|
if (nested === void 0) {
|
|
16896
16902
|
continue;
|
|
16897
16903
|
}
|
|
16898
16904
|
if (nested === name) {
|
|
16899
|
-
return [...
|
|
16905
|
+
return [...path49, nested];
|
|
16900
16906
|
}
|
|
16901
|
-
if (
|
|
16907
|
+
if (path49.includes(nested)) {
|
|
16902
16908
|
continue;
|
|
16903
16909
|
}
|
|
16904
|
-
const found = walk2(nested, [...
|
|
16910
|
+
const found = walk2(nested, [...path49, nested]);
|
|
16905
16911
|
if (found !== void 0) {
|
|
16906
16912
|
return found;
|
|
16907
16913
|
}
|
|
@@ -17613,7 +17619,7 @@ var ResetRowSchema = import_zod24.z.strictObject({
|
|
|
17613
17619
|
var ResetScheduleSchema = import_zod24.z.strictObject({ resets: import_zod24.z.readonly(import_zod24.z.array(ResetRowSchema)) });
|
|
17614
17620
|
|
|
17615
17621
|
// src/frontdoor/controlSchemas.ts
|
|
17616
|
-
var
|
|
17622
|
+
var import_node_path36 = __toESM(require("node:path"), 1);
|
|
17617
17623
|
var import_zod32 = require("zod");
|
|
17618
17624
|
|
|
17619
17625
|
// src/doctorReport.ts
|
|
@@ -17662,8 +17668,8 @@ var RenameJournalUnreadableError = class extends CliError {
|
|
|
17662
17668
|
}
|
|
17663
17669
|
detail;
|
|
17664
17670
|
};
|
|
17665
|
-
function readRenameJournal(
|
|
17666
|
-
const raw =
|
|
17671
|
+
function readRenameJournal(fs16, file) {
|
|
17672
|
+
const raw = fs16.readFileUtf8(file);
|
|
17667
17673
|
if (raw === void 0) {
|
|
17668
17674
|
return void 0;
|
|
17669
17675
|
}
|
|
@@ -17679,16 +17685,16 @@ function readRenameJournal(fs15, file) {
|
|
|
17679
17685
|
}
|
|
17680
17686
|
return result.data;
|
|
17681
17687
|
}
|
|
17682
|
-
function listRenameJournals(
|
|
17688
|
+
function listRenameJournals(fs16, directory) {
|
|
17683
17689
|
const journals = [];
|
|
17684
17690
|
const unreadable = [];
|
|
17685
|
-
for (const name of [...
|
|
17691
|
+
for (const name of [...fs16.readdir(directory)].sort()) {
|
|
17686
17692
|
if (!name.endsWith(JOURNAL_SUFFIX)) {
|
|
17687
17693
|
continue;
|
|
17688
17694
|
}
|
|
17689
17695
|
const file = import_node_path30.default.join(directory, name);
|
|
17690
17696
|
try {
|
|
17691
|
-
const journal = readRenameJournal(
|
|
17697
|
+
const journal = readRenameJournal(fs16, file);
|
|
17692
17698
|
if (journal !== void 0) {
|
|
17693
17699
|
journals.push(journal);
|
|
17694
17700
|
}
|
|
@@ -17731,8 +17737,8 @@ var NameHeldByUnfinishedRenameError = class extends CliError {
|
|
|
17731
17737
|
this.name = "NameHeldByUnfinishedRenameError";
|
|
17732
17738
|
}
|
|
17733
17739
|
};
|
|
17734
|
-
function requireNameFreeOfUnfinishedRename(
|
|
17735
|
-
const held = listRenameJournals(
|
|
17740
|
+
function requireNameFreeOfUnfinishedRename(fs16, directory, name, action, sameName, exists) {
|
|
17741
|
+
const held = listRenameJournals(fs16, directory).journals.find((journal) => [journal.from, journal.to].some((heldName) => heldName === name || sameName(name, heldName)));
|
|
17736
17742
|
if (held !== void 0) {
|
|
17737
17743
|
throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
|
|
17738
17744
|
}
|
|
@@ -18082,8 +18088,46 @@ function removeIdentity(paths, name) {
|
|
|
18082
18088
|
|
|
18083
18089
|
// src/doctorReport.ts
|
|
18084
18090
|
init_realPorts();
|
|
18085
|
-
var
|
|
18086
|
-
|
|
18091
|
+
var import_node_fs12 = __toESM(require("node:fs"), 1);
|
|
18092
|
+
|
|
18093
|
+
// src/doctorPath.ts
|
|
18094
|
+
var import_node_fs10 = __toESM(require("node:fs"), 1);
|
|
18095
|
+
var import_node_path33 = __toESM(require("node:path"), 1);
|
|
18096
|
+
init_blockingSpawn();
|
|
18097
|
+
init_realPorts();
|
|
18098
|
+
function realpathOrSelf(target) {
|
|
18099
|
+
try {
|
|
18100
|
+
return import_node_fs10.default.realpathSync(target);
|
|
18101
|
+
} catch {
|
|
18102
|
+
return target;
|
|
18103
|
+
}
|
|
18104
|
+
}
|
|
18105
|
+
var MAX_FORWARDING_SCRIPT_BYTES = 8192;
|
|
18106
|
+
function resolveMiseDispatcher(target, pathDirs, env, trustedExecutable) {
|
|
18107
|
+
const executable = realpathOrSelf(target);
|
|
18108
|
+
const trustedMise = import_node_path33.default.join(import_node_path33.default.dirname(trustedExecutable), "mise");
|
|
18109
|
+
if (import_node_path33.default.basename(executable) !== "mise" || realpathOrSelf(trustedMise) !== executable) return void 0;
|
|
18110
|
+
const result = spawnSyncBlocking("a mise shim lookup", executable, ["which", import_node_path33.default.basename(target)], { encoding: "utf8", env });
|
|
18111
|
+
if (result.error !== void 0) return void 0;
|
|
18112
|
+
if (result.status === 0 && result.stdout.trim() !== "") return result.stdout.trim();
|
|
18113
|
+
if (!result.stderr.includes("not currently active")) return void 0;
|
|
18114
|
+
for (const dir of pathDirs) {
|
|
18115
|
+
const candidate = findExecutableInDir(dir, import_node_path33.default.basename(target));
|
|
18116
|
+
if (candidate !== void 0 && realpathOrSelf(candidate) !== executable) {
|
|
18117
|
+
try {
|
|
18118
|
+
const script = import_node_fs10.default.statSync(candidate).size <= MAX_FORWARDING_SCRIPT_BYTES ? realFsPort.readFileUtf8(candidate) : void 0;
|
|
18119
|
+
const forwarded = script === void 0 ? void 0 : /^#!\/bin\/sh\r?\nexec (\/[A-Za-z0-9_./+-]+) "\$@"\r?\n?$/.exec(script)?.[1];
|
|
18120
|
+
return forwarded ?? candidate;
|
|
18121
|
+
} catch {
|
|
18122
|
+
return candidate;
|
|
18123
|
+
}
|
|
18124
|
+
}
|
|
18125
|
+
}
|
|
18126
|
+
return void 0;
|
|
18127
|
+
}
|
|
18128
|
+
|
|
18129
|
+
// src/doctorReport.ts
|
|
18130
|
+
var import_node_path35 = __toESM(require("node:path"), 1);
|
|
18087
18131
|
init_signIn();
|
|
18088
18132
|
init_identityAccounts();
|
|
18089
18133
|
init_read();
|
|
@@ -18329,7 +18373,7 @@ function pushFrontDoorListeners(push, readings) {
|
|
|
18329
18373
|
}
|
|
18330
18374
|
|
|
18331
18375
|
// src/frontdoor/listenerReadings.ts
|
|
18332
|
-
var
|
|
18376
|
+
var import_node_fs11 = __toESM(require("node:fs"), 1);
|
|
18333
18377
|
init_probe();
|
|
18334
18378
|
function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
18335
18379
|
if (!supervisorAlive) {
|
|
@@ -18350,7 +18394,7 @@ function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
|
18350
18394
|
}
|
|
18351
18395
|
function realFrontDoorListenerProbes(paths) {
|
|
18352
18396
|
return {
|
|
18353
|
-
authenticateProvider: (port) => probeFrontDoorSync(port,
|
|
18397
|
+
authenticateProvider: (port) => probeFrontDoorSync(port, import_node_fs11.default.readFileSync(paths.frontdoorCaCertFile, "utf8")),
|
|
18354
18398
|
connect: probeListenerAcceptSync,
|
|
18355
18399
|
now: () => performance.now()
|
|
18356
18400
|
};
|
|
@@ -18482,11 +18526,12 @@ var DOCTOR_SECTIONS = [
|
|
|
18482
18526
|
"frontdoor",
|
|
18483
18527
|
"models"
|
|
18484
18528
|
];
|
|
18485
|
-
function refinePathShadow(status, ownExecutablePath, realpath) {
|
|
18529
|
+
function refinePathShadow(status, ownExecutablePath, realpath, resolveDispatcher) {
|
|
18486
18530
|
if (status.status !== "shadowed") {
|
|
18487
18531
|
return status;
|
|
18488
18532
|
}
|
|
18489
|
-
|
|
18533
|
+
const resolved = resolveDispatcher?.(status.by) ?? status.by;
|
|
18534
|
+
return realpath(resolved) === realpath(ownExecutablePath) ? { status: "ok" } : status;
|
|
18490
18535
|
}
|
|
18491
18536
|
function validateJson(schema, input) {
|
|
18492
18537
|
if (input.raw === void 0) {
|
|
@@ -18515,7 +18560,7 @@ function tcpPortEraRecord(raw) {
|
|
|
18515
18560
|
return (has("port") || has("lastPort")) && !has("socketPath");
|
|
18516
18561
|
}
|
|
18517
18562
|
function pushPathResolution(push, resolution) {
|
|
18518
|
-
const ownDir =
|
|
18563
|
+
const ownDir = import_node_path35.default.dirname(resolution.ownExecutablePath);
|
|
18519
18564
|
switch (resolution.agentShim.status) {
|
|
18520
18565
|
case "ok":
|
|
18521
18566
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -18635,14 +18680,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
18635
18680
|
}
|
|
18636
18681
|
function pushLegacyName(push, params) {
|
|
18637
18682
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
18638
|
-
if (legacyVariables.length === 0 &&
|
|
18683
|
+
if (legacyVariables.length === 0 && import_node_path35.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
18639
18684
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
18640
18685
|
return;
|
|
18641
18686
|
}
|
|
18642
18687
|
for (const name of legacyVariables) {
|
|
18643
18688
|
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);
|
|
18644
18689
|
}
|
|
18645
|
-
if (
|
|
18690
|
+
if (import_node_path35.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
18646
18691
|
push(
|
|
18647
18692
|
"legacy-name",
|
|
18648
18693
|
"warn",
|
|
@@ -18736,7 +18781,7 @@ function runDoctor(params) {
|
|
|
18736
18781
|
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);
|
|
18737
18782
|
}
|
|
18738
18783
|
for (const { file, detail } of params.renameJournals?.unreadable ?? []) {
|
|
18739
|
-
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.`,
|
|
18784
|
+
push("identity", "fail", `${file} is not a rename journal this agent-shim can read (${detail}), so no identity can be renamed until it is fixed or removed, and it may be the trace of a rename that was left unfinished.`, import_node_path35.default.basename(file));
|
|
18740
18785
|
}
|
|
18741
18786
|
const validIdentityNames = /* @__PURE__ */ new Set();
|
|
18742
18787
|
const signedInAccounts = [];
|
|
@@ -19086,13 +19131,6 @@ function formatDoctorReport(report) {
|
|
|
19086
19131
|
lines.push("", report.ok ? "All checks passed." : `${String(failCount)} check(s) failed.`);
|
|
19087
19132
|
return lines;
|
|
19088
19133
|
}
|
|
19089
|
-
function realpathOrSelf(target) {
|
|
19090
|
-
try {
|
|
19091
|
-
return import_node_fs11.default.realpathSync(target);
|
|
19092
|
-
} catch {
|
|
19093
|
-
return target;
|
|
19094
|
-
}
|
|
19095
|
-
}
|
|
19096
19134
|
function servingDoorListeners(paths) {
|
|
19097
19135
|
const state = readFrontDoorState(realFarmFs, paths.frontdoorStateFile) ?? {};
|
|
19098
19136
|
const alive = state.supervisorPid !== void 0 && realIsProcessRunning(state.supervisorPid);
|
|
@@ -19102,9 +19140,9 @@ function collectDoctorReport(params) {
|
|
|
19102
19140
|
const { paths } = params;
|
|
19103
19141
|
const { names: identityNames, unreachable: unreachableIdentities } = listIdentityDirectories(paths);
|
|
19104
19142
|
const identities = identityNames.map((name) => {
|
|
19105
|
-
const farmRoot =
|
|
19106
|
-
const identityPath =
|
|
19107
|
-
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent:
|
|
19143
|
+
const farmRoot = import_node_path35.default.join(paths.identitiesDir, name);
|
|
19144
|
+
const identityPath = import_node_path35.default.join(farmRoot, "identity.json");
|
|
19145
|
+
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs12.default.existsSync(credentialsFilePath(farmRoot)), account: readIdentityAccount(realFsPort, paths.identitiesDir, name)?.account };
|
|
19108
19146
|
});
|
|
19109
19147
|
const usageSnapshots = {};
|
|
19110
19148
|
for (const name of identityNames) {
|
|
@@ -19119,14 +19157,14 @@ function collectDoctorReport(params) {
|
|
|
19119
19157
|
}
|
|
19120
19158
|
}
|
|
19121
19159
|
}
|
|
19122
|
-
const profileNames =
|
|
19160
|
+
const profileNames = import_node_fs12.default.existsSync(paths.configProfilesDir) ? import_node_fs12.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
19123
19161
|
const configProfiles = profileNames.map((name) => {
|
|
19124
|
-
const profilePath =
|
|
19162
|
+
const profilePath = import_node_path35.default.join(paths.configProfilesDir, `${name}.json`);
|
|
19125
19163
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
19126
19164
|
});
|
|
19127
|
-
const providerNames =
|
|
19165
|
+
const providerNames = import_node_fs12.default.existsSync(paths.providersDir) ? import_node_fs12.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
19128
19166
|
const providers = providerNames.map((name) => {
|
|
19129
|
-
const providerPath =
|
|
19167
|
+
const providerPath = import_node_path35.default.join(paths.providersDir, `${name}.json`);
|
|
19130
19168
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
19131
19169
|
});
|
|
19132
19170
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -19138,16 +19176,17 @@ function collectDoctorReport(params) {
|
|
|
19138
19176
|
binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
19139
19177
|
}
|
|
19140
19178
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
19141
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
19179
|
+
const pathDirs = (params.env.PATH ?? "").split(import_node_path35.default.delimiter).filter((dir) => dir !== "");
|
|
19142
19180
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
19143
19181
|
findPathShadow({
|
|
19144
19182
|
pathDirs,
|
|
19145
|
-
targetDir:
|
|
19146
|
-
targetFilename:
|
|
19183
|
+
targetDir: import_node_path35.default.dirname(shimState.targetPath),
|
|
19184
|
+
targetFilename: import_node_path35.default.basename(shimState.targetPath),
|
|
19147
19185
|
findExecutableInDir
|
|
19148
19186
|
}),
|
|
19149
19187
|
shimState.targetPath,
|
|
19150
|
-
realpathOrSelf
|
|
19188
|
+
realpathOrSelf,
|
|
19189
|
+
(target) => resolveMiseDispatcher(target, pathDirs, params.env, shimState.targetPath)
|
|
19151
19190
|
);
|
|
19152
19191
|
const uid = process.getuid?.();
|
|
19153
19192
|
const allowlistContent = realFarmFs.readFileUtf8(paths.headroomAllowlistFile);
|
|
@@ -19175,19 +19214,20 @@ function collectDoctorReport(params) {
|
|
|
19175
19214
|
categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
|
|
19176
19215
|
activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
|
|
19177
19216
|
binaryDiscovery,
|
|
19178
|
-
claudeShim: { state: shimState, targetExists: shimState !== void 0 &&
|
|
19217
|
+
claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs12.default.existsSync(shimState.targetPath) },
|
|
19179
19218
|
rootPath: paths.root,
|
|
19180
19219
|
pathResolution: {
|
|
19181
19220
|
ownExecutablePath,
|
|
19182
19221
|
agentShim: refinePathShadow(
|
|
19183
19222
|
findPathShadow({
|
|
19184
19223
|
pathDirs,
|
|
19185
|
-
targetDir:
|
|
19224
|
+
targetDir: import_node_path35.default.dirname(ownExecutablePath),
|
|
19186
19225
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
19187
19226
|
findExecutableInDir
|
|
19188
19227
|
}),
|
|
19189
19228
|
ownExecutablePath,
|
|
19190
|
-
realpathOrSelf
|
|
19229
|
+
realpathOrSelf,
|
|
19230
|
+
(target) => resolveMiseDispatcher(target, pathDirs, params.env, ownExecutablePath)
|
|
19191
19231
|
),
|
|
19192
19232
|
...claudeShimShadow === void 0 ? {} : { claude: claudeShimShadow }
|
|
19193
19233
|
},
|
|
@@ -19272,11 +19312,11 @@ var FrontDoorSessionsOutputSchema = import_zod32.z.strictObject({ sessions: impo
|
|
|
19272
19312
|
var CheckRunInputSchema = import_zod32.z.strictObject({
|
|
19273
19313
|
path: import_zod32.z.string().min(1),
|
|
19274
19314
|
identity: import_zod32.z.string().min(1).optional()
|
|
19275
|
-
}).refine((input) =>
|
|
19315
|
+
}).refine((input) => import_node_path36.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
19276
19316
|
var PoolPickInputSchema = import_zod32.z.strictObject({
|
|
19277
19317
|
pool: import_zod32.z.string().min(1),
|
|
19278
19318
|
path: import_zod32.z.string().min(1)
|
|
19279
|
-
}).refine((input) =>
|
|
19319
|
+
}).refine((input) => import_node_path36.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
19280
19320
|
var DoctorFindingSchema = import_zod32.z.strictObject({
|
|
19281
19321
|
section: import_zod32.z.enum(DOCTOR_SECTIONS),
|
|
19282
19322
|
subject: import_zod32.z.string().optional(),
|
|
@@ -19700,7 +19740,7 @@ function profileValue(name, paths) {
|
|
|
19700
19740
|
function createConfigApiRouter(deps) {
|
|
19701
19741
|
const authed = doorApiAuth(deps.expectedToken);
|
|
19702
19742
|
const { paths } = deps;
|
|
19703
|
-
const route = (
|
|
19743
|
+
const route = (path49, summary) => authed.meta((0, import_openapi3.openapi)({ method: "POST", path: path49, summary, tags: [CONFIG_API_TAG] }));
|
|
19704
19744
|
return {
|
|
19705
19745
|
config: {
|
|
19706
19746
|
identity: {
|
|
@@ -20087,7 +20127,7 @@ var import_openapi6 = require("@orpc/openapi");
|
|
|
20087
20127
|
init_cliError();
|
|
20088
20128
|
|
|
20089
20129
|
// src/frontdoor/launchSchemas.ts
|
|
20090
|
-
var
|
|
20130
|
+
var import_node_path37 = __toESM(require("node:path"), 1);
|
|
20091
20131
|
var import_zod36 = require("zod");
|
|
20092
20132
|
init_statusline();
|
|
20093
20133
|
init_claudeVersion();
|
|
@@ -20098,7 +20138,7 @@ var LaunchResolveInputSchema = import_zod36.z.strictObject({
|
|
|
20098
20138
|
argv: import_zod36.z.readonly(import_zod36.z.array(import_zod36.z.string())).optional(),
|
|
20099
20139
|
/** 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. */
|
|
20100
20140
|
env: import_zod36.z.record(import_zod36.z.string(), import_zod36.z.string()).optional()
|
|
20101
|
-
}).refine((input) =>
|
|
20141
|
+
}).refine((input) => import_node_path37.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
20102
20142
|
var LaunchPoolDecisionSchema = import_zod36.z.strictObject({
|
|
20103
20143
|
name: import_zod36.z.string(),
|
|
20104
20144
|
reasons: import_zod36.z.readonly(import_zod36.z.array(import_zod36.z.string())),
|
|
@@ -22278,7 +22318,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
22278
22318
|
}
|
|
22279
22319
|
|
|
22280
22320
|
// src/frontdoor/rcSelfHostMint.ts
|
|
22281
|
-
var
|
|
22321
|
+
var import_node_path38 = __toESM(require("node:path"), 1);
|
|
22282
22322
|
init_account();
|
|
22283
22323
|
var CREDENTIALS_FILE2 = ".credentials.json";
|
|
22284
22324
|
var CLAUDE_JSON2 = ".claude.json";
|
|
@@ -22289,8 +22329,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
|
22289
22329
|
function isRecord14(value) {
|
|
22290
22330
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22291
22331
|
}
|
|
22292
|
-
function readJsonObject(
|
|
22293
|
-
const raw =
|
|
22332
|
+
function readJsonObject(fs16, file) {
|
|
22333
|
+
const raw = fs16.readFileUtf8(file);
|
|
22294
22334
|
if (raw === void 0) {
|
|
22295
22335
|
return void 0;
|
|
22296
22336
|
}
|
|
@@ -22302,8 +22342,8 @@ function readJsonObject(fs15, file) {
|
|
|
22302
22342
|
}
|
|
22303
22343
|
return isRecord14(parsed) ? parsed : void 0;
|
|
22304
22344
|
}
|
|
22305
|
-
function readRcSelfHostRecord(
|
|
22306
|
-
const parsed = readJsonObject(
|
|
22345
|
+
function readRcSelfHostRecord(fs16, frontdoorDir) {
|
|
22346
|
+
const parsed = readJsonObject(fs16, import_node_path38.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
22307
22347
|
if (parsed === void 0) {
|
|
22308
22348
|
return void 0;
|
|
22309
22349
|
}
|
|
@@ -22317,11 +22357,11 @@ function mintRcSelfHostCredential(deps) {
|
|
|
22317
22357
|
if (!isIdentityName(deps.identity)) {
|
|
22318
22358
|
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
22319
22359
|
}
|
|
22320
|
-
const identityDir =
|
|
22321
|
-
const credentialsFile =
|
|
22322
|
-
const claudeJsonFile =
|
|
22323
|
-
const recordDir =
|
|
22324
|
-
const recordFile2 =
|
|
22360
|
+
const identityDir = import_node_path38.default.join(deps.identitiesDir, deps.identity);
|
|
22361
|
+
const credentialsFile = import_node_path38.default.join(identityDir, CREDENTIALS_FILE2);
|
|
22362
|
+
const claudeJsonFile = import_node_path38.default.join(identityDir, CLAUDE_JSON2);
|
|
22363
|
+
const recordDir = import_node_path38.default.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
22364
|
+
const recordFile2 = import_node_path38.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
22325
22365
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
22326
22366
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
22327
22367
|
const existingOauth = isRecord14(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
@@ -22337,7 +22377,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
22337
22377
|
const organizationUuid = deps.newUuid();
|
|
22338
22378
|
const accountUuid = deps.newUuid();
|
|
22339
22379
|
const mintedAt = new Date(deps.now()).toISOString();
|
|
22340
|
-
deps.fs.mkdirPrivate(
|
|
22380
|
+
deps.fs.mkdirPrivate(import_node_path38.default.dirname(credentialsFile));
|
|
22341
22381
|
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)}
|
|
22342
22382
|
`);
|
|
22343
22383
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
@@ -22373,27 +22413,27 @@ function mintRcSelfHostCredential(deps) {
|
|
|
22373
22413
|
init_ensure2();
|
|
22374
22414
|
|
|
22375
22415
|
// src/frontdoor/liveSessionRegistry.ts
|
|
22376
|
-
var
|
|
22416
|
+
var import_node_path39 = __toESM(require("node:path"), 1);
|
|
22377
22417
|
init_capability();
|
|
22378
22418
|
init_state();
|
|
22379
22419
|
function sameStat(recorded, current) {
|
|
22380
22420
|
return recorded?.mtimeMs === current.mtimeMs && recorded.sizeBytes === current.sizeBytes;
|
|
22381
22421
|
}
|
|
22382
22422
|
function createLiveSessionRegistry(ports) {
|
|
22383
|
-
const { fs:
|
|
22423
|
+
const { fs: fs16, sessionsDir } = ports;
|
|
22384
22424
|
const known = /* @__PURE__ */ new Map();
|
|
22385
22425
|
let tokens = /* @__PURE__ */ new Set();
|
|
22386
22426
|
let bySessionId = /* @__PURE__ */ new Map();
|
|
22387
|
-
const recordNames = () =>
|
|
22427
|
+
const recordNames = () => fs16.readdir(sessionsDir).filter(isSessionRecordName);
|
|
22388
22428
|
const rebuildIndexes = () => {
|
|
22389
22429
|
const records = [...known.values()].flatMap(({ record }) => record === void 0 ? [] : [record]);
|
|
22390
22430
|
tokens = new Set(records.map((record) => record.token));
|
|
22391
22431
|
bySessionId = new Map(records.flatMap((record) => record.sessionId === void 0 ? [] : [[record.sessionId, record]]));
|
|
22392
22432
|
};
|
|
22393
22433
|
const load = (name, stat) => {
|
|
22394
|
-
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(
|
|
22434
|
+
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(fs16, sessionsDir, name) });
|
|
22395
22435
|
};
|
|
22396
|
-
const statOf = (name) =>
|
|
22436
|
+
const statOf = (name) => fs16.lstat(import_node_path39.default.join(sessionsDir, name));
|
|
22397
22437
|
const reconcile = () => {
|
|
22398
22438
|
const names = new Set(recordNames());
|
|
22399
22439
|
let changed = false;
|
|
@@ -22460,7 +22500,7 @@ init_plan2();
|
|
|
22460
22500
|
init_poolPick();
|
|
22461
22501
|
|
|
22462
22502
|
// src/agents/read.ts
|
|
22463
|
-
var
|
|
22503
|
+
var import_node_path40 = __toESM(require("node:path"), 1);
|
|
22464
22504
|
var import_zod38 = require("zod");
|
|
22465
22505
|
var PROJECTS_DIR = "projects";
|
|
22466
22506
|
var TASKS_DIR = "tasks";
|
|
@@ -22484,17 +22524,17 @@ function parseEntry2(project, entry) {
|
|
|
22484
22524
|
const base = match?.[1];
|
|
22485
22525
|
return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
|
|
22486
22526
|
}
|
|
22487
|
-
function listSessions2(
|
|
22527
|
+
function listSessions2(fs16, configDir) {
|
|
22488
22528
|
const found = [];
|
|
22489
|
-
for (const project of
|
|
22490
|
-
const projectDir =
|
|
22529
|
+
for (const project of fs16.readdir(import_node_path40.default.join(configDir, PROJECTS_DIR))) {
|
|
22530
|
+
const projectDir = import_node_path40.default.join(configDir, PROJECTS_DIR, project);
|
|
22491
22531
|
const entries = /* @__PURE__ */ new Set();
|
|
22492
|
-
for (const name of
|
|
22532
|
+
for (const name of fs16.readdir(projectDir)) {
|
|
22493
22533
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
22494
22534
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
22495
22535
|
continue;
|
|
22496
22536
|
}
|
|
22497
|
-
const children =
|
|
22537
|
+
const children = fs16.readdir(import_node_path40.default.join(projectDir, name));
|
|
22498
22538
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
22499
22539
|
entries.add(name);
|
|
22500
22540
|
}
|
|
@@ -22505,17 +22545,17 @@ function listSessions2(fs15, configDir) {
|
|
|
22505
22545
|
}
|
|
22506
22546
|
return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
|
|
22507
22547
|
}
|
|
22508
|
-
function locateAgents(
|
|
22548
|
+
function locateAgents(fs16, configDir, relativeDir, workflowRunId, report) {
|
|
22509
22549
|
const located = [];
|
|
22510
|
-
for (const name of listDirOrReport(
|
|
22550
|
+
for (const name of listDirOrReport(fs16, configDir, relativeDir, report)) {
|
|
22511
22551
|
if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
|
|
22512
22552
|
continue;
|
|
22513
22553
|
}
|
|
22514
22554
|
const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
|
|
22515
22555
|
located.push({
|
|
22516
22556
|
id,
|
|
22517
|
-
metaPath:
|
|
22518
|
-
transcriptPath:
|
|
22557
|
+
metaPath: import_node_path40.default.join(relativeDir, name),
|
|
22558
|
+
transcriptPath: import_node_path40.default.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
|
|
22519
22559
|
workflowRunId
|
|
22520
22560
|
});
|
|
22521
22561
|
}
|
|
@@ -22556,17 +22596,17 @@ function toNode(read, children) {
|
|
|
22556
22596
|
function describeFailure(error) {
|
|
22557
22597
|
return error instanceof Error ? error.message : String(error);
|
|
22558
22598
|
}
|
|
22559
|
-
function readFileOrReport(
|
|
22599
|
+
function readFileOrReport(fs16, configDir, relative, report) {
|
|
22560
22600
|
try {
|
|
22561
|
-
return
|
|
22601
|
+
return fs16.readFileUtf8(import_node_path40.default.join(configDir, relative));
|
|
22562
22602
|
} catch (error) {
|
|
22563
22603
|
report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
|
|
22564
22604
|
return void 0;
|
|
22565
22605
|
}
|
|
22566
22606
|
}
|
|
22567
|
-
function listDirOrReport(
|
|
22607
|
+
function listDirOrReport(fs16, configDir, relative, report) {
|
|
22568
22608
|
try {
|
|
22569
|
-
return
|
|
22609
|
+
return fs16.readdir(import_node_path40.default.join(configDir, relative));
|
|
22570
22610
|
} catch (error) {
|
|
22571
22611
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
|
|
22572
22612
|
return [];
|
|
@@ -22589,38 +22629,38 @@ var WorkflowRunFileSchema = import_zod38.z.object({
|
|
|
22589
22629
|
phases: import_zod38.z.array(import_zod38.z.object({ title: import_zod38.z.string() })).default([]),
|
|
22590
22630
|
summary: import_zod38.z.string().optional()
|
|
22591
22631
|
});
|
|
22592
|
-
function summariseSession(
|
|
22593
|
-
const sessionRelative =
|
|
22594
|
-
const subagentsRelative =
|
|
22595
|
-
const workflowsUnderSubagents =
|
|
22632
|
+
function summariseSession(fs16, configDir, ref) {
|
|
22633
|
+
const sessionRelative = import_node_path40.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22634
|
+
const subagentsRelative = import_node_path40.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
22635
|
+
const workflowsUnderSubagents = import_node_path40.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
22596
22636
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
22597
|
-
let agentCount =
|
|
22598
|
-
for (const runDir of
|
|
22637
|
+
let agentCount = fs16.readdir(import_node_path40.default.join(configDir, subagentsRelative)).filter(isMeta).length;
|
|
22638
|
+
for (const runDir of fs16.readdir(import_node_path40.default.join(configDir, workflowsUnderSubagents))) {
|
|
22599
22639
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
22600
|
-
agentCount +=
|
|
22640
|
+
agentCount += fs16.readdir(import_node_path40.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
22601
22641
|
}
|
|
22602
22642
|
}
|
|
22603
|
-
const workflowRunCount =
|
|
22604
|
-
const transcript =
|
|
22643
|
+
const workflowRunCount = fs16.readdir(import_node_path40.default.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
|
|
22644
|
+
const transcript = fs16.lstat(import_node_path40.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
|
|
22605
22645
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
22606
22646
|
}
|
|
22607
|
-
function readSessionAgentTree(
|
|
22647
|
+
function readSessionAgentTree(fs16, configDir, ref, options = {}) {
|
|
22608
22648
|
const problems = [];
|
|
22609
22649
|
const report = (problem) => {
|
|
22610
22650
|
problems.push(problem);
|
|
22611
22651
|
};
|
|
22612
|
-
const sessionRelative =
|
|
22613
|
-
const subagentsRelative =
|
|
22614
|
-
const workflowsUnderSubagents =
|
|
22615
|
-
const located = locateAgents(
|
|
22616
|
-
for (const runDir of listDirOrReport(
|
|
22652
|
+
const sessionRelative = import_node_path40.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22653
|
+
const subagentsRelative = import_node_path40.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
22654
|
+
const workflowsUnderSubagents = import_node_path40.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
22655
|
+
const located = locateAgents(fs16, configDir, subagentsRelative, void 0, report);
|
|
22656
|
+
for (const runDir of listDirOrReport(fs16, configDir, workflowsUnderSubagents, report)) {
|
|
22617
22657
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
22618
|
-
located.push(...locateAgents(
|
|
22658
|
+
located.push(...locateAgents(fs16, configDir, import_node_path40.default.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
22619
22659
|
}
|
|
22620
22660
|
}
|
|
22621
22661
|
const agents = /* @__PURE__ */ new Map();
|
|
22622
22662
|
for (const candidate of located) {
|
|
22623
|
-
const text = readFileOrReport(
|
|
22663
|
+
const text = readFileOrReport(fs16, configDir, candidate.metaPath, report);
|
|
22624
22664
|
if (text === void 0) {
|
|
22625
22665
|
continue;
|
|
22626
22666
|
}
|
|
@@ -22632,7 +22672,7 @@ function readSessionAgentTree(fs15, configDir, ref, options = {}) {
|
|
|
22632
22672
|
agents.set(candidate.id, { located: candidate, meta: parsed.data });
|
|
22633
22673
|
}
|
|
22634
22674
|
const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
|
|
22635
|
-
const parentOf3 = resolveParents(
|
|
22675
|
+
const parentOf3 = resolveParents(fs16, configDir, agents, report);
|
|
22636
22676
|
const childrenOf = /* @__PURE__ */ new Map();
|
|
22637
22677
|
const roots = [];
|
|
22638
22678
|
for (const id of agents.keys()) {
|
|
@@ -22655,12 +22695,12 @@ function readSessionAgentTree(fs15, configDir, ref, options = {}) {
|
|
|
22655
22695
|
sessionId: ref.sessionId,
|
|
22656
22696
|
superseded: ref.superseded,
|
|
22657
22697
|
agents: roots.sort().map(build),
|
|
22658
|
-
tasks: readTasks(
|
|
22659
|
-
workflowRuns: readWorkflowRuns(
|
|
22698
|
+
tasks: readTasks(fs16, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
|
|
22699
|
+
workflowRuns: readWorkflowRuns(fs16, configDir, import_node_path40.default.join(sessionRelative, WORKFLOWS_DIR), report),
|
|
22660
22700
|
problems
|
|
22661
22701
|
};
|
|
22662
22702
|
}
|
|
22663
|
-
function resolveParents(
|
|
22703
|
+
function resolveParents(fs16, configDir, agents, report) {
|
|
22664
22704
|
const parentOf3 = /* @__PURE__ */ new Map();
|
|
22665
22705
|
const transcriptCache = /* @__PURE__ */ new Map();
|
|
22666
22706
|
const transcriptOf = (agent) => {
|
|
@@ -22668,7 +22708,7 @@ function resolveParents(fs15, configDir, agents, report) {
|
|
|
22668
22708
|
if (cached !== void 0) {
|
|
22669
22709
|
return cached;
|
|
22670
22710
|
}
|
|
22671
|
-
const text = readFileOrReport(
|
|
22711
|
+
const text = readFileOrReport(fs16, configDir, agent.located.transcriptPath, report) ?? "";
|
|
22672
22712
|
transcriptCache.set(agent.located.id, text);
|
|
22673
22713
|
return text;
|
|
22674
22714
|
};
|
|
@@ -22718,16 +22758,16 @@ function resolveParents(fs15, configDir, agents, report) {
|
|
|
22718
22758
|
function ownTaskLists(sessionId) {
|
|
22719
22759
|
return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
|
|
22720
22760
|
}
|
|
22721
|
-
function readTasks(
|
|
22761
|
+
function readTasks(fs16, configDir, ownLists, sharedLists, report) {
|
|
22722
22762
|
const tasks = [];
|
|
22723
22763
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
22724
|
-
const relativeDir =
|
|
22725
|
-
for (const name of [...listDirOrReport(
|
|
22764
|
+
const relativeDir = import_node_path40.default.join(TASKS_DIR, scope);
|
|
22765
|
+
for (const name of [...listDirOrReport(fs16, configDir, relativeDir, report)].sort()) {
|
|
22726
22766
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
22727
22767
|
continue;
|
|
22728
22768
|
}
|
|
22729
|
-
const relative =
|
|
22730
|
-
const text = readFileOrReport(
|
|
22769
|
+
const relative = import_node_path40.default.join(relativeDir, name);
|
|
22770
|
+
const text = readFileOrReport(fs16, configDir, relative, report);
|
|
22731
22771
|
const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
22732
22772
|
if (parsed.success) {
|
|
22733
22773
|
tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
|
|
@@ -22738,14 +22778,14 @@ function readTasks(fs15, configDir, ownLists, sharedLists, report) {
|
|
|
22738
22778
|
});
|
|
22739
22779
|
return tasks;
|
|
22740
22780
|
}
|
|
22741
|
-
function readWorkflowRuns(
|
|
22781
|
+
function readWorkflowRuns(fs16, configDir, relativeDir, report) {
|
|
22742
22782
|
const runs = [];
|
|
22743
|
-
for (const name of [...listDirOrReport(
|
|
22783
|
+
for (const name of [...listDirOrReport(fs16, configDir, relativeDir, report)].sort()) {
|
|
22744
22784
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
22745
22785
|
continue;
|
|
22746
22786
|
}
|
|
22747
|
-
const relative =
|
|
22748
|
-
const text = readFileOrReport(
|
|
22787
|
+
const relative = import_node_path40.default.join(relativeDir, name);
|
|
22788
|
+
const text = readFileOrReport(fs16, configDir, relative, report);
|
|
22749
22789
|
const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
22750
22790
|
if (!parsed.success) {
|
|
22751
22791
|
if (text !== void 0) {
|
|
@@ -22760,7 +22800,7 @@ function readWorkflowRuns(fs15, configDir, relativeDir, report) {
|
|
|
22760
22800
|
}
|
|
22761
22801
|
|
|
22762
22802
|
// src/agents/sessions.ts
|
|
22763
|
-
var
|
|
22803
|
+
var import_node_path41 = __toESM(require("node:path"), 1);
|
|
22764
22804
|
init_cliError();
|
|
22765
22805
|
var SessionLookupError = class extends CliError {
|
|
22766
22806
|
constructor(message) {
|
|
@@ -22769,13 +22809,13 @@ var SessionLookupError = class extends CliError {
|
|
|
22769
22809
|
}
|
|
22770
22810
|
};
|
|
22771
22811
|
function identityConfigDir(identitiesDir, identity) {
|
|
22772
|
-
return
|
|
22812
|
+
return import_node_path41.default.join(identitiesDir, identity);
|
|
22773
22813
|
}
|
|
22774
|
-
function historyStores(
|
|
22814
|
+
function historyStores(fs16, identitiesDir, identities) {
|
|
22775
22815
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
22776
22816
|
for (const identity of identities) {
|
|
22777
22817
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
22778
|
-
const real =
|
|
22818
|
+
const real = fs16.realpath(import_node_path41.default.join(configDir, "projects"));
|
|
22779
22819
|
if (real === void 0) {
|
|
22780
22820
|
continue;
|
|
22781
22821
|
}
|
|
@@ -22788,15 +22828,15 @@ function historyStores(fs15, identitiesDir, identities) {
|
|
|
22788
22828
|
}
|
|
22789
22829
|
return [...byRealPath.values()];
|
|
22790
22830
|
}
|
|
22791
|
-
function collectSessionList(
|
|
22831
|
+
function collectSessionList(fs16, identitiesDir, identities, filters) {
|
|
22792
22832
|
const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
|
|
22793
22833
|
if (filters.identity !== void 0 && names.length === 0) {
|
|
22794
22834
|
throw new SessionLookupError(`no identity named "${filters.identity}"`);
|
|
22795
22835
|
}
|
|
22796
22836
|
const sessions = [];
|
|
22797
|
-
for (const store of historyStores(
|
|
22798
|
-
for (const ref of listSessions2(
|
|
22799
|
-
const summary = summariseSession(
|
|
22837
|
+
for (const store of historyStores(fs16, identitiesDir, names)) {
|
|
22838
|
+
for (const ref of listSessions2(fs16, store.configDir)) {
|
|
22839
|
+
const summary = summariseSession(fs16, store.configDir, ref);
|
|
22800
22840
|
if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
|
|
22801
22841
|
sessions.push({ ...summary, identities: store.identities });
|
|
22802
22842
|
}
|
|
@@ -22804,14 +22844,14 @@ function collectSessionList(fs15, identitiesDir, identities, filters) {
|
|
|
22804
22844
|
}
|
|
22805
22845
|
return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
|
|
22806
22846
|
}
|
|
22807
|
-
function locateSession(
|
|
22847
|
+
function locateSession(fs16, identitiesDir, identities, query, onlyIdentity) {
|
|
22808
22848
|
const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
|
|
22809
22849
|
if (onlyIdentity !== void 0 && names.length === 0) {
|
|
22810
22850
|
throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
|
|
22811
22851
|
}
|
|
22812
22852
|
const matches = [];
|
|
22813
|
-
for (const store of historyStores(
|
|
22814
|
-
for (const ref of listSessions2(
|
|
22853
|
+
for (const store of historyStores(fs16, identitiesDir, names)) {
|
|
22854
|
+
for (const ref of listSessions2(fs16, store.configDir)) {
|
|
22815
22855
|
if (ref.sessionId.startsWith(query)) {
|
|
22816
22856
|
matches.push({ identities: store.identities, configDir: store.configDir, ref });
|
|
22817
22857
|
}
|
|
@@ -22828,19 +22868,19 @@ function locateSession(fs15, identitiesDir, identities, query, onlyIdentity) {
|
|
|
22828
22868
|
}
|
|
22829
22869
|
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`);
|
|
22830
22870
|
}
|
|
22831
|
-
function showSession(
|
|
22832
|
-
const located = locateSession(
|
|
22833
|
-
return { identities: located.identities, tree: readSessionAgentTree(
|
|
22871
|
+
function showSession(fs16, identitiesDir, identities, query, onlyIdentity) {
|
|
22872
|
+
const located = locateSession(fs16, identitiesDir, identities, query, onlyIdentity);
|
|
22873
|
+
return { identities: located.identities, tree: readSessionAgentTree(fs16, located.configDir, located.ref) };
|
|
22834
22874
|
}
|
|
22835
22875
|
|
|
22836
22876
|
// src/agents/realFs.ts
|
|
22837
|
-
var
|
|
22877
|
+
var import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
22838
22878
|
init_realPorts();
|
|
22839
22879
|
var realSessionFs = {
|
|
22840
22880
|
...realFarmFs,
|
|
22841
22881
|
realpath: (candidate) => {
|
|
22842
22882
|
try {
|
|
22843
|
-
return
|
|
22883
|
+
return import_node_fs13.default.realpathSync(candidate);
|
|
22844
22884
|
} catch {
|
|
22845
22885
|
return void 0;
|
|
22846
22886
|
}
|