agent-shim 7.1.3 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +455 -324
- package/dist/index.cjs +25 -4
- package/dist/index.mjs +25 -4
- package/dist/types/frontdoor/capture.d.ts +49 -0
- package/dist/types/frontdoor/connect.d.ts +8 -5
- package/dist/types/usage/schema.d.ts +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -3248,42 +3248,42 @@ var require_defaults = __commonJS({
|
|
|
3248
3248
|
var require_env_paths = __commonJS({
|
|
3249
3249
|
"node_modules/.pnpm/env-paths@2.2.1/node_modules/env-paths/index.js"(exports2, module2) {
|
|
3250
3250
|
"use strict";
|
|
3251
|
-
var
|
|
3251
|
+
var path38 = require("path");
|
|
3252
3252
|
var os9 = require("os");
|
|
3253
3253
|
var homedir = os9.homedir();
|
|
3254
3254
|
var tmpdir = os9.tmpdir();
|
|
3255
3255
|
var { env } = process;
|
|
3256
3256
|
var macos = (name) => {
|
|
3257
|
-
const library =
|
|
3257
|
+
const library = path38.join(homedir, "Library");
|
|
3258
3258
|
return {
|
|
3259
|
-
data:
|
|
3260
|
-
config:
|
|
3261
|
-
cache:
|
|
3262
|
-
log:
|
|
3263
|
-
temp:
|
|
3259
|
+
data: path38.join(library, "Application Support", name),
|
|
3260
|
+
config: path38.join(library, "Preferences", name),
|
|
3261
|
+
cache: path38.join(library, "Caches", name),
|
|
3262
|
+
log: path38.join(library, "Logs", name),
|
|
3263
|
+
temp: path38.join(tmpdir, name)
|
|
3264
3264
|
};
|
|
3265
3265
|
};
|
|
3266
3266
|
var windows = (name) => {
|
|
3267
|
-
const appData = env.APPDATA ||
|
|
3268
|
-
const localAppData = env.LOCALAPPDATA ||
|
|
3267
|
+
const appData = env.APPDATA || path38.join(homedir, "AppData", "Roaming");
|
|
3268
|
+
const localAppData = env.LOCALAPPDATA || path38.join(homedir, "AppData", "Local");
|
|
3269
3269
|
return {
|
|
3270
3270
|
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
|
|
3271
|
-
data:
|
|
3272
|
-
config:
|
|
3273
|
-
cache:
|
|
3274
|
-
log:
|
|
3275
|
-
temp:
|
|
3271
|
+
data: path38.join(localAppData, name, "Data"),
|
|
3272
|
+
config: path38.join(appData, name, "Config"),
|
|
3273
|
+
cache: path38.join(localAppData, name, "Cache"),
|
|
3274
|
+
log: path38.join(localAppData, name, "Log"),
|
|
3275
|
+
temp: path38.join(tmpdir, name)
|
|
3276
3276
|
};
|
|
3277
3277
|
};
|
|
3278
3278
|
var linux = (name) => {
|
|
3279
|
-
const username =
|
|
3279
|
+
const username = path38.basename(homedir);
|
|
3280
3280
|
return {
|
|
3281
|
-
data:
|
|
3282
|
-
config:
|
|
3283
|
-
cache:
|
|
3281
|
+
data: path38.join(env.XDG_DATA_HOME || path38.join(homedir, ".local", "share"), name),
|
|
3282
|
+
config: path38.join(env.XDG_CONFIG_HOME || path38.join(homedir, ".config"), name),
|
|
3283
|
+
cache: path38.join(env.XDG_CACHE_HOME || path38.join(homedir, ".cache"), name),
|
|
3284
3284
|
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
|
|
3285
|
-
log:
|
|
3286
|
-
temp:
|
|
3285
|
+
log: path38.join(env.XDG_STATE_HOME || path38.join(homedir, ".local", "state"), name),
|
|
3286
|
+
temp: path38.join(tmpdir, username, name)
|
|
3287
3287
|
};
|
|
3288
3288
|
};
|
|
3289
3289
|
var envPaths = (name, options) => {
|
|
@@ -3351,11 +3351,11 @@ var require_util = __commonJS({
|
|
|
3351
3351
|
return result;
|
|
3352
3352
|
}
|
|
3353
3353
|
exports2.emplace = emplace;
|
|
3354
|
-
function getPropertyByPath(source,
|
|
3355
|
-
if (typeof
|
|
3356
|
-
return source[
|
|
3354
|
+
function getPropertyByPath(source, path38) {
|
|
3355
|
+
if (typeof path38 === "string" && Object.prototype.hasOwnProperty.call(source, path38)) {
|
|
3356
|
+
return source[path38];
|
|
3357
3357
|
}
|
|
3358
|
-
const parsedPath = typeof
|
|
3358
|
+
const parsedPath = typeof path38 === "string" ? path38.split(".") : path38;
|
|
3359
3359
|
return parsedPath.reduce((previous, key) => {
|
|
3360
3360
|
if (previous === void 0) {
|
|
3361
3361
|
return previous;
|
|
@@ -3378,9 +3378,9 @@ var require_util = __commonJS({
|
|
|
3378
3378
|
return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== void 0));
|
|
3379
3379
|
}
|
|
3380
3380
|
exports2.removeUndefinedValuesFromObject = removeUndefinedValuesFromObject;
|
|
3381
|
-
async function isDirectory(
|
|
3381
|
+
async function isDirectory(path38) {
|
|
3382
3382
|
try {
|
|
3383
|
-
const stat = await fs_1.promises.stat(
|
|
3383
|
+
const stat = await fs_1.promises.stat(path38);
|
|
3384
3384
|
return stat.isDirectory();
|
|
3385
3385
|
} catch (e) {
|
|
3386
3386
|
if (e.code === "ENOENT") {
|
|
@@ -3390,9 +3390,9 @@ var require_util = __commonJS({
|
|
|
3390
3390
|
}
|
|
3391
3391
|
}
|
|
3392
3392
|
exports2.isDirectory = isDirectory;
|
|
3393
|
-
function isDirectorySync(
|
|
3393
|
+
function isDirectorySync(path38) {
|
|
3394
3394
|
try {
|
|
3395
|
-
const stat = fs_1.default.statSync(
|
|
3395
|
+
const stat = fs_1.default.statSync(path38);
|
|
3396
3396
|
return stat.isDirectory();
|
|
3397
3397
|
} catch (e) {
|
|
3398
3398
|
if (e.code === "ENOENT") {
|
|
@@ -3490,7 +3490,7 @@ var require_ExplorerBase = __commonJS({
|
|
|
3490
3490
|
const idx = importStack.indexOf(fullPath);
|
|
3491
3491
|
if (idx !== -1) {
|
|
3492
3492
|
throw new Error(`Circular import detected:
|
|
3493
|
-
${[...importStack, fullPath].map((
|
|
3493
|
+
${[...importStack, fullPath].map((path38, i2) => `${i2 + 1}. ${path38}`).join("\n")} (same as ${idx + 1}.)`);
|
|
3494
3494
|
}
|
|
3495
3495
|
}
|
|
3496
3496
|
}
|
|
@@ -3678,9 +3678,9 @@ var require_Explorer = __commonJS({
|
|
|
3678
3678
|
throw error62;
|
|
3679
3679
|
}
|
|
3680
3680
|
}
|
|
3681
|
-
async #fileExists(
|
|
3681
|
+
async #fileExists(path38) {
|
|
3682
3682
|
try {
|
|
3683
|
-
await promises_1.default.stat(
|
|
3683
|
+
await promises_1.default.stat(path38);
|
|
3684
3684
|
return true;
|
|
3685
3685
|
} catch (e) {
|
|
3686
3686
|
return false;
|
|
@@ -3840,9 +3840,9 @@ var require_ExplorerSync = __commonJS({
|
|
|
3840
3840
|
throw error62;
|
|
3841
3841
|
}
|
|
3842
3842
|
}
|
|
3843
|
-
#fileExists(
|
|
3843
|
+
#fileExists(path38) {
|
|
3844
3844
|
try {
|
|
3845
|
-
fs_1.default.statSync(
|
|
3845
|
+
fs_1.default.statSync(path38);
|
|
3846
3846
|
return true;
|
|
3847
3847
|
} catch (e) {
|
|
3848
3848
|
return false;
|
|
@@ -3966,7 +3966,7 @@ var require_dist = __commonJS({
|
|
|
3966
3966
|
};
|
|
3967
3967
|
}
|
|
3968
3968
|
function getResolvedSearchPlaces(moduleName, toolDefinedSearchPlaces, userConfiguredOptions) {
|
|
3969
|
-
const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((
|
|
3969
|
+
const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((path38) => path38.replace("{name}", moduleName));
|
|
3970
3970
|
if (userConfiguredOptions.mergeSearchPlaces) {
|
|
3971
3971
|
return [...userConfiguredSearchPlaces ?? [], ...toolDefinedSearchPlaces];
|
|
3972
3972
|
}
|
|
@@ -4374,8 +4374,8 @@ var require_utils = __commonJS({
|
|
|
4374
4374
|
}
|
|
4375
4375
|
return output2;
|
|
4376
4376
|
};
|
|
4377
|
-
exports2.basename = (
|
|
4378
|
-
const segs =
|
|
4377
|
+
exports2.basename = (path38, { windows } = {}) => {
|
|
4378
|
+
const segs = path38.split(windows ? /[\\/]/ : "/");
|
|
4379
4379
|
const last = segs[segs.length - 1];
|
|
4380
4380
|
if (last === "") {
|
|
4381
4381
|
return segs[segs.length - 2];
|
|
@@ -7003,14 +7003,14 @@ var require_util2 = __commonJS({
|
|
|
7003
7003
|
}
|
|
7004
7004
|
const port = url2.port != null ? url2.port : url2.protocol === "https:" ? 443 : 80;
|
|
7005
7005
|
let origin = url2.origin != null ? url2.origin : `${url2.protocol || ""}//${url2.hostname || ""}:${port}`;
|
|
7006
|
-
let
|
|
7006
|
+
let path38 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
|
|
7007
7007
|
if (origin[origin.length - 1] === "/") {
|
|
7008
7008
|
origin = origin.slice(0, origin.length - 1);
|
|
7009
7009
|
}
|
|
7010
|
-
if (
|
|
7011
|
-
|
|
7010
|
+
if (path38 && path38[0] !== "/") {
|
|
7011
|
+
path38 = `/${path38}`;
|
|
7012
7012
|
}
|
|
7013
|
-
return new URL(`${origin}${
|
|
7013
|
+
return new URL(`${origin}${path38}`);
|
|
7014
7014
|
}
|
|
7015
7015
|
if (!isHttpOrHttpsPrefixed(url2.origin || url2.protocol)) {
|
|
7016
7016
|
throw new InvalidArgumentError2("Invalid URL protocol: the URL must start with `http:` or `https:`.");
|
|
@@ -7831,9 +7831,9 @@ var require_diagnostics = __commonJS({
|
|
|
7831
7831
|
"undici:client:sendHeaders",
|
|
7832
7832
|
(evt) => {
|
|
7833
7833
|
const {
|
|
7834
|
-
request: { method, path:
|
|
7834
|
+
request: { method, path: path38, origin }
|
|
7835
7835
|
} = evt;
|
|
7836
|
-
debugLog("sending request to %s %s%s", method, origin,
|
|
7836
|
+
debugLog("sending request to %s %s%s", method, origin, path38);
|
|
7837
7837
|
}
|
|
7838
7838
|
);
|
|
7839
7839
|
}
|
|
@@ -7851,14 +7851,14 @@ var require_diagnostics = __commonJS({
|
|
|
7851
7851
|
"undici:request:headers",
|
|
7852
7852
|
(evt) => {
|
|
7853
7853
|
const {
|
|
7854
|
-
request: { method, path:
|
|
7854
|
+
request: { method, path: path38, origin },
|
|
7855
7855
|
response: { statusCode }
|
|
7856
7856
|
} = evt;
|
|
7857
7857
|
debugLog(
|
|
7858
7858
|
"received response to %s %s%s - HTTP %d",
|
|
7859
7859
|
method,
|
|
7860
7860
|
origin,
|
|
7861
|
-
|
|
7861
|
+
path38,
|
|
7862
7862
|
statusCode
|
|
7863
7863
|
);
|
|
7864
7864
|
}
|
|
@@ -7867,23 +7867,23 @@ var require_diagnostics = __commonJS({
|
|
|
7867
7867
|
"undici:request:trailers",
|
|
7868
7868
|
(evt) => {
|
|
7869
7869
|
const {
|
|
7870
|
-
request: { method, path:
|
|
7870
|
+
request: { method, path: path38, origin }
|
|
7871
7871
|
} = evt;
|
|
7872
|
-
debugLog("trailers received from %s %s%s", method, origin,
|
|
7872
|
+
debugLog("trailers received from %s %s%s", method, origin, path38);
|
|
7873
7873
|
}
|
|
7874
7874
|
);
|
|
7875
7875
|
diagnosticsChannel.subscribe(
|
|
7876
7876
|
"undici:request:error",
|
|
7877
7877
|
(evt) => {
|
|
7878
7878
|
const {
|
|
7879
|
-
request: { method, path:
|
|
7879
|
+
request: { method, path: path38, origin },
|
|
7880
7880
|
error: error62
|
|
7881
7881
|
} = evt;
|
|
7882
7882
|
debugLog(
|
|
7883
7883
|
"request to %s %s%s errored - %s",
|
|
7884
7884
|
method,
|
|
7885
7885
|
origin,
|
|
7886
|
-
|
|
7886
|
+
path38,
|
|
7887
7887
|
error62.message
|
|
7888
7888
|
);
|
|
7889
7889
|
}
|
|
@@ -7998,7 +7998,7 @@ var require_request = __commonJS({
|
|
|
7998
7998
|
var kHandler = /* @__PURE__ */ Symbol("handler");
|
|
7999
7999
|
var Request = class {
|
|
8000
8000
|
constructor(origin, {
|
|
8001
|
-
path:
|
|
8001
|
+
path: path38,
|
|
8002
8002
|
method,
|
|
8003
8003
|
body,
|
|
8004
8004
|
headers,
|
|
@@ -8015,11 +8015,11 @@ var require_request = __commonJS({
|
|
|
8015
8015
|
maxRedirections,
|
|
8016
8016
|
typeOfService
|
|
8017
8017
|
}, handler) {
|
|
8018
|
-
if (typeof
|
|
8018
|
+
if (typeof path38 !== "string") {
|
|
8019
8019
|
throw new InvalidArgumentError2("path must be a string");
|
|
8020
|
-
} else if (
|
|
8020
|
+
} else if (path38[0] !== "/" && !(path38.startsWith("http://") || path38.startsWith("https://")) && method !== "CONNECT") {
|
|
8021
8021
|
throw new InvalidArgumentError2("path must be an absolute URL or start with a slash");
|
|
8022
|
-
} else if (invalidPathRegex.test(
|
|
8022
|
+
} else if (invalidPathRegex.test(path38)) {
|
|
8023
8023
|
throw new InvalidArgumentError2("invalid request path");
|
|
8024
8024
|
}
|
|
8025
8025
|
if (typeof method !== "string") {
|
|
@@ -8094,7 +8094,7 @@ var require_request = __commonJS({
|
|
|
8094
8094
|
this.completed = false;
|
|
8095
8095
|
this.aborted = false;
|
|
8096
8096
|
this.upgrade = upgrade || null;
|
|
8097
|
-
this.path = query ? serializePathWithQuery(
|
|
8097
|
+
this.path = query ? serializePathWithQuery(path38, query) : path38;
|
|
8098
8098
|
this.origin = origin;
|
|
8099
8099
|
this.protocol = getProtocolFromUrlString(origin);
|
|
8100
8100
|
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
|
|
@@ -13276,7 +13276,7 @@ var require_client_h1 = __commonJS({
|
|
|
13276
13276
|
return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
|
|
13277
13277
|
}
|
|
13278
13278
|
function writeH1(client, request6) {
|
|
13279
|
-
const { method, path:
|
|
13279
|
+
const { method, path: path38, host, upgrade, blocking, reset } = request6;
|
|
13280
13280
|
let { body, headers, contentLength } = request6;
|
|
13281
13281
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
|
|
13282
13282
|
if (util.isFormDataLike(body)) {
|
|
@@ -13354,7 +13354,7 @@ var require_client_h1 = __commonJS({
|
|
|
13354
13354
|
if (socket.setTypeOfService) {
|
|
13355
13355
|
socket.setTypeOfService(request6.typeOfService);
|
|
13356
13356
|
}
|
|
13357
|
-
let header = `${method} ${
|
|
13357
|
+
let header = `${method} ${path38} HTTP/1.1\r
|
|
13358
13358
|
`;
|
|
13359
13359
|
if (typeof host === "string") {
|
|
13360
13360
|
header += `host: ${host}\r
|
|
@@ -14033,7 +14033,7 @@ var require_client_h2 = __commonJS({
|
|
|
14033
14033
|
const headersTimeout = request6.headersTimeout ?? client[kHeadersTimeout];
|
|
14034
14034
|
const bodyTimeout = request6.bodyTimeout ?? client[kBodyTimeout];
|
|
14035
14035
|
const session = client[kHTTP2Session];
|
|
14036
|
-
const { method, path:
|
|
14036
|
+
const { method, path: path38, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request6;
|
|
14037
14037
|
let { body } = request6;
|
|
14038
14038
|
if (upgrade != null && upgrade !== "websocket") {
|
|
14039
14039
|
util.errorRequest(client, request6, new InvalidArgumentError2(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
|
|
@@ -14102,7 +14102,7 @@ var require_client_h2 = __commonJS({
|
|
|
14102
14102
|
}
|
|
14103
14103
|
headers[HTTP2_HEADER_METHOD] = "CONNECT";
|
|
14104
14104
|
headers[HTTP2_HEADER_PROTOCOL] = "websocket";
|
|
14105
|
-
headers[HTTP2_HEADER_PATH] =
|
|
14105
|
+
headers[HTTP2_HEADER_PATH] = path38;
|
|
14106
14106
|
if (protocol === "ws:" || protocol === "wss:") {
|
|
14107
14107
|
headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
|
|
14108
14108
|
} else {
|
|
@@ -14144,7 +14144,7 @@ var require_client_h2 = __commonJS({
|
|
|
14144
14144
|
stream.setTimeout(headersTimeout);
|
|
14145
14145
|
return true;
|
|
14146
14146
|
}
|
|
14147
|
-
headers[HTTP2_HEADER_PATH] =
|
|
14147
|
+
headers[HTTP2_HEADER_PATH] = path38;
|
|
14148
14148
|
headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
|
|
14149
14149
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
14150
14150
|
if (body && typeof body.read === "function") {
|
|
@@ -16496,10 +16496,10 @@ var require_proxy_agent = __commonJS({
|
|
|
16496
16496
|
};
|
|
16497
16497
|
const {
|
|
16498
16498
|
origin,
|
|
16499
|
-
path:
|
|
16499
|
+
path: path38 = "/",
|
|
16500
16500
|
headers = {}
|
|
16501
16501
|
} = opts;
|
|
16502
|
-
opts.path = origin +
|
|
16502
|
+
opts.path = origin + path38;
|
|
16503
16503
|
if (!("host" in headers) && !("Host" in headers)) {
|
|
16504
16504
|
const { host } = new URL(origin);
|
|
16505
16505
|
headers.host = host;
|
|
@@ -18608,20 +18608,20 @@ var require_mock_utils = __commonJS({
|
|
|
18608
18608
|
}
|
|
18609
18609
|
return normalizedQp;
|
|
18610
18610
|
}
|
|
18611
|
-
function safeUrl(
|
|
18612
|
-
if (typeof
|
|
18613
|
-
return
|
|
18611
|
+
function safeUrl(path38) {
|
|
18612
|
+
if (typeof path38 !== "string") {
|
|
18613
|
+
return path38;
|
|
18614
18614
|
}
|
|
18615
|
-
const pathSegments =
|
|
18615
|
+
const pathSegments = path38.split("?", 3);
|
|
18616
18616
|
if (pathSegments.length !== 2) {
|
|
18617
|
-
return
|
|
18617
|
+
return path38;
|
|
18618
18618
|
}
|
|
18619
18619
|
const qp = new URLSearchParams(pathSegments.pop());
|
|
18620
18620
|
qp.sort();
|
|
18621
18621
|
return [...pathSegments, qp.toString()].join("?");
|
|
18622
18622
|
}
|
|
18623
|
-
function matchKey(mockDispatch2, { path:
|
|
18624
|
-
const pathMatch = matchValue(mockDispatch2.path,
|
|
18623
|
+
function matchKey(mockDispatch2, { path: path38, method, body, headers }) {
|
|
18624
|
+
const pathMatch = matchValue(mockDispatch2.path, path38);
|
|
18625
18625
|
const methodMatch = matchValue(mockDispatch2.method, method);
|
|
18626
18626
|
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
|
|
18627
18627
|
const headersMatch = matchHeaders(mockDispatch2, headers);
|
|
@@ -18646,8 +18646,8 @@ var require_mock_utils = __commonJS({
|
|
|
18646
18646
|
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
|
|
18647
18647
|
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
|
|
18648
18648
|
const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
|
|
18649
|
-
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path:
|
|
18650
|
-
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(
|
|
18649
|
+
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path38, ignoreTrailingSlash }) => {
|
|
18650
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path38)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path38), resolvedPath);
|
|
18651
18651
|
});
|
|
18652
18652
|
if (matchedMockDispatches.length === 0) {
|
|
18653
18653
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
@@ -18686,19 +18686,19 @@ var require_mock_utils = __commonJS({
|
|
|
18686
18686
|
mockDispatches.splice(index, 1);
|
|
18687
18687
|
}
|
|
18688
18688
|
}
|
|
18689
|
-
function removeTrailingSlash(
|
|
18690
|
-
while (
|
|
18691
|
-
|
|
18689
|
+
function removeTrailingSlash(path38) {
|
|
18690
|
+
while (path38.endsWith("/")) {
|
|
18691
|
+
path38 = path38.slice(0, -1);
|
|
18692
18692
|
}
|
|
18693
|
-
if (
|
|
18694
|
-
|
|
18693
|
+
if (path38.length === 0) {
|
|
18694
|
+
path38 = "/";
|
|
18695
18695
|
}
|
|
18696
|
-
return
|
|
18696
|
+
return path38;
|
|
18697
18697
|
}
|
|
18698
18698
|
function buildKey(opts) {
|
|
18699
|
-
const { path:
|
|
18699
|
+
const { path: path38, method, body, headers, query } = opts;
|
|
18700
18700
|
return {
|
|
18701
|
-
path:
|
|
18701
|
+
path: path38,
|
|
18702
18702
|
method,
|
|
18703
18703
|
body,
|
|
18704
18704
|
headers,
|
|
@@ -19388,10 +19388,10 @@ var require_pending_interceptors_formatter = __commonJS({
|
|
|
19388
19388
|
}
|
|
19389
19389
|
format(pendingInterceptors) {
|
|
19390
19390
|
const withPrettyHeaders = pendingInterceptors.map(
|
|
19391
|
-
({ method, path:
|
|
19391
|
+
({ method, path: path38, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
19392
19392
|
Method: method,
|
|
19393
19393
|
Origin: origin,
|
|
19394
|
-
Path:
|
|
19394
|
+
Path: path38,
|
|
19395
19395
|
"Status code": statusCode,
|
|
19396
19396
|
Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
|
|
19397
19397
|
Invocations: timesInvoked,
|
|
@@ -19473,9 +19473,9 @@ var require_mock_agent = __commonJS({
|
|
|
19473
19473
|
const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
|
|
19474
19474
|
const dispatchOpts = { ...opts };
|
|
19475
19475
|
if (acceptNonStandardSearchParameters && dispatchOpts.path) {
|
|
19476
|
-
const [
|
|
19476
|
+
const [path38, searchParams] = dispatchOpts.path.split("?");
|
|
19477
19477
|
const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
|
|
19478
|
-
dispatchOpts.path = `${
|
|
19478
|
+
dispatchOpts.path = `${path38}?${normalizedSearchParams}`;
|
|
19479
19479
|
}
|
|
19480
19480
|
return this[kAgent].dispatch(dispatchOpts, handler);
|
|
19481
19481
|
}
|
|
@@ -19680,7 +19680,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
19680
19680
|
"node_modules/.pnpm/undici@7.29.1/node_modules/undici/lib/mock/snapshot-recorder.js"(exports2, module2) {
|
|
19681
19681
|
"use strict";
|
|
19682
19682
|
var { writeFile, readFile, mkdir } = require("node:fs/promises");
|
|
19683
|
-
var { dirname, resolve } = require("node:path");
|
|
19683
|
+
var { dirname: dirname2, resolve } = require("node:path");
|
|
19684
19684
|
var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = require("node:timers");
|
|
19685
19685
|
var { InvalidArgumentError: InvalidArgumentError2, UndiciError } = require_errors();
|
|
19686
19686
|
var { hashId, isUrlExcludedFactory, normalizeHeaders, createHeaderFilters } = require_snapshot_utils();
|
|
@@ -19876,12 +19876,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
19876
19876
|
* @return {Promise<void>} - Resolves when snapshots are loaded
|
|
19877
19877
|
*/
|
|
19878
19878
|
async loadSnapshots(filePath) {
|
|
19879
|
-
const
|
|
19880
|
-
if (!
|
|
19879
|
+
const path38 = filePath || this.#snapshotPath;
|
|
19880
|
+
if (!path38) {
|
|
19881
19881
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
19882
19882
|
}
|
|
19883
19883
|
try {
|
|
19884
|
-
const data = await readFile(resolve(
|
|
19884
|
+
const data = await readFile(resolve(path38), "utf8");
|
|
19885
19885
|
const parsed = JSON.parse(data);
|
|
19886
19886
|
if (Array.isArray(parsed)) {
|
|
19887
19887
|
this.#snapshots.clear();
|
|
@@ -19895,7 +19895,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
19895
19895
|
if (error62.code === "ENOENT") {
|
|
19896
19896
|
this.#snapshots.clear();
|
|
19897
19897
|
} else {
|
|
19898
|
-
throw new UndiciError(`Failed to load snapshots from ${
|
|
19898
|
+
throw new UndiciError(`Failed to load snapshots from ${path38}`, { cause: error62 });
|
|
19899
19899
|
}
|
|
19900
19900
|
}
|
|
19901
19901
|
}
|
|
@@ -19906,12 +19906,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
19906
19906
|
* @returns {Promise<void>} - Resolves when snapshots are saved
|
|
19907
19907
|
*/
|
|
19908
19908
|
async saveSnapshots(filePath) {
|
|
19909
|
-
const
|
|
19910
|
-
if (!
|
|
19909
|
+
const path38 = filePath || this.#snapshotPath;
|
|
19910
|
+
if (!path38) {
|
|
19911
19911
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
19912
19912
|
}
|
|
19913
|
-
const resolvedPath = resolve(
|
|
19914
|
-
await mkdir(
|
|
19913
|
+
const resolvedPath = resolve(path38);
|
|
19914
|
+
await mkdir(dirname2(resolvedPath), { recursive: true });
|
|
19915
19915
|
const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
|
|
19916
19916
|
hash: hash2,
|
|
19917
19917
|
snapshot
|
|
@@ -20542,15 +20542,15 @@ var require_redirect_handler = __commonJS({
|
|
|
20542
20542
|
return;
|
|
20543
20543
|
}
|
|
20544
20544
|
const { origin, pathname, search } = util.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
|
|
20545
|
-
const
|
|
20546
|
-
const redirectUrlString = `${origin}${
|
|
20545
|
+
const path38 = search ? `${pathname}${search}` : pathname;
|
|
20546
|
+
const redirectUrlString = `${origin}${path38}`;
|
|
20547
20547
|
for (const historyUrl of this.history) {
|
|
20548
20548
|
if (historyUrl.toString() === redirectUrlString) {
|
|
20549
20549
|
throw new InvalidArgumentError2(`Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.`);
|
|
20550
20550
|
}
|
|
20551
20551
|
}
|
|
20552
20552
|
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
|
|
20553
|
-
this.opts.path =
|
|
20553
|
+
this.opts.path = path38;
|
|
20554
20554
|
this.opts.origin = origin;
|
|
20555
20555
|
this.opts.query = null;
|
|
20556
20556
|
}
|
|
@@ -22310,10 +22310,10 @@ var require_cache_handler = __commonJS({
|
|
|
22310
22310
|
}
|
|
22311
22311
|
return locationUrl.pathname + locationUrl.search;
|
|
22312
22312
|
}
|
|
22313
|
-
function deleteCachedUri(store, cacheKey,
|
|
22313
|
+
function deleteCachedUri(store, cacheKey, path38) {
|
|
22314
22314
|
deleteCachedValue(store, {
|
|
22315
22315
|
...cacheKey,
|
|
22316
|
-
path:
|
|
22316
|
+
path: path38
|
|
22317
22317
|
});
|
|
22318
22318
|
for (let i2 = 0; i2 < util.safeHTTPMethods.length; i2++) {
|
|
22319
22319
|
const method = util.safeHTTPMethods[i2];
|
|
@@ -22321,7 +22321,7 @@ var require_cache_handler = __commonJS({
|
|
|
22321
22321
|
deleteCachedValue(store, {
|
|
22322
22322
|
...cacheKey,
|
|
22323
22323
|
method,
|
|
22324
|
-
path:
|
|
22324
|
+
path: path38
|
|
22325
22325
|
});
|
|
22326
22326
|
}
|
|
22327
22327
|
}
|
|
@@ -22332,9 +22332,9 @@ var require_cache_handler = __commonJS({
|
|
|
22332
22332
|
}
|
|
22333
22333
|
const values = Array.isArray(headerValue2) ? headerValue2 : [headerValue2];
|
|
22334
22334
|
for (let i2 = 0; i2 < values.length; i2++) {
|
|
22335
|
-
const
|
|
22336
|
-
if (
|
|
22337
|
-
deleteCachedUri(store, cacheKey,
|
|
22335
|
+
const path38 = getSameOriginPath(cacheKey, values[i2]);
|
|
22336
|
+
if (path38 !== void 0) {
|
|
22337
|
+
deleteCachedUri(store, cacheKey, path38);
|
|
22338
22338
|
}
|
|
22339
22339
|
}
|
|
22340
22340
|
}
|
|
@@ -27334,11 +27334,11 @@ var require_fetch = __commonJS({
|
|
|
27334
27334
|
function dispatch({ body }) {
|
|
27335
27335
|
const url2 = requestCurrentURL(request6);
|
|
27336
27336
|
const agent = fetchParams.controller.dispatcher;
|
|
27337
|
-
const
|
|
27337
|
+
const path38 = url2.pathname + url2.search;
|
|
27338
27338
|
const hasTrailingQuestionMark = url2.search.length === 0 && url2.href[url2.href.length - url2.hash.length - 1] === "?";
|
|
27339
27339
|
return new Promise((resolve, reject) => agent.dispatch(
|
|
27340
27340
|
{
|
|
27341
|
-
path: hasTrailingQuestionMark ? `${
|
|
27341
|
+
path: hasTrailingQuestionMark ? `${path38}?` : path38,
|
|
27342
27342
|
origin: url2.origin,
|
|
27343
27343
|
method: request6.method,
|
|
27344
27344
|
body: agent.isMockActive ? request6.body && (request6.body.source || request6.body.stream) : body,
|
|
@@ -28285,9 +28285,9 @@ var require_util5 = __commonJS({
|
|
|
28285
28285
|
}
|
|
28286
28286
|
}
|
|
28287
28287
|
}
|
|
28288
|
-
function validateCookiePath(
|
|
28289
|
-
for (let i2 = 0; i2 <
|
|
28290
|
-
const code =
|
|
28288
|
+
function validateCookiePath(path38) {
|
|
28289
|
+
for (let i2 = 0; i2 < path38.length; ++i2) {
|
|
28290
|
+
const code = path38.charCodeAt(i2);
|
|
28291
28291
|
if (code < 32 || // exclude CTLs (0-31)
|
|
28292
28292
|
code > 126 || // exclude DEL and non-ascii
|
|
28293
28293
|
code === 59) {
|
|
@@ -31635,11 +31635,11 @@ var require_undici = __commonJS({
|
|
|
31635
31635
|
if (typeof opts.path !== "string") {
|
|
31636
31636
|
throw new InvalidArgumentError2("invalid opts.path");
|
|
31637
31637
|
}
|
|
31638
|
-
let
|
|
31638
|
+
let path38 = opts.path;
|
|
31639
31639
|
if (!opts.path.startsWith("/")) {
|
|
31640
|
-
|
|
31640
|
+
path38 = `/${path38}`;
|
|
31641
31641
|
}
|
|
31642
|
-
url2 = new URL(util.parseOrigin(url2).origin +
|
|
31642
|
+
url2 = new URL(util.parseOrigin(url2).origin + path38);
|
|
31643
31643
|
} else {
|
|
31644
31644
|
if (!opts) {
|
|
31645
31645
|
opts = typeof url2 === "object" ? url2 : {};
|
|
@@ -31749,7 +31749,7 @@ ${captureLines}` : capture.stack;
|
|
|
31749
31749
|
});
|
|
31750
31750
|
|
|
31751
31751
|
// src/cli.ts
|
|
31752
|
-
var
|
|
31752
|
+
var import_node_path36 = __toESM(require("node:path"), 1);
|
|
31753
31753
|
|
|
31754
31754
|
// node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
|
|
31755
31755
|
var CommanderError = class extends Error {
|
|
@@ -34862,9 +34862,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
34862
34862
|
* @param {string} [path]
|
|
34863
34863
|
* @return {(string|null|Command)}
|
|
34864
34864
|
*/
|
|
34865
|
-
executableDir(
|
|
34866
|
-
if (
|
|
34867
|
-
this._executableDir =
|
|
34865
|
+
executableDir(path38) {
|
|
34866
|
+
if (path38 === void 0) return this._executableDir;
|
|
34867
|
+
this._executableDir = path38;
|
|
34868
34868
|
return this;
|
|
34869
34869
|
}
|
|
34870
34870
|
/**
|
|
@@ -36002,10 +36002,10 @@ function mergeDefs(...defs) {
|
|
|
36002
36002
|
function cloneDef(schema) {
|
|
36003
36003
|
return mergeDefs(schema._zod.def);
|
|
36004
36004
|
}
|
|
36005
|
-
function getElementAtPath(obj,
|
|
36006
|
-
if (!
|
|
36005
|
+
function getElementAtPath(obj, path38) {
|
|
36006
|
+
if (!path38)
|
|
36007
36007
|
return obj;
|
|
36008
|
-
return
|
|
36008
|
+
return path38.reduce((acc, key) => acc?.[key], obj);
|
|
36009
36009
|
}
|
|
36010
36010
|
function promiseAllObject(promisesObj) {
|
|
36011
36011
|
const keys = Object.keys(promisesObj);
|
|
@@ -36345,11 +36345,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
36345
36345
|
}
|
|
36346
36346
|
return false;
|
|
36347
36347
|
}
|
|
36348
|
-
function prefixIssues(
|
|
36348
|
+
function prefixIssues(path38, issues) {
|
|
36349
36349
|
return issues.map((iss) => {
|
|
36350
36350
|
var _a3;
|
|
36351
36351
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
36352
|
-
iss.path.unshift(
|
|
36352
|
+
iss.path.unshift(path38);
|
|
36353
36353
|
return iss;
|
|
36354
36354
|
});
|
|
36355
36355
|
}
|
|
@@ -36799,16 +36799,16 @@ function flattenError(error62, mapper = (issue2) => issue2.message) {
|
|
|
36799
36799
|
}
|
|
36800
36800
|
function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
36801
36801
|
const fieldErrors = { _errors: [] };
|
|
36802
|
-
const processError = (error63,
|
|
36802
|
+
const processError = (error63, path38 = []) => {
|
|
36803
36803
|
for (const issue2 of error63.issues) {
|
|
36804
36804
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
36805
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
36805
|
+
issue2.errors.map((issues) => processError({ issues }, [...path38, ...issue2.path]));
|
|
36806
36806
|
} else if (issue2.code === "invalid_key") {
|
|
36807
|
-
processError({ issues: issue2.issues }, [...
|
|
36807
|
+
processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
|
|
36808
36808
|
} else if (issue2.code === "invalid_element") {
|
|
36809
|
-
processError({ issues: issue2.issues }, [...
|
|
36809
|
+
processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
|
|
36810
36810
|
} else {
|
|
36811
|
-
const fullpath = [...
|
|
36811
|
+
const fullpath = [...path38, ...issue2.path];
|
|
36812
36812
|
if (fullpath.length === 0) {
|
|
36813
36813
|
fieldErrors._errors.push(mapper(issue2));
|
|
36814
36814
|
} else {
|
|
@@ -36847,17 +36847,17 @@ function formatError(error62, mapper = (issue2) => issue2.message) {
|
|
|
36847
36847
|
}
|
|
36848
36848
|
function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
36849
36849
|
const result = { errors: [] };
|
|
36850
|
-
const processError = (error63,
|
|
36850
|
+
const processError = (error63, path38 = []) => {
|
|
36851
36851
|
var _a3;
|
|
36852
36852
|
for (const issue2 of error63.issues) {
|
|
36853
36853
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
36854
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
36854
|
+
issue2.errors.map((issues) => processError({ issues }, [...path38, ...issue2.path]));
|
|
36855
36855
|
} else if (issue2.code === "invalid_key") {
|
|
36856
|
-
processError({ issues: issue2.issues }, [...
|
|
36856
|
+
processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
|
|
36857
36857
|
} else if (issue2.code === "invalid_element") {
|
|
36858
|
-
processError({ issues: issue2.issues }, [...
|
|
36858
|
+
processError({ issues: issue2.issues }, [...path38, ...issue2.path]);
|
|
36859
36859
|
} else {
|
|
36860
|
-
const fullpath = [...
|
|
36860
|
+
const fullpath = [...path38, ...issue2.path];
|
|
36861
36861
|
if (fullpath.length === 0) {
|
|
36862
36862
|
result.errors.push(mapper(issue2));
|
|
36863
36863
|
continue;
|
|
@@ -36896,8 +36896,8 @@ function treeifyError(error62, mapper = (issue2) => issue2.message) {
|
|
|
36896
36896
|
}
|
|
36897
36897
|
function toDotPath(_path) {
|
|
36898
36898
|
const segs = [];
|
|
36899
|
-
const
|
|
36900
|
-
for (const seg of
|
|
36899
|
+
const path38 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
36900
|
+
for (const seg of path38) {
|
|
36901
36901
|
if (typeof seg === "number")
|
|
36902
36902
|
segs.push(`[${seg}]`);
|
|
36903
36903
|
else if (typeof seg === "symbol")
|
|
@@ -53999,13 +53999,13 @@ function resolveRef(ref, ctx) {
|
|
|
53999
53999
|
if (!ref.startsWith("#")) {
|
|
54000
54000
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
54001
54001
|
}
|
|
54002
|
-
const
|
|
54003
|
-
if (
|
|
54002
|
+
const path38 = ref.slice(1).split("/").filter(Boolean);
|
|
54003
|
+
if (path38.length === 0) {
|
|
54004
54004
|
return ctx.rootSchema;
|
|
54005
54005
|
}
|
|
54006
54006
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
54007
|
-
if (
|
|
54008
|
-
const key =
|
|
54007
|
+
if (path38[0] === defsKey) {
|
|
54008
|
+
const key = path38[1] === void 0 ? void 0 : decodeJSONPointerSegment(path38[1]);
|
|
54009
54009
|
if (!key || !ctx.defs[key]) {
|
|
54010
54010
|
throw new Error(`Reference not found: ${ref}`);
|
|
54011
54011
|
}
|
|
@@ -55399,16 +55399,16 @@ function parseJson(raw, schema) {
|
|
|
55399
55399
|
const parsed = schema.safeParse(JSON.parse(raw));
|
|
55400
55400
|
return parsed.success ? parsed.data : void 0;
|
|
55401
55401
|
}
|
|
55402
|
-
function readHeadroomState(
|
|
55402
|
+
function readHeadroomState(fs18, stateFile) {
|
|
55403
55403
|
try {
|
|
55404
|
-
return parseJson(
|
|
55404
|
+
return parseJson(fs18.readFileUtf8(stateFile), HeadroomStateSchema);
|
|
55405
55405
|
} catch {
|
|
55406
55406
|
return void 0;
|
|
55407
55407
|
}
|
|
55408
55408
|
}
|
|
55409
|
-
function writeHeadroomState(
|
|
55410
|
-
|
|
55411
|
-
|
|
55409
|
+
function writeHeadroomState(fs18, stateFile, state) {
|
|
55410
|
+
fs18.mkdirp(import_node_path5.default.dirname(stateFile));
|
|
55411
|
+
fs18.writeFilePrivate(stateFile, `${JSON.stringify(state, null, 2)}
|
|
55412
55412
|
`);
|
|
55413
55413
|
}
|
|
55414
55414
|
function headroomAllowlist(providers) {
|
|
@@ -55428,14 +55428,14 @@ function headroomUpstreams(providers, frontDoorOrigin2) {
|
|
|
55428
55428
|
function hashAllowlist(allowlist) {
|
|
55429
55429
|
return (0, import_node_crypto2.createHash)("sha256").update(allowlist.join("\n")).digest("hex");
|
|
55430
55430
|
}
|
|
55431
|
-
function readAllProviders(
|
|
55431
|
+
function readAllProviders(fs18, providersDir) {
|
|
55432
55432
|
const result = [];
|
|
55433
|
-
for (const name of
|
|
55433
|
+
for (const name of fs18.readdir(providersDir)) {
|
|
55434
55434
|
if (!name.endsWith(".json")) {
|
|
55435
55435
|
continue;
|
|
55436
55436
|
}
|
|
55437
55437
|
try {
|
|
55438
|
-
const parsed = parseJson(
|
|
55438
|
+
const parsed = parseJson(fs18.readFileUtf8(import_node_path5.default.join(providersDir, name)), ProviderSchema);
|
|
55439
55439
|
if (parsed !== void 0) {
|
|
55440
55440
|
result.push({ name: name.slice(0, -".json".length), provider: parsed });
|
|
55441
55441
|
}
|
|
@@ -55445,22 +55445,22 @@ function readAllProviders(fs17, providersDir) {
|
|
|
55445
55445
|
}
|
|
55446
55446
|
return result;
|
|
55447
55447
|
}
|
|
55448
|
-
function writeSession(
|
|
55449
|
-
|
|
55450
|
-
|
|
55448
|
+
function writeSession(fs18, sessionsDir, session) {
|
|
55449
|
+
fs18.mkdirp(sessionsDir);
|
|
55450
|
+
fs18.writeFileUtf8(import_node_path5.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
55451
55451
|
`);
|
|
55452
55452
|
}
|
|
55453
|
-
function removeSession(
|
|
55454
|
-
|
|
55453
|
+
function removeSession(fs18, sessionsDir, pid) {
|
|
55454
|
+
fs18.removeRecursive(import_node_path5.default.join(sessionsDir, `${String(pid)}.json`));
|
|
55455
55455
|
}
|
|
55456
|
-
function listSessions(
|
|
55456
|
+
function listSessions(fs18, sessionsDir) {
|
|
55457
55457
|
const sessions = [];
|
|
55458
|
-
for (const name of
|
|
55458
|
+
for (const name of fs18.readdir(sessionsDir)) {
|
|
55459
55459
|
if (!name.endsWith(".json")) {
|
|
55460
55460
|
continue;
|
|
55461
55461
|
}
|
|
55462
55462
|
try {
|
|
55463
|
-
const parsed = parseJson(
|
|
55463
|
+
const parsed = parseJson(fs18.readFileUtf8(import_node_path5.default.join(sessionsDir, name)), HeadroomSessionSchema);
|
|
55464
55464
|
if (parsed !== void 0) {
|
|
55465
55465
|
sessions.push(parsed);
|
|
55466
55466
|
}
|
|
@@ -55470,22 +55470,22 @@ function listSessions(fs17, sessionsDir) {
|
|
|
55470
55470
|
}
|
|
55471
55471
|
return sessions.sort((a2, b) => a2.pid - b.pid);
|
|
55472
55472
|
}
|
|
55473
|
-
function sessionsForSupervisor(
|
|
55474
|
-
return listSessions(
|
|
55473
|
+
function sessionsForSupervisor(fs18, sessionsDir, supervisorPid) {
|
|
55474
|
+
return listSessions(fs18, sessionsDir).filter((session) => session.supervisorPid === supervisorPid);
|
|
55475
55475
|
}
|
|
55476
|
-
function pruneDeadSessions(
|
|
55476
|
+
function pruneDeadSessions(fs18, sessionsDir, isRunning) {
|
|
55477
55477
|
const removed = [];
|
|
55478
|
-
for (const session of listSessions(
|
|
55478
|
+
for (const session of listSessions(fs18, sessionsDir)) {
|
|
55479
55479
|
if (!isRunning(session.pid)) {
|
|
55480
|
-
removeSession(
|
|
55480
|
+
removeSession(fs18, sessionsDir, session.pid);
|
|
55481
55481
|
removed.push(session.pid);
|
|
55482
55482
|
}
|
|
55483
55483
|
}
|
|
55484
55484
|
return removed;
|
|
55485
55485
|
}
|
|
55486
|
-
function readStartLock(
|
|
55486
|
+
function readStartLock(fs18, lockFile) {
|
|
55487
55487
|
try {
|
|
55488
|
-
return parseJson(
|
|
55488
|
+
return parseJson(fs18.readFileUtf8(lockFile), HeadroomLockSchema);
|
|
55489
55489
|
} catch {
|
|
55490
55490
|
return void 0;
|
|
55491
55491
|
}
|
|
@@ -58797,8 +58797,8 @@ var FarmManifestSchema = external_exports.strictObject({
|
|
|
58797
58797
|
materialised: external_exports.array(external_exports.string()),
|
|
58798
58798
|
links: external_exports.array(external_exports.strictObject({ rel: external_exports.string(), target: external_exports.string() }))
|
|
58799
58799
|
});
|
|
58800
|
-
function readFarmManifest(
|
|
58801
|
-
const raw =
|
|
58800
|
+
function readFarmManifest(fs18, farmRoot) {
|
|
58801
|
+
const raw = fs18.readFileUtf8(import_node_path11.default.join(farmRoot, FARM_MANIFEST_FILENAME)) ?? fs18.readFileUtf8(import_node_path11.default.join(farmRoot, LEGACY_FARM_MANIFEST_FILENAME));
|
|
58802
58802
|
if (raw === void 0) {
|
|
58803
58803
|
return void 0;
|
|
58804
58804
|
}
|
|
@@ -58856,9 +58856,9 @@ function buildEntryFacts(params) {
|
|
|
58856
58856
|
entries
|
|
58857
58857
|
};
|
|
58858
58858
|
}
|
|
58859
|
-
function listSubtree(
|
|
58859
|
+
function listSubtree(fs18, root, rel) {
|
|
58860
58860
|
const absolute = import_node_path11.default.join(root, rel);
|
|
58861
|
-
const stat =
|
|
58861
|
+
const stat = fs18.lstat(absolute);
|
|
58862
58862
|
if (stat === void 0) {
|
|
58863
58863
|
return [];
|
|
58864
58864
|
}
|
|
@@ -58866,10 +58866,10 @@ function listSubtree(fs17, root, rel) {
|
|
|
58866
58866
|
return [{ rel, kind: "symlink" }];
|
|
58867
58867
|
}
|
|
58868
58868
|
if (stat.kind === "dir") {
|
|
58869
|
-
const children = [...
|
|
58869
|
+
const children = [...fs18.readdir(absolute)].sort().flatMap((name) => listSubtree(fs18, root, `${rel}/${name}`));
|
|
58870
58870
|
return [{ rel, kind: "dir" }, ...children];
|
|
58871
58871
|
}
|
|
58872
|
-
const contentHash =
|
|
58872
|
+
const contentHash = fs18.hashFile(absolute);
|
|
58873
58873
|
return [{ rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } }];
|
|
58874
58874
|
}
|
|
58875
58875
|
function topLevelScopeRoots(roots) {
|
|
@@ -58883,25 +58883,25 @@ function topLevelScopeRoots(roots) {
|
|
|
58883
58883
|
}
|
|
58884
58884
|
return kept;
|
|
58885
58885
|
}
|
|
58886
|
-
function reconciliationScope(
|
|
58886
|
+
function reconciliationScope(fs18, farmRoot, manifest) {
|
|
58887
58887
|
if (manifest !== void 0) {
|
|
58888
58888
|
return topLevelScopeRoots(manifest.materialised);
|
|
58889
58889
|
}
|
|
58890
|
-
return [...
|
|
58890
|
+
return [...fs18.readdir(farmRoot)].filter((name) => name !== FARM_MANIFEST_FILENAME && name !== LEGACY_FARM_MANIFEST_FILENAME && fs18.lstat(import_node_path11.default.join(farmRoot, name))?.kind === "dir").sort();
|
|
58891
58891
|
}
|
|
58892
|
-
function collectFarmListing(
|
|
58893
|
-
return scopeRoots.flatMap((root) => listSubtree(
|
|
58892
|
+
function collectFarmListing(fs18, farmRoot, scopeRoots) {
|
|
58893
|
+
return scopeRoots.flatMap((root) => listSubtree(fs18, farmRoot, root));
|
|
58894
58894
|
}
|
|
58895
|
-
function collectCanonicalCounterparts(
|
|
58895
|
+
function collectCanonicalCounterparts(fs18, claudeHome, farmListing) {
|
|
58896
58896
|
const out = [];
|
|
58897
58897
|
for (const entry of farmListing) {
|
|
58898
58898
|
const absolute = import_node_path11.default.join(claudeHome, entry.rel);
|
|
58899
|
-
const stat =
|
|
58899
|
+
const stat = fs18.lstat(absolute);
|
|
58900
58900
|
if (stat === void 0) {
|
|
58901
58901
|
continue;
|
|
58902
58902
|
}
|
|
58903
58903
|
if (stat.kind === "file") {
|
|
58904
|
-
const contentHash =
|
|
58904
|
+
const contentHash = fs18.hashFile(absolute);
|
|
58905
58905
|
out.push({ rel: entry.rel, kind: "file", ...contentHash === void 0 ? {} : { contentHash } });
|
|
58906
58906
|
continue;
|
|
58907
58907
|
}
|
|
@@ -59741,8 +59741,8 @@ function decideConfigProfile(params) {
|
|
|
59741
59741
|
}
|
|
59742
59742
|
return { source: "none" };
|
|
59743
59743
|
}
|
|
59744
|
-
function loadIdentity(identitiesDir, name,
|
|
59745
|
-
return loadConfigFile(import_node_path14.default.join(identitiesDir, name, "identity.json"), IdentitySchema,
|
|
59744
|
+
function loadIdentity(identitiesDir, name, fs18) {
|
|
59745
|
+
return loadConfigFile(import_node_path14.default.join(identitiesDir, name, "identity.json"), IdentitySchema, fs18.readConfigFile);
|
|
59746
59746
|
}
|
|
59747
59747
|
|
|
59748
59748
|
// src/poolStore.ts
|
|
@@ -61051,7 +61051,7 @@ function resolveLaunchIdentity(paths, cwd) {
|
|
|
61051
61051
|
// package.json
|
|
61052
61052
|
var package_default = {
|
|
61053
61053
|
name: "agent-shim",
|
|
61054
|
-
version: "7.
|
|
61054
|
+
version: "7.3.0",
|
|
61055
61055
|
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.",
|
|
61056
61056
|
license: "MIT",
|
|
61057
61057
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -61418,12 +61418,12 @@ function isIdentityName(name) {
|
|
|
61418
61418
|
function claudeJsonPath(identitiesDir, identity) {
|
|
61419
61419
|
return import_node_path20.default.join(identitiesDir, identity, CLAUDE_JSON);
|
|
61420
61420
|
}
|
|
61421
|
-
function readAccountMetadata(
|
|
61421
|
+
function readAccountMetadata(fs18, identitiesDir, identity) {
|
|
61422
61422
|
if (!isIdentityName(identity)) {
|
|
61423
61423
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
61424
61424
|
}
|
|
61425
61425
|
const file2 = claudeJsonPath(identitiesDir, identity);
|
|
61426
|
-
const raw =
|
|
61426
|
+
const raw = fs18.readFileUtf8(file2);
|
|
61427
61427
|
if (raw === void 0) {
|
|
61428
61428
|
return void 0;
|
|
61429
61429
|
}
|
|
@@ -61453,19 +61453,19 @@ function readAccountMetadata(fs17, identitiesDir, identity) {
|
|
|
61453
61453
|
}
|
|
61454
61454
|
return account.data;
|
|
61455
61455
|
}
|
|
61456
|
-
function createAccountReader(
|
|
61456
|
+
function createAccountReader(fs18, identitiesDir) {
|
|
61457
61457
|
const cache = /* @__PURE__ */ new Map();
|
|
61458
61458
|
return (identity) => {
|
|
61459
61459
|
if (!isIdentityName(identity)) {
|
|
61460
61460
|
throw new Error(`"${identity}" is not a valid identity name.`);
|
|
61461
61461
|
}
|
|
61462
|
-
const stat =
|
|
61462
|
+
const stat = fs18.lstat(claudeJsonPath(identitiesDir, identity));
|
|
61463
61463
|
const stamp = stat === void 0 ? "absent" : `${String(stat.mtimeMs)}:${String(stat.sizeBytes)}`;
|
|
61464
61464
|
const cached2 = cache.get(identity);
|
|
61465
61465
|
if (cached2?.stamp === stamp) {
|
|
61466
61466
|
return cached2.account;
|
|
61467
61467
|
}
|
|
61468
|
-
const account = readAccountMetadata(
|
|
61468
|
+
const account = readAccountMetadata(fs18, identitiesDir, identity);
|
|
61469
61469
|
cache.set(identity, { stamp, account });
|
|
61470
61470
|
return account;
|
|
61471
61471
|
};
|
|
@@ -61555,11 +61555,11 @@ function providerBaseUrl(port, provider) {
|
|
|
61555
61555
|
function directOrigin(port) {
|
|
61556
61556
|
return `http://127.0.0.1:${String(port)}`;
|
|
61557
61557
|
}
|
|
61558
|
-
function parseProviderPath(
|
|
61559
|
-
if (!
|
|
61558
|
+
function parseProviderPath(path38) {
|
|
61559
|
+
if (!path38.startsWith(PROVIDER_PATH_PREFIX)) {
|
|
61560
61560
|
return void 0;
|
|
61561
61561
|
}
|
|
61562
|
-
const tail =
|
|
61562
|
+
const tail = path38.slice(PROVIDER_PATH_PREFIX.length);
|
|
61563
61563
|
const slash = tail.indexOf("/");
|
|
61564
61564
|
if (slash <= 0) {
|
|
61565
61565
|
return void 0;
|
|
@@ -61959,9 +61959,9 @@ function decoderFor(encoding) {
|
|
|
61959
61959
|
return void 0;
|
|
61960
61960
|
}
|
|
61961
61961
|
}
|
|
61962
|
-
function destinationOf(
|
|
61963
|
-
const scoped = parseProviderPath(
|
|
61964
|
-
return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint:
|
|
61962
|
+
function destinationOf(path38) {
|
|
61963
|
+
const scoped = parseProviderPath(path38);
|
|
61964
|
+
return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path38 } : { provider: scoped.provider, endpoint: scoped.rest };
|
|
61965
61965
|
}
|
|
61966
61966
|
function buildRecord(event, context) {
|
|
61967
61967
|
const { scan } = context;
|
|
@@ -62233,8 +62233,8 @@ function segmentDay(epochMs) {
|
|
|
62233
62233
|
function segmentName(day, pid) {
|
|
62234
62234
|
return `${day}.${String(pid)}.jsonl`;
|
|
62235
62235
|
}
|
|
62236
|
-
function listLogSegments(
|
|
62237
|
-
return
|
|
62236
|
+
function listLogSegments(fs18, logDir) {
|
|
62237
|
+
return fs18.readdir(logDir).flatMap((name) => {
|
|
62238
62238
|
const match = SEGMENT_RE.exec(name);
|
|
62239
62239
|
const day = match?.[1];
|
|
62240
62240
|
if (day === void 0) {
|
|
@@ -62243,15 +62243,15 @@ function listLogSegments(fs17, logDir) {
|
|
|
62243
62243
|
return [{ name, day, endsAt: Date.parse(`${day}T00:00:00.000Z`) + DAY_MS }];
|
|
62244
62244
|
}).sort((left, right) => left.day.localeCompare(right.day) || left.name.localeCompare(right.name));
|
|
62245
62245
|
}
|
|
62246
|
-
function readUsageLog(
|
|
62246
|
+
function readUsageLog(fs18, logDir, options = {}) {
|
|
62247
62247
|
const { sinceMs } = options;
|
|
62248
62248
|
const records = [];
|
|
62249
62249
|
let invalidLines = 0;
|
|
62250
|
-
for (const segment of listLogSegments(
|
|
62250
|
+
for (const segment of listLogSegments(fs18, logDir)) {
|
|
62251
62251
|
if (sinceMs !== void 0 && segment.endsAt <= sinceMs) {
|
|
62252
62252
|
continue;
|
|
62253
62253
|
}
|
|
62254
|
-
const contents =
|
|
62254
|
+
const contents = fs18.readFileUtf8(import_node_path21.default.join(logDir, segment.name));
|
|
62255
62255
|
if (contents === void 0) {
|
|
62256
62256
|
continue;
|
|
62257
62257
|
}
|
|
@@ -62295,9 +62295,9 @@ function snapshotPath(snapshotsDir, identity) {
|
|
|
62295
62295
|
}
|
|
62296
62296
|
return import_node_path21.default.join(snapshotsDir, `${identity}.json`);
|
|
62297
62297
|
}
|
|
62298
|
-
function readUsageSnapshot(
|
|
62298
|
+
function readUsageSnapshot(fs18, snapshotsDir, identity) {
|
|
62299
62299
|
const file2 = snapshotPath(snapshotsDir, identity);
|
|
62300
|
-
const raw =
|
|
62300
|
+
const raw = fs18.readFileUtf8(file2);
|
|
62301
62301
|
if (raw === void 0) {
|
|
62302
62302
|
return void 0;
|
|
62303
62303
|
}
|
|
@@ -62313,8 +62313,8 @@ function readUsageSnapshot(fs17, snapshotsDir, identity) {
|
|
|
62313
62313
|
}
|
|
62314
62314
|
return snapshot.data;
|
|
62315
62315
|
}
|
|
62316
|
-
function listUsageSnapshots(
|
|
62317
|
-
return
|
|
62316
|
+
function listUsageSnapshots(fs18, snapshotsDir) {
|
|
62317
|
+
return fs18.readdir(snapshotsDir).flatMap((name) => {
|
|
62318
62318
|
if (!name.endsWith(".json")) {
|
|
62319
62319
|
return [];
|
|
62320
62320
|
}
|
|
@@ -62322,7 +62322,7 @@ function listUsageSnapshots(fs17, snapshotsDir) {
|
|
|
62322
62322
|
if (!isIdentityName(identity)) {
|
|
62323
62323
|
return [];
|
|
62324
62324
|
}
|
|
62325
|
-
const snapshot = readUsageSnapshot(
|
|
62325
|
+
const snapshot = readUsageSnapshot(fs18, snapshotsDir, identity);
|
|
62326
62326
|
return snapshot === void 0 ? [] : [snapshot];
|
|
62327
62327
|
}).sort((left, right) => left.identity.localeCompare(right.identity));
|
|
62328
62328
|
}
|
|
@@ -62381,11 +62381,11 @@ var import_node_path22 = __toESM(require("node:path"), 1);
|
|
|
62381
62381
|
var DAY_MS2 = 864e5;
|
|
62382
62382
|
var DAYS_IN_WEEK = 7;
|
|
62383
62383
|
var USAGE_RETENTION_MS = DAYS_IN_WEEK * DAY_MS2;
|
|
62384
|
-
function pruneUsageLog(
|
|
62384
|
+
function pruneUsageLog(fs18, logDir, nowMs) {
|
|
62385
62385
|
const cutoff = nowMs - USAGE_RETENTION_MS;
|
|
62386
|
-
for (const segment of listLogSegments(
|
|
62386
|
+
for (const segment of listLogSegments(fs18, logDir)) {
|
|
62387
62387
|
if (segment.endsAt <= cutoff) {
|
|
62388
|
-
|
|
62388
|
+
fs18.removeRecursive(import_node_path22.default.join(logDir, segment.name));
|
|
62389
62389
|
}
|
|
62390
62390
|
}
|
|
62391
62391
|
}
|
|
@@ -62414,7 +62414,7 @@ function foldProviderState(current, record2) {
|
|
|
62414
62414
|
};
|
|
62415
62415
|
}
|
|
62416
62416
|
function createUsageStore(deps) {
|
|
62417
|
-
const { fs:
|
|
62417
|
+
const { fs: fs18, paths } = deps;
|
|
62418
62418
|
let prunedDay;
|
|
62419
62419
|
const rewriteSnapshot = (identity, fold) => {
|
|
62420
62420
|
if (!isIdentityName(identity)) {
|
|
@@ -62423,7 +62423,7 @@ function createUsageStore(deps) {
|
|
|
62423
62423
|
}
|
|
62424
62424
|
let current;
|
|
62425
62425
|
try {
|
|
62426
|
-
current = readUsageSnapshot(
|
|
62426
|
+
current = readUsageSnapshot(fs18, paths.usageSnapshotsDir, identity);
|
|
62427
62427
|
} catch (error62) {
|
|
62428
62428
|
if (!(error62 instanceof UsageSnapshotError)) {
|
|
62429
62429
|
throw error62;
|
|
@@ -62450,8 +62450,8 @@ function createUsageStore(deps) {
|
|
|
62450
62450
|
...account === void 0 ? {} : { account },
|
|
62451
62451
|
providers
|
|
62452
62452
|
});
|
|
62453
|
-
|
|
62454
|
-
|
|
62453
|
+
fs18.mkdirPrivate(paths.usageSnapshotsDir);
|
|
62454
|
+
fs18.writeFilePrivate(snapshotPath(paths.usageSnapshotsDir, identity), `${JSON.stringify(snapshot, null, 2)}
|
|
62455
62455
|
`);
|
|
62456
62456
|
return true;
|
|
62457
62457
|
};
|
|
@@ -62459,14 +62459,14 @@ function createUsageStore(deps) {
|
|
|
62459
62459
|
record: (input2) => {
|
|
62460
62460
|
const record2 = UsageRecordSchema.parse(input2);
|
|
62461
62461
|
const nowMs = deps.now();
|
|
62462
|
-
|
|
62463
|
-
|
|
62462
|
+
fs18.mkdirPrivate(paths.usageDir);
|
|
62463
|
+
fs18.mkdirPrivate(paths.usageLogDir);
|
|
62464
62464
|
const day = segmentDay(nowMs);
|
|
62465
62465
|
if (prunedDay !== day) {
|
|
62466
|
-
pruneUsageLog(
|
|
62466
|
+
pruneUsageLog(fs18, paths.usageLogDir, nowMs);
|
|
62467
62467
|
prunedDay = day;
|
|
62468
62468
|
}
|
|
62469
|
-
|
|
62469
|
+
fs18.appendFilePrivate(import_node_path22.default.join(paths.usageLogDir, segmentName(day, deps.pid)), `${JSON.stringify(record2)}
|
|
62470
62470
|
`);
|
|
62471
62471
|
if (record2.identity !== void 0) {
|
|
62472
62472
|
rewriteSnapshot(record2.identity, (current) => ({ ...current?.providers, [record2.provider]: foldProviderState(current?.providers[record2.provider], record2) }));
|
|
@@ -62493,14 +62493,14 @@ var PicksFileSchema = external_exports.strictObject({
|
|
|
62493
62493
|
function errorMessage(error62) {
|
|
62494
62494
|
return error62 instanceof Error ? error62.message : String(error62);
|
|
62495
62495
|
}
|
|
62496
|
-
function loadPoolMembers(
|
|
62496
|
+
function loadPoolMembers(fs18, paths, identities, nowMs) {
|
|
62497
62497
|
const windowStartMs = nowMs - FIVE_HOUR_WINDOW_MS;
|
|
62498
|
-
const log = readUsageLog(
|
|
62498
|
+
const log = readUsageLog(fs18, paths.usageLogDir, { sinceMs: windowStartMs });
|
|
62499
62499
|
return identities.map((identity) => {
|
|
62500
62500
|
const records = log.records.filter((record2) => record2.identity === identity && record2.provider === ANTHROPIC_PROVIDER && Date.parse(record2.at) >= windowStartMs);
|
|
62501
62501
|
try {
|
|
62502
|
-
const snapshot = readUsageSnapshot(
|
|
62503
|
-
const account = readAccountMetadata(
|
|
62502
|
+
const snapshot = readUsageSnapshot(fs18, paths.usageSnapshotsDir, identity);
|
|
62503
|
+
const account = readAccountMetadata(fs18, paths.identitiesDir, identity) ?? snapshot?.account;
|
|
62504
62504
|
return { identity, records, ...snapshot === void 0 ? {} : { snapshot }, ...account === void 0 ? {} : { account } };
|
|
62505
62505
|
} catch (error62) {
|
|
62506
62506
|
if (error62 instanceof UsageSnapshotError || error62 instanceof AccountMetadataError) {
|
|
@@ -62518,9 +62518,9 @@ function rankPoolFromStore(params) {
|
|
|
62518
62518
|
...params.sticky === void 0 ? {} : { sticky: params.sticky }
|
|
62519
62519
|
});
|
|
62520
62520
|
}
|
|
62521
|
-
function readPicksFile(
|
|
62521
|
+
function readPicksFile(fs18, file2) {
|
|
62522
62522
|
const empty = { schemaVersion: SCHEMA_VERSION, picks: {} };
|
|
62523
|
-
const raw =
|
|
62523
|
+
const raw = fs18.readFileUtf8(file2);
|
|
62524
62524
|
if (raw === void 0) {
|
|
62525
62525
|
return { file: empty };
|
|
62526
62526
|
}
|
|
@@ -62533,17 +62533,17 @@ function readPicksFile(fs17, file2) {
|
|
|
62533
62533
|
const result = PicksFileSchema.safeParse(parsed);
|
|
62534
62534
|
return result.success ? { file: result.data } : { file: empty, problem: `${file2} is not a picks file this agent-shim can read` };
|
|
62535
62535
|
}
|
|
62536
|
-
function readStickyPick(
|
|
62537
|
-
const read = readPicksFile(
|
|
62536
|
+
function readStickyPick(fs18, picksFile, directory) {
|
|
62537
|
+
const read = readPicksFile(fs18, picksFile);
|
|
62538
62538
|
const entry = read.file.picks[directory];
|
|
62539
62539
|
return { ...entry === void 0 ? {} : { sticky: entry }, ...read.problem === void 0 ? {} : { problem: read.problem } };
|
|
62540
62540
|
}
|
|
62541
|
-
function recordStickyPick(
|
|
62542
|
-
const current = readPicksFile(
|
|
62541
|
+
function recordStickyPick(fs18, picksFile, directory, identity, nowMs) {
|
|
62542
|
+
const current = readPicksFile(fs18, picksFile).file.picks;
|
|
62543
62543
|
const kept = Object.entries(current).filter(([, entry]) => nowMs - Date.parse(entry.at) <= USAGE_RETENTION_MS);
|
|
62544
62544
|
const next = { schemaVersion: SCHEMA_VERSION, picks: { ...Object.fromEntries(kept), [directory]: { identity, at: new Date(nowMs).toISOString() } } };
|
|
62545
|
-
|
|
62546
|
-
|
|
62545
|
+
fs18.mkdirPrivate(import_node_path23.default.dirname(picksFile));
|
|
62546
|
+
fs18.writeFilePrivate(picksFile, `${JSON.stringify(next, null, 2)}
|
|
62547
62547
|
`);
|
|
62548
62548
|
}
|
|
62549
62549
|
|
|
@@ -62551,8 +62551,8 @@ function recordStickyPick(fs17, picksFile, directory, identity, nowMs) {
|
|
|
62551
62551
|
var RESUME_FLAGS = /* @__PURE__ */ new Set(["--continue", "-c", "--resume", "-r"]);
|
|
62552
62552
|
var TERMINATOR = "--";
|
|
62553
62553
|
var REASONS_LOGGED = 3;
|
|
62554
|
-
function splitMembers(pool, paths,
|
|
62555
|
-
const exists = (name) => loadIdentity(paths.identitiesDir, name,
|
|
62554
|
+
function splitMembers(pool, paths, fs18) {
|
|
62555
|
+
const exists = (name) => loadIdentity(paths.identitiesDir, name, fs18) !== void 0;
|
|
62556
62556
|
return { present: pool.identities.filter(exists), missing: pool.identities.filter((name) => !exists(name)) };
|
|
62557
62557
|
}
|
|
62558
62558
|
function isResuming(passthrough) {
|
|
@@ -63816,10 +63816,10 @@ var FrontDoorStateSchema = external_exports.strictObject({
|
|
|
63816
63816
|
/** The last fatal error, kept across shutdowns so `frontdoor status` can explain a front door that is not running. */
|
|
63817
63817
|
lastError: external_exports.string().optional()
|
|
63818
63818
|
});
|
|
63819
|
-
function readFrontDoorState(
|
|
63819
|
+
function readFrontDoorState(fs18, stateFile) {
|
|
63820
63820
|
let raw;
|
|
63821
63821
|
try {
|
|
63822
|
-
raw =
|
|
63822
|
+
raw = fs18.readFileUtf8(stateFile);
|
|
63823
63823
|
} catch {
|
|
63824
63824
|
return void 0;
|
|
63825
63825
|
}
|
|
@@ -63833,28 +63833,28 @@ function readFrontDoorState(fs17, stateFile) {
|
|
|
63833
63833
|
return void 0;
|
|
63834
63834
|
}
|
|
63835
63835
|
}
|
|
63836
|
-
function writeFrontDoorState(
|
|
63837
|
-
|
|
63838
|
-
|
|
63836
|
+
function writeFrontDoorState(fs18, stateFile, state) {
|
|
63837
|
+
fs18.mkdirp(import_node_path26.default.dirname(stateFile));
|
|
63838
|
+
fs18.writeFileUtf8(stateFile, `${JSON.stringify(state, null, 2)}
|
|
63839
63839
|
`);
|
|
63840
63840
|
}
|
|
63841
63841
|
function frontDoorOrigin(state) {
|
|
63842
63842
|
const port = state?.directPort ?? state?.lastDirectPort;
|
|
63843
63843
|
return port === void 0 ? void 0 : `http://127.0.0.1:${String(port)}`;
|
|
63844
63844
|
}
|
|
63845
|
-
function writeFrontDoorSession(
|
|
63846
|
-
|
|
63847
|
-
|
|
63845
|
+
function writeFrontDoorSession(fs18, sessionsDir, session) {
|
|
63846
|
+
fs18.mkdirPrivate(sessionsDir);
|
|
63847
|
+
fs18.writeFilePrivate(import_node_path26.default.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
63848
63848
|
`);
|
|
63849
63849
|
}
|
|
63850
|
-
function listFrontDoorSessions(
|
|
63850
|
+
function listFrontDoorSessions(fs18, sessionsDir) {
|
|
63851
63851
|
const sessions = [];
|
|
63852
|
-
for (const name of
|
|
63852
|
+
for (const name of fs18.readdir(sessionsDir)) {
|
|
63853
63853
|
if (!name.endsWith(".json")) {
|
|
63854
63854
|
continue;
|
|
63855
63855
|
}
|
|
63856
63856
|
try {
|
|
63857
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
63857
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs18.readFileUtf8(import_node_path26.default.join(sessionsDir, name)) ?? ""));
|
|
63858
63858
|
if (parsed.success) {
|
|
63859
63859
|
sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt });
|
|
63860
63860
|
}
|
|
@@ -63864,27 +63864,27 @@ function listFrontDoorSessions(fs17, sessionsDir) {
|
|
|
63864
63864
|
}
|
|
63865
63865
|
return sessions.sort((a2, b) => a2.pid - b.pid);
|
|
63866
63866
|
}
|
|
63867
|
-
function removeFrontDoorSession(
|
|
63868
|
-
|
|
63867
|
+
function removeFrontDoorSession(fs18, sessionsDir, pid) {
|
|
63868
|
+
fs18.removeRecursive(import_node_path26.default.join(sessionsDir, `${String(pid)}.json`));
|
|
63869
63869
|
}
|
|
63870
|
-
function pruneDeadFrontDoorSessions(
|
|
63870
|
+
function pruneDeadFrontDoorSessions(fs18, sessionsDir, isRunning) {
|
|
63871
63871
|
const removed = [];
|
|
63872
|
-
for (const session of listFrontDoorSessions(
|
|
63872
|
+
for (const session of listFrontDoorSessions(fs18, sessionsDir)) {
|
|
63873
63873
|
if (!isRunning(session.pid)) {
|
|
63874
|
-
removeFrontDoorSession(
|
|
63874
|
+
removeFrontDoorSession(fs18, sessionsDir, session.pid);
|
|
63875
63875
|
removed.push(session.pid);
|
|
63876
63876
|
}
|
|
63877
63877
|
}
|
|
63878
63878
|
return removed;
|
|
63879
63879
|
}
|
|
63880
|
-
function liveSessionTokens(
|
|
63880
|
+
function liveSessionTokens(fs18, sessionsDir) {
|
|
63881
63881
|
const tokens = /* @__PURE__ */ new Set();
|
|
63882
|
-
for (const name of
|
|
63882
|
+
for (const name of fs18.readdir(sessionsDir)) {
|
|
63883
63883
|
if (!name.endsWith(".json")) {
|
|
63884
63884
|
continue;
|
|
63885
63885
|
}
|
|
63886
63886
|
try {
|
|
63887
|
-
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(
|
|
63887
|
+
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs18.readFileUtf8(import_node_path26.default.join(sessionsDir, name)) ?? ""));
|
|
63888
63888
|
if (parsed.success) {
|
|
63889
63889
|
tokens.add(parsed.data.token);
|
|
63890
63890
|
}
|
|
@@ -64250,6 +64250,7 @@ function registerCodexCommand(program2, deps) {
|
|
|
64250
64250
|
|
|
64251
64251
|
// src/frontdoor/commands.ts
|
|
64252
64252
|
var import_node_crypto13 = require("node:crypto");
|
|
64253
|
+
var import_node_path29 = __toESM(require("node:path"), 1);
|
|
64253
64254
|
var import_node_fs11 = __toESM(require("node:fs"), 1);
|
|
64254
64255
|
|
|
64255
64256
|
// src/frontdoor/custody.ts
|
|
@@ -64387,9 +64388,113 @@ function isLiveCapability(presented, live) {
|
|
|
64387
64388
|
return matched;
|
|
64388
64389
|
}
|
|
64389
64390
|
|
|
64391
|
+
// src/frontdoor/capture.ts
|
|
64392
|
+
var fs11 = __toESM(require("node:fs"), 1);
|
|
64393
|
+
var path28 = __toESM(require("node:path"), 1);
|
|
64394
|
+
var SECRET_HEADER_NAME = /authorization|cookie|token|secret|credential|api[-_]key/i;
|
|
64395
|
+
var SECRET_JSON_KEY = /token|secret|password|credential|authorization|api[-_]key/i;
|
|
64396
|
+
var SECRET_BODY_PATTERNS = [
|
|
64397
|
+
{ pattern: /sk-ant-[A-Za-z0-9_-]{8,}/g, replacement: "<redacted>" },
|
|
64398
|
+
{ pattern: /Bearer\s+[A-Za-z0-9._~+/=-]{8,}/gi, replacement: "Bearer <redacted>" },
|
|
64399
|
+
{ pattern: /eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{8,}/g, replacement: "<redacted>" }
|
|
64400
|
+
];
|
|
64401
|
+
var CHUNK_LOG_CAP_BYTES = 8192;
|
|
64402
|
+
var STREAM_LOG_CAP_BYTES = 262144;
|
|
64403
|
+
var CAPTURE_FILE_MODE = 384;
|
|
64404
|
+
function redactHeaders(headers) {
|
|
64405
|
+
const result = {};
|
|
64406
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
64407
|
+
result[name] = value !== void 0 && SECRET_HEADER_NAME.test(name) ? "<redacted>" : value;
|
|
64408
|
+
}
|
|
64409
|
+
return result;
|
|
64410
|
+
}
|
|
64411
|
+
function redactText(text2) {
|
|
64412
|
+
return SECRET_BODY_PATTERNS.reduce((accumulated, { pattern, replacement }) => accumulated.replace(pattern, replacement), text2);
|
|
64413
|
+
}
|
|
64414
|
+
function redactJsonValue(value) {
|
|
64415
|
+
if (typeof value === "string") {
|
|
64416
|
+
return redactText(value);
|
|
64417
|
+
}
|
|
64418
|
+
if (Array.isArray(value)) {
|
|
64419
|
+
return value.map(redactJsonValue);
|
|
64420
|
+
}
|
|
64421
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
64422
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, SECRET_JSON_KEY.test(key) ? "<redacted>" : redactJsonValue(entry)]));
|
|
64423
|
+
}
|
|
64424
|
+
return value;
|
|
64425
|
+
}
|
|
64426
|
+
function redactBody(chunk) {
|
|
64427
|
+
const text2 = chunk.toString("utf8");
|
|
64428
|
+
try {
|
|
64429
|
+
const parsed = JSON.parse(text2);
|
|
64430
|
+
return JSON.stringify(redactJsonValue(parsed));
|
|
64431
|
+
} catch {
|
|
64432
|
+
return redactText(text2);
|
|
64433
|
+
}
|
|
64434
|
+
}
|
|
64435
|
+
var CAPTURE_ENV = "AGENT_SHIM_FRONTDOOR_CAPTURE";
|
|
64436
|
+
function captureFromEnv(env, logsDir) {
|
|
64437
|
+
return env[CAPTURE_ENV] === "1" ? createFileCapture(path28.join(logsDir, "frontdoor-capture.jsonl")) : void 0;
|
|
64438
|
+
}
|
|
64439
|
+
function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
64440
|
+
fs11.mkdirSync(path28.dirname(file2), { recursive: true });
|
|
64441
|
+
let nextId = 0;
|
|
64442
|
+
const append = (record2) => {
|
|
64443
|
+
fs11.appendFileSync(file2, `${JSON.stringify({ ts: now().toISOString(), ...record2 })}
|
|
64444
|
+
`, { mode: CAPTURE_FILE_MODE });
|
|
64445
|
+
};
|
|
64446
|
+
return {
|
|
64447
|
+
connect: (target, intercepted) => {
|
|
64448
|
+
append({ kind: "connect", host: target.host, port: target.port, intercepted });
|
|
64449
|
+
},
|
|
64450
|
+
upgrade: (request6) => {
|
|
64451
|
+
append({ kind: "upgrade", method: request6.method ?? "?", url: request6.url ?? "?", headers: redactHeaders(request6.headers) });
|
|
64452
|
+
},
|
|
64453
|
+
observePassthrough: (request6) => {
|
|
64454
|
+
nextId += 1;
|
|
64455
|
+
const id = nextId;
|
|
64456
|
+
append({ kind: "request", id, method: request6.method ?? "?", url: request6.url ?? "?", headers: redactHeaders(request6.headers) });
|
|
64457
|
+
const logged = { request: 0, response: 0 };
|
|
64458
|
+
const sequences = { request: 0, response: 0 };
|
|
64459
|
+
const chunk = (direction, incoming) => {
|
|
64460
|
+
sequences[direction] += 1;
|
|
64461
|
+
const budget = STREAM_LOG_CAP_BYTES - logged[direction];
|
|
64462
|
+
if (budget <= 0) {
|
|
64463
|
+
return;
|
|
64464
|
+
}
|
|
64465
|
+
const excerpt = incoming.subarray(0, Math.min(CHUNK_LOG_CAP_BYTES, budget));
|
|
64466
|
+
logged[direction] += excerpt.length;
|
|
64467
|
+
append({
|
|
64468
|
+
kind: `${direction}-chunk`,
|
|
64469
|
+
id,
|
|
64470
|
+
seq: sequences[direction],
|
|
64471
|
+
bytes: incoming.length,
|
|
64472
|
+
stored: excerpt.length,
|
|
64473
|
+
truncated: excerpt.length < incoming.length,
|
|
64474
|
+
body: redactBody(excerpt)
|
|
64475
|
+
});
|
|
64476
|
+
};
|
|
64477
|
+
return {
|
|
64478
|
+
onRequestChunk: (incoming) => {
|
|
64479
|
+
chunk("request", incoming);
|
|
64480
|
+
},
|
|
64481
|
+
onResponse: (status, headers) => {
|
|
64482
|
+
append({ kind: "response", id, status, headers: redactHeaders(headers) });
|
|
64483
|
+
},
|
|
64484
|
+
onResponseChunk: (incoming) => {
|
|
64485
|
+
chunk("response", incoming);
|
|
64486
|
+
},
|
|
64487
|
+
onEnd: () => {
|
|
64488
|
+
append({ kind: "end", id, requestBytesCapped: logged.request >= STREAM_LOG_CAP_BYTES, responseBytesCapped: logged.response >= STREAM_LOG_CAP_BYTES });
|
|
64489
|
+
}
|
|
64490
|
+
};
|
|
64491
|
+
}
|
|
64492
|
+
};
|
|
64493
|
+
}
|
|
64494
|
+
|
|
64390
64495
|
// src/frontdoor/connect.ts
|
|
64391
64496
|
var import_node_crypto10 = require("node:crypto");
|
|
64392
|
-
var
|
|
64497
|
+
var fs12 = __toESM(require("node:fs"), 1);
|
|
64393
64498
|
var http = __toESM(require("node:http"), 1);
|
|
64394
64499
|
var https = __toESM(require("node:https"), 1);
|
|
64395
64500
|
var net3 = __toESM(require("node:net"), 1);
|
|
@@ -64671,8 +64776,8 @@ var FRONTDOOR_SUPERVISOR_STILL_RUNNING = -1;
|
|
|
64671
64776
|
var FRONTDOOR_POLL_MS = 1e3;
|
|
64672
64777
|
var MS_PER_MINUTE = 6e4;
|
|
64673
64778
|
async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {}) {
|
|
64674
|
-
const { fs:
|
|
64675
|
-
const previous = readFrontDoorState(
|
|
64779
|
+
const { fs: fs18, paths } = ports;
|
|
64780
|
+
const previous = readFrontDoorState(fs18, paths.frontdoorStateFile);
|
|
64676
64781
|
let lastPort = previous?.lastPort;
|
|
64677
64782
|
let lastConnectPort = previous?.lastConnectPort;
|
|
64678
64783
|
let lastDirectPort = previous?.lastDirectPort;
|
|
@@ -64682,12 +64787,12 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
64682
64787
|
...lastDirectPort === void 0 ? {} : { lastDirectPort }
|
|
64683
64788
|
});
|
|
64684
64789
|
const fail = (message) => {
|
|
64685
|
-
writeFrontDoorState(
|
|
64686
|
-
|
|
64790
|
+
writeFrontDoorState(fs18, paths.frontdoorStateFile, { lastError: message, ...sticky() });
|
|
64791
|
+
fs18.removeRecursive(paths.frontdoorLockFile);
|
|
64687
64792
|
ports.log(`agent-shim frontdoor supervisor: ${message}`);
|
|
64688
64793
|
return 1;
|
|
64689
64794
|
};
|
|
64690
|
-
writeFrontDoorState(
|
|
64795
|
+
writeFrontDoorState(fs18, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, ...sticky() });
|
|
64691
64796
|
const previousSticky = lastPort;
|
|
64692
64797
|
let http5;
|
|
64693
64798
|
try {
|
|
@@ -64724,8 +64829,8 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
64724
64829
|
ports.log(`agent-shim frontdoor supervisor: sticky direct port ${String(previousStickyDirect)} was occupied; moving to ${String(direct.port)} (headroom must be restarted to admit the new address)`);
|
|
64725
64830
|
}
|
|
64726
64831
|
lastDirectPort = direct.port;
|
|
64727
|
-
writeFrontDoorState(
|
|
64728
|
-
|
|
64832
|
+
writeFrontDoorState(fs18, paths.frontdoorStateFile, { supervisorPid: ports.ownPid, port: http5.port, connectPort: connect2.port, directPort: direct.port, ...sticky() });
|
|
64833
|
+
fs18.removeRecursive(paths.frontdoorLockFile);
|
|
64729
64834
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http5.port)}, CONNECT surface on 127.0.0.1:${String(connect2.port)}`);
|
|
64730
64835
|
let idleSince;
|
|
64731
64836
|
let ticks = 0;
|
|
@@ -64734,15 +64839,15 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
64734
64839
|
return FRONTDOOR_SUPERVISOR_STILL_RUNNING;
|
|
64735
64840
|
}
|
|
64736
64841
|
ticks += 1;
|
|
64737
|
-
pruneDeadFrontDoorSessions(
|
|
64738
|
-
if (listFrontDoorSessions(
|
|
64842
|
+
pruneDeadFrontDoorSessions(fs18, paths.frontdoorSessionsDir, ports.isRunning);
|
|
64843
|
+
if (listFrontDoorSessions(fs18, paths.frontdoorSessionsDir).length === 0) {
|
|
64739
64844
|
idleSince ??= ports.now();
|
|
64740
64845
|
if (ports.now() - idleSince >= idleShutdownMinutes * MS_PER_MINUTE) {
|
|
64741
64846
|
ports.log(`agent-shim frontdoor supervisor: no sessions for ${String(idleShutdownMinutes)} minute(s); closing the front door and exiting`);
|
|
64742
64847
|
await direct.close();
|
|
64743
64848
|
await connect2.close();
|
|
64744
64849
|
await http5.close();
|
|
64745
|
-
writeFrontDoorState(
|
|
64850
|
+
writeFrontDoorState(fs18, paths.frontdoorStateFile, sticky());
|
|
64746
64851
|
return 0;
|
|
64747
64852
|
}
|
|
64748
64853
|
} else {
|
|
@@ -64796,8 +64901,8 @@ function parseConnectTarget(authority) {
|
|
|
64796
64901
|
function isInterceptedHost(host, interceptHost) {
|
|
64797
64902
|
return host === interceptHost;
|
|
64798
64903
|
}
|
|
64799
|
-
function servedByPipeline(
|
|
64800
|
-
return
|
|
64904
|
+
function servedByPipeline(path38) {
|
|
64905
|
+
return path38?.startsWith(ROUTED_PATH_PREFIX) === true;
|
|
64801
64906
|
}
|
|
64802
64907
|
var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
|
|
64803
64908
|
"connection",
|
|
@@ -64870,9 +64975,9 @@ async function startConnectServer(config2, effects, preferredPort) {
|
|
|
64870
64975
|
config2.serveRouted(request6, response);
|
|
64871
64976
|
return;
|
|
64872
64977
|
}
|
|
64873
|
-
effects.forwardHttp(config2.upstream, request6, response);
|
|
64978
|
+
effects.forwardHttp(config2.upstream, request6, response, config2.capture?.observePassthrough(request6));
|
|
64874
64979
|
};
|
|
64875
|
-
const httpSession = effects.createHttpSession(handler);
|
|
64980
|
+
const httpSession = effects.createHttpSession(handler, config2.capture === void 0 ? void 0 : (request6) => config2.capture?.upgrade(request6));
|
|
64876
64981
|
const tlsAcceptor = effects.createTlsAcceptor(config2.leafFor(config2.interceptHost), (secure) => {
|
|
64877
64982
|
httpSession.serve(secure);
|
|
64878
64983
|
});
|
|
@@ -65025,6 +65130,7 @@ function routeConnect(socket, head, context) {
|
|
|
65025
65130
|
refuse(socket, REFUSAL.serviceUnavailable);
|
|
65026
65131
|
return;
|
|
65027
65132
|
}
|
|
65133
|
+
config2.capture?.connect(target, isInterceptedHost(target.host, config2.interceptHost));
|
|
65028
65134
|
socket.write(CONNECT_ESTABLISHED);
|
|
65029
65135
|
if (isInterceptedHost(target.host, config2.interceptHost)) {
|
|
65030
65136
|
tlsAcceptor.accept(socket);
|
|
@@ -65121,11 +65227,17 @@ function realConnectEffects() {
|
|
|
65121
65227
|
}
|
|
65122
65228
|
};
|
|
65123
65229
|
},
|
|
65124
|
-
createHttpSession: (handler) => {
|
|
65230
|
+
createHttpSession: (handler, onUpgrade) => {
|
|
65125
65231
|
const server = http.createServer(handler);
|
|
65126
65232
|
server.on("clientError", (_error, socket) => {
|
|
65127
65233
|
socket.destroy();
|
|
65128
65234
|
});
|
|
65235
|
+
if (onUpgrade !== void 0) {
|
|
65236
|
+
server.on("upgrade", (request6, socket) => {
|
|
65237
|
+
onUpgrade(request6);
|
|
65238
|
+
socket.destroy();
|
|
65239
|
+
});
|
|
65240
|
+
}
|
|
65129
65241
|
return {
|
|
65130
65242
|
serve: (socket) => {
|
|
65131
65243
|
server.emit("connection", socket);
|
|
@@ -65143,7 +65255,7 @@ function realConnectEffects() {
|
|
|
65143
65255
|
});
|
|
65144
65256
|
socket.once("error", reject);
|
|
65145
65257
|
}),
|
|
65146
|
-
forwardHttp: (target, request6, response) => {
|
|
65258
|
+
forwardHttp: (target, request6, response, observer) => {
|
|
65147
65259
|
const headers = forwardableHeaders(request6.headers);
|
|
65148
65260
|
const options = {
|
|
65149
65261
|
host: target.host,
|
|
@@ -65163,8 +65275,14 @@ function realConnectEffects() {
|
|
|
65163
65275
|
}
|
|
65164
65276
|
}
|
|
65165
65277
|
const onUpstreamResponse = (upstreamResponse) => {
|
|
65278
|
+
observer?.onResponse(upstreamResponse.statusCode ?? HTTP_BAD_GATEWAY, upstreamResponse.headers);
|
|
65166
65279
|
response.writeHead(upstreamResponse.statusCode ?? HTTP_BAD_GATEWAY, forwardableHeaders(upstreamResponse.headers));
|
|
65167
65280
|
response.flushHeaders();
|
|
65281
|
+
if (observer !== void 0) {
|
|
65282
|
+
upstreamResponse.on("data", (chunk) => {
|
|
65283
|
+
observer.onResponseChunk(chunk);
|
|
65284
|
+
});
|
|
65285
|
+
}
|
|
65168
65286
|
upstreamResponse.pipe(response);
|
|
65169
65287
|
};
|
|
65170
65288
|
const upstream = target.tls ? https.request(options, onUpstreamResponse) : http.request(options, onUpstreamResponse);
|
|
@@ -65177,6 +65295,14 @@ function realConnectEffects() {
|
|
|
65177
65295
|
response.writeHead(HTTP_BAD_GATEWAY, { "content-type": "text/plain", "content-length": String(body.length) });
|
|
65178
65296
|
response.end(body);
|
|
65179
65297
|
});
|
|
65298
|
+
if (observer !== void 0) {
|
|
65299
|
+
request6.on("data", (chunk) => {
|
|
65300
|
+
observer.onRequestChunk(chunk);
|
|
65301
|
+
});
|
|
65302
|
+
response.on("close", () => {
|
|
65303
|
+
observer.onEnd();
|
|
65304
|
+
});
|
|
65305
|
+
}
|
|
65180
65306
|
request6.pipe(upstream);
|
|
65181
65307
|
request6.socket.setNoDelay(true);
|
|
65182
65308
|
upstream.on("socket", (socket) => {
|
|
@@ -65191,7 +65317,7 @@ function isEnoent5(error62) {
|
|
|
65191
65317
|
function realConnectCertStore(paths) {
|
|
65192
65318
|
const read = (file2) => {
|
|
65193
65319
|
try {
|
|
65194
|
-
return
|
|
65320
|
+
return fs12.readFileSync(file2, "utf8");
|
|
65195
65321
|
} catch (error62) {
|
|
65196
65322
|
if (isEnoent5(error62)) {
|
|
65197
65323
|
return void 0;
|
|
@@ -65206,10 +65332,10 @@ function realConnectCertStore(paths) {
|
|
|
65206
65332
|
return certPem === void 0 || keyPem2 === void 0 ? void 0 : { certPem, keyPem: keyPem2 };
|
|
65207
65333
|
},
|
|
65208
65334
|
writeCa: (ca) => {
|
|
65209
|
-
|
|
65210
|
-
|
|
65211
|
-
|
|
65212
|
-
|
|
65335
|
+
fs12.mkdirSync(paths.frontdoorCaDir, { recursive: true });
|
|
65336
|
+
fs12.writeFileSync(paths.frontdoorCaCertFile, ca.certPem, "utf8");
|
|
65337
|
+
fs12.writeFileSync(paths.frontdoorCaKeyFile, ca.keyPem, { encoding: "utf8", mode: CA_KEY_FILE_MODE });
|
|
65338
|
+
fs12.chmodSync(paths.frontdoorCaKeyFile, CA_KEY_FILE_MODE);
|
|
65213
65339
|
}
|
|
65214
65340
|
};
|
|
65215
65341
|
}
|
|
@@ -66296,8 +66422,8 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
|
|
|
66296
66422
|
request6.body.resume();
|
|
66297
66423
|
return;
|
|
66298
66424
|
}
|
|
66299
|
-
const
|
|
66300
|
-
const translated = { method: request6.method, path:
|
|
66425
|
+
const path38 = new URL(request6.url, "http://127.0.0.1").pathname;
|
|
66426
|
+
const translated = { method: request6.method, path: path38, body, signal: request6.signal };
|
|
66301
66427
|
const routed = await route(translated);
|
|
66302
66428
|
if (request6.signal.aborted) {
|
|
66303
66429
|
return;
|
|
@@ -66331,7 +66457,7 @@ function createPassthroughRoute(name, target) {
|
|
|
66331
66457
|
headroomUpstream: target.headroomUpstream,
|
|
66332
66458
|
serve: async (request6, response) => {
|
|
66333
66459
|
const incoming = new URL(request6.url, "http://127.0.0.1");
|
|
66334
|
-
const
|
|
66460
|
+
const path38 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
|
|
66335
66461
|
const headers = forwardableHeaders(request6.headers);
|
|
66336
66462
|
delete headers.host;
|
|
66337
66463
|
await new Promise((resolve) => {
|
|
@@ -66339,7 +66465,7 @@ function createPassthroughRoute(name, target) {
|
|
|
66339
66465
|
host: base.hostname,
|
|
66340
66466
|
port: base.port === "" ? void 0 : Number(base.port),
|
|
66341
66467
|
method: request6.method,
|
|
66342
|
-
path: `${basePath}${
|
|
66468
|
+
path: `${basePath}${path38}${incoming.search}`,
|
|
66343
66469
|
headers,
|
|
66344
66470
|
agent
|
|
66345
66471
|
};
|
|
@@ -66401,10 +66527,10 @@ function createProviderRouteResolver(deps) {
|
|
|
66401
66527
|
return route;
|
|
66402
66528
|
};
|
|
66403
66529
|
const resolve = (request6) => {
|
|
66404
|
-
const
|
|
66405
|
-
const scoped = parseProviderPath(
|
|
66530
|
+
const path38 = new URL(request6.url, "http://127.0.0.1").pathname;
|
|
66531
|
+
const scoped = parseProviderPath(path38);
|
|
66406
66532
|
if (scoped === void 0) {
|
|
66407
|
-
return
|
|
66533
|
+
return path38.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path38}` };
|
|
66408
66534
|
}
|
|
66409
66535
|
const { provider } = scoped;
|
|
66410
66536
|
let definition;
|
|
@@ -66448,14 +66574,14 @@ var import_node_crypto12 = require("node:crypto");
|
|
|
66448
66574
|
var import_node_path28 = __toESM(require("node:path"), 1);
|
|
66449
66575
|
var BUNDLE_NAME_HEX_DIGITS = 16;
|
|
66450
66576
|
function resolveTrustBundle(params) {
|
|
66451
|
-
const { caCertFile, bundlesDir, inherited, fs:
|
|
66577
|
+
const { caCertFile, bundlesDir, inherited, fs: fs18 } = params;
|
|
66452
66578
|
if (inherited === void 0 || inherited === "" || import_node_path28.default.resolve(inherited) === import_node_path28.default.resolve(caCertFile)) {
|
|
66453
66579
|
return { path: caCertFile };
|
|
66454
66580
|
}
|
|
66455
|
-
const caPem =
|
|
66581
|
+
const caPem = fs18.readFileUtf8(caCertFile);
|
|
66456
66582
|
let inheritedPem;
|
|
66457
66583
|
try {
|
|
66458
|
-
inheritedPem =
|
|
66584
|
+
inheritedPem = fs18.readFileUtf8(inherited);
|
|
66459
66585
|
} catch (error62) {
|
|
66460
66586
|
return {
|
|
66461
66587
|
path: caCertFile,
|
|
@@ -66468,9 +66594,9 @@ function resolveTrustBundle(params) {
|
|
|
66468
66594
|
const combined = `${inheritedPem.trimEnd()}
|
|
66469
66595
|
${caPem}`;
|
|
66470
66596
|
const bundle = import_node_path28.default.join(bundlesDir, `${(0, import_node_crypto12.createHash)("sha256").update(combined).digest("hex").slice(0, BUNDLE_NAME_HEX_DIGITS)}.pem`);
|
|
66471
|
-
if (!
|
|
66472
|
-
|
|
66473
|
-
|
|
66597
|
+
if (!fs18.exists(bundle)) {
|
|
66598
|
+
fs18.mkdirp(bundlesDir);
|
|
66599
|
+
fs18.writeFileAtomic(bundle, combined);
|
|
66474
66600
|
}
|
|
66475
66601
|
return { path: bundle };
|
|
66476
66602
|
}
|
|
@@ -66835,6 +66961,10 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
66835
66961
|
},
|
|
66836
66962
|
startConnectListener: async (preferredPort) => {
|
|
66837
66963
|
const leafFor = createLeafCache(loadCa(), () => /* @__PURE__ */ new Date());
|
|
66964
|
+
const capture = captureFromEnv(process.env, paths.logsDir);
|
|
66965
|
+
if (capture !== void 0) {
|
|
66966
|
+
log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path29.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
|
|
66967
|
+
}
|
|
66838
66968
|
const server = await startConnectServer(
|
|
66839
66969
|
{
|
|
66840
66970
|
interceptHost: CONNECT_INTERCEPT_HOST,
|
|
@@ -66860,7 +66990,8 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
66860
66990
|
leafFor,
|
|
66861
66991
|
upstream: { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT, tls: true },
|
|
66862
66992
|
isLiveCapability: isLiveToken,
|
|
66863
|
-
limits: CONNECT_LIMITS
|
|
66993
|
+
limits: CONNECT_LIMITS,
|
|
66994
|
+
...capture === void 0 ? {} : { capture }
|
|
66864
66995
|
},
|
|
66865
66996
|
realConnectEffects(),
|
|
66866
66997
|
preferredPort
|
|
@@ -67277,15 +67408,15 @@ var import_node_child_process4 = require("node:child_process");
|
|
|
67277
67408
|
|
|
67278
67409
|
// src/identityToken.ts
|
|
67279
67410
|
var import_node_fs12 = __toESM(require("node:fs"), 1);
|
|
67280
|
-
var
|
|
67411
|
+
var import_node_path30 = __toESM(require("node:path"), 1);
|
|
67281
67412
|
var TOKEN_FILE_MODE = 384;
|
|
67282
67413
|
var TOKEN_DIR_MODE = 448;
|
|
67283
67414
|
var OAUTH_TOKEN_RE = /^sk-ant-oat\d+-[A-Za-z0-9_-]+$/;
|
|
67284
67415
|
function identityTokenDir(paths) {
|
|
67285
|
-
return
|
|
67416
|
+
return import_node_path30.default.join(paths.root, "credentials");
|
|
67286
67417
|
}
|
|
67287
67418
|
function identityTokenPath(paths, identityName) {
|
|
67288
|
-
return
|
|
67419
|
+
return import_node_path30.default.join(identityTokenDir(paths), `${identityName}.token`);
|
|
67289
67420
|
}
|
|
67290
67421
|
function storeIdentityToken(paths, identityName, raw) {
|
|
67291
67422
|
const token = raw.trim();
|
|
@@ -67296,7 +67427,7 @@ function storeIdentityToken(paths, identityName, raw) {
|
|
|
67296
67427
|
import_node_fs12.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
|
|
67297
67428
|
import_node_fs12.default.chmodSync(dir, TOKEN_DIR_MODE);
|
|
67298
67429
|
const target = identityTokenPath(paths, identityName);
|
|
67299
|
-
const temp =
|
|
67430
|
+
const temp = import_node_path30.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
|
|
67300
67431
|
import_node_fs12.default.writeFileSync(temp, `${token}
|
|
67301
67432
|
`, { mode: TOKEN_FILE_MODE });
|
|
67302
67433
|
import_node_fs12.default.renameSync(temp, target);
|
|
@@ -67306,7 +67437,7 @@ function storeIdentityToken(paths, identityName, raw) {
|
|
|
67306
67437
|
// src/realCredentialCache.ts
|
|
67307
67438
|
var import_node_child_process3 = require("node:child_process");
|
|
67308
67439
|
var import_node_fs13 = __toESM(require("node:fs"), 1);
|
|
67309
|
-
var
|
|
67440
|
+
var import_node_path31 = __toESM(require("node:path"), 1);
|
|
67310
67441
|
var KEYCHAIN_CACHE_SERVICE = "agent-shim-credential-cache";
|
|
67311
67442
|
var CACHE_DIR_MODE = 448;
|
|
67312
67443
|
var CACHE_FILE_MODE = 384;
|
|
@@ -67333,8 +67464,8 @@ function security(args, stdin2) {
|
|
|
67333
67464
|
return { status: result.status, stdout: result.stdout };
|
|
67334
67465
|
}
|
|
67335
67466
|
function createRealCredentialCache(root) {
|
|
67336
|
-
const dir =
|
|
67337
|
-
const filePath = (owner) =>
|
|
67467
|
+
const dir = import_node_path31.default.join(root, "credential-cache");
|
|
67468
|
+
const filePath = (owner) => import_node_path31.default.join(dir, cacheFileNameFor(owner));
|
|
67338
67469
|
return {
|
|
67339
67470
|
read(store, owner) {
|
|
67340
67471
|
if (store === "file") {
|
|
@@ -67513,7 +67644,7 @@ function subjectName(positional, provider) {
|
|
|
67513
67644
|
|
|
67514
67645
|
// src/doctor.ts
|
|
67515
67646
|
var import_node_fs14 = __toESM(require("node:fs"), 1);
|
|
67516
|
-
var
|
|
67647
|
+
var import_node_path32 = __toESM(require("node:path"), 1);
|
|
67517
67648
|
|
|
67518
67649
|
// src/headroom/source.ts
|
|
67519
67650
|
var GIT_SPEC_RE = /git\+[^@\s]+(?:@([^\s#]+))?/;
|
|
@@ -67564,7 +67695,7 @@ function validateJson(schema, input2) {
|
|
|
67564
67695
|
return { ok: true, data: result.data };
|
|
67565
67696
|
}
|
|
67566
67697
|
function pushPathResolution(push, resolution) {
|
|
67567
|
-
const ownDir =
|
|
67698
|
+
const ownDir = import_node_path32.default.dirname(resolution.ownExecutablePath);
|
|
67568
67699
|
switch (resolution.agentShim.status) {
|
|
67569
67700
|
case "ok":
|
|
67570
67701
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -67632,14 +67763,14 @@ function pushProvider(push, entry) {
|
|
|
67632
67763
|
}
|
|
67633
67764
|
function pushLegacyName(push, params) {
|
|
67634
67765
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
67635
|
-
if (legacyVariables.length === 0 &&
|
|
67766
|
+
if (legacyVariables.length === 0 && import_node_path32.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
67636
67767
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
67637
67768
|
return;
|
|
67638
67769
|
}
|
|
67639
67770
|
for (const name of legacyVariables) {
|
|
67640
67771
|
push("legacy-name", "warn", `${name} is the former name of ${name.replace(LEGACY_ENV_PREFIX, ENV_PREFIX)}. Rename it; the old name still works but is only a fallback.`, name);
|
|
67641
67772
|
}
|
|
67642
|
-
if (
|
|
67773
|
+
if (import_node_path32.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
67643
67774
|
push(
|
|
67644
67775
|
"legacy-name",
|
|
67645
67776
|
"warn",
|
|
@@ -67950,18 +68081,18 @@ function registerDoctorCommand(program2, deps) {
|
|
|
67950
68081
|
).option("--json", "Print the report as JSON.").action((options) => {
|
|
67951
68082
|
const identityNames = import_node_fs14.default.existsSync(paths.identitiesDir) ? import_node_fs14.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
|
|
67952
68083
|
const identities = identityNames.map((name) => {
|
|
67953
|
-
const farmRoot =
|
|
67954
|
-
const identityPath =
|
|
68084
|
+
const farmRoot = import_node_path32.default.join(paths.identitiesDir, name);
|
|
68085
|
+
const identityPath = import_node_path32.default.join(farmRoot, "identity.json");
|
|
67955
68086
|
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot };
|
|
67956
68087
|
});
|
|
67957
68088
|
const profileNames = import_node_fs14.default.existsSync(paths.configProfilesDir) ? import_node_fs14.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
67958
68089
|
const configProfiles = profileNames.map((name) => {
|
|
67959
|
-
const profilePath =
|
|
68090
|
+
const profilePath = import_node_path32.default.join(paths.configProfilesDir, `${name}.json`);
|
|
67960
68091
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
67961
68092
|
});
|
|
67962
68093
|
const providerNames = import_node_fs14.default.existsSync(paths.providersDir) ? import_node_fs14.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
67963
68094
|
const providers = providerNames.map((name) => {
|
|
67964
|
-
const providerPath =
|
|
68095
|
+
const providerPath = import_node_path32.default.join(paths.providersDir, `${name}.json`);
|
|
67965
68096
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
67966
68097
|
});
|
|
67967
68098
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -67973,12 +68104,12 @@ function registerDoctorCommand(program2, deps) {
|
|
|
67973
68104
|
binaryDiscovery = { ok: false, message: error62 instanceof Error ? error62.message : String(error62) };
|
|
67974
68105
|
}
|
|
67975
68106
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
67976
|
-
const pathDirs = (process.env.PATH ?? "").split(
|
|
68107
|
+
const pathDirs = (process.env.PATH ?? "").split(import_node_path32.default.delimiter).filter((dir) => dir !== "");
|
|
67977
68108
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
67978
68109
|
findPathShadow({
|
|
67979
68110
|
pathDirs,
|
|
67980
|
-
targetDir:
|
|
67981
|
-
targetFilename:
|
|
68111
|
+
targetDir: import_node_path32.default.dirname(shimState.targetPath),
|
|
68112
|
+
targetFilename: import_node_path32.default.basename(shimState.targetPath),
|
|
67982
68113
|
findExecutableInDir
|
|
67983
68114
|
}),
|
|
67984
68115
|
shimState.targetPath,
|
|
@@ -68001,7 +68132,7 @@ function registerDoctorCommand(program2, deps) {
|
|
|
68001
68132
|
agentShim: refinePathShadow(
|
|
68002
68133
|
findPathShadow({
|
|
68003
68134
|
pathDirs,
|
|
68004
|
-
targetDir:
|
|
68135
|
+
targetDir: import_node_path32.default.dirname(ownExecutablePath),
|
|
68005
68136
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
68006
68137
|
findExecutableInDir
|
|
68007
68138
|
}),
|
|
@@ -68034,7 +68165,7 @@ function registerDoctorCommand(program2, deps) {
|
|
|
68034
68165
|
// src/headroom/commands.ts
|
|
68035
68166
|
var import_node_fs15 = __toESM(require("node:fs"), 1);
|
|
68036
68167
|
var import_node_net3 = __toESM(require("node:net"), 1);
|
|
68037
|
-
var
|
|
68168
|
+
var import_node_path33 = __toESM(require("node:path"), 1);
|
|
68038
68169
|
var import_node_child_process5 = require("node:child_process");
|
|
68039
68170
|
|
|
68040
68171
|
// src/headroom/settings.ts
|
|
@@ -68165,9 +68296,9 @@ function compareVersions2(a2, b) {
|
|
|
68165
68296
|
}
|
|
68166
68297
|
var HEADROOM_SUPERVISOR_STILL_RUNNING = -1;
|
|
68167
68298
|
async function runSupervisor(initialConfig, ports, options = {}) {
|
|
68168
|
-
const { fs:
|
|
68299
|
+
const { fs: fs18, paths } = ports;
|
|
68169
68300
|
let config2 = initialConfig;
|
|
68170
|
-
const previousState = readHeadroomState(
|
|
68301
|
+
const previousState = readHeadroomState(fs18, paths.headroomStateFile);
|
|
68171
68302
|
if (previousState?.supervisorPid !== void 0 && previousState.supervisorPid !== ports.ownPid && ports.isRunning(previousState.supervisorPid)) {
|
|
68172
68303
|
ports.log(`agent-shim headroom supervisor ${String(ports.ownPid)}: supervisor ${String(previousState.supervisorPid)} already owns the daemon; exiting`);
|
|
68173
68304
|
return 0;
|
|
@@ -68176,19 +68307,19 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
68176
68307
|
let lastPort = previousState?.lastPort;
|
|
68177
68308
|
const sticky = () => lastPort === void 0 ? {} : { lastPort };
|
|
68178
68309
|
const ownsState = () => {
|
|
68179
|
-
const owner = readHeadroomState(
|
|
68310
|
+
const owner = readHeadroomState(fs18, paths.headroomStateFile)?.supervisorPid;
|
|
68180
68311
|
return owner === void 0 || owner === ports.ownPid || !ports.isRunning(owner);
|
|
68181
68312
|
};
|
|
68182
68313
|
const writeOwnState = (state) => {
|
|
68183
68314
|
if (!ownsState()) {
|
|
68184
68315
|
return false;
|
|
68185
68316
|
}
|
|
68186
|
-
writeHeadroomState(
|
|
68317
|
+
writeHeadroomState(fs18, paths.headroomStateFile, state);
|
|
68187
68318
|
return true;
|
|
68188
68319
|
};
|
|
68189
68320
|
const fail = (message) => {
|
|
68190
68321
|
if (writeOwnState({ lastError: message, ...sticky() })) {
|
|
68191
|
-
|
|
68322
|
+
fs18.removeRecursive(paths.headroomLockFile);
|
|
68192
68323
|
}
|
|
68193
68324
|
ports.log(`agent-shim headroom supervisor: ${message}`);
|
|
68194
68325
|
return 1;
|
|
@@ -68237,7 +68368,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
68237
68368
|
const settingsHash = hashSettings(config2.settings);
|
|
68238
68369
|
const allowlist = allowlistOf(ports);
|
|
68239
68370
|
const allowlistHash = hashAllowlist(allowlist);
|
|
68240
|
-
pruneDeadSessions(
|
|
68371
|
+
pruneDeadSessions(fs18, paths.headroomSessionsDir, ports.isRunning);
|
|
68241
68372
|
const ownsNow = ownsState();
|
|
68242
68373
|
if (!ownsNow && !superseded) {
|
|
68243
68374
|
ports.log("agent-shim headroom supervisor: another supervisor now owns state.json; serving this daemon's own sessions until they end");
|
|
@@ -68289,7 +68420,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
68289
68420
|
...sticky()
|
|
68290
68421
|
});
|
|
68291
68422
|
if (recorded) {
|
|
68292
|
-
|
|
68423
|
+
fs18.removeRecursive(paths.headroomLockFile);
|
|
68293
68424
|
}
|
|
68294
68425
|
idleSince = void 0;
|
|
68295
68426
|
ports.log(`agent-shim headroom supervisor: headroom pid ${String(pid)} ready on 127.0.0.1:${String(port)}`);
|
|
@@ -68304,7 +68435,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
68304
68435
|
}
|
|
68305
68436
|
} else {
|
|
68306
68437
|
if (runningHash !== allowlistHash || runningSettingsHash !== settingsHash || installedSource !== config2.source) {
|
|
68307
|
-
if (sessionsForSupervisor(
|
|
68438
|
+
if (sessionsForSupervisor(fs18, paths.headroomSessionsDir, ports.ownPid).length === 0) {
|
|
68308
68439
|
ports.log("agent-shim headroom supervisor: configuration drifted and no sessions are live; restarting headroom");
|
|
68309
68440
|
ports.stopProcess(headroomPid);
|
|
68310
68441
|
headroomPid = void 0;
|
|
@@ -68313,7 +68444,7 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
68313
68444
|
continue;
|
|
68314
68445
|
}
|
|
68315
68446
|
}
|
|
68316
|
-
const sessions = sessionsForSupervisor(
|
|
68447
|
+
const sessions = sessionsForSupervisor(fs18, paths.headroomSessionsDir, ports.ownPid);
|
|
68317
68448
|
if (sessions.length === 0) {
|
|
68318
68449
|
idleSince ??= ports.now();
|
|
68319
68450
|
const idleMs = ports.now() - idleSince;
|
|
@@ -68335,9 +68466,9 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
68335
68466
|
await ports.sleep(HEADROOM_POLL_MS);
|
|
68336
68467
|
}
|
|
68337
68468
|
}
|
|
68338
|
-
function currentHeadroomAllowlist(
|
|
68339
|
-
const providers = readAllProviders(
|
|
68340
|
-
return headroomAllowlist(headroomUpstreams(providers, frontDoorOrigin(readFrontDoorState(
|
|
68469
|
+
function currentHeadroomAllowlist(fs18, paths) {
|
|
68470
|
+
const providers = readAllProviders(fs18, paths.providersDir).map((entry) => entry.provider);
|
|
68471
|
+
return headroomAllowlist(headroomUpstreams(providers, frontDoorOrigin(readFrontDoorState(fs18, paths.frontdoorStateFile))));
|
|
68341
68472
|
}
|
|
68342
68473
|
function allowlistOf(ports) {
|
|
68343
68474
|
return currentHeadroomAllowlist(ports.fs, ports.paths);
|
|
@@ -68449,12 +68580,12 @@ function readInstalledHeadroomCommit() {
|
|
|
68449
68580
|
if (toolDir.status !== 0) {
|
|
68450
68581
|
return void 0;
|
|
68451
68582
|
}
|
|
68452
|
-
const libDir =
|
|
68583
|
+
const libDir = import_node_path33.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
|
|
68453
68584
|
for (const python of realFarmFs.readdir(libDir)) {
|
|
68454
|
-
const sitePackages =
|
|
68585
|
+
const sitePackages = import_node_path33.default.join(libDir, python, "site-packages");
|
|
68455
68586
|
for (const entry of realFarmFs.readdir(sitePackages)) {
|
|
68456
68587
|
if (entry.startsWith("headroom_ai-") && entry.endsWith(".dist-info")) {
|
|
68457
|
-
const directUrl = realFarmFs.readFileUtf8(
|
|
68588
|
+
const directUrl = realFarmFs.readFileUtf8(import_node_path33.default.join(sitePackages, entry, "direct_url.json"));
|
|
68458
68589
|
return directUrl === void 0 ? void 0 : parseInstalledCommit(directUrl);
|
|
68459
68590
|
}
|
|
68460
68591
|
}
|
|
@@ -68608,14 +68739,14 @@ function requireIdentity(paths, name) {
|
|
|
68608
68739
|
throw new IdentityNotFoundError(name);
|
|
68609
68740
|
}
|
|
68610
68741
|
}
|
|
68611
|
-
function collectUsageReport(
|
|
68742
|
+
function collectUsageReport(fs18, paths, filters) {
|
|
68612
68743
|
const { identity, provider, sinceMs } = filters;
|
|
68613
68744
|
if (identity !== void 0) {
|
|
68614
68745
|
requireIdentity(paths, identity);
|
|
68615
68746
|
}
|
|
68616
|
-
const log = readUsageLog(
|
|
68747
|
+
const log = readUsageLog(fs18, paths.usageLogDir, sinceMs === void 0 ? {} : { sinceMs });
|
|
68617
68748
|
const records = log.records.filter((record2) => (identity === void 0 || record2.identity === identity) && (provider === void 0 || record2.provider === provider));
|
|
68618
|
-
const snapshots = (identity === void 0 ? listUsageSnapshots(
|
|
68749
|
+
const snapshots = (identity === void 0 ? listUsageSnapshots(fs18, paths.usageSnapshotsDir) : [readUsageSnapshot(fs18, paths.usageSnapshotsDir, identity)].flatMap((snapshot) => snapshot === void 0 ? [] : [snapshot])).map((snapshot) => provider === void 0 ? snapshot : { ...snapshot, providers: Object.fromEntries(Object.entries(snapshot.providers).filter(([name]) => name === provider)) }).filter((snapshot) => Object.keys(snapshot.providers).length > 0);
|
|
68619
68750
|
return {
|
|
68620
68751
|
since: sinceMs === void 0 ? void 0 : new Date(sinceMs).toISOString(),
|
|
68621
68752
|
logDir: paths.usageLogDir,
|
|
@@ -68711,15 +68842,15 @@ function formatUsageReport(report) {
|
|
|
68711
68842
|
}
|
|
68712
68843
|
return lines;
|
|
68713
68844
|
}
|
|
68714
|
-
function collectAccounts(
|
|
68845
|
+
function collectAccounts(fs18, paths, identity) {
|
|
68715
68846
|
if (identity !== void 0) {
|
|
68716
68847
|
requireIdentity(paths, identity);
|
|
68717
68848
|
}
|
|
68718
68849
|
const names = identity === void 0 ? listIdentities(paths).map((entry) => entry.name) : [identity];
|
|
68719
68850
|
return names.map((name) => ({
|
|
68720
68851
|
identity: name,
|
|
68721
|
-
account: readAccountMetadata(
|
|
68722
|
-
usage: readUsageSnapshot(
|
|
68852
|
+
account: readAccountMetadata(fs18, paths.identitiesDir, name),
|
|
68853
|
+
usage: readUsageSnapshot(fs18, paths.usageSnapshotsDir, name)
|
|
68723
68854
|
}));
|
|
68724
68855
|
}
|
|
68725
68856
|
function formatAccounts(views) {
|
|
@@ -68886,7 +69017,7 @@ var import_node_crypto16 = require("node:crypto");
|
|
|
68886
69017
|
|
|
68887
69018
|
// src/launcher.ts
|
|
68888
69019
|
var import_node_crypto15 = require("node:crypto");
|
|
68889
|
-
var
|
|
69020
|
+
var import_node_path35 = __toESM(require("node:path"), 1);
|
|
68890
69021
|
|
|
68891
69022
|
// src/launcher/cliOverride.ts
|
|
68892
69023
|
var InvalidCliCategoryError = class extends CliError {
|
|
@@ -68970,7 +69101,7 @@ function buildCliOverride(params) {
|
|
|
68970
69101
|
}
|
|
68971
69102
|
|
|
68972
69103
|
// src/launcher/flags.ts
|
|
68973
|
-
var
|
|
69104
|
+
var import_node_path34 = __toESM(require("node:path"), 1);
|
|
68974
69105
|
|
|
68975
69106
|
// src/headroom/headers.ts
|
|
68976
69107
|
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
@@ -69040,7 +69171,7 @@ function buildEnv(params) {
|
|
|
69040
69171
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
69041
69172
|
let providerCustomHeaders;
|
|
69042
69173
|
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
69043
|
-
env.CLAUDE_CONFIG_DIR =
|
|
69174
|
+
env.CLAUDE_CONFIG_DIR = import_node_path34.default.join(params.identitiesDir, params.resolvedIdentityName);
|
|
69044
69175
|
}
|
|
69045
69176
|
if (params.provider !== void 0) {
|
|
69046
69177
|
const providerEnv = params.provider.definition.env ?? {};
|
|
@@ -69132,7 +69263,7 @@ function resolveIdentityCredential(identity, credential, env, port) {
|
|
|
69132
69263
|
return resolution.ok ? resolution : { ok: false, status: CREDENTIAL_UNAVAILABLE_EXIT, message: resolution.message };
|
|
69133
69264
|
}
|
|
69134
69265
|
function pickFromPool(decided, params, parsedArgv) {
|
|
69135
|
-
const { paths, fs:
|
|
69266
|
+
const { paths, fs: fs18, proc, log } = params;
|
|
69136
69267
|
if (decided.pool === void 0) {
|
|
69137
69268
|
return { identityDecision: decided };
|
|
69138
69269
|
}
|
|
@@ -69146,7 +69277,7 @@ function pickFromPool(decided, params, parsedArgv) {
|
|
|
69146
69277
|
selectedVia: decided.source,
|
|
69147
69278
|
pools: params.pools,
|
|
69148
69279
|
paths,
|
|
69149
|
-
fs:
|
|
69280
|
+
fs: fs18,
|
|
69150
69281
|
usageFs: farmRuntime.fs,
|
|
69151
69282
|
cwd: farmRuntime.cwd,
|
|
69152
69283
|
now: farmRuntime.now,
|
|
@@ -69162,7 +69293,7 @@ function pickFromPool(decided, params, parsedArgv) {
|
|
|
69162
69293
|
return { identityDecision: { ...decided, name: resolution.identity }, poolExplanation: resolution.explanation };
|
|
69163
69294
|
}
|
|
69164
69295
|
function runLauncher(params) {
|
|
69165
|
-
const { paths, fs:
|
|
69296
|
+
const { paths, fs: fs18, spawn: spawn3, proc, log } = params;
|
|
69166
69297
|
const { env, argv } = proc;
|
|
69167
69298
|
const parsedArgv = parseLauncherArgv(argv);
|
|
69168
69299
|
const cliOverride = buildCliOverride({
|
|
@@ -69177,7 +69308,7 @@ function runLauncher(params) {
|
|
|
69177
69308
|
argv0Identity: parsedArgv.identity,
|
|
69178
69309
|
directoryPinnedIdentity: params.directoryPinnedIdentity,
|
|
69179
69310
|
readActiveIdentityFile: () => {
|
|
69180
|
-
const raw =
|
|
69311
|
+
const raw = fs18.readFileUtf8(paths.activeIdentityFile);
|
|
69181
69312
|
if (raw === void 0) {
|
|
69182
69313
|
return void 0;
|
|
69183
69314
|
}
|
|
@@ -69212,7 +69343,7 @@ function runLauncher(params) {
|
|
|
69212
69343
|
}
|
|
69213
69344
|
let loadedIdentity;
|
|
69214
69345
|
if (identityDecision.name !== void 0) {
|
|
69215
|
-
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name,
|
|
69346
|
+
loadedIdentity = loadIdentity(paths.identitiesDir, identityDecision.name, fs18);
|
|
69216
69347
|
if (loadedIdentity === void 0) {
|
|
69217
69348
|
log.error(
|
|
69218
69349
|
`agent-shim: no identity named "${identityDecision.name}" (selected via ${identityDecision.source}). Run \`agent-shim identity add ${identityDecision.name}\` first.`
|
|
@@ -69227,7 +69358,7 @@ function runLauncher(params) {
|
|
|
69227
69358
|
identityDefaultConfigProfile: loadedIdentity?.config.defaultConfigProfile,
|
|
69228
69359
|
globalDefaultConfigProfile: params.globalDefaultConfigProfile
|
|
69229
69360
|
});
|
|
69230
|
-
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true &&
|
|
69361
|
+
if (configProfileDecision.name !== void 0 && params.allowMissingConfigProfile !== true && fs18.readConfigFile(import_node_path35.default.join(paths.configProfilesDir, `${configProfileDecision.name}.json`)) === void 0) {
|
|
69231
69362
|
log.error(
|
|
69232
69363
|
`agent-shim: no configuration profile named "${configProfileDecision.name}" (selected via ${configProfileDecision.source}). Run \`agent-shim profile add ${configProfileDecision.name}\` first.`
|
|
69233
69364
|
);
|
|
@@ -69236,7 +69367,7 @@ function runLauncher(params) {
|
|
|
69236
69367
|
const farmContext = farm !== void 0 && farmIdentity !== void 0 ? { farm, identity: farmIdentity, cascade: farm.loadCascade(configProfileDecision.name, cliOverride) } : void 0;
|
|
69237
69368
|
const provider = parsedArgv.provider === false ? void 0 : resolveProvider({
|
|
69238
69369
|
paths,
|
|
69239
|
-
port:
|
|
69370
|
+
port: fs18,
|
|
69240
69371
|
env,
|
|
69241
69372
|
...params.credentials === void 0 ? {} : { credentials: params.credentials },
|
|
69242
69373
|
...parsedArgv.provider === void 0 ? {} : { cliProvider: parsedArgv.provider },
|
|
@@ -69520,7 +69651,7 @@ async function runClaude(argvOverride) {
|
|
|
69520
69651
|
// src/cli.ts
|
|
69521
69652
|
async function main() {
|
|
69522
69653
|
aliasLegacyEnv(process.env);
|
|
69523
|
-
const invokedName =
|
|
69654
|
+
const invokedName = import_node_path36.default.basename(process.argv[1] ?? "agent-shim");
|
|
69524
69655
|
if (isInvokedAsClaude(invokedName)) {
|
|
69525
69656
|
await runClaude();
|
|
69526
69657
|
return;
|