agent-shim 11.40.5 → 11.42.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 +4 -0
- package/dist/cli.cjs +668 -322
- package/dist/index.cjs +1855 -1561
- package/dist/index.mjs +1456 -1162
- package/dist/types/index.d.ts +457 -40
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -229,7 +229,7 @@ function isTimeZone(name) {
|
|
|
229
229
|
return false;
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
var 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, ANTIGRAVITY_MODES, CLAUDE_TIERS, ANTIGRAVITY_EFFORTS, ANTIGRAVITY_DEFAULT_MODE, ANTIGRAVITY_DEFAULT_MODEL, ANTIGRAVITY_DEFAULT_TIER_MODELS, ANTIGRAVITY_DEFAULT_EFFORT, AntigravityModelTargetSchema, AntigravityProviderConfigSchema, CODEX_EFFORTS, CODEX_LOGINS, CODEX_DEFAULT_LOGIN, CODEX_DEFAULT_MODEL, CODEX_DEFAULT_TIER_MODELS, CODEX_DEFAULT_EFFORT, CodexProviderConfigSchema, ProviderRouteSchema, PickerModelSchema, PickerModelsSchema, ProviderCatalogueSchema, HttpProviderSchema, CodexProviderSchema, RouterProviderSchema, AntigravityProviderSchema, ProviderSchema, SELECTION_MODES, VirtualModelSchema, ModelPricesSchema, ModelsConfigSchema, ModelsLayerSchema, ConfigProfileSchema, POOL_SELECTOR_PREFIX, POOL_NAME_PATTERN, IDENTITY_NAME_PATTERN, PoolNameSchema, SELECTOR_RE, IdentitySelectorSchema, PoolMemberSchema, POOL_PREFERENCES, PoolPreferenceSchema, WHOLE_PERCENT_MAX, CompactAtUtilisationSchema, PoolSchema, WEEKDAYS, AnchorSchema, JOB_WINDOWS, JobTriggerSchema, JobTargetSchema, JobSchema, 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, FrontDoorGlobalConfigSchema, UPDATE_MODES, UpdateGlobalConfigSchema, GlobalConfigSchema, IdentitySchema, CategoryClassificationSchema, CategoryClassificationOverlaySchema, SHIPPED_CATEGORY_DEFAULTS;
|
|
232
|
+
var 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, ANTIGRAVITY_MODES, CLAUDE_TIERS, ANTIGRAVITY_EFFORTS, ANTIGRAVITY_DEFAULT_MODE, ANTIGRAVITY_DEFAULT_MODEL, ANTIGRAVITY_DEFAULT_TIER_MODELS, ANTIGRAVITY_DEFAULT_EFFORT, AntigravityModelTargetSchema, AntigravityProviderConfigSchema, CODEX_EFFORTS, CODEX_LOGINS, CODEX_DEFAULT_LOGIN, CODEX_DEFAULT_MODEL, CODEX_DEFAULT_TIER_MODELS, CODEX_DEFAULT_EFFORT, CodexProviderConfigSchema, ProviderRouteSchema, PickerModelSchema, PickerModelsSchema, ProviderCatalogueSchema, HttpProviderSchema, CodexProviderSchema, RouterProviderSchema, AntigravityProviderSchema, ProviderSchema, SELECTION_MODES, VirtualModelSchema, ModelPricesSchema, FamilySettingsSchema, ModelsConfigSchema, ModelsLayerSchema, ConfigProfileSchema, POOL_SELECTOR_PREFIX, POOL_NAME_PATTERN, IDENTITY_NAME_PATTERN, PoolNameSchema, SELECTOR_RE, IdentitySelectorSchema, PoolMemberSchema, POOL_PREFERENCES, PoolPreferenceSchema, WHOLE_PERCENT_MAX, CompactAtUtilisationSchema, PoolSchema, WEEKDAYS, AnchorSchema, JOB_WINDOWS, JobTriggerSchema, JobTargetSchema, JobSchema, 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, FrontDoorGlobalConfigSchema, UPDATE_MODES, UpdateGlobalConfigSchema, GlobalConfigSchema, IdentitySchema, CategoryClassificationSchema, CategoryClassificationOverlaySchema, SHIPPED_CATEGORY_DEFAULTS;
|
|
233
233
|
var init_schema = __esm({
|
|
234
234
|
"src/config/schema.ts"() {
|
|
235
235
|
"use strict";
|
|
@@ -473,6 +473,14 @@ var init_schema = __esm({
|
|
|
473
473
|
input: z.number().positive(),
|
|
474
474
|
output: z.number().positive()
|
|
475
475
|
});
|
|
476
|
+
FamilySettingsSchema = z.strictObject({
|
|
477
|
+
names: z.array(z.string().min(1)).optional(),
|
|
478
|
+
mode: z.enum(SELECTION_MODES).optional(),
|
|
479
|
+
context: z.number().int().positive().optional(),
|
|
480
|
+
vision: z.boolean().optional(),
|
|
481
|
+
tools: z.boolean().optional(),
|
|
482
|
+
thinking: z.boolean().optional()
|
|
483
|
+
});
|
|
476
484
|
ModelsConfigSchema = z.strictObject({
|
|
477
485
|
/** Virtual models, by name. */
|
|
478
486
|
virtual: z.record(z.string().min(1), VirtualModelSchema).optional(),
|
|
@@ -488,7 +496,13 @@ var init_schema = __esm({
|
|
|
488
496
|
/** Model refs hidden from the picker and from routing, whatever else names them. */
|
|
489
497
|
hide: z.array(z.string().min(1)).optional(),
|
|
490
498
|
/** When set, the only model refs visible; everything else is hidden. */
|
|
491
|
-
show: z.array(z.string().min(1)).optional()
|
|
499
|
+
show: z.array(z.string().min(1)).optional(),
|
|
500
|
+
/** Assertions that each group of refs is one model under several names, overriding what the names alone say. */
|
|
501
|
+
same: z.array(z.array(z.string().min(1)).min(2)).optional(),
|
|
502
|
+
/** Assertions that each pair of refs is two models however alike their names look. */
|
|
503
|
+
distinct: z.array(z.tuple([z.string().min(1), z.string().min(1)])).optional(),
|
|
504
|
+
/** Per-family settings and the names the normaliser cannot know, by family key. */
|
|
505
|
+
families: z.record(z.string().min(1), FamilySettingsSchema).optional()
|
|
492
506
|
});
|
|
493
507
|
ModelsLayerSchema = z.strictObject({
|
|
494
508
|
virtual: z.record(z.string().min(1), z.union([VirtualModelSchema, z.null()])).optional(),
|
|
@@ -500,7 +514,10 @@ var init_schema = __esm({
|
|
|
500
514
|
}).optional(),
|
|
501
515
|
prices: z.record(z.string().min(1), z.union([ModelPricesSchema, z.null()])).optional(),
|
|
502
516
|
hide: z.array(z.string().min(1)).optional(),
|
|
503
|
-
show: z.array(z.string().min(1)).optional()
|
|
517
|
+
show: z.array(z.string().min(1)).optional(),
|
|
518
|
+
same: z.array(z.array(z.string().min(1)).min(2)).optional(),
|
|
519
|
+
distinct: z.array(z.tuple([z.string().min(1), z.string().min(1)])).optional(),
|
|
520
|
+
families: z.record(z.string().min(1), z.union([FamilySettingsSchema, z.null()])).optional()
|
|
504
521
|
});
|
|
505
522
|
ConfigProfileSchema = z.strictObject({
|
|
506
523
|
$schema: z.string().optional(),
|
|
@@ -1577,6 +1594,26 @@ function mergeModels(current, layer) {
|
|
|
1577
1594
|
if (layer.show !== void 0) {
|
|
1578
1595
|
pieces.show = layer.show;
|
|
1579
1596
|
}
|
|
1597
|
+
if (layer.same !== void 0) {
|
|
1598
|
+
pieces.same = [...current?.same ?? [], ...layer.same.filter((group) => !(current?.same ?? []).some((known) => known.length === group.length && known.every((ref, index) => ref === group[index])))];
|
|
1599
|
+
}
|
|
1600
|
+
if (layer.distinct !== void 0) {
|
|
1601
|
+
pieces.distinct = [...current?.distinct ?? [], ...layer.distinct.filter(([left, right]) => !(current?.distinct ?? []).some(([a, b]) => a === left && b === right))];
|
|
1602
|
+
}
|
|
1603
|
+
if (layer.families !== void 0) {
|
|
1604
|
+
const families = {};
|
|
1605
|
+
for (const [key, settings] of Object.entries(current?.families ?? {})) {
|
|
1606
|
+
if (layer.families[key] === void 0) {
|
|
1607
|
+
families[key] = settings;
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
for (const [key, settings] of Object.entries(layer.families)) {
|
|
1611
|
+
if (settings !== null) {
|
|
1612
|
+
families[key] = settings;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
pieces.families = families;
|
|
1616
|
+
}
|
|
1580
1617
|
const merged = modelsOf(pieces);
|
|
1581
1618
|
return Object.keys(merged).length === 0 ? void 0 : merged;
|
|
1582
1619
|
}
|
|
@@ -1586,7 +1623,10 @@ function modelsOf(pieces) {
|
|
|
1586
1623
|
...pieces.tiers === void 0 || Object.keys(pieces.tiers).length === 0 ? {} : { tiers: pieces.tiers },
|
|
1587
1624
|
...pieces.prices === void 0 || Object.keys(pieces.prices).length === 0 ? {} : { prices: pieces.prices },
|
|
1588
1625
|
...pieces.hide === void 0 || pieces.hide.length === 0 ? {} : { hide: [...pieces.hide] },
|
|
1589
|
-
...pieces.show === void 0 || pieces.show.length === 0 ? {} : { show: [...pieces.show] }
|
|
1626
|
+
...pieces.show === void 0 || pieces.show.length === 0 ? {} : { show: [...pieces.show] },
|
|
1627
|
+
...pieces.same === void 0 || pieces.same.length === 0 ? {} : { same: pieces.same.map((group) => [...group]) },
|
|
1628
|
+
...pieces.distinct === void 0 || pieces.distinct.length === 0 ? {} : { distinct: pieces.distinct.map(([left, right]) => [left, right]) },
|
|
1629
|
+
...pieces.families === void 0 || Object.keys(pieces.families).length === 0 ? {} : { families: pieces.families }
|
|
1590
1630
|
};
|
|
1591
1631
|
}
|
|
1592
1632
|
var init_flatten = __esm({
|
|
@@ -2014,7 +2054,8 @@ function assembleCascade(input) {
|
|
|
2014
2054
|
...config.categories === void 0 ? {} : { categories: config.categories },
|
|
2015
2055
|
...config.entries === void 0 ? {} : { entries: config.entries },
|
|
2016
2056
|
...entryOrder === void 0 ? {} : { entryOrder },
|
|
2017
|
-
...config.launch === void 0 ? {} : { launch: config.launch }
|
|
2057
|
+
...config.launch === void 0 ? {} : { launch: config.launch },
|
|
2058
|
+
...config.models === void 0 ? {} : { models: config.models }
|
|
2018
2059
|
});
|
|
2019
2060
|
nextId += 1;
|
|
2020
2061
|
}
|
|
@@ -2970,6 +3011,9 @@ function pruneDeadFrontDoorDirectRecords(fs13, recordsDir, records, liveness) {
|
|
|
2970
3011
|
}
|
|
2971
3012
|
}
|
|
2972
3013
|
}
|
|
3014
|
+
function recordOf(details) {
|
|
3015
|
+
return details === void 0 ? {} : { sessionId: details.sessionId, ...details.models === void 0 ? {} : { models: details.models } };
|
|
3016
|
+
}
|
|
2973
3017
|
function writeFrontDoorSession(fs13, sessionsDir, session) {
|
|
2974
3018
|
fs13.mkdirPrivate(sessionsDir);
|
|
2975
3019
|
fs13.writeFilePrivate(path8.join(sessionsDir, `${String(session.pid)}.json`), `${JSON.stringify(session, null, 2)}
|
|
@@ -3009,8 +3053,9 @@ var FRONT_DOOR_PROTOCOL, FrontDoorSessionSchema, FrontDoorStateSchema, MAX_TCP_P
|
|
|
3009
3053
|
var init_state = __esm({
|
|
3010
3054
|
"src/frontdoor/state.ts"() {
|
|
3011
3055
|
"use strict";
|
|
3056
|
+
init_schema();
|
|
3012
3057
|
FRONT_DOOR_PROTOCOL = 4;
|
|
3013
|
-
FrontDoorSessionSchema = z3.strictObject({ pid: z3.number().int().positive(), startedAt: z3.number(), token: z3.string().min(1), supervisorPid: z3.number().int().positive().optional() });
|
|
3058
|
+
FrontDoorSessionSchema = z3.strictObject({ pid: z3.number().int().positive(), startedAt: z3.number(), token: z3.string().min(1), supervisorPid: z3.number().int().positive().optional(), sessionId: z3.string().min(1).optional(), models: ModelsConfigSchema.optional() });
|
|
3014
3059
|
FrontDoorStateSchema = z3.strictObject({
|
|
3015
3060
|
/**
|
|
3016
3061
|
* 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`).
|
|
@@ -3082,7 +3127,7 @@ var init_package = __esm({
|
|
|
3082
3127
|
"package.json"() {
|
|
3083
3128
|
package_default = {
|
|
3084
3129
|
name: "agent-shim",
|
|
3085
|
-
version: "11.
|
|
3130
|
+
version: "11.42.0",
|
|
3086
3131
|
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.",
|
|
3087
3132
|
license: "MIT",
|
|
3088
3133
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -6863,6 +6908,213 @@ var init_credential = __esm({
|
|
|
6863
6908
|
}
|
|
6864
6909
|
});
|
|
6865
6910
|
|
|
6911
|
+
// src/models/identity.ts
|
|
6912
|
+
function withoutContextMarker(model) {
|
|
6913
|
+
return model.toLowerCase().endsWith(CONTEXT_MARKER_1M) ? model.slice(0, -CONTEXT_MARKER_1M.length) : model;
|
|
6914
|
+
}
|
|
6915
|
+
function canonicalText(name) {
|
|
6916
|
+
return name.trim().toLowerCase().replace(NON_IDENTITY_BRACKET_RE, "").replace(/[\s_]+/g, "-").replace(/([a-z])(\d+(?:\.\d+)+)/g, "$1-$2").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
6917
|
+
}
|
|
6918
|
+
function splitVariants(tokens) {
|
|
6919
|
+
const variants = [];
|
|
6920
|
+
let end = tokens.length;
|
|
6921
|
+
for (; ; ) {
|
|
6922
|
+
const token = tokens[end - 1];
|
|
6923
|
+
if (token === void 0 || !KNOWN_VARIANTS.has(token)) {
|
|
6924
|
+
return { familyTokens: tokens.slice(0, end), variants };
|
|
6925
|
+
}
|
|
6926
|
+
variants.unshift(token);
|
|
6927
|
+
end -= 1;
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
function versionOf(tokens) {
|
|
6931
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
6932
|
+
const token = tokens[index];
|
|
6933
|
+
const next = tokens[index + 1];
|
|
6934
|
+
if (token === void 0) {
|
|
6935
|
+
return "";
|
|
6936
|
+
}
|
|
6937
|
+
if (/^\d+$/.test(token) && next !== void 0 && /^\d+$/.test(next)) {
|
|
6938
|
+
return `${token}.${next}`;
|
|
6939
|
+
}
|
|
6940
|
+
const dotted = /^\d+(?:\.\d+)+$/.exec(token);
|
|
6941
|
+
if (dotted !== null) {
|
|
6942
|
+
return dotted[0];
|
|
6943
|
+
}
|
|
6944
|
+
}
|
|
6945
|
+
return "";
|
|
6946
|
+
}
|
|
6947
|
+
function modelIdentity(rawName) {
|
|
6948
|
+
const segments = rawName.trim().toLowerCase().split("/");
|
|
6949
|
+
const stripped = canonicalText(segments[segments.length - 1] ?? "").split(":")[0] ?? "";
|
|
6950
|
+
const withoutDate = stripped.replace(DATE_STAMP_RE, "");
|
|
6951
|
+
const tokens = withoutDate.split("-").filter((token) => token !== "");
|
|
6952
|
+
const { familyTokens, variants } = splitVariants(tokens);
|
|
6953
|
+
const version = versionOf(familyTokens);
|
|
6954
|
+
const versionless = familyTokens.filter((token, index) => {
|
|
6955
|
+
if (version === "") {
|
|
6956
|
+
return true;
|
|
6957
|
+
}
|
|
6958
|
+
const dotted = /^\d+(?:\.\d+)+$/.test(token);
|
|
6959
|
+
const previous = familyTokens[index - 1];
|
|
6960
|
+
const next = familyTokens[index + 1];
|
|
6961
|
+
const insideVersionRun = dotted || /^\d+$/.test(token) && (previous !== void 0 && /^\d+$/.test(previous) || next !== void 0 && /^\d+$/.test(next));
|
|
6962
|
+
return !insideVersionRun;
|
|
6963
|
+
});
|
|
6964
|
+
const family = versionless.join("-");
|
|
6965
|
+
const tokenVendor = familyTokens.find((token) => Object.keys(VENDOR_BY_TOKEN).some((key) => token === key || token.startsWith(key)));
|
|
6966
|
+
const namespace = segments.length >= 2 ? (segments[0] ?? "").split(":").pop() ?? "" : "";
|
|
6967
|
+
const namespaceVendor = VENDOR_BY_NAMESPACE[namespace] ?? "";
|
|
6968
|
+
const tokenVendorName = tokenVendor === void 0 ? "" : VENDOR_BY_TOKEN[Object.keys(VENDOR_BY_TOKEN).find((key) => tokenVendor === key || tokenVendor.startsWith(key)) ?? ""] ?? "";
|
|
6969
|
+
return {
|
|
6970
|
+
vendor: tokenVendorName === "" ? namespaceVendor : tokenVendorName,
|
|
6971
|
+
vendorConflict: tokenVendorName !== "" && namespaceVendor !== "" && tokenVendorName !== namespaceVendor,
|
|
6972
|
+
family,
|
|
6973
|
+
version,
|
|
6974
|
+
variant: variants.join("-"),
|
|
6975
|
+
familyAndVersion: version === "" ? family : `${family}-${version.replace(/\./g, "-")}`
|
|
6976
|
+
};
|
|
6977
|
+
}
|
|
6978
|
+
function relateModels(left, right) {
|
|
6979
|
+
const a = modelIdentity(left);
|
|
6980
|
+
const b = modelIdentity(right);
|
|
6981
|
+
if (a.familyAndVersion !== b.familyAndVersion) {
|
|
6982
|
+
return sameFamilyOtherVersion(a, b) ? "similar" : "distinct";
|
|
6983
|
+
}
|
|
6984
|
+
if (a.variant !== b.variant || a.vendorConflict || b.vendorConflict || a.vendor !== "" && b.vendor !== "" && a.vendor !== b.vendor) {
|
|
6985
|
+
return "similar";
|
|
6986
|
+
}
|
|
6987
|
+
return "same";
|
|
6988
|
+
}
|
|
6989
|
+
function sameFamilyOtherVersion(a, b) {
|
|
6990
|
+
if (a.family !== b.family) {
|
|
6991
|
+
return false;
|
|
6992
|
+
}
|
|
6993
|
+
if (a.vendor !== "" && b.vendor !== "" && a.vendor !== b.vendor) {
|
|
6994
|
+
return false;
|
|
6995
|
+
}
|
|
6996
|
+
return true;
|
|
6997
|
+
}
|
|
6998
|
+
var NON_IDENTITY_BRACKET_RE, CONTEXT_MARKER_1M, DATE_STAMP_RE, KNOWN_VARIANTS, VENDOR_BY_NAMESPACE, VENDOR_BY_TOKEN;
|
|
6999
|
+
var init_identity2 = __esm({
|
|
7000
|
+
"src/models/identity.ts"() {
|
|
7001
|
+
"use strict";
|
|
7002
|
+
NON_IDENTITY_BRACKET_RE = /\[[^\]]*\]/g;
|
|
7003
|
+
CONTEXT_MARKER_1M = "[1m]";
|
|
7004
|
+
DATE_STAMP_RE = /-(?:19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])$/;
|
|
7005
|
+
KNOWN_VARIANTS = /* @__PURE__ */ new Set(["high", "medium", "low", "thinking", "xhigh", "max", "highspeed", "sol", "terra", "luna", "mini", "flash-lite", "turbo"]);
|
|
7006
|
+
VENDOR_BY_NAMESPACE = Object.freeze({
|
|
7007
|
+
anthropic: "anthropic",
|
|
7008
|
+
google: "google",
|
|
7009
|
+
openai: "openai",
|
|
7010
|
+
zai: "zai",
|
|
7011
|
+
"z-ai": "zai",
|
|
7012
|
+
minimax: "minimax",
|
|
7013
|
+
qwen: "qwen",
|
|
7014
|
+
deepseek: "deepseek",
|
|
7015
|
+
moonshot: "moonshot",
|
|
7016
|
+
meta: "meta",
|
|
7017
|
+
mistral: "mistral"
|
|
7018
|
+
});
|
|
7019
|
+
VENDOR_BY_TOKEN = Object.freeze({
|
|
7020
|
+
claude: "anthropic",
|
|
7021
|
+
gemini: "google",
|
|
7022
|
+
antigravity: "google",
|
|
7023
|
+
gpt: "openai",
|
|
7024
|
+
glm: "zai",
|
|
7025
|
+
minimax: "minimax",
|
|
7026
|
+
qwen: "qwen",
|
|
7027
|
+
deepseek: "deepseek",
|
|
7028
|
+
kimi: "moonshot",
|
|
7029
|
+
llama: "meta",
|
|
7030
|
+
mistral: "mistral",
|
|
7031
|
+
mixtral: "mistral"
|
|
7032
|
+
});
|
|
7033
|
+
}
|
|
7034
|
+
});
|
|
7035
|
+
|
|
7036
|
+
// src/models/families.ts
|
|
7037
|
+
function modelOf(ref) {
|
|
7038
|
+
const slash = ref.indexOf("/");
|
|
7039
|
+
return slash === -1 ? ref : ref.slice(slash + 1);
|
|
7040
|
+
}
|
|
7041
|
+
function familyKeyOf(rawModel) {
|
|
7042
|
+
const identity = modelIdentity(rawModel);
|
|
7043
|
+
return identity.variant === "" ? identity.familyAndVersion : `${identity.familyAndVersion}${VARIANT_SEPARATOR}${identity.variant}`;
|
|
7044
|
+
}
|
|
7045
|
+
function assertionsOf(models) {
|
|
7046
|
+
return { same: models?.same ?? [], distinct: models?.distinct ?? [] };
|
|
7047
|
+
}
|
|
7048
|
+
function sameModel(left, right, assertions) {
|
|
7049
|
+
if (assertions.distinct.some(([a, b]) => a === left && b === right || a === right && b === left)) {
|
|
7050
|
+
return false;
|
|
7051
|
+
}
|
|
7052
|
+
const leftGroup = assertions.same.find((group) => group.includes(left));
|
|
7053
|
+
const rightGroup = assertions.same.find((group) => group.includes(right));
|
|
7054
|
+
if (leftGroup !== void 0 && leftGroup === rightGroup) {
|
|
7055
|
+
return true;
|
|
7056
|
+
}
|
|
7057
|
+
if (leftGroup !== void 0 && !leftGroup.includes(right) || rightGroup !== void 0 && !rightGroup.includes(left)) {
|
|
7058
|
+
return false;
|
|
7059
|
+
}
|
|
7060
|
+
return relateModels(modelOf(left), modelOf(right)) === "same";
|
|
7061
|
+
}
|
|
7062
|
+
function pinnedTo(settings, ref) {
|
|
7063
|
+
return settings?.names?.some((name) => name === ref || name === modelOf(ref)) === true;
|
|
7064
|
+
}
|
|
7065
|
+
function buildFamilies(refs, models) {
|
|
7066
|
+
const assertions = assertionsOf(models);
|
|
7067
|
+
const settingsByKey = models?.families ?? {};
|
|
7068
|
+
const groups = [];
|
|
7069
|
+
for (const ref of refs) {
|
|
7070
|
+
const pinnedKey = Object.entries(settingsByKey).find(([, settings]) => pinnedTo(settings, ref))?.[0];
|
|
7071
|
+
const joined2 = groups.find((group) => pinnedKey === void 0 ? group.refs.some((first) => sameModel(first, ref, assertions)) : group.key === pinnedKey);
|
|
7072
|
+
if (joined2 !== void 0) {
|
|
7073
|
+
joined2.refs.push(ref);
|
|
7074
|
+
} else {
|
|
7075
|
+
groups.push({ key: pinnedKey ?? familyKeyOf(modelOf(ref)), refs: [ref] });
|
|
7076
|
+
}
|
|
7077
|
+
}
|
|
7078
|
+
return groups.map((group) => ({ key: group.key, refs: group.refs, settings: settingsByKey[group.key] ?? {} }));
|
|
7079
|
+
}
|
|
7080
|
+
function familyNamed(families, member) {
|
|
7081
|
+
if (!member.startsWith(FAMILY_PREFIX)) {
|
|
7082
|
+
return void 0;
|
|
7083
|
+
}
|
|
7084
|
+
const key = member.slice(FAMILY_PREFIX.length);
|
|
7085
|
+
return families.find((family) => family.key === key);
|
|
7086
|
+
}
|
|
7087
|
+
function familyMode(settings) {
|
|
7088
|
+
return settings.mode ?? "ordered";
|
|
7089
|
+
}
|
|
7090
|
+
function sharedFamilies(families) {
|
|
7091
|
+
return families.filter((family) => family.refs.length > 1);
|
|
7092
|
+
}
|
|
7093
|
+
function expandFamilyMembers(members, families) {
|
|
7094
|
+
const expanded = [];
|
|
7095
|
+
for (const member of members) {
|
|
7096
|
+
for (const ref of member.startsWith(FAMILY_PREFIX) ? familyNamed(families, member)?.refs ?? [] : [member]) {
|
|
7097
|
+
if (!expanded.includes(ref)) {
|
|
7098
|
+
expanded.push(ref);
|
|
7099
|
+
}
|
|
7100
|
+
}
|
|
7101
|
+
}
|
|
7102
|
+
return expanded;
|
|
7103
|
+
}
|
|
7104
|
+
function accountRefsOf(models) {
|
|
7105
|
+
const named = [...(models?.same ?? []).flat(), ...Object.values(models?.families ?? {}).flatMap((settings) => settings.names ?? [])];
|
|
7106
|
+
return [...new Set(named.filter((ref) => ref.startsWith("acct:")))];
|
|
7107
|
+
}
|
|
7108
|
+
var FAMILY_PREFIX, VARIANT_SEPARATOR;
|
|
7109
|
+
var init_families = __esm({
|
|
7110
|
+
"src/models/families.ts"() {
|
|
7111
|
+
"use strict";
|
|
7112
|
+
init_identity2();
|
|
7113
|
+
FAMILY_PREFIX = "family:";
|
|
7114
|
+
VARIANT_SEPARATOR = "+";
|
|
7115
|
+
}
|
|
7116
|
+
});
|
|
7117
|
+
|
|
6866
7118
|
// src/providersStore.ts
|
|
6867
7119
|
import fs7 from "node:fs";
|
|
6868
7120
|
import path25 from "node:path";
|
|
@@ -7159,8 +7411,15 @@ function resolveRoutedProviderCredentials(params) {
|
|
|
7159
7411
|
}
|
|
7160
7412
|
const virtualNames = new Set(Object.keys(models.virtual ?? {}));
|
|
7161
7413
|
const providerNames = /* @__PURE__ */ new Set();
|
|
7414
|
+
const families = () => buildFamilies(params.targets?.() ?? [], models);
|
|
7162
7415
|
const collect = (ref) => {
|
|
7163
|
-
if (ref.startsWith(
|
|
7416
|
+
if (ref.startsWith(FAMILY_PREFIX)) {
|
|
7417
|
+
for (const target of expandFamilyMembers([ref], families())) {
|
|
7418
|
+
collect(target);
|
|
7419
|
+
}
|
|
7420
|
+
return;
|
|
7421
|
+
}
|
|
7422
|
+
if (ref.startsWith("acct:") || virtualNames.has(ref)) {
|
|
7164
7423
|
return;
|
|
7165
7424
|
}
|
|
7166
7425
|
const [provider] = ref.split("/", 1);
|
|
@@ -7215,6 +7474,7 @@ var init_providersStore = __esm({
|
|
|
7215
7474
|
init_cliError();
|
|
7216
7475
|
init_credential();
|
|
7217
7476
|
init_walk();
|
|
7477
|
+
init_families();
|
|
7218
7478
|
ProviderNotFoundError = class extends CliError {
|
|
7219
7479
|
constructor(name) {
|
|
7220
7480
|
super(`No provider named "${name}". Run \`agent-shim provider add ${name}\` first.`);
|
|
@@ -7520,9 +7780,6 @@ var init_claudeShim = __esm({
|
|
|
7520
7780
|
});
|
|
7521
7781
|
|
|
7522
7782
|
// src/modelsStore.ts
|
|
7523
|
-
function readModels(paths) {
|
|
7524
|
-
return readGlobalConfig(paths)?.models;
|
|
7525
|
-
}
|
|
7526
7783
|
function memberKindOf(ref, models) {
|
|
7527
7784
|
if (ref.startsWith("acct:")) {
|
|
7528
7785
|
return "account";
|
|
@@ -7575,152 +7832,531 @@ var init_modelsStore = __esm({
|
|
|
7575
7832
|
}
|
|
7576
7833
|
});
|
|
7577
7834
|
|
|
7578
|
-
// src/
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
refuseToBlockInRole("a synchronous probe of the front door");
|
|
7582
|
-
return runProbeWorker(PROBE_SOURCE, { port, ca: caPem });
|
|
7583
|
-
}
|
|
7584
|
-
function probeListenerAcceptSync(port) {
|
|
7585
|
-
refuseToBlockInRole("a synchronous probe of a front door listener");
|
|
7586
|
-
return runProbeWorker(ACCEPT_PROBE_SOURCE, { port });
|
|
7587
|
-
}
|
|
7588
|
-
function runProbeWorker(source, data) {
|
|
7589
|
-
const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
|
|
7590
|
-
const header = new Int32Array(shared, 0, HEADER_SLOTS);
|
|
7591
|
-
const worker = new Worker(source, {
|
|
7592
|
-
eval: true,
|
|
7593
|
-
workerData: { ...data, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
|
|
7594
|
-
});
|
|
7595
|
-
worker.unref();
|
|
7596
|
-
try {
|
|
7597
|
-
const waited = Atomics.wait(header, 0, VERDICT_PENDING, PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS);
|
|
7598
|
-
const verdict = Atomics.load(header, 0);
|
|
7599
|
-
if (waited === "timed-out" || verdict === VERDICT_PENDING) {
|
|
7600
|
-
return { ok: false, reason: `the probe did not finish within ${String(PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS)}ms` };
|
|
7601
|
-
}
|
|
7602
|
-
if (verdict === VERDICT_OK) {
|
|
7603
|
-
return { ok: true };
|
|
7604
|
-
}
|
|
7605
|
-
const length = Atomics.load(header, 1);
|
|
7606
|
-
return { ok: false, reason: Buffer.from(new Uint8Array(shared, HEADER_SLOTS * INT32_BYTES, length)).toString("utf8") };
|
|
7607
|
-
} finally {
|
|
7608
|
-
void worker.terminate();
|
|
7609
|
-
}
|
|
7610
|
-
}
|
|
7611
|
-
var PROBE_TIMEOUT_MS, PROBE_WAIT_MARGIN_MS, REASON_BYTES, HEADER_SLOTS, INT32_BYTES, VERDICT_PENDING, VERDICT_OK, VERDICT_FAILED, PROBE_SOURCE, ACCEPT_PROBE_SOURCE;
|
|
7612
|
-
var init_probe = __esm({
|
|
7613
|
-
"src/frontdoor/probe.ts"() {
|
|
7835
|
+
// src/selection/engine.ts
|
|
7836
|
+
var init_engine = __esm({
|
|
7837
|
+
"src/selection/engine.ts"() {
|
|
7614
7838
|
"use strict";
|
|
7615
|
-
init_processRole();
|
|
7616
|
-
PROBE_TIMEOUT_MS = 2e3;
|
|
7617
|
-
PROBE_WAIT_MARGIN_MS = 1e3;
|
|
7618
|
-
REASON_BYTES = 1024;
|
|
7619
|
-
HEADER_SLOTS = 2;
|
|
7620
|
-
INT32_BYTES = 4;
|
|
7621
|
-
VERDICT_PENDING = 0;
|
|
7622
|
-
VERDICT_OK = 1;
|
|
7623
|
-
VERDICT_FAILED = 2;
|
|
7624
|
-
PROBE_SOURCE = `
|
|
7625
|
-
const { workerData } = require("node:worker_threads");
|
|
7626
|
-
const https = require("node:https");
|
|
7627
|
-
const { port, ca, timeoutMs, shared, ok, failed, headerSlots } = workerData;
|
|
7628
|
-
const header = new Int32Array(shared, 0, headerSlots);
|
|
7629
|
-
const reason = new Uint8Array(shared, headerSlots * 4);
|
|
7630
|
-
let done = false;
|
|
7631
|
-
const finish = (verdict, message) => {
|
|
7632
|
-
if (done) return;
|
|
7633
|
-
done = true;
|
|
7634
|
-
const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
|
|
7635
|
-
reason.set(bytes);
|
|
7636
|
-
Atomics.store(header, 1, bytes.length);
|
|
7637
|
-
Atomics.store(header, 0, verdict);
|
|
7638
|
-
Atomics.notify(header, 0);
|
|
7639
|
-
};
|
|
7640
|
-
const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca], agent: false }, (response) => {
|
|
7641
|
-
let body = "";
|
|
7642
|
-
response.setEncoding("utf8");
|
|
7643
|
-
response.on("data", (chunk) => { body += chunk; });
|
|
7644
|
-
response.on("end", () => {
|
|
7645
|
-
if (response.statusCode === 200 && body === "ok") finish(ok, "");
|
|
7646
|
-
else finish(failed, "the listener answered its health probe with HTTP " + String(response.statusCode));
|
|
7647
|
-
});
|
|
7648
|
-
response.on("error", (error) => finish(failed, error.message));
|
|
7649
|
-
});
|
|
7650
|
-
// A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
|
|
7651
|
-
setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
|
|
7652
|
-
request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
|
|
7653
|
-
`;
|
|
7654
|
-
ACCEPT_PROBE_SOURCE = `
|
|
7655
|
-
const { workerData } = require("node:worker_threads");
|
|
7656
|
-
const net = require("node:net");
|
|
7657
|
-
const { port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
|
|
7658
|
-
const header = new Int32Array(shared, 0, headerSlots);
|
|
7659
|
-
const reason = new Uint8Array(shared, headerSlots * 4);
|
|
7660
|
-
let done = false;
|
|
7661
|
-
const finish = (verdict, message) => {
|
|
7662
|
-
if (done) return;
|
|
7663
|
-
done = true;
|
|
7664
|
-
const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
|
|
7665
|
-
reason.set(bytes);
|
|
7666
|
-
Atomics.store(header, 1, bytes.length);
|
|
7667
|
-
Atomics.store(header, 0, verdict);
|
|
7668
|
-
Atomics.notify(header, 0);
|
|
7669
|
-
};
|
|
7670
|
-
const socket = net.connect({ host: "127.0.0.1", port });
|
|
7671
|
-
socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
|
|
7672
|
-
socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
|
|
7673
|
-
setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
|
|
7674
|
-
`;
|
|
7675
7839
|
}
|
|
7676
7840
|
});
|
|
7677
7841
|
|
|
7678
|
-
// src/
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
7682
|
-
if (match === null) {
|
|
7683
|
-
throw new Error(`not a plain release version: ${version}`);
|
|
7684
|
-
}
|
|
7685
|
-
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
7686
|
-
};
|
|
7687
|
-
const leftParts = parse(left);
|
|
7688
|
-
const rightParts = parse(right);
|
|
7689
|
-
return leftParts.map((part, index) => part - (rightParts[index] ?? 0)).find((difference) => difference !== 0) ?? 0;
|
|
7690
|
-
}
|
|
7691
|
-
function releaseTagFromUrl(url) {
|
|
7692
|
-
const segment = url.split("?")[0]?.split("/").at(-1);
|
|
7693
|
-
const candidate = segment?.startsWith("v") === true ? segment.slice(1) : void 0;
|
|
7694
|
-
return candidate !== void 0 && /^\d+\.\d+\.\d+$/.test(candidate) ? candidate : void 0;
|
|
7695
|
-
}
|
|
7696
|
-
var LATEST_RELEASE_URL, UpdateChannelError, UpdateConflictError, UpdateDownloadError;
|
|
7697
|
-
var init_update = __esm({
|
|
7698
|
-
"src/update/update.ts"() {
|
|
7842
|
+
// src/antigravity/cloudUpstream.ts
|
|
7843
|
+
var init_cloudUpstream = __esm({
|
|
7844
|
+
"src/antigravity/cloudUpstream.ts"() {
|
|
7699
7845
|
"use strict";
|
|
7700
|
-
init_cliError();
|
|
7701
|
-
LATEST_RELEASE_URL = "https://github.com/ExaDev/agent-shim/releases/latest";
|
|
7702
|
-
UpdateChannelError = class extends CliError {
|
|
7703
|
-
constructor(message) {
|
|
7704
|
-
super(message);
|
|
7705
|
-
this.name = "UpdateChannelError";
|
|
7706
|
-
}
|
|
7707
|
-
};
|
|
7708
|
-
UpdateConflictError = class extends CliError {
|
|
7709
|
-
constructor(message) {
|
|
7710
|
-
super(message);
|
|
7711
|
-
this.name = "UpdateConflictError";
|
|
7712
|
-
}
|
|
7713
|
-
};
|
|
7714
|
-
UpdateDownloadError = class extends CliError {
|
|
7715
|
-
constructor(message) {
|
|
7716
|
-
super(message);
|
|
7717
|
-
this.name = "UpdateDownloadError";
|
|
7718
|
-
}
|
|
7719
|
-
};
|
|
7720
7846
|
}
|
|
7721
7847
|
});
|
|
7722
7848
|
|
|
7723
|
-
// src/
|
|
7849
|
+
// src/antigravity/quota.ts
|
|
7850
|
+
var SECONDS_PER_HOUR, HOURS_PER_FIVE_HOUR_WINDOW, DAYS_PER_WEEK, HOURS_PER_DAY4, FIVE_HOUR_PERIOD_SECONDS, WEEK_PERIOD_SECONDS;
|
|
7851
|
+
var init_quota = __esm({
|
|
7852
|
+
"src/antigravity/quota.ts"() {
|
|
7853
|
+
"use strict";
|
|
7854
|
+
init_cloudUpstream();
|
|
7855
|
+
SECONDS_PER_HOUR = 3600;
|
|
7856
|
+
HOURS_PER_FIVE_HOUR_WINDOW = 5;
|
|
7857
|
+
DAYS_PER_WEEK = 7;
|
|
7858
|
+
HOURS_PER_DAY4 = 24;
|
|
7859
|
+
FIVE_HOUR_PERIOD_SECONDS = HOURS_PER_FIVE_HOUR_WINDOW * SECONDS_PER_HOUR;
|
|
7860
|
+
WEEK_PERIOD_SECONDS = DAYS_PER_WEEK * HOURS_PER_DAY4 * SECONDS_PER_HOUR;
|
|
7861
|
+
}
|
|
7862
|
+
});
|
|
7863
|
+
|
|
7864
|
+
// src/antigravity/signatures.ts
|
|
7865
|
+
var init_signatures = __esm({
|
|
7866
|
+
"src/antigravity/signatures.ts"() {
|
|
7867
|
+
"use strict";
|
|
7868
|
+
}
|
|
7869
|
+
});
|
|
7870
|
+
|
|
7871
|
+
// src/codex/anthropic.ts
|
|
7872
|
+
import { z as z23 } from "zod";
|
|
7873
|
+
var TextBlockSchema, Base64ImageSourceSchema, UrlImageSourceSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultContentBlockSchema, ToolResultBlockSchema, OtherBlockSchema, ContentBlockSchema, MessageSchema, ToolSchema, ToolChoiceSchema, SystemSchema, MessagesRequestSchema, CountTokensRequestSchema;
|
|
7874
|
+
var init_anthropic = __esm({
|
|
7875
|
+
"src/codex/anthropic.ts"() {
|
|
7876
|
+
"use strict";
|
|
7877
|
+
TextBlockSchema = z23.looseObject({ type: z23.literal("text"), text: z23.string() });
|
|
7878
|
+
Base64ImageSourceSchema = z23.looseObject({ type: z23.literal("base64"), media_type: z23.string().min(1), data: z23.string() });
|
|
7879
|
+
UrlImageSourceSchema = z23.looseObject({ type: z23.literal("url"), url: z23.string().min(1) });
|
|
7880
|
+
ImageBlockSchema = z23.looseObject({
|
|
7881
|
+
type: z23.literal("image"),
|
|
7882
|
+
source: z23.union([Base64ImageSourceSchema, UrlImageSourceSchema])
|
|
7883
|
+
});
|
|
7884
|
+
ToolUseBlockSchema = z23.looseObject({
|
|
7885
|
+
type: z23.literal("tool_use"),
|
|
7886
|
+
id: z23.string().min(1),
|
|
7887
|
+
name: z23.string().min(1),
|
|
7888
|
+
input: z23.unknown()
|
|
7889
|
+
});
|
|
7890
|
+
ToolResultContentBlockSchema = z23.union([TextBlockSchema, z23.looseObject({ type: z23.string() })]);
|
|
7891
|
+
ToolResultBlockSchema = z23.looseObject({
|
|
7892
|
+
type: z23.literal("tool_result"),
|
|
7893
|
+
tool_use_id: z23.string().min(1),
|
|
7894
|
+
content: z23.union([z23.string(), z23.array(ToolResultContentBlockSchema)]).optional()
|
|
7895
|
+
});
|
|
7896
|
+
OtherBlockSchema = z23.looseObject({ type: z23.string() });
|
|
7897
|
+
ContentBlockSchema = z23.union([TextBlockSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultBlockSchema, OtherBlockSchema]);
|
|
7898
|
+
MessageSchema = z23.looseObject({
|
|
7899
|
+
role: z23.enum(["user", "assistant", "system"]),
|
|
7900
|
+
content: z23.union([z23.string(), z23.array(ContentBlockSchema)])
|
|
7901
|
+
});
|
|
7902
|
+
ToolSchema = z23.looseObject({
|
|
7903
|
+
name: z23.string().min(1),
|
|
7904
|
+
description: z23.string().optional(),
|
|
7905
|
+
input_schema: z23.record(z23.string(), z23.unknown()).optional()
|
|
7906
|
+
});
|
|
7907
|
+
ToolChoiceSchema = z23.union([
|
|
7908
|
+
z23.looseObject({ type: z23.enum(["auto", "none", "any"]) }),
|
|
7909
|
+
z23.looseObject({ type: z23.literal("tool"), name: z23.string().min(1) })
|
|
7910
|
+
]);
|
|
7911
|
+
SystemSchema = z23.union([z23.string(), z23.array(z23.union([TextBlockSchema, OtherBlockSchema]))]);
|
|
7912
|
+
MessagesRequestSchema = z23.looseObject({
|
|
7913
|
+
model: z23.string().optional(),
|
|
7914
|
+
system: SystemSchema.optional(),
|
|
7915
|
+
messages: z23.array(MessageSchema),
|
|
7916
|
+
tools: z23.array(ToolSchema).optional(),
|
|
7917
|
+
tool_choice: ToolChoiceSchema.optional(),
|
|
7918
|
+
stream: z23.boolean().optional(),
|
|
7919
|
+
/** `user_id` is stable for one Claude Code session and differs between sessions, which is what makes it the right key for both the backend's prompt cache and its session header. */
|
|
7920
|
+
metadata: z23.looseObject({ user_id: z23.string().optional() }).optional(),
|
|
7921
|
+
/** Claude Code's effort setting. Any string is accepted; the translator honours only the levels the backend understands. */
|
|
7922
|
+
output_config: z23.looseObject({ effort: z23.string().optional() }).optional()
|
|
7923
|
+
});
|
|
7924
|
+
CountTokensRequestSchema = z23.looseObject({
|
|
7925
|
+
system: z23.unknown().optional(),
|
|
7926
|
+
messages: z23.unknown().optional(),
|
|
7927
|
+
tools: z23.unknown().optional()
|
|
7928
|
+
});
|
|
7929
|
+
}
|
|
7930
|
+
});
|
|
7931
|
+
|
|
7932
|
+
// src/antigravity/translate.ts
|
|
7933
|
+
function candidatesOf(target) {
|
|
7934
|
+
return typeof target === "string" ? [target] : target;
|
|
7935
|
+
}
|
|
7936
|
+
function isAntigravityTier(key) {
|
|
7937
|
+
return CLAUDE_TIERS.some((tier) => tier === key);
|
|
7938
|
+
}
|
|
7939
|
+
function resolveAntigravityConfig(config) {
|
|
7940
|
+
const overrides = config?.models ?? {};
|
|
7941
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
7942
|
+
for (const [key, target] of Object.entries(overrides)) {
|
|
7943
|
+
if (!isAntigravityTier(key)) {
|
|
7944
|
+
aliases.set(key.toLowerCase(), candidatesOf(target));
|
|
7945
|
+
}
|
|
7946
|
+
}
|
|
7947
|
+
const tierModel = (tier) => {
|
|
7948
|
+
const target = overrides[tier];
|
|
7949
|
+
return target === void 0 ? ANTIGRAVITY_DEFAULT_TIER_MODELS[tier] : candidatesOf(target);
|
|
7950
|
+
};
|
|
7951
|
+
if (!aliases.has(AUTO_ALIAS)) {
|
|
7952
|
+
aliases.set(AUTO_ALIAS, [...new Set(CLAUDE_TIERS.flatMap(tierModel))]);
|
|
7953
|
+
}
|
|
7954
|
+
return {
|
|
7955
|
+
mode: config?.mode ?? ANTIGRAVITY_DEFAULT_MODE,
|
|
7956
|
+
defaultModel: config?.defaultModel ?? ANTIGRAVITY_DEFAULT_MODEL,
|
|
7957
|
+
models: { fable: tierModel("fable"), opus: tierModel("opus"), sonnet: tierModel("sonnet"), haiku: tierModel("haiku") },
|
|
7958
|
+
aliases,
|
|
7959
|
+
degradeDownTiers: config?.degradeDownTiers ?? false,
|
|
7960
|
+
effort: config?.effort ?? ANTIGRAVITY_DEFAULT_EFFORT,
|
|
7961
|
+
cloud: {
|
|
7962
|
+
endpoint: config?.cloud?.endpoint,
|
|
7963
|
+
projectId: config?.cloud?.projectId,
|
|
7964
|
+
location: config?.cloud?.location
|
|
7965
|
+
},
|
|
7966
|
+
local: {
|
|
7967
|
+
command: config?.local?.command,
|
|
7968
|
+
socketPath: config?.local?.socketPath
|
|
7969
|
+
}
|
|
7970
|
+
};
|
|
7971
|
+
}
|
|
7972
|
+
var AUTO_ALIAS;
|
|
7973
|
+
var init_translate = __esm({
|
|
7974
|
+
"src/antigravity/translate.ts"() {
|
|
7975
|
+
"use strict";
|
|
7976
|
+
init_identity2();
|
|
7977
|
+
init_engine();
|
|
7978
|
+
init_quota();
|
|
7979
|
+
init_signatures();
|
|
7980
|
+
init_schema();
|
|
7981
|
+
init_anthropic();
|
|
7982
|
+
AUTO_ALIAS = "auto";
|
|
7983
|
+
}
|
|
7984
|
+
});
|
|
7985
|
+
|
|
7986
|
+
// src/codex/translate.ts
|
|
7987
|
+
function resolveCodexConfig(config) {
|
|
7988
|
+
const overrides = config?.models;
|
|
7989
|
+
return {
|
|
7990
|
+
defaultModel: config?.defaultModel ?? CODEX_DEFAULT_MODEL,
|
|
7991
|
+
models: {
|
|
7992
|
+
fable: overrides?.fable ?? CODEX_DEFAULT_TIER_MODELS.fable,
|
|
7993
|
+
opus: overrides?.opus ?? CODEX_DEFAULT_TIER_MODELS.opus,
|
|
7994
|
+
sonnet: overrides?.sonnet ?? CODEX_DEFAULT_TIER_MODELS.sonnet,
|
|
7995
|
+
haiku: overrides?.haiku ?? CODEX_DEFAULT_TIER_MODELS.haiku
|
|
7996
|
+
},
|
|
7997
|
+
effort: config?.effort ?? CODEX_DEFAULT_EFFORT,
|
|
7998
|
+
login: config?.login ?? CODEX_DEFAULT_LOGIN
|
|
7999
|
+
};
|
|
8000
|
+
}
|
|
8001
|
+
var init_translate2 = __esm({
|
|
8002
|
+
"src/codex/translate.ts"() {
|
|
8003
|
+
"use strict";
|
|
8004
|
+
init_schema();
|
|
8005
|
+
init_anthropic();
|
|
8006
|
+
}
|
|
8007
|
+
});
|
|
8008
|
+
|
|
8009
|
+
// src/providerCatalogue.ts
|
|
8010
|
+
import path30 from "node:path";
|
|
8011
|
+
import picomatch4 from "picomatch";
|
|
8012
|
+
import { z as z24 } from "zod";
|
|
8013
|
+
function catalogueCachePath(paths, name) {
|
|
8014
|
+
return path30.join(paths.catalogueDir, `${name}.json`);
|
|
8015
|
+
}
|
|
8016
|
+
function parseCatalogueCache(text) {
|
|
8017
|
+
if (text === void 0) {
|
|
8018
|
+
return void 0;
|
|
8019
|
+
}
|
|
8020
|
+
try {
|
|
8021
|
+
const parsed = CatalogueCacheSchema.safeParse(JSON.parse(text));
|
|
8022
|
+
return parsed.success ? parsed.data : void 0;
|
|
8023
|
+
} catch {
|
|
8024
|
+
return void 0;
|
|
8025
|
+
}
|
|
8026
|
+
}
|
|
8027
|
+
function filterCatalogue(models, catalogue) {
|
|
8028
|
+
const included = catalogue.include === void 0 ? void 0 : picomatch4(catalogue.include, { dot: true });
|
|
8029
|
+
const excluded = catalogue.exclude === void 0 ? void 0 : picomatch4(catalogue.exclude, { dot: true });
|
|
8030
|
+
return models.filter((model) => included?.(model.id) !== false && excluded?.(model.id) !== true);
|
|
8031
|
+
}
|
|
8032
|
+
var DEFAULT_CANDIDATE_URLS, MS_PER_SECOND5, SECONDS_PER_HOUR2, HOURS_PER_DAY5, MS_PER_HOUR4, HOURS_BETWEEN_RETRIES, CATALOGUE_MAX_AGE_MS, CATALOGUE_RETRY_MS, CATALOGUE_REQUEST_SECONDS, CATALOGUE_REQUEST_TIMEOUT_MS, CATALOGUE_REFRESH_TIMEOUT_MS, CatalogueModelSchema, CatalogueCacheSchema;
|
|
8033
|
+
var init_providerCatalogue = __esm({
|
|
8034
|
+
"src/providerCatalogue.ts"() {
|
|
8035
|
+
"use strict";
|
|
8036
|
+
DEFAULT_CANDIDATE_URLS = 2;
|
|
8037
|
+
MS_PER_SECOND5 = 1e3;
|
|
8038
|
+
SECONDS_PER_HOUR2 = 3600;
|
|
8039
|
+
HOURS_PER_DAY5 = 24;
|
|
8040
|
+
MS_PER_HOUR4 = SECONDS_PER_HOUR2 * MS_PER_SECOND5;
|
|
8041
|
+
HOURS_BETWEEN_RETRIES = 1;
|
|
8042
|
+
CATALOGUE_MAX_AGE_MS = HOURS_PER_DAY5 * MS_PER_HOUR4;
|
|
8043
|
+
CATALOGUE_RETRY_MS = HOURS_BETWEEN_RETRIES * MS_PER_HOUR4;
|
|
8044
|
+
CATALOGUE_REQUEST_SECONDS = 10;
|
|
8045
|
+
CATALOGUE_REQUEST_TIMEOUT_MS = CATALOGUE_REQUEST_SECONDS * MS_PER_SECOND5;
|
|
8046
|
+
CATALOGUE_REFRESH_TIMEOUT_MS = DEFAULT_CANDIDATE_URLS * CATALOGUE_REQUEST_TIMEOUT_MS;
|
|
8047
|
+
CatalogueModelSchema = z24.strictObject({ id: z24.string().min(1), name: z24.string().min(1).optional() });
|
|
8048
|
+
CatalogueCacheSchema = z24.strictObject({ fetchedAt: z24.number(), url: z24.string().min(1), models: z24.array(CatalogueModelSchema) });
|
|
8049
|
+
}
|
|
8050
|
+
});
|
|
8051
|
+
|
|
8052
|
+
// src/launcher/modelPicker.ts
|
|
8053
|
+
function labelOf(model) {
|
|
8054
|
+
return withoutContextMarker(model);
|
|
8055
|
+
}
|
|
8056
|
+
function describedAs(model, description) {
|
|
8057
|
+
return model.toLowerCase().endsWith(CONTEXT_MARKER_1M) ? `${description}; 1M context` : description;
|
|
8058
|
+
}
|
|
8059
|
+
function joined(parts) {
|
|
8060
|
+
const last = parts[parts.length - 1];
|
|
8061
|
+
return last === void 0 || parts.length === 1 ? last ?? "" : `${parts.slice(0, -1).join(", ")} and ${last}`;
|
|
8062
|
+
}
|
|
8063
|
+
function rowOf2(model, reaches) {
|
|
8064
|
+
const lead = reaches.find((reach) => reach.standing === "first") ?? reaches[0];
|
|
8065
|
+
if (lead === void 0) {
|
|
8066
|
+
throw new Error(`model ${model} is reached by no tier`);
|
|
8067
|
+
}
|
|
8068
|
+
const firsts = reaches.filter((reach) => reach.standing === "first").map((reach) => reach.tier);
|
|
8069
|
+
const fallbacks = reaches.filter((reach) => reach.standing === "fallback").map((reach) => reach.tier);
|
|
8070
|
+
const serves = firsts.length === 0 ? [] : [`Serves the ${joined(firsts)} tier${firsts.length === 1 ? "" : "s"}`];
|
|
8071
|
+
const falls = fallbacks.length === 0 ? [] : [`${serves.length === 0 ? "Fallback" : "fallback"} for ${joined(fallbacks)}`];
|
|
8072
|
+
return { model, label: labelOf(model), description: describedAs(model, [...serves, ...falls].join("; ")), behavesAs: TIER_BEHAVES_AS[lead.tier] };
|
|
8073
|
+
}
|
|
8074
|
+
function rowsOfTable(table) {
|
|
8075
|
+
const reachesByModel = /* @__PURE__ */ new Map();
|
|
8076
|
+
for (const [tier, candidates] of table) {
|
|
8077
|
+
candidates.forEach((model, index) => {
|
|
8078
|
+
const reaches = reachesByModel.get(model) ?? [];
|
|
8079
|
+
if (!reaches.some((reach) => reach.tier === tier)) {
|
|
8080
|
+
reaches.push({ tier, standing: index === 0 ? "first" : "fallback" });
|
|
8081
|
+
}
|
|
8082
|
+
reachesByModel.set(model, reaches);
|
|
8083
|
+
});
|
|
8084
|
+
}
|
|
8085
|
+
return [...reachesByModel].map(([model, reaches]) => rowOf2(model, reaches));
|
|
8086
|
+
}
|
|
8087
|
+
function antigravityRows(provider) {
|
|
8088
|
+
const config = resolveAntigravityConfig(provider.antigravity);
|
|
8089
|
+
const tiers = rowsOfTable(CLAUDE_TIERS.map((tier) => [tier, config.models[tier]]));
|
|
8090
|
+
const behavesAsOf = new Map(tiers.map((row) => [row.model, row.behavesAs]));
|
|
8091
|
+
const aliases = [...config.aliases].flatMap(([alias, candidates]) => {
|
|
8092
|
+
const [first] = candidates;
|
|
8093
|
+
const behavesAs = first === void 0 ? void 0 : behavesAsOf.get(first);
|
|
8094
|
+
const description = alias === AUTO_ALIAS ? `Routes each request to a backend model with quota left, best first (${String(candidates.length)} models)` : `Alias for ${candidates.join(", then ")}`;
|
|
8095
|
+
return behavesAs === void 0 ? [] : [{ model: alias, label: labelOf(alias), description, behavesAs }];
|
|
8096
|
+
});
|
|
8097
|
+
return [...aliases.filter((row) => row.model === AUTO_ALIAS), ...tiers, ...aliases.filter((row) => row.model !== AUTO_ALIAS)];
|
|
8098
|
+
}
|
|
8099
|
+
function codexRows(provider) {
|
|
8100
|
+
const config = resolveCodexConfig(provider.codex);
|
|
8101
|
+
return rowsOfTable(CLAUDE_TIERS.map((tier) => [tier, [config.models[tier]]]));
|
|
8102
|
+
}
|
|
8103
|
+
function httpRows(provider) {
|
|
8104
|
+
const env = provider.env ?? {};
|
|
8105
|
+
const table = CLAUDE_TIERS.flatMap((tier) => {
|
|
8106
|
+
const model = env[TIER_ENV_VARIABLES[tier]];
|
|
8107
|
+
return model === void 0 || model === "" ? [] : [[tier, [model]]];
|
|
8108
|
+
});
|
|
8109
|
+
return rowsOfTable(table);
|
|
8110
|
+
}
|
|
8111
|
+
function declaredRow(entry) {
|
|
8112
|
+
return {
|
|
8113
|
+
model: entry.model,
|
|
8114
|
+
label: entry.label ?? labelOf(entry.model),
|
|
8115
|
+
description: entry.description ?? describedAs(entry.model, `Declared by the provider for the ${entry.tier} tier`),
|
|
8116
|
+
behavesAs: TIER_BEHAVES_AS[entry.tier]
|
|
8117
|
+
};
|
|
8118
|
+
}
|
|
8119
|
+
function catalogueRows(provider, models) {
|
|
8120
|
+
if (provider.kind !== void 0 && provider.kind !== "http" || provider.catalogue === void 0) {
|
|
8121
|
+
return [];
|
|
8122
|
+
}
|
|
8123
|
+
const { tier } = provider.catalogue;
|
|
8124
|
+
return filterCatalogue(models, provider.catalogue).map((model) => ({ model: model.id, label: labelOf(model.id), description: describedAs(model.id, model.name === void 0 ? "Listed by the provider" : `Listed by the provider as ${model.name}`), behavesAs: TIER_BEHAVES_AS[tier] })).sort((left, right) => left.model.localeCompare(right.model));
|
|
8125
|
+
}
|
|
8126
|
+
function providerModelRows(provider, catalogue = []) {
|
|
8127
|
+
const derived = provider.kind === "codex" ? codexRows(provider) : provider.kind === "antigravity" ? antigravityRows(provider) : provider.kind === "router" ? [] : httpRows(provider);
|
|
8128
|
+
const declared = provider.kind === "router" ? [] : (provider.pickerModels ?? []).map(declaredRow);
|
|
8129
|
+
const declaredModels = new Set(declared.map((row) => row.model));
|
|
8130
|
+
const named = [...derived.filter((row) => !declaredModels.has(row.model)), ...declared];
|
|
8131
|
+
const taken = new Set(named.map((row) => labelOf(row.model)));
|
|
8132
|
+
return [...named, ...catalogueRows(provider, catalogue).filter((row) => !taken.has(labelOf(row.model)))];
|
|
8133
|
+
}
|
|
8134
|
+
function routedModelRows(models, providers) {
|
|
8135
|
+
const hidden = new Set(models.hide ?? []);
|
|
8136
|
+
const shown = models.show === void 0 ? void 0 : new Set(models.show);
|
|
8137
|
+
const visible = (model) => shown === void 0 ? !hidden.has(model) : shown.has(model);
|
|
8138
|
+
const concrete = providers.flatMap(([name, provider]) => providerModelRows(provider).map((row) => ({ ...row, model: `${name}/${row.model}`, label: `${name} / ${row.label}`, description: `${name}: ${row.description}` })));
|
|
8139
|
+
const concreteByRef = new Map(concrete.map((row) => [row.model, row]));
|
|
8140
|
+
const families = buildFamilies([...concrete.map((row) => row.model), ...accountRefsOf(models)], models);
|
|
8141
|
+
const handlingOf = (refs) => refs.map((ref) => concreteByRef.get(ref)?.behavesAs).find((behavesAs) => behavesAs !== void 0) ?? TIER_BEHAVES_AS.sonnet;
|
|
8142
|
+
const virtual = Object.entries(models.virtual ?? {}).flatMap(([name, definition]) => {
|
|
8143
|
+
if (!visible(name)) {
|
|
8144
|
+
return [];
|
|
8145
|
+
}
|
|
8146
|
+
const targets = expandFamilyMembers(safeExpand(name, models), families);
|
|
8147
|
+
return [{ model: name, label: name, description: `Virtual (${definition.mode})`, behavesAs: handlingOf(targets) }];
|
|
8148
|
+
});
|
|
8149
|
+
const familyRows = sharedFamilies(families).flatMap((family) => {
|
|
8150
|
+
const member = `${FAMILY_PREFIX}${family.key}`;
|
|
8151
|
+
return visible(member) ? [{ model: member, label: family.key, description: `Family (${familyMode(family.settings)}): ${family.refs.join(", ")}`, behavesAs: handlingOf(family.refs) }] : [];
|
|
8152
|
+
});
|
|
8153
|
+
return [...virtual, ...familyRows, ...concrete.filter((row) => visible(row.model))];
|
|
8154
|
+
}
|
|
8155
|
+
function safeExpand(name, models) {
|
|
8156
|
+
try {
|
|
8157
|
+
return expandMembers(name, models);
|
|
8158
|
+
} catch {
|
|
8159
|
+
return models.virtual?.[name]?.members ?? [];
|
|
8160
|
+
}
|
|
8161
|
+
}
|
|
8162
|
+
function modelPickerSettings(provider, catalogue = []) {
|
|
8163
|
+
return modelPickerSettingsFromRows(providerModelRows(provider, catalogue), true);
|
|
8164
|
+
}
|
|
8165
|
+
function modelPickerSettingsFromRows(options, replaceBuiltInOptions) {
|
|
8166
|
+
return options.length === 0 ? void 0 : JSON.stringify({ modelPicker: { options, replaceBuiltInOptions } });
|
|
8167
|
+
}
|
|
8168
|
+
var TIER_BEHAVES_AS, TIER_ENV_VARIABLES;
|
|
8169
|
+
var init_modelPicker = __esm({
|
|
8170
|
+
"src/launcher/modelPicker.ts"() {
|
|
8171
|
+
"use strict";
|
|
8172
|
+
init_translate();
|
|
8173
|
+
init_translate2();
|
|
8174
|
+
init_providerCatalogue();
|
|
8175
|
+
init_schema();
|
|
8176
|
+
init_identity2();
|
|
8177
|
+
init_families();
|
|
8178
|
+
init_modelsStore();
|
|
8179
|
+
TIER_BEHAVES_AS = Object.freeze({
|
|
8180
|
+
fable: "claude-fable-5-1",
|
|
8181
|
+
opus: "claude-opus-5-5",
|
|
8182
|
+
sonnet: "claude-sonnet-5-5",
|
|
8183
|
+
haiku: "claude-haiku-5-5"
|
|
8184
|
+
});
|
|
8185
|
+
TIER_ENV_VARIABLES = Object.freeze({
|
|
8186
|
+
fable: "ANTHROPIC_DEFAULT_FABLE_MODEL",
|
|
8187
|
+
opus: "ANTHROPIC_DEFAULT_OPUS_MODEL",
|
|
8188
|
+
sonnet: "ANTHROPIC_DEFAULT_SONNET_MODEL",
|
|
8189
|
+
haiku: "ANTHROPIC_DEFAULT_HAIKU_MODEL"
|
|
8190
|
+
});
|
|
8191
|
+
}
|
|
8192
|
+
});
|
|
8193
|
+
|
|
8194
|
+
// src/models/targets.ts
|
|
8195
|
+
function providerModels(paths) {
|
|
8196
|
+
return listProviders(paths).flatMap((entry) => {
|
|
8197
|
+
const catalogue = parseCatalogueCache(realFsPort.readFileUtf8(catalogueCachePath(paths, entry.name)));
|
|
8198
|
+
return providerModelRows(entry.provider, catalogue?.models).map((row) => ({ provider: entry.name, model: row.model }));
|
|
8199
|
+
});
|
|
8200
|
+
}
|
|
8201
|
+
function targetRefs(paths) {
|
|
8202
|
+
return providerModels(paths).map((entry) => `${entry.provider}/${entry.model}`);
|
|
8203
|
+
}
|
|
8204
|
+
var init_targets = __esm({
|
|
8205
|
+
"src/models/targets.ts"() {
|
|
8206
|
+
"use strict";
|
|
8207
|
+
init_modelPicker();
|
|
8208
|
+
init_providerCatalogue();
|
|
8209
|
+
init_providersStore();
|
|
8210
|
+
init_realPorts();
|
|
8211
|
+
}
|
|
8212
|
+
});
|
|
8213
|
+
|
|
8214
|
+
// src/frontdoor/probe.ts
|
|
8215
|
+
import { Worker } from "node:worker_threads";
|
|
8216
|
+
function probeFrontDoorSync(port, caPem) {
|
|
8217
|
+
refuseToBlockInRole("a synchronous probe of the front door");
|
|
8218
|
+
return runProbeWorker(PROBE_SOURCE, { port, ca: caPem });
|
|
8219
|
+
}
|
|
8220
|
+
function probeListenerAcceptSync(port) {
|
|
8221
|
+
refuseToBlockInRole("a synchronous probe of a front door listener");
|
|
8222
|
+
return runProbeWorker(ACCEPT_PROBE_SOURCE, { port });
|
|
8223
|
+
}
|
|
8224
|
+
function runProbeWorker(source, data) {
|
|
8225
|
+
const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
|
|
8226
|
+
const header = new Int32Array(shared, 0, HEADER_SLOTS);
|
|
8227
|
+
const worker = new Worker(source, {
|
|
8228
|
+
eval: true,
|
|
8229
|
+
workerData: { ...data, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
|
|
8230
|
+
});
|
|
8231
|
+
worker.unref();
|
|
8232
|
+
try {
|
|
8233
|
+
const waited = Atomics.wait(header, 0, VERDICT_PENDING, PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS);
|
|
8234
|
+
const verdict = Atomics.load(header, 0);
|
|
8235
|
+
if (waited === "timed-out" || verdict === VERDICT_PENDING) {
|
|
8236
|
+
return { ok: false, reason: `the probe did not finish within ${String(PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS)}ms` };
|
|
8237
|
+
}
|
|
8238
|
+
if (verdict === VERDICT_OK) {
|
|
8239
|
+
return { ok: true };
|
|
8240
|
+
}
|
|
8241
|
+
const length = Atomics.load(header, 1);
|
|
8242
|
+
return { ok: false, reason: Buffer.from(new Uint8Array(shared, HEADER_SLOTS * INT32_BYTES, length)).toString("utf8") };
|
|
8243
|
+
} finally {
|
|
8244
|
+
void worker.terminate();
|
|
8245
|
+
}
|
|
8246
|
+
}
|
|
8247
|
+
var PROBE_TIMEOUT_MS, PROBE_WAIT_MARGIN_MS, REASON_BYTES, HEADER_SLOTS, INT32_BYTES, VERDICT_PENDING, VERDICT_OK, VERDICT_FAILED, PROBE_SOURCE, ACCEPT_PROBE_SOURCE;
|
|
8248
|
+
var init_probe = __esm({
|
|
8249
|
+
"src/frontdoor/probe.ts"() {
|
|
8250
|
+
"use strict";
|
|
8251
|
+
init_processRole();
|
|
8252
|
+
PROBE_TIMEOUT_MS = 2e3;
|
|
8253
|
+
PROBE_WAIT_MARGIN_MS = 1e3;
|
|
8254
|
+
REASON_BYTES = 1024;
|
|
8255
|
+
HEADER_SLOTS = 2;
|
|
8256
|
+
INT32_BYTES = 4;
|
|
8257
|
+
VERDICT_PENDING = 0;
|
|
8258
|
+
VERDICT_OK = 1;
|
|
8259
|
+
VERDICT_FAILED = 2;
|
|
8260
|
+
PROBE_SOURCE = `
|
|
8261
|
+
const { workerData } = require("node:worker_threads");
|
|
8262
|
+
const https = require("node:https");
|
|
8263
|
+
const { port, ca, timeoutMs, shared, ok, failed, headerSlots } = workerData;
|
|
8264
|
+
const header = new Int32Array(shared, 0, headerSlots);
|
|
8265
|
+
const reason = new Uint8Array(shared, headerSlots * 4);
|
|
8266
|
+
let done = false;
|
|
8267
|
+
const finish = (verdict, message) => {
|
|
8268
|
+
if (done) return;
|
|
8269
|
+
done = true;
|
|
8270
|
+
const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
|
|
8271
|
+
reason.set(bytes);
|
|
8272
|
+
Atomics.store(header, 1, bytes.length);
|
|
8273
|
+
Atomics.store(header, 0, verdict);
|
|
8274
|
+
Atomics.notify(header, 0);
|
|
8275
|
+
};
|
|
8276
|
+
const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca], agent: false }, (response) => {
|
|
8277
|
+
let body = "";
|
|
8278
|
+
response.setEncoding("utf8");
|
|
8279
|
+
response.on("data", (chunk) => { body += chunk; });
|
|
8280
|
+
response.on("end", () => {
|
|
8281
|
+
if (response.statusCode === 200 && body === "ok") finish(ok, "");
|
|
8282
|
+
else finish(failed, "the listener answered its health probe with HTTP " + String(response.statusCode));
|
|
8283
|
+
});
|
|
8284
|
+
response.on("error", (error) => finish(failed, error.message));
|
|
8285
|
+
});
|
|
8286
|
+
// A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
|
|
8287
|
+
setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
|
|
8288
|
+
request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
|
|
8289
|
+
`;
|
|
8290
|
+
ACCEPT_PROBE_SOURCE = `
|
|
8291
|
+
const { workerData } = require("node:worker_threads");
|
|
8292
|
+
const net = require("node:net");
|
|
8293
|
+
const { port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
|
|
8294
|
+
const header = new Int32Array(shared, 0, headerSlots);
|
|
8295
|
+
const reason = new Uint8Array(shared, headerSlots * 4);
|
|
8296
|
+
let done = false;
|
|
8297
|
+
const finish = (verdict, message) => {
|
|
8298
|
+
if (done) return;
|
|
8299
|
+
done = true;
|
|
8300
|
+
const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
|
|
8301
|
+
reason.set(bytes);
|
|
8302
|
+
Atomics.store(header, 1, bytes.length);
|
|
8303
|
+
Atomics.store(header, 0, verdict);
|
|
8304
|
+
Atomics.notify(header, 0);
|
|
8305
|
+
};
|
|
8306
|
+
const socket = net.connect({ host: "127.0.0.1", port });
|
|
8307
|
+
socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
|
|
8308
|
+
socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
|
|
8309
|
+
setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
|
|
8310
|
+
`;
|
|
8311
|
+
}
|
|
8312
|
+
});
|
|
8313
|
+
|
|
8314
|
+
// src/update/update.ts
|
|
8315
|
+
function compareVersions3(left, right) {
|
|
8316
|
+
const parse = (version) => {
|
|
8317
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
8318
|
+
if (match === null) {
|
|
8319
|
+
throw new Error(`not a plain release version: ${version}`);
|
|
8320
|
+
}
|
|
8321
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
8322
|
+
};
|
|
8323
|
+
const leftParts = parse(left);
|
|
8324
|
+
const rightParts = parse(right);
|
|
8325
|
+
return leftParts.map((part, index) => part - (rightParts[index] ?? 0)).find((difference) => difference !== 0) ?? 0;
|
|
8326
|
+
}
|
|
8327
|
+
function releaseTagFromUrl(url) {
|
|
8328
|
+
const segment = url.split("?")[0]?.split("/").at(-1);
|
|
8329
|
+
const candidate = segment?.startsWith("v") === true ? segment.slice(1) : void 0;
|
|
8330
|
+
return candidate !== void 0 && /^\d+\.\d+\.\d+$/.test(candidate) ? candidate : void 0;
|
|
8331
|
+
}
|
|
8332
|
+
var LATEST_RELEASE_URL, UpdateChannelError, UpdateConflictError, UpdateDownloadError;
|
|
8333
|
+
var init_update = __esm({
|
|
8334
|
+
"src/update/update.ts"() {
|
|
8335
|
+
"use strict";
|
|
8336
|
+
init_cliError();
|
|
8337
|
+
LATEST_RELEASE_URL = "https://github.com/ExaDev/agent-shim/releases/latest";
|
|
8338
|
+
UpdateChannelError = class extends CliError {
|
|
8339
|
+
constructor(message) {
|
|
8340
|
+
super(message);
|
|
8341
|
+
this.name = "UpdateChannelError";
|
|
8342
|
+
}
|
|
8343
|
+
};
|
|
8344
|
+
UpdateConflictError = class extends CliError {
|
|
8345
|
+
constructor(message) {
|
|
8346
|
+
super(message);
|
|
8347
|
+
this.name = "UpdateConflictError";
|
|
8348
|
+
}
|
|
8349
|
+
};
|
|
8350
|
+
UpdateDownloadError = class extends CliError {
|
|
8351
|
+
constructor(message) {
|
|
8352
|
+
super(message);
|
|
8353
|
+
this.name = "UpdateDownloadError";
|
|
8354
|
+
}
|
|
8355
|
+
};
|
|
8356
|
+
}
|
|
8357
|
+
});
|
|
8358
|
+
|
|
8359
|
+
// src/frontdoor/ensure.ts
|
|
7724
8360
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
7725
8361
|
function ensureFrontDoor(params) {
|
|
7726
8362
|
const { paths, ports } = params;
|
|
@@ -7763,7 +8399,7 @@ function ensureFrontDoor(params) {
|
|
|
7763
8399
|
if (state?.port !== void 0 && state.connectPort !== void 0) {
|
|
7764
8400
|
if (supervisorPid === params.launcherPid && params.replace !== true && ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
7765
8401
|
const token = randomUUID3();
|
|
7766
|
-
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid });
|
|
8402
|
+
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
7767
8403
|
return { port: state.port, connectPort: state.connectPort, token };
|
|
7768
8404
|
}
|
|
7769
8405
|
const verdict = verifyWithRetry(state.port);
|
|
@@ -7777,7 +8413,7 @@ function ensureFrontDoor(params) {
|
|
|
7777
8413
|
}
|
|
7778
8414
|
if (verdict.ok) {
|
|
7779
8415
|
const token = randomUUID3();
|
|
7780
|
-
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid });
|
|
8416
|
+
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid, ...recordOf(params.session) });
|
|
7781
8417
|
return { port: state.port, connectPort: state.connectPort, token };
|
|
7782
8418
|
}
|
|
7783
8419
|
lastRejection = `the listener on 127.0.0.1:${String(state.port)} (recorded for pid ${String(supervisorPid)}) failed authentication: ${verdict.reason}`;
|
|
@@ -8179,7 +8815,7 @@ var init_headers = __esm({
|
|
|
8179
8815
|
});
|
|
8180
8816
|
|
|
8181
8817
|
// src/launcher/flags.ts
|
|
8182
|
-
import
|
|
8818
|
+
import path37 from "node:path";
|
|
8183
8819
|
function resolveLaunchFlags(params) {
|
|
8184
8820
|
return {
|
|
8185
8821
|
skipPermissions: params.flags?.skipPermissions ?? parseEnvBool("AGENT_SHIM_SKIP_PERMISSIONS", params.env.AGENT_SHIM_SKIP_PERMISSIONS) ?? params.cascade?.skipPermissions ?? false,
|
|
@@ -8226,7 +8862,7 @@ function buildEnv(params) {
|
|
|
8226
8862
|
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
8227
8863
|
let providerCustomHeaders;
|
|
8228
8864
|
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
8229
|
-
env.CLAUDE_CONFIG_DIR =
|
|
8865
|
+
env.CLAUDE_CONFIG_DIR = path37.join(params.identitiesDir, params.resolvedIdentityName);
|
|
8230
8866
|
}
|
|
8231
8867
|
if (params.provider !== void 0) {
|
|
8232
8868
|
const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
|
|
@@ -8234,787 +8870,399 @@ function buildEnv(params) {
|
|
|
8234
8870
|
env.ANTHROPIC_BASE_URL = void 0;
|
|
8235
8871
|
env.AGENT_SHIM_PROVIDER = params.provider.definition.displayName;
|
|
8236
8872
|
for (const [key, value] of Object.entries(providerEnv)) {
|
|
8237
|
-
env[key] = value;
|
|
8238
|
-
}
|
|
8239
|
-
}
|
|
8240
|
-
if (params.provider !== void 0) {
|
|
8241
|
-
env.ANTHROPIC_AUTH_TOKEN = params.remoteControl ? void 0 : PROVIDER_SESSION_PLACEHOLDER;
|
|
8242
|
-
env.ANTHROPIC_API_KEY = void 0;
|
|
8243
|
-
env.CLAUDE_CODE_OAUTH_TOKEN = void 0;
|
|
8244
|
-
} else if (params.identityCredential !== void 0) {
|
|
8245
|
-
for (const [variable, value] of Object.entries(credentialVariables(params.identityCredential.target, params.identityCredential.token))) {
|
|
8246
|
-
env[variable] = value;
|
|
8247
|
-
}
|
|
8248
|
-
}
|
|
8249
|
-
if (params.frontdoor !== void 0) {
|
|
8250
|
-
env.ANTHROPIC_CUSTOM_HEADERS = mergeAnthropicCustomHeaders(
|
|
8251
|
-
[
|
|
8252
|
-
...parentCustomHeaders === void 0 ? [] : [parentCustomHeaders],
|
|
8253
|
-
...providerCustomHeaders === void 0 ? [] : [providerCustomHeaders]
|
|
8254
|
-
],
|
|
8255
|
-
[
|
|
8256
|
-
...params.resolvedIdentityName === void 0 ? [] : [{ name: IDENTITY_HEADER, value: params.resolvedIdentityName }],
|
|
8257
|
-
{ name: SESSION_HEADER, value: params.sessionId },
|
|
8258
|
-
{ name: AUTH_HEADER, value: params.frontdoor.sessionToken },
|
|
8259
|
-
...params.provider === void 0 ? [] : [{ name: PROVIDER_HEADER, value: params.provider.name }],
|
|
8260
|
-
...params.routeByName ? [{ name: ROUTE_BY_NAME_HEADER, value: "1" }] : [],
|
|
8261
|
-
...params.headroom === void 0 ? [] : [
|
|
8262
|
-
{ name: HEADROOM_FLAG_HEADER, value: "1" },
|
|
8263
|
-
{ name: PROJECT_ID_HEADER, value: params.headroom.projectId }
|
|
8264
|
-
]
|
|
8265
|
-
]
|
|
8266
|
-
);
|
|
8267
|
-
env.NODE_EXTRA_CA_CERTS = params.frontdoor.trustBundlePath;
|
|
8268
|
-
env.HTTPS_PROXY = connectProxyUrl(params.frontdoor.connectPort, params.frontdoor.sessionToken);
|
|
8269
|
-
env.NO_PROXY = withLoopbackHosts(env.NO_PROXY);
|
|
8270
|
-
env.no_proxy = withLoopbackHosts(env.no_proxy);
|
|
8271
|
-
}
|
|
8272
|
-
return env;
|
|
8273
|
-
}
|
|
8274
|
-
var LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
|
|
8275
|
-
var init_flags = __esm({
|
|
8276
|
-
"src/launcher/flags.ts"() {
|
|
8277
|
-
"use strict";
|
|
8278
|
-
init_envBool();
|
|
8279
|
-
init_cliError();
|
|
8280
|
-
init_conditions();
|
|
8281
|
-
init_credential();
|
|
8282
|
-
init_headers();
|
|
8283
|
-
init_capability();
|
|
8284
|
-
init_route();
|
|
8285
|
-
LOOPBACK_HOSTS = ["127.0.0.1", "localhost", "::1"];
|
|
8286
|
-
PROVIDER_SESSION_PLACEHOLDER = "agent-shim-provider-session";
|
|
8287
|
-
}
|
|
8288
|
-
});
|
|
8289
|
-
|
|
8290
|
-
// src/launcher/extraFlags.ts
|
|
8291
|
-
function splitExtraFlags(value) {
|
|
8292
|
-
if (value === void 0) {
|
|
8293
|
-
return [];
|
|
8294
|
-
}
|
|
8295
|
-
const trimmed = value.trim();
|
|
8296
|
-
if (trimmed === "") {
|
|
8297
|
-
return [];
|
|
8298
|
-
}
|
|
8299
|
-
return trimmed.split(/\s+/);
|
|
8300
|
-
}
|
|
8301
|
-
var init_extraFlags = __esm({
|
|
8302
|
-
"src/launcher/extraFlags.ts"() {
|
|
8303
|
-
"use strict";
|
|
8304
|
-
}
|
|
8305
|
-
});
|
|
8306
|
-
|
|
8307
|
-
// src/usage/resumeContext.ts
|
|
8308
|
-
import path37 from "node:path";
|
|
8309
|
-
function projectDirNameOf(cwd) {
|
|
8310
|
-
return cwd.replace(/[^A-Za-z0-9]/g, "-");
|
|
8311
|
-
}
|
|
8312
|
-
function resumeTargetOf(passthrough) {
|
|
8313
|
-
const end = passthrough.indexOf("--");
|
|
8314
|
-
const tokens = end === -1 ? passthrough : passthrough.slice(0, end);
|
|
8315
|
-
for (const [index, token] of tokens.entries()) {
|
|
8316
|
-
if (token === "--continue" || token === "-c") {
|
|
8317
|
-
return { kind: "latest" };
|
|
8318
|
-
}
|
|
8319
|
-
if (token === "--resume" || token === "-r") {
|
|
8320
|
-
const next = tokens[index + 1];
|
|
8321
|
-
return next === void 0 || next.startsWith("-") ? void 0 : { kind: "id", id: next };
|
|
8322
|
-
}
|
|
8323
|
-
if (token.startsWith("--resume=")) {
|
|
8324
|
-
const id = token.slice("--resume=".length);
|
|
8325
|
-
return id === "" ? void 0 : { kind: "id", id };
|
|
8326
|
-
}
|
|
8327
|
-
}
|
|
8328
|
-
return void 0;
|
|
8329
|
-
}
|
|
8330
|
-
function countOf(usage, key) {
|
|
8331
|
-
const value = key in usage ? Reflect.get(usage, key) : void 0;
|
|
8332
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
8333
|
-
}
|
|
8334
|
-
function contextTokensOfTranscript(text) {
|
|
8335
|
-
const lines = text.split("\n");
|
|
8336
|
-
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
8337
|
-
const line = lines[index];
|
|
8338
|
-
if (line === void 0 || line === "") {
|
|
8339
|
-
continue;
|
|
8340
|
-
}
|
|
8341
|
-
let parsed;
|
|
8342
|
-
try {
|
|
8343
|
-
parsed = JSON.parse(line);
|
|
8344
|
-
} catch {
|
|
8345
|
-
continue;
|
|
8346
|
-
}
|
|
8347
|
-
if (typeof parsed !== "object" || parsed === null || !("type" in parsed) || parsed.type !== "assistant" || !("message" in parsed)) {
|
|
8348
|
-
continue;
|
|
8349
|
-
}
|
|
8350
|
-
const { message } = parsed;
|
|
8351
|
-
if (typeof message !== "object" || message === null || !("usage" in message) || typeof message.usage !== "object" || message.usage === null) {
|
|
8352
|
-
continue;
|
|
8353
|
-
}
|
|
8354
|
-
const { usage } = message;
|
|
8355
|
-
return countOf(usage, "input_tokens") + countOf(usage, "cache_read_input_tokens") + countOf(usage, "cache_creation_input_tokens");
|
|
8356
|
-
}
|
|
8357
|
-
return void 0;
|
|
8358
|
-
}
|
|
8359
|
-
function newestTranscript(fs13, projectDir) {
|
|
8360
|
-
let newest;
|
|
8361
|
-
let newestMs = -Infinity;
|
|
8362
|
-
for (const name of fs13.readdir(projectDir)) {
|
|
8363
|
-
if (!name.endsWith(".jsonl")) {
|
|
8364
|
-
continue;
|
|
8365
|
-
}
|
|
8366
|
-
const candidate = path37.join(projectDir, name);
|
|
8367
|
-
const stat = fs13.lstat(candidate);
|
|
8368
|
-
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
8369
|
-
newestMs = stat.mtimeMs;
|
|
8370
|
-
newest = candidate;
|
|
8371
|
-
}
|
|
8372
|
-
}
|
|
8373
|
-
return newest;
|
|
8374
|
-
}
|
|
8375
|
-
function resumedContextTokens(fs13, params) {
|
|
8376
|
-
const target = resumeTargetOf(params.passthrough);
|
|
8377
|
-
if (target === void 0) {
|
|
8378
|
-
return void 0;
|
|
8379
|
-
}
|
|
8380
|
-
const projectDir = path37.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
8381
|
-
const file = target.kind === "id" ? path37.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs13, projectDir);
|
|
8382
|
-
const text = file === void 0 ? void 0 : fs13.readFileUtf8(file);
|
|
8383
|
-
return text === void 0 ? void 0 : contextTokensOfTranscript(text);
|
|
8384
|
-
}
|
|
8385
|
-
var init_resumeContext = __esm({
|
|
8386
|
-
"src/usage/resumeContext.ts"() {
|
|
8387
|
-
"use strict";
|
|
8388
|
-
}
|
|
8389
|
-
});
|
|
8390
|
-
|
|
8391
|
-
// src/launcher/claudeSession.ts
|
|
8392
|
-
function isFlag(token) {
|
|
8393
|
-
return token?.startsWith("-") === true;
|
|
8394
|
-
}
|
|
8395
|
-
function withConversation(passthrough, conversation, id) {
|
|
8396
|
-
const end = passthrough.indexOf(TERMINATOR2);
|
|
8397
|
-
const head = end === -1 ? passthrough : passthrough.slice(0, end);
|
|
8398
|
-
const tail = end === -1 ? [] : passthrough.slice(end);
|
|
8399
|
-
const kept = [];
|
|
8400
|
-
for (let index = 0; index < head.length; index += 1) {
|
|
8401
|
-
const token = head[index];
|
|
8402
|
-
if (token === void 0 || CONTINUE_FLAGS.has(token) || token.startsWith("--resume=") || token.startsWith("--session-id=")) {
|
|
8403
|
-
continue;
|
|
8404
|
-
}
|
|
8405
|
-
if (VALUED_CONVERSATION_FLAGS.has(token)) {
|
|
8406
|
-
if (!isFlag(head[index + 1]) && head[index + 1] !== void 0) {
|
|
8407
|
-
index += 1;
|
|
8408
|
-
}
|
|
8409
|
-
continue;
|
|
8410
|
-
}
|
|
8411
|
-
kept.push(token);
|
|
8412
|
-
}
|
|
8413
|
-
return [...kept, conversation === "start" ? "--session-id" : "--resume", id, ...tail];
|
|
8414
|
-
}
|
|
8415
|
-
function hasSettingsArgument(passthrough) {
|
|
8416
|
-
const end = passthrough.indexOf(TERMINATOR2);
|
|
8417
|
-
return (end === -1 ? passthrough : passthrough.slice(0, end)).some((token) => token === "--settings" || token.startsWith("--settings="));
|
|
8418
|
-
}
|
|
8419
|
-
function withSupervision(passthrough, supervised) {
|
|
8420
|
-
if (supervised.conversation === "as-given") {
|
|
8421
|
-
return passthrough;
|
|
8422
|
-
}
|
|
8423
|
-
const conversed = withConversation(passthrough, supervised.conversation, supervised.sessionId);
|
|
8424
|
-
if (supervised.model === void 0) {
|
|
8425
|
-
return conversed;
|
|
8426
|
-
}
|
|
8427
|
-
const end = conversed.indexOf(TERMINATOR2);
|
|
8428
|
-
const head = end === -1 ? conversed : conversed.slice(0, end);
|
|
8429
|
-
const tail = end === -1 ? [] : conversed.slice(end);
|
|
8430
|
-
const kept = [];
|
|
8431
|
-
for (let index = 0; index < head.length; index += 1) {
|
|
8432
|
-
const token = head[index];
|
|
8433
|
-
if (token === "--model") {
|
|
8434
|
-
index += 1;
|
|
8435
|
-
continue;
|
|
8436
|
-
}
|
|
8437
|
-
if (token !== void 0 && !token.startsWith("--model=")) {
|
|
8438
|
-
kept.push(token);
|
|
8439
|
-
}
|
|
8440
|
-
}
|
|
8441
|
-
return [...kept, "--model", supervised.model, ...tail];
|
|
8442
|
-
}
|
|
8443
|
-
function withLauncherSettings(passthrough, settings) {
|
|
8444
|
-
if (settings === void 0) {
|
|
8445
|
-
return passthrough;
|
|
8446
|
-
}
|
|
8447
|
-
const end = passthrough.indexOf(TERMINATOR2);
|
|
8448
|
-
return end === -1 ? [...passthrough, "--settings", settings] : [...passthrough.slice(0, end), "--settings", settings, ...passthrough.slice(end)];
|
|
8449
|
-
}
|
|
8450
|
-
function isRecord15(value) {
|
|
8451
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8452
|
-
}
|
|
8453
|
-
function mergeSettings(parts) {
|
|
8454
|
-
const merged = {};
|
|
8455
|
-
let any = false;
|
|
8456
|
-
for (const part of parts) {
|
|
8457
|
-
if (part === void 0) {
|
|
8458
|
-
continue;
|
|
8459
|
-
}
|
|
8460
|
-
const parsed = JSON.parse(part);
|
|
8461
|
-
if (!isRecord15(parsed)) {
|
|
8462
|
-
throw new Error("a launch's settings part is not a JSON object");
|
|
8463
|
-
}
|
|
8464
|
-
for (const [key, value] of Object.entries(parsed)) {
|
|
8465
|
-
if (key in merged) {
|
|
8466
|
-
throw new Error(`two launch settings parts both set "${key}"`);
|
|
8467
|
-
}
|
|
8468
|
-
merged[key] = value;
|
|
8469
|
-
}
|
|
8470
|
-
any = true;
|
|
8471
|
-
}
|
|
8472
|
-
return any ? JSON.stringify(merged) : void 0;
|
|
8473
|
-
}
|
|
8474
|
-
var TERMINATOR2, VALUED_CONVERSATION_FLAGS, CONTINUE_FLAGS;
|
|
8475
|
-
var init_claudeSession = __esm({
|
|
8476
|
-
"src/launcher/claudeSession.ts"() {
|
|
8477
|
-
"use strict";
|
|
8478
|
-
init_resumeContext();
|
|
8479
|
-
TERMINATOR2 = "--";
|
|
8480
|
-
VALUED_CONVERSATION_FLAGS = /* @__PURE__ */ new Set(["--resume", "-r", "--session-id"]);
|
|
8481
|
-
CONTINUE_FLAGS = /* @__PURE__ */ new Set(["--continue", "-c"]);
|
|
8482
|
-
}
|
|
8483
|
-
});
|
|
8484
|
-
|
|
8485
|
-
// src/launcher/diagnostics.ts
|
|
8486
|
-
function diagnosticLines(diagnostics) {
|
|
8487
|
-
const unclassified = [...new Set(diagnostics.filter((diagnostic) => diagnostic.code === "UNCLASSIFIED_ENTRY").map((diagnostic) => diagnostic.subject))];
|
|
8488
|
-
const lines = [];
|
|
8489
|
-
let unclassifiedReported = false;
|
|
8490
|
-
for (const diagnostic of diagnostics) {
|
|
8491
|
-
if (diagnostic.severity === "info") {
|
|
8492
|
-
continue;
|
|
8873
|
+
env[key] = value;
|
|
8493
8874
|
}
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8875
|
+
}
|
|
8876
|
+
if (params.routeByName) {
|
|
8877
|
+
for (const tier of CLAUDE_TIERS) {
|
|
8878
|
+
const ref = params.tierModels?.[tier];
|
|
8879
|
+
if (ref !== void 0) {
|
|
8880
|
+
env[`ANTHROPIC_DEFAULT_${tier.toUpperCase()}_MODEL`] = ref;
|
|
8500
8881
|
}
|
|
8501
|
-
continue;
|
|
8502
8882
|
}
|
|
8503
|
-
lines.push({ severity: diagnostic.severity, text: `agent-shim: ${diagnostic.code}: ${diagnostic.message}` });
|
|
8504
8883
|
}
|
|
8505
|
-
|
|
8506
|
-
|
|
8507
|
-
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
log.warn(line.text);
|
|
8884
|
+
if (params.provider !== void 0) {
|
|
8885
|
+
env.ANTHROPIC_AUTH_TOKEN = params.remoteControl ? void 0 : PROVIDER_SESSION_PLACEHOLDER;
|
|
8886
|
+
env.ANTHROPIC_API_KEY = void 0;
|
|
8887
|
+
env.CLAUDE_CODE_OAUTH_TOKEN = void 0;
|
|
8888
|
+
} else if (params.identityCredential !== void 0) {
|
|
8889
|
+
for (const [variable, value] of Object.entries(credentialVariables(params.identityCredential.target, params.identityCredential.token))) {
|
|
8890
|
+
env[variable] = value;
|
|
8513
8891
|
}
|
|
8514
8892
|
}
|
|
8515
|
-
|
|
8516
|
-
|
|
8517
|
-
|
|
8518
|
-
|
|
8519
|
-
|
|
8520
|
-
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
}
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
}
|
|
8530
|
-
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8537
|
-
}
|
|
8538
|
-
log.info(`agent-shim: starting in ${describeDelay(hold.delayMs)}`);
|
|
8539
|
-
port.sleep(hold.delayMs);
|
|
8540
|
-
return "go";
|
|
8541
|
-
}
|
|
8542
|
-
var LAUNCH_CANCELLED_EXIT, MS_PER_SECOND7;
|
|
8543
|
-
var init_hold = __esm({
|
|
8544
|
-
"src/launcher/hold.ts"() {
|
|
8545
|
-
"use strict";
|
|
8546
|
-
LAUNCH_CANCELLED_EXIT = 130;
|
|
8547
|
-
MS_PER_SECOND7 = 1e3;
|
|
8893
|
+
if (params.frontdoor !== void 0) {
|
|
8894
|
+
env.ANTHROPIC_CUSTOM_HEADERS = mergeAnthropicCustomHeaders(
|
|
8895
|
+
[
|
|
8896
|
+
...parentCustomHeaders === void 0 ? [] : [parentCustomHeaders],
|
|
8897
|
+
...providerCustomHeaders === void 0 ? [] : [providerCustomHeaders]
|
|
8898
|
+
],
|
|
8899
|
+
[
|
|
8900
|
+
...params.resolvedIdentityName === void 0 ? [] : [{ name: IDENTITY_HEADER, value: params.resolvedIdentityName }],
|
|
8901
|
+
{ name: SESSION_HEADER, value: params.sessionId },
|
|
8902
|
+
{ name: AUTH_HEADER, value: params.frontdoor.sessionToken },
|
|
8903
|
+
...params.provider === void 0 ? [] : [{ name: PROVIDER_HEADER, value: params.provider.name }],
|
|
8904
|
+
...params.routeByName ? [{ name: ROUTE_BY_NAME_HEADER, value: "1" }] : [],
|
|
8905
|
+
...params.headroom === void 0 ? [] : [
|
|
8906
|
+
{ name: HEADROOM_FLAG_HEADER, value: "1" },
|
|
8907
|
+
{ name: PROJECT_ID_HEADER, value: params.headroom.projectId }
|
|
8908
|
+
]
|
|
8909
|
+
]
|
|
8910
|
+
);
|
|
8911
|
+
env.NODE_EXTRA_CA_CERTS = params.frontdoor.trustBundlePath;
|
|
8912
|
+
env.HTTPS_PROXY = connectProxyUrl(params.frontdoor.connectPort, params.frontdoor.sessionToken);
|
|
8913
|
+
env.NO_PROXY = withLoopbackHosts(env.NO_PROXY);
|
|
8914
|
+
env.no_proxy = withLoopbackHosts(env.no_proxy);
|
|
8548
8915
|
}
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
// src/usage/candidateText.ts
|
|
8552
|
-
function candidateHeading(candidate) {
|
|
8553
|
-
const score = candidate.score === void 0 ? "" : ` score ${candidate.score.toFixed(2)}${candidate.scoreWindow === "fiveHour" ? " by 5h reset" : " by 7d reset"}`;
|
|
8554
|
-
const dry = candidate.feasible ? "" : " (5h would run dry)";
|
|
8555
|
-
return `[${candidate.class}${score}]${dry}`;
|
|
8916
|
+
return env;
|
|
8556
8917
|
}
|
|
8557
|
-
var
|
|
8558
|
-
|
|
8918
|
+
var LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
|
|
8919
|
+
var init_flags = __esm({
|
|
8920
|
+
"src/launcher/flags.ts"() {
|
|
8559
8921
|
"use strict";
|
|
8922
|
+
init_envBool();
|
|
8923
|
+
init_cliError();
|
|
8924
|
+
init_conditions();
|
|
8925
|
+
init_schema();
|
|
8926
|
+
init_credential();
|
|
8927
|
+
init_headers();
|
|
8928
|
+
init_capability();
|
|
8929
|
+
init_route();
|
|
8930
|
+
LOOPBACK_HOSTS = ["127.0.0.1", "localhost", "::1"];
|
|
8931
|
+
PROVIDER_SESSION_PLACEHOLDER = "agent-shim-provider-session";
|
|
8560
8932
|
}
|
|
8561
8933
|
});
|
|
8562
8934
|
|
|
8563
|
-
// src/launcher/
|
|
8564
|
-
function
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
return { detail: `moved off ${pool.movedOff.identity}: ${pool.movedOff.reason}`, ...reason === void 0 ? {} : { notes: [reason] } };
|
|
8935
|
+
// src/launcher/extraFlags.ts
|
|
8936
|
+
function splitExtraFlags(value) {
|
|
8937
|
+
if (value === void 0) {
|
|
8938
|
+
return [];
|
|
8568
8939
|
}
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
function rankingNotes(ranking, picked) {
|
|
8572
|
-
return ranking.flatMap((candidate, index) => [
|
|
8573
|
-
`${String(index + 1)}. ${candidate.identity} ${candidateHeading(candidate)}${candidate.identity === picked ? " (picked)" : ""}`,
|
|
8574
|
-
` ${candidate.reasons.join("; ")}`
|
|
8575
|
-
]);
|
|
8576
|
-
}
|
|
8577
|
-
function decisionRows(facts) {
|
|
8578
|
-
return [
|
|
8579
|
-
{ label: "identity", value: facts.identity ?? "(none)", detail: facts.identitySource },
|
|
8580
|
-
...facts.pool === void 0 ? [] : [
|
|
8581
|
-
{
|
|
8582
|
-
label: "pool",
|
|
8583
|
-
value: facts.pool.name,
|
|
8584
|
-
...poolDetail(facts.pool),
|
|
8585
|
-
...facts.ranking === void 0 ? {} : { notes: rankingNotes(facts.ranking, facts.identity) }
|
|
8586
|
-
}
|
|
8587
|
-
],
|
|
8588
|
-
...facts.profile === void 0 ? [] : [{ label: "profile", value: facts.profile.name, detail: facts.profile.source }],
|
|
8589
|
-
...facts.provider === void 0 ? [] : [{ label: "provider", value: facts.provider.name, detail: `credential ${facts.provider.credential}` }],
|
|
8590
|
-
...facts.identityCredential === void 0 ? [] : [{ label: "credential", value: facts.identityCredential, detail: "the identity's own" }]
|
|
8591
|
-
];
|
|
8592
|
-
}
|
|
8593
|
-
function pinnedVersionRow(version, source) {
|
|
8594
|
-
return { label: "claude", value: version, detail: `pinned by ${source}` };
|
|
8595
|
-
}
|
|
8596
|
-
function routingRows(facts) {
|
|
8597
|
-
if (facts.frontDoor === void 0) {
|
|
8940
|
+
const trimmed = value.trim();
|
|
8941
|
+
if (trimmed === "") {
|
|
8598
8942
|
return [];
|
|
8599
8943
|
}
|
|
8600
|
-
return
|
|
8601
|
-
{
|
|
8602
|
-
label: "routing",
|
|
8603
|
-
value: `front door 127.0.0.1:${String(facts.frontDoor.port)}`,
|
|
8604
|
-
...facts.provider ? {} : { detail: `OAuth via CONNECT 127.0.0.1:${String(facts.frontDoor.connectPort)}` }
|
|
8605
|
-
},
|
|
8606
|
-
...facts.headroom === void 0 ? [] : [{ label: "headroom", value: "on", detail: `project ${facts.headroom.projectId}` }]
|
|
8607
|
-
];
|
|
8608
|
-
}
|
|
8609
|
-
function farmRow(links, builtDirectories, adopted) {
|
|
8610
|
-
const counted = (count, singular, plural) => `${String(count)} ${count === 1 ? singular : plural}`;
|
|
8611
|
-
const parts = [counted(links, "link", "links"), counted(builtDirectories, "built directory", "built directories"), ...adopted === 0 ? [] : [`${String(adopted)} adopted`]];
|
|
8612
|
-
return { label: "farm", value: "resynced", detail: parts.join(", ") };
|
|
8613
|
-
}
|
|
8614
|
-
function noteRow(text) {
|
|
8615
|
-
return { label: "note", value: text };
|
|
8944
|
+
return trimmed.split(/\s+/);
|
|
8616
8945
|
}
|
|
8617
|
-
var
|
|
8618
|
-
"src/launcher/
|
|
8946
|
+
var init_extraFlags = __esm({
|
|
8947
|
+
"src/launcher/extraFlags.ts"() {
|
|
8619
8948
|
"use strict";
|
|
8620
|
-
init_candidateText();
|
|
8621
8949
|
}
|
|
8622
8950
|
});
|
|
8623
8951
|
|
|
8624
|
-
// src/
|
|
8625
|
-
|
|
8626
|
-
|
|
8952
|
+
// src/usage/resumeContext.ts
|
|
8953
|
+
import path38 from "node:path";
|
|
8954
|
+
function projectDirNameOf(cwd) {
|
|
8955
|
+
return cwd.replace(/[^A-Za-z0-9]/g, "-");
|
|
8627
8956
|
}
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
meta: "meta",
|
|
8644
|
-
mistral: "mistral"
|
|
8645
|
-
});
|
|
8646
|
-
VENDOR_BY_TOKEN = Object.freeze({
|
|
8647
|
-
claude: "anthropic",
|
|
8648
|
-
gemini: "google",
|
|
8649
|
-
antigravity: "google",
|
|
8650
|
-
gpt: "openai",
|
|
8651
|
-
glm: "zai",
|
|
8652
|
-
minimax: "minimax",
|
|
8653
|
-
qwen: "qwen",
|
|
8654
|
-
deepseek: "deepseek",
|
|
8655
|
-
kimi: "moonshot",
|
|
8656
|
-
llama: "meta",
|
|
8657
|
-
mistral: "mistral",
|
|
8658
|
-
mixtral: "mistral"
|
|
8659
|
-
});
|
|
8957
|
+
function resumeTargetOf(passthrough) {
|
|
8958
|
+
const end = passthrough.indexOf("--");
|
|
8959
|
+
const tokens = end === -1 ? passthrough : passthrough.slice(0, end);
|
|
8960
|
+
for (const [index, token] of tokens.entries()) {
|
|
8961
|
+
if (token === "--continue" || token === "-c") {
|
|
8962
|
+
return { kind: "latest" };
|
|
8963
|
+
}
|
|
8964
|
+
if (token === "--resume" || token === "-r") {
|
|
8965
|
+
const next = tokens[index + 1];
|
|
8966
|
+
return next === void 0 || next.startsWith("-") ? void 0 : { kind: "id", id: next };
|
|
8967
|
+
}
|
|
8968
|
+
if (token.startsWith("--resume=")) {
|
|
8969
|
+
const id = token.slice("--resume=".length);
|
|
8970
|
+
return id === "" ? void 0 : { kind: "id", id };
|
|
8971
|
+
}
|
|
8660
8972
|
}
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
"
|
|
8666
|
-
|
|
8973
|
+
return void 0;
|
|
8974
|
+
}
|
|
8975
|
+
function countOf(usage, key) {
|
|
8976
|
+
const value = key in usage ? Reflect.get(usage, key) : void 0;
|
|
8977
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
8978
|
+
}
|
|
8979
|
+
function contextTokensOfTranscript(text) {
|
|
8980
|
+
const lines = text.split("\n");
|
|
8981
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
8982
|
+
const line = lines[index];
|
|
8983
|
+
if (line === void 0 || line === "") {
|
|
8984
|
+
continue;
|
|
8985
|
+
}
|
|
8986
|
+
let parsed;
|
|
8987
|
+
try {
|
|
8988
|
+
parsed = JSON.parse(line);
|
|
8989
|
+
} catch {
|
|
8990
|
+
continue;
|
|
8991
|
+
}
|
|
8992
|
+
if (typeof parsed !== "object" || parsed === null || !("type" in parsed) || parsed.type !== "assistant" || !("message" in parsed)) {
|
|
8993
|
+
continue;
|
|
8994
|
+
}
|
|
8995
|
+
const { message } = parsed;
|
|
8996
|
+
if (typeof message !== "object" || message === null || !("usage" in message) || typeof message.usage !== "object" || message.usage === null) {
|
|
8997
|
+
continue;
|
|
8998
|
+
}
|
|
8999
|
+
const { usage } = message;
|
|
9000
|
+
return countOf(usage, "input_tokens") + countOf(usage, "cache_read_input_tokens") + countOf(usage, "cache_creation_input_tokens");
|
|
8667
9001
|
}
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
9002
|
+
return void 0;
|
|
9003
|
+
}
|
|
9004
|
+
function newestTranscript(fs13, projectDir) {
|
|
9005
|
+
let newest;
|
|
9006
|
+
let newestMs = -Infinity;
|
|
9007
|
+
for (const name of fs13.readdir(projectDir)) {
|
|
9008
|
+
if (!name.endsWith(".jsonl")) {
|
|
9009
|
+
continue;
|
|
9010
|
+
}
|
|
9011
|
+
const candidate = path38.join(projectDir, name);
|
|
9012
|
+
const stat = fs13.lstat(candidate);
|
|
9013
|
+
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
9014
|
+
newestMs = stat.mtimeMs;
|
|
9015
|
+
newest = candidate;
|
|
9016
|
+
}
|
|
8674
9017
|
}
|
|
8675
|
-
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
"use strict";
|
|
8682
|
-
init_cloudUpstream();
|
|
8683
|
-
SECONDS_PER_HOUR = 3600;
|
|
8684
|
-
HOURS_PER_FIVE_HOUR_WINDOW = 5;
|
|
8685
|
-
DAYS_PER_WEEK = 7;
|
|
8686
|
-
HOURS_PER_DAY4 = 24;
|
|
8687
|
-
FIVE_HOUR_PERIOD_SECONDS = HOURS_PER_FIVE_HOUR_WINDOW * SECONDS_PER_HOUR;
|
|
8688
|
-
WEEK_PERIOD_SECONDS = DAYS_PER_WEEK * HOURS_PER_DAY4 * SECONDS_PER_HOUR;
|
|
9018
|
+
return newest;
|
|
9019
|
+
}
|
|
9020
|
+
function resumedContextTokens(fs13, params) {
|
|
9021
|
+
const target = resumeTargetOf(params.passthrough);
|
|
9022
|
+
if (target === void 0) {
|
|
9023
|
+
return void 0;
|
|
8689
9024
|
}
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
|
|
9025
|
+
const projectDir = path38.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
9026
|
+
const file = target.kind === "id" ? path38.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs13, projectDir);
|
|
9027
|
+
const text = file === void 0 ? void 0 : fs13.readFileUtf8(file);
|
|
9028
|
+
return text === void 0 ? void 0 : contextTokensOfTranscript(text);
|
|
9029
|
+
}
|
|
9030
|
+
var init_resumeContext = __esm({
|
|
9031
|
+
"src/usage/resumeContext.ts"() {
|
|
8695
9032
|
"use strict";
|
|
8696
9033
|
}
|
|
8697
9034
|
});
|
|
8698
9035
|
|
|
8699
|
-
// src/
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
|
|
8706
|
-
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
type: z29.literal("tool_result"),
|
|
8721
|
-
tool_use_id: z29.string().min(1),
|
|
8722
|
-
content: z29.union([z29.string(), z29.array(ToolResultContentBlockSchema)]).optional()
|
|
8723
|
-
});
|
|
8724
|
-
OtherBlockSchema = z29.looseObject({ type: z29.string() });
|
|
8725
|
-
ContentBlockSchema = z29.union([TextBlockSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultBlockSchema, OtherBlockSchema]);
|
|
8726
|
-
MessageSchema = z29.looseObject({
|
|
8727
|
-
role: z29.enum(["user", "assistant", "system"]),
|
|
8728
|
-
content: z29.union([z29.string(), z29.array(ContentBlockSchema)])
|
|
8729
|
-
});
|
|
8730
|
-
ToolSchema = z29.looseObject({
|
|
8731
|
-
name: z29.string().min(1),
|
|
8732
|
-
description: z29.string().optional(),
|
|
8733
|
-
input_schema: z29.record(z29.string(), z29.unknown()).optional()
|
|
8734
|
-
});
|
|
8735
|
-
ToolChoiceSchema = z29.union([
|
|
8736
|
-
z29.looseObject({ type: z29.enum(["auto", "none", "any"]) }),
|
|
8737
|
-
z29.looseObject({ type: z29.literal("tool"), name: z29.string().min(1) })
|
|
8738
|
-
]);
|
|
8739
|
-
SystemSchema = z29.union([z29.string(), z29.array(z29.union([TextBlockSchema, OtherBlockSchema]))]);
|
|
8740
|
-
MessagesRequestSchema = z29.looseObject({
|
|
8741
|
-
model: z29.string().optional(),
|
|
8742
|
-
system: SystemSchema.optional(),
|
|
8743
|
-
messages: z29.array(MessageSchema),
|
|
8744
|
-
tools: z29.array(ToolSchema).optional(),
|
|
8745
|
-
tool_choice: ToolChoiceSchema.optional(),
|
|
8746
|
-
stream: z29.boolean().optional(),
|
|
8747
|
-
/** `user_id` is stable for one Claude Code session and differs between sessions, which is what makes it the right key for both the backend's prompt cache and its session header. */
|
|
8748
|
-
metadata: z29.looseObject({ user_id: z29.string().optional() }).optional(),
|
|
8749
|
-
/** Claude Code's effort setting. Any string is accepted; the translator honours only the levels the backend understands. */
|
|
8750
|
-
output_config: z29.looseObject({ effort: z29.string().optional() }).optional()
|
|
8751
|
-
});
|
|
8752
|
-
CountTokensRequestSchema = z29.looseObject({
|
|
8753
|
-
system: z29.unknown().optional(),
|
|
8754
|
-
messages: z29.unknown().optional(),
|
|
8755
|
-
tools: z29.unknown().optional()
|
|
8756
|
-
});
|
|
9036
|
+
// src/launcher/claudeSession.ts
|
|
9037
|
+
function isFlag(token) {
|
|
9038
|
+
return token?.startsWith("-") === true;
|
|
9039
|
+
}
|
|
9040
|
+
function withConversation(passthrough, conversation, id) {
|
|
9041
|
+
const end = passthrough.indexOf(TERMINATOR2);
|
|
9042
|
+
const head = end === -1 ? passthrough : passthrough.slice(0, end);
|
|
9043
|
+
const tail = end === -1 ? [] : passthrough.slice(end);
|
|
9044
|
+
const kept = [];
|
|
9045
|
+
for (let index = 0; index < head.length; index += 1) {
|
|
9046
|
+
const token = head[index];
|
|
9047
|
+
if (token === void 0 || CONTINUE_FLAGS.has(token) || token.startsWith("--resume=") || token.startsWith("--session-id=")) {
|
|
9048
|
+
continue;
|
|
9049
|
+
}
|
|
9050
|
+
if (VALUED_CONVERSATION_FLAGS.has(token)) {
|
|
9051
|
+
if (!isFlag(head[index + 1]) && head[index + 1] !== void 0) {
|
|
9052
|
+
index += 1;
|
|
9053
|
+
}
|
|
9054
|
+
continue;
|
|
9055
|
+
}
|
|
9056
|
+
kept.push(token);
|
|
8757
9057
|
}
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
// src/antigravity/translate.ts
|
|
8761
|
-
function candidatesOf(target) {
|
|
8762
|
-
return typeof target === "string" ? [target] : target;
|
|
9058
|
+
return [...kept, conversation === "start" ? "--session-id" : "--resume", id, ...tail];
|
|
8763
9059
|
}
|
|
8764
|
-
function
|
|
8765
|
-
|
|
9060
|
+
function hasSettingsArgument(passthrough) {
|
|
9061
|
+
const end = passthrough.indexOf(TERMINATOR2);
|
|
9062
|
+
return (end === -1 ? passthrough : passthrough.slice(0, end)).some((token) => token === "--settings" || token.startsWith("--settings="));
|
|
8766
9063
|
}
|
|
8767
|
-
function
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
for (const [key, target] of Object.entries(overrides)) {
|
|
8771
|
-
if (!isAntigravityTier(key)) {
|
|
8772
|
-
aliases.set(key.toLowerCase(), candidatesOf(target));
|
|
8773
|
-
}
|
|
9064
|
+
function withSupervision(passthrough, supervised) {
|
|
9065
|
+
if (supervised.conversation === "as-given") {
|
|
9066
|
+
return passthrough;
|
|
8774
9067
|
}
|
|
8775
|
-
const
|
|
8776
|
-
|
|
8777
|
-
return
|
|
8778
|
-
};
|
|
8779
|
-
if (!aliases.has(AUTO_ALIAS)) {
|
|
8780
|
-
aliases.set(AUTO_ALIAS, [...new Set(CLAUDE_TIERS.flatMap(tierModel))]);
|
|
9068
|
+
const conversed = withConversation(passthrough, supervised.conversation, supervised.sessionId);
|
|
9069
|
+
if (supervised.model === void 0) {
|
|
9070
|
+
return conversed;
|
|
8781
9071
|
}
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
projectId: config?.cloud?.projectId,
|
|
8792
|
-
location: config?.cloud?.location
|
|
8793
|
-
},
|
|
8794
|
-
local: {
|
|
8795
|
-
command: config?.local?.command,
|
|
8796
|
-
socketPath: config?.local?.socketPath
|
|
9072
|
+
const end = conversed.indexOf(TERMINATOR2);
|
|
9073
|
+
const head = end === -1 ? conversed : conversed.slice(0, end);
|
|
9074
|
+
const tail = end === -1 ? [] : conversed.slice(end);
|
|
9075
|
+
const kept = [];
|
|
9076
|
+
for (let index = 0; index < head.length; index += 1) {
|
|
9077
|
+
const token = head[index];
|
|
9078
|
+
if (token === "--model") {
|
|
9079
|
+
index += 1;
|
|
9080
|
+
continue;
|
|
8797
9081
|
}
|
|
8798
|
-
|
|
9082
|
+
if (token !== void 0 && !token.startsWith("--model=")) {
|
|
9083
|
+
kept.push(token);
|
|
9084
|
+
}
|
|
9085
|
+
}
|
|
9086
|
+
return [...kept, "--model", supervised.model, ...tail];
|
|
8799
9087
|
}
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
"use strict";
|
|
8804
|
-
init_identity2();
|
|
8805
|
-
init_engine();
|
|
8806
|
-
init_quota();
|
|
8807
|
-
init_signatures();
|
|
8808
|
-
init_schema();
|
|
8809
|
-
init_anthropic();
|
|
8810
|
-
AUTO_ALIAS = "auto";
|
|
9088
|
+
function withLauncherSettings(passthrough, settings) {
|
|
9089
|
+
if (settings === void 0) {
|
|
9090
|
+
return passthrough;
|
|
8811
9091
|
}
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
// src/codex/translate.ts
|
|
8815
|
-
function resolveCodexConfig(config) {
|
|
8816
|
-
const overrides = config?.models;
|
|
8817
|
-
return {
|
|
8818
|
-
defaultModel: config?.defaultModel ?? CODEX_DEFAULT_MODEL,
|
|
8819
|
-
models: {
|
|
8820
|
-
fable: overrides?.fable ?? CODEX_DEFAULT_TIER_MODELS.fable,
|
|
8821
|
-
opus: overrides?.opus ?? CODEX_DEFAULT_TIER_MODELS.opus,
|
|
8822
|
-
sonnet: overrides?.sonnet ?? CODEX_DEFAULT_TIER_MODELS.sonnet,
|
|
8823
|
-
haiku: overrides?.haiku ?? CODEX_DEFAULT_TIER_MODELS.haiku
|
|
8824
|
-
},
|
|
8825
|
-
effort: config?.effort ?? CODEX_DEFAULT_EFFORT,
|
|
8826
|
-
login: config?.login ?? CODEX_DEFAULT_LOGIN
|
|
8827
|
-
};
|
|
9092
|
+
const end = passthrough.indexOf(TERMINATOR2);
|
|
9093
|
+
return end === -1 ? [...passthrough, "--settings", settings] : [...passthrough.slice(0, end), "--settings", settings, ...passthrough.slice(end)];
|
|
8828
9094
|
}
|
|
8829
|
-
|
|
8830
|
-
"
|
|
9095
|
+
function isRecord15(value) {
|
|
9096
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9097
|
+
}
|
|
9098
|
+
function mergeSettings(parts) {
|
|
9099
|
+
const merged = {};
|
|
9100
|
+
let any = false;
|
|
9101
|
+
for (const part of parts) {
|
|
9102
|
+
if (part === void 0) {
|
|
9103
|
+
continue;
|
|
9104
|
+
}
|
|
9105
|
+
const parsed = JSON.parse(part);
|
|
9106
|
+
if (!isRecord15(parsed)) {
|
|
9107
|
+
throw new Error("a launch's settings part is not a JSON object");
|
|
9108
|
+
}
|
|
9109
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
9110
|
+
if (key in merged) {
|
|
9111
|
+
throw new Error(`two launch settings parts both set "${key}"`);
|
|
9112
|
+
}
|
|
9113
|
+
merged[key] = value;
|
|
9114
|
+
}
|
|
9115
|
+
any = true;
|
|
9116
|
+
}
|
|
9117
|
+
return any ? JSON.stringify(merged) : void 0;
|
|
9118
|
+
}
|
|
9119
|
+
var TERMINATOR2, VALUED_CONVERSATION_FLAGS, CONTINUE_FLAGS;
|
|
9120
|
+
var init_claudeSession = __esm({
|
|
9121
|
+
"src/launcher/claudeSession.ts"() {
|
|
8831
9122
|
"use strict";
|
|
8832
|
-
|
|
8833
|
-
|
|
9123
|
+
init_resumeContext();
|
|
9124
|
+
TERMINATOR2 = "--";
|
|
9125
|
+
VALUED_CONVERSATION_FLAGS = /* @__PURE__ */ new Set(["--resume", "-r", "--session-id"]);
|
|
9126
|
+
CONTINUE_FLAGS = /* @__PURE__ */ new Set(["--continue", "-c"]);
|
|
8834
9127
|
}
|
|
8835
9128
|
});
|
|
8836
9129
|
|
|
8837
|
-
// src/
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
9130
|
+
// src/launcher/diagnostics.ts
|
|
9131
|
+
function diagnosticLines(diagnostics) {
|
|
9132
|
+
const unclassified = [...new Set(diagnostics.filter((diagnostic) => diagnostic.code === "UNCLASSIFIED_ENTRY").map((diagnostic) => diagnostic.subject))];
|
|
9133
|
+
const lines = [];
|
|
9134
|
+
let unclassifiedReported = false;
|
|
9135
|
+
for (const diagnostic of diagnostics) {
|
|
9136
|
+
if (diagnostic.severity === "info") {
|
|
9137
|
+
continue;
|
|
9138
|
+
}
|
|
9139
|
+
if (diagnostic.code === "UNCLASSIFIED_ENTRY") {
|
|
9140
|
+
if (!unclassifiedReported) {
|
|
9141
|
+
unclassifiedReported = true;
|
|
9142
|
+
const names = unclassified.filter((name) => name !== void 0);
|
|
9143
|
+
lines.push({ severity: diagnostic.severity, text: `agent-shim: ${diagnostic.code}: ${unclassifiedEntrySummary(names)}
|
|
9144
|
+
${unclassifiedEntryFix(names)}.` });
|
|
9145
|
+
}
|
|
9146
|
+
continue;
|
|
9147
|
+
}
|
|
9148
|
+
lines.push({ severity: diagnostic.severity, text: `agent-shim: ${diagnostic.code}: ${diagnostic.message}` });
|
|
9149
|
+
}
|
|
9150
|
+
return lines;
|
|
8843
9151
|
}
|
|
8844
|
-
function
|
|
8845
|
-
|
|
8846
|
-
|
|
9152
|
+
function printDiagnosticLines(log, lines, options) {
|
|
9153
|
+
for (const line of lines) {
|
|
9154
|
+
if (line.severity === "error" && !options.errorsAsWarnings) {
|
|
9155
|
+
log.error(line.text);
|
|
9156
|
+
} else {
|
|
9157
|
+
log.warn(line.text);
|
|
9158
|
+
}
|
|
8847
9159
|
}
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
9160
|
+
}
|
|
9161
|
+
function reportDiagnostics(log, diagnostics, options) {
|
|
9162
|
+
printDiagnosticLines(log, diagnosticLines(diagnostics), options);
|
|
9163
|
+
}
|
|
9164
|
+
var init_diagnostics = __esm({
|
|
9165
|
+
"src/launcher/diagnostics.ts"() {
|
|
9166
|
+
"use strict";
|
|
9167
|
+
init_decide();
|
|
8853
9168
|
}
|
|
9169
|
+
});
|
|
9170
|
+
|
|
9171
|
+
// src/launcher/hold.ts
|
|
9172
|
+
function describeDelay(ms) {
|
|
9173
|
+
return ms % MS_PER_SECOND8 === 0 ? `${String(ms / MS_PER_SECOND8)}s` : `${String(ms)}ms`;
|
|
8854
9174
|
}
|
|
8855
|
-
function
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
9175
|
+
function holdBeforeLaunch(hold, port, log) {
|
|
9176
|
+
if (port === void 0 || !port.attended() || !hold.pause && hold.delayMs <= 0) {
|
|
9177
|
+
return "go";
|
|
9178
|
+
}
|
|
9179
|
+
if (hold.pause) {
|
|
9180
|
+
log.info("agent-shim: paused before launch; press any key to start, or Ctrl-C to cancel");
|
|
9181
|
+
return port.waitForKey() === "interrupt" ? "cancelled" : "go";
|
|
9182
|
+
}
|
|
9183
|
+
log.info(`agent-shim: starting in ${describeDelay(hold.delayMs)}`);
|
|
9184
|
+
port.sleep(hold.delayMs);
|
|
9185
|
+
return "go";
|
|
8859
9186
|
}
|
|
8860
|
-
var
|
|
8861
|
-
var
|
|
8862
|
-
"src/
|
|
9187
|
+
var LAUNCH_CANCELLED_EXIT, MS_PER_SECOND8;
|
|
9188
|
+
var init_hold = __esm({
|
|
9189
|
+
"src/launcher/hold.ts"() {
|
|
8863
9190
|
"use strict";
|
|
8864
|
-
|
|
9191
|
+
LAUNCH_CANCELLED_EXIT = 130;
|
|
8865
9192
|
MS_PER_SECOND8 = 1e3;
|
|
8866
|
-
SECONDS_PER_HOUR2 = 3600;
|
|
8867
|
-
HOURS_PER_DAY5 = 24;
|
|
8868
|
-
MS_PER_HOUR5 = SECONDS_PER_HOUR2 * MS_PER_SECOND8;
|
|
8869
|
-
HOURS_BETWEEN_RETRIES = 1;
|
|
8870
|
-
CATALOGUE_MAX_AGE_MS = HOURS_PER_DAY5 * MS_PER_HOUR5;
|
|
8871
|
-
CATALOGUE_RETRY_MS = HOURS_BETWEEN_RETRIES * MS_PER_HOUR5;
|
|
8872
|
-
CATALOGUE_REQUEST_SECONDS = 10;
|
|
8873
|
-
CATALOGUE_REQUEST_TIMEOUT_MS = CATALOGUE_REQUEST_SECONDS * MS_PER_SECOND8;
|
|
8874
|
-
CATALOGUE_REFRESH_TIMEOUT_MS = DEFAULT_CANDIDATE_URLS * CATALOGUE_REQUEST_TIMEOUT_MS;
|
|
8875
|
-
CatalogueModelSchema = z30.strictObject({ id: z30.string().min(1), name: z30.string().min(1).optional() });
|
|
8876
|
-
CatalogueCacheSchema = z30.strictObject({ fetchedAt: z30.number(), url: z30.string().min(1), models: z30.array(CatalogueModelSchema) });
|
|
8877
9193
|
}
|
|
8878
9194
|
});
|
|
8879
9195
|
|
|
8880
|
-
// src/
|
|
8881
|
-
function
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
return model.toLowerCase().endsWith(CONTEXT_MARKER_1M) ? `${description}; 1M context` : description;
|
|
8886
|
-
}
|
|
8887
|
-
function joined(parts) {
|
|
8888
|
-
const last = parts[parts.length - 1];
|
|
8889
|
-
return last === void 0 || parts.length === 1 ? last ?? "" : `${parts.slice(0, -1).join(", ")} and ${last}`;
|
|
9196
|
+
// src/usage/candidateText.ts
|
|
9197
|
+
function candidateHeading(candidate) {
|
|
9198
|
+
const score = candidate.score === void 0 ? "" : ` score ${candidate.score.toFixed(2)}${candidate.scoreWindow === "fiveHour" ? " by 5h reset" : " by 7d reset"}`;
|
|
9199
|
+
const dry = candidate.feasible ? "" : " (5h would run dry)";
|
|
9200
|
+
return `[${candidate.class}${score}]${dry}`;
|
|
8890
9201
|
}
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
throw new Error(`model ${model} is reached by no tier`);
|
|
9202
|
+
var init_candidateText = __esm({
|
|
9203
|
+
"src/usage/candidateText.ts"() {
|
|
9204
|
+
"use strict";
|
|
8895
9205
|
}
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
8903
|
-
const reachesByModel = /* @__PURE__ */ new Map();
|
|
8904
|
-
for (const [tier, candidates] of table) {
|
|
8905
|
-
candidates.forEach((model, index) => {
|
|
8906
|
-
const reaches = reachesByModel.get(model) ?? [];
|
|
8907
|
-
if (!reaches.some((reach) => reach.tier === tier)) {
|
|
8908
|
-
reaches.push({ tier, standing: index === 0 ? "first" : "fallback" });
|
|
8909
|
-
}
|
|
8910
|
-
reachesByModel.set(model, reaches);
|
|
8911
|
-
});
|
|
9206
|
+
});
|
|
9207
|
+
|
|
9208
|
+
// src/launcher/launchReport.ts
|
|
9209
|
+
function poolDetail(pool) {
|
|
9210
|
+
const [reason] = pool.reasons;
|
|
9211
|
+
if (pool.movedOff !== void 0) {
|
|
9212
|
+
return { detail: `moved off ${pool.movedOff.identity}: ${pool.movedOff.reason}`, ...reason === void 0 ? {} : { notes: [reason] } };
|
|
8912
9213
|
}
|
|
8913
|
-
return
|
|
8914
|
-
}
|
|
8915
|
-
function antigravityRows(provider) {
|
|
8916
|
-
const config = resolveAntigravityConfig(provider.antigravity);
|
|
8917
|
-
const tiers = rowsOfTable(CLAUDE_TIERS.map((tier) => [tier, config.models[tier]]));
|
|
8918
|
-
const behavesAsOf = new Map(tiers.map((row) => [row.model, row.behavesAs]));
|
|
8919
|
-
const aliases = [...config.aliases].flatMap(([alias, candidates]) => {
|
|
8920
|
-
const [first] = candidates;
|
|
8921
|
-
const behavesAs = first === void 0 ? void 0 : behavesAsOf.get(first);
|
|
8922
|
-
const description = alias === AUTO_ALIAS ? `Routes each request to a backend model with quota left, best first (${String(candidates.length)} models)` : `Alias for ${candidates.join(", then ")}`;
|
|
8923
|
-
return behavesAs === void 0 ? [] : [{ model: alias, label: labelOf(alias), description, behavesAs }];
|
|
8924
|
-
});
|
|
8925
|
-
return [...aliases.filter((row) => row.model === AUTO_ALIAS), ...tiers, ...aliases.filter((row) => row.model !== AUTO_ALIAS)];
|
|
9214
|
+
return reason === void 0 ? {} : { detail: reason };
|
|
8926
9215
|
}
|
|
8927
|
-
function
|
|
8928
|
-
|
|
8929
|
-
|
|
9216
|
+
function rankingNotes(ranking, picked) {
|
|
9217
|
+
return ranking.flatMap((candidate, index) => [
|
|
9218
|
+
`${String(index + 1)}. ${candidate.identity} ${candidateHeading(candidate)}${candidate.identity === picked ? " (picked)" : ""}`,
|
|
9219
|
+
` ${candidate.reasons.join("; ")}`
|
|
9220
|
+
]);
|
|
8930
9221
|
}
|
|
8931
|
-
function
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
9222
|
+
function decisionRows(facts) {
|
|
9223
|
+
return [
|
|
9224
|
+
{ label: "identity", value: facts.identity ?? "(none)", detail: facts.identitySource },
|
|
9225
|
+
...facts.pool === void 0 ? [] : [
|
|
9226
|
+
{
|
|
9227
|
+
label: "pool",
|
|
9228
|
+
value: facts.pool.name,
|
|
9229
|
+
...poolDetail(facts.pool),
|
|
9230
|
+
...facts.ranking === void 0 ? {} : { notes: rankingNotes(facts.ranking, facts.identity) }
|
|
9231
|
+
}
|
|
9232
|
+
],
|
|
9233
|
+
...facts.profile === void 0 ? [] : [{ label: "profile", value: facts.profile.name, detail: facts.profile.source }],
|
|
9234
|
+
...facts.provider === void 0 ? [] : [{ label: "provider", value: facts.provider.name, detail: `credential ${facts.provider.credential}` }],
|
|
9235
|
+
...facts.identityCredential === void 0 ? [] : [{ label: "credential", value: facts.identityCredential, detail: "the identity's own" }]
|
|
9236
|
+
];
|
|
8938
9237
|
}
|
|
8939
|
-
function
|
|
8940
|
-
return {
|
|
8941
|
-
model: entry.model,
|
|
8942
|
-
label: entry.label ?? labelOf(entry.model),
|
|
8943
|
-
description: entry.description ?? describedAs(entry.model, `Declared by the provider for the ${entry.tier} tier`),
|
|
8944
|
-
behavesAs: TIER_BEHAVES_AS[entry.tier]
|
|
8945
|
-
};
|
|
9238
|
+
function pinnedVersionRow(version, source) {
|
|
9239
|
+
return { label: "claude", value: version, detail: `pinned by ${source}` };
|
|
8946
9240
|
}
|
|
8947
|
-
function
|
|
8948
|
-
if (
|
|
9241
|
+
function routingRows(facts) {
|
|
9242
|
+
if (facts.frontDoor === void 0) {
|
|
8949
9243
|
return [];
|
|
8950
9244
|
}
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
|
|
8959
|
-
const taken = new Set(named.map((row) => labelOf(row.model)));
|
|
8960
|
-
return [...named, ...catalogueRows(provider, catalogue).filter((row) => !taken.has(labelOf(row.model)))];
|
|
8961
|
-
}
|
|
8962
|
-
function routedModelRows(models, providers) {
|
|
8963
|
-
const hidden = new Set(models.hide ?? []);
|
|
8964
|
-
const shown = models.show === void 0 ? void 0 : new Set(models.show);
|
|
8965
|
-
const visible = (model) => shown === void 0 ? !hidden.has(model) : shown.has(model);
|
|
8966
|
-
const tierOf = (model) => {
|
|
8967
|
-
for (const [, provider] of providers) {
|
|
8968
|
-
if (provider.kind !== void 0 && provider.kind !== "http") {
|
|
8969
|
-
continue;
|
|
8970
|
-
}
|
|
8971
|
-
const match = Object.entries(provider.env ?? {}).find(([key, value]) => value === model && key.startsWith("ANTHROPIC_DEFAULT_") && key.endsWith("_MODEL"));
|
|
8972
|
-
if (match !== void 0) {
|
|
8973
|
-
const tier = match[0].replace("ANTHROPIC_DEFAULT_", "").replace("_MODEL", "").toLowerCase();
|
|
8974
|
-
return tier === "fable" || tier === "opus" || tier === "sonnet" || tier === "haiku" ? tier : void 0;
|
|
8975
|
-
}
|
|
8976
|
-
}
|
|
8977
|
-
return void 0;
|
|
8978
|
-
};
|
|
8979
|
-
const virtual = Object.entries(models.virtual ?? {}).flatMap(([name, definition]) => {
|
|
8980
|
-
if (!visible(name)) {
|
|
8981
|
-
return [];
|
|
8982
|
-
}
|
|
8983
|
-
const first = definition.members.find((member) => member.includes("/"));
|
|
8984
|
-
const tier = first === void 0 ? void 0 : tierOf(first.split("/").slice(1).join("/"));
|
|
8985
|
-
const behavesAs = tier === void 0 ? void 0 : TIER_BEHAVES_AS[tier];
|
|
8986
|
-
return behavesAs === void 0 ? [] : [{ model: name, label: name, description: `Virtual (${definition.mode})`, behavesAs }];
|
|
8987
|
-
});
|
|
8988
|
-
const concrete = providers.flatMap(([name, provider]) => providerModelRows(provider).map((row) => ({ ...row, model: `${name}/${row.model}`, label: `${name} / ${row.label}`, description: `${name}: ${row.description}` })));
|
|
8989
|
-
return [...virtual, ...concrete.filter((row) => visible(row.model))];
|
|
9245
|
+
return [
|
|
9246
|
+
{
|
|
9247
|
+
label: "routing",
|
|
9248
|
+
value: `front door 127.0.0.1:${String(facts.frontDoor.port)}`,
|
|
9249
|
+
...facts.provider ? {} : { detail: `OAuth via CONNECT 127.0.0.1:${String(facts.frontDoor.connectPort)}` }
|
|
9250
|
+
},
|
|
9251
|
+
...facts.headroom === void 0 ? [] : [{ label: "headroom", value: "on", detail: `project ${facts.headroom.projectId}` }]
|
|
9252
|
+
];
|
|
8990
9253
|
}
|
|
8991
|
-
function
|
|
8992
|
-
|
|
9254
|
+
function farmRow(links, builtDirectories, adopted) {
|
|
9255
|
+
const counted = (count, singular, plural) => `${String(count)} ${count === 1 ? singular : plural}`;
|
|
9256
|
+
const parts = [counted(links, "link", "links"), counted(builtDirectories, "built directory", "built directories"), ...adopted === 0 ? [] : [`${String(adopted)} adopted`]];
|
|
9257
|
+
return { label: "farm", value: "resynced", detail: parts.join(", ") };
|
|
8993
9258
|
}
|
|
8994
|
-
function
|
|
8995
|
-
return
|
|
9259
|
+
function noteRow(text) {
|
|
9260
|
+
return { label: "note", value: text };
|
|
8996
9261
|
}
|
|
8997
|
-
var
|
|
8998
|
-
|
|
8999
|
-
"src/launcher/modelPicker.ts"() {
|
|
9262
|
+
var init_launchReport = __esm({
|
|
9263
|
+
"src/launcher/launchReport.ts"() {
|
|
9000
9264
|
"use strict";
|
|
9001
|
-
|
|
9002
|
-
init_translate2();
|
|
9003
|
-
init_providerCatalogue();
|
|
9004
|
-
init_schema();
|
|
9005
|
-
init_identity2();
|
|
9006
|
-
TIER_BEHAVES_AS = Object.freeze({
|
|
9007
|
-
fable: "claude-fable-5-1",
|
|
9008
|
-
opus: "claude-opus-5-5",
|
|
9009
|
-
sonnet: "claude-sonnet-5-5",
|
|
9010
|
-
haiku: "claude-haiku-5-5"
|
|
9011
|
-
});
|
|
9012
|
-
TIER_ENV_VARIABLES = Object.freeze({
|
|
9013
|
-
fable: "ANTHROPIC_DEFAULT_FABLE_MODEL",
|
|
9014
|
-
opus: "ANTHROPIC_DEFAULT_OPUS_MODEL",
|
|
9015
|
-
sonnet: "ANTHROPIC_DEFAULT_SONNET_MODEL",
|
|
9016
|
-
haiku: "ANTHROPIC_DEFAULT_HAIKU_MODEL"
|
|
9017
|
-
});
|
|
9265
|
+
init_candidateText();
|
|
9018
9266
|
}
|
|
9019
9267
|
});
|
|
9020
9268
|
|
|
@@ -9219,6 +9467,7 @@ var init_launchHook = __esm({
|
|
|
9219
9467
|
|
|
9220
9468
|
// src/launcher.ts
|
|
9221
9469
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
9470
|
+
import { isDeepStrictEqual } from "node:util";
|
|
9222
9471
|
import path39 from "node:path";
|
|
9223
9472
|
function resolveIdentityCredential(identity, credential, env, port) {
|
|
9224
9473
|
if (port === void 0) {
|
|
@@ -9410,10 +9659,12 @@ function decideLaunch(params, readOnly) {
|
|
|
9410
9659
|
}
|
|
9411
9660
|
const launchCascade = farmContext?.cascade ?? (params.farm === void 0 ? void 0 : params.farm.loadCascade(configProfileDecision.name, cliOverride));
|
|
9412
9661
|
let cascadeLaunch;
|
|
9662
|
+
let cascadeModels;
|
|
9413
9663
|
if (launchCascade !== void 0 && params.farm !== void 0) {
|
|
9414
9664
|
const assembled = assembleCascade(launchCascade);
|
|
9415
9665
|
const flattened = flattenLayers(assembled.layers, { home: params.farm.home });
|
|
9416
9666
|
cascadeLaunch = flattened.launch;
|
|
9667
|
+
cascadeModels = flattened.models;
|
|
9417
9668
|
if (readOnly || farmContext === void 0) {
|
|
9418
9669
|
reportDiagnostics(log, [...assembled.diagnostics, ...flattened.diagnostics], { errorsAsWarnings: readOnly });
|
|
9419
9670
|
}
|
|
@@ -9442,7 +9693,9 @@ function decideLaunch(params, readOnly) {
|
|
|
9442
9693
|
const flags = loginlessProvider === void 0 ? requestedFlags : { ...requestedFlags, remoteControl: false };
|
|
9443
9694
|
const catalogue = selectedProvider === void 0 ? void 0 : parseCatalogueCache(params.fs.readFileUtf8(catalogueCachePath(paths, selectedProvider.name)));
|
|
9444
9695
|
const routesByName = flags.routeByName || selectedProvider !== void 0 && isRouterProvider(selectedProvider.definition);
|
|
9445
|
-
const
|
|
9696
|
+
const globalModels = loadConfigFile(paths.globalConfigFile, GlobalConfigSchema, params.fs.readConfigFile)?.config.models;
|
|
9697
|
+
const models = launchCascade !== void 0 && params.farm !== void 0 ? cascadeModels : globalModels;
|
|
9698
|
+
const pickerSettings = routesByName ? modelPickerSettingsFromRows(routedModelRows(models ?? {}, listProviders(paths).map((entry) => [entry.name, entry.provider])), selectedProvider !== void 0) : selectedProvider === void 0 ? void 0 : modelPickerSettings(selectedProvider.definition, catalogue?.models);
|
|
9446
9699
|
const callerSettings = hasSettingsArgument(parsedArgv.rest);
|
|
9447
9700
|
if (pickerSettings !== void 0 && callerSettings) {
|
|
9448
9701
|
notes.push("--settings was passed, so /model keeps Claude Code's own model names");
|
|
@@ -9480,6 +9733,8 @@ function decideLaunch(params, readOnly) {
|
|
|
9480
9733
|
identityCredential,
|
|
9481
9734
|
pinnedVersion,
|
|
9482
9735
|
flags,
|
|
9736
|
+
models,
|
|
9737
|
+
globalModels,
|
|
9483
9738
|
bin: discovered.path,
|
|
9484
9739
|
args,
|
|
9485
9740
|
decision
|
|
@@ -9546,7 +9801,7 @@ function prepareLaunch(params) {
|
|
|
9546
9801
|
}
|
|
9547
9802
|
const routesByName = resolvedFlags.routeByName || resolvedProvider !== void 0 && isRouterProvider(resolvedProvider.definition);
|
|
9548
9803
|
if (routesByName) {
|
|
9549
|
-
const check = resolveRoutedProviderCredentials({ paths, port: params.fs, env, ...params.credentials === void 0 ? {} : { credentials: params.credentials }, models:
|
|
9804
|
+
const check = resolveRoutedProviderCredentials({ paths, port: params.fs, env, ...params.credentials === void 0 ? {} : { credentials: params.credentials }, models: decided.models, targets: () => targetRefs(paths) });
|
|
9550
9805
|
if (!check.ok) {
|
|
9551
9806
|
log.error(check.message);
|
|
9552
9807
|
proc.exit(check.status);
|
|
@@ -9558,7 +9813,10 @@ function prepareLaunch(params) {
|
|
|
9558
9813
|
log.error("agent-shim: this launch routes through the front-door daemon, but this launcher has no front-door port wired; refusing to launch without it.");
|
|
9559
9814
|
proc.exit(1);
|
|
9560
9815
|
}
|
|
9561
|
-
const
|
|
9816
|
+
const sessionId = params.supervised?.sessionId ?? randomUUID4();
|
|
9817
|
+
const resolvedModels = decided.models ?? (decided.globalModels === void 0 ? void 0 : {});
|
|
9818
|
+
const sessionModels = isDeepStrictEqual(resolvedModels, decided.globalModels) ? void 0 : resolvedModels;
|
|
9819
|
+
const frontDoor = frontDoorEngaged && frontDoorPort !== void 0 ? frontDoorPort.ensure(env.NODE_EXTRA_CA_CERTS, { sessionId, ...sessionModels === void 0 ? {} : { models: sessionModels } }) : void 0;
|
|
9562
9820
|
if (frontDoor?.trustWarning !== void 0) {
|
|
9563
9821
|
log.warn(frontDoor.trustWarning);
|
|
9564
9822
|
}
|
|
@@ -9572,7 +9830,6 @@ function prepareLaunch(params) {
|
|
|
9572
9830
|
}
|
|
9573
9831
|
rows.push(...routingRows({ frontDoor, headroom, provider: resolvedProvider !== void 0 }));
|
|
9574
9832
|
const frontDoorRelease = frontDoor === void 0 ? void 0 : frontDoorPort?.release;
|
|
9575
|
-
const sessionId = params.supervised?.sessionId ?? randomUUID4();
|
|
9576
9833
|
const finalEnv = buildEnv({
|
|
9577
9834
|
baseEnv: env,
|
|
9578
9835
|
configDirEscapeHatch: configDirEscapeHatchApplies,
|
|
@@ -9584,7 +9841,8 @@ function prepareLaunch(params) {
|
|
|
9584
9841
|
...headroom === void 0 ? {} : { headroom },
|
|
9585
9842
|
sessionId,
|
|
9586
9843
|
remoteControl: resolvedFlags.remoteControl,
|
|
9587
|
-
routeByName: routesByName
|
|
9844
|
+
routeByName: routesByName,
|
|
9845
|
+
...decided.models?.tiers === void 0 ? {} : { tierModels: decided.models.tiers }
|
|
9588
9846
|
});
|
|
9589
9847
|
const releases = [...headroom === void 0 || headroomPort === void 0 ? [] : [headroomPort.release], ...frontDoorRelease === void 0 ? [] : [frontDoorRelease]];
|
|
9590
9848
|
const release = () => {
|
|
@@ -9664,7 +9922,6 @@ var init_launcher = __esm({
|
|
|
9664
9922
|
init_launchReport();
|
|
9665
9923
|
init_modelPicker();
|
|
9666
9924
|
init_providerCatalogue();
|
|
9667
|
-
init_modelsStore();
|
|
9668
9925
|
init_providersStore();
|
|
9669
9926
|
init_pool();
|
|
9670
9927
|
init_resumeContext();
|
|
@@ -9682,6 +9939,7 @@ var init_launcher = __esm({
|
|
|
9682
9939
|
init_read();
|
|
9683
9940
|
init_claudeVersion();
|
|
9684
9941
|
init_launchHook();
|
|
9942
|
+
init_targets();
|
|
9685
9943
|
}
|
|
9686
9944
|
});
|
|
9687
9945
|
|
|
@@ -9779,8 +10037,8 @@ function realEnsurePorts(paths, spawnDaemon) {
|
|
|
9779
10037
|
}
|
|
9780
10038
|
function realFrontDoorPort(paths, spawnDaemon) {
|
|
9781
10039
|
return {
|
|
9782
|
-
ensure: (inheritedExtraCaCerts) => {
|
|
9783
|
-
const up = ensureFrontDoor({ paths, launcherPid: process.pid, ports: realEnsurePorts(paths, spawnDaemon) });
|
|
10040
|
+
ensure: (inheritedExtraCaCerts, session) => {
|
|
10041
|
+
const up = ensureFrontDoor({ paths, launcherPid: process.pid, ports: realEnsurePorts(paths, spawnDaemon), ...session === void 0 ? {} : { session } });
|
|
9784
10042
|
const trust = resolveTrustBundle({ caCertFile: paths.frontdoorCaCertFile, bundlesDir: paths.frontdoorCaBundlesDir, variable: "NODE_EXTRA_CA_CERTS", inherited: inheritedExtraCaCerts, fs: realTrustBundleFs });
|
|
9785
10043
|
return {
|
|
9786
10044
|
port: up.port,
|
|
@@ -14775,8 +15033,8 @@ var ResetRowSchema = z18.strictObject({
|
|
|
14775
15033
|
var ResetScheduleSchema = z18.strictObject({ resets: z18.readonly(z18.array(ResetRowSchema)) });
|
|
14776
15034
|
|
|
14777
15035
|
// src/frontdoor/controlSchemas.ts
|
|
14778
|
-
import
|
|
14779
|
-
import { z as
|
|
15036
|
+
import path32 from "node:path";
|
|
15037
|
+
import { z as z25 } from "zod";
|
|
14780
15038
|
|
|
14781
15039
|
// src/doctorReport.ts
|
|
14782
15040
|
init_claudeShim();
|
|
@@ -14952,7 +15210,7 @@ function removeIdentity(paths, name) {
|
|
|
14952
15210
|
// src/doctorReport.ts
|
|
14953
15211
|
init_realPorts();
|
|
14954
15212
|
import fs11 from "node:fs";
|
|
14955
|
-
import
|
|
15213
|
+
import path31 from "node:path";
|
|
14956
15214
|
init_signIn();
|
|
14957
15215
|
|
|
14958
15216
|
// src/codex/siwcStore.ts
|
|
@@ -15043,6 +15301,8 @@ init_source();
|
|
|
15043
15301
|
|
|
15044
15302
|
// src/models/doctor.ts
|
|
15045
15303
|
init_modelsStore();
|
|
15304
|
+
init_families();
|
|
15305
|
+
init_identity2();
|
|
15046
15306
|
function modelsFindings(input) {
|
|
15047
15307
|
const findings = [];
|
|
15048
15308
|
const { models } = input;
|
|
@@ -15087,6 +15347,38 @@ function modelsFindings(input) {
|
|
|
15087
15347
|
findings.push({ severity: "fail", message: `Tier ${tier} points at "${ref}", which names nothing defined.` });
|
|
15088
15348
|
}
|
|
15089
15349
|
}
|
|
15350
|
+
const modelOfRef = (ref) => ref.slice(ref.indexOf("/") + 1);
|
|
15351
|
+
for (const group of models.same ?? []) {
|
|
15352
|
+
for (let outer = 0; outer < group.length; outer += 1) {
|
|
15353
|
+
for (let inner = outer + 1; inner < group.length; inner += 1) {
|
|
15354
|
+
const left = group[outer] ?? "";
|
|
15355
|
+
const right = group[inner] ?? "";
|
|
15356
|
+
if (!left.startsWith("acct:") && !right.startsWith("acct:") && relateModels(modelOfRef(left), modelOfRef(right)) === "distinct") {
|
|
15357
|
+
findings.push({ severity: "warn", message: `"${left}" and "${right}" are asserted to be one model, but their names say they are different models; check the assertion is not a typo.` });
|
|
15358
|
+
}
|
|
15359
|
+
if ((models.distinct ?? []).some(([a, b]) => a === left && b === right || a === right && b === left)) {
|
|
15360
|
+
findings.push({ severity: "fail", message: `"${left}" and "${right}" are asserted to be both one model and two models.` });
|
|
15361
|
+
}
|
|
15362
|
+
}
|
|
15363
|
+
}
|
|
15364
|
+
}
|
|
15365
|
+
for (const [name, model] of Object.entries(models.virtual ?? {})) {
|
|
15366
|
+
const concrete = model.members.filter((member) => memberKindOf(member, models) === "provider" && member.includes("/"));
|
|
15367
|
+
const looksAlike = concrete.flatMap((left, index) => concrete.slice(index + 1).filter((right) => relateModels(modelOfRef(left), modelOfRef(right)) === "same").map((right) => [left, right]));
|
|
15368
|
+
for (const [left, right] of looksAlike) {
|
|
15369
|
+
findings.push({ severity: "warn", message: `Virtual model "${name}" lists "${left}" and "${right}", which look like one model; a member ${FAMILY_PREFIX}${familyKeyOf(modelOfRef(left))} names every target of it.` });
|
|
15370
|
+
}
|
|
15371
|
+
}
|
|
15372
|
+
if (input.targets !== void 0) {
|
|
15373
|
+
const families = buildFamilies(input.targets, models);
|
|
15374
|
+
for (const [name, model] of Object.entries(models.virtual ?? {})) {
|
|
15375
|
+
for (const member of model.members.filter((entry) => entry.startsWith(FAMILY_PREFIX))) {
|
|
15376
|
+
if (!families.some((family) => `${FAMILY_PREFIX}${family.key}` === member)) {
|
|
15377
|
+
findings.push({ severity: "warn", message: `Virtual model "${name}" names ${member}, but no target the providers offer belongs to that family.` });
|
|
15378
|
+
}
|
|
15379
|
+
}
|
|
15380
|
+
}
|
|
15381
|
+
}
|
|
15090
15382
|
const hidden = new Set(models.hide ?? []);
|
|
15091
15383
|
const shown = new Set(models.show ?? []);
|
|
15092
15384
|
for (const ref of hidden) {
|
|
@@ -15098,6 +15390,7 @@ function modelsFindings(input) {
|
|
|
15098
15390
|
}
|
|
15099
15391
|
|
|
15100
15392
|
// src/doctorReport.ts
|
|
15393
|
+
init_targets();
|
|
15101
15394
|
init_configProfilesStore();
|
|
15102
15395
|
|
|
15103
15396
|
// src/headroom/allowlistDrift.ts
|
|
@@ -15322,7 +15615,7 @@ function tcpPortEraRecord(raw) {
|
|
|
15322
15615
|
return (has("port") || has("lastPort")) && !has("socketPath");
|
|
15323
15616
|
}
|
|
15324
15617
|
function pushPathResolution(push, resolution) {
|
|
15325
|
-
const ownDir =
|
|
15618
|
+
const ownDir = path31.dirname(resolution.ownExecutablePath);
|
|
15326
15619
|
switch (resolution.agentShim.status) {
|
|
15327
15620
|
case "ok":
|
|
15328
15621
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -15426,14 +15719,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
15426
15719
|
}
|
|
15427
15720
|
function pushLegacyName(push, params) {
|
|
15428
15721
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
15429
|
-
if (legacyVariables.length === 0 &&
|
|
15722
|
+
if (legacyVariables.length === 0 && path31.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
15430
15723
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
15431
15724
|
return;
|
|
15432
15725
|
}
|
|
15433
15726
|
for (const name of legacyVariables) {
|
|
15434
15727
|
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);
|
|
15435
15728
|
}
|
|
15436
|
-
if (
|
|
15729
|
+
if (path31.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
15437
15730
|
push(
|
|
15438
15731
|
"legacy-name",
|
|
15439
15732
|
"warn",
|
|
@@ -15650,7 +15943,7 @@ function runDoctor(params) {
|
|
|
15650
15943
|
if (models === void 0) {
|
|
15651
15944
|
push("models", "pass", "No models block configured.");
|
|
15652
15945
|
} else {
|
|
15653
|
-
for (const finding of modelsFindings({ models, providers: params.providers.map((entry) => entry.name), identities: params.identities.map((entry) => entry.name) })) {
|
|
15946
|
+
for (const finding of modelsFindings({ models, providers: params.providers.map((entry) => entry.name), identities: params.identities.map((entry) => entry.name), ...params.modelTargets === void 0 ? {} : { targets: params.modelTargets } })) {
|
|
15654
15947
|
push("models", finding.severity, finding.message);
|
|
15655
15948
|
}
|
|
15656
15949
|
push("models", "pass", "The models block is consistent.");
|
|
@@ -15832,18 +16125,18 @@ function collectDoctorReport(params) {
|
|
|
15832
16125
|
const { paths } = params;
|
|
15833
16126
|
const identityNames = fs11.existsSync(paths.identitiesDir) ? fs11.readdirSync(paths.identitiesDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isIdentityDirectoryName(entry.name)).map((entry) => entry.name).sort() : [];
|
|
15834
16127
|
const identities = identityNames.map((name) => {
|
|
15835
|
-
const farmRoot =
|
|
15836
|
-
const identityPath =
|
|
16128
|
+
const farmRoot = path31.join(paths.identitiesDir, name);
|
|
16129
|
+
const identityPath = path31.join(farmRoot, "identity.json");
|
|
15837
16130
|
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: fs11.existsSync(credentialsFilePath(farmRoot)) };
|
|
15838
16131
|
});
|
|
15839
16132
|
const profileNames = fs11.existsSync(paths.configProfilesDir) ? fs11.readdirSync(paths.configProfilesDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
15840
16133
|
const configProfiles = profileNames.map((name) => {
|
|
15841
|
-
const profilePath =
|
|
16134
|
+
const profilePath = path31.join(paths.configProfilesDir, `${name}.json`);
|
|
15842
16135
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
15843
16136
|
});
|
|
15844
16137
|
const providerNames = fs11.existsSync(paths.providersDir) ? fs11.readdirSync(paths.providersDir, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).map((entry) => entry.name.slice(0, -".json".length)).sort() : [];
|
|
15845
16138
|
const providers = providerNames.map((name) => {
|
|
15846
|
-
const providerPath =
|
|
16139
|
+
const providerPath = path31.join(paths.providersDir, `${name}.json`);
|
|
15847
16140
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
15848
16141
|
});
|
|
15849
16142
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -15855,12 +16148,12 @@ function collectDoctorReport(params) {
|
|
|
15855
16148
|
binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
15856
16149
|
}
|
|
15857
16150
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
15858
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
16151
|
+
const pathDirs = (params.env.PATH ?? "").split(path31.delimiter).filter((dir) => dir !== "");
|
|
15859
16152
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
15860
16153
|
findPathShadow({
|
|
15861
16154
|
pathDirs,
|
|
15862
|
-
targetDir:
|
|
15863
|
-
targetFilename:
|
|
16155
|
+
targetDir: path31.dirname(shimState.targetPath),
|
|
16156
|
+
targetFilename: path31.basename(shimState.targetPath),
|
|
15864
16157
|
findExecutableInDir
|
|
15865
16158
|
}),
|
|
15866
16159
|
shimState.targetPath,
|
|
@@ -15884,6 +16177,7 @@ function collectDoctorReport(params) {
|
|
|
15884
16177
|
directoryRules: { path: paths.directoryRulesFile, raw: realFsPort.readFileUtf8(paths.directoryRulesFile) },
|
|
15885
16178
|
globalConfig: { path: paths.globalConfigFile, raw: realFsPort.readFileUtf8(paths.globalConfigFile) },
|
|
15886
16179
|
models: parsedModelsOf(paths),
|
|
16180
|
+
modelTargets: targetRefs(paths),
|
|
15887
16181
|
categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
|
|
15888
16182
|
activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
|
|
15889
16183
|
binaryDiscovery,
|
|
@@ -15894,7 +16188,7 @@ function collectDoctorReport(params) {
|
|
|
15894
16188
|
agentShim: refinePathShadow(
|
|
15895
16189
|
findPathShadow({
|
|
15896
16190
|
pathDirs,
|
|
15897
|
-
targetDir:
|
|
16191
|
+
targetDir: path31.dirname(ownExecutablePath),
|
|
15898
16192
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
15899
16193
|
findExecutableInDir
|
|
15900
16194
|
}),
|
|
@@ -15935,90 +16229,90 @@ function collectDoctorReport(params) {
|
|
|
15935
16229
|
// src/frontdoor/controlSchemas.ts
|
|
15936
16230
|
init_schema2();
|
|
15937
16231
|
init_state();
|
|
15938
|
-
var UsageListOutputSchema =
|
|
15939
|
-
var UsageWindowsInputSchema =
|
|
15940
|
-
identity:
|
|
15941
|
-
provider:
|
|
16232
|
+
var UsageListOutputSchema = z25.strictObject({ snapshots: z25.readonly(z25.array(UsageSnapshotSchema)) });
|
|
16233
|
+
var UsageWindowsInputSchema = z25.strictObject({
|
|
16234
|
+
identity: z25.string().min(1),
|
|
16235
|
+
provider: z25.string().min(1).optional()
|
|
15942
16236
|
});
|
|
15943
|
-
var EffectiveWindowSchema =
|
|
16237
|
+
var EffectiveWindowSchema = z25.strictObject({
|
|
15944
16238
|
/** True when the window's reset time has passed, so the recorded observation describes a window that no longer exists. */
|
|
15945
|
-
reset:
|
|
16239
|
+
reset: z25.boolean(),
|
|
15946
16240
|
/** The fraction used: 0 for a reset window, otherwise what was last observed, absent when none was reported. */
|
|
15947
|
-
utilization:
|
|
16241
|
+
utilization: z25.number().optional(),
|
|
15948
16242
|
/** The reset instant, for a window that has not reset yet and reported one. */
|
|
15949
|
-
resetsAtMs:
|
|
16243
|
+
resetsAtMs: z25.number().optional(),
|
|
15950
16244
|
/** The window's own status, for a window that has not reset yet. */
|
|
15951
|
-
status:
|
|
16245
|
+
status: z25.string().optional()
|
|
15952
16246
|
});
|
|
15953
|
-
var UsageWindowsOutputSchema =
|
|
15954
|
-
identity:
|
|
15955
|
-
provider:
|
|
16247
|
+
var UsageWindowsOutputSchema = z25.strictObject({
|
|
16248
|
+
identity: z25.string(),
|
|
16249
|
+
provider: z25.string(),
|
|
15956
16250
|
/** When the rate-limit state the windows come from was observed. */
|
|
15957
|
-
observedAt:
|
|
16251
|
+
observedAt: z25.iso.datetime().optional(),
|
|
15958
16252
|
fiveHour: EffectiveWindowSchema.optional(),
|
|
15959
16253
|
sevenDay: EffectiveWindowSchema.optional()
|
|
15960
16254
|
});
|
|
15961
|
-
var UsageLiveOutputSchema =
|
|
16255
|
+
var UsageLiveOutputSchema = z25.strictObject({
|
|
15962
16256
|
/** The freshest observation the door holds, never narrowed by the read's session filter because it is the door's single latest statement of the account's quota; absent while no rate_limit_event has been filed at all. */
|
|
15963
16257
|
latest: RcLiveRateLimitSchema.optional(),
|
|
15964
16258
|
/** One observation per session whose stream has filed a rate_limit_event this door generation. */
|
|
15965
|
-
sessions:
|
|
16259
|
+
sessions: z25.readonly(z25.array(RcLiveRateLimitSchema))
|
|
15966
16260
|
});
|
|
15967
|
-
var FrontDoorSessionStatusSchema =
|
|
15968
|
-
pid:
|
|
15969
|
-
startedAt:
|
|
15970
|
-
alive:
|
|
16261
|
+
var FrontDoorSessionStatusSchema = z25.strictObject({
|
|
16262
|
+
pid: z25.int().positive(),
|
|
16263
|
+
startedAt: z25.number(),
|
|
16264
|
+
alive: z25.boolean()
|
|
15971
16265
|
});
|
|
15972
|
-
var HeadroomSocketTargetSchema =
|
|
15973
|
-
var FrontDoorStatusOutputSchema =
|
|
16266
|
+
var HeadroomSocketTargetSchema = z25.union([z25.strictObject({ socketPath: z25.string() }), z25.strictObject({ refused: z25.string() })]);
|
|
16267
|
+
var FrontDoorStatusOutputSchema = z25.strictObject({
|
|
15974
16268
|
state: FrontDoorStateSchema,
|
|
15975
|
-
supervisorAlive:
|
|
15976
|
-
sessions:
|
|
16269
|
+
supervisorAlive: z25.boolean(),
|
|
16270
|
+
sessions: z25.readonly(z25.array(FrontDoorSessionStatusSchema)),
|
|
15977
16271
|
headroomSocket: HeadroomSocketTargetSchema.optional(),
|
|
15978
|
-
logPath:
|
|
15979
|
-
logExists:
|
|
16272
|
+
logPath: z25.string(),
|
|
16273
|
+
logExists: z25.boolean()
|
|
15980
16274
|
});
|
|
15981
|
-
var FrontDoorSessionsOutputSchema =
|
|
15982
|
-
var CheckRunInputSchema =
|
|
15983
|
-
path:
|
|
15984
|
-
identity:
|
|
15985
|
-
}).refine((input) =>
|
|
15986
|
-
var PoolPickInputSchema =
|
|
15987
|
-
pool:
|
|
15988
|
-
path:
|
|
15989
|
-
}).refine((input) =>
|
|
15990
|
-
var DoctorFindingSchema =
|
|
15991
|
-
section:
|
|
15992
|
-
subject:
|
|
15993
|
-
severity:
|
|
15994
|
-
message:
|
|
16275
|
+
var FrontDoorSessionsOutputSchema = z25.strictObject({ sessions: z25.readonly(z25.array(FrontDoorSessionStatusSchema)) });
|
|
16276
|
+
var CheckRunInputSchema = z25.strictObject({
|
|
16277
|
+
path: z25.string().min(1),
|
|
16278
|
+
identity: z25.string().min(1).optional()
|
|
16279
|
+
}).refine((input) => path32.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
16280
|
+
var PoolPickInputSchema = z25.strictObject({
|
|
16281
|
+
pool: z25.string().min(1),
|
|
16282
|
+
path: z25.string().min(1)
|
|
16283
|
+
}).refine((input) => path32.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
16284
|
+
var DoctorFindingSchema = z25.strictObject({
|
|
16285
|
+
section: z25.enum(DOCTOR_SECTIONS),
|
|
16286
|
+
subject: z25.string().optional(),
|
|
16287
|
+
severity: z25.enum(DOCTOR_SEVERITIES),
|
|
16288
|
+
message: z25.string()
|
|
15995
16289
|
});
|
|
15996
|
-
var DoctorRunOutputSchema =
|
|
16290
|
+
var DoctorRunOutputSchema = z25.strictObject({
|
|
15997
16291
|
/** False exactly when any finding is a `fail`; a `warn` never fails the report on its own. */
|
|
15998
|
-
ok:
|
|
15999
|
-
findings:
|
|
16292
|
+
ok: z25.boolean(),
|
|
16293
|
+
findings: z25.readonly(z25.array(DoctorFindingSchema))
|
|
16000
16294
|
});
|
|
16001
|
-
var FrontDoorRestartOutputSchema =
|
|
16002
|
-
action:
|
|
16003
|
-
previousPid:
|
|
16295
|
+
var FrontDoorRestartOutputSchema = z25.strictObject({
|
|
16296
|
+
action: z25.literal("restarting"),
|
|
16297
|
+
previousPid: z25.int().positive()
|
|
16004
16298
|
});
|
|
16005
|
-
var UpdateCheckOutputSchema =
|
|
16006
|
-
current:
|
|
16007
|
-
latest:
|
|
16008
|
-
action:
|
|
16299
|
+
var UpdateCheckOutputSchema = z25.strictObject({
|
|
16300
|
+
current: z25.string(),
|
|
16301
|
+
latest: z25.string(),
|
|
16302
|
+
action: z25.enum(["current", "available", "updated"])
|
|
16009
16303
|
});
|
|
16010
|
-
var CodexSignInSchema =
|
|
16011
|
-
|
|
16012
|
-
|
|
16013
|
-
|
|
16304
|
+
var CodexSignInSchema = z25.discriminatedUnion("state", [
|
|
16305
|
+
z25.strictObject({ state: z25.literal("none") }),
|
|
16306
|
+
z25.strictObject({ state: z25.literal("signed-in"), email: z25.string().optional(), planScope: z25.boolean(), accessTokenExpiresAt: z25.number() }),
|
|
16307
|
+
z25.strictObject({ state: z25.literal("unreadable"), message: z25.string() })
|
|
16014
16308
|
]);
|
|
16015
|
-
var CodexStatusOutputSchema =
|
|
16309
|
+
var CodexStatusOutputSchema = z25.strictObject({
|
|
16016
16310
|
signIn: CodexSignInSchema,
|
|
16017
|
-
codexProviders:
|
|
16311
|
+
codexProviders: z25.readonly(z25.array(z25.string()))
|
|
16018
16312
|
});
|
|
16019
|
-
var CodexLogoutOutputSchema =
|
|
16020
|
-
hadGrant:
|
|
16021
|
-
revoked:
|
|
16313
|
+
var CodexLogoutOutputSchema = z25.strictObject({
|
|
16314
|
+
hadGrant: z25.boolean(),
|
|
16315
|
+
revoked: z25.boolean()
|
|
16022
16316
|
});
|
|
16023
16317
|
|
|
16024
16318
|
// src/frontdoor/codexApi.ts
|
|
@@ -16176,143 +16470,143 @@ init_providersStore();
|
|
|
16176
16470
|
|
|
16177
16471
|
// src/frontdoor/configSchemas.ts
|
|
16178
16472
|
init_schema();
|
|
16179
|
-
import { z as
|
|
16180
|
-
var RemovalConfirmationSchema =
|
|
16181
|
-
var CredentialWriteSchema = (targets) =>
|
|
16182
|
-
sources:
|
|
16183
|
-
target:
|
|
16184
|
-
cache:
|
|
16473
|
+
import { z as z26 } from "zod";
|
|
16474
|
+
var RemovalConfirmationSchema = z26.boolean();
|
|
16475
|
+
var CredentialWriteSchema = (targets) => z26.strictObject({
|
|
16476
|
+
sources: z26.array(RemoteCredentialSourceSchema).min(1).optional(),
|
|
16477
|
+
target: z26.enum(targets).optional(),
|
|
16478
|
+
cache: z26.union([z26.literal(false), CredentialCacheSchema]).optional()
|
|
16185
16479
|
});
|
|
16186
|
-
var CredentialSummarySchema2 =
|
|
16187
|
-
target:
|
|
16188
|
-
sources:
|
|
16189
|
-
|
|
16190
|
-
|
|
16191
|
-
|
|
16192
|
-
|
|
16193
|
-
|
|
16194
|
-
|
|
16195
|
-
|
|
16480
|
+
var CredentialSummarySchema2 = z26.strictObject({
|
|
16481
|
+
target: z26.enum(CREDENTIAL_TARGETS),
|
|
16482
|
+
sources: z26.readonly(z26.array(
|
|
16483
|
+
z26.discriminatedUnion("kind", [
|
|
16484
|
+
z26.strictObject({ kind: z26.literal("env"), variable: z26.string() }),
|
|
16485
|
+
z26.strictObject({ kind: z26.literal("file"), path: z26.string() }),
|
|
16486
|
+
z26.strictObject({ kind: z26.literal("command"), program: z26.string() }),
|
|
16487
|
+
z26.strictObject({ kind: z26.literal("op"), reference: z26.string() }),
|
|
16488
|
+
z26.strictObject({ kind: z26.literal("keychain"), service: z26.string(), account: z26.string().optional() }),
|
|
16489
|
+
z26.strictObject({ kind: z26.literal("literal") })
|
|
16196
16490
|
])
|
|
16197
16491
|
)),
|
|
16198
16492
|
cache: CredentialCacheSchema.optional()
|
|
16199
16493
|
});
|
|
16200
|
-
var mutationOutput = (kind, action) =>
|
|
16201
|
-
var storedMutationOutput = (kind, action, value) =>
|
|
16202
|
-
var IdentityValueSchema =
|
|
16203
|
-
name:
|
|
16204
|
-
defaultConfigProfile:
|
|
16205
|
-
allowAmbientCredential:
|
|
16494
|
+
var mutationOutput = (kind, action) => z26.strictObject({ action: z26.literal(action), kind: z26.literal(kind), name: z26.string() });
|
|
16495
|
+
var storedMutationOutput = (kind, action, value) => z26.strictObject({ action: z26.literal(action), kind: z26.literal(kind), name: z26.string(), value });
|
|
16496
|
+
var IdentityValueSchema = z26.strictObject({
|
|
16497
|
+
name: z26.string(),
|
|
16498
|
+
defaultConfigProfile: z26.string().optional(),
|
|
16499
|
+
allowAmbientCredential: z26.boolean(),
|
|
16206
16500
|
credential: CredentialSummarySchema2.optional(),
|
|
16207
|
-
anchors:
|
|
16501
|
+
anchors: z26.array(AnchorSchema).optional()
|
|
16208
16502
|
});
|
|
16209
16503
|
var ProfileValueSchema = ConfigProfileSchema.omit({ $schema: true });
|
|
16210
|
-
var ProviderValueSchema =
|
|
16211
|
-
name:
|
|
16212
|
-
kind:
|
|
16213
|
-
displayName:
|
|
16214
|
-
baseUrl:
|
|
16504
|
+
var ProviderValueSchema = z26.strictObject({
|
|
16505
|
+
name: z26.string(),
|
|
16506
|
+
kind: z26.enum(PROVIDER_KINDS),
|
|
16507
|
+
displayName: z26.string(),
|
|
16508
|
+
baseUrl: z26.string().optional(),
|
|
16215
16509
|
codex: CodexProviderConfigSchema.optional(),
|
|
16216
16510
|
credential: CredentialSummarySchema2.optional(),
|
|
16217
|
-
env:
|
|
16511
|
+
env: z26.record(z26.string(), z26.string()).optional()
|
|
16218
16512
|
});
|
|
16219
|
-
var ConfigNameInputSchema =
|
|
16513
|
+
var ConfigNameInputSchema = z26.strictObject({ name: z26.string().min(1) });
|
|
16220
16514
|
var ConfigIdentityAddOutputSchema = storedMutationOutput("identity", "created", IdentityValueSchema);
|
|
16221
|
-
var ConfigIdentitySetInputSchema =
|
|
16222
|
-
name:
|
|
16223
|
-
defaultConfigProfile:
|
|
16224
|
-
allowAmbientCredential:
|
|
16225
|
-
credential:
|
|
16515
|
+
var ConfigIdentitySetInputSchema = z26.strictObject({
|
|
16516
|
+
name: z26.string().min(1),
|
|
16517
|
+
defaultConfigProfile: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16518
|
+
allowAmbientCredential: z26.boolean().optional(),
|
|
16519
|
+
credential: z26.union([z26.literal(false), CredentialWriteSchema(CREDENTIAL_TARGETS)]).optional(),
|
|
16226
16520
|
/** `false` removes the anchors; a list replaces them. */
|
|
16227
|
-
anchors:
|
|
16521
|
+
anchors: z26.union([z26.literal(false), z26.array(AnchorSchema).min(1)]).optional()
|
|
16228
16522
|
});
|
|
16229
16523
|
var ConfigIdentitySetOutputSchema = storedMutationOutput("identity", "updated", IdentityValueSchema);
|
|
16230
|
-
var ConfigIdentityRemoveInputSchema =
|
|
16524
|
+
var ConfigIdentityRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16231
16525
|
var ConfigIdentityRemoveOutputSchema = mutationOutput("identity", "removed");
|
|
16232
16526
|
var ConfigIdentityUseOutputSchema = mutationOutput("identity", "selected");
|
|
16233
|
-
var ConfigProfileAddInputSchema =
|
|
16234
|
-
name:
|
|
16235
|
-
extends:
|
|
16236
|
-
description:
|
|
16527
|
+
var ConfigProfileAddInputSchema = z26.strictObject({
|
|
16528
|
+
name: z26.string().min(1),
|
|
16529
|
+
extends: z26.array(z26.string().min(1)).optional(),
|
|
16530
|
+
description: z26.string().optional()
|
|
16237
16531
|
});
|
|
16238
16532
|
var ConfigProfileAddOutputSchema = storedMutationOutput("profile", "created", ProfileValueSchema);
|
|
16239
|
-
var ConfigProfileSetInputSchema =
|
|
16240
|
-
name:
|
|
16241
|
-
category:
|
|
16242
|
-
entry:
|
|
16243
|
-
extends:
|
|
16244
|
-
description:
|
|
16245
|
-
launch:
|
|
16246
|
-
skipPermissions:
|
|
16247
|
-
remoteControl:
|
|
16248
|
-
headroom:
|
|
16249
|
-
trackUsage:
|
|
16250
|
-
provider:
|
|
16251
|
-
claudeVersion:
|
|
16252
|
-
delay:
|
|
16253
|
-
pause:
|
|
16254
|
-
explain:
|
|
16255
|
-
routeByName:
|
|
16533
|
+
var ConfigProfileSetInputSchema = z26.strictObject({
|
|
16534
|
+
name: z26.string().min(1),
|
|
16535
|
+
category: z26.record(z26.string(), z26.boolean()).optional(),
|
|
16536
|
+
entry: z26.record(z26.string(), z26.boolean()).optional(),
|
|
16537
|
+
extends: z26.union([z26.array(z26.string().min(1)), z26.literal(false)]).optional(),
|
|
16538
|
+
description: z26.union([z26.string(), z26.literal(false)]).optional(),
|
|
16539
|
+
launch: z26.strictObject({
|
|
16540
|
+
skipPermissions: z26.boolean().optional(),
|
|
16541
|
+
remoteControl: z26.boolean().optional(),
|
|
16542
|
+
headroom: z26.boolean().optional(),
|
|
16543
|
+
trackUsage: z26.boolean().optional(),
|
|
16544
|
+
provider: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16545
|
+
claudeVersion: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16546
|
+
delay: z26.union([z26.string().regex(DURATION_RE), z26.literal(false)]).optional(),
|
|
16547
|
+
pause: z26.boolean().optional(),
|
|
16548
|
+
explain: z26.boolean().optional(),
|
|
16549
|
+
routeByName: z26.boolean().optional()
|
|
16256
16550
|
}).optional()
|
|
16257
16551
|
});
|
|
16258
16552
|
var ConfigProfileSetOutputSchema = storedMutationOutput("profile", "updated", ProfileValueSchema);
|
|
16259
|
-
var ConfigProfileRemoveInputSchema =
|
|
16553
|
+
var ConfigProfileRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16260
16554
|
var ConfigProfileRemoveOutputSchema = mutationOutput("profile", "removed");
|
|
16261
16555
|
var ConfigProfileUseOutputSchema = mutationOutput("profile", "selected");
|
|
16262
|
-
var PoolMembersInputSchema =
|
|
16263
|
-
var ConfigPoolAddInputSchema =
|
|
16264
|
-
name:
|
|
16556
|
+
var PoolMembersInputSchema = z26.array(z26.string().min(1)).min(1);
|
|
16557
|
+
var ConfigPoolAddInputSchema = z26.strictObject({
|
|
16558
|
+
name: z26.string().min(1),
|
|
16265
16559
|
identities: PoolMembersInputSchema,
|
|
16266
|
-
preference:
|
|
16267
|
-
resumeOnLimit:
|
|
16268
|
-
compactBeforeLimit:
|
|
16560
|
+
preference: z26.enum(POOL_PREFERENCES).optional(),
|
|
16561
|
+
resumeOnLimit: z26.boolean().optional(),
|
|
16562
|
+
compactBeforeLimit: z26.boolean().optional(),
|
|
16269
16563
|
compactAtUtilisation: CompactAtUtilisationSchema.optional()
|
|
16270
16564
|
});
|
|
16271
16565
|
var ConfigPoolAddOutputSchema = storedMutationOutput("pool", "created", PoolSchema);
|
|
16272
|
-
var ConfigPoolSetInputSchema =
|
|
16273
|
-
name:
|
|
16566
|
+
var ConfigPoolSetInputSchema = z26.strictObject({
|
|
16567
|
+
name: z26.string().min(1),
|
|
16274
16568
|
identities: PoolMembersInputSchema.optional(),
|
|
16275
|
-
preference:
|
|
16276
|
-
resumeOnLimit:
|
|
16277
|
-
compactBeforeLimit:
|
|
16278
|
-
compactAtUtilisation:
|
|
16569
|
+
preference: z26.union([z26.enum(POOL_PREFERENCES), z26.literal(false)]).optional(),
|
|
16570
|
+
resumeOnLimit: z26.boolean().optional(),
|
|
16571
|
+
compactBeforeLimit: z26.boolean().optional(),
|
|
16572
|
+
compactAtUtilisation: z26.union([CompactAtUtilisationSchema, z26.literal(false)]).optional()
|
|
16279
16573
|
});
|
|
16280
16574
|
var ConfigPoolSetOutputSchema = storedMutationOutput("pool", "updated", PoolSchema);
|
|
16281
|
-
var ConfigPoolRemoveInputSchema =
|
|
16575
|
+
var ConfigPoolRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16282
16576
|
var ConfigPoolRemoveOutputSchema = mutationOutput("pool", "removed");
|
|
16283
16577
|
var ConfigPoolUseOutputSchema = mutationOutput("pool", "selected");
|
|
16284
|
-
var ConfigProviderAddInputSchema =
|
|
16285
|
-
name:
|
|
16286
|
-
kind:
|
|
16287
|
-
displayName:
|
|
16288
|
-
baseUrl:
|
|
16578
|
+
var ConfigProviderAddInputSchema = z26.strictObject({
|
|
16579
|
+
name: z26.string().min(1),
|
|
16580
|
+
kind: z26.enum(PROVIDER_KINDS).optional(),
|
|
16581
|
+
displayName: z26.string().min(1),
|
|
16582
|
+
baseUrl: z26.string().min(1).optional(),
|
|
16289
16583
|
credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).required({ sources: true }),
|
|
16290
16584
|
codex: CodexProviderConfigSchema.optional()
|
|
16291
16585
|
});
|
|
16292
16586
|
var ConfigProviderAddOutputSchema = storedMutationOutput("provider", "created", ProviderValueSchema);
|
|
16293
|
-
var ConfigProviderSetInputSchema =
|
|
16294
|
-
name:
|
|
16295
|
-
displayName:
|
|
16296
|
-
baseUrl:
|
|
16587
|
+
var ConfigProviderSetInputSchema = z26.strictObject({
|
|
16588
|
+
name: z26.string().min(1),
|
|
16589
|
+
displayName: z26.string().min(1).optional(),
|
|
16590
|
+
baseUrl: z26.string().min(1).optional(),
|
|
16297
16591
|
credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).optional(),
|
|
16298
16592
|
codex: CodexProviderConfigSchema.optional()
|
|
16299
16593
|
});
|
|
16300
16594
|
var ConfigProviderSetOutputSchema = storedMutationOutput("provider", "updated", ProviderValueSchema);
|
|
16301
|
-
var ConfigProviderRemoveInputSchema =
|
|
16595
|
+
var ConfigProviderRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16302
16596
|
var ConfigProviderRemoveOutputSchema = mutationOutput("provider", "removed");
|
|
16303
|
-
var ConfigRuleAddInputSchema =
|
|
16304
|
-
path:
|
|
16305
|
-
configProfile:
|
|
16306
|
-
identity:
|
|
16597
|
+
var ConfigRuleAddInputSchema = z26.strictObject({
|
|
16598
|
+
path: z26.string().min(1),
|
|
16599
|
+
configProfile: z26.string().min(1).optional(),
|
|
16600
|
+
identity: z26.string().min(1).optional()
|
|
16307
16601
|
});
|
|
16308
16602
|
var ConfigRuleAddOutputSchema = storedMutationOutput("rule", "created", DirectoryRuleSchema);
|
|
16309
|
-
var ConfigRuleSetInputSchema =
|
|
16310
|
-
path:
|
|
16311
|
-
configProfile:
|
|
16312
|
-
identity:
|
|
16603
|
+
var ConfigRuleSetInputSchema = z26.strictObject({
|
|
16604
|
+
path: z26.string().min(1),
|
|
16605
|
+
configProfile: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16606
|
+
identity: z26.union([z26.string().min(1), z26.literal(false)]).optional()
|
|
16313
16607
|
});
|
|
16314
16608
|
var ConfigRuleSetOutputSchema = storedMutationOutput("rule", "updated", DirectoryRuleSchema);
|
|
16315
|
-
var ConfigRuleRemoveInputSchema =
|
|
16609
|
+
var ConfigRuleRemoveInputSchema = z26.strictObject({ path: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16316
16610
|
var ConfigRuleRemoveOutputSchema = mutationOutput("rule", "removed");
|
|
16317
16611
|
|
|
16318
16612
|
// src/frontdoor/configApi.ts
|
|
@@ -16624,43 +16918,43 @@ import { openapi as openapi4 } from "@orpc/openapi";
|
|
|
16624
16918
|
import { eventIterator as eventIterator2, withEventMeta as withEventMeta2 } from "@orpc/server";
|
|
16625
16919
|
|
|
16626
16920
|
// src/frontdoor/eventSchemas.ts
|
|
16627
|
-
import { z as
|
|
16921
|
+
import { z as z27 } from "zod";
|
|
16628
16922
|
var DOOR_EVENT_SOURCE_RC = "rc";
|
|
16629
16923
|
var LAUNCH_EVENT_SOURCE = "launch";
|
|
16630
16924
|
var USAGE_EVENT_SOURCE = "usage";
|
|
16631
16925
|
var DOOR_HEALTH_EVENT_SOURCE = "door";
|
|
16632
16926
|
var QUOTA_EXPIRING_EVENT_SOURCE = "quota-expiring";
|
|
16633
|
-
var DoorEventSchema =
|
|
16634
|
-
source:
|
|
16927
|
+
var DoorEventSchema = z27.strictObject({
|
|
16928
|
+
source: z27.string().min(1),
|
|
16635
16929
|
/** A positive integer because the backbone's counters start at one and only ever increase. */
|
|
16636
|
-
sequence:
|
|
16637
|
-
payload:
|
|
16930
|
+
sequence: z27.number().int().positive(),
|
|
16931
|
+
payload: z27.unknown()
|
|
16638
16932
|
});
|
|
16639
|
-
var DoorEventSourceQuerySchema =
|
|
16640
|
-
sources:
|
|
16933
|
+
var DoorEventSourceQuerySchema = z27.strictObject({
|
|
16934
|
+
sources: z27.array(z27.string().min(1)).min(1).optional()
|
|
16641
16935
|
});
|
|
16642
|
-
var LaunchLifecycleEventSchema =
|
|
16643
|
-
kind:
|
|
16644
|
-
pid:
|
|
16645
|
-
startedAt:
|
|
16646
|
-
observedAt:
|
|
16936
|
+
var LaunchLifecycleEventSchema = z27.strictObject({
|
|
16937
|
+
kind: z27.enum(["registered", "pruned", "ended"]),
|
|
16938
|
+
pid: z27.number().int().positive(),
|
|
16939
|
+
startedAt: z27.number(),
|
|
16940
|
+
observedAt: z27.number()
|
|
16647
16941
|
});
|
|
16648
|
-
var DoorHealthEventSchema =
|
|
16649
|
-
|
|
16650
|
-
|
|
16651
|
-
|
|
16652
|
-
|
|
16653
|
-
|
|
16654
|
-
|
|
16942
|
+
var DoorHealthEventSchema = z27.discriminatedUnion("kind", [
|
|
16943
|
+
z27.strictObject({ kind: z27.literal("generation"), pid: z27.number().int().positive(), providerPort: z27.number().int().positive(), connectPort: z27.number().int().positive(), directPort: z27.number().int().positive(), observedAt: z27.number() }),
|
|
16944
|
+
z27.strictObject({ kind: z27.literal("listenerFailed"), pid: z27.number().int().positive(), listener: z27.enum(["provider", "connect", "direct"]), message: z27.string(), observedAt: z27.number() }),
|
|
16945
|
+
z27.strictObject({ kind: z27.literal("binaryTurnover"), pid: z27.number().int().positive(), observedAt: z27.number() }),
|
|
16946
|
+
z27.strictObject({ kind: z27.literal("idleShutdown"), pid: z27.number().int().positive(), observedAt: z27.number() }),
|
|
16947
|
+
z27.strictObject({ kind: z27.literal("superseded"), pid: z27.number().int().positive(), ownerPid: z27.number().int().positive(), observedAt: z27.number() }),
|
|
16948
|
+
z27.strictObject({ kind: z27.literal("drained"), pid: z27.number().int().positive(), observedAt: z27.number() })
|
|
16655
16949
|
]);
|
|
16656
|
-
var QuotaExpiringEventSchema =
|
|
16657
|
-
identity:
|
|
16658
|
-
provider:
|
|
16659
|
-
window:
|
|
16950
|
+
var QuotaExpiringEventSchema = z27.strictObject({
|
|
16951
|
+
identity: z27.string().min(1),
|
|
16952
|
+
provider: z27.string().min(1),
|
|
16953
|
+
window: z27.enum(["fiveHour", "sevenDay"]),
|
|
16660
16954
|
/** The fraction of the window already used when it was seen expiring, always below one because a fully used window has nothing left to spend. */
|
|
16661
|
-
utilization:
|
|
16662
|
-
resetsAt:
|
|
16663
|
-
observedAt:
|
|
16955
|
+
utilization: z27.number().min(0).max(1),
|
|
16956
|
+
resetsAt: z27.iso.datetime(),
|
|
16957
|
+
observedAt: z27.number()
|
|
16664
16958
|
});
|
|
16665
16959
|
|
|
16666
16960
|
// src/frontdoor/eventsApi.ts
|
|
@@ -16743,57 +17037,57 @@ import { ORPCError as ORPCError5 } from "@orpc/client";
|
|
|
16743
17037
|
import { openapi as openapi6 } from "@orpc/openapi";
|
|
16744
17038
|
|
|
16745
17039
|
// src/frontdoor/launchSchemas.ts
|
|
16746
|
-
import
|
|
16747
|
-
import { z as
|
|
17040
|
+
import path33 from "node:path";
|
|
17041
|
+
import { z as z28 } from "zod";
|
|
16748
17042
|
init_claudeVersion();
|
|
16749
17043
|
init_identity();
|
|
16750
|
-
var LaunchResolveInputSchema =
|
|
16751
|
-
path:
|
|
17044
|
+
var LaunchResolveInputSchema = z28.strictObject({
|
|
17045
|
+
path: z28.string().min(1),
|
|
16752
17046
|
/** `@name`, launch flags, then the arguments for `claude`; empty for a bare launch. */
|
|
16753
|
-
argv:
|
|
17047
|
+
argv: z28.readonly(z28.array(z28.string())).optional(),
|
|
16754
17048
|
/** 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. */
|
|
16755
|
-
env:
|
|
16756
|
-
}).refine((input) =>
|
|
16757
|
-
var LaunchPoolDecisionSchema =
|
|
16758
|
-
name:
|
|
16759
|
-
reasons:
|
|
16760
|
-
movedOff:
|
|
17049
|
+
env: z28.record(z28.string(), z28.string()).optional()
|
|
17050
|
+
}).refine((input) => path33.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
17051
|
+
var LaunchPoolDecisionSchema = z28.strictObject({
|
|
17052
|
+
name: z28.string(),
|
|
17053
|
+
reasons: z28.readonly(z28.array(z28.string())),
|
|
17054
|
+
movedOff: z28.strictObject({ identity: z28.string(), reason: z28.string() }).optional()
|
|
16761
17055
|
});
|
|
16762
|
-
var LaunchDecisionSchema =
|
|
16763
|
-
identity:
|
|
16764
|
-
identitySource:
|
|
17056
|
+
var LaunchDecisionSchema = z28.strictObject({
|
|
17057
|
+
identity: z28.string().optional(),
|
|
17058
|
+
identitySource: z28.enum(IDENTITY_DECISION_SOURCES),
|
|
16765
17059
|
pool: LaunchPoolDecisionSchema.optional(),
|
|
16766
|
-
configDirEscapeHatch:
|
|
16767
|
-
configDir:
|
|
16768
|
-
configProfile:
|
|
16769
|
-
configProfileSource:
|
|
16770
|
-
provider:
|
|
17060
|
+
configDirEscapeHatch: z28.boolean(),
|
|
17061
|
+
configDir: z28.string().optional(),
|
|
17062
|
+
configProfile: z28.string().optional(),
|
|
17063
|
+
configProfileSource: z28.enum(CONFIG_PROFILE_DECISION_SOURCES),
|
|
17064
|
+
provider: z28.string().optional()
|
|
16771
17065
|
});
|
|
16772
|
-
var LaunchFlagsSchema =
|
|
16773
|
-
skipPermissions:
|
|
16774
|
-
remoteControl:
|
|
16775
|
-
headroom:
|
|
16776
|
-
trackUsage:
|
|
16777
|
-
pause:
|
|
16778
|
-
explain:
|
|
16779
|
-
routeByName:
|
|
17066
|
+
var LaunchFlagsSchema = z28.strictObject({
|
|
17067
|
+
skipPermissions: z28.boolean(),
|
|
17068
|
+
remoteControl: z28.boolean(),
|
|
17069
|
+
headroom: z28.boolean(),
|
|
17070
|
+
trackUsage: z28.boolean(),
|
|
17071
|
+
pause: z28.boolean(),
|
|
17072
|
+
explain: z28.boolean(),
|
|
17073
|
+
routeByName: z28.boolean(),
|
|
16780
17074
|
/** How long the launch waits after its own output before it starts claude, in milliseconds. */
|
|
16781
|
-
delayMs:
|
|
17075
|
+
delayMs: z28.number()
|
|
16782
17076
|
});
|
|
16783
|
-
var LaunchResolveOutputSchema =
|
|
17077
|
+
var LaunchResolveOutputSchema = z28.strictObject({
|
|
16784
17078
|
decision: LaunchDecisionSchema,
|
|
16785
17079
|
flags: LaunchFlagsSchema,
|
|
16786
|
-
claudeVersion:
|
|
17080
|
+
claudeVersion: z28.strictObject({ version: z28.string(), source: z28.enum(CLAUDE_VERSION_SOURCES) }).optional(),
|
|
16787
17081
|
/** The real `claude` binary the launch would spawn, on the door's host. */
|
|
16788
|
-
bin:
|
|
17082
|
+
bin: z28.string(),
|
|
16789
17083
|
/** The arguments the launch would pass it: the tool's own flags, then `CLAUDE_EXTRA_FLAGS`, then the caller's own. */
|
|
16790
|
-
args:
|
|
17084
|
+
args: z28.readonly(z28.array(z28.string())),
|
|
16791
17085
|
/** The credential the launch would authenticate with, by target and source kinds. Absent when none applies. */
|
|
16792
|
-
credential:
|
|
16793
|
-
routing:
|
|
17086
|
+
credential: z28.strictObject({ subject: z28.enum(["provider", "identity"]), name: z28.string(), summary: CredentialSummarySchema }).optional(),
|
|
17087
|
+
routing: z28.strictObject({ frontDoor: z28.boolean(), headroom: z28.boolean(), routeByName: z28.boolean() }),
|
|
16794
17088
|
/** The names of the environment variables the launch would set or unset, sorted. Values are not reported. */
|
|
16795
|
-
environment:
|
|
16796
|
-
warnings:
|
|
17089
|
+
environment: z28.readonly(z28.array(z28.string())),
|
|
17090
|
+
warnings: z28.readonly(z28.array(z28.string()))
|
|
16797
17091
|
});
|
|
16798
17092
|
|
|
16799
17093
|
// src/frontdoor/launchApi.ts
|
|
@@ -16829,22 +17123,22 @@ function createLaunchApiRouter(deps) {
|
|
|
16829
17123
|
// src/frontdoor/agentTreesApi.ts
|
|
16830
17124
|
import { ORPCError as ORPCError6 } from "@orpc/client";
|
|
16831
17125
|
import { openapi as openapi7 } from "@orpc/openapi";
|
|
16832
|
-
import { z as
|
|
17126
|
+
import { z as z29 } from "zod";
|
|
16833
17127
|
init_cliError();
|
|
16834
|
-
var AgentTreesListInputSchema =
|
|
17128
|
+
var AgentTreesListInputSchema = z29.strictObject({
|
|
16835
17129
|
/** Only this identity's sessions. */
|
|
16836
|
-
identity:
|
|
17130
|
+
identity: z29.string().optional(),
|
|
16837
17131
|
/** Include sessions that spawned no agent and ran no workflow. */
|
|
16838
|
-
all:
|
|
17132
|
+
all: z29.boolean().optional()
|
|
16839
17133
|
});
|
|
16840
|
-
var AgentTreesListOutputSchema =
|
|
16841
|
-
var AgentTreesShowInputSchema =
|
|
17134
|
+
var AgentTreesListOutputSchema = z29.array(SessionSummarySchema);
|
|
17135
|
+
var AgentTreesShowInputSchema = z29.strictObject({
|
|
16842
17136
|
/** A session id, or an unambiguous prefix of one. */
|
|
16843
|
-
session:
|
|
17137
|
+
session: z29.string().min(1),
|
|
16844
17138
|
/** Look only in this identity. */
|
|
16845
|
-
identity:
|
|
17139
|
+
identity: z29.string().optional()
|
|
16846
17140
|
});
|
|
16847
|
-
var AgentTreesShowOutputSchema =
|
|
17141
|
+
var AgentTreesShowOutputSchema = z29.strictObject({ identities: z29.array(z29.string()), ...MergedAgentTreeSchema.shape });
|
|
16848
17142
|
function asBadRequest(error) {
|
|
16849
17143
|
if (error instanceof CliError) {
|
|
16850
17144
|
throw new ORPCError6("BAD_REQUEST", { message: error.message });
|
|
@@ -17230,11 +17524,11 @@ function createDoorHealthPublisher(hub, now, pid) {
|
|
|
17230
17524
|
|
|
17231
17525
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
17232
17526
|
init_schema2();
|
|
17233
|
-
var
|
|
17527
|
+
var MS_PER_HOUR5 = 36e5;
|
|
17234
17528
|
var MS_PER_DAY2 = 864e5;
|
|
17235
17529
|
var FIVE_HOUR_WINDOW_HOURS = 5;
|
|
17236
17530
|
var SEVEN_DAY_WINDOW_DAYS = 7;
|
|
17237
|
-
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS *
|
|
17531
|
+
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS * MS_PER_HOUR5;
|
|
17238
17532
|
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS * MS_PER_DAY2;
|
|
17239
17533
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
17240
17534
|
var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
|
|
@@ -17927,7 +18221,7 @@ async function serveRcConversations(ctx, pathname, method) {
|
|
|
17927
18221
|
var RC_SELF_HOST_OAUTH_HOST = "platform.claude.com";
|
|
17928
18222
|
var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:claude_code", "user:mcp_servers", "user:file_upload"];
|
|
17929
18223
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
17930
|
-
var
|
|
18224
|
+
var MS_PER_SECOND6 = 1e3;
|
|
17931
18225
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
17932
18226
|
function isRecord12(value) {
|
|
17933
18227
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -17983,7 +18277,7 @@ function createRcSelfHostLocal(deps) {
|
|
|
17983
18277
|
}
|
|
17984
18278
|
if (method === "POST" && pathname.startsWith("/api/eval/")) {
|
|
17985
18279
|
await deps.readBody(request4, CONTROL_BODY_CAP_BYTES);
|
|
17986
|
-
answerServerJson(response, HTTP_STATUS.ok, { features: growthBookFeatures(), dateUpdated: Math.floor(deps.now() /
|
|
18280
|
+
answerServerJson(response, HTTP_STATUS.ok, { features: growthBookFeatures(), dateUpdated: Math.floor(deps.now() / MS_PER_SECOND6) });
|
|
17987
18281
|
return true;
|
|
17988
18282
|
}
|
|
17989
18283
|
if (method === "GET" && pathname === "/api/oauth/profile") {
|
|
@@ -18282,7 +18576,7 @@ var RC_COMPAT_SESSIONS_PATH = "/v1/sessions";
|
|
|
18282
18576
|
var RC_SESSION_ID_PREFIX2 = "cse_";
|
|
18283
18577
|
var RC_SELF_HOST_API_BASE_URL = "https://api.anthropic.com";
|
|
18284
18578
|
var HTTP_CONFLICT = 409;
|
|
18285
|
-
var
|
|
18579
|
+
var MS_PER_SECOND7 = 1e3;
|
|
18286
18580
|
var HTTP_SERVICE_UNAVAILABLE2 = 503;
|
|
18287
18581
|
var RC_SELF_HOST_WORKER_JWT_TTL_SECONDS = 46800;
|
|
18288
18582
|
var RC_SELF_HOST_KEEPALIVE_MS = 15e3;
|
|
@@ -18382,7 +18676,7 @@ function parseJsonObject5(body) {
|
|
|
18382
18676
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
18383
18677
|
const encode = (value) => Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
|
|
18384
18678
|
const header = encode({ alg: "HS256", typ: "JWT" });
|
|
18385
|
-
const payload = encode({ exp: Math.floor((issuedAt + RC_SELF_HOST_WORKER_JWT_TTL_SECONDS *
|
|
18679
|
+
const payload = encode({ exp: Math.floor((issuedAt + RC_SELF_HOST_WORKER_JWT_TTL_SECONDS * MS_PER_SECOND7) / MS_PER_SECOND7), iat: Math.floor(issuedAt / MS_PER_SECOND7) });
|
|
18386
18680
|
return `${header}.${payload}.${Buffer.from(randomToken(), "utf8").toString("base64url")}`;
|
|
18387
18681
|
}
|
|
18388
18682
|
function createRcSelfHostSurface(deps) {
|
|
@@ -18926,7 +19220,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
18926
19220
|
|
|
18927
19221
|
// src/frontdoor/rcSelfHostMint.ts
|
|
18928
19222
|
init_account();
|
|
18929
|
-
import
|
|
19223
|
+
import path34 from "node:path";
|
|
18930
19224
|
var CREDENTIALS_FILE2 = ".credentials.json";
|
|
18931
19225
|
var CLAUDE_JSON2 = ".claude.json";
|
|
18932
19226
|
var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
@@ -18950,7 +19244,7 @@ function readJsonObject(fs13, file) {
|
|
|
18950
19244
|
return isRecord14(parsed) ? parsed : void 0;
|
|
18951
19245
|
}
|
|
18952
19246
|
function readRcSelfHostRecord(fs13, frontdoorDir) {
|
|
18953
|
-
const parsed = readJsonObject(fs13,
|
|
19247
|
+
const parsed = readJsonObject(fs13, path34.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
18954
19248
|
if (parsed === void 0) {
|
|
18955
19249
|
return void 0;
|
|
18956
19250
|
}
|
|
@@ -18964,11 +19258,11 @@ function mintRcSelfHostCredential(deps) {
|
|
|
18964
19258
|
if (!isIdentityName(deps.identity)) {
|
|
18965
19259
|
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
18966
19260
|
}
|
|
18967
|
-
const identityDir =
|
|
18968
|
-
const credentialsFile =
|
|
18969
|
-
const claudeJsonFile =
|
|
18970
|
-
const recordDir =
|
|
18971
|
-
const recordFile =
|
|
19261
|
+
const identityDir = path34.join(deps.identitiesDir, deps.identity);
|
|
19262
|
+
const credentialsFile = path34.join(identityDir, CREDENTIALS_FILE2);
|
|
19263
|
+
const claudeJsonFile = path34.join(identityDir, CLAUDE_JSON2);
|
|
19264
|
+
const recordDir = path34.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
19265
|
+
const recordFile = path34.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
18972
19266
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
18973
19267
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
18974
19268
|
const existingOauth = isRecord14(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
@@ -18984,7 +19278,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
18984
19278
|
const organizationUuid = deps.newUuid();
|
|
18985
19279
|
const accountUuid = deps.newUuid();
|
|
18986
19280
|
const mintedAt = new Date(deps.now()).toISOString();
|
|
18987
|
-
deps.fs.mkdirPrivate(
|
|
19281
|
+
deps.fs.mkdirPrivate(path34.dirname(credentialsFile));
|
|
18988
19282
|
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)}
|
|
18989
19283
|
`);
|
|
18990
19284
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
@@ -19026,8 +19320,8 @@ init_plan2();
|
|
|
19026
19320
|
init_poolPick();
|
|
19027
19321
|
|
|
19028
19322
|
// src/agents/read.ts
|
|
19029
|
-
import
|
|
19030
|
-
import { z as
|
|
19323
|
+
import path35 from "node:path";
|
|
19324
|
+
import { z as z30 } from "zod";
|
|
19031
19325
|
var PROJECTS_DIR = "projects";
|
|
19032
19326
|
var TASKS_DIR = "tasks";
|
|
19033
19327
|
var SUBAGENTS_DIR = "subagents";
|
|
@@ -19052,15 +19346,15 @@ function parseEntry2(project, entry) {
|
|
|
19052
19346
|
}
|
|
19053
19347
|
function listSessions2(fs13, configDir) {
|
|
19054
19348
|
const found = [];
|
|
19055
|
-
for (const project of fs13.readdir(
|
|
19056
|
-
const projectDir =
|
|
19349
|
+
for (const project of fs13.readdir(path35.join(configDir, PROJECTS_DIR))) {
|
|
19350
|
+
const projectDir = path35.join(configDir, PROJECTS_DIR, project);
|
|
19057
19351
|
const entries = /* @__PURE__ */ new Set();
|
|
19058
19352
|
for (const name of fs13.readdir(projectDir)) {
|
|
19059
19353
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
19060
19354
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
19061
19355
|
continue;
|
|
19062
19356
|
}
|
|
19063
|
-
const children = fs13.readdir(
|
|
19357
|
+
const children = fs13.readdir(path35.join(projectDir, name));
|
|
19064
19358
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
19065
19359
|
entries.add(name);
|
|
19066
19360
|
}
|
|
@@ -19080,8 +19374,8 @@ function locateAgents(fs13, configDir, relativeDir, workflowRunId, report) {
|
|
|
19080
19374
|
const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
|
|
19081
19375
|
located.push({
|
|
19082
19376
|
id,
|
|
19083
|
-
metaPath:
|
|
19084
|
-
transcriptPath:
|
|
19377
|
+
metaPath: path35.join(relativeDir, name),
|
|
19378
|
+
transcriptPath: path35.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
|
|
19085
19379
|
workflowRunId
|
|
19086
19380
|
});
|
|
19087
19381
|
}
|
|
@@ -19124,7 +19418,7 @@ function describeFailure(error) {
|
|
|
19124
19418
|
}
|
|
19125
19419
|
function readFileOrReport(fs13, configDir, relative, report) {
|
|
19126
19420
|
try {
|
|
19127
|
-
return fs13.readFileUtf8(
|
|
19421
|
+
return fs13.readFileUtf8(path35.join(configDir, relative));
|
|
19128
19422
|
} catch (error) {
|
|
19129
19423
|
report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
|
|
19130
19424
|
return void 0;
|
|
@@ -19132,7 +19426,7 @@ function readFileOrReport(fs13, configDir, relative, report) {
|
|
|
19132
19426
|
}
|
|
19133
19427
|
function listDirOrReport(fs13, configDir, relative, report) {
|
|
19134
19428
|
try {
|
|
19135
|
-
return fs13.readdir(
|
|
19429
|
+
return fs13.readdir(path35.join(configDir, relative));
|
|
19136
19430
|
} catch (error) {
|
|
19137
19431
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
|
|
19138
19432
|
return [];
|
|
@@ -19146,28 +19440,28 @@ function parseJson2(text) {
|
|
|
19146
19440
|
return void 0;
|
|
19147
19441
|
}
|
|
19148
19442
|
}
|
|
19149
|
-
var TaskFileSchema =
|
|
19150
|
-
var WorkflowRunFileSchema =
|
|
19151
|
-
runId:
|
|
19152
|
-
workflowName:
|
|
19153
|
-
status:
|
|
19154
|
-
startTime:
|
|
19155
|
-
phases:
|
|
19156
|
-
summary:
|
|
19443
|
+
var TaskFileSchema = z30.object({ ...TaskItemSchema.omit({ taskList: true }).shape, blocks: z30.array(z30.string()).default([]), blockedBy: z30.array(z30.string()).default([]) });
|
|
19444
|
+
var WorkflowRunFileSchema = z30.object({
|
|
19445
|
+
runId: z30.string(),
|
|
19446
|
+
workflowName: z30.string().optional(),
|
|
19447
|
+
status: z30.string().optional(),
|
|
19448
|
+
startTime: z30.number().optional(),
|
|
19449
|
+
phases: z30.array(z30.object({ title: z30.string() })).default([]),
|
|
19450
|
+
summary: z30.string().optional()
|
|
19157
19451
|
});
|
|
19158
19452
|
function summariseSession(fs13, configDir, ref) {
|
|
19159
|
-
const sessionRelative =
|
|
19160
|
-
const subagentsRelative =
|
|
19161
|
-
const workflowsUnderSubagents =
|
|
19453
|
+
const sessionRelative = path35.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
19454
|
+
const subagentsRelative = path35.join(sessionRelative, SUBAGENTS_DIR);
|
|
19455
|
+
const workflowsUnderSubagents = path35.join(subagentsRelative, WORKFLOWS_DIR);
|
|
19162
19456
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
19163
|
-
let agentCount = fs13.readdir(
|
|
19164
|
-
for (const runDir of fs13.readdir(
|
|
19457
|
+
let agentCount = fs13.readdir(path35.join(configDir, subagentsRelative)).filter(isMeta).length;
|
|
19458
|
+
for (const runDir of fs13.readdir(path35.join(configDir, workflowsUnderSubagents))) {
|
|
19165
19459
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
19166
|
-
agentCount += fs13.readdir(
|
|
19460
|
+
agentCount += fs13.readdir(path35.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
19167
19461
|
}
|
|
19168
19462
|
}
|
|
19169
|
-
const workflowRunCount = fs13.readdir(
|
|
19170
|
-
const transcript = fs13.lstat(
|
|
19463
|
+
const workflowRunCount = fs13.readdir(path35.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
|
|
19464
|
+
const transcript = fs13.lstat(path35.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
|
|
19171
19465
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
19172
19466
|
}
|
|
19173
19467
|
function readSessionAgentTree(fs13, configDir, ref, options = {}) {
|
|
@@ -19175,13 +19469,13 @@ function readSessionAgentTree(fs13, configDir, ref, options = {}) {
|
|
|
19175
19469
|
const report = (problem) => {
|
|
19176
19470
|
problems.push(problem);
|
|
19177
19471
|
};
|
|
19178
|
-
const sessionRelative =
|
|
19179
|
-
const subagentsRelative =
|
|
19180
|
-
const workflowsUnderSubagents =
|
|
19472
|
+
const sessionRelative = path35.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
19473
|
+
const subagentsRelative = path35.join(sessionRelative, SUBAGENTS_DIR);
|
|
19474
|
+
const workflowsUnderSubagents = path35.join(subagentsRelative, WORKFLOWS_DIR);
|
|
19181
19475
|
const located = locateAgents(fs13, configDir, subagentsRelative, void 0, report);
|
|
19182
19476
|
for (const runDir of listDirOrReport(fs13, configDir, workflowsUnderSubagents, report)) {
|
|
19183
19477
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
19184
|
-
located.push(...locateAgents(fs13, configDir,
|
|
19478
|
+
located.push(...locateAgents(fs13, configDir, path35.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
19185
19479
|
}
|
|
19186
19480
|
}
|
|
19187
19481
|
const agents = /* @__PURE__ */ new Map();
|
|
@@ -19222,7 +19516,7 @@ function readSessionAgentTree(fs13, configDir, ref, options = {}) {
|
|
|
19222
19516
|
superseded: ref.superseded,
|
|
19223
19517
|
agents: roots.sort().map(build),
|
|
19224
19518
|
tasks: readTasks(fs13, configDir, ownTaskLists(ref.sessionId), [.../* @__PURE__ */ new Set([...teamNames, ...options.taskListIds ?? []])].filter((id) => !ownTaskLists(ref.sessionId).includes(id)), report),
|
|
19225
|
-
workflowRuns: readWorkflowRuns(fs13, configDir,
|
|
19519
|
+
workflowRuns: readWorkflowRuns(fs13, configDir, path35.join(sessionRelative, WORKFLOWS_DIR), report),
|
|
19226
19520
|
problems
|
|
19227
19521
|
};
|
|
19228
19522
|
}
|
|
@@ -19287,12 +19581,12 @@ function ownTaskLists(sessionId) {
|
|
|
19287
19581
|
function readTasks(fs13, configDir, ownLists, sharedLists, report) {
|
|
19288
19582
|
const tasks = [];
|
|
19289
19583
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
19290
|
-
const relativeDir =
|
|
19584
|
+
const relativeDir = path35.join(TASKS_DIR, scope);
|
|
19291
19585
|
for (const name of [...listDirOrReport(fs13, configDir, relativeDir, report)].sort()) {
|
|
19292
19586
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
19293
19587
|
continue;
|
|
19294
19588
|
}
|
|
19295
|
-
const relative =
|
|
19589
|
+
const relative = path35.join(relativeDir, name);
|
|
19296
19590
|
const text = readFileOrReport(fs13, configDir, relative, report);
|
|
19297
19591
|
const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
19298
19592
|
if (parsed.success) {
|
|
@@ -19310,7 +19604,7 @@ function readWorkflowRuns(fs13, configDir, relativeDir, report) {
|
|
|
19310
19604
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
19311
19605
|
continue;
|
|
19312
19606
|
}
|
|
19313
|
-
const relative =
|
|
19607
|
+
const relative = path35.join(relativeDir, name);
|
|
19314
19608
|
const text = readFileOrReport(fs13, configDir, relative, report);
|
|
19315
19609
|
const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
19316
19610
|
if (!parsed.success) {
|
|
@@ -19327,7 +19621,7 @@ function readWorkflowRuns(fs13, configDir, relativeDir, report) {
|
|
|
19327
19621
|
|
|
19328
19622
|
// src/agents/sessions.ts
|
|
19329
19623
|
init_cliError();
|
|
19330
|
-
import
|
|
19624
|
+
import path36 from "node:path";
|
|
19331
19625
|
var SessionLookupError = class extends CliError {
|
|
19332
19626
|
constructor(message) {
|
|
19333
19627
|
super(message);
|
|
@@ -19335,13 +19629,13 @@ var SessionLookupError = class extends CliError {
|
|
|
19335
19629
|
}
|
|
19336
19630
|
};
|
|
19337
19631
|
function identityConfigDir(identitiesDir, identity) {
|
|
19338
|
-
return
|
|
19632
|
+
return path36.join(identitiesDir, identity);
|
|
19339
19633
|
}
|
|
19340
19634
|
function historyStores(fs13, identitiesDir, identities) {
|
|
19341
19635
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
19342
19636
|
for (const identity of identities) {
|
|
19343
19637
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
19344
|
-
const real = fs13.realpath(
|
|
19638
|
+
const real = fs13.realpath(path36.join(configDir, "projects"));
|
|
19345
19639
|
if (real === void 0) {
|
|
19346
19640
|
continue;
|
|
19347
19641
|
}
|