@hasna/switcher 0.2.6 → 0.2.7
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 +31 -2
- package/dist/antigravity-config.d.ts +7 -0
- package/dist/bedrock.d.ts +2 -0
- package/dist/cli/index.js +501 -228
- package/dist/domain.d.ts +18 -8
- package/dist/generated/api.d.ts +17 -5
- package/dist/harnesses.d.ts +2 -2
- package/dist/index.js +23 -4
- package/dist/junie-config.d.ts +8 -0
- package/dist/launcher.d.ts +1 -1
- package/dist/mcp/index.js +82 -8
- package/dist/model-policy-schema.d.ts +3 -0
- package/dist/model-policy.d.ts +1 -0
- package/dist/native-cli-settings.d.ts +6 -0
- package/dist/native-model-policy.d.ts +1 -1
- package/dist/sdk.d.ts +18 -9
- package/dist/sdk.js +23 -4
- package/dist/serve/index.js +78 -7
- package/docs/MODEL-POLICY.md +6 -2
- package/openapi.json +53 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -480,6 +480,7 @@ var fallbacksSchema = z3.record(policyModelIdSchema, z3.array(policyModelIdSchem
|
|
|
480
480
|
});
|
|
481
481
|
var modelPolicySchema = z3.object({
|
|
482
482
|
version: z3.literal(1).default(1),
|
|
483
|
+
selection: z3.enum(["restricted", "catalog"]).optional(),
|
|
483
484
|
roles: z3.object({
|
|
484
485
|
subagent: policyModelIdSchema.optional(),
|
|
485
486
|
fast: policyModelIdSchema.optional(),
|
|
@@ -514,8 +515,8 @@ function canonicalPolicyJSON(value) {
|
|
|
514
515
|
}
|
|
515
516
|
|
|
516
517
|
// src/domain.ts
|
|
517
|
-
var VERSION = "0.2.
|
|
518
|
-
var harnessSchema = z4.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"]);
|
|
518
|
+
var VERSION = "0.2.7";
|
|
519
|
+
var harnessSchema = z4.enum(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "antigravity", "junie", "aider", "kilo"]);
|
|
519
520
|
var protocolSchema = z4.enum(["anthropic-messages", "openai-responses", "openai-chat", "gemini-generate-content"]);
|
|
520
521
|
var idSchema = z4.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/);
|
|
521
522
|
var label = z4.string().min(1).max(200);
|
|
@@ -647,7 +648,7 @@ function compatible(harness, protocol) {
|
|
|
647
648
|
return protocol === "anthropic-messages";
|
|
648
649
|
if (harness === "codex")
|
|
649
650
|
return protocol === "openai-responses";
|
|
650
|
-
if (harness === "gemini")
|
|
651
|
+
if (harness === "gemini" || harness === "antigravity")
|
|
651
652
|
return protocol === "gemini-generate-content";
|
|
652
653
|
if (protocol === "gemini-generate-content")
|
|
653
654
|
return false;
|
|
@@ -656,7 +657,7 @@ function compatible(harness, protocol) {
|
|
|
656
657
|
function validateHarnessProvider(harness, provider) {
|
|
657
658
|
if (!compatible(harness, provider.protocol))
|
|
658
659
|
throw new Fault(422, "protocol_mismatch", "Harness does not support this provider protocol.");
|
|
659
|
-
if (harness === "gemini" && provider.authStyle !== "x-api-key")
|
|
660
|
+
if ((harness === "gemini" || harness === "antigravity") && provider.authStyle !== "x-api-key")
|
|
660
661
|
throw new Fault(422, "auth_mismatch", "Gemini CLI requires x-api-key authentication for its native generateContent protocol.");
|
|
661
662
|
}
|
|
662
663
|
function modelExpired(model, now = new Date) {
|
|
@@ -855,6 +856,8 @@ function aiderArguments(args) {
|
|
|
855
856
|
|
|
856
857
|
// src/harness-arguments.ts
|
|
857
858
|
var reserved2 = {
|
|
859
|
+
antigravity: ["--model", "--agent", "--remote-control", "--project", "--new-project"],
|
|
860
|
+
junie: ["--model", "--provider", "--auth", "-a", "--openai-api-key", "--anthropic-api-key", "--grok-api-key", "--openrouter-api-key", "--google-api-key", "--litellm-api-key", "--litellm-url", "--config-location", "--config-default-locations", "--model-location", "--model-default-locations", "--cache-dir", "-c", "--project", "-p", "--acp", "--gateway", "--gateway-stop", "--gateway-status"],
|
|
858
861
|
gemini: ["--model", "--no-model", "--no-m", "-m", "--settings", "--acp", "--experimental-acp", "--experimentalAcp"],
|
|
859
862
|
"prime-agent": ["--model", "--provider", "--api-key", "--models", "--session-dir", "--daemon-socket"],
|
|
860
863
|
hermes: ["--model", "-m", "--provider", "--config", "--profile", "-p", "--api-key", "--base-url", "--ignore-user-config", "--safe-mode", "--worktree", "-w"],
|
|
@@ -871,6 +874,8 @@ var reserved2 = {
|
|
|
871
874
|
omp: ["--model", "--provider", "--api-key", "--profile", "--cwd", "--config", "--session-dir", "--models", "--no-rules", "--smol", "--slow", "--plan", "--prewalk", "--prewalk-into", "--plan-yolo-into", "--plan-yolo", "--auto-approve", "--yolo", "--approval-mode", "--alias", "--plugin-dir", "--hook", "--extension", "-e", "--trusted-extension", "--from-claude", "--from-codex"]
|
|
872
875
|
};
|
|
873
876
|
var values = {
|
|
877
|
+
antigravity: ["--add-dir", "--conversation", "--effort", "-i", "--prompt-interactive", "--input-format", "--json-schema", "--log-file", "--mode", "--output-format", "-p", "--print", "--prompt", "--print-timeout"],
|
|
878
|
+
junie: ["--task", "--prompt", "--session-id", "--share-anonymous-statistics", "--input-format", "--output-format", "--json-output-file", "--agent-mode", "--guidelines-filename", "--ide-guidelines", "--effort", "--mcp-default-locations", "--mcp-location", "--extensions-default-location", "--skill-default-locations", "--skill-location", "--command-default-location", "--command-location", "--agent-default-location", "--agent-location"],
|
|
874
879
|
gemini: ["--prompt", "-p", "--prompt-interactive", "--promptInteractive", "-i", "--approval-mode", "--approvalMode", "--policy", "--admin-policy", "--adminPolicy", "--allowed-mcp-server-names", "--allowedMcpServerNames", "--extensions", "-e", "--session-file", "--sessionFile", "--session-id", "--sessionId", "--include-directories", "--includeDirectories", "--output-format", "--outputFormat", "-o", "--allowed-tools", "--allowedTools", "--delete-session", "--deleteSession"],
|
|
875
880
|
"prime-agent": ["--mode", "--system-prompt", "--append-system-prompt", "--name", "--session", "--session-id", "--fork", "--tools", "--exclude-tools", "--thinking", "--export", "--extension", "--skill", "--prompt-template", "--theme", "--use-theme", "--tui-mode", "--prompt", "--output-format"],
|
|
876
881
|
hermes: ["--model", "--provider", "--reasoning", "--toolsets", "--skills", "--resume", "--usage-file", "--in", "--oneshot", "--query", "--query-file", "--image", "--max-turns", "--run-budget", "--source"],
|
|
@@ -896,6 +901,7 @@ var optionalValues = {
|
|
|
896
901
|
omp: ["--resume", "-r", "--session"]
|
|
897
902
|
};
|
|
898
903
|
var short = {
|
|
904
|
+
junie: { required: "apc", optional: "", boolean: "hv" },
|
|
899
905
|
hermes: { required: "zmtsrqp", optional: "c", boolean: "VhvQw" },
|
|
900
906
|
cline: { required: "Pmksct", optional: "", boolean: "yz" },
|
|
901
907
|
codex: { required: "cimpsCao", optional: "", boolean: "hV" },
|
|
@@ -953,6 +959,8 @@ function assertHarnessArguments(harness, args, options = {}) {
|
|
|
953
959
|
return;
|
|
954
960
|
}
|
|
955
961
|
const blocked = new Set([...reserved2[harness], ...options.additionalReserved ?? []]);
|
|
962
|
+
if (harness === "antigravity" && args[0] && !args[0].startsWith("-"))
|
|
963
|
+
throw new Error("Antigravity subcommands are outside the managed inference launch; pass prompts with -p.");
|
|
956
964
|
const reject = () => {
|
|
957
965
|
throw new Error("Provider/model configuration arguments are reserved by the launch profile; update the profile instead.");
|
|
958
966
|
};
|
|
@@ -984,6 +992,8 @@ function assertHarnessArguments(harness, args, options = {}) {
|
|
|
984
992
|
}
|
|
985
993
|
const equals = arg.indexOf("=");
|
|
986
994
|
let flag = equals < 0 ? arg : arg.slice(0, equals);
|
|
995
|
+
if (harness === "antigravity" && /^-[^-].+/.test(flag))
|
|
996
|
+
flag = "-" + flag;
|
|
987
997
|
if (harness === "hermes" && flag.startsWith("--")) {
|
|
988
998
|
if ([...blocked].some((option) => option.startsWith(flag)))
|
|
989
999
|
reject();
|
|
@@ -1065,6 +1075,19 @@ async function boundedJson(response, maxBytes = MAX_BYTES) {
|
|
|
1065
1075
|
// src/sdk.ts
|
|
1066
1076
|
import { createClientTransport } from "@hasna/contracts/client";
|
|
1067
1077
|
|
|
1078
|
+
// src/bedrock.ts
|
|
1079
|
+
function bedrockMantleOrigin(value) {
|
|
1080
|
+
let url;
|
|
1081
|
+
try {
|
|
1082
|
+
url = new URL(value);
|
|
1083
|
+
} catch {
|
|
1084
|
+
return;
|
|
1085
|
+
}
|
|
1086
|
+
if (url.protocol !== "https:" || url.port || url.username || url.password || url.search || url.hash || url.pathname.replace(/\/+$/, "") !== "/anthropic/v1")
|
|
1087
|
+
return;
|
|
1088
|
+
return /^bedrock-mantle\.[a-z]{2}(?:-[a-z]+)+-\d+\.api\.aws$/.test(url.hostname) ? url.origin : undefined;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1068
1091
|
// src/presets.ts
|
|
1069
1092
|
var route = (protocol, baseUrl, options = {}) => ({
|
|
1070
1093
|
protocol,
|
|
@@ -1097,8 +1120,10 @@ var providerPresets = [
|
|
|
1097
1120
|
], ["https://api-docs.deepseek.com/guides/anthropic_api", "https://api-docs.deepseek.com/api/list-models", "https://api-docs.deepseek.com/updates/", "https://api-docs.deepseek.com/guides/responses_api/"], "DEEPSEEK_API_KEY"),
|
|
1098
1121
|
preset("openrouter", "OpenRouter", ["openai-chat", "openai-responses", "anthropic-messages"].map((protocol) => route(protocol, "https://openrouter.ai/api/v1", { catalogAuthStyle: "none", credentialCheck: { method: "GET", path: "key" } })), ["https://openrouter.ai/docs/api/api-reference/models/list-all-models-and-their-properties", "https://openrouter.ai/docs/guides/overview"], "OPENROUTER_API_KEY"),
|
|
1099
1122
|
preset("anthropic", "Anthropic", [route("anthropic-messages", "https://api.anthropic.com/v1", { authStyle: "x-api-key" })], ["https://platform.claude.com/docs/en/api/overview", "https://platform.claude.com/docs/en/api/models/list"], "ANTHROPIC_API_KEY"),
|
|
1123
|
+
preset("bedrock", "Amazon Bedrock (Mantle)", [route("anthropic-messages", undefined, { authStyle: "x-api-key", catalogAuthStyle: "bearer", notes: ["Pass the regional https://bedrock-mantle.<region>.api.aws/anthropic/v1 endpoint and a Bedrock API key. The authenticated catalog is /v1/models on that same origin. Model access and regional availability remain controlled by the AWS account; this route does not distribute or inherit AWS administrative credentials."] })], ["https://docs.aws.amazon.com/bedrock/latest/userguide/inference-messages-api.html", "https://docs.aws.amazon.com/bedrock/latest/userguide/api-keys.html"], "AWS_BEARER_TOKEN_BEDROCK"),
|
|
1100
1124
|
preset("gemini", "Google Gemini", [route("gemini-generate-content", "https://generativelanguage.googleapis.com/v1beta", {
|
|
1101
1125
|
authStyle: "x-api-key",
|
|
1126
|
+
credentialCheck: { method: "GET", path: "models" },
|
|
1102
1127
|
catalogBaseUrl: "https://generativelanguage.googleapis.com/v1beta",
|
|
1103
1128
|
catalogFormat: "gemini",
|
|
1104
1129
|
catalogAuthStyle: "x-api-key",
|
|
@@ -1169,16 +1194,19 @@ function providerFromPreset(presetId, options = {}) {
|
|
|
1169
1194
|
const baseUrl = options.baseUrl ?? selected.baseUrl;
|
|
1170
1195
|
if (!baseUrl)
|
|
1171
1196
|
throw new Fault(400, "endpoint_required", "This preset requires an explicit --url for its inference endpoint.");
|
|
1197
|
+
const bedrockOrigin = presetId === "bedrock" ? bedrockMantleOrigin(endpoint(baseUrl)) : undefined;
|
|
1198
|
+
if (presetId === "bedrock" && !bedrockOrigin)
|
|
1199
|
+
throw new Fault(400, "invalid_url", "Bedrock requires a regional HTTPS Mantle endpoint ending in /anthropic/v1.");
|
|
1172
1200
|
if (presetId === "azure-openai" && !/\/openai\/v1$/.test(endpoint(baseUrl)))
|
|
1173
1201
|
throw new Fault(400, "invalid_url", "Azure OpenAI v1 requires an explicit endpoint ending in /openai/v1; deployment and api-version URLs are unsupported.");
|
|
1174
1202
|
if (options.baseUrl && selected.baseUrl && new URL(endpoint(options.baseUrl)).origin !== new URL(selected.baseUrl).origin && preset2.credentialEnv && !options.credentialEnv)
|
|
1175
1203
|
throw new Fault(422, "credential_authority", "An endpoint on another origin requires an explicit --credential-env reference.");
|
|
1176
|
-
const suffix = selected.protocol === "anthropic-messages" ? "messages" : selected.protocol === "openai-responses" ? "responses" : "chat";
|
|
1204
|
+
const suffix = selected.protocol === "anthropic-messages" ? "messages" : selected.protocol === "openai-responses" ? "responses" : selected.protocol === "gemini-generate-content" ? "generate-content" : "chat";
|
|
1177
1205
|
if (presetId === "fireworks" && !options.catalogBaseUrl && !options.catalogAccountId)
|
|
1178
1206
|
throw new Fault(400, "catalog_account_required", "Fireworks model discovery requires --catalog-account-id or an explicit --catalog-url.");
|
|
1179
1207
|
if (selected.catalogFormat === "none" && options.catalogFormat && options.catalogFormat !== "none" && !options.catalogBaseUrl)
|
|
1180
1208
|
throw new Fault(400, "catalog_url_required", "This preset requires an explicit --catalog-url when enabling a catalog parser.");
|
|
1181
|
-
const catalogBaseUrl = options.catalogBaseUrl ?? (presetId === "fireworks" && options.catalogAccountId ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(options.catalogAccountId)}` : options.baseUrl ? undefined : selected.catalogBaseUrl);
|
|
1209
|
+
const catalogBaseUrl = options.catalogBaseUrl ?? (bedrockOrigin ? `${bedrockOrigin}/v1` : presetId === "fireworks" && options.catalogAccountId ? `https://api.fireworks.ai/v1/accounts/${encodeURIComponent(options.catalogAccountId)}` : options.baseUrl ? undefined : selected.catalogBaseUrl);
|
|
1182
1210
|
return parse2(providerInputSchema, {
|
|
1183
1211
|
id: options.id ?? `${preset2.id}-${suffix}`,
|
|
1184
1212
|
name: preset2.name,
|
|
@@ -1207,7 +1235,7 @@ function providerCredential(provider, env = process.env) {
|
|
|
1207
1235
|
return;
|
|
1208
1236
|
let value = env[provider.credentialEnv];
|
|
1209
1237
|
if (!value) {
|
|
1210
|
-
const preset2 = providerPresets.find((p) => p.credentialEnv === provider.credentialEnv && p.protocols.some((route2) => route2.protocol === provider.protocol && (route2.baseUrl ? new URL(route2.baseUrl).origin === new URL(provider.baseUrl).origin : p.id === "azure-openai")));
|
|
1238
|
+
const preset2 = providerPresets.find((p) => p.credentialEnv === provider.credentialEnv && p.protocols.some((route2) => route2.protocol === provider.protocol && (route2.baseUrl ? new URL(route2.baseUrl).origin === new URL(provider.baseUrl).origin : p.id === "azure-openai" || p.id === "bedrock" && !!bedrockMantleOrigin(provider.baseUrl))));
|
|
1211
1239
|
value = preset2?.credentialAliases.map((name) => env[name]).find(Boolean);
|
|
1212
1240
|
}
|
|
1213
1241
|
if (value && /[\r\n]/.test(value))
|
|
@@ -2147,6 +2175,8 @@ async function discoverBase(provider, env = process.env, resolveCredential) {
|
|
|
2147
2175
|
reasoningEfforts: row.reasoning?.supported_efforts,
|
|
2148
2176
|
...provider.catalogFormat === "gemini" && row.supportedGenerationMethods !== undefined ? { supportedGenerationMethods: row.supportedGenerationMethods } : {}
|
|
2149
2177
|
};
|
|
2178
|
+
if (provider.protocol === "anthropic-messages" && bedrockMantleOrigin(provider.baseUrl) && !id.startsWith("anthropic."))
|
|
2179
|
+
candidate.available = false;
|
|
2150
2180
|
if (provider.catalogFormat === "mistral") {
|
|
2151
2181
|
const capabilities = row.capabilities;
|
|
2152
2182
|
if (typeof capabilities?.function_calling === "boolean")
|
|
@@ -2312,6 +2342,7 @@ function compileModelPolicy(model, catalog, policy) {
|
|
|
2312
2342
|
throw new Fault(400, "invalid_model_policy", "Model policy allowedModels is too large.");
|
|
2313
2343
|
for (const value of explicitAllowed)
|
|
2314
2344
|
requireAvailable(value, "An allowed model is not present in the eligible catalog.");
|
|
2345
|
+
const catalogAllowed = p.selection === "catalog" ? [...available] : [];
|
|
2315
2346
|
const aliases = Object.create(null);
|
|
2316
2347
|
for (const [name, target] of Object.entries(p.aliases ?? {})) {
|
|
2317
2348
|
if (Object.keys(aliases).length >= 200 || !/^[A-Za-z0-9._/-]{1,120}$/.test(name) || ["__proto__", "prototype", "constructor"].includes(name))
|
|
@@ -2323,7 +2354,7 @@ function compileModelPolicy(model, catalog, policy) {
|
|
|
2323
2354
|
aliases[name] = canonical;
|
|
2324
2355
|
}
|
|
2325
2356
|
const fallbacks = Object.create(null);
|
|
2326
|
-
const allowedSources = new Set([selected, ...Object.values(compiledRoles), ...explicitAllowed]);
|
|
2357
|
+
const allowedSources = new Set([selected, ...Object.values(compiledRoles), ...explicitAllowed, ...catalogAllowed]);
|
|
2327
2358
|
for (const [source, targets] of Object.entries(p.fallbacks ?? {})) {
|
|
2328
2359
|
if (!allowedSources.has(source) || !available.has(source) || !Array.isArray(targets) || Object.keys(fallbacks).length >= 200 || targets.length > 20)
|
|
2329
2360
|
throw new Fault(400, "invalid_model_policy", "Fallback source or list is invalid.");
|
|
@@ -2334,7 +2365,7 @@ function compileModelPolicy(model, catalog, policy) {
|
|
|
2334
2365
|
throw new Fault(400, "invalid_model_policy", "A model cannot fall back to itself.");
|
|
2335
2366
|
fallbacks[source] = uniq(values2);
|
|
2336
2367
|
}
|
|
2337
|
-
const allowedModels = uniq([selected, ...Object.values(compiledRoles), ...explicitAllowed, ...Object.values(fallbacks).flat()]).sort();
|
|
2368
|
+
const allowedModels = uniq([selected, ...Object.values(compiledRoles), ...explicitAllowed, ...catalogAllowed, ...Object.values(fallbacks).flat()]).sort();
|
|
2338
2369
|
if (Object.values(aliases).some((value) => !allowedModels.includes(value)))
|
|
2339
2370
|
throw new Fault(422, "model_not_allowed", "A model alias target must be explicitly allowed by the launch policy.");
|
|
2340
2371
|
const result = { version: 1, model: selected, roles: compiledRoles, allowedModels, aliases, fallbacks };
|
|
@@ -2440,7 +2471,7 @@ var openapi_default = {
|
|
|
2440
2471
|
openapi: "3.0.3",
|
|
2441
2472
|
info: {
|
|
2442
2473
|
title: "Switcher API",
|
|
2443
|
-
version: "0.2.
|
|
2474
|
+
version: "0.2.7",
|
|
2444
2475
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
2445
2476
|
},
|
|
2446
2477
|
security: [
|
|
@@ -4513,6 +4544,8 @@ var openapi_default = {
|
|
|
4513
4544
|
"hermes",
|
|
4514
4545
|
"prime-agent",
|
|
4515
4546
|
"gemini",
|
|
4547
|
+
"antigravity",
|
|
4548
|
+
"junie",
|
|
4516
4549
|
"aider",
|
|
4517
4550
|
"kilo"
|
|
4518
4551
|
]
|
|
@@ -4532,6 +4565,13 @@ var openapi_default = {
|
|
|
4532
4565
|
],
|
|
4533
4566
|
default: 1
|
|
4534
4567
|
},
|
|
4568
|
+
selection: {
|
|
4569
|
+
type: "string",
|
|
4570
|
+
enum: [
|
|
4571
|
+
"restricted",
|
|
4572
|
+
"catalog"
|
|
4573
|
+
]
|
|
4574
|
+
},
|
|
4535
4575
|
roles: {
|
|
4536
4576
|
type: "object",
|
|
4537
4577
|
properties: {
|
|
@@ -4662,6 +4702,8 @@ var openapi_default = {
|
|
|
4662
4702
|
"hermes",
|
|
4663
4703
|
"prime-agent",
|
|
4664
4704
|
"gemini",
|
|
4705
|
+
"antigravity",
|
|
4706
|
+
"junie",
|
|
4665
4707
|
"aider",
|
|
4666
4708
|
"kilo"
|
|
4667
4709
|
]
|
|
@@ -4681,6 +4723,13 @@ var openapi_default = {
|
|
|
4681
4723
|
],
|
|
4682
4724
|
default: 1
|
|
4683
4725
|
},
|
|
4726
|
+
selection: {
|
|
4727
|
+
type: "string",
|
|
4728
|
+
enum: [
|
|
4729
|
+
"restricted",
|
|
4730
|
+
"catalog"
|
|
4731
|
+
]
|
|
4732
|
+
},
|
|
4684
4733
|
roles: {
|
|
4685
4734
|
type: "object",
|
|
4686
4735
|
properties: {
|
|
@@ -4891,6 +4940,13 @@ var openapi_default = {
|
|
|
4891
4940
|
],
|
|
4892
4941
|
default: 1
|
|
4893
4942
|
},
|
|
4943
|
+
selection: {
|
|
4944
|
+
type: "string",
|
|
4945
|
+
enum: [
|
|
4946
|
+
"restricted",
|
|
4947
|
+
"catalog"
|
|
4948
|
+
]
|
|
4949
|
+
},
|
|
4894
4950
|
roles: {
|
|
4895
4951
|
type: "object",
|
|
4896
4952
|
properties: {
|
|
@@ -5660,6 +5716,8 @@ var openapi_default = {
|
|
|
5660
5716
|
"hermes",
|
|
5661
5717
|
"prime-agent",
|
|
5662
5718
|
"gemini",
|
|
5719
|
+
"antigravity",
|
|
5720
|
+
"junie",
|
|
5663
5721
|
"aider",
|
|
5664
5722
|
"kilo"
|
|
5665
5723
|
]
|
|
@@ -5679,6 +5737,13 @@ var openapi_default = {
|
|
|
5679
5737
|
],
|
|
5680
5738
|
default: 1
|
|
5681
5739
|
},
|
|
5740
|
+
selection: {
|
|
5741
|
+
type: "string",
|
|
5742
|
+
enum: [
|
|
5743
|
+
"restricted",
|
|
5744
|
+
"catalog"
|
|
5745
|
+
]
|
|
5746
|
+
},
|
|
5682
5747
|
roles: {
|
|
5683
5748
|
type: "object",
|
|
5684
5749
|
properties: {
|
|
@@ -5952,6 +6017,8 @@ var openapi_default = {
|
|
|
5952
6017
|
"hermes",
|
|
5953
6018
|
"prime-agent",
|
|
5954
6019
|
"gemini",
|
|
6020
|
+
"antigravity",
|
|
6021
|
+
"junie",
|
|
5955
6022
|
"aider",
|
|
5956
6023
|
"kilo"
|
|
5957
6024
|
]
|
|
@@ -5971,6 +6038,13 @@ var openapi_default = {
|
|
|
5971
6038
|
],
|
|
5972
6039
|
default: 1
|
|
5973
6040
|
},
|
|
6041
|
+
selection: {
|
|
6042
|
+
type: "string",
|
|
6043
|
+
enum: [
|
|
6044
|
+
"restricted",
|
|
6045
|
+
"catalog"
|
|
6046
|
+
]
|
|
6047
|
+
},
|
|
5974
6048
|
roles: {
|
|
5975
6049
|
type: "object",
|
|
5976
6050
|
properties: {
|
|
@@ -6217,6 +6291,8 @@ var openapi_default = {
|
|
|
6217
6291
|
"hermes",
|
|
6218
6292
|
"prime-agent",
|
|
6219
6293
|
"gemini",
|
|
6294
|
+
"antigravity",
|
|
6295
|
+
"junie",
|
|
6220
6296
|
"aider",
|
|
6221
6297
|
"kilo"
|
|
6222
6298
|
]
|
|
@@ -6236,6 +6312,13 @@ var openapi_default = {
|
|
|
6236
6312
|
],
|
|
6237
6313
|
default: 1
|
|
6238
6314
|
},
|
|
6315
|
+
selection: {
|
|
6316
|
+
type: "string",
|
|
6317
|
+
enum: [
|
|
6318
|
+
"restricted",
|
|
6319
|
+
"catalog"
|
|
6320
|
+
]
|
|
6321
|
+
},
|
|
6239
6322
|
roles: {
|
|
6240
6323
|
type: "object",
|
|
6241
6324
|
properties: {
|
|
@@ -7289,6 +7372,164 @@ async function prepareGemini(input) {
|
|
|
7289
7372
|
] };
|
|
7290
7373
|
}
|
|
7291
7374
|
|
|
7375
|
+
// src/antigravity-config.ts
|
|
7376
|
+
import { join as join7 } from "path";
|
|
7377
|
+
import { readFile as readFile3, writeFile as writeFile5, lstat as lstat4 } from "fs/promises";
|
|
7378
|
+
|
|
7379
|
+
// src/native-cli-settings.ts
|
|
7380
|
+
import { lstat as lstat3, readFile as readFile2, writeFile as writeFile4, symlink as symlink2 } from "fs/promises";
|
|
7381
|
+
import { join as join6, isAbsolute as isAbsolute6 } from "path";
|
|
7382
|
+
import { homedir as homedir5 } from "os";
|
|
7383
|
+
function nativeHome(env) {
|
|
7384
|
+
const home = env.HOME ?? homedir5();
|
|
7385
|
+
if (!isAbsolute6(home))
|
|
7386
|
+
throw new Error("Native CLI requires an absolute home.");
|
|
7387
|
+
return home;
|
|
7388
|
+
}
|
|
7389
|
+
async function readNativeSettings(path) {
|
|
7390
|
+
let file;
|
|
7391
|
+
try {
|
|
7392
|
+
file = await lstat3(path);
|
|
7393
|
+
} catch (error) {
|
|
7394
|
+
if (error.code === "ENOENT")
|
|
7395
|
+
return {};
|
|
7396
|
+
throw error;
|
|
7397
|
+
}
|
|
7398
|
+
if (!file.isFile() || file.size > 1024 * 1024)
|
|
7399
|
+
throw new Error("Native CLI settings must be a bounded regular file.");
|
|
7400
|
+
let value;
|
|
7401
|
+
try {
|
|
7402
|
+
value = JSON.parse(await readFile2(path, "utf8"));
|
|
7403
|
+
} catch {
|
|
7404
|
+
throw new Error("Native CLI settings must contain a JSON object.");
|
|
7405
|
+
}
|
|
7406
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
7407
|
+
throw new Error("Native CLI settings must contain a JSON object.");
|
|
7408
|
+
return value;
|
|
7409
|
+
}
|
|
7410
|
+
function rejectNativeRouting(value, keys) {
|
|
7411
|
+
if (!value || typeof value !== "object")
|
|
7412
|
+
return;
|
|
7413
|
+
for (const [key, item] of Object.entries(value)) {
|
|
7414
|
+
const normalized = key.toLowerCase().replace(/[-_]/g, "");
|
|
7415
|
+
if (keys.has(normalized))
|
|
7416
|
+
throw new Error("Native CLI routing configuration conflicts with the Switcher launch profile.");
|
|
7417
|
+
rejectNativeRouting(item, keys);
|
|
7418
|
+
}
|
|
7419
|
+
}
|
|
7420
|
+
async function writeNativeSettings(path, value) {
|
|
7421
|
+
await writeFile4(path, JSON.stringify(value, null, 2) + `
|
|
7422
|
+
`, { mode: 384, flag: "wx" });
|
|
7423
|
+
return path;
|
|
7424
|
+
}
|
|
7425
|
+
async function durableNativeDirectory(root, target, name) {
|
|
7426
|
+
const directory = join6(target, name);
|
|
7427
|
+
await privateDirectory(directory);
|
|
7428
|
+
await symlink2(directory, join6(root, name), "dir");
|
|
7429
|
+
}
|
|
7430
|
+
async function readNativeText(path) {
|
|
7431
|
+
let file;
|
|
7432
|
+
try {
|
|
7433
|
+
file = await lstat3(path);
|
|
7434
|
+
} catch (error) {
|
|
7435
|
+
if (error.code === "ENOENT")
|
|
7436
|
+
return;
|
|
7437
|
+
throw error;
|
|
7438
|
+
}
|
|
7439
|
+
if (!file.isFile() || file.size > 1024 * 1024)
|
|
7440
|
+
throw new Error("Native CLI policy and instructions must be bounded regular files.");
|
|
7441
|
+
const text = await readFile2(path, "utf8");
|
|
7442
|
+
if (Buffer.byteLength(text) > 1024 * 1024)
|
|
7443
|
+
throw new Error("Native CLI policy and instructions exceed their size limit.");
|
|
7444
|
+
return text;
|
|
7445
|
+
}
|
|
7446
|
+
|
|
7447
|
+
// src/antigravity-config.ts
|
|
7448
|
+
var antigravityHelperModel = "gemini-3.1-flash-lite-preview";
|
|
7449
|
+
var routing = new Set(["custommodels", "custommodelsconfig", "apikey", "baseurl", "modelconfig", "modelconfigoverrides"]);
|
|
7450
|
+
async function validateAntigravityConfiguration(cwd, env = process.env) {
|
|
7451
|
+
const home = nativeHome(env), paths = [join7(home, ".gemini", "config", "config.json"), join7(home, ".gemini", "antigravity-cli", "settings.json"), join7(cwd, ".gemini", "antigravity-cli", "settings.json")];
|
|
7452
|
+
const layers = [];
|
|
7453
|
+
for (const path of [...new Set(paths)]) {
|
|
7454
|
+
const settings2 = await readNativeSettings(path);
|
|
7455
|
+
rejectNativeRouting(settings2, routing);
|
|
7456
|
+
layers.push(settings2);
|
|
7457
|
+
}
|
|
7458
|
+
if (cwd !== home && Object.keys(layers.at(-1) ?? {}).length)
|
|
7459
|
+
throw new Error("Antigravity project settings are not a supported native routing or permission source.");
|
|
7460
|
+
return { home, settings: Object.assign({}, ...layers) };
|
|
7461
|
+
}
|
|
7462
|
+
async function prepareAntigravity(input) {
|
|
7463
|
+
const original = await validateAntigravityConfiguration(input.cwd);
|
|
7464
|
+
const home = join7(input.stateDir, "antigravity-home"), gemini = join7(home, ".gemini"), dir = join7(gemini, "antigravity-cli"), shared = join7(gemini, "config");
|
|
7465
|
+
for (const path2 of [home, gemini, dir, shared])
|
|
7466
|
+
await privateDirectory(path2);
|
|
7467
|
+
const durable = join7(input.sessionDir ?? join7(input.stateDir, "sessions"), "antigravity");
|
|
7468
|
+
await privateDirectory(durable);
|
|
7469
|
+
for (const name of ["conversations", "brain", "annotations", "knowledge", "cache"])
|
|
7470
|
+
await durableNativeDirectory(dir, durable, name);
|
|
7471
|
+
await durableNativeDirectory(shared, join7(durable, "shared"), "projects");
|
|
7472
|
+
const settings2 = { ...original.settings, modelProvider: "gemini", customModelsConfig: { customModels: { switcher: { modelName: input.model } } } };
|
|
7473
|
+
const path = await writeNativeSettings(join7(dir, "settings.json"), settings2);
|
|
7474
|
+
const context = join7(original.home, ".gemini", "GEMINI.md");
|
|
7475
|
+
try {
|
|
7476
|
+
const file = await lstat4(context);
|
|
7477
|
+
if (!file.isFile() || file.size > 1024 * 1024)
|
|
7478
|
+
throw new Error("Antigravity global instructions must be a bounded regular file.");
|
|
7479
|
+
await writeFile5(join7(gemini, "GEMINI.md"), await readFile3(context), { mode: 384, flag: "wx" });
|
|
7480
|
+
} catch (error) {
|
|
7481
|
+
if (error.code !== "ENOENT")
|
|
7482
|
+
throw error;
|
|
7483
|
+
}
|
|
7484
|
+
return { executable: input.executable ?? "agy", args: ["--add-dir", input.cwd, "--model", "switcher", ...input.args ?? []], env: { HOME: home, GEMINI_API_KEY: input.credential, GOOGLE_GEMINI_BASE_URL: input.baseUrl.replace(/\/v1beta\/?$/i, "") }, configPaths: [path], warnings: [
|
|
7485
|
+
"Antigravity 1.2.5 uses an isolated native home, preserved permission settings and durable profile conversations. Native project instructions and permissions remain active.",
|
|
7486
|
+
"The native Flash Lite helper is routed to the policy fast model (main by default). Other models remain subject to the launch policy. Global plugins, authentication and shared app state are not imported; ~ in native tools resolves to the private home."
|
|
7487
|
+
] };
|
|
7488
|
+
}
|
|
7489
|
+
|
|
7490
|
+
// src/junie-config.ts
|
|
7491
|
+
import { writeFile as writeFile6 } from "fs/promises";
|
|
7492
|
+
import { join as join8, isAbsolute as isAbsolute7 } from "path";
|
|
7493
|
+
var routing2 = new Set(["model", "provider", "llmprovider", "byok", "apikey", "auth", "baseurl", "litellmurl", "configlocation", "configdefaultlocations", "modellocation", "modeldefaultlocations", "cachedir", "juniehome", "primarymodel", "fastermodel", "flags"]);
|
|
7494
|
+
async function validateJunieConfiguration(cwd, env = process.env) {
|
|
7495
|
+
const home = env.JUNIE_HOME ?? join8(nativeHome(env), ".junie");
|
|
7496
|
+
if (!isAbsolute7(home))
|
|
7497
|
+
throw new Error("Junie requires an absolute native home.");
|
|
7498
|
+
const configs = [], settings2 = [];
|
|
7499
|
+
for (const root of [...new Set([home, join8(cwd, ".junie")])]) {
|
|
7500
|
+
const config = await readNativeSettings(join8(root, "config.json")), setting = await readNativeSettings(join8(root, "settings.json"));
|
|
7501
|
+
rejectNativeRouting(config, routing2);
|
|
7502
|
+
rejectNativeRouting(setting, routing2);
|
|
7503
|
+
configs.push(config);
|
|
7504
|
+
settings2.push(setting);
|
|
7505
|
+
}
|
|
7506
|
+
return { configs, settings: settings2, allowlist: await readNativeText(join8(home, "allowlist.json")), globalInstructions: await readNativeText(join8(home, "AGENTS.md")) };
|
|
7507
|
+
}
|
|
7508
|
+
async function prepareJunie(input) {
|
|
7509
|
+
const original = await validateJunieConfiguration(input.cwd);
|
|
7510
|
+
const home = join8(input.stateDir, "junie-home"), models = join8(home, "models"), cache = join8(input.sessionDir ?? join8(input.stateDir, "sessions"), "junie-cache");
|
|
7511
|
+
for (const path of [home, models, cache])
|
|
7512
|
+
await privateDirectory(path);
|
|
7513
|
+
await durableNativeDirectory(home, join8(input.sessionDir ?? join8(input.stateDir, "sessions"), "junie"), "sessions");
|
|
7514
|
+
const preservedPaths = [];
|
|
7515
|
+
for (const [name, content] of [["allowlist.json", original.allowlist], ["AGENTS.md", original.globalInstructions]])
|
|
7516
|
+
if (content !== undefined) {
|
|
7517
|
+
const path = join8(home, name);
|
|
7518
|
+
await writeFile6(path, content, { mode: 384, flag: "wx" });
|
|
7519
|
+
preservedPaths.push(path);
|
|
7520
|
+
}
|
|
7521
|
+
const apiType = input.protocol === "openai-chat" ? "OpenAICompletion" : input.protocol === "openai-responses" ? "OpenAIResponses" : "Anthropic";
|
|
7522
|
+
const suffix = input.protocol === "openai-chat" ? "/chat/completions" : input.protocol === "openai-responses" ? "/responses" : "/messages";
|
|
7523
|
+
const model = (id2) => ({ id: id2, displayName: id2, providerName: "Switcher", baseUrl: input.baseUrl + suffix, apiType, apiKey: "${SWITCHER_HARNESS_API_KEY}", maxContextLength: input.models.find((m) => m.id === id2)?.contextWindow ?? 128000 });
|
|
7524
|
+
const profile = await writeNativeSettings(join8(models, "switcher.json"), { ...model(input.model), fasterModel: model(input.compiledPolicy.roles.fast) });
|
|
7525
|
+
const config = await writeNativeSettings(join8(home, "config.json"), Object.assign({}, ...original.configs, { "auto-update": false }));
|
|
7526
|
+
const settings2 = await writeNativeSettings(join8(home, "settings.json"), Object.assign({}, ...original.settings));
|
|
7527
|
+
return { executable: input.executable ?? "junie", args: ["--skip-update-check", "--config-default-locations", "false", "--config-location", config, "--model-default-locations", "false", "--model-location", models, "--model", "custom:switcher", "--cache-dir", cache, ...input.args ?? []], env: { JUNIE_HOME: home, SWITCHER_HARNESS_API_KEY: input.credential }, configPaths: [profile, config, settings2, ...preservedPaths], warnings: [
|
|
7528
|
+
"Junie build 3196.5 uses an isolated custom model profile and durable profile cache and sessions. The primary and faster models use the managed gateway; inherited routing configuration fails preflight.",
|
|
7529
|
+
"Native permissions, project guidelines and native noninteractive trust behavior remain active. User and project settings, ordered global permission rules and global AGENTS.md are snapshotted; global authentication is not imported."
|
|
7530
|
+
] };
|
|
7531
|
+
}
|
|
7532
|
+
|
|
7292
7533
|
// src/gemini-bridge.ts
|
|
7293
7534
|
import { createHash as createHash5, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
7294
7535
|
function geminiBridge(input, timing = {}) {
|
|
@@ -7407,6 +7648,12 @@ function compileNativeModelPolicy(input) {
|
|
|
7407
7648
|
const config = {};
|
|
7408
7649
|
let unsupportedRoles = [];
|
|
7409
7650
|
switch (input.harness) {
|
|
7651
|
+
case "antigravity":
|
|
7652
|
+
case "junie":
|
|
7653
|
+
config.model = models.main;
|
|
7654
|
+
config.fast = models.fast;
|
|
7655
|
+
unsupportedRoles = nativeRoles.filter((role) => role !== "main" && role !== "fast");
|
|
7656
|
+
break;
|
|
7410
7657
|
case "claude":
|
|
7411
7658
|
if (!versionAtLeast(input.version, [2, 1, 257]))
|
|
7412
7659
|
throw new Error("Claude model policy enforcement requires Claude Code >=2.1.257.");
|
|
@@ -7997,7 +8244,7 @@ function createInferenceGateway(input, timing = {}) {
|
|
|
7997
8244
|
const digest = (value) => createHash6("sha256").update(value).digest();
|
|
7998
8245
|
const expected = digest(token), policy = input.compiledPolicy;
|
|
7999
8246
|
const known = new Set(input.models.map((m) => m.id));
|
|
8000
|
-
const safeModel = (value) => typeof value === "string" && value !== input.credential && (known.has(value) || Object.hasOwn(policy.aliases, value)) ? value : "<unrecognized>";
|
|
8247
|
+
const safeModel = (value) => typeof value === "string" && value !== input.credential && (known.has(value) || Object.hasOwn(policy.aliases, value) || input.harness === "antigravity" && value === antigravityHelperModel) ? value : "<unrecognized>";
|
|
8001
8248
|
const fail = (status, code, message) => Response.json({ error: { type: "switcher_model_policy", code, message: message ?? (code === "model_not_allowed" ? "This model is outside the launch policy. Select it with switcher launch --model or explicitly assign an allowed role model." : `Switcher inference gateway: ${code}.`) } }, { status });
|
|
8002
8249
|
let closing = false, stopped;
|
|
8003
8250
|
const active = new Set;
|
|
@@ -8048,7 +8295,10 @@ function createInferenceGateway(input, timing = {}) {
|
|
|
8048
8295
|
throw new Fault(403, "routing_override", "Unmanaged model routing is disabled.");
|
|
8049
8296
|
if (typeof requested !== "string")
|
|
8050
8297
|
throw new Fault(400, "model_required", "A model is required.");
|
|
8051
|
-
|
|
8298
|
+
const nativeHelper = input.harness === "antigravity" && requested === antigravityHelperModel;
|
|
8299
|
+
resolved = resolvePolicyModel(policy, nativeHelper ? policy.roles.fast : requested);
|
|
8300
|
+
if (nativeHelper)
|
|
8301
|
+
event.reason = "antigravity_helper_model";
|
|
8052
8302
|
if (input.models.some((model) => model.id === resolved && modelExpired(model)))
|
|
8053
8303
|
throw new Fault(422, "model_expired", "Selected model has expired.");
|
|
8054
8304
|
if (gemini) {
|
|
@@ -8235,8 +8485,8 @@ function createInferenceGateway(input, timing = {}) {
|
|
|
8235
8485
|
}
|
|
8236
8486
|
|
|
8237
8487
|
// src/codex-model-policy.ts
|
|
8238
|
-
import { mkdir as mkdir5, readFile as
|
|
8239
|
-
import { dirname as dirname4, isAbsolute as
|
|
8488
|
+
import { mkdir as mkdir5, readFile as readFile4, realpath as realpath3, stat as stat4, writeFile as writeFile7 } from "fs/promises";
|
|
8489
|
+
import { dirname as dirname4, isAbsolute as isAbsolute8, join as join9, resolve as resolve5 } from "path";
|
|
8240
8490
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
8241
8491
|
import { createHash as createHash7 } from "crypto";
|
|
8242
8492
|
var dict = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
@@ -8256,7 +8506,7 @@ function codexAgentsFromEffectiveConfig(config, trustedProject = true, baseDir)
|
|
|
8256
8506
|
const rawConfigFile = value.config_file;
|
|
8257
8507
|
if (rawConfigFile !== undefined && typeof rawConfigFile !== "string")
|
|
8258
8508
|
throw new Error(`Codex agents.${name}.config_file must be a string.`);
|
|
8259
|
-
const configFile = rawConfigFile === undefined ? undefined :
|
|
8509
|
+
const configFile = rawConfigFile === undefined ? undefined : isAbsolute8(rawConfigFile) ? rawConfigFile : baseDir ? resolve5(baseDir, rawConfigFile) : undefined;
|
|
8260
8510
|
if (rawConfigFile !== undefined && !configFile)
|
|
8261
8511
|
throw new Error(`Codex agents.${name}.config_file must be absolute after precedence resolution.`);
|
|
8262
8512
|
const definition = { trusted: trustedProject, config_file: configFile };
|
|
@@ -8385,16 +8635,16 @@ async function writeCodexAgentOverrides(result, stateDir) {
|
|
|
8385
8635
|
const paths = {};
|
|
8386
8636
|
for (const agent of result.agents) {
|
|
8387
8637
|
const digest = createHash7("sha256").update(agent.name).digest("hex").slice(0, 16);
|
|
8388
|
-
const path =
|
|
8389
|
-
await
|
|
8638
|
+
const path = join9(root, `agent-${digest}.toml`);
|
|
8639
|
+
await writeFile7(path, renderCodexAgentToml(agent.config), { encoding: "utf8", mode: 384, flag: "wx" });
|
|
8390
8640
|
paths[agent.name] = path;
|
|
8391
8641
|
}
|
|
8392
8642
|
return paths;
|
|
8393
8643
|
}
|
|
8394
8644
|
async function prepareCodexModelPolicy(input) {
|
|
8395
|
-
const home = resolve5(input.home ?? process.env.CODEX_HOME ??
|
|
8645
|
+
const home = resolve5(input.home ?? process.env.CODEX_HOME ?? join9(process.env.HOME ?? "/", ".codex"));
|
|
8396
8646
|
const cwd = resolve5(input.cwd);
|
|
8397
|
-
const globalPath =
|
|
8647
|
+
const globalPath = join9(home, "config.toml");
|
|
8398
8648
|
const readConfig = async (path) => {
|
|
8399
8649
|
let info;
|
|
8400
8650
|
try {
|
|
@@ -8406,7 +8656,7 @@ async function prepareCodexModelPolicy(input) {
|
|
|
8406
8656
|
}
|
|
8407
8657
|
if (!info.isFile() || info.size > 1024 * 1024)
|
|
8408
8658
|
throw new Error(`Codex config must be a regular file no larger than 1 MiB: ${path}`);
|
|
8409
|
-
const text = await
|
|
8659
|
+
const text = await readFile4(path, "utf8");
|
|
8410
8660
|
if (Buffer.byteLength(text) > 1024 * 1024)
|
|
8411
8661
|
throw new Error(`Codex config exceeds 1 MiB: ${path}`);
|
|
8412
8662
|
try {
|
|
@@ -8418,7 +8668,7 @@ async function prepareCodexModelPolicy(input) {
|
|
|
8418
8668
|
const global = await readConfig(globalPath) ?? {};
|
|
8419
8669
|
const projects = dict(global.projects) ? global.projects : {};
|
|
8420
8670
|
const markers = global.project_root_markers ?? [".git"];
|
|
8421
|
-
if (!Array.isArray(markers) || markers.some((m) => typeof m !== "string" ||
|
|
8671
|
+
if (!Array.isArray(markers) || markers.some((m) => typeof m !== "string" || isAbsolute8(m) || m.includes("..")))
|
|
8422
8672
|
throw new Error("Unsupported Codex project root markers.");
|
|
8423
8673
|
const ancestorDirs = [];
|
|
8424
8674
|
for (let dir = cwd;; dir = dirname4(dir)) {
|
|
@@ -8431,9 +8681,9 @@ async function prepareCodexModelPolicy(input) {
|
|
|
8431
8681
|
for (const dir of ancestorDirs)
|
|
8432
8682
|
for (const marker of markers) {
|
|
8433
8683
|
try {
|
|
8434
|
-
const info = await stat4(
|
|
8684
|
+
const info = await stat4(join9(dir, marker));
|
|
8435
8685
|
if (marker === ".git" && info.isDirectory())
|
|
8436
|
-
await stat4(
|
|
8686
|
+
await stat4(join9(dir, marker, "HEAD"));
|
|
8437
8687
|
projectRoot = dir;
|
|
8438
8688
|
break findRoot;
|
|
8439
8689
|
} catch {}
|
|
@@ -8458,7 +8708,7 @@ async function prepareCodexModelPolicy(input) {
|
|
|
8458
8708
|
const layers = [{ path: globalPath, config: global }];
|
|
8459
8709
|
const projectDirs = ancestorDirs.slice(0, ancestorDirs.indexOf(projectRoot) + 1).reverse();
|
|
8460
8710
|
for (const dir of projectDirs) {
|
|
8461
|
-
const path =
|
|
8711
|
+
const path = join9(dir, ".codex", "config.toml");
|
|
8462
8712
|
if (path === globalPath)
|
|
8463
8713
|
continue;
|
|
8464
8714
|
const decision = await trust(dir) ?? projectTrust ?? repoTrust;
|
|
@@ -8487,13 +8737,13 @@ async function prepareCodexModelPolicy(input) {
|
|
|
8487
8737
|
return { ...result, agentConfigPaths: await writeCodexAgentOverrides(result, input.stateDir), configPaths: loaded };
|
|
8488
8738
|
}
|
|
8489
8739
|
async function readCodexAgentConfig(path) {
|
|
8490
|
-
if (!
|
|
8740
|
+
if (!isAbsolute8(path))
|
|
8491
8741
|
throw new Error("Codex agent config_file must be absolute before launch.");
|
|
8492
8742
|
const canonical = await realpath3(path);
|
|
8493
8743
|
const info = await stat4(canonical);
|
|
8494
8744
|
if (!info.isFile() || info.size > 1024 * 1024)
|
|
8495
8745
|
throw new Error(`Codex agent config must be a regular file no larger than 1 MiB: ${path}`);
|
|
8496
|
-
const text = await
|
|
8746
|
+
const text = await readFile4(canonical, "utf8");
|
|
8497
8747
|
try {
|
|
8498
8748
|
return Bun.TOML.parse(text);
|
|
8499
8749
|
} catch {
|
|
@@ -8502,29 +8752,29 @@ async function readCodexAgentConfig(path) {
|
|
|
8502
8752
|
}
|
|
8503
8753
|
|
|
8504
8754
|
// src/harnesses.ts
|
|
8505
|
-
import { access as access3, mkdir as mkdir10, readFile as
|
|
8506
|
-
import { basename as basename2, dirname as dirname7, join as
|
|
8507
|
-
import { homedir as
|
|
8755
|
+
import { access as access3, mkdir as mkdir10, readFile as readFile6, readdir as readdir4, writeFile as writeFile13, rm as rm2 } from "fs/promises";
|
|
8756
|
+
import { basename as basename2, dirname as dirname7, join as join15, isAbsolute as isAbsolute13, resolve as resolve8 } from "path";
|
|
8757
|
+
import { homedir as homedir8, tmpdir } from "os";
|
|
8508
8758
|
import { createHash as createHash9, randomUUID as randomUUID4, timingSafeEqual as timingSafeEqual5 } from "crypto";
|
|
8509
8759
|
import { execFile as execFile2 } from "child_process";
|
|
8510
8760
|
import { promisify as promisify2 } from "util";
|
|
8511
8761
|
import { createConnection } from "net";
|
|
8512
8762
|
|
|
8513
8763
|
// src/aider-config.ts
|
|
8514
|
-
import { readFile as
|
|
8764
|
+
import { readFile as readFile5, writeFile as writeFile8, lstat as lstat5, copyFile, rename, realpath as realpath4, access as access2 } from "fs/promises";
|
|
8515
8765
|
import { constants as constants3 } from "fs";
|
|
8516
|
-
import { dirname as dirname5, basename, join as
|
|
8517
|
-
import { homedir as
|
|
8766
|
+
import { dirname as dirname5, basename, join as join10, resolve as resolve6, isAbsolute as isAbsolute9 } from "path";
|
|
8767
|
+
import { homedir as homedir6 } from "os";
|
|
8518
8768
|
import { parseDocument as parseDocument2 } from "yaml";
|
|
8519
8769
|
var KEY2 = "SWITCHER_HARNESS_API_KEY";
|
|
8520
8770
|
var object3 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
8521
8771
|
async function data(path) {
|
|
8522
8772
|
let text;
|
|
8523
8773
|
try {
|
|
8524
|
-
const stat5 = await
|
|
8774
|
+
const stat5 = await lstat5(path);
|
|
8525
8775
|
if (!stat5.isFile() || stat5.size > 1024 * 1024)
|
|
8526
8776
|
throw new Error("unsupported");
|
|
8527
|
-
text = await
|
|
8777
|
+
text = await readFile5(path, "utf8");
|
|
8528
8778
|
} catch (error) {
|
|
8529
8779
|
if (error.code === "ENOENT")
|
|
8530
8780
|
return;
|
|
@@ -8555,9 +8805,9 @@ async function gitRoot(path) {
|
|
|
8555
8805
|
parent = dirname5(parent);
|
|
8556
8806
|
}
|
|
8557
8807
|
}
|
|
8558
|
-
for (let dir =
|
|
8808
|
+
for (let dir = join10(parent, ...missing);; dir = dirname5(dir)) {
|
|
8559
8809
|
try {
|
|
8560
|
-
await
|
|
8810
|
+
await lstat5(join10(dir, ".git"));
|
|
8561
8811
|
return dir;
|
|
8562
8812
|
} catch (error) {
|
|
8563
8813
|
if (!["ENOENT", "ENOTDIR"].includes(error.code ?? ""))
|
|
@@ -8570,9 +8820,9 @@ async function gitRoot(path) {
|
|
|
8570
8820
|
var falseValue = (v) => v === undefined || v === null || v === false || v === 0 || typeof v === "string" && ["", "false", "no", "off", "0"].includes(v.toLowerCase());
|
|
8571
8821
|
var startup = `yes-always gui browser upgrade install-main-branch just-check-update apply-clipboard-edits test lint commit`.split(" ");
|
|
8572
8822
|
var safeParameters = new Set(`max_tokens temperature top_p top_k min_p stop seed reasoning_effort thinking`.split(" "));
|
|
8573
|
-
var expandHome = (path, home) => path === "~" ? home : path.startsWith("~/") ?
|
|
8574
|
-
async function validateAiderConfiguration(cwd, args = [], home = process.env.HOME ??
|
|
8575
|
-
if (!
|
|
8823
|
+
var expandHome = (path, home) => path === "~" ? home : path.startsWith("~/") ? join10(home, path.slice(2)) : path;
|
|
8824
|
+
async function validateAiderConfiguration(cwd, args = [], home = process.env.HOME ?? homedir6()) {
|
|
8825
|
+
if (!isAbsolute9(home))
|
|
8576
8826
|
throw new Error("Aider requires an absolute HOME to preserve native instruction paths.");
|
|
8577
8827
|
const parsed = aiderArguments(args), cwdRoot = await gitRoot(cwd);
|
|
8578
8828
|
const roots = new Set([resolve6(home), ...cwdRoot ? [cwdRoot] : [], resolve6(cwd)]);
|
|
@@ -8583,7 +8833,7 @@ async function validateAiderConfiguration(cwd, args = [], home = process.env.HOM
|
|
|
8583
8833
|
}
|
|
8584
8834
|
let effective = {};
|
|
8585
8835
|
for (const root of roots) {
|
|
8586
|
-
const path =
|
|
8836
|
+
const path = join10(root, ".aider.conf.yml"), value = await data(path);
|
|
8587
8837
|
if (value !== undefined) {
|
|
8588
8838
|
if (!object3(value))
|
|
8589
8839
|
throw new Error(`Aider configuration must be a mapping: ${path}`);
|
|
@@ -8608,13 +8858,13 @@ async function validateAiderConfiguration(cwd, args = [], home = process.env.HOM
|
|
|
8608
8858
|
}
|
|
8609
8859
|
effective = { ...effective, ...normalized };
|
|
8610
8860
|
}
|
|
8611
|
-
const settings2 = await data(
|
|
8861
|
+
const settings2 = await data(join10(root, ".aider.model.settings.yml"));
|
|
8612
8862
|
if (settings2 !== undefined) {
|
|
8613
8863
|
if (!Array.isArray(settings2))
|
|
8614
8864
|
throw new Error("Aider model settings must be a list.");
|
|
8615
8865
|
for (const entry of settings2)
|
|
8616
8866
|
if (!object3(entry) || entry.extra_params !== undefined && (!object3(entry.extra_params) || Object.keys(entry.extra_params).some((key) => !safeParameters.has(key))))
|
|
8617
|
-
throw new Error(`Aider custom transport or callback model settings cannot be preserved safely: ${
|
|
8867
|
+
throw new Error(`Aider custom transport or callback model settings cannot be preserved safely: ${join10(root, ".aider.model.settings.yml")}`);
|
|
8618
8868
|
}
|
|
8619
8869
|
}
|
|
8620
8870
|
if (effective.read !== undefined && !(typeof effective.read === "string" || Array.isArray(effective.read) && effective.read.every((v) => typeof v === "string")))
|
|
@@ -8635,7 +8885,7 @@ function aiderModelName(protocol, id2) {
|
|
|
8635
8885
|
return `${protocol === "anthropic-messages" ? "anthropic" : protocol === "openai-responses" ? "openai/responses" : "openai"}/${id2}`;
|
|
8636
8886
|
}
|
|
8637
8887
|
async function historyFile(path) {
|
|
8638
|
-
const stat5 = await
|
|
8888
|
+
const stat5 = await lstat5(path);
|
|
8639
8889
|
if (!stat5.isFile() || stat5.isSymbolicLink() || stat5.size > 64 * 1024 * 1024 || process.platform !== "win32" && ((stat5.mode & 63) !== 0 || stat5.uid !== process.getuid?.()))
|
|
8640
8890
|
throw new Error("Aider history must be an owner-only regular file smaller than 64 MiB.");
|
|
8641
8891
|
}
|
|
@@ -8650,7 +8900,7 @@ async function prepareAider(input) {
|
|
|
8650
8900
|
const files = parsed.args.splice(literal2).slice(1);
|
|
8651
8901
|
parsed.args.push(...files.map((path) => resolve6(input.cwd, path)));
|
|
8652
8902
|
}
|
|
8653
|
-
const sourceHome = process.env.HOME ??
|
|
8903
|
+
const sourceHome = process.env.HOME ?? homedir6();
|
|
8654
8904
|
for (let i = 0;i < parsed.args.length; i++) {
|
|
8655
8905
|
if (parsed.args[i] === "--read") {
|
|
8656
8906
|
i++;
|
|
@@ -8658,39 +8908,39 @@ async function prepareAider(input) {
|
|
|
8658
8908
|
} else if (parsed.args[i].startsWith("--read="))
|
|
8659
8909
|
parsed.args[i] = "--read=" + expandHome(parsed.args[i].slice(7), sourceHome);
|
|
8660
8910
|
}
|
|
8661
|
-
const home =
|
|
8911
|
+
const home = join10(input.stateDir, "aider-home");
|
|
8662
8912
|
await privateDirectory(home);
|
|
8663
|
-
const originalHome = process.env.HOME ??
|
|
8664
|
-
const gitSources = process.env.GIT_CONFIG_GLOBAL ? [resolve6(process.env.GIT_CONFIG_GLOBAL)] : [
|
|
8665
|
-
const gitConfig =
|
|
8666
|
-
await
|
|
8913
|
+
const originalHome = process.env.HOME ?? homedir6();
|
|
8914
|
+
const gitSources = process.env.GIT_CONFIG_GLOBAL ? [resolve6(process.env.GIT_CONFIG_GLOBAL)] : [join10(process.env.XDG_CONFIG_HOME ?? join10(originalHome, ".config"), "git", "config"), join10(originalHome, ".gitconfig")];
|
|
8915
|
+
const gitConfig = join10(home, ".gitconfig");
|
|
8916
|
+
await writeFile8(gitConfig, gitSources.map((path) => `[include]
|
|
8667
8917
|
path = ${JSON.stringify(path)}
|
|
8668
8918
|
`).join(""), { mode: 384, flag: "wx" });
|
|
8669
|
-
const sessions = input.sessionDir ??
|
|
8919
|
+
const sessions = input.sessionDir ?? join10(input.stateDir, "sessions");
|
|
8670
8920
|
await privateDirectory(sessions);
|
|
8671
|
-
const id2 = crypto.randomUUID(), history =
|
|
8921
|
+
const id2 = crypto.randomUUID(), history = join10(sessions, `${id2}.chat.md`), inputHistory = join10(sessions, `${id2}.input`);
|
|
8672
8922
|
if (parsed.restore) {
|
|
8673
|
-
const latest =
|
|
8923
|
+
const latest = join10(sessions, "latest.json");
|
|
8674
8924
|
await historyFile(latest).catch(() => {
|
|
8675
8925
|
throw new Error("No valid completed Aider history is available for this profile.");
|
|
8676
8926
|
});
|
|
8677
|
-
const previous = JSON.parse(await
|
|
8927
|
+
const previous = JSON.parse(await readFile5(latest, "utf8"));
|
|
8678
8928
|
if (!object3(previous) || typeof previous.id !== "string" || !/^[-a-f0-9]{36}$/.test(previous.id))
|
|
8679
8929
|
throw new Error("Invalid Aider history reference.");
|
|
8680
|
-
const source =
|
|
8930
|
+
const source = join10(sessions, `${previous.id}.chat.md`);
|
|
8681
8931
|
await historyFile(source);
|
|
8682
8932
|
await copyFile(source, history, 1);
|
|
8683
8933
|
} else
|
|
8684
|
-
await
|
|
8685
|
-
const originalHistoryLength = (await
|
|
8686
|
-
await
|
|
8934
|
+
await writeFile8(history, "", { mode: 384, flag: "wx" });
|
|
8935
|
+
const originalHistoryLength = (await readFile5(history, "utf8")).length;
|
|
8936
|
+
await writeFile8(inputHistory, "", { mode: 384, flag: "wx" });
|
|
8687
8937
|
const model2 = aiderModelName(input.protocol, input.model);
|
|
8688
8938
|
const weakModel = aiderModelName(input.protocol, input.compiledPolicy?.roles.weak ?? input.model), editorModel = aiderModelName(input.protocol, input.compiledPolicy?.roles.editor ?? input.model);
|
|
8689
8939
|
const extra = { api_base: input.protocol === "anthropic-messages" ? input.baseUrl.replace(/\/v1$/i, "") : input.baseUrl, api_key: `os.environ/${KEY2}` };
|
|
8690
|
-
const settings2 =
|
|
8940
|
+
const settings2 = join10(input.stateDir, "aider-model-settings.json"), metadata = join10(input.stateDir, "aider-model-metadata.json"), config = join10(input.stateDir, "aider-config.json"), empty = join10(input.stateDir, "aider-empty.env");
|
|
8691
8941
|
const definitions = input.models.map((m) => ({ name: aiderModelName(input.protocol, m.id), edit_format: "whole", use_repo_map: true, weak_model_name: weakModel, editor_model_name: editorModel, extra_params: extra }));
|
|
8692
|
-
await
|
|
8693
|
-
await
|
|
8942
|
+
await writeFile8(settings2, JSON.stringify([...definitions, { name: "aider/extra_params", extra_params: extra }]), { mode: 384, flag: "wx" });
|
|
8943
|
+
await writeFile8(metadata, JSON.stringify(Object.fromEntries(input.models.map((m) => [aiderModelName(input.protocol, m.id), {
|
|
8694
8944
|
...m.contextWindow ? { max_input_tokens: m.contextWindow } : {},
|
|
8695
8945
|
...m.maxOutputTokens ? { max_output_tokens: m.maxOutputTokens, max_tokens: m.maxOutputTokens } : {},
|
|
8696
8946
|
litellm_provider: input.protocol === "anthropic-messages" ? "anthropic" : "openai",
|
|
@@ -8699,14 +8949,14 @@ async function prepareAider(input) {
|
|
|
8699
8949
|
}]))), { mode: 384, flag: "wx" });
|
|
8700
8950
|
const ignored = new Set(`model weak-model editor-model openai-api-key anthropic-api-key openai-api-base openai-api-type openai-api-version openai-api-deployment-id openai-organization-id set-env api-key alias config env-file model-settings-file model-metadata-file input-history-file chat-history-file llm-history-file restore-chat-history load analytics analytics-log analytics-posthog-host analytics-posthog-project-api-key analytics-disable check-update show-release-notes`.split(" "));
|
|
8701
8951
|
const preserved = Object.fromEntries(Object.entries(global).filter(([key]) => !ignored.has(key) && !startup.includes(key)));
|
|
8702
|
-
await
|
|
8703
|
-
await
|
|
8952
|
+
await writeFile8(config, JSON.stringify({ ...preserved, model: model2, "weak-model": weakModel, "editor-model": editorModel, "model-settings-file": settings2, "model-metadata-file": metadata, "env-file": empty, "input-history-file": inputHistory, "chat-history-file": history, "llm-history-file": "", "restore-chat-history": parsed.restore, load: "", analytics: false, "check-update": false, "show-release-notes": false, "openai-api-key": "", "anthropic-api-key": "", "openai-api-base": input.baseUrl, "openai-api-type": "", "openai-api-version": "", "openai-api-deployment-id": "", "openai-organization-id": "" }), { mode: 384, flag: "wx" });
|
|
8953
|
+
await writeFile8(empty, "", { mode: 384, flag: "wx" });
|
|
8704
8954
|
const aliases = ["--alias", `switcher-${id2}:${model2}`];
|
|
8705
8955
|
let cleaned = false;
|
|
8706
8956
|
return {
|
|
8707
8957
|
executable: input.executable ?? "aider",
|
|
8708
8958
|
args: ["--config", config, "--model", model2, "--weak-model", weakModel, "--editor-model", editorModel, "--set-env", "PYTHON_DOTENV_DISABLED=1", "--api-key", "SWITCHER_UNUSED=unused", ...aliases, ...parsed.args],
|
|
8709
|
-
env: { HOME: home, XDG_CONFIG_HOME:
|
|
8959
|
+
env: { HOME: home, XDG_CONFIG_HOME: join10(home, "config"), XDG_CACHE_HOME: join10(home, "cache"), XDG_DATA_HOME: join10(home, "data"), PYTHON_DOTENV_DISABLED: "1", LITELLM_LOCAL_MODEL_COST_MAP: "True", [KEY2]: input.credential, [input.protocol === "anthropic-messages" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY"]: input.credential },
|
|
8710
8960
|
configPaths: [config, settings2, metadata, empty, gitConfig],
|
|
8711
8961
|
warnings: [
|
|
8712
8962
|
...input.protocol === "openai-responses" ? ["Aider 0.86.2 with LiteLLM 1.81.10 uses buffered Responses requests even when native streaming is requested; incremental upstream Responses output is unavailable through this adapter."] : [],
|
|
@@ -8720,11 +8970,11 @@ async function prepareAider(input) {
|
|
|
8720
8970
|
return;
|
|
8721
8971
|
cleaned = true;
|
|
8722
8972
|
await historyFile(history);
|
|
8723
|
-
if (!/^#### /m.test((await
|
|
8973
|
+
if (!/^#### /m.test((await readFile5(history, "utf8")).slice(originalHistoryLength)))
|
|
8724
8974
|
return;
|
|
8725
|
-
const pending =
|
|
8726
|
-
await
|
|
8727
|
-
await rename(pending,
|
|
8975
|
+
const pending = join10(sessions, `${id2}.latest.json`);
|
|
8976
|
+
await writeFile8(pending, JSON.stringify({ id: id2 }), { mode: 384, flag: "wx" });
|
|
8977
|
+
await rename(pending, join10(sessions, "latest.json"));
|
|
8728
8978
|
}
|
|
8729
8979
|
};
|
|
8730
8980
|
}
|
|
@@ -8806,9 +9056,9 @@ function validateGrokResume(args) {
|
|
|
8806
9056
|
}
|
|
8807
9057
|
|
|
8808
9058
|
// src/cline-backend.ts
|
|
8809
|
-
import { mkdir as mkdir6, writeFile as
|
|
9059
|
+
import { mkdir as mkdir6, writeFile as writeFile9 } from "fs/promises";
|
|
8810
9060
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
8811
|
-
import { isAbsolute as
|
|
9061
|
+
import { isAbsolute as isAbsolute10, join as join11 } from "path";
|
|
8812
9062
|
var ENV_BY_PROTOCOL = {
|
|
8813
9063
|
"anthropic-messages": "ANTHROPIC_API_KEY",
|
|
8814
9064
|
"openai-responses": "OPENAI_API_KEY",
|
|
@@ -8834,7 +9084,7 @@ function modelEntry(model2, protocol) {
|
|
|
8834
9084
|
};
|
|
8835
9085
|
}
|
|
8836
9086
|
async function writeJson(path, value) {
|
|
8837
|
-
await
|
|
9087
|
+
await writeFile9(path, `${JSON.stringify(value, null, 2)}
|
|
8838
9088
|
`, { mode: 384, flag: "wx" });
|
|
8839
9089
|
return path;
|
|
8840
9090
|
}
|
|
@@ -8854,18 +9104,18 @@ async function prepareClineLaunch(input) {
|
|
|
8854
9104
|
throw new Error(`Cline ${input.protocol} uses ${mapping.authStyle} authentication; use a provider with the native Cline auth contract.`);
|
|
8855
9105
|
if (input.credential && /[\r\n]/.test(input.credential))
|
|
8856
9106
|
throw new Error("Provider credential contains invalid header characters.");
|
|
8857
|
-
if (!
|
|
9107
|
+
if (!isAbsolute10(input.stateDir) || !isAbsolute10(input.cwd))
|
|
8858
9108
|
throw new Error("Launch state and working directories must be absolute.");
|
|
8859
|
-
const dataDir =
|
|
8860
|
-
const sessionDir = input.sessionDir ??
|
|
8861
|
-
const launchDir =
|
|
8862
|
-
const settingsDir =
|
|
8863
|
-
const configDir =
|
|
9109
|
+
const dataDir = join11(input.stateDir, "cline-data");
|
|
9110
|
+
const sessionDir = input.sessionDir ?? join11(dataDir, "sessions");
|
|
9111
|
+
const launchDir = join11(input.stateDir, `cline-launch-${randomUUID2()}`);
|
|
9112
|
+
const settingsDir = join11(launchDir, "settings");
|
|
9113
|
+
const configDir = join11(launchDir, "config");
|
|
8864
9114
|
await mkdir6(settingsDir, { recursive: true, mode: 448 });
|
|
8865
9115
|
await mkdir6(configDir, { recursive: true, mode: 448 });
|
|
8866
9116
|
const baseUrl = endpoint(input.baseUrl);
|
|
8867
9117
|
const providerId = mapping.providerId;
|
|
8868
|
-
const providersPath = await writeJson(
|
|
9118
|
+
const providersPath = await writeJson(join11(settingsDir, "providers.json"), {
|
|
8869
9119
|
version: 1,
|
|
8870
9120
|
lastUsedProvider: providerId,
|
|
8871
9121
|
modes: {},
|
|
@@ -8885,7 +9135,7 @@ async function prepareClineLaunch(input) {
|
|
|
8885
9135
|
}
|
|
8886
9136
|
}
|
|
8887
9137
|
});
|
|
8888
|
-
const modelsPath = await writeJson(
|
|
9138
|
+
const modelsPath = await writeJson(join11(settingsDir, "models.json"), {
|
|
8889
9139
|
version: 1,
|
|
8890
9140
|
providers: {
|
|
8891
9141
|
[providerId]: {
|
|
@@ -8934,10 +9184,10 @@ async function prepareClineLaunch(input) {
|
|
|
8934
9184
|
}
|
|
8935
9185
|
|
|
8936
9186
|
// src/opencode2-config.ts
|
|
8937
|
-
import { mkdir as mkdir7, open as open2, realpath as realpath5, readdir as readdir3, stat as stat5, writeFile as
|
|
9187
|
+
import { mkdir as mkdir7, open as open2, realpath as realpath5, readdir as readdir3, stat as stat5, writeFile as writeFile10 } from "fs/promises";
|
|
8938
9188
|
import { constants as constants4 } from "fs";
|
|
8939
|
-
import { dirname as dirname6, isAbsolute as
|
|
8940
|
-
import { homedir as
|
|
9189
|
+
import { dirname as dirname6, isAbsolute as isAbsolute11, join as join12, relative as relative4, resolve as resolve7 } from "path";
|
|
9190
|
+
import { homedir as homedir7 } from "os";
|
|
8941
9191
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
8942
9192
|
import { Database as Database2 } from "bun:sqlite";
|
|
8943
9193
|
import { parse as parse3, parseTree as parseTree3 } from "jsonc-parser";
|
|
@@ -8952,7 +9202,7 @@ var maxTotalBytes2 = 8 * 1024 * 1024;
|
|
|
8952
9202
|
var maxFiles2 = 256;
|
|
8953
9203
|
var inside2 = (root, path) => {
|
|
8954
9204
|
const rel = relative4(root, path);
|
|
8955
|
-
return rel === "" || !
|
|
9205
|
+
return rel === "" || !isAbsolute11(rel) && rel !== ".." && !rel.startsWith("../");
|
|
8956
9206
|
};
|
|
8957
9207
|
var action = (value) => ({ bash: "shell", task: "subagent", write: "edit", patch: "edit" })[value] ?? value;
|
|
8958
9208
|
function invalid2(path, field) {
|
|
@@ -9004,7 +9254,7 @@ function permissions(value, path, home) {
|
|
|
9004
9254
|
literal2(item.resource, path, "permission resource");
|
|
9005
9255
|
if (!["read", "edit", "external_directory"].includes(item.action))
|
|
9006
9256
|
return item;
|
|
9007
|
-
const resource = item.resource === "~" || item.resource === "$HOME" ? home : item.resource.startsWith("~/") ?
|
|
9257
|
+
const resource = item.resource === "~" || item.resource === "$HOME" ? home : item.resource.startsWith("~/") ? join12(home, item.resource.slice(2)) : item.resource.startsWith("$HOME/") || item.resource.startsWith("$HOME\\") ? join12(home, item.resource.slice(6)) : item.resource;
|
|
9008
9258
|
return { ...item, resource };
|
|
9009
9259
|
});
|
|
9010
9260
|
}
|
|
@@ -9032,8 +9282,8 @@ function jsonc2(text, path) {
|
|
|
9032
9282
|
return record2(value, path, "configuration object");
|
|
9033
9283
|
}
|
|
9034
9284
|
async function checkRemoteConfiguration(dataHome) {
|
|
9035
|
-
const path =
|
|
9036
|
-
const legacyAuth = await stat5(
|
|
9285
|
+
const path = join12(dataHome, "opencode", "opencode.db");
|
|
9286
|
+
const legacyAuth = await stat5(join12(dataHome, "opencode", "auth.json")).then(() => true, (error) => {
|
|
9037
9287
|
if (error.code === "ENOENT")
|
|
9038
9288
|
return false;
|
|
9039
9289
|
throw error;
|
|
@@ -9073,16 +9323,16 @@ async function checkRemoteConfiguration(dataHome) {
|
|
|
9073
9323
|
}
|
|
9074
9324
|
async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
9075
9325
|
for (const name of ["HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "OPENCODE_CONFIG_DIR"])
|
|
9076
|
-
if (env[name] && !
|
|
9326
|
+
if (env[name] && !isAbsolute11(env[name]))
|
|
9077
9327
|
throw new Error(`OpenCode 2 requires an absolute ${name} to preserve native configuration authority.`);
|
|
9078
|
-
const home = resolve7(env.HOME ||
|
|
9079
|
-
const configRoot = resolve7(env.OPENCODE_CONFIG_DIR ||
|
|
9328
|
+
const home = resolve7(env.HOME || homedir7());
|
|
9329
|
+
const configRoot = resolve7(env.OPENCODE_CONFIG_DIR || join12(env.XDG_CONFIG_HOME || join12(home, ".config"), "opencode"));
|
|
9080
9330
|
const canonicalConfigRoot = await realpath5(configRoot).catch((error) => {
|
|
9081
9331
|
if (error.code === "ENOENT")
|
|
9082
9332
|
return configRoot;
|
|
9083
9333
|
throw error;
|
|
9084
9334
|
});
|
|
9085
|
-
const dataHome = resolve7(env.XDG_DATA_HOME ||
|
|
9335
|
+
const dataHome = resolve7(env.XDG_DATA_HOME || join12(home, ".local", "share"));
|
|
9086
9336
|
await checkRemoteConfiguration(dataHome);
|
|
9087
9337
|
let files = 0, total = 0;
|
|
9088
9338
|
const paths = [];
|
|
@@ -9122,7 +9372,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
|
9122
9372
|
invalid2(path, "agent prompt environment reference");
|
|
9123
9373
|
let result = "", cursor = 0;
|
|
9124
9374
|
for (const match of text.matchAll(/\{file:([^}]+)\}/g)) {
|
|
9125
|
-
const requested = match[1].startsWith("~/") ?
|
|
9375
|
+
const requested = match[1].startsWith("~/") ? join12(home, match[1].slice(2)) : resolve7(dirname6(path), match[1]);
|
|
9126
9376
|
const content = (await read(requested, false)).trim();
|
|
9127
9377
|
literal2(content, requested, "nested prompt variable reference");
|
|
9128
9378
|
result += text.slice(cursor, match.index) + content;
|
|
@@ -9144,7 +9394,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
|
9144
9394
|
}
|
|
9145
9395
|
async function agentsDirectory(directory2) {
|
|
9146
9396
|
for (const source of ["agent", "agents", "mode", "modes"]) {
|
|
9147
|
-
const base =
|
|
9397
|
+
const base = join12(directory2, source), entries = [];
|
|
9148
9398
|
const visited = new Set;
|
|
9149
9399
|
let examined = 0;
|
|
9150
9400
|
async function walk(dir, depth) {
|
|
@@ -9163,7 +9413,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
|
9163
9413
|
if (depth > 16 || (examined += names.length) > maxFiles2)
|
|
9164
9414
|
throw new Error("OpenCode 2 agent policy exceeds its bounded directory limit.");
|
|
9165
9415
|
for (const name of names) {
|
|
9166
|
-
const path =
|
|
9416
|
+
const path = join12(dir, name);
|
|
9167
9417
|
const info = await stat5(path);
|
|
9168
9418
|
if (info.isDirectory()) {
|
|
9169
9419
|
if (source === "agent" || source === "agents")
|
|
@@ -9197,8 +9447,8 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
|
9197
9447
|
}
|
|
9198
9448
|
}
|
|
9199
9449
|
async function directory(path) {
|
|
9200
|
-
await document(
|
|
9201
|
-
await document(
|
|
9450
|
+
await document(join12(path, "opencode.json"));
|
|
9451
|
+
await document(join12(path, "opencode.jsonc"));
|
|
9202
9452
|
await agentsDirectory(path);
|
|
9203
9453
|
}
|
|
9204
9454
|
await directory(configRoot);
|
|
@@ -9213,11 +9463,11 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
|
9213
9463
|
const projectEnabled = !["1", "true"].includes((env.OPENCODE_CONFIG_PROJECT_DISABLE ?? env.OPENCODE_DISABLE_PROJECT_CONFIG ?? "").toLowerCase());
|
|
9214
9464
|
if (projectEnabled) {
|
|
9215
9465
|
for (const path of [...ancestors].reverse()) {
|
|
9216
|
-
await document(
|
|
9217
|
-
await document(
|
|
9466
|
+
await document(join12(path, "opencode.json"));
|
|
9467
|
+
await document(join12(path, "opencode.jsonc"));
|
|
9218
9468
|
}
|
|
9219
9469
|
for (const path of [...ancestors].reverse()) {
|
|
9220
|
-
const candidate =
|
|
9470
|
+
const candidate = join12(path, ".opencode");
|
|
9221
9471
|
const canonical = await realpath5(candidate).catch((error) => {
|
|
9222
9472
|
if (error.code === "ENOENT")
|
|
9223
9473
|
return candidate;
|
|
@@ -9228,7 +9478,7 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
|
9228
9478
|
}
|
|
9229
9479
|
}
|
|
9230
9480
|
if (env.OPENCODE_CONFIG_CONTENT)
|
|
9231
|
-
documents.push({ path:
|
|
9481
|
+
documents.push({ path: join12(cwd, "OPENCODE_CONFIG_CONTENT"), value: jsonc2(env.OPENCODE_CONFIG_CONTENT, "OPENCODE_CONFIG_CONTENT") });
|
|
9232
9482
|
const policy = [];
|
|
9233
9483
|
const agents = Object.create(null);
|
|
9234
9484
|
let defaultAgent;
|
|
@@ -9321,34 +9571,34 @@ async function isolateOpenCode2(cwd, stateDir, providerID, env = process.env) {
|
|
|
9321
9571
|
instructions.push(`Instructions from: ${path}
|
|
9322
9572
|
${content}`);
|
|
9323
9573
|
}
|
|
9324
|
-
await instruction(
|
|
9574
|
+
await instruction(join12(configRoot, "AGENTS.md"));
|
|
9325
9575
|
if (projectEnabled) {
|
|
9326
9576
|
let stop = resolve7(cwd);
|
|
9327
9577
|
if (inside2(home, resolve7(cwd)))
|
|
9328
9578
|
stop = home;
|
|
9329
9579
|
else
|
|
9330
9580
|
for (const path of ancestors) {
|
|
9331
|
-
if (await stat5(
|
|
9581
|
+
if (await stat5(join12(path, ".git")).then(() => true, () => false)) {
|
|
9332
9582
|
stop = path;
|
|
9333
9583
|
break;
|
|
9334
9584
|
}
|
|
9335
9585
|
}
|
|
9336
9586
|
for (const path of ancestors) {
|
|
9337
|
-
await instruction(
|
|
9587
|
+
await instruction(join12(path, "AGENTS.md"));
|
|
9338
9588
|
if (path === stop)
|
|
9339
9589
|
break;
|
|
9340
9590
|
}
|
|
9341
9591
|
}
|
|
9342
|
-
const privateHome =
|
|
9343
|
-
const instructionFile =
|
|
9592
|
+
const privateHome = join12(stateDir, "opencode-home"), privateConfig = join12(stateDir, "opencode-config");
|
|
9593
|
+
const instructionFile = join12(privateConfig, "opencode", "AGENTS.md");
|
|
9344
9594
|
await mkdir7(dirname6(instructionFile), { recursive: true, mode: 448 });
|
|
9345
9595
|
await mkdir7(privateHome, { recursive: true, mode: 448 });
|
|
9346
|
-
await
|
|
9596
|
+
await writeFile10(instructionFile, instructions.join(`
|
|
9347
9597
|
|
|
9348
9598
|
`), { flag: "wx", mode: 384 });
|
|
9349
9599
|
return {
|
|
9350
9600
|
config: { permissions: policy, agents, ...defaultAgent ? { default_agent: defaultAgent } : {}, experimental: { policies: [{ action: "provider.use", resource: "*", effect: "deny" }, { action: "provider.use", resource: providerID, effect: "allow" }] } },
|
|
9351
|
-
env: { HOME: privateHome, XDG_CONFIG_HOME: privateConfig, OPENCODE_CONFIG_DIR:
|
|
9601
|
+
env: { HOME: privateHome, XDG_CONFIG_HOME: privateConfig, OPENCODE_CONFIG_DIR: join12(privateConfig, "opencode"), XDG_CACHE_HOME: join12(stateDir, "opencode-cache"), XDG_STATE_HOME: join12(stateDir, "opencode-state"), XDG_DATA_HOME: dataHome, OPENCODE_DISABLE_PROJECT_CONFIG: "true", OPENCODE_CONFIG_PROJECT_DISABLE: "true", OPENCODE_DISABLE_MODELS_FETCH: "true" },
|
|
9352
9602
|
instructionFile,
|
|
9353
9603
|
sourcePaths: paths
|
|
9354
9604
|
};
|
|
@@ -9363,8 +9613,8 @@ function openCode2ConfigText(config, providerID, keyEnv) {
|
|
|
9363
9613
|
}
|
|
9364
9614
|
|
|
9365
9615
|
// src/omp-backend.ts
|
|
9366
|
-
import { mkdir as mkdir8, rm, writeFile as
|
|
9367
|
-
import { join as
|
|
9616
|
+
import { mkdir as mkdir8, rm, writeFile as writeFile11 } from "fs/promises";
|
|
9617
|
+
import { join as join13 } from "path";
|
|
9368
9618
|
var KEY3 = "SWITCHER_HARNESS_API_KEY";
|
|
9369
9619
|
var API = {
|
|
9370
9620
|
"anthropic-messages": "anthropic-messages",
|
|
@@ -9389,8 +9639,8 @@ async function prepareOmpLaunch(input) {
|
|
|
9389
9639
|
const baseUrl = endpoint(input.baseUrl);
|
|
9390
9640
|
if (input.credential && /[\r\n]/.test(input.credential))
|
|
9391
9641
|
throw new Error("Provider credential contains invalid header characters.");
|
|
9392
|
-
const agentDir =
|
|
9393
|
-
const sessionDir = input.sessionDir ??
|
|
9642
|
+
const agentDir = join13(input.stateDir, "omp-agent");
|
|
9643
|
+
const sessionDir = input.sessionDir ?? join13(input.stateDir, "sessions");
|
|
9394
9644
|
await mkdir8(agentDir, { recursive: true, mode: 448 });
|
|
9395
9645
|
await mkdir8(sessionDir, { recursive: true, mode: 448 });
|
|
9396
9646
|
const api = API[input.protocol];
|
|
@@ -9416,12 +9666,12 @@ async function prepareOmpLaunch(input) {
|
|
|
9416
9666
|
provider.apiKey = KEY3;
|
|
9417
9667
|
provider.authHeader = true;
|
|
9418
9668
|
}
|
|
9419
|
-
const modelsPath =
|
|
9420
|
-
const configPath =
|
|
9669
|
+
const modelsPath = join13(agentDir, "models.yml");
|
|
9670
|
+
const configPath = join13(agentDir, "config.yml");
|
|
9421
9671
|
const selector = `switcher/${input.model}`;
|
|
9422
|
-
await
|
|
9672
|
+
await writeFile11(modelsPath, JSON.stringify({ providers: { switcher: provider } }, null, 2) + `
|
|
9423
9673
|
`, { mode: 384, flag: "wx" });
|
|
9424
|
-
await
|
|
9674
|
+
await writeFile11(configPath, JSON.stringify({
|
|
9425
9675
|
enabledModels: ["switcher/**"],
|
|
9426
9676
|
modelRoles: { default: selector, smol: `switcher/${input.compiledPolicy?.roles.fast ?? input.model}`, slow: `switcher/${input.compiledPolicy?.roles.planning ?? input.model}`, plan: `switcher/${input.compiledPolicy?.roles.planning ?? input.model}` }
|
|
9427
9677
|
}, null, 2) + `
|
|
@@ -9494,8 +9744,8 @@ function compileHermesModelPolicy(currentModel, roles2, baseUrl, apiMode = "chat
|
|
|
9494
9744
|
|
|
9495
9745
|
// src/hermes-backend.ts
|
|
9496
9746
|
import { createHash as createHash8, timingSafeEqual as timingSafeEqual4 } from "crypto";
|
|
9497
|
-
import { mkdir as mkdir9, symlink as
|
|
9498
|
-
import { isAbsolute as
|
|
9747
|
+
import { mkdir as mkdir9, symlink as symlink3, writeFile as writeFile12 } from "fs/promises";
|
|
9748
|
+
import { isAbsolute as isAbsolute12, join as join14 } from "path";
|
|
9499
9749
|
var hermesApiMode = {
|
|
9500
9750
|
"anthropic-messages": "anthropic_messages",
|
|
9501
9751
|
"openai-responses": "codex_responses",
|
|
@@ -9639,7 +9889,7 @@ function createHermesBridge(input, timing = {}) {
|
|
|
9639
9889
|
};
|
|
9640
9890
|
}
|
|
9641
9891
|
async function prepareHermesLaunch(input) {
|
|
9642
|
-
if (!
|
|
9892
|
+
if (!isAbsolute12(input.stateDir) || !isAbsolute12(input.cwd))
|
|
9643
9893
|
throw new Error("Launch state and working directories must be absolute.");
|
|
9644
9894
|
if (input.protocol !== "anthropic-messages" && input.protocol !== "openai-responses" && input.protocol !== "openai-chat")
|
|
9645
9895
|
throw new Error("Hermes does not support this provider protocol.");
|
|
@@ -9649,12 +9899,12 @@ async function prepareHermesLaunch(input) {
|
|
|
9649
9899
|
throw new Error("Hermes cannot safely select model IDs that differ only by letter case; update the provider catalog.");
|
|
9650
9900
|
if (input.credential && /[\r\n]/.test(input.credential))
|
|
9651
9901
|
throw new Error("Provider credential contains invalid header characters.");
|
|
9652
|
-
const sessionDir = input.sessionDir ??
|
|
9653
|
-
const sessionsDir =
|
|
9902
|
+
const sessionDir = input.sessionDir ?? join14(input.stateDir, "hermes-session");
|
|
9903
|
+
const sessionsDir = join14(sessionDir, "sessions");
|
|
9654
9904
|
await mkdir9(input.stateDir, { recursive: true, mode: 448 });
|
|
9655
9905
|
await mkdir9(sessionsDir, { recursive: true, mode: 448 });
|
|
9656
|
-
await
|
|
9657
|
-
await
|
|
9906
|
+
await symlink3(join14(sessionDir, "state.db"), join14(input.stateDir, "state.db"));
|
|
9907
|
+
await symlink3(sessionsDir, join14(input.stateDir, "sessions"));
|
|
9658
9908
|
const bridge = createHermesBridge(input);
|
|
9659
9909
|
let policy;
|
|
9660
9910
|
try {
|
|
@@ -9682,9 +9932,9 @@ async function prepareHermesLaunch(input) {
|
|
|
9682
9932
|
}
|
|
9683
9933
|
}
|
|
9684
9934
|
};
|
|
9685
|
-
const configPath =
|
|
9935
|
+
const configPath = join14(input.stateDir, "config.yaml");
|
|
9686
9936
|
try {
|
|
9687
|
-
await
|
|
9937
|
+
await writeFile12(configPath, JSON.stringify(config, null, 2) + `
|
|
9688
9938
|
`, { mode: 384, flag: "wx" });
|
|
9689
9939
|
} catch (error) {
|
|
9690
9940
|
await bridge.cleanup();
|
|
@@ -9699,7 +9949,7 @@ async function prepareHermesLaunch(input) {
|
|
|
9699
9949
|
SWITCHER_HERMES_AUX_API_KEY: bridge.token,
|
|
9700
9950
|
OPENAI_API_KEY: bridge.token,
|
|
9701
9951
|
OPENAI_BASE_URL: bridge.baseUrl,
|
|
9702
|
-
CODEX_HOME:
|
|
9952
|
+
CODEX_HOME: join14(input.stateDir, "codex-home")
|
|
9703
9953
|
},
|
|
9704
9954
|
configPaths: [configPath],
|
|
9705
9955
|
warnings: [
|
|
@@ -9713,6 +9963,8 @@ async function prepareHermesLaunch(input) {
|
|
|
9713
9963
|
|
|
9714
9964
|
// src/harness-installation.ts
|
|
9715
9965
|
var records = {
|
|
9966
|
+
antigravity: { displayName: "Antigravity CLI", executable: "agy", versionRequirement: "1.2.5", packageOrProject: "Google Antigravity official distribution", documentationUrl: "https://antigravity.google/docs/cli/install", installationGuidance: "install the official Antigravity CLI 1.2.5 and ensure agy is on PATH, or pass the absolute binary path with --executable" },
|
|
9967
|
+
junie: { displayName: "Junie CLI", executable: "junie", versionRequirement: "build 3196.5", packageOrProject: "JetBrains Junie official distribution", documentationUrl: "https://junie.jetbrains.com/docs/quickstart.html", installationGuidance: "install official Junie build 3196.5 and ensure junie is on PATH, or pass its absolute path with --executable" },
|
|
9716
9968
|
claude: {
|
|
9717
9969
|
displayName: "Claude Code",
|
|
9718
9970
|
executable: "claude",
|
|
@@ -9841,8 +10093,8 @@ var execute2 = promisify2(execFile2);
|
|
|
9841
10093
|
var KEY4 = "SWITCHER_HARNESS_API_KEY";
|
|
9842
10094
|
var quote = (value) => JSON.stringify(value);
|
|
9843
10095
|
async function detectHarness(harness, override) {
|
|
9844
|
-
const executable = override ?? Bun.which(harness) ?? harness;
|
|
9845
10096
|
const installation = harnessInstallation(harness);
|
|
10097
|
+
const executable = override ?? Bun.which(installation.executable) ?? installation.executable;
|
|
9846
10098
|
try {
|
|
9847
10099
|
const { stdout, stderr } = await execute2(executable, ["--version"], { timeout: 8000, maxBuffer: 65536, env: childEnvironment() });
|
|
9848
10100
|
return { harness, executable, available: true, version: (stdout.trim() || stderr.trim()).slice(0, 200), installation };
|
|
@@ -9857,6 +10109,10 @@ async function validateHarnessConfiguration(harness, cwd, args = []) {
|
|
|
9857
10109
|
await validateAiderConfiguration(cwd, args);
|
|
9858
10110
|
if (harness === "gemini")
|
|
9859
10111
|
await validateGeminiConfiguration(cwd);
|
|
10112
|
+
if (harness === "antigravity")
|
|
10113
|
+
await validateAntigravityConfiguration(cwd);
|
|
10114
|
+
if (harness === "junie")
|
|
10115
|
+
await validateJunieConfiguration(cwd);
|
|
9860
10116
|
}
|
|
9861
10117
|
var versionAtLeast2 = (raw, minimum) => {
|
|
9862
10118
|
const match = raw?.match(/(\d+)\.(\d+)\.(\d+)/);
|
|
@@ -9872,6 +10128,10 @@ var versionAtLeast2 = (raw, minimum) => {
|
|
|
9872
10128
|
return true;
|
|
9873
10129
|
};
|
|
9874
10130
|
function validateHarnessVersion(harness, version) {
|
|
10131
|
+
if (harness === "antigravity" && version?.trim() !== "1.2.5")
|
|
10132
|
+
throw new Error("Antigravity CLI 1.2.5 is required by the verified native adapter.");
|
|
10133
|
+
if (harness === "junie" && !/\b3196\.5\b/.test(version ?? ""))
|
|
10134
|
+
throw new Error("Junie build 3196.5 is required by the verified custom model adapter.");
|
|
9875
10135
|
if (harness === "kilo" && !versionAtLeast2(version, [7, 5, 15]))
|
|
9876
10136
|
throw new Error("Kilo >=7.5.15 is required by this scoped provider bridge.");
|
|
9877
10137
|
if (harness === "omp" && !versionAtLeast2(version, [18, 1, 11]))
|
|
@@ -9905,8 +10165,8 @@ function validateHarnessVersion(harness, version) {
|
|
|
9905
10165
|
throw new Error("Gemini CLI 0.58.0 is required by the verified native settings and argument contract.");
|
|
9906
10166
|
}
|
|
9907
10167
|
async function jsonFile(dir, name, value) {
|
|
9908
|
-
const path =
|
|
9909
|
-
await
|
|
10168
|
+
const path = join15(dir, name);
|
|
10169
|
+
await writeFile13(path, JSON.stringify(value, null, 2) + `
|
|
9910
10170
|
`, { mode: 384, flag: "wx" });
|
|
9911
10171
|
return path;
|
|
9912
10172
|
}
|
|
@@ -9914,7 +10174,7 @@ async function projectInstructionPaths(cwd) {
|
|
|
9914
10174
|
let dir = resolve8(cwd);
|
|
9915
10175
|
while (true) {
|
|
9916
10176
|
for (const name of ["AGENTS.md", "CLAUDE.md", "CONTEXT.md"]) {
|
|
9917
|
-
const path =
|
|
10177
|
+
const path = join15(dir, name);
|
|
9918
10178
|
if (await access3(path).then(() => true, () => false))
|
|
9919
10179
|
return [path];
|
|
9920
10180
|
}
|
|
@@ -9991,7 +10251,7 @@ function expandHomePattern(value) {
|
|
|
9991
10251
|
const record3 = value;
|
|
9992
10252
|
const output = {};
|
|
9993
10253
|
for (const [key, item] of Object.entries(record3)) {
|
|
9994
|
-
const expanded = key === "~" ?
|
|
10254
|
+
const expanded = key === "~" ? homedir8() : key.startsWith("~/") ? join15(homedir8(), key.slice(2)) : key;
|
|
9995
10255
|
output[expanded] = expandHomePattern(item);
|
|
9996
10256
|
}
|
|
9997
10257
|
return output;
|
|
@@ -10047,7 +10307,7 @@ function decodePolicy(text, file) {
|
|
|
10047
10307
|
async function readPolicyFile(file) {
|
|
10048
10308
|
let text;
|
|
10049
10309
|
try {
|
|
10050
|
-
text = await
|
|
10310
|
+
text = await readFile6(file, "utf8");
|
|
10051
10311
|
} catch (error) {
|
|
10052
10312
|
if (error.code === "ENOENT")
|
|
10053
10313
|
return;
|
|
@@ -10067,7 +10327,7 @@ async function agentPolicyFiles(dir, kind) {
|
|
|
10067
10327
|
throw error;
|
|
10068
10328
|
}
|
|
10069
10329
|
for (const entry of entries) {
|
|
10070
|
-
const file =
|
|
10330
|
+
const file = join15(current, entry.name);
|
|
10071
10331
|
if (entry.isDirectory())
|
|
10072
10332
|
await visit(file, root);
|
|
10073
10333
|
else if (entry.isFile() && entry.name.endsWith(".md"))
|
|
@@ -10075,11 +10335,11 @@ async function agentPolicyFiles(dir, kind) {
|
|
|
10075
10335
|
}
|
|
10076
10336
|
};
|
|
10077
10337
|
for (const rootName of [kind, `${kind}s`])
|
|
10078
|
-
await visit(
|
|
10338
|
+
await visit(join15(dir, rootName), join15(dir, rootName));
|
|
10079
10339
|
return result.sort((a, b) => a.file.localeCompare(b.file));
|
|
10080
10340
|
}
|
|
10081
10341
|
async function readAgentPolicyFile(file, kind, root) {
|
|
10082
|
-
const text = await
|
|
10342
|
+
const text = await readFile6(file, "utf8");
|
|
10083
10343
|
const match = text.match(/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
|
|
10084
10344
|
if (!match)
|
|
10085
10345
|
return;
|
|
@@ -10131,9 +10391,9 @@ async function preservedOpenCodePolicy(cwd) {
|
|
|
10131
10391
|
result.mode = { ...result.mode ?? {}, [policy.name]: { permission: merged } };
|
|
10132
10392
|
}
|
|
10133
10393
|
};
|
|
10134
|
-
const originalConfig =
|
|
10394
|
+
const originalConfig = join15(process.env.XDG_CONFIG_HOME ?? join15(homedir8(), ".config"), "opencode");
|
|
10135
10395
|
for (const name of ["config.json", "opencode.json", "opencode.jsonc"])
|
|
10136
|
-
await apply(
|
|
10396
|
+
await apply(join15(originalConfig, name));
|
|
10137
10397
|
await applyMarkdown(originalConfig, "agent");
|
|
10138
10398
|
await applyMarkdown(originalConfig, "mode");
|
|
10139
10399
|
if (process.env.OPENCODE_CONFIG)
|
|
@@ -10149,22 +10409,22 @@ async function preservedOpenCodePolicy(cwd) {
|
|
|
10149
10409
|
}
|
|
10150
10410
|
for (const current of [...dirs].reverse())
|
|
10151
10411
|
for (const name of ["opencode.jsonc", "opencode.json"])
|
|
10152
|
-
await apply(
|
|
10412
|
+
await apply(join15(current, name));
|
|
10153
10413
|
for (const current of dirs) {
|
|
10154
|
-
const configDir =
|
|
10414
|
+
const configDir = join15(current, ".opencode");
|
|
10155
10415
|
for (const name of ["opencode.json", "opencode.jsonc"])
|
|
10156
|
-
await apply(
|
|
10416
|
+
await apply(join15(configDir, name));
|
|
10157
10417
|
await applyMarkdown(configDir, "agent");
|
|
10158
10418
|
await applyMarkdown(configDir, "mode");
|
|
10159
10419
|
}
|
|
10160
|
-
const homeConfig =
|
|
10420
|
+
const homeConfig = join15(homedir8(), ".opencode");
|
|
10161
10421
|
for (const name of ["opencode.json", "opencode.jsonc"])
|
|
10162
|
-
await apply(
|
|
10422
|
+
await apply(join15(homeConfig, name));
|
|
10163
10423
|
await applyMarkdown(homeConfig, "agent");
|
|
10164
10424
|
await applyMarkdown(homeConfig, "mode");
|
|
10165
10425
|
if (process.env.OPENCODE_CONFIG_DIR) {
|
|
10166
10426
|
for (const name of ["opencode.json", "opencode.jsonc"])
|
|
10167
|
-
await apply(
|
|
10427
|
+
await apply(join15(process.env.OPENCODE_CONFIG_DIR, name));
|
|
10168
10428
|
await applyMarkdown(process.env.OPENCODE_CONFIG_DIR, "agent");
|
|
10169
10429
|
await applyMarkdown(process.env.OPENCODE_CONFIG_DIR, "mode");
|
|
10170
10430
|
}
|
|
@@ -10335,20 +10595,20 @@ var PRIME_DAEMON_STARTUP_TIMEOUT_MS = 30000;
|
|
|
10335
10595
|
var PRIME_DAEMON_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
10336
10596
|
function primeSocketPaths(runtimeDir) {
|
|
10337
10597
|
const basename3 = `p-${randomUUID4().replaceAll("-", "").slice(0, 8)}.sock`;
|
|
10338
|
-
const daemonSocket =
|
|
10598
|
+
const daemonSocket = join15(runtimeDir, basename3);
|
|
10339
10599
|
const uid = typeof process.getuid === "function" ? String(process.getuid()) : "user";
|
|
10340
|
-
const workerDir =
|
|
10600
|
+
const workerDir = join15(runtimeDir, `prime-agent-${uid}`);
|
|
10341
10601
|
const workerKey = createHash9("sha256").update(daemonSocket).digest("hex").slice(0, 12);
|
|
10342
|
-
const workerSocket =
|
|
10602
|
+
const workerSocket = join15(workerDir, `worker-${workerKey}-${"x".repeat(12)}.sock`);
|
|
10343
10603
|
const overlong = [daemonSocket, workerSocket].find((path) => Buffer.byteLength(path, "utf8") > PRIME_UNIX_SOCKET_LIMIT);
|
|
10344
|
-
return { daemonSocket, runtimeDir, workerDir, workerPrefix:
|
|
10604
|
+
return { daemonSocket, runtimeDir, workerDir, workerPrefix: join15(workerDir, `worker-${workerKey}-`), overlong };
|
|
10345
10605
|
}
|
|
10346
10606
|
async function primeSocketInfo() {
|
|
10347
10607
|
const requested = tmpdir();
|
|
10348
10608
|
const direct = primeSocketPaths(requested);
|
|
10349
10609
|
if (!direct.overlong)
|
|
10350
10610
|
return direct;
|
|
10351
|
-
const fallback =
|
|
10611
|
+
const fallback = join15(switcherHome(), "r");
|
|
10352
10612
|
await privateDirectory(switcherHome());
|
|
10353
10613
|
await privateDirectory(fallback);
|
|
10354
10614
|
const scoped = primeSocketPaths(fallback);
|
|
@@ -10529,7 +10789,7 @@ async function primeRemainingSockets(socketPath, workerPrefix) {
|
|
|
10529
10789
|
const workerDir = workerPrefix.slice(0, workerPrefix.lastIndexOf("/"));
|
|
10530
10790
|
const prefix = workerPrefix.slice(workerPrefix.lastIndexOf("/") + 1);
|
|
10531
10791
|
const workers = await readdir4(workerDir).then((entries) => entries.filter((entry) => entry.startsWith(prefix)), () => []);
|
|
10532
|
-
return [...daemon ? [socketPath] : [], ...workers.map((entry) =>
|
|
10792
|
+
return [...daemon ? [socketPath] : [], ...workers.map((entry) => join15(workerDir, entry))];
|
|
10533
10793
|
}
|
|
10534
10794
|
function primeModel(input, api) {
|
|
10535
10795
|
return input.models.map((model3) => ({
|
|
@@ -10547,7 +10807,7 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10547
10807
|
if (!compatible(input.harness, input.protocol))
|
|
10548
10808
|
throw new Error("Harness and provider protocol are incompatible.");
|
|
10549
10809
|
validateHarnessVersion(input.harness, input.version);
|
|
10550
|
-
if (!
|
|
10810
|
+
if (!isAbsolute13(input.stateDir) || !isAbsolute13(input.cwd))
|
|
10551
10811
|
throw new Error("Launch state and working directories must be absolute.");
|
|
10552
10812
|
if (!input.models.length || !input.models.some((m) => m.id === input.model))
|
|
10553
10813
|
throw new Error("Selected model is missing from the launch catalog.");
|
|
@@ -10566,6 +10826,10 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10566
10826
|
warnings.push(`${missing} catalog models have no declared context limit; native fallback limits may be inaccurate.`);
|
|
10567
10827
|
if (input.harness === "gemini")
|
|
10568
10828
|
return prepareGemini(input);
|
|
10829
|
+
if (input.harness === "antigravity")
|
|
10830
|
+
return prepareAntigravity(input);
|
|
10831
|
+
if (input.harness === "junie")
|
|
10832
|
+
return prepareJunie(input);
|
|
10569
10833
|
if (input.protocol === "gemini-generate-content")
|
|
10570
10834
|
throw new Error("Harness and provider protocol are incompatible.");
|
|
10571
10835
|
if (input.harness === "aider")
|
|
@@ -10587,7 +10851,8 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10587
10851
|
}
|
|
10588
10852
|
if (input.harness === "codex") {
|
|
10589
10853
|
const rolePolicy2 = await prepareCodexModelPolicy({ cwd: input.cwd, stateDir: input.stateDir, model: input.model, policy: input.modelPolicy ? { version: 1, ...input.modelPolicy } : undefined, switcherProvider: "switcher", switcherBaseUrl: input.baseUrl });
|
|
10590
|
-
const
|
|
10854
|
+
const selectableModels = input.models.filter((model3) => input.compiledPolicy?.allowedModels.includes(model3.id) ?? true);
|
|
10855
|
+
const file2 = await jsonFile(input.stateDir, "codex-models.json", { models: selectableModels.map((model3, index) => codexModel(model3, index, providerBaseUrl, model3.id === input.model ? input.reasoning : undefined)) });
|
|
10591
10856
|
configPaths.push(file2);
|
|
10592
10857
|
configPaths.push(...Object.values(rolePolicy2.agentConfigPaths));
|
|
10593
10858
|
env[KEY4] = input.credential ?? "switcher-local-no-auth";
|
|
@@ -10636,8 +10901,8 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10636
10901
|
throw new Error("Pi cannot safely select model IDs that differ only by letter case; update the provider catalog.");
|
|
10637
10902
|
const api = { "anthropic-messages": "anthropic-messages", "openai-responses": "openai-responses", "openai-chat": "openai-completions", "gemini-generate-content": "gemini" }[input.protocol];
|
|
10638
10903
|
const providerId = piProviderId(input, providerBaseUrl);
|
|
10639
|
-
const agentDir =
|
|
10640
|
-
const sessionDir = input.sessionDir ??
|
|
10904
|
+
const agentDir = join15(input.stateDir, "pi-agent");
|
|
10905
|
+
const sessionDir = input.sessionDir ?? join15(input.stateDir, "sessions");
|
|
10641
10906
|
const piBaseUrl = input.protocol === "anthropic-messages" ? input.baseUrl.replace(/\/v1$/i, "") : input.baseUrl;
|
|
10642
10907
|
await mkdir10(agentDir, { recursive: true, mode: 448 });
|
|
10643
10908
|
await mkdir10(sessionDir, { recursive: true, mode: 448 });
|
|
@@ -10662,9 +10927,9 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10662
10927
|
const selected = dshArguments(args);
|
|
10663
10928
|
const providerId = piProviderId(input, providerBaseUrl);
|
|
10664
10929
|
const api = { "anthropic-messages": "anthropic-messages", "openai-responses": "openai-responses", "openai-chat": "openai-completions" }[input.protocol];
|
|
10665
|
-
const home =
|
|
10666
|
-
const sessionDir = input.sessionDir ??
|
|
10667
|
-
if (!
|
|
10930
|
+
const home = join15(input.stateDir, "dsh-home");
|
|
10931
|
+
const sessionDir = input.sessionDir ?? join15(input.stateDir, "dsh-state");
|
|
10932
|
+
if (!isAbsolute13(sessionDir))
|
|
10668
10933
|
throw new Error("DSH session directory must be absolute.");
|
|
10669
10934
|
await mkdir10(home, { recursive: true, mode: 448 });
|
|
10670
10935
|
await mkdir10(sessionDir, { recursive: true, mode: 448 });
|
|
@@ -10685,7 +10950,7 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10685
10950
|
}))
|
|
10686
10951
|
} } } },
|
|
10687
10952
|
{ id: "agent-default-model", config: route2 },
|
|
10688
|
-
{ id: "session-persistence-jsonl", config: { root:
|
|
10953
|
+
{ id: "session-persistence-jsonl", config: { root: join15(sessionDir, "sessions") } },
|
|
10689
10954
|
{ id: "attachment-local", config: { dshHome: sessionDir } },
|
|
10690
10955
|
...selected.profile === "acp" ? [{ id: "acp", config: route2 }] : []
|
|
10691
10956
|
];
|
|
@@ -10711,15 +10976,15 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10711
10976
|
throw new Error("Prime Agent cannot safely select model IDs that differ only by letter case; update the provider catalog.");
|
|
10712
10977
|
const api = { "anthropic-messages": "anthropic-messages", "openai-responses": "openai-responses", "openai-chat": "openai-completions" }[input.protocol];
|
|
10713
10978
|
const providerId = primeProviderId(input, providerBaseUrl);
|
|
10714
|
-
const sessionDir = input.sessionDir ??
|
|
10715
|
-
const agentDir =
|
|
10979
|
+
const sessionDir = input.sessionDir ?? join15(input.stateDir, "sessions");
|
|
10980
|
+
const agentDir = join15(input.stateDir, "prime-agent");
|
|
10716
10981
|
const socketInfo = await primeSocketInfo();
|
|
10717
10982
|
const { daemonSocket, runtimeDir, workerPrefix } = socketInfo;
|
|
10718
10983
|
const primeBaseUrl = input.protocol === "anthropic-messages" ? input.baseUrl.replace(/\/v1$/i, "") : input.baseUrl;
|
|
10719
10984
|
await mkdir10(agentDir, { recursive: true, mode: 448 });
|
|
10720
10985
|
await mkdir10(sessionDir, { recursive: true, mode: 448 });
|
|
10721
|
-
const file2 =
|
|
10722
|
-
await
|
|
10986
|
+
const file2 = join15(agentDir, "models.json");
|
|
10987
|
+
await writeFile13(file2, JSON.stringify({ providers: { [providerId]: {
|
|
10723
10988
|
name: "Switcher",
|
|
10724
10989
|
baseUrl: primeBaseUrl,
|
|
10725
10990
|
api,
|
|
@@ -10810,13 +11075,13 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10810
11075
|
const file2 = await jsonFile(input.stateDir, "opencode-legacy.json", config2);
|
|
10811
11076
|
configPaths.push(file2);
|
|
10812
11077
|
env.OPENCODE_CONFIG = file2;
|
|
10813
|
-
const sessionDir = input.sessionDir ??
|
|
11078
|
+
const sessionDir = input.sessionDir ?? join15(input.stateDir, "sessions");
|
|
10814
11079
|
await mkdir10(sessionDir, { recursive: true, mode: 448 });
|
|
10815
|
-
env.XDG_DATA_HOME =
|
|
10816
|
-
env.XDG_CONFIG_HOME =
|
|
10817
|
-
env.XDG_CACHE_HOME =
|
|
10818
|
-
env.XDG_STATE_HOME =
|
|
10819
|
-
env.HOME =
|
|
11080
|
+
env.XDG_DATA_HOME = join15(sessionDir, "data");
|
|
11081
|
+
env.XDG_CONFIG_HOME = join15(input.stateDir, "config");
|
|
11082
|
+
env.XDG_CACHE_HOME = join15(input.stateDir, "cache");
|
|
11083
|
+
env.XDG_STATE_HOME = join15(input.stateDir, "state");
|
|
11084
|
+
env.HOME = join15(input.stateDir, "home");
|
|
10820
11085
|
env.OPENCODE_DISABLE_PROJECT_CONFIG = "true";
|
|
10821
11086
|
env.OPENCODE_CONFIG_CONTENT = JSON.stringify(config2);
|
|
10822
11087
|
env[KEY4] = input.credential ?? "switcher-local-no-auth";
|
|
@@ -10840,8 +11105,8 @@ async function prepareNativeLaunch(input, providerBaseUrl = input.providerBaseUr
|
|
|
10840
11105
|
const rolePolicy = compileOpenCodeModelPolicy({ providerId: providerID, mainModel: input.model, roles: input.compiledPolicy?.roles, preservedAgents: Object.entries(isolated.config.agents ?? {}).map(([name, agent]) => ({ ...agent, name })) });
|
|
10841
11106
|
const modelRef = openCodeInvocationModel(args, rolePolicy, isolated.config.default_agent);
|
|
10842
11107
|
const config = { ...isolated.config, ...rolePolicy.config, providers: { [providerID]: { name: "Switcher", env: [KEY4], package: `@opencode-ai/ai/providers/${packageName}`, settings: settings2, models } } };
|
|
10843
|
-
const file =
|
|
10844
|
-
await
|
|
11108
|
+
const file = join15(input.stateDir, "opencode.json");
|
|
11109
|
+
await writeFile13(file, openCode2ConfigText(config, providerID, KEY4), { mode: 384, flag: "wx" });
|
|
10845
11110
|
configPaths.push(file, isolated.instructionFile);
|
|
10846
11111
|
Object.assign(env, isolated.env);
|
|
10847
11112
|
env.OPENCODE_CONFIG = file;
|
|
@@ -10925,9 +11190,11 @@ async function prepareHarnessLaunch(input) {
|
|
|
10925
11190
|
validateHarnessVersion(input.harness, input.version);
|
|
10926
11191
|
if (!compatible(input.harness, input.protocol))
|
|
10927
11192
|
throw new Error("Harness and provider protocol are incompatible.");
|
|
10928
|
-
if (!
|
|
11193
|
+
if (!isAbsolute13(input.stateDir) || !isAbsolute13(input.cwd))
|
|
10929
11194
|
throw new Error("Launch state and working directories must be absolute.");
|
|
10930
11195
|
const compiledPolicy = compileModelPolicy(input.model, input.models, input.modelPolicy);
|
|
11196
|
+
if (input.harness === "antigravity" && input.model === antigravityHelperModel && compiledPolicy.roles.fast !== input.model)
|
|
11197
|
+
throw new Error("Antigravity main and helper requests are indistinguishable for this model; the fast role must use the same model.");
|
|
10931
11198
|
input = { ...input, models: input.models.filter((model3) => !modelExpired(model3)) };
|
|
10932
11199
|
const nativePolicy = compileNativeModelPolicy({ harness: input.harness, mainModel: input.model, roles: compiledPolicy.roles, version: input.version });
|
|
10933
11200
|
const specialized = new Set(["opencode", "opencode2", "gemini", "hermes"]);
|
|
@@ -10940,7 +11207,7 @@ async function prepareHarnessLaunch(input) {
|
|
|
10940
11207
|
try {
|
|
10941
11208
|
const nativeAuth = input.protocol === "gemini-generate-content" ? "x-api-key" : input.harness === "claude" ? input.authStyle === "x-api-key" ? "x-api-key" : "bearer" : input.protocol === "anthropic-messages" ? "x-api-key" : "bearer";
|
|
10942
11209
|
const prepared = await prepareTransportLaunch({ ...input, providerBaseUrl: input.baseUrl, baseUrl: bridge.baseUrl, credential: bridge.token, authStyle: nativeAuth, compiledPolicy, nativePolicy });
|
|
10943
|
-
return { ...prepared, configPaths: [...prepared.configPaths, catalogPath], warnings: [...prepared.warnings, "Switcher injects model guidance into every managed inference request and permits only
|
|
11210
|
+
return { ...prepared, configPaths: [...prepared.configPaths, catalogPath], warnings: [...prepared.warnings, "Switcher injects model guidance into every managed inference request and permits only models authorized by the launch policy, including catalog selection when enabled. The gateway translates the selected credential to the provider authentication header. The full catalog remains discoverable."], cleanup: async () => {
|
|
10944
11211
|
try {
|
|
10945
11212
|
await prepared.cleanup?.();
|
|
10946
11213
|
} finally {
|
|
@@ -10956,9 +11223,9 @@ async function prepareHarnessLaunch(input) {
|
|
|
10956
11223
|
}
|
|
10957
11224
|
|
|
10958
11225
|
// src/ori-model-policy.ts
|
|
10959
|
-
import { isAbsolute as
|
|
11226
|
+
import { isAbsolute as isAbsolute14 } from "path";
|
|
10960
11227
|
function prepareOriModelPolicy(target, prepared) {
|
|
10961
|
-
if (!
|
|
11228
|
+
if (!isAbsolute14(prepared.executable) || /[\0\r\n]/.test(prepared.executable))
|
|
10962
11229
|
throw new Error("Ori requires an absolute verified native executable.");
|
|
10963
11230
|
const entries = Object.entries(prepared.env);
|
|
10964
11231
|
if (entries.some(([key]) => !/^[A-Z_][A-Z0-9_]*$/.test(key)))
|
|
@@ -10982,8 +11249,8 @@ exec "$SWITCHER_ORI_NATIVE_EXECUTABLE" ${prepared.args.map(quote2).join(" ")}
|
|
|
10982
11249
|
}
|
|
10983
11250
|
|
|
10984
11251
|
// src/launcher.ts
|
|
10985
|
-
import { mkdir as mkdir11, mkdtemp, rm as rm6, writeFile as
|
|
10986
|
-
import { join as
|
|
11252
|
+
import { mkdir as mkdir11, mkdtemp, rm as rm6, writeFile as writeFile17 } from "fs/promises";
|
|
11253
|
+
import { join as join19, resolve as resolve9 } from "path";
|
|
10987
11254
|
|
|
10988
11255
|
// src/provider-credential-onboarding.ts
|
|
10989
11256
|
import { z as z8 } from "zod";
|
|
@@ -10993,8 +11260,8 @@ import { createInterface } from "readline/promises";
|
|
|
10993
11260
|
// src/credentials.ts
|
|
10994
11261
|
import { z as z7 } from "zod";
|
|
10995
11262
|
import { constants as constants5 } from "fs";
|
|
10996
|
-
import { open as open3, readdir as readdir5, unlink, link, lstat as
|
|
10997
|
-
import { join as
|
|
11263
|
+
import { open as open3, readdir as readdir5, unlink, link, lstat as lstat6, access as access4, stat as stat6, realpath as realpath6, readlink, rename as rename2 } from "fs/promises";
|
|
11264
|
+
import { join as join16, isAbsolute as isAbsolute15, dirname as dirname8, parse as pathParts, resolve as resolvePath, sep as sep2 } from "path";
|
|
10998
11265
|
import { createHash as createHash10, randomUUID as randomUUID5 } from "crypto";
|
|
10999
11266
|
import { execFile as execFile3, spawn } from "child_process";
|
|
11000
11267
|
import { promisify as promisify3 } from "util";
|
|
@@ -11020,7 +11287,7 @@ var credentialBindingSchema = z7.object({
|
|
|
11020
11287
|
kind: z7.literal("vault"),
|
|
11021
11288
|
key: vaultKeySchema,
|
|
11022
11289
|
url: z7.string().max(2000).transform(endpoint).optional(),
|
|
11023
|
-
executable: z7.string().max(4096).regex(/^[^\x00-\x1f\x7f]+$/).refine(
|
|
11290
|
+
executable: z7.string().max(4096).regex(/^[^\x00-\x1f\x7f]+$/).refine(isAbsolute15, "Secrets executable must be an absolute path"),
|
|
11024
11291
|
operator
|
|
11025
11292
|
}).strict()])
|
|
11026
11293
|
}).strict().superRefine((binding, ctx) => {
|
|
@@ -11036,16 +11303,16 @@ class CredentialBindings {
|
|
|
11036
11303
|
directory;
|
|
11037
11304
|
constructor(env = process.env) {
|
|
11038
11305
|
this.env = env;
|
|
11039
|
-
this.directory =
|
|
11306
|
+
this.directory = join16(switcherHome(env), "config", "credential-bindings");
|
|
11040
11307
|
}
|
|
11041
11308
|
path(name) {
|
|
11042
|
-
return
|
|
11309
|
+
return join16(this.directory, parse2(reference, name) + ".json");
|
|
11043
11310
|
}
|
|
11044
11311
|
async readableDirectory() {
|
|
11045
|
-
for (const path of [switcherHome(this.env),
|
|
11312
|
+
for (const path of [switcherHome(this.env), join16(switcherHome(this.env), "config"), this.directory]) {
|
|
11046
11313
|
let info;
|
|
11047
11314
|
try {
|
|
11048
|
-
info = await
|
|
11315
|
+
info = await lstat6(path);
|
|
11049
11316
|
} catch (error) {
|
|
11050
11317
|
if (error.code === "ENOENT")
|
|
11051
11318
|
return false;
|
|
@@ -11111,9 +11378,9 @@ class CredentialBindings {
|
|
|
11111
11378
|
if (binding.source.kind === "vault")
|
|
11112
11379
|
await validateVaultExecutable(binding.source.executable);
|
|
11113
11380
|
await privateDirectory(switcherHome(this.env));
|
|
11114
|
-
await privateDirectory(
|
|
11381
|
+
await privateDirectory(join16(switcherHome(this.env), "config"));
|
|
11115
11382
|
await privateDirectory(this.directory);
|
|
11116
|
-
const temporary =
|
|
11383
|
+
const temporary = join16(this.directory, `.binding-${randomUUID5()}`);
|
|
11117
11384
|
const file = await open3(temporary, "wx", 384);
|
|
11118
11385
|
try {
|
|
11119
11386
|
await file.writeFile(JSON.stringify(binding, null, 2) + `
|
|
@@ -11169,13 +11436,13 @@ async function inspectVaultExecutable(path, permitWritableFile = false) {
|
|
|
11169
11436
|
for (const part of candidate.slice(prefix.length).split(sep2)) {
|
|
11170
11437
|
if (!part)
|
|
11171
11438
|
continue;
|
|
11172
|
-
prefix =
|
|
11439
|
+
prefix = join16(prefix, part);
|
|
11173
11440
|
if (seen.has(prefix))
|
|
11174
11441
|
continue;
|
|
11175
11442
|
seen.add(prefix);
|
|
11176
11443
|
if (seen.size > 256)
|
|
11177
11444
|
throw new Fault(422, "vault_exec_permissions", "The secrets executable path has too many symlink components.");
|
|
11178
|
-
const entry = await
|
|
11445
|
+
const entry = await lstat6(prefix);
|
|
11179
11446
|
const permittedFile = permitWritableFile && prefix === resolved && entry.isFile();
|
|
11180
11447
|
if (entry.uid !== 0 && entry.uid !== process.getuid?.() || !entry.isSymbolicLink() && !permittedFile && entry.mode & 18)
|
|
11181
11448
|
throw new Fault(422, "vault_exec_permissions", "The secrets executable and its ancestor directories must not be replaceable by other users. Choose an installation owned by this user or root without group/public write permissions.");
|
|
@@ -11200,7 +11467,7 @@ async function validateVaultExecutable(path) {
|
|
|
11200
11467
|
async function repairVaultExecutablePermissions(path, expectedSha256) {
|
|
11201
11468
|
if (!/^[a-f0-9]{64}$/.test(expectedSha256))
|
|
11202
11469
|
throw new Fault(400, "invalid_request", "--sha256 requires the SHA256 of the executable member from a verified package artifact.");
|
|
11203
|
-
if (!
|
|
11470
|
+
if (!isAbsolute15(path) || path.length > 4096 || /[\x00-\x1f\x7f]/.test(path))
|
|
11204
11471
|
throw new Fault(400, "invalid_request", "Secrets executable must be an absolute path without control characters.");
|
|
11205
11472
|
if (process.platform === "win32")
|
|
11206
11473
|
throw new Fault(422, "vault_exec_repair_unsafe", "Executable permission repair requires POSIX file permissions.");
|
|
@@ -11238,13 +11505,13 @@ async function repairVaultExecutablePermissions(path, expectedSha256) {
|
|
|
11238
11505
|
await hash2();
|
|
11239
11506
|
const mode = before.mode & 511 & ~18;
|
|
11240
11507
|
const changed = mode !== (before.mode & 511);
|
|
11241
|
-
if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await
|
|
11508
|
+
if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat6(resolved)))
|
|
11242
11509
|
throw unsafe();
|
|
11243
11510
|
if (!changed) {
|
|
11244
11511
|
await validateVaultExecutable(path);
|
|
11245
11512
|
return { changed, mode: mode.toString(8).padStart(4, "0"), sha256: expectedSha256 };
|
|
11246
11513
|
}
|
|
11247
|
-
temporary =
|
|
11514
|
+
temporary = join16(dirname8(resolved), `.switcher-repair-${randomUUID5()}`);
|
|
11248
11515
|
const replacement = await open3(temporary, "wx", 384);
|
|
11249
11516
|
try {
|
|
11250
11517
|
await hash2(replacement);
|
|
@@ -11253,11 +11520,11 @@ async function repairVaultExecutablePermissions(path, expectedSha256) {
|
|
|
11253
11520
|
const ready = await replacement.stat();
|
|
11254
11521
|
if (!ready.isFile() || ready.nlink !== 1 || ready.uid !== before.uid || ready.size !== before.size)
|
|
11255
11522
|
throw unsafe();
|
|
11256
|
-
if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await
|
|
11523
|
+
if (await inspectVaultExecutable(path, true) !== resolved || !sameFile(await lstat6(resolved)))
|
|
11257
11524
|
throw unsafe();
|
|
11258
11525
|
await rename2(temporary, resolved);
|
|
11259
11526
|
temporary = undefined;
|
|
11260
|
-
const installed = await
|
|
11527
|
+
const installed = await lstat6(resolved);
|
|
11261
11528
|
if (installed.dev !== ready.dev || installed.ino !== ready.ino || await validateVaultExecutable(path) !== resolved)
|
|
11262
11529
|
throw unsafe();
|
|
11263
11530
|
const directory = await open3(dirname8(resolved), constants5.O_RDONLY | constants5.O_DIRECTORY | constants5.O_NOFOLLOW);
|
|
@@ -11639,6 +11906,9 @@ function authenticationProbe(provider) {
|
|
|
11639
11906
|
return { url, method: provider.credentialCheck.method ?? "GET", authStyle: provider.authStyle ?? "bearer" };
|
|
11640
11907
|
}
|
|
11641
11908
|
const base = new URL(provider.baseUrl);
|
|
11909
|
+
const bedrockOrigin = bedrockMantleOrigin(provider.baseUrl);
|
|
11910
|
+
if (provider.protocol === "anthropic-messages" && bedrockOrigin)
|
|
11911
|
+
return { url: new URL("/v1/models", bedrockOrigin), method: "GET", authStyle: "bearer" };
|
|
11642
11912
|
if (provider.credentialEnv === "SWITCHER_PROVIDER_OPENROUTER" && base.origin === "https://openrouter.ai" && base.pathname.replace(/\/+$/, "") === "/api/v1")
|
|
11643
11913
|
return { url: new URL("https://openrouter.ai/api/v1/key"), method: "GET", authStyle: provider.authStyle ?? "bearer" };
|
|
11644
11914
|
return;
|
|
@@ -12312,18 +12582,18 @@ function oriLaunchWarnings(target) {
|
|
|
12312
12582
|
|
|
12313
12583
|
// src/chatgpt-launch.ts
|
|
12314
12584
|
import { createHash as createHash12 } from "crypto";
|
|
12315
|
-
import { writeFile as
|
|
12316
|
-
import { join as
|
|
12585
|
+
import { writeFile as writeFile15, rm as rm4 } from "fs/promises";
|
|
12586
|
+
import { join as join17 } from "path";
|
|
12317
12587
|
|
|
12318
12588
|
// src/desktop-state.ts
|
|
12319
12589
|
import { Database as Database3 } from "bun:sqlite";
|
|
12320
|
-
import { readFile as
|
|
12590
|
+
import { readFile as readFile7, writeFile as writeFile14, rm as rm3, lstat as lstat7, rename as rename3, chmod as chmod2 } from "fs/promises";
|
|
12321
12591
|
async function safeDesktopRead(path) {
|
|
12322
12592
|
try {
|
|
12323
|
-
const info = await
|
|
12593
|
+
const info = await lstat7(path);
|
|
12324
12594
|
if (!info.isFile() || info.isSymbolicLink() || info.uid !== process.getuid?.())
|
|
12325
12595
|
throw new Fault(422, "desktop_state_permissions", "Desktop settings must be regular files owned by this user.");
|
|
12326
|
-
return await
|
|
12596
|
+
return await readFile7(path, "utf8");
|
|
12327
12597
|
} catch (error) {
|
|
12328
12598
|
if (error.code === "ENOENT")
|
|
12329
12599
|
return;
|
|
@@ -12333,7 +12603,7 @@ async function safeDesktopRead(path) {
|
|
|
12333
12603
|
async function writeDesktopPrivate(path, text) {
|
|
12334
12604
|
const temporary = path + "." + crypto.randomUUID() + ".tmp";
|
|
12335
12605
|
try {
|
|
12336
|
-
await
|
|
12606
|
+
await writeFile14(temporary, text, { mode: 384, flag: "wx" });
|
|
12337
12607
|
await rename3(temporary, path);
|
|
12338
12608
|
} finally {
|
|
12339
12609
|
await rm3(temporary, { force: true });
|
|
@@ -12341,7 +12611,7 @@ async function writeDesktopPrivate(path, text) {
|
|
|
12341
12611
|
}
|
|
12342
12612
|
async function desktopLease(path) {
|
|
12343
12613
|
try {
|
|
12344
|
-
const info = await
|
|
12614
|
+
const info = await lstat7(path);
|
|
12345
12615
|
if (!info.isFile() || info.isSymbolicLink() || info.uid !== process.getuid?.())
|
|
12346
12616
|
throw new Fault(422, "desktop_state_permissions", "Desktop lease must be a regular file owned by this user.");
|
|
12347
12617
|
} catch (error) {
|
|
@@ -12377,12 +12647,12 @@ var digest = (value) => createHash12("sha256").update(value).digest("hex");
|
|
|
12377
12647
|
var quote2 = (value) => `'${value.replaceAll("'", `'"'"'`)}'`;
|
|
12378
12648
|
async function prepareChatGPTLaunch(native, app, stateDir, sessionDir) {
|
|
12379
12649
|
await privateDirectory(sessionDir);
|
|
12380
|
-
const home =
|
|
12650
|
+
const home = join17(sessionDir, "codex"), userData = join17(sessionDir, "electron");
|
|
12381
12651
|
await privateDirectory(home);
|
|
12382
12652
|
await privateDirectory(userData);
|
|
12383
|
-
const release = await desktopLease(
|
|
12653
|
+
const release = await desktopLease(join17(sessionDir, "launch.sqlite"));
|
|
12384
12654
|
let released = false, authText;
|
|
12385
|
-
const authPath =
|
|
12655
|
+
const authPath = join17(home, "auth.json"), receiptPath = join17(home, ".switcher-auth.sha256");
|
|
12386
12656
|
const cleanup = async () => {
|
|
12387
12657
|
if (released)
|
|
12388
12658
|
return;
|
|
@@ -12408,7 +12678,7 @@ async function prepareChatGPTLaunch(native, app, stateDir, sessionDir) {
|
|
|
12408
12678
|
settings2.push('approval_policy="on-request"');
|
|
12409
12679
|
if (!settings2.some((setting) => setting.startsWith("sandbox_mode=")))
|
|
12410
12680
|
settings2.push('sandbox_mode="workspace-write"');
|
|
12411
|
-
const configPath =
|
|
12681
|
+
const configPath = join17(home, "config.toml");
|
|
12412
12682
|
const previousAuth = await safeDesktopRead(authPath), previousReceipt = await safeDesktopRead(receiptPath);
|
|
12413
12683
|
if (previousAuth !== undefined && previousReceipt !== digest(previousAuth))
|
|
12414
12684
|
throw new Fault(409, "desktop_auth_changed", "This isolated desktop profile contains authentication that Switcher did not create. Sign out of that provider profile before launching it again; Switcher will not overwrite it.");
|
|
@@ -12429,9 +12699,9 @@ async function prepareChatGPTLaunch(native, app, stateDir, sessionDir) {
|
|
|
12429
12699
|
`;
|
|
12430
12700
|
await writeDesktopPrivate(receiptPath, digest(authText));
|
|
12431
12701
|
await writeDesktopPrivate(authPath, authText);
|
|
12432
|
-
const wrapper =
|
|
12702
|
+
const wrapper = join17(stateDir, "chatgpt-codex");
|
|
12433
12703
|
const overrides = settings2.flatMap((setting) => ["-c", setting]);
|
|
12434
|
-
await
|
|
12704
|
+
await writeFile15(wrapper, `#!/bin/sh
|
|
12435
12705
|
set -eu
|
|
12436
12706
|
unset OPENAI_API_KEY CODEX_API_KEY CODEX_ACCESS_TOKEN OPENAI_BASE_URL OPENAI_ORG_ID OPENAI_ORGANIZATION OPENAI_PROJECT_ID
|
|
12437
12707
|
export CODEX_HOME=${quote2(home)}
|
|
@@ -12464,15 +12734,15 @@ exec ${quote2(app.codexExecutable)} "$@" ${overrides.map(quote2).join(" ")}
|
|
|
12464
12734
|
// src/claude-desktop-launch.ts
|
|
12465
12735
|
import { createHash as createHash13 } from "crypto";
|
|
12466
12736
|
import { execFile as execFile5 } from "child_process";
|
|
12467
|
-
import { access as access5, rm as rm5, writeFile as
|
|
12468
|
-
import { homedir as
|
|
12469
|
-
import { join as
|
|
12737
|
+
import { access as access5, rm as rm5, writeFile as writeFile16 } from "fs/promises";
|
|
12738
|
+
import { homedir as homedir9, userInfo as userInfo2 } from "os";
|
|
12739
|
+
import { join as join18 } from "path";
|
|
12470
12740
|
import { promisify as promisify5 } from "util";
|
|
12471
12741
|
var execute4 = promisify5(execFile5);
|
|
12472
12742
|
var hash2 = (text) => createHash13("sha256").update(text).digest("hex");
|
|
12473
|
-
var claudeDesktopDataDirectory = () =>
|
|
12743
|
+
var claudeDesktopDataDirectory = () => join18(homedir9(), "Library/Application Support/Claude-3p");
|
|
12474
12744
|
async function assertAvailable(userData) {
|
|
12475
|
-
for (const path of [
|
|
12745
|
+
for (const path of [join18("/Library/Managed Preferences", userInfo2().username, "com.anthropic.claudefordesktop.plist"), "/Library/Managed Preferences/com.anthropic.claudefordesktop.plist"])
|
|
12476
12746
|
if (await access5(path).then(() => true, () => false))
|
|
12477
12747
|
throw new Fault(409, "desktop_managed", "Claude has managed preferences. Configure its gateway through the administrator's policy; Switcher will not override it.");
|
|
12478
12748
|
let openFiles;
|
|
@@ -12506,15 +12776,15 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
|
|
|
12506
12776
|
const check2 = system?.assertAvailable ?? (() => assertAvailable(userData));
|
|
12507
12777
|
await check2();
|
|
12508
12778
|
await privateDirectory(userData);
|
|
12509
|
-
const library =
|
|
12779
|
+
const library = join18(userData, "configLibrary");
|
|
12510
12780
|
await privateDirectory(library);
|
|
12511
|
-
const release = await desktopLease(
|
|
12512
|
-
const metaPath =
|
|
12781
|
+
const release = await desktopLease(join18(library, ".switcher-lease.sqlite"));
|
|
12782
|
+
const metaPath = join18(library, "_meta.json"), receiptPath = join18(library, ".switcher-selection.json");
|
|
12513
12783
|
let receipt, gateway, closed = false;
|
|
12514
12784
|
const restore = async (record3) => {
|
|
12515
12785
|
if (!/^[a-f0-9-]{36}$/.test(record3.id) || typeof record3.configHash !== "string" || typeof record3.appliedMeta !== "string" || record3.previousMeta !== null && typeof record3.previousMeta !== "string")
|
|
12516
12786
|
throw new Fault(422, "desktop_config_invalid", "Claude's Switcher recovery record is invalid.");
|
|
12517
|
-
const configPath =
|
|
12787
|
+
const configPath = join18(library, record3.id + ".json"), current = await safeDesktopRead(configPath);
|
|
12518
12788
|
if (current !== undefined && hash2(current) !== record3.configHash)
|
|
12519
12789
|
throw new Fault(409, "desktop_config_changed", "The Switcher Claude configuration was edited outside this launch. Switcher will preserve it; review the configuration library before relaunching.");
|
|
12520
12790
|
const currentMeta = await safeDesktopRead(metaPath);
|
|
@@ -12543,7 +12813,7 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
|
|
|
12543
12813
|
const recovery = await safeDesktopRead(receiptPath);
|
|
12544
12814
|
if (recovery)
|
|
12545
12815
|
await restore(JSON.parse(recovery));
|
|
12546
|
-
const localConfig = await safeDesktopRead(
|
|
12816
|
+
const localConfig = await safeDesktopRead(join18(userData, "claude_desktop_config.json"));
|
|
12547
12817
|
if (localConfig && JSON.parse(localConfig).deploymentMode === "1p")
|
|
12548
12818
|
throw new Fault(409, "desktop_mode", "Claude's third-party profile is set to standard account mode. Select third-party mode in Claude before launching this gateway.");
|
|
12549
12819
|
await privateDirectory(sessionDir);
|
|
@@ -12554,10 +12824,10 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
|
|
|
12554
12824
|
if (input.modelPolicy?.aliases?.[alias] && input.modelPolicy.aliases[alias] !== target)
|
|
12555
12825
|
throw new Fault(409, "desktop_alias_conflict", "The model policy conflicts with Claude desktop's reserved switcher/sonnet, switcher/opus or switcher/haiku routing aliases.");
|
|
12556
12826
|
const compiledPolicy = compileModelPolicy(input.model, input.models, { ...input.modelPolicy, version: 1, aliases: { ...input.modelPolicy?.aliases, ...aliases } });
|
|
12557
|
-
const catalogPath =
|
|
12558
|
-
await
|
|
12827
|
+
const catalogPath = join18(input.stateDir, "claude-desktop-policy.json");
|
|
12828
|
+
await writeFile16(catalogPath, JSON.stringify({ policy: compiledPolicy, models: input.models }), { mode: 384, flag: "wx" });
|
|
12559
12829
|
gateway = createInferenceGateway({ ...input, compiledPolicy, catalogPath });
|
|
12560
|
-
const id2 = crypto.randomUUID(), configPath =
|
|
12830
|
+
const id2 = crypto.randomUUID(), configPath = join18(library, id2 + ".json");
|
|
12561
12831
|
const config = JSON.stringify({
|
|
12562
12832
|
inferenceProvider: "gateway",
|
|
12563
12833
|
inferenceGatewayBaseUrl: gateway.baseUrl.replace(/\/v1$/, ""),
|
|
@@ -12593,13 +12863,15 @@ async function prepareClaudeDesktopLaunch(input, app, sessionDir, system) {
|
|
|
12593
12863
|
// src/launcher.ts
|
|
12594
12864
|
var LATE_RUN_FINALIZATION_TIMEOUT_MS = 5000;
|
|
12595
12865
|
async function writeOriCodexCatalog(stateDir, models) {
|
|
12596
|
-
const path =
|
|
12866
|
+
const path = join19(stateDir, "ori-codex-models.json");
|
|
12597
12867
|
const nativeModels2 = models.filter(codingEligible).map((model3, index) => codexModel(model3, index));
|
|
12598
|
-
await
|
|
12868
|
+
await writeFile17(path, JSON.stringify({ models: nativeModels2 }, null, 2) + `
|
|
12599
12869
|
`, { mode: 384, flag: "wx" });
|
|
12600
12870
|
return path;
|
|
12601
12871
|
}
|
|
12602
12872
|
function oriTarget(harness) {
|
|
12873
|
+
if (harness === "antigravity" || harness === "junie")
|
|
12874
|
+
throw new Error("This CLI is supported through the direct Switcher backend only.");
|
|
12603
12875
|
if (harness === "kilo")
|
|
12604
12876
|
throw new Error("Ori does not launch Kilo; use the direct backend.");
|
|
12605
12877
|
if (harness === "opencode")
|
|
@@ -12684,9 +12956,9 @@ async function prepareOriForPlan(plan, options) {
|
|
|
12684
12956
|
});
|
|
12685
12957
|
try {
|
|
12686
12958
|
const shim = prepareOriModelPolicy(request.target, native);
|
|
12687
|
-
const dir =
|
|
12959
|
+
const dir = join19(options.stateDir, "ori-bin"), path = join19(dir, shim.name);
|
|
12688
12960
|
await mkdir11(dir, { mode: 448 });
|
|
12689
|
-
await
|
|
12961
|
+
await writeFile17(path, shim.script, { mode: 448, flag: "wx" });
|
|
12690
12962
|
return { contract, prepared: {
|
|
12691
12963
|
...ori,
|
|
12692
12964
|
env: { ...ori.env, ...shim.env, PATH: `${dir}:${ori.env.PATH ?? process.env.PATH ?? ""}` },
|
|
@@ -12706,7 +12978,7 @@ async function launch(client, profileId, options = {}) {
|
|
|
12706
12978
|
if ((options.reasoning || options.dangerouslyBypassApprovalsAndSandbox) && (profile.harness !== "codex" || (options.backend ?? "direct") !== "direct"))
|
|
12707
12979
|
throw new Error("Reasoning and full-access launch options require direct Codex or ChatGPT.");
|
|
12708
12980
|
assertHarnessArguments(profile.harness, options.args ?? []);
|
|
12709
|
-
if (profile.harness === "gemini")
|
|
12981
|
+
if (profile.harness === "gemini" || profile.harness === "antigravity")
|
|
12710
12982
|
validateHarnessProvider(profile.harness, await client.getProvider(profile.providerId));
|
|
12711
12983
|
await validateHarnessConfiguration(profile.harness, resolve9(options.cwd ?? process.cwd()), options.args);
|
|
12712
12984
|
if (profile.harness === "grok" && !["", "0", "false", "no", "off"].includes((process.env.GROK_DISABLE_API_KEY_AUTH ?? "").trim().toLowerCase()))
|
|
@@ -12739,9 +13011,9 @@ async function launch(client, profileId, options = {}) {
|
|
|
12739
13011
|
validateHarnessVersion("gemini", detection?.version);
|
|
12740
13012
|
if (backend === "direct" && plan.profile.harness === "aider")
|
|
12741
13013
|
validateHarnessVersion(plan.profile.harness, detection?.version);
|
|
12742
|
-
const root = resolve9(options.stateDir ??
|
|
13014
|
+
const root = resolve9(options.stateDir ?? join19(switcherHome(), "state"));
|
|
12743
13015
|
await privateDirectory(root);
|
|
12744
|
-
const stateDir = await mkdtemp(
|
|
13016
|
+
const stateDir = await mkdtemp(join19(root, "launch-"));
|
|
12745
13017
|
let credential;
|
|
12746
13018
|
if (backend === "direct") {
|
|
12747
13019
|
try {
|
|
@@ -12799,7 +13071,7 @@ async function launch(client, profileId, options = {}) {
|
|
|
12799
13071
|
stateDir,
|
|
12800
13072
|
cwd: resolve9(options.cwd ?? process.cwd())
|
|
12801
13073
|
};
|
|
12802
|
-
let prepared = options.claudeDesktop ? await prepareClaudeDesktopLaunch(input, options.claudeDesktop,
|
|
13074
|
+
let prepared = options.claudeDesktop ? await prepareClaudeDesktopLaunch(input, options.claudeDesktop, join19(root, "desktop-claude", profileId)) : backend === "ori" ? (await prepareOriForPlan(plan, { ...options, stateDir, onRoutingEvent })).prepared : await prepareHarnessLaunch({
|
|
12803
13075
|
harness: plan.profile.harness,
|
|
12804
13076
|
baseUrl: plan.provider.baseUrl,
|
|
12805
13077
|
protocol: plan.provider.protocol,
|
|
@@ -12817,11 +13089,11 @@ async function launch(client, profileId, options = {}) {
|
|
|
12817
13089
|
stateDir,
|
|
12818
13090
|
cwd: resolve9(options.cwd ?? process.cwd()),
|
|
12819
13091
|
version: detection?.version,
|
|
12820
|
-
...["pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "opencode", "kilo"].includes(plan.profile.harness) ? { sessionDir:
|
|
13092
|
+
...["pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "opencode", "kilo", "antigravity", "junie"].includes(plan.profile.harness) ? { sessionDir: join19(root, "sessions", plan.profile.harness, profileId) } : {}
|
|
12821
13093
|
});
|
|
12822
13094
|
cleanup = prepared.cleanup;
|
|
12823
13095
|
if (options.desktop) {
|
|
12824
|
-
prepared = await prepareChatGPTLaunch(prepared, options.desktop, stateDir,
|
|
13096
|
+
prepared = await prepareChatGPTLaunch(prepared, options.desktop, stateDir, join19(root, "desktop", profileId));
|
|
12825
13097
|
cleanup = prepared.cleanup;
|
|
12826
13098
|
}
|
|
12827
13099
|
for (const warning of [...plan.warnings, ...prepared.warnings])
|
|
@@ -13013,7 +13285,8 @@ async function selectModel(models, query = "", harness) {
|
|
|
13013
13285
|
}
|
|
13014
13286
|
}
|
|
13015
13287
|
async function ensureLaunchProfile(client, provider, harness, model3, modelPolicy) {
|
|
13016
|
-
const
|
|
13288
|
+
const policy = modelPolicy ?? (harness === "codex" ? { version: 1, selection: "catalog" } : undefined);
|
|
13289
|
+
const normalizedPolicy = policy === undefined ? undefined : parse2(modelPolicySchema, policy);
|
|
13017
13290
|
const identity = normalizedPolicy === undefined ? [provider.id, harness, model3] : [provider.id, harness, model3, normalizedPolicy];
|
|
13018
13291
|
const hash3 = createHash14("sha256").update(canonicalPolicyJSON(identity)).digest("hex").slice(0, 24);
|
|
13019
13292
|
const desired = parse2(profileInputSchema, { id: `launch-${harness}-${hash3}`, name: `${harness}: ${model3}`.slice(0, 200), providerId: provider.id, harness, model: model3, ...normalizedPolicy ? { modelPolicy: normalizedPolicy } : {} });
|
|
@@ -13076,7 +13349,7 @@ var HELP = `switcher \u2014 launch coding harnesses and desktop apps with your p
|
|
|
13076
13349
|
switcher credentials repair-executable --vault-cli PATH --sha256 EXPECTED
|
|
13077
13350
|
switcher doctor
|
|
13078
13351
|
|
|
13079
|
-
HARNESS: claude, codex, grok, opencode, opencode2, pi, omp, dsh, cline, hermes, prime-agent, gemini, aider, kilo
|
|
13352
|
+
HARNESS: claude, codex, grok, opencode, opencode2, pi, omp, dsh, cline, hermes, prime-agent, gemini, antigravity, junie, aider, kilo
|
|
13080
13353
|
chatgpt launches the installed macOS desktop app in an isolated provider profile.
|
|
13081
13354
|
Its local Codex conversations use the selected Responses-compatible provider.
|
|
13082
13355
|
claude-desktop launches Claude in its separate Claude-3p gateway profile with a
|
|
@@ -13365,7 +13638,7 @@ async function main(args = process.argv.slice(2)) {
|
|
|
13365
13638
|
modelsPath: values2["models-path"]
|
|
13366
13639
|
});
|
|
13367
13640
|
if (command === "doctor") {
|
|
13368
|
-
const harnesses = await Promise.all(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "aider", "kilo"].map((h) => detectHarness(h)));
|
|
13641
|
+
const harnesses = await Promise.all(["claude", "codex", "grok", "opencode", "opencode2", "pi", "omp", "dsh", "cline", "hermes", "prime-agent", "gemini", "antigravity", "junie", "aider", "kilo"].map((h) => detectHarness(h)));
|
|
13369
13642
|
let api;
|
|
13370
13643
|
try {
|
|
13371
13644
|
api = { mode: runtime.mode, reachable: true, health: await client.health(), ready: await client.ready() };
|
|
@@ -13422,7 +13695,7 @@ async function main(args = process.argv.slice(2)) {
|
|
|
13422
13695
|
assertHarnessArguments(profile.harness, nativeArgs);
|
|
13423
13696
|
await validateHarnessConfiguration(profile.harness, values2.cwd ?? process.cwd(), nativeArgs);
|
|
13424
13697
|
const provider = await client.getProvider(profile.providerId);
|
|
13425
|
-
if (profile.harness === "gemini")
|
|
13698
|
+
if (profile.harness === "gemini" || profile.harness === "antigravity")
|
|
13426
13699
|
validateHarnessProvider(profile.harness, provider);
|
|
13427
13700
|
let prepared;
|
|
13428
13701
|
if (!values2["dry-run"]) {
|