agent-shim 11.84.0 → 11.84.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1043 -1009
- package/dist/index.cjs +499 -465
- package/dist/index.mjs +487 -453
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1300,7 +1300,7 @@ function parseIgnoringUnrecognisedKeys(schema, raw) {
|
|
|
1300
1300
|
return second.success ? { success: true, data: second.data, ignored } : { success: false, issues: second.error.issues };
|
|
1301
1301
|
}
|
|
1302
1302
|
function describeIgnoredKeys(filePath, ignored) {
|
|
1303
|
-
const places = ignored.map(({ path:
|
|
1303
|
+
const places = ignored.map(({ path: path49, keys }) => `${path49.length === 0 ? "" : `${path49.map(String).join(".")}.`}${keys.join(", ")}`);
|
|
1304
1304
|
return `${filePath} has settings this version of agent-shim does not know and ignores: ${places.join("; ")}. A newer release may read them.`;
|
|
1305
1305
|
}
|
|
1306
1306
|
function noteIgnoredKeys(filePath, ignored) {
|
|
@@ -1322,9 +1322,9 @@ function restoreIgnoredKeys(filePath, value) {
|
|
|
1322
1322
|
return value;
|
|
1323
1323
|
}
|
|
1324
1324
|
const restored = structuredClone(value);
|
|
1325
|
-
for (const { path:
|
|
1325
|
+
for (const { path: path49, values } of ignored) {
|
|
1326
1326
|
let holder = restored;
|
|
1327
|
-
for (const step of
|
|
1327
|
+
for (const step of path49) {
|
|
1328
1328
|
holder = isRecord(holder) ? holder[step] : void 0;
|
|
1329
1329
|
}
|
|
1330
1330
|
if (isRecord(holder)) {
|
|
@@ -3044,8 +3044,8 @@ var init_lock = __esm({
|
|
|
3044
3044
|
});
|
|
3045
3045
|
|
|
3046
3046
|
// src/launcher/farm.ts
|
|
3047
|
-
function readFarmManifest(
|
|
3048
|
-
const raw =
|
|
3047
|
+
function readFarmManifest(fs16, farmRoot) {
|
|
3048
|
+
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
3049
|
if (raw === void 0) {
|
|
3050
3050
|
return void 0;
|
|
3051
3051
|
}
|
|
@@ -3103,9 +3103,9 @@ function buildEntryFacts(params) {
|
|
|
3103
3103
|
entries
|
|
3104
3104
|
};
|
|
3105
3105
|
}
|
|
3106
|
-
function listSubtree(
|
|
3106
|
+
function listSubtree(fs16, root, rel) {
|
|
3107
3107
|
const absolute = import_node_path8.default.join(root, rel);
|
|
3108
|
-
const stat =
|
|
3108
|
+
const stat = fs16.lstat(absolute);
|
|
3109
3109
|
if (stat === void 0) {
|
|
3110
3110
|
return [];
|
|
3111
3111
|
}
|
|
@@ -3113,10 +3113,10 @@ function listSubtree(fs15, root, rel) {
|
|
|
3113
3113
|
return [{ rel, kind: "symlink" }];
|
|
3114
3114
|
}
|
|
3115
3115
|
if (stat.kind === "dir") {
|
|
3116
|
-
const children = [...
|
|
3116
|
+
const children = [...fs16.readdir(absolute)].sort().flatMap((name) => listSubtree(fs16, root, `${rel}/${name}`));
|
|
3117
3117
|
return [{ rel, kind: "dir" }, ...children];
|
|
3118
3118
|
}
|
|
3119
|
-
const contentHash =
|
|
3119
|
+
const contentHash = fs16.hashFile(absolute);
|
|
3120
3120
|
return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
|
|
3121
3121
|
}
|
|
3122
3122
|
function topLevelScopeRoots(roots) {
|
|
@@ -3130,25 +3130,25 @@ function topLevelScopeRoots(roots) {
|
|
|
3130
3130
|
}
|
|
3131
3131
|
return kept;
|
|
3132
3132
|
}
|
|
3133
|
-
function reconciliationScope(
|
|
3133
|
+
function reconciliationScope(fs16, farmRoot, manifest) {
|
|
3134
3134
|
if (manifest !== void 0) {
|
|
3135
3135
|
return topLevelScopeRoots(manifest.materialised);
|
|
3136
3136
|
}
|
|
3137
|
-
return [...
|
|
3137
|
+
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
3138
|
}
|
|
3139
|
-
function collectFarmListing(
|
|
3140
|
-
return scopeRoots.flatMap((root) => listSubtree(
|
|
3139
|
+
function collectFarmListing(fs16, farmRoot, scopeRoots) {
|
|
3140
|
+
return scopeRoots.flatMap((root) => listSubtree(fs16, farmRoot, root));
|
|
3141
3141
|
}
|
|
3142
|
-
function collectCanonicalCounterparts(
|
|
3142
|
+
function collectCanonicalCounterparts(fs16, claudeHome, farmListing) {
|
|
3143
3143
|
const out = [];
|
|
3144
3144
|
for (const entry of farmListing) {
|
|
3145
3145
|
const absolute = import_node_path8.default.join(claudeHome, entry.rel);
|
|
3146
|
-
const stat =
|
|
3146
|
+
const stat = fs16.lstat(absolute);
|
|
3147
3147
|
if (stat === void 0) {
|
|
3148
3148
|
continue;
|
|
3149
3149
|
}
|
|
3150
3150
|
if (stat.kind === "file") {
|
|
3151
|
-
const contentHash =
|
|
3151
|
+
const contentHash = fs16.hashFile(absolute);
|
|
3152
3152
|
out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
|
|
3153
3153
|
continue;
|
|
3154
3154
|
}
|
|
@@ -3986,9 +3986,9 @@ var init_providerCatalogue = __esm({
|
|
|
3986
3986
|
});
|
|
3987
3987
|
|
|
3988
3988
|
// src/frontdoor/state.ts
|
|
3989
|
-
function readCatalogueStatus(
|
|
3989
|
+
function readCatalogueStatus(fs16, paths, pid, generation, name) {
|
|
3990
3990
|
const file = import_node_path10.default.join(import_node_path10.default.dirname(catalogueCachePath(paths, name, pid, generation)), `${name}.status.json`);
|
|
3991
|
-
const raw =
|
|
3991
|
+
const raw = fs16.readFileUtf8(file);
|
|
3992
3992
|
if (raw === void 0) return void 0;
|
|
3993
3993
|
try {
|
|
3994
3994
|
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 +3997,14 @@ function readCatalogueStatus(fs15, paths, pid, generation, name) {
|
|
|
3997
3997
|
return void 0;
|
|
3998
3998
|
}
|
|
3999
3999
|
}
|
|
4000
|
-
function writeFrontDoorCodexHome(
|
|
4000
|
+
function writeFrontDoorCodexHome(fs16, frontdoorDir, pid, codexHome, generation) {
|
|
4001
4001
|
const directory = import_node_path10.default.join(frontdoorDir, "codex-homes");
|
|
4002
|
-
|
|
4003
|
-
|
|
4002
|
+
fs16.mkdirp(directory);
|
|
4003
|
+
fs16.writeFilePrivate(import_node_path10.default.join(directory, `${String(pid)}.json`), `${JSON.stringify({ codexHome, generation })}
|
|
4004
4004
|
`);
|
|
4005
4005
|
}
|
|
4006
|
-
function readFrontDoorCodexRecord(
|
|
4007
|
-
const raw =
|
|
4006
|
+
function readFrontDoorCodexRecord(fs16, frontdoorDir, pid) {
|
|
4007
|
+
const raw = fs16.readFileUtf8(import_node_path10.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
4008
4008
|
if (raw === void 0) return void 0;
|
|
4009
4009
|
try {
|
|
4010
4010
|
const parsed = import_zod6.z.strictObject({ codexHome: import_zod6.z.string().min(1), generation: import_zod6.z.uuid() }).safeParse(JSON.parse(raw));
|
|
@@ -4013,13 +4013,13 @@ function readFrontDoorCodexRecord(fs15, frontdoorDir, pid) {
|
|
|
4013
4013
|
return void 0;
|
|
4014
4014
|
}
|
|
4015
4015
|
}
|
|
4016
|
-
function removeFrontDoorCodexHome(
|
|
4017
|
-
|
|
4016
|
+
function removeFrontDoorCodexHome(fs16, frontdoorDir, pid) {
|
|
4017
|
+
fs16.removeRecursive(import_node_path10.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
4018
4018
|
}
|
|
4019
|
-
function readFrontDoorState(
|
|
4019
|
+
function readFrontDoorState(fs16, stateFile) {
|
|
4020
4020
|
let raw;
|
|
4021
4021
|
try {
|
|
4022
|
-
raw =
|
|
4022
|
+
raw = fs16.readFileUtf8(stateFile);
|
|
4023
4023
|
} catch {
|
|
4024
4024
|
return void 0;
|
|
4025
4025
|
}
|
|
@@ -4033,9 +4033,9 @@ function readFrontDoorState(fs15, stateFile) {
|
|
|
4033
4033
|
return void 0;
|
|
4034
4034
|
}
|
|
4035
4035
|
}
|
|
4036
|
-
function writeFrontDoorState(
|
|
4037
|
-
|
|
4038
|
-
|
|
4036
|
+
function writeFrontDoorState(fs16, stateFile, state) {
|
|
4037
|
+
fs16.mkdirp(import_node_path10.default.dirname(stateFile));
|
|
4038
|
+
fs16.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
4039
4039
|
`);
|
|
4040
4040
|
}
|
|
4041
4041
|
function directOrigin(port) {
|
|
@@ -4045,37 +4045,37 @@ function frontDoorOrigin(state) {
|
|
|
4045
4045
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
4046
4046
|
return port === void 0 ? void 0 : directOrigin(port);
|
|
4047
4047
|
}
|
|
4048
|
-
function writeFrontDoorDirectRecord(
|
|
4049
|
-
|
|
4050
|
-
|
|
4048
|
+
function writeFrontDoorDirectRecord(fs16, recordsDir, record) {
|
|
4049
|
+
fs16.mkdirp(recordsDir);
|
|
4050
|
+
fs16.writeFilePrivate(import_node_path10.default.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
|
|
4051
4051
|
`);
|
|
4052
4052
|
}
|
|
4053
|
-
function removeFrontDoorDirectRecord(
|
|
4054
|
-
|
|
4053
|
+
function removeFrontDoorDirectRecord(fs16, recordsDir, pid) {
|
|
4054
|
+
fs16.removeRecursive(import_node_path10.default.join(recordsDir, `${String(pid)}.json`));
|
|
4055
4055
|
}
|
|
4056
|
-
function markFrontDoorDraining(
|
|
4057
|
-
|
|
4058
|
-
|
|
4056
|
+
function markFrontDoorDraining(fs16, markersDir, pid) {
|
|
4057
|
+
fs16.mkdirp(markersDir);
|
|
4058
|
+
fs16.writeFilePrivate(import_node_path10.default.join(markersDir, String(pid)), "\n");
|
|
4059
4059
|
}
|
|
4060
|
-
function unmarkFrontDoorDraining(
|
|
4061
|
-
|
|
4060
|
+
function unmarkFrontDoorDraining(fs16, markersDir, pid) {
|
|
4061
|
+
fs16.removeRecursive(import_node_path10.default.join(markersDir, String(pid)));
|
|
4062
4062
|
}
|
|
4063
|
-
function listDrainingFrontDoors(
|
|
4064
|
-
return
|
|
4063
|
+
function listDrainingFrontDoors(fs16, markersDir, isRunning) {
|
|
4064
|
+
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
4065
|
}
|
|
4066
4066
|
function recordPid(file) {
|
|
4067
4067
|
const pidText = /^([1-9]\d*)\.json$/.exec(file)?.[1];
|
|
4068
4068
|
const pid = pidText === void 0 ? void 0 : Number(pidText);
|
|
4069
4069
|
return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
|
|
4070
4070
|
}
|
|
4071
|
-
function readDirectRecordEntry(
|
|
4071
|
+
function readDirectRecordEntry(fs16, recordsDir, file) {
|
|
4072
4072
|
const pid = recordPid(file);
|
|
4073
4073
|
if (pid === void 0) {
|
|
4074
4074
|
return void 0;
|
|
4075
4075
|
}
|
|
4076
4076
|
let raw;
|
|
4077
4077
|
try {
|
|
4078
|
-
raw =
|
|
4078
|
+
raw = fs16.readFileUtf8(import_node_path10.default.join(recordsDir, file));
|
|
4079
4079
|
} catch {
|
|
4080
4080
|
return void 0;
|
|
4081
4081
|
}
|
|
@@ -4089,37 +4089,37 @@ function readDirectRecordEntry(fs15, recordsDir, file) {
|
|
|
4089
4089
|
return { malformed: true };
|
|
4090
4090
|
}
|
|
4091
4091
|
}
|
|
4092
|
-
function listFrontDoorDirectRecords(
|
|
4093
|
-
return
|
|
4094
|
-
const entry = readDirectRecordEntry(
|
|
4092
|
+
function listFrontDoorDirectRecords(fs16, recordsDir) {
|
|
4093
|
+
return fs16.readdir(recordsDir).flatMap((file) => {
|
|
4094
|
+
const entry = readDirectRecordEntry(fs16, recordsDir, file);
|
|
4095
4095
|
return entry?.record === void 0 ? [] : [entry.record];
|
|
4096
4096
|
}).sort((a, b) => a.pid - b.pid);
|
|
4097
4097
|
}
|
|
4098
|
-
function pruneMalformedFrontDoorDirectFiles(
|
|
4099
|
-
for (const file of
|
|
4098
|
+
function pruneMalformedFrontDoorDirectFiles(fs16, recordsDir, isRunning) {
|
|
4099
|
+
for (const file of fs16.readdir(recordsDir)) {
|
|
4100
4100
|
const writer = RECORD_TEMPORARY_FILE.exec(file)?.[1];
|
|
4101
4101
|
const stale = writer !== void 0 && !isRunning(Number(writer));
|
|
4102
|
-
if (stale || readDirectRecordEntry(
|
|
4103
|
-
|
|
4102
|
+
if (stale || readDirectRecordEntry(fs16, recordsDir, file)?.malformed === true) {
|
|
4103
|
+
fs16.removeRecursive(import_node_path10.default.join(recordsDir, file));
|
|
4104
4104
|
}
|
|
4105
4105
|
}
|
|
4106
4106
|
}
|
|
4107
4107
|
function liveFrontDoorDirectRecords(records, liveness) {
|
|
4108
4108
|
return records.filter((record) => liveness.doors.has(record.pid) || liveness.unknown.has(record.pid));
|
|
4109
4109
|
}
|
|
4110
|
-
function pruneDeadFrontDoorDirectRecords(
|
|
4110
|
+
function pruneDeadFrontDoorDirectRecords(fs16, recordsDir, records, liveness) {
|
|
4111
4111
|
for (const record of records) {
|
|
4112
4112
|
if (!liveness.doors.has(record.pid) && !liveness.unknown.has(record.pid)) {
|
|
4113
|
-
removeFrontDoorDirectRecord(
|
|
4113
|
+
removeFrontDoorDirectRecord(fs16, recordsDir, record.pid);
|
|
4114
4114
|
}
|
|
4115
4115
|
}
|
|
4116
4116
|
}
|
|
4117
4117
|
function recordOf(details) {
|
|
4118
4118
|
return details === void 0 ? {} : { sessionId: details.sessionId, ...details.models === void 0 ? {} : { models: details.models } };
|
|
4119
4119
|
}
|
|
4120
|
-
function writeFrontDoorSession(
|
|
4121
|
-
|
|
4122
|
-
|
|
4120
|
+
function writeFrontDoorSession(fs16, sessionsDir, session) {
|
|
4121
|
+
fs16.mkdirPrivate(sessionsDir);
|
|
4122
|
+
fs16.writeFilePrivate(import_node_path10.default.join(sessionsDir, sessionRecordName(session.pid)), `${JSON.stringify(session, null, 2)}
|
|
4123
4123
|
`);
|
|
4124
4124
|
}
|
|
4125
4125
|
function sessionRecordName(pid) {
|
|
@@ -4131,32 +4131,32 @@ function isSessionRecordName(name) {
|
|
|
4131
4131
|
function summaryOf(session) {
|
|
4132
4132
|
return { pid: session.pid, startedAt: session.startedAt, ...session.supervisorPid === void 0 ? {} : { supervisorPid: session.supervisorPid } };
|
|
4133
4133
|
}
|
|
4134
|
-
function readFrontDoorSessionRecord(
|
|
4134
|
+
function readFrontDoorSessionRecord(fs16, sessionsDir, name) {
|
|
4135
4135
|
try {
|
|
4136
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
4136
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs16.readFileUtf8(import_node_path10.default.join(sessionsDir, name)) ?? ""));
|
|
4137
4137
|
return parsed.success ? parsed.data : void 0;
|
|
4138
4138
|
} catch {
|
|
4139
4139
|
return void 0;
|
|
4140
4140
|
}
|
|
4141
4141
|
}
|
|
4142
|
-
function listFrontDoorSessions(
|
|
4142
|
+
function listFrontDoorSessions(fs16, sessionsDir) {
|
|
4143
4143
|
const sessions = [];
|
|
4144
|
-
for (const name of
|
|
4145
|
-
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(
|
|
4144
|
+
for (const name of fs16.readdir(sessionsDir)) {
|
|
4145
|
+
const record = isSessionRecordName(name) ? readFrontDoorSessionRecord(fs16, sessionsDir, name) : void 0;
|
|
4146
4146
|
if (record !== void 0) {
|
|
4147
4147
|
sessions.push(summaryOf(record));
|
|
4148
4148
|
}
|
|
4149
4149
|
}
|
|
4150
4150
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
4151
4151
|
}
|
|
4152
|
-
function removeFrontDoorSession(
|
|
4153
|
-
|
|
4152
|
+
function removeFrontDoorSession(fs16, sessionsDir, pid) {
|
|
4153
|
+
fs16.removeRecursive(import_node_path10.default.join(sessionsDir, sessionRecordName(pid)));
|
|
4154
4154
|
}
|
|
4155
|
-
function pruneDeadFrontDoorSessions(
|
|
4155
|
+
function pruneDeadFrontDoorSessions(fs16, sessionsDir, listed, isRunning) {
|
|
4156
4156
|
const removed = [];
|
|
4157
4157
|
for (const session of listed) {
|
|
4158
4158
|
if (!isRunning(session.pid)) {
|
|
4159
|
-
removeFrontDoorSession(
|
|
4159
|
+
removeFrontDoorSession(fs16, sessionsDir, session.pid);
|
|
4160
4160
|
removed.push(session.pid);
|
|
4161
4161
|
}
|
|
4162
4162
|
}
|
|
@@ -4239,19 +4239,19 @@ var init_processRole = __esm({
|
|
|
4239
4239
|
});
|
|
4240
4240
|
|
|
4241
4241
|
// src/frontdoor/catalogueCleanup.ts
|
|
4242
|
-
async function pruneAbandonedCatalogueGenerations(
|
|
4242
|
+
async function pruneAbandonedCatalogueGenerations(fs16, paths, ownPid, generation, runningAmong) {
|
|
4243
4243
|
const root = import_node_path11.default.join(paths.catalogueDir, "supervisors");
|
|
4244
|
-
const owners =
|
|
4244
|
+
const owners = fs16.readdir(root).flatMap((entry) => {
|
|
4245
4245
|
const pid = Number(entry);
|
|
4246
|
-
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry &&
|
|
4246
|
+
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry && fs16.lstat(import_node_path11.default.join(root, entry))?.kind === "dir" ? [pid] : [];
|
|
4247
4247
|
});
|
|
4248
4248
|
const running = await runningAmong(owners);
|
|
4249
4249
|
for (const pid of owners) {
|
|
4250
4250
|
if (pid !== ownPid && running.has(pid)) continue;
|
|
4251
4251
|
const directory = import_node_path11.default.join(root, String(pid));
|
|
4252
|
-
for (const entry of
|
|
4252
|
+
for (const entry of fs16.readdir(directory)) {
|
|
4253
4253
|
const candidate = import_node_path11.default.join(directory, entry);
|
|
4254
|
-
if (import_zod7.z.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) &&
|
|
4254
|
+
if (import_zod7.z.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) && fs16.lstat(candidate)?.kind === "dir") fs16.removeRecursive(candidate);
|
|
4255
4255
|
}
|
|
4256
4256
|
}
|
|
4257
4257
|
}
|
|
@@ -4282,9 +4282,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
4282
4282
|
}
|
|
4283
4283
|
}
|
|
4284
4284
|
async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
4285
|
-
const { fs:
|
|
4285
|
+
const { fs: fs16, paths } = ports;
|
|
4286
4286
|
const servingBinary = ports.statOwnExecutable();
|
|
4287
|
-
const previous = readFrontDoorState(
|
|
4287
|
+
const previous = readFrontDoorState(fs16, paths.frontdoorStateFile);
|
|
4288
4288
|
let lastPort = previous?.lastPort;
|
|
4289
4289
|
let lastConnectPort = previous?.lastConnectPort;
|
|
4290
4290
|
let lastDirectPort = previous?.lastDirectPort;
|
|
@@ -4298,8 +4298,8 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4298
4298
|
const fail = async (message) => {
|
|
4299
4299
|
ports.closeRcStreamHub();
|
|
4300
4300
|
if (predecessor === void 0) {
|
|
4301
|
-
writeFrontDoorState(
|
|
4302
|
-
|
|
4301
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { lastError: message, ...sticky() });
|
|
4302
|
+
fs16.removeRecursive(paths.frontdoorLockFile);
|
|
4303
4303
|
}
|
|
4304
4304
|
ports.log(`agent-shim frontdoor supervisor: ${message}`);
|
|
4305
4305
|
const chain = ports.respawnChain;
|
|
@@ -4310,7 +4310,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4310
4310
|
return 1;
|
|
4311
4311
|
};
|
|
4312
4312
|
if (predecessor === void 0) {
|
|
4313
|
-
writeFrontDoorState(
|
|
4313
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
|
|
4314
4314
|
}
|
|
4315
4315
|
const previousSticky = lastPort;
|
|
4316
4316
|
let http3;
|
|
@@ -4351,14 +4351,14 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4351
4351
|
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
4352
|
}
|
|
4353
4353
|
lastDirectPort = direct.port;
|
|
4354
|
-
writeFrontDoorDirectRecord(
|
|
4355
|
-
writeFrontDoorCodexHome(
|
|
4356
|
-
writeFrontDoorState(
|
|
4357
|
-
await pruneAbandonedCatalogueGenerations(
|
|
4354
|
+
writeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
|
|
4355
|
+
writeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid, ports.codexHome, ports.catalogueGeneration);
|
|
4356
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http3.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
|
|
4357
|
+
await pruneAbandonedCatalogueGenerations(fs16, paths, ports.ownPid, ports.catalogueGeneration, ports.runningAmong);
|
|
4358
4358
|
ports.onServing();
|
|
4359
4359
|
ports.doorHealth.generation({ providerPort: http3.port, connectPort: connect3.port, directPort: direct.port });
|
|
4360
4360
|
if (predecessor === void 0) {
|
|
4361
|
-
|
|
4361
|
+
fs16.removeRecursive(paths.frontdoorLockFile);
|
|
4362
4362
|
} else {
|
|
4363
4363
|
predecessor.serving();
|
|
4364
4364
|
}
|
|
@@ -4367,7 +4367,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4367
4367
|
let idleSince;
|
|
4368
4368
|
let ticks = 0;
|
|
4369
4369
|
const supersedingOwner = async () => {
|
|
4370
|
-
const owner = readFrontDoorState(
|
|
4370
|
+
const owner = readFrontDoorState(fs16, paths.frontdoorStateFile)?.supervisorPid;
|
|
4371
4371
|
return owner !== void 0 && owner !== ports.ownPid && (await ports.runningAmong([owner])).has(owner) ? owner : void 0;
|
|
4372
4372
|
};
|
|
4373
4373
|
let supersededBy;
|
|
@@ -4396,15 +4396,15 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4396
4396
|
ports.stopBackgroundWork?.();
|
|
4397
4397
|
const drained = [direct.drain(), connect3.drain(), http3.drain()];
|
|
4398
4398
|
if (await supersedingOwner() === void 0) {
|
|
4399
|
-
writeFrontDoorState(
|
|
4399
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, sticky());
|
|
4400
4400
|
}
|
|
4401
|
-
markFrontDoorDraining(
|
|
4401
|
+
markFrontDoorDraining(fs16, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4402
4402
|
ports.closeRcStreamHub();
|
|
4403
4403
|
await Promise.all(drained);
|
|
4404
|
-
unmarkFrontDoorDraining(
|
|
4405
|
-
removeFrontDoorDirectRecord(
|
|
4406
|
-
removeFrontDoorCodexHome(
|
|
4407
|
-
|
|
4404
|
+
unmarkFrontDoorDraining(fs16, paths.frontdoorDrainingDir, ports.ownPid);
|
|
4405
|
+
removeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4406
|
+
removeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid);
|
|
4407
|
+
fs16.removeRecursive(catalogueGenerationDir(paths, ports.ownPid, ports.catalogueGeneration));
|
|
4408
4408
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: the connections this door carried have ended; exiting`);
|
|
4409
4409
|
return 0;
|
|
4410
4410
|
};
|
|
@@ -4425,14 +4425,14 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4425
4425
|
await connect3.close();
|
|
4426
4426
|
await http3.close();
|
|
4427
4427
|
ports.closeRcStreamHub();
|
|
4428
|
-
removeFrontDoorDirectRecord(
|
|
4429
|
-
removeFrontDoorCodexHome(
|
|
4430
|
-
|
|
4428
|
+
removeFrontDoorDirectRecord(fs16, paths.frontdoorDirectRecordsDir, ports.ownPid);
|
|
4429
|
+
removeFrontDoorCodexHome(fs16, paths.frontdoorDir, ports.ownPid);
|
|
4430
|
+
fs16.removeRecursive(catalogueGenerationDir(paths, ports.ownPid, ports.catalogueGeneration));
|
|
4431
4431
|
};
|
|
4432
4432
|
const shutdown = async () => {
|
|
4433
4433
|
await closeServing();
|
|
4434
4434
|
if (await supersedingOwner() === void 0) {
|
|
4435
|
-
writeFrontDoorState(
|
|
4435
|
+
writeFrontDoorState(fs16, paths.frontdoorStateFile, sticky());
|
|
4436
4436
|
}
|
|
4437
4437
|
return 0;
|
|
4438
4438
|
};
|
|
@@ -4451,7 +4451,7 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
|
|
|
4451
4451
|
ticks += 1;
|
|
4452
4452
|
const listed = ports.registry.rescan();
|
|
4453
4453
|
const running = await ports.runningAmong(listed.map((session) => session.pid));
|
|
4454
|
-
const pruned = pruneDeadFrontDoorSessions(
|
|
4454
|
+
const pruned = pruneDeadFrontDoorSessions(fs16, paths.frontdoorSessionsDir, listed, (pid) => running.has(pid));
|
|
4455
4455
|
ports.registry.forget(pruned);
|
|
4456
4456
|
ports.observeLaunchRegistry(listed, pruned);
|
|
4457
4457
|
ports.checkQuotaExpiry();
|
|
@@ -4527,8 +4527,8 @@ function parseConnectTarget(authority) {
|
|
|
4527
4527
|
function isInterceptedHost(host, interceptHosts) {
|
|
4528
4528
|
return interceptHosts.includes(host);
|
|
4529
4529
|
}
|
|
4530
|
-
function servedByPipeline(
|
|
4531
|
-
return
|
|
4530
|
+
function servedByPipeline(path49) {
|
|
4531
|
+
return path49?.startsWith(ROUTED_PATH_PREFIX) === true;
|
|
4532
4532
|
}
|
|
4533
4533
|
function forwardableHeaders(headers) {
|
|
4534
4534
|
const connectionTokens = new Set(
|
|
@@ -4974,7 +4974,7 @@ var init_package = __esm({
|
|
|
4974
4974
|
"package.json"() {
|
|
4975
4975
|
package_default = {
|
|
4976
4976
|
name: "agent-shim",
|
|
4977
|
-
version: "11.84.
|
|
4977
|
+
version: "11.84.1",
|
|
4978
4978
|
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
4979
|
license: "MIT",
|
|
4980
4980
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -5196,43 +5196,43 @@ function parseJson(raw, schema) {
|
|
|
5196
5196
|
const parsed = schema.safeParse(JSON.parse(raw));
|
|
5197
5197
|
return parsed.success ? parsed.data : void 0;
|
|
5198
5198
|
}
|
|
5199
|
-
function readHeadroomState(
|
|
5199
|
+
function readHeadroomState(fs16, stateFile) {
|
|
5200
5200
|
try {
|
|
5201
|
-
return parseJson(
|
|
5201
|
+
return parseJson(fs16.readFileUtf8(stateFile), HeadroomStateSchema);
|
|
5202
5202
|
} catch {
|
|
5203
5203
|
return void 0;
|
|
5204
5204
|
}
|
|
5205
5205
|
}
|
|
5206
|
-
function writeHeadroomState(
|
|
5207
|
-
|
|
5208
|
-
|
|
5206
|
+
function writeHeadroomState(fs16, stateFile, state) {
|
|
5207
|
+
fs16.mkdirp(import_node_path14.default.dirname(stateFile));
|
|
5208
|
+
fs16.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
5209
5209
|
`);
|
|
5210
5210
|
}
|
|
5211
|
-
function resolveServingHeadroomState(
|
|
5212
|
-
const current = readHeadroomState(
|
|
5211
|
+
function resolveServingHeadroomState(fs16, files, isRunning) {
|
|
5212
|
+
const current = readHeadroomState(fs16, files.stateFile);
|
|
5213
5213
|
if (current !== void 0) {
|
|
5214
5214
|
return { path: files.stateFile, state: current };
|
|
5215
5215
|
}
|
|
5216
|
-
const legacy = readHeadroomState(
|
|
5216
|
+
const legacy = readHeadroomState(fs16, files.legacyStateFile);
|
|
5217
5217
|
if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
|
|
5218
5218
|
return { path: files.legacyStateFile, state: legacy };
|
|
5219
5219
|
}
|
|
5220
5220
|
return void 0;
|
|
5221
5221
|
}
|
|
5222
|
-
function migrateHeadroomState(
|
|
5223
|
-
const legacy = readHeadroomState(
|
|
5222
|
+
function migrateHeadroomState(fs16, files, isRunning) {
|
|
5223
|
+
const legacy = readHeadroomState(fs16, files.legacyStateFile);
|
|
5224
5224
|
const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
|
|
5225
|
-
const current = readHeadroomState(
|
|
5225
|
+
const current = readHeadroomState(fs16, files.stateFile);
|
|
5226
5226
|
if (current !== void 0 || legacyLive) {
|
|
5227
|
-
if (!legacyLive &&
|
|
5228
|
-
|
|
5227
|
+
if (!legacyLive && fs16.readFileUtf8(files.legacyStateFile) !== void 0) {
|
|
5228
|
+
fs16.removeRecursive(files.legacyStateFile);
|
|
5229
5229
|
}
|
|
5230
5230
|
return;
|
|
5231
5231
|
}
|
|
5232
5232
|
if (legacy !== void 0) {
|
|
5233
|
-
writeHeadroomState(
|
|
5233
|
+
writeHeadroomState(fs16, files.stateFile, legacy);
|
|
5234
5234
|
}
|
|
5235
|
-
|
|
5235
|
+
fs16.removeRecursive(files.legacyStateFile);
|
|
5236
5236
|
}
|
|
5237
5237
|
function hashAllowlist(allowlist) {
|
|
5238
5238
|
return (0, import_node_crypto6.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
@@ -5265,27 +5265,27 @@ function isAdmissibleUrl(entry) {
|
|
|
5265
5265
|
function parseAllowlistFile(content) {
|
|
5266
5266
|
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
5267
|
}
|
|
5268
|
-
function writeAllowlistFile(
|
|
5269
|
-
|
|
5270
|
-
|
|
5268
|
+
function writeAllowlistFile(fs16, allowlistFile, allowlist) {
|
|
5269
|
+
fs16.mkdirPrivate(import_node_path14.default.dirname(allowlistFile));
|
|
5270
|
+
fs16.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
|
|
5271
5271
|
}
|
|
5272
|
-
function pruneStaleAllowlistTemporaries(
|
|
5272
|
+
function pruneStaleAllowlistTemporaries(fs16, allowlistFile, isRunning) {
|
|
5273
5273
|
const prefix = `${import_node_path14.default.basename(allowlistFile)}.`;
|
|
5274
|
-
for (const name of
|
|
5274
|
+
for (const name of fs16.readdir(import_node_path14.default.dirname(allowlistFile))) {
|
|
5275
5275
|
const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
|
|
5276
5276
|
if (writer !== void 0 && !isRunning(Number(writer))) {
|
|
5277
|
-
|
|
5277
|
+
fs16.removeRecursive(import_node_path14.default.join(import_node_path14.default.dirname(allowlistFile), name));
|
|
5278
5278
|
}
|
|
5279
5279
|
}
|
|
5280
5280
|
}
|
|
5281
|
-
function readAllProviders(
|
|
5281
|
+
function readAllProviders(fs16, providersDir) {
|
|
5282
5282
|
const result = [];
|
|
5283
|
-
for (const name of
|
|
5283
|
+
for (const name of fs16.readdir(providersDir)) {
|
|
5284
5284
|
if (!name.endsWith(".json")) {
|
|
5285
5285
|
continue;
|
|
5286
5286
|
}
|
|
5287
5287
|
try {
|
|
5288
|
-
const parsed = parseJson(
|
|
5288
|
+
const parsed = parseJson(fs16.readFileUtf8(import_node_path14.default.join(providersDir, name)), ProviderSchema);
|
|
5289
5289
|
if (parsed !== void 0) {
|
|
5290
5290
|
result.push({ name: name.slice(0, -".json".length), provider: parsed });
|
|
5291
5291
|
}
|
|
@@ -5295,22 +5295,22 @@ function readAllProviders(fs15, providersDir) {
|
|
|
5295
5295
|
}
|
|
5296
5296
|
return result;
|
|
5297
5297
|
}
|
|
5298
|
-
function writeSession(
|
|
5299
|
-
|
|
5300
|
-
|
|
5298
|
+
function writeSession(fs16, sessionsDir, session) {
|
|
5299
|
+
fs16.mkdirp(sessionsDir);
|
|
5300
|
+
fs16.writeFileUtf8(import_node_path14.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
5301
5301
|
`);
|
|
5302
5302
|
}
|
|
5303
|
-
function removeSession(
|
|
5304
|
-
|
|
5303
|
+
function removeSession(fs16, sessionsDir, pid) {
|
|
5304
|
+
fs16.removeRecursive(import_node_path14.default.join(sessionsDir, `${String(pid)}.json`));
|
|
5305
5305
|
}
|
|
5306
|
-
function listSessions(
|
|
5306
|
+
function listSessions(fs16, sessionsDir) {
|
|
5307
5307
|
const sessions = [];
|
|
5308
|
-
for (const name of
|
|
5308
|
+
for (const name of fs16.readdir(sessionsDir)) {
|
|
5309
5309
|
if (!name.endsWith(".json")) {
|
|
5310
5310
|
continue;
|
|
5311
5311
|
}
|
|
5312
5312
|
try {
|
|
5313
|
-
const parsed = parseJson(
|
|
5313
|
+
const parsed = parseJson(fs16.readFileUtf8(import_node_path14.default.join(sessionsDir, name)), HeadroomSessionSchema);
|
|
5314
5314
|
if (parsed !== void 0) {
|
|
5315
5315
|
sessions.push(parsed);
|
|
5316
5316
|
}
|
|
@@ -5320,22 +5320,22 @@ function listSessions(fs15, sessionsDir) {
|
|
|
5320
5320
|
}
|
|
5321
5321
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
5322
5322
|
}
|
|
5323
|
-
function sessionsForSupervisor(
|
|
5324
|
-
return listSessions(
|
|
5323
|
+
function sessionsForSupervisor(fs16, sessionsDir, supervisorPid) {
|
|
5324
|
+
return listSessions(fs16, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
|
|
5325
5325
|
}
|
|
5326
|
-
function pruneDeadSessions(
|
|
5326
|
+
function pruneDeadSessions(fs16, sessionsDir, isRunning) {
|
|
5327
5327
|
const removed = [];
|
|
5328
|
-
for (const session of listSessions(
|
|
5328
|
+
for (const session of listSessions(fs16, sessionsDir)) {
|
|
5329
5329
|
if (!isRunning(session.pid)) {
|
|
5330
|
-
removeSession(
|
|
5330
|
+
removeSession(fs16, sessionsDir, session.pid);
|
|
5331
5331
|
removed.push(session.pid);
|
|
5332
5332
|
}
|
|
5333
5333
|
}
|
|
5334
5334
|
return removed;
|
|
5335
5335
|
}
|
|
5336
|
-
function readStartLock(
|
|
5336
|
+
function readStartLock(fs16, lockFile) {
|
|
5337
5337
|
try {
|
|
5338
|
-
return parseJson(
|
|
5338
|
+
return parseJson(fs16.readFileUtf8(lockFile), HeadroomLockSchema);
|
|
5339
5339
|
} catch {
|
|
5340
5340
|
return void 0;
|
|
5341
5341
|
}
|
|
@@ -5428,12 +5428,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
|
|
|
5428
5428
|
}
|
|
5429
5429
|
return hashAllowlist([...entries].sort());
|
|
5430
5430
|
}
|
|
5431
|
-
function earlierReleaseDaemon(
|
|
5431
|
+
function earlierReleaseDaemon(fs16, paths, daemon) {
|
|
5432
5432
|
if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
|
|
5433
5433
|
return void 0;
|
|
5434
5434
|
}
|
|
5435
|
-
const providers = readAllProviders(
|
|
5436
|
-
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(
|
|
5435
|
+
const providers = readAllProviders(fs16, paths.providersDir).map((entry) => entry.provider);
|
|
5436
|
+
const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile)));
|
|
5437
5437
|
return { admitsServingDoor: daemon.recordedHash === expected };
|
|
5438
5438
|
}
|
|
5439
5439
|
var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
|
|
@@ -5458,8 +5458,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
|
|
|
5458
5458
|
}
|
|
5459
5459
|
return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
|
|
5460
5460
|
}
|
|
5461
|
-
function daemonAdmits(
|
|
5462
|
-
const content =
|
|
5461
|
+
function daemonAdmits(fs16, allowlistFile, recordedHash, required) {
|
|
5462
|
+
const content = fs16.readFileUtf8(allowlistFile);
|
|
5463
5463
|
if (content === void 0 || recordedHash === void 0) {
|
|
5464
5464
|
return false;
|
|
5465
5465
|
}
|
|
@@ -5728,7 +5728,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
|
|
|
5728
5728
|
const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
|
|
5729
5729
|
return { message: refusal2, repairable: replaceable };
|
|
5730
5730
|
}
|
|
5731
|
-
function prepareHeadroomSocket(
|
|
5731
|
+
function prepareHeadroomSocket(fs16, ports, paths, supervisorPid) {
|
|
5732
5732
|
const unsupported = platformRefusal(ports.platform);
|
|
5733
5733
|
if (unsupported !== void 0) {
|
|
5734
5734
|
return { refused: unsupported };
|
|
@@ -5743,18 +5743,18 @@ function prepareHeadroomSocket(fs15, ports, paths, supervisorPid) {
|
|
|
5743
5743
|
if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
|
|
5744
5744
|
return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
|
|
5745
5745
|
}
|
|
5746
|
-
|
|
5746
|
+
fs16.mkdirPrivate(paths.headroomSocketDir);
|
|
5747
5747
|
const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
|
|
5748
5748
|
return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
|
|
5749
5749
|
}
|
|
5750
|
-
function pruneStaleHeadroomSockets(
|
|
5750
|
+
function pruneStaleHeadroomSockets(fs16, paths, isRunning) {
|
|
5751
5751
|
const removed = [];
|
|
5752
|
-
for (const name of
|
|
5752
|
+
for (const name of fs16.readdir(paths.headroomSocketDir)) {
|
|
5753
5753
|
const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
|
|
5754
5754
|
if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
|
|
5755
5755
|
continue;
|
|
5756
5756
|
}
|
|
5757
|
-
|
|
5757
|
+
fs16.removeRecursive(import_node_path15.default.join(paths.headroomSocketDir, name));
|
|
5758
5758
|
removed.push(name);
|
|
5759
5759
|
}
|
|
5760
5760
|
return removed;
|
|
@@ -5866,37 +5866,37 @@ function compareVersions2(a, b) {
|
|
|
5866
5866
|
return 0;
|
|
5867
5867
|
}
|
|
5868
5868
|
async function runSupervisor(initialConfig, ports, options = {}) {
|
|
5869
|
-
const { fs:
|
|
5869
|
+
const { fs: fs16, paths } = ports;
|
|
5870
5870
|
let config = initialConfig;
|
|
5871
|
-
migrateHeadroomState(
|
|
5872
|
-
const previousState = resolveServingHeadroomState(
|
|
5871
|
+
migrateHeadroomState(fs16, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
|
|
5872
|
+
const previousState = resolveServingHeadroomState(fs16, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
|
|
5873
5873
|
if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
|
|
5874
5874
|
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
|
|
5875
5875
|
return 0;
|
|
5876
5876
|
}
|
|
5877
5877
|
let installedSource = previousState?.installedSource;
|
|
5878
5878
|
const ownsState = () => {
|
|
5879
|
-
const owner = readHeadroomState(
|
|
5879
|
+
const owner = readHeadroomState(fs16, paths.headroomStateFile)?.supervisorPid;
|
|
5880
5880
|
return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
|
|
5881
5881
|
};
|
|
5882
5882
|
const writeOwnState = (state) => {
|
|
5883
5883
|
if (!ownsState()) {
|
|
5884
5884
|
return false;
|
|
5885
5885
|
}
|
|
5886
|
-
writeHeadroomState(
|
|
5886
|
+
writeHeadroomState(fs16, paths.headroomStateFile, state);
|
|
5887
5887
|
return true;
|
|
5888
5888
|
};
|
|
5889
5889
|
const fail = (message) => {
|
|
5890
5890
|
if (writeOwnState({ lastError: message })) {
|
|
5891
|
-
|
|
5891
|
+
fs16.removeRecursive(paths.headroomLockFile);
|
|
5892
5892
|
}
|
|
5893
5893
|
ports.log(`agent-shim headroom supervisor: ${message}`);
|
|
5894
5894
|
return 1;
|
|
5895
5895
|
};
|
|
5896
5896
|
const syncAllowlistFile = (allowlist) => {
|
|
5897
5897
|
try {
|
|
5898
|
-
if (
|
|
5899
|
-
writeAllowlistFile(
|
|
5898
|
+
if (fs16.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
|
|
5899
|
+
writeAllowlistFile(fs16, paths.headroomAllowlistFile, allowlist);
|
|
5900
5900
|
ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
|
|
5901
5901
|
}
|
|
5902
5902
|
return void 0;
|
|
@@ -5914,9 +5914,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5914
5914
|
}
|
|
5915
5915
|
ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
|
|
5916
5916
|
try {
|
|
5917
|
-
|
|
5918
|
-
|
|
5919
|
-
writeAllowlistFile(
|
|
5917
|
+
fs16.mkdirPrivate(paths.headroomDir);
|
|
5918
|
+
fs16.mkdirPrivate(import_node_path16.default.dirname(paths.headroomAllowlistFile));
|
|
5919
|
+
writeAllowlistFile(fs16, paths.headroomAllowlistFile, allowlist);
|
|
5920
5920
|
} catch (error) {
|
|
5921
5921
|
return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error instanceof Error ? error.message : String(error)}`;
|
|
5922
5922
|
}
|
|
@@ -5941,20 +5941,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5941
5941
|
installedSource = config.source;
|
|
5942
5942
|
return void 0;
|
|
5943
5943
|
};
|
|
5944
|
-
const socket = prepareHeadroomSocket(
|
|
5944
|
+
const socket = prepareHeadroomSocket(fs16, ports.socketTrust, paths, ports.ownPid);
|
|
5945
5945
|
if (socket.refused !== void 0) {
|
|
5946
5946
|
return fail(socket.refused);
|
|
5947
5947
|
}
|
|
5948
5948
|
const { socketPath } = socket;
|
|
5949
|
-
pruneStaleHeadroomSockets(
|
|
5950
|
-
pruneStaleAllowlistTemporaries(
|
|
5949
|
+
pruneStaleHeadroomSockets(fs16, paths, ports.isRunning);
|
|
5950
|
+
pruneStaleAllowlistTemporaries(fs16, paths.headroomAllowlistFile, ports.isRunning);
|
|
5951
5951
|
const installFailure = ensureInstalled();
|
|
5952
5952
|
if (installFailure !== void 0) {
|
|
5953
5953
|
return fail(installFailure);
|
|
5954
5954
|
}
|
|
5955
5955
|
const version = ports.headroomVersion() ?? "unknown";
|
|
5956
5956
|
writeOwnState({ supervisorPid: ports.ownPid, version, installedSource });
|
|
5957
|
-
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(
|
|
5957
|
+
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs16, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
|
|
5958
5958
|
const orphanPid = previousState?.headroomPid;
|
|
5959
5959
|
const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
|
|
5960
5960
|
const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
|
|
@@ -5992,12 +5992,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
5992
5992
|
}
|
|
5993
5993
|
config = ports.readConfig();
|
|
5994
5994
|
const settingsHash = hashSettings(config.settings);
|
|
5995
|
-
const inputs = currentHeadroomAllowlistInputs(
|
|
5996
|
-
pruneDeadFrontDoorDirectRecords(
|
|
5997
|
-
pruneMalformedFrontDoorDirectFiles(
|
|
5995
|
+
const inputs = currentHeadroomAllowlistInputs(fs16, paths, ports.frontDoorLiveness);
|
|
5996
|
+
pruneDeadFrontDoorDirectRecords(fs16, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
|
|
5997
|
+
pruneMalformedFrontDoorDirectFiles(fs16, paths.frontdoorDirectRecordsDir, ports.isRunning);
|
|
5998
5998
|
const allowlist = inputs.frontDoorOrigins;
|
|
5999
5999
|
const allowlistHash = hashAllowlist(allowlist);
|
|
6000
|
-
pruneDeadSessions(
|
|
6000
|
+
pruneDeadSessions(fs16, paths.headroomSessionsDir, ports.isRunning);
|
|
6001
6001
|
const ownsNow = ownsState();
|
|
6002
6002
|
if (!ownsNow && !superseded) {
|
|
6003
6003
|
ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
|
|
@@ -6044,7 +6044,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6044
6044
|
runningSettingsHash = settingsHash;
|
|
6045
6045
|
const recorded = writeOwnState(servingState(pid));
|
|
6046
6046
|
if (recorded) {
|
|
6047
|
-
|
|
6047
|
+
fs16.removeRecursive(paths.headroomLockFile);
|
|
6048
6048
|
}
|
|
6049
6049
|
idleSince = void 0;
|
|
6050
6050
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
|
|
@@ -6072,7 +6072,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6072
6072
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
|
|
6073
6073
|
}
|
|
6074
6074
|
if (runningSettingsHash !== settingsHash || installedSource !== config.source) {
|
|
6075
|
-
if (sessionsForSupervisor(
|
|
6075
|
+
if (sessionsForSupervisor(fs16, paths.headroomSessionsDir, ports.ownPid).length === 0) {
|
|
6076
6076
|
ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
|
|
6077
6077
|
ports.stopProcess(headroomPid);
|
|
6078
6078
|
headroomPid = void 0;
|
|
@@ -6081,7 +6081,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
6081
6081
|
continue;
|
|
6082
6082
|
}
|
|
6083
6083
|
}
|
|
6084
|
-
const sessions = sessionsForSupervisor(
|
|
6084
|
+
const sessions = sessionsForSupervisor(fs16, paths.headroomSessionsDir, ports.ownPid);
|
|
6085
6085
|
if (sessions.length === 0) {
|
|
6086
6086
|
idleSince ??= ports.now();
|
|
6087
6087
|
const idleMs = ports.now() - idleSince;
|
|
@@ -6106,9 +6106,9 @@ function undeterminedFrontDoors(inputs) {
|
|
|
6106
6106
|
return reason === void 0 ? [] : [{ pid: record.pid, origin: directOrigin(record.directPort), reason }];
|
|
6107
6107
|
});
|
|
6108
6108
|
}
|
|
6109
|
-
function currentHeadroomAllowlistInputs(
|
|
6110
|
-
const named = frontDoorOrigin(readFrontDoorState(
|
|
6111
|
-
const records = listFrontDoorDirectRecords(
|
|
6109
|
+
function currentHeadroomAllowlistInputs(fs16, paths, frontDoorLiveness) {
|
|
6110
|
+
const named = frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile));
|
|
6111
|
+
const records = listFrontDoorDirectRecords(fs16, paths.frontdoorDirectRecordsDir);
|
|
6112
6112
|
const liveness = frontDoorLiveness(records.map((record) => record.pid));
|
|
6113
6113
|
const live = liveFrontDoorDirectRecords(records, liveness).map((record) => directOrigin(record.directPort));
|
|
6114
6114
|
return {
|
|
@@ -6117,8 +6117,8 @@ function currentHeadroomAllowlistInputs(fs15, paths, frontDoorLiveness) {
|
|
|
6117
6117
|
frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
|
|
6118
6118
|
};
|
|
6119
6119
|
}
|
|
6120
|
-
function launchRequiredUpstreams(
|
|
6121
|
-
const door = frontDoorOrigin(readFrontDoorState(
|
|
6120
|
+
function launchRequiredUpstreams(fs16, paths) {
|
|
6121
|
+
const door = frontDoorOrigin(readFrontDoorState(fs16, paths.frontdoorStateFile));
|
|
6122
6122
|
return door === void 0 ? [] : [door];
|
|
6123
6123
|
}
|
|
6124
6124
|
async function waitUntilReady(ports, socketPath, pid) {
|
|
@@ -6909,8 +6909,8 @@ var init_cascade = __esm({
|
|
|
6909
6909
|
function poolNameOf(selector) {
|
|
6910
6910
|
return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
|
|
6911
6911
|
}
|
|
6912
|
-
function readActiveIdentity(
|
|
6913
|
-
const trimmed =
|
|
6912
|
+
function readActiveIdentity(fs16, activeIdentityFile) {
|
|
6913
|
+
const trimmed = fs16.readFileUtf8(activeIdentityFile)?.trim();
|
|
6914
6914
|
return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
|
|
6915
6915
|
}
|
|
6916
6916
|
function isNonEmpty(value) {
|
|
@@ -6960,11 +6960,11 @@ function decideConfigProfile(params) {
|
|
|
6960
6960
|
}
|
|
6961
6961
|
return { source: "none" };
|
|
6962
6962
|
}
|
|
6963
|
-
function loadIdentity(identitiesDir, name,
|
|
6963
|
+
function loadIdentity(identitiesDir, name, fs16) {
|
|
6964
6964
|
if (!isFileName(name)) {
|
|
6965
6965
|
throw new UnsafeNameError(name, "identity", FILE_NAME_RULE);
|
|
6966
6966
|
}
|
|
6967
|
-
return loadConfigFile(import_node_path20.default.join(identitiesDir, name, "identity.json"), IdentitySchema,
|
|
6967
|
+
return loadConfigFile(import_node_path20.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs16.readConfigFile);
|
|
6968
6968
|
}
|
|
6969
6969
|
var import_node_path20, IDENTITY_DECISION_SOURCES, IDENTITY_SOURCE_LABELS, CONFIG_PROFILE_DECISION_SOURCES;
|
|
6970
6970
|
var init_identity = __esm({
|
|
@@ -7218,14 +7218,14 @@ function isIdentityName(name) {
|
|
|
7218
7218
|
function claudeJsonPath(identitiesDir, identity) {
|
|
7219
7219
|
return import_node_path21.default.join(identitiesDir, identity, CLAUDE_JSON);
|
|
7220
7220
|
}
|
|
7221
|
-
function readAccountMetadata(
|
|
7221
|
+
function readAccountMetadata(fs16, identitiesDir, identity) {
|
|
7222
7222
|
if (!isIdentityName(identity)) {
|
|
7223
7223
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
7224
7224
|
}
|
|
7225
|
-
return readAccountMetadataFile(
|
|
7225
|
+
return readAccountMetadataFile(fs16, claudeJsonPath(identitiesDir, identity));
|
|
7226
7226
|
}
|
|
7227
|
-
function readAccountMetadataFile(
|
|
7228
|
-
const raw =
|
|
7227
|
+
function readAccountMetadataFile(fs16, file) {
|
|
7228
|
+
const raw = fs16.readFileUtf8(file);
|
|
7229
7229
|
if (raw === void 0) {
|
|
7230
7230
|
return void 0;
|
|
7231
7231
|
}
|
|
@@ -7255,19 +7255,19 @@ function readAccountMetadataFile(fs15, file) {
|
|
|
7255
7255
|
}
|
|
7256
7256
|
return account.data;
|
|
7257
7257
|
}
|
|
7258
|
-
function createAccountReader(
|
|
7258
|
+
function createAccountReader(fs16, identitiesDir) {
|
|
7259
7259
|
const cache = /* @__PURE__ */ new Map();
|
|
7260
7260
|
return (identity) => {
|
|
7261
7261
|
if (!isIdentityName(identity)) {
|
|
7262
7262
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
7263
7263
|
}
|
|
7264
|
-
const stat =
|
|
7264
|
+
const stat = fs16.lstat(claudeJsonPath(identitiesDir, identity));
|
|
7265
7265
|
const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
|
|
7266
7266
|
const cached = cache.get(identity);
|
|
7267
7267
|
if (cached?.stamp === stamp) {
|
|
7268
7268
|
return cached.account;
|
|
7269
7269
|
}
|
|
7270
|
-
const account = readAccountMetadata(
|
|
7270
|
+
const account = readAccountMetadata(fs16, identitiesDir, identity);
|
|
7271
7271
|
cache.set(identity, { stamp, account });
|
|
7272
7272
|
return account;
|
|
7273
7273
|
};
|
|
@@ -7304,9 +7304,9 @@ var init_accountDescription = __esm({
|
|
|
7304
7304
|
});
|
|
7305
7305
|
|
|
7306
7306
|
// src/identityAccounts.ts
|
|
7307
|
-
function readIdentityAccount(
|
|
7307
|
+
function readIdentityAccount(fs16, identitiesDir, identity) {
|
|
7308
7308
|
try {
|
|
7309
|
-
const account = readAccountMetadata(
|
|
7309
|
+
const account = readAccountMetadata(fs16, identitiesDir, identity);
|
|
7310
7310
|
return account === void 0 ? void 0 : { account };
|
|
7311
7311
|
} catch (error) {
|
|
7312
7312
|
if (error instanceof AccountMetadataError) {
|
|
@@ -7944,8 +7944,8 @@ function segmentDay(epochMs) {
|
|
|
7944
7944
|
function segmentName(day, pid) {
|
|
7945
7945
|
return `${day}.${String(pid)}.jsonl`;
|
|
7946
7946
|
}
|
|
7947
|
-
function listLogSegments(
|
|
7948
|
-
return
|
|
7947
|
+
function listLogSegments(fs16, logDir) {
|
|
7948
|
+
return fs16.readdir(logDir).flatMap((name) => {
|
|
7949
7949
|
const match = SEGMENT_RE.exec(name);
|
|
7950
7950
|
const day = match?.[1];
|
|
7951
7951
|
if (day === void 0) {
|
|
@@ -7954,15 +7954,15 @@ function listLogSegments(fs15, logDir) {
|
|
|
7954
7954
|
return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
|
|
7955
7955
|
}).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
|
|
7956
7956
|
}
|
|
7957
|
-
function readUsageLog(
|
|
7957
|
+
function readUsageLog(fs16, logDir, options = {}) {
|
|
7958
7958
|
const { sinceMs } = options;
|
|
7959
7959
|
const records = [];
|
|
7960
7960
|
let invalidLines = 0;
|
|
7961
|
-
for (const segment of listLogSegments(
|
|
7961
|
+
for (const segment of listLogSegments(fs16, logDir)) {
|
|
7962
7962
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
7963
7963
|
continue;
|
|
7964
7964
|
}
|
|
7965
|
-
const read = readSegment(
|
|
7965
|
+
const read = readSegment(fs16, logDir, segment);
|
|
7966
7966
|
if (read === void 0) {
|
|
7967
7967
|
continue;
|
|
7968
7968
|
}
|
|
@@ -7976,8 +7976,8 @@ function readUsageLog(fs15, logDir, options = {}) {
|
|
|
7976
7976
|
records.sort((left, right) => left.at.localeCompare(right.at));
|
|
7977
7977
|
return { records, invalidLines };
|
|
7978
7978
|
}
|
|
7979
|
-
function readSegment(
|
|
7980
|
-
const contents =
|
|
7979
|
+
function readSegment(fs16, logDir, segment) {
|
|
7980
|
+
const contents = fs16.readFileUtf8(import_node_path22.default.join(logDir, segment.name));
|
|
7981
7981
|
if (contents === void 0) {
|
|
7982
7982
|
return void 0;
|
|
7983
7983
|
}
|
|
@@ -8011,9 +8011,9 @@ function snapshotPath(snapshotsDir, identity) {
|
|
|
8011
8011
|
}
|
|
8012
8012
|
return import_node_path22.default.join(snapshotsDir, `${identity}.json`);
|
|
8013
8013
|
}
|
|
8014
|
-
function readUsageSnapshot(
|
|
8014
|
+
function readUsageSnapshot(fs16, snapshotsDir, identity) {
|
|
8015
8015
|
const file = snapshotPath(snapshotsDir, identity);
|
|
8016
|
-
const raw =
|
|
8016
|
+
const raw = fs16.readFileUtf8(file);
|
|
8017
8017
|
if (raw === void 0) {
|
|
8018
8018
|
return void 0;
|
|
8019
8019
|
}
|
|
@@ -8029,8 +8029,8 @@ function readUsageSnapshot(fs15, snapshotsDir, identity) {
|
|
|
8029
8029
|
}
|
|
8030
8030
|
return snapshot.data;
|
|
8031
8031
|
}
|
|
8032
|
-
function listUsageSnapshots(
|
|
8033
|
-
return
|
|
8032
|
+
function listUsageSnapshots(fs16, snapshotsDir) {
|
|
8033
|
+
return fs16.readdir(snapshotsDir).flatMap((name) => {
|
|
8034
8034
|
if (!name.endsWith(".json")) {
|
|
8035
8035
|
return [];
|
|
8036
8036
|
}
|
|
@@ -8038,7 +8038,7 @@ function listUsageSnapshots(fs15, snapshotsDir) {
|
|
|
8038
8038
|
if (!isIdentityName(identity)) {
|
|
8039
8039
|
return [];
|
|
8040
8040
|
}
|
|
8041
|
-
const snapshot = readUsageSnapshot(
|
|
8041
|
+
const snapshot = readUsageSnapshot(fs16, snapshotsDir, identity);
|
|
8042
8042
|
return snapshot === void 0 ? [] : [snapshot];
|
|
8043
8043
|
}).sort((left, right) => left.identity.localeCompare(right.identity));
|
|
8044
8044
|
}
|
|
@@ -8063,11 +8063,11 @@ var init_read = __esm({
|
|
|
8063
8063
|
});
|
|
8064
8064
|
|
|
8065
8065
|
// src/usage/store.ts
|
|
8066
|
-
function pruneUsageLog(
|
|
8066
|
+
function pruneUsageLog(fs16, logDir, nowMs) {
|
|
8067
8067
|
const cutoff = nowMs - USAGE_RETENTION_MS;
|
|
8068
|
-
for (const segment of listLogSegments(
|
|
8068
|
+
for (const segment of listLogSegments(fs16, logDir)) {
|
|
8069
8069
|
if (segment.endsAt <= cutoff) {
|
|
8070
|
-
|
|
8070
|
+
fs16.removeRecursive(import_node_path23.default.join(logDir, segment.name));
|
|
8071
8071
|
}
|
|
8072
8072
|
}
|
|
8073
8073
|
}
|
|
@@ -8096,7 +8096,7 @@ function foldProviderState(current, record) {
|
|
|
8096
8096
|
};
|
|
8097
8097
|
}
|
|
8098
8098
|
function createUsageStore(deps) {
|
|
8099
|
-
const { fs:
|
|
8099
|
+
const { fs: fs16, paths } = deps;
|
|
8100
8100
|
let prunedDay;
|
|
8101
8101
|
const rewriteSnapshot = (identity, fold) => {
|
|
8102
8102
|
if (!isIdentityName(identity)) {
|
|
@@ -8105,7 +8105,7 @@ function createUsageStore(deps) {
|
|
|
8105
8105
|
}
|
|
8106
8106
|
let current;
|
|
8107
8107
|
try {
|
|
8108
|
-
current = readUsageSnapshot(
|
|
8108
|
+
current = readUsageSnapshot(fs16, paths.usageSnapshotsDir, identity);
|
|
8109
8109
|
} catch (error) {
|
|
8110
8110
|
if (!(error instanceof UsageSnapshotError)) {
|
|
8111
8111
|
throw error;
|
|
@@ -8132,8 +8132,8 @@ function createUsageStore(deps) {
|
|
|
8132
8132
|
...account === void 0 ? {} : { account },
|
|
8133
8133
|
providers
|
|
8134
8134
|
});
|
|
8135
|
-
|
|
8136
|
-
|
|
8135
|
+
fs16.mkdirPrivate(paths.usageSnapshotsDir);
|
|
8136
|
+
fs16.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
|
|
8137
8137
|
`);
|
|
8138
8138
|
deps.publish?.(snapshot);
|
|
8139
8139
|
return true;
|
|
@@ -8142,14 +8142,14 @@ function createUsageStore(deps) {
|
|
|
8142
8142
|
record: (input) => {
|
|
8143
8143
|
const record = UsageRecordSchema.parse(input);
|
|
8144
8144
|
const nowMs = deps.now();
|
|
8145
|
-
|
|
8146
|
-
|
|
8145
|
+
fs16.mkdirPrivate(paths.usageDir);
|
|
8146
|
+
fs16.mkdirPrivate(paths.usageLogDir);
|
|
8147
8147
|
const day = segmentDay(nowMs);
|
|
8148
8148
|
if (prunedDay !== day) {
|
|
8149
|
-
pruneUsageLog(
|
|
8149
|
+
pruneUsageLog(fs16, paths.usageLogDir, nowMs);
|
|
8150
8150
|
prunedDay = day;
|
|
8151
8151
|
}
|
|
8152
|
-
|
|
8152
|
+
fs16.appendFilePrivate(import_node_path23.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
|
|
8153
8153
|
`);
|
|
8154
8154
|
deps.onRecord?.(record);
|
|
8155
8155
|
if (record.identity !== void 0) {
|
|
@@ -8192,14 +8192,14 @@ var init_store2 = __esm({
|
|
|
8192
8192
|
function errorMessage(error) {
|
|
8193
8193
|
return error instanceof Error ? error.message : String(error);
|
|
8194
8194
|
}
|
|
8195
|
-
function loadPoolMembers(
|
|
8195
|
+
function loadPoolMembers(fs16, paths, identities, nowMs) {
|
|
8196
8196
|
const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
|
|
8197
|
-
const log = readUsageLog(
|
|
8197
|
+
const log = readUsageLog(fs16, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
8198
8198
|
return identities.map((identity) => {
|
|
8199
8199
|
const records = log.records.filter((record) => record.identity === identity && record.provider === ANTHROPIC_PROVIDER && Date.parse(record.at) >= windowStartMs);
|
|
8200
8200
|
try {
|
|
8201
|
-
const snapshot = readUsageSnapshot(
|
|
8202
|
-
const account = readAccountMetadata(
|
|
8201
|
+
const snapshot = readUsageSnapshot(fs16, paths.usageSnapshotsDir, identity);
|
|
8202
|
+
const account = readAccountMetadata(fs16, paths.identitiesDir, identity) ?? snapshot?.account;
|
|
8203
8203
|
return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
|
|
8204
8204
|
} catch (error) {
|
|
8205
8205
|
if (error instanceof UsageSnapshotError || error instanceof AccountMetadataError) {
|
|
@@ -8318,9 +8318,9 @@ function collectPoolIdentities(pools, poolName, stack, found) {
|
|
|
8318
8318
|
collectPoolIdentities(pools, nestedName, childStack, found);
|
|
8319
8319
|
}
|
|
8320
8320
|
}
|
|
8321
|
-
function readPicksFile(
|
|
8321
|
+
function readPicksFile(fs16, file) {
|
|
8322
8322
|
const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
|
|
8323
|
-
const raw =
|
|
8323
|
+
const raw = fs16.readFileUtf8(file);
|
|
8324
8324
|
if (raw === void 0) {
|
|
8325
8325
|
return { file: empty };
|
|
8326
8326
|
}
|
|
@@ -8333,17 +8333,17 @@ function readPicksFile(fs15, file) {
|
|
|
8333
8333
|
const result = PicksFileSchema.safeParse(parsed);
|
|
8334
8334
|
return result.success ? { file: result.data } : { file: empty, problem: `${file} is not a picks file this agent-shim can read` };
|
|
8335
8335
|
}
|
|
8336
|
-
function readStickyPick(
|
|
8337
|
-
const read = readPicksFile(
|
|
8336
|
+
function readStickyPick(fs16, picksFile, directory) {
|
|
8337
|
+
const read = readPicksFile(fs16, picksFile);
|
|
8338
8338
|
const entry = read.file.picks[directory];
|
|
8339
8339
|
return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
|
|
8340
8340
|
}
|
|
8341
|
-
function recordStickyPick(
|
|
8342
|
-
const current = readPicksFile(
|
|
8341
|
+
function recordStickyPick(fs16, picksFile, directory, identity, nowMs) {
|
|
8342
|
+
const current = readPicksFile(fs16, picksFile).file.picks;
|
|
8343
8343
|
const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
|
|
8344
8344
|
const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
|
|
8345
|
-
|
|
8346
|
-
|
|
8345
|
+
fs16.mkdirPrivate(import_node_path24.default.dirname(picksFile));
|
|
8346
|
+
fs16.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
8347
8347
|
`);
|
|
8348
8348
|
}
|
|
8349
8349
|
var import_node_path24, import_zod17, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
|
|
@@ -8377,9 +8377,9 @@ var init_poolPick = __esm({
|
|
|
8377
8377
|
});
|
|
8378
8378
|
|
|
8379
8379
|
// src/statusline/keys.ts
|
|
8380
|
-
function valueAt(source,
|
|
8380
|
+
function valueAt(source, path49) {
|
|
8381
8381
|
let current = source;
|
|
8382
|
-
for (const part of
|
|
8382
|
+
for (const part of path49) {
|
|
8383
8383
|
if (!isPlainObject(current)) {
|
|
8384
8384
|
return void 0;
|
|
8385
8385
|
}
|
|
@@ -8387,14 +8387,14 @@ function valueAt(source, path48) {
|
|
|
8387
8387
|
}
|
|
8388
8388
|
return current;
|
|
8389
8389
|
}
|
|
8390
|
-
function acceptsNull(
|
|
8391
|
-
const layer =
|
|
8390
|
+
function acceptsNull(path49) {
|
|
8391
|
+
const layer = path49.reduceRight((inner, part) => ({ [part]: inner }), null);
|
|
8392
8392
|
return StatuslineSchema.safeParse(layer).success;
|
|
8393
8393
|
}
|
|
8394
|
-
function keyOf(
|
|
8394
|
+
function keyOf(path49, declared) {
|
|
8395
8395
|
const optional = declared instanceof import_zod18.z.ZodOptional;
|
|
8396
8396
|
const leaf = optional ? declared.unwrap() : declared;
|
|
8397
|
-
const common = { path:
|
|
8397
|
+
const common = { path: path49.join("."), description: declared.description ?? "", defaultValue: valueAt(STATUSLINE_DEFAULTS, path49), optional, unsettable: acceptsNull(path49) };
|
|
8398
8398
|
if (leaf instanceof import_zod18.z.ZodNumber) {
|
|
8399
8399
|
return { ...common, kind: "integer", choices: [] };
|
|
8400
8400
|
}
|
|
@@ -8419,7 +8419,7 @@ function keyOf(path48, declared) {
|
|
|
8419
8419
|
if (leaf instanceof import_zod18.z.ZodArray && leaf.element instanceof import_zod18.z.ZodString) {
|
|
8420
8420
|
return { ...common, kind: "textList", choices: [] };
|
|
8421
8421
|
}
|
|
8422
|
-
throw new TypeError(`statusline setting ${
|
|
8422
|
+
throw new TypeError(`statusline setting ${path49.join(".")} has a kind the key listing does not describe`);
|
|
8423
8423
|
}
|
|
8424
8424
|
function walk(shape, prefix) {
|
|
8425
8425
|
return Object.entries(shape).flatMap(([name, schema]) => schema instanceof import_zod18.z.ZodObject ? walk(schema.shape, [...prefix, name]) : [keyOf([...prefix, name], schema)]);
|
|
@@ -8437,15 +8437,15 @@ var init_keys = __esm({
|
|
|
8437
8437
|
});
|
|
8438
8438
|
|
|
8439
8439
|
// src/statusline/change.ts
|
|
8440
|
-
function keyNamed(
|
|
8441
|
-
const found = statuslineKeys().find((key) => key.path ===
|
|
8440
|
+
function keyNamed(path49) {
|
|
8441
|
+
const found = statuslineKeys().find((key) => key.path === path49);
|
|
8442
8442
|
if (found === void 0) {
|
|
8443
|
-
throw new UsageError(`"${
|
|
8443
|
+
throw new UsageError(`"${path49}" is not a statusline setting; \`agent-shim statusline keys\` lists them.`);
|
|
8444
8444
|
}
|
|
8445
8445
|
return found;
|
|
8446
8446
|
}
|
|
8447
|
-
function setAt(target,
|
|
8448
|
-
const [head, ...rest] =
|
|
8447
|
+
function setAt(target, path49, value) {
|
|
8448
|
+
const [head, ...rest] = path49;
|
|
8449
8449
|
if (head === void 0) {
|
|
8450
8450
|
return;
|
|
8451
8451
|
}
|
|
@@ -8458,8 +8458,8 @@ function setAt(target, path48, value) {
|
|
|
8458
8458
|
target[head] = next;
|
|
8459
8459
|
setAt(next, rest, value);
|
|
8460
8460
|
}
|
|
8461
|
-
function removeAt(target,
|
|
8462
|
-
const [head, ...rest] =
|
|
8461
|
+
function removeAt(target, path49) {
|
|
8462
|
+
const [head, ...rest] = path49;
|
|
8463
8463
|
if (head === void 0) {
|
|
8464
8464
|
return;
|
|
8465
8465
|
}
|
|
@@ -8477,13 +8477,13 @@ function removeAt(target, path48) {
|
|
|
8477
8477
|
}
|
|
8478
8478
|
function applyStatuslineChange(existing, change) {
|
|
8479
8479
|
const draft = structuredClone(existing ?? {});
|
|
8480
|
-
for (const [
|
|
8481
|
-
keyNamed(
|
|
8482
|
-
setAt(draft,
|
|
8480
|
+
for (const [path49, value] of Object.entries(change.set ?? {})) {
|
|
8481
|
+
keyNamed(path49);
|
|
8482
|
+
setAt(draft, path49.split("."), value);
|
|
8483
8483
|
}
|
|
8484
|
-
for (const
|
|
8485
|
-
keyNamed(
|
|
8486
|
-
removeAt(draft,
|
|
8484
|
+
for (const path49 of change.unset ?? []) {
|
|
8485
|
+
keyNamed(path49);
|
|
8486
|
+
removeAt(draft, path49.split("."));
|
|
8487
8487
|
}
|
|
8488
8488
|
const result = StatuslineSchema.safeParse(draft);
|
|
8489
8489
|
if (!result.success) {
|
|
@@ -9861,13 +9861,13 @@ function decideSignIn(facts) {
|
|
|
9861
9861
|
function credentialsFilePath(farmRoot) {
|
|
9862
9862
|
return import_node_path27.default.join(farmRoot, CREDENTIALS_FILE);
|
|
9863
9863
|
}
|
|
9864
|
-
function identitySignIn(
|
|
9864
|
+
function identitySignIn(fs16, probe, identity) {
|
|
9865
9865
|
const probing = !identity.hasCredentialBlock && identity.provider === void 0;
|
|
9866
9866
|
return decideSignIn({
|
|
9867
9867
|
hasCredentialBlock: identity.hasCredentialBlock,
|
|
9868
9868
|
provider: identity.provider,
|
|
9869
9869
|
keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
|
|
9870
|
-
credentialsFile: probing &&
|
|
9870
|
+
credentialsFile: probing && fs16.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
|
|
9871
9871
|
platform: probe.platform
|
|
9872
9872
|
});
|
|
9873
9873
|
}
|
|
@@ -10329,15 +10329,15 @@ function signInCatalogueFingerprint(raw, filePath) {
|
|
|
10329
10329
|
function savedCatalogueFingerprint(provider, paths, env, home, read) {
|
|
10330
10330
|
if (provider.codex?.login === "chatgpt-sign-in") return signInCatalogueFingerprint(read(paths.chatgptSignInFile), paths.chatgptSignInFile);
|
|
10331
10331
|
const configuredHome = env.CODEX_HOME;
|
|
10332
|
-
const codexHome = configuredHome === void 0 || configuredHome === "" ?
|
|
10333
|
-
return cliCatalogueFingerprint(read(
|
|
10332
|
+
const codexHome = configuredHome === void 0 || configuredHome === "" ? import_node_path34.default.join(home, ".codex") : configuredHome;
|
|
10333
|
+
return cliCatalogueFingerprint(read(import_node_path34.default.join(codexHome, "auth.json")));
|
|
10334
10334
|
}
|
|
10335
|
-
var import_node_crypto10,
|
|
10335
|
+
var import_node_crypto10, import_node_path34, import_zod30, CatalogueBindingSchema;
|
|
10336
10336
|
var init_catalogueCredential = __esm({
|
|
10337
10337
|
"src/codex/catalogueCredential.ts"() {
|
|
10338
10338
|
"use strict";
|
|
10339
10339
|
import_node_crypto10 = require("node:crypto");
|
|
10340
|
-
|
|
10340
|
+
import_node_path34 = __toESM(require("node:path"), 1);
|
|
10341
10341
|
import_zod30 = require("zod");
|
|
10342
10342
|
init_siwcStore();
|
|
10343
10343
|
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) });
|
|
@@ -11442,13 +11442,13 @@ var init_cliOverride = __esm({
|
|
|
11442
11442
|
|
|
11443
11443
|
// src/launcher/launchRecords.ts
|
|
11444
11444
|
function recordFile(directory, pid, identity) {
|
|
11445
|
-
return
|
|
11445
|
+
return import_node_path42.default.join(directory, `${String(pid)}.${identity}${RECORD_SUFFIX}`);
|
|
11446
11446
|
}
|
|
11447
|
-
function readRecord(
|
|
11447
|
+
function readRecord(fs16, directory, name) {
|
|
11448
11448
|
if (!name.endsWith(RECORD_SUFFIX)) {
|
|
11449
11449
|
return void 0;
|
|
11450
11450
|
}
|
|
11451
|
-
const raw =
|
|
11451
|
+
const raw = fs16.readFileUtf8(import_node_path42.default.join(directory, name));
|
|
11452
11452
|
if (raw === void 0) {
|
|
11453
11453
|
return void 0;
|
|
11454
11454
|
}
|
|
@@ -11461,27 +11461,27 @@ function readRecord(fs15, directory, name) {
|
|
|
11461
11461
|
const result = LaunchRecordSchema.safeParse(parsed);
|
|
11462
11462
|
return result.success ? result.data : void 0;
|
|
11463
11463
|
}
|
|
11464
|
-
function registerLaunch(
|
|
11465
|
-
|
|
11466
|
-
for (const name of
|
|
11467
|
-
const record2 = readRecord(
|
|
11464
|
+
function registerLaunch(fs16, directory, owner, isRunning) {
|
|
11465
|
+
fs16.mkdirPrivate(directory);
|
|
11466
|
+
for (const name of fs16.readdir(directory)) {
|
|
11467
|
+
const record2 = readRecord(fs16, directory, name);
|
|
11468
11468
|
if (record2 !== void 0 && !isRunning(record2.pid)) {
|
|
11469
|
-
|
|
11469
|
+
fs16.removeRecursive(import_node_path42.default.join(directory, name));
|
|
11470
11470
|
}
|
|
11471
11471
|
}
|
|
11472
11472
|
const file = recordFile(directory, owner.pid, owner.identity);
|
|
11473
11473
|
const record = { pid: owner.pid, identity: owner.identity, startedAt: new Date(owner.startedAtMs).toISOString() };
|
|
11474
|
-
|
|
11474
|
+
fs16.writeFilePrivate(file, `${JSON.stringify(record)}
|
|
11475
11475
|
`);
|
|
11476
11476
|
return () => {
|
|
11477
|
-
|
|
11477
|
+
fs16.removeRecursive(file);
|
|
11478
11478
|
};
|
|
11479
11479
|
}
|
|
11480
|
-
var
|
|
11480
|
+
var import_node_path42, import_zod39, LaunchRecordSchema, RECORD_SUFFIX;
|
|
11481
11481
|
var init_launchRecords = __esm({
|
|
11482
11482
|
"src/launcher/launchRecords.ts"() {
|
|
11483
11483
|
"use strict";
|
|
11484
|
-
|
|
11484
|
+
import_node_path42 = __toESM(require("node:path"), 1);
|
|
11485
11485
|
import_zod39 = require("zod");
|
|
11486
11486
|
LaunchRecordSchema = import_zod39.z.strictObject({
|
|
11487
11487
|
/** The launcher's process id, which is what tells a launch in progress from a record a crashed launcher left behind. */
|
|
@@ -11616,7 +11616,7 @@ function buildEnv(params) {
|
|
|
11616
11616
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
11617
11617
|
let providerCustomHeaders;
|
|
11618
11618
|
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
11619
|
-
env.CLAUDE_CONFIG_DIR =
|
|
11619
|
+
env.CLAUDE_CONFIG_DIR = import_node_path43.default.join(params.identitiesDir, params.resolvedIdentityName);
|
|
11620
11620
|
}
|
|
11621
11621
|
if (params.provider !== void 0) {
|
|
11622
11622
|
const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
|
|
@@ -11670,11 +11670,11 @@ function buildEnv(params) {
|
|
|
11670
11670
|
}
|
|
11671
11671
|
return env;
|
|
11672
11672
|
}
|
|
11673
|
-
var
|
|
11673
|
+
var import_node_path43, LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
|
|
11674
11674
|
var init_flags = __esm({
|
|
11675
11675
|
"src/launcher/flags.ts"() {
|
|
11676
11676
|
"use strict";
|
|
11677
|
-
|
|
11677
|
+
import_node_path43 = __toESM(require("node:path"), 1);
|
|
11678
11678
|
init_envBool();
|
|
11679
11679
|
init_cliError();
|
|
11680
11680
|
init_conditions();
|
|
@@ -11759,15 +11759,15 @@ function contextTokensOfTranscript(text) {
|
|
|
11759
11759
|
}
|
|
11760
11760
|
return void 0;
|
|
11761
11761
|
}
|
|
11762
|
-
function newestTranscript(
|
|
11762
|
+
function newestTranscript(fs16, projectDir) {
|
|
11763
11763
|
let newest;
|
|
11764
11764
|
let newestMs = -Infinity;
|
|
11765
|
-
for (const name of
|
|
11765
|
+
for (const name of fs16.readdir(projectDir)) {
|
|
11766
11766
|
if (!name.endsWith(".jsonl")) {
|
|
11767
11767
|
continue;
|
|
11768
11768
|
}
|
|
11769
|
-
const candidate =
|
|
11770
|
-
const stat =
|
|
11769
|
+
const candidate = import_node_path44.default.join(projectDir, name);
|
|
11770
|
+
const stat = fs16.lstat(candidate);
|
|
11771
11771
|
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
11772
11772
|
newestMs = stat.mtimeMs;
|
|
11773
11773
|
newest = candidate;
|
|
@@ -11775,21 +11775,21 @@ function newestTranscript(fs15, projectDir) {
|
|
|
11775
11775
|
}
|
|
11776
11776
|
return newest;
|
|
11777
11777
|
}
|
|
11778
|
-
function resumedContextTokens(
|
|
11778
|
+
function resumedContextTokens(fs16, params) {
|
|
11779
11779
|
const target = resumeTargetOf(params.passthrough);
|
|
11780
11780
|
if (target === void 0) {
|
|
11781
11781
|
return void 0;
|
|
11782
11782
|
}
|
|
11783
|
-
const projectDir =
|
|
11784
|
-
const file = target.kind === "id" ?
|
|
11785
|
-
const text = file === void 0 ? void 0 :
|
|
11783
|
+
const projectDir = import_node_path44.default.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
11784
|
+
const file = target.kind === "id" ? import_node_path44.default.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs16, projectDir);
|
|
11785
|
+
const text = file === void 0 ? void 0 : fs16.readFileUtf8(file);
|
|
11786
11786
|
return text === void 0 ? void 0 : contextTokensOfTranscript(text);
|
|
11787
11787
|
}
|
|
11788
|
-
var
|
|
11788
|
+
var import_node_path44;
|
|
11789
11789
|
var init_resumeContext = __esm({
|
|
11790
11790
|
"src/usage/resumeContext.ts"() {
|
|
11791
11791
|
"use strict";
|
|
11792
|
-
|
|
11792
|
+
import_node_path44 = __toESM(require("node:path"), 1);
|
|
11793
11793
|
}
|
|
11794
11794
|
});
|
|
11795
11795
|
|
|
@@ -12386,7 +12386,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
|
|
|
12386
12386
|
return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
|
|
12387
12387
|
}
|
|
12388
12388
|
function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
12389
|
-
const { paths, fs:
|
|
12389
|
+
const { paths, fs: fs16, proc, log } = params;
|
|
12390
12390
|
if (decided.pool === void 0) {
|
|
12391
12391
|
return { identityDecision: decided };
|
|
12392
12392
|
}
|
|
@@ -12405,7 +12405,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
12405
12405
|
selectedVia: decided.source,
|
|
12406
12406
|
pools: params.pools,
|
|
12407
12407
|
paths,
|
|
12408
|
-
fs:
|
|
12408
|
+
fs: fs16,
|
|
12409
12409
|
usageFs: farmRuntime.fs,
|
|
12410
12410
|
cwd: farmRuntime.cwd,
|
|
12411
12411
|
now: farmRuntime.now,
|
|
@@ -12429,7 +12429,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
|
|
|
12429
12429
|
};
|
|
12430
12430
|
}
|
|
12431
12431
|
function decideLaunch(params, readOnly) {
|
|
12432
|
-
const { paths, fs:
|
|
12432
|
+
const { paths, fs: fs16, proc, log } = params;
|
|
12433
12433
|
const { env, argv } = proc;
|
|
12434
12434
|
const parsedArgv = parseLauncherArgv(argv);
|
|
12435
12435
|
const cliOverride = buildCliOverride({
|
|
@@ -12444,7 +12444,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12444
12444
|
argv0Identity: params.pickedIdentity ?? parsedArgv.identity,
|
|
12445
12445
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
12446
12446
|
readActiveIdentityFile: () => {
|
|
12447
|
-
const raw =
|
|
12447
|
+
const raw = fs16.readFileUtf8(paths.activeIdentityFile);
|
|
12448
12448
|
if (raw === void 0) {
|
|
12449
12449
|
return void 0;
|
|
12450
12450
|
}
|
|
@@ -12479,7 +12479,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12479
12479
|
}
|
|
12480
12480
|
let loadedIdentity;
|
|
12481
12481
|
if (identityDecision.name !== void 0) {
|
|
12482
|
-
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name,
|
|
12482
|
+
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs16);
|
|
12483
12483
|
if (loadedIdentity === void 0) {
|
|
12484
12484
|
log.error(
|
|
12485
12485
|
`agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
|
|
@@ -12494,7 +12494,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12494
12494
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
12495
12495
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
12496
12496
|
});
|
|
12497
|
-
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true &&
|
|
12497
|
+
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
12498
|
log.error(
|
|
12499
12499
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
12500
12500
|
);
|
|
@@ -12503,7 +12503,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12503
12503
|
const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
|
|
12504
12504
|
const providerParams = {
|
|
12505
12505
|
paths,
|
|
12506
|
-
port:
|
|
12506
|
+
port: fs16,
|
|
12507
12507
|
...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
|
|
12508
12508
|
...farmContext === void 0 ? {} : { cascade: farmContext.cascade },
|
|
12509
12509
|
...loadedIdentity?.config.provider === void 0 ? {} : { identityProvider: loadedIdentity.config.provider }
|
|
@@ -12624,9 +12624,9 @@ function decideLaunch(params, readOnly) {
|
|
|
12624
12624
|
const doorRecord = doorPid === void 0 ? void 0 : readFrontDoorCodexRecord(params.fs, paths.frontdoorDir, doorPid);
|
|
12625
12625
|
const doorHome = doorRecord?.codexHome;
|
|
12626
12626
|
const catalogueEnv = doorHome === void 0 ? proc.env : { ...proc.env, CODEX_HOME: doorHome };
|
|
12627
|
-
const listedProviders = listProviderNames(
|
|
12627
|
+
const listedProviders = listProviderNames(fs16.readdir, paths.providersDir).flatMap((name) => {
|
|
12628
12628
|
try {
|
|
12629
|
-
const definition = loadProvider(paths.providersDir, name,
|
|
12629
|
+
const definition = loadProvider(paths.providersDir, name, fs16);
|
|
12630
12630
|
if (definition === void 0) return [];
|
|
12631
12631
|
const catalogueOwner = definition.kind === "codex" ? doorPid : void 0;
|
|
12632
12632
|
const generation = definition.kind === "codex" ? doorRecord?.generation : void 0;
|
|
@@ -12636,8 +12636,8 @@ function decideLaunch(params, readOnly) {
|
|
|
12636
12636
|
if (definition.kind === "codex" && readOnly && cache !== void 0) {
|
|
12637
12637
|
const binding = parseCatalogueBinding(params.fs.readFileUtf8(catalogueBindingPath(paths, name, catalogueOwner, generation)));
|
|
12638
12638
|
const configuredHome = catalogueEnv.CODEX_HOME;
|
|
12639
|
-
const home = configuredHome === void 0 || configuredHome === "" ?
|
|
12640
|
-
const source = definition.codex?.login === "chatgpt-sign-in" ? paths.chatgptSignInFile :
|
|
12639
|
+
const home = configuredHome === void 0 || configuredHome === "" ? import_node_path45.default.join(import_node_os8.default.homedir(), ".codex") : configuredHome;
|
|
12640
|
+
const source = definition.codex?.login === "chatgpt-sign-in" ? paths.chatgptSignInFile : import_node_path45.default.resolve(home, "auth.json");
|
|
12641
12641
|
const revision = params.fs.fileRevision?.(source);
|
|
12642
12642
|
if (binding === void 0 || binding.fingerprint !== cache.credentialFingerprint || binding.source !== source || revision === void 0 || revision !== binding.revision) return [];
|
|
12643
12643
|
}
|
|
@@ -12658,7 +12658,7 @@ function decideLaunch(params, readOnly) {
|
|
|
12658
12658
|
return { args: args2, pickerSuppressed: startsSession && pickerSettings !== void 0 && callerSettings };
|
|
12659
12659
|
};
|
|
12660
12660
|
const args = argsForSupervisor().args;
|
|
12661
|
-
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR :
|
|
12661
|
+
const configDir = configDirEscapeHatchApplies || identityDecision.name === void 0 ? env.CLAUDE_CONFIG_DIR : import_node_path45.default.join(paths.identitiesDir, identityDecision.name);
|
|
12662
12662
|
const decision = {
|
|
12663
12663
|
identitySource: identityDecision.source,
|
|
12664
12664
|
configDirEscapeHatch: identityDecision.configDirEscapeHatch,
|
|
@@ -12733,7 +12733,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
|
|
|
12733
12733
|
let unregisterLaunch;
|
|
12734
12734
|
const updateCheck = runLaunchUpdateCheck({
|
|
12735
12735
|
mode: params.updateMode ?? "off",
|
|
12736
|
-
checkPath:
|
|
12736
|
+
checkPath: import_node_path45.default.join(paths.root, "update.check"),
|
|
12737
12737
|
currentVersion: package_default.version,
|
|
12738
12738
|
port: params.update
|
|
12739
12739
|
});
|
|
@@ -12898,7 +12898,7 @@ function runLaunchPlan(plan, spawn3) {
|
|
|
12898
12898
|
function runLauncher(params) {
|
|
12899
12899
|
params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
|
|
12900
12900
|
}
|
|
12901
|
-
var import_node_crypto12, import_node_os8, import_node_util2,
|
|
12901
|
+
var import_node_crypto12, import_node_os8, import_node_util2, import_node_path45;
|
|
12902
12902
|
var init_launcher = __esm({
|
|
12903
12903
|
"src/launcher.ts"() {
|
|
12904
12904
|
"use strict";
|
|
@@ -12906,7 +12906,7 @@ var init_launcher = __esm({
|
|
|
12906
12906
|
import_node_os8 = __toESM(require("node:os"), 1);
|
|
12907
12907
|
init_catalogueCredential();
|
|
12908
12908
|
import_node_util2 = require("node:util");
|
|
12909
|
-
|
|
12909
|
+
import_node_path45 = __toESM(require("node:path"), 1);
|
|
12910
12910
|
init_package();
|
|
12911
12911
|
init_envBool();
|
|
12912
12912
|
init_argv();
|
|
@@ -12953,13 +12953,13 @@ function agentShimCliPath(distDir = typeof __AGENT_SHIM_DIST_DIR__ === "string"
|
|
|
12953
12953
|
if (distDir === void 0) {
|
|
12954
12954
|
throw new OwnCliPathUnknownError();
|
|
12955
12955
|
}
|
|
12956
|
-
return
|
|
12956
|
+
return import_node_path46.default.join(distDir, OWN_CLI_FILE_NAME);
|
|
12957
12957
|
}
|
|
12958
|
-
var
|
|
12958
|
+
var import_node_path46, OWN_CLI_FILE_NAME, OwnCliPathUnknownError;
|
|
12959
12959
|
var init_ownCli = __esm({
|
|
12960
12960
|
"src/ownCli.ts"() {
|
|
12961
12961
|
"use strict";
|
|
12962
|
-
|
|
12962
|
+
import_node_path46 = __toESM(require("node:path"), 1);
|
|
12963
12963
|
init_cliError();
|
|
12964
12964
|
OWN_CLI_FILE_NAME = "cli.cjs";
|
|
12965
12965
|
OwnCliPathUnknownError = class extends CliError {
|
|
@@ -12983,15 +12983,15 @@ var init_childRun = __esm({
|
|
|
12983
12983
|
|
|
12984
12984
|
// src/frontdoor/doorLog.ts
|
|
12985
12985
|
function appendDoorLog(paths, line) {
|
|
12986
|
-
|
|
12987
|
-
|
|
12986
|
+
import_node_fs14.default.mkdirSync(paths.logsDir, { recursive: true });
|
|
12987
|
+
import_node_fs14.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
12988
12988
|
`);
|
|
12989
12989
|
}
|
|
12990
|
-
var
|
|
12990
|
+
var import_node_fs14;
|
|
12991
12991
|
var init_doorLog = __esm({
|
|
12992
12992
|
"src/frontdoor/doorLog.ts"() {
|
|
12993
12993
|
"use strict";
|
|
12994
|
-
|
|
12994
|
+
import_node_fs14 = __toESM(require("node:fs"), 1);
|
|
12995
12995
|
}
|
|
12996
12996
|
});
|
|
12997
12997
|
|
|
@@ -13011,14 +13011,14 @@ var init_selfIdentity = __esm({
|
|
|
13011
13011
|
|
|
13012
13012
|
// src/frontdoor/trust.ts
|
|
13013
13013
|
function resolveTrustBundle(params) {
|
|
13014
|
-
const { caCertFile, bundlesDir, variable, inherited, fs:
|
|
13015
|
-
if (inherited === void 0 || inherited === "" ||
|
|
13014
|
+
const { caCertFile, bundlesDir, variable, inherited, fs: fs16 } = params;
|
|
13015
|
+
if (inherited === void 0 || inherited === "" || import_node_path47.default.resolve(inherited) === import_node_path47.default.resolve(caCertFile)) {
|
|
13016
13016
|
return { path: caCertFile };
|
|
13017
13017
|
}
|
|
13018
|
-
const caPem =
|
|
13018
|
+
const caPem = fs16.readFileUtf8(caCertFile);
|
|
13019
13019
|
let inheritedPem;
|
|
13020
13020
|
try {
|
|
13021
|
-
inheritedPem =
|
|
13021
|
+
inheritedPem = fs16.readFileUtf8(inherited);
|
|
13022
13022
|
} catch (error) {
|
|
13023
13023
|
return {
|
|
13024
13024
|
path: caCertFile,
|
|
@@ -13030,19 +13030,19 @@ function resolveTrustBundle(params) {
|
|
|
13030
13030
|
}
|
|
13031
13031
|
const combined = `${inheritedPem.trimEnd()}
|
|
13032
13032
|
${caPem}`;
|
|
13033
|
-
const bundle =
|
|
13034
|
-
if (!
|
|
13035
|
-
|
|
13036
|
-
|
|
13033
|
+
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`);
|
|
13034
|
+
if (!fs16.exists(bundle)) {
|
|
13035
|
+
fs16.mkdirp(bundlesDir);
|
|
13036
|
+
fs16.writeFileAtomic(bundle, combined);
|
|
13037
13037
|
}
|
|
13038
13038
|
return { path: bundle };
|
|
13039
13039
|
}
|
|
13040
|
-
var import_node_crypto13,
|
|
13040
|
+
var import_node_crypto13, import_node_path47, BUNDLE_NAME_HEX_DIGITS;
|
|
13041
13041
|
var init_trust = __esm({
|
|
13042
13042
|
"src/frontdoor/trust.ts"() {
|
|
13043
13043
|
"use strict";
|
|
13044
13044
|
import_node_crypto13 = require("node:crypto");
|
|
13045
|
-
|
|
13045
|
+
import_node_path47 = __toESM(require("node:path"), 1);
|
|
13046
13046
|
BUNDLE_NAME_HEX_DIGITS = 16;
|
|
13047
13047
|
}
|
|
13048
13048
|
});
|
|
@@ -13073,7 +13073,7 @@ function realEnsurePorts(paths, spawnDaemon) {
|
|
|
13073
13073
|
}
|
|
13074
13074
|
},
|
|
13075
13075
|
// 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,
|
|
13076
|
+
verifyListener: (port) => probeFrontDoorSync(port, import_node_fs15.default.readFileSync(paths.frontdoorCaCertFile, "utf8"))
|
|
13077
13077
|
};
|
|
13078
13078
|
}
|
|
13079
13079
|
function realFrontDoorPort(paths, spawnDaemon) {
|
|
@@ -13144,11 +13144,11 @@ function realFrontDoorPort(paths, spawnDaemon) {
|
|
|
13144
13144
|
}
|
|
13145
13145
|
};
|
|
13146
13146
|
}
|
|
13147
|
-
var
|
|
13147
|
+
var import_node_fs15, import_node_os9, realTrustBundleFs;
|
|
13148
13148
|
var init_realFrontDoorPort = __esm({
|
|
13149
13149
|
"src/frontdoor/realFrontDoorPort.ts"() {
|
|
13150
13150
|
"use strict";
|
|
13151
|
-
|
|
13151
|
+
import_node_fs15 = __toESM(require("node:fs"), 1);
|
|
13152
13152
|
import_node_os9 = __toESM(require("node:os"), 1);
|
|
13153
13153
|
init_providersStore();
|
|
13154
13154
|
init_providerCatalogue();
|
|
@@ -13162,10 +13162,10 @@ var init_realFrontDoorPort = __esm({
|
|
|
13162
13162
|
init_selfIdentity();
|
|
13163
13163
|
init_trust();
|
|
13164
13164
|
realTrustBundleFs = {
|
|
13165
|
-
readFileUtf8: (file) =>
|
|
13166
|
-
exists: (file) =>
|
|
13165
|
+
readFileUtf8: (file) => import_node_fs15.default.readFileSync(file, "utf8"),
|
|
13166
|
+
exists: (file) => import_node_fs15.default.existsSync(file),
|
|
13167
13167
|
mkdirp: (dir) => {
|
|
13168
|
-
|
|
13168
|
+
import_node_fs15.default.mkdirSync(dir, { recursive: true });
|
|
13169
13169
|
},
|
|
13170
13170
|
writeFileAtomic: (file, contents) => {
|
|
13171
13171
|
realFarmFs.writeFilePrivate(file, contents);
|
|
@@ -13228,7 +13228,7 @@ function realPrepareLaunchParams(paths, options) {
|
|
|
13228
13228
|
frontdoor: realFrontDoorPort(paths, options.spawnDaemon),
|
|
13229
13229
|
credentials: { ...realCredentialPort, cache: realCredentialCacheEnv(paths) },
|
|
13230
13230
|
hold: realHoldPort,
|
|
13231
|
-
hasStoredLogin: (identity) => identitySignIn(realFarmFs, { platform: process.platform, run: options.run ?? realRunPort }, { farmRoot:
|
|
13231
|
+
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
13232
|
...farm.directoryIdentity === void 0 ? {} : { directoryPinnedIdentity: farm.directoryIdentity },
|
|
13233
13233
|
...farm.directoryConfigProfile === void 0 ? {} : { directoryRuleConfigProfile: farm.directoryConfigProfile },
|
|
13234
13234
|
...farm.globalDefaultConfigProfile === void 0 ? {} : { globalDefaultConfigProfile: farm.globalDefaultConfigProfile },
|
|
@@ -13289,12 +13289,12 @@ function resolveClaudeLaunch(options, run = realRunPort) {
|
|
|
13289
13289
|
};
|
|
13290
13290
|
return { resolution: resolveLaunch(realPrepareLaunchParams(paths, { proc, log, spawnDaemon, run, farm: buildFarmRuntime(paths, options.cwd, run) })), warnings };
|
|
13291
13291
|
}
|
|
13292
|
-
var import_node_os10,
|
|
13292
|
+
var import_node_os10, import_node_path48, import_node_crypto14, LaunchRefusedError;
|
|
13293
13293
|
var init_launchWiring = __esm({
|
|
13294
13294
|
"src/launchWiring.ts"() {
|
|
13295
13295
|
"use strict";
|
|
13296
13296
|
import_node_os10 = __toESM(require("node:os"), 1);
|
|
13297
|
-
|
|
13297
|
+
import_node_path48 = __toESM(require("node:path"), 1);
|
|
13298
13298
|
import_node_crypto14 = require("node:crypto");
|
|
13299
13299
|
init_cliError();
|
|
13300
13300
|
init_claudeShim();
|
|
@@ -14353,8 +14353,8 @@ function pathnameOf(url) {
|
|
|
14353
14353
|
return new URL(url ?? "/", "http://127.0.0.1").pathname;
|
|
14354
14354
|
}
|
|
14355
14355
|
function isRcSessionExchange(url) {
|
|
14356
|
-
const
|
|
14357
|
-
return
|
|
14356
|
+
const path49 = pathnameOf(url);
|
|
14357
|
+
return path49 === RC_SESSIONS_PATH_PREFIX || path49.startsWith(`${RC_SESSIONS_PATH_PREFIX}/`);
|
|
14358
14358
|
}
|
|
14359
14359
|
var RC_SESSION_ID_PREFIX = "cse_";
|
|
14360
14360
|
var RC_IDLE_EXPIRY_MS = 45e3;
|
|
@@ -14913,8 +14913,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
|
|
|
14913
14913
|
function isRcReadFileEncoding(value) {
|
|
14914
14914
|
return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value);
|
|
14915
14915
|
}
|
|
14916
|
-
function buildRcReadFilePayload(requestId,
|
|
14917
|
-
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path:
|
|
14916
|
+
function buildRcReadFilePayload(requestId, path49, options) {
|
|
14917
|
+
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path49, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
|
|
14918
14918
|
}
|
|
14919
14919
|
function buildRcFileSuggestionsPayload(requestId, query) {
|
|
14920
14920
|
return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
|
|
@@ -15016,15 +15016,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
|
|
|
15016
15016
|
const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
|
|
15017
15017
|
return result.ok ? { ...result, requestId } : result;
|
|
15018
15018
|
}
|
|
15019
|
-
async function readRcSessionFile(deps, sessionId,
|
|
15020
|
-
if (
|
|
15019
|
+
async function readRcSessionFile(deps, sessionId, path49, options) {
|
|
15020
|
+
if (path49 === "") {
|
|
15021
15021
|
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
15022
|
}
|
|
15023
15023
|
if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
|
|
15024
15024
|
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
15025
|
}
|
|
15026
15026
|
const requestId = deps.newUuid();
|
|
15027
|
-
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId,
|
|
15027
|
+
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path49, options), `read ${path49} from session ${sessionId}`);
|
|
15028
15028
|
return result.ok ? { ...result, requestId } : result;
|
|
15029
15029
|
}
|
|
15030
15030
|
async function suggestRcSessionFiles(deps, sessionId, query) {
|
|
@@ -15193,11 +15193,11 @@ function createRcControlHandler(deps) {
|
|
|
15193
15193
|
path: "read-file",
|
|
15194
15194
|
read: (body) => {
|
|
15195
15195
|
const session = bodyString(body, "session");
|
|
15196
|
-
const
|
|
15196
|
+
const path49 = bodyString(body, "path");
|
|
15197
15197
|
const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
|
|
15198
15198
|
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,
|
|
15199
|
+
const refused2 = session === void 0 || path49 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === 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, path49, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
|
|
15201
15201
|
}
|
|
15202
15202
|
},
|
|
15203
15203
|
{
|
|
@@ -15507,9 +15507,9 @@ function requestIdOfBody(body) {
|
|
|
15507
15507
|
}
|
|
15508
15508
|
function frontDoorRcControl(transport, token) {
|
|
15509
15509
|
const headers = { authorization: `Bearer ${token}` };
|
|
15510
|
-
const listAnswerOf = async (
|
|
15510
|
+
const listAnswerOf = async (path49, what) => {
|
|
15511
15511
|
try {
|
|
15512
|
-
return await transport.request({ method: "GET", path:
|
|
15512
|
+
return await transport.request({ method: "GET", path: path49, headers });
|
|
15513
15513
|
} catch (error) {
|
|
15514
15514
|
throw new Error(`${what}: could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
15515
15515
|
}
|
|
@@ -15581,10 +15581,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15581
15581
|
}
|
|
15582
15582
|
return pending;
|
|
15583
15583
|
};
|
|
15584
|
-
const writeOf = async (
|
|
15584
|
+
const writeOf = async (path49, body, describeFailure2) => {
|
|
15585
15585
|
let answer;
|
|
15586
15586
|
try {
|
|
15587
|
-
answer = await transport.request({ method: "POST", path:
|
|
15587
|
+
answer = await transport.request({ method: "POST", path: path49, headers: { ...headers, "content-type": "application/json" }, body });
|
|
15588
15588
|
} catch (error) {
|
|
15589
15589
|
return { ok: false, message: `could not reach the front door's control listener: ${error instanceof Error ? error.message : String(error)}` };
|
|
15590
15590
|
}
|
|
@@ -15615,10 +15615,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
15615
15615
|
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
15616
|
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
15617
|
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,
|
|
15618
|
+
readFile: async (sessionId, path49, options) => await writeOf(
|
|
15619
15619
|
`${CONTROL_PATH_PREFIX}/read-file`,
|
|
15620
|
-
JSON.stringify({ session: sessionId, path:
|
|
15621
|
-
(status, message) => `reading ${
|
|
15620
|
+
JSON.stringify({ session: sessionId, path: path49, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
|
|
15621
|
+
(status, message) => `reading ${path49} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
15622
15622
|
),
|
|
15623
15623
|
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
15624
|
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 +15777,12 @@ function tlsFacts(options) {
|
|
|
15777
15777
|
}
|
|
15778
15778
|
function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15779
15779
|
const agent = new ExemptTlsAgent();
|
|
15780
|
-
const post = async (
|
|
15780
|
+
const post = async (path49, headers, body) => await new Promise((resolve, reject) => {
|
|
15781
15781
|
const options = {
|
|
15782
15782
|
host: target.host,
|
|
15783
15783
|
port: target.port,
|
|
15784
15784
|
method: "POST",
|
|
15785
|
-
path:
|
|
15785
|
+
path: path49,
|
|
15786
15786
|
// 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
15787
|
headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
|
|
15788
15788
|
agent
|
|
@@ -15847,12 +15847,12 @@ function lateRcStreamDial(resolve) {
|
|
|
15847
15847
|
}
|
|
15848
15848
|
function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
15849
15849
|
const agent = new ExemptTlsAgent();
|
|
15850
|
-
const request4 = async (method,
|
|
15850
|
+
const request4 = async (method, path49, headers, body, signal) => await new Promise((resolve, reject) => {
|
|
15851
15851
|
const options = {
|
|
15852
15852
|
host: target.host,
|
|
15853
15853
|
port: target.port,
|
|
15854
15854
|
method,
|
|
15855
|
-
path:
|
|
15855
|
+
path: path49,
|
|
15856
15856
|
// 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
15857
|
headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
|
|
15858
15858
|
agent,
|
|
@@ -15894,9 +15894,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
|
|
|
15894
15894
|
return { status, body: await readAll(response) };
|
|
15895
15895
|
},
|
|
15896
15896
|
openStream: async (sessionId, headers, resume, signal) => {
|
|
15897
|
-
const
|
|
15897
|
+
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
15898
|
const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
|
|
15899
|
-
const { status, response } = await request4("GET",
|
|
15899
|
+
const { status, response } = await request4("GET", path49, streamHeaders, void 0, signal);
|
|
15900
15900
|
if (!isSuccessful2(status)) {
|
|
15901
15901
|
await readAll(response);
|
|
15902
15902
|
return { status, chunks: NO_CHUNKS };
|
|
@@ -16146,11 +16146,11 @@ function credentialOfJson(parsed) {
|
|
|
16146
16146
|
function sequenceNumOfJson(value) {
|
|
16147
16147
|
return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
|
|
16148
16148
|
}
|
|
16149
|
-
function createRcCredentialStore(
|
|
16150
|
-
|
|
16149
|
+
function createRcCredentialStore(fs16, dir) {
|
|
16150
|
+
fs16.mkdirPrivate(dir);
|
|
16151
16151
|
const fileFor = (sessionId) => import_node_path13.default.join(dir, `${sessionId}.json`);
|
|
16152
16152
|
const readParsed = (sessionId) => {
|
|
16153
|
-
const raw =
|
|
16153
|
+
const raw = fs16.readFileUtf8(fileFor(sessionId));
|
|
16154
16154
|
if (raw === void 0) {
|
|
16155
16155
|
return void 0;
|
|
16156
16156
|
}
|
|
@@ -16175,7 +16175,7 @@ function createRcCredentialStore(fs15, dir) {
|
|
|
16175
16175
|
}
|
|
16176
16176
|
const cursor = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
|
|
16177
16177
|
const record = { ...credential, ...cursor === void 0 ? {} : { highestSequenceNum: cursor } };
|
|
16178
|
-
|
|
16178
|
+
fs16.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
16179
16179
|
`);
|
|
16180
16180
|
},
|
|
16181
16181
|
readCursor: (sessionId) => {
|
|
@@ -16190,14 +16190,14 @@ function createRcCredentialStore(fs15, dir) {
|
|
|
16190
16190
|
}
|
|
16191
16191
|
const credential = credentialOfJson(readParsed(sessionId));
|
|
16192
16192
|
const record = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
|
|
16193
|
-
|
|
16193
|
+
fs16.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
|
|
16194
16194
|
`);
|
|
16195
16195
|
},
|
|
16196
16196
|
remove: (sessionId) => {
|
|
16197
16197
|
if (!isSafeSessionId(sessionId)) {
|
|
16198
16198
|
return;
|
|
16199
16199
|
}
|
|
16200
|
-
|
|
16200
|
+
fs16.removeRecursive(fileFor(sessionId));
|
|
16201
16201
|
}
|
|
16202
16202
|
};
|
|
16203
16203
|
}
|
|
@@ -16889,19 +16889,19 @@ function writePools(paths, pools) {
|
|
|
16889
16889
|
applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
|
|
16890
16890
|
}
|
|
16891
16891
|
function poolCycleOf(pools, name) {
|
|
16892
|
-
const walk2 = (current,
|
|
16892
|
+
const walk2 = (current, path49) => {
|
|
16893
16893
|
for (const entry of pools[current]?.identities ?? []) {
|
|
16894
16894
|
const nested = poolNameOf(poolMemberIdentity(entry));
|
|
16895
16895
|
if (nested === void 0) {
|
|
16896
16896
|
continue;
|
|
16897
16897
|
}
|
|
16898
16898
|
if (nested === name) {
|
|
16899
|
-
return [...
|
|
16899
|
+
return [...path49, nested];
|
|
16900
16900
|
}
|
|
16901
|
-
if (
|
|
16901
|
+
if (path49.includes(nested)) {
|
|
16902
16902
|
continue;
|
|
16903
16903
|
}
|
|
16904
|
-
const found = walk2(nested, [...
|
|
16904
|
+
const found = walk2(nested, [...path49, nested]);
|
|
16905
16905
|
if (found !== void 0) {
|
|
16906
16906
|
return found;
|
|
16907
16907
|
}
|
|
@@ -17613,7 +17613,7 @@ var ResetRowSchema = import_zod24.z.strictObject({
|
|
|
17613
17613
|
var ResetScheduleSchema = import_zod24.z.strictObject({ resets: import_zod24.z.readonly(import_zod24.z.array(ResetRowSchema)) });
|
|
17614
17614
|
|
|
17615
17615
|
// src/frontdoor/controlSchemas.ts
|
|
17616
|
-
var
|
|
17616
|
+
var import_node_path36 = __toESM(require("node:path"), 1);
|
|
17617
17617
|
var import_zod32 = require("zod");
|
|
17618
17618
|
|
|
17619
17619
|
// src/doctorReport.ts
|
|
@@ -17662,8 +17662,8 @@ var RenameJournalUnreadableError = class extends CliError {
|
|
|
17662
17662
|
}
|
|
17663
17663
|
detail;
|
|
17664
17664
|
};
|
|
17665
|
-
function readRenameJournal(
|
|
17666
|
-
const raw =
|
|
17665
|
+
function readRenameJournal(fs16, file) {
|
|
17666
|
+
const raw = fs16.readFileUtf8(file);
|
|
17667
17667
|
if (raw === void 0) {
|
|
17668
17668
|
return void 0;
|
|
17669
17669
|
}
|
|
@@ -17679,16 +17679,16 @@ function readRenameJournal(fs15, file) {
|
|
|
17679
17679
|
}
|
|
17680
17680
|
return result.data;
|
|
17681
17681
|
}
|
|
17682
|
-
function listRenameJournals(
|
|
17682
|
+
function listRenameJournals(fs16, directory) {
|
|
17683
17683
|
const journals = [];
|
|
17684
17684
|
const unreadable = [];
|
|
17685
|
-
for (const name of [...
|
|
17685
|
+
for (const name of [...fs16.readdir(directory)].sort()) {
|
|
17686
17686
|
if (!name.endsWith(JOURNAL_SUFFIX)) {
|
|
17687
17687
|
continue;
|
|
17688
17688
|
}
|
|
17689
17689
|
const file = import_node_path30.default.join(directory, name);
|
|
17690
17690
|
try {
|
|
17691
|
-
const journal = readRenameJournal(
|
|
17691
|
+
const journal = readRenameJournal(fs16, file);
|
|
17692
17692
|
if (journal !== void 0) {
|
|
17693
17693
|
journals.push(journal);
|
|
17694
17694
|
}
|
|
@@ -17731,8 +17731,8 @@ var NameHeldByUnfinishedRenameError = class extends CliError {
|
|
|
17731
17731
|
this.name = "NameHeldByUnfinishedRenameError";
|
|
17732
17732
|
}
|
|
17733
17733
|
};
|
|
17734
|
-
function requireNameFreeOfUnfinishedRename(
|
|
17735
|
-
const held = listRenameJournals(
|
|
17734
|
+
function requireNameFreeOfUnfinishedRename(fs16, directory, name, action, sameName, exists) {
|
|
17735
|
+
const held = listRenameJournals(fs16, directory).journals.find((journal) => [journal.from, journal.to].some((heldName) => heldName === name || sameName(name, heldName)));
|
|
17736
17736
|
if (held !== void 0) {
|
|
17737
17737
|
throw new NameHeldByUnfinishedRenameError(action, name, held, finishabilityOf(held, exists));
|
|
17738
17738
|
}
|
|
@@ -18082,8 +18082,46 @@ function removeIdentity(paths, name) {
|
|
|
18082
18082
|
|
|
18083
18083
|
// src/doctorReport.ts
|
|
18084
18084
|
init_realPorts();
|
|
18085
|
-
var
|
|
18086
|
-
|
|
18085
|
+
var import_node_fs12 = __toESM(require("node:fs"), 1);
|
|
18086
|
+
|
|
18087
|
+
// src/doctorPath.ts
|
|
18088
|
+
var import_node_fs10 = __toESM(require("node:fs"), 1);
|
|
18089
|
+
var import_node_path33 = __toESM(require("node:path"), 1);
|
|
18090
|
+
init_blockingSpawn();
|
|
18091
|
+
init_realPorts();
|
|
18092
|
+
function realpathOrSelf(target) {
|
|
18093
|
+
try {
|
|
18094
|
+
return import_node_fs10.default.realpathSync(target);
|
|
18095
|
+
} catch {
|
|
18096
|
+
return target;
|
|
18097
|
+
}
|
|
18098
|
+
}
|
|
18099
|
+
var MAX_FORWARDING_SCRIPT_BYTES = 8192;
|
|
18100
|
+
function resolveMiseDispatcher(target, pathDirs, env, trustedExecutable) {
|
|
18101
|
+
const executable = realpathOrSelf(target);
|
|
18102
|
+
const trustedMise = import_node_path33.default.join(import_node_path33.default.dirname(trustedExecutable), "mise");
|
|
18103
|
+
if (import_node_path33.default.basename(executable) !== "mise" || realpathOrSelf(trustedMise) !== executable) return void 0;
|
|
18104
|
+
const result = spawnSyncBlocking("a mise shim lookup", executable, ["which", import_node_path33.default.basename(target)], { encoding: "utf8", env });
|
|
18105
|
+
if (result.error !== void 0) return void 0;
|
|
18106
|
+
if (result.status === 0 && result.stdout.trim() !== "") return result.stdout.trim();
|
|
18107
|
+
if (!result.stderr.includes("not currently active")) return void 0;
|
|
18108
|
+
for (const dir of pathDirs) {
|
|
18109
|
+
const candidate = findExecutableInDir(dir, import_node_path33.default.basename(target));
|
|
18110
|
+
if (candidate !== void 0 && realpathOrSelf(candidate) !== executable) {
|
|
18111
|
+
try {
|
|
18112
|
+
const script = import_node_fs10.default.statSync(candidate).size <= MAX_FORWARDING_SCRIPT_BYTES ? realFsPort.readFileUtf8(candidate) : void 0;
|
|
18113
|
+
const forwarded = script === void 0 ? void 0 : /^#!\/bin\/sh\r?\nexec (\/[A-Za-z0-9_./+-]+) "\$@"\r?\n?$/.exec(script)?.[1];
|
|
18114
|
+
return forwarded ?? candidate;
|
|
18115
|
+
} catch {
|
|
18116
|
+
return candidate;
|
|
18117
|
+
}
|
|
18118
|
+
}
|
|
18119
|
+
}
|
|
18120
|
+
return void 0;
|
|
18121
|
+
}
|
|
18122
|
+
|
|
18123
|
+
// src/doctorReport.ts
|
|
18124
|
+
var import_node_path35 = __toESM(require("node:path"), 1);
|
|
18087
18125
|
init_signIn();
|
|
18088
18126
|
init_identityAccounts();
|
|
18089
18127
|
init_read();
|
|
@@ -18329,7 +18367,7 @@ function pushFrontDoorListeners(push, readings) {
|
|
|
18329
18367
|
}
|
|
18330
18368
|
|
|
18331
18369
|
// src/frontdoor/listenerReadings.ts
|
|
18332
|
-
var
|
|
18370
|
+
var import_node_fs11 = __toESM(require("node:fs"), 1);
|
|
18333
18371
|
init_probe();
|
|
18334
18372
|
function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
18335
18373
|
if (!supervisorAlive) {
|
|
@@ -18350,7 +18388,7 @@ function readFrontDoorListeners(state, supervisorAlive, probes) {
|
|
|
18350
18388
|
}
|
|
18351
18389
|
function realFrontDoorListenerProbes(paths) {
|
|
18352
18390
|
return {
|
|
18353
|
-
authenticateProvider: (port) => probeFrontDoorSync(port,
|
|
18391
|
+
authenticateProvider: (port) => probeFrontDoorSync(port, import_node_fs11.default.readFileSync(paths.frontdoorCaCertFile, "utf8")),
|
|
18354
18392
|
connect: probeListenerAcceptSync,
|
|
18355
18393
|
now: () => performance.now()
|
|
18356
18394
|
};
|
|
@@ -18482,11 +18520,12 @@ var DOCTOR_SECTIONS = [
|
|
|
18482
18520
|
"frontdoor",
|
|
18483
18521
|
"models"
|
|
18484
18522
|
];
|
|
18485
|
-
function refinePathShadow(status, ownExecutablePath, realpath) {
|
|
18523
|
+
function refinePathShadow(status, ownExecutablePath, realpath, resolveDispatcher) {
|
|
18486
18524
|
if (status.status !== "shadowed") {
|
|
18487
18525
|
return status;
|
|
18488
18526
|
}
|
|
18489
|
-
|
|
18527
|
+
const resolved = resolveDispatcher?.(status.by) ?? status.by;
|
|
18528
|
+
return realpath(resolved) === realpath(ownExecutablePath) ? { status: "ok" } : status;
|
|
18490
18529
|
}
|
|
18491
18530
|
function validateJson(schema, input) {
|
|
18492
18531
|
if (input.raw === void 0) {
|
|
@@ -18515,7 +18554,7 @@ function tcpPortEraRecord(raw) {
|
|
|
18515
18554
|
return (has("port") || has("lastPort")) && !has("socketPath");
|
|
18516
18555
|
}
|
|
18517
18556
|
function pushPathResolution(push, resolution) {
|
|
18518
|
-
const ownDir =
|
|
18557
|
+
const ownDir = import_node_path35.default.dirname(resolution.ownExecutablePath);
|
|
18519
18558
|
switch (resolution.agentShim.status) {
|
|
18520
18559
|
case "ok":
|
|
18521
18560
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -18635,14 +18674,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
18635
18674
|
}
|
|
18636
18675
|
function pushLegacyName(push, params) {
|
|
18637
18676
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
18638
|
-
if (legacyVariables.length === 0 &&
|
|
18677
|
+
if (legacyVariables.length === 0 && import_node_path35.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
18639
18678
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
18640
18679
|
return;
|
|
18641
18680
|
}
|
|
18642
18681
|
for (const name of legacyVariables) {
|
|
18643
18682
|
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
18683
|
}
|
|
18645
|
-
if (
|
|
18684
|
+
if (import_node_path35.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
18646
18685
|
push(
|
|
18647
18686
|
"legacy-name",
|
|
18648
18687
|
"warn",
|
|
@@ -18736,7 +18775,7 @@ function runDoctor(params) {
|
|
|
18736
18775
|
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
18776
|
}
|
|
18738
18777
|
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.`,
|
|
18778
|
+
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
18779
|
}
|
|
18741
18780
|
const validIdentityNames = /* @__PURE__ */ new Set();
|
|
18742
18781
|
const signedInAccounts = [];
|
|
@@ -19086,13 +19125,6 @@ function formatDoctorReport(report) {
|
|
|
19086
19125
|
lines.push("", report.ok ? "All checks passed." : `${String(failCount)} check(s) failed.`);
|
|
19087
19126
|
return lines;
|
|
19088
19127
|
}
|
|
19089
|
-
function realpathOrSelf(target) {
|
|
19090
|
-
try {
|
|
19091
|
-
return import_node_fs11.default.realpathSync(target);
|
|
19092
|
-
} catch {
|
|
19093
|
-
return target;
|
|
19094
|
-
}
|
|
19095
|
-
}
|
|
19096
19128
|
function servingDoorListeners(paths) {
|
|
19097
19129
|
const state = readFrontDoorState(realFarmFs, paths.frontdoorStateFile) ?? {};
|
|
19098
19130
|
const alive = state.supervisorPid !== void 0 && realIsProcessRunning(state.supervisorPid);
|
|
@@ -19102,9 +19134,9 @@ function collectDoctorReport(params) {
|
|
|
19102
19134
|
const { paths } = params;
|
|
19103
19135
|
const { names: identityNames, unreachable: unreachableIdentities } = listIdentityDirectories(paths);
|
|
19104
19136
|
const identities = identityNames.map((name) => {
|
|
19105
|
-
const farmRoot =
|
|
19106
|
-
const identityPath =
|
|
19107
|
-
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent:
|
|
19137
|
+
const farmRoot = import_node_path35.default.join(paths.identitiesDir, name);
|
|
19138
|
+
const identityPath = import_node_path35.default.join(farmRoot, "identity.json");
|
|
19139
|
+
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
19140
|
});
|
|
19109
19141
|
const usageSnapshots = {};
|
|
19110
19142
|
for (const name of identityNames) {
|
|
@@ -19119,14 +19151,14 @@ function collectDoctorReport(params) {
|
|
|
19119
19151
|
}
|
|
19120
19152
|
}
|
|
19121
19153
|
}
|
|
19122
|
-
const profileNames =
|
|
19154
|
+
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
19155
|
const configProfiles = profileNames.map((name) => {
|
|
19124
|
-
const profilePath =
|
|
19156
|
+
const profilePath = import_node_path35.default.join(paths.configProfilesDir, `${name}.json`);
|
|
19125
19157
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
19126
19158
|
});
|
|
19127
|
-
const providerNames =
|
|
19159
|
+
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
19160
|
const providers = providerNames.map((name) => {
|
|
19129
|
-
const providerPath =
|
|
19161
|
+
const providerPath = import_node_path35.default.join(paths.providersDir, `${name}.json`);
|
|
19130
19162
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
19131
19163
|
});
|
|
19132
19164
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -19138,16 +19170,17 @@ function collectDoctorReport(params) {
|
|
|
19138
19170
|
binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
19139
19171
|
}
|
|
19140
19172
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
19141
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
19173
|
+
const pathDirs = (params.env.PATH ?? "").split(import_node_path35.default.delimiter).filter((dir) => dir !== "");
|
|
19142
19174
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
19143
19175
|
findPathShadow({
|
|
19144
19176
|
pathDirs,
|
|
19145
|
-
targetDir:
|
|
19146
|
-
targetFilename:
|
|
19177
|
+
targetDir: import_node_path35.default.dirname(shimState.targetPath),
|
|
19178
|
+
targetFilename: import_node_path35.default.basename(shimState.targetPath),
|
|
19147
19179
|
findExecutableInDir
|
|
19148
19180
|
}),
|
|
19149
19181
|
shimState.targetPath,
|
|
19150
|
-
realpathOrSelf
|
|
19182
|
+
realpathOrSelf,
|
|
19183
|
+
(target) => resolveMiseDispatcher(target, pathDirs, params.env, shimState.targetPath)
|
|
19151
19184
|
);
|
|
19152
19185
|
const uid = process.getuid?.();
|
|
19153
19186
|
const allowlistContent = realFarmFs.readFileUtf8(paths.headroomAllowlistFile);
|
|
@@ -19175,19 +19208,20 @@ function collectDoctorReport(params) {
|
|
|
19175
19208
|
categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
|
|
19176
19209
|
activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
|
|
19177
19210
|
binaryDiscovery,
|
|
19178
|
-
claudeShim: { state: shimState, targetExists: shimState !== void 0 &&
|
|
19211
|
+
claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs12.default.existsSync(shimState.targetPath) },
|
|
19179
19212
|
rootPath: paths.root,
|
|
19180
19213
|
pathResolution: {
|
|
19181
19214
|
ownExecutablePath,
|
|
19182
19215
|
agentShim: refinePathShadow(
|
|
19183
19216
|
findPathShadow({
|
|
19184
19217
|
pathDirs,
|
|
19185
|
-
targetDir:
|
|
19218
|
+
targetDir: import_node_path35.default.dirname(ownExecutablePath),
|
|
19186
19219
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
19187
19220
|
findExecutableInDir
|
|
19188
19221
|
}),
|
|
19189
19222
|
ownExecutablePath,
|
|
19190
|
-
realpathOrSelf
|
|
19223
|
+
realpathOrSelf,
|
|
19224
|
+
(target) => resolveMiseDispatcher(target, pathDirs, params.env, ownExecutablePath)
|
|
19191
19225
|
),
|
|
19192
19226
|
...claudeShimShadow === void 0 ? {} : { claude: claudeShimShadow }
|
|
19193
19227
|
},
|
|
@@ -19272,11 +19306,11 @@ var FrontDoorSessionsOutputSchema = import_zod32.z.strictObject({ sessions: impo
|
|
|
19272
19306
|
var CheckRunInputSchema = import_zod32.z.strictObject({
|
|
19273
19307
|
path: import_zod32.z.string().min(1),
|
|
19274
19308
|
identity: import_zod32.z.string().min(1).optional()
|
|
19275
|
-
}).refine((input) =>
|
|
19309
|
+
}).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
19310
|
var PoolPickInputSchema = import_zod32.z.strictObject({
|
|
19277
19311
|
pool: import_zod32.z.string().min(1),
|
|
19278
19312
|
path: import_zod32.z.string().min(1)
|
|
19279
|
-
}).refine((input) =>
|
|
19313
|
+
}).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
19314
|
var DoctorFindingSchema = import_zod32.z.strictObject({
|
|
19281
19315
|
section: import_zod32.z.enum(DOCTOR_SECTIONS),
|
|
19282
19316
|
subject: import_zod32.z.string().optional(),
|
|
@@ -19700,7 +19734,7 @@ function profileValue(name, paths) {
|
|
|
19700
19734
|
function createConfigApiRouter(deps) {
|
|
19701
19735
|
const authed = doorApiAuth(deps.expectedToken);
|
|
19702
19736
|
const { paths } = deps;
|
|
19703
|
-
const route = (
|
|
19737
|
+
const route = (path49, summary) => authed.meta((0, import_openapi3.openapi)({ method: "POST", path: path49, summary, tags: [CONFIG_API_TAG] }));
|
|
19704
19738
|
return {
|
|
19705
19739
|
config: {
|
|
19706
19740
|
identity: {
|
|
@@ -20087,7 +20121,7 @@ var import_openapi6 = require("@orpc/openapi");
|
|
|
20087
20121
|
init_cliError();
|
|
20088
20122
|
|
|
20089
20123
|
// src/frontdoor/launchSchemas.ts
|
|
20090
|
-
var
|
|
20124
|
+
var import_node_path37 = __toESM(require("node:path"), 1);
|
|
20091
20125
|
var import_zod36 = require("zod");
|
|
20092
20126
|
init_statusline();
|
|
20093
20127
|
init_claudeVersion();
|
|
@@ -20098,7 +20132,7 @@ var LaunchResolveInputSchema = import_zod36.z.strictObject({
|
|
|
20098
20132
|
argv: import_zod36.z.readonly(import_zod36.z.array(import_zod36.z.string())).optional(),
|
|
20099
20133
|
/** 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
20134
|
env: import_zod36.z.record(import_zod36.z.string(), import_zod36.z.string()).optional()
|
|
20101
|
-
}).refine((input) =>
|
|
20135
|
+
}).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
20136
|
var LaunchPoolDecisionSchema = import_zod36.z.strictObject({
|
|
20103
20137
|
name: import_zod36.z.string(),
|
|
20104
20138
|
reasons: import_zod36.z.readonly(import_zod36.z.array(import_zod36.z.string())),
|
|
@@ -22278,7 +22312,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
22278
22312
|
}
|
|
22279
22313
|
|
|
22280
22314
|
// src/frontdoor/rcSelfHostMint.ts
|
|
22281
|
-
var
|
|
22315
|
+
var import_node_path38 = __toESM(require("node:path"), 1);
|
|
22282
22316
|
init_account();
|
|
22283
22317
|
var CREDENTIALS_FILE2 = ".credentials.json";
|
|
22284
22318
|
var CLAUDE_JSON2 = ".claude.json";
|
|
@@ -22289,8 +22323,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
|
|
|
22289
22323
|
function isRecord14(value) {
|
|
22290
22324
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22291
22325
|
}
|
|
22292
|
-
function readJsonObject(
|
|
22293
|
-
const raw =
|
|
22326
|
+
function readJsonObject(fs16, file) {
|
|
22327
|
+
const raw = fs16.readFileUtf8(file);
|
|
22294
22328
|
if (raw === void 0) {
|
|
22295
22329
|
return void 0;
|
|
22296
22330
|
}
|
|
@@ -22302,8 +22336,8 @@ function readJsonObject(fs15, file) {
|
|
|
22302
22336
|
}
|
|
22303
22337
|
return isRecord14(parsed) ? parsed : void 0;
|
|
22304
22338
|
}
|
|
22305
|
-
function readRcSelfHostRecord(
|
|
22306
|
-
const parsed = readJsonObject(
|
|
22339
|
+
function readRcSelfHostRecord(fs16, frontdoorDir) {
|
|
22340
|
+
const parsed = readJsonObject(fs16, import_node_path38.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
22307
22341
|
if (parsed === void 0) {
|
|
22308
22342
|
return void 0;
|
|
22309
22343
|
}
|
|
@@ -22317,11 +22351,11 @@ function mintRcSelfHostCredential(deps) {
|
|
|
22317
22351
|
if (!isIdentityName(deps.identity)) {
|
|
22318
22352
|
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
22319
22353
|
}
|
|
22320
|
-
const identityDir =
|
|
22321
|
-
const credentialsFile =
|
|
22322
|
-
const claudeJsonFile =
|
|
22323
|
-
const recordDir =
|
|
22324
|
-
const recordFile2 =
|
|
22354
|
+
const identityDir = import_node_path38.default.join(deps.identitiesDir, deps.identity);
|
|
22355
|
+
const credentialsFile = import_node_path38.default.join(identityDir, CREDENTIALS_FILE2);
|
|
22356
|
+
const claudeJsonFile = import_node_path38.default.join(identityDir, CLAUDE_JSON2);
|
|
22357
|
+
const recordDir = import_node_path38.default.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
22358
|
+
const recordFile2 = import_node_path38.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
22325
22359
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
22326
22360
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
22327
22361
|
const existingOauth = isRecord14(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
@@ -22337,7 +22371,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
22337
22371
|
const organizationUuid = deps.newUuid();
|
|
22338
22372
|
const accountUuid = deps.newUuid();
|
|
22339
22373
|
const mintedAt = new Date(deps.now()).toISOString();
|
|
22340
|
-
deps.fs.mkdirPrivate(
|
|
22374
|
+
deps.fs.mkdirPrivate(import_node_path38.default.dirname(credentialsFile));
|
|
22341
22375
|
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
22376
|
`);
|
|
22343
22377
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
@@ -22373,27 +22407,27 @@ function mintRcSelfHostCredential(deps) {
|
|
|
22373
22407
|
init_ensure2();
|
|
22374
22408
|
|
|
22375
22409
|
// src/frontdoor/liveSessionRegistry.ts
|
|
22376
|
-
var
|
|
22410
|
+
var import_node_path39 = __toESM(require("node:path"), 1);
|
|
22377
22411
|
init_capability();
|
|
22378
22412
|
init_state();
|
|
22379
22413
|
function sameStat(recorded, current) {
|
|
22380
22414
|
return recorded?.mtimeMs === current.mtimeMs && recorded.sizeBytes === current.sizeBytes;
|
|
22381
22415
|
}
|
|
22382
22416
|
function createLiveSessionRegistry(ports) {
|
|
22383
|
-
const { fs:
|
|
22417
|
+
const { fs: fs16, sessionsDir } = ports;
|
|
22384
22418
|
const known = /* @__PURE__ */ new Map();
|
|
22385
22419
|
let tokens = /* @__PURE__ */ new Set();
|
|
22386
22420
|
let bySessionId = /* @__PURE__ */ new Map();
|
|
22387
|
-
const recordNames = () =>
|
|
22421
|
+
const recordNames = () => fs16.readdir(sessionsDir).filter(isSessionRecordName);
|
|
22388
22422
|
const rebuildIndexes = () => {
|
|
22389
22423
|
const records = [...known.values()].flatMap(({ record }) => record === void 0 ? [] : [record]);
|
|
22390
22424
|
tokens = new Set(records.map((record) => record.token));
|
|
22391
22425
|
bySessionId = new Map(records.flatMap((record) => record.sessionId === void 0 ? [] : [[record.sessionId, record]]));
|
|
22392
22426
|
};
|
|
22393
22427
|
const load = (name, stat) => {
|
|
22394
|
-
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(
|
|
22428
|
+
known.set(name, { stat: { mtimeMs: stat.mtimeMs, sizeBytes: stat.sizeBytes }, record: readFrontDoorSessionRecord(fs16, sessionsDir, name) });
|
|
22395
22429
|
};
|
|
22396
|
-
const statOf = (name) =>
|
|
22430
|
+
const statOf = (name) => fs16.lstat(import_node_path39.default.join(sessionsDir, name));
|
|
22397
22431
|
const reconcile = () => {
|
|
22398
22432
|
const names = new Set(recordNames());
|
|
22399
22433
|
let changed = false;
|
|
@@ -22460,7 +22494,7 @@ init_plan2();
|
|
|
22460
22494
|
init_poolPick();
|
|
22461
22495
|
|
|
22462
22496
|
// src/agents/read.ts
|
|
22463
|
-
var
|
|
22497
|
+
var import_node_path40 = __toESM(require("node:path"), 1);
|
|
22464
22498
|
var import_zod38 = require("zod");
|
|
22465
22499
|
var PROJECTS_DIR = "projects";
|
|
22466
22500
|
var TASKS_DIR = "tasks";
|
|
@@ -22484,17 +22518,17 @@ function parseEntry2(project, entry) {
|
|
|
22484
22518
|
const base = match?.[1];
|
|
22485
22519
|
return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
|
|
22486
22520
|
}
|
|
22487
|
-
function listSessions2(
|
|
22521
|
+
function listSessions2(fs16, configDir) {
|
|
22488
22522
|
const found = [];
|
|
22489
|
-
for (const project of
|
|
22490
|
-
const projectDir =
|
|
22523
|
+
for (const project of fs16.readdir(import_node_path40.default.join(configDir, PROJECTS_DIR))) {
|
|
22524
|
+
const projectDir = import_node_path40.default.join(configDir, PROJECTS_DIR, project);
|
|
22491
22525
|
const entries = /* @__PURE__ */ new Set();
|
|
22492
|
-
for (const name of
|
|
22526
|
+
for (const name of fs16.readdir(projectDir)) {
|
|
22493
22527
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
22494
22528
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
22495
22529
|
continue;
|
|
22496
22530
|
}
|
|
22497
|
-
const children =
|
|
22531
|
+
const children = fs16.readdir(import_node_path40.default.join(projectDir, name));
|
|
22498
22532
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
22499
22533
|
entries.add(name);
|
|
22500
22534
|
}
|
|
@@ -22505,17 +22539,17 @@ function listSessions2(fs15, configDir) {
|
|
|
22505
22539
|
}
|
|
22506
22540
|
return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
|
|
22507
22541
|
}
|
|
22508
|
-
function locateAgents(
|
|
22542
|
+
function locateAgents(fs16, configDir, relativeDir, workflowRunId, report) {
|
|
22509
22543
|
const located = [];
|
|
22510
|
-
for (const name of listDirOrReport(
|
|
22544
|
+
for (const name of listDirOrReport(fs16, configDir, relativeDir, report)) {
|
|
22511
22545
|
if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
|
|
22512
22546
|
continue;
|
|
22513
22547
|
}
|
|
22514
22548
|
const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
|
|
22515
22549
|
located.push({
|
|
22516
22550
|
id,
|
|
22517
|
-
metaPath:
|
|
22518
|
-
transcriptPath:
|
|
22551
|
+
metaPath: import_node_path40.default.join(relativeDir, name),
|
|
22552
|
+
transcriptPath: import_node_path40.default.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
|
|
22519
22553
|
workflowRunId
|
|
22520
22554
|
});
|
|
22521
22555
|
}
|
|
@@ -22556,17 +22590,17 @@ function toNode(read, children) {
|
|
|
22556
22590
|
function describeFailure(error) {
|
|
22557
22591
|
return error instanceof Error ? error.message : String(error);
|
|
22558
22592
|
}
|
|
22559
|
-
function readFileOrReport(
|
|
22593
|
+
function readFileOrReport(fs16, configDir, relative, report) {
|
|
22560
22594
|
try {
|
|
22561
|
-
return
|
|
22595
|
+
return fs16.readFileUtf8(import_node_path40.default.join(configDir, relative));
|
|
22562
22596
|
} catch (error) {
|
|
22563
22597
|
report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
|
|
22564
22598
|
return void 0;
|
|
22565
22599
|
}
|
|
22566
22600
|
}
|
|
22567
|
-
function listDirOrReport(
|
|
22601
|
+
function listDirOrReport(fs16, configDir, relative, report) {
|
|
22568
22602
|
try {
|
|
22569
|
-
return
|
|
22603
|
+
return fs16.readdir(import_node_path40.default.join(configDir, relative));
|
|
22570
22604
|
} catch (error) {
|
|
22571
22605
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
|
|
22572
22606
|
return [];
|
|
@@ -22589,38 +22623,38 @@ var WorkflowRunFileSchema = import_zod38.z.object({
|
|
|
22589
22623
|
phases: import_zod38.z.array(import_zod38.z.object({ title: import_zod38.z.string() })).default([]),
|
|
22590
22624
|
summary: import_zod38.z.string().optional()
|
|
22591
22625
|
});
|
|
22592
|
-
function summariseSession(
|
|
22593
|
-
const sessionRelative =
|
|
22594
|
-
const subagentsRelative =
|
|
22595
|
-
const workflowsUnderSubagents =
|
|
22626
|
+
function summariseSession(fs16, configDir, ref) {
|
|
22627
|
+
const sessionRelative = import_node_path40.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22628
|
+
const subagentsRelative = import_node_path40.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
22629
|
+
const workflowsUnderSubagents = import_node_path40.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
22596
22630
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
22597
|
-
let agentCount =
|
|
22598
|
-
for (const runDir of
|
|
22631
|
+
let agentCount = fs16.readdir(import_node_path40.default.join(configDir, subagentsRelative)).filter(isMeta).length;
|
|
22632
|
+
for (const runDir of fs16.readdir(import_node_path40.default.join(configDir, workflowsUnderSubagents))) {
|
|
22599
22633
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
22600
|
-
agentCount +=
|
|
22634
|
+
agentCount += fs16.readdir(import_node_path40.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
22601
22635
|
}
|
|
22602
22636
|
}
|
|
22603
|
-
const workflowRunCount =
|
|
22604
|
-
const transcript =
|
|
22637
|
+
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;
|
|
22638
|
+
const transcript = fs16.lstat(import_node_path40.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
|
|
22605
22639
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
22606
22640
|
}
|
|
22607
|
-
function readSessionAgentTree(
|
|
22641
|
+
function readSessionAgentTree(fs16, configDir, ref, options = {}) {
|
|
22608
22642
|
const problems = [];
|
|
22609
22643
|
const report = (problem) => {
|
|
22610
22644
|
problems.push(problem);
|
|
22611
22645
|
};
|
|
22612
|
-
const sessionRelative =
|
|
22613
|
-
const subagentsRelative =
|
|
22614
|
-
const workflowsUnderSubagents =
|
|
22615
|
-
const located = locateAgents(
|
|
22616
|
-
for (const runDir of listDirOrReport(
|
|
22646
|
+
const sessionRelative = import_node_path40.default.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
22647
|
+
const subagentsRelative = import_node_path40.default.join(sessionRelative, SUBAGENTS_DIR);
|
|
22648
|
+
const workflowsUnderSubagents = import_node_path40.default.join(subagentsRelative, WORKFLOWS_DIR);
|
|
22649
|
+
const located = locateAgents(fs16, configDir, subagentsRelative, void 0, report);
|
|
22650
|
+
for (const runDir of listDirOrReport(fs16, configDir, workflowsUnderSubagents, report)) {
|
|
22617
22651
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
22618
|
-
located.push(...locateAgents(
|
|
22652
|
+
located.push(...locateAgents(fs16, configDir, import_node_path40.default.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
22619
22653
|
}
|
|
22620
22654
|
}
|
|
22621
22655
|
const agents = /* @__PURE__ */ new Map();
|
|
22622
22656
|
for (const candidate of located) {
|
|
22623
|
-
const text = readFileOrReport(
|
|
22657
|
+
const text = readFileOrReport(fs16, configDir, candidate.metaPath, report);
|
|
22624
22658
|
if (text === void 0) {
|
|
22625
22659
|
continue;
|
|
22626
22660
|
}
|
|
@@ -22632,7 +22666,7 @@ function readSessionAgentTree(fs15, configDir, ref, options = {}) {
|
|
|
22632
22666
|
agents.set(candidate.id, { located: candidate, meta: parsed.data });
|
|
22633
22667
|
}
|
|
22634
22668
|
const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
|
|
22635
|
-
const parentOf3 = resolveParents(
|
|
22669
|
+
const parentOf3 = resolveParents(fs16, configDir, agents, report);
|
|
22636
22670
|
const childrenOf = /* @__PURE__ */ new Map();
|
|
22637
22671
|
const roots = [];
|
|
22638
22672
|
for (const id of agents.keys()) {
|
|
@@ -22655,12 +22689,12 @@ function readSessionAgentTree(fs15, configDir, ref, options = {}) {
|
|
|
22655
22689
|
sessionId: ref.sessionId,
|
|
22656
22690
|
superseded: ref.superseded,
|
|
22657
22691
|
agents: roots.sort().map(build),
|
|
22658
|
-
tasks: readTasks(
|
|
22659
|
-
workflowRuns: readWorkflowRuns(
|
|
22692
|
+
tasks: readTasks(fs16, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
|
|
22693
|
+
workflowRuns: readWorkflowRuns(fs16, configDir, import_node_path40.default.join(sessionRelative, WORKFLOWS_DIR), report),
|
|
22660
22694
|
problems
|
|
22661
22695
|
};
|
|
22662
22696
|
}
|
|
22663
|
-
function resolveParents(
|
|
22697
|
+
function resolveParents(fs16, configDir, agents, report) {
|
|
22664
22698
|
const parentOf3 = /* @__PURE__ */ new Map();
|
|
22665
22699
|
const transcriptCache = /* @__PURE__ */ new Map();
|
|
22666
22700
|
const transcriptOf = (agent) => {
|
|
@@ -22668,7 +22702,7 @@ function resolveParents(fs15, configDir, agents, report) {
|
|
|
22668
22702
|
if (cached !== void 0) {
|
|
22669
22703
|
return cached;
|
|
22670
22704
|
}
|
|
22671
|
-
const text = readFileOrReport(
|
|
22705
|
+
const text = readFileOrReport(fs16, configDir, agent.located.transcriptPath, report) ?? "";
|
|
22672
22706
|
transcriptCache.set(agent.located.id, text);
|
|
22673
22707
|
return text;
|
|
22674
22708
|
};
|
|
@@ -22718,16 +22752,16 @@ function resolveParents(fs15, configDir, agents, report) {
|
|
|
22718
22752
|
function ownTaskLists(sessionId) {
|
|
22719
22753
|
return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
|
|
22720
22754
|
}
|
|
22721
|
-
function readTasks(
|
|
22755
|
+
function readTasks(fs16, configDir, ownLists, sharedLists, report) {
|
|
22722
22756
|
const tasks = [];
|
|
22723
22757
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
22724
|
-
const relativeDir =
|
|
22725
|
-
for (const name of [...listDirOrReport(
|
|
22758
|
+
const relativeDir = import_node_path40.default.join(TASKS_DIR, scope);
|
|
22759
|
+
for (const name of [...listDirOrReport(fs16, configDir, relativeDir, report)].sort()) {
|
|
22726
22760
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
22727
22761
|
continue;
|
|
22728
22762
|
}
|
|
22729
|
-
const relative =
|
|
22730
|
-
const text = readFileOrReport(
|
|
22763
|
+
const relative = import_node_path40.default.join(relativeDir, name);
|
|
22764
|
+
const text = readFileOrReport(fs16, configDir, relative, report);
|
|
22731
22765
|
const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
22732
22766
|
if (parsed.success) {
|
|
22733
22767
|
tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
|
|
@@ -22738,14 +22772,14 @@ function readTasks(fs15, configDir, ownLists, sharedLists, report) {
|
|
|
22738
22772
|
});
|
|
22739
22773
|
return tasks;
|
|
22740
22774
|
}
|
|
22741
|
-
function readWorkflowRuns(
|
|
22775
|
+
function readWorkflowRuns(fs16, configDir, relativeDir, report) {
|
|
22742
22776
|
const runs = [];
|
|
22743
|
-
for (const name of [...listDirOrReport(
|
|
22777
|
+
for (const name of [...listDirOrReport(fs16, configDir, relativeDir, report)].sort()) {
|
|
22744
22778
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
22745
22779
|
continue;
|
|
22746
22780
|
}
|
|
22747
|
-
const relative =
|
|
22748
|
-
const text = readFileOrReport(
|
|
22781
|
+
const relative = import_node_path40.default.join(relativeDir, name);
|
|
22782
|
+
const text = readFileOrReport(fs16, configDir, relative, report);
|
|
22749
22783
|
const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
22750
22784
|
if (!parsed.success) {
|
|
22751
22785
|
if (text !== void 0) {
|
|
@@ -22760,7 +22794,7 @@ function readWorkflowRuns(fs15, configDir, relativeDir, report) {
|
|
|
22760
22794
|
}
|
|
22761
22795
|
|
|
22762
22796
|
// src/agents/sessions.ts
|
|
22763
|
-
var
|
|
22797
|
+
var import_node_path41 = __toESM(require("node:path"), 1);
|
|
22764
22798
|
init_cliError();
|
|
22765
22799
|
var SessionLookupError = class extends CliError {
|
|
22766
22800
|
constructor(message) {
|
|
@@ -22769,13 +22803,13 @@ var SessionLookupError = class extends CliError {
|
|
|
22769
22803
|
}
|
|
22770
22804
|
};
|
|
22771
22805
|
function identityConfigDir(identitiesDir, identity) {
|
|
22772
|
-
return
|
|
22806
|
+
return import_node_path41.default.join(identitiesDir, identity);
|
|
22773
22807
|
}
|
|
22774
|
-
function historyStores(
|
|
22808
|
+
function historyStores(fs16, identitiesDir, identities) {
|
|
22775
22809
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
22776
22810
|
for (const identity of identities) {
|
|
22777
22811
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
22778
|
-
const real =
|
|
22812
|
+
const real = fs16.realpath(import_node_path41.default.join(configDir, "projects"));
|
|
22779
22813
|
if (real === void 0) {
|
|
22780
22814
|
continue;
|
|
22781
22815
|
}
|
|
@@ -22788,15 +22822,15 @@ function historyStores(fs15, identitiesDir, identities) {
|
|
|
22788
22822
|
}
|
|
22789
22823
|
return [...byRealPath.values()];
|
|
22790
22824
|
}
|
|
22791
|
-
function collectSessionList(
|
|
22825
|
+
function collectSessionList(fs16, identitiesDir, identities, filters) {
|
|
22792
22826
|
const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
|
|
22793
22827
|
if (filters.identity !== void 0 && names.length === 0) {
|
|
22794
22828
|
throw new SessionLookupError(`no identity named "${filters.identity}"`);
|
|
22795
22829
|
}
|
|
22796
22830
|
const sessions = [];
|
|
22797
|
-
for (const store of historyStores(
|
|
22798
|
-
for (const ref of listSessions2(
|
|
22799
|
-
const summary = summariseSession(
|
|
22831
|
+
for (const store of historyStores(fs16, identitiesDir, names)) {
|
|
22832
|
+
for (const ref of listSessions2(fs16, store.configDir)) {
|
|
22833
|
+
const summary = summariseSession(fs16, store.configDir, ref);
|
|
22800
22834
|
if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
|
|
22801
22835
|
sessions.push({ ...summary, identities: store.identities });
|
|
22802
22836
|
}
|
|
@@ -22804,14 +22838,14 @@ function collectSessionList(fs15, identitiesDir, identities, filters) {
|
|
|
22804
22838
|
}
|
|
22805
22839
|
return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
|
|
22806
22840
|
}
|
|
22807
|
-
function locateSession(
|
|
22841
|
+
function locateSession(fs16, identitiesDir, identities, query, onlyIdentity) {
|
|
22808
22842
|
const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
|
|
22809
22843
|
if (onlyIdentity !== void 0 && names.length === 0) {
|
|
22810
22844
|
throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
|
|
22811
22845
|
}
|
|
22812
22846
|
const matches = [];
|
|
22813
|
-
for (const store of historyStores(
|
|
22814
|
-
for (const ref of listSessions2(
|
|
22847
|
+
for (const store of historyStores(fs16, identitiesDir, names)) {
|
|
22848
|
+
for (const ref of listSessions2(fs16, store.configDir)) {
|
|
22815
22849
|
if (ref.sessionId.startsWith(query)) {
|
|
22816
22850
|
matches.push({ identities: store.identities, configDir: store.configDir, ref });
|
|
22817
22851
|
}
|
|
@@ -22828,19 +22862,19 @@ function locateSession(fs15, identitiesDir, identities, query, onlyIdentity) {
|
|
|
22828
22862
|
}
|
|
22829
22863
|
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
22864
|
}
|
|
22831
|
-
function showSession(
|
|
22832
|
-
const located = locateSession(
|
|
22833
|
-
return { identities: located.identities, tree: readSessionAgentTree(
|
|
22865
|
+
function showSession(fs16, identitiesDir, identities, query, onlyIdentity) {
|
|
22866
|
+
const located = locateSession(fs16, identitiesDir, identities, query, onlyIdentity);
|
|
22867
|
+
return { identities: located.identities, tree: readSessionAgentTree(fs16, located.configDir, located.ref) };
|
|
22834
22868
|
}
|
|
22835
22869
|
|
|
22836
22870
|
// src/agents/realFs.ts
|
|
22837
|
-
var
|
|
22871
|
+
var import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
22838
22872
|
init_realPorts();
|
|
22839
22873
|
var realSessionFs = {
|
|
22840
22874
|
...realFarmFs,
|
|
22841
22875
|
realpath: (candidate) => {
|
|
22842
22876
|
try {
|
|
22843
|
-
return
|
|
22877
|
+
return import_node_fs13.default.realpathSync(candidate);
|
|
22844
22878
|
} catch {
|
|
22845
22879
|
return void 0;
|
|
22846
22880
|
}
|