claude-use 11.6.2 → 11.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs 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.6.2",
34010
+ version: "11.8.0",
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
  };
@@ -35065,8 +35065,8 @@ function segmentDay(epochMs) {
35065
35065
  function segmentName(day, pid) {
35066
35066
  return `${day}.${String(pid)}.jsonl`;
35067
35067
  }
35068
- function listLogSegments(fs23, logDir) {
35069
- return fs23.readdir(logDir).flatMap((name) => {
35068
+ function listLogSegments(fs24, logDir) {
35069
+ return fs24.readdir(logDir).flatMap((name) => {
35070
35070
  const match = SEGMENT_RE.exec(name);
35071
35071
  const day = match?.[1];
35072
35072
  if (day === void 0) {
@@ -35075,15 +35075,15 @@ function listLogSegments(fs23, logDir) {
35075
35075
  return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
35076
35076
  }).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
35077
35077
  }
35078
- function readUsageLog(fs23, logDir, options = {}) {
35078
+ function readUsageLog(fs24, logDir, options = {}) {
35079
35079
  const { sinceMs } = options;
35080
35080
  const records = [];
35081
35081
  let invalidLines = 0;
35082
- for (const segment of listLogSegments(fs23, logDir)) {
35082
+ for (const segment of listLogSegments(fs24, logDir)) {
35083
35083
  if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
35084
35084
  continue;
35085
35085
  }
35086
- const contents = fs23.readFileUtf8(import_node_path25.default.join(logDir, segment.name));
35086
+ const contents = fs24.readFileUtf8(import_node_path25.default.join(logDir, segment.name));
35087
35087
  if (contents === void 0) {
35088
35088
  continue;
35089
35089
  }
@@ -35119,9 +35119,9 @@ function snapshotPath(snapshotsDir, identity) {
35119
35119
  }
35120
35120
  return import_node_path25.default.join(snapshotsDir, `${identity}.json`);
35121
35121
  }
35122
- function readUsageSnapshot(fs23, snapshotsDir, identity) {
35122
+ function readUsageSnapshot(fs24, snapshotsDir, identity) {
35123
35123
  const file2 = snapshotPath(snapshotsDir, identity);
35124
- const raw = fs23.readFileUtf8(file2);
35124
+ const raw = fs24.readFileUtf8(file2);
35125
35125
  if (raw === void 0) {
35126
35126
  return void 0;
35127
35127
  }
@@ -35137,8 +35137,8 @@ function readUsageSnapshot(fs23, snapshotsDir, identity) {
35137
35137
  }
35138
35138
  return snapshot.data;
35139
35139
  }
35140
- function listUsageSnapshots(fs23, snapshotsDir) {
35141
- return fs23.readdir(snapshotsDir).flatMap((name) => {
35140
+ function listUsageSnapshots(fs24, snapshotsDir) {
35141
+ return fs24.readdir(snapshotsDir).flatMap((name) => {
35142
35142
  if (!name.endsWith(".json")) {
35143
35143
  return [];
35144
35144
  }
@@ -35146,7 +35146,7 @@ function listUsageSnapshots(fs23, snapshotsDir) {
35146
35146
  if (!isIdentityName(identity)) {
35147
35147
  return [];
35148
35148
  }
35149
- const snapshot = readUsageSnapshot(fs23, snapshotsDir, identity);
35149
+ const snapshot = readUsageSnapshot(fs24, snapshotsDir, identity);
35150
35150
  return snapshot === void 0 ? [] : [snapshot];
35151
35151
  }).sort((left, right) => left.identity.localeCompare(right.identity));
35152
35152
  }
@@ -35220,11 +35220,11 @@ var init_read = __esm({
35220
35220
  });
35221
35221
 
35222
35222
  // src/usage/store.ts
35223
- function pruneUsageLog(fs23, logDir, nowMs) {
35223
+ function pruneUsageLog(fs24, logDir, nowMs) {
35224
35224
  const cutoff = nowMs - USAGE_RETENTION_MS;
35225
- for (const segment of listLogSegments(fs23, logDir)) {
35225
+ for (const segment of listLogSegments(fs24, logDir)) {
35226
35226
  if (segment.endsAt <= cutoff) {
35227
- fs23.removeRecursive(import_node_path26.default.join(logDir, segment.name));
35227
+ fs24.removeRecursive(import_node_path26.default.join(logDir, segment.name));
35228
35228
  }
35229
35229
  }
35230
35230
  }
@@ -35253,7 +35253,7 @@ function foldProviderState(current, record2) {
35253
35253
  };
35254
35254
  }
35255
35255
  function createUsageStore(deps) {
35256
- const { fs: fs23, paths } = deps;
35256
+ const { fs: fs24, paths } = deps;
35257
35257
  let prunedDay;
35258
35258
  const rewriteSnapshot = (identity, fold) => {
35259
35259
  if (!isIdentityName(identity)) {
@@ -35262,7 +35262,7 @@ function createUsageStore(deps) {
35262
35262
  }
35263
35263
  let current;
35264
35264
  try {
35265
- current = readUsageSnapshot(fs23, paths.usageSnapshotsDir, identity);
35265
+ current = readUsageSnapshot(fs24, paths.usageSnapshotsDir, identity);
35266
35266
  } catch (error63) {
35267
35267
  if (!(error63 instanceof UsageSnapshotError)) {
35268
35268
  throw error63;
@@ -35289,8 +35289,8 @@ function createUsageStore(deps) {
35289
35289
  ...account === void 0 ? {} : { account },
35290
35290
  providers
35291
35291
  });
35292
- fs23.mkdirPrivate(paths.usageSnapshotsDir);
35293
- fs23.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
35292
+ fs24.mkdirPrivate(paths.usageSnapshotsDir);
35293
+ fs24.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
35294
35294
  `);
35295
35295
  deps.publish?.(snapshot);
35296
35296
  return true;
@@ -35299,14 +35299,14 @@ function createUsageStore(deps) {
35299
35299
  record: (input2) => {
35300
35300
  const record2 = UsageRecordSchema.parse(input2);
35301
35301
  const nowMs = deps.now();
35302
- fs23.mkdirPrivate(paths.usageDir);
35303
- fs23.mkdirPrivate(paths.usageLogDir);
35302
+ fs24.mkdirPrivate(paths.usageDir);
35303
+ fs24.mkdirPrivate(paths.usageLogDir);
35304
35304
  const day = segmentDay(nowMs);
35305
35305
  if (prunedDay !== day) {
35306
- pruneUsageLog(fs23, paths.usageLogDir, nowMs);
35306
+ pruneUsageLog(fs24, paths.usageLogDir, nowMs);
35307
35307
  prunedDay = day;
35308
35308
  }
35309
- fs23.appendFilePrivate(import_node_path26.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
35309
+ fs24.appendFilePrivate(import_node_path26.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
35310
35310
  `);
35311
35311
  if (record2.identity !== void 0) {
35312
35312
  rewriteSnapshot(record2.identity, (current) => ({ ...current?.providers, [record2.provider]: foldProviderState(current?.providers[record2.provider], record2) }));
@@ -35348,14 +35348,14 @@ var init_store2 = __esm({
35348
35348
  function errorMessage(error63) {
35349
35349
  return error63 instanceof Error ? error63.message : String(error63);
35350
35350
  }
35351
- function loadPoolMembers(fs23, paths, identities, nowMs) {
35351
+ function loadPoolMembers(fs24, paths, identities, nowMs) {
35352
35352
  const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
35353
- const log = readUsageLog(fs23, paths.usageLogDir, { sinceMs: windowStartMs });
35353
+ const log = readUsageLog(fs24, paths.usageLogDir, { sinceMs: windowStartMs });
35354
35354
  return identities.map((identity) => {
35355
35355
  const records = log.records.filter((record2) => record2.identity === identity && record2.provider === ANTHROPIC_PROVIDER && Date.parse(record2.at) >= windowStartMs);
35356
35356
  try {
35357
- const snapshot = readUsageSnapshot(fs23, paths.usageSnapshotsDir, identity);
35358
- const account = readAccountMetadata(fs23, paths.identitiesDir, identity) ?? snapshot?.account;
35357
+ const snapshot = readUsageSnapshot(fs24, paths.usageSnapshotsDir, identity);
35358
+ const account = readAccountMetadata(fs24, paths.identitiesDir, identity) ?? snapshot?.account;
35359
35359
  return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
35360
35360
  } catch (error63) {
35361
35361
  if (error63 instanceof UsageSnapshotError || error63 instanceof AccountMetadataError) {
@@ -35427,9 +35427,9 @@ function nestedMember(input2, nestedName, childStack, sticky) {
35427
35427
  missing: nested.missing
35428
35428
  };
35429
35429
  }
35430
- function readPicksFile(fs23, file2) {
35430
+ function readPicksFile(fs24, file2) {
35431
35431
  const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
35432
- const raw = fs23.readFileUtf8(file2);
35432
+ const raw = fs24.readFileUtf8(file2);
35433
35433
  if (raw === void 0) {
35434
35434
  return { file: empty };
35435
35435
  }
@@ -35442,17 +35442,17 @@ function readPicksFile(fs23, file2) {
35442
35442
  const result = PicksFileSchema.safeParse(parsed);
35443
35443
  return result.success ? { file: result.data } : { file: empty, problem: `${file2} is not a picks file this agent-shim can read` };
35444
35444
  }
35445
- function readStickyPick(fs23, picksFile, directory) {
35446
- const read = readPicksFile(fs23, picksFile);
35445
+ function readStickyPick(fs24, picksFile, directory) {
35446
+ const read = readPicksFile(fs24, picksFile);
35447
35447
  const entry = read.file.picks[directory];
35448
35448
  return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
35449
35449
  }
35450
- function recordStickyPick(fs23, picksFile, directory, identity, nowMs) {
35451
- const current = readPicksFile(fs23, picksFile).file.picks;
35450
+ function recordStickyPick(fs24, picksFile, directory, identity, nowMs) {
35451
+ const current = readPicksFile(fs24, picksFile).file.picks;
35452
35452
  const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
35453
35453
  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)}
35454
+ fs24.mkdirPrivate(import_node_path27.default.dirname(picksFile));
35455
+ fs24.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
35456
35456
  `);
35457
35457
  }
35458
35458
  var import_node_path27, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
@@ -61979,11 +61979,18 @@ var init_ensure2 = __esm({
61979
61979
  // src/frontdoor/probe.ts
61980
61980
  function probeFrontDoorSync(port, caPem) {
61981
61981
  refuseToBlockInRole("a synchronous probe of the front door");
61982
+ return runProbeWorker(PROBE_SOURCE, { port, ca: caPem });
61983
+ }
61984
+ function probeListenerAcceptSync(port) {
61985
+ refuseToBlockInRole("a synchronous probe of a front door listener");
61986
+ return runProbeWorker(ACCEPT_PROBE_SOURCE, { port });
61987
+ }
61988
+ function runProbeWorker(source, data) {
61982
61989
  const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
61983
61990
  const header = new Int32Array(shared, 0, HEADER_SLOTS);
61984
- const worker = new import_node_worker_threads.Worker(PROBE_SOURCE, {
61991
+ const worker = new import_node_worker_threads.Worker(source, {
61985
61992
  eval: true,
61986
- workerData: { port, ca: caPem, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
61993
+ workerData: { ...data, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
61987
61994
  });
61988
61995
  worker.unref();
61989
61996
  try {
@@ -62001,7 +62008,7 @@ function probeFrontDoorSync(port, caPem) {
62001
62008
  void worker.terminate();
62002
62009
  }
62003
62010
  }
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;
62011
+ 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
62012
  var init_probe = __esm({
62006
62013
  "src/frontdoor/probe.ts"() {
62007
62014
  "use strict";
@@ -62044,6 +62051,27 @@ const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca],
62044
62051
  // 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
62052
  setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
62046
62053
  request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
62054
+ `;
62055
+ ACCEPT_PROBE_SOURCE = `
62056
+ const { workerData } = require("node:worker_threads");
62057
+ const net = require("node:net");
62058
+ const { port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
62059
+ const header = new Int32Array(shared, 0, headerSlots);
62060
+ const reason = new Uint8Array(shared, headerSlots * 4);
62061
+ let done = false;
62062
+ const finish = (verdict, message) => {
62063
+ if (done) return;
62064
+ done = true;
62065
+ const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
62066
+ reason.set(bytes);
62067
+ Atomics.store(header, 1, bytes.length);
62068
+ Atomics.store(header, 0, verdict);
62069
+ Atomics.notify(header, 0);
62070
+ };
62071
+ const socket = net.connect({ host: "127.0.0.1", port });
62072
+ socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
62073
+ socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
62074
+ setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
62047
62075
  `;
62048
62076
  }
62049
62077
  });
@@ -62064,14 +62092,14 @@ var init_selfIdentity = __esm({
62064
62092
 
62065
62093
  // src/frontdoor/trust.ts
62066
62094
  function resolveTrustBundle(params) {
62067
- const { caCertFile, bundlesDir, variable, inherited, fs: fs23 } = params;
62095
+ const { caCertFile, bundlesDir, variable, inherited, fs: fs24 } = params;
62068
62096
  if (inherited === void 0 || inherited === "" || import_node_path35.default.resolve(inherited) === import_node_path35.default.resolve(caCertFile)) {
62069
62097
  return { path: caCertFile };
62070
62098
  }
62071
- const caPem = fs23.readFileUtf8(caCertFile);
62099
+ const caPem = fs24.readFileUtf8(caCertFile);
62072
62100
  let inheritedPem;
62073
62101
  try {
62074
- inheritedPem = fs23.readFileUtf8(inherited);
62102
+ inheritedPem = fs24.readFileUtf8(inherited);
62075
62103
  } catch (error63) {
62076
62104
  return {
62077
62105
  path: caCertFile,
@@ -62084,9 +62112,9 @@ function resolveTrustBundle(params) {
62084
62112
  const combined = `${inheritedPem.trimEnd()}
62085
62113
  ${caPem}`;
62086
62114
  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);
62115
+ if (!fs24.exists(bundle)) {
62116
+ fs24.mkdirp(bundlesDir);
62117
+ fs24.writeFileAtomic(bundle, combined);
62090
62118
  }
62091
62119
  return { path: bundle };
62092
62120
  }
@@ -62253,20 +62281,20 @@ function lockHolder(contents) {
62253
62281
  const pid = Number((contents ?? "").trim());
62254
62282
  return Number.isInteger(pid) && pid > 0 ? pid : void 0;
62255
62283
  }
62256
- function acquireUpdateLock(fs23, isProcessAlive, pid, lockPath) {
62257
- const take = () => fs23.writeFileExclusive(lockPath, `${String(pid)}
62284
+ function acquireUpdateLock(fs24, isProcessAlive, pid, lockPath) {
62285
+ const take = () => fs24.writeFileExclusive(lockPath, `${String(pid)}
62258
62286
  `);
62259
62287
  const release = () => {
62260
- fs23.unlink(lockPath);
62288
+ fs24.unlink(lockPath);
62261
62289
  };
62262
62290
  if (take()) {
62263
62291
  return release;
62264
62292
  }
62265
- const holder = lockHolder(fs23.readFileUtf8(lockPath));
62293
+ const holder = lockHolder(fs24.readFileUtf8(lockPath));
62266
62294
  if (holder !== void 0 && holder !== pid && isProcessAlive(holder)) {
62267
62295
  throw new UpdateConflictError(`another agent-shim update (pid ${String(holder)}) is already running`);
62268
62296
  }
62269
- fs23.unlink(lockPath);
62297
+ fs24.unlink(lockPath);
62270
62298
  if (!take()) {
62271
62299
  throw new UpdateConflictError("another agent-shim update took the lock while it was being replaced");
62272
62300
  }
@@ -63117,7 +63145,7 @@ function contextTokensOfTranscript(text2) {
63117
63145
  }
63118
63146
  return void 0;
63119
63147
  }
63120
- function resumedContextTokens(fs23, params) {
63148
+ function resumedContextTokens(fs24, params) {
63121
63149
  const target = resumeTargetOf(params.passthrough);
63122
63150
  if (target === void 0) {
63123
63151
  return void 0;
@@ -63128,19 +63156,19 @@ function resumedContextTokens(fs23, params) {
63128
63156
  file2 = import_node_path40.default.join(projectDir, `${target.id}.jsonl`);
63129
63157
  } else {
63130
63158
  let newestMs = -Infinity;
63131
- for (const name of fs23.readdir(projectDir)) {
63159
+ for (const name of fs24.readdir(projectDir)) {
63132
63160
  if (!name.endsWith(".jsonl")) {
63133
63161
  continue;
63134
63162
  }
63135
63163
  const candidate = import_node_path40.default.join(projectDir, name);
63136
- const stat = fs23.lstat(candidate);
63164
+ const stat = fs24.lstat(candidate);
63137
63165
  if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
63138
63166
  newestMs = stat.mtimeMs;
63139
63167
  file2 = candidate;
63140
63168
  }
63141
63169
  }
63142
63170
  }
63143
- const text2 = file2 === void 0 ? void 0 : fs23.readFileUtf8(file2);
63171
+ const text2 = file2 === void 0 ? void 0 : fs24.readFileUtf8(file2);
63144
63172
  return text2 === void 0 ? void 0 : contextTokensOfTranscript(text2);
63145
63173
  }
63146
63174
  var import_node_path40;
@@ -63258,7 +63286,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
63258
63286
  return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
63259
63287
  }
63260
63288
  function pickFromPool(decided, params, parsedArgv, readOnly) {
63261
- const { paths, fs: fs23, proc, log } = params;
63289
+ const { paths, fs: fs24, proc, log } = params;
63262
63290
  if (decided.pool === void 0) {
63263
63291
  return { identityDecision: decided };
63264
63292
  }
@@ -63273,7 +63301,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
63273
63301
  selectedVia: decided.source,
63274
63302
  pools: params.pools,
63275
63303
  paths,
63276
- fs: fs23,
63304
+ fs: fs24,
63277
63305
  usageFs: farmRuntime.fs,
63278
63306
  cwd: farmRuntime.cwd,
63279
63307
  now: farmRuntime.now,
@@ -63296,7 +63324,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
63296
63324
  };
63297
63325
  }
63298
63326
  function decideLaunch(params, readOnly) {
63299
- const { paths, fs: fs23, proc, log } = params;
63327
+ const { paths, fs: fs24, proc, log } = params;
63300
63328
  const { env, argv } = proc;
63301
63329
  const parsedArgv = parseLauncherArgv(argv);
63302
63330
  const cliOverride = buildCliOverride({
@@ -63311,7 +63339,7 @@ function decideLaunch(params, readOnly) {
63311
63339
  argv0Identity: parsedArgv.identity,
63312
63340
  directoryPinnedIdentity: params.directoryPinnedIdentity,
63313
63341
  readActiveIdentityFile: () => {
63314
- const raw = fs23.readFileUtf8(paths.activeIdentityFile);
63342
+ const raw = fs24.readFileUtf8(paths.activeIdentityFile);
63315
63343
  if (raw === void 0) {
63316
63344
  return void 0;
63317
63345
  }
@@ -63346,7 +63374,7 @@ function decideLaunch(params, readOnly) {
63346
63374
  }
63347
63375
  let loadedIdentity;
63348
63376
  if (identityDecision.name !== void 0) {
63349
- loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs23);
63377
+ loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs24);
63350
63378
  if (loadedIdentity === void 0) {
63351
63379
  log.error(
63352
63380
  `agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
@@ -63361,7 +63389,7 @@ function decideLaunch(params, readOnly) {
63361
63389
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
63362
63390
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
63363
63391
  });
63364
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs23.readConfigFile(import_node_path41.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
63392
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs24.readConfigFile(import_node_path41.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
63365
63393
  log.error(
63366
63394
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
63367
63395
  );
@@ -63370,7 +63398,7 @@ function decideLaunch(params, readOnly) {
63370
63398
  const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
63371
63399
  const providerParams = {
63372
63400
  paths,
63373
- port: fs23,
63401
+ port: fs24,
63374
63402
  ...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
63375
63403
  ...farmContext === void 0 ? {} : { cascade: farmContext.cascade }
63376
63404
  };
@@ -104799,12 +104827,12 @@ var require_dist2 = __commonJS({
104799
104827
  throw new Error(`Unknown format "${name}"`);
104800
104828
  return f;
104801
104829
  };
104802
- function addFormats(ajv, list, fs23, exportName) {
104830
+ function addFormats(ajv, list, fs24, exportName) {
104803
104831
  var _a4;
104804
104832
  var _b2;
104805
104833
  (_a4 = (_b2 = ajv.opts.code).formats) !== null && _a4 !== void 0 ? _a4 : _b2.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
104806
104834
  for (const f of list)
104807
- ajv.addFormat(f, fs23[f]);
104835
+ ajv.addFormat(f, fs24[f]);
104808
104836
  }
104809
104837
  module2.exports = exports2 = formatsPlugin;
104810
104838
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -112532,7 +112560,7 @@ function registerCodexCommand(program2, deps) {
112532
112560
  // src/frontdoor/commands.ts
112533
112561
  var import_node_crypto21 = require("node:crypto");
112534
112562
  var import_node_path51 = __toESM(require("node:path"), 1);
112535
- var import_node_fs18 = __toESM(require("node:fs"), 1);
112563
+ var import_node_fs19 = __toESM(require("node:fs"), 1);
112536
112564
  init_commandDeps();
112537
112565
  init_schema();
112538
112566
  init_conditions();
@@ -112673,17 +112701,17 @@ function parseEntry2(project, entry) {
112673
112701
  const base = match?.[1];
112674
112702
  return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
112675
112703
  }
112676
- function listSessions2(fs23, configDir) {
112704
+ function listSessions2(fs24, configDir) {
112677
112705
  const found = [];
112678
- for (const project of fs23.readdir(import_node_path33.default.join(configDir, PROJECTS_DIR))) {
112706
+ for (const project of fs24.readdir(import_node_path33.default.join(configDir, PROJECTS_DIR))) {
112679
112707
  const projectDir = import_node_path33.default.join(configDir, PROJECTS_DIR, project);
112680
112708
  const entries = /* @__PURE__ */ new Set();
112681
- for (const name of fs23.readdir(projectDir)) {
112709
+ for (const name of fs24.readdir(projectDir)) {
112682
112710
  if (name.endsWith(TRANSCRIPT_SUFFIX)) {
112683
112711
  entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
112684
112712
  continue;
112685
112713
  }
112686
- const children = fs23.readdir(import_node_path33.default.join(projectDir, name));
112714
+ const children = fs24.readdir(import_node_path33.default.join(projectDir, name));
112687
112715
  if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
112688
112716
  entries.add(name);
112689
112717
  }
@@ -112694,9 +112722,9 @@ function listSessions2(fs23, configDir) {
112694
112722
  }
112695
112723
  return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
112696
112724
  }
112697
- function locateAgents(fs23, configDir, relativeDir, workflowRunId, report) {
112725
+ function locateAgents(fs24, configDir, relativeDir, workflowRunId, report) {
112698
112726
  const located = [];
112699
- for (const name of listDirOrReport(fs23, configDir, relativeDir, report)) {
112727
+ for (const name of listDirOrReport(fs24, configDir, relativeDir, report)) {
112700
112728
  if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
112701
112729
  continue;
112702
112730
  }
@@ -112745,17 +112773,17 @@ function toNode(read, children) {
112745
112773
  function describeFailure(error63) {
112746
112774
  return error63 instanceof Error ? error63.message : String(error63);
112747
112775
  }
112748
- function readFileOrReport(fs23, configDir, relative, report) {
112776
+ function readFileOrReport(fs24, configDir, relative, report) {
112749
112777
  try {
112750
- return fs23.readFileUtf8(import_node_path33.default.join(configDir, relative));
112778
+ return fs24.readFileUtf8(import_node_path33.default.join(configDir, relative));
112751
112779
  } catch (error63) {
112752
112780
  report({ path: relative, reason: `could not be read: ${describeFailure(error63)}` });
112753
112781
  return void 0;
112754
112782
  }
112755
112783
  }
112756
- function listDirOrReport(fs23, configDir, relative, report) {
112784
+ function listDirOrReport(fs24, configDir, relative, report) {
112757
112785
  try {
112758
- return fs23.readdir(import_node_path33.default.join(configDir, relative));
112786
+ return fs24.readdir(import_node_path33.default.join(configDir, relative));
112759
112787
  } catch (error63) {
112760
112788
  report({ path: relative, reason: `could not be listed: ${describeFailure(error63)}` });
112761
112789
  return [];
@@ -112778,22 +112806,22 @@ var WorkflowRunFileSchema = external_exports.object({
112778
112806
  phases: external_exports.array(external_exports.object({ title: external_exports.string() })).default([]),
112779
112807
  summary: external_exports.string().optional()
112780
112808
  });
112781
- function summariseSession(fs23, configDir, ref) {
112809
+ function summariseSession(fs24, configDir, ref) {
112782
112810
  const sessionRelative = import_node_path33.default.join(PROJECTS_DIR, ref.project, ref.entry);
112783
112811
  const subagentsRelative = import_node_path33.default.join(sessionRelative, SUBAGENTS_DIR);
112784
112812
  const workflowsUnderSubagents = import_node_path33.default.join(subagentsRelative, WORKFLOWS_DIR);
112785
112813
  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))) {
112814
+ let agentCount = fs24.readdir(import_node_path33.default.join(configDir, subagentsRelative)).filter(isMeta).length;
112815
+ for (const runDir of fs24.readdir(import_node_path33.default.join(configDir, workflowsUnderSubagents))) {
112788
112816
  if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
112789
- agentCount += fs23.readdir(import_node_path33.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
112817
+ agentCount += fs24.readdir(import_node_path33.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
112790
112818
  }
112791
112819
  }
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}`));
112820
+ 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;
112821
+ const transcript = fs24.lstat(import_node_path33.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
112794
112822
  return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
112795
112823
  }
112796
- function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112824
+ function readSessionAgentTree(fs24, configDir, ref, options = {}) {
112797
112825
  const problems = [];
112798
112826
  const report = (problem) => {
112799
112827
  problems.push(problem);
@@ -112801,15 +112829,15 @@ function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112801
112829
  const sessionRelative = import_node_path33.default.join(PROJECTS_DIR, ref.project, ref.entry);
112802
112830
  const subagentsRelative = import_node_path33.default.join(sessionRelative, SUBAGENTS_DIR);
112803
112831
  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)) {
112832
+ const located = locateAgents(fs24, configDir, subagentsRelative, void 0, report);
112833
+ for (const runDir of listDirOrReport(fs24, configDir, workflowsUnderSubagents, report)) {
112806
112834
  if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
112807
- located.push(...locateAgents(fs23, configDir, import_node_path33.default.join(workflowsUnderSubagents, runDir), runDir, report));
112835
+ located.push(...locateAgents(fs24, configDir, import_node_path33.default.join(workflowsUnderSubagents, runDir), runDir, report));
112808
112836
  }
112809
112837
  }
112810
112838
  const agents = /* @__PURE__ */ new Map();
112811
112839
  for (const candidate of located) {
112812
- const text2 = readFileOrReport(fs23, configDir, candidate.metaPath, report);
112840
+ const text2 = readFileOrReport(fs24, configDir, candidate.metaPath, report);
112813
112841
  if (text2 === void 0) {
112814
112842
  continue;
112815
112843
  }
@@ -112821,7 +112849,7 @@ function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112821
112849
  agents.set(candidate.id, { located: candidate, meta: parsed.data });
112822
112850
  }
112823
112851
  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);
112852
+ const parentOf4 = resolveParents(fs24, configDir, agents, report);
112825
112853
  const childrenOf = /* @__PURE__ */ new Map();
112826
112854
  const roots = [];
112827
112855
  for (const id2 of agents.keys()) {
@@ -112844,12 +112872,12 @@ function readSessionAgentTree(fs23, configDir, ref, options = {}) {
112844
112872
  sessionId: ref.sessionId,
112845
112873
  superseded: ref.superseded,
112846
112874
  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),
112875
+ tasks: readTasks(fs24, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id2) => !ownTaskLists(ref.sessionId).includes(id2)), report),
112876
+ workflowRuns: readWorkflowRuns(fs24, configDir, import_node_path33.default.join(sessionRelative, WORKFLOWS_DIR), report),
112849
112877
  problems
112850
112878
  };
112851
112879
  }
112852
- function resolveParents(fs23, configDir, agents, report) {
112880
+ function resolveParents(fs24, configDir, agents, report) {
112853
112881
  const parentOf4 = /* @__PURE__ */ new Map();
112854
112882
  const transcriptCache = /* @__PURE__ */ new Map();
112855
112883
  const transcriptOf = (agent) => {
@@ -112857,7 +112885,7 @@ function resolveParents(fs23, configDir, agents, report) {
112857
112885
  if (cached2 !== void 0) {
112858
112886
  return cached2;
112859
112887
  }
112860
- const text2 = readFileOrReport(fs23, configDir, agent.located.transcriptPath, report) ?? "";
112888
+ const text2 = readFileOrReport(fs24, configDir, agent.located.transcriptPath, report) ?? "";
112861
112889
  transcriptCache.set(agent.located.id, text2);
112862
112890
  return text2;
112863
112891
  };
@@ -112907,16 +112935,16 @@ function resolveParents(fs23, configDir, agents, report) {
112907
112935
  function ownTaskLists(sessionId) {
112908
112936
  return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
112909
112937
  }
112910
- function readTasks(fs23, configDir, ownLists, sharedLists, report) {
112938
+ function readTasks(fs24, configDir, ownLists, sharedLists, report) {
112911
112939
  const tasks = [];
112912
112940
  [...ownLists, ...sharedLists].forEach((scope, index) => {
112913
112941
  const relativeDir = import_node_path33.default.join(TASKS_DIR, scope);
112914
- for (const name of [...listDirOrReport(fs23, configDir, relativeDir, report)].sort()) {
112942
+ for (const name of [...listDirOrReport(fs24, configDir, relativeDir, report)].sort()) {
112915
112943
  if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
112916
112944
  continue;
112917
112945
  }
112918
112946
  const relative = import_node_path33.default.join(relativeDir, name);
112919
- const text2 = readFileOrReport(fs23, configDir, relative, report);
112947
+ const text2 = readFileOrReport(fs24, configDir, relative, report);
112920
112948
  const parsed = TaskFileSchema.safeParse(text2 === void 0 ? void 0 : parseJson3(text2));
112921
112949
  if (parsed.success) {
112922
112950
  tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
@@ -112927,14 +112955,14 @@ function readTasks(fs23, configDir, ownLists, sharedLists, report) {
112927
112955
  });
112928
112956
  return tasks;
112929
112957
  }
112930
- function readWorkflowRuns(fs23, configDir, relativeDir, report) {
112958
+ function readWorkflowRuns(fs24, configDir, relativeDir, report) {
112931
112959
  const runs = [];
112932
- for (const name of [...listDirOrReport(fs23, configDir, relativeDir, report)].sort()) {
112960
+ for (const name of [...listDirOrReport(fs24, configDir, relativeDir, report)].sort()) {
112933
112961
  if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
112934
112962
  continue;
112935
112963
  }
112936
112964
  const relative = import_node_path33.default.join(relativeDir, name);
112937
- const text2 = readFileOrReport(fs23, configDir, relative, report);
112965
+ const text2 = readFileOrReport(fs24, configDir, relative, report);
112938
112966
  const parsed = WorkflowRunFileSchema.safeParse(text2 === void 0 ? void 0 : parseJson3(text2));
112939
112967
  if (!parsed.success) {
112940
112968
  if (text2 !== void 0) {
@@ -112958,11 +112986,11 @@ var SessionLookupError = class extends CliError {
112958
112986
  function identityConfigDir(identitiesDir, identity) {
112959
112987
  return import_node_path34.default.join(identitiesDir, identity);
112960
112988
  }
112961
- function historyStores(fs23, identitiesDir, identities) {
112989
+ function historyStores(fs24, identitiesDir, identities) {
112962
112990
  const byRealPath = /* @__PURE__ */ new Map();
112963
112991
  for (const identity of identities) {
112964
112992
  const configDir = identityConfigDir(identitiesDir, identity);
112965
- const real = fs23.realpath(import_node_path34.default.join(configDir, "projects"));
112993
+ const real = fs24.realpath(import_node_path34.default.join(configDir, "projects"));
112966
112994
  if (real === void 0) {
112967
112995
  continue;
112968
112996
  }
@@ -112975,15 +113003,15 @@ function historyStores(fs23, identitiesDir, identities) {
112975
113003
  }
112976
113004
  return [...byRealPath.values()];
112977
113005
  }
112978
- function collectSessionList(fs23, identitiesDir, identities, filters) {
113006
+ function collectSessionList(fs24, identitiesDir, identities, filters) {
112979
113007
  const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
112980
113008
  if (filters.identity !== void 0 && names.length === 0) {
112981
113009
  throw new SessionLookupError(`no identity named "${filters.identity}"`);
112982
113010
  }
112983
113011
  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);
113012
+ for (const store of historyStores(fs24, identitiesDir, names)) {
113013
+ for (const ref of listSessions2(fs24, store.configDir)) {
113014
+ const summary = summariseSession(fs24, store.configDir, ref);
112987
113015
  if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
112988
113016
  sessions.push({ ...summary, identities: store.identities });
112989
113017
  }
@@ -112991,14 +113019,14 @@ function collectSessionList(fs23, identitiesDir, identities, filters) {
112991
113019
  }
112992
113020
  return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
112993
113021
  }
112994
- function locateSession(fs23, identitiesDir, identities, query, onlyIdentity) {
113022
+ function locateSession(fs24, identitiesDir, identities, query, onlyIdentity) {
112995
113023
  const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
112996
113024
  if (onlyIdentity !== void 0 && names.length === 0) {
112997
113025
  throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
112998
113026
  }
112999
113027
  const matches = [];
113000
- for (const store of historyStores(fs23, identitiesDir, names)) {
113001
- for (const ref of listSessions2(fs23, store.configDir)) {
113028
+ for (const store of historyStores(fs24, identitiesDir, names)) {
113029
+ for (const ref of listSessions2(fs24, store.configDir)) {
113002
113030
  if (ref.sessionId.startsWith(query)) {
113003
113031
  matches.push({ identities: store.identities, configDir: store.configDir, ref });
113004
113032
  }
@@ -113015,9 +113043,9 @@ function locateSession(fs23, identitiesDir, identities, query, onlyIdentity) {
113015
113043
  }
113016
113044
  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
113045
  }
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) };
113046
+ function showSession(fs24, identitiesDir, identities, query, onlyIdentity) {
113047
+ const located = locateSession(fs24, identitiesDir, identities, query, onlyIdentity);
113048
+ return { identities: located.identities, tree: readSessionAgentTree(fs24, located.configDir, located.ref) };
113021
113049
  }
113022
113050
 
113023
113051
  // src/frontdoor/commands.ts
@@ -113389,8 +113417,8 @@ var StampsFileSchema = external_exports.strictObject({
113389
113417
  schemaVersion: external_exports.literal(STAMPS_SCHEMA_VERSION),
113390
113418
  handled: external_exports.record(external_exports.string().min(1), external_exports.iso.datetime())
113391
113419
  });
113392
- function readHandled(fs23, file2) {
113393
- const raw = fs23.readFileUtf8(file2);
113420
+ function readHandled(fs24, file2) {
113421
+ const raw = fs24.readFileUtf8(file2);
113394
113422
  if (raw === void 0) {
113395
113423
  return {};
113396
113424
  }
@@ -113403,10 +113431,10 @@ function readHandled(fs23, file2) {
113403
113431
  const result = StampsFileSchema.safeParse(parsed);
113404
113432
  return result.success ? Object.fromEntries(Object.entries(result.data.handled).map(([key, at2]) => [key, Date.parse(at2)])) : {};
113405
113433
  }
113406
- function writeHandled(fs23, file2, handled) {
113434
+ function writeHandled(fs24, file2, handled) {
113407
113435
  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)}
113436
+ fs24.mkdirPrivate(import_node_path43.default.dirname(file2));
113437
+ fs24.writeFilePrivate(file2, `${JSON.stringify(next, null, 2)}
113410
113438
  `);
113411
113439
  }
113412
113440
 
@@ -114167,9 +114195,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
114167
114195
  }
114168
114196
  }
114169
114197
  async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114170
- const { fs: fs23, paths } = ports;
114198
+ const { fs: fs24, paths } = ports;
114171
114199
  const servingBinary = ports.statOwnExecutable();
114172
- const previous = readFrontDoorState(fs23, paths.frontdoorStateFile);
114200
+ const previous = readFrontDoorState(fs24, paths.frontdoorStateFile);
114173
114201
  let lastPort = previous?.lastPort;
114174
114202
  let lastConnectPort = previous?.lastConnectPort;
114175
114203
  let lastDirectPort = previous?.lastDirectPort;
@@ -114180,12 +114208,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114180
114208
  });
114181
114209
  const fail = (message) => {
114182
114210
  ports.closeRcStreamHub();
114183
- writeFrontDoorState(fs23, paths.frontdoorStateFile, { lastError: message, ...sticky() });
114184
- fs23.removeRecursive(paths.frontdoorLockFile);
114211
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, { lastError: message, ...sticky() });
114212
+ fs24.removeRecursive(paths.frontdoorLockFile);
114185
114213
  ports.log(`agent-shim frontdoor supervisor: ${message}`);
114186
114214
  return 1;
114187
114215
  };
114188
- writeFrontDoorState(fs23, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
114216
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
114189
114217
  const previousSticky = lastPort;
114190
114218
  let http8;
114191
114219
  try {
@@ -114225,15 +114253,16 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114225
114253
  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
114254
  }
114227
114255
  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() });
114256
+ writeFrontDoorDirectRecord(fs24, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
114257
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http8.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
114230
114258
  ports.doorHealth.generation({ providerPort: http8.port, connectPort: connect3.port, directPort: direct.port });
114231
- fs23.removeRecursive(paths.frontdoorLockFile);
114259
+ fs24.removeRecursive(paths.frontdoorLockFile);
114232
114260
  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)}`);
114261
+ const watchdog = ports.startWatchdog?.();
114233
114262
  let idleSince;
114234
114263
  let ticks = 0;
114235
114264
  const supersedingOwner = () => {
114236
- const owner = readFrontDoorState(fs23, paths.frontdoorStateFile)?.supervisorPid;
114265
+ const owner = readFrontDoorState(fs24, paths.frontdoorStateFile)?.supervisorPid;
114237
114266
  return owner !== void 0 && owner !== ports.ownPid && ports.isRunning(owner) ? owner : void 0;
114238
114267
  };
114239
114268
  let supersededBy;
@@ -114243,26 +114272,29 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
114243
114272
  return current !== void 0 && servingBinary !== void 0 && (current.dev !== servingBinary.dev || current.ino !== servingBinary.ino || current.size !== servingBinary.size || current.mtimeMs !== servingBinary.mtimeMs);
114244
114273
  };
114245
114274
  const closeServing = async () => {
114275
+ watchdog?.stop();
114246
114276
  await direct.close();
114247
114277
  await connect3.close();
114248
114278
  await http8.close();
114249
114279
  ports.closeRcStreamHub();
114250
- removeFrontDoorDirectRecord(fs23, paths.frontdoorDirectRecordsDir, ports.ownPid);
114280
+ removeFrontDoorDirectRecord(fs24, paths.frontdoorDirectRecordsDir, ports.ownPid);
114251
114281
  };
114252
114282
  const shutdown = async () => {
114253
114283
  await closeServing();
114254
114284
  if (supersedingOwner() === void 0) {
114255
- writeFrontDoorState(fs23, paths.frontdoorStateFile, sticky());
114285
+ writeFrontDoorState(fs24, paths.frontdoorStateFile, sticky());
114256
114286
  }
114257
114287
  return 0;
114258
114288
  };
114259
114289
  for (; ; ) {
114290
+ watchdog?.beat();
114260
114291
  if (options.tickLimit !== void 0 && ticks >= options.tickLimit) {
114292
+ watchdog?.stop();
114261
114293
  return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
114262
114294
  }
114263
114295
  ticks += 1;
114264
- const listed = listFrontDoorSessions(fs23, paths.frontdoorSessionsDir);
114265
- const pruned = pruneDeadFrontDoorSessions(fs23, paths.frontdoorSessionsDir, ports.isRunning);
114296
+ const listed = listFrontDoorSessions(fs24, paths.frontdoorSessionsDir);
114297
+ const pruned = pruneDeadFrontDoorSessions(fs24, paths.frontdoorSessionsDir, ports.isRunning);
114266
114298
  ports.observeLaunchRegistry(listed, pruned);
114267
114299
  ports.checkQuotaExpiry();
114268
114300
  const prunedPids = new Set(pruned);
@@ -116742,7 +116774,7 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
116742
116774
  init_claudeShim();
116743
116775
  init_store();
116744
116776
  init_realPorts();
116745
- var import_node_fs17 = __toESM(require("node:fs"), 1);
116777
+ var import_node_fs18 = __toESM(require("node:fs"), 1);
116746
116778
  var import_node_path46 = __toESM(require("node:path"), 1);
116747
116779
 
116748
116780
  // src/usage/signIn.ts
@@ -116766,12 +116798,12 @@ function decideSignIn(facts) {
116766
116798
  function credentialsFilePath(farmRoot) {
116767
116799
  return import_node_path45.default.join(farmRoot, CREDENTIALS_FILE);
116768
116800
  }
116769
- function identitySignIn(fs23, probe, identity) {
116801
+ function identitySignIn(fs24, probe, identity) {
116770
116802
  const probing = !identity.hasCredentialBlock;
116771
116803
  return decideSignIn({
116772
116804
  hasCredentialBlock: identity.hasCredentialBlock,
116773
116805
  keychainItem: probing && probe.platform === "darwin" && probe.run !== void 0 ? keychainHasItem(probe.run, identity.farmRoot) : void 0,
116774
- credentialsFile: probing && fs23.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
116806
+ credentialsFile: probing && fs24.lstat(credentialsFilePath(identity.farmRoot)) !== void 0,
116775
116807
  platform: probe.platform
116776
116808
  });
116777
116809
  }
@@ -116897,6 +116929,53 @@ function pushFrontDoor(push, supervisors, registeredPid, liveSessions) {
116897
116929
  );
116898
116930
  }
116899
116931
  }
116932
+ var LISTENER_ROUTES = {
116933
+ provider: "provider sessions (`z`, `m` and the like)",
116934
+ connect: "every plain OAuth session, which reaches Anthropic through it"
116935
+ };
116936
+ function pushFrontDoorListeners(push, readings) {
116937
+ for (const reading of readings) {
116938
+ const where = `127.0.0.1:${String(reading.port)}`;
116939
+ if (reading.ok) {
116940
+ push("frontdoor", "pass", `The front door's ${reading.listener} listener on ${where} accepted a probe in ${String(Math.round(reading.elapsedMs))} ms.`, reading.listener);
116941
+ continue;
116942
+ }
116943
+ push(
116944
+ "frontdoor",
116945
+ "fail",
116946
+ `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.`,
116947
+ reading.listener
116948
+ );
116949
+ }
116950
+ }
116951
+
116952
+ // src/frontdoor/listenerReadings.ts
116953
+ var import_node_fs17 = __toESM(require("node:fs"), 1);
116954
+ init_probe();
116955
+ function readFrontDoorListeners(state, supervisorAlive, probes) {
116956
+ if (!supervisorAlive) {
116957
+ return [];
116958
+ }
116959
+ const readings = [];
116960
+ const take = (listener, port, probe) => {
116961
+ if (port === void 0) {
116962
+ return;
116963
+ }
116964
+ const started = probes.now();
116965
+ const verdict = probe(port);
116966
+ readings.push({ listener, port, ok: verdict.ok, ...verdict.ok ? {} : { reason: verdict.reason }, elapsedMs: Math.max(0, probes.now() - started) });
116967
+ };
116968
+ take("provider", state.port, probes.authenticateProvider);
116969
+ take("connect", state.connectPort, probes.connect);
116970
+ return readings;
116971
+ }
116972
+ function realFrontDoorListenerProbes(paths) {
116973
+ return {
116974
+ authenticateProvider: (port) => probeFrontDoorSync(port, import_node_fs17.default.readFileSync(paths.frontdoorCaCertFile, "utf8")),
116975
+ connect: probeListenerAcceptSync,
116976
+ now: () => performance.now()
116977
+ };
116978
+ }
116900
116979
 
116901
116980
  // src/doctorReport.ts
116902
116981
  init_supervisorProcesses();
@@ -117341,6 +117420,9 @@ function runDoctor(params) {
117341
117420
  if (params.frontDoor !== void 0) {
117342
117421
  const validated2 = params.frontDoor.state.raw === void 0 ? void 0 : validateJson(FrontDoorStateSchema, params.frontDoor.state);
117343
117422
  pushFrontDoor(push, params.frontDoor.supervisors, validated2?.ok === true ? validated2.data.supervisorPid : void 0, params.frontDoor.liveSessions);
117423
+ if (params.frontDoor.listeners !== void 0) {
117424
+ pushFrontDoorListeners(push, params.frontDoor.listeners);
117425
+ }
117344
117426
  }
117345
117427
  if (params.activeIdentity.raw === void 0) {
117346
117428
  push("active-identity", "pass", "No active identity set.");
@@ -117424,25 +117506,30 @@ function formatDoctorReport(report) {
117424
117506
  }
117425
117507
  function realpathOrSelf(target) {
117426
117508
  try {
117427
- return import_node_fs17.default.realpathSync(target);
117509
+ return import_node_fs18.default.realpathSync(target);
117428
117510
  } catch {
117429
117511
  return target;
117430
117512
  }
117431
117513
  }
117514
+ function servingDoorListeners(paths) {
117515
+ const state = readFrontDoorState(realFarmFs, paths.frontdoorStateFile) ?? {};
117516
+ const alive = state.supervisorPid !== void 0 && realIsProcessRunning(state.supervisorPid);
117517
+ return readFrontDoorListeners(state, alive, realFrontDoorListenerProbes(paths));
117518
+ }
117432
117519
  function collectDoctorReport(params) {
117433
117520
  const { paths } = params;
117434
- 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() : [];
117521
+ 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() : [];
117435
117522
  const identities = identityNames.map((name) => {
117436
117523
  const farmRoot = import_node_path46.default.join(paths.identitiesDir, name);
117437
117524
  const identityPath = import_node_path46.default.join(farmRoot, "identity.json");
117438
- return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs17.default.existsSync(credentialsFilePath(farmRoot)) };
117525
+ return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs18.default.existsSync(credentialsFilePath(farmRoot)) };
117439
117526
  });
117440
- 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() : [];
117527
+ 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() : [];
117441
117528
  const configProfiles = profileNames.map((name) => {
117442
117529
  const profilePath = import_node_path46.default.join(paths.configProfilesDir, `${name}.json`);
117443
117530
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
117444
117531
  });
117445
- 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() : [];
117532
+ 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() : [];
117446
117533
  const providers = providerNames.map((name) => {
117447
117534
  const providerPath = import_node_path46.default.join(paths.providersDir, `${name}.json`);
117448
117535
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
@@ -117487,7 +117574,7 @@ function collectDoctorReport(params) {
117487
117574
  categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
117488
117575
  activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
117489
117576
  binaryDiscovery,
117490
- claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs17.default.existsSync(shimState.targetPath) },
117577
+ claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs18.default.existsSync(shimState.targetPath) },
117491
117578
  rootPath: paths.root,
117492
117579
  pathResolution: {
117493
117580
  ownExecutablePath,
@@ -117527,7 +117614,7 @@ function collectDoctorReport(params) {
117527
117614
  logPath: paths.headroomLogPath
117528
117615
  }
117529
117616
  },
117530
- ...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)) } }
117617
+ ...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) } }
117531
117618
  });
117532
117619
  return report;
117533
117620
  }
@@ -128459,8 +128546,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
128459
128546
  function isRecord8(value2) {
128460
128547
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
128461
128548
  }
128462
- function readJsonObject(fs23, file2) {
128463
- const raw = fs23.readFileUtf8(file2);
128549
+ function readJsonObject(fs24, file2) {
128550
+ const raw = fs24.readFileUtf8(file2);
128464
128551
  if (raw === void 0) {
128465
128552
  return void 0;
128466
128553
  }
@@ -128472,8 +128559,8 @@ function readJsonObject(fs23, file2) {
128472
128559
  }
128473
128560
  return isRecord8(parsed) ? parsed : void 0;
128474
128561
  }
128475
- function readRcSelfHostRecord(fs23, frontdoorDir) {
128476
- const parsed = readJsonObject(fs23, import_node_path49.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
128562
+ function readRcSelfHostRecord(fs24, frontdoorDir) {
128563
+ const parsed = readJsonObject(fs24, import_node_path49.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
128477
128564
  if (parsed === void 0) {
128478
128565
  return void 0;
128479
128566
  }
@@ -128918,11 +129005,11 @@ function credentialOfJson(parsed) {
128918
129005
  function sequenceNumOfJson(value2) {
128919
129006
  return typeof value2 === "number" && Number.isInteger(value2) && value2 >= 0 ? value2 : void 0;
128920
129007
  }
128921
- function createRcCredentialStore(fs23, dir) {
128922
- fs23.mkdirPrivate(dir);
129008
+ function createRcCredentialStore(fs24, dir) {
129009
+ fs24.mkdirPrivate(dir);
128923
129010
  const fileFor = (sessionId) => import_node_path50.default.join(dir, `${sessionId}.json`);
128924
129011
  const readParsed = (sessionId) => {
128925
- const raw = fs23.readFileUtf8(fileFor(sessionId));
129012
+ const raw = fs24.readFileUtf8(fileFor(sessionId));
128926
129013
  if (raw === void 0) {
128927
129014
  return void 0;
128928
129015
  }
@@ -128947,7 +129034,7 @@ function createRcCredentialStore(fs23, dir) {
128947
129034
  }
128948
129035
  const cursor3 = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
128949
129036
  const record2 = { ...credential, ...cursor3 === void 0 ? {} : { highestSequenceNum: cursor3 } };
128950
- fs23.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
129037
+ fs24.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
128951
129038
  `);
128952
129039
  },
128953
129040
  readCursor: (sessionId) => {
@@ -128962,14 +129049,14 @@ function createRcCredentialStore(fs23, dir) {
128962
129049
  }
128963
129050
  const credential = credentialOfJson(readParsed(sessionId));
128964
129051
  const record2 = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
128965
- fs23.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
129052
+ fs24.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record2, null, 2)}
128966
129053
  `);
128967
129054
  },
128968
129055
  remove: (sessionId) => {
128969
129056
  if (!isSafeSessionId(sessionId)) {
128970
129057
  return;
128971
129058
  }
128972
- fs23.removeRecursive(fileFor(sessionId));
129059
+ fs24.removeRecursive(fileFor(sessionId));
128973
129060
  }
128974
129061
  };
128975
129062
  }
@@ -130991,6 +131078,93 @@ function createRcStreamHub(deps) {
130991
131078
  };
130992
131079
  }
130993
131080
 
131081
+ // src/frontdoor/watchdog.ts
131082
+ var import_node_worker_threads2 = require("node:worker_threads");
131083
+ init_ensure2();
131084
+ init_probe();
131085
+ var DOOR_STALL_BOUND_MS = 2 * FRONTDOOR_PROBE_ATTEMPTS * PROBE_TIMEOUT_MS;
131086
+ var CHECKS_PER_PROBE_DEADLINE = 2;
131087
+ var DOOR_WATCHDOG_CHECK_MS = PROBE_TIMEOUT_MS / CHECKS_PER_PROBE_DEADLINE;
131088
+ var WATCHDOG_SOURCE = `
131089
+ const { workerData, parentPort } = require("node:worker_threads");
131090
+ const fs = require("node:fs");
131091
+ const { shared, boundMs, checkEveryMs, stateFile, ownPid, action } = workerData;
131092
+ const counter = new Int32Array(shared);
131093
+ let lastValue = Atomics.load(counter, 0);
131094
+ let lastChangeAt = Date.now();
131095
+ let lastCheckAt = Date.now();
131096
+ let stopped = false;
131097
+ const record = (message) => {
131098
+ try {
131099
+ const existing = JSON.parse(fs.readFileSync(stateFile, "utf8"));
131100
+ const next = Object.assign({}, existing, { lastError: message });
131101
+ const temporary = stateFile + "." + String(ownPid) + ".watchdog";
131102
+ fs.writeFileSync(temporary, JSON.stringify(next, null, 2) + "\\n", { mode: 0o600 });
131103
+ fs.renameSync(temporary, stateFile);
131104
+ } catch (error) {
131105
+ // The state file is a courtesy to whoever looks next; the process still has to end.
131106
+ }
131107
+ };
131108
+ const timer = setInterval(() => {
131109
+ if (stopped) return;
131110
+ const now = Date.now();
131111
+ const sinceLastCheck = now - lastCheckAt;
131112
+ lastCheckAt = now;
131113
+ const value = Atomics.load(counter, 0);
131114
+ if (value !== lastValue || sinceLastCheck > checkEveryMs * 2) {
131115
+ lastValue = value;
131116
+ lastChangeAt = now;
131117
+ return;
131118
+ }
131119
+ if (now - lastChangeAt >= boundMs) {
131120
+ const message = "the front door's event loop did not run for " + String(now - lastChangeAt) + "ms; its watchdog ended the process so the next launch starts a fresh door on the same ports";
131121
+ record(message);
131122
+ stopped = true;
131123
+ clearInterval(timer);
131124
+ if (action === "kill-process") {
131125
+ process.kill(ownPid, "SIGKILL");
131126
+ } else {
131127
+ parentPort.postMessage({ stalled: true, message });
131128
+ }
131129
+ }
131130
+ }, checkEveryMs);
131131
+ parentPort.on("message", (message) => {
131132
+ if (message === "stop") {
131133
+ stopped = true;
131134
+ clearInterval(timer);
131135
+ process.exit(0);
131136
+ }
131137
+ });
131138
+ `;
131139
+ function startThreadWatchdog(params) {
131140
+ const shared = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT);
131141
+ const counter = new Int32Array(shared);
131142
+ const worker = new import_node_worker_threads2.Worker(WATCHDOG_SOURCE, {
131143
+ eval: true,
131144
+ workerData: { shared, boundMs: params.boundMs, checkEveryMs: params.checkEveryMs, stateFile: params.stateFile, ownPid: params.ownPid, action: params.action }
131145
+ });
131146
+ worker.unref();
131147
+ worker.on("message", (message) => {
131148
+ if (typeof message === "object" && message !== null && "message" in message && typeof message.message === "string") {
131149
+ params.onReport?.(message.message);
131150
+ }
131151
+ });
131152
+ let stopped = false;
131153
+ return {
131154
+ beat: () => {
131155
+ Atomics.add(counter, 0, 1);
131156
+ },
131157
+ stop: () => {
131158
+ if (stopped) {
131159
+ return;
131160
+ }
131161
+ stopped = true;
131162
+ worker.postMessage("stop");
131163
+ void worker.terminate();
131164
+ }
131165
+ };
131166
+ }
131167
+
130994
131168
  // src/frontdoor/status.ts
130995
131169
  init_socket();
130996
131170
  init_state2();
@@ -131046,6 +131220,12 @@ function formatFrontDoorStatus(status, caCertPath) {
131046
131220
  lines.push(`daemon log: ${status.logPath}${status.logExists ? "" : " (not created yet)"}`);
131047
131221
  return lines;
131048
131222
  }
131223
+ function formatFrontDoorListeners(readings) {
131224
+ return readings.map((reading) => {
131225
+ const what = reading.listener === "provider" ? "provider listener" : "connect surface";
131226
+ 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})`}`;
131227
+ });
131228
+ }
131049
131229
 
131050
131230
  // src/frontdoor/commands.ts
131051
131231
  init_state();
@@ -131090,8 +131270,8 @@ function createRealQuotaRefresher(params) {
131090
131270
  // src/frontdoor/commands.ts
131091
131271
  init_store2();
131092
131272
  function appendLog(paths, line) {
131093
- import_node_fs18.default.mkdirSync(paths.logsDir, { recursive: true });
131094
- import_node_fs18.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
131273
+ import_node_fs19.default.mkdirSync(paths.logsDir, { recursive: true });
131274
+ import_node_fs19.default.appendFileSync(paths.frontdoorLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
131095
131275
  `);
131096
131276
  }
131097
131277
  function rcObservingResolver(resolve2, tracker, hub) {
@@ -131104,7 +131284,7 @@ function rcObservingResolver(resolve2, tracker, hub) {
131104
131284
  }
131105
131285
  function realStatOwnExecutable(watchPath) {
131106
131286
  return () => {
131107
- const st2 = import_node_fs18.default.statSync(watchPath, { throwIfNoEntry: false });
131287
+ const st2 = import_node_fs19.default.statSync(watchPath, { throwIfNoEntry: false });
131108
131288
  return st2?.isFile() !== true ? void 0 : { dev: st2.dev, ino: st2.ino, size: st2.size, mtimeMs: st2.mtimeMs };
131109
131289
  };
131110
131290
  }
@@ -131304,7 +131484,7 @@ function realFrontDoorSupervisorPorts(paths) {
131304
131484
  },
131305
131485
  isRunning: realIsProcessRunning,
131306
131486
  // 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).
131307
- statOwnExecutable: realStatOwnExecutable(watchedInstallEntry(realOwnExecutablePath(), (candidate) => import_node_fs18.default.existsSync(candidate))),
131487
+ statOwnExecutable: realStatOwnExecutable(watchedInstallEntry(realOwnExecutablePath(), (candidate) => import_node_fs19.default.existsSync(candidate))),
131308
131488
  startProviderListener: async (preferredPort) => {
131309
131489
  const authority = loadCa();
131310
131490
  const rcDial = rcSelfHost ? lateRcEventDial(rcSelfHostDialTarget) : realRcEventDial();
@@ -131482,6 +131662,7 @@ function realFrontDoorSupervisorPorts(paths) {
131482
131662
  return { port: handle.port, close: handle.close };
131483
131663
  },
131484
131664
  closeRcStreamHub: rcHub.close,
131665
+ startWatchdog: () => startThreadWatchdog({ stateFile: paths.frontdoorStateFile, ownPid: process.pid, boundMs: DOOR_STALL_BOUND_MS, checkEveryMs: DOOR_WATCHDOG_CHECK_MS, action: "kill-process" }),
131485
131666
  // The launch lifecycle publisher over the same backbone the typed API serves: the tick's registry facts go in here, and the door's own register, prune and end moments come out as source-tagged events.
131486
131667
  observeLaunchRegistry: createLaunchEventPublisher(doorEvents, () => Date.now()).observe,
131487
131668
  doorHealth,
@@ -131499,11 +131680,12 @@ function registerFrontDoorCommand(program2, deps) {
131499
131680
  withExamples(
131500
131681
  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) => {
131501
131682
  const status = collectFrontDoorStatus(realFarmFs, realHeadroomSocketTrust, paths, realIsProcessRunning);
131683
+ const listeners = readFrontDoorListeners(status.state, status.supervisorAlive, realFrontDoorListenerProbes(paths));
131502
131684
  if (options.json === true) {
131503
- printJson(status);
131685
+ printJson({ ...status, listeners });
131504
131686
  return;
131505
131687
  }
131506
- for (const line of formatFrontDoorStatus(status, paths.frontdoorCaCertFile)) {
131688
+ for (const line of [...formatFrontDoorStatus(status, paths.frontdoorCaCertFile), ...formatFrontDoorListeners(listeners)]) {
131507
131689
  console.log(line);
131508
131690
  }
131509
131691
  }),
@@ -141283,7 +141465,7 @@ async function serveMcp(mcp, transport, options = {}) {
141283
141465
  }
141284
141466
 
141285
141467
  // src/mcp/permissions.ts
141286
- var import_node_fs19 = __toESM(require("node:fs"), 1);
141468
+ var import_node_fs20 = __toESM(require("node:fs"), 1);
141287
141469
  var import_node_path52 = __toESM(require("node:path"), 1);
141288
141470
  init_zod();
141289
141471
  init_store();
@@ -141300,15 +141482,15 @@ function readStoredMcpPermissions(paths) {
141300
141482
  }
141301
141483
  function writeStoredMcpPermissions(paths, permissions) {
141302
141484
  writeJsonAtomic(paths.mcpPermissionsFile, { writes: permissions.writes, remoteControl: permissions.remoteControl, history: permissions.history });
141303
- import_node_fs19.default.chmodSync(paths.mcpPermissionsFile, OWNER_ONLY_MODE);
141485
+ import_node_fs20.default.chmodSync(paths.mcpPermissionsFile, OWNER_ONLY_MODE);
141304
141486
  }
141305
141487
  function effectiveMcpPermissions(flags, stored) {
141306
141488
  return { writes: flags.writes || stored.writes, remoteControl: flags.remoteControl || stored.remoteControl, history: flags.history || stored.history };
141307
141489
  }
141308
141490
  function watchMcpPermissions(paths, onChange) {
141309
141491
  const directory = import_node_path52.default.dirname(paths.mcpPermissionsFile);
141310
- import_node_fs19.default.mkdirSync(directory, { recursive: true });
141311
- const watcher = import_node_fs19.default.watch(directory, (_event, filename) => {
141492
+ import_node_fs20.default.mkdirSync(directory, { recursive: true });
141493
+ const watcher = import_node_fs20.default.watch(directory, (_event, filename) => {
141312
141494
  if (filename === null || filename === import_node_path52.default.basename(paths.mcpPermissionsFile)) {
141313
141495
  onChange();
141314
141496
  }
@@ -141621,7 +141803,7 @@ init_credential();
141621
141803
  init_credentialCache();
141622
141804
 
141623
141805
  // src/identityToken.ts
141624
- var import_node_fs20 = __toESM(require("node:fs"), 1);
141806
+ var import_node_fs21 = __toESM(require("node:fs"), 1);
141625
141807
  var import_node_path53 = __toESM(require("node:path"), 1);
141626
141808
  init_cliError();
141627
141809
  var TOKEN_FILE_MODE = 384;
@@ -141639,13 +141821,13 @@ function storeIdentityToken(paths, identityName, raw) {
141639
141821
  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.");
141640
141822
  }
141641
141823
  const dir = identityTokenDir(paths);
141642
- import_node_fs20.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
141643
- import_node_fs20.default.chmodSync(dir, TOKEN_DIR_MODE);
141824
+ import_node_fs21.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
141825
+ import_node_fs21.default.chmodSync(dir, TOKEN_DIR_MODE);
141644
141826
  const target = identityTokenPath(paths, identityName);
141645
141827
  const temp = import_node_path53.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
141646
- import_node_fs20.default.writeFileSync(temp, `${token}
141828
+ import_node_fs21.default.writeFileSync(temp, `${token}
141647
141829
  `, { mode: TOKEN_FILE_MODE });
141648
- import_node_fs20.default.renameSync(temp, target);
141830
+ import_node_fs21.default.renameSync(temp, target);
141649
141831
  return target;
141650
141832
  }
141651
141833
 
@@ -141808,7 +141990,7 @@ function registerDoctorCommand(program2, deps) {
141808
141990
  }
141809
141991
 
141810
141992
  // src/headroom/commands.ts
141811
- var import_node_fs21 = __toESM(require("node:fs"), 1);
141993
+ var import_node_fs22 = __toESM(require("node:fs"), 1);
141812
141994
  var import_node_http4 = __toESM(require("node:http"), 1);
141813
141995
  var import_node_path54 = __toESM(require("node:path"), 1);
141814
141996
  var import_node_child_process7 = require("node:child_process");
@@ -142032,12 +142214,12 @@ function realSupervisorPorts(paths) {
142032
142214
  readConfig: () => resolveSupervisorConfig(readGlobalConfig(paths)?.headroom ?? {}),
142033
142215
  spawnHeadroom: (socketPath, allowlistFile, settings2) => {
142034
142216
  const trust = resolveHeadroomTrustBundle({ caCertFile: paths.frontdoorCaCertFile, bundlesDir: paths.frontdoorCaBundlesDir, inherited: process.env[HEADROOM_CA_BUNDLE], fs: realTrustBundleFs });
142035
- import_node_fs21.default.mkdirSync(paths.logsDir, { recursive: true });
142217
+ import_node_fs22.default.mkdirSync(paths.logsDir, { recursive: true });
142036
142218
  if (trust?.warning !== void 0) {
142037
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${trust.warning}
142219
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${trust.warning}
142038
142220
  `);
142039
142221
  }
142040
- const logFd = import_node_fs21.default.openSync(paths.headroomLogPath, "a");
142222
+ const logFd = import_node_fs22.default.openSync(paths.headroomLogPath, "a");
142041
142223
  try {
142042
142224
  const child = (0, import_node_child_process7.spawn)("headroom", headroomProxyArgs(socketPath, allowlistFile, settings2), {
142043
142225
  detached: true,
@@ -142052,12 +142234,12 @@ function realSupervisorPorts(paths) {
142052
142234
  child.once("exit", (code, signal) => {
142053
142235
  ownedHeadroom.delete(pid);
142054
142236
  exitedHeadroom.add(pid);
142055
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: headroom exited (${signal ?? `code ${String(code)}`})
142237
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: headroom exited (${signal ?? `code ${String(code)}`})
142056
142238
  `);
142057
142239
  });
142058
142240
  return pid;
142059
142241
  } finally {
142060
- import_node_fs21.default.closeSync(logFd);
142242
+ import_node_fs22.default.closeSync(logFd);
142061
142243
  }
142062
142244
  },
142063
142245
  stopProcess: (pid) => {
@@ -142070,7 +142252,7 @@ function realSupervisorPorts(paths) {
142070
142252
  now: () => Date.now()
142071
142253
  });
142072
142254
  if (outcome === "still-running") {
142073
- import_node_fs21.default.appendFileSync(
142255
+ import_node_fs22.default.appendFileSync(
142074
142256
  paths.headroomLogPath,
142075
142257
  `${(/* @__PURE__ */ new Date()).toISOString()} agent-shim headroom supervisor: pid ${String(pid)} survived SIGKILL within its grace; it is stuck uninterruptibly
142076
142258
  `
@@ -142088,10 +142270,10 @@ function realSupervisorPorts(paths) {
142088
142270
  };
142089
142271
  }
142090
142272
  if (result.stdout !== "") {
142091
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, result.stdout);
142273
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, result.stdout);
142092
142274
  }
142093
142275
  if (result.stderr !== "") {
142094
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, result.stderr);
142276
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, result.stderr);
142095
142277
  }
142096
142278
  return result.status === 0 ? { ok: true } : { ok: false, error: `uv tool install exited ${String(result.status)}` };
142097
142279
  },
@@ -142101,8 +142283,8 @@ function realSupervisorPorts(paths) {
142101
142283
  },
142102
142284
  installedCommit: readInstalledHeadroomCommit,
142103
142285
  log: (line) => {
142104
- import_node_fs21.default.mkdirSync(paths.logsDir, { recursive: true });
142105
- import_node_fs21.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
142286
+ import_node_fs22.default.mkdirSync(paths.logsDir, { recursive: true });
142287
+ import_node_fs22.default.appendFileSync(paths.headroomLogPath, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
142106
142288
  `);
142107
142289
  }
142108
142290
  };
@@ -142843,14 +143025,14 @@ function requireIdentity(paths, name) {
142843
143025
  throw new IdentityNotFoundError(name);
142844
143026
  }
142845
143027
  }
142846
- function collectUsageReport(fs23, paths, filters) {
143028
+ function collectUsageReport(fs24, paths, filters) {
142847
143029
  const { identity, provider, sinceMs } = filters;
142848
143030
  if (identity !== void 0) {
142849
143031
  requireIdentity(paths, identity);
142850
143032
  }
142851
- const log = readUsageLog(fs23, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
143033
+ const log = readUsageLog(fs24, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
142852
143034
  const records = log.records.filter((record2) => (identity === void 0 || record2.identity === identity) && (provider === void 0 || record2.provider === provider));
142853
- 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);
143035
+ 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);
142854
143036
  return {
142855
143037
  since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
142856
143038
  logDir: paths.usageLogDir,
@@ -142957,16 +143139,16 @@ function formatUsageReport(report) {
142957
143139
  }
142958
143140
  return lines;
142959
143141
  }
142960
- function collectAccounts(fs23, paths, identity, probe) {
143142
+ function collectAccounts(fs24, paths, identity, probe) {
142961
143143
  if (identity !== void 0) {
142962
143144
  requireIdentity(paths, identity);
142963
143145
  }
142964
143146
  const names = identity === void 0 ? listIdentities(paths).map((entry) => entry.name) : [identity];
142965
143147
  return names.map((name) => ({
142966
143148
  identity: name,
142967
- account: readAccountMetadata(fs23, paths.identitiesDir, name),
142968
- signIn: identitySignIn(fs23, probe, { farmRoot: import_node_path57.default.join(paths.identitiesDir, name), hasCredentialBlock: readIdentity(paths, name)?.credential !== void 0 }),
142969
- usage: readUsageSnapshot(fs23, paths.usageSnapshotsDir, name)
143149
+ account: readAccountMetadata(fs24, paths.identitiesDir, name),
143150
+ signIn: identitySignIn(fs24, probe, { farmRoot: import_node_path57.default.join(paths.identitiesDir, name), hasCredentialBlock: readIdentity(paths, name)?.credential !== void 0 }),
143151
+ usage: readUsageSnapshot(fs24, paths.usageSnapshotsDir, name)
142970
143152
  }));
142971
143153
  }
142972
143154
  function formatAccounts(views) {