claude-use 9.12.1 → 9.14.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/README.md +1 -0
- package/dist/cli.cjs +1073 -586
- package/dist/index.cjs +284 -82
- package/dist/index.mjs +284 -82
- package/dist/types/index.d.ts +224 -41
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -318,10 +318,10 @@ function mergeDefs(...defs) {
|
|
|
318
318
|
function cloneDef(schema) {
|
|
319
319
|
return mergeDefs(schema._zod.def);
|
|
320
320
|
}
|
|
321
|
-
function getElementAtPath(obj,
|
|
322
|
-
if (!
|
|
321
|
+
function getElementAtPath(obj, path52) {
|
|
322
|
+
if (!path52)
|
|
323
323
|
return obj;
|
|
324
|
-
return
|
|
324
|
+
return path52.reduce((acc, key) => acc?.[key], obj);
|
|
325
325
|
}
|
|
326
326
|
function promiseAllObject(promisesObj) {
|
|
327
327
|
const keys = Object.keys(promisesObj);
|
|
@@ -580,11 +580,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
580
580
|
}
|
|
581
581
|
return false;
|
|
582
582
|
}
|
|
583
|
-
function prefixIssues(
|
|
583
|
+
function prefixIssues(path52, issues) {
|
|
584
584
|
return issues.map((iss) => {
|
|
585
585
|
var _a4;
|
|
586
586
|
(_a4 = iss).path ?? (_a4.path = []);
|
|
587
|
-
iss.path.unshift(
|
|
587
|
+
iss.path.unshift(path52);
|
|
588
588
|
return iss;
|
|
589
589
|
});
|
|
590
590
|
}
|
|
@@ -1105,16 +1105,16 @@ function flattenError(error63, mapper = (issue2) => issue2.message) {
|
|
|
1105
1105
|
}
|
|
1106
1106
|
function formatError(error63, mapper = (issue2) => issue2.message) {
|
|
1107
1107
|
const fieldErrors = { _errors: [] };
|
|
1108
|
-
const processError = (error64,
|
|
1108
|
+
const processError = (error64, path52 = []) => {
|
|
1109
1109
|
for (const issue2 of error64.issues) {
|
|
1110
1110
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1111
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1111
|
+
issue2.errors.map((issues) => processError({ issues }, [...path52, ...issue2.path]));
|
|
1112
1112
|
} else if (issue2.code === "invalid_key") {
|
|
1113
|
-
processError({ issues: issue2.issues }, [...
|
|
1113
|
+
processError({ issues: issue2.issues }, [...path52, ...issue2.path]);
|
|
1114
1114
|
} else if (issue2.code === "invalid_element") {
|
|
1115
|
-
processError({ issues: issue2.issues }, [...
|
|
1115
|
+
processError({ issues: issue2.issues }, [...path52, ...issue2.path]);
|
|
1116
1116
|
} else {
|
|
1117
|
-
const fullpath = [...
|
|
1117
|
+
const fullpath = [...path52, ...issue2.path];
|
|
1118
1118
|
if (fullpath.length === 0) {
|
|
1119
1119
|
fieldErrors._errors.push(mapper(issue2));
|
|
1120
1120
|
} else {
|
|
@@ -1153,17 +1153,17 @@ function formatError(error63, mapper = (issue2) => issue2.message) {
|
|
|
1153
1153
|
}
|
|
1154
1154
|
function treeifyError(error63, mapper = (issue2) => issue2.message) {
|
|
1155
1155
|
const result = { errors: [] };
|
|
1156
|
-
const processError = (error64,
|
|
1156
|
+
const processError = (error64, path52 = []) => {
|
|
1157
1157
|
var _a4;
|
|
1158
1158
|
for (const issue2 of error64.issues) {
|
|
1159
1159
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
1160
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
1160
|
+
issue2.errors.map((issues) => processError({ issues }, [...path52, ...issue2.path]));
|
|
1161
1161
|
} else if (issue2.code === "invalid_key") {
|
|
1162
|
-
processError({ issues: issue2.issues }, [...
|
|
1162
|
+
processError({ issues: issue2.issues }, [...path52, ...issue2.path]);
|
|
1163
1163
|
} else if (issue2.code === "invalid_element") {
|
|
1164
|
-
processError({ issues: issue2.issues }, [...
|
|
1164
|
+
processError({ issues: issue2.issues }, [...path52, ...issue2.path]);
|
|
1165
1165
|
} else {
|
|
1166
|
-
const fullpath = [...
|
|
1166
|
+
const fullpath = [...path52, ...issue2.path];
|
|
1167
1167
|
if (fullpath.length === 0) {
|
|
1168
1168
|
result.errors.push(mapper(issue2));
|
|
1169
1169
|
continue;
|
|
@@ -1202,8 +1202,8 @@ function treeifyError(error63, mapper = (issue2) => issue2.message) {
|
|
|
1202
1202
|
}
|
|
1203
1203
|
function toDotPath(_path) {
|
|
1204
1204
|
const segs = [];
|
|
1205
|
-
const
|
|
1206
|
-
for (const seg of
|
|
1205
|
+
const path52 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
1206
|
+
for (const seg of path52) {
|
|
1207
1207
|
if (typeof seg === "number")
|
|
1208
1208
|
segs.push(`[${seg}]`);
|
|
1209
1209
|
else if (typeof seg === "symbol")
|
|
@@ -19199,13 +19199,13 @@ function resolveRef(ref, ctx) {
|
|
|
19199
19199
|
if (!ref.startsWith("#")) {
|
|
19200
19200
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
19201
19201
|
}
|
|
19202
|
-
const
|
|
19203
|
-
if (
|
|
19202
|
+
const path52 = ref.slice(1).split("/").filter(Boolean);
|
|
19203
|
+
if (path52.length === 0) {
|
|
19204
19204
|
return ctx.rootSchema;
|
|
19205
19205
|
}
|
|
19206
19206
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
19207
|
-
if (
|
|
19208
|
-
const key =
|
|
19207
|
+
if (path52[0] === defsKey) {
|
|
19208
|
+
const key = path52[1] === void 0 ? void 0 : decodeJSONPointerSegment(path52[1]);
|
|
19209
19209
|
if (!key || !ctx.defs[key]) {
|
|
19210
19210
|
throw new Error(`Reference not found: ${ref}`);
|
|
19211
19211
|
}
|
|
@@ -23712,42 +23712,42 @@ var require_defaults = __commonJS({
|
|
|
23712
23712
|
var require_env_paths = __commonJS({
|
|
23713
23713
|
"node_modules/.pnpm/env-paths@2.2.1/node_modules/env-paths/index.js"(exports2, module2) {
|
|
23714
23714
|
"use strict";
|
|
23715
|
-
var
|
|
23715
|
+
var path52 = require("path");
|
|
23716
23716
|
var os12 = require("os");
|
|
23717
23717
|
var homedir = os12.homedir();
|
|
23718
23718
|
var tmpdir = os12.tmpdir();
|
|
23719
23719
|
var { env } = process;
|
|
23720
23720
|
var macos = (name) => {
|
|
23721
|
-
const library =
|
|
23721
|
+
const library = path52.join(homedir, "Library");
|
|
23722
23722
|
return {
|
|
23723
|
-
data:
|
|
23724
|
-
config:
|
|
23725
|
-
cache:
|
|
23726
|
-
log:
|
|
23727
|
-
temp:
|
|
23723
|
+
data: path52.join(library, "Application Support", name),
|
|
23724
|
+
config: path52.join(library, "Preferences", name),
|
|
23725
|
+
cache: path52.join(library, "Caches", name),
|
|
23726
|
+
log: path52.join(library, "Logs", name),
|
|
23727
|
+
temp: path52.join(tmpdir, name)
|
|
23728
23728
|
};
|
|
23729
23729
|
};
|
|
23730
23730
|
var windows = (name) => {
|
|
23731
|
-
const appData = env.APPDATA ||
|
|
23732
|
-
const localAppData = env.LOCALAPPDATA ||
|
|
23731
|
+
const appData = env.APPDATA || path52.join(homedir, "AppData", "Roaming");
|
|
23732
|
+
const localAppData = env.LOCALAPPDATA || path52.join(homedir, "AppData", "Local");
|
|
23733
23733
|
return {
|
|
23734
23734
|
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
|
|
23735
|
-
data:
|
|
23736
|
-
config:
|
|
23737
|
-
cache:
|
|
23738
|
-
log:
|
|
23739
|
-
temp:
|
|
23735
|
+
data: path52.join(localAppData, name, "Data"),
|
|
23736
|
+
config: path52.join(appData, name, "Config"),
|
|
23737
|
+
cache: path52.join(localAppData, name, "Cache"),
|
|
23738
|
+
log: path52.join(localAppData, name, "Log"),
|
|
23739
|
+
temp: path52.join(tmpdir, name)
|
|
23740
23740
|
};
|
|
23741
23741
|
};
|
|
23742
23742
|
var linux = (name) => {
|
|
23743
|
-
const username =
|
|
23743
|
+
const username = path52.basename(homedir);
|
|
23744
23744
|
return {
|
|
23745
|
-
data:
|
|
23746
|
-
config:
|
|
23747
|
-
cache:
|
|
23745
|
+
data: path52.join(env.XDG_DATA_HOME || path52.join(homedir, ".local", "share"), name),
|
|
23746
|
+
config: path52.join(env.XDG_CONFIG_HOME || path52.join(homedir, ".config"), name),
|
|
23747
|
+
cache: path52.join(env.XDG_CACHE_HOME || path52.join(homedir, ".cache"), name),
|
|
23748
23748
|
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
|
|
23749
|
-
log:
|
|
23750
|
-
temp:
|
|
23749
|
+
log: path52.join(env.XDG_STATE_HOME || path52.join(homedir, ".local", "state"), name),
|
|
23750
|
+
temp: path52.join(tmpdir, username, name)
|
|
23751
23751
|
};
|
|
23752
23752
|
};
|
|
23753
23753
|
var envPaths = (name, options) => {
|
|
@@ -23815,11 +23815,11 @@ var require_util = __commonJS({
|
|
|
23815
23815
|
return result;
|
|
23816
23816
|
}
|
|
23817
23817
|
exports2.emplace = emplace;
|
|
23818
|
-
function getPropertyByPath(source,
|
|
23819
|
-
if (typeof
|
|
23820
|
-
return source[
|
|
23818
|
+
function getPropertyByPath(source, path52) {
|
|
23819
|
+
if (typeof path52 === "string" && Object.prototype.hasOwnProperty.call(source, path52)) {
|
|
23820
|
+
return source[path52];
|
|
23821
23821
|
}
|
|
23822
|
-
const parsedPath = typeof
|
|
23822
|
+
const parsedPath = typeof path52 === "string" ? path52.split(".") : path52;
|
|
23823
23823
|
return parsedPath.reduce((previous, key) => {
|
|
23824
23824
|
if (previous === void 0) {
|
|
23825
23825
|
return previous;
|
|
@@ -23842,9 +23842,9 @@ var require_util = __commonJS({
|
|
|
23842
23842
|
return Object.fromEntries(Object.entries(options).filter(([, value2]) => value2 !== void 0));
|
|
23843
23843
|
}
|
|
23844
23844
|
exports2.removeUndefinedValuesFromObject = removeUndefinedValuesFromObject;
|
|
23845
|
-
async function isDirectory(
|
|
23845
|
+
async function isDirectory(path52) {
|
|
23846
23846
|
try {
|
|
23847
|
-
const stat = await fs_1.promises.stat(
|
|
23847
|
+
const stat = await fs_1.promises.stat(path52);
|
|
23848
23848
|
return stat.isDirectory();
|
|
23849
23849
|
} catch (e14) {
|
|
23850
23850
|
if (e14.code === "ENOENT") {
|
|
@@ -23854,9 +23854,9 @@ var require_util = __commonJS({
|
|
|
23854
23854
|
}
|
|
23855
23855
|
}
|
|
23856
23856
|
exports2.isDirectory = isDirectory;
|
|
23857
|
-
function isDirectorySync(
|
|
23857
|
+
function isDirectorySync(path52) {
|
|
23858
23858
|
try {
|
|
23859
|
-
const stat = fs_1.default.statSync(
|
|
23859
|
+
const stat = fs_1.default.statSync(path52);
|
|
23860
23860
|
return stat.isDirectory();
|
|
23861
23861
|
} catch (e14) {
|
|
23862
23862
|
if (e14.code === "ENOENT") {
|
|
@@ -23954,7 +23954,7 @@ var require_ExplorerBase = __commonJS({
|
|
|
23954
23954
|
const idx = importStack.indexOf(fullPath);
|
|
23955
23955
|
if (idx !== -1) {
|
|
23956
23956
|
throw new Error(`Circular import detected:
|
|
23957
|
-
${[...importStack, fullPath].map((
|
|
23957
|
+
${[...importStack, fullPath].map((path52, i10) => `${i10 + 1}. ${path52}`).join("\n")} (same as ${idx + 1}.)`);
|
|
23958
23958
|
}
|
|
23959
23959
|
}
|
|
23960
23960
|
}
|
|
@@ -24142,9 +24142,9 @@ var require_Explorer = __commonJS({
|
|
|
24142
24142
|
throw error63;
|
|
24143
24143
|
}
|
|
24144
24144
|
}
|
|
24145
|
-
async #fileExists(
|
|
24145
|
+
async #fileExists(path52) {
|
|
24146
24146
|
try {
|
|
24147
|
-
await promises_1.default.stat(
|
|
24147
|
+
await promises_1.default.stat(path52);
|
|
24148
24148
|
return true;
|
|
24149
24149
|
} catch (e14) {
|
|
24150
24150
|
return false;
|
|
@@ -24304,9 +24304,9 @@ var require_ExplorerSync = __commonJS({
|
|
|
24304
24304
|
throw error63;
|
|
24305
24305
|
}
|
|
24306
24306
|
}
|
|
24307
|
-
#fileExists(
|
|
24307
|
+
#fileExists(path52) {
|
|
24308
24308
|
try {
|
|
24309
|
-
fs_1.default.statSync(
|
|
24309
|
+
fs_1.default.statSync(path52);
|
|
24310
24310
|
return true;
|
|
24311
24311
|
} catch (e14) {
|
|
24312
24312
|
return false;
|
|
@@ -24430,7 +24430,7 @@ var require_dist = __commonJS({
|
|
|
24430
24430
|
};
|
|
24431
24431
|
}
|
|
24432
24432
|
function getResolvedSearchPlaces(moduleName, toolDefinedSearchPlaces, userConfiguredOptions) {
|
|
24433
|
-
const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((
|
|
24433
|
+
const userConfiguredSearchPlaces = userConfiguredOptions.searchPlaces?.map((path52) => path52.replace("{name}", moduleName));
|
|
24434
24434
|
if (userConfiguredOptions.mergeSearchPlaces) {
|
|
24435
24435
|
return [...userConfiguredSearchPlaces ?? [], ...toolDefinedSearchPlaces];
|
|
24436
24436
|
}
|
|
@@ -24790,6 +24790,36 @@ var init_versionDiscovery = __esm({
|
|
|
24790
24790
|
}
|
|
24791
24791
|
});
|
|
24792
24792
|
|
|
24793
|
+
// src/frontdoor/supervisorProcesses.ts
|
|
24794
|
+
function parseFrontDoorSupervisorPids(psOutput) {
|
|
24795
|
+
const pids = [];
|
|
24796
|
+
for (const line of psOutput.split("\n")) {
|
|
24797
|
+
const [pidText, ...argumentsList] = line.trim().split(/\s+/);
|
|
24798
|
+
const pid = Number(pidText);
|
|
24799
|
+
if (Number.isInteger(pid) && pid > 0 && argumentsList.includes(FRONT_DOOR_SUPERVISOR_ARGUMENT)) {
|
|
24800
|
+
pids.push(pid);
|
|
24801
|
+
}
|
|
24802
|
+
}
|
|
24803
|
+
return pids.sort((a10, b) => a10 - b);
|
|
24804
|
+
}
|
|
24805
|
+
function listFrontDoorSupervisors(run, uid) {
|
|
24806
|
+
const result = run.run("ps", ["-U", String(uid), "-o", "pid=,command="]);
|
|
24807
|
+
if (result.status === null) {
|
|
24808
|
+
return { ok: false, message: "ps could not be run" };
|
|
24809
|
+
}
|
|
24810
|
+
if (result.status !== 0) {
|
|
24811
|
+
return { ok: false, message: `ps exited ${String(result.status)}${result.stderr.trim() === "" ? "" : `: ${result.stderr.trim()}`}` };
|
|
24812
|
+
}
|
|
24813
|
+
return { ok: true, pids: parseFrontDoorSupervisorPids(result.stdout) };
|
|
24814
|
+
}
|
|
24815
|
+
var FRONT_DOOR_SUPERVISOR_ARGUMENT;
|
|
24816
|
+
var init_supervisorProcesses = __esm({
|
|
24817
|
+
"src/frontdoor/supervisorProcesses.ts"() {
|
|
24818
|
+
"use strict";
|
|
24819
|
+
FRONT_DOOR_SUPERVISOR_ARGUMENT = "__frontdoor-supervisor";
|
|
24820
|
+
}
|
|
24821
|
+
});
|
|
24822
|
+
|
|
24793
24823
|
// node_modules/.pnpm/trilean@1.7.1/node_modules/trilean/dist/complex.js
|
|
24794
24824
|
var complexFromPolar;
|
|
24795
24825
|
var init_complex = __esm({
|
|
@@ -26769,7 +26799,15 @@ function isCodexProvider(provider) {
|
|
|
26769
26799
|
function poolMemberIdentity(member) {
|
|
26770
26800
|
return typeof member === "string" ? member : member.identity;
|
|
26771
26801
|
}
|
|
26772
|
-
|
|
26802
|
+
function isTimeZone(name) {
|
|
26803
|
+
try {
|
|
26804
|
+
new Intl.DateTimeFormat("en", { timeZone: name });
|
|
26805
|
+
return true;
|
|
26806
|
+
} catch {
|
|
26807
|
+
return false;
|
|
26808
|
+
}
|
|
26809
|
+
}
|
|
26810
|
+
var import_node_path4, CATEGORY_NAMES, OVERRIDABLE_CATEGORIES, CategoryMapSchema, DURATION_RE, DurationSchema, WhenConditionObjectSchema, WhenSchema, EntryValueSchema, ENTRY_KEY_RE, EntriesSchema, LaunchSchema, CREDENTIAL_TARGETS, PROVIDER_CREDENTIAL_TARGETS, CREDENTIAL_TARGET_VARS, ArgvSchema, CommandSourceOptions, EnvCredentialSourceSchema, FileCredentialSourceSchema, CommandCredentialSourceSchema, OpCredentialSourceSchema, KeychainCredentialSourceSchema, LiteralCredentialSourceSchema, CredentialSourceSchema, RemoteCredentialSourceSchema, CREDENTIAL_CACHE_STORES, CredentialCacheSchema, CredentialSchema, ProviderCredentialSchema, RESERVED_PROVIDER_ENV_KEYS, ProviderEnvSchema, PROVIDER_KINDS, CODEX_TIERS, CODEX_EFFORTS, CODEX_LOGINS, CODEX_DEFAULT_LOGIN, CODEX_DEFAULT_MODEL, CODEX_DEFAULT_TIER_MODELS, CODEX_DEFAULT_EFFORT, CodexProviderConfigSchema, ProviderRouteSchema, HttpProviderSchema, CodexProviderSchema, ProviderSchema, ConfigProfileSchema, POOL_SELECTOR_PREFIX, POOL_NAME_PATTERN, IDENTITY_NAME_PATTERN, PoolNameSchema, SELECTOR_RE, IdentitySelectorSchema, PoolMemberSchema, POOL_PREFERENCES, PoolPreferenceSchema, PoolSchema, DirectoryRuleSchema, DirectoryRulesSchema, PortableConfigSchema, HEADROOM_MODES, HEADROOM_CCR_MODES, HEADROOM_ROLLOUT_CHANNELS, INTERCEPT_CHANNELS, READ_MATURATION_CHANNELS, HeadroomGlobalConfigObjectSchema, HeadroomGlobalConfigSchema, HEADROOM_DEFAULT_SOURCE, HEADROOM_DEFAULT_IDLE_SHUTDOWN_MINUTES, FRONTDOOR_DEFAULT_IDLE_SHUTDOWN_MINUTES, FrontDoorGlobalConfigSchema, UPDATE_MODES, UpdateGlobalConfigSchema, GlobalConfigSchema, WEEKDAYS, AnchorSchema, IdentitySchema, CategoryClassificationSchema, CategoryClassificationOverlaySchema, SHIPPED_CATEGORY_DEFAULTS;
|
|
26773
26811
|
var init_schema = __esm({
|
|
26774
26812
|
"src/config/schema.ts"() {
|
|
26775
26813
|
"use strict";
|
|
@@ -27014,12 +27052,20 @@ var init_schema = __esm({
|
|
|
27014
27052
|
update: UpdateGlobalConfigSchema.optional(),
|
|
27015
27053
|
pools: external_exports.record(PoolNameSchema, PoolSchema).optional()
|
|
27016
27054
|
});
|
|
27055
|
+
WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
|
|
27056
|
+
AnchorSchema = external_exports.strictObject({
|
|
27057
|
+
days: external_exports.array(external_exports.enum(WEEKDAYS)).min(1).refine((days) => new Set(days).size === days.length, "an anchor names each weekday at most once"),
|
|
27058
|
+
time: external_exports.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "a 24-hour time such as 06:00"),
|
|
27059
|
+
timeZone: external_exports.string().refine(isTimeZone, "an IANA time zone such as Europe/London").optional()
|
|
27060
|
+
});
|
|
27017
27061
|
IdentitySchema = external_exports.strictObject({
|
|
27018
27062
|
$schema: external_exports.string().optional(),
|
|
27019
27063
|
name: external_exports.string().min(1).regex(/^[A-Za-z0-9][A-Za-z0-9._@-]*$/),
|
|
27020
27064
|
defaultConfigProfile: external_exports.string().min(1).optional(),
|
|
27021
27065
|
allowAmbientCredential: external_exports.boolean().default(false),
|
|
27022
|
-
credential: CredentialSchema.optional()
|
|
27066
|
+
credential: CredentialSchema.optional(),
|
|
27067
|
+
/** When this identity's five-hour window should be open: the front door opens one at each anchor if none is. Absent, nothing is opened on a schedule. */
|
|
27068
|
+
anchors: external_exports.array(AnchorSchema).min(1).optional()
|
|
27023
27069
|
});
|
|
27024
27070
|
CategoryClassificationSchema = external_exports.strictObject({
|
|
27025
27071
|
$schema: external_exports.string().optional(),
|
|
@@ -27321,7 +27367,7 @@ function listFrontDoorSessions(fs22, sessionsDir) {
|
|
|
27321
27367
|
try {
|
|
27322
27368
|
const parsed = FrontDoorSessionSchema.safeParse(JSON.parse(fs22.readFileUtf8(import_node_path6.default.join(sessionsDir, name)) ?? ""));
|
|
27323
27369
|
if (parsed.success) {
|
|
27324
|
-
sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt });
|
|
27370
|
+
sessions.push({ pid: parsed.data.pid, startedAt: parsed.data.startedAt, ...parsed.data.supervisorPid === void 0 ? {} : { supervisorPid: parsed.data.supervisorPid } });
|
|
27325
27371
|
}
|
|
27326
27372
|
} catch {
|
|
27327
27373
|
continue;
|
|
@@ -27366,7 +27412,7 @@ var init_state2 = __esm({
|
|
|
27366
27412
|
import_node_path6 = __toESM(require("node:path"), 1);
|
|
27367
27413
|
init_zod();
|
|
27368
27414
|
FRONT_DOOR_PROTOCOL = 3;
|
|
27369
|
-
FrontDoorSessionSchema = external_exports.strictObject({ pid: external_exports.number().int().positive(), startedAt: external_exports.number(), token: external_exports.string().min(1) });
|
|
27415
|
+
FrontDoorSessionSchema = external_exports.strictObject({ pid: external_exports.number().int().positive(), startedAt: external_exports.number(), token: external_exports.string().min(1), supervisorPid: external_exports.number().int().positive().optional() });
|
|
27370
27416
|
FrontDoorStateSchema = external_exports.strictObject({
|
|
27371
27417
|
/**
|
|
27372
27418
|
* The launcher-to-door wire protocol this supervisor speaks, written once it is serving; absent in state written by a release that predates the field, which `ensureFrontDoor` reads as protocol 0. A launcher replaces a door whose protocol is lower than its own (see `FRONT_DOOR_PROTOCOL`).
|
|
@@ -27799,9 +27845,15 @@ async function runSupervisor(initialConfig, ports, options = {}) {
|
|
|
27799
27845
|
await ports.sleep(HEADROOM_POLL_MS);
|
|
27800
27846
|
}
|
|
27801
27847
|
}
|
|
27848
|
+
function currentHeadroomAllowlistInputs(fs22, paths) {
|
|
27849
|
+
return {
|
|
27850
|
+
providers: readAllProviders(fs22, paths.providersDir).map((entry) => entry.provider),
|
|
27851
|
+
frontDoorOrigin: frontDoorOrigin(readFrontDoorState(fs22, paths.frontdoorStateFile))
|
|
27852
|
+
};
|
|
27853
|
+
}
|
|
27802
27854
|
function currentHeadroomAllowlist(fs22, paths) {
|
|
27803
|
-
const
|
|
27804
|
-
return headroomAllowlist(headroomUpstreams(providers, frontDoorOrigin
|
|
27855
|
+
const inputs = currentHeadroomAllowlistInputs(fs22, paths);
|
|
27856
|
+
return headroomAllowlist(headroomUpstreams(inputs.providers, inputs.frontDoorOrigin));
|
|
27805
27857
|
}
|
|
27806
27858
|
function allowlistOf(ports) {
|
|
27807
27859
|
return currentHeadroomAllowlist(ports.fs, ports.paths);
|
|
@@ -27867,8 +27919,8 @@ function realIsProcessRunning(pid) {
|
|
|
27867
27919
|
return realIsProcessAlive(pid) && !realIsProcessZombie(pid);
|
|
27868
27920
|
}
|
|
27869
27921
|
function realIsFrontDoorSupervisor(pid) {
|
|
27870
|
-
const result = (0, import_node_child_process2.spawnSync)("ps", ["-o", "command=", "-p", String(pid)], { encoding: "utf8" });
|
|
27871
|
-
return result.status === 0 && result.stdout
|
|
27922
|
+
const result = (0, import_node_child_process2.spawnSync)("ps", ["-o", "pid=,command=", "-p", String(pid)], { encoding: "utf8" });
|
|
27923
|
+
return result.status === 0 && parseFrontDoorSupervisorPids(result.stdout).includes(pid);
|
|
27872
27924
|
}
|
|
27873
27925
|
function expandHome(filePath) {
|
|
27874
27926
|
return filePath.startsWith("~/") ? import_node_path8.default.join(import_node_os2.default.homedir(), filePath.slice(1)) : filePath;
|
|
@@ -28072,7 +28124,7 @@ function realResolveClaudeBinary(isOwnBinary) {
|
|
|
28072
28124
|
function realInstalledClaudeVersions() {
|
|
28073
28125
|
return installedVersions(listVersionsDir(defaultVersionsDir()));
|
|
28074
28126
|
}
|
|
28075
|
-
var import_node_child_process2, import_node_crypto4, import_node_fs3, import_node_os2, import_node_path8, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS, realFarmFs, INT32_BYTE_LENGTH,
|
|
28127
|
+
var import_node_child_process2, import_node_crypto4, import_node_fs3, import_node_os2, import_node_path8, import_node_sea, realFsPort, OWNER_ONLY_DIR_MODE, OWNER_ONLY_FILE_MODE, PERMISSION_BITS, realFarmFs, INT32_BYTE_LENGTH, realRunPort, MACOS_GUI_SESSION_MANAGER, realCredentialPort, SOCKET_PERMISSION_BITS, realHeadroomSocketTrust, realSpawnPort, realProcPort, realLogPort, EXECUTE_BITS_MASK, WINDOWS_DEFAULT_PATHEXT;
|
|
28076
28128
|
var init_realPorts = __esm({
|
|
28077
28129
|
"src/realPorts.ts"() {
|
|
28078
28130
|
"use strict";
|
|
@@ -28084,6 +28136,7 @@ var init_realPorts = __esm({
|
|
|
28084
28136
|
import_node_sea = require("node:sea");
|
|
28085
28137
|
init_load();
|
|
28086
28138
|
init_versionDiscovery();
|
|
28139
|
+
init_supervisorProcesses();
|
|
28087
28140
|
init_ensure();
|
|
28088
28141
|
init_supervisor();
|
|
28089
28142
|
init_state();
|
|
@@ -28213,7 +28266,6 @@ var init_realPorts = __esm({
|
|
|
28213
28266
|
}
|
|
28214
28267
|
};
|
|
28215
28268
|
INT32_BYTE_LENGTH = 4;
|
|
28216
|
-
FRONT_DOOR_SUPERVISOR_SUBCOMMAND = "__frontdoor-supervisor";
|
|
28217
28269
|
realRunPort = {
|
|
28218
28270
|
run(command, args) {
|
|
28219
28271
|
const result = (0, import_node_child_process2.spawnSync)(command, [...args], { encoding: "utf8" });
|
|
@@ -28875,8 +28927,8 @@ var require_utils = __commonJS({
|
|
|
28875
28927
|
}
|
|
28876
28928
|
return output2;
|
|
28877
28929
|
};
|
|
28878
|
-
exports2.basename = (
|
|
28879
|
-
const segs =
|
|
28930
|
+
exports2.basename = (path52, { windows } = {}) => {
|
|
28931
|
+
const segs = path52.split(windows ? /[\\/]/ : "/");
|
|
28880
28932
|
const last = segs[segs.length - 1];
|
|
28881
28933
|
if (last === "") {
|
|
28882
28934
|
return segs[segs.length - 2];
|
|
@@ -32542,6 +32594,7 @@ function buildLayoutPaths(root) {
|
|
|
32542
32594
|
usageLogDir: import_node_path19.default.join(root, "usage", "log"),
|
|
32543
32595
|
usageSnapshotsDir: import_node_path19.default.join(root, "usage", "snapshots"),
|
|
32544
32596
|
usagePicksFile: import_node_path19.default.join(root, "usage", "picks.json"),
|
|
32597
|
+
usageAnchorsFile: import_node_path19.default.join(root, "usage", "anchors.json"),
|
|
32545
32598
|
mcpPermissionsFile: import_node_path19.default.join(root, "mcp", "permissions.json")
|
|
32546
32599
|
};
|
|
32547
32600
|
}
|
|
@@ -32559,6 +32612,47 @@ var init_paths = __esm({
|
|
|
32559
32612
|
}
|
|
32560
32613
|
});
|
|
32561
32614
|
|
|
32615
|
+
// src/cli/pairs.ts
|
|
32616
|
+
function splitCommas(input2) {
|
|
32617
|
+
if (input2 === "") {
|
|
32618
|
+
return [];
|
|
32619
|
+
}
|
|
32620
|
+
return input2.split(",");
|
|
32621
|
+
}
|
|
32622
|
+
function parsePair(input2) {
|
|
32623
|
+
const eqIndex = input2.indexOf("=");
|
|
32624
|
+
if (eqIndex === -1) {
|
|
32625
|
+
throw new Error(`Expected "<key>=<value>", got "${input2}" (no "=" found)`);
|
|
32626
|
+
}
|
|
32627
|
+
const key = input2.slice(0, eqIndex);
|
|
32628
|
+
const value2 = input2.slice(eqIndex + 1);
|
|
32629
|
+
if (key === "") {
|
|
32630
|
+
throw new Error(`Expected a non-empty key before "=" in "${input2}"`);
|
|
32631
|
+
}
|
|
32632
|
+
return { key, value: value2 };
|
|
32633
|
+
}
|
|
32634
|
+
function parseBool(input2) {
|
|
32635
|
+
const parsed = parseBoolWord(input2);
|
|
32636
|
+
if (parsed === void 0) {
|
|
32637
|
+
throw new Error(`Expected "true", "false", "1" or "0", got "${input2}"`);
|
|
32638
|
+
}
|
|
32639
|
+
return parsed;
|
|
32640
|
+
}
|
|
32641
|
+
function parseBoolPairList(input2) {
|
|
32642
|
+
const result = {};
|
|
32643
|
+
for (const piece of splitCommas(input2)) {
|
|
32644
|
+
const { key, value: value2 } = parsePair(piece);
|
|
32645
|
+
result[key] = parseBool(value2);
|
|
32646
|
+
}
|
|
32647
|
+
return result;
|
|
32648
|
+
}
|
|
32649
|
+
var init_pairs = __esm({
|
|
32650
|
+
"src/cli/pairs.ts"() {
|
|
32651
|
+
"use strict";
|
|
32652
|
+
init_bool();
|
|
32653
|
+
}
|
|
32654
|
+
});
|
|
32655
|
+
|
|
32562
32656
|
// src/usage/schema.ts
|
|
32563
32657
|
function isRateLimitHeader(name) {
|
|
32564
32658
|
const lower = name.toLowerCase();
|
|
@@ -32758,7 +32852,7 @@ function epochSecondsToIso(value2) {
|
|
|
32758
32852
|
return void 0;
|
|
32759
32853
|
}
|
|
32760
32854
|
const seconds = Number(value2);
|
|
32761
|
-
return Number.isFinite(seconds) && seconds > 0 ? new Date(seconds *
|
|
32855
|
+
return Number.isFinite(seconds) && seconds > 0 ? new Date(seconds * MS_PER_SECOND2).toISOString() : void 0;
|
|
32762
32856
|
}
|
|
32763
32857
|
function nonNegativeNumber(value2) {
|
|
32764
32858
|
if (value2 === void 0 || value2.trim() === "") {
|
|
@@ -32842,7 +32936,7 @@ function retryAfterSeconds(value2, nowMs) {
|
|
|
32842
32936
|
return seconds;
|
|
32843
32937
|
}
|
|
32844
32938
|
const date5 = Date.parse(value2);
|
|
32845
|
-
return Number.isNaN(date5) ? void 0 : Math.max(0, Math.ceil((date5 - nowMs) /
|
|
32939
|
+
return Number.isNaN(date5) ? void 0 : Math.max(0, Math.ceil((date5 - nowMs) / MS_PER_SECOND2));
|
|
32846
32940
|
}
|
|
32847
32941
|
function classifyLimit(params) {
|
|
32848
32942
|
const { status, headers, error: error63 } = params;
|
|
@@ -32881,14 +32975,14 @@ function classifyLimit(params) {
|
|
|
32881
32975
|
evidence
|
|
32882
32976
|
};
|
|
32883
32977
|
}
|
|
32884
|
-
var TOO_MANY_REQUESTS, PAYMENT_REQUIRED,
|
|
32978
|
+
var TOO_MANY_REQUESTS, PAYMENT_REQUIRED, MS_PER_SECOND2, UNIFIED_PREFIX, QUOTA_EXHAUSTED_ERRORS, QUOTA_EXHAUSTED_MESSAGE, EVIDENCE_TOKEN;
|
|
32885
32979
|
var init_rateLimit = __esm({
|
|
32886
32980
|
"src/usage/rateLimit.ts"() {
|
|
32887
32981
|
"use strict";
|
|
32888
32982
|
init_schema2();
|
|
32889
32983
|
TOO_MANY_REQUESTS = 429;
|
|
32890
32984
|
PAYMENT_REQUIRED = 402;
|
|
32891
|
-
|
|
32985
|
+
MS_PER_SECOND2 = 1e3;
|
|
32892
32986
|
UNIFIED_PREFIX = "anthropic-ratelimit-unified-";
|
|
32893
32987
|
QUOTA_EXHAUSTED_ERRORS = /* @__PURE__ */ new Set(["usage_limit_reached", "insufficient_quota", "1308", "1309", "1310", "1316", "1317", "1318", "1319", "1320", "1321"]);
|
|
32894
32988
|
QUOTA_EXHAUSTED_MESSAGE = /usage limit|quota (?:exceeded|exhausted)|limit exhausted|insufficient (?:balance|credits|quota)/i;
|
|
@@ -32898,11 +32992,11 @@ var init_rateLimit = __esm({
|
|
|
32898
32992
|
|
|
32899
32993
|
// src/usage/preflight.ts
|
|
32900
32994
|
function formatAge(ms2) {
|
|
32901
|
-
const minutes = Math.floor(ms2 / (
|
|
32902
|
-
if (minutes <
|
|
32995
|
+
const minutes = Math.floor(ms2 / (MS_PER_SECOND3 * SECONDS_PER_MINUTE));
|
|
32996
|
+
if (minutes < MINUTES_PER_HOUR2) {
|
|
32903
32997
|
return `${String(Math.max(minutes, 0))}m`;
|
|
32904
32998
|
}
|
|
32905
|
-
const hours = Math.floor(minutes /
|
|
32999
|
+
const hours = Math.floor(minutes / MINUTES_PER_HOUR2);
|
|
32906
33000
|
return hours < HOURS_PER_DAY ? `${String(hours)}h` : `${String(Math.floor(hours / HOURS_PER_DAY))}d`;
|
|
32907
33001
|
}
|
|
32908
33002
|
function effectiveWindow(window, nowMs) {
|
|
@@ -32939,14 +33033,14 @@ function quotaWarnings(snapshot, provider, nowMs) {
|
|
|
32939
33033
|
return [`agent-shim: identity ${snapshot.identity}: the ${name} quota is ${verdict}${reset} (last seen ${age2} ago)`];
|
|
32940
33034
|
});
|
|
32941
33035
|
}
|
|
32942
|
-
var
|
|
33036
|
+
var MS_PER_SECOND3, SECONDS_PER_MINUTE, MINUTES_PER_HOUR2, HOURS_PER_DAY, WARNING_STATUSES;
|
|
32943
33037
|
var init_preflight = __esm({
|
|
32944
33038
|
"src/usage/preflight.ts"() {
|
|
32945
33039
|
"use strict";
|
|
32946
33040
|
init_rateLimit();
|
|
32947
|
-
|
|
33041
|
+
MS_PER_SECOND3 = 1e3;
|
|
32948
33042
|
SECONDS_PER_MINUTE = 60;
|
|
32949
|
-
|
|
33043
|
+
MINUTES_PER_HOUR2 = 60;
|
|
32950
33044
|
HOURS_PER_DAY = 24;
|
|
32951
33045
|
WARNING_STATUSES = /* @__PURE__ */ new Set(["allowed_warning", "rejected"]);
|
|
32952
33046
|
}
|
|
@@ -33201,54 +33295,13 @@ var init_credential = __esm({
|
|
|
33201
33295
|
}
|
|
33202
33296
|
});
|
|
33203
33297
|
|
|
33204
|
-
// src/cli/pairs.ts
|
|
33205
|
-
function splitCommas(input2) {
|
|
33206
|
-
if (input2 === "") {
|
|
33207
|
-
return [];
|
|
33208
|
-
}
|
|
33209
|
-
return input2.split(",");
|
|
33210
|
-
}
|
|
33211
|
-
function parsePair(input2) {
|
|
33212
|
-
const eqIndex = input2.indexOf("=");
|
|
33213
|
-
if (eqIndex === -1) {
|
|
33214
|
-
throw new Error(`Expected "<key>=<value>", got "${input2}" (no "=" found)`);
|
|
33215
|
-
}
|
|
33216
|
-
const key = input2.slice(0, eqIndex);
|
|
33217
|
-
const value2 = input2.slice(eqIndex + 1);
|
|
33218
|
-
if (key === "") {
|
|
33219
|
-
throw new Error(`Expected a non-empty key before "=" in "${input2}"`);
|
|
33220
|
-
}
|
|
33221
|
-
return { key, value: value2 };
|
|
33222
|
-
}
|
|
33223
|
-
function parseBool(input2) {
|
|
33224
|
-
const parsed = parseBoolWord(input2);
|
|
33225
|
-
if (parsed === void 0) {
|
|
33226
|
-
throw new Error(`Expected "true", "false", "1" or "0", got "${input2}"`);
|
|
33227
|
-
}
|
|
33228
|
-
return parsed;
|
|
33229
|
-
}
|
|
33230
|
-
function parseBoolPairList(input2) {
|
|
33231
|
-
const result = {};
|
|
33232
|
-
for (const piece of splitCommas(input2)) {
|
|
33233
|
-
const { key, value: value2 } = parsePair(piece);
|
|
33234
|
-
result[key] = parseBool(value2);
|
|
33235
|
-
}
|
|
33236
|
-
return result;
|
|
33237
|
-
}
|
|
33238
|
-
var init_pairs = __esm({
|
|
33239
|
-
"src/cli/pairs.ts"() {
|
|
33240
|
-
"use strict";
|
|
33241
|
-
init_bool();
|
|
33242
|
-
}
|
|
33243
|
-
});
|
|
33244
|
-
|
|
33245
33298
|
// package.json
|
|
33246
33299
|
var package_default;
|
|
33247
33300
|
var init_package = __esm({
|
|
33248
33301
|
"package.json"() {
|
|
33249
33302
|
package_default = {
|
|
33250
33303
|
name: "claude-use",
|
|
33251
|
-
version: "9.
|
|
33304
|
+
version: "9.14.0",
|
|
33252
33305
|
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.",
|
|
33253
33306
|
license: "MIT",
|
|
33254
33307
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -33519,11 +33572,11 @@ function identifyRequest(headers) {
|
|
|
33519
33572
|
function directOrigin(port) {
|
|
33520
33573
|
return `http://127.0.0.1:${String(port)}`;
|
|
33521
33574
|
}
|
|
33522
|
-
function parseProviderPath(
|
|
33523
|
-
if (!
|
|
33575
|
+
function parseProviderPath(path52) {
|
|
33576
|
+
if (!path52.startsWith(PROVIDER_PATH_PREFIX)) {
|
|
33524
33577
|
return void 0;
|
|
33525
33578
|
}
|
|
33526
|
-
const tail =
|
|
33579
|
+
const tail = path52.slice(PROVIDER_PATH_PREFIX.length);
|
|
33527
33580
|
const slash = tail.indexOf("/");
|
|
33528
33581
|
if (slash <= 0) {
|
|
33529
33582
|
return void 0;
|
|
@@ -33849,9 +33902,9 @@ function decoderFor(encoding) {
|
|
|
33849
33902
|
return void 0;
|
|
33850
33903
|
}
|
|
33851
33904
|
}
|
|
33852
|
-
function destinationOf(
|
|
33853
|
-
const scoped = parseProviderPath(
|
|
33854
|
-
return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint:
|
|
33905
|
+
function destinationOf(path52) {
|
|
33906
|
+
const scoped = parseProviderPath(path52);
|
|
33907
|
+
return scoped === void 0 ? { provider: ANTHROPIC_PROVIDER, endpoint: path52 } : { provider: scoped.provider, endpoint: scoped.rest };
|
|
33855
33908
|
}
|
|
33856
33909
|
function buildRecord(event, context) {
|
|
33857
33910
|
const { scan } = context;
|
|
@@ -34008,7 +34061,7 @@ function limitBlockedUntil(state, nowMs) {
|
|
|
34008
34061
|
if (state.lastRequestAt !== void 0 && Date.parse(state.lastRequestAt) > Date.parse(limit.observedAt)) {
|
|
34009
34062
|
return void 0;
|
|
34010
34063
|
}
|
|
34011
|
-
const until = limit.resetAt === void 0 ? limit.retryAfterSeconds === void 0 ? void 0 : Date.parse(limit.observedAt) + limit.retryAfterSeconds *
|
|
34064
|
+
const until = limit.resetAt === void 0 ? limit.retryAfterSeconds === void 0 ? void 0 : Date.parse(limit.observedAt) + limit.retryAfterSeconds * MS_PER_SECOND4 : Date.parse(limit.resetAt);
|
|
34012
34065
|
return until !== void 0 && until > nowMs ? until : void 0;
|
|
34013
34066
|
}
|
|
34014
34067
|
function windowBlockedUntil(windows) {
|
|
@@ -34118,7 +34171,7 @@ function assessIdentity(member, nowMs) {
|
|
|
34118
34171
|
);
|
|
34119
34172
|
if (blockedUntil > nowMs) {
|
|
34120
34173
|
if (unified.overageStatus === "allowed") {
|
|
34121
|
-
return { candidate: { ...base, class: "pay-per-use", reasons: [`plan exhausted until ${new Date(blockedUntil).toISOString()}, continues as extra usage`, ...windowReasons, ...planReasons] } };
|
|
34174
|
+
return { candidate: { ...base, class: "pay-per-use", planReturnsAtMs: blockedUntil, reasons: [`plan exhausted until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)}), continues as extra usage`, ...windowReasons, ...planReasons] } };
|
|
34122
34175
|
}
|
|
34123
34176
|
return { candidate: { ...base, class: "ineligible", blockedUntilMs: blockedUntil, reasons: [`refused until ${new Date(blockedUntil).toISOString()} (in ${formatAge(blockedUntil - nowMs)})`, ...unified.fallbackAvailable === true ? ["a fallback is on offer, so requests for some models may still be served"] : [], ...windowReasons, ...overageReasons, ...planReasons] } };
|
|
34124
34177
|
}
|
|
@@ -34131,10 +34184,10 @@ function assessIdentity(member, nowMs) {
|
|
|
34131
34184
|
return { candidate: { ...base, class: "unknown", reasons: ["quota windows reported no utilisation", ...windowReasons, ...planReasons] } };
|
|
34132
34185
|
}
|
|
34133
34186
|
const remaining = Math.max(0, 1 - basis.window.utilization);
|
|
34134
|
-
const untilResetMs = basis.window.resetsAtMs === void 0 ? basis.windowMs : Math.max(basis.window.resetsAtMs - nowMs,
|
|
34187
|
+
const untilResetMs = basis.window.resetsAtMs === void 0 ? basis.windowMs : Math.max(basis.window.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
34135
34188
|
const weeklyScore = remaining * plan.capacity / (untilResetMs / MS_PER_HOUR2);
|
|
34136
34189
|
const fiveRemaining = five?.utilization === void 0 ? void 0 : Math.max(0, 1 - five.utilization);
|
|
34137
|
-
const fiveUntil = five?.resetsAtMs === void 0 ? FIVE_HOUR_WINDOW_MS : Math.max(five.resetsAtMs - nowMs,
|
|
34190
|
+
const fiveUntil = five?.resetsAtMs === void 0 ? FIVE_HOUR_WINDOW_MS : Math.max(five.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
34138
34191
|
const ratio = windowRatio(member.records);
|
|
34139
34192
|
const fiveHourScore = basis.name === "sevenDay" && fiveRemaining !== void 0 && ratio !== void 0 ? Math.min(fiveRemaining * ratio, remaining) * plan.capacity / (fiveUntil / MS_PER_HOUR2) : void 0;
|
|
34140
34193
|
const fiveHourLeads = fiveHourScore !== void 0 && fiveHourScore > weeklyScore;
|
|
@@ -34143,7 +34196,7 @@ function assessIdentity(member, nowMs) {
|
|
|
34143
34196
|
const fiveHourTermReasons = basis.name !== "sevenDay" || fiveRemaining === void 0 ? [] : ratio === void 0 ? ["5h reset not scored: no measured 5h to 7d ratio yet"] : fiveHourLeads ? [`5h term leads: ${percent(fiveRemaining)} of 5h unused is about ${percent(Math.min(fiveRemaining * ratio, remaining))} of the week at the measured ratio, resets in ${formatAge(fiveUntil)}`] : [];
|
|
34144
34197
|
const burn = windowBurn(member.records, "fiveHour");
|
|
34145
34198
|
const sevenRemaining = seven?.utilization === void 0 ? void 0 : Math.max(0, 1 - seven.utilization);
|
|
34146
|
-
const sevenUntil = seven?.resetsAtMs === void 0 ? SEVEN_DAY_WINDOW_MS : Math.max(seven.resetsAtMs - nowMs,
|
|
34199
|
+
const sevenUntil = seven?.resetsAtMs === void 0 ? SEVEN_DAY_WINDOW_MS : Math.max(seven.resetsAtMs - nowMs, MS_PER_SECOND4);
|
|
34147
34200
|
const sevenDayBurn = windowBurn(member.records, "sevenDay");
|
|
34148
34201
|
return {
|
|
34149
34202
|
candidate: { ...base, class: "scored", score, scoreWindow, reasons: [...fiveHourTermReasons, ...windowReasons.map((reason, index) => index === windowReasons.length - 1 ? `${reason}${observedAgo}` : reason), ...planReasons] },
|
|
@@ -34233,10 +34286,11 @@ function rankPool(input2) {
|
|
|
34233
34286
|
return {
|
|
34234
34287
|
candidates: ordered,
|
|
34235
34288
|
...pick2 === void 0 ? { ...earliestReturn === void 0 ? {} : { earliestReturn } } : { pick: pick2 },
|
|
34236
|
-
...movedOff === void 0 || pick2 === void 0 ? {} : { movedOff }
|
|
34289
|
+
...movedOff === void 0 || pick2 === void 0 ? {} : { movedOff },
|
|
34290
|
+
...pick2?.planReturnsAtMs === void 0 ? {} : { planReturn: { identity: pick2.identity, atMs: pick2.planReturnsAtMs } }
|
|
34237
34291
|
};
|
|
34238
34292
|
}
|
|
34239
|
-
var
|
|
34293
|
+
var MS_PER_SECOND4, MS_PER_HOUR2, HOURS_PER_DAY2, FIVE_HOURS, PROMPT_CACHE_TTL_HOURS, PERCENT, SEVEN_DAYS, FIVE_HOUR_WINDOW_MS, SEVEN_DAY_WINDOW_MS, PROMPT_CACHE_TTL_MS, CLASS_ORDER;
|
|
34240
34294
|
var init_pick = __esm({
|
|
34241
34295
|
"src/usage/pick.ts"() {
|
|
34242
34296
|
"use strict";
|
|
@@ -34246,7 +34300,7 @@ var init_pick = __esm({
|
|
|
34246
34300
|
init_preflight();
|
|
34247
34301
|
init_quotaFacts();
|
|
34248
34302
|
init_rateLimit();
|
|
34249
|
-
|
|
34303
|
+
MS_PER_SECOND4 = 1e3;
|
|
34250
34304
|
MS_PER_HOUR2 = 36e5;
|
|
34251
34305
|
HOURS_PER_DAY2 = 24;
|
|
34252
34306
|
FIVE_HOURS = 5;
|
|
@@ -34531,7 +34585,7 @@ function createUsageStore(deps) {
|
|
|
34531
34585
|
})
|
|
34532
34586
|
};
|
|
34533
34587
|
}
|
|
34534
|
-
var import_node_path25, DAY_MS2,
|
|
34588
|
+
var import_node_path25, DAY_MS2, DAYS_IN_WEEK2, USAGE_RETENTION_MS;
|
|
34535
34589
|
var init_store2 = __esm({
|
|
34536
34590
|
"src/usage/store.ts"() {
|
|
34537
34591
|
"use strict";
|
|
@@ -34541,8 +34595,8 @@ var init_store2 = __esm({
|
|
|
34541
34595
|
init_read();
|
|
34542
34596
|
init_schema2();
|
|
34543
34597
|
DAY_MS2 = 864e5;
|
|
34544
|
-
|
|
34545
|
-
USAGE_RETENTION_MS =
|
|
34598
|
+
DAYS_IN_WEEK2 = 7;
|
|
34599
|
+
USAGE_RETENTION_MS = DAYS_IN_WEEK2 * DAY_MS2;
|
|
34546
34600
|
}
|
|
34547
34601
|
});
|
|
34548
34602
|
|
|
@@ -36286,14 +36340,14 @@ var require_util2 = __commonJS({
|
|
|
36286
36340
|
}
|
|
36287
36341
|
const port = url2.port != null ? url2.port : url2.protocol === "https:" ? 443 : 80;
|
|
36288
36342
|
let origin = url2.origin != null ? url2.origin : `${url2.protocol || ""}//${url2.hostname || ""}:${port}`;
|
|
36289
|
-
let
|
|
36343
|
+
let path52 = url2.path != null ? url2.path : `${url2.pathname || ""}${url2.search || ""}`;
|
|
36290
36344
|
if (origin[origin.length - 1] === "/") {
|
|
36291
36345
|
origin = origin.slice(0, origin.length - 1);
|
|
36292
36346
|
}
|
|
36293
|
-
if (
|
|
36294
|
-
|
|
36347
|
+
if (path52 && path52[0] !== "/") {
|
|
36348
|
+
path52 = `/${path52}`;
|
|
36295
36349
|
}
|
|
36296
|
-
return new URL(`${origin}${
|
|
36350
|
+
return new URL(`${origin}${path52}`);
|
|
36297
36351
|
}
|
|
36298
36352
|
if (!isHttpOrHttpsPrefixed(url2.origin || url2.protocol)) {
|
|
36299
36353
|
throw new InvalidArgumentError2("Invalid URL protocol: the URL must start with `http:` or `https:`.");
|
|
@@ -37114,9 +37168,9 @@ var require_diagnostics = __commonJS({
|
|
|
37114
37168
|
"undici:client:sendHeaders",
|
|
37115
37169
|
(evt) => {
|
|
37116
37170
|
const {
|
|
37117
|
-
request: { method, path:
|
|
37171
|
+
request: { method, path: path52, origin }
|
|
37118
37172
|
} = evt;
|
|
37119
|
-
debugLog("sending request to %s %s%s", method, origin,
|
|
37173
|
+
debugLog("sending request to %s %s%s", method, origin, path52);
|
|
37120
37174
|
}
|
|
37121
37175
|
);
|
|
37122
37176
|
}
|
|
@@ -37134,14 +37188,14 @@ var require_diagnostics = __commonJS({
|
|
|
37134
37188
|
"undici:request:headers",
|
|
37135
37189
|
(evt) => {
|
|
37136
37190
|
const {
|
|
37137
|
-
request: { method, path:
|
|
37191
|
+
request: { method, path: path52, origin },
|
|
37138
37192
|
response: { statusCode }
|
|
37139
37193
|
} = evt;
|
|
37140
37194
|
debugLog(
|
|
37141
37195
|
"received response to %s %s%s - HTTP %d",
|
|
37142
37196
|
method,
|
|
37143
37197
|
origin,
|
|
37144
|
-
|
|
37198
|
+
path52,
|
|
37145
37199
|
statusCode
|
|
37146
37200
|
);
|
|
37147
37201
|
}
|
|
@@ -37150,23 +37204,23 @@ var require_diagnostics = __commonJS({
|
|
|
37150
37204
|
"undici:request:trailers",
|
|
37151
37205
|
(evt) => {
|
|
37152
37206
|
const {
|
|
37153
|
-
request: { method, path:
|
|
37207
|
+
request: { method, path: path52, origin }
|
|
37154
37208
|
} = evt;
|
|
37155
|
-
debugLog("trailers received from %s %s%s", method, origin,
|
|
37209
|
+
debugLog("trailers received from %s %s%s", method, origin, path52);
|
|
37156
37210
|
}
|
|
37157
37211
|
);
|
|
37158
37212
|
diagnosticsChannel.subscribe(
|
|
37159
37213
|
"undici:request:error",
|
|
37160
37214
|
(evt) => {
|
|
37161
37215
|
const {
|
|
37162
|
-
request: { method, path:
|
|
37216
|
+
request: { method, path: path52, origin },
|
|
37163
37217
|
error: error63
|
|
37164
37218
|
} = evt;
|
|
37165
37219
|
debugLog(
|
|
37166
37220
|
"request to %s %s%s errored - %s",
|
|
37167
37221
|
method,
|
|
37168
37222
|
origin,
|
|
37169
|
-
|
|
37223
|
+
path52,
|
|
37170
37224
|
error63.message
|
|
37171
37225
|
);
|
|
37172
37226
|
}
|
|
@@ -37281,7 +37335,7 @@ var require_request = __commonJS({
|
|
|
37281
37335
|
var kHandler = /* @__PURE__ */ Symbol("handler");
|
|
37282
37336
|
var Request2 = class {
|
|
37283
37337
|
constructor(origin, {
|
|
37284
|
-
path:
|
|
37338
|
+
path: path52,
|
|
37285
37339
|
method,
|
|
37286
37340
|
body,
|
|
37287
37341
|
headers,
|
|
@@ -37298,11 +37352,11 @@ var require_request = __commonJS({
|
|
|
37298
37352
|
maxRedirections,
|
|
37299
37353
|
typeOfService
|
|
37300
37354
|
}, handler) {
|
|
37301
|
-
if (typeof
|
|
37355
|
+
if (typeof path52 !== "string") {
|
|
37302
37356
|
throw new InvalidArgumentError2("path must be a string");
|
|
37303
|
-
} else if (
|
|
37357
|
+
} else if (path52[0] !== "/" && !(path52.startsWith("http://") || path52.startsWith("https://")) && method !== "CONNECT") {
|
|
37304
37358
|
throw new InvalidArgumentError2("path must be an absolute URL or start with a slash");
|
|
37305
|
-
} else if (invalidPathRegex.test(
|
|
37359
|
+
} else if (invalidPathRegex.test(path52)) {
|
|
37306
37360
|
throw new InvalidArgumentError2("invalid request path");
|
|
37307
37361
|
}
|
|
37308
37362
|
if (typeof method !== "string") {
|
|
@@ -37377,7 +37431,7 @@ var require_request = __commonJS({
|
|
|
37377
37431
|
this.completed = false;
|
|
37378
37432
|
this.aborted = false;
|
|
37379
37433
|
this.upgrade = upgrade || null;
|
|
37380
|
-
this.path = query ? serializePathWithQuery(
|
|
37434
|
+
this.path = query ? serializePathWithQuery(path52, query) : path52;
|
|
37381
37435
|
this.origin = origin;
|
|
37382
37436
|
this.protocol = getProtocolFromUrlString(origin);
|
|
37383
37437
|
this.idempotent = idempotent == null ? method === "HEAD" || method === "GET" : idempotent;
|
|
@@ -42559,7 +42613,7 @@ var require_client_h1 = __commonJS({
|
|
|
42559
42613
|
return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
|
|
42560
42614
|
}
|
|
42561
42615
|
function writeH1(client, request7) {
|
|
42562
|
-
const { method, path:
|
|
42616
|
+
const { method, path: path52, host, upgrade, blocking, reset } = request7;
|
|
42563
42617
|
let { body, headers, contentLength } = request7;
|
|
42564
42618
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
|
|
42565
42619
|
if (util2.isFormDataLike(body)) {
|
|
@@ -42637,7 +42691,7 @@ var require_client_h1 = __commonJS({
|
|
|
42637
42691
|
if (socket.setTypeOfService) {
|
|
42638
42692
|
socket.setTypeOfService(request7.typeOfService);
|
|
42639
42693
|
}
|
|
42640
|
-
let header = `${method} ${
|
|
42694
|
+
let header = `${method} ${path52} HTTP/1.1\r
|
|
42641
42695
|
`;
|
|
42642
42696
|
if (typeof host === "string") {
|
|
42643
42697
|
header += `host: ${host}\r
|
|
@@ -43316,7 +43370,7 @@ var require_client_h2 = __commonJS({
|
|
|
43316
43370
|
const headersTimeout = request7.headersTimeout ?? client[kHeadersTimeout];
|
|
43317
43371
|
const bodyTimeout = request7.bodyTimeout ?? client[kBodyTimeout];
|
|
43318
43372
|
const session = client[kHTTP2Session];
|
|
43319
|
-
const { method, path:
|
|
43373
|
+
const { method, path: path52, host, upgrade, expectContinue, signal, protocol, headers: reqHeaders } = request7;
|
|
43320
43374
|
let { body } = request7;
|
|
43321
43375
|
if (upgrade != null && upgrade !== "websocket") {
|
|
43322
43376
|
util2.errorRequest(client, request7, new InvalidArgumentError2(`Custom upgrade "${upgrade}" not supported over HTTP/2`));
|
|
@@ -43385,7 +43439,7 @@ var require_client_h2 = __commonJS({
|
|
|
43385
43439
|
}
|
|
43386
43440
|
headers[HTTP2_HEADER_METHOD] = "CONNECT";
|
|
43387
43441
|
headers[HTTP2_HEADER_PROTOCOL] = "websocket";
|
|
43388
|
-
headers[HTTP2_HEADER_PATH] =
|
|
43442
|
+
headers[HTTP2_HEADER_PATH] = path52;
|
|
43389
43443
|
if (protocol === "ws:" || protocol === "wss:") {
|
|
43390
43444
|
headers[HTTP2_HEADER_SCHEME] = protocol === "ws:" ? "http" : "https";
|
|
43391
43445
|
} else {
|
|
@@ -43427,7 +43481,7 @@ var require_client_h2 = __commonJS({
|
|
|
43427
43481
|
stream.setTimeout(headersTimeout);
|
|
43428
43482
|
return true;
|
|
43429
43483
|
}
|
|
43430
|
-
headers[HTTP2_HEADER_PATH] =
|
|
43484
|
+
headers[HTTP2_HEADER_PATH] = path52;
|
|
43431
43485
|
headers[HTTP2_HEADER_SCHEME] = protocol === "http:" ? "http" : "https";
|
|
43432
43486
|
const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH";
|
|
43433
43487
|
if (body && typeof body.read === "function") {
|
|
@@ -45779,10 +45833,10 @@ var require_proxy_agent = __commonJS({
|
|
|
45779
45833
|
};
|
|
45780
45834
|
const {
|
|
45781
45835
|
origin,
|
|
45782
|
-
path:
|
|
45836
|
+
path: path52 = "/",
|
|
45783
45837
|
headers = {}
|
|
45784
45838
|
} = opts;
|
|
45785
|
-
opts.path = origin +
|
|
45839
|
+
opts.path = origin + path52;
|
|
45786
45840
|
if (!("host" in headers) && !("Host" in headers)) {
|
|
45787
45841
|
const { host } = new URL(origin);
|
|
45788
45842
|
headers.host = host;
|
|
@@ -47891,20 +47945,20 @@ var require_mock_utils = __commonJS({
|
|
|
47891
47945
|
}
|
|
47892
47946
|
return normalizedQp;
|
|
47893
47947
|
}
|
|
47894
|
-
function safeUrl(
|
|
47895
|
-
if (typeof
|
|
47896
|
-
return
|
|
47948
|
+
function safeUrl(path52) {
|
|
47949
|
+
if (typeof path52 !== "string") {
|
|
47950
|
+
return path52;
|
|
47897
47951
|
}
|
|
47898
|
-
const pathSegments =
|
|
47952
|
+
const pathSegments = path52.split("?", 3);
|
|
47899
47953
|
if (pathSegments.length !== 2) {
|
|
47900
|
-
return
|
|
47954
|
+
return path52;
|
|
47901
47955
|
}
|
|
47902
47956
|
const qp2 = new URLSearchParams(pathSegments.pop());
|
|
47903
47957
|
qp2.sort();
|
|
47904
47958
|
return [...pathSegments, qp2.toString()].join("?");
|
|
47905
47959
|
}
|
|
47906
|
-
function matchKey(mockDispatch2, { path:
|
|
47907
|
-
const pathMatch = matchValue(mockDispatch2.path,
|
|
47960
|
+
function matchKey(mockDispatch2, { path: path52, method, body, headers }) {
|
|
47961
|
+
const pathMatch = matchValue(mockDispatch2.path, path52);
|
|
47908
47962
|
const methodMatch = matchValue(mockDispatch2.method, method);
|
|
47909
47963
|
const bodyMatch = typeof mockDispatch2.body !== "undefined" ? matchValue(mockDispatch2.body, body) : true;
|
|
47910
47964
|
const headersMatch = matchHeaders(mockDispatch2, headers);
|
|
@@ -47929,8 +47983,8 @@ var require_mock_utils = __commonJS({
|
|
|
47929
47983
|
const basePath = key.query ? serializePathWithQuery(key.path, key.query) : key.path;
|
|
47930
47984
|
const resolvedPath = typeof basePath === "string" ? safeUrl(basePath) : basePath;
|
|
47931
47985
|
const resolvedPathWithoutTrailingSlash = removeTrailingSlash(resolvedPath);
|
|
47932
|
-
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path:
|
|
47933
|
-
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(
|
|
47986
|
+
let matchedMockDispatches = mockDispatches.filter(({ consumed }) => !consumed).filter(({ path: path52, ignoreTrailingSlash }) => {
|
|
47987
|
+
return ignoreTrailingSlash ? matchValue(removeTrailingSlash(safeUrl(path52)), resolvedPathWithoutTrailingSlash) : matchValue(safeUrl(path52), resolvedPath);
|
|
47934
47988
|
});
|
|
47935
47989
|
if (matchedMockDispatches.length === 0) {
|
|
47936
47990
|
throw new MockNotMatchedError(`Mock dispatch not matched for path '${resolvedPath}'`);
|
|
@@ -47969,19 +48023,19 @@ var require_mock_utils = __commonJS({
|
|
|
47969
48023
|
mockDispatches.splice(index, 1);
|
|
47970
48024
|
}
|
|
47971
48025
|
}
|
|
47972
|
-
function removeTrailingSlash(
|
|
47973
|
-
while (
|
|
47974
|
-
|
|
48026
|
+
function removeTrailingSlash(path52) {
|
|
48027
|
+
while (path52.endsWith("/")) {
|
|
48028
|
+
path52 = path52.slice(0, -1);
|
|
47975
48029
|
}
|
|
47976
|
-
if (
|
|
47977
|
-
|
|
48030
|
+
if (path52.length === 0) {
|
|
48031
|
+
path52 = "/";
|
|
47978
48032
|
}
|
|
47979
|
-
return
|
|
48033
|
+
return path52;
|
|
47980
48034
|
}
|
|
47981
48035
|
function buildKey(opts) {
|
|
47982
|
-
const { path:
|
|
48036
|
+
const { path: path52, method, body, headers, query } = opts;
|
|
47983
48037
|
return {
|
|
47984
|
-
path:
|
|
48038
|
+
path: path52,
|
|
47985
48039
|
method,
|
|
47986
48040
|
body,
|
|
47987
48041
|
headers,
|
|
@@ -48671,10 +48725,10 @@ var require_pending_interceptors_formatter = __commonJS({
|
|
|
48671
48725
|
}
|
|
48672
48726
|
format(pendingInterceptors) {
|
|
48673
48727
|
const withPrettyHeaders = pendingInterceptors.map(
|
|
48674
|
-
({ method, path:
|
|
48728
|
+
({ method, path: path52, data: { statusCode }, persist, times, timesInvoked, origin }) => ({
|
|
48675
48729
|
Method: method,
|
|
48676
48730
|
Origin: origin,
|
|
48677
|
-
Path:
|
|
48731
|
+
Path: path52,
|
|
48678
48732
|
"Status code": statusCode,
|
|
48679
48733
|
Persistent: persist ? PERSISTENT : NOT_PERSISTENT,
|
|
48680
48734
|
Invocations: timesInvoked,
|
|
@@ -48756,9 +48810,9 @@ var require_mock_agent = __commonJS({
|
|
|
48756
48810
|
const acceptNonStandardSearchParameters = this[kMockAgentAcceptsNonStandardSearchParameters];
|
|
48757
48811
|
const dispatchOpts = { ...opts };
|
|
48758
48812
|
if (acceptNonStandardSearchParameters && dispatchOpts.path) {
|
|
48759
|
-
const [
|
|
48813
|
+
const [path52, searchParams] = dispatchOpts.path.split("?");
|
|
48760
48814
|
const normalizedSearchParams = normalizeSearchParams(searchParams, acceptNonStandardSearchParameters);
|
|
48761
|
-
dispatchOpts.path = `${
|
|
48815
|
+
dispatchOpts.path = `${path52}?${normalizedSearchParams}`;
|
|
48762
48816
|
}
|
|
48763
48817
|
return this[kAgent].dispatch(dispatchOpts, handler);
|
|
48764
48818
|
}
|
|
@@ -49159,12 +49213,12 @@ var require_snapshot_recorder = __commonJS({
|
|
|
49159
49213
|
* @return {Promise<void>} - Resolves when snapshots are loaded
|
|
49160
49214
|
*/
|
|
49161
49215
|
async loadSnapshots(filePath) {
|
|
49162
|
-
const
|
|
49163
|
-
if (!
|
|
49216
|
+
const path52 = filePath || this.#snapshotPath;
|
|
49217
|
+
if (!path52) {
|
|
49164
49218
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
49165
49219
|
}
|
|
49166
49220
|
try {
|
|
49167
|
-
const data = await readFile(resolve2(
|
|
49221
|
+
const data = await readFile(resolve2(path52), "utf8");
|
|
49168
49222
|
const parsed = JSON.parse(data);
|
|
49169
49223
|
if (Array.isArray(parsed)) {
|
|
49170
49224
|
this.#snapshots.clear();
|
|
@@ -49178,7 +49232,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
49178
49232
|
if (error63.code === "ENOENT") {
|
|
49179
49233
|
this.#snapshots.clear();
|
|
49180
49234
|
} else {
|
|
49181
|
-
throw new UndiciError(`Failed to load snapshots from ${
|
|
49235
|
+
throw new UndiciError(`Failed to load snapshots from ${path52}`, { cause: error63 });
|
|
49182
49236
|
}
|
|
49183
49237
|
}
|
|
49184
49238
|
}
|
|
@@ -49189,11 +49243,11 @@ var require_snapshot_recorder = __commonJS({
|
|
|
49189
49243
|
* @returns {Promise<void>} - Resolves when snapshots are saved
|
|
49190
49244
|
*/
|
|
49191
49245
|
async saveSnapshots(filePath) {
|
|
49192
|
-
const
|
|
49193
|
-
if (!
|
|
49246
|
+
const path52 = filePath || this.#snapshotPath;
|
|
49247
|
+
if (!path52) {
|
|
49194
49248
|
throw new InvalidArgumentError2("Snapshot path is required");
|
|
49195
49249
|
}
|
|
49196
|
-
const resolvedPath = resolve2(
|
|
49250
|
+
const resolvedPath = resolve2(path52);
|
|
49197
49251
|
await mkdir(dirname3(resolvedPath), { recursive: true });
|
|
49198
49252
|
const data = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
|
|
49199
49253
|
hash: hash2,
|
|
@@ -49825,15 +49879,15 @@ var require_redirect_handler = __commonJS({
|
|
|
49825
49879
|
return;
|
|
49826
49880
|
}
|
|
49827
49881
|
const { origin, pathname, search } = util2.parseURL(new URL(this.location, this.opts.origin && new URL(this.opts.path, this.opts.origin)));
|
|
49828
|
-
const
|
|
49829
|
-
const redirectUrlString = `${origin}${
|
|
49882
|
+
const path52 = search ? `${pathname}${search}` : pathname;
|
|
49883
|
+
const redirectUrlString = `${origin}${path52}`;
|
|
49830
49884
|
for (const historyUrl of this.history) {
|
|
49831
49885
|
if (historyUrl.toString() === redirectUrlString) {
|
|
49832
49886
|
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.`);
|
|
49833
49887
|
}
|
|
49834
49888
|
}
|
|
49835
49889
|
this.opts.headers = cleanRequestHeaders(this.opts.headers, statusCode === 303, this.opts.origin !== origin);
|
|
49836
|
-
this.opts.path =
|
|
49890
|
+
this.opts.path = path52;
|
|
49837
49891
|
this.opts.origin = origin;
|
|
49838
49892
|
this.opts.query = null;
|
|
49839
49893
|
}
|
|
@@ -51593,10 +51647,10 @@ var require_cache_handler = __commonJS({
|
|
|
51593
51647
|
}
|
|
51594
51648
|
return locationUrl.pathname + locationUrl.search;
|
|
51595
51649
|
}
|
|
51596
|
-
function deleteCachedUri(store, cacheKey,
|
|
51650
|
+
function deleteCachedUri(store, cacheKey, path52) {
|
|
51597
51651
|
deleteCachedValue(store, {
|
|
51598
51652
|
...cacheKey,
|
|
51599
|
-
path:
|
|
51653
|
+
path: path52
|
|
51600
51654
|
});
|
|
51601
51655
|
for (let i10 = 0; i10 < util2.safeHTTPMethods.length; i10++) {
|
|
51602
51656
|
const method = util2.safeHTTPMethods[i10];
|
|
@@ -51604,7 +51658,7 @@ var require_cache_handler = __commonJS({
|
|
|
51604
51658
|
deleteCachedValue(store, {
|
|
51605
51659
|
...cacheKey,
|
|
51606
51660
|
method,
|
|
51607
|
-
path:
|
|
51661
|
+
path: path52
|
|
51608
51662
|
});
|
|
51609
51663
|
}
|
|
51610
51664
|
}
|
|
@@ -51615,9 +51669,9 @@ var require_cache_handler = __commonJS({
|
|
|
51615
51669
|
}
|
|
51616
51670
|
const values = Array.isArray(headerValue2) ? headerValue2 : [headerValue2];
|
|
51617
51671
|
for (let i10 = 0; i10 < values.length; i10++) {
|
|
51618
|
-
const
|
|
51619
|
-
if (
|
|
51620
|
-
deleteCachedUri(store, cacheKey,
|
|
51672
|
+
const path52 = getSameOriginPath(cacheKey, values[i10]);
|
|
51673
|
+
if (path52 !== void 0) {
|
|
51674
|
+
deleteCachedUri(store, cacheKey, path52);
|
|
51621
51675
|
}
|
|
51622
51676
|
}
|
|
51623
51677
|
}
|
|
@@ -56617,11 +56671,11 @@ var require_fetch = __commonJS({
|
|
|
56617
56671
|
function dispatch({ body }) {
|
|
56618
56672
|
const url2 = requestCurrentURL(request7);
|
|
56619
56673
|
const agent = fetchParams.controller.dispatcher;
|
|
56620
|
-
const
|
|
56674
|
+
const path52 = url2.pathname + url2.search;
|
|
56621
56675
|
const hasTrailingQuestionMark = url2.search.length === 0 && url2.href[url2.href.length - url2.hash.length - 1] === "?";
|
|
56622
56676
|
return new Promise((resolve2, reject) => agent.dispatch(
|
|
56623
56677
|
{
|
|
56624
|
-
path: hasTrailingQuestionMark ? `${
|
|
56678
|
+
path: hasTrailingQuestionMark ? `${path52}?` : path52,
|
|
56625
56679
|
origin: url2.origin,
|
|
56626
56680
|
method: request7.method,
|
|
56627
56681
|
body: agent.isMockActive ? request7.body && (request7.body.source || request7.body.stream) : body,
|
|
@@ -57568,9 +57622,9 @@ var require_util5 = __commonJS({
|
|
|
57568
57622
|
}
|
|
57569
57623
|
}
|
|
57570
57624
|
}
|
|
57571
|
-
function validateCookiePath(
|
|
57572
|
-
for (let i10 = 0; i10 <
|
|
57573
|
-
const code =
|
|
57625
|
+
function validateCookiePath(path52) {
|
|
57626
|
+
for (let i10 = 0; i10 < path52.length; ++i10) {
|
|
57627
|
+
const code = path52.charCodeAt(i10);
|
|
57574
57628
|
if (code < 32 || // exclude CTLs (0-31)
|
|
57575
57629
|
code > 126 || // exclude DEL and non-ascii
|
|
57576
57630
|
code === 59) {
|
|
@@ -60918,11 +60972,11 @@ var require_undici = __commonJS({
|
|
|
60918
60972
|
if (typeof opts.path !== "string") {
|
|
60919
60973
|
throw new InvalidArgumentError2("invalid opts.path");
|
|
60920
60974
|
}
|
|
60921
|
-
let
|
|
60975
|
+
let path52 = opts.path;
|
|
60922
60976
|
if (!opts.path.startsWith("/")) {
|
|
60923
|
-
|
|
60977
|
+
path52 = `/${path52}`;
|
|
60924
60978
|
}
|
|
60925
|
-
url2 = new URL(util2.parseOrigin(url2).origin +
|
|
60979
|
+
url2 = new URL(util2.parseOrigin(url2).origin + path52);
|
|
60926
60980
|
} else {
|
|
60927
60981
|
if (!opts) {
|
|
60928
60982
|
opts = typeof url2 === "object" ? url2 : {};
|
|
@@ -61072,7 +61126,7 @@ function ensureFrontDoor(params) {
|
|
|
61072
61126
|
}
|
|
61073
61127
|
if (verdict.ok) {
|
|
61074
61128
|
const token = (0, import_node_crypto10.randomUUID)();
|
|
61075
|
-
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token });
|
|
61129
|
+
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid });
|
|
61076
61130
|
return { port: state.port, connectPort: state.connectPort, token };
|
|
61077
61131
|
}
|
|
61078
61132
|
lastRejection = `the listener on 127.0.0.1:${String(state.port)} (recorded for pid ${String(supervisorPid)}) failed authentication: ${verdict.reason}`;
|
|
@@ -62153,7 +62207,12 @@ function resolvePoolLaunch(params) {
|
|
|
62153
62207
|
if (graph.ranking.candidates.length === 0) {
|
|
62154
62208
|
return { ok: false, message: `agent-shim: no member of pool "${poolName}" is an existing identity.` };
|
|
62155
62209
|
}
|
|
62156
|
-
const { pick: pick2, earliestReturn, movedOff } = graph.ranking;
|
|
62210
|
+
const { pick: pick2, earliestReturn, movedOff, planReturn } = graph.ranking;
|
|
62211
|
+
if (pick2 !== void 0 && params.wait && planReturn !== void 0) {
|
|
62212
|
+
log.info(`agent-shim: pool "${poolName}" would continue ${planReturn.identity} on extra usage; waiting until ${new Date(planReturn.atMs).toISOString()} for its plan window`);
|
|
62213
|
+
params.sleep(Math.max(planReturn.atMs - nowMs, 0));
|
|
62214
|
+
continue;
|
|
62215
|
+
}
|
|
62157
62216
|
if (pick2 !== void 0) {
|
|
62158
62217
|
if (params.recordPick) {
|
|
62159
62218
|
recordStickyPick(params.usageFs, params.paths.usagePicksFile, params.cwd, pick2.identity, nowMs);
|
|
@@ -62832,6 +62891,57 @@ var init_launchWiring = __esm({
|
|
|
62832
62891
|
}
|
|
62833
62892
|
});
|
|
62834
62893
|
|
|
62894
|
+
// src/usage/identityClaude.ts
|
|
62895
|
+
function definedEnvironment(env) {
|
|
62896
|
+
return Object.fromEntries(Object.entries(env).flatMap(([name, value2]) => value2 === void 0 ? [] : [[name, value2]]));
|
|
62897
|
+
}
|
|
62898
|
+
function identityLaunchArgv(identity, flags) {
|
|
62899
|
+
return [`@${identity}`, IDENTITY_ONLY_FLAG, ...flags];
|
|
62900
|
+
}
|
|
62901
|
+
async function withIdentityClaude(params, identity, flags, use2) {
|
|
62902
|
+
const refusals = [];
|
|
62903
|
+
const plan = prepareLaunch(
|
|
62904
|
+
realPrepareLaunchParams(params.paths, {
|
|
62905
|
+
proc: {
|
|
62906
|
+
env: Object.fromEntries(Object.entries(process.env).filter(([name]) => name !== CONFIG_DIR_VARIABLE)),
|
|
62907
|
+
argv: [...identityLaunchArgv(identity, flags)],
|
|
62908
|
+
exit: (code) => {
|
|
62909
|
+
throw new LaunchRefusedError(refusals.join("\n") || `the launch was refused (exit ${String(code)})`, code);
|
|
62910
|
+
}
|
|
62911
|
+
},
|
|
62912
|
+
log: {
|
|
62913
|
+
info: () => void 0,
|
|
62914
|
+
warn: () => void 0,
|
|
62915
|
+
error: (message) => {
|
|
62916
|
+
refusals.push(message);
|
|
62917
|
+
}
|
|
62918
|
+
},
|
|
62919
|
+
spawnDaemon: params.spawnDaemon,
|
|
62920
|
+
farm: buildFarmRuntime(params.paths, params.cwd)
|
|
62921
|
+
})
|
|
62922
|
+
);
|
|
62923
|
+
const abort = new AbortController();
|
|
62924
|
+
const timer = setTimeout(() => {
|
|
62925
|
+
abort.abort();
|
|
62926
|
+
}, params.timeoutMs);
|
|
62927
|
+
try {
|
|
62928
|
+
return await use2({ bin: plan.bin, env: definedEnvironment(plan.env), cwd: params.cwd, abort });
|
|
62929
|
+
} finally {
|
|
62930
|
+
clearTimeout(timer);
|
|
62931
|
+
plan.release();
|
|
62932
|
+
}
|
|
62933
|
+
}
|
|
62934
|
+
var CONFIG_DIR_VARIABLE, IDENTITY_ONLY_FLAG;
|
|
62935
|
+
var init_identityClaude = __esm({
|
|
62936
|
+
"src/usage/identityClaude.ts"() {
|
|
62937
|
+
"use strict";
|
|
62938
|
+
init_launchWiring();
|
|
62939
|
+
init_launcher();
|
|
62940
|
+
CONFIG_DIR_VARIABLE = "CLAUDE_CONFIG_DIR";
|
|
62941
|
+
IDENTITY_ONLY_FLAG = "--no-provider";
|
|
62942
|
+
}
|
|
62943
|
+
});
|
|
62944
|
+
|
|
62835
62945
|
// src/usage/providerQuota.ts
|
|
62836
62946
|
function zaiWindow(limit) {
|
|
62837
62947
|
const unitMs = ZAI_UNIT_MS.get(limit.unit);
|
|
@@ -62866,7 +62976,7 @@ async function openRouterGet(url2, schema, apiKey, http8, signal) {
|
|
|
62866
62976
|
return parsed.data;
|
|
62867
62977
|
}
|
|
62868
62978
|
function nextUtcMidnight(nowMs) {
|
|
62869
|
-
return new Date((Math.floor(nowMs /
|
|
62979
|
+
return new Date((Math.floor(nowMs / MS_PER_DAY2) + 1) * MS_PER_DAY2).toISOString();
|
|
62870
62980
|
}
|
|
62871
62981
|
function adapterFor(baseUrl) {
|
|
62872
62982
|
return PROVIDER_QUOTA_ADAPTERS.find((adapter) => adapter.matches(baseUrl));
|
|
@@ -62875,7 +62985,7 @@ function quotaFreshnessMs(quota) {
|
|
|
62875
62985
|
const lengths = quota.windows.flatMap((window) => window.periodMs === void 0 ? [] : [window.periodMs]);
|
|
62876
62986
|
return lengths.length === 0 ? Number.POSITIVE_INFINITY : Math.min(...lengths) / PERCENT3;
|
|
62877
62987
|
}
|
|
62878
|
-
var ProviderQuotaError,
|
|
62988
|
+
var ProviderQuotaError, MS_PER_SECOND6, SECONDS_PER_HOUR, HOURS_PER_DAY3, DAYS_PER_MONTH, PERCENT3, HTTP_OK, ZAI_SOURCE, ZAI_HOST, ZAI_QUOTA_URL, ZAI_UNIT_HOURS, ZAI_UNIT_MONTHS, ZAI_UNIT_MS, ZAI_MEASURES, ZaiLimitSchema, ZaiResponseSchema, zaiQuotaAdapter, OPENROUTER_SOURCE, OPENROUTER_HOST, OPENROUTER_KEY_URL, OPENROUTER_CREDITS_URL, HTTP_FORBIDDEN, MS_PER_DAY2, OpenRouterKeySchema, OpenRouterCreditsSchema, openRouterQuotaAdapter, PROVIDER_QUOTA_ADAPTERS;
|
|
62879
62989
|
var init_providerQuota = __esm({
|
|
62880
62990
|
"src/usage/providerQuota.ts"() {
|
|
62881
62991
|
"use strict";
|
|
@@ -62887,7 +62997,7 @@ var init_providerQuota = __esm({
|
|
|
62887
62997
|
this.name = "ProviderQuotaError";
|
|
62888
62998
|
}
|
|
62889
62999
|
};
|
|
62890
|
-
|
|
63000
|
+
MS_PER_SECOND6 = 1e3;
|
|
62891
63001
|
SECONDS_PER_HOUR = 3600;
|
|
62892
63002
|
HOURS_PER_DAY3 = 24;
|
|
62893
63003
|
DAYS_PER_MONTH = 30;
|
|
@@ -62899,8 +63009,8 @@ var init_providerQuota = __esm({
|
|
|
62899
63009
|
ZAI_UNIT_HOURS = 3;
|
|
62900
63010
|
ZAI_UNIT_MONTHS = 5;
|
|
62901
63011
|
ZAI_UNIT_MS = /* @__PURE__ */ new Map([
|
|
62902
|
-
[ZAI_UNIT_HOURS, SECONDS_PER_HOUR *
|
|
62903
|
-
[ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY3 * SECONDS_PER_HOUR *
|
|
63012
|
+
[ZAI_UNIT_HOURS, SECONDS_PER_HOUR * MS_PER_SECOND6],
|
|
63013
|
+
[ZAI_UNIT_MONTHS, DAYS_PER_MONTH * HOURS_PER_DAY3 * SECONDS_PER_HOUR * MS_PER_SECOND6]
|
|
62904
63014
|
]);
|
|
62905
63015
|
ZAI_MEASURES = { TOKENS_LIMIT: "tokens", TIME_LIMIT: "tool-calls" };
|
|
62906
63016
|
ZaiLimitSchema = external_exports.object({
|
|
@@ -62952,7 +63062,7 @@ var init_providerQuota = __esm({
|
|
|
62952
63062
|
OPENROUTER_KEY_URL = `https://${OPENROUTER_HOST}/api/v1/key`;
|
|
62953
63063
|
OPENROUTER_CREDITS_URL = `https://${OPENROUTER_HOST}/api/v1/credits`;
|
|
62954
63064
|
HTTP_FORBIDDEN = 403;
|
|
62955
|
-
|
|
63065
|
+
MS_PER_DAY2 = HOURS_PER_DAY3 * SECONDS_PER_HOUR * MS_PER_SECOND6;
|
|
62956
63066
|
OpenRouterKeySchema = external_exports.object({
|
|
62957
63067
|
data: external_exports.object({
|
|
62958
63068
|
limit: external_exports.number().nonnegative().nullable(),
|
|
@@ -62983,7 +63093,7 @@ var init_providerQuota = __esm({
|
|
|
62983
63093
|
windows.push({ measures: "account-credits", period: "prepaid", utilization: used / total, limit: total, used, remaining: Math.max(total - used, 0) });
|
|
62984
63094
|
}
|
|
62985
63095
|
if (free !== void 0 && free.limit > 0) {
|
|
62986
|
-
windows.push({ measures: "free-model-requests", periodMs:
|
|
63096
|
+
windows.push({ measures: "free-model-requests", periodMs: MS_PER_DAY2, utilization: free.used / free.limit, resetsAt: nextUtcMidnight(nowMs), limit: free.limit, used: free.used, remaining: Math.max(free.remaining, 0) });
|
|
62987
63097
|
}
|
|
62988
63098
|
return ProviderQuotaSchema.parse({
|
|
62989
63099
|
observedAt: new Date(nowMs).toISOString(),
|
|
@@ -96575,9 +96685,6 @@ var realAnthropicUsageProbe_exports = {};
|
|
|
96575
96685
|
__export(realAnthropicUsageProbe_exports, {
|
|
96576
96686
|
createRealAnthropicUsageRefresher: () => createRealAnthropicUsageRefresher
|
|
96577
96687
|
});
|
|
96578
|
-
function definedEnvironment(env) {
|
|
96579
|
-
return Object.fromEntries(Object.entries(env).flatMap(([name, value2]) => value2 === void 0 ? [] : [[name, value2]]));
|
|
96580
|
-
}
|
|
96581
96688
|
function idlePrompt(signal) {
|
|
96582
96689
|
return {
|
|
96583
96690
|
[Symbol.asyncIterator]: () => ({
|
|
@@ -96590,58 +96697,28 @@ function idlePrompt(signal) {
|
|
|
96590
96697
|
};
|
|
96591
96698
|
}
|
|
96592
96699
|
function createRealAnthropicUsageProbe(params) {
|
|
96593
|
-
return async (identity) => {
|
|
96594
|
-
const refusals = [];
|
|
96595
|
-
const plan = prepareLaunch(
|
|
96596
|
-
realPrepareLaunchParams(params.paths, {
|
|
96597
|
-
proc: {
|
|
96598
|
-
env: Object.fromEntries(Object.entries(process.env).filter(([name]) => name !== CONFIG_DIR_VARIABLE)),
|
|
96599
|
-
argv: [`@${identity}`, ...PROBE_LAUNCH_FLAGS],
|
|
96600
|
-
exit: (code) => {
|
|
96601
|
-
throw new LaunchRefusedError(refusals.join("\n") || `the launch was refused (exit ${String(code)})`, code);
|
|
96602
|
-
}
|
|
96603
|
-
},
|
|
96604
|
-
log: {
|
|
96605
|
-
info: () => void 0,
|
|
96606
|
-
warn: () => void 0,
|
|
96607
|
-
error: (message) => {
|
|
96608
|
-
refusals.push(message);
|
|
96609
|
-
}
|
|
96610
|
-
},
|
|
96611
|
-
spawnDaemon: params.spawnDaemon,
|
|
96612
|
-
farm: buildFarmRuntime(params.paths, params.cwd)
|
|
96613
|
-
})
|
|
96614
|
-
);
|
|
96700
|
+
return async (identity) => await withIdentityClaude(params, identity, PROBE_LAUNCH_FLAGS, async ({ bin, env, cwd, abort }) => {
|
|
96615
96701
|
const { query } = await Promise.resolve().then(() => (init_sdk(), sdk_exports));
|
|
96616
|
-
const
|
|
96617
|
-
|
|
96618
|
-
|
|
96619
|
-
|
|
96620
|
-
|
|
96621
|
-
|
|
96622
|
-
|
|
96623
|
-
|
|
96624
|
-
|
|
96625
|
-
|
|
96626
|
-
|
|
96627
|
-
abortController: abort,
|
|
96628
|
-
settingSources: [],
|
|
96629
|
-
mcpServers: {},
|
|
96630
|
-
strictMcpConfig: true,
|
|
96631
|
-
persistSession: false
|
|
96632
|
-
}
|
|
96633
|
-
});
|
|
96634
|
-
try {
|
|
96635
|
-
const report = await session.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true });
|
|
96636
|
-
return unifiedFromReportedLimits(report.rate_limits_available ? report.rate_limits : null);
|
|
96637
|
-
} finally {
|
|
96638
|
-
session.close();
|
|
96702
|
+
const session = query({
|
|
96703
|
+
prompt: idlePrompt(abort.signal),
|
|
96704
|
+
options: {
|
|
96705
|
+
pathToClaudeCodeExecutable: bin,
|
|
96706
|
+
env,
|
|
96707
|
+
cwd,
|
|
96708
|
+
abortController: abort,
|
|
96709
|
+
settingSources: [],
|
|
96710
|
+
mcpServers: {},
|
|
96711
|
+
strictMcpConfig: true,
|
|
96712
|
+
persistSession: false
|
|
96639
96713
|
}
|
|
96714
|
+
});
|
|
96715
|
+
try {
|
|
96716
|
+
const report = await session.usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET({ skipBehaviors: true });
|
|
96717
|
+
return unifiedFromReportedLimits(report.rate_limits_available ? report.rate_limits : null);
|
|
96640
96718
|
} finally {
|
|
96641
|
-
|
|
96642
|
-
plan.release();
|
|
96719
|
+
session.close();
|
|
96643
96720
|
}
|
|
96644
|
-
};
|
|
96721
|
+
});
|
|
96645
96722
|
}
|
|
96646
96723
|
function createRealAnthropicUsageRefresher(params) {
|
|
96647
96724
|
return createAnthropicUsageRefresher({
|
|
@@ -96654,18 +96731,16 @@ function createRealAnthropicUsageRefresher(params) {
|
|
|
96654
96731
|
concurrency: (0, import_node_os11.availableParallelism)()
|
|
96655
96732
|
});
|
|
96656
96733
|
}
|
|
96657
|
-
var import_node_os11, PROBE_LAUNCH_FLAGS
|
|
96734
|
+
var import_node_os11, PROBE_LAUNCH_FLAGS;
|
|
96658
96735
|
var init_realAnthropicUsageProbe = __esm({
|
|
96659
96736
|
"src/usage/realAnthropicUsageProbe.ts"() {
|
|
96660
96737
|
"use strict";
|
|
96661
96738
|
import_node_os11 = require("node:os");
|
|
96662
|
-
init_launchWiring();
|
|
96663
|
-
init_launcher();
|
|
96664
96739
|
init_anthropicUsageRefresh();
|
|
96740
|
+
init_identityClaude();
|
|
96665
96741
|
init_middleware();
|
|
96666
96742
|
init_quotaRefresh();
|
|
96667
96743
|
PROBE_LAUNCH_FLAGS = ["--no-headroom", "--no-remote-control"];
|
|
96668
|
-
CONFIG_DIR_VARIABLE = "CLAUDE_CONFIG_DIR";
|
|
96669
96744
|
}
|
|
96670
96745
|
});
|
|
96671
96746
|
|
|
@@ -99898,8 +99973,8 @@ var require_utils3 = __commonJS({
|
|
|
99898
99973
|
}
|
|
99899
99974
|
return ind;
|
|
99900
99975
|
}
|
|
99901
|
-
function removeDotSegments(
|
|
99902
|
-
let input2 =
|
|
99976
|
+
function removeDotSegments(path52) {
|
|
99977
|
+
let input2 = path52;
|
|
99903
99978
|
const output2 = [];
|
|
99904
99979
|
let nextSlash = -1;
|
|
99905
99980
|
let len = 0;
|
|
@@ -100308,8 +100383,8 @@ var require_schemes = __commonJS({
|
|
|
100308
100383
|
}
|
|
100309
100384
|
if (wsComponent.resourceName) {
|
|
100310
100385
|
const queryIndex = wsComponent.resourceName.indexOf("?");
|
|
100311
|
-
const
|
|
100312
|
-
wsComponent.path =
|
|
100386
|
+
const path52 = queryIndex === -1 ? wsComponent.resourceName : wsComponent.resourceName.slice(0, queryIndex);
|
|
100387
|
+
wsComponent.path = path52 && path52 !== "/" ? path52 : void 0;
|
|
100313
100388
|
wsComponent.query = queryIndex === -1 ? void 0 : wsComponent.resourceName.slice(queryIndex + 1);
|
|
100314
100389
|
wsComponent.resourceName = void 0;
|
|
100315
100390
|
}
|
|
@@ -103836,7 +103911,7 @@ var require_dist2 = __commonJS({
|
|
|
103836
103911
|
});
|
|
103837
103912
|
|
|
103838
103913
|
// src/cli.ts
|
|
103839
|
-
var
|
|
103914
|
+
var import_node_path51 = __toESM(require("node:path"), 1);
|
|
103840
103915
|
|
|
103841
103916
|
// node_modules/.pnpm/commander@15.0.0/node_modules/commander/lib/error.js
|
|
103842
103917
|
var CommanderError = class extends Error {
|
|
@@ -106949,9 +107024,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
106949
107024
|
* @param {string} [path]
|
|
106950
107025
|
* @return {(string|null|Command)}
|
|
106951
107026
|
*/
|
|
106952
|
-
executableDir(
|
|
106953
|
-
if (
|
|
106954
|
-
this._executableDir =
|
|
107027
|
+
executableDir(path52) {
|
|
107028
|
+
if (path52 === void 0) return this._executableDir;
|
|
107029
|
+
this._executableDir = path52;
|
|
106955
107030
|
return this;
|
|
106956
107031
|
}
|
|
106957
107032
|
/**
|
|
@@ -108600,19 +108675,19 @@ function writePools(paths, pools) {
|
|
|
108600
108675
|
applyPatch(paths.globalConfigFile, GlobalConfigSchema, { pools }, { defaults: {} });
|
|
108601
108676
|
}
|
|
108602
108677
|
function poolCycleOf(pools, name) {
|
|
108603
|
-
const walk = (current,
|
|
108678
|
+
const walk = (current, path52) => {
|
|
108604
108679
|
for (const entry of pools[current]?.identities ?? []) {
|
|
108605
108680
|
const nested = poolNameOf(poolMemberIdentity(entry));
|
|
108606
108681
|
if (nested === void 0) {
|
|
108607
108682
|
continue;
|
|
108608
108683
|
}
|
|
108609
108684
|
if (nested === name) {
|
|
108610
|
-
return [...
|
|
108685
|
+
return [...path52, nested];
|
|
108611
108686
|
}
|
|
108612
|
-
if (
|
|
108687
|
+
if (path52.includes(nested)) {
|
|
108613
108688
|
continue;
|
|
108614
108689
|
}
|
|
108615
|
-
const found = walk(nested, [...
|
|
108690
|
+
const found = walk(nested, [...path52, nested]);
|
|
108616
108691
|
if (found !== void 0) {
|
|
108617
108692
|
return found;
|
|
108618
108693
|
}
|
|
@@ -108763,6 +108838,18 @@ function listIdentities(paths) {
|
|
|
108763
108838
|
}
|
|
108764
108839
|
return result;
|
|
108765
108840
|
}
|
|
108841
|
+
function listAnchoredIdentities(paths) {
|
|
108842
|
+
return listIdentities(paths).flatMap(({ name }) => {
|
|
108843
|
+
const anchors = readIdentity(paths, name)?.anchors;
|
|
108844
|
+
return anchors === void 0 ? [] : [{ identity: name, anchors }];
|
|
108845
|
+
});
|
|
108846
|
+
}
|
|
108847
|
+
function setIdentityAnchors(paths, identityName, anchors) {
|
|
108848
|
+
if (!identityExists(paths, identityName)) {
|
|
108849
|
+
throw new IdentityNotFoundError(identityName);
|
|
108850
|
+
}
|
|
108851
|
+
return applyPatch(identityJsonPath(paths, identityName), IdentitySchema, { anchors: anchors === void 0 ? void 0 : [...anchors] });
|
|
108852
|
+
}
|
|
108766
108853
|
function setDefaultConfigProfile(paths, identityName, profileName) {
|
|
108767
108854
|
if (!identityExists(paths, identityName)) {
|
|
108768
108855
|
throw new IdentityNotFoundError(identityName);
|
|
@@ -109541,6 +109628,135 @@ function cacheChange(options, existing) {
|
|
|
109541
109628
|
}
|
|
109542
109629
|
}
|
|
109543
109630
|
|
|
109631
|
+
// src/usage/anchor.ts
|
|
109632
|
+
init_schema();
|
|
109633
|
+
var MS_PER_SECOND = 1e3;
|
|
109634
|
+
var MS_PER_MINUTE2 = 6e4;
|
|
109635
|
+
var MINUTES_PER_HOUR = 60;
|
|
109636
|
+
var DAYS_IN_WEEK = 7;
|
|
109637
|
+
var MS_PER_DAY = 864e5;
|
|
109638
|
+
var SEARCH_MARGIN_DAYS = 1;
|
|
109639
|
+
var WORKING_DAYS = 5;
|
|
109640
|
+
var WEEKDAY_SHORTHANDS = { daily: WEEKDAYS, weekdays: WEEKDAYS.slice(0, WORKING_DAYS) };
|
|
109641
|
+
function zoneOffsetMs(utcMs, timeZone) {
|
|
109642
|
+
const wholeSecondMs = Math.floor(utcMs / MS_PER_SECOND) * MS_PER_SECOND;
|
|
109643
|
+
const parts = new Intl.DateTimeFormat("en-GB", { timeZone, hourCycle: "h23", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" }).formatToParts(new Date(wholeSecondMs));
|
|
109644
|
+
const field = (type2) => Number(parts.find((part) => part.type === type2)?.value);
|
|
109645
|
+
return Date.UTC(field("year"), field("month") - 1, field("day"), field("hour"), field("minute"), field("second")) - wholeSecondMs;
|
|
109646
|
+
}
|
|
109647
|
+
function wallTimeToUtcMs(date5, minutesOfDay, timeZone) {
|
|
109648
|
+
const asUtc = Date.UTC(date5.year, date5.month - 1, date5.day) + minutesOfDay * MS_PER_MINUTE2;
|
|
109649
|
+
const candidates = [zoneOffsetMs(asUtc - MS_PER_DAY, timeZone), zoneOffsetMs(asUtc + MS_PER_DAY, timeZone)].map((offset) => ({ offset, instant: asUtc - offset }));
|
|
109650
|
+
const valid = candidates.filter(({ offset, instant }) => zoneOffsetMs(instant, timeZone) === offset).map(({ instant }) => instant);
|
|
109651
|
+
return valid.length === 0 ? asUtc - (candidates[0]?.offset ?? 0) : Math.min(...valid);
|
|
109652
|
+
}
|
|
109653
|
+
function localDate(utcMs, timeZone) {
|
|
109654
|
+
const local = new Date(utcMs + zoneOffsetMs(utcMs, timeZone));
|
|
109655
|
+
return { year: local.getUTCFullYear(), month: local.getUTCMonth() + 1, day: local.getUTCDate() };
|
|
109656
|
+
}
|
|
109657
|
+
function weekdayOf(date5) {
|
|
109658
|
+
const sundayFirst = new Date(Date.UTC(date5.year, date5.month - 1, date5.day)).getUTCDay();
|
|
109659
|
+
const day = WEEKDAYS[(sundayFirst + DAYS_IN_WEEK - 1) % DAYS_IN_WEEK];
|
|
109660
|
+
if (day === void 0) {
|
|
109661
|
+
throw new RangeError(`no weekday for day number ${String(sundayFirst)}`);
|
|
109662
|
+
}
|
|
109663
|
+
return day;
|
|
109664
|
+
}
|
|
109665
|
+
function minutesOfDayOf(time4) {
|
|
109666
|
+
const [hours, minutes] = time4.split(":").map(Number);
|
|
109667
|
+
return (hours ?? 0) * MINUTES_PER_HOUR + (minutes ?? 0);
|
|
109668
|
+
}
|
|
109669
|
+
function anchorInstants(anchors, afterMs, uptoMs, defaultTimeZone) {
|
|
109670
|
+
const instants = anchors.flatMap((anchor2) => {
|
|
109671
|
+
const timeZone = anchor2.timeZone ?? defaultTimeZone;
|
|
109672
|
+
const minutesOfDay = minutesOfDayOf(anchor2.time);
|
|
109673
|
+
const first = localDate(afterMs - SEARCH_MARGIN_DAYS * MS_PER_DAY, timeZone);
|
|
109674
|
+
const found = [];
|
|
109675
|
+
for (let offset = 0; ; offset += 1) {
|
|
109676
|
+
const date5 = localDate(Date.UTC(first.year, first.month - 1, first.day + offset) + MS_PER_DAY / 2, "UTC");
|
|
109677
|
+
const instant = wallTimeToUtcMs(date5, minutesOfDay, timeZone);
|
|
109678
|
+
if (instant > uptoMs + SEARCH_MARGIN_DAYS * MS_PER_DAY) {
|
|
109679
|
+
return found;
|
|
109680
|
+
}
|
|
109681
|
+
if (instant > afterMs && instant <= uptoMs && anchor2.days.includes(weekdayOf(date5))) {
|
|
109682
|
+
found.push(instant);
|
|
109683
|
+
}
|
|
109684
|
+
}
|
|
109685
|
+
});
|
|
109686
|
+
return instants.sort((left, right) => left - right);
|
|
109687
|
+
}
|
|
109688
|
+
function dueAnchor(anchors, nowMs, handledMs, defaultTimeZone) {
|
|
109689
|
+
const since = Math.max(handledMs, nowMs - DAYS_IN_WEEK * MS_PER_DAY);
|
|
109690
|
+
return anchorInstants(anchors, since, nowMs, defaultTimeZone).at(-1);
|
|
109691
|
+
}
|
|
109692
|
+
function parseDayItem(item) {
|
|
109693
|
+
const [from, to2, ...extra] = item.split("-");
|
|
109694
|
+
const index = (name) => WEEKDAYS.findIndex((day) => day === name);
|
|
109695
|
+
if (from === void 0 || extra.length > 0 || index(from) === -1 || to2 !== void 0 && index(to2) === -1) {
|
|
109696
|
+
throw new Error(`"${item}" is not a weekday (${WEEKDAYS.join(", ")}) or a range such as mon-fri`);
|
|
109697
|
+
}
|
|
109698
|
+
if (to2 === void 0) {
|
|
109699
|
+
return [WEEKDAYS[index(from)] ?? "mon"];
|
|
109700
|
+
}
|
|
109701
|
+
const length = (index(to2) - index(from) + DAYS_IN_WEEK) % DAYS_IN_WEEK + 1;
|
|
109702
|
+
return Array.from({ length }, (_, step2) => WEEKDAYS[(index(from) + step2) % DAYS_IN_WEEK] ?? "mon");
|
|
109703
|
+
}
|
|
109704
|
+
function parseAnchor(spec) {
|
|
109705
|
+
const match = /^(?<days>[^@]+)@(?<time>[^/]+)(?:\/(?<zone>.+))?$/.exec(spec);
|
|
109706
|
+
const { days, time: time4, zone } = match?.groups ?? {};
|
|
109707
|
+
if (days === void 0 || time4 === void 0) {
|
|
109708
|
+
throw new Error(`"${spec}" is not an anchor: write <days>@<HH:MM>[/<time zone>], such as mon-fri@06:00 or sat,sun@08:30/Europe/London`);
|
|
109709
|
+
}
|
|
109710
|
+
const named = WEEKDAY_SHORTHANDS[days] ?? days.split(",").flatMap(parseDayItem);
|
|
109711
|
+
const parsed = AnchorSchema.safeParse({ days: [...new Set(named)], time: time4, ...zone === void 0 ? {} : { timeZone: zone } });
|
|
109712
|
+
if (!parsed.success) {
|
|
109713
|
+
throw new Error(`"${spec}" is not an anchor: ${parsed.error.issues.map((issue2) => issue2.message).join("; ")}`);
|
|
109714
|
+
}
|
|
109715
|
+
return parsed.data;
|
|
109716
|
+
}
|
|
109717
|
+
var ANCHOR_SYNTAX = "<days>@<HH:MM>[/<time zone>], where days are daily, weekdays, or weekday names and ranges such as mon,wed or mon-fri, and the zone defaults to the machine's own";
|
|
109718
|
+
function formatAnchor(anchor2) {
|
|
109719
|
+
return `${anchor2.days.join(",")}@${anchor2.time}${anchor2.timeZone === void 0 ? "" : `/${anchor2.timeZone}`}`;
|
|
109720
|
+
}
|
|
109721
|
+
function machineTimeZone() {
|
|
109722
|
+
return new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
109723
|
+
}
|
|
109724
|
+
|
|
109725
|
+
// src/cli/parsers.ts
|
|
109726
|
+
init_conditions();
|
|
109727
|
+
init_pairs();
|
|
109728
|
+
function asInvalidArgument(parse4) {
|
|
109729
|
+
try {
|
|
109730
|
+
return parse4();
|
|
109731
|
+
} catch (error63) {
|
|
109732
|
+
if (error63 instanceof Error && !(error63 instanceof InvalidArgumentError)) {
|
|
109733
|
+
throw new InvalidArgumentError(error63.message);
|
|
109734
|
+
}
|
|
109735
|
+
throw error63;
|
|
109736
|
+
}
|
|
109737
|
+
}
|
|
109738
|
+
function collectBoolPair(value2, previous = {}) {
|
|
109739
|
+
return asInvalidArgument(() => {
|
|
109740
|
+
const { key, value: raw } = parsePair(value2);
|
|
109741
|
+
return { ...previous, [key]: parseBool(raw) };
|
|
109742
|
+
});
|
|
109743
|
+
}
|
|
109744
|
+
function collectStringPair(value2, previous = {}) {
|
|
109745
|
+
return asInvalidArgument(() => {
|
|
109746
|
+
const { key, value: raw } = parsePair(value2);
|
|
109747
|
+
return { ...previous, [key]: raw };
|
|
109748
|
+
});
|
|
109749
|
+
}
|
|
109750
|
+
function collectRepeated(value2, previous = []) {
|
|
109751
|
+
return [...previous, value2];
|
|
109752
|
+
}
|
|
109753
|
+
function collectAnchor(value2, previous = []) {
|
|
109754
|
+
return [...previous, asInvalidArgument(() => parseAnchor(value2))];
|
|
109755
|
+
}
|
|
109756
|
+
function parseDurationOption(value2) {
|
|
109757
|
+
return asInvalidArgument(() => parseDuration(value2));
|
|
109758
|
+
}
|
|
109759
|
+
|
|
109544
109760
|
// src/identityManager.ts
|
|
109545
109761
|
init_classify();
|
|
109546
109762
|
init_schema();
|
|
@@ -109594,40 +109810,6 @@ async function resolveFarmConflicts(params) {
|
|
|
109594
109810
|
|
|
109595
109811
|
// src/configProfiles.ts
|
|
109596
109812
|
init_commandDeps();
|
|
109597
|
-
|
|
109598
|
-
// src/cli/parsers.ts
|
|
109599
|
-
init_conditions();
|
|
109600
|
-
init_pairs();
|
|
109601
|
-
function asInvalidArgument(parse4) {
|
|
109602
|
-
try {
|
|
109603
|
-
return parse4();
|
|
109604
|
-
} catch (error63) {
|
|
109605
|
-
if (error63 instanceof Error && !(error63 instanceof InvalidArgumentError)) {
|
|
109606
|
-
throw new InvalidArgumentError(error63.message);
|
|
109607
|
-
}
|
|
109608
|
-
throw error63;
|
|
109609
|
-
}
|
|
109610
|
-
}
|
|
109611
|
-
function collectBoolPair(value2, previous = {}) {
|
|
109612
|
-
return asInvalidArgument(() => {
|
|
109613
|
-
const { key, value: raw } = parsePair(value2);
|
|
109614
|
-
return { ...previous, [key]: parseBool(raw) };
|
|
109615
|
-
});
|
|
109616
|
-
}
|
|
109617
|
-
function collectStringPair(value2, previous = {}) {
|
|
109618
|
-
return asInvalidArgument(() => {
|
|
109619
|
-
const { key, value: raw } = parsePair(value2);
|
|
109620
|
-
return { ...previous, [key]: raw };
|
|
109621
|
-
});
|
|
109622
|
-
}
|
|
109623
|
-
function collectRepeated(value2, previous = []) {
|
|
109624
|
-
return [...previous, value2];
|
|
109625
|
-
}
|
|
109626
|
-
function parseDurationOption(value2) {
|
|
109627
|
-
return asInvalidArgument(() => parseDuration(value2));
|
|
109628
|
-
}
|
|
109629
|
-
|
|
109630
|
-
// src/configProfiles.ts
|
|
109631
109813
|
init_cliError();
|
|
109632
109814
|
async function ensureProfileExists(deps, name) {
|
|
109633
109815
|
if (profileExists(deps.paths, name)) {
|
|
@@ -109857,7 +110039,8 @@ function toIdentityView(paths, entry) {
|
|
|
109857
110039
|
...entry.problem === void 0 ? {
|
|
109858
110040
|
...entry.identity.defaultConfigProfile === void 0 ? {} : { defaultConfigProfile: entry.identity.defaultConfigProfile },
|
|
109859
110041
|
allowAmbientCredential: entry.identity.allowAmbientCredential,
|
|
109860
|
-
...entry.identity.credential === void 0 ? {} : { credential: summariseCredential(entry.identity.credential) }
|
|
110042
|
+
...entry.identity.credential === void 0 ? {} : { credential: summariseCredential(entry.identity.credential) },
|
|
110043
|
+
...entry.identity.anchors === void 0 ? {} : { anchors: entry.identity.anchors }
|
|
109861
110044
|
} : { problem: entry.problem }
|
|
109862
110045
|
};
|
|
109863
110046
|
}
|
|
@@ -109926,6 +110109,7 @@ function registerIdentityCommand(program2, deps) {
|
|
|
109926
110109
|
console.log(`Default configuration profile: ${view.defaultConfigProfile ?? "(none)"}`);
|
|
109927
110110
|
console.log(`Allows ambient credential: ${view.allowAmbientCredential === true ? "yes" : "no"}`);
|
|
109928
110111
|
console.log(`Credential: ${entry.identity?.credential === void 0 ? "(none; uses its stored login)" : describeCredential(entry.identity.credential)}`);
|
|
110112
|
+
console.log(`Anchors: ${view.anchors === void 0 ? "(none)" : view.anchors.map(formatAnchor).join(" ")}`);
|
|
109929
110113
|
}),
|
|
109930
110114
|
["agent-shim identity show work", "agent-shim identity show work --json"]
|
|
109931
110115
|
);
|
|
@@ -109933,7 +110117,11 @@ function registerIdentityCommand(program2, deps) {
|
|
|
109933
110117
|
"--credential <source>",
|
|
109934
110118
|
`Authenticate this identity from a token instead of its stored login, replacing any existing sources (repeatable, in the order tried): ${CREDENTIAL_SOURCE_SYNTAX}.`,
|
|
109935
110119
|
collectCredentialSource
|
|
109936
|
-
).option("--no-credential", "Remove this identity's credential, returning it to its stored login.").
|
|
110120
|
+
).option("--no-credential", "Remove this identity's credential, returning it to its stored login.").option(
|
|
110121
|
+
"--anchor <spec>",
|
|
110122
|
+
`Have the front door open a five-hour window for this identity at these times when none is open, so its window resets when you want (repeatable, replacing any existing anchors): ${ANCHOR_SYNTAX}.`,
|
|
110123
|
+
collectAnchor
|
|
110124
|
+
).option("--no-anchor", "Remove this identity's anchors.").addOption(
|
|
109937
110125
|
new Option(
|
|
109938
110126
|
"--credential-target <target>",
|
|
109939
110127
|
"Where the token goes: oauthToken sets CLAUDE_CODE_OAUTH_TOKEN (a `claude setup-token` token), bearer sets ANTHROPIC_AUTH_TOKEN (the default), apiKey sets ANTHROPIC_API_KEY."
|
|
@@ -109945,7 +110133,7 @@ function registerIdentityCommand(program2, deps) {
|
|
|
109945
110133
|
const { json: json2, ...options } = allOptions;
|
|
109946
110134
|
if (Object.entries(allOptions).every(([key, value2]) => key === "json" || value2 === void 0)) {
|
|
109947
110135
|
throw new UsageError(
|
|
109948
|
-
"Nothing to change: pass --default-profile, --no-default-profile, --allow-ambient-credential, --no-allow-ambient-credential, --credential, --no-credential, --credential-target or a --credential-cache option."
|
|
110136
|
+
"Nothing to change: pass --default-profile, --no-default-profile, --allow-ambient-credential, --no-allow-ambient-credential, --credential, --no-credential, --credential-target, --anchor, --no-anchor or a --credential-cache option."
|
|
109949
110137
|
);
|
|
109950
110138
|
}
|
|
109951
110139
|
if (!identityExists(paths, name)) {
|
|
@@ -109980,6 +110168,10 @@ function registerIdentityCommand(program2, deps) {
|
|
|
109980
110168
|
messages.push(`Identity "${name}" now authenticates with credential ${describeCredential(updated.credential)}.`);
|
|
109981
110169
|
}
|
|
109982
110170
|
}
|
|
110171
|
+
if (options.anchor !== void 0) {
|
|
110172
|
+
const updated = setIdentityAnchors(paths, name, options.anchor === false ? void 0 : options.anchor);
|
|
110173
|
+
messages.push(updated.anchors === void 0 ? `Identity "${name}" no longer has anchors.` : `Identity "${name}" now has anchors ${updated.anchors.map(formatAnchor).join(" ")}.`);
|
|
110174
|
+
}
|
|
109983
110175
|
reportMutation(json2, { action: "updated", kind: "identity", name, value: readIdentity(paths, name) }, () => {
|
|
109984
110176
|
for (const message of messages) {
|
|
109985
110177
|
console.log(message);
|
|
@@ -109990,7 +110182,9 @@ function registerIdentityCommand(program2, deps) {
|
|
|
109990
110182
|
"agent-shim identity set work --default-profile client-acme",
|
|
109991
110183
|
"agent-shim identity set work --allow-ambient-credential",
|
|
109992
110184
|
"agent-shim identity set work --credential-target oauthToken --credential op:op://vault/claude-work/token",
|
|
109993
|
-
"agent-shim identity set work --no-credential"
|
|
110185
|
+
"agent-shim identity set work --no-credential",
|
|
110186
|
+
"agent-shim identity set work --anchor mon-fri@06:00",
|
|
110187
|
+
"agent-shim identity set work --no-anchor"
|
|
109994
110188
|
]
|
|
109995
110189
|
);
|
|
109996
110190
|
withExamples(
|
|
@@ -110740,7 +110934,7 @@ var SIWC_PLAN_SCOPE = "chatgpt.tokens.use.direct";
|
|
|
110740
110934
|
var SIWC_CALLBACK_PORT = 1455;
|
|
110741
110935
|
var SIWC_CALLBACK_PATH = "/auth/callback";
|
|
110742
110936
|
var SIWC_RANDOM_BYTES = 32;
|
|
110743
|
-
var
|
|
110937
|
+
var MS_PER_SECOND5 = 1e3;
|
|
110744
110938
|
var ID_TOKEN_ALGORITHM = "RS256";
|
|
110745
110939
|
var SiwcError = class extends Error {
|
|
110746
110940
|
constructor(message) {
|
|
@@ -110836,7 +111030,7 @@ function grantTokens(ports, answer) {
|
|
|
110836
111030
|
refreshToken: answer.refresh_token,
|
|
110837
111031
|
idToken: answer.id_token,
|
|
110838
111032
|
scopes: answer.scope === void 0 ? void 0 : answer.scope.split(" ").filter((part) => part !== ""),
|
|
110839
|
-
expiresAt: ports.now().getTime() + answer.expires_in *
|
|
111033
|
+
expiresAt: ports.now().getTime() + answer.expires_in * MS_PER_SECOND5
|
|
110840
111034
|
};
|
|
110841
111035
|
}
|
|
110842
111036
|
async function exchangeCode(ports, request7) {
|
|
@@ -110897,7 +111091,7 @@ async function verifyIdToken(ports, idToken, expected) {
|
|
|
110897
111091
|
if (!(Array.isArray(claims.aud) ? claims.aud : [claims.aud]).includes(expected.clientId)) {
|
|
110898
111092
|
throw new SiwcError("the ID token was issued for a different client");
|
|
110899
111093
|
}
|
|
110900
|
-
if (claims.exp *
|
|
111094
|
+
if (claims.exp * MS_PER_SECOND5 <= ports.now().getTime()) {
|
|
110901
111095
|
throw new SiwcError("the ID token has already expired");
|
|
110902
111096
|
}
|
|
110903
111097
|
if (expected.nonce !== void 0 && claims.nonce !== expected.nonce) {
|
|
@@ -111429,7 +111623,7 @@ function registerCodexCommand(program2, deps) {
|
|
|
111429
111623
|
|
|
111430
111624
|
// src/frontdoor/commands.ts
|
|
111431
111625
|
var import_node_crypto20 = require("node:crypto");
|
|
111432
|
-
var
|
|
111626
|
+
var import_node_path46 = __toESM(require("node:path"), 1);
|
|
111433
111627
|
var import_node_fs16 = __toESM(require("node:fs"), 1);
|
|
111434
111628
|
init_commandDeps();
|
|
111435
111629
|
init_schema();
|
|
@@ -111644,6 +111838,140 @@ async function refreshStalePoolMembers(params) {
|
|
|
111644
111838
|
init_anthropicUsageRefresh();
|
|
111645
111839
|
init_poolPick();
|
|
111646
111840
|
init_realAnthropicUsageProbe();
|
|
111841
|
+
|
|
111842
|
+
// src/usage/realWindowOpener.ts
|
|
111843
|
+
init_identityClaude();
|
|
111844
|
+
var OPENER_LAUNCH_FLAGS = ["--no-headroom", "--no-remote-control", "--track-usage"];
|
|
111845
|
+
var WINDOW_OPENING_MODEL = "haiku";
|
|
111846
|
+
var WINDOW_OPENING_PROMPT = "ok";
|
|
111847
|
+
var WINDOW_OPENING_SYSTEM_PROMPT = "Reply with one word.";
|
|
111848
|
+
var WINDOW_OPEN_TIMEOUT_MS = 6e4;
|
|
111849
|
+
function createRealWindowOpener(params) {
|
|
111850
|
+
return async (identity) => {
|
|
111851
|
+
await withIdentityClaude({ ...params, timeoutMs: WINDOW_OPEN_TIMEOUT_MS }, identity, OPENER_LAUNCH_FLAGS, async ({ bin, env, cwd, abort }) => {
|
|
111852
|
+
const { query } = await Promise.resolve().then(() => (init_sdk(), sdk_exports));
|
|
111853
|
+
const session = query({
|
|
111854
|
+
prompt: WINDOW_OPENING_PROMPT,
|
|
111855
|
+
options: {
|
|
111856
|
+
pathToClaudeCodeExecutable: bin,
|
|
111857
|
+
env,
|
|
111858
|
+
cwd,
|
|
111859
|
+
abortController: abort,
|
|
111860
|
+
settingSources: [],
|
|
111861
|
+
mcpServers: {},
|
|
111862
|
+
strictMcpConfig: true,
|
|
111863
|
+
persistSession: false,
|
|
111864
|
+
model: WINDOW_OPENING_MODEL,
|
|
111865
|
+
maxTurns: 1,
|
|
111866
|
+
tools: [],
|
|
111867
|
+
systemPrompt: WINDOW_OPENING_SYSTEM_PROMPT,
|
|
111868
|
+
thinking: { type: "disabled" }
|
|
111869
|
+
}
|
|
111870
|
+
});
|
|
111871
|
+
try {
|
|
111872
|
+
for await (const message of session) {
|
|
111873
|
+
if (message.type === "result") {
|
|
111874
|
+
if (message.subtype !== "success") {
|
|
111875
|
+
throw new Error(`the opening request ended as ${message.subtype}`);
|
|
111876
|
+
}
|
|
111877
|
+
return;
|
|
111878
|
+
}
|
|
111879
|
+
}
|
|
111880
|
+
throw new Error("the opening request ended without a result");
|
|
111881
|
+
} finally {
|
|
111882
|
+
session.close();
|
|
111883
|
+
}
|
|
111884
|
+
});
|
|
111885
|
+
};
|
|
111886
|
+
}
|
|
111887
|
+
|
|
111888
|
+
// src/usage/windowKeeper.ts
|
|
111889
|
+
var import_node_path38 = __toESM(require("node:path"), 1);
|
|
111890
|
+
init_zod();
|
|
111891
|
+
init_preflight();
|
|
111892
|
+
init_pick();
|
|
111893
|
+
init_middleware();
|
|
111894
|
+
var STAMPS_SCHEMA_VERSION = 1;
|
|
111895
|
+
var StampsFileSchema = external_exports.strictObject({
|
|
111896
|
+
schemaVersion: external_exports.literal(STAMPS_SCHEMA_VERSION),
|
|
111897
|
+
handled: external_exports.record(external_exports.string().min(1), external_exports.iso.datetime())
|
|
111898
|
+
});
|
|
111899
|
+
function readStamps(fs22, file2) {
|
|
111900
|
+
const raw = fs22.readFileUtf8(file2);
|
|
111901
|
+
if (raw === void 0) {
|
|
111902
|
+
return {};
|
|
111903
|
+
}
|
|
111904
|
+
let parsed;
|
|
111905
|
+
try {
|
|
111906
|
+
parsed = JSON.parse(raw);
|
|
111907
|
+
} catch {
|
|
111908
|
+
parsed = void 0;
|
|
111909
|
+
}
|
|
111910
|
+
const result = StampsFileSchema.safeParse(parsed);
|
|
111911
|
+
return result.success ? Object.fromEntries(Object.entries(result.data.handled).map(([identity, at2]) => [identity, Date.parse(at2)])) : {};
|
|
111912
|
+
}
|
|
111913
|
+
function writeStamps(fs22, file2, handled) {
|
|
111914
|
+
const next = { schemaVersion: STAMPS_SCHEMA_VERSION, handled: Object.fromEntries(Object.entries(handled).map(([identity, at2]) => [identity, new Date(at2).toISOString()])) };
|
|
111915
|
+
fs22.mkdirPrivate(import_node_path38.default.dirname(file2));
|
|
111916
|
+
fs22.writeFilePrivate(file2, `${JSON.stringify(next, null, 2)}
|
|
111917
|
+
`);
|
|
111918
|
+
}
|
|
111919
|
+
function reasonNotToOpen(identity, snapshot, nowMs) {
|
|
111920
|
+
if (snapshot === void 0) {
|
|
111921
|
+
return void 0;
|
|
111922
|
+
}
|
|
111923
|
+
const unified = snapshot.providers[ANTHROPIC_PROVIDER]?.rateLimit?.unified;
|
|
111924
|
+
if (unified !== void 0 && unified.fiveHour === void 0 && unified.sevenDay === void 0) {
|
|
111925
|
+
return "it reports no plan windows, so there is no five-hour window to anchor";
|
|
111926
|
+
}
|
|
111927
|
+
const five = unified?.fiveHour === void 0 ? void 0 : effectiveWindow(unified.fiveHour, nowMs);
|
|
111928
|
+
if (five?.resetsAtMs !== void 0) {
|
|
111929
|
+
return `a five-hour window is already open, resetting in ${formatAge(five.resetsAtMs - nowMs)}`;
|
|
111930
|
+
}
|
|
111931
|
+
const candidate = rankPool({ members: [{ identity, snapshot, records: [] }], nowMs, resuming: false }).candidates[0];
|
|
111932
|
+
return candidate?.class === "ineligible" ? `it is refused right now (${candidate.reasons[0] ?? "no reason recorded"})` : void 0;
|
|
111933
|
+
}
|
|
111934
|
+
async function runWindowKeeper(ports) {
|
|
111935
|
+
const nowMs = ports.nowMs();
|
|
111936
|
+
const anchored = ports.anchored();
|
|
111937
|
+
const previous = readStamps(ports.fs, ports.stampsFile);
|
|
111938
|
+
const handled = Object.fromEntries(anchored.flatMap(({ identity }) => previous[identity] === void 0 ? [] : [[identity, previous[identity]]]));
|
|
111939
|
+
const outcomes = [];
|
|
111940
|
+
for (const { identity, anchors } of anchored) {
|
|
111941
|
+
const last = handled[identity];
|
|
111942
|
+
if (last === void 0) {
|
|
111943
|
+
handled[identity] = nowMs;
|
|
111944
|
+
outcomes.push({ identity, status: "armed", detail: "anchors noted; the next anchor to fall is the first acted on" });
|
|
111945
|
+
continue;
|
|
111946
|
+
}
|
|
111947
|
+
const due2 = dueAnchor(anchors, nowMs, last, ports.timeZone);
|
|
111948
|
+
if (due2 === void 0) {
|
|
111949
|
+
outcomes.push({ identity, status: "waiting", detail: "no anchor has fallen since the last handled" });
|
|
111950
|
+
continue;
|
|
111951
|
+
}
|
|
111952
|
+
handled[identity] = nowMs;
|
|
111953
|
+
const reason = reasonNotToOpen(identity, ports.snapshot(identity), nowMs);
|
|
111954
|
+
if (reason !== void 0) {
|
|
111955
|
+
outcomes.push({ identity, status: "skipped", detail: `anchor ${new Date(due2).toISOString()}: ${reason}` });
|
|
111956
|
+
continue;
|
|
111957
|
+
}
|
|
111958
|
+
try {
|
|
111959
|
+
await ports.open(identity);
|
|
111960
|
+
outcomes.push({ identity, status: "opened", detail: `anchor ${new Date(due2).toISOString()}: opened a five-hour window` });
|
|
111961
|
+
} catch (error63) {
|
|
111962
|
+
outcomes.push({ identity, status: "failed", detail: `anchor ${new Date(due2).toISOString()}: could not open a window: ${error63 instanceof Error ? error63.message : String(error63)}` });
|
|
111963
|
+
}
|
|
111964
|
+
}
|
|
111965
|
+
writeStamps(ports.fs, ports.stampsFile, handled);
|
|
111966
|
+
for (const outcome of outcomes) {
|
|
111967
|
+
if (outcome.status === "opened" || outcome.status === "skipped" || outcome.status === "failed") {
|
|
111968
|
+
ports.log(`window keeper: ${outcome.identity}: ${outcome.detail}`);
|
|
111969
|
+
}
|
|
111970
|
+
}
|
|
111971
|
+
return outcomes;
|
|
111972
|
+
}
|
|
111973
|
+
|
|
111974
|
+
// src/frontdoor/commands.ts
|
|
111647
111975
|
init_realCredentialCache();
|
|
111648
111976
|
|
|
111649
111977
|
// src/frontdoor/custody.ts
|
|
@@ -111752,7 +112080,7 @@ init_capability();
|
|
|
111752
112080
|
|
|
111753
112081
|
// src/frontdoor/capture.ts
|
|
111754
112082
|
var fs15 = __toESM(require("node:fs"), 1);
|
|
111755
|
-
var
|
|
112083
|
+
var path38 = __toESM(require("node:path"), 1);
|
|
111756
112084
|
var SECRET_HEADER_NAME = /authorization|cookie|token|secret|credential|api[-_]key/i;
|
|
111757
112085
|
var SECRET_JSON_KEY = /token|secret|password|credential|authorization|api[-_]key/i;
|
|
111758
112086
|
var SECRET_BODY_PATTERNS = [
|
|
@@ -111796,10 +112124,10 @@ function redactBody(chunk) {
|
|
|
111796
112124
|
}
|
|
111797
112125
|
var CAPTURE_ENV = "AGENT_SHIM_FRONTDOOR_CAPTURE";
|
|
111798
112126
|
function captureFromEnv(env, logsDir) {
|
|
111799
|
-
return env[CAPTURE_ENV] === "1" ? createFileCapture(
|
|
112127
|
+
return env[CAPTURE_ENV] === "1" ? createFileCapture(path38.join(logsDir, "frontdoor-capture.jsonl")) : void 0;
|
|
111800
112128
|
}
|
|
111801
112129
|
function createFileCapture(file2, now = () => /* @__PURE__ */ new Date()) {
|
|
111802
|
-
fs15.mkdirSync(
|
|
112130
|
+
fs15.mkdirSync(path38.dirname(file2), { recursive: true });
|
|
111803
112131
|
let nextId = 0;
|
|
111804
112132
|
const append = (record2) => {
|
|
111805
112133
|
fs15.appendFileSync(file2, `${JSON.stringify({ ts: now().toISOString(), ...record2 })}
|
|
@@ -111928,7 +112256,7 @@ var HIGH_BIT = 128;
|
|
|
111928
112256
|
var BASE_128_PAYLOAD_MASK = 127;
|
|
111929
112257
|
var FIRST_ARC_WEIGHT = 40;
|
|
111930
112258
|
var SHORT_FORM_MAX_LENGTH = 127;
|
|
111931
|
-
var
|
|
112259
|
+
var MS_PER_SECOND7 = 1e3;
|
|
111932
112260
|
var UTC_TIME_LAST_YEAR = 2049;
|
|
111933
112261
|
var YEAR_DIGITS = 4;
|
|
111934
112262
|
var TWO_DIGIT_YEAR_DIGITS = 2;
|
|
@@ -111987,7 +112315,7 @@ function wholeBitString(content) {
|
|
|
111987
112315
|
return tlv(TAG_BIT_STRING, Buffer.concat([Buffer.from([0]), content]));
|
|
111988
112316
|
}
|
|
111989
112317
|
function time3(instant) {
|
|
111990
|
-
const iso = new Date(Math.floor(instant.getTime() /
|
|
112318
|
+
const iso = new Date(Math.floor(instant.getTime() / MS_PER_SECOND7) * MS_PER_SECOND7).toISOString();
|
|
111991
112319
|
const compact = `${iso.replace(/[-:T]/g, "").slice(0, COMPACT_TIME_DIGITS)}Z`;
|
|
111992
112320
|
if (instant.getUTCFullYear() > UTC_TIME_LAST_YEAR) {
|
|
111993
112321
|
return tlv(TAG_GENERALIZED_TIME, Buffer.from(compact, "ascii"));
|
|
@@ -112218,19 +112546,19 @@ init_capability();
|
|
|
112218
112546
|
init_route();
|
|
112219
112547
|
|
|
112220
112548
|
// src/frontdoor/supervisor.ts
|
|
112221
|
-
var
|
|
112549
|
+
var import_node_path39 = __toESM(require("node:path"), 1);
|
|
112222
112550
|
init_state2();
|
|
112223
112551
|
function watchedInstallEntry(resolvedOwnExecutablePath, siblingExists) {
|
|
112224
|
-
const parsed =
|
|
112552
|
+
const parsed = import_node_path39.default.parse(resolvedOwnExecutablePath);
|
|
112225
112553
|
if (parsed.name === "agent-shim") {
|
|
112226
112554
|
return resolvedOwnExecutablePath;
|
|
112227
112555
|
}
|
|
112228
|
-
const sibling =
|
|
112556
|
+
const sibling = import_node_path39.default.join(parsed.dir, `agent-shim${parsed.ext}`);
|
|
112229
112557
|
return siblingExists(sibling) ? sibling : resolvedOwnExecutablePath;
|
|
112230
112558
|
}
|
|
112231
112559
|
var FRONTDOOR_SUPERVISOR_STILL_RUNNING = -1;
|
|
112232
112560
|
var FRONTDOOR_POLL_MS = 1e3;
|
|
112233
|
-
var
|
|
112561
|
+
var MS_PER_MINUTE3 = 6e4;
|
|
112234
112562
|
async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {}) {
|
|
112235
112563
|
const { fs: fs22, paths } = ports;
|
|
112236
112564
|
const servingBinary = ports.statOwnExecutable();
|
|
@@ -112296,16 +112624,27 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
112296
112624
|
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: front door on 127.0.0.1:${String(http8.port)}, CONNECT surface on 127.0.0.1:${String(connect3.port)}`);
|
|
112297
112625
|
let idleSince;
|
|
112298
112626
|
let ticks = 0;
|
|
112627
|
+
const supersedingOwner = () => {
|
|
112628
|
+
const owner = readFrontDoorState(fs22, paths.frontdoorStateFile)?.supervisorPid;
|
|
112629
|
+
return owner !== void 0 && owner !== ports.ownPid && ports.isRunning(owner) ? owner : void 0;
|
|
112630
|
+
};
|
|
112631
|
+
let supersededBy;
|
|
112632
|
+
let served;
|
|
112299
112633
|
const binaryReplaced = () => {
|
|
112300
112634
|
const current = ports.statOwnExecutable();
|
|
112301
112635
|
return current !== void 0 && servingBinary !== void 0 && (current.dev !== servingBinary.dev || current.ino !== servingBinary.ino || current.size !== servingBinary.size || current.mtimeMs !== servingBinary.mtimeMs);
|
|
112302
112636
|
};
|
|
112303
|
-
const
|
|
112637
|
+
const closeServing = async () => {
|
|
112304
112638
|
await direct.close();
|
|
112305
112639
|
await connect3.close();
|
|
112306
112640
|
await http8.close();
|
|
112307
112641
|
ports.closeRcStreamHub();
|
|
112308
|
-
|
|
112642
|
+
};
|
|
112643
|
+
const shutdown = async () => {
|
|
112644
|
+
await closeServing();
|
|
112645
|
+
if (supersedingOwner() === void 0) {
|
|
112646
|
+
writeFrontDoorState(fs22, paths.frontdoorStateFile, sticky());
|
|
112647
|
+
}
|
|
112309
112648
|
return 0;
|
|
112310
112649
|
};
|
|
112311
112650
|
for (; ; ) {
|
|
@@ -112318,14 +112657,35 @@ async function runFrontDoorSupervisor(idleShutdownMinutes, ports, options = {})
|
|
|
112318
112657
|
ports.observeLaunchRegistry(listed, pruned);
|
|
112319
112658
|
ports.checkQuotaExpiry();
|
|
112320
112659
|
const prunedPids = new Set(pruned);
|
|
112321
|
-
|
|
112660
|
+
const live = listed.filter((session) => !prunedPids.has(session.pid));
|
|
112661
|
+
if (supersededBy === void 0) {
|
|
112662
|
+
supersededBy = supersedingOwner();
|
|
112663
|
+
if (supersededBy !== void 0) {
|
|
112664
|
+
ports.log(`agent-shim frontdoor supervisor ${String(ports.ownPid)}: supervisor ${String(supersededBy)} now owns the front door; taking no new sessions and exiting once the sessions this door serves have ended`);
|
|
112665
|
+
ports.doorHealth.superseded(supersededBy);
|
|
112666
|
+
await ports.sleep(FRONTDOOR_POLL_MS);
|
|
112667
|
+
continue;
|
|
112668
|
+
}
|
|
112669
|
+
} else {
|
|
112670
|
+
const owner = supersededBy;
|
|
112671
|
+
served = (served ?? live.filter((session) => session.pid !== ports.ownPid && session.pid !== owner && (session.supervisorPid === void 0 || session.supervisorPid === ports.ownPid))).filter((own2) => live.some((session) => session.pid === own2.pid && session.startedAt === own2.startedAt));
|
|
112672
|
+
if (served.length === 0) {
|
|
112673
|
+
ports.log("agent-shim frontdoor supervisor: the sessions this superseded door served have ended; closing the front door and exiting");
|
|
112674
|
+
ports.doorHealth.drained();
|
|
112675
|
+
await closeServing();
|
|
112676
|
+
return 0;
|
|
112677
|
+
}
|
|
112678
|
+
await ports.sleep(FRONTDOOR_POLL_MS);
|
|
112679
|
+
continue;
|
|
112680
|
+
}
|
|
112681
|
+
if (live.length === 0) {
|
|
112322
112682
|
if (ticks > 1 && binaryReplaced()) {
|
|
112323
112683
|
ports.log("agent-shim frontdoor supervisor: the installed binary changed and no sessions are live; turning the door over for the next launch");
|
|
112324
112684
|
ports.doorHealth.binaryTurnover();
|
|
112325
112685
|
return await shutdown();
|
|
112326
112686
|
}
|
|
112327
112687
|
idleSince ??= ports.now();
|
|
112328
|
-
if (ports.now() - idleSince >= idleShutdownMinutes *
|
|
112688
|
+
if (ports.now() - idleSince >= idleShutdownMinutes * MS_PER_MINUTE3) {
|
|
112329
112689
|
ports.log(`agent-shim frontdoor supervisor: no sessions for ${String(idleShutdownMinutes)} minute(s); closing the front door and exiting`);
|
|
112330
112690
|
ports.doorHealth.idleShutdown();
|
|
112331
112691
|
return await shutdown();
|
|
@@ -112366,7 +112726,7 @@ var CONNECT_LIMITS = {
|
|
|
112366
112726
|
var CA_VALIDITY_DAYS = 3650;
|
|
112367
112727
|
var LEAF_VALIDITY_DAYS = 397;
|
|
112368
112728
|
var CA_SUBJECT_COMMON_NAME = "agent-shim front door CA";
|
|
112369
|
-
var
|
|
112729
|
+
var MS_PER_DAY3 = 864e5;
|
|
112370
112730
|
function parseConnectTarget(authority) {
|
|
112371
112731
|
const colon = authority.lastIndexOf(":");
|
|
112372
112732
|
if (colon === -1) {
|
|
@@ -112380,8 +112740,8 @@ function parseConnectTarget(authority) {
|
|
|
112380
112740
|
}
|
|
112381
112741
|
return { host, port };
|
|
112382
112742
|
}
|
|
112383
|
-
function servedByPipeline(
|
|
112384
|
-
return
|
|
112743
|
+
function servedByPipeline(path52) {
|
|
112744
|
+
return path52?.startsWith(ROUTED_PATH_PREFIX) === true;
|
|
112385
112745
|
}
|
|
112386
112746
|
var HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
|
|
112387
112747
|
"connection",
|
|
@@ -112412,11 +112772,11 @@ function forwardableHeaders(headers) {
|
|
|
112412
112772
|
return result;
|
|
112413
112773
|
}
|
|
112414
112774
|
function generateCa(now) {
|
|
112415
|
-
return issueCaCertificate(CA_SUBJECT_COMMON_NAME, new Date(now.getTime() -
|
|
112775
|
+
return issueCaCertificate(CA_SUBJECT_COMMON_NAME, new Date(now.getTime() - MS_PER_DAY3), new Date(now.getTime() + CA_VALIDITY_DAYS * MS_PER_DAY3));
|
|
112416
112776
|
}
|
|
112417
112777
|
var LOOPBACK_LEAF_NAMES = ["127.0.0.1", "localhost"];
|
|
112418
112778
|
function mintLeaf(ca2, names, now) {
|
|
112419
|
-
return issueLeafCertificate(ca2, names, new Date(now.getTime() -
|
|
112779
|
+
return issueLeafCertificate(ca2, names, new Date(now.getTime() - MS_PER_DAY3), new Date(now.getTime() + LEAF_VALIDITY_DAYS * MS_PER_DAY3));
|
|
112420
112780
|
}
|
|
112421
112781
|
function createLeafCache(ca2, now) {
|
|
112422
112782
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -112900,11 +113260,11 @@ function createRcSessionTracker(deps) {
|
|
|
112900
113260
|
};
|
|
112901
113261
|
const observeExchange = (request7) => {
|
|
112902
113262
|
const method = (request7.method ?? "").toUpperCase();
|
|
112903
|
-
const
|
|
112904
|
-
if (!
|
|
113263
|
+
const path52 = new URL(request7.url ?? "/", "http://127.0.0.1").pathname;
|
|
113264
|
+
if (!path52.startsWith(RC_SESSIONS_PATH_PREFIX)) {
|
|
112905
113265
|
return void 0;
|
|
112906
113266
|
}
|
|
112907
|
-
const tail =
|
|
113267
|
+
const tail = path52.slice(RC_SESSIONS_PATH_PREFIX.length);
|
|
112908
113268
|
const facts = {
|
|
112909
113269
|
oauthAuthorization: oauthAuthorizationOf(request7.headers),
|
|
112910
113270
|
anthropicVersion: singleHeader(request7.headers, "anthropic-version"),
|
|
@@ -113265,8 +113625,8 @@ var RC_READ_FILE_ENCODINGS = ["utf-8", "base64"];
|
|
|
113265
113625
|
function isRcReadFileEncoding(value2) {
|
|
113266
113626
|
return RC_READ_FILE_ENCODINGS.some((encoding) => encoding === value2);
|
|
113267
113627
|
}
|
|
113268
|
-
function buildRcReadFilePayload(requestId,
|
|
113269
|
-
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path:
|
|
113628
|
+
function buildRcReadFilePayload(requestId, path52, options) {
|
|
113629
|
+
return buildRcControlRequestPayload(requestId, { subtype: "read_file", path: path52, ...options?.maxBytes === void 0 ? {} : { max_bytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } });
|
|
113270
113630
|
}
|
|
113271
113631
|
function buildRcFileSuggestionsPayload(requestId, query) {
|
|
113272
113632
|
return buildRcControlRequestPayload(requestId, { subtype: "file_suggestions", query });
|
|
@@ -113368,15 +113728,15 @@ async function getRcSessionContextUsage(deps, sessionId, detail) {
|
|
|
113368
113728
|
const result = await deliverRcClientPayload(deps, sessionId, buildRcGetContextUsagePayload(requestId, detail), `request the context usage of session ${sessionId}`);
|
|
113369
113729
|
return result.ok ? { ...result, requestId } : result;
|
|
113370
113730
|
}
|
|
113371
|
-
async function readRcSessionFile(deps, sessionId,
|
|
113372
|
-
if (
|
|
113731
|
+
async function readRcSessionFile(deps, sessionId, path52, options) {
|
|
113732
|
+
if (path52 === "") {
|
|
113373
113733
|
return { ok: false, message: "a read-file write needs a non-empty path: the SDK's own field names the file the worker resolves against the session's cwd, and an empty string names none" };
|
|
113374
113734
|
}
|
|
113375
113735
|
if (options?.maxBytes !== void 0 && (!Number.isInteger(options.maxBytes) || options.maxBytes <= 0)) {
|
|
113376
113736
|
return { ok: false, message: "a read-file write's max-bytes is a positive whole number of bytes: the SDK's own field caps the read, and a zero or negative cap reads nothing" };
|
|
113377
113737
|
}
|
|
113378
113738
|
const requestId = deps.newUuid();
|
|
113379
|
-
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId,
|
|
113739
|
+
const result = await deliverRcClientPayload(deps, sessionId, buildRcReadFilePayload(requestId, path52, options), `read ${path52} from session ${sessionId}`);
|
|
113380
113740
|
return result.ok ? { ...result, requestId } : result;
|
|
113381
113741
|
}
|
|
113382
113742
|
async function suggestRcSessionFiles(deps, sessionId, query) {
|
|
@@ -113547,11 +113907,11 @@ function createRcControlHandler(deps) {
|
|
|
113547
113907
|
path: "read-file",
|
|
113548
113908
|
read: (body) => {
|
|
113549
113909
|
const session = bodyString(body, "session");
|
|
113550
|
-
const
|
|
113910
|
+
const path52 = bodyString(body, "path");
|
|
113551
113911
|
const maxBytes = "maxBytes" in body ? bodyPositiveInteger(body, "maxBytes") : void 0;
|
|
113552
113912
|
const encoding = "encoding" in body && isRcReadFileEncoding(body.encoding) ? body.encoding : void 0;
|
|
113553
|
-
const refused2 = session === void 0 ||
|
|
113554
|
-
return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session,
|
|
113913
|
+
const refused2 = session === void 0 || path52 === void 0 || "maxBytes" in body && maxBytes === void 0 || "encoding" in body && encoding === void 0;
|
|
113914
|
+
return refused2 ? { error: `the read-file body must be JSON naming a non-empty session id and path, maxBytes only as a positive whole number or absent, and an encoding the SDK's own type permits (${RC_READ_FILE_ENCODINGS.join(", ")}) or none` } : { session, run: async () => await deps.readFile(session, path52, { ...maxBytes === void 0 ? {} : { maxBytes }, ...encoding === void 0 ? {} : { encoding } }) };
|
|
113555
113915
|
}
|
|
113556
113916
|
},
|
|
113557
113917
|
{
|
|
@@ -113861,9 +114221,9 @@ function requestIdOfBody(body) {
|
|
|
113861
114221
|
}
|
|
113862
114222
|
function frontDoorRcControl(transport, token) {
|
|
113863
114223
|
const headers = { authorization: `Bearer ${token}` };
|
|
113864
|
-
const listAnswerOf = async (
|
|
114224
|
+
const listAnswerOf = async (path52, what) => {
|
|
113865
114225
|
try {
|
|
113866
|
-
return await transport.request({ method: "GET", path:
|
|
114226
|
+
return await transport.request({ method: "GET", path: path52, headers });
|
|
113867
114227
|
} catch (error63) {
|
|
113868
114228
|
throw new Error(`${what}: could not reach the front door's control listener: ${error63 instanceof Error ? error63.message : String(error63)}`, { cause: error63 });
|
|
113869
114229
|
}
|
|
@@ -113935,10 +114295,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
113935
114295
|
}
|
|
113936
114296
|
return pending;
|
|
113937
114297
|
};
|
|
113938
|
-
const writeOf = async (
|
|
114298
|
+
const writeOf = async (path52, body, describeFailure) => {
|
|
113939
114299
|
let answer;
|
|
113940
114300
|
try {
|
|
113941
|
-
answer = await transport.request({ method: "POST", path:
|
|
114301
|
+
answer = await transport.request({ method: "POST", path: path52, headers: { ...headers, "content-type": "application/json" }, body });
|
|
113942
114302
|
} catch (error63) {
|
|
113943
114303
|
return { ok: false, message: `could not reach the front door's control listener: ${error63 instanceof Error ? error63.message : String(error63)}` };
|
|
113944
114304
|
}
|
|
@@ -113969,10 +114329,10 @@ function frontDoorRcControl(transport, token) {
|
|
|
113969
114329
|
endSession: async (sessionId, reason) => await writeOf(`${CONTROL_PATH_PREFIX}/end-session`, JSON.stringify({ session: sessionId, ...reason === void 0 ? {} : { reason } }), (status, message) => `ending ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
113970
114330
|
getUsage: async (sessionId, skipBehaviors) => await writeOf(`${CONTROL_PATH_PREFIX}/get-usage`, JSON.stringify({ session: sessionId, ...skipBehaviors === void 0 ? {} : { skipBehaviors } }), (status, message) => `requesting the usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
113971
114331
|
getContextUsage: async (sessionId, detail) => await writeOf(`${CONTROL_PATH_PREFIX}/get-context-usage`, JSON.stringify({ session: sessionId, ...detail === void 0 ? {} : { detail } }), (status, message) => `requesting the context usage of ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
113972
|
-
readFile: async (sessionId,
|
|
114332
|
+
readFile: async (sessionId, path52, options) => await writeOf(
|
|
113973
114333
|
`${CONTROL_PATH_PREFIX}/read-file`,
|
|
113974
|
-
JSON.stringify({ session: sessionId, path:
|
|
113975
|
-
(status, message) => `reading ${
|
|
114334
|
+
JSON.stringify({ session: sessionId, path: path52, ...options?.maxBytes === void 0 ? {} : { maxBytes: options.maxBytes }, ...options?.encoding === void 0 ? {} : { encoding: options.encoding } }),
|
|
114335
|
+
(status, message) => `reading ${path52} from ${sessionId} failed (HTTP ${String(status)}): ${message}`
|
|
113976
114336
|
),
|
|
113977
114337
|
fileSuggestions: async (sessionId, query) => await writeOf(`${CONTROL_PATH_PREFIX}/file-suggestions`, JSON.stringify({ session: sessionId, query }), (status, message) => `requesting file suggestions from ${sessionId} failed (HTTP ${String(status)}): ${message}`),
|
|
113978
114338
|
keepAlive: async (sessionId) => await writeOf(`${CONTROL_PATH_PREFIX}/keep-alive`, JSON.stringify({ session: sessionId }), (status, message) => `keeping ${sessionId} alive failed (HTTP ${String(status)}): ${message}`),
|
|
@@ -114266,12 +114626,12 @@ function tlsFacts(options) {
|
|
|
114266
114626
|
}
|
|
114267
114627
|
function realRcEventDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
114268
114628
|
const agent = new ExemptTlsAgent();
|
|
114269
|
-
const post = async (
|
|
114629
|
+
const post = async (path52, headers, body) => await new Promise((resolve2, reject) => {
|
|
114270
114630
|
const options = {
|
|
114271
114631
|
host: target.host,
|
|
114272
114632
|
port: target.port,
|
|
114273
114633
|
method: "POST",
|
|
114274
|
-
path:
|
|
114634
|
+
path: path52,
|
|
114275
114635
|
// The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
|
|
114276
114636
|
headers: { ...headers, host: target.servername ?? target.host, "content-length": String(Buffer.byteLength(body, "utf8")) },
|
|
114277
114637
|
agent
|
|
@@ -114336,12 +114696,12 @@ function lateRcStreamDial(resolve2) {
|
|
|
114336
114696
|
}
|
|
114337
114697
|
function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_PORT }) {
|
|
114338
114698
|
const agent = new ExemptTlsAgent();
|
|
114339
|
-
const request7 = async (method,
|
|
114699
|
+
const request7 = async (method, path52, headers, body, signal) => await new Promise((resolve2, reject) => {
|
|
114340
114700
|
const options = {
|
|
114341
114701
|
host: target.host,
|
|
114342
114702
|
port: target.port,
|
|
114343
114703
|
method,
|
|
114344
|
-
path:
|
|
114704
|
+
path: path52,
|
|
114345
114705
|
// The Host header names the host whose API this is, not the address dialled: a redirected test dials a loopback stand-in while still speaking to the API host by name, exactly as the forwarded paths present their SNI.
|
|
114346
114706
|
headers: { ...headers, host: target.servername ?? target.host, ...body === void 0 ? {} : { "content-length": String(Buffer.byteLength(body, "utf8")) } },
|
|
114347
114707
|
agent,
|
|
@@ -114383,9 +114743,9 @@ function realRcStreamDial(target = { host: CONNECT_INTERCEPT_HOST, port: HTTPS_P
|
|
|
114383
114743
|
return { status, body: await readAll(response) };
|
|
114384
114744
|
},
|
|
114385
114745
|
openStream: async (sessionId, headers, resume, signal) => {
|
|
114386
|
-
const
|
|
114746
|
+
const path52 = resume === void 0 ? `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream` : `/v1/code/sessions/${encodeURIComponent(sessionId)}/events/stream?from_sequence_num=${String(resume.fromSequenceNum)}`;
|
|
114387
114747
|
const streamHeaders = resume === void 0 ? headers : { ...headers, "last-event-id": String(resume.fromSequenceNum) };
|
|
114388
|
-
const { status, response } = await request7("GET",
|
|
114748
|
+
const { status, response } = await request7("GET", path52, streamHeaders, void 0, signal);
|
|
114389
114749
|
if (!isSuccessful2(status)) {
|
|
114390
114750
|
await readAll(response);
|
|
114391
114751
|
return { status, chunks: NO_CHUNKS };
|
|
@@ -114601,10 +114961,10 @@ init_claudeShim();
|
|
|
114601
114961
|
init_store();
|
|
114602
114962
|
init_realPorts();
|
|
114603
114963
|
var import_node_fs15 = __toESM(require("node:fs"), 1);
|
|
114604
|
-
var
|
|
114964
|
+
var import_node_path41 = __toESM(require("node:path"), 1);
|
|
114605
114965
|
|
|
114606
114966
|
// src/usage/signIn.ts
|
|
114607
|
-
var
|
|
114967
|
+
var import_node_path40 = __toESM(require("node:path"), 1);
|
|
114608
114968
|
var CREDENTIALS_FILE = ".credentials.json";
|
|
114609
114969
|
function keychainHasItem(run, account) {
|
|
114610
114970
|
return run.run("security", ["find-generic-password", "-a", account]).status === 0;
|
|
@@ -114622,7 +114982,7 @@ function decideSignIn(facts) {
|
|
|
114622
114982
|
return { state: "signed-out", detail: facts.platform === "darwin" ? `no Keychain item and no ${CREDENTIALS_FILE}` : `no ${CREDENTIALS_FILE}` };
|
|
114623
114983
|
}
|
|
114624
114984
|
function credentialsFilePath(farmRoot) {
|
|
114625
|
-
return
|
|
114985
|
+
return import_node_path40.default.join(farmRoot, CREDENTIALS_FILE);
|
|
114626
114986
|
}
|
|
114627
114987
|
function identitySignIn(fs22, probe, identity) {
|
|
114628
114988
|
const probing = !identity.hasCredentialBlock;
|
|
@@ -114641,7 +115001,55 @@ init_credential();
|
|
|
114641
115001
|
init_credentialCache();
|
|
114642
115002
|
init_realCredentialCache();
|
|
114643
115003
|
init_source();
|
|
115004
|
+
|
|
115005
|
+
// src/headroom/allowlistDrift.ts
|
|
115006
|
+
init_state();
|
|
115007
|
+
function diagnoseAllowlistDrift(params) {
|
|
115008
|
+
const { recordedHash, providers, frontDoorOrigin: frontDoorOrigin2 } = params;
|
|
115009
|
+
if (recordedHash === void 0 || recordedHash === hashAllowlist(headroomAllowlist(headroomUpstreams(providers, frontDoorOrigin2)))) {
|
|
115010
|
+
return void 0;
|
|
115011
|
+
}
|
|
115012
|
+
const originIsInput = providers.length > 0 && frontDoorOrigin2 !== void 0;
|
|
115013
|
+
if (!originIsInput) {
|
|
115014
|
+
return ["provider-files"];
|
|
115015
|
+
}
|
|
115016
|
+
return recordedHash === hashAllowlist(headroomAllowlist(headroomUpstreams(providers, void 0))) ? ["front-door-origin"] : ["provider-files", "front-door-origin"];
|
|
115017
|
+
}
|
|
115018
|
+
|
|
115019
|
+
// src/doctorReport.ts
|
|
114644
115020
|
init_state();
|
|
115021
|
+
init_supervisor();
|
|
115022
|
+
init_state2();
|
|
115023
|
+
|
|
115024
|
+
// src/doctorFrontDoor.ts
|
|
115025
|
+
function pushFrontDoor(push, supervisors, registeredPid) {
|
|
115026
|
+
if (!supervisors.ok) {
|
|
115027
|
+
push("frontdoor", "warn", `Could not list processes to look for duplicate front door supervisors: ${supervisors.message}.`);
|
|
115028
|
+
return;
|
|
115029
|
+
}
|
|
115030
|
+
const { pids } = supervisors;
|
|
115031
|
+
if (pids.length === 0) {
|
|
115032
|
+
push("frontdoor", "pass", "No front door supervisor is running.");
|
|
115033
|
+
return;
|
|
115034
|
+
}
|
|
115035
|
+
const [only, ...rest] = pids;
|
|
115036
|
+
if (only !== void 0 && rest.length === 0) {
|
|
115037
|
+
push("frontdoor", "pass", `One front door supervisor is running (pid ${String(only)}).`);
|
|
115038
|
+
return;
|
|
115039
|
+
}
|
|
115040
|
+
const serving = registeredPid !== void 0 && pids.includes(registeredPid) ? `The front door state file names pid ${String(registeredPid)} as the serving supervisor.` : "The front door state file names no running supervisor.";
|
|
115041
|
+
for (const pid of pids.filter((candidate) => candidate !== registeredPid)) {
|
|
115042
|
+
push(
|
|
115043
|
+
"frontdoor",
|
|
115044
|
+
"fail",
|
|
115045
|
+
`Front door supervisor pid ${String(pid)} is running beside ${String(pids.length - 1)} other(s). ${serving} Stop it with \`kill ${String(pid)}\`; launches still connected to it lose their door.`,
|
|
115046
|
+
String(pid)
|
|
115047
|
+
);
|
|
115048
|
+
}
|
|
115049
|
+
}
|
|
115050
|
+
|
|
115051
|
+
// src/doctorReport.ts
|
|
115052
|
+
init_supervisorProcesses();
|
|
114645
115053
|
init_legacy();
|
|
114646
115054
|
init_providersStore();
|
|
114647
115055
|
init_guard();
|
|
@@ -114664,7 +115072,8 @@ var DOCTOR_SECTIONS = [
|
|
|
114664
115072
|
"global-config",
|
|
114665
115073
|
"categories-local",
|
|
114666
115074
|
"active-identity",
|
|
114667
|
-
"headroom"
|
|
115075
|
+
"headroom",
|
|
115076
|
+
"frontdoor"
|
|
114668
115077
|
];
|
|
114669
115078
|
function refinePathShadow(status, ownExecutablePath, realpath) {
|
|
114670
115079
|
if (status.status !== "shadowed") {
|
|
@@ -114699,7 +115108,7 @@ function tcpPortEraRecord(raw) {
|
|
|
114699
115108
|
return (has("port") || has("lastPort")) && !has("socketPath");
|
|
114700
115109
|
}
|
|
114701
115110
|
function pushPathResolution(push, resolution) {
|
|
114702
|
-
const ownDir =
|
|
115111
|
+
const ownDir = import_node_path41.default.dirname(resolution.ownExecutablePath);
|
|
114703
115112
|
switch (resolution.agentShim.status) {
|
|
114704
115113
|
case "ok":
|
|
114705
115114
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -114798,14 +115207,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
114798
115207
|
}
|
|
114799
115208
|
function pushLegacyName(push, params) {
|
|
114800
115209
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
114801
|
-
if (legacyVariables.length === 0 &&
|
|
115210
|
+
if (legacyVariables.length === 0 && import_node_path41.default.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
114802
115211
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
114803
115212
|
return;
|
|
114804
115213
|
}
|
|
114805
115214
|
for (const name of legacyVariables) {
|
|
114806
115215
|
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);
|
|
114807
115216
|
}
|
|
114808
|
-
if (
|
|
115217
|
+
if (import_node_path41.default.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
114809
115218
|
push(
|
|
114810
115219
|
"legacy-name",
|
|
114811
115220
|
"warn",
|
|
@@ -115060,6 +115469,17 @@ function runDoctor(params) {
|
|
|
115060
115469
|
`Headroom daemon is up on unix socket ${state.socketPath} (supervisor ${String(state.supervisorPid)}, daemon ${String(state.headroomPid)}).`
|
|
115061
115470
|
);
|
|
115062
115471
|
}
|
|
115472
|
+
const allowlist = params.headroom.allowlist;
|
|
115473
|
+
if (supervisorAlive && headroomAlive && state.socketPath !== void 0 && allowlist?.driftInputs?.includes("front-door-origin") === true) {
|
|
115474
|
+
const origin = allowlist.frontDoorOrigin ?? "";
|
|
115475
|
+
const certainty = allowlist.driftInputs.includes("provider-files") ? "may exclude" : "excludes";
|
|
115476
|
+
push(
|
|
115477
|
+
"headroom",
|
|
115478
|
+
"fail",
|
|
115479
|
+
`Headroom daemon ${String(state.headroomPid)} was started with an allowlist that ${certainty} the serving front door's direct origin ${origin}, so it refuses every request a provider launch sends back through the door. Its supervisor restarts it once no launch is registered against it; \`agent-shim headroom status\` lists the registered launches, and \`--no-headroom\` launches are unaffected.`,
|
|
115480
|
+
String(state.headroomPid)
|
|
115481
|
+
);
|
|
115482
|
+
}
|
|
115063
115483
|
if (state.lastError !== void 0 && supervisorAlive) {
|
|
115064
115484
|
push("headroom", "warn", `Headroom recorded a previous error: ${state.lastError}`);
|
|
115065
115485
|
}
|
|
@@ -115072,6 +115492,10 @@ function runDoctor(params) {
|
|
|
115072
115492
|
}
|
|
115073
115493
|
}
|
|
115074
115494
|
}
|
|
115495
|
+
if (params.frontDoor !== void 0) {
|
|
115496
|
+
const validated2 = params.frontDoor.state.raw === void 0 ? void 0 : validateJson(FrontDoorStateSchema, params.frontDoor.state);
|
|
115497
|
+
pushFrontDoor(push, params.frontDoor.supervisors, validated2?.ok === true ? validated2.data.supervisorPid : void 0);
|
|
115498
|
+
}
|
|
115075
115499
|
if (params.activeIdentity.raw === void 0) {
|
|
115076
115500
|
push("active-identity", "pass", "No active identity set.");
|
|
115077
115501
|
} else {
|
|
@@ -115101,6 +115525,7 @@ var SECTION_TITLES = {
|
|
|
115101
115525
|
"directory-rules": "Directory rules",
|
|
115102
115526
|
"global-config": "Global config",
|
|
115103
115527
|
headroom: "Headroom daemon",
|
|
115528
|
+
frontdoor: "Front door",
|
|
115104
115529
|
"categories-local": "categories.local.json",
|
|
115105
115530
|
"active-identity": "Active identity"
|
|
115106
115531
|
};
|
|
@@ -115118,6 +115543,7 @@ var SECTION_ORDER = [
|
|
|
115118
115543
|
"directory-rules",
|
|
115119
115544
|
"global-config",
|
|
115120
115545
|
"headroom",
|
|
115546
|
+
"frontdoor",
|
|
115121
115547
|
"categories-local",
|
|
115122
115548
|
"active-identity"
|
|
115123
115549
|
];
|
|
@@ -115161,18 +115587,18 @@ function collectDoctorReport(params) {
|
|
|
115161
115587
|
const { paths } = params;
|
|
115162
115588
|
const identityNames = import_node_fs15.default.existsSync(paths.identitiesDir) ? import_node_fs15.default.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
|
|
115163
115589
|
const identities = identityNames.map((name) => {
|
|
115164
|
-
const farmRoot =
|
|
115165
|
-
const identityPath =
|
|
115590
|
+
const farmRoot = import_node_path41.default.join(paths.identitiesDir, name);
|
|
115591
|
+
const identityPath = import_node_path41.default.join(farmRoot, "identity.json");
|
|
115166
115592
|
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: import_node_fs15.default.existsSync(credentialsFilePath(farmRoot)) };
|
|
115167
115593
|
});
|
|
115168
115594
|
const profileNames = import_node_fs15.default.existsSync(paths.configProfilesDir) ? import_node_fs15.default.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
115169
115595
|
const configProfiles = profileNames.map((name) => {
|
|
115170
|
-
const profilePath =
|
|
115596
|
+
const profilePath = import_node_path41.default.join(paths.configProfilesDir, `${name}.json`);
|
|
115171
115597
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
115172
115598
|
});
|
|
115173
115599
|
const providerNames = import_node_fs15.default.existsSync(paths.providersDir) ? import_node_fs15.default.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
115174
115600
|
const providers = providerNames.map((name) => {
|
|
115175
|
-
const providerPath =
|
|
115601
|
+
const providerPath = import_node_path41.default.join(paths.providersDir, `${name}.json`);
|
|
115176
115602
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
115177
115603
|
});
|
|
115178
115604
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -115184,17 +115610,20 @@ function collectDoctorReport(params) {
|
|
|
115184
115610
|
binaryDiscovery = { ok: false, message: error63 instanceof Error ? error63.message : String(error63) };
|
|
115185
115611
|
}
|
|
115186
115612
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
115187
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
115613
|
+
const pathDirs = (params.env.PATH ?? "").split(import_node_path41.default.delimiter).filter((dir) => dir !== "");
|
|
115188
115614
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
115189
115615
|
findPathShadow({
|
|
115190
115616
|
pathDirs,
|
|
115191
|
-
targetDir:
|
|
115192
|
-
targetFilename:
|
|
115617
|
+
targetDir: import_node_path41.default.dirname(shimState.targetPath),
|
|
115618
|
+
targetFilename: import_node_path41.default.basename(shimState.targetPath),
|
|
115193
115619
|
findExecutableInDir
|
|
115194
115620
|
}),
|
|
115195
115621
|
shimState.targetPath,
|
|
115196
115622
|
realpathOrSelf
|
|
115197
115623
|
);
|
|
115624
|
+
const uid = process.getuid?.();
|
|
115625
|
+
const allowlistInputs = currentHeadroomAllowlistInputs(realFarmFs, paths);
|
|
115626
|
+
const servingHeadroom = resolveServingHeadroomState(realFarmFs, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, realIsProcessRunning);
|
|
115198
115627
|
const report = runDoctor({
|
|
115199
115628
|
env: params.env,
|
|
115200
115629
|
credentialCache: realCredentialCacheEnv(paths),
|
|
@@ -115215,7 +115644,7 @@ function collectDoctorReport(params) {
|
|
|
115215
115644
|
agentShim: refinePathShadow(
|
|
115216
115645
|
findPathShadow({
|
|
115217
115646
|
pathDirs,
|
|
115218
|
-
targetDir:
|
|
115647
|
+
targetDir: import_node_path41.default.dirname(ownExecutablePath),
|
|
115219
115648
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
115220
115649
|
findExecutableInDir
|
|
115221
115650
|
}),
|
|
@@ -115233,8 +115662,13 @@ function collectDoctorReport(params) {
|
|
|
115233
115662
|
const statePath = resolved?.path ?? paths.headroomStateFile;
|
|
115234
115663
|
return { path: statePath, raw: realFarmFs.readFileUtf8(statePath) };
|
|
115235
115664
|
})(),
|
|
115236
|
-
isRunning: realIsProcessRunning
|
|
115237
|
-
|
|
115665
|
+
isRunning: realIsProcessRunning,
|
|
115666
|
+
allowlist: {
|
|
115667
|
+
driftInputs: diagnoseAllowlistDrift({ recordedHash: servingHeadroom?.state.allowlistHash, ...allowlistInputs }),
|
|
115668
|
+
frontDoorOrigin: allowlistInputs.frontDoorOrigin
|
|
115669
|
+
}
|
|
115670
|
+
},
|
|
115671
|
+
...uid === void 0 ? {} : { frontDoor: { state: { path: paths.frontdoorStateFile, raw: realFsPort.readFileUtf8(paths.frontdoorStateFile) }, supervisors: listFrontDoorSupervisors(realRunPort, uid) } }
|
|
115238
115672
|
});
|
|
115239
115673
|
return report;
|
|
115240
115674
|
}
|
|
@@ -115473,11 +115907,11 @@ function tryOrUndefined(fn2) {
|
|
|
115473
115907
|
return void 0;
|
|
115474
115908
|
}
|
|
115475
115909
|
}
|
|
115476
|
-
function pathToHttpPath(
|
|
115477
|
-
return `/${
|
|
115910
|
+
function pathToHttpPath(path52) {
|
|
115911
|
+
return `/${path52.map(safeEncodeURIComponent).join("/")}`;
|
|
115478
115912
|
}
|
|
115479
|
-
function normalizeHttpPath(
|
|
115480
|
-
const paths =
|
|
115913
|
+
function normalizeHttpPath(path52) {
|
|
115914
|
+
const paths = path52.split("/");
|
|
115481
115915
|
if (paths.at(0) === "") {
|
|
115482
115916
|
paths.shift();
|
|
115483
115917
|
}
|
|
@@ -115662,9 +116096,9 @@ function isPlainObject2(value2) {
|
|
|
115662
116096
|
function getOwn(object3, key) {
|
|
115663
116097
|
return Object.hasOwn(object3, key) ? object3[key] : void 0;
|
|
115664
116098
|
}
|
|
115665
|
-
function get(object3,
|
|
116099
|
+
function get(object3, path52) {
|
|
115666
116100
|
let current = object3;
|
|
115667
|
-
for (const key of
|
|
116101
|
+
for (const key of path52) {
|
|
115668
116102
|
if (!isTypescriptObject(current)) {
|
|
115669
116103
|
return void 0;
|
|
115670
116104
|
}
|
|
@@ -116887,7 +117321,7 @@ function resolveClientRest(rest) {
|
|
|
116887
117321
|
// rest[1] can be undefined if all fields of FriendlyClientOptions are optional
|
|
116888
117322
|
];
|
|
116889
117323
|
}
|
|
116890
|
-
function createORPCClient(link, { path:
|
|
117324
|
+
function createORPCClient(link, { path: path52 = [], ...options } = {}) {
|
|
116891
117325
|
const procedureClient = (...rest) => {
|
|
116892
117326
|
const [input2, callOptions] = resolveClientRest(rest);
|
|
116893
117327
|
const interceptors = [
|
|
@@ -116896,7 +117330,7 @@ function createORPCClient(link, { path: path51 = [], ...options } = {}) {
|
|
|
116896
117330
|
];
|
|
116897
117331
|
return intercept(
|
|
116898
117332
|
interceptors,
|
|
116899
|
-
{ ...callOptions, input: input2, path:
|
|
117333
|
+
{ ...callOptions, input: input2, path: path52 },
|
|
116900
117334
|
({ path: path210, input: input22, ...callOptions2 }) => link.call(path210, input22, callOptions2)
|
|
116901
117335
|
);
|
|
116902
117336
|
};
|
|
@@ -116910,7 +117344,7 @@ function createORPCClient(link, { path: path51 = [], ...options } = {}) {
|
|
|
116910
117344
|
if (client === void 0) {
|
|
116911
117345
|
client = createORPCClient(link, {
|
|
116912
117346
|
...options,
|
|
116913
|
-
path: [...
|
|
117347
|
+
path: [...path52, key],
|
|
116914
117348
|
scoped: options.scoped?.[key]
|
|
116915
117349
|
});
|
|
116916
117350
|
cache.set(key, client);
|
|
@@ -116932,24 +117366,24 @@ var BracketNotationSerializer = class {
|
|
|
116932
117366
|
this.internalSerialize(data, "", true, result);
|
|
116933
117367
|
return result;
|
|
116934
117368
|
}
|
|
116935
|
-
internalSerialize(data,
|
|
117369
|
+
internalSerialize(data, path52, isRoot, result) {
|
|
116936
117370
|
if (Array.isArray(data)) {
|
|
116937
117371
|
data.forEach((item, i10) => {
|
|
116938
|
-
this.internalSerialize(item, isRoot ? i10.toString() : `${
|
|
117372
|
+
this.internalSerialize(item, isRoot ? i10.toString() : `${path52}[${i10}]`, false, result);
|
|
116939
117373
|
});
|
|
116940
117374
|
} else if (isPlainObject2(data)) {
|
|
116941
117375
|
for (const key of Object.keys(data)) {
|
|
116942
|
-
this.internalSerialize(data[key], isRoot ? key : `${
|
|
117376
|
+
this.internalSerialize(data[key], isRoot ? key : `${path52}[${key}]`, false, result);
|
|
116943
117377
|
}
|
|
116944
117378
|
} else {
|
|
116945
|
-
result.push([
|
|
117379
|
+
result.push([path52, data]);
|
|
116946
117380
|
}
|
|
116947
117381
|
}
|
|
116948
117382
|
deserialize(serialized) {
|
|
116949
117383
|
const arrayPushStyles = /* @__PURE__ */ new WeakSet();
|
|
116950
117384
|
const root = new NullProtoObj();
|
|
116951
|
-
for (const [
|
|
116952
|
-
const segments = this.parsePath(
|
|
117385
|
+
for (const [path52, value2] of serialized) {
|
|
117386
|
+
const segments = this.parsePath(path52);
|
|
116953
117387
|
let currentRef = root;
|
|
116954
117388
|
let nextSegment = segments[0];
|
|
116955
117389
|
for (let i10 = 1; i10 < segments.length; i10++) {
|
|
@@ -117000,13 +117434,13 @@ var BracketNotationSerializer = class {
|
|
|
117000
117434
|
}
|
|
117001
117435
|
return result;
|
|
117002
117436
|
}
|
|
117003
|
-
parsePath(
|
|
117437
|
+
parsePath(path52) {
|
|
117004
117438
|
const segments = [];
|
|
117005
117439
|
let inBrackets = false;
|
|
117006
117440
|
let currentSegment = "";
|
|
117007
|
-
for (let i10 = 0; i10 <
|
|
117008
|
-
const char =
|
|
117009
|
-
const nextChar =
|
|
117441
|
+
for (let i10 = 0; i10 < path52.length; i10++) {
|
|
117442
|
+
const char = path52[i10];
|
|
117443
|
+
const nextChar = path52[i10 + 1];
|
|
117010
117444
|
if (inBrackets && char === "]" && (nextChar === void 0 || nextChar === "[")) {
|
|
117011
117445
|
if (nextChar === void 0) {
|
|
117012
117446
|
inBrackets = false;
|
|
@@ -117022,7 +117456,7 @@ var BracketNotationSerializer = class {
|
|
|
117022
117456
|
currentSegment += char;
|
|
117023
117457
|
}
|
|
117024
117458
|
}
|
|
117025
|
-
return inBrackets || segments.length === 0 ? [
|
|
117459
|
+
return inBrackets || segments.length === 0 ? [path52] : segments;
|
|
117026
117460
|
}
|
|
117027
117461
|
};
|
|
117028
117462
|
var INTEGER_PATTERN = /^0$|^[1-9]\d*$/;
|
|
@@ -117595,11 +118029,11 @@ var OpenAPISerializer = class {
|
|
|
117595
118029
|
return json2;
|
|
117596
118030
|
}
|
|
117597
118031
|
const form = new FormData();
|
|
117598
|
-
for (const [
|
|
118032
|
+
for (const [path52, value22] of this.bracketNotation.serialize(json2)) {
|
|
117599
118033
|
if (value22 instanceof Blob) {
|
|
117600
|
-
form.append(
|
|
118034
|
+
form.append(path52, value22);
|
|
117601
118035
|
} else if (value22 !== void 0 && value22 !== null) {
|
|
117602
|
-
form.append(
|
|
118036
|
+
form.append(path52, String(value22));
|
|
117603
118037
|
}
|
|
117604
118038
|
}
|
|
117605
118039
|
return form;
|
|
@@ -117637,30 +118071,30 @@ function isBodylessMethod(method) {
|
|
|
117637
118071
|
return method === "GET" || method === "HEAD";
|
|
117638
118072
|
}
|
|
117639
118073
|
var PARAMETER_NAME_REGEX = /^[\w-]+$/;
|
|
117640
|
-
function getDynamicPathParams(
|
|
117641
|
-
if (!
|
|
118074
|
+
function getDynamicPathParams(path52) {
|
|
118075
|
+
if (!path52.includes("{")) {
|
|
117642
118076
|
return void 0;
|
|
117643
118077
|
}
|
|
117644
|
-
const len =
|
|
118078
|
+
const len = path52.length;
|
|
117645
118079
|
let params;
|
|
117646
118080
|
let index = 1;
|
|
117647
118081
|
while (index < len) {
|
|
117648
118082
|
const segmentStart = index;
|
|
117649
|
-
const slashPos =
|
|
118083
|
+
const slashPos = path52.indexOf("/", index);
|
|
117650
118084
|
const segmentEnd = slashPos === -1 ? len : slashPos;
|
|
117651
|
-
if (segmentEnd > segmentStart &&
|
|
118085
|
+
if (segmentEnd > segmentStart && path52.charCodeAt(segmentStart) === 123 && path52.charCodeAt(segmentEnd - 1) === 125) {
|
|
117652
118086
|
let parameterStart = segmentStart + 1;
|
|
117653
118087
|
let allowsSlash = false;
|
|
117654
|
-
const operator =
|
|
118088
|
+
const operator = path52.charCodeAt(parameterStart);
|
|
117655
118089
|
if (operator === 43) {
|
|
117656
118090
|
allowsSlash = true;
|
|
117657
118091
|
parameterStart++;
|
|
117658
118092
|
}
|
|
117659
|
-
const parameterName =
|
|
118093
|
+
const parameterName = path52.slice(parameterStart, segmentEnd - 1);
|
|
117660
118094
|
if (PARAMETER_NAME_REGEX.test(parameterName)) {
|
|
117661
118095
|
params ??= [];
|
|
117662
118096
|
params.push({
|
|
117663
|
-
segment:
|
|
118097
|
+
segment: path52.slice(segmentStart, segmentEnd),
|
|
117664
118098
|
startIndex: segmentStart,
|
|
117665
118099
|
parameterName,
|
|
117666
118100
|
allowsSlash
|
|
@@ -117703,8 +118137,8 @@ openapi.method = (method) => ({
|
|
|
117703
118137
|
...openapi({ method }),
|
|
117704
118138
|
name: "~openapi/method"
|
|
117705
118139
|
});
|
|
117706
|
-
openapi.path = (
|
|
117707
|
-
...openapi({ path:
|
|
118140
|
+
openapi.path = (path52) => ({
|
|
118141
|
+
...openapi({ path: path52 }),
|
|
117708
118142
|
name: "~openapi/path"
|
|
117709
118143
|
});
|
|
117710
118144
|
openapi.spec = (spec) => ({
|
|
@@ -118565,22 +118999,22 @@ function visitJsonSchemaRefs(value2, visit2, schemaLevel = true, seen = /* @__PU
|
|
|
118565
118999
|
}
|
|
118566
119000
|
}
|
|
118567
119001
|
}
|
|
118568
|
-
function mapJsonSchemaRefs(value2, map2, schemaLevel = true,
|
|
119002
|
+
function mapJsonSchemaRefs(value2, map2, schemaLevel = true, path52 = []) {
|
|
118569
119003
|
if (!value2 || typeof value2 !== "object") {
|
|
118570
119004
|
return value2;
|
|
118571
119005
|
}
|
|
118572
119006
|
if (Array.isArray(value2)) {
|
|
118573
|
-
return value2.map((item, index) => mapJsonSchemaRefs(item, map2, schemaLevel, [...
|
|
119007
|
+
return value2.map((item, index) => mapJsonSchemaRefs(item, map2, schemaLevel, [...path52, index]));
|
|
118574
119008
|
}
|
|
118575
119009
|
const result = {};
|
|
118576
119010
|
for (const key of Object.keys(value2)) {
|
|
118577
119011
|
const val = value2[key];
|
|
118578
119012
|
if (key === "$ref" && typeof val === "string") {
|
|
118579
|
-
setOwn(result, key, map2(val, [...
|
|
119013
|
+
setOwn(result, key, map2(val, [...path52, key]));
|
|
118580
119014
|
} else if (!schemaLevel) {
|
|
118581
|
-
setOwn(result, key, mapJsonSchemaRefs(val, map2, true, [...
|
|
119015
|
+
setOwn(result, key, mapJsonSchemaRefs(val, map2, true, [...path52, key]));
|
|
118582
119016
|
} else if (JSON_SCHEMA_LOGIC_KEYWORDS.has(key) || JSON_SCHEMA_RECORD_KEYWORDS.has(key)) {
|
|
118583
|
-
setOwn(result, key, mapJsonSchemaRefs(val, map2, !JSON_SCHEMA_RECORD_KEYWORDS.has(key), [...
|
|
119017
|
+
setOwn(result, key, mapJsonSchemaRefs(val, map2, !JSON_SCHEMA_RECORD_KEYWORDS.has(key), [...path52, key]));
|
|
118584
119018
|
} else {
|
|
118585
119019
|
setOwn(result, key, val);
|
|
118586
119020
|
}
|
|
@@ -119110,7 +119544,7 @@ function unlazy(maybeLazy) {
|
|
|
119110
119544
|
function createProcedureClient(lazyableProcedure, ...rest) {
|
|
119111
119545
|
const options = resolveMaybeOptionalOptions(rest);
|
|
119112
119546
|
return async (...[input2, callerOptions]) => {
|
|
119113
|
-
const
|
|
119547
|
+
const path52 = toArray(options.path);
|
|
119114
119548
|
const { default: procedure } = await unlazy(lazyableProcedure);
|
|
119115
119549
|
const clientContext = callerOptions?.context ?? {};
|
|
119116
119550
|
const context = await value(options.context, clientContext) ?? {};
|
|
@@ -119123,7 +119557,7 @@ function createProcedureClient(lazyableProcedure, ...rest) {
|
|
|
119123
119557
|
};
|
|
119124
119558
|
try {
|
|
119125
119559
|
const output2 = await runWithSpan("call_procedure", (span) => {
|
|
119126
|
-
span?.setAttribute("procedure.path",
|
|
119560
|
+
span?.setAttribute("procedure.path", path52);
|
|
119127
119561
|
return intercept(
|
|
119128
119562
|
options.interceptors,
|
|
119129
119563
|
{
|
|
@@ -119131,7 +119565,7 @@ function createProcedureClient(lazyableProcedure, ...rest) {
|
|
|
119131
119565
|
// input can be optional if it is undefinable
|
|
119132
119566
|
input: input2,
|
|
119133
119567
|
errors,
|
|
119134
|
-
path:
|
|
119568
|
+
path: path52,
|
|
119135
119569
|
procedure,
|
|
119136
119570
|
signal: callerOptions?.signal,
|
|
119137
119571
|
lastEventId: callerOptions?.lastEventId
|
|
@@ -119382,10 +119816,10 @@ function augmentRouter(router, options) {
|
|
|
119382
119816
|
}
|
|
119383
119817
|
return enhanced;
|
|
119384
119818
|
}
|
|
119385
|
-
function getRouter(router,
|
|
119819
|
+
function getRouter(router, path52) {
|
|
119386
119820
|
let current = router;
|
|
119387
|
-
for (let i10 = 0; i10 <
|
|
119388
|
-
const segment =
|
|
119821
|
+
for (let i10 = 0; i10 < path52.length; i10++) {
|
|
119822
|
+
const segment = path52[i10];
|
|
119389
119823
|
if (!isTypescriptObject(current)) {
|
|
119390
119824
|
return void 0;
|
|
119391
119825
|
}
|
|
@@ -119397,7 +119831,7 @@ function getRouter(router, path51) {
|
|
|
119397
119831
|
continue;
|
|
119398
119832
|
}
|
|
119399
119833
|
const lazied = current;
|
|
119400
|
-
const rest =
|
|
119834
|
+
const rest = path52.slice(i10);
|
|
119401
119835
|
return new Lazy({
|
|
119402
119836
|
...lazied["~orpc"],
|
|
119403
119837
|
async loader() {
|
|
@@ -119412,40 +119846,40 @@ function getRouter(router, path51) {
|
|
|
119412
119846
|
}
|
|
119413
119847
|
return current;
|
|
119414
119848
|
}
|
|
119415
|
-
function walkProcedureContractsSync(router, callback,
|
|
119849
|
+
function walkProcedureContractsSync(router, callback, path52 = []) {
|
|
119416
119850
|
const lazyResults = [];
|
|
119417
|
-
walkProcedureContractsSyncInternal(router, callback,
|
|
119851
|
+
walkProcedureContractsSyncInternal(router, callback, path52.slice(), lazyResults);
|
|
119418
119852
|
return lazyResults;
|
|
119419
119853
|
}
|
|
119420
|
-
function walkProcedureContractsSyncInternal(router, callback,
|
|
119854
|
+
function walkProcedureContractsSyncInternal(router, callback, path52, lazyResults) {
|
|
119421
119855
|
const hiddenContract = getHiddenRouterContract(router);
|
|
119422
119856
|
if (hiddenContract !== void 0) {
|
|
119423
119857
|
router = hiddenContract;
|
|
119424
119858
|
}
|
|
119425
119859
|
if (router instanceof ProcedureContract) {
|
|
119426
|
-
callback(router,
|
|
119860
|
+
callback(router, path52.slice());
|
|
119427
119861
|
return;
|
|
119428
119862
|
}
|
|
119429
119863
|
if (!isTypescriptObject(router)) {
|
|
119430
119864
|
return;
|
|
119431
119865
|
}
|
|
119432
119866
|
for (const [key, value2] of Object.entries(router)) {
|
|
119433
|
-
|
|
119867
|
+
path52.push(key);
|
|
119434
119868
|
if (value2 instanceof Lazy) {
|
|
119435
|
-
lazyResults.push({ router: value2, path:
|
|
119869
|
+
lazyResults.push({ router: value2, path: path52.slice() });
|
|
119436
119870
|
} else {
|
|
119437
|
-
walkProcedureContractsSyncInternal(value2, callback,
|
|
119871
|
+
walkProcedureContractsSyncInternal(value2, callback, path52, lazyResults);
|
|
119438
119872
|
}
|
|
119439
|
-
|
|
119873
|
+
path52.pop();
|
|
119440
119874
|
}
|
|
119441
119875
|
}
|
|
119442
|
-
async function walkProcedureContractsAsync(router, callback,
|
|
119876
|
+
async function walkProcedureContractsAsync(router, callback, path52 = []) {
|
|
119443
119877
|
const hiddenContract = getHiddenRouterContract(router);
|
|
119444
119878
|
if (hiddenContract !== void 0) {
|
|
119445
119879
|
router = hiddenContract;
|
|
119446
119880
|
}
|
|
119447
119881
|
if (router instanceof ProcedureContract) {
|
|
119448
|
-
await callback(router,
|
|
119882
|
+
await callback(router, path52);
|
|
119449
119883
|
return;
|
|
119450
119884
|
}
|
|
119451
119885
|
if (!isTypescriptObject(router)) {
|
|
@@ -119454,9 +119888,9 @@ async function walkProcedureContractsAsync(router, callback, path51 = []) {
|
|
|
119454
119888
|
for (const [key, value2] of Object.entries(router)) {
|
|
119455
119889
|
if (value2 instanceof Lazy) {
|
|
119456
119890
|
const { default: router2 } = await unlazy(value2);
|
|
119457
|
-
await walkProcedureContractsAsync(router2, callback, [...
|
|
119891
|
+
await walkProcedureContractsAsync(router2, callback, [...path52, key]);
|
|
119458
119892
|
} else {
|
|
119459
|
-
await walkProcedureContractsAsync(value2, callback, [...
|
|
119893
|
+
await walkProcedureContractsAsync(value2, callback, [...path52, key]);
|
|
119460
119894
|
}
|
|
119461
119895
|
}
|
|
119462
119896
|
}
|
|
@@ -119942,18 +120376,18 @@ function rewriteComponentSchemaRefs(schema, renameMap) {
|
|
|
119942
120376
|
}
|
|
119943
120377
|
var OpenAPIGeneratorError = class extends TypeError {
|
|
119944
120378
|
};
|
|
119945
|
-
function toOpenAPIPath(
|
|
120379
|
+
function toOpenAPIPath(path52, dynamicPathParams) {
|
|
119946
120380
|
if (!dynamicPathParams?.length) {
|
|
119947
|
-
return
|
|
120381
|
+
return path52;
|
|
119948
120382
|
}
|
|
119949
120383
|
let normalized = "";
|
|
119950
120384
|
let currentIndex = 0;
|
|
119951
120385
|
for (const param of dynamicPathParams) {
|
|
119952
|
-
normalized +=
|
|
120386
|
+
normalized += path52.slice(currentIndex, param.startIndex);
|
|
119953
120387
|
normalized += `{${param.parameterName}}`;
|
|
119954
120388
|
currentIndex = param.startIndex + param.segment.length;
|
|
119955
120389
|
}
|
|
119956
|
-
normalized +=
|
|
120390
|
+
normalized += path52.slice(currentIndex);
|
|
119957
120391
|
return normalized;
|
|
119958
120392
|
}
|
|
119959
120393
|
function buildRequest(ctx, operation, def, meta3, dynamicPathParams) {
|
|
@@ -120387,8 +120821,8 @@ var OpenAPIGenerator = class {
|
|
|
120387
120821
|
customErrorResponseBodySchema: options.customErrorResponseBodySchema
|
|
120388
120822
|
};
|
|
120389
120823
|
const errors = [];
|
|
120390
|
-
await walkProcedureContractsAsync(router, (contract,
|
|
120391
|
-
if (value(options.filter, contract,
|
|
120824
|
+
await walkProcedureContractsAsync(router, (contract, path52) => {
|
|
120825
|
+
if (value(options.filter, contract, path52) === false) {
|
|
120392
120826
|
return;
|
|
120393
120827
|
}
|
|
120394
120828
|
try {
|
|
@@ -120400,7 +120834,7 @@ var OpenAPIGenerator = class {
|
|
|
120400
120834
|
`QUERY operations require OpenAPI 3.2, but version "${version2}" was requested.`
|
|
120401
120835
|
);
|
|
120402
120836
|
}
|
|
120403
|
-
const postPath = meta3?.path ?? pathToHttpPath(
|
|
120837
|
+
const postPath = meta3?.path ?? pathToHttpPath(path52);
|
|
120404
120838
|
const httpPath = meta3?.prefix ? mergeHttpPath(meta3.prefix, postPath) : postPath;
|
|
120405
120839
|
const dynamicPathParams = getDynamicPathParams(httpPath);
|
|
120406
120840
|
const openApiPath = toOpenAPIPath(httpPath, dynamicPathParams);
|
|
@@ -120409,7 +120843,7 @@ var OpenAPIGenerator = class {
|
|
|
120409
120843
|
operation = meta3.spec;
|
|
120410
120844
|
} else {
|
|
120411
120845
|
operation = {
|
|
120412
|
-
operationId: meta3?.operationId ??
|
|
120846
|
+
operationId: meta3?.operationId ?? path52.join("."),
|
|
120413
120847
|
summary: meta3?.summary,
|
|
120414
120848
|
description: meta3?.description,
|
|
120415
120849
|
deprecated: meta3?.deprecated,
|
|
@@ -120429,7 +120863,7 @@ var OpenAPIGenerator = class {
|
|
|
120429
120863
|
if (!(e14 instanceof OpenAPIGeneratorError)) {
|
|
120430
120864
|
throw e14;
|
|
120431
120865
|
}
|
|
120432
|
-
errors.push(`Procedure at ${
|
|
120866
|
+
errors.push(`Procedure at ${path52.join(".") || "(root)"}: ${e14.message}`);
|
|
120433
120867
|
}
|
|
120434
120868
|
});
|
|
120435
120869
|
if (errors.length) {
|
|
@@ -120737,7 +121171,7 @@ var ResetRowSchema = external_exports.strictObject({
|
|
|
120737
121171
|
var ResetScheduleSchema = external_exports.strictObject({ resets: external_exports.readonly(external_exports.array(ResetRowSchema)) });
|
|
120738
121172
|
|
|
120739
121173
|
// src/frontdoor/controlSchemas.ts
|
|
120740
|
-
var
|
|
121174
|
+
var import_node_path42 = __toESM(require("node:path"), 1);
|
|
120741
121175
|
init_zod();
|
|
120742
121176
|
init_schema2();
|
|
120743
121177
|
|
|
@@ -120949,11 +121383,11 @@ var FrontDoorSessionsOutputSchema = external_exports.strictObject({ sessions: ex
|
|
|
120949
121383
|
var CheckRunInputSchema = external_exports.strictObject({
|
|
120950
121384
|
path: external_exports.string().min(1),
|
|
120951
121385
|
identity: external_exports.string().min(1).optional()
|
|
120952
|
-
}).refine((input2) =>
|
|
121386
|
+
}).refine((input2) => import_node_path42.default.isAbsolute(input2.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
120953
121387
|
var PoolPickInputSchema = external_exports.strictObject({
|
|
120954
121388
|
pool: external_exports.string().min(1),
|
|
120955
121389
|
path: external_exports.string().min(1)
|
|
120956
|
-
}).refine((input2) =>
|
|
121390
|
+
}).refine((input2) => import_node_path42.default.isAbsolute(input2.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
120957
121391
|
var DoctorFindingSchema = external_exports.strictObject({
|
|
120958
121392
|
section: external_exports.enum(DOCTOR_SECTIONS),
|
|
120959
121393
|
subject: external_exports.string().optional(),
|
|
@@ -121274,16 +121708,16 @@ var StandardLink = class {
|
|
|
121274
121708
|
/**
|
|
121275
121709
|
* @throws ORPCError, transport-level errors (network failures, timeouts, etc.)
|
|
121276
121710
|
*/
|
|
121277
|
-
call(
|
|
121278
|
-
return runWithSpan(`${ORPC_NAME}.${
|
|
121711
|
+
call(path52, input2, options) {
|
|
121712
|
+
return runWithSpan(`${ORPC_NAME}.${path52.join("/")}`, (span) => {
|
|
121279
121713
|
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
121280
|
-
span?.setAttribute("rpc.method",
|
|
121714
|
+
span?.setAttribute("rpc.method", path52.join("."));
|
|
121281
121715
|
if (getTracer() && isAsyncIteratorObject(input2)) {
|
|
121282
121716
|
input2 = override(input2, traceAsyncIterator("consume_async_iterator_object_input", input2));
|
|
121283
121717
|
} else if (getTracer() && input2 instanceof ReadableStream) {
|
|
121284
121718
|
input2 = override(input2, traceReadableStream("consume_octet_stream_input", input2));
|
|
121285
121719
|
}
|
|
121286
|
-
return intercept(this.interceptors, { ...options, path:
|
|
121720
|
+
return intercept(this.interceptors, { ...options, path: path52, input: input2 }, async ({ path: path210, input: input22, ...options2 }) => {
|
|
121287
121721
|
const tracer = getTracer();
|
|
121288
121722
|
const activeSpan = tracer?.getActiveSpan() ?? span;
|
|
121289
121723
|
let request7 = await runWithSpan(
|
|
@@ -121340,18 +121774,18 @@ var RPCLinkCodec = class {
|
|
|
121340
121774
|
this.headers = options.headers ?? {};
|
|
121341
121775
|
this.serializer = options.serializer ?? new RPCSerializer();
|
|
121342
121776
|
}
|
|
121343
|
-
async encodeInput(input2,
|
|
121344
|
-
let headers = toResolvedStandardHeaders(await value(this.headers, options,
|
|
121777
|
+
async encodeInput(input2, path52, options) {
|
|
121778
|
+
let headers = toResolvedStandardHeaders(await value(this.headers, options, path52, input2));
|
|
121345
121779
|
if (options.lastEventId !== void 0) {
|
|
121346
121780
|
headers = mergeStandardHeaders(headers, { "last-event-id": options.lastEventId });
|
|
121347
121781
|
}
|
|
121348
|
-
const expectedMethod = await value(this.expectedMethod, options,
|
|
121349
|
-
const baseUrl = await value(this.baseUrl, options,
|
|
121782
|
+
const expectedMethod = await value(this.expectedMethod, options, path52, input2);
|
|
121783
|
+
const baseUrl = await value(this.baseUrl, options, path52, input2);
|
|
121350
121784
|
const [pathname, search, hash2] = parseStandardUrl(baseUrl);
|
|
121351
|
-
const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(
|
|
121785
|
+
const newPathname = `${pathname.replace(END_SLASH_REGEX, "")}${pathToHttpPath(path52)}`;
|
|
121352
121786
|
const serialized = this.serializer.serialize(input2);
|
|
121353
121787
|
if (expectedMethod === "GET" && !(serialized instanceof Blob) && !(serialized instanceof ReadableStream) && !(serialized instanceof FormData) && !isAsyncIteratorObject(serialized)) {
|
|
121354
|
-
const maxUrlLength = await value(this.maxUrlLength, options,
|
|
121788
|
+
const maxUrlLength = await value(this.maxUrlLength, options, path52, input2);
|
|
121355
121789
|
const mergedSearch = new URLSearchParams(search);
|
|
121356
121790
|
mergedSearch.append("data", stringifyJSON(serialized) ?? "");
|
|
121357
121791
|
const url22 = `${newPathname}?${mergedSearch}${hash2 ?? ""}`;
|
|
@@ -121436,8 +121870,8 @@ var FetchLinkTransport = class {
|
|
|
121436
121870
|
this.fetch = options.fetch ?? ((url2, init) => globalThis.fetch(url2, init));
|
|
121437
121871
|
this.toFetchRequestOptions = options.toFetchRequest;
|
|
121438
121872
|
}
|
|
121439
|
-
async send(standardRequest,
|
|
121440
|
-
let origin = await value(this.origin, options,
|
|
121873
|
+
async send(standardRequest, path52, options) {
|
|
121874
|
+
let origin = await value(this.origin, options, path52);
|
|
121441
121875
|
if (origin?.endsWith("/")) {
|
|
121442
121876
|
origin = origin.slice(0, -1);
|
|
121443
121877
|
}
|
|
@@ -121457,7 +121891,7 @@ var FetchLinkTransport = class {
|
|
|
121457
121891
|
}
|
|
121458
121892
|
}
|
|
121459
121893
|
const fetch3 = this.fetch;
|
|
121460
|
-
const response = await fetch3(url2, init, options,
|
|
121894
|
+
const response = await fetch3(url2, init, options, path52);
|
|
121461
121895
|
const standardResponse = toStandardLazyResponse(response);
|
|
121462
121896
|
return standardResponse;
|
|
121463
121897
|
}
|
|
@@ -121848,14 +122282,14 @@ var StandardHandler = class {
|
|
|
121848
122282
|
span?.setAttribute("url.path", request22.url);
|
|
121849
122283
|
return { matched: false };
|
|
121850
122284
|
}
|
|
121851
|
-
const { path:
|
|
121852
|
-
span?.updateName(`${ORPC_NAME}.${
|
|
122285
|
+
const { path: path52, procedure, decodeInput } = matchedOrNot;
|
|
122286
|
+
span?.updateName(`${ORPC_NAME}.${path52.join("/")}`);
|
|
121853
122287
|
span?.setAttribute("rpc.system", ORPC_NAME);
|
|
121854
|
-
span?.setAttribute("rpc.method",
|
|
122288
|
+
span?.setAttribute("rpc.method", path52.join("."));
|
|
121855
122289
|
try {
|
|
121856
122290
|
const response = await intercept(
|
|
121857
122291
|
this.interceptors,
|
|
121858
|
-
{ context: context2, prefix: prefix2, request: request22, path:
|
|
122292
|
+
{ context: context2, prefix: prefix2, request: request22, path: path52, procedure, decodeInput },
|
|
121859
122293
|
async ({ context: context3, prefix: prefix3, request: request32, path: path210, procedure: procedure2, decodeInput: decodeInput2 }) => {
|
|
121860
122294
|
step2 = "decode_input";
|
|
121861
122295
|
let input2 = await runWithSpan("decode_input", decodeInput2);
|
|
@@ -121889,7 +122323,7 @@ var StandardHandler = class {
|
|
|
121889
122323
|
message: `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.`,
|
|
121890
122324
|
cause: e14
|
|
121891
122325
|
}) : toORPCError(e14);
|
|
121892
|
-
const response = await this.codec.encodeError(error63, procedure,
|
|
122326
|
+
const response = await this.codec.encodeError(error63, procedure, path52, { context: context2, prefix: prefix2 });
|
|
121893
122327
|
return { matched: true, response };
|
|
121894
122328
|
}
|
|
121895
122329
|
}
|
|
@@ -121995,7 +122429,7 @@ var RPCMatcher = class {
|
|
|
121995
122429
|
this.rootRouter = router;
|
|
121996
122430
|
this.index(router);
|
|
121997
122431
|
}
|
|
121998
|
-
index(router,
|
|
122432
|
+
index(router, path52 = []) {
|
|
121999
122433
|
const lazyResults = walkProcedureContractsSync(router, (procedure, procedurePath) => {
|
|
122000
122434
|
if (!value(this.filter, procedure, procedurePath)) {
|
|
122001
122435
|
return;
|
|
@@ -122006,7 +122440,7 @@ var RPCMatcher = class {
|
|
|
122006
122440
|
// contract-first entries have no implementation yet, resolveProcedure fills it in on demand
|
|
122007
122441
|
procedure: procedure instanceof Procedure ? procedure : void 0
|
|
122008
122442
|
});
|
|
122009
|
-
},
|
|
122443
|
+
}, path52);
|
|
122010
122444
|
for (const result of lazyResults) {
|
|
122011
122445
|
this.pendingLazyRouters.set(pathToHttpPath(result.path), result);
|
|
122012
122446
|
}
|
|
@@ -122138,10 +122572,10 @@ var RPCHandlerCodec = class {
|
|
|
122138
122572
|
}
|
|
122139
122573
|
};
|
|
122140
122574
|
}
|
|
122141
|
-
encodeOutput(output2, procedure,
|
|
122575
|
+
encodeOutput(output2, procedure, path52, options) {
|
|
122142
122576
|
return {
|
|
122143
122577
|
headers: {},
|
|
122144
|
-
status: value(this.outputStatus, output2, procedure,
|
|
122578
|
+
status: value(this.outputStatus, output2, procedure, path52, options) ?? DEFAULT_SUCCESS_STATUS,
|
|
122145
122579
|
body: this.serializer.serialize(output2)
|
|
122146
122580
|
};
|
|
122147
122581
|
}
|
|
@@ -122195,39 +122629,39 @@ function createRouter() {
|
|
|
122195
122629
|
static: new NullProtoObj2()
|
|
122196
122630
|
};
|
|
122197
122631
|
}
|
|
122198
|
-
function scanFirstGroup(
|
|
122632
|
+
function scanFirstGroup(path52) {
|
|
122199
122633
|
let i10 = 0;
|
|
122200
122634
|
let depth = 0;
|
|
122201
|
-
for (; i10 <
|
|
122202
|
-
const c10 =
|
|
122635
|
+
for (; i10 < path52.length; i10++) {
|
|
122636
|
+
const c10 = path52.charCodeAt(i10);
|
|
122203
122637
|
if (c10 === 92) i10++;
|
|
122204
122638
|
else if (c10 === 40) depth++;
|
|
122205
122639
|
else if (c10 === 41 && depth > 0) depth--;
|
|
122206
122640
|
else if (c10 === 123 && depth === 0) break;
|
|
122207
122641
|
}
|
|
122208
|
-
if (i10 >=
|
|
122642
|
+
if (i10 >= path52.length) return;
|
|
122209
122643
|
let j10 = i10 + 1;
|
|
122210
122644
|
depth = 0;
|
|
122211
|
-
for (; j10 <
|
|
122212
|
-
const c10 =
|
|
122645
|
+
for (; j10 < path52.length; j10++) {
|
|
122646
|
+
const c10 = path52.charCodeAt(j10);
|
|
122213
122647
|
if (c10 === 92) j10++;
|
|
122214
122648
|
else if (c10 === 40) depth++;
|
|
122215
122649
|
else if (c10 === 41 && depth > 0) depth--;
|
|
122216
122650
|
else if (c10 === 125 && depth === 0) break;
|
|
122217
122651
|
}
|
|
122218
|
-
if (j10 >=
|
|
122219
|
-
const mod =
|
|
122652
|
+
if (j10 >= path52.length) return;
|
|
122653
|
+
const mod = path52[j10 + 1];
|
|
122220
122654
|
const hasMod = mod === "?" || mod === "+" || mod === "*";
|
|
122221
122655
|
return [
|
|
122222
|
-
|
|
122223
|
-
|
|
122224
|
-
|
|
122656
|
+
path52.slice(0, i10),
|
|
122657
|
+
path52.slice(i10 + 1, j10),
|
|
122658
|
+
path52.slice(j10 + (hasMod ? 2 : 1)),
|
|
122225
122659
|
hasMod ? mod : void 0
|
|
122226
122660
|
];
|
|
122227
122661
|
}
|
|
122228
|
-
function expandGroupDelimiters(
|
|
122229
|
-
if (!
|
|
122230
|
-
const group = scanFirstGroup(
|
|
122662
|
+
function expandGroupDelimiters(path52) {
|
|
122663
|
+
if (!path52.includes("{")) return;
|
|
122664
|
+
const group = scanFirstGroup(path52);
|
|
122231
122665
|
if (!group) return;
|
|
122232
122666
|
const [pre2, body, suf, mod] = group;
|
|
122233
122667
|
if (!mod) return [pre2 + body + suf];
|
|
@@ -122297,9 +122731,9 @@ function replaceSegmentWildcards(segment, unnamedStart, toGroupKey = toUnnamedGr
|
|
|
122297
122731
|
}
|
|
122298
122732
|
return [replaced, nextIndex];
|
|
122299
122733
|
}
|
|
122300
|
-
function encodeEscapes(
|
|
122301
|
-
if (!
|
|
122302
|
-
return
|
|
122734
|
+
function encodeEscapes(path52) {
|
|
122735
|
+
if (!path52.includes("\\")) return path52;
|
|
122736
|
+
return path52.replace(/\\([:(){}])/g, (_, c10) => "\uFFFD" + "ABCDE"[":(){}".indexOf(c10)]);
|
|
122303
122737
|
}
|
|
122304
122738
|
function segmentKey(segment) {
|
|
122305
122739
|
if (segment.startsWith("**")) return 2;
|
|
@@ -122328,22 +122762,22 @@ function expandModifiers(segments) {
|
|
|
122328
122762
|
return m10[2] === "+" ? [wc2] : [wc2, without];
|
|
122329
122763
|
}
|
|
122330
122764
|
}
|
|
122331
|
-
function normalizePath(
|
|
122332
|
-
if (!
|
|
122765
|
+
function normalizePath(path52) {
|
|
122766
|
+
if (!path52.includes("/.")) return path52;
|
|
122333
122767
|
const r10 = [];
|
|
122334
|
-
for (const s of
|
|
122768
|
+
for (const s of path52.split("/")) if (s === ".") continue;
|
|
122335
122769
|
else if (s === ".." && r10.length > 1) r10.pop();
|
|
122336
122770
|
else r10.push(s);
|
|
122337
122771
|
return r10.join("/") || "/";
|
|
122338
122772
|
}
|
|
122339
|
-
function splitPath(
|
|
122340
|
-
const s =
|
|
122773
|
+
function splitPath(path52) {
|
|
122774
|
+
const s = path52.split("/");
|
|
122341
122775
|
s.shift();
|
|
122342
122776
|
if (s[s.length - 1] === "") s.pop();
|
|
122343
122777
|
return s;
|
|
122344
122778
|
}
|
|
122345
|
-
function splitRoute(
|
|
122346
|
-
const s = splitPath(
|
|
122779
|
+
function splitRoute(path52) {
|
|
122780
|
+
const s = splitPath(path52);
|
|
122347
122781
|
while (s[s.length - 1] === "") s.pop();
|
|
122348
122782
|
return s;
|
|
122349
122783
|
}
|
|
@@ -122359,16 +122793,16 @@ function getMatchParams(segments, paramsMap) {
|
|
|
122359
122793
|
}
|
|
122360
122794
|
return params;
|
|
122361
122795
|
}
|
|
122362
|
-
function addRoute(ctx, method = "",
|
|
122796
|
+
function addRoute(ctx, method = "", path52, data) {
|
|
122363
122797
|
method = method.toUpperCase();
|
|
122364
|
-
if (
|
|
122365
|
-
const groupExpanded = expandGroupDelimiters(
|
|
122798
|
+
if (path52.charCodeAt(0) !== 47) path52 = `/${path52}`;
|
|
122799
|
+
const groupExpanded = expandGroupDelimiters(path52);
|
|
122366
122800
|
if (groupExpanded) {
|
|
122367
122801
|
for (const expandedPath of groupExpanded) addRoute(ctx, method, expandedPath, data);
|
|
122368
122802
|
return;
|
|
122369
122803
|
}
|
|
122370
|
-
|
|
122371
|
-
const segments = splitRoute(
|
|
122804
|
+
path52 = encodeEscapes(path52);
|
|
122805
|
+
const segments = splitRoute(path52);
|
|
122372
122806
|
const expanded = expandModifiers(segments);
|
|
122373
122807
|
if (expanded) {
|
|
122374
122808
|
for (const p of expanded) addRoute(ctx, method, p, data);
|
|
@@ -122459,15 +122893,15 @@ function getParamRegexp(segment, unnamedStart = 0) {
|
|
|
122459
122893
|
const regex = _s2.replace(/:([\w-]+)(?:\(([^)]*)\))?/g, (_, id2, p) => `(?<${toGroupName(id2)}>${p || "[^/]+"})`).replace(/\((?![?<])/g, () => `(?<${toUnnamedGroupKey(_i2++)}>`).replace(/\uFFFE(.)/g, (_, c10) => /[.*+?^${}()|[\]\\]/.test(c10) ? `\\${c10}` : c10);
|
|
122460
122894
|
return [new RegExp(`^${regex}$`), _i2];
|
|
122461
122895
|
}
|
|
122462
|
-
function findRoute(ctx, method = "",
|
|
122463
|
-
if (opts?.normalize)
|
|
122464
|
-
if (
|
|
122465
|
-
const staticNode = ctx.static[
|
|
122896
|
+
function findRoute(ctx, method = "", path52, opts) {
|
|
122897
|
+
if (opts?.normalize) path52 = normalizePath(path52);
|
|
122898
|
+
if (path52.charCodeAt(path52.length - 1) === 47) path52 = path52.slice(0, -1);
|
|
122899
|
+
const staticNode = ctx.static[path52];
|
|
122466
122900
|
if (staticNode && staticNode.methods) {
|
|
122467
122901
|
const staticMatch = staticNode.methods[method] || staticNode.methods[""];
|
|
122468
122902
|
if (staticMatch !== void 0) return staticMatch[0];
|
|
122469
122903
|
}
|
|
122470
|
-
const segments = splitPath(
|
|
122904
|
+
const segments = splitPath(path52);
|
|
122471
122905
|
const match = _lookupTree(ctx.root, method, segments, 0);
|
|
122472
122906
|
if (match === void 0) return;
|
|
122473
122907
|
if (opts?.params === false) return match;
|
|
@@ -122667,7 +123101,7 @@ var OpenAPIMatcher = class {
|
|
|
122667
123101
|
this.rootRouter = router;
|
|
122668
123102
|
this.index(router);
|
|
122669
123103
|
}
|
|
122670
|
-
index(router,
|
|
123104
|
+
index(router, path52 = []) {
|
|
122671
123105
|
const lazyResults = walkProcedureContractsSync(router, (contract, path210) => {
|
|
122672
123106
|
if (!value(this.filter, contract, path210)) {
|
|
122673
123107
|
return;
|
|
@@ -122682,7 +123116,7 @@ var OpenAPIMatcher = class {
|
|
|
122682
123116
|
contract,
|
|
122683
123117
|
procedure: contract instanceof Procedure ? contract : void 0
|
|
122684
123118
|
});
|
|
122685
|
-
},
|
|
123119
|
+
}, path52);
|
|
122686
123120
|
for (const result of lazyResults) {
|
|
122687
123121
|
const prefix = getOpenAPIMeta(result.router)?.prefix;
|
|
122688
123122
|
this.pendingLazyRouters.add({
|
|
@@ -122769,20 +123203,20 @@ var OpenAPIMatcher = class {
|
|
|
122769
123203
|
return entry.procedure;
|
|
122770
123204
|
}
|
|
122771
123205
|
};
|
|
122772
|
-
function toRou3Pattern(
|
|
122773
|
-
const params = getDynamicPathParams(
|
|
123206
|
+
function toRou3Pattern(path52) {
|
|
123207
|
+
const params = getDynamicPathParams(path52);
|
|
122774
123208
|
if (!params?.length) {
|
|
122775
|
-
return
|
|
123209
|
+
return path52;
|
|
122776
123210
|
}
|
|
122777
123211
|
for (let i10 = params.length - 1; i10 >= 0; i10--) {
|
|
122778
123212
|
const param = params[i10];
|
|
122779
123213
|
const pattern = param.allowsSlash ? `**:${param.parameterName}` : `:${param.parameterName}`;
|
|
122780
|
-
|
|
123214
|
+
path52 = path52.slice(0, param.startIndex) + pattern + path52.slice(param.startIndex + param.segment.length);
|
|
122781
123215
|
}
|
|
122782
|
-
return
|
|
123216
|
+
return path52;
|
|
122783
123217
|
}
|
|
122784
|
-
function toRou3PrefixMatcher(
|
|
122785
|
-
const pattern = toRou3Pattern(
|
|
123218
|
+
function toRou3PrefixMatcher(path52) {
|
|
123219
|
+
const pattern = toRou3Pattern(path52);
|
|
122786
123220
|
return routeToRegExp(pattern === "/" ? "/**" : `${pattern}/**`);
|
|
122787
123221
|
}
|
|
122788
123222
|
function decodeParams(params) {
|
|
@@ -122861,7 +123295,7 @@ var OpenAPIHandlerCodecCore = class {
|
|
|
122861
123295
|
/**
|
|
122862
123296
|
* @throws {TypeError} If `outputStructure` is "detailed" and the output doesn't match the expected structure.
|
|
122863
123297
|
*/
|
|
122864
|
-
encodeOutput(output2, procedure,
|
|
123298
|
+
encodeOutput(output2, procedure, path52) {
|
|
122865
123299
|
const meta3 = getOpenAPIMeta(procedure);
|
|
122866
123300
|
const successStatus = meta3?.successStatus ?? DEFAULT_SUCCESS_STATUS;
|
|
122867
123301
|
const outputStructure = meta3?.outputStructure ?? DEFAULT_OPENAPI_OUTPUT_STRUCTURE;
|
|
@@ -122874,7 +123308,7 @@ var OpenAPIHandlerCodecCore = class {
|
|
|
122874
123308
|
}
|
|
122875
123309
|
if (!isValidDetailedOutput(output2)) {
|
|
122876
123310
|
throw new TypeError(`
|
|
122877
|
-
Invalid "detailed" output structure returned by procedure (${
|
|
123311
|
+
Invalid "detailed" output structure returned by procedure (${path52.join(".")}):
|
|
122878
123312
|
\u2022 Expected an object with optional properties:
|
|
122879
123313
|
- status (number <400)
|
|
122880
123314
|
- headers (object)
|
|
@@ -123262,7 +123696,8 @@ var IdentityValueSchema = external_exports.strictObject({
|
|
|
123262
123696
|
name: external_exports.string(),
|
|
123263
123697
|
defaultConfigProfile: external_exports.string().optional(),
|
|
123264
123698
|
allowAmbientCredential: external_exports.boolean(),
|
|
123265
|
-
credential: CredentialSummarySchema2.optional()
|
|
123699
|
+
credential: CredentialSummarySchema2.optional(),
|
|
123700
|
+
anchors: external_exports.array(AnchorSchema).optional()
|
|
123266
123701
|
});
|
|
123267
123702
|
var ProfileValueSchema = ConfigProfileSchema.omit({ $schema: true });
|
|
123268
123703
|
var ProviderValueSchema = external_exports.strictObject({
|
|
@@ -123280,7 +123715,9 @@ var ConfigIdentitySetInputSchema = external_exports.strictObject({
|
|
|
123280
123715
|
name: external_exports.string().min(1),
|
|
123281
123716
|
defaultConfigProfile: external_exports.union([external_exports.string().min(1), external_exports.literal(false)]).optional(),
|
|
123282
123717
|
allowAmbientCredential: external_exports.boolean().optional(),
|
|
123283
|
-
credential: external_exports.union([external_exports.literal(false), CredentialWriteSchema(CREDENTIAL_TARGETS)]).optional()
|
|
123718
|
+
credential: external_exports.union([external_exports.literal(false), CredentialWriteSchema(CREDENTIAL_TARGETS)]).optional(),
|
|
123719
|
+
/** `false` removes the anchors; a list replaces them. */
|
|
123720
|
+
anchors: external_exports.union([external_exports.literal(false), external_exports.array(AnchorSchema).min(1)]).optional()
|
|
123284
123721
|
});
|
|
123285
123722
|
var ConfigIdentitySetOutputSchema = storedMutationOutput("identity", "updated", IdentityValueSchema);
|
|
123286
123723
|
var ConfigIdentityRemoveInputSchema = external_exports.strictObject({ name: external_exports.string().min(1), confirm: RemovalConfirmationSchema });
|
|
@@ -123401,7 +123838,8 @@ function identityValue(name, paths) {
|
|
|
123401
123838
|
name: identity.name,
|
|
123402
123839
|
...identity.defaultConfigProfile === void 0 ? {} : { defaultConfigProfile: identity.defaultConfigProfile },
|
|
123403
123840
|
allowAmbientCredential: identity.allowAmbientCredential,
|
|
123404
|
-
...identity.credential === void 0 ? {} : { credential: summariseCredential(identity.credential) }
|
|
123841
|
+
...identity.credential === void 0 ? {} : { credential: summariseCredential(identity.credential) },
|
|
123842
|
+
...identity.anchors === void 0 ? {} : { anchors: identity.anchors }
|
|
123405
123843
|
};
|
|
123406
123844
|
}
|
|
123407
123845
|
function providerValue(name, provider) {
|
|
@@ -123422,7 +123860,7 @@ function profileValue(name, paths) {
|
|
|
123422
123860
|
function createConfigApiRouter(deps) {
|
|
123423
123861
|
const authed = doorApiAuth(deps.expectedToken);
|
|
123424
123862
|
const { paths } = deps;
|
|
123425
|
-
const route = (
|
|
123863
|
+
const route = (path52, summary) => authed.meta(openapi({ method: "POST", path: path52, summary, tags: [CONFIG_API_TAG] }));
|
|
123426
123864
|
return {
|
|
123427
123865
|
config: {
|
|
123428
123866
|
identity: {
|
|
@@ -123432,9 +123870,9 @@ function createConfigApiRouter(deps) {
|
|
|
123432
123870
|
return { action: "created", kind: "identity", name: input2.name, value: identityValue(input2.name, paths) };
|
|
123433
123871
|
})
|
|
123434
123872
|
),
|
|
123435
|
-
set: route("/rest/config/identity/set", "Update an identity's default profile, ambient-credential setting or
|
|
123873
|
+
set: route("/rest/config/identity/set", "Update an identity's default profile, ambient-credential setting, credential or anchors").input(ConfigIdentitySetInputSchema).output(ConfigIdentitySetOutputSchema).handler(
|
|
123436
123874
|
({ input: input2 }) => guarded(() => {
|
|
123437
|
-
requireChange(input2.defaultConfigProfile !== void 0 || input2.allowAmbientCredential !== void 0 || input2.credential !== void 0, "defaultConfigProfile, allowAmbientCredential or
|
|
123875
|
+
requireChange(input2.defaultConfigProfile !== void 0 || input2.allowAmbientCredential !== void 0 || input2.credential !== void 0 || input2.anchors !== void 0, "defaultConfigProfile, allowAmbientCredential, credential or anchors");
|
|
123438
123876
|
if (!identityExists(paths, input2.name)) {
|
|
123439
123877
|
throw new IdentityNotFoundError(input2.name);
|
|
123440
123878
|
}
|
|
@@ -123459,6 +123897,9 @@ function createConfigApiRouter(deps) {
|
|
|
123459
123897
|
};
|
|
123460
123898
|
setIdentityCredential(paths, input2.name, change);
|
|
123461
123899
|
}
|
|
123900
|
+
if (input2.anchors !== void 0) {
|
|
123901
|
+
setIdentityAnchors(paths, input2.name, input2.anchors === false ? void 0 : input2.anchors);
|
|
123902
|
+
}
|
|
123462
123903
|
return { action: "updated", kind: "identity", name: input2.name, value: identityValue(input2.name, paths) };
|
|
123463
123904
|
})
|
|
123464
123905
|
),
|
|
@@ -123684,7 +124125,9 @@ var DoorHealthEventSchema = external_exports.discriminatedUnion("kind", [
|
|
|
123684
124125
|
external_exports.strictObject({ kind: external_exports.literal("generation"), pid: external_exports.number().int().positive(), providerPort: external_exports.number().int().positive(), connectPort: external_exports.number().int().positive(), directPort: external_exports.number().int().positive(), observedAt: external_exports.number() }),
|
|
123685
124126
|
external_exports.strictObject({ kind: external_exports.literal("listenerFailed"), pid: external_exports.number().int().positive(), listener: external_exports.enum(["provider", "connect", "direct"]), message: external_exports.string(), observedAt: external_exports.number() }),
|
|
123686
124127
|
external_exports.strictObject({ kind: external_exports.literal("binaryTurnover"), pid: external_exports.number().int().positive(), observedAt: external_exports.number() }),
|
|
123687
|
-
external_exports.strictObject({ kind: external_exports.literal("idleShutdown"), pid: external_exports.number().int().positive(), observedAt: external_exports.number() })
|
|
124128
|
+
external_exports.strictObject({ kind: external_exports.literal("idleShutdown"), pid: external_exports.number().int().positive(), observedAt: external_exports.number() }),
|
|
124129
|
+
external_exports.strictObject({ kind: external_exports.literal("superseded"), pid: external_exports.number().int().positive(), ownerPid: external_exports.number().int().positive(), observedAt: external_exports.number() }),
|
|
124130
|
+
external_exports.strictObject({ kind: external_exports.literal("drained"), pid: external_exports.number().int().positive(), observedAt: external_exports.number() })
|
|
123688
124131
|
]);
|
|
123689
124132
|
var QuotaExpiringEventSchema = external_exports.strictObject({
|
|
123690
124133
|
identity: external_exports.string().min(1),
|
|
@@ -123772,7 +124215,7 @@ function createLifecycleApiRouter(deps) {
|
|
|
123772
124215
|
init_cliError();
|
|
123773
124216
|
|
|
123774
124217
|
// src/frontdoor/launchSchemas.ts
|
|
123775
|
-
var
|
|
124218
|
+
var import_node_path43 = __toESM(require("node:path"), 1);
|
|
123776
124219
|
init_zod();
|
|
123777
124220
|
init_claudeVersion();
|
|
123778
124221
|
init_identity();
|
|
@@ -123782,7 +124225,7 @@ var LaunchResolveInputSchema = external_exports.strictObject({
|
|
|
123782
124225
|
argv: external_exports.readonly(external_exports.array(external_exports.string())).optional(),
|
|
123783
124226
|
/** The launch's inherited environment. Absent means an empty one: the door's own environment is never a substitute for the caller's, so a caller that wants `AGENT_SHIM_*` switches or a `CLAUDE_CONFIG_DIR` considered names them here. Values are read, never reported. */
|
|
123784
124227
|
env: external_exports.record(external_exports.string(), external_exports.string()).optional()
|
|
123785
|
-
}).refine((input2) =>
|
|
124228
|
+
}).refine((input2) => import_node_path43.default.isAbsolute(input2.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
123786
124229
|
var LaunchPoolDecisionSchema = external_exports.strictObject({
|
|
123787
124230
|
name: external_exports.string(),
|
|
123788
124231
|
reasons: external_exports.readonly(external_exports.array(external_exports.string())),
|
|
@@ -123939,6 +124382,12 @@ function createDoorHealthPublisher(hub, now, pid) {
|
|
|
123939
124382
|
},
|
|
123940
124383
|
binaryTurnover: () => {
|
|
123941
124384
|
publisher.publish({ kind: "binaryTurnover", pid, observedAt: now() });
|
|
124385
|
+
},
|
|
124386
|
+
superseded: (ownerPid) => {
|
|
124387
|
+
publisher.publish({ kind: "superseded", pid, ownerPid, observedAt: now() });
|
|
124388
|
+
},
|
|
124389
|
+
drained: () => {
|
|
124390
|
+
publisher.publish({ kind: "drained", pid, observedAt: now() });
|
|
123942
124391
|
}
|
|
123943
124392
|
};
|
|
123944
124393
|
}
|
|
@@ -124052,11 +124501,11 @@ function rcFanoutOnDoorHub(fanout, hub) {
|
|
|
124052
124501
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
124053
124502
|
init_schema2();
|
|
124054
124503
|
var MS_PER_HOUR4 = 36e5;
|
|
124055
|
-
var
|
|
124504
|
+
var MS_PER_DAY4 = 864e5;
|
|
124056
124505
|
var FIVE_HOUR_WINDOW_HOURS = 5;
|
|
124057
124506
|
var SEVEN_DAY_WINDOW_DAYS = 7;
|
|
124058
124507
|
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS * MS_PER_HOUR4;
|
|
124059
|
-
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS *
|
|
124508
|
+
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS * MS_PER_DAY4;
|
|
124060
124509
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
124061
124510
|
var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
|
|
124062
124511
|
function createQuotaExpiringPublisher(hub, deps) {
|
|
@@ -124854,17 +125303,17 @@ function unifiedQuotaHeaders(upstream, rejected, quotaError) {
|
|
|
124854
125303
|
}
|
|
124855
125304
|
return headers;
|
|
124856
125305
|
}
|
|
124857
|
-
var
|
|
125306
|
+
var MS_PER_SECOND8 = 1e3;
|
|
124858
125307
|
function buildUsageSnapshot(upstream, quotaError, nowMs) {
|
|
124859
125308
|
const used7 = upstream.get("x-codex-primary-used-percent") ?? (quotaError === void 0 ? null : EXHAUSTED_PERCENT);
|
|
124860
125309
|
const reset7 = upstream.get("x-codex-primary-reset-at") ?? (quotaError?.resets_at === void 0 ? null : String(quotaError.resets_at));
|
|
124861
|
-
const sevenDay = used7 !== null && reset7 !== null ? { used_percentage: Number(used7), resets_at: new Date(Number(reset7) *
|
|
125310
|
+
const sevenDay = used7 !== null && reset7 !== null ? { used_percentage: Number(used7), resets_at: new Date(Number(reset7) * MS_PER_SECOND8).toISOString() } : void 0;
|
|
124862
125311
|
let fiveHour;
|
|
124863
125312
|
if (Number(upstream.get("x-codex-secondary-window-minutes")) > 0) {
|
|
124864
125313
|
const used5 = upstream.get("x-codex-secondary-used-percent");
|
|
124865
125314
|
const reset5 = upstream.get("x-codex-secondary-reset-at");
|
|
124866
125315
|
if (used5 !== null && reset5 !== null) {
|
|
124867
|
-
fiveHour = { used_percentage: Number(used5), resets_at: new Date(Number(reset5) *
|
|
125316
|
+
fiveHour = { used_percentage: Number(used5), resets_at: new Date(Number(reset5) * MS_PER_SECOND8).toISOString() };
|
|
124868
125317
|
}
|
|
124869
125318
|
}
|
|
124870
125319
|
if (sevenDay === void 0 && fiveHour === void 0) {
|
|
@@ -125273,8 +125722,8 @@ function createCodexRouteMount(ports, upstreamBase, provider) {
|
|
|
125273
125722
|
request7.body.resume();
|
|
125274
125723
|
return;
|
|
125275
125724
|
}
|
|
125276
|
-
const
|
|
125277
|
-
const translated = { method: request7.method, path:
|
|
125725
|
+
const path52 = new URL(request7.url, "http://127.0.0.1").pathname;
|
|
125726
|
+
const translated = { method: request7.method, path: path52, body, signal: request7.signal };
|
|
125278
125727
|
const routed = await route(translated);
|
|
125279
125728
|
if (request7.signal.aborted) {
|
|
125280
125729
|
return;
|
|
@@ -125308,7 +125757,7 @@ function createPassthroughRoute(name, target) {
|
|
|
125308
125757
|
headroomUpstream: target.headroomUpstream,
|
|
125309
125758
|
serve: async (request7, response) => {
|
|
125310
125759
|
const incoming = new URL(request7.url, "http://127.0.0.1");
|
|
125311
|
-
const
|
|
125760
|
+
const path52 = target.stripPrefix !== void 0 && incoming.pathname.startsWith(target.stripPrefix) ? incoming.pathname.slice(target.stripPrefix.length) : incoming.pathname;
|
|
125312
125761
|
const headers = forwardableHeaders(request7.headers);
|
|
125313
125762
|
delete headers.host;
|
|
125314
125763
|
await new Promise((resolve2) => {
|
|
@@ -125316,7 +125765,7 @@ function createPassthroughRoute(name, target) {
|
|
|
125316
125765
|
host: base.hostname,
|
|
125317
125766
|
port: base.port === "" ? void 0 : Number(base.port),
|
|
125318
125767
|
method: request7.method,
|
|
125319
|
-
path: `${basePath}${
|
|
125768
|
+
path: `${basePath}${path52}${incoming.search}`,
|
|
125320
125769
|
headers,
|
|
125321
125770
|
agent
|
|
125322
125771
|
};
|
|
@@ -125449,7 +125898,7 @@ async function scanRequestHead(request7, wholeBody = false) {
|
|
|
125449
125898
|
|
|
125450
125899
|
// src/frontdoor/providerRoute.ts
|
|
125451
125900
|
function createProviderRouteResolver(deps) {
|
|
125452
|
-
const isRcSelfHostPath = (
|
|
125901
|
+
const isRcSelfHostPath = (path52) => path52 === "/v1/code/sessions" || path52.startsWith("/v1/code/sessions/") || path52 === "/v1/sessions" || path52.startsWith("/v1/sessions/");
|
|
125453
125902
|
const oauthRoute = createPassthroughRoute("anthropic", { baseUrl: `https://${CONNECT_INTERCEPT_HOST}:${String(HTTPS_PORT)}`, stripPrefix: void 0, headroomUpstream: void 0 });
|
|
125454
125903
|
const passthroughByTarget = /* @__PURE__ */ new Map();
|
|
125455
125904
|
const passthroughFor = (name, target) => {
|
|
@@ -125463,16 +125912,16 @@ function createProviderRouteResolver(deps) {
|
|
|
125463
125912
|
return route;
|
|
125464
125913
|
};
|
|
125465
125914
|
const resolve2 = (request7) => {
|
|
125466
|
-
const
|
|
125467
|
-
const scoped = parseProviderPath(
|
|
125915
|
+
const path52 = new URL(request7.url, "http://127.0.0.1").pathname;
|
|
125916
|
+
const scoped = parseProviderPath(path52);
|
|
125468
125917
|
if (scoped === void 0) {
|
|
125469
|
-
if (deps.rcSelfHostRoute !== void 0 && isRcSelfHostPath(
|
|
125918
|
+
if (deps.rcSelfHostRoute !== void 0 && isRcSelfHostPath(path52)) {
|
|
125470
125919
|
return { ok: true, route: deps.rcSelfHostRoute };
|
|
125471
125920
|
}
|
|
125472
|
-
if (request7.session.provider !== void 0 &&
|
|
125921
|
+
if (request7.session.provider !== void 0 && path52.startsWith("/v1/") && !isRcSelfHostPath(path52)) {
|
|
125473
125922
|
return resolve2({ ...request7, url: `${PROVIDER_PATH_PREFIX}${encodeURIComponent(request7.session.provider)}${request7.url}` });
|
|
125474
125923
|
}
|
|
125475
|
-
return
|
|
125924
|
+
return path52.startsWith("/v1/") ? { ok: true, route: oauthRoute } : { ok: false, status: HTTP_STATUS.notFound, message: `no such endpoint: ${path52}` };
|
|
125476
125925
|
}
|
|
125477
125926
|
const { provider } = scoped;
|
|
125478
125927
|
let definition;
|
|
@@ -125525,8 +125974,8 @@ function createProviderRouteResolver(deps) {
|
|
|
125525
125974
|
let replay;
|
|
125526
125975
|
const visited = /* @__PURE__ */ new Set();
|
|
125527
125976
|
for (; ; ) {
|
|
125528
|
-
const
|
|
125529
|
-
const scoped = parseProviderPath(
|
|
125977
|
+
const path52 = new URL(current.url, "http://127.0.0.1").pathname;
|
|
125978
|
+
const scoped = parseProviderPath(path52);
|
|
125530
125979
|
const providerName = scoped?.provider ?? current.session.provider;
|
|
125531
125980
|
if (providerName !== void 0 && visited.has(providerName)) {
|
|
125532
125981
|
return { ok: false, status: HTTP_STATUS.internalServerError, message: `provider routing cycle: ${[...visited, providerName].join(" -> ")}` };
|
|
@@ -125584,7 +126033,7 @@ function createProviderRouteResolver(deps) {
|
|
|
125584
126033
|
const headers = Object.fromEntries(Object.entries(replay.headers).filter(([name]) => name.toLowerCase() !== "content-length"));
|
|
125585
126034
|
replay = { ...replay, headers, body: import_node_stream3.Readable.from([Buffer.from(rewritten, "utf8")]) };
|
|
125586
126035
|
}
|
|
125587
|
-
const rest = scoped === void 0 ?
|
|
126036
|
+
const rest = scoped === void 0 ? path52 : path52.slice(`${PROVIDER_PATH_PREFIX}${encodeURIComponent(scoped.provider)}`.length);
|
|
125588
126037
|
const query = current.url.includes("?") ? current.url.slice(current.url.indexOf("?")) : "";
|
|
125589
126038
|
current = { ...current, url: `${PROVIDER_PATH_PREFIX}${encodeURIComponent(matched.provider)}${rest}${query}`, body: replay.body, headers: replay.headers };
|
|
125590
126039
|
}
|
|
@@ -125691,14 +126140,14 @@ function createRcLiveUsage(deps) {
|
|
|
125691
126140
|
}
|
|
125692
126141
|
|
|
125693
126142
|
// src/frontdoor/rcSelfHostMint.ts
|
|
125694
|
-
var
|
|
126143
|
+
var import_node_path44 = __toESM(require("node:path"), 1);
|
|
125695
126144
|
init_account();
|
|
125696
126145
|
|
|
125697
126146
|
// src/frontdoor/rcSelfHostLocal.ts
|
|
125698
126147
|
var RC_SELF_HOST_OAUTH_HOST = "platform.claude.com";
|
|
125699
126148
|
var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:claude_code", "user:mcp_servers", "user:file_upload"];
|
|
125700
126149
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
125701
|
-
var
|
|
126150
|
+
var MS_PER_SECOND9 = 1e3;
|
|
125702
126151
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
125703
126152
|
function isRecord6(value2) {
|
|
125704
126153
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
@@ -125754,7 +126203,7 @@ function createRcSelfHostLocal(deps) {
|
|
|
125754
126203
|
}
|
|
125755
126204
|
if (method === "POST" && pathname.startsWith("/api/eval/")) {
|
|
125756
126205
|
await deps.readBody(request7, CONTROL_BODY_CAP_BYTES);
|
|
125757
|
-
answerServerJson(response, HTTP_STATUS.ok, { features: growthBookFeatures(), dateUpdated: Math.floor(deps.now() /
|
|
126206
|
+
answerServerJson(response, HTTP_STATUS.ok, { features: growthBookFeatures(), dateUpdated: Math.floor(deps.now() / MS_PER_SECOND9) });
|
|
125758
126207
|
return true;
|
|
125759
126208
|
}
|
|
125760
126209
|
if (method === "GET" && pathname === "/api/oauth/profile") {
|
|
@@ -125821,7 +126270,7 @@ function readJsonObject(fs22, file2) {
|
|
|
125821
126270
|
return isRecord7(parsed) ? parsed : void 0;
|
|
125822
126271
|
}
|
|
125823
126272
|
function readRcSelfHostRecord(fs22, frontdoorDir) {
|
|
125824
|
-
const parsed = readJsonObject(fs22,
|
|
126273
|
+
const parsed = readJsonObject(fs22, import_node_path44.default.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
125825
126274
|
if (parsed === void 0) {
|
|
125826
126275
|
return void 0;
|
|
125827
126276
|
}
|
|
@@ -125835,11 +126284,11 @@ function mintRcSelfHostCredential(deps) {
|
|
|
125835
126284
|
if (!isIdentityName(deps.identity)) {
|
|
125836
126285
|
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
125837
126286
|
}
|
|
125838
|
-
const identityDir =
|
|
125839
|
-
const credentialsFile =
|
|
125840
|
-
const claudeJsonFile =
|
|
125841
|
-
const recordDir =
|
|
125842
|
-
const recordFile =
|
|
126287
|
+
const identityDir = import_node_path44.default.join(deps.identitiesDir, deps.identity);
|
|
126288
|
+
const credentialsFile = import_node_path44.default.join(identityDir, CREDENTIALS_FILE2);
|
|
126289
|
+
const claudeJsonFile = import_node_path44.default.join(identityDir, CLAUDE_JSON2);
|
|
126290
|
+
const recordDir = import_node_path44.default.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
126291
|
+
const recordFile = import_node_path44.default.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
125843
126292
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
125844
126293
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
125845
126294
|
const existingOauth = isRecord7(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
@@ -125855,7 +126304,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
125855
126304
|
const organizationUuid = deps.newUuid();
|
|
125856
126305
|
const accountUuid = deps.newUuid();
|
|
125857
126306
|
const mintedAt = new Date(deps.now()).toISOString();
|
|
125858
|
-
deps.fs.mkdirPrivate(
|
|
126307
|
+
deps.fs.mkdirPrivate(import_node_path44.default.dirname(credentialsFile));
|
|
125859
126308
|
deps.fs.writeFilePrivate(credentialsFile, `${JSON.stringify({ ...existingCredentials, claudeAiOauth: { accessToken, refreshToken, expiresAt: null, scopes: [...RC_SELF_HOST_SCOPE_LIST], subscriptionType: SELF_HOST_SUBSCRIPTION_TYPE, rateLimitTier: null } }, null, 2)}
|
|
125860
126309
|
`);
|
|
125861
126310
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
@@ -125938,12 +126387,12 @@ function eventExcerpt(text2) {
|
|
|
125938
126387
|
return text2.length <= RC_PENDING_SUMMARY_EXCERPT_CHARS ? text2 : `${text2.slice(0, RC_PENDING_SUMMARY_EXCERPT_CHARS)}...`;
|
|
125939
126388
|
}
|
|
125940
126389
|
var PERCENT_SCALE = 100;
|
|
125941
|
-
var
|
|
126390
|
+
var MS_PER_SECOND10 = 1e3;
|
|
125942
126391
|
function percentOf(fraction) {
|
|
125943
126392
|
return `${String(Math.round(fraction * PERCENT_SCALE))}%`;
|
|
125944
126393
|
}
|
|
125945
126394
|
function resetInstantOf(epochSeconds) {
|
|
125946
|
-
return new Date(epochSeconds *
|
|
126395
|
+
return new Date(epochSeconds * MS_PER_SECOND10).toISOString();
|
|
125947
126396
|
}
|
|
125948
126397
|
function formatRcRateLimitInfo(info) {
|
|
125949
126398
|
const parts = [info.status];
|
|
@@ -126242,7 +126691,7 @@ function registerRcCommand(frontdoor, paths) {
|
|
|
126242
126691
|
}
|
|
126243
126692
|
|
|
126244
126693
|
// src/frontdoor/rcCredentialStore.ts
|
|
126245
|
-
var
|
|
126694
|
+
var import_node_path45 = __toESM(require("node:path"), 1);
|
|
126246
126695
|
function isSafeSessionId(sessionId) {
|
|
126247
126696
|
return /^[A-Za-z0-9_-]+$/.test(sessionId);
|
|
126248
126697
|
}
|
|
@@ -126268,7 +126717,7 @@ function sequenceNumOfJson(value2) {
|
|
|
126268
126717
|
}
|
|
126269
126718
|
function createRcCredentialStore(fs22, dir) {
|
|
126270
126719
|
fs22.mkdirPrivate(dir);
|
|
126271
|
-
const fileFor = (sessionId) =>
|
|
126720
|
+
const fileFor = (sessionId) => import_node_path45.default.join(dir, `${sessionId}.json`);
|
|
126272
126721
|
const readParsed = (sessionId) => {
|
|
126273
126722
|
const raw = fs22.readFileUtf8(fileFor(sessionId));
|
|
126274
126723
|
if (raw === void 0) {
|
|
@@ -127378,7 +127827,7 @@ var RC_COMPAT_SESSIONS_PATH = "/v1/sessions";
|
|
|
127378
127827
|
var RC_SESSION_ID_PREFIX2 = "cse_";
|
|
127379
127828
|
var RC_SELF_HOST_API_BASE_URL = "https://api.anthropic.com";
|
|
127380
127829
|
var HTTP_CONFLICT = 409;
|
|
127381
|
-
var
|
|
127830
|
+
var MS_PER_SECOND11 = 1e3;
|
|
127382
127831
|
var HTTP_SERVICE_UNAVAILABLE2 = 503;
|
|
127383
127832
|
var RC_SELF_HOST_WORKER_JWT_TTL_SECONDS = 46800;
|
|
127384
127833
|
var RC_SELF_HOST_KEEPALIVE_MS = 15e3;
|
|
@@ -127478,7 +127927,7 @@ function parseJsonObject5(body) {
|
|
|
127478
127927
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
127479
127928
|
const encode3 = (value2) => Buffer.from(JSON.stringify(value2), "utf8").toString("base64url");
|
|
127480
127929
|
const header = encode3({ alg: "HS256", typ: "JWT" });
|
|
127481
|
-
const payload = encode3({ exp: Math.floor((issuedAt + RC_SELF_HOST_WORKER_JWT_TTL_SECONDS *
|
|
127930
|
+
const payload = encode3({ exp: Math.floor((issuedAt + RC_SELF_HOST_WORKER_JWT_TTL_SECONDS * MS_PER_SECOND11) / MS_PER_SECOND11), iat: Math.floor(issuedAt / MS_PER_SECOND11) });
|
|
127482
127931
|
return `${header}.${payload}.${Buffer.from(randomToken(), "utf8").toString("base64url")}`;
|
|
127483
127932
|
}
|
|
127484
127933
|
function createRcSelfHostSurface(deps) {
|
|
@@ -128549,6 +128998,28 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
128549
128998
|
const pools = readPools(paths);
|
|
128550
128999
|
void refreshStalePoolMembers({ poolNames: Object.keys(pools), pools, loadMembers: (identities) => loadPoolMembers(realFarmFs, paths, identities, Date.now()), refresher: anthropicRefresher });
|
|
128551
129000
|
}, ANTHROPIC_USAGE_FRESHNESS_MS).unref();
|
|
129001
|
+
const windowOpener = createRealWindowOpener({ paths, cwd: process.cwd(), spawnDaemon: spawnDetachedSupervisor });
|
|
129002
|
+
let keeperRunning = false;
|
|
129003
|
+
setInterval(() => {
|
|
129004
|
+
if (keeperRunning) {
|
|
129005
|
+
return;
|
|
129006
|
+
}
|
|
129007
|
+
keeperRunning = true;
|
|
129008
|
+
void runWindowKeeper({
|
|
129009
|
+
fs: realFarmFs,
|
|
129010
|
+
stampsFile: paths.usageAnchorsFile,
|
|
129011
|
+
nowMs: () => Date.now(),
|
|
129012
|
+
timeZone: machineTimeZone(),
|
|
129013
|
+
anchored: () => listAnchoredIdentities(paths),
|
|
129014
|
+
snapshot: (identity) => readUsageSnapshot(realFarmFs, paths.usageSnapshotsDir, identity),
|
|
129015
|
+
open: windowOpener,
|
|
129016
|
+
log
|
|
129017
|
+
}).catch((error63) => {
|
|
129018
|
+
log(`window keeper failed: ${error63 instanceof Error ? error63.message : String(error63)}`);
|
|
129019
|
+
}).finally(() => {
|
|
129020
|
+
keeperRunning = false;
|
|
129021
|
+
});
|
|
129022
|
+
}, ANTHROPIC_USAGE_FRESHNESS_MS).unref();
|
|
128552
129023
|
const usageMiddleware = createUsageMiddleware({
|
|
128553
129024
|
record: withQuotaRefresh(usageStore.record, quotaRefresher),
|
|
128554
129025
|
defer: (task) => {
|
|
@@ -128692,7 +129163,7 @@ function realFrontDoorSupervisorPorts(paths) {
|
|
|
128692
129163
|
const leafFor = createLeafCache(loadCa(), () => /* @__PURE__ */ new Date());
|
|
128693
129164
|
const capture = captureFromEnv(process.env, paths.logsDir);
|
|
128694
129165
|
if (capture !== void 0) {
|
|
128695
|
-
log(`capture enabled, recording CONNECT targets and piped exchanges to ${
|
|
129166
|
+
log(`capture enabled, recording CONNECT targets and piped exchanges to ${import_node_path46.default.join(paths.logsDir, "frontdoor-capture.jsonl")}`);
|
|
128696
129167
|
}
|
|
128697
129168
|
if (rcSelfHostSurface !== void 0) {
|
|
128698
129169
|
log("self-hosted Remote Control surface on: the door serves the CCR session family itself, and its own client-half dials its own transparent surface");
|
|
@@ -130829,8 +131300,8 @@ function getErrorMap2() {
|
|
|
130829
131300
|
|
|
130830
131301
|
// node_modules/.pnpm/zod@4.6.5/node_modules/zod/v3/helpers/parseUtil.js
|
|
130831
131302
|
var makeIssue = (params) => {
|
|
130832
|
-
const { data, path:
|
|
130833
|
-
const fullPath = [...
|
|
131303
|
+
const { data, path: path52, errorMaps, issueData } = params;
|
|
131304
|
+
const fullPath = [...path52, ...issueData.path || []];
|
|
130834
131305
|
const fullIssue = {
|
|
130835
131306
|
...issueData,
|
|
130836
131307
|
path: fullPath
|
|
@@ -130945,11 +131416,11 @@ var errorUtil;
|
|
|
130945
131416
|
|
|
130946
131417
|
// node_modules/.pnpm/zod@4.6.5/node_modules/zod/v3/types.js
|
|
130947
131418
|
var ParseInputLazyPath = class {
|
|
130948
|
-
constructor(parent, value2,
|
|
131419
|
+
constructor(parent, value2, path52, key) {
|
|
130949
131420
|
this._cachedPath = [];
|
|
130950
131421
|
this.parent = parent;
|
|
130951
131422
|
this.data = value2;
|
|
130952
|
-
this._path =
|
|
131423
|
+
this._path = path52;
|
|
130953
131424
|
this._key = key;
|
|
130954
131425
|
}
|
|
130955
131426
|
get path() {
|
|
@@ -134512,11 +134983,11 @@ function normalizeObjectSchema(schema) {
|
|
|
134512
134983
|
}
|
|
134513
134984
|
return void 0;
|
|
134514
134985
|
}
|
|
134515
|
-
function getDotPath(
|
|
134516
|
-
if (
|
|
134986
|
+
function getDotPath(path52) {
|
|
134987
|
+
if (path52.length === 0) {
|
|
134517
134988
|
return "object root";
|
|
134518
134989
|
}
|
|
134519
|
-
return
|
|
134990
|
+
return path52.reduce((acc, seg, index) => {
|
|
134520
134991
|
if (index === 0) {
|
|
134521
134992
|
return String(seg);
|
|
134522
134993
|
}
|
|
@@ -138559,7 +139030,7 @@ async function serveMcp(mcp, transport, options = {}) {
|
|
|
138559
139030
|
|
|
138560
139031
|
// src/mcp/permissions.ts
|
|
138561
139032
|
var import_node_fs17 = __toESM(require("node:fs"), 1);
|
|
138562
|
-
var
|
|
139033
|
+
var import_node_path47 = __toESM(require("node:path"), 1);
|
|
138563
139034
|
init_zod();
|
|
138564
139035
|
init_store();
|
|
138565
139036
|
var StoredMcpPermissionsSchema = external_exports.strictObject({
|
|
@@ -138579,10 +139050,10 @@ function effectiveMcpPermissions(flags, stored) {
|
|
|
138579
139050
|
return { writes: flags.writes || stored.writes, remoteControl: flags.remoteControl || stored.remoteControl };
|
|
138580
139051
|
}
|
|
138581
139052
|
function watchMcpPermissions(paths, onChange) {
|
|
138582
|
-
const directory =
|
|
139053
|
+
const directory = import_node_path47.default.dirname(paths.mcpPermissionsFile);
|
|
138583
139054
|
import_node_fs17.default.mkdirSync(directory, { recursive: true });
|
|
138584
139055
|
const watcher = import_node_fs17.default.watch(directory, (_event, filename) => {
|
|
138585
|
-
if (filename === null || filename ===
|
|
139056
|
+
if (filename === null || filename === import_node_path47.default.basename(paths.mcpPermissionsFile)) {
|
|
138586
139057
|
onChange();
|
|
138587
139058
|
}
|
|
138588
139059
|
});
|
|
@@ -138891,16 +139362,16 @@ init_credentialCache();
|
|
|
138891
139362
|
|
|
138892
139363
|
// src/identityToken.ts
|
|
138893
139364
|
var import_node_fs18 = __toESM(require("node:fs"), 1);
|
|
138894
|
-
var
|
|
139365
|
+
var import_node_path48 = __toESM(require("node:path"), 1);
|
|
138895
139366
|
init_cliError();
|
|
138896
139367
|
var TOKEN_FILE_MODE = 384;
|
|
138897
139368
|
var TOKEN_DIR_MODE = 448;
|
|
138898
139369
|
var OAUTH_TOKEN_RE = /^sk-ant-oat\d+-[A-Za-z0-9_-]+$/;
|
|
138899
139370
|
function identityTokenDir(paths) {
|
|
138900
|
-
return
|
|
139371
|
+
return import_node_path48.default.join(paths.root, "credentials");
|
|
138901
139372
|
}
|
|
138902
139373
|
function identityTokenPath(paths, identityName) {
|
|
138903
|
-
return
|
|
139374
|
+
return import_node_path48.default.join(identityTokenDir(paths), `${identityName}.token`);
|
|
138904
139375
|
}
|
|
138905
139376
|
function storeIdentityToken(paths, identityName, raw) {
|
|
138906
139377
|
const token = raw.trim();
|
|
@@ -138911,7 +139382,7 @@ function storeIdentityToken(paths, identityName, raw) {
|
|
|
138911
139382
|
import_node_fs18.default.mkdirSync(dir, { recursive: true, mode: TOKEN_DIR_MODE });
|
|
138912
139383
|
import_node_fs18.default.chmodSync(dir, TOKEN_DIR_MODE);
|
|
138913
139384
|
const target = identityTokenPath(paths, identityName);
|
|
138914
|
-
const temp =
|
|
139385
|
+
const temp = import_node_path48.default.join(dir, `.${identityName}.${String(process.pid)}.tmp`);
|
|
138915
139386
|
import_node_fs18.default.writeFileSync(temp, `${token}
|
|
138916
139387
|
`, { mode: TOKEN_FILE_MODE });
|
|
138917
139388
|
import_node_fs18.default.renameSync(temp, target);
|
|
@@ -139079,7 +139550,7 @@ function registerDoctorCommand(program2, deps) {
|
|
|
139079
139550
|
// src/headroom/commands.ts
|
|
139080
139551
|
var import_node_fs19 = __toESM(require("node:fs"), 1);
|
|
139081
139552
|
var import_node_http4 = __toESM(require("node:http"), 1);
|
|
139082
|
-
var
|
|
139553
|
+
var import_node_path49 = __toESM(require("node:path"), 1);
|
|
139083
139554
|
var import_node_child_process6 = require("node:child_process");
|
|
139084
139555
|
init_commandDeps();
|
|
139085
139556
|
init_realFrontDoorPort();
|
|
@@ -139091,7 +139562,9 @@ init_state();
|
|
|
139091
139562
|
init_supervisor();
|
|
139092
139563
|
function collectHeadroomStatus(fsPort, paths, isRunning) {
|
|
139093
139564
|
const state = resolveServingHeadroomState(fsPort, { stateFile: paths.headroomStateFile, legacyStateFile: paths.headroomLegacyStateFile }, isRunning)?.state ?? {};
|
|
139094
|
-
const
|
|
139565
|
+
const inputs = currentHeadroomAllowlistInputs(fsPort, paths);
|
|
139566
|
+
const allowlist = headroomAllowlist(headroomUpstreams(inputs.providers, inputs.frontDoorOrigin));
|
|
139567
|
+
const allowlistDriftInputs = diagnoseAllowlistDrift({ recordedHash: state.allowlistHash, providers: inputs.providers, frontDoorOrigin: inputs.frontDoorOrigin });
|
|
139095
139568
|
const settings2 = settingsOf(readGlobalConfig(paths)?.headroom ?? {});
|
|
139096
139569
|
return {
|
|
139097
139570
|
state,
|
|
@@ -139102,13 +139575,27 @@ function collectHeadroomStatus(fsPort, paths, isRunning) {
|
|
|
139102
139575
|
alive: isRunning(session.pid)
|
|
139103
139576
|
})),
|
|
139104
139577
|
allowlist,
|
|
139105
|
-
allowlistDrifted:
|
|
139578
|
+
allowlistDrifted: allowlistDriftInputs !== void 0,
|
|
139579
|
+
frontDoorOrigin: inputs.frontDoorOrigin,
|
|
139580
|
+
allowlistDriftInputs,
|
|
139106
139581
|
settings: settings2,
|
|
139107
139582
|
settingsDrifted: state.settingsHash !== void 0 && state.settingsHash !== hashSettings(settings2),
|
|
139108
139583
|
logPath: paths.headroomLogPath,
|
|
139109
139584
|
logExists: fsPort.readFileUtf8(paths.headroomLogPath) !== void 0
|
|
139110
139585
|
};
|
|
139111
139586
|
}
|
|
139587
|
+
function describeAllowlistDrift(status) {
|
|
139588
|
+
const inputs = status.allowlistDriftInputs ?? [];
|
|
139589
|
+
if (!inputs.includes("front-door-origin")) {
|
|
139590
|
+
return "DRIFTED: current provider files differ from the running daemon's allowlist; a restart is pending";
|
|
139591
|
+
}
|
|
139592
|
+
const origin = status.frontDoorOrigin ?? "";
|
|
139593
|
+
const consequence = "provider launches through headroom are refused until the daemon restarts, which waits for the launches registered against it to end";
|
|
139594
|
+
if (!inputs.includes("provider-files")) {
|
|
139595
|
+
return `DRIFTED: the daemon was started before the serving front door's direct origin ${origin} existed, so its allowlist excludes it; ${consequence}`;
|
|
139596
|
+
}
|
|
139597
|
+
return `DRIFTED: the provider files or the serving front door's direct origin ${origin} changed since the daemon started, so its allowlist may exclude the door; ${consequence}`;
|
|
139598
|
+
}
|
|
139112
139599
|
function formatHeadroomStatus(status) {
|
|
139113
139600
|
const lines = [];
|
|
139114
139601
|
if (status.state.supervisorPid === void 0) {
|
|
@@ -139125,7 +139612,7 @@ function formatHeadroomStatus(status) {
|
|
|
139125
139612
|
`headroom: pid ${String(status.state.headroomPid)} (${status.headroomAlive ? "alive" : "NOT running"}), listening on unix socket ${status.state.socketPath}` + (status.state.version === void 0 ? "" : `, ${status.state.version}`)
|
|
139126
139613
|
);
|
|
139127
139614
|
}
|
|
139128
|
-
const drift = status.allowlistDrifted ?
|
|
139615
|
+
const drift = status.allowlistDrifted ? ` (${describeAllowlistDrift(status)})` : "";
|
|
139129
139616
|
lines.push(`allowlist: ${status.allowlist.join(", ")}${drift}`);
|
|
139130
139617
|
const configured = Object.entries(status.settings).map(([name, value2]) => `${name} ${String(value2)}`);
|
|
139131
139618
|
const settingsDrift = status.settingsDrifted ? " (DRIFTED: the configured settings differ from the running daemon's; a restart is pending)" : "";
|
|
@@ -139193,12 +139680,12 @@ function readInstalledHeadroomCommit() {
|
|
|
139193
139680
|
if (toolDir.status !== 0) {
|
|
139194
139681
|
return void 0;
|
|
139195
139682
|
}
|
|
139196
|
-
const libDir =
|
|
139683
|
+
const libDir = import_node_path49.default.join(toolDir.stdout.trim(), HEADROOM_TOOL_NAME, "lib");
|
|
139197
139684
|
for (const python of realFarmFs.readdir(libDir)) {
|
|
139198
|
-
const sitePackages =
|
|
139685
|
+
const sitePackages = import_node_path49.default.join(libDir, python, "site-packages");
|
|
139199
139686
|
for (const entry of realFarmFs.readdir(sitePackages)) {
|
|
139200
139687
|
if (entry.startsWith("headroom_ai-") && entry.endsWith(".dist-info")) {
|
|
139201
|
-
const directUrl = realFarmFs.readFileUtf8(
|
|
139688
|
+
const directUrl = realFarmFs.readFileUtf8(import_node_path49.default.join(sitePackages, entry, "direct_url.json"));
|
|
139202
139689
|
return directUrl === void 0 ? void 0 : parseInstalledCommit(directUrl);
|
|
139203
139690
|
}
|
|
139204
139691
|
}
|
|
@@ -139738,7 +140225,7 @@ function registerRunCommand(program2, handler) {
|
|
|
139738
140225
|
}
|
|
139739
140226
|
|
|
139740
140227
|
// src/usage/commands.ts
|
|
139741
|
-
var
|
|
140228
|
+
var import_node_path50 = __toESM(require("node:path"), 1);
|
|
139742
140229
|
init_commandDeps();
|
|
139743
140230
|
init_realPorts();
|
|
139744
140231
|
init_account();
|
|
@@ -139876,7 +140363,7 @@ function collectAccounts(fs22, paths, identity, probe) {
|
|
|
139876
140363
|
return names.map((name) => ({
|
|
139877
140364
|
identity: name,
|
|
139878
140365
|
account: readAccountMetadata(fs22, paths.identitiesDir, name),
|
|
139879
|
-
signIn: identitySignIn(fs22, probe, { farmRoot:
|
|
140366
|
+
signIn: identitySignIn(fs22, probe, { farmRoot: import_node_path50.default.join(paths.identitiesDir, name), hasCredentialBlock: readIdentity(paths, name)?.credential !== void 0 }),
|
|
139880
140367
|
usage: readUsageSnapshot(fs22, paths.usageSnapshotsDir, name)
|
|
139881
140368
|
}));
|
|
139882
140369
|
}
|
|
@@ -140221,7 +140708,7 @@ async function runClaude(argvOverride) {
|
|
|
140221
140708
|
// src/cli.ts
|
|
140222
140709
|
async function main() {
|
|
140223
140710
|
aliasLegacyEnv(process.env);
|
|
140224
|
-
const invokedName =
|
|
140711
|
+
const invokedName = import_node_path51.default.basename(process.argv[1] ?? "agent-shim");
|
|
140225
140712
|
if (isInvokedAsClaude(invokedName)) {
|
|
140226
140713
|
await runClaude();
|
|
140227
140714
|
return;
|