claude-use 11.7.0 → 11.8.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 CHANGED
@@ -27201,10 +27201,10 @@ var init_schema = __esm({
27201
27201
  });
27202
27202
 
27203
27203
  // src/frontdoor/state.ts
27204
- function readFrontDoorState(fs23, stateFile) {
27204
+ function readFrontDoorState(fs24, stateFile) {
27205
27205
  let raw;
27206
27206
  try {
27207
- raw = fs23.readFileUtf8(stateFile);
27207
+ raw = fs24.readFileUtf8(stateFile);
27208
27208
  } catch {
27209
27209
  return void 0;
27210
27210
  }
@@ -27218,9 +27218,9 @@ function readFrontDoorState(fs23, stateFile) {
27218
27218
  return void 0;
27219
27219
  }
27220
27220
  }
27221
- function writeFrontDoorState(fs23, stateFile, state) {
27222
- fs23.mkdirp(import_node_path5.default.dirname(stateFile));
27223
- fs23.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
27221
+ function writeFrontDoorState(fs24, stateFile, state) {
27222
+ fs24.mkdirp(import_node_path5.default.dirname(stateFile));
27223
+ fs24.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
27224
27224
  `);
27225
27225
  }
27226
27226
  function directOrigin(port) {
@@ -27230,27 +27230,27 @@ function frontDoorOrigin(state) {
27230
27230
  const port = state?.directPort ?? state?.lastDirectPort;
27231
27231
  return port === void 0 ? void 0 : directOrigin(port);
27232
27232
  }
27233
- function writeFrontDoorDirectRecord(fs23, recordsDir, record2) {
27234
- fs23.mkdirp(recordsDir);
27235
- fs23.writeFilePrivate(import_node_path5.default.join(recordsDir, `${String(record2.pid)}.json`), `${JSON.stringify({ directPort: record2.directPort })}
27233
+ function writeFrontDoorDirectRecord(fs24, recordsDir, record2) {
27234
+ fs24.mkdirp(recordsDir);
27235
+ fs24.writeFilePrivate(import_node_path5.default.join(recordsDir, `${String(record2.pid)}.json`), `${JSON.stringify({ directPort: record2.directPort })}
27236
27236
  `);
27237
27237
  }
27238
- function removeFrontDoorDirectRecord(fs23, recordsDir, pid) {
27239
- fs23.removeRecursive(import_node_path5.default.join(recordsDir, `${String(pid)}.json`));
27238
+ function removeFrontDoorDirectRecord(fs24, recordsDir, pid) {
27239
+ fs24.removeRecursive(import_node_path5.default.join(recordsDir, `${String(pid)}.json`));
27240
27240
  }
27241
27241
  function recordPid(file2) {
27242
27242
  const pidText = /^([1-9]\d*)\.json$/.exec(file2)?.[1];
27243
27243
  const pid = pidText === void 0 ? void 0 : Number(pidText);
27244
27244
  return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
27245
27245
  }
27246
- function readDirectRecordEntry(fs23, recordsDir, file2) {
27246
+ function readDirectRecordEntry(fs24, recordsDir, file2) {
27247
27247
  const pid = recordPid(file2);
27248
27248
  if (pid === void 0) {
27249
27249
  return void 0;
27250
27250
  }
27251
27251
  let raw;
27252
27252
  try {
27253
- raw = fs23.readFileUtf8(import_node_path5.default.join(recordsDir, file2));
27253
+ raw = fs24.readFileUtf8(import_node_path5.default.join(recordsDir, file2));
27254
27254
  } catch {
27255
27255
  return void 0;
27256
27256
  }
@@ -27264,44 +27264,44 @@ function readDirectRecordEntry(fs23, recordsDir, file2) {
27264
27264
  return { malformed: true };
27265
27265
  }
27266
27266
  }
27267
- function listFrontDoorDirectRecords(fs23, recordsDir) {
27268
- return fs23.readdir(recordsDir).flatMap((file2) => {
27269
- const entry = readDirectRecordEntry(fs23, recordsDir, file2);
27267
+ function listFrontDoorDirectRecords(fs24, recordsDir) {
27268
+ return fs24.readdir(recordsDir).flatMap((file2) => {
27269
+ const entry = readDirectRecordEntry(fs24, recordsDir, file2);
27270
27270
  return entry?.record === void 0 ? [] : [entry.record];
27271
27271
  }).sort((a10, b) => a10.pid - b.pid);
27272
27272
  }
27273
- function pruneMalformedFrontDoorDirectFiles(fs23, recordsDir, isRunning) {
27274
- for (const file2 of fs23.readdir(recordsDir)) {
27273
+ function pruneMalformedFrontDoorDirectFiles(fs24, recordsDir, isRunning) {
27274
+ for (const file2 of fs24.readdir(recordsDir)) {
27275
27275
  const writer = RECORD_TEMPORARY_FILE.exec(file2)?.[1];
27276
27276
  const stale = writer !== void 0 && !isRunning(Number(writer));
27277
- if (stale || readDirectRecordEntry(fs23, recordsDir, file2)?.malformed === true) {
27278
- fs23.removeRecursive(import_node_path5.default.join(recordsDir, file2));
27277
+ if (stale || readDirectRecordEntry(fs24, recordsDir, file2)?.malformed === true) {
27278
+ fs24.removeRecursive(import_node_path5.default.join(recordsDir, file2));
27279
27279
  }
27280
27280
  }
27281
27281
  }
27282
27282
  function liveFrontDoorDirectRecords(records, liveness) {
27283
27283
  return records.filter((record2) => liveness.doors.has(record2.pid) || liveness.unknown.has(record2.pid));
27284
27284
  }
27285
- function pruneDeadFrontDoorDirectRecords(fs23, recordsDir, records, liveness) {
27285
+ function pruneDeadFrontDoorDirectRecords(fs24, recordsDir, records, liveness) {
27286
27286
  for (const record2 of records) {
27287
27287
  if (!liveness.doors.has(record2.pid) && !liveness.unknown.has(record2.pid)) {
27288
- removeFrontDoorDirectRecord(fs23, recordsDir, record2.pid);
27288
+ removeFrontDoorDirectRecord(fs24, recordsDir, record2.pid);
27289
27289
  }
27290
27290
  }
27291
27291
  }
27292
- function writeFrontDoorSession(fs23, sessionsDir, session) {
27293
- fs23.mkdirPrivate(sessionsDir);
27294
- fs23.writeFilePrivate(import_node_path5.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
27292
+ function writeFrontDoorSession(fs24, sessionsDir, session) {
27293
+ fs24.mkdirPrivate(sessionsDir);
27294
+ fs24.writeFilePrivate(import_node_path5.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
27295
27295
  `);
27296
27296
  }
27297
- function listFrontDoorSessions(fs23, sessionsDir) {
27297
+ function listFrontDoorSessions(fs24, sessionsDir) {
27298
27298
  const sessions = [];
27299
- for (const name of fs23.readdir(sessionsDir)) {
27299
+ for (const name of fs24.readdir(sessionsDir)) {
27300
27300
  if (!name.endsWith(".json")) {
27301
27301
  continue;
27302
27302
  }
27303
27303
  try {
27304
- const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs23.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
27304
+ const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs24.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
27305
27305
  if (parsed.success) {
27306
27306
  sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt, ...parsed.data.supervisorPid === void 0 ? {} : { supervisorPid: parsed.data.supervisorPid } });
27307
27307
  }
@@ -27311,27 +27311,27 @@ function listFrontDoorSessions(fs23, sessionsDir) {
27311
27311
  }
27312
27312
  return sessions.sort((a10, b) => a10.pid - b.pid);
27313
27313
  }
27314
- function removeFrontDoorSession(fs23, sessionsDir, pid) {
27315
- fs23.removeRecursive(import_node_path5.default.join(sessionsDir, `${String(pid)}.json`));
27314
+ function removeFrontDoorSession(fs24, sessionsDir, pid) {
27315
+ fs24.removeRecursive(import_node_path5.default.join(sessionsDir, `${String(pid)}.json`));
27316
27316
  }
27317
- function pruneDeadFrontDoorSessions(fs23, sessionsDir, isRunning) {
27317
+ function pruneDeadFrontDoorSessions(fs24, sessionsDir, isRunning) {
27318
27318
  const removed = [];
27319
- for (const session of listFrontDoorSessions(fs23, sessionsDir)) {
27319
+ for (const session of listFrontDoorSessions(fs24, sessionsDir)) {
27320
27320
  if (!isRunning(session.pid)) {
27321
- removeFrontDoorSession(fs23, sessionsDir, session.pid);
27321
+ removeFrontDoorSession(fs24, sessionsDir, session.pid);
27322
27322
  removed.push(session.pid);
27323
27323
  }
27324
27324
  }
27325
27325
  return removed;
27326
27326
  }
27327
- function liveSessionTokens(fs23, sessionsDir) {
27327
+ function liveSessionTokens(fs24, sessionsDir) {
27328
27328
  const tokens = /* @__PURE__ */ new Set();
27329
- for (const name of fs23.readdir(sessionsDir)) {
27329
+ for (const name of fs24.readdir(sessionsDir)) {
27330
27330
  if (!name.endsWith(".json")) {
27331
27331
  continue;
27332
27332
  }
27333
27333
  try {
27334
- const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs23.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
27334
+ const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs24.readFileUtf8(import_node_path5.default.join(sessionsDir, name)) ?? ""));
27335
27335
  if (parsed.success) {
27336
27336
  tokens.add(parsed.data.token);
27337
27337
  }
@@ -27393,43 +27393,43 @@ function parseJson(raw, schema) {
27393
27393
  const parsed = schema.safeParse(JSON.parse(raw));
27394
27394
  return parsed.success ? parsed.data : void 0;
27395
27395
  }
27396
- function readHeadroomState(fs23, stateFile) {
27396
+ function readHeadroomState(fs24, stateFile) {
27397
27397
  try {
27398
- return parseJson(fs23.readFileUtf8(stateFile), HeadroomStateSchema);
27398
+ return parseJson(fs24.readFileUtf8(stateFile), HeadroomStateSchema);
27399
27399
  } catch {
27400
27400
  return void 0;
27401
27401
  }
27402
27402
  }
27403
- function writeHeadroomState(fs23, stateFile, state) {
27404
- fs23.mkdirp(import_node_path6.default.dirname(stateFile));
27405
- fs23.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
27403
+ function writeHeadroomState(fs24, stateFile, state) {
27404
+ fs24.mkdirp(import_node_path6.default.dirname(stateFile));
27405
+ fs24.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
27406
27406
  `);
27407
27407
  }
27408
- function resolveServingHeadroomState(fs23, files, isRunning) {
27409
- const current = readHeadroomState(fs23, files.stateFile);
27408
+ function resolveServingHeadroomState(fs24, files, isRunning) {
27409
+ const current = readHeadroomState(fs24, files.stateFile);
27410
27410
  if (current !== void 0) {
27411
27411
  return { path: files.stateFile, state: current };
27412
27412
  }
27413
- const legacy = readHeadroomState(fs23, files.legacyStateFile);
27413
+ const legacy = readHeadroomState(fs24, files.legacyStateFile);
27414
27414
  if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
27415
27415
  return { path: files.legacyStateFile, state: legacy };
27416
27416
  }
27417
27417
  return void 0;
27418
27418
  }
27419
- function migrateHeadroomState(fs23, files, isRunning) {
27420
- const legacy = readHeadroomState(fs23, files.legacyStateFile);
27419
+ function migrateHeadroomState(fs24, files, isRunning) {
27420
+ const legacy = readHeadroomState(fs24, files.legacyStateFile);
27421
27421
  const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
27422
- const current = readHeadroomState(fs23, files.stateFile);
27422
+ const current = readHeadroomState(fs24, files.stateFile);
27423
27423
  if (current !== void 0 || legacyLive) {
27424
- if (!legacyLive && fs23.readFileUtf8(files.legacyStateFile) !== void 0) {
27425
- fs23.removeRecursive(files.legacyStateFile);
27424
+ if (!legacyLive && fs24.readFileUtf8(files.legacyStateFile) !== void 0) {
27425
+ fs24.removeRecursive(files.legacyStateFile);
27426
27426
  }
27427
27427
  return;
27428
27428
  }
27429
27429
  if (legacy !== void 0) {
27430
- writeHeadroomState(fs23, files.stateFile, legacy);
27430
+ writeHeadroomState(fs24, files.stateFile, legacy);
27431
27431
  }
27432
- fs23.removeRecursive(files.legacyStateFile);
27432
+ fs24.removeRecursive(files.legacyStateFile);
27433
27433
  }
27434
27434
  function hashAllowlist(allowlist) {
27435
27435
  return (0, import_node_crypto2.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
@@ -27462,27 +27462,27 @@ function isAdmissibleUrl(entry) {
27462
27462
  function parseAllowlistFile(content) {
27463
27463
  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)));
27464
27464
  }
27465
- function writeAllowlistFile(fs23, allowlistFile, allowlist) {
27466
- fs23.mkdirPrivate(import_node_path6.default.dirname(allowlistFile));
27467
- fs23.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
27465
+ function writeAllowlistFile(fs24, allowlistFile, allowlist) {
27466
+ fs24.mkdirPrivate(import_node_path6.default.dirname(allowlistFile));
27467
+ fs24.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
27468
27468
  }
27469
- function pruneStaleAllowlistTemporaries(fs23, allowlistFile, isRunning) {
27469
+ function pruneStaleAllowlistTemporaries(fs24, allowlistFile, isRunning) {
27470
27470
  const prefix = `${import_node_path6.default.basename(allowlistFile)}.`;
27471
- for (const name of fs23.readdir(import_node_path6.default.dirname(allowlistFile))) {
27471
+ for (const name of fs24.readdir(import_node_path6.default.dirname(allowlistFile))) {
27472
27472
  const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
27473
27473
  if (writer !== void 0 && !isRunning(Number(writer))) {
27474
- fs23.removeRecursive(import_node_path6.default.join(import_node_path6.default.dirname(allowlistFile), name));
27474
+ fs24.removeRecursive(import_node_path6.default.join(import_node_path6.default.dirname(allowlistFile), name));
27475
27475
  }
27476
27476
  }
27477
27477
  }
27478
- function readAllProviders(fs23, providersDir) {
27478
+ function readAllProviders(fs24, providersDir) {
27479
27479
  const result = [];
27480
- for (const name of fs23.readdir(providersDir)) {
27480
+ for (const name of fs24.readdir(providersDir)) {
27481
27481
  if (!name.endsWith(".json")) {
27482
27482
  continue;
27483
27483
  }
27484
27484
  try {
27485
- const parsed = parseJson(fs23.readFileUtf8(import_node_path6.default.join(providersDir, name)), ProviderSchema);
27485
+ const parsed = parseJson(fs24.readFileUtf8(import_node_path6.default.join(providersDir, name)), ProviderSchema);
27486
27486
  if (parsed !== void 0) {
27487
27487
  result.push({ name: name.slice(0, -".json".length), provider: parsed });
27488
27488
  }
@@ -27492,22 +27492,22 @@ function readAllProviders(fs23, providersDir) {
27492
27492
  }
27493
27493
  return result;
27494
27494
  }
27495
- function writeSession(fs23, sessionsDir, session) {
27496
- fs23.mkdirp(sessionsDir);
27497
- fs23.writeFileUtf8(import_node_path6.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
27495
+ function writeSession(fs24, sessionsDir, session) {
27496
+ fs24.mkdirp(sessionsDir);
27497
+ fs24.writeFileUtf8(import_node_path6.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
27498
27498
  `);
27499
27499
  }
27500
- function removeSession(fs23, sessionsDir, pid) {
27501
- fs23.removeRecursive(import_node_path6.default.join(sessionsDir, `${String(pid)}.json`));
27500
+ function removeSession(fs24, sessionsDir, pid) {
27501
+ fs24.removeRecursive(import_node_path6.default.join(sessionsDir, `${String(pid)}.json`));
27502
27502
  }
27503
- function listSessions(fs23, sessionsDir) {
27503
+ function listSessions(fs24, sessionsDir) {
27504
27504
  const sessions = [];
27505
- for (const name of fs23.readdir(sessionsDir)) {
27505
+ for (const name of fs24.readdir(sessionsDir)) {
27506
27506
  if (!name.endsWith(".json")) {
27507
27507
  continue;
27508
27508
  }
27509
27509
  try {
27510
- const parsed = parseJson(fs23.readFileUtf8(import_node_path6.default.join(sessionsDir, name)), HeadroomSessionSchema);
27510
+ const parsed = parseJson(fs24.readFileUtf8(import_node_path6.default.join(sessionsDir, name)), HeadroomSessionSchema);
27511
27511
  if (parsed !== void 0) {
27512
27512
  sessions.push(parsed);
27513
27513
  }
@@ -27517,22 +27517,22 @@ function listSessions(fs23, sessionsDir) {
27517
27517
  }
27518
27518
  return sessions.sort((a10, b) => a10.pid - b.pid);
27519
27519
  }
27520
- function sessionsForSupervisor(fs23, sessionsDir, supervisorPid) {
27521
- return listSessions(fs23, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
27520
+ function sessionsForSupervisor(fs24, sessionsDir, supervisorPid) {
27521
+ return listSessions(fs24, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
27522
27522
  }
27523
- function pruneDeadSessions(fs23, sessionsDir, isRunning) {
27523
+ function pruneDeadSessions(fs24, sessionsDir, isRunning) {
27524
27524
  const removed = [];
27525
- for (const session of listSessions(fs23, sessionsDir)) {
27525
+ for (const session of listSessions(fs24, sessionsDir)) {
27526
27526
  if (!isRunning(session.pid)) {
27527
- removeSession(fs23, sessionsDir, session.pid);
27527
+ removeSession(fs24, sessionsDir, session.pid);
27528
27528
  removed.push(session.pid);
27529
27529
  }
27530
27530
  }
27531
27531
  return removed;
27532
27532
  }
27533
- function readStartLock(fs23, lockFile) {
27533
+ function readStartLock(fs24, lockFile) {
27534
27534
  try {
27535
- return parseJson(fs23.readFileUtf8(lockFile), HeadroomLockSchema);
27535
+ return parseJson(fs24.readFileUtf8(lockFile), HeadroomLockSchema);
27536
27536
  } catch {
27537
27537
  return void 0;
27538
27538
  }
@@ -27625,12 +27625,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
27625
27625
  }
27626
27626
  return hashAllowlist([...entries].sort());
27627
27627
  }
27628
- function earlierReleaseDaemon(fs23, paths, daemon) {
27628
+ function earlierReleaseDaemon(fs24, paths, daemon) {
27629
27629
  if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
27630
27630
  return void 0;
27631
27631
  }
27632
- const providers = readAllProviders(fs23, paths.providersDir).map((entry) => entry.provider);
27633
- const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs23, paths.frontdoorStateFile)));
27632
+ const providers = readAllProviders(fs24, paths.providersDir).map((entry) => entry.provider);
27633
+ const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs24, paths.frontdoorStateFile)));
27634
27634
  return { admitsServingDoor: daemon.recordedHash === expected };
27635
27635
  }
27636
27636
  var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
@@ -27655,8 +27655,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
27655
27655
  }
27656
27656
  return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
27657
27657
  }
27658
- function daemonAdmits(fs23, allowlistFile, recordedHash, required2) {
27659
- const content = fs23.readFileUtf8(allowlistFile);
27658
+ function daemonAdmits(fs24, allowlistFile, recordedHash, required2) {
27659
+ const content = fs24.readFileUtf8(allowlistFile);
27660
27660
  if (content === void 0 || recordedHash === void 0) {
27661
27661
  return false;
27662
27662
  }
@@ -28046,7 +28046,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
28046
28046
  const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
28047
28047
  return { message: refusal2, repairable: replaceable };
28048
28048
  }
28049
- function prepareHeadroomSocket(fs23, ports, paths, supervisorPid) {
28049
+ function prepareHeadroomSocket(fs24, ports, paths, supervisorPid) {
28050
28050
  const unsupported = platformRefusal(ports.platform);
28051
28051
  if (unsupported !== void 0) {
28052
28052
  return { refused: unsupported };
@@ -28061,18 +28061,18 @@ function prepareHeadroomSocket(fs23, ports, paths, supervisorPid) {
28061
28061
  if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
28062
28062
  return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
28063
28063
  }
28064
- fs23.mkdirPrivate(paths.headroomSocketDir);
28064
+ fs24.mkdirPrivate(paths.headroomSocketDir);
28065
28065
  const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
28066
28066
  return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
28067
28067
  }
28068
- function pruneStaleHeadroomSockets(fs23, paths, isRunning) {
28068
+ function pruneStaleHeadroomSockets(fs24, paths, isRunning) {
28069
28069
  const removed = [];
28070
- for (const name of fs23.readdir(paths.headroomSocketDir)) {
28070
+ for (const name of fs24.readdir(paths.headroomSocketDir)) {
28071
28071
  const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
28072
28072
  if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
28073
28073
  continue;
28074
28074
  }
28075
- fs23.removeRecursive(import_node_path7.default.join(paths.headroomSocketDir, name));
28075
+ fs24.removeRecursive(import_node_path7.default.join(paths.headroomSocketDir, name));
28076
28076
  removed.push(name);
28077
28077
  }
28078
28078
  return removed;
@@ -28219,37 +28219,37 @@ function compareVersions2(a10, b) {
28219
28219
  return 0;
28220
28220
  }
28221
28221
  async function runSupervisor(initialConfig, ports, options = {}) {
28222
- const { fs: fs23, paths } = ports;
28222
+ const { fs: fs24, paths } = ports;
28223
28223
  let config2 = initialConfig;
28224
- migrateHeadroomState(fs23, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
28225
- const previousState = resolveServingHeadroomState(fs23, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
28224
+ migrateHeadroomState(fs24, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
28225
+ const previousState = resolveServingHeadroomState(fs24, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
28226
28226
  if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
28227
28227
  ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
28228
28228
  return 0;
28229
28229
  }
28230
28230
  let installedSource = previousState?.installedSource;
28231
28231
  const ownsState = () => {
28232
- const owner = readHeadroomState(fs23, paths.headroomStateFile)?.supervisorPid;
28232
+ const owner = readHeadroomState(fs24, paths.headroomStateFile)?.supervisorPid;
28233
28233
  return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
28234
28234
  };
28235
28235
  const writeOwnState = (state) => {
28236
28236
  if (!ownsState()) {
28237
28237
  return false;
28238
28238
  }
28239
- writeHeadroomState(fs23, paths.headroomStateFile, state);
28239
+ writeHeadroomState(fs24, paths.headroomStateFile, state);
28240
28240
  return true;
28241
28241
  };
28242
28242
  const fail = (message) => {
28243
28243
  if (writeOwnState({ lastError: message })) {
28244
- fs23.removeRecursive(paths.headroomLockFile);
28244
+ fs24.removeRecursive(paths.headroomLockFile);
28245
28245
  }
28246
28246
  ports.log(`agent-shim headroom supervisor: ${message}`);
28247
28247
  return 1;
28248
28248
  };
28249
28249
  const syncAllowlistFile = (allowlist) => {
28250
28250
  try {
28251
- if (fs23.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
28252
- writeAllowlistFile(fs23, paths.headroomAllowlistFile, allowlist);
28251
+ if (fs24.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
28252
+ writeAllowlistFile(fs24, paths.headroomAllowlistFile, allowlist);
28253
28253
  ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
28254
28254
  }
28255
28255
  return void 0;
@@ -28267,9 +28267,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
28267
28267
  }
28268
28268
  ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
28269
28269
  try {
28270
- fs23.mkdirPrivate(paths.headroomDir);
28271
- fs23.mkdirPrivate(import_node_path8.default.dirname(paths.headroomAllowlistFile));
28272
- writeAllowlistFile(fs23, paths.headroomAllowlistFile, allowlist);
28270
+ fs24.mkdirPrivate(paths.headroomDir);
28271
+ fs24.mkdirPrivate(import_node_path8.default.dirname(paths.headroomAllowlistFile));
28272
+ writeAllowlistFile(fs24, paths.headroomAllowlistFile, allowlist);
28273
28273
  } catch (error63) {
28274
28274
  return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error63 instanceof Error ? error63.message : String(error63)}`;
28275
28275
  }
@@ -28294,20 +28294,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
28294
28294
  installedSource = config2.source;
28295
28295
  return void 0;
28296
28296
  };
28297
- const socket = prepareHeadroomSocket(fs23, ports.socketTrust, paths, ports.ownPid);
28297
+ const socket = prepareHeadroomSocket(fs24, ports.socketTrust, paths, ports.ownPid);
28298
28298
  if (socket.refused !== void 0) {
28299
28299
  return fail(socket.refused);
28300
28300
  }
28301
28301
  const { socketPath } = socket;
28302
- pruneStaleHeadroomSockets(fs23, paths, ports.isRunning);
28303
- pruneStaleAllowlistTemporaries(fs23, paths.headroomAllowlistFile, ports.isRunning);
28302
+ pruneStaleHeadroomSockets(fs24, paths, ports.isRunning);
28303
+ pruneStaleAllowlistTemporaries(fs24, paths.headroomAllowlistFile, ports.isRunning);
28304
28304
  const installFailure = ensureInstalled();
28305
28305
  if (installFailure !== void 0) {
28306
28306
  return fail(installFailure);
28307
28307
  }
28308
28308
  const version2 = ports.headroomVersion() ?? "unknown";
28309
28309
  writeOwnState({ supervisorPid: ports.ownPid, version: version2, installedSource });
28310
- ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs23, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
28310
+ ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs24, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
28311
28311
  const orphanPid = previousState?.headroomPid;
28312
28312
  const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
28313
28313
  const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
@@ -28342,12 +28342,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
28342
28342
  ticks += 1;
28343
28343
  config2 = ports.readConfig();
28344
28344
  const settingsHash = hashSettings(config2.settings);
28345
- const inputs = currentHeadroomAllowlistInputs(fs23, paths, ports.frontDoorLiveness);
28346
- pruneDeadFrontDoorDirectRecords(fs23, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
28347
- pruneMalformedFrontDoorDirectFiles(fs23, paths.frontdoorDirectRecordsDir, ports.isRunning);
28345
+ const inputs = currentHeadroomAllowlistInputs(fs24, paths, ports.frontDoorLiveness);
28346
+ pruneDeadFrontDoorDirectRecords(fs24, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
28347
+ pruneMalformedFrontDoorDirectFiles(fs24, paths.frontdoorDirectRecordsDir, ports.isRunning);
28348
28348
  const allowlist = inputs.frontDoorOrigins;
28349
28349
  const allowlistHash = hashAllowlist(allowlist);
28350
- pruneDeadSessions(fs23, paths.headroomSessionsDir, ports.isRunning);
28350
+ pruneDeadSessions(fs24, paths.headroomSessionsDir, ports.isRunning);
28351
28351
  const ownsNow = ownsState();
28352
28352
  if (!ownsNow && !superseded) {
28353
28353
  ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
@@ -28394,7 +28394,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
28394
28394
  runningSettingsHash = settingsHash;
28395
28395
  const recorded = writeOwnState(servingState(pid));
28396
28396
  if (recorded) {
28397
- fs23.removeRecursive(paths.headroomLockFile);
28397
+ fs24.removeRecursive(paths.headroomLockFile);
28398
28398
  }
28399
28399
  idleSince = void 0;
28400
28400
  ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
@@ -28422,7 +28422,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
28422
28422
  ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
28423
28423
  }
28424
28424
  if (runningSettingsHash !== settingsHash || installedSource !== config2.source) {
28425
- if (sessionsForSupervisor(fs23, paths.headroomSessionsDir, ports.ownPid).length === 0) {
28425
+ if (sessionsForSupervisor(fs24, paths.headroomSessionsDir, ports.ownPid).length === 0) {
28426
28426
  ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
28427
28427
  ports.stopProcess(headroomPid);
28428
28428
  headroomPid = void 0;
@@ -28431,7 +28431,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
28431
28431
  continue;
28432
28432
  }
28433
28433
  }
28434
- const sessions = sessionsForSupervisor(fs23, paths.headroomSessionsDir, ports.ownPid);
28434
+ const sessions = sessionsForSupervisor(fs24, paths.headroomSessionsDir, ports.ownPid);
28435
28435
  if (sessions.length === 0) {
28436
28436
  idleSince ??= ports.now();
28437
28437
  const idleMs = ports.now() - idleSince;
@@ -28456,9 +28456,9 @@ function undeterminedFrontDoors(inputs) {
28456
28456
  return reason === void 0 ? [] : [{ pid: record2.pid, origin: directOrigin(record2.directPort), reason }];
28457
28457
  });
28458
28458
  }
28459
- function currentHeadroomAllowlistInputs(fs23, paths, frontDoorLiveness) {
28460
- const named = frontDoorOrigin(readFrontDoorState(fs23, paths.frontdoorStateFile));
28461
- const records = listFrontDoorDirectRecords(fs23, paths.frontdoorDirectRecordsDir);
28459
+ function currentHeadroomAllowlistInputs(fs24, paths, frontDoorLiveness) {
28460
+ const named = frontDoorOrigin(readFrontDoorState(fs24, paths.frontdoorStateFile));
28461
+ const records = listFrontDoorDirectRecords(fs24, paths.frontdoorDirectRecordsDir);
28462
28462
  const liveness = frontDoorLiveness(records.map((record2) => record2.pid));
28463
28463
  const live = liveFrontDoorDirectRecords(records, liveness).map((record2) => directOrigin(record2.directPort));
28464
28464
  return {
@@ -28467,8 +28467,8 @@ function currentHeadroomAllowlistInputs(fs23, paths, frontDoorLiveness) {
28467
28467
  frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
28468
28468
  };
28469
28469
  }
28470
- function launchRequiredUpstreams(fs23, paths) {
28471
- const door = frontDoorOrigin(readFrontDoorState(fs23, paths.frontdoorStateFile));
28470
+ function launchRequiredUpstreams(fs24, paths) {
28471
+ const door = frontDoorOrigin(readFrontDoorState(fs24, paths.frontdoorStateFile));
28472
28472
  return door === void 0 ? [] : [door];
28473
28473
  }
28474
28474
  async function waitUntilReady(ports, socketPath, pid) {
@@ -31299,8 +31299,8 @@ var init_classify = __esm({
31299
31299
  function poolNameOf(selector) {
31300
31300
  return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
31301
31301
  }
31302
- function readActiveIdentity(fs23, activeIdentityFile) {
31303
- const trimmed = fs23.readFileUtf8(activeIdentityFile)?.trim();
31302
+ function readActiveIdentity(fs24, activeIdentityFile) {
31303
+ const trimmed = fs24.readFileUtf8(activeIdentityFile)?.trim();
31304
31304
  return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
31305
31305
  }
31306
31306
  function isNonEmpty(value2) {
@@ -31347,8 +31347,8 @@ function decideConfigProfile(params) {
31347
31347
  }
31348
31348
  return { source: "none" };
31349
31349
  }
31350
- function loadIdentity(identitiesDir, name, fs23) {
31351
- return loadConfigFile(import_node_path11.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs23.readConfigFile);
31350
+ function loadIdentity(identitiesDir, name, fs24) {
31351
+ return loadConfigFile(import_node_path11.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs24.readConfigFile);
31352
31352
  }
31353
31353
  var import_node_path11, IDENTITY_DECISION_SOURCES, CONFIG_PROFILE_DECISION_SOURCES;
31354
31354
  var init_identity = __esm({
@@ -32752,8 +32752,8 @@ var init_pipeline = __esm({
32752
32752
  });
32753
32753
 
32754
32754
  // src/launcher/farm.ts
32755
- function readFarmManifest(fs23, farmRoot) {
32756
- const raw = fs23.readFileUtf8(import_node_path19.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs23.readFileUtf8(import_node_path19.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
32755
+ function readFarmManifest(fs24, farmRoot) {
32756
+ const raw = fs24.readFileUtf8(import_node_path19.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs24.readFileUtf8(import_node_path19.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
32757
32757
  if (raw === void 0) {
32758
32758
  return void 0;
32759
32759
  }
@@ -32811,9 +32811,9 @@ function buildEntryFacts(params) {
32811
32811
  entries
32812
32812
  };
32813
32813
  }
32814
- function listSubtree(fs23, root, rel) {
32814
+ function listSubtree(fs24, root, rel) {
32815
32815
  const absolute = import_node_path19.default.join(root, rel);
32816
- const stat = fs23.lstat(absolute);
32816
+ const stat = fs24.lstat(absolute);
32817
32817
  if (stat === void 0) {
32818
32818
  return [];
32819
32819
  }
@@ -32821,10 +32821,10 @@ function listSubtree(fs23, root, rel) {
32821
32821
  return [{ rel, kind: "symlink" }];
32822
32822
  }
32823
32823
  if (stat.kind === "dir") {
32824
- const children = [...fs23.readdir(absolute)].sort().flatMap((name) => listSubtree(fs23, root, `${rel}/${name}`));
32824
+ const children = [...fs24.readdir(absolute)].sort().flatMap((name) => listSubtree(fs24, root, `${rel}/${name}`));
32825
32825
  return [{ rel, kind: "dir" }, ...children];
32826
32826
  }
32827
- const contentHash = fs23.hashFile(absolute);
32827
+ const contentHash = fs24.hashFile(absolute);
32828
32828
  return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
32829
32829
  }
32830
32830
  function topLevelScopeRoots(roots) {
@@ -32838,25 +32838,25 @@ function topLevelScopeRoots(roots) {
32838
32838
  }
32839
32839
  return kept;
32840
32840
  }
32841
- function reconciliationScope(fs23, farmRoot, manifest) {
32841
+ function reconciliationScope(fs24, farmRoot, manifest) {
32842
32842
  if (manifest !== void 0) {
32843
32843
  return topLevelScopeRoots(manifest.materialised);
32844
32844
  }
32845
- return [...fs23.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs23.lstat(import_node_path19.default.join(farmRoot, name))?.kind === "dir").sort();
32845
+ return [...fs24.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs24.lstat(import_node_path19.default.join(farmRoot, name))?.kind === "dir").sort();
32846
32846
  }
32847
- function collectFarmListing(fs23, farmRoot, scopeRoots) {
32848
- return scopeRoots.flatMap((root) => listSubtree(fs23, farmRoot, root));
32847
+ function collectFarmListing(fs24, farmRoot, scopeRoots) {
32848
+ return scopeRoots.flatMap((root) => listSubtree(fs24, farmRoot, root));
32849
32849
  }
32850
- function collectCanonicalCounterparts(fs23, claudeHome, farmListing) {
32850
+ function collectCanonicalCounterparts(fs24, claudeHome, farmListing) {
32851
32851
  const out = [];
32852
32852
  for (const entry of farmListing) {
32853
32853
  const absolute = import_node_path19.default.join(claudeHome, entry.rel);
32854
- const stat = fs23.lstat(absolute);
32854
+ const stat = fs24.lstat(absolute);
32855
32855
  if (stat === void 0) {
32856
32856
  continue;
32857
32857
  }
32858
32858
  if (stat.kind === "file") {
32859
- const contentHash = fs23.hashFile(absolute);
32859
+ const contentHash = fs24.hashFile(absolute);
32860
32860
  out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
32861
32861
  continue;
32862
32862
  }
@@ -34007,7 +34007,7 @@ var init_package = __esm({
34007
34007
  "package.json"() {
34008
34008
  package_default = {
34009
34009
  name: "claude-use",
34010
- version: "11.7.0",
34010
+ version: "11.8.1",
34011
34011
  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.",
34012
34012
  license: "MIT",
34013
34013
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -34120,12 +34120,12 @@ function isIdentityName(name) {
34120
34120
  function claudeJsonPath(identitiesDir, identity) {
34121
34121
  return import_node_path24.default.join(identitiesDir, identity, CLAUDE_JSON);
34122
34122
  }
34123
- function readAccountMetadata(fs23, identitiesDir, identity) {
34123
+ function readAccountMetadata(fs24, identitiesDir, identity) {
34124
34124
  if (!isIdentityName(identity)) {
34125
34125
  throw new Error(`"${identity}" is not a valid identity name.`);
34126
34126
  }
34127
34127
  const file2 = claudeJsonPath(identitiesDir, identity);
34128
- const raw = fs23.readFileUtf8(file2);
34128
+ const raw = fs24.readFileUtf8(file2);
34129
34129
  if (raw === void 0) {
34130
34130
  return void 0;
34131
34131
  }
@@ -34155,19 +34155,19 @@ function readAccountMetadata(fs23, identitiesDir, identity) {
34155
34155
  }
34156
34156
  return account.data;
34157
34157
  }
34158
- function createAccountReader(fs23, identitiesDir) {
34158
+ function createAccountReader(fs24, identitiesDir) {
34159
34159
  const cache = /* @__PURE__ */ new Map();
34160
34160
  return (identity) => {
34161
34161
  if (!isIdentityName(identity)) {
34162
34162
  throw new Error(`"${identity}" is not a valid identity name.`);
34163
34163
  }
34164
- const stat = fs23.lstat(claudeJsonPath(identitiesDir, identity));
34164
+ const stat = fs24.lstat(claudeJsonPath(identitiesDir, identity));
34165
34165
  const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
34166
34166
  const cached2 = cache.get(identity);
34167
34167
  if (cached2?.stamp === stamp) {
34168
34168
  return cached2.account;
34169
34169
  }
34170
- const account = readAccountMetadata(fs23, identitiesDir, identity);
34170
+ const account = readAccountMetadata(fs24, identitiesDir, identity);
34171
34171
  cache.set(identity, { stamp, account });
34172
34172
  return account;
34173
34173
  };
@@ -34289,10 +34289,11 @@ function parseProviderPath(path59) {
34289
34289
  }
34290
34290
  return { provider: decodeURIComponent(tail.slice(0, slash)), rest: tail.slice(slash) };
34291
34291
  }
34292
- var INTERNAL_HEADER_NAMES, IDENTITY_HEADER, SESSION_HEADER, PROVIDER_HEADER, HEADROOM_FLAG_HEADER, PROJECT_ID_HEADER, SESSION_ATTRIBUTION_HEADER, HEADROOM_BASE_URL_HEADER, AUTH_HEADER, HOP_SECRET_HEADER, HOP_ID_HEADER, PROVIDER_PATH_PREFIX;
34292
+ var HEADROOM_SESSION_HEADER, INTERNAL_HEADER_NAMES, IDENTITY_HEADER, SESSION_HEADER, PROVIDER_HEADER, HEADROOM_FLAG_HEADER, PROJECT_ID_HEADER, CLIENT_SESSION_HEADER, HEADROOM_BASE_URL_HEADER, AUTH_HEADER, HOP_SECRET_HEADER, HOP_ID_HEADER, PROVIDER_PATH_PREFIX;
34293
34293
  var init_route = __esm({
34294
34294
  "src/frontdoor/route.ts"() {
34295
34295
  "use strict";
34296
+ HEADROOM_SESSION_HEADER = "x-headroom-session-id";
34296
34297
  INTERNAL_HEADER_NAMES = [
34297
34298
  "x-agent-shim-identity",
34298
34299
  "x-agent-shim-session",
@@ -34302,7 +34303,7 @@ var init_route = __esm({
34302
34303
  "x-agent-shim-hop",
34303
34304
  "x-agent-shim-hop-id",
34304
34305
  "x-headroom-project-id",
34305
- "x-headroom-session-id",
34306
+ HEADROOM_SESSION_HEADER,
34306
34307
  "x-headroom-base-url"
34307
34308
  ];
34308
34309
  IDENTITY_HEADER = "x-agent-shim-identity";
@@ -34310,7 +34311,7 @@ var init_route = __esm({
34310
34311
  PROVIDER_HEADER = "x-agent-shim-provider";
34311
34312
  HEADROOM_FLAG_HEADER = "x-agent-shim-headroom";
34312
34313
  PROJECT_ID_HEADER = "x-headroom-project-id";
34313
- SESSION_ATTRIBUTION_HEADER = "x-headroom-session-id";
34314
+ CLIENT_SESSION_HEADER = "x-claude-code-session-id";
34314
34315
  HEADROOM_BASE_URL_HEADER = "x-headroom-base-url";
34315
34316
  AUTH_HEADER = "x-agent-shim-auth";
34316
34317
  HOP_SECRET_HEADER = "x-agent-shim-hop";
@@ -35065,8 +35066,8 @@ function segmentDay(epochMs) {
35065
35066
  function segmentName(day, pid) {
35066
35067
  return `${day}.${String(pid)}.jsonl`;
35067
35068
  }
35068
- function listLogSegments(fs23, logDir) {
35069
- return fs23.readdir(logDir).flatMap((name) => {
35069
+ function listLogSegments(fs24, logDir) {
35070
+ return fs24.readdir(logDir).flatMap((name) => {
35070
35071
  const match = SEGMENT_RE.exec(name);
35071
35072
  const day = match?.[1];
35072
35073
  if (day === void 0) {
@@ -35075,15 +35076,15 @@ function listLogSegments(fs23, logDir) {
35075
35076
  return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
35076
35077
  }).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
35077
35078
  }
35078
- function readUsageLog(fs23, logDir, options = {}) {
35079
+ function readUsageLog(fs24, logDir, options = {}) {
35079
35080
  const { sinceMs } = options;
35080
35081
  const records = [];
35081
35082
  let invalidLines = 0;
35082
- for (const segment of listLogSegments(fs23, logDir)) {
35083
+ for (const segment of listLogSegments(fs24, logDir)) {
35083
35084
  if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
35084
35085
  continue;
35085
35086
  }
35086
- const contents = fs23.readFileUtf8(import_node_path25.default.join(logDir, segment.name));
35087
+ const contents = fs24.readFileUtf8(import_node_path25.default.join(logDir, segment.name));
35087
35088
  if (contents === void 0) {
35088
35089
  continue;
35089
35090
  }
@@ -35119,9 +35120,9 @@ function snapshotPath(snapshotsDir, identity) {
35119
35120
  }
35120
35121
  return import_node_path25.default.join(snapshotsDir, `${identity}.json`);
35121
35122
  }
35122
- function readUsageSnapshot(fs23, snapshotsDir, identity) {
35123
+ function readUsageSnapshot(fs24, snapshotsDir, identity) {
35123
35124
  const file2 = snapshotPath(snapshotsDir, identity);
35124
- const raw = fs23.readFileUtf8(file2);
35125
+ const raw = fs24.readFileUtf8(file2);
35125
35126
  if (raw === void 0) {
35126
35127
  return void 0;
35127
35128
  }
@@ -35137,8 +35138,8 @@ function readUsageSnapshot(fs23, snapshotsDir, identity) {
35137
35138
  }
35138
35139
  return snapshot.data;
35139
35140
  }
35140
- function listUsageSnapshots(fs23, snapshotsDir) {
35141
- return fs23.readdir(snapshotsDir).flatMap((name) => {
35141
+ function listUsageSnapshots(fs24, snapshotsDir) {
35142
+ return fs24.readdir(snapshotsDir).flatMap((name) => {
35142
35143
  if (!name.endsWith(".json")) {
35143
35144
  return [];
35144
35145
  }
@@ -35146,7 +35147,7 @@ function listUsageSnapshots(fs23, snapshotsDir) {
35146
35147
  if (!isIdentityName(identity)) {
35147
35148
  return [];
35148
35149
  }
35149
- const snapshot = readUsageSnapshot(fs23, snapshotsDir, identity);
35150
+ const snapshot = readUsageSnapshot(fs24, snapshotsDir, identity);
35150
35151
  return snapshot === void 0 ? [] : [snapshot];
35151
35152
  }).sort((left, right) => left.identity.localeCompare(right.identity));
35152
35153
  }
@@ -35220,11 +35221,11 @@ var init_read = __esm({
35220
35221
  });
35221
35222
 
35222
35223
  // src/usage/store.ts
35223
- function pruneUsageLog(fs23, logDir, nowMs) {
35224
+ function pruneUsageLog(fs24, logDir, nowMs) {
35224
35225
  const cutoff = nowMs - USAGE_RETENTION_MS;
35225
- for (const segment of listLogSegments(fs23, logDir)) {
35226
+ for (const segment of listLogSegments(fs24, logDir)) {
35226
35227
  if (segment.endsAt <= cutoff) {
35227
- fs23.removeRecursive(import_node_path26.default.join(logDir, segment.name));
35228
+ fs24.removeRecursive(import_node_path26.default.join(logDir, segment.name));
35228
35229
  }
35229
35230
  }
35230
35231
  }
@@ -35253,7 +35254,7 @@ function foldProviderState(current, record2) {
35253
35254
  };
35254
35255
  }
35255
35256
  function createUsageStore(deps) {
35256
- const { fs: fs23, paths } = deps;
35257
+ const { fs: fs24, paths } = deps;
35257
35258
  let prunedDay;
35258
35259
  const rewriteSnapshot = (identity, fold) => {
35259
35260
  if (!isIdentityName(identity)) {
@@ -35262,7 +35263,7 @@ function createUsageStore(deps) {
35262
35263
  }
35263
35264
  let current;
35264
35265
  try {
35265
- current = readUsageSnapshot(fs23, paths.usageSnapshotsDir, identity);
35266
+ current = readUsageSnapshot(fs24, paths.usageSnapshotsDir, identity);
35266
35267
  } catch (error63) {
35267
35268
  if (!(error63 instanceof UsageSnapshotError)) {
35268
35269
  throw error63;
@@ -35289,8 +35290,8 @@ function createUsageStore(deps) {
35289
35290
  ...account === void 0 ? {} : { account },
35290
35291
  providers
35291
35292
  });
35292
- fs23.mkdirPrivate(paths.usageSnapshotsDir);
35293
- fs23.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
35293
+ fs24.mkdirPrivate(paths.usageSnapshotsDir);
35294
+ fs24.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
35294
35295
  `);
35295
35296
  deps.publish?.(snapshot);
35296
35297
  return true;
@@ -35299,14 +35300,14 @@ function createUsageStore(deps) {
35299
35300
  record: (input2) => {
35300
35301
  const record2 = UsageRecordSchema.parse(input2);
35301
35302
  const nowMs = deps.now();
35302
- fs23.mkdirPrivate(paths.usageDir);
35303
- fs23.mkdirPrivate(paths.usageLogDir);
35303
+ fs24.mkdirPrivate(paths.usageDir);
35304
+ fs24.mkdirPrivate(paths.usageLogDir);
35304
35305
  const day = segmentDay(nowMs);
35305
35306
  if (prunedDay !== day) {
35306
- pruneUsageLog(fs23, paths.usageLogDir, nowMs);
35307
+ pruneUsageLog(fs24, paths.usageLogDir, nowMs);
35307
35308
  prunedDay = day;
35308
35309
  }
35309
- fs23.appendFilePrivate(import_node_path26.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
35310
+ fs24.appendFilePrivate(import_node_path26.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
35310
35311
  `);
35311
35312
  if (record2.identity !== void 0) {
35312
35313
  rewriteSnapshot(record2.identity, (current) => ({ ...current?.providers, [record2.provider]: foldProviderState(current?.providers[record2.provider], record2) }));
@@ -35348,14 +35349,14 @@ var init_store2 = __esm({
35348
35349
  function errorMessage(error63) {
35349
35350
  return error63 instanceof Error ? error63.message : String(error63);
35350
35351
  }
35351
- function loadPoolMembers(fs23, paths, identities, nowMs) {
35352
+ function loadPoolMembers(fs24, paths, identities, nowMs) {
35352
35353
  const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
35353
- const log = readUsageLog(fs23, paths.usageLogDir, { sinceMs: windowStartMs });
35354
+ const log = readUsageLog(fs24, paths.usageLogDir, { sinceMs: windowStartMs });
35354
35355
  return identities.map((identity) => {
35355
35356
  const records = log.records.filter((record2) => record2.identity === identity && record2.provider === ANTHROPIC_PROVIDER && Date.parse(record2.at) >= windowStartMs);
35356
35357
  try {
35357
- const snapshot = readUsageSnapshot(fs23, paths.usageSnapshotsDir, identity);
35358
- const account = readAccountMetadata(fs23, paths.identitiesDir, identity) ?? snapshot?.account;
35358
+ const snapshot = readUsageSnapshot(fs24, paths.usageSnapshotsDir, identity);
35359
+ const account = readAccountMetadata(fs24, paths.identitiesDir, identity) ?? snapshot?.account;
35359
35360
  return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
35360
35361
  } catch (error63) {
35361
35362
  if (error63 instanceof UsageSnapshotError || error63 instanceof AccountMetadataError) {
@@ -35427,9 +35428,9 @@ function nestedMember(input2, nestedName, childStack, sticky) {
35427
35428
  missing: nested.missing
35428
35429
  };
35429
35430
  }
35430
- function readPicksFile(fs23, file2) {
35431
+ function readPicksFile(fs24, file2) {
35431
35432
  const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
35432
- const raw = fs23.readFileUtf8(file2);
35433
+ const raw = fs24.readFileUtf8(file2);
35433
35434
  if (raw === void 0) {
35434
35435
  return { file: empty };
35435
35436
  }
@@ -35442,17 +35443,17 @@ function readPicksFile(fs23, file2) {
35442
35443
  const result = PicksFileSchema.safeParse(parsed);
35443
35444
  return result.success ? { file: result.data } : { file: empty, problem: `${file2} is not a picks file this agent-shim can read` };
35444
35445
  }
35445
- function readStickyPick(fs23, picksFile, directory) {
35446
- const read = readPicksFile(fs23, picksFile);
35446
+ function readStickyPick(fs24, picksFile, directory) {
35447
+ const read = readPicksFile(fs24, picksFile);
35447
35448
  const entry = read.file.picks[directory];
35448
35449
  return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
35449
35450
  }
35450
- function recordStickyPick(fs23, picksFile, directory, identity, nowMs) {
35451
- const current = readPicksFile(fs23, picksFile).file.picks;
35451
+ function recordStickyPick(fs24, picksFile, directory, identity, nowMs) {
35452
+ const current = readPicksFile(fs24, picksFile).file.picks;
35452
35453
  const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
35453
35454
  const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
35454
- fs23.mkdirPrivate(import_node_path27.default.dirname(picksFile));
35455
- fs23.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
35455
+ fs24.mkdirPrivate(import_node_path27.default.dirname(picksFile));
35456
+ fs24.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
35456
35457
  `);
35457
35458
  }
35458
35459
  var import_node_path27, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
@@ -61979,11 +61980,18 @@ var init_ensure2 = __esm({
61979
61980
  // src/frontdoor/probe.ts
61980
61981
  function probeFrontDoorSync(port, caPem) {
61981
61982
  refuseToBlockInRole("a synchronous probe of the front door");
61983
+ return runProbeWorker(PROBE_SOURCE, { port, ca: caPem });
61984
+ }
61985
+ function probeListenerAcceptSync(port) {
61986
+ refuseToBlockInRole("a synchronous probe of a front door listener");
61987
+ return runProbeWorker(ACCEPT_PROBE_SOURCE, { port });
61988
+ }
61989
+ function runProbeWorker(source, data) {
61982
61990
  const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
61983
61991
  const header = new Int32Array(shared, 0, HEADER_SLOTS);
61984
- const worker = new import_node_worker_threads.Worker(PROBE_SOURCE, {
61992
+ const worker = new import_node_worker_threads.Worker(source, {
61985
61993
  eval: true,
61986
- workerData: { port, ca: caPem, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
61994
+ workerData: { ...data, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
61987
61995
  });
61988
61996
  worker.unref();
61989
61997
  try {
@@ -62001,7 +62009,7 @@ function probeFrontDoorSync(port, caPem) {
62001
62009
  void worker.terminate();
62002
62010
  }
62003
62011
  }
62004
- var import_node_worker_threads, PROBE_TIMEOUT_MS, PROBE_WAIT_MARGIN_MS, REASON_BYTES, HEADER_SLOTS, INT32_BYTES, VERDICT_PENDING, VERDICT_OK, VERDICT_FAILED, PROBE_SOURCE;
62012
+ var import_node_worker_threads, PROBE_TIMEOUT_MS, PROBE_WAIT_MARGIN_MS, REASON_BYTES, HEADER_SLOTS, INT32_BYTES, VERDICT_PENDING, VERDICT_OK, VERDICT_FAILED, PROBE_SOURCE, ACCEPT_PROBE_SOURCE;
62005
62013
  var init_probe = __esm({
62006
62014
  "src/frontdoor/probe.ts"() {
62007
62015
  "use strict";
@@ -62044,6 +62052,27 @@ const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca],
62044
62052
  // A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
62045
62053
  setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
62046
62054
  request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
62055
+ `;
62056
+ ACCEPT_PROBE_SOURCE = `
62057
+ const { workerData } = require("node:worker_threads");
62058
+ const net = require("node:net");
62059
+ const { port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
62060
+ const header = new Int32Array(shared, 0, headerSlots);
62061
+ const reason = new Uint8Array(shared, headerSlots * 4);
62062
+ let done = false;
62063
+ const finish = (verdict, message) => {
62064
+ if (done) return;
62065
+ done = true;
62066
+ const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
62067
+ reason.set(bytes);
62068
+ Atomics.store(header, 1, bytes.length);
62069
+ Atomics.store(header, 0, verdict);
62070
+ Atomics.notify(header, 0);
62071
+ };
62072
+ const socket = net.connect({ host: "127.0.0.1", port });
62073
+ socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
62074
+ socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
62075
+ setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
62047
62076
  `;
62048
62077
  }
62049
62078
  });
@@ -62064,14 +62093,14 @@ var init_selfIdentity = __esm({
62064
62093
 
62065
62094
  // src/frontdoor/trust.ts
62066
62095
  function resolveTrustBundle(params) {
62067
- const { caCertFile, bundlesDir, variable, inherited, fs: fs23 } = params;
62096
+ const { caCertFile, bundlesDir, variable, inherited, fs: fs24 } = params;
62068
62097
  if (inherited === void 0 || inherited === "" || import_node_path35.default.resolve(inherited) === import_node_path35.default.resolve(caCertFile)) {
62069
62098
  return { path: caCertFile };
62070
62099
  }
62071
- const caPem = fs23.readFileUtf8(caCertFile);
62100
+ const caPem = fs24.readFileUtf8(caCertFile);
62072
62101
  let inheritedPem;
62073
62102
  try {
62074
- inheritedPem = fs23.readFileUtf8(inherited);
62103
+ inheritedPem = fs24.readFileUtf8(inherited);
62075
62104
  } catch (error63) {
62076
62105
  return {
62077
62106
  path: caCertFile,
@@ -62084,9 +62113,9 @@ function resolveTrustBundle(params) {
62084
62113
  const combined = `${inheritedPem.trimEnd()}
62085
62114
  ${caPem}`;
62086
62115
  const bundle = import_node_path35.default.join(bundlesDir, `${(0, import_node_crypto11.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
62087
- if (!fs23.exists(bundle)) {
62088
- fs23.mkdirp(bundlesDir);
62089
- fs23.writeFileAtomic(bundle, combined);
62116
+ if (!fs24.exists(bundle)) {
62117
+ fs24.mkdirp(bundlesDir);
62118
+ fs24.writeFileAtomic(bundle, combined);
62090
62119
  }
62091
62120
  return { path: bundle };
62092
62121
  }
@@ -62253,20 +62282,20 @@ function lockHolder(contents) {
62253
62282
  const pid = Number((contents ?? "").trim());
62254
62283
  return Number.isInteger(pid) && pid > 0 ? pid : void 0;
62255
62284
  }
62256
- function acquireUpdateLock(fs23, isProcessAlive, pid, lockPath) {
62257
- const take = () => fs23.writeFileExclusive(lockPath, `${String(pid)}
62285
+ function acquireUpdateLock(fs24, isProcessAlive, pid, lockPath) {
62286
+ const take = () => fs24.writeFileExclusive(lockPath, `${String(pid)}
62258
62287
  `);
62259
62288
  const release = () => {
62260
- fs23.unlink(lockPath);
62289
+ fs24.unlink(lockPath);
62261
62290
  };
62262
62291
  if (take()) {
62263
62292
  return release;
62264
62293
  }
62265
- const holder = lockHolder(fs23.readFileUtf8(lockPath));
62294
+ const holder = lockHolder(fs24.readFileUtf8(lockPath));
62266
62295
  if (holder !== void 0 && holder !== pid && isProcessAlive(holder)) {
62267
62296
  throw new UpdateConflictError(`another agent-shim update (pid ${String(holder)}) is already running`);
62268
62297
  }
62269
- fs23.unlink(lockPath);
62298
+ fs24.unlink(lockPath);
62270
62299
  if (!take()) {
62271
62300
  throw new UpdateConflictError("another agent-shim update took the lock while it was being replaced");
62272
62301
  }
@@ -63117,7 +63146,7 @@ function contextTokensOfTranscript(text2) {
63117
63146
  }
63118
63147
  return void 0;
63119
63148
  }
63120
- function resumedContextTokens(fs23, params) {
63149
+ function resumedContextTokens(fs24, params) {
63121
63150
  const target = resumeTargetOf(params.passthrough);
63122
63151
  if (target === void 0) {
63123
63152
  return void 0;
@@ -63128,19 +63157,19 @@ function resumedContextTokens(fs23, params) {
63128
63157
  file2 = import_node_path40.default.join(projectDir, `${target.id}.jsonl`);
63129
63158
  } else {
63130
63159
  let newestMs = -Infinity;
63131
- for (const name of fs23.readdir(projectDir)) {
63160
+ for (const name of fs24.readdir(projectDir)) {
63132
63161
  if (!name.endsWith(".jsonl")) {
63133
63162
  continue;
63134
63163
  }
63135
63164
  const candidate = import_node_path40.default.join(projectDir, name);
63136
- const stat = fs23.lstat(candidate);
63165
+ const stat = fs24.lstat(candidate);
63137
63166
  if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
63138
63167
  newestMs = stat.mtimeMs;
63139
63168
  file2 = candidate;
63140
63169
  }
63141
63170
  }
63142
63171
  }
63143
- const text2 = file2 === void 0 ? void 0 : fs23.readFileUtf8(file2);
63172
+ const text2 = file2 === void 0 ? void 0 : fs24.readFileUtf8(file2);
63144
63173
  return text2 === void 0 ? void 0 : contextTokensOfTranscript(text2);
63145
63174
  }
63146
63175
  var import_node_path40;
@@ -63258,7 +63287,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
63258
63287
  return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
63259
63288
  }
63260
63289
  function pickFromPool(decided, params, parsedArgv, readOnly) {
63261
- const { paths, fs: fs23, proc, log } = params;
63290
+ const { paths, fs: fs24, proc, log } = params;
63262
63291
  if (decided.pool === void 0) {
63263
63292
  return { identityDecision: decided };
63264
63293
  }
@@ -63273,7 +63302,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
63273
63302
  selectedVia: decided.source,
63274
63303
  pools: params.pools,
63275
63304
  paths,
63276
- fs: fs23,
63305
+ fs: fs24,
63277
63306
  usageFs: farmRuntime.fs,
63278
63307
  cwd: farmRuntime.cwd,
63279
63308
  now: farmRuntime.now,
@@ -63296,7 +63325,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
63296
63325
  };
63297
63326
  }
63298
63327
  function decideLaunch(params, readOnly) {
63299
- const { paths, fs: fs23, proc, log } = params;
63328
+ const { paths, fs: fs24, proc, log } = params;
63300
63329
  const { env, argv } = proc;
63301
63330
  const parsedArgv = parseLauncherArgv(argv);
63302
63331
  const cliOverride = buildCliOverride({
@@ -63311,7 +63340,7 @@ function decideLaunch(params, readOnly) {
63311
63340
  argv0Identity: parsedArgv.identity,
63312
63341
  directoryPinnedIdentity: params.directoryPinnedIdentity,
63313
63342
  readActiveIdentityFile: () => {
63314
- const raw = fs23.readFileUtf8(paths.activeIdentityFile);
63343
+ const raw = fs24.readFileUtf8(paths.activeIdentityFile);
63315
63344
  if (raw === void 0) {
63316
63345
  return void 0;
63317
63346
  }
@@ -63346,7 +63375,7 @@ function decideLaunch(params, readOnly) {
63346
63375
  }
63347
63376
  let loadedIdentity;
63348
63377
  if (identityDecision.name !== void 0) {
63349
- loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs23);
63378
+ loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs24);
63350
63379
  if (loadedIdentity === void 0) {
63351
63380
  log.error(
63352
63381
  `agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
@@ -63361,7 +63390,7 @@ function decideLaunch(params, readOnly) {
63361
63390
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
63362
63391
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
63363
63392
  });
63364
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs23.readConfigFile(import_node_path41.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
63393
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs24.readConfigFile(import_node_path41.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
63365
63394
  log.error(
63366
63395
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
63367
63396
  );
@@ -63370,7 +63399,7 @@ function decideLaunch(params, readOnly) {
63370
63399
  const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
63371
63400
  const providerParams = {
63372
63401
  paths,
63373
- port: fs23,
63402
+ port: fs24,
63374
63403
  ...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
63375
63404
  ...farmContext === void 0 ? {} : { cascade: farmContext.cascade }
63376
63405
  };
@@ -104799,12 +104828,12 @@ var require_dist2 = __commonJS({
104799
104828
  throw new Error(`Unknown format "${name}"`);
104800
104829
  return f;
104801
104830
  };
104802
- function addFormats(ajv, list, fs23, exportName) {
104831
+ function addFormats(ajv, list, fs24, exportName) {
104803
104832
  var _a4;
104804
104833
  var _b2;
104805
104834
  (_a4 = (_b2 = ajv.opts.code).formats) !== null && _a4 !== void 0 ? _a4 : _b2.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
104806
104835
  for (const f of list)
104807
- ajv.addFormat(f, fs23[f]);
104836
+ ajv.addFormat(f, fs24[f]);
104808
104837
  }
104809
104838
  module2.exports = exports2 = formatsPlugin;
104810
104839
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -112532,7 +112561,7 @@ function registerCodexCommand(program2, deps) {
112532
112561
  // src/frontdoor/commands.ts
112533
112562
  var import_node_crypto21 = require("node:crypto");
112534
112563
  var import_node_path51 = __toESM(require("node:path"), 1);
112535
- var import_node_fs18 = __toESM(require("node:fs"), 1);
112564
+ var import_node_fs19 = __toESM(require("node:fs"), 1);
112536
112565
  init_commandDeps();
112537
112566
  init_schema();
112538
112567
  init_conditions();
@@ -112673,17 +112702,17 @@ function parseEntry2(project, entry) {
112673
112702
  const base = match?.[1];
112674
112703
  return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
112675
112704
  }
112676
- function listSessions2(fs23, configDir) {
112705
+ function listSessions2(fs24, configDir) {
112677
112706
  const found = [];
112678
- for (const project of fs23.readdir(import_node_path33.default.join(configDir, PROJECTS_DIR))) {
112707
+ for (const project of fs24.readdir(import_node_path33.default.join(configDir, PROJECTS_DIR))) {
112679
112708
  const projectDir = import_node_path33.default.join(configDir, PROJECTS_DIR, project);
112680
112709
  const entries = /* @__PURE__ */ new Set();
112681
- for (const name of fs23.readdir(projectDir)) {
112710
+ for (const name of fs24.readdir(projectDir)) {
112682
112711
  if (name.endsWith(TRANSCRIPT_SUFFIX)) {
112683
112712
  entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
112684
112713
  continue;
112685
112714
  }
112686
- const children = fs23.readdir(import_node_path33.default.join(projectDir, name));
112715
+ const children = fs24.readdir(import_node_path33.default.join(projectDir, name));
112687
112716
  if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
112688
112717
  entries.add(name);
112689
112718
  }
@@ -112694,9 +112723,9 @@ function listSessions2(fs23, configDir) {
112694
112723
  }
112695
112724
  return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
112696
112725
  }
112697
- function locateAgents(fs23, configDir, relativeDir, workflowRunId, report) {
112726
+ function locateAgents(fs24, configDir, relativeDir, workflowRunId, report) {
112698
112727
  const located = [];
112699
- for (const name of listDirOrReport(fs23, configDir, relativeDir, report)) {
112728
+ for (const name of listDirOrReport(fs24, configDir, relativeDir, report)) {
112700
112729
  if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
112701
112730
  continue;
112702
112731
  }
@@ -112745,17 +112774,17 @@ function toNode(read, children) {
112745
112774
  function describeFailure(error63) {
112746
112775
  return error63 instanceof Error ? error63.message : String(error63);
112747
112776
  }
112748
- function readFileOrReport(fs23, configDir, relative, report) {
112777
+ function readFileOrReport(fs24, configDir, relative, report) {
112749
112778
  try {
112750
- return fs23.readFileUtf8(import_node_path33.default.join(configDir, relative));
112779
+ return fs24.readFileUtf8(import_node_path33.default.join(configDir, relative));
112751
112780
  } catch (error63) {
112752
112781
  report({ path: relative, reason: `could not be read: ${describeFailure(error63)}` });
112753
112782
  return void 0;
112754
112783
  }
112755
112784
  }
112756
- function listDirOrReport(fs23, configDir, relative, report) {
112785
+ function listDirOrReport(fs24, configDir, relative, report) {
112757
112786
  try {
112758
- return fs23.readdir(import_node_path33.default.join(configDir, relative));
112787
+ return fs24.readdir(import_node_path33.default.join(configDir, relative));
112759
112788
  } catch (error63) {
112760
112789
  report({ path: relative, reason: `could not be listed: ${describeFailure(error63)}` });
112761
112790
  return [];
@@ -112778,22 +112807,22 @@ var WorkflowRunFileSchema = external_exports.object({
112778
112807
  phases: external_exports.array(external_exports.object({ title: external_exports.string() })).default([]),
112779
112808
  summary: external_exports.string().optional()
112780
112809
  });
112781
- function summariseSession(fs23, configDir, ref) {
112810
+ function summariseSession(fs24, configDir, ref) {
112782
112811
  const sessionRelative = import_node_path33.default.join(PROJECTS_DIR, ref.project, ref.entry);
112783
112812
  const subagentsRelative = import_node_path33.default.join(sessionRelative, SUBAGENTS_DIR);
112784
112813
  const workflowsUnderSubagents = import_node_path33.default.join(subagentsRelative, WORKFLOWS_DIR);
112785
112814
  const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
112786
- let agentCount = fs23.readdir(import_node_path33.default.join(configDir, subagentsRelative)).filter(isMeta).length;
112787
- for (const runDir of fs23.readdir(import_node_path33.default.join(configDir, workflowsUnderSubagents))) {
112815
+ let agentCount = fs24.readdir(import_node_path33.default.join(configDir, subagentsRelative)).filter(isMeta).length;
112816
+ for (const runDir of fs24.readdir(import_node_path33.default.join(configDir, workflowsUnderSubagents))) {
112788
112817
  if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
112789
- agentCount += fs23.readdir(import_node_path33.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
112818
+ agentCount += fs24.readdir(import_node_path33.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
112790
112819
  }
112791
112820
  }
112792
- const workflowRunCount = fs23.readdir(import_node_path33.default.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
112793
- const transcript = fs23.lstat(import_node_path33.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
112821
+ const workflowRunCount = fs24.readdir(import_node_path33.default.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
112822
+ const transcript = fs24.lstat(import_node_path33.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
112794
112823
  return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
112795
112824
  }
112796
- function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112825
+ function readSessionAgentTree(fs24, configDir, ref, options = {}) {
112797
112826
  const problems = [];
112798
112827
  const report = (problem) => {
112799
112828
  problems.push(problem);
@@ -112801,15 +112830,15 @@ function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112801
112830
  const sessionRelative = import_node_path33.default.join(PROJECTS_DIR, ref.project, ref.entry);
112802
112831
  const subagentsRelative = import_node_path33.default.join(sessionRelative, SUBAGENTS_DIR);
112803
112832
  const workflowsUnderSubagents = import_node_path33.default.join(subagentsRelative, WORKFLOWS_DIR);
112804
- const located = locateAgents(fs23, configDir, subagentsRelative, void 0, report);
112805
- for (const runDir of listDirOrReport(fs23, configDir, workflowsUnderSubagents, report)) {
112833
+ const located = locateAgents(fs24, configDir, subagentsRelative, void 0, report);
112834
+ for (const runDir of listDirOrReport(fs24, configDir, workflowsUnderSubagents, report)) {
112806
112835
  if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
112807
- located.push(...locateAgents(fs23, configDir, import_node_path33.default.join(workflowsUnderSubagents, runDir), runDir, report));
112836
+ located.push(...locateAgents(fs24, configDir, import_node_path33.default.join(workflowsUnderSubagents, runDir), runDir, report));
112808
112837
  }
112809
112838
  }
112810
112839
  const agents = /* @__PURE__ */ new Map();
112811
112840
  for (const candidate of located) {
112812
- const text2 = readFileOrReport(fs23, configDir, candidate.metaPath, report);
112841
+ const text2 = readFileOrReport(fs24, configDir, candidate.metaPath, report);
112813
112842
  if (text2 === void 0) {
112814
112843
  continue;
112815
112844
  }
@@ -112821,7 +112850,7 @@ function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112821
112850
  agents.set(candidate.id, { located: candidate, meta: parsed.data });
112822
112851
  }
112823
112852
  const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
112824
- const parentOf4 = resolveParents(fs23, configDir, agents, report);
112853
+ const parentOf4 = resolveParents(fs24, configDir, agents, report);
112825
112854
  const childrenOf = /* @__PURE__ */ new Map();
112826
112855
  const roots = [];
112827
112856
  for (const id2 of agents.keys()) {
@@ -112844,12 +112873,12 @@ function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112844
112873
  sessionId: ref.sessionId,
112845
112874
  superseded: ref.superseded,
112846
112875
  agents: roots.sort().map(build),
112847
- tasks: readTasks(fs23, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id2) => !ownTaskLists(ref.sessionId).includes(id2)), report),
112848
- workflowRuns: readWorkflowRuns(fs23, configDir, import_node_path33.default.join(sessionRelative, WORKFLOWS_DIR), report),
112876
+ tasks: readTasks(fs24, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id2) => !ownTaskLists(ref.sessionId).includes(id2)), report),
112877
+ workflowRuns: readWorkflowRuns(fs24, configDir, import_node_path33.default.join(sessionRelative, WORKFLOWS_DIR), report),
112849
112878
  problems
112850
112879
  };
112851
112880
  }
112852
- function resolveParents(fs23, configDir, agents, report) {
112881
+ function resolveParents(fs24, configDir, agents, report) {
112853
112882
  const parentOf4 = /* @__PURE__ */ new Map();
112854
112883
  const transcriptCache = /* @__PURE__ */ new Map();
112855
112884
  const transcriptOf = (agent) => {
@@ -112857,7 +112886,7 @@ function resolveParents(fs23, configDir, agents, report) {
112857
112886
  if (cached2 !== void 0) {
112858
112887
  return cached2;
112859
112888
  }
112860
- const text2 = readFileOrReport(fs23, configDir, agent.located.transcriptPath, report) ?? "";
112889
+ const text2 = readFileOrReport(fs24, configDir, agent.located.transcriptPath, report) ?? "";
112861
112890
  transcriptCache.set(agent.located.id, text2);
112862
112891
  return text2;
112863
112892
  };
@@ -112907,16 +112936,16 @@ function resolveParents(fs23, configDir, agents, report) {
112907
112936
  function ownTaskLists(sessionId) {
112908
112937
  return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
112909
112938
  }
112910
- function readTasks(fs23, configDir, ownLists, sharedLists, report) {
112939
+ function readTasks(fs24, configDir, ownLists, sharedLists, report) {
112911
112940
  const tasks = [];
112912
112941
  [...ownLists, ...sharedLists].forEach((scope, index) => {
112913
112942
  const relativeDir = import_node_path33.default.join(TASKS_DIR, scope);
112914
- for (const name of [...listDirOrReport(fs23, configDir, relativeDir, report)].sort()) {
112943
+ for (const name of [...listDirOrReport(fs24, configDir, relativeDir, report)].sort()) {
112915
112944
  if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
112916
112945
  continue;
112917
112946
  }
112918
112947
  const relative = import_node_path33.default.join(relativeDir, name);
112919
- const text2 = readFileOrReport(fs23, configDir, relative, report);
112948
+ const text2 = readFileOrReport(fs24, configDir, relative, report);
112920
112949
  const parsed = TaskFileSchema.safeParse(text2 === void 0 ? void 0 : parseJson3(text2));
112921
112950
  if (parsed.success) {
112922
112951
  tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
@@ -112927,14 +112956,14 @@ function readTasks(fs23, configDir, ownLists, sharedLists, report) {
112927
112956
  });
112928
112957
  return tasks;
112929
112958
  }
112930
- function readWorkflowRuns(fs23, configDir, relativeDir, report) {
112959
+ function readWorkflowRuns(fs24, configDir, relativeDir, report) {
112931
112960
  const runs = [];
112932
- for (const name of [...listDirOrReport(fs23, configDir, relativeDir, report)].sort()) {
112961
+ for (const name of [...listDirOrReport(fs24, configDir, relativeDir, report)].sort()) {
112933
112962
  if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
112934
112963
  continue;
112935
112964
  }
112936
112965
  const relative = import_node_path33.default.join(relativeDir, name);
112937
- const text2 = readFileOrReport(fs23, configDir, relative, report);
112966
+ const text2 = readFileOrReport(fs24, configDir, relative, report);
112938
112967
  const parsed = WorkflowRunFileSchema.safeParse(text2 === void 0 ? void 0 : parseJson3(text2));
112939
112968
  if (!parsed.success) {
112940
112969
  if (text2 !== void 0) {
@@ -112958,11 +112987,11 @@ var SessionLookupError = class extends CliError {
112958
112987
  function identityConfigDir(identitiesDir, identity) {
112959
112988
  return import_node_path34.default.join(identitiesDir, identity);
112960
112989
  }
112961
- function historyStores(fs23, identitiesDir, identities) {
112990
+ function historyStores(fs24, identitiesDir, identities) {
112962
112991
  const byRealPath = /* @__PURE__ */ new Map();
112963
112992
  for (const identity of identities) {
112964
112993
  const configDir = identityConfigDir(identitiesDir, identity);
112965
- const real = fs23.realpath(import_node_path34.default.join(configDir, "projects"));
112994
+ const real = fs24.realpath(import_node_path34.default.join(configDir, "projects"));
112966
112995
  if (real === void 0) {
112967
112996
  continue;
112968
112997
  }
@@ -112975,15 +113004,15 @@ function historyStores(fs23, identitiesDir, identities) {
112975
113004
  }
112976
113005
  return [...byRealPath.values()];
112977
113006
  }
112978
- function collectSessionList(fs23, identitiesDir, identities, filters) {
113007
+ function collectSessionList(fs24, identitiesDir, identities, filters) {
112979
113008
  const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
112980
113009
  if (filters.identity !== void 0 && names.length === 0) {
112981
113010
  throw new SessionLookupError(`no identity named "${filters.identity}"`);
112982
113011
  }
112983
113012
  const sessions = [];
112984
- for (const store of historyStores(fs23, identitiesDir, names)) {
112985
- for (const ref of listSessions2(fs23, store.configDir)) {
112986
- const summary = summariseSession(fs23, store.configDir, ref);
113013
+ for (const store of historyStores(fs24, identitiesDir, names)) {
113014
+ for (const ref of listSessions2(fs24, store.configDir)) {
113015
+ const summary = summariseSession(fs24, store.configDir, ref);
112987
113016
  if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
112988
113017
  sessions.push({ ...summary, identities: store.identities });
112989
113018
  }
@@ -112991,14 +113020,14 @@ function collectSessionList(fs23, identitiesDir, identities, filters) {
112991
113020
  }
112992
113021
  return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
112993
113022
  }
112994
- function locateSession(fs23, identitiesDir, identities, query, onlyIdentity) {
113023
+ function locateSession(fs24, identitiesDir, identities, query, onlyIdentity) {
112995
113024
  const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
112996
113025
  if (onlyIdentity !== void 0 && names.length === 0) {
112997
113026
  throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
112998
113027
  }
112999
113028
  const matches = [];
113000
- for (const store of historyStores(fs23, identitiesDir, names)) {
113001
- for (const ref of listSessions2(fs23, store.configDir)) {
113029
+ for (const store of historyStores(fs24, identitiesDir, names)) {
113030
+ for (const ref of listSessions2(fs24, store.configDir)) {
113002
113031
  if (ref.sessionId.startsWith(query)) {
113003
113032
  matches.push({ identities: store.identities, configDir: store.configDir, ref });
113004
113033
  }
@@ -113015,9 +113044,9 @@ function locateSession(fs23, identitiesDir, identities, query, onlyIdentity) {
113015
113044
  }
113016
113045
  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`);
113017
113046
  }
113018
- function showSession(fs23, identitiesDir, identities, query, onlyIdentity) {
113019
- const located = locateSession(fs23, identitiesDir, identities, query, onlyIdentity);
113020
- return { identities: located.identities, tree: readSessionAgentTree(fs23, located.configDir, located.ref) };
113047
+ function showSession(fs24, identitiesDir, identities, query, onlyIdentity) {
113048
+ const located = locateSession(fs24, identitiesDir, identities, query, onlyIdentity);
113049
+ return { identities: located.identities, tree: readSessionAgentTree(fs24, located.configDir, located.ref) };
113021
113050
  }
113022
113051
 
113023
113052
  // src/frontdoor/commands.ts
@@ -113389,8 +113418,8 @@ var StampsFileSchema = external_exports.strictObject({
113389
113418
  schemaVersion: external_exports.literal(STAMPS_SCHEMA_VERSION),
113390
113419
  handled: external_exports.record(external_exports.string().min(1), external_exports.iso.datetime())
113391
113420
  });
113392
- function readHandled(fs23, file2) {
113393
- const raw = fs23.readFileUtf8(file2);
113421
+ function readHandled(fs24, file2) {
113422
+ const raw = fs24.readFileUtf8(file2);
113394
113423
  if (raw === void 0) {
113395
113424
  return {};
113396
113425
  }
@@ -113403,10 +113432,10 @@ function readHandled(fs23, file2) {
113403
113432
  const result = StampsFileSchema.safeParse(parsed);
113404
113433
  return result.success ? Object.fromEntries(Object.entries(result.data.handled).map(([key, at2]) => [key, Date.parse(at2)])) : {};
113405
113434
  }
113406
- function writeHandled(fs23, file2, handled) {
113435
+ function writeHandled(fs24, file2, handled) {
113407
113436
  const next = { schemaVersion: STAMPS_SCHEMA_VERSION, handled: Object.fromEntries(Object.entries(handled).map(([key, at2]) => [key, new Date(at2).toISOString()])) };
113408
- fs23.mkdirPrivate(import_node_path43.default.dirname(file2));
113409
- fs23.writeFilePrivate(file2, `${JSON.stringify(next, null, 2)}
113437
+ fs24.mkdirPrivate(import_node_path43.default.dirname(file2));
113438
+ fs24.writeFilePrivate(file2, `${JSON.stringify(next, null, 2)}
113410
113439
  `);
113411
113440
  }
113412
113441
 
@@ -114167,9 +114196,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
114167
114196
  }
114168
114197
  }
114169
114198
  async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114170
- const { fs: fs23, paths } = ports;
114199
+ const { fs: fs24, paths } = ports;
114171
114200
  const servingBinary = ports.statOwnExecutable();
114172
- const previous = readFrontDoorState(fs23, paths.frontdoorStateFile);
114201
+ const previous = readFrontDoorState(fs24, paths.frontdoorStateFile);
114173
114202
  let lastPort = previous?.lastPort;
114174
114203
  let lastConnectPort = previous?.lastConnectPort;
114175
114204
  let lastDirectPort = previous?.lastDirectPort;
@@ -114180,12 +114209,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114180
114209
  });
114181
114210
  const fail = (message) => {
114182
114211
  ports.closeRcStreamHub();
114183
- writeFrontDoorState(fs23, paths.frontdoorStateFile, { lastError: message, ...sticky() });
114184
- fs23.removeRecursive(paths.frontdoorLockFile);
114212
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, { lastError: message, ...sticky() });
114213
+ fs24.removeRecursive(paths.frontdoorLockFile);
114185
114214
  ports.log(`agent-shim frontdoor supervisor: ${message}`);
114186
114215
  return 1;
114187
114216
  };
114188
- writeFrontDoorState(fs23, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
114217
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
114189
114218
  const previousSticky = lastPort;
114190
114219
  let http8;
114191
114220
  try {
@@ -114225,16 +114254,16 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114225
114254
  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)`);
114226
114255
  }
114227
114256
  lastDirectPort = direct.port;
114228
- writeFrontDoorDirectRecord(fs23, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
114229
- writeFrontDoorState(fs23, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http8.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
114257
+ writeFrontDoorDirectRecord(fs24, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
114258
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http8.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
114230
114259
  ports.doorHealth.generation({ providerPort: http8.port, connectPort: connect3.port, directPort: direct.port });
114231
- fs23.removeRecursive(paths.frontdoorLockFile);
114260
+ fs24.removeRecursive(paths.frontdoorLockFile);
114232
114261
  ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http8.port)}, CONNECT surface on 127.0.0.1:${String(connect3.port)}`);
114233
114262
  const watchdog = ports.startWatchdog?.();
114234
114263
  let idleSince;
114235
114264
  let ticks = 0;
114236
114265
  const supersedingOwner = () => {
114237
- const owner = readFrontDoorState(fs23, paths.frontdoorStateFile)?.supervisorPid;
114266
+ const owner = readFrontDoorState(fs24, paths.frontdoorStateFile)?.supervisorPid;
114238
114267
  return owner !== void 0 && owner !== ports.ownPid && ports.isRunning(owner) ? owner : void 0;
114239
114268
  };
114240
114269
  let supersededBy;
@@ -114249,12 +114278,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114249
114278
  await connect3.close();
114250
114279
  await http8.close();
114251
114280
  ports.closeRcStreamHub();
114252
- removeFrontDoorDirectRecord(fs23, paths.frontdoorDirectRecordsDir, ports.ownPid);
114281
+ removeFrontDoorDirectRecord(fs24, paths.frontdoorDirectRecordsDir, ports.ownPid);
114253
114282
  };
114254
114283
  const shutdown = async () => {
114255
114284
  await closeServing();
114256
114285
  if (supersedingOwner() === void 0) {
114257
- writeFrontDoorState(fs23, paths.frontdoorStateFile, sticky());
114286
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, sticky());
114258
114287
  }
114259
114288
  return 0;
114260
114289
  };
@@ -114265,8 +114294,8 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114265
114294
  return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
114266
114295
  }
114267
114296
  ticks += 1;
114268
- const listed = listFrontDoorSessions(fs23, paths.frontdoorSessionsDir);
114269
- const pruned = pruneDeadFrontDoorSessions(fs23, paths.frontdoorSessionsDir, ports.isRunning);
114297
+ const listed = listFrontDoorSessions(fs24, paths.frontdoorSessionsDir);
114298
+ const pruned = pruneDeadFrontDoorSessions(fs24, paths.frontdoorSessionsDir, ports.isRunning);
114270
114299
  ports.observeLaunchRegistry(listed, pruned);
114271
114300
  ports.checkQuotaExpiry();
114272
114301
  const prunedPids = new Set(pruned);
@@ -116746,7 +116775,7 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
116746
116775
  init_claudeShim();
116747
116776
  init_store();
116748
116777
  init_realPorts();
116749
- var import_node_fs17 = __toESM(require("node:fs"), 1);
116778
+ var import_node_fs18 = __toESM(require("node:fs"), 1);
116750
116779
  var import_node_path46 = __toESM(require("node:path"), 1);
116751
116780
 
116752
116781
  // src/usage/signIn.ts
@@ -116770,12 +116799,12 @@ function decideSignIn(facts) {
116770
116799
  function credentialsFilePath(farmRoot) {
116771
116800
  return import_node_path45.default.join(farmRoot, CREDENTIALS_FILE);
116772
116801
  }
116773
- function identitySignIn(fs23, probe, identity) {
116802
+ function identitySignIn(fs24, probe, identity) {
116774
116803
  const probing = !identity.hasCredentialBlock;
116775
116804
  return decideSignIn({
116776
116805
  hasCredentialBlock: identity.hasCredentialBlock,
116777
116806
  keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
116778
- credentialsFile: probing && fs23.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
116807
+ credentialsFile: probing && fs24.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
116779
116808
  platform: probe.platform
116780
116809
  });
116781
116810
  }
@@ -116901,6 +116930,53 @@ function pushFrontDoor(push, supervisors, registeredPid, liveSessions) {
116901
116930
  );
116902
116931
  }
116903
116932
  }
116933
+ var LISTENER_ROUTES = {
116934
+ provider: "provider sessions (`z`, `m` and the like)",
116935
+ connect: "every plain OAuth session, which reaches Anthropic through it"
116936
+ };
116937
+ function pushFrontDoorListeners(push, readings) {
116938
+ for (const reading of readings) {
116939
+ const where = `127.0.0.1:${String(reading.port)}`;
116940
+ if (reading.ok) {
116941
+ push("frontdoor", "pass", `The front door's ${reading.listener} listener on ${where} accepted a probe in ${String(Math.round(reading.elapsedMs))} ms.`, reading.listener);
116942
+ continue;
116943
+ }
116944
+ push(
116945
+ "frontdoor",
116946
+ "fail",
116947
+ `The front door's ${reading.listener} listener on ${where} did not accept a probe${reading.reason === void 0 ? "" : ` (${reading.reason})`}, so ${LISTENER_ROUTES[reading.listener]} cannot get through while it stays like this. The supervisor is alive but is not serving: \`agent-shim frontdoor restart\` replaces it.`,
116948
+ reading.listener
116949
+ );
116950
+ }
116951
+ }
116952
+
116953
+ // src/frontdoor/listenerReadings.ts
116954
+ var import_node_fs17 = __toESM(require("node:fs"), 1);
116955
+ init_probe();
116956
+ function readFrontDoorListeners(state, supervisorAlive, probes) {
116957
+ if (!supervisorAlive) {
116958
+ return [];
116959
+ }
116960
+ const readings = [];
116961
+ const take = (listener, port, probe) => {
116962
+ if (port === void 0) {
116963
+ return;
116964
+ }
116965
+ const started = probes.now();
116966
+ const verdict = probe(port);
116967
+ readings.push({ listener, port, ok: verdict.ok, ...verdict.ok ? {} : { reason: verdict.reason }, elapsedMs: Math.max(0, probes.now() - started) });
116968
+ };
116969
+ take("provider", state.port, probes.authenticateProvider);
116970
+ take("connect", state.connectPort, probes.connect);
116971
+ return readings;
116972
+ }
116973
+ function realFrontDoorListenerProbes(paths) {
116974
+ return {
116975
+ authenticateProvider: (port) => probeFrontDoorSync(port, import_node_fs17.default.readFileSync(paths.frontdoorCaCertFile, "utf8")),
116976
+ connect: probeListenerAcceptSync,
116977
+ now: () => performance.now()
116978
+ };
116979
+ }
116904
116980
 
116905
116981
  // src/doctorReport.ts
116906
116982
  init_supervisorProcesses();
@@ -117345,6 +117421,9 @@ function runDoctor(params) {
117345
117421
  if (params.frontDoor !== void 0) {
117346
117422
  const validated2 = params.frontDoor.state.raw === void 0 ? void 0 : validateJson(FrontDoorStateSchema, params.frontDoor.state);
117347
117423
  pushFrontDoor(push, params.frontDoor.supervisors, validated2?.ok === true ? validated2.data.supervisorPid : void 0, params.frontDoor.liveSessions);
117424
+ if (params.frontDoor.listeners !== void 0) {
117425
+ pushFrontDoorListeners(push, params.frontDoor.listeners);
117426
+ }
117348
117427
  }
117349
117428
  if (params.activeIdentity.raw === void 0) {
117350
117429
  push("active-identity", "pass", "No active identity set.");
@@ -117428,25 +117507,30 @@ function formatDoctorReport(report) {
117428
117507
  }
117429
117508
  function realpathOrSelf(target) {
117430
117509
  try {
117431
- return import_node_fs17.default.realpathSync(target);
117510
+ return import_node_fs18.default.realpathSync(target);
117432
117511
  } catch {
117433
117512
  return target;
117434
117513
  }
117435
117514
  }
117515
+ function servingDoorListeners(paths) {
117516
+ const state = readFrontDoorState(realFarmFs, paths.frontdoorStateFile) ?? {};
117517
+ const alive = state.supervisorPid !== void 0 && realIsProcessRunning(state.supervisorPid);
117518
+ return readFrontDoorListeners(state, alive, realFrontDoorListenerProbes(paths));
117519
+ }
117436
117520
  function collectDoctorReport(params) {
117437
117521
  const { paths } = params;
117438
- const identityNames = import_node_fs17.default.existsSync(paths.identitiesDir) ? import_node_fs17.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
117522
+ const identityNames = import_node_fs18.default.existsSync(paths.identitiesDir) ? import_node_fs18.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
117439
117523
  const identities = identityNames.map((name) => {
117440
117524
  const farmRoot = import_node_path46.default.join(paths.identitiesDir, name);
117441
117525
  const identityPath = import_node_path46.default.join(farmRoot, "identity.json");
117442
- return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs17.default.existsSync(credentialsFilePath(farmRoot)) };
117526
+ return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs18.default.existsSync(credentialsFilePath(farmRoot)) };
117443
117527
  });
117444
- const profileNames = import_node_fs17.default.existsSync(paths.configProfilesDir) ? import_node_fs17.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
117528
+ const profileNames = import_node_fs18.default.existsSync(paths.configProfilesDir) ? import_node_fs18.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
117445
117529
  const configProfiles = profileNames.map((name) => {
117446
117530
  const profilePath = import_node_path46.default.join(paths.configProfilesDir, `${name}.json`);
117447
117531
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
117448
117532
  });
117449
- const providerNames = import_node_fs17.default.existsSync(paths.providersDir) ? import_node_fs17.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
117533
+ const providerNames = import_node_fs18.default.existsSync(paths.providersDir) ? import_node_fs18.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
117450
117534
  const providers = providerNames.map((name) => {
117451
117535
  const providerPath = import_node_path46.default.join(paths.providersDir, `${name}.json`);
117452
117536
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
@@ -117491,7 +117575,7 @@ function collectDoctorReport(params) {
117491
117575
  categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
117492
117576
  activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
117493
117577
  binaryDiscovery,
117494
- claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs17.default.existsSync(shimState.targetPath) },
117578
+ claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs18.default.existsSync(shimState.targetPath) },
117495
117579
  rootPath: paths.root,
117496
117580
  pathResolution: {
117497
117581
  ownExecutablePath,
@@ -117531,7 +117615,7 @@ function collectDoctorReport(params) {
117531
117615
  logPath: paths.headroomLogPath
117532
117616
  }
117533
117617
  },
117534
- ...uid === void 0 ? {} : { frontDoor: { state: { path: paths.frontdoorStateFile, raw: realFsPort.readFileUtf8(paths.frontdoorStateFile) }, supervisors: listFrontDoorSupervisors(realRunPort, uid), liveSessions: listFrontDoorSessions(realFarmFs, paths.frontdoorSessionsDir).filter((session) => realIsProcessRunning(session.pid)) } }
117618
+ ...uid === void 0 ? {} : { frontDoor: { state: { path: paths.frontdoorStateFile, raw: realFsPort.readFileUtf8(paths.frontdoorStateFile) }, supervisors: listFrontDoorSupervisors(realRunPort, uid), liveSessions: listFrontDoorSessions(realFarmFs, paths.frontdoorSessionsDir).filter((session) => realIsProcessRunning(session.pid)), listeners: servingDoorListeners(paths) } }
117535
117619
  });
117536
117620
  return report;
117537
117621
  }
@@ -126773,8 +126857,8 @@ async function applyHeadroomHop(request7, response, upstream, deps, onThread) {
126773
126857
  if (request7.session.projectId !== void 0) {
126774
126858
  headers[PROJECT_ID_HEADER] = request7.session.projectId;
126775
126859
  }
126776
- if (request7.session.sessionId !== void 0) {
126777
- headers[SESSION_ATTRIBUTION_HEADER] = request7.session.sessionId;
126860
+ if (request7.session.sessionId !== void 0 && !Object.keys(headers).some((name) => name.toLowerCase() === CLIENT_SESSION_HEADER)) {
126861
+ headers[CLIENT_SESSION_HEADER] = request7.session.sessionId;
126778
126862
  }
126779
126863
  headers[HOP_SECRET_HEADER] = deps.hopSecret;
126780
126864
  try {
@@ -128463,8 +128547,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
128463
128547
  function isRecord8(value2) {
128464
128548
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
128465
128549
  }
128466
- function readJsonObject(fs23, file2) {
128467
- const raw = fs23.readFileUtf8(file2);
128550
+ function readJsonObject(fs24, file2) {
128551
+ const raw = fs24.readFileUtf8(file2);
128468
128552
  if (raw === void 0) {
128469
128553
  return void 0;
128470
128554
  }
@@ -128476,8 +128560,8 @@ function readJsonObject(fs23, file2) {
128476
128560
  }
128477
128561
  return isRecord8(parsed) ? parsed : void 0;
128478
128562
  }
128479
- function readRcSelfHostRecord(fs23, frontdoorDir) {
128480
- const parsed = readJsonObject(fs23, import_node_path49.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
128563
+ function readRcSelfHostRecord(fs24, frontdoorDir) {
128564
+ const parsed = readJsonObject(fs24, import_node_path49.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
128481
128565
  if (parsed === void 0) {
128482
128566
  return void 0;
128483
128567
  }
@@ -128922,11 +129006,11 @@ function credentialOfJson(parsed) {
128922
129006
  function sequenceNumOfJson(value2) {
128923
129007
  return typeof value2 === "number" && Number.isInteger(value2) && value2 >= 0 ? value2 : void 0;
128924
129008
  }
128925
- function createRcCredentialStore(fs23, dir) {
128926
- fs23.mkdirPrivate(dir);
129009
+ function createRcCredentialStore(fs24, dir) {
129010
+ fs24.mkdirPrivate(dir);
128927
129011
  const fileFor = (sessionId) => import_node_path50.default.join(dir, `${sessionId}.json`);
128928
129012
  const readParsed = (sessionId) => {
128929
- const raw = fs23.readFileUtf8(fileFor(sessionId));
129013
+ const raw = fs24.readFileUtf8(fileFor(sessionId));
128930
129014
  if (raw === void 0) {
128931
129015
  return void 0;
128932
129016
  }
@@ -128951,7 +129035,7 @@ function createRcCredentialStore(fs23, dir) {
128951
129035
  }
128952
129036
  const cursor3 = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
128953
129037
  const record2 = { ...credential, ...cursor3 === void 0 ? {} : { highestSequenceNum: cursor3 } };
128954
- fs23.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
129038
+ fs24.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
128955
129039
  `);
128956
129040
  },
128957
129041
  readCursor: (sessionId) => {
@@ -128966,14 +129050,14 @@ function createRcCredentialStore(fs23, dir) {
128966
129050
  }
128967
129051
  const credential = credentialOfJson(readParsed(sessionId));
128968
129052
  const record2 = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
128969
- fs23.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
129053
+ fs24.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
128970
129054
  `);
128971
129055
  },
128972
129056
  remove: (sessionId) => {
128973
129057
  if (!isSafeSessionId(sessionId)) {
128974
129058
  return;
128975
129059
  }
128976
- fs23.removeRecursive(fileFor(sessionId));
129060
+ fs24.removeRecursive(fileFor(sessionId));
128977
129061
  }
128978
129062
  };
128979
129063
  }
@@ -131137,6 +131221,12 @@ function formatFrontDoorStatus(status, caCertPath) {
131137
131221
  lines.push(`daemon log: ${status.logPath}${status.logExists ? "" : " (not created yet)"}`);
131138
131222
  return lines;
131139
131223
  }
131224
+ function formatFrontDoorListeners(readings) {
131225
+ return readings.map((reading) => {
131226
+ const what = reading.listener === "provider" ? "provider listener" : "connect surface";
131227
+ return reading.ok ? `${what}: accepting on 127.0.0.1:${String(reading.port)} (probe took ${String(Math.round(reading.elapsedMs))} ms)` : `${what}: NOT accepting on 127.0.0.1:${String(reading.port)}${reading.reason === void 0 ? "" : ` (${reading.reason})`}`;
131228
+ });
131229
+ }
131140
131230
 
131141
131231
  // src/frontdoor/commands.ts
131142
131232
  init_state();
@@ -131181,8 +131271,8 @@ function createRealQuotaRefresher(params) {
131181
131271
  // src/frontdoor/commands.ts
131182
131272
  init_store2();
131183
131273
  function appendLog(paths, line) {
131184
- import_node_fs18.default.mkdirSync(paths.logsDir, { recursive: true });
131185
- import_node_fs18.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
131274
+ import_node_fs19.default.mkdirSync(paths.logsDir, { recursive: true });
131275
+ import_node_fs19.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
131186
131276
  `);
131187
131277
  }
131188
131278
  function rcObservingResolver(resolve2, tracker, hub) {
@@ -131195,7 +131285,7 @@ function rcObservingResolver(resolve2, tracker, hub) {
131195
131285
  }
131196
131286
  function realStatOwnExecutable(watchPath) {
131197
131287
  return () => {
131198
- const st2 = import_node_fs18.default.statSync(watchPath, { throwIfNoEntry: false });
131288
+ const st2 = import_node_fs19.default.statSync(watchPath, { throwIfNoEntry: false });
131199
131289
  return st2?.isFile() !== true ? void 0 : { dev: st2.dev, ino: st2.ino, size: st2.size, mtimeMs: st2.mtimeMs };
131200
131290
  };
131201
131291
  }
@@ -131395,7 +131485,7 @@ function realFrontDoorSupervisorPorts(paths) {
131395
131485
  },
131396
131486
  isRunning: realIsProcessRunning,
131397
131487
  // The turnover check's file identity, over the installed entry resolved once at door start: re-resolving per tick would re-run the PATH scan every second and could theoretically flip between two files, while the entry itself is fixed for as long as this door lives. The existence check prefers the agent-shim sibling only when it is really there (see watchedInstallEntry).
131398
- statOwnExecutable: realStatOwnExecutable(watchedInstallEntry(realOwnExecutablePath(), (candidate) => import_node_fs18.default.existsSync(candidate))),
131488
+ statOwnExecutable: realStatOwnExecutable(watchedInstallEntry(realOwnExecutablePath(), (candidate) => import_node_fs19.default.existsSync(candidate))),
131399
131489
  startProviderListener: async (preferredPort) => {
131400
131490
  const authority = loadCa();
131401
131491
  const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
@@ -131591,11 +131681,12 @@ function registerFrontDoorCommand(program2, deps) {
131591
131681
  withExamples(
131592
131682
  frontdoor.command("status").description("Report the front door's supervisor, listeners, sessions, and last error. Read-only.").option("--json", "Print the status as JSON.").action((options) => {
131593
131683
  const status = collectFrontDoorStatus(realFarmFs, realHeadroomSocketTrust, paths, realIsProcessRunning);
131684
+ const listeners = readFrontDoorListeners(status.state, status.supervisorAlive, realFrontDoorListenerProbes(paths));
131594
131685
  if (options.json === true) {
131595
- printJson(status);
131686
+ printJson({ ...status, listeners });
131596
131687
  return;
131597
131688
  }
131598
- for (const line of formatFrontDoorStatus(status, paths.frontdoorCaCertFile)) {
131689
+ for (const line of [...formatFrontDoorStatus(status, paths.frontdoorCaCertFile), ...formatFrontDoorListeners(listeners)]) {
131599
131690
  console.log(line);
131600
131691
  }
131601
131692
  }),
@@ -141375,7 +141466,7 @@ async function serveMcp(mcp, transport, options = {}) {
141375
141466
  }
141376
141467
 
141377
141468
  // src/mcp/permissions.ts
141378
- var import_node_fs19 = __toESM(require("node:fs"), 1);
141469
+ var import_node_fs20 = __toESM(require("node:fs"), 1);
141379
141470
  var import_node_path52 = __toESM(require("node:path"), 1);
141380
141471
  init_zod();
141381
141472
  init_store();
@@ -141392,15 +141483,15 @@ function readStoredMcpPermissions(paths) {
141392
141483
  }
141393
141484
  function writeStoredMcpPermissions(paths, permissions) {
141394
141485
  writeJsonAtomic(paths.mcpPermissionsFile, { writes: permissions.writes, remoteControl: permissions.remoteControl, history: permissions.history });
141395
- import_node_fs19.default.chmodSync(paths.mcpPermissionsFile, OWNER_ONLY_MODE);
141486
+ import_node_fs20.default.chmodSync(paths.mcpPermissionsFile, OWNER_ONLY_MODE);
141396
141487
  }
141397
141488
  function effectiveMcpPermissions(flags, stored) {
141398
141489
  return { writes: flags.writes || stored.writes, remoteControl: flags.remoteControl || stored.remoteControl, history: flags.history || stored.history };
141399
141490
  }
141400
141491
  function watchMcpPermissions(paths, onChange) {
141401
141492
  const directory = import_node_path52.default.dirname(paths.mcpPermissionsFile);
141402
- import_node_fs19.default.mkdirSync(directory, { recursive: true });
141403
- const watcher = import_node_fs19.default.watch(directory, (_event, filename) => {
141493
+ import_node_fs20.default.mkdirSync(directory, { recursive: true });
141494
+ const watcher = import_node_fs20.default.watch(directory, (_event, filename) => {
141404
141495
  if (filename === null || filename === import_node_path52.default.basename(paths.mcpPermissionsFile)) {
141405
141496
  onChange();
141406
141497
  }
@@ -141713,7 +141804,7 @@ init_credential();
141713
141804
  init_credentialCache();
141714
141805
 
141715
141806
  // src/identityToken.ts
141716
- var import_node_fs20 = __toESM(require("node:fs"), 1);
141807
+ var import_node_fs21 = __toESM(require("node:fs"), 1);
141717
141808
  var import_node_path53 = __toESM(require("node:path"), 1);
141718
141809
  init_cliError();
141719
141810
  var TOKEN_FILE_MODE = 384;
@@ -141731,13 +141822,13 @@ function storeIdentityToken(paths, identityName, raw) {
141731
141822
  throw new UsageError("That is not a claude setup-token token (expected it to start with sk-ant-oat). Run `claude setup-token` and pass its token on standard input.");
141732
141823
  }
141733
141824
  const dir = identityTokenDir(paths);
141734
- import_node_fs20.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
141735
- import_node_fs20.default.chmodSync(dir, TOKEN_DIR_MODE);
141825
+ import_node_fs21.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
141826
+ import_node_fs21.default.chmodSync(dir, TOKEN_DIR_MODE);
141736
141827
  const target = identityTokenPath(paths, identityName);
141737
141828
  const temp = import_node_path53.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
141738
- import_node_fs20.default.writeFileSync(temp, `${token}
141829
+ import_node_fs21.default.writeFileSync(temp, `${token}
141739
141830
  `, { mode: TOKEN_FILE_MODE });
141740
- import_node_fs20.default.renameSync(temp, target);
141831
+ import_node_fs21.default.renameSync(temp, target);
141741
141832
  return target;
141742
141833
  }
141743
141834
 
@@ -141900,7 +141991,7 @@ function registerDoctorCommand(program2, deps) {
141900
141991
  }
141901
141992
 
141902
141993
  // src/headroom/commands.ts
141903
- var import_node_fs21 = __toESM(require("node:fs"), 1);
141994
+ var import_node_fs22 = __toESM(require("node:fs"), 1);
141904
141995
  var import_node_http4 = __toESM(require("node:http"), 1);
141905
141996
  var import_node_path54 = __toESM(require("node:path"), 1);
141906
141997
  var import_node_child_process7 = require("node:child_process");
@@ -142124,12 +142215,12 @@ function realSupervisorPorts(paths) {
142124
142215
  readConfig: () => resolveSupervisorConfig(readGlobalConfig(paths)?.headroom ?? {}),
142125
142216
  spawnHeadroom: (socketPath, allowlistFile, settings2) => {
142126
142217
  const trust = resolveHeadroomTrustBundle({ caCertFile: paths.frontdoorCaCertFile, bundlesDir: paths.frontdoorCaBundlesDir, inherited: process.env[HEADROOM_CA_BUNDLE], fs: realTrustBundleFs });
142127
- import_node_fs21.default.mkdirSync(paths.logsDir, { recursive: true });
142218
+ import_node_fs22.default.mkdirSync(paths.logsDir, { recursive: true });
142128
142219
  if (trust?.warning !== void 0) {
142129
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${trust.warning}
142220
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${trust.warning}
142130
142221
  `);
142131
142222
  }
142132
- const logFd = import_node_fs21.default.openSync(paths.headroomLogPath, "a");
142223
+ const logFd = import_node_fs22.default.openSync(paths.headroomLogPath, "a");
142133
142224
  try {
142134
142225
  const child = (0, import_node_child_process7.spawn)("headroom", headroomProxyArgs(socketPath, allowlistFile, settings2), {
142135
142226
  detached: true,
@@ -142144,12 +142235,12 @@ function realSupervisorPorts(paths) {
142144
142235
  child.once("exit", (code, signal) => {
142145
142236
  ownedHeadroom.delete(pid);
142146
142237
  exitedHeadroom.add(pid);
142147
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: headroom exited (${signal ?? `code ${String(code)}`})
142238
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: headroom exited (${signal ?? `code ${String(code)}`})
142148
142239
  `);
142149
142240
  });
142150
142241
  return pid;
142151
142242
  } finally {
142152
- import_node_fs21.default.closeSync(logFd);
142243
+ import_node_fs22.default.closeSync(logFd);
142153
142244
  }
142154
142245
  },
142155
142246
  stopProcess: (pid) => {
@@ -142162,7 +142253,7 @@ function realSupervisorPorts(paths) {
142162
142253
  now: () => Date.now()
142163
142254
  });
142164
142255
  if (outcome === "still-running") {
142165
- import_node_fs21.default.appendFileSync(
142256
+ import_node_fs22.default.appendFileSync(
142166
142257
  paths.headroomLogPath,
142167
142258
  `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: pid ${String(pid)} survived SIGKILL within its grace; it is stuck uninterruptibly
142168
142259
  `
@@ -142180,10 +142271,10 @@ function realSupervisorPorts(paths) {
142180
142271
  };
142181
142272
  }
142182
142273
  if (result.stdout !== "") {
142183
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, result.stdout);
142274
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, result.stdout);
142184
142275
  }
142185
142276
  if (result.stderr !== "") {
142186
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, result.stderr);
142277
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, result.stderr);
142187
142278
  }
142188
142279
  return result.status === 0 ? { ok: true } : { ok: false, error: `uv tool install exited ${String(result.status)}` };
142189
142280
  },
@@ -142193,8 +142284,8 @@ function realSupervisorPorts(paths) {
142193
142284
  },
142194
142285
  installedCommit: readInstalledHeadroomCommit,
142195
142286
  log: (line) => {
142196
- import_node_fs21.default.mkdirSync(paths.logsDir, { recursive: true });
142197
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
142287
+ import_node_fs22.default.mkdirSync(paths.logsDir, { recursive: true });
142288
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
142198
142289
  `);
142199
142290
  }
142200
142291
  };
@@ -142935,14 +143026,14 @@ function requireIdentity(paths, name) {
142935
143026
  throw new IdentityNotFoundError(name);
142936
143027
  }
142937
143028
  }
142938
- function collectUsageReport(fs23, paths, filters) {
143029
+ function collectUsageReport(fs24, paths, filters) {
142939
143030
  const { identity, provider, sinceMs } = filters;
142940
143031
  if (identity !== void 0) {
142941
143032
  requireIdentity(paths, identity);
142942
143033
  }
142943
- const log = readUsageLog(fs23, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
143034
+ const log = readUsageLog(fs24, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
142944
143035
  const records = log.records.filter((record2) => (identity === void 0 || record2.identity === identity) && (provider === void 0 || record2.provider === provider));
142945
- const snapshots = (identity === void 0 ? listUsageSnapshots(fs23, paths.usageSnapshotsDir) : [readUsageSnapshot(fs23, paths.usageSnapshotsDir, identity)].flatMap((snapshot) => snapshot === void 0 ? [] : [snapshot])).map((snapshot) => provider === void 0 ? snapshot : { ...snapshot, providers: Object.fromEntries(Object.entries(snapshot.providers).filter(([name]) => name === provider)) }).filter((snapshot) => Object.keys(snapshot.providers).length > 0);
143036
+ const snapshots = (identity === void 0 ? listUsageSnapshots(fs24, paths.usageSnapshotsDir) : [readUsageSnapshot(fs24, paths.usageSnapshotsDir, identity)].flatMap((snapshot) => snapshot === void 0 ? [] : [snapshot])).map((snapshot) => provider === void 0 ? snapshot : { ...snapshot, providers: Object.fromEntries(Object.entries(snapshot.providers).filter(([name]) => name === provider)) }).filter((snapshot) => Object.keys(snapshot.providers).length > 0);
142946
143037
  return {
142947
143038
  since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
142948
143039
  logDir: paths.usageLogDir,
@@ -143049,16 +143140,16 @@ function formatUsageReport(report) {
143049
143140
  }
143050
143141
  return lines;
143051
143142
  }
143052
- function collectAccounts(fs23, paths, identity, probe) {
143143
+ function collectAccounts(fs24, paths, identity, probe) {
143053
143144
  if (identity !== void 0) {
143054
143145
  requireIdentity(paths, identity);
143055
143146
  }
143056
143147
  const names = identity === void 0 ? listIdentities(paths).map((entry) => entry.name) : [identity];
143057
143148
  return names.map((name) => ({
143058
143149
  identity: name,
143059
- account: readAccountMetadata(fs23, paths.identitiesDir, name),
143060
- signIn: identitySignIn(fs23, probe, { farmRoot: import_node_path57.default.join(paths.identitiesDir, name), hasCredentialBlock: readIdentity(paths, name)?.credential !== void 0 }),
143061
- usage: readUsageSnapshot(fs23, paths.usageSnapshotsDir, name)
143150
+ account: readAccountMetadata(fs24, paths.identitiesDir, name),
143151
+ signIn: identitySignIn(fs24, probe, { farmRoot: import_node_path57.default.join(paths.identitiesDir, name), hasCredentialBlock: readIdentity(paths, name)?.credential !== void 0 }),
143152
+ usage: readUsageSnapshot(fs24, paths.usageSnapshotsDir, name)
143062
143153
  }));
143063
143154
  }
143064
143155
  function formatAccounts(views) {