agent-shim 11.87.5 → 11.88.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5189,7 +5189,7 @@ var init_package = __esm({
5189
5189
  "package.json"() {
5190
5190
  package_default = {
5191
5191
  name: "agent-shim",
5192
- version: "11.87.5",
5192
+ version: "11.88.1",
5193
5193
  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.",
5194
5194
  license: "MIT",
5195
5195
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -6747,8 +6747,10 @@ var init_realPorts = __esm({
6747
6747
  init_ensure();
6748
6748
  init_supervisor2();
6749
6749
  init_state2();
6750
+ init_sameDirectory();
6750
6751
  init_logStyle();
6751
6752
  realFsPort = {
6753
+ sameDirectory,
6752
6754
  fileRevision(filePath) {
6753
6755
  try {
6754
6756
  const stat = import_node_fs4.default.statSync(filePath, { bigint: true });
@@ -7180,19 +7182,21 @@ function readActiveIdentity(fs17, activeIdentityFile) {
7180
7182
  function isNonEmpty(value) {
7181
7183
  return value !== void 0 && value !== "";
7182
7184
  }
7183
- function selected(selector, source) {
7185
+ function selected(selector, source, supersededConfigDir) {
7184
7186
  if (!IdentitySelectorSchema.safeParse(selector).success) {
7185
7187
  throw new UnsafeNameError(selector, "identity", `${FILE_NAME_RULE}, or be pool:<name> for a pool`, IDENTITY_SOURCE_LABELS[source]);
7186
7188
  }
7187
7189
  const pool = poolNameOf(selector);
7188
- return pool === void 0 ? { name: selector, source, configDirEscapeHatch: false } : { pool, source, configDirEscapeHatch: false };
7190
+ const superseded = supersededConfigDir === void 0 ? {} : { supersededConfigDir };
7191
+ return pool === void 0 ? { name: selector, source, configDirEscapeHatch: false, ...superseded } : { pool, source, configDirEscapeHatch: false, ...superseded };
7189
7192
  }
7190
7193
  function decideIdentity(params) {
7191
- if (isNonEmpty(params.env.CLAUDE_CONFIG_DIR)) {
7192
- return { source: "config-dir-escape-hatch", configDirEscapeHatch: true };
7193
- }
7194
+ const inheritedConfigDir = isNonEmpty(params.env.CLAUDE_CONFIG_DIR) ? params.env.CLAUDE_CONFIG_DIR : void 0;
7194
7195
  if (isNonEmpty(params.argv0Identity)) {
7195
- return selected(params.argv0Identity, "argv");
7196
+ return selected(params.argv0Identity, "argv", inheritedConfigDir);
7197
+ }
7198
+ if (inheritedConfigDir !== void 0) {
7199
+ return { source: "config-dir-escape-hatch", configDirEscapeHatch: true };
7196
7200
  }
7197
7201
  if (isNonEmpty(params.env.AGENT_SHIM_IDENTITY)) {
7198
7202
  return selected(params.env.AGENT_SHIM_IDENTITY, "env");
@@ -7271,7 +7275,7 @@ var init_identity = __esm({
7271
7275
  init_identityRecords();
7272
7276
  init_sameDirectory();
7273
7277
  IDENTITY_DECISION_SOURCES = [
7274
- /** `CLAUDE_CONFIG_DIR` was already set: identity resolution is skipped entirely and the real binary uses whatever it already points to. */
7278
+ /** `CLAUDE_CONFIG_DIR` was already set and nothing on the command line names an identity: identity resolution is skipped entirely and the real binary uses whatever it already points to. */
7275
7279
  "config-dir-escape-hatch",
7276
7280
  /** A leading `@name` argv[0] positional, or its explicit form `--identity <name>`. */
7277
7281
  "argv",
@@ -11561,6 +11565,156 @@ var init_claudeVersion = __esm({
11561
11565
  }
11562
11566
  });
11563
11567
 
11568
+ // src/headroom/headers.ts
11569
+ function mergeAnthropicCustomHeaders(existing, additions) {
11570
+ const merged = /* @__PURE__ */ new Map();
11571
+ for (const block of existing) {
11572
+ if (block === void 0) {
11573
+ continue;
11574
+ }
11575
+ for (const line of block.split("\n")) {
11576
+ const entry = parseCustomHeaderLine(line);
11577
+ if (entry === void 0) {
11578
+ continue;
11579
+ }
11580
+ merged.set(entry.name, entry.value);
11581
+ }
11582
+ }
11583
+ for (const entry of additions) {
11584
+ merged.set(entry.name, entry.value);
11585
+ }
11586
+ return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
11587
+ }
11588
+ function parseAnthropicCustomHeaders(block) {
11589
+ return block.split("\n").flatMap((line) => {
11590
+ const entry = parseCustomHeaderLine(line);
11591
+ return entry === void 0 ? [] : [entry];
11592
+ });
11593
+ }
11594
+ function withoutAnthropicCustomHeaders(block, remove) {
11595
+ const lines = block.split("\n");
11596
+ const kept = lines.filter((line) => {
11597
+ const entry = parseCustomHeaderLine(line);
11598
+ return entry === void 0 || !remove(entry);
11599
+ });
11600
+ return kept.length === lines.length ? block : kept.join("\n");
11601
+ }
11602
+ function parseCustomHeaderLine(line) {
11603
+ const trimmed = line.trim();
11604
+ if (trimmed === "") {
11605
+ return void 0;
11606
+ }
11607
+ const colon = trimmed.indexOf(":");
11608
+ if (colon <= 0) {
11609
+ return void 0;
11610
+ }
11611
+ return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
11612
+ }
11613
+ var init_headers = __esm({
11614
+ "src/headroom/headers.ts"() {
11615
+ "use strict";
11616
+ }
11617
+ });
11618
+
11619
+ // src/launcher/injected.ts
11620
+ function listKey(list) {
11621
+ return `${list},appended`;
11622
+ }
11623
+ function digest2(value) {
11624
+ return (0, import_node_crypto13.createHash)("sha256").update(value).digest("hex");
11625
+ }
11626
+ function recordedDigests(env) {
11627
+ const raw = env[INJECTED_ENV];
11628
+ if (raw === void 0 || raw === "") {
11629
+ return {};
11630
+ }
11631
+ let parsed;
11632
+ try {
11633
+ parsed = JSON.parse(raw);
11634
+ } catch {
11635
+ return {};
11636
+ }
11637
+ const result = InjectedSchema.safeParse(parsed);
11638
+ return result.success ? result.data : {};
11639
+ }
11640
+ function recordInjections(base) {
11641
+ const env = { ...base };
11642
+ const digests = new Map(Object.entries(recordedDigests(env)));
11643
+ return {
11644
+ env,
11645
+ set: (name, value) => {
11646
+ env[name] = value;
11647
+ digests.set(name, digest2(value));
11648
+ },
11649
+ unset: (name) => {
11650
+ env[name] = void 0;
11651
+ digests.delete(name);
11652
+ },
11653
+ recordHeaders: (names) => {
11654
+ const block = env[CUSTOM_HEADERS_ENV];
11655
+ for (const entry of block === void 0 ? [] : parseAnthropicCustomHeaders(block)) {
11656
+ if (names.includes(entry.name)) {
11657
+ digests.set(`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`, digest2(entry.value));
11658
+ }
11659
+ }
11660
+ },
11661
+ recordBypassHosts: (list, hosts) => {
11662
+ const recordedHosts = [.../* @__PURE__ */ new Set([...digests.get(listKey(list))?.split(",") ?? [], ...hosts.map((host) => host.trim().toLowerCase()).filter((host) => host !== "")])];
11663
+ if (recordedHosts.length > 0) {
11664
+ digests.set(listKey(list), recordedHosts.join(","));
11665
+ }
11666
+ },
11667
+ finish: () => {
11668
+ if (digests.size > 0) {
11669
+ env[INJECTED_ENV] = JSON.stringify(Object.fromEntries(digests));
11670
+ }
11671
+ }
11672
+ };
11673
+ }
11674
+ function withoutRecordedHosts(list, value, digests) {
11675
+ const recordedHosts = new Set(digests[listKey(list)]?.split(","));
11676
+ const entries = value.split(",");
11677
+ const kept = entries.filter((entry) => !recordedHosts.has(entry.trim().toLowerCase()));
11678
+ return kept.length === entries.length ? value : kept.join(",");
11679
+ }
11680
+ function launchEnvironment(env, configDirEscapeHatch) {
11681
+ return configDirEscapeHatch ? env : withoutInjected(env);
11682
+ }
11683
+ function withoutInjected(env) {
11684
+ const digests = recordedDigests(env);
11685
+ const entries = Object.entries(env).flatMap(([name, value]) => {
11686
+ if (name === INJECTED_ENV) {
11687
+ return [];
11688
+ }
11689
+ if (value === void 0) {
11690
+ return [[name, value]];
11691
+ }
11692
+ if (name === CUSTOM_HEADERS_ENV) {
11693
+ const remaining = withoutAnthropicCustomHeaders(value, (entry) => digests[`${HEADER_KEY_PREFIX}${entry.name.toLowerCase()}`] === digest2(entry.value));
11694
+ return remaining !== value && remaining.trim() === "" ? [] : [[name, remaining]];
11695
+ }
11696
+ if (name === "NO_PROXY" || name === "no_proxy") {
11697
+ const remaining = withoutRecordedHosts(name, value, digests);
11698
+ return remaining !== value && remaining.split(",").every((entry) => entry.trim() === "") ? [] : [[name, remaining]];
11699
+ }
11700
+ return digests[name] === digest2(value) ? [] : [[name, value]];
11701
+ });
11702
+ return Object.fromEntries(entries);
11703
+ }
11704
+ var import_node_crypto13, import_zod24, INJECTED_ENV, CUSTOM_HEADERS_ENV, HEADER_KEY_PREFIX, InjectedSchema;
11705
+ var init_injected = __esm({
11706
+ "src/launcher/injected.ts"() {
11707
+ "use strict";
11708
+ import_node_crypto13 = require("node:crypto");
11709
+ import_zod24 = require("zod");
11710
+ init_headers();
11711
+ INJECTED_ENV = "AGENT_SHIM_INJECTED";
11712
+ CUSTOM_HEADERS_ENV = "ANTHROPIC_CUSTOM_HEADERS";
11713
+ HEADER_KEY_PREFIX = `${CUSTOM_HEADERS_ENV}:`;
11714
+ InjectedSchema = import_zod24.z.record(import_zod24.z.string(), import_zod24.z.string());
11715
+ }
11716
+ });
11717
+
11564
11718
  // src/launcher/guard.ts
11565
11719
  function detectAmbientCredential(env, injected) {
11566
11720
  for (const variable of AMBIENT_CREDENTIAL_VARS) {
@@ -11599,10 +11753,22 @@ function evaluateAmbientCredentialGuard(params) {
11599
11753
  message: formatAmbientCredentialGuardMessage(detected.variable, params.identityName)
11600
11754
  };
11601
11755
  }
11756
+ function ambientCredentialFinding(env) {
11757
+ const named = detectAmbientCredential(launchEnvironment(env, false));
11758
+ if (named !== void 0) {
11759
+ return { severity: "warn", message: formatAmbientCredentialGuardMessage(named.variable) };
11760
+ }
11761
+ const bare = env.CLAUDE_CONFIG_DIR === void 0 || env.CLAUDE_CONFIG_DIR === "" ? void 0 : detectAmbientCredential(env);
11762
+ if (bare !== void 0) {
11763
+ return { severity: "warn", message: `${bare.variable} was set in this session by the launcher that started it. A launch that names an identity drops it, but a launch naming none keeps the session's CLAUDE_CONFIG_DIR and environment and is refused. Name an identity, as in \`claude @<name>\`.` };
11764
+ }
11765
+ return { severity: "pass", message: "No ambient-credential environment variable is set." };
11766
+ }
11602
11767
  var AMBIENT_CREDENTIAL_VARS;
11603
11768
  var init_guard = __esm({
11604
11769
  "src/launcher/guard.ts"() {
11605
11770
  "use strict";
11771
+ init_injected();
11606
11772
  AMBIENT_CREDENTIAL_VARS = [
11607
11773
  "ANTHROPIC_API_KEY",
11608
11774
  "ANTHROPIC_AUTH_TOKEN",
@@ -11720,46 +11886,46 @@ function findPathShadow(params) {
11720
11886
  }
11721
11887
  return params.pathDirs.some((dir) => import_node_path37.default.resolve(dir) === resolvedTargetDir) ? { status: "ok" } : { status: "not-on-path" };
11722
11888
  }
11723
- var import_node_fs11, import_node_path37, import_zod28, ClaudeShimStateSchema, nodeLinkFs;
11889
+ var import_node_fs11, import_node_path37, import_zod29, ClaudeShimStateSchema, nodeLinkFs;
11724
11890
  var init_claudeShim = __esm({
11725
11891
  "src/claudeShim.ts"() {
11726
11892
  "use strict";
11727
11893
  import_node_fs11 = __toESM(require("node:fs"), 1);
11728
11894
  import_node_path37 = __toESM(require("node:path"), 1);
11729
- import_zod28 = require("zod");
11895
+ import_zod29 = require("zod");
11730
11896
  init_commandDeps();
11731
11897
  init_store();
11732
11898
  init_realPorts();
11733
11899
  init_cliError();
11734
- ClaudeShimStateSchema = import_zod28.z.strictObject({
11735
- targetPath: import_zod28.z.string().min(1),
11736
- method: import_zod28.z.enum(["hardlink", "copy"]),
11737
- installedAtMs: import_zod28.z.number()
11900
+ ClaudeShimStateSchema = import_zod29.z.strictObject({
11901
+ targetPath: import_zod29.z.string().min(1),
11902
+ method: import_zod29.z.enum(["hardlink", "copy"]),
11903
+ installedAtMs: import_zod29.z.number()
11738
11904
  });
11739
11905
  nodeLinkFs = { link: import_node_fs11.default.linkSync, copyFile: import_node_fs11.default.copyFileSync, chmod: import_node_fs11.default.chmodSync };
11740
11906
  }
11741
11907
  });
11742
11908
 
11743
11909
  // src/codex/auth.ts
11744
- var import_zod29, AuthFileSchema, TokenGrantSchema, CodexAuthError;
11910
+ var import_zod30, AuthFileSchema, TokenGrantSchema, CodexAuthError;
11745
11911
  var init_auth = __esm({
11746
11912
  "src/codex/auth.ts"() {
11747
11913
  "use strict";
11748
- import_zod29 = require("zod");
11749
- AuthFileSchema = import_zod29.z.looseObject({
11750
- tokens: import_zod29.z.looseObject({
11751
- access_token: import_zod29.z.string().optional(),
11752
- refresh_token: import_zod29.z.string().optional(),
11753
- id_token: import_zod29.z.string().optional(),
11754
- account_id: import_zod29.z.string().optional()
11914
+ import_zod30 = require("zod");
11915
+ AuthFileSchema = import_zod30.z.looseObject({
11916
+ tokens: import_zod30.z.looseObject({
11917
+ access_token: import_zod30.z.string().optional(),
11918
+ refresh_token: import_zod30.z.string().optional(),
11919
+ id_token: import_zod30.z.string().optional(),
11920
+ account_id: import_zod30.z.string().optional()
11755
11921
  }).nullish(),
11756
- last_refresh: import_zod29.z.string().optional()
11922
+ last_refresh: import_zod30.z.string().optional()
11757
11923
  });
11758
- TokenGrantSchema = import_zod29.z.looseObject({
11759
- access_token: import_zod29.z.string().min(1).optional(),
11760
- refresh_token: import_zod29.z.string().min(1).optional(),
11761
- id_token: import_zod29.z.string().min(1).optional(),
11762
- account_id: import_zod29.z.string().min(1).optional()
11924
+ TokenGrantSchema = import_zod30.z.looseObject({
11925
+ access_token: import_zod30.z.string().min(1).optional(),
11926
+ refresh_token: import_zod30.z.string().min(1).optional(),
11927
+ id_token: import_zod30.z.string().min(1).optional(),
11928
+ account_id: import_zod30.z.string().min(1).optional()
11763
11929
  });
11764
11930
  CodexAuthError = class extends Error {
11765
11931
  constructor(message) {
@@ -11771,31 +11937,31 @@ var init_auth = __esm({
11771
11937
  });
11772
11938
 
11773
11939
  // src/codex/siwc.ts
11774
- var import_zod30, SIWC_RESOURCE, SIWC_RESPONSES_URL, SIWC_PLAN_SCOPE, TokenResponseSchema, JwtHeaderSchema, IdTokenClaimsSchema, JwksSchema;
11940
+ var import_zod31, SIWC_RESOURCE, SIWC_RESPONSES_URL, SIWC_PLAN_SCOPE, TokenResponseSchema, JwtHeaderSchema, IdTokenClaimsSchema, JwksSchema;
11775
11941
  var init_siwc = __esm({
11776
11942
  "src/codex/siwc.ts"() {
11777
11943
  "use strict";
11778
- import_zod30 = require("zod");
11944
+ import_zod31 = require("zod");
11779
11945
  SIWC_RESOURCE = "https://api.openai.com/v1";
11780
11946
  SIWC_RESPONSES_URL = `${SIWC_RESOURCE}/responses`;
11781
11947
  SIWC_PLAN_SCOPE = "chatgpt.tokens.use.direct";
11782
- TokenResponseSchema = import_zod30.z.looseObject({
11783
- access_token: import_zod30.z.string().min(1),
11784
- refresh_token: import_zod30.z.string().min(1).optional(),
11785
- id_token: import_zod30.z.string().min(1).optional(),
11786
- expires_in: import_zod30.z.number().positive(),
11787
- scope: import_zod30.z.string().optional()
11948
+ TokenResponseSchema = import_zod31.z.looseObject({
11949
+ access_token: import_zod31.z.string().min(1),
11950
+ refresh_token: import_zod31.z.string().min(1).optional(),
11951
+ id_token: import_zod31.z.string().min(1).optional(),
11952
+ expires_in: import_zod31.z.number().positive(),
11953
+ scope: import_zod31.z.string().optional()
11788
11954
  });
11789
- JwtHeaderSchema = import_zod30.z.looseObject({ alg: import_zod30.z.string(), kid: import_zod30.z.string().optional() });
11790
- IdTokenClaimsSchema = import_zod30.z.looseObject({
11791
- iss: import_zod30.z.string(),
11792
- sub: import_zod30.z.string().min(1),
11793
- aud: import_zod30.z.union([import_zod30.z.string(), import_zod30.z.array(import_zod30.z.string())]),
11794
- exp: import_zod30.z.number(),
11795
- nonce: import_zod30.z.string().optional(),
11796
- email: import_zod30.z.string().optional()
11955
+ JwtHeaderSchema = import_zod31.z.looseObject({ alg: import_zod31.z.string(), kid: import_zod31.z.string().optional() });
11956
+ IdTokenClaimsSchema = import_zod31.z.looseObject({
11957
+ iss: import_zod31.z.string(),
11958
+ sub: import_zod31.z.string().min(1),
11959
+ aud: import_zod31.z.union([import_zod31.z.string(), import_zod31.z.array(import_zod31.z.string())]),
11960
+ exp: import_zod31.z.number(),
11961
+ nonce: import_zod31.z.string().optional(),
11962
+ email: import_zod31.z.string().optional()
11797
11963
  });
11798
- JwksSchema = import_zod30.z.object({ keys: import_zod30.z.array(import_zod30.z.looseObject({ kid: import_zod30.z.string().optional(), kty: import_zod30.z.string() })) });
11964
+ JwksSchema = import_zod31.z.object({ keys: import_zod31.z.array(import_zod31.z.looseObject({ kid: import_zod31.z.string().optional(), kty: import_zod31.z.string() })) });
11799
11965
  }
11800
11966
  });
11801
11967
 
@@ -11813,25 +11979,25 @@ function parseSiwcFile(raw, filePath) {
11813
11979
  }
11814
11980
  return parsed.data;
11815
11981
  }
11816
- var import_zod31, SiwcGrantSchema, SiwcFileSchema;
11982
+ var import_zod32, SiwcGrantSchema, SiwcFileSchema;
11817
11983
  var init_siwcStore = __esm({
11818
11984
  "src/codex/siwcStore.ts"() {
11819
11985
  "use strict";
11820
- import_zod31 = require("zod");
11986
+ import_zod32 = require("zod");
11821
11987
  init_auth();
11822
11988
  init_siwc();
11823
- SiwcGrantSchema = import_zod31.z.strictObject({
11824
- clientId: import_zod31.z.string().min(1),
11825
- sub: import_zod31.z.string().min(1),
11826
- email: import_zod31.z.string().optional(),
11827
- idToken: import_zod31.z.string().min(1),
11828
- accessToken: import_zod31.z.string().min(1),
11829
- refreshToken: import_zod31.z.string().min(1),
11830
- scopes: import_zod31.z.array(import_zod31.z.string()).readonly(),
11989
+ SiwcGrantSchema = import_zod32.z.strictObject({
11990
+ clientId: import_zod32.z.string().min(1),
11991
+ sub: import_zod32.z.string().min(1),
11992
+ email: import_zod32.z.string().optional(),
11993
+ idToken: import_zod32.z.string().min(1),
11994
+ accessToken: import_zod32.z.string().min(1),
11995
+ refreshToken: import_zod32.z.string().min(1),
11996
+ scopes: import_zod32.z.array(import_zod32.z.string()).readonly(),
11831
11997
  /** When the access token stops working, in milliseconds since the epoch. */
11832
- expiresAt: import_zod31.z.number()
11998
+ expiresAt: import_zod32.z.number()
11833
11999
  });
11834
- SiwcFileSchema = import_zod31.z.strictObject({ registeredClientId: import_zod31.z.string().min(1).optional(), grant: SiwcGrantSchema.optional() });
12000
+ SiwcFileSchema = import_zod32.z.strictObject({ registeredClientId: import_zod32.z.string().min(1).optional(), grant: SiwcGrantSchema.optional() });
11835
12001
  }
11836
12002
  });
11837
12003
 
@@ -11899,7 +12065,7 @@ function parseCatalogueBinding(raw) {
11899
12065
  }
11900
12066
  }
11901
12067
  function catalogueCredentialFingerprint(cli, token, accountId) {
11902
- return (0, import_node_crypto13.createHash)("sha256").update(JSON.stringify([cli, token, accountId])).digest("hex");
12068
+ return (0, import_node_crypto14.createHash)("sha256").update(JSON.stringify([cli, token, accountId])).digest("hex");
11903
12069
  }
11904
12070
  function cliCatalogueFingerprint(raw) {
11905
12071
  if (raw === void 0) return void 0;
@@ -11924,15 +12090,15 @@ function savedCatalogueFingerprint(provider, paths, env, home, read) {
11924
12090
  const codexHome = configuredHome === void 0 || configuredHome === "" ? import_node_path40.default.join(home, ".codex") : configuredHome;
11925
12091
  return cliCatalogueFingerprint(read(import_node_path40.default.join(codexHome, "auth.json")));
11926
12092
  }
11927
- var import_node_crypto13, import_node_path40, import_zod32, CatalogueBindingSchema;
12093
+ var import_node_crypto14, import_node_path40, import_zod33, CatalogueBindingSchema;
11928
12094
  var init_catalogueCredential = __esm({
11929
12095
  "src/codex/catalogueCredential.ts"() {
11930
12096
  "use strict";
11931
- import_node_crypto13 = require("node:crypto");
12097
+ import_node_crypto14 = require("node:crypto");
11932
12098
  import_node_path40 = __toESM(require("node:path"), 1);
11933
- import_zod32 = require("zod");
12099
+ import_zod33 = require("zod");
11934
12100
  init_siwcStore();
11935
- CatalogueBindingSchema = import_zod32.z.strictObject({ fingerprint: import_zod32.z.string().min(1), source: import_zod32.z.string().min(1), revision: import_zod32.z.string().min(1) });
12101
+ CatalogueBindingSchema = import_zod33.z.strictObject({ fingerprint: import_zod33.z.string().min(1), source: import_zod33.z.string().min(1), revision: import_zod33.z.string().min(1) });
11936
12102
  }
11937
12103
  });
11938
12104
 
@@ -11983,64 +12149,64 @@ var init_signatures = __esm({
11983
12149
  });
11984
12150
 
11985
12151
  // src/codex/anthropic.ts
11986
- var import_zod33, TextBlockSchema, Base64ImageSourceSchema, UrlImageSourceSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultContentBlockSchema, ToolResultBlockSchema, OtherBlockSchema, ContentBlockSchema, MessageSchema, ToolSchema, ToolChoiceSchema, SystemSchema, MessagesRequestSchema, CountTokensRequestSchema;
12152
+ var import_zod34, TextBlockSchema, Base64ImageSourceSchema, UrlImageSourceSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultContentBlockSchema, ToolResultBlockSchema, OtherBlockSchema, ContentBlockSchema, MessageSchema, ToolSchema, ToolChoiceSchema, SystemSchema, MessagesRequestSchema, CountTokensRequestSchema;
11987
12153
  var init_anthropic = __esm({
11988
12154
  "src/codex/anthropic.ts"() {
11989
12155
  "use strict";
11990
- import_zod33 = require("zod");
11991
- TextBlockSchema = import_zod33.z.looseObject({ type: import_zod33.z.literal("text"), text: import_zod33.z.string() });
11992
- Base64ImageSourceSchema = import_zod33.z.looseObject({ type: import_zod33.z.literal("base64"), media_type: import_zod33.z.string().min(1), data: import_zod33.z.string() });
11993
- UrlImageSourceSchema = import_zod33.z.looseObject({ type: import_zod33.z.literal("url"), url: import_zod33.z.string().min(1) });
11994
- ImageBlockSchema = import_zod33.z.looseObject({
11995
- type: import_zod33.z.literal("image"),
11996
- source: import_zod33.z.union([Base64ImageSourceSchema, UrlImageSourceSchema])
12156
+ import_zod34 = require("zod");
12157
+ TextBlockSchema = import_zod34.z.looseObject({ type: import_zod34.z.literal("text"), text: import_zod34.z.string() });
12158
+ Base64ImageSourceSchema = import_zod34.z.looseObject({ type: import_zod34.z.literal("base64"), media_type: import_zod34.z.string().min(1), data: import_zod34.z.string() });
12159
+ UrlImageSourceSchema = import_zod34.z.looseObject({ type: import_zod34.z.literal("url"), url: import_zod34.z.string().min(1) });
12160
+ ImageBlockSchema = import_zod34.z.looseObject({
12161
+ type: import_zod34.z.literal("image"),
12162
+ source: import_zod34.z.union([Base64ImageSourceSchema, UrlImageSourceSchema])
11997
12163
  });
11998
- ToolUseBlockSchema = import_zod33.z.looseObject({
11999
- type: import_zod33.z.literal("tool_use"),
12000
- id: import_zod33.z.string().min(1),
12001
- name: import_zod33.z.string().min(1),
12002
- input: import_zod33.z.unknown()
12164
+ ToolUseBlockSchema = import_zod34.z.looseObject({
12165
+ type: import_zod34.z.literal("tool_use"),
12166
+ id: import_zod34.z.string().min(1),
12167
+ name: import_zod34.z.string().min(1),
12168
+ input: import_zod34.z.unknown()
12003
12169
  });
12004
- ToolResultContentBlockSchema = import_zod33.z.union([TextBlockSchema, import_zod33.z.looseObject({ type: import_zod33.z.string() })]);
12005
- ToolResultBlockSchema = import_zod33.z.looseObject({
12006
- type: import_zod33.z.literal("tool_result"),
12007
- tool_use_id: import_zod33.z.string().min(1),
12008
- content: import_zod33.z.union([import_zod33.z.string(), import_zod33.z.array(ToolResultContentBlockSchema)]).optional()
12170
+ ToolResultContentBlockSchema = import_zod34.z.union([TextBlockSchema, import_zod34.z.looseObject({ type: import_zod34.z.string() })]);
12171
+ ToolResultBlockSchema = import_zod34.z.looseObject({
12172
+ type: import_zod34.z.literal("tool_result"),
12173
+ tool_use_id: import_zod34.z.string().min(1),
12174
+ content: import_zod34.z.union([import_zod34.z.string(), import_zod34.z.array(ToolResultContentBlockSchema)]).optional()
12009
12175
  });
12010
- OtherBlockSchema = import_zod33.z.looseObject({ type: import_zod33.z.string() });
12011
- ContentBlockSchema = import_zod33.z.union([TextBlockSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultBlockSchema, OtherBlockSchema]);
12012
- MessageSchema = import_zod33.z.looseObject({
12013
- role: import_zod33.z.enum(["user", "assistant", "system"]),
12014
- content: import_zod33.z.union([import_zod33.z.string(), import_zod33.z.array(ContentBlockSchema)])
12176
+ OtherBlockSchema = import_zod34.z.looseObject({ type: import_zod34.z.string() });
12177
+ ContentBlockSchema = import_zod34.z.union([TextBlockSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultBlockSchema, OtherBlockSchema]);
12178
+ MessageSchema = import_zod34.z.looseObject({
12179
+ role: import_zod34.z.enum(["user", "assistant", "system"]),
12180
+ content: import_zod34.z.union([import_zod34.z.string(), import_zod34.z.array(ContentBlockSchema)])
12015
12181
  });
12016
- ToolSchema = import_zod33.z.looseObject({
12017
- name: import_zod33.z.string().min(1),
12018
- description: import_zod33.z.string().optional(),
12019
- input_schema: import_zod33.z.record(import_zod33.z.string(), import_zod33.z.unknown()).optional(),
12020
- allowed_domains: import_zod33.z.array(import_zod33.z.string()).optional(),
12021
- blocked_domains: import_zod33.z.array(import_zod33.z.string()).optional()
12182
+ ToolSchema = import_zod34.z.looseObject({
12183
+ name: import_zod34.z.string().min(1),
12184
+ description: import_zod34.z.string().optional(),
12185
+ input_schema: import_zod34.z.record(import_zod34.z.string(), import_zod34.z.unknown()).optional(),
12186
+ allowed_domains: import_zod34.z.array(import_zod34.z.string()).optional(),
12187
+ blocked_domains: import_zod34.z.array(import_zod34.z.string()).optional()
12022
12188
  });
12023
- ToolChoiceSchema = import_zod33.z.union([
12024
- import_zod33.z.looseObject({ type: import_zod33.z.enum(["auto", "none", "any"]) }),
12025
- import_zod33.z.looseObject({ type: import_zod33.z.literal("tool"), name: import_zod33.z.string().min(1) })
12189
+ ToolChoiceSchema = import_zod34.z.union([
12190
+ import_zod34.z.looseObject({ type: import_zod34.z.enum(["auto", "none", "any"]) }),
12191
+ import_zod34.z.looseObject({ type: import_zod34.z.literal("tool"), name: import_zod34.z.string().min(1) })
12026
12192
  ]);
12027
- SystemSchema = import_zod33.z.union([import_zod33.z.string(), import_zod33.z.array(import_zod33.z.union([TextBlockSchema, OtherBlockSchema]))]);
12028
- MessagesRequestSchema = import_zod33.z.looseObject({
12029
- model: import_zod33.z.string().optional(),
12193
+ SystemSchema = import_zod34.z.union([import_zod34.z.string(), import_zod34.z.array(import_zod34.z.union([TextBlockSchema, OtherBlockSchema]))]);
12194
+ MessagesRequestSchema = import_zod34.z.looseObject({
12195
+ model: import_zod34.z.string().optional(),
12030
12196
  system: SystemSchema.optional(),
12031
- messages: import_zod33.z.array(MessageSchema),
12032
- tools: import_zod33.z.array(ToolSchema).optional(),
12197
+ messages: import_zod34.z.array(MessageSchema),
12198
+ tools: import_zod34.z.array(ToolSchema).optional(),
12033
12199
  tool_choice: ToolChoiceSchema.optional(),
12034
- stream: import_zod33.z.boolean().optional(),
12200
+ stream: import_zod34.z.boolean().optional(),
12035
12201
  /** `user_id` is stable for one Claude Code session and differs between sessions, which is what makes it the right key for both the backend's prompt cache and its session header. */
12036
- metadata: import_zod33.z.looseObject({ user_id: import_zod33.z.string().optional() }).optional(),
12202
+ metadata: import_zod34.z.looseObject({ user_id: import_zod34.z.string().optional() }).optional(),
12037
12203
  /** Claude Code's effort setting. Any string is accepted; the translator honours only the levels the backend understands. */
12038
- output_config: import_zod33.z.looseObject({ effort: import_zod33.z.string().optional(), format: import_zod33.z.object({ type: import_zod33.z.literal("json_schema"), schema: import_zod33.z.record(import_zod33.z.string(), import_zod33.z.unknown()) }).optional() }).optional()
12204
+ output_config: import_zod34.z.looseObject({ effort: import_zod34.z.string().optional(), format: import_zod34.z.object({ type: import_zod34.z.literal("json_schema"), schema: import_zod34.z.record(import_zod34.z.string(), import_zod34.z.unknown()) }).optional() }).optional()
12039
12205
  });
12040
- CountTokensRequestSchema = import_zod33.z.looseObject({
12041
- system: import_zod33.z.unknown().optional(),
12042
- messages: import_zod33.z.unknown().optional(),
12043
- tools: import_zod33.z.unknown().optional()
12206
+ CountTokensRequestSchema = import_zod34.z.looseObject({
12207
+ system: import_zod34.z.unknown().optional(),
12208
+ messages: import_zod34.z.unknown().optional(),
12209
+ tools: import_zod34.z.unknown().optional()
12044
12210
  });
12045
12211
  }
12046
12212
  });
@@ -12453,10 +12619,9 @@ function checkedProxyBypass(entries, source) {
12453
12619
  }
12454
12620
  return kept;
12455
12621
  }
12456
- function withBypassHosts(existing, hosts) {
12457
- const listed = (existing ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
12458
- const have = new Set(listed.map((entry) => entry.toLowerCase()));
12459
- const added = hosts.filter((host) => {
12622
+ function appendedBypassHosts(existing, hosts) {
12623
+ const have = new Set((existing ?? "").split(",").map((entry) => entry.trim().toLowerCase()).filter((entry) => entry !== ""));
12624
+ return hosts.filter((host) => {
12460
12625
  const key = host.toLowerCase();
12461
12626
  if (have.has(key)) {
12462
12627
  return false;
@@ -12464,7 +12629,10 @@ function withBypassHosts(existing, hosts) {
12464
12629
  have.add(key);
12465
12630
  return true;
12466
12631
  });
12467
- return [...listed, ...added].join(",");
12632
+ }
12633
+ function withBypassHosts(existing, hosts) {
12634
+ const listed = (existing ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
12635
+ return [...listed, ...appendedBypassHosts(existing, hosts)].join(",");
12468
12636
  }
12469
12637
  var init_proxyBypass2 = __esm({
12470
12638
  "src/launcher/proxyBypass.ts"() {
@@ -12647,7 +12815,7 @@ function ensureFrontDoor(params) {
12647
12815
  if (supervisorPid !== void 0 && !distrusted.has(supervisorPid) && ports.isRunning(supervisorPid)) {
12648
12816
  if (state?.port !== void 0 && state.connectPort !== void 0) {
12649
12817
  if (supervisorPid === params.launcherPid && params.replace === void 0 && ports.isFrontDoorSupervisor(supervisorPid)) {
12650
- const token = (0, import_node_crypto14.randomUUID)();
12818
+ const token = (0, import_node_crypto15.randomUUID)();
12651
12819
  writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
12652
12820
  return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
12653
12821
  }
@@ -12668,7 +12836,7 @@ function ensureFrontDoor(params) {
12668
12836
  continue;
12669
12837
  }
12670
12838
  if (verdict.ok) {
12671
- const token = (0, import_node_crypto14.randomUUID)();
12839
+ const token = (0, import_node_crypto15.randomUUID)();
12672
12840
  writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
12673
12841
  return { port: state.port, connectPort: state.connectPort, token, supervisorPid };
12674
12842
  }
@@ -12721,11 +12889,11 @@ function ensureFrontDoor(params) {
12721
12889
  ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
12722
12890
  }
12723
12891
  }
12724
- var import_node_crypto14, FRONTDOOR_START_TIMEOUT_MS, FRONTDOOR_LAUNCHER_POLL_MS, FRONTDOOR_PROBE_ATTEMPTS, FRONTDOOR_EXIT_GRACE_MS, FrontDoorStartError;
12892
+ var import_node_crypto15, FRONTDOOR_START_TIMEOUT_MS, FRONTDOOR_LAUNCHER_POLL_MS, FRONTDOOR_PROBE_ATTEMPTS, FRONTDOOR_EXIT_GRACE_MS, FrontDoorStartError;
12725
12893
  var init_ensure2 = __esm({
12726
12894
  "src/frontdoor/ensure.ts"() {
12727
12895
  "use strict";
12728
- import_node_crypto14 = require("node:crypto");
12896
+ import_node_crypto15 = require("node:crypto");
12729
12897
  init_cliError();
12730
12898
  init_state2();
12731
12899
  init_replacement();
@@ -13035,43 +13203,6 @@ var init_cliOverride = __esm({
13035
13203
  }
13036
13204
  });
13037
13205
 
13038
- // src/headroom/headers.ts
13039
- function mergeAnthropicCustomHeaders(existing, additions) {
13040
- const merged = /* @__PURE__ */ new Map();
13041
- for (const block of existing) {
13042
- if (block === void 0) {
13043
- continue;
13044
- }
13045
- for (const line of block.split("\n")) {
13046
- const entry = parseCustomHeaderLine(line);
13047
- if (entry === void 0) {
13048
- continue;
13049
- }
13050
- merged.set(entry.name, entry.value);
13051
- }
13052
- }
13053
- for (const entry of additions) {
13054
- merged.set(entry.name, entry.value);
13055
- }
13056
- return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
13057
- }
13058
- function parseCustomHeaderLine(line) {
13059
- const trimmed = line.trim();
13060
- if (trimmed === "") {
13061
- return void 0;
13062
- }
13063
- const colon = trimmed.indexOf(":");
13064
- if (colon <= 0) {
13065
- return void 0;
13066
- }
13067
- return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
13068
- }
13069
- var init_headers = __esm({
13070
- "src/headroom/headers.ts"() {
13071
- "use strict";
13072
- }
13073
- });
13074
-
13075
13206
  // src/statusline/settings.ts
13076
13207
  function checkedStatusline(settings, source) {
13077
13208
  try {
@@ -13154,7 +13285,10 @@ function buildArgv(params) {
13154
13285
  return [...params.toolFlags, ...params.extraFlags, ...params.passthrough];
13155
13286
  }
13156
13287
  function buildEnv(params) {
13157
- const env = { ...params.baseEnv };
13288
+ const injections = recordInjections(params.baseEnv);
13289
+ const { env } = injections;
13290
+ const inject = injections.set;
13291
+ const injectedHeaderNames = [];
13158
13292
  const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
13159
13293
  let providerCustomHeaders;
13160
13294
  if (!params.configDirEscapeHatch && params.identityId !== void 0) {
@@ -13163,53 +13297,75 @@ function buildEnv(params) {
13163
13297
  if (params.provider !== void 0) {
13164
13298
  const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
13165
13299
  providerCustomHeaders = providerEnv.ANTHROPIC_CUSTOM_HEADERS;
13166
- env.ANTHROPIC_BASE_URL = void 0;
13167
- env.AGENT_SHIM_PROVIDER = params.provider.definition.displayName;
13300
+ injections.unset("ANTHROPIC_BASE_URL");
13301
+ inject("AGENT_SHIM_PROVIDER", params.provider.definition.displayName);
13168
13302
  for (const [key, value] of Object.entries(providerEnv)) {
13169
- env[key] = value;
13303
+ if (key === CUSTOM_HEADERS_ENV) {
13304
+ env[key] = value;
13305
+ injectedHeaderNames.push(...parseAnthropicCustomHeaders(value).map(({ name }) => name));
13306
+ } else if (key === "NO_PROXY" || key === "no_proxy") {
13307
+ env[key] = value;
13308
+ injections.recordBypassHosts(key, value.split(","));
13309
+ } else {
13310
+ inject(key, value);
13311
+ }
13170
13312
  }
13171
13313
  }
13172
13314
  for (const tier of CLAUDE_TIERS) {
13173
13315
  const ref = params.tierModels?.[tier];
13174
13316
  if (ref !== void 0) {
13175
- env[`ANTHROPIC_DEFAULT_${tier.toUpperCase()}_MODEL`] = ref;
13317
+ inject(`ANTHROPIC_DEFAULT_${tier.toUpperCase()}_MODEL`, ref);
13176
13318
  }
13177
13319
  }
13178
13320
  if (params.provider !== void 0) {
13179
- env.ANTHROPIC_AUTH_TOKEN = params.remoteControl ? void 0 : PROVIDER_SESSION_PLACEHOLDER;
13180
- env.ANTHROPIC_API_KEY = void 0;
13181
- env.CLAUDE_CODE_OAUTH_TOKEN = void 0;
13321
+ if (params.remoteControl) {
13322
+ injections.unset("ANTHROPIC_AUTH_TOKEN");
13323
+ } else {
13324
+ inject("ANTHROPIC_AUTH_TOKEN", PROVIDER_SESSION_PLACEHOLDER);
13325
+ }
13326
+ injections.unset("ANTHROPIC_API_KEY");
13327
+ injections.unset("CLAUDE_CODE_OAUTH_TOKEN");
13182
13328
  } else if (params.identityCredential !== void 0) {
13183
13329
  for (const [variable, value] of Object.entries(credentialVariables(params.identityCredential.target, params.identityCredential.token))) {
13184
- env[variable] = value;
13330
+ if (value === void 0) {
13331
+ injections.unset(variable);
13332
+ } else {
13333
+ inject(variable, value);
13334
+ }
13185
13335
  }
13186
13336
  }
13187
13337
  if (params.frontdoor !== void 0) {
13338
+ const launcherHeaders = [
13339
+ ...params.identityId === void 0 ? [] : [{ name: IDENTITY_HEADER, value: params.identityId }],
13340
+ { name: SESSION_HEADER, value: params.sessionId },
13341
+ { name: AUTH_HEADER, value: params.frontdoor.sessionToken },
13342
+ ...params.provider === void 0 ? [] : [{ name: PROVIDER_HEADER, value: params.provider.name }],
13343
+ ...params.headroom === void 0 ? [] : [
13344
+ { name: HEADROOM_FLAG_HEADER, value: "1" },
13345
+ { name: PROJECT_ID_HEADER, value: params.headroom.projectId }
13346
+ ]
13347
+ ];
13348
+ injectedHeaderNames.push(...launcherHeaders.map(({ name }) => name));
13188
13349
  env.ANTHROPIC_CUSTOM_HEADERS = mergeAnthropicCustomHeaders(
13189
13350
  [
13190
13351
  ...parentCustomHeaders === void 0 ? [] : [parentCustomHeaders],
13191
13352
  ...providerCustomHeaders === void 0 ? [] : [providerCustomHeaders]
13192
13353
  ],
13193
- [
13194
- ...params.identityId === void 0 ? [] : [{ name: IDENTITY_HEADER, value: params.identityId }],
13195
- { name: SESSION_HEADER, value: params.sessionId },
13196
- { name: AUTH_HEADER, value: params.frontdoor.sessionToken },
13197
- ...params.provider === void 0 ? [] : [{ name: PROVIDER_HEADER, value: params.provider.name }],
13198
- ...params.headroom === void 0 ? [] : [
13199
- { name: HEADROOM_FLAG_HEADER, value: "1" },
13200
- { name: PROJECT_ID_HEADER, value: params.headroom.projectId }
13201
- ]
13202
- ]
13354
+ launcherHeaders
13203
13355
  );
13204
- env.NODE_EXTRA_CA_CERTS = params.frontdoor.trustBundlePath;
13205
- env.HTTPS_PROXY = connectProxyUrl(params.frontdoor.connectPort, params.frontdoor.sessionToken);
13356
+ inject("NODE_EXTRA_CA_CERTS", params.frontdoor.trustBundlePath);
13357
+ inject("HTTPS_PROXY", connectProxyUrl(params.frontdoor.connectPort, params.frontdoor.sessionToken));
13206
13358
  const bypassed = [...LOOPBACK_HOSTS, ...params.proxyBypass ?? []];
13207
- env.NO_PROXY = withBypassHosts(env.NO_PROXY, bypassed);
13208
- env.no_proxy = withBypassHosts(env.no_proxy, bypassed);
13359
+ for (const list of ["NO_PROXY", "no_proxy"]) {
13360
+ injections.recordBypassHosts(list, appendedBypassHosts(env[list], bypassed));
13361
+ env[list] = withBypassHosts(env[list], bypassed);
13362
+ }
13209
13363
  }
13210
13364
  if (params.statusline !== void 0) {
13211
- env[STATUSLINE_ENV] = JSON.stringify(params.statusline);
13365
+ inject(STATUSLINE_ENV, JSON.stringify(params.statusline));
13212
13366
  }
13367
+ injections.recordHeaders(injectedHeaderNames);
13368
+ injections.finish();
13213
13369
  return env;
13214
13370
  }
13215
13371
  var import_node_path48, LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
@@ -13223,6 +13379,7 @@ var init_flags = __esm({
13223
13379
  init_schema();
13224
13380
  init_credential();
13225
13381
  init_headers();
13382
+ init_injected();
13226
13383
  init_capability();
13227
13384
  init_route();
13228
13385
  init_statusline();
@@ -13981,19 +14138,18 @@ function pickFromPool(decided, params, parsedArgv, readOnly) {
13981
14138
  ...resolution.lastRanAs === void 0 ? {} : { lastRanAs: { identity: resolution.lastRanAs.identity, agoMs: farmRuntime.now() - Date.parse(resolution.lastRanAs.at) } }
13982
14139
  };
13983
14140
  }
14141
+ function warnOfSupersededConfigDir(warn, fs17, superseded, identity, identityDir) {
14142
+ if (superseded === void 0 || superseded === identityDir || fs17.sameDirectory(superseded, identityDir)) {
14143
+ return;
14144
+ }
14145
+ warn(`agent-shim: the identity named on the command line outranks the inherited CLAUDE_CONFIG_DIR ${superseded}; running as ${identity} in ${identityDir}`);
14146
+ }
13984
14147
  function decideLaunch(params, readOnly, onRecorded) {
13985
14148
  const { paths, fs: fs17, proc, log } = params;
13986
- const { env, argv } = proc;
14149
+ const { argv } = proc;
13987
14150
  const parsedArgv = parseLauncherArgv(argv);
13988
- const cliOverride = buildCliOverride({
13989
- env,
13990
- categoryFlags: parsedArgv.categoryFlags,
13991
- shareFlags: parsedArgv.shareFlags,
13992
- hideFlags: parsedArgv.hideFlags
13993
- });
13994
- const configDirEscapeHatchApplies = env.CLAUDE_CONFIG_DIR !== void 0 && env.CLAUDE_CONFIG_DIR !== "";
13995
14151
  const decidedIdentity = decideIdentity({
13996
- env,
14152
+ env: proc.env,
13997
14153
  argv0Identity: params.pickedIdentity ?? parsedArgv.identity,
13998
14154
  directoryPinnedIdentity: params.directoryPinnedIdentity,
13999
14155
  readActiveIdentityFile: () => {
@@ -14005,6 +14161,14 @@ function decideLaunch(params, readOnly, onRecorded) {
14005
14161
  return trimmed === "" ? void 0 : trimmed;
14006
14162
  }
14007
14163
  });
14164
+ const configDirEscapeHatchApplies = decidedIdentity.configDirEscapeHatch;
14165
+ const env = launchEnvironment(proc.env, configDirEscapeHatchApplies);
14166
+ const cliOverride = buildCliOverride({
14167
+ env,
14168
+ categoryFlags: parsedArgv.categoryFlags,
14169
+ shareFlags: parsedArgv.shareFlags,
14170
+ hideFlags: parsedArgv.hideFlags
14171
+ });
14008
14172
  const { identityDecision, poolPick, poolRanking, lastRanAs } = pickFromPool(decidedIdentity, params, parsedArgv, readOnly);
14009
14173
  const lockFarm = !readOnly && !configDirEscapeHatchApplies && identityDecision.name !== void 0 ? params.farm : void 0;
14010
14174
  const lockPorts = params.namesLock ?? (lockFarm === void 0 ? realIdentityNamesLockPorts : { fs: lockFarm.fs, nowMs: lockFarm.now, ...lockFarm.lock });
@@ -14012,6 +14176,9 @@ function decideLaunch(params, readOnly, onRecorded) {
14012
14176
  try {
14013
14177
  const farmIdentity = configDirEscapeHatchApplies || identityDecision.name === void 0 ? void 0 : resolveIdentityId(paths.identitiesDir, identityDecision.name, fs17);
14014
14178
  const farm = farmIdentity === void 0 ? void 0 : params.farm;
14179
+ if (!readOnly && params.supervised?.member === void 0 && farmIdentity !== void 0 && identityDecision.name !== void 0) {
14180
+ warnOfSupersededConfigDir(log.warn, fs17, identityDecision.supersededConfigDir, identityDecision.name, import_node_path50.default.join(paths.identitiesDir, farmIdentity));
14181
+ }
14015
14182
  if (!readOnly && farm !== void 0 && farmIdentity !== void 0) {
14016
14183
  try {
14017
14184
  recoverFarmWarning(
@@ -14178,7 +14345,7 @@ function decideLaunch(params, readOnly, onRecorded) {
14178
14345
  const doorPid = supervisorPid ?? (recordedPid !== void 0 && proc.isProcessAlive(recordedPid) ? recordedPid : void 0);
14179
14346
  const doorRecord = doorPid === void 0 ? void 0 : readFrontDoorCodexRecord(params.fs, paths.frontdoorDir, doorPid);
14180
14347
  const doorHome = doorRecord?.codexHome;
14181
- const catalogueEnv = doorHome === void 0 ? proc.env : { ...proc.env, CODEX_HOME: doorHome };
14348
+ const catalogueEnv = doorHome === void 0 ? env : { ...env, CODEX_HOME: doorHome };
14182
14349
  const listedProviders = listProviderNames(fs17.readdir, paths.providersDir).flatMap((name) => {
14183
14350
  try {
14184
14351
  const definition = loadProvider(paths.providersDir, name, fs17);
@@ -14240,6 +14407,7 @@ function decideLaunch(params, readOnly, onRecorded) {
14240
14407
  billing,
14241
14408
  notes,
14242
14409
  configDirEscapeHatch: configDirEscapeHatchApplies,
14410
+ env,
14243
14411
  farmIdentity,
14244
14412
  farmContext,
14245
14413
  configProfileDecision,
@@ -14275,12 +14443,12 @@ function prepareLaunch(params) {
14275
14443
  }
14276
14444
  function prepareRegisteredLaunch(params, onRecorded) {
14277
14445
  const { paths, proc, log } = params;
14278
- const { env } = proc;
14279
14446
  let unregisterLaunch;
14280
14447
  const decided = decideLaunch(params, false, (remove) => {
14281
14448
  unregisterLaunch = remove;
14282
14449
  onRecorded(remove);
14283
14450
  });
14451
+ const { env } = decided;
14284
14452
  const { identityDecision, configProfileDecision, resolvedProvider, identityCredential, poolPick, poolRanking, lastRanAs, billing, notes, flags: resolvedFlags, configDirEscapeHatch: configDirEscapeHatchApplies, decision } = decided;
14285
14453
  const rows = [
14286
14454
  ...decisionRows({
@@ -14355,7 +14523,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
14355
14523
  log.error("agent-shim: this launch routes through the front-door daemon, but this launcher has no front-door port wired; refusing to launch without it.");
14356
14524
  proc.exit(1);
14357
14525
  }
14358
- const sessionId = params.supervised?.sessionId ?? (0, import_node_crypto15.randomUUID)();
14526
+ const sessionId = params.supervised?.sessionId ?? (0, import_node_crypto16.randomUUID)();
14359
14527
  const resolvedModels = decided.models ?? (decided.globalModels === void 0 ? void 0 : {});
14360
14528
  const sessionModels = (0, import_node_util2.isDeepStrictEqual)(resolvedModels, decided.globalModels) ? void 0 : resolvedModels;
14361
14529
  const session = { sessionId, ...sessionModels === void 0 ? {} : { models: sessionModels } };
@@ -14416,7 +14584,7 @@ function prepareRegisteredLaunch(params, onRecorded) {
14416
14584
  }
14417
14585
  function resolveLaunch(params) {
14418
14586
  const decided = decideLaunch(params, true);
14419
- const { env } = params.proc;
14587
+ const { env } = decided;
14420
14588
  const frontDoor = decided.provider !== void 0 || decided.flags.headroom || decided.flags.trackUsage;
14421
14589
  const built = buildEnv({
14422
14590
  baseEnv: env,
@@ -14432,7 +14600,7 @@ function resolveLaunch(params) {
14432
14600
  ...decided.flags.statusline === void 0 ? {} : { statusline: decided.flags.statusline }
14433
14601
  });
14434
14602
  const credentialNames = decided.identityCredentialBlock === void 0 ? [] : Object.keys(credentialVariables(decided.identityCredentialBlock.target ?? "bearer", ""));
14435
- const environment = [.../* @__PURE__ */ new Set([...Object.keys(built).filter((name) => built[name] !== env[name]), ...credentialNames])].sort();
14603
+ const environment = [.../* @__PURE__ */ new Set([...Object.keys(built).filter((name) => name !== INJECTED_ENV && built[name] !== env[name]), ...credentialNames])].sort();
14436
14604
  const credential = decided.provider !== void 0 ? isRouterProvider(decided.provider.definition) ? void 0 : { subject: "provider", name: decided.provider.name, summary: summariseCredential(decided.provider.definition.credential) } : decided.identityCredentialBlock !== void 0 && decided.farmIdentity !== void 0 && decided.identityDecision.name !== void 0 ? { subject: "identity", name: decided.identityDecision.name, summary: summariseCredential(decided.identityCredentialBlock) } : void 0;
14437
14605
  return {
14438
14606
  decision: decided.decision,
@@ -14463,11 +14631,11 @@ function runLaunchPlan(plan, spawn3) {
14463
14631
  function runLauncher(params) {
14464
14632
  params.proc.exit(runLaunchPlan(prepareLaunch(params), params.spawn));
14465
14633
  }
14466
- var import_node_crypto15, import_node_os8, import_node_util2, import_node_path50;
14634
+ var import_node_crypto16, import_node_os8, import_node_util2, import_node_path50;
14467
14635
  var init_launcher = __esm({
14468
14636
  "src/launcher.ts"() {
14469
14637
  "use strict";
14470
- import_node_crypto15 = require("node:crypto");
14638
+ import_node_crypto16 = require("node:crypto");
14471
14639
  import_node_os8 = __toESM(require("node:os"), 1);
14472
14640
  init_catalogueCredential();
14473
14641
  import_node_util2 = require("node:util");
@@ -14513,6 +14681,7 @@ var init_launcher = __esm({
14513
14681
  init_launchHook();
14514
14682
  init_targets();
14515
14683
  init_names();
14684
+ init_injected();
14516
14685
  }
14517
14686
  });
14518
14687
 
@@ -14598,18 +14767,18 @@ function resolveTrustBundle(params) {
14598
14767
  }
14599
14768
  const combined = `${inheritedPem.trimEnd()}
14600
14769
  ${caPem}`;
14601
- const bundle = import_node_path52.default.join(bundlesDir, `${(0, import_node_crypto16.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
14770
+ const bundle = import_node_path52.default.join(bundlesDir, `${(0, import_node_crypto17.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
14602
14771
  if (!fs17.exists(bundle)) {
14603
14772
  fs17.mkdirp(bundlesDir);
14604
14773
  fs17.writeFileAtomic(bundle, combined);
14605
14774
  }
14606
14775
  return { path: bundle };
14607
14776
  }
14608
- var import_node_crypto16, import_node_path52, BUNDLE_NAME_HEX_DIGITS;
14777
+ var import_node_crypto17, import_node_path52, BUNDLE_NAME_HEX_DIGITS;
14609
14778
  var init_trust = __esm({
14610
14779
  "src/frontdoor/trust.ts"() {
14611
14780
  "use strict";
14612
- import_node_crypto16 = require("node:crypto");
14781
+ import_node_crypto17 = require("node:crypto");
14613
14782
  import_node_path52 = __toESM(require("node:path"), 1);
14614
14783
  BUNDLE_NAME_HEX_DIGITS = 16;
14615
14784
  }
@@ -14769,7 +14938,7 @@ function buildFarmRuntime(paths, cwd, run = realRunPort) {
14769
14938
  ...cliOverride === void 0 ? {} : { cliOverride }
14770
14939
  }).input,
14771
14940
  now: () => Date.now(),
14772
- uniqueSuffix: `${String(process.pid)}.${(0, import_node_crypto17.randomUUID)()}`,
14941
+ uniqueSuffix: `${String(process.pid)}.${(0, import_node_crypto18.randomUUID)()}`,
14773
14942
  // Zombie-aware on purpose: a previous launcher that crashed out of a resync without releasing the lock may sit unreaped, still answering signal 0 as alive, and must read as a dead holder so this launch takes the lock over instead of timing out.
14774
14943
  lock: { pid: process.pid, isRunning: realIsProcessRunning, sleep: realSleepSync }
14775
14944
  },
@@ -14857,13 +15026,13 @@ function resolveClaudeLaunch(options, run = realRunPort) {
14857
15026
  };
14858
15027
  return { resolution: resolveLaunch(realPrepareLaunchParams(paths, { proc, log, spawnDaemon, run, farm: buildFarmRuntime(paths, options.cwd, run) })), warnings };
14859
15028
  }
14860
- var import_node_os10, import_node_path53, import_node_crypto17, LaunchRefusedError;
15029
+ var import_node_os10, import_node_path53, import_node_crypto18, LaunchRefusedError;
14861
15030
  var init_launchWiring = __esm({
14862
15031
  "src/launchWiring.ts"() {
14863
15032
  "use strict";
14864
15033
  import_node_os10 = __toESM(require("node:os"), 1);
14865
15034
  import_node_path53 = __toESM(require("node:path"), 1);
14866
- import_node_crypto17 = require("node:crypto");
15035
+ import_node_crypto18 = require("node:crypto");
14867
15036
  init_cliError();
14868
15037
  init_claudeShim();
14869
15038
  init_classify();
@@ -15036,7 +15205,7 @@ function identityLaunchArgv(identity, flags) {
15036
15205
  }
15037
15206
  async function withIdentityClaude(params, identity, flags, use) {
15038
15207
  const refusals = [];
15039
- const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => name !== CONFIG_DIR_VARIABLE));
15208
+ const env = { ...process.env };
15040
15209
  const argv = [...identityLaunchArgv(identity, flags)];
15041
15210
  const run = await recordRuns((replay) => resolveClaudeLaunch({ argv, cwd: params.cwd, env: definedEnvironment(env), paths: params.paths }, replay), params.runAsync ?? realRunAsync);
15042
15211
  const farm = buildFarmRuntime(params.paths, params.cwd, run);
@@ -15074,7 +15243,7 @@ async function withIdentityClaude(params, identity, flags, use) {
15074
15243
  plan.release();
15075
15244
  }
15076
15245
  }
15077
- var CONFIG_DIR_VARIABLE, IDENTITY_ONLY_FLAG;
15246
+ var IDENTITY_ONLY_FLAG;
15078
15247
  var init_identityClaude = __esm({
15079
15248
  "src/usage/identityClaude.ts"() {
15080
15249
  "use strict";
@@ -15083,17 +15252,16 @@ var init_identityClaude = __esm({
15083
15252
  init_realPorts();
15084
15253
  init_replayRun();
15085
15254
  init_identityNamesLock();
15086
- CONFIG_DIR_VARIABLE = "CLAUDE_CONFIG_DIR";
15087
15255
  IDENTITY_ONLY_FLAG = "--no-provider";
15088
15256
  }
15089
15257
  });
15090
15258
 
15091
15259
  // src/usage/providerQuota.ts
15092
- var import_zod41, MS_PER_SECOND9, SECONDS_PER_HOUR3, HOURS_PER_DAY6, DAYS_PER_MONTH, ZAI_HOST, ZAI_QUOTA_URL, ZAI_UNIT_HOURS, ZAI_UNIT_MONTHS, ZAI_UNIT_MS, ZaiLimitSchema, ZaiResponseSchema, OPENROUTER_HOST, OPENROUTER_KEY_URL, OPENROUTER_CREDITS_URL, MS_PER_DAY2, OpenRouterKeySchema, OpenRouterCreditsSchema, ANTIGRAVITY_HOST, ANTIGRAVITY_QUOTA_URL, ANTIGRAVITY_USER_URL, FIVE_HOURS2, DAYS_PER_WEEK2, FIVE_HOURS_MS, WEEK_MS, AntigravityBucketSchema, AntigravitySummarySchema, GoogleTokenInfoSchema, AntigravityUserSchema;
15260
+ var import_zod43, MS_PER_SECOND9, SECONDS_PER_HOUR3, HOURS_PER_DAY6, DAYS_PER_MONTH, ZAI_HOST, ZAI_QUOTA_URL, ZAI_UNIT_HOURS, ZAI_UNIT_MONTHS, ZAI_UNIT_MS, ZaiLimitSchema, ZaiResponseSchema, OPENROUTER_HOST, OPENROUTER_KEY_URL, OPENROUTER_CREDITS_URL, MS_PER_DAY2, OpenRouterKeySchema, OpenRouterCreditsSchema, ANTIGRAVITY_HOST, ANTIGRAVITY_QUOTA_URL, ANTIGRAVITY_USER_URL, FIVE_HOURS2, DAYS_PER_WEEK2, FIVE_HOURS_MS, WEEK_MS, AntigravityBucketSchema, AntigravitySummarySchema, GoogleTokenInfoSchema, AntigravityUserSchema;
15093
15261
  var init_providerQuota = __esm({
15094
15262
  "src/usage/providerQuota.ts"() {
15095
15263
  "use strict";
15096
- import_zod41 = require("zod");
15264
+ import_zod43 = require("zod");
15097
15265
  init_cloudUpstream();
15098
15266
  init_schema2();
15099
15267
  MS_PER_SECOND9 = 1e3;
@@ -15108,35 +15276,35 @@ var init_providerQuota = __esm({
15108
15276
  [ZAI_UNIT_HOURS, SECONDS_PER_HOUR3 * MS_PER_SECOND9],
15109
15277
  [ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY6 * SECONDS_PER_HOUR3 * MS_PER_SECOND9]
15110
15278
  ]);
15111
- ZaiLimitSchema = import_zod41.z.object({
15112
- type: import_zod41.z.string(),
15113
- unit: import_zod41.z.number().int(),
15114
- number: import_zod41.z.number().int().positive(),
15115
- percentage: import_zod41.z.number().nonnegative(),
15116
- nextResetTime: import_zod41.z.number().positive().optional(),
15117
- usage: import_zod41.z.number().nonnegative().optional(),
15118
- currentValue: import_zod41.z.number().nonnegative().optional(),
15119
- remaining: import_zod41.z.number().nonnegative().optional()
15279
+ ZaiLimitSchema = import_zod43.z.object({
15280
+ type: import_zod43.z.string(),
15281
+ unit: import_zod43.z.number().int(),
15282
+ number: import_zod43.z.number().int().positive(),
15283
+ percentage: import_zod43.z.number().nonnegative(),
15284
+ nextResetTime: import_zod43.z.number().positive().optional(),
15285
+ usage: import_zod43.z.number().nonnegative().optional(),
15286
+ currentValue: import_zod43.z.number().nonnegative().optional(),
15287
+ remaining: import_zod43.z.number().nonnegative().optional()
15120
15288
  });
15121
- ZaiResponseSchema = import_zod41.z.object({
15122
- success: import_zod41.z.boolean(),
15123
- msg: import_zod41.z.string().optional(),
15124
- data: import_zod41.z.object({ level: import_zod41.z.string().optional(), limits: import_zod41.z.array(ZaiLimitSchema) })
15289
+ ZaiResponseSchema = import_zod43.z.object({
15290
+ success: import_zod43.z.boolean(),
15291
+ msg: import_zod43.z.string().optional(),
15292
+ data: import_zod43.z.object({ level: import_zod43.z.string().optional(), limits: import_zod43.z.array(ZaiLimitSchema) })
15125
15293
  });
15126
15294
  OPENROUTER_HOST = "openrouter.ai";
15127
15295
  OPENROUTER_KEY_URL = `https://${OPENROUTER_HOST}/api/v1/key`;
15128
15296
  OPENROUTER_CREDITS_URL = `https://${OPENROUTER_HOST}/api/v1/credits`;
15129
15297
  MS_PER_DAY2 = HOURS_PER_DAY6 * SECONDS_PER_HOUR3 * MS_PER_SECOND9;
15130
- OpenRouterKeySchema = import_zod41.z.object({
15131
- data: import_zod41.z.object({
15132
- limit: import_zod41.z.number().nonnegative().nullable(),
15133
- limit_remaining: import_zod41.z.number().nullable(),
15134
- limit_reset: import_zod41.z.string().nullable(),
15135
- is_free_tier: import_zod41.z.boolean().optional(),
15136
- free_model_daily_requests: import_zod41.z.object({ used: import_zod41.z.number().nonnegative(), limit: import_zod41.z.number().nonnegative(), remaining: import_zod41.z.number() }).optional()
15298
+ OpenRouterKeySchema = import_zod43.z.object({
15299
+ data: import_zod43.z.object({
15300
+ limit: import_zod43.z.number().nonnegative().nullable(),
15301
+ limit_remaining: import_zod43.z.number().nullable(),
15302
+ limit_reset: import_zod43.z.string().nullable(),
15303
+ is_free_tier: import_zod43.z.boolean().optional(),
15304
+ free_model_daily_requests: import_zod43.z.object({ used: import_zod43.z.number().nonnegative(), limit: import_zod43.z.number().nonnegative(), remaining: import_zod43.z.number() }).optional()
15137
15305
  })
15138
15306
  });
15139
- OpenRouterCreditsSchema = import_zod41.z.object({ data: import_zod41.z.object({ total_credits: import_zod41.z.number().nonnegative(), total_usage: import_zod41.z.number().nonnegative() }) });
15307
+ OpenRouterCreditsSchema = import_zod43.z.object({ data: import_zod43.z.object({ total_credits: import_zod43.z.number().nonnegative(), total_usage: import_zod43.z.number().nonnegative() }) });
15140
15308
  ANTIGRAVITY_HOST = "daily-cloudcode-pa.googleapis.com";
15141
15309
  ANTIGRAVITY_QUOTA_URL = `https://${ANTIGRAVITY_HOST}/v1internal:retrieveUserQuotaSummary`;
15142
15310
  ANTIGRAVITY_USER_URL = `https://${ANTIGRAVITY_HOST}/v1internal:loadCodeAssist`;
@@ -15144,21 +15312,21 @@ var init_providerQuota = __esm({
15144
15312
  DAYS_PER_WEEK2 = 7;
15145
15313
  FIVE_HOURS_MS = FIVE_HOURS2 * SECONDS_PER_HOUR3 * MS_PER_SECOND9;
15146
15314
  WEEK_MS = DAYS_PER_WEEK2 * HOURS_PER_DAY6 * SECONDS_PER_HOUR3 * MS_PER_SECOND9;
15147
- AntigravityBucketSchema = import_zod41.z.object({
15148
- bucketId: import_zod41.z.string(),
15149
- remainingFraction: import_zod41.z.number().optional(),
15150
- resetTime: import_zod41.z.string().optional()
15315
+ AntigravityBucketSchema = import_zod43.z.object({
15316
+ bucketId: import_zod43.z.string(),
15317
+ remainingFraction: import_zod43.z.number().optional(),
15318
+ resetTime: import_zod43.z.string().optional()
15151
15319
  });
15152
- AntigravitySummarySchema = import_zod41.z.object({ groups: import_zod41.z.array(import_zod41.z.object({ buckets: import_zod41.z.array(AntigravityBucketSchema) })) });
15153
- GoogleTokenInfoSchema = import_zod41.z.object({
15154
- email: import_zod41.z.string().optional(),
15155
- sub: import_zod41.z.string().optional()
15320
+ AntigravitySummarySchema = import_zod43.z.object({ groups: import_zod43.z.array(import_zod43.z.object({ buckets: import_zod43.z.array(AntigravityBucketSchema) })) });
15321
+ GoogleTokenInfoSchema = import_zod43.z.object({
15322
+ email: import_zod43.z.string().optional(),
15323
+ sub: import_zod43.z.string().optional()
15156
15324
  });
15157
- AntigravityUserSchema = import_zod41.z.object({
15325
+ AntigravityUserSchema = import_zod43.z.object({
15158
15326
  /** The code-assist tier context, which defaults to the free tier for every account. */
15159
- currentTier: import_zod41.z.object({ name: import_zod41.z.string().optional(), id: import_zod41.z.string().optional() }).optional(),
15327
+ currentTier: import_zod43.z.object({ name: import_zod43.z.string().optional(), id: import_zod43.z.string().optional() }).optional(),
15160
15328
  /** The account's paid subscription; absent when the account has none. */
15161
- paidTier: import_zod41.z.object({ name: import_zod41.z.string().optional(), id: import_zod41.z.string().optional() }).optional()
15329
+ paidTier: import_zod43.z.object({ name: import_zod43.z.string().optional(), id: import_zod43.z.string().optional() }).optional()
15162
15330
  });
15163
15331
  }
15164
15332
  });
@@ -15381,6 +15549,7 @@ __export(index_exports, {
15381
15549
  RC_IDLE_EXPIRY_MS: () => RC_IDLE_EXPIRY_MS,
15382
15550
  RC_ORPC_PATH_PREFIX: () => RC_ORPC_PATH_PREFIX,
15383
15551
  RC_PENDING_DEADLINE_MS: () => RC_PENDING_DEADLINE_MS,
15552
+ RC_PENDING_RETIRE_REASONS: () => RC_PENDING_RETIRE_REASONS,
15384
15553
  RC_PERMISSION_MODES: () => RC_PERMISSION_MODES,
15385
15554
  RC_READ_FILE_ENCODINGS: () => RC_READ_FILE_ENCODINGS,
15386
15555
  RC_REQUEST_PARSE_CAP_BYTES: () => RC_REQUEST_PARSE_CAP_BYTES,
@@ -15392,6 +15561,8 @@ __export(index_exports, {
15392
15561
  RC_SELF_HOST_SCOPE_LIST: () => RC_SELF_HOST_SCOPE_LIST,
15393
15562
  RC_SELF_HOST_WORKER_JWT_TTL_SECONDS: () => RC_SELF_HOST_WORKER_JWT_TTL_SECONDS,
15394
15563
  RC_SESSIONS_PATH_PREFIX: () => RC_SESSIONS_PATH_PREFIX,
15564
+ RC_SESSION_END_REASONS: () => RC_SESSION_END_REASONS,
15565
+ RC_SESSION_EVENT_LOG_CAPACITY: () => RC_SESSION_EVENT_LOG_CAPACITY,
15395
15566
  RC_STREAM_BACKOFF_MS: () => RC_STREAM_BACKOFF_MS,
15396
15567
  RC_WEB_FETCH_ALLOW_PRIVATE_ENV: () => RC_WEB_FETCH_ALLOW_PRIVATE_ENV,
15397
15568
  RC_WEB_FETCH_DEADLINE_MS: () => RC_WEB_FETCH_DEADLINE_MS,
@@ -15402,6 +15573,13 @@ __export(index_exports, {
15402
15573
  RcPermissionModeSchema: () => RcPermissionModeSchema,
15403
15574
  RcRateLimitInfoSchema: () => RcRateLimitInfoSchema,
15404
15575
  RcRateLimitWindowSchema: () => RcRateLimitWindowSchema,
15576
+ RcSessionEventCursorExpiredError: () => RcSessionEventCursorExpiredError,
15577
+ RcSessionEventSchema: () => RcSessionEventSchema,
15578
+ RcSessionEventsPageInputSchema: () => RcSessionEventsPageInputSchema,
15579
+ RcSessionEventsReadInputSchema: () => RcSessionEventsReadInputSchema,
15580
+ RcSessionEventsReadOutputSchema: () => RcSessionEventsReadOutputSchema,
15581
+ RcSessionEventsStreamInputSchema: () => RcSessionEventsStreamInputSchema,
15582
+ RcSessionTransitionSchema: () => RcSessionTransitionSchema,
15405
15583
  RcStreamEnvelopeSchema: () => RcStreamEnvelopeSchema,
15406
15584
  RcStreamEventSchema: () => RcStreamEventSchema,
15407
15585
  ResetRowSchema: () => ResetRowSchema,
@@ -15483,6 +15661,8 @@ __export(index_exports, {
15483
15661
  createRcEventFanout: () => createRcEventFanout,
15484
15662
  createRcLiveUsage: () => createRcLiveUsage,
15485
15663
  createRcSelfHostSurface: () => createRcSelfHostSurface,
15664
+ createRcSessionEventLog: () => createRcSessionEventLog,
15665
+ createRcSessionEventsApiRouter: () => createRcSessionEventsApiRouter,
15486
15666
  createRcSessionTracker: () => createRcSessionTracker,
15487
15667
  createRcStreamHub: () => createRcStreamHub,
15488
15668
  createSseParser: () => createSseParser,
@@ -15498,6 +15678,7 @@ __export(index_exports, {
15498
15678
  evaluateAmbientCredentialGuard: () => evaluateAmbientCredentialGuard,
15499
15679
  evaluateWhen: () => evaluateWhen,
15500
15680
  fetchThroughWebProxy: () => fetchThroughWebProxy,
15681
+ followRcSessionEvents: () => followRcSessionEvents,
15501
15682
  formatAmbientCredentialGuardMessage: () => formatAmbientCredentialGuardMessage,
15502
15683
  formatCheckReport: () => formatCheckReport,
15503
15684
  formatDoctorReport: () => formatDoctorReport,
@@ -16066,30 +16247,60 @@ function parseRcRequestBody(kind, body) {
16066
16247
  }
16067
16248
  function createRcSessionTracker(deps) {
16068
16249
  const entries = /* @__PURE__ */ new Map();
16069
- const expire = (id) => {
16250
+ const retirePending = (entry, requestId, reason) => {
16251
+ if (entry.pending.delete(requestId)) {
16252
+ entry.retired.set(requestId, deps.now());
16253
+ deps.onTransition?.({ kind: "pending-retired", session: entry.id, requestId, reason, at: deps.now() });
16254
+ }
16255
+ };
16256
+ const addPending = (entry, pending) => {
16257
+ if (entry.retired.has(pending.requestId)) {
16258
+ return;
16259
+ }
16260
+ const born = !entry.pending.has(pending.requestId);
16261
+ entry.pending.set(pending.requestId, pending);
16262
+ if (born) {
16263
+ deps.onTransition?.({ kind: "pending-born", session: entry.id, requestId: pending.requestId, type: pending.type, summary: pending.summary, at: pending.observedAt });
16264
+ }
16265
+ };
16266
+ const expire = (id, reason) => {
16267
+ const entry = entries.get(id);
16268
+ if (entry === void 0) {
16269
+ return;
16270
+ }
16271
+ for (const requestId of [...entry.pending.keys()]) {
16272
+ retirePending(entry, requestId, "session-ended");
16273
+ }
16070
16274
  entries.delete(id);
16275
+ deps.onTransition?.({ kind: "session-ended", session: id, reason, at: deps.now() });
16071
16276
  };
16072
16277
  const expirePendings = (entry, now) => {
16073
16278
  for (const [requestId, pending] of entry.pending) {
16074
16279
  if (now - pending.observedAt >= RC_PENDING_DEADLINE_MS) {
16075
- entry.pending.delete(requestId);
16280
+ retirePending(entry, requestId, "expired");
16281
+ }
16282
+ }
16283
+ for (const [requestId, retiredAt] of entry.retired) {
16284
+ if (now - retiredAt >= RC_PENDING_DEADLINE_MS) {
16285
+ entry.retired.delete(requestId);
16076
16286
  }
16077
16287
  }
16078
16288
  };
16079
16289
  const sweep = () => {
16080
16290
  for (const [id, entry] of entries) {
16081
16291
  if (deps.now() - entry.lastSeenAt >= deps.idleMs) {
16082
- expire(id);
16292
+ expire(id, "expired");
16083
16293
  continue;
16084
16294
  }
16085
16295
  expirePendings(entry, deps.now());
16086
16296
  }
16087
16297
  };
16088
- const timer = setInterval(sweep, deps.idleMs);
16298
+ const timer = setInterval(sweep, Math.min(deps.idleMs, RC_PENDING_DEADLINE_MS));
16089
16299
  timer.unref();
16090
16300
  const birth = (id, facts) => {
16091
- const record = { id, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), workerState: void 0, workerIdleSeconds: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map() };
16301
+ const record = { id, createdAt: deps.now(), lastSeenAt: deps.now(), ...facts, pending: /* @__PURE__ */ new Map(), retired: /* @__PURE__ */ new Map(), workerState: void 0, workerIdleSeconds: void 0, sequenceNum: void 0, liveTasks: /* @__PURE__ */ new Map() };
16092
16302
  entries.set(id, record);
16303
+ deps.onTransition?.({ kind: "session-appeared", session: id, at: record.createdAt });
16093
16304
  return record;
16094
16305
  };
16095
16306
  const persistCredential = (entry) => {
@@ -16097,6 +16308,13 @@ function createRcSessionTracker(deps) {
16097
16308
  deps.credentialStore?.write(entry.id, { authorization: entry.oauthAuthorization, anthropicVersion: entry.anthropicVersion, anthropicClientPlatform: entry.anthropicClientPlatform });
16098
16309
  }
16099
16310
  };
16311
+ const refresh = (entry, facts) => {
16312
+ entry.lastSeenAt = deps.now();
16313
+ entry.oauthAuthorization = facts.oauthAuthorization ?? entry.oauthAuthorization;
16314
+ entry.anthropicVersion = facts.anthropicVersion ?? entry.anthropicVersion;
16315
+ entry.anthropicClientPlatform = facts.anthropicClientPlatform ?? entry.anthropicClientPlatform;
16316
+ persistCredential(entry);
16317
+ };
16100
16318
  const observeExchange = (request4) => {
16101
16319
  const method = (request4.method ?? "").toUpperCase();
16102
16320
  if (!isRcSessionExchange(request4.url)) {
@@ -16135,7 +16353,12 @@ function createRcSessionTracker(deps) {
16135
16353
  if (id2 === void 0) {
16136
16354
  return;
16137
16355
  }
16138
- persistCredential(birth(id2, facts));
16356
+ const existing = entries.get(id2);
16357
+ if (existing === void 0) {
16358
+ persistCredential(birth(id2, facts));
16359
+ return;
16360
+ }
16361
+ refresh(existing, facts);
16139
16362
  }
16140
16363
  };
16141
16364
  }
@@ -16144,12 +16367,10 @@ function createRcSessionTracker(deps) {
16144
16367
  if (id?.startsWith(RC_SESSION_ID_PREFIX) !== true) {
16145
16368
  return void 0;
16146
16369
  }
16147
- const entry = entries.get(id) ?? birth(id, facts);
16148
- entry.lastSeenAt = deps.now();
16149
- entry.oauthAuthorization = facts.oauthAuthorization ?? entry.oauthAuthorization;
16150
- entry.anthropicVersion = facts.anthropicVersion ?? entry.anthropicVersion;
16151
- entry.anthropicClientPlatform = facts.anthropicClientPlatform ?? entry.anthropicClientPlatform;
16152
- persistCredential(entry);
16370
+ const tracked = entries.get(id);
16371
+ if (tracked !== void 0) {
16372
+ refresh(tracked, facts);
16373
+ }
16153
16374
  const bodyKind = method === "POST" && rest === `${id}/worker/events` ? "worker-events" : method === "POST" && rest === `${id}/events` ? "client-events" : method === "POST" && rest === `${id}/worker/heartbeat` ? "heartbeat" : method === "PUT" && rest === `${id}/worker` ? "worker-registration" : void 0;
16154
16375
  let chunks = [];
16155
16376
  let buffered = 0;
@@ -16170,10 +16391,10 @@ function createRcSessionTracker(deps) {
16170
16391
  }
16171
16392
  const now = deps.now();
16172
16393
  for (const controlRequest of factsOfBody.controlRequests) {
16173
- entryNow.pending.set(controlRequest.requestId, { sessionId: id, ...controlRequest, observedAt: now });
16394
+ addPending(entryNow, { sessionId: id, ...controlRequest, observedAt: now });
16174
16395
  }
16175
16396
  for (const requestId of factsOfBody.answeredRequestIds) {
16176
- entryNow.pending.delete(requestId);
16397
+ retirePending(entryNow, requestId, "answered");
16177
16398
  }
16178
16399
  for (const payload of factsOfBody.payloads) {
16179
16400
  entryNow.liveTasks = applyAgentTaskEvent(entryNow.liveTasks, id, payload, now);
@@ -16182,7 +16403,11 @@ function createRcSessionTracker(deps) {
16182
16403
  entryNow.workerIdleSeconds = { value: factsOfBody.idleSeconds, observedAt: now };
16183
16404
  }
16184
16405
  if (factsOfBody.workerStatus !== void 0) {
16406
+ const previous = entryNow.workerState?.value;
16185
16407
  entryNow.workerState = { value: factsOfBody.workerStatus, observedAt: now };
16408
+ if (previous !== factsOfBody.workerStatus) {
16409
+ deps.onTransition?.({ kind: "worker-state", session: id, state: factsOfBody.workerStatus, ...previous === void 0 ? {} : { previous }, at: now });
16410
+ }
16186
16411
  }
16187
16412
  };
16188
16413
  const archiving = method === "POST" && rest === `${id}/archive`;
@@ -16207,10 +16432,13 @@ function createRcSessionTracker(deps) {
16207
16432
  onResponse: (status, headers) => {
16208
16433
  if (singleHeader(headers, CONFLICT_REASON_HEADER) !== void 0 || archiving && isSuccessful(status)) {
16209
16434
  deps.credentialStore?.remove(id);
16210
- expire(id);
16435
+ expire(id, singleHeader(headers, CONFLICT_REASON_HEADER) === void 0 ? "archived" : "conflict");
16211
16436
  return;
16212
16437
  }
16213
16438
  accepted = isSuccessful(status);
16439
+ if (accepted && !entries.has(id)) {
16440
+ persistCredential(birth(id, facts));
16441
+ }
16214
16442
  file();
16215
16443
  },
16216
16444
  onBodyChunk: () => {
@@ -16275,12 +16503,12 @@ function createRcSessionTracker(deps) {
16275
16503
  const pending = pendingOfControlRequestPayload(event.payload);
16276
16504
  if (pending !== void 0) {
16277
16505
  if (event.source === RC_STREAM_WORKER_SOURCE) {
16278
- entry.pending.set(pending.requestId, { sessionId, ...pending, observedAt: deps.now() });
16506
+ addPending(entry, { sessionId, ...pending, observedAt: deps.now() });
16279
16507
  }
16280
16508
  return;
16281
16509
  }
16282
16510
  for (const requestId of answeredRequestIdsOfControlResponsePayload(event.payload)) {
16283
- entry.pending.delete(requestId);
16511
+ retirePending(entry, requestId, "answered");
16284
16512
  }
16285
16513
  },
16286
16514
  liveTasksOf: (sessionId) => {
@@ -16288,10 +16516,14 @@ function createRcSessionTracker(deps) {
16288
16516
  return sortedEntries().filter((entry) => sessionId === void 0 || entry.id === sessionId).flatMap((entry) => [...entry.liveTasks.values()].sort((left, right) => left.observedAt - right.observedAt || (left.taskId < right.taskId ? -1 : 1)));
16289
16517
  },
16290
16518
  completePending: (sessionId, requestId) => {
16291
- entries.get(sessionId)?.pending.delete(requestId);
16519
+ const entry = entries.get(sessionId);
16520
+ if (entry !== void 0) {
16521
+ retirePending(entry, requestId, "answered");
16522
+ }
16292
16523
  },
16293
16524
  close: () => {
16294
16525
  clearInterval(timer);
16526
+ deps.onClose?.();
16295
16527
  }
16296
16528
  };
16297
16529
  }
@@ -18371,8 +18603,8 @@ init_cliError();
18371
18603
  init_realPorts();
18372
18604
 
18373
18605
  // src/frontdoor/controlApi.ts
18374
- var import_client7 = require("@orpc/client");
18375
- var import_openapi8 = require("@orpc/openapi");
18606
+ var import_client8 = require("@orpc/client");
18607
+ var import_openapi9 = require("@orpc/openapi");
18376
18608
 
18377
18609
  // src/checkReport.ts
18378
18610
  var import_node_os5 = __toESM(require("node:os"), 1);
@@ -18503,7 +18735,7 @@ init_providersStore();
18503
18735
  init_signIn();
18504
18736
  init_realPorts();
18505
18737
  var import_node_path36 = __toESM(require("node:path"), 1);
18506
- var import_zod24 = require("zod");
18738
+ var import_zod25 = require("zod");
18507
18739
  init_envBool();
18508
18740
  init_load();
18509
18741
  init_schema();
@@ -18515,6 +18747,7 @@ init_farm();
18515
18747
  init_guard();
18516
18748
  init_providersStore();
18517
18749
  init_projects();
18750
+ init_injected();
18518
18751
  init_pipeline();
18519
18752
  var HISTORY_PROJECTS_KEY_PREFIX = "history/projects/";
18520
18753
  function projectFragmentOf(rawKey) {
@@ -18584,9 +18817,9 @@ function lookupKeychainService(run, farmRoot) {
18584
18817
  }
18585
18818
  return { checked: true, found: true, serviceName, note: `Keychain service name for this identity: "${serviceName}".` };
18586
18819
  }
18587
- var SettingsSecretsShapeSchema = import_zod24.z.looseObject({
18588
- env: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.unknown()).optional(),
18589
- hooks: import_zod24.z.record(import_zod24.z.string(), import_zod24.z.array(import_zod24.z.unknown())).optional()
18820
+ var SettingsSecretsShapeSchema = import_zod25.z.looseObject({
18821
+ env: import_zod25.z.record(import_zod25.z.string(), import_zod25.z.unknown()).optional(),
18822
+ hooks: import_zod25.z.record(import_zod25.z.string(), import_zod25.z.array(import_zod25.z.unknown())).optional()
18590
18823
  });
18591
18824
  function hookCommandCountOf(group) {
18592
18825
  if (typeof group !== "object" || group === null) {
@@ -18687,10 +18920,11 @@ function runCheck(params) {
18687
18920
  const resolved = resolveDecisions({ facts, cascade: params.cascade, classification: params.classification });
18688
18921
  const decisionLines = [...resolved.decisions.values()].slice().sort((a, b) => a.relPath < b.relPath ? -1 : a.relPath > b.relPath ? 1 : 0).map(formatDecision);
18689
18922
  const projectEncodingAmbiguities = flagAmbiguousEncodings(resolved.flattened, facts);
18923
+ const guardEnv = launchEnvironment(params.env, params.configDirEscapeHatch);
18690
18924
  const ambientCredential = isCodex ? codexCredentialGuard(params.env, params.identity?.allowAmbientCredential ?? false) : evaluateAmbientCredentialGuard({
18691
- env: params.env,
18925
+ env: guardEnv,
18692
18926
  allowAmbientCredential: params.identity?.allowAmbientCredential ?? false,
18693
- allowAmbientCredentialOverride: parseEnvBool("AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL", params.env.AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL) === true,
18927
+ allowAmbientCredentialOverride: parseEnvBool("AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL", guardEnv.AGENT_SHIM_ALLOW_AMBIENT_CREDENTIAL) === true,
18694
18928
  ...params.identityName === void 0 ? {} : { identityName: params.identityName }
18695
18929
  });
18696
18930
  const settingsShared = resolved.flattened.categories.get("settings") ?? SHIPPED_CATEGORY_DEFAULTS.settings;
@@ -18860,6 +19094,7 @@ function collectCheckReport(params) {
18860
19094
  home,
18861
19095
  claudeHome,
18862
19096
  env: params.env,
19097
+ configDirEscapeHatch: identityDecision.configDirEscapeHatch,
18863
19098
  ...git.branch === void 0 ? {} : { branch: git.branch },
18864
19099
  ...git.branchDetached === void 0 ? {} : { branchDetached: git.branchDetached },
18865
19100
  nowMs: Date.now(),
@@ -18885,7 +19120,7 @@ function collectCheckReport(params) {
18885
19120
  }
18886
19121
 
18887
19122
  // src/checkReportSchema.ts
18888
- var import_zod26 = require("zod");
19123
+ var import_zod27 = require("zod");
18889
19124
  init_schema();
18890
19125
  init_claudeVersion();
18891
19126
  init_identity();
@@ -18949,124 +19184,124 @@ var DIAGNOSTIC_CODES = [
18949
19184
  var DIAGNOSTIC_SEVERITIES = ["error", "warning", "info"];
18950
19185
 
18951
19186
  // src/usage/pickReportSchema.ts
18952
- var import_zod25 = require("zod");
19187
+ var import_zod26 = require("zod");
18953
19188
  init_plan2();
18954
- var PoolPickCandidateViewSchema = import_zod25.z.strictObject({
18955
- identity: import_zod25.z.string(),
19189
+ var PoolPickCandidateViewSchema = import_zod26.z.strictObject({
19190
+ identity: import_zod26.z.string(),
18956
19191
  /** In pick order: `scored` has usable quota data, `unknown` has none, `pay-per-use` bills by use, `ineligible` is refused right now. */
18957
- class: import_zod25.z.enum(["scored", "unknown", "pay-per-use", "ineligible"]),
19192
+ class: import_zod26.z.enum(["scored", "unknown", "pay-per-use", "ineligible"]),
18958
19193
  /** Plan-size-weighted remaining quota per hour until its reset; present for `scored` only. */
18959
- score: import_zod25.z.number().optional(),
19194
+ score: import_zod26.z.number().optional(),
18960
19195
  /** Which window's reset divides the score: the seven-day window, or the five-hour one when the member reports no seven-day utilisation or its measured-ratio five-hour term outranks the weekly one; present with `score`. */
18961
- scoreWindow: import_zod25.z.enum(["sevenDay", "fiveHour"]).optional(),
19196
+ scoreWindow: import_zod26.z.enum(["sevenDay", "fiveHour"]).optional(),
18962
19197
  /** False when the five-hour window would run dry, at the observed pace, before it resets. */
18963
- feasible: import_zod25.z.boolean(),
19198
+ feasible: import_zod26.z.boolean(),
18964
19199
  /** When an `ineligible` member can be used again, as an ISO instant. */
18965
- blockedUntil: import_zod25.z.iso.datetime().optional(),
19200
+ blockedUntil: import_zod26.z.iso.datetime().optional(),
18966
19201
  plan: PlanClassSchema,
18967
19202
  /** The facts behind the class and score, in the order they matter. */
18968
- reasons: import_zod25.z.array(import_zod25.z.string())
19203
+ reasons: import_zod26.z.array(import_zod26.z.string())
18969
19204
  });
18970
- var PoolPickReportSchema = import_zod25.z.strictObject({
18971
- pool: import_zod25.z.string(),
18972
- directory: import_zod25.z.string(),
19205
+ var PoolPickReportSchema = import_zod26.z.strictObject({
19206
+ pool: import_zod26.z.string(),
19207
+ directory: import_zod26.z.string(),
18973
19208
  /** The member a launch would run as, absent when every member is refused. */
18974
- pick: import_zod25.z.string().optional(),
18975
- candidates: import_zod25.z.array(PoolPickCandidateViewSchema),
19209
+ pick: import_zod26.z.string().optional(),
19210
+ candidates: import_zod26.z.array(PoolPickCandidateViewSchema),
18976
19211
  /** Identity members anywhere in the pool's graph that do not exist; a launch skips them. */
18977
- missing: import_zod25.z.array(import_zod25.z.string()),
19212
+ missing: import_zod26.z.array(import_zod26.z.string()),
18978
19213
  /** When nothing can be picked, the soonest any member returns. */
18979
- earliestReturn: import_zod25.z.strictObject({ identity: import_zod25.z.string(), at: import_zod25.z.iso.datetime() }).optional(),
19214
+ earliestReturn: import_zod26.z.strictObject({ identity: import_zod26.z.string(), at: import_zod26.z.iso.datetime() }).optional(),
18980
19215
  /** The member a resumed conversation started on but moved off, and why, when the ranking could not keep it. */
18981
- movedOff: import_zod25.z.strictObject({ identity: import_zod25.z.string(), reason: import_zod25.z.string() }).optional(),
19216
+ movedOff: import_zod26.z.strictObject({ identity: import_zod26.z.string(), reason: import_zod26.z.string() }).optional(),
18982
19217
  /** Why the last-pick record could not be read, when that is the case. */
18983
- stickyProblem: import_zod25.z.string().optional()
19218
+ stickyProblem: import_zod26.z.string().optional()
18984
19219
  });
18985
19220
 
18986
19221
  // src/checkReportSchema.ts
18987
19222
  var CHECK_CREDENTIAL_APPLIES = ["provider", "identity", "stored-login"];
18988
- var CheckLayerViewSchema = import_zod26.z.strictObject({
18989
- id: import_zod26.z.int(),
18990
- kind: import_zod26.z.enum(LAYER_KINDS),
18991
- source: import_zod26.z.string()
19223
+ var CheckLayerViewSchema = import_zod27.z.strictObject({
19224
+ id: import_zod27.z.int(),
19225
+ kind: import_zod27.z.enum(LAYER_KINDS),
19226
+ source: import_zod27.z.string()
18992
19227
  });
18993
- var CheckEntryViewSchema = import_zod26.z.strictObject({
18994
- path: import_zod26.z.string(),
18995
- shared: import_zod26.z.boolean(),
18996
- via: import_zod26.z.enum(DECISION_VIAS),
19228
+ var CheckEntryViewSchema = import_zod27.z.strictObject({
19229
+ path: import_zod27.z.string(),
19230
+ shared: import_zod27.z.boolean(),
19231
+ via: import_zod27.z.enum(DECISION_VIAS),
18997
19232
  /** The entry's real category, or null when nothing classifies it. */
18998
- category: import_zod26.z.enum(CATEGORY_NAMES).nullable(),
18999
- rule: import_zod26.z.strictObject({ key: import_zod26.z.string(), layer: import_zod26.z.int() }).optional(),
19233
+ category: import_zod27.z.enum(CATEGORY_NAMES).nullable(),
19234
+ rule: import_zod27.z.strictObject({ key: import_zod27.z.string(), layer: import_zod27.z.int() }).optional(),
19000
19235
  /** Rules that matched but whose `when` condition failed, each with the conditions that failed. */
19001
- eliminated: import_zod26.z.readonly(import_zod26.z.array(import_zod26.z.strictObject({ key: import_zod26.z.string(), failed: import_zod26.z.readonly(import_zod26.z.array(import_zod26.z.string())) }))).optional()
19236
+ eliminated: import_zod27.z.readonly(import_zod27.z.array(import_zod27.z.strictObject({ key: import_zod27.z.string(), failed: import_zod27.z.readonly(import_zod27.z.array(import_zod27.z.string())) }))).optional()
19002
19237
  });
19003
- var CheckDiagnosticSchema = import_zod26.z.strictObject({
19004
- code: import_zod26.z.enum(DIAGNOSTIC_CODES),
19005
- severity: import_zod26.z.enum(DIAGNOSTIC_SEVERITIES),
19006
- message: import_zod26.z.string(),
19007
- subject: import_zod26.z.string().optional(),
19008
- layer: import_zod26.z.int().optional()
19238
+ var CheckDiagnosticSchema = import_zod27.z.strictObject({
19239
+ code: import_zod27.z.enum(DIAGNOSTIC_CODES),
19240
+ severity: import_zod27.z.enum(DIAGNOSTIC_SEVERITIES),
19241
+ message: import_zod27.z.string(),
19242
+ subject: import_zod27.z.string().optional(),
19243
+ layer: import_zod27.z.int().optional()
19009
19244
  });
19010
- var CheckAmbientCredentialSchema = import_zod26.z.union([import_zod26.z.strictObject({ ok: import_zod26.z.literal(true) }), import_zod26.z.strictObject({ ok: import_zod26.z.literal(false), variable: import_zod26.z.string(), message: import_zod26.z.string() })]);
19011
- var CheckKeychainSchema = import_zod26.z.strictObject({
19012
- checked: import_zod26.z.literal(true),
19013
- found: import_zod26.z.boolean(),
19014
- serviceName: import_zod26.z.string().optional(),
19015
- note: import_zod26.z.string()
19245
+ var CheckAmbientCredentialSchema = import_zod27.z.union([import_zod27.z.strictObject({ ok: import_zod27.z.literal(true) }), import_zod27.z.strictObject({ ok: import_zod27.z.literal(false), variable: import_zod27.z.string(), message: import_zod27.z.string() })]);
19246
+ var CheckKeychainSchema = import_zod27.z.strictObject({
19247
+ checked: import_zod27.z.literal(true),
19248
+ found: import_zod27.z.boolean(),
19249
+ serviceName: import_zod27.z.string().optional(),
19250
+ note: import_zod27.z.string()
19016
19251
  });
19017
- var CheckSettingsExposureSchema = import_zod26.z.strictObject({
19018
- file: import_zod26.z.string(),
19019
- envKeyNames: import_zod26.z.readonly(import_zod26.z.array(import_zod26.z.string())),
19020
- hookEventNames: import_zod26.z.readonly(import_zod26.z.array(import_zod26.z.string())),
19021
- hookCommandCount: import_zod26.z.int().nonnegative()
19252
+ var CheckSettingsExposureSchema = import_zod27.z.strictObject({
19253
+ file: import_zod27.z.string(),
19254
+ envKeyNames: import_zod27.z.readonly(import_zod27.z.array(import_zod27.z.string())),
19255
+ hookEventNames: import_zod27.z.readonly(import_zod27.z.array(import_zod27.z.string())),
19256
+ hookCommandCount: import_zod27.z.int().nonnegative()
19022
19257
  });
19023
- var CredentialSourceSummarySchema = import_zod26.z.union([
19024
- import_zod26.z.strictObject({ kind: import_zod26.z.literal("env"), variable: import_zod26.z.string() }),
19025
- import_zod26.z.strictObject({ kind: import_zod26.z.literal("file"), path: import_zod26.z.string() }),
19026
- import_zod26.z.strictObject({ kind: import_zod26.z.literal("command"), program: import_zod26.z.string() }),
19027
- import_zod26.z.strictObject({ kind: import_zod26.z.literal("op"), reference: import_zod26.z.string() }),
19028
- import_zod26.z.strictObject({ kind: import_zod26.z.literal("keychain"), service: import_zod26.z.string(), account: import_zod26.z.string().optional() }),
19029
- import_zod26.z.strictObject({ kind: import_zod26.z.literal("literal") })
19258
+ var CredentialSourceSummarySchema = import_zod27.z.union([
19259
+ import_zod27.z.strictObject({ kind: import_zod27.z.literal("env"), variable: import_zod27.z.string() }),
19260
+ import_zod27.z.strictObject({ kind: import_zod27.z.literal("file"), path: import_zod27.z.string() }),
19261
+ import_zod27.z.strictObject({ kind: import_zod27.z.literal("command"), program: import_zod27.z.string() }),
19262
+ import_zod27.z.strictObject({ kind: import_zod27.z.literal("op"), reference: import_zod27.z.string() }),
19263
+ import_zod27.z.strictObject({ kind: import_zod27.z.literal("keychain"), service: import_zod27.z.string(), account: import_zod27.z.string().optional() }),
19264
+ import_zod27.z.strictObject({ kind: import_zod27.z.literal("literal") })
19030
19265
  ]);
19031
- var CredentialSummarySchema = import_zod26.z.strictObject({
19032
- target: import_zod26.z.enum(CREDENTIAL_TARGETS),
19033
- sources: import_zod26.z.readonly(import_zod26.z.array(CredentialSourceSummarySchema)),
19266
+ var CredentialSummarySchema = import_zod27.z.strictObject({
19267
+ target: import_zod27.z.enum(CREDENTIAL_TARGETS),
19268
+ sources: import_zod27.z.readonly(import_zod27.z.array(CredentialSourceSummarySchema)),
19034
19269
  cache: CredentialCacheSchema.optional()
19035
19270
  });
19036
- var CachedCredentialStateSchema = import_zod26.z.union([
19037
- import_zod26.z.strictObject({ store: import_zod26.z.enum(CREDENTIAL_CACHE_STORES), status: import_zod26.z.literal("empty") }),
19038
- import_zod26.z.strictObject({ store: import_zod26.z.enum(CREDENTIAL_CACHE_STORES), status: import_zod26.z.literal("unreadable"), reason: import_zod26.z.string() }),
19039
- import_zod26.z.strictObject({ store: import_zod26.z.enum(CREDENTIAL_CACHE_STORES), status: import_zod26.z.enum(["fresh", "expired"]), ageMs: import_zod26.z.number(), expiresInMs: import_zod26.z.number().optional() })
19271
+ var CachedCredentialStateSchema = import_zod27.z.union([
19272
+ import_zod27.z.strictObject({ store: import_zod27.z.enum(CREDENTIAL_CACHE_STORES), status: import_zod27.z.literal("empty") }),
19273
+ import_zod27.z.strictObject({ store: import_zod27.z.enum(CREDENTIAL_CACHE_STORES), status: import_zod27.z.literal("unreadable"), reason: import_zod27.z.string() }),
19274
+ import_zod27.z.strictObject({ store: import_zod27.z.enum(CREDENTIAL_CACHE_STORES), status: import_zod27.z.enum(["fresh", "expired"]), ageMs: import_zod27.z.number(), expiresInMs: import_zod27.z.number().optional() })
19040
19275
  ]);
19041
- var CheckCredentialProviderSchema = import_zod26.z.union([
19042
- import_zod26.z.strictObject({ name: import_zod26.z.string(), credential: CredentialSummarySchema.optional(), cached: CachedCredentialStateSchema.optional() }),
19043
- import_zod26.z.strictObject({ name: import_zod26.z.string(), problem: import_zod26.z.string() })
19276
+ var CheckCredentialProviderSchema = import_zod27.z.union([
19277
+ import_zod27.z.strictObject({ name: import_zod27.z.string(), credential: CredentialSummarySchema.optional(), cached: CachedCredentialStateSchema.optional() }),
19278
+ import_zod27.z.strictObject({ name: import_zod27.z.string(), problem: import_zod27.z.string() })
19044
19279
  ]);
19045
- var CheckCredentialSchema = import_zod26.z.strictObject({
19046
- applies: import_zod26.z.enum(CHECK_CREDENTIAL_APPLIES),
19280
+ var CheckCredentialSchema = import_zod27.z.strictObject({
19281
+ applies: import_zod27.z.enum(CHECK_CREDENTIAL_APPLIES),
19047
19282
  provider: CheckCredentialProviderSchema.optional(),
19048
19283
  identity: CredentialSummarySchema.optional(),
19049
19284
  identityCached: CachedCredentialStateSchema.optional()
19050
19285
  });
19051
- var CheckClaudeVersionSchema = import_zod26.z.strictObject({
19052
- pinned: import_zod26.z.strictObject({ version: import_zod26.z.string(), source: import_zod26.z.enum(CLAUDE_VERSION_SOURCES), installed: import_zod26.z.boolean() }).optional(),
19053
- highestInstalled: import_zod26.z.string().optional(),
19054
- installed: import_zod26.z.readonly(import_zod26.z.array(import_zod26.z.string()))
19286
+ var CheckClaudeVersionSchema = import_zod27.z.strictObject({
19287
+ pinned: import_zod27.z.strictObject({ version: import_zod27.z.string(), source: import_zod27.z.enum(CLAUDE_VERSION_SOURCES), installed: import_zod27.z.boolean() }).optional(),
19288
+ highestInstalled: import_zod27.z.string().optional(),
19289
+ installed: import_zod27.z.readonly(import_zod27.z.array(import_zod27.z.string()))
19055
19290
  });
19056
- var CheckReportJsonSchema = import_zod26.z.strictObject({
19057
- identity: import_zod26.z.strictObject({ name: import_zod26.z.string().nullable(), source: import_zod26.z.enum(IDENTITY_DECISION_SOURCES) }),
19291
+ var CheckReportJsonSchema = import_zod27.z.strictObject({
19292
+ identity: import_zod27.z.strictObject({ name: import_zod27.z.string().nullable(), source: import_zod27.z.enum(IDENTITY_DECISION_SOURCES) }),
19058
19293
  /** The pool ranking, when the launch named a pool instead of an identity. */
19059
19294
  pool: PoolPickReportSchema.optional(),
19060
- configProfile: import_zod26.z.strictObject({ name: import_zod26.z.string().nullable(), source: import_zod26.z.enum(CONFIG_PROFILE_DECISION_SOURCES) }),
19061
- layers: import_zod26.z.readonly(import_zod26.z.array(CheckLayerViewSchema)),
19062
- entries: import_zod26.z.readonly(import_zod26.z.array(CheckEntryViewSchema)),
19063
- projectEncodingAmbiguities: import_zod26.z.readonly(
19064
- import_zod26.z.array(import_zod26.z.strictObject({ fragment: import_zod26.z.string(), encoded: import_zod26.z.string(), reason: import_zod26.z.enum(ENCODING_AMBIGUITY_REASONS), detail: import_zod26.z.string() }))
19295
+ configProfile: import_zod27.z.strictObject({ name: import_zod27.z.string().nullable(), source: import_zod27.z.enum(CONFIG_PROFILE_DECISION_SOURCES) }),
19296
+ layers: import_zod27.z.readonly(import_zod27.z.array(CheckLayerViewSchema)),
19297
+ entries: import_zod27.z.readonly(import_zod27.z.array(CheckEntryViewSchema)),
19298
+ projectEncodingAmbiguities: import_zod27.z.readonly(
19299
+ import_zod27.z.array(import_zod27.z.strictObject({ fragment: import_zod27.z.string(), encoded: import_zod27.z.string(), reason: import_zod27.z.enum(ENCODING_AMBIGUITY_REASONS), detail: import_zod27.z.string() }))
19065
19300
  ),
19066
- diagnostics: import_zod26.z.readonly(import_zod26.z.array(CheckDiagnosticSchema)),
19301
+ diagnostics: import_zod27.z.readonly(import_zod27.z.array(CheckDiagnosticSchema)),
19067
19302
  ambientCredential: CheckAmbientCredentialSchema,
19068
19303
  keychain: CheckKeychainSchema.optional(),
19069
- settingsExposure: import_zod26.z.readonly(import_zod26.z.array(CheckSettingsExposureSchema)),
19304
+ settingsExposure: import_zod27.z.readonly(import_zod27.z.array(CheckSettingsExposureSchema)),
19070
19305
  credential: CheckCredentialSchema,
19071
19306
  claudeVersion: CheckClaudeVersionSchema.optional()
19072
19307
  });
@@ -19077,28 +19312,28 @@ init_preflight();
19077
19312
  init_resets();
19078
19313
 
19079
19314
  // src/usage/resetsSchema.ts
19080
- var import_zod27 = require("zod");
19081
- var ResetRowSchema = import_zod27.z.strictObject({
19082
- identity: import_zod27.z.string(),
19083
- provider: import_zod27.z.string(),
19315
+ var import_zod28 = require("zod");
19316
+ var ResetRowSchema = import_zod28.z.strictObject({
19317
+ identity: import_zod28.z.string(),
19318
+ provider: import_zod28.z.string(),
19084
19319
  /** What the window is: `5h`, `7d` or `extra usage` for an Anthropic account, or the provider's own measure and period (`tokens 5h`). */
19085
- window: import_zod27.z.string(),
19320
+ window: import_zod28.z.string(),
19086
19321
  /** When the state the window comes from was observed, as an ISO instant. */
19087
- observedAt: import_zod27.z.iso.datetime(),
19322
+ observedAt: import_zod28.z.iso.datetime(),
19088
19323
  /** When the window resets, as an ISO instant; absent when the upstream reported none. */
19089
- resetsAt: import_zod27.z.iso.datetime().optional(),
19324
+ resetsAt: import_zod28.z.iso.datetime().optional(),
19090
19325
  /** True when the reset time has passed, so the recorded observation describes a window that no longer exists and its utilisation reads as 0. */
19091
- reset: import_zod27.z.boolean(),
19326
+ reset: import_zod28.z.boolean(),
19092
19327
  /** The fraction used, as `effectiveWindow` reads it at the report's own clock. */
19093
- utilization: import_zod27.z.number().optional(),
19328
+ utilization: import_zod28.z.number().optional(),
19094
19329
  /** The window's own status, for a window that has not reset yet. */
19095
- status: import_zod27.z.string().optional()
19330
+ status: import_zod28.z.string().optional()
19096
19331
  });
19097
- var ResetScheduleSchema = import_zod27.z.strictObject({ resets: import_zod27.z.readonly(import_zod27.z.array(ResetRowSchema)) });
19332
+ var ResetScheduleSchema = import_zod28.z.strictObject({ resets: import_zod28.z.readonly(import_zod28.z.array(ResetRowSchema)) });
19098
19333
 
19099
19334
  // src/frontdoor/controlSchemas.ts
19100
19335
  var import_node_path42 = __toESM(require("node:path"), 1);
19101
- var import_zod34 = require("zod");
19336
+ var import_zod35 = require("zod");
19102
19337
 
19103
19338
  // src/codex/doctor.ts
19104
19339
  function codexIdentityFindings(entry, identity) {
@@ -19772,12 +20007,8 @@ function runDoctor(params) {
19772
20007
  }
19773
20008
  push(section, "warn", `${where} pins Claude Code ${version}, which is not installed (installed: ${installed.length === 0 ? "none" : installed.join(", ")}); a launch that resolves to it fails.`, subject);
19774
20009
  };
19775
- const ambient = detectAmbientCredential(params.env);
19776
- if (ambient === void 0) {
19777
- push("ambient-credential", "pass", "No ambient-credential environment variable is set.");
19778
- } else {
19779
- push("ambient-credential", "warn", formatAmbientCredentialGuardMessage(ambient.variable));
19780
- }
20010
+ const ambient = ambientCredentialFinding(params.env);
20011
+ push("ambient-credential", ambient.severity, ambient.message);
19781
20012
  if (params.binaryDiscovery.ok) {
19782
20013
  const { binary } = params.binaryDiscovery;
19783
20014
  const versionNote = binary.version === void 0 ? "" : `, version ${binary.version}`;
@@ -20329,92 +20560,92 @@ function collectDoctorReport(params) {
20329
20560
  // src/frontdoor/controlSchemas.ts
20330
20561
  init_schema2();
20331
20562
  init_state();
20332
- var UsageListOutputSchema = import_zod34.z.strictObject({ snapshots: import_zod34.z.readonly(import_zod34.z.array(UsageSnapshotSchema)) });
20333
- var UsageWindowsInputSchema = import_zod34.z.strictObject({
20334
- identity: import_zod34.z.string().min(1),
20335
- provider: import_zod34.z.string().min(1).optional()
20563
+ var UsageListOutputSchema = import_zod35.z.strictObject({ snapshots: import_zod35.z.readonly(import_zod35.z.array(UsageSnapshotSchema)) });
20564
+ var UsageWindowsInputSchema = import_zod35.z.strictObject({
20565
+ identity: import_zod35.z.string().min(1),
20566
+ provider: import_zod35.z.string().min(1).optional()
20336
20567
  });
20337
- var EffectiveWindowSchema = import_zod34.z.strictObject({
20568
+ var EffectiveWindowSchema = import_zod35.z.strictObject({
20338
20569
  /** True when the window's reset time has passed, so the recorded observation describes a window that no longer exists. */
20339
- reset: import_zod34.z.boolean(),
20570
+ reset: import_zod35.z.boolean(),
20340
20571
  /** The fraction used: 0 for a reset window, otherwise what was last observed, absent when none was reported. */
20341
- utilization: import_zod34.z.number().optional(),
20572
+ utilization: import_zod35.z.number().optional(),
20342
20573
  /** The reset instant, for a window that has not reset yet and reported one. */
20343
- resetsAtMs: import_zod34.z.number().optional(),
20574
+ resetsAtMs: import_zod35.z.number().optional(),
20344
20575
  /** The window's own status, for a window that has not reset yet. */
20345
- status: import_zod34.z.string().optional()
20576
+ status: import_zod35.z.string().optional()
20346
20577
  });
20347
- var UsageWindowsOutputSchema = import_zod34.z.strictObject({
20348
- identity: import_zod34.z.string(),
20349
- provider: import_zod34.z.string(),
20578
+ var UsageWindowsOutputSchema = import_zod35.z.strictObject({
20579
+ identity: import_zod35.z.string(),
20580
+ provider: import_zod35.z.string(),
20350
20581
  /** When the rate-limit state the windows come from was observed. */
20351
- observedAt: import_zod34.z.iso.datetime().optional(),
20582
+ observedAt: import_zod35.z.iso.datetime().optional(),
20352
20583
  fiveHour: EffectiveWindowSchema.optional(),
20353
20584
  sevenDay: EffectiveWindowSchema.optional()
20354
20585
  });
20355
- var UsageLiveOutputSchema = import_zod34.z.strictObject({
20586
+ var UsageLiveOutputSchema = import_zod35.z.strictObject({
20356
20587
  /** The freshest observation the door holds, never narrowed by the read's session filter because it is the door's single latest statement of the account's quota; absent while no rate_limit_event has been filed at all. */
20357
20588
  latest: RcLiveRateLimitSchema.optional(),
20358
20589
  /** One observation per session whose stream has filed a rate_limit_event this door generation. */
20359
- sessions: import_zod34.z.readonly(import_zod34.z.array(RcLiveRateLimitSchema))
20590
+ sessions: import_zod35.z.readonly(import_zod35.z.array(RcLiveRateLimitSchema))
20360
20591
  });
20361
- var FrontDoorSessionStatusSchema = import_zod34.z.strictObject({
20362
- pid: import_zod34.z.int().positive(),
20363
- startedAt: import_zod34.z.number(),
20364
- alive: import_zod34.z.boolean()
20592
+ var FrontDoorSessionStatusSchema = import_zod35.z.strictObject({
20593
+ pid: import_zod35.z.int().positive(),
20594
+ startedAt: import_zod35.z.number(),
20595
+ alive: import_zod35.z.boolean()
20365
20596
  });
20366
- var HeadroomSocketTargetSchema = import_zod34.z.union([import_zod34.z.strictObject({ socketPath: import_zod34.z.string() }), import_zod34.z.strictObject({ refused: import_zod34.z.string() })]);
20367
- var FrontDoorStatusOutputSchema = import_zod34.z.strictObject({
20597
+ var HeadroomSocketTargetSchema = import_zod35.z.union([import_zod35.z.strictObject({ socketPath: import_zod35.z.string() }), import_zod35.z.strictObject({ refused: import_zod35.z.string() })]);
20598
+ var FrontDoorStatusOutputSchema = import_zod35.z.strictObject({
20368
20599
  state: FrontDoorStateSchema,
20369
- supervisorAlive: import_zod34.z.boolean(),
20600
+ supervisorAlive: import_zod35.z.boolean(),
20370
20601
  /** The pids of earlier doors that released their addresses and are finishing the connections they carried: running, but not serving anything new. */
20371
- draining: import_zod34.z.readonly(import_zod34.z.array(import_zod34.z.number().int().positive())),
20372
- sessions: import_zod34.z.readonly(import_zod34.z.array(FrontDoorSessionStatusSchema)),
20602
+ draining: import_zod35.z.readonly(import_zod35.z.array(import_zod35.z.number().int().positive())),
20603
+ sessions: import_zod35.z.readonly(import_zod35.z.array(FrontDoorSessionStatusSchema)),
20373
20604
  headroomSocket: HeadroomSocketTargetSchema.optional(),
20374
- logPath: import_zod34.z.string(),
20375
- logExists: import_zod34.z.boolean()
20605
+ logPath: import_zod35.z.string(),
20606
+ logExists: import_zod35.z.boolean()
20376
20607
  });
20377
- var FrontDoorSessionsOutputSchema = import_zod34.z.strictObject({ sessions: import_zod34.z.readonly(import_zod34.z.array(FrontDoorSessionStatusSchema)) });
20378
- var CheckRunInputSchema = import_zod34.z.strictObject({
20379
- path: import_zod34.z.string().min(1),
20380
- identity: import_zod34.z.string().min(1).optional()
20608
+ var FrontDoorSessionsOutputSchema = import_zod35.z.strictObject({ sessions: import_zod35.z.readonly(import_zod35.z.array(FrontDoorSessionStatusSchema)) });
20609
+ var CheckRunInputSchema = import_zod35.z.strictObject({
20610
+ path: import_zod35.z.string().min(1),
20611
+ identity: import_zod35.z.string().min(1).optional()
20381
20612
  }).refine((input) => import_node_path42.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
20382
- var PoolPickInputSchema = import_zod34.z.strictObject({
20383
- pool: import_zod34.z.string().min(1),
20384
- path: import_zod34.z.string().min(1)
20613
+ var PoolPickInputSchema = import_zod35.z.strictObject({
20614
+ pool: import_zod35.z.string().min(1),
20615
+ path: import_zod35.z.string().min(1)
20385
20616
  }).refine((input) => import_node_path42.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
20386
- var DoctorFindingSchema = import_zod34.z.strictObject({
20387
- section: import_zod34.z.enum(DOCTOR_SECTIONS),
20388
- subject: import_zod34.z.string().optional(),
20389
- severity: import_zod34.z.enum(DOCTOR_SEVERITIES),
20390
- message: import_zod34.z.string()
20617
+ var DoctorFindingSchema = import_zod35.z.strictObject({
20618
+ section: import_zod35.z.enum(DOCTOR_SECTIONS),
20619
+ subject: import_zod35.z.string().optional(),
20620
+ severity: import_zod35.z.enum(DOCTOR_SEVERITIES),
20621
+ message: import_zod35.z.string()
20391
20622
  });
20392
- var DoctorRunOutputSchema = import_zod34.z.strictObject({
20623
+ var DoctorRunOutputSchema = import_zod35.z.strictObject({
20393
20624
  /** False exactly when any finding is a `fail`; a `warn` never fails the report on its own. */
20394
- ok: import_zod34.z.boolean(),
20395
- findings: import_zod34.z.readonly(import_zod34.z.array(DoctorFindingSchema))
20625
+ ok: import_zod35.z.boolean(),
20626
+ findings: import_zod35.z.readonly(import_zod35.z.array(DoctorFindingSchema))
20396
20627
  });
20397
- var FrontDoorRestartOutputSchema = import_zod34.z.strictObject({
20398
- action: import_zod34.z.literal("restarting"),
20399
- previousPid: import_zod34.z.int().positive()
20628
+ var FrontDoorRestartOutputSchema = import_zod35.z.strictObject({
20629
+ action: import_zod35.z.literal("restarting"),
20630
+ previousPid: import_zod35.z.int().positive()
20400
20631
  });
20401
- var UpdateCheckOutputSchema = import_zod34.z.strictObject({
20402
- current: import_zod34.z.string(),
20403
- latest: import_zod34.z.string(),
20404
- action: import_zod34.z.enum(["current", "available", "updated"])
20632
+ var UpdateCheckOutputSchema = import_zod35.z.strictObject({
20633
+ current: import_zod35.z.string(),
20634
+ latest: import_zod35.z.string(),
20635
+ action: import_zod35.z.enum(["current", "available", "updated"])
20405
20636
  });
20406
- var CodexSignInSchema = import_zod34.z.discriminatedUnion("state", [
20407
- import_zod34.z.strictObject({ state: import_zod34.z.literal("none") }),
20408
- import_zod34.z.strictObject({ state: import_zod34.z.literal("signed-in"), email: import_zod34.z.string().optional(), planScope: import_zod34.z.boolean(), accessTokenExpiresAt: import_zod34.z.number() }),
20409
- import_zod34.z.strictObject({ state: import_zod34.z.literal("unreadable"), message: import_zod34.z.string() })
20637
+ var CodexSignInSchema = import_zod35.z.discriminatedUnion("state", [
20638
+ import_zod35.z.strictObject({ state: import_zod35.z.literal("none") }),
20639
+ import_zod35.z.strictObject({ state: import_zod35.z.literal("signed-in"), email: import_zod35.z.string().optional(), planScope: import_zod35.z.boolean(), accessTokenExpiresAt: import_zod35.z.number() }),
20640
+ import_zod35.z.strictObject({ state: import_zod35.z.literal("unreadable"), message: import_zod35.z.string() })
20410
20641
  ]);
20411
- var CodexStatusOutputSchema = import_zod34.z.strictObject({
20642
+ var CodexStatusOutputSchema = import_zod35.z.strictObject({
20412
20643
  signIn: CodexSignInSchema,
20413
- codexProviders: import_zod34.z.readonly(import_zod34.z.array(import_zod34.z.string()))
20644
+ codexProviders: import_zod35.z.readonly(import_zod35.z.array(import_zod35.z.string()))
20414
20645
  });
20415
- var CodexLogoutOutputSchema = import_zod34.z.strictObject({
20416
- hadGrant: import_zod34.z.boolean(),
20417
- revoked: import_zod34.z.boolean()
20646
+ var CodexLogoutOutputSchema = import_zod35.z.strictObject({
20647
+ hadGrant: import_zod35.z.boolean(),
20648
+ revoked: import_zod35.z.boolean()
20418
20649
  });
20419
20650
 
20420
20651
  // src/frontdoor/codexApi.ts
@@ -20478,71 +20709,71 @@ init_poolStore();
20478
20709
  init_providersStore();
20479
20710
 
20480
20711
  // src/frontdoor/configSchemas.ts
20481
- var import_zod35 = require("zod");
20712
+ var import_zod36 = require("zod");
20482
20713
  init_schema();
20483
20714
  init_names();
20484
20715
  init_keychainLogin();
20485
20716
  init_statusline();
20486
- var RemovalConfirmationSchema = import_zod35.z.boolean();
20487
- var CredentialWriteSchema = (targets) => import_zod35.z.strictObject({
20488
- sources: import_zod35.z.array(RemoteCredentialSourceSchema).min(1).optional(),
20489
- target: import_zod35.z.enum(targets).optional(),
20490
- cache: import_zod35.z.union([import_zod35.z.literal(false), CredentialCacheSchema]).optional()
20717
+ var RemovalConfirmationSchema = import_zod36.z.boolean();
20718
+ var CredentialWriteSchema = (targets) => import_zod36.z.strictObject({
20719
+ sources: import_zod36.z.array(RemoteCredentialSourceSchema).min(1).optional(),
20720
+ target: import_zod36.z.enum(targets).optional(),
20721
+ cache: import_zod36.z.union([import_zod36.z.literal(false), CredentialCacheSchema]).optional()
20491
20722
  });
20492
- var CredentialSummarySchema2 = import_zod35.z.strictObject({
20493
- target: import_zod35.z.enum(CREDENTIAL_TARGETS),
20494
- sources: import_zod35.z.readonly(import_zod35.z.array(
20495
- import_zod35.z.discriminatedUnion("kind", [
20496
- import_zod35.z.strictObject({ kind: import_zod35.z.literal("env"), variable: import_zod35.z.string() }),
20497
- import_zod35.z.strictObject({ kind: import_zod35.z.literal("file"), path: import_zod35.z.string() }),
20498
- import_zod35.z.strictObject({ kind: import_zod35.z.literal("command"), program: import_zod35.z.string() }),
20499
- import_zod35.z.strictObject({ kind: import_zod35.z.literal("op"), reference: import_zod35.z.string() }),
20500
- import_zod35.z.strictObject({ kind: import_zod35.z.literal("keychain"), service: import_zod35.z.string(), account: import_zod35.z.string().optional() }),
20501
- import_zod35.z.strictObject({ kind: import_zod35.z.literal("literal") })
20723
+ var CredentialSummarySchema2 = import_zod36.z.strictObject({
20724
+ target: import_zod36.z.enum(CREDENTIAL_TARGETS),
20725
+ sources: import_zod36.z.readonly(import_zod36.z.array(
20726
+ import_zod36.z.discriminatedUnion("kind", [
20727
+ import_zod36.z.strictObject({ kind: import_zod36.z.literal("env"), variable: import_zod36.z.string() }),
20728
+ import_zod36.z.strictObject({ kind: import_zod36.z.literal("file"), path: import_zod36.z.string() }),
20729
+ import_zod36.z.strictObject({ kind: import_zod36.z.literal("command"), program: import_zod36.z.string() }),
20730
+ import_zod36.z.strictObject({ kind: import_zod36.z.literal("op"), reference: import_zod36.z.string() }),
20731
+ import_zod36.z.strictObject({ kind: import_zod36.z.literal("keychain"), service: import_zod36.z.string(), account: import_zod36.z.string().optional() }),
20732
+ import_zod36.z.strictObject({ kind: import_zod36.z.literal("literal") })
20502
20733
  ])
20503
20734
  )),
20504
20735
  cache: CredentialCacheSchema.optional()
20505
20736
  });
20506
- var mutationOutput = (kind, action) => import_zod35.z.strictObject({ action: import_zod35.z.literal(action), kind: import_zod35.z.literal(kind), name: import_zod35.z.string() });
20507
- var storedMutationOutput = (kind, action, value) => import_zod35.z.strictObject({ action: import_zod35.z.literal(action), kind: import_zod35.z.literal(kind), name: import_zod35.z.string(), value });
20508
- var IdentityValueSchema = import_zod35.z.strictObject({
20509
- name: import_zod35.z.string(),
20510
- label: import_zod35.z.string().optional(),
20511
- defaultConfigProfile: import_zod35.z.string().optional(),
20512
- provider: import_zod35.z.string().optional(),
20513
- allowAmbientCredential: import_zod35.z.boolean(),
20737
+ var mutationOutput = (kind, action) => import_zod36.z.strictObject({ action: import_zod36.z.literal(action), kind: import_zod36.z.literal(kind), name: import_zod36.z.string() });
20738
+ var storedMutationOutput = (kind, action, value) => import_zod36.z.strictObject({ action: import_zod36.z.literal(action), kind: import_zod36.z.literal(kind), name: import_zod36.z.string(), value });
20739
+ var IdentityValueSchema = import_zod36.z.strictObject({
20740
+ name: import_zod36.z.string(),
20741
+ label: import_zod36.z.string().optional(),
20742
+ defaultConfigProfile: import_zod36.z.string().optional(),
20743
+ provider: import_zod36.z.string().optional(),
20744
+ allowAmbientCredential: import_zod36.z.boolean(),
20514
20745
  credential: CredentialSummarySchema2.optional(),
20515
- anchors: import_zod35.z.array(AnchorSchema).optional()
20746
+ anchors: import_zod36.z.array(AnchorSchema).optional()
20516
20747
  });
20517
20748
  var ProfileValueSchema = ConfigProfileSchema.omit({ $schema: true });
20518
- var ProviderValueSchema = import_zod35.z.strictObject({
20519
- name: import_zod35.z.string(),
20520
- kind: import_zod35.z.enum(PROVIDER_KINDS),
20521
- displayName: import_zod35.z.string(),
20522
- baseUrl: import_zod35.z.string().optional(),
20749
+ var ProviderValueSchema = import_zod36.z.strictObject({
20750
+ name: import_zod36.z.string(),
20751
+ kind: import_zod36.z.enum(PROVIDER_KINDS),
20752
+ displayName: import_zod36.z.string(),
20753
+ baseUrl: import_zod36.z.string().optional(),
20523
20754
  codex: CodexProviderConfigSchema.optional(),
20524
20755
  credential: CredentialSummarySchema2.optional(),
20525
- env: import_zod35.z.record(import_zod35.z.string(), import_zod35.z.string()).optional()
20756
+ env: import_zod36.z.record(import_zod36.z.string(), import_zod36.z.string()).optional()
20526
20757
  });
20527
- var ConfigNameInputSchema = import_zod35.z.strictObject({ name: import_zod35.z.string().min(1) });
20528
- var ConfigIdentityAddInputSchema = import_zod35.z.strictObject({ name: import_zod35.z.string().min(1), keepKeychainLogin: import_zod35.z.boolean().optional().describe(KEEP_KEYCHAIN_LOGIN_DESCRIPTION) });
20758
+ var ConfigNameInputSchema = import_zod36.z.strictObject({ name: import_zod36.z.string().min(1) });
20759
+ var ConfigIdentityAddInputSchema = import_zod36.z.strictObject({ name: import_zod36.z.string().min(1), keepKeychainLogin: import_zod36.z.boolean().optional().describe(KEEP_KEYCHAIN_LOGIN_DESCRIPTION) });
20529
20760
  var ConfigIdentityAddOutputSchema = storedMutationOutput("identity", "created", IdentityValueSchema);
20530
- var ConfigIdentitySetInputSchema = import_zod35.z.strictObject({
20531
- name: import_zod35.z.string().min(1),
20761
+ var ConfigIdentitySetInputSchema = import_zod36.z.strictObject({
20762
+ name: import_zod36.z.string().min(1),
20532
20763
  /** The identity's display label; `false` clears it. */
20533
- label: import_zod35.z.union([IdentityLabelSchema, import_zod35.z.literal(false)]).optional(),
20534
- defaultConfigProfile: import_zod35.z.union([import_zod35.z.string().min(1), import_zod35.z.literal(false)]).optional(),
20764
+ label: import_zod36.z.union([IdentityLabelSchema, import_zod36.z.literal(false)]).optional(),
20765
+ defaultConfigProfile: import_zod36.z.union([import_zod36.z.string().min(1), import_zod36.z.literal(false)]).optional(),
20535
20766
  /** The provider the identity exists for; `false` clears it. */
20536
- provider: import_zod35.z.union([import_zod35.z.string().min(1), import_zod35.z.literal(false)]).optional(),
20537
- allowAmbientCredential: import_zod35.z.boolean().optional(),
20538
- credential: import_zod35.z.union([import_zod35.z.literal(false), CredentialWriteSchema(CREDENTIAL_TARGETS)]).optional(),
20767
+ provider: import_zod36.z.union([import_zod36.z.string().min(1), import_zod36.z.literal(false)]).optional(),
20768
+ allowAmbientCredential: import_zod36.z.boolean().optional(),
20769
+ credential: import_zod36.z.union([import_zod36.z.literal(false), CredentialWriteSchema(CREDENTIAL_TARGETS)]).optional(),
20539
20770
  /** `false` removes the anchors; a list replaces them. */
20540
- anchors: import_zod35.z.union([import_zod35.z.literal(false), import_zod35.z.array(AnchorSchema).min(1)]).optional()
20771
+ anchors: import_zod36.z.union([import_zod36.z.literal(false), import_zod36.z.array(AnchorSchema).min(1)]).optional()
20541
20772
  });
20542
20773
  var ConfigIdentitySetOutputSchema = storedMutationOutput("identity", "updated", IdentityValueSchema);
20543
- var ConfigIdentityRemoveInputSchema = import_zod35.z.strictObject({ name: import_zod35.z.string().min(1), confirm: RemovalConfirmationSchema });
20774
+ var ConfigIdentityRemoveInputSchema = import_zod36.z.strictObject({ name: import_zod36.z.string().min(1), confirm: RemovalConfirmationSchema });
20544
20775
  var ConfigIdentityRemoveOutputSchema = mutationOutput("identity", "removed");
20545
- var ConfigStatuslineSetSchema = import_zod35.z.record(import_zod35.z.string(), import_zod35.z.unknown()).superRefine((settings, context) => {
20776
+ var ConfigStatuslineSetSchema = import_zod36.z.record(import_zod36.z.string(), import_zod36.z.unknown()).superRefine((settings, context) => {
20546
20777
  for (const key of Object.keys(settings)) {
20547
20778
  if (key === STATUSLINE_EXTRA_GROUP || key.startsWith(`${STATUSLINE_EXTRA_GROUP}.`)) {
20548
20779
  context.addIssue({ code: "custom", path: [key], message: `a config write through the API cannot set "${key}": the extra segment's command runs a program, so only your own configuration (the global config, a profile you edit yourself, a directory rule or a command-line assignment) may set it` });
@@ -20550,93 +20781,93 @@ var ConfigStatuslineSetSchema = import_zod35.z.record(import_zod35.z.string(), i
20550
20781
  }
20551
20782
  });
20552
20783
  var ConfigIdentityUseOutputSchema = mutationOutput("identity", "selected");
20553
- var ConfigProfileAddInputSchema = import_zod35.z.strictObject({
20554
- name: import_zod35.z.string().min(1),
20555
- extends: import_zod35.z.array(import_zod35.z.string().min(1)).optional(),
20556
- description: import_zod35.z.string().optional()
20784
+ var ConfigProfileAddInputSchema = import_zod36.z.strictObject({
20785
+ name: import_zod36.z.string().min(1),
20786
+ extends: import_zod36.z.array(import_zod36.z.string().min(1)).optional(),
20787
+ description: import_zod36.z.string().optional()
20557
20788
  });
20558
20789
  var ConfigProfileAddOutputSchema = storedMutationOutput("profile", "created", ProfileValueSchema);
20559
- var ConfigProfileSetInputSchema = import_zod35.z.strictObject({
20560
- name: import_zod35.z.string().min(1),
20561
- category: import_zod35.z.record(import_zod35.z.string(), import_zod35.z.boolean()).optional(),
20562
- entry: import_zod35.z.record(import_zod35.z.string(), import_zod35.z.boolean()).optional(),
20563
- extends: import_zod35.z.union([import_zod35.z.array(import_zod35.z.string().min(1)), import_zod35.z.literal(false)]).optional(),
20564
- description: import_zod35.z.union([import_zod35.z.string(), import_zod35.z.literal(false)]).optional(),
20565
- launch: import_zod35.z.strictObject({
20566
- skipPermissions: import_zod35.z.boolean().optional(),
20567
- remoteControl: import_zod35.z.boolean().optional(),
20568
- headroom: import_zod35.z.boolean().optional(),
20569
- trackUsage: import_zod35.z.boolean().optional(),
20570
- provider: import_zod35.z.union([import_zod35.z.string().min(1), import_zod35.z.literal(false)]).optional(),
20571
- claudeVersion: import_zod35.z.union([import_zod35.z.string().min(1), import_zod35.z.literal(false)]).optional(),
20572
- delay: import_zod35.z.union([import_zod35.z.string().regex(DURATION_RE), import_zod35.z.literal(false)]).optional(),
20573
- pause: import_zod35.z.boolean().optional(),
20574
- explain: import_zod35.z.boolean().optional(),
20575
- proxyBypass: import_zod35.z.union([import_zod35.z.array(import_zod35.z.string().min(1)), import_zod35.z.literal(false)]).optional(),
20576
- statusline: import_zod35.z.strictObject({
20790
+ var ConfigProfileSetInputSchema = import_zod36.z.strictObject({
20791
+ name: import_zod36.z.string().min(1),
20792
+ category: import_zod36.z.record(import_zod36.z.string(), import_zod36.z.boolean()).optional(),
20793
+ entry: import_zod36.z.record(import_zod36.z.string(), import_zod36.z.boolean()).optional(),
20794
+ extends: import_zod36.z.union([import_zod36.z.array(import_zod36.z.string().min(1)), import_zod36.z.literal(false)]).optional(),
20795
+ description: import_zod36.z.union([import_zod36.z.string(), import_zod36.z.literal(false)]).optional(),
20796
+ launch: import_zod36.z.strictObject({
20797
+ skipPermissions: import_zod36.z.boolean().optional(),
20798
+ remoteControl: import_zod36.z.boolean().optional(),
20799
+ headroom: import_zod36.z.boolean().optional(),
20800
+ trackUsage: import_zod36.z.boolean().optional(),
20801
+ provider: import_zod36.z.union([import_zod36.z.string().min(1), import_zod36.z.literal(false)]).optional(),
20802
+ claudeVersion: import_zod36.z.union([import_zod36.z.string().min(1), import_zod36.z.literal(false)]).optional(),
20803
+ delay: import_zod36.z.union([import_zod36.z.string().regex(DURATION_RE), import_zod36.z.literal(false)]).optional(),
20804
+ pause: import_zod36.z.boolean().optional(),
20805
+ explain: import_zod36.z.boolean().optional(),
20806
+ proxyBypass: import_zod36.z.union([import_zod36.z.array(import_zod36.z.string().min(1)), import_zod36.z.literal(false)]).optional(),
20807
+ statusline: import_zod36.z.strictObject({
20577
20808
  set: ConfigStatuslineSetSchema.optional(),
20578
- unset: import_zod35.z.array(import_zod35.z.string()).optional()
20809
+ unset: import_zod36.z.array(import_zod36.z.string()).optional()
20579
20810
  }).optional()
20580
20811
  }).optional()
20581
20812
  });
20582
20813
  var ConfigProfileSetOutputSchema = storedMutationOutput("profile", "updated", ProfileValueSchema);
20583
- var ConfigProfileRemoveInputSchema = import_zod35.z.strictObject({ name: import_zod35.z.string().min(1), confirm: RemovalConfirmationSchema });
20814
+ var ConfigProfileRemoveInputSchema = import_zod36.z.strictObject({ name: import_zod36.z.string().min(1), confirm: RemovalConfirmationSchema });
20584
20815
  var ConfigProfileRemoveOutputSchema = mutationOutput("profile", "removed");
20585
20816
  var ConfigProfileUseOutputSchema = mutationOutput("profile", "selected");
20586
- var PoolMembersInputSchema = import_zod35.z.array(import_zod35.z.string().min(1)).min(1);
20587
- var ConfigPoolAddInputSchema = import_zod35.z.strictObject({
20588
- name: import_zod35.z.string().min(1),
20817
+ var PoolMembersInputSchema = import_zod36.z.array(import_zod36.z.string().min(1)).min(1);
20818
+ var ConfigPoolAddInputSchema = import_zod36.z.strictObject({
20819
+ name: import_zod36.z.string().min(1),
20589
20820
  identities: PoolMembersInputSchema,
20590
- preference: import_zod35.z.enum(POOL_PREFERENCES).optional(),
20591
- resumeOnLimit: import_zod35.z.boolean().optional(),
20592
- compactBeforeLimit: import_zod35.z.boolean().optional(),
20821
+ preference: import_zod36.z.enum(POOL_PREFERENCES).optional(),
20822
+ resumeOnLimit: import_zod36.z.boolean().optional(),
20823
+ compactBeforeLimit: import_zod36.z.boolean().optional(),
20593
20824
  compactAtUtilisation: CompactAtUtilisationSchema.optional()
20594
20825
  });
20595
20826
  var ConfigPoolAddOutputSchema = storedMutationOutput("pool", "created", PoolSchema);
20596
- var ConfigPoolSetInputSchema = import_zod35.z.strictObject({
20597
- name: import_zod35.z.string().min(1),
20827
+ var ConfigPoolSetInputSchema = import_zod36.z.strictObject({
20828
+ name: import_zod36.z.string().min(1),
20598
20829
  identities: PoolMembersInputSchema.optional(),
20599
- preference: import_zod35.z.union([import_zod35.z.enum(POOL_PREFERENCES), import_zod35.z.literal(false)]).optional(),
20600
- resumeOnLimit: import_zod35.z.boolean().optional(),
20601
- compactBeforeLimit: import_zod35.z.boolean().optional(),
20602
- compactAtUtilisation: import_zod35.z.union([CompactAtUtilisationSchema, import_zod35.z.literal(false)]).optional()
20830
+ preference: import_zod36.z.union([import_zod36.z.enum(POOL_PREFERENCES), import_zod36.z.literal(false)]).optional(),
20831
+ resumeOnLimit: import_zod36.z.boolean().optional(),
20832
+ compactBeforeLimit: import_zod36.z.boolean().optional(),
20833
+ compactAtUtilisation: import_zod36.z.union([CompactAtUtilisationSchema, import_zod36.z.literal(false)]).optional()
20603
20834
  });
20604
20835
  var ConfigPoolSetOutputSchema = storedMutationOutput("pool", "updated", PoolSchema);
20605
- var ConfigPoolRemoveInputSchema = import_zod35.z.strictObject({ name: import_zod35.z.string().min(1), confirm: RemovalConfirmationSchema });
20836
+ var ConfigPoolRemoveInputSchema = import_zod36.z.strictObject({ name: import_zod36.z.string().min(1), confirm: RemovalConfirmationSchema });
20606
20837
  var ConfigPoolRemoveOutputSchema = mutationOutput("pool", "removed");
20607
20838
  var ConfigPoolUseOutputSchema = mutationOutput("pool", "selected");
20608
- var ConfigProviderAddInputSchema = import_zod35.z.strictObject({
20609
- name: import_zod35.z.string().min(1),
20610
- kind: import_zod35.z.enum(PROVIDER_KINDS).optional(),
20611
- displayName: import_zod35.z.string().min(1),
20612
- baseUrl: import_zod35.z.string().min(1).optional(),
20839
+ var ConfigProviderAddInputSchema = import_zod36.z.strictObject({
20840
+ name: import_zod36.z.string().min(1),
20841
+ kind: import_zod36.z.enum(PROVIDER_KINDS).optional(),
20842
+ displayName: import_zod36.z.string().min(1),
20843
+ baseUrl: import_zod36.z.string().min(1).optional(),
20613
20844
  credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).required({ sources: true }),
20614
20845
  codex: CodexProviderConfigSchema.optional()
20615
20846
  });
20616
20847
  var ConfigProviderAddOutputSchema = storedMutationOutput("provider", "created", ProviderValueSchema);
20617
- var ConfigProviderSetInputSchema = import_zod35.z.strictObject({
20618
- name: import_zod35.z.string().min(1),
20619
- displayName: import_zod35.z.string().min(1).optional(),
20620
- baseUrl: import_zod35.z.string().min(1).optional(),
20848
+ var ConfigProviderSetInputSchema = import_zod36.z.strictObject({
20849
+ name: import_zod36.z.string().min(1),
20850
+ displayName: import_zod36.z.string().min(1).optional(),
20851
+ baseUrl: import_zod36.z.string().min(1).optional(),
20621
20852
  credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).optional(),
20622
20853
  codex: CodexProviderConfigSchema.optional()
20623
20854
  });
20624
20855
  var ConfigProviderSetOutputSchema = storedMutationOutput("provider", "updated", ProviderValueSchema);
20625
- var ConfigProviderRemoveInputSchema = import_zod35.z.strictObject({ name: import_zod35.z.string().min(1), confirm: RemovalConfirmationSchema });
20856
+ var ConfigProviderRemoveInputSchema = import_zod36.z.strictObject({ name: import_zod36.z.string().min(1), confirm: RemovalConfirmationSchema });
20626
20857
  var ConfigProviderRemoveOutputSchema = mutationOutput("provider", "removed");
20627
- var ConfigRuleAddInputSchema = import_zod35.z.strictObject({
20628
- path: import_zod35.z.string().min(1),
20629
- configProfile: import_zod35.z.string().min(1).optional(),
20630
- identity: import_zod35.z.string().min(1).optional()
20858
+ var ConfigRuleAddInputSchema = import_zod36.z.strictObject({
20859
+ path: import_zod36.z.string().min(1),
20860
+ configProfile: import_zod36.z.string().min(1).optional(),
20861
+ identity: import_zod36.z.string().min(1).optional()
20631
20862
  });
20632
20863
  var ConfigRuleAddOutputSchema = storedMutationOutput("rule", "created", DirectoryRuleSchema);
20633
- var ConfigRuleSetInputSchema = import_zod35.z.strictObject({
20634
- path: import_zod35.z.string().min(1),
20635
- configProfile: import_zod35.z.union([import_zod35.z.string().min(1), import_zod35.z.literal(false)]).optional(),
20636
- identity: import_zod35.z.union([import_zod35.z.string().min(1), import_zod35.z.literal(false)]).optional()
20864
+ var ConfigRuleSetInputSchema = import_zod36.z.strictObject({
20865
+ path: import_zod36.z.string().min(1),
20866
+ configProfile: import_zod36.z.union([import_zod36.z.string().min(1), import_zod36.z.literal(false)]).optional(),
20867
+ identity: import_zod36.z.union([import_zod36.z.string().min(1), import_zod36.z.literal(false)]).optional()
20637
20868
  });
20638
20869
  var ConfigRuleSetOutputSchema = storedMutationOutput("rule", "updated", DirectoryRuleSchema);
20639
- var ConfigRuleRemoveInputSchema = import_zod35.z.strictObject({ path: import_zod35.z.string().min(1), confirm: RemovalConfirmationSchema });
20870
+ var ConfigRuleRemoveInputSchema = import_zod36.z.strictObject({ path: import_zod36.z.string().min(1), confirm: RemovalConfirmationSchema });
20640
20871
  var ConfigRuleRemoveOutputSchema = mutationOutput("rule", "removed");
20641
20872
 
20642
20873
  // src/frontdoor/configApi.ts
@@ -20988,51 +21219,51 @@ var import_openapi4 = require("@orpc/openapi");
20988
21219
  var import_server3 = require("@orpc/server");
20989
21220
 
20990
21221
  // src/frontdoor/eventSchemas.ts
20991
- var import_zod36 = require("zod");
21222
+ var import_zod37 = require("zod");
20992
21223
  init_schema2();
20993
21224
  var DOOR_EVENT_SOURCE_RC = "rc";
20994
21225
  var LAUNCH_EVENT_SOURCE = "launch";
20995
21226
  var USAGE_EVENT_SOURCE = "usage";
20996
21227
  var DOOR_HEALTH_EVENT_SOURCE = "door";
20997
21228
  var QUOTA_EXPIRING_EVENT_SOURCE = "quota-expiring";
20998
- var DoorEventSchema = import_zod36.z.strictObject({
20999
- source: import_zod36.z.string().min(1),
21229
+ var DoorEventSchema = import_zod37.z.strictObject({
21230
+ source: import_zod37.z.string().min(1),
21000
21231
  /** A positive integer because the backbone's counters start at one and only ever increase. */
21001
- sequence: import_zod36.z.number().int().positive(),
21002
- payload: import_zod36.z.unknown()
21232
+ sequence: import_zod37.z.number().int().positive(),
21233
+ payload: import_zod37.z.unknown()
21003
21234
  });
21004
- var DoorEventSourceQuerySchema = import_zod36.z.strictObject({
21005
- sources: import_zod36.z.array(import_zod36.z.string().min(1)).min(1).optional()
21235
+ var DoorEventSourceQuerySchema = import_zod37.z.strictObject({
21236
+ sources: import_zod37.z.array(import_zod37.z.string().min(1)).min(1).optional()
21006
21237
  });
21007
- var LaunchLifecycleEventSchema = import_zod36.z.strictObject({
21008
- kind: import_zod36.z.enum(["registered", "pruned", "ended"]),
21009
- pid: import_zod36.z.number().int().positive(),
21010
- startedAt: import_zod36.z.number(),
21011
- observedAt: import_zod36.z.number()
21238
+ var LaunchLifecycleEventSchema = import_zod37.z.strictObject({
21239
+ kind: import_zod37.z.enum(["registered", "pruned", "ended"]),
21240
+ pid: import_zod37.z.number().int().positive(),
21241
+ startedAt: import_zod37.z.number(),
21242
+ observedAt: import_zod37.z.number()
21012
21243
  });
21013
- var DoorHealthEventSchema = import_zod36.z.discriminatedUnion("kind", [
21014
- import_zod36.z.strictObject({ kind: import_zod36.z.literal("generation"), pid: import_zod36.z.number().int().positive(), providerPort: import_zod36.z.number().int().positive(), connectPort: import_zod36.z.number().int().positive(), directPort: import_zod36.z.number().int().positive(), observedAt: import_zod36.z.number() }),
21015
- import_zod36.z.strictObject({ kind: import_zod36.z.literal("listenerFailed"), pid: import_zod36.z.number().int().positive(), listener: import_zod36.z.enum(["provider", "connect", "direct"]), message: import_zod36.z.string(), observedAt: import_zod36.z.number() }),
21016
- import_zod36.z.strictObject({ kind: import_zod36.z.literal("binaryTurnover"), pid: import_zod36.z.number().int().positive(), observedAt: import_zod36.z.number() }),
21017
- import_zod36.z.strictObject({ kind: import_zod36.z.literal("idleShutdown"), pid: import_zod36.z.number().int().positive(), observedAt: import_zod36.z.number() }),
21018
- import_zod36.z.strictObject({ kind: import_zod36.z.literal("superseded"), pid: import_zod36.z.number().int().positive(), ownerPid: import_zod36.z.number().int().positive(), observedAt: import_zod36.z.number() }),
21019
- import_zod36.z.strictObject({ kind: import_zod36.z.literal("drained"), pid: import_zod36.z.number().int().positive(), observedAt: import_zod36.z.number() })
21244
+ var DoorHealthEventSchema = import_zod37.z.discriminatedUnion("kind", [
21245
+ import_zod37.z.strictObject({ kind: import_zod37.z.literal("generation"), pid: import_zod37.z.number().int().positive(), providerPort: import_zod37.z.number().int().positive(), connectPort: import_zod37.z.number().int().positive(), directPort: import_zod37.z.number().int().positive(), observedAt: import_zod37.z.number() }),
21246
+ import_zod37.z.strictObject({ kind: import_zod37.z.literal("listenerFailed"), pid: import_zod37.z.number().int().positive(), listener: import_zod37.z.enum(["provider", "connect", "direct"]), message: import_zod37.z.string(), observedAt: import_zod37.z.number() }),
21247
+ import_zod37.z.strictObject({ kind: import_zod37.z.literal("binaryTurnover"), pid: import_zod37.z.number().int().positive(), observedAt: import_zod37.z.number() }),
21248
+ import_zod37.z.strictObject({ kind: import_zod37.z.literal("idleShutdown"), pid: import_zod37.z.number().int().positive(), observedAt: import_zod37.z.number() }),
21249
+ import_zod37.z.strictObject({ kind: import_zod37.z.literal("superseded"), pid: import_zod37.z.number().int().positive(), ownerPid: import_zod37.z.number().int().positive(), observedAt: import_zod37.z.number() }),
21250
+ import_zod37.z.strictObject({ kind: import_zod37.z.literal("drained"), pid: import_zod37.z.number().int().positive(), observedAt: import_zod37.z.number() })
21020
21251
  ]);
21021
- var QuotaExpiringEventSchema = import_zod36.z.strictObject({
21252
+ var QuotaExpiringEventSchema = import_zod37.z.strictObject({
21022
21253
  /** The id of the identity whose window it is: what its usage is filed under, which a rename keeps. */
21023
- id: import_zod36.z.string().min(1),
21254
+ id: import_zod37.z.string().min(1),
21024
21255
  /** The identity's name when the event was published, absent for an identity no longer stored under the id. */
21025
- name: import_zod36.z.string().min(1).optional(),
21026
- provider: import_zod36.z.string().min(1),
21027
- window: import_zod36.z.enum(["fiveHour", "sevenDay"]),
21256
+ name: import_zod37.z.string().min(1).optional(),
21257
+ provider: import_zod37.z.string().min(1),
21258
+ window: import_zod37.z.enum(["fiveHour", "sevenDay"]),
21028
21259
  /** The fraction of the window already used when it was seen expiring, always below one because a fully used window has nothing left to spend. */
21029
- utilization: import_zod36.z.number().min(0).max(1),
21030
- resetsAt: import_zod36.z.iso.datetime(),
21031
- observedAt: import_zod36.z.number()
21260
+ utilization: import_zod37.z.number().min(0).max(1),
21261
+ resetsAt: import_zod37.z.iso.datetime(),
21262
+ observedAt: import_zod37.z.number()
21032
21263
  });
21033
21264
  var UsageChangeEventSchema = UsageSnapshotSchema.extend({
21034
- id: import_zod36.z.string().min(1),
21035
- name: import_zod36.z.string().min(1).optional()
21265
+ id: import_zod37.z.string().min(1),
21266
+ name: import_zod37.z.string().min(1).optional()
21036
21267
  });
21037
21268
 
21038
21269
  // src/frontdoor/eventsApi.ts
@@ -21076,7 +21307,7 @@ function createEventsApiRouter(deps) {
21076
21307
  // src/frontdoor/lifecycleApi.ts
21077
21308
  var import_client4 = require("@orpc/client");
21078
21309
  var import_openapi5 = require("@orpc/openapi");
21079
- var import_zod37 = require("zod");
21310
+ var import_zod38 = require("zod");
21080
21311
  init_update();
21081
21312
  var FRONTDOOR_API_TAG = "frontdoor";
21082
21313
  var UPDATE_API_TAG = "update";
@@ -21084,7 +21315,7 @@ function createLifecycleApiRouter(deps) {
21084
21315
  const authed = doorApiAuth(deps.expectedToken);
21085
21316
  return {
21086
21317
  frontdoor: {
21087
- refreshCatalogues: authed.meta((0, import_openapi5.openapi)({ method: "POST", path: "/rest/frontdoor/catalogues/refresh", summary: "Request a catalogue refresh tick", tags: [FRONTDOOR_API_TAG] })).output(import_zod37.z.strictObject({ requested: import_zod37.z.literal(true) })).handler(() => {
21318
+ refreshCatalogues: authed.meta((0, import_openapi5.openapi)({ method: "POST", path: "/rest/frontdoor/catalogues/refresh", summary: "Request a catalogue refresh tick", tags: [FRONTDOOR_API_TAG] })).output(import_zod38.z.strictObject({ requested: import_zod38.z.literal(true) })).handler(() => {
21088
21319
  deps.refreshCatalogues();
21089
21320
  return { requested: true };
21090
21321
  }),
@@ -21121,61 +21352,62 @@ init_cliError();
21121
21352
 
21122
21353
  // src/frontdoor/launchSchemas.ts
21123
21354
  var import_node_path43 = __toESM(require("node:path"), 1);
21124
- var import_zod38 = require("zod");
21355
+ var import_zod39 = require("zod");
21125
21356
  init_statusline();
21126
21357
  init_claudeVersion();
21127
21358
  init_identity();
21128
- var LaunchResolveInputSchema = import_zod38.z.strictObject({
21129
- path: import_zod38.z.string().min(1),
21359
+ var LaunchResolveInputSchema = import_zod39.z.strictObject({
21360
+ path: import_zod39.z.string().min(1),
21130
21361
  /** `@name`, launch flags, then the arguments for `claude`; empty for a bare launch. */
21131
- argv: import_zod38.z.readonly(import_zod38.z.array(import_zod38.z.string())).optional(),
21362
+ argv: import_zod39.z.readonly(import_zod39.z.array(import_zod39.z.string())).optional(),
21132
21363
  /** The launch's inherited environment. Absent means an empty one: the door's own environment is never a substitute for the caller's, so a caller that wants `AGENT_SHIM_*` switches or a `CLAUDE_CONFIG_DIR` considered names them here. Values are read, never reported. */
21133
- env: import_zod38.z.record(import_zod38.z.string(), import_zod38.z.string()).optional()
21364
+ env: import_zod39.z.record(import_zod39.z.string(), import_zod39.z.string()).optional()
21134
21365
  }).refine((input) => import_node_path43.default.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
21135
- var LaunchPoolDecisionSchema = import_zod38.z.strictObject({
21136
- name: import_zod38.z.string(),
21137
- reasons: import_zod38.z.readonly(import_zod38.z.array(import_zod38.z.string())),
21138
- movedOff: import_zod38.z.strictObject({ identity: import_zod38.z.string(), reason: import_zod38.z.string() }).optional()
21366
+ var LaunchPoolDecisionSchema = import_zod39.z.strictObject({
21367
+ name: import_zod39.z.string(),
21368
+ reasons: import_zod39.z.readonly(import_zod39.z.array(import_zod39.z.string())),
21369
+ movedOff: import_zod39.z.strictObject({ identity: import_zod39.z.string(), reason: import_zod39.z.string() }).optional()
21139
21370
  });
21140
- var LaunchDecisionSchema = import_zod38.z.strictObject({
21141
- identity: import_zod38.z.string().optional(),
21142
- identityId: import_zod38.z.string().optional(),
21143
- identitySource: import_zod38.z.enum(IDENTITY_DECISION_SOURCES),
21371
+ var LaunchDecisionSchema = import_zod39.z.strictObject({
21372
+ identity: import_zod39.z.string().optional(),
21373
+ identityId: import_zod39.z.string().optional(),
21374
+ identitySource: import_zod39.z.enum(IDENTITY_DECISION_SOURCES),
21144
21375
  pool: LaunchPoolDecisionSchema.optional(),
21145
- configDirEscapeHatch: import_zod38.z.boolean(),
21146
- configDir: import_zod38.z.string().optional(),
21147
- configProfile: import_zod38.z.string().optional(),
21148
- configProfileSource: import_zod38.z.enum(CONFIG_PROFILE_DECISION_SOURCES),
21149
- provider: import_zod38.z.string().optional()
21376
+ /** True when `CLAUDE_CONFIG_DIR` was already set and nothing on the command line named an identity; an identity named there outranks the variable and leaves it false. */
21377
+ configDirEscapeHatch: import_zod39.z.boolean(),
21378
+ configDir: import_zod39.z.string().optional(),
21379
+ configProfile: import_zod39.z.string().optional(),
21380
+ configProfileSource: import_zod39.z.enum(CONFIG_PROFILE_DECISION_SOURCES),
21381
+ provider: import_zod39.z.string().optional()
21150
21382
  });
21151
- var LaunchFlagsSchema = import_zod38.z.strictObject({
21152
- skipPermissions: import_zod38.z.boolean(),
21153
- remoteControl: import_zod38.z.boolean(),
21154
- headroom: import_zod38.z.boolean(),
21155
- trackUsage: import_zod38.z.boolean(),
21156
- pause: import_zod38.z.boolean(),
21157
- explain: import_zod38.z.boolean(),
21383
+ var LaunchFlagsSchema = import_zod39.z.strictObject({
21384
+ skipPermissions: import_zod39.z.boolean(),
21385
+ remoteControl: import_zod39.z.boolean(),
21386
+ headroom: import_zod39.z.boolean(),
21387
+ trackUsage: import_zod39.z.boolean(),
21388
+ pause: import_zod39.z.boolean(),
21389
+ explain: import_zod39.z.boolean(),
21158
21390
  /** How long the launch waits after its own output before it starts claude, in milliseconds. */
21159
- delayMs: import_zod38.z.number(),
21391
+ delayMs: import_zod39.z.number(),
21160
21392
  /** The hosts the launch keeps off the front door by adding them to the child's `NO_PROXY`. */
21161
- proxyBypass: import_zod38.z.array(import_zod38.z.string()).readonly(),
21393
+ proxyBypass: import_zod39.z.array(import_zod39.z.string()).readonly(),
21162
21394
  /** How the session's built-in statusline looks, when the launch configures any of it. */
21163
21395
  statusline: StatuslineSchema.optional()
21164
21396
  });
21165
- var LaunchResolveOutputSchema = import_zod38.z.strictObject({
21397
+ var LaunchResolveOutputSchema = import_zod39.z.strictObject({
21166
21398
  decision: LaunchDecisionSchema,
21167
21399
  flags: LaunchFlagsSchema,
21168
- claudeVersion: import_zod38.z.strictObject({ version: import_zod38.z.string(), source: import_zod38.z.enum(CLAUDE_VERSION_SOURCES) }).optional(),
21400
+ claudeVersion: import_zod39.z.strictObject({ version: import_zod39.z.string(), source: import_zod39.z.enum(CLAUDE_VERSION_SOURCES) }).optional(),
21169
21401
  /** The real `claude` binary the launch would spawn, on the door's host. */
21170
- bin: import_zod38.z.string(),
21402
+ bin: import_zod39.z.string(),
21171
21403
  /** The arguments the launch would pass it: the tool's own flags, then `CLAUDE_EXTRA_FLAGS`, then the caller's own. */
21172
- args: import_zod38.z.readonly(import_zod38.z.array(import_zod38.z.string())),
21404
+ args: import_zod39.z.readonly(import_zod39.z.array(import_zod39.z.string())),
21173
21405
  /** The credential the launch would authenticate with, by target and source kinds. Absent when none applies. */
21174
- credential: import_zod38.z.strictObject({ subject: import_zod38.z.enum(["provider", "identity"]), name: import_zod38.z.string(), summary: CredentialSummarySchema }).optional(),
21175
- routing: import_zod38.z.strictObject({ frontDoor: import_zod38.z.boolean(), headroom: import_zod38.z.boolean() }),
21406
+ credential: import_zod39.z.strictObject({ subject: import_zod39.z.enum(["provider", "identity"]), name: import_zod39.z.string(), summary: CredentialSummarySchema }).optional(),
21407
+ routing: import_zod39.z.strictObject({ frontDoor: import_zod39.z.boolean(), headroom: import_zod39.z.boolean() }),
21176
21408
  /** The names of the environment variables the launch would set or unset, sorted. Values are not reported. */
21177
- environment: import_zod38.z.readonly(import_zod38.z.array(import_zod38.z.string())),
21178
- warnings: import_zod38.z.readonly(import_zod38.z.array(import_zod38.z.string()))
21409
+ environment: import_zod39.z.readonly(import_zod39.z.array(import_zod39.z.string())),
21410
+ warnings: import_zod39.z.readonly(import_zod39.z.array(import_zod39.z.string()))
21179
21411
  });
21180
21412
 
21181
21413
  // src/frontdoor/launchApi.ts
@@ -21211,22 +21443,22 @@ function createLaunchApiRouter(deps) {
21211
21443
  // src/frontdoor/agentTreesApi.ts
21212
21444
  var import_client6 = require("@orpc/client");
21213
21445
  var import_openapi7 = require("@orpc/openapi");
21214
- var import_zod39 = require("zod");
21446
+ var import_zod40 = require("zod");
21215
21447
  init_cliError();
21216
- var AgentTreesListInputSchema = import_zod39.z.strictObject({
21448
+ var AgentTreesListInputSchema = import_zod40.z.strictObject({
21217
21449
  /** Only this identity's sessions. */
21218
- identity: import_zod39.z.string().optional(),
21450
+ identity: import_zod40.z.string().optional(),
21219
21451
  /** Include sessions that spawned no agent and ran no workflow. */
21220
- all: import_zod39.z.boolean().optional()
21452
+ all: import_zod40.z.boolean().optional()
21221
21453
  });
21222
- var AgentTreesListOutputSchema = import_zod39.z.array(SessionSummarySchema);
21223
- var AgentTreesShowInputSchema = import_zod39.z.strictObject({
21454
+ var AgentTreesListOutputSchema = import_zod40.z.array(SessionSummarySchema);
21455
+ var AgentTreesShowInputSchema = import_zod40.z.strictObject({
21224
21456
  /** A session id, or an unambiguous prefix of one. */
21225
- session: import_zod39.z.string().min(1),
21457
+ session: import_zod40.z.string().min(1),
21226
21458
  /** Look only in this identity. */
21227
- identity: import_zod39.z.string().optional()
21459
+ identity: import_zod40.z.string().optional()
21228
21460
  });
21229
- var AgentTreesShowOutputSchema = import_zod39.z.strictObject({ identities: import_zod39.z.array(import_zod39.z.string()), ...MergedAgentTreeSchema.shape });
21461
+ var AgentTreesShowOutputSchema = import_zod40.z.strictObject({ identities: import_zod40.z.array(import_zod40.z.string()), ...MergedAgentTreeSchema.shape });
21230
21462
  function asBadRequest(error) {
21231
21463
  if (error instanceof CliError) {
21232
21464
  throw new import_client6.ORPCError("BAD_REQUEST", { message: error.message });
@@ -21273,22 +21505,397 @@ function createAgentTreesApiRouter(deps) {
21273
21505
  };
21274
21506
  }
21275
21507
 
21276
- // src/frontdoor/controlApi.ts
21277
- var USAGE_API_TAG = "usage";
21278
- var FRONTDOOR_API_TAG2 = "frontdoor";
21279
- var CHECK_API_TAG = "check";
21280
- var DOCTOR_API_TAG = "doctor";
21281
- var POOL_API_TAG = "pool";
21282
- function createControlApiRouter(deps) {
21283
- const authed = doorApiAuth(deps.expectedToken);
21284
- return {
21285
- usage: {
21286
- list: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/usage/snapshots", summary: "List every identity's usage snapshot", tags: [USAGE_API_TAG] })).output(UsageListOutputSchema).handler(() => ({ snapshots: deps.usageSnapshots() })),
21287
- resets: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/usage/resets", summary: "List every recorded quota window with when it resets", tags: [USAGE_API_TAG] })).output(ResetScheduleSchema).handler(() => collectResets(deps.usageSnapshots(), deps.now())),
21288
- effectiveWindow: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/usage/windows", summary: "Read one identity's effective quota windows", tags: [USAGE_API_TAG] })).input(UsageWindowsInputSchema).output(UsageWindowsOutputSchema).handler(({ input }) => {
21289
- const snapshot = deps.usageSnapshotOf(input.identity);
21290
- if (snapshot === void 0) {
21291
- throw new import_client7.ORPCError("NOT_FOUND", { message: `identity ${input.identity} has no usage snapshot yet, so no quota window has been observed for it` });
21508
+ // src/frontdoor/rcEventLogApi.ts
21509
+ var import_client7 = require("@orpc/client");
21510
+ var import_openapi8 = require("@orpc/openapi");
21511
+ var import_server4 = require("@orpc/server");
21512
+
21513
+ // src/frontdoor/rcEventLog.ts
21514
+ var import_zod41 = require("zod");
21515
+
21516
+ // src/frontdoor/eventHub.ts
21517
+ var DOOR_EVENT_BUFFER_EVENTS = 100;
21518
+ function createDoorEventHub() {
21519
+ const sequences = /* @__PURE__ */ new Map();
21520
+ const registered = /* @__PURE__ */ new Set();
21521
+ const every = /* @__PURE__ */ new Set();
21522
+ const bySource = /* @__PURE__ */ new Map();
21523
+ const deliver = (event) => {
21524
+ for (const listener of every) {
21525
+ listener(event);
21526
+ }
21527
+ for (const listener of bySource.get(event.source) ?? []) {
21528
+ listener(event);
21529
+ }
21530
+ };
21531
+ const publish = (source, payload) => {
21532
+ const sequence2 = (sequences.get(source) ?? 0) + 1;
21533
+ sequences.set(source, sequence2);
21534
+ deliver({ source, sequence: sequence2, payload });
21535
+ };
21536
+ const addListener = (sources, listener) => {
21537
+ if (sources === void 0) {
21538
+ every.add(listener);
21539
+ return () => {
21540
+ every.delete(listener);
21541
+ };
21542
+ }
21543
+ const listenersFor = (source) => {
21544
+ const listeners = bySource.get(source) ?? /* @__PURE__ */ new Set();
21545
+ bySource.set(source, listeners);
21546
+ return listeners;
21547
+ };
21548
+ const detachers = sources.map((source) => {
21549
+ const listeners = listenersFor(source);
21550
+ listeners.add(listener);
21551
+ return () => {
21552
+ listeners.delete(listener);
21553
+ if (listeners.size === 0) {
21554
+ bySource.delete(source);
21555
+ }
21556
+ };
21557
+ });
21558
+ return () => {
21559
+ for (const detach of detachers) {
21560
+ detach();
21561
+ }
21562
+ };
21563
+ };
21564
+ return {
21565
+ publisher: (source) => {
21566
+ registered.add(source);
21567
+ return {
21568
+ source,
21569
+ publish: (payload) => {
21570
+ publish(source, payload);
21571
+ }
21572
+ };
21573
+ },
21574
+ subscribe: addListener,
21575
+ stream: (sources) => {
21576
+ const queue = [];
21577
+ let wake;
21578
+ let closed = false;
21579
+ const detach = addListener(sources, (event) => {
21580
+ if (queue.length >= DOOR_EVENT_BUFFER_EVENTS) {
21581
+ queue.shift();
21582
+ }
21583
+ queue.push(event);
21584
+ wake?.();
21585
+ });
21586
+ return {
21587
+ next: async () => {
21588
+ for (; ; ) {
21589
+ const event = queue.shift();
21590
+ if (event !== void 0) {
21591
+ return { value: event, done: false };
21592
+ }
21593
+ if (closed) {
21594
+ return { value: void 0, done: true };
21595
+ }
21596
+ await new Promise((resolve) => {
21597
+ wake = resolve;
21598
+ });
21599
+ }
21600
+ },
21601
+ close: () => {
21602
+ closed = true;
21603
+ detach();
21604
+ wake?.();
21605
+ }
21606
+ };
21607
+ },
21608
+ sources: () => [...registered].sort()
21609
+ };
21610
+ }
21611
+ function rcFanoutOnDoorHub(fanout, hub) {
21612
+ const publisher = hub.publisher(DOOR_EVENT_SOURCE_RC);
21613
+ return {
21614
+ publish: (event) => {
21615
+ fanout.publish(event);
21616
+ publisher.publish(event);
21617
+ },
21618
+ subscribe: (session, listener) => fanout.subscribe(session, listener)
21619
+ };
21620
+ }
21621
+
21622
+ // src/frontdoor/rcEventLog.ts
21623
+ var RC_SESSION_EVENT_TOKEN_MAX_CHARS = 255;
21624
+ var HIGH_SURROGATE_FIRST = 55296;
21625
+ var HIGH_SURROGATE_LAST = 56319;
21626
+ var LOW_SURROGATE_FIRST = 56320;
21627
+ var LOW_SURROGATE_LAST = 57343;
21628
+ var CUT_MARKER = "...";
21629
+ var RC_SESSION_EVENT_SUMMARY_MAX_CHARS = RC_SESSION_EVENT_TOKEN_MAX_CHARS + " ".length + RC_PENDING_SUMMARY_EXCERPT_CHARS + CUT_MARKER.length;
21630
+ var RC_SESSION_EVENT_GENERATION_MAX_CHARS = "00000000-0000-4000-8000-000000000000".length;
21631
+ var SEQUENCE_MAX_DIGITS = String(Number.MAX_SAFE_INTEGER).length;
21632
+ var NUMBER_BYTES = Float64Array.BYTES_PER_ELEMENT;
21633
+ var NUMBER_FIELDS = ["at", "sequence"].length;
21634
+ var BYTES_PER_CODE_UNIT = Uint16Array.BYTES_PER_ELEMENT;
21635
+ var RC_SESSION_END_REASONS = ["expired", "archived", "conflict"];
21636
+ var RC_PENDING_RETIRE_REASONS = ["answered", "expired", "session-ended"];
21637
+ var transitionBase = { session: import_zod41.z.string(), at: import_zod41.z.number() };
21638
+ var cursorFields = { cursor: import_zod41.z.string(), sequence: import_zod41.z.int().positive() };
21639
+ var sessionAppearedShape = { kind: import_zod41.z.literal("session-appeared"), ...transitionBase };
21640
+ var sessionEndedShape = { kind: import_zod41.z.literal("session-ended"), reason: import_zod41.z.enum(RC_SESSION_END_REASONS), ...transitionBase };
21641
+ var workerStateShape = { kind: import_zod41.z.literal("worker-state"), state: import_zod41.z.string(), previous: import_zod41.z.string().optional(), ...transitionBase };
21642
+ var pendingBornShape = { kind: import_zod41.z.literal("pending-born"), requestId: import_zod41.z.string(), type: import_zod41.z.string(), summary: import_zod41.z.string(), ...transitionBase };
21643
+ var pendingRetiredShape = { kind: import_zod41.z.literal("pending-retired"), requestId: import_zod41.z.string(), reason: import_zod41.z.enum(RC_PENDING_RETIRE_REASONS), ...transitionBase };
21644
+ var RcSessionTransitionSchema = import_zod41.z.discriminatedUnion("kind", [
21645
+ import_zod41.z.strictObject(sessionAppearedShape),
21646
+ import_zod41.z.strictObject(sessionEndedShape),
21647
+ import_zod41.z.strictObject(workerStateShape),
21648
+ import_zod41.z.strictObject(pendingBornShape),
21649
+ import_zod41.z.strictObject(pendingRetiredShape)
21650
+ ]);
21651
+ var KIND_MAX_CHARS = Math.max(...RcSessionTransitionSchema.options.map((option) => option.shape.kind.value.length));
21652
+ var RC_SESSION_EVENT_MAX_BYTES = (RC_SESSION_EVENT_GENERATION_MAX_CHARS + ".".length + SEQUENCE_MAX_DIGITS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + KIND_MAX_CHARS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + RC_SESSION_EVENT_TOKEN_MAX_CHARS + RC_SESSION_EVENT_SUMMARY_MAX_CHARS) * BYTES_PER_CODE_UNIT + NUMBER_FIELDS * NUMBER_BYTES;
21653
+ var RC_SESSION_EVENT_LOG_CAPACITY = Math.floor(CONTROL_BODY_CAP_BYTES / RC_SESSION_EVENT_MAX_BYTES);
21654
+ var RcSessionEventSchema = import_zod41.z.discriminatedUnion("kind", [
21655
+ import_zod41.z.strictObject({ ...cursorFields, ...sessionAppearedShape }),
21656
+ import_zod41.z.strictObject({ ...cursorFields, ...sessionEndedShape }),
21657
+ import_zod41.z.strictObject({ ...cursorFields, ...workerStateShape }),
21658
+ import_zod41.z.strictObject({ ...cursorFields, ...pendingBornShape }),
21659
+ import_zod41.z.strictObject({ ...cursorFields, ...pendingRetiredShape })
21660
+ ]);
21661
+ var RcSessionEventsReadInputSchema = import_zod41.z.strictObject({
21662
+ /** The cursor of the last event the caller saw; every retained event when omitted. */
21663
+ since: import_zod41.z.string().min(1).optional(),
21664
+ /** One `cse_` session id; every session when omitted. */
21665
+ session: import_zod41.z.string().min(1).optional(),
21666
+ /** The most events one answer carries; every event after `since` when omitted. */
21667
+ limit: import_zod41.z.int().positive().optional()
21668
+ });
21669
+ var RcSessionEventsPageInputSchema = RcSessionEventsReadInputSchema.extend({
21670
+ /** The most events this page carries: by default and at most, the bound the door's event backbone already holds per slow consumer (`DOOR_EVENT_BUFFER_EVENTS`, oRPC's own documented default for that case). A page lands whole in its reader, so a reader receives at most one consumer buffer's worth at a time (at worst `DOOR_EVENT_BUFFER_EVENTS` times `RC_SESSION_EVENT_MAX_BYTES`) and pages on with the cursor for more; a maximum of the whole window would let one page carry the log's entire memory budget into an agent's context. */
21671
+ limit: import_zod41.z.int().positive().max(DOOR_EVENT_BUFFER_EVENTS).default(DOOR_EVENT_BUFFER_EVENTS)
21672
+ });
21673
+ var RcSessionEventsStreamInputSchema = RcSessionEventsReadInputSchema.omit({ limit: true });
21674
+ var RcSessionEventsReadOutputSchema = import_zod41.z.discriminatedUnion("status", [
21675
+ import_zod41.z.strictObject({ status: import_zod41.z.literal("ok"), events: import_zod41.z.readonly(import_zod41.z.array(RcSessionEventSchema)), cursor: import_zod41.z.string(), more: import_zod41.z.boolean(), head: import_zod41.z.string() }),
21676
+ import_zod41.z.strictObject({ status: import_zod41.z.literal("expired"), message: import_zod41.z.string(), head: import_zod41.z.string() })
21677
+ ]);
21678
+ var CURSOR_SEPARATOR = ".";
21679
+ var RESYNC_ADVICE = "cursor expired, resync from status: read `rc status` for every session's present state, then resume after the head this answer names";
21680
+ function cursorOf(generation, sequence2) {
21681
+ return `${generation}${CURSOR_SEPARATOR}${String(sequence2)}`;
21682
+ }
21683
+ function parseCursor(cursor) {
21684
+ const at = cursor.lastIndexOf(CURSOR_SEPARATOR);
21685
+ if (at <= 0) {
21686
+ return void 0;
21687
+ }
21688
+ const digits = cursor.slice(at + 1);
21689
+ if (!/^[0-9]+$/.test(digits)) {
21690
+ return void 0;
21691
+ }
21692
+ return { generation: cursor.slice(0, at), sequence: Number(digits) };
21693
+ }
21694
+ function codePointBoundary(text, at) {
21695
+ const before = text.charCodeAt(at - 1);
21696
+ const after = text.charCodeAt(at);
21697
+ const isHigh = before >= HIGH_SURROGATE_FIRST && before <= HIGH_SURROGATE_LAST;
21698
+ const isLow = after >= LOW_SURROGATE_FIRST && after <= LOW_SURROGATE_LAST;
21699
+ return isHigh && isLow ? at - 1 : at;
21700
+ }
21701
+ function bounded2(text, maxChars) {
21702
+ const kept = text.length <= maxChars ? text : `${text.slice(0, codePointBoundary(text, maxChars - CUT_MARKER.length))}${CUT_MARKER}`;
21703
+ return Buffer.from(kept, "utf16le").toString("utf16le");
21704
+ }
21705
+ function boundedTransition(transition) {
21706
+ const session = bounded2(transition.session, RC_SESSION_EVENT_TOKEN_MAX_CHARS);
21707
+ if (transition.kind === "worker-state") {
21708
+ return { ...transition, session, state: bounded2(transition.state, RC_SESSION_EVENT_TOKEN_MAX_CHARS), ...transition.previous === void 0 ? {} : { previous: bounded2(transition.previous, RC_SESSION_EVENT_TOKEN_MAX_CHARS) } };
21709
+ }
21710
+ if (transition.kind === "pending-born") {
21711
+ return { ...transition, session, requestId: bounded2(transition.requestId, RC_SESSION_EVENT_TOKEN_MAX_CHARS), type: bounded2(transition.type, RC_SESSION_EVENT_TOKEN_MAX_CHARS), summary: bounded2(transition.summary, RC_SESSION_EVENT_SUMMARY_MAX_CHARS) };
21712
+ }
21713
+ if (transition.kind === "pending-retired") {
21714
+ return { ...transition, session, requestId: bounded2(transition.requestId, RC_SESSION_EVENT_TOKEN_MAX_CHARS) };
21715
+ }
21716
+ return { ...transition, session };
21717
+ }
21718
+ function createRcSessionEventLog(deps) {
21719
+ if (deps.generation.includes(CURSOR_SEPARATOR)) {
21720
+ throw new Error(`a door generation id must not contain "${CURSOR_SEPARATOR}", which separates a cursor's generation from its sequence`);
21721
+ }
21722
+ if (deps.generation.length > RC_SESSION_EVENT_GENERATION_MAX_CHARS) {
21723
+ throw new Error(`a door generation id must be at most ${String(RC_SESSION_EVENT_GENERATION_MAX_CHARS)} characters, a UUID's length`);
21724
+ }
21725
+ const events = [];
21726
+ let lastSequence = 0;
21727
+ const listeners = /* @__PURE__ */ new Set();
21728
+ let isClosed = false;
21729
+ const expired = (reason) => ({ status: "expired", message: `${reason}; ${RESYNC_ADVICE}`, head: cursorOf(deps.generation, lastSequence) });
21730
+ return {
21731
+ append: (transition) => {
21732
+ lastSequence += 1;
21733
+ events.push({ ...boundedTransition(transition), cursor: cursorOf(deps.generation, lastSequence), sequence: lastSequence });
21734
+ if (events.length > deps.capacity) {
21735
+ events.splice(0, events.length - deps.capacity);
21736
+ }
21737
+ for (const listener of listeners) {
21738
+ listener();
21739
+ }
21740
+ },
21741
+ head: () => cursorOf(deps.generation, lastSequence),
21742
+ read: ({ since, session, limit }) => {
21743
+ let after = 0;
21744
+ if (since !== void 0) {
21745
+ const parsed = parseCursor(since);
21746
+ if (parsed === void 0) {
21747
+ return expired(`"${since}" is not a cursor this door issues`);
21748
+ }
21749
+ if (parsed.generation !== deps.generation) {
21750
+ return expired(`the cursor "${since}" was issued by another generation of the front door, whose events this one never held`);
21751
+ }
21752
+ if (parsed.sequence > lastSequence) {
21753
+ return expired(`the cursor "${since}" names an event past this door's newest`);
21754
+ }
21755
+ const oldest = events[0]?.sequence ?? lastSequence + 1;
21756
+ if (parsed.sequence < oldest - 1) {
21757
+ return expired(`the events after "${since}" have been evicted (the log retains the newest ${String(deps.capacity)} and the oldest it still holds is "${cursorOf(deps.generation, oldest)}")`);
21758
+ }
21759
+ after = parsed.sequence;
21760
+ }
21761
+ const selected2 = [];
21762
+ let cursor = cursorOf(deps.generation, lastSequence);
21763
+ let more = false;
21764
+ for (const event of events) {
21765
+ if (event.sequence <= after || session !== void 0 && event.session !== session) {
21766
+ continue;
21767
+ }
21768
+ if (limit !== void 0 && selected2.length === limit) {
21769
+ more = true;
21770
+ cursor = selected2.at(-1)?.cursor ?? cursor;
21771
+ break;
21772
+ }
21773
+ selected2.push(event);
21774
+ }
21775
+ return { status: "ok", events: selected2, cursor, more, head: cursorOf(deps.generation, lastSequence) };
21776
+ },
21777
+ onAppend: (listener) => {
21778
+ listeners.add(listener);
21779
+ return () => {
21780
+ listeners.delete(listener);
21781
+ };
21782
+ },
21783
+ close: () => {
21784
+ if (isClosed) {
21785
+ return;
21786
+ }
21787
+ isClosed = true;
21788
+ for (const listener of listeners) {
21789
+ listener();
21790
+ }
21791
+ },
21792
+ closed: () => isClosed
21793
+ };
21794
+ }
21795
+ var RcSessionEventCursorExpiredError = class extends Error {
21796
+ /** The cursor naming the log's newest event at the moment of the refusal: where to resume after once the status read has restated the present. */
21797
+ head;
21798
+ constructor(message, head) {
21799
+ super(message);
21800
+ this.name = "RcSessionEventCursorExpiredError";
21801
+ this.head = head;
21802
+ }
21803
+ };
21804
+ function followRcSessionEvents(log, input, signal) {
21805
+ return followAfter(log, input.since ?? log.head(), input.session, signal);
21806
+ }
21807
+ async function* followAfter(log, since, session, signal) {
21808
+ let cursor = since;
21809
+ let onAbort = () => void 0;
21810
+ const aborted = new Promise((resolve) => {
21811
+ onAbort = resolve;
21812
+ });
21813
+ signal?.addEventListener("abort", onAbort, { once: true });
21814
+ try {
21815
+ for (; ; ) {
21816
+ signal?.throwIfAborted();
21817
+ const closedBeforeRead = log.closed();
21818
+ let detach = () => void 0;
21819
+ const woken = new Promise((resolve) => {
21820
+ detach = log.onAppend(resolve);
21821
+ });
21822
+ try {
21823
+ const read = log.read({ since: cursor, ...session === void 0 ? {} : { session } });
21824
+ if (read.status === "expired") {
21825
+ throw new RcSessionEventCursorExpiredError(read.message, read.head);
21826
+ }
21827
+ if (read.events.length === 0) {
21828
+ cursor = read.cursor;
21829
+ if (closedBeforeRead) {
21830
+ return;
21831
+ }
21832
+ await Promise.race([woken, aborted]);
21833
+ continue;
21834
+ }
21835
+ for (const event of read.events) {
21836
+ yield event;
21837
+ cursor = event.cursor;
21838
+ }
21839
+ cursor = read.cursor;
21840
+ } finally {
21841
+ detach();
21842
+ }
21843
+ }
21844
+ } finally {
21845
+ signal?.removeEventListener("abort", onAbort);
21846
+ }
21847
+ }
21848
+
21849
+ // src/frontdoor/rcEventLogApi.ts
21850
+ var RC_API_TAG2 = "remote-control";
21851
+ var CURSOR_EXPIRED_CODE = "GONE";
21852
+ async function* sseOf(follower) {
21853
+ try {
21854
+ for await (const event of follower) {
21855
+ yield (0, import_server4.withEventMeta)(event, { id: event.cursor });
21856
+ }
21857
+ } catch (error) {
21858
+ if (error instanceof RcSessionEventCursorExpiredError) {
21859
+ throw new import_client7.ORPCError(CURSOR_EXPIRED_CODE, { message: error.message, data: { head: error.head } });
21860
+ }
21861
+ throw error;
21862
+ }
21863
+ }
21864
+ function createRcSessionEventsApiRouter(deps) {
21865
+ const authed = doorApiAuth(deps.expectedToken);
21866
+ return {
21867
+ rcSessions: {
21868
+ events: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/rc/session-events", summary: "Stream every observed session's state transitions, pending requests and endings (SSE), resumable by cursor", tags: [RC_API_TAG2] })).input(RcSessionEventsStreamInputSchema).output((0, import_server4.eventIterator)(RcSessionEventSchema)).handler(({ input, signal, lastEventId }) => sseOf(followRcSessionEvents(deps.sessionEvents, { since: lastEventId ?? input.since, session: input.session }, signal))),
21869
+ eventsPage: authed.meta(
21870
+ (0, import_openapi8.openapi)({
21871
+ method: "POST",
21872
+ path: "/rest/rc/session-events/page",
21873
+ summary: "Read every observed session's state transitions, pending requests and endings after a cursor, one page at a time",
21874
+ tags: [RC_API_TAG2],
21875
+ // A POST because the page size is a number a query string cannot type, but the answer changes nothing.
21876
+ spec: (current) => ({ ...current, [READ_ONLY_OPERATION_EXTENSION]: true })
21877
+ })
21878
+ ).input(RcSessionEventsPageInputSchema).output(RcSessionEventsReadOutputSchema).handler(({ input }) => deps.sessionEvents.read(input))
21879
+ }
21880
+ };
21881
+ }
21882
+
21883
+ // src/frontdoor/controlApi.ts
21884
+ var USAGE_API_TAG = "usage";
21885
+ var FRONTDOOR_API_TAG2 = "frontdoor";
21886
+ var CHECK_API_TAG = "check";
21887
+ var DOCTOR_API_TAG = "doctor";
21888
+ var POOL_API_TAG = "pool";
21889
+ function createControlApiRouter(deps) {
21890
+ const authed = doorApiAuth(deps.expectedToken);
21891
+ return {
21892
+ usage: {
21893
+ list: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/usage/snapshots", summary: "List every identity's usage snapshot", tags: [USAGE_API_TAG] })).output(UsageListOutputSchema).handler(() => ({ snapshots: deps.usageSnapshots() })),
21894
+ resets: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/usage/resets", summary: "List every recorded quota window with when it resets", tags: [USAGE_API_TAG] })).output(ResetScheduleSchema).handler(() => collectResets(deps.usageSnapshots(), deps.now())),
21895
+ effectiveWindow: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/usage/windows", summary: "Read one identity's effective quota windows", tags: [USAGE_API_TAG] })).input(UsageWindowsInputSchema).output(UsageWindowsOutputSchema).handler(({ input }) => {
21896
+ const snapshot = deps.usageSnapshotOf(input.identity);
21897
+ if (snapshot === void 0) {
21898
+ throw new import_client8.ORPCError("NOT_FOUND", { message: `identity ${input.identity} has no usage snapshot yet, so no quota window has been observed for it` });
21292
21899
  }
21293
21900
  const provider = input.provider ?? ANTHROPIC_PROVIDER;
21294
21901
  const rateLimit = snapshot.providers[provider]?.rateLimit;
@@ -21302,34 +21909,34 @@ function createControlApiRouter(deps) {
21302
21909
  ...unified?.sevenDay === void 0 ? {} : { sevenDay: effectiveWindow(unified.sevenDay, now) }
21303
21910
  };
21304
21911
  }),
21305
- live: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/usage/live", summary: "Read the live rate-limit observations the event backbone files", tags: [USAGE_API_TAG] })).input(RcSessionQuerySchema).output(UsageLiveOutputSchema).handler(({ input }) => {
21912
+ live: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/usage/live", summary: "Read the live rate-limit observations the event backbone files", tags: [USAGE_API_TAG] })).input(RcSessionQuerySchema).output(UsageLiveOutputSchema).handler(({ input }) => {
21306
21913
  const sessions = deps.liveRateLimits(input.session);
21307
21914
  if (input.session !== void 0 && sessions.length === 0) {
21308
21915
  if (deps.list().some((session) => session.id === input.session)) {
21309
- throw new import_client7.ORPCError("NOT_FOUND", { message: `session ${input.session} has filed no rate_limit_event on its stream yet: the worker emits one only once a turn has completed, so retry after this session's next turn` });
21916
+ throw new import_client8.ORPCError("NOT_FOUND", { message: `session ${input.session} has filed no rate_limit_event on its stream yet: the worker emits one only once a turn has completed, so retry after this session's next turn` });
21310
21917
  }
21311
- throw new import_client7.ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input.session) });
21918
+ throw new import_client8.ORPCError("NOT_FOUND", { message: rcSessionNotObservedMessage(input.session) });
21312
21919
  }
21313
21920
  return { latest: deps.latestRateLimit(), sessions };
21314
21921
  })
21315
21922
  },
21316
21923
  frontdoor: {
21317
- status: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/frontdoor/status", summary: "Read the front door's status", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorStatusOutputSchema).handler(() => deps.frontDoorStatus()),
21318
- sessions: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/frontdoor/sessions", summary: "Read the front door's session registry", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorSessionsOutputSchema).handler(() => ({ sessions: deps.frontDoorStatus().sessions }))
21924
+ status: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/frontdoor/status", summary: "Read the front door's status", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorStatusOutputSchema).handler(() => deps.frontDoorStatus()),
21925
+ sessions: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/frontdoor/sessions", summary: "Read the front door's session registry", tags: [FRONTDOOR_API_TAG2] })).output(FrontDoorSessionsOutputSchema).handler(() => ({ sessions: deps.frontDoorStatus().sessions }))
21319
21926
  },
21320
21927
  check: {
21321
21928
  // The report's own JSON shape is the contract (the same one `check --json` prints and `checkReportSchema.ts` defines), so the procedure returns exactly that conversion.
21322
- run: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/check", summary: "Run the check report for one directory", tags: [CHECK_API_TAG] })).input(CheckRunInputSchema).output(CheckReportJsonSchema).handler(({ input }) => checkReportToJson(deps.checkReport(input.path, input.identity)))
21929
+ run: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/check", summary: "Run the check report for one directory", tags: [CHECK_API_TAG] })).input(CheckRunInputSchema).output(CheckReportJsonSchema).handler(({ input }) => checkReportToJson(deps.checkReport(input.path, input.identity)))
21323
21930
  },
21324
21931
  doctor: {
21325
- run: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/doctor", summary: "Run the doctor report", tags: [DOCTOR_API_TAG] })).output(DoctorRunOutputSchema).handler(() => deps.doctorReport())
21932
+ run: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/doctor", summary: "Run the doctor report", tags: [DOCTOR_API_TAG] })).output(DoctorRunOutputSchema).handler(() => deps.doctorReport())
21326
21933
  },
21327
21934
  pool: {
21328
- pick: authed.meta((0, import_openapi8.openapi)({ method: "GET", path: "/rest/pool/pick", summary: "Rank one pool exactly as a launch from a directory would right now", tags: [POOL_API_TAG] })).input(PoolPickInputSchema).output(PoolPickReportSchema).handler(({ input }) => {
21935
+ pick: authed.meta((0, import_openapi9.openapi)({ method: "GET", path: "/rest/pool/pick", summary: "Rank one pool exactly as a launch from a directory would right now", tags: [POOL_API_TAG] })).input(PoolPickInputSchema).output(PoolPickReportSchema).handler(({ input }) => {
21329
21936
  const report = deps.poolPick(input.pool, input.path);
21330
21937
  if (report === void 0) {
21331
21938
  const live = deps.poolNames();
21332
- throw new import_client7.ORPCError("NOT_FOUND", {
21939
+ throw new import_client8.ORPCError("NOT_FOUND", {
21333
21940
  message: live.length === 0 ? `no pools are configured, so none is named ${input.pool}` : `no pool is named ${input.pool}; the live pools are ${live.map((name) => `"${name}"`).join(", ")}`
21334
21941
  });
21335
21942
  }
@@ -21341,13 +21948,13 @@ function createControlApiRouter(deps) {
21341
21948
  function createDoorApiRouter(deps) {
21342
21949
  const control = createControlApiRouter(deps);
21343
21950
  const lifecycle = createLifecycleApiRouter(deps);
21344
- return { ...createRcApiRouter(deps), ...control, ...lifecycle, ...createConfigApiRouter(deps), ...createCodexApiRouter(deps), ...createLaunchApiRouter(deps), ...createAgentTreesApiRouter(deps), ...createEventsApiRouter(deps), frontdoor: { ...control.frontdoor, ...lifecycle.frontdoor } };
21951
+ return { ...createRcApiRouter(deps), ...createRcSessionEventsApiRouter(deps), ...control, ...lifecycle, ...createConfigApiRouter(deps), ...createCodexApiRouter(deps), ...createLaunchApiRouter(deps), ...createAgentTreesApiRouter(deps), ...createEventsApiRouter(deps), frontdoor: { ...control.frontdoor, ...lifecycle.frontdoor } };
21345
21952
  }
21346
21953
  function createDoorApiNodeHandler(deps) {
21347
21954
  return doorApiNodeHandlerOf(createDoorApiRouter(deps), deps.expectedToken);
21348
21955
  }
21349
21956
  function frontDoorApiClient(port, ca, token) {
21350
- return (0, import_client7.createORPCClient)(frontDoorApiLink(port, ca, token));
21957
+ return (0, import_client8.createORPCClient)(frontDoorApiLink(port, ca, token));
21351
21958
  }
21352
21959
 
21353
21960
  // src/frontdoor/doorClient.ts
@@ -21447,112 +22054,6 @@ function formatFrontDoorStatus(status, caCertPath) {
21447
22054
  // src/index.ts
21448
22055
  init_state();
21449
22056
 
21450
- // src/frontdoor/eventHub.ts
21451
- var DOOR_EVENT_BUFFER_EVENTS = 100;
21452
- function createDoorEventHub() {
21453
- const sequences = /* @__PURE__ */ new Map();
21454
- const registered = /* @__PURE__ */ new Set();
21455
- const every = /* @__PURE__ */ new Set();
21456
- const bySource = /* @__PURE__ */ new Map();
21457
- const deliver = (event) => {
21458
- for (const listener of every) {
21459
- listener(event);
21460
- }
21461
- for (const listener of bySource.get(event.source) ?? []) {
21462
- listener(event);
21463
- }
21464
- };
21465
- const publish = (source, payload) => {
21466
- const sequence2 = (sequences.get(source) ?? 0) + 1;
21467
- sequences.set(source, sequence2);
21468
- deliver({ source, sequence: sequence2, payload });
21469
- };
21470
- const addListener = (sources, listener) => {
21471
- if (sources === void 0) {
21472
- every.add(listener);
21473
- return () => {
21474
- every.delete(listener);
21475
- };
21476
- }
21477
- const listenersFor = (source) => {
21478
- const listeners = bySource.get(source) ?? /* @__PURE__ */ new Set();
21479
- bySource.set(source, listeners);
21480
- return listeners;
21481
- };
21482
- const detachers = sources.map((source) => {
21483
- const listeners = listenersFor(source);
21484
- listeners.add(listener);
21485
- return () => {
21486
- listeners.delete(listener);
21487
- if (listeners.size === 0) {
21488
- bySource.delete(source);
21489
- }
21490
- };
21491
- });
21492
- return () => {
21493
- for (const detach of detachers) {
21494
- detach();
21495
- }
21496
- };
21497
- };
21498
- return {
21499
- publisher: (source) => {
21500
- registered.add(source);
21501
- return {
21502
- source,
21503
- publish: (payload) => {
21504
- publish(source, payload);
21505
- }
21506
- };
21507
- },
21508
- subscribe: addListener,
21509
- stream: (sources) => {
21510
- const queue = [];
21511
- let wake;
21512
- let closed = false;
21513
- const detach = addListener(sources, (event) => {
21514
- if (queue.length >= DOOR_EVENT_BUFFER_EVENTS) {
21515
- queue.shift();
21516
- }
21517
- queue.push(event);
21518
- wake?.();
21519
- });
21520
- return {
21521
- next: async () => {
21522
- for (; ; ) {
21523
- const event = queue.shift();
21524
- if (event !== void 0) {
21525
- return { value: event, done: false };
21526
- }
21527
- if (closed) {
21528
- return { value: void 0, done: true };
21529
- }
21530
- await new Promise((resolve) => {
21531
- wake = resolve;
21532
- });
21533
- }
21534
- },
21535
- close: () => {
21536
- closed = true;
21537
- detach();
21538
- wake?.();
21539
- }
21540
- };
21541
- },
21542
- sources: () => [...registered].sort()
21543
- };
21544
- }
21545
- function rcFanoutOnDoorHub(fanout, hub) {
21546
- const publisher = hub.publisher(DOOR_EVENT_SOURCE_RC);
21547
- return {
21548
- publish: (event) => {
21549
- fanout.publish(event);
21550
- publisher.publish(event);
21551
- },
21552
- subscribe: (session, listener) => fanout.subscribe(session, listener)
21553
- };
21554
- }
21555
-
21556
22057
  // src/frontdoor/launchEvents.ts
21557
22058
  function createLaunchEventPublisher(hub, now) {
21558
22059
  const publisher = hub.publisher(LAUNCH_EVENT_SOURCE);
@@ -23500,7 +24001,7 @@ init_poolPick();
23500
24001
 
23501
24002
  // src/agents/read.ts
23502
24003
  var import_node_path46 = __toESM(require("node:path"), 1);
23503
- var import_zod40 = require("zod");
24004
+ var import_zod42 = require("zod");
23504
24005
  var PROJECTS_DIR = "projects";
23505
24006
  var TASKS_DIR = "tasks";
23506
24007
  var SUBAGENTS_DIR = "subagents";
@@ -23619,14 +24120,14 @@ function parseJson2(text) {
23619
24120
  return void 0;
23620
24121
  }
23621
24122
  }
23622
- var TaskFileSchema = import_zod40.z.object({ ...TaskItemSchema.omit({ taskList: true }).shape, blocks: import_zod40.z.array(import_zod40.z.string()).default([]), blockedBy: import_zod40.z.array(import_zod40.z.string()).default([]) });
23623
- var WorkflowRunFileSchema = import_zod40.z.object({
23624
- runId: import_zod40.z.string(),
23625
- workflowName: import_zod40.z.string().optional(),
23626
- status: import_zod40.z.string().optional(),
23627
- startTime: import_zod40.z.number().optional(),
23628
- phases: import_zod40.z.array(import_zod40.z.object({ title: import_zod40.z.string() })).default([]),
23629
- summary: import_zod40.z.string().optional()
24123
+ var TaskFileSchema = import_zod42.z.object({ ...TaskItemSchema.omit({ taskList: true }).shape, blocks: import_zod42.z.array(import_zod42.z.string()).default([]), blockedBy: import_zod42.z.array(import_zod42.z.string()).default([]) });
24124
+ var WorkflowRunFileSchema = import_zod42.z.object({
24125
+ runId: import_zod42.z.string(),
24126
+ workflowName: import_zod42.z.string().optional(),
24127
+ status: import_zod42.z.string().optional(),
24128
+ startTime: import_zod42.z.number().optional(),
24129
+ phases: import_zod42.z.array(import_zod42.z.object({ title: import_zod42.z.string() })).default([]),
24130
+ summary: import_zod42.z.string().optional()
23630
24131
  });
23631
24132
  function summariseSession(fs17, configDir, ref) {
23632
24133
  const sessionRelative = import_node_path46.default.join(PROJECTS_DIR, ref.project, ref.entry);
@@ -24134,6 +24635,7 @@ init_ownCli();
24134
24635
  RC_IDLE_EXPIRY_MS,
24135
24636
  RC_ORPC_PATH_PREFIX,
24136
24637
  RC_PENDING_DEADLINE_MS,
24638
+ RC_PENDING_RETIRE_REASONS,
24137
24639
  RC_PERMISSION_MODES,
24138
24640
  RC_READ_FILE_ENCODINGS,
24139
24641
  RC_REQUEST_PARSE_CAP_BYTES,
@@ -24145,6 +24647,8 @@ init_ownCli();
24145
24647
  RC_SELF_HOST_SCOPE_LIST,
24146
24648
  RC_SELF_HOST_WORKER_JWT_TTL_SECONDS,
24147
24649
  RC_SESSIONS_PATH_PREFIX,
24650
+ RC_SESSION_END_REASONS,
24651
+ RC_SESSION_EVENT_LOG_CAPACITY,
24148
24652
  RC_STREAM_BACKOFF_MS,
24149
24653
  RC_WEB_FETCH_ALLOW_PRIVATE_ENV,
24150
24654
  RC_WEB_FETCH_DEADLINE_MS,
@@ -24155,6 +24659,13 @@ init_ownCli();
24155
24659
  RcPermissionModeSchema,
24156
24660
  RcRateLimitInfoSchema,
24157
24661
  RcRateLimitWindowSchema,
24662
+ RcSessionEventCursorExpiredError,
24663
+ RcSessionEventSchema,
24664
+ RcSessionEventsPageInputSchema,
24665
+ RcSessionEventsReadInputSchema,
24666
+ RcSessionEventsReadOutputSchema,
24667
+ RcSessionEventsStreamInputSchema,
24668
+ RcSessionTransitionSchema,
24158
24669
  RcStreamEnvelopeSchema,
24159
24670
  RcStreamEventSchema,
24160
24671
  ResetRowSchema,
@@ -24236,6 +24747,8 @@ init_ownCli();
24236
24747
  createRcEventFanout,
24237
24748
  createRcLiveUsage,
24238
24749
  createRcSelfHostSurface,
24750
+ createRcSessionEventLog,
24751
+ createRcSessionEventsApiRouter,
24239
24752
  createRcSessionTracker,
24240
24753
  createRcStreamHub,
24241
24754
  createSseParser,
@@ -24251,6 +24764,7 @@ init_ownCli();
24251
24764
  evaluateAmbientCredentialGuard,
24252
24765
  evaluateWhen,
24253
24766
  fetchThroughWebProxy,
24767
+ followRcSessionEvents,
24254
24768
  formatAmbientCredentialGuardMessage,
24255
24769
  formatCheckReport,
24256
24770
  formatDoctorReport,