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/cli.cjs +14511 -14029
- package/dist/index.cjs +358 -187
- package/dist/index.mjs +350 -179
- package/dist/types/index.d.ts +30 -4
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -74,14 +74,42 @@ var init_categories_default = __esm({
|
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
// src/
|
|
78
|
-
function
|
|
79
|
-
const
|
|
80
|
-
return
|
|
77
|
+
// src/hostName.ts
|
|
78
|
+
function isDottedDecimalIpv4(host) {
|
|
79
|
+
const parts = host.split(".");
|
|
80
|
+
return parts.length === IPV4_PARTS && parts.every((part) => IPV4_PART.test(part) && Number(part) <= MAX_OCTET);
|
|
81
81
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
82
|
+
function dnsNameProblem(name) {
|
|
83
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
84
|
+
return `a host longer than ${String(MAX_NAME_LENGTH)} characters`;
|
|
85
|
+
}
|
|
86
|
+
const labels = name.split(".");
|
|
87
|
+
if (labels.some((label) => label.length > MAX_LABEL_LENGTH)) {
|
|
88
|
+
return `a host with a label longer than ${String(MAX_LABEL_LENGTH)} characters`;
|
|
89
|
+
}
|
|
90
|
+
if (!labels.every((label) => LABEL.test(label))) {
|
|
91
|
+
return "a host that is not letters, digits, underscores and interior hyphens in non-empty dot-separated labels";
|
|
92
|
+
}
|
|
93
|
+
if (NUMERIC_LAST_LABEL.test(labels[labels.length - 1] ?? "")) {
|
|
94
|
+
return "a numeric host that is not a dotted-decimal IPv4 address";
|
|
95
|
+
}
|
|
96
|
+
return void 0;
|
|
84
97
|
}
|
|
98
|
+
var MAX_LABEL_LENGTH, MAX_NAME_LENGTH, IPV4_PARTS, MAX_OCTET, LABEL, NUMERIC_LAST_LABEL, IPV4_PART;
|
|
99
|
+
var init_hostName = __esm({
|
|
100
|
+
"src/hostName.ts"() {
|
|
101
|
+
"use strict";
|
|
102
|
+
MAX_LABEL_LENGTH = 63;
|
|
103
|
+
MAX_NAME_LENGTH = 253;
|
|
104
|
+
IPV4_PARTS = 4;
|
|
105
|
+
MAX_OCTET = 255;
|
|
106
|
+
LABEL = /^[a-z0-9_](?:[a-z0-9_-]*[a-z0-9_])?$/i;
|
|
107
|
+
NUMERIC_LAST_LABEL = /^(?:\d+|0x[0-9a-f]*)$/i;
|
|
108
|
+
IPV4_PART = /^(?:0|[1-9]\d{0,2})$/;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// src/config/proxyBypass.ts
|
|
85
113
|
function proxyBypassSyntaxProblem(entry) {
|
|
86
114
|
if (entry === "" || entry !== entry.trim()) {
|
|
87
115
|
return "is empty or has surrounding whitespace";
|
|
@@ -98,21 +126,15 @@ function proxyBypassSyntaxProblem(entry) {
|
|
|
98
126
|
if (entry.includes(":")) {
|
|
99
127
|
return "has a port, which the proxy variable cannot express: list the host alone";
|
|
100
128
|
}
|
|
101
|
-
return
|
|
129
|
+
return isDottedDecimalIpv4(entry) || dnsNameProblem(entry.replace(/^\./, "")) === void 0 ? void 0 : "is not a host name or an IPv4 address";
|
|
102
130
|
}
|
|
103
131
|
function proxyBypassName(entry) {
|
|
104
|
-
return
|
|
132
|
+
return isDottedDecimalIpv4(entry) ? void 0 : entry.replace(/^\./, "").toLowerCase();
|
|
105
133
|
}
|
|
106
|
-
var MAX_NAME_LENGTH, MAX_LABEL_LENGTH, MAX_OCTET, LABEL_RE, IPV4_RE, DIGITS_RE;
|
|
107
134
|
var init_proxyBypass = __esm({
|
|
108
135
|
"src/config/proxyBypass.ts"() {
|
|
109
136
|
"use strict";
|
|
110
|
-
|
|
111
|
-
MAX_LABEL_LENGTH = 63;
|
|
112
|
-
MAX_OCTET = 255;
|
|
113
|
-
LABEL_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/;
|
|
114
|
-
IPV4_RE = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
|
115
|
-
DIGITS_RE = /^\d+$/;
|
|
137
|
+
init_hostName();
|
|
116
138
|
}
|
|
117
139
|
});
|
|
118
140
|
|
|
@@ -308,7 +330,7 @@ function resolveStatusline(settings) {
|
|
|
308
330
|
}
|
|
309
331
|
return resolved;
|
|
310
332
|
}
|
|
311
|
-
var 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,
|
|
333
|
+
var 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;
|
|
312
334
|
var init_statusline = __esm({
|
|
313
335
|
"src/config/statusline.ts"() {
|
|
314
336
|
"use strict";
|
|
@@ -379,7 +401,7 @@ var init_statusline = __esm({
|
|
|
379
401
|
MAX_EXTRA_COMMAND_ARGUMENT_CHARS = 1024;
|
|
380
402
|
STATUSLINE_EXTRA_GROUP = "extra";
|
|
381
403
|
commandArgument = z2.string().max(MAX_EXTRA_COMMAND_ARGUMENT_CHARS).refine((argument) => !argument.includes("\0"), "must not contain a NUL character");
|
|
382
|
-
|
|
404
|
+
LABEL_RE = /^[^\p{C}\p{Z}]+(?: [^\p{C}\p{Z}]+)*$/u;
|
|
383
405
|
OPTIONAL_LABEL_RE = /^(?:[^\p{C}\p{Z}]+(?: [^\p{C}\p{Z}]+)*)?$/u;
|
|
384
406
|
mergeGroups = z2.array(distinctList(z2.enum(STATUSLINE_ROWS)).min(2)).refine((groups) => {
|
|
385
407
|
const rows = groups.flat();
|
|
@@ -396,7 +418,7 @@ var init_statusline = __esm({
|
|
|
396
418
|
labelWithinColumnsMessage = `must take no more than ${String(MAX_STATUSLINE_LABEL_COLUMNS)} terminal columns`;
|
|
397
419
|
labelShowsSomething = (text) => !drawsNothing(text);
|
|
398
420
|
labelShowsSomethingMessage = "must show something: a label of only combining marks or blank characters draws nothing";
|
|
399
|
-
labelIsPlainText = (text) =>
|
|
421
|
+
labelIsPlainText = (text) => LABEL_RE.test(text);
|
|
400
422
|
labelIsPlainTextMessage = "must be visible text without control characters";
|
|
401
423
|
windowLabel = z2.string().refine((text) => text === "" || labelWithinColumns(text), labelWithinColumnsMessage).refine((text) => text === "" || labelShowsSomething(text), labelShowsSomethingMessage).refine((text) => text === "" || labelIsPlainText(text), labelIsPlainTextMessage);
|
|
402
424
|
overrideText = z2.string().max(MAX_DISPLAY_TEXT_CHARS).regex(OPTIONAL_LABEL_RE, "must be visible text without control characters");
|
|
@@ -3747,6 +3769,120 @@ var init_farm = __esm({
|
|
|
3747
3769
|
}
|
|
3748
3770
|
});
|
|
3749
3771
|
|
|
3772
|
+
// src/baseUrlDial.ts
|
|
3773
|
+
import { isIPv6 } from "node:net";
|
|
3774
|
+
import { domainToASCII } from "node:url";
|
|
3775
|
+
function dialHostOf(url) {
|
|
3776
|
+
return withoutRootDot(url.hostname.replace(/^\[(.*)\]$/, "$1"));
|
|
3777
|
+
}
|
|
3778
|
+
function withoutRootDot(host) {
|
|
3779
|
+
return host.endsWith(".") ? host.slice(0, -1) : host;
|
|
3780
|
+
}
|
|
3781
|
+
function bareZone(literal) {
|
|
3782
|
+
return literal.replace("%25", "%");
|
|
3783
|
+
}
|
|
3784
|
+
function portOf(text) {
|
|
3785
|
+
if (text === "") {
|
|
3786
|
+
return "has no port after the colon";
|
|
3787
|
+
}
|
|
3788
|
+
if (!/^\d+$/.test(text)) {
|
|
3789
|
+
return "has a port that is not a number";
|
|
3790
|
+
}
|
|
3791
|
+
const port = Number(text);
|
|
3792
|
+
return port >= 1 && port <= MAX_TCP_PORT ? port : `has a port outside 1 to ${String(MAX_TCP_PORT)}`;
|
|
3793
|
+
}
|
|
3794
|
+
function isAscii(text) {
|
|
3795
|
+
return new RegExp("^\\p{ASCII}*$", "u").test(text);
|
|
3796
|
+
}
|
|
3797
|
+
function nameOf(host) {
|
|
3798
|
+
const rooted = withoutRootDot(host.toLowerCase());
|
|
3799
|
+
if (rooted === "") {
|
|
3800
|
+
return { refusal: "an authority that names no host" };
|
|
3801
|
+
}
|
|
3802
|
+
const lowered = isAscii(rooted) ? rooted : domainToASCII(rooted);
|
|
3803
|
+
if (lowered === "") {
|
|
3804
|
+
return { refusal: "a host that does not convert to an ASCII name" };
|
|
3805
|
+
}
|
|
3806
|
+
if (isDottedDecimalIpv4(lowered)) {
|
|
3807
|
+
return lowered;
|
|
3808
|
+
}
|
|
3809
|
+
const problem = dnsNameProblem(lowered);
|
|
3810
|
+
if (problem !== void 0) {
|
|
3811
|
+
return { refusal: problem };
|
|
3812
|
+
}
|
|
3813
|
+
return lowered;
|
|
3814
|
+
}
|
|
3815
|
+
function canonicalLiteral(literal) {
|
|
3816
|
+
return literal.includes("%") ? lowerHost(literal) : dialHostOf(new URL(`http://[${literal}]/`));
|
|
3817
|
+
}
|
|
3818
|
+
function lowerHost(host) {
|
|
3819
|
+
const zone = host.indexOf("%");
|
|
3820
|
+
return zone === -1 ? host.toLowerCase() : `${host.slice(0, zone).toLowerCase()}${host.slice(zone)}`;
|
|
3821
|
+
}
|
|
3822
|
+
function parseDialAuthority(authority, defaultPort) {
|
|
3823
|
+
if (authority.includes("@")) {
|
|
3824
|
+
return { refusal: "an authority with userinfo cannot be dialled" };
|
|
3825
|
+
}
|
|
3826
|
+
if (NOT_AUTHORITY.test(authority)) {
|
|
3827
|
+
return { refusal: "an authority holds whitespace, a path, a query or a fragment" };
|
|
3828
|
+
}
|
|
3829
|
+
if (authority.startsWith("[")) {
|
|
3830
|
+
const close = authority.indexOf("]");
|
|
3831
|
+
if (close === -1) {
|
|
3832
|
+
return { refusal: "an authority with an unterminated bracket" };
|
|
3833
|
+
}
|
|
3834
|
+
const literal = bareZone(authority.slice(1, close));
|
|
3835
|
+
const rest = authority.slice(close + 1);
|
|
3836
|
+
if (literal === "") {
|
|
3837
|
+
return { refusal: "an authority that names no host" };
|
|
3838
|
+
}
|
|
3839
|
+
if (!isIPv6(literal)) {
|
|
3840
|
+
return { refusal: "a bracketed host that is not an IPv6 literal" };
|
|
3841
|
+
}
|
|
3842
|
+
if (rest !== "" && !rest.startsWith(":")) {
|
|
3843
|
+
return { refusal: "an authority with text after the closing bracket other than a port" };
|
|
3844
|
+
}
|
|
3845
|
+
const port2 = rest === "" ? defaultPort : portOf(rest.slice(1));
|
|
3846
|
+
return typeof port2 === "string" ? { refusal: `an authority that ${port2}` } : { host: canonicalLiteral(literal), port: port2 };
|
|
3847
|
+
}
|
|
3848
|
+
const colons = authority.split(":").length - 1;
|
|
3849
|
+
if (colons > 1) {
|
|
3850
|
+
return { refusal: "an unbracketed IPv6 literal, which must be written in brackets" };
|
|
3851
|
+
}
|
|
3852
|
+
const colon = authority.indexOf(":");
|
|
3853
|
+
const host = colon === -1 ? authority : authority.slice(0, colon);
|
|
3854
|
+
if (host === "") {
|
|
3855
|
+
return { refusal: "an authority that names no host" };
|
|
3856
|
+
}
|
|
3857
|
+
if (/[[\]]/.test(host)) {
|
|
3858
|
+
return { refusal: "an authority with brackets round something other than an IPv6 literal" };
|
|
3859
|
+
}
|
|
3860
|
+
const name = nameOf(host);
|
|
3861
|
+
if (typeof name !== "string") {
|
|
3862
|
+
return name;
|
|
3863
|
+
}
|
|
3864
|
+
const port = colon === -1 ? defaultPort : portOf(authority.slice(colon + 1));
|
|
3865
|
+
return typeof port === "string" ? { refusal: `an authority that ${port}` } : { host: name, port };
|
|
3866
|
+
}
|
|
3867
|
+
function dialTargetOf(baseUrl) {
|
|
3868
|
+
const url = new URL(baseUrl);
|
|
3869
|
+
const defaultPort = DEFAULT_PORTS[url.protocol];
|
|
3870
|
+
if (defaultPort === void 0) {
|
|
3871
|
+
throw new Error(`${url.protocol} is not a scheme a provider's base URL can have`);
|
|
3872
|
+
}
|
|
3873
|
+
return { host: dialHostOf(url), port: url.port === "" ? defaultPort : Number(url.port) };
|
|
3874
|
+
}
|
|
3875
|
+
var MAX_TCP_PORT, NOT_AUTHORITY, DEFAULT_PORTS;
|
|
3876
|
+
var init_baseUrlDial = __esm({
|
|
3877
|
+
"src/baseUrlDial.ts"() {
|
|
3878
|
+
"use strict";
|
|
3879
|
+
init_hostName();
|
|
3880
|
+
MAX_TCP_PORT = 65535;
|
|
3881
|
+
NOT_AUTHORITY = /[\s/?#\\]/;
|
|
3882
|
+
DEFAULT_PORTS = { "http:": 80, "https:": 443 };
|
|
3883
|
+
}
|
|
3884
|
+
});
|
|
3885
|
+
|
|
3750
3886
|
// src/frontdoor/x509.ts
|
|
3751
3887
|
import { createHash, createPrivateKey, generateKeyPairSync, randomBytes, sign, X509Certificate } from "node:crypto";
|
|
3752
3888
|
import net from "node:net";
|
|
@@ -4135,6 +4271,39 @@ var init_route = __esm({
|
|
|
4135
4271
|
}
|
|
4136
4272
|
});
|
|
4137
4273
|
|
|
4274
|
+
// src/processRole.ts
|
|
4275
|
+
function enterProcessRole(role) {
|
|
4276
|
+
const previous = currentRole;
|
|
4277
|
+
currentRole = role;
|
|
4278
|
+
return () => {
|
|
4279
|
+
currentRole = previous;
|
|
4280
|
+
};
|
|
4281
|
+
}
|
|
4282
|
+
function noteBlockingStep() {
|
|
4283
|
+
blockingStepObserver?.();
|
|
4284
|
+
}
|
|
4285
|
+
function refuseToBlockInRole(operation) {
|
|
4286
|
+
noteBlockingStep();
|
|
4287
|
+
if (currentRole !== void 0) {
|
|
4288
|
+
throw new BlockingInEventLoopError(operation, currentRole);
|
|
4289
|
+
}
|
|
4290
|
+
}
|
|
4291
|
+
var currentRole, BlockingInEventLoopError, blockingStepObserver;
|
|
4292
|
+
var init_processRole = __esm({
|
|
4293
|
+
"src/processRole.ts"() {
|
|
4294
|
+
"use strict";
|
|
4295
|
+
init_cliError();
|
|
4296
|
+
BlockingInEventLoopError = class extends CliError {
|
|
4297
|
+
constructor(operation, role) {
|
|
4298
|
+
super(
|
|
4299
|
+
`${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)`
|
|
4300
|
+
);
|
|
4301
|
+
this.name = "BlockingInEventLoopError";
|
|
4302
|
+
}
|
|
4303
|
+
};
|
|
4304
|
+
}
|
|
4305
|
+
});
|
|
4306
|
+
|
|
4138
4307
|
// src/baseUrlDisplay.ts
|
|
4139
4308
|
function displayBaseUrl(baseUrl) {
|
|
4140
4309
|
const url = new URL(baseUrl);
|
|
@@ -4885,38 +5054,63 @@ var init_providerCatalogue = __esm({
|
|
|
4885
5054
|
}
|
|
4886
5055
|
});
|
|
4887
5056
|
|
|
4888
|
-
// src/frontdoor/
|
|
5057
|
+
// src/frontdoor/catalogueCleanup.ts
|
|
4889
5058
|
import path12 from "node:path";
|
|
4890
5059
|
import { z as z8 } from "zod";
|
|
5060
|
+
async function pruneAbandonedCatalogueGenerations(fs17, paths, ownPid, generation, runningAmong) {
|
|
5061
|
+
const root = path12.join(paths.catalogueDir, "supervisors");
|
|
5062
|
+
const owners = fs17.readdir(root).flatMap((entry) => {
|
|
5063
|
+
const pid = Number(entry);
|
|
5064
|
+
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry && fs17.lstat(path12.join(root, entry))?.kind === "dir" ? [pid] : [];
|
|
5065
|
+
});
|
|
5066
|
+
const running = await runningAmong(owners);
|
|
5067
|
+
for (const pid of owners) {
|
|
5068
|
+
if (pid !== ownPid && running.has(pid)) continue;
|
|
5069
|
+
const directory = path12.join(root, String(pid));
|
|
5070
|
+
for (const entry of fs17.readdir(directory)) {
|
|
5071
|
+
const candidate = path12.join(directory, entry);
|
|
5072
|
+
if (z8.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) && fs17.lstat(candidate)?.kind === "dir") fs17.removeRecursive(candidate);
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
var init_catalogueCleanup = __esm({
|
|
5077
|
+
"src/frontdoor/catalogueCleanup.ts"() {
|
|
5078
|
+
"use strict";
|
|
5079
|
+
}
|
|
5080
|
+
});
|
|
5081
|
+
|
|
5082
|
+
// src/frontdoor/state.ts
|
|
5083
|
+
import path13 from "node:path";
|
|
5084
|
+
import { z as z9 } from "zod";
|
|
4891
5085
|
function readCatalogueStatus(fs17, paths, pid, generation, name) {
|
|
4892
|
-
const file =
|
|
5086
|
+
const file = path13.join(path13.dirname(catalogueCachePath(paths, name, pid, generation)), `${name}.status.json`);
|
|
4893
5087
|
const raw = fs17.readFileUtf8(file);
|
|
4894
5088
|
if (raw === void 0) return void 0;
|
|
4895
5089
|
try {
|
|
4896
|
-
const value =
|
|
5090
|
+
const value = z9.strictObject({ status: z9.enum(["running", "ready", "failed"]), fingerprint: z9.string().min(1).optional(), recordedAt: z9.number().optional() }).safeParse(JSON.parse(raw));
|
|
4897
5091
|
return value.success ? value.data : void 0;
|
|
4898
5092
|
} catch {
|
|
4899
5093
|
return void 0;
|
|
4900
5094
|
}
|
|
4901
5095
|
}
|
|
4902
5096
|
function writeFrontDoorCodexHome(fs17, frontdoorDir, pid, codexHome, generation) {
|
|
4903
|
-
const directory =
|
|
5097
|
+
const directory = path13.join(frontdoorDir, "codex-homes");
|
|
4904
5098
|
fs17.mkdirp(directory);
|
|
4905
|
-
fs17.writeFilePrivate(
|
|
5099
|
+
fs17.writeFilePrivate(path13.join(directory, `${String(pid)}.json`), `${JSON.stringify({ codexHome, generation })}
|
|
4906
5100
|
`);
|
|
4907
5101
|
}
|
|
4908
5102
|
function readFrontDoorCodexRecord(fs17, frontdoorDir, pid) {
|
|
4909
|
-
const raw = fs17.readFileUtf8(
|
|
5103
|
+
const raw = fs17.readFileUtf8(path13.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
4910
5104
|
if (raw === void 0) return void 0;
|
|
4911
5105
|
try {
|
|
4912
|
-
const parsed =
|
|
4913
|
-
return parsed.success &&
|
|
5106
|
+
const parsed = z9.strictObject({ codexHome: z9.string().min(1), generation: z9.uuid() }).safeParse(JSON.parse(raw));
|
|
5107
|
+
return parsed.success && path13.isAbsolute(parsed.data.codexHome) ? parsed.data : void 0;
|
|
4914
5108
|
} catch {
|
|
4915
5109
|
return void 0;
|
|
4916
5110
|
}
|
|
4917
5111
|
}
|
|
4918
5112
|
function removeFrontDoorCodexHome(fs17, frontdoorDir, pid) {
|
|
4919
|
-
fs17.removeRecursive(
|
|
5113
|
+
fs17.removeRecursive(path13.join(frontdoorDir, "codex-homes", `${String(pid)}.json`));
|
|
4920
5114
|
}
|
|
4921
5115
|
function readFrontDoorState(fs17, stateFile) {
|
|
4922
5116
|
let raw;
|
|
@@ -4936,7 +5130,7 @@ function readFrontDoorState(fs17, stateFile) {
|
|
|
4936
5130
|
}
|
|
4937
5131
|
}
|
|
4938
5132
|
function writeFrontDoorState(fs17, stateFile, state) {
|
|
4939
|
-
fs17.mkdirp(
|
|
5133
|
+
fs17.mkdirp(path13.dirname(stateFile));
|
|
4940
5134
|
fs17.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
4941
5135
|
`);
|
|
4942
5136
|
}
|
|
@@ -4949,18 +5143,18 @@ function frontDoorOrigin(state) {
|
|
|
4949
5143
|
}
|
|
4950
5144
|
function writeFrontDoorDirectRecord(fs17, recordsDir, record) {
|
|
4951
5145
|
fs17.mkdirp(recordsDir);
|
|
4952
|
-
fs17.writeFilePrivate(
|
|
5146
|
+
fs17.writeFilePrivate(path13.join(recordsDir, `${String(record.pid)}.json`), `${JSON.stringify({ directPort: record.directPort })}
|
|
4953
5147
|
`);
|
|
4954
5148
|
}
|
|
4955
5149
|
function removeFrontDoorDirectRecord(fs17, recordsDir, pid) {
|
|
4956
|
-
fs17.removeRecursive(
|
|
5150
|
+
fs17.removeRecursive(path13.join(recordsDir, `${String(pid)}.json`));
|
|
4957
5151
|
}
|
|
4958
5152
|
function markFrontDoorDraining(fs17, markersDir, pid) {
|
|
4959
5153
|
fs17.mkdirp(markersDir);
|
|
4960
|
-
fs17.writeFilePrivate(
|
|
5154
|
+
fs17.writeFilePrivate(path13.join(markersDir, String(pid)), "\n");
|
|
4961
5155
|
}
|
|
4962
5156
|
function unmarkFrontDoorDraining(fs17, markersDir, pid) {
|
|
4963
|
-
fs17.removeRecursive(
|
|
5157
|
+
fs17.removeRecursive(path13.join(markersDir, String(pid)));
|
|
4964
5158
|
}
|
|
4965
5159
|
function listDrainingFrontDoors(fs17, markersDir, isRunning) {
|
|
4966
5160
|
return fs17.readdir(markersDir).flatMap((file) => /^[1-9]\d*$/.test(file) && Number.isSafeInteger(Number(file)) ? [Number(file)] : []).filter(isRunning).sort((a, b) => a - b);
|
|
@@ -4977,7 +5171,7 @@ function readDirectRecordEntry(fs17, recordsDir, file) {
|
|
|
4977
5171
|
}
|
|
4978
5172
|
let raw;
|
|
4979
5173
|
try {
|
|
4980
|
-
raw = fs17.readFileUtf8(
|
|
5174
|
+
raw = fs17.readFileUtf8(path13.join(recordsDir, file));
|
|
4981
5175
|
} catch {
|
|
4982
5176
|
return void 0;
|
|
4983
5177
|
}
|
|
@@ -5002,7 +5196,7 @@ function pruneMalformedFrontDoorDirectFiles(fs17, recordsDir, isRunning) {
|
|
|
5002
5196
|
const writer = RECORD_TEMPORARY_FILE.exec(file)?.[1];
|
|
5003
5197
|
const stale = writer !== void 0 && !isRunning(Number(writer));
|
|
5004
5198
|
if (stale || readDirectRecordEntry(fs17, recordsDir, file)?.malformed === true) {
|
|
5005
|
-
fs17.removeRecursive(
|
|
5199
|
+
fs17.removeRecursive(path13.join(recordsDir, file));
|
|
5006
5200
|
}
|
|
5007
5201
|
}
|
|
5008
5202
|
}
|
|
@@ -5021,7 +5215,7 @@ function recordOf(details) {
|
|
|
5021
5215
|
}
|
|
5022
5216
|
function writeFrontDoorSession(fs17, sessionsDir, session) {
|
|
5023
5217
|
fs17.mkdirPrivate(sessionsDir);
|
|
5024
|
-
fs17.writeFilePrivate(
|
|
5218
|
+
fs17.writeFilePrivate(path13.join(sessionsDir, sessionRecordName(session.pid)), `${JSON.stringify(session, null, 2)}
|
|
5025
5219
|
`);
|
|
5026
5220
|
}
|
|
5027
5221
|
function sessionRecordName(pid) {
|
|
@@ -5035,7 +5229,7 @@ function summaryOf(session) {
|
|
|
5035
5229
|
}
|
|
5036
5230
|
function readFrontDoorSessionRecord(fs17, sessionsDir, name) {
|
|
5037
5231
|
try {
|
|
5038
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs17.readFileUtf8(
|
|
5232
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs17.readFileUtf8(path13.join(sessionsDir, name)) ?? ""));
|
|
5039
5233
|
return parsed.success ? parsed.data : void 0;
|
|
5040
5234
|
} catch {
|
|
5041
5235
|
return void 0;
|
|
@@ -5052,7 +5246,7 @@ function listFrontDoorSessions(fs17, sessionsDir) {
|
|
|
5052
5246
|
return sessions.sort((a, b) => a.pid - b.pid);
|
|
5053
5247
|
}
|
|
5054
5248
|
function removeFrontDoorSession(fs17, sessionsDir, pid) {
|
|
5055
|
-
fs17.removeRecursive(
|
|
5249
|
+
fs17.removeRecursive(path13.join(sessionsDir, sessionRecordName(pid)));
|
|
5056
5250
|
}
|
|
5057
5251
|
function pruneDeadFrontDoorSessions(fs17, sessionsDir, listed, isRunning) {
|
|
5058
5252
|
const removed = [];
|
|
@@ -5064,109 +5258,51 @@ function pruneDeadFrontDoorSessions(fs17, sessionsDir, listed, isRunning) {
|
|
|
5064
5258
|
}
|
|
5065
5259
|
return removed;
|
|
5066
5260
|
}
|
|
5067
|
-
var FRONT_DOOR_PROTOCOL, FRONT_DOOR_HANDOVER_PROTOCOL, FrontDoorSessionSchema, FrontDoorStateSchema,
|
|
5261
|
+
var FRONT_DOOR_PROTOCOL, FRONT_DOOR_HANDOVER_PROTOCOL, FrontDoorSessionSchema, FrontDoorStateSchema, FrontDoorDirectRecordSchema, RECORD_TEMPORARY_FILE;
|
|
5068
5262
|
var init_state = __esm({
|
|
5069
5263
|
"src/frontdoor/state.ts"() {
|
|
5070
5264
|
"use strict";
|
|
5071
5265
|
init_schema();
|
|
5266
|
+
init_baseUrlDial();
|
|
5072
5267
|
init_providerCatalogue();
|
|
5073
5268
|
FRONT_DOOR_PROTOCOL = 8;
|
|
5074
5269
|
FRONT_DOOR_HANDOVER_PROTOCOL = 6;
|
|
5075
|
-
FrontDoorSessionSchema =
|
|
5076
|
-
FrontDoorStateSchema =
|
|
5270
|
+
FrontDoorSessionSchema = z9.strictObject({ pid: z9.number().int().positive(), startedAt: z9.number(), token: z9.string().min(1), supervisorPid: z9.number().int().positive().optional(), sessionId: z9.string().min(1).optional(), identity: z9.string().min(1).optional(), models: ModelsConfigSchema.optional() });
|
|
5271
|
+
FrontDoorStateSchema = z9.strictObject({
|
|
5077
5272
|
/**
|
|
5078
5273
|
* 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`).
|
|
5079
5274
|
*/
|
|
5080
|
-
protocol:
|
|
5275
|
+
protocol: z9.number().int().nonnegative().optional(),
|
|
5081
5276
|
/** The supervisor process serving the front door. Alive means both listeners are up in that process. */
|
|
5082
|
-
supervisorPid:
|
|
5277
|
+
supervisorPid: z9.number().int().positive().optional(),
|
|
5083
5278
|
/** 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. */
|
|
5084
|
-
port:
|
|
5279
|
+
port: z9.number().int().positive().optional(),
|
|
5085
5280
|
/**
|
|
5086
5281
|
* 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.
|
|
5087
5282
|
*/
|
|
5088
|
-
lastPort:
|
|
5283
|
+
lastPort: z9.number().int().positive().optional(),
|
|
5089
5284
|
/**
|
|
5090
5285
|
* 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`.
|
|
5091
5286
|
*/
|
|
5092
|
-
connectPort:
|
|
5287
|
+
connectPort: z9.number().int().positive().optional(),
|
|
5093
5288
|
/**
|
|
5094
5289
|
* 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.
|
|
5095
5290
|
*/
|
|
5096
|
-
lastConnectPort:
|
|
5291
|
+
lastConnectPort: z9.number().int().positive().optional(),
|
|
5097
5292
|
/**
|
|
5098
5293
|
* 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.
|
|
5099
5294
|
*/
|
|
5100
|
-
directPort:
|
|
5295
|
+
directPort: z9.number().int().positive().optional(),
|
|
5101
5296
|
/** The sticky port preference for the direct listener, for the reason `directPort` gives. */
|
|
5102
|
-
lastDirectPort:
|
|
5297
|
+
lastDirectPort: z9.number().int().positive().optional(),
|
|
5103
5298
|
/** The last fatal error, kept across shutdowns so `frontdoor status` can explain a front door that is not running. */
|
|
5104
|
-
lastError:
|
|
5299
|
+
lastError: z9.string().optional()
|
|
5105
5300
|
});
|
|
5106
|
-
|
|
5107
|
-
FrontDoorDirectRecordSchema = z8.strictObject({ directPort: z8.number().int().positive().max(MAX_TCP_PORT) });
|
|
5301
|
+
FrontDoorDirectRecordSchema = z9.strictObject({ directPort: z9.number().int().positive().max(MAX_TCP_PORT) });
|
|
5108
5302
|
RECORD_TEMPORARY_FILE = /^[1-9]\d*\.json\.([1-9]\d*)\.tmp$/;
|
|
5109
5303
|
}
|
|
5110
5304
|
});
|
|
5111
5305
|
|
|
5112
|
-
// src/processRole.ts
|
|
5113
|
-
function enterProcessRole(role) {
|
|
5114
|
-
const previous = currentRole;
|
|
5115
|
-
currentRole = role;
|
|
5116
|
-
return () => {
|
|
5117
|
-
currentRole = previous;
|
|
5118
|
-
};
|
|
5119
|
-
}
|
|
5120
|
-
function noteBlockingStep() {
|
|
5121
|
-
blockingStepObserver?.();
|
|
5122
|
-
}
|
|
5123
|
-
function refuseToBlockInRole(operation) {
|
|
5124
|
-
noteBlockingStep();
|
|
5125
|
-
if (currentRole !== void 0) {
|
|
5126
|
-
throw new BlockingInEventLoopError(operation, currentRole);
|
|
5127
|
-
}
|
|
5128
|
-
}
|
|
5129
|
-
var currentRole, BlockingInEventLoopError, blockingStepObserver;
|
|
5130
|
-
var init_processRole = __esm({
|
|
5131
|
-
"src/processRole.ts"() {
|
|
5132
|
-
"use strict";
|
|
5133
|
-
init_cliError();
|
|
5134
|
-
BlockingInEventLoopError = class extends CliError {
|
|
5135
|
-
constructor(operation, role) {
|
|
5136
|
-
super(
|
|
5137
|
-
`${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)`
|
|
5138
|
-
);
|
|
5139
|
-
this.name = "BlockingInEventLoopError";
|
|
5140
|
-
}
|
|
5141
|
-
};
|
|
5142
|
-
}
|
|
5143
|
-
});
|
|
5144
|
-
|
|
5145
|
-
// src/frontdoor/catalogueCleanup.ts
|
|
5146
|
-
import path13 from "node:path";
|
|
5147
|
-
import { z as z9 } from "zod";
|
|
5148
|
-
async function pruneAbandonedCatalogueGenerations(fs17, paths, ownPid, generation, runningAmong) {
|
|
5149
|
-
const root = path13.join(paths.catalogueDir, "supervisors");
|
|
5150
|
-
const owners = fs17.readdir(root).flatMap((entry) => {
|
|
5151
|
-
const pid = Number(entry);
|
|
5152
|
-
return Number.isSafeInteger(pid) && pid > 0 && String(pid) === entry && fs17.lstat(path13.join(root, entry))?.kind === "dir" ? [pid] : [];
|
|
5153
|
-
});
|
|
5154
|
-
const running = await runningAmong(owners);
|
|
5155
|
-
for (const pid of owners) {
|
|
5156
|
-
if (pid !== ownPid && running.has(pid)) continue;
|
|
5157
|
-
const directory = path13.join(root, String(pid));
|
|
5158
|
-
for (const entry of fs17.readdir(directory)) {
|
|
5159
|
-
const candidate = path13.join(directory, entry);
|
|
5160
|
-
if (z9.uuid().safeParse(entry).success && (pid !== ownPid || entry !== generation) && fs17.lstat(candidate)?.kind === "dir") fs17.removeRecursive(candidate);
|
|
5161
|
-
}
|
|
5162
|
-
}
|
|
5163
|
-
}
|
|
5164
|
-
var init_catalogueCleanup = __esm({
|
|
5165
|
-
"src/frontdoor/catalogueCleanup.ts"() {
|
|
5166
|
-
"use strict";
|
|
5167
|
-
}
|
|
5168
|
-
});
|
|
5169
|
-
|
|
5170
5306
|
// src/frontdoor/supervisor.ts
|
|
5171
5307
|
import path14 from "node:path";
|
|
5172
5308
|
function watchedInstallEntry(resolvedOwnExecutablePath, siblingExists) {
|
|
@@ -5417,17 +5553,8 @@ var init_supervisor = __esm({
|
|
|
5417
5553
|
import { X509Certificate as X509Certificate2, createPrivateKey as createPrivateKey2 } from "node:crypto";
|
|
5418
5554
|
import * as fs3 from "node:fs";
|
|
5419
5555
|
function parseConnectTarget(authority) {
|
|
5420
|
-
const
|
|
5421
|
-
|
|
5422
|
-
const host2 = authority.trim().toLowerCase();
|
|
5423
|
-
return host2 === "" ? void 0 : { host: host2, port: HTTPS_PORT };
|
|
5424
|
-
}
|
|
5425
|
-
const host = authority.slice(0, colon).trim().toLowerCase();
|
|
5426
|
-
const port = Number.parseInt(authority.slice(colon + 1), 10);
|
|
5427
|
-
if (host === "" || !Number.isInteger(port) || port <= 0 || port > MAX_TCP_PORT) {
|
|
5428
|
-
return void 0;
|
|
5429
|
-
}
|
|
5430
|
-
return { host, port };
|
|
5556
|
+
const parsed = parseDialAuthority(authority, HTTPS_PORT);
|
|
5557
|
+
return "refusal" in parsed ? void 0 : parsed;
|
|
5431
5558
|
}
|
|
5432
5559
|
function isInterceptedHost(host, interceptHosts) {
|
|
5433
5560
|
return interceptHosts.includes(host);
|
|
@@ -5746,9 +5873,9 @@ function routeConnect(socket, head, context) {
|
|
|
5746
5873
|
const requestLine = head.split("\r\n", 1)[0] ?? "";
|
|
5747
5874
|
const parts = requestLine.split(" ");
|
|
5748
5875
|
const authority = parts.length === CONNECT_LINE_TOKENS && parts[0]?.toUpperCase() === "CONNECT" ? parts[1] ?? "" : void 0;
|
|
5749
|
-
const target = authority === void 0 ? void 0 :
|
|
5750
|
-
if (target === void 0) {
|
|
5751
|
-
refuse(socket, REFUSAL.badRequest);
|
|
5876
|
+
const target = authority === void 0 ? void 0 : parseDialAuthority(authority, HTTPS_PORT);
|
|
5877
|
+
if (target === void 0 || "refusal" in target) {
|
|
5878
|
+
refuse(socket, REFUSAL.badRequest, target === void 0 ? [] : [`${REFUSAL_HEADER}: ${target.refusal}`]);
|
|
5752
5879
|
return;
|
|
5753
5880
|
}
|
|
5754
5881
|
const session = sessions.find((entry) => entry.host === target.host);
|
|
@@ -5819,15 +5946,15 @@ function realConnectCertStore(paths) {
|
|
|
5819
5946
|
}
|
|
5820
5947
|
};
|
|
5821
5948
|
}
|
|
5822
|
-
var 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;
|
|
5949
|
+
var 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;
|
|
5823
5950
|
var init_connect = __esm({
|
|
5824
5951
|
"src/frontdoor/connect.ts"() {
|
|
5825
5952
|
"use strict";
|
|
5953
|
+
init_baseUrlDial();
|
|
5826
5954
|
init_x509();
|
|
5827
5955
|
init_tap();
|
|
5828
5956
|
init_capability();
|
|
5829
5957
|
init_route();
|
|
5830
|
-
init_state();
|
|
5831
5958
|
init_supervisor();
|
|
5832
5959
|
CONNECT_INTERCEPT_HOST = "api.anthropic.com";
|
|
5833
5960
|
CONNECT_INTERCEPT_HOSTS = [CONNECT_INTERCEPT_HOST, "platform.claude.com"];
|
|
@@ -5839,6 +5966,7 @@ var init_connect = __esm({
|
|
|
5839
5966
|
HEAD_TERMINATOR = "\r\n\r\n";
|
|
5840
5967
|
MAX_CONNECT_HEAD_BYTES = 8192;
|
|
5841
5968
|
CONNECT_ESTABLISHED = "HTTP/1.1 200 Connection Established\r\n\r\n";
|
|
5969
|
+
REFUSAL_HEADER = "x-agent-shim-refusal";
|
|
5842
5970
|
REFUSAL = {
|
|
5843
5971
|
badRequest: "400 Bad Request",
|
|
5844
5972
|
proxyAuthenticationRequired: "407 Proxy Authentication Required",
|
|
@@ -8077,6 +8205,20 @@ function createDoorLookup(io) {
|
|
|
8077
8205
|
});
|
|
8078
8206
|
};
|
|
8079
8207
|
}
|
|
8208
|
+
function sourcePortClassifier(platform) {
|
|
8209
|
+
const classify = (error) => {
|
|
8210
|
+
const attempts = Reflect.get(error, "errors");
|
|
8211
|
+
if (Array.isArray(attempts) && attempts.length > 0) {
|
|
8212
|
+
const kinds = attempts.map((attempt) => attempt instanceof Error ? classify(attempt) : void 0);
|
|
8213
|
+
return kinds.includes("excluded") ? "excluded" : kinds.includes("held") ? "held" : void 0;
|
|
8214
|
+
}
|
|
8215
|
+
if (error.code === "EADDRINUSE" || error.code === "EADDRNOTAVAIL") {
|
|
8216
|
+
return "held";
|
|
8217
|
+
}
|
|
8218
|
+
return platform === "win32" && error.code === "EACCES" && error.syscall === "bind" ? "excluded" : void 0;
|
|
8219
|
+
};
|
|
8220
|
+
return classify;
|
|
8221
|
+
}
|
|
8080
8222
|
function doorDial(io, target, ports) {
|
|
8081
8223
|
const dialOnce = (options) => new Promise((resolve) => {
|
|
8082
8224
|
const socket = io.connect(options);
|
|
@@ -8089,12 +8231,15 @@ function doorDial(io, target, ports) {
|
|
|
8089
8231
|
if (error.message === "" && Array.isArray(attempts) && attempts.length > 0) {
|
|
8090
8232
|
const flattened = new Error(attempts.map((attempt) => withoutLocalEnd(attempt instanceof Error ? attempt.message : String(attempt))).join("; "));
|
|
8091
8233
|
flattened.code = error.code;
|
|
8234
|
+
flattened.syscall = error.syscall;
|
|
8235
|
+
Object.defineProperty(flattened, "errors", { value: attempts });
|
|
8092
8236
|
resolve({ error: flattened, socket });
|
|
8093
8237
|
return;
|
|
8094
8238
|
}
|
|
8095
8239
|
if (withoutLocalEnd(error.message) !== error.message) {
|
|
8096
8240
|
const trimmed = new Error(withoutLocalEnd(error.message));
|
|
8097
8241
|
trimmed.code = error.code;
|
|
8242
|
+
trimmed.syscall = error.syscall;
|
|
8098
8243
|
resolve({ error: trimmed, socket });
|
|
8099
8244
|
return;
|
|
8100
8245
|
}
|
|
@@ -8104,17 +8249,35 @@ function doorDial(io, target, ports) {
|
|
|
8104
8249
|
if (io.isIP(target.host) !== 0) {
|
|
8105
8250
|
return dialOnce({ host: target.host, port: target.port });
|
|
8106
8251
|
}
|
|
8107
|
-
const attemptFrom = (attempt
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8252
|
+
const attemptFrom = (attempt, refused2) => {
|
|
8253
|
+
const port = ports.take();
|
|
8254
|
+
return dialOnce({ host: target.host, port: target.port, localPort: port, lookup: io.lookup }).then((outcome) => {
|
|
8255
|
+
if (outcome.error === null) {
|
|
8256
|
+
return outcome;
|
|
8257
|
+
}
|
|
8258
|
+
const failure = io.sourcePortFailure(outcome.error);
|
|
8259
|
+
if (failure === void 0) {
|
|
8260
|
+
return outcome;
|
|
8261
|
+
}
|
|
8262
|
+
if (failure === "excluded") {
|
|
8263
|
+
ports.exclude(port);
|
|
8264
|
+
}
|
|
8265
|
+
const refusedSoFar = failure === "excluded" ? refused2 + 1 : refused2;
|
|
8266
|
+
if (attempt < ports.count - 1) {
|
|
8267
|
+
return attemptFrom(attempt + 1, refusedSoFar);
|
|
8268
|
+
}
|
|
8269
|
+
if (refusedSoFar === 0) {
|
|
8270
|
+
return outcome;
|
|
8271
|
+
}
|
|
8272
|
+
const scope = refusedSoFar === ports.count ? "every source port" : `${String(refusedSoFar)} of its ${String(ports.count)} source ports (the rest were held by other sockets)`;
|
|
8273
|
+
const refusal2 = new Error(
|
|
8274
|
+
`${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\``
|
|
8275
|
+
);
|
|
8276
|
+
refusal2.code = refusedSoFar === ports.count ? "EACCES" : outcome.error.code;
|
|
8277
|
+
return { error: refusal2, socket: outcome.socket };
|
|
8278
|
+
});
|
|
8279
|
+
};
|
|
8280
|
+
return attemptFrom(0, 0);
|
|
8118
8281
|
}
|
|
8119
8282
|
function probeAccept(dial, timeoutMs, startTimer) {
|
|
8120
8283
|
return new Promise((resolve) => {
|
|
@@ -8149,7 +8312,7 @@ function runAcceptProbe(deps, data, startTimer) {
|
|
|
8149
8312
|
const lookup2 = deps.createDoorLookup({ isIP: deps.net.isIP, resolve4: (name, callback) => {
|
|
8150
8313
|
deps.dns.resolve4(name, callback);
|
|
8151
8314
|
} });
|
|
8152
|
-
const io = { connect: (options) => deps.net.connect(options), lookup: lookup2, isIP: deps.net.isIP };
|
|
8315
|
+
const io = { connect: (options) => deps.net.connect(options), lookup: lookup2, isIP: deps.net.isIP, sourcePortFailure: deps.sourcePortClassifier(data.platform) };
|
|
8153
8316
|
return deps.probeAccept(() => deps.doorDial(io, { host: data.host, port: data.port }, new deps.SourcePortRange(data.portStart, data.portEnd, data.portFirst)), data.timeoutMs, startTimer);
|
|
8154
8317
|
}
|
|
8155
8318
|
var init_doorDial = __esm({
|
|
@@ -8167,14 +8330,17 @@ import * as tls from "node:tls";
|
|
|
8167
8330
|
function isSuccessful2(status) {
|
|
8168
8331
|
return status >= HTTP_STATUS.ok && status < SUCCESS_STATUS_MAX_EXCLUSIVE2;
|
|
8169
8332
|
}
|
|
8333
|
+
function realDoorDialIo(platform = process.platform, connect3 = (options) => net2.connect(options)) {
|
|
8334
|
+
return { connect: connect3, lookup: realAddressLookup, isIP: net2.isIP, sourcePortFailure: sourcePortClassifier(platform) };
|
|
8335
|
+
}
|
|
8170
8336
|
function dialTarget(options, defaultPort) {
|
|
8171
8337
|
return { host: typeof options.host === "string" ? options.host : "", port: typeof options.port === "number" ? options.port : defaultPort };
|
|
8172
8338
|
}
|
|
8173
8339
|
function literalDial(target) {
|
|
8174
8340
|
return net2.connect({ host: target.host, port: target.port });
|
|
8175
8341
|
}
|
|
8176
|
-
async function reservedDial(target, ports) {
|
|
8177
|
-
return await doorDial(
|
|
8342
|
+
async function reservedDial(target, ports, io) {
|
|
8343
|
+
return await doorDial(io, target, ports);
|
|
8178
8344
|
}
|
|
8179
8345
|
function requestServername(options, fallback) {
|
|
8180
8346
|
return "servername" in options && typeof options.servername === "string" && options.servername !== "" ? options.servername : fallback;
|
|
@@ -8314,9 +8480,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
|
|
|
8314
8480
|
}
|
|
8315
8481
|
};
|
|
8316
8482
|
}
|
|
8317
|
-
function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
|
|
8318
|
-
const plainAgent = new ExemptHttpAgent(ports);
|
|
8319
|
-
const tlsAgent = new ExemptTlsAgent(ports);
|
|
8483
|
+
function realConnectEffects(ports = DOOR_SOURCE_PORTS, io = realDoorDialIo()) {
|
|
8484
|
+
const plainAgent = new ExemptHttpAgent(ports, io);
|
|
8485
|
+
const tlsAgent = new ExemptTlsAgent(ports, io);
|
|
8320
8486
|
const listenOnce = async (target, onSocket) => await new Promise((resolve, reject) => {
|
|
8321
8487
|
const accepted = /* @__PURE__ */ new Set();
|
|
8322
8488
|
const server = net2.createServer((socket) => {
|
|
@@ -8448,7 +8614,7 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
|
|
|
8448
8614
|
};
|
|
8449
8615
|
},
|
|
8450
8616
|
connectTlsUpstream: async (host, port, clientAlpn) => {
|
|
8451
|
-
const dialled = await reservedDial({ host, port }, ports);
|
|
8617
|
+
const dialled = await reservedDial({ host, port }, ports, io);
|
|
8452
8618
|
if (dialled.error !== null) {
|
|
8453
8619
|
throw dialled.error;
|
|
8454
8620
|
}
|
|
@@ -8529,7 +8695,7 @@ function realConnectEffects(ports = DOOR_SOURCE_PORTS) {
|
|
|
8529
8695
|
}
|
|
8530
8696
|
};
|
|
8531
8697
|
}
|
|
8532
|
-
var 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,
|
|
8698
|
+
var 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;
|
|
8533
8699
|
var init_connectEffects = __esm({
|
|
8534
8700
|
"src/frontdoor/connectEffects.ts"() {
|
|
8535
8701
|
"use strict";
|
|
@@ -8546,13 +8712,28 @@ var init_connectEffects = __esm({
|
|
|
8546
8712
|
this.end = end;
|
|
8547
8713
|
this.count = end - start + 1;
|
|
8548
8714
|
this.next = first;
|
|
8715
|
+
this.excluded = /* @__PURE__ */ new Set();
|
|
8549
8716
|
}
|
|
8550
|
-
/**
|
|
8717
|
+
/**
|
|
8718
|
+
* 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.
|
|
8719
|
+
*/
|
|
8551
8720
|
take() {
|
|
8721
|
+
for (let skipped = 0; skipped < this.count; skipped += 1) {
|
|
8722
|
+
const port2 = this.next;
|
|
8723
|
+
this.next = this.next === this.end ? this.start : this.next + 1;
|
|
8724
|
+
if (!this.excluded.has(port2)) {
|
|
8725
|
+
return port2;
|
|
8726
|
+
}
|
|
8727
|
+
}
|
|
8728
|
+
this.excluded.clear();
|
|
8552
8729
|
const port = this.next;
|
|
8553
8730
|
this.next = this.next === this.end ? this.start : this.next + 1;
|
|
8554
8731
|
return port;
|
|
8555
8732
|
}
|
|
8733
|
+
/** 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. */
|
|
8734
|
+
exclude(port) {
|
|
8735
|
+
this.excluded.add(port);
|
|
8736
|
+
}
|
|
8556
8737
|
};
|
|
8557
8738
|
DOOR_SOURCE_PORT_START = 47900;
|
|
8558
8739
|
DOOR_SOURCE_PORT_COUNT = 1e3;
|
|
@@ -8564,39 +8745,42 @@ var init_connectEffects = __esm({
|
|
|
8564
8745
|
realAddressLookup = createDoorLookup({ isIP: net2.isIP, resolve4: (host, callback) => {
|
|
8565
8746
|
dns.resolve4(host, callback);
|
|
8566
8747
|
} });
|
|
8567
|
-
realDialIo = { connect: (options) => net2.connect(options), lookup: realAddressLookup, isIP: net2.isIP };
|
|
8568
8748
|
HTTP_PORT = 80;
|
|
8569
8749
|
ExemptHttpAgent = class extends http.Agent {
|
|
8570
|
-
constructor(ports = DOOR_SOURCE_PORTS) {
|
|
8750
|
+
constructor(ports = DOOR_SOURCE_PORTS, io = realDoorDialIo()) {
|
|
8571
8751
|
super(POOLING);
|
|
8572
8752
|
this.ports = ports;
|
|
8753
|
+
this.io = io;
|
|
8573
8754
|
}
|
|
8574
8755
|
ports;
|
|
8756
|
+
io;
|
|
8575
8757
|
// 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.
|
|
8576
8758
|
createConnection(options, oncreate) {
|
|
8577
8759
|
const target = dialTarget(options, HTTP_PORT);
|
|
8578
8760
|
if (net2.isIP(target.host) !== 0) {
|
|
8579
8761
|
return literalDial(target);
|
|
8580
8762
|
}
|
|
8581
|
-
void reservedDial(target, this.ports).then((outcome) => {
|
|
8763
|
+
void reservedDial(target, this.ports, this.io).then((outcome) => {
|
|
8582
8764
|
oncreate?.(outcome.error, outcome.socket);
|
|
8583
8765
|
});
|
|
8584
8766
|
return void 0;
|
|
8585
8767
|
}
|
|
8586
8768
|
};
|
|
8587
8769
|
ExemptTlsAgent = class extends https2.Agent {
|
|
8588
|
-
constructor(ports = DOOR_SOURCE_PORTS) {
|
|
8770
|
+
constructor(ports = DOOR_SOURCE_PORTS, io = realDoorDialIo()) {
|
|
8589
8771
|
super(POOLING);
|
|
8590
8772
|
this.ports = ports;
|
|
8773
|
+
this.io = io;
|
|
8591
8774
|
}
|
|
8592
8775
|
ports;
|
|
8776
|
+
io;
|
|
8593
8777
|
// 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.
|
|
8594
8778
|
createConnection(options, oncreate) {
|
|
8595
8779
|
const target = dialTarget(options, HTTPS_PORT);
|
|
8596
8780
|
if (net2.isIP(target.host) !== 0) {
|
|
8597
8781
|
return tls.connect({ socket: literalDial(target), servername: requestServername(options, target.host), ...tlsFacts(options) });
|
|
8598
8782
|
}
|
|
8599
|
-
void reservedDial(target, this.ports).then((outcome) => {
|
|
8783
|
+
void reservedDial(target, this.ports, this.io).then((outcome) => {
|
|
8600
8784
|
if (outcome.error !== null) {
|
|
8601
8785
|
oncreate?.(outcome.error, outcome.socket);
|
|
8602
8786
|
return;
|
|
@@ -10646,6 +10830,9 @@ function reportableAllowlistFileProblem(allowlistFile, ports, served) {
|
|
|
10646
10830
|
return problem?.repairable === false || served ? problem : void 0;
|
|
10647
10831
|
}
|
|
10648
10832
|
function verifyAllowlistFile(allowlistFile, ports) {
|
|
10833
|
+
if (platformRefusal(ports.platform) !== void 0) {
|
|
10834
|
+
return void 0;
|
|
10835
|
+
}
|
|
10649
10836
|
const uid = ports.currentUid();
|
|
10650
10837
|
const directories = pathDirectories(allowlistFile, ports);
|
|
10651
10838
|
if (typeof directories === "string") {
|
|
@@ -11716,7 +11903,10 @@ var init_realPorts = __esm({
|
|
|
11716
11903
|
};
|
|
11717
11904
|
SOCKET_PERMISSION_BITS = 4095;
|
|
11718
11905
|
realHeadroomSocketTrust = {
|
|
11719
|
-
platform
|
|
11906
|
+
// Read at each use, not fixed when the module loads, so what the checks do for a platform is testable through the real wiring.
|
|
11907
|
+
get platform() {
|
|
11908
|
+
return process.platform;
|
|
11909
|
+
},
|
|
11720
11910
|
currentUid: () => {
|
|
11721
11911
|
if (process.getuid === void 0) {
|
|
11722
11912
|
throw new Error(`no POSIX user id on ${process.platform}`);
|
|
@@ -13659,7 +13849,7 @@ var init_package = __esm({
|
|
|
13659
13849
|
"package.json"() {
|
|
13660
13850
|
package_default = {
|
|
13661
13851
|
name: "claude-use",
|
|
13662
|
-
version: "14.0.
|
|
13852
|
+
version: "14.0.3",
|
|
13663
13853
|
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.",
|
|
13664
13854
|
license: "MIT",
|
|
13665
13855
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -13708,7 +13898,7 @@ var init_package = __esm({
|
|
|
13708
13898
|
schema: "node scripts/gen-schema.mts"
|
|
13709
13899
|
},
|
|
13710
13900
|
dependencies: {
|
|
13711
|
-
"@anthropic-ai/claude-agent-sdk": "0.3.
|
|
13901
|
+
"@anthropic-ai/claude-agent-sdk": "0.3.316",
|
|
13712
13902
|
"@clack/prompts": "^1.8.0",
|
|
13713
13903
|
"@modelcontextprotocol/sdk": "1.32.0",
|
|
13714
13904
|
"@orpc/client": "2.0.0-beta.46",
|
|
@@ -14921,26 +15111,6 @@ var init_paths = __esm({
|
|
|
14921
15111
|
}
|
|
14922
15112
|
});
|
|
14923
15113
|
|
|
14924
|
-
// src/baseUrlDial.ts
|
|
14925
|
-
function dialHostOf(url) {
|
|
14926
|
-
return url.hostname.replace(/^\[(.*)\]$/, "$1");
|
|
14927
|
-
}
|
|
14928
|
-
function dialTargetOf(baseUrl) {
|
|
14929
|
-
const url = new URL(baseUrl);
|
|
14930
|
-
const defaultPort = DEFAULT_PORTS[url.protocol];
|
|
14931
|
-
if (defaultPort === void 0) {
|
|
14932
|
-
throw new Error(`${url.protocol} is not a scheme a provider's base URL can have`);
|
|
14933
|
-
}
|
|
14934
|
-
return { host: dialHostOf(url), port: url.port === "" ? defaultPort : Number(url.port) };
|
|
14935
|
-
}
|
|
14936
|
-
var DEFAULT_PORTS;
|
|
14937
|
-
var init_baseUrlDial = __esm({
|
|
14938
|
-
"src/baseUrlDial.ts"() {
|
|
14939
|
-
"use strict";
|
|
14940
|
-
DEFAULT_PORTS = { "http:": 80, "https:": 443 };
|
|
14941
|
-
}
|
|
14942
|
-
});
|
|
14943
|
-
|
|
14944
15114
|
// src/frontdoor/probe.ts
|
|
14945
15115
|
import { Worker } from "node:worker_threads";
|
|
14946
15116
|
function probeWorkerSource(body) {
|
|
@@ -14958,7 +15128,7 @@ function probeFrontDoorSync(port, caPem, timeoutMs = PROBE_TIMEOUT_MS, workers =
|
|
|
14958
15128
|
}
|
|
14959
15129
|
function probeListenerAcceptSync(port, timeoutMs = PROBE_TIMEOUT_MS, workers = realProbeWorkers) {
|
|
14960
15130
|
refuseToBlockInRole("a synchronous probe of a front door listener");
|
|
14961
|
-
return workers.start(ACCEPT_PROBE_SOURCE, { host: "127.0.0.1", port, portStart: DOOR_SOURCE_PORT_START, portEnd: DOOR_SOURCE_PORT_END }, timeoutMs).verdict();
|
|
15131
|
+
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();
|
|
14962
15132
|
}
|
|
14963
15133
|
function startAddressProbes(targets, workers = realProbeWorkers, portBase) {
|
|
14964
15134
|
refuseToBlockInRole("a synchronous probe of a provider's address");
|
|
@@ -14983,7 +15153,7 @@ function startAddressProbes(targets, workers = realProbeWorkers, portBase) {
|
|
|
14983
15153
|
}
|
|
14984
15154
|
const portFirst = DOOR_SOURCE_PORT_START + (base + index * stride) % DOOR_SOURCE_PORT_COUNT;
|
|
14985
15155
|
try {
|
|
14986
|
-
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);
|
|
15156
|
+
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);
|
|
14987
15157
|
running.push({ key: targetKey(target), verdict: started.verdict, cancel: started.cancel });
|
|
14988
15158
|
} catch (error) {
|
|
14989
15159
|
const reason = `${PROBE_WORKER_FAILURE_PREFIX}the worker could not be started: ${error instanceof Error ? error.message : String(error)}`;
|
|
@@ -15157,15 +15327,16 @@ request.end();
|
|
|
15157
15327
|
ACCEPT_PROBE_SOURCE = probeWorkerSource(`
|
|
15158
15328
|
const net = require("node:net");
|
|
15159
15329
|
const dns = require("node:dns");
|
|
15160
|
-
const { host, port, portStart, portEnd, portFirst, timeoutMs, ok, failed } = workerData;
|
|
15330
|
+
const { host, port, portStart, portEnd, portFirst, platform, timeoutMs, ok, failed } = workerData;
|
|
15161
15331
|
const finish = finishProbe;
|
|
15162
15332
|
const SourcePortRange = ${SourcePortRange.toString()};
|
|
15163
15333
|
const createDoorLookup = ${createDoorLookup.toString()};
|
|
15334
|
+
const sourcePortClassifier = ${sourcePortClassifier.toString()};
|
|
15164
15335
|
const doorDial = ${doorDial.toString()};
|
|
15165
15336
|
const probeAccept = ${probeAccept.toString()};
|
|
15166
15337
|
const runAcceptProbe = ${runAcceptProbe.toString()};
|
|
15167
15338
|
const startTimer = (callback, ms) => { const timer = setTimeout(callback, ms); return () => { clearTimeout(timer); }; };
|
|
15168
|
-
runAcceptProbe({ net, dns, createDoorLookup, doorDial, probeAccept, SourcePortRange }, { host, port, portStart, portEnd, portFirst, timeoutMs }, startTimer).then((verdict) => {
|
|
15339
|
+
runAcceptProbe({ net, dns, createDoorLookup, doorDial, probeAccept, SourcePortRange, sourcePortClassifier }, { host, port, portStart, portEnd, portFirst, platform, timeoutMs }, startTimer).then((verdict) => {
|
|
15169
15340
|
finish(verdict.ok ? ok : failed, verdict.ok ? "" : verdict.reason);
|
|
15170
15341
|
});
|
|
15171
15342
|
`);
|
|
@@ -18805,13 +18976,13 @@ function withRegisteredSessionFacts(statuses, registry) {
|
|
|
18805
18976
|
};
|
|
18806
18977
|
});
|
|
18807
18978
|
}
|
|
18808
|
-
function withIdentityNames(statuses,
|
|
18979
|
+
function withIdentityNames(statuses, nameOf2) {
|
|
18809
18980
|
return statuses.map((status) => {
|
|
18810
18981
|
if (status.identity === void 0) {
|
|
18811
18982
|
return status;
|
|
18812
18983
|
}
|
|
18813
18984
|
const { identity: id, ...rest } = status;
|
|
18814
|
-
const name =
|
|
18985
|
+
const name = nameOf2(id);
|
|
18815
18986
|
return name === void 0 ? rest : { ...rest, identity: name };
|
|
18816
18987
|
});
|
|
18817
18988
|
}
|