claude-use 11.40.5 → 11.41.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 +261 -30
- package/dist/index.cjs +1409 -1184
- package/dist/index.mjs +1765 -1540
- package/dist/types/index.d.ts +363 -0
- 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({
|
|
@@ -3082,7 +3122,7 @@ var init_package = __esm({
|
|
|
3082
3122
|
"package.json"() {
|
|
3083
3123
|
package_default = {
|
|
3084
3124
|
name: "claude-use",
|
|
3085
|
-
version: "11.
|
|
3125
|
+
version: "11.41.0",
|
|
3086
3126
|
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
3127
|
license: "MIT",
|
|
3088
3128
|
author: "Joseph Mearman <joseph@mearman.co.uk>",
|
|
@@ -7575,1446 +7615,1532 @@ var init_modelsStore = __esm({
|
|
|
7575
7615
|
}
|
|
7576
7616
|
});
|
|
7577
7617
|
|
|
7578
|
-
// src/
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
refuseToBlockInRole("a synchronous probe of the front door");
|
|
7582
|
-
return runProbeWorker(PROBE_SOURCE, { port, ca: caPem });
|
|
7618
|
+
// src/models/identity.ts
|
|
7619
|
+
function withoutContextMarker(model) {
|
|
7620
|
+
return model.toLowerCase().endsWith(CONTEXT_MARKER_1M) ? model.slice(0, -CONTEXT_MARKER_1M.length) : model;
|
|
7583
7621
|
}
|
|
7584
|
-
function
|
|
7585
|
-
|
|
7586
|
-
return runProbeWorker(ACCEPT_PROBE_SOURCE, { port });
|
|
7622
|
+
function canonicalText(name) {
|
|
7623
|
+
return name.trim().toLowerCase().replace(NON_IDENTITY_BRACKET_RE, "").replace(/[\s_]+/g, "-").replace(/([a-z])(\d+(?:\.\d+)+)/g, "$1-$2").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
7587
7624
|
}
|
|
7588
|
-
function
|
|
7589
|
-
const
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
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` };
|
|
7625
|
+
function splitVariants(tokens) {
|
|
7626
|
+
const variants = [];
|
|
7627
|
+
let end = tokens.length;
|
|
7628
|
+
for (; ; ) {
|
|
7629
|
+
const token = tokens[end - 1];
|
|
7630
|
+
if (token === void 0 || !KNOWN_VARIANTS.has(token)) {
|
|
7631
|
+
return { familyTokens: tokens.slice(0, end), variants };
|
|
7601
7632
|
}
|
|
7602
|
-
|
|
7603
|
-
|
|
7633
|
+
variants.unshift(token);
|
|
7634
|
+
end -= 1;
|
|
7635
|
+
}
|
|
7636
|
+
}
|
|
7637
|
+
function versionOf(tokens) {
|
|
7638
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
7639
|
+
const token = tokens[index];
|
|
7640
|
+
const next = tokens[index + 1];
|
|
7641
|
+
if (token === void 0) {
|
|
7642
|
+
return "";
|
|
7643
|
+
}
|
|
7644
|
+
if (/^\d+$/.test(token) && next !== void 0 && /^\d+$/.test(next)) {
|
|
7645
|
+
return `${token}.${next}`;
|
|
7646
|
+
}
|
|
7647
|
+
const dotted = /^\d+(?:\.\d+)+$/.exec(token);
|
|
7648
|
+
if (dotted !== null) {
|
|
7649
|
+
return dotted[0];
|
|
7604
7650
|
}
|
|
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
7651
|
}
|
|
7652
|
+
return "";
|
|
7610
7653
|
}
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
"
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7625
|
-
const
|
|
7626
|
-
|
|
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));
|
|
7654
|
+
function modelIdentity(rawName) {
|
|
7655
|
+
const segments = rawName.trim().toLowerCase().split("/");
|
|
7656
|
+
const stripped = canonicalText(segments[segments.length - 1] ?? "").split(":")[0] ?? "";
|
|
7657
|
+
const withoutDate = stripped.replace(DATE_STAMP_RE, "");
|
|
7658
|
+
const tokens = withoutDate.split("-").filter((token) => token !== "");
|
|
7659
|
+
const { familyTokens, variants } = splitVariants(tokens);
|
|
7660
|
+
const version = versionOf(familyTokens);
|
|
7661
|
+
const versionless = familyTokens.filter((token, index) => {
|
|
7662
|
+
if (version === "") {
|
|
7663
|
+
return true;
|
|
7664
|
+
}
|
|
7665
|
+
const dotted = /^\d+(?:\.\d+)+$/.test(token);
|
|
7666
|
+
const previous = familyTokens[index - 1];
|
|
7667
|
+
const next = familyTokens[index + 1];
|
|
7668
|
+
const insideVersionRun = dotted || /^\d+$/.test(token) && (previous !== void 0 && /^\d+$/.test(previous) || next !== void 0 && /^\d+$/.test(next));
|
|
7669
|
+
return !insideVersionRun;
|
|
7647
7670
|
});
|
|
7648
|
-
|
|
7671
|
+
const family = versionless.join("-");
|
|
7672
|
+
const tokenVendor = familyTokens.find((token) => Object.keys(VENDOR_BY_TOKEN).some((key) => token === key || token.startsWith(key)));
|
|
7673
|
+
const namespace = segments.length >= 2 ? (segments[0] ?? "").split(":").pop() ?? "" : "";
|
|
7674
|
+
const namespaceVendor = VENDOR_BY_NAMESPACE[namespace] ?? "";
|
|
7675
|
+
const tokenVendorName = tokenVendor === void 0 ? "" : VENDOR_BY_TOKEN[Object.keys(VENDOR_BY_TOKEN).find((key) => tokenVendor === key || tokenVendor.startsWith(key)) ?? ""] ?? "";
|
|
7676
|
+
return {
|
|
7677
|
+
vendor: tokenVendorName === "" ? namespaceVendor : tokenVendorName,
|
|
7678
|
+
vendorConflict: tokenVendorName !== "" && namespaceVendor !== "" && tokenVendorName !== namespaceVendor,
|
|
7679
|
+
family,
|
|
7680
|
+
version,
|
|
7681
|
+
variant: variants.join("-"),
|
|
7682
|
+
familyAndVersion: version === "" ? family : `${family}-${version.replace(/\./g, "-")}`
|
|
7683
|
+
};
|
|
7684
|
+
}
|
|
7685
|
+
function relateModels(left, right) {
|
|
7686
|
+
const a = modelIdentity(left);
|
|
7687
|
+
const b = modelIdentity(right);
|
|
7688
|
+
if (a.familyAndVersion !== b.familyAndVersion) {
|
|
7689
|
+
return sameFamilyOtherVersion(a, b) ? "similar" : "distinct";
|
|
7690
|
+
}
|
|
7691
|
+
if (a.variant !== b.variant || a.vendorConflict || b.vendorConflict || a.vendor !== "" && b.vendor !== "" && a.vendor !== b.vendor) {
|
|
7692
|
+
return "similar";
|
|
7693
|
+
}
|
|
7694
|
+
return "same";
|
|
7695
|
+
}
|
|
7696
|
+
function sameFamilyOtherVersion(a, b) {
|
|
7697
|
+
if (a.family !== b.family) {
|
|
7698
|
+
return false;
|
|
7699
|
+
}
|
|
7700
|
+
if (a.vendor !== "" && b.vendor !== "" && a.vendor !== b.vendor) {
|
|
7701
|
+
return false;
|
|
7702
|
+
}
|
|
7703
|
+
return true;
|
|
7704
|
+
}
|
|
7705
|
+
var NON_IDENTITY_BRACKET_RE, CONTEXT_MARKER_1M, DATE_STAMP_RE, KNOWN_VARIANTS, VENDOR_BY_NAMESPACE, VENDOR_BY_TOKEN;
|
|
7706
|
+
var init_identity2 = __esm({
|
|
7707
|
+
"src/models/identity.ts"() {
|
|
7708
|
+
"use strict";
|
|
7709
|
+
NON_IDENTITY_BRACKET_RE = /\[[^\]]*\]/g;
|
|
7710
|
+
CONTEXT_MARKER_1M = "[1m]";
|
|
7711
|
+
DATE_STAMP_RE = /-(?:19|20)\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])$/;
|
|
7712
|
+
KNOWN_VARIANTS = /* @__PURE__ */ new Set(["high", "medium", "low", "thinking", "xhigh", "max", "highspeed", "sol", "terra", "luna", "mini", "flash-lite", "turbo"]);
|
|
7713
|
+
VENDOR_BY_NAMESPACE = Object.freeze({
|
|
7714
|
+
anthropic: "anthropic",
|
|
7715
|
+
google: "google",
|
|
7716
|
+
openai: "openai",
|
|
7717
|
+
zai: "zai",
|
|
7718
|
+
"z-ai": "zai",
|
|
7719
|
+
minimax: "minimax",
|
|
7720
|
+
qwen: "qwen",
|
|
7721
|
+
deepseek: "deepseek",
|
|
7722
|
+
moonshot: "moonshot",
|
|
7723
|
+
meta: "meta",
|
|
7724
|
+
mistral: "mistral"
|
|
7725
|
+
});
|
|
7726
|
+
VENDOR_BY_TOKEN = Object.freeze({
|
|
7727
|
+
claude: "anthropic",
|
|
7728
|
+
gemini: "google",
|
|
7729
|
+
antigravity: "google",
|
|
7730
|
+
gpt: "openai",
|
|
7731
|
+
glm: "zai",
|
|
7732
|
+
minimax: "minimax",
|
|
7733
|
+
qwen: "qwen",
|
|
7734
|
+
deepseek: "deepseek",
|
|
7735
|
+
kimi: "moonshot",
|
|
7736
|
+
llama: "meta",
|
|
7737
|
+
mistral: "mistral",
|
|
7738
|
+
mixtral: "mistral"
|
|
7739
|
+
});
|
|
7740
|
+
}
|
|
7649
7741
|
});
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
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
|
-
`;
|
|
7742
|
+
|
|
7743
|
+
// src/selection/engine.ts
|
|
7744
|
+
var init_engine = __esm({
|
|
7745
|
+
"src/selection/engine.ts"() {
|
|
7746
|
+
"use strict";
|
|
7675
7747
|
}
|
|
7676
7748
|
});
|
|
7677
7749
|
|
|
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"() {
|
|
7750
|
+
// src/antigravity/cloudUpstream.ts
|
|
7751
|
+
var init_cloudUpstream = __esm({
|
|
7752
|
+
"src/antigravity/cloudUpstream.ts"() {
|
|
7699
7753
|
"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
7754
|
}
|
|
7721
7755
|
});
|
|
7722
7756
|
|
|
7723
|
-
// src/
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
).length;
|
|
7736
|
-
const verifyWithRetry = (port) => {
|
|
7737
|
-
let verdict = ports.verifyListener(port);
|
|
7738
|
-
for (let attempt = 1; !verdict.ok && attempt < FRONTDOOR_PROBE_ATTEMPTS; attempt += 1) {
|
|
7739
|
-
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
7740
|
-
verdict = ports.verifyListener(port);
|
|
7741
|
-
}
|
|
7742
|
-
return verdict;
|
|
7743
|
-
};
|
|
7744
|
-
const stopAndAwaitExit = (supervisorPid, failure) => {
|
|
7745
|
-
ports.stopSupervisor(supervisorPid);
|
|
7746
|
-
const graceEnds = ports.now() + FRONTDOOR_EXIT_GRACE_MS;
|
|
7747
|
-
let killed = false;
|
|
7748
|
-
while (ports.isRunning(supervisorPid)) {
|
|
7749
|
-
if (!killed && ports.now() >= graceEnds) {
|
|
7750
|
-
ports.killSupervisor(supervisorPid);
|
|
7751
|
-
killed = true;
|
|
7752
|
-
}
|
|
7753
|
-
if (ports.now() >= deadline) {
|
|
7754
|
-
throw new FrontDoorStartError(`${failure}. Daemon log: ${paths.frontdoorLogPath}`);
|
|
7755
|
-
}
|
|
7756
|
-
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
7757
|
-
}
|
|
7758
|
-
};
|
|
7759
|
-
for (; ; ) {
|
|
7760
|
-
const state = readFrontDoorState(ports.fs, paths.frontdoorStateFile);
|
|
7761
|
-
const supervisorPid = state?.supervisorPid;
|
|
7762
|
-
if (supervisorPid !== void 0 && !distrusted.has(supervisorPid) && ports.isRunning(supervisorPid)) {
|
|
7763
|
-
if (state?.port !== void 0 && state.connectPort !== void 0) {
|
|
7764
|
-
if (supervisorPid === params.launcherPid && params.replace !== true && ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
7765
|
-
const token = randomUUID3();
|
|
7766
|
-
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid });
|
|
7767
|
-
return { port: state.port, connectPort: state.connectPort, token };
|
|
7768
|
-
}
|
|
7769
|
-
const verdict = verifyWithRetry(state.port);
|
|
7770
|
-
if (verdict.ok && !replaced && !spawned && (params.replace === true || (state.protocol ?? 0) < FRONT_DOOR_PROTOCOL)) {
|
|
7771
|
-
stopAndAwaitExit(
|
|
7772
|
-
supervisorPid,
|
|
7773
|
-
`the front door (pid ${String(supervisorPid)}, protocol ${String(state.protocol ?? 0)}; this launcher speaks protocol ${String(FRONT_DOOR_PROTOCOL)}) was asked to be replaced and did not exit`
|
|
7774
|
-
);
|
|
7775
|
-
replaced = true;
|
|
7776
|
-
continue;
|
|
7777
|
-
}
|
|
7778
|
-
if (verdict.ok) {
|
|
7779
|
-
const token = randomUUID3();
|
|
7780
|
-
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid });
|
|
7781
|
-
return { port: state.port, connectPort: state.connectPort, token };
|
|
7782
|
-
}
|
|
7783
|
-
lastRejection = `the listener on 127.0.0.1:${String(state.port)} (recorded for pid ${String(supervisorPid)}) failed authentication: ${verdict.reason}`;
|
|
7784
|
-
if (spawned) {
|
|
7785
|
-
throw new FrontDoorStartError(`${lastRejection}; refusing to send this session's credentials to it. Daemon log: ${paths.frontdoorLogPath}`);
|
|
7786
|
-
}
|
|
7787
|
-
if (ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
7788
|
-
const stranded = liveSessionsOn(supervisorPid);
|
|
7789
|
-
if (params.replace === true && !replaced) {
|
|
7790
|
-
stopAndAwaitExit(supervisorPid, `the front door (pid ${String(supervisorPid)}) stopped answering and did not exit when asked to`);
|
|
7791
|
-
replaced = true;
|
|
7792
|
-
continue;
|
|
7793
|
-
}
|
|
7794
|
-
if (stranded > 0) {
|
|
7795
|
-
busyDoor = { pid: supervisorPid, sessions: stranded };
|
|
7796
|
-
} else {
|
|
7797
|
-
stopAndAwaitExit(supervisorPid, `the front door (pid ${String(supervisorPid)}) stopped answering and did not exit when asked to`);
|
|
7798
|
-
continue;
|
|
7799
|
-
}
|
|
7800
|
-
} else {
|
|
7801
|
-
distrusted.add(supervisorPid);
|
|
7802
|
-
continue;
|
|
7803
|
-
}
|
|
7804
|
-
}
|
|
7805
|
-
if (state?.lastError !== void 0) {
|
|
7806
|
-
throw new FrontDoorStartError(`the front door reported a fatal error and is not serving: ${state.lastError} (daemon log: ${paths.frontdoorLogPath})`);
|
|
7807
|
-
}
|
|
7808
|
-
} else if (!spawned) {
|
|
7809
|
-
ports.fs.mkdirp(paths.frontdoorDir);
|
|
7810
|
-
const created = ports.fs.writeFileExclusive(paths.frontdoorLockFile, `${JSON.stringify({ pid: params.launcherPid, at: ports.now() })}
|
|
7811
|
-
`);
|
|
7812
|
-
if (created) {
|
|
7813
|
-
ports.spawnSupervisor(paths);
|
|
7814
|
-
spawned = true;
|
|
7815
|
-
} else {
|
|
7816
|
-
const lock = readStartLock(ports.fs, paths.frontdoorLockFile);
|
|
7817
|
-
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
7818
|
-
ports.fs.removeRecursive(paths.frontdoorLockFile);
|
|
7819
|
-
continue;
|
|
7820
|
-
}
|
|
7821
|
-
}
|
|
7822
|
-
}
|
|
7823
|
-
if (ports.now() >= deadline) {
|
|
7824
|
-
const lastError = state?.lastError;
|
|
7825
|
-
throw new FrontDoorStartError(
|
|
7826
|
-
`the front door did not become ready within ${String(FRONTDOOR_START_TIMEOUT_MS)}ms` + (lastError === void 0 ? "" : ` (last error: ${lastError})`) + (lastRejection === void 0 ? "" : ` (${lastRejection})`) + (busyDoor === void 0 ? "" : `. It was not replaced because ${String(busyDoor.sessions)} live session(s) are using it and would lose their connections; run \`agent-shim frontdoor restart\` to replace it deliberately`) + `. Daemon log: ${paths.frontdoorLogPath}`
|
|
7827
|
-
);
|
|
7828
|
-
}
|
|
7829
|
-
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
7757
|
+
// src/antigravity/quota.ts
|
|
7758
|
+
var SECONDS_PER_HOUR, HOURS_PER_FIVE_HOUR_WINDOW, DAYS_PER_WEEK, HOURS_PER_DAY4, FIVE_HOUR_PERIOD_SECONDS, WEEK_PERIOD_SECONDS;
|
|
7759
|
+
var init_quota = __esm({
|
|
7760
|
+
"src/antigravity/quota.ts"() {
|
|
7761
|
+
"use strict";
|
|
7762
|
+
init_cloudUpstream();
|
|
7763
|
+
SECONDS_PER_HOUR = 3600;
|
|
7764
|
+
HOURS_PER_FIVE_HOUR_WINDOW = 5;
|
|
7765
|
+
DAYS_PER_WEEK = 7;
|
|
7766
|
+
HOURS_PER_DAY4 = 24;
|
|
7767
|
+
FIVE_HOUR_PERIOD_SECONDS = HOURS_PER_FIVE_HOUR_WINDOW * SECONDS_PER_HOUR;
|
|
7768
|
+
WEEK_PERIOD_SECONDS = DAYS_PER_WEEK * HOURS_PER_DAY4 * SECONDS_PER_HOUR;
|
|
7830
7769
|
}
|
|
7831
|
-
}
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
|
|
7770
|
+
});
|
|
7771
|
+
|
|
7772
|
+
// src/antigravity/signatures.ts
|
|
7773
|
+
var init_signatures = __esm({
|
|
7774
|
+
"src/antigravity/signatures.ts"() {
|
|
7835
7775
|
"use strict";
|
|
7836
|
-
init_cliError();
|
|
7837
|
-
init_state2();
|
|
7838
|
-
init_state();
|
|
7839
|
-
FRONTDOOR_START_TIMEOUT_MS = 3e4;
|
|
7840
|
-
FRONTDOOR_LAUNCHER_POLL_MS = 100;
|
|
7841
|
-
FRONTDOOR_PROBE_ATTEMPTS = 3;
|
|
7842
|
-
FRONTDOOR_EXIT_GRACE_MS = 5e3;
|
|
7843
|
-
FrontDoorStartError = class extends CliError {
|
|
7844
|
-
constructor(message) {
|
|
7845
|
-
super(message);
|
|
7846
|
-
this.name = "FrontDoorStartError";
|
|
7847
|
-
}
|
|
7848
|
-
};
|
|
7849
7776
|
}
|
|
7850
7777
|
});
|
|
7851
7778
|
|
|
7852
|
-
// src/
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
}
|
|
7779
|
+
// src/codex/anthropic.ts
|
|
7780
|
+
import { z as z23 } from "zod";
|
|
7781
|
+
var TextBlockSchema, Base64ImageSourceSchema, UrlImageSourceSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultContentBlockSchema, ToolResultBlockSchema, OtherBlockSchema, ContentBlockSchema, MessageSchema, ToolSchema, ToolChoiceSchema, SystemSchema, MessagesRequestSchema, CountTokensRequestSchema;
|
|
7782
|
+
var init_anthropic = __esm({
|
|
7783
|
+
"src/codex/anthropic.ts"() {
|
|
7784
|
+
"use strict";
|
|
7785
|
+
TextBlockSchema = z23.looseObject({ type: z23.literal("text"), text: z23.string() });
|
|
7786
|
+
Base64ImageSourceSchema = z23.looseObject({ type: z23.literal("base64"), media_type: z23.string().min(1), data: z23.string() });
|
|
7787
|
+
UrlImageSourceSchema = z23.looseObject({ type: z23.literal("url"), url: z23.string().min(1) });
|
|
7788
|
+
ImageBlockSchema = z23.looseObject({
|
|
7789
|
+
type: z23.literal("image"),
|
|
7790
|
+
source: z23.union([Base64ImageSourceSchema, UrlImageSourceSchema])
|
|
7791
|
+
});
|
|
7792
|
+
ToolUseBlockSchema = z23.looseObject({
|
|
7793
|
+
type: z23.literal("tool_use"),
|
|
7794
|
+
id: z23.string().min(1),
|
|
7795
|
+
name: z23.string().min(1),
|
|
7796
|
+
input: z23.unknown()
|
|
7797
|
+
});
|
|
7798
|
+
ToolResultContentBlockSchema = z23.union([TextBlockSchema, z23.looseObject({ type: z23.string() })]);
|
|
7799
|
+
ToolResultBlockSchema = z23.looseObject({
|
|
7800
|
+
type: z23.literal("tool_result"),
|
|
7801
|
+
tool_use_id: z23.string().min(1),
|
|
7802
|
+
content: z23.union([z23.string(), z23.array(ToolResultContentBlockSchema)]).optional()
|
|
7803
|
+
});
|
|
7804
|
+
OtherBlockSchema = z23.looseObject({ type: z23.string() });
|
|
7805
|
+
ContentBlockSchema = z23.union([TextBlockSchema, ImageBlockSchema, ToolUseBlockSchema, ToolResultBlockSchema, OtherBlockSchema]);
|
|
7806
|
+
MessageSchema = z23.looseObject({
|
|
7807
|
+
role: z23.enum(["user", "assistant", "system"]),
|
|
7808
|
+
content: z23.union([z23.string(), z23.array(ContentBlockSchema)])
|
|
7809
|
+
});
|
|
7810
|
+
ToolSchema = z23.looseObject({
|
|
7811
|
+
name: z23.string().min(1),
|
|
7812
|
+
description: z23.string().optional(),
|
|
7813
|
+
input_schema: z23.record(z23.string(), z23.unknown()).optional()
|
|
7814
|
+
});
|
|
7815
|
+
ToolChoiceSchema = z23.union([
|
|
7816
|
+
z23.looseObject({ type: z23.enum(["auto", "none", "any"]) }),
|
|
7817
|
+
z23.looseObject({ type: z23.literal("tool"), name: z23.string().min(1) })
|
|
7818
|
+
]);
|
|
7819
|
+
SystemSchema = z23.union([z23.string(), z23.array(z23.union([TextBlockSchema, OtherBlockSchema]))]);
|
|
7820
|
+
MessagesRequestSchema = z23.looseObject({
|
|
7821
|
+
model: z23.string().optional(),
|
|
7822
|
+
system: SystemSchema.optional(),
|
|
7823
|
+
messages: z23.array(MessageSchema),
|
|
7824
|
+
tools: z23.array(ToolSchema).optional(),
|
|
7825
|
+
tool_choice: ToolChoiceSchema.optional(),
|
|
7826
|
+
stream: z23.boolean().optional(),
|
|
7827
|
+
/** `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. */
|
|
7828
|
+
metadata: z23.looseObject({ user_id: z23.string().optional() }).optional(),
|
|
7829
|
+
/** Claude Code's effort setting. Any string is accepted; the translator honours only the levels the backend understands. */
|
|
7830
|
+
output_config: z23.looseObject({ effort: z23.string().optional() }).optional()
|
|
7831
|
+
});
|
|
7832
|
+
CountTokensRequestSchema = z23.looseObject({
|
|
7833
|
+
system: z23.unknown().optional(),
|
|
7834
|
+
messages: z23.unknown().optional(),
|
|
7835
|
+
tools: z23.unknown().optional()
|
|
7836
|
+
});
|
|
7861
7837
|
}
|
|
7862
|
-
|
|
7838
|
+
});
|
|
7839
|
+
|
|
7840
|
+
// src/antigravity/translate.ts
|
|
7841
|
+
function candidatesOf(target) {
|
|
7842
|
+
return typeof target === "string" ? [target] : target;
|
|
7863
7843
|
}
|
|
7864
|
-
function
|
|
7865
|
-
|
|
7866
|
-
if (token === flag) {
|
|
7867
|
-
return { key, value: true };
|
|
7868
|
-
}
|
|
7869
|
-
if (token === `--no-${flag.slice(2)}`) {
|
|
7870
|
-
return { key, value: false };
|
|
7871
|
-
}
|
|
7872
|
-
}
|
|
7873
|
-
return void 0;
|
|
7844
|
+
function isAntigravityTier(key) {
|
|
7845
|
+
return CLAUDE_TIERS.some((tier) => tier === key);
|
|
7874
7846
|
}
|
|
7875
|
-
function
|
|
7876
|
-
const
|
|
7877
|
-
const
|
|
7878
|
-
const
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
let configProfile;
|
|
7882
|
-
let provider;
|
|
7883
|
-
let claudeVersion;
|
|
7884
|
-
let delay;
|
|
7885
|
-
const booleans = {};
|
|
7886
|
-
const categoryFlags = [];
|
|
7887
|
-
const shareFlags = [];
|
|
7888
|
-
const hideFlags = [];
|
|
7889
|
-
const rest = [];
|
|
7890
|
-
for (let index = 0; index < remaining.length; index += 1) {
|
|
7891
|
-
const token = remaining[index];
|
|
7892
|
-
if (token === void 0) {
|
|
7893
|
-
continue;
|
|
7894
|
-
}
|
|
7895
|
-
if (token === TERMINATOR) {
|
|
7896
|
-
rest.push(...remaining.slice(index));
|
|
7897
|
-
break;
|
|
7898
|
-
}
|
|
7899
|
-
if (token === "--no-provider") {
|
|
7900
|
-
provider = false;
|
|
7901
|
-
continue;
|
|
7902
|
-
}
|
|
7903
|
-
if (token === NATIVE_FLAG) {
|
|
7904
|
-
native = true;
|
|
7905
|
-
continue;
|
|
7906
|
-
}
|
|
7907
|
-
const booleanFlag = matchBooleanFlag(token);
|
|
7908
|
-
if (booleanFlag !== void 0) {
|
|
7909
|
-
booleans[booleanFlag.key] = booleanFlag.value;
|
|
7910
|
-
continue;
|
|
7911
|
-
}
|
|
7912
|
-
const matched = matchValuedFlag(token);
|
|
7913
|
-
if (matched === void 0) {
|
|
7914
|
-
rest.push(token);
|
|
7915
|
-
continue;
|
|
7916
|
-
}
|
|
7917
|
-
let value;
|
|
7918
|
-
if (matched.inlineValue !== void 0) {
|
|
7919
|
-
value = matched.inlineValue;
|
|
7920
|
-
} else {
|
|
7921
|
-
const next = remaining[index + 1];
|
|
7922
|
-
if (next === void 0 || next === TERMINATOR) {
|
|
7923
|
-
rest.push(token);
|
|
7924
|
-
continue;
|
|
7925
|
-
}
|
|
7926
|
-
value = next;
|
|
7927
|
-
index += 1;
|
|
7928
|
-
}
|
|
7929
|
-
switch (matched.flag) {
|
|
7930
|
-
case "--identity":
|
|
7931
|
-
flagIdentity = value;
|
|
7932
|
-
break;
|
|
7933
|
-
case "--config-profile":
|
|
7934
|
-
configProfile = value;
|
|
7935
|
-
break;
|
|
7936
|
-
case "--provider":
|
|
7937
|
-
provider = value;
|
|
7938
|
-
break;
|
|
7939
|
-
case "--claude-version":
|
|
7940
|
-
claudeVersion = value;
|
|
7941
|
-
break;
|
|
7942
|
-
case "--delay":
|
|
7943
|
-
delay = value;
|
|
7944
|
-
break;
|
|
7945
|
-
case "--category":
|
|
7946
|
-
categoryFlags.push(value);
|
|
7947
|
-
break;
|
|
7948
|
-
case "--share":
|
|
7949
|
-
shareFlags.push(value);
|
|
7950
|
-
break;
|
|
7951
|
-
case "--hide":
|
|
7952
|
-
hideFlags.push(value);
|
|
7953
|
-
break;
|
|
7954
|
-
default:
|
|
7955
|
-
matched.flag;
|
|
7847
|
+
function resolveAntigravityConfig(config) {
|
|
7848
|
+
const overrides = config?.models ?? {};
|
|
7849
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
7850
|
+
for (const [key, target] of Object.entries(overrides)) {
|
|
7851
|
+
if (!isAntigravityTier(key)) {
|
|
7852
|
+
aliases.set(key.toLowerCase(), candidatesOf(target));
|
|
7956
7853
|
}
|
|
7957
7854
|
}
|
|
7958
|
-
|
|
7959
|
-
|
|
7855
|
+
const tierModel = (tier) => {
|
|
7856
|
+
const target = overrides[tier];
|
|
7857
|
+
return target === void 0 ? ANTIGRAVITY_DEFAULT_TIER_MODELS[tier] : candidatesOf(target);
|
|
7858
|
+
};
|
|
7859
|
+
if (!aliases.has(AUTO_ALIAS)) {
|
|
7860
|
+
aliases.set(AUTO_ALIAS, [...new Set(CLAUDE_TIERS.flatMap(tierModel))]);
|
|
7960
7861
|
}
|
|
7961
|
-
const identity = flagIdentity ?? positionalIdentity;
|
|
7962
7862
|
return {
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7863
|
+
mode: config?.mode ?? ANTIGRAVITY_DEFAULT_MODE,
|
|
7864
|
+
defaultModel: config?.defaultModel ?? ANTIGRAVITY_DEFAULT_MODEL,
|
|
7865
|
+
models: { fable: tierModel("fable"), opus: tierModel("opus"), sonnet: tierModel("sonnet"), haiku: tierModel("haiku") },
|
|
7866
|
+
aliases,
|
|
7867
|
+
degradeDownTiers: config?.degradeDownTiers ?? false,
|
|
7868
|
+
effort: config?.effort ?? ANTIGRAVITY_DEFAULT_EFFORT,
|
|
7869
|
+
cloud: {
|
|
7870
|
+
endpoint: config?.cloud?.endpoint,
|
|
7871
|
+
projectId: config?.cloud?.projectId,
|
|
7872
|
+
location: config?.cloud?.location
|
|
7873
|
+
},
|
|
7874
|
+
local: {
|
|
7875
|
+
command: config?.local?.command,
|
|
7876
|
+
socketPath: config?.local?.socketPath
|
|
7877
|
+
}
|
|
7974
7878
|
};
|
|
7975
7879
|
}
|
|
7976
|
-
var
|
|
7977
|
-
var
|
|
7978
|
-
"src/
|
|
7880
|
+
var AUTO_ALIAS;
|
|
7881
|
+
var init_translate = __esm({
|
|
7882
|
+
"src/antigravity/translate.ts"() {
|
|
7979
7883
|
"use strict";
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
}
|
|
7988
|
-
positional;
|
|
7989
|
-
flag;
|
|
7990
|
-
};
|
|
7991
|
-
VALUED_FLAGS = ["--identity", "--config-profile", "--provider", "--claude-version", "--delay", "--category", "--share", "--hide"];
|
|
7992
|
-
BOOLEAN_FLAGS = [
|
|
7993
|
-
{ flag: "--headroom", key: "headroom" },
|
|
7994
|
-
{ flag: "--track-usage", key: "trackUsage" },
|
|
7995
|
-
{ flag: "--skip-permissions", key: "skipPermissions" },
|
|
7996
|
-
{ flag: "--remote-control", key: "remoteControl" },
|
|
7997
|
-
{ flag: "--wait", key: "wait" },
|
|
7998
|
-
{ flag: "--pause", key: "pause" },
|
|
7999
|
-
{ flag: "--explain", key: "explain" },
|
|
8000
|
-
{ flag: "--route-by-name", key: "routeByName" }
|
|
8001
|
-
];
|
|
8002
|
-
LAUNCHER_FLAG_NAMES = [
|
|
8003
|
-
...VALUED_FLAGS,
|
|
8004
|
-
"--native",
|
|
8005
|
-
"--no-provider",
|
|
8006
|
-
...BOOLEAN_FLAGS.flatMap(({ flag }) => [flag, `--no-${flag.slice(2)}`])
|
|
8007
|
-
];
|
|
8008
|
-
NATIVE_FLAG = "--native";
|
|
8009
|
-
TERMINATOR = "--";
|
|
7884
|
+
init_identity2();
|
|
7885
|
+
init_engine();
|
|
7886
|
+
init_quota();
|
|
7887
|
+
init_signatures();
|
|
7888
|
+
init_schema();
|
|
7889
|
+
init_anthropic();
|
|
7890
|
+
AUTO_ALIAS = "auto";
|
|
8010
7891
|
}
|
|
8011
7892
|
});
|
|
8012
7893
|
|
|
8013
|
-
// src/
|
|
8014
|
-
function
|
|
8015
|
-
|
|
8016
|
-
|
|
7894
|
+
// src/codex/translate.ts
|
|
7895
|
+
function resolveCodexConfig(config) {
|
|
7896
|
+
const overrides = config?.models;
|
|
7897
|
+
return {
|
|
7898
|
+
defaultModel: config?.defaultModel ?? CODEX_DEFAULT_MODEL,
|
|
7899
|
+
models: {
|
|
7900
|
+
fable: overrides?.fable ?? CODEX_DEFAULT_TIER_MODELS.fable,
|
|
7901
|
+
opus: overrides?.opus ?? CODEX_DEFAULT_TIER_MODELS.opus,
|
|
7902
|
+
sonnet: overrides?.sonnet ?? CODEX_DEFAULT_TIER_MODELS.sonnet,
|
|
7903
|
+
haiku: overrides?.haiku ?? CODEX_DEFAULT_TIER_MODELS.haiku
|
|
7904
|
+
},
|
|
7905
|
+
effort: config?.effort ?? CODEX_DEFAULT_EFFORT,
|
|
7906
|
+
login: config?.login ?? CODEX_DEFAULT_LOGIN
|
|
7907
|
+
};
|
|
7908
|
+
}
|
|
7909
|
+
var init_translate2 = __esm({
|
|
7910
|
+
"src/codex/translate.ts"() {
|
|
7911
|
+
"use strict";
|
|
7912
|
+
init_schema();
|
|
7913
|
+
init_anthropic();
|
|
8017
7914
|
}
|
|
8018
|
-
|
|
7915
|
+
});
|
|
7916
|
+
|
|
7917
|
+
// src/providerCatalogue.ts
|
|
7918
|
+
import path30 from "node:path";
|
|
7919
|
+
import picomatch4 from "picomatch";
|
|
7920
|
+
import { z as z24 } from "zod";
|
|
7921
|
+
function catalogueCachePath(paths, name) {
|
|
7922
|
+
return path30.join(paths.catalogueDir, `${name}.json`);
|
|
8019
7923
|
}
|
|
8020
|
-
function
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
throw new Error(`Expected "<key>=<value>", got "${input}" (no "=" found)`);
|
|
7924
|
+
function parseCatalogueCache(text) {
|
|
7925
|
+
if (text === void 0) {
|
|
7926
|
+
return void 0;
|
|
8024
7927
|
}
|
|
8025
|
-
|
|
8026
|
-
|
|
8027
|
-
|
|
8028
|
-
|
|
7928
|
+
try {
|
|
7929
|
+
const parsed = CatalogueCacheSchema.safeParse(JSON.parse(text));
|
|
7930
|
+
return parsed.success ? parsed.data : void 0;
|
|
7931
|
+
} catch {
|
|
7932
|
+
return void 0;
|
|
8029
7933
|
}
|
|
8030
|
-
return { key, value };
|
|
8031
7934
|
}
|
|
8032
|
-
function
|
|
8033
|
-
const
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
7935
|
+
function filterCatalogue(models, catalogue) {
|
|
7936
|
+
const included = catalogue.include === void 0 ? void 0 : picomatch4(catalogue.include, { dot: true });
|
|
7937
|
+
const excluded = catalogue.exclude === void 0 ? void 0 : picomatch4(catalogue.exclude, { dot: true });
|
|
7938
|
+
return models.filter((model) => included?.(model.id) !== false && excluded?.(model.id) !== true);
|
|
7939
|
+
}
|
|
7940
|
+
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;
|
|
7941
|
+
var init_providerCatalogue = __esm({
|
|
7942
|
+
"src/providerCatalogue.ts"() {
|
|
7943
|
+
"use strict";
|
|
7944
|
+
DEFAULT_CANDIDATE_URLS = 2;
|
|
7945
|
+
MS_PER_SECOND5 = 1e3;
|
|
7946
|
+
SECONDS_PER_HOUR2 = 3600;
|
|
7947
|
+
HOURS_PER_DAY5 = 24;
|
|
7948
|
+
MS_PER_HOUR4 = SECONDS_PER_HOUR2 * MS_PER_SECOND5;
|
|
7949
|
+
HOURS_BETWEEN_RETRIES = 1;
|
|
7950
|
+
CATALOGUE_MAX_AGE_MS = HOURS_PER_DAY5 * MS_PER_HOUR4;
|
|
7951
|
+
CATALOGUE_RETRY_MS = HOURS_BETWEEN_RETRIES * MS_PER_HOUR4;
|
|
7952
|
+
CATALOGUE_REQUEST_SECONDS = 10;
|
|
7953
|
+
CATALOGUE_REQUEST_TIMEOUT_MS = CATALOGUE_REQUEST_SECONDS * MS_PER_SECOND5;
|
|
7954
|
+
CATALOGUE_REFRESH_TIMEOUT_MS = DEFAULT_CANDIDATE_URLS * CATALOGUE_REQUEST_TIMEOUT_MS;
|
|
7955
|
+
CatalogueModelSchema = z24.strictObject({ id: z24.string().min(1), name: z24.string().min(1).optional() });
|
|
7956
|
+
CatalogueCacheSchema = z24.strictObject({ fetchedAt: z24.number(), url: z24.string().min(1), models: z24.array(CatalogueModelSchema) });
|
|
7957
|
+
}
|
|
7958
|
+
});
|
|
7959
|
+
|
|
7960
|
+
// src/launcher/modelPicker.ts
|
|
7961
|
+
function labelOf(model) {
|
|
7962
|
+
return withoutContextMarker(model);
|
|
7963
|
+
}
|
|
7964
|
+
function describedAs(model, description) {
|
|
7965
|
+
return model.toLowerCase().endsWith(CONTEXT_MARKER_1M) ? `${description}; 1M context` : description;
|
|
7966
|
+
}
|
|
7967
|
+
function joined(parts) {
|
|
7968
|
+
const last = parts[parts.length - 1];
|
|
7969
|
+
return last === void 0 || parts.length === 1 ? last ?? "" : `${parts.slice(0, -1).join(", ")} and ${last}`;
|
|
7970
|
+
}
|
|
7971
|
+
function rowOf2(model, reaches) {
|
|
7972
|
+
const lead = reaches.find((reach) => reach.standing === "first") ?? reaches[0];
|
|
7973
|
+
if (lead === void 0) {
|
|
7974
|
+
throw new Error(`model ${model} is reached by no tier`);
|
|
7975
|
+
}
|
|
7976
|
+
const firsts = reaches.filter((reach) => reach.standing === "first").map((reach) => reach.tier);
|
|
7977
|
+
const fallbacks = reaches.filter((reach) => reach.standing === "fallback").map((reach) => reach.tier);
|
|
7978
|
+
const serves = firsts.length === 0 ? [] : [`Serves the ${joined(firsts)} tier${firsts.length === 1 ? "" : "s"}`];
|
|
7979
|
+
const falls = fallbacks.length === 0 ? [] : [`${serves.length === 0 ? "Fallback" : "fallback"} for ${joined(fallbacks)}`];
|
|
7980
|
+
return { model, label: labelOf(model), description: describedAs(model, [...serves, ...falls].join("; ")), behavesAs: TIER_BEHAVES_AS[lead.tier] };
|
|
7981
|
+
}
|
|
7982
|
+
function rowsOfTable(table) {
|
|
7983
|
+
const reachesByModel = /* @__PURE__ */ new Map();
|
|
7984
|
+
for (const [tier, candidates] of table) {
|
|
7985
|
+
candidates.forEach((model, index) => {
|
|
7986
|
+
const reaches = reachesByModel.get(model) ?? [];
|
|
7987
|
+
if (!reaches.some((reach) => reach.tier === tier)) {
|
|
7988
|
+
reaches.push({ tier, standing: index === 0 ? "first" : "fallback" });
|
|
7989
|
+
}
|
|
7990
|
+
reachesByModel.set(model, reaches);
|
|
7991
|
+
});
|
|
7992
|
+
}
|
|
7993
|
+
return [...reachesByModel].map(([model, reaches]) => rowOf2(model, reaches));
|
|
7994
|
+
}
|
|
7995
|
+
function antigravityRows(provider) {
|
|
7996
|
+
const config = resolveAntigravityConfig(provider.antigravity);
|
|
7997
|
+
const tiers = rowsOfTable(CLAUDE_TIERS.map((tier) => [tier, config.models[tier]]));
|
|
7998
|
+
const behavesAsOf = new Map(tiers.map((row) => [row.model, row.behavesAs]));
|
|
7999
|
+
const aliases = [...config.aliases].flatMap(([alias, candidates]) => {
|
|
8000
|
+
const [first] = candidates;
|
|
8001
|
+
const behavesAs = first === void 0 ? void 0 : behavesAsOf.get(first);
|
|
8002
|
+
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 ")}`;
|
|
8003
|
+
return behavesAs === void 0 ? [] : [{ model: alias, label: labelOf(alias), description, behavesAs }];
|
|
8004
|
+
});
|
|
8005
|
+
return [...aliases.filter((row) => row.model === AUTO_ALIAS), ...tiers, ...aliases.filter((row) => row.model !== AUTO_ALIAS)];
|
|
8006
|
+
}
|
|
8007
|
+
function codexRows(provider) {
|
|
8008
|
+
const config = resolveCodexConfig(provider.codex);
|
|
8009
|
+
return rowsOfTable(CLAUDE_TIERS.map((tier) => [tier, [config.models[tier]]]));
|
|
8010
|
+
}
|
|
8011
|
+
function httpRows(provider) {
|
|
8012
|
+
const env = provider.env ?? {};
|
|
8013
|
+
const table = CLAUDE_TIERS.flatMap((tier) => {
|
|
8014
|
+
const model = env[TIER_ENV_VARIABLES[tier]];
|
|
8015
|
+
return model === void 0 || model === "" ? [] : [[tier, [model]]];
|
|
8016
|
+
});
|
|
8017
|
+
return rowsOfTable(table);
|
|
8018
|
+
}
|
|
8019
|
+
function declaredRow(entry) {
|
|
8020
|
+
return {
|
|
8021
|
+
model: entry.model,
|
|
8022
|
+
label: entry.label ?? labelOf(entry.model),
|
|
8023
|
+
description: entry.description ?? describedAs(entry.model, `Declared by the provider for the ${entry.tier} tier`),
|
|
8024
|
+
behavesAs: TIER_BEHAVES_AS[entry.tier]
|
|
8025
|
+
};
|
|
8026
|
+
}
|
|
8027
|
+
function catalogueRows(provider, models) {
|
|
8028
|
+
if (provider.kind !== void 0 && provider.kind !== "http" || provider.catalogue === void 0) {
|
|
8029
|
+
return [];
|
|
8030
|
+
}
|
|
8031
|
+
const { tier } = provider.catalogue;
|
|
8032
|
+
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));
|
|
8033
|
+
}
|
|
8034
|
+
function providerModelRows(provider, catalogue = []) {
|
|
8035
|
+
const derived = provider.kind === "codex" ? codexRows(provider) : provider.kind === "antigravity" ? antigravityRows(provider) : provider.kind === "router" ? [] : httpRows(provider);
|
|
8036
|
+
const declared = provider.kind === "router" ? [] : (provider.pickerModels ?? []).map(declaredRow);
|
|
8037
|
+
const declaredModels = new Set(declared.map((row) => row.model));
|
|
8038
|
+
const named = [...derived.filter((row) => !declaredModels.has(row.model)), ...declared];
|
|
8039
|
+
const taken = new Set(named.map((row) => labelOf(row.model)));
|
|
8040
|
+
return [...named, ...catalogueRows(provider, catalogue).filter((row) => !taken.has(labelOf(row.model)))];
|
|
8041
|
+
}
|
|
8042
|
+
function routedModelRows(models, providers) {
|
|
8043
|
+
const hidden = new Set(models.hide ?? []);
|
|
8044
|
+
const shown = models.show === void 0 ? void 0 : new Set(models.show);
|
|
8045
|
+
const visible = (model) => shown === void 0 ? !hidden.has(model) : shown.has(model);
|
|
8046
|
+
const tierOf = (model) => {
|
|
8047
|
+
for (const [, provider] of providers) {
|
|
8048
|
+
if (provider.kind !== void 0 && provider.kind !== "http") {
|
|
8049
|
+
continue;
|
|
8050
|
+
}
|
|
8051
|
+
const match = Object.entries(provider.env ?? {}).find(([key, value]) => value === model && key.startsWith("ANTHROPIC_DEFAULT_") && key.endsWith("_MODEL"));
|
|
8052
|
+
if (match !== void 0) {
|
|
8053
|
+
const tier = match[0].replace("ANTHROPIC_DEFAULT_", "").replace("_MODEL", "").toLowerCase();
|
|
8054
|
+
return tier === "fable" || tier === "opus" || tier === "sonnet" || tier === "haiku" ? tier : void 0;
|
|
8055
|
+
}
|
|
8056
|
+
}
|
|
8057
|
+
return void 0;
|
|
8058
|
+
};
|
|
8059
|
+
const virtual = Object.entries(models.virtual ?? {}).flatMap(([name, definition]) => {
|
|
8060
|
+
if (!visible(name)) {
|
|
8061
|
+
return [];
|
|
8062
|
+
}
|
|
8063
|
+
const first = definition.members.find((member) => member.includes("/"));
|
|
8064
|
+
const tier = first === void 0 ? void 0 : tierOf(first.split("/").slice(1).join("/"));
|
|
8065
|
+
const behavesAs = tier === void 0 ? void 0 : TIER_BEHAVES_AS[tier];
|
|
8066
|
+
return behavesAs === void 0 ? [] : [{ model: name, label: name, description: `Virtual (${definition.mode})`, behavesAs }];
|
|
8067
|
+
});
|
|
8068
|
+
const concrete = providers.flatMap(([name, provider]) => providerModelRows(provider).map((row) => ({ ...row, model: `${name}/${row.model}`, label: `${name} / ${row.label}`, description: `${name}: ${row.description}` })));
|
|
8069
|
+
return [...virtual, ...concrete.filter((row) => visible(row.model))];
|
|
8070
|
+
}
|
|
8071
|
+
function modelPickerSettings(provider, catalogue = []) {
|
|
8072
|
+
return modelPickerSettingsFromRows(providerModelRows(provider, catalogue), true);
|
|
8038
8073
|
}
|
|
8039
|
-
function
|
|
8040
|
-
|
|
8041
|
-
for (const piece of splitCommas(input)) {
|
|
8042
|
-
const { key, value } = parsePair(piece);
|
|
8043
|
-
result[key] = parseBool(value);
|
|
8044
|
-
}
|
|
8045
|
-
return result;
|
|
8074
|
+
function modelPickerSettingsFromRows(options, replaceBuiltInOptions) {
|
|
8075
|
+
return options.length === 0 ? void 0 : JSON.stringify({ modelPicker: { options, replaceBuiltInOptions } });
|
|
8046
8076
|
}
|
|
8047
|
-
var
|
|
8048
|
-
|
|
8077
|
+
var TIER_BEHAVES_AS, TIER_ENV_VARIABLES;
|
|
8078
|
+
var init_modelPicker = __esm({
|
|
8079
|
+
"src/launcher/modelPicker.ts"() {
|
|
8049
8080
|
"use strict";
|
|
8050
|
-
|
|
8081
|
+
init_translate();
|
|
8082
|
+
init_translate2();
|
|
8083
|
+
init_providerCatalogue();
|
|
8084
|
+
init_schema();
|
|
8085
|
+
init_identity2();
|
|
8086
|
+
TIER_BEHAVES_AS = Object.freeze({
|
|
8087
|
+
fable: "claude-fable-5-1",
|
|
8088
|
+
opus: "claude-opus-5-5",
|
|
8089
|
+
sonnet: "claude-sonnet-5-5",
|
|
8090
|
+
haiku: "claude-haiku-5-5"
|
|
8091
|
+
});
|
|
8092
|
+
TIER_ENV_VARIABLES = Object.freeze({
|
|
8093
|
+
fable: "ANTHROPIC_DEFAULT_FABLE_MODEL",
|
|
8094
|
+
opus: "ANTHROPIC_DEFAULT_OPUS_MODEL",
|
|
8095
|
+
sonnet: "ANTHROPIC_DEFAULT_SONNET_MODEL",
|
|
8096
|
+
haiku: "ANTHROPIC_DEFAULT_HAIKU_MODEL"
|
|
8097
|
+
});
|
|
8051
8098
|
}
|
|
8052
8099
|
});
|
|
8053
8100
|
|
|
8054
|
-
// src/
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
if (!isOverridableCategory(key)) {
|
|
8060
|
-
throw new InvalidCliCategoryError(key);
|
|
8061
|
-
}
|
|
8062
|
-
result[key] = value;
|
|
8063
|
-
}
|
|
8064
|
-
return result;
|
|
8101
|
+
// src/frontdoor/probe.ts
|
|
8102
|
+
import { Worker } from "node:worker_threads";
|
|
8103
|
+
function probeFrontDoorSync(port, caPem) {
|
|
8104
|
+
refuseToBlockInRole("a synchronous probe of the front door");
|
|
8105
|
+
return runProbeWorker(PROBE_SOURCE, { port, ca: caPem });
|
|
8065
8106
|
}
|
|
8066
|
-
function
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
throw new InvalidCliEntryKeyError(key);
|
|
8070
|
-
}
|
|
8071
|
-
}
|
|
8072
|
-
return pairs;
|
|
8107
|
+
function probeListenerAcceptSync(port) {
|
|
8108
|
+
refuseToBlockInRole("a synchronous probe of a front door listener");
|
|
8109
|
+
return runProbeWorker(ACCEPT_PROBE_SOURCE, { port });
|
|
8073
8110
|
}
|
|
8074
|
-
function
|
|
8111
|
+
function runProbeWorker(source, data) {
|
|
8112
|
+
const shared = new SharedArrayBuffer(HEADER_SLOTS * INT32_BYTES + REASON_BYTES);
|
|
8113
|
+
const header = new Int32Array(shared, 0, HEADER_SLOTS);
|
|
8114
|
+
const worker = new Worker(source, {
|
|
8115
|
+
eval: true,
|
|
8116
|
+
workerData: { ...data, timeoutMs: PROBE_TIMEOUT_MS, shared, ok: VERDICT_OK, failed: VERDICT_FAILED, headerSlots: HEADER_SLOTS }
|
|
8117
|
+
});
|
|
8118
|
+
worker.unref();
|
|
8075
8119
|
try {
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
if (
|
|
8079
|
-
|
|
8120
|
+
const waited = Atomics.wait(header, 0, VERDICT_PENDING, PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS);
|
|
8121
|
+
const verdict = Atomics.load(header, 0);
|
|
8122
|
+
if (waited === "timed-out" || verdict === VERDICT_PENDING) {
|
|
8123
|
+
return { ok: false, reason: `the probe did not finish within ${String(PROBE_TIMEOUT_MS + PROBE_WAIT_MARGIN_MS)}ms` };
|
|
8080
8124
|
}
|
|
8081
|
-
|
|
8125
|
+
if (verdict === VERDICT_OK) {
|
|
8126
|
+
return { ok: true };
|
|
8127
|
+
}
|
|
8128
|
+
const length = Atomics.load(header, 1);
|
|
8129
|
+
return { ok: false, reason: Buffer.from(new Uint8Array(shared, HEADER_SLOTS * INT32_BYTES, length)).toString("utf8") };
|
|
8130
|
+
} finally {
|
|
8131
|
+
void worker.terminate();
|
|
8082
8132
|
}
|
|
8083
8133
|
}
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
const
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8134
|
+
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;
|
|
8135
|
+
var init_probe = __esm({
|
|
8136
|
+
"src/frontdoor/probe.ts"() {
|
|
8137
|
+
"use strict";
|
|
8138
|
+
init_processRole();
|
|
8139
|
+
PROBE_TIMEOUT_MS = 2e3;
|
|
8140
|
+
PROBE_WAIT_MARGIN_MS = 1e3;
|
|
8141
|
+
REASON_BYTES = 1024;
|
|
8142
|
+
HEADER_SLOTS = 2;
|
|
8143
|
+
INT32_BYTES = 4;
|
|
8144
|
+
VERDICT_PENDING = 0;
|
|
8145
|
+
VERDICT_OK = 1;
|
|
8146
|
+
VERDICT_FAILED = 2;
|
|
8147
|
+
PROBE_SOURCE = `
|
|
8148
|
+
const { workerData } = require("node:worker_threads");
|
|
8149
|
+
const https = require("node:https");
|
|
8150
|
+
const { port, ca, timeoutMs, shared, ok, failed, headerSlots } = workerData;
|
|
8151
|
+
const header = new Int32Array(shared, 0, headerSlots);
|
|
8152
|
+
const reason = new Uint8Array(shared, headerSlots * 4);
|
|
8153
|
+
let done = false;
|
|
8154
|
+
const finish = (verdict, message) => {
|
|
8155
|
+
if (done) return;
|
|
8156
|
+
done = true;
|
|
8157
|
+
const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
|
|
8158
|
+
reason.set(bytes);
|
|
8159
|
+
Atomics.store(header, 1, bytes.length);
|
|
8160
|
+
Atomics.store(header, 0, verdict);
|
|
8161
|
+
Atomics.notify(header, 0);
|
|
8162
|
+
};
|
|
8163
|
+
const request = https.get({ host: "127.0.0.1", port, path: "/healthz", ca: [ca], agent: false }, (response) => {
|
|
8164
|
+
let body = "";
|
|
8165
|
+
response.setEncoding("utf8");
|
|
8166
|
+
response.on("data", (chunk) => { body += chunk; });
|
|
8167
|
+
response.on("end", () => {
|
|
8168
|
+
if (response.statusCode === 200 && body === "ok") finish(ok, "");
|
|
8169
|
+
else finish(failed, "the listener answered its health probe with HTTP " + String(response.statusCode));
|
|
8170
|
+
});
|
|
8171
|
+
response.on("error", (error) => finish(failed, error.message));
|
|
8172
|
+
});
|
|
8173
|
+
// A hard deadline over the whole exchange, handshake included: a listener that accepts the connection and then says nothing must still fail the probe.
|
|
8174
|
+
setTimeout(() => { request.destroy(new Error("no answer within " + String(timeoutMs) + "ms")); }, timeoutMs);
|
|
8175
|
+
request.on("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
|
|
8176
|
+
`;
|
|
8177
|
+
ACCEPT_PROBE_SOURCE = `
|
|
8178
|
+
const { workerData } = require("node:worker_threads");
|
|
8179
|
+
const net = require("node:net");
|
|
8180
|
+
const { port, timeoutMs, shared, ok, failed, headerSlots } = workerData;
|
|
8181
|
+
const header = new Int32Array(shared, 0, headerSlots);
|
|
8182
|
+
const reason = new Uint8Array(shared, headerSlots * 4);
|
|
8183
|
+
let done = false;
|
|
8184
|
+
const finish = (verdict, message) => {
|
|
8185
|
+
if (done) return;
|
|
8186
|
+
done = true;
|
|
8187
|
+
const bytes = Buffer.from(String(message), "utf8").subarray(0, reason.length);
|
|
8188
|
+
reason.set(bytes);
|
|
8189
|
+
Atomics.store(header, 1, bytes.length);
|
|
8190
|
+
Atomics.store(header, 0, verdict);
|
|
8191
|
+
Atomics.notify(header, 0);
|
|
8192
|
+
};
|
|
8193
|
+
const socket = net.connect({ host: "127.0.0.1", port });
|
|
8194
|
+
socket.once("connect", () => { socket.destroy(); finish(ok, ""); });
|
|
8195
|
+
socket.once("error", (error) => finish(failed, (error.code ? error.code + ": " : "") + error.message));
|
|
8196
|
+
setTimeout(() => { socket.destroy(); finish(failed, "no connection accepted within " + String(timeoutMs) + "ms"); }, timeoutMs);
|
|
8197
|
+
`;
|
|
8111
8198
|
}
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8199
|
+
});
|
|
8200
|
+
|
|
8201
|
+
// src/update/update.ts
|
|
8202
|
+
function compareVersions3(left, right) {
|
|
8203
|
+
const parse = (version) => {
|
|
8204
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
8205
|
+
if (match === null) {
|
|
8206
|
+
throw new Error(`not a plain release version: ${version}`);
|
|
8207
|
+
}
|
|
8208
|
+
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
8116
8209
|
};
|
|
8210
|
+
const leftParts = parse(left);
|
|
8211
|
+
const rightParts = parse(right);
|
|
8212
|
+
return leftParts.map((part, index) => part - (rightParts[index] ?? 0)).find((difference) => difference !== 0) ?? 0;
|
|
8117
8213
|
}
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
"
|
|
8214
|
+
function releaseTagFromUrl(url) {
|
|
8215
|
+
const segment = url.split("?")[0]?.split("/").at(-1);
|
|
8216
|
+
const candidate = segment?.startsWith("v") === true ? segment.slice(1) : void 0;
|
|
8217
|
+
return candidate !== void 0 && /^\d+\.\d+\.\d+$/.test(candidate) ? candidate : void 0;
|
|
8218
|
+
}
|
|
8219
|
+
var LATEST_RELEASE_URL, UpdateChannelError, UpdateConflictError, UpdateDownloadError;
|
|
8220
|
+
var init_update = __esm({
|
|
8221
|
+
"src/update/update.ts"() {
|
|
8121
8222
|
"use strict";
|
|
8122
|
-
init_pairs();
|
|
8123
|
-
init_schema();
|
|
8124
8223
|
init_cliError();
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
this.name = "
|
|
8224
|
+
LATEST_RELEASE_URL = "https://github.com/ExaDev/agent-shim/releases/latest";
|
|
8225
|
+
UpdateChannelError = class extends CliError {
|
|
8226
|
+
constructor(message) {
|
|
8227
|
+
super(message);
|
|
8228
|
+
this.name = "UpdateChannelError";
|
|
8229
|
+
}
|
|
8230
|
+
};
|
|
8231
|
+
UpdateConflictError = class extends CliError {
|
|
8232
|
+
constructor(message) {
|
|
8233
|
+
super(message);
|
|
8234
|
+
this.name = "UpdateConflictError";
|
|
8130
8235
|
}
|
|
8131
|
-
categoryName;
|
|
8132
8236
|
};
|
|
8133
|
-
|
|
8134
|
-
constructor(
|
|
8135
|
-
super(
|
|
8136
|
-
this.
|
|
8137
|
-
this.name = "InvalidCliEntryKeyError";
|
|
8237
|
+
UpdateDownloadError = class extends CliError {
|
|
8238
|
+
constructor(message) {
|
|
8239
|
+
super(message);
|
|
8240
|
+
this.name = "UpdateDownloadError";
|
|
8138
8241
|
}
|
|
8139
|
-
key;
|
|
8140
8242
|
};
|
|
8141
8243
|
}
|
|
8142
8244
|
});
|
|
8143
8245
|
|
|
8144
|
-
// src/
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8246
|
+
// src/frontdoor/ensure.ts
|
|
8247
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
8248
|
+
function ensureFrontDoor(params) {
|
|
8249
|
+
const { paths, ports } = params;
|
|
8250
|
+
const deadline = ports.now() + FRONTDOOR_START_TIMEOUT_MS;
|
|
8251
|
+
let spawned = false;
|
|
8252
|
+
let replaced = false;
|
|
8253
|
+
const distrusted = /* @__PURE__ */ new Set();
|
|
8254
|
+
let lastRejection;
|
|
8255
|
+
let busyDoor;
|
|
8256
|
+
const liveSessionsOn = (doorPid) => listFrontDoorSessions(ports.fs, paths.frontdoorSessionsDir).filter(
|
|
8257
|
+
(session) => session.pid !== params.launcherPid && ports.isRunning(session.pid) && (session.supervisorPid === void 0 || session.supervisorPid === doorPid)
|
|
8258
|
+
).length;
|
|
8259
|
+
const verifyWithRetry = (port) => {
|
|
8260
|
+
let verdict = ports.verifyListener(port);
|
|
8261
|
+
for (let attempt = 1; !verdict.ok && attempt < FRONTDOOR_PROBE_ATTEMPTS; attempt += 1) {
|
|
8262
|
+
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
8263
|
+
verdict = ports.verifyListener(port);
|
|
8150
8264
|
}
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8265
|
+
return verdict;
|
|
8266
|
+
};
|
|
8267
|
+
const stopAndAwaitExit = (supervisorPid, failure) => {
|
|
8268
|
+
ports.stopSupervisor(supervisorPid);
|
|
8269
|
+
const graceEnds = ports.now() + FRONTDOOR_EXIT_GRACE_MS;
|
|
8270
|
+
let killed = false;
|
|
8271
|
+
while (ports.isRunning(supervisorPid)) {
|
|
8272
|
+
if (!killed && ports.now() >= graceEnds) {
|
|
8273
|
+
ports.killSupervisor(supervisorPid);
|
|
8274
|
+
killed = true;
|
|
8155
8275
|
}
|
|
8156
|
-
|
|
8276
|
+
if (ports.now() >= deadline) {
|
|
8277
|
+
throw new FrontDoorStartError(`${failure}. Daemon log: ${paths.frontdoorLogPath}`);
|
|
8278
|
+
}
|
|
8279
|
+
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
8157
8280
|
}
|
|
8281
|
+
};
|
|
8282
|
+
for (; ; ) {
|
|
8283
|
+
const state = readFrontDoorState(ports.fs, paths.frontdoorStateFile);
|
|
8284
|
+
const supervisorPid = state?.supervisorPid;
|
|
8285
|
+
if (supervisorPid !== void 0 && !distrusted.has(supervisorPid) && ports.isRunning(supervisorPid)) {
|
|
8286
|
+
if (state?.port !== void 0 && state.connectPort !== void 0) {
|
|
8287
|
+
if (supervisorPid === params.launcherPid && params.replace !== true && ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
8288
|
+
const token = randomUUID3();
|
|
8289
|
+
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid });
|
|
8290
|
+
return { port: state.port, connectPort: state.connectPort, token };
|
|
8291
|
+
}
|
|
8292
|
+
const verdict = verifyWithRetry(state.port);
|
|
8293
|
+
if (verdict.ok && !replaced && !spawned && (params.replace === true || (state.protocol ?? 0) < FRONT_DOOR_PROTOCOL)) {
|
|
8294
|
+
stopAndAwaitExit(
|
|
8295
|
+
supervisorPid,
|
|
8296
|
+
`the front door (pid ${String(supervisorPid)}, protocol ${String(state.protocol ?? 0)}; this launcher speaks protocol ${String(FRONT_DOOR_PROTOCOL)}) was asked to be replaced and did not exit`
|
|
8297
|
+
);
|
|
8298
|
+
replaced = true;
|
|
8299
|
+
continue;
|
|
8300
|
+
}
|
|
8301
|
+
if (verdict.ok) {
|
|
8302
|
+
const token = randomUUID3();
|
|
8303
|
+
writeFrontDoorSession(ports.fs, paths.frontdoorSessionsDir, { pid: params.launcherPid, startedAt: ports.now(), token, supervisorPid });
|
|
8304
|
+
return { port: state.port, connectPort: state.connectPort, token };
|
|
8305
|
+
}
|
|
8306
|
+
lastRejection = `the listener on 127.0.0.1:${String(state.port)} (recorded for pid ${String(supervisorPid)}) failed authentication: ${verdict.reason}`;
|
|
8307
|
+
if (spawned) {
|
|
8308
|
+
throw new FrontDoorStartError(`${lastRejection}; refusing to send this session's credentials to it. Daemon log: ${paths.frontdoorLogPath}`);
|
|
8309
|
+
}
|
|
8310
|
+
if (ports.isFrontDoorSupervisor(supervisorPid)) {
|
|
8311
|
+
const stranded = liveSessionsOn(supervisorPid);
|
|
8312
|
+
if (params.replace === true && !replaced) {
|
|
8313
|
+
stopAndAwaitExit(supervisorPid, `the front door (pid ${String(supervisorPid)}) stopped answering and did not exit when asked to`);
|
|
8314
|
+
replaced = true;
|
|
8315
|
+
continue;
|
|
8316
|
+
}
|
|
8317
|
+
if (stranded > 0) {
|
|
8318
|
+
busyDoor = { pid: supervisorPid, sessions: stranded };
|
|
8319
|
+
} else {
|
|
8320
|
+
stopAndAwaitExit(supervisorPid, `the front door (pid ${String(supervisorPid)}) stopped answering and did not exit when asked to`);
|
|
8321
|
+
continue;
|
|
8322
|
+
}
|
|
8323
|
+
} else {
|
|
8324
|
+
distrusted.add(supervisorPid);
|
|
8325
|
+
continue;
|
|
8326
|
+
}
|
|
8327
|
+
}
|
|
8328
|
+
if (state?.lastError !== void 0) {
|
|
8329
|
+
throw new FrontDoorStartError(`the front door reported a fatal error and is not serving: ${state.lastError} (daemon log: ${paths.frontdoorLogPath})`);
|
|
8330
|
+
}
|
|
8331
|
+
} else if (!spawned) {
|
|
8332
|
+
ports.fs.mkdirp(paths.frontdoorDir);
|
|
8333
|
+
const created = ports.fs.writeFileExclusive(paths.frontdoorLockFile, `${JSON.stringify({ pid: params.launcherPid, at: ports.now() })}
|
|
8334
|
+
`);
|
|
8335
|
+
if (created) {
|
|
8336
|
+
ports.spawnSupervisor(paths);
|
|
8337
|
+
spawned = true;
|
|
8338
|
+
} else {
|
|
8339
|
+
const lock = readStartLock(ports.fs, paths.frontdoorLockFile);
|
|
8340
|
+
if (lock === void 0 || !ports.isRunning(lock.pid)) {
|
|
8341
|
+
ports.fs.removeRecursive(paths.frontdoorLockFile);
|
|
8342
|
+
continue;
|
|
8343
|
+
}
|
|
8344
|
+
}
|
|
8345
|
+
}
|
|
8346
|
+
if (ports.now() >= deadline) {
|
|
8347
|
+
const lastError = state?.lastError;
|
|
8348
|
+
throw new FrontDoorStartError(
|
|
8349
|
+
`the front door did not become ready within ${String(FRONTDOOR_START_TIMEOUT_MS)}ms` + (lastError === void 0 ? "" : ` (last error: ${lastError})`) + (lastRejection === void 0 ? "" : ` (${lastRejection})`) + (busyDoor === void 0 ? "" : `. It was not replaced because ${String(busyDoor.sessions)} live session(s) are using it and would lose their connections; run \`agent-shim frontdoor restart\` to replace it deliberately`) + `. Daemon log: ${paths.frontdoorLogPath}`
|
|
8350
|
+
);
|
|
8351
|
+
}
|
|
8352
|
+
ports.sleep(FRONTDOOR_LAUNCHER_POLL_MS);
|
|
8158
8353
|
}
|
|
8159
|
-
for (const entry of additions) {
|
|
8160
|
-
merged.set(entry.name, entry.value);
|
|
8161
|
-
}
|
|
8162
|
-
return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
|
|
8163
|
-
}
|
|
8164
|
-
function parseCustomHeaderLine(line) {
|
|
8165
|
-
const trimmed = line.trim();
|
|
8166
|
-
if (trimmed === "") {
|
|
8167
|
-
return void 0;
|
|
8168
|
-
}
|
|
8169
|
-
const colon = trimmed.indexOf(":");
|
|
8170
|
-
if (colon <= 0) {
|
|
8171
|
-
return void 0;
|
|
8172
|
-
}
|
|
8173
|
-
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
8174
8354
|
}
|
|
8175
|
-
var
|
|
8176
|
-
|
|
8355
|
+
var FRONTDOOR_START_TIMEOUT_MS, FRONTDOOR_LAUNCHER_POLL_MS, FRONTDOOR_PROBE_ATTEMPTS, FRONTDOOR_EXIT_GRACE_MS, FrontDoorStartError;
|
|
8356
|
+
var init_ensure2 = __esm({
|
|
8357
|
+
"src/frontdoor/ensure.ts"() {
|
|
8177
8358
|
"use strict";
|
|
8359
|
+
init_cliError();
|
|
8360
|
+
init_state2();
|
|
8361
|
+
init_state();
|
|
8362
|
+
FRONTDOOR_START_TIMEOUT_MS = 3e4;
|
|
8363
|
+
FRONTDOOR_LAUNCHER_POLL_MS = 100;
|
|
8364
|
+
FRONTDOOR_PROBE_ATTEMPTS = 3;
|
|
8365
|
+
FRONTDOOR_EXIT_GRACE_MS = 5e3;
|
|
8366
|
+
FrontDoorStartError = class extends CliError {
|
|
8367
|
+
constructor(message) {
|
|
8368
|
+
super(message);
|
|
8369
|
+
this.name = "FrontDoorStartError";
|
|
8370
|
+
}
|
|
8371
|
+
};
|
|
8178
8372
|
}
|
|
8179
8373
|
});
|
|
8180
8374
|
|
|
8181
|
-
// src/launcher/
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
explain: params.flags?.explain ?? parseEnvBool("AGENT_SHIM_EXPLAIN", params.env.AGENT_SHIM_EXPLAIN) ?? params.cascade?.explain ?? false,
|
|
8191
|
-
routeByName: params.flags?.routeByName ?? parseEnvBool("AGENT_SHIM_ROUTE_BY_NAME", params.env.AGENT_SHIM_ROUTE_BY_NAME) ?? params.cascade?.routeByName ?? false,
|
|
8192
|
-
delayMs: resolveDelayMs(params)
|
|
8193
|
-
};
|
|
8194
|
-
}
|
|
8195
|
-
function resolveDelayMs(params) {
|
|
8196
|
-
const fromEnv = params.env.AGENT_SHIM_DELAY === "" ? void 0 : params.env.AGENT_SHIM_DELAY;
|
|
8197
|
-
const [literal, source] = params.flags?.delay !== void 0 ? [params.flags.delay, "--delay"] : fromEnv !== void 0 ? [fromEnv, "AGENT_SHIM_DELAY"] : [params.cascade?.delay, "launch.delay"];
|
|
8198
|
-
if (literal === void 0) {
|
|
8199
|
-
return 0;
|
|
8200
|
-
}
|
|
8201
|
-
try {
|
|
8202
|
-
return parseDuration(literal);
|
|
8203
|
-
} catch (error) {
|
|
8204
|
-
throw new UsageError(`${source}: ${error instanceof Error ? error.message : String(error)}`);
|
|
8375
|
+
// src/launcher/argv.ts
|
|
8376
|
+
function matchValuedFlag(token) {
|
|
8377
|
+
for (const flag of VALUED_FLAGS) {
|
|
8378
|
+
if (token === flag) {
|
|
8379
|
+
return { flag };
|
|
8380
|
+
}
|
|
8381
|
+
if (token.startsWith(`${flag}=`)) {
|
|
8382
|
+
return { flag, inlineValue: token.slice(flag.length + 1) };
|
|
8383
|
+
}
|
|
8205
8384
|
}
|
|
8385
|
+
return void 0;
|
|
8206
8386
|
}
|
|
8207
|
-
function
|
|
8208
|
-
const
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
|
|
8387
|
+
function matchBooleanFlag(token) {
|
|
8388
|
+
for (const { flag, key } of BOOLEAN_FLAGS) {
|
|
8389
|
+
if (token === flag) {
|
|
8390
|
+
return { key, value: true };
|
|
8391
|
+
}
|
|
8392
|
+
if (token === `--no-${flag.slice(2)}`) {
|
|
8393
|
+
return { key, value: false };
|
|
8394
|
+
}
|
|
8214
8395
|
}
|
|
8215
|
-
return
|
|
8216
|
-
}
|
|
8217
|
-
function buildArgv(params) {
|
|
8218
|
-
return [...params.toolFlags, ...params.extraFlags, ...params.passthrough];
|
|
8219
|
-
}
|
|
8220
|
-
function withLoopbackHosts(existing) {
|
|
8221
|
-
const listed = (existing ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
8222
|
-
return [...listed, ...LOOPBACK_HOSTS.filter((host) => !listed.includes(host))].join(",");
|
|
8396
|
+
return void 0;
|
|
8223
8397
|
}
|
|
8224
|
-
function
|
|
8225
|
-
const
|
|
8226
|
-
const
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8398
|
+
function parseLauncherArgv(argv) {
|
|
8399
|
+
const first = argv[0];
|
|
8400
|
+
const positionalIdentity = first !== void 0 && first.startsWith("@") && first.length > 1 ? first.slice(1) : void 0;
|
|
8401
|
+
const remaining = positionalIdentity === void 0 ? argv : argv.slice(1);
|
|
8402
|
+
let native = false;
|
|
8403
|
+
let flagIdentity;
|
|
8404
|
+
let configProfile;
|
|
8405
|
+
let provider;
|
|
8406
|
+
let claudeVersion;
|
|
8407
|
+
let delay;
|
|
8408
|
+
const booleans = {};
|
|
8409
|
+
const categoryFlags = [];
|
|
8410
|
+
const shareFlags = [];
|
|
8411
|
+
const hideFlags = [];
|
|
8412
|
+
const rest = [];
|
|
8413
|
+
for (let index = 0; index < remaining.length; index += 1) {
|
|
8414
|
+
const token = remaining[index];
|
|
8415
|
+
if (token === void 0) {
|
|
8416
|
+
continue;
|
|
8417
|
+
}
|
|
8418
|
+
if (token === TERMINATOR) {
|
|
8419
|
+
rest.push(...remaining.slice(index));
|
|
8420
|
+
break;
|
|
8421
|
+
}
|
|
8422
|
+
if (token === "--no-provider") {
|
|
8423
|
+
provider = false;
|
|
8424
|
+
continue;
|
|
8238
8425
|
}
|
|
8239
|
-
|
|
8240
|
-
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8426
|
+
if (token === NATIVE_FLAG) {
|
|
8427
|
+
native = true;
|
|
8428
|
+
continue;
|
|
8429
|
+
}
|
|
8430
|
+
const booleanFlag = matchBooleanFlag(token);
|
|
8431
|
+
if (booleanFlag !== void 0) {
|
|
8432
|
+
booleans[booleanFlag.key] = booleanFlag.value;
|
|
8433
|
+
continue;
|
|
8434
|
+
}
|
|
8435
|
+
const matched = matchValuedFlag(token);
|
|
8436
|
+
if (matched === void 0) {
|
|
8437
|
+
rest.push(token);
|
|
8438
|
+
continue;
|
|
8439
|
+
}
|
|
8440
|
+
let value;
|
|
8441
|
+
if (matched.inlineValue !== void 0) {
|
|
8442
|
+
value = matched.inlineValue;
|
|
8443
|
+
} else {
|
|
8444
|
+
const next = remaining[index + 1];
|
|
8445
|
+
if (next === void 0 || next === TERMINATOR) {
|
|
8446
|
+
rest.push(token);
|
|
8447
|
+
continue;
|
|
8448
|
+
}
|
|
8449
|
+
value = next;
|
|
8450
|
+
index += 1;
|
|
8451
|
+
}
|
|
8452
|
+
switch (matched.flag) {
|
|
8453
|
+
case "--identity":
|
|
8454
|
+
flagIdentity = value;
|
|
8455
|
+
break;
|
|
8456
|
+
case "--config-profile":
|
|
8457
|
+
configProfile = value;
|
|
8458
|
+
break;
|
|
8459
|
+
case "--provider":
|
|
8460
|
+
provider = value;
|
|
8461
|
+
break;
|
|
8462
|
+
case "--claude-version":
|
|
8463
|
+
claudeVersion = value;
|
|
8464
|
+
break;
|
|
8465
|
+
case "--delay":
|
|
8466
|
+
delay = value;
|
|
8467
|
+
break;
|
|
8468
|
+
case "--category":
|
|
8469
|
+
categoryFlags.push(value);
|
|
8470
|
+
break;
|
|
8471
|
+
case "--share":
|
|
8472
|
+
shareFlags.push(value);
|
|
8473
|
+
break;
|
|
8474
|
+
case "--hide":
|
|
8475
|
+
hideFlags.push(value);
|
|
8476
|
+
break;
|
|
8477
|
+
default:
|
|
8478
|
+
matched.flag;
|
|
8247
8479
|
}
|
|
8248
8480
|
}
|
|
8249
|
-
if (
|
|
8250
|
-
|
|
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);
|
|
8481
|
+
if (positionalIdentity !== void 0 && flagIdentity !== void 0 && positionalIdentity !== flagIdentity) {
|
|
8482
|
+
throw new ConflictingIdentityError(positionalIdentity, flagIdentity);
|
|
8271
8483
|
}
|
|
8272
|
-
|
|
8484
|
+
const identity = flagIdentity ?? positionalIdentity;
|
|
8485
|
+
return {
|
|
8486
|
+
...identity === void 0 ? {} : { identity },
|
|
8487
|
+
...configProfile === void 0 ? {} : { configProfile },
|
|
8488
|
+
...provider === void 0 ? {} : { provider },
|
|
8489
|
+
...claudeVersion === void 0 ? {} : { claudeVersion },
|
|
8490
|
+
...delay === void 0 ? {} : { delay },
|
|
8491
|
+
...native ? { native: true } : {},
|
|
8492
|
+
...booleans,
|
|
8493
|
+
categoryFlags,
|
|
8494
|
+
shareFlags,
|
|
8495
|
+
hideFlags,
|
|
8496
|
+
rest
|
|
8497
|
+
};
|
|
8273
8498
|
}
|
|
8274
|
-
var
|
|
8275
|
-
var
|
|
8276
|
-
"src/launcher/
|
|
8499
|
+
var ConflictingIdentityError, VALUED_FLAGS, BOOLEAN_FLAGS, LAUNCHER_FLAG_NAMES, NATIVE_FLAG, TERMINATOR;
|
|
8500
|
+
var init_argv = __esm({
|
|
8501
|
+
"src/launcher/argv.ts"() {
|
|
8277
8502
|
"use strict";
|
|
8278
|
-
init_envBool();
|
|
8279
8503
|
init_cliError();
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8504
|
+
ConflictingIdentityError = class extends UsageError {
|
|
8505
|
+
constructor(positional, flag) {
|
|
8506
|
+
super(`The launch names two identities: "@${positional}" and "--identity ${flag}". Pass only one.`);
|
|
8507
|
+
this.positional = positional;
|
|
8508
|
+
this.flag = flag;
|
|
8509
|
+
this.name = "ConflictingIdentityError";
|
|
8510
|
+
}
|
|
8511
|
+
positional;
|
|
8512
|
+
flag;
|
|
8513
|
+
};
|
|
8514
|
+
VALUED_FLAGS = ["--identity", "--config-profile", "--provider", "--claude-version", "--delay", "--category", "--share", "--hide"];
|
|
8515
|
+
BOOLEAN_FLAGS = [
|
|
8516
|
+
{ flag: "--headroom", key: "headroom" },
|
|
8517
|
+
{ flag: "--track-usage", key: "trackUsage" },
|
|
8518
|
+
{ flag: "--skip-permissions", key: "skipPermissions" },
|
|
8519
|
+
{ flag: "--remote-control", key: "remoteControl" },
|
|
8520
|
+
{ flag: "--wait", key: "wait" },
|
|
8521
|
+
{ flag: "--pause", key: "pause" },
|
|
8522
|
+
{ flag: "--explain", key: "explain" },
|
|
8523
|
+
{ flag: "--route-by-name", key: "routeByName" }
|
|
8524
|
+
];
|
|
8525
|
+
LAUNCHER_FLAG_NAMES = [
|
|
8526
|
+
...VALUED_FLAGS,
|
|
8527
|
+
"--native",
|
|
8528
|
+
"--no-provider",
|
|
8529
|
+
...BOOLEAN_FLAGS.flatMap(({ flag }) => [flag, `--no-${flag.slice(2)}`])
|
|
8530
|
+
];
|
|
8531
|
+
NATIVE_FLAG = "--native";
|
|
8532
|
+
TERMINATOR = "--";
|
|
8287
8533
|
}
|
|
8288
8534
|
});
|
|
8289
8535
|
|
|
8290
|
-
// src/
|
|
8291
|
-
function
|
|
8292
|
-
if (
|
|
8536
|
+
// src/cli/pairs.ts
|
|
8537
|
+
function splitCommas(input) {
|
|
8538
|
+
if (input === "") {
|
|
8293
8539
|
return [];
|
|
8294
8540
|
}
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8541
|
+
return input.split(",");
|
|
8542
|
+
}
|
|
8543
|
+
function parsePair(input) {
|
|
8544
|
+
const eqIndex = input.indexOf("=");
|
|
8545
|
+
if (eqIndex === -1) {
|
|
8546
|
+
throw new Error(`Expected "<key>=<value>", got "${input}" (no "=" found)`);
|
|
8298
8547
|
}
|
|
8299
|
-
|
|
8548
|
+
const key = input.slice(0, eqIndex);
|
|
8549
|
+
const value = input.slice(eqIndex + 1);
|
|
8550
|
+
if (key === "") {
|
|
8551
|
+
throw new Error(`Expected a non-empty key before "=" in "${input}"`);
|
|
8552
|
+
}
|
|
8553
|
+
return { key, value };
|
|
8300
8554
|
}
|
|
8301
|
-
|
|
8302
|
-
|
|
8555
|
+
function parseBool(input) {
|
|
8556
|
+
const parsed = parseBoolWord(input);
|
|
8557
|
+
if (parsed === void 0) {
|
|
8558
|
+
throw new Error(`Expected "true", "false", "1" or "0", got "${input}"`);
|
|
8559
|
+
}
|
|
8560
|
+
return parsed;
|
|
8561
|
+
}
|
|
8562
|
+
function parseBoolPairList(input) {
|
|
8563
|
+
const result = {};
|
|
8564
|
+
for (const piece of splitCommas(input)) {
|
|
8565
|
+
const { key, value } = parsePair(piece);
|
|
8566
|
+
result[key] = parseBool(value);
|
|
8567
|
+
}
|
|
8568
|
+
return result;
|
|
8569
|
+
}
|
|
8570
|
+
var init_pairs = __esm({
|
|
8571
|
+
"src/cli/pairs.ts"() {
|
|
8303
8572
|
"use strict";
|
|
8573
|
+
init_bool();
|
|
8304
8574
|
}
|
|
8305
8575
|
});
|
|
8306
8576
|
|
|
8307
|
-
// src/
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
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 };
|
|
8577
|
+
// src/launcher/cliOverride.ts
|
|
8578
|
+
function toCategoryMap(pairs) {
|
|
8579
|
+
const expanded = expandAllCategoryKey(pairs);
|
|
8580
|
+
const result = {};
|
|
8581
|
+
for (const [key, value] of Object.entries(expanded)) {
|
|
8582
|
+
if (!isOverridableCategory(key)) {
|
|
8583
|
+
throw new InvalidCliCategoryError(key);
|
|
8326
8584
|
}
|
|
8585
|
+
result[key] = value;
|
|
8327
8586
|
}
|
|
8328
|
-
return
|
|
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;
|
|
8587
|
+
return result;
|
|
8333
8588
|
}
|
|
8334
|
-
function
|
|
8335
|
-
const
|
|
8336
|
-
|
|
8337
|
-
|
|
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;
|
|
8589
|
+
function toEntries(pairs) {
|
|
8590
|
+
for (const key of Object.keys(pairs)) {
|
|
8591
|
+
if (!ENTRY_KEY_RE.test(key)) {
|
|
8592
|
+
throw new InvalidCliEntryKeyError(key);
|
|
8353
8593
|
}
|
|
8354
|
-
const { usage } = message;
|
|
8355
|
-
return countOf(usage, "input_tokens") + countOf(usage, "cache_read_input_tokens") + countOf(usage, "cache_creation_input_tokens");
|
|
8356
8594
|
}
|
|
8357
|
-
return
|
|
8595
|
+
return pairs;
|
|
8358
8596
|
}
|
|
8359
|
-
function
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
if (!
|
|
8364
|
-
|
|
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;
|
|
8597
|
+
function parseOverride(source, raw, parse) {
|
|
8598
|
+
try {
|
|
8599
|
+
return parse(raw);
|
|
8600
|
+
} catch (error) {
|
|
8601
|
+
if (error instanceof Error && !(error instanceof CliError)) {
|
|
8602
|
+
throw new UsageError(`Invalid ${source} value "${raw}": ${error.message}.`);
|
|
8371
8603
|
}
|
|
8604
|
+
throw error;
|
|
8372
8605
|
}
|
|
8373
|
-
return newest;
|
|
8374
8606
|
}
|
|
8375
|
-
function
|
|
8376
|
-
|
|
8377
|
-
if (
|
|
8607
|
+
function buildCliOverride(params) {
|
|
8608
|
+
let categoryPairs = {};
|
|
8609
|
+
if (params.env.AGENT_SHIM_CATEGORY_OVERRIDE !== void 0 && params.env.AGENT_SHIM_CATEGORY_OVERRIDE !== "") {
|
|
8610
|
+
categoryPairs = parseOverride("AGENT_SHIM_CATEGORY_OVERRIDE", params.env.AGENT_SHIM_CATEGORY_OVERRIDE, parseBoolPairList);
|
|
8611
|
+
}
|
|
8612
|
+
for (const flagValue of params.categoryFlags) {
|
|
8613
|
+
const pair = parseOverride("--category", flagValue, (raw) => {
|
|
8614
|
+
const { key, value } = parsePair(raw);
|
|
8615
|
+
return { key, value: parseBool(value) };
|
|
8616
|
+
});
|
|
8617
|
+
categoryPairs[pair.key] = pair.value;
|
|
8618
|
+
}
|
|
8619
|
+
let entryPairs = {};
|
|
8620
|
+
if (params.env.AGENT_SHIM_ENTRY_OVERRIDE !== void 0 && params.env.AGENT_SHIM_ENTRY_OVERRIDE !== "") {
|
|
8621
|
+
entryPairs = parseOverride("AGENT_SHIM_ENTRY_OVERRIDE", params.env.AGENT_SHIM_ENTRY_OVERRIDE, parseBoolPairList);
|
|
8622
|
+
}
|
|
8623
|
+
for (const entryPath of params.shareFlags) {
|
|
8624
|
+
entryPairs[entryPath] = true;
|
|
8625
|
+
}
|
|
8626
|
+
for (const entryPath of params.hideFlags) {
|
|
8627
|
+
entryPairs[entryPath] = false;
|
|
8628
|
+
}
|
|
8629
|
+
const hasCategories = Object.keys(categoryPairs).length > 0;
|
|
8630
|
+
const hasEntries = Object.keys(entryPairs).length > 0;
|
|
8631
|
+
const hasProvider = params.providerFlag !== void 0 && params.providerFlag !== "";
|
|
8632
|
+
if (!hasCategories && !hasEntries && !hasProvider) {
|
|
8378
8633
|
return void 0;
|
|
8379
8634
|
}
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8635
|
+
return {
|
|
8636
|
+
...hasCategories ? { categories: toCategoryMap(categoryPairs) } : {},
|
|
8637
|
+
...hasEntries ? { entries: toEntries(entryPairs) } : {},
|
|
8638
|
+
...hasProvider ? { launch: { provider: params.providerFlag } } : {}
|
|
8639
|
+
};
|
|
8384
8640
|
}
|
|
8385
|
-
var
|
|
8386
|
-
|
|
8641
|
+
var InvalidCliCategoryError, InvalidCliEntryKeyError;
|
|
8642
|
+
var init_cliOverride = __esm({
|
|
8643
|
+
"src/launcher/cliOverride.ts"() {
|
|
8387
8644
|
"use strict";
|
|
8645
|
+
init_pairs();
|
|
8646
|
+
init_schema();
|
|
8647
|
+
init_cliError();
|
|
8648
|
+
InvalidCliCategoryError = class extends CliError {
|
|
8649
|
+
constructor(categoryName) {
|
|
8650
|
+
super(`"${categoryName}" is not a category this launch may toggle (runtime, history, knowledge, settings).`);
|
|
8651
|
+
this.categoryName = categoryName;
|
|
8652
|
+
this.name = "InvalidCliCategoryError";
|
|
8653
|
+
}
|
|
8654
|
+
categoryName;
|
|
8655
|
+
};
|
|
8656
|
+
InvalidCliEntryKeyError = class extends CliError {
|
|
8657
|
+
constructor(key) {
|
|
8658
|
+
super(`"${key}" is not a valid entries key \u2014 it must start with "<category>/", e.g. "knowledge/skills/commit".`);
|
|
8659
|
+
this.key = key;
|
|
8660
|
+
this.name = "InvalidCliEntryKeyError";
|
|
8661
|
+
}
|
|
8662
|
+
key;
|
|
8663
|
+
};
|
|
8388
8664
|
}
|
|
8389
8665
|
});
|
|
8390
8666
|
|
|
8391
|
-
// src/
|
|
8392
|
-
function
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
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=")) {
|
|
8667
|
+
// src/headroom/headers.ts
|
|
8668
|
+
function mergeAnthropicCustomHeaders(existing, additions) {
|
|
8669
|
+
const merged = /* @__PURE__ */ new Map();
|
|
8670
|
+
for (const block of existing) {
|
|
8671
|
+
if (block === void 0) {
|
|
8403
8672
|
continue;
|
|
8404
8673
|
}
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8674
|
+
for (const line of block.split("\n")) {
|
|
8675
|
+
const entry = parseCustomHeaderLine(line);
|
|
8676
|
+
if (entry === void 0) {
|
|
8677
|
+
continue;
|
|
8408
8678
|
}
|
|
8409
|
-
|
|
8679
|
+
merged.set(entry.name, entry.value);
|
|
8410
8680
|
}
|
|
8411
|
-
kept.push(token);
|
|
8412
8681
|
}
|
|
8413
|
-
|
|
8682
|
+
for (const entry of additions) {
|
|
8683
|
+
merged.set(entry.name, entry.value);
|
|
8684
|
+
}
|
|
8685
|
+
return [...merged].map(([name, value]) => `${name}: ${value}`).join("\n");
|
|
8414
8686
|
}
|
|
8415
|
-
function
|
|
8416
|
-
const
|
|
8417
|
-
|
|
8687
|
+
function parseCustomHeaderLine(line) {
|
|
8688
|
+
const trimmed = line.trim();
|
|
8689
|
+
if (trimmed === "") {
|
|
8690
|
+
return void 0;
|
|
8691
|
+
}
|
|
8692
|
+
const colon = trimmed.indexOf(":");
|
|
8693
|
+
if (colon <= 0) {
|
|
8694
|
+
return void 0;
|
|
8695
|
+
}
|
|
8696
|
+
return { name: trimmed.slice(0, colon).trim(), value: trimmed.slice(colon + 1).trim() };
|
|
8418
8697
|
}
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8698
|
+
var init_headers = __esm({
|
|
8699
|
+
"src/headroom/headers.ts"() {
|
|
8700
|
+
"use strict";
|
|
8422
8701
|
}
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8702
|
+
});
|
|
8703
|
+
|
|
8704
|
+
// src/launcher/flags.ts
|
|
8705
|
+
import path37 from "node:path";
|
|
8706
|
+
function resolveLaunchFlags(params) {
|
|
8707
|
+
return {
|
|
8708
|
+
skipPermissions: params.flags?.skipPermissions ?? parseEnvBool("AGENT_SHIM_SKIP_PERMISSIONS", params.env.AGENT_SHIM_SKIP_PERMISSIONS) ?? params.cascade?.skipPermissions ?? false,
|
|
8709
|
+
remoteControl: params.flags?.remoteControl ?? parseEnvBool("AGENT_SHIM_REMOTE_CONTROL", params.env.AGENT_SHIM_REMOTE_CONTROL) ?? params.cascade?.remoteControl ?? false,
|
|
8710
|
+
headroom: params.flags?.headroom ?? parseEnvBool("AGENT_SHIM_HEADROOM", params.env.AGENT_SHIM_HEADROOM) ?? params.cascade?.headroom ?? false,
|
|
8711
|
+
trackUsage: params.flags?.trackUsage ?? parseEnvBool("AGENT_SHIM_TRACK_USAGE", params.env.AGENT_SHIM_TRACK_USAGE) ?? params.cascade?.trackUsage ?? true,
|
|
8712
|
+
pause: params.flags?.pause ?? parseEnvBool("AGENT_SHIM_PAUSE", params.env.AGENT_SHIM_PAUSE) ?? params.cascade?.pause ?? false,
|
|
8713
|
+
explain: params.flags?.explain ?? parseEnvBool("AGENT_SHIM_EXPLAIN", params.env.AGENT_SHIM_EXPLAIN) ?? params.cascade?.explain ?? false,
|
|
8714
|
+
routeByName: params.flags?.routeByName ?? parseEnvBool("AGENT_SHIM_ROUTE_BY_NAME", params.env.AGENT_SHIM_ROUTE_BY_NAME) ?? params.cascade?.routeByName ?? false,
|
|
8715
|
+
delayMs: resolveDelayMs(params)
|
|
8716
|
+
};
|
|
8717
|
+
}
|
|
8718
|
+
function resolveDelayMs(params) {
|
|
8719
|
+
const fromEnv = params.env.AGENT_SHIM_DELAY === "" ? void 0 : params.env.AGENT_SHIM_DELAY;
|
|
8720
|
+
const [literal, source] = params.flags?.delay !== void 0 ? [params.flags.delay, "--delay"] : fromEnv !== void 0 ? [fromEnv, "AGENT_SHIM_DELAY"] : [params.cascade?.delay, "launch.delay"];
|
|
8721
|
+
if (literal === void 0) {
|
|
8722
|
+
return 0;
|
|
8426
8723
|
}
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
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
|
-
}
|
|
8724
|
+
try {
|
|
8725
|
+
return parseDuration(literal);
|
|
8726
|
+
} catch (error) {
|
|
8727
|
+
throw new UsageError(`${source}: ${error instanceof Error ? error.message : String(error)}`);
|
|
8440
8728
|
}
|
|
8441
|
-
return [...kept, "--model", supervised.model, ...tail];
|
|
8442
8729
|
}
|
|
8443
|
-
function
|
|
8444
|
-
|
|
8445
|
-
|
|
8730
|
+
function buildFlagArgs(flags) {
|
|
8731
|
+
const args = [];
|
|
8732
|
+
if (flags.skipPermissions) {
|
|
8733
|
+
args.push("--dangerously-skip-permissions");
|
|
8446
8734
|
}
|
|
8447
|
-
|
|
8448
|
-
|
|
8735
|
+
if (flags.remoteControl) {
|
|
8736
|
+
args.push("--remote-control=");
|
|
8737
|
+
}
|
|
8738
|
+
return args;
|
|
8449
8739
|
}
|
|
8450
|
-
function
|
|
8451
|
-
return
|
|
8740
|
+
function buildArgv(params) {
|
|
8741
|
+
return [...params.toolFlags, ...params.extraFlags, ...params.passthrough];
|
|
8452
8742
|
}
|
|
8453
|
-
function
|
|
8454
|
-
const
|
|
8455
|
-
|
|
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;
|
|
8743
|
+
function withLoopbackHosts(existing) {
|
|
8744
|
+
const listed = (existing ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== "");
|
|
8745
|
+
return [...listed, ...LOOPBACK_HOSTS.filter((host) => !listed.includes(host))].join(",");
|
|
8473
8746
|
}
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
VALUED_CONVERSATION_FLAGS = /* @__PURE__ */ new Set(["--resume", "-r", "--session-id"]);
|
|
8481
|
-
CONTINUE_FLAGS = /* @__PURE__ */ new Set(["--continue", "-c"]);
|
|
8747
|
+
function buildEnv(params) {
|
|
8748
|
+
const env = { ...params.baseEnv };
|
|
8749
|
+
const parentCustomHeaders = params.baseEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
8750
|
+
let providerCustomHeaders;
|
|
8751
|
+
if (!params.configDirEscapeHatch && params.resolvedIdentityName !== void 0) {
|
|
8752
|
+
env.CLAUDE_CONFIG_DIR = path37.join(params.identitiesDir, params.resolvedIdentityName);
|
|
8482
8753
|
}
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
|
|
8487
|
-
|
|
8488
|
-
|
|
8489
|
-
|
|
8490
|
-
for (const diagnostic of diagnostics) {
|
|
8491
|
-
if (diagnostic.severity === "info") {
|
|
8492
|
-
continue;
|
|
8493
|
-
}
|
|
8494
|
-
if (diagnostic.code === "UNCLASSIFIED_ENTRY") {
|
|
8495
|
-
if (!unclassifiedReported) {
|
|
8496
|
-
unclassifiedReported = true;
|
|
8497
|
-
const names = unclassified.filter((name) => name !== void 0);
|
|
8498
|
-
lines.push({ severity: diagnostic.severity, text: `agent-shim: ${diagnostic.code}: ${unclassifiedEntrySummary(names)}
|
|
8499
|
-
${unclassifiedEntryFix(names)}.` });
|
|
8500
|
-
}
|
|
8501
|
-
continue;
|
|
8754
|
+
if (params.provider !== void 0) {
|
|
8755
|
+
const providerEnv = params.provider.definition.kind !== void 0 && params.provider.definition.kind !== "http" ? {} : params.provider.definition.env ?? {};
|
|
8756
|
+
providerCustomHeaders = providerEnv.ANTHROPIC_CUSTOM_HEADERS;
|
|
8757
|
+
env.ANTHROPIC_BASE_URL = void 0;
|
|
8758
|
+
env.AGENT_SHIM_PROVIDER = params.provider.definition.displayName;
|
|
8759
|
+
for (const [key, value] of Object.entries(providerEnv)) {
|
|
8760
|
+
env[key] = value;
|
|
8502
8761
|
}
|
|
8503
|
-
lines.push({ severity: diagnostic.severity, text: `agent-shim: ${diagnostic.code}: ${diagnostic.message}` });
|
|
8504
8762
|
}
|
|
8505
|
-
|
|
8506
|
-
|
|
8507
|
-
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
log.warn(line.text);
|
|
8763
|
+
if (params.provider !== void 0) {
|
|
8764
|
+
env.ANTHROPIC_AUTH_TOKEN = params.remoteControl ? void 0 : PROVIDER_SESSION_PLACEHOLDER;
|
|
8765
|
+
env.ANTHROPIC_API_KEY = void 0;
|
|
8766
|
+
env.CLAUDE_CODE_OAUTH_TOKEN = void 0;
|
|
8767
|
+
} else if (params.identityCredential !== void 0) {
|
|
8768
|
+
for (const [variable, value] of Object.entries(credentialVariables(params.identityCredential.target, params.identityCredential.token))) {
|
|
8769
|
+
env[variable] = value;
|
|
8513
8770
|
}
|
|
8514
8771
|
}
|
|
8772
|
+
if (params.frontdoor !== void 0) {
|
|
8773
|
+
env.ANTHROPIC_CUSTOM_HEADERS = mergeAnthropicCustomHeaders(
|
|
8774
|
+
[
|
|
8775
|
+
...parentCustomHeaders === void 0 ? [] : [parentCustomHeaders],
|
|
8776
|
+
...providerCustomHeaders === void 0 ? [] : [providerCustomHeaders]
|
|
8777
|
+
],
|
|
8778
|
+
[
|
|
8779
|
+
...params.resolvedIdentityName === void 0 ? [] : [{ name: IDENTITY_HEADER, value: params.resolvedIdentityName }],
|
|
8780
|
+
{ name: SESSION_HEADER, value: params.sessionId },
|
|
8781
|
+
{ name: AUTH_HEADER, value: params.frontdoor.sessionToken },
|
|
8782
|
+
...params.provider === void 0 ? [] : [{ name: PROVIDER_HEADER, value: params.provider.name }],
|
|
8783
|
+
...params.routeByName ? [{ name: ROUTE_BY_NAME_HEADER, value: "1" }] : [],
|
|
8784
|
+
...params.headroom === void 0 ? [] : [
|
|
8785
|
+
{ name: HEADROOM_FLAG_HEADER, value: "1" },
|
|
8786
|
+
{ name: PROJECT_ID_HEADER, value: params.headroom.projectId }
|
|
8787
|
+
]
|
|
8788
|
+
]
|
|
8789
|
+
);
|
|
8790
|
+
env.NODE_EXTRA_CA_CERTS = params.frontdoor.trustBundlePath;
|
|
8791
|
+
env.HTTPS_PROXY = connectProxyUrl(params.frontdoor.connectPort, params.frontdoor.sessionToken);
|
|
8792
|
+
env.NO_PROXY = withLoopbackHosts(env.NO_PROXY);
|
|
8793
|
+
env.no_proxy = withLoopbackHosts(env.no_proxy);
|
|
8794
|
+
}
|
|
8795
|
+
return env;
|
|
8515
8796
|
}
|
|
8516
|
-
|
|
8517
|
-
|
|
8518
|
-
|
|
8519
|
-
var init_diagnostics = __esm({
|
|
8520
|
-
"src/launcher/diagnostics.ts"() {
|
|
8797
|
+
var LOOPBACK_HOSTS, PROVIDER_SESSION_PLACEHOLDER;
|
|
8798
|
+
var init_flags = __esm({
|
|
8799
|
+
"src/launcher/flags.ts"() {
|
|
8521
8800
|
"use strict";
|
|
8522
|
-
|
|
8801
|
+
init_envBool();
|
|
8802
|
+
init_cliError();
|
|
8803
|
+
init_conditions();
|
|
8804
|
+
init_credential();
|
|
8805
|
+
init_headers();
|
|
8806
|
+
init_capability();
|
|
8807
|
+
init_route();
|
|
8808
|
+
LOOPBACK_HOSTS = ["127.0.0.1", "localhost", "::1"];
|
|
8809
|
+
PROVIDER_SESSION_PLACEHOLDER = "agent-shim-provider-session";
|
|
8523
8810
|
}
|
|
8524
8811
|
});
|
|
8525
8812
|
|
|
8526
|
-
// src/launcher/
|
|
8527
|
-
function
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
function holdBeforeLaunch(hold, port, log) {
|
|
8531
|
-
if (port === void 0 || !port.attended() || !hold.pause && hold.delayMs <= 0) {
|
|
8532
|
-
return "go";
|
|
8533
|
-
}
|
|
8534
|
-
if (hold.pause) {
|
|
8535
|
-
log.info("agent-shim: paused before launch; press any key to start, or Ctrl-C to cancel");
|
|
8536
|
-
return port.waitForKey() === "interrupt" ? "cancelled" : "go";
|
|
8813
|
+
// src/launcher/extraFlags.ts
|
|
8814
|
+
function splitExtraFlags(value) {
|
|
8815
|
+
if (value === void 0) {
|
|
8816
|
+
return [];
|
|
8537
8817
|
}
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
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;
|
|
8818
|
+
const trimmed = value.trim();
|
|
8819
|
+
if (trimmed === "") {
|
|
8820
|
+
return [];
|
|
8548
8821
|
}
|
|
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}`;
|
|
8822
|
+
return trimmed.split(/\s+/);
|
|
8556
8823
|
}
|
|
8557
|
-
var
|
|
8558
|
-
"src/
|
|
8824
|
+
var init_extraFlags = __esm({
|
|
8825
|
+
"src/launcher/extraFlags.ts"() {
|
|
8559
8826
|
"use strict";
|
|
8560
8827
|
}
|
|
8561
8828
|
});
|
|
8562
8829
|
|
|
8563
|
-
// src/
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
return { detail: `moved off ${pool.movedOff.identity}: ${pool.movedOff.reason}`, ...reason === void 0 ? {} : { notes: [reason] } };
|
|
8568
|
-
}
|
|
8569
|
-
return reason === void 0 ? {} : { detail: reason };
|
|
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}` };
|
|
8830
|
+
// src/usage/resumeContext.ts
|
|
8831
|
+
import path38 from "node:path";
|
|
8832
|
+
function projectDirNameOf(cwd) {
|
|
8833
|
+
return cwd.replace(/[^A-Za-z0-9]/g, "-");
|
|
8595
8834
|
}
|
|
8596
|
-
function
|
|
8597
|
-
|
|
8598
|
-
|
|
8835
|
+
function resumeTargetOf(passthrough) {
|
|
8836
|
+
const end = passthrough.indexOf("--");
|
|
8837
|
+
const tokens = end === -1 ? passthrough : passthrough.slice(0, end);
|
|
8838
|
+
for (const [index, token] of tokens.entries()) {
|
|
8839
|
+
if (token === "--continue" || token === "-c") {
|
|
8840
|
+
return { kind: "latest" };
|
|
8841
|
+
}
|
|
8842
|
+
if (token === "--resume" || token === "-r") {
|
|
8843
|
+
const next = tokens[index + 1];
|
|
8844
|
+
return next === void 0 || next.startsWith("-") ? void 0 : { kind: "id", id: next };
|
|
8845
|
+
}
|
|
8846
|
+
if (token.startsWith("--resume=")) {
|
|
8847
|
+
const id = token.slice("--resume=".length);
|
|
8848
|
+
return id === "" ? void 0 : { kind: "id", id };
|
|
8849
|
+
}
|
|
8599
8850
|
}
|
|
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(", ") };
|
|
8851
|
+
return void 0;
|
|
8613
8852
|
}
|
|
8614
|
-
function
|
|
8615
|
-
|
|
8853
|
+
function countOf(usage, key) {
|
|
8854
|
+
const value = key in usage ? Reflect.get(usage, key) : void 0;
|
|
8855
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
8616
8856
|
}
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
|
|
8620
|
-
|
|
8857
|
+
function contextTokensOfTranscript(text) {
|
|
8858
|
+
const lines = text.split("\n");
|
|
8859
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
8860
|
+
const line = lines[index];
|
|
8861
|
+
if (line === void 0 || line === "") {
|
|
8862
|
+
continue;
|
|
8863
|
+
}
|
|
8864
|
+
let parsed;
|
|
8865
|
+
try {
|
|
8866
|
+
parsed = JSON.parse(line);
|
|
8867
|
+
} catch {
|
|
8868
|
+
continue;
|
|
8869
|
+
}
|
|
8870
|
+
if (typeof parsed !== "object" || parsed === null || !("type" in parsed) || parsed.type !== "assistant" || !("message" in parsed)) {
|
|
8871
|
+
continue;
|
|
8872
|
+
}
|
|
8873
|
+
const { message } = parsed;
|
|
8874
|
+
if (typeof message !== "object" || message === null || !("usage" in message) || typeof message.usage !== "object" || message.usage === null) {
|
|
8875
|
+
continue;
|
|
8876
|
+
}
|
|
8877
|
+
const { usage } = message;
|
|
8878
|
+
return countOf(usage, "input_tokens") + countOf(usage, "cache_read_input_tokens") + countOf(usage, "cache_creation_input_tokens");
|
|
8621
8879
|
}
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
// src/models/identity.ts
|
|
8625
|
-
function withoutContextMarker(model) {
|
|
8626
|
-
return model.toLowerCase().endsWith(CONTEXT_MARKER_1M) ? model.slice(0, -CONTEXT_MARKER_1M.length) : model;
|
|
8880
|
+
return void 0;
|
|
8627
8881
|
}
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
deepseek: "deepseek",
|
|
8642
|
-
moonshot: "moonshot",
|
|
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
|
-
});
|
|
8660
|
-
}
|
|
8661
|
-
});
|
|
8662
|
-
|
|
8663
|
-
// src/selection/engine.ts
|
|
8664
|
-
var init_engine = __esm({
|
|
8665
|
-
"src/selection/engine.ts"() {
|
|
8666
|
-
"use strict";
|
|
8667
|
-
}
|
|
8668
|
-
});
|
|
8669
|
-
|
|
8670
|
-
// src/antigravity/cloudUpstream.ts
|
|
8671
|
-
var init_cloudUpstream = __esm({
|
|
8672
|
-
"src/antigravity/cloudUpstream.ts"() {
|
|
8673
|
-
"use strict";
|
|
8674
|
-
}
|
|
8675
|
-
});
|
|
8676
|
-
|
|
8677
|
-
// src/antigravity/quota.ts
|
|
8678
|
-
var SECONDS_PER_HOUR, HOURS_PER_FIVE_HOUR_WINDOW, DAYS_PER_WEEK, HOURS_PER_DAY4, FIVE_HOUR_PERIOD_SECONDS, WEEK_PERIOD_SECONDS;
|
|
8679
|
-
var init_quota = __esm({
|
|
8680
|
-
"src/antigravity/quota.ts"() {
|
|
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;
|
|
8882
|
+
function newestTranscript(fs13, projectDir) {
|
|
8883
|
+
let newest;
|
|
8884
|
+
let newestMs = -Infinity;
|
|
8885
|
+
for (const name of fs13.readdir(projectDir)) {
|
|
8886
|
+
if (!name.endsWith(".jsonl")) {
|
|
8887
|
+
continue;
|
|
8888
|
+
}
|
|
8889
|
+
const candidate = path38.join(projectDir, name);
|
|
8890
|
+
const stat = fs13.lstat(candidate);
|
|
8891
|
+
if (stat?.kind === "file" && stat.mtimeMs > newestMs) {
|
|
8892
|
+
newestMs = stat.mtimeMs;
|
|
8893
|
+
newest = candidate;
|
|
8894
|
+
}
|
|
8689
8895
|
}
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
|
|
8896
|
+
return newest;
|
|
8897
|
+
}
|
|
8898
|
+
function resumedContextTokens(fs13, params) {
|
|
8899
|
+
const target = resumeTargetOf(params.passthrough);
|
|
8900
|
+
if (target === void 0) {
|
|
8901
|
+
return void 0;
|
|
8696
8902
|
}
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
var
|
|
8703
|
-
"src/
|
|
8903
|
+
const projectDir = path38.join(params.claudeHome, "projects", projectDirNameOf(params.cwd));
|
|
8904
|
+
const file = target.kind === "id" ? path38.join(projectDir, `${target.id}.jsonl`) : newestTranscript(fs13, projectDir);
|
|
8905
|
+
const text = file === void 0 ? void 0 : fs13.readFileUtf8(file);
|
|
8906
|
+
return text === void 0 ? void 0 : contextTokensOfTranscript(text);
|
|
8907
|
+
}
|
|
8908
|
+
var init_resumeContext = __esm({
|
|
8909
|
+
"src/usage/resumeContext.ts"() {
|
|
8704
8910
|
"use strict";
|
|
8705
|
-
TextBlockSchema = z29.looseObject({ type: z29.literal("text"), text: z29.string() });
|
|
8706
|
-
Base64ImageSourceSchema = z29.looseObject({ type: z29.literal("base64"), media_type: z29.string().min(1), data: z29.string() });
|
|
8707
|
-
UrlImageSourceSchema = z29.looseObject({ type: z29.literal("url"), url: z29.string().min(1) });
|
|
8708
|
-
ImageBlockSchema = z29.looseObject({
|
|
8709
|
-
type: z29.literal("image"),
|
|
8710
|
-
source: z29.union([Base64ImageSourceSchema, UrlImageSourceSchema])
|
|
8711
|
-
});
|
|
8712
|
-
ToolUseBlockSchema = z29.looseObject({
|
|
8713
|
-
type: z29.literal("tool_use"),
|
|
8714
|
-
id: z29.string().min(1),
|
|
8715
|
-
name: z29.string().min(1),
|
|
8716
|
-
input: z29.unknown()
|
|
8717
|
-
});
|
|
8718
|
-
ToolResultContentBlockSchema = z29.union([TextBlockSchema, z29.looseObject({ type: z29.string() })]);
|
|
8719
|
-
ToolResultBlockSchema = z29.looseObject({
|
|
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
|
-
});
|
|
8757
8911
|
}
|
|
8758
8912
|
});
|
|
8759
8913
|
|
|
8760
|
-
// src/
|
|
8761
|
-
function
|
|
8762
|
-
return
|
|
8914
|
+
// src/launcher/claudeSession.ts
|
|
8915
|
+
function isFlag(token) {
|
|
8916
|
+
return token?.startsWith("-") === true;
|
|
8763
8917
|
}
|
|
8764
|
-
function
|
|
8765
|
-
|
|
8918
|
+
function withConversation(passthrough, conversation, id) {
|
|
8919
|
+
const end = passthrough.indexOf(TERMINATOR2);
|
|
8920
|
+
const head = end === -1 ? passthrough : passthrough.slice(0, end);
|
|
8921
|
+
const tail = end === -1 ? [] : passthrough.slice(end);
|
|
8922
|
+
const kept = [];
|
|
8923
|
+
for (let index = 0; index < head.length; index += 1) {
|
|
8924
|
+
const token = head[index];
|
|
8925
|
+
if (token === void 0 || CONTINUE_FLAGS.has(token) || token.startsWith("--resume=") || token.startsWith("--session-id=")) {
|
|
8926
|
+
continue;
|
|
8927
|
+
}
|
|
8928
|
+
if (VALUED_CONVERSATION_FLAGS.has(token)) {
|
|
8929
|
+
if (!isFlag(head[index + 1]) && head[index + 1] !== void 0) {
|
|
8930
|
+
index += 1;
|
|
8931
|
+
}
|
|
8932
|
+
continue;
|
|
8933
|
+
}
|
|
8934
|
+
kept.push(token);
|
|
8935
|
+
}
|
|
8936
|
+
return [...kept, conversation === "start" ? "--session-id" : "--resume", id, ...tail];
|
|
8766
8937
|
}
|
|
8767
|
-
function
|
|
8768
|
-
const
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8938
|
+
function hasSettingsArgument(passthrough) {
|
|
8939
|
+
const end = passthrough.indexOf(TERMINATOR2);
|
|
8940
|
+
return (end === -1 ? passthrough : passthrough.slice(0, end)).some((token) => token === "--settings" || token.startsWith("--settings="));
|
|
8941
|
+
}
|
|
8942
|
+
function withSupervision(passthrough, supervised) {
|
|
8943
|
+
if (supervised.conversation === "as-given") {
|
|
8944
|
+
return passthrough;
|
|
8945
|
+
}
|
|
8946
|
+
const conversed = withConversation(passthrough, supervised.conversation, supervised.sessionId);
|
|
8947
|
+
if (supervised.model === void 0) {
|
|
8948
|
+
return conversed;
|
|
8949
|
+
}
|
|
8950
|
+
const end = conversed.indexOf(TERMINATOR2);
|
|
8951
|
+
const head = end === -1 ? conversed : conversed.slice(0, end);
|
|
8952
|
+
const tail = end === -1 ? [] : conversed.slice(end);
|
|
8953
|
+
const kept = [];
|
|
8954
|
+
for (let index = 0; index < head.length; index += 1) {
|
|
8955
|
+
const token = head[index];
|
|
8956
|
+
if (token === "--model") {
|
|
8957
|
+
index += 1;
|
|
8958
|
+
continue;
|
|
8959
|
+
}
|
|
8960
|
+
if (token !== void 0 && !token.startsWith("--model=")) {
|
|
8961
|
+
kept.push(token);
|
|
8773
8962
|
}
|
|
8774
8963
|
}
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
|
|
8780
|
-
aliases.set(AUTO_ALIAS, [...new Set(CLAUDE_TIERS.flatMap(tierModel))]);
|
|
8964
|
+
return [...kept, "--model", supervised.model, ...tail];
|
|
8965
|
+
}
|
|
8966
|
+
function withLauncherSettings(passthrough, settings) {
|
|
8967
|
+
if (settings === void 0) {
|
|
8968
|
+
return passthrough;
|
|
8781
8969
|
}
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
local: {
|
|
8795
|
-
command: config?.local?.command,
|
|
8796
|
-
socketPath: config?.local?.socketPath
|
|
8970
|
+
const end = passthrough.indexOf(TERMINATOR2);
|
|
8971
|
+
return end === -1 ? [...passthrough, "--settings", settings] : [...passthrough.slice(0, end), "--settings", settings, ...passthrough.slice(end)];
|
|
8972
|
+
}
|
|
8973
|
+
function isRecord15(value) {
|
|
8974
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8975
|
+
}
|
|
8976
|
+
function mergeSettings(parts) {
|
|
8977
|
+
const merged = {};
|
|
8978
|
+
let any = false;
|
|
8979
|
+
for (const part of parts) {
|
|
8980
|
+
if (part === void 0) {
|
|
8981
|
+
continue;
|
|
8797
8982
|
}
|
|
8798
|
-
|
|
8983
|
+
const parsed = JSON.parse(part);
|
|
8984
|
+
if (!isRecord15(parsed)) {
|
|
8985
|
+
throw new Error("a launch's settings part is not a JSON object");
|
|
8986
|
+
}
|
|
8987
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
8988
|
+
if (key in merged) {
|
|
8989
|
+
throw new Error(`two launch settings parts both set "${key}"`);
|
|
8990
|
+
}
|
|
8991
|
+
merged[key] = value;
|
|
8992
|
+
}
|
|
8993
|
+
any = true;
|
|
8994
|
+
}
|
|
8995
|
+
return any ? JSON.stringify(merged) : void 0;
|
|
8799
8996
|
}
|
|
8800
|
-
var
|
|
8801
|
-
var
|
|
8802
|
-
"src/
|
|
8997
|
+
var TERMINATOR2, VALUED_CONVERSATION_FLAGS, CONTINUE_FLAGS;
|
|
8998
|
+
var init_claudeSession = __esm({
|
|
8999
|
+
"src/launcher/claudeSession.ts"() {
|
|
8803
9000
|
"use strict";
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
init_schema();
|
|
8809
|
-
init_anthropic();
|
|
8810
|
-
AUTO_ALIAS = "auto";
|
|
9001
|
+
init_resumeContext();
|
|
9002
|
+
TERMINATOR2 = "--";
|
|
9003
|
+
VALUED_CONVERSATION_FLAGS = /* @__PURE__ */ new Set(["--resume", "-r", "--session-id"]);
|
|
9004
|
+
CONTINUE_FLAGS = /* @__PURE__ */ new Set(["--continue", "-c"]);
|
|
8811
9005
|
}
|
|
8812
9006
|
});
|
|
8813
9007
|
|
|
8814
|
-
// src/
|
|
8815
|
-
function
|
|
8816
|
-
const
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
9008
|
+
// src/launcher/diagnostics.ts
|
|
9009
|
+
function diagnosticLines(diagnostics) {
|
|
9010
|
+
const unclassified = [...new Set(diagnostics.filter((diagnostic) => diagnostic.code === "UNCLASSIFIED_ENTRY").map((diagnostic) => diagnostic.subject))];
|
|
9011
|
+
const lines = [];
|
|
9012
|
+
let unclassifiedReported = false;
|
|
9013
|
+
for (const diagnostic of diagnostics) {
|
|
9014
|
+
if (diagnostic.severity === "info") {
|
|
9015
|
+
continue;
|
|
9016
|
+
}
|
|
9017
|
+
if (diagnostic.code === "UNCLASSIFIED_ENTRY") {
|
|
9018
|
+
if (!unclassifiedReported) {
|
|
9019
|
+
unclassifiedReported = true;
|
|
9020
|
+
const names = unclassified.filter((name) => name !== void 0);
|
|
9021
|
+
lines.push({ severity: diagnostic.severity, text: `agent-shim: ${diagnostic.code}: ${unclassifiedEntrySummary(names)}
|
|
9022
|
+
${unclassifiedEntryFix(names)}.` });
|
|
9023
|
+
}
|
|
9024
|
+
continue;
|
|
9025
|
+
}
|
|
9026
|
+
lines.push({ severity: diagnostic.severity, text: `agent-shim: ${diagnostic.code}: ${diagnostic.message}` });
|
|
9027
|
+
}
|
|
9028
|
+
return lines;
|
|
8828
9029
|
}
|
|
8829
|
-
|
|
8830
|
-
|
|
9030
|
+
function printDiagnosticLines(log, lines, options) {
|
|
9031
|
+
for (const line of lines) {
|
|
9032
|
+
if (line.severity === "error" && !options.errorsAsWarnings) {
|
|
9033
|
+
log.error(line.text);
|
|
9034
|
+
} else {
|
|
9035
|
+
log.warn(line.text);
|
|
9036
|
+
}
|
|
9037
|
+
}
|
|
9038
|
+
}
|
|
9039
|
+
function reportDiagnostics(log, diagnostics, options) {
|
|
9040
|
+
printDiagnosticLines(log, diagnosticLines(diagnostics), options);
|
|
9041
|
+
}
|
|
9042
|
+
var init_diagnostics = __esm({
|
|
9043
|
+
"src/launcher/diagnostics.ts"() {
|
|
8831
9044
|
"use strict";
|
|
8832
|
-
|
|
8833
|
-
init_anthropic();
|
|
9045
|
+
init_decide();
|
|
8834
9046
|
}
|
|
8835
9047
|
});
|
|
8836
9048
|
|
|
8837
|
-
// src/
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
import { z as z30 } from "zod";
|
|
8841
|
-
function catalogueCachePath(paths, name) {
|
|
8842
|
-
return path38.join(paths.catalogueDir, `${name}.json`);
|
|
9049
|
+
// src/launcher/hold.ts
|
|
9050
|
+
function describeDelay(ms) {
|
|
9051
|
+
return ms % MS_PER_SECOND8 === 0 ? `${String(ms / MS_PER_SECOND8)}s` : `${String(ms)}ms`;
|
|
8843
9052
|
}
|
|
8844
|
-
function
|
|
8845
|
-
if (
|
|
8846
|
-
return
|
|
9053
|
+
function holdBeforeLaunch(hold, port, log) {
|
|
9054
|
+
if (port === void 0 || !port.attended() || !hold.pause && hold.delayMs <= 0) {
|
|
9055
|
+
return "go";
|
|
8847
9056
|
}
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
return
|
|
8851
|
-
} catch {
|
|
8852
|
-
return void 0;
|
|
9057
|
+
if (hold.pause) {
|
|
9058
|
+
log.info("agent-shim: paused before launch; press any key to start, or Ctrl-C to cancel");
|
|
9059
|
+
return port.waitForKey() === "interrupt" ? "cancelled" : "go";
|
|
8853
9060
|
}
|
|
9061
|
+
log.info(`agent-shim: starting in ${describeDelay(hold.delayMs)}`);
|
|
9062
|
+
port.sleep(hold.delayMs);
|
|
9063
|
+
return "go";
|
|
8854
9064
|
}
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
return models.filter((model) => included?.(model.id) !== false && excluded?.(model.id) !== true);
|
|
8859
|
-
}
|
|
8860
|
-
var DEFAULT_CANDIDATE_URLS, MS_PER_SECOND8, SECONDS_PER_HOUR2, HOURS_PER_DAY5, MS_PER_HOUR5, HOURS_BETWEEN_RETRIES, CATALOGUE_MAX_AGE_MS, CATALOGUE_RETRY_MS, CATALOGUE_REQUEST_SECONDS, CATALOGUE_REQUEST_TIMEOUT_MS, CATALOGUE_REFRESH_TIMEOUT_MS, CatalogueModelSchema, CatalogueCacheSchema;
|
|
8861
|
-
var init_providerCatalogue = __esm({
|
|
8862
|
-
"src/providerCatalogue.ts"() {
|
|
9065
|
+
var LAUNCH_CANCELLED_EXIT, MS_PER_SECOND8;
|
|
9066
|
+
var init_hold = __esm({
|
|
9067
|
+
"src/launcher/hold.ts"() {
|
|
8863
9068
|
"use strict";
|
|
8864
|
-
|
|
8865
|
-
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) });
|
|
9069
|
+
LAUNCH_CANCELLED_EXIT = 130;
|
|
9070
|
+
MS_PER_SECOND8 = 1e3;
|
|
8877
9071
|
}
|
|
8878
9072
|
});
|
|
8879
9073
|
|
|
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}`;
|
|
9074
|
+
// src/usage/candidateText.ts
|
|
9075
|
+
function candidateHeading(candidate) {
|
|
9076
|
+
const score = candidate.score === void 0 ? "" : ` score ${candidate.score.toFixed(2)}${candidate.scoreWindow === "fiveHour" ? " by 5h reset" : " by 7d reset"}`;
|
|
9077
|
+
const dry = candidate.feasible ? "" : " (5h would run dry)";
|
|
9078
|
+
return `[${candidate.class}${score}]${dry}`;
|
|
8890
9079
|
}
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
throw new Error(`model ${model} is reached by no tier`);
|
|
9080
|
+
var init_candidateText = __esm({
|
|
9081
|
+
"src/usage/candidateText.ts"() {
|
|
9082
|
+
"use strict";
|
|
8895
9083
|
}
|
|
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
|
-
});
|
|
9084
|
+
});
|
|
9085
|
+
|
|
9086
|
+
// src/launcher/launchReport.ts
|
|
9087
|
+
function poolDetail(pool) {
|
|
9088
|
+
const [reason] = pool.reasons;
|
|
9089
|
+
if (pool.movedOff !== void 0) {
|
|
9090
|
+
return { detail: `moved off ${pool.movedOff.identity}: ${pool.movedOff.reason}`, ...reason === void 0 ? {} : { notes: [reason] } };
|
|
8912
9091
|
}
|
|
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)];
|
|
9092
|
+
return reason === void 0 ? {} : { detail: reason };
|
|
8926
9093
|
}
|
|
8927
|
-
function
|
|
8928
|
-
|
|
8929
|
-
|
|
9094
|
+
function rankingNotes(ranking, picked) {
|
|
9095
|
+
return ranking.flatMap((candidate, index) => [
|
|
9096
|
+
`${String(index + 1)}. ${candidate.identity} ${candidateHeading(candidate)}${candidate.identity === picked ? " (picked)" : ""}`,
|
|
9097
|
+
` ${candidate.reasons.join("; ")}`
|
|
9098
|
+
]);
|
|
8930
9099
|
}
|
|
8931
|
-
function
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
9100
|
+
function decisionRows(facts) {
|
|
9101
|
+
return [
|
|
9102
|
+
{ label: "identity", value: facts.identity ?? "(none)", detail: facts.identitySource },
|
|
9103
|
+
...facts.pool === void 0 ? [] : [
|
|
9104
|
+
{
|
|
9105
|
+
label: "pool",
|
|
9106
|
+
value: facts.pool.name,
|
|
9107
|
+
...poolDetail(facts.pool),
|
|
9108
|
+
...facts.ranking === void 0 ? {} : { notes: rankingNotes(facts.ranking, facts.identity) }
|
|
9109
|
+
}
|
|
9110
|
+
],
|
|
9111
|
+
...facts.profile === void 0 ? [] : [{ label: "profile", value: facts.profile.name, detail: facts.profile.source }],
|
|
9112
|
+
...facts.provider === void 0 ? [] : [{ label: "provider", value: facts.provider.name, detail: `credential ${facts.provider.credential}` }],
|
|
9113
|
+
...facts.identityCredential === void 0 ? [] : [{ label: "credential", value: facts.identityCredential, detail: "the identity's own" }]
|
|
9114
|
+
];
|
|
8938
9115
|
}
|
|
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
|
-
};
|
|
9116
|
+
function pinnedVersionRow(version, source) {
|
|
9117
|
+
return { label: "claude", value: version, detail: `pinned by ${source}` };
|
|
8946
9118
|
}
|
|
8947
|
-
function
|
|
8948
|
-
if (
|
|
9119
|
+
function routingRows(facts) {
|
|
9120
|
+
if (facts.frontDoor === void 0) {
|
|
8949
9121
|
return [];
|
|
8950
9122
|
}
|
|
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))];
|
|
9123
|
+
return [
|
|
9124
|
+
{
|
|
9125
|
+
label: "routing",
|
|
9126
|
+
value: `front door 127.0.0.1:${String(facts.frontDoor.port)}`,
|
|
9127
|
+
...facts.provider ? {} : { detail: `OAuth via CONNECT 127.0.0.1:${String(facts.frontDoor.connectPort)}` }
|
|
9128
|
+
},
|
|
9129
|
+
...facts.headroom === void 0 ? [] : [{ label: "headroom", value: "on", detail: `project ${facts.headroom.projectId}` }]
|
|
9130
|
+
];
|
|
8990
9131
|
}
|
|
8991
|
-
function
|
|
8992
|
-
|
|
9132
|
+
function farmRow(links, builtDirectories, adopted) {
|
|
9133
|
+
const counted = (count, singular, plural) => `${String(count)} ${count === 1 ? singular : plural}`;
|
|
9134
|
+
const parts = [counted(links, "link", "links"), counted(builtDirectories, "built directory", "built directories"), ...adopted === 0 ? [] : [`${String(adopted)} adopted`]];
|
|
9135
|
+
return { label: "farm", value: "resynced", detail: parts.join(", ") };
|
|
8993
9136
|
}
|
|
8994
|
-
function
|
|
8995
|
-
return
|
|
9137
|
+
function noteRow(text) {
|
|
9138
|
+
return { label: "note", value: text };
|
|
8996
9139
|
}
|
|
8997
|
-
var
|
|
8998
|
-
|
|
8999
|
-
"src/launcher/modelPicker.ts"() {
|
|
9140
|
+
var init_launchReport = __esm({
|
|
9141
|
+
"src/launcher/launchReport.ts"() {
|
|
9000
9142
|
"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
|
-
});
|
|
9143
|
+
init_candidateText();
|
|
9018
9144
|
}
|
|
9019
9145
|
});
|
|
9020
9146
|
|
|
@@ -14775,8 +14901,8 @@ var ResetRowSchema = z18.strictObject({
|
|
|
14775
14901
|
var ResetScheduleSchema = z18.strictObject({ resets: z18.readonly(z18.array(ResetRowSchema)) });
|
|
14776
14902
|
|
|
14777
14903
|
// src/frontdoor/controlSchemas.ts
|
|
14778
|
-
import
|
|
14779
|
-
import { z as
|
|
14904
|
+
import path32 from "node:path";
|
|
14905
|
+
import { z as z25 } from "zod";
|
|
14780
14906
|
|
|
14781
14907
|
// src/doctorReport.ts
|
|
14782
14908
|
init_claudeShim();
|
|
@@ -14952,7 +15078,7 @@ function removeIdentity(paths, name) {
|
|
|
14952
15078
|
// src/doctorReport.ts
|
|
14953
15079
|
init_realPorts();
|
|
14954
15080
|
import fs11 from "node:fs";
|
|
14955
|
-
import
|
|
15081
|
+
import path31 from "node:path";
|
|
14956
15082
|
init_signIn();
|
|
14957
15083
|
|
|
14958
15084
|
// src/codex/siwcStore.ts
|
|
@@ -15043,6 +15169,57 @@ init_source();
|
|
|
15043
15169
|
|
|
15044
15170
|
// src/models/doctor.ts
|
|
15045
15171
|
init_modelsStore();
|
|
15172
|
+
|
|
15173
|
+
// src/models/families.ts
|
|
15174
|
+
init_identity2();
|
|
15175
|
+
var FAMILY_PREFIX = "family:";
|
|
15176
|
+
var VARIANT_SEPARATOR = "+";
|
|
15177
|
+
function modelOf(ref) {
|
|
15178
|
+
const slash = ref.indexOf("/");
|
|
15179
|
+
return slash === -1 ? ref : ref.slice(slash + 1);
|
|
15180
|
+
}
|
|
15181
|
+
function familyKeyOf(rawModel) {
|
|
15182
|
+
const identity = modelIdentity(rawModel);
|
|
15183
|
+
return identity.variant === "" ? identity.familyAndVersion : `${identity.familyAndVersion}${VARIANT_SEPARATOR}${identity.variant}`;
|
|
15184
|
+
}
|
|
15185
|
+
function assertionsOf(models) {
|
|
15186
|
+
return { same: models?.same ?? [], distinct: models?.distinct ?? [] };
|
|
15187
|
+
}
|
|
15188
|
+
function sameModel(left, right, assertions) {
|
|
15189
|
+
if (assertions.distinct.some(([a, b]) => a === left && b === right || a === right && b === left)) {
|
|
15190
|
+
return false;
|
|
15191
|
+
}
|
|
15192
|
+
const leftGroup = assertions.same.find((group) => group.includes(left));
|
|
15193
|
+
const rightGroup = assertions.same.find((group) => group.includes(right));
|
|
15194
|
+
if (leftGroup !== void 0 && leftGroup === rightGroup) {
|
|
15195
|
+
return true;
|
|
15196
|
+
}
|
|
15197
|
+
if (leftGroup !== void 0 && !leftGroup.includes(right) || rightGroup !== void 0 && !rightGroup.includes(left)) {
|
|
15198
|
+
return false;
|
|
15199
|
+
}
|
|
15200
|
+
return relateModels(modelOf(left), modelOf(right)) === "same";
|
|
15201
|
+
}
|
|
15202
|
+
function pinnedTo(settings, ref) {
|
|
15203
|
+
return settings?.names?.some((name) => name === ref || name === modelOf(ref)) === true;
|
|
15204
|
+
}
|
|
15205
|
+
function buildFamilies(refs, models) {
|
|
15206
|
+
const assertions = assertionsOf(models);
|
|
15207
|
+
const settingsByKey = models?.families ?? {};
|
|
15208
|
+
const groups = [];
|
|
15209
|
+
for (const ref of refs) {
|
|
15210
|
+
const pinnedKey = Object.entries(settingsByKey).find(([, settings]) => pinnedTo(settings, ref))?.[0];
|
|
15211
|
+
const joined2 = groups.find((group) => pinnedKey === void 0 ? group.refs.some((first) => sameModel(first, ref, assertions)) : group.key === pinnedKey);
|
|
15212
|
+
if (joined2 !== void 0) {
|
|
15213
|
+
joined2.refs.push(ref);
|
|
15214
|
+
} else {
|
|
15215
|
+
groups.push({ key: pinnedKey ?? familyKeyOf(modelOf(ref)), refs: [ref] });
|
|
15216
|
+
}
|
|
15217
|
+
}
|
|
15218
|
+
return groups.map((group) => ({ key: group.key, refs: group.refs, settings: settingsByKey[group.key] ?? {} }));
|
|
15219
|
+
}
|
|
15220
|
+
|
|
15221
|
+
// src/models/doctor.ts
|
|
15222
|
+
init_identity2();
|
|
15046
15223
|
function modelsFindings(input) {
|
|
15047
15224
|
const findings = [];
|
|
15048
15225
|
const { models } = input;
|
|
@@ -15087,6 +15264,38 @@ function modelsFindings(input) {
|
|
|
15087
15264
|
findings.push({ severity: "fail", message: `Tier ${tier} points at "${ref}", which names nothing defined.` });
|
|
15088
15265
|
}
|
|
15089
15266
|
}
|
|
15267
|
+
const modelOfRef = (ref) => ref.slice(ref.indexOf("/") + 1);
|
|
15268
|
+
for (const group of models.same ?? []) {
|
|
15269
|
+
for (let outer = 0; outer < group.length; outer += 1) {
|
|
15270
|
+
for (let inner = outer + 1; inner < group.length; inner += 1) {
|
|
15271
|
+
const left = group[outer] ?? "";
|
|
15272
|
+
const right = group[inner] ?? "";
|
|
15273
|
+
if (!left.startsWith("acct:") && !right.startsWith("acct:") && relateModels(modelOfRef(left), modelOfRef(right)) === "distinct") {
|
|
15274
|
+
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.` });
|
|
15275
|
+
}
|
|
15276
|
+
if ((models.distinct ?? []).some(([a, b]) => a === left && b === right || a === right && b === left)) {
|
|
15277
|
+
findings.push({ severity: "fail", message: `"${left}" and "${right}" are asserted to be both one model and two models.` });
|
|
15278
|
+
}
|
|
15279
|
+
}
|
|
15280
|
+
}
|
|
15281
|
+
}
|
|
15282
|
+
for (const [name, model] of Object.entries(models.virtual ?? {})) {
|
|
15283
|
+
const concrete = model.members.filter((member) => memberKindOf(member, models) === "provider" && member.includes("/"));
|
|
15284
|
+
const looksAlike = concrete.flatMap((left, index) => concrete.slice(index + 1).filter((right) => relateModels(modelOfRef(left), modelOfRef(right)) === "same").map((right) => [left, right]));
|
|
15285
|
+
for (const [left, right] of looksAlike) {
|
|
15286
|
+
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.` });
|
|
15287
|
+
}
|
|
15288
|
+
}
|
|
15289
|
+
if (input.targets !== void 0) {
|
|
15290
|
+
const families = buildFamilies(input.targets, models);
|
|
15291
|
+
for (const [name, model] of Object.entries(models.virtual ?? {})) {
|
|
15292
|
+
for (const member of model.members.filter((entry) => entry.startsWith(FAMILY_PREFIX))) {
|
|
15293
|
+
if (!families.some((family) => `${FAMILY_PREFIX}${family.key}` === member)) {
|
|
15294
|
+
findings.push({ severity: "warn", message: `Virtual model "${name}" names ${member}, but no target the providers offer belongs to that family.` });
|
|
15295
|
+
}
|
|
15296
|
+
}
|
|
15297
|
+
}
|
|
15298
|
+
}
|
|
15090
15299
|
const hidden = new Set(models.hide ?? []);
|
|
15091
15300
|
const shown = new Set(models.show ?? []);
|
|
15092
15301
|
for (const ref of hidden) {
|
|
@@ -15097,6 +15306,21 @@ function modelsFindings(input) {
|
|
|
15097
15306
|
return findings;
|
|
15098
15307
|
}
|
|
15099
15308
|
|
|
15309
|
+
// src/models/targets.ts
|
|
15310
|
+
init_modelPicker();
|
|
15311
|
+
init_providerCatalogue();
|
|
15312
|
+
init_providersStore();
|
|
15313
|
+
init_realPorts();
|
|
15314
|
+
function providerModels(paths) {
|
|
15315
|
+
return listProviders(paths).flatMap((entry) => {
|
|
15316
|
+
const catalogue = parseCatalogueCache(realFsPort.readFileUtf8(catalogueCachePath(paths, entry.name)));
|
|
15317
|
+
return providerModelRows(entry.provider, catalogue?.models).map((row) => ({ provider: entry.name, model: row.model }));
|
|
15318
|
+
});
|
|
15319
|
+
}
|
|
15320
|
+
function targetRefs(paths) {
|
|
15321
|
+
return providerModels(paths).map((entry) => `${entry.provider}/${entry.model}`);
|
|
15322
|
+
}
|
|
15323
|
+
|
|
15100
15324
|
// src/doctorReport.ts
|
|
15101
15325
|
init_configProfilesStore();
|
|
15102
15326
|
|
|
@@ -15322,7 +15546,7 @@ function tcpPortEraRecord(raw) {
|
|
|
15322
15546
|
return (has("port") || has("lastPort")) && !has("socketPath");
|
|
15323
15547
|
}
|
|
15324
15548
|
function pushPathResolution(push, resolution) {
|
|
15325
|
-
const ownDir =
|
|
15549
|
+
const ownDir = path31.dirname(resolution.ownExecutablePath);
|
|
15326
15550
|
switch (resolution.agentShim.status) {
|
|
15327
15551
|
case "ok":
|
|
15328
15552
|
push("path-resolution", "pass", `\`agent-shim\` on PATH resolves to this running executable, ${resolution.ownExecutablePath}.`, "agent-shim");
|
|
@@ -15426,14 +15650,14 @@ function pushProvider(push, entry, cacheEnv, signIn) {
|
|
|
15426
15650
|
}
|
|
15427
15651
|
function pushLegacyName(push, params) {
|
|
15428
15652
|
const legacyVariables = Object.keys(params.env).filter((name) => name.startsWith(LEGACY_ENV_PREFIX) && params.env[name] !== void 0).sort();
|
|
15429
|
-
if (legacyVariables.length === 0 &&
|
|
15653
|
+
if (legacyVariables.length === 0 && path31.basename(params.rootPath) !== LEGACY_HOME_DIRNAME) {
|
|
15430
15654
|
push("legacy-name", "pass", "Nothing here still uses the former `claude-use` name.");
|
|
15431
15655
|
return;
|
|
15432
15656
|
}
|
|
15433
15657
|
for (const name of legacyVariables) {
|
|
15434
15658
|
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
15659
|
}
|
|
15436
|
-
if (
|
|
15660
|
+
if (path31.basename(params.rootPath) === LEGACY_HOME_DIRNAME) {
|
|
15437
15661
|
push(
|
|
15438
15662
|
"legacy-name",
|
|
15439
15663
|
"warn",
|
|
@@ -15650,7 +15874,7 @@ function runDoctor(params) {
|
|
|
15650
15874
|
if (models === void 0) {
|
|
15651
15875
|
push("models", "pass", "No models block configured.");
|
|
15652
15876
|
} else {
|
|
15653
|
-
for (const finding of modelsFindings({ models, providers: params.providers.map((entry) => entry.name), identities: params.identities.map((entry) => entry.name) })) {
|
|
15877
|
+
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
15878
|
push("models", finding.severity, finding.message);
|
|
15655
15879
|
}
|
|
15656
15880
|
push("models", "pass", "The models block is consistent.");
|
|
@@ -15832,18 +16056,18 @@ function collectDoctorReport(params) {
|
|
|
15832
16056
|
const { paths } = params;
|
|
15833
16057
|
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
16058
|
const identities = identityNames.map((name) => {
|
|
15835
|
-
const farmRoot =
|
|
15836
|
-
const identityPath =
|
|
16059
|
+
const farmRoot = path31.join(paths.identitiesDir, name);
|
|
16060
|
+
const identityPath = path31.join(farmRoot, "identity.json");
|
|
15837
16061
|
return { name, path: identityPath, raw: realFsPort.readFileUtf8(identityPath), farmRoot, credentialsFilePresent: fs11.existsSync(credentialsFilePath(farmRoot)) };
|
|
15838
16062
|
});
|
|
15839
16063
|
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
16064
|
const configProfiles = profileNames.map((name) => {
|
|
15841
|
-
const profilePath =
|
|
16065
|
+
const profilePath = path31.join(paths.configProfilesDir, `${name}.json`);
|
|
15842
16066
|
return { name, path: profilePath, raw: realFsPort.readFileUtf8(profilePath) };
|
|
15843
16067
|
});
|
|
15844
16068
|
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
16069
|
const providers = providerNames.map((name) => {
|
|
15846
|
-
const providerPath =
|
|
16070
|
+
const providerPath = path31.join(paths.providersDir, `${name}.json`);
|
|
15847
16071
|
return { name, path: providerPath, raw: realFsPort.readFileUtf8(providerPath) };
|
|
15848
16072
|
});
|
|
15849
16073
|
const ownExecutablePath = realOwnExecutablePath();
|
|
@@ -15855,12 +16079,12 @@ function collectDoctorReport(params) {
|
|
|
15855
16079
|
binaryDiscovery = { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
15856
16080
|
}
|
|
15857
16081
|
const shimState = readJson(paths.claudeShimFile, ClaudeShimStateSchema);
|
|
15858
|
-
const pathDirs = (params.env.PATH ?? "").split(
|
|
16082
|
+
const pathDirs = (params.env.PATH ?? "").split(path31.delimiter).filter((dir) => dir !== "");
|
|
15859
16083
|
const claudeShimShadow = shimState === void 0 ? void 0 : refinePathShadow(
|
|
15860
16084
|
findPathShadow({
|
|
15861
16085
|
pathDirs,
|
|
15862
|
-
targetDir:
|
|
15863
|
-
targetFilename:
|
|
16086
|
+
targetDir: path31.dirname(shimState.targetPath),
|
|
16087
|
+
targetFilename: path31.basename(shimState.targetPath),
|
|
15864
16088
|
findExecutableInDir
|
|
15865
16089
|
}),
|
|
15866
16090
|
shimState.targetPath,
|
|
@@ -15884,6 +16108,7 @@ function collectDoctorReport(params) {
|
|
|
15884
16108
|
directoryRules: { path: paths.directoryRulesFile, raw: realFsPort.readFileUtf8(paths.directoryRulesFile) },
|
|
15885
16109
|
globalConfig: { path: paths.globalConfigFile, raw: realFsPort.readFileUtf8(paths.globalConfigFile) },
|
|
15886
16110
|
models: parsedModelsOf(paths),
|
|
16111
|
+
modelTargets: targetRefs(paths),
|
|
15887
16112
|
categoriesLocal: { path: paths.categoriesLocalFile, raw: realFsPort.readFileUtf8(paths.categoriesLocalFile) },
|
|
15888
16113
|
activeIdentity: { path: paths.activeIdentityFile, raw: realFsPort.readFileUtf8(paths.activeIdentityFile) },
|
|
15889
16114
|
binaryDiscovery,
|
|
@@ -15894,7 +16119,7 @@ function collectDoctorReport(params) {
|
|
|
15894
16119
|
agentShim: refinePathShadow(
|
|
15895
16120
|
findPathShadow({
|
|
15896
16121
|
pathDirs,
|
|
15897
|
-
targetDir:
|
|
16122
|
+
targetDir: path31.dirname(ownExecutablePath),
|
|
15898
16123
|
targetFilename: commandFilename(ownExecutablePath, "agent-shim"),
|
|
15899
16124
|
findExecutableInDir
|
|
15900
16125
|
}),
|
|
@@ -15935,90 +16160,90 @@ function collectDoctorReport(params) {
|
|
|
15935
16160
|
// src/frontdoor/controlSchemas.ts
|
|
15936
16161
|
init_schema2();
|
|
15937
16162
|
init_state();
|
|
15938
|
-
var UsageListOutputSchema =
|
|
15939
|
-
var UsageWindowsInputSchema =
|
|
15940
|
-
identity:
|
|
15941
|
-
provider:
|
|
16163
|
+
var UsageListOutputSchema = z25.strictObject({ snapshots: z25.readonly(z25.array(UsageSnapshotSchema)) });
|
|
16164
|
+
var UsageWindowsInputSchema = z25.strictObject({
|
|
16165
|
+
identity: z25.string().min(1),
|
|
16166
|
+
provider: z25.string().min(1).optional()
|
|
15942
16167
|
});
|
|
15943
|
-
var EffectiveWindowSchema =
|
|
16168
|
+
var EffectiveWindowSchema = z25.strictObject({
|
|
15944
16169
|
/** True when the window's reset time has passed, so the recorded observation describes a window that no longer exists. */
|
|
15945
|
-
reset:
|
|
16170
|
+
reset: z25.boolean(),
|
|
15946
16171
|
/** The fraction used: 0 for a reset window, otherwise what was last observed, absent when none was reported. */
|
|
15947
|
-
utilization:
|
|
16172
|
+
utilization: z25.number().optional(),
|
|
15948
16173
|
/** The reset instant, for a window that has not reset yet and reported one. */
|
|
15949
|
-
resetsAtMs:
|
|
16174
|
+
resetsAtMs: z25.number().optional(),
|
|
15950
16175
|
/** The window's own status, for a window that has not reset yet. */
|
|
15951
|
-
status:
|
|
16176
|
+
status: z25.string().optional()
|
|
15952
16177
|
});
|
|
15953
|
-
var UsageWindowsOutputSchema =
|
|
15954
|
-
identity:
|
|
15955
|
-
provider:
|
|
16178
|
+
var UsageWindowsOutputSchema = z25.strictObject({
|
|
16179
|
+
identity: z25.string(),
|
|
16180
|
+
provider: z25.string(),
|
|
15956
16181
|
/** When the rate-limit state the windows come from was observed. */
|
|
15957
|
-
observedAt:
|
|
16182
|
+
observedAt: z25.iso.datetime().optional(),
|
|
15958
16183
|
fiveHour: EffectiveWindowSchema.optional(),
|
|
15959
16184
|
sevenDay: EffectiveWindowSchema.optional()
|
|
15960
16185
|
});
|
|
15961
|
-
var UsageLiveOutputSchema =
|
|
16186
|
+
var UsageLiveOutputSchema = z25.strictObject({
|
|
15962
16187
|
/** 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
16188
|
latest: RcLiveRateLimitSchema.optional(),
|
|
15964
16189
|
/** One observation per session whose stream has filed a rate_limit_event this door generation. */
|
|
15965
|
-
sessions:
|
|
16190
|
+
sessions: z25.readonly(z25.array(RcLiveRateLimitSchema))
|
|
15966
16191
|
});
|
|
15967
|
-
var FrontDoorSessionStatusSchema =
|
|
15968
|
-
pid:
|
|
15969
|
-
startedAt:
|
|
15970
|
-
alive:
|
|
16192
|
+
var FrontDoorSessionStatusSchema = z25.strictObject({
|
|
16193
|
+
pid: z25.int().positive(),
|
|
16194
|
+
startedAt: z25.number(),
|
|
16195
|
+
alive: z25.boolean()
|
|
15971
16196
|
});
|
|
15972
|
-
var HeadroomSocketTargetSchema =
|
|
15973
|
-
var FrontDoorStatusOutputSchema =
|
|
16197
|
+
var HeadroomSocketTargetSchema = z25.union([z25.strictObject({ socketPath: z25.string() }), z25.strictObject({ refused: z25.string() })]);
|
|
16198
|
+
var FrontDoorStatusOutputSchema = z25.strictObject({
|
|
15974
16199
|
state: FrontDoorStateSchema,
|
|
15975
|
-
supervisorAlive:
|
|
15976
|
-
sessions:
|
|
16200
|
+
supervisorAlive: z25.boolean(),
|
|
16201
|
+
sessions: z25.readonly(z25.array(FrontDoorSessionStatusSchema)),
|
|
15977
16202
|
headroomSocket: HeadroomSocketTargetSchema.optional(),
|
|
15978
|
-
logPath:
|
|
15979
|
-
logExists:
|
|
16203
|
+
logPath: z25.string(),
|
|
16204
|
+
logExists: z25.boolean()
|
|
15980
16205
|
});
|
|
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:
|
|
16206
|
+
var FrontDoorSessionsOutputSchema = z25.strictObject({ sessions: z25.readonly(z25.array(FrontDoorSessionStatusSchema)) });
|
|
16207
|
+
var CheckRunInputSchema = z25.strictObject({
|
|
16208
|
+
path: z25.string().min(1),
|
|
16209
|
+
identity: z25.string().min(1).optional()
|
|
16210
|
+
}).refine((input) => path32.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
16211
|
+
var PoolPickInputSchema = z25.strictObject({
|
|
16212
|
+
pool: z25.string().min(1),
|
|
16213
|
+
path: z25.string().min(1)
|
|
16214
|
+
}).refine((input) => path32.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
16215
|
+
var DoctorFindingSchema = z25.strictObject({
|
|
16216
|
+
section: z25.enum(DOCTOR_SECTIONS),
|
|
16217
|
+
subject: z25.string().optional(),
|
|
16218
|
+
severity: z25.enum(DOCTOR_SEVERITIES),
|
|
16219
|
+
message: z25.string()
|
|
15995
16220
|
});
|
|
15996
|
-
var DoctorRunOutputSchema =
|
|
16221
|
+
var DoctorRunOutputSchema = z25.strictObject({
|
|
15997
16222
|
/** False exactly when any finding is a `fail`; a `warn` never fails the report on its own. */
|
|
15998
|
-
ok:
|
|
15999
|
-
findings:
|
|
16223
|
+
ok: z25.boolean(),
|
|
16224
|
+
findings: z25.readonly(z25.array(DoctorFindingSchema))
|
|
16000
16225
|
});
|
|
16001
|
-
var FrontDoorRestartOutputSchema =
|
|
16002
|
-
action:
|
|
16003
|
-
previousPid:
|
|
16226
|
+
var FrontDoorRestartOutputSchema = z25.strictObject({
|
|
16227
|
+
action: z25.literal("restarting"),
|
|
16228
|
+
previousPid: z25.int().positive()
|
|
16004
16229
|
});
|
|
16005
|
-
var UpdateCheckOutputSchema =
|
|
16006
|
-
current:
|
|
16007
|
-
latest:
|
|
16008
|
-
action:
|
|
16230
|
+
var UpdateCheckOutputSchema = z25.strictObject({
|
|
16231
|
+
current: z25.string(),
|
|
16232
|
+
latest: z25.string(),
|
|
16233
|
+
action: z25.enum(["current", "available", "updated"])
|
|
16009
16234
|
});
|
|
16010
|
-
var CodexSignInSchema =
|
|
16011
|
-
|
|
16012
|
-
|
|
16013
|
-
|
|
16235
|
+
var CodexSignInSchema = z25.discriminatedUnion("state", [
|
|
16236
|
+
z25.strictObject({ state: z25.literal("none") }),
|
|
16237
|
+
z25.strictObject({ state: z25.literal("signed-in"), email: z25.string().optional(), planScope: z25.boolean(), accessTokenExpiresAt: z25.number() }),
|
|
16238
|
+
z25.strictObject({ state: z25.literal("unreadable"), message: z25.string() })
|
|
16014
16239
|
]);
|
|
16015
|
-
var CodexStatusOutputSchema =
|
|
16240
|
+
var CodexStatusOutputSchema = z25.strictObject({
|
|
16016
16241
|
signIn: CodexSignInSchema,
|
|
16017
|
-
codexProviders:
|
|
16242
|
+
codexProviders: z25.readonly(z25.array(z25.string()))
|
|
16018
16243
|
});
|
|
16019
|
-
var CodexLogoutOutputSchema =
|
|
16020
|
-
hadGrant:
|
|
16021
|
-
revoked:
|
|
16244
|
+
var CodexLogoutOutputSchema = z25.strictObject({
|
|
16245
|
+
hadGrant: z25.boolean(),
|
|
16246
|
+
revoked: z25.boolean()
|
|
16022
16247
|
});
|
|
16023
16248
|
|
|
16024
16249
|
// src/frontdoor/codexApi.ts
|
|
@@ -16176,143 +16401,143 @@ init_providersStore();
|
|
|
16176
16401
|
|
|
16177
16402
|
// src/frontdoor/configSchemas.ts
|
|
16178
16403
|
init_schema();
|
|
16179
|
-
import { z as
|
|
16180
|
-
var RemovalConfirmationSchema =
|
|
16181
|
-
var CredentialWriteSchema = (targets) =>
|
|
16182
|
-
sources:
|
|
16183
|
-
target:
|
|
16184
|
-
cache:
|
|
16404
|
+
import { z as z26 } from "zod";
|
|
16405
|
+
var RemovalConfirmationSchema = z26.boolean();
|
|
16406
|
+
var CredentialWriteSchema = (targets) => z26.strictObject({
|
|
16407
|
+
sources: z26.array(RemoteCredentialSourceSchema).min(1).optional(),
|
|
16408
|
+
target: z26.enum(targets).optional(),
|
|
16409
|
+
cache: z26.union([z26.literal(false), CredentialCacheSchema]).optional()
|
|
16185
16410
|
});
|
|
16186
|
-
var CredentialSummarySchema2 =
|
|
16187
|
-
target:
|
|
16188
|
-
sources:
|
|
16189
|
-
|
|
16190
|
-
|
|
16191
|
-
|
|
16192
|
-
|
|
16193
|
-
|
|
16194
|
-
|
|
16195
|
-
|
|
16411
|
+
var CredentialSummarySchema2 = z26.strictObject({
|
|
16412
|
+
target: z26.enum(CREDENTIAL_TARGETS),
|
|
16413
|
+
sources: z26.readonly(z26.array(
|
|
16414
|
+
z26.discriminatedUnion("kind", [
|
|
16415
|
+
z26.strictObject({ kind: z26.literal("env"), variable: z26.string() }),
|
|
16416
|
+
z26.strictObject({ kind: z26.literal("file"), path: z26.string() }),
|
|
16417
|
+
z26.strictObject({ kind: z26.literal("command"), program: z26.string() }),
|
|
16418
|
+
z26.strictObject({ kind: z26.literal("op"), reference: z26.string() }),
|
|
16419
|
+
z26.strictObject({ kind: z26.literal("keychain"), service: z26.string(), account: z26.string().optional() }),
|
|
16420
|
+
z26.strictObject({ kind: z26.literal("literal") })
|
|
16196
16421
|
])
|
|
16197
16422
|
)),
|
|
16198
16423
|
cache: CredentialCacheSchema.optional()
|
|
16199
16424
|
});
|
|
16200
|
-
var mutationOutput = (kind, action) =>
|
|
16201
|
-
var storedMutationOutput = (kind, action, value) =>
|
|
16202
|
-
var IdentityValueSchema =
|
|
16203
|
-
name:
|
|
16204
|
-
defaultConfigProfile:
|
|
16205
|
-
allowAmbientCredential:
|
|
16425
|
+
var mutationOutput = (kind, action) => z26.strictObject({ action: z26.literal(action), kind: z26.literal(kind), name: z26.string() });
|
|
16426
|
+
var storedMutationOutput = (kind, action, value) => z26.strictObject({ action: z26.literal(action), kind: z26.literal(kind), name: z26.string(), value });
|
|
16427
|
+
var IdentityValueSchema = z26.strictObject({
|
|
16428
|
+
name: z26.string(),
|
|
16429
|
+
defaultConfigProfile: z26.string().optional(),
|
|
16430
|
+
allowAmbientCredential: z26.boolean(),
|
|
16206
16431
|
credential: CredentialSummarySchema2.optional(),
|
|
16207
|
-
anchors:
|
|
16432
|
+
anchors: z26.array(AnchorSchema).optional()
|
|
16208
16433
|
});
|
|
16209
16434
|
var ProfileValueSchema = ConfigProfileSchema.omit({ $schema: true });
|
|
16210
|
-
var ProviderValueSchema =
|
|
16211
|
-
name:
|
|
16212
|
-
kind:
|
|
16213
|
-
displayName:
|
|
16214
|
-
baseUrl:
|
|
16435
|
+
var ProviderValueSchema = z26.strictObject({
|
|
16436
|
+
name: z26.string(),
|
|
16437
|
+
kind: z26.enum(PROVIDER_KINDS),
|
|
16438
|
+
displayName: z26.string(),
|
|
16439
|
+
baseUrl: z26.string().optional(),
|
|
16215
16440
|
codex: CodexProviderConfigSchema.optional(),
|
|
16216
16441
|
credential: CredentialSummarySchema2.optional(),
|
|
16217
|
-
env:
|
|
16442
|
+
env: z26.record(z26.string(), z26.string()).optional()
|
|
16218
16443
|
});
|
|
16219
|
-
var ConfigNameInputSchema =
|
|
16444
|
+
var ConfigNameInputSchema = z26.strictObject({ name: z26.string().min(1) });
|
|
16220
16445
|
var ConfigIdentityAddOutputSchema = storedMutationOutput("identity", "created", IdentityValueSchema);
|
|
16221
|
-
var ConfigIdentitySetInputSchema =
|
|
16222
|
-
name:
|
|
16223
|
-
defaultConfigProfile:
|
|
16224
|
-
allowAmbientCredential:
|
|
16225
|
-
credential:
|
|
16446
|
+
var ConfigIdentitySetInputSchema = z26.strictObject({
|
|
16447
|
+
name: z26.string().min(1),
|
|
16448
|
+
defaultConfigProfile: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16449
|
+
allowAmbientCredential: z26.boolean().optional(),
|
|
16450
|
+
credential: z26.union([z26.literal(false), CredentialWriteSchema(CREDENTIAL_TARGETS)]).optional(),
|
|
16226
16451
|
/** `false` removes the anchors; a list replaces them. */
|
|
16227
|
-
anchors:
|
|
16452
|
+
anchors: z26.union([z26.literal(false), z26.array(AnchorSchema).min(1)]).optional()
|
|
16228
16453
|
});
|
|
16229
16454
|
var ConfigIdentitySetOutputSchema = storedMutationOutput("identity", "updated", IdentityValueSchema);
|
|
16230
|
-
var ConfigIdentityRemoveInputSchema =
|
|
16455
|
+
var ConfigIdentityRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16231
16456
|
var ConfigIdentityRemoveOutputSchema = mutationOutput("identity", "removed");
|
|
16232
16457
|
var ConfigIdentityUseOutputSchema = mutationOutput("identity", "selected");
|
|
16233
|
-
var ConfigProfileAddInputSchema =
|
|
16234
|
-
name:
|
|
16235
|
-
extends:
|
|
16236
|
-
description:
|
|
16458
|
+
var ConfigProfileAddInputSchema = z26.strictObject({
|
|
16459
|
+
name: z26.string().min(1),
|
|
16460
|
+
extends: z26.array(z26.string().min(1)).optional(),
|
|
16461
|
+
description: z26.string().optional()
|
|
16237
16462
|
});
|
|
16238
16463
|
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:
|
|
16464
|
+
var ConfigProfileSetInputSchema = z26.strictObject({
|
|
16465
|
+
name: z26.string().min(1),
|
|
16466
|
+
category: z26.record(z26.string(), z26.boolean()).optional(),
|
|
16467
|
+
entry: z26.record(z26.string(), z26.boolean()).optional(),
|
|
16468
|
+
extends: z26.union([z26.array(z26.string().min(1)), z26.literal(false)]).optional(),
|
|
16469
|
+
description: z26.union([z26.string(), z26.literal(false)]).optional(),
|
|
16470
|
+
launch: z26.strictObject({
|
|
16471
|
+
skipPermissions: z26.boolean().optional(),
|
|
16472
|
+
remoteControl: z26.boolean().optional(),
|
|
16473
|
+
headroom: z26.boolean().optional(),
|
|
16474
|
+
trackUsage: z26.boolean().optional(),
|
|
16475
|
+
provider: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16476
|
+
claudeVersion: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16477
|
+
delay: z26.union([z26.string().regex(DURATION_RE), z26.literal(false)]).optional(),
|
|
16478
|
+
pause: z26.boolean().optional(),
|
|
16479
|
+
explain: z26.boolean().optional(),
|
|
16480
|
+
routeByName: z26.boolean().optional()
|
|
16256
16481
|
}).optional()
|
|
16257
16482
|
});
|
|
16258
16483
|
var ConfigProfileSetOutputSchema = storedMutationOutput("profile", "updated", ProfileValueSchema);
|
|
16259
|
-
var ConfigProfileRemoveInputSchema =
|
|
16484
|
+
var ConfigProfileRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16260
16485
|
var ConfigProfileRemoveOutputSchema = mutationOutput("profile", "removed");
|
|
16261
16486
|
var ConfigProfileUseOutputSchema = mutationOutput("profile", "selected");
|
|
16262
|
-
var PoolMembersInputSchema =
|
|
16263
|
-
var ConfigPoolAddInputSchema =
|
|
16264
|
-
name:
|
|
16487
|
+
var PoolMembersInputSchema = z26.array(z26.string().min(1)).min(1);
|
|
16488
|
+
var ConfigPoolAddInputSchema = z26.strictObject({
|
|
16489
|
+
name: z26.string().min(1),
|
|
16265
16490
|
identities: PoolMembersInputSchema,
|
|
16266
|
-
preference:
|
|
16267
|
-
resumeOnLimit:
|
|
16268
|
-
compactBeforeLimit:
|
|
16491
|
+
preference: z26.enum(POOL_PREFERENCES).optional(),
|
|
16492
|
+
resumeOnLimit: z26.boolean().optional(),
|
|
16493
|
+
compactBeforeLimit: z26.boolean().optional(),
|
|
16269
16494
|
compactAtUtilisation: CompactAtUtilisationSchema.optional()
|
|
16270
16495
|
});
|
|
16271
16496
|
var ConfigPoolAddOutputSchema = storedMutationOutput("pool", "created", PoolSchema);
|
|
16272
|
-
var ConfigPoolSetInputSchema =
|
|
16273
|
-
name:
|
|
16497
|
+
var ConfigPoolSetInputSchema = z26.strictObject({
|
|
16498
|
+
name: z26.string().min(1),
|
|
16274
16499
|
identities: PoolMembersInputSchema.optional(),
|
|
16275
|
-
preference:
|
|
16276
|
-
resumeOnLimit:
|
|
16277
|
-
compactBeforeLimit:
|
|
16278
|
-
compactAtUtilisation:
|
|
16500
|
+
preference: z26.union([z26.enum(POOL_PREFERENCES), z26.literal(false)]).optional(),
|
|
16501
|
+
resumeOnLimit: z26.boolean().optional(),
|
|
16502
|
+
compactBeforeLimit: z26.boolean().optional(),
|
|
16503
|
+
compactAtUtilisation: z26.union([CompactAtUtilisationSchema, z26.literal(false)]).optional()
|
|
16279
16504
|
});
|
|
16280
16505
|
var ConfigPoolSetOutputSchema = storedMutationOutput("pool", "updated", PoolSchema);
|
|
16281
|
-
var ConfigPoolRemoveInputSchema =
|
|
16506
|
+
var ConfigPoolRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16282
16507
|
var ConfigPoolRemoveOutputSchema = mutationOutput("pool", "removed");
|
|
16283
16508
|
var ConfigPoolUseOutputSchema = mutationOutput("pool", "selected");
|
|
16284
|
-
var ConfigProviderAddInputSchema =
|
|
16285
|
-
name:
|
|
16286
|
-
kind:
|
|
16287
|
-
displayName:
|
|
16288
|
-
baseUrl:
|
|
16509
|
+
var ConfigProviderAddInputSchema = z26.strictObject({
|
|
16510
|
+
name: z26.string().min(1),
|
|
16511
|
+
kind: z26.enum(PROVIDER_KINDS).optional(),
|
|
16512
|
+
displayName: z26.string().min(1),
|
|
16513
|
+
baseUrl: z26.string().min(1).optional(),
|
|
16289
16514
|
credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).required({ sources: true }),
|
|
16290
16515
|
codex: CodexProviderConfigSchema.optional()
|
|
16291
16516
|
});
|
|
16292
16517
|
var ConfigProviderAddOutputSchema = storedMutationOutput("provider", "created", ProviderValueSchema);
|
|
16293
|
-
var ConfigProviderSetInputSchema =
|
|
16294
|
-
name:
|
|
16295
|
-
displayName:
|
|
16296
|
-
baseUrl:
|
|
16518
|
+
var ConfigProviderSetInputSchema = z26.strictObject({
|
|
16519
|
+
name: z26.string().min(1),
|
|
16520
|
+
displayName: z26.string().min(1).optional(),
|
|
16521
|
+
baseUrl: z26.string().min(1).optional(),
|
|
16297
16522
|
credential: CredentialWriteSchema(PROVIDER_CREDENTIAL_TARGETS).optional(),
|
|
16298
16523
|
codex: CodexProviderConfigSchema.optional()
|
|
16299
16524
|
});
|
|
16300
16525
|
var ConfigProviderSetOutputSchema = storedMutationOutput("provider", "updated", ProviderValueSchema);
|
|
16301
|
-
var ConfigProviderRemoveInputSchema =
|
|
16526
|
+
var ConfigProviderRemoveInputSchema = z26.strictObject({ name: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16302
16527
|
var ConfigProviderRemoveOutputSchema = mutationOutput("provider", "removed");
|
|
16303
|
-
var ConfigRuleAddInputSchema =
|
|
16304
|
-
path:
|
|
16305
|
-
configProfile:
|
|
16306
|
-
identity:
|
|
16528
|
+
var ConfigRuleAddInputSchema = z26.strictObject({
|
|
16529
|
+
path: z26.string().min(1),
|
|
16530
|
+
configProfile: z26.string().min(1).optional(),
|
|
16531
|
+
identity: z26.string().min(1).optional()
|
|
16307
16532
|
});
|
|
16308
16533
|
var ConfigRuleAddOutputSchema = storedMutationOutput("rule", "created", DirectoryRuleSchema);
|
|
16309
|
-
var ConfigRuleSetInputSchema =
|
|
16310
|
-
path:
|
|
16311
|
-
configProfile:
|
|
16312
|
-
identity:
|
|
16534
|
+
var ConfigRuleSetInputSchema = z26.strictObject({
|
|
16535
|
+
path: z26.string().min(1),
|
|
16536
|
+
configProfile: z26.union([z26.string().min(1), z26.literal(false)]).optional(),
|
|
16537
|
+
identity: z26.union([z26.string().min(1), z26.literal(false)]).optional()
|
|
16313
16538
|
});
|
|
16314
16539
|
var ConfigRuleSetOutputSchema = storedMutationOutput("rule", "updated", DirectoryRuleSchema);
|
|
16315
|
-
var ConfigRuleRemoveInputSchema =
|
|
16540
|
+
var ConfigRuleRemoveInputSchema = z26.strictObject({ path: z26.string().min(1), confirm: RemovalConfirmationSchema });
|
|
16316
16541
|
var ConfigRuleRemoveOutputSchema = mutationOutput("rule", "removed");
|
|
16317
16542
|
|
|
16318
16543
|
// src/frontdoor/configApi.ts
|
|
@@ -16624,43 +16849,43 @@ import { openapi as openapi4 } from "@orpc/openapi";
|
|
|
16624
16849
|
import { eventIterator as eventIterator2, withEventMeta as withEventMeta2 } from "@orpc/server";
|
|
16625
16850
|
|
|
16626
16851
|
// src/frontdoor/eventSchemas.ts
|
|
16627
|
-
import { z as
|
|
16852
|
+
import { z as z27 } from "zod";
|
|
16628
16853
|
var DOOR_EVENT_SOURCE_RC = "rc";
|
|
16629
16854
|
var LAUNCH_EVENT_SOURCE = "launch";
|
|
16630
16855
|
var USAGE_EVENT_SOURCE = "usage";
|
|
16631
16856
|
var DOOR_HEALTH_EVENT_SOURCE = "door";
|
|
16632
16857
|
var QUOTA_EXPIRING_EVENT_SOURCE = "quota-expiring";
|
|
16633
|
-
var DoorEventSchema =
|
|
16634
|
-
source:
|
|
16858
|
+
var DoorEventSchema = z27.strictObject({
|
|
16859
|
+
source: z27.string().min(1),
|
|
16635
16860
|
/** A positive integer because the backbone's counters start at one and only ever increase. */
|
|
16636
|
-
sequence:
|
|
16637
|
-
payload:
|
|
16861
|
+
sequence: z27.number().int().positive(),
|
|
16862
|
+
payload: z27.unknown()
|
|
16638
16863
|
});
|
|
16639
|
-
var DoorEventSourceQuerySchema =
|
|
16640
|
-
sources:
|
|
16864
|
+
var DoorEventSourceQuerySchema = z27.strictObject({
|
|
16865
|
+
sources: z27.array(z27.string().min(1)).min(1).optional()
|
|
16641
16866
|
});
|
|
16642
|
-
var LaunchLifecycleEventSchema =
|
|
16643
|
-
kind:
|
|
16644
|
-
pid:
|
|
16645
|
-
startedAt:
|
|
16646
|
-
observedAt:
|
|
16867
|
+
var LaunchLifecycleEventSchema = z27.strictObject({
|
|
16868
|
+
kind: z27.enum(["registered", "pruned", "ended"]),
|
|
16869
|
+
pid: z27.number().int().positive(),
|
|
16870
|
+
startedAt: z27.number(),
|
|
16871
|
+
observedAt: z27.number()
|
|
16647
16872
|
});
|
|
16648
|
-
var DoorHealthEventSchema =
|
|
16649
|
-
|
|
16650
|
-
|
|
16651
|
-
|
|
16652
|
-
|
|
16653
|
-
|
|
16654
|
-
|
|
16873
|
+
var DoorHealthEventSchema = z27.discriminatedUnion("kind", [
|
|
16874
|
+
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() }),
|
|
16875
|
+
z27.strictObject({ kind: z27.literal("listenerFailed"), pid: z27.number().int().positive(), listener: z27.enum(["provider", "connect", "direct"]), message: z27.string(), observedAt: z27.number() }),
|
|
16876
|
+
z27.strictObject({ kind: z27.literal("binaryTurnover"), pid: z27.number().int().positive(), observedAt: z27.number() }),
|
|
16877
|
+
z27.strictObject({ kind: z27.literal("idleShutdown"), pid: z27.number().int().positive(), observedAt: z27.number() }),
|
|
16878
|
+
z27.strictObject({ kind: z27.literal("superseded"), pid: z27.number().int().positive(), ownerPid: z27.number().int().positive(), observedAt: z27.number() }),
|
|
16879
|
+
z27.strictObject({ kind: z27.literal("drained"), pid: z27.number().int().positive(), observedAt: z27.number() })
|
|
16655
16880
|
]);
|
|
16656
|
-
var QuotaExpiringEventSchema =
|
|
16657
|
-
identity:
|
|
16658
|
-
provider:
|
|
16659
|
-
window:
|
|
16881
|
+
var QuotaExpiringEventSchema = z27.strictObject({
|
|
16882
|
+
identity: z27.string().min(1),
|
|
16883
|
+
provider: z27.string().min(1),
|
|
16884
|
+
window: z27.enum(["fiveHour", "sevenDay"]),
|
|
16660
16885
|
/** 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:
|
|
16886
|
+
utilization: z27.number().min(0).max(1),
|
|
16887
|
+
resetsAt: z27.iso.datetime(),
|
|
16888
|
+
observedAt: z27.number()
|
|
16664
16889
|
});
|
|
16665
16890
|
|
|
16666
16891
|
// src/frontdoor/eventsApi.ts
|
|
@@ -16743,57 +16968,57 @@ import { ORPCError as ORPCError5 } from "@orpc/client";
|
|
|
16743
16968
|
import { openapi as openapi6 } from "@orpc/openapi";
|
|
16744
16969
|
|
|
16745
16970
|
// src/frontdoor/launchSchemas.ts
|
|
16746
|
-
import
|
|
16747
|
-
import { z as
|
|
16971
|
+
import path33 from "node:path";
|
|
16972
|
+
import { z as z28 } from "zod";
|
|
16748
16973
|
init_claudeVersion();
|
|
16749
16974
|
init_identity();
|
|
16750
|
-
var LaunchResolveInputSchema =
|
|
16751
|
-
path:
|
|
16975
|
+
var LaunchResolveInputSchema = z28.strictObject({
|
|
16976
|
+
path: z28.string().min(1),
|
|
16752
16977
|
/** `@name`, launch flags, then the arguments for `claude`; empty for a bare launch. */
|
|
16753
|
-
argv:
|
|
16978
|
+
argv: z28.readonly(z28.array(z28.string())).optional(),
|
|
16754
16979
|
/** 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:
|
|
16980
|
+
env: z28.record(z28.string(), z28.string()).optional()
|
|
16981
|
+
}).refine((input) => path33.isAbsolute(input.path), { message: "path must be absolute: the door cannot resolve a relative path against the caller's working directory" });
|
|
16982
|
+
var LaunchPoolDecisionSchema = z28.strictObject({
|
|
16983
|
+
name: z28.string(),
|
|
16984
|
+
reasons: z28.readonly(z28.array(z28.string())),
|
|
16985
|
+
movedOff: z28.strictObject({ identity: z28.string(), reason: z28.string() }).optional()
|
|
16761
16986
|
});
|
|
16762
|
-
var LaunchDecisionSchema =
|
|
16763
|
-
identity:
|
|
16764
|
-
identitySource:
|
|
16987
|
+
var LaunchDecisionSchema = z28.strictObject({
|
|
16988
|
+
identity: z28.string().optional(),
|
|
16989
|
+
identitySource: z28.enum(IDENTITY_DECISION_SOURCES),
|
|
16765
16990
|
pool: LaunchPoolDecisionSchema.optional(),
|
|
16766
|
-
configDirEscapeHatch:
|
|
16767
|
-
configDir:
|
|
16768
|
-
configProfile:
|
|
16769
|
-
configProfileSource:
|
|
16770
|
-
provider:
|
|
16991
|
+
configDirEscapeHatch: z28.boolean(),
|
|
16992
|
+
configDir: z28.string().optional(),
|
|
16993
|
+
configProfile: z28.string().optional(),
|
|
16994
|
+
configProfileSource: z28.enum(CONFIG_PROFILE_DECISION_SOURCES),
|
|
16995
|
+
provider: z28.string().optional()
|
|
16771
16996
|
});
|
|
16772
|
-
var LaunchFlagsSchema =
|
|
16773
|
-
skipPermissions:
|
|
16774
|
-
remoteControl:
|
|
16775
|
-
headroom:
|
|
16776
|
-
trackUsage:
|
|
16777
|
-
pause:
|
|
16778
|
-
explain:
|
|
16779
|
-
routeByName:
|
|
16997
|
+
var LaunchFlagsSchema = z28.strictObject({
|
|
16998
|
+
skipPermissions: z28.boolean(),
|
|
16999
|
+
remoteControl: z28.boolean(),
|
|
17000
|
+
headroom: z28.boolean(),
|
|
17001
|
+
trackUsage: z28.boolean(),
|
|
17002
|
+
pause: z28.boolean(),
|
|
17003
|
+
explain: z28.boolean(),
|
|
17004
|
+
routeByName: z28.boolean(),
|
|
16780
17005
|
/** How long the launch waits after its own output before it starts claude, in milliseconds. */
|
|
16781
|
-
delayMs:
|
|
17006
|
+
delayMs: z28.number()
|
|
16782
17007
|
});
|
|
16783
|
-
var LaunchResolveOutputSchema =
|
|
17008
|
+
var LaunchResolveOutputSchema = z28.strictObject({
|
|
16784
17009
|
decision: LaunchDecisionSchema,
|
|
16785
17010
|
flags: LaunchFlagsSchema,
|
|
16786
|
-
claudeVersion:
|
|
17011
|
+
claudeVersion: z28.strictObject({ version: z28.string(), source: z28.enum(CLAUDE_VERSION_SOURCES) }).optional(),
|
|
16787
17012
|
/** The real `claude` binary the launch would spawn, on the door's host. */
|
|
16788
|
-
bin:
|
|
17013
|
+
bin: z28.string(),
|
|
16789
17014
|
/** The arguments the launch would pass it: the tool's own flags, then `CLAUDE_EXTRA_FLAGS`, then the caller's own. */
|
|
16790
|
-
args:
|
|
17015
|
+
args: z28.readonly(z28.array(z28.string())),
|
|
16791
17016
|
/** The credential the launch would authenticate with, by target and source kinds. Absent when none applies. */
|
|
16792
|
-
credential:
|
|
16793
|
-
routing:
|
|
17017
|
+
credential: z28.strictObject({ subject: z28.enum(["provider", "identity"]), name: z28.string(), summary: CredentialSummarySchema }).optional(),
|
|
17018
|
+
routing: z28.strictObject({ frontDoor: z28.boolean(), headroom: z28.boolean(), routeByName: z28.boolean() }),
|
|
16794
17019
|
/** The names of the environment variables the launch would set or unset, sorted. Values are not reported. */
|
|
16795
|
-
environment:
|
|
16796
|
-
warnings:
|
|
17020
|
+
environment: z28.readonly(z28.array(z28.string())),
|
|
17021
|
+
warnings: z28.readonly(z28.array(z28.string()))
|
|
16797
17022
|
});
|
|
16798
17023
|
|
|
16799
17024
|
// src/frontdoor/launchApi.ts
|
|
@@ -16829,22 +17054,22 @@ function createLaunchApiRouter(deps) {
|
|
|
16829
17054
|
// src/frontdoor/agentTreesApi.ts
|
|
16830
17055
|
import { ORPCError as ORPCError6 } from "@orpc/client";
|
|
16831
17056
|
import { openapi as openapi7 } from "@orpc/openapi";
|
|
16832
|
-
import { z as
|
|
17057
|
+
import { z as z29 } from "zod";
|
|
16833
17058
|
init_cliError();
|
|
16834
|
-
var AgentTreesListInputSchema =
|
|
17059
|
+
var AgentTreesListInputSchema = z29.strictObject({
|
|
16835
17060
|
/** Only this identity's sessions. */
|
|
16836
|
-
identity:
|
|
17061
|
+
identity: z29.string().optional(),
|
|
16837
17062
|
/** Include sessions that spawned no agent and ran no workflow. */
|
|
16838
|
-
all:
|
|
17063
|
+
all: z29.boolean().optional()
|
|
16839
17064
|
});
|
|
16840
|
-
var AgentTreesListOutputSchema =
|
|
16841
|
-
var AgentTreesShowInputSchema =
|
|
17065
|
+
var AgentTreesListOutputSchema = z29.array(SessionSummarySchema);
|
|
17066
|
+
var AgentTreesShowInputSchema = z29.strictObject({
|
|
16842
17067
|
/** A session id, or an unambiguous prefix of one. */
|
|
16843
|
-
session:
|
|
17068
|
+
session: z29.string().min(1),
|
|
16844
17069
|
/** Look only in this identity. */
|
|
16845
|
-
identity:
|
|
17070
|
+
identity: z29.string().optional()
|
|
16846
17071
|
});
|
|
16847
|
-
var AgentTreesShowOutputSchema =
|
|
17072
|
+
var AgentTreesShowOutputSchema = z29.strictObject({ identities: z29.array(z29.string()), ...MergedAgentTreeSchema.shape });
|
|
16848
17073
|
function asBadRequest(error) {
|
|
16849
17074
|
if (error instanceof CliError) {
|
|
16850
17075
|
throw new ORPCError6("BAD_REQUEST", { message: error.message });
|
|
@@ -17230,11 +17455,11 @@ function createDoorHealthPublisher(hub, now, pid) {
|
|
|
17230
17455
|
|
|
17231
17456
|
// src/frontdoor/quotaExpiringEvents.ts
|
|
17232
17457
|
init_schema2();
|
|
17233
|
-
var
|
|
17458
|
+
var MS_PER_HOUR5 = 36e5;
|
|
17234
17459
|
var MS_PER_DAY2 = 864e5;
|
|
17235
17460
|
var FIVE_HOUR_WINDOW_HOURS = 5;
|
|
17236
17461
|
var SEVEN_DAY_WINDOW_DAYS = 7;
|
|
17237
|
-
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS *
|
|
17462
|
+
var FIVE_HOUR_WINDOW_MS2 = FIVE_HOUR_WINDOW_HOURS * MS_PER_HOUR5;
|
|
17238
17463
|
var SEVEN_DAY_WINDOW_MS2 = SEVEN_DAY_WINDOW_DAYS * MS_PER_DAY2;
|
|
17239
17464
|
var FINAL_SPAN_DENOMINATOR = 30;
|
|
17240
17465
|
var QUOTA_EXPIRING_WINDOW_FRACTION = 1 / FINAL_SPAN_DENOMINATOR;
|
|
@@ -17927,7 +18152,7 @@ async function serveRcConversations(ctx, pathname, method) {
|
|
|
17927
18152
|
var RC_SELF_HOST_OAUTH_HOST = "platform.claude.com";
|
|
17928
18153
|
var RC_SELF_HOST_SCOPE_LIST = ["user:profile", "user:inference", "user:sessions:claude_code", "user:mcp_servers", "user:file_upload"];
|
|
17929
18154
|
var RC_SELF_HOST_OAUTH_TOKEN_TTL_SECONDS = 3600;
|
|
17930
|
-
var
|
|
18155
|
+
var MS_PER_SECOND6 = 1e3;
|
|
17931
18156
|
var HTTP_SERVICE_UNAVAILABLE = 503;
|
|
17932
18157
|
function isRecord12(value) {
|
|
17933
18158
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -17983,7 +18208,7 @@ function createRcSelfHostLocal(deps) {
|
|
|
17983
18208
|
}
|
|
17984
18209
|
if (method === "POST" && pathname.startsWith("/api/eval/")) {
|
|
17985
18210
|
await deps.readBody(request4, CONTROL_BODY_CAP_BYTES);
|
|
17986
|
-
answerServerJson(response, HTTP_STATUS.ok, { features: growthBookFeatures(), dateUpdated: Math.floor(deps.now() /
|
|
18211
|
+
answerServerJson(response, HTTP_STATUS.ok, { features: growthBookFeatures(), dateUpdated: Math.floor(deps.now() / MS_PER_SECOND6) });
|
|
17987
18212
|
return true;
|
|
17988
18213
|
}
|
|
17989
18214
|
if (method === "GET" && pathname === "/api/oauth/profile") {
|
|
@@ -18282,7 +18507,7 @@ var RC_COMPAT_SESSIONS_PATH = "/v1/sessions";
|
|
|
18282
18507
|
var RC_SESSION_ID_PREFIX2 = "cse_";
|
|
18283
18508
|
var RC_SELF_HOST_API_BASE_URL = "https://api.anthropic.com";
|
|
18284
18509
|
var HTTP_CONFLICT = 409;
|
|
18285
|
-
var
|
|
18510
|
+
var MS_PER_SECOND7 = 1e3;
|
|
18286
18511
|
var HTTP_SERVICE_UNAVAILABLE2 = 503;
|
|
18287
18512
|
var RC_SELF_HOST_WORKER_JWT_TTL_SECONDS = 46800;
|
|
18288
18513
|
var RC_SELF_HOST_KEEPALIVE_MS = 15e3;
|
|
@@ -18382,7 +18607,7 @@ function parseJsonObject5(body) {
|
|
|
18382
18607
|
function mintWorkerJwt(randomToken, issuedAt) {
|
|
18383
18608
|
const encode = (value) => Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
|
|
18384
18609
|
const header = encode({ alg: "HS256", typ: "JWT" });
|
|
18385
|
-
const payload = encode({ exp: Math.floor((issuedAt + RC_SELF_HOST_WORKER_JWT_TTL_SECONDS *
|
|
18610
|
+
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
18611
|
return `${header}.${payload}.${Buffer.from(randomToken(), "utf8").toString("base64url")}`;
|
|
18387
18612
|
}
|
|
18388
18613
|
function createRcSelfHostSurface(deps) {
|
|
@@ -18926,7 +19151,7 @@ data: ${JSON.stringify(envelope)}
|
|
|
18926
19151
|
|
|
18927
19152
|
// src/frontdoor/rcSelfHostMint.ts
|
|
18928
19153
|
init_account();
|
|
18929
|
-
import
|
|
19154
|
+
import path34 from "node:path";
|
|
18930
19155
|
var CREDENTIALS_FILE2 = ".credentials.json";
|
|
18931
19156
|
var CLAUDE_JSON2 = ".claude.json";
|
|
18932
19157
|
var RC_SELF_HOST_RECORD_DIR = "rc-selfhost";
|
|
@@ -18950,7 +19175,7 @@ function readJsonObject(fs13, file) {
|
|
|
18950
19175
|
return isRecord14(parsed) ? parsed : void 0;
|
|
18951
19176
|
}
|
|
18952
19177
|
function readRcSelfHostRecord(fs13, frontdoorDir) {
|
|
18953
|
-
const parsed = readJsonObject(fs13,
|
|
19178
|
+
const parsed = readJsonObject(fs13, path34.join(frontdoorDir, RC_SELF_HOST_RECORD_DIR, RC_SELF_HOST_RECORD_FILE));
|
|
18954
19179
|
if (parsed === void 0) {
|
|
18955
19180
|
return void 0;
|
|
18956
19181
|
}
|
|
@@ -18964,11 +19189,11 @@ function mintRcSelfHostCredential(deps) {
|
|
|
18964
19189
|
if (!isIdentityName(deps.identity)) {
|
|
18965
19190
|
throw new Error(`"${deps.identity}" is not a valid identity name.`);
|
|
18966
19191
|
}
|
|
18967
|
-
const identityDir =
|
|
18968
|
-
const credentialsFile =
|
|
18969
|
-
const claudeJsonFile =
|
|
18970
|
-
const recordDir =
|
|
18971
|
-
const recordFile =
|
|
19192
|
+
const identityDir = path34.join(deps.identitiesDir, deps.identity);
|
|
19193
|
+
const credentialsFile = path34.join(identityDir, CREDENTIALS_FILE2);
|
|
19194
|
+
const claudeJsonFile = path34.join(identityDir, CLAUDE_JSON2);
|
|
19195
|
+
const recordDir = path34.join(deps.frontdoorDir, RC_SELF_HOST_RECORD_DIR);
|
|
19196
|
+
const recordFile = path34.join(recordDir, RC_SELF_HOST_RECORD_FILE);
|
|
18972
19197
|
const previousRecord = readRcSelfHostRecord(deps.fs, deps.frontdoorDir);
|
|
18973
19198
|
const existingCredentials = readJsonObject(deps.fs, credentialsFile);
|
|
18974
19199
|
const existingOauth = isRecord14(existingCredentials?.claudeAiOauth) ? existingCredentials.claudeAiOauth : void 0;
|
|
@@ -18984,7 +19209,7 @@ function mintRcSelfHostCredential(deps) {
|
|
|
18984
19209
|
const organizationUuid = deps.newUuid();
|
|
18985
19210
|
const accountUuid = deps.newUuid();
|
|
18986
19211
|
const mintedAt = new Date(deps.now()).toISOString();
|
|
18987
|
-
deps.fs.mkdirPrivate(
|
|
19212
|
+
deps.fs.mkdirPrivate(path34.dirname(credentialsFile));
|
|
18988
19213
|
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
19214
|
`);
|
|
18990
19215
|
const claudeJson = readJsonObject(deps.fs, claudeJsonFile) ?? {};
|
|
@@ -19026,8 +19251,8 @@ init_plan2();
|
|
|
19026
19251
|
init_poolPick();
|
|
19027
19252
|
|
|
19028
19253
|
// src/agents/read.ts
|
|
19029
|
-
import
|
|
19030
|
-
import { z as
|
|
19254
|
+
import path35 from "node:path";
|
|
19255
|
+
import { z as z30 } from "zod";
|
|
19031
19256
|
var PROJECTS_DIR = "projects";
|
|
19032
19257
|
var TASKS_DIR = "tasks";
|
|
19033
19258
|
var SUBAGENTS_DIR = "subagents";
|
|
@@ -19052,15 +19277,15 @@ function parseEntry2(project, entry) {
|
|
|
19052
19277
|
}
|
|
19053
19278
|
function listSessions2(fs13, configDir) {
|
|
19054
19279
|
const found = [];
|
|
19055
|
-
for (const project of fs13.readdir(
|
|
19056
|
-
const projectDir =
|
|
19280
|
+
for (const project of fs13.readdir(path35.join(configDir, PROJECTS_DIR))) {
|
|
19281
|
+
const projectDir = path35.join(configDir, PROJECTS_DIR, project);
|
|
19057
19282
|
const entries = /* @__PURE__ */ new Set();
|
|
19058
19283
|
for (const name of fs13.readdir(projectDir)) {
|
|
19059
19284
|
if (name.endsWith(TRANSCRIPT_SUFFIX)) {
|
|
19060
19285
|
entries.add(name.slice(0, -TRANSCRIPT_SUFFIX.length));
|
|
19061
19286
|
continue;
|
|
19062
19287
|
}
|
|
19063
|
-
const children = fs13.readdir(
|
|
19288
|
+
const children = fs13.readdir(path35.join(projectDir, name));
|
|
19064
19289
|
if (children.includes(SUBAGENTS_DIR) || children.includes(WORKFLOWS_DIR)) {
|
|
19065
19290
|
entries.add(name);
|
|
19066
19291
|
}
|
|
@@ -19080,8 +19305,8 @@ function locateAgents(fs13, configDir, relativeDir, workflowRunId, report) {
|
|
|
19080
19305
|
const id = name.slice(AGENT_FILE_PREFIX.length, -META_SUFFIX.length);
|
|
19081
19306
|
located.push({
|
|
19082
19307
|
id,
|
|
19083
|
-
metaPath:
|
|
19084
|
-
transcriptPath:
|
|
19308
|
+
metaPath: path35.join(relativeDir, name),
|
|
19309
|
+
transcriptPath: path35.join(relativeDir, `${AGENT_FILE_PREFIX}${id}${TRANSCRIPT_SUFFIX}`),
|
|
19085
19310
|
workflowRunId
|
|
19086
19311
|
});
|
|
19087
19312
|
}
|
|
@@ -19124,7 +19349,7 @@ function describeFailure(error) {
|
|
|
19124
19349
|
}
|
|
19125
19350
|
function readFileOrReport(fs13, configDir, relative, report) {
|
|
19126
19351
|
try {
|
|
19127
|
-
return fs13.readFileUtf8(
|
|
19352
|
+
return fs13.readFileUtf8(path35.join(configDir, relative));
|
|
19128
19353
|
} catch (error) {
|
|
19129
19354
|
report({ path: relative, reason: `could not be read: ${describeFailure(error)}` });
|
|
19130
19355
|
return void 0;
|
|
@@ -19132,7 +19357,7 @@ function readFileOrReport(fs13, configDir, relative, report) {
|
|
|
19132
19357
|
}
|
|
19133
19358
|
function listDirOrReport(fs13, configDir, relative, report) {
|
|
19134
19359
|
try {
|
|
19135
|
-
return fs13.readdir(
|
|
19360
|
+
return fs13.readdir(path35.join(configDir, relative));
|
|
19136
19361
|
} catch (error) {
|
|
19137
19362
|
report({ path: relative, reason: `could not be listed: ${describeFailure(error)}` });
|
|
19138
19363
|
return [];
|
|
@@ -19146,28 +19371,28 @@ function parseJson2(text) {
|
|
|
19146
19371
|
return void 0;
|
|
19147
19372
|
}
|
|
19148
19373
|
}
|
|
19149
|
-
var TaskFileSchema =
|
|
19150
|
-
var WorkflowRunFileSchema =
|
|
19151
|
-
runId:
|
|
19152
|
-
workflowName:
|
|
19153
|
-
status:
|
|
19154
|
-
startTime:
|
|
19155
|
-
phases:
|
|
19156
|
-
summary:
|
|
19374
|
+
var TaskFileSchema = z30.object({ ...TaskItemSchema.omit({ taskList: true }).shape, blocks: z30.array(z30.string()).default([]), blockedBy: z30.array(z30.string()).default([]) });
|
|
19375
|
+
var WorkflowRunFileSchema = z30.object({
|
|
19376
|
+
runId: z30.string(),
|
|
19377
|
+
workflowName: z30.string().optional(),
|
|
19378
|
+
status: z30.string().optional(),
|
|
19379
|
+
startTime: z30.number().optional(),
|
|
19380
|
+
phases: z30.array(z30.object({ title: z30.string() })).default([]),
|
|
19381
|
+
summary: z30.string().optional()
|
|
19157
19382
|
});
|
|
19158
19383
|
function summariseSession(fs13, configDir, ref) {
|
|
19159
|
-
const sessionRelative =
|
|
19160
|
-
const subagentsRelative =
|
|
19161
|
-
const workflowsUnderSubagents =
|
|
19384
|
+
const sessionRelative = path35.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
19385
|
+
const subagentsRelative = path35.join(sessionRelative, SUBAGENTS_DIR);
|
|
19386
|
+
const workflowsUnderSubagents = path35.join(subagentsRelative, WORKFLOWS_DIR);
|
|
19162
19387
|
const isMeta = (name) => name.startsWith(AGENT_FILE_PREFIX) && name.endsWith(META_SUFFIX);
|
|
19163
|
-
let agentCount = fs13.readdir(
|
|
19164
|
-
for (const runDir of fs13.readdir(
|
|
19388
|
+
let agentCount = fs13.readdir(path35.join(configDir, subagentsRelative)).filter(isMeta).length;
|
|
19389
|
+
for (const runDir of fs13.readdir(path35.join(configDir, workflowsUnderSubagents))) {
|
|
19165
19390
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
19166
|
-
agentCount += fs13.readdir(
|
|
19391
|
+
agentCount += fs13.readdir(path35.join(configDir, workflowsUnderSubagents, runDir)).filter(isMeta).length;
|
|
19167
19392
|
}
|
|
19168
19393
|
}
|
|
19169
|
-
const workflowRunCount = fs13.readdir(
|
|
19170
|
-
const transcript = fs13.lstat(
|
|
19394
|
+
const workflowRunCount = fs13.readdir(path35.join(configDir, sessionRelative, WORKFLOWS_DIR)).filter((name) => name.startsWith(WORKFLOW_RUN_PREFIX) && name.endsWith(JSON_SUFFIX)).length;
|
|
19395
|
+
const transcript = fs13.lstat(path35.join(configDir, PROJECTS_DIR, ref.project, `${ref.entry}${TRANSCRIPT_SUFFIX}`));
|
|
19171
19396
|
return { ...ref, agentCount, workflowRunCount, ...transcript === void 0 ? {} : { updatedAt: new Date(transcript.mtimeMs).toISOString() } };
|
|
19172
19397
|
}
|
|
19173
19398
|
function readSessionAgentTree(fs13, configDir, ref, options = {}) {
|
|
@@ -19175,13 +19400,13 @@ function readSessionAgentTree(fs13, configDir, ref, options = {}) {
|
|
|
19175
19400
|
const report = (problem) => {
|
|
19176
19401
|
problems.push(problem);
|
|
19177
19402
|
};
|
|
19178
|
-
const sessionRelative =
|
|
19179
|
-
const subagentsRelative =
|
|
19180
|
-
const workflowsUnderSubagents =
|
|
19403
|
+
const sessionRelative = path35.join(PROJECTS_DIR, ref.project, ref.entry);
|
|
19404
|
+
const subagentsRelative = path35.join(sessionRelative, SUBAGENTS_DIR);
|
|
19405
|
+
const workflowsUnderSubagents = path35.join(subagentsRelative, WORKFLOWS_DIR);
|
|
19181
19406
|
const located = locateAgents(fs13, configDir, subagentsRelative, void 0, report);
|
|
19182
19407
|
for (const runDir of listDirOrReport(fs13, configDir, workflowsUnderSubagents, report)) {
|
|
19183
19408
|
if (runDir.startsWith(WORKFLOW_RUN_PREFIX)) {
|
|
19184
|
-
located.push(...locateAgents(fs13, configDir,
|
|
19409
|
+
located.push(...locateAgents(fs13, configDir, path35.join(workflowsUnderSubagents, runDir), runDir, report));
|
|
19185
19410
|
}
|
|
19186
19411
|
}
|
|
19187
19412
|
const agents = /* @__PURE__ */ new Map();
|
|
@@ -19222,7 +19447,7 @@ function readSessionAgentTree(fs13, configDir, ref, options = {}) {
|
|
|
19222
19447
|
superseded: ref.superseded,
|
|
19223
19448
|
agents: roots.sort().map(build),
|
|
19224
19449
|
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,
|
|
19450
|
+
workflowRuns: readWorkflowRuns(fs13, configDir, path35.join(sessionRelative, WORKFLOWS_DIR), report),
|
|
19226
19451
|
problems
|
|
19227
19452
|
};
|
|
19228
19453
|
}
|
|
@@ -19287,12 +19512,12 @@ function ownTaskLists(sessionId) {
|
|
|
19287
19512
|
function readTasks(fs13, configDir, ownLists, sharedLists, report) {
|
|
19288
19513
|
const tasks = [];
|
|
19289
19514
|
[...ownLists, ...sharedLists].forEach((scope, index) => {
|
|
19290
|
-
const relativeDir =
|
|
19515
|
+
const relativeDir = path35.join(TASKS_DIR, scope);
|
|
19291
19516
|
for (const name of [...listDirOrReport(fs13, configDir, relativeDir, report)].sort()) {
|
|
19292
19517
|
if (name.startsWith(".") || !name.endsWith(JSON_SUFFIX)) {
|
|
19293
19518
|
continue;
|
|
19294
19519
|
}
|
|
19295
|
-
const relative =
|
|
19520
|
+
const relative = path35.join(relativeDir, name);
|
|
19296
19521
|
const text = readFileOrReport(fs13, configDir, relative, report);
|
|
19297
19522
|
const parsed = TaskFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
19298
19523
|
if (parsed.success) {
|
|
@@ -19310,7 +19535,7 @@ function readWorkflowRuns(fs13, configDir, relativeDir, report) {
|
|
|
19310
19535
|
if (!name.startsWith(WORKFLOW_RUN_PREFIX) || !name.endsWith(JSON_SUFFIX)) {
|
|
19311
19536
|
continue;
|
|
19312
19537
|
}
|
|
19313
|
-
const relative =
|
|
19538
|
+
const relative = path35.join(relativeDir, name);
|
|
19314
19539
|
const text = readFileOrReport(fs13, configDir, relative, report);
|
|
19315
19540
|
const parsed = WorkflowRunFileSchema.safeParse(text === void 0 ? void 0 : parseJson2(text));
|
|
19316
19541
|
if (!parsed.success) {
|
|
@@ -19327,7 +19552,7 @@ function readWorkflowRuns(fs13, configDir, relativeDir, report) {
|
|
|
19327
19552
|
|
|
19328
19553
|
// src/agents/sessions.ts
|
|
19329
19554
|
init_cliError();
|
|
19330
|
-
import
|
|
19555
|
+
import path36 from "node:path";
|
|
19331
19556
|
var SessionLookupError = class extends CliError {
|
|
19332
19557
|
constructor(message) {
|
|
19333
19558
|
super(message);
|
|
@@ -19335,13 +19560,13 @@ var SessionLookupError = class extends CliError {
|
|
|
19335
19560
|
}
|
|
19336
19561
|
};
|
|
19337
19562
|
function identityConfigDir(identitiesDir, identity) {
|
|
19338
|
-
return
|
|
19563
|
+
return path36.join(identitiesDir, identity);
|
|
19339
19564
|
}
|
|
19340
19565
|
function historyStores(fs13, identitiesDir, identities) {
|
|
19341
19566
|
const byRealPath = /* @__PURE__ */ new Map();
|
|
19342
19567
|
for (const identity of identities) {
|
|
19343
19568
|
const configDir = identityConfigDir(identitiesDir, identity);
|
|
19344
|
-
const real = fs13.realpath(
|
|
19569
|
+
const real = fs13.realpath(path36.join(configDir, "projects"));
|
|
19345
19570
|
if (real === void 0) {
|
|
19346
19571
|
continue;
|
|
19347
19572
|
}
|