claude-use 14.0.1 → 14.0.3

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
@@ -96,14 +96,42 @@ var init_categories_default = __esm({
96
96
  }
97
97
  });
98
98
 
99
- // src/config/proxyBypass.ts
100
- function isDnsName(name) {
101
- const labels = name.split(".");
102
- return name.length <= MAX_NAME_LENGTH && labels.every((label) => label.length <= MAX_LABEL_LENGTH && LABEL_RE.test(label)) && !DIGITS_RE.test(labels.at(-1) ?? "");
99
+ // src/hostName.ts
100
+ function isDottedDecimalIpv4(host) {
101
+ const parts = host.split(".");
102
+ return parts.length === IPV4_PARTS && parts.every((part) => IPV4_PART.test(part) && Number(part) <= MAX_OCTET);
103
103
  }
104
- function isIpv4(host) {
105
- return IPV4_RE.test(host) && host.split(".").every((octet) => Number(octet) <= MAX_OCTET);
104
+ function dnsNameProblem(name) {
105
+ if (name.length > MAX_NAME_LENGTH) {
106
+ return `a host longer than ${String(MAX_NAME_LENGTH)} characters`;
107
+ }
108
+ const labels = name.split(".");
109
+ if (labels.some((label) => label.length > MAX_LABEL_LENGTH)) {
110
+ return `a host with a label longer than ${String(MAX_LABEL_LENGTH)} characters`;
111
+ }
112
+ if (!labels.every((label) => LABEL.test(label))) {
113
+ return "a host that is not letters, digits, underscores and interior hyphens in non-empty dot-separated labels";
114
+ }
115
+ if (NUMERIC_LAST_LABEL.test(labels[labels.length - 1] ?? "")) {
116
+ return "a numeric host that is not a dotted-decimal IPv4 address";
117
+ }
118
+ return void 0;
106
119
  }
120
+ var MAX_LABEL_LENGTH, MAX_NAME_LENGTH, IPV4_PARTS, MAX_OCTET, LABEL, NUMERIC_LAST_LABEL, IPV4_PART;
121
+ var init_hostName = __esm({
122
+ "src/hostName.ts"() {
123
+ "use strict";
124
+ MAX_LABEL_LENGTH = 63;
125
+ MAX_NAME_LENGTH = 253;
126
+ IPV4_PARTS = 4;
127
+ MAX_OCTET = 255;
128
+ LABEL = /^[a-z0-9_](?:[a-z0-9_-]*[a-z0-9_])?$/i;
129
+ NUMERIC_LAST_LABEL = /^(?:\d+|0x[0-9a-f]*)$/i;
130
+ IPV4_PART = /^(?:0|[1-9]\d{0,2})$/;
131
+ }
132
+ });
133
+
134
+ // src/config/proxyBypass.ts
107
135
  function proxyBypassSyntaxProblem(entry) {
108
136
  if (entry === "" || entry !== entry.trim()) {
109
137
  return "is empty or has surrounding whitespace";
@@ -120,21 +148,15 @@ function proxyBypassSyntaxProblem(entry) {
120
148
  if (entry.includes(":")) {
121
149
  return "has a port, which the proxy variable cannot express: list the host alone";
122
150
  }
123
- return isIpv4(entry) || isDnsName(entry.replace(/^\./, "")) ? void 0 : "is not a host name or an IPv4 address";
151
+ return isDottedDecimalIpv4(entry) || dnsNameProblem(entry.replace(/^\./, "")) === void 0 ? void 0 : "is not a host name or an IPv4 address";
124
152
  }
125
153
  function proxyBypassName(entry) {
126
- return isIpv4(entry) ? void 0 : entry.replace(/^\./, "").toLowerCase();
154
+ return isDottedDecimalIpv4(entry) ? void 0 : entry.replace(/^\./, "").toLowerCase();
127
155
  }
128
- var MAX_NAME_LENGTH, MAX_LABEL_LENGTH, MAX_OCTET, LABEL_RE, IPV4_RE, DIGITS_RE;
129
156
  var init_proxyBypass = __esm({
130
157
  "src/config/proxyBypass.ts"() {
131
158
  "use strict";
132
- MAX_NAME_LENGTH = 253;
133
- MAX_LABEL_LENGTH = 63;
134
- MAX_OCTET = 255;
135
- LABEL_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/;
136
- IPV4_RE = /^\d{1,3}(?:\.\d{1,3}){3}$/;
137
- DIGITS_RE = /^\d+$/;
159
+ init_hostName();
138
160
  }
139
161
  });
140
162
 
@@ -328,7 +350,7 @@ function resolveStatusline(settings) {
328
350
  }
329
351
  return resolved;
330
352
  }
331
- var import_string_width2, import_zod2, STATUSLINE_HEADER_SEGMENTS, STATUSLINE_ROWS, STATUSLINE_SESSION_TIME_PARTS, PROMPT_CACHE_TTL_SECONDS, ORANGE_PALETTE_INDEX, STATUSLINE_COLOUR_NAMES, DEFAULT_HEADER_SEGMENTS, DEFAULT_ROWS, CLAUDE_HUD_DEFAULTS, STATUSLINE_PRESETS, GIT_WITH_DIRTY_MARKER, JJ_OFF, PRESET_BUNDLES, STATUSLINE_PATH_LEVELS, STATUSLINE_USAGE_VALUES, STATUSLINE_BAR_GRADIENTS, STATUSLINE_TIME_FORMATS, STATUSLINE_HOUR_CYCLES, MAX_PERCENT, MAX_STATUSLINE_PALETTE_INDEX, MAX_STATUSLINE_LABEL_COLUMNS, MIN_STATUSLINE_COLUMNS, MAX_STATUSLINE_COLUMNS, MAX_BAR_CELLS, MAX_ACCOUNT_USER_CHARS, MAX_DISPLAY_TEXT_CHARS, MAX_EXTRA_COMMAND_ARGUMENTS, MAX_EXTRA_COMMAND_ARGUMENT_CHARS, STATUSLINE_EXTRA_GROUP, commandArgument, LABEL_RE2, OPTIONAL_LABEL_RE, mergeGroups, colourValue, barCharacter, STATUSLINE_CONTEXT_VALUES, STATUSLINE_CONTEXT_ESTIMATES, AUTOCOMPACT_RESERVE_FRACTION, AUTOCOMPACT_RESERVE_RAMP_START, AUTOCOMPACT_RESERVE_RAMP_END, labelWithinColumns, labelWithinColumnsMessage, labelShowsSomething, labelShowsSomethingMessage, labelIsPlainText, labelIsPlainTextMessage, windowLabel, overrideText, wholePercent, thresholdPercent, SHAPES, UNSET_NOTE, RESET_NOTE, LANGUAGE_DESCRIPTION, LANGUAGE_TAGS, LANGUAGE_ALIASES, TOP_LEVEL, StatuslineSchema, ResolvedStatuslineSchema, STATUSLINE_DEFAULTS, STATUSLINE_ENV;
353
+ var import_string_width2, import_zod2, STATUSLINE_HEADER_SEGMENTS, STATUSLINE_ROWS, STATUSLINE_SESSION_TIME_PARTS, PROMPT_CACHE_TTL_SECONDS, ORANGE_PALETTE_INDEX, STATUSLINE_COLOUR_NAMES, DEFAULT_HEADER_SEGMENTS, DEFAULT_ROWS, CLAUDE_HUD_DEFAULTS, STATUSLINE_PRESETS, GIT_WITH_DIRTY_MARKER, JJ_OFF, PRESET_BUNDLES, STATUSLINE_PATH_LEVELS, STATUSLINE_USAGE_VALUES, STATUSLINE_BAR_GRADIENTS, STATUSLINE_TIME_FORMATS, STATUSLINE_HOUR_CYCLES, MAX_PERCENT, MAX_STATUSLINE_PALETTE_INDEX, MAX_STATUSLINE_LABEL_COLUMNS, MIN_STATUSLINE_COLUMNS, MAX_STATUSLINE_COLUMNS, MAX_BAR_CELLS, MAX_ACCOUNT_USER_CHARS, MAX_DISPLAY_TEXT_CHARS, MAX_EXTRA_COMMAND_ARGUMENTS, MAX_EXTRA_COMMAND_ARGUMENT_CHARS, STATUSLINE_EXTRA_GROUP, commandArgument, LABEL_RE, OPTIONAL_LABEL_RE, mergeGroups, colourValue, barCharacter, STATUSLINE_CONTEXT_VALUES, STATUSLINE_CONTEXT_ESTIMATES, AUTOCOMPACT_RESERVE_FRACTION, AUTOCOMPACT_RESERVE_RAMP_START, AUTOCOMPACT_RESERVE_RAMP_END, labelWithinColumns, labelWithinColumnsMessage, labelShowsSomething, labelShowsSomethingMessage, labelIsPlainText, labelIsPlainTextMessage, windowLabel, overrideText, wholePercent, thresholdPercent, SHAPES, UNSET_NOTE, RESET_NOTE, LANGUAGE_DESCRIPTION, LANGUAGE_TAGS, LANGUAGE_ALIASES, TOP_LEVEL, StatuslineSchema, ResolvedStatuslineSchema, STATUSLINE_DEFAULTS, STATUSLINE_ENV;
332
354
  var init_statusline = __esm({
333
355
  "src/config/statusline.ts"() {
334
356
  "use strict";
@@ -401,7 +423,7 @@ var init_statusline = __esm({
401
423
  MAX_EXTRA_COMMAND_ARGUMENT_CHARS = 1024;
402
424
  STATUSLINE_EXTRA_GROUP = "extra";
403
425
  commandArgument = import_zod2.z.string().max(MAX_EXTRA_COMMAND_ARGUMENT_CHARS).refine((argument) => !argument.includes("\0"), "must not contain a NUL character");
404
- LABEL_RE2 = /^[^\p{C}\p{Z}]+(?: [^\p{C}\p{Z}]+)*$/u;
426
+ LABEL_RE = /^[^\p{C}\p{Z}]+(?: [^\p{C}\p{Z}]+)*$/u;
405
427
  OPTIONAL_LABEL_RE = /^(?:[^\p{C}\p{Z}]+(?: [^\p{C}\p{Z}]+)*)?$/u;
406
428
  mergeGroups = import_zod2.z.array(distinctList(import_zod2.z.enum(STATUSLINE_ROWS)).min(2)).refine((groups) => {
407
429
  const rows = groups.flat();
@@ -418,7 +440,7 @@ var init_statusline = __esm({
418
440
  labelWithinColumnsMessage = `must take no more than ${String(MAX_STATUSLINE_LABEL_COLUMNS)} terminal columns`;
419
441
  labelShowsSomething = (text) => !drawsNothing(text);
420
442
  labelShowsSomethingMessage = "must show something: a label of only combining marks or blank characters draws nothing";
421
- labelIsPlainText = (text) => LABEL_RE2.test(text);
443
+ labelIsPlainText = (text) => LABEL_RE.test(text);
422
444
  labelIsPlainTextMessage = "must be visible text without control characters";
423
445
  windowLabel = import_zod2.z.string().refine((text) => text === "" || labelWithinColumns(text), labelWithinColumnsMessage).refine((text) => text === "" || labelShowsSomething(text), labelShowsSomethingMessage).refine((text) => text === "" || labelIsPlainText(text), labelIsPlainTextMessage);
424
446
  overrideText = import_zod2.z.string().max(MAX_DISPLAY_TEXT_CHARS).regex(OPTIONAL_LABEL_RE, "must be visible text without control characters");
@@ -3771,6 +3793,120 @@ var init_farm = __esm({
3771
3793
  }
3772
3794
  });
3773
3795
 
3796
+ // src/baseUrlDial.ts
3797
+ function dialHostOf(url) {
3798
+ return withoutRootDot(url.hostname.replace(/^\[(.*)\]$/, "$1"));
3799
+ }
3800
+ function withoutRootDot(host) {
3801
+ return host.endsWith(".") ? host.slice(0, -1) : host;
3802
+ }
3803
+ function bareZone(literal) {
3804
+ return literal.replace("%25", "%");
3805
+ }
3806
+ function portOf(text) {
3807
+ if (text === "") {
3808
+ return "has no port after the colon";
3809
+ }
3810
+ if (!/^\d+$/.test(text)) {
3811
+ return "has a port that is not a number";
3812
+ }
3813
+ const port = Number(text);
3814
+ return port >= 1 && port <= MAX_TCP_PORT ? port : `has a port outside 1 to ${String(MAX_TCP_PORT)}`;
3815
+ }
3816
+ function isAscii(text) {
3817
+ return new RegExp("^\\p{ASCII}*$", "u").test(text);
3818
+ }
3819
+ function nameOf(host) {
3820
+ const rooted = withoutRootDot(host.toLowerCase());
3821
+ if (rooted === "") {
3822
+ return { refusal: "an authority that names no host" };
3823
+ }
3824
+ const lowered = isAscii(rooted) ? rooted : (0, import_node_url.domainToASCII)(rooted);
3825
+ if (lowered === "") {
3826
+ return { refusal: "a host that does not convert to an ASCII name" };
3827
+ }
3828
+ if (isDottedDecimalIpv4(lowered)) {
3829
+ return lowered;
3830
+ }
3831
+ const problem = dnsNameProblem(lowered);
3832
+ if (problem !== void 0) {
3833
+ return { refusal: problem };
3834
+ }
3835
+ return lowered;
3836
+ }
3837
+ function canonicalLiteral(literal) {
3838
+ return literal.includes("%") ? lowerHost(literal) : dialHostOf(new URL(`http://[${literal}]/`));
3839
+ }
3840
+ function lowerHost(host) {
3841
+ const zone = host.indexOf("%");
3842
+ return zone === -1 ? host.toLowerCase() : `${host.slice(0, zone).toLowerCase()}${host.slice(zone)}`;
3843
+ }
3844
+ function parseDialAuthority(authority, defaultPort) {
3845
+ if (authority.includes("@")) {
3846
+ return { refusal: "an authority with userinfo cannot be dialled" };
3847
+ }
3848
+ if (NOT_AUTHORITY.test(authority)) {
3849
+ return { refusal: "an authority holds whitespace, a path, a query or a fragment" };
3850
+ }
3851
+ if (authority.startsWith("[")) {
3852
+ const close = authority.indexOf("]");
3853
+ if (close === -1) {
3854
+ return { refusal: "an authority with an unterminated bracket" };
3855
+ }
3856
+ const literal = bareZone(authority.slice(1, close));
3857
+ const rest = authority.slice(close + 1);
3858
+ if (literal === "") {
3859
+ return { refusal: "an authority that names no host" };
3860
+ }
3861
+ if (!(0, import_node_net.isIPv6)(literal)) {
3862
+ return { refusal: "a bracketed host that is not an IPv6 literal" };
3863
+ }
3864
+ if (rest !== "" && !rest.startsWith(":")) {
3865
+ return { refusal: "an authority with text after the closing bracket other than a port" };
3866
+ }
3867
+ const port2 = rest === "" ? defaultPort : portOf(rest.slice(1));
3868
+ return typeof port2 === "string" ? { refusal: `an authority that ${port2}` } : { host: canonicalLiteral(literal), port: port2 };
3869
+ }
3870
+ const colons = authority.split(":").length - 1;
3871
+ if (colons > 1) {
3872
+ return { refusal: "an unbracketed IPv6 literal, which must be written in brackets" };
3873
+ }
3874
+ const colon = authority.indexOf(":");
3875
+ const host = colon === -1 ? authority : authority.slice(0, colon);
3876
+ if (host === "") {
3877
+ return { refusal: "an authority that names no host" };
3878
+ }
3879
+ if (/[[\]]/.test(host)) {
3880
+ return { refusal: "an authority with brackets round something other than an IPv6 literal" };
3881
+ }
3882
+ const name = nameOf(host);
3883
+ if (typeof name !== "string") {
3884
+ return name;
3885
+ }
3886
+ const port = colon === -1 ? defaultPort : portOf(authority.slice(colon + 1));
3887
+ return typeof port === "string" ? { refusal: `an authority that ${port}` } : { host: name, port };
3888
+ }
3889
+ function dialTargetOf(baseUrl) {
3890
+ const url = new URL(baseUrl);
3891
+ const defaultPort = DEFAULT_PORTS[url.protocol];
3892
+ if (defaultPort === void 0) {
3893
+ throw new Error(`${url.protocol} is not a scheme a provider's base URL can have`);
3894
+ }
3895
+ return { host: dialHostOf(url), port: url.port === "" ? defaultPort : Number(url.port) };
3896
+ }
3897
+ var import_node_net, import_node_url, MAX_TCP_PORT, NOT_AUTHORITY, DEFAULT_PORTS;
3898
+ var init_baseUrlDial = __esm({
3899
+ "src/baseUrlDial.ts"() {
3900
+ "use strict";
3901
+ import_node_net = require("node:net");
3902
+ import_node_url = require("node:url");
3903
+ init_hostName();
3904
+ MAX_TCP_PORT = 65535;
3905
+ NOT_AUTHORITY = /[\s/?#\\]/;
3906
+ DEFAULT_PORTS = { "http:": 80, "https:": 443 };
3907
+ }
3908
+ });
3909
+
3774
3910
  // src/frontdoor/x509.ts
3775
3911
  function tlv(tag, content) {
3776
3912
  const length = content.length;
@@ -3853,7 +3989,7 @@ function ipv6Groups(address) {
3853
3989
  const [head = "", tail] = address.split("::");
3854
3990
  const split = (text) => text === "" ? [] : text.split(":");
3855
3991
  const expand = (groups) => groups.flatMap((group) => {
3856
- if (!import_node_net.default.isIPv4(group)) {
3992
+ if (!import_node_net2.default.isIPv4(group)) {
3857
3993
  return [Number.parseInt(group, HEX_RADIX)];
3858
3994
  }
3859
3995
  const [a = 0, b = 0, c = 0, d = 0] = group.split(".").map(Number);
@@ -3865,10 +4001,10 @@ function ipv6Groups(address) {
3865
4001
  return [...before, ...filler, ...after];
3866
4002
  }
3867
4003
  function ipBytes(address) {
3868
- if (import_node_net.default.isIPv4(address)) {
4004
+ if (import_node_net2.default.isIPv4(address)) {
3869
4005
  return Buffer.from(address.split(".").map(Number));
3870
4006
  }
3871
- if (!import_node_net.default.isIPv6(address)) {
4007
+ if (!import_node_net2.default.isIPv6(address)) {
3872
4008
  throw new Error(`${address} is not an IP address`);
3873
4009
  }
3874
4010
  const bytes = Buffer.alloc(IPV6_GROUPS * BYTES_PER_IPV6_GROUP);
@@ -3976,7 +4112,7 @@ function issueLeafCertificate(ca, names, notBefore, notAfter) {
3976
4112
  const caCertificate = new import_node_crypto3.X509Certificate(ca.certPem);
3977
4113
  const caPrivateKey = (0, import_node_crypto3.createPrivateKey)(ca.keyPem);
3978
4114
  const { publicKey, privateKey } = rsaKeyPair();
3979
- const generalNames = names.map((name) => import_node_net.default.isIP(name) === 0 ? tlv(TAG_GENERAL_NAME_DNS, Buffer.from(name, "ascii")) : tlv(TAG_GENERAL_NAME_IP, ipBytes(name)));
4115
+ const generalNames = names.map((name) => import_node_net2.default.isIP(name) === 0 ? tlv(TAG_GENERAL_NAME_DNS, Buffer.from(name, "ascii")) : tlv(TAG_GENERAL_NAME_IP, ipBytes(name)));
3980
4116
  const der = assemble({
3981
4117
  subjectPublicKey: publicKey,
3982
4118
  subjectName: commonNameOnly(commonName),
@@ -3995,12 +4131,12 @@ function issueLeafCertificate(ca, names, notBefore, notAfter) {
3995
4131
  });
3996
4132
  return { certPem: toPem("CERTIFICATE", der), keyPem: keyPem(privateKey) };
3997
4133
  }
3998
- var import_node_crypto3, import_node_net, TAG_BOOLEAN, TAG_INTEGER, TAG_BIT_STRING, TAG_OCTET_STRING, TAG_NULL, TAG_OID, TAG_UTF8_STRING, TAG_UTC_TIME, TAG_GENERALIZED_TIME, TAG_SEQUENCE, TAG_SET, TAG_VERSION, TAG_EXTENSIONS, TAG_GENERAL_NAME_DNS, TAG_GENERAL_NAME_IP, TAG_KEY_IDENTIFIER, OID_COMMON_NAME, OID_SHA256_WITH_RSA, OID_SUBJECT_KEY_IDENTIFIER, OID_KEY_USAGE, OID_SUBJECT_ALT_NAME, OID_BASIC_CONSTRAINTS, OID_AUTHORITY_KEY_IDENTIFIER, OID_EXT_KEY_USAGE, OID_SERVER_AUTH, VERSION_3, SERIAL_NUMBER_BYTES, RSA_MODULUS_BITS, BITS_PER_BYTE, BYTE_MASK, HIGH_BIT, BASE_128_PAYLOAD_MASK, FIRST_ARC_WEIGHT, SHORT_FORM_MAX_LENGTH, MS_PER_SECOND, UTC_TIME_LAST_YEAR, YEAR_DIGITS, TWO_DIGIT_YEAR_DIGITS, COMPACT_TIME_DIGITS, KEY_USAGE, SIGNATURE_ALGORITHM, IPV6_GROUPS, HEX_RADIX, BYTES_PER_IPV6_GROUP;
4134
+ var import_node_crypto3, import_node_net2, TAG_BOOLEAN, TAG_INTEGER, TAG_BIT_STRING, TAG_OCTET_STRING, TAG_NULL, TAG_OID, TAG_UTF8_STRING, TAG_UTC_TIME, TAG_GENERALIZED_TIME, TAG_SEQUENCE, TAG_SET, TAG_VERSION, TAG_EXTENSIONS, TAG_GENERAL_NAME_DNS, TAG_GENERAL_NAME_IP, TAG_KEY_IDENTIFIER, OID_COMMON_NAME, OID_SHA256_WITH_RSA, OID_SUBJECT_KEY_IDENTIFIER, OID_KEY_USAGE, OID_SUBJECT_ALT_NAME, OID_BASIC_CONSTRAINTS, OID_AUTHORITY_KEY_IDENTIFIER, OID_EXT_KEY_USAGE, OID_SERVER_AUTH, VERSION_3, SERIAL_NUMBER_BYTES, RSA_MODULUS_BITS, BITS_PER_BYTE, BYTE_MASK, HIGH_BIT, BASE_128_PAYLOAD_MASK, FIRST_ARC_WEIGHT, SHORT_FORM_MAX_LENGTH, MS_PER_SECOND, UTC_TIME_LAST_YEAR, YEAR_DIGITS, TWO_DIGIT_YEAR_DIGITS, COMPACT_TIME_DIGITS, KEY_USAGE, SIGNATURE_ALGORITHM, IPV6_GROUPS, HEX_RADIX, BYTES_PER_IPV6_GROUP;
3999
4135
  var init_x509 = __esm({
4000
4136
  "src/frontdoor/x509.ts"() {
4001
4137
  "use strict";
4002
4138
  import_node_crypto3 = require("node:crypto");
4003
- import_node_net = __toESM(require("node:net"), 1);
4139
+ import_node_net2 = __toESM(require("node:net"), 1);
4004
4140
  TAG_BOOLEAN = 1;
4005
4141
  TAG_INTEGER = 2;
4006
4142
  TAG_BIT_STRING = 3;
@@ -4159,6 +4295,39 @@ var init_route = __esm({
4159
4295
  }
4160
4296
  });
4161
4297
 
4298
+ // src/processRole.ts
4299
+ function enterProcessRole(role) {
4300
+ const previous = currentRole;
4301
+ currentRole = role;
4302
+ return () => {
4303
+ currentRole = previous;
4304
+ };
4305
+ }
4306
+ function noteBlockingStep() {
4307
+ blockingStepObserver?.();
4308
+ }
4309
+ function refuseToBlockInRole(operation) {
4310
+ noteBlockingStep();
4311
+ if (currentRole !== void 0) {
4312
+ throw new BlockingInEventLoopError(operation, currentRole);
4313
+ }
4314
+ }
4315
+ var currentRole, BlockingInEventLoopError, blockingStepObserver;
4316
+ var init_processRole = __esm({
4317
+ "src/processRole.ts"() {
4318
+ "use strict";
4319
+ init_cliError();
4320
+ BlockingInEventLoopError = class extends CliError {
4321
+ constructor(operation, role) {
4322
+ super(
4323
+ `${operation} blocks the calling thread, which in the ${role} is the event loop that answers every session; it must not run there (a launch planned inside the door reaches it through its own addresses, never through the launcher's synchronous coordination)`
4324
+ );
4325
+ this.name = "BlockingInEventLoopError";
4326
+ }
4327
+ };
4328
+ }
4329
+ });
4330
+
4162
4331
  // src/baseUrlDisplay.ts
4163
4332
  function displayBaseUrl(baseUrl) {
4164
4333
  const url = new URL(baseUrl);
@@ -4909,36 +5078,62 @@ var init_providerCatalogue = __esm({
4909
5078
  }
4910
5079
  });
4911
5080
 
5081
+ // src/frontdoor/catalogueCleanup.ts
5082
+ async function pruneAbandonedCatalogueGenerations(fs17, paths, ownPid, generation, runningAmong) {
5083
+ const root = import_node_path12.default.join(paths.catalogueDir, "supervisors");
5084
+ const owners = fs17.readdir(root).flatMap((entry) => {
5085
+ const pid = Number(entry);
5086
+ return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry && fs17.lstat(import_node_path12.default.join(root, entry))?.kind === "dir" ? [pid] : [];
5087
+ });
5088
+ const running = await runningAmong(owners);
5089
+ for (const pid of owners) {
5090
+ if (pid !== ownPid && running.has(pid)) continue;
5091
+ const directory = import_node_path12.default.join(root, String(pid));
5092
+ for (const entry of fs17.readdir(directory)) {
5093
+ const candidate = import_node_path12.default.join(directory, entry);
5094
+ if (import_zod8.z.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) && fs17.lstat(candidate)?.kind === "dir") fs17.removeRecursive(candidate);
5095
+ }
5096
+ }
5097
+ }
5098
+ var import_node_path12, import_zod8;
5099
+ var init_catalogueCleanup = __esm({
5100
+ "src/frontdoor/catalogueCleanup.ts"() {
5101
+ "use strict";
5102
+ import_node_path12 = __toESM(require("node:path"), 1);
5103
+ import_zod8 = require("zod");
5104
+ }
5105
+ });
5106
+
4912
5107
  // src/frontdoor/state.ts
4913
5108
  function readCatalogueStatus(fs17, paths, pid, generation, name) {
4914
- const file = import_node_path12.default.join(import_node_path12.default.dirname(catalogueCachePath(paths, name, pid, generation)), `${name}.status.json`);
5109
+ const file = import_node_path13.default.join(import_node_path13.default.dirname(catalogueCachePath(paths, name, pid, generation)), `${name}.status.json`);
4915
5110
  const raw = fs17.readFileUtf8(file);
4916
5111
  if (raw === void 0) return void 0;
4917
5112
  try {
4918
- const value = import_zod8.z.strictObject({ status: import_zod8.z.enum(["running", "ready", "failed"]), fingerprint: import_zod8.z.string().min(1).optional(), recordedAt: import_zod8.z.number().optional() }).safeParse(JSON.parse(raw));
5113
+ const value = import_zod9.z.strictObject({ status: import_zod9.z.enum(["running", "ready", "failed"]), fingerprint: import_zod9.z.string().min(1).optional(), recordedAt: import_zod9.z.number().optional() }).safeParse(JSON.parse(raw));
4919
5114
  return value.success ? value.data : void 0;
4920
5115
  } catch {
4921
5116
  return void 0;
4922
5117
  }
4923
5118
  }
4924
5119
  function writeFrontDoorCodexHome(fs17, frontdoorDir, pid, codexHome, generation) {
4925
- const directory = import_node_path12.default.join(frontdoorDir, "codex-homes");
5120
+ const directory = import_node_path13.default.join(frontdoorDir, "codex-homes");
4926
5121
  fs17.mkdirp(directory);
4927
- fs17.writeFilePrivate(import_node_path12.default.join(directory, `${String(pid)}.json`), `${JSON.stringify({ codexHome, generation })}
5122
+ fs17.writeFilePrivate(import_node_path13.default.join(directory, `${String(pid)}.json`), `${JSON.stringify({ codexHome, generation })}
4928
5123
  `);
4929
5124
  }
4930
5125
  function readFrontDoorCodexRecord(fs17, frontdoorDir, pid) {
4931
- const raw = fs17.readFileUtf8(import_node_path12.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
5126
+ const raw = fs17.readFileUtf8(import_node_path13.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
4932
5127
  if (raw === void 0) return void 0;
4933
5128
  try {
4934
- const parsed = import_zod8.z.strictObject({ codexHome: import_zod8.z.string().min(1), generation: import_zod8.z.uuid() }).safeParse(JSON.parse(raw));
4935
- return parsed.success && import_node_path12.default.isAbsolute(parsed.data.codexHome) ? parsed.data : void 0;
5129
+ const parsed = import_zod9.z.strictObject({ codexHome: import_zod9.z.string().min(1), generation: import_zod9.z.uuid() }).safeParse(JSON.parse(raw));
5130
+ return parsed.success && import_node_path13.default.isAbsolute(parsed.data.codexHome) ? parsed.data : void 0;
4936
5131
  } catch {
4937
5132
  return void 0;
4938
5133
  }
4939
5134
  }
4940
5135
  function removeFrontDoorCodexHome(fs17, frontdoorDir, pid) {
4941
- fs17.removeRecursive(import_node_path12.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
5136
+ fs17.removeRecursive(import_node_path13.default.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
4942
5137
  }
4943
5138
  function readFrontDoorState(fs17, stateFile) {
4944
5139
  let raw;
@@ -4958,7 +5153,7 @@ function readFrontDoorState(fs17, stateFile) {
4958
5153
  }
4959
5154
  }
4960
5155
  function writeFrontDoorState(fs17, stateFile, state) {
4961
- fs17.mkdirp(import_node_path12.default.dirname(stateFile));
5156
+ fs17.mkdirp(import_node_path13.default.dirname(stateFile));
4962
5157
  fs17.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
4963
5158
  `);
4964
5159
  }
@@ -4971,18 +5166,18 @@ function frontDoorOrigin(state) {
4971
5166
  }
4972
5167
  function writeFrontDoorDirectRecord(fs17, recordsDir, record) {
4973
5168
  fs17.mkdirp(recordsDir);
4974
- fs17.writeFilePrivate(import_node_path12.default.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
5169
+ fs17.writeFilePrivate(import_node_path13.default.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
4975
5170
  `);
4976
5171
  }
4977
5172
  function removeFrontDoorDirectRecord(fs17, recordsDir, pid) {
4978
- fs17.removeRecursive(import_node_path12.default.join(recordsDir, `${String(pid)}.json`));
5173
+ fs17.removeRecursive(import_node_path13.default.join(recordsDir, `${String(pid)}.json`));
4979
5174
  }
4980
5175
  function markFrontDoorDraining(fs17, markersDir, pid) {
4981
5176
  fs17.mkdirp(markersDir);
4982
- fs17.writeFilePrivate(import_node_path12.default.join(markersDir, String(pid)), "\n");
5177
+ fs17.writeFilePrivate(import_node_path13.default.join(markersDir, String(pid)), "\n");
4983
5178
  }
4984
5179
  function unmarkFrontDoorDraining(fs17, markersDir, pid) {
4985
- fs17.removeRecursive(import_node_path12.default.join(markersDir, String(pid)));
5180
+ fs17.removeRecursive(import_node_path13.default.join(markersDir, String(pid)));
4986
5181
  }
4987
5182
  function listDrainingFrontDoors(fs17, markersDir, isRunning) {
4988
5183
  return fs17.readdir(markersDir).flatMap((file) => /^[1-9]\d*$/.test(file) && Number.isSafeInteger(Number(file)) ? [Number(file)] : []).filter(isRunning).sort((a, b) => a - b);
@@ -4999,7 +5194,7 @@ function readDirectRecordEntry(fs17, recordsDir, file) {
4999
5194
  }
5000
5195
  let raw;
5001
5196
  try {
5002
- raw = fs17.readFileUtf8(import_node_path12.default.join(recordsDir, file));
5197
+ raw = fs17.readFileUtf8(import_node_path13.default.join(recordsDir, file));
5003
5198
  } catch {
5004
5199
  return void 0;
5005
5200
  }
@@ -5024,7 +5219,7 @@ function pruneMalformedFrontDoorDirectFiles(fs17, recordsDir, isRunning) {
5024
5219
  const writer = RECORD_TEMPORARY_FILE.exec(file)?.[1];
5025
5220
  const stale = writer !== void 0 && !isRunning(Number(writer));
5026
5221
  if (stale || readDirectRecordEntry(fs17, recordsDir, file)?.malformed === true) {
5027
- fs17.removeRecursive(import_node_path12.default.join(recordsDir, file));
5222
+ fs17.removeRecursive(import_node_path13.default.join(recordsDir, file));
5028
5223
  }
5029
5224
  }
5030
5225
  }
@@ -5043,7 +5238,7 @@ function recordOf(details) {
5043
5238
  }
5044
5239
  function writeFrontDoorSession(fs17, sessionsDir, session) {
5045
5240
  fs17.mkdirPrivate(sessionsDir);
5046
- fs17.writeFilePrivate(import_node_path12.default.join(sessionsDir, sessionRecordName(session.pid)), `${JSON.stringify(session, null, 2)}
5241
+ fs17.writeFilePrivate(import_node_path13.default.join(sessionsDir, sessionRecordName(session.pid)), `${JSON.stringify(session, null, 2)}
5047
5242
  `);
5048
5243
  }
5049
5244
  function sessionRecordName(pid) {
@@ -5057,7 +5252,7 @@ function summaryOf(session) {
5057
5252
  }
5058
5253
  function readFrontDoorSessionRecord(fs17, sessionsDir, name) {
5059
5254
  try {
5060
- const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs17.readFileUtf8(import_node_path12.default.join(sessionsDir, name)) ?? ""));
5255
+ const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs17.readFileUtf8(import_node_path13.default.join(sessionsDir, name)) ?? ""));
5061
5256
  return parsed.success ? parsed.data : void 0;
5062
5257
  } catch {
5063
5258
  return void 0;
@@ -5074,7 +5269,7 @@ function listFrontDoorSessions(fs17, sessionsDir) {
5074
5269
  return sessions.sort((a, b) => a.pid - b.pid);
5075
5270
  }
5076
5271
  function removeFrontDoorSession(fs17, sessionsDir, pid) {
5077
- fs17.removeRecursive(import_node_path12.default.join(sessionsDir, sessionRecordName(pid)));
5272
+ fs17.removeRecursive(import_node_path13.default.join(sessionsDir, sessionRecordName(pid)));
5078
5273
  }
5079
5274
  function pruneDeadFrontDoorSessions(fs17, sessionsDir, listed, isRunning) {
5080
5275
  const removed = [];
@@ -5086,112 +5281,53 @@ function pruneDeadFrontDoorSessions(fs17, sessionsDir, listed, isRunning) {
5086
5281
  }
5087
5282
  return removed;
5088
5283
  }
5089
- var import_node_path12, import_zod8, FRONT_DOOR_PROTOCOL, FRONT_DOOR_HANDOVER_PROTOCOL, FrontDoorSessionSchema, FrontDoorStateSchema, MAX_TCP_PORT, FrontDoorDirectRecordSchema, RECORD_TEMPORARY_FILE;
5284
+ var import_node_path13, import_zod9, FRONT_DOOR_PROTOCOL, FRONT_DOOR_HANDOVER_PROTOCOL, FrontDoorSessionSchema, FrontDoorStateSchema, FrontDoorDirectRecordSchema, RECORD_TEMPORARY_FILE;
5090
5285
  var init_state = __esm({
5091
5286
  "src/frontdoor/state.ts"() {
5092
5287
  "use strict";
5093
- import_node_path12 = __toESM(require("node:path"), 1);
5094
- import_zod8 = require("zod");
5288
+ import_node_path13 = __toESM(require("node:path"), 1);
5289
+ import_zod9 = require("zod");
5095
5290
  init_schema();
5291
+ init_baseUrlDial();
5096
5292
  init_providerCatalogue();
5097
5293
  FRONT_DOOR_PROTOCOL = 8;
5098
5294
  FRONT_DOOR_HANDOVER_PROTOCOL = 6;
5099
- FrontDoorSessionSchema = import_zod8.z.strictObject({ pid: import_zod8.z.number().int().positive(), startedAt: import_zod8.z.number(), token: import_zod8.z.string().min(1), supervisorPid: import_zod8.z.number().int().positive().optional(), sessionId: import_zod8.z.string().min(1).optional(), identity: import_zod8.z.string().min(1).optional(), models: ModelsConfigSchema.optional() });
5100
- FrontDoorStateSchema = import_zod8.z.strictObject({
5295
+ FrontDoorSessionSchema = import_zod9.z.strictObject({ pid: import_zod9.z.number().int().positive(), startedAt: import_zod9.z.number(), token: import_zod9.z.string().min(1), supervisorPid: import_zod9.z.number().int().positive().optional(), sessionId: import_zod9.z.string().min(1).optional(), identity: import_zod9.z.string().min(1).optional(), models: ModelsConfigSchema.optional() });
5296
+ FrontDoorStateSchema = import_zod9.z.strictObject({
5101
5297
  /**
5102
5298
  * The launcher-to-door wire protocol this supervisor speaks, written once it is serving; absent in state written by a release that predates the field, which `ensureFrontDoor` reads as protocol 0. A launcher replaces a door whose protocol is lower than its own (see `FRONT_DOOR_PROTOCOL`).
5103
5299
  */
5104
- protocol: import_zod8.z.number().int().nonnegative().optional(),
5300
+ protocol: import_zod9.z.number().int().nonnegative().optional(),
5105
5301
  /** The supervisor process serving the front door. Alive means both listeners are up in that process. */
5106
- supervisorPid: import_zod8.z.number().int().positive().optional(),
5302
+ supervisorPid: import_zod9.z.number().int().positive().optional(),
5107
5303
  /** The loopback port the HTTPS provider listener serves on. Absent until the listener has bound and answered its health probe, so "port is set" is itself the ready signal a launcher polls for. */
5108
- port: import_zod8.z.number().int().positive().optional(),
5304
+ port: import_zod9.z.number().int().positive().optional(),
5109
5305
  /**
5110
5306
  * The sticky port preference for the provider listener: kept across crashes, restarts and idle shutdowns so every provider session, whose base URL was frozen at launch, keeps finding the front door at the same address.
5111
5307
  */
5112
- lastPort: import_zod8.z.number().int().positive().optional(),
5308
+ lastPort: import_zod9.z.number().int().positive().optional(),
5113
5309
  /**
5114
5310
  * The loopback port the CONNECT surface listens on. Absent whenever no supervisor is serving it, so "connectPort is set" is the ready signal an OAuth launch polls for alongside `port`.
5115
5311
  */
5116
- connectPort: import_zod8.z.number().int().positive().optional(),
5312
+ connectPort: import_zod9.z.number().int().positive().optional(),
5117
5313
  /**
5118
5314
  * The sticky port preference for the CONNECT surface, the exact analogue of `lastPort` for the second listener: it survives every shutdown, because every OAuth session's environment was frozen at launch with HTTPS_PROXY pointing at this address and a restart that moves strands them.
5119
5315
  */
5120
- lastConnectPort: import_zod8.z.number().int().positive().optional(),
5316
+ lastConnectPort: import_zod9.z.number().int().positive().optional(),
5121
5317
  /**
5122
5318
  * The loopback port the direct listener serves on: the listener a headroom hop tells the daemon to forward routed traffic back to. Sticky like the others, because headroom's allowlist admits its exact origin: the headroom supervisor rewrites the daemon's allowlist file when the origin moves, but a provider launch waits at its gate until it has, so an ephemeral port would hold launches up after every restart.
5123
5319
  */
5124
- directPort: import_zod8.z.number().int().positive().optional(),
5320
+ directPort: import_zod9.z.number().int().positive().optional(),
5125
5321
  /** The sticky port preference for the direct listener, for the reason `directPort` gives. */
5126
- lastDirectPort: import_zod8.z.number().int().positive().optional(),
5322
+ lastDirectPort: import_zod9.z.number().int().positive().optional(),
5127
5323
  /** The last fatal error, kept across shutdowns so `frontdoor status` can explain a front door that is not running. */
5128
- lastError: import_zod8.z.string().optional()
5324
+ lastError: import_zod9.z.string().optional()
5129
5325
  });
5130
- MAX_TCP_PORT = 65535;
5131
- FrontDoorDirectRecordSchema = import_zod8.z.strictObject({ directPort: import_zod8.z.number().int().positive().max(MAX_TCP_PORT) });
5326
+ FrontDoorDirectRecordSchema = import_zod9.z.strictObject({ directPort: import_zod9.z.number().int().positive().max(MAX_TCP_PORT) });
5132
5327
  RECORD_TEMPORARY_FILE = /^[1-9]\d*\.json\.([1-9]\d*)\.tmp$/;
5133
5328
  }
5134
5329
  });
5135
5330
 
5136
- // src/processRole.ts
5137
- function enterProcessRole(role) {
5138
- const previous = currentRole;
5139
- currentRole = role;
5140
- return () => {
5141
- currentRole = previous;
5142
- };
5143
- }
5144
- function noteBlockingStep() {
5145
- blockingStepObserver?.();
5146
- }
5147
- function refuseToBlockInRole(operation) {
5148
- noteBlockingStep();
5149
- if (currentRole !== void 0) {
5150
- throw new BlockingInEventLoopError(operation, currentRole);
5151
- }
5152
- }
5153
- var currentRole, BlockingInEventLoopError, blockingStepObserver;
5154
- var init_processRole = __esm({
5155
- "src/processRole.ts"() {
5156
- "use strict";
5157
- init_cliError();
5158
- BlockingInEventLoopError = class extends CliError {
5159
- constructor(operation, role) {
5160
- super(
5161
- `${operation} blocks the calling thread, which in the ${role} is the event loop that answers every session; it must not run there (a launch planned inside the door reaches it through its own addresses, never through the launcher's synchronous coordination)`
5162
- );
5163
- this.name = "BlockingInEventLoopError";
5164
- }
5165
- };
5166
- }
5167
- });
5168
-
5169
- // src/frontdoor/catalogueCleanup.ts
5170
- async function pruneAbandonedCatalogueGenerations(fs17, paths, ownPid, generation, runningAmong) {
5171
- const root = import_node_path13.default.join(paths.catalogueDir, "supervisors");
5172
- const owners = fs17.readdir(root).flatMap((entry) => {
5173
- const pid = Number(entry);
5174
- return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry && fs17.lstat(import_node_path13.default.join(root, entry))?.kind === "dir" ? [pid] : [];
5175
- });
5176
- const running = await runningAmong(owners);
5177
- for (const pid of owners) {
5178
- if (pid !== ownPid && running.has(pid)) continue;
5179
- const directory = import_node_path13.default.join(root, String(pid));
5180
- for (const entry of fs17.readdir(directory)) {
5181
- const candidate = import_node_path13.default.join(directory, entry);
5182
- if (import_zod9.z.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) && fs17.lstat(candidate)?.kind === "dir") fs17.removeRecursive(candidate);
5183
- }
5184
- }
5185
- }
5186
- var import_node_path13, import_zod9;
5187
- var init_catalogueCleanup = __esm({
5188
- "src/frontdoor/catalogueCleanup.ts"() {
5189
- "use strict";
5190
- import_node_path13 = __toESM(require("node:path"), 1);
5191
- import_zod9 = require("zod");
5192
- }
5193
- });
5194
-
5195
5331
  // src/frontdoor/supervisor.ts
5196
5332
  function watchedInstallEntry(resolvedOwnExecutablePath, siblingExists) {
5197
5333
  const parsed = import_node_path14.default.parse(resolvedOwnExecutablePath);
@@ -5440,17 +5576,8 @@ var init_supervisor = __esm({
5440
5576
 
5441
5577
  // src/frontdoor/connect.ts
5442
5578
  function parseConnectTarget(authority) {
5443
- const colon = authority.lastIndexOf(":");
5444
- if (colon === -1) {
5445
- const host2 = authority.trim().toLowerCase();
5446
- return host2 === "" ? void 0 : { host: host2, port: HTTPS_PORT };
5447
- }
5448
- const host = authority.slice(0, colon).trim().toLowerCase();
5449
- const port = Number.parseInt(authority.slice(colon + 1), 10);
5450
- if (host === "" || !Number.isInteger(port) || port <= 0 || port > MAX_TCP_PORT) {
5451
- return void 0;
5452
- }
5453
- return { host, port };
5579
+ const parsed = parseDialAuthority(authority, HTTPS_PORT);
5580
+ return "refusal" in parsed ? void 0 : parsed;
5454
5581
  }
5455
5582
  function isInterceptedHost(host, interceptHosts) {
5456
5583
  return interceptHosts.includes(host);
@@ -5769,9 +5896,9 @@ function routeConnect(socket, head, context) {
5769
5896
  const requestLine = head.split("\r\n", 1)[0] ?? "";
5770
5897
  const parts = requestLine.split(" ");
5771
5898
  const authority = parts.length === CONNECT_LINE_TOKENS && parts[0]?.toUpperCase() === "CONNECT" ? parts[1] ?? "" : void 0;
5772
- const target = authority === void 0 ? void 0 : parseConnectTarget(authority);
5773
- if (target === void 0) {
5774
- refuse(socket, REFUSAL.badRequest);
5899
+ const target = authority === void 0 ? void 0 : parseDialAuthority(authority, HTTPS_PORT);
5900
+ if (target === void 0 || "refusal" in target) {
5901
+ refuse(socket, REFUSAL.badRequest, target === void 0 ? [] : [`${REFUSAL_HEADER}: ${target.refusal}`]);
5775
5902
  return;
5776
5903
  }
5777
5904
  const session = sessions.find((entry) => entry.host === target.host);
@@ -5842,17 +5969,17 @@ function realConnectCertStore(paths) {
5842
5969
  }
5843
5970
  };
5844
5971
  }
5845
- var import_node_crypto5, fs3, CONNECT_INTERCEPT_HOST, CONNECT_INTERCEPT_HOSTS, ROUTED_PATH_PREFIX, HTTPS_PORT, HTTP_BAD_GATEWAY, CA_KEY_FILE_MODE, CONNECT_LINE_TOKENS, HEAD_TERMINATOR, MAX_CONNECT_HEAD_BYTES, CONNECT_ESTABLISHED, REFUSAL, CONNECT_LIMITS, CA_VALIDITY_DAYS, LEAF_VALIDITY_DAYS, CA_SUBJECT_COMMON_NAME, MS_PER_DAY, HOP_BY_HOP_HEADERS, TAP_ALPN_PROTOCOLS;
5972
+ var import_node_crypto5, fs3, CONNECT_INTERCEPT_HOST, CONNECT_INTERCEPT_HOSTS, ROUTED_PATH_PREFIX, HTTPS_PORT, HTTP_BAD_GATEWAY, CA_KEY_FILE_MODE, CONNECT_LINE_TOKENS, HEAD_TERMINATOR, MAX_CONNECT_HEAD_BYTES, CONNECT_ESTABLISHED, REFUSAL_HEADER, REFUSAL, CONNECT_LIMITS, CA_VALIDITY_DAYS, LEAF_VALIDITY_DAYS, CA_SUBJECT_COMMON_NAME, MS_PER_DAY, HOP_BY_HOP_HEADERS, TAP_ALPN_PROTOCOLS;
5846
5973
  var init_connect = __esm({
5847
5974
  "src/frontdoor/connect.ts"() {
5848
5975
  "use strict";
5849
5976
  import_node_crypto5 = require("node:crypto");
5850
5977
  fs3 = __toESM(require("node:fs"), 1);
5978
+ init_baseUrlDial();
5851
5979
  init_x509();
5852
5980
  init_tap();
5853
5981
  init_capability();
5854
5982
  init_route();
5855
- init_state();
5856
5983
  init_supervisor();
5857
5984
  CONNECT_INTERCEPT_HOST = "api.anthropic.com";
5858
5985
  CONNECT_INTERCEPT_HOSTS = [CONNECT_INTERCEPT_HOST, "platform.claude.com"];
@@ -5864,6 +5991,7 @@ var init_connect = __esm({
5864
5991
  HEAD_TERMINATOR = "\r\n\r\n";
5865
5992
  MAX_CONNECT_HEAD_BYTES = 8192;
5866
5993
  CONNECT_ESTABLISHED = "HTTP/1.1 200 Connection Established\r\n\r\n";
5994
+ REFUSAL_HEADER = "x-agent-shim-refusal";
5867
5995
  REFUSAL = {
5868
5996
  badRequest: "400 Bad Request",
5869
5997
  proxyAuthenticationRequired: "407 Proxy Authentication Required",
@@ -8102,6 +8230,20 @@ function createDoorLookup(io) {
8102
8230
  });
8103
8231
  };
8104
8232
  }
8233
+ function sourcePortClassifier(platform) {
8234
+ const classify = (error) => {
8235
+ const attempts = Reflect.get(error, "errors");
8236
+ if (Array.isArray(attempts) && attempts.length > 0) {
8237
+ const kinds = attempts.map((attempt) => attempt instanceof Error ? classify(attempt) : void 0);
8238
+ return kinds.includes("excluded") ? "excluded" : kinds.includes("held") ? "held" : void 0;
8239
+ }
8240
+ if (error.code === "EADDRINUSE" || error.code === "EADDRNOTAVAIL") {
8241
+ return "held";
8242
+ }
8243
+ return platform === "win32" && error.code === "EACCES" && error.syscall === "bind" ? "excluded" : void 0;
8244
+ };
8245
+ return classify;
8246
+ }
8105
8247
  function doorDial(io, target, ports) {
8106
8248
  const dialOnce = (options) => new Promise((resolve) => {
8107
8249
  const socket = io.connect(options);
@@ -8114,12 +8256,15 @@ function doorDial(io, target, ports) {
8114
8256
  if (error.message === "" && Array.isArray(attempts) && attempts.length > 0) {
8115
8257
  const flattened = new Error(attempts.map((attempt) => withoutLocalEnd(attempt instanceof Error ? attempt.message : String(attempt))).join("; "));
8116
8258
  flattened.code = error.code;
8259
+ flattened.syscall = error.syscall;
8260
+ Object.defineProperty(flattened, "errors", { value: attempts });
8117
8261
  resolve({ error: flattened, socket });
8118
8262
  return;
8119
8263
  }
8120
8264
  if (withoutLocalEnd(error.message) !== error.message) {
8121
8265
  const trimmed = new Error(withoutLocalEnd(error.message));
8122
8266
  trimmed.code = error.code;
8267
+ trimmed.syscall = error.syscall;
8123
8268
  resolve({ error: trimmed, socket });
8124
8269
  return;
8125
8270
  }
@@ -8129,17 +8274,35 @@ function doorDial(io, target, ports) {
8129
8274
  if (io.isIP(target.host) !== 0) {
8130
8275
  return dialOnce({ host: target.host, port: target.port });
8131
8276
  }
8132
- const attemptFrom = (attempt) => dialOnce({ host: target.host, port: target.port, localPort: ports.take(), lookup: io.lookup }).then((outcome) => {
8133
- if (outcome.error === null) {
8134
- return outcome;
8135
- }
8136
- const held = outcome.error.code === "EADDRINUSE" || outcome.error.code === "EADDRNOTAVAIL";
8137
- if (!held || attempt === ports.count - 1) {
8138
- return outcome;
8139
- }
8140
- return attemptFrom(attempt + 1);
8141
- });
8142
- return attemptFrom(0);
8277
+ const attemptFrom = (attempt, refused2) => {
8278
+ const port = ports.take();
8279
+ return dialOnce({ host: target.host, port: target.port, localPort: port, lookup: io.lookup }).then((outcome) => {
8280
+ if (outcome.error === null) {
8281
+ return outcome;
8282
+ }
8283
+ const failure = io.sourcePortFailure(outcome.error);
8284
+ if (failure === void 0) {
8285
+ return outcome;
8286
+ }
8287
+ if (failure === "excluded") {
8288
+ ports.exclude(port);
8289
+ }
8290
+ const refusedSoFar = failure === "excluded" ? refused2 + 1 : refused2;
8291
+ if (attempt < ports.count - 1) {
8292
+ return attemptFrom(attempt + 1, refusedSoFar);
8293
+ }
8294
+ if (refusedSoFar === 0) {
8295
+ return outcome;
8296
+ }
8297
+ const scope = refusedSoFar === ports.count ? "every source port" : `${String(refusedSoFar)} of its ${String(ports.count)} source ports (the rest were held by other sockets)`;
8298
+ const refusal2 = new Error(
8299
+ `${scope} of the door's reserved range (${String(ports.start)} to ${String(ports.end)}) could not be bound: Windows refuses a port inside an excluded range with EACCES (Hyper-V, WSL2 and Docker Desktop reserve blocks of ports). List the excluded ranges with \`netsh int ipv4 show excludedportrange protocol=tcp\``
8300
+ );
8301
+ refusal2.code = refusedSoFar === ports.count ? "EACCES" : outcome.error.code;
8302
+ return { error: refusal2, socket: outcome.socket };
8303
+ });
8304
+ };
8305
+ return attemptFrom(0, 0);
8143
8306
  }
8144
8307
  function probeAccept(dial, timeoutMs, startTimer) {
8145
8308
  return new Promise((resolve) => {
@@ -8174,7 +8337,7 @@ function runAcceptProbe(deps, data, startTimer) {
8174
8337
  const lookup2 = deps.createDoorLookup({ isIP: deps.net.isIP, resolve4: (name, callback) => {
8175
8338
  deps.dns.resolve4(name, callback);
8176
8339
  } });
8177
- const io = { connect: (options) => deps.net.connect(options), lookup: lookup2, isIP: deps.net.isIP };
8340
+ const io = { connect: (options) => deps.net.connect(options), lookup: lookup2, isIP: deps.net.isIP, sourcePortFailure: deps.sourcePortClassifier(data.platform) };
8178
8341
  return deps.probeAccept(() => deps.doorDial(io, { host: data.host, port: data.port }, new deps.SourcePortRange(data.portStart, data.portEnd, data.portFirst)), data.timeoutMs, startTimer);
8179
8342
  }
8180
8343
  var init_doorDial = __esm({
@@ -8187,14 +8350,17 @@ var init_doorDial = __esm({
8187
8350
  function isSuccessful2(status) {
8188
8351
  return status >= HTTP_STATUS.ok && status < SUCCESS_STATUS_MAX_EXCLUSIVE2;
8189
8352
  }
8353
+ function realDoorDialIo(platform = process.platform, connect3 = (options) => net2.connect(options)) {
8354
+ return { connect: connect3, lookup: realAddressLookup, isIP: net2.isIP, sourcePortFailure: sourcePortClassifier(platform) };
8355
+ }
8190
8356
  function dialTarget(options, defaultPort) {
8191
8357
  return { host: typeof options.host === "string" ? options.host : "", port: typeof options.port === "number" ? options.port : defaultPort };
8192
8358
  }
8193
8359
  function literalDial(target) {
8194
8360
  return net2.connect({ host: target.host, port: target.port });
8195
8361
  }
8196
- async function reservedDial(target, ports) {
8197
- return await doorDial(realDialIo, target, ports);
8362
+ async function reservedDial(target, ports, io) {
8363
+ return await doorDial(io, target, ports);
8198
8364
  }
8199
8365
  function requestServername(options, fallback) {
8200
8366
  return "servername" in options && typeof options.servername === "string" && options.servername !== "" ? options.servername : fallback;
@@ -8334,9 +8500,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
8334
8500
  }
8335
8501
  };
8336
8502
  }
8337
- function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
8338
- const plainAgent = new ExemptHttpAgent(ports);
8339
- const tlsAgent = new ExemptTlsAgent(ports);
8503
+ function realConnectEffects(ports = DOOR_SOURCE_PORTS, io = realDoorDialIo()) {
8504
+ const plainAgent = new ExemptHttpAgent(ports, io);
8505
+ const tlsAgent = new ExemptTlsAgent(ports, io);
8340
8506
  const listenOnce = async (target, onSocket) => await new Promise((resolve, reject) => {
8341
8507
  const accepted = /* @__PURE__ */ new Set();
8342
8508
  const server = net2.createServer((socket) => {
@@ -8468,7 +8634,7 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
8468
8634
  };
8469
8635
  },
8470
8636
  connectTlsUpstream: async (host, port, clientAlpn) => {
8471
- const dialled = await reservedDial({ host, port }, ports);
8637
+ const dialled = await reservedDial({ host, port }, ports, io);
8472
8638
  if (dialled.error !== null) {
8473
8639
  throw dialled.error;
8474
8640
  }
@@ -8549,7 +8715,7 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
8549
8715
  }
8550
8716
  };
8551
8717
  }
8552
- var import_node_dns, http, https2, net2, tls, SUCCESS_STATUS_MAX_EXCLUSIVE2, SourcePortRange, DOOR_SOURCE_PORT_START, DOOR_SOURCE_PORT_COUNT, DOOR_SOURCE_PORT_END, DOOR_SOURCE_PORTS, POOLED_SOCKET_IDLE_MS, POOLED_SOCKETS_KEPT_IDLE, POOLING, realAddressLookup, realDialIo, HTTP_PORT, ExemptHttpAgent, ExemptTlsAgent, NO_CHUNKS;
8718
+ var import_node_dns, http, https2, net2, tls, SUCCESS_STATUS_MAX_EXCLUSIVE2, SourcePortRange, DOOR_SOURCE_PORT_START, DOOR_SOURCE_PORT_COUNT, DOOR_SOURCE_PORT_END, DOOR_SOURCE_PORTS, POOLED_SOCKET_IDLE_MS, POOLED_SOCKETS_KEPT_IDLE, POOLING, realAddressLookup, HTTP_PORT, ExemptHttpAgent, ExemptTlsAgent, NO_CHUNKS;
8553
8719
  var init_connectEffects = __esm({
8554
8720
  "src/frontdoor/connectEffects.ts"() {
8555
8721
  "use strict";
@@ -8571,13 +8737,28 @@ var init_connectEffects = __esm({
8571
8737
  this.end = end;
8572
8738
  this.count = end - start + 1;
8573
8739
  this.next = first;
8740
+ this.excluded = /* @__PURE__ */ new Set();
8574
8741
  }
8575
- /** The next port in rotation, wrapping from the end back to the start. */
8742
+ /**
8743
+ * The next port in rotation, wrapping from the end back to the start, skipping every port the system has refused to bind (`exclude`) so a dial does not walk a refused block again. A cycle that finds nothing else forgets the refusals and starts over: the exclusions of a host can change while the door runs, and a range refused throughout is then tried again, one pass, not skipped for ever. The memory is a set of ports of the range, so it holds at most `count` entries.
8744
+ */
8576
8745
  take() {
8746
+ for (let skipped = 0; skipped < this.count; skipped += 1) {
8747
+ const port2 = this.next;
8748
+ this.next = this.next === this.end ? this.start : this.next + 1;
8749
+ if (!this.excluded.has(port2)) {
8750
+ return port2;
8751
+ }
8752
+ }
8753
+ this.excluded.clear();
8577
8754
  const port = this.next;
8578
8755
  this.next = this.next === this.end ? this.start : this.next + 1;
8579
8756
  return port;
8580
8757
  }
8758
+ /** Remembers that the system refuses to bind `port`, so `take` skips it. Only an exclusion belongs here: a port a sibling holds is free again when the sibling closes. */
8759
+ exclude(port) {
8760
+ this.excluded.add(port);
8761
+ }
8581
8762
  };
8582
8763
  DOOR_SOURCE_PORT_START = 47900;
8583
8764
  DOOR_SOURCE_PORT_COUNT = 1e3;
@@ -8589,39 +8770,42 @@ var init_connectEffects = __esm({
8589
8770
  realAddressLookup = createDoorLookup({ isIP: net2.isIP, resolve4: (host, callback) => {
8590
8771
  import_node_dns.default.resolve4(host, callback);
8591
8772
  } });
8592
- realDialIo = { connect: (options) => net2.connect(options), lookup: realAddressLookup, isIP: net2.isIP };
8593
8773
  HTTP_PORT = 80;
8594
8774
  ExemptHttpAgent = class extends http.Agent {
8595
- constructor(ports = DOOR_SOURCE_PORTS) {
8775
+ constructor(ports = DOOR_SOURCE_PORTS, io = realDoorDialIo()) {
8596
8776
  super(POOLING);
8597
8777
  this.ports = ports;
8778
+ this.io = io;
8598
8779
  }
8599
8780
  ports;
8781
+ io;
8600
8782
  // A reserved-port dial that has to retry cannot produce its socket synchronously, so it settles first and arrives through the callback (node's documented asynchronous createConnection form); a literal dial has nothing to retry and keeps node's own synchronous shape.
8601
8783
  createConnection(options, oncreate) {
8602
8784
  const target = dialTarget(options, HTTP_PORT);
8603
8785
  if (net2.isIP(target.host) !== 0) {
8604
8786
  return literalDial(target);
8605
8787
  }
8606
- void reservedDial(target, this.ports).then((outcome) => {
8788
+ void reservedDial(target, this.ports, this.io).then((outcome) => {
8607
8789
  oncreate?.(outcome.error, outcome.socket);
8608
8790
  });
8609
8791
  return void 0;
8610
8792
  }
8611
8793
  };
8612
8794
  ExemptTlsAgent = class extends https2.Agent {
8613
- constructor(ports = DOOR_SOURCE_PORTS) {
8795
+ constructor(ports = DOOR_SOURCE_PORTS, io = realDoorDialIo()) {
8614
8796
  super(POOLING);
8615
8797
  this.ports = ports;
8798
+ this.io = io;
8616
8799
  }
8617
8800
  ports;
8801
+ io;
8618
8802
  // The same split as the plain sibling: a literal dial wraps TLS around the socket node's own agent would have returned, a reserved dial settles (retries included) first and arrives through the callback, which is exactly where node's own agent wraps its own dials.
8619
8803
  createConnection(options, oncreate) {
8620
8804
  const target = dialTarget(options, HTTPS_PORT);
8621
8805
  if (net2.isIP(target.host) !== 0) {
8622
8806
  return tls.connect({ socket: literalDial(target), servername: requestServername(options, target.host), ...tlsFacts(options) });
8623
8807
  }
8624
- void reservedDial(target, this.ports).then((outcome) => {
8808
+ void reservedDial(target, this.ports, this.io).then((outcome) => {
8625
8809
  if (outcome.error !== null) {
8626
8810
  oncreate?.(outcome.error, outcome.socket);
8627
8811
  return;
@@ -10672,6 +10856,9 @@ function reportableAllowlistFileProblem(allowlistFile, ports, served) {
10672
10856
  return problem?.repairable === false || served ? problem : void 0;
10673
10857
  }
10674
10858
  function verifyAllowlistFile(allowlistFile, ports) {
10859
+ if (platformRefusal(ports.platform) !== void 0) {
10860
+ return void 0;
10861
+ }
10675
10862
  const uid = ports.currentUid();
10676
10863
  const directories = pathDirectories(allowlistFile, ports);
10677
10864
  if (typeof directories === "string") {
@@ -11743,7 +11930,10 @@ var init_realPorts = __esm({
11743
11930
  };
11744
11931
  SOCKET_PERMISSION_BITS = 4095;
11745
11932
  realHeadroomSocketTrust = {
11746
- platform: process.platform,
11933
+ // Read at each use, not fixed when the module loads, so what the checks do for a platform is testable through the real wiring.
11934
+ get platform() {
11935
+ return process.platform;
11936
+ },
11747
11937
  currentUid: () => {
11748
11938
  if (process.getuid === void 0) {
11749
11939
  throw new Error(`no POSIX user id on ${process.platform}`);
@@ -13686,7 +13876,7 @@ var init_package = __esm({
13686
13876
  "package.json"() {
13687
13877
  package_default = {
13688
13878
  name: "claude-use",
13689
- version: "14.0.1",
13879
+ version: "14.0.3",
13690
13880
  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.",
13691
13881
  license: "MIT",
13692
13882
  author: "Joseph Mearman <joseph@mearman.co.uk>",
@@ -13735,7 +13925,7 @@ var init_package = __esm({
13735
13925
  schema: "node scripts/gen-schema.mts"
13736
13926
  },
13737
13927
  dependencies: {
13738
- "@anthropic-ai/claude-agent-sdk": "0.3.311",
13928
+ "@anthropic-ai/claude-agent-sdk": "0.3.316",
13739
13929
  "@clack/prompts": "^1.8.0",
13740
13930
  "@modelcontextprotocol/sdk": "1.32.0",
13741
13931
  "@orpc/client": "2.0.0-beta.46",
@@ -14950,26 +15140,6 @@ var init_paths = __esm({
14950
15140
  }
14951
15141
  });
14952
15142
 
14953
- // src/baseUrlDial.ts
14954
- function dialHostOf(url) {
14955
- return url.hostname.replace(/^\[(.*)\]$/, "$1");
14956
- }
14957
- function dialTargetOf(baseUrl) {
14958
- const url = new URL(baseUrl);
14959
- const defaultPort = DEFAULT_PORTS[url.protocol];
14960
- if (defaultPort === void 0) {
14961
- throw new Error(`${url.protocol} is not a scheme a provider's base URL can have`);
14962
- }
14963
- return { host: dialHostOf(url), port: url.port === "" ? defaultPort : Number(url.port) };
14964
- }
14965
- var DEFAULT_PORTS;
14966
- var init_baseUrlDial = __esm({
14967
- "src/baseUrlDial.ts"() {
14968
- "use strict";
14969
- DEFAULT_PORTS = { "http:": 80, "https:": 443 };
14970
- }
14971
- });
14972
-
14973
15143
  // src/frontdoor/probe.ts
14974
15144
  function probeWorkerSource(body) {
14975
15145
  return `const { workerData } = require("node:worker_threads");
@@ -14986,7 +15156,7 @@ function probeFrontDoorSync(port, caPem, timeoutMs = PROBE_TIMEOUT_MS, workers =
14986
15156
  }
14987
15157
  function probeListenerAcceptSync(port, timeoutMs = PROBE_TIMEOUT_MS, workers = realProbeWorkers) {
14988
15158
  refuseToBlockInRole("a synchronous probe of a front door listener");
14989
- return workers.start(ACCEPT_PROBE_SOURCE, { host: "127.0.0.1", port, portStart: DOOR_SOURCE_PORT_START, portEnd: DOOR_SOURCE_PORT_END }, timeoutMs).verdict();
15159
+ return workers.start(ACCEPT_PROBE_SOURCE, { host: "127.0.0.1", port, portStart: DOOR_SOURCE_PORT_START, portEnd: DOOR_SOURCE_PORT_END, platform: process.platform }, timeoutMs).verdict();
14990
15160
  }
14991
15161
  function startAddressProbes(targets, workers = realProbeWorkers, portBase) {
14992
15162
  refuseToBlockInRole("a synchronous probe of a provider's address");
@@ -15011,7 +15181,7 @@ function startAddressProbes(targets, workers = realProbeWorkers, portBase) {
15011
15181
  }
15012
15182
  const portFirst = DOOR_SOURCE_PORT_START + (base + index * stride) % DOOR_SOURCE_PORT_COUNT;
15013
15183
  try {
15014
- const started = workers.start(ACCEPT_PROBE_SOURCE, { host: target.host, port: target.port, portStart: DOOR_SOURCE_PORT_START, portEnd: DOOR_SOURCE_PORT_END, portFirst }, target.timeoutMs);
15184
+ const started = workers.start(ACCEPT_PROBE_SOURCE, { host: target.host, port: target.port, portStart: DOOR_SOURCE_PORT_START, portEnd: DOOR_SOURCE_PORT_END, portFirst, platform: process.platform }, target.timeoutMs);
15015
15185
  running.push({ key: targetKey(target), verdict: started.verdict, cancel: started.cancel });
15016
15186
  } catch (error) {
15017
15187
  const reason = `${PROBE_WORKER_FAILURE_PREFIX}the worker could not be started: ${error instanceof Error ? error.message : String(error)}`;
@@ -15186,15 +15356,16 @@ request.end();
15186
15356
  ACCEPT_PROBE_SOURCE = probeWorkerSource(`
15187
15357
  const net = require("node:net");
15188
15358
  const dns = require("node:dns");
15189
- const { host, port, portStart, portEnd, portFirst, timeoutMs, ok, failed } = workerData;
15359
+ const { host, port, portStart, portEnd, portFirst, platform, timeoutMs, ok, failed } = workerData;
15190
15360
  const finish = finishProbe;
15191
15361
  const SourcePortRange = ${SourcePortRange.toString()};
15192
15362
  const createDoorLookup = ${createDoorLookup.toString()};
15363
+ const sourcePortClassifier = ${sourcePortClassifier.toString()};
15193
15364
  const doorDial = ${doorDial.toString()};
15194
15365
  const probeAccept = ${probeAccept.toString()};
15195
15366
  const runAcceptProbe = ${runAcceptProbe.toString()};
15196
15367
  const startTimer = (callback, ms) => { const timer = setTimeout(callback, ms); return () => { clearTimeout(timer); }; };
15197
- runAcceptProbe({ net, dns, createDoorLookup, doorDial, probeAccept, SourcePortRange }, { host, port, portStart, portEnd, portFirst, timeoutMs }, startTimer).then((verdict) => {
15368
+ runAcceptProbe({ net, dns, createDoorLookup, doorDial, probeAccept, SourcePortRange, sourcePortClassifier }, { host, port, portStart, portEnd, portFirst, platform, timeoutMs }, startTimer).then((verdict) => {
15198
15369
  finish(verdict.ok ? ok : failed, verdict.ok ? "" : verdict.reason);
15199
15370
  });
15200
15371
  `);
@@ -19256,13 +19427,13 @@ function withRegisteredSessionFacts(statuses, registry) {
19256
19427
  };
19257
19428
  });
19258
19429
  }
19259
- function withIdentityNames(statuses, nameOf) {
19430
+ function withIdentityNames(statuses, nameOf2) {
19260
19431
  return statuses.map((status) => {
19261
19432
  if (status.identity === void 0) {
19262
19433
  return status;
19263
19434
  }
19264
19435
  const { identity: id, ...rest } = status;
19265
- const name = nameOf(id);
19436
+ const name = nameOf2(id);
19266
19437
  return name === void 0 ? rest : { ...rest, identity: name };
19267
19438
  });
19268
19439
  }