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/index.cjs CHANGED
@@ -2043,8 +2043,8 @@ var init_lock = __esm({
2043
2043
  });
2044
2044
 
2045
2045
  // src/launcher/farm.ts
2046
- function readFarmManifest(fs12, farmRoot) {
2047
- const raw = fs12.readFileUtf8(import_node_path7.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs12.readFileUtf8(import_node_path7.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
2046
+ function readFarmManifest(fs13, farmRoot) {
2047
+ const raw = fs13.readFileUtf8(import_node_path7.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs13.readFileUtf8(import_node_path7.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
2048
2048
  if (raw === void 0) {
2049
2049
  return void 0;
2050
2050
  }
@@ -2102,9 +2102,9 @@ function buildEntryFacts(params) {
2102
2102
  entries
2103
2103
  };
2104
2104
  }
2105
- function listSubtree(fs12, root, rel) {
2105
+ function listSubtree(fs13, root, rel) {
2106
2106
  const absolute = import_node_path7.default.join(root, rel);
2107
- const stat = fs12.lstat(absolute);
2107
+ const stat = fs13.lstat(absolute);
2108
2108
  if (stat === void 0) {
2109
2109
  return [];
2110
2110
  }
@@ -2112,10 +2112,10 @@ function listSubtree(fs12, root, rel) {
2112
2112
  return [{ rel, kind: "symlink" }];
2113
2113
  }
2114
2114
  if (stat.kind === "dir") {
2115
- const children = [...fs12.readdir(absolute)].sort().flatMap((name) => listSubtree(fs12, root, `${rel}/${name}`));
2115
+ const children = [...fs13.readdir(absolute)].sort().flatMap((name) => listSubtree(fs13, root, `${rel}/${name}`));
2116
2116
  return [{ rel, kind: "dir" }, ...children];
2117
2117
  }
2118
- const contentHash = fs12.hashFile(absolute);
2118
+ const contentHash = fs13.hashFile(absolute);
2119
2119
  return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
2120
2120
  }
2121
2121
  function topLevelScopeRoots(roots) {
@@ -2129,25 +2129,25 @@ function topLevelScopeRoots(roots) {
2129
2129
  }
2130
2130
  return kept;
2131
2131
  }
2132
- function reconciliationScope(fs12, farmRoot, manifest) {
2132
+ function reconciliationScope(fs13, farmRoot, manifest) {
2133
2133
  if (manifest !== void 0) {
2134
2134
  return topLevelScopeRoots(manifest.materialised);
2135
2135
  }
2136
- return [...fs12.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs12.lstat(import_node_path7.default.join(farmRoot, name))?.kind === "dir").sort();
2136
+ return [...fs13.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs13.lstat(import_node_path7.default.join(farmRoot, name))?.kind === "dir").sort();
2137
2137
  }
2138
- function collectFarmListing(fs12, farmRoot, scopeRoots) {
2139
- return scopeRoots.flatMap((root) => listSubtree(fs12, farmRoot, root));
2138
+ function collectFarmListing(fs13, farmRoot, scopeRoots) {
2139
+ return scopeRoots.flatMap((root) => listSubtree(fs13, farmRoot, root));
2140
2140
  }
2141
- function collectCanonicalCounterparts(fs12, claudeHome, farmListing) {
2141
+ function collectCanonicalCounterparts(fs13, claudeHome, farmListing) {
2142
2142
  const out = [];
2143
2143
  for (const entry of farmListing) {
2144
2144
  const absolute = import_node_path7.default.join(claudeHome, entry.rel);
2145
- const stat = fs12.lstat(absolute);
2145
+ const stat = fs13.lstat(absolute);
2146
2146
  if (stat === void 0) {
2147
2147
  continue;
2148
2148
  }
2149
2149
  if (stat.kind === "file") {
2150
- const contentHash = fs12.hashFile(absolute);
2150
+ const contentHash = fs13.hashFile(absolute);
2151
2151
  out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
2152
2152
  continue;
2153
2153
  }
@@ -2585,10 +2585,10 @@ var init_route = __esm({
2585
2585
  });
2586
2586
 
2587
2587
  // src/frontdoor/state.ts
2588
- function readFrontDoorState(fs12, stateFile) {
2588
+ function readFrontDoorState(fs13, stateFile) {
2589
2589
  let raw;
2590
2590
  try {
2591
- raw = fs12.readFileUtf8(stateFile);
2591
+ raw = fs13.readFileUtf8(stateFile);
2592
2592
  } catch {
2593
2593
  return void 0;
2594
2594
  }
@@ -2602,9 +2602,9 @@ function readFrontDoorState(fs12, stateFile) {
2602
2602
  return void 0;
2603
2603
  }
2604
2604
  }
2605
- function writeFrontDoorState(fs12, stateFile, state) {
2606
- fs12.mkdirp(import_node_path8.default.dirname(stateFile));
2607
- fs12.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
2605
+ function writeFrontDoorState(fs13, stateFile, state) {
2606
+ fs13.mkdirp(import_node_path8.default.dirname(stateFile));
2607
+ fs13.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
2608
2608
  `);
2609
2609
  }
2610
2610
  function directOrigin(port) {
@@ -2614,27 +2614,27 @@ function frontDoorOrigin(state) {
2614
2614
  const port = state?.directPort ?? state?.lastDirectPort;
2615
2615
  return port === void 0 ? void 0 : directOrigin(port);
2616
2616
  }
2617
- function writeFrontDoorDirectRecord(fs12, recordsDir, record) {
2618
- fs12.mkdirp(recordsDir);
2619
- fs12.writeFilePrivate(import_node_path8.default.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
2617
+ function writeFrontDoorDirectRecord(fs13, recordsDir, record) {
2618
+ fs13.mkdirp(recordsDir);
2619
+ fs13.writeFilePrivate(import_node_path8.default.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
2620
2620
  `);
2621
2621
  }
2622
- function removeFrontDoorDirectRecord(fs12, recordsDir, pid) {
2623
- fs12.removeRecursive(import_node_path8.default.join(recordsDir, `${String(pid)}.json`));
2622
+ function removeFrontDoorDirectRecord(fs13, recordsDir, pid) {
2623
+ fs13.removeRecursive(import_node_path8.default.join(recordsDir, `${String(pid)}.json`));
2624
2624
  }
2625
2625
  function recordPid(file) {
2626
2626
  const pidText = /^([1-9]\d*)\.json$/.exec(file)?.[1];
2627
2627
  const pid = pidText === void 0 ? void 0 : Number(pidText);
2628
2628
  return pid !== void 0 && Number.isSafeInteger(pid) ? pid : void 0;
2629
2629
  }
2630
- function readDirectRecordEntry(fs12, recordsDir, file) {
2630
+ function readDirectRecordEntry(fs13, recordsDir, file) {
2631
2631
  const pid = recordPid(file);
2632
2632
  if (pid === void 0) {
2633
2633
  return void 0;
2634
2634
  }
2635
2635
  let raw;
2636
2636
  try {
2637
- raw = fs12.readFileUtf8(import_node_path8.default.join(recordsDir, file));
2637
+ raw = fs13.readFileUtf8(import_node_path8.default.join(recordsDir, file));
2638
2638
  } catch {
2639
2639
  return void 0;
2640
2640
  }
@@ -2648,44 +2648,44 @@ function readDirectRecordEntry(fs12, recordsDir, file) {
2648
2648
  return { malformed: true };
2649
2649
  }
2650
2650
  }
2651
- function listFrontDoorDirectRecords(fs12, recordsDir) {
2652
- return fs12.readdir(recordsDir).flatMap((file) => {
2653
- const entry = readDirectRecordEntry(fs12, recordsDir, file);
2651
+ function listFrontDoorDirectRecords(fs13, recordsDir) {
2652
+ return fs13.readdir(recordsDir).flatMap((file) => {
2653
+ const entry = readDirectRecordEntry(fs13, recordsDir, file);
2654
2654
  return entry?.record === void 0 ? [] : [entry.record];
2655
2655
  }).sort((a, b) => a.pid - b.pid);
2656
2656
  }
2657
- function pruneMalformedFrontDoorDirectFiles(fs12, recordsDir, isRunning) {
2658
- for (const file of fs12.readdir(recordsDir)) {
2657
+ function pruneMalformedFrontDoorDirectFiles(fs13, recordsDir, isRunning) {
2658
+ for (const file of fs13.readdir(recordsDir)) {
2659
2659
  const writer = RECORD_TEMPORARY_FILE.exec(file)?.[1];
2660
2660
  const stale = writer !== void 0 && !isRunning(Number(writer));
2661
- if (stale || readDirectRecordEntry(fs12, recordsDir, file)?.malformed === true) {
2662
- fs12.removeRecursive(import_node_path8.default.join(recordsDir, file));
2661
+ if (stale || readDirectRecordEntry(fs13, recordsDir, file)?.malformed === true) {
2662
+ fs13.removeRecursive(import_node_path8.default.join(recordsDir, file));
2663
2663
  }
2664
2664
  }
2665
2665
  }
2666
2666
  function liveFrontDoorDirectRecords(records, liveness) {
2667
2667
  return records.filter((record) => liveness.doors.has(record.pid) || liveness.unknown.has(record.pid));
2668
2668
  }
2669
- function pruneDeadFrontDoorDirectRecords(fs12, recordsDir, records, liveness) {
2669
+ function pruneDeadFrontDoorDirectRecords(fs13, recordsDir, records, liveness) {
2670
2670
  for (const record of records) {
2671
2671
  if (!liveness.doors.has(record.pid) && !liveness.unknown.has(record.pid)) {
2672
- removeFrontDoorDirectRecord(fs12, recordsDir, record.pid);
2672
+ removeFrontDoorDirectRecord(fs13, recordsDir, record.pid);
2673
2673
  }
2674
2674
  }
2675
2675
  }
2676
- function writeFrontDoorSession(fs12, sessionsDir, session) {
2677
- fs12.mkdirPrivate(sessionsDir);
2678
- fs12.writeFilePrivate(import_node_path8.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
2676
+ function writeFrontDoorSession(fs13, sessionsDir, session) {
2677
+ fs13.mkdirPrivate(sessionsDir);
2678
+ fs13.writeFilePrivate(import_node_path8.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
2679
2679
  `);
2680
2680
  }
2681
- function listFrontDoorSessions(fs12, sessionsDir) {
2681
+ function listFrontDoorSessions(fs13, sessionsDir) {
2682
2682
  const sessions = [];
2683
- for (const name of fs12.readdir(sessionsDir)) {
2683
+ for (const name of fs13.readdir(sessionsDir)) {
2684
2684
  if (!name.endsWith(".json")) {
2685
2685
  continue;
2686
2686
  }
2687
2687
  try {
2688
- const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs12.readFileUtf8(import_node_path8.default.join(sessionsDir, name)) ?? ""));
2688
+ const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs13.readFileUtf8(import_node_path8.default.join(sessionsDir, name)) ?? ""));
2689
2689
  if (parsed.success) {
2690
2690
  sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt, ...parsed.data.supervisorPid === void 0 ? {} : { supervisorPid: parsed.data.supervisorPid } });
2691
2691
  }
@@ -2695,14 +2695,14 @@ function listFrontDoorSessions(fs12, sessionsDir) {
2695
2695
  }
2696
2696
  return sessions.sort((a, b) => a.pid - b.pid);
2697
2697
  }
2698
- function removeFrontDoorSession(fs12, sessionsDir, pid) {
2699
- fs12.removeRecursive(import_node_path8.default.join(sessionsDir, `${String(pid)}.json`));
2698
+ function removeFrontDoorSession(fs13, sessionsDir, pid) {
2699
+ fs13.removeRecursive(import_node_path8.default.join(sessionsDir, `${String(pid)}.json`));
2700
2700
  }
2701
- function pruneDeadFrontDoorSessions(fs12, sessionsDir, isRunning) {
2701
+ function pruneDeadFrontDoorSessions(fs13, sessionsDir, isRunning) {
2702
2702
  const removed = [];
2703
- for (const session of listFrontDoorSessions(fs12, sessionsDir)) {
2703
+ for (const session of listFrontDoorSessions(fs13, sessionsDir)) {
2704
2704
  if (!isRunning(session.pid)) {
2705
- removeFrontDoorSession(fs12, sessionsDir, session.pid);
2705
+ removeFrontDoorSession(fs13, sessionsDir, session.pid);
2706
2706
  removed.push(session.pid);
2707
2707
  }
2708
2708
  }
@@ -2787,7 +2787,7 @@ var init_package = __esm({
2787
2787
  "package.json"() {
2788
2788
  package_default = {
2789
2789
  name: "claude-use",
2790
- version: "11.6.2",
2790
+ version: "11.8.0",
2791
2791
  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.",
2792
2792
  license: "MIT",
2793
2793
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -2992,43 +2992,43 @@ function parseJson(raw, schema) {
2992
2992
  const parsed = schema.safeParse(JSON.parse(raw));
2993
2993
  return parsed.success ? parsed.data : void 0;
2994
2994
  }
2995
- function readHeadroomState(fs12, stateFile) {
2995
+ function readHeadroomState(fs13, stateFile) {
2996
2996
  try {
2997
- return parseJson(fs12.readFileUtf8(stateFile), HeadroomStateSchema);
2997
+ return parseJson(fs13.readFileUtf8(stateFile), HeadroomStateSchema);
2998
2998
  } catch {
2999
2999
  return void 0;
3000
3000
  }
3001
3001
  }
3002
- function writeHeadroomState(fs12, stateFile, state) {
3003
- fs12.mkdirp(import_node_path11.default.dirname(stateFile));
3004
- fs12.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
3002
+ function writeHeadroomState(fs13, stateFile, state) {
3003
+ fs13.mkdirp(import_node_path11.default.dirname(stateFile));
3004
+ fs13.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
3005
3005
  `);
3006
3006
  }
3007
- function resolveServingHeadroomState(fs12, files, isRunning) {
3008
- const current = readHeadroomState(fs12, files.stateFile);
3007
+ function resolveServingHeadroomState(fs13, files, isRunning) {
3008
+ const current = readHeadroomState(fs13, files.stateFile);
3009
3009
  if (current !== void 0) {
3010
3010
  return { path: files.stateFile, state: current };
3011
3011
  }
3012
- const legacy = readHeadroomState(fs12, files.legacyStateFile);
3012
+ const legacy = readHeadroomState(fs13, files.legacyStateFile);
3013
3013
  if (legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid)) {
3014
3014
  return { path: files.legacyStateFile, state: legacy };
3015
3015
  }
3016
3016
  return void 0;
3017
3017
  }
3018
- function migrateHeadroomState(fs12, files, isRunning) {
3019
- const legacy = readHeadroomState(fs12, files.legacyStateFile);
3018
+ function migrateHeadroomState(fs13, files, isRunning) {
3019
+ const legacy = readHeadroomState(fs13, files.legacyStateFile);
3020
3020
  const legacyLive = legacy?.supervisorPid !== void 0 && isRunning(legacy.supervisorPid);
3021
- const current = readHeadroomState(fs12, files.stateFile);
3021
+ const current = readHeadroomState(fs13, files.stateFile);
3022
3022
  if (current !== void 0 || legacyLive) {
3023
- if (!legacyLive && fs12.readFileUtf8(files.legacyStateFile) !== void 0) {
3024
- fs12.removeRecursive(files.legacyStateFile);
3023
+ if (!legacyLive && fs13.readFileUtf8(files.legacyStateFile) !== void 0) {
3024
+ fs13.removeRecursive(files.legacyStateFile);
3025
3025
  }
3026
3026
  return;
3027
3027
  }
3028
3028
  if (legacy !== void 0) {
3029
- writeHeadroomState(fs12, files.stateFile, legacy);
3029
+ writeHeadroomState(fs13, files.stateFile, legacy);
3030
3030
  }
3031
- fs12.removeRecursive(files.legacyStateFile);
3031
+ fs13.removeRecursive(files.legacyStateFile);
3032
3032
  }
3033
3033
  function hashAllowlist(allowlist) {
3034
3034
  return (0, import_node_crypto6.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
@@ -3061,27 +3061,27 @@ function isAdmissibleUrl(entry) {
3061
3061
  function parseAllowlistFile(content) {
3062
3062
  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)));
3063
3063
  }
3064
- function writeAllowlistFile(fs12, allowlistFile, allowlist) {
3065
- fs12.mkdirPrivate(import_node_path11.default.dirname(allowlistFile));
3066
- fs12.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
3064
+ function writeAllowlistFile(fs13, allowlistFile, allowlist) {
3065
+ fs13.mkdirPrivate(import_node_path11.default.dirname(allowlistFile));
3066
+ fs13.writeFilePrivate(allowlistFile, formatAllowlistFile(allowlist));
3067
3067
  }
3068
- function pruneStaleAllowlistTemporaries(fs12, allowlistFile, isRunning) {
3068
+ function pruneStaleAllowlistTemporaries(fs13, allowlistFile, isRunning) {
3069
3069
  const prefix = `${import_node_path11.default.basename(allowlistFile)}.`;
3070
- for (const name of fs12.readdir(import_node_path11.default.dirname(allowlistFile))) {
3070
+ for (const name of fs13.readdir(import_node_path11.default.dirname(allowlistFile))) {
3071
3071
  const writer = name.startsWith(prefix) ? /^([1-9]\d*)\.tmp$/.exec(name.slice(prefix.length))?.[1] : void 0;
3072
3072
  if (writer !== void 0 && !isRunning(Number(writer))) {
3073
- fs12.removeRecursive(import_node_path11.default.join(import_node_path11.default.dirname(allowlistFile), name));
3073
+ fs13.removeRecursive(import_node_path11.default.join(import_node_path11.default.dirname(allowlistFile), name));
3074
3074
  }
3075
3075
  }
3076
3076
  }
3077
- function readAllProviders(fs12, providersDir) {
3077
+ function readAllProviders(fs13, providersDir) {
3078
3078
  const result = [];
3079
- for (const name of fs12.readdir(providersDir)) {
3079
+ for (const name of fs13.readdir(providersDir)) {
3080
3080
  if (!name.endsWith(".json")) {
3081
3081
  continue;
3082
3082
  }
3083
3083
  try {
3084
- const parsed = parseJson(fs12.readFileUtf8(import_node_path11.default.join(providersDir, name)), ProviderSchema);
3084
+ const parsed = parseJson(fs13.readFileUtf8(import_node_path11.default.join(providersDir, name)), ProviderSchema);
3085
3085
  if (parsed !== void 0) {
3086
3086
  result.push({ name: name.slice(0, -".json".length), provider: parsed });
3087
3087
  }
@@ -3091,22 +3091,22 @@ function readAllProviders(fs12, providersDir) {
3091
3091
  }
3092
3092
  return result;
3093
3093
  }
3094
- function writeSession(fs12, sessionsDir, session) {
3095
- fs12.mkdirp(sessionsDir);
3096
- fs12.writeFileUtf8(import_node_path11.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
3094
+ function writeSession(fs13, sessionsDir, session) {
3095
+ fs13.mkdirp(sessionsDir);
3096
+ fs13.writeFileUtf8(import_node_path11.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
3097
3097
  `);
3098
3098
  }
3099
- function removeSession(fs12, sessionsDir, pid) {
3100
- fs12.removeRecursive(import_node_path11.default.join(sessionsDir, `${String(pid)}.json`));
3099
+ function removeSession(fs13, sessionsDir, pid) {
3100
+ fs13.removeRecursive(import_node_path11.default.join(sessionsDir, `${String(pid)}.json`));
3101
3101
  }
3102
- function listSessions(fs12, sessionsDir) {
3102
+ function listSessions(fs13, sessionsDir) {
3103
3103
  const sessions = [];
3104
- for (const name of fs12.readdir(sessionsDir)) {
3104
+ for (const name of fs13.readdir(sessionsDir)) {
3105
3105
  if (!name.endsWith(".json")) {
3106
3106
  continue;
3107
3107
  }
3108
3108
  try {
3109
- const parsed = parseJson(fs12.readFileUtf8(import_node_path11.default.join(sessionsDir, name)), HeadroomSessionSchema);
3109
+ const parsed = parseJson(fs13.readFileUtf8(import_node_path11.default.join(sessionsDir, name)), HeadroomSessionSchema);
3110
3110
  if (parsed !== void 0) {
3111
3111
  sessions.push(parsed);
3112
3112
  }
@@ -3116,22 +3116,22 @@ function listSessions(fs12, sessionsDir) {
3116
3116
  }
3117
3117
  return sessions.sort((a, b) => a.pid - b.pid);
3118
3118
  }
3119
- function sessionsForSupervisor(fs12, sessionsDir, supervisorPid) {
3120
- return listSessions(fs12, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
3119
+ function sessionsForSupervisor(fs13, sessionsDir, supervisorPid) {
3120
+ return listSessions(fs13, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
3121
3121
  }
3122
- function pruneDeadSessions(fs12, sessionsDir, isRunning) {
3122
+ function pruneDeadSessions(fs13, sessionsDir, isRunning) {
3123
3123
  const removed = [];
3124
- for (const session of listSessions(fs12, sessionsDir)) {
3124
+ for (const session of listSessions(fs13, sessionsDir)) {
3125
3125
  if (!isRunning(session.pid)) {
3126
- removeSession(fs12, sessionsDir, session.pid);
3126
+ removeSession(fs13, sessionsDir, session.pid);
3127
3127
  removed.push(session.pid);
3128
3128
  }
3129
3129
  }
3130
3130
  return removed;
3131
3131
  }
3132
- function readStartLock(fs12, lockFile) {
3132
+ function readStartLock(fs13, lockFile) {
3133
3133
  try {
3134
- return parseJson(fs12.readFileUtf8(lockFile), HeadroomLockSchema);
3134
+ return parseJson(fs13.readFileUtf8(lockFile), HeadroomLockSchema);
3135
3135
  } catch {
3136
3136
  return void 0;
3137
3137
  }
@@ -3224,12 +3224,12 @@ function earlierReleaseAllowlistHash(providers, doorOrigin) {
3224
3224
  }
3225
3225
  return hashAllowlist([...entries].sort());
3226
3226
  }
3227
- function earlierReleaseDaemon(fs12, paths, daemon) {
3227
+ function earlierReleaseDaemon(fs13, paths, daemon) {
3228
3228
  if (daemonIdentity(daemon.commandLine, daemon.socketPath) !== "earlier-release") {
3229
3229
  return void 0;
3230
3230
  }
3231
- const providers = readAllProviders(fs12, paths.providersDir).map((entry) => entry.provider);
3232
- const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs12, paths.frontdoorStateFile)));
3231
+ const providers = readAllProviders(fs13, paths.providersDir).map((entry) => entry.provider);
3232
+ const expected = earlierReleaseAllowlistHash(providers, frontDoorOrigin(readFrontDoorState(fs13, paths.frontdoorStateFile)));
3233
3233
  return { admitsServingDoor: daemon.recordedHash === expected };
3234
3234
  }
3235
3235
  var EARLIER_RELEASE_ALLOWLIST, EARLIER_RELEASE_ANTHROPIC_UPSTREAM;
@@ -3254,8 +3254,8 @@ function awaitingCause(daemonPid, identity, allowlistFile) {
3254
3254
  }
3255
3255
  return `the headroom supervisor has not written an allowlist admitting this launch's upstreams to ${allowlistFile} within ${String(HEADROOM_START_TIMEOUT_MS)}ms`;
3256
3256
  }
3257
- function daemonAdmits(fs12, allowlistFile, recordedHash, required) {
3258
- const content = fs12.readFileUtf8(allowlistFile);
3257
+ function daemonAdmits(fs13, allowlistFile, recordedHash, required) {
3258
+ const content = fs13.readFileUtf8(allowlistFile);
3259
3259
  if (content === void 0 || recordedHash === void 0) {
3260
3260
  return false;
3261
3261
  }
@@ -3518,7 +3518,7 @@ function verifyAllowlistFile(allowlistFile, ports) {
3518
3518
  const replaceable = fileStat === void 0 || fileStat.kind === "file" || fileStat.kind === "symlink";
3519
3519
  return { message: refusal2, repairable: replaceable };
3520
3520
  }
3521
- function prepareHeadroomSocket(fs12, ports, paths, supervisorPid) {
3521
+ function prepareHeadroomSocket(fs13, ports, paths, supervisorPid) {
3522
3522
  const unsupported = platformRefusal(ports.platform);
3523
3523
  if (unsupported !== void 0) {
3524
3524
  return { refused: unsupported };
@@ -3533,18 +3533,18 @@ function prepareHeadroomSocket(fs12, ports, paths, supervisorPid) {
3533
3533
  if (ports.lstat(paths.headroomSocketDir)?.kind === "symlink") {
3534
3534
  return { refused: `the headroom socket directory ${paths.headroomSocketDir} is a symlink; it must be the real directory` };
3535
3535
  }
3536
- fs12.mkdirPrivate(paths.headroomSocketDir);
3536
+ fs13.mkdirPrivate(paths.headroomSocketDir);
3537
3537
  const refusal2 = ownerOnlyRefusal("socket directory", paths.headroomSocketDir, ports.lstat(paths.headroomSocketDir), "dir", ports.currentUid());
3538
3538
  return refusal2 === void 0 ? { socketPath } : { refused: refusal2 };
3539
3539
  }
3540
- function pruneStaleHeadroomSockets(fs12, paths, isRunning) {
3540
+ function pruneStaleHeadroomSockets(fs13, paths, isRunning) {
3541
3541
  const removed = [];
3542
- for (const name of fs12.readdir(paths.headroomSocketDir)) {
3542
+ for (const name of fs13.readdir(paths.headroomSocketDir)) {
3543
3543
  const pid = HEADROOM_SOCKET_NAME.exec(name)?.[1];
3544
3544
  if (pid === void 0 || isRunning(Number.parseInt(pid, 10))) {
3545
3545
  continue;
3546
3546
  }
3547
- fs12.removeRecursive(import_node_path12.default.join(paths.headroomSocketDir, name));
3547
+ fs13.removeRecursive(import_node_path12.default.join(paths.headroomSocketDir, name));
3548
3548
  removed.push(name);
3549
3549
  }
3550
3550
  return removed;
@@ -3656,37 +3656,37 @@ function compareVersions2(a, b) {
3656
3656
  return 0;
3657
3657
  }
3658
3658
  async function runSupervisor(initialConfig, ports, options = {}) {
3659
- const { fs: fs12, paths } = ports;
3659
+ const { fs: fs13, paths } = ports;
3660
3660
  let config = initialConfig;
3661
- migrateHeadroomState(fs12, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
3662
- const previousState = resolveServingHeadroomState(fs12, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
3661
+ migrateHeadroomState(fs13, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning);
3662
+ const previousState = resolveServingHeadroomState(fs13, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, ports.isRunning)?.state;
3663
3663
  if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
3664
3664
  ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
3665
3665
  return 0;
3666
3666
  }
3667
3667
  let installedSource = previousState?.installedSource;
3668
3668
  const ownsState = () => {
3669
- const owner = readHeadroomState(fs12, paths.headroomStateFile)?.supervisorPid;
3669
+ const owner = readHeadroomState(fs13, paths.headroomStateFile)?.supervisorPid;
3670
3670
  return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
3671
3671
  };
3672
3672
  const writeOwnState = (state) => {
3673
3673
  if (!ownsState()) {
3674
3674
  return false;
3675
3675
  }
3676
- writeHeadroomState(fs12, paths.headroomStateFile, state);
3676
+ writeHeadroomState(fs13, paths.headroomStateFile, state);
3677
3677
  return true;
3678
3678
  };
3679
3679
  const fail = (message) => {
3680
3680
  if (writeOwnState({ lastError: message })) {
3681
- fs12.removeRecursive(paths.headroomLockFile);
3681
+ fs13.removeRecursive(paths.headroomLockFile);
3682
3682
  }
3683
3683
  ports.log(`agent-shim headroom supervisor: ${message}`);
3684
3684
  return 1;
3685
3685
  };
3686
3686
  const syncAllowlistFile = (allowlist) => {
3687
3687
  try {
3688
- if (fs12.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
3689
- writeAllowlistFile(fs12, paths.headroomAllowlistFile, allowlist);
3688
+ if (fs13.readFileUtf8(paths.headroomAllowlistFile) !== formatAllowlistFile(allowlist)) {
3689
+ writeAllowlistFile(fs13, paths.headroomAllowlistFile, allowlist);
3690
3690
  ports.log(`agent-shim headroom supervisor: wrote allowlist [${allowlist.join(", ")}] to ${paths.headroomAllowlistFile}`);
3691
3691
  }
3692
3692
  return void 0;
@@ -3704,9 +3704,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
3704
3704
  }
3705
3705
  ports.log(`agent-shim headroom supervisor: repairing the allowlist file: ${problem.message}`);
3706
3706
  try {
3707
- fs12.mkdirPrivate(paths.headroomDir);
3708
- fs12.mkdirPrivate(import_node_path13.default.dirname(paths.headroomAllowlistFile));
3709
- writeAllowlistFile(fs12, paths.headroomAllowlistFile, allowlist);
3707
+ fs13.mkdirPrivate(paths.headroomDir);
3708
+ fs13.mkdirPrivate(import_node_path13.default.dirname(paths.headroomAllowlistFile));
3709
+ writeAllowlistFile(fs13, paths.headroomAllowlistFile, allowlist);
3710
3710
  } catch (error) {
3711
3711
  return `could not write the headroom allowlist file ${paths.headroomAllowlistFile}: ${error instanceof Error ? error.message : String(error)}`;
3712
3712
  }
@@ -3731,20 +3731,20 @@ async function runSupervisor(initialConfig, ports, options = {}) {
3731
3731
  installedSource = config.source;
3732
3732
  return void 0;
3733
3733
  };
3734
- const socket = prepareHeadroomSocket(fs12, ports.socketTrust, paths, ports.ownPid);
3734
+ const socket = prepareHeadroomSocket(fs13, ports.socketTrust, paths, ports.ownPid);
3735
3735
  if (socket.refused !== void 0) {
3736
3736
  return fail(socket.refused);
3737
3737
  }
3738
3738
  const { socketPath } = socket;
3739
- pruneStaleHeadroomSockets(fs12, paths, ports.isRunning);
3740
- pruneStaleAllowlistTemporaries(fs12, paths.headroomAllowlistFile, ports.isRunning);
3739
+ pruneStaleHeadroomSockets(fs13, paths, ports.isRunning);
3740
+ pruneStaleAllowlistTemporaries(fs13, paths.headroomAllowlistFile, ports.isRunning);
3741
3741
  const installFailure = ensureInstalled();
3742
3742
  if (installFailure !== void 0) {
3743
3743
  return fail(installFailure);
3744
3744
  }
3745
3745
  const version = ports.headroomVersion() ?? "unknown";
3746
3746
  writeOwnState({ supervisorPid: ports.ownPid, version, installedSource });
3747
- ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs12, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
3747
+ ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: managing headroom on allowlist [${currentHeadroomAllowlistInputs(fs13, paths, ports.frontDoorLiveness).frontDoorOrigins.join(", ")}]`);
3748
3748
  const orphanPid = previousState?.headroomPid;
3749
3749
  const orphanSocket = previousState?.socketPath ?? (previousState?.supervisorPid === void 0 ? void 0 : headroomSocketPath(paths, previousState.supervisorPid));
3750
3750
  const orphanIdentity = orphanPid === void 0 || orphanSocket === void 0 || !ports.isRunning(orphanPid) ? void 0 : daemonIdentity(ports.daemonCommandLine(orphanPid), orphanSocket);
@@ -3779,12 +3779,12 @@ async function runSupervisor(initialConfig, ports, options = {}) {
3779
3779
  ticks += 1;
3780
3780
  config = ports.readConfig();
3781
3781
  const settingsHash = hashSettings(config.settings);
3782
- const inputs = currentHeadroomAllowlistInputs(fs12, paths, ports.frontDoorLiveness);
3783
- pruneDeadFrontDoorDirectRecords(fs12, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
3784
- pruneMalformedFrontDoorDirectFiles(fs12, paths.frontdoorDirectRecordsDir, ports.isRunning);
3782
+ const inputs = currentHeadroomAllowlistInputs(fs13, paths, ports.frontDoorLiveness);
3783
+ pruneDeadFrontDoorDirectRecords(fs13, paths.frontdoorDirectRecordsDir, inputs.frontDoorRecords, inputs.frontDoorLiveness);
3784
+ pruneMalformedFrontDoorDirectFiles(fs13, paths.frontdoorDirectRecordsDir, ports.isRunning);
3785
3785
  const allowlist = inputs.frontDoorOrigins;
3786
3786
  const allowlistHash = hashAllowlist(allowlist);
3787
- pruneDeadSessions(fs12, paths.headroomSessionsDir, ports.isRunning);
3787
+ pruneDeadSessions(fs13, paths.headroomSessionsDir, ports.isRunning);
3788
3788
  const ownsNow = ownsState();
3789
3789
  if (!ownsNow && !superseded) {
3790
3790
  ports.log("agent-shim headroom supervisor: another supervisor now owns the state file; serving this daemon's own sessions until they end");
@@ -3831,7 +3831,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
3831
3831
  runningSettingsHash = settingsHash;
3832
3832
  const recorded = writeOwnState(servingState(pid));
3833
3833
  if (recorded) {
3834
- fs12.removeRecursive(paths.headroomLockFile);
3834
+ fs13.removeRecursive(paths.headroomLockFile);
3835
3835
  }
3836
3836
  idleSince = void 0;
3837
3837
  ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on unix socket ${socketPath}`);
@@ -3859,7 +3859,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
3859
3859
  ports.log(`agent-shim headroom supervisor: headroom pid ${String(headroomPid)} now serves allowlist [${allowlist.join(", ")}]`);
3860
3860
  }
3861
3861
  if (runningSettingsHash !== settingsHash || installedSource !== config.source) {
3862
- if (sessionsForSupervisor(fs12, paths.headroomSessionsDir, ports.ownPid).length === 0) {
3862
+ if (sessionsForSupervisor(fs13, paths.headroomSessionsDir, ports.ownPid).length === 0) {
3863
3863
  ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
3864
3864
  ports.stopProcess(headroomPid);
3865
3865
  headroomPid = void 0;
@@ -3868,7 +3868,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
3868
3868
  continue;
3869
3869
  }
3870
3870
  }
3871
- const sessions = sessionsForSupervisor(fs12, paths.headroomSessionsDir, ports.ownPid);
3871
+ const sessions = sessionsForSupervisor(fs13, paths.headroomSessionsDir, ports.ownPid);
3872
3872
  if (sessions.length === 0) {
3873
3873
  idleSince ??= ports.now();
3874
3874
  const idleMs = ports.now() - idleSince;
@@ -3893,9 +3893,9 @@ function undeterminedFrontDoors(inputs) {
3893
3893
  return reason === void 0 ? [] : [{ pid: record.pid, origin: directOrigin(record.directPort), reason }];
3894
3894
  });
3895
3895
  }
3896
- function currentHeadroomAllowlistInputs(fs12, paths, frontDoorLiveness) {
3897
- const named = frontDoorOrigin(readFrontDoorState(fs12, paths.frontdoorStateFile));
3898
- const records = listFrontDoorDirectRecords(fs12, paths.frontdoorDirectRecordsDir);
3896
+ function currentHeadroomAllowlistInputs(fs13, paths, frontDoorLiveness) {
3897
+ const named = frontDoorOrigin(readFrontDoorState(fs13, paths.frontdoorStateFile));
3898
+ const records = listFrontDoorDirectRecords(fs13, paths.frontdoorDirectRecordsDir);
3899
3899
  const liveness = frontDoorLiveness(records.map((record) => record.pid));
3900
3900
  const live = liveFrontDoorDirectRecords(records, liveness).map((record) => directOrigin(record.directPort));
3901
3901
  return {
@@ -3904,8 +3904,8 @@ function currentHeadroomAllowlistInputs(fs12, paths, frontDoorLiveness) {
3904
3904
  frontDoorOrigins: [.../* @__PURE__ */ new Set([...named === void 0 ? [] : [named], ...live])].sort()
3905
3905
  };
3906
3906
  }
3907
- function launchRequiredUpstreams(fs12, paths) {
3908
- const door = frontDoorOrigin(readFrontDoorState(fs12, paths.frontdoorStateFile));
3907
+ function launchRequiredUpstreams(fs13, paths) {
3908
+ const door = frontDoorOrigin(readFrontDoorState(fs13, paths.frontdoorStateFile));
3909
3909
  return door === void 0 ? [] : [door];
3910
3910
  }
3911
3911
  async function waitUntilReady(ports, socketPath, pid) {
@@ -4526,8 +4526,8 @@ var init_cascade = __esm({
4526
4526
  function poolNameOf(selector) {
4527
4527
  return selector.startsWith(POOL_SELECTOR_PREFIX) ? selector.slice(POOL_SELECTOR_PREFIX.length) : void 0;
4528
4528
  }
4529
- function readActiveIdentity(fs12, activeIdentityFile) {
4530
- const trimmed = fs12.readFileUtf8(activeIdentityFile)?.trim();
4529
+ function readActiveIdentity(fs13, activeIdentityFile) {
4530
+ const trimmed = fs13.readFileUtf8(activeIdentityFile)?.trim();
4531
4531
  return trimmed === void 0 || trimmed === "" ? void 0 : trimmed;
4532
4532
  }
4533
4533
  function isNonEmpty(value) {
@@ -4574,8 +4574,8 @@ function decideConfigProfile(params) {
4574
4574
  }
4575
4575
  return { source: "none" };
4576
4576
  }
4577
- function loadIdentity(identitiesDir, name, fs12) {
4578
- return loadConfigFile(import_node_path17.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs12.readConfigFile);
4577
+ function loadIdentity(identitiesDir, name, fs13) {
4578
+ return loadConfigFile(import_node_path17.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs13.readConfigFile);
4579
4579
  }
4580
4580
  var import_node_path17, IDENTITY_DECISION_SOURCES, CONFIG_PROFILE_DECISION_SOURCES;
4581
4581
  var init_identity = __esm({
@@ -4807,12 +4807,12 @@ function isIdentityName(name) {
4807
4807
  function claudeJsonPath(identitiesDir, identity) {
4808
4808
  return import_node_path18.default.join(identitiesDir, identity, CLAUDE_JSON);
4809
4809
  }
4810
- function readAccountMetadata(fs12, identitiesDir, identity) {
4810
+ function readAccountMetadata(fs13, identitiesDir, identity) {
4811
4811
  if (!isIdentityName(identity)) {
4812
4812
  throw new Error(`"${identity}" is not a valid identity name.`);
4813
4813
  }
4814
4814
  const file = claudeJsonPath(identitiesDir, identity);
4815
- const raw = fs12.readFileUtf8(file);
4815
+ const raw = fs13.readFileUtf8(file);
4816
4816
  if (raw === void 0) {
4817
4817
  return void 0;
4818
4818
  }
@@ -4842,19 +4842,19 @@ function readAccountMetadata(fs12, identitiesDir, identity) {
4842
4842
  }
4843
4843
  return account.data;
4844
4844
  }
4845
- function createAccountReader(fs12, identitiesDir) {
4845
+ function createAccountReader(fs13, identitiesDir) {
4846
4846
  const cache = /* @__PURE__ */ new Map();
4847
4847
  return (identity) => {
4848
4848
  if (!isIdentityName(identity)) {
4849
4849
  throw new Error(`"${identity}" is not a valid identity name.`);
4850
4850
  }
4851
- const stat = fs12.lstat(claudeJsonPath(identitiesDir, identity));
4851
+ const stat = fs13.lstat(claudeJsonPath(identitiesDir, identity));
4852
4852
  const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
4853
4853
  const cached = cache.get(identity);
4854
4854
  if (cached?.stamp === stamp) {
4855
4855
  return cached.account;
4856
4856
  }
4857
- const account = readAccountMetadata(fs12, identitiesDir, identity);
4857
+ const account = readAccountMetadata(fs13, identitiesDir, identity);
4858
4858
  cache.set(identity, { stamp, account });
4859
4859
  return account;
4860
4860
  };
@@ -5436,8 +5436,8 @@ function segmentDay(epochMs) {
5436
5436
  function segmentName(day, pid) {
5437
5437
  return `${day}.${String(pid)}.jsonl`;
5438
5438
  }
5439
- function listLogSegments(fs12, logDir) {
5440
- return fs12.readdir(logDir).flatMap((name) => {
5439
+ function listLogSegments(fs13, logDir) {
5440
+ return fs13.readdir(logDir).flatMap((name) => {
5441
5441
  const match = SEGMENT_RE.exec(name);
5442
5442
  const day = match?.[1];
5443
5443
  if (day === void 0) {
@@ -5446,15 +5446,15 @@ function listLogSegments(fs12, logDir) {
5446
5446
  return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
5447
5447
  }).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
5448
5448
  }
5449
- function readUsageLog(fs12, logDir, options = {}) {
5449
+ function readUsageLog(fs13, logDir, options = {}) {
5450
5450
  const { sinceMs } = options;
5451
5451
  const records = [];
5452
5452
  let invalidLines = 0;
5453
- for (const segment of listLogSegments(fs12, logDir)) {
5453
+ for (const segment of listLogSegments(fs13, logDir)) {
5454
5454
  if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
5455
5455
  continue;
5456
5456
  }
5457
- const contents = fs12.readFileUtf8(import_node_path19.default.join(logDir, segment.name));
5457
+ const contents = fs13.readFileUtf8(import_node_path19.default.join(logDir, segment.name));
5458
5458
  if (contents === void 0) {
5459
5459
  continue;
5460
5460
  }
@@ -5490,9 +5490,9 @@ function snapshotPath(snapshotsDir, identity) {
5490
5490
  }
5491
5491
  return import_node_path19.default.join(snapshotsDir, `${identity}.json`);
5492
5492
  }
5493
- function readUsageSnapshot(fs12, snapshotsDir, identity) {
5493
+ function readUsageSnapshot(fs13, snapshotsDir, identity) {
5494
5494
  const file = snapshotPath(snapshotsDir, identity);
5495
- const raw = fs12.readFileUtf8(file);
5495
+ const raw = fs13.readFileUtf8(file);
5496
5496
  if (raw === void 0) {
5497
5497
  return void 0;
5498
5498
  }
@@ -5508,8 +5508,8 @@ function readUsageSnapshot(fs12, snapshotsDir, identity) {
5508
5508
  }
5509
5509
  return snapshot.data;
5510
5510
  }
5511
- function listUsageSnapshots(fs12, snapshotsDir) {
5512
- return fs12.readdir(snapshotsDir).flatMap((name) => {
5511
+ function listUsageSnapshots(fs13, snapshotsDir) {
5512
+ return fs13.readdir(snapshotsDir).flatMap((name) => {
5513
5513
  if (!name.endsWith(".json")) {
5514
5514
  return [];
5515
5515
  }
@@ -5517,7 +5517,7 @@ function listUsageSnapshots(fs12, snapshotsDir) {
5517
5517
  if (!isIdentityName(identity)) {
5518
5518
  return [];
5519
5519
  }
5520
- const snapshot = readUsageSnapshot(fs12, snapshotsDir, identity);
5520
+ const snapshot = readUsageSnapshot(fs13, snapshotsDir, identity);
5521
5521
  return snapshot === void 0 ? [] : [snapshot];
5522
5522
  }).sort((left, right) => left.identity.localeCompare(right.identity));
5523
5523
  }
@@ -5542,11 +5542,11 @@ var init_read = __esm({
5542
5542
  });
5543
5543
 
5544
5544
  // src/usage/store.ts
5545
- function pruneUsageLog(fs12, logDir, nowMs) {
5545
+ function pruneUsageLog(fs13, logDir, nowMs) {
5546
5546
  const cutoff = nowMs - USAGE_RETENTION_MS;
5547
- for (const segment of listLogSegments(fs12, logDir)) {
5547
+ for (const segment of listLogSegments(fs13, logDir)) {
5548
5548
  if (segment.endsAt <= cutoff) {
5549
- fs12.removeRecursive(import_node_path20.default.join(logDir, segment.name));
5549
+ fs13.removeRecursive(import_node_path20.default.join(logDir, segment.name));
5550
5550
  }
5551
5551
  }
5552
5552
  }
@@ -5575,7 +5575,7 @@ function foldProviderState(current, record) {
5575
5575
  };
5576
5576
  }
5577
5577
  function createUsageStore(deps) {
5578
- const { fs: fs12, paths } = deps;
5578
+ const { fs: fs13, paths } = deps;
5579
5579
  let prunedDay;
5580
5580
  const rewriteSnapshot = (identity, fold) => {
5581
5581
  if (!isIdentityName(identity)) {
@@ -5584,7 +5584,7 @@ function createUsageStore(deps) {
5584
5584
  }
5585
5585
  let current;
5586
5586
  try {
5587
- current = readUsageSnapshot(fs12, paths.usageSnapshotsDir, identity);
5587
+ current = readUsageSnapshot(fs13, paths.usageSnapshotsDir, identity);
5588
5588
  } catch (error) {
5589
5589
  if (!(error instanceof UsageSnapshotError)) {
5590
5590
  throw error;
@@ -5611,8 +5611,8 @@ function createUsageStore(deps) {
5611
5611
  ...account === void 0 ? {} : { account },
5612
5612
  providers
5613
5613
  });
5614
- fs12.mkdirPrivate(paths.usageSnapshotsDir);
5615
- fs12.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
5614
+ fs13.mkdirPrivate(paths.usageSnapshotsDir);
5615
+ fs13.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
5616
5616
  `);
5617
5617
  deps.publish?.(snapshot);
5618
5618
  return true;
@@ -5621,14 +5621,14 @@ function createUsageStore(deps) {
5621
5621
  record: (input) => {
5622
5622
  const record = UsageRecordSchema.parse(input);
5623
5623
  const nowMs = deps.now();
5624
- fs12.mkdirPrivate(paths.usageDir);
5625
- fs12.mkdirPrivate(paths.usageLogDir);
5624
+ fs13.mkdirPrivate(paths.usageDir);
5625
+ fs13.mkdirPrivate(paths.usageLogDir);
5626
5626
  const day = segmentDay(nowMs);
5627
5627
  if (prunedDay !== day) {
5628
- pruneUsageLog(fs12, paths.usageLogDir, nowMs);
5628
+ pruneUsageLog(fs13, paths.usageLogDir, nowMs);
5629
5629
  prunedDay = day;
5630
5630
  }
5631
- fs12.appendFilePrivate(import_node_path20.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
5631
+ fs13.appendFilePrivate(import_node_path20.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record)}
5632
5632
  `);
5633
5633
  if (record.identity !== void 0) {
5634
5634
  rewriteSnapshot(record.identity, (current) => ({ ...current?.providers, [record.provider]: foldProviderState(current?.providers[record.provider], record) }));
@@ -5670,14 +5670,14 @@ var init_store2 = __esm({
5670
5670
  function errorMessage(error) {
5671
5671
  return error instanceof Error ? error.message : String(error);
5672
5672
  }
5673
- function loadPoolMembers(fs12, paths, identities, nowMs) {
5673
+ function loadPoolMembers(fs13, paths, identities, nowMs) {
5674
5674
  const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
5675
- const log = readUsageLog(fs12, paths.usageLogDir, { sinceMs: windowStartMs });
5675
+ const log = readUsageLog(fs13, paths.usageLogDir, { sinceMs: windowStartMs });
5676
5676
  return identities.map((identity) => {
5677
5677
  const records = log.records.filter((record) => record.identity === identity && record.provider === ANTHROPIC_PROVIDER && Date.parse(record.at) >= windowStartMs);
5678
5678
  try {
5679
- const snapshot = readUsageSnapshot(fs12, paths.usageSnapshotsDir, identity);
5680
- const account = readAccountMetadata(fs12, paths.identitiesDir, identity) ?? snapshot?.account;
5679
+ const snapshot = readUsageSnapshot(fs13, paths.usageSnapshotsDir, identity);
5680
+ const account = readAccountMetadata(fs13, paths.identitiesDir, identity) ?? snapshot?.account;
5681
5681
  return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
5682
5682
  } catch (error) {
5683
5683
  if (error instanceof UsageSnapshotError || error instanceof AccountMetadataError) {
@@ -5770,9 +5770,9 @@ function collectPoolIdentities(pools, poolName, stack, found) {
5770
5770
  collectPoolIdentities(pools, nestedName, childStack, found);
5771
5771
  }
5772
5772
  }
5773
- function readPicksFile(fs12, file) {
5773
+ function readPicksFile(fs13, file) {
5774
5774
  const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
5775
- const raw = fs12.readFileUtf8(file);
5775
+ const raw = fs13.readFileUtf8(file);
5776
5776
  if (raw === void 0) {
5777
5777
  return { file: empty };
5778
5778
  }
@@ -5785,17 +5785,17 @@ function readPicksFile(fs12, file) {
5785
5785
  const result = PicksFileSchema.safeParse(parsed);
5786
5786
  return result.success ? { file: result.data } : { file: empty, problem: `${file} is not a picks file this agent-shim can read` };
5787
5787
  }
5788
- function readStickyPick(fs12, picksFile, directory) {
5789
- const read = readPicksFile(fs12, picksFile);
5788
+ function readStickyPick(fs13, picksFile, directory) {
5789
+ const read = readPicksFile(fs13, picksFile);
5790
5790
  const entry = read.file.picks[directory];
5791
5791
  return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
5792
5792
  }
5793
- function recordStickyPick(fs12, picksFile, directory, identity, nowMs) {
5794
- const current = readPicksFile(fs12, picksFile).file.picks;
5793
+ function recordStickyPick(fs13, picksFile, directory, identity, nowMs) {
5794
+ const current = readPicksFile(fs13, picksFile).file.picks;
5795
5795
  const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
5796
5796
  const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
5797
- fs12.mkdirPrivate(import_node_path21.default.dirname(picksFile));
5798
- fs12.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
5797
+ fs13.mkdirPrivate(import_node_path21.default.dirname(picksFile));
5798
+ fs13.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
5799
5799
  `);
5800
5800
  }
5801
5801
  var import_node_path21, import_zod13, PoolGraphError, SCHEMA_VERSION, PickEntrySchema, PicksFileSchema;
@@ -6736,6 +6736,106 @@ var init_claudeShim = __esm({
6736
6736
  }
6737
6737
  });
6738
6738
 
6739
+ // src/frontdoor/probe.ts
6740
+ function probeFrontDoorSync(port, caPem) {
6741
+ refuseToBlockInRole("a synchronous probe of the front door");
6742
+ return runProbeWorker(PROBE_SOURCE, { port, ca: caPem });
6743
+ }
6744
+ function probeListenerAcceptSync(port) {
6745
+ refuseToBlockInRole("a synchronous probe of a front door listener");
6746
+ return runProbeWorker(ACCEPT_PROBE_SOURCE, { port });
6747
+ }
6748
+ function runProbeWorker(source, data) {
6749
+ const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
6750
+ const header = new Int32Array(shared, 0, HEADER_SLOTS);
6751
+ const worker = new import_node_worker_threads.Worker(source, {
6752
+ eval: true,
6753
+ workerData: { ...data, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
6754
+ });
6755
+ worker.unref();
6756
+ try {
6757
+ const waited = Atomics.wait(header, 0, VERDICT_PENDING, PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS);
6758
+ const verdict = Atomics.load(header, 0);
6759
+ if (waited === "timed-out" || verdict === VERDICT_PENDING) {
6760
+ return { ok: false, reason: `the probe did not finish within ${String(PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS)}ms` };
6761
+ }
6762
+ if (verdict === VERDICT_OK) {
6763
+ return { ok: true };
6764
+ }
6765
+ const length = Atomics.load(header, 1);
6766
+ return { ok: false, reason: Buffer.from(new Uint8Array(shared, HEADER_SLOTS * INT32_BYTES, length)).toString("utf8") };
6767
+ } finally {
6768
+ void worker.terminate();
6769
+ }
6770
+ }
6771
+ 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;
6772
+ var init_probe = __esm({
6773
+ "src/frontdoor/probe.ts"() {
6774
+ "use strict";
6775
+ init_processRole();
6776
+ import_node_worker_threads = require("node:worker_threads");
6777
+ PROBE_TIMEOUT_MS = 2e3;
6778
+ PROBE_WAIT_MARGIN_MS = 1e3;
6779
+ REASON_BYTES = 1024;
6780
+ HEADER_SLOTS = 2;
6781
+ INT32_BYTES = 4;
6782
+ VERDICT_PENDING = 0;
6783
+ VERDICT_OK = 1;
6784
+ VERDICT_FAILED = 2;
6785
+ PROBE_SOURCE = `
6786
+ const { workerData } = require("node:worker_threads");
6787
+ const https = require("node:https");
6788
+ const { port, ca, timeoutMs, shared, ok, failed, headerSlots } = workerData;
6789
+ const header = new Int32Array(shared, 0, headerSlots);
6790
+ const reason = new Uint8Array(shared, headerSlots * 4);
6791
+ let done = false;
6792
+ const finish = (verdict, message) => {
6793
+ if (done) return;
6794
+ done = true;
6795
+ const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
6796
+ reason.set(bytes);
6797
+ Atomics.store(header, 1, bytes.length);
6798
+ Atomics.store(header, 0, verdict);
6799
+ Atomics.notify(header, 0);
6800
+ };
6801
+ const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca], agent: false }, (response) => {
6802
+ let body = "";
6803
+ response.setEncoding("utf8");
6804
+ response.on("data", (chunk) => { body += chunk; });
6805
+ response.on("end", () => {
6806
+ if (response.statusCode === 200 && body === "ok") finish(ok, "");
6807
+ else finish(failed, "the listener answered its health probe with HTTP " + String(response.statusCode));
6808
+ });
6809
+ response.on("error", (error) => finish(failed, error.message));
6810
+ });
6811
+ // A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
6812
+ setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
6813
+ request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
6814
+ `;
6815
+ ACCEPT_PROBE_SOURCE = `
6816
+ const { workerData } = require("node:worker_threads");
6817
+ const net = require("node:net");
6818
+ const { port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
6819
+ const header = new Int32Array(shared, 0, headerSlots);
6820
+ const reason = new Uint8Array(shared, headerSlots * 4);
6821
+ let done = false;
6822
+ const finish = (verdict, message) => {
6823
+ if (done) return;
6824
+ done = true;
6825
+ const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
6826
+ reason.set(bytes);
6827
+ Atomics.store(header, 1, bytes.length);
6828
+ Atomics.store(header, 0, verdict);
6829
+ Atomics.notify(header, 0);
6830
+ };
6831
+ const socket = net.connect({ host: "127.0.0.1", port });
6832
+ socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
6833
+ socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
6834
+ setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
6835
+ `;
6836
+ }
6837
+ });
6838
+
6739
6839
  // src/update/update.ts
6740
6840
  function compareVersions3(left, right) {
6741
6841
  const parse = (version) => {
@@ -7487,7 +7587,7 @@ function contextTokensOfTranscript(text) {
7487
7587
  }
7488
7588
  return void 0;
7489
7589
  }
7490
- function resumedContextTokens(fs12, params) {
7590
+ function resumedContextTokens(fs13, params) {
7491
7591
  const target = resumeTargetOf(params.passthrough);
7492
7592
  if (target === void 0) {
7493
7593
  return void 0;
@@ -7498,19 +7598,19 @@ function resumedContextTokens(fs12, params) {
7498
7598
  file = import_node_path37.default.join(projectDir, `${target.id}.jsonl`);
7499
7599
  } else {
7500
7600
  let newestMs = -Infinity;
7501
- for (const name of fs12.readdir(projectDir)) {
7601
+ for (const name of fs13.readdir(projectDir)) {
7502
7602
  if (!name.endsWith(".jsonl")) {
7503
7603
  continue;
7504
7604
  }
7505
7605
  const candidate = import_node_path37.default.join(projectDir, name);
7506
- const stat = fs12.lstat(candidate);
7606
+ const stat = fs13.lstat(candidate);
7507
7607
  if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
7508
7608
  newestMs = stat.mtimeMs;
7509
7609
  file = candidate;
7510
7610
  }
7511
7611
  }
7512
7612
  }
7513
- const text = file === void 0 ? void 0 : fs12.readFileUtf8(file);
7613
+ const text = file === void 0 ? void 0 : fs13.readFileUtf8(file);
7514
7614
  return text === void 0 ? void 0 : contextTokensOfTranscript(text);
7515
7615
  }
7516
7616
  var import_node_path37;
@@ -7628,7 +7728,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
7628
7728
  return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
7629
7729
  }
7630
7730
  function pickFromPool(decided, params, parsedArgv, readOnly) {
7631
- const { paths, fs: fs12, proc, log } = params;
7731
+ const { paths, fs: fs13, proc, log } = params;
7632
7732
  if (decided.pool === void 0) {
7633
7733
  return { identityDecision: decided };
7634
7734
  }
@@ -7643,7 +7743,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
7643
7743
  selectedVia: decided.source,
7644
7744
  pools: params.pools,
7645
7745
  paths,
7646
- fs: fs12,
7746
+ fs: fs13,
7647
7747
  usageFs: farmRuntime.fs,
7648
7748
  cwd: farmRuntime.cwd,
7649
7749
  now: farmRuntime.now,
@@ -7666,7 +7766,7 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
7666
7766
  };
7667
7767
  }
7668
7768
  function decideLaunch(params, readOnly) {
7669
- const { paths, fs: fs12, proc, log } = params;
7769
+ const { paths, fs: fs13, proc, log } = params;
7670
7770
  const { env, argv } = proc;
7671
7771
  const parsedArgv = parseLauncherArgv(argv);
7672
7772
  const cliOverride = buildCliOverride({
@@ -7681,7 +7781,7 @@ function decideLaunch(params, readOnly) {
7681
7781
  argv0Identity: parsedArgv.identity,
7682
7782
  directoryPinnedIdentity: params.directoryPinnedIdentity,
7683
7783
  readActiveIdentityFile: () => {
7684
- const raw = fs12.readFileUtf8(paths.activeIdentityFile);
7784
+ const raw = fs13.readFileUtf8(paths.activeIdentityFile);
7685
7785
  if (raw === void 0) {
7686
7786
  return void 0;
7687
7787
  }
@@ -7716,7 +7816,7 @@ function decideLaunch(params, readOnly) {
7716
7816
  }
7717
7817
  let loadedIdentity;
7718
7818
  if (identityDecision.name !== void 0) {
7719
- loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs12);
7819
+ loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs13);
7720
7820
  if (loadedIdentity === void 0) {
7721
7821
  log.error(
7722
7822
  `agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
@@ -7731,7 +7831,7 @@ function decideLaunch(params, readOnly) {
7731
7831
  identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
7732
7832
  globalDefaultConfigProfile: params.globalDefaultConfigProfile
7733
7833
  });
7734
- if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs12.readConfigFile(import_node_path38.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7834
+ if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs13.readConfigFile(import_node_path38.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
7735
7835
  log.error(
7736
7836
  `agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
7737
7837
  );
@@ -7740,7 +7840,7 @@ function decideLaunch(params, readOnly) {
7740
7840
  const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
7741
7841
  const providerParams = {
7742
7842
  paths,
7743
- port: fs12,
7843
+ port: fs13,
7744
7844
  ...parsedArgv.provider === void 0 || parsedArgv.provider === false ? {} : { cliProvider: parsedArgv.provider },
7745
7845
  ...farmContext === void 0 ? {} : { cascade: farmContext.cascade }
7746
7846
  };
@@ -8068,78 +8168,6 @@ var init_ownCli = __esm({
8068
8168
  }
8069
8169
  });
8070
8170
 
8071
- // src/frontdoor/probe.ts
8072
- function probeFrontDoorSync(port, caPem) {
8073
- refuseToBlockInRole("a synchronous probe of the front door");
8074
- const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
8075
- const header = new Int32Array(shared, 0, HEADER_SLOTS);
8076
- const worker = new import_node_worker_threads.Worker(PROBE_SOURCE, {
8077
- eval: true,
8078
- workerData: { port, ca: caPem, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
8079
- });
8080
- worker.unref();
8081
- try {
8082
- const waited = Atomics.wait(header, 0, VERDICT_PENDING, PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS);
8083
- const verdict = Atomics.load(header, 0);
8084
- if (waited === "timed-out" || verdict === VERDICT_PENDING) {
8085
- return { ok: false, reason: `the probe did not finish within ${String(PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS)}ms` };
8086
- }
8087
- if (verdict === VERDICT_OK) {
8088
- return { ok: true };
8089
- }
8090
- const length = Atomics.load(header, 1);
8091
- return { ok: false, reason: Buffer.from(new Uint8Array(shared, HEADER_SLOTS * INT32_BYTES, length)).toString("utf8") };
8092
- } finally {
8093
- void worker.terminate();
8094
- }
8095
- }
8096
- 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;
8097
- var init_probe = __esm({
8098
- "src/frontdoor/probe.ts"() {
8099
- "use strict";
8100
- init_processRole();
8101
- import_node_worker_threads = require("node:worker_threads");
8102
- PROBE_TIMEOUT_MS = 2e3;
8103
- PROBE_WAIT_MARGIN_MS = 1e3;
8104
- REASON_BYTES = 1024;
8105
- HEADER_SLOTS = 2;
8106
- INT32_BYTES = 4;
8107
- VERDICT_PENDING = 0;
8108
- VERDICT_OK = 1;
8109
- VERDICT_FAILED = 2;
8110
- PROBE_SOURCE = `
8111
- const { workerData } = require("node:worker_threads");
8112
- const https = require("node:https");
8113
- const { port, ca, timeoutMs, shared, ok, failed, headerSlots } = workerData;
8114
- const header = new Int32Array(shared, 0, headerSlots);
8115
- const reason = new Uint8Array(shared, headerSlots * 4);
8116
- let done = false;
8117
- const finish = (verdict, message) => {
8118
- if (done) return;
8119
- done = true;
8120
- const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
8121
- reason.set(bytes);
8122
- Atomics.store(header, 1, bytes.length);
8123
- Atomics.store(header, 0, verdict);
8124
- Atomics.notify(header, 0);
8125
- };
8126
- const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca], agent: false }, (response) => {
8127
- let body = "";
8128
- response.setEncoding("utf8");
8129
- response.on("data", (chunk) => { body += chunk; });
8130
- response.on("end", () => {
8131
- if (response.statusCode === 200 && body === "ok") finish(ok, "");
8132
- else finish(failed, "the listener answered its health probe with HTTP " + String(response.statusCode));
8133
- });
8134
- response.on("error", (error) => finish(failed, error.message));
8135
- });
8136
- // A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
8137
- setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
8138
- request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
8139
- `;
8140
- }
8141
- });
8142
-
8143
8171
  // src/frontdoor/selfIdentity.ts
8144
8172
  function isFrontDoorSupervisorPid(pid, identify) {
8145
8173
  return declaredPid !== void 0 && pid === declaredPid && pid === process.pid || identify(pid);
@@ -8153,14 +8181,14 @@ var init_selfIdentity = __esm({
8153
8181
 
8154
8182
  // src/frontdoor/trust.ts
8155
8183
  function resolveTrustBundle(params) {
8156
- const { caCertFile, bundlesDir, variable, inherited, fs: fs12 } = params;
8184
+ const { caCertFile, bundlesDir, variable, inherited, fs: fs13 } = params;
8157
8185
  if (inherited === void 0 || inherited === "" || import_node_path40.default.resolve(inherited) === import_node_path40.default.resolve(caCertFile)) {
8158
8186
  return { path: caCertFile };
8159
8187
  }
8160
- const caPem = fs12.readFileUtf8(caCertFile);
8188
+ const caPem = fs13.readFileUtf8(caCertFile);
8161
8189
  let inheritedPem;
8162
8190
  try {
8163
- inheritedPem = fs12.readFileUtf8(inherited);
8191
+ inheritedPem = fs13.readFileUtf8(inherited);
8164
8192
  } catch (error) {
8165
8193
  return {
8166
8194
  path: caCertFile,
@@ -8173,9 +8201,9 @@ function resolveTrustBundle(params) {
8173
8201
  const combined = `${inheritedPem.trimEnd()}
8174
8202
  ${caPem}`;
8175
8203
  const bundle = import_node_path40.default.join(bundlesDir, `${(0, import_node_crypto11.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
8176
- if (!fs12.exists(bundle)) {
8177
- fs12.mkdirp(bundlesDir);
8178
- fs12.writeFileAtomic(bundle, combined);
8204
+ if (!fs13.exists(bundle)) {
8205
+ fs13.mkdirp(bundlesDir);
8206
+ fs13.writeFileAtomic(bundle, combined);
8179
8207
  }
8180
8208
  return { path: bundle };
8181
8209
  }
@@ -8205,7 +8233,7 @@ function realEnsurePorts(paths, spawnDaemon) {
8205
8233
  process.kill(pid, "SIGKILL");
8206
8234
  },
8207
8235
  // Read fresh for each probe: a replacement supervisor may have regenerated an unparseable CA, and the probe must trust exactly what the serving door's leaf chains to.
8208
- verifyListener: (port) => probeFrontDoorSync(port, import_node_fs11.default.readFileSync(paths.frontdoorCaCertFile, "utf8"))
8236
+ verifyListener: (port) => probeFrontDoorSync(port, import_node_fs12.default.readFileSync(paths.frontdoorCaCertFile, "utf8"))
8209
8237
  };
8210
8238
  }
8211
8239
  function realFrontDoorPort(paths, spawnDaemon) {
@@ -8226,11 +8254,11 @@ function realFrontDoorPort(paths, spawnDaemon) {
8226
8254
  }
8227
8255
  };
8228
8256
  }
8229
- var import_node_fs11, realTrustBundleFs;
8257
+ var import_node_fs12, realTrustBundleFs;
8230
8258
  var init_realFrontDoorPort = __esm({
8231
8259
  "src/frontdoor/realFrontDoorPort.ts"() {
8232
8260
  "use strict";
8233
- import_node_fs11 = __toESM(require("node:fs"), 1);
8261
+ import_node_fs12 = __toESM(require("node:fs"), 1);
8234
8262
  init_realPorts();
8235
8263
  init_ensure2();
8236
8264
  init_state();
@@ -8238,10 +8266,10 @@ var init_realFrontDoorPort = __esm({
8238
8266
  init_selfIdentity();
8239
8267
  init_trust();
8240
8268
  realTrustBundleFs = {
8241
- readFileUtf8: (file) => import_node_fs11.default.readFileSync(file, "utf8"),
8242
- exists: (file) => import_node_fs11.default.existsSync(file),
8269
+ readFileUtf8: (file) => import_node_fs12.default.readFileSync(file, "utf8"),
8270
+ exists: (file) => import_node_fs12.default.existsSync(file),
8243
8271
  mkdirp: (dir) => {
8244
- import_node_fs11.default.mkdirSync(dir, { recursive: true });
8272
+ import_node_fs12.default.mkdirSync(dir, { recursive: true });
8245
8273
  },
8246
8274
  writeFileAtomic: (file, contents) => {
8247
8275
  realFarmFs.writeFilePrivate(file, contents);
@@ -9449,9 +9477,9 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
9449
9477
  }
9450
9478
  }
9451
9479
  async function serveFrontDoor(idleShutdownMinutes, ports, options) {
9452
- const { fs: fs12, paths } = ports;
9480
+ const { fs: fs13, paths } = ports;
9453
9481
  const servingBinary = ports.statOwnExecutable();
9454
- const previous = readFrontDoorState(fs12, paths.frontdoorStateFile);
9482
+ const previous = readFrontDoorState(fs13, paths.frontdoorStateFile);
9455
9483
  let lastPort = previous?.lastPort;
9456
9484
  let lastConnectPort = previous?.lastConnectPort;
9457
9485
  let lastDirectPort = previous?.lastDirectPort;
@@ -9462,12 +9490,12 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
9462
9490
  });
9463
9491
  const fail = (message) => {
9464
9492
  ports.closeRcStreamHub();
9465
- writeFrontDoorState(fs12, paths.frontdoorStateFile, { lastError: message, ...sticky() });
9466
- fs12.removeRecursive(paths.frontdoorLockFile);
9493
+ writeFrontDoorState(fs13, paths.frontdoorStateFile, { lastError: message, ...sticky() });
9494
+ fs13.removeRecursive(paths.frontdoorLockFile);
9467
9495
  ports.log(`agent-shim frontdoor supervisor: ${message}`);
9468
9496
  return 1;
9469
9497
  };
9470
- writeFrontDoorState(fs12, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
9498
+ writeFrontDoorState(fs13, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
9471
9499
  const previousSticky = lastPort;
9472
9500
  let http3;
9473
9501
  try {
@@ -9507,15 +9535,16 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
9507
9535
  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)`);
9508
9536
  }
9509
9537
  lastDirectPort = direct.port;
9510
- writeFrontDoorDirectRecord(fs12, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
9511
- writeFrontDoorState(fs12, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http3.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
9538
+ writeFrontDoorDirectRecord(fs13, paths.frontdoorDirectRecordsDir, { pid: ports.ownPid, directPort: direct.port });
9539
+ writeFrontDoorState(fs13, paths.frontdoorStateFile, { protocol: FRONT_DOOR_PROTOCOL, supervisorPid: ports.ownPid, port: http3.port, connectPort: connect3.port, directPort: direct.port, ...sticky() });
9512
9540
  ports.doorHealth.generation({ providerPort: http3.port, connectPort: connect3.port, directPort: direct.port });
9513
- fs12.removeRecursive(paths.frontdoorLockFile);
9541
+ fs13.removeRecursive(paths.frontdoorLockFile);
9514
9542
  ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http3.port)}, CONNECT surface on 127.0.0.1:${String(connect3.port)}`);
9543
+ const watchdog = ports.startWatchdog?.();
9515
9544
  let idleSince;
9516
9545
  let ticks = 0;
9517
9546
  const supersedingOwner = () => {
9518
- const owner = readFrontDoorState(fs12, paths.frontdoorStateFile)?.supervisorPid;
9547
+ const owner = readFrontDoorState(fs13, paths.frontdoorStateFile)?.supervisorPid;
9519
9548
  return owner !== void 0 && owner !== ports.ownPid && ports.isRunning(owner) ? owner : void 0;
9520
9549
  };
9521
9550
  let supersededBy;
@@ -9525,26 +9554,29 @@ async function serveFrontDoor(idleShutdownMinutes, ports, options) {
9525
9554
  return current !== void 0 && servingBinary !== void 0 && (current.dev !== servingBinary.dev || current.ino !== servingBinary.ino || current.size !== servingBinary.size || current.mtimeMs !== servingBinary.mtimeMs);
9526
9555
  };
9527
9556
  const closeServing = async () => {
9557
+ watchdog?.stop();
9528
9558
  await direct.close();
9529
9559
  await connect3.close();
9530
9560
  await http3.close();
9531
9561
  ports.closeRcStreamHub();
9532
- removeFrontDoorDirectRecord(fs12, paths.frontdoorDirectRecordsDir, ports.ownPid);
9562
+ removeFrontDoorDirectRecord(fs13, paths.frontdoorDirectRecordsDir, ports.ownPid);
9533
9563
  };
9534
9564
  const shutdown = async () => {
9535
9565
  await closeServing();
9536
9566
  if (supersedingOwner() === void 0) {
9537
- writeFrontDoorState(fs12, paths.frontdoorStateFile, sticky());
9567
+ writeFrontDoorState(fs13, paths.frontdoorStateFile, sticky());
9538
9568
  }
9539
9569
  return 0;
9540
9570
  };
9541
9571
  for (; ; ) {
9572
+ watchdog?.beat();
9542
9573
  if (options.tickLimit !== void 0 && ticks >= options.tickLimit) {
9574
+ watchdog?.stop();
9543
9575
  return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
9544
9576
  }
9545
9577
  ticks += 1;
9546
- const listed = listFrontDoorSessions(fs12, paths.frontdoorSessionsDir);
9547
- const pruned = pruneDeadFrontDoorSessions(fs12, paths.frontdoorSessionsDir, ports.isRunning);
9578
+ const listed = listFrontDoorSessions(fs13, paths.frontdoorSessionsDir);
9579
+ const pruned = pruneDeadFrontDoorSessions(fs13, paths.frontdoorSessionsDir, ports.isRunning);
9548
9580
  ports.observeLaunchRegistry(listed, pruned);
9549
9581
  ports.checkQuotaExpiry();
9550
9582
  const prunedPids = new Set(pruned);
@@ -12040,11 +12072,11 @@ function credentialOfJson(parsed) {
12040
12072
  function sequenceNumOfJson(value) {
12041
12073
  return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
12042
12074
  }
12043
- function createRcCredentialStore(fs12, dir) {
12044
- fs12.mkdirPrivate(dir);
12075
+ function createRcCredentialStore(fs13, dir) {
12076
+ fs13.mkdirPrivate(dir);
12045
12077
  const fileFor = (sessionId) => import_node_path10.default.join(dir, `${sessionId}.json`);
12046
12078
  const readParsed = (sessionId) => {
12047
- const raw = fs12.readFileUtf8(fileFor(sessionId));
12079
+ const raw = fs13.readFileUtf8(fileFor(sessionId));
12048
12080
  if (raw === void 0) {
12049
12081
  return void 0;
12050
12082
  }
@@ -12069,7 +12101,7 @@ function createRcCredentialStore(fs12, dir) {
12069
12101
  }
12070
12102
  const cursor = sequenceNumOfJson(readParsed(sessionId)?.highestSequenceNum);
12071
12103
  const record = { ...credential, ...cursor === void 0 ? {} : { highestSequenceNum: cursor } };
12072
- fs12.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
12104
+ fs13.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
12073
12105
  `);
12074
12106
  },
12075
12107
  readCursor: (sessionId) => {
@@ -12084,14 +12116,14 @@ function createRcCredentialStore(fs12, dir) {
12084
12116
  }
12085
12117
  const credential = credentialOfJson(readParsed(sessionId));
12086
12118
  const record = credential === void 0 ? { highestSequenceNum } : { ...credential, highestSequenceNum };
12087
- fs12.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
12119
+ fs13.writeFilePrivate(fileFor(sessionId), `${JSON.stringify(record, null, 2)}
12088
12120
  `);
12089
12121
  },
12090
12122
  remove: (sessionId) => {
12091
12123
  if (!isSafeSessionId(sessionId)) {
12092
12124
  return;
12093
12125
  }
12094
- fs12.removeRecursive(fileFor(sessionId));
12126
+ fs13.removeRecursive(fileFor(sessionId));
12095
12127
  }
12096
12128
  };
12097
12129
  }
@@ -13887,7 +13919,7 @@ function removeIdentity(paths, name) {
13887
13919
 
13888
13920
  // src/doctorReport.ts
13889
13921
  init_realPorts();
13890
- var import_node_fs9 = __toESM(require("node:fs"), 1);
13922
+ var import_node_fs10 = __toESM(require("node:fs"), 1);
13891
13923
  var import_node_path30 = __toESM(require("node:path"), 1);
13892
13924
 
13893
13925
  // src/usage/signIn.ts
@@ -14110,6 +14142,53 @@ function pushFrontDoor(push, supervisors, registeredPid, liveSessions) {
14110
14142
  );
14111
14143
  }
14112
14144
  }
14145
+ var LISTENER_ROUTES = {
14146
+ provider: "provider sessions (`z`, `m` and the like)",
14147
+ connect: "every plain OAuth session, which reaches Anthropic through it"
14148
+ };
14149
+ function pushFrontDoorListeners(push, readings) {
14150
+ for (const reading of readings) {
14151
+ const where = `127.0.0.1:${String(reading.port)}`;
14152
+ if (reading.ok) {
14153
+ push("frontdoor", "pass", `The front door's ${reading.listener} listener on ${where} accepted a probe in ${String(Math.round(reading.elapsedMs))} ms.`, reading.listener);
14154
+ continue;
14155
+ }
14156
+ push(
14157
+ "frontdoor",
14158
+ "fail",
14159
+ `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.`,
14160
+ reading.listener
14161
+ );
14162
+ }
14163
+ }
14164
+
14165
+ // src/frontdoor/listenerReadings.ts
14166
+ var import_node_fs9 = __toESM(require("node:fs"), 1);
14167
+ init_probe();
14168
+ function readFrontDoorListeners(state, supervisorAlive, probes) {
14169
+ if (!supervisorAlive) {
14170
+ return [];
14171
+ }
14172
+ const readings = [];
14173
+ const take = (listener, port, probe) => {
14174
+ if (port === void 0) {
14175
+ return;
14176
+ }
14177
+ const started = probes.now();
14178
+ const verdict = probe(port);
14179
+ readings.push({ listener, port, ok: verdict.ok, ...verdict.ok ? {} : { reason: verdict.reason }, elapsedMs: Math.max(0, probes.now() - started) });
14180
+ };
14181
+ take("provider", state.port, probes.authenticateProvider);
14182
+ take("connect", state.connectPort, probes.connect);
14183
+ return readings;
14184
+ }
14185
+ function realFrontDoorListenerProbes(paths) {
14186
+ return {
14187
+ authenticateProvider: (port) => probeFrontDoorSync(port, import_node_fs9.default.readFileSync(paths.frontdoorCaCertFile, "utf8")),
14188
+ connect: probeListenerAcceptSync,
14189
+ now: () => performance.now()
14190
+ };
14191
+ }
14113
14192
 
14114
14193
  // src/doctorReport.ts
14115
14194
  init_supervisorProcesses();
@@ -14554,6 +14633,9 @@ function runDoctor(params) {
14554
14633
  if (params.frontDoor !== void 0) {
14555
14634
  const validated3 = params.frontDoor.state.raw === void 0 ? void 0 : validateJson(FrontDoorStateSchema, params.frontDoor.state);
14556
14635
  pushFrontDoor(push, params.frontDoor.supervisors, validated3?.ok === true ? validated3.data.supervisorPid : void 0, params.frontDoor.liveSessions);
14636
+ if (params.frontDoor.listeners !== void 0) {
14637
+ pushFrontDoorListeners(push, params.frontDoor.listeners);
14638
+ }
14557
14639
  }
14558
14640
  if (params.activeIdentity.raw === void 0) {
14559
14641
  push("active-identity", "pass", "No active identity set.");
@@ -14637,25 +14719,30 @@ function formatDoctorReport(report) {
14637
14719
  }
14638
14720
  function realpathOrSelf(target) {
14639
14721
  try {
14640
- return import_node_fs9.default.realpathSync(target);
14722
+ return import_node_fs10.default.realpathSync(target);
14641
14723
  } catch {
14642
14724
  return target;
14643
14725
  }
14644
14726
  }
14727
+ function servingDoorListeners(paths) {
14728
+ const state = readFrontDoorState(realFarmFs, paths.frontdoorStateFile) ?? {};
14729
+ const alive = state.supervisorPid !== void 0 && realIsProcessRunning(state.supervisorPid);
14730
+ return readFrontDoorListeners(state, alive, realFrontDoorListenerProbes(paths));
14731
+ }
14645
14732
  function collectDoctorReport(params) {
14646
14733
  const { paths } = params;
14647
- const identityNames = import_node_fs9.default.existsSync(paths.identitiesDir) ? import_node_fs9.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
14734
+ const identityNames = import_node_fs10.default.existsSync(paths.identitiesDir) ? import_node_fs10.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
14648
14735
  const identities = identityNames.map((name) => {
14649
14736
  const farmRoot = import_node_path30.default.join(paths.identitiesDir, name);
14650
14737
  const identityPath = import_node_path30.default.join(farmRoot, "identity.json");
14651
- return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs9.default.existsSync(credentialsFilePath(farmRoot)) };
14738
+ return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs10.default.existsSync(credentialsFilePath(farmRoot)) };
14652
14739
  });
14653
- const profileNames = import_node_fs9.default.existsSync(paths.configProfilesDir) ? import_node_fs9.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
14740
+ const profileNames = import_node_fs10.default.existsSync(paths.configProfilesDir) ? import_node_fs10.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
14654
14741
  const configProfiles = profileNames.map((name) => {
14655
14742
  const profilePath = import_node_path30.default.join(paths.configProfilesDir, `${name}.json`);
14656
14743
  return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
14657
14744
  });
14658
- const providerNames = import_node_fs9.default.existsSync(paths.providersDir) ? import_node_fs9.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
14745
+ const providerNames = import_node_fs10.default.existsSync(paths.providersDir) ? import_node_fs10.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
14659
14746
  const providers = providerNames.map((name) => {
14660
14747
  const providerPath = import_node_path30.default.join(paths.providersDir, `${name}.json`);
14661
14748
  return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
@@ -14700,7 +14787,7 @@ function collectDoctorReport(params) {
14700
14787
  categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
14701
14788
  activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
14702
14789
  binaryDiscovery,
14703
- claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs9.default.existsSync(shimState.targetPath) },
14790
+ claudeShim: { state: shimState, targetExists: shimState !== void 0 && import_node_fs10.default.existsSync(shimState.targetPath) },
14704
14791
  rootPath: paths.root,
14705
14792
  pathResolution: {
14706
14793
  ownExecutablePath,
@@ -14740,7 +14827,7 @@ function collectDoctorReport(params) {
14740
14827
  logPath: paths.headroomLogPath
14741
14828
  }
14742
14829
  },
14743
- ...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)) } }
14830
+ ...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) } }
14744
14831
  });
14745
14832
  return report;
14746
14833
  }
@@ -17731,8 +17818,8 @@ var SELF_HOST_SUBSCRIPTION_TYPE = "max";
17731
17818
  function isRecord12(value) {
17732
17819
  return typeof value === "object" && value !== null && !Array.isArray(value);
17733
17820
  }
17734
- function readJsonObject(fs12, file) {
17735
- const raw = fs12.readFileUtf8(file);
17821
+ function readJsonObject(fs13, file) {
17822
+ const raw = fs13.readFileUtf8(file);
17736
17823
  if (raw === void 0) {
17737
17824
  return void 0;
17738
17825
  }
@@ -17744,8 +17831,8 @@ function readJsonObject(fs12, file) {
17744
17831
  }
17745
17832
  return isRecord12(parsed) ? parsed : void 0;
17746
17833
  }
17747
- function readRcSelfHostRecord(fs12, frontdoorDir) {
17748
- const parsed = readJsonObject(fs12, import_node_path33.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
17834
+ function readRcSelfHostRecord(fs13, frontdoorDir) {
17835
+ const parsed = readJsonObject(fs13, import_node_path33.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
17749
17836
  if (parsed === void 0) {
17750
17837
  return void 0;
17751
17838
  }
@@ -17845,17 +17932,17 @@ function parseEntry2(project, entry) {
17845
17932
  const base = match?.[1];
17846
17933
  return base === void 0 ? { project, sessionId: entry, superseded: false, entry } : { project, sessionId: base, superseded: true, entry };
17847
17934
  }
17848
- function listSessions2(fs12, configDir) {
17935
+ function listSessions2(fs13, configDir) {
17849
17936
  const found = [];
17850
- for (const project of fs12.readdir(import_node_path34.default.join(configDir, PROJECTS_DIR))) {
17937
+ for (const project of fs13.readdir(import_node_path34.default.join(configDir, PROJECTS_DIR))) {
17851
17938
  const projectDir = import_node_path34.default.join(configDir, PROJECTS_DIR, project);
17852
17939
  const entries = /* @__PURE__ */ new Set();
17853
- for (const name of fs12.readdir(projectDir)) {
17940
+ for (const name of fs13.readdir(projectDir)) {
17854
17941
  if (name.endsWith(TRANSCRIPT_SUFFIX)) {
17855
17942
  entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
17856
17943
  continue;
17857
17944
  }
17858
- const children = fs12.readdir(import_node_path34.default.join(projectDir, name));
17945
+ const children = fs13.readdir(import_node_path34.default.join(projectDir, name));
17859
17946
  if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
17860
17947
  entries.add(name);
17861
17948
  }
@@ -17866,9 +17953,9 @@ function listSessions2(fs12, configDir) {
17866
17953
  }
17867
17954
  return found.sort((left, right) => left.project.localeCompare(right.project) || left.entry.localeCompare(right.entry));
17868
17955
  }
17869
- function locateAgents(fs12, configDir, relativeDir, workflowRunId, report) {
17956
+ function locateAgents(fs13, configDir, relativeDir, workflowRunId, report) {
17870
17957
  const located = [];
17871
- for (const name of listDirOrReport(fs12, configDir, relativeDir, report)) {
17958
+ for (const name of listDirOrReport(fs13, configDir, relativeDir, report)) {
17872
17959
  if (!name.startsWith(AGENT_FILE_PREFIX) || !name.endsWith(META_SUFFIX)) {
17873
17960
  continue;
17874
17961
  }
@@ -17917,17 +18004,17 @@ function toNode(read, children) {
17917
18004
  function describeFailure(error) {
17918
18005
  return error instanceof Error ? error.message : String(error);
17919
18006
  }
17920
- function readFileOrReport(fs12, configDir, relative, report) {
18007
+ function readFileOrReport(fs13, configDir, relative, report) {
17921
18008
  try {
17922
- return fs12.readFileUtf8(import_node_path34.default.join(configDir, relative));
18009
+ return fs13.readFileUtf8(import_node_path34.default.join(configDir, relative));
17923
18010
  } catch (error) {
17924
18011
  report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
17925
18012
  return void 0;
17926
18013
  }
17927
18014
  }
17928
- function listDirOrReport(fs12, configDir, relative, report) {
18015
+ function listDirOrReport(fs13, configDir, relative, report) {
17929
18016
  try {
17930
- return fs12.readdir(import_node_path34.default.join(configDir, relative));
18017
+ return fs13.readdir(import_node_path34.default.join(configDir, relative));
17931
18018
  } catch (error) {
17932
18019
  report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
17933
18020
  return [];
@@ -17950,22 +18037,22 @@ var WorkflowRunFileSchema = import_zod28.z.object({
17950
18037
  phases: import_zod28.z.array(import_zod28.z.object({ title: import_zod28.z.string() })).default([]),
17951
18038
  summary: import_zod28.z.string().optional()
17952
18039
  });
17953
- function summariseSession(fs12, configDir, ref) {
18040
+ function summariseSession(fs13, configDir, ref) {
17954
18041
  const sessionRelative = import_node_path34.default.join(PROJECTS_DIR, ref.project, ref.entry);
17955
18042
  const subagentsRelative = import_node_path34.default.join(sessionRelative, SUBAGENTS_DIR);
17956
18043
  const workflowsUnderSubagents = import_node_path34.default.join(subagentsRelative, WORKFLOWS_DIR);
17957
18044
  const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
17958
- let agentCount = fs12.readdir(import_node_path34.default.join(configDir, subagentsRelative)).filter(isMeta).length;
17959
- for (const runDir of fs12.readdir(import_node_path34.default.join(configDir, workflowsUnderSubagents))) {
18045
+ let agentCount = fs13.readdir(import_node_path34.default.join(configDir, subagentsRelative)).filter(isMeta).length;
18046
+ for (const runDir of fs13.readdir(import_node_path34.default.join(configDir, workflowsUnderSubagents))) {
17960
18047
  if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
17961
- agentCount += fs12.readdir(import_node_path34.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
18048
+ agentCount += fs13.readdir(import_node_path34.default.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
17962
18049
  }
17963
18050
  }
17964
- const workflowRunCount = fs12.readdir(import_node_path34.default.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
17965
- const transcript = fs12.lstat(import_node_path34.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
18051
+ const workflowRunCount = fs13.readdir(import_node_path34.default.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
18052
+ const transcript = fs13.lstat(import_node_path34.default.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
17966
18053
  return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
17967
18054
  }
17968
- function readSessionAgentTree(fs12, configDir, ref, options = {}) {
18055
+ function readSessionAgentTree(fs13, configDir, ref, options = {}) {
17969
18056
  const problems = [];
17970
18057
  const report = (problem) => {
17971
18058
  problems.push(problem);
@@ -17973,15 +18060,15 @@ function readSessionAgentTree(fs12, configDir, ref, options = {}) {
17973
18060
  const sessionRelative = import_node_path34.default.join(PROJECTS_DIR, ref.project, ref.entry);
17974
18061
  const subagentsRelative = import_node_path34.default.join(sessionRelative, SUBAGENTS_DIR);
17975
18062
  const workflowsUnderSubagents = import_node_path34.default.join(subagentsRelative, WORKFLOWS_DIR);
17976
- const located = locateAgents(fs12, configDir, subagentsRelative, void 0, report);
17977
- for (const runDir of listDirOrReport(fs12, configDir, workflowsUnderSubagents, report)) {
18063
+ const located = locateAgents(fs13, configDir, subagentsRelative, void 0, report);
18064
+ for (const runDir of listDirOrReport(fs13, configDir, workflowsUnderSubagents, report)) {
17978
18065
  if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
17979
- located.push(...locateAgents(fs12, configDir, import_node_path34.default.join(workflowsUnderSubagents, runDir), runDir, report));
18066
+ located.push(...locateAgents(fs13, configDir, import_node_path34.default.join(workflowsUnderSubagents, runDir), runDir, report));
17980
18067
  }
17981
18068
  }
17982
18069
  const agents = /* @__PURE__ */ new Map();
17983
18070
  for (const candidate of located) {
17984
- const text = readFileOrReport(fs12, configDir, candidate.metaPath, report);
18071
+ const text = readFileOrReport(fs13, configDir, candidate.metaPath, report);
17985
18072
  if (text === void 0) {
17986
18073
  continue;
17987
18074
  }
@@ -17993,7 +18080,7 @@ function readSessionAgentTree(fs12, configDir, ref, options = {}) {
17993
18080
  agents.set(candidate.id, { located: candidate, meta: parsed.data });
17994
18081
  }
17995
18082
  const teamNames = [...new Set([...agents.values()].flatMap((agent) => agent.meta.teamName === void 0 ? [] : [agent.meta.teamName]))].sort();
17996
- const parentOf3 = resolveParents(fs12, configDir, agents, report);
18083
+ const parentOf3 = resolveParents(fs13, configDir, agents, report);
17997
18084
  const childrenOf = /* @__PURE__ */ new Map();
17998
18085
  const roots = [];
17999
18086
  for (const id of agents.keys()) {
@@ -18016,12 +18103,12 @@ function readSessionAgentTree(fs12, configDir, ref, options = {}) {
18016
18103
  sessionId: ref.sessionId,
18017
18104
  superseded: ref.superseded,
18018
18105
  agents: roots.sort().map(build),
18019
- tasks: readTasks(fs12, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
18020
- workflowRuns: readWorkflowRuns(fs12, configDir, import_node_path34.default.join(sessionRelative, WORKFLOWS_DIR), report),
18106
+ tasks: readTasks(fs13, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
18107
+ workflowRuns: readWorkflowRuns(fs13, configDir, import_node_path34.default.join(sessionRelative, WORKFLOWS_DIR), report),
18021
18108
  problems
18022
18109
  };
18023
18110
  }
18024
- function resolveParents(fs12, configDir, agents, report) {
18111
+ function resolveParents(fs13, configDir, agents, report) {
18025
18112
  const parentOf3 = /* @__PURE__ */ new Map();
18026
18113
  const transcriptCache = /* @__PURE__ */ new Map();
18027
18114
  const transcriptOf = (agent) => {
@@ -18029,7 +18116,7 @@ function resolveParents(fs12, configDir, agents, report) {
18029
18116
  if (cached !== void 0) {
18030
18117
  return cached;
18031
18118
  }
18032
- const text = readFileOrReport(fs12, configDir, agent.located.transcriptPath, report) ?? "";
18119
+ const text = readFileOrReport(fs13, configDir, agent.located.transcriptPath, report) ?? "";
18033
18120
  transcriptCache.set(agent.located.id, text);
18034
18121
  return text;
18035
18122
  };
@@ -18079,16 +18166,16 @@ function resolveParents(fs12, configDir, agents, report) {
18079
18166
  function ownTaskLists(sessionId) {
18080
18167
  return [sessionId, `${SHORT_SESSION_LIST_PREFIX}${sessionId.slice(0, SHORT_SESSION_ID_LENGTH)}`];
18081
18168
  }
18082
- function readTasks(fs12, configDir, ownLists, sharedLists, report) {
18169
+ function readTasks(fs13, configDir, ownLists, sharedLists, report) {
18083
18170
  const tasks = [];
18084
18171
  [...ownLists, ...sharedLists].forEach((scope, index) => {
18085
18172
  const relativeDir = import_node_path34.default.join(TASKS_DIR, scope);
18086
- for (const name of [...listDirOrReport(fs12, configDir, relativeDir, report)].sort()) {
18173
+ for (const name of [...listDirOrReport(fs13, configDir, relativeDir, report)].sort()) {
18087
18174
  if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
18088
18175
  continue;
18089
18176
  }
18090
18177
  const relative = import_node_path34.default.join(relativeDir, name);
18091
- const text = readFileOrReport(fs12, configDir, relative, report);
18178
+ const text = readFileOrReport(fs13, configDir, relative, report);
18092
18179
  const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
18093
18180
  if (parsed.success) {
18094
18181
  tasks.push(index < ownLists.length ? parsed.data : { ...parsed.data, taskList: scope });
@@ -18099,14 +18186,14 @@ function readTasks(fs12, configDir, ownLists, sharedLists, report) {
18099
18186
  });
18100
18187
  return tasks;
18101
18188
  }
18102
- function readWorkflowRuns(fs12, configDir, relativeDir, report) {
18189
+ function readWorkflowRuns(fs13, configDir, relativeDir, report) {
18103
18190
  const runs = [];
18104
- for (const name of [...listDirOrReport(fs12, configDir, relativeDir, report)].sort()) {
18191
+ for (const name of [...listDirOrReport(fs13, configDir, relativeDir, report)].sort()) {
18105
18192
  if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
18106
18193
  continue;
18107
18194
  }
18108
18195
  const relative = import_node_path34.default.join(relativeDir, name);
18109
- const text = readFileOrReport(fs12, configDir, relative, report);
18196
+ const text = readFileOrReport(fs13, configDir, relative, report);
18110
18197
  const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
18111
18198
  if (!parsed.success) {
18112
18199
  if (text !== void 0) {
@@ -18132,11 +18219,11 @@ var SessionLookupError = class extends CliError {
18132
18219
  function identityConfigDir(identitiesDir, identity) {
18133
18220
  return import_node_path35.default.join(identitiesDir, identity);
18134
18221
  }
18135
- function historyStores(fs12, identitiesDir, identities) {
18222
+ function historyStores(fs13, identitiesDir, identities) {
18136
18223
  const byRealPath = /* @__PURE__ */ new Map();
18137
18224
  for (const identity of identities) {
18138
18225
  const configDir = identityConfigDir(identitiesDir, identity);
18139
- const real = fs12.realpath(import_node_path35.default.join(configDir, "projects"));
18226
+ const real = fs13.realpath(import_node_path35.default.join(configDir, "projects"));
18140
18227
  if (real === void 0) {
18141
18228
  continue;
18142
18229
  }
@@ -18149,15 +18236,15 @@ function historyStores(fs12, identitiesDir, identities) {
18149
18236
  }
18150
18237
  return [...byRealPath.values()];
18151
18238
  }
18152
- function collectSessionList(fs12, identitiesDir, identities, filters) {
18239
+ function collectSessionList(fs13, identitiesDir, identities, filters) {
18153
18240
  const names = filters.identity === void 0 ? identities : identities.filter((name) => name === filters.identity);
18154
18241
  if (filters.identity !== void 0 && names.length === 0) {
18155
18242
  throw new SessionLookupError(`no identity named "${filters.identity}"`);
18156
18243
  }
18157
18244
  const sessions = [];
18158
- for (const store of historyStores(fs12, identitiesDir, names)) {
18159
- for (const ref of listSessions2(fs12, store.configDir)) {
18160
- const summary = summariseSession(fs12, store.configDir, ref);
18245
+ for (const store of historyStores(fs13, identitiesDir, names)) {
18246
+ for (const ref of listSessions2(fs13, store.configDir)) {
18247
+ const summary = summariseSession(fs13, store.configDir, ref);
18161
18248
  if (filters.all === true || summary.agentCount > 0 || summary.workflowRunCount > 0) {
18162
18249
  sessions.push({ ...summary, identities: store.identities });
18163
18250
  }
@@ -18165,14 +18252,14 @@ function collectSessionList(fs12, identitiesDir, identities, filters) {
18165
18252
  }
18166
18253
  return sessions.sort((left, right) => (right.updatedAt ?? "").localeCompare(left.updatedAt ?? "") || left.sessionId.localeCompare(right.sessionId));
18167
18254
  }
18168
- function locateSession(fs12, identitiesDir, identities, query, onlyIdentity) {
18255
+ function locateSession(fs13, identitiesDir, identities, query, onlyIdentity) {
18169
18256
  const names = onlyIdentity === void 0 ? identities : identities.filter((name) => name === onlyIdentity);
18170
18257
  if (onlyIdentity !== void 0 && names.length === 0) {
18171
18258
  throw new SessionLookupError(`no identity named "${onlyIdentity}"`);
18172
18259
  }
18173
18260
  const matches = [];
18174
- for (const store of historyStores(fs12, identitiesDir, names)) {
18175
- for (const ref of listSessions2(fs12, store.configDir)) {
18261
+ for (const store of historyStores(fs13, identitiesDir, names)) {
18262
+ for (const ref of listSessions2(fs13, store.configDir)) {
18176
18263
  if (ref.sessionId.startsWith(query)) {
18177
18264
  matches.push({ identities: store.identities, configDir: store.configDir, ref });
18178
18265
  }
@@ -18189,19 +18276,19 @@ function locateSession(fs12, identitiesDir, identities, query, onlyIdentity) {
18189
18276
  }
18190
18277
  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`);
18191
18278
  }
18192
- function showSession(fs12, identitiesDir, identities, query, onlyIdentity) {
18193
- const located = locateSession(fs12, identitiesDir, identities, query, onlyIdentity);
18194
- return { identities: located.identities, tree: readSessionAgentTree(fs12, located.configDir, located.ref) };
18279
+ function showSession(fs13, identitiesDir, identities, query, onlyIdentity) {
18280
+ const located = locateSession(fs13, identitiesDir, identities, query, onlyIdentity);
18281
+ return { identities: located.identities, tree: readSessionAgentTree(fs13, located.configDir, located.ref) };
18195
18282
  }
18196
18283
 
18197
18284
  // src/agents/realFs.ts
18198
- var import_node_fs10 = __toESM(require("node:fs"), 1);
18285
+ var import_node_fs11 = __toESM(require("node:fs"), 1);
18199
18286
  init_realPorts();
18200
18287
  var realSessionFs = {
18201
18288
  ...realFarmFs,
18202
18289
  realpath: (candidate) => {
18203
18290
  try {
18204
- return import_node_fs10.default.realpathSync(candidate);
18291
+ return import_node_fs11.default.realpathSync(candidate);
18205
18292
  } catch {
18206
18293
  return void 0;
18207
18294
  }